@usejunior/docx-core 0.10.0 → 0.11.1

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 (248) hide show
  1. package/LICENSE +202 -21
  2. package/NOTICE +2 -0
  3. package/README.md +2 -2
  4. package/dist/.tsbuildinfo +1 -1
  5. package/dist/atomizer.d.ts +13 -7
  6. package/dist/atomizer.d.ts.map +1 -1
  7. package/dist/atomizer.js +59 -24
  8. package/dist/atomizer.js.map +1 -1
  9. package/dist/baselines/atomizer/auxiliaryIdCollision.d.ts +99 -0
  10. package/dist/baselines/atomizer/auxiliaryIdCollision.d.ts.map +1 -0
  11. package/dist/baselines/atomizer/auxiliaryIdCollision.js +415 -0
  12. package/dist/baselines/atomizer/auxiliaryIdCollision.js.map +1 -0
  13. package/dist/baselines/atomizer/documentReconstructor.d.ts.map +1 -1
  14. package/dist/baselines/atomizer/documentReconstructor.js +120 -27
  15. package/dist/baselines/atomizer/documentReconstructor.js.map +1 -1
  16. package/dist/baselines/atomizer/inPlaceModifier-wrappers.d.ts +9 -0
  17. package/dist/baselines/atomizer/inPlaceModifier-wrappers.d.ts.map +1 -1
  18. package/dist/baselines/atomizer/inPlaceModifier-wrappers.js +52 -4
  19. package/dist/baselines/atomizer/inPlaceModifier-wrappers.js.map +1 -1
  20. package/dist/baselines/atomizer/pipeline.d.ts +12 -53
  21. package/dist/baselines/atomizer/pipeline.d.ts.map +1 -1
  22. package/dist/baselines/atomizer/pipeline.js +126 -231
  23. package/dist/baselines/atomizer/pipeline.js.map +1 -1
  24. package/dist/baselines/atomizer/trackChangesAcceptorAst.d.ts.map +1 -1
  25. package/dist/baselines/atomizer/trackChangesAcceptorAst.js +153 -23
  26. package/dist/baselines/atomizer/trackChangesAcceptorAst.js.map +1 -1
  27. package/dist/baselines/wmlcomparer/DotnetCli.d.ts.map +1 -1
  28. package/dist/baselines/wmlcomparer/DotnetCli.js +7 -0
  29. package/dist/baselines/wmlcomparer/DotnetCli.js.map +1 -1
  30. package/dist/cli/compare-two.d.ts.map +1 -1
  31. package/dist/cli/compare-two.js +3 -1
  32. package/dist/cli/compare-two.js.map +1 -1
  33. package/dist/cli/conformance-adapter.d.ts +3 -0
  34. package/dist/cli/conformance-adapter.d.ts.map +1 -0
  35. package/dist/cli/conformance-adapter.js +93 -0
  36. package/dist/cli/conformance-adapter.js.map +1 -0
  37. package/dist/cli/index.d.ts.map +1 -1
  38. package/dist/cli/index.js +5 -1
  39. package/dist/cli/index.js.map +1 -1
  40. package/dist/compare-types.d.ts +46 -0
  41. package/dist/compare-types.d.ts.map +1 -1
  42. package/dist/generation/compile.d.ts +22 -0
  43. package/dist/generation/compile.d.ts.map +1 -0
  44. package/dist/generation/compile.js +58 -0
  45. package/dist/generation/compile.js.map +1 -0
  46. package/dist/generation/context.d.ts +42 -0
  47. package/dist/generation/context.d.ts.map +1 -0
  48. package/dist/generation/context.js +65 -0
  49. package/dist/generation/context.js.map +1 -0
  50. package/dist/generation/emit/comments-part.d.ts +36 -0
  51. package/dist/generation/emit/comments-part.d.ts.map +1 -0
  52. package/dist/generation/emit/comments-part.js +116 -0
  53. package/dist/generation/emit/comments-part.js.map +1 -0
  54. package/dist/generation/emit/document-part.d.ts +24 -0
  55. package/dist/generation/emit/document-part.d.ts.map +1 -0
  56. package/dist/generation/emit/document-part.js +60 -0
  57. package/dist/generation/emit/document-part.js.map +1 -0
  58. package/dist/generation/emit/emit-context.d.ts +28 -0
  59. package/dist/generation/emit/emit-context.d.ts.map +1 -0
  60. package/dist/generation/emit/emit-context.js +19 -0
  61. package/dist/generation/emit/emit-context.js.map +1 -0
  62. package/dist/generation/emit/font-table-part.d.ts +16 -0
  63. package/dist/generation/emit/font-table-part.d.ts.map +1 -0
  64. package/dist/generation/emit/font-table-part.js +74 -0
  65. package/dist/generation/emit/font-table-part.js.map +1 -0
  66. package/dist/generation/emit/header-footer-part.d.ts +23 -0
  67. package/dist/generation/emit/header-footer-part.d.ts.map +1 -0
  68. package/dist/generation/emit/header-footer-part.js +57 -0
  69. package/dist/generation/emit/header-footer-part.js.map +1 -0
  70. package/dist/generation/emit/numbering-part.d.ts +29 -0
  71. package/dist/generation/emit/numbering-part.d.ts.map +1 -0
  72. package/dist/generation/emit/numbering-part.js +102 -0
  73. package/dist/generation/emit/numbering-part.js.map +1 -0
  74. package/dist/generation/emit/package-parts.d.ts +24 -0
  75. package/dist/generation/emit/package-parts.d.ts.map +1 -0
  76. package/dist/generation/emit/package-parts.js +121 -0
  77. package/dist/generation/emit/package-parts.js.map +1 -0
  78. package/dist/generation/emit/paragraph.d.ts +24 -0
  79. package/dist/generation/emit/paragraph.d.ts.map +1 -0
  80. package/dist/generation/emit/paragraph.js +63 -0
  81. package/dist/generation/emit/paragraph.js.map +1 -0
  82. package/dist/generation/emit/properties.d.ts +36 -0
  83. package/dist/generation/emit/properties.d.ts.map +1 -0
  84. package/dist/generation/emit/properties.js +154 -0
  85. package/dist/generation/emit/properties.js.map +1 -0
  86. package/dist/generation/emit/run.d.ts +16 -0
  87. package/dist/generation/emit/run.d.ts.map +1 -0
  88. package/dist/generation/emit/run.js +71 -0
  89. package/dist/generation/emit/run.js.map +1 -0
  90. package/dist/generation/emit/section.d.ts +29 -0
  91. package/dist/generation/emit/section.d.ts.map +1 -0
  92. package/dist/generation/emit/section.js +117 -0
  93. package/dist/generation/emit/section.js.map +1 -0
  94. package/dist/generation/emit/settings-part.d.ts +13 -0
  95. package/dist/generation/emit/settings-part.d.ts.map +1 -0
  96. package/dist/generation/emit/settings-part.js +68 -0
  97. package/dist/generation/emit/settings-part.js.map +1 -0
  98. package/dist/generation/emit/styles-part.d.ts +16 -0
  99. package/dist/generation/emit/styles-part.d.ts.map +1 -0
  100. package/dist/generation/emit/styles-part.js +82 -0
  101. package/dist/generation/emit/styles-part.js.map +1 -0
  102. package/dist/generation/emit/table.d.ts +26 -0
  103. package/dist/generation/emit/table.d.ts.map +1 -0
  104. package/dist/generation/emit/table.js +209 -0
  105. package/dist/generation/emit/table.js.map +1 -0
  106. package/dist/generation/emit/theme-part.d.ts +21 -0
  107. package/dist/generation/emit/theme-part.d.ts.map +1 -0
  108. package/dist/generation/emit/theme-part.js +151 -0
  109. package/dist/generation/emit/theme-part.js.map +1 -0
  110. package/dist/generation/emit/web-settings-part.d.ts +12 -0
  111. package/dist/generation/emit/web-settings-part.d.ts.map +1 -0
  112. package/dist/generation/emit/web-settings-part.js +19 -0
  113. package/dist/generation/emit/web-settings-part.js.map +1 -0
  114. package/dist/generation/errors.d.ts +22 -0
  115. package/dist/generation/errors.d.ts.map +1 -0
  116. package/dist/generation/errors.js +29 -0
  117. package/dist/generation/errors.js.map +1 -0
  118. package/dist/generation/index.d.ts +13 -0
  119. package/dist/generation/index.d.ts.map +1 -0
  120. package/dist/generation/index.js +12 -0
  121. package/dist/generation/index.js.map +1 -0
  122. package/dist/generation/ordering.d.ts +46 -0
  123. package/dist/generation/ordering.d.ts.map +1 -0
  124. package/dist/generation/ordering.js +119 -0
  125. package/dist/generation/ordering.js.map +1 -0
  126. package/dist/generation/recipes.d.ts +70 -0
  127. package/dist/generation/recipes.d.ts.map +1 -0
  128. package/dist/generation/recipes.js +149 -0
  129. package/dist/generation/recipes.js.map +1 -0
  130. package/dist/generation/structural-checks.d.ts +24 -0
  131. package/dist/generation/structural-checks.d.ts.map +1 -0
  132. package/dist/generation/structural-checks.js +318 -0
  133. package/dist/generation/structural-checks.js.map +1 -0
  134. package/dist/generation/theme-colors.d.ts +4 -0
  135. package/dist/generation/theme-colors.d.ts.map +1 -0
  136. package/dist/generation/theme-colors.js +18 -0
  137. package/dist/generation/theme-colors.js.map +1 -0
  138. package/dist/generation/types.d.ts +249 -0
  139. package/dist/generation/types.d.ts.map +1 -0
  140. package/dist/generation/types.js +54 -0
  141. package/dist/generation/types.js.map +1 -0
  142. package/dist/generation/validate-spec.d.ts +27 -0
  143. package/dist/generation/validate-spec.d.ts.map +1 -0
  144. package/dist/generation/validate-spec.js +359 -0
  145. package/dist/generation/validate-spec.js.map +1 -0
  146. package/dist/index.d.ts +3 -0
  147. package/dist/index.d.ts.map +1 -1
  148. package/dist/index.js +8 -0
  149. package/dist/index.js.map +1 -1
  150. package/dist/integration/generation-probes.d.ts +15 -0
  151. package/dist/integration/generation-probes.d.ts.map +1 -0
  152. package/dist/integration/generation-probes.js +84 -0
  153. package/dist/integration/generation-probes.js.map +1 -0
  154. package/dist/integration/libreoffice-oracle.d.ts +8 -0
  155. package/dist/integration/libreoffice-oracle.d.ts.map +1 -1
  156. package/dist/integration/libreoffice-oracle.js +14 -6
  157. package/dist/integration/libreoffice-oracle.js.map +1 -1
  158. package/dist/integration/synthetic-docx-fixture.d.ts +72 -0
  159. package/dist/integration/synthetic-docx-fixture.d.ts.map +1 -1
  160. package/dist/integration/synthetic-docx-fixture.js +131 -4
  161. package/dist/integration/synthetic-docx-fixture.js.map +1 -1
  162. package/dist/primitives/accept_changes.d.ts +2 -1
  163. package/dist/primitives/accept_changes.d.ts.map +1 -1
  164. package/dist/primitives/accept_changes.js +153 -12
  165. package/dist/primitives/accept_changes.js.map +1 -1
  166. package/dist/primitives/document.d.ts +38 -0
  167. package/dist/primitives/document.d.ts.map +1 -1
  168. package/dist/primitives/document.js +75 -9
  169. package/dist/primitives/document.js.map +1 -1
  170. package/dist/primitives/document_view-comments.d.ts.map +1 -1
  171. package/dist/primitives/document_view-comments.js +4 -3
  172. package/dist/primitives/document_view-comments.js.map +1 -1
  173. package/dist/primitives/document_view-types.d.ts +15 -0
  174. package/dist/primitives/document_view-types.d.ts.map +1 -1
  175. package/dist/primitives/document_view.d.ts.map +1 -1
  176. package/dist/primitives/document_view.js +21 -13
  177. package/dist/primitives/document_view.js.map +1 -1
  178. package/dist/primitives/formatting_tags.d.ts +1 -0
  179. package/dist/primitives/formatting_tags.d.ts.map +1 -1
  180. package/dist/primitives/formatting_tags.js +16 -10
  181. package/dist/primitives/formatting_tags.js.map +1 -1
  182. package/dist/primitives/index.d.ts +4 -0
  183. package/dist/primitives/index.d.ts.map +1 -1
  184. package/dist/primitives/index.js +4 -0
  185. package/dist/primitives/index.js.map +1 -1
  186. package/dist/primitives/layout.d.ts.map +1 -1
  187. package/dist/primitives/layout.js +13 -0
  188. package/dist/primitives/layout.js.map +1 -1
  189. package/dist/primitives/minimal_save.d.ts +38 -0
  190. package/dist/primitives/minimal_save.d.ts.map +1 -0
  191. package/dist/primitives/minimal_save.js +323 -0
  192. package/dist/primitives/minimal_save.js.map +1 -0
  193. package/dist/primitives/namespaces.d.ts +46 -0
  194. package/dist/primitives/namespaces.d.ts.map +1 -1
  195. package/dist/primitives/namespaces.js +49 -0
  196. package/dist/primitives/namespaces.js.map +1 -1
  197. package/dist/primitives/reject_changes.d.ts +4 -2
  198. package/dist/primitives/reject_changes.d.ts.map +1 -1
  199. package/dist/primitives/reject_changes.js +177 -24
  200. package/dist/primitives/reject_changes.js.map +1 -1
  201. package/dist/primitives/revision-parts.d.ts +7 -0
  202. package/dist/primitives/revision-parts.d.ts.map +1 -0
  203. package/dist/primitives/revision-parts.js +27 -0
  204. package/dist/primitives/revision-parts.js.map +1 -0
  205. package/dist/primitives/revision-vocabulary.d.ts +7 -0
  206. package/dist/primitives/revision-vocabulary.d.ts.map +1 -0
  207. package/dist/primitives/revision-vocabulary.js +39 -0
  208. package/dist/primitives/revision-vocabulary.js.map +1 -0
  209. package/dist/primitives/schema-corpus-capture.d.ts +19 -0
  210. package/dist/primitives/schema-corpus-capture.d.ts.map +1 -0
  211. package/dist/primitives/schema-corpus-capture.js +29 -0
  212. package/dist/primitives/schema-corpus-capture.js.map +1 -0
  213. package/dist/primitives/sectPrAudit.d.ts +19 -0
  214. package/dist/primitives/sectPrAudit.d.ts.map +1 -0
  215. package/dist/primitives/sectPrAudit.js +165 -0
  216. package/dist/primitives/sectPrAudit.js.map +1 -0
  217. package/dist/primitives/semantic_tags.d.ts.map +1 -1
  218. package/dist/primitives/semantic_tags.js +2 -1
  219. package/dist/primitives/semantic_tags.js.map +1 -1
  220. package/dist/primitives/serialize_html.d.ts +1 -0
  221. package/dist/primitives/serialize_html.d.ts.map +1 -1
  222. package/dist/primitives/serialize_html.js +4 -2
  223. package/dist/primitives/serialize_html.js.map +1 -1
  224. package/dist/primitives/styles.d.ts +15 -0
  225. package/dist/primitives/styles.d.ts.map +1 -1
  226. package/dist/primitives/styles.js +11 -0
  227. package/dist/primitives/styles.js.map +1 -1
  228. package/dist/primitives/track-changes-emitter.d.ts +9 -0
  229. package/dist/primitives/track-changes-emitter.d.ts.map +1 -1
  230. package/dist/primitives/track-changes-emitter.js +54 -4
  231. package/dist/primitives/track-changes-emitter.js.map +1 -1
  232. package/dist/primitives/validate_ai_revisions.d.ts +35 -0
  233. package/dist/primitives/validate_ai_revisions.d.ts.map +1 -0
  234. package/dist/primitives/validate_ai_revisions.js +323 -0
  235. package/dist/primitives/validate_ai_revisions.js.map +1 -0
  236. package/dist/primitives/xml.d.ts +5 -0
  237. package/dist/primitives/xml.d.ts.map +1 -1
  238. package/dist/primitives/xml.js +5 -0
  239. package/dist/primitives/xml.js.map +1 -1
  240. package/dist/primitives/zip.d.ts +1 -0
  241. package/dist/primitives/zip.d.ts.map +1 -1
  242. package/dist/primitives/zip.js +21 -3
  243. package/dist/primitives/zip.js.map +1 -1
  244. package/dist/shared/field-structure.d.ts +14 -0
  245. package/dist/shared/field-structure.d.ts.map +1 -0
  246. package/dist/shared/field-structure.js +166 -0
  247. package/dist/shared/field-structure.js.map +1 -0
  248. package/package.json +7 -4
