@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,3239 @@
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
+ var __assign = (this && this.__assign) || function () {
15
+ __assign = Object.assign || function(t) {
16
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
17
+ s = arguments[i];
18
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
19
+ t[p] = s[p];
20
+ }
21
+ return t;
22
+ };
23
+ return __assign.apply(this, arguments);
24
+ };
25
+ var __values = (this && this.__values) || function (o) {
26
+ var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
27
+ if (m) return m.call(o);
28
+ return {
29
+ next: function () {
30
+ if (o && i >= o.length) o = void 0;
31
+ return { value: o && o[i++], done: !o };
32
+ }
33
+ };
34
+ };
35
+ var __read = (this && this.__read) || function (o, n) {
36
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
37
+ if (!m) return o;
38
+ var i = m.call(o), r, ar = [], e;
39
+ try {
40
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
41
+ }
42
+ catch (error) { e = { error: error }; }
43
+ finally {
44
+ try {
45
+ if (r && !r.done && (m = i["return"])) m.call(i);
46
+ }
47
+ finally { if (e) throw e.error; }
48
+ }
49
+ return ar;
50
+ };
51
+ var __spread = (this && this.__spread) || function () {
52
+ for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
53
+ return ar;
54
+ };
55
+ import { EntityType } from '../document/entity-type';
56
+ import { pointToEmus, pointToCoordinateEmus, emuToPoint } from '../document/length';
57
+ import { Body } from '../document/body';
58
+ import { Paragraph } from '../document/paragraph';
59
+ import { FeatureRunParagraphItem } from '../document/text-range';
60
+ import { isWml, wmlElement } from '../document/wml';
61
+ import { DetachedObjectError, DocxError } from '../../core/errors/docx-error';
62
+ import { assertEnumMember, HORIZONTAL_ALIGNMENT_SET, HORIZONTAL_ORIGIN_SET, TEXT_WRAPPING_STYLE_SET, TEXT_WRAPPING_TYPE_SET, TextWrappingStyle, TextWrappingType, VERTICAL_ALIGNMENT_SET, VERTICAL_ORIGIN_SET, HorizontalAlignment as HorizontalAlignmentType, HorizontalOrigin as HorizontalOriginType, VerticalAlignment as VerticalAlignmentType, VerticalOrigin as VerticalOriginType } from '../images/layout-types';
63
+ import { isTableBlock, isTableBodyItem } from '../tables/index';
64
+ import { ContentControl } from '../content-controls/index';
65
+ import { isBlockContentControl } from '../content-controls/index';
66
+ function bindFeatureBlockToDocument(value, document) {
67
+ if (document === undefined) {
68
+ return;
69
+ }
70
+ if (typeof value !== 'object' || value === null || !('bindDocument' in value)) {
71
+ return;
72
+ }
73
+ var bindDocument = value.bindDocument;
74
+ bindDocument.call(value, document);
75
+ }
76
+ import { buildNestedWpsShape, encodeAuthoredDrawingShape, encodeAuthoredGroup, findFirstElement, isNestedDrawingResidual, preferredDrawingElement, patchResidualCNvPr, patchResidualDocPr, patchResidualLayout, readCNvPrIdentity, readDocPrIdentity, readDrawingLayout, readDrawingPositionState, readDrawingWrapState, WP_NS, WPS_NS, parseTxbxContentBlocks, serializeTxbxContentBlocks } from './host-codec';
77
+ import { readShapePropertiesState } from './sp-pr';
78
+ import { buildBodyPrElement, findTxbxContentElement, findTxbxElement, readBodyPropertiesState } from './body-pr';
79
+ import { AutoShapeType, isPresetAutoShapeType, isStShapeType } from './shape-types';
80
+ import { defaultAuthoredShapeFill, FillFormat } from './fill-format';
81
+ import { defaultAuthoredShapeLine, LineFormat } from './line-format';
82
+ import { WrapFormat } from './wrap-format';
83
+ import { TextFrame } from './text-frame';
84
+ import { ANCHOR_DEFAULT_SIDE_DIST_EMU } from './types';
85
+ import { cloneResidualElement, collectRelationshipIds, detectDmlVariant, detectVmlVariant, elementChildren, emptyTxbxParagraphBlocks, findNestedDrawingContainer, residualHasVmlFallback, } from './residual-utils';
86
+ import { drawingShapeInit, encodeDrawingShapeInput, encodeGroupInput, modeledFillForEncode, modeledLineForEncode, } from './encode-builders';
87
+ import { allocateDocPrId } from './parse-register';
88
+ /**
89
+ * Shape `w:txbxContent` story as a document {@link Body}.
90
+ * Syncs the live block store back onto the parent shape on mutate.
91
+ * @private
92
+ */
93
+ var ShapeTextBoxBody = /** @class */ (function (_super) {
94
+ __extends(ShapeTextBoxBody, _super);
95
+ function ShapeTextBoxBody(hostShape, document, items) {
96
+ var _this = _super.call(this, document, items) || this;
97
+ _this.hostShape = hostShape;
98
+ return _this;
99
+ }
100
+ /**
101
+ * @private
102
+ */
103
+ ShapeTextBoxBody.prototype.replaceRawBlocks = function (blocks) {
104
+ _super.prototype.replaceRawBlocks.call(this, blocks);
105
+ this.hostShape.syncTxbxBlocksFromBody(this.rawBlocks());
106
+ };
107
+ /**
108
+ * @private
109
+ * Prefer the shape anchor document when the body was constructed detached.
110
+ */
111
+ ShapeTextBoxBody.prototype.owningDocument = function () {
112
+ try {
113
+ return _super.prototype.owningDocument.call(this);
114
+ }
115
+ catch (e) {
116
+ return this.hostShape.internalOwningDocument();
117
+ }
118
+ };
119
+ return ShapeTextBoxBody;
120
+ }(Body));
121
+ var TextBoxParagraphOwner = /** @class */ (function () {
122
+ function TextBoxParagraphOwner(shape) {
123
+ this.shape = shape;
124
+ }
125
+ TextBoxParagraphOwner.prototype.assertAttachedParagraph = function (target) {
126
+ if (!blockListOwnsParagraph(this.shape.internalBlocks(), target)) {
127
+ throw new DetachedObjectError('Paragraph is not in this text box');
128
+ }
129
+ };
130
+ /**
131
+ * @private
132
+ */
133
+ TextBoxParagraphOwner.prototype.owningDocument = function () {
134
+ // Text box paragraphs live inside the run leaf; the owning document is the
135
+ // document that owns the anchoring paragraph. Resolve lazily through the
136
+ // shape's anchor paragraph when bound; otherwise detached.
137
+ return this.shape.internalOwningDocument();
138
+ };
139
+ return TextBoxParagraphOwner;
140
+ }());
141
+ export { TextBoxParagraphOwner };
142
+ /** Deep membership check: direct or nested (table cell / SDT) paragraph. */
143
+ export function blockListOwnsParagraph(blocks, target) {
144
+ var e_1, _a;
145
+ try {
146
+ for (var blocks_1 = __values(blocks), blocks_1_1 = blocks_1.next(); !blocks_1_1.done; blocks_1_1 = blocks_1.next()) {
147
+ var block = blocks_1_1.value;
148
+ if (block.type === 'paragraph' && block.paragraph === target) {
149
+ return true;
150
+ }
151
+ if (isTableBlock(block)) {
152
+ if (tableOwnsParagraph(block.value, target)) {
153
+ return true;
154
+ }
155
+ }
156
+ if (isBlockContentControl(block)) {
157
+ var inner = block.value.blockContentControl;
158
+ if (inner !== undefined && bodyItemsOwnParagraph(inner, target)) {
159
+ return true;
160
+ }
161
+ }
162
+ }
163
+ }
164
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
165
+ finally {
166
+ try {
167
+ if (blocks_1_1 && !blocks_1_1.done && (_a = blocks_1.return)) _a.call(blocks_1);
168
+ }
169
+ finally { if (e_1) throw e_1.error; }
170
+ }
171
+ return false;
172
+ }
173
+ /** Membership over projected public body items (nested SDT children). */
174
+ function bodyItemsOwnParagraph(items, target) {
175
+ var e_2, _a;
176
+ try {
177
+ for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
178
+ var item = items_1_1.value;
179
+ if (item instanceof Paragraph && item === target) {
180
+ return true;
181
+ }
182
+ if (isTableBodyItem(item)) {
183
+ if (tableOwnsParagraph(item, target)) {
184
+ return true;
185
+ }
186
+ }
187
+ if (item instanceof ContentControl) {
188
+ var nested = item.blockContentControl;
189
+ if (nested !== undefined && bodyItemsOwnParagraph(nested, target)) {
190
+ return true;
191
+ }
192
+ }
193
+ }
194
+ }
195
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
196
+ finally {
197
+ try {
198
+ if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
199
+ }
200
+ finally { if (e_2) throw e_2.error; }
201
+ }
202
+ return false;
203
+ }
204
+ export function tableOwnsParagraph(table, target) {
205
+ var e_3, _a, e_4, _b, e_5, _c, e_6, _d;
206
+ try {
207
+ for (var _e = __values(table.rows.toArray()), _f = _e.next(); !_f.done; _f = _e.next()) {
208
+ var row = _f.value;
209
+ try {
210
+ for (var _g = __values(row.cells.toArray()), _h = _g.next(); !_h.done; _h = _g.next()) {
211
+ var cell = _h.value;
212
+ try {
213
+ for (var _j = __values(cell.listParagraphs()), _k = _j.next(); !_k.done; _k = _j.next()) {
214
+ var cellParagraph = _k.value;
215
+ if (cellParagraph === target) {
216
+ return true;
217
+ }
218
+ }
219
+ }
220
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
221
+ finally {
222
+ try {
223
+ if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
224
+ }
225
+ finally { if (e_5) throw e_5.error; }
226
+ }
227
+ try {
228
+ for (var _l = __values(cell.nestedTables), _m = _l.next(); !_m.done; _m = _l.next()) {
229
+ var nested = _m.value;
230
+ if (tableOwnsParagraph(nested, target)) {
231
+ return true;
232
+ }
233
+ }
234
+ }
235
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
236
+ finally {
237
+ try {
238
+ if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
239
+ }
240
+ finally { if (e_6) throw e_6.error; }
241
+ }
242
+ }
243
+ }
244
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
245
+ finally {
246
+ try {
247
+ if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
248
+ }
249
+ finally { if (e_4) throw e_4.error; }
250
+ }
251
+ }
252
+ }
253
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
254
+ finally {
255
+ try {
256
+ if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
257
+ }
258
+ finally { if (e_3) throw e_3.error; }
259
+ }
260
+ return false;
261
+ }
262
+ /**
263
+ * Minimum `w:txbxContent` body: one empty paragraph (`EG_BlockLevelElts`
264
+ * minOccurs=1 — `CT_TxbxContent` cannot be empty; Word authors a bare `w:p`).
265
+ */
266
+ /**
267
+ * Shared base for DrawingML / VML run leaves: identity, placement, size,
268
+ * rotation/flip/lock, wrap/distances, position, residual dirty plumbing, and
269
+ * `FeatureRunLeaf` serialization.
270
+ *
271
+ * Concrete leaves are {@link Shape}; group/canvas hosts are {@link GroupShape}.
272
+ * Prefer those subclasses (and {@link createDrawingShape}) at construction time.
273
+ * `instanceof DrawingShape` remains true for both subclasses so existing leaf
274
+ * guards keep working.
275
+ *
276
+ * Clean load/save is residual pass-through. Identity mutators patch `wp:docPr`
277
+ * only. Layout mutators (size/rotation/lock/flip) patch residual extent+xfrm+locks
278
+ * without full dual-AC rebuild. Position mutators (H/V origin, offset vs align,
279
+ * `lockAnchor`/`allowOverlap`/`layoutInCell`) mark the shape structure dirty:
280
+ * the dual MC shell is re-encoded with residual position preserved per-axis
281
+ * when a mode was not modeled. Authoring (`appendShape`) emits dual MC
282
+ * AlternateContent (Choice wps + Fallback VML stub) — GO Policy B.
283
+ * Text box leaves expose `wps:bodyPr` typed state and the `w:txbxContent`
284
+ * block body (paragraphs / tables / nested tables / block SDTs — GO Q6);
285
+ * non-textBox shapes throw on body APIs (TASK-8049).
286
+ *
287
+ * @private
288
+ */
289
+ var DrawingShape = /** @class */ (function () {
290
+ /**
291
+ * @private
292
+ */
293
+ function DrawingShape(encodingOrInit, element) {
294
+ var e_7, _a;
295
+ /** Whether a horizontal position mode (offset or align) is explicitly modeled. */
296
+ this.horizontalModeled = false;
297
+ /** Whether a vertical position mode (offset or align) is explicitly modeled. */
298
+ this.verticalModeled = false;
299
+ if (typeof encodingOrInit === 'string') {
300
+ if (element === undefined) {
301
+ throw new TypeError('DrawingShape residual element is required');
302
+ }
303
+ this.encodingValue = encodingOrInit;
304
+ this.residual = element;
305
+ this.dirtyMode = 'clean';
306
+ var identity = isNestedDrawingResidual(element)
307
+ ? readCNvPrIdentity(element)
308
+ : readDocPrIdentity(element);
309
+ this.nameValue = identity.name;
310
+ this.titleValue = identity.title;
311
+ this.descriptionValue = identity.description;
312
+ this.docPrIdValue = identity.docPrId;
313
+ this.distancesModeled = false;
314
+ this.behindDocumentModeled = false;
315
+ this.fillModeled = false;
316
+ this.lineModeled = false;
317
+ this.txbxBodyModeled = false;
318
+ this.bodyPrModeled = false;
319
+ this.childrenValue = [];
320
+ this.childrenModeled = false;
321
+ this.childrenCache = undefined;
322
+ this.parentGroup = undefined;
323
+ // Layout / wrap / position / spPr fields stay undefined until first
324
+ // read/mtate so clean residual path does not force modeled defaults onto wire.
325
+ return;
326
+ }
327
+ this.encodingValue = encodingOrInit.encoding;
328
+ this.residual = encodingOrInit.residual;
329
+ this.dirtyMode = encodingOrInit.dirty;
330
+ this.nameValue = encodingOrInit.name;
331
+ this.titleValue = encodingOrInit.title;
332
+ this.descriptionValue = encodingOrInit.description;
333
+ this.docPrIdValue = encodingOrInit.docPrId;
334
+ this.placementValue = encodingOrInit.placement;
335
+ this.widthValue = encodingOrInit.width;
336
+ this.heightValue = encodingOrInit.height;
337
+ this.presetGeometryValue = encodingOrInit.presetGeometry;
338
+ this.rotationValue = encodingOrInit.rotation;
339
+ this.lockAspectRatioValue = encodingOrInit.lockAspectRatio;
340
+ this.flipHorizontalValue = encodingOrInit.flipHorizontal;
341
+ this.flipVerticalValue = encodingOrInit.flipVertical;
342
+ this.wrappingValue = encodingOrInit.wrapping;
343
+ this.wrappingTypeValue = encodingOrInit.wrapType;
344
+ this.distanceTopValue = encodingOrInit.distanceTop;
345
+ this.distanceBottomValue = encodingOrInit.distanceBottom;
346
+ this.distanceLeftValue = encodingOrInit.distanceLeft;
347
+ this.distanceRightValue = encodingOrInit.distanceRight;
348
+ this.behindDocumentValue = encodingOrInit.behindDocument;
349
+ this.distancesModeled =
350
+ encodingOrInit.distanceTop !== undefined ||
351
+ encodingOrInit.distanceBottom !== undefined ||
352
+ encodingOrInit.distanceLeft !== undefined ||
353
+ encodingOrInit.distanceRight !== undefined;
354
+ this.behindDocumentModeled = encodingOrInit.behindDocument !== undefined;
355
+ this.horizontalOriginValue = encodingOrInit.horizontalOrigin;
356
+ this.verticalOriginValue = encodingOrInit.verticalOrigin;
357
+ this.horizontalPositionValue = encodingOrInit.horizontalPosition;
358
+ this.verticalPositionValue = encodingOrInit.verticalPosition;
359
+ this.horizontalAlignmentValue = encodingOrInit.horizontalAlignment;
360
+ this.verticalAlignmentValue = encodingOrInit.verticalAlignment;
361
+ this.horizontalModeled =
362
+ encodingOrInit.horizontalPosition !== undefined ||
363
+ encodingOrInit.horizontalAlignment !== undefined ||
364
+ encodingOrInit.horizontalOrigin !== undefined;
365
+ this.verticalModeled =
366
+ encodingOrInit.verticalPosition !== undefined ||
367
+ encodingOrInit.verticalAlignment !== undefined ||
368
+ encodingOrInit.verticalOrigin !== undefined;
369
+ this.lockAnchorValue = encodingOrInit.lockAnchor;
370
+ this.allowOverlapValue = encodingOrInit.allowOverlap;
371
+ this.layoutInCellValue = encodingOrInit.layoutInCell;
372
+ this.fillValue = encodingOrInit.fill;
373
+ this.fillModeled = encodingOrInit.fill !== undefined;
374
+ this.lineValue = encodingOrInit.line;
375
+ this.lineModeled = encodingOrInit.line !== undefined;
376
+ this.txbxBodyModeled = encodingOrInit.txbxContent !== undefined;
377
+ this.bodyPrModeled = encodingOrInit.bodyPrElement !== undefined;
378
+ if (encodingOrInit.bodyPrElement !== undefined) {
379
+ this.bodyPrValue = readBodyPropertiesState(encodingOrInit.bodyPrElement);
380
+ }
381
+ this.childrenValue =
382
+ encodingOrInit.children !== undefined ? __spread(encodingOrInit.children) : [];
383
+ this.childrenModeled = encodingOrInit.children !== undefined;
384
+ this.childrenCache = undefined;
385
+ this.parentGroup = undefined;
386
+ if (this.childrenModeled) {
387
+ try {
388
+ for (var _b = __values(this.childrenValue), _c = _b.next(); !_c.done; _c = _b.next()) {
389
+ var child = _c.value;
390
+ child.parentGroup = this;
391
+ }
392
+ }
393
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
394
+ finally {
395
+ try {
396
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
397
+ }
398
+ finally { if (e_7) throw e_7.error; }
399
+ }
400
+ }
401
+ }
402
+ /**
403
+ * Whether this leaf is DrawingML (`w:drawing` / MC Choice) or VML (`w:pict`).
404
+ *
405
+ * @private
406
+ */
407
+ DrawingShape.prototype.encoding = function () {
408
+ return this.encodingValue;
409
+ };
410
+ /**
411
+ * Placement host for DrawingML leaves, or `unknown` for VML.
412
+ *
413
+ * @private
414
+ */
415
+ DrawingShape.prototype.placement = function () {
416
+ if (this.placementValue !== undefined) {
417
+ return this.placementValue;
418
+ }
419
+ if (this.encodingValue === 'vml') {
420
+ return 'unknown';
421
+ }
422
+ var drawing = this.drawingRoot();
423
+ if (drawing === undefined) {
424
+ return 'unknown';
425
+ }
426
+ if (findFirstElement(drawing, WP_NS, 'anchor') !== undefined) {
427
+ return 'anchor';
428
+ }
429
+ if (findFirstElement(drawing, WP_NS, 'inline') !== undefined) {
430
+ return 'inline';
431
+ }
432
+ return 'unknown';
433
+ };
434
+ /**
435
+ * Shape variant: kind of drawing object this leaf hosts.
436
+ *
437
+ * Detection is via `a:graphicData @uri` for DML and child element localName
438
+ * for VML. Modeled empty groups (`childrenModeled`) read as `'group'` before
439
+ * residual URI detection. Nested residual leaves (`wps:wsp` / `wpg:grpSp`)
440
+ * are classified from their own element when no `w:drawing` host is present
441
+ * (TASK-8051). Authored structure + presetGeometry still short-circuits to
442
+ * `'shape'` / `'textBox'` after group/canvas checks so residual groups are
443
+ * never misread as shapes.
444
+ *
445
+ * @private
446
+ */
447
+ DrawingShape.prototype.variant = function () {
448
+ if (this.encodingValue === 'vml') {
449
+ return detectVmlVariant(this.residual);
450
+ }
451
+ // Authored empty groups (and residual materialised children lists).
452
+ if (this.childrenModeled) {
453
+ return 'group';
454
+ }
455
+ // Nested residual shape/group hosts have no wp:docPr drawing root.
456
+ if (isNestedDrawingResidual(this.residual)) {
457
+ if (this.residual.localName === 'grpSp') {
458
+ return 'group';
459
+ }
460
+ if (this.txbxBodyModeled) {
461
+ return 'textBox';
462
+ }
463
+ if (this.presetGeometryValue !== undefined || this.dirtyMode === 'structure') {
464
+ return 'shape';
465
+ }
466
+ // Residual nested wsp: text box vs shape via local wps:txbx presence.
467
+ if (findFirstElement(this.residual, WPS_NS, 'txbx') !== undefined) {
468
+ return 'textBox';
469
+ }
470
+ return 'shape';
471
+ }
472
+ var drawing = this.drawingRoot();
473
+ if (drawing !== undefined) {
474
+ var fromUri = detectDmlVariant(drawing);
475
+ // Prefer residual group/canvas over structure+preset short-circuit so
476
+ // loaded groups never flip to 'shape' when geometry is later modeled.
477
+ if (fromUri === 'group' || fromUri === 'canvas') {
478
+ return fromUri;
479
+ }
480
+ }
481
+ if (this.presetGeometryValue !== undefined && this.dirtyMode === 'structure') {
482
+ return this.txbxBodyModeled ? 'textBox' : 'shape';
483
+ }
484
+ if (drawing === undefined) {
485
+ return 'unknown';
486
+ }
487
+ return detectDmlVariant(drawing);
488
+ };
489
+ /**
490
+ * Nested DrawingML children under a group or canvas host (TASK-8051).
491
+ *
492
+ * Leaf shapes, VML, and unknown variants return `[]`. Residual group/canvas
493
+ * hosts lazy-parse `wps:wsp` / `wpg:grpSp` under `wpg:wgp` or `wpc:wpc`.
494
+ * Modeled groups (including empty authored groups) return the owned list.
495
+ * Public consumers use {@link GroupShape.childShapes}.
496
+ *
497
+ * @private
498
+ */
499
+ DrawingShape.prototype.children = function () {
500
+ if (this.encodingValue === 'vml') {
501
+ return [];
502
+ }
503
+ if (this.childrenModeled) {
504
+ return this.childrenValue;
505
+ }
506
+ if (this.childrenCache !== undefined) {
507
+ return this.childrenCache;
508
+ }
509
+ var nested = this.parseNestedChildrenFromResidual();
510
+ this.childrenCache = nested;
511
+ return nested;
512
+ };
513
+ Object.defineProperty(DrawingShape.prototype, "name", {
514
+ /**
515
+ * Non-visual drawing name from `wp:docPr @name` / nested `cNvPr @name`.
516
+ * @public
517
+ */
518
+ get: function () {
519
+ if (this.nameValue !== undefined) {
520
+ return this.nameValue;
521
+ }
522
+ return this.readResidualIdentity().name;
523
+ },
524
+ set: function (value) {
525
+ this.nameValue = value;
526
+ this.markIdentityDirty();
527
+ },
528
+ enumerable: true,
529
+ configurable: true
530
+ });
531
+ Object.defineProperty(DrawingShape.prototype, "title", {
532
+ /**
533
+ * Title from `wp:docPr @title` / nested `cNvPr @title`.
534
+ * @public
535
+ */
536
+ get: function () {
537
+ if (this.dirtyMode !== 'clean' || this.titleValue !== undefined) {
538
+ return this.titleValue;
539
+ }
540
+ return this.readResidualIdentity().title;
541
+ },
542
+ set: function (value) {
543
+ this.titleValue = value;
544
+ this.markIdentityDirty();
545
+ },
546
+ enumerable: true,
547
+ configurable: true
548
+ });
549
+ Object.defineProperty(DrawingShape.prototype, "alternativeText", {
550
+ /**
551
+ * Alternative text from `wp:docPr @descr` / nested `cNvPr @descr`.
552
+ * @public
553
+ */
554
+ get: function () {
555
+ if (this.dirtyMode !== 'clean' || this.descriptionValue !== undefined) {
556
+ return this.descriptionValue;
557
+ }
558
+ return this.readResidualIdentity().description;
559
+ },
560
+ set: function (value) {
561
+ this.descriptionValue = value;
562
+ this.markIdentityDirty();
563
+ },
564
+ enumerable: true,
565
+ configurable: true
566
+ });
567
+ Object.defineProperty(DrawingShape.prototype, "fillFormat", {
568
+ /**
569
+ * Stable fill format facade (Shape.md).
570
+ * @public
571
+ */
572
+ get: function () {
573
+ if (this.fillFormatValue === undefined) {
574
+ this.fillFormatValue = new FillFormat(this);
575
+ }
576
+ return this.fillFormatValue;
577
+ },
578
+ enumerable: true,
579
+ configurable: true
580
+ });
581
+ Object.defineProperty(DrawingShape.prototype, "lineFormat", {
582
+ /**
583
+ * Stable line format facade (Shape.md).
584
+ * @public
585
+ */
586
+ get: function () {
587
+ if (this.lineFormatValue === undefined) {
588
+ this.lineFormatValue = new LineFormat(this);
589
+ }
590
+ return this.lineFormatValue;
591
+ },
592
+ enumerable: true,
593
+ configurable: true
594
+ });
595
+ Object.defineProperty(DrawingShape.prototype, "wrapFormat", {
596
+ /**
597
+ * Stable wrap format facade (Shape.md).
598
+ * @public
599
+ */
600
+ get: function () {
601
+ if (this.wrapFormatValue === undefined) {
602
+ this.wrapFormatValue = new WrapFormat(this);
603
+ }
604
+ return this.wrapFormatValue;
605
+ },
606
+ enumerable: true,
607
+ configurable: true
608
+ });
609
+ Object.defineProperty(DrawingShape.prototype, "textFrame", {
610
+ /**
611
+ * Stable text frame facade (Shape.md).
612
+ * @public
613
+ */
614
+ get: function () {
615
+ if (this.textFrameValue === undefined) {
616
+ this.textFrameValue = new TextFrame(this);
617
+ }
618
+ return this.textFrameValue;
619
+ },
620
+ enumerable: true,
621
+ configurable: true
622
+ });
623
+ Object.defineProperty(DrawingShape.prototype, "textBody", {
624
+ /**
625
+ * Text-box story content as a document {@link Body} (`w:txbxContent`).
626
+ * First access promotes the leaf to a text-box variant (`wps:txbx`).
627
+ * @public
628
+ */
629
+ get: function () {
630
+ this.ensureTextBodyAccessible();
631
+ if (this.textBodyValue === undefined) {
632
+ var state = this.readTxbxState();
633
+ var document_1;
634
+ try {
635
+ document_1 = this.internalOwningDocument();
636
+ }
637
+ catch (e) {
638
+ document_1 = undefined;
639
+ }
640
+ this.textBodyValue = new ShapeTextBoxBody(this, document_1, state.blocks);
641
+ // Share the Body store with the txbx cache (constructor copies once).
642
+ this.syncTxbxBlocksFromBody(this.textBodyValue.rawBlocks());
643
+ }
644
+ return this.textBodyValue;
645
+ },
646
+ enumerable: true,
647
+ configurable: true
648
+ });
649
+ Object.defineProperty(DrawingShape.prototype, "autoShapeType", {
650
+ /**
651
+ * Auto shape type from preset geometry. Returns AutoShapeType.Unknown when missing/unrecognized/VML; Custom for custGeom.
652
+ * @public
653
+ */
654
+ get: function () {
655
+ if (this.encodingValue === 'vml') {
656
+ return AutoShapeType.Unknown;
657
+ }
658
+ if (this.readSpPrState().useCustomGeometry) {
659
+ return AutoShapeType.Custom;
660
+ }
661
+ var token = this.presetGeometryToken;
662
+ if (token !== undefined && isStShapeType(token)) {
663
+ return token;
664
+ }
665
+ return AutoShapeType.Unknown;
666
+ },
667
+ enumerable: true,
668
+ configurable: true
669
+ });
670
+ /** @private */
671
+ DrawingShape.prototype.readShapeFillState = function () {
672
+ if (this.fillModeled) {
673
+ return this.fillValue;
674
+ }
675
+ if (this.encodingValue === 'vml') {
676
+ return undefined;
677
+ }
678
+ return this.readSpPrState().fill;
679
+ };
680
+ /** @private */
681
+ DrawingShape.prototype.writeShapeFillState = function (value) {
682
+ if (value !== undefined && value.kind !== 'solid' && value.kind !== 'none') {
683
+ throw new RangeError("Fill kind \"" + String(value.kind) + "\" cannot be authored; use solid or none");
684
+ }
685
+ this.fillValue = value;
686
+ this.fillModeled = true;
687
+ this.markStructureDirty();
688
+ };
689
+ /** @private */
690
+ DrawingShape.prototype.readShapeLineState = function () {
691
+ if (this.lineModeled) {
692
+ return this.lineValue;
693
+ }
694
+ if (this.encodingValue === 'vml') {
695
+ return undefined;
696
+ }
697
+ return this.readSpPrState().line;
698
+ };
699
+ /** @private */
700
+ DrawingShape.prototype.writeShapeLineState = function (value) {
701
+ if (value !== undefined && value.kind !== 'solid' && value.kind !== 'none') {
702
+ throw new RangeError("Line kind \"" + String(value.kind) + "\" cannot be authored; use solid or none");
703
+ }
704
+ if (value !== undefined && value.kind === 'solid' && value.srgbColor === undefined) {
705
+ throw new RangeError('Solid line requires an sRGB color');
706
+ }
707
+ this.lineValue = value;
708
+ this.lineModeled = true;
709
+ this.markStructureDirty();
710
+ };
711
+ /** @private */
712
+ DrawingShape.prototype.readWrapStyle = function () {
713
+ return this.wrappingStyleInternal;
714
+ };
715
+ /** @private */
716
+ DrawingShape.prototype.writeWrapStyle = function (value) {
717
+ this.wrappingStyleInternal = value;
718
+ };
719
+ /** @private */
720
+ DrawingShape.prototype.readWrapType = function () {
721
+ if (this.wrappingTypeValue !== undefined) {
722
+ return this.wrappingTypeValue;
723
+ }
724
+ if (this.encodingValue === 'vml') {
725
+ return TextWrappingType.Both;
726
+ }
727
+ return readDrawingWrapState(this.residual).wrapType;
728
+ };
729
+ /** @private */
730
+ DrawingShape.prototype.writeWrapType = function (value) {
731
+ if (value === TextWrappingType.Unknown) {
732
+ throw new RangeError('WrapFormat.textWrappingType cannot be set to TextWrappingType.Unknown');
733
+ }
734
+ assertEnumMember('wrapType', value, TEXT_WRAPPING_TYPE_SET);
735
+ this.wrappingTypeValue = value;
736
+ this.markStructureDirty();
737
+ };
738
+ /** @private */
739
+ DrawingShape.prototype.readAllowOverlap = function () {
740
+ return this.allowOverlapInternal;
741
+ };
742
+ /** @private */
743
+ DrawingShape.prototype.writeAllowOverlap = function (value) {
744
+ this.allowOverlapInternal = value;
745
+ };
746
+ /** @private */
747
+ DrawingShape.prototype.readDistanceTop = function () {
748
+ return this.distanceTopInternal;
749
+ };
750
+ /** @private */
751
+ DrawingShape.prototype.writeDistanceTop = function (value) {
752
+ this.distanceTopInternal = value;
753
+ };
754
+ /** @private */
755
+ DrawingShape.prototype.readDistanceBottom = function () {
756
+ return this.distanceBottomInternal;
757
+ };
758
+ /** @private */
759
+ DrawingShape.prototype.writeDistanceBottom = function (value) {
760
+ this.distanceBottomInternal = value;
761
+ };
762
+ /** @private */
763
+ DrawingShape.prototype.readDistanceLeft = function () {
764
+ return this.distanceLeftInternal;
765
+ };
766
+ /** @private */
767
+ DrawingShape.prototype.writeDistanceLeft = function (value) {
768
+ this.distanceLeftInternal = value;
769
+ };
770
+ /** @private */
771
+ DrawingShape.prototype.readDistanceRight = function () {
772
+ return this.distanceRightInternal;
773
+ };
774
+ /** @private */
775
+ DrawingShape.prototype.writeDistanceRight = function (value) {
776
+ this.distanceRightInternal = value;
777
+ };
778
+ /** @private */
779
+ DrawingShape.prototype.readTextFrameDirection = function () {
780
+ return this.textDirection;
781
+ };
782
+ /** @private */
783
+ DrawingShape.prototype.writeTextFrameDirection = function (value) {
784
+ this.textDirection = value;
785
+ };
786
+ /** @private */
787
+ DrawingShape.prototype.readTextFrameVerticalAlignment = function () {
788
+ return this.verticalAnchor;
789
+ };
790
+ /** @private */
791
+ DrawingShape.prototype.writeTextFrameVerticalAlignment = function (value) {
792
+ this.verticalAnchor = value;
793
+ };
794
+ /** @private */
795
+ DrawingShape.prototype.readInternalMarginLeft = function () {
796
+ return this.readInsetPoints('left', 91440);
797
+ };
798
+ /** @private */
799
+ DrawingShape.prototype.writeInternalMarginLeft = function (value) {
800
+ this.writeInsetPoints('left', value);
801
+ };
802
+ /** @private */
803
+ DrawingShape.prototype.readInternalMarginTop = function () {
804
+ return this.readInsetPoints('top', 45720);
805
+ };
806
+ /** @private */
807
+ DrawingShape.prototype.writeInternalMarginTop = function (value) {
808
+ this.writeInsetPoints('top', value);
809
+ };
810
+ /** @private */
811
+ DrawingShape.prototype.readInternalMarginRight = function () {
812
+ return this.readInsetPoints('right', 91440);
813
+ };
814
+ /** @private */
815
+ DrawingShape.prototype.writeInternalMarginRight = function (value) {
816
+ this.writeInsetPoints('right', value);
817
+ };
818
+ /** @private */
819
+ DrawingShape.prototype.readInternalMarginBottom = function () {
820
+ return this.readInsetPoints('bottom', 45720);
821
+ };
822
+ /** @private */
823
+ DrawingShape.prototype.writeInternalMarginBottom = function (value) {
824
+ this.writeInsetPoints('bottom', value);
825
+ };
826
+ /** @private */
827
+ DrawingShape.prototype.readBodyInsets = function () {
828
+ return this.insets;
829
+ };
830
+ /** @private */
831
+ DrawingShape.prototype.writeBodyInsets = function (value) {
832
+ this.insets = value;
833
+ };
834
+ /**
835
+ * BodyInsets sides are **points** (body-pr parse/build converts at the
836
+ * wire boundary). Defaults are Word bodyPr EMU constants converted once.
837
+ * @private
838
+ */
839
+ DrawingShape.prototype.readInsetPoints = function (side, defaultEmu) {
840
+ var insets = this.readBodyInsets();
841
+ var points;
842
+ if (insets !== undefined) {
843
+ if (side === 'left')
844
+ points = insets.left;
845
+ else if (side === 'top')
846
+ points = insets.top;
847
+ else if (side === 'right')
848
+ points = insets.right;
849
+ else
850
+ points = insets.bottom;
851
+ }
852
+ if (points !== undefined) {
853
+ return points;
854
+ }
855
+ return emuToPoint(defaultEmu);
856
+ };
857
+ /**
858
+ * Store InternalMargin sides as points on BodyInsets (same unit as
859
+ * body-pr model). Do not convert to EMU here — buildBodyPrElement does.
860
+ * @private
861
+ */
862
+ DrawingShape.prototype.writeInsetPoints = function (side, points) {
863
+ var prev = this.readBodyInsets() || {};
864
+ var next = {
865
+ left: prev.left,
866
+ top: prev.top,
867
+ right: prev.right,
868
+ bottom: prev.bottom,
869
+ };
870
+ if (side === 'left')
871
+ next.left = points;
872
+ else if (side === 'top')
873
+ next.top = points;
874
+ else if (side === 'right')
875
+ next.right = points;
876
+ else
877
+ next.bottom = points;
878
+ this.writeBodyInsets(next);
879
+ };
880
+ /** @private */
881
+ DrawingShape.prototype.ensureTextBodyAccessible = function () {
882
+ // Keep the live DOM empty until the caller appends body content.
883
+ // Wire format still requires CT_TxbxContent minOccurs=1: serialize paths
884
+ // fall back to emptyTxbxParagraphBlocks() when blocks.length === 0.
885
+ this.readTxbxState();
886
+ // First textBody access promotes the leaf to a textBox variant (wps:txbx).
887
+ this.markTxbxBodyModeled();
888
+ };
889
+ /**
890
+ * @private
891
+ * Point the txbx cache at the Body block store after Body mutations.
892
+ */
893
+ DrawingShape.prototype.syncTxbxBlocksFromBody = function (blocks) {
894
+ var state = this.readTxbxState();
895
+ // TextBoxStateCached.blocks is readonly on the type but the cache is live.
896
+ state.blocks = blocks;
897
+ this.markTxbxBodyModeled();
898
+ this.markStructureDirty();
899
+ };
900
+ /**
901
+ * Append a nested preset-geometry shape under this group or canvas (TASK-8051).
902
+ *
903
+ * Only valid when {@link variant} is `'group'` or `'canvas'`. Nested children
904
+ * serialize as bare `wps:wsp` (with `wps:cNvPr`) under `wpg:wgp` / `wpc:wpc`
905
+ * — not as a second `w:drawing` host. Marks this host structure-dirty.
906
+ *
907
+ * @throws DocxError `content/invalid-shape` when the host is not a group/canvas,
908
+ * or when geometry/size options are invalid.
909
+ *
910
+ * Public consumers call {@link GroupShape.appendShape}.
911
+ *
912
+ * @private
913
+ */
914
+ /**
915
+ * Append a nested preset-geometry {@link Shape} under this group or canvas.
916
+ * @public
917
+ */
918
+ DrawingShape.prototype.appendShape = function (autoShapeType, width, height) {
919
+ var hostVariant = this.variant();
920
+ if (hostVariant !== 'group' && hostVariant !== 'canvas') {
921
+ throw new DocxError('content/invalid-shape', "appendShape is only valid on group or canvas hosts; variant is \"" + hostVariant + "\"");
922
+ }
923
+ if (!isPresetAutoShapeType(autoShapeType)) {
924
+ throw new DocxError('content/invalid-shape', "Invalid autoShapeType \"" + String(autoShapeType) + "\"; expected a preset AutoShapeType token");
925
+ }
926
+ var widthEmu;
927
+ var heightEmu;
928
+ try {
929
+ widthEmu = pointToEmus(width);
930
+ heightEmu = pointToEmus(height);
931
+ }
932
+ catch (error) {
933
+ if (error instanceof RangeError) {
934
+ throw new DocxError('content/invalid-shape', 'Shape width and height must be positive point values', { cause: error });
935
+ }
936
+ throw error;
937
+ }
938
+ if (!(widthEmu > 0) || !(heightEmu > 0)) {
939
+ throw new DocxError('content/invalid-shape', 'Shape width and height must be positive point values');
940
+ }
941
+ var rotation = 0;
942
+ var name = 'Shape';
943
+ var lockAspectRatio = true;
944
+ var flipHorizontal = false;
945
+ var flipVertical = false;
946
+ var docPrId = this.allocateNestedDocPrId();
947
+ var defaultFill = defaultAuthoredShapeFill();
948
+ var defaultLine = defaultAuthoredShapeLine();
949
+ var nestedWsp = buildNestedWpsShape({
950
+ placement: 'anchor',
951
+ widthEmu: widthEmu,
952
+ heightEmu: heightEmu,
953
+ presetGeometry: autoShapeType,
954
+ docPrId: docPrId,
955
+ name: name,
956
+ title: undefined,
957
+ description: undefined,
958
+ rotation: rotation,
959
+ flipHorizontal: flipHorizontal,
960
+ flipVertical: flipVertical,
961
+ lockAspectRatio: lockAspectRatio,
962
+ txbxContent: undefined,
963
+ bodyPr: undefined,
964
+ fill: defaultFill,
965
+ line: modeledLineForEncode(defaultLine),
966
+ });
967
+ this.ensureChildrenModeled();
968
+ var child = new Shape(drawingShapeInit({
969
+ encoding: 'drawingml',
970
+ residual: nestedWsp,
971
+ dirty: 'structure',
972
+ name: name,
973
+ title: undefined,
974
+ description: undefined,
975
+ docPrId: docPrId,
976
+ width: width,
977
+ height: height,
978
+ presetGeometry: autoShapeType,
979
+ rotation: rotation,
980
+ lockAspectRatio: lockAspectRatio,
981
+ flipHorizontal: flipHorizontal,
982
+ flipVertical: flipVertical,
983
+ fill: defaultFill,
984
+ line: defaultLine,
985
+ }));
986
+ child.parentGroup = this;
987
+ this.childrenValue.push(child);
988
+ this.childrenModeled = true;
989
+ this.childrenCache = undefined;
990
+ this.markStructureDirty();
991
+ this.notifyParentOfChildDirty();
992
+ return child;
993
+ };
994
+ /**
995
+ * Extent (width × height) from modeled size or `wp:extent`, as point `number`.
996
+ *
997
+ * Returns `undefined` when no size is modeled and no `wp:extent` / `a:ext`
998
+ * is reachable with numeric `cx`/`cy`. VML leaves return `undefined`.
999
+ *
1000
+ * @private
1001
+ */
1002
+ DrawingShape.prototype.extent = function () {
1003
+ if (this.widthValue !== undefined && this.heightValue !== undefined) {
1004
+ return { width: this.widthValue, height: this.heightValue };
1005
+ }
1006
+ if (this.encodingValue === 'vml') {
1007
+ return undefined;
1008
+ }
1009
+ var layout = readDrawingLayout(this.residual);
1010
+ if (layout.widthEmu !== undefined && layout.heightEmu !== undefined) {
1011
+ return { width: emuToPoint(layout.widthEmu), height: emuToPoint(layout.heightEmu) };
1012
+ }
1013
+ return undefined;
1014
+ };
1015
+ /**
1016
+
1017
+ * numbers; kept for back-compat with existing feature-module tests.
1018
+ *
1019
+ * @private
1020
+ */
1021
+ DrawingShape.prototype.extentEmu = function () {
1022
+ var e = this.extent();
1023
+ if (e === undefined) {
1024
+ return undefined;
1025
+ }
1026
+ return { width: pointToEmus(e.width), height: pointToEmus(e.height) };
1027
+ };
1028
+ Object.defineProperty(DrawingShape.prototype, "width", {
1029
+ /**
1030
+ * Display width (`wp:extent/@cx` preferred; EMU-backed point `number`).
1031
+ * Setter marks layout dirty and updates both `wp:extent` and `a:xfrm/a:ext`
1032
+ * on save. Does **not** auto-adjust height when {@link lockAspectRatio} is true
1033
+ * (images parity — lock is a flag for consumers/Word).
1034
+ *
1035
+ * @public
1036
+ */
1037
+ get: function () {
1038
+ if (this.widthValue !== undefined) {
1039
+ return this.widthValue;
1040
+ }
1041
+ if (this.encodingValue === 'vml') {
1042
+ return undefined;
1043
+ }
1044
+ var layout = readDrawingLayout(this.residual);
1045
+ return layout.widthEmu !== undefined ? emuToPoint(layout.widthEmu) : undefined;
1046
+ },
1047
+ set: function (value) {
1048
+ this.widthValue = value;
1049
+ this.markLayoutDirty();
1050
+ },
1051
+ enumerable: true,
1052
+ configurable: true
1053
+ });
1054
+ Object.defineProperty(DrawingShape.prototype, "height", {
1055
+ /**
1056
+ * Display height (`wp:extent/@cy` preferred). Same lock semantics as {@link width}.
1057
+ *
1058
+ * @public
1059
+ */
1060
+ get: function () {
1061
+ if (this.heightValue !== undefined) {
1062
+ return this.heightValue;
1063
+ }
1064
+ if (this.encodingValue === 'vml') {
1065
+ return undefined;
1066
+ }
1067
+ var layout = readDrawingLayout(this.residual);
1068
+ return layout.heightEmu !== undefined ? emuToPoint(layout.heightEmu) : undefined;
1069
+ },
1070
+ set: function (value) {
1071
+ this.heightValue = value;
1072
+ this.markLayoutDirty();
1073
+ },
1074
+ enumerable: true,
1075
+ configurable: true
1076
+ });
1077
+ Object.defineProperty(DrawingShape.prototype, "rotation", {
1078
+ /**
1079
+ * Clockwise rotation in degrees (`a:xfrm/@rot`).
1080
+ * Wire uses ST_Angle = degrees × 60000. Missing attribute reads as `0`.
1081
+ * `@rot` is omitted on encode when the value is `0`.
1082
+ *
1083
+ * @throws RangeError when the value is not finite.
1084
+ *
1085
+ * @public
1086
+ */
1087
+ get: function () {
1088
+ if (this.rotationValue !== undefined) {
1089
+ return this.rotationValue;
1090
+ }
1091
+ if (this.encodingValue === 'vml') {
1092
+ return 0;
1093
+ }
1094
+ return readDrawingLayout(this.residual).rotation;
1095
+ },
1096
+ set: function (value) {
1097
+ if (!Number.isFinite(value)) {
1098
+ throw new RangeError("Invalid rotation value \"" + String(value) + "\"; expected a finite number");
1099
+ }
1100
+ this.rotationValue = value;
1101
+ this.markLayoutDirty();
1102
+ },
1103
+ enumerable: true,
1104
+ configurable: true
1105
+ });
1106
+ Object.defineProperty(DrawingShape.prototype, "lockAspectRatio", {
1107
+ /**
1108
+ * Aspect-ratio lock (`a:graphicFrameLocks/@noChangeAspect`).
1109
+ * Authoring default is `true`; missing locks on load read as `false`.
1110
+ * Setting the flag does not recompute width/height (images parity).
1111
+ *
1112
+ * @public
1113
+ */
1114
+ get: function () {
1115
+ if (this.lockAspectRatioValue !== undefined) {
1116
+ return this.lockAspectRatioValue;
1117
+ }
1118
+ if (this.encodingValue === 'vml') {
1119
+ return false;
1120
+ }
1121
+ return readDrawingLayout(this.residual).lockAspectRatio;
1122
+ },
1123
+ set: function (value) {
1124
+ this.lockAspectRatioValue = value;
1125
+ this.markLayoutDirty();
1126
+ },
1127
+ enumerable: true,
1128
+ configurable: true
1129
+ });
1130
+ Object.defineProperty(DrawingShape.prototype, "flipHorizontal", {
1131
+ /**
1132
+ * Horizontal flip (`a:xfrm/@flipH`). Missing attribute reads as `false`.
1133
+ *
1134
+ * @public
1135
+ */
1136
+ get: function () {
1137
+ if (this.flipHorizontalValue !== undefined) {
1138
+ return this.flipHorizontalValue;
1139
+ }
1140
+ if (this.encodingValue === 'vml') {
1141
+ return false;
1142
+ }
1143
+ return readDrawingLayout(this.residual).flipHorizontal;
1144
+ },
1145
+ set: function (value) {
1146
+ this.flipHorizontalValue = value;
1147
+ this.markLayoutDirty();
1148
+ },
1149
+ enumerable: true,
1150
+ configurable: true
1151
+ });
1152
+ Object.defineProperty(DrawingShape.prototype, "flipVertical", {
1153
+ /**
1154
+ * Vertical flip (`a:xfrm/@flipV`). Missing attribute reads as `false`.
1155
+ *
1156
+ * @public
1157
+ */
1158
+ get: function () {
1159
+ if (this.flipVerticalValue !== undefined) {
1160
+ return this.flipVerticalValue;
1161
+ }
1162
+ if (this.encodingValue === 'vml') {
1163
+ return false;
1164
+ }
1165
+ return readDrawingLayout(this.residual).flipVertical;
1166
+ },
1167
+ set: function (value) {
1168
+ this.flipVerticalValue = value;
1169
+ this.markLayoutDirty();
1170
+ },
1171
+ enumerable: true,
1172
+ configurable: true
1173
+ });
1174
+ Object.defineProperty(DrawingShape.prototype, "wrappingStyleInternal", {
1175
+ /**
1176
+ * Text wrapping style.
1177
+ *
1178
+ * - `'inline'` serializes as `wp:inline`. Collapsing an anchored shape to
1179
+ * inline **drops** position and wrap residual by design (images parity).
1180
+ * - Other values promote to `wp:anchor` with the matching `wp:wrap*` child.
1181
+ * Tight/through without a residual wrapPolygon fall back to `wrapNone`
1182
+ * (library does not invent polygons).
1183
+ *
1184
+ * VML leaves report `'none'`.
1185
+ *
1186
+ * @throws RangeError when `value` is not a known {@link TextWrappingStyle}.
1187
+ *
1188
+ * @public
1189
+ */
1190
+ /** @private */
1191
+ get: function () {
1192
+ if (this.wrappingValue !== undefined) {
1193
+ return this.wrappingValue;
1194
+ }
1195
+ if (this.encodingValue === 'vml') {
1196
+ return TextWrappingStyle.None;
1197
+ }
1198
+ return readDrawingWrapState(this.residual).wrapping;
1199
+ },
1200
+ /** @private */
1201
+ set: function (value) {
1202
+ assertEnumMember('wrappingStyle', value, TEXT_WRAPPING_STYLE_SET);
1203
+ this.wrappingValue = value;
1204
+ if (value === TextWrappingStyle.Inline) {
1205
+ this.placementValue = 'inline';
1206
+ }
1207
+ else {
1208
+ this.placementValue = 'anchor';
1209
+ }
1210
+ this.markStructureDirty();
1211
+ },
1212
+ enumerable: true,
1213
+ configurable: true
1214
+ });
1215
+ Object.defineProperty(DrawingShape.prototype, "distanceTopInternal", {
1216
+ /**
1217
+ * Distance from text above the shape (`wp:inline|wp:anchor/@distT`).
1218
+ * Missing residual attribute reads as `emuToPoint(0)`.
1219
+ *
1220
+ * @public
1221
+ */
1222
+ /** @private */
1223
+ get: function () {
1224
+ return this.readDistancePoints('top');
1225
+ },
1226
+ /** @private */
1227
+ set: function (value) {
1228
+ this.distanceTopValue = value;
1229
+ this.distancesModeled = true;
1230
+ this.markStructureDirty();
1231
+ },
1232
+ enumerable: true,
1233
+ configurable: true
1234
+ });
1235
+ Object.defineProperty(DrawingShape.prototype, "distanceBottomInternal", {
1236
+ /**
1237
+ * Distance from text below the shape (`wp:inline|wp:anchor/@distB`).
1238
+ * Missing residual attribute reads as `0` points.
1239
+ *
1240
+ * @public
1241
+ */
1242
+ /** @private */
1243
+ get: function () {
1244
+ return this.readDistancePoints('bottom');
1245
+ },
1246
+ /** @private */
1247
+ set: function (value) {
1248
+ this.distanceBottomValue = value;
1249
+ this.distancesModeled = true;
1250
+ this.markStructureDirty();
1251
+ },
1252
+ enumerable: true,
1253
+ configurable: true
1254
+ });
1255
+ Object.defineProperty(DrawingShape.prototype, "distanceLeftInternal", {
1256
+ /**
1257
+ * Distance from text to the left of the shape (`wp:inline|wp:anchor/@distL`).
1258
+ * Missing residual on anchor reads as author default `emuToPoint(114300)`; inline `0` points.
1259
+ *
1260
+ * @public
1261
+ */
1262
+ /** @private */
1263
+ get: function () {
1264
+ return this.readDistancePoints('left');
1265
+ },
1266
+ /** @private */
1267
+ set: function (value) {
1268
+ this.distanceLeftValue = value;
1269
+ this.distancesModeled = true;
1270
+ this.markStructureDirty();
1271
+ },
1272
+ enumerable: true,
1273
+ configurable: true
1274
+ });
1275
+ Object.defineProperty(DrawingShape.prototype, "distanceRightInternal", {
1276
+ /**
1277
+ * Distance from text to the right of the shape (`wp:inline|wp:anchor/@distR`).
1278
+ * Missing residual on anchor reads as author default `emuToPoint(114300)`; inline `0` points.
1279
+ *
1280
+ * @public
1281
+ */
1282
+ /** @private */
1283
+ get: function () {
1284
+ return this.readDistancePoints('right');
1285
+ },
1286
+ /** @private */
1287
+ set: function (value) {
1288
+ this.distanceRightValue = value;
1289
+ this.distancesModeled = true;
1290
+ this.markStructureDirty();
1291
+ },
1292
+ enumerable: true,
1293
+ configurable: true
1294
+ });
1295
+ Object.defineProperty(DrawingShape.prototype, "isBelowText", {
1296
+ /**
1297
+ * Whether the shape is behind document text (`wp:anchor/@behindDoc`).
1298
+ * Inline hosts always report `false`. VML leaves report `false`.
1299
+ *
1300
+ * @private
1301
+ */
1302
+ /**
1303
+ * Whether the shape is drawn below text (`wp:anchor/@behindDoc`).
1304
+ * @public
1305
+ */
1306
+ get: function () {
1307
+ if (this.behindDocumentValue !== undefined) {
1308
+ return this.behindDocumentValue;
1309
+ }
1310
+ if (this.encodingValue === 'vml') {
1311
+ return false;
1312
+ }
1313
+ return readDrawingWrapState(this.residual).behindDocument;
1314
+ },
1315
+ set: function (value) {
1316
+ this.behindDocumentValue = value;
1317
+ this.behindDocumentModeled = true;
1318
+ this.markStructureDirty();
1319
+ },
1320
+ enumerable: true,
1321
+ configurable: true
1322
+ });
1323
+ Object.defineProperty(DrawingShape.prototype, "horizontalOrigin", {
1324
+ /**
1325
+ * Horizontal origin (`wp:positionH/@relativeFrom`, `ST_RelFromH`).
1326
+ * Missing residual position reads as {@link HorizontalOrigin.Column}.
1327
+ * Effective getter never returns `undefined` and does not dirty on read.
1328
+ *
1329
+ * @throws RangeError when `value` is not a known {@link HorizontalOrigin}.
1330
+ *
1331
+ * @public
1332
+ */
1333
+ get: function () {
1334
+ if (this.horizontalOriginValue !== undefined) {
1335
+ return this.horizontalOriginValue;
1336
+ }
1337
+ if (this.encodingValue === 'vml') {
1338
+ return HorizontalOriginType.Column;
1339
+ }
1340
+ var fromResidual = readDrawingPositionState(this.residual).horizontalOrigin;
1341
+ return fromResidual !== undefined ? fromResidual : HorizontalOriginType.Column;
1342
+ },
1343
+ set: function (value) {
1344
+ if (value !== undefined) {
1345
+ assertEnumMember('horizontalOrigin', value, HORIZONTAL_ORIGIN_SET);
1346
+ }
1347
+ this.horizontalModeled = true;
1348
+ this.horizontalOriginValue = value;
1349
+ this.markStructureDirty();
1350
+ },
1351
+ enumerable: true,
1352
+ configurable: true
1353
+ });
1354
+ Object.defineProperty(DrawingShape.prototype, "verticalOrigin", {
1355
+ /**
1356
+ * Vertical origin (`wp:positionV/@relativeFrom`, `ST_RelFromV`).
1357
+ * Missing residual position reads as {@link VerticalOrigin.Paragraph}.
1358
+ * Effective getter never returns `undefined` and does not dirty on read.
1359
+ *
1360
+ * @throws RangeError when `value` is not a known {@link VerticalOrigin}.
1361
+ *
1362
+ * @public
1363
+ */
1364
+ get: function () {
1365
+ if (this.verticalOriginValue !== undefined) {
1366
+ return this.verticalOriginValue;
1367
+ }
1368
+ if (this.encodingValue === 'vml') {
1369
+ return VerticalOriginType.Paragraph;
1370
+ }
1371
+ var fromResidual = readDrawingPositionState(this.residual).verticalOrigin;
1372
+ return fromResidual !== undefined ? fromResidual : VerticalOriginType.Paragraph;
1373
+ },
1374
+ set: function (value) {
1375
+ if (value !== undefined) {
1376
+ assertEnumMember('verticalOrigin', value, VERTICAL_ORIGIN_SET);
1377
+ }
1378
+ this.verticalModeled = true;
1379
+ this.verticalOriginValue = value;
1380
+ this.markStructureDirty();
1381
+ },
1382
+ enumerable: true,
1383
+ configurable: true
1384
+ });
1385
+ Object.defineProperty(DrawingShape.prototype, "horizontalPosition", {
1386
+ /**
1387
+ * Horizontal offset (`wp:positionH/wp:posOffset`).
1388
+ * Setting a defined offset clears {@link horizontalAlignment} (align XOR
1389
+ * posOffset — CT_PosH schema choice). Setting `undefined` clears the modeled
1390
+ * offset (encoder then falls back to offset `0` unless align is modeled).
1391
+ *
1392
+ * @public
1393
+ */
1394
+ get: function () {
1395
+ if (this.horizontalPositionValue !== undefined) {
1396
+ return this.horizontalPositionValue;
1397
+ }
1398
+ if (this.encodingValue === 'vml') {
1399
+ return undefined;
1400
+ }
1401
+ return readDrawingPositionState(this.residual).horizontalPosition;
1402
+ },
1403
+ set: function (value) {
1404
+ this.horizontalModeled = true;
1405
+ this.horizontalPositionValue = value;
1406
+ if (value !== undefined) {
1407
+ this.horizontalAlignmentValue = undefined;
1408
+ }
1409
+ this.markStructureDirty();
1410
+ },
1411
+ enumerable: true,
1412
+ configurable: true
1413
+ });
1414
+ Object.defineProperty(DrawingShape.prototype, "verticalPosition", {
1415
+ /**
1416
+ * Vertical offset (`wp:positionV/wp:posOffset`).
1417
+ * Setting a defined offset clears {@link verticalAlignment} (align XOR
1418
+ * posOffset — CT_PosV schema choice). Setting `undefined` clears the modeled
1419
+ * offset (encoder then falls back to offset `0` unless align is modeled).
1420
+ *
1421
+ * @public
1422
+ */
1423
+ get: function () {
1424
+ if (this.verticalPositionValue !== undefined) {
1425
+ return this.verticalPositionValue;
1426
+ }
1427
+ if (this.encodingValue === 'vml') {
1428
+ return undefined;
1429
+ }
1430
+ return readDrawingPositionState(this.residual).verticalPosition;
1431
+ },
1432
+ set: function (value) {
1433
+ this.verticalModeled = true;
1434
+ this.verticalPositionValue = value;
1435
+ if (value !== undefined) {
1436
+ this.verticalAlignmentValue = undefined;
1437
+ }
1438
+ this.markStructureDirty();
1439
+ },
1440
+ enumerable: true,
1441
+ configurable: true
1442
+ });
1443
+ Object.defineProperty(DrawingShape.prototype, "horizontalAlignment", {
1444
+ /**
1445
+ * Horizontal alignment (`wp:positionH/wp:align`, `ST_AlignH`).
1446
+ * Setting a defined alignment clears {@link horizontalPosition} (align XOR
1447
+ * posOffset — CT_PosH schema choice). Effective value is never undefined:
1448
+ * modeled alignment, else residual align, else {@link HorizontalAlignment.None}
1449
+ * when the axis uses posOffset or the leaf is VML.
1450
+ *
1451
+ * @throws RangeError when `value` is not a known {@link HorizontalAlignment}.
1452
+ *
1453
+ * @public
1454
+ */
1455
+ get: function () {
1456
+ if (this.horizontalAlignmentValue !== undefined) {
1457
+ return this.horizontalAlignmentValue;
1458
+ }
1459
+ if (this.horizontalPositionValue !== undefined) {
1460
+ return HorizontalAlignmentType.None;
1461
+ }
1462
+ if (this.encodingValue === 'vml') {
1463
+ return HorizontalAlignmentType.None;
1464
+ }
1465
+ var fromResidual = readDrawingPositionState(this.residual).horizontalAlignment;
1466
+ return fromResidual !== undefined ? fromResidual : HorizontalAlignmentType.None;
1467
+ },
1468
+ set: function (value) {
1469
+ if (value !== undefined) {
1470
+ if (value === HorizontalAlignmentType.Unknown) {
1471
+ throw new RangeError('horizontalAlignment cannot be set to HorizontalAlignment.Unknown');
1472
+ }
1473
+ assertEnumMember('horizontalAlignment', value, HORIZONTAL_ALIGNMENT_SET);
1474
+ this.horizontalPositionValue = undefined;
1475
+ }
1476
+ this.horizontalModeled = true;
1477
+ this.horizontalAlignmentValue = value;
1478
+ this.markStructureDirty();
1479
+ },
1480
+ enumerable: true,
1481
+ configurable: true
1482
+ });
1483
+ Object.defineProperty(DrawingShape.prototype, "verticalAlignment", {
1484
+ /**
1485
+ * Vertical alignment (`wp:positionV/wp:align`, `ST_AlignV`).
1486
+ * Setting a defined alignment clears {@link verticalPosition} (align XOR
1487
+ * posOffset — CT_PosV schema choice). Effective value is never undefined:
1488
+ * modeled alignment, else residual align, else {@link VerticalAlignment.None}
1489
+ * when the axis uses posOffset or the leaf is VML.
1490
+ *
1491
+ * @throws RangeError when `value` is not a known {@link VerticalAlignment}.
1492
+ *
1493
+ * @public
1494
+ */
1495
+ get: function () {
1496
+ if (this.verticalAlignmentValue !== undefined) {
1497
+ return this.verticalAlignmentValue;
1498
+ }
1499
+ if (this.verticalPositionValue !== undefined) {
1500
+ return VerticalAlignmentType.None;
1501
+ }
1502
+ if (this.encodingValue === 'vml') {
1503
+ return VerticalAlignmentType.None;
1504
+ }
1505
+ var fromResidual = readDrawingPositionState(this.residual).verticalAlignment;
1506
+ return fromResidual !== undefined ? fromResidual : VerticalAlignmentType.None;
1507
+ },
1508
+ set: function (value) {
1509
+ if (value !== undefined) {
1510
+ if (value === VerticalAlignmentType.Unknown) {
1511
+ throw new RangeError('verticalAlignment cannot be set to VerticalAlignment.Unknown');
1512
+ }
1513
+ assertEnumMember('verticalAlignment', value, VERTICAL_ALIGNMENT_SET);
1514
+ this.verticalPositionValue = undefined;
1515
+ }
1516
+ this.verticalModeled = true;
1517
+ this.verticalAlignmentValue = value;
1518
+ this.markStructureDirty();
1519
+ },
1520
+ enumerable: true,
1521
+ configurable: true
1522
+ });
1523
+ Object.defineProperty(DrawingShape.prototype, "lockAnchor", {
1524
+ /**
1525
+ * Lock anchor (`wp:anchor/@locked`): the anchor location must not be modified
1526
+ * at runtime by an application editing the document (ECMA-376-1 §20.4.2.1).
1527
+ * Inline and VML leaves report `false`.
1528
+ *
1529
+ * @public
1530
+ */
1531
+ get: function () {
1532
+ if (this.lockAnchorValue !== undefined) {
1533
+ return this.lockAnchorValue;
1534
+ }
1535
+ if (this.encodingValue === 'vml') {
1536
+ return false;
1537
+ }
1538
+ return readDrawingWrapState(this.residual).lockAnchor;
1539
+ },
1540
+ set: function (value) {
1541
+ this.lockAnchorValue = value;
1542
+ this.markStructureDirty();
1543
+ },
1544
+ enumerable: true,
1545
+ configurable: true
1546
+ });
1547
+ Object.defineProperty(DrawingShape.prototype, "allowOverlapInternal", {
1548
+ /**
1549
+ * Allow overlap (`wp:anchor/@allowOverlap`). Inline and VML leaves report
1550
+ * `false` (inline hosts have no anchor surface).
1551
+ *
1552
+ * @public
1553
+ */
1554
+ /** @private */
1555
+ get: function () {
1556
+ if (this.allowOverlapValue !== undefined) {
1557
+ return this.allowOverlapValue;
1558
+ }
1559
+ if (this.encodingValue === 'vml') {
1560
+ return false;
1561
+ }
1562
+ return readDrawingWrapState(this.residual).allowOverlap;
1563
+ },
1564
+ /** @private */
1565
+ set: function (value) {
1566
+ this.allowOverlapValue = value;
1567
+ this.markStructureDirty();
1568
+ },
1569
+ enumerable: true,
1570
+ configurable: true
1571
+ });
1572
+ Object.defineProperty(DrawingShape.prototype, "layoutInCell", {
1573
+ /**
1574
+ * Layout in table cell (`wp:anchor/@layoutInCell`). Inline and VML leaves
1575
+ * report `false` (inline hosts have no anchor surface).
1576
+ *
1577
+ * @public
1578
+ */
1579
+ get: function () {
1580
+ if (this.layoutInCellValue !== undefined) {
1581
+ return this.layoutInCellValue;
1582
+ }
1583
+ if (this.encodingValue === 'vml') {
1584
+ return false;
1585
+ }
1586
+ return readDrawingWrapState(this.residual).layoutInCell;
1587
+ },
1588
+ set: function (value) {
1589
+ this.layoutInCellValue = value;
1590
+ this.markStructureDirty();
1591
+ },
1592
+ enumerable: true,
1593
+ configurable: true
1594
+ });
1595
+ // -------------------------------------------------------------------------
1596
+ // Geometry, fill, line MVP (TASK-8048)
1597
+ // -------------------------------------------------------------------------
1598
+ /** Lazy spPr state read (cached per instance; invalidated on structure dirty). */
1599
+ DrawingShape.prototype.readSpPrState = function () {
1600
+ if (this.spPrState === undefined) {
1601
+ var state = readShapePropertiesState(this.residual);
1602
+ this.spPrState = {
1603
+ presetGeometry: state.presetGeometry,
1604
+ useCustomGeometry: state.useCustomGeometry,
1605
+ fill: state.fill,
1606
+ line: state.line,
1607
+ hasThemeStyle: state.hasThemeStyle,
1608
+ };
1609
+ }
1610
+ return this.spPrState;
1611
+ };
1612
+ Object.defineProperty(DrawingShape.prototype, "presetGeometryToken", {
1613
+ /**
1614
+ * Preset geometry token (`a:prstGeom/@prst`, `ST_ShapeType`).
1615
+ * `undefined` when spPr is absent, has `a:custGeom`, or the `@prst` token is
1616
+ * not in the schema set (residual passthrough). VML reads `undefined`.
1617
+ *
1618
+ * @throws RangeError when set to a value outside `ST_ShapeType`.
1619
+ *
1620
+ * @private
1621
+ */
1622
+ get: function () {
1623
+ if (this.presetGeometryValue !== undefined) {
1624
+ return this.presetGeometryValue;
1625
+ }
1626
+ if (this.encodingValue === 'vml') {
1627
+ return undefined;
1628
+ }
1629
+ return this.readSpPrState().presetGeometry;
1630
+ },
1631
+ set: function (value) {
1632
+ if (value !== undefined && !isStShapeType(value)) {
1633
+ throw new RangeError("Invalid presetGeometry value \"" + value + "\"; expected an ST_ShapeType token");
1634
+ }
1635
+ this.presetGeometryValue = value;
1636
+ this.markStructureDirty();
1637
+ },
1638
+ enumerable: true,
1639
+ configurable: true
1640
+ });
1641
+ Object.defineProperty(DrawingShape.prototype, "fillInternal", {
1642
+ /**
1643
+ * Fill MVP (`CT_ShapeProperties` `EG_FillProperties`).
1644
+ *
1645
+ * Reads:
1646
+ * - `a:solidFill/a:srgbClr` → `{ kind: 'solid', srgb }`
1647
+ * - `a:noFill` → `{ kind: 'none' }`
1648
+ * - `a:pattFill` → `{ kind: 'pattern', preset }` (residual-preserving slice)
1649
+ * - theme/absent/gradient/picture → `undefined` or `{ kind: 'theme' }`
1650
+ * (never an invented color); check {@link DrawingShape.hasThemeStyle}.
1651
+ *
1652
+ * Setting `solid`/`none` marks the shape structure dirty and replaces the
1653
+ * spPr fill child (`wps:style` theme refs stay residual per GO).
1654
+ *
1655
+ * @public
1656
+ */
1657
+ /** @private */
1658
+ get: function () {
1659
+ if (this.fillModeled) {
1660
+ return this.fillValue;
1661
+ }
1662
+ if (this.encodingValue === 'vml') {
1663
+ return undefined;
1664
+ }
1665
+ return this.readSpPrState().fill;
1666
+ },
1667
+ /** @private */
1668
+ set: function (value) {
1669
+ if (value !== undefined && value.kind !== 'solid' && value.kind !== 'none') {
1670
+ throw new RangeError("Fill kind \"" + String(value.kind) + "\" cannot be authored; use solid or none");
1671
+ }
1672
+ this.fillValue = value;
1673
+ this.fillModeled = true;
1674
+ this.markStructureDirty();
1675
+ },
1676
+ enumerable: true,
1677
+ configurable: true
1678
+ });
1679
+ Object.defineProperty(DrawingShape.prototype, "lineInternal", {
1680
+ /**
1681
+ * Line MVP (`a:ln`). `kind: 'theme'` when absent/non-srgb (inherited from
1682
+ * `wps:style`); `kind: 'none'` when `a:ln/a:noFill`; `residual: true` flags a
1683
+ * line with unmodeled children (join/custDash/nknown dash) — mutating it
1684
+ * would drop those children, so serialization keeps the residual element
1685
+ * unless the caller models it explicitly.
1686
+ *
1687
+ * @public
1688
+ */
1689
+ /** @private */
1690
+ get: function () {
1691
+ if (this.lineModeled) {
1692
+ return this.lineValue;
1693
+ }
1694
+ if (this.encodingValue === 'vml') {
1695
+ return undefined;
1696
+ }
1697
+ return this.readSpPrState().line;
1698
+ },
1699
+ /** @private */
1700
+ set: function (value) {
1701
+ if (value !== undefined && value.kind !== 'solid' && value.kind !== 'none') {
1702
+ throw new RangeError("Line kind \"" + String(value.kind) + "\" cannot be authored; use solid or none");
1703
+ }
1704
+ this.lineValue = value;
1705
+ this.lineModeled = true;
1706
+ this.markStructureDirty();
1707
+ },
1708
+ enumerable: true,
1709
+ configurable: true
1710
+ });
1711
+ Object.defineProperty(DrawingShape.prototype, "hasThemeStyle", {
1712
+ /**
1713
+ * Whether theme formatting (`wps:style` with `lnRef`/`fillRef`/`effectRef`/
1714
+ * `fontRef`) is present on the shape. Theme-styled shapes without a solid
1715
+ *
1716
+ * @private
1717
+ * override read fill/line as `theme`/`undefined` — set {@link fill}/
1718
+ * {@link line} to replace.
1719
+ */
1720
+ get: function () {
1721
+ if (this.encodingValue === 'vml') {
1722
+ return false;
1723
+ }
1724
+ return this.readSpPrState().hasThemeStyle;
1725
+ },
1726
+ enumerable: true,
1727
+ configurable: true
1728
+ });
1729
+ // -------------------------------------------------------------------------
1730
+ // Text box bodyPr + txbx body (TASK-8049)
1731
+ // -------------------------------------------------------------------------
1732
+ /**
1733
+ * Lazy residual txbx state read (cached per instance).
1734
+ * @private
1735
+ */
1736
+ DrawingShape.prototype.readTxbxState = function () {
1737
+ if (this.txbxState === undefined) {
1738
+ if (this.encodingValue === 'vml') {
1739
+ this.txbxState = {
1740
+ present: false,
1741
+ blocks: [],
1742
+ residualTxbx: undefined,
1743
+ residualTxbxContent: undefined,
1744
+ };
1745
+ return this.txbxState;
1746
+ }
1747
+ var residualTxbx = findTxbxElement(this.residual);
1748
+ var residualTxbxContent = residualTxbx !== undefined ? findTxbxContentElement(residualTxbx) : undefined;
1749
+ // Materialize lazily (spec: prefer lazy on first body access). Parse on
1750
+ // first access with a textbox-scoped paragraph owner so appended content
1751
+ // validates membership against this shape's body.
1752
+ var blocks = residualTxbxContent !== undefined
1753
+ ? parseTxbxContentBlocks(residualTxbxContent, this.textBoxOwnerForParse())
1754
+ : [];
1755
+ this.txbxState = {
1756
+ present: residualTxbx !== undefined,
1757
+ blocks: blocks,
1758
+ residualTxbx: residualTxbx,
1759
+ residualTxbxContent: residualTxbxContent,
1760
+ };
1761
+ }
1762
+ return this.txbxState;
1763
+ };
1764
+ /**
1765
+ * Paragraph-owner context for lazy body parse.
1766
+ * @private
1767
+ */
1768
+ DrawingShape.prototype.textBoxOwnerForParse = function () {
1769
+ if (this.textBoxOwner === undefined) {
1770
+ this.textBoxOwner = new TextBoxParagraphOwner(this);
1771
+ }
1772
+ return this.textBoxOwner;
1773
+ };
1774
+ /**
1775
+ * Whether this shape hosts a WordprocessingShape text box
1776
+ * (`wps:txbx` child). Deep residual walk only — does **not** materialize
1777
+ * the body block state (reads stay byte-stable). `linkedTxbx` also reports
1778
+ * true for guard purposes — linked text boxes are out of scope (GO) but
1779
+ * body APIs still throw the documented non-textBox error only when no txbx
1780
+ * of any kind exists.
1781
+ *
1782
+ * @private
1783
+ */
1784
+ DrawingShape.prototype.isTextBox = function () {
1785
+ if (this.encodingValue === 'vml') {
1786
+ return false;
1787
+ }
1788
+ if (this.txbxBodyModeled) {
1789
+ return true;
1790
+ }
1791
+ return findTxbxElement(this.residual) !== undefined;
1792
+ };
1793
+ /**
1794
+ * Whether the residual root carries a Markup Compatibility Fallback branch
1795
+ * with a VML `w:pict` tree (Policy B dual AC — TASK-8050).
1796
+ *
1797
+ * True for authored dual AC and for residual Choice+Fallback fixtures.
1798
+ * Pure DrawingML-only or pure VML leaves return false. Does not execute VML.
1799
+ *
1800
+ * @private
1801
+ */
1802
+ DrawingShape.prototype.hasVmlFallback = function () {
1803
+ if (this.encodingValue === 'vml') {
1804
+ return false;
1805
+ }
1806
+ return residualHasVmlFallback(this.residual);
1807
+ };
1808
+ /** Guard for body APIs on non-textBox shapes. */
1809
+ DrawingShape.prototype.requireTextBox = function () {
1810
+ if (!this.isTextBox()) {
1811
+ throw new DocxError('content/invalid-shape', 'Text box body APIs require a textBox variant shape (wps:txbx). ' +
1812
+ 'Author one with appendShape({ textBox: true }) or edit a loaded text box.');
1813
+ }
1814
+ return this.readTxbxState();
1815
+ };
1816
+ /**
1817
+ * Lazy residual bodyPr state read (cached per instance).
1818
+ * @private
1819
+ */
1820
+ DrawingShape.prototype.readBodyPrState = function () {
1821
+ if (this.bodyPrModeled && this.bodyPrValue !== undefined) {
1822
+ return this.bodyPrValue;
1823
+ }
1824
+ if (this.bodyPrValue === undefined) {
1825
+ if (this.encodingValue === 'vml') {
1826
+ this.bodyPrValue = {
1827
+ verticalAnchor: undefined,
1828
+ anchorCenter: undefined,
1829
+ textDirection: undefined,
1830
+ textWrapInside: undefined,
1831
+ verticalOverflow: undefined,
1832
+ horizontalOverflow: undefined,
1833
+ fromWordArt: undefined,
1834
+ insets: undefined,
1835
+ autoFit: undefined,
1836
+ hasPresetTextWarp: false,
1837
+ residual: false,
1838
+ };
1839
+ }
1840
+ else {
1841
+ this.bodyPrValue = readBodyPropertiesState(this.residual);
1842
+ }
1843
+ }
1844
+ return this.bodyPrValue;
1845
+ };
1846
+ /**
1847
+ * Persist a modeled bodyPr slice (marks structure dirty).
1848
+ * @private
1849
+ */
1850
+ DrawingShape.prototype.writeBodyPrField = function (patch) {
1851
+ if (this.encodingValue === 'vml') {
1852
+ throw new DocxError('content/invalid-shape', 'VML leaves do not carry wps:bodyPr; convert to DrawingML to model text body properties');
1853
+ }
1854
+ this.bodyPrValue = patch;
1855
+ this.bodyPrModeled = true;
1856
+ this.markStructureDirty();
1857
+ };
1858
+ Object.defineProperty(DrawingShape.prototype, "verticalAnchor", {
1859
+ /**
1860
+ * Text anchor inside the shape (`wps:bodyPr/@anchor`,
1861
+ * `ST_TextAnchoringType`: `t|ctr|b|just|dist`). `undefined` = attribute
1862
+ * absent (Word default `t`).
1863
+ *
1864
+ * @throws DocxError `content/invalid-shape` on a VML leaf.
1865
+ *
1866
+ * @private
1867
+ */
1868
+ get: function () {
1869
+ return this.readBodyPrState().verticalAnchor;
1870
+ },
1871
+ /**
1872
+ * Text anchor inside the shape (`wps:bodyPr/@anchor`,
1873
+ * `ST_TextAnchoringType`: `t|ctr|b|just|dist`). `undefined` = attribute
1874
+ * absent (Word default `t`).
1875
+ *
1876
+ * @throws DocxError `content/invalid-shape` on a VML leaf.
1877
+ *
1878
+ * @private
1879
+ */
1880
+ set: function (value) {
1881
+ var current = this.readBodyPrState();
1882
+ this.writeBodyPrField(__assign({}, current, { verticalAnchor: value }));
1883
+ },
1884
+ enumerable: true,
1885
+ configurable: true
1886
+ });
1887
+ Object.defineProperty(DrawingShape.prototype, "anchorCenter", {
1888
+ /**
1889
+ * Center anchoring (`wps:bodyPr/@anchorCtr`). `undefined` = attribute absent.
1890
+ *
1891
+ * @throws DocxError `content/invalid-shape` on a VML leaf.
1892
+ *
1893
+ * @private
1894
+ */
1895
+ get: function () {
1896
+ return this.readBodyPrState().anchorCenter;
1897
+ },
1898
+ /**
1899
+ * Center anchoring (`wps:bodyPr/@anchorCtr`). `undefined` = attribute absent.
1900
+ *
1901
+ * @throws DocxError `content/invalid-shape` on a VML leaf.
1902
+ *
1903
+ * @private
1904
+ */
1905
+ set: function (value) {
1906
+ var current = this.readBodyPrState();
1907
+ this.writeBodyPrField(__assign({}, current, { anchorCenter: value }));
1908
+ },
1909
+ enumerable: true,
1910
+ configurable: true
1911
+ });
1912
+ Object.defineProperty(DrawingShape.prototype, "textDirection", {
1913
+ /**
1914
+ * Vertical text type (`wps:bodyPr/@vert`, `ST_TextVerticalType`).
1915
+ * `undefined` = attribute absent (horizontal).
1916
+ *
1917
+ * @throws DocxError `content/invalid-shape` on a VML leaf.
1918
+ *
1919
+ * @public
1920
+ */
1921
+ get: function () {
1922
+ return this.readBodyPrState().textDirection;
1923
+ },
1924
+ set: function (value) {
1925
+ var current = this.readBodyPrState();
1926
+ this.writeBodyPrField(__assign({}, current, { textDirection: value }));
1927
+ },
1928
+ enumerable: true,
1929
+ configurable: true
1930
+ });
1931
+ Object.defineProperty(DrawingShape.prototype, "textWrapInside", {
1932
+ /**
1933
+ * Text wrap inside the shape (`wps:bodyPr/@wrap`,
1934
+ * `ST_TextWrappingType`: `none|square` only per schema).
1935
+ * `undefined` = attribute absent (square).
1936
+ *
1937
+ * @throws DocxError `content/invalid-shape` on a VML leaf.
1938
+ *
1939
+ * @private
1940
+ */
1941
+ get: function () {
1942
+ return this.readBodyPrState().textWrapInside;
1943
+ },
1944
+ /**
1945
+ * Text wrap inside the shape (`wps:bodyPr/@wrap`,
1946
+ * `ST_TextWrappingType`: `none|square` only per schema).
1947
+ * `undefined` = attribute absent (square).
1948
+ *
1949
+ * @throws DocxError `content/invalid-shape` on a VML leaf.
1950
+ *
1951
+ * @private
1952
+ */
1953
+ set: function (value) {
1954
+ var current = this.readBodyPrState();
1955
+ this.writeBodyPrField(__assign({}, current, { textWrapInside: value }));
1956
+ },
1957
+ enumerable: true,
1958
+ configurable: true
1959
+ });
1960
+ Object.defineProperty(DrawingShape.prototype, "verticalOverflow", {
1961
+ /**
1962
+ * Vertical text overflow (`wps:bodyPr/@vertOverflow`,
1963
+ * `ST_TextVertOverflowType`). `undefined` = attribute absent.
1964
+ *
1965
+ * @throws DocxError `content/invalid-shape` on a VML leaf.
1966
+ *
1967
+ * @private
1968
+ */
1969
+ get: function () {
1970
+ return this.readBodyPrState().verticalOverflow;
1971
+ },
1972
+ /**
1973
+ * Vertical text overflow (`wps:bodyPr/@vertOverflow`,
1974
+ * `ST_TextVertOverflowType`). `undefined` = attribute absent.
1975
+ *
1976
+ * @throws DocxError `content/invalid-shape` on a VML leaf.
1977
+ *
1978
+ * @private
1979
+ */
1980
+ set: function (value) {
1981
+ var current = this.readBodyPrState();
1982
+ this.writeBodyPrField(__assign({}, current, { verticalOverflow: value }));
1983
+ },
1984
+ enumerable: true,
1985
+ configurable: true
1986
+ });
1987
+ Object.defineProperty(DrawingShape.prototype, "horizontalOverflow", {
1988
+ /**
1989
+ * Horizontal text overflow (`wps:bodyPr/@horzOverflow`,
1990
+ * `ST_TextHorzOverflowType`). `undefined` = attribute absent.
1991
+ *
1992
+ * @throws DocxError `content/invalid-shape` on a VML leaf.
1993
+ *
1994
+ * @private
1995
+ */
1996
+ get: function () {
1997
+ return this.readBodyPrState().horizontalOverflow;
1998
+ },
1999
+ /**
2000
+ * Horizontal text overflow (`wps:bodyPr/@horzOverflow`,
2001
+ * `ST_TextHorzOverflowType`). `undefined` = attribute absent.
2002
+ *
2003
+ * @throws DocxError `content/invalid-shape` on a VML leaf.
2004
+ *
2005
+ * @private
2006
+ */
2007
+ set: function (value) {
2008
+ var current = this.readBodyPrState();
2009
+ this.writeBodyPrField(__assign({}, current, { horizontalOverflow: value }));
2010
+ },
2011
+ enumerable: true,
2012
+ configurable: true
2013
+ });
2014
+ Object.defineProperty(DrawingShape.prototype, "fromWordArt", {
2015
+ /**
2016
+ * WordArt source flag (`wps:bodyPr/@fromWordArt`). `undefined` = absent.
2017
+ * Flag only — no WordArt pipeline (GO).
2018
+ *
2019
+ * @throws DocxError `content/invalid-shape` on a VML leaf.
2020
+ *
2021
+ * @private
2022
+ */
2023
+ get: function () {
2024
+ return this.readBodyPrState().fromWordArt;
2025
+ },
2026
+ /**
2027
+ * WordArt source flag (`wps:bodyPr/@fromWordArt`). `undefined` = absent.
2028
+ * Flag only — no WordArt pipeline (GO).
2029
+ *
2030
+ * @throws DocxError `content/invalid-shape` on a VML leaf.
2031
+ *
2032
+ * @private
2033
+ */
2034
+ set: function (value) {
2035
+ var current = this.readBodyPrState();
2036
+ this.writeBodyPrField(__assign({}, current, { fromWordArt: value }));
2037
+ },
2038
+ enumerable: true,
2039
+ configurable: true
2040
+ });
2041
+ Object.defineProperty(DrawingShape.prototype, "insets", {
2042
+ /**
2043
+ * Text insets (`wps:bodyPr/@lIns|tIns|rIns|bIns`, `ST_Coordinate32` EMU).
2044
+ * Non-negative EMU `Point`; `undefined` per side = attribute absent
2045
+ * (Word default 91440/45720/91440/45720). Absent insets object = no
2046
+ * inset attribute modeled.
2047
+ *
2048
+ * @throws DocxError `content/invalid-shape` on a VML leaf.
2049
+ *
2050
+ * @private
2051
+ */
2052
+ get: function () {
2053
+ return this.readBodyPrState().insets;
2054
+ },
2055
+ /**
2056
+ * Text insets (`wps:bodyPr/@lIns|tIns|rIns|bIns`, `ST_Coordinate32` EMU).
2057
+ * Non-negative EMU `Point`; `undefined` per side = attribute absent
2058
+ * (Word default 91440/45720/91440/45720). Absent insets object = no
2059
+ * inset attribute modeled.
2060
+ *
2061
+ * @throws DocxError `content/invalid-shape` on a VML leaf.
2062
+ *
2063
+ * @private
2064
+ */
2065
+ set: function (value) {
2066
+ var current = this.readBodyPrState();
2067
+ this.writeBodyPrField(__assign({}, current, { insets: value }));
2068
+ },
2069
+ enumerable: true,
2070
+ configurable: true
2071
+ });
2072
+ Object.defineProperty(DrawingShape.prototype, "autoFit", {
2073
+ /**
2074
+ * Autofit choice (`wps:bodyPr` child: `a:noAutofit` | `a:normAutofit` |
2075
+ * `a:spAutoFit`, `EG_TextAutofit`). `undefined` = no autofit child
2076
+ * (Word default noAutofit). Residual `a:prstTxWarp` / 3D / extLst stay
2077
+ * residual — setting any bodyPr field rebuilds bodyPr without them
2078
+ * (residual flag on read documents what was dropped).
2079
+ *
2080
+ * @throws DocxError `content/invalid-shape` on a VML leaf.
2081
+ *
2082
+ * @private
2083
+ */
2084
+ get: function () {
2085
+ return this.readBodyPrState().autoFit;
2086
+ },
2087
+ /**
2088
+ * Text insets (`wps:bodyPr/@lIns|tIns|rIns|bIns`, `ST_Coordinate32` EMU).
2089
+ * Non-negative EMU `Point`; `undefined` per side = attribute absent
2090
+ * (Word default 91440/45720/91440/45720). Absent insets object = no
2091
+ * inset attribute modeled.
2092
+ *
2093
+ * @throws DocxError `content/invalid-shape` on a VML leaf.
2094
+ *
2095
+ * @private
2096
+ */
2097
+ set: function (value) {
2098
+ var current = this.readBodyPrState();
2099
+ this.writeBodyPrField(__assign({}, current, { autoFit: value }));
2100
+ },
2101
+ enumerable: true,
2102
+ configurable: true
2103
+ });
2104
+ Object.defineProperty(DrawingShape.prototype, "bodyPrResidual", {
2105
+ /**
2106
+ * Whether residual `wps:bodyPr` carries unmodeled content (`a:prstTxWarp`,
2107
+ * 3D children, `extLst`, unknown attributes). Read-only; mutating any
2108
+ * bodyPr field rebuilds `wps:bodyPr` from modeled state and drops the
2109
+ * residual children (documented in the mapping).
2110
+ *
2111
+ * @private
2112
+ */
2113
+ get: function () {
2114
+ if (this.encodingValue === 'vml') {
2115
+ return false;
2116
+ }
2117
+ return this.readBodyPrState().residual;
2118
+ },
2119
+ enumerable: true,
2120
+ configurable: true
2121
+ });
2122
+ Object.defineProperty(DrawingShape.prototype, "hasPresetTextWarp", {
2123
+ /**
2124
+ * Whether the residual bodyPr has WordArt warp (`a:prstTxWarp` child).
2125
+ * Read-only flag — warp is not modeled (never invented).
2126
+ *
2127
+ * @private
2128
+ */
2129
+ get: function () {
2130
+ if (this.encodingValue === 'vml') {
2131
+ return false;
2132
+ }
2133
+ return this.readBodyPrState().hasPresetTextWarp;
2134
+ },
2135
+ enumerable: true,
2136
+ configurable: true
2137
+ });
2138
+ Object.defineProperty(DrawingShape.prototype, "blocks", {
2139
+ /**
2140
+ * Modeled blocks inside `w:txbxContent` (GO Q6). Public consumers use
2141
+ * {@link Shape.items} / {@link Shape.insertBodyItemAt}.
2142
+ * Projects internal {@link BlockContent} store via body-item adapters.
2143
+ *
2144
+ * @private
2145
+ */
2146
+ get: function () {
2147
+ this.requireTextBox();
2148
+ return this.textBody.items.toArray();
2149
+ },
2150
+ enumerable: true,
2151
+ configurable: true
2152
+ });
2153
+ /**
2154
+ * Insert a body item at `index` in the text box block list.
2155
+ * Public consumers use {@link Shape.insertBodyItemAt}.
2156
+ *
2157
+ * @private
2158
+ */
2159
+ DrawingShape.prototype.insertBodyItemAt = function (index, item) {
2160
+ this.requireTextBox();
2161
+ return this.textBody.items.insert(index, item);
2162
+ };
2163
+ /**
2164
+ * Remove the body item at `index` in the text box block list.
2165
+ * Public consumers use {@link Shape.removeBodyItemAt}.
2166
+ *
2167
+ * @private
2168
+ */
2169
+ DrawingShape.prototype.removeBodyItemAt = function (index) {
2170
+ this.requireTextBox();
2171
+ this.textBody.items.removeAt(index);
2172
+ };
2173
+ /**
2174
+ * Remove a body item from the text box block list by projected identity.
2175
+ * Public consumers use {@link Shape.removeBodyItem}.
2176
+ *
2177
+ * @private
2178
+ */
2179
+ DrawingShape.prototype.removeBodyItem = function (item) {
2180
+ this.requireTextBox();
2181
+ this.textBody.items.remove(item);
2182
+ };
2183
+ /**
2184
+ * @private
2185
+ * Txbx block store for TextBoxParagraphOwner attach checks.
2186
+ */
2187
+ DrawingShape.prototype.internalBlocks = function () {
2188
+ if (this.textBodyValue !== undefined) {
2189
+ return this.textBodyValue.rawBlocks();
2190
+ }
2191
+ if (this.txbxState !== undefined) {
2192
+ return this.txbxState.blocks;
2193
+ }
2194
+ return this.readTxbxState().blocks;
2195
+ };
2196
+ /**
2197
+ * @private
2198
+ * Owning document for textbox body paragraphs. Resolves through
2199
+ * the anchoring paragraph when bound; throws detached otherwise.
2200
+ */
2201
+ DrawingShape.prototype.internalOwningDocument = function () {
2202
+ var paragraph = this.anchoringParagraph;
2203
+ if (paragraph !== undefined) {
2204
+ return paragraph.owningDocument();
2205
+ }
2206
+ throw new DetachedObjectError('This drawing shape is not attached to a document paragraph');
2207
+ };
2208
+ /**
2209
+ * @private
2210
+ * Bind the anchoring paragraph for textbox owner document resolution. */
2211
+ /** @private */
2212
+ /** Anchoring paragraph accessor; package-visible for GroupShape reparenting. @private */
2213
+ DrawingShape.prototype.getAnchoringParagraph = function () {
2214
+ return this.anchoringParagraph;
2215
+ };
2216
+ DrawingShape.prototype.bindAnchoringParagraph = function (paragraph) {
2217
+ this.anchoringParagraph = paragraph;
2218
+ };
2219
+ /**
2220
+ * Relationship ids referenced by `r:embed` or `r:link` in the preserved subtree.
2221
+ *
2222
+ * @private
2223
+ */
2224
+ DrawingShape.prototype.relationshipIds = function () {
2225
+ return collectRelationshipIds(this.residual);
2226
+ };
2227
+ /**
2228
+ * @private
2229
+ */
2230
+ DrawingShape.prototype.toOpenXml = function () {
2231
+ // Text box body serialization precedence (TASK-8049): once the txbx block
2232
+ // state was materialized, the DOM owns `w:txbxContent` on every path —
2233
+ // nested table-cell/SDT mutations serialize even when the host stays
2234
+ // clean. The host shell is preserved (clone + txbxContent replacement on
2235
+ // clean/identity/layout; full dual-AC rebuild only on structure), so
2236
+ // unmodified bodies round-trip byte-stable (modeled paragraph
2237
+ // serialization is the same byte-stable path as the document body).
2238
+ if (this.txbxState !== undefined && this.encodingValue !== 'vml') {
2239
+ var state = this.readTxbxState();
2240
+ if (this.dirtyMode === 'clean') {
2241
+ var host = this.replaceTxbxContentInResidual(cloneResidualElement(this.residual), state);
2242
+ if (this.hasDirtyNestedChildren()) {
2243
+ host = this.rewriteResidualNestedChildren(host);
2244
+ }
2245
+ return host;
2246
+ }
2247
+ if (this.dirtyMode === 'identity') {
2248
+ var patchedIdentity = isNestedDrawingResidual(this.residual)
2249
+ ? patchResidualCNvPr(cloneResidualElement(this.residual), {
2250
+ name: this.nameValue,
2251
+ title: this.titleValue,
2252
+ description: this.descriptionValue,
2253
+ docPrId: this.docPrIdValue,
2254
+ })
2255
+ : patchResidualDocPr(cloneResidualElement(this.residual), {
2256
+ name: this.nameValue,
2257
+ title: this.titleValue,
2258
+ description: this.descriptionValue,
2259
+ docPrId: this.docPrIdValue,
2260
+ });
2261
+ var host = this.replaceTxbxContentInResidual(patchedIdentity, state);
2262
+ if (this.hasDirtyNestedChildren()) {
2263
+ host = this.rewriteResidualNestedChildren(host);
2264
+ }
2265
+ return host;
2266
+ }
2267
+ if (this.dirtyMode === 'layout') {
2268
+ if (this.widthValue === undefined || this.heightValue === undefined) {
2269
+ throw new DocxError('content/invalid-shape', 'Layout-dirty drawing shape is missing width or height');
2270
+ }
2271
+ var widthEmu_1 = pointToEmus(this.widthValue);
2272
+ var heightEmu_1 = pointToEmus(this.heightValue);
2273
+ var host = patchResidualLayout(this.residual, {
2274
+ widthEmu: widthEmu_1,
2275
+ heightEmu: heightEmu_1,
2276
+ rotation: this.rotationValue != null ? this.rotationValue : 0,
2277
+ flipHorizontal: this.flipHorizontalValue != null ? this.flipHorizontalValue : false,
2278
+ flipVertical: this.flipVerticalValue != null ? this.flipVerticalValue : false,
2279
+ lockAspectRatio: this.lockAspectRatioValue != null ? this.lockAspectRatioValue : false,
2280
+ name: this.nameValue,
2281
+ title: this.titleValue,
2282
+ description: this.descriptionValue,
2283
+ docPrId: this.docPrIdValue,
2284
+ });
2285
+ // DOM owns w:txbxContent once materialized — layout must not drop body edits.
2286
+ host = this.replaceTxbxContentInResidual(host, state);
2287
+ if (this.hasDirtyNestedChildren()) {
2288
+ host = this.rewriteResidualNestedChildren(host);
2289
+ }
2290
+ return host;
2291
+ }
2292
+ // structure — falls through to the full rebuild below.
2293
+ }
2294
+ if (this.dirtyMode === 'clean') {
2295
+ // Parent group/canvas may stay clean while a nested child is dirty
2296
+ // (e.g. ChildA rename). Rewrite nested wsp/grpSp in-place, preserving
2297
+ // residual grpSpPr and unknown siblings (TASK-8051).
2298
+ if (this.hasDirtyNestedChildren()) {
2299
+ return this.rewriteResidualNestedChildren(cloneResidualElement(this.residual));
2300
+ }
2301
+ return this.residual;
2302
+ }
2303
+ if (this.dirtyMode === 'identity') {
2304
+ var identity = {
2305
+ name: this.nameValue,
2306
+ title: this.titleValue,
2307
+ description: this.descriptionValue,
2308
+ docPrId: this.docPrIdValue,
2309
+ };
2310
+ var host = isNestedDrawingResidual(this.residual)
2311
+ ? patchResidualCNvPr(this.residual, identity)
2312
+ : patchResidualDocPr(this.residual, identity);
2313
+ if (this.hasDirtyNestedChildren()) {
2314
+ host = this.rewriteResidualNestedChildren(host === this.residual ? cloneResidualElement(this.residual) : host);
2315
+ }
2316
+ return host;
2317
+ }
2318
+ if (this.dirtyMode === 'layout') {
2319
+ if (this.widthValue === undefined || this.heightValue === undefined) {
2320
+ throw new DocxError('content/invalid-shape', 'Layout-dirty drawing shape is missing width or height');
2321
+ }
2322
+ var widthEmu_2 = pointToEmus(this.widthValue);
2323
+ var heightEmu_2 = pointToEmus(this.heightValue);
2324
+ var host = patchResidualLayout(this.residual, {
2325
+ widthEmu: widthEmu_2,
2326
+ heightEmu: heightEmu_2,
2327
+ rotation: this.rotationValue != null ? this.rotationValue : 0,
2328
+ flipHorizontal: this.flipHorizontalValue != null ? this.flipHorizontalValue : false,
2329
+ flipVertical: this.flipVerticalValue != null ? this.flipVerticalValue : false,
2330
+ lockAspectRatio: this.lockAspectRatioValue != null ? this.lockAspectRatioValue : false,
2331
+ name: this.nameValue,
2332
+ title: this.titleValue,
2333
+ description: this.descriptionValue,
2334
+ docPrId: this.docPrIdValue,
2335
+ });
2336
+ if (this.hasDirtyNestedChildren()) {
2337
+ host = this.rewriteResidualNestedChildren(host);
2338
+ }
2339
+ return host;
2340
+ }
2341
+ // structure — dual AC author / rebuild (host kind / wrap / geometry / group)
2342
+ var placement = this.placementValue != null ? this.placementValue : 'anchor';
2343
+ var widthEmu = this.widthValue === undefined ? undefined : pointToEmus(this.widthValue);
2344
+ var heightEmu = this.heightValue === undefined ? undefined : pointToEmus(this.heightValue);
2345
+ // Coordinates/distances may be 0; do not wrap with emus() (positive-only).
2346
+ var distanceTopEmu = this.distanceTopValue === undefined ? undefined : pointToCoordinateEmus(this.distanceTopValue);
2347
+ var distanceBottomEmu = this.distanceBottomValue === undefined ? undefined : pointToCoordinateEmus(this.distanceBottomValue);
2348
+ var distanceLeftEmu = this.distanceLeftValue === undefined ? undefined : pointToCoordinateEmus(this.distanceLeftValue);
2349
+ var distanceRightEmu = this.distanceRightValue === undefined ? undefined : pointToCoordinateEmus(this.distanceRightValue);
2350
+ var horizontalPositionEmu = this.horizontalPositionValue === undefined ? undefined : pointToCoordinateEmus(this.horizontalPositionValue);
2351
+ var verticalPositionEmu = this.verticalPositionValue === undefined ? undefined : pointToCoordinateEmus(this.verticalPositionValue);
2352
+ var docPrId = this.docPrIdValue != null ? this.docPrIdValue : 1;
2353
+ var wrapping = this.wrappingValue != null ? this.wrappingValue : (placement === 'inline' ? TextWrappingStyle.Inline : TextWrappingStyle.None);
2354
+ // TASK-8051: group/canvas structure encode (empty children OK). Must run
2355
+ // before the leaf presetGeometry required check.
2356
+ var variant = this.variant();
2357
+ var isGroupOrCanvasHost = this.childrenModeled || variant === 'group' || variant === 'canvas';
2358
+ if (isGroupOrCanvasHost) {
2359
+ if (widthEmu === undefined || heightEmu === undefined) {
2360
+ throw new DocxError('content/invalid-shape', 'Authored drawing group is missing width or height');
2361
+ }
2362
+ this.ensureChildrenModeled();
2363
+ var childElements = this.childrenValue.map(function (child) { return child.toOpenXml(); });
2364
+ return encodeAuthoredGroup(encodeGroupInput({
2365
+ placement: placement,
2366
+ widthEmu: widthEmu,
2367
+ heightEmu: heightEmu,
2368
+ docPrId: docPrId,
2369
+ name: this.nameValue != null ? this.nameValue : 'Group',
2370
+ title: this.titleValue,
2371
+ description: this.descriptionValue,
2372
+ rotation: this.rotationValue != null ? this.rotationValue : 0,
2373
+ flipHorizontal: this.flipHorizontalValue != null ? this.flipHorizontalValue : false,
2374
+ flipVertical: this.flipVerticalValue != null ? this.flipVerticalValue : false,
2375
+ lockAspectRatio: this.lockAspectRatioValue != null ? this.lockAspectRatioValue : true,
2376
+ wrapping: wrapping,
2377
+ distanceTopEmu: distanceTopEmu,
2378
+ distanceBottomEmu: distanceBottomEmu,
2379
+ distanceLeftEmu: distanceLeftEmu,
2380
+ distanceRightEmu: distanceRightEmu,
2381
+ behindDocument: this.behindDocumentValue,
2382
+ horizontalOrigin: this.horizontalOriginValue,
2383
+ verticalOrigin: this.verticalOriginValue,
2384
+ horizontalPositionEmu: horizontalPositionEmu,
2385
+ verticalPositionEmu: verticalPositionEmu,
2386
+ horizontalAlignment: this.horizontalAlignmentValue,
2387
+ verticalAlignment: this.verticalAlignmentValue,
2388
+ horizontalModeled: this.horizontalModeled,
2389
+ verticalModeled: this.verticalModeled,
2390
+ lockAnchor: this.lockAnchorValue,
2391
+ allowOverlap: this.allowOverlapValue,
2392
+ layoutInCell: this.layoutInCellValue,
2393
+ preservedHost: this.residual,
2394
+ layoutDirty: true,
2395
+ children: childElements,
2396
+ }));
2397
+ }
2398
+ // TASK-8051: nested bare wsp structure rebuild (no second drawing host).
2399
+ if (isNestedDrawingResidual(this.residual)) {
2400
+ if (widthEmu === undefined || heightEmu === undefined) {
2401
+ throw new DocxError('content/invalid-shape', 'Authored nested drawing shape is missing width or height');
2402
+ }
2403
+ var presetGeometryNested = this.presetGeometryValue;
2404
+ if (presetGeometryNested === undefined) {
2405
+ throw new DocxError('content/invalid-shape', 'Authored nested drawing shape is missing presetGeometry');
2406
+ }
2407
+ var txbxContentNested = void 0;
2408
+ if (this.txbxState !== undefined || this.txbxBodyModeled) {
2409
+ var state = this.readTxbxState();
2410
+ txbxContentNested = serializeTxbxContentBlocks(state.blocks.length > 0 ? state.blocks : emptyTxbxParagraphBlocks());
2411
+ }
2412
+ var bodyPrNested = this.bodyPrModeled
2413
+ ? buildBodyPrElement(this.bodyPrValue != null ? this.bodyPrValue : {})
2414
+ : undefined;
2415
+ var encodeFillNested = this.fillModeled
2416
+ ? modeledFillForEncode(this.fillValue)
2417
+ : undefined;
2418
+ var encodeLineNested = this.lineModeled
2419
+ ? modeledLineForEncode(this.lineValue)
2420
+ : undefined;
2421
+ return buildNestedWpsShape({
2422
+ placement: 'anchor',
2423
+ widthEmu: widthEmu,
2424
+ heightEmu: heightEmu,
2425
+ presetGeometry: presetGeometryNested,
2426
+ docPrId: docPrId,
2427
+ name: this.nameValue != null ? this.nameValue : 'Shape',
2428
+ title: this.titleValue,
2429
+ description: this.descriptionValue,
2430
+ rotation: this.rotationValue != null ? this.rotationValue : 0,
2431
+ flipHorizontal: this.flipHorizontalValue != null ? this.flipHorizontalValue : false,
2432
+ flipVertical: this.flipVerticalValue != null ? this.flipVerticalValue : false,
2433
+ lockAspectRatio: this.lockAspectRatioValue != null ? this.lockAspectRatioValue : true,
2434
+ txbxContent: txbxContentNested,
2435
+ bodyPr: bodyPrNested,
2436
+ fill: encodeFillNested,
2437
+ line: encodeLineNested,
2438
+ });
2439
+ }
2440
+ var presetGeometry = this.presetGeometryValue;
2441
+ if (widthEmu === undefined || heightEmu === undefined || presetGeometry === undefined) {
2442
+ throw new DocxError('content/invalid-shape', 'Authored drawing shape is missing size or presetGeometry');
2443
+ }
2444
+ // TASK-8049: text box body + bodyPr encode. The body is rebuilt from the
2445
+ // typed block state whenever it was materialized (any body access —
2446
+ // top-level or nested inside a table/SDT) or explicitly modeled; nested
2447
+ // mutations serialize because the materialized blocks reference the same
2448
+ // live Paragraph/Table/SDT objects. When the body was never accessed, the
2449
+ // residual txbx is cloned verbatim (structure dirt from layout/wrap
2450
+ // mutators must not drop textbox content). bodyPr emits when modeled.
2451
+ var txbxContent;
2452
+ if (this.txbxState !== undefined || this.txbxBodyModeled) {
2453
+ var state = this.readTxbxState();
2454
+ txbxContent = serializeTxbxContentBlocks(state.blocks.length > 0 ? state.blocks : emptyTxbxParagraphBlocks());
2455
+ }
2456
+ var bodyPrElement = this.bodyPrModeled
2457
+ ? buildBodyPrElement(this.bodyPrValue != null ? this.bodyPrValue : {})
2458
+ : undefined;
2459
+ return encodeAuthoredDrawingShape(encodeDrawingShapeInput({
2460
+ placement: placement,
2461
+ widthEmu: widthEmu,
2462
+ heightEmu: heightEmu,
2463
+ presetGeometry: presetGeometry,
2464
+ docPrId: docPrId,
2465
+ name: this.nameValue != null ? this.nameValue : 'Shape',
2466
+ title: this.titleValue,
2467
+ description: this.descriptionValue,
2468
+ rotation: this.rotationValue != null ? this.rotationValue : 0,
2469
+ flipHorizontal: this.flipHorizontalValue != null ? this.flipHorizontalValue : false,
2470
+ flipVertical: this.flipVerticalValue != null ? this.flipVerticalValue : false,
2471
+ lockAspectRatio: this.lockAspectRatioValue != null ? this.lockAspectRatioValue : true,
2472
+ wrapping: wrapping,
2473
+ wrapType: this.readWrapType(),
2474
+ distanceTopEmu: distanceTopEmu,
2475
+ distanceBottomEmu: distanceBottomEmu,
2476
+ distanceLeftEmu: distanceLeftEmu,
2477
+ distanceRightEmu: distanceRightEmu,
2478
+ behindDocument: this.behindDocumentValue,
2479
+ horizontalOrigin: this.horizontalOriginValue,
2480
+ verticalOrigin: this.verticalOriginValue,
2481
+ horizontalPositionEmu: horizontalPositionEmu,
2482
+ verticalPositionEmu: verticalPositionEmu,
2483
+ horizontalAlignment: this.horizontalAlignmentValue,
2484
+ verticalAlignment: this.verticalAlignmentValue,
2485
+ horizontalModeled: this.horizontalModeled,
2486
+ verticalModeled: this.verticalModeled,
2487
+ lockAnchor: this.lockAnchorValue,
2488
+ allowOverlap: this.allowOverlapValue,
2489
+ layoutInCell: this.layoutInCellValue,
2490
+ preservedHost: this.residual,
2491
+ layoutDirty: true,
2492
+ txbxContent: txbxContent,
2493
+ bodyPr: bodyPrElement,
2494
+ fill: this.fillModeled ? modeledFillForEncode(this.fillValue) : undefined,
2495
+ line: this.lineModeled ? modeledLineForEncode(this.lineValue) : undefined,
2496
+ }));
2497
+ };
2498
+ /**
2499
+ * Replace the materialized `w:txbxContent` inside a cloned residual host
2500
+ * (identity / layout dirty paths keep everything else verbatim).
2501
+ */
2502
+ DrawingShape.prototype.replaceTxbxContentInResidual = function (host, state) {
2503
+ var txbxContentHost = findTxbxElement(host);
2504
+ if (txbxContentHost === undefined) {
2505
+ return host;
2506
+ }
2507
+ var txbxContent = serializeTxbxContentBlocks(state.blocks.length > 0 ? state.blocks : emptyTxbxParagraphBlocks());
2508
+ // Replace the w:txbxContent child of the cloned wps:txbx (attributes
2509
+ // — e.g. @id for linked-box pairs — and linkedTxbx siblings stay).
2510
+ var children = txbxContentHost.children.filter(function (c) { return !(c.kind === 'element' && c.localName === 'txbxContent'); });
2511
+ txbxContentHost.children = __spread(children, [
2512
+ (function () {
2513
+ var el = wmlElement('txbxContent', { children: txbxContent });
2514
+ return el;
2515
+ })(),
2516
+ ]);
2517
+ return host;
2518
+ };
2519
+ DrawingShape.prototype.drawingRoot = function () {
2520
+ var __ts33_0;
2521
+ return ((__ts33_0 = preferredDrawingElement(this.residual)), __ts33_0 != null ? __ts33_0 : (isWml(this.residual, 'drawing') ? this.residual : undefined));
2522
+ };
2523
+ DrawingShape.prototype.markIdentityDirty = function () {
2524
+ if (this.dirtyMode === 'structure' || this.dirtyMode === 'layout') {
2525
+ this.notifyParentOfChildDirty();
2526
+ return;
2527
+ }
2528
+ if (this.dirtyMode === 'clean') {
2529
+ var identity = this.readResidualIdentity();
2530
+ if (this.nameValue === undefined) {
2531
+ this.nameValue = identity.name;
2532
+ }
2533
+ if (this.titleValue === undefined) {
2534
+ this.titleValue = identity.title;
2535
+ }
2536
+ if (this.descriptionValue === undefined) {
2537
+ this.descriptionValue = identity.description;
2538
+ }
2539
+ if (this.docPrIdValue === undefined) {
2540
+ this.docPrIdValue = identity.docPrId;
2541
+ }
2542
+ }
2543
+ this.dirtyMode = 'identity';
2544
+ this.notifyParentOfChildDirty();
2545
+ };
2546
+ /**
2547
+ * Promote to layout dirty. Never demotes `structure`.
2548
+ * Hydrates size/transform/lock from residual when leaving `clean`/`identity`.
2549
+ */
2550
+ DrawingShape.prototype.markLayoutDirty = function () {
2551
+ if (this.dirtyMode === 'structure') {
2552
+ this.notifyParentOfChildDirty();
2553
+ return;
2554
+ }
2555
+ if (this.dirtyMode === 'clean' || this.dirtyMode === 'identity') {
2556
+ this.hydrateIdentityAndLayoutFromResidual();
2557
+ }
2558
+ this.dirtyMode = 'layout';
2559
+ this.notifyParentOfChildDirty();
2560
+ };
2561
+ /**
2562
+ * Promote the leaf to a textBox variant (`wps:txbx` modeled).
2563
+ * Never demotes; idempotent once set.
2564
+ * @private
2565
+ */
2566
+ DrawingShape.prototype.markTxbxBodyModeled = function () {
2567
+ this.txbxBodyModeled = true;
2568
+ };
2569
+ /**
2570
+ * Promote to structure dirty (host kind / wrap / distances / behindDoc).
2571
+ * Never demotes. Hydrates identity, layout, wrap, and presetGeometry from residual.
2572
+ */
2573
+ /** Promote dirty mode to structure; package-visible for GroupShape. @private */
2574
+ DrawingShape.prototype.markStructureDirty = function () {
2575
+ if (this.dirtyMode !== 'structure') {
2576
+ this.hydrateIdentityAndLayoutFromResidual();
2577
+ if (this.encodingValue !== 'vml') {
2578
+ var wrap = readDrawingWrapState(this.residual);
2579
+ if (this.placementValue === undefined) {
2580
+ this.placementValue = wrap.placement;
2581
+ }
2582
+ if (this.wrappingValue === undefined) {
2583
+ this.wrappingValue = wrap.wrapping;
2584
+ }
2585
+ if (!this.distancesModeled) {
2586
+ if (this.distanceTopValue === undefined && wrap.distanceTopEmu !== undefined) {
2587
+ this.distanceTopValue = emuToPoint(wrap.distanceTopEmu);
2588
+ }
2589
+ if (this.distanceBottomValue === undefined && wrap.distanceBottomEmu !== undefined) {
2590
+ this.distanceBottomValue = emuToPoint(wrap.distanceBottomEmu);
2591
+ }
2592
+ if (this.distanceLeftValue === undefined && wrap.distanceLeftEmu !== undefined) {
2593
+ this.distanceLeftValue = emuToPoint(wrap.distanceLeftEmu);
2594
+ }
2595
+ if (this.distanceRightValue === undefined && wrap.distanceRightEmu !== undefined) {
2596
+ this.distanceRightValue = emuToPoint(wrap.distanceRightEmu);
2597
+ }
2598
+ }
2599
+ if (!this.behindDocumentModeled && this.behindDocumentValue === undefined) {
2600
+ this.behindDocumentValue = wrap.behindDocument;
2601
+ }
2602
+ if (this.presetGeometryValue === undefined) {
2603
+ this.presetGeometryValue = wrap.presetGeometry;
2604
+ }
2605
+ // Hydrate position values and anchor booleans from residual so structure
2606
+ // encode never invents tokens or silently flips residual option values.
2607
+ // Hydration fills missing fields on BOTH axes regardless of the per-axis
2608
+ // modeled flags — the flags only decide whether an axis is rebuilt from
2609
+ // model or preserved verbatim on the wire (host-codec).
2610
+ var position = readDrawingPositionState(this.residual);
2611
+ if (this.horizontalOriginValue === undefined) {
2612
+ this.horizontalOriginValue = position.horizontalOrigin;
2613
+ }
2614
+ if (this.horizontalPositionValue === undefined && position.horizontalPositionEmu !== undefined) {
2615
+ this.horizontalPositionValue = emuToPoint(position.horizontalPositionEmu);
2616
+ }
2617
+ if (this.horizontalAlignmentValue === undefined) {
2618
+ this.horizontalAlignmentValue = position.horizontalAlignment;
2619
+ }
2620
+ if (this.verticalOriginValue === undefined) {
2621
+ this.verticalOriginValue = position.verticalOrigin;
2622
+ }
2623
+ if (this.verticalPositionValue === undefined && position.verticalPositionEmu !== undefined) {
2624
+ this.verticalPositionValue = emuToPoint(position.verticalPositionEmu);
2625
+ }
2626
+ if (this.verticalAlignmentValue === undefined) {
2627
+ this.verticalAlignmentValue = position.verticalAlignment;
2628
+ }
2629
+ if (this.lockAnchorValue === undefined) {
2630
+ this.lockAnchorValue = wrap.lockAnchor;
2631
+ }
2632
+ if (this.allowOverlapValue === undefined) {
2633
+ this.allowOverlapValue = wrap.allowOverlap;
2634
+ }
2635
+ if (this.layoutInCellValue === undefined) {
2636
+ this.layoutInCellValue = wrap.layoutInCell;
2637
+ }
2638
+ }
2639
+ // Always invalidate cached residual spPr reads when structure dirtied —
2640
+ // including when already structure (geometry/fill/line mutators).
2641
+ this.spPrState = undefined;
2642
+ }
2643
+ // Re-reads of bodyPr residual after a modeled write must reflect the
2644
+ // modeled state, not the stale residual — only clear the residual-derived
2645
+ // cache when bodyPr was not modeled here.
2646
+ if (!this.bodyPrModeled) {
2647
+ this.bodyPrValue = undefined;
2648
+ }
2649
+ this.dirtyMode = 'structure';
2650
+ this.notifyParentOfChildDirty();
2651
+ };
2652
+ DrawingShape.prototype.hydrateIdentityAndLayoutFromResidual = function () {
2653
+ var identity = this.readResidualIdentity();
2654
+ if (this.nameValue === undefined) {
2655
+ this.nameValue = identity.name;
2656
+ }
2657
+ if (this.titleValue === undefined) {
2658
+ this.titleValue = identity.title;
2659
+ }
2660
+ if (this.descriptionValue === undefined) {
2661
+ this.descriptionValue = identity.description;
2662
+ }
2663
+ if (this.docPrIdValue === undefined) {
2664
+ this.docPrIdValue = identity.docPrId;
2665
+ }
2666
+ if (this.encodingValue !== 'vml') {
2667
+ var layout = readDrawingLayout(this.residual);
2668
+ if (this.widthValue === undefined && layout.widthEmu !== undefined) {
2669
+ this.widthValue = emuToPoint(layout.widthEmu);
2670
+ }
2671
+ if (this.heightValue === undefined && layout.heightEmu !== undefined) {
2672
+ this.heightValue = emuToPoint(layout.heightEmu);
2673
+ }
2674
+ if (this.rotationValue === undefined) {
2675
+ this.rotationValue = layout.rotation;
2676
+ }
2677
+ if (this.flipHorizontalValue === undefined) {
2678
+ this.flipHorizontalValue = layout.flipHorizontal;
2679
+ }
2680
+ if (this.flipVerticalValue === undefined) {
2681
+ this.flipVerticalValue = layout.flipVertical;
2682
+ }
2683
+ if (this.lockAspectRatioValue === undefined) {
2684
+ this.lockAspectRatioValue = layout.lockAspectRatio;
2685
+ }
2686
+ }
2687
+ };
2688
+ /**
2689
+ * Read identity from nested `wps:cNvPr` / `wpg:cNvPr` when residual is a bare
2690
+ * nested shape/group; otherwise from top-level `wp:docPr`.
2691
+ */
2692
+ DrawingShape.prototype.readResidualIdentity = function () {
2693
+ if (isNestedDrawingResidual(this.residual)) {
2694
+ return readCNvPrIdentity(this.residual);
2695
+ }
2696
+ return readDocPrIdentity(this.residual);
2697
+ };
2698
+ /**
2699
+ * Parse nested `wps:wsp` / `wpg:grpSp` children under residual `wpg:wgp` or
2700
+ * `wpc:wpc` (TASK-8051). Unknown residual siblings are not modeled as children.
2701
+ */
2702
+ DrawingShape.prototype.parseNestedChildrenFromResidual = function () {
2703
+ var e_8, _a;
2704
+ if (this.encodingValue === 'vml') {
2705
+ return [];
2706
+ }
2707
+ var container = findNestedDrawingContainer(this.residual);
2708
+ if (container === undefined) {
2709
+ return [];
2710
+ }
2711
+ var children = [];
2712
+ try {
2713
+ for (var _b = __values(elementChildren(container)), _c = _b.next(); !_c.done; _c = _b.next()) {
2714
+ var childEl = _c.value;
2715
+ if (!isNestedDrawingResidual(childEl)) {
2716
+ continue;
2717
+ }
2718
+ var child = createDrawingShape('drawingml', childEl);
2719
+ child.parentGroup = this;
2720
+ children.push(child);
2721
+ }
2722
+ }
2723
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
2724
+ finally {
2725
+ try {
2726
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2727
+ }
2728
+ finally { if (e_8) throw e_8.error; }
2729
+ }
2730
+ return children;
2731
+ };
2732
+ /**
2733
+ * Materialize residual or cached children into {@link childrenValue} so nested
2734
+ * authoring can push without dropping lazy residual siblings.
2735
+ */
2736
+ DrawingShape.prototype.ensureChildrenModeled = function () {
2737
+ var e_9, _a;
2738
+ if (this.childrenModeled) {
2739
+ return;
2740
+ }
2741
+ var existing = this.childrenCache !== undefined
2742
+ ? this.childrenCache
2743
+ : this.parseNestedChildrenFromResidual();
2744
+ this.childrenValue = __spread(existing);
2745
+ try {
2746
+ for (var _b = __values(this.childrenValue), _c = _b.next(); !_c.done; _c = _b.next()) {
2747
+ var child = _c.value;
2748
+ child.parentGroup = this;
2749
+ }
2750
+ }
2751
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
2752
+ finally {
2753
+ try {
2754
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2755
+ }
2756
+ finally { if (e_9) throw e_9.error; }
2757
+ }
2758
+ this.childrenModeled = true;
2759
+ this.childrenCache = undefined;
2760
+ };
2761
+ /**
2762
+ * Allocate a package-unique cNvPr/docPr id for a nested child using the
2763
+ * top-level host's anchoring paragraph when available.
2764
+ */
2765
+ DrawingShape.prototype.allocateNestedDocPrId = function () {
2766
+ var e_10, _a;
2767
+ var paragraph = this.anchoringParagraph != null ? this.anchoringParagraph : this.parentGroup == null ? undefined : this.parentGroup.anchoringParagraph;
2768
+ if (paragraph !== undefined) {
2769
+ return allocateDocPrId(paragraph);
2770
+ }
2771
+ // Detached authoring path: walk already-modeled descendants only.
2772
+ var max = this.docPrIdValue != null ? this.docPrIdValue : 0;
2773
+ try {
2774
+ for (var _b = __values(this.children()), _c = _b.next(); !_c.done; _c = _b.next()) {
2775
+ var child = _c.value;
2776
+ var id = child.docPrIdValue;
2777
+ if (id !== undefined && id > max) {
2778
+ max = id;
2779
+ }
2780
+ }
2781
+ }
2782
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
2783
+ finally {
2784
+ try {
2785
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2786
+ }
2787
+ finally { if (e_10) throw e_10.error; }
2788
+ }
2789
+ return max + 1;
2790
+ };
2791
+ /** True when any nested child (direct) is not clean. */
2792
+ DrawingShape.prototype.hasDirtyNestedChildren = function () {
2793
+ var e_11, _a;
2794
+ if (this.encodingValue === 'vml') {
2795
+ return false;
2796
+ }
2797
+ // Avoid infinite recursion via children() cache population while still
2798
+ // detecting dirt on already-modeled children without forcing parse.
2799
+ var kids = this.childrenModeled
2800
+ ? this.childrenValue
2801
+ : this.childrenCache !== undefined
2802
+ ? this.childrenCache
2803
+ : undefined;
2804
+ if (kids === undefined) {
2805
+ return false;
2806
+ }
2807
+ try {
2808
+ for (var kids_1 = __values(kids), kids_1_1 = kids_1.next(); !kids_1_1.done; kids_1_1 = kids_1.next()) {
2809
+ var child = kids_1_1.value;
2810
+ if (child.dirtyMode !== 'clean' || child.hasDirtyNestedChildren()) {
2811
+ return true;
2812
+ }
2813
+ }
2814
+ }
2815
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
2816
+ finally {
2817
+ try {
2818
+ if (kids_1_1 && !kids_1_1.done && (_a = kids_1.return)) _a.call(kids_1);
2819
+ }
2820
+ finally { if (e_11) throw e_11.error; }
2821
+ }
2822
+ return false;
2823
+ };
2824
+ /**
2825
+ * Clone residual host and replace nested wsp/grpSp under wgp/wpc with each
2826
+ * child's {@link toOpenXml}, preserving grpSpPr and unknown residual siblings.
2827
+ */
2828
+ DrawingShape.prototype.rewriteResidualNestedChildren = function (host) {
2829
+ var e_12, _a;
2830
+ this.ensureChildrenModeled();
2831
+ var container = findNestedDrawingContainer(host);
2832
+ if (container === undefined) {
2833
+ return host;
2834
+ }
2835
+ var modeled = this.childrenValue;
2836
+ var modelIndex = 0;
2837
+ var nextChildren = [];
2838
+ try {
2839
+ for (var _b = __values(container.children), _c = _b.next(); !_c.done; _c = _b.next()) {
2840
+ var node = _c.value;
2841
+ if (node.kind !== 'element' || !isNestedDrawingResidual(node)) {
2842
+ nextChildren.push(node);
2843
+ continue;
2844
+ }
2845
+ var child = modeled[modelIndex];
2846
+ if (child !== undefined) {
2847
+ nextChildren.push(child.toOpenXml());
2848
+ modelIndex += 1;
2849
+ }
2850
+ // Extra residual nested shapes beyond modeled list are dropped only when
2851
+ // the model intentionally no longer contains them (structure author path
2852
+ // rebuilds entirely). Preserve-by-model-order for dirty-child rewrite.
2853
+ }
2854
+ }
2855
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
2856
+ finally {
2857
+ try {
2858
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2859
+ }
2860
+ finally { if (e_12) throw e_12.error; }
2861
+ }
2862
+ // Append any additional modeled children not matched to residual slots.
2863
+ while (modelIndex < modeled.length) {
2864
+ var child = modeled[modelIndex];
2865
+ if (child === undefined) {
2866
+ break;
2867
+ }
2868
+ nextChildren.push(child.toOpenXml());
2869
+ modelIndex += 1;
2870
+ }
2871
+ container.children = nextChildren;
2872
+ return host;
2873
+ };
2874
+ /**
2875
+ * Nested child dirt must surface on save even when the parent residual stays
2876
+ * clean — notify by ensuring children are modeled (so hasDirtyNestedChildren
2877
+ * can see them). Parent dirtyMode is left alone; toOpenXml rewrites kids.
2878
+ */
2879
+ DrawingShape.prototype.notifyParentOfChildDirty = function () {
2880
+ var parent = this.parentGroup;
2881
+ if (parent === undefined) {
2882
+ return;
2883
+ }
2884
+ parent.ensureChildrenModeled();
2885
+ };
2886
+ DrawingShape.prototype.readDistancePoints = function (side) {
2887
+ var modeled = side === 'top'
2888
+ ? this.distanceTopValue
2889
+ : side === 'bottom'
2890
+ ? this.distanceBottomValue
2891
+ : side === 'left'
2892
+ ? this.distanceLeftValue
2893
+ : this.distanceRightValue;
2894
+ if (modeled !== undefined) {
2895
+ return modeled;
2896
+ }
2897
+ if (this.encodingValue === 'vml') {
2898
+ return 0;
2899
+ }
2900
+ var wrap = readDrawingWrapState(this.residual);
2901
+ var residual = side === 'top'
2902
+ ? wrap.distanceTopEmu
2903
+ : side === 'bottom'
2904
+ ? wrap.distanceBottomEmu
2905
+ : side === 'left'
2906
+ ? wrap.distanceLeftEmu
2907
+ : wrap.distanceRightEmu;
2908
+ if (residual !== undefined) {
2909
+ return emuToPoint(residual);
2910
+ }
2911
+ var placement = this.placement();
2912
+ if ((side === 'left' || side === 'right') && placement === 'anchor') {
2913
+ return emuToPoint(ANCHOR_DEFAULT_SIDE_DIST_EMU);
2914
+ }
2915
+ return 0;
2916
+ };
2917
+ return DrawingShape;
2918
+ }());
2919
+ export { DrawingShape };
2920
+ /**
2921
+ * Leaf DrawingML / VML shape (preset geometry, fill/line, optional text box).
2922
+ *
2923
+ * Inherits identity, placement, size, wrap, and position format from
2924
+ * {@link DrawingShape}. Text-box body content uses {@link Shape.items}.
2925
+ * Group hosts use {@link GroupShape}.
2926
+ *
2927
+ * @public
2928
+ */
2929
+ var Shape = /** @class */ (function (_super) {
2930
+ __extends(Shape, _super);
2931
+ /**
2932
+ * @private
2933
+ */
2934
+ function Shape(encodingOrInit, element) {
2935
+ var _this =
2936
+ // Base constructor validates `element` for the string-encoding overload
2937
+ // (throws when undefined); super() must remain the first statement here
2938
+ // because this class has initialized properties (TS2376).
2939
+ _super.call(this, encodingOrInit, element) || this;
2940
+ /**
2941
+ * Public discriminant for {@link Paragraph.items} ({@link EntityType.Shape}).
2942
+ * @public
2943
+ */
2944
+ _this.type = EntityType.Shape;
2945
+ return _this;
2946
+ }
2947
+ Object.defineProperty(Shape.prototype, "items", {
2948
+ /**
2949
+ * Ordered text-box body children ({@link BodyItem}) — paragraphs, tables,
2950
+ * block content controls, and residual-opaque blocks in document order.
2951
+ *
2952
+ * Requires a text-box variant (`wps:txbx`). Mutate only through
2953
+ * {@link insertBodyItemAt}, {@link removeBodyItemAt}, and {@link removeBodyItem}.
2954
+ *
2955
+ * @throws DocxError `content/invalid-shape` when the shape is not a text box.
2956
+ *
2957
+ * @public
2958
+ */
2959
+ get: function () {
2960
+ return this.blocks;
2961
+ },
2962
+ enumerable: true,
2963
+ configurable: true
2964
+ });
2965
+ /**
2966
+ * Inserts a body item at `index` in {@link Shape.items}
2967
+ * (`0…length` inclusive — insert-before / append).
2968
+ *
2969
+ * Attaches paragraphs and binds feature blocks to the owning document.
2970
+ * Returns the same `item` reference for chaining (API-RULES R1.1).
2971
+ *
2972
+ * @param index - Index in {@link Shape.items}.
2973
+ * @param item - Paragraph, feature, or opaque body child.
2974
+ * @returns The inserted {@link BodyItem}.
2975
+ * @throws RangeError if `index` is out of range.
2976
+ * @throws DocxError `content/invalid-shape` when the shape is not a text box.
2977
+ *
2978
+ * @public
2979
+ */
2980
+ Shape.prototype.insertBodyItemAt = function (index, item) {
2981
+ return _super.prototype.insertBodyItemAt.call(this, index, item);
2982
+ };
2983
+ /**
2984
+ * Removes the body item at `index` in {@link Shape.items}
2985
+ * (`0…length-1`). Paragraphs detach; feature blocks may release content.
2986
+ *
2987
+ * @param index - Index in {@link Shape.items}.
2988
+ * @throws RangeError if `index` is out of range.
2989
+ * @throws DocxError `content/invalid-shape` when the shape is not a text box.
2990
+ *
2991
+ * @public
2992
+ */
2993
+ Shape.prototype.removeBodyItemAt = function (index) {
2994
+ _super.prototype.removeBodyItemAt.call(this, index);
2995
+ };
2996
+ /**
2997
+ * Removes a body item from {@link Shape.items}.
2998
+ *
2999
+ * Matches by collection entry identity first, then by payload identity
3000
+ * (same {@link Paragraph}, feature value, or opaque XML node).
3001
+ *
3002
+ * @param item - Entry from `items`, or an equivalent payload wrapper.
3003
+ * @throws DetachedObjectError if `item` is not in this text box.
3004
+ * @throws DocxError `content/invalid-shape` when the shape is not a text box.
3005
+ *
3006
+ * @public
3007
+ */
3008
+ Shape.prototype.removeBodyItem = function (item) {
3009
+ _super.prototype.removeBodyItem.call(this, item);
3010
+ };
3011
+ return Shape;
3012
+ }(DrawingShape));
3013
+ export { Shape };
3014
+ /**
3015
+ * DrawingML group or canvas host with nested {@link Shape} / {@link GroupShape}
3016
+ * children (TASK-8051).
3017
+ *
3018
+ * Inherits identity, placement, size, wrap, and position format from
3019
+ * {@link DrawingShape}. Nested children are exposed as {@link childShapes};
3020
+ * author nested leaves with {@link appendShape}.
3021
+ *
3022
+ * @public
3023
+ */
3024
+ var GroupShape = /** @class */ (function (_super) {
3025
+ __extends(GroupShape, _super);
3026
+ /**
3027
+ * @private
3028
+ */
3029
+ function GroupShape(encodingOrInit, element) {
3030
+ var _this =
3031
+ // Base constructor validates `element` for the string-encoding overload
3032
+ // (throws when undefined); super() must remain the first statement here
3033
+ // because this class has initialized properties (TS2376).
3034
+ _super.call(this, encodingOrInit, element) || this;
3035
+ /**
3036
+ * Public discriminant for {@link Paragraph.items} ({@link EntityType.GroupShape}).
3037
+ * @public
3038
+ */
3039
+ _this.type = EntityType.GroupShape;
3040
+ return _this;
3041
+ }
3042
+ Object.defineProperty(GroupShape.prototype, "childShapes", {
3043
+ /**
3044
+ * Nested DrawingML children under this group or canvas, in document order.
3045
+ * @public
3046
+ */
3047
+ get: function () {
3048
+ return this.children();
3049
+ },
3050
+ enumerable: true,
3051
+ configurable: true
3052
+ });
3053
+ Object.defineProperty(GroupShape.prototype, "childItems", {
3054
+ /**
3055
+ * Nested child items (collection surface).
3056
+ * @public
3057
+ */
3058
+ get: function () {
3059
+ return this.children();
3060
+ },
3061
+ enumerable: true,
3062
+ configurable: true
3063
+ });
3064
+ /**
3065
+ * Nested DrawingML children under this group or canvas.
3066
+ * @private
3067
+ */
3068
+ GroupShape.prototype.children = function () {
3069
+ return _super.prototype.children.call(this);
3070
+ };
3071
+ /**
3072
+ * Add an existing drawing leaf as a nested child. Detaches from anchoring paragraph when needed.
3073
+ * @public
3074
+ */
3075
+ GroupShape.prototype.add = function (paragraphItem) {
3076
+ var child;
3077
+ if (paragraphItem instanceof DrawingShape) {
3078
+ child = paragraphItem;
3079
+ }
3080
+ else if (paragraphItem instanceof FeatureRunParagraphItem &&
3081
+ paragraphItem.value instanceof DrawingShape) {
3082
+ child = paragraphItem.value;
3083
+ }
3084
+ if (child === undefined) {
3085
+ throw new DocxError('content/invalid-shape', 'GroupShape.add requires a drawing shape paragraph item');
3086
+ }
3087
+ if (child === this) {
3088
+ throw new DocxError('content/invalid-shape', 'GroupShape cannot add itself');
3089
+ }
3090
+ var para = child.getAnchoringParagraph();
3091
+ if (para !== undefined) {
3092
+ var items = para.items.toArray();
3093
+ for (var i = items.length - 1; i >= 0; i -= 1) {
3094
+ var it_1 = items[i];
3095
+ if (it_1 instanceof FeatureRunParagraphItem && it_1.value === child) {
3096
+ para.removeFeatureRunItem(child);
3097
+ break;
3098
+ }
3099
+ }
3100
+ }
3101
+ child.parentGroup = this;
3102
+ this.ensureChildrenModeled();
3103
+ this.childrenValue.push(child);
3104
+ this.childrenModeled = true;
3105
+ this.childrenCache = undefined;
3106
+ this.markStructureDirty();
3107
+ this.notifyParentOfChildDirty();
3108
+ };
3109
+ /**
3110
+ * Ungroup children into an array of drawing leaves.
3111
+ * @public
3112
+ */
3113
+ GroupShape.prototype.unGroup = function () {
3114
+ var e_13, _a;
3115
+ var kids = __spread(this.children());
3116
+ this.ensureChildrenModeled();
3117
+ try {
3118
+ for (var kids_2 = __values(kids), kids_2_1 = kids_2.next(); !kids_2_1.done; kids_2_1 = kids_2.next()) {
3119
+ var child = kids_2_1.value;
3120
+ child.parentGroup = undefined;
3121
+ }
3122
+ }
3123
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
3124
+ finally {
3125
+ try {
3126
+ if (kids_2_1 && !kids_2_1.done && (_a = kids_2.return)) _a.call(kids_2);
3127
+ }
3128
+ finally { if (e_13) throw e_13.error; }
3129
+ }
3130
+ this.childrenValue = [];
3131
+ this.childrenModeled = true;
3132
+ this.childrenCache = undefined;
3133
+ this.markStructureDirty();
3134
+ return kids;
3135
+ };
3136
+ /**
3137
+ * Append a nested preset-geometry {@link Shape} under this group.
3138
+ * @public
3139
+ */
3140
+ GroupShape.prototype.appendShape = function (autoShapeType, width, height) {
3141
+ return _super.prototype.appendShape.call(this, autoShapeType, width, height);
3142
+ };
3143
+ /** @private */
3144
+ GroupShape.prototype.writeShapeFillState = function (_value) {
3145
+ throw new DocxError('content/invalid-shape', 'Fill is not supported on GroupShape');
3146
+ };
3147
+ /** @private */
3148
+ GroupShape.prototype.writeShapeLineState = function (_value) {
3149
+ throw new DocxError('content/invalid-shape', 'Line is not supported on GroupShape');
3150
+ };
3151
+ /** @private */
3152
+ GroupShape.prototype.writeTextFrameDirection = function (_value) {
3153
+ throw new DocxError('content/invalid-shape', 'Text frame is not supported on GroupShape');
3154
+ };
3155
+ /** @private */
3156
+ GroupShape.prototype.writeTextFrameVerticalAlignment = function (_value) {
3157
+ throw new DocxError('content/invalid-shape', 'Text frame is not supported on GroupShape');
3158
+ };
3159
+ /** @private */
3160
+ GroupShape.prototype.ensureTextBodyAccessible = function () {
3161
+ throw new DocxError('content/invalid-shape', 'Text body is not supported on GroupShape');
3162
+ };
3163
+ return GroupShape;
3164
+ }(Shape));
3165
+ export { GroupShape };
3166
+ /**
3167
+ * Construct {@link Shape} or {@link GroupShape} from a residual host element.
3168
+ * Nested `wps:wsp` / `wpg:grpSp` residuals and top-level dual-AC trees are
3169
+ * classified by residual localName / Choice URI (TASK-8051).
3170
+ *
3171
+ * @private
3172
+ */
3173
+ export function createDrawingShape(encoding, element) {
3174
+ var __ts33_1;
3175
+ if (encoding === 'vml') {
3176
+ return new Shape(encoding, element);
3177
+ }
3178
+ if (isNestedDrawingResidual(element)) {
3179
+ if (element.localName === 'grpSp') {
3180
+ return new GroupShape(encoding, element);
3181
+ }
3182
+ return new Shape(encoding, element);
3183
+ }
3184
+ var drawing = ((__ts33_1 = preferredDrawingElement(element)), __ts33_1 != null ? __ts33_1 : (isWml(element, 'drawing') ? element : undefined));
3185
+ if (drawing !== undefined) {
3186
+ var fromUri = detectDmlVariant(drawing);
3187
+ if (fromUri === 'group' || fromUri === 'canvas') {
3188
+ return new GroupShape(encoding, element);
3189
+ }
3190
+ }
3191
+ // Unknown / picture-declined / bare fragments still surface as Shape leaves so
3192
+ // residual pass-through and identity APIs remain available.
3193
+ return new Shape(encoding, element);
3194
+ }
3195
+ /**
3196
+ * Construct {@link Shape} or {@link GroupShape} from an authored / modeled init.
3197
+ * Modeled `children` (including `[]`) always yields {@link GroupShape}.
3198
+ *
3199
+ * @private
3200
+ */
3201
+ export function createDrawingShapeFromInit(init) {
3202
+ var __ts33_2;
3203
+ if (init.children !== undefined) {
3204
+ return new GroupShape(init);
3205
+ }
3206
+ if (init.encoding === 'vml') {
3207
+ return new Shape(init);
3208
+ }
3209
+ if (isNestedDrawingResidual(init.residual)) {
3210
+ if (init.residual.localName === 'grpSp') {
3211
+ return new GroupShape(init);
3212
+ }
3213
+ return new Shape(init);
3214
+ }
3215
+ var drawing = ((__ts33_2 = preferredDrawingElement(init.residual)), __ts33_2 != null ? __ts33_2 : (isWml(init.residual, 'drawing') ? init.residual : undefined));
3216
+ if (drawing !== undefined) {
3217
+ var fromUri = detectDmlVariant(drawing);
3218
+ if (fromUri === 'group' || fromUri === 'canvas') {
3219
+ return new GroupShape(init);
3220
+ }
3221
+ }
3222
+ return new Shape(init);
3223
+ }
3224
+ /**
3225
+ * Type guard for leaf {@link Shape} instances (not group/canvas hosts).
3226
+ *
3227
+ * @private
3228
+ */
3229
+ export function isShape(value) {
3230
+ return value instanceof Shape;
3231
+ }
3232
+ /**
3233
+ * Type guard for {@link GroupShape} group/canvas hosts.
3234
+ *
3235
+ * @private
3236
+ */
3237
+ export function isGroupShape(value) {
3238
+ return value instanceof GroupShape;
3239
+ }