docx-kit 0.2.0 → 0.4.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/README.md +10 -531
- package/dist/ai.d.ts +1 -0
- package/dist/ai.js +1 -0
- package/dist/browser.d.ts +65 -1812
- package/dist/browser.js +66 -2354
- package/dist/loader-browser.d.ts +1 -0
- package/dist/loader-browser.js +1 -0
- package/dist/loader-node.d.ts +1 -0
- package/dist/loader-node.js +2 -0
- package/dist/loader.d.ts +1 -0
- package/dist/loader.js +1 -0
- package/dist/mcp.d.ts +1 -0
- package/dist/mcp.js +2 -0
- package/dist/node.d.ts +109 -0
- package/dist/node.js +122 -0
- package/dist/pdk.d.ts +1 -0
- package/dist/pdk.js +1 -0
- package/dist/registry.d.ts +1 -0
- package/dist/registry.js +2 -0
- package/package.json +67 -50
- package/dist/compileDocument-DIFdjo67.mjs +0 -1051
- package/dist/compileDocument-Vy7rz9_8.js +0 -1051
- package/dist/errors-c9CC63Ti.js +0 -63
- package/dist/errors-c9CC63Ti.mjs +0 -63
- package/dist/fs-BuKdtuxB.js +0 -30
- package/dist/fs-DF8ug9Wi.mjs +0 -43
- package/dist/image-CdfLh9GO.js +0 -76
- package/dist/image-CdfLh9GO.mjs +0 -76
- package/dist/node.d.mts +0 -1817
- package/dist/node.mjs +0 -2362
- package/dist/pack-Bkdfq0_u.mjs +0 -79
- package/dist/pack-u3tMQYCL.js +0 -79
package/dist/pack-Bkdfq0_u.mjs
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import "./fs-DF8ug9Wi.mjs";
|
|
2
|
-
import { t as DocxKitError } from "./errors-c9CC63Ti.mjs";
|
|
3
|
-
import { Packer } from "docx";
|
|
4
|
-
//#region src/renderer/pack.ts
|
|
5
|
-
/**
|
|
6
|
-
* Document packaging — converts a `docx` `Document` instance to
|
|
7
|
-
* various output formats (Blob, Buffer, base64, file).
|
|
8
|
-
*
|
|
9
|
-
* These are thin wrappers around the `docx` `Packer` API, with
|
|
10
|
-
* normalization for cross-platform compatibility.
|
|
11
|
-
*
|
|
12
|
-
* @module renderer/pack
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* Pack a document to a base64-encoded string.
|
|
16
|
-
*
|
|
17
|
-
* @param doc - — A compiled `docx` `Document` instance
|
|
18
|
-
* @returns Base64-encoded .docx data
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```ts
|
|
22
|
-
* const doc = await compileDocument({ ... })
|
|
23
|
-
* const b64 = await packToBase64String(doc)
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
async function packToBase64String(doc) {
|
|
27
|
-
try {
|
|
28
|
-
return await Packer.toBase64String(doc);
|
|
29
|
-
} catch (err) {
|
|
30
|
-
throw new DocxKitError("EXPORT_FAILED", "Failed to pack document to base64", err);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Pack a document to a `Blob` (browser-friendly).
|
|
35
|
-
*
|
|
36
|
-
* @param doc - — A compiled `docx` `Document` instance
|
|
37
|
-
* @returns A `Blob` containing the .docx binary
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```ts
|
|
41
|
-
* const blob = await packToBlob(doc)
|
|
42
|
-
* const url = URL.createObjectURL(blob)
|
|
43
|
-
* // trigger download in browser
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
async function packToBlob(doc) {
|
|
47
|
-
try {
|
|
48
|
-
return await Packer.toBlob(doc);
|
|
49
|
-
} catch (err) {
|
|
50
|
-
throw new DocxKitError("EXPORT_FAILED", "Failed to pack document to blob", err);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Pack a document to a `Uint8Array` (browser & Node.js).
|
|
55
|
-
*
|
|
56
|
-
* Normalizes the `Packer.toBuffer()` Node.js Buffer to a
|
|
57
|
-
* standard `Uint8Array` for cross-platform compatibility.
|
|
58
|
-
*
|
|
59
|
-
* @param doc - — A compiled `docx` `Document` instance
|
|
60
|
-
* @returns Raw .docx bytes as `Uint8Array`
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```ts
|
|
64
|
-
* const bytes = await packToBuffer(doc)
|
|
65
|
-
* // In Node.js:
|
|
66
|
-
* import { writeFileSync } from 'node:fs'
|
|
67
|
-
* writeFileSync('output.docx', bytes)
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
async function packToBuffer(doc) {
|
|
71
|
-
try {
|
|
72
|
-
const buffer = await Packer.toBuffer(doc);
|
|
73
|
-
return new Uint8Array(buffer);
|
|
74
|
-
} catch (err) {
|
|
75
|
-
throw new DocxKitError("EXPORT_FAILED", "Failed to pack document to buffer", err);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
//#endregion
|
|
79
|
-
export { packToBase64String, packToBlob, packToBuffer };
|
package/dist/pack-u3tMQYCL.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { t as DocxKitError } from "./errors-c9CC63Ti.js";
|
|
2
|
-
import "./fs-BuKdtuxB.js";
|
|
3
|
-
import { Packer } from "docx";
|
|
4
|
-
//#region src/renderer/pack.ts
|
|
5
|
-
/**
|
|
6
|
-
* Document packaging — converts a `docx` `Document` instance to
|
|
7
|
-
* various output formats (Blob, Buffer, base64, file).
|
|
8
|
-
*
|
|
9
|
-
* These are thin wrappers around the `docx` `Packer` API, with
|
|
10
|
-
* normalization for cross-platform compatibility.
|
|
11
|
-
*
|
|
12
|
-
* @module renderer/pack
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* Pack a document to a base64-encoded string.
|
|
16
|
-
*
|
|
17
|
-
* @param doc - — A compiled `docx` `Document` instance
|
|
18
|
-
* @returns Base64-encoded .docx data
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```ts
|
|
22
|
-
* const doc = await compileDocument({ ... })
|
|
23
|
-
* const b64 = await packToBase64String(doc)
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
async function packToBase64String(doc) {
|
|
27
|
-
try {
|
|
28
|
-
return await Packer.toBase64String(doc);
|
|
29
|
-
} catch (err) {
|
|
30
|
-
throw new DocxKitError("EXPORT_FAILED", "Failed to pack document to base64", err);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Pack a document to a `Blob` (browser-friendly).
|
|
35
|
-
*
|
|
36
|
-
* @param doc - — A compiled `docx` `Document` instance
|
|
37
|
-
* @returns A `Blob` containing the .docx binary
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```ts
|
|
41
|
-
* const blob = await packToBlob(doc)
|
|
42
|
-
* const url = URL.createObjectURL(blob)
|
|
43
|
-
* // trigger download in browser
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
async function packToBlob(doc) {
|
|
47
|
-
try {
|
|
48
|
-
return await Packer.toBlob(doc);
|
|
49
|
-
} catch (err) {
|
|
50
|
-
throw new DocxKitError("EXPORT_FAILED", "Failed to pack document to blob", err);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Pack a document to a `Uint8Array` (browser & Node.js).
|
|
55
|
-
*
|
|
56
|
-
* Normalizes the `Packer.toBuffer()` Node.js Buffer to a
|
|
57
|
-
* standard `Uint8Array` for cross-platform compatibility.
|
|
58
|
-
*
|
|
59
|
-
* @param doc - — A compiled `docx` `Document` instance
|
|
60
|
-
* @returns Raw .docx bytes as `Uint8Array`
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```ts
|
|
64
|
-
* const bytes = await packToBuffer(doc)
|
|
65
|
-
* // In Node.js:
|
|
66
|
-
* import { writeFileSync } from 'node:fs'
|
|
67
|
-
* writeFileSync('output.docx', bytes)
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
async function packToBuffer(doc) {
|
|
71
|
-
try {
|
|
72
|
-
const buffer = await Packer.toBuffer(doc);
|
|
73
|
-
return new Uint8Array(buffer);
|
|
74
|
-
} catch (err) {
|
|
75
|
-
throw new DocxKitError("EXPORT_FAILED", "Failed to pack document to buffer", err);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
//#endregion
|
|
79
|
-
export { packToBase64String, packToBlob, packToBuffer };
|