@embedpdf/plugin-export 1.0.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/LICENSE +21 -0
- package/dist/index.cjs +92 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +28 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/dist/preact/index.cjs +68 -0
- package/dist/preact/index.cjs.map +1 -0
- package/dist/preact/index.d.cts +18 -0
- package/dist/preact/index.d.ts +18 -0
- package/dist/preact/index.js +39 -0
- package/dist/preact/index.js.map +1 -0
- package/dist/react/index.cjs +68 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +18 -0
- package/dist/react/index.d.ts +18 -0
- package/dist/react/index.js +39 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 CloudPDF
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
EXPORT_PLUGIN_ID: () => EXPORT_PLUGIN_ID,
|
|
24
|
+
ExportPlugin: () => ExportPlugin,
|
|
25
|
+
ExportPluginPackage: () => ExportPluginPackage,
|
|
26
|
+
manifest: () => manifest
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
|
|
30
|
+
// src/lib/export-plugin.ts
|
|
31
|
+
var import_core = require("@embedpdf/core");
|
|
32
|
+
var import_models = require("@embedpdf/models");
|
|
33
|
+
var ExportPlugin = class extends import_core.BasePlugin {
|
|
34
|
+
constructor(id, registry, engine) {
|
|
35
|
+
super(id, registry);
|
|
36
|
+
this.downloadRequest$ = (0, import_core.createEmitter)();
|
|
37
|
+
this.engine = engine;
|
|
38
|
+
}
|
|
39
|
+
async initialize(_) {
|
|
40
|
+
}
|
|
41
|
+
buildCapability() {
|
|
42
|
+
return {
|
|
43
|
+
saveAsCopy: this.saveAsCopy.bind(this),
|
|
44
|
+
download: this.download.bind(this),
|
|
45
|
+
onRequest: this.downloadRequest$.on
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
download() {
|
|
49
|
+
this.downloadRequest$.emit("download");
|
|
50
|
+
}
|
|
51
|
+
saveAsCopy() {
|
|
52
|
+
const document = this.coreState.core.document;
|
|
53
|
+
if (!document)
|
|
54
|
+
return import_models.PdfTaskHelper.reject({
|
|
55
|
+
code: import_models.PdfErrorCode.DocNotOpen,
|
|
56
|
+
message: "Document not found"
|
|
57
|
+
});
|
|
58
|
+
return this.engine.saveAsCopy(document);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
ExportPlugin.id = "export";
|
|
62
|
+
|
|
63
|
+
// src/lib/manifest.ts
|
|
64
|
+
var EXPORT_PLUGIN_ID = "export";
|
|
65
|
+
var manifest = {
|
|
66
|
+
id: EXPORT_PLUGIN_ID,
|
|
67
|
+
name: "Export Plugin",
|
|
68
|
+
version: "1.0.0",
|
|
69
|
+
provides: ["export"],
|
|
70
|
+
requires: [],
|
|
71
|
+
optional: [],
|
|
72
|
+
defaultConfig: {
|
|
73
|
+
enabled: true
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/lib/index.ts
|
|
78
|
+
var ExportPluginPackage = {
|
|
79
|
+
manifest,
|
|
80
|
+
create: (registry, engine) => new ExportPlugin(EXPORT_PLUGIN_ID, registry, engine),
|
|
81
|
+
reducer: () => {
|
|
82
|
+
},
|
|
83
|
+
initialState: {}
|
|
84
|
+
};
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
EXPORT_PLUGIN_ID,
|
|
88
|
+
ExportPlugin,
|
|
89
|
+
ExportPluginPackage,
|
|
90
|
+
manifest
|
|
91
|
+
});
|
|
92
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/lib/export-plugin.ts","../src/lib/manifest.ts","../src/lib/index.ts"],"sourcesContent":["export * from './lib';\n","import { BasePlugin, createEmitter, PluginRegistry } from '@embedpdf/core';\nimport { PdfEngine, PdfErrorCode, PdfErrorReason, PdfTaskHelper, Task } from '@embedpdf/models';\n\nimport { 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\n private engine: PdfEngine;\n\n constructor(id: string, registry: PluginRegistry, engine: PdfEngine) {\n super(id, registry);\n\n this.engine = engine;\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 onRequest: this.downloadRequest$.on,\n };\n }\n\n private download(): void {\n this.downloadRequest$.emit('download');\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 },\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, engine) => new ExportPlugin(EXPORT_PLUGIN_ID, registry, engine),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './export-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA0D;AAC1D,oBAA6E;AAItE,IAAM,eAAN,cAA2B,uBAAiD;AAAA,EAOjF,YAAY,IAAY,UAA0B,QAAmB;AACnE,UAAM,IAAI,QAAQ;AALpB,SAAiB,uBAAmB,2BAA0B;AAO5D,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,MAAM,WAAW,GAAsC;AAAA,EAAC;AAAA,EAE9C,kBAAoC;AAC5C,WAAO;AAAA,MACL,YAAY,KAAK,WAAW,KAAK,IAAI;AAAA,MACrC,UAAU,KAAK,SAAS,KAAK,IAAI;AAAA,MACjC,WAAW,KAAK,iBAAiB;AAAA,IACnC;AAAA,EACF;AAAA,EAEQ,WAAiB;AACvB,SAAK,iBAAiB,KAAK,UAAU;AAAA,EACvC;AAAA,EAEQ,aAAgD;AACtD,UAAM,WAAW,KAAK,UAAU,KAAK;AAErC,QAAI,CAAC;AACH,aAAO,4BAAc,OAAO;AAAA,QAC1B,MAAM,2BAAa;AAAA,QACnB,SAAS;AAAA,MACX,CAAC;AAEH,WAAO,KAAK,OAAO,WAAW,QAAQ;AAAA,EACxC;AACF;AAtCa,aACK,KAAK;;;ACHhB,IAAM,mBAAmB;AAEzB,IAAM,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,EACX;AACF;;;ACTO,IAAM,sBAAuE;AAAA,EAClF;AAAA,EACA,QAAQ,CAAC,UAAU,WAAW,IAAI,aAAa,kBAAkB,UAAU,MAAM;AAAA,EACjF,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,cAAc,CAAC;AACjB;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BasePluginConfig, EventHook, BasePlugin, PluginRegistry, PluginManifest, PluginPackage } from '@embedpdf/core';
|
|
2
|
+
import { Task, PdfErrorReason, PdfEngine } from '@embedpdf/models';
|
|
3
|
+
|
|
4
|
+
interface ExportPluginConfig extends BasePluginConfig {
|
|
5
|
+
}
|
|
6
|
+
interface ExportCapability {
|
|
7
|
+
saveAsCopy: () => Task<ArrayBuffer, PdfErrorReason>;
|
|
8
|
+
download: () => void;
|
|
9
|
+
onRequest: EventHook<'download'>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare class ExportPlugin extends BasePlugin<ExportPluginConfig, ExportCapability> {
|
|
13
|
+
static readonly id: "export";
|
|
14
|
+
private readonly downloadRequest$;
|
|
15
|
+
private engine;
|
|
16
|
+
constructor(id: string, registry: PluginRegistry, engine: PdfEngine);
|
|
17
|
+
initialize(_: ExportPluginConfig): Promise<void>;
|
|
18
|
+
protected buildCapability(): ExportCapability;
|
|
19
|
+
private download;
|
|
20
|
+
private saveAsCopy;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare const EXPORT_PLUGIN_ID = "export";
|
|
24
|
+
declare const manifest: PluginManifest<ExportPluginConfig>;
|
|
25
|
+
|
|
26
|
+
declare const ExportPluginPackage: PluginPackage<ExportPlugin, ExportPluginConfig>;
|
|
27
|
+
|
|
28
|
+
export { EXPORT_PLUGIN_ID, type ExportCapability, ExportPlugin, type ExportPluginConfig, ExportPluginPackage, manifest };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BasePluginConfig, EventHook, BasePlugin, PluginRegistry, PluginManifest, PluginPackage } from '@embedpdf/core';
|
|
2
|
+
import { Task, PdfErrorReason, PdfEngine } from '@embedpdf/models';
|
|
3
|
+
|
|
4
|
+
interface ExportPluginConfig extends BasePluginConfig {
|
|
5
|
+
}
|
|
6
|
+
interface ExportCapability {
|
|
7
|
+
saveAsCopy: () => Task<ArrayBuffer, PdfErrorReason>;
|
|
8
|
+
download: () => void;
|
|
9
|
+
onRequest: EventHook<'download'>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare class ExportPlugin extends BasePlugin<ExportPluginConfig, ExportCapability> {
|
|
13
|
+
static readonly id: "export";
|
|
14
|
+
private readonly downloadRequest$;
|
|
15
|
+
private engine;
|
|
16
|
+
constructor(id: string, registry: PluginRegistry, engine: PdfEngine);
|
|
17
|
+
initialize(_: ExportPluginConfig): Promise<void>;
|
|
18
|
+
protected buildCapability(): ExportCapability;
|
|
19
|
+
private download;
|
|
20
|
+
private saveAsCopy;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare const EXPORT_PLUGIN_ID = "export";
|
|
24
|
+
declare const manifest: PluginManifest<ExportPluginConfig>;
|
|
25
|
+
|
|
26
|
+
declare const ExportPluginPackage: PluginPackage<ExportPlugin, ExportPluginConfig>;
|
|
27
|
+
|
|
28
|
+
export { EXPORT_PLUGIN_ID, type ExportCapability, ExportPlugin, type ExportPluginConfig, ExportPluginPackage, manifest };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// src/lib/export-plugin.ts
|
|
2
|
+
import { BasePlugin, createEmitter } from "@embedpdf/core";
|
|
3
|
+
import { PdfErrorCode, PdfTaskHelper } from "@embedpdf/models";
|
|
4
|
+
var ExportPlugin = class extends BasePlugin {
|
|
5
|
+
constructor(id, registry, engine) {
|
|
6
|
+
super(id, registry);
|
|
7
|
+
this.downloadRequest$ = createEmitter();
|
|
8
|
+
this.engine = engine;
|
|
9
|
+
}
|
|
10
|
+
async initialize(_) {
|
|
11
|
+
}
|
|
12
|
+
buildCapability() {
|
|
13
|
+
return {
|
|
14
|
+
saveAsCopy: this.saveAsCopy.bind(this),
|
|
15
|
+
download: this.download.bind(this),
|
|
16
|
+
onRequest: this.downloadRequest$.on
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
download() {
|
|
20
|
+
this.downloadRequest$.emit("download");
|
|
21
|
+
}
|
|
22
|
+
saveAsCopy() {
|
|
23
|
+
const document = this.coreState.core.document;
|
|
24
|
+
if (!document)
|
|
25
|
+
return PdfTaskHelper.reject({
|
|
26
|
+
code: PdfErrorCode.DocNotOpen,
|
|
27
|
+
message: "Document not found"
|
|
28
|
+
});
|
|
29
|
+
return this.engine.saveAsCopy(document);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
ExportPlugin.id = "export";
|
|
33
|
+
|
|
34
|
+
// src/lib/manifest.ts
|
|
35
|
+
var EXPORT_PLUGIN_ID = "export";
|
|
36
|
+
var manifest = {
|
|
37
|
+
id: EXPORT_PLUGIN_ID,
|
|
38
|
+
name: "Export Plugin",
|
|
39
|
+
version: "1.0.0",
|
|
40
|
+
provides: ["export"],
|
|
41
|
+
requires: [],
|
|
42
|
+
optional: [],
|
|
43
|
+
defaultConfig: {
|
|
44
|
+
enabled: true
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/lib/index.ts
|
|
49
|
+
var ExportPluginPackage = {
|
|
50
|
+
manifest,
|
|
51
|
+
create: (registry, engine) => new ExportPlugin(EXPORT_PLUGIN_ID, registry, engine),
|
|
52
|
+
reducer: () => {
|
|
53
|
+
},
|
|
54
|
+
initialState: {}
|
|
55
|
+
};
|
|
56
|
+
export {
|
|
57
|
+
EXPORT_PLUGIN_ID,
|
|
58
|
+
ExportPlugin,
|
|
59
|
+
ExportPluginPackage,
|
|
60
|
+
manifest
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/export-plugin.ts","../src/lib/manifest.ts","../src/lib/index.ts"],"sourcesContent":["import { BasePlugin, createEmitter, PluginRegistry } from '@embedpdf/core';\nimport { PdfEngine, PdfErrorCode, PdfErrorReason, PdfTaskHelper, Task } from '@embedpdf/models';\n\nimport { 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\n private engine: PdfEngine;\n\n constructor(id: string, registry: PluginRegistry, engine: PdfEngine) {\n super(id, registry);\n\n this.engine = engine;\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 onRequest: this.downloadRequest$.on,\n };\n }\n\n private download(): void {\n this.downloadRequest$.emit('download');\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 },\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, engine) => new ExportPlugin(EXPORT_PLUGIN_ID, registry, engine),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './export-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"mappings":";AAAA,SAAS,YAAY,qBAAqC;AAC1D,SAAoB,cAA8B,qBAA2B;AAItE,IAAM,eAAN,cAA2B,WAAiD;AAAA,EAOjF,YAAY,IAAY,UAA0B,QAAmB;AACnE,UAAM,IAAI,QAAQ;AALpB,SAAiB,mBAAmB,cAA0B;AAO5D,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,MAAM,WAAW,GAAsC;AAAA,EAAC;AAAA,EAE9C,kBAAoC;AAC5C,WAAO;AAAA,MACL,YAAY,KAAK,WAAW,KAAK,IAAI;AAAA,MACrC,UAAU,KAAK,SAAS,KAAK,IAAI;AAAA,MACjC,WAAW,KAAK,iBAAiB;AAAA,IACnC;AAAA,EACF;AAAA,EAEQ,WAAiB;AACvB,SAAK,iBAAiB,KAAK,UAAU;AAAA,EACvC;AAAA,EAEQ,aAAgD;AACtD,UAAM,WAAW,KAAK,UAAU,KAAK;AAErC,QAAI,CAAC;AACH,aAAO,cAAc,OAAO;AAAA,QAC1B,MAAM,aAAa;AAAA,QACnB,SAAS;AAAA,MACX,CAAC;AAEH,WAAO,KAAK,OAAO,WAAW,QAAQ;AAAA,EACxC;AACF;AAtCa,aACK,KAAK;;;ACHhB,IAAM,mBAAmB;AAEzB,IAAM,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,EACX;AACF;;;ACTO,IAAM,sBAAuE;AAAA,EAClF;AAAA,EACA,QAAQ,CAAC,UAAU,WAAW,IAAI,aAAa,kBAAkB,UAAU,MAAM;AAAA,EACjF,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,cAAc,CAAC;AACjB;","names":[]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/preact/index.ts
|
|
21
|
+
var preact_exports = {};
|
|
22
|
+
__export(preact_exports, {
|
|
23
|
+
Download: () => Download,
|
|
24
|
+
useExport: () => useExport,
|
|
25
|
+
useExportCapability: () => useExportCapability
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(preact_exports);
|
|
28
|
+
|
|
29
|
+
// src/preact/hooks/use-export.ts
|
|
30
|
+
var import_preact = require("@embedpdf/core/preact");
|
|
31
|
+
var import_plugin_export = require("@embedpdf/plugin-export");
|
|
32
|
+
var useExport = () => (0, import_preact.usePlugin)(import_plugin_export.ExportPlugin.id);
|
|
33
|
+
var useExportCapability = () => (0, import_preact.useCapability)(import_plugin_export.ExportPlugin.id);
|
|
34
|
+
|
|
35
|
+
// src/preact/components/download.tsx
|
|
36
|
+
var import_models = require("@embedpdf/models");
|
|
37
|
+
var import_hooks = require("preact/hooks");
|
|
38
|
+
var import_jsx_runtime = require("preact/jsx-runtime");
|
|
39
|
+
function Download() {
|
|
40
|
+
const { provides: exportCapability } = useExportCapability();
|
|
41
|
+
const ref = (0, import_hooks.useRef)(null);
|
|
42
|
+
(0, import_hooks.useEffect)(() => {
|
|
43
|
+
if (!exportCapability) return;
|
|
44
|
+
const unsub = exportCapability.onRequest(async (action) => {
|
|
45
|
+
if (action === "download") {
|
|
46
|
+
const el = ref.current;
|
|
47
|
+
if (!el) return;
|
|
48
|
+
const task = exportCapability.saveAsCopy();
|
|
49
|
+
task.wait((buffer) => {
|
|
50
|
+
const url = URL.createObjectURL(new Blob([buffer]));
|
|
51
|
+
el.href = url;
|
|
52
|
+
el.download = "document.pdf";
|
|
53
|
+
el.click();
|
|
54
|
+
URL.revokeObjectURL(url);
|
|
55
|
+
}, import_models.ignore);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return unsub;
|
|
59
|
+
}, [exportCapability]);
|
|
60
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { style: { display: "none" }, ref });
|
|
61
|
+
}
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
Download,
|
|
65
|
+
useExport,
|
|
66
|
+
useExportCapability
|
|
67
|
+
});
|
|
68
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/preact/index.ts","../../src/preact/hooks/use-export.ts","../../src/preact/components/download.tsx"],"sourcesContent":["export * from './hooks';\nexport * from './components';\n","import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport { ExportPlugin } from '@embedpdf/plugin-export';\n\nexport const useExport = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n","/** @jsxImportSource preact */\nimport { ignore } from '@embedpdf/models';\nimport { useEffect, useRef } from 'preact/hooks';\n\nimport { useExportCapability } from '../hooks';\n\nexport function Download() {\n const { provides: exportCapability } = useExportCapability();\n const ref = useRef<HTMLAnchorElement>(null);\n\n useEffect(() => {\n if (!exportCapability) return;\n\n const unsub = exportCapability.onRequest(async (action) => {\n if (action === 'download') {\n const el = ref.current;\n if (!el) return;\n\n const task = exportCapability.saveAsCopy();\n task.wait((buffer) => {\n const url = URL.createObjectURL(new Blob([buffer]));\n el.href = url;\n el.download = 'document.pdf';\n el.click();\n URL.revokeObjectURL(url);\n }, ignore);\n }\n });\n\n return unsub;\n }, [exportCapability]);\n\n return <a style={{ display: 'none' }} ref={ref} />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyC;AACzC,2BAA6B;AAEtB,IAAM,YAAY,UAAM,yBAAwB,kCAAa,EAAE;AAC/D,IAAM,sBAAsB,UAAM,6BAA4B,kCAAa,EAAE;;;ACHpF,oBAAuB;AACvB,mBAAkC;AA8BzB;AA1BF,SAAS,WAAW;AACzB,QAAM,EAAE,UAAU,iBAAiB,IAAI,oBAAoB;AAC3D,QAAM,UAAM,qBAA0B,IAAI;AAE1C,8BAAU,MAAM;AACd,QAAI,CAAC,iBAAkB;AAEvB,UAAM,QAAQ,iBAAiB,UAAU,OAAO,WAAW;AACzD,UAAI,WAAW,YAAY;AACzB,cAAM,KAAK,IAAI;AACf,YAAI,CAAC,GAAI;AAET,cAAM,OAAO,iBAAiB,WAAW;AACzC,aAAK,KAAK,CAAC,WAAW;AACpB,gBAAM,MAAM,IAAI,gBAAgB,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;AAClD,aAAG,OAAO;AACV,aAAG,WAAW;AACd,aAAG,MAAM;AACT,cAAI,gBAAgB,GAAG;AAAA,QACzB,GAAG,oBAAM;AAAA,MACX;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT,GAAG,CAAC,gBAAgB,CAAC;AAErB,SAAO,4CAAC,OAAE,OAAO,EAAE,SAAS,OAAO,GAAG,KAAU;AAClD;","names":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as _embedpdf_plugin_export from '@embedpdf/plugin-export';
|
|
2
|
+
import { ExportPlugin } from '@embedpdf/plugin-export';
|
|
3
|
+
import * as preact from 'preact';
|
|
4
|
+
|
|
5
|
+
declare const useExport: () => {
|
|
6
|
+
plugin: ExportPlugin | null;
|
|
7
|
+
isLoading: boolean;
|
|
8
|
+
ready: Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
declare const useExportCapability: () => {
|
|
11
|
+
provides: Readonly<_embedpdf_plugin_export.ExportCapability> | null;
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
ready: Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
declare function Download(): preact.JSX.Element;
|
|
17
|
+
|
|
18
|
+
export { Download, useExport, useExportCapability };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as _embedpdf_plugin_export from '@embedpdf/plugin-export';
|
|
2
|
+
import { ExportPlugin } from '@embedpdf/plugin-export';
|
|
3
|
+
import * as preact from 'preact';
|
|
4
|
+
|
|
5
|
+
declare const useExport: () => {
|
|
6
|
+
plugin: ExportPlugin | null;
|
|
7
|
+
isLoading: boolean;
|
|
8
|
+
ready: Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
declare const useExportCapability: () => {
|
|
11
|
+
provides: Readonly<_embedpdf_plugin_export.ExportCapability> | null;
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
ready: Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
declare function Download(): preact.JSX.Element;
|
|
17
|
+
|
|
18
|
+
export { Download, useExport, useExportCapability };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/preact/hooks/use-export.ts
|
|
2
|
+
import { useCapability, usePlugin } from "@embedpdf/core/preact";
|
|
3
|
+
import { ExportPlugin } from "@embedpdf/plugin-export";
|
|
4
|
+
var useExport = () => usePlugin(ExportPlugin.id);
|
|
5
|
+
var useExportCapability = () => useCapability(ExportPlugin.id);
|
|
6
|
+
|
|
7
|
+
// src/preact/components/download.tsx
|
|
8
|
+
import { ignore } from "@embedpdf/models";
|
|
9
|
+
import { useEffect, useRef } from "preact/hooks";
|
|
10
|
+
import { jsx } from "preact/jsx-runtime";
|
|
11
|
+
function Download() {
|
|
12
|
+
const { provides: exportCapability } = useExportCapability();
|
|
13
|
+
const ref = useRef(null);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!exportCapability) return;
|
|
16
|
+
const unsub = exportCapability.onRequest(async (action) => {
|
|
17
|
+
if (action === "download") {
|
|
18
|
+
const el = ref.current;
|
|
19
|
+
if (!el) return;
|
|
20
|
+
const task = exportCapability.saveAsCopy();
|
|
21
|
+
task.wait((buffer) => {
|
|
22
|
+
const url = URL.createObjectURL(new Blob([buffer]));
|
|
23
|
+
el.href = url;
|
|
24
|
+
el.download = "document.pdf";
|
|
25
|
+
el.click();
|
|
26
|
+
URL.revokeObjectURL(url);
|
|
27
|
+
}, ignore);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return unsub;
|
|
31
|
+
}, [exportCapability]);
|
|
32
|
+
return /* @__PURE__ */ jsx("a", { style: { display: "none" }, ref });
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
Download,
|
|
36
|
+
useExport,
|
|
37
|
+
useExportCapability
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/preact/hooks/use-export.ts","../../src/preact/components/download.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport { ExportPlugin } from '@embedpdf/plugin-export';\n\nexport const useExport = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n","/** @jsxImportSource preact */\nimport { ignore } from '@embedpdf/models';\nimport { useEffect, useRef } from 'preact/hooks';\n\nimport { useExportCapability } from '../hooks';\n\nexport function Download() {\n const { provides: exportCapability } = useExportCapability();\n const ref = useRef<HTMLAnchorElement>(null);\n\n useEffect(() => {\n if (!exportCapability) return;\n\n const unsub = exportCapability.onRequest(async (action) => {\n if (action === 'download') {\n const el = ref.current;\n if (!el) return;\n\n const task = exportCapability.saveAsCopy();\n task.wait((buffer) => {\n const url = URL.createObjectURL(new Blob([buffer]));\n el.href = url;\n el.download = 'document.pdf';\n el.click();\n URL.revokeObjectURL(url);\n }, ignore);\n }\n });\n\n return unsub;\n }, [exportCapability]);\n\n return <a style={{ display: 'none' }} ref={ref} />;\n}\n"],"mappings":";AAAA,SAAS,eAAe,iBAAiB;AACzC,SAAS,oBAAoB;AAEtB,IAAM,YAAY,MAAM,UAAwB,aAAa,EAAE;AAC/D,IAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;;;ACHpF,SAAS,cAAc;AACvB,SAAS,WAAW,cAAc;AA8BzB;AA1BF,SAAS,WAAW;AACzB,QAAM,EAAE,UAAU,iBAAiB,IAAI,oBAAoB;AAC3D,QAAM,MAAM,OAA0B,IAAI;AAE1C,YAAU,MAAM;AACd,QAAI,CAAC,iBAAkB;AAEvB,UAAM,QAAQ,iBAAiB,UAAU,OAAO,WAAW;AACzD,UAAI,WAAW,YAAY;AACzB,cAAM,KAAK,IAAI;AACf,YAAI,CAAC,GAAI;AAET,cAAM,OAAO,iBAAiB,WAAW;AACzC,aAAK,KAAK,CAAC,WAAW;AACpB,gBAAM,MAAM,IAAI,gBAAgB,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;AAClD,aAAG,OAAO;AACV,aAAG,WAAW;AACd,aAAG,MAAM;AACT,cAAI,gBAAgB,GAAG;AAAA,QACzB,GAAG,MAAM;AAAA,MACX;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT,GAAG,CAAC,gBAAgB,CAAC;AAErB,SAAO,oBAAC,OAAE,OAAO,EAAE,SAAS,OAAO,GAAG,KAAU;AAClD;","names":[]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/react/index.ts
|
|
21
|
+
var react_exports = {};
|
|
22
|
+
__export(react_exports, {
|
|
23
|
+
Download: () => Download,
|
|
24
|
+
useExport: () => useExport,
|
|
25
|
+
useExportCapability: () => useExportCapability
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(react_exports);
|
|
28
|
+
|
|
29
|
+
// src/react/hooks/use-export.ts
|
|
30
|
+
var import_react = require("@embedpdf/core/react");
|
|
31
|
+
var import_plugin_export = require("@embedpdf/plugin-export");
|
|
32
|
+
var useExport = () => (0, import_react.usePlugin)(import_plugin_export.ExportPlugin.id);
|
|
33
|
+
var useExportCapability = () => (0, import_react.useCapability)(import_plugin_export.ExportPlugin.id);
|
|
34
|
+
|
|
35
|
+
// src/react/component/download.tsx
|
|
36
|
+
var import_models = require("@embedpdf/models");
|
|
37
|
+
var import_react2 = require("react");
|
|
38
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
39
|
+
function Download() {
|
|
40
|
+
const { provides: exportCapability } = useExportCapability();
|
|
41
|
+
const ref = (0, import_react2.useRef)(null);
|
|
42
|
+
(0, import_react2.useEffect)(() => {
|
|
43
|
+
if (!exportCapability) return;
|
|
44
|
+
const unsub = exportCapability.onRequest(async (action) => {
|
|
45
|
+
if (action === "download") {
|
|
46
|
+
const el = ref.current;
|
|
47
|
+
if (!el) return;
|
|
48
|
+
const task = exportCapability.saveAsCopy();
|
|
49
|
+
task.wait((buffer) => {
|
|
50
|
+
const url = URL.createObjectURL(new Blob([buffer]));
|
|
51
|
+
el.href = url;
|
|
52
|
+
el.download = "document.pdf";
|
|
53
|
+
el.click();
|
|
54
|
+
URL.revokeObjectURL(url);
|
|
55
|
+
}, import_models.ignore);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return unsub;
|
|
59
|
+
}, [exportCapability]);
|
|
60
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { style: { display: "none" }, ref });
|
|
61
|
+
}
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
Download,
|
|
65
|
+
useExport,
|
|
66
|
+
useExportCapability
|
|
67
|
+
});
|
|
68
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/react/index.ts","../../src/react/hooks/use-export.ts","../../src/react/component/download.tsx"],"sourcesContent":["export * from './hooks';\nexport * from './component';\n","import { useCapability, usePlugin } from '@embedpdf/core/react';\nimport { ExportPlugin } from '@embedpdf/plugin-export';\n\nexport const useExport = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n","import { ignore } from '@embedpdf/models';\nimport { useEffect, useRef } from 'react';\n\nimport { useExportCapability } from '../hooks';\n\nexport function Download() {\n const { provides: exportCapability } = useExportCapability();\n const ref = useRef<HTMLAnchorElement>(null);\n\n useEffect(() => {\n if (!exportCapability) return;\n\n const unsub = exportCapability.onRequest(async (action) => {\n if (action === 'download') {\n const el = ref.current;\n if (!el) return;\n\n const task = exportCapability.saveAsCopy();\n task.wait((buffer) => {\n const url = URL.createObjectURL(new Blob([buffer]));\n el.href = url;\n el.download = 'document.pdf';\n el.click();\n URL.revokeObjectURL(url);\n }, ignore);\n }\n });\n\n return unsub;\n }, [exportCapability]);\n\n return <a style={{ display: 'none' }} ref={ref} />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAyC;AACzC,2BAA6B;AAEtB,IAAM,YAAY,UAAM,wBAAwB,kCAAa,EAAE;AAC/D,IAAM,sBAAsB,UAAM,4BAA4B,kCAAa,EAAE;;;ACJpF,oBAAuB;AACvB,IAAAA,gBAAkC;AA8BzB;AA1BF,SAAS,WAAW;AACzB,QAAM,EAAE,UAAU,iBAAiB,IAAI,oBAAoB;AAC3D,QAAM,UAAM,sBAA0B,IAAI;AAE1C,+BAAU,MAAM;AACd,QAAI,CAAC,iBAAkB;AAEvB,UAAM,QAAQ,iBAAiB,UAAU,OAAO,WAAW;AACzD,UAAI,WAAW,YAAY;AACzB,cAAM,KAAK,IAAI;AACf,YAAI,CAAC,GAAI;AAET,cAAM,OAAO,iBAAiB,WAAW;AACzC,aAAK,KAAK,CAAC,WAAW;AACpB,gBAAM,MAAM,IAAI,gBAAgB,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;AAClD,aAAG,OAAO;AACV,aAAG,WAAW;AACd,aAAG,MAAM;AACT,cAAI,gBAAgB,GAAG;AAAA,QACzB,GAAG,oBAAM;AAAA,MACX;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT,GAAG,CAAC,gBAAgB,CAAC;AAErB,SAAO,4CAAC,OAAE,OAAO,EAAE,SAAS,OAAO,GAAG,KAAU;AAClD;","names":["import_react"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as _embedpdf_plugin_export from '@embedpdf/plugin-export';
|
|
2
|
+
import { ExportPlugin } from '@embedpdf/plugin-export';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
declare const useExport: () => {
|
|
6
|
+
plugin: ExportPlugin | null;
|
|
7
|
+
isLoading: boolean;
|
|
8
|
+
ready: Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
declare const useExportCapability: () => {
|
|
11
|
+
provides: Readonly<_embedpdf_plugin_export.ExportCapability> | null;
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
ready: Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
declare function Download(): react_jsx_runtime.JSX.Element;
|
|
17
|
+
|
|
18
|
+
export { Download, useExport, useExportCapability };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as _embedpdf_plugin_export from '@embedpdf/plugin-export';
|
|
2
|
+
import { ExportPlugin } from '@embedpdf/plugin-export';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
declare const useExport: () => {
|
|
6
|
+
plugin: ExportPlugin | null;
|
|
7
|
+
isLoading: boolean;
|
|
8
|
+
ready: Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
declare const useExportCapability: () => {
|
|
11
|
+
provides: Readonly<_embedpdf_plugin_export.ExportCapability> | null;
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
ready: Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
declare function Download(): react_jsx_runtime.JSX.Element;
|
|
17
|
+
|
|
18
|
+
export { Download, useExport, useExportCapability };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/react/hooks/use-export.ts
|
|
2
|
+
import { useCapability, usePlugin } from "@embedpdf/core/react";
|
|
3
|
+
import { ExportPlugin } from "@embedpdf/plugin-export";
|
|
4
|
+
var useExport = () => usePlugin(ExportPlugin.id);
|
|
5
|
+
var useExportCapability = () => useCapability(ExportPlugin.id);
|
|
6
|
+
|
|
7
|
+
// src/react/component/download.tsx
|
|
8
|
+
import { ignore } from "@embedpdf/models";
|
|
9
|
+
import { useEffect, useRef } from "react";
|
|
10
|
+
import { jsx } from "react/jsx-runtime";
|
|
11
|
+
function Download() {
|
|
12
|
+
const { provides: exportCapability } = useExportCapability();
|
|
13
|
+
const ref = useRef(null);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!exportCapability) return;
|
|
16
|
+
const unsub = exportCapability.onRequest(async (action) => {
|
|
17
|
+
if (action === "download") {
|
|
18
|
+
const el = ref.current;
|
|
19
|
+
if (!el) return;
|
|
20
|
+
const task = exportCapability.saveAsCopy();
|
|
21
|
+
task.wait((buffer) => {
|
|
22
|
+
const url = URL.createObjectURL(new Blob([buffer]));
|
|
23
|
+
el.href = url;
|
|
24
|
+
el.download = "document.pdf";
|
|
25
|
+
el.click();
|
|
26
|
+
URL.revokeObjectURL(url);
|
|
27
|
+
}, ignore);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return unsub;
|
|
31
|
+
}, [exportCapability]);
|
|
32
|
+
return /* @__PURE__ */ jsx("a", { style: { display: "none" }, ref });
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
Download,
|
|
36
|
+
useExport,
|
|
37
|
+
useExportCapability
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/react/hooks/use-export.ts","../../src/react/component/download.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/react';\nimport { ExportPlugin } from '@embedpdf/plugin-export';\n\nexport const useExport = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n","import { ignore } from '@embedpdf/models';\nimport { useEffect, useRef } from 'react';\n\nimport { useExportCapability } from '../hooks';\n\nexport function Download() {\n const { provides: exportCapability } = useExportCapability();\n const ref = useRef<HTMLAnchorElement>(null);\n\n useEffect(() => {\n if (!exportCapability) return;\n\n const unsub = exportCapability.onRequest(async (action) => {\n if (action === 'download') {\n const el = ref.current;\n if (!el) return;\n\n const task = exportCapability.saveAsCopy();\n task.wait((buffer) => {\n const url = URL.createObjectURL(new Blob([buffer]));\n el.href = url;\n el.download = 'document.pdf';\n el.click();\n URL.revokeObjectURL(url);\n }, ignore);\n }\n });\n\n return unsub;\n }, [exportCapability]);\n\n return <a style={{ display: 'none' }} ref={ref} />;\n}\n"],"mappings":";AAAA,SAAS,eAAe,iBAAiB;AACzC,SAAS,oBAAoB;AAEtB,IAAM,YAAY,MAAM,UAAwB,aAAa,EAAE;AAC/D,IAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;;;ACJpF,SAAS,cAAc;AACvB,SAAS,WAAW,cAAc;AA8BzB;AA1BF,SAAS,WAAW;AACzB,QAAM,EAAE,UAAU,iBAAiB,IAAI,oBAAoB;AAC3D,QAAM,MAAM,OAA0B,IAAI;AAE1C,YAAU,MAAM;AACd,QAAI,CAAC,iBAAkB;AAEvB,UAAM,QAAQ,iBAAiB,UAAU,OAAO,WAAW;AACzD,UAAI,WAAW,YAAY;AACzB,cAAM,KAAK,IAAI;AACf,YAAI,CAAC,GAAI;AAET,cAAM,OAAO,iBAAiB,WAAW;AACzC,aAAK,KAAK,CAAC,WAAW;AACpB,gBAAM,MAAM,IAAI,gBAAgB,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;AAClD,aAAG,OAAO;AACV,aAAG,WAAW;AACd,aAAG,MAAM;AACT,cAAI,gBAAgB,GAAG;AAAA,QACzB,GAAG,MAAM;AAAA,MACX;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT,GAAG,CAAC,gBAAgB,CAAC;AAErB,SAAO,oBAAC,OAAE,OAAO,EAAE,SAAS,OAAO,GAAG,KAAU;AAClD;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@embedpdf/plugin-export",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
},
|
|
14
|
+
"./preact": {
|
|
15
|
+
"types": "./dist/preact/index.d.ts",
|
|
16
|
+
"import": "./dist/preact/index.js",
|
|
17
|
+
"require": "./dist/preact/index.cjs"
|
|
18
|
+
},
|
|
19
|
+
"./react": {
|
|
20
|
+
"types": "./dist/react/index.d.ts",
|
|
21
|
+
"import": "./dist/react/index.js",
|
|
22
|
+
"require": "./dist/react/index.cjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@embedpdf/models": "1.0.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/react": "^18.2.0",
|
|
30
|
+
"tsup": "^8.0.0",
|
|
31
|
+
"typescript": "^5.0.0",
|
|
32
|
+
"@embedpdf/core": "1.0.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"react": ">=16.8.0",
|
|
36
|
+
"react-dom": ">=16.8.0",
|
|
37
|
+
"preact": "^10.26.4",
|
|
38
|
+
"@embedpdf/core": "1.0.0"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"README.md"
|
|
43
|
+
],
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "https://github.com/embedpdf/embed-pdf-viewer",
|
|
47
|
+
"directory": "packages/plugin-download"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://www.embedpdf.com/docs",
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/embedpdf/embed-pdf-viewer/issues"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "PROJECT_CWD=$(pwd) pnpm -w p:build",
|
|
58
|
+
"build:watch": "PROJECT_CWD=$(pwd) pnpm -w p:build:watch",
|
|
59
|
+
"clean": "PROJECT_CWD=$(pwd) pnpm -w p:clean",
|
|
60
|
+
"lint": "PROJECT_CWD=$(pwd) pnpm -w p:lint",
|
|
61
|
+
"lint:fix": "PROJECT_CWD=$(pwd) pnpm -w p:lint:fix",
|
|
62
|
+
"typecheck": "PROJECT_CWD=$(pwd) pnpm -w p:typecheck"
|
|
63
|
+
}
|
|
64
|
+
}
|