@syncfusion/ej2-docx 0.0.0-stage → 35.1.39

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 (416) hide show
  1. package/README.md +68 -2
  2. package/core.js +4 -0
  3. package/dist/ej2-docx.umd.min.js +2 -0
  4. package/dist/ej2-docx.umd.min.js.map +1 -0
  5. package/dist/es6/ej2-docx.es2015.js +66697 -0
  6. package/dist/es6/ej2-docx.es2015.js.map +1 -0
  7. package/dist/es6/ej2-docx.es5.js +77568 -0
  8. package/dist/es6/ej2-docx.es5.js.map +1 -0
  9. package/dist/global/ej2-docx.min.js +2 -0
  10. package/dist/global/ej2-docx.min.js.map +1 -0
  11. package/dist/global/index.d.ts +5 -0
  12. package/features.js +4 -0
  13. package/index.js +4 -0
  14. package/license +10 -0
  15. package/package.json +31 -4
  16. package/src/all.d.ts +50 -0
  17. package/src/all.js +147 -0
  18. package/src/core/compat/base64.d.ts +13 -0
  19. package/src/core/compat/base64.js +90 -0
  20. package/src/core/compat/object-compat.d.ts +30 -0
  21. package/src/core/compat/object-compat.js +40 -0
  22. package/src/core/compat/sha256.d.ts +9 -0
  23. package/src/core/compat/sha256.js +98 -0
  24. package/src/core/errors/docx-error.d.ts +89 -0
  25. package/src/core/errors/docx-error.js +138 -0
  26. package/src/core/errors/error-codes.d.ts +8 -0
  27. package/src/core/errors/error-codes.js +0 -0
  28. package/src/core/errors/index.d.ts +10 -0
  29. package/src/core/errors/index.js +9 -0
  30. package/src/core/index.d.ts +12 -0
  31. package/src/core/index.js +12 -0
  32. package/src/core/mc/alternate-content.d.ts +7 -0
  33. package/src/core/mc/alternate-content.js +67 -0
  34. package/src/core/mc/attributes.d.ts +24 -0
  35. package/src/core/mc/attributes.js +82 -0
  36. package/src/core/mc/index.d.ts +7 -0
  37. package/src/core/mc/index.js +5 -0
  38. package/src/core/mc/inspect.d.ts +16 -0
  39. package/src/core/mc/inspect.js +148 -0
  40. package/src/core/mc/namespaces.d.ts +4 -0
  41. package/src/core/mc/namespaces.js +4 -0
  42. package/src/core/mc/scope.d.ts +6 -0
  43. package/src/core/mc/scope.js +47 -0
  44. package/src/core/opc/content-types.d.ts +34 -0
  45. package/src/core/opc/content-types.js +162 -0
  46. package/src/core/opc/index.d.ts +8 -0
  47. package/src/core/opc/index.js +4 -0
  48. package/src/core/opc/package.d.ts +49 -0
  49. package/src/core/opc/package.js +324 -0
  50. package/src/core/opc/part-name.d.ts +47 -0
  51. package/src/core/opc/part-name.js +205 -0
  52. package/src/core/opc/relationships.d.ts +46 -0
  53. package/src/core/opc/relationships.js +212 -0
  54. package/src/core/preservation/index.d.ts +2 -0
  55. package/src/core/preservation/index.js +1 -0
  56. package/src/core/preservation/opaque-body.d.ts +16 -0
  57. package/src/core/preservation/opaque-body.js +69 -0
  58. package/src/core/registry/block-handlers.d.ts +30 -0
  59. package/src/core/registry/block-handlers.js +36 -0
  60. package/src/core/registry/create-defaults.d.ts +39 -0
  61. package/src/core/registry/create-defaults.js +42 -0
  62. package/src/core/registry/feature-registry.d.ts +20 -0
  63. package/src/core/registry/feature-registry.js +29 -0
  64. package/src/core/registry/index.d.ts +9 -0
  65. package/src/core/registry/index.js +8 -0
  66. package/src/core/registry/inline-handlers.d.ts +20 -0
  67. package/src/core/registry/inline-handlers.js +30 -0
  68. package/src/core/registry/materialize-handlers.d.ts +35 -0
  69. package/src/core/registry/materialize-handlers.js +75 -0
  70. package/src/core/registry/multi-part-handlers.d.ts +37 -0
  71. package/src/core/registry/multi-part-handlers.js +206 -0
  72. package/src/core/registry/package-part-handlers.d.ts +28 -0
  73. package/src/core/registry/package-part-handlers.js +190 -0
  74. package/src/core/registry/part-handlers.d.ts +24 -0
  75. package/src/core/registry/part-handlers.js +172 -0
  76. package/src/core/registry/run-leaf-handlers.d.ts +26 -0
  77. package/src/core/registry/run-leaf-handlers.js +72 -0
  78. package/src/core/security/limits.d.ts +40 -0
  79. package/src/core/security/limits.js +26 -0
  80. package/src/core/xml/index.d.ts +7 -0
  81. package/src/core/xml/index.js +3 -0
  82. package/src/core/xml/model.d.ts +66 -0
  83. package/src/core/xml/model.js +17 -0
  84. package/src/core/xml/parse.d.ts +12 -0
  85. package/src/core/xml/parse.js +382 -0
  86. package/src/core/xml/serialize.d.ts +6 -0
  87. package/src/core/xml/serialize.js +93 -0
  88. package/src/core/zip/crc32.d.ts +2 -0
  89. package/src/core/zip/crc32.js +25 -0
  90. package/src/core/zip/deflate.d.ts +6 -0
  91. package/src/core/zip/deflate.js +6 -0
  92. package/src/core/zip/index.d.ts +10 -0
  93. package/src/core/zip/index.js +4 -0
  94. package/src/core/zip/inflate-raw.d.ts +17 -0
  95. package/src/core/zip/inflate-raw.js +450 -0
  96. package/src/core/zip/names.d.ts +6 -0
  97. package/src/core/zip/names.js +52 -0
  98. package/src/core/zip/read.d.ts +8 -0
  99. package/src/core/zip/read.js +262 -0
  100. package/src/core/zip/write.d.ts +7 -0
  101. package/src/core/zip/write.js +189 -0
  102. package/src/core/zip/zip-entry.d.ts +4 -0
  103. package/src/core/zip/zip-entry.js +0 -0
  104. package/src/features/bibliography/index.d.ts +100 -0
  105. package/src/features/bibliography/index.js +290 -0
  106. package/src/features/bookmarks/index.d.ts +331 -0
  107. package/src/features/bookmarks/index.js +1009 -0
  108. package/src/features/comments/comment-extensions.d.ts +157 -0
  109. package/src/features/comments/comment-extensions.js +356 -0
  110. package/src/features/comments/index.d.ts +579 -0
  111. package/src/features/comments/index.js +1727 -0
  112. package/src/features/content-controls/index.d.ts +821 -0
  113. package/src/features/content-controls/index.js +2857 -0
  114. package/src/features/custom-xml/index.d.ts +236 -0
  115. package/src/features/custom-xml/index.js +661 -0
  116. package/src/features/document/alignment.d.ts +23 -0
  117. package/src/features/document/alignment.js +36 -0
  118. package/src/features/document/alt-chunk.d.ts +103 -0
  119. package/src/features/document/alt-chunk.js +221 -0
  120. package/src/features/document/assert-never.d.ts +1 -0
  121. package/src/features/document/assert-never.js +4 -0
  122. package/src/features/document/augmentations.d.ts +578 -0
  123. package/src/features/document/augmentations.js +0 -0
  124. package/src/features/document/body-always-on.d.ts +36 -0
  125. package/src/features/document/body-always-on.js +66 -0
  126. package/src/features/document/body-blocks.d.ts +7 -0
  127. package/src/features/document/body-blocks.js +78 -0
  128. package/src/features/document/body-item-adapters.d.ts +62 -0
  129. package/src/features/document/body-item-adapters.js +97 -0
  130. package/src/features/document/body-item-collection.d.ts +151 -0
  131. package/src/features/document/body-item-collection.js +440 -0
  132. package/src/features/document/body-item.d.ts +35 -0
  133. package/src/features/document/body-item.js +8 -0
  134. package/src/features/document/body.d.ts +150 -0
  135. package/src/features/document/body.js +263 -0
  136. package/src/features/document/character-format.d.ts +413 -0
  137. package/src/features/document/character-format.js +2054 -0
  138. package/src/features/document/color.d.ts +178 -0
  139. package/src/features/document/color.js +495 -0
  140. package/src/features/document/document.d.ts +410 -0
  141. package/src/features/document/document.js +1049 -0
  142. package/src/features/document/element-type.d.ts +68 -0
  143. package/src/features/document/element-type.js +133 -0
  144. package/src/features/document/entity-type.d.ts +92 -0
  145. package/src/features/document/entity-type.js +93 -0
  146. package/src/features/document/feature-block.d.ts +16 -0
  147. package/src/features/document/feature-block.js +0 -0
  148. package/src/features/document/feature-inline.d.ts +13 -0
  149. package/src/features/document/feature-inline.js +0 -0
  150. package/src/features/document/feature-multi-package-part.d.ts +19 -0
  151. package/src/features/document/feature-multi-package-part.js +8 -0
  152. package/src/features/document/feature-package-level-part.d.ts +18 -0
  153. package/src/features/document/feature-package-level-part.js +8 -0
  154. package/src/features/document/feature-package-part.d.ts +14 -0
  155. package/src/features/document/feature-package-part.js +0 -0
  156. package/src/features/document/feature-run-leaf.d.ts +9 -0
  157. package/src/features/document/feature-run-leaf.js +0 -0
  158. package/src/features/document/headers-footers.d.ts +206 -0
  159. package/src/features/document/headers-footers.js +384 -0
  160. package/src/features/document/index.d.ts +41 -0
  161. package/src/features/document/index.js +34 -0
  162. package/src/features/document/length.d.ts +152 -0
  163. package/src/features/document/length.js +245 -0
  164. package/src/features/document/load-options.d.ts +14 -0
  165. package/src/features/document/load-options.js +0 -0
  166. package/src/features/document/locale-ids.d.ts +227 -0
  167. package/src/features/document/locale-ids.js +485 -0
  168. package/src/features/document/on-off.d.ts +9 -0
  169. package/src/features/document/on-off.js +27 -0
  170. package/src/features/document/page-setup.d.ts +339 -0
  171. package/src/features/document/page-setup.js +244 -0
  172. package/src/features/document/paragraph-format.d.ts +880 -0
  173. package/src/features/document/paragraph-format.js +2807 -0
  174. package/src/features/document/paragraph-item-collection.d.ts +162 -0
  175. package/src/features/document/paragraph-item-collection.js +363 -0
  176. package/src/features/document/paragraph-item.d.ts +83 -0
  177. package/src/features/document/paragraph-item.js +103 -0
  178. package/src/features/document/paragraph.d.ts +435 -0
  179. package/src/features/document/paragraph.js +888 -0
  180. package/src/features/document/run.d.ts +1 -0
  181. package/src/features/document/run.js +768 -0
  182. package/src/features/document/section-partition-flatten.d.ts +124 -0
  183. package/src/features/document/section-partition-flatten.js +217 -0
  184. package/src/features/document/section-properties-model.d.ts +13 -0
  185. package/src/features/document/section-properties-model.js +0 -0
  186. package/src/features/document/section.d.ts +93 -0
  187. package/src/features/document/section.js +178 -0
  188. package/src/features/document/sections.d.ts +103 -0
  189. package/src/features/document/sections.js +217 -0
  190. package/src/features/document/sub-super-script.d.ts +23 -0
  191. package/src/features/document/sub-super-script.js +43 -0
  192. package/src/features/document/text-range.d.ts +445 -0
  193. package/src/features/document/text-range.js +1156 -0
  194. package/src/features/document/typed-body-collections.d.ts +162 -0
  195. package/src/features/document/typed-body-collections.js +371 -0
  196. package/src/features/document/underline-style.d.ts +38 -0
  197. package/src/features/document/underline-style.js +126 -0
  198. package/src/features/document/units.d.ts +8 -0
  199. package/src/features/document/units.js +7 -0
  200. package/src/features/document/wml.d.ts +16 -0
  201. package/src/features/document/wml.js +67 -0
  202. package/src/features/drawing/authoring.d.ts +27 -0
  203. package/src/features/drawing/authoring.js +271 -0
  204. package/src/features/drawing/body-pr.d.ts +271 -0
  205. package/src/features/drawing/body-pr.js +663 -0
  206. package/src/features/drawing/drawing-shape.d.ts +1192 -0
  207. package/src/features/drawing/drawing-shape.js +3239 -0
  208. package/src/features/drawing/encode-builders.d.ts +176 -0
  209. package/src/features/drawing/encode-builders.js +390 -0
  210. package/src/features/drawing/fill-format.d.ts +52 -0
  211. package/src/features/drawing/fill-format.js +124 -0
  212. package/src/features/drawing/host-codec.d.ts +632 -0
  213. package/src/features/drawing/host-codec.js +2595 -0
  214. package/src/features/drawing/index.d.ts +13 -0
  215. package/src/features/drawing/index.js +33 -0
  216. package/src/features/drawing/line-format.d.ts +76 -0
  217. package/src/features/drawing/line-format.js +343 -0
  218. package/src/features/drawing/parse-register.d.ts +50 -0
  219. package/src/features/drawing/parse-register.js +257 -0
  220. package/src/features/drawing/residual-utils.d.ts +47 -0
  221. package/src/features/drawing/residual-utils.js +290 -0
  222. package/src/features/drawing/shape-types.d.ts +433 -0
  223. package/src/features/drawing/shape-types.js +437 -0
  224. package/src/features/drawing/sp-pr.d.ts +396 -0
  225. package/src/features/drawing/sp-pr.js +610 -0
  226. package/src/features/drawing/text-frame.d.ts +90 -0
  227. package/src/features/drawing/text-frame.js +152 -0
  228. package/src/features/drawing/types.d.ts +352 -0
  229. package/src/features/drawing/types.js +60 -0
  230. package/src/features/drawing/wrap-format.d.ts +62 -0
  231. package/src/features/drawing/wrap-format.js +114 -0
  232. package/src/features/editable-ranges/index.d.ts +494 -0
  233. package/src/features/editable-ranges/index.js +1348 -0
  234. package/src/features/fields/index.d.ts +428 -0
  235. package/src/features/fields/index.js +2148 -0
  236. package/src/features/fields/paragraph-field.d.ts +187 -0
  237. package/src/features/fields/paragraph-field.js +692 -0
  238. package/src/features/font-table/font-substitution-table.d.ts +75 -0
  239. package/src/features/font-table/font-substitution-table.js +257 -0
  240. package/src/features/font-table/font-table-entry.d.ts +255 -0
  241. package/src/features/font-table/font-table-entry.js +823 -0
  242. package/src/features/font-table/font-table.d.ts +128 -0
  243. package/src/features/font-table/font-table.js +313 -0
  244. package/src/features/font-table/index.d.ts +27 -0
  245. package/src/features/font-table/index.js +48 -0
  246. package/src/features/glossary/index.d.ts +97 -0
  247. package/src/features/glossary/index.js +286 -0
  248. package/src/features/headers-footers/index.d.ts +506 -0
  249. package/src/features/headers-footers/index.js +1666 -0
  250. package/src/features/hyperlinks/index.d.ts +230 -0
  251. package/src/features/hyperlinks/index.js +685 -0
  252. package/src/features/images/caption-authoring-api.d.ts +33 -0
  253. package/src/features/images/caption-authoring-api.js +33 -0
  254. package/src/features/images/caption-enums.d.ts +52 -0
  255. package/src/features/images/caption-enums.js +141 -0
  256. package/src/features/images/caption-host.d.ts +10 -0
  257. package/src/features/images/caption-host.js +21 -0
  258. package/src/features/images/captions.d.ts +13 -0
  259. package/src/features/images/captions.js +142 -0
  260. package/src/features/images/host-codec.d.ts +103 -0
  261. package/src/features/images/host-codec.js +720 -0
  262. package/src/features/images/image-sniff.d.ts +21 -0
  263. package/src/features/images/image-sniff.js +71 -0
  264. package/src/features/images/index.d.ts +506 -0
  265. package/src/features/images/index.js +1429 -0
  266. package/src/features/images/layout-types.d.ts +232 -0
  267. package/src/features/images/layout-types.js +294 -0
  268. package/src/features/images/public-entry.d.ts +9 -0
  269. package/src/features/images/public-entry.js +9 -0
  270. package/src/features/index.d.ts +35 -0
  271. package/src/features/index.js +36 -0
  272. package/src/features/mail-merge/index.d.ts +113 -0
  273. package/src/features/mail-merge/index.js +315 -0
  274. package/src/features/notes/index.d.ts +573 -0
  275. package/src/features/notes/index.js +1725 -0
  276. package/src/features/numbering/abstract-numbering.d.ts +90 -0
  277. package/src/features/numbering/abstract-numbering.js +292 -0
  278. package/src/features/numbering/index.d.ts +182 -0
  279. package/src/features/numbering/index.js +668 -0
  280. package/src/features/numbering/list-format.d.ts +158 -0
  281. package/src/features/numbering/list-format.js +590 -0
  282. package/src/features/numbering/list-string.d.ts +7 -0
  283. package/src/features/numbering/list-string.js +423 -0
  284. package/src/features/numbering/list-style.d.ts +204 -0
  285. package/src/features/numbering/list-style.js +1084 -0
  286. package/src/features/numbering/numbering-instance.d.ts +101 -0
  287. package/src/features/numbering/numbering-instance.js +329 -0
  288. package/src/features/numbering/numbering-level.d.ts +118 -0
  289. package/src/features/numbering/numbering-level.js +501 -0
  290. package/src/features/numbering/picture-bullet.d.ts +34 -0
  291. package/src/features/numbering/picture-bullet.js +88 -0
  292. package/src/features/ole-object/catalog.d.ts +300 -0
  293. package/src/features/ole-object/catalog.js +908 -0
  294. package/src/features/ole-object/index.d.ts +526 -0
  295. package/src/features/ole-object/index.js +1421 -0
  296. package/src/features/ole-object/relationship.d.ts +27 -0
  297. package/src/features/ole-object/relationship.js +27 -0
  298. package/src/features/ole-object/typed-dom.d.ts +186 -0
  299. package/src/features/ole-object/typed-dom.js +595 -0
  300. package/src/features/properties/index.d.ts +205 -0
  301. package/src/features/properties/index.js +549 -0
  302. package/src/features/revisions/index.d.ts +204 -0
  303. package/src/features/revisions/index.js +695 -0
  304. package/src/features/sections/column-collection.d.ts +119 -0
  305. package/src/features/sections/column-collection.js +478 -0
  306. package/src/features/sections/column.d.ts +15 -0
  307. package/src/features/sections/column.js +37 -0
  308. package/src/features/sections/index.d.ts +91 -0
  309. package/src/features/sections/index.js +1096 -0
  310. package/src/features/sections/margins.d.ts +40 -0
  311. package/src/features/sections/margins.js +105 -0
  312. package/src/features/sections/page-number-style.d.ts +21 -0
  313. package/src/features/sections/page-number-style.js +62 -0
  314. package/src/features/sections/page-orientation.d.ts +10 -0
  315. package/src/features/sections/page-orientation.js +10 -0
  316. package/src/features/sections/page-setup.d.ts +435 -0
  317. package/src/features/sections/page-setup.js +1479 -0
  318. package/src/features/sections/page-size.d.ts +59 -0
  319. package/src/features/sections/page-size.js +68 -0
  320. package/src/features/sections/section-break-code.d.ts +27 -0
  321. package/src/features/sections/section-break-code.js +60 -0
  322. package/src/features/sections/section-document-association.d.ts +18 -0
  323. package/src/features/sections/section-document-association.js +31 -0
  324. package/src/features/sections/section-validation.d.ts +43 -0
  325. package/src/features/sections/section-validation.js +97 -0
  326. package/src/features/settings/attached-template.d.ts +35 -0
  327. package/src/features/settings/attached-template.js +98 -0
  328. package/src/features/settings/compat-settings.d.ts +216 -0
  329. package/src/features/settings/compat-settings.js +508 -0
  330. package/src/features/settings/document-background.d.ts +59 -0
  331. package/src/features/settings/document-background.js +131 -0
  332. package/src/features/settings/document-protection.d.ts +65 -0
  333. package/src/features/settings/document-protection.js +157 -0
  334. package/src/features/settings/document-settings-facades.d.ts +108 -0
  335. package/src/features/settings/document-settings-facades.js +312 -0
  336. package/src/features/settings/document-settings-values.d.ts +43 -0
  337. package/src/features/settings/document-settings-values.js +60 -0
  338. package/src/features/settings/footnote-properties.d.ts +211 -0
  339. package/src/features/settings/footnote-properties.js +591 -0
  340. package/src/features/settings/index.d.ts +356 -0
  341. package/src/features/settings/index.js +829 -0
  342. package/src/features/settings/settings-children.d.ts +151 -0
  343. package/src/features/settings/settings-children.js +505 -0
  344. package/src/features/settings/web-settings.d.ts +88 -0
  345. package/src/features/settings/web-settings.js +227 -0
  346. package/src/features/settings/zoom.d.ts +79 -0
  347. package/src/features/settings/zoom.js +147 -0
  348. package/src/features/styles/builtin-catalog.d.ts +159 -0
  349. package/src/features/styles/builtin-catalog.js +963 -0
  350. package/src/features/styles/builtin-resolver.d.ts +49 -0
  351. package/src/features/styles/builtin-resolver.js +165 -0
  352. package/src/features/styles/default-styles.d.ts +37 -0
  353. package/src/features/styles/default-styles.js +186 -0
  354. package/src/features/styles/default-theme.d.ts +13 -0
  355. package/src/features/styles/default-theme.js +13 -0
  356. package/src/features/styles/doc-defaults.d.ts +58 -0
  357. package/src/features/styles/doc-defaults.js +178 -0
  358. package/src/features/styles/formatting-resolver.d.ts +27 -0
  359. package/src/features/styles/formatting-resolver.js +72 -0
  360. package/src/features/styles/index.d.ts +256 -0
  361. package/src/features/styles/index.js +1325 -0
  362. package/src/features/styles/latent-styles.d.ts +68 -0
  363. package/src/features/styles/latent-styles.js +305 -0
  364. package/src/features/styles/paragraph-properties.d.ts +71 -0
  365. package/src/features/styles/paragraph-properties.js +237 -0
  366. package/src/features/styles/run-properties.d.ts +93 -0
  367. package/src/features/styles/run-properties.js +516 -0
  368. package/src/features/styles/style-base.d.ts +402 -0
  369. package/src/features/styles/style-base.js +1026 -0
  370. package/src/features/styles/style-collection.d.ts +264 -0
  371. package/src/features/styles/style-collection.js +714 -0
  372. package/src/features/styles/style-format-bridge.d.ts +64 -0
  373. package/src/features/styles/style-format-bridge.js +100 -0
  374. package/src/features/styles/style.d.ts +84 -0
  375. package/src/features/styles/style.js +375 -0
  376. package/src/features/styles/styles-with-effects.d.ts +71 -0
  377. package/src/features/styles/styles-with-effects.js +180 -0
  378. package/src/features/styles/table-style.d.ts +272 -0
  379. package/src/features/styles/table-style.js +1226 -0
  380. package/src/features/styles/theme.d.ts +126 -0
  381. package/src/features/styles/theme.js +377 -0
  382. package/src/features/tables/border-style-map.d.ts +24 -0
  383. package/src/features/tables/border-style-map.js +81 -0
  384. package/src/features/tables/borders.d.ts +126 -0
  385. package/src/features/tables/borders.js +527 -0
  386. package/src/features/tables/collections.d.ts +113 -0
  387. package/src/features/tables/collections.js +261 -0
  388. package/src/features/tables/format.d.ts +208 -0
  389. package/src/features/tables/format.js +716 -0
  390. package/src/features/tables/index.d.ts +597 -0
  391. package/src/features/tables/index.js +2386 -0
  392. package/src/features/tables/paddings.d.ts +41 -0
  393. package/src/features/tables/paddings.js +97 -0
  394. package/src/features/tables/tbl-pr-positioning.d.ts +27 -0
  395. package/src/features/tables/tbl-pr-positioning.js +178 -0
  396. package/src/features/tables/tbl-pr.d.ts +528 -0
  397. package/src/features/tables/tbl-pr.js +1208 -0
  398. package/src/features/tables/tc-pr.d.ts +168 -0
  399. package/src/features/tables/tc-pr.js +553 -0
  400. package/src/features/tables/tr-pr.d.ts +60 -0
  401. package/src/features/tables/tr-pr.js +215 -0
  402. package/src/features/watermark/detect.d.ts +76 -0
  403. package/src/features/watermark/detect.js +219 -0
  404. package/src/features/watermark/index.d.ts +28 -0
  405. package/src/features/watermark/index.js +91 -0
  406. package/src/features/watermark/logical-store.d.ts +29 -0
  407. package/src/features/watermark/logical-store.js +31 -0
  408. package/src/features/watermark/model.d.ts +285 -0
  409. package/src/features/watermark/model.js +597 -0
  410. package/src/features/watermark/parse.d.ts +84 -0
  411. package/src/features/watermark/parse.js +815 -0
  412. package/src/features/watermark/serialize.d.ts +98 -0
  413. package/src/features/watermark/serialize.js +1517 -0
  414. package/src/global.js +1 -0
  415. package/src/index.d.ts +2 -0
  416. package/src/index.js +2 -0
