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.
@@ -0,0 +1 @@
1
+ export * from "@docxkit/loader/browser";
@@ -0,0 +1 @@
1
+ export * from "@docxkit/loader/browser";
@@ -0,0 +1 @@
1
+ export * from "@docxkit/loader/node";
@@ -0,0 +1,2 @@
1
+ export * from "@docxkit/loader/node";
2
+ export {};
@@ -0,0 +1 @@
1
+ export * from "@docxkit/loader";
package/dist/loader.js ADDED
@@ -0,0 +1 @@
1
+ export * from "@docxkit/loader";
package/dist/mcp.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "@docxkit/mcp";
package/dist/mcp.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "@docxkit/mcp";
2
+ export {};
package/dist/node.d.ts ADDED
@@ -0,0 +1,109 @@
1
+ import { BuiltinPluginMap, DocxBuilder, DocxKitConfig, DocxPlugin, DocxPreset, DocxSchema, DocxTheme, PluginRegistry, StyleSheet, dataUrlToUint8Array } from "@docxkit/core";
2
+ import { academicPreset } from "@docxkit/preset-academic";
3
+ import { classicPreset } from "@docxkit/preset-classic";
4
+ import { modernPreset } from "@docxkit/preset-modern";
5
+ import { minimalTheme } from "@docxkit/theme-minimal";
6
+ import { oceanTheme } from "@docxkit/theme-ocean";
7
+ import { warmTheme } from "@docxkit/theme-warm";
8
+ import { Document } from "docx";
9
+ import { TocOptions, TocOptions as TocOptions$1, tocPlugin } from "@docxkit/plugin-toc";
10
+ import { BadgeOptions, BadgeOptions as BadgeOptions$1, badgePlugin } from "@docxkit/plugin-badge";
11
+ import { QRCodePluginOptions, QRCodePluginOptions as QRCodePluginOptions$1, qrcodePlugin } from "@docxkit/plugin-qrcode";
12
+ import { BarcodeFormat, BarcodeOptions, BarcodeOptions as BarcodeOptions$1, barcodePlugin } from "@docxkit/plugin-barcode";
13
+ import { CalloutOptions, CalloutOptions as CalloutOptions$1, calloutPlugin } from "@docxkit/plugin-callout";
14
+ import { DividerOptions, DividerOptions as DividerOptions$1, dividerPlugin } from "@docxkit/plugin-divider";
15
+ import { InvoiceLineItem, InvoiceOptions, InvoiceOptions as InvoiceOptions$1, InvoiceParty, invoicePlugin } from "@docxkit/plugin-invoice";
16
+ import { TimelineEvent, TimelineOptions, TimelineOptions as TimelineOptions$1, timelinePlugin } from "@docxkit/plugin-timeline";
17
+ import { ChangelogEntry, ChangelogOptions, ChangelogOptions as ChangelogOptions$1, changelogPlugin } from "@docxkit/plugin-changelog";
18
+ import { WatermarkOptions, WatermarkOptions as WatermarkOptions$1, watermarkPlugin } from "@docxkit/plugin-watermark";
19
+ import { CodeBlockOptions, CodeBlockOptions as CodeBlockOptions$1, codeBlockPlugin } from "@docxkit/plugin-code-block";
20
+ import { CoverPageOptions, CoverPageOptions as CoverPageOptions$1, coverPagePlugin } from "@docxkit/plugin-cover-page";
21
+ import { ColAlign, ColFormat, DataTableOptions, DataTableOptions as DataTableOptions$1, dataTablePlugin } from "@docxkit/plugin-data-table";
22
+ import { LetterheadOptions, LetterheadOptions as LetterheadOptions$1, letterheadPlugin } from "@docxkit/plugin-letterhead";
23
+ import { PageNumberOptions, PageNumberOptions as PageNumberOptions$1, pageNumberPlugin } from "@docxkit/plugin-page-number";
24
+ import { PropertyItem, PropertyTableOptions, PropertyTableOptions as PropertyTableOptions$1, propertyTablePlugin } from "@docxkit/plugin-property-table";
25
+ import { AgendaItem, MeetingMinutesOptions, MeetingMinutesOptions as MeetingMinutesOptions$1, meetingMinutesPlugin } from "@docxkit/plugin-meeting-minutes";
26
+ import { SignatureBlockOptions, SignatureBlockOptions as SignatureBlockOptions$1, SignatureParty, signatureBlockPlugin } from "@docxkit/plugin-signature-block";
27
+ import { Readable } from "node:stream";
28
+ import { EChartsPluginOptions } from "@docxkit/plugin-echarts";
29
+ export * from "@docxkit/core";
30
+ //#region src/node/fs.d.ts
31
+ /**
32
+ * Save a compiled document to a file on disk.
33
+ *
34
+ * Streams the generated package to disk without materializing an additional
35
+ * complete output buffer. This function is **Node.js only**.
36
+ *
37
+ * @param doc - — A compiled `docx` `Document` instance
38
+ * @param filename - — Output file path (e.g. `"report.docx"`)
39
+ * @returns A promise that resolves when the file has been written
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * import { saveDocument } from 'docx-kit/node'
44
+ *
45
+ * const doc = await compileDocument({ ... })
46
+ * await saveDocument(doc, 'report.docx')
47
+ * ```
48
+ */
49
+ declare function saveDocument(doc: Document, filename: string): Promise<void>;
50
+ /**
51
+ * Pack a compiled document as a Node.js stream.
52
+ *
53
+ * @param doc - — A compiled `docx` `Document` instance
54
+ * @returns A readable stream containing the DOCX package
55
+ */
56
+ declare function streamDocument(doc: Document): Readable;
57
+ //#endregion
58
+ //#region src/types/plugin-map.d.ts
59
+ declare module '@docxkit/core' {
60
+ interface BuiltinPluginMap {
61
+ badge: BadgeOptions$1;
62
+ barcode: BarcodeOptions$1;
63
+ callout: CalloutOptions$1;
64
+ changelog: ChangelogOptions$1;
65
+ codeBlock: CodeBlockOptions$1;
66
+ coverPage: CoverPageOptions$1;
67
+ dataTable: DataTableOptions$1;
68
+ divider: DividerOptions$1;
69
+ echarts: EChartsPluginOptions;
70
+ invoice: InvoiceOptions$1;
71
+ letterhead: LetterheadOptions$1;
72
+ meetingMinutes: MeetingMinutesOptions$1;
73
+ pageNumber: PageNumberOptions$1;
74
+ propertyTable: PropertyTableOptions$1;
75
+ qrcode: QRCodePluginOptions$1;
76
+ signatureBlock: SignatureBlockOptions$1;
77
+ timeline: TimelineOptions$1;
78
+ toc: TocOptions$1;
79
+ watermark: WatermarkOptions$1;
80
+ }
81
+ }
82
+ //#endregion
83
+ //#region src/node.d.ts
84
+ /**
85
+ * A {@link DocxBuilder} with the Node.js filesystem save adapter installed.
86
+ */
87
+ interface NodeDocxBuilder<TStyles extends StyleSheet = StyleSheet, TPlugins extends PluginRegistry = BuiltinPluginMap & PluginRegistry> extends DocxBuilder<TStyles, TPlugins> {
88
+ /** Save the generated document to the local filesystem. */
89
+ save: (filename: string) => Promise<void>;
90
+ /** Pack the generated document as a Node.js stream. */
91
+ toStream: () => Promise<Readable>;
92
+ use: <TName extends string, TOptions, TRender>(plugin: DocxPlugin<TName, TOptions, TRender>) => NodeDocxBuilder<TStyles, Record<TName, TOptions> & TPlugins>;
93
+ }
94
+ /**
95
+ * Create a fluent document builder with Node.js filesystem saving enabled.
96
+ */
97
+ declare function createDocx<const TStyles extends StyleSheet = StyleSheet>(config?: DocxKitConfig<TStyles>): NodeDocxBuilder<TStyles>;
98
+ /**
99
+ * Render a JSON document schema with Node.js filesystem saving enabled.
100
+ */
101
+ declare function renderDocx<const TStyles extends StyleSheet = StyleSheet>(schema: DocxSchema<TStyles>): Promise<NodeDocxBuilder<TStyles>>;
102
+ declare const BUILTIN_PRESETS: ReadonlyMap<string, DocxPreset>;
103
+ declare const PRESET_LIST: readonly DocxPreset[];
104
+ declare function usePreset(id: string): DocxPreset | undefined;
105
+ declare const BUILTIN_THEMES: ReadonlyMap<string, DocxTheme>;
106
+ declare const THEME_LIST: readonly DocxTheme[];
107
+ declare function useTheme(id: string): DocxTheme | undefined;
108
+ //#endregion
109
+ export { type AgendaItem, BUILTIN_PRESETS, BUILTIN_THEMES, type BadgeOptions, type BarcodeFormat, type BarcodeOptions, type CalloutOptions, type ChangelogEntry, type ChangelogOptions, type CodeBlockOptions, type ColAlign, type ColFormat, type CoverPageOptions, type DataTableOptions, type DividerOptions, type InvoiceLineItem, type InvoiceOptions, type InvoiceParty, type LetterheadOptions, type MeetingMinutesOptions, NodeDocxBuilder, PRESET_LIST, type PageNumberOptions, type PropertyItem, type PropertyTableOptions, type QRCodePluginOptions, type SignatureBlockOptions, type SignatureParty, THEME_LIST, type TimelineEvent, type TimelineOptions, type TocOptions, type WatermarkOptions, academicPreset, badgePlugin, barcodePlugin, calloutPlugin, changelogPlugin, classicPreset, codeBlockPlugin, coverPagePlugin, createDocx, dataTablePlugin, dataUrlToUint8Array, dividerPlugin, invoicePlugin, letterheadPlugin, meetingMinutesPlugin, minimalTheme, modernPreset, oceanTheme, pageNumberPlugin, propertyTablePlugin, qrcodePlugin, renderDocx, saveDocument, signatureBlockPlugin, streamDocument, timelinePlugin, tocPlugin, usePreset, useTheme, warmTheme, watermarkPlugin };
package/dist/node.js ADDED
@@ -0,0 +1,122 @@
1
+ import { createDocx as createDocx$1, dataUrlToUint8Array, renderDocx as renderDocx$1 } from "@docxkit/core";
2
+ import { academicPreset } from "@docxkit/preset-academic";
3
+ import { classicPreset } from "@docxkit/preset-classic";
4
+ import { modernPreset } from "@docxkit/preset-modern";
5
+ import { minimalTheme } from "@docxkit/theme-minimal";
6
+ import { oceanTheme } from "@docxkit/theme-ocean";
7
+ import { warmTheme } from "@docxkit/theme-warm";
8
+ import { Packer } from "docx";
9
+ import { tocPlugin } from "@docxkit/plugin-toc";
10
+ import { badgePlugin } from "@docxkit/plugin-badge";
11
+ import { qrcodePlugin } from "@docxkit/plugin-qrcode";
12
+ import { barcodePlugin } from "@docxkit/plugin-barcode";
13
+ import { calloutPlugin } from "@docxkit/plugin-callout";
14
+ import { dividerPlugin } from "@docxkit/plugin-divider";
15
+ import { invoicePlugin } from "@docxkit/plugin-invoice";
16
+ import { timelinePlugin } from "@docxkit/plugin-timeline";
17
+ import { changelogPlugin } from "@docxkit/plugin-changelog";
18
+ import { watermarkPlugin } from "@docxkit/plugin-watermark";
19
+ import { codeBlockPlugin } from "@docxkit/plugin-code-block";
20
+ import { coverPagePlugin } from "@docxkit/plugin-cover-page";
21
+ import { dataTablePlugin } from "@docxkit/plugin-data-table";
22
+ import { letterheadPlugin } from "@docxkit/plugin-letterhead";
23
+ import { pageNumberPlugin } from "@docxkit/plugin-page-number";
24
+ import { propertyTablePlugin } from "@docxkit/plugin-property-table";
25
+ import { meetingMinutesPlugin } from "@docxkit/plugin-meeting-minutes";
26
+ import { signatureBlockPlugin } from "@docxkit/plugin-signature-block";
27
+ export * from "@docxkit/core";
28
+ //#region src/node/fs.ts
29
+ /**
30
+ * Node.js filesystem utilities for saving documents to disk.
31
+ *
32
+ * @module node/fs
33
+ */
34
+ /**
35
+ * Save a compiled document to a file on disk.
36
+ *
37
+ * Streams the generated package to disk without materializing an additional
38
+ * complete output buffer. This function is **Node.js only**.
39
+ *
40
+ * @param doc - — A compiled `docx` `Document` instance
41
+ * @param filename - — Output file path (e.g. `"report.docx"`)
42
+ * @returns A promise that resolves when the file has been written
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * import { saveDocument } from 'docx-kit/node'
47
+ *
48
+ * const doc = await compileDocument({ ... })
49
+ * await saveDocument(doc, 'report.docx')
50
+ * ```
51
+ */
52
+ async function saveDocument(doc, filename) {
53
+ const [{ createWriteStream }, { pipeline }] = await Promise.all([import("node:fs"), import("node:stream/promises")]);
54
+ await pipeline(streamDocument(doc), createWriteStream(filename));
55
+ }
56
+ /**
57
+ * Pack a compiled document as a Node.js stream.
58
+ *
59
+ * @param doc - — A compiled `docx` `Document` instance
60
+ * @returns A readable stream containing the DOCX package
61
+ */
62
+ function streamDocument(doc) {
63
+ return Packer.toStream(doc);
64
+ }
65
+ //#endregion
66
+ //#region src/node.ts
67
+ /**
68
+ * docx-kit — Node.js platform entry.
69
+ *
70
+ * Import from 'docx-kit/node'.
71
+ *
72
+ * @module docx-kit/node
73
+ * @packageDocumentation
74
+ */
75
+ /**
76
+ * Create a fluent document builder with Node.js filesystem saving enabled.
77
+ */
78
+ function createDocx(config = {}) {
79
+ return attachNodeSave(createDocx$1(config));
80
+ }
81
+ /**
82
+ * Render a JSON document schema with Node.js filesystem saving enabled.
83
+ */
84
+ async function renderDocx(schema) {
85
+ return attachNodeSave(await renderDocx$1(schema));
86
+ }
87
+ function attachNodeSave(builder) {
88
+ const nodeBuilder = builder;
89
+ nodeBuilder.save = async (filename) => {
90
+ await saveDocument(await nodeBuilder.toDocument(), filename);
91
+ };
92
+ nodeBuilder.toStream = async () => streamDocument(await nodeBuilder.toDocument());
93
+ return nodeBuilder;
94
+ }
95
+ const BUILTIN_PRESETS = /* @__PURE__ */ new Map([
96
+ [academicPreset.id, academicPreset],
97
+ [classicPreset.id, classicPreset],
98
+ [modernPreset.id, modernPreset]
99
+ ]);
100
+ const PRESET_LIST = [
101
+ classicPreset,
102
+ modernPreset,
103
+ academicPreset
104
+ ];
105
+ function usePreset(id) {
106
+ return BUILTIN_PRESETS.get(id);
107
+ }
108
+ const BUILTIN_THEMES = /* @__PURE__ */ new Map([
109
+ [minimalTheme.id, minimalTheme],
110
+ [oceanTheme.id, oceanTheme],
111
+ [warmTheme.id, warmTheme]
112
+ ]);
113
+ const THEME_LIST = [
114
+ minimalTheme,
115
+ oceanTheme,
116
+ warmTheme
117
+ ];
118
+ function useTheme(id) {
119
+ return BUILTIN_THEMES.get(id);
120
+ }
121
+ //#endregion
122
+ export { BUILTIN_PRESETS, BUILTIN_THEMES, PRESET_LIST, THEME_LIST, academicPreset, badgePlugin, barcodePlugin, calloutPlugin, changelogPlugin, classicPreset, codeBlockPlugin, coverPagePlugin, createDocx, dataTablePlugin, dataUrlToUint8Array, dividerPlugin, invoicePlugin, letterheadPlugin, meetingMinutesPlugin, minimalTheme, modernPreset, oceanTheme, pageNumberPlugin, propertyTablePlugin, qrcodePlugin, renderDocx, saveDocument, signatureBlockPlugin, streamDocument, timelinePlugin, tocPlugin, usePreset, useTheme, warmTheme, watermarkPlugin };
package/dist/pdk.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "@docxkit/pdk";
package/dist/pdk.js ADDED
@@ -0,0 +1 @@
1
+ export * from "@docxkit/pdk";
@@ -0,0 +1 @@
1
+ export * from "@docxkit/registry";
@@ -0,0 +1,2 @@
1
+ export * from "@docxkit/registry";
2
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "docx-kit",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.4.0",
5
5
  "description": "CSS-like DOCX API Kit — a type-safe, plugin-extensible DOCX generation library built on dolanmiu/docx.",
