docx-kit 0.2.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/dist/browser.d.ts CHANGED
@@ -1,1796 +1,56 @@
1
- import { AlignmentType } from "docx";
2
- import { EChartsOption } from "echarts";
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";
3
28
 
4
- //#region src/types/utility.d.ts
5
- /** Hexadecimal CSS color string, e.g. `"#ff0000"`. */
6
- type HexColor = `#${string}`;
7
- /**
8
- * A literal union type that still allows arbitrary string values.
9
- * Useful for autocomplete-friendly APIs with extensible values.
10
- *
11
- * @template T — The literal subtype (e.g. `'Arial' | 'Calibri'`)
12
- * @template U — The base type, defaults to `string`
13
- */
14
- type LiteralUnion<T extends U, U = string> = T | (U & {});
15
- /**
16
- * A value that might be synchronous or wrapped in a Promise.
17
- *
18
- * @template T — The inner value type
19
- */
20
- type MaybePromise<T> = Promise<T> | T;
21
- /**
22
- * CSS-like length value.
23
- *
24
- * Supports bare numbers, and explicit unit strings:
25
- * `%`, `cm`, `in`, `mm`, `pt`, `px`.
26
- *
27
- * Bare-number conventions vary by context:
28
- * - `fontSize` → interpreted as `pt`
29
- * - spacing / indent → interpreted as `pt`
30
- * - image size → interpreted as `px`
31
- */
32
- type UnitValue = `${number}%` | `${number}cm` | `${number}in` | `${number}mm` | `${number}pt` | `${number}px` | number;
33
- //#endregion
34
- //#region src/types/style.d.ts
35
- /**
36
- * A single border side descriptor.
37
- *
38
- * Follows the CSS `border` shorthand convention (style, width, color).
39
- */
40
- interface BorderRule {
41
- /** Border color (e.g. `"#333"` or named color). */
42
- color?: string | HexColor;
43
- /** Line style. */
44
- style?: BorderStyle;
45
- /** Line width (bare number treated as pt). */
46
- width?: UnitValue;
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
+ }
47
51
  }
