@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,1517 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __values = (this && this.__values) || function (o) {
13
+ var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
14
+ if (m) return m.call(o);
15
+ return {
16
+ next: function () {
17
+ if (o && i >= o.length) o = void 0;
18
+ return { value: o && o[i++], done: !o };
19
+ }
20
+ };
21
+ };
22
+ var __read = (this && this.__read) || function (o, n) {
23
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
24
+ if (!m) return o;
25
+ var i = m.call(o), r, ar = [], e;
26
+ try {
27
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
28
+ }
29
+ catch (error) { e = { error: error }; }
30
+ finally {
31
+ try {
32
+ if (r && !r.done && (m = i["return"])) m.call(i);
33
+ }
34
+ finally { if (e) throw e.error; }
35
+ }
36
+ return ar;
37
+ };
38
+ var __spread = (this && this.__spread) || function () {
39
+ for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
40
+ return ar;
41
+ };
42
+ /**
43
+ * Dirty watermark header rewrite (TASK-8062).
44
+ *
45
+ * Materializes logical watermark state into section headers on save.
46
+ * Picture media + header-local image relationships are staged as a
47
+ * {@link FeaturePackageLevelPart} applied after header multi-part writes.
48
+ *
49
+ * Canonical emit: `docs/specs/watermark-basic.md`. Washout tokens from
50
+ * PictureWatermark.docx fixture: `gain="19661f"` `blacklevel="22938f"`.
51
+ *
52
+ * @packageDocumentation
53
+ */
54
+ import { sha256Hex } from '../../core/compat/sha256';
55
+ import { OpaqueParagraphItem, OpaqueRunItem } from '../document/text-range';
56
+ import { elementChildren, isWml, wmlElement } from '../document/wml';
57
+ import { DocxError } from '../../core/errors/docx-error';
58
+ import { objectEntries } from '../../core/compat/object-compat';
59
+ import { allocateRelationshipId, partByName, relationshipsForPart, relationshipsWith, resolveInternalTarget, withAddedPart, withContentTypeOverride, withPartRelationships } from '../../core/opc/index';
60
+ import { partName, partNameKey } from '../../core/opc/part-name';
61
+ import { featureId } from '../../core/registry/feature-registry';
62
+ import { parseXml } from '../../core/xml/index';
63
+ import { headersFootersFor } from '../headers-footers/index';
64
+ import { IMAGE_RELATIONSHIP_TYPE, JPEG_CONTENT_TYPE, PNG_CONTENT_TYPE, STRICT_IMAGE_RELATIONSHIP_TYPE } from '../images/index';
65
+ import { sniffImageContentType, sniffImagePixelDimensions } from '../images/image-sniff';
66
+ import { finalSection, paragraphSectionBreak } from '../sections/index';
67
+ import { isPictureWatermarkShape, isTextWatermarkShape, isVml, PICTURE_WATERMARK_ID_PREFIX, PICTURE_WATERMARK_TYPE, TEXT_WATERMARK_ID_PREFIX, TEXT_WATERMARK_TYPE, VML_NS, } from './detect';
68
+ import { ImageType, WatermarkLayout, WatermarkType } from './model';
69
+ import { logicalWatermarkOf } from './logical-store';
70
+ var WATERMARK = featureId('watermark');
71
+ /** Office namespace used for `o:title` / washout attrs on `v:imagedata`. */
72
+ var OFFICE_NS = 'urn:schemas-microsoft-com:office:office';
73
+ /** Relationships namespace for `r:id` on `v:imagedata`. */
74
+ var R_NS = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships';
75
+ /** Image relationship types (transitional + strict). */
76
+ var IMAGE_RELATIONSHIP_TYPES = [
77
+ IMAGE_RELATIONSHIP_TYPE,
78
+ STRICT_IMAGE_RELATIONSHIP_TYPE,
79
+ ];
80
+ /** Text fallback dimensions (pt) when width/height unset — locked by spec. */
81
+ var TEXT_FALLBACK_WIDTH_PT = 250;
82
+ var TEXT_FALLBACK_HEIGHT_PT = 100;
83
+ /** Canonical dirty text z-index. */
84
+ var TEXT_Z_INDEX = '-251658752';
85
+ /** Canonical dirty picture z-index. */
86
+ var PICTURE_Z_INDEX = '-1';
87
+ /**
88
+ * Verified Word washout tokens from PictureWatermark.docx fixture
89
+ * (`v:imagedata` gain + blacklevel).
90
+ */
91
+ var WASHOUT_GAIN = '19661f';
92
+ var WASHOUT_BLACKLEVEL = '22938f';
93
+ /** Header reference types stamped for scratch watermark policy. */
94
+ var HEADER_REF_TYPES = ['default', 'even', 'first'];
95
+ /** Documents whose logical watermark assignment requires header rewrite. */
96
+ var dirtyDocuments = new WeakSet();
97
+ /**
98
+ * Package-level pending state for watermark picture media + header image rels
99
+ * (adds) and post-strip GC (header image rel filters + media removals).
100
+ *
101
+ * Applied in `applyFeaturePackageParts` after HF multi-part writes header XML.
102
+ */
103
+ var WatermarkPackageParts = /** @class */ (function () {
104
+ function WatermarkPackageParts() {
105
+ this.dirtyValue = false;
106
+ this.mediaParts = [];
107
+ this.headerRels = [];
108
+ this.headerImageRelFilters = [];
109
+ this.mediaRemovals = [];
110
+ }
111
+ /**
112
+ * @private
113
+ */
114
+ WatermarkPackageParts.prototype.isDirty = function () {
115
+ return this.dirtyValue;
116
+ };
117
+ /**
118
+ * @private
119
+ * Stage a media part (dedupe by bytes+content type externally). */
120
+ WatermarkPackageParts.prototype.stageMedia = function (part) {
121
+ this.mediaParts.push(part);
122
+ this.dirtyValue = true;
123
+ };
124
+ /**
125
+ * @private
126
+ * Stage a header-local image relationship. */
127
+ WatermarkPackageParts.prototype.stageHeaderRel = function (headerPartName, relationship) {
128
+ this.headerRels.push({ headerPartName: headerPartName, relationship: relationship });
129
+ this.dirtyValue = true;
130
+ };
131
+ /**
132
+ * @private
133
+ * Relationship ids staged for a header part (not yet in package).
134
+ * GC must treat these as still referenced so filters do not drop them.
135
+ */
136
+ WatermarkPackageParts.prototype.stagedHeaderRelIds = function (headerPartName) {
137
+ var e_1, _a;
138
+ var key = partNameKey(headerPartName);
139
+ var ids = new Set();
140
+ try {
141
+ for (var _b = __values(this.headerRels), _c = _b.next(); !_c.done; _c = _b.next()) {
142
+ var item = _c.value;
143
+ if (partNameKey(item.headerPartName) === key) {
144
+ ids.add(item.relationship.id);
145
+ }
146
+ }
147
+ }
148
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
149
+ finally {
150
+ try {
151
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
152
+ }
153
+ finally { if (e_1) throw e_1.error; }
154
+ }
155
+ return ids;
156
+ };
157
+ /**
158
+ * @private
159
+ * After rewrite, drop header-local image relationships whose ids
160
+ * are no longer referenced in that header's body (Removal rule 7).
161
+ */
162
+ WatermarkPackageParts.prototype.stageHeaderImageRelFilter = function (headerPartName, referencedIds) {
163
+ this.headerImageRelFilters.push({ headerPartName: headerPartName, referencedIds: referencedIds });
164
+ this.dirtyValue = true;
165
+ };
166
+ /**
167
+ * @private
168
+ * Stage media part removal when package-wide unused (Removal rule 8).
169
+ */
170
+ WatermarkPackageParts.prototype.stageMediaRemoval = function (name) {
171
+ var key = partNameKey(name);
172
+ if (this.mediaRemovals.some(function (existing) { return partNameKey(existing) === key; })) {
173
+ return;
174
+ }
175
+ this.mediaRemovals.push(name);
176
+ this.dirtyValue = true;
177
+ };
178
+ /**
179
+ * @private
180
+ * Clear after successful apply. */
181
+ WatermarkPackageParts.prototype.clear = function () {
182
+ this.mediaParts = [];
183
+ this.headerRels = [];
184
+ this.headerImageRelFilters = [];
185
+ this.mediaRemovals = [];
186
+ this.dirtyValue = false;
187
+ };
188
+ /**
189
+ * @private
190
+ */
191
+ WatermarkPackageParts.prototype.applyToPackage = function (pkg) {
192
+ var e_2, _a, e_3, _b, e_4, _c, e_5, _d, e_6, _e, e_7, _f;
193
+ if (!this.dirtyValue) {
194
+ return pkg;
195
+ }
196
+ var next = pkg;
197
+ try {
198
+ for (var _g = __values(this.mediaParts), _h = _g.next(); !_h.done; _h = _g.next()) {
199
+ var media = _h.value;
200
+ var packagePart = {
201
+ name: media.partName,
202
+ contentType: media.contentType,
203
+ data: media.data,
204
+ };
205
+ next = withAddedPart(next, packagePart);
206
+ next = withContentTypeOverride(next, media.partName, media.contentType);
207
+ }
208
+ }
209
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
210
+ finally {
211
+ try {
212
+ if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
213
+ }
214
+ finally { if (e_2) throw e_2.error; }
215
+ }
216
+ // Group header rels by part and merge.
217
+ var byHeader = new Map();
218
+ try {
219
+ for (var _j = __values(this.headerRels), _k = _j.next(); !_k.done; _k = _j.next()) {
220
+ var item = _k.value;
221
+ var key = partNameKey(item.headerPartName);
222
+ var bucket = byHeader.get(key);
223
+ if (bucket === undefined) {
224
+ bucket = { partName: item.headerPartName, rels: [] };
225
+ byHeader.set(key, bucket);
226
+ }
227
+ bucket.rels.push(item.relationship);
228
+ }
229
+ }
230
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
231
+ finally {
232
+ try {
233
+ if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
234
+ }
235
+ finally { if (e_3) throw e_3.error; }
236
+ }
237
+ try {
238
+ for (var _l = __values(byHeader.values()), _m = _l.next(); !_m.done; _m = _l.next()) {
239
+ var bucket = _m.value;
240
+ var existing = relationshipsForPart(next, bucket.partName);
241
+ var used = new Set(existing.items.map(function (r) { return r.id; }));
242
+ var merged = __spread(existing.items);
243
+ var _loop_1 = function (rel) {
244
+ if (merged.some(function (item) { return item.type === rel.type && item.target === rel.target; })) {
245
+ return "continue";
246
+ }
247
+ var id = rel.id;
248
+ while (used.has(id)) {
249
+ id = allocateRelationshipId(used);
250
+ }
251
+ used.add(id);
252
+ merged.push(__assign({}, rel, { id: id }));
253
+ };
254
+ try {
255
+ for (var _o = __values(bucket.rels), _p = _o.next(); !_p.done; _p = _o.next()) {
256
+ var rel = _p.value;
257
+ _loop_1(rel);
258
+ }
259
+ }
260
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
261
+ finally {
262
+ try {
263
+ if (_p && !_p.done && (_d = _o.return)) _d.call(_o);
264
+ }
265
+ finally { if (e_5) throw e_5.error; }
266
+ }
267
+ next = withPartRelationships(next, bucket.partName, relationshipsWith(merged, existing.opaque));
268
+ }
269
+ }
270
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
271
+ finally {
272
+ try {
273
+ if (_m && !_m.done && (_c = _l.return)) _c.call(_l);
274
+ }
275
+ finally { if (e_4) throw e_4.error; }
276
+ }
277
+ var _loop_2 = function (filter) {
278
+ next = withFilteredPartRelationshipsLocal(next, filter.headerPartName, function (rel) { return !isImageRelationshipType(rel.type) || filter.referencedIds.has(rel.id); });
279
+ };
280
+ try {
281
+ // Drop unused header-local image relationships (rule 7).
282
+ for (var _q = __values(this.headerImageRelFilters), _r = _q.next(); !_r.done; _r = _q.next()) {
283
+ var filter = _r.value;
284
+ _loop_2(filter);
285
+ }
286
+ }
287
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
288
+ finally {
289
+ try {
290
+ if (_r && !_r.done && (_e = _q.return)) _e.call(_q);
291
+ }
292
+ finally { if (e_6) throw e_6.error; }
293
+ }
294
+ try {
295
+ // Drop media only when package-wide unreferenced (rule 8).
296
+ for (var _s = __values(this.mediaRemovals), _t = _s.next(); !_t.done; _t = _s.next()) {
297
+ var mediaName = _t.value;
298
+ if (mediaPartIsReferenced(next, mediaName)) {
299
+ continue;
300
+ }
301
+ next = withRemovedPartLocal(next, mediaName);
302
+ next = withRemovedContentTypeOverrideLocal(next, mediaName);
303
+ }
304
+ }
305
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
306
+ finally {
307
+ try {
308
+ if (_t && !_t.done && (_f = _s.return)) _f.call(_s);
309
+ }
310
+ finally { if (e_7) throw e_7.error; }
311
+ }
312
+ this.clear();
313
+ return next;
314
+ };
315
+ return WatermarkPackageParts;
316
+ }());
317
+ export { WatermarkPackageParts };
318
+ function isImageRelationshipType(type) {
319
+ return IMAGE_RELATIONSHIP_TYPES.indexOf(type) !== -1;
320
+ }
321
+ function withRemovedPartLocal(pkg, name) {
322
+ var key = partNameKey(name);
323
+ var parts = pkg.parts.filter(function (part) { return partNameKey(part.name) !== key; });
324
+ if (parts.length === pkg.parts.length) {
325
+ return pkg;
326
+ }
327
+ return __assign({}, pkg, { parts: parts });
328
+ }
329
+ function withRemovedContentTypeOverrideLocal(pkg, logicalPartName) {
330
+ return __assign({}, pkg, { contentTypes: {
331
+ records: pkg.contentTypes.records.filter(function (record) { return !(record.kind === 'override' && record.partName === logicalPartName); }),
332
+ } });
333
+ }
334
+ function withFilteredPartRelationshipsLocal(pkg, source, keep) {
335
+ var existing = relationshipsForPart(pkg, source);
336
+ var kept = existing.items.filter(keep);
337
+ if (kept.length === existing.items.length) {
338
+ return pkg;
339
+ }
340
+ return withPartRelationships(pkg, source, relationshipsWith(kept, existing.opaque));
341
+ }
342
+ function mediaPartIsReferenced(pkg, mediaName) {
343
+ var e_8, _a, e_9, _b, e_10, _c;
344
+ var mediaKey = partNameKey(mediaName);
345
+ var check = function (rel, source) {
346
+ if (rel.targetMode === 'External') {
347
+ return false;
348
+ }
349
+ try {
350
+ // Package Relationships resolve with omitted source (not partName('/')).
351
+ return partNameKey(resolveInternalTarget(rel.target, source)) === mediaKey;
352
+ }
353
+ catch (_a) {
354
+ return false;
355
+ }
356
+ };
357
+ try {
358
+ for (var _d = __values(pkg.packageRelationships.items), _e = _d.next(); !_e.done; _e = _d.next()) {
359
+ var rel = _e.value;
360
+ if (check(rel)) {
361
+ return true;
362
+ }
363
+ }
364
+ }
365
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
366
+ finally {
367
+ try {
368
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
369
+ }
370
+ finally { if (e_8) throw e_8.error; }
371
+ }
372
+ try {
373
+ for (var _f = __values(pkg.partRelationships), _g = _f.next(); !_g.done; _g = _f.next()) {
374
+ var set = _g.value;
375
+ try {
376
+ for (var _h = __values(set.relationships.items), _j = _h.next(); !_j.done; _j = _h.next()) {
377
+ var rel = _j.value;
378
+ if (check(rel, set.source)) {
379
+ return true;
380
+ }
381
+ }
382
+ }
383
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
384
+ finally {
385
+ try {
386
+ if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
387
+ }
388
+ finally { if (e_10) throw e_10.error; }
389
+ }
390
+ }
391
+ }
392
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
393
+ finally {
394
+ try {
395
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
396
+ }
397
+ finally { if (e_9) throw e_9.error; }
398
+ }
399
+ return false;
400
+ }
401
+ /**
402
+ * Mark document dirty for watermark materialize.
403
+ * @private
404
+ */
405
+ export function markWatermarkDirty(document) {
406
+ dirtyDocuments.add(document);
407
+ }
408
+ /**
409
+ * True when watermark materialize must rewrite headers.
410
+ * @private
411
+ */
412
+ export function isWatermarkDirty(document) {
413
+ return dirtyDocuments.has(document);
414
+ }
415
+ /**
416
+ * Clear dirty flag (after successful materialize or clean load).
417
+ * @private
418
+ */
419
+ export function clearWatermarkDirty(document) {
420
+ dirtyDocuments.delete(document);
421
+ }
422
+ /**
423
+ * Reset module dirty state for tests.
424
+ * @private
425
+ */
426
+ export function resetWatermarkSerializeStateForTests() {
427
+ // WeakSet cannot be cleared globally; documents are GC'd. No-op holder for API symmetry.
428
+ }
429
+ function packagePartsFor(document) {
430
+ var existing = document.featurePart(WATERMARK);
431
+ if (existing instanceof WatermarkPackageParts) {
432
+ return existing;
433
+ }
434
+ var created = new WatermarkPackageParts();
435
+ document.setFeaturePart(WATERMARK, created);
436
+ return created;
437
+ }
438
+ function usedRelationshipIds(document) {
439
+ var e_11, _a;
440
+ var main = partName('/word/document.xml');
441
+ var used = new Set();
442
+ try {
443
+ for (var _b = __values(relationshipsForPart(document.opcPackage(), main).items), _c = _b.next(); !_c.done; _c = _b.next()) {
444
+ var rel = _c.value;
445
+ used.add(rel.id);
446
+ }
447
+ }
448
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
449
+ finally {
450
+ try {
451
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
452
+ }
453
+ finally { if (e_11) throw e_11.error; }
454
+ }
455
+ return used;
456
+ }
457
+ function usedPartNameKeys(document) {
458
+ var e_12, _a;
459
+ var used = new Set();
460
+ try {
461
+ for (var _b = __values(document.opcPackage().parts), _c = _b.next(); !_c.done; _c = _b.next()) {
462
+ var part = _c.value;
463
+ used.add(partNameKey(part.name));
464
+ }
465
+ }
466
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
467
+ finally {
468
+ try {
469
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
470
+ }
471
+ finally { if (e_12) throw e_12.error; }
472
+ }
473
+ return used;
474
+ }
475
+ /**
476
+ * Ordered dual-hold section properties: paragraph break bags, then body-final.
477
+ * Internal walk only — the public surface is `lastSection` / `sectionBreak`.
478
+ */
479
+ function sectionPropertiesInDocumentOrder(document) {
480
+ var e_13, _a;
481
+ var out = [];
482
+ try {
483
+ for (var _b = __values(document.listBlocks()), _c = _b.next(); !_c.done; _c = _b.next()) {
484
+ var block = _c.value;
485
+ if (block.type !== 'paragraph') {
486
+ continue;
487
+ }
488
+ var breakProps = paragraphSectionBreak(block.paragraph);
489
+ if (breakProps !== undefined) {
490
+ out.push(breakProps);
491
+ }
492
+ }
493
+ }
494
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
495
+ finally {
496
+ try {
497
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
498
+ }
499
+ finally { if (e_13) throw e_13.error; }
500
+ }
501
+ var bodyFinal = finalSection(document);
502
+ if (bodyFinal !== undefined) {
503
+ out.push(bodyFinal);
504
+ }
505
+ return out;
506
+ }
507
+ /**
508
+ * Dual-hold already keeps each `PageSetup` on its break paragraph or
509
+ * body-final slot. Mutating header refs in place is enough for save; no
510
+ * Section-view write-back is required.
511
+ */
512
+ function ensureScratchHeaders(document, catalog) {
513
+ var e_14, _a, e_15, _b;
514
+ var usedRelIds = usedRelationshipIds(document);
515
+ var usedPartNames = usedPartNameKeys(document);
516
+ try {
517
+ for (var _c = __values(sectionPropertiesInDocumentOrder(document)), _d = _c.next(); !_d.done; _d = _c.next()) {
518
+ var props = _d.value;
519
+ try {
520
+ for (var HEADER_REF_TYPES_1 = __values(HEADER_REF_TYPES), HEADER_REF_TYPES_1_1 = HEADER_REF_TYPES_1.next(); !HEADER_REF_TYPES_1_1.done; HEADER_REF_TYPES_1_1 = HEADER_REF_TYPES_1.next()) {
521
+ var refType = HEADER_REF_TYPES_1_1.value;
522
+ var relationshipId = catalog.ensurePart('header', props, refType, usedRelIds, usedPartNames).relationshipId;
523
+ props.setHeaderFooterReference('header', refType, relationshipId);
524
+ usedRelIds.add(relationshipId);
525
+ }
526
+ }
527
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
528
+ finally {
529
+ try {
530
+ if (HEADER_REF_TYPES_1_1 && !HEADER_REF_TYPES_1_1.done && (_b = HEADER_REF_TYPES_1.return)) _b.call(HEADER_REF_TYPES_1);
531
+ }
532
+ finally { if (e_15) throw e_15.error; }
533
+ }
534
+ }
535
+ }
536
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
537
+ finally {
538
+ try {
539
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
540
+ }
541
+ finally { if (e_14) throw e_14.error; }
542
+ }
543
+ }
544
+ function shapesUnderPict(pict) {
545
+ var e_16, _a;
546
+ var shapes = [];
547
+ try {
548
+ for (var _b = __values(elementChildren(pict)), _c = _b.next(); !_c.done; _c = _b.next()) {
549
+ var child = _c.value;
550
+ if (isVml(child, 'shape')) {
551
+ shapes.push(child);
552
+ }
553
+ }
554
+ }
555
+ catch (e_16_1) { e_16 = { error: e_16_1 }; }
556
+ finally {
557
+ try {
558
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
559
+ }
560
+ finally { if (e_16) throw e_16.error; }
561
+ }
562
+ return shapes;
563
+ }
564
+ function pictContainsRecognizedWatermark(pict) {
565
+ var e_17, _a;
566
+ try {
567
+ for (var _b = __values(shapesUnderPict(pict)), _c = _b.next(); !_c.done; _c = _b.next()) {
568
+ var shape = _c.value;
569
+ if (isTextWatermarkShape(shape) || isPictureWatermarkShape(shape)) {
570
+ return true;
571
+ }
572
+ }
573
+ }
574
+ catch (e_17_1) { e_17 = { error: e_17_1 }; }
575
+ finally {
576
+ try {
577
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
578
+ }
579
+ finally { if (e_17) throw e_17.error; }
580
+ }
581
+ return false;
582
+ }
583
+ function openXmlContainsRecognizedWatermark(node) {
584
+ var e_18, _a;
585
+ if (isWml(node, 'pict')) {
586
+ return pictContainsRecognizedWatermark(node);
587
+ }
588
+ try {
589
+ for (var _b = __values(elementChildren(node)), _c = _b.next(); !_c.done; _c = _b.next()) {
590
+ var child = _c.value;
591
+ if (openXmlContainsRecognizedWatermark(child)) {
592
+ return true;
593
+ }
594
+ }
595
+ }
596
+ catch (e_18_1) { e_18 = { error: e_18_1 }; }
597
+ finally {
598
+ try {
599
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
600
+ }
601
+ finally { if (e_18) throw e_18.error; }
602
+ }
603
+ return false;
604
+ }
605
+ function isWatermarkOpaqueInline(inline) {
606
+ return (inline instanceof OpaqueParagraphItem &&
607
+ openXmlContainsRecognizedWatermark(inline.xml));
608
+ }
609
+ /**
610
+ * True when every remaining item is a watermark opaque (or the paragraph is empty) —
611
+ * i.e. the paragraph is watermark-owned and safely empty after strip (Removal 4).
612
+ */
613
+ function isWatermarkOnlyParagraph(paragraph) {
614
+ var content = paragraph.items;
615
+ if (content.length === 0) {
616
+ return true;
617
+ }
618
+ return content.every(function (inline) { return isWatermarkOpaqueInline(inline); });
619
+ }
620
+ /**
621
+ * Strip recognized watermark `w:pict` items from a header entry (Removal 1–5).
622
+ *
623
+ * - Opaque watermark paragraph items: filter via paragraph snapshot + hydrate.
624
+ * - Watermark-only empty paragraphs: omit from blocks (never delete header parts).
625
+ * - Tables / non-wm opaque / feature blocks: preserved.
626
+ */
627
+ function stripEntryWatermarkLeaves(entry) {
628
+ var e_19, _a;
629
+ var nextBlocks = [];
630
+ var changed = false;
631
+ try {
632
+ for (var _b = __values(entry.blocks), _c = _b.next(); !_c.done; _c = _b.next()) {
633
+ var block = _c.value;
634
+ if (block.type === 'opaque') {
635
+ if (openXmlContainsRecognizedWatermark(block.xml)) {
636
+ changed = true;
637
+ continue;
638
+ }
639
+ nextBlocks.push(block);
640
+ continue;
641
+ }
642
+ if (block.type !== 'paragraph') {
643
+ nextBlocks.push(block);
644
+ continue;
645
+ }
646
+ var paragraph = block.paragraph;
647
+ var strippedWm = false;
648
+ if (paragraph.items.some(isWatermarkOpaqueInline)) {
649
+ strippedWm = true;
650
+ if (isWatermarkOnlyParagraph(paragraph)) {
651
+ // Removal 4: watermark-owned and safely empty → drop paragraph.
652
+ changed = true;
653
+ continue;
654
+ }
655
+ var snap = paragraph.snapshot();
656
+ var filteredItems = snap.items.filter(function (inline) { return !isWatermarkOpaqueInline(inline); });
657
+ if (filteredItems.length !== snap.items.length) {
658
+ paragraph.hydrate(__assign({}, snap, { items: filteredItems }));
659
+ changed = true;
660
+ }
661
+ }
662
+ // After strip, drop paragraphs that only held watermark content.
663
+ if (strippedWm && isWatermarkOnlyParagraph(paragraph)) {
664
+ changed = true;
665
+ continue;
666
+ }
667
+ nextBlocks.push(block);
668
+ }
669
+ }
670
+ catch (e_19_1) { e_19 = { error: e_19_1 }; }
671
+ finally {
672
+ try {
673
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
674
+ }
675
+ finally { if (e_19) throw e_19.error; }
676
+ }
677
+ if (changed) {
678
+ entry.blocks = nextBlocks;
679
+ entry.dirty = true;
680
+ }
681
+ return changed;
682
+ }
683
+ /**
684
+ * Collect relationship ids still referenced from header body markup
685
+ * (`r:id` attributes, including `v:imagedata`).
686
+ */
687
+ function collectReferencedRelationshipIds(entry) {
688
+ var e_20, _a, e_21, _b;
689
+ var ids = new Set();
690
+ var scan = function (node) {
691
+ var e_22, _a, e_23, _b;
692
+ try {
693
+ for (var _c = __values(node.attributes), _d = _c.next(); !_d.done; _d = _c.next()) {
694
+ var a = _d.value;
695
+ if (a.localName === 'id' && (a.namespaceUri === R_NS || a.prefix === 'r')) {
696
+ ids.add(a.value);
697
+ }
698
+ if (a.namespaceUri === R_NS && (a.localName === 'embed' || a.localName === 'link')) {
699
+ ids.add(a.value);
700
+ }
701
+ }
702
+ }
703
+ catch (e_22_1) { e_22 = { error: e_22_1 }; }
704
+ finally {
705
+ try {
706
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
707
+ }
708
+ finally { if (e_22) throw e_22.error; }
709
+ }
710
+ try {
711
+ for (var _e = __values(elementChildren(node)), _f = _e.next(); !_f.done; _f = _e.next()) {
712
+ var child = _f.value;
713
+ scan(child);
714
+ }
715
+ }
716
+ catch (e_23_1) { e_23 = { error: e_23_1 }; }
717
+ finally {
718
+ try {
719
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
720
+ }
721
+ finally { if (e_23) throw e_23.error; }
722
+ }
723
+ };
724
+ try {
725
+ for (var _c = __values(entry.blocks), _d = _c.next(); !_d.done; _d = _c.next()) {
726
+ var block = _d.value;
727
+ if (block.type === 'opaque') {
728
+ scan(block.xml);
729
+ continue;
730
+ }
731
+ if (block.type === 'paragraph') {
732
+ try {
733
+ for (var _e = __values(block.paragraph.items), _f = _e.next(); !_f.done; _f = _e.next()) {
734
+ var inline = _f.value;
735
+ if (inline instanceof OpaqueParagraphItem || inline instanceof OpaqueRunItem) {
736
+ scan(inline.xml);
737
+ }
738
+ }
739
+ }
740
+ catch (e_21_1) { e_21 = { error: e_21_1 }; }
741
+ finally {
742
+ try {
743
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
744
+ }
745
+ finally { if (e_21) throw e_21.error; }
746
+ }
747
+ try {
748
+ scan(block.paragraph.toOpenXml());
749
+ }
750
+ catch (_g) {
751
+ // Detached / incomplete — live scan above is enough.
752
+ }
753
+ }
754
+ }
755
+ }
756
+ catch (e_20_1) { e_20 = { error: e_20_1 }; }
757
+ finally {
758
+ try {
759
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
760
+ }
761
+ finally { if (e_20) throw e_20.error; }
762
+ }
763
+ return ids;
764
+ }
765
+ /**
766
+ * Stage header-local image rel GC (rule 7) and package-wide media GC (rule 8)
767
+ * for one unique header after strip/rewrite.
768
+ */
769
+ function stageHeaderRelationshipGc(document, headerPartName, entry, protectedMediaKeys) {
770
+ var e_24, _a, e_25, _b;
771
+ var packageParts = packagePartsFor(document);
772
+ var referencedIds = collectReferencedRelationshipIds(entry);
773
+ try {
774
+ for (var _c = __values(packageParts.stagedHeaderRelIds(headerPartName)), _d = _c.next(); !_d.done; _d = _c.next()) {
775
+ var id = _d.value;
776
+ referencedIds.add(id);
777
+ }
778
+ }
779
+ catch (e_24_1) { e_24 = { error: e_24_1 }; }
780
+ finally {
781
+ try {
782
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
783
+ }
784
+ finally { if (e_24) throw e_24.error; }
785
+ }
786
+ packageParts.stageHeaderImageRelFilter(headerPartName, referencedIds);
787
+ var pkg = document.opcPackage();
788
+ var headerRels = relationshipsForPart(pkg, headerPartName);
789
+ try {
790
+ for (var _e = __values(headerRels.items), _f = _e.next(); !_f.done; _f = _e.next()) {
791
+ var rel = _f.value;
792
+ if (!isImageRelationshipType(rel.type)) {
793
+ continue;
794
+ }
795
+ if (referencedIds.has(rel.id)) {
796
+ continue;
797
+ }
798
+ try {
799
+ var target = resolveInternalTarget(rel.target, headerPartName);
800
+ if (protectedMediaKeys.has(partNameKey(target))) {
801
+ continue;
802
+ }
803
+ if (partByName(pkg, target) === undefined) {
804
+ continue;
805
+ }
806
+ packageParts.stageMediaRemoval(target);
807
+ }
808
+ catch (_g) {
809
+ // Invalid target — skip.
810
+ }
811
+ }
812
+ }
813
+ catch (e_25_1) { e_25 = { error: e_25_1 }; }
814
+ finally {
815
+ try {
816
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
817
+ }
818
+ finally { if (e_25) throw e_25.error; }
819
+ }
820
+ }
821
+ function vAttr(localName, value) {
822
+ return { namespaceUri: '', localName: localName, prefix: '', value: value };
823
+ }
824
+ function vElement(localName, options) {
825
+ var __ts33_0, __ts33_1, __ts33_2;
826
+ return {
827
+ kind: 'element',
828
+ namespaceUri: VML_NS,
829
+ localName: localName,
830
+ prefix: 'v',
831
+ attributes: ((__ts33_0 = options == null ? undefined : options.attributes), __ts33_0 != null ? __ts33_0 : []),
832
+ namespaceDeclarations: ((__ts33_1 = options == null ? undefined : options.namespaceDeclarations), __ts33_1 != null ? __ts33_1 : []),
833
+ children: ((__ts33_2 = options == null ? undefined : options.children), __ts33_2 != null ? __ts33_2 : []),
834
+ };
835
+ }
836
+ function formatPt(value) {
837
+ if (Number.isInteger(value)) {
838
+ return String(value);
839
+ }
840
+ // Trim excessive float noise while keeping precision for scaled sizes.
841
+ return String(Math.round(value * 1000) / 1000);
842
+ }
843
+ function textRotationDegrees(model) {
844
+ var custom = model.getCustomRotationDegrees();
845
+ if (custom !== undefined) {
846
+ return custom;
847
+ }
848
+ return model.layout === WatermarkLayout.Horizontal ? 0 : 315;
849
+ }
850
+ function textWidthHeight(model) {
851
+ return {
852
+ width: model.width != null ? model.width : TEXT_FALLBACK_WIDTH_PT,
853
+ height: model.height != null ? model.height : TEXT_FALLBACK_HEIGHT_PT,
854
+ };
855
+ }
856
+ function buildTextStyle(model) {
857
+ var _a = textWidthHeight(model), width = _a.width, height = _a.height;
858
+ var rotation = textRotationDegrees(model);
859
+ return [
860
+ 'position:absolute',
861
+ 'margin-left:0',
862
+ 'margin-top:0',
863
+ "width:" + formatPt(width) + "pt",
864
+ "height:" + formatPt(height) + "pt",
865
+ "rotation:" + formatPt(rotation),
866
+ "z-index:" + TEXT_Z_INDEX,
867
+ 'mso-position-horizontal:center',
868
+ 'mso-position-horizontal-relative:margin',
869
+ 'mso-position-vertical:center',
870
+ 'mso-position-vertical-relative:margin',
871
+ ].join(';');
872
+ }
873
+ function buildTextpathStyle(model) {
874
+ var font = model.fontName.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
875
+ return "font-family:\"" + font + "\";font-size:" + formatPt(model.size) + "pt";
876
+ }
877
+ function mergeResidualShapeAttrs(base, residual, skip) {
878
+ var e_26, _a;
879
+ if ((residual == null ? undefined : residual.extraShapeAttributes) === undefined) {
880
+ return base;
881
+ }
882
+ var out = __spread(base);
883
+ var present = new Set(base.map(function (a) { return a.localName; }));
884
+ try {
885
+ for (var _b = __values(objectEntries(residual.extraShapeAttributes)), _c = _b.next(); !_c.done; _c = _b.next()) {
886
+ var _d = __read(_c.value, 2), name_1 = _d[0], value = _d[1];
887
+ if (skip.has(name_1) || present.has(name_1)) {
888
+ continue;
889
+ }
890
+ out.push(vAttr(name_1, value));
891
+ present.add(name_1);
892
+ }
893
+ }
894
+ catch (e_26_1) { e_26 = { error: e_26_1 }; }
895
+ finally {
896
+ try {
897
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
898
+ }
899
+ finally { if (e_26) throw e_26.error; }
900
+ }
901
+ return out;
902
+ }
903
+ function residualExtraChildren(residual) {
904
+ var e_27, _a;
905
+ if ((residual == null ? undefined : residual.extraChildXml) === undefined || residual.extraChildXml.length === 0) {
906
+ return [];
907
+ }
908
+ var children = [];
909
+ try {
910
+ for (var _b = __values(residual.extraChildXml), _c = _b.next(); !_c.done; _c = _b.next()) {
911
+ var xml = _c.value;
912
+ try {
913
+ children.push(parseXml(xml));
914
+ }
915
+ catch (_d) {
916
+ // Skip unparsable residual fragments rather than fail save.
917
+ }
918
+ }
919
+ }
920
+ catch (e_27_1) { e_27 = { error: e_27_1 }; }
921
+ finally {
922
+ try {
923
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
924
+ }
925
+ finally { if (e_27) throw e_27.error; }
926
+ }
927
+ return children;
928
+ }
929
+ function buildTextPict(model, shapeId) {
930
+ var e_28, _a;
931
+ var residual = model.getParseResidual();
932
+ var skip = new Set([
933
+ 'id',
934
+ 'type',
935
+ 'style',
936
+ 'fillcolor',
937
+ 'stroked',
938
+ 'filled',
939
+ ]);
940
+ var attrs = mergeResidualShapeAttrs([
941
+ vAttr('id', shapeId),
942
+ vAttr('type', TEXT_WATERMARK_TYPE),
943
+ vAttr('style', buildTextStyle(model)),
944
+ vAttr('fillcolor', model.color),
945
+ vAttr('stroked', 'f'),
946
+ ], residual, skip);
947
+ var children = [];
948
+ // Dirty opacity: true → exact .5; false → verified full opacity="1" (overrides residual
949
+ // transparency and round-trips through parse as Opaque, not Unknown/absent).
950
+ if (model.semitransparent) {
951
+ children.push(vElement('fill', { attributes: [vAttr('opacity', '.5')] }));
952
+ }
953
+ else {
954
+ children.push(vElement('fill', { attributes: [vAttr('opacity', '1')] }));
955
+ }
956
+ children.push(vElement('textpath', {
957
+ attributes: [
958
+ vAttr('on', 't'),
959
+ vAttr('string', model.text),
960
+ vAttr('style', buildTextpathStyle(model)),
961
+ ],
962
+ }));
963
+ try {
964
+ // Residual extra children that are not fill/textpath (already owned).
965
+ for (var _b = __values(residualExtraChildren(residual)), _c = _b.next(); !_c.done; _c = _b.next()) {
966
+ var child = _c.value;
967
+ if (child.kind === 'element' && isVml(child, 'fill')) {
968
+ // Owned by dirty semitransparent path — skip residual fill when dirty controls opacity.
969
+ continue;
970
+ }
971
+ if (child.kind === 'element' && isVml(child, 'textpath')) {
972
+ continue;
973
+ }
974
+ children.push(child);
975
+ }
976
+ }
977
+ catch (e_28_1) { e_28 = { error: e_28_1 }; }
978
+ finally {
979
+ try {
980
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
981
+ }
982
+ finally { if (e_28) throw e_28.error; }
983
+ }
984
+ var shape = vElement('shape', {
985
+ attributes: attrs,
986
+ children: children,
987
+ namespaceDeclarations: [
988
+ { prefix: 'v', namespaceUri: VML_NS },
989
+ { prefix: 'o', namespaceUri: OFFICE_NS },
990
+ { prefix: 'r', namespaceUri: R_NS },
991
+ ],
992
+ });
993
+ return wmlElement('pict', { children: [shape] });
994
+ }
995
+ function pictureBaseSizePt(model) {
996
+ var bytes = model.imageData;
997
+ if (bytes !== undefined) {
998
+ var pixels = sniffImagePixelDimensions(bytes);
999
+ if (pixels !== undefined) {
1000
+ // 96 DPI: px * 72/96 = px * 0.75
1001
+ return { width: pixels.width * 0.75, height: pixels.height * 0.75 };
1002
+ }
1003
+ }
1004
+ // Fallback when dimensions unknown.
1005
+ return { width: 100, height: 100 };
1006
+ }
1007
+ /**
1008
+ * Scaling matrix (requirement):
1009
+ * - neither explicit W/H → base * scaling/100
1010
+ * - only width → width + height from aspect (no scale on width)
1011
+ * - only height → symmetric
1012
+ * - both explicit → neither scaled
1013
+ */
1014
+ function pictureWidthHeight(model) {
1015
+ var base = pictureBaseSizePt(model);
1016
+ var explicitWidth = model.width;
1017
+ var explicitHeight = model.height;
1018
+ if (explicitWidth !== undefined && explicitHeight !== undefined) {
1019
+ return { width: explicitWidth, height: explicitHeight };
1020
+ }
1021
+ if (explicitWidth !== undefined) {
1022
+ var aspect = base.height / (base.width === 0 ? 1 : base.width);
1023
+ return { width: explicitWidth, height: explicitWidth * aspect };
1024
+ }
1025
+ if (explicitHeight !== undefined) {
1026
+ var aspect = base.width / (base.height === 0 ? 1 : base.height);
1027
+ return { width: explicitHeight * aspect, height: explicitHeight };
1028
+ }
1029
+ var scale = model.scaling / 100;
1030
+ return { width: base.width * scale, height: base.height * scale };
1031
+ }
1032
+ function buildPictureStyle(model) {
1033
+ var _a = pictureWidthHeight(model), width = _a.width, height = _a.height;
1034
+ return [
1035
+ 'position:absolute',
1036
+ 'margin-left:0',
1037
+ 'margin-top:0',
1038
+ "width:" + formatPt(width) + "pt",
1039
+ "height:" + formatPt(height) + "pt",
1040
+ "z-index:" + PICTURE_Z_INDEX,
1041
+ 'mso-position-horizontal:center',
1042
+ 'mso-position-horizontal-relative:margin',
1043
+ 'mso-position-vertical:center',
1044
+ 'mso-position-vertical-relative:margin',
1045
+ ].join(';');
1046
+ }
1047
+ function resolvePictureContentType(model) {
1048
+ var bytes = model.imageData;
1049
+ if (bytes === undefined || bytes.byteLength === 0) {
1050
+ throw new DocxError('content/invalid-image', 'Picture watermark has no image bytes to serialize');
1051
+ }
1052
+ var sniffed = sniffImageContentType(bytes);
1053
+ if (sniffed !== undefined) {
1054
+ return sniffed;
1055
+ }
1056
+ if (model.imageType === ImageType.Jpeg) {
1057
+ return JPEG_CONTENT_TYPE;
1058
+ }
1059
+ if (model.imageType === ImageType.Png) {
1060
+ return PNG_CONTENT_TYPE;
1061
+ }
1062
+ throw new DocxError('content/invalid-image', 'Picture watermark image bytes are not a supported JPEG or PNG payload');
1063
+ }
1064
+ function sha256(data) {
1065
+ return sha256Hex(data);
1066
+ }
1067
+ function allocateImagePartName(contentType, used) {
1068
+ var ext = contentType === JPEG_CONTENT_TYPE ? 'jpeg' : 'png';
1069
+ var index = 1;
1070
+ while (used.has(partNameKey(partName("/word/media/image" + String(index) + "." + ext)))) {
1071
+ index += 1;
1072
+ }
1073
+ return partName("/word/media/image" + String(index) + "." + ext);
1074
+ }
1075
+ function relativeMediaTarget(partNameValue) {
1076
+ // Header is under /word/; media target is relative: media/imageN.ext
1077
+ return partNameValue.slice('/word/'.length);
1078
+ }
1079
+ function buildPicturePict(model, shapeId, imageRelId) {
1080
+ var e_29, _a;
1081
+ var residual = model.getParseResidual();
1082
+ var skip = new Set(['id', 'type', 'style', 'filled', 'stroked', 'fillcolor']);
1083
+ var attrs = mergeResidualShapeAttrs([
1084
+ vAttr('id', shapeId),
1085
+ vAttr('type', PICTURE_WATERMARK_TYPE),
1086
+ vAttr('style', buildPictureStyle(model)),
1087
+ vAttr('filled', 'f'),
1088
+ vAttr('stroked', 'f'),
1089
+ ], residual, skip);
1090
+ var imageAttrs = [
1091
+ { namespaceUri: R_NS, localName: 'id', prefix: 'r', value: imageRelId },
1092
+ { namespaceUri: OFFICE_NS, localName: 'title', prefix: 'o', value: '' },
1093
+ ];
1094
+ if (model.washout) {
1095
+ imageAttrs.push(vAttr('gain', WASHOUT_GAIN));
1096
+ imageAttrs.push(vAttr('blacklevel', WASHOUT_BLACKLEVEL));
1097
+ }
1098
+ var children = [
1099
+ vElement('imagedata', { attributes: imageAttrs }),
1100
+ ];
1101
+ try {
1102
+ for (var _b = __values(residualExtraChildren(residual)), _c = _b.next(); !_c.done; _c = _b.next()) {
1103
+ var child = _c.value;
1104
+ if (child.kind === 'element' && isVml(child, 'imagedata')) {
1105
+ continue;
1106
+ }
1107
+ children.push(child);
1108
+ }
1109
+ }
1110
+ catch (e_29_1) { e_29 = { error: e_29_1 }; }
1111
+ finally {
1112
+ try {
1113
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1114
+ }
1115
+ finally { if (e_29) throw e_29.error; }
1116
+ }
1117
+ var shape = vElement('shape', {
1118
+ attributes: attrs,
1119
+ children: children,
1120
+ namespaceDeclarations: [
1121
+ { prefix: 'v', namespaceUri: VML_NS },
1122
+ { prefix: 'o', namespaceUri: OFFICE_NS },
1123
+ { prefix: 'r', namespaceUri: R_NS },
1124
+ ],
1125
+ });
1126
+ return wmlElement('pict', { children: [shape] });
1127
+ }
1128
+ function collectUsedShapeIds(catalog) {
1129
+ var e_30, _a;
1130
+ var used = new Set();
1131
+ var _loop_3 = function (relId) {
1132
+ var e_31, _a, e_32, _b;
1133
+ var entry = catalog.entryForRelationship(relId);
1134
+ if (entry === undefined) {
1135
+ return "continue";
1136
+ }
1137
+ var scan = function (node) {
1138
+ var e_33, _a;
1139
+ if (isVml(node, 'shape')) {
1140
+ var idAttr = node.attributes.find(function (a) { return a.localName === 'id'; });
1141
+ if (idAttr !== undefined) {
1142
+ used.add(idAttr.value);
1143
+ }
1144
+ }
1145
+ try {
1146
+ for (var _b = __values(elementChildren(node)), _c = _b.next(); !_c.done; _c = _b.next()) {
1147
+ var child = _c.value;
1148
+ scan(child);
1149
+ }
1150
+ }
1151
+ catch (e_33_1) { e_33 = { error: e_33_1 }; }
1152
+ finally {
1153
+ try {
1154
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1155
+ }
1156
+ finally { if (e_33) throw e_33.error; }
1157
+ }
1158
+ };
1159
+ try {
1160
+ for (var _c = __values(entry.blocks), _d = _c.next(); !_d.done; _d = _c.next()) {
1161
+ var block = _d.value;
1162
+ if (block.type === 'opaque') {
1163
+ scan(block.xml);
1164
+ }
1165
+ else if (block.type === 'paragraph') {
1166
+ try {
1167
+ for (var _e = __values(block.paragraph.items), _f = _e.next(); !_f.done; _f = _e.next()) {
1168
+ var inline = _f.value;
1169
+ if (inline instanceof OpaqueParagraphItem || inline instanceof OpaqueRunItem) {
1170
+ scan(inline.xml);
1171
+ }
1172
+ }
1173
+ }
1174
+ catch (e_32_1) { e_32 = { error: e_32_1 }; }
1175
+ finally {
1176
+ try {
1177
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
1178
+ }
1179
+ finally { if (e_32) throw e_32.error; }
1180
+ }
1181
+ }
1182
+ }
1183
+ }
1184
+ catch (e_31_1) { e_31 = { error: e_31_1 }; }
1185
+ finally {
1186
+ try {
1187
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
1188
+ }
1189
+ finally { if (e_31) throw e_31.error; }
1190
+ }
1191
+ };
1192
+ try {
1193
+ for (var _b = __values(catalog.relationshipIds('header')), _c = _b.next(); !_c.done; _c = _b.next()) {
1194
+ var relId = _c.value;
1195
+ _loop_3(relId);
1196
+ }
1197
+ }
1198
+ catch (e_30_1) { e_30 = { error: e_30_1 }; }
1199
+ finally {
1200
+ try {
1201
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1202
+ }
1203
+ finally { if (e_30) throw e_30.error; }
1204
+ }
1205
+ return used;
1206
+ }
1207
+ function allocateShapeId(prefix, used) {
1208
+ var n = 1;
1209
+ while (used.has("" + prefix + String(n))) {
1210
+ n += 1;
1211
+ }
1212
+ var id = "" + prefix + String(n);
1213
+ used.add(id);
1214
+ return id;
1215
+ }
1216
+ function appendWatermarkPict(catalog, relationshipId, pict) {
1217
+ var paragraph = catalog.appendParagraphForRelationship(relationshipId);
1218
+ paragraph.appendParagraphItem(new OpaqueParagraphItem(pict));
1219
+ }
1220
+ function preparePictureMedia(document, model, headerPartNames) {
1221
+ var e_34, _a, e_35, _b, e_36, _c;
1222
+ var contentType = resolvePictureContentType(model);
1223
+ var data = model.imageData;
1224
+ if (data === undefined || data.byteLength === 0) {
1225
+ throw new DocxError('content/invalid-image', 'Picture watermark has no image bytes to serialize');
1226
+ }
1227
+ var pkg = document.opcPackage();
1228
+ var usedPartNames = usedPartNameKeys(document);
1229
+ // Dedupe: reuse existing media part with same hash+content type when present.
1230
+ var hash = sha256(data);
1231
+ var mediaPartName;
1232
+ try {
1233
+ for (var _d = __values(pkg.parts), _e = _d.next(); !_e.done; _e = _d.next()) {
1234
+ var part = _e.value;
1235
+ if (part.contentType !== contentType) {
1236
+ continue;
1237
+ }
1238
+ if (!String(part.name).includes('/word/media/')) {
1239
+ continue;
1240
+ }
1241
+ if (part.data.byteLength === data.byteLength && sha256(part.data) === hash) {
1242
+ mediaPartName = part.name;
1243
+ break;
1244
+ }
1245
+ }
1246
+ }
1247
+ catch (e_34_1) { e_34 = { error: e_34_1 }; }
1248
+ finally {
1249
+ try {
1250
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
1251
+ }
1252
+ finally { if (e_34) throw e_34.error; }
1253
+ }
1254
+ var packageParts = packagePartsFor(document);
1255
+ if (mediaPartName === undefined) {
1256
+ mediaPartName = allocateImagePartName(contentType, usedPartNames);
1257
+ usedPartNames.add(partNameKey(mediaPartName));
1258
+ packageParts.stageMedia({ partName: mediaPartName, contentType: contentType, data: data });
1259
+ }
1260
+ var relIdByHeaderPartKey = new Map();
1261
+ var target = relativeMediaTarget(mediaPartName);
1262
+ try {
1263
+ for (var headerPartNames_1 = __values(headerPartNames), headerPartNames_1_1 = headerPartNames_1.next(); !headerPartNames_1_1.done; headerPartNames_1_1 = headerPartNames_1.next()) {
1264
+ var headerPartName = headerPartNames_1_1.value;
1265
+ var key = partNameKey(headerPartName);
1266
+ if (relIdByHeaderPartKey.has(key)) {
1267
+ continue;
1268
+ }
1269
+ var existingRels = relationshipsForPart(pkg, headerPartName);
1270
+ var match = existingRels.items.find(function (r) { return r.type === IMAGE_RELATIONSHIP_TYPE && r.target === target; });
1271
+ var relId = void 0;
1272
+ if (match !== undefined) {
1273
+ relId = match.id;
1274
+ }
1275
+ else {
1276
+ var used = new Set(existingRels.items.map(function (r) { return r.id; }));
1277
+ try {
1278
+ // Also reserve ids already staged for this header.
1279
+ for (var _f = __values(relIdByHeaderPartKey.values()), _g = _f.next(); !_g.done; _g = _f.next()) {
1280
+ var id = _g.value;
1281
+ used.add(id);
1282
+ }
1283
+ }
1284
+ catch (e_36_1) { e_36 = { error: e_36_1 }; }
1285
+ finally {
1286
+ try {
1287
+ if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
1288
+ }
1289
+ finally { if (e_36) throw e_36.error; }
1290
+ }
1291
+ relId = allocateRelationshipId(used);
1292
+ var relationship = {
1293
+ id: relId,
1294
+ type: IMAGE_RELATIONSHIP_TYPE,
1295
+ target: target,
1296
+ extraAttributes: [],
1297
+ children: [],
1298
+ };
1299
+ packageParts.stageHeaderRel(headerPartName, relationship);
1300
+ }
1301
+ relIdByHeaderPartKey.set(key, relId);
1302
+ }
1303
+ }
1304
+ catch (e_35_1) { e_35 = { error: e_35_1 }; }
1305
+ finally {
1306
+ try {
1307
+ if (headerPartNames_1_1 && !headerPartNames_1_1.done && (_b = headerPartNames_1.return)) _b.call(headerPartNames_1);
1308
+ }
1309
+ finally { if (e_35) throw e_35.error; }
1310
+ }
1311
+ return { relIdByHeaderPartKey: relIdByHeaderPartKey, contentType: contentType, data: data, mediaPartName: mediaPartName };
1312
+ }
1313
+ function uniqueHeaderEntries(document, catalog) {
1314
+ var e_37, _a, e_38, _b;
1315
+ var seen = new Set();
1316
+ var out = [];
1317
+ try {
1318
+ for (var _c = __values(sectionPropertiesInDocumentOrder(document)), _d = _c.next(); !_d.done; _d = _c.next()) {
1319
+ var props = _d.value;
1320
+ try {
1321
+ for (var HEADER_REF_TYPES_2 = __values(HEADER_REF_TYPES), HEADER_REF_TYPES_2_1 = HEADER_REF_TYPES_2.next(); !HEADER_REF_TYPES_2_1.done; HEADER_REF_TYPES_2_1 = HEADER_REF_TYPES_2.next()) {
1322
+ var refType = HEADER_REF_TYPES_2_1.value;
1323
+ var relId = props.headerFooterReferenceId('header', refType);
1324
+ if (relId === undefined) {
1325
+ continue;
1326
+ }
1327
+ var entry = catalog.entryForRelationship(relId);
1328
+ if (entry === undefined) {
1329
+ continue;
1330
+ }
1331
+ var key = partNameKey(entry.partName);
1332
+ if (seen.has(key)) {
1333
+ continue;
1334
+ }
1335
+ seen.add(key);
1336
+ out.push({ relationshipId: relId, partName: entry.partName });
1337
+ }
1338
+ }
1339
+ catch (e_38_1) { e_38 = { error: e_38_1 }; }
1340
+ finally {
1341
+ try {
1342
+ if (HEADER_REF_TYPES_2_1 && !HEADER_REF_TYPES_2_1.done && (_b = HEADER_REF_TYPES_2.return)) _b.call(HEADER_REF_TYPES_2);
1343
+ }
1344
+ finally { if (e_38) throw e_38.error; }
1345
+ }
1346
+ }
1347
+ }
1348
+ catch (e_37_1) { e_37 = { error: e_37_1 }; }
1349
+ finally {
1350
+ try {
1351
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
1352
+ }
1353
+ finally { if (e_37) throw e_37.error; }
1354
+ }
1355
+ return out;
1356
+ }
1357
+ /**
1358
+ * Materialize dirty logical watermark into header parts.
1359
+ *
1360
+ * Called from the feature materialize handler before multi-part apply.
1361
+ *
1362
+ * - Assign/replace (`logical` defined): ensure scratch headers, strip recognized
1363
+ * watermark leaves, append canonical text/picture markup, stage image-rel/media GC.
1364
+ * - Remove (`logical` undefined): strip recognized watermark leaves from existing
1365
+ * unique headers only (no new scratch headers), stage GC (Removal 1–10).
1366
+ *
1367
+ * @private
1368
+ */
1369
+ export function materializeWatermarks(document) {
1370
+ var e_39, _a, e_40, _b, e_41, _c, e_42, _d, e_43, _e, e_44, _f;
1371
+ var __ts33_3;
1372
+ if (!isWatermarkDirty(document)) {
1373
+ return;
1374
+ }
1375
+ var catalog;
1376
+ try {
1377
+ catalog = headersFootersFor(document);
1378
+ }
1379
+ catch (_g) {
1380
+ // HF not registered — cannot materialize; leave dirty for honest failure on save paths that need it.
1381
+ return;
1382
+ }
1383
+ var logical = logicalWatermarkOf(document);
1384
+ // Assign/replace needs scratch headers; remove-only rewrites existing headers.
1385
+ if (logical !== undefined) {
1386
+ ensureScratchHeaders(document, catalog);
1387
+ }
1388
+ var headers = uniqueHeaderEntries(document, catalog);
1389
+ var usedShapeIds = collectUsedShapeIds(catalog);
1390
+ var protectedMediaKeys = new Set();
1391
+ try {
1392
+ // Strip recognized watermark leaves from each unique header once.
1393
+ for (var headers_1 = __values(headers), headers_1_1 = headers_1.next(); !headers_1_1.done; headers_1_1 = headers_1.next()) {
1394
+ var header = headers_1_1.value;
1395
+ var entry = catalog.entryForRelationship(header.relationshipId);
1396
+ if (entry === undefined) {
1397
+ continue;
1398
+ }
1399
+ stripEntryWatermarkLeaves(entry);
1400
+ }
1401
+ }
1402
+ catch (e_39_1) { e_39 = { error: e_39_1 }; }
1403
+ finally {
1404
+ try {
1405
+ if (headers_1_1 && !headers_1_1.done && (_a = headers_1.return)) _a.call(headers_1);
1406
+ }
1407
+ finally { if (e_39) throw e_39.error; }
1408
+ }
1409
+ if (logical === undefined) {
1410
+ try {
1411
+ // Remove path: strip + GC only (rules 1–10); never delete header parts (rule 9).
1412
+ for (var headers_2 = __values(headers), headers_2_1 = headers_2.next(); !headers_2_1.done; headers_2_1 = headers_2.next()) {
1413
+ var header = headers_2_1.value;
1414
+ var entry = catalog.entryForRelationship(header.relationshipId);
1415
+ if (entry === undefined) {
1416
+ continue;
1417
+ }
1418
+ stageHeaderRelationshipGc(document, header.partName, entry, protectedMediaKeys);
1419
+ }
1420
+ }
1421
+ catch (e_40_1) { e_40 = { error: e_40_1 }; }
1422
+ finally {
1423
+ try {
1424
+ if (headers_2_1 && !headers_2_1.done && (_b = headers_2.return)) _b.call(headers_2);
1425
+ }
1426
+ finally { if (e_40) throw e_40.error; }
1427
+ }
1428
+ clearWatermarkDirty(document);
1429
+ return;
1430
+ }
1431
+ if (logical.type === WatermarkType.TextWatermark) {
1432
+ var text = logical;
1433
+ try {
1434
+ for (var headers_3 = __values(headers), headers_3_1 = headers_3.next(); !headers_3_1.done; headers_3_1 = headers_3.next()) {
1435
+ var header = headers_3_1.value;
1436
+ var shapeId = allocateShapeId(TEXT_WATERMARK_ID_PREFIX, usedShapeIds);
1437
+ var pict = buildTextPict(text, shapeId);
1438
+ appendWatermarkPict(catalog, header.relationshipId, pict);
1439
+ }
1440
+ }
1441
+ catch (e_41_1) { e_41 = { error: e_41_1 }; }
1442
+ finally {
1443
+ try {
1444
+ if (headers_3_1 && !headers_3_1.done && (_c = headers_3.return)) _c.call(headers_3);
1445
+ }
1446
+ finally { if (e_41) throw e_41.error; }
1447
+ }
1448
+ try {
1449
+ for (var headers_4 = __values(headers), headers_4_1 = headers_4.next(); !headers_4_1.done; headers_4_1 = headers_4.next()) {
1450
+ var header = headers_4_1.value;
1451
+ var entry = catalog.entryForRelationship(header.relationshipId);
1452
+ if (entry === undefined) {
1453
+ continue;
1454
+ }
1455
+ stageHeaderRelationshipGc(document, header.partName, entry, protectedMediaKeys);
1456
+ }
1457
+ }
1458
+ catch (e_42_1) { e_42 = { error: e_42_1 }; }
1459
+ finally {
1460
+ try {
1461
+ if (headers_4_1 && !headers_4_1.done && (_d = headers_4.return)) _d.call(headers_4);
1462
+ }
1463
+ finally { if (e_42) throw e_42.error; }
1464
+ }
1465
+ clearWatermarkDirty(document);
1466
+ return;
1467
+ }
1468
+ // Only remaining public watermark kind is picture (WatermarkType.PictureWatermark).
1469
+ var picture = logical;
1470
+ var media = preparePictureMedia(document, picture, headers.map(function (h) { return h.partName; }));
1471
+ protectedMediaKeys.add(partNameKey(media.mediaPartName));
1472
+ try {
1473
+ for (var headers_5 = __values(headers), headers_5_1 = headers_5.next(); !headers_5_1.done; headers_5_1 = headers_5.next()) {
1474
+ var header = headers_5_1.value;
1475
+ var shapeId = allocateShapeId(PICTURE_WATERMARK_ID_PREFIX, usedShapeIds);
1476
+ var relId = ((__ts33_3 = media.relIdByHeaderPartKey.get(partNameKey(header.partName))), __ts33_3 != null ? __ts33_3 : media.relIdByHeaderPartKey.values().next().value);
1477
+ if (relId === undefined) {
1478
+ throw new DocxError('content/invalid-image', 'Picture watermark failed to allocate a header image relationship');
1479
+ }
1480
+ var pict = buildPicturePict(picture, shapeId, relId);
1481
+ appendWatermarkPict(catalog, header.relationshipId, pict);
1482
+ }
1483
+ }
1484
+ catch (e_43_1) { e_43 = { error: e_43_1 }; }
1485
+ finally {
1486
+ try {
1487
+ if (headers_5_1 && !headers_5_1.done && (_e = headers_5.return)) _e.call(headers_5);
1488
+ }
1489
+ finally { if (e_43) throw e_43.error; }
1490
+ }
1491
+ try {
1492
+ for (var headers_6 = __values(headers), headers_6_1 = headers_6.next(); !headers_6_1.done; headers_6_1 = headers_6.next()) {
1493
+ var header = headers_6_1.value;
1494
+ var entry = catalog.entryForRelationship(header.relationshipId);
1495
+ if (entry === undefined) {
1496
+ continue;
1497
+ }
1498
+ stageHeaderRelationshipGc(document, header.partName, entry, protectedMediaKeys);
1499
+ }
1500
+ }
1501
+ catch (e_44_1) { e_44 = { error: e_44_1 }; }
1502
+ finally {
1503
+ try {
1504
+ if (headers_6_1 && !headers_6_1.done && (_f = headers_6.return)) _f.call(headers_6);
1505
+ }
1506
+ finally { if (e_44) throw e_44.error; }
1507
+ }
1508
+ clearWatermarkDirty(document);
1509
+ }
1510
+ /**
1511
+ * Load empty/clean package parts for registration.
1512
+ * @private
1513
+ */
1514
+ export function loadWatermarkPackageParts(_pkg) {
1515
+ void _pkg;
1516
+ return new WatermarkPackageParts();
1517
+ }