docx-kit 0.3.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/dist/ai.d.ts +1 -0
- package/dist/ai.js +1 -0
- package/dist/browser.d.ts +3 -2
- package/dist/browser.js +4 -3
- 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 +51 -24
- package/dist/node.js +39 -9
- 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 +47 -46
package/dist/ai.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@docxkit/ai";
|
package/dist/ai.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@docxkit/ai";
|
package/dist/browser.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { DocxPreset, DocxTheme } from "@docxkit/core";
|
|
|
8
8
|
import { TocOptions, TocOptions as TocOptions$1, tocPlugin } from "@docxkit/plugin-toc";
|
|
9
9
|
import { BadgeOptions, BadgeOptions as BadgeOptions$1, badgePlugin } from "@docxkit/plugin-badge";
|
|
10
10
|
import { QRCodePluginOptions, QRCodePluginOptions as QRCodePluginOptions$1, qrcodePlugin } from "@docxkit/plugin-qrcode";
|
|
11
|
+
import { BarcodeFormat, BarcodeOptions, BarcodeOptions as BarcodeOptions$1, barcodePlugin } from "@docxkit/plugin-barcode";
|
|
11
12
|
import { CalloutOptions, CalloutOptions as CalloutOptions$1, calloutPlugin } from "@docxkit/plugin-callout";
|
|
12
13
|
import { DividerOptions, DividerOptions as DividerOptions$1, dividerPlugin } from "@docxkit/plugin-divider";
|
|
13
14
|
import { EChartsPluginOptions, EChartsPluginOptions as EChartsPluginOptions$1, echartsPlugin } from "@docxkit/plugin-echarts";
|
|
@@ -25,11 +26,11 @@ import { AgendaItem, MeetingMinutesOptions, MeetingMinutesOptions as MeetingMinu
|
|
|
25
26
|
import { SignatureBlockOptions, SignatureBlockOptions as SignatureBlockOptions$1, SignatureParty, signatureBlockPlugin } from "@docxkit/plugin-signature-block";
|
|
26
27
|
import { DocxInput, DocxPreview, DocxPreviewOptions, PREVIEW_ERROR_CODES, PreviewErrorCode, RendererKind, createDocxPreview } from "@docxkit/renderer";
|
|
27
28
|
export * from "@docxkit/core";
|
|
28
|
-
|
|
29
29
|
//#region src/types/plugin-map.d.ts
|
|
30
30
|
declare module '@docxkit/core' {
|
|
31
31
|
interface BuiltinPluginMap {
|
|
32
32
|
badge: BadgeOptions$1;
|
|
33
|
+
barcode: BarcodeOptions$1;
|
|
33
34
|
callout: CalloutOptions$1;
|
|
34
35
|
changelog: ChangelogOptions$1;
|
|
35
36
|
codeBlock: CodeBlockOptions$1;
|
|
@@ -85,4 +86,4 @@ declare const THEME_LIST: readonly DocxTheme[];
|
|
|
85
86
|
/** Look up a built-in theme by ID. */
|
|
86
87
|
declare function useTheme(id: string): DocxTheme | undefined;
|
|
87
88
|
//#endregion
|
|
88
|
-
export { type AgendaItem, BUILTIN_PRESETS, BUILTIN_THEMES, type BadgeOptions, type CalloutOptions, type ChangelogEntry, type ChangelogOptions, type CodeBlockOptions, type ColAlign, type ColFormat, type CoverPageOptions, type DataTableOptions, type DividerOptions, type DocxInput, type DocxPreview, type DocxPreviewOptions, type EChartsPluginOptions, type InvoiceLineItem, type InvoiceOptions, type InvoiceParty, type LetterheadOptions, type MeetingMinutesOptions, PRESET_LIST, PREVIEW_ERROR_CODES, type PageNumberOptions, type PreviewErrorCode, type PropertyItem, type PropertyTableOptions, type QRCodePluginOptions, type RendererKind, type SignatureBlockOptions, type SignatureParty, THEME_LIST, type TimelineEvent, type TimelineOptions, type TocOptions, type WatermarkOptions, academicPreset, badgePlugin, calloutPlugin, changelogPlugin, classicPreset, codeBlockPlugin, coverPagePlugin, createDocxPreview, dataTablePlugin, dividerPlugin, echartsPlugin, invoicePlugin, letterheadPlugin, meetingMinutesPlugin, minimalTheme, modernPreset, normalizeImageData, oceanTheme, pageNumberPlugin, propertyTablePlugin, qrcodePlugin, signatureBlockPlugin, timelinePlugin, tocPlugin, usePreset, useTheme, warmTheme, watermarkPlugin };
|
|
89
|
+
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 DocxInput, type DocxPreview, type DocxPreviewOptions, type EChartsPluginOptions, type InvoiceLineItem, type InvoiceOptions, type InvoiceParty, type LetterheadOptions, type MeetingMinutesOptions, PRESET_LIST, PREVIEW_ERROR_CODES, type PageNumberOptions, type PreviewErrorCode, type PropertyItem, type PropertyTableOptions, type QRCodePluginOptions, type RendererKind, type SignatureBlockOptions, type SignatureParty, THEME_LIST, type TimelineEvent, type TimelineOptions, type TocOptions, type WatermarkOptions, academicPreset, badgePlugin, barcodePlugin, calloutPlugin, changelogPlugin, classicPreset, codeBlockPlugin, coverPagePlugin, createDocxPreview, dataTablePlugin, dividerPlugin, echartsPlugin, invoicePlugin, letterheadPlugin, meetingMinutesPlugin, minimalTheme, modernPreset, normalizeImageData, oceanTheme, pageNumberPlugin, propertyTablePlugin, qrcodePlugin, signatureBlockPlugin, timelinePlugin, tocPlugin, usePreset, useTheme, warmTheme, watermarkPlugin };
|
package/dist/browser.js
CHANGED
|
@@ -8,6 +8,7 @@ import "@docxkit/core";
|
|
|
8
8
|
import { tocPlugin } from "@docxkit/plugin-toc";
|
|
9
9
|
import { badgePlugin } from "@docxkit/plugin-badge";
|
|
10
10
|
import { qrcodePlugin } from "@docxkit/plugin-qrcode";
|
|
11
|
+
import { barcodePlugin } from "@docxkit/plugin-barcode";
|
|
11
12
|
import { calloutPlugin } from "@docxkit/plugin-callout";
|
|
12
13
|
import { dividerPlugin } from "@docxkit/plugin-divider";
|
|
13
14
|
import { echartsPlugin } from "@docxkit/plugin-echarts";
|
|
@@ -62,7 +63,7 @@ async function normalizeImageData(data) {
|
|
|
62
63
|
* @packageDocumentation
|
|
63
64
|
*/
|
|
64
65
|
/** All built-in presets, keyed by ID. */
|
|
65
|
-
const BUILTIN_PRESETS = new Map([
|
|
66
|
+
const BUILTIN_PRESETS = /* @__PURE__ */ new Map([
|
|
66
67
|
[academicPreset.id, academicPreset],
|
|
67
68
|
[classicPreset.id, classicPreset],
|
|
68
69
|
[modernPreset.id, modernPreset]
|
|
@@ -78,7 +79,7 @@ function usePreset(id) {
|
|
|
78
79
|
return BUILTIN_PRESETS.get(id);
|
|
79
80
|
}
|
|
80
81
|
/** All built-in themes, keyed by ID. */
|
|
81
|
-
const BUILTIN_THEMES = new Map([
|
|
82
|
+
const BUILTIN_THEMES = /* @__PURE__ */ new Map([
|
|
82
83
|
[minimalTheme.id, minimalTheme],
|
|
83
84
|
[oceanTheme.id, oceanTheme],
|
|
84
85
|
[warmTheme.id, warmTheme]
|
|
@@ -94,4 +95,4 @@ function useTheme(id) {
|
|
|
94
95
|
return BUILTIN_THEMES.get(id);
|
|
95
96
|
}
|
|
96
97
|
//#endregion
|
|
97
|
-
export { BUILTIN_PRESETS, BUILTIN_THEMES, PRESET_LIST, PREVIEW_ERROR_CODES, THEME_LIST, academicPreset, badgePlugin, calloutPlugin, changelogPlugin, classicPreset, codeBlockPlugin, coverPagePlugin, createDocxPreview, dataTablePlugin, dividerPlugin, echartsPlugin, invoicePlugin, letterheadPlugin, meetingMinutesPlugin, minimalTheme, modernPreset, normalizeImageData, oceanTheme, pageNumberPlugin, propertyTablePlugin, qrcodePlugin, signatureBlockPlugin, timelinePlugin, tocPlugin, usePreset, useTheme, warmTheme, watermarkPlugin };
|
|
98
|
+
export { BUILTIN_PRESETS, BUILTIN_THEMES, PRESET_LIST, PREVIEW_ERROR_CODES, THEME_LIST, academicPreset, badgePlugin, barcodePlugin, calloutPlugin, changelogPlugin, classicPreset, codeBlockPlugin, coverPagePlugin, createDocxPreview, dataTablePlugin, dividerPlugin, echartsPlugin, invoicePlugin, letterheadPlugin, meetingMinutesPlugin, minimalTheme, modernPreset, normalizeImageData, oceanTheme, pageNumberPlugin, propertyTablePlugin, qrcodePlugin, signatureBlockPlugin, timelinePlugin, tocPlugin, usePreset, useTheme, warmTheme, watermarkPlugin };
|
|
@@ -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";
|
package/dist/loader.d.ts
ADDED
|
@@ -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
package/dist/node.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import { BuiltinPluginMap, DocxBuilder, DocxKitConfig, DocxPlugin, DocxPreset, DocxSchema, DocxTheme, PluginRegistry, StyleSheet, dataUrlToUint8Array } from "@docxkit/core";
|
|
1
2
|
import { academicPreset } from "@docxkit/preset-academic";
|
|
2
3
|
import { classicPreset } from "@docxkit/preset-classic";
|
|
3
4
|
import { modernPreset } from "@docxkit/preset-modern";
|
|
4
5
|
import { minimalTheme } from "@docxkit/theme-minimal";
|
|
5
6
|
import { oceanTheme } from "@docxkit/theme-ocean";
|
|
6
7
|
import { warmTheme } from "@docxkit/theme-warm";
|
|
7
|
-
import {
|
|
8
|
+
import { Document } from "docx";
|
|
8
9
|
import { TocOptions, TocOptions as TocOptions$1, tocPlugin } from "@docxkit/plugin-toc";
|
|
9
10
|
import { BadgeOptions, BadgeOptions as BadgeOptions$1, badgePlugin } from "@docxkit/plugin-badge";
|
|
10
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";
|
|
11
13
|
import { CalloutOptions, CalloutOptions as CalloutOptions$1, calloutPlugin } from "@docxkit/plugin-callout";
|
|
12
14
|
import { DividerOptions, DividerOptions as DividerOptions$1, dividerPlugin } from "@docxkit/plugin-divider";
|
|
13
15
|
import { InvoiceLineItem, InvoiceOptions, InvoiceOptions as InvoiceOptions$1, InvoiceParty, invoicePlugin } from "@docxkit/plugin-invoice";
|
|
@@ -19,17 +21,45 @@ import { CoverPageOptions, CoverPageOptions as CoverPageOptions$1, coverPagePlug
|
|
|
19
21
|
import { ColAlign, ColFormat, DataTableOptions, DataTableOptions as DataTableOptions$1, dataTablePlugin } from "@docxkit/plugin-data-table";
|
|
20
22
|
import { LetterheadOptions, LetterheadOptions as LetterheadOptions$1, letterheadPlugin } from "@docxkit/plugin-letterhead";
|
|
21
23
|
import { PageNumberOptions, PageNumberOptions as PageNumberOptions$1, pageNumberPlugin } from "@docxkit/plugin-page-number";
|
|
22
|
-
import { Document } from "docx";
|
|
23
24
|
import { PropertyItem, PropertyTableOptions, PropertyTableOptions as PropertyTableOptions$1, propertyTablePlugin } from "@docxkit/plugin-property-table";
|
|
24
25
|
import { AgendaItem, MeetingMinutesOptions, MeetingMinutesOptions as MeetingMinutesOptions$1, meetingMinutesPlugin } from "@docxkit/plugin-meeting-minutes";
|
|
25
26
|
import { SignatureBlockOptions, SignatureBlockOptions as SignatureBlockOptions$1, SignatureParty, signatureBlockPlugin } from "@docxkit/plugin-signature-block";
|
|
27
|
+
import { Readable } from "node:stream";
|
|
26
28
|
import { EChartsPluginOptions } from "@docxkit/plugin-echarts";
|
|
27
29
|
export * from "@docxkit/core";
|
|
28
|
-
|
|
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
|
|
29
58
|
//#region src/types/plugin-map.d.ts
|
|
30
59
|
declare module '@docxkit/core' {
|
|
31
60
|
interface BuiltinPluginMap {
|
|
32
61
|
badge: BadgeOptions$1;
|
|
62
|
+
barcode: BarcodeOptions$1;
|
|
33
63
|
callout: CalloutOptions$1;
|
|
34
64
|
changelog: ChangelogOptions$1;
|
|
35
65
|
codeBlock: CodeBlockOptions$1;
|
|
@@ -50,28 +80,25 @@ declare module '@docxkit/core' {
|
|
|
50
80
|
}
|
|
51
81
|
}
|
|
52
82
|
//#endregion
|
|
53
|
-
//#region src/node
|
|
83
|
+
//#region src/node.d.ts
|
|
54
84
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* Uses `Packer.toBuffer()` to produce the .docx binary, then
|
|
58
|
-
* writes via `node:fs/promises`. This function is **Node.js only**.
|
|
59
|
-
*
|
|
60
|
-
* @param doc - — A compiled `docx` `Document` instance
|
|
61
|
-
* @param filename - — Output file path (e.g. `"report.docx"`)
|
|
62
|
-
* @returns A promise that resolves when the file has been written
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```ts
|
|
66
|
-
* import { saveDocument } from 'docx-kit/node'
|
|
67
|
-
*
|
|
68
|
-
* const doc = await compileDocument({ ... })
|
|
69
|
-
* await saveDocument(doc, 'report.docx')
|
|
70
|
-
* ```
|
|
85
|
+
* A {@link DocxBuilder} with the Node.js filesystem save adapter installed.
|
|
71
86
|
*/
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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>>;
|
|
75
102
|
declare const BUILTIN_PRESETS: ReadonlyMap<string, DocxPreset>;
|
|
76
103
|
declare const PRESET_LIST: readonly DocxPreset[];
|
|
77
104
|
declare function usePreset(id: string): DocxPreset | undefined;
|
|
@@ -79,4 +106,4 @@ declare const BUILTIN_THEMES: ReadonlyMap<string, DocxTheme>;
|
|
|
79
106
|
declare const THEME_LIST: readonly DocxTheme[];
|
|
80
107
|
declare function useTheme(id: string): DocxTheme | undefined;
|
|
81
108
|
//#endregion
|
|
82
|
-
export { type AgendaItem, BUILTIN_PRESETS, BUILTIN_THEMES, type BadgeOptions, 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, 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, calloutPlugin, changelogPlugin, classicPreset, codeBlockPlugin, coverPagePlugin, dataTablePlugin, dataUrlToUint8Array, dividerPlugin, invoicePlugin, letterheadPlugin, meetingMinutesPlugin, minimalTheme, modernPreset, oceanTheme, pageNumberPlugin, propertyTablePlugin, qrcodePlugin, saveDocument, signatureBlockPlugin, timelinePlugin, tocPlugin, usePreset, useTheme, warmTheme, watermarkPlugin };
|
|
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
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import { createDocx as createDocx$1, dataUrlToUint8Array, renderDocx as renderDocx$1 } from "@docxkit/core";
|
|
1
2
|
import { academicPreset } from "@docxkit/preset-academic";
|
|
2
3
|
import { classicPreset } from "@docxkit/preset-classic";
|
|
3
4
|
import { modernPreset } from "@docxkit/preset-modern";
|
|
4
5
|
import { minimalTheme } from "@docxkit/theme-minimal";
|
|
5
6
|
import { oceanTheme } from "@docxkit/theme-ocean";
|
|
6
7
|
import { warmTheme } from "@docxkit/theme-warm";
|
|
7
|
-
import {
|
|
8
|
+
import { Packer } from "docx";
|
|
8
9
|
import { tocPlugin } from "@docxkit/plugin-toc";
|
|
9
10
|
import { badgePlugin } from "@docxkit/plugin-badge";
|
|
10
11
|
import { qrcodePlugin } from "@docxkit/plugin-qrcode";
|
|
12
|
+
import { barcodePlugin } from "@docxkit/plugin-barcode";
|
|
11
13
|
import { calloutPlugin } from "@docxkit/plugin-callout";
|
|
12
14
|
import { dividerPlugin } from "@docxkit/plugin-divider";
|
|
13
15
|
import { invoicePlugin } from "@docxkit/plugin-invoice";
|
|
@@ -19,7 +21,6 @@ import { coverPagePlugin } from "@docxkit/plugin-cover-page";
|
|
|
19
21
|
import { dataTablePlugin } from "@docxkit/plugin-data-table";
|
|
20
22
|
import { letterheadPlugin } from "@docxkit/plugin-letterhead";
|
|
21
23
|
import { pageNumberPlugin } from "@docxkit/plugin-page-number";
|
|
22
|
-
import { Packer } from "docx";
|
|
23
24
|
import { propertyTablePlugin } from "@docxkit/plugin-property-table";
|
|
24
25
|
import { meetingMinutesPlugin } from "@docxkit/plugin-meeting-minutes";
|
|
25
26
|
import { signatureBlockPlugin } from "@docxkit/plugin-signature-block";
|
|
@@ -33,8 +34,8 @@ export * from "@docxkit/core";
|
|
|
33
34
|
/**
|
|
34
35
|
* Save a compiled document to a file on disk.
|
|
35
36
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
37
|
+
* Streams the generated package to disk without materializing an additional
|
|
38
|
+
* complete output buffer. This function is **Node.js only**.
|
|
38
39
|
*
|
|
39
40
|
* @param doc - — A compiled `docx` `Document` instance
|
|
40
41
|
* @param filename - — Output file path (e.g. `"report.docx"`)
|
|
@@ -49,8 +50,17 @@ export * from "@docxkit/core";
|
|
|
49
50
|
* ```
|
|
50
51
|
*/
|
|
51
52
|
async function saveDocument(doc, filename) {
|
|
52
|
-
const {
|
|
53
|
-
await
|
|
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);
|
|
54
64
|
}
|
|
55
65
|
//#endregion
|
|
56
66
|
//#region src/node.ts
|
|
@@ -62,7 +72,27 @@ async function saveDocument(doc, filename) {
|
|
|
62
72
|
* @module docx-kit/node
|
|
63
73
|
* @packageDocumentation
|
|
64
74
|
*/
|
|
65
|
-
|
|
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([
|
|
66
96
|
[academicPreset.id, academicPreset],
|
|
67
97
|
[classicPreset.id, classicPreset],
|
|
68
98
|
[modernPreset.id, modernPreset]
|
|
@@ -75,7 +105,7 @@ const PRESET_LIST = [
|
|
|
75
105
|
function usePreset(id) {
|
|
76
106
|
return BUILTIN_PRESETS.get(id);
|
|
77
107
|
}
|
|
78
|
-
const BUILTIN_THEMES = new Map([
|
|
108
|
+
const BUILTIN_THEMES = /* @__PURE__ */ new Map([
|
|
79
109
|
[minimalTheme.id, minimalTheme],
|
|
80
110
|
[oceanTheme.id, oceanTheme],
|
|
81
111
|
[warmTheme.id, warmTheme]
|
|
@@ -89,4 +119,4 @@ function useTheme(id) {
|
|
|
89
119
|
return BUILTIN_THEMES.get(id);
|
|
90
120
|
}
|
|
91
121
|
//#endregion
|
|
92
|
-
export { BUILTIN_PRESETS, BUILTIN_THEMES, PRESET_LIST, THEME_LIST, academicPreset, badgePlugin, calloutPlugin, changelogPlugin, classicPreset, codeBlockPlugin, coverPagePlugin, dataTablePlugin, dataUrlToUint8Array, dividerPlugin, invoicePlugin, letterheadPlugin, meetingMinutesPlugin, minimalTheme, modernPreset, oceanTheme, pageNumberPlugin, propertyTablePlugin, qrcodePlugin, saveDocument, signatureBlockPlugin, timelinePlugin, tocPlugin, usePreset, useTheme, warmTheme, watermarkPlugin };
|
|
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";
|
package/dist/registry.js
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docx-kit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "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",
|
|
@@ -34,40 +34,40 @@
|
|
|
34
34
|
"default": "./dist/browser.js"
|
|
35
35
|
},
|
|
36
36
|
"./ai": {
|
|
37
|
-
"types": "./dist/ai
|
|
38
|
-
"default": "./dist/ai
|
|
37
|
+
"types": "./dist/ai.d.ts",
|
|
38
|
+
"default": "./dist/ai.js"
|
|
39
39
|
},
|
|
40
40
|
"./browser": {
|
|
41
41
|
"types": "./dist/browser.d.ts",
|
|
42
42
|
"default": "./dist/browser.js"
|
|
43
43
|
},
|
|
44
44
|
"./loader": {
|
|
45
|
-
"types": "./dist/loader
|
|
46
|
-
"default": "./dist/loader
|
|
45
|
+
"types": "./dist/loader.d.ts",
|
|
46
|
+
"default": "./dist/loader.js"
|
|
47
47
|
},
|
|
48
48
|
"./loader/browser": {
|
|
49
|
-
"types": "./dist/loader-
|
|
50
|
-
"default": "./dist/loader-
|
|
49
|
+
"types": "./dist/loader-browser.d.ts",
|
|
50
|
+
"default": "./dist/loader-browser.js"
|
|
51
51
|
},
|
|
52
52
|
"./loader/node": {
|
|
53
|
-
"types": "./dist/loader-
|
|
54
|
-
"default": "./dist/loader-
|
|
53
|
+
"types": "./dist/loader-node.d.ts",
|
|
54
|
+
"default": "./dist/loader-node.js"
|
|
55
55
|
},
|
|
56
56
|
"./mcp": {
|
|
57
|
-
"types": "./dist/mcp
|
|
58
|
-
"default": "./dist/mcp
|
|
57
|
+
"types": "./dist/mcp.d.ts",
|
|
58
|
+
"default": "./dist/mcp.js"
|
|
59
59
|
},
|
|
60
60
|
"./node": {
|
|
61
61
|
"types": "./dist/node.d.ts",
|
|
62
62
|
"default": "./dist/node.js"
|
|
63
63
|
},
|
|
64
64
|
"./pdk": {
|
|
65
|
-
"types": "./dist/pdk
|
|
66
|
-
"default": "./dist/pdk
|
|
65
|
+
"types": "./dist/pdk.d.ts",
|
|
66
|
+
"default": "./dist/pdk.js"
|
|
67
67
|
},
|
|
68
68
|
"./registry": {
|
|
69
|
-
"types": "./dist/registry
|
|
70
|
-
"default": "./dist/registry
|
|
69
|
+
"types": "./dist/registry.d.ts",
|
|
70
|
+
"default": "./dist/registry.js"
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
73
|
"main": "./dist/browser.js",
|
|
@@ -83,37 +83,38 @@
|
|
|
83
83
|
"docx": "^9.7.1"
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
|
-
"@docxkit/ai": "0.
|
|
87
|
-
"@docxkit/
|
|
88
|
-
"@docxkit/
|
|
89
|
-
"@docxkit/
|
|
90
|
-
"@docxkit/
|
|
91
|
-
"@docxkit/plugin-
|
|
92
|
-
"@docxkit/
|
|
93
|
-
"@docxkit/
|
|
94
|
-
"@docxkit/plugin-
|
|
95
|
-
"@docxkit/plugin-
|
|
96
|
-
"@docxkit/plugin-
|
|
97
|
-
"@docxkit/plugin-
|
|
98
|
-
"@docxkit/plugin-
|
|
99
|
-
"@docxkit/plugin-
|
|
100
|
-
"@docxkit/plugin-
|
|
101
|
-
"@docxkit/plugin-
|
|
102
|
-
"@docxkit/plugin-meeting-minutes": "0.
|
|
103
|
-
"@docxkit/plugin-
|
|
104
|
-
"@docxkit/plugin-
|
|
105
|
-
"@docxkit/
|
|
106
|
-
"@docxkit/plugin-
|
|
107
|
-
"@docxkit/plugin-
|
|
108
|
-
"@docxkit/plugin-
|
|
109
|
-
"@docxkit/
|
|
110
|
-
"@docxkit/
|
|
111
|
-
"@docxkit/
|
|
112
|
-
"@docxkit/
|
|
113
|
-
"@docxkit/
|
|
114
|
-
"@docxkit/
|
|
115
|
-
"@docxkit/theme-
|
|
116
|
-
"@docxkit/
|
|
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"
|
|
117
118
|
},
|
|
118
119
|
"scripts": {
|
|
119
120
|
"build": "tsdown",
|