@@ -0,0 +1,1049 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ return new (P || (P = Promise))(function (resolve, reject) {
3
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
4
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
5
+ function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
6
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
7
+ });
8
+ };
9
+ var __generator = (this && this.__generator) || function (thisArg, body) {
10
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
11
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ function verb(n) { return function (v) { return step([n, v]); }; }
13
+ function step(op) {
14
+ if (f) throw new TypeError("Generator is already executing.");
15
+ while (_) try {
16
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
17
+ if (y = 0, t) op = [op[0] & 2, t.value];
18
+ switch (op[0]) {
19
+ case 0: case 1: t = op; break;
20
+ case 4: _.label++; return { value: op[1], done: false };
21
+ case 5: _.label++; y = op[1]; op = [0]; continue;
22
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
23
+ default:
24
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
25
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
26
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
27
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
28
+ if (t[2]) _.ops.pop();
29
+ _.trys.pop(); continue;
30
+ }
31
+ op = body.call(thisArg, _);
32
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
33
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
34
+ }
35
+ };
36
+ var __values = (this && this.__values) || function (o) {
37
+ var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
38
+ if (m) return m.call(o);
39
+ return {
40
+ next: function () {
41
+ if (o && i >= o.length) o = void 0;
42
+ return { value: o && o[i++], done: !o };
43
+ }
44
+ };
45
+ };
46
+ var __read = (this && this.__read) || function (o, n) {
47
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
48
+ if (!m) return o;
49
+ var i = m.call(o), r, ar = [], e;
50
+ try {
51
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
52
+ }
53
+ catch (error) { e = { error: error }; }
54
+ finally {
55
+ try {
56
+ if (r && !r.done && (m = i["return"])) m.call(i);
57
+ }
58
+ finally { if (e) throw e.error; }
59
+ }
60
+ return ar;
61
+ };
62
+ var __spread = (this && this.__spread) || function () {
63
+ for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
64
+ return ar;
65
+ };
66
+ import { DetachedObjectError, InvalidArgumentError, IoError } from '../../core/errors/docx-error';
67
+ import { inspectMarkupCompatibility } from '../../core/mc/index';
68
+ import { createTransitionalWordPackage, loadOpcPackage, officeDocumentPartName, partByName, saveOpcPackage, withReplacedPart } from '../../core/opc/index';
69
+ import { documentBody } from '../../core/preservation/index';
70
+ import { parseXml, serializeXml, WML_TRANSITIONAL_NAMESPACE } from '../../core/xml/index';
71
+ import { materializeFeatureSideEffects } from '../../core/registry/materialize-handlers';
72
+ import { applyFeatureParts, loadFeatureParts, } from '../../core/registry/part-handlers';
73
+ import { applyFeatureMultiParts, loadFeatureMultiParts, } from '../../core/registry/multi-part-handlers';
74
+ import { applyFeaturePackageParts, loadFeaturePackageParts, } from '../../core/registry/package-part-handlers';
75
+ import { detachedBodyBlockParseContext } from '../../core/registry/block-handlers';
76
+ import { isFeaturePackageLevelPart } from './feature-package-level-part';
77
+ import { isFeatureMultiPackagePart } from './feature-multi-package-part';
78
+ import { altChunksInBlocks, bindAltChunkDocument, ensureCoreBlockHandlers } from './alt-chunk';
79
+ import { ensureAlwaysOnBodyFeaturesRegistered } from './body-always-on';
80
+ import { parseBodyBlocks, serializeBodyBlocks } from './body-blocks';
81
+ import { Paragraph } from './paragraph';
82
+ import { Section } from './section';
83
+ import { flattenSectionsToBodyBlocks, materializeSectionProperties, notifySectionPropertiesAttached, partitionBodyIntoSections, } from './section-partition-flatten';
84
+ import { Sections } from './sections';
85
+ import { isWml, wmlElement } from './wml';
86
+ import { decodeBase64, encodeBase64 } from '../../core/compat/base64';
87
+ /**
88
+ * Core alt-chunk handlers + always-on body/run features (tables / content-controls /
89
+ * images / drawing when bootstrapped from the main entry).
90
+ */
91
+ function ensureBodyParseHandlers() {
92
+ ensureCoreBlockHandlers();
93
+ ensureAlwaysOnBodyFeaturesRegistered();
94
+ }
95
+ var utf8 = new TextEncoder();
96
+ var utf8Decoder = new TextDecoder('utf-8');
97
+ /**
98
+ * In-memory WordprocessingML document backed by an OPC package.
99
+ *
100
+ * Load via {@link WordDocument.open} / {@link WordDocument.openSync} from bytes or base64,
101
+ * or {@link WordDocument.openAsync} from a browser `File` / `Blob`. There is no filesystem-path open.
102
+ * Serialize with {@link WordDocument.save} / {@link WordDocument.saveSync} to bytes, a browser
103
+ * download file name, or base64. There is no Node.js filesystem write.
104
+ *
105
+ * Main-story entry is {@link Document.sections} (each {@link Section.body}).
106
+ *
107
+ * @public
108
+ */
109
+ var WordDocument = /** @class */ (function () {
110
+ function WordDocument(pkg, rootExtra, background, items, sectPr, featureParts) {
111
+ var e_1, _a;
112
+ this.pkg = pkg;
113
+ this.rootExtra = rootExtra;
114
+ this.background = background;
115
+ this.sectPr = sectPr;
116
+ this.finalSectionModel = undefined;
117
+ this.featureParts = featureParts;
118
+ var section = new Section(this, items);
119
+ this.sectionsInstance = new Sections(this, [section]);
120
+ // Body constructor only copies the store — attach / bind seeded blocks here.
121
+ var body = section.body;
122
+ try {
123
+ for (var _b = __values(body.listBlocks()), _c = _b.next(); !_c.done; _c = _b.next()) {
124
+ var block = _c.value;
125
+ if (block.type === 'paragraph') {
126
+ block.paragraph.attach(body);
127
+ continue;
128
+ }
129
+ if (block.type === 'feature') {
130
+ bindDocumentToFeatureBlock(block.value, this);
131
+ }
132
+ }
133
+ }
134
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
135
+ finally {
136
+ try {
137
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
138
+ }
139
+ finally { if (e_1) throw e_1.error; }
140
+ }
141
+ bindAltChunkDocument(body.listBlocks(), this);
142
+ section.syncCollections();
143
+ }
144
+ /**
145
+ * Minimal Transitional package with one empty paragraph (`w:p` in `w:body`).
146
+ *
147
+ * Builds the in-memory document and package scaffold directly — does not
148
+ * serialize then re-parse as the sole create path.
149
+ */
150
+ WordDocument.create = function () {
151
+ ensureBodyParseHandlers();
152
+ var pkg = createTransitionalWordPackage();
153
+ var name = officeDocumentPartName(pkg);
154
+ var paragraph = new Paragraph(undefined);
155
+ return new WordDocument(pkg, {
156
+ attributes: [],
157
+ namespaceDeclarations: [{ prefix: 'w', namespaceUri: WML_TRANSITIONAL_NAMESPACE }],
158
+ }, undefined, [{ type: 'paragraph', paragraph: paragraph }], undefined, mergeFeatureParts(loadFeatureParts(pkg, name), loadFeatureMultiParts(pkg, name), loadFeaturePackageParts(pkg)));
159
+ };
160
+ /**
161
+ * @private
162
+ */
163
+ WordDocument.fromPackage = function (pkg, limits) {
164
+ var e_2, _a, e_3, _b, e_4, _c;
165
+ ensureBodyParseHandlers();
166
+ var name = officeDocumentPartName(pkg);
167
+ var part = partByName(pkg, name);
168
+ if (part === undefined) {
169
+ throw new DetachedObjectError('Main document part is missing');
170
+ }
171
+ var root = parseXml(utf8Decoder.decode(part.data), limits);
172
+ inspectMarkupCompatibility(root);
173
+ var background;
174
+ try {
175
+ for (var _d = __values(root.children), _e = _d.next(); !_e.done; _e = _d.next()) {
176
+ var child = _e.value;
177
+ if (child.kind === 'element' && isWml(child, 'background')) {
178
+ background = child;
179
+ break;
180
+ }
181
+ }
182
+ }
183
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
184
+ finally {
185
+ try {
186
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
187
+ }
188
+ finally { if (e_2) throw e_2.error; }
189
+ }
190
+ // Chart, ink, and diagram parts have no typed handlers. Leaving them
191
+ // unregistered keeps those OPC parts untouched on save.
192
+ var featureParts = mergeFeatureParts(loadFeatureParts(pkg, name, limits), loadFeatureMultiParts(pkg, name, limits), loadFeaturePackageParts(pkg, limits));
193
+ var body = documentBody(root);
194
+ var parseCtx = detachedBodyBlockParseContext();
195
+ var blocks = [];
196
+ var sectPr;
197
+ try {
198
+ for (var _f = __values(body.children), _g = _f.next(); !_g.done; _g = _f.next()) {
199
+ var child = _g.value;
200
+ if (child.kind !== 'element') {
201
+ continue;
202
+ }
203
+ if (isWml(child, 'sectPr')) {
204
+ sectPr = child;
205
+ continue;
206
+ }
207
+ blocks.push.apply(blocks, __spread(parseBodyBlocks([child], parseCtx)));
208
+ }
209
+ }
210
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
211
+ finally {
212
+ try {
213
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
214
+ }
215
+ finally { if (e_3) throw e_3.error; }
216
+ }
217
+ var document = new WordDocument(pkg, {
218
+ attributes: root.attributes,
219
+ namespaceDeclarations: root.namespaceDeclarations.length > 0
220
+ ? root.namespaceDeclarations
221
+ : [{ prefix: 'w', namespaceUri: WML_TRANSITIONAL_NAMESPACE }],
222
+ }, background, [], undefined, featureParts);
223
+ document.hydratePartitionedSections(blocks, sectPr);
224
+ try {
225
+ // Feature post-load hooks (comments main-story elevation TASK-8055 / D14).
226
+ // Duck-typed so `document.ts` does not value-import `features/comments` (that
227
+ // cycle left `Paragraph` undefined when comments attached prototype methods).
228
+ for (var _h = __values(featureParts.values()), _j = _h.next(); !_j.done; _j = _h.next()) {
229
+ var featurePart = _j.value;
230
+ var part_1 = featurePart;
231
+ part_1.afterMainDocumentLoad == null ? undefined : part_1.afterMainDocumentLoad(document);
232
+ }
233
+ }
234
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
235
+ finally {
236
+ try {
237
+ if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
238
+ }
239
+ finally { if (e_4) throw e_4.error; }
240
+ }
241
+ return document;
242
+ };
243
+ /**
244
+ * @private
245
+ * Partition body blocks into logical sections and attach them (TASK-8075).
246
+ * Non-final section properties stay dual-held internally on the closing
247
+ * paragraph and {@link Section.pageSetup} for flatten/serialize; final
248
+ * properties dual-hold body-final model / last pageSetup.
249
+ *
250
+ * Also used after dual-hold authoring (`setParagraphSectionBreak`) so
251
+ * `Document.sections` matches paragraph break topology before save.
252
+ */
253
+ WordDocument.prototype.hydratePartitionedSections = function (blocks, trailingSectPr) {
254
+ var e_5, _a;
255
+ var parts = partitionBodyIntoSections(blocks, trailingSectPr);
256
+ var sections = [];
257
+ for (var i = 0; i < parts.length; i += 1) {
258
+ var part = parts[i];
259
+ var materialized = materializeSectionProperties(part.properties);
260
+ var pageSetup = materialized !== undefined &&
261
+ typeof materialized.toOpenXml === 'function'
262
+ ? materialized
263
+ : undefined;
264
+ var section = new Section(this, part.items, pageSetup);
265
+ sections.push(section);
266
+ notifySectionPropertiesAttached(pageSetup, this);
267
+ // Internal dual-hold: pin the same pageSetup identity on the non-final
268
+ // closing paragraph so flatten/serialize can read break properties.
269
+ if (!part.isFinal && pageSetup !== undefined) {
270
+ var items = part.items;
271
+ var last = items[items.length - 1];
272
+ if (last !== undefined && last.type === 'paragraph') {
273
+ last.paragraph.replaceSectionBreakPropertiesModel(pageSetup);
274
+ }
275
+ }
276
+ }
277
+ this.sectionsInstance.replaceAll(sections);
278
+ this.sectPr = undefined;
279
+ this.finalSectionModel = undefined;
280
+ var lastPart = parts[parts.length - 1];
281
+ var lastSection = sections[sections.length - 1];
282
+ if (lastPart !== undefined && lastSection !== undefined) {
283
+ var finalMaterialized = materializeSectionProperties(lastPart.properties);
284
+ if (finalMaterialized !== undefined &&
285
+ typeof finalMaterialized.toOpenXml === 'function') {
286
+ this.finalSectionModel = finalMaterialized;
287
+ lastSection.setPageSetup(this.finalSectionModel);
288
+ notifySectionPropertiesAttached(this.finalSectionModel, this);
289
+ this.sectPr = undefined;
290
+ }
291
+ else if (trailingSectPr !== undefined) {
292
+ // No sections feature model — keep preserved body-final XML only.
293
+ // trailing may be model | OpenXml; only OpenXml belongs on sectPr.
294
+ if (trailingSectPr.kind === 'element') {
295
+ this.sectPr = trailingSectPr;
296
+ lastSection.setPageSetup(undefined);
297
+ }
298
+ else {
299
+ this.finalSectionModel = trailingSectPr;
300
+ lastSection.setPageSetup(this.finalSectionModel);
301
+ notifySectionPropertiesAttached(this.finalSectionModel, this);
302
+ }
303
+ }
304
+ else {
305
+ // No trailing sectPr and no materialized model: seed default
306
+ // pageSetup when the sections feature is registered.
307
+ lastSection.setPageSetup(undefined);
308
+ }
309
+ }
310
+ for (var i = 0; i < sections.length; i += 1) {
311
+ var section = sections[i];
312
+ var body = section.body;
313
+ try {
314
+ for (var _b = __values(body.listBlocks()), _c = _b.next(); !_c.done; _c = _b.next()) {
315
+ var block = _c.value;
316
+ if (block.type === 'paragraph') {
317
+ block.paragraph.attach(body);
318
+ continue;
319
+ }
320
+ if (block.type === 'feature') {
321
+ bindDocumentToFeatureBlock(block.value, this);
322
+ }
323
+ }
324
+ }
325
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
326
+ finally {
327
+ try {
328
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
329
+ }
330
+ finally { if (e_5) throw e_5.error; }
331
+ }
332
+ bindAltChunkDocument(body.listBlocks(), this);
333
+ section.syncCollections();
334
+ }
335
+ };
336
+ /**
337
+ * @private
338
+ * Rebuild {@link Document.sections} from current body blocks + dual-hold
339
+ * paragraph/body section properties (TASK-8075/8076 authoring path).
340
+ *
341
+ * Call after `setParagraphSectionBreak` so non-final pageSetup lives on its
342
+ * own section and flatten emits paragraph-level + body-final `w:sectPr`.
343
+ */
344
+ WordDocument.prototype.repartitionFromBodyBlocks = function () {
345
+ var trailingModel = this.finalSectionPropertiesModel();
346
+ var trailing = trailingModel !== undefined ? trailingModel : this.sectPr;
347
+ this.hydratePartitionedSections(this.listBlocks().slice(), trailing);
348
+ };
349
+ WordDocument.open = function (dataOrPath, options) {
350
+ // Narrow for TS 3.3 overload resolution (string vs binary packages).
351
+ if (typeof dataOrPath === 'string') {
352
+ if (options !== undefined && options.format === 'base64') {
353
+ var base64Options = {
354
+ format: 'base64',
355
+ limits: options.limits,
356
+ };
357
+ return WordDocument.openSync(dataOrPath, base64Options);
358
+ }
359
+ return WordDocument.openSync(dataOrPath, options);
360
+ }
361
+ return WordDocument.openSync(dataOrPath, options);
362
+ };
363
+ WordDocument.openAsync = function (dataOrPath, options) {
364
+ return openDocumentAsync(dataOrPath, options);
365
+ };
366
+ WordDocument.openSync = function (dataOrPath, options) {
367
+ var bytes = resolveOpenInputToBytes(dataOrPath, options);
368
+ return WordDocument.fromPackage(loadOpcPackage(bytes, options == null ? undefined : options.limits), options == null ? undefined : options.limits);
369
+ };
370
+ WordDocument.load = function (dataOrPath, options) {
371
+ if (typeof dataOrPath === 'string') {
372
+ if (options !== undefined && options.format === 'base64') {
373
+ var base64Options = {
374
+ format: 'base64',
375
+ limits: options.limits,
376
+ };
377
+ return WordDocument.open(dataOrPath, base64Options);
378
+ }
379
+ return WordDocument.open(dataOrPath, options);
380
+ }
381
+ return WordDocument.open(dataOrPath, options);
382
+ };
383
+ WordDocument.loadAsync = function (dataOrPath, options) {
384
+ return openDocumentAsync(dataOrPath, options);
385
+ };
386
+ WordDocument.loadSync = function (dataOrPath, options) {
387
+ if (typeof dataOrPath === 'string') {
388
+ if (options !== undefined && options.format === 'base64') {
389
+ var base64Options = {
390
+ format: 'base64',
391
+ limits: options.limits,
392
+ };
393
+ return WordDocument.openSync(dataOrPath, base64Options);
394
+ }
395
+ return WordDocument.openSync(dataOrPath, options);
396
+ }
397
+ return WordDocument.openSync(dataOrPath, options);
398
+ };
399
+ Object.defineProperty(WordDocument.prototype, "sections", {
400
+ /**
401
+ * Ordered document sections. Sole main-story entry (API-RULES / TASK-8074).
402
+ *
403
+ * @public
404
+ */
405
+ get: function () {
406
+ return this.sectionsInstance;
407
+ },
408
+ enumerable: true,
409
+ configurable: true
410
+ });
411
+ Object.defineProperty(WordDocument.prototype, "lastSection", {
412
+ /**
413
+ * Last section in {@link WordDocument.sections}.
414
+ *
415
+ * Equivalent to `sections[sections.count - 1]`. The document always has at
416
+ * least one section.
417
+ *
418
+ * @public
419
+ */
420
+ get: function () {
421
+ var count = this.sectionsInstance.count;
422
+ var section = this.sectionsInstance[count - 1];
423
+ if (section === undefined) {
424
+ throw new DetachedObjectError('Document must have at least one section');
425
+ }
426
+ return section;
427
+ },
428
+ enumerable: true,
429
+ configurable: true
430
+ });
431
+ Object.defineProperty(WordDocument.prototype, "lastParagraph", {
432
+ /**
433
+ * Last block-level paragraph of {@link WordDocument.lastSection}.
434
+ *
435
+ * Does not walk paragraphs nested in tables or text boxes. Authored
436
+ * documents always have at least one body paragraph per section.
437
+ *
438
+ * @throws DetachedObjectError when the last section has no block-level
439
+ * paragraph (malformed loaded package).
440
+ *
441
+ * @public
442
+ */
443
+ get: function () {
444
+ var paragraphs = this.lastSection.body.listParagraphs();
445
+ var paragraph = paragraphs[paragraphs.length - 1];
446
+ if (paragraph === undefined) {
447
+ throw new DetachedObjectError('Last section has no block-level paragraph (model invariant violated)');
448
+ }
449
+ return paragraph;
450
+ },
451
+ enumerable: true,
452
+ configurable: true
453
+ });
454
+ Object.defineProperty(WordDocument.prototype, "body", {
455
+ /**
456
+ * First section body — convenience bridge matching create-path documents
457
+ * (single section) and public samples that use `doc.body`.
458
+ *
459
+ * Prefer {@link WordDocument.sections} for multi-section documents.
460
+ *
461
+ * @public
462
+ */
463
+ get: function () {
464
+ return this.firstSectionBody();
465
+ },
466
+ enumerable: true,
467
+ configurable: true
468
+ });
469
+ /**
470
+ * Appends a paragraph to {@link WordDocument.body}.
471
+ *
472
+ * Style ids route through {@link Paragraph.applyStyle} so built-in catalog
473
+ * resolution and validation run on assignment.
474
+ *
475
+ * @param options - Optional paragraph style id and/or initial text.
476
+ * @returns The appended {@link Paragraph}.
477
+ *
478
+ * @public
479
+ */
480
+ WordDocument.prototype.appendParagraph = function (options) {
481
+ return this.body.appendParagraph(options);
482
+ };
483
+ /**
484
+ * Appends a new section after the current last section.
485
+ *
486
+ * Thin delegate over {@link Sections.add}. Clones page setup from the
487
+ * previous last section when the sections feature has registered a clone
488
+ * hook; otherwise seeds a default letter page setup when a seed hook is
489
+ * registered.
490
+ *
491
+ * @returns The new {@link Section}.
492
+ *
493
+ * @public
494
+ */
495
+ WordDocument.prototype.addSection = function () {
496
+ return this.sectionsInstance.add();
497
+ };
498
+ /**
499
+ * @private
500
+ */
501
+ WordDocument.prototype.assertAttachedParagraph = function (target) {
502
+ var e_6, _a;
503
+ try {
504
+ for (var _b = __values(this.sectionsInstance.asArray()), _c = _b.next(); !_c.done; _c = _b.next()) {
505
+ var section = _c.value;
506
+ var found = section.body.listBlocks().some(function (b) { return b.type === 'paragraph' && b.paragraph === target; });
507
+ if (found) {
508
+ return;
509
+ }
510
+ }
511
+ }
512
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
513
+ finally {
514
+ try {
515
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
516
+ }
517
+ finally { if (e_6) throw e_6.error; }
518
+ }
519
+ throw new DetachedObjectError('This paragraph is no longer in the document');
520
+ };
521
+ /**
522
+ * @private
523
+ */
524
+ WordDocument.prototype.owningDocument = function () {
525
+ return this;
526
+ };
527
+ Object.defineProperty(WordDocument.prototype, "altChunks", {
528
+ /**
529
+ * Modeled `w:altChunk` anchors in the Main Document body.
530
+ *
531
+ * @private
532
+ */
533
+ get: function () {
534
+ return altChunksInBlocks(this.listBlocks());
535
+ },
536
+ enumerable: true,
537
+ configurable: true
538
+ });
539
+ /**
540
+ * @private
541
+ * First section body (internal feature/load bridges).
542
+ */
543
+ WordDocument.prototype.firstSectionBody = function () {
544
+ var first = this.sectionsInstance[0];
545
+ if (first === undefined) {
546
+ throw new DetachedObjectError('Document must have at least one section');
547
+ }
548
+ return first.body;
549
+ };
550
+ /**
551
+ * @private
552
+ */
553
+ WordDocument.prototype.listParagraphs = function () {
554
+ var e_7, _a;
555
+ var out = [];
556
+ try {
557
+ for (var _b = __values(this.sectionsInstance.asArray()), _c = _b.next(); !_c.done; _c = _b.next()) {
558
+ var section = _c.value;
559
+ var paras = section.body.listParagraphs();
560
+ for (var i = 0; i < paras.length; i += 1) {
561
+ out.push(paras[i]);
562
+ }
563
+ }
564
+ }
565
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
566
+ finally {
567
+ try {
568
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
569
+ }
570
+ finally { if (e_7) throw e_7.error; }
571
+ }
572
+ return out;
573
+ };
574
+ /**
575
+ * @private
576
+ * Flattened internal store across sections.
577
+ */
578
+ WordDocument.prototype.listBlocks = function () {
579
+ var e_8, _a;
580
+ var out = [];
581
+ try {
582
+ for (var _b = __values(this.sectionsInstance.asArray()), _c = _b.next(); !_c.done; _c = _b.next()) {
583
+ var section = _c.value;
584
+ var blocks = section.body.listBlocks();
585
+ for (var i = 0; i < blocks.length; i += 1) {
586
+ out.push(blocks[i]);
587
+ }
588
+ }
589
+ }
590
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
591
+ finally {
592
+ try {
593
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
594
+ }
595
+ finally { if (e_8) throw e_8.error; }
596
+ }
597
+ return out;
598
+ };
599
+ /**
600
+ * @private
601
+ */
602
+ WordDocument.prototype.appendBlock = function (block) {
603
+ this.firstSectionBody().appendRawBlock(block);
604
+ };
605
+ /**
606
+ * Inserts a body item at index (`0…count` inclusive) on the first section body.
607
+ *
608
+ * @private
609
+ */
610
+ WordDocument.prototype.insertBlockAt = function (index, block) {
611
+ this.firstSectionBody().insertRawBlockAt(index, block);
612
+ };
613
+ /**
614
+ * Inserts an empty paragraph at a body item index (`0…count` inclusive).
615
+ *
616
+ * @private
617
+ */
618
+ WordDocument.prototype.insertParagraphAtBlockIndex = function (index) {
619
+ var paragraph = new Paragraph(undefined);
620
+ this.insertBlockAt(index, { type: 'paragraph', paragraph: paragraph });
621
+ return paragraph;
622
+ };
623
+ /**
624
+ * @private
625
+ */
626
+ WordDocument.prototype.insertParagraph = function (index) {
627
+ return this.firstSectionBody().paragraphs.insert(index);
628
+ };
629
+ /**
630
+ * @private
631
+ */
632
+ WordDocument.prototype.removeParagraph = function (paragraph) {
633
+ this.firstSectionBody().paragraphs.remove(paragraph);
634
+ };
635
+ /**
636
+ * Removes the body item at `index` (`0…count-1`) on the first section body.
637
+ *
638
+ * @private
639
+ */
640
+ WordDocument.prototype.removeBlockAt = function (index) {
641
+ this.firstSectionBody().removeRawBlockAt(index);
642
+ };
643
+ /**
644
+ * Advanced L3 hatch: Main Document `w:document` tree (API-RULES R5.4).
645
+ * Unstable; prefer semantic properties and `save` / `saveSync`.
646
+ *
647
+ * Always flattens section bodies into one physical `w:body` (TASK-8075/8076).
648
+ *
649
+ * @private
650
+ */
651
+ WordDocument.prototype.toOpenXml = function () {
652
+ var _this = this;
653
+ var sectionList = this.sectionsInstance.asArray();
654
+ var bodyBlocks = flattenSectionsToBodyBlocks(sectionList.map(function (section, index) { return ({
655
+ listBlocks: function () { return section.body.listBlocks(); },
656
+ pageSetup: section.internalPageSetupModel(),
657
+ pageSetupXml: index === sectionList.length - 1 &&
658
+ section.internalPageSetupModel() === undefined
659
+ ? _this.sectPr
660
+ : undefined,
661
+ replaceItems: function (items) {
662
+ section.body.replaceItems(items);
663
+ // Flatten may append an empty terminator paragraph when a
664
+ // non-final section ends on a table (or other non-p). Attach
665
+ // so subsequent mutation does not throw DetachedObjectError.
666
+ for (var bi = 0; bi < items.length; bi += 1) {
667
+ var block = items[bi];
668
+ if (block.type === 'paragraph') {
669
+ block.paragraph.attach(section.body);
670
+ }
671
+ }
672
+ },
673
+ isLast: index === sectionList.length - 1,
674
+ }); }));
675
+ var bodyChildren = serializeBodyBlocks(bodyBlocks);
676
+ var sectPr = this.bodySectPr();
677
+ if (sectPr !== undefined) {
678
+ bodyChildren.push(sectPr);
679
+ }
680
+ var children = [];
681
+ if (this.background !== undefined) {
682
+ children.push(this.background);
683
+ }
684
+ children.push(wmlElement('body', { children: bodyChildren }));
685
+ return wmlElement('document', {
686
+ attributes: this.rootExtra.attributes,
687
+ namespaceDeclarations: this.rootExtra.namespaceDeclarations,
688
+ children: children,
689
+ });
690
+ };
691
+ /**
692
+ * Preserved `w:document/w:background` subtree from load, if any.
693
+ *
694
+ * @private
695
+ */
696
+ WordDocument.prototype.preservedBackground = function () {
697
+ return this.background;
698
+ };
699
+ /**
700
+ * @private
701
+ * Body-final `w:sectPr`, when present.
702
+ * Serializes a live section-properties model when the sections feature owns it;
703
+ * otherwise returns preserved OOXML from load / XML write-back.
704
+ */
705
+ WordDocument.prototype.bodySectPr = function () {
706
+ if (this.finalSectionModel !== undefined) {
707
+ return this.finalSectionModel.toOpenXml();
708
+ }
709
+ // Prefer pageSetup on the last section when dual-held (TASK-8074 bridge).
710
+ var sections = this.sectionsInstance.asArray();
711
+ var last = sections[sections.length - 1];
712
+ var lastModel = last == null ? undefined : last.internalPageSetupModel();
713
+ if (lastModel !== undefined) {
714
+ return lastModel.toOpenXml();
715
+ }
716
+ return this.sectPr;
717
+ };
718
+ /**
719
+ * @private
720
+ * Replace body-final `w:sectPr` as preserved OOXML.
721
+ * Clears any live section-properties model (XML becomes source of truth again).
722
+ */
723
+ WordDocument.prototype.replaceBodySectPr = function (value) {
724
+ this.finalSectionModel = undefined;
725
+ this.sectPr = value;
726
+ var sections = this.sectionsInstance.asArray();
727
+ var last = sections[sections.length - 1];
728
+ if (last !== undefined) {
729
+ last.setPageSetup(undefined);
730
+ }
731
+ };
732
+ /**
733
+ * @private
734
+ * Live body-final section properties model (sections feature), if any.
735
+ */
736
+ WordDocument.prototype.finalSectionPropertiesModel = function () {
737
+ if (this.finalSectionModel !== undefined) {
738
+ return this.finalSectionModel;
739
+ }
740
+ var sections = this.sectionsInstance.asArray();
741
+ var last = sections[sections.length - 1];
742
+ return last == null ? undefined : last.internalPageSetupModel();
743
+ };
744
+ /**
745
+ * @private
746
+ * Attach or clear the live body-final section properties model.
747
+ * When set, clears preserved `w:sectPr` XML so the model is the sole source of truth.
748
+ * Also seeds {@link Section.pageSetup} on the last section (TASK-8074 dual-hold).
749
+ */
750
+ WordDocument.prototype.replaceFinalSectionPropertiesModel = function (value) {
751
+ this.finalSectionModel = value;
752
+ if (value !== undefined) {
753
+ this.sectPr = undefined;
754
+ }
755
+ var sections = this.sectionsInstance.asArray();
756
+ var last = sections[sections.length - 1];
757
+ if (last !== undefined) {
758
+ last.setPageSetup(value);
759
+ }
760
+ if (value !== undefined) {
761
+ notifySectionPropertiesAttached(value, this);
762
+ }
763
+ };
764
+ /**
765
+ * @private
766
+ */
767
+ WordDocument.prototype.featurePart = function (id) {
768
+ return this.featureParts.get(id);
769
+ };
770
+ /**
771
+ * @private
772
+ */
773
+ WordDocument.prototype.setFeaturePart = function (id, part) {
774
+ this.featureParts.set(id, part);
775
+ };
776
+ /**
777
+ * @private
778
+ */
779
+ WordDocument.prototype.opcPackage = function () {
780
+ return this.pkg;
781
+ };
782
+ WordDocument.prototype.saveSync = function (options) {
783
+ var bytes = this.saveSyncBytes();
784
+ if (options != null && options.format === 'base64') {
785
+ return encodeBytesToBase64(bytes);
786
+ }
787
+ return bytes;
788
+ };
789
+ /**
790
+ * @private
791
+ * Shared package serialization used by `saveSync` overloads and async `save`.
792
+ */
793
+ WordDocument.prototype.saveSyncBytes = function () {
794
+ var e_9, _a;
795
+ materializeFeatureSideEffects(this);
796
+ var name = officeDocumentPartName(this.pkg);
797
+ var next = this.pkg;
798
+ var singleParts = new Map();
799
+ var multiParts = new Map();
800
+ var packageParts = new Map();
801
+ try {
802
+ for (var _b = __values(this.featureParts), _c = _b.next(); !_c.done; _c = _b.next()) {
803
+ var _d = __read(_c.value, 2), id = _d[0], part = _d[1];
804
+ if (isFeatureMultiPackagePart(part)) {
805
+ multiParts.set(id, part);
806
+ }
807
+ else if (isFeaturePackageLevelPart(part)) {
808
+ packageParts.set(id, part);
809
+ }
810
+ else {
811
+ singleParts.set(id, part);
812
+ }
813
+ }
814
+ }
815
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
816
+ finally {
817
+ try {
818
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
819
+ }
820
+ finally { if (e_9) throw e_9.error; }
821
+ }
822
+ // Multi-part handlers (headers/footers) reserve sectPr relationship ids before
823
+ // single-part handlers (styles/numbering) allocate new document relationships.
824
+ next = applyFeatureMultiParts(next, name, multiParts);
825
+ next = applyFeatureParts(next, name, singleParts);
826
+ next = applyFeaturePackageParts(next, packageParts);
827
+ var xml = serializeXml(this.toOpenXml());
828
+ next = withReplacedPart(next, name, utf8.encode(xml));
829
+ // Keep the in-memory package aligned with what was written. Feature multi-part
830
+ // catalogs clear dirty flags after apply; without this, a later saveSync would
831
+ // start from the pre-apply package and drop embeddings/media/rels (TASK-8056).
832
+ this.pkg = next;
833
+ return saveOpcPackage(next);
834
+ };
835
+ WordDocument.prototype.save = function (filePathOrOptions) {
836
+ return __awaiter(this, void 0, void 0, function () {
837
+ var bytes;
838
+ return __generator(this, function (_a) {
839
+ switch (_a.label) {
840
+ case 0:
841
+ bytes = this.saveSyncBytes();
842
+ if (filePathOrOptions === undefined) {
843
+ return [2 /*return*/, bytes];
844
+ }
845
+ if (typeof filePathOrOptions === 'object' && filePathOrOptions.format === 'base64') {
846
+ return [2 /*return*/, encodeBytesToBase64(bytes)];
847
+ }
848
+ return [4 /*yield*/, writeDocumentToPath(filePathOrOptions, bytes)];
849
+ case 1:
850
+ _a.sent();
851
+ return [2 /*return*/];
852
+ }
853
+ });
854
+ });
855
+ };
856
+ return WordDocument;
857
+ }());
858
+ export { WordDocument };
859
+ /**
860
+ * Page `document` used to start a filename download.
861
+ * Does not probe Node.js `fs` — that module must stay out of the browser bundle.
862
+ *
863
+ * @private
864
+ */
865
+ function browserDocument() {
866
+ var globalObject = Function('return this')();
867
+ var host = globalObject.window;
868
+ if (host == null || host.document == null || typeof host.document.createElementNS !== 'function') {
869
+ return undefined;
870
+ }
871
+ return host.document;
872
+ }
873
+ /**
874
+ * Download file name from a path-shaped argument (`./out/Output.docx` → `Output.docx`).
875
+ *
876
+ * @private
877
+ */
878
+ function downloadFileName(filePath) {
879
+ var trimmed = filePath.trim();
880
+ var parts = trimmed.split(/[/\\]/);
881
+ var name = parts[parts.length - 1];
882
+ return name !== undefined && name.length > 0 ? name : trimmed;
883
+ }
884
+ /**
885
+ * Trigger a browser download of the package bytes.
886
+ * Same approach as the PDF library filename save (Blob + anchor click).
887
+ *
888
+ * @private
889
+ */
890
+ function downloadDocumentInBrowser(fileName, bytes, doc) {
891
+ var host = Function('return this')();
892
+ var blob = new host.Blob([bytes], {
893
+ type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
894
+ });
895
+ var nav = host.navigator;
896
+ if (nav != null && typeof nav.msSaveBlob === 'function') {
897
+ nav.msSaveBlob(blob, fileName);
898
+ return;
899
+ }
900
+ var url = host.URL.createObjectURL(blob);
901
+ var link = doc.createElementNS('http://www.w3.org/1999/xhtml', 'a');
902
+ link.download = fileName;
903
+ link.href = url;
904
+ var event = doc.createEvent('MouseEvent');
905
+ event.initEvent('click', true, true);
906
+ link.dispatchEvent(event);
907
+ host.setTimeout(function () {
908
+ host.URL.revokeObjectURL(url);
909
+ }, 0);
910
+ }
911
+ /**
912
+ * @private
913
+ * Browser download of the file name (PDF `save(filename)` pattern).
914
+ * Never calls Node.js `fs` — Vite externalizes that module and throws
915
+ * `Cannot access "fs.writeFile"` when the client bundle evaluates it.
916
+ */
917
+ function writeDocumentToPath(filePath, bytes) {
918
+ if (typeof filePath !== 'string' || filePath.trim().length === 0) {
919
+ throw new InvalidArgumentError('save(fileName) requires a non-empty file name string');
920
+ }
921
+ var browserDoc = browserDocument();
922
+ if (browserDoc === undefined) {
923
+ throw new IoError('save(fileName) downloads in the browser and does not write a filesystem path. Use save() or saveSync() and write the bytes from application code.');
924
+ }
925
+ downloadDocumentInBrowser(downloadFileName(filePath), bytes, browserDoc);
926
+ return Promise.resolve();
927
+ }
928
+ function toUint8Array(data) {
929
+ if (data instanceof Uint8Array) {
930
+ return data;
931
+ }
932
+ return new Uint8Array(data);
933
+ }
934
+ function openDocumentAsync(dataOrPath, options) {
935
+ if (isBlobLike(dataOrPath)) {
936
+ return dataOrPath.arrayBuffer().then(function (buffer) {
937
+ return WordDocument.openSync(buffer, options);
938
+ });
939
+ }
940
+ try {
941
+ if (typeof dataOrPath === 'string') {
942
+ if (options !== undefined && options.format === 'base64') {
943
+ var base64Options = {
944
+ format: 'base64',
945
+ limits: options.limits,
946
+ };
947
+ return Promise.resolve(WordDocument.openSync(dataOrPath, base64Options));
948
+ }
949
+ return Promise.reject(pathOpenRemoved());
950
+ }
951
+ return Promise.resolve(WordDocument.openSync(dataOrPath, options));
952
+ }
953
+ catch (err) {
954
+ return Promise.reject(err);
955
+ }
956
+ }
957
+ function isBlobLike(value) {
958
+ if (typeof value !== 'object' || value === null || !('arrayBuffer' in value)) {
959
+ return false;
960
+ }
961
+ return typeof value.arrayBuffer === 'function';
962
+ }
963
+ function stripBase64DataUrlPrefix(value) {
964
+ var comma = value.indexOf(',');
965
+ if (comma >= 0 && /^data:/i.test(value) && /;base64/i.test(value.slice(0, comma))) {
966
+ return value.slice(comma + 1);
967
+ }
968
+ return value;
969
+ }
970
+ function decodeBase64ToBytes(base64) {
971
+ if (typeof base64 !== 'string' || base64.trim().length === 0) {
972
+ throw new InvalidArgumentError("open(..., { format: 'base64' }) requires a non-empty base64 string");
973
+ }
974
+ var payload = stripBase64DataUrlPrefix(base64).replace(/\s+/g, '');
975
+ try {
976
+ return decodeBase64(payload);
977
+ }
978
+ catch (err) {
979
+ throw new InvalidArgumentError("Invalid base64 payload for open(..., { format: 'base64' })", { cause: err });
980
+ }
981
+ }
982
+ function encodeBytesToBase64(bytes) {
983
+ return encodeBase64(bytes);
984
+ }
985
+ function resolveOpenInputToBytes(dataOrPath, options) {
986
+ if (typeof dataOrPath !== 'string') {
987
+ return toUint8Array(dataOrPath);
988
+ }
989
+ if (options != null && options.format === 'base64') {
990
+ return decodeBase64ToBytes(dataOrPath);
991
+ }
992
+ throw pathOpenRemoved();
993
+ }
994
+ function pathOpenRemoved() {
995
+ return new InvalidArgumentError("open/load does not read a filesystem path. Pass Uint8Array, ArrayBuffer, base64 with { format: 'base64' }, or a File/Blob to openAsync/loadAsync.");
996
+ }
997
+ function bindDocumentToFeatureBlock(value, document) {
998
+ if (typeof value !== 'object' || value === null || !('bindDocument' in value)) {
999
+ return;
1000
+ }
1001
+ var bindDocument = value.bindDocument;
1002
+ bindDocument.call(value, document);
1003
+ }
1004
+ function mergeFeatureParts(single, multi, packageLevel) {
1005
+ var e_10, _a, e_11, _b, e_12, _c;
1006
+ var out = new Map();
1007
+ try {
1008
+ for (var single_1 = __values(single), single_1_1 = single_1.next(); !single_1_1.done; single_1_1 = single_1.next()) {
1009
+ var _d = __read(single_1_1.value, 2), id = _d[0], part = _d[1];
1010
+ out.set(id, part);
1011
+ }
1012
+ }
1013
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
1014
+ finally {
1015
+ try {
1016
+ if (single_1_1 && !single_1_1.done && (_a = single_1.return)) _a.call(single_1);
1017
+ }
1018
+ finally { if (e_10) throw e_10.error; }
1019
+ }
1020
+ try {
1021
+ for (var multi_1 = __values(multi), multi_1_1 = multi_1.next(); !multi_1_1.done; multi_1_1 = multi_1.next()) {
1022
+ var _e = __read(multi_1_1.value, 2), id = _e[0], part = _e[1];
1023
+ out.set(id, part);
1024
+ }
1025
+ }
1026
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
1027
+ finally {
1028
+ try {
1029
+ if (multi_1_1 && !multi_1_1.done && (_b = multi_1.return)) _b.call(multi_1);
1030
+ }
1031
+ finally { if (e_11) throw e_11.error; }
1032
+ }
1033
+ try {
1034
+ for (var packageLevel_1 = __values(packageLevel), packageLevel_1_1 = packageLevel_1.next(); !packageLevel_1_1.done; packageLevel_1_1 = packageLevel_1.next()) {
1035
+ var _f = __read(packageLevel_1_1.value, 2), id = _f[0], part = _f[1];
1036
+ out.set(id, part);
1037
+ }
1038
+ }
1039
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
1040
+ finally {
1041
+ try {
1042
+ if (packageLevel_1_1 && !packageLevel_1_1.done && (_c = packageLevel_1.return)) _c.call(packageLevel_1);
1043
+ }
1044
+ finally { if (e_12) throw e_12.error; }
1045
+ }
1046
+ return out;
1047
+ }
1048
+ // Re-export Body from body.ts so existing `import { Document, Body } from '.../document'` keeps working.
1049
+ export { Body } from './body';