@@ -0,0 +1,60 @@
1
+ /**
2
+ * word/document.xml emitter.
3
+ *
4
+ * Builds the main document part from a namespace-declaring skeleton: the
5
+ * skeleton string carries every namespace the part uses on the root element,
6
+ * and all children are created through the namespace-safe DOM helpers.
7
+ * xmldom's serializer omits the XML declaration, so it is prepended here;
8
+ * the structural validator asserts every part starts with one.
9
+ */
10
+ import { createWmlElement } from '../../primitives/dom-helpers.js';
11
+ import { OOXML, W } from '../../primitives/namespaces.js';
12
+ import { parseXml, serializeXml, XML_DECL } from '../../primitives/xml.js';
13
+ import { GenerationInternalError } from '../errors.js';
14
+ import { buildSectPr } from './section.js';
15
+ import { buildBlock } from './table.js';
16
+ const DOCUMENT_SKELETON = `<w:document xmlns:w="${OOXML.W_NS}" xmlns:r="${OOXML.R_NS}" xmlns:w14="${OOXML.W14_NS}">` +
17
+ `<w:body/></w:document>`;
18
+ /**
19
+ * Compile the body: each section's blocks in order. Every non-final section
20
+ * ends with a dedicated break paragraph whose pPr contains only that
21
+ * section's sectPr (what Word itself emits on Insert → Section Break; it
22
+ * also sidesteps the trailing-table case), and the final section's
23
+ * properties bind as the body's last child.
24
+ *
25
+ * @conformance ECMA-376 edition 5, Part 1 § 17.6.18
26
+ * @conformance ECMA-376 edition 5, Part 1 § 17.6.17
27
+ */
28
+ export function emitDocumentPart(spec, refs, ctx) {
29
+ const doc = parseXml(DOCUMENT_SKELETON);
30
+ const body = doc.getElementsByTagName('w:body').item(0);
31
+ if (!body)
32
+ throw new GenerationInternalError('document skeleton lost its w:body');
33
+ spec.sections.forEach((section, index) => {
34
+ for (const block of section.blocks) {
35
+ body.appendChild(buildBlock(doc, block, ctx));
36
+ }
37
+ const sectPr = buildSectPr(doc, section, refs?.[index]);
38
+ const isFinal = index === spec.sections.length - 1;
39
+ if (isFinal) {
40
+ // The body must not end with a table (readers treat it as truncated);
41
+ // a final trailing table gets a closing empty paragraph before the
42
+ // body-level sectPr binds. Non-final sections already end with their
43
+ // dedicated break paragraph.
44
+ const lastBlock = section.blocks[section.blocks.length - 1];
45
+ if (lastBlock && lastBlock.kind === 'table') {
46
+ body.appendChild(createWmlElement(doc, W.p));
47
+ }
48
+ body.appendChild(sectPr);
49
+ }
50
+ else {
51
+ const breakParagraph = createWmlElement(doc, W.p);
52
+ const pPr = createWmlElement(doc, W.pPr);
53
+ pPr.appendChild(sectPr);
54
+ breakParagraph.appendChild(pPr);
55
+ body.appendChild(breakParagraph);
56
+ }
57
+ });
58
+ return XML_DECL + serializeXml(doc);
59
+ }
60
+ //# sourceMappingURL=document-part.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-part.js","sourceRoot":"","sources":["../../../src/generation/emit/document-part.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAGvD,OAAO,EAAE,WAAW,EAAgC,MAAM,cAAc,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,iBAAiB,GACrB,wBAAwB,KAAK,CAAC,IAAI,cAAc,KAAK,CAAC,IAAI,gBAAgB,KAAK,CAAC,MAAM,IAAI;IAC1F,wBAAwB,CAAC;AAE3B;;;;;;;;;GASG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAkB,EAAE,IAAgC,EAAE,GAAsB;IAC3G,MAAM,GAAG,GAAG,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IACxC,MAAM,IAAI,GAAG,GAAG,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACxD,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,uBAAuB,CAAC,mCAAmC,CAAC,CAAC;IAElF,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;QACvC,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACnC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;QAChD,CAAC;QAED,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;QACxD,MAAM,OAAO,GAAG,KAAK,KAAK,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;QACnD,IAAI,OAAO,EAAE,CAAC;YACZ,sEAAsE;YACtE,mEAAmE;YACnE,qEAAqE;YACrE,6BAA6B;YAC7B,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAC5D,IAAI,SAAS,IAAI,SAAS,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;gBAC5C,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC/C,CAAC;YACD,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAC3B,CAAC;aAAM,CAAC;YACN,MAAM,cAAc,GAAG,gBAAgB,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAClD,MAAM,GAAG,GAAG,gBAAgB,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;YACzC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YACxB,cAAc,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;YAChC,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;QACnC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;AACtC,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Shared state the block emitters thread through paragraph/table recursion.
3
+ *
4
+ * Bundling it in one object keeps emitter signatures stable as features
5
+ * land: numbering binds spec handles to numeric ids, and the drafting-note
6
+ * collector allocates comment ids in document order (absent in stories that
7
+ * cannot carry notes, e.g. headers/footers, and when notes are disabled).
8
+ */
9
+ import type { DraftingNoteSpec, ThemeColorSlot } from '../types.js';
10
+ /** Spec-level numbering handle → numeric w:numId value. */
11
+ export type NumberingIdMap = ReadonlyMap<string, number>;
12
+ /** Allocates deterministic comment ids and records notes in document order. */
13
+ export declare class DraftingNoteCollector {
14
+ readonly collected: Array<{
15
+ id: number;
16
+ note: DraftingNoteSpec;
17
+ }>;
18
+ private nextId;
19
+ allocate(note: DraftingNoteSpec): number;
20
+ }
21
+ export type BlockEmitContext = {
22
+ numberingIds?: NumberingIdMap;
23
+ /** Present only where drafting notes may anchor (body story, notes enabled). */
24
+ notes?: DraftingNoteCollector;
25
+ /** Merged canonical/custom theme colors used as reader fallback values. */
26
+ themeColorValues?: ReadonlyMap<ThemeColorSlot, string>;
27
+ };
28
+ //# sourceMappingURL=emit-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emit-context.d.ts","sourceRoot":"","sources":["../../../src/generation/emit/emit-context.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEpE,2DAA2D;AAC3D,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEzD,+EAA+E;AAC/E,qBAAa,qBAAqB;IAChC,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,gBAAgB,CAAA;KAAE,CAAC,CAAM;IACvE,OAAO,CAAC,MAAM,CAAK;IAEnB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM;CAKzC;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,YAAY,CAAC,EAAE,cAAc,CAAC;IAC9B,gFAAgF;IAChF,KAAK,CAAC,EAAE,qBAAqB,CAAC;IAC9B,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,WAAW,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;CACxD,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Shared state the block emitters thread through paragraph/table recursion.
3
+ *
4
+ * Bundling it in one object keeps emitter signatures stable as features
5
+ * land: numbering binds spec handles to numeric ids, and the drafting-note
6
+ * collector allocates comment ids in document order (absent in stories that
7
+ * cannot carry notes, e.g. headers/footers, and when notes are disabled).
8
+ */
9
+ /** Allocates deterministic comment ids and records notes in document order. */
10
+ export class DraftingNoteCollector {
11
+ collected = [];
12
+ nextId = 1;
13
+ allocate(note) {
14
+ const id = this.nextId++;
15
+ this.collected.push({ id, note });
16
+ return id;
17
+ }
18
+ }
19
+ //# sourceMappingURL=emit-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emit-context.js","sourceRoot":"","sources":["../../../src/generation/emit/emit-context.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,+EAA+E;AAC/E,MAAM,OAAO,qBAAqB;IACvB,SAAS,GAAkD,EAAE,CAAC;IAC/D,MAAM,GAAG,CAAC,CAAC;IAEnB,QAAQ,CAAC,IAAsB;QAC7B,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QACzB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QAClC,OAAO,EAAE,CAAC;IACZ,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * word/fontTable.xml emitter.
3
+ *
4
+ * Emitted on every package. Word-authored documents declare a font table; we
5
+ * enumerate the fonts the spec actually references (the Calibri default plus any
6
+ * font named on a style, run, or numbering level) rather than a fixed stub, so the
7
+ * metadata is faithful — a run set in Georgia produces a Georgia entry. panose1 is
8
+ * omitted because we cannot derive it for an arbitrary font name, and Word tolerates
9
+ * its absence. The walk is pure over the spec, so output stays deterministic.
10
+ *
11
+ * The root is the WordprocessingML `w:fonts` font-table element.
12
+ */
13
+ import type { CompileContext } from '../context.js';
14
+ import type { DocumentSpec } from '../types.js';
15
+ export declare function emitFontTablePart(spec: DocumentSpec, ctx: CompileContext): void;
16
+ //# sourceMappingURL=font-table-part.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"font-table-part.d.ts","sourceRoot":"","sources":["../../../src/generation/emit/font-table-part.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAa,YAAY,EAAY,MAAM,aAAa,CAAC;AAUrE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,cAAc,GAAG,IAAI,CAa/E"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * word/fontTable.xml emitter.
3
+ *
4
+ * Emitted on every package. Word-authored documents declare a font table; we
5
+ * enumerate the fonts the spec actually references (the Calibri default plus any
6
+ * font named on a style, run, or numbering level) rather than a fixed stub, so the
7
+ * metadata is faithful — a run set in Georgia produces a Georgia entry. panose1 is
8
+ * omitted because we cannot derive it for an arbitrary font name, and Word tolerates
9
+ * its absence. The walk is pure over the spec, so output stays deterministic.
10
+ *
11
+ * The root is the WordprocessingML `w:fonts` font-table element.
12
+ */
13
+ import { createWmlElement } from '../../primitives/dom-helpers.js';
14
+ import { OOXML, W } from '../../primitives/namespaces.js';
15
+ import { parseXml, serializeXml, XML_DECL } from '../../primitives/xml.js';
16
+ const FONT_TABLE_CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml';
17
+ const FONT_TABLE_REL_TYPE = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable';
18
+ /** The docDefaults run font (see styles-part.ts DEFAULT_FONT); always declared. */
19
+ const DEFAULT_FONT = 'Calibri';
20
+ export function emitFontTablePart(spec, ctx) {
21
+ ctx.registerPart('word/fontTable.xml', FONT_TABLE_CONTENT_TYPE, FONT_TABLE_REL_TYPE);
22
+ const doc = parseXml(`<w:fonts xmlns:w="${OOXML.W_NS}"/>`);
23
+ const root = doc.documentElement;
24
+ for (const name of collectFonts(spec)) {
25
+ const font = createWmlElement(doc, W.font, { 'w:name': name });
26
+ font.appendChild(createWmlElement(doc, W.charset, { 'w:val': '00' }));
27
+ font.appendChild(createWmlElement(doc, W.family, { 'w:val': 'auto' }));
28
+ font.appendChild(createWmlElement(doc, W.pitch, { 'w:val': 'variable' }));
29
+ root.appendChild(font);
30
+ }
31
+ ctx.setFileContent('word/fontTable.xml', XML_DECL + serializeXml(doc));
32
+ }
33
+ /** Distinct fonts the spec references, sorted for determinism, default first. */
34
+ function collectFonts(spec) {
35
+ const names = new Set();
36
+ const add = (props) => {
37
+ if (props?.font)
38
+ names.add(props.font);
39
+ };
40
+ for (const style of spec.styles ?? [])
41
+ add(style.run);
42
+ for (const def of spec.numbering ?? []) {
43
+ for (const level of def.levels)
44
+ add(level.runProps);
45
+ }
46
+ for (const section of spec.sections) {
47
+ for (const set of [section.headers, section.footers]) {
48
+ for (const hf of [set?.default, set?.first, set?.even]) {
49
+ if (hf)
50
+ walkBlocks(hf.blocks, add);
51
+ }
52
+ }
53
+ walkBlocks(section.blocks, add);
54
+ }
55
+ names.delete(DEFAULT_FONT);
56
+ return [DEFAULT_FONT, ...Array.from(names).sort()];
57
+ }
58
+ function walkBlocks(blocks, add) {
59
+ for (const block of blocks) {
60
+ if (block.kind === 'paragraph') {
61
+ for (const run of block.runs) {
62
+ if (run.kind === 'text' || run.kind === 'field')
63
+ add(run);
64
+ }
65
+ }
66
+ else {
67
+ for (const row of block.rows) {
68
+ for (const cell of row.cells)
69
+ walkBlocks(cell.blocks, add);
70
+ }
71
+ }
72
+ }
73
+ }
74
+ //# sourceMappingURL=font-table-part.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"font-table-part.js","sourceRoot":"","sources":["../../../src/generation/emit/font-table-part.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,KA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AAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YAC/B,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;gBAC7B,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO;oBAAE,GAAG,CAAC,GAAG,CAAC,CAAC;YAC5D,CAAC;QACH,CAAC;aAAM,CAAC;YACN,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;gBAC7B,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,KAAK;oBAAE,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YAC7D,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Header and footer part emitters.
3
+ *
4
+ * Each declared header/footer slot (default / first / even) becomes its own
5
+ * part — word/headerN.xml or word/footerN.xml — registered with a
6
+ * content-type override and a relationship from the main document part. The
7
+ * block content reuses the same paragraph/run emitters as the body, so a
8
+ * footer's "Page X of Y" field compiles through exactly the same five-part
9
+ * field machinery.
10
+ *
11
+ * @conformance ECMA-376 edition 5, Part 1 § 17.10.4
12
+ */
13
+ import type { CompileContext } from '../context.js';
14
+ import type { DocumentSpec } from '../types.js';
15
+ import type { BlockEmitContext } from './emit-context.js';
16
+ import type { SectionHeaderFooterRefs } from './section.js';
17
+ /**
18
+ * Allocate and emit every header/footer part, returning per-section
19
+ * reference maps for the sectPr emitter. Runs before the document part so
20
+ * relationship ids exist when sections bind their references.
21
+ */
22
+ export declare function emitHeaderFooterParts(spec: DocumentSpec, ctx: CompileContext, blockCtx?: BlockEmitContext): SectionHeaderFooterRefs[];
23
+ //# sourceMappingURL=header-footer-part.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"header-footer-part.d.ts","sourceRoot":"","sources":["../../../src/generation/emit/header-footer-part.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAiC,MAAM,aAAa,CAAC;AAC/E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAS5D;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,cAAc,EAAE,QAAQ,CAAC,EAAE,gBAAgB,GAAG,uBAAuB,EAAE,CAErI"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Header and footer part emitters.
3
+ *
4
+ * Each declared header/footer slot (default / first / even) becomes its own
5
+ * part — word/headerN.xml or word/footerN.xml — registered with a
6
+ * content-type override and a relationship from the main document part. The
7
+ * block content reuses the same paragraph/run emitters as the body, so a
8
+ * footer's "Page X of Y" field compiles through exactly the same five-part
9
+ * field machinery.
10
+ *
11
+ * @conformance ECMA-376 edition 5, Part 1 § 17.10.4
12
+ */
13
+ import { OOXML } from '../../primitives/namespaces.js';
14
+ import { parseXml, serializeXml, XML_DECL } from '../../primitives/xml.js';
15
+ import { buildBlock } from './table.js';
16
+ const HEADER_CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml';
17
+ const FOOTER_CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml';
18
+ const HEADER_REL_TYPE = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/header';
19
+ const FOOTER_REL_TYPE = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer';
20
+ const SLOT_ORDER = ['first', 'default', 'even'];
21
+ /**
22
+ * Allocate and emit every header/footer part, returning per-section
23
+ * reference maps for the sectPr emitter. Runs before the document part so
24
+ * relationship ids exist when sections bind their references.
25
+ */
26
+ export function emitHeaderFooterParts(spec, ctx, blockCtx) {
27
+ return spec.sections.map((section) => emitForSection(section, ctx, blockCtx));
28
+ }
29
+ function emitForSection(section, ctx, blockCtx) {
30
+ const refs = { headers: {}, footers: {} };
31
+ for (const slot of SLOT_ORDER) {
32
+ const header = section.headers?.[slot];
33
+ if (header) {
34
+ refs.headers[slot] = emitPart(header, ctx, 'header', blockCtx);
35
+ }
36
+ const footer = section.footers?.[slot];
37
+ if (footer) {
38
+ refs.footers[slot] = emitPart(footer, ctx, 'footer', blockCtx);
39
+ }
40
+ }
41
+ return refs;
42
+ }
43
+ /** @conformance ECMA-376 edition 5, Part 1 § 17.10.3 */
44
+ function emitPart(content, ctx, kind, blockCtx) {
45
+ const isHeader = kind === 'header';
46
+ const partName = isHeader ? ctx.allocateHeaderPartName() : ctx.allocateFooterPartName();
47
+ const part = ctx.registerPart(partName, isHeader ? HEADER_CONTENT_TYPE : FOOTER_CONTENT_TYPE, isHeader ? HEADER_REL_TYPE : FOOTER_REL_TYPE);
48
+ const rootTag = isHeader ? 'w:hdr' : 'w:ftr';
49
+ const doc = parseXml(`<${rootTag} xmlns:w="${OOXML.W_NS}" xmlns:r="${OOXML.R_NS}"/>`);
50
+ const root = doc.documentElement;
51
+ for (const block of content.blocks) {
52
+ root.appendChild(buildBlock(doc, block, blockCtx));
53
+ }
54
+ ctx.setFileContent(partName, XML_DECL + serializeXml(doc));
55
+ return part.documentRel.rId;
56
+ }
57
+ //# sourceMappingURL=header-footer-part.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"header-footer-part.js","sourceRoot":"","sources":["../../../src/generation/emit/header-footer-part.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAI3E,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGx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EAAE,QAA2B;IACtH,MAAM,QAAQ,GAAG,IAAI,KAAK,QAAQ,CAAC;IACnC,MAAM,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,sBAAsB,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,sBAAsB,EAAE,CAAC;IACxF,MAAM,IAAI,GAAG,GAAG,CAAC,YAAY,CAC3B,QAAQ,EACR,QAAQ,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,mBAAmB,EACpD,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,CAC7C,CAAC;IAEF,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;IAC7C,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,OAAO,aAAa,KAAK,CAAC,IAAI,cAAc,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC;IACtF,MAAM,IAAI,GAAG,GAAG,CAAC,eAAgB,CAAC;IAClC,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,GAAG,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3D,OAAO,IAAI,CAAC,WAAY,CAAC,GAAG,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * word/numbering.xml emitter.
3
+ *
4
+ * Each NumberingSpec compiles to one abstract definition plus one instance:
5
+ * the spec's string handle (`numId`) maps to sequential numeric ids assigned
6
+ * in declaration order, so identical specs always produce identical ids. The
7
+ * returned map is what lets paragraph `w:numPr` references bind to the
8
+ * numeric `w:numId` deterministically.
9
+ *
10
+ * Level children follow the CT_Lvl sequence (start, numFmt, suff, lvlText,
11
+ * lvlJc, pPr, rPr); level run properties reuse the shared rPr builder so a
12
+ * bullet glyph's font serializes exactly like body formatting would.
13
+ *
14
+ * @conformance ECMA-376 edition 5, Part 1 § 17.9.16
15
+ * @conformance ECMA-376 edition 5, Part 1 § 17.9.1
16
+ * @conformance ECMA-376 edition 5, Part 1 § 17.9.15
17
+ * @conformance ECMA-376 edition 5, Part 1 § 17.9.2
18
+ */
19
+ import type { CompileContext } from '../context.js';
20
+ import type { DocumentSpec } from '../types.js';
21
+ import type { NumberingIdMap } from './emit-context.js';
22
+ export declare const NUMBERING_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml";
23
+ export declare const NUMBERING_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering";
24
+ /**
25
+ * Emit word/numbering.xml when the spec declares numbering definitions.
26
+ * Returns the handle → numeric id map (empty when no part is emitted).
27
+ */
28
+ export declare function emitNumberingPartIfNeeded(spec: DocumentSpec, ctx: CompileContext): NumberingIdMap;
29
+ //# sourceMappingURL=numbering-part.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numbering-part.d.ts","sourceRoot":"","sources":["../../../src/generation/emit/numbering-part.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAiC,MAAM,aAAa,CAAC;AAE/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,eAAO,MAAM,sBAAsB,iFAC6C,CAAC;AACjF,eAAO,MAAM,kBAAkB,kFACkD,CAAC;AAIlF;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,cAAc,GAAG,cAAc,CA0BjG"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * word/numbering.xml emitter.
3
+ *
4
+ * Each NumberingSpec compiles to one abstract definition plus one instance:
5
+ * the spec's string handle (`numId`) maps to sequential numeric ids assigned
6
+ * in declaration order, so identical specs always produce identical ids. The
7
+ * returned map is what lets paragraph `w:numPr` references bind to the
8
+ * numeric `w:numId` deterministically.
9
+ *
10
+ * Level children follow the CT_Lvl sequence (start, numFmt, suff, lvlText,
11
+ * lvlJc, pPr, rPr); level run properties reuse the shared rPr builder so a
12
+ * bullet glyph's font serializes exactly like body formatting would.
13
+ *
14
+ * @conformance ECMA-376 edition 5, Part 1 § 17.9.16
15
+ * @conformance ECMA-376 edition 5, Part 1 § 17.9.1
16
+ * @conformance ECMA-376 edition 5, Part 1 § 17.9.15
17
+ * @conformance ECMA-376 edition 5, Part 1 § 17.9.2
18
+ */
19
+ import { createWmlElement } from '../../primitives/dom-helpers.js';
20
+ import { OOXML, W } from '../../primitives/namespaces.js';
21
+ import { parseXml, serializeXml, XML_DECL } from '../../primitives/xml.js';
22
+ import { resolveThemeColorValues } from '../theme-colors.js';
23
+ import { buildRunPropsElement } from './properties.js';
24
+ export const NUMBERING_CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml';
25
+ export const NUMBERING_REL_TYPE = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering';
26
+ const NUMBERING_SKELETON = `<w:numbering xmlns:w="${OOXML.W_NS}"/>`;
27
+ /**
28
+ * Emit word/numbering.xml when the spec declares numbering definitions.
29
+ * Returns the handle → numeric id map (empty when no part is emitted).
30
+ */
31
+ export function emitNumberingPartIfNeeded(spec, ctx) {
32
+ const ids = new Map();
33
+ const definitions = spec.numbering ?? [];
34
+ if (definitions.length === 0)
35
+ return ids;
36
+ ctx.registerPart('word/numbering.xml', NUMBERING_CONTENT_TYPE, NUMBERING_REL_TYPE);
37
+ const doc = parseXml(NUMBERING_SKELETON);
38
+ const root = doc.documentElement;
39
+ definitions.forEach((definition, index) => {
40
+ ids.set(definition.numId, index + 1);
41
+ });
42
+ const themeColorValues = resolveThemeColorValues(spec.theme);
43
+ // CT_Numbering sequence: every abstractNum precedes every num.
44
+ definitions.forEach((definition, index) => {
45
+ root.appendChild(buildAbstractNum(doc, definition, index, themeColorValues));
46
+ });
47
+ definitions.forEach((_definition, index) => {
48
+ const num = createWmlElement(doc, W.num, { 'w:numId': String(index + 1) });
49
+ num.appendChild(createWmlElement(doc, W.abstractNumId, { 'w:val': String(index) }));
50
+ root.appendChild(num);
51
+ });
52
+ ctx.setFileContent('word/numbering.xml', XML_DECL + serializeXml(doc));
53
+ return ids;
54
+ }
55
+ /**
56
+ * @conformance ECMA-376 edition 5, Part 1 § 17.9.12
57
+ * @conformance ECMA-376 edition 5, Part 1 § 17.9.6
58
+ */
59
+ function buildAbstractNum(doc, definition, abstractId, themeColorValues) {
60
+ const abstractNum = createWmlElement(doc, W.abstractNum, { 'w:abstractNumId': String(abstractId) });
61
+ abstractNum.appendChild(createWmlElement(doc, W.multiLevelType, {
62
+ 'w:val': definition.levels.length > 1 ? 'multilevel' : 'singleLevel',
63
+ }));
64
+ for (const level of definition.levels) {
65
+ abstractNum.appendChild(buildLevel(doc, level, themeColorValues));
66
+ }
67
+ return abstractNum;
68
+ }
69
+ /**
70
+ * @conformance ECMA-376 edition 5, Part 1 § 17.9.25
71
+ * @conformance ECMA-376 edition 5, Part 1 § 17.9.17
72
+ * @conformance ECMA-376 edition 5, Part 1 § 17.9.28
73
+ * @conformance ECMA-376 edition 5, Part 1 § 17.9.11
74
+ * @conformance ECMA-376 edition 5, Part 1 § 17.9.7
75
+ */
76
+ function buildLevel(doc, level, themeColorValues) {
77
+ const lvl = createWmlElement(doc, W.lvl, { 'w:ilvl': String(level.ilvl) });
78
+ lvl.appendChild(createWmlElement(doc, W.start, { 'w:val': String(level.start ?? 1) }));
79
+ lvl.appendChild(createWmlElement(doc, W.numFmt, { 'w:val': level.numFmt }));
80
+ if (level.suff !== undefined) {
81
+ lvl.appendChild(createWmlElement(doc, W.suff, { 'w:val': level.suff }));
82
+ }
83
+ lvl.appendChild(createWmlElement(doc, W.lvlText, { 'w:val': level.lvlText }));
84
+ lvl.appendChild(createWmlElement(doc, W.lvlJc, { 'w:val': 'left' }));
85
+ if (level.indentTwips !== undefined) {
86
+ const pPr = createWmlElement(doc, W.pPr);
87
+ const attrs = {};
88
+ if (level.indentTwips.left !== undefined)
89
+ attrs['w:left'] = String(level.indentTwips.left);
90
+ if (level.indentTwips.hanging !== undefined)
91
+ attrs['w:hanging'] = String(level.indentTwips.hanging);
92
+ pPr.appendChild(createWmlElement(doc, W.ind, attrs));
93
+ lvl.appendChild(pPr);
94
+ }
95
+ if (level.runProps !== undefined) {
96
+ const rPr = buildRunPropsElement(doc, level.runProps, { themeColorValues });
97
+ if (rPr)
98
+ lvl.appendChild(rPr);
99
+ }
100
+ return lvl;
101
+ }
102
+ //# sourceMappingURL=numbering-part.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numbering-part.js","sourceRoot":"","sources":["../../../src/generation/emit/numbering-part.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAG3E,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,MAAM,CAAC,MAAM,sBAAsB,GACjC,8EAA8E,CAAC;AACjF,MAAM,CAAC,MAAM,kBAAkB,GAC7B,+EAA+E,CAAC;AAElF,MAAM,kBAAkB,GAAG,yBAAyB,KAAK,CAAC,IAAI,KAAK,CAAC;AAEpE;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAC,IAAkB,EAAE,GAAmB;IAC/E,MAAM,GAAG,GAAG,IAAI,GA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,GAAG,oBAAoB,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC;QAC5E,IAAI,GAAG;YAAE,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * OPC package plumbing: [Content_Types].xml, package/part relationships, and
3
+ * document properties. Built with the same skeleton-parse + namespace-aware
4
+ * DOM approach as the WML parts — no string concatenation of dynamic values.
5
+ *
6
+ * docProps/core.xml dates come exclusively from the spec (meta.createdIso);
7
+ * generation never reads the clock, keeping output byte-deterministic.
8
+ */
9
+ import type { CompileContext } from '../context.js';
10
+ import type { DocumentSpec } from '../types.js';
11
+ export declare const CONTENT_TYPES: {
12
+ readonly document: "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml";
13
+ readonly coreProps: "application/vnd.openxmlformats-package.core-properties+xml";
14
+ readonly extendedProps: "application/vnd.openxmlformats-officedocument.extended-properties+xml";
15
+ readonly relationships: "application/vnd.openxmlformats-package.relationships+xml";
16
+ };
17
+ export declare const REL_TYPES: {
18
+ readonly officeDocument: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
19
+ readonly coreProps: "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
20
+ readonly extendedProps: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties";
21
+ };
22
+ /** Emit every package-plumbing part into the context's file map. */
23
+ export declare function emitPackageParts(spec: DocumentSpec, ctx: CompileContext): void;
24
+ //# sourceMappingURL=package-parts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-parts.d.ts","sourceRoot":"","sources":["../../../src/generation/emit/package-parts.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,eAAO,MAAM,aAAa;;;;;CAKhB,CAAC;AAEX,eAAO,MAAM,SAAS;;;;CAIZ,CAAC;AAWX,oEAAoE;AACpE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,cAAc,GAAG,IAAI,CAM9E"}
@@ -0,0 +1,121 @@
1
+ /**
2
+ * OPC package plumbing: [Content_Types].xml, package/part relationships, and
3
+ * document properties. Built with the same skeleton-parse + namespace-aware
4
+ * DOM approach as the WML parts — no string concatenation of dynamic values.
5
+ *
6
+ * docProps/core.xml dates come exclusively from the spec (meta.createdIso);
7
+ * generation never reads the clock, keeping output byte-deterministic.
8
+ */
9
+ import { OOXML } from '../../primitives/namespaces.js';
10
+ import { parseXml, serializeXml, XML_DECL } from '../../primitives/xml.js';
11
+ export const CONTENT_TYPES = {
12
+ document: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml',
13
+ coreProps: 'application/vnd.openxmlformats-package.core-properties+xml',
14
+ extendedProps: 'application/vnd.openxmlformats-officedocument.extended-properties+xml',
15
+ relationships: 'application/vnd.openxmlformats-package.relationships+xml',
16
+ };
17
+ export const REL_TYPES = {
18
+ officeDocument: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
19
+ coreProps: 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
20
+ extendedProps: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties',
21
+ };
22
+ const CORE_PROPS_NS = {
23
+ cp: 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties',
24
+ dc: 'http://purl.org/dc/elements/1.1/',
25
+ dcterms: 'http://purl.org/dc/terms/',
26
+ xsi: 'http://www.w3.org/2001/XMLSchema-instance',
27
+ };
28
+ const EXTENDED_PROPS_NS = 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties';
29
+ /** Emit every package-plumbing part into the context's file map. */
30
+ export function emitPackageParts(spec, ctx) {
31
+ ctx.setFileContent('docProps/core.xml', emitCoreProps(spec));
32
+ ctx.setFileContent('docProps/app.xml', emitAppProps());
33
+ ctx.setFileContent('_rels/.rels', emitPackageRels());
34
+ ctx.setFileContent('word/_rels/document.xml.rels', emitDocumentRels(ctx));
35
+ ctx.setFileContent('[Content_Types].xml', emitContentTypes(ctx));
36
+ }
37
+ function emitContentTypes(ctx) {
38
+ const doc = parseXml(`<Types xmlns="${OOXML.CT_NS}"/>`);
39
+ const root = doc.documentElement;
40
+ const addDefault = (extension, contentType) => {
41
+ const el = doc.createElementNS(OOXML.CT_NS, 'Default');
42
+ el.setAttribute('Extension', extension);
43
+ el.setAttribute('ContentType', contentType);
44
+ root.appendChild(el);
45
+ };
46
+ const addOverride = (partName, contentType) => {
47
+ const el = doc.createElementNS(OOXML.CT_NS, 'Override');
48
+ el.setAttribute('PartName', partName);
49
+ el.setAttribute('ContentType', contentType);
50
+ root.appendChild(el);
51
+ };
52
+ addDefault('rels', CONTENT_TYPES.relationships);
53
+ addDefault('xml', 'application/xml');
54
+ addOverride('/word/document.xml', CONTENT_TYPES.document);
55
+ addOverride('/docProps/core.xml', CONTENT_TYPES.coreProps);
56
+ addOverride('/docProps/app.xml', CONTENT_TYPES.extendedProps);
57
+ for (const part of ctx.registeredParts()) {
58
+ addOverride(`/${part.name}`, part.contentType);
59
+ }
60
+ return XML_DECL + serializeXml(doc);
61
+ }
62
+ function emitPackageRels() {
63
+ const doc = parseXml(`<Relationships xmlns="${OOXML.REL_NS}"/>`);
64
+ const root = doc.documentElement;
65
+ const add = (id, type, target) => {
66
+ const el = doc.createElementNS(OOXML.REL_NS, 'Relationship');
67
+ el.setAttribute('Id', id);
68
+ el.setAttribute('Type', type);
69
+ el.setAttribute('Target', target);
70
+ root.appendChild(el);
71
+ };
72
+ add('rId1', REL_TYPES.officeDocument, 'word/document.xml');
73
+ add('rId2', REL_TYPES.coreProps, 'docProps/core.xml');
74
+ add('rId3', REL_TYPES.extendedProps, 'docProps/app.xml');
75
+ return XML_DECL + serializeXml(doc);
76
+ }
77
+ function emitDocumentRels(ctx) {
78
+ const doc = parseXml(`<Relationships xmlns="${OOXML.REL_NS}"/>`);
79
+ const root = doc.documentElement;
80
+ for (const part of ctx.documentRelParts()) {
81
+ const el = doc.createElementNS(OOXML.REL_NS, 'Relationship');
82
+ el.setAttribute('Id', part.documentRel.rId);
83
+ el.setAttribute('Type', part.documentRel.type);
84
+ // Targets are resolved relative to word/, the directory owning document.xml.
85
+ el.setAttribute('Target', part.name.replace(/^word\//, ''));
86
+ root.appendChild(el);
87
+ }
88
+ return XML_DECL + serializeXml(doc);
89
+ }
90
+ function emitCoreProps(spec) {
91
+ const doc = parseXml(`<cp:coreProperties xmlns:cp="${CORE_PROPS_NS.cp}" xmlns:dc="${CORE_PROPS_NS.dc}"` +
92
+ ` xmlns:dcterms="${CORE_PROPS_NS.dcterms}" xmlns:xsi="${CORE_PROPS_NS.xsi}"/>`);
93
+ const root = doc.documentElement;
94
+ const meta = spec.meta;
95
+ const addText = (ns, qname, text, attrs) => {
96
+ const el = doc.createElementNS(ns, qname);
97
+ if (attrs)
98
+ for (const [k, v] of Object.entries(attrs))
99
+ el.setAttribute(k, v);
100
+ el.appendChild(doc.createTextNode(text));
101
+ root.appendChild(el);
102
+ };
103
+ if (meta?.title)
104
+ addText(CORE_PROPS_NS.dc, 'dc:title', meta.title);
105
+ if (meta?.author)
106
+ addText(CORE_PROPS_NS.dc, 'dc:creator', meta.author);
107
+ if (meta?.createdIso) {
108
+ addText(CORE_PROPS_NS.dcterms, 'dcterms:created', meta.createdIso, { 'xsi:type': 'dcterms:W3CDTF' });
109
+ addText(CORE_PROPS_NS.dcterms, 'dcterms:modified', meta.createdIso, { 'xsi:type': 'dcterms:W3CDTF' });
110
+ }
111
+ return XML_DECL + serializeXml(doc);
112
+ }
113
+ function emitAppProps() {
114
+ const doc = parseXml(`<Properties xmlns="${EXTENDED_PROPS_NS}"/>`);
115
+ const root = doc.documentElement;
116
+ const app = doc.createElementNS(EXTENDED_PROPS_NS, 'Application');
117
+ app.appendChild(doc.createTextNode('safe-docx'));
118
+ root.appendChild(app);
119
+ return XML_DECL + serializeXml(doc);
120
+ }
121
+ //# sourceMappingURL=package-parts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-parts.js","sourceRoot":"","sources":["../../../src/generation/emit/package-parts.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAI3E,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,QAAQ,EAAE,kFAAkF;IAC5F,SAAS,EAAE,4DAA4D;IACvE,aAAa,EAAE,uEAAuE;IACtF,aAAa,EAAE,0DAA0D;CACjE,CAAC;AAEX,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,cAAc,EAAE,oFAAoF;IACpG,SAAS,EAAE,uFAAuF;IAClG,aAAa,EAAE,yFAAyF;CAChG,CAAC;AAEX,MAAM,aAAa,GAAG;IACpB,EAAE,EAAE,yEAAyE;IAC7E,EAAE,EAAE,kCAAkC;IACtC,OAAO,EAAE,2BAA2B;IACpC,GAAG,EAAE,2CAA2C;CACxC,CAAC;AAEX,MAAM,iBAAiB,GAAG,2EAA2E,CAAC;AAEtG,oEAAoE;AACpE,MAAM,UAAU,gBAAgB,CAAC,IAAkB,EAAE,GAAmB;IACtE,GAAG,CAAC,cAAc,CAAC,mBAAmB,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7D,GAAG,CAAC,cAAc,CAAC,kBAAkB,EAAE,YAAY,EAAE,CAAC,CAAC;IACvD,GAAG,CAAC,cAAc,CAAC,aAAa,EAAE,eAAe,EAAE,CAAC,CAAC;IACrD,GAAG,CAAC,cAAc,CAAC,8BAA8B,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1E,GAA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