docx-kit 0.0.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,79 @@
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 };
@@ -0,0 +1,79 @@
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 };
package/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "docx-kit",
3
3
  "type": "module",
4
- "version": "0.0.0",
5
- "packageManager": "pnpm@10.27.0",
6
- "description": "TypeScript library for generating Word (.docx) documents easily with rich content, styles, and intuitive, customizable API.",
4
+ "version": "0.2.0",
5
+ "description": "CSS-like DOCX API Kit — a type-safe, plugin-extensible DOCX generation library built on dolanmiu/docx.",
7
6
  "keywords": [
8
7
  "document",
9
8
  "docx",
@@ -20,19 +19,30 @@
20
19
  "email": "ntnyq13@gmail.com"
21
20
  },
22
21
  "homepage": "https://github.com/ntnyq/docx-kit#readme",
23
- "repository": "ntnyq/docx-kit",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "ntnyq/docx-kit"
25
+ },
24
26
  "bugs": {
25
27
  "url": "https://github.com/ntnyq/docx-kit/issues"
26
28
  },
27
29
  "exports": {
28
30
  "./package.json": "./package.json",
29
31
  ".": {
30
- "types": "./dist/index.d.ts",
31
- "default": "./dist/index.js"
32
+ "types": "./dist/browser.d.ts",
33
+ "default": "./dist/browser.js"
34
+ },
35
+ "./browser": {
36
+ "types": "./dist/browser.d.ts",
37
+ "default": "./dist/browser.js"
38
+ },
39
+ "./node": {
40
+ "types": "./dist/node.d.mts",
41
+ "default": "./dist/node.mjs"
32
42
  }
33
43
  },
34
- "main": "./dist/index.js",
35
- "types": "./dist/index.d.ts",
44
+ "main": "./dist/browser.js",
45
+ "types": "./dist/browser.d.ts",
36
46
  "files": [
37
47
  "dist"
38
48
  ],
@@ -40,40 +50,57 @@
40
50
  "access": "public"
41
51
  },
42
52
  "sideEffects": false,
43
- "scripts": {
44
- "build": "tsdown",
45
- "dev": "tsdown --watch",
46
- "lint": "eslint",
47
- "prepare": "husky",
48
- "prepublishOnly": "pnpm run build",
49
- "release": "run-s release:check release:version",
50
- "release:check": "run-s lint typecheck test",
51
- "release:version": "bumpp",
52
- "test": "vitest",
53
- "typecheck": "tsc --noEmit"
53
+ "peerDependencies": {
54
+ "echarts": ">=5.0.0",
55
+ "highlight.js": ">=11.0.0",
56
+ "qrcode": ">=1.5.0"
57
+ },
58
+ "peerDependenciesMeta": {
59
+ "echarts": {
60
+ "optional": true
61
+ },
62
+ "highlight.js": {
63
+ "optional": true
64
+ },
65
+ "qrcode": {
66
+ "optional": true
67
+ }
54
68
  },
55
69
  "dependencies": {
56
- "@ntnyq/utils": "^0.10.0",
57
- "docx": "^9.5.1",
58
- "echarts": "^6.0.0",
59
- "qrcode": "^1.5.4"
70
+ "docx": "^9.7.1"
60
71
  },
61
72
  "devDependencies": {
62
- "@ntnyq/eslint-config": "^5.9.0",
73
+ "@ntnyq/eslint-config": "^6.1.5",
63
74
  "@ntnyq/prettier-config": "^3.0.1",
64
- "@types/node": "^25.0.3",
65
- "bumpp": "^10.3.2",
66
- "eslint": "^9.39.2",
75
+ "@types/node": "^25.9.2",
76
+ "@types/qrcode": "^1.5.6",
77
+ "bumpp": "^11.1.0",
78
+ "echarts": "^6.1.0",
79
+ "eslint": "^10.4.1",
67
80
  "husky": "^9.1.7",
68
- "nano-staged": "^0.9.0",
69
- "npm-run-all2": "^8.0.4",
70
- "prettier": "^3.7.4",
71
- "tsdown": "^0.19.0-beta.2",
72
- "typescript": "^5.9.3",
73
- "vitest": "^4.0.16"
81
+ "nano-staged": "^1.0.2",
82
+ "npm-run-all2": "^9.0.1",
83
+ "prettier": "^3.8.4",
84
+ "qrcode": "^1.5.4",
85
+ "tsdown": "^0.22.2",
86
+ "typescript": "^6.0.3",
87
+ "vite": "^8.0.16",
88
+ "vitest": "^4.1.8"
74
89
  },
75
90
  "nano-staged": {
76
91
  "*.{js,ts,mjs,cjs,md,vue,yml,yaml,toml,json}": "eslint --fix",
77
92
  "*.{css,scss,html}": "prettier -uw"
93
+ },
94
+ "scripts": {
95
+ "build": "tsdown",
96
+ "dev": "tsdown --watch",
97
+ "docs:build": "pnpm -C docs run build",
98
+ "docs:dev": "pnpm -C docs run dev",
99
+ "lint": "eslint",
100
+ "release": "run-s release:check release:version",
101
+ "release:check": "run-s lint typecheck test",
102
+ "release:version": "bumpp",
103
+ "test": "vitest",
104
+ "typecheck": "tsc --noEmit"
78
105
  }
79
- }
106
+ }
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- //#region src/index.d.ts
2
- declare const msg = "hello world";
3
- declare function greet(): string;
4
- //#endregion
5
- export { greet, msg };
package/dist/index.js DELETED
@@ -1,9 +0,0 @@
1
- //#region src/index.ts
2
- const msg = "hello world";
3
- function greet() {
4
- console.log(msg);
5
- return msg;
6
- }
7
-
8
- //#endregion
9
- export { greet, msg };