6
6
  "keywords": [
7
7
  "document",
@@ -21,7 +21,8 @@
21
21
  "homepage": "https://github.com/ntnyq/docx-kit#readme",
22
22
  "repository": {
23
23
  "type": "git",
24
- "url": "ntnyq/docx-kit"
24
+ "url": "https://github.com/ntnyq/docx-kit",
25
+ "directory": "packages/docx-kit"
25
26
  },
26
27
  "bugs": {
27
28
  "url": "https://github.com/ntnyq/docx-kit/issues"
@@ -32,13 +33,41 @@
32
33
  "types": "./dist/browser.d.ts",
33
34
  "default": "./dist/browser.js"
34
35
  },
36
+ "./ai": {
37
+ "types": "./dist/ai.d.ts",
38
+ "default": "./dist/ai.js"
39
+ },
35
40
  "./browser": {
36
41
  "types": "./dist/browser.d.ts",
37
42
  "default": "./dist/browser.js"
38
43
  },
44
+ "./loader": {
45
+ "types": "./dist/loader.d.ts",
46
+ "default": "./dist/loader.js"
47
+ },
48
+ "./loader/browser": {
49
+ "types": "./dist/loader-browser.d.ts",
50
+ "default": "./dist/loader-browser.js"
51
+ },
52
+ "./loader/node": {
53
+ "types": "./dist/loader-node.d.ts",
54
+ "default": "./dist/loader-node.js"
55
+ },
56
+ "./mcp": {
57
+ "types": "./dist/mcp.d.ts",
58
+ "default": "./dist/mcp.js"
59
+ },
39
60
  "./node": {
40
- "types": "./dist/node.d.mts",
41
- "default": "./dist/node.mjs"
61
+ "types": "./dist/node.d.ts",
62
+ "default": "./dist/node.js"
63
+ },
64
+ "./pdk": {
65
+ "types": "./dist/pdk.d.ts",
66
+ "default": "./dist/pdk.js"
67
+ },
68
+ "./registry": {
69
+ "types": "./dist/registry.d.ts",
70
+ "default": "./dist/registry.js"
42
71
  }
43
72
  },
