@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,1725 @@
1
+ var __read = (this && this.__read) || function (o, n) {
2
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
3
+ if (!m) return o;
4
+ var i = m.call(o), r, ar = [], e;
5
+ try {
6
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
+ }
8
+ catch (error) { e = { error: error }; }
9
+ finally {
10
+ try {
11
+ if (r && !r.done && (m = i["return"])) m.call(i);
12
+ }
13
+ finally { if (e) throw e.error; }
14
+ }
15
+ return ar;
16
+ };
17
+ var __spread = (this && this.__spread) || function () {
18
+ for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
19
+ return ar;
20
+ };
21
+ var __values = (this && this.__values) || function (o) {
22
+ var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
23
+ if (m) return m.call(o);
24
+ return {
25
+ next: function () {
26
+ if (o && i >= o.length) o = void 0;
27
+ return { value: o && o[i++], done: !o };
28
+ }
29
+ };
30
+ };
31
+ import { DetachedObjectError, DocxError } from '../../core/errors/docx-error';
32
+ import { parseBodyBlocks, serializeBodyBlocks } from '../document/body-blocks';
33
+ import { WordDocument } from '../document/document';
34
+ import { bodyItemToBlock, projectBlockToBodyItem } from '../document/body-item-adapters';
35
+ import { SubSuperScript } from '../document/character-format';
36
+ import { Paragraph } from '../document/paragraph';
37
+ import { FeatureRunParagraphItem, TextRange } from '../document/text-range';
38
+ import { elementChildren, isWml, wmlAttr, wmlElement } from '../document/wml';
39
+ import { allocateRelationshipId } from '../../core/opc/relationships';
40
+ import { partByName, relationshipsForPart } from '../../core/opc/package';
41
+ import { partName, partNameKey, resolveInternalTarget } from '../../core/opc/part-name';
42
+ import { featureId, isFeatureRegistered, registerFeature, registerFeatureMultiPartHandler, registerFeatureRunLeafHandler, replaceOrAddPackagePart, visitParagraphsInDocumentOrder, } from '../../core/registry/index';
43
+ import { parseXml, serializeXml, WML_TRANSITIONAL_NAMESPACE } from '../../core/xml/index';
44
+ import { createTable } from '../tables/index';
45
+ import { createBlockContentControl, } from '../content-controls/index';
46
+ var NOTES = featureId('notes');
47
+ var WML = WML_TRANSITIONAL_NAMESPACE;
48
+ var utf8Decoder = new TextDecoder('utf-8');
49
+ var utf8 = new TextEncoder();
50
+ /**
51
+ * @private
52
+ * Transitional footnotes relationship (ECMA-376-4 §9.2.6). */
53
+ export var FOOTNOTES_RELATIONSHIP_TYPE = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes';
54
+ /**
55
+ * @private
56
+ * Transitional endnotes relationship (ECMA-376-4 §9.2.5). */
57
+ export var ENDNOTES_RELATIONSHIP_TYPE = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes';
58
+ /**
59
+ * @private
60
+ * Strict footnotes relationship. */
61
+ export var STRICT_FOOTNOTES_RELATIONSHIP_TYPE = 'http://purl.oclc.org/ooxml/officeDocument/relationships/footnotes';
62
+ /**
63
+ * @private
64
+ * Strict endnotes relationship. */
65
+ export var STRICT_ENDNOTES_RELATIONSHIP_TYPE = 'http://purl.oclc.org/ooxml/officeDocument/relationships/endnotes';
66
+ /**
67
+ * @private
68
+ */
69
+ export var FOOTNOTES_CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml';
70
+ /**
71
+ * @private
72
+ */
73
+ export var ENDNOTES_CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml';
74
+ var FOOTNOTES_RELATIONSHIP_TYPES = [
75
+ FOOTNOTES_RELATIONSHIP_TYPE,
76
+ STRICT_FOOTNOTES_RELATIONSHIP_TYPE,
77
+ ];
78
+ var ENDNOTES_RELATIONSHIP_TYPES = [
79
+ ENDNOTES_RELATIONSHIP_TYPE,
80
+ STRICT_ENDNOTES_RELATIONSHIP_TYPE,
81
+ ];
82
+ var ALL_RELATIONSHIP_TYPES = __spread(FOOTNOTES_RELATIONSHIP_TYPES, ENDNOTES_RELATIONSHIP_TYPES);
83
+ function wmlAttribute(el, localName) {
84
+ var __ts33_0;
85
+ return ((__ts33_0 = el.attributes.find(function (a) { return a.localName === localName && (a.namespaceUri === '' || a.prefix === 'w'); })), __ts33_0 == null ? undefined : __ts33_0.value);
86
+ }
87
+ function parseNoteId(raw) {
88
+ if (raw === undefined || !/^-?\d+$/.test(raw)) {
89
+ return undefined;
90
+ }
91
+ return Number.parseInt(raw, 10);
92
+ }
93
+ function parseFtnEdnType(raw) {
94
+ if (raw === 'normal' ||
95
+ raw === 'separator' ||
96
+ raw === 'continuationSeparator' ||
97
+ raw === 'continuationNotice') {
98
+ return raw;
99
+ }
100
+ return undefined;
101
+ }
102
+ function isSpecialNoteEntry(noteId, noteType) {
103
+ return (noteId <= 0 ||
104
+ noteType === 'separator' ||
105
+ noteType === 'continuationSeparator' ||
106
+ noteType === 'continuationNotice');
107
+ }
108
+ function rootLocalName(kind) {
109
+ return kind === 'footnote' ? 'footnotes' : 'endnotes';
110
+ }
111
+ function entryLocalName(kind) {
112
+ return kind === 'footnote' ? 'footnote' : 'endnote';
113
+ }
114
+ function contentTypeForKind(kind) {
115
+ return kind === 'footnote' ? FOOTNOTES_CONTENT_TYPE : ENDNOTES_CONTENT_TYPE;
116
+ }
117
+ function relationshipTypeForKind(kind) {
118
+ return kind === 'footnote' ? FOOTNOTES_RELATIONSHIP_TYPE : ENDNOTES_RELATIONSHIP_TYPE;
119
+ }
120
+ function relativeTarget(partNameValue) {
121
+ return partNameValue.slice('/word/'.length);
122
+ }
123
+ function kindForRelationshipType(type) {
124
+ if (FOOTNOTES_RELATIONSHIP_TYPES.indexOf(type) !== -1) {
125
+ return 'footnote';
126
+ }
127
+ if (ENDNOTES_RELATIONSHIP_TYPES.indexOf(type) !== -1) {
128
+ return 'endnote';
129
+ }
130
+ return undefined;
131
+ }
132
+ function firstParagraphText(blocks) {
133
+ var e_1, _a, e_2, _b;
134
+ try {
135
+ for (var blocks_1 = __values(blocks), blocks_1_1 = blocks_1.next(); !blocks_1_1.done; blocks_1_1 = blocks_1.next()) {
136
+ var block = blocks_1_1.value;
137
+ if (block.type !== 'paragraph') {
138
+ continue;
139
+ }
140
+ try {
141
+ for (var _c = __values(block.paragraph.items), _d = _c.next(); !_d.done; _d = _c.next()) {
142
+ var item = _d.value;
143
+ if (item instanceof TextRange) {
144
+ return item.text;
145
+ }
146
+ }
147
+ }
148
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
149
+ finally {
150
+ try {
151
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
152
+ }
153
+ finally { if (e_2) throw e_2.error; }
154
+ }
155
+ }
156
+ }
157
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
158
+ finally {
159
+ try {
160
+ if (blocks_1_1 && !blocks_1_1.done && (_a = blocks_1.return)) _a.call(blocks_1);
161
+ }
162
+ finally { if (e_1) throw e_1.error; }
163
+ }
164
+ return undefined;
165
+ }
166
+ var detachedParagraphOwner = {
167
+ assertAttachedParagraph: function () {
168
+ return;
169
+ },
170
+ owningDocument: function () {
171
+ throw new DetachedObjectError('Note content is not in a WordDocument');
172
+ },
173
+ };
174
+ /**
175
+ * Paragraph owner scoped to one footnote or endnote catalog entry.
176
+ * Membership is checked against the live entry blocks.
177
+ */
178
+ var NotePartOwner = /** @class */ (function () {
179
+ function NotePartOwner(WordDocument, kind, noteId) {
180
+ this.WordDocument = WordDocument;
181
+ this.kind = kind;
182
+ this.noteId = noteId;
183
+ }
184
+ NotePartOwner.prototype.assertAttachedParagraph = function (target) {
185
+ var catalog = notesFor(this.WordDocument);
186
+ var entry = catalog.normalEntry(this.kind, this.noteId);
187
+ if (entry === undefined) {
188
+ throw new DetachedObjectError('Note part is no longer loaded');
189
+ }
190
+ var found = entry.blocks.some(function (block) { return block.type === 'paragraph' && block.paragraph === target; });
191
+ if (!found) {
192
+ throw new DetachedObjectError('This paragraph is no longer in its note');
193
+ }
194
+ };
195
+ /**
196
+ * @private
197
+ */
198
+ NotePartOwner.prototype.owningDocument = function () {
199
+ return this.WordDocument;
200
+ };
201
+ return NotePartOwner;
202
+ }());
203
+ function ownerForNote(WordDocument, kind, noteId) {
204
+ return new NotePartOwner(WordDocument, kind, noteId);
205
+ }
206
+ /**
207
+ * Bind a feature body block (table, content control, …) to the owning WordDocument when
208
+ * the value exposes `bindDocument`. Mirrors Body without exporting that helper
209
+ * from WordDocument.ts.
210
+ */
211
+ function bindDocumentToFeatureBlock(value, WordDocument) {
212
+ if (typeof value !== 'object' || value === null || !('bindDocument' in value)) {
213
+ return;
214
+ }
215
+ var bindDocument = value.bindDocument;
216
+ bindDocument.call(value, WordDocument);
217
+ }
218
+ function releaseFeatureBlockContent(value) {
219
+ if (typeof value !== 'object' || value === null || !('releaseContent' in value)) {
220
+ return;
221
+ }
222
+ var releaseContent = value.releaseContent;
223
+ // TS 3.3: Function.call typing treats free functions as `this: void`.
224
+ if (typeof releaseContent === 'function') {
225
+ releaseContent.call(value);
226
+ }
227
+ }
228
+ function attachNoteParagraphs(WordDocument, kind, entry) {
229
+ var e_3, _a;
230
+ var owner = ownerForNote(WordDocument, kind, entry.noteId);
231
+ try {
232
+ for (var _b = __values(entry.blocks), _c = _b.next(); !_c.done; _c = _b.next()) {
233
+ var block = _c.value;
234
+ if (block.type === 'paragraph') {
235
+ block.paragraph.attach(owner);
236
+ }
237
+ else if (block.type === 'feature') {
238
+ bindDocumentToFeatureBlock(block.value, WordDocument);
239
+ }
240
+ }
241
+ }
242
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
243
+ finally {
244
+ try {
245
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
246
+ }
247
+ finally { if (e_3) throw e_3.error; }
248
+ }
249
+ }
250
+ function detachNoteBlocks(blocks) {
251
+ var e_4, _a;
252
+ try {
253
+ for (var blocks_2 = __values(blocks), blocks_2_1 = blocks_2.next(); !blocks_2_1.done; blocks_2_1 = blocks_2.next()) {
254
+ var block = blocks_2_1.value;
255
+ if (block.type === 'paragraph') {
256
+ block.paragraph.detach();
257
+ }
258
+ else if (block.type === 'feature') {
259
+ releaseFeatureBlockContent(block.value);
260
+ }
261
+ }
262
+ }
263
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
264
+ finally {
265
+ try {
266
+ if (blocks_2_1 && !blocks_2_1.done && (_a = blocks_2.return)) _a.call(blocks_2);
267
+ }
268
+ finally { if (e_4) throw e_4.error; }
269
+ }
270
+ }
271
+ function blocksWithSimpleText(text, owner) {
272
+ if (owner === void 0) { owner = detachedParagraphOwner; }
273
+ return parseBodyBlocks([
274
+ wmlElement('p', {
275
+ children: [
276
+ wmlElement('r', {
277
+ children: [wmlElement('t', { children: [{ kind: 'text', value: text }] })],
278
+ }),
279
+ ],
280
+ }),
281
+ ], owner);
282
+ }
283
+ function defaultSeparatorEntries(kind) {
284
+ var childName = entryLocalName(kind);
285
+ var separatorLeaf = kind === 'footnote' ? 'separator' : 'separator';
286
+ var continuationLeaf = kind === 'footnote' ? 'continuationSeparator' : 'continuationSeparator';
287
+ return [
288
+ {
289
+ noteId: -1,
290
+ noteType: 'separator',
291
+ blocks: [],
292
+ preservedXml: wmlElement(childName, {
293
+ attributes: [wmlAttr('type', 'separator'), wmlAttr('id', '-1')],
294
+ children: [
295
+ wmlElement('p', {
296
+ children: [wmlElement('r', { children: [wmlElement(separatorLeaf)] })],
297
+ }),
298
+ ],
299
+ }),
300
+ },
301
+ {
302
+ noteId: 0,
303
+ noteType: 'continuationSeparator',
304
+ blocks: [],
305
+ preservedXml: wmlElement(childName, {
306
+ attributes: [wmlAttr('type', 'continuationSeparator'), wmlAttr('id', '0')],
307
+ children: [
308
+ wmlElement('p', {
309
+ children: [wmlElement('r', { children: [wmlElement(continuationLeaf)] })],
310
+ }),
311
+ ],
312
+ }),
313
+ },
314
+ ];
315
+ }
316
+ /**
317
+ * Footnote reference run leaf (`w:footnoteReference`).
318
+ *
319
+ * @private
320
+ */
321
+ var FootnoteReference = /** @class */ (function () {
322
+ /**
323
+ * @private
324
+ */
325
+ function FootnoteReference(noteId) {
326
+ this.noteId = noteId;
327
+ }
328
+ /**
329
+ * @private
330
+ */
331
+ FootnoteReference.prototype.toOpenXml = function () {
332
+ return wmlElement('footnoteReference', { attributes: [wmlAttr('id', String(this.noteId))] });
333
+ };
334
+ return FootnoteReference;
335
+ }());
336
+ export { FootnoteReference };
337
+ /**
338
+ * Endnote reference run leaf (`w:endnoteReference`).
339
+ *
340
+ * @private
341
+ */
342
+ var EndnoteReference = /** @class */ (function () {
343
+ /**
344
+ * @private
345
+ */
346
+ function EndnoteReference(noteId) {
347
+ this.noteId = noteId;
348
+ }
349
+ /**
350
+ * @private
351
+ */
352
+ EndnoteReference.prototype.toOpenXml = function () {
353
+ return wmlElement('endnoteReference', { attributes: [wmlAttr('id', String(this.noteId))] });
354
+ };
355
+ return EndnoteReference;
356
+ }());
357
+ export { EndnoteReference };
358
+ function serializeNotePart(state) {
359
+ var e_5, _a;
360
+ var childName = entryLocalName(state.kind);
361
+ var children = [];
362
+ try {
363
+ for (var _b = __values(state.entries), _c = _b.next(); !_c.done; _c = _b.next()) {
364
+ var entry = _c.value;
365
+ if (entry.preservedXml !== undefined) {
366
+ children.push(entry.preservedXml);
367
+ continue;
368
+ }
369
+ var attributes = [wmlAttr('id', String(entry.noteId))];
370
+ if (entry.noteType !== undefined && entry.noteType !== 'normal') {
371
+ attributes.push(wmlAttr('type', entry.noteType));
372
+ }
373
+ children.push(wmlElement(childName, {
374
+ attributes: attributes,
375
+ children: serializeBodyBlocks(entry.blocks),
376
+ }));
377
+ }
378
+ }
379
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
380
+ finally {
381
+ try {
382
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
383
+ }
384
+ finally { if (e_5) throw e_5.error; }
385
+ }
386
+ var root = wmlElement(rootLocalName(state.kind), {
387
+ attributes: state.rootExtra.attributes,
388
+ namespaceDeclarations: state.rootExtra.namespaceDeclarations.length > 0
389
+ ? state.rootExtra.namespaceDeclarations
390
+ : [{ prefix: 'w', namespaceUri: WML }],
391
+ children: children,
392
+ });
393
+ return utf8.encode(serializeXml(root));
394
+ }
395
+ function parseNotePart(part, relationship, kind) {
396
+ var e_6, _a;
397
+ var root = parseXml(utf8Decoder.decode(part.data));
398
+ if (!isWml(root, rootLocalName(kind))) {
399
+ return undefined;
400
+ }
401
+ var entries = [];
402
+ var childName = entryLocalName(kind);
403
+ try {
404
+ for (var _b = __values(elementChildren(root)), _c = _b.next(); !_c.done; _c = _b.next()) {
405
+ var child = _c.value;
406
+ if (!isWml(child, childName)) {
407
+ continue;
408
+ }
409
+ var noteId = parseNoteId(wmlAttribute(child, 'id'));
410
+ if (noteId === undefined) {
411
+ continue;
412
+ }
413
+ var noteType = parseFtnEdnType(wmlAttribute(child, 'type'));
414
+ if (isSpecialNoteEntry(noteId, noteType)) {
415
+ entries.push({ noteId: noteId, noteType: noteType, blocks: [], preservedXml: child });
416
+ continue;
417
+ }
418
+ entries.push({
419
+ noteId: noteId,
420
+ noteType: noteType != null ? noteType : 'normal',
421
+ blocks: parseBodyBlocks(child.children, detachedParagraphOwner),
422
+ preservedXml: undefined,
423
+ });
424
+ }
425
+ }
426
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
427
+ finally {
428
+ try {
429
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
430
+ }
431
+ finally { if (e_6) throw e_6.error; }
432
+ }
433
+ return {
434
+ partName: part.name,
435
+ relationshipId: relationship.id,
436
+ relationshipType: relationship.type,
437
+ kind: kind,
438
+ rootExtra: {
439
+ attributes: root.attributes,
440
+ namespaceDeclarations: root.namespaceDeclarations.length > 0
441
+ ? root.namespaceDeclarations
442
+ : [{ prefix: 'w', namespaceUri: WML }],
443
+ },
444
+ entries: entries,
445
+ dirty: false,
446
+ pendingRelationship: undefined,
447
+ };
448
+ }
449
+ function allocatePartName(kind, used) {
450
+ var base = kind === 'footnote' ? 'footnotes.xml' : 'endnotes.xml';
451
+ var primary = partName("/word/" + base);
452
+ if (!used.has(partNameKey(primary))) {
453
+ return primary;
454
+ }
455
+ var index = 2;
456
+ while (used.has(partNameKey(partName("/word/" + kind + String(index) + ".xml")))) {
457
+ index += 1;
458
+ }
459
+ return partName("/word/" + kind + String(index) + ".xml");
460
+ }
461
+ function allocateNoteId(entries) {
462
+ var e_7, _a;
463
+ var max = 0;
464
+ try {
465
+ for (var entries_1 = __values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
466
+ var entry = entries_1_1.value;
467
+ if (entry.noteId > max && !isSpecialNoteEntry(entry.noteId, entry.noteType)) {
468
+ max = entry.noteId;
469
+ }
470
+ }
471
+ }
472
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
473
+ finally {
474
+ try {
475
+ if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) _a.call(entries_1);
476
+ }
477
+ finally { if (e_7) throw e_7.error; }
478
+ }
479
+ return max + 1;
480
+ }
481
+ /**
482
+ * Footnotes and endnotes parts linked from the Main WordDocument.
483
+ *
484
+ * @private
485
+ */
486
+ var NotesCatalog = /** @class */ (function () {
487
+ /**
488
+ * @private
489
+ */
490
+ function NotesCatalog(parts) {
491
+ this.parts = parts;
492
+ this.boundDocument = undefined;
493
+ }
494
+ /**
495
+ * Bind this catalog to a live WordDocument so paragraph owners can resolve.
496
+ * Re-attaches existing modeled note body blocks to entry-scoped owners.
497
+ *
498
+ * @private
499
+ */
500
+ NotesCatalog.prototype.bindDocument = function (WordDocument) {
501
+ var e_8, _a, e_9, _b;
502
+ this.boundDocument = WordDocument;
503
+ try {
504
+ for (var _c = __values(this.parts.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
505
+ var part = _d.value;
506
+ try {
507
+ for (var _e = __values(part.entries), _f = _e.next(); !_f.done; _f = _e.next()) {
508
+ var entry = _f.value;
509
+ if (entry.preservedXml !== undefined) {
510
+ continue;
511
+ }
512
+ if (isSpecialNoteEntry(entry.noteId, entry.noteType)) {
513
+ continue;
514
+ }
515
+ attachNoteParagraphs(WordDocument, part.kind, entry);
516
+ }
517
+ }
518
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
519
+ finally {
520
+ try {
521
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
522
+ }
523
+ finally { if (e_9) throw e_9.error; }
524
+ }
525
+ }
526
+ }
527
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
528
+ finally {
529
+ try {
530
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
531
+ }
532
+ finally { if (e_8) throw e_8.error; }
533
+ }
534
+ };
535
+ NotesCatalog.prototype.requireBoundDocument = function () {
536
+ if (this.boundDocument === undefined) {
537
+ throw new DocxError('content/unknown-note', 'Notes catalog is not bound to a WordDocument');
538
+ }
539
+ return this.boundDocument;
540
+ };
541
+ NotesCatalog.prototype.markPartDirty = function (kind) {
542
+ var part = this.parts.get(kind);
543
+ if (part === undefined) {
544
+ throw new DocxError('content/unknown-note', 'Notes part is not loaded');
545
+ }
546
+ part.dirty = true;
547
+ };
548
+ /**
549
+ * @private
550
+ */
551
+ NotesCatalog.prototype.isDirty = function () {
552
+ var e_10, _a;
553
+ try {
554
+ for (var _b = __values(this.parts.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
555
+ var part = _c.value;
556
+ if (part.dirty || part.pendingRelationship !== undefined) {
557
+ return true;
558
+ }
559
+ }
560
+ }
561
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
562
+ finally {
563
+ try {
564
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
565
+ }
566
+ finally { if (e_10) throw e_10.error; }
567
+ }
568
+ return false;
569
+ };
570
+ /**
571
+ * @private
572
+ */
573
+ NotesCatalog.prototype.applyToPackage = function (pkg, mainPartName) {
574
+ var e_11, _a;
575
+ var next = pkg;
576
+ var _loop_1 = function (part) {
577
+ if (!part.dirty && part.pendingRelationship === undefined) {
578
+ return "continue";
579
+ }
580
+ var data = serializeNotePart(part);
581
+ var rel = part.pendingRelationship != null ? part.pendingRelationship : relationshipsForPart(next, mainPartName).items.find(function (item) { return item.id === part.relationshipId; });
582
+ next = replaceOrAddPackagePart(next, mainPartName, part.partName, contentTypeForKind(part.kind), data, rel);
583
+ part.dirty = false;
584
+ part.pendingRelationship = undefined;
585
+ };
586
+ try {
587
+ for (var _b = __values(this.parts.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
588
+ var part = _c.value;
589
+ _loop_1(part);
590
+ }
591
+ }
592
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
593
+ finally {
594
+ try {
595
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
596
+ }
597
+ finally { if (e_11) throw e_11.error; }
598
+ }
599
+ return next;
600
+ };
601
+ /**
602
+ * @private
603
+ */
604
+ NotesCatalog.prototype.ensurePart = function (kind, usedRelIds, usedPartNames) {
605
+ var existing = this.parts.get(kind);
606
+ if (existing !== undefined) {
607
+ return existing;
608
+ }
609
+ var partNameValue = allocatePartName(kind, usedPartNames);
610
+ var relId = allocateRelationshipId(usedRelIds);
611
+ while (__spread(this.parts.values()).some(function (part) { return part.relationshipId === relId; })) {
612
+ relId = allocateRelationshipId(new Set(__spread(usedRelIds, [relId])));
613
+ }
614
+ var created = {
615
+ partName: partNameValue,
616
+ relationshipId: relId,
617
+ relationshipType: relationshipTypeForKind(kind),
618
+ kind: kind,
619
+ rootExtra: {
620
+ attributes: [],
621
+ namespaceDeclarations: [{ prefix: 'w', namespaceUri: WML }],
622
+ },
623
+ entries: defaultSeparatorEntries(kind),
624
+ dirty: true,
625
+ pendingRelationship: {
626
+ id: relId,
627
+ type: relationshipTypeForKind(kind),
628
+ target: relativeTarget(partNameValue),
629
+ extraAttributes: [],
630
+ children: [],
631
+ },
632
+ };
633
+ this.parts.set(kind, created);
634
+ return created;
635
+ };
636
+ /**
637
+ * @private
638
+ */
639
+ NotesCatalog.prototype.addNormalEntry = function (kind, text) {
640
+ var part = this.parts.get(kind);
641
+ if (part === undefined) {
642
+ throw new DocxError('content/unknown-note', 'Notes part is not loaded');
643
+ }
644
+ var noteId = allocateNoteId(part.entries);
645
+ var blocks = this.boundDocument !== undefined
646
+ ? blocksWithSimpleText(text, ownerForNote(this.boundDocument, kind, noteId))
647
+ : blocksWithSimpleText(text);
648
+ part.entries = __spread(part.entries, [
649
+ { noteId: noteId, noteType: 'normal', blocks: blocks, preservedXml: undefined },
650
+ ]);
651
+ part.dirty = true;
652
+ return noteId;
653
+ };
654
+ /**
655
+ * @private
656
+ */
657
+ NotesCatalog.prototype.normalEntry = function (kind, noteId) {
658
+ var part = this.parts.get(kind);
659
+ if (part === undefined) {
660
+ return undefined;
661
+ }
662
+ var entry = part.entries.find(function (candidate) { return candidate.noteId === noteId; });
663
+ if (entry === undefined || entry.preservedXml !== undefined) {
664
+ return undefined;
665
+ }
666
+ if (isSpecialNoteEntry(entry.noteId, entry.noteType)) {
667
+ return undefined;
668
+ }
669
+ return entry;
670
+ };
671
+ NotesCatalog.prototype.requireNormalEntry = function (kind, noteId) {
672
+ var entry = this.normalEntry(kind, noteId);
673
+ if (entry === undefined) {
674
+ throw new DocxError('content/unknown-note', "Note id " + String(noteId) + " is not a modeled normal note");
675
+ }
676
+ return entry;
677
+ };
678
+ /**
679
+ * @private
680
+ */
681
+ NotesCatalog.prototype.textForNote = function (kind, noteId) {
682
+ var entry = this.normalEntry(kind, noteId);
683
+ if (entry === undefined) {
684
+ return undefined;
685
+ }
686
+ return firstParagraphText(entry.blocks);
687
+ };
688
+ /**
689
+ * Ordered body children ({@link BodyItem}) for a normal note — paragraphs, tables,
690
+ * block content controls, and residuals, in WordDocument order (same model as Body.items).
691
+ *
692
+ * @private
693
+ */
694
+ NotesCatalog.prototype.itemsForNote = function (kind, noteId) {
695
+ return this.blocksForNote(kind, noteId);
696
+ };
697
+ /**
698
+ * Body blocks of a normal note, when modeled (paragraphs, tables, content controls, residuals).
699
+ *
700
+ * @private
701
+ * Prefer {@link NotesCatalog.itemsForNote}.
702
+ */
703
+ NotesCatalog.prototype.blocksForNote = function (kind, noteId) {
704
+ var entry = this.normalEntry(kind, noteId);
705
+ if (entry === undefined) {
706
+ return [];
707
+ }
708
+ if (this.boundDocument !== undefined) {
709
+ attachNoteParagraphs(this.boundDocument, kind, entry);
710
+ }
711
+ var items = [];
712
+ for (var i = 0; i < entry.blocks.length; i += 1) {
713
+ var projected = projectBlockToBodyItem(entry.blocks[i]);
714
+ if (projected !== undefined) {
715
+ items.push(projected);
716
+ }
717
+ }
718
+ return items;
719
+ };
720
+ /**
721
+ * Body paragraphs of a normal note, when modeled.
722
+ *
723
+ * @private
724
+ * Prefer {@link NotesCatalog.itemsForNote} for mixed body content.
725
+ */
726
+ NotesCatalog.prototype.paragraphsForNote = function (kind, noteId) {
727
+ var e_12, _a;
728
+ var entry = this.normalEntry(kind, noteId);
729
+ if (entry === undefined) {
730
+ return [];
731
+ }
732
+ if (this.boundDocument !== undefined) {
733
+ attachNoteParagraphs(this.boundDocument, kind, entry);
734
+ }
735
+ var paragraphs = [];
736
+ try {
737
+ for (var _b = __values(entry.blocks), _c = _b.next(); !_c.done; _c = _b.next()) {
738
+ var block = _c.value;
739
+ if (block.type === 'paragraph') {
740
+ paragraphs.push(block.paragraph);
741
+ }
742
+ }
743
+ }
744
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
745
+ finally {
746
+ try {
747
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
748
+ }
749
+ finally { if (e_12) throw e_12.error; }
750
+ }
751
+ return paragraphs;
752
+ };
753
+ /**
754
+ * Replace the body of a normal note with a single paragraph of plain text.
755
+ *
756
+ * @private
757
+ */
758
+ NotesCatalog.prototype.setTextForNote = function (kind, noteId, text) {
759
+ var part = this.parts.get(kind);
760
+ if (part === undefined) {
761
+ throw new DocxError('content/unknown-note', 'Notes part is not loaded');
762
+ }
763
+ var entry = part.entries.find(function (candidate) { return candidate.noteId === noteId; });
764
+ if (entry === undefined || entry.preservedXml !== undefined) {
765
+ throw new DocxError('content/unknown-note', "Note id " + String(noteId) + " is not a modeled normal note");
766
+ }
767
+ if (isSpecialNoteEntry(entry.noteId, entry.noteType)) {
768
+ throw new DocxError('content/unknown-note', "Note id " + String(noteId) + " is a separator or special note and cannot be edited");
769
+ }
770
+ detachNoteBlocks(entry.blocks);
771
+ if (this.boundDocument !== undefined) {
772
+ entry.blocks = blocksWithSimpleText(text, ownerForNote(this.boundDocument, kind, noteId));
773
+ }
774
+ else {
775
+ entry.blocks = blocksWithSimpleText(text);
776
+ }
777
+ part.dirty = true;
778
+ };
779
+ /**
780
+ * Insert a body item at `index` in a normal note (`0…length` inclusive).
781
+ *
782
+ * Attaches paragraphs and feature blocks when the catalog is WordDocument-bound.
783
+ * Returns the same `item` reference for chaining.
784
+ *
785
+ * @throws RangeError if `index` is out of range.
786
+ * @throws DocxError when the note is unknown or the catalog is unbound.
787
+ *
788
+ * @private
789
+ */
790
+ NotesCatalog.prototype.insertBodyItemAtForNote = function (kind, noteId, index, item) {
791
+ var document = this.requireBoundDocument();
792
+ var entry = this.requireNormalEntry(kind, noteId);
793
+ if (index < 0 || index > entry.blocks.length) {
794
+ throw new RangeError("Body item index " + String(index) + " is out of range");
795
+ }
796
+ var block = bodyItemToBlock(item);
797
+ if (block.type === 'paragraph') {
798
+ block.paragraph.attach(ownerForNote(document, kind, noteId));
799
+ }
800
+ else if (block.type === 'feature') {
801
+ bindDocumentToFeatureBlock(block.value, document);
802
+ }
803
+ var next = entry.blocks.slice();
804
+ next.splice(index, 0, block);
805
+ entry.blocks = next;
806
+ this.markPartDirty(kind);
807
+ return item;
808
+ };
809
+ /**
810
+ * Remove the body item at `index` in a normal note (`0…length-1`).
811
+ * Paragraphs detach; feature blocks may release content.
812
+ *
813
+ * @throws RangeError if `index` is out of range.
814
+ * @throws DocxError when the note is unknown.
815
+ *
816
+ * @private
817
+ */
818
+ NotesCatalog.prototype.removeBodyItemAtForNote = function (kind, noteId, index) {
819
+ var entry = this.requireNormalEntry(kind, noteId);
820
+ if (index < 0 || index >= entry.blocks.length) {
821
+ throw new RangeError("Body item index " + String(index) + " is out of range");
822
+ }
823
+ var block = entry.blocks[index];
824
+ if (block === undefined) {
825
+ throw new RangeError("Body item index " + String(index) + " is out of range");
826
+ }
827
+ var next = __spread(entry.blocks);
828
+ next.splice(index, 1);
829
+ entry.blocks = next;
830
+ if (block.type === 'paragraph') {
831
+ block.paragraph.detach();
832
+ }
833
+ else if (block.type === 'feature') {
834
+ releaseFeatureBlockContent(block.value);
835
+ }
836
+ this.markPartDirty(kind);
837
+ };
838
+ /**
839
+ * Remove a body item from a normal note by collection or payload identity.
840
+ *
841
+ * @throws DetachedObjectError when the item is not in the note.
842
+ * @throws DocxError when the note is unknown.
843
+ *
844
+ * @private
845
+ */
846
+ NotesCatalog.prototype.removeBodyItemForNote = function (kind, noteId, item) {
847
+ var entry = this.requireNormalEntry(kind, noteId);
848
+ var at = -1;
849
+ for (var i = 0; i < entry.blocks.length; i += 1) {
850
+ if (projectBlockToBodyItem(entry.blocks[i]) === item) {
851
+ at = i;
852
+ break;
853
+ }
854
+ }
855
+ if (at === -1) {
856
+ throw new DetachedObjectError('Body item is not in this note');
857
+ }
858
+ this.removeBodyItemAtForNote(kind, noteId, at);
859
+ };
860
+ /**
861
+ * Append a paragraph to a normal note body.
862
+ *
863
+ * @throws DocxError when the note is unknown or the catalog is unbound.
864
+ *
865
+ * @private
866
+ */
867
+ NotesCatalog.prototype.appendParagraphToNote = function (kind, noteId, options) {
868
+ var WordDocument = this.requireBoundDocument();
869
+ var entry = this.requireNormalEntry(kind, noteId);
870
+ var owner = ownerForNote(WordDocument, kind, noteId);
871
+ var paragraph = new Paragraph(owner);
872
+ this.insertBodyItemAtForNote(kind, noteId, entry.blocks.length, paragraph);
873
+ if ((options == null ? undefined : options.style) !== undefined) {
874
+ // Route through the styles facade so built-in ids/names resolve.
875
+ paragraph.applyStyle(options.style);
876
+ }
877
+ if ((options == null ? undefined : options.text) !== undefined) {
878
+ paragraph.appendText(options.text);
879
+ }
880
+ return paragraph;
881
+ };
882
+ /**
883
+ * Append a table to a normal note body.
884
+ *
885
+ * @throws DocxError when the note is unknown or the catalog is unbound.
886
+ * @throws RangeError when dimensions are less than 1.
887
+ *
888
+ * @private
889
+ */
890
+ NotesCatalog.prototype.appendTableToNote = function (kind, noteId, rowCount, columnCount) {
891
+ this.requireBoundDocument();
892
+ var entry = this.requireNormalEntry(kind, noteId);
893
+ var table = createTable(rowCount, columnCount);
894
+ this.insertBodyItemAtForNote(kind, noteId, entry.blocks.length, table);
895
+ return table;
896
+ };
897
+ /**
898
+ * Append a block-level content control to a normal note body.
899
+ *
900
+ * @throws DocxError when the note is unknown or the catalog is unbound.
901
+ *
902
+ * @private
903
+ */
904
+ NotesCatalog.prototype.appendBlockContentControlToNote = function (kind, noteId, type) {
905
+ this.requireBoundDocument();
906
+ var entry = this.requireNormalEntry(kind, noteId);
907
+ var sdt = createBlockContentControl(type);
908
+ // ContentControl is the runtime block SDT; BodyItem is a structural union in core.
909
+ this.insertBodyItemAtForNote(kind, noteId, entry.blocks.length, sdt);
910
+ return sdt;
911
+ };
912
+ /**
913
+ * @private
914
+ */
915
+ NotesCatalog.prototype.removeNormalEntry = function (kind, noteId) {
916
+ var part = this.parts.get(kind);
917
+ if (part === undefined) {
918
+ throw new DocxError('content/unknown-note', 'Notes part is not loaded');
919
+ }
920
+ var next = part.entries.filter(function (entry) { return entry.noteId !== noteId; });
921
+ if (next.length === part.entries.length) {
922
+ throw new DocxError('content/unknown-note', "Note id " + String(noteId) + " is not in this WordDocument");
923
+ }
924
+ part.entries = next;
925
+ part.dirty = true;
926
+ };
927
+ return NotesCatalog;
928
+ }());
929
+ export { NotesCatalog };
930
+ /**
931
+ * Live view of a footnote body in the footnotes part.
932
+ *
933
+ * Bound to a WordDocument and note id; reads and writes go through
934
+ * {@link NotesCatalog}. Body content is the same R5.6
935
+ * {@link BodyItem} list as {@link Body} (`items` +
936
+ * insert/remove). Does not expose raw OOXML.
937
+ *
938
+ * @public
939
+ */
940
+ var Footnote = /** @class */ (function () {
941
+ /**
942
+ * @private
943
+ */
944
+ function Footnote(WordDocument, noteId) {
945
+ this.WordDocument = WordDocument;
946
+ this.id = noteId;
947
+ }
948
+ Object.defineProperty(Footnote.prototype, "noteId", {
949
+ /**
950
+ * @private
951
+ * Stable id matching the footnote reference and footnotes part entry. */
952
+ get: function () {
953
+ return this.id;
954
+ },
955
+ enumerable: true,
956
+ configurable: true
957
+ });
958
+ Object.defineProperty(Footnote.prototype, "items", {
959
+ /**
960
+ * Ordered body children ({@link BodyItem}) for this footnote —
961
+ * paragraphs, tables, block content controls, and residuals, in
962
+ * WordDocument order (same model as {@link Body.items}).
963
+ *
964
+ * @public
965
+ */
966
+ get: function () {
967
+ return notesFor(this.WordDocument).itemsForNote('footnote', this.id);
968
+ },
969
+ enumerable: true,
970
+ configurable: true
971
+ });
972
+ /**
973
+ * Insert a body item at `index` in {@link Footnote.items}
974
+ * (`0…length` inclusive — insert-before / append).
975
+ *
976
+ * Attaches paragraphs and feature blocks to the owning WordDocument. Returns the
977
+ * same `item` reference for chaining (API-RULES R1.1).
978
+ *
979
+ * @param index - Index in {@link Footnote.items}.
980
+ * @param item - Paragraph, feature, or opaque body child.
981
+ * @returns The inserted {@link BodyItem}.
982
+ * @throws RangeError if `index` is out of range.
983
+ *
984
+ * @public
985
+ */
986
+ Footnote.prototype.insertBodyItemAt = function (index, item) {
987
+ return notesFor(this.WordDocument).insertBodyItemAtForNote('footnote', this.id, index, item);
988
+ };
989
+ /**
990
+ * Remove the body item at `index` in {@link Footnote.items}
991
+ * (`0…length-1`). Paragraphs detach; feature blocks may release content.
992
+ *
993
+ * @param index - Index in {@link Footnote.items}.
994
+ * @throws RangeError if `index` is out of range.
995
+ *
996
+ * @public
997
+ */
998
+ Footnote.prototype.removeBodyItemAt = function (index) {
999
+ notesFor(this.WordDocument).removeBodyItemAtForNote('footnote', this.id, index);
1000
+ };
1001
+ /**
1002
+ * Remove a body item from {@link Footnote.items} by collection or payload identity.
1003
+ *
1004
+ * @param item - Entry from `items`, or an equivalent payload wrapper.
1005
+ * @throws DetachedObjectError if `item` is not in this footnote.
1006
+ *
1007
+ * @public
1008
+ */
1009
+ Footnote.prototype.removeBodyItem = function (item) {
1010
+ notesFor(this.WordDocument).removeBodyItemForNote('footnote', this.id, item);
1011
+ };
1012
+ return Footnote;
1013
+ }());
1014
+ export { Footnote };
1015
+ /**
1016
+ * Live view of an endnote body in the endnotes part.
1017
+ *
1018
+ * Bound to a WordDocument and note id; reads and writes go through
1019
+ * {@link NotesCatalog}. Body content is the same R5.6
1020
+ * {@link BodyItem} list as {@link Body} (`items` +
1021
+ * insert/remove). Does not expose raw OOXML.
1022
+ *
1023
+ * @public
1024
+ */
1025
+ var Endnote = /** @class */ (function () {
1026
+ /**
1027
+ * @private
1028
+ */
1029
+ function Endnote(WordDocument, noteId) {
1030
+ this.WordDocument = WordDocument;
1031
+ this.id = noteId;
1032
+ }
1033
+ Object.defineProperty(Endnote.prototype, "noteId", {
1034
+ /**
1035
+ * @private
1036
+ * Stable id matching the endnote reference and endnotes part entry. */
1037
+ get: function () {
1038
+ return this.id;
1039
+ },
1040
+ enumerable: true,
1041
+ configurable: true
1042
+ });
1043
+ Object.defineProperty(Endnote.prototype, "items", {
1044
+ /**
1045
+ * Ordered body children ({@link BodyItem}) for this endnote —
1046
+ * paragraphs, tables, block content controls, and residuals, in
1047
+ * WordDocument order (same model as {@link Body.items}).
1048
+ *
1049
+ * @public
1050
+ */
1051
+ get: function () {
1052
+ return notesFor(this.WordDocument).itemsForNote('endnote', this.id);
1053
+ },
1054
+ enumerable: true,
1055
+ configurable: true
1056
+ });
1057
+ /**
1058
+ * Insert a body item at `index` in {@link Endnote.items}
1059
+ * (`0…length` inclusive — insert-before / append).
1060
+ *
1061
+ * Attaches paragraphs and feature blocks to the owning WordDocument. Returns the
1062
+ * same `item` reference for chaining (API-RULES R1.1).
1063
+ *
1064
+ * @param index - Index in {@link Endnote.items}.
1065
+ * @param item - Paragraph, feature, or opaque body child.
1066
+ * @returns The inserted {@link BodyItem}.
1067
+ * @throws RangeError if `index` is out of range.
1068
+ *
1069
+ * @public
1070
+ */
1071
+ Endnote.prototype.insertBodyItemAt = function (index, item) {
1072
+ return notesFor(this.WordDocument).insertBodyItemAtForNote('endnote', this.id, index, item);
1073
+ };
1074
+ /**
1075
+ * Remove the body item at `index` in {@link Endnote.items}
1076
+ * (`0…length-1`). Paragraphs detach; feature blocks may release content.
1077
+ *
1078
+ * @param index - Index in {@link Endnote.items}.
1079
+ * @throws RangeError if `index` is out of range.
1080
+ *
1081
+ * @public
1082
+ */
1083
+ Endnote.prototype.removeBodyItemAt = function (index) {
1084
+ notesFor(this.WordDocument).removeBodyItemAtForNote('endnote', this.id, index);
1085
+ };
1086
+ /**
1087
+ * Remove a body item from {@link Endnote.items} by collection or payload identity.
1088
+ *
1089
+ * @param item - Entry from `items`, or an equivalent payload wrapper.
1090
+ * @throws DetachedObjectError if `item` is not in this endnote.
1091
+ *
1092
+ * @public
1093
+ */
1094
+ Endnote.prototype.removeBodyItem = function (item) {
1095
+ notesFor(this.WordDocument).removeBodyItemForNote('endnote', this.id, item);
1096
+ };
1097
+ return Endnote;
1098
+ }());
1099
+ export { Endnote };
1100
+ function loadCatalog(pkg, mainPartName) {
1101
+ var e_13, _a;
1102
+ var parts = new Map();
1103
+ try {
1104
+ for (var _b = __values(relationshipsForPart(pkg, mainPartName).items), _c = _b.next(); !_c.done; _c = _b.next()) {
1105
+ var rel = _c.value;
1106
+ var kind = kindForRelationshipType(rel.type);
1107
+ if (kind === undefined) {
1108
+ continue;
1109
+ }
1110
+ var target = resolveInternalTarget(rel.target, mainPartName);
1111
+ var part = partByName(pkg, target);
1112
+ if (part === undefined) {
1113
+ continue;
1114
+ }
1115
+ var parsed = parseNotePart(part, rel, kind);
1116
+ if (parsed !== undefined) {
1117
+ parts.set(kind, parsed);
1118
+ }
1119
+ }
1120
+ }
1121
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
1122
+ finally {
1123
+ try {
1124
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1125
+ }
1126
+ finally { if (e_13) throw e_13.error; }
1127
+ }
1128
+ return new NotesCatalog(parts);
1129
+ }
1130
+ function usedRelationshipIds(WordDocument) {
1131
+ var e_14, _a;
1132
+ var main = partName('/word/WordDocument.xml');
1133
+ var used = new Set();
1134
+ try {
1135
+ for (var _b = __values(relationshipsForPart(WordDocument.opcPackage(), main).items), _c = _b.next(); !_c.done; _c = _b.next()) {
1136
+ var rel = _c.value;
1137
+ used.add(rel.id);
1138
+ }
1139
+ }
1140
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
1141
+ finally {
1142
+ try {
1143
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1144
+ }
1145
+ finally { if (e_14) throw e_14.error; }
1146
+ }
1147
+ return used;
1148
+ }
1149
+ function usedPartNameKeys(WordDocument) {
1150
+ var e_15, _a;
1151
+ var used = new Set();
1152
+ try {
1153
+ for (var _b = __values(WordDocument.opcPackage().parts), _c = _b.next(); !_c.done; _c = _b.next()) {
1154
+ var part = _c.value;
1155
+ used.add(partNameKey(part.name));
1156
+ }
1157
+ }
1158
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
1159
+ finally {
1160
+ try {
1161
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1162
+ }
1163
+ finally { if (e_15) throw e_15.error; }
1164
+ }
1165
+ return used;
1166
+ }
1167
+ var registered = false;
1168
+ /**
1169
+ * @private
1170
+ * Test hook */
1171
+ export function resetNotesFeatureForTests() {
1172
+ registered = false;
1173
+ }
1174
+ /**
1175
+ * @private
1176
+ * Register note reference and notes-part handlers. Idempotent. */
1177
+ export function registerNotesFeature() {
1178
+ if (registered) {
1179
+ return;
1180
+ }
1181
+ registered = true;
1182
+ registerFeature({ id: NOTES });
1183
+ registerFeatureMultiPartHandler({
1184
+ featureId: NOTES,
1185
+ relationshipTypes: ALL_RELATIONSHIP_TYPES,
1186
+ loadParts: function (pkg, ctx) {
1187
+ return loadCatalog(pkg, ctx.mainPartName);
1188
+ },
1189
+ });
1190
+ registerFeatureRunLeafHandler({
1191
+ featureId: NOTES,
1192
+ wmlLocalName: 'footnoteReference',
1193
+ tryParse: function (element) {
1194
+ if (!isWml(element, 'footnoteReference')) {
1195
+ return undefined;
1196
+ }
1197
+ var noteId = parseNoteId(wmlAttribute(element, 'id'));
1198
+ if (noteId === undefined) {
1199
+ return undefined;
1200
+ }
1201
+ return new FootnoteReference(noteId);
1202
+ },
1203
+ });
1204
+ registerFeatureRunLeafHandler({
1205
+ featureId: NOTES,
1206
+ wmlLocalName: 'endnoteReference',
1207
+ tryParse: function (element) {
1208
+ if (!isWml(element, 'endnoteReference')) {
1209
+ return undefined;
1210
+ }
1211
+ var noteId = parseNoteId(wmlAttribute(element, 'id'));
1212
+ if (noteId === undefined) {
1213
+ return undefined;
1214
+ }
1215
+ return new EndnoteReference(noteId);
1216
+ },
1217
+ });
1218
+ }
1219
+ /**
1220
+ * Notes catalog for a WordDocument.
1221
+ *
1222
+ * On a loaded package this is the catalog built from footnotes/endnotes parts.
1223
+ * On a newly authored WordDocument there may be no notes parts yet, so this function
1224
+ * attaches an empty catalog on first use when the feature is registered.
1225
+ *
1226
+ * @throws DocxError `feature/not-registered` when the module was not registered.
1227
+ *
1228
+ * @private
1229
+ */
1230
+ export function notesFor(WordDocument) {
1231
+ var part = WordDocument.featurePart(NOTES);
1232
+ if (part instanceof NotesCatalog) {
1233
+ part.bindDocument(WordDocument);
1234
+ return part;
1235
+ }
1236
+ if (part !== undefined) {
1237
+ throw new DocxError('feature/not-registered', 'Notes feature state was replaced with an unexpected part type');
1238
+ }
1239
+ if (!isFeatureRegistered(NOTES)) {
1240
+ throw new DocxError('feature/not-registered', 'Notes feature is not registered; call registerNotesFeature() before use');
1241
+ }
1242
+ var created = new NotesCatalog(new Map());
1243
+ created.bindDocument(WordDocument);
1244
+ WordDocument.setFeaturePart(NOTES, created);
1245
+ return created;
1246
+ }
1247
+ /** Interned footnote body views per document (stable `===` by note id). */
1248
+ var footnoteViews = new WeakMap();
1249
+ /** Interned endnote body views per document (stable `===` by note id). */
1250
+ var endnoteViews = new WeakMap();
1251
+ function footnoteViewMap(document) {
1252
+ var map = footnoteViews.get(document);
1253
+ if (map === undefined) {
1254
+ map = new Map();
1255
+ footnoteViews.set(document, map);
1256
+ }
1257
+ return map;
1258
+ }
1259
+ function endnoteViewMap(document) {
1260
+ var map = endnoteViews.get(document);
1261
+ if (map === undefined) {
1262
+ map = new Map();
1263
+ endnoteViews.set(document, map);
1264
+ }
1265
+ return map;
1266
+ }
1267
+ /**
1268
+ * Interned live {@link Footnote} for `(document, noteId)`.
1269
+ *
1270
+ * @private
1271
+ */
1272
+ export function footnoteInstanceFor(document, noteId) {
1273
+ var map = footnoteViewMap(document);
1274
+ var existing = map.get(noteId);
1275
+ if (existing !== undefined) {
1276
+ return existing;
1277
+ }
1278
+ var created = new Footnote(document, noteId);
1279
+ map.set(noteId, created);
1280
+ return created;
1281
+ }
1282
+ /**
1283
+ * Interned live {@link Endnote} for `(document, noteId)`.
1284
+ *
1285
+ * @private
1286
+ */
1287
+ export function endnoteInstanceFor(document, noteId) {
1288
+ var map = endnoteViewMap(document);
1289
+ var existing = map.get(noteId);
1290
+ if (existing !== undefined) {
1291
+ return existing;
1292
+ }
1293
+ var created = new Endnote(document, noteId);
1294
+ map.set(noteId, created);
1295
+ return created;
1296
+ }
1297
+ /**
1298
+ * Live {@link Footnote} view for a reference in this WordDocument.
1299
+ *
1300
+ * @private
1301
+ */
1302
+ export function footnoteFor(WordDocument, reference) {
1303
+ return footnoteInstanceFor(WordDocument, reference.noteId);
1304
+ }
1305
+ /**
1306
+ * Live {@link Endnote} view for a reference in this WordDocument.
1307
+ *
1308
+ * @private
1309
+ */
1310
+ export function endnoteFor(WordDocument, reference) {
1311
+ return endnoteInstanceFor(WordDocument, reference.noteId);
1312
+ }
1313
+ /**
1314
+ * Footnote bodies referenced from the WordDocument body, in WordDocument order (first occurrence).
1315
+ *
1316
+ * @private
1317
+ */
1318
+ export function footnotesInDocument(WordDocument) {
1319
+ var found = [];
1320
+ var seen = new Set();
1321
+ visitParagraphsInDocumentOrder(WordDocument, function (paragraph) {
1322
+ var e_16, _a;
1323
+ try {
1324
+ for (var _b = __values(footnotesInParagraph(paragraph)), _c = _b.next(); !_c.done; _c = _b.next()) {
1325
+ var reference = _c.value;
1326
+ if (seen.has(reference.noteId)) {
1327
+ continue;
1328
+ }
1329
+ seen.add(reference.noteId);
1330
+ found.push(footnoteInstanceFor(WordDocument, reference.noteId));
1331
+ }
1332
+ }
1333
+ catch (e_16_1) { e_16 = { error: e_16_1 }; }
1334
+ finally {
1335
+ try {
1336
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1337
+ }
1338
+ finally { if (e_16) throw e_16.error; }
1339
+ }
1340
+ });
1341
+ return found;
1342
+ }
1343
+ /**
1344
+ * Endnote bodies referenced from the WordDocument body, in WordDocument order (first occurrence).
1345
+ *
1346
+ * @private
1347
+ */
1348
+ export function endnotesInDocument(WordDocument) {
1349
+ var found = [];
1350
+ var seen = new Set();
1351
+ visitParagraphsInDocumentOrder(WordDocument, function (paragraph) {
1352
+ var e_17, _a;
1353
+ try {
1354
+ for (var _b = __values(endnotesInParagraph(paragraph)), _c = _b.next(); !_c.done; _c = _b.next()) {
1355
+ var reference = _c.value;
1356
+ if (seen.has(reference.noteId)) {
1357
+ continue;
1358
+ }
1359
+ seen.add(reference.noteId);
1360
+ found.push(endnoteInstanceFor(WordDocument, reference.noteId));
1361
+ }
1362
+ }
1363
+ catch (e_17_1) { e_17 = { error: e_17_1 }; }
1364
+ finally {
1365
+ try {
1366
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1367
+ }
1368
+ finally { if (e_17) throw e_17.error; }
1369
+ }
1370
+ });
1371
+ return found;
1372
+ }
1373
+ /**
1374
+ * Document-level footnotes manager (`WordDocument.footnotes`).
1375
+ *
1376
+ * Stable per-document identity. Enumerates interned {@link Footnote} bodies
1377
+ * referenced from the main story in document order. Named {@link Footnotes}
1378
+ * (plural) so it does not collide with the per-note {@link Footnote} body class.
1379
+ *
1380
+ * @public
1381
+ */
1382
+ var Footnotes = /** @class */ (function () {
1383
+ /**
1384
+ * @private
1385
+ */
1386
+ function Footnotes(document) {
1387
+ this.cachedLength = 0;
1388
+ this.document = document;
1389
+ }
1390
+ Object.defineProperty(Footnotes.prototype, "count", {
1391
+ /**
1392
+ * Number of distinct footnote bodies referenced from the main story.
1393
+ *
1394
+ * @public
1395
+ */
1396
+ get: function () {
1397
+ this.rebuildIndexProperties();
1398
+ return this.cachedLength;
1399
+ },
1400
+ enumerable: true,
1401
+ configurable: true
1402
+ });
1403
+ /**
1404
+ * Footnote at zero-based `index`, or `undefined` when out of range.
1405
+ *
1406
+ * @public
1407
+ */
1408
+ Footnotes.prototype.itemAt = function (index) {
1409
+ return footnotesInDocument(this.document)[index];
1410
+ };
1411
+ Footnotes.prototype[Symbol.iterator] = function () {
1412
+ var items = footnotesInDocument(this.document).slice();
1413
+ var i = 0;
1414
+ return {
1415
+ next: function () {
1416
+ if (i >= items.length) {
1417
+ return { done: true, value: undefined };
1418
+ }
1419
+ var value = items[i];
1420
+ i += 1;
1421
+ return { done: false, value: value };
1422
+ },
1423
+ };
1424
+ };
1425
+ /**
1426
+ * @private
1427
+ */
1428
+ Footnotes.prototype.rebuildIndexProperties = function () {
1429
+ var items = footnotesInDocument(this.document);
1430
+ var nextLen = items.length;
1431
+ var prevLen = this.cachedLength;
1432
+ var limit = prevLen > nextLen ? prevLen : nextLen;
1433
+ for (var i = 0; i < limit; i += 1) {
1434
+ var key = String(i);
1435
+ if (i < nextLen) {
1436
+ Object.defineProperty(this, key, {
1437
+ value: items[i],
1438
+ writable: false,
1439
+ enumerable: true,
1440
+ configurable: true,
1441
+ });
1442
+ }
1443
+ else {
1444
+ delete this[key];
1445
+ }
1446
+ }
1447
+ this.cachedLength = nextLen;
1448
+ };
1449
+ return Footnotes;
1450
+ }());
1451
+ export { Footnotes };
1452
+ /**
1453
+ * Document-level endnotes manager (`WordDocument.endnotes`).
1454
+ *
1455
+ * Stable per-document identity. Enumerates interned {@link Endnote} bodies
1456
+ * referenced from the main story in document order. Named {@link Endnotes}
1457
+ * (plural) so it does not collide with the per-note {@link Endnote} body class.
1458
+ *
1459
+ * @public
1460
+ */
1461
+ var Endnotes = /** @class */ (function () {
1462
+ /**
1463
+ * @private
1464
+ */
1465
+ function Endnotes(document) {
1466
+ this.cachedLength = 0;
1467
+ this.document = document;
1468
+ }
1469
+ Object.defineProperty(Endnotes.prototype, "count", {
1470
+ /**
1471
+ * Number of distinct endnote bodies referenced from the main story.
1472
+ *
1473
+ * @public
1474
+ */
1475
+ get: function () {
1476
+ this.rebuildIndexProperties();
1477
+ return this.cachedLength;
1478
+ },
1479
+ enumerable: true,
1480
+ configurable: true
1481
+ });
1482
+ /**
1483
+ * Endnote at zero-based `index`, or `undefined` when out of range.
1484
+ *
1485
+ * @public
1486
+ */
1487
+ Endnotes.prototype.itemAt = function (index) {
1488
+ return endnotesInDocument(this.document)[index];
1489
+ };
1490
+ Endnotes.prototype[Symbol.iterator] = function () {
1491
+ var items = endnotesInDocument(this.document).slice();
1492
+ var i = 0;
1493
+ return {
1494
+ next: function () {
1495
+ if (i >= items.length) {
1496
+ return { done: true, value: undefined };
1497
+ }
1498
+ var value = items[i];
1499
+ i += 1;
1500
+ return { done: false, value: value };
1501
+ },
1502
+ };
1503
+ };
1504
+ /**
1505
+ * @private
1506
+ */
1507
+ Endnotes.prototype.rebuildIndexProperties = function () {
1508
+ var items = endnotesInDocument(this.document);
1509
+ var nextLen = items.length;
1510
+ var prevLen = this.cachedLength;
1511
+ var limit = prevLen > nextLen ? prevLen : nextLen;
1512
+ for (var i = 0; i < limit; i += 1) {
1513
+ var key = String(i);
1514
+ if (i < nextLen) {
1515
+ Object.defineProperty(this, key, {
1516
+ value: items[i],
1517
+ writable: false,
1518
+ enumerable: true,
1519
+ configurable: true,
1520
+ });
1521
+ }
1522
+ else {
1523
+ delete this[key];
1524
+ }
1525
+ }
1526
+ this.cachedLength = nextLen;
1527
+ };
1528
+ return Endnotes;
1529
+ }());
1530
+ export { Endnotes };
1531
+ var footnotesManagers = new WeakMap();
1532
+ var endnotesManagers = new WeakMap();
1533
+ /**
1534
+ * Stable {@link Footnotes} manager for `document`.
1535
+ *
1536
+ * @private
1537
+ */
1538
+ export function footnotesFor(document) {
1539
+ registerNotesFeature();
1540
+ var cached = footnotesManagers.get(document);
1541
+ if (cached !== undefined) {
1542
+ cached.rebuildIndexProperties();
1543
+ return cached;
1544
+ }
1545
+ var created = new Footnotes(document);
1546
+ created.rebuildIndexProperties();
1547
+ footnotesManagers.set(document, created);
1548
+ return created;
1549
+ }
1550
+ /**
1551
+ * Stable {@link Endnotes} manager for `document`.
1552
+ *
1553
+ * @private
1554
+ */
1555
+ export function endnotesFor(document) {
1556
+ registerNotesFeature();
1557
+ var cached = endnotesManagers.get(document);
1558
+ if (cached !== undefined) {
1559
+ cached.rebuildIndexProperties();
1560
+ return cached;
1561
+ }
1562
+ var created = new Endnotes(document);
1563
+ created.rebuildIndexProperties();
1564
+ endnotesManagers.set(document, created);
1565
+ return created;
1566
+ }
1567
+ function referencesInParagraph(paragraph, predicate) {
1568
+ var e_18, _a;
1569
+ var found = [];
1570
+ try {
1571
+ for (var _b = __values(paragraph.items), _c = _b.next(); !_c.done; _c = _b.next()) {
1572
+ var item = _c.value;
1573
+ if (predicate(item)) {
1574
+ found.push(item.value);
1575
+ }
1576
+ }
1577
+ }
1578
+ catch (e_18_1) { e_18 = { error: e_18_1 }; }
1579
+ finally {
1580
+ try {
1581
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1582
+ }
1583
+ finally { if (e_18) throw e_18.error; }
1584
+ }
1585
+ return found;
1586
+ }
1587
+ /**
1588
+ * Footnote references in a paragraph, in WordDocument order.
1589
+ *
1590
+ * @private
1591
+ */
1592
+ export function footnotesInParagraph(paragraph) {
1593
+ return referencesInParagraph(paragraph, isFootnoteReferenceLeaf);
1594
+ }
1595
+ /**
1596
+ * Endnote references in a paragraph, in WordDocument order.
1597
+ *
1598
+ * @private
1599
+ */
1600
+ export function endnotesInParagraph(paragraph) {
1601
+ return referencesInParagraph(paragraph, isEndnoteReferenceLeaf);
1602
+ }
1603
+ /**
1604
+ * Visible text of a footnote body, when loaded.
1605
+ *
1606
+ * @private
1607
+ */
1608
+ export function footnoteText(WordDocument, reference) {
1609
+ return notesFor(WordDocument).textForNote('footnote', reference.noteId);
1610
+ }
1611
+ /**
1612
+ * Visible text of an endnote body, when loaded.
1613
+ *
1614
+ * @private
1615
+ */
1616
+ export function endnoteText(WordDocument, reference) {
1617
+ return notesFor(WordDocument).textForNote('endnote', reference.noteId);
1618
+ }
1619
+ /**
1620
+ * Insert a footnote reference and body at the end of a paragraph.
1621
+ *
1622
+ * @private
1623
+ */
1624
+ export function insertFootnote(WordDocument, paragraph, text) {
1625
+ var catalog = notesFor(WordDocument);
1626
+ catalog.ensurePart('footnote', usedRelationshipIds(WordDocument), usedPartNameKeys(WordDocument));
1627
+ var noteId = catalog.addNormalEntry('footnote', text);
1628
+ var reference = new FootnoteReference(noteId);
1629
+ var item = paragraph.appendFeatureRunItem(NOTES, reference);
1630
+ // Note markers are superscript in Word (w:rPr/w:vertAlign w:val="superscript").
1631
+ item.wireGroup.characterFormat.subSuperScript = SubSuperScript.SuperScript;
1632
+ return reference;
1633
+ }
1634
+ /**
1635
+ * Insert an endnote reference and body at the end of a paragraph.
1636
+ *
1637
+ * @private
1638
+ */
1639
+ export function insertEndnote(WordDocument, paragraph, text) {
1640
+ var catalog = notesFor(WordDocument);
1641
+ catalog.ensurePart('endnote', usedRelationshipIds(WordDocument), usedPartNameKeys(WordDocument));
1642
+ var noteId = catalog.addNormalEntry('endnote', text);
1643
+ var reference = new EndnoteReference(noteId);
1644
+ var item = paragraph.appendFeatureRunItem(NOTES, reference);
1645
+ // Note markers are superscript in Word (w:rPr/w:vertAlign w:val="superscript").
1646
+ item.wireGroup.characterFormat.subSuperScript = SubSuperScript.SuperScript;
1647
+ return reference;
1648
+ }
1649
+ function removeReferenceRun(paragraph, reference) {
1650
+ var e_19, _a;
1651
+ try {
1652
+ for (var _b = __values(paragraph.items), _c = _b.next(); !_c.done; _c = _b.next()) {
1653
+ var item = _c.value;
1654
+ if (item instanceof FeatureRunParagraphItem && item.featureId === NOTES && item.value === reference) {
1655
+ paragraph.removeFeatureRunItem(reference);
1656
+ return;
1657
+ }
1658
+ }
1659
+ }
1660
+ catch (e_19_1) { e_19 = { error: e_19_1 }; }
1661
+ finally {
1662
+ try {
1663
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1664
+ }
1665
+ finally { if (e_19) throw e_19.error; }
1666
+ }
1667
+ throw new DocxError('content/unknown-note', 'Note reference is not in this paragraph');
1668
+ }
1669
+ /**
1670
+ * Remove a footnote reference and body from a WordDocument.
1671
+ *
1672
+ * @private
1673
+ */
1674
+ export function removeFootnote(WordDocument, paragraph, reference) {
1675
+ removeReferenceRun(paragraph, reference);
1676
+ notesFor(WordDocument).removeNormalEntry('footnote', reference.noteId);
1677
+ }
1678
+ /**
1679
+ * Remove an endnote reference and body from a WordDocument.
1680
+ *
1681
+ * @private
1682
+ */
1683
+ export function removeEndnote(WordDocument, paragraph, reference) {
1684
+ removeReferenceRun(paragraph, reference);
1685
+ notesFor(WordDocument).removeNormalEntry('endnote', reference.noteId);
1686
+ }
1687
+ /**
1688
+ * Whether a paragraph item is a modeled footnote reference from this module.
1689
+ *
1690
+ * @private
1691
+ */
1692
+ export function isFootnoteReferenceLeaf(item) {
1693
+ return item instanceof FeatureRunParagraphItem && item.featureId === NOTES && item.value instanceof FootnoteReference;
1694
+ }
1695
+ /**
1696
+ * Whether a paragraph item is a modeled endnote reference from this module.
1697
+ *
1698
+ * @private
1699
+ */
1700
+ export function isEndnoteReferenceLeaf(item) {
1701
+ return item instanceof FeatureRunParagraphItem && item.featureId === NOTES && item.value instanceof EndnoteReference;
1702
+ }
1703
+ Object.defineProperty(WordDocument.prototype, 'footnotes', {
1704
+ configurable: true,
1705
+ enumerable: false,
1706
+ get: function () {
1707
+ return footnotesFor(this);
1708
+ },
1709
+ });
1710
+ Object.defineProperty(WordDocument.prototype, 'endnotes', {
1711
+ configurable: true,
1712
+ enumerable: false,
1713
+ get: function () {
1714
+ return endnotesFor(this);
1715
+ },
1716
+ });
1717
+ Paragraph.prototype.appendFootnote = function (text) {
1718
+ var reference = insertFootnote(this.owningDocument(), this, text);
1719
+ return footnoteInstanceFor(this.owningDocument(), reference.noteId);
1720
+ };
1721
+ Paragraph.prototype.appendEndnote = function (text) {
1722
+ var reference = insertEndnote(this.owningDocument(), this, text);
1723
+ return endnoteInstanceFor(this.owningDocument(), reference.noteId);
1724
+ };
1725
+ registerNotesFeature();