48
- /** Available border line styles. */
49
- type BorderStyle = 'dashed' | 'dotted' | 'double' | 'none' | 'single';
50
- /**
51
- * CSS-like style descriptor for a run, paragraph, cell, or table.
52
- *
53
- * Keys mirror familiar CSS property names. Unknown properties that don't
54
- * map to Word XML are silently ignored.
55
- */
56
- interface DocxStyleRule {
57
- /** Force text to uppercase (small caps-like). */
58
- allCaps?: boolean;
59
- /** Background / shading color. */
60
- backgroundColor?: string | HexColor;
61
- /** Shorthand border for all four sides. */
62
- border?: BorderRule;
63
- /** Bottom border override. */
64
- borderBottom?: BorderRule;
65
- /** Left border override. */
66
- borderLeft?: BorderRule;
67
- /** Right border override. */
68
- borderRight?: BorderRule;
69
- /** Top border override. */
70
- borderTop?: BorderRule;
71
- /** Character spacing (letter-spacing). */
72
- characterSpacing?: number;
73
- /** Text / foreground color. */
74
- color?: string | HexColor;
75
- /**
76
- * Direct passthrough to the underlying `docx` library constructor options.
77
- * Use for properties not yet covered by the CSS-like mapping.
78
- */
79
- docx?: Record<string, unknown>;
80
- /** Font family name. */
81
- fontFamily?: LiteralUnion<'Arial' | 'Calibri' | 'Times New Roman'>;
82
- /** Font size (bare number = pt). */
83
- fontSize?: UnitValue;
84
- /** Italic toggle. */
85
- fontStyle?: 'italic' | 'normal';
86
- /** Font weight: keyword `"bold"` / `"normal"` or numeric 100–900. */
87
- fontWeight?: FontWeight;
88
- /** Element height. */
89
- height?: UnitValue;
90
- /** Text highlight color (background marker). */
91
- highlight?: HighlightColor;
92
- /** Keep lines together on same page. */
93
- keepLines?: boolean;
94
- /** Keep this paragraph with the next one. */
95
- keepNext?: boolean;
96
- /** Character spacing. */
97
- letterSpacing?: UnitValue;
98
- /** Line height multiplier or explicit unit value. */
99
- lineHeight?: number | UnitValue;
100
- /** Bottom margin. */
101
- marginBottom?: UnitValue;
102
- /** Left margin. */
103
- marginLeft?: UnitValue;
104
- /** Right margin. */
105
- marginRight?: UnitValue;
106
- /** Top margin. */
107
- marginTop?: UnitValue;
108
- /** Force page break before this paragraph. */
109
- pageBreakBefore?: boolean;
110
- /** Small caps text variant. */
111
- smallCaps?: boolean;
112
- /** Strikethrough toggle. */
113
- strike?: boolean;
114
- /** Sub-script text. */
115
- subScript?: boolean;
116
- /** Super-script text. */
117
- superScript?: boolean;
118
- /** Horizontal text alignment. */
119
- textAlign?: TextAlign;
120
- /** First-line indent. */
121
- textIndent?: UnitValue;
122
- /** Underline style. */
123
- underline?: 'double' | 'single' | boolean;
124
- /** Vertical alignment (mostly for table cells). */
125
- verticalAlign?: VerticalAlign;
126
- /** Element width. */
127
- width?: UnitValue;
128
- /**
129
- * CSS-like margin shorthand.
130
- *
131
- * Supports 1-value, 2-value, and 4-value string syntax
132
- * (e.g. `"10pt"`, `"10pt 20pt"`, `"10pt 20pt 30pt 40pt"`).
133
- */
134
- margin?: `${string} ${string}` | `${string} ${string} ${string} ${string}` | UnitValue;
135
- /**
136
- * CSS-like padding shorthand (same syntax as margin).
137
- */
138
- padding?: `${string} ${string}` | `${string} ${string} ${string} ${string}` | UnitValue;
139
- }
140
- /**
141
- * Font weight: keyword `"bold"` / `"normal"`, or numeric 100–900
142
- * following the CSS `font-weight` spec.
143
- */
144
- type FontWeight = 'bold' | 'normal' | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
145
- /** Text highlight / marker colors (matches Word highlight palette). */
146
- type HighlightColor = 'black' | 'blue' | 'cyan' | 'darkBlue' | 'darkCyan' | 'darkGray' | 'darkGreen' | 'darkMagenta' | 'darkRed' | 'darkYellow' | 'green' | 'lightGray' | 'magenta' | 'none' | 'red' | 'white' | 'yellow';
147
- /**
148
- * A map of class name → style rule.
149
- *
150
- * Used to define reusable named styles referenced via `className` on nodes.
151
- *
152
- * @example
153
- * ```ts
154
- * const styles = defineStyles({
155
- * red: { color: '#ff0000' },
156
- * big: { fontSize: 20 },
157
- * })
158
- * ```
159
- */
160
- type StyleSheet = Record<string, DocxStyleRule>;
161
- /** Horizontal text alignment. */
162
- type TextAlign = 'center' | 'justify' | 'left' | 'right';
163
- /** Vertical alignment (for table cells). */
164
- type VerticalAlign = 'bottom' | 'middle' | 'top';
165
- /**
166
- * Define a type-safe stylesheet.
167
- *
168
- * `fontSize` defaults to pt when passed as a bare number.
169
- *
170
- * @param styles - — The stylesheet object
171
- * @returns The same stylesheet with `const` type inference
172
- *
173
- * @example
174
- * ```ts
175
- * const styles = defineStyles({
176
- * title: { fontSize: 28, fontWeight: 'bold' },
177
- * body: { fontSize: 12, lineHeight: 1.5 },
178
- * })
179
- * ```
180
- */
181
- declare function defineStyles<const T extends StyleSheet>(styles: T): T;
182
- //#endregion
183
- //#region src/types/document.d.ts
184
- /**
185
- * Top-level configuration passed to `createDocx()`.
186
- *
187
- * Covers page setup, stylesheet, theme tokens, element defaults,
188
- * and document metadata.
189
- *
190
- * @template TStyles — The user's stylesheet type (inferred from `styles`).
191
- */
192
- interface DocxKitConfig<TStyles extends StyleSheet = StyleSheet> {
193
- /** Page dimensions and margins. */
194
- page?: PageConfig;
195
- /** Named style classes (class → style rule map). */
196
- styles?: TStyles;
197
- /** Semantic design tokens for theming. */
198
- theme?: DocxTheme;
199
- /** Default styles applied as base for each element type. */
200
- defaults?: {
201
- /** Default table cell style. */cell?: DocxStyleRule; /** Default image style (applied to the paragraph wrapping the image). */
202
- image?: DocxStyleRule; /** Default paragraph style. */
203
- paragraph?: DocxStyleRule; /** Default table style. */
204
- table?: DocxStyleRule; /** Default text run style. */
205
- text?: DocxStyleRule;
206
- };
207
- /** OOXML core properties (appear in File → Info). */
208
- metadata?: {
209
- /** Document author. */creator?: string; /** Document description / summary. */
210
- description?: string; /** Keywords / tags. */
211
- keywords?: string[]; /** Last editor. */
212
- lastModifiedBy?: string; /** Document subject. */
213
- subject?: string; /** Document title. */
214
- title?: string;
215
- };
216
- }
217
- /**
218
- * Theme tokens that can be referenced in styles.
219
- *
220
- * Allows defining a single source of truth for colors, fonts,
221
- * font sizes, and spacing values.
222
- */
223
- interface DocxTheme {
224
- /** Color palette (name → hex). */
225
- colors?: Record<string, string>;
226
- /** Font family tokens (name → font family). */
227
- fontFamily?: Record<string, string>;
228
- /** Font size tokens (name → value). */
229
- fontSize?: Record<string, UnitValue>;
230
- /** Spacing tokens (name → value). */
231
- spacing?: Record<string, UnitValue>;
232
- }
233
- /**
234
- * Header/footer configuration for a section.
235
- *
236
- * Supports standard, first-page, and even-page variants.
237
- *
238
- * @example
239
- * ```ts
240
- * {
241
- * default: { children: ['Chapter 1'] },
242
- * first: { children: ['Title Page'] },
243
- * }
244
- * ```
245
- */
246
- interface HeaderFooterConfig {
247
- /** Default header/footer (appears on all pages). */
248
- default?: HeaderFooterContent;
249
- /** Even-page header/footer (overrides default on even pages). */
250
- even?: HeaderFooterContent;
251
- /** First-page-only header/footer (overrides default on page 1). */
252
- first?: HeaderFooterContent;
253
- }
254
- /**
255
- * Content for a header or footer — a list of text strings.
256
- *
257
- * Each string maps to a `Paragraph` in the compiled .docx output.
258
- * Future versions may support richer content (tables, images, page numbers).
259
- *
260
- * @example
261
- * ```ts
262
- * { default: ['Company Name', 'Confidential'] }
263
- * ```
264
- */
265
- interface HeaderFooterContent {
266
- /** Paragraph text lines. */
267
- children: string[];
268
- }
269
- /** Page orientation. */
270
- type Orientation = 'landscape' | 'portrait';
271
- /**
272
- * Page configuration (size, orientation, margin).
273
- */
274
- interface PageConfig {
275
- /** Page orientation (`"portrait"` default). */
276
- orientation?: Orientation;
277
- /** Page size: preset name or explicit dimensions. */
278
- size?: PageSize | {
279
- height: UnitValue;
280
- width: UnitValue;
281
- };
282
- /**
283
- * Page margin.
284
- *
285
- * Supports 1-value, 2-value, and 4-value shorthand
286
- * (e.g. `"20mm"`, `"20mm 15mm"`, `"20mm 15mm 25mm 15mm"`).
287
- */
288
- margin?: `${string} ${string}` | `${string} ${string} ${string} ${string}` | UnitValue;
289
- }
290
- /** Available page size presets. */
291
- type PageSize = 'A3' | 'A4' | 'Legal' | 'Letter';
292
- /**
293
- * Per-section configuration.
294
- *
295
- * Each call to `.section(config)` starts a new document section, which
296
- * can have its own page setup, headers, and footers independent of other
297
- * sections.
298
- *
299
- * @example
300
- * ```ts
301
- * doc.section({
302
- * page: { size: 'A3', orientation: 'landscape' },
303
- * header: { default: { children: ['Wide Page'] } },
304
- * })
305
- * ```
306
- */
307
- interface SectionConfig {
308
- /** Section footer(s). */
309
- footer?: HeaderFooterConfig;
310
- /** Section header(s). */
311
- header?: HeaderFooterConfig;
312
- /** Section-specific page dimensions (overrides document-level `page`). */
313
- page?: PageConfig;
314
- }
315
- //#endregion
316
- //#region src/dsl/nodes.d.ts
317
- /**
318
- * Common properties shared by all nodes.
319
- *
320
- * @template TStyles — The user's stylesheet type
321
- */
322
- interface BaseNode<TStyles extends StyleSheet = StyleSheet> {
323
- /**
324
- * CSS-like class name(s) referencing stylesheet entries.
325
- *
326
- * Can be a single string, an array, or a space-separated string.
327
- */
328
- className?: string | ClassName<TStyles> | ClassName<TStyles>[];
329
- /** Optional unique identifier (for templating / references). */
330
- id?: string;
331
- /** Inline style override for this specific node. */
332
- style?: DocxStyleRule;
333
- }
334
- /**
335
- * Union of all top-level content node types.
336
- *
337
- * @template TStyles — The user's stylesheet type
338
- */
339
- type BlockNode<TStyles extends StyleSheet = StyleSheet> = BulletListNode<TStyles> | HeadingNode<TStyles> | HyperlinkNode<TStyles> | ImageNode<TStyles> | NumberedListNode<TStyles> | PageBreakNode | ParagraphNode<TStyles> | PluginNode<string, unknown, TStyles> | SectionBreakNode | TableNode<Record<string, unknown>, TStyles>;
340
- /**
341
- * A structured list item (for rich bullet/numbered items).
342
- *
343
- * @template TStyles — The user's stylesheet type
344
- */
345
- interface BulletItem<TStyles extends StyleSheet = StyleSheet> extends BaseNode<TStyles> {
346
- /** Item text content. */
347
- text: string;
348
- /** Optional inline children override (instead of text). */
349
- children?: InlineNode<TStyles>[];
350
- }
351
- /**
352
- * A bullet list node.
353
- *
354
- * Supports plain string items or structured items with children.
355
- *
356
- * @template TStyles — The user's stylesheet type
357
- */
358
- interface BulletListNode<TStyles extends StyleSheet = StyleSheet> extends BaseNode<TStyles> {
359
- /** List items — strings or structured items. */
360
- items: (string | BulletItem<TStyles>)[];
361
- type: 'bulletList';
362
- /** Bullet character / style. Default: `'•'`. */
363
- bullet?: string;
364
- /** Nested list level (0 = top-level). */
365
- level?: number;
366
- }
367
- /**
368
- * Extract valid class name keys from a stylesheet type.
369
- *
370
- * @template TStyles — The user's stylesheet type
371
- */
372
- type ClassName<TStyles extends StyleSheet> = Extract<keyof TStyles, string>;
373
- /**
374
- * A heading node (h1–h6).
375
- *
376
- * @template TStyles — The user's stylesheet type
377
- */
378
- interface HeadingNode<TStyles extends StyleSheet = StyleSheet> extends BaseNode<TStyles> {
379
- /** Heading level (1 = largest, 6 = smallest). */
380
- level: 1 | 2 | 3 | 4 | 5 | 6;
381
- /** Heading text content. */
382
- text: string;
383
- type: 'heading';
384
- }
385
- /**
386
- * A hyperlink node (inline content that creates a clickable link).
387
- *
388
- * @template TStyles — The user's stylesheet type
389
- */
390
- interface HyperlinkNode<TStyles extends StyleSheet = StyleSheet> extends BaseNode<TStyles> {
391
- /** Display text or inline children. */
392
- children: (string | TextNode<TStyles>)[];
393
- type: 'hyperlink';
394
- /** Link target URL. */
395
- url: string;
396
- }
397
- /**
398
- * An image node.
399
- *
400
- * Supports raw bytes (`Uint8Array`, `ArrayBuffer`, `Blob`) or a file path string.
401
- *
402
- * @template TStyles — The user's stylesheet type
403
- */
404
- interface ImageNode<TStyles extends StyleSheet = StyleSheet> extends BaseNode<TStyles> {
405
- /** Image data as bytes, blob, or file path. */
406
- data: string | ArrayBuffer | Blob | Uint8Array;
407
- type: 'image';
408
- /** Alt text for accessibility. */
409
- alt?: string;
410
- /** Display height. */
411
- height?: UnitValue;
412
- /** Image format hint. Auto-detected if omitted. */
413
- imageType?: 'bmp' | 'gif' | 'jpeg' | 'jpg' | 'png';
414
- /** Display width. */
415
- width?: UnitValue;
416
- /**
417
- * Floating layout configuration.
418
- *
419
- * - `true` enables default floating
420
- * - Object allows wrap mode and position offsets
421
- */
422
- floating?: boolean | {
423
- /** Text wrap mode. */wrap?: 'square' | 'tight' | 'topAndBottom'; /** Horizontal offset. */
424
- x?: UnitValue; /** Vertical offset. */
425
- y?: UnitValue;
426
- };
427
- }
428
- /**
429
- * Union of inline content node types (appear inside paragraphs).
430
- *
431
- * @template TStyles — The user's stylesheet type
432
- */
433
- type InlineNode<TStyles extends StyleSheet = StyleSheet> = HyperlinkNode<TStyles> | ImageNode<TStyles> | TextNode<TStyles>;
434
- /**
435
- * A numbered / ordered list node.
436
- *
437
- * @template TStyles — The user's stylesheet type
438
- */
439
- interface NumberedListNode<TStyles extends StyleSheet = StyleSheet> extends BaseNode<TStyles> {
440
- /** List items. */
441
- items: (string | BulletItem<TStyles>)[];
442
- type: 'numberedList';
443
- /** Nested list level (0 = top-level). */
444
- level?: number;
445
- /** Starting number (default: 1). */
446
- start?: number;
447
- /**
448
- * Numbering format.
449
- *
450
- * {@link `LevelFormat.DECIMAL`} by default.
451
- * e.g. `'decimal'`, `'upperRoman'`, `'lowerLetter'`
452
- */
453
- numberingFormat?: 'decimal' | 'lowerLetter' | 'lowerRoman' | 'upperLetter' | 'upperRoman';
454
- }
455
- /**
456
- * A forced page break.
457
- */
458
- interface PageBreakNode {
459
- type: 'pageBreak';
460
- }
461
- /**
462
- * A paragraph containing text and/or inline children.
463
- *
464
- * @template TStyles — The user's stylesheet type
465
- */
466
- interface ParagraphNode<TStyles extends StyleSheet = StyleSheet> extends BaseNode<TStyles> {
467
- type: 'paragraph';
468
- /** Inline children (text runs, inline images, etc.). */
469
- children?: InlineNode<TStyles>[];
470
- /** Plain-text content (used when `children` is not provided). */
471
- text?: string;
472
- }
473
- /**
474
- * A plugin-invocation node.
475
- *
476
- * Plugins extend the DSL with arbitrary content types.
477
- *
478
- * @template TName — Plugin name (string literal)
479
- * @template TOptions — Plugin-specific options shape
480
- * @template TStyles — The user's stylesheet type
481
- */
482
- interface PluginNode<TName extends string = string, TOptions = unknown, TStyles extends StyleSheet = StyleSheet> extends BaseNode<TStyles> {
483
- /** Registered plugin name. */
484
- name: TName;
485
- /** Plugin-specific options. */
486
- options: TOptions;
487
- type: 'plugin';
488
- }
489
- /**
490
- * Internal marker node that represents a section boundary.
491
- *
492
- * Created automatically by {@link DocxBuilder.section} — users should
493
- * not create this node directly.
494
- *
495
- * When the compiler encounters this marker, it starts a new section
496
- * with the provided configuration.
497
- */
498
- interface SectionBreakNode {
499
- type: 'sectionBreak';
500
- /** Optional per-section page/header/footer overrides. */
501
- config?: SectionConfig;
502
- }
503
- /**
504
- * A column definition for a table.
505
- *
506
- * @template TData — The row data type
507
- */
508
- interface TableColumn<TData extends Record<string, unknown> = Record<string, unknown>> {
509
- /** Key in the data object this column maps to. */
510
- key: Extract<keyof TData, string>;
511
- /** Column header text. */
512
- title: string;
513
- /** Cell text alignment. */
514
- align?: 'center' | 'left' | 'right';
515
- /**
516
- * Span multiple columns horizontally.
517
- *
518
- * Applied to all cells in this column.
519
- */
520
- colSpan?: number;
521
- /**
522
- * Span multiple rows vertically (per-cell via data hints).
523
- *
524
- * Set `rowSpan` on individual data objects using `_rowSpan: N` or keep it
525
- * as a static column default.
526
- */
527
- rowSpan?: number;
528
- /** Column width. Supports percentage strings (e.g. `"30%"`). */
529
- width?: UnitValue;
530
- /**
531
- * Custom cell renderer.
532
- *
533
- * Receives the raw value, full row data, and row index.
534
- * Returns a string or inline nodes.
535
- */
536
- render?: (value: TData[keyof TData], row: TData, index: number) => string | InlineNode[];
537
- }
538
- /**
539
- * A table node with column definitions and data rows.
540
- *
541
- * @template TData — The row data type
542
- * @template TStyles — The user's stylesheet type
543
- */
544
- interface TableNode<TData extends Record<string, unknown> = Record<string, unknown>, TStyles extends StyleSheet = StyleSheet> extends BaseNode<TStyles> {
545
- /** Column definitions. */
546
- columns: TableColumn<TData>[];
547
- /** Row data objects. */
548
- data: TData[];
549
- type: 'table';
550
- /** Show table borders. */
551
- bordered?: boolean;
552
- /** Default cell style for data rows. */
553
- cellStyle?: DocxStyleRule;
554
- /** Show header row (default: `true`). */
555
- header?: boolean;
556
- /** Style for header cells. */
557
- headerCellStyle?: DocxStyleRule;
558
- /** Alternate row shading. */
559
- striped?: boolean;
560
- }
561
- /**
562
- * A text run node (inline content).
563
- *
564
- * @template TStyles — The user's stylesheet type
565
- */
566
- interface TextNode<TStyles extends StyleSheet = StyleSheet> extends BaseNode<TStyles> {
567
- /** Text content. */
568
- text: string;
569
- type: 'text';
570
- }
571
- //#endregion
572
- //#region src/types/plugin.d.ts
573
- /**
574
- * A docx-kit plugin.
575
- *
576
- * Plugins have a unique `name`, an optional `setup` hook,
577
- * and a required `render` function that receives user options
578
- * and a rendering context.
579
- *
580
- * @template TName — The plugin name (string literal type)
581
- * @template TOptions — The shape of the user-provided options
582
- */
583
- interface DocxPlugin<TName extends string = string, TOptions = unknown> {
584
- /** Unique plugin name, used as the node discriminator. */
585
- name: TName;
586
- /** One-time setup called when the plugin is registered. */
587
- setup?: () => MaybePromise<void>;
588
- /**
589
- * Render plugin content into one or more `docx` objects
590
- * (Paragraph, Table, etc.).
591
- *
592
- * @param options - — User-provided plugin options
593
- * @param context - — Rendering context with helper utilities
594
- */
595
- render: (options: TOptions, context: PluginRenderContext) => MaybePromise<unknown>;
596
- }
597
- /**
598
- * Type-level map of plugin name → options type.
599
- *
600
- * Constructed via `Builder.use()` chaining.
601
- */
602
- type PluginRegistry = Record<string, unknown>;
603
- /**
604
- * Rendering context passed to a plugin's `render()` function.
605
- *
606
- * Provides access to the document config, image utilities,
607
- * and the ability to compile child nodes.
608
- */
609
- interface PluginRenderContext {
610
- /** The full document config. */
611
- config: DocxKitConfig;
612
- /** Compile a child node (useful for nesting). */
613
- compileNode: (node: BlockNode) => Promise<unknown>;
614
- /** Utility helpers. */
615
- utils: {
616
- image: {
617
- /** Convert a Blob to raw image bytes. */fromBlob: (blob: Blob) => Promise<Uint8Array>;
618
- /**
619
- * Decode a base64 data-URL to raw image bytes.
620
- * Works in both browser and Node.js environments.
621
- */
622
- fromDataUrl: (dataUrl: string) => MaybePromise<Uint8Array>;
623
- };
624
- };
625
- }
626
- /**
627
- * Define a type-safe plugin with full inference.
628
- *
629
- * @param plugin - — The plugin definition object
630
- * @returns The same plugin with `const` type inference
631
- *
632
- * @example
633
- * ```ts
634
- * const myPlugin = definePlugin<'badge', { text: string }>({
635
- * name: 'badge',
636
- * render: async (opts, ctx) => {
637
- * // ... render logic
638
- * return new Paragraph({ text: opts.text })
639
- * },
640
- * })
641
- * ```
642
- */
643
- declare function definePlugin<const TName extends string, TOptions>(plugin: DocxPlugin<TName, TOptions>): DocxPlugin<TName, TOptions>;
644
- //#endregion
645
- //#region src/plugins/qrcode/index.d.ts
646
- /**
647
- * QR Code plugin — embeds a QR code image in the document.
648
- *
649
- * Uses the `qrcode` package (peer dependency) to generate
650
- * a QR code PNG and renders it as an inline `ImageRun`.
651
- *
652
- * @module plugins/qrcode
653
- *
654
- * @example
655
- * ```ts
656
- * const doc = createDocx()
657
- * .use(qrcodePlugin())
658
- * .h1('Scan Me')
659
- * .plugin('qrcode', { text: 'https://example.com', caption: 'Visit us' })
660
- * .save('qrcode.docx')
661
- * ```
662
- */
663
- /**
664
- * Options for the QRCode plugin.
665
- */
666
- interface QRCodePluginOptions {
667
- /** The text / URL to encode. */
668
- text: string;
669
- /** Optional caption text displayed below the QR code. */
670
- caption?: string;
671
- /**
672
- * QR error correction level.
673
- *
674
- * - `"L"` — ~7% recovery
675
- * - `"M"` — ~15% recovery
676
- * - `"Q"` — ~25% recovery
677
- * - `"H"` — ~30% recovery
678
- *
679
- * @default "M"
680
- */
681
- errorCorrectionLevel?: 'H' | 'L' | 'M' | 'Q';
682
- /** QR code margin (in modules). @default 1 */
683
- margin?: number;
684
- /** QR code image size in pixels. @default 128 */
685
- size?: number;
686
- }
687
- /**
688
- * Create a QRCode plugin instance.
689
- *
690
- * The plugin dynamically imports the `qrcode` package at render time,
691
- * keeping it an optional peer dependency of docx-kit core.
692
- *
693
- * @returns A configured DocxPlugin for `'qrcode'`
694
- *
695
- * @example
696
- * ```ts
697
- * import { createDocx, qrcodePlugin } from 'docx-kit'
698
- *
699
- * const doc = createDocx()
700
- * .use(qrcodePlugin())
701
- * .plugin('qrcode', {
702
- * text: 'https://example.com',
703
- * size: 256,
704
- * errorCorrectionLevel: 'H',
705
- * caption: 'Scan to visit',
706
- * })
707
- * ```
708
- */
709
- declare function qrcodePlugin(): DocxPlugin<"qrcode", QRCodePluginOptions>;
710
- //#endregion
711
- //#region src/plugins/callout/index.d.ts
712
- /**
713
- * Callout plugin — colored info / warning / success / danger boxes.
714
- *
715
- * Renders a single `Paragraph` with a prominent left border, a tinted
716
- * background, an emoji icon, an optional bold title, and body text.
717
- *
718
- * @module plugins/callout
719
- *
720
- * @example
721
- * ```ts
722
- * const doc = createDocx()
723
- * .use(calloutPlugin())
724
- * .plugin('callout', {
725
- * type: 'warning',
726
- * title: '注意',
727
- * content: '此操作不可撤销,请确认后再提交。',
728
- * })
729
- * .save('callout.docx')
730
- * ```
731
- */
732
- /** Options for the Callout plugin. */
733
- interface CalloutOptions {
734
- /** Body text of the callout. */
735
- content: string;
736
- /** Callout style — controls icon, color, and tone. */
737
- type: 'danger' | 'info' | 'success' | 'warning';
738
- /** Optional bold title line placed before the content. */
739
- title?: string;
740
- }
741
- /**
742
- * Create a Callout plugin instance.
743
- *
744
- * @returns A configured DocxPlugin for `'callout'`
745
- *
746
- * @example
747
- * ```ts
748
- * import { createDocx, calloutPlugin } from 'docx-kit'
749
- *
750
- * const doc = createDocx()
751
- * .use(calloutPlugin())
752
- * .plugin('callout', { type: 'info', content: '系统将在今晚 22:00 升级。' })
753
- * ```
754
- */
755
- declare function calloutPlugin(): DocxPlugin<"callout", CalloutOptions>;
756
- //#endregion
757
- //#region src/plugins/echarts/index.d.ts
758
- /**
759
- * Options for the ECharts plugin.
760
- */
761
- interface EChartsPluginOptions {
762
- /** Full ECharts option object (series, axes, title, etc.). */
763
- option: EChartsOption;
764
- /** Optional caption text displayed below the chart. */
765
- caption?: string;
766
- /** Chart height in pixels. @default 360 */
767
- height?: number;
768
- /** Output image format. @default "png" */
769
- imageType?: 'png' | 'svg';
770
- /** ECharts rendering engine. @default "canvas" */
771
- renderer?: 'canvas' | 'svg';
772
- /** Chart width in pixels. @default 640 */
773
- width?: number;
774
- }
775
- /**
776
- * Create an ECharts plugin instance.
777
- *
778
- * The plugin renders charts using the browser DOM. In Node.js
779
- * environments, it throws an error prompting the user to provide
780
- * a server-side canvas implementation.
781
- *
782
- * @returns A configured DocxPlugin for `'echarts'`
783
- *
784
- * @example
785
- * ```ts
786
- * import { createDocx, echartsPlugin } from 'docx-kit'
787
- *
788
- * const doc = createDocx()
789
- * .use(echartsPlugin())
790
- * .plugin('echarts', {
791
- * option: {
792
- * title: { text: 'Revenue' },
793
- * xAxis: { type: 'category', data: ['Q1', 'Q2', 'Q3', 'Q4'] },
794
- * yAxis: { type: 'value' },
795
- * series: [{ data: [820, 932, 901, 1347], type: 'line' }],
796
- * },
797
- * caption: 'Quarterly revenue trend',
798
- * })
799
- * ```
800
- */
801
- declare function echartsPlugin(): DocxPlugin<"echarts", EChartsPluginOptions>;
802
- //#endregion
803
- //#region src/builder/DocxBuilder.d.ts
804
- /**
805
- * Fluent document builder.
806
- *
807
- * Use `createDocx()` to instantiate, then chain `.h1()`, `.p()`, `.table()`,
808
- * etc. to build content. Call `.save()`, `.toBlob()`, `.toBuffer()`, or
809
- * `.toBase64()` to export the document.
810
- *
811
- * @template TStyles — Inferred stylesheet type from `config.styles`
812
- * @template TPlugins — Accumulated plugin registry (built via `.use()`)
813
- */
814
- declare class DocxBuilder<TStyles extends StyleSheet = StyleSheet, TPlugins extends PluginRegistry = Record<never, never>> {
815
- private readonly config;
816
- private readonly nodes;
817
- private readonly pendingSetups;
818
- private readonly pluginMap;
819
- constructor(config?: DocxKitConfig<TStyles>);
820
- /**
821
- * Add a raw DSL node to the document.
822
- *
823
- * @param node - — Any block-level node
824
- * @returns The builder (for chaining)
825
- *
826
- * @example
827
- * ```ts
828
- * doc.add({ type: 'heading', level: 2, text: 'Section' })
829
- * doc.add({ type: 'pageBreak' })
830
- * ```
831
- */
832
- add(node: BlockNode<TStyles>): this;
833
- /**
834
- * Add a bullet (unordered) list.
835
- *
836
- * @param items - — List items (strings or structured items)
837
- * @param options - — Optional bullet character, className, style, level
838
- * @returns The builder (for chaining)
839
- *
840
- * @example
841
- * ```ts
842
- * doc.bulletList(['Item 1', 'Item 2', 'Item 3'])
843
- * doc.bulletList([
844
- * 'Simple item',
845
- * { text: 'Rich item', className: 'highlight' },
846
- * ], { bullet: '\u25CB' })
847
- * ```
848
- */
849
- bulletList(items: (string | BulletItem<TStyles>)[], options?: Omit<Partial<BulletListNode<TStyles>>, 'items' | 'type'>): this;
850
- /**
851
- * Add a level-1 heading.
852
- *
853
- * @param text - — Heading text
854
- * @param options - — Optional style overrides (className, id, style)
855
- * @returns The builder (for chaining)
856
- *
857
- * @example
858
- * ```ts
859
- * doc.h1('Introduction', { className: 'title' })
860
- * ```
861
- */
862
- h1(text: string, options?: Omit<Partial<HeadingNode<TStyles>>, 'level' | 'text' | 'type'>): this;
863
- /**
864
- * Add a level-2 heading.
865
- *
866
- * @param text - — Heading text
867
- * @param options - — Optional style overrides
868
- * @returns The builder (for chaining)
869
- */
870
- h2(text: string, options?: Omit<Partial<HeadingNode<TStyles>>, 'level' | 'text' | 'type'>): this;
871
- /**
872
- * Add a level-3 heading.
873
- *
874
- * @param text - — Heading text
875
- * @param options - — Optional style overrides
876
- * @returns The builder (for chaining)
877
- */
878
- h3(text: string, options?: Omit<Partial<HeadingNode<TStyles>>, 'level' | 'text' | 'type'>): this;
879
- /**
880
- * Add a level-4 heading.
881
- *
882
- * @param text - — Heading text
883
- * @param options - — Optional style overrides
884
- * @returns The builder (for chaining)
885
- */
886
- h4(text: string, options?: Omit<Partial<HeadingNode<TStyles>>, 'level' | 'text' | 'type'>): this;
887
- /**
888
- * Add a level-5 heading.
889
- *
890
- * @param text - — Heading text
891
- * @param options - — Optional style overrides
892
- * @returns The builder (for chaining)
893
- */
894
- h5(text: string, options?: Omit<Partial<HeadingNode<TStyles>>, 'level' | 'text' | 'type'>): this;
895
- /**
896
- * Add a level-6 heading.
897
- *
898
- * @param text - — Heading text
899
- * @param options - — Optional style overrides
900
- * @returns The builder (for chaining)
901
- */
902
- h6(text: string, options?: Omit<Partial<HeadingNode<TStyles>>, 'level' | 'text' | 'type'>): this;
903
- /**
904
- * Add a hyperlink.
905
- *
906
- * @param url - — Target URL
907
- * @param text - — Display text
908
- * @param options - — Optional style overrides
909
- * @returns The builder (for chaining)
910
- *
911
- * @example
912
- * ```ts
913
- * doc.hyperlink('https://example.com', 'Click here')
914
- * ```
915
- */
916
- hyperlink(url: string, text: string, options?: Omit<Partial<HyperlinkNode<TStyles>>, 'children' | 'type' | 'url'>): this;
917
- /**
918
- * Add an image node.
919
- *
920
- * @param options - — Image node options (data, width, height, etc.)
921
- * @returns The builder (for chaining)
922
- *
923
- * @example
924
- * ```ts
925
- * doc.image({ data: imageBytes, width: 400, height: 300 })
926
- * ```
927
- */
928
- image(options: Omit<ImageNode<TStyles>, 'type'>): this;
929
- /**
930
- * Add a numbered (ordered) list.
931
- *
932
- * @param items - — List items
933
- * @param options - — Optional numbering format, start, className, style, level
934
- * @returns The builder (for chaining)
935
- *
936
- * @example
937
- * ```ts
938
- * doc.numberedList(['First', 'Second', 'Third'])
939
- * doc.numberedList(
940
- * [{ text: 'Intro' }, { text: 'Body' }],
941
- * { numberingFormat: 'upperRoman', start: 1 },
942
- * )
943
- * ```
944
- */
945
- numberedList(items: (string | BulletItem<TStyles>)[], options?: Omit<Partial<NumberedListNode<TStyles>>, 'items' | 'type'>): this;
946
- /**
947
- * Add a paragraph.
948
- *
949
- * @param text - — Paragraph text content
950
- * @param options - — Optional style overrides (className, id, style)
951
- * @returns The builder (for chaining)
952
- *
953
- * @example
954
- * ```ts
955
- * doc.p('Hello world', { className: 'body', style: { textAlign: 'center' } })
956
- * ```
957
- */
958
- p(text: string, options?: Omit<Partial<ParagraphNode<TStyles>>, 'text' | 'type'>): this;
959
- /**
960
- * Add a forced page break.
961
- *
962
- * @returns The builder (for chaining)
963
- *
964
- * @example
965
- * ```ts
966
- * doc.h1('Chapter 1').pageBreak().h1('Chapter 2')
967
- * ```
968
- */
969
- pageBreak(): this;
970
- /**
971
- * Invoke a registered plugin.
972
- *
973
- * @param name - — Plugin name (must match a previously registered plugin)
974
- * @param options - — Plugin-specific options
975
- * @param style - — Optional inline style for the plugin's container
976
- * @returns The builder (for chaining)
977
- *
978
- * @example
979
- * ```ts
980
- * doc.use(qrcodePlugin()).plugin('qrcode', { text: 'https://example.com' })
981
- * ```
982
- */
983
- plugin<TName extends string & keyof TPlugins>(name: TName, options: TPlugins[TName], style?: DocxStyleRule): this;
984
- /**
985
- * Save the document to a file (Node.js only).
986
- *
987
- * **⚠️ Not available in browser environments.**
988
- * Use {@link toBlob} and trigger a download instead.
989
- *
990
- * @param filename - — Output file path (e.g. `"report.docx"`)
991
- *
992
- * @example
993
- * ```ts
994
- * await doc.save('output.docx')
995
- * ```
996
- */
997
- save(filename: string): Promise<void>;
998
- /**
999
- * Start a new document section.
1000
- *
1001
- * Each section can have its own page size, orientation, margins,
1002
- * headers, and footers. Content added after this call belongs to
1003
- * the new section.
1004
- *
1005
- * @param config - — Optional section-level page/header/footer overrides
1006
- * @returns The builder (for chaining)
1007
- *
1008
- * @example
1009
- * ```ts
1010
- * // Simple section break
1011
- * doc.p('Section 1 content').section().p('Section 2 content')
1012
- *
1013
- * // Section with custom page setup
1014
- * doc.section({ page: { size: 'A3', orientation: 'landscape' } })
1015
- * .h1('Wide table')
1016
- * .table({ columns: [...], data: [...] })
1017
- *
1018
- * // Section with header and footer
1019
- * doc.section({
1020
- * header: { default: { children: ['Chapter 2', 'Confidential'] } },
1021
- * footer: { default: { children: ['Page 2'] } },
1022
- * })
1023
- * ```
1024
- */
1025
- section(config?: SectionConfig): this;
1026
- /**
1027
- * Add a table.
1028
- *
1029
- * @param options - — Table node options (columns, data, style, etc.)
1030
- * @returns The builder (for chaining)
1031
- *
1032
- * @example
1033
- * ```ts
1034
- * doc.table({
1035
- * columns: [
1036
- * { key: 'name', title: 'Name' },
1037
- * { key: 'value', title: 'Value', align: 'right' },
1038
- * ],
1039
- * data: [{ name: 'Revenue', value: '$1.2M' }],
1040
- * headerCellStyle: { fontWeight: 'bold' },
1041
- * })
1042
- * ```
1043
- */
1044
- table<TData extends Record<string, unknown>>(options: Omit<TableNode<TData, TStyles>, 'type'>): this;
1045
- /**
1046
- * Export the document as a base64-encoded string.
1047
- *
1048
- * @returns Base64-encoded .docx data
1049
- *
1050
- * @example
1051
- * ```ts
1052
- * const b64 = await doc.toBase64()
1053
- * // Send b64 over HTTP or store in a database
1054
- * ```
1055
- */
1056
- toBase64(): Promise<string>;
1057
- /**
1058
- * Export the document as a `Blob` (browser-friendly).
1059
- *
1060
- * @returns A `Blob` containing the .docx binary
1061
- *
1062
- * @example
1063
- * ```ts
1064
- * const blob = await doc.toBlob()
1065
- * const url = URL.createObjectURL(blob)
1066
- * ```
1067
- */
1068
- toBlob(): Promise<Blob>;
1069
- /**
1070
- * Export the document as a `Uint8Array` (alias for {@link toUint8Array}).
1071
- *
1072
- * **Note:** Despite the name, this returns a standard `Uint8Array`,
1073
- * not a Node.js `Buffer`. Prefer using {@link toUint8Array} for clarity.
1074
- *
1075
- * @returns Raw .docx bytes
1076
- *
1077
- * @example
1078
- * ```ts
1079
- * const bytes = await doc.toBuffer()
1080
- * fs.writeFileSync('output.docx', bytes)
1081
- * ```
1082
- */
1083
- toBuffer(): Promise<Uint8Array>;
1084
- /**
1085
- * Compile and return the internal `docx` {@link Document} instance.
1086
- *
1087
- * Useful if you need to further manipulate the document with the
1088
- * raw `docx` library before packaging.
1089
- *
1090
- * @returns A `docx` `Document` object
1091
- */
1092
- toDocument(): Promise<import("docx").Document>;
1093
- /**
1094
- * Serialize the builder state to a JSON-friendly object.
1095
- *
1096
- * Useful for debugging, serialization, or AI-driven document generation.
1097
- *
1098
- * @returns The config + content node array as a plain object
1099
- */
1100
- toJSON(): {
1101
- content: BlockNode<TStyles>[];
1102
- page?: PageConfig;
1103
- styles?: TStyles | undefined;
1104
- theme?: DocxTheme;
1105
- defaults?: {
1106
- cell?: DocxStyleRule;
1107
- image?: DocxStyleRule;
1108
- paragraph?: DocxStyleRule;
1109
- table?: DocxStyleRule;
1110
- text?: DocxStyleRule;
1111
- };
1112
- metadata?: {
1113
- creator?: string;
1114
- description?: string;
1115
- keywords?: string[];
1116
- lastModifiedBy?: string;
1117
- subject?: string;
1118
- title?: string;
1119
- };
1120
- };
1121
- /**
1122
- * Export the document as a `Uint8Array` (browser & Node.js).
1123
- *
1124
- * This is the preferred cross-platform export method.
1125
- *
1126
- * @returns Raw .docx bytes
1127
- *
1128
- * @example
1129
- * ```ts
1130
- * const bytes = await doc.toUint8Array()
1131
- * // In Node.js: import { writeFileSync } from 'node:fs'
1132
- * // In browser: trigger a download
1133
- * ```
1134
- */
1135
- toUint8Array(): Promise<Uint8Array>;
1136
- /**
1137
- * Register a plugin.
1138
- *
1139
- * The plugin's name and options type are accumulated into the builder's
1140
- * type-level plugin registry, enabling type-safe `.plugin()` calls.
1141
- *
1142
- * @param plugin - — The plugin definition returned by `definePlugin()`
1143
- * @returns The builder with the plugin type merged into `TPlugins`
1144
- *
1145
- * @example
1146
- * ```ts
1147
- * const doc = createDocx()
1148
- * .use(qrcodePlugin())
1149
- * .plugin('qrcode', { text: 'https://example.com' })
1150
- * ```
1151
- */
1152
- use<TName extends string, TOptions>(plugin: DocxPlugin<TName, TOptions>): DocxBuilder<TStyles, Record<TName, TOptions> & TPlugins>;
1153
- }
1154
- //#endregion
1155
- //#region src/plugins/timeline/index.d.ts
1156
- /**
1157
- * Timeline plugin — renders a chronological timeline as a styled table.
1158
- *
1159
- * Each event occupies one table row: a date cell, a visual connector
1160
- * cell, and a content cell (title + optional description).
1161
- *
1162
- * @module plugins/timeline
1163
- *
1164
- * @example
1165
- * ```ts
1166
- * const doc = createDocx()
1167
- * .use(timelinePlugin())
1168
- * .plugin('timeline', {
1169
- * events: [
1170
- * { date: '2026-01', title: '项目立项', description: '完成需求评审' },
1171
- * { date: '2026-03', title: 'MVP 发布', description: '核心功能上线' },
1172
- * ],
1173
- * })
1174
- * .save('timeline.docx')
1175
- * ```
1176
- */
1177
- /** A single timeline event. */
1178
- interface TimelineEvent {
1179
- /** Date / time label (e.g. "2026-06" or "Q3"). */
1180
- date: string;
1181
- /** Short event title. */
1182
- title: string;
1183
- /** Optional longer description. */
1184
- description?: string;
1185
- }
1186
- /** Options for the Timeline plugin. */
1187
- interface TimelineOptions {
1188
- /** Array of timeline events in chronological order. */
1189
- events: TimelineEvent[];
1190
- /**
1191
- * Accent color for the connector line and date highlight.
1192
- * @default '4472C4'
1193
- */
1194
- accentColor?: string;
1195
- /**
1196
- * Layout style.
1197
- *
1198
- * - `'alternating'` — dates alternate left / right (default)
1199
- * - `'left'` — all dates on the left, content on the right
1200
- * - `'right'` — all content on the left, dates on the right
1201
- *
1202
- * @default 'alternating'
1203
- */
1204
- layout?: 'alternating' | 'left' | 'right';
1205
- }
1206
- /**
1207
- * Create a Timeline plugin instance.
1208
- *
1209
- * @returns A configured DocxPlugin for `'timeline'`
1210
- *
1211
- * @example
1212
- * ```ts
1213
- * import { createDocx, timelinePlugin } from 'docx-kit'
1214
- *
1215
- * const doc = createDocx()
1216
- * .use(timelinePlugin())
1217
- * .plugin('timeline', {
1218
- * events: [
1219
- * { date: '2026-01', title: '项目启动', description: '团队组建完成' },
1220
- * { date: '2026-04', title: 'Beta 测试', description: '收集用户反馈' },
1221
- * { date: '2026-06', title: '正式发布' },
1222
- * ],
1223
- * })
1224
- * ```
1225
- */
1226
- declare function timelinePlugin(): DocxPlugin<"timeline", TimelineOptions>;
1227
- //#endregion
1228
- //#region src/errors.d.ts
1229
- /**
1230
- * Error handling types and classes for docx-kit.
1231
- *
1232
- * @module errors
1233
- */
1234
- /**
1235
- * Well-known error codes used throughout the library.
1236
- *
1237
- * Consumers can match against these codes for structured error handling.
1238
- */
1239
- declare const ERROR_CODES: {
1240
- /** Document export failed. */readonly EXPORT_FAILED: "EXPORT_FAILED"; /** Image data is empty, corrupt, or unsupported. */
1241
- readonly IMAGE_INVALID_DATA: "IMAGE_INVALID_DATA"; /** A plugin node referenced an unregistered plugin. */
1242
- readonly PLUGIN_NOT_REGISTERED: "PLUGIN_NOT_REGISTERED"; /** A plugin's `render()` method threw an error. */
1243
- readonly PLUGIN_RENDER_FAILED: "PLUGIN_RENDER_FAILED"; /** A `className` referenced a stylesheet key that doesn't exist. */
1244
- readonly STYLE_UNKNOWN_CLASS: "STYLE_UNKNOWN_CLASS"; /** Table was created with no columns. */
1245
- readonly TABLE_INVALID_COLUMNS: "TABLE_INVALID_COLUMNS"; /** Encountered a node type that has no registered compiler. */
1246
- readonly UNKNOWN_NODE_TYPE: "UNKNOWN_NODE_TYPE";
1247
- };
1248
- /** Union type of all known error codes. */
1249
- type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
1250
- /**
1251
- * Structured error class for docx-kit.
1252
- *
1253
- * Carries a machine-readable `code`, a human-readable `message`,
1254
- * and optionally the underlying `cause`.
1255
- *
1256
- * @example
1257
- * ```ts
1258
- * try {
1259
- * await doc.save('output.docx')
1260
- * } catch (err) {
1261
- * if (err instanceof DocxKitError && err.code === ERROR_CODES.EXPORT_FAILED) {
1262
- * console.error('Export failed:', err.message)
1263
- * }
1264
- * }
1265
- * ```
1266
- */
1267
- declare class DocxKitError extends Error {
1268
- /** The underlying error that caused this failure (if any). */
1269
- readonly cause: unknown;
1270
- /** Machine-readable error code. */
1271
- readonly code: string | ErrorCode;
1272
- /**
1273
- * @param code - — Known error code from {@link ERROR_CODES}
1274
- * @param message - — Human-readable description
1275
- * @param cause - — Optional underlying error
1276
- */
1277
- constructor(code: string | ErrorCode, message: string, cause?: unknown);
1278
- }
1279
- //#endregion
1280
- //#region src/plugins/watermark/index.d.ts
1281
- /** Options for the Watermark plugin. */
1282
- interface WatermarkOptions {
1283
- /** Watermark text. */
1284
- text: string;
1285
- /**
1286
- * Horizontal alignment.
1287
- * @default 'center'
1288
- */
1289
- alignment?: (typeof AlignmentType)[keyof typeof AlignmentType];
1290
- /**
1291
- * Text color in hex RRGGBB.
1292
- * @default 'BFBFBF'
1293
- */
1294
- color?: string;
1295
- /**
1296
- * Font size in half-points (20 = 10pt).
1297
- * @default 48
1298
- */
1299
- fontSize?: number;
1300
- }
1301
- /**
1302
- * Create a Watermark plugin instance.
1303
- *
1304
- * @returns A configured DocxPlugin for `'watermark'`
1305
- *
1306
- * @example
1307
- * ```ts
1308
- * import { createDocx, watermarkPlugin } from 'docx-kit'
1309
- *
1310
- * const doc = createDocx()
1311
- * .use(watermarkPlugin())
1312
- * .plugin('watermark', { text: 'DRAFT', color: 'FF0000' })
1313
- * ```
1314
- */
1315
- declare function watermarkPlugin(): DocxPlugin<"watermark", WatermarkOptions>;
1316
- //#endregion
1317
- //#region src/plugins/code-block/index.d.ts
1318
- /**
1319
- * Code Block plugin — renders source code with monospaced font and
1320
- * optional line numbers and syntax highlighting.
1321
- *
1322
- * Syntax highlighting requires `highlight.js` as an optional peer dependency.
1323
- * When unavailable (or when `language` is not provided), the plugin falls
1324
- * back to plain monospaced rendering.
1325
- *
1326
- * @module plugins/code-block
1327
- *
1328
- * @example
1329
- * ```ts
1330
- * const doc = createDocx()
1331
- * .use(codeBlockPlugin())
1332
- * .plugin('codeBlock', {
1333
- * code: `export function hello() {\n return "world"\n}`,
1334
- * language: 'typescript',
1335
- * showLineNumbers: true,
1336
- * })
1337
- * .save('code.docx')
1338
- * ```
1339
- */
1340
- /** Options for the CodeBlock plugin. */
1341
- interface CodeBlockOptions {
1342
- /** Source code string. */
1343
- code: string;
1344
- /**
1345
- * Language identifier for syntax highlighting (optional).
1346
- *
1347
- * Requires `highlight.js` as a peer dependency. Falls back
1348
- * to monospaced rendering when the package is not installed.
1349
- */
1350
- language?: string;
1351
- /** Prepend line numbers. @default false */
1352
- showLineNumbers?: boolean;
1353
- }
1354
- /**
1355
- * Create a CodeBlock plugin instance.
1356
- *
1357
- * @returns A configured DocxPlugin for `'codeBlock'`
1358
- */
1359
- declare function codeBlockPlugin(): DocxPlugin<"codeBlock", CodeBlockOptions>;
1360
- //#endregion
1361
- //#region src/plugins/cover-page/index.d.ts
1362
- /** Options for the Cover Page plugin. */
1363
- interface CoverPageOptions {
1364
- /** Main title text (required). */
1365
- title: string;
1366
- /** Horizontal text alignment. @default CENTER */
1367
- alignment?: (typeof AlignmentType)[keyof typeof AlignmentType];
1368
- /** Author or department name. */
1369
- author?: string;
1370
- /** Background color of the cover page in hex RRGGBB. */
1371
- backgroundColor?: string;
1372
- /** Date string (e.g. "2026-06-11"). */
1373
- date?: string;
1374
- /** Organization / company name. */
1375
- organization?: string;
1376
- /**
1377
- * Show a decorative horizontal rule between title and author.
1378
- * @default true
1379
- */
1380
- showRule?: boolean;
1381
- /** Sub-title text displayed below the title. */
1382
- subtitle?: string;
1383
- }
1384
- /**
1385
- * Create a Cover Page plugin instance.
1386
- *
1387
- * @returns A configured DocxPlugin for `'coverPage'`
1388
- *
1389
- * @example
1390
- * ```ts
1391
- * import { coverPagePlugin, createDocx } from 'docx-kit'
1392
- *
1393
- * const doc = createDocx()
1394
- * .use(coverPagePlugin())
1395
- * .plugin('coverPage', {
1396
- * title: '年度报告',
1397
- * subtitle: '2026',
1398
- * author: '战略发展部',
1399
- * organization: 'XX 科技集团',
1400
- * })
1401
- * ```
1402
- */
1403
- declare function coverPagePlugin(): DocxPlugin<"coverPage", CoverPageOptions>;
1404
- //#endregion
1405
- //#region src/plugins/data-table/index.d.ts
1406
- /**
1407
- * Data Table plugin — renders an array of objects as a styled table.
1408
- *
1409
- * Columns are auto-inferred from the first object’s keys. Column headers
1410
- * can be localised via `labels`, value formatting is controlled by `format`,
1411
- * and per-column alignment is controlled by `align`.
1412
- *
1413
- * @module plugins/data-table
1414
- *
1415
- * @example
1416
- * ```ts
1417
- * const doc = createDocx()
1418
- * .use(dataTablePlugin())
1419
- * .plugin('dataTable', {
1420
- * data: [
1421
- * { name: 'Alice', age: 30, salary: 85000 },
1422
- * { name: 'Bob', age: 25, salary: 62000 },
1423
- * ],
1424
- * labels: { name: '姓名', age: '年龄', salary: '薪资' },
1425
- * format: { salary: 'currency' },
1426
- * striped: true,
1427
- * })
1428
- * .save('table.docx')
1429
- * ```
1430
- */
1431
- /** Per-column alignment hint. */
1432
- type ColAlign = 'center' | 'left' | 'right';
1433
- /** Value formatter identifier. */
1434
- type ColFormat = 'currency' | 'date' | 'number' | 'percent';
1435
- /** Options for the DataTable plugin. */
1436
- interface DataTableOptions {
1437
- /**
1438
- * The data to render — each object is one row.
1439
- *
1440
- * Column keys are taken from the first object in the array.
1441
- */
1442
- data: Record<string, unknown>[];
1443
- /** Per-column alignment. Auto-detected from value types when omitted. */
1444
- align?: Record<string, ColAlign>;
1445
- /** Render visible table borders. @default true */
1446
- bordered?: boolean;
1447
- /** Per-column value formatter. */
1448
- format?: Record<string, ColFormat>;
1449
- /** Human-readable column labels (e.g. `{ salary: '薪资' }`). */
1450
- labels?: Record<string, string>;
1451
- /** Alternate row background shading. @default false */
1452
- striped?: boolean;
1453
- }
1454
- /**
1455
- * Create a DataTable plugin instance.
1456
- *
1457
- * @returns A configured DocxPlugin for `'dataTable'`
1458
- */
1459
- declare function dataTablePlugin(): DocxPlugin<"dataTable", DataTableOptions>;
1460
- //#endregion
1461
- //#region src/plugins/page-number/index.d.ts
1462
- /** Options for the Page Number plugin. */
1463
- interface PageNumberOptions {
1464
- /**
1465
- * Horizontal alignment of the page number.
1466
- * @default 'center'
1467
- */
1468
- alignment?: (typeof AlignmentType)[keyof typeof AlignmentType];
1469
- /**
1470
- * Font size in half-points.
1471
- * @default 20
1472
- */
1473
- fontSize?: number;
1474
- /**
1475
- * Show "Page X of Y" instead of just "X".
1476
- * @default false
1477
- */
1478
- showTotal?: boolean;
1479
- }
1480
- /**
1481
- * Create a Page Number plugin instance.
1482
- *
1483
- * @returns A configured DocxPlugin for `'pageNumber'`
1484
- *
1485
- * @example
1486
- * ```ts
1487
- * import { createDocx, pageNumberPlugin } from 'docx-kit'
1488
- *
1489
- * const doc = createDocx()
1490
- * .use(pageNumberPlugin())
1491
- * // Use the page number content in a footer
1492
- * const pn = doc.plugin('pageNumber', { alignment: 'center' })
1493
- * ```
1494
- */
1495
- declare function pageNumberPlugin(): DocxPlugin<"pageNumber", PageNumberOptions>;
1496
- //#endregion
1497
- //#region src/builder/createDocx.d.ts
1498
- /**
1499
- * JSON schema for `renderDocx()`.
1500
- *
1501
- * The schema is deliberately simple — a flat config object plus an
1502
- * ordered array of block nodes. This makes it easy to generate from
1503
- * AI / LLMs or store as JSON.
1504
- *
1505
- * @template TStyles — The user's stylesheet type
1506
- */
1507
- interface DocxSchema<TStyles extends StyleSheet = StyleSheet> {
1508
- /** Ordered array of block nodes. */
1509
- content: BlockNode<TStyles>[];
1510
- /** Optional page configuration. */
1511
- page?: DocxKitConfig<TStyles>['page'];
1512
- /** Named stylesheet entries. */
1513
- styles?: TStyles;
1514
- }
1515
- /**
1516
- * Create a new DocxBuilder with optional configuration.
1517
- *
1518
- * This is the primary entry point for the fluent builder API.
1519
- * Chain `.h1()`, `.p()`, `.table()`, etc. and call `.save()`
1520
- * or `.toBlob()` to export.
1521
- *
1522
- * @param config - — Document configuration (page, styles, metadata, theme, defaults)
1523
- * @returns A new `DocxBuilder` instance
1524
- *
1525
- * @example
1526
- * ```ts
1527
- * const styles = defineStyles({
1528
- * title: { fontSize: 28, fontWeight: 'bold' },
1529
- * body: { fontSize: 12, lineHeight: 1.5 },
1530
- * })
1531
- *
1532
- * const doc = createDocx({
1533
- * styles,
1534
- * page: { size: 'A4', margin: '20mm' },
1535
- * metadata: { title: 'Report', creator: 'docx-kit' },
1536
- * })
1537
- *
1538
- * await doc
1539
- * .h1('Annual Report', { className: 'title' })
1540
- * .p('Lorem ipsum...', { className: 'body' })
1541
- * .save('report.docx')
1542
- * ```
1543
- */
1544
- declare function createDocx<const TStyles extends StyleSheet = StyleSheet>(config?: DocxKitConfig<TStyles>): DocxBuilder<TStyles, Record<never, never>>;
1545
- /**
1546
- * Render a document from a JSON schema (AI-friendly / serializable DSL).
1547
- *
1548
- * Unlike `createDocx()`, this accepts a single JSON-serializable object
1549
- * with `content` (node array), optional `styles`, and optional `page` config.
1550
- * Ideal for AI-driven document generation or API integrations.
1551
- *
1552
- * @param schema - — The `DocxSchema` object
1553
- * @returns A `DocxBuilder` instance (ready to export)
1554
- *
1555
- * @example
1556
- * ```ts
1557
- * const blob = await renderDocx({
1558
- * page: { size: 'A4', margin: '20mm' },
1559
- * styles: {
1560
- * h1: { fontSize: 24, fontWeight: 'bold' },
1561
- * p: { fontSize: 12 },
1562
- * },
1563
- * content: [
1564
- * { type: 'heading', level: 1, text: 'Report', className: 'h1' },
1565
- * { type: 'paragraph', text: 'This is a report generated via JSON DSL.', className: 'p' },
1566
- * { type: 'pageBreak' },
1567
- * {
1568
- * type: 'table',
1569
- * columns: [{ key: 'name', title: 'Name' }, { key: 'value', title: 'Value' }],
1570
- * data: [{ name: 'Revenue', value: '$1.2M' }],
1571
- * },
1572
- * ],
1573
- * }).toBlob()
1574
- * ```
1575
- */
1576
- declare function renderDocx<const TStyles extends StyleSheet = StyleSheet>(schema: DocxSchema<TStyles>): DocxBuilder<TStyles>;
1577
- //#endregion
1578
- //#region src/plugins/property-table/index.d.ts
1579
- /**
1580
- * Property Table plugin — renders key-value pairs as a styled 2-column table.
1581
- *
1582
- * The key column is right-aligned with gray background; the value column
1583
- * is left-aligned. Ideal for config tables, parameter docs, and spec sheets.
1584
- *
1585
- * @module plugins/property-table
1586
- *
1587
- * @example
1588
- * ```ts
1589
- * const doc = createDocx()
1590
- * .use(propertyTablePlugin())
1591
- * .plugin('propertyTable', {
1592
- * items: [
1593
- * { key: '项目名称', value: 'XX管理系统' },
1594
- * { key: '技术栈', value: 'React + Node.js + PostgreSQL' },
1595
- * ],
1596
- * keyBold: true,
1597
- * })
1598
- * .save('props.docx')
1599
- * ```
1600
- */
1601
- /** A single key-value pair. */
1602
- interface PropertyItem {
1603
- key: string;
1604
- value: string;
1605
- }
1606
- /** Options for the PropertyTable plugin. */
1607
- interface PropertyTableOptions {
1608
- /** Key-value items to display. */
1609
- items: PropertyItem[];
1610
- /**
1611
- * Whether the key column text is bold. @default true
1612
- */
1613
- keyBold?: boolean;
1614
- /** Alternate row background shading. @default true */
1615
- striped?: boolean;
1616
- }
1617
- /**
1618
- * Create a PropertyTable plugin instance.
1619
- *
1620
- * @returns A configured DocxPlugin for `'propertyTable'`
1621
- */
1622
- declare function propertyTablePlugin(): DocxPlugin<"propertyTable", PropertyTableOptions>;
1623
- //#endregion
1624
- //#region src/plugins/meeting-minutes/index.d.ts
1625
- /**
1626
- * Meeting Minutes plugin — structured meeting notes with header, meta info,
1627
- * and an agenda table.
1628
- *
1629
- * Renders a title paragraph, a date/attendees summary line, and a 4-column
1630
- * agenda table (Topic | Discussion | Decision | Owner).
1631
- *
1632
- * @module plugins/meeting-minutes
1633
- *
1634
- * @example
1635
- * ```ts
1636
- * const doc = createDocx()
1637
- * .use(meetingMinutesPlugin())
1638
- * .plugin('meetingMinutes', {
1639
- * title: '项目周会纪要',
1640
- * date: '2026-06-11',
1641
- * attendees: ['张三', '李四', '王五'],
1642
- * agenda: [
1643
- * { topic: '项目进度', discussion: '模块A已完成80%', decision: '下周一上线', owner: '张三' },
1644
- * { topic: '风险项', discussion: '第三方API不稳定', decision: '增加重试机制', owner: '李四' },
1645
- * ],
1646
- * })
1647
- * .save('minutes.docx')
1648
- * ```
1649
- */
1650
- /** A single agenda item. */
1651
- interface AgendaItem {
1652
- /** Discussion notes. */
1653
- discussion: string;
1654
- /** Meeting topic. */
1655
- topic: string;
1656
- /** Decision made. */
1657
- decision?: string;
1658
- /** Responsible person. */
1659
- owner?: string;
1660
- }
1661
- /** Options for the MeetingMinutes plugin. */
1662
- interface MeetingMinutesOptions {
1663
- /** Agenda items to render in the table. */
1664
- agenda: AgendaItem[];
1665
- /** Attendee names. */
1666
- attendees: string[];
1667
- /** Meeting date (e.g. "2026-06-11"). */
1668
- date: string;
1669
- /** Meeting title (rendered as Heading 1). */
1670
- title: string;
1671
- }
1672
- /**
1673
- * Create a MeetingMinutes plugin instance.
1674
- *
1675
- * @returns A configured DocxPlugin for `'meetingMinutes'`
1676
- */
1677
- declare function meetingMinutesPlugin(): DocxPlugin<"meetingMinutes", MeetingMinutesOptions>;
1678
- //#endregion
1679
- //#region src/plugins/signature-block/index.d.ts
1680
- /**
1681
- * Signature Block plugin — renders signature lines for contracts and approvals.
1682
- *
1683
- * Each party gets a cell in a borderless table with a bold label,
1684
- * a signature line (underlined placeholder), and an optional date.
1685
- *
1686
- * @module plugins/signature-block
1687
- *
1688
- * @example
1689
- * ```ts
1690
- * const doc = createDocx()
1691
- * .use(signatureBlockPlugin())
1692
- * .plugin('signatureBlock', {
1693
- * parties: [
1694
- * { label: '甲方(盖章)', date: '2026年 月 日' },
1695
- * { label: '乙方(盖章)', date: '2026年 月 日' },
1696
- * ],
1697
- * columns: 2,
1698
- * })
1699
- * .save('signature.docx')
1700
- * ```
1701
- */
1702
- /** Options for the SignatureBlock plugin. */
1703
- interface SignatureBlockOptions {
1704
- /** The signing parties. */
1705
- parties: SignatureParty[];
1706
- /** Number of columns in the signature grid. @default 2 */
1707
- columns?: number;
1708
- }
1709
- /** A single party in a signature block. */
1710
- interface SignatureParty {
1711
- /** Party label (e.g. "甲方(盖章)"). */
1712
- label: string;
1713
- /** Pre-filled date (e.g. "2026年 月 日"). */
1714
- date?: string;
1715
- /** Pre-filled name (shown underlined when provided). */
1716
- name?: string;
1717
- }
1718
- /**
1719
- * Create a SignatureBlock plugin instance.
1720
- *
1721
- * @returns A configured DocxPlugin for `'signatureBlock'`
1722
- */
1723
- declare function signatureBlockPlugin(): DocxPlugin<"signatureBlock", SignatureBlockOptions>;
1724
- //#endregion
1725
- //#region src/presets/types.d.ts
1726
- /**
1727
- * A named, reusable style preset.
1728
- *
1729
- * Each preset provides a `config` object compatible with `DocxKitConfig`.
1730
- * Spread the config into `createDocx()` to apply the preset, or use the
1731
- * `usePreset()` helper for lookup by ID.
1732
- */
1733
- interface DocxPreset {
1734
- /** The config fragment to merge into `createDocx()`. */
1735
- readonly config: DocxKitConfig;
1736
- /** Short description of the preset's visual character. */
1737
- readonly description: string;
1738
- /** Machine-readable identifier (e.g. `"classic"`). */
1739
- readonly id: string;
1740
- /** Human-readable display name (e.g. `"Classic"`). */
1741
- readonly name: string;
1742
- }
1743
- //#endregion
1744
- //#region src/presets/academic.d.ts
1745
- declare const academicPreset: DocxPreset;
1746
- //#endregion
1747
- //#region src/presets/classic.d.ts
1748
- declare const classicPreset: DocxPreset;
1749
- //#endregion
1750
- //#region src/presets/modern.d.ts
1751
- declare const modernPreset: DocxPreset;
1752
- //#endregion
1753
- //#region src/presets/index.d.ts
1754
- /** Ordered list of built-in presets (for UI selectors). */
1755
- declare const PRESET_LIST: readonly DocxPreset[];
1756
- /**
1757
- * Look up a built-in preset by ID.
1758
- *
1759
- * @param id - — Preset identifier (`"classic"`, `"modern"`, or `"academic"`)
1760
- * @returns The matching preset, or `undefined` if not found
1761
- *
1762
- * @example
1763
- * ```ts
1764
- * const preset = usePreset('modern')
1765
- * const doc = createDocx(preset!.config)
1766
- * ```
1767
- */
1768
- declare function usePreset(id: string): DocxPreset | undefined;
1769
52
  //#endregion