44
73
  "main": "./dist/browser.js",
@@ -51,56 +80,44 @@
51
80
  },
52
81
  "sideEffects": false,
53
82
  "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
- }
68
- },
69
- "dependencies": {
70
83
  "docx": "^9.7.1"
71
84
  },
72
- "devDependencies": {
73
- "@ntnyq/eslint-config": "^6.1.5",
74
- "@ntnyq/prettier-config": "^3.0.1",
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",
80
- "husky": "^9.1.7",
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"
89
- },
90
- "nano-staged": {
91
- "*.{js,ts,mjs,cjs,md,vue,yml,yaml,toml,json}": "eslint --fix",
92
- "*.{css,scss,html}": "prettier -uw"
85
+ "dependencies": {
86
+ "@docxkit/ai": "0.4.0",
87
+ "@docxkit/core": "0.4.0",
88
+ "@docxkit/pdk": "0.4.0",
89
+ "@docxkit/mcp": "0.4.0",
90
+ "@docxkit/plugin-callout": "0.4.0",
91
+ "@docxkit/plugin-badge": "0.4.0",
92
+ "@docxkit/plugin-barcode": "0.4.0",
93
+ "@docxkit/loader": "0.4.0",
94
+ "@docxkit/plugin-changelog": "0.4.0",
95
+ "@docxkit/plugin-code-block": "0.4.0",
96
+ "@docxkit/plugin-cover-page": "0.4.0",
97
+ "@docxkit/plugin-data-table": "0.4.0",
98
+ "@docxkit/plugin-echarts": "0.4.0",
99
+ "@docxkit/plugin-invoice": "0.4.0",
100
+ "@docxkit/plugin-letterhead": "0.4.0",
101
+ "@docxkit/plugin-divider": "0.4.0",
102
+ "@docxkit/plugin-meeting-minutes": "0.4.0",
103
+ "@docxkit/plugin-property-table": "0.4.0",
104
+ "@docxkit/plugin-qrcode": "0.4.0",
105
+ "@docxkit/plugin-page-number": "0.4.0",
106
+ "@docxkit/plugin-signature-block": "0.4.0",
107
+ "@docxkit/plugin-toc": "0.4.0",
108
+ "@docxkit/plugin-timeline": "0.4.0",
109
+ "@docxkit/plugin-watermark": "0.4.0",
110
+ "@docxkit/preset-academic": "0.4.0",
111
+ "@docxkit/preset-classic": "0.4.0",
112
+ "@docxkit/registry": "0.4.0",
113
+ "@docxkit/preset-modern": "0.4.0",
114
+ "@docxkit/renderer": "0.4.0",
115
+ "@docxkit/theme-warm": "0.4.0",
116
+ "@docxkit/theme-minimal": "0.4.0",
117
+ "@docxkit/theme-ocean": "0.4.0"
93
118
  },
94
119
  "scripts": {
95
120
  "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"
121
+ "dev": "tsdown --watch"
105
122
  }
106
123
  }