@docen/docx 0.3.0 → 0.3.2

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.
Files changed (74) hide show
  1. package/README.md +2 -3
  2. package/dist/converters/docx.d.mts +95 -5
  3. package/dist/converters/docx.mjs +732 -82
  4. package/dist/converters/html.d.mts +20 -5
  5. package/dist/converters/html.mjs +94 -8
  6. package/dist/converters/markdown.d.mts +1 -1
  7. package/dist/converters/markdown.mjs +1 -1
  8. package/dist/converters/patch.d.mts +1 -1
  9. package/dist/converters/patch.mjs +4 -5
  10. package/dist/converters/prepare.d.mts +15 -3
  11. package/dist/converters/prepare.mjs +50 -4
  12. package/dist/converters/styles.d.mts +85 -0
  13. package/dist/converters/styles.mjs +285 -0
  14. package/dist/core-C9VunJ8o.d.mts +174 -0
  15. package/dist/core-DT9IrTzN.mjs +670 -0
  16. package/dist/core.d.mts +1 -1
  17. package/dist/core.mjs +1 -1
  18. package/dist/document-BH1y4qHM.d.mts +6 -0
  19. package/dist/editor.d.mts +1 -1
  20. package/dist/editor.mjs +3 -2
  21. package/dist/extensions/blockquote.d.mts +23 -0
  22. package/dist/extensions/blockquote.mjs +31 -0
  23. package/dist/extensions/code-block.d.mts +19 -0
  24. package/dist/extensions/code-block.mjs +23 -0
  25. package/dist/extensions/column-break.d.mts +31 -0
  26. package/dist/extensions/column-break.mjs +2 -0
  27. package/dist/extensions/details.d.mts +19 -0
  28. package/dist/extensions/details.mjs +18 -0
  29. package/dist/extensions/document.d.mts +2 -0
  30. package/dist/extensions/document.mjs +50 -0
  31. package/dist/extensions/extensions.d.mts +5 -5
  32. package/dist/extensions/extensions.mjs +4 -3
  33. package/dist/extensions/formatting-marks.d.mts +38 -0
  34. package/dist/extensions/formatting-marks.mjs +2 -0
  35. package/dist/extensions/heading.mjs +24 -3
  36. package/dist/extensions/image.d.mts +2 -2
  37. package/dist/extensions/image.mjs +244 -49
  38. package/dist/extensions/index.d.mts +4 -2
  39. package/dist/extensions/index.mjs +4 -2
  40. package/dist/extensions/mention.d.mts +25 -0
  41. package/dist/extensions/mention.mjs +44 -0
  42. package/dist/extensions/ordered-list.d.mts +25 -0
  43. package/dist/extensions/ordered-list.mjs +41 -0
  44. package/dist/extensions/page-break.d.mts +2 -0
  45. package/dist/extensions/page-break.mjs +2 -0
  46. package/dist/extensions/paragraph.d.mts +1 -1
  47. package/dist/extensions/paragraph.mjs +39 -4
  48. package/dist/extensions/passthrough.d.mts +2 -0
  49. package/dist/extensions/passthrough.mjs +2 -0
  50. package/dist/extensions/section-break.d.mts +44 -0
  51. package/dist/extensions/section-break.mjs +2 -0
  52. package/dist/extensions/table.mjs +29 -3
  53. package/dist/extensions/task-item.d.mts +27 -0
  54. package/dist/extensions/task-item.mjs +37 -0
  55. package/dist/extensions/text-style.mjs +20 -3
  56. package/dist/extensions/tiptap.d.mts +2 -2
  57. package/dist/extensions/tiptap.mjs +1 -3
  58. package/dist/extensions/types.d.mts +7 -5
  59. package/dist/extensions/utils.d.mts +2 -49
  60. package/dist/extensions/utils.mjs +222 -12
  61. package/dist/extensions/wpg-group.d.mts +2 -0
  62. package/dist/extensions/wpg-group.mjs +2 -0
  63. package/dist/extensions/wps-shape.d.mts +2 -0
  64. package/dist/extensions/wps-shape.mjs +2 -0
  65. package/dist/index.d.mts +127 -18
  66. package/dist/index.mjs +7 -2
  67. package/dist/paragraph-D8mpHo_o.d.mts +8 -0
  68. package/dist/{tiptap-TErPjuNJ.d.mts → tiptap-pZsNPsvV.d.mts} +1 -3
  69. package/dist/utils-D87vukzp.d.mts +128 -0
  70. package/package.json +40 -40
  71. package/dist/core-CFIQVRfx.mjs +0 -88
  72. package/dist/core-omBKMRtl.d.mts +0 -34
  73. package/dist/image-Ge1y6uam.d.mts +0 -47
  74. package/dist/paragraph-fhEXtAN2.d.mts +0 -16
