@syncfusion/ej2-docx 0.0.0-stage → 35.1.40

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 (417) hide show
  1. package/.gitleaksignore +35 -0
  2. package/README.md +68 -2
  3. package/core.js +4 -0
  4. package/dist/ej2-docx.umd.min.js +11 -0
  5. package/dist/ej2-docx.umd.min.js.map +1 -0
  6. package/dist/es6/ej2-docx.es2015.js +66697 -0
  7. package/dist/es6/ej2-docx.es2015.js.map +1 -0
  8. package/dist/es6/ej2-docx.es5.js +77568 -0
  9. package/dist/es6/ej2-docx.es5.js.map +1 -0
  10. package/dist/global/ej2-docx.min.js +11 -0
  11. package/dist/global/ej2-docx.min.js.map +1 -0
  12. package/dist/global/index.d.ts +14 -0
  13. package/features.js +4 -0
  14. package/index.js +4 -0
  15. package/license +10 -0
  16. package/package.json +30 -3
  17. package/src/all.d.ts +50 -0
  18. package/src/all.js +147 -0
  19. package/src/core/compat/base64.d.ts +13 -0
  20. package/src/core/compat/base64.js +90 -0
  21. package/src/core/compat/object-compat.d.ts +30 -0
  22. package/src/core/compat/object-compat.js +40 -0
  23. package/src/core/compat/sha256.d.ts +9 -0
  24. package/src/core/compat/sha256.js +98 -0
  25. package/src/core/errors/docx-error.d.ts +89 -0
  26. package/src/core/errors/docx-error.js +138 -0
  27. package/src/core/errors/error-codes.d.ts +8 -0
  28. package/src/core/errors/error-codes.js +0 -0
  29. package/src/core/errors/index.d.ts +10 -0
  30. package/src/core/errors/index.js +9 -0
  31. package/src/core/index.d.ts +12 -0
  32. package/src/core/index.js +12 -0
  33. package/src/core/mc/alternate-content.d.ts +7 -0
  34. package/src/core/mc/alternate-content.js +67 -0
  35. package/src/core/mc/attributes.d.ts +24 -0
  36. package/src/core/mc/attributes.js +82 -0
  37. package/src/core/mc/index.d.ts +7 -0
  38. package/src/core/mc/index.js +5 -0
  39. package/src/core/mc/inspect.d.ts +16 -0
  40. package/src/core/mc/inspect.js +148 -0
  41. package/src/core/mc/namespaces.d.ts +4 -0
  42. package/src/core/mc/namespaces.js +4 -0
  43. package/src/core/mc/scope.d.ts +6 -0
  44. package/src/core/mc/scope.js +47 -0
  45. package/src/core/opc/content-types.d.ts +34 -0
  46. package/src/core/opc/content-types.js +162 -0
  47. package/src/core/opc/index.d.ts +8 -0
  48. package/src/core/opc/index.js +4 -0
  49. package/src/core/opc/package.d.ts +49 -0
  50. package/src/core/opc/package.js +324 -0
  51. package/src/core/opc/part-name.d.ts +47 -0
  52. package/src/core/opc/part-name.js +205 -0
  53. package/src/core/opc/relationships.d.ts +46 -0
  54. package/src/core/opc/relationships.js +212 -0
  55. package/src/core/preservation/index.d.ts +2 -0
  56. package/src/core/preservation/index.js +1 -0
  57. package/src/core/preservation/opaque-body.d.ts +16 -0
  58. package/src/core/preservation/opaque-body.js +69 -0
  59. package/src/core/registry/block-handlers.d.ts +30 -0
  60. package/src/core/registry/block-handlers.js +36 -0
  61. package/src/core/registry/create-defaults.d.ts +39 -0
  62. package/src/core/registry/create-defaults.js +42 -0
  63. package/src/core/registry/feature-registry.d.ts +20 -0
  64. package/src/core/registry/feature-registry.js +29 -0
  65. package/src/core/registry/index.d.ts +9 -0
  66. package/src/core/registry/index.js +8 -0
  67. package/src/core/registry/inline-handlers.d.ts +20 -0
  68. package/src/core/registry/inline-handlers.js +30 -0
  69. package/src/core/registry/materialize-handlers.d.ts +35 -0
  70. package/src/core/registry/materialize-handlers.js +75 -0
  71. package/src/core/registry/multi-part-handlers.d.ts +37 -0
  72. package/src/core/registry/multi-part-handlers.js +206 -0
  73. package/src/core/registry/package-part-handlers.d.ts +28 -0
  74. package/src/core/registry/package-part-handlers.js +190 -0
  75. package/src/core/registry/part-handlers.d.ts +24 -0
  76. package/src/core/registry/part-handlers.js +172 -0
  77. package/src/core/registry/run-leaf-handlers.d.ts +26 -0
  78. package/src/core/registry/run-leaf-handlers.js +72 -0
  79. package/src/core/security/limits.d.ts +40 -0
  80. package/src/core/security/limits.js +26 -0
  81. package/src/core/xml/index.d.ts +7 -0
  82. package/src/core/xml/index.js +3 -0
  83. package/src/core/xml/model.d.ts +66 -0
  84. package/src/core/xml/model.js +17 -0
  85. package/src/core/xml/parse.d.ts +12 -0
  86. package/src/core/xml/parse.js +382 -0
  87. package/src/core/xml/serialize.d.ts +6 -0
  88. package/src/core/xml/serialize.js +93 -0
  89. package/src/core/zip/crc32.d.ts +2 -0
  90. package/src/core/zip/crc32.js +25 -0
  91. package/src/core/zip/deflate.d.ts +6 -0
  92. package/src/core/zip/deflate.js +6 -0
  93. package/src/core/zip/index.d.ts +10 -0
  94. package/src/core/zip/index.js +4 -0
  95. package/src/core/zip/inflate-raw.d.ts +17 -0
  96. package/src/core/zip/inflate-raw.js +450 -0
  97. package/src/core/zip/names.d.ts +6 -0
  98. package/src/core/zip/names.js +52 -0
  99. package/src/core/zip/read.d.ts +8 -0
  100. package/src/core/zip/read.js +262 -0
  101. package/src/core/zip/write.d.ts +7 -0
  102. package/src/core/zip/write.js +189 -0
  103. package/src/core/zip/zip-entry.d.ts +4 -0
  104. package/src/core/zip/zip-entry.js +0 -0
  105. package/src/features/bibliography/index.d.ts +100 -0
  106. package/src/features/bibliography/index.js +290 -0
  107. package/src/features/bookmarks/index.d.ts +331 -0
  108. package/src/features/bookmarks/index.js +1009 -0
  109. package/src/features/comments/comment-extensions.d.ts +157 -0
  110. package/src/features/comments/comment-extensions.js +356 -0
  111. package/src/features/comments/index.d.ts +579 -0
  112. package/src/features/comments/index.js +1727 -0
  113. package/src/features/content-controls/index.d.ts +821 -0
  114. package/src/features/content-controls/index.js +2857 -0
  115. package/src/features/custom-xml/index.d.ts +236 -0
  116. package/src/features/custom-xml/index.js +661 -0
  117. package/src/features/document/alignment.d.ts +23 -0
  118. package/src/features/document/alignment.js +36 -0
  119. package/src/features/document/alt-chunk.d.ts +103 -0
  120. package/src/features/document/alt-chunk.js +221 -0
  121. package/src/features/document/assert-never.d.ts +1 -0
  122. package/src/features/document/assert-never.js +4 -0
  123. package/src/features/document/augmentations.d.ts +578 -0
  124. package/src/features/document/augmentations.js +0 -0
  125. package/src/features/document/body-always-on.d.ts +36 -0
  126. package/src/features/document/body-always-on.js +66 -0
  127. package/src/features/document/body-blocks.d.ts +7 -0
  128. package/src/features/document/body-blocks.js +78 -0
  129. package/src/features/document/body-item-adapters.d.ts +62 -0
  130. package/src/features/document/body-item-adapters.js +97 -0
  131. package/src/features/document/body-item-collection.d.ts +151 -0
  132. package/src/features/document/body-item-collection.js +440 -0
  133. package/src/features/document/body-item.d.ts +35 -0
  134. package/src/features/document/body-item.js +8 -0
  135. package/src/features/document/body.d.ts +150 -0
  136. package/src/features/document/body.js +263 -0
  137. package/src/features/document/character-format.d.ts +413 -0
  138. package/src/features/document/character-format.js +2054 -0
  139. package/src/features/document/color.d.ts +178 -0
  140. package/src/features/document/color.js +495 -0
  141. package/src/features/document/document.d.ts +410 -0
  142. package/src/features/document/document.js +1049 -0
  143. package/src/features/document/element-type.d.ts +68 -0
  144. package/src/features/document/element-type.js +133 -0
  145. package/src/features/document/entity-type.d.ts +92 -0
  146. package/src/features/document/entity-type.js +93 -0
  147. package/src/features/document/feature-block.d.ts +16 -0
  148. package/src/features/document/feature-block.js +0 -0
  149. package/src/features/document/feature-inline.d.ts +13 -0
  150. package/src/features/document/feature-inline.js +0 -0
  151. package/src/features/document/feature-multi-package-part.d.ts +19 -0
  152. package/src/features/document/feature-multi-package-part.js +8 -0
  153. package/src/features/document/feature-package-level-part.d.ts +18 -0
  154. package/src/features/document/feature-package-level-part.js +8 -0
  155. package/src/features/document/feature-package-part.d.ts +14 -0
  156. package/src/features/document/feature-package-part.js +0 -0
  157. package/src/features/document/feature-run-leaf.d.ts +9 -0
  158. package/src/features/document/feature-run-leaf.js +0 -0
  159. package/src/features/document/headers-footers.d.ts +206 -0
  160. package/src/features/document/headers-footers.js +384 -0
  161. package/src/features/document/index.d.ts +41 -0
  162. package/src/features/document/index.js +34 -0
  163. package/src/features/document/length.d.ts +152 -0
  164. package/src/features/document/length.js +245 -0
  165. package/src/features/document/load-options.d.ts +14 -0
  166. package/src/features/document/load-options.js +0 -0
  167. package/src/features/document/locale-ids.d.ts +227 -0
  168. package/src/features/document/locale-ids.js +485 -0
  169. package/src/features/document/on-off.d.ts +9 -0
  170. package/src/features/document/on-off.js +27 -0
  171. package/src/features/document/page-setup.d.ts +339 -0
  172. package/src/features/document/page-setup.js +244 -0
  173. package/src/features/document/paragraph-format.d.ts +880 -0
  174. package/src/features/document/paragraph-format.js +2807 -0
  175. package/src/features/document/paragraph-item-collection.d.ts +162 -0
  176. package/src/features/document/paragraph-item-collection.js +363 -0
  177. package/src/features/document/paragraph-item.d.ts +83 -0
  178. package/src/features/document/paragraph-item.js +103 -0
  179. package/src/features/document/paragraph.d.ts +435 -0
  180. package/src/features/document/paragraph.js +888 -0
  181. package/src/features/document/run.d.ts +1 -0
  182. package/src/features/document/run.js +768 -0
  183. package/src/features/document/section-partition-flatten.d.ts +124 -0
  184. package/src/features/document/section-partition-flatten.js +217 -0
  185. package/src/features/document/section-properties-model.d.ts +13 -0
  186. package/src/features/document/section-properties-model.js +0 -0
  187. package/src/features/document/section.d.ts +93 -0
  188. package/src/features/document/section.js +178 -0
  189. package/src/features/document/sections.d.ts +103 -0
  190. package/src/features/document/sections.js +217 -0
  191. package/src/features/document/sub-super-script.d.ts +23 -0
  192. package/src/features/document/sub-super-script.js +43 -0
  193. package/src/features/document/text-range.d.ts +445 -0
  194. package/src/features/document/text-range.js +1156 -0
  195. package/src/features/document/typed-body-collections.d.ts +162 -0
  196. package/src/features/document/typed-body-collections.js +371 -0
  197. package/src/features/document/underline-style.d.ts +38 -0
  198. package/src/features/document/underline-style.js +126 -0
  199. package/src/features/document/units.d.ts +8 -0
  200. package/src/features/document/units.js +7 -0
  201. package/src/features/document/wml.d.ts +16 -0
  202. package/src/features/document/wml.js +67 -0
  203. package/src/features/drawing/authoring.d.ts +27 -0
  204. package/src/features/drawing/authoring.js +271 -0
  205. package/src/features/drawing/body-pr.d.ts +271 -0
  206. package/src/features/drawing/body-pr.js +663 -0
  207. package/src/features/drawing/drawing-shape.d.ts +1192 -0
  208. package/src/features/drawing/drawing-shape.js +3239 -0
  209. package/src/features/drawing/encode-builders.d.ts +176 -0
  210. package/src/features/drawing/encode-builders.js +390 -0
  211. package/src/features/drawing/fill-format.d.ts +52 -0
  212. package/src/features/drawing/fill-format.js +124 -0
  213. package/src/features/drawing/host-codec.d.ts +632 -0
  214. package/src/features/drawing/host-codec.js +2595 -0
  215. package/src/features/drawing/index.d.ts +13 -0
  216. package/src/features/drawing/index.js +33 -0
  217. package/src/features/drawing/line-format.d.ts +76 -0
  218. package/src/features/drawing/line-format.js +343 -0
  219. package/src/features/drawing/parse-register.d.ts +50 -0
  220. package/src/features/drawing/parse-register.js +257 -0
  221. package/src/features/drawing/residual-utils.d.ts +47 -0
  222. package/src/features/drawing/residual-utils.js +290 -0
  223. package/src/features/drawing/shape-types.d.ts +433 -0
  224. package/src/features/drawing/shape-types.js +437 -0
  225. package/src/features/drawing/sp-pr.d.ts +396 -0
  226. package/src/features/drawing/sp-pr.js +610 -0
  227. package/src/features/drawing/text-frame.d.ts +90 -0
  228. package/src/features/drawing/text-frame.js +152 -0
  229. package/src/features/drawing/types.d.ts +352 -0
  230. package/src/features/drawing/types.js +60 -0
  231. package/src/features/drawing/wrap-format.d.ts +62 -0
  232. package/src/features/drawing/wrap-format.js +114 -0
  233. package/src/features/editable-ranges/index.d.ts +494 -0
  234. package/src/features/editable-ranges/index.js +1348 -0
  235. package/src/features/fields/index.d.ts +428 -0
  236. package/src/features/fields/index.js +2148 -0
  237. package/src/features/fields/paragraph-field.d.ts +187 -0
  238. package/src/features/fields/paragraph-field.js +692 -0
  239. package/src/features/font-table/font-substitution-table.d.ts +75 -0
  240. package/src/features/font-table/font-substitution-table.js +257 -0
  241. package/src/features/font-table/font-table-entry.d.ts +255 -0
  242. package/src/features/font-table/font-table-entry.js +823 -0
  243. package/src/features/font-table/font-table.d.ts +128 -0
  244. package/src/features/font-table/font-table.js +313 -0
  245. package/src/features/font-table/index.d.ts +27 -0
  246. package/src/features/font-table/index.js +48 -0
  247. package/src/features/glossary/index.d.ts +97 -0
  248. package/src/features/glossary/index.js +286 -0
  249. package/src/features/headers-footers/index.d.ts +506 -0
  250. package/src/features/headers-footers/index.js +1666 -0
  251. package/src/features/hyperlinks/index.d.ts +230 -0
  252. package/src/features/hyperlinks/index.js +685 -0
  253. package/src/features/images/caption-authoring-api.d.ts +33 -0
  254. package/src/features/images/caption-authoring-api.js +33 -0
  255. package/src/features/images/caption-enums.d.ts +52 -0
  256. package/src/features/images/caption-enums.js +141 -0
  257. package/src/features/images/caption-host.d.ts +10 -0
  258. package/src/features/images/caption-host.js +21 -0
  259. package/src/features/images/captions.d.ts +13 -0
  260. package/src/features/images/captions.js +142 -0
  261. package/src/features/images/host-codec.d.ts +103 -0
  262. package/src/features/images/host-codec.js +720 -0
  263. package/src/features/images/image-sniff.d.ts +21 -0
  264. package/src/features/images/image-sniff.js +71 -0
  265. package/src/features/images/index.d.ts +506 -0
  266. package/src/features/images/index.js +1429 -0
  267. package/src/features/images/layout-types.d.ts +232 -0
  268. package/src/features/images/layout-types.js +294 -0
  269. package/src/features/images/public-entry.d.ts +9 -0
  270. package/src/features/images/public-entry.js +9 -0
  271. package/src/features/index.d.ts +35 -0
  272. package/src/features/index.js +36 -0
  273. package/src/features/mail-merge/index.d.ts +113 -0
  274. package/src/features/mail-merge/index.js +315 -0
  275. package/src/features/notes/index.d.ts +573 -0
  276. package/src/features/notes/index.js +1725 -0
  277. package/src/features/numbering/abstract-numbering.d.ts +90 -0
  278. package/src/features/numbering/abstract-numbering.js +292 -0
  279. package/src/features/numbering/index.d.ts +182 -0
  280. package/src/features/numbering/index.js +668 -0
  281. package/src/features/numbering/list-format.d.ts +158 -0
  282. package/src/features/numbering/list-format.js +590 -0
  283. package/src/features/numbering/list-string.d.ts +7 -0
  284. package/src/features/numbering/list-string.js +423 -0
  285. package/src/features/numbering/list-style.d.ts +204 -0
  286. package/src/features/numbering/list-style.js +1084 -0
  287. package/src/features/numbering/numbering-instance.d.ts +101 -0
  288. package/src/features/numbering/numbering-instance.js +329 -0
  289. package/src/features/numbering/numbering-level.d.ts +118 -0
  290. package/src/features/numbering/numbering-level.js +501 -0
  291. package/src/features/numbering/picture-bullet.d.ts +34 -0
  292. package/src/features/numbering/picture-bullet.js +88 -0
  293. package/src/features/ole-object/catalog.d.ts +300 -0
  294. package/src/features/ole-object/catalog.js +908 -0
  295. package/src/features/ole-object/index.d.ts +526 -0
  296. package/src/features/ole-object/index.js +1421 -0
  297. package/src/features/ole-object/relationship.d.ts +27 -0
  298. package/src/features/ole-object/relationship.js +27 -0
  299. package/src/features/ole-object/typed-dom.d.ts +186 -0
  300. package/src/features/ole-object/typed-dom.js +595 -0
  301. package/src/features/properties/index.d.ts +205 -0
  302. package/src/features/properties/index.js +549 -0
  303. package/src/features/revisions/index.d.ts +204 -0
  304. package/src/features/revisions/index.js +695 -0
  305. package/src/features/sections/column-collection.d.ts +119 -0
  306. package/src/features/sections/column-collection.js +478 -0
  307. package/src/features/sections/column.d.ts +15 -0
  308. package/src/features/sections/column.js +37 -0
  309. package/src/features/sections/index.d.ts +91 -0
  310. package/src/features/sections/index.js +1096 -0
  311. package/src/features/sections/margins.d.ts +40 -0
  312. package/src/features/sections/margins.js +105 -0
  313. package/src/features/sections/page-number-style.d.ts +21 -0
  314. package/src/features/sections/page-number-style.js +62 -0
  315. package/src/features/sections/page-orientation.d.ts +10 -0
  316. package/src/features/sections/page-orientation.js +10 -0
  317. package/src/features/sections/page-setup.d.ts +435 -0
  318. package/src/features/sections/page-setup.js +1479 -0
  319. package/src/features/sections/page-size.d.ts +59 -0
  320. package/src/features/sections/page-size.js +68 -0
  321. package/src/features/sections/section-break-code.d.ts +27 -0
  322. package/src/features/sections/section-break-code.js +60 -0
  323. package/src/features/sections/section-document-association.d.ts +18 -0
  324. package/src/features/sections/section-document-association.js +31 -0
  325. package/src/features/sections/section-validation.d.ts +43 -0
  326. package/src/features/sections/section-validation.js +97 -0
  327. package/src/features/settings/attached-template.d.ts +35 -0
  328. package/src/features/settings/attached-template.js +98 -0
  329. package/src/features/settings/compat-settings.d.ts +216 -0
  330. package/src/features/settings/compat-settings.js +508 -0
  331. package/src/features/settings/document-background.d.ts +59 -0
  332. package/src/features/settings/document-background.js +131 -0
  333. package/src/features/settings/document-protection.d.ts +65 -0
  334. package/src/features/settings/document-protection.js +157 -0
  335. package/src/features/settings/document-settings-facades.d.ts +108 -0
  336. package/src/features/settings/document-settings-facades.js +312 -0
  337. package/src/features/settings/document-settings-values.d.ts +43 -0
  338. package/src/features/settings/document-settings-values.js +60 -0
  339. package/src/features/settings/footnote-properties.d.ts +211 -0
  340. package/src/features/settings/footnote-properties.js +591 -0
  341. package/src/features/settings/index.d.ts +356 -0
  342. package/src/features/settings/index.js +829 -0
  343. package/src/features/settings/settings-children.d.ts +151 -0
  344. package/src/features/settings/settings-children.js +505 -0
  345. package/src/features/settings/web-settings.d.ts +88 -0
  346. package/src/features/settings/web-settings.js +227 -0
  347. package/src/features/settings/zoom.d.ts +79 -0
  348. package/src/features/settings/zoom.js +147 -0
  349. package/src/features/styles/builtin-catalog.d.ts +159 -0
  350. package/src/features/styles/builtin-catalog.js +963 -0
  351. package/src/features/styles/builtin-resolver.d.ts +49 -0
  352. package/src/features/styles/builtin-resolver.js +165 -0
  353. package/src/features/styles/default-styles.d.ts +37 -0
  354. package/src/features/styles/default-styles.js +186 -0
  355. package/src/features/styles/default-theme.d.ts +13 -0
  356. package/src/features/styles/default-theme.js +13 -0
  357. package/src/features/styles/doc-defaults.d.ts +58 -0
  358. package/src/features/styles/doc-defaults.js +178 -0
  359. package/src/features/styles/formatting-resolver.d.ts +27 -0
  360. package/src/features/styles/formatting-resolver.js +72 -0
  361. package/src/features/styles/index.d.ts +256 -0
  362. package/src/features/styles/index.js +1325 -0
  363. package/src/features/styles/latent-styles.d.ts +68 -0
  364. package/src/features/styles/latent-styles.js +305 -0
  365. package/src/features/styles/paragraph-properties.d.ts +71 -0
  366. package/src/features/styles/paragraph-properties.js +237 -0
  367. package/src/features/styles/run-properties.d.ts +93 -0
  368. package/src/features/styles/run-properties.js +516 -0
  369. package/src/features/styles/style-base.d.ts +402 -0
  370. package/src/features/styles/style-base.js +1026 -0
  371. package/src/features/styles/style-collection.d.ts +264 -0
  372. package/src/features/styles/style-collection.js +714 -0
  373. package/src/features/styles/style-format-bridge.d.ts +64 -0
  374. package/src/features/styles/style-format-bridge.js +100 -0
  375. package/src/features/styles/style.d.ts +84 -0
  376. package/src/features/styles/style.js +375 -0
  377. package/src/features/styles/styles-with-effects.d.ts +71 -0
  378. package/src/features/styles/styles-with-effects.js +180 -0
  379. package/src/features/styles/table-style.d.ts +272 -0
  380. package/src/features/styles/table-style.js +1226 -0
  381. package/src/features/styles/theme.d.ts +126 -0
  382. package/src/features/styles/theme.js +377 -0
  383. package/src/features/tables/border-style-map.d.ts +24 -0
  384. package/src/features/tables/border-style-map.js +81 -0
  385. package/src/features/tables/borders.d.ts +126 -0
  386. package/src/features/tables/borders.js +527 -0
  387. package/src/features/tables/collections.d.ts +113 -0
  388. package/src/features/tables/collections.js +261 -0
  389. package/src/features/tables/format.d.ts +208 -0
  390. package/src/features/tables/format.js +716 -0
  391. package/src/features/tables/index.d.ts +597 -0
  392. package/src/features/tables/index.js +2386 -0
  393. package/src/features/tables/paddings.d.ts +41 -0
  394. package/src/features/tables/paddings.js +97 -0
  395. package/src/features/tables/tbl-pr-positioning.d.ts +27 -0
  396. package/src/features/tables/tbl-pr-positioning.js +178 -0
  397. package/src/features/tables/tbl-pr.d.ts +528 -0
  398. package/src/features/tables/tbl-pr.js +1208 -0
  399. package/src/features/tables/tc-pr.d.ts +168 -0
  400. package/src/features/tables/tc-pr.js +553 -0
  401. package/src/features/tables/tr-pr.d.ts +60 -0
  402. package/src/features/tables/tr-pr.js +215 -0
  403. package/src/features/watermark/detect.d.ts +76 -0
  404. package/src/features/watermark/detect.js +219 -0
  405. package/src/features/watermark/index.d.ts +28 -0
  406. package/src/features/watermark/index.js +91 -0
  407. package/src/features/watermark/logical-store.d.ts +29 -0
  408. package/src/features/watermark/logical-store.js +31 -0
  409. package/src/features/watermark/model.d.ts +285 -0
  410. package/src/features/watermark/model.js +597 -0
  411. package/src/features/watermark/parse.d.ts +84 -0
  412. package/src/features/watermark/parse.js +815 -0
  413. package/src/features/watermark/serialize.d.ts +98 -0
  414. package/src/features/watermark/serialize.js +1517 -0
  415. package/src/global.js +1 -0
  416. package/src/index.d.ts +2 -0
  417. package/src/index.js +2 -0
