docx-kit 0.1.0 → 0.3.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 +13 -15
- package/dist/browser.d.ts +65 -44
- package/dist/browser.js +73 -30
- package/dist/node.d.ts +58 -53
- package/dist/node.js +78 -16
- package/package.json +68 -48
- package/dist/compileDocument-BvuU28Yj.js +0 -750
- package/dist/errors-c9CC63Ti.js +0 -63
- package/dist/fs-DF8ug9Wi.js +0 -43
- package/dist/image-6yS25Ggr.js +0 -76
- package/dist/index.d.ts +0 -1032
- package/dist/index.js +0 -683
- package/dist/pack-0Jsv03Sk.js +0 -79
package/README.md
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
# docx-kit
|
|
2
2
|
|
|
3
|
-
[
|
|
4
|
-
[](https://www.npmjs.com/package/docx-kit)
|
|
5
|
-
[](https://www.npmjs.com/package/docx-kit)
|
|
6
|
-
[](https://github.com/ntnyq/docx-kit/blob/main/LICENSE)
|
|
3
|
+
CSS-like DOCX API Kit — a type-safe, plugin-extensible DOCX generation library built on [dolanmiu/docx](https://github.com/dolanmiu/docx).
|
|
7
4
|
|
|
8
|
-
|
|
5
|
+
This is the umbrella package that re-exports all core APIs, built-in plugins, presets, and themes.
|
|
9
6
|
|
|
10
|
-
##
|
|
7
|
+
## Installation
|
|
11
8
|
|
|
12
|
-
```
|
|
9
|
+
```bash
|
|
13
10
|
npm install docx-kit
|
|
14
11
|
```
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
yarn add docx-kit
|
|
18
|
-
```
|
|
13
|
+
## Usage
|
|
19
14
|
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
```
|
|
15
|
+
```ts
|
|
16
|
+
import { createDocx } from 'docx-kit'
|
|
23
17
|
|
|
24
|
-
|
|
18
|
+
const docx = createDocx()
|
|
19
|
+
.paragraph('Hello, world!')
|
|
20
|
+
.build()
|
|
25
21
|
|
|
26
|
-
|
|
22
|
+
// Use built-in plugins
|
|
23
|
+
import { calloutPlugin, codeBlockPlugin } from 'docx-kit'
|
|
24
|
+
```
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,27 +1,56 @@
|
|
|
1
|
+
import { academicPreset } from "@docxkit/preset-academic";
|
|
2
|
+
import { classicPreset } from "@docxkit/preset-classic";
|
|
3
|
+
import { modernPreset } from "@docxkit/preset-modern";
|
|
4
|
+
import { minimalTheme } from "@docxkit/theme-minimal";
|
|
5
|
+
import { oceanTheme } from "@docxkit/theme-ocean";
|
|
6
|
+
import { warmTheme } from "@docxkit/theme-warm";
|
|
7
|
+
import { DocxPreset, DocxTheme } from "@docxkit/core";
|
|
8
|
+
import { TocOptions, TocOptions as TocOptions$1, tocPlugin } from "@docxkit/plugin-toc";
|
|
9
|
+
import { BadgeOptions, BadgeOptions as BadgeOptions$1, badgePlugin } from "@docxkit/plugin-badge";
|
|
10
|
+
import { QRCodePluginOptions, QRCodePluginOptions as QRCodePluginOptions$1, qrcodePlugin } from "@docxkit/plugin-qrcode";
|
|
11
|
+
import { CalloutOptions, CalloutOptions as CalloutOptions$1, calloutPlugin } from "@docxkit/plugin-callout";
|
|
12
|
+
import { DividerOptions, DividerOptions as DividerOptions$1, dividerPlugin } from "@docxkit/plugin-divider";
|
|
13
|
+
import { EChartsPluginOptions, EChartsPluginOptions as EChartsPluginOptions$1, echartsPlugin } from "@docxkit/plugin-echarts";
|
|
14
|
+
import { InvoiceLineItem, InvoiceOptions, InvoiceOptions as InvoiceOptions$1, InvoiceParty, invoicePlugin } from "@docxkit/plugin-invoice";
|
|
15
|
+
import { TimelineEvent, TimelineOptions, TimelineOptions as TimelineOptions$1, timelinePlugin } from "@docxkit/plugin-timeline";
|
|
16
|
+
import { ChangelogEntry, ChangelogOptions, ChangelogOptions as ChangelogOptions$1, changelogPlugin } from "@docxkit/plugin-changelog";
|
|
17
|
+
import { WatermarkOptions, WatermarkOptions as WatermarkOptions$1, watermarkPlugin } from "@docxkit/plugin-watermark";
|
|
18
|
+
import { CodeBlockOptions, CodeBlockOptions as CodeBlockOptions$1, codeBlockPlugin } from "@docxkit/plugin-code-block";
|
|
19
|
+
import { CoverPageOptions, CoverPageOptions as CoverPageOptions$1, coverPagePlugin } from "@docxkit/plugin-cover-page";
|
|
20
|
+
import { ColAlign, ColFormat, DataTableOptions, DataTableOptions as DataTableOptions$1, dataTablePlugin } from "@docxkit/plugin-data-table";
|
|
21
|
+
import { LetterheadOptions, LetterheadOptions as LetterheadOptions$1, letterheadPlugin } from "@docxkit/plugin-letterhead";
|
|
22
|
+
import { PageNumberOptions, PageNumberOptions as PageNumberOptions$1, pageNumberPlugin } from "@docxkit/plugin-page-number";
|
|
23
|
+
import { PropertyItem, PropertyTableOptions, PropertyTableOptions as PropertyTableOptions$1, propertyTablePlugin } from "@docxkit/plugin-property-table";
|
|
24
|
+
import { AgendaItem, MeetingMinutesOptions, MeetingMinutesOptions as MeetingMinutesOptions$1, meetingMinutesPlugin } from "@docxkit/plugin-meeting-minutes";
|
|
25
|
+
import { SignatureBlockOptions, SignatureBlockOptions as SignatureBlockOptions$1, SignatureParty, signatureBlockPlugin } from "@docxkit/plugin-signature-block";
|
|
26
|
+
import { DocxInput, DocxPreview, DocxPreviewOptions, PREVIEW_ERROR_CODES, PreviewErrorCode, RendererKind, createDocxPreview } from "@docxkit/renderer";
|
|
27
|
+
export * from "@docxkit/core";
|
|
28
|
+
|
|
29
|
+
//#region src/types/plugin-map.d.ts
|
|
30
|
+
declare module '@docxkit/core' {
|
|
31
|
+
interface BuiltinPluginMap {
|
|
32
|
+
badge: BadgeOptions$1;
|
|
33
|
+
callout: CalloutOptions$1;
|
|
34
|
+
changelog: ChangelogOptions$1;
|
|
35
|
+
codeBlock: CodeBlockOptions$1;
|
|
36
|
+
coverPage: CoverPageOptions$1;
|
|
37
|
+
dataTable: DataTableOptions$1;
|
|
38
|
+
divider: DividerOptions$1;
|
|
39
|
+
echarts: EChartsPluginOptions$1;
|
|
40
|
+
invoice: InvoiceOptions$1;
|
|
41
|
+
letterhead: LetterheadOptions$1;
|
|
42
|
+
meetingMinutes: MeetingMinutesOptions$1;
|
|
43
|
+
pageNumber: PageNumberOptions$1;
|
|
44
|
+
propertyTable: PropertyTableOptions$1;
|
|
45
|
+
qrcode: QRCodePluginOptions$1;
|
|
46
|
+
signatureBlock: SignatureBlockOptions$1;
|
|
47
|
+
timeline: TimelineOptions$1;
|
|
48
|
+
toc: TocOptions$1;
|
|
49
|
+
watermark: WatermarkOptions$1;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
1
53
|
//#region src/browser/dom.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Browser DOM utilities — base64 decoding and Blob/image handling.
|
|
4
|
-
*
|
|
5
|
-
* @module browser/dom
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Decode a base64 data-URL to raw bytes using the browser `atob` API.
|
|
9
|
-
*
|
|
10
|
-
* Strips the `"data:*;base64,"` prefix, decodes the base64 string
|
|
11
|
-
* via `atob()`, and populates a `Uint8Array` from each character's
|
|
12
|
-
* code point.
|
|
13
|
-
*
|
|
14
|
-
* @param dataUrl - — A base64 data-URI string (e.g. `"data:image/png;base64,iVBO..."`)
|
|
15
|
-
* @returns Raw bytes as `Uint8Array`
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* import { dataUrlToUint8Array } from 'docx-kit/browser'
|
|
20
|
-
*
|
|
21
|
-
* const bytes = await dataUrlToUint8Array('data:image/png;base64,iVBORw...')
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
declare function dataUrlToUint8Array(dataUrl: string): Promise<Uint8Array>;
|
|
25
54
|
/**
|
|
26
55
|
* Normalize image data for `ImageRun` — converts `Blob` to `Uint8Array`.
|
|
27
56
|
*
|
|
@@ -43,25 +72,17 @@ declare function dataUrlToUint8Array(dataUrl: string): Promise<Uint8Array>;
|
|
|
43
72
|
declare function normalizeImageData(data: unknown): Promise<string | ArrayBuffer | Uint8Array>;
|
|
44
73
|
//#endregion
|
|
45
74
|
//#region src/browser.d.ts
|
|
46
|
-
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
* a.download = 'output.docx'
|
|
59
|
-
* a.click()
|
|
60
|
-
* URL.revokeObjectURL(url)
|
|
61
|
-
* ```
|
|
62
|
-
*
|
|
63
|
-
* @deprecated This API is not available in browsers. Use `doc.toBlob()` instead.
|
|
64
|
-
*/
|
|
65
|
-
declare const saveDocument: never;
|
|
75
|
+
/** All built-in presets, keyed by ID. */
|
|
76
|
+
declare const BUILTIN_PRESETS: ReadonlyMap<string, DocxPreset>;
|
|
77
|
+
/** Ordered list of built-in presets (for UI selectors). */
|
|
78
|
+
declare const PRESET_LIST: readonly DocxPreset[];
|
|
79
|
+
/** Look up a built-in preset by ID. */
|
|
80
|
+
declare function usePreset(id: string): DocxPreset | undefined;
|
|
81
|
+
/** All built-in themes, keyed by ID. */
|
|
82
|
+
declare const BUILTIN_THEMES: ReadonlyMap<string, DocxTheme>;
|
|
83
|
+
/** Ordered list of built-in themes (for UI selectors). */
|
|
84
|
+
declare const THEME_LIST: readonly DocxTheme[];
|
|
85
|
+
/** Look up a built-in theme by ID. */
|
|
86
|
+
declare function useTheme(id: string): DocxTheme | undefined;
|
|
66
87
|
//#endregion
|
|
67
|
-
export {
|
|
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 };
|
package/dist/browser.js
CHANGED
|
@@ -1,34 +1,32 @@
|
|
|
1
|
+
import { academicPreset } from "@docxkit/preset-academic";
|
|
2
|
+
import { classicPreset } from "@docxkit/preset-classic";
|
|
3
|
+
import { modernPreset } from "@docxkit/preset-modern";
|
|
4
|
+
import { minimalTheme } from "@docxkit/theme-minimal";
|
|
5
|
+
import { oceanTheme } from "@docxkit/theme-ocean";
|
|
6
|
+
import { warmTheme } from "@docxkit/theme-warm";
|
|
7
|
+
import "@docxkit/core";
|
|
8
|
+
import { tocPlugin } from "@docxkit/plugin-toc";
|
|
9
|
+
import { badgePlugin } from "@docxkit/plugin-badge";
|
|
10
|
+
import { qrcodePlugin } from "@docxkit/plugin-qrcode";
|
|
11
|
+
import { calloutPlugin } from "@docxkit/plugin-callout";
|
|
12
|
+
import { dividerPlugin } from "@docxkit/plugin-divider";
|
|
13
|
+
import { echartsPlugin } from "@docxkit/plugin-echarts";
|
|
14
|
+
import { invoicePlugin } from "@docxkit/plugin-invoice";
|
|
15
|
+
import { timelinePlugin } from "@docxkit/plugin-timeline";
|
|
16
|
+
import { changelogPlugin } from "@docxkit/plugin-changelog";
|
|
17
|
+
import { watermarkPlugin } from "@docxkit/plugin-watermark";
|
|
18
|
+
import { codeBlockPlugin } from "@docxkit/plugin-code-block";
|
|
19
|
+
import { coverPagePlugin } from "@docxkit/plugin-cover-page";
|
|
20
|
+
import { dataTablePlugin } from "@docxkit/plugin-data-table";
|
|
21
|
+
import { letterheadPlugin } from "@docxkit/plugin-letterhead";
|
|
22
|
+
import { pageNumberPlugin } from "@docxkit/plugin-page-number";
|
|
23
|
+
import { propertyTablePlugin } from "@docxkit/plugin-property-table";
|
|
24
|
+
import { meetingMinutesPlugin } from "@docxkit/plugin-meeting-minutes";
|
|
25
|
+
import { signatureBlockPlugin } from "@docxkit/plugin-signature-block";
|
|
26
|
+
import { PREVIEW_ERROR_CODES, createDocxPreview } from "@docxkit/renderer";
|
|
27
|
+
export * from "@docxkit/core";
|
|
1
28
|
//#region src/browser/dom.ts
|
|
2
29
|
/**
|
|
3
|
-
* Browser DOM utilities — base64 decoding and Blob/image handling.
|
|
4
|
-
*
|
|
5
|
-
* @module browser/dom
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Decode a base64 data-URL to raw bytes using the browser `atob` API.
|
|
9
|
-
*
|
|
10
|
-
* Strips the `"data:*;base64,"` prefix, decodes the base64 string
|
|
11
|
-
* via `atob()`, and populates a `Uint8Array` from each character's
|
|
12
|
-
* code point.
|
|
13
|
-
*
|
|
14
|
-
* @param dataUrl - — A base64 data-URI string (e.g. `"data:image/png;base64,iVBO..."`)
|
|
15
|
-
* @returns Raw bytes as `Uint8Array`
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* import { dataUrlToUint8Array } from 'docx-kit/browser'
|
|
20
|
-
*
|
|
21
|
-
* const bytes = await dataUrlToUint8Array('data:image/png;base64,iVBORw...')
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
async function dataUrlToUint8Array(dataUrl) {
|
|
25
|
-
const base64 = dataUrl.split(",")[1];
|
|
26
|
-
const binary = atob(base64);
|
|
27
|
-
const bytes = new Uint8Array(binary.length);
|
|
28
|
-
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
29
|
-
return bytes;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
30
|
* Normalize image data for `ImageRun` — converts `Blob` to `Uint8Array`.
|
|
33
31
|
*
|
|
34
32
|
* In the browser, image data often arrives as a `Blob` (e.g. from
|
|
@@ -51,4 +49,49 @@ async function normalizeImageData(data) {
|
|
|
51
49
|
return data;
|
|
52
50
|
}
|
|
53
51
|
//#endregion
|
|
54
|
-
|
|
52
|
+
//#region src/browser.ts
|
|
53
|
+
/**
|
|
54
|
+
* docx-kit — Browser platform entry (default).
|
|
55
|
+
*
|
|
56
|
+
* Re-exports all APIs from @docxkit/core plus built-in plugins,
|
|
57
|
+
* presets, and themes. This is the default import target.
|
|
58
|
+
*
|
|
59
|
+
* For Node.js–only APIs (filesystem save), import from 'docx-kit/node'.
|
|
60
|
+
*
|
|
61
|
+
* @module docx-kit
|
|
62
|
+
* @packageDocumentation
|
|
63
|
+
*/
|
|
64
|
+
/** All built-in presets, keyed by ID. */
|
|
65
|
+
const BUILTIN_PRESETS = new Map([
|
|
66
|
+
[academicPreset.id, academicPreset],
|
|
67
|
+
[classicPreset.id, classicPreset],
|
|
68
|
+
[modernPreset.id, modernPreset]
|
|
69
|
+
]);
|
|
70
|
+
/** Ordered list of built-in presets (for UI selectors). */
|
|
71
|
+
const PRESET_LIST = [
|
|
72
|
+
classicPreset,
|
|
73
|
+
modernPreset,
|
|
74
|
+
academicPreset
|
|
75
|
+
];
|
|
76
|
+
/** Look up a built-in preset by ID. */
|
|
77
|
+
function usePreset(id) {
|
|
78
|
+
return BUILTIN_PRESETS.get(id);
|
|
79
|
+
}
|
|
80
|
+
/** All built-in themes, keyed by ID. */
|
|
81
|
+
const BUILTIN_THEMES = new Map([
|
|
82
|
+
[minimalTheme.id, minimalTheme],
|
|
83
|
+
[oceanTheme.id, oceanTheme],
|
|
84
|
+
[warmTheme.id, warmTheme]
|
|
85
|
+
]);
|
|
86
|
+
/** Ordered list of built-in themes (for UI selectors). */
|
|
87
|
+
const THEME_LIST = [
|
|
88
|
+
minimalTheme,
|
|
89
|
+
oceanTheme,
|
|
90
|
+
warmTheme
|
|
91
|
+
];
|
|
92
|
+
/** Look up a built-in theme by ID. */
|
|
93
|
+
function useTheme(id) {
|
|
94
|
+
return BUILTIN_THEMES.get(id);
|
|
95
|
+
}
|
|
96
|
+
//#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 };
|
package/dist/node.d.ts
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
|
+
import { academicPreset } from "@docxkit/preset-academic";
|
|
2
|
+
import { classicPreset } from "@docxkit/preset-classic";
|
|
3
|
+
import { modernPreset } from "@docxkit/preset-modern";
|
|
4
|
+
import { minimalTheme } from "@docxkit/theme-minimal";
|
|
5
|
+
import { oceanTheme } from "@docxkit/theme-ocean";
|
|
6
|
+
import { warmTheme } from "@docxkit/theme-warm";
|
|
7
|
+
import { DocxPreset, DocxTheme, dataUrlToUint8Array } from "@docxkit/core";
|
|
8
|
+
import { TocOptions, TocOptions as TocOptions$1, tocPlugin } from "@docxkit/plugin-toc";
|
|
9
|
+
import { BadgeOptions, BadgeOptions as BadgeOptions$1, badgePlugin } from "@docxkit/plugin-badge";
|
|
10
|
+
import { QRCodePluginOptions, QRCodePluginOptions as QRCodePluginOptions$1, qrcodePlugin } from "@docxkit/plugin-qrcode";
|
|
11
|
+
import { CalloutOptions, CalloutOptions as CalloutOptions$1, calloutPlugin } from "@docxkit/plugin-callout";
|
|
12
|
+
import { DividerOptions, DividerOptions as DividerOptions$1, dividerPlugin } from "@docxkit/plugin-divider";
|
|
13
|
+
import { InvoiceLineItem, InvoiceOptions, InvoiceOptions as InvoiceOptions$1, InvoiceParty, invoicePlugin } from "@docxkit/plugin-invoice";
|
|
14
|
+
import { TimelineEvent, TimelineOptions, TimelineOptions as TimelineOptions$1, timelinePlugin } from "@docxkit/plugin-timeline";
|
|
15
|
+
import { ChangelogEntry, ChangelogOptions, ChangelogOptions as ChangelogOptions$1, changelogPlugin } from "@docxkit/plugin-changelog";
|
|
16
|
+
import { WatermarkOptions, WatermarkOptions as WatermarkOptions$1, watermarkPlugin } from "@docxkit/plugin-watermark";
|
|
17
|
+
import { CodeBlockOptions, CodeBlockOptions as CodeBlockOptions$1, codeBlockPlugin } from "@docxkit/plugin-code-block";
|
|
18
|
+
import { CoverPageOptions, CoverPageOptions as CoverPageOptions$1, coverPagePlugin } from "@docxkit/plugin-cover-page";
|
|
19
|
+
import { ColAlign, ColFormat, DataTableOptions, DataTableOptions as DataTableOptions$1, dataTablePlugin } from "@docxkit/plugin-data-table";
|
|
20
|
+
import { LetterheadOptions, LetterheadOptions as LetterheadOptions$1, letterheadPlugin } from "@docxkit/plugin-letterhead";
|
|
21
|
+
import { PageNumberOptions, PageNumberOptions as PageNumberOptions$1, pageNumberPlugin } from "@docxkit/plugin-page-number";
|
|
1
22
|
import { Document } from "docx";
|
|
23
|
+
import { PropertyItem, PropertyTableOptions, PropertyTableOptions as PropertyTableOptions$1, propertyTablePlugin } from "@docxkit/plugin-property-table";
|
|
24
|
+
import { AgendaItem, MeetingMinutesOptions, MeetingMinutesOptions as MeetingMinutesOptions$1, meetingMinutesPlugin } from "@docxkit/plugin-meeting-minutes";
|
|
25
|
+
import { SignatureBlockOptions, SignatureBlockOptions as SignatureBlockOptions$1, SignatureParty, signatureBlockPlugin } from "@docxkit/plugin-signature-block";
|
|
26
|
+
import { EChartsPluginOptions } from "@docxkit/plugin-echarts";
|
|
27
|
+
export * from "@docxkit/core";
|
|
2
28
|
|
|
29
|
+
//#region src/types/plugin-map.d.ts
|
|
30
|
+
declare module '@docxkit/core' {
|
|
31
|
+
interface BuiltinPluginMap {
|
|
32
|
+
badge: BadgeOptions$1;
|
|
33
|
+
callout: CalloutOptions$1;
|
|
34
|
+
changelog: ChangelogOptions$1;
|
|
35
|
+
codeBlock: CodeBlockOptions$1;
|
|
36
|
+
coverPage: CoverPageOptions$1;
|
|
37
|
+
dataTable: DataTableOptions$1;
|
|
38
|
+
divider: DividerOptions$1;
|
|
39
|
+
echarts: EChartsPluginOptions;
|
|
40
|
+
invoice: InvoiceOptions$1;
|
|
41
|
+
letterhead: LetterheadOptions$1;
|
|
42
|
+
meetingMinutes: MeetingMinutesOptions$1;
|
|
43
|
+
pageNumber: PageNumberOptions$1;
|
|
44
|
+
propertyTable: PropertyTableOptions$1;
|
|
45
|
+
qrcode: QRCodePluginOptions$1;
|
|
46
|
+
signatureBlock: SignatureBlockOptions$1;
|
|
47
|
+
timeline: TimelineOptions$1;
|
|
48
|
+
toc: TocOptions$1;
|
|
49
|
+
watermark: WatermarkOptions$1;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
3
53
|
//#region src/node/fs.d.ts
|
|
4
54
|
/**
|
|
5
55
|
* Save a compiled document to a file on disk.
|
|
@@ -9,6 +59,7 @@ import { Document } from "docx";
|
|
|
9
59
|
*
|
|
10
60
|
* @param doc - — A compiled `docx` `Document` instance
|
|
11
61
|
* @param filename - — Output file path (e.g. `"report.docx"`)
|
|
62
|
+
* @returns A promise that resolves when the file has been written
|
|
12
63
|
*
|
|
13
64
|
* @example
|
|
14
65
|
* ```ts
|
|
@@ -20,58 +71,12 @@ import { Document } from "docx";
|
|
|
20
71
|
*/
|
|
21
72
|
declare function saveDocument(doc: Document, filename: string): Promise<void>;
|
|
22
73
|
//#endregion
|
|
23
|
-
//#region src/node/dataUrl.d.ts
|
|
24
|
-
/**
|
|
25
|
-
* Node.js base64 data-URL decoder (uses `Buffer` from `node:buffer`).
|
|
26
|
-
*
|
|
27
|
-
* @module node/dataUrl
|
|
28
|
-
*/
|
|
29
|
-
/**
|
|
30
|
-
* Decode a base64 data-URL to raw bytes using Node.js `Buffer`.
|
|
31
|
-
*
|
|
32
|
-
* Strips the `"data:*;base64,"` prefix and decodes via
|
|
33
|
-
* `Buffer.from(base64, 'base64')`.
|
|
34
|
-
*
|
|
35
|
-
* @param dataUrl - — A base64 data-URI string (e.g. `"data:image/png;base64,iVBO..."`)
|
|
36
|
-
* @returns Raw bytes as `Uint8Array`
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```ts
|
|
40
|
-
* import { dataUrlToUint8Array } from 'docx-kit/node'
|
|
41
|
-
*
|
|
42
|
-
* const bytes = await dataUrlToUint8Array('data:image/png;base64,iVBORw...')
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
declare function dataUrlToUint8Array(dataUrl: string): Promise<Uint8Array>;
|
|
46
|
-
//#endregion
|
|
47
74
|
//#region src/node.d.ts
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
* **Workarounds:**
|
|
55
|
-
* - Use a server-side canvas library (e.g. `node-canvas` + `echarts`)
|
|
56
|
-
* - Pre-render charts on the client and pass the image data to docx-kit
|
|
57
|
-
*
|
|
58
|
-
* @deprecated This API is not available in Node.js. See workarounds above.
|
|
59
|
-
*/
|
|
60
|
-
declare const echartsPlugin: never;
|
|
61
|
-
/**
|
|
62
|
-
* ### ❌ `normalizeImageData()` — Not built-in for Node.js
|
|
63
|
-
*
|
|
64
|
-
* This utility converts `Blob` instances to `Uint8Array`. While `Blob`
|
|
65
|
-
* is available in Node.js ≥ 18, it is rarely the carrier for image data
|
|
66
|
-
* in Node workflows (most users work with `Buffer` or file paths directly).
|
|
67
|
-
*
|
|
68
|
-
* If you need Blob→Uint8Array in Node.js, use:
|
|
69
|
-
* ```ts
|
|
70
|
-
* const bytes = new Uint8Array(await blob.arrayBuffer())
|
|
71
|
-
* ```
|
|
72
|
-
*
|
|
73
|
-
* @deprecated Use inline `new Uint8Array(await blob.arrayBuffer())` instead.
|
|
74
|
-
*/
|
|
75
|
-
declare const normalizeImageData: never;
|
|
75
|
+
declare const BUILTIN_PRESETS: ReadonlyMap<string, DocxPreset>;
|
|
76
|
+
declare const PRESET_LIST: readonly DocxPreset[];
|
|
77
|
+
declare function usePreset(id: string): DocxPreset | undefined;
|
|
78
|
+
declare const BUILTIN_THEMES: ReadonlyMap<string, DocxTheme>;
|
|
79
|
+
declare const THEME_LIST: readonly DocxTheme[];
|
|
80
|
+
declare function useTheme(id: string): DocxTheme | undefined;
|
|
76
81
|
//#endregion
|
|
77
|
-
export { dataUrlToUint8Array,
|
|
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 };
|
package/dist/node.js
CHANGED
|
@@ -1,30 +1,92 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { academicPreset } from "@docxkit/preset-academic";
|
|
2
|
+
import { classicPreset } from "@docxkit/preset-classic";
|
|
3
|
+
import { modernPreset } from "@docxkit/preset-modern";
|
|
4
|
+
import { minimalTheme } from "@docxkit/theme-minimal";
|
|
5
|
+
import { oceanTheme } from "@docxkit/theme-ocean";
|
|
6
|
+
import { warmTheme } from "@docxkit/theme-warm";
|
|
7
|
+
import { dataUrlToUint8Array } from "@docxkit/core";
|
|
8
|
+
import { tocPlugin } from "@docxkit/plugin-toc";
|
|
9
|
+
import { badgePlugin } from "@docxkit/plugin-badge";
|
|
10
|
+
import { qrcodePlugin } from "@docxkit/plugin-qrcode";
|
|
11
|
+
import { calloutPlugin } from "@docxkit/plugin-callout";
|
|
12
|
+
import { dividerPlugin } from "@docxkit/plugin-divider";
|
|
13
|
+
import { invoicePlugin } from "@docxkit/plugin-invoice";
|
|
14
|
+
import { timelinePlugin } from "@docxkit/plugin-timeline";
|
|
15
|
+
import { changelogPlugin } from "@docxkit/plugin-changelog";
|
|
16
|
+
import { watermarkPlugin } from "@docxkit/plugin-watermark";
|
|
17
|
+
import { codeBlockPlugin } from "@docxkit/plugin-code-block";
|
|
18
|
+
import { coverPagePlugin } from "@docxkit/plugin-cover-page";
|
|
19
|
+
import { dataTablePlugin } from "@docxkit/plugin-data-table";
|
|
20
|
+
import { letterheadPlugin } from "@docxkit/plugin-letterhead";
|
|
21
|
+
import { pageNumberPlugin } from "@docxkit/plugin-page-number";
|
|
22
|
+
import { Packer } from "docx";
|
|
23
|
+
import { propertyTablePlugin } from "@docxkit/plugin-property-table";
|
|
24
|
+
import { meetingMinutesPlugin } from "@docxkit/plugin-meeting-minutes";
|
|
25
|
+
import { signatureBlockPlugin } from "@docxkit/plugin-signature-block";
|
|
26
|
+
export * from "@docxkit/core";
|
|
27
|
+
//#region src/node/fs.ts
|
|
3
28
|
/**
|
|
4
|
-
* Node.js
|
|
29
|
+
* Node.js filesystem utilities for saving documents to disk.
|
|
5
30
|
*
|
|
6
|
-
* @module node/
|
|
31
|
+
* @module node/fs
|
|
7
32
|
*/
|
|
8
33
|
/**
|
|
9
|
-
*
|
|
34
|
+
* Save a compiled document to a file on disk.
|
|
10
35
|
*
|
|
11
|
-
*
|
|
12
|
-
* `
|
|
36
|
+
* Uses `Packer.toBuffer()` to produce the .docx binary, then
|
|
37
|
+
* writes via `node:fs/promises`. This function is **Node.js only**.
|
|
13
38
|
*
|
|
14
|
-
* @param
|
|
15
|
-
* @
|
|
39
|
+
* @param doc - — A compiled `docx` `Document` instance
|
|
40
|
+
* @param filename - — Output file path (e.g. `"report.docx"`)
|
|
41
|
+
* @returns A promise that resolves when the file has been written
|
|
16
42
|
*
|
|
17
43
|
* @example
|
|
18
44
|
* ```ts
|
|
19
|
-
* import {
|
|
45
|
+
* import { saveDocument } from 'docx-kit/node'
|
|
20
46
|
*
|
|
21
|
-
* const
|
|
47
|
+
* const doc = await compileDocument({ ... })
|
|
48
|
+
* await saveDocument(doc, 'report.docx')
|
|
22
49
|
* ```
|
|
23
50
|
*/
|
|
24
|
-
async function
|
|
25
|
-
const {
|
|
26
|
-
|
|
27
|
-
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
51
|
+
async function saveDocument(doc, filename) {
|
|
52
|
+
const { writeFile } = await import("node:fs/promises");
|
|
53
|
+
await writeFile(filename, await Packer.toBuffer(doc));
|
|
28
54
|
}
|
|
29
55
|
//#endregion
|
|
30
|
-
|
|
56
|
+
//#region src/node.ts
|
|
57
|
+
/**
|
|
58
|
+
* docx-kit — Node.js platform entry.
|
|
59
|
+
*
|
|
60
|
+
* Import from 'docx-kit/node'.
|
|
61
|
+
*
|
|
62
|
+
* @module docx-kit/node
|
|
63
|
+
* @packageDocumentation
|
|
64
|
+
*/
|
|
65
|
+
const BUILTIN_PRESETS = new Map([
|
|
66
|
+
[academicPreset.id, academicPreset],
|
|
67
|
+
[classicPreset.id, classicPreset],
|
|
68
|
+
[modernPreset.id, modernPreset]
|
|
69
|
+
]);
|
|
70
|
+
const PRESET_LIST = [
|
|
71
|
+
classicPreset,
|
|
72
|
+
modernPreset,
|
|
73
|
+
academicPreset
|
|
74
|
+
];
|
|
75
|
+
function usePreset(id) {
|
|
76
|
+
return BUILTIN_PRESETS.get(id);
|
|
77
|
+
}
|
|
78
|
+
const BUILTIN_THEMES = new Map([
|
|
79
|
+
[minimalTheme.id, minimalTheme],
|
|
80
|
+
[oceanTheme.id, oceanTheme],
|
|
81
|
+
[warmTheme.id, warmTheme]
|
|
82
|
+
]);
|
|
83
|
+
const THEME_LIST = [
|
|
84
|
+
minimalTheme,
|
|
85
|
+
oceanTheme,
|
|
86
|
+
warmTheme
|
|
87
|
+
];
|
|
88
|
+
function useTheme(id) {
|
|
89
|
+
return BUILTIN_THEMES.get(id);
|
|
90
|
+
}
|
|
91
|
+
//#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 };
|