1770
53
  //#region src/browser/dom.d.ts
1771
- /**
1772
- * Browser DOM utilities — base64 decoding and Blob/image handling.
1773
- *
1774
- * @module browser/dom
1775
- */
1776
- /**
1777
- * Decode a base64 data-URL to raw bytes using the browser `atob` API.
1778
- *
1779
- * Strips the `"data:*;base64,"` prefix, decodes the base64 string
1780
- * via `atob()`, and populates a `Uint8Array` from each character's
1781
- * code point.
1782
- *
1783
- * @param dataUrl - — A base64 data-URI string (e.g. `"data:image/png;base64,iVBO..."`)
1784
- * @returns Raw bytes as `Uint8Array`
1785
- *
1786
- * @example
1787
- * ```ts
1788
- * import { dataUrlToUint8Array } from 'docx-kit/browser'
1789
- *
1790
- * const bytes = await dataUrlToUint8Array('data:image/png;base64,iVBORw...')
1791
- * ```
1792
- */
1793
- declare function dataUrlToUint8Array(dataUrl: string): Promise<Uint8Array>;
1794
54
  /**
1795
55
  * Normalize image data for `ImageRun` — converts `Blob` to `Uint8Array`.
1796
56
  *
@@ -1812,25 +72,17 @@ declare function dataUrlToUint8Array(dataUrl: string): Promise<Uint8Array>;
1812
72
  declare function normalizeImageData(data: unknown): Promise<string | ArrayBuffer | Uint8Array>;
1813
73
  //#endregion
1814
74
  //#region src/browser.d.ts
1815
- /**
1816
- * ### `saveDocument()` — Not available in browsers
1817
- *
1818
- * Browsers do not provide direct filesystem access for security reasons.
1819
- * To trigger a file download in the browser, use `doc.toBlob()` with
1820
- * `URL.createObjectURL()` and a temporary `<a>` element:
1821
- *
1822
- * ```ts
1823
- * const blob = await doc.toBlob()
1824
- * const url = URL.createObjectURL(blob)
1825
- * const a = document.createElement('a')
1826
- * a.href = url
1827
- * a.download = 'output.docx'
1828
- * a.click()
1829
- * URL.revokeObjectURL(url)
1830
- * ```
1831
- *
1832
- * @deprecated This API is not available in browsers. Use `doc.toBlob()` instead.
1833
- */
1834
- declare const saveDocument: never;
1835
- //#endregion
1836
- export { type AgendaItem, type BaseNode, type BlockNode, type BorderRule, type BorderStyle, type BulletItem, type BulletListNode, type CalloutOptions, type ClassName, type CodeBlockOptions, type ColAlign, type ColFormat, type CoverPageOptions, type DataTableOptions, DocxBuilder, type DocxKitConfig, DocxKitError, type DocxPlugin, type DocxPreset, type DocxSchema, type DocxStyleRule, type DocxTheme, type EChartsPluginOptions, ERROR_CODES, type ErrorCode, type FontWeight, type HeaderFooterConfig, type HeaderFooterContent, type HeadingNode, type HighlightColor, type HyperlinkNode, type ImageNode, type InlineNode, type MeetingMinutesOptions, type NumberedListNode, type Orientation, PRESET_LIST, type PageBreakNode, type PageConfig, type PageNumberOptions, type PageSize, type ParagraphNode, type PluginNode, type PluginRegistry, type PluginRenderContext, type PropertyItem, type PropertyTableOptions, type QRCodePluginOptions, type SectionBreakNode, type SectionConfig, type SignatureBlockOptions, type SignatureParty, type StyleSheet, type TableColumn, type TableNode, type TextAlign, type TextNode, type TimelineEvent, type TimelineOptions, type VerticalAlign, type WatermarkOptions, academicPreset, calloutPlugin, classicPreset, codeBlockPlugin, coverPagePlugin, createDocx, dataTablePlugin, dataUrlToUint8Array, definePlugin, defineStyles, echartsPlugin, meetingMinutesPlugin, modernPreset, normalizeImageData, pageNumberPlugin, propertyTablePlugin, qrcodePlugin, renderDocx, saveDocument, signatureBlockPlugin, timelinePlugin, usePreset, watermarkPlugin };
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;
87
+ //#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 };