@@ -0,0 +1,2386 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ extendStatics(d, b);
10
+ function __() { this.constructor = d; }
11
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12
+ };
13
+ })();
14
+ export * from './border-style-map';
15
+ export * from './borders';
16
+ export * from './collections';
17
+ export * from './format';
18
+ export * from './paddings';
19
+ export * from './tbl-pr-positioning';
20
+ export * from './tbl-pr';
21
+ export * from './tc-pr';
22
+ export * from './tr-pr';
23
+ import { DetachedObjectError } from '../../core/errors/docx-error';
24
+ import { parseBodyBlocks, serializeBodyBlocks } from '../document/body-blocks';
25
+ import { WordDocument, Body } from '../document/document';
26
+ import { Paragraph } from '../document/paragraph';
27
+ import { registerAlwaysOnBodyFeatureBootstrap } from '../document/body-always-on';
28
+ import { registerBodyItemAdapter } from '../document/body-item-adapters';
29
+ import { registerTypedCollectionHooks } from '../document/typed-body-collections';
30
+ import { elementChildren, isWml, wmlAttr, wmlElement } from '../document/wml';
31
+ import { featureId, registerFeature, registerFeatureBlockHandler, registerFeatureBlockParagraphWalker, visitBlocksInDocumentOrder, } from '../../core/registry/index';
32
+ import { hasAnyCnfStyleFlag, normalizeCnfStyle, parseDecimalVal, readTableCaption, readTableColumnBandSize, readTableDescription, readTableIndent, readTableLayout, readTableLook, readTablePreferredWidth, readTableRowBandSize, readTableShading, readTableStyle, pointToTwips, twipsToPoint, wmlAttrVal, writeTableCaption, writeTableColumnBandSize, writeTableDescription, writeTableIndent, writeTableLayout, writeTableLook, writeTablePreferredWidth, writeTableRowBandSize, writeTableStyle, } from './tbl-pr';
33
+ import { BuiltinTableStyle, ConditionalFormattingType, resolveStyleForTarget, styleCollectionFor, stylesFor, } from '../styles/index';
34
+ import { readRowCnfStyle, readRowHeight, readRowIsHeader, writeRowCnfStyle, writeRowHeight, writeRowIsHeader, } from './tr-pr';
35
+ import { readCellCnfStyle, readCellPreferredWidth, readCellShading, readGridSpan, readVerticalMerge, writeCellCnfStyle, writeCellPreferredWidth, writeCellShading, writeGridSpan, writeVerticalMerge, } from './tc-pr';
36
+ import { CellFormat, RowFormat, TableFormat, } from './format';
37
+ import { TableCellCollection, TableRowCollection, } from './collections';
38
+ /**
39
+ * AutoFit modes for {@link Table.autoFit}, matching DocIO `AutoFitType`.
40
+ *
41
+ * - {@link AutoFitType.FitToContent}: auto layout; clear fixed preferred widths.
42
+ * - {@link AutoFitType.FitToWindow}: auto layout; table 100% width; cell % widths.
43
+ * - {@link AutoFitType.FixedColumnWidth}: fixed layout; cell DXA widths from grid.
44
+ *
45
+ * @public
46
+ */
47
+ export var AutoFitType = {
48
+ FitToContent: 'fitToContent',
49
+ FitToWindow: 'fitToWindow',
50
+ FixedColumnWidth: 'fixedColumnWidth',
51
+ };
52
+ function autoWidthZero() {
53
+ return { type: 'auto', value: twipsToPoint(0) };
54
+ }
55
+ var DEFAULT_GRID_COL_TWIPS = 1440;
56
+ var PCT_100_FIFTIETHS = 5000;
57
+ /** Default page content width in points when no section is available (Letter − 72 − 72). */
58
+ var DEFAULT_PAGE_CLIENT_WIDTH_POINTS = 468;
59
+ /**
60
+ * Distribute `totalTwips` across `columnCount` equal columns without losing remainder.
61
+ *
62
+ * @private
63
+ */
64
+ function equalColumnTwips(totalTwips, columnCount) {
65
+ var cols = columnCount > 0 ? columnCount : 1;
66
+ var safeTotal = totalTwips > 0 ? Math.floor(totalTwips) : DEFAULT_GRID_COL_TWIPS * cols;
67
+ var base = Math.floor(safeTotal / cols);
68
+ var remainder = safeTotal - base * cols;
69
+ var out = [];
70
+ for (var i = 0; i < cols; i += 1) {
71
+ out.push(base + (i < remainder ? 1 : 0));
72
+ }
73
+ return out;
74
+ }
75
+ /**
76
+ * Build `w:tblGrid` from explicit column widths in twips.
77
+ *
78
+ * @private
79
+ */
80
+ function tblGridFromTwips(widthsTwips) {
81
+ var cols = [];
82
+ for (var i = 0; i < widthsTwips.length; i += 1) {
83
+ var w = widthsTwips[i];
84
+ cols.push(wmlElement('gridCol', {
85
+ attributes: [wmlAttr('w', String(w > 0 ? w : DEFAULT_GRID_COL_TWIPS))],
86
+ }));
87
+ }
88
+ return wmlElement('tblGrid', { children: cols });
89
+ }
90
+ var TABLES = featureId('tables');
91
+ function cellColumnSpan(cell) {
92
+ var span = cell.gridSpan;
93
+ return span !== undefined && span > 0 ? span : 1;
94
+ }
95
+ function findCoveringCell(row, gridColumn) {
96
+ var cursor = 0;
97
+ var cells = row.listCells();
98
+ for (var i = 0; i < cells.length; i += 1) {
99
+ var cell = cells[i];
100
+ if (cell === undefined) {
101
+ continue;
102
+ }
103
+ var span = cellColumnSpan(cell);
104
+ if (gridColumn >= cursor && gridColumn < cursor + span) {
105
+ return { cell: cell, startColumn: cursor, cellIndex: i };
106
+ }
107
+ cursor += span;
108
+ }
109
+ return undefined;
110
+ }
111
+ function cellStartColumn(row, target) {
112
+ var cursor = 0;
113
+ var cells = row.listCells();
114
+ for (var i = 0; i < cells.length; i += 1) {
115
+ var cell = cells[i];
116
+ if (cell === target) {
117
+ return cursor;
118
+ }
119
+ cursor += cellColumnSpan(cell);
120
+ }
121
+ return -1;
122
+ }
123
+ function cellHasVisibleText(cell) {
124
+ return cell.text.trim().length > 0;
125
+ }
126
+ /**
127
+ * A table — ordered grid of rows and cells with table-level formatting.
128
+ *
129
+ * Create with {@link Body.appendTable} then size via {@link Table.resetCells}.
130
+ *
131
+ * @public
132
+ */
133
+ var Table = /** @class */ (function () {
134
+ /**
135
+ * @private
136
+ */
137
+ function Table(prefixMarkup, tblPr, tblGrid, rows) {
138
+ this.prefixMarkup = prefixMarkup;
139
+ this.tblPr = tblPr;
140
+ this.tblGrid = tblGrid;
141
+ this.tableRows = rows;
142
+ this.documentOwner = undefined;
143
+ this.rowsInstance = new TableRowCollection(this);
144
+ this.tableFormatInstance = new TableFormat(this);
145
+ this.conditionalFormattingDirty = false;
146
+ }
147
+ Object.defineProperty(Table.prototype, "rows", {
148
+ /** Rows collection (DocIO-aligned). */
149
+ get: function () {
150
+ return this.rowsInstance;
151
+ },
152
+ enumerable: true,
153
+ configurable: true
154
+ });
155
+ /**
156
+ * @private
157
+ */
158
+ Table.prototype.listRows = function () {
159
+ return this.tableRows;
160
+ };
161
+ /**
162
+ * @private
163
+ */
164
+ Table.prototype.replaceRows = function (rows) {
165
+ if (rows.length < 1) {
166
+ throw new DetachedObjectError('A table must retain at least one row');
167
+ }
168
+ var previous = this.tableRows;
169
+ for (var i = 0; i < previous.length; i += 1) {
170
+ if (rows.indexOf(previous[i]) === -1) {
171
+ previous[i].setOwnerTable(undefined);
172
+ }
173
+ }
174
+ this.tableRows = rows;
175
+ for (var i = 0; i < rows.length; i += 1) {
176
+ rows[i].setOwnerTable(this);
177
+ }
178
+ this.rowsInstance.syncFromHost();
179
+ this.markConditionalFormattingDirty();
180
+ };
181
+ /**
182
+ * @private
183
+ */
184
+ Table.prototype.createEmptyRow = function () {
185
+ return this.buildEmptyRow();
186
+ };
187
+ /**
188
+ * @private
189
+ */
190
+ Table.prototype.bindRow = function (row) {
191
+ row.setOwnerTable(this);
192
+ if (this.documentOwner !== undefined) {
193
+ row.bindDocument(this.documentOwner);
194
+ var cells = row.listCells();
195
+ for (var i = 0; i < cells.length; i += 1) {
196
+ cells[i].bindDocument(this.documentOwner);
197
+ }
198
+ }
199
+ };
200
+ /**
201
+ * @private
202
+ */
203
+ Table.prototype.minRowCount = function () {
204
+ return 1;
205
+ };
206
+ /**
207
+ * @private
208
+ */
209
+ Table.prototype.readTblPr = function () {
210
+ return this.tblPr;
211
+ };
212
+ /**
213
+ * @private
214
+ */
215
+ Table.prototype.writeTblPr = function (next) {
216
+ this.tblPr = next;
217
+ };
218
+ /**
219
+ * DocIO parity: copy table back fill onto every cell as direct `w:tcPr/w:shd`
220
+ * (`val="clear"` `color="auto"` `fill=<wire>`). Clearing table backColor
221
+ * removes cell fills that still match the previous painted fill so independent
222
+ * cell colors are left alone when possible.
223
+ *
224
+ * @private
225
+ */
226
+ Table.prototype.applyTableBackColorToCells = function (fill) {
227
+ var rows = this.tableRows;
228
+ for (var r = 0; r < rows.length; r += 1) {
229
+ var cells = rows[r].listCells();
230
+ for (var c = 0; c < cells.length; c += 1) {
231
+ var cell = cells[c];
232
+ var prev = readCellShading(cell.readTcPr());
233
+ if (fill === undefined) {
234
+ // Clear only when the cell has no independent shading beyond
235
+ // the DocIO-shaped clear/auto bag (or empty fill).
236
+ if (prev === undefined) {
237
+ continue;
238
+ }
239
+ var onlyPaintedFill = (prev.pattern === undefined || prev.pattern === 'clear') &&
240
+ (prev.color === undefined || prev.color === 'auto');
241
+ if (!onlyPaintedFill) {
242
+ continue;
243
+ }
244
+ cell.writeTcPr(writeCellShading(cell.readTcPr(), undefined));
245
+ continue;
246
+ }
247
+ var pattern = prev !== undefined &&
248
+ prev.pattern !== undefined &&
249
+ prev.pattern.length > 0
250
+ ? prev.pattern
251
+ : 'clear';
252
+ var color = prev !== undefined && prev.color !== undefined && prev.color.length > 0
253
+ ? prev.color
254
+ : 'auto';
255
+ var next = {
256
+ fill: fill,
257
+ color: color,
258
+ pattern: pattern,
259
+ };
260
+ cell.writeTcPr(writeCellShading(cell.readTcPr(), next));
261
+ }
262
+ }
263
+ };
264
+ Object.defineProperty(Table.prototype, "tableFormat", {
265
+ /** Table-level format facade. */
266
+ get: function () {
267
+ return this.tableFormatInstance;
268
+ },
269
+ enumerable: true,
270
+ configurable: true
271
+ });
272
+ Object.defineProperty(Table.prototype, "title", {
273
+ /**
274
+ * Accessibility title (`w:tblCaption`). Formerly `caption`.
275
+ */
276
+ get: function () {
277
+ return readTableCaption(this.tblPr);
278
+ },
279
+ set: function (value) {
280
+ this.tblPr = writeTableCaption(this.tblPr, value);
281
+ },
282
+ enumerable: true,
283
+ configurable: true
284
+ });
285
+ Object.defineProperty(Table.prototype, "description", {
286
+ get: function () {
287
+ return readTableDescription(this.tblPr);
288
+ },
289
+ set: function (value) {
290
+ this.tblPr = writeTableDescription(this.tblPr, value);
291
+ },
292
+ enumerable: true,
293
+ configurable: true
294
+ });
295
+ Object.defineProperty(Table.prototype, "indentFromLeft", {
296
+ /**
297
+ * Left indent in points (`w:tblInd`). Formerly `indent`.
298
+ */
299
+ get: function () {
300
+ return readTableIndent(this.tblPr);
301
+ },
302
+ set: function (value) {
303
+ this.tblPr = writeTableIndent(this.tblPr, value);
304
+ },
305
+ enumerable: true,
306
+ configurable: true
307
+ });
308
+ Object.defineProperty(Table.prototype, "width", {
309
+ /**
310
+ * Effective table width in points from the sum of grid column widths
311
+ * (`w:tblGrid`). When a fixed DXA preferred width is set, that value is
312
+ * written on the setter; the getter always reports the grid sum.
313
+ */
314
+ get: function () {
315
+ var gridWidths = this.gridColumnWidthsTwips();
316
+ var totalTwips = 0;
317
+ for (var i = 0; i < gridWidths.length; i += 1) {
318
+ totalTwips += gridWidths[i];
319
+ }
320
+ if (totalTwips <= 0) {
321
+ return 0;
322
+ }
323
+ return twipsToPoint(totalTwips);
324
+ },
325
+ set: function (value) {
326
+ if (!isFinite(value) || value < 0) {
327
+ throw new RangeError('Table width must be a non-negative finite number of points, got ' + String(value));
328
+ }
329
+ this.tblPr = writeTablePreferredWidth(this.tblPr, {
330
+ type: 'dxa',
331
+ value: value,
332
+ });
333
+ },
334
+ enumerable: true,
335
+ configurable: true
336
+ });
337
+ Object.defineProperty(Table.prototype, "preferredWidth", {
338
+ /**
339
+ * @private
340
+ */
341
+ get: function () {
342
+ return readTablePreferredWidth(this.tblPr);
343
+ },
344
+ set: function (value) {
345
+ this.tblPr = writeTablePreferredWidth(this.tblPr, value);
346
+ },
347
+ enumerable: true,
348
+ configurable: true
349
+ });
350
+ Object.defineProperty(Table.prototype, "layout", {
351
+ /**
352
+ * @private
353
+ */
354
+ get: function () {
355
+ return readTableLayout(this.tblPr);
356
+ },
357
+ set: function (value) {
358
+ this.tblPr = writeTableLayout(this.tblPr, value);
359
+ },
360
+ enumerable: true,
361
+ configurable: true
362
+ });
363
+ Object.defineProperty(Table.prototype, "look", {
364
+ /**
365
+ * @private
366
+ */
367
+ get: function () {
368
+ return readTableLook(this.tblPr);
369
+ },
370
+ set: function (value) {
371
+ this.tblPr = writeTableLook(this.tblPr, value);
372
+ },
373
+ enumerable: true,
374
+ configurable: true
375
+ });
376
+ Object.defineProperty(Table.prototype, "rowBandSize", {
377
+ /**
378
+ * Rows per table-style horizontal band (`w:tblStyleRowBandSize/@w:val`).
379
+ *
380
+ * Absent on the wire reads as `undefined` (Word default band height is 1).
381
+ * Setting `undefined` removes the element. Non-finite values throw
382
+ * `RangeError`. Does not recompute conditional formatting masks.
383
+ *
384
+ * @public
385
+ */
386
+ get: function () {
387
+ return readTableRowBandSize(this.tblPr);
388
+ },
389
+ set: function (value) {
390
+ if (value !== undefined && !isFinite(value)) {
391
+ throw new RangeError('Table rowBandSize must be a finite number or undefined, got ' + String(value));
392
+ }
393
+ this.tblPr = writeTableRowBandSize(this.tblPr, value !== undefined ? Math.trunc(value) : undefined);
394
+ this.markConditionalFormattingDirty();
395
+ },
396
+ enumerable: true,
397
+ configurable: true
398
+ });
399
+ Object.defineProperty(Table.prototype, "columnBandSize", {
400
+ /**
401
+ * Columns per table-style vertical band (`w:tblStyleColBandSize/@w:val`).
402
+ *
403
+ * Absent on the wire reads as `undefined` (Word default band width is 1).
404
+ * Setting `undefined` removes the element. Non-finite values throw
405
+ * `RangeError`. Does not recompute conditional formatting masks.
406
+ *
407
+ * @public
408
+ */
409
+ get: function () {
410
+ return readTableColumnBandSize(this.tblPr);
411
+ },
412
+ set: function (value) {
413
+ if (value !== undefined && !isFinite(value)) {
414
+ throw new RangeError('Table columnBandSize must be a finite number or undefined, got ' + String(value));
415
+ }
416
+ this.tblPr = writeTableColumnBandSize(this.tblPr, value !== undefined ? Math.trunc(value) : undefined);
417
+ this.markConditionalFormattingDirty();
418
+ },
419
+ enumerable: true,
420
+ configurable: true
421
+ });
422
+ Object.defineProperty(Table.prototype, "styleId", {
423
+ /**
424
+ * Canonical table style id (`w:tblStyle/@w:val`), when assigned.
425
+ *
426
+ * @public
427
+ */
428
+ get: function () {
429
+ return readTableStyle(this.tblPr);
430
+ },
431
+ set: function (value) {
432
+ this.tblPr = writeTableStyle(this.tblPr, value);
433
+ this.markConditionalFormattingDirty();
434
+ },
435
+ enumerable: true,
436
+ configurable: true
437
+ });
438
+ Object.defineProperty(Table.prototype, "styleName", {
439
+ /**
440
+ * Style id of the applied table style (`w:tblStyle/@w:val`).
441
+ * Matches the id written by {@link Table.applyStyle} / authoring defaults
442
+ * (e.g. `TableGrid`, `LightShading`). Absent style → `undefined`.
443
+ *
444
+ * @public
445
+ */
446
+ get: function () {
447
+ return readTableStyle(this.tblPr);
448
+ },
449
+ enumerable: true,
450
+ configurable: true
451
+ });
452
+ /**
453
+ * Apply a built-in, custom, or named table style to this table.
454
+ *
455
+ * Resolves the style through the document styles collection, materializing
456
+ * built-in definitions when needed, and writes `w:tblPr/w:tblStyle`.
457
+ * Does not change table-look application options.
458
+ *
459
+ * @param style Built-in id, live {@link TableStyle}, or style id / name string.
460
+ * @throws DetachedObjectError when the table is not bound to a document.
461
+ * @public
462
+ */
463
+ Table.prototype.applyStyle = function (style) {
464
+ if (this.documentOwner === undefined) {
465
+ throw new DetachedObjectError('Cannot apply a table style to a table that is not attached to a document');
466
+ }
467
+ var requested;
468
+ if (typeof style === 'string') {
469
+ requested = style;
470
+ }
471
+ else {
472
+ requested = style.styleId;
473
+ }
474
+ var resolved = resolveStyleForTarget(stylesFor(this.documentOwner), requested, 'table');
475
+ this.tblPr = writeTableStyle(this.tblPr, resolved.styleId);
476
+ this.markConditionalFormattingDirty();
477
+ };
478
+ Object.defineProperty(Table.prototype, "applyStyleForFirstRow", {
479
+ /**
480
+ * Whether the assigned table style applies first-row conditional formatting.
481
+ * Maps to `w:tblLook/@w:firstRow`. Absent look → `false`.
482
+ *
483
+ * @public
484
+ */
485
+ get: function () {
486
+ var look = this.look;
487
+ return look !== undefined && look.firstRow === true;
488
+ },
489
+ set: function (value) {
490
+ this.mergeTableLook({ firstRow: value === true });
491
+ },
492
+ enumerable: true,
493
+ configurable: true
494
+ });
495
+ Object.defineProperty(Table.prototype, "applyStyleForLastRow", {
496
+ /**
497
+ * Whether the assigned table style applies last-row conditional formatting.
498
+ * Maps to `w:tblLook/@w:lastRow`. Absent look → `false`.
499
+ *
500
+ * @public
501
+ */
502
+ get: function () {
503
+ var look = this.look;
504
+ return look !== undefined && look.lastRow === true;
505
+ },
506
+ set: function (value) {
507
+ this.mergeTableLook({ lastRow: value === true });
508
+ },
509
+ enumerable: true,
510
+ configurable: true
511
+ });
512
+ Object.defineProperty(Table.prototype, "applyStyleForFirstColumn", {
513
+ /**
514
+ * Whether the assigned table style applies first-column conditional formatting.
515
+ * Maps to `w:tblLook/@w:firstColumn`. Absent look → `false`.
516
+ *
517
+ * @public
518
+ */
519
+ get: function () {
520
+ var look = this.look;
521
+ return look !== undefined && look.firstCol === true;
522
+ },
523
+ set: function (value) {
524
+ this.mergeTableLook({ firstCol: value === true });
525
+ },
526
+ enumerable: true,
527
+ configurable: true
528
+ });
529
+ Object.defineProperty(Table.prototype, "applyStyleForLastColumn", {
530
+ /**
531
+ * Whether the assigned table style applies last-column conditional formatting.
532
+ * Maps to `w:tblLook/@w:lastColumn`. Absent look → `false`.
533
+ *
534
+ * @public
535
+ */
536
+ get: function () {
537
+ var look = this.look;
538
+ return look !== undefined && look.lastCol === true;
539
+ },
540
+ set: function (value) {
541
+ this.mergeTableLook({ lastCol: value === true });
542
+ },
543
+ enumerable: true,
544
+ configurable: true
545
+ });
546
+ Object.defineProperty(Table.prototype, "applyStyleForBandedRows", {
547
+ /**
548
+ * Whether the assigned table style applies horizontal band formatting to
549
+ * alternating table rows. Maps inversely to `w:tblLook/@w:noHBand`.
550
+ * Absent look → `true`.
551
+ *
552
+ * @public
553
+ */
554
+ get: function () {
555
+ var look = this.look;
556
+ if (look === undefined) {
557
+ return true;
558
+ }
559
+ return look.noHBand !== true;
560
+ },
561
+ set: function (value) {
562
+ this.mergeTableLook({ noHBand: value !== true });
563
+ },
564
+ enumerable: true,
565
+ configurable: true
566
+ });
567
+ Object.defineProperty(Table.prototype, "applyStyleForBandedColumns", {
568
+ /**
569
+ * Whether the assigned table style applies vertical band formatting to
570
+ * alternating table columns. Maps inversely to `w:tblLook/@w:noVBand`.
571
+ * Absent look → `true`.
572
+ *
573
+ * @public
574
+ */
575
+ get: function () {
576
+ var look = this.look;
577
+ if (look === undefined) {
578
+ return true;
579
+ }
580
+ return look.noVBand !== true;
581
+ },
582
+ set: function (value) {
583
+ this.mergeTableLook({ noVBand: value !== true });
584
+ },
585
+ enumerable: true,
586
+ configurable: true
587
+ });
588
+ /**
589
+ * Merge one or more `w:tblLook` flags without clearing unrelated flags.
590
+ *
591
+ * @private
592
+ */
593
+ Table.prototype.mergeTableLook = function (partial) {
594
+ var current = this.look;
595
+ var next = {
596
+ firstRow: partial.firstRow !== undefined
597
+ ? partial.firstRow
598
+ : current !== undefined ? current.firstRow : undefined,
599
+ lastRow: partial.lastRow !== undefined
600
+ ? partial.lastRow
601
+ : current !== undefined ? current.lastRow : undefined,
602
+ firstCol: partial.firstCol !== undefined
603
+ ? partial.firstCol
604
+ : current !== undefined ? current.firstCol : undefined,
605
+ lastCol: partial.lastCol !== undefined
606
+ ? partial.lastCol
607
+ : current !== undefined ? current.lastCol : undefined,
608
+ noHBand: partial.noHBand !== undefined
609
+ ? partial.noHBand
610
+ : current !== undefined ? current.noHBand : undefined,
611
+ noVBand: partial.noVBand !== undefined
612
+ ? partial.noVBand
613
+ : current !== undefined ? current.noVBand : undefined,
614
+ };
615
+ this.tblPr = writeTableLook(this.tblPr, next);
616
+ this.markConditionalFormattingDirty();
617
+ };
618
+ /**
619
+ * Marks row and cell conditional style membership for recalculation.
620
+ * Paragraph `w:pPr/w:cnfStyle` is not authored on dirty paths (DocIO parity).
621
+ *
622
+ * @private
623
+ */
624
+ Table.prototype.markConditionalFormattingDirty = function () {
625
+ this.conditionalFormattingDirty = true;
626
+ };
627
+ /**
628
+ * Recalculate conditional table-style membership masks on rows and cells
629
+ * (`w:trPr` / `w:tcPr`). Does not write `w:pPr/w:cnfStyle` — DocIO emits
630
+ * membership on row/cell only; paragraph cnf is cleared when styles are
631
+ * removed or when a dirty recompute runs so authored output stays clean.
632
+ * Nested tables own their own cascade.
633
+ *
634
+ * @private
635
+ */
636
+ Table.prototype.updateConditionalFormatting = function () {
637
+ var styleId = this.styleId;
638
+ var rows = this.tableRows;
639
+ var rowCount = rows.length;
640
+ var clearParagraphCnf = function (cell) {
641
+ var paragraphs = cell.listParagraphs();
642
+ for (var p = 0; p < paragraphs.length; p += 1) {
643
+ paragraphs[p].setConditionalFormatting(undefined);
644
+ }
645
+ };
646
+ var clearAllCnf = function () {
647
+ for (var r = 0; r < rowCount; r += 1) {
648
+ var row = rows[r];
649
+ row.setConditionalFormatting(undefined);
650
+ var cells = row.listCells();
651
+ for (var c = 0; c < cells.length; c += 1) {
652
+ var cell = cells[c];
653
+ cell.setConditionalFormatting(undefined);
654
+ clearParagraphCnf(cell);
655
+ }
656
+ }
657
+ };
658
+ if (styleId === undefined || styleId.length === 0) {
659
+ clearAllCnf();
660
+ this.conditionalFormattingDirty = false;
661
+ return;
662
+ }
663
+ var tableStyle;
664
+ var doc = this.documentOwner;
665
+ if (doc !== undefined) {
666
+ try {
667
+ tableStyle = styleCollectionFor(doc).getTableStyle(styleId);
668
+ }
669
+ catch (_e) {
670
+ tableStyle = undefined;
671
+ }
672
+ }
673
+ if (tableStyle === undefined) {
674
+ // No resolvable table style: preserve source cnf unless dirty.
675
+ this.conditionalFormattingDirty = false;
676
+ return;
677
+ }
678
+ var condStyles = tableStyle.conditionalFormattingStyles;
679
+ if (condStyles.count === 0) {
680
+ this.conditionalFormattingDirty = false;
681
+ return;
682
+ }
683
+ var hasType = function (type) {
684
+ return condStyles.findByType(type) !== undefined;
685
+ };
686
+ var applyFirstRow = this.applyStyleForFirstRow;
687
+ var applyLastRow = this.applyStyleForLastRow;
688
+ var applyFirstCol = this.applyStyleForFirstColumn;
689
+ var applyLastCol = this.applyStyleForLastColumn;
690
+ var applyHBand = this.applyStyleForBandedRows;
691
+ var applyVBand = this.applyStyleForBandedColumns;
692
+ for (var r = 0; r < rowCount; r += 1) {
693
+ var row = rows[r];
694
+ var rowIndex = r;
695
+ // Row trPr cnf: row-level flags only (existing band-size-aware path
696
+ // retained for trPr; gated on style conditional types).
697
+ var isFirstRow = hasType(ConditionalFormattingType.FirstRow) && applyFirstRow && rowIndex === 0;
698
+ var isLastRow = hasType(ConditionalFormattingType.LastRow) &&
699
+ applyLastRow &&
700
+ rowIndex !== 0 &&
701
+ rowIndex === rowCount - 1;
702
+ var oddHBand = false;
703
+ var evenHBand = false;
704
+ if (hasType(ConditionalFormattingType.OddRowBand) &&
705
+ applyHBand &&
706
+ rowIndex !== rowCount - 1 &&
707
+ rowIndex % 2 === 1) {
708
+ oddHBand = true;
709
+ }
710
+ if (hasType(ConditionalFormattingType.EvenRowBand) &&
711
+ applyHBand &&
712
+ rowIndex !== 0 &&
713
+ rowIndex !== rowCount - 1 &&
714
+ rowIndex % 2 === 0) {
715
+ evenHBand = true;
716
+ }
717
+ var rowFlags = normalizeCnfStyle({
718
+ firstRow: isFirstRow,
719
+ lastRow: isLastRow,
720
+ oddHBand: oddHBand,
721
+ evenHBand: evenHBand,
722
+ });
723
+ row.setConditionalFormatting(rowFlags);
724
+ var cells = row.listCells();
725
+ var cellCount = cells.length;
726
+ for (var c = 0; c < cellCount; c += 1) {
727
+ var cell = cells[c];
728
+ var cellIndex = c;
729
+ var cellState = normalizeCnfStyle({
730
+ firstColumn: hasType(ConditionalFormattingType.FirstColumn) &&
731
+ cellIndex === 0 &&
732
+ applyFirstCol,
733
+ lastColumn: hasType(ConditionalFormattingType.LastColumn) &&
734
+ cellIndex !== 0 &&
735
+ cellIndex === cellCount - 1 &&
736
+ applyLastCol,
737
+ oddVBand: hasType(ConditionalFormattingType.OddColumnBand) &&
738
+ cellIndex !== cellCount - 1 &&
739
+ cellIndex % 2 === 1 &&
740
+ applyVBand,
741
+ evenVBand: hasType(ConditionalFormattingType.EvenColumnBand) &&
742
+ cellIndex !== 0 &&
743
+ cellIndex !== cellCount - 1 &&
744
+ cellIndex % 2 === 0 &&
745
+ applyVBand,
746
+ firstRowLastColumn: hasType(ConditionalFormattingType.TopRightCell) &&
747
+ rowIndex === 0 &&
748
+ cellIndex !== 0 &&
749
+ cellIndex === cellCount - 1 &&
750
+ applyFirstRow &&
751
+ applyLastCol,
752
+ firstRowFirstColumn: hasType(ConditionalFormattingType.TopLeftCell) &&
753
+ rowIndex === 0 &&
754
+ cellIndex === 0 &&
755
+ applyFirstRow &&
756
+ applyFirstCol,
757
+ lastRowLastColumn: hasType(ConditionalFormattingType.BottomRightCell) &&
758
+ rowIndex !== 0 &&
759
+ rowIndex === rowCount - 1 &&
760
+ cellIndex !== 0 &&
761
+ cellIndex === cellCount - 1 &&
762
+ applyLastRow &&
763
+ applyLastCol,
764
+ lastRowFirstColumn: hasType(ConditionalFormattingType.BottomLeftCell) &&
765
+ rowIndex !== 0 &&
766
+ rowIndex === rowCount - 1 &&
767
+ cellIndex === 0 &&
768
+ applyLastRow &&
769
+ applyFirstCol,
770
+ });
771
+ // DocIO writes cnf on trPr/tcPr only — never author pPr/cnfStyle.
772
+ if (hasAnyCnfStyleFlag(cellState)) {
773
+ cell.setConditionalFormatting(cellState);
774
+ }
775
+ else {
776
+ cell.setConditionalFormatting(undefined);
777
+ }
778
+ clearParagraphCnf(cell);
779
+ }
780
+ }
781
+ this.conditionalFormattingDirty = false;
782
+ };
783
+ Object.defineProperty(Table.prototype, "owner", {
784
+ /**
785
+ * Owning document when bound.
786
+ *
787
+ * @private
788
+ */
789
+ get: function () {
790
+ return this.documentOwner;
791
+ },
792
+ enumerable: true,
793
+ configurable: true
794
+ });
795
+ /**
796
+ * Rebuild the table to `rowCount` × `columnCount` empty cells.
797
+ *
798
+ * Authoring path: empty cells (no auto paragraph), fixed layout, equal
799
+ * client-width columns, and `TableGrid` when document-bound.
800
+ */
801
+ Table.prototype.resetCells = function (rowCount, columnCount) {
802
+ if (rowCount < 1 || columnCount < 1) {
803
+ throw new RangeError('Table must have at least one row and one column');
804
+ }
805
+ var rows = [];
806
+ for (var r = 0; r < rowCount; r += 1) {
807
+ rows.push(this.buildEmptyRowWithColumns(columnCount));
808
+ }
809
+ this.tableRows = rows;
810
+ this.rowsInstance.syncFromHost();
811
+ if (this.documentOwner !== undefined) {
812
+ this.bindDocument(this.documentOwner);
813
+ }
814
+ applyAuthoringTableDefaults(this, columnCount);
815
+ // DocIO paints table backColor onto every cell; rebuilds must re-apply
816
+ // because paint-at-setter only walks cells that existed when backColor was set.
817
+ this.reapplyTableBackColorToCells();
818
+ this.markConditionalFormattingDirty();
819
+ };
820
+ Table.prototype.autoFit = function (autoFitType) {
821
+ switch (autoFitType) {
822
+ case AutoFitType.FitToContent:
823
+ this.applyFitToContent();
824
+ return;
825
+ case AutoFitType.FitToWindow:
826
+ this.applyFitToWindow();
827
+ return;
828
+ case AutoFitType.FixedColumnWidth:
829
+ this.applyFixedColumnWidth();
830
+ return;
831
+ default: {
832
+ var _exhaustive = autoFitType;
833
+ throw new RangeError('Unsupported AutoFitType: ' + String(_exhaustive));
834
+ }
835
+ }
836
+ };
837
+ /**
838
+ * Append an empty row with the current column count.
839
+ * Prefer {@link Table.rows}.add for new code.
840
+ */
841
+ Table.prototype.appendRow = function () {
842
+ return this.rowsInstance.add();
843
+ };
844
+ /**
845
+ * Insert an empty row at `index` (0 … rows.length inclusive).
846
+ * Prefer {@link Table.rows}.insert for new code.
847
+ */
848
+ Table.prototype.insertRow = function (index) {
849
+ return this.rowsInstance.insert(index);
850
+ };
851
+ /**
852
+ * Remove a row that currently belongs to this table.
853
+ * Prefer {@link Table.rows}.remove for new code.
854
+ */
855
+ Table.prototype.removeRow = function (row) {
856
+ this.rowsInstance.remove(row);
857
+ };
858
+ /**
859
+ * Merge contiguous structural cells in one row (inclusive cell indexes).
860
+ */
861
+ Table.prototype.applyHorizontalMerge = function (rowIndex, startCellIndex, endCellIndex) {
862
+ if (!Number.isInteger(rowIndex) ||
863
+ !Number.isInteger(startCellIndex) ||
864
+ !Number.isInteger(endCellIndex)) {
865
+ throw new RangeError('applyHorizontalMerge indexes must be integers');
866
+ }
867
+ if (startCellIndex > endCellIndex) {
868
+ throw new RangeError('applyHorizontalMerge range is inverted or empty');
869
+ }
870
+ var row = this.tableRows[rowIndex];
871
+ if (row === undefined) {
872
+ throw new RangeError('applyHorizontalMerge row index is out of bounds');
873
+ }
874
+ var cells = row.listCells();
875
+ if (startCellIndex < 0 || endCellIndex >= cells.length) {
876
+ throw new RangeError('applyHorizontalMerge cell index is out of bounds');
877
+ }
878
+ if (startCellIndex === endCellIndex) {
879
+ return;
880
+ }
881
+ var startCell = cells[startCellIndex];
882
+ var endCell = cells[endCellIndex];
883
+ var fromColumn = cellStartColumn(row, startCell);
884
+ var toColumn = cellStartColumn(row, endCell) + cellColumnSpan(endCell) - 1;
885
+ if (fromColumn < 0 || toColumn < fromColumn) {
886
+ throw new RangeError('applyHorizontalMerge could not resolve grid columns');
887
+ }
888
+ this.mergeCells({
889
+ fromRow: rowIndex,
890
+ fromColumn: fromColumn,
891
+ toRow: rowIndex,
892
+ toColumn: toColumn,
893
+ });
894
+ };
895
+ /**
896
+ * Vertical merge along one grid column across inclusive row indexes.
897
+ */
898
+ Table.prototype.applyVerticalMerge = function (columnIndex, startRowIndex, endRowIndex) {
899
+ if (!Number.isInteger(columnIndex) ||
900
+ !Number.isInteger(startRowIndex) ||
901
+ !Number.isInteger(endRowIndex)) {
902
+ throw new RangeError('applyVerticalMerge indexes must be integers');
903
+ }
904
+ if (startRowIndex > endRowIndex) {
905
+ throw new RangeError('applyVerticalMerge range is inverted or empty');
906
+ }
907
+ if (startRowIndex < 0 || endRowIndex >= this.tableRows.length) {
908
+ throw new RangeError('applyVerticalMerge row index is out of bounds');
909
+ }
910
+ if (columnIndex < 0 || columnIndex >= this.columnCount()) {
911
+ throw new RangeError('applyVerticalMerge column index is out of bounds');
912
+ }
913
+ if (startRowIndex === endRowIndex) {
914
+ return;
915
+ }
916
+ this.mergeCells({
917
+ fromRow: startRowIndex,
918
+ fromColumn: columnIndex,
919
+ toRow: endRowIndex,
920
+ toColumn: columnIndex,
921
+ });
922
+ };
923
+ /**
924
+ * @private
925
+ */
926
+ Table.prototype.mergeCells = function (range) {
927
+ var __ts33_0;
928
+ var __ts33_1;
929
+ var fromRow = range.fromRow;
930
+ var fromColumn = range.fromColumn;
931
+ var toRow = range.toRow;
932
+ var toColumn = range.toColumn;
933
+ if (!Number.isInteger(fromRow) ||
934
+ !Number.isInteger(fromColumn) ||
935
+ !Number.isInteger(toRow) ||
936
+ !Number.isInteger(toColumn)) {
937
+ throw new RangeError('mergeCells range coordinates must be integers');
938
+ }
939
+ if (fromRow > toRow || fromColumn > toColumn) {
940
+ throw new RangeError('mergeCells range is inverted or empty');
941
+ }
942
+ if (fromRow < 0 || fromColumn < 0 || toRow >= this.tableRows.length) {
943
+ throw new RangeError('mergeCells range is out of bounds');
944
+ }
945
+ var colCount = this.columnCount();
946
+ if (toColumn >= colCount) {
947
+ throw new RangeError('mergeCells range is out of bounds');
948
+ }
949
+ var rowSpan = toRow - fromRow + 1;
950
+ var colSpan = toColumn - fromColumn + 1;
951
+ if (rowSpan === 1 && colSpan === 1) {
952
+ var singleRow = this.tableRows[fromRow];
953
+ if (singleRow === undefined) {
954
+ throw new RangeError('mergeCells range is out of bounds');
955
+ }
956
+ var single = findCoveringCell(singleRow, fromColumn);
957
+ if (single === undefined) {
958
+ throw new RangeError('mergeCells range is out of bounds');
959
+ }
960
+ return single.cell;
961
+ }
962
+ var absorbed = [];
963
+ var origin;
964
+ for (var r = fromRow; r <= toRow; r += 1) {
965
+ var row = this.tableRows[r];
966
+ if (row === undefined) {
967
+ throw new RangeError('mergeCells range is out of bounds');
968
+ }
969
+ var c = fromColumn;
970
+ while (c <= toColumn) {
971
+ var hit = findCoveringCell(row, c);
972
+ if (hit === undefined) {
973
+ throw new RangeError('mergeCells range is out of bounds');
974
+ }
975
+ if (hit.startColumn < fromColumn ||
976
+ hit.startColumn + cellColumnSpan(hit.cell) - 1 > toColumn) {
977
+ throw new RangeError('mergeCells range partially overlaps an existing merged cell');
978
+ }
979
+ if (r === fromRow && hit.startColumn === fromColumn) {
980
+ origin = hit.cell;
981
+ }
982
+ else if (hit.cell !== origin) {
983
+ absorbed.push(hit.cell);
984
+ }
985
+ c = hit.startColumn + cellColumnSpan(hit.cell);
986
+ }
987
+ }
988
+ if (origin === undefined) {
989
+ throw new RangeError('mergeCells could not resolve origin cell');
990
+ }
991
+ for (var ai = 0; ai < absorbed.length; ai += 1) {
992
+ this.moveCellContentInto(origin, absorbed[ai]);
993
+ }
994
+ var preMergeSpan = new Map();
995
+ for (var r = fromRow; r <= toRow; r += 1) {
996
+ var snapRow = this.tableRows[r];
997
+ if (snapRow === undefined) {
998
+ throw new RangeError('mergeCells range is out of bounds');
999
+ }
1000
+ var snapCells = snapRow.listCells();
1001
+ for (var si = 0; si < snapCells.length; si += 1) {
1002
+ var cell = snapCells[si];
1003
+ preMergeSpan.set(cell, cellColumnSpan(cell));
1004
+ }
1005
+ }
1006
+ if (colSpan > 1) {
1007
+ origin.gridSpan = colSpan;
1008
+ }
1009
+ else {
1010
+ origin.gridSpan = undefined;
1011
+ }
1012
+ if (rowSpan > 1) {
1013
+ origin.verticalMerge = 'restart';
1014
+ }
1015
+ else {
1016
+ origin.verticalMerge = undefined;
1017
+ }
1018
+ for (var r = fromRow; r <= toRow; r += 1) {
1019
+ var row = this.tableRows[r];
1020
+ if (row === undefined) {
1021
+ throw new RangeError('mergeCells range is out of bounds');
1022
+ }
1023
+ var keep = [];
1024
+ var cursor = 0;
1025
+ var placedMergeCell = false;
1026
+ var rowCells = row.listCells();
1027
+ for (var ci = 0; ci < rowCells.length; ci += 1) {
1028
+ var cell = rowCells[ci];
1029
+ var span = ((__ts33_0 = preMergeSpan.get(cell)), __ts33_0 != null ? __ts33_0 : cellColumnSpan(cell));
1030
+ var cellStart = cursor;
1031
+ var cellEnd = cursor + span - 1;
1032
+ cursor += span;
1033
+ var overlaps = cellEnd >= fromColumn && cellStart <= toColumn;
1034
+ if (!overlaps) {
1035
+ keep.push(cell);
1036
+ continue;
1037
+ }
1038
+ if (r === fromRow && cell === origin) {
1039
+ keep.push(cell);
1040
+ placedMergeCell = true;
1041
+ continue;
1042
+ }
1043
+ if (r > fromRow && cellStart === fromColumn && !placedMergeCell) {
1044
+ cell.gridSpan = colSpan > 1 ? colSpan : undefined;
1045
+ cell.verticalMerge = 'continue';
1046
+ this.ensureAtLeastOneParagraph(cell);
1047
+ keep.push(cell);
1048
+ placedMergeCell = true;
1049
+ continue;
1050
+ }
1051
+ }
1052
+ if (r > fromRow && !placedMergeCell) {
1053
+ var contCell = this.createBoundEmptyCell();
1054
+ contCell.gridSpan = colSpan > 1 ? colSpan : undefined;
1055
+ contCell.verticalMerge = 'continue';
1056
+ var insertAt = 0;
1057
+ var g = 0;
1058
+ while (insertAt < keep.length && g < fromColumn) {
1059
+ var kept = keep[insertAt];
1060
+ if (kept === undefined) {
1061
+ break;
1062
+ }
1063
+ g += ((__ts33_1 = preMergeSpan.get(kept)), __ts33_1 != null ? __ts33_1 : cellColumnSpan(kept));
1064
+ insertAt += 1;
1065
+ }
1066
+ keep.splice(insertAt, 0, contCell);
1067
+ }
1068
+ if (keep.length < 1) {
1069
+ throw new DetachedObjectError('mergeCells would leave a row with no cells');
1070
+ }
1071
+ row.replaceCells(keep);
1072
+ }
1073
+ this.markConditionalFormattingDirty();
1074
+ return origin;
1075
+ };
1076
+ /**
1077
+ * @private
1078
+ */
1079
+ Table.prototype.splitCell = function (cell) {
1080
+ var region = this.getMergeRegion(cell);
1081
+ if (region === undefined || region.origin !== cell) {
1082
+ throw new RangeError('splitCell requires a merge origin cell in this table');
1083
+ }
1084
+ var fromRow = region.fromRow;
1085
+ var fromColumn = region.fromColumn;
1086
+ var toRow = region.toRow;
1087
+ var toColumn = region.toColumn;
1088
+ var released = [];
1089
+ var regionCells = [region.origin];
1090
+ for (var i = 0; i < region.continuations.length; i += 1) {
1091
+ regionCells.push(region.continuations[i]);
1092
+ }
1093
+ for (var r = fromRow; r <= toRow; r += 1) {
1094
+ var row = this.tableRows[r];
1095
+ if (row === undefined) {
1096
+ continue;
1097
+ }
1098
+ var next = [];
1099
+ var cursor = 0;
1100
+ var structuralCells = row.listCells();
1101
+ for (var si = 0; si < structuralCells.length; si += 1) {
1102
+ var structural = structuralCells[si];
1103
+ var span = cellColumnSpan(structural);
1104
+ var start = cursor;
1105
+ cursor += span;
1106
+ var inRegion = false;
1107
+ for (var ri = 0; ri < regionCells.length; ri += 1) {
1108
+ if (regionCells[ri] === structural) {
1109
+ inRegion = true;
1110
+ break;
1111
+ }
1112
+ }
1113
+ if (!inRegion) {
1114
+ next.push(structural);
1115
+ continue;
1116
+ }
1117
+ for (var c = start; c < start + span; c += 1) {
1118
+ if (c < fromColumn || c > toColumn) {
1119
+ var piece_1 = this.createBoundEmptyCell();
1120
+ next.push(piece_1);
1121
+ released.push(piece_1);
1122
+ continue;
1123
+ }
1124
+ var piece = void 0;
1125
+ if (r === fromRow && c === fromColumn) {
1126
+ piece = region.origin;
1127
+ piece.gridSpan = undefined;
1128
+ piece.verticalMerge = undefined;
1129
+ }
1130
+ else if (c === start && structural !== region.origin) {
1131
+ piece = structural;
1132
+ piece.gridSpan = undefined;
1133
+ piece.verticalMerge = undefined;
1134
+ this.ensureAtLeastOneParagraph(piece);
1135
+ }
1136
+ else {
1137
+ piece = this.createBoundEmptyCell();
1138
+ }
1139
+ next.push(piece);
1140
+ released.push(piece);
1141
+ }
1142
+ }
1143
+ if (next.length < 1) {
1144
+ throw new DetachedObjectError('splitCell would leave a row with no cells');
1145
+ }
1146
+ row.replaceCells(next);
1147
+ }
1148
+ this.markConditionalFormattingDirty();
1149
+ return released;
1150
+ };
1151
+ /**
1152
+ * @private
1153
+ */
1154
+ Table.prototype.getMergeRegion = function (cell) {
1155
+ var rowIndex = -1;
1156
+ for (var i = 0; i < this.tableRows.length; i += 1) {
1157
+ var rowCells = this.tableRows[i] == null ? undefined : this.tableRows[i].listCells();
1158
+ if (rowCells !== undefined && rowCells.indexOf(cell) !== -1) {
1159
+ rowIndex = i;
1160
+ break;
1161
+ }
1162
+ }
1163
+ if (rowIndex < 0) {
1164
+ return undefined;
1165
+ }
1166
+ var row = this.tableRows[rowIndex];
1167
+ if (row === undefined) {
1168
+ return undefined;
1169
+ }
1170
+ var startCol = cellStartColumn(row, cell);
1171
+ if (startCol < 0) {
1172
+ return undefined;
1173
+ }
1174
+ var span = cellColumnSpan(cell);
1175
+ var vMerge = cell.verticalMerge;
1176
+ if (span <= 1 && vMerge === undefined) {
1177
+ return undefined;
1178
+ }
1179
+ var originRow = rowIndex;
1180
+ var originCell = cell;
1181
+ if (vMerge === 'continue') {
1182
+ var foundRestart = false;
1183
+ for (var r = rowIndex - 1; r >= 0; r -= 1) {
1184
+ var aboveRow = this.tableRows[r];
1185
+ if (aboveRow === undefined) {
1186
+ break;
1187
+ }
1188
+ var above = findCoveringCell(aboveRow, startCol);
1189
+ if (above === undefined || above.startColumn !== startCol) {
1190
+ break;
1191
+ }
1192
+ if (cellColumnSpan(above.cell) !== span) {
1193
+ break;
1194
+ }
1195
+ if (above.cell.verticalMerge === 'restart') {
1196
+ originRow = r;
1197
+ originCell = above.cell;
1198
+ foundRestart = true;
1199
+ break;
1200
+ }
1201
+ if (above.cell.verticalMerge === 'continue') {
1202
+ continue;
1203
+ }
1204
+ break;
1205
+ }
1206
+ if (!foundRestart) {
1207
+ return {
1208
+ fromRow: rowIndex,
1209
+ fromColumn: startCol,
1210
+ toRow: rowIndex,
1211
+ toColumn: startCol + span - 1,
1212
+ origin: cell,
1213
+ continuations: [],
1214
+ };
1215
+ }
1216
+ }
1217
+ var originSpan = cellColumnSpan(originCell);
1218
+ var originRowObj = this.tableRows[originRow];
1219
+ if (originRowObj === undefined) {
1220
+ return undefined;
1221
+ }
1222
+ var fromColumn = cellStartColumn(originRowObj, originCell);
1223
+ if (fromColumn < 0) {
1224
+ return undefined;
1225
+ }
1226
+ var toColumn = fromColumn + originSpan - 1;
1227
+ var toRow = originRow;
1228
+ var continuations = [];
1229
+ if (originCell.verticalMerge === 'restart') {
1230
+ for (var r = originRow + 1; r < this.tableRows.length; r += 1) {
1231
+ var contRow = this.tableRows[r];
1232
+ if (contRow === undefined) {
1233
+ break;
1234
+ }
1235
+ var hit = findCoveringCell(contRow, fromColumn);
1236
+ if (hit === undefined ||
1237
+ hit.startColumn !== fromColumn ||
1238
+ cellColumnSpan(hit.cell) !== originSpan ||
1239
+ hit.cell.verticalMerge !== 'continue') {
1240
+ break;
1241
+ }
1242
+ toRow = r;
1243
+ continuations.push(hit.cell);
1244
+ }
1245
+ }
1246
+ if (originSpan <= 1 && originCell.verticalMerge === undefined) {
1247
+ return undefined;
1248
+ }
1249
+ return {
1250
+ fromRow: originRow,
1251
+ fromColumn: fromColumn,
1252
+ toRow: toRow,
1253
+ toColumn: toColumn,
1254
+ origin: originCell,
1255
+ continuations: continuations,
1256
+ };
1257
+ };
1258
+ Table.prototype.moveCellContentInto = function (target, source) {
1259
+ if (target === source) {
1260
+ return;
1261
+ }
1262
+ var needBreak = cellHasVisibleText(target) && cellHasVisibleText(source);
1263
+ if (needBreak) {
1264
+ var br = new Paragraph(undefined);
1265
+ target.appendRawBlock({ type: 'paragraph', paragraph: br });
1266
+ }
1267
+ var moved = source.listBlocks().slice();
1268
+ source.replaceItems([]);
1269
+ for (var i = 0; i < moved.length; i += 1) {
1270
+ target.appendRawBlock(moved[i]);
1271
+ }
1272
+ this.ensureAtLeastOneParagraph(source);
1273
+ };
1274
+ Table.prototype.ensureAtLeastOneParagraph = function (cell) {
1275
+ // Merge path only: WordprocessingML cells require ≥1 paragraph after content moves.
1276
+ if (cell.listParagraphs().length === 0) {
1277
+ cell.appendParagraph();
1278
+ }
1279
+ };
1280
+ Table.prototype.createBoundEmptyCell = function () {
1281
+ var cell = new TableCell(this.documentOwner, []);
1282
+ if (this.documentOwner !== undefined) {
1283
+ cell.bindDocument(this.documentOwner);
1284
+ }
1285
+ this.paintTableBackColorOntoCell(cell);
1286
+ return cell;
1287
+ };
1288
+ /**
1289
+ * Re-paint every cell from current `w:tblPr/w:shd` fill (DocIO parity).
1290
+ * No-op when table shading has no fill.
1291
+ *
1292
+ * @private
1293
+ */
1294
+ Table.prototype.reapplyTableBackColorToCells = function () {
1295
+ var shd = readTableShading(this.tblPr);
1296
+ var fill = shd === undefined ? undefined : shd.fill;
1297
+ if (fill === undefined || fill.length === 0) {
1298
+ return;
1299
+ }
1300
+ this.applyTableBackColorToCells(fill);
1301
+ };
1302
+ /**
1303
+ * Copy table-level back fill onto one newly created cell.
1304
+ *
1305
+ * @private
1306
+ */
1307
+ Table.prototype.paintTableBackColorOntoCell = function (cell) {
1308
+ var shd = readTableShading(this.tblPr);
1309
+ if (shd === undefined || shd.fill === undefined || shd.fill.length === 0) {
1310
+ return;
1311
+ }
1312
+ var pattern = shd.pattern !== undefined && shd.pattern.length > 0 ? shd.pattern : 'clear';
1313
+ var color = shd.color !== undefined && shd.color.length > 0 ? shd.color : 'auto';
1314
+ var next = {
1315
+ fill: shd.fill,
1316
+ color: color,
1317
+ pattern: pattern,
1318
+ };
1319
+ cell.writeTcPr(writeCellShading(cell.readTcPr(), next));
1320
+ };
1321
+ /**
1322
+ * @private
1323
+ */
1324
+ Table.prototype.bindDocument = function (document) {
1325
+ this.documentOwner = document;
1326
+ for (var r = 0; r < this.tableRows.length; r += 1) {
1327
+ var row = this.tableRows[r];
1328
+ row.bindDocument(document);
1329
+ var cells = row.listCells();
1330
+ for (var c = 0; c < cells.length; c += 1) {
1331
+ cells[c].bindDocument(document);
1332
+ }
1333
+ }
1334
+ };
1335
+ /**
1336
+ * @private
1337
+ */
1338
+ Table.prototype.toOpenXml = function () {
1339
+ if (this.conditionalFormattingDirty) {
1340
+ this.updateConditionalFormatting();
1341
+ }
1342
+ var children = [];
1343
+ for (var i = 0; i < this.prefixMarkup.length; i += 1) {
1344
+ children.push(this.prefixMarkup[i]);
1345
+ }
1346
+ children.push(this.tblPr);
1347
+ children.push(this.tblGrid);
1348
+ for (var r = 0; r < this.tableRows.length; r += 1) {
1349
+ children.push(this.tableRows[r].toOpenXml());
1350
+ }
1351
+ return wmlElement('tbl', { children: children });
1352
+ };
1353
+ Table.prototype.columnCount = function () {
1354
+ var gridCols = 0;
1355
+ var kids = elementChildren(this.tblGrid);
1356
+ for (var i = 0; i < kids.length; i += 1) {
1357
+ if (isWml(kids[i], 'gridCol')) {
1358
+ gridCols += 1;
1359
+ }
1360
+ }
1361
+ if (gridCols > 0) {
1362
+ return gridCols;
1363
+ }
1364
+ var firstRow = this.tableRows[0];
1365
+ if (firstRow === undefined) {
1366
+ return 1;
1367
+ }
1368
+ var first = firstRow.listCells().length;
1369
+ return first > 0 ? first : 1;
1370
+ };
1371
+ Table.prototype.gridColumnWidthsTwips = function () {
1372
+ var widths = [];
1373
+ var kids = elementChildren(this.tblGrid);
1374
+ for (var i = 0; i < kids.length; i += 1) {
1375
+ var child = kids[i];
1376
+ if (!isWml(child, 'gridCol')) {
1377
+ continue;
1378
+ }
1379
+ var raw = parseDecimalVal(wmlAttrVal(child, 'w'));
1380
+ widths.push(raw !== undefined && raw > 0 ? raw : DEFAULT_GRID_COL_TWIPS);
1381
+ }
1382
+ if (widths.length > 0) {
1383
+ return widths;
1384
+ }
1385
+ var cols = this.columnCount();
1386
+ var out = [];
1387
+ for (var i = 0; i < cols; i += 1) {
1388
+ out.push(DEFAULT_GRID_COL_TWIPS);
1389
+ }
1390
+ return out;
1391
+ };
1392
+ Table.prototype.cellWidthFromGridTwips = function (gridWidths, startColumn, span) {
1393
+ var total = 0;
1394
+ for (var i = 0; i < span; i += 1) {
1395
+ var w = gridWidths[startColumn + i];
1396
+ total += w !== undefined && w > 0 ? w : DEFAULT_GRID_COL_TWIPS;
1397
+ }
1398
+ return total > 0 ? total : DEFAULT_GRID_COL_TWIPS * Math.max(span, 1);
1399
+ };
1400
+ Table.prototype.applyFitToContent = function () {
1401
+ this.layout = 'autoFit';
1402
+ this.preferredWidth = autoWidthZero();
1403
+ for (var r = 0; r < this.tableRows.length; r += 1) {
1404
+ var cells = this.tableRows[r].listCells();
1405
+ for (var c = 0; c < cells.length; c += 1) {
1406
+ cells[c].preferredWidth = autoWidthZero();
1407
+ }
1408
+ }
1409
+ };
1410
+ Table.prototype.applyFitToWindow = function () {
1411
+ var gridWidths = this.gridColumnWidthsTwips();
1412
+ var tableWidthTwips = 0;
1413
+ for (var i = 0; i < gridWidths.length; i += 1) {
1414
+ tableWidthTwips += gridWidths[i];
1415
+ }
1416
+ var divisor = tableWidthTwips > 0 ? tableWidthTwips : DEFAULT_GRID_COL_TWIPS;
1417
+ this.layout = 'autoFit';
1418
+ this.preferredWidth = {
1419
+ type: 'pct',
1420
+ value: twipsToPoint(PCT_100_FIFTIETHS),
1421
+ };
1422
+ for (var r = 0; r < this.tableRows.length; r += 1) {
1423
+ var cursor = 0;
1424
+ var cells = this.tableRows[r].listCells();
1425
+ for (var c = 0; c < cells.length; c += 1) {
1426
+ var cell = cells[c];
1427
+ var span = cellColumnSpan(cell);
1428
+ var existing = cell.preferredWidth;
1429
+ if ((existing == null ? undefined : existing.type) !== 'pct') {
1430
+ var cellTwips = this.cellWidthFromGridTwips(gridWidths, cursor, span);
1431
+ var fiftieths = Math.max(0, Math.round((cellTwips / divisor) * PCT_100_FIFTIETHS));
1432
+ cell.preferredWidth = {
1433
+ type: 'pct',
1434
+ value: twipsToPoint(fiftieths),
1435
+ };
1436
+ }
1437
+ cursor += span;
1438
+ }
1439
+ }
1440
+ };
1441
+ Table.prototype.applyFixedColumnWidth = function () {
1442
+ var gridWidths = this.gridColumnWidthsTwips();
1443
+ this.layout = 'fixed';
1444
+ this.preferredWidth = autoWidthZero();
1445
+ for (var r = 0; r < this.tableRows.length; r += 1) {
1446
+ var cursor = 0;
1447
+ var cells = this.tableRows[r].listCells();
1448
+ for (var c = 0; c < cells.length; c += 1) {
1449
+ var cell = cells[c];
1450
+ var span = cellColumnSpan(cell);
1451
+ var cellTwips = this.cellWidthFromGridTwips(gridWidths, cursor, span);
1452
+ cell.preferredWidth = {
1453
+ type: 'dxa',
1454
+ value: twipsToPoint(cellTwips),
1455
+ };
1456
+ cursor += span;
1457
+ }
1458
+ }
1459
+ };
1460
+ Table.prototype.buildEmptyRow = function () {
1461
+ return this.buildEmptyRowWithColumns(this.columnCount());
1462
+ };
1463
+ Table.prototype.buildEmptyRowWithColumns = function (columnCount) {
1464
+ var cells = [];
1465
+ for (var c = 0; c < columnCount; c += 1) {
1466
+ cells.push(this.createBoundEmptyCell());
1467
+ }
1468
+ var row = new TableRow([], undefined, cells, this);
1469
+ if (this.documentOwner !== undefined) {
1470
+ row.bindDocument(this.documentOwner);
1471
+ for (var i = 0; i < cells.length; i += 1) {
1472
+ cells[i].bindDocument(this.documentOwner);
1473
+ }
1474
+ }
1475
+ return row;
1476
+ };
1477
+ /**
1478
+ * @private
1479
+ * Effective cell width in points from the table grid (and cell span).
1480
+ */
1481
+ Table.prototype.effectiveCellWidthPoints = function (cell) {
1482
+ var rows = this.tableRows;
1483
+ for (var r = 0; r < rows.length; r += 1) {
1484
+ var row = rows[r];
1485
+ var cells = row.listCells();
1486
+ var cursor = 0;
1487
+ for (var c = 0; c < cells.length; c += 1) {
1488
+ var current = cells[c];
1489
+ var span = cellColumnSpan(current);
1490
+ if (current === cell) {
1491
+ var twips = this.cellWidthFromGridTwips(this.gridColumnWidthsTwips(), cursor, span);
1492
+ return twipsToPoint(twips);
1493
+ }
1494
+ cursor += span;
1495
+ }
1496
+ }
1497
+ return twipsToPoint(DEFAULT_GRID_COL_TWIPS);
1498
+ };
1499
+ return Table;
1500
+ }());
1501
+ export { Table };
1502
+ /**
1503
+ * One row of a table — ordered cells with row-level formatting.
1504
+ *
1505
+ * @public
1506
+ */
1507
+ var TableRow = /** @class */ (function () {
1508
+ /**
1509
+ * @private
1510
+ */
1511
+ function TableRow(extras, trPr, cells, ownerTable) {
1512
+ this.rowExtras = extras;
1513
+ this.trPr = trPr;
1514
+ this.tableCells = cells;
1515
+ this.boundDocument = undefined;
1516
+ this.ownerTableRef = ownerTable;
1517
+ this.cellsInstance = new TableCellCollection(this);
1518
+ this.rowFormatInstance = new RowFormat(this);
1519
+ for (var i = 0; i < cells.length; i += 1) {
1520
+ cells[i].setOwnerRow(this);
1521
+ }
1522
+ }
1523
+ /**
1524
+ * @private
1525
+ */
1526
+ TableRow.prototype.setOwnerTable = function (table) {
1527
+ this.ownerTableRef = table;
1528
+ };
1529
+ Object.defineProperty(TableRow.prototype, "cells", {
1530
+ /** Cells collection (DocIO-aligned). */
1531
+ get: function () {
1532
+ return this.cellsInstance;
1533
+ },
1534
+ enumerable: true,
1535
+ configurable: true
1536
+ });
1537
+ /**
1538
+ * @private
1539
+ */
1540
+ TableRow.prototype.listCells = function () {
1541
+ return this.tableCells;
1542
+ };
1543
+ /**
1544
+ * @private
1545
+ * Replace structural cells in this row (merge/split internal).
1546
+ */
1547
+ TableRow.prototype.replaceCells = function (cells) {
1548
+ if (cells.length < 1) {
1549
+ throw new DetachedObjectError('A table row must retain at least one cell');
1550
+ }
1551
+ var previous = this.tableCells;
1552
+ for (var i = 0; i < previous.length; i += 1) {
1553
+ if (cells.indexOf(previous[i]) === -1) {
1554
+ previous[i].setOwnerRow(undefined);
1555
+ }
1556
+ }
1557
+ this.tableCells = cells;
1558
+ for (var i = 0; i < cells.length; i += 1) {
1559
+ cells[i].setOwnerRow(this);
1560
+ }
1561
+ this.cellsInstance.syncFromHost();
1562
+ if (this.ownerTableRef !== undefined) {
1563
+ this.ownerTableRef.markConditionalFormattingDirty();
1564
+ }
1565
+ };
1566
+ /**
1567
+ * @private
1568
+ */
1569
+ TableRow.prototype.createEmptyCell = function () {
1570
+ var cell = new TableCell(this.boundDocument, []);
1571
+ cell.setOwnerRow(this);
1572
+ if (this.boundDocument !== undefined) {
1573
+ cell.bindDocument(this.boundDocument);
1574
+ }
1575
+ if (this.ownerTableRef !== undefined) {
1576
+ this.ownerTableRef.paintTableBackColorOntoCell(cell);
1577
+ }
1578
+ return cell;
1579
+ };
1580
+ /**
1581
+ * @private
1582
+ */
1583
+ TableRow.prototype.bindCell = function (cell) {
1584
+ cell.setOwnerRow(this);
1585
+ if (this.boundDocument !== undefined) {
1586
+ cell.bindDocument(this.boundDocument);
1587
+ }
1588
+ };
1589
+ /**
1590
+ * @private
1591
+ */
1592
+ TableRow.prototype.minCellCount = function () {
1593
+ return 1;
1594
+ };
1595
+ /**
1596
+ * @private
1597
+ * Host probe for {@link TableCellCollection} (nullable; does not throw).
1598
+ */
1599
+ TableRow.prototype.getOwnerTableOrUndefined = function () {
1600
+ return this.ownerTableRef;
1601
+ };
1602
+ /**
1603
+ * @private
1604
+ */
1605
+ TableRow.prototype.readTrPr = function () {
1606
+ return this.trPr;
1607
+ };
1608
+ /**
1609
+ * @private
1610
+ */
1611
+ TableRow.prototype.writeTrPr = function (next) {
1612
+ this.trPr = next;
1613
+ };
1614
+ Object.defineProperty(TableRow.prototype, "rowFormat", {
1615
+ /** Row-level format facade. */
1616
+ get: function () {
1617
+ return this.rowFormatInstance;
1618
+ },
1619
+ enumerable: true,
1620
+ configurable: true
1621
+ });
1622
+ Object.defineProperty(TableRow.prototype, "ownerTable", {
1623
+ /**
1624
+ * Owning table. Throws {@link DetachedObjectError} when the row is detached.
1625
+ */
1626
+ get: function () {
1627
+ if (this.ownerTableRef === undefined) {
1628
+ throw new DetachedObjectError('This row is no longer attached to a table');
1629
+ }
1630
+ return this.ownerTableRef;
1631
+ },
1632
+ enumerable: true,
1633
+ configurable: true
1634
+ });
1635
+ Object.defineProperty(TableRow.prototype, "height", {
1636
+ /**
1637
+ * Row height in points (`w:trHeight/@w:val` twips on the wire).
1638
+ * `0` when unset (auto height to content).
1639
+ */
1640
+ get: function () {
1641
+ var bag = readRowHeight(this.trPr);
1642
+ return bag === undefined ? 0 : bag.value;
1643
+ },
1644
+ set: function (value) {
1645
+ if (!isFinite(value) || value < 0) {
1646
+ throw new RangeError('Row height must be a non-negative finite number of points, got ' + String(value));
1647
+ }
1648
+ var prev = readRowHeight(this.trPr);
1649
+ var rule = prev !== undefined
1650
+ ? prev.rule
1651
+ : 'auto';
1652
+ if (value === 0 && rule === 'auto') {
1653
+ this.trPr = writeRowHeight(this.trPr, undefined);
1654
+ return;
1655
+ }
1656
+ this.trPr = writeRowHeight(this.trPr, { value: value, rule: rule });
1657
+ },
1658
+ enumerable: true,
1659
+ configurable: true
1660
+ });
1661
+ Object.defineProperty(TableRow.prototype, "heightType", {
1662
+ /**
1663
+ * How Word treats {@link TableRow.height} (`w:trHeight/@w:hRule`).
1664
+ * Defaults to `'auto'` when unset.
1665
+ */
1666
+ get: function () {
1667
+ var bag = readRowHeight(this.trPr);
1668
+ return bag === undefined ? 'auto' : bag.rule;
1669
+ },
1670
+ set: function (value) {
1671
+ if (value !== 'auto' &&
1672
+ value !== 'exact' &&
1673
+ value !== 'atLeast') {
1674
+ throw new RangeError('Invalid row heightType: ' + String(value));
1675
+ }
1676
+ var prev = readRowHeight(this.trPr);
1677
+ var heightValue = prev !== undefined ? prev.value : 0;
1678
+ if (value === 'auto' && heightValue === 0) {
1679
+ this.trPr = writeRowHeight(this.trPr, undefined);
1680
+ return;
1681
+ }
1682
+ this.trPr = writeRowHeight(this.trPr, { value: heightValue, rule: value });
1683
+ },
1684
+ enumerable: true,
1685
+ configurable: true
1686
+ });
1687
+ Object.defineProperty(TableRow.prototype, "isHeader", {
1688
+ /**
1689
+ * When `true`, the row repeats at the top of every page the table spans
1690
+ * (a repeating header row). Defaults to `false`.
1691
+ */
1692
+ get: function () {
1693
+ return readRowIsHeader(this.trPr) === true;
1694
+ },
1695
+ set: function (value) {
1696
+ this.trPr = writeRowIsHeader(this.trPr, value === true ? true : undefined);
1697
+ },
1698
+ enumerable: true,
1699
+ configurable: true
1700
+ });
1701
+ /**
1702
+ * @private
1703
+ * Records the owning document so appended cells bind to it.
1704
+ */
1705
+ TableRow.prototype.bindDocument = function (document) {
1706
+ this.boundDocument = document;
1707
+ for (var i = 0; i < this.tableCells.length; i += 1) {
1708
+ this.tableCells[i].bindDocument(document);
1709
+ }
1710
+ };
1711
+ /**
1712
+ * @private
1713
+ * Serializes the row back to its `w:tr` element.
1714
+ */
1715
+ /**
1716
+ * Conditional table-style membership on `w:trPr/w:cnfStyle`.
1717
+ *
1718
+ * @public
1719
+ */
1720
+ TableRow.prototype.getConditionalFormatting = function () {
1721
+ return readRowCnfStyle(this.trPr);
1722
+ };
1723
+ /**
1724
+ * Write or clear row conditional formatting membership.
1725
+ *
1726
+ * @param state Normalized flags, or `undefined` to remove.
1727
+ * @public
1728
+ */
1729
+ TableRow.prototype.setConditionalFormatting = function (state) {
1730
+ this.trPr = writeRowCnfStyle(this.trPr, state);
1731
+ };
1732
+ TableRow.prototype.toOpenXml = function () {
1733
+ var children = [];
1734
+ for (var i = 0; i < this.rowExtras.length; i += 1) {
1735
+ children.push(this.rowExtras[i]);
1736
+ }
1737
+ if (this.trPr !== undefined) {
1738
+ children.push(this.trPr);
1739
+ }
1740
+ for (var i = 0; i < this.tableCells.length; i += 1) {
1741
+ children.push(this.tableCells[i].toOpenXml());
1742
+ }
1743
+ return wmlElement('tr', { children: children });
1744
+ };
1745
+ return TableRow;
1746
+ }());
1747
+ export { TableRow };
1748
+ /**
1749
+ * One cell of a table — a body container for paragraphs and nested tables,
1750
+ * with cell-level settings such as width and formatting.
1751
+ *
1752
+ * Nested tables: call {@link Body.appendTable} on the cell, then
1753
+ * {@link Table.resetCells} for size.
1754
+ *
1755
+ * @public
1756
+ */
1757
+ var TableCell = /** @class */ (function (_super) {
1758
+ __extends(TableCell, _super);
1759
+ /**
1760
+ * @private
1761
+ */
1762
+ function TableCell(document, blocks) {
1763
+ var _this = _super.call(this, document, blocks) || this;
1764
+ /**
1765
+ * Marks this body as a table-cell owner for {@link Paragraph.isInCell}.
1766
+ *
1767
+ * @private
1768
+ */
1769
+ _this.bodyOwnerKind = 'tableCell';
1770
+ _this.tcPrValue = undefined;
1771
+ _this.cellFormatInstance = new CellFormat(_this);
1772
+ _this.ownerRowRef = undefined;
1773
+ _this.reattachNestedTables();
1774
+ return _this;
1775
+ }
1776
+ /**
1777
+ * @private
1778
+ */
1779
+ TableCell.prototype.setOwnerRow = function (row) {
1780
+ this.ownerRowRef = row;
1781
+ };
1782
+ /**
1783
+ * @private
1784
+ * Apply `w:tcPr` after parse (constructor only takes body blocks).
1785
+ */
1786
+ TableCell.prototype.applyTcPr = function (tcPr) {
1787
+ this.tcPrValue = tcPr;
1788
+ };
1789
+ /**
1790
+ * @private
1791
+ */
1792
+ TableCell.prototype.readTcPr = function () {
1793
+ return this.tcPrValue;
1794
+ };
1795
+ /**
1796
+ * @private
1797
+ */
1798
+ TableCell.prototype.writeTcPr = function (next) {
1799
+ this.tcPrValue = next;
1800
+ };
1801
+ Object.defineProperty(TableCell.prototype, "cellFormat", {
1802
+ /** Cell-level format facade. */
1803
+ get: function () {
1804
+ return this.cellFormatInstance;
1805
+ },
1806
+ enumerable: true,
1807
+ configurable: true
1808
+ });
1809
+ Object.defineProperty(TableCell.prototype, "gridSpan", {
1810
+ /**
1811
+ * Number of grid columns this cell spans (`w:tcPr/w:gridSpan`).
1812
+ *
1813
+ * @private
1814
+ * Merge plumbing writes this value; public surface is
1815
+ * {@link CellFormat.columnSpan}.
1816
+ */
1817
+ get: function () {
1818
+ return readGridSpan(this.tcPrValue);
1819
+ },
1820
+ set: function (span) {
1821
+ this.tcPrValue = writeGridSpan(this.tcPrValue, span);
1822
+ var row = this.ownerRowRef;
1823
+ if (row !== undefined) {
1824
+ var table = row.getOwnerTableOrUndefined();
1825
+ if (table !== undefined) {
1826
+ table.markConditionalFormattingDirty();
1827
+ }
1828
+ }
1829
+ },
1830
+ enumerable: true,
1831
+ configurable: true
1832
+ });
1833
+ Object.defineProperty(TableCell.prototype, "verticalMerge", {
1834
+ /**
1835
+ * Vertical merge wire state (`w:tcPr/w:vMerge`): `'restart'` | `'continue'`.
1836
+ *
1837
+ * @private
1838
+ * Merge algorithm uses this; public surface is
1839
+ * {@link CellFormat.verticalMerge} ({@link CellMerge}).
1840
+ */
1841
+ get: function () {
1842
+ return readVerticalMerge(this.tcPrValue);
1843
+ },
1844
+ set: function (merge) {
1845
+ this.tcPrValue = writeVerticalMerge(this.tcPrValue, merge);
1846
+ },
1847
+ enumerable: true,
1848
+ configurable: true
1849
+ });
1850
+ Object.defineProperty(TableCell.prototype, "preferredWidth", {
1851
+ /**
1852
+ * Outer width of the cell as authored (`w:tcPr/w:tcW`).
1853
+ *
1854
+ * @private
1855
+ */
1856
+ get: function () {
1857
+ return readCellPreferredWidth(this.tcPrValue);
1858
+ },
1859
+ set: function (value) {
1860
+ this.tcPrValue = writeCellPreferredWidth(this.tcPrValue, value);
1861
+ },
1862
+ enumerable: true,
1863
+ configurable: true
1864
+ });
1865
+ Object.defineProperty(TableCell.prototype, "width", {
1866
+ /**
1867
+ * Preferred / effective cell width in points (1/72 inch).
1868
+ *
1869
+ * Fixed DXA `w:tcW` wins when present; otherwise the value is derived from
1870
+ * the parent table grid. Never returns `undefined`.
1871
+ */
1872
+ get: function () {
1873
+ var preferred = readCellPreferredWidth(this.tcPrValue);
1874
+ if (preferred !== undefined && preferred.type === 'dxa') {
1875
+ return preferred.value;
1876
+ }
1877
+ var row = this.ownerRowRef;
1878
+ if (row === undefined) {
1879
+ return twipsToPoint(DEFAULT_GRID_COL_TWIPS);
1880
+ }
1881
+ var table;
1882
+ try {
1883
+ table = row.ownerTable;
1884
+ }
1885
+ catch (_e) {
1886
+ table = undefined;
1887
+ }
1888
+ if (table === undefined) {
1889
+ return twipsToPoint(DEFAULT_GRID_COL_TWIPS);
1890
+ }
1891
+ return table.effectiveCellWidthPoints(this);
1892
+ },
1893
+ set: function (value) {
1894
+ if (!isFinite(value) || value < 0) {
1895
+ throw new RangeError('Cell width must be a non-negative finite number of points, got ' + String(value));
1896
+ }
1897
+ this.tcPrValue = writeCellPreferredWidth(this.tcPrValue, {
1898
+ type: 'dxa',
1899
+ value: value,
1900
+ });
1901
+ },
1902
+ enumerable: true,
1903
+ configurable: true
1904
+ });
1905
+ Object.defineProperty(TableCell.prototype, "text", {
1906
+ /**
1907
+ * Plain text of the cell, concatenated across all paragraphs.
1908
+ */
1909
+ get: function () {
1910
+ var parts = [];
1911
+ var paras = this.listParagraphs();
1912
+ for (var i = 0; i < paras.length; i += 1) {
1913
+ parts.push(paras[i].text);
1914
+ }
1915
+ return parts.join('');
1916
+ },
1917
+ set: function (value) {
1918
+ var paragraph = this.listParagraphs()[0];
1919
+ if (paragraph === undefined) {
1920
+ paragraph = this.appendParagraph();
1921
+ }
1922
+ // Clear existing modeled text by replacing with a single paragraph text.
1923
+ // Prefer appendText on a fresh empty paragraph path when possible.
1924
+ var current = paragraph.text;
1925
+ if (current.length > 0 || value.length === 0) {
1926
+ // Rebuild: remove all body blocks and put one paragraph with text.
1927
+ this.replaceItems([]);
1928
+ paragraph = this.appendParagraph({ text: value });
1929
+ return;
1930
+ }
1931
+ paragraph.appendText(value);
1932
+ },
1933
+ enumerable: true,
1934
+ configurable: true
1935
+ });
1936
+ Object.defineProperty(TableCell.prototype, "nestedTables", {
1937
+ /**
1938
+ * Nested tables contained in this cell body (feature blocks).
1939
+ * Prefer {@link TableCell.appendTable} to create nested tables.
1940
+ */
1941
+ get: function () {
1942
+ var result = [];
1943
+ var blocks = this.listBlocks();
1944
+ for (var i = 0; i < blocks.length; i += 1) {
1945
+ var block = blocks[i];
1946
+ if (block.type === 'feature' && block.featureId === TABLES && block.value instanceof Table) {
1947
+ result.push(block.value);
1948
+ }
1949
+ }
1950
+ return result;
1951
+ },
1952
+ enumerable: true,
1953
+ configurable: true
1954
+ });
1955
+ /**
1956
+ * @private
1957
+ * Binds the cell (and nested tables) to a document on attachment.
1958
+ */
1959
+ TableCell.prototype.bindDocument = function (document) {
1960
+ this.setOwningDocument(document);
1961
+ this.reattachNestedTables();
1962
+ var blocks = this.listBlocks();
1963
+ for (var i = 0; i < blocks.length; i += 1) {
1964
+ var block = blocks[i];
1965
+ if (block.type === 'feature' && block.featureId === TABLES && block.value instanceof Table) {
1966
+ block.value.bindDocument(document);
1967
+ }
1968
+ }
1969
+ };
1970
+ /**
1971
+ * @private
1972
+ * Re-attach nested table ownership after construction / content moves.
1973
+ */
1974
+ TableCell.prototype.reattachNestedTables = function () {
1975
+ var doc;
1976
+ try {
1977
+ doc = this.owningDocument();
1978
+ }
1979
+ catch (_e) {
1980
+ doc = undefined;
1981
+ }
1982
+ var blocks = this.listBlocks();
1983
+ for (var i = 0; i < blocks.length; i += 1) {
1984
+ var block = blocks[i];
1985
+ if (block.type === 'feature' && block.featureId === TABLES && block.value instanceof Table) {
1986
+ if (doc !== undefined) {
1987
+ block.value.bindDocument(doc);
1988
+ }
1989
+ }
1990
+ }
1991
+ };
1992
+ /**
1993
+ * @private
1994
+ * Serializes the cell back to its `w:tc` element.
1995
+ */
1996
+ /**
1997
+ * Conditional table-style membership on `w:tcPr/w:cnfStyle`.
1998
+ *
1999
+ * @public
2000
+ */
2001
+ TableCell.prototype.getConditionalFormatting = function () {
2002
+ return readCellCnfStyle(this.tcPrValue);
2003
+ };
2004
+ /**
2005
+ * Write or clear cell conditional formatting membership.
2006
+ *
2007
+ * @param state Normalized flags, or `undefined` to remove.
2008
+ * @public
2009
+ */
2010
+ TableCell.prototype.setConditionalFormatting = function (state) {
2011
+ this.tcPrValue = writeCellCnfStyle(this.tcPrValue, state);
2012
+ };
2013
+ TableCell.prototype.toOpenXml = function () {
2014
+ var children = [];
2015
+ if (this.tcPrValue !== undefined) {
2016
+ children.push(this.tcPrValue);
2017
+ }
2018
+ var blocks = this.listBlocks();
2019
+ if (blocks.length === 0) {
2020
+ // WordprocessingML cells require ≥1 paragraph on the wire; keep the
2021
+ // public DOM empty and emit a serialize-only empty `w:p`.
2022
+ children.push(wmlElement('p'));
2023
+ }
2024
+ else {
2025
+ var serialized = serializeBodyBlocks(blocks);
2026
+ for (var i = 0; i < serialized.length; i += 1) {
2027
+ children.push(serialized[i]);
2028
+ }
2029
+ }
2030
+ return wmlElement('tc', { children: children });
2031
+ };
2032
+ return TableCell;
2033
+ }(Body));
2034
+ export { TableCell };
2035
+ function defaultTblPr() {
2036
+ return wmlElement('tblPr');
2037
+ }
2038
+ function defaultTblGrid(columnCount) {
2039
+ var widths = equalColumnTwips(DEFAULT_GRID_COL_TWIPS * columnCount, columnCount);
2040
+ return tblGridFromTwips(widths);
2041
+ }
2042
+ /**
2043
+ * Client width available for equal column distribution (points).
2044
+ * Top-level uses page width − left/right margins; falls back to Letter − 72 − 72.
2045
+ *
2046
+ * @private
2047
+ */
2048
+ function resolveClientWidthPoints(table) {
2049
+ var doc = table['documentOwner'];
2050
+ if (doc !== undefined) {
2051
+ try {
2052
+ var sections = doc.sections;
2053
+ if (sections !== undefined && sections.count > 0) {
2054
+ var setup = sections[0].pageSetup;
2055
+ var pageWidth = setup.pageSize.width;
2056
+ var left = setup.margins.left;
2057
+ var right = setup.margins.right;
2058
+ var client = pageWidth - left - right;
2059
+ if (isFinite(client) && client > 0) {
2060
+ return client;
2061
+ }
2062
+ }
2063
+ }
2064
+ catch (_e) {
2065
+ /* fall through */
2066
+ }
2067
+ }
2068
+ return DEFAULT_PAGE_CLIENT_WIDTH_POINTS;
2069
+ }
2070
+ /**
2071
+ * Apply create-path defaults: TableGrid (when bound), fixed layout, equal widths.
2072
+ *
2073
+ * @private
2074
+ */
2075
+ function applyAuthoringTableDefaults(table, columnCount) {
2076
+ var cols = columnCount > 0 ? columnCount : 1;
2077
+ var clientPoints = resolveClientWidthPoints(table);
2078
+ var totalTwips = pointToTwips(clientPoints);
2079
+ var widths = equalColumnTwips(totalTwips, cols);
2080
+ table['tblGrid'] = tblGridFromTwips(widths);
2081
+ table.layout = 'fixed';
2082
+ var sum = 0;
2083
+ for (var i = 0; i < widths.length; i += 1) {
2084
+ sum += widths[i];
2085
+ }
2086
+ table['tblPr'] = writeTablePreferredWidth(table['tblPr'], {
2087
+ type: 'dxa',
2088
+ value: twipsToPoint(sum),
2089
+ });
2090
+ var rows = table.listRows();
2091
+ for (var r = 0; r < rows.length; r += 1) {
2092
+ var cursor = 0;
2093
+ var cells = rows[r].listCells();
2094
+ for (var c = 0; c < cells.length; c += 1) {
2095
+ var cell = cells[c];
2096
+ var span = cellColumnSpan(cell);
2097
+ var cellTwips = 0;
2098
+ for (var s = 0; s < span; s += 1) {
2099
+ var w = widths[cursor + s];
2100
+ cellTwips += w !== undefined && w > 0 ? w : DEFAULT_GRID_COL_TWIPS;
2101
+ }
2102
+ cell.preferredWidth = {
2103
+ type: 'dxa',
2104
+ value: twipsToPoint(cellTwips > 0 ? cellTwips : DEFAULT_GRID_COL_TWIPS),
2105
+ };
2106
+ cursor += span;
2107
+ }
2108
+ }
2109
+ var doc = table['documentOwner'];
2110
+ if (doc !== undefined) {
2111
+ try {
2112
+ table.applyStyle(BuiltinTableStyle.TableGrid);
2113
+ }
2114
+ catch (_e) {
2115
+ table['tblPr'] = writeTableStyle(table['tblPr'], BuiltinTableStyle.TableGrid);
2116
+ }
2117
+ }
2118
+ else {
2119
+ table['tblPr'] = writeTableStyle(table['tblPr'], BuiltinTableStyle.TableGrid);
2120
+ }
2121
+ }
2122
+ /**
2123
+ * Create an empty table with empty cells (no auto-injected paragraphs).
2124
+ * Authoring defaults (style/layout/equal widths) are applied by appendTable/resetCells.
2125
+ *
2126
+ * @private
2127
+ */
2128
+ export function createTable(rowCount, columnCount) {
2129
+ if (rowCount < 1 || columnCount < 1) {
2130
+ throw new RangeError('Table must have at least one row and one column');
2131
+ }
2132
+ var rows = [];
2133
+ for (var r = 0; r < rowCount; r += 1) {
2134
+ var cells = [];
2135
+ for (var c = 0; c < columnCount; c += 1) {
2136
+ cells.push(new TableCell(undefined, []));
2137
+ }
2138
+ rows.push(new TableRow([], undefined, cells));
2139
+ }
2140
+ var table = new Table([], defaultTblPr(), defaultTblGrid(columnCount), rows);
2141
+ for (var i = 0; i < rows.length; i += 1) {
2142
+ rows[i].setOwnerTable(table);
2143
+ }
2144
+ return table;
2145
+ }
2146
+ function parseOwningDocument(ctx) {
2147
+ try {
2148
+ return ctx.owningDocument();
2149
+ }
2150
+ catch (_e) {
2151
+ return undefined;
2152
+ }
2153
+ }
2154
+ function parseTable(element, ctx) {
2155
+ var __ts33_2;
2156
+ if (!isWml(element, 'tbl')) {
2157
+ return undefined;
2158
+ }
2159
+ var prefix = [];
2160
+ var tblPr;
2161
+ var tblGrid;
2162
+ var rows = [];
2163
+ var kids = elementChildren(element);
2164
+ for (var i = 0; i < kids.length; i += 1) {
2165
+ var child = kids[i];
2166
+ if (isWml(child, 'tblPr') && tblPr === undefined) {
2167
+ tblPr = child;
2168
+ continue;
2169
+ }
2170
+ if (isWml(child, 'tblGrid') && tblGrid === undefined) {
2171
+ tblGrid = child;
2172
+ continue;
2173
+ }
2174
+ if (isWml(child, 'tr')) {
2175
+ rows.push(parseRow(child, ctx));
2176
+ continue;
2177
+ }
2178
+ if (tblPr === undefined) {
2179
+ prefix.push(child);
2180
+ }
2181
+ }
2182
+ if (tblPr === undefined) {
2183
+ tblPr = defaultTblPr();
2184
+ }
2185
+ if (tblGrid === undefined) {
2186
+ var firstRow = rows[0];
2187
+ var cols = ((__ts33_2 =
2188
+ firstRow == null ? undefined : firstRow.listCells().length),
2189
+ __ts33_2 != null ? __ts33_2 : 1);
2190
+ tblGrid = defaultTblGrid(Math.max(cols, 1));
2191
+ }
2192
+ if (rows.length < 1) {
2193
+ // Enforce ≥1 row for modeled tables.
2194
+ var paragraph = new Paragraph(undefined);
2195
+ var cell = new TableCell(parseOwningDocument(ctx), [
2196
+ { type: 'paragraph', paragraph: paragraph },
2197
+ ]);
2198
+ rows.push(new TableRow([], undefined, [cell]));
2199
+ }
2200
+ var table = new Table(prefix, tblPr, tblGrid, rows);
2201
+ for (var i = 0; i < rows.length; i += 1) {
2202
+ rows[i].setOwnerTable(table);
2203
+ if (parseOwningDocument(ctx) !== undefined) {
2204
+ rows[i].bindDocument(parseOwningDocument(ctx));
2205
+ }
2206
+ }
2207
+ if (parseOwningDocument(ctx) !== undefined) {
2208
+ table.bindDocument(parseOwningDocument(ctx));
2209
+ }
2210
+ return table;
2211
+ }
2212
+ function parseRow(element, ctx) {
2213
+ var extras = [];
2214
+ var trPr;
2215
+ var cells = [];
2216
+ var kids = elementChildren(element);
2217
+ for (var i = 0; i < kids.length; i += 1) {
2218
+ var child = kids[i];
2219
+ if (isWml(child, 'trPr') && trPr === undefined) {
2220
+ trPr = child;
2221
+ continue;
2222
+ }
2223
+ if (isWml(child, 'tc')) {
2224
+ cells.push(parseCell(child, ctx));
2225
+ continue;
2226
+ }
2227
+ extras.push(child);
2228
+ }
2229
+ if (cells.length < 1) {
2230
+ var paragraph = new Paragraph(undefined);
2231
+ cells.push(new TableCell(parseOwningDocument(ctx), [{ type: 'paragraph', paragraph: paragraph }]));
2232
+ }
2233
+ return new TableRow(extras, trPr, cells);
2234
+ }
2235
+ function parseCell(element, ctx) {
2236
+ var tcPr;
2237
+ var content = [];
2238
+ var kids = elementChildren(element);
2239
+ for (var i = 0; i < kids.length; i += 1) {
2240
+ var child = kids[i];
2241
+ if (isWml(child, 'tcPr') && tcPr === undefined) {
2242
+ tcPr = child;
2243
+ continue;
2244
+ }
2245
+ content.push(child);
2246
+ }
2247
+ var blocks = parseBodyBlocks(content, ctx);
2248
+ var cell = new TableCell(parseOwningDocument(ctx), blocks);
2249
+ cell.applyTcPr(tcPr);
2250
+ return cell;
2251
+ }
2252
+ var registered = false;
2253
+ /**
2254
+ * @private
2255
+ * Test hook
2256
+ */
2257
+ export function resetTablesFeatureForTests() {
2258
+ registered = false;
2259
+ }
2260
+ function visitTableParagraphs(table, visit) {
2261
+ var rows = table.listRows();
2262
+ for (var r = 0; r < rows.length; r += 1) {
2263
+ var cells = rows[r].listCells();
2264
+ for (var c = 0; c < cells.length; c += 1) {
2265
+ // Nested feature blocks (tables, content controls) use registered walkers.
2266
+ visitBlocksInDocumentOrder(cells[c].listBlocks(), visit);
2267
+ }
2268
+ }
2269
+ }
2270
+ /**
2271
+ * @private
2272
+ * Register the tables feature block handler. Idempotent.
2273
+ */
2274
+ export function registerTablesFeature() {
2275
+ if (registered) {
2276
+ return;
2277
+ }
2278
+ registered = true;
2279
+ registerFeature({ id: TABLES });
2280
+ registerFeatureBlockHandler({
2281
+ featureId: TABLES,
2282
+ wmlLocalName: 'tbl',
2283
+ tryParse: parseTable,
2284
+ });
2285
+ registerFeatureBlockParagraphWalker({
2286
+ featureId: TABLES,
2287
+ visitParagraphs: function (block, visit) {
2288
+ if (block instanceof Table) {
2289
+ visitTableParagraphs(block, visit);
2290
+ }
2291
+ },
2292
+ });
2293
+ registerBodyItemAdapter({
2294
+ project: function (block) {
2295
+ if (block.featureId === TABLES && block.value instanceof Table) {
2296
+ return block.value;
2297
+ }
2298
+ return undefined;
2299
+ },
2300
+ toBlock: function (item) {
2301
+ if (item instanceof Table) {
2302
+ return { type: 'feature', featureId: TABLES, value: item };
2303
+ }
2304
+ return undefined;
2305
+ },
2306
+ isInstance: function (item) {
2307
+ return item instanceof Table;
2308
+ },
2309
+ });
2310
+ registerTypedCollectionHooks({
2311
+ isTable: function (item) {
2312
+ return item instanceof Table;
2313
+ },
2314
+ createTable: function () {
2315
+ return createTable(1, 1);
2316
+ },
2317
+ });
2318
+ }
2319
+ /**
2320
+ * Feature id constant for the tables module (used by host features that embed
2321
+ * table blocks, e.g. text box bodies in the drawing module).
2322
+ *
2323
+ * @private
2324
+ */
2325
+ export var TABLES_FEATURE_ID = TABLES;
2326
+ /**
2327
+ * Type guard for a tables feature block on a {@link BodyItem} list.
2328
+ *
2329
+ * @private
2330
+ */
2331
+ export function isTableBlock(block) {
2332
+ if (block instanceof Table) {
2333
+ return true;
2334
+ }
2335
+ if (typeof block !== 'object' || block === null) {
2336
+ return false;
2337
+ }
2338
+ var candidate = block;
2339
+ return (candidate.type === 'feature' &&
2340
+ candidate.featureId === TABLES &&
2341
+ candidate.value instanceof Table);
2342
+ }
2343
+ /** True when `value` is a public Table body item instance. */
2344
+ export function isTableBodyItem(value) {
2345
+ return value instanceof Table;
2346
+ }
2347
+ Object.defineProperty(Body.prototype, 'appendTable', {
2348
+ value: function () {
2349
+ // Always 1×1; callers size the grid with Table.resetCells(rows, columns).
2350
+ var table = createTable(1, 1);
2351
+ this.appendRawBlock({ type: 'feature', featureId: TABLES, value: table });
2352
+ try {
2353
+ var doc = this.owningDocument();
2354
+ table.bindDocument(doc);
2355
+ }
2356
+ catch (_e) {
2357
+ /* detached body during construction */
2358
+ }
2359
+ // Authoring defaults: TableGrid, fixed layout, equal client-width columns.
2360
+ applyAuthoringTableDefaults(table, 1);
2361
+ // Trailing empty paragraph after the table in the same container (not inside a cell).
2362
+ var blocks = this.listBlocks();
2363
+ var last = blocks.length > 0 ? blocks[blocks.length - 1] : undefined;
2364
+ var alreadyTrailingEmpty = false;
2365
+ if (last !== undefined && last.type === 'paragraph' && last.paragraph !== undefined) {
2366
+ alreadyTrailingEmpty = last.paragraph.items.length === 0;
2367
+ }
2368
+ if (!alreadyTrailingEmpty) {
2369
+ this.appendParagraph();
2370
+ }
2371
+ return table;
2372
+ },
2373
+ writable: true,
2374
+ configurable: true,
2375
+ });
2376
+ Object.defineProperty(WordDocument.prototype, 'appendTable', {
2377
+ value: function () {
2378
+ return this.firstSectionBody().appendTable();
2379
+ },
2380
+ writable: true,
2381
+ configurable: true,
2382
+ });
2383
+ registerAlwaysOnBodyFeatureBootstrap(function () {
2384
+ registerTablesFeature();
2385
+ });
2386
+ registerTablesFeature();