package/README.md CHANGED
@@ -6,6 +6,8 @@
6
6
 
7
7
  > DOCX editor and converter powered by @office-open/docx with Tiptap editing layer, supporting bidirectional conversion between DOCX, HTML, and Markdown.
8
8
 
9
+ > Need a ready-made visual editor? [`@docen/editor`](../editor/README.md) wraps this engine in a Fluent UI shell with the turnkey `<docen-document>` super-component.
10
+
9
11
  ## Features
10
12
 
11
13
  - 📝 **Tiptap Editor** — Full-featured WYSIWYG editor with DOCX-aware extensions
@@ -142,9 +144,6 @@ Standalone Functions (core)
142
144
  ↕ used by
143
145
  Tiptap Extension Commands (thin wrappers)
144
146
  editor.commands.importDocx() / exportDocx()
145
- ↕ used by
146
- @docen/ui (Fluent UI Web Components)
147
- <docx-editor> toolbar / ribbon / menus
148
147
  ```
149
148
 
150
149
  - **Runtime model**: Tiptap JSON with DOCX-rich attributes via custom extensions
@@ -1,4 +1,4 @@
1
- import { a as JSONContent } from "../core-omBKMRtl.mjs";
1
+ import { a as JSONContent } from "../core-C9VunJ8o.mjs";
2
2
  import { PrepareStep } from "./prepare.mjs";
3
3
  import { DocumentOptions, OutputByType, OutputType, PackerOptions, parseDocument } from "@office-open/docx";
4
4
 
@@ -10,12 +10,26 @@ import { DocumentOptions, OutputByType, OutputType, PackerOptions, parseDocument
10
10
  * DocxManager handles tree walking, child assembly, and dispatching.
11
11
  */
12
12
  declare class DocxManager {
13
+ private numberingConfigs;
14
+ private orderedInstanceCounter;
15
+ private resolveStyles;
13
16
  compile(json: JSONContent): DocumentOptions;
17
+ /** Assemble a SectionOptions from compiled children + optional layout/headers/footers. */
18
+ private buildSection;
19
+ /**
20
+ * Compile resolved header/footer slots (JSONContent[] per slot) back into
21
+ * SectionChild[] per slot. Returns undefined when no slot has content.
22
+ */
23
+ private compileHeaderFooter;
24
+ /**
25
+ * Resolve a section's header/footer group (SectionChild[] per slot) into
26
+ * Tiptap JSON slots. Returns null when no slot has content.
27
+ */
28
+ private resolveHeaderFooter;
14
29
  resolve(docOpts: DocumentOptions): JSONContent;
15
30
  private compileSectionChild;
16
31
  private compileParagraphNode;
17
32
  private compileHeadingNode;
18
- private compileCodeBlock;
19
33
  /** Simple text optimization: merge plain runs into text field */
20
34
  private simplifyParagraph;
21
35
  private compileTableNode;
@@ -28,11 +42,74 @@ declare class DocxManager {
28
42
  private computeColumnWidths;
29
43
  private compileTableCellNode;
30
44
  private compileListFromNode;
45
+ /**
46
+ * Register (or reuse) an abstractNum for an ordered list's `start`, and
47
+ * return a fresh instance so this list counts independently of other lists
48
+ * that share the same definition.
49
+ */
50
+ private registerOrderedNumbering;
51
+ /**
52
+ * Prepend an inline checkbox SDT to a task paragraph. The SDT is tagged
53
+ * "docen-task" so resolve can tell task items apart from ordinary paragraphs
54
+ * that happen to contain an SDT.
55
+ */
56
+ private injectTaskCheckbox;
57
+ /**
58
+ * details → block-level group-SDT. The summary paragraph is tagged with a
59
+ * fixed style so resolve can split it back out; content blocks flatten in
60
+ * after it. (No native collapse in DOCX — structure round-trips, the view
61
+ * stays expanded.)
62
+ */
63
+ private compileDetailsNode;
31
64
  private compileInlineContent;
32
65
  private compileTextNode;
66
+ /** Emit a single run for `text` with all inline marks applied. */
67
+ private compileTextRun;
33
68
  private resolveSectionChild;
69
+ /** Wrap an opaque SectionChild in a passthrough atom (attrs.data = JSON). */
70
+ private resolvePassthrough;
71
+ /**
72
+ * Resolve a details group-SDT: the summary-style paragraph becomes
73
+ * detailsSummary, the remaining blocks fold into detailsContent.
74
+ */
75
+ private resolveDetailsSdt;
34
76
  private resolveParagraph;
35
- private resolveListItem;
77
+ /** Look up a paragraph style's NAME from its styleId, via the styles table
78
+ * carried on the current resolve(). Returns undefined outside resolve. */
79
+ private styleNameOf;
80
+ /** reference → level-0 format/start, for classifying numbering paragraphs. */
81
+ private buildNumberingLookup;
82
+ /**
83
+ * Walk section children, grouping consecutive list paragraphs into nested
84
+ * Tiptap lists. Non-list children resolve individually. DOCX flattens lists
85
+ * to a paragraph sequence (depth carried by `level`); this rebuilds the tree.
86
+ */
87
+ private resolveSectionChildren;
88
+ /** Classify a paragraph as a list item, or null if it isn't one. */
89
+ private detectList;
90
+ /**
91
+ * Rebuild nested Tiptap lists from a flat run of list paragraphs. Stack-based:
92
+ * each frame is an active list at a given depth; the `key` (level:type:
93
+ * reference) decides whether a paragraph continues the top list, starts a
94
+ * nested list, or splits off a new sibling list.
95
+ */
96
+ private buildListTree;
97
+ /** Classify a paragraph as a blockquote member by its signature. */
98
+ private detectBlockquote;
99
+ /**
100
+ * Rebuild a blockquote node from a run of signature-carrying paragraphs,
101
+ * stripping the indent/border signature so child paragraphs render clean.
102
+ */
103
+ private buildBlockquote;
104
+ /**
105
+ * Resolve a list-item paragraph to a Tiptap paragraph/heading node, stripping
106
+ * the list marker (bullet/numbering) and the leading task checkbox — those
107
+ * are expressed at the list/item level, not inside the paragraph.
108
+ */
109
+ private resolveListItemParagraph;
110
+ /** Return a copy of `para` with its leading docen-task checkbox SDT removed. */
111
+ private stripTaskCheckbox;
112
+ private resolveCodeBlock;
36
113
  private resolveTable;
37
114
  /**
38
115
  * Resolve a paragraph's inline content. @office-open collapses a plain-text
@@ -43,6 +120,8 @@ declare class DocxManager {
43
120
  private resolveInlineContent;
44
121
  private resolveParagraphChildren;
45
122
  private resolveParagraphChild;
123
+ /** Resolve an inline SDT (mention carrier; other inline SDTs unsupported). */
124
+ private resolveInlineSdt;
46
125
  private resolveRun;
47
126
  private resolveMarks;
48
127
  private resolveImage;
@@ -71,6 +150,17 @@ interface DocxGenerateOptions<T extends OutputType = "nodebuffer"> {
71
150
  prepare?: boolean | PrepareStep[];
72
151
  /** Packer options; `type` controls the output format (default `"nodebuffer"` → Buffer). */
73
152
  packer?: PackerOptions<T>;
153
+ /**
154
+ * Document-level options injected into the compiled `DocumentOptions` — core
155
+ * properties (`title`/`creator`/`description`/…), `styles`/`externalStyles`,
156
+ * `background`, `features`, `fonts`, etc. Excludes `sections` (always compiled
157
+ * from the JSON) and `numbering` (collected from ordered-list nodes).
158
+ *
159
+ * `styles`/`externalStyles` here take precedence over any `styles` carried on
160
+ * `json.attrs.styles` (e.g. from a prior `parseDOCX`); the two are mutually
161
+ * exclusive, so specifying `externalStyles` drops the compiled `styles`.
162
+ */
163
+ document?: Omit<Partial<DocumentOptions>, "sections" | "numbering">;
74
164
  }
75
165
  /**
76
166
  * Generate a DOCX file from Tiptap JSON (runtime model), asynchronously.
@@ -87,9 +177,9 @@ declare function generateDOCX<T extends OutputType = "nodebuffer">(json: JSONCon
87
177
  *
88
178
  * Pipeline: `DocxManager.compile` → `generateDocumentSync`. Does **not** run
89
179
  * `prepareDocument` (it is async); call `await prepareDocument(json)` first
90
- * when http images need embedding.
180
+ * when http images need embedding. `options.document` is still applied.
91
181
  */
92
- declare function generateDOCXSync<T extends OutputType = "nodebuffer">(json: JSONContent, packerOptions?: PackerOptions<T>): OutputByType[T];
182
+ declare function generateDOCXSync<T extends OutputType = "nodebuffer">(json: JSONContent, options?: DocxGenerateOptions<T>): OutputByType[T];
93
183
  /**
94
184
  * Generate a DOCX file as a `ReadableStream<Uint8Array>` — for large documents
95
185
  * or streaming HTTP responses.