ooxml-core 1.32.0 → 1.33.0

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 (318) hide show
  1. package/dist/{PptxHandler-TESZUH66.cjs → PptxHandler-MGKMIK22.cjs} +3 -3
  2. package/dist/PptxHandler-Q7CFNKOU.mjs +7 -0
  3. package/dist/PptxHandler-TEC7SWBU.mjs +4 -0
  4. package/dist/{PresentationBuilder-3CH5TR4W.mjs → PresentationBuilder-PJMQRZI6.mjs} +2 -2
  5. package/dist/{PresentationBuilder-S6HXHKEJ.mjs → PresentationBuilder-SADKXDWC.mjs} +4 -4
  6. package/dist/{PresentationBuilder-5NFBUP7Y.cjs → PresentationBuilder-VP2637RH.cjs} +5 -5
  7. package/dist/automation/index.cjs +4398 -2262
  8. package/dist/automation/index.mjs +4398 -2262
  9. package/dist/chart/funnel-geometry.d.ts +1 -1
  10. package/dist/chart/funnel-geometry.d.ts.map +1 -1
  11. package/dist/chart/index.cjs +5743 -3820
  12. package/dist/chart/index.mjs +5736 -3821
  13. package/dist/chart/region-map/alias.d.ts +12 -0
  14. package/dist/chart/region-map/alias.d.ts.map +1 -0
  15. package/dist/chart/region-map/cache.d.ts +20 -0
  16. package/dist/chart/region-map/cache.d.ts.map +1 -0
  17. package/dist/chart/region-map/colors.d.ts +4 -0
  18. package/dist/chart/region-map/colors.d.ts.map +1 -0
  19. package/dist/chart/region-map/data.d.ts +45 -0
  20. package/dist/chart/region-map/data.d.ts.map +1 -0
  21. package/dist/chart/region-map/geographic-projection.d.ts +4 -0
  22. package/dist/chart/region-map/geographic-projection.d.ts.map +1 -0
  23. package/dist/chart/region-map/geometry.d.ts +10 -0
  24. package/dist/chart/region-map/geometry.d.ts.map +1 -0
  25. package/dist/chart/region-map/index.cjs +892 -0
  26. package/dist/chart/region-map/index.d.ts +12 -0
  27. package/dist/chart/region-map/index.d.ts.map +1 -0
  28. package/dist/chart/region-map/index.mjs +870 -0
  29. package/dist/chart/region-map/projection.d.ts +19 -0
  30. package/dist/chart/region-map/projection.d.ts.map +1 -0
  31. package/dist/chart/region-map/types.d.ts +39 -0
  32. package/dist/chart/region-map/types.d.ts.map +1 -0
  33. package/dist/chart/region-map/value-color-positions.d.ts +4 -0
  34. package/dist/chart/region-map/value-color-positions.d.ts.map +1 -0
  35. package/dist/chart/region-map/value-colors.d.ts +4 -0
  36. package/dist/chart/region-map/value-colors.d.ts.map +1 -0
  37. package/dist/chart/region-map/world-regions.d.ts +22 -0
  38. package/dist/chart/region-map/world-regions.d.ts.map +1 -0
  39. package/dist/chart/render/chart-3d-camera.d.ts +26 -0
  40. package/dist/chart/render/chart-3d-camera.d.ts.map +1 -0
  41. package/dist/chart/render/chart-3d-layout.d.ts +27 -0
  42. package/dist/chart/render/chart-3d-layout.d.ts.map +1 -0
  43. package/dist/chart/render/chart-3d-marks.d.ts +10 -0
  44. package/dist/chart/render/chart-3d-marks.d.ts.map +1 -0
  45. package/dist/chart/render/chart-3d-mesh.d.ts +32 -0
  46. package/dist/chart/render/chart-3d-mesh.d.ts.map +1 -0
  47. package/dist/chart/render/chart-3d-pie.d.ts +16 -0
  48. package/dist/chart/render/chart-3d-pie.d.ts.map +1 -0
  49. package/dist/chart/render/chart-3d-projection.d.ts +37 -0
  50. package/dist/chart/render/chart-3d-projection.d.ts.map +1 -0
  51. package/dist/chart/render/chart-3d-scene.d.ts +9 -0
  52. package/dist/chart/render/chart-3d-scene.d.ts.map +1 -0
  53. package/dist/chart/render/chart-3d-shading.d.ts +10 -0
  54. package/dist/chart/render/chart-3d-shading.d.ts.map +1 -0
  55. package/dist/chart/render/chart-3d-surface.d.ts +5 -0
  56. package/dist/chart/render/chart-3d-surface.d.ts.map +1 -0
  57. package/dist/chart/render/chart-3d-svg.d.ts +7 -0
  58. package/dist/chart/render/chart-3d-svg.d.ts.map +1 -0
  59. package/dist/chart/render/chart-3d-walls.d.ts +13 -0
  60. package/dist/chart/render/chart-3d-walls.d.ts.map +1 -0
  61. package/dist/chart/render/chart-svg-funnel.d.ts.map +1 -1
  62. package/dist/chart/render/chart-svg-region-map.d.ts +4 -0
  63. package/dist/chart/render/chart-svg-region-map.d.ts.map +1 -0
  64. package/dist/chart/render/chart-svg-text-metrics.d.ts +2 -0
  65. package/dist/chart/render/chart-svg-text-metrics.d.ts.map +1 -1
  66. package/dist/chart/render/chart-svg.d.ts.map +1 -1
  67. package/dist/chart/render/chart-view.d.ts +5 -1
  68. package/dist/chart/render/chart-view.d.ts.map +1 -1
  69. package/dist/chart/render/index.d.ts +5 -0
  70. package/dist/chart/render/index.d.ts.map +1 -1
  71. package/dist/chart/render/render-space.d.ts.map +1 -1
  72. package/dist/chart/render/summary-ex-formatting.d.ts +5 -0
  73. package/dist/chart/render/summary-ex-formatting.d.ts.map +1 -0
  74. package/dist/chart/render/summary-ex-series.d.ts.map +1 -1
  75. package/dist/chart/render/summary-from-chartex.d.ts.map +1 -1
  76. package/dist/chart/render/summary-from-space.d.ts.map +1 -1
  77. package/dist/chart/render/summary.d.ts +5 -1
  78. package/dist/chart/render/summary.d.ts.map +1 -1
  79. package/dist/{chunk-Q6NM64J2.cjs → chunk-2LTIDUXH.cjs} +4791 -950
  80. package/dist/chunk-2N7RZQLC.mjs +8 -0
  81. package/dist/{chunk-NAWLWKOJ.mjs → chunk-3LMHYL4W.mjs} +2 -2
  82. package/dist/{chunk-O7SVHLD7.mjs → chunk-6LJW76BZ.mjs} +4756 -951
  83. package/dist/{chunk-X6VNUBES.cjs → chunk-BDZR4DZ6.cjs} +2058 -1748
  84. package/dist/{chunk-IOTGRLJH.mjs → chunk-BQGLWC6N.mjs} +867 -557
  85. package/dist/{chunk-N6424WKA.mjs → chunk-EBBWRRSB.mjs} +1 -1
  86. package/dist/{chunk-UYMSFJQZ.mjs → chunk-JQVOUS6B.mjs} +5 -5
  87. package/dist/{chunk-3H5UAJB3.mjs → chunk-QRXMYOVN.mjs} +870 -525
  88. package/dist/{chunk-54S5A5PZ.mjs → chunk-VDUNZTJC.mjs} +36 -1
  89. package/dist/{chunk-4R65YYAD.mjs → chunk-Y2RH4QWG.mjs} +4228 -1070
  90. package/dist/diagram/drawing-resolve.d.ts.map +1 -1
  91. package/dist/diagram/drawing-view.d.ts +6 -0
  92. package/dist/diagram/drawing-view.d.ts.map +1 -1
  93. package/dist/diagram/engine/engine-to-result.d.ts.map +1 -1
  94. package/dist/diagram/index.cjs +786 -145
  95. package/dist/diagram/index.d.ts +1 -0
  96. package/dist/diagram/index.d.ts.map +1 -1
  97. package/dist/diagram/index.mjs +783 -147
  98. package/dist/diagram/layout/smartart-layout-types.d.ts +7 -0
  99. package/dist/diagram/layout/smartart-layout-types.d.ts.map +1 -1
  100. package/dist/diagram/layout-preview.d.ts +4 -0
  101. package/dist/diagram/layout-preview.d.ts.map +1 -1
  102. package/dist/diagram/layout-role-style.d.ts +4 -0
  103. package/dist/diagram/layout-role-style.d.ts.map +1 -0
  104. package/dist/diagram/load.d.ts.map +1 -1
  105. package/dist/diagram/picture-layout.d.ts +23 -0
  106. package/dist/diagram/picture-layout.d.ts.map +1 -0
  107. package/dist/diagram/types.d.ts +6 -0
  108. package/dist/diagram/types.d.ts.map +1 -1
  109. package/dist/diagram/write/cache.d.ts +1 -0
  110. package/dist/diagram/write/cache.d.ts.map +1 -1
  111. package/dist/digest/crc32.d.ts +2 -0
  112. package/dist/digest/crc32.d.ts.map +1 -0
  113. package/dist/digest/index.cjs +11 -0
  114. package/dist/digest/index.d.ts +1 -0
  115. package/dist/digest/index.d.ts.map +1 -1
  116. package/dist/digest/index.mjs +11 -1
  117. package/dist/docx/diagram-cache.d.ts.map +1 -1
  118. package/dist/docx/diagram-save.d.ts.map +1 -1
  119. package/dist/docx/drawing.d.ts.map +1 -1
  120. package/dist/docx/embedded.cjs +882 -212
  121. package/dist/docx/embedded.mjs +882 -212
  122. package/dist/docx/index.cjs +3082 -866
  123. package/dist/docx/index.mjs +3082 -866
  124. package/dist/docx/inline-model.d.ts +4 -0
  125. package/dist/docx/inline-model.d.ts.map +1 -1
  126. package/dist/docx/layout/adapt-floats.d.ts.map +1 -1
  127. package/dist/docx/layout/adapter.d.ts.map +1 -1
  128. package/dist/docx/layout/floats.d.ts.map +1 -1
  129. package/dist/docx/layout/index.cjs +2200 -438
  130. package/dist/docx/layout/index.mjs +2200 -438
  131. package/dist/docx/layout/input.d.ts +3 -0
  132. package/dist/docx/layout/input.d.ts.map +1 -1
  133. package/dist/docx/layout/result.d.ts +3 -0
  134. package/dist/docx/layout/result.d.ts.map +1 -1
  135. package/dist/docx/load/index.cjs +1311 -641
  136. package/dist/docx/load/index.mjs +1311 -641
  137. package/dist/docx/parse.d.ts.map +1 -1
  138. package/dist/docx/ui/index.cjs +2832 -842
  139. package/dist/docx/ui/index.mjs +2832 -842
  140. package/dist/docx/ui/inline-content-schema.d.ts.map +1 -1
  141. package/dist/docx/ui/run-adapter.d.ts.map +1 -1
  142. package/dist/docx/write-drawing.d.ts.map +1 -1
  143. package/dist/drawingml/index.cjs +707 -111
  144. package/dist/drawingml/index.d.ts +7 -0
  145. package/dist/drawingml/index.d.ts.map +1 -1
  146. package/dist/drawingml/index.mjs +697 -113
  147. package/dist/drawingml/picture-artistic.d.ts +14 -0
  148. package/dist/drawingml/picture-artistic.d.ts.map +1 -0
  149. package/dist/drawingml/picture-effects.d.ts +4 -1
  150. package/dist/drawingml/picture-effects.d.ts.map +1 -1
  151. package/dist/drawingml/picture-fill.d.ts.map +1 -1
  152. package/dist/drawingml/picture-hsl-pixels.d.ts +4 -0
  153. package/dist/drawingml/picture-hsl-pixels.d.ts.map +1 -0
  154. package/dist/drawingml/picture-layout.d.ts +25 -0
  155. package/dist/drawingml/picture-layout.d.ts.map +1 -0
  156. package/dist/drawingml/picture-standard-effects.d.ts +15 -0
  157. package/dist/drawingml/picture-standard-effects.d.ts.map +1 -0
  158. package/dist/drawingml/picture-transfer.d.ts +11 -0
  159. package/dist/drawingml/picture-transfer.d.ts.map +1 -0
  160. package/dist/drawingml/raster-image.d.ts +29 -0
  161. package/dist/drawingml/raster-image.d.ts.map +1 -0
  162. package/dist/drawingml/types.d.ts +1 -0
  163. package/dist/drawingml/types.d.ts.map +1 -1
  164. package/dist/drawingml/write-pattern-picture.d.ts.map +1 -1
  165. package/dist/geometry/index.cjs +38 -0
  166. package/dist/geometry/index.d.ts +1 -0
  167. package/dist/geometry/index.d.ts.map +1 -1
  168. package/dist/geometry/index.mjs +36 -1
  169. package/dist/geometry/picture-tile.d.ts +29 -0
  170. package/dist/geometry/picture-tile.d.ts.map +1 -0
  171. package/dist/index.cjs +15164 -12669
  172. package/dist/index.mjs +15164 -12669
  173. package/dist/pptx/automation/index.cjs +7431 -2967
  174. package/dist/pptx/automation/index.d.ts +5 -5
  175. package/dist/pptx/automation/index.mjs +7 -7
  176. package/dist/pptx/chunks/{elements-mSCZ84Tc.d.ts → elements-f3UbFph-.d.ts} +7 -2
  177. package/dist/pptx/chunks/elements-f3UbFph-.d.ts.map +1 -0
  178. package/dist/pptx/chunks/{index-DnWlmYCy.d.ts → index-BnH2QjYm.d.ts} +4 -4
  179. package/dist/pptx/chunks/{index-DnWlmYCy.d.ts.map → index-BnH2QjYm.d.ts.map} +1 -1
  180. package/dist/pptx/chunks/{index-D-FdgqrP.d.ts → index-Bp-1pGo1.d.ts} +4 -4
  181. package/dist/pptx/chunks/{index-D-FdgqrP.d.ts.map → index-Bp-1pGo1.d.ts.map} +1 -1
  182. package/dist/pptx/chunks/{index-DKybuHPT.d.ts → index-BuMPQDQb.d.ts} +27 -16
  183. package/dist/pptx/chunks/index-BuMPQDQb.d.ts.map +1 -0
  184. package/dist/pptx/chunks/{smart-art-DLumQo90.d.ts → smart-art-CmOrPLLQ.d.ts} +86 -2
  185. package/dist/pptx/chunks/smart-art-CmOrPLLQ.d.ts.map +1 -0
  186. package/dist/pptx/chunks/{text-operations-hyPODwIQ.d.ts → text-operations-D5sgspO6.d.ts} +2 -2
  187. package/dist/pptx/chunks/{text-operations-hyPODwIQ.d.ts.map → text-operations-D5sgspO6.d.ts.map} +1 -1
  188. package/dist/pptx/cli/index.cjs +7196 -2732
  189. package/dist/pptx/cli/index.d.ts +1 -1
  190. package/dist/pptx/cli/index.mjs +6 -6
  191. package/dist/pptx/converter/index.cjs +3895 -503
  192. package/dist/pptx/converter/index.d.ts +1 -1
  193. package/dist/pptx/converter/index.mjs +3 -3
  194. package/dist/pptx/editor/render/find-replace.cjs +14 -14
  195. package/dist/pptx/editor/render/find-replace.d.ts +2 -2
  196. package/dist/pptx/editor/render/find-replace.mjs +1 -1
  197. package/dist/pptx/editor/render/slide-operations.cjs +8 -8
  198. package/dist/pptx/editor/render/slide-operations.mjs +2 -2
  199. package/dist/pptx/editor/render/text-runs-style-patch.d.ts +1 -1
  200. package/dist/pptx/editor/render/text-style-scope.d.ts +1 -1
  201. package/dist/pptx/index.cjs +6828 -2969
  202. package/dist/pptx/index.d.ts +7 -7
  203. package/dist/pptx/index.mjs +7 -7
  204. package/dist/pptx/node/index.d.ts +1 -1
  205. package/dist/pptx/smartart-layouts/index.d.ts +1 -1
  206. package/dist/pptx/smartart-layouts/index.mjs +2 -2
  207. package/dist/teams/index.cjs +1964 -726
  208. package/dist/teams/index.mjs +1964 -726
  209. package/dist/visio/cell-formula.d.ts +5 -1
  210. package/dist/visio/cell-formula.d.ts.map +1 -1
  211. package/dist/visio/collab/index.cjs +3 -1
  212. package/dist/visio/collab/index.mjs +3 -1
  213. package/dist/visio/container-relationships.d.ts +19 -0
  214. package/dist/visio/container-relationships.d.ts.map +1 -0
  215. package/dist/visio/edit-container-fit.d.ts +19 -0
  216. package/dist/visio/edit-container-fit.d.ts.map +1 -0
  217. package/dist/visio/edit-container-members.d.ts +21 -0
  218. package/dist/visio/edit-container-members.d.ts.map +1 -0
  219. package/dist/visio/edit-delete.d.ts.map +1 -1
  220. package/dist/visio/edit-diagram-parts-commands.d.ts +23 -1
  221. package/dist/visio/edit-diagram-parts-commands.d.ts.map +1 -1
  222. package/dist/visio/edit-diagram-parts.d.ts +3 -2
  223. package/dist/visio/edit-diagram-parts.d.ts.map +1 -1
  224. package/dist/visio/edit-geometry.d.ts +4 -1
  225. package/dist/visio/edit-geometry.d.ts.map +1 -1
  226. package/dist/visio/edit-recalculate-index.d.ts +13 -0
  227. package/dist/visio/edit-recalculate-index.d.ts.map +1 -1
  228. package/dist/visio/edit-recalculate-values.d.ts.map +1 -1
  229. package/dist/visio/edit-recalculate.d.ts.map +1 -1
  230. package/dist/visio/edit.d.ts.map +1 -1
  231. package/dist/visio/formula-analyze.d.ts +2 -0
  232. package/dist/visio/formula-analyze.d.ts.map +1 -1
  233. package/dist/visio/formula-evaluate.d.ts.map +1 -1
  234. package/dist/visio/formula-master.d.ts +1 -0
  235. package/dist/visio/formula-master.d.ts.map +1 -1
  236. package/dist/visio/index.cjs +2771 -1312
  237. package/dist/visio/index.d.ts +1 -1
  238. package/dist/visio/index.d.ts.map +1 -1
  239. package/dist/visio/index.mjs +2771 -1312
  240. package/dist/visio/media.d.ts +4 -23
  241. package/dist/visio/media.d.ts.map +1 -1
  242. package/dist/visio/package-common.d.ts +1 -1
  243. package/dist/visio/package-common.d.ts.map +1 -1
  244. package/dist/visio/shape-structure.d.ts +6 -3
  245. package/dist/visio/shape-structure.d.ts.map +1 -1
  246. package/dist/visio/ui/diagram-parts.d.ts +12 -1
  247. package/dist/visio/ui/diagram-parts.d.ts.map +1 -1
  248. package/dist/visio/ui/index.cjs +2679 -1201
  249. package/dist/visio/ui/index.mjs +2679 -1202
  250. package/dist/xlsx/edit/cell-values.d.ts.map +1 -1
  251. package/dist/xlsx/edit/chart-ex.d.ts +1 -0
  252. package/dist/xlsx/edit/chart-ex.d.ts.map +1 -1
  253. package/dist/xlsx/edit/filter.d.ts +5 -1
  254. package/dist/xlsx/edit/filter.d.ts.map +1 -1
  255. package/dist/xlsx/edit/index.d.ts +1 -0
  256. package/dist/xlsx/edit/index.d.ts.map +1 -1
  257. package/dist/xlsx/edit/session-calc.d.ts +5 -0
  258. package/dist/xlsx/edit/session-calc.d.ts.map +1 -1
  259. package/dist/xlsx/edit/session.d.ts.map +1 -1
  260. package/dist/xlsx/edit/text-columns.d.ts +21 -0
  261. package/dist/xlsx/edit/text-columns.d.ts.map +1 -0
  262. package/dist/xlsx/edit/types.d.ts +5 -1
  263. package/dist/xlsx/edit/types.d.ts.map +1 -1
  264. package/dist/xlsx/embedded-chart-ex-space.d.ts +18 -0
  265. package/dist/xlsx/embedded-chart-ex-space.d.ts.map +1 -0
  266. package/dist/xlsx/filter-criteria.d.ts +22 -0
  267. package/dist/xlsx/filter-criteria.d.ts.map +1 -0
  268. package/dist/xlsx/filter-dynamic.d.ts +8 -0
  269. package/dist/xlsx/filter-dynamic.d.ts.map +1 -0
  270. package/dist/xlsx/filter-menu.d.ts +49 -0
  271. package/dist/xlsx/filter-menu.d.ts.map +1 -0
  272. package/dist/xlsx/filter-rows.d.ts +4 -4
  273. package/dist/xlsx/filter-rows.d.ts.map +1 -1
  274. package/dist/xlsx/index.cjs +5861 -2939
  275. package/dist/xlsx/index.d.ts +4 -0
  276. package/dist/xlsx/index.d.ts.map +1 -1
  277. package/dist/xlsx/index.mjs +5844 -2939
  278. package/dist/xlsx/load/index.cjs +1871 -585
  279. package/dist/xlsx/load/index.mjs +1871 -585
  280. package/dist/xlsx/model-filter.d.ts +54 -0
  281. package/dist/xlsx/model-filter.d.ts.map +1 -0
  282. package/dist/xlsx/model.d.ts +42 -3
  283. package/dist/xlsx/model.d.ts.map +1 -1
  284. package/dist/xlsx/read/chart.d.ts.map +1 -1
  285. package/dist/xlsx/read/drawing.d.ts.map +1 -1
  286. package/dist/xlsx/read/filter-columns.d.ts +5 -0
  287. package/dist/xlsx/read/filter-columns.d.ts.map +1 -0
  288. package/dist/xlsx/read/shared-strings.d.ts +5 -3
  289. package/dist/xlsx/read/shared-strings.d.ts.map +1 -1
  290. package/dist/xlsx/read/sheet-data.d.ts.map +1 -1
  291. package/dist/xlsx/read/sheet-props.d.ts +2 -2
  292. package/dist/xlsx/read/sheet-props.d.ts.map +1 -1
  293. package/dist/xlsx/ui/commands/i18n/filters.d.ts +3 -0
  294. package/dist/xlsx/ui/commands/i18n/filters.d.ts.map +1 -0
  295. package/dist/xlsx/ui/commands/i18n/index.d.ts.map +1 -1
  296. package/dist/xlsx/ui/commands/i18n/navigation.d.ts.map +1 -1
  297. package/dist/xlsx/ui/commands/i18n/tools.d.ts.map +1 -1
  298. package/dist/xlsx/ui/commands/sort-filter.d.ts.map +1 -1
  299. package/dist/xlsx/ui/dialogs/grid-chart.d.ts.map +1 -1
  300. package/dist/xlsx/ui/index.cjs +7177 -4234
  301. package/dist/xlsx/ui/index.mjs +7177 -4234
  302. package/dist/xlsx/write/drawing.d.ts.map +1 -1
  303. package/dist/xlsx/write/filter-columns.d.ts +39 -0
  304. package/dist/xlsx/write/filter-columns.d.ts.map +1 -0
  305. package/dist/xlsx/write/shared-strings.d.ts +4 -4
  306. package/dist/xlsx/write/shared-strings.d.ts.map +1 -1
  307. package/dist/xlsx/write/sheet-props.d.ts +2 -1
  308. package/dist/xlsx/write/sheet-props.d.ts.map +1 -1
  309. package/dist/xlsx/write/smart-art-cache.d.ts.map +1 -1
  310. package/dist/xlsx/write/smart-art.d.ts.map +1 -1
  311. package/dist/xlsx/write/workbook-part.d.ts.map +1 -1
  312. package/package.json +6 -1
  313. package/dist/PptxHandler-QY5VL3CY.mjs +0 -7
  314. package/dist/PptxHandler-SJ5ZUIUX.mjs +0 -4
  315. package/dist/chunk-3GXV5MPC.mjs +0 -41
  316. package/dist/pptx/chunks/elements-mSCZ84Tc.d.ts.map +0 -1
  317. package/dist/pptx/chunks/index-DKybuHPT.d.ts.map +0 -1
  318. package/dist/pptx/chunks/smart-art-DLumQo90.d.ts.map +0 -1
@@ -8461,359 +8461,133 @@ function setExtendedRunProperties(doc, props, run2, base) {
8461
8461
  }
8462
8462
  }
8463
8463
 
8464
- // drawingml/image-content-type.ts
8465
- function imageContentType(partName) {
8466
- const extension = partName.split(".").pop()?.toLowerCase();
8467
- const known = {
8468
- png: "image/png",
8469
- jpg: "image/jpeg",
8470
- jpeg: "image/jpeg",
8471
- gif: "image/gif",
8472
- bmp: "image/bmp",
8473
- svg: "image/svg+xml",
8474
- tif: "image/tiff",
8475
- tiff: "image/tiff",
8476
- emf: "image/x-emf",
8477
- wmf: "image/x-wmf"
8464
+ // drawingml/dom.ts
8465
+ function attributeReader(element4) {
8466
+ return (name) => {
8467
+ if (!element4) return void 0;
8468
+ const direct = element4.getAttribute(name);
8469
+ if (direct !== null) return direct;
8470
+ const attributes2 = element4.attributes;
8471
+ for (let index = 0; index < attributes2.length; index++) {
8472
+ const candidate = attributes2.item(index);
8473
+ if (candidate && candidate.localName === name) return candidate.value;
8474
+ }
8475
+ return void 0;
8478
8476
  };
8479
- return extension && known[extension] || "application/octet-stream";
8480
8477
  }
8481
-
8482
- // docx/package-parts.ts
8483
- function resolveInternalTarget(target) {
8484
- if (target.startsWith("/")) return target.replace(/^\//, "");
8485
- return `word/${target.replace(/^\.\//, "")}`;
8478
+ function stringAttribute(element4, name) {
8479
+ const value = attributeReader(element4)(name)?.trim();
8480
+ return value ? value : void 0;
8486
8481
  }
8487
-
8488
- // docx/defined-props.ts
8489
- function definedProps(source2) {
8490
- return Object.fromEntries(Object.entries(source2).filter(([, value]) => value !== void 0));
8482
+ function integerAttribute(element4, name) {
8483
+ const parsed = Number.parseInt(attributeReader(element4)(name) ?? "", 10);
8484
+ return Number.isFinite(parsed) ? parsed : void 0;
8491
8485
  }
8492
-
8493
- // docx/watermark.ts
8494
- var VML_NS = "urn:schemas-microsoft-com:vml";
8495
- var OFFICE_NS = "urn:schemas-microsoft-com:office:office";
8496
- var WORD10_NS = "urn:schemas-microsoft-com:office:word";
8497
- var NAMED = {
8498
- silver: "#c0c0c0",
8499
- gray: "#808080",
8500
- grey: "#808080",
8501
- black: "#000000",
8502
- white: "#ffffff",
8503
- red: "#ff0000",
8504
- blue: "#0000ff",
8505
- green: "#008000",
8506
- yellow: "#ffff00"
8507
- };
8508
- var POINT_TO_PX = 96 / 72;
8509
- var WATERMARK_PREFIX = "PowerPlusWaterMarkObject";
8510
- var DEFAULT_WATERMARK_COLOR = "#c0c0c0";
8511
- function colorOf(value) {
8512
- const text = (value ?? "").trim().toLowerCase().split(/\s/)[0] ?? "";
8513
- if (NAMED[text]) return NAMED[text];
8514
- const hex = /^#?([0-9a-f]{6})$/.exec(text);
8515
- return hex ? `#${hex[1]}` : DEFAULT_WATERMARK_COLOR;
8486
+ function booleanAttribute(element4, name) {
8487
+ const value = attributeReader(element4)(name)?.trim().toLowerCase();
8488
+ if (value === "1" || value === "true") return true;
8489
+ if (value === "0" || value === "false") return false;
8490
+ return void 0;
8516
8491
  }
8517
- function parseWatermarkShape(shape) {
8518
- if (!shape || !(shape.getAttribute("id") ?? "").startsWith(WATERMARK_PREFIX)) return void 0;
8519
- const path3 = Array.from(shape.getElementsByTagNameNS(VML_NS, "textpath"))[0];
8520
- if (!path3) return void 0;
8521
- const style = shape.getAttribute("style") ?? "";
8522
- const fill = Array.from(shape.getElementsByTagNameNS(VML_NS, "fill"))[0];
8523
- const opacity = fill?.getAttribute("opacity");
8524
- const family = /font-family:\s*(?:&quot;|"|')?([^;"'&]+)/i.exec(
8525
- path3.getAttribute("style") ?? ""
8526
- )?.[1];
8527
- const width = /width:\s*([\d.]+)pt/i.exec(style);
8528
- const height = /height:\s*([\d.]+)pt/i.exec(style);
8529
- const rotation2 = /rotation:\s*(-?[\d.]+)/i.exec(style);
8530
- const spec = {
8531
- text: path3.getAttribute("string") ?? "",
8532
- color: colorOf(shape.getAttribute("fillcolor")),
8533
- semitransparent: opacity !== null && opacity !== "" && opacity !== "1",
8534
- layout: rotation2 && Math.abs(Number(rotation2[1]) % 360) > 1 ? "diagonal" : "horizontal",
8535
- ...family ? { fontFamily: family.trim() } : {}
8536
- };
8537
- return {
8538
- relId: "",
8539
- partName: "",
8540
- contentType: "application/octet-stream",
8541
- widthPx: width ? Math.round(Number(width[1]) * POINT_TO_PX) : 0,
8542
- heightPx: height ? Math.round(Number(height[1]) * POINT_TO_PX) : 0,
8543
- unsupported: "Watermark",
8544
- watermark: spec
8492
+ function descendants(root, local) {
8493
+ const result = [];
8494
+ const visit = (node) => {
8495
+ for (const child8 of Array.from(node.childNodes)) {
8496
+ if (!isElement(child8)) continue;
8497
+ if (child8.localName === local) result.push(child8);
8498
+ visit(child8);
8499
+ }
8545
8500
  };
8501
+ visit(root);
8502
+ return result;
8546
8503
  }
8547
- function watermarkSizePt(spec) {
8548
- const chars = Math.max(1, [...spec.text].length);
8549
- const width = Math.min(spec.layout === "diagonal" ? 527 : 468, Math.max(150, chars * 44));
8550
- return { width, height: Math.round(width / (chars * 0.55) * 100) / 100 };
8504
+
8505
+ // drawingml/picture-crop.ts
8506
+ var SIDES5 = { l: "cropLeft", t: "cropTop", r: "cropRight", b: "cropBottom" };
8507
+ function parsePictureCrop(blipFill) {
8508
+ const rect2 = first(blipFill, "srcRect", NS.a);
8509
+ if (!rect2) return void 0;
8510
+ const result = {};
8511
+ for (const [attr3, key] of Object.entries(SIDES5)) {
8512
+ const raw2 = rect2.getAttribute(attr3);
8513
+ if (raw2 === null || !raw2.trim()) continue;
8514
+ const percent = raw2.endsWith("%");
8515
+ const value = Number(percent ? raw2.slice(0, -1) : raw2) / (percent ? 100 : 1e5);
8516
+ if (Number.isFinite(value)) result[key] = value;
8517
+ }
8518
+ return result;
8551
8519
  }
8552
- var FORMULAS = [
8553
- "sum #0 0 10800",
8554
- "prod #0 2 1",
8555
- "sum 21600 0 @1",
8556
- "sum 0 0 @2",
8557
- "sum 21600 0 @3",
8558
- "if @0 @3 0",
8559
- "if @0 21600 @1",
8560
- "if @0 0 @2",
8561
- "if @0 @4 21600",
8562
- "mid @5 @6",
8563
- "mid @8 @5",
8564
- "mid @7 @8",
8565
- "mid @6 @7",
8566
- "sum @6 0 @5"
8567
- ];
8568
- function buildWatermarkRun(doc, spec, uniqueId) {
8569
- const v = (name) => makeNS(doc, VML_NS, `v:${name}`);
8570
- const run2 = makeW(doc, "r");
8571
- const props = makeW(doc, "rPr");
8572
- props.appendChild(makeW(doc, "noProof"));
8573
- run2.appendChild(props);
8574
- const pict = makeW(doc, "pict");
8575
- const type = v("shapetype");
8576
- type.setAttribute("id", "_x0000_t136");
8577
- type.setAttribute("coordsize", "21600,21600");
8578
- type.setAttributeNS(OFFICE_NS, "o:spt", "136");
8579
- type.setAttribute("adj", "10800");
8580
- type.setAttribute("path", "m@7,l@8,m@5,21600l@6,21600e");
8581
- const formulas = v("formulas");
8582
- for (const eqn of FORMULAS) {
8583
- const f6 = v("f");
8584
- f6.setAttribute("eqn", eqn);
8585
- formulas.appendChild(f6);
8520
+ function applyPictureCrop(blipFill, crop) {
8521
+ let rect2 = first(blipFill, "srcRect", NS.a);
8522
+ if (!rect2 && crop && Object.values(crop).some((value) => value !== void 0)) {
8523
+ rect2 = blipFill.ownerDocument.createElementNS(NS.a, "a:srcRect");
8524
+ const blip = first(blipFill, "blip", NS.a);
8525
+ blipFill.insertBefore(rect2, blip?.nextSibling ?? blipFill.firstChild);
8526
+ }
8527
+ if (!rect2) return;
8528
+ for (const [attr3, key] of Object.entries(SIDES5)) {
8529
+ const value = crop?.[key];
8530
+ if (value === void 0) rect2.removeAttribute(attr3);
8531
+ else {
8532
+ if (!Number.isFinite(value)) throw new RangeError("Picture crop must be finite");
8533
+ rect2.setAttribute(attr3, String(Math.round(value * 1e5)));
8534
+ }
8586
8535
  }
8587
- const path3 = v("path");
8588
- path3.setAttribute("textpathok", "t");
8589
- path3.setAttributeNS(OFFICE_NS, "o:connecttype", "custom");
8590
- path3.setAttributeNS(OFFICE_NS, "o:connectlocs", "@9,0;@10,10800;@11,21600;@12,10800");
8591
- path3.setAttributeNS(OFFICE_NS, "o:connectangles", "270,180,90,0");
8592
- const typePath = v("textpath");
8593
- typePath.setAttribute("on", "t");
8594
- typePath.setAttribute("fitshape", "t");
8595
- const handles = v("handles");
8596
- const handle = v("h");
8597
- handle.setAttribute("position", "#0,bottomRight");
8598
- handle.setAttribute("xrange", "6629,14971");
8599
- handles.appendChild(handle);
8600
- const lock = makeNS(doc, OFFICE_NS, "o:lock");
8601
- lock.setAttributeNS(VML_NS, "v:ext", "edit");
8602
- lock.setAttribute("text", "t");
8603
- lock.setAttribute("shapetype", "t");
8604
- for (const child8 of [formulas, path3, typePath, handles, lock]) type.appendChild(child8);
8605
- const size = watermarkSizePt(spec);
8606
- const shape = v("shape");
8607
- shape.setAttribute("id", `${WATERMARK_PREFIX}${uniqueId}`);
8608
- shape.setAttributeNS(OFFICE_NS, "o:spid", `_x0000_s${2048 + (Number(uniqueId) || 1)}`);
8609
- shape.setAttribute("type", "#_x0000_t136");
8610
- shape.setAttribute(
8611
- "style",
8612
- `position:absolute;margin-left:0;margin-top:0;width:${size.width}pt;height:${size.height}pt;${spec.layout === "diagonal" ? "rotation:315;" : ""}z-index:-251658752;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin`
8613
- );
8614
- shape.setAttributeNS(OFFICE_NS, "o:allowincell", "f");
8615
- shape.setAttribute("fillcolor", spec.color.replace(/^#/, "").toLowerCase());
8616
- shape.setAttribute("stroked", "f");
8617
- const fill = v("fill");
8618
- fill.setAttribute("opacity", spec.semitransparent ? ".5" : "1");
8619
- const text = v("textpath");
8620
- text.setAttribute("style", `font-family:"${spec.fontFamily ?? "Calibri"}";font-size:1pt`);
8621
- text.setAttribute("string", spec.text);
8622
- const wrap2 = makeNS(doc, WORD10_NS, "w10:wrap");
8623
- wrap2.setAttribute("anchorx", "margin");
8624
- wrap2.setAttribute("anchory", "margin");
8625
- for (const child8 of [fill, text, wrap2]) shape.appendChild(child8);
8626
- pict.appendChild(type);
8627
- pict.appendChild(shape);
8628
- run2.appendChild(pict);
8629
- return run2;
8630
8536
  }
8631
8537
 
8632
- // docx/write-text-box.ts
8633
- var A_NS = "http://schemas.openxmlformats.org/drawingml/2006/main";
8634
- var WP_NS = "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing";
8635
- var WPS_NS = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
8636
- var W_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
8637
- var SHAPE_GRAPHIC_URI = WPS_NS;
8638
- var el = (doc, ns, name) => makeNS(doc, ns, name);
8639
- var add = (parent, ...items) => {
8640
- for (const item2 of items) parent.appendChild(item2);
8641
- return parent;
8642
- };
8643
- var emu = (px2) => String(Math.max(1, Math.round(px2 * EMU_PER_PIXEL)));
8644
- var descendants = (root, ns, local) => Array.from(root.getElementsByTagNameNS(ns, local));
8645
- function paragraphsFor(doc, lines2) {
8646
- return (lines2.length ? lines2 : [""]).map((line2) => {
8647
- const paragraph2 = makeW(doc, "p");
8648
- if (line2) {
8649
- const run2 = makeW(doc, "r");
8650
- const text = makeW(doc, "t");
8651
- if (/^\s|\s$/.test(line2))
8652
- text.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:space", "preserve");
8653
- text.textContent = line2;
8654
- add(run2, text);
8655
- add(paragraph2, run2);
8656
- }
8657
- return paragraph2;
8658
- });
8659
- }
8660
- function outline(doc, border) {
8661
- const ln = el(doc, A_NS, "a:ln");
8662
- if (!border) return add(ln, el(doc, A_NS, "a:noFill"));
8663
- ln.setAttribute("w", "9525");
8664
- const color = el(doc, A_NS, "a:srgbClr");
8665
- color.setAttribute("val", "000000");
8666
- return add(ln, add(el(doc, A_NS, "a:solidFill"), color));
8667
- }
8668
- function buildTextBoxDrawing(doc, image, docPrId) {
8669
- const drawing = makeW(doc, "drawing");
8670
- const inline = el(doc, WP_NS, "wp:inline");
8671
- for (const side of ["distT", "distB", "distL", "distR"]) inline.setAttribute(side, "0");
8672
- const extent = el(doc, WP_NS, "wp:extent");
8673
- extent.setAttribute("cx", emu(image.widthPx));
8674
- extent.setAttribute("cy", emu(image.heightPx));
8675
- const effect = el(doc, WP_NS, "wp:effectExtent");
8676
- for (const side of ["l", "t", "r", "b"]) effect.setAttribute(side, "0");
8677
- const docPr = el(doc, WP_NS, "wp:docPr");
8678
- docPr.setAttribute("id", docPrId);
8679
- docPr.setAttribute("name", `Text Box ${docPrId}`);
8680
- if (image.altText) docPr.setAttribute("descr", image.altText);
8681
- const wsp = el(doc, WPS_NS, "wps:wsp");
8682
- const cNvSpPr = el(doc, WPS_NS, "wps:cNvSpPr");
8683
- cNvSpPr.setAttribute("txBox", "1");
8684
- const xfrm = el(doc, A_NS, "a:xfrm");
8685
- const off = el(doc, A_NS, "a:off");
8686
- off.setAttribute("x", "0");
8687
- off.setAttribute("y", "0");
8688
- const ext = el(doc, A_NS, "a:ext");
8689
- ext.setAttribute("cx", emu(image.widthPx));
8690
- ext.setAttribute("cy", emu(image.heightPx));
8691
- const geometry2 = el(doc, A_NS, "a:prstGeom");
8692
- geometry2.setAttribute("prst", "rect");
8693
- add(geometry2, el(doc, A_NS, "a:avLst"));
8694
- const fillColor = el(doc, A_NS, "a:srgbClr");
8695
- fillColor.setAttribute("val", "FFFFFF");
8696
- const spPr = add(
8697
- el(doc, WPS_NS, "wps:spPr"),
8698
- add(xfrm, off, ext),
8699
- geometry2,
8700
- add(el(doc, A_NS, "a:solidFill"), fillColor),
8701
- outline(doc, image.textBoxBorder !== false)
8702
- );
8703
- const content = add(
8704
- el(doc, W_NS, "w:txbxContent"),
8705
- ...paragraphsFor(doc, image.textBoxText ?? [])
8706
- );
8707
- const body = el(doc, WPS_NS, "wps:bodyPr");
8708
- for (const [name, value] of [
8709
- ["rot", "0"],
8710
- ["vert", "horz"],
8711
- ["wrap", "square"],
8712
- ["lIns", "91440"],
8713
- ["tIns", "45720"],
8714
- ["rIns", "91440"],
8715
- ["bIns", "45720"],
8716
- ["anchor", "t"],
8717
- ["anchorCtr", "0"]
8718
- ])
8719
- body.setAttribute(name, value);
8720
- add(body, el(doc, A_NS, "a:noAutofit"));
8721
- add(wsp, cNvSpPr, spPr, add(el(doc, WPS_NS, "wps:txbx"), content), body);
8722
- const graphicData = el(doc, A_NS, "a:graphicData");
8723
- graphicData.setAttribute("uri", SHAPE_GRAPHIC_URI);
8724
- add(
8725
- inline,
8726
- extent,
8727
- effect,
8728
- docPr,
8729
- el(doc, WP_NS, "wp:cNvGraphicFramePr"),
8730
- add(el(doc, A_NS, "a:graphic"), add(graphicData, wsp))
8731
- );
8732
- return add(drawing, inline);
8733
- }
8734
- function isSimpleTextBox(graphicData, anchored) {
8735
- if (!graphicData || anchored) return false;
8736
- const content = descendants(graphicData, W_NS, "txbxContent")[0];
8737
- if (!content) return false;
8738
- const plain = (node, allowed) => Array.from(node.childNodes).filter(isElement).every((child8) => child8.namespaceURI === W_NS && allowed.includes(child8.localName));
8739
- return plain(content, ["p"]) && descendants(content, W_NS, "p").every(
8740
- (paragraph2) => plain(paragraph2, ["r"]) && descendants(paragraph2, W_NS, "r").every((run2) => plain(run2, ["t"]))
8741
- );
8742
- }
8743
- function textBoxHasBorder(graphicData) {
8744
- const spPr = graphicData && descendants(graphicData, WPS_NS, "spPr")[0];
8745
- const ln = spPr && Array.from(spPr.getElementsByTagNameNS(A_NS, "ln"))[0];
8746
- return Boolean(ln && !ln.getElementsByTagNameNS(A_NS, "noFill").length);
8747
- }
8748
- function patchTextBox(doc, drawing, image, base) {
8749
- if (image.widthPx !== base.widthPx || image.heightPx !== base.heightPx)
8750
- for (const node of [
8751
- ...descendants(drawing, WP_NS, "extent"),
8752
- ...descendants(drawing, A_NS, "ext").filter(
8753
- (ext) => ext.parentNode?.localName === "xfrm"
8754
- )
8755
- ]) {
8756
- node.setAttribute("cx", emu(image.widthPx));
8757
- node.setAttribute("cy", emu(image.heightPx));
8758
- }
8759
- if (JSON.stringify(image.textBoxText) !== JSON.stringify(base.textBoxText)) {
8760
- const content = descendants(drawing, W_NS, "txbxContent")[0];
8761
- if (content) {
8762
- for (const child8 of Array.from(content.childNodes)) content.removeChild(child8);
8763
- add(content, ...paragraphsFor(doc, image.textBoxText ?? []));
8764
- }
8765
- }
8766
- if (image.textBoxBorder !== false !== (base.textBoxBorder !== false)) {
8767
- const spPr = descendants(drawing, WPS_NS, "spPr")[0];
8768
- if (spPr) {
8769
- for (const old of Array.from(spPr.childNodes).filter(
8770
- (node) => isElement(node) && node.localName === "ln"
8771
- ))
8772
- spPr.removeChild(old);
8773
- spPr.appendChild(outline(doc, image.textBoxBorder !== false));
8774
- }
8775
- }
8776
- }
8777
-
8778
- // drawingml/dom.ts
8779
- function attributeReader(element4) {
8780
- return (name) => {
8781
- if (!element4) return void 0;
8782
- const direct = element4.getAttribute(name);
8783
- if (direct !== null) return direct;
8784
- const attributes2 = element4.attributes;
8785
- for (let index = 0; index < attributes2.length; index++) {
8786
- const candidate = attributes2.item(index);
8787
- if (candidate && candidate.localName === name) return candidate.value;
8788
- }
8789
- return void 0;
8790
- };
8791
- }
8792
- function stringAttribute(element4, name) {
8793
- const value = attributeReader(element4)(name)?.trim();
8794
- return value ? value : void 0;
8795
- }
8796
- function integerAttribute(element4, name) {
8797
- const parsed = Number.parseInt(attributeReader(element4)(name) ?? "", 10);
8798
- return Number.isFinite(parsed) ? parsed : void 0;
8799
- }
8800
- function booleanAttribute(element4, name) {
8801
- const value = attributeReader(element4)(name)?.trim().toLowerCase();
8802
- if (value === "1" || value === "true") return true;
8803
- if (value === "0" || value === "false") return false;
8804
- return void 0;
8805
- }
8806
- function descendants2(root, local) {
8807
- const result = [];
8808
- const visit = (node) => {
8809
- for (const child8 of Array.from(node.childNodes)) {
8810
- if (!isElement(child8)) continue;
8811
- if (child8.localName === local) result.push(child8);
8812
- visit(child8);
8813
- }
8814
- };
8815
- visit(root);
8816
- return result;
8538
+ // drawingml/picture-artistic.ts
8539
+ var ARTISTIC_PRIMARY_ATTRIBUTE = {
8540
+ artisticBlur: "radius",
8541
+ artisticCement: "crackSpacing",
8542
+ artisticChalkSketch: "pressure",
8543
+ artisticCrisscrossEtching: "pressure",
8544
+ artisticCutout: "numberOfShades",
8545
+ artisticFilmGrain: "grainSize",
8546
+ artisticGlass: "scaling",
8547
+ artisticGlowDiffused: "intensity",
8548
+ artisticGlowEdges: "smoothness",
8549
+ artisticLightScreen: "gridSize",
8550
+ artisticLineDrawing: "pencilSize",
8551
+ artisticMarker: "size",
8552
+ // Spelled "Mosiaic" in the schema; Microsoft's typo is part of the format.
8553
+ artisticMosiaicBubbles: "pressure",
8554
+ artisticPaintBrush: "brushSize",
8555
+ artisticPaintStrokes: "intensity",
8556
+ artisticPastelsSmooth: "scaling",
8557
+ artisticPencilGrayscale: "pencilSize",
8558
+ artisticPencilSketch: "pressure",
8559
+ artisticPhotocopy: "detail",
8560
+ artisticPlasticWrap: "smoothness",
8561
+ artisticTexturizer: "scaling",
8562
+ artisticWatercolorSponge: "brushSize"
8563
+ };
8564
+ function parseArtisticPictureExtension(node) {
8565
+ if (node.namespaceURI !== NS.a || node.localName !== "extLst") return void 0;
8566
+ const found = [];
8567
+ const unhandled = [];
8568
+ const pending = [node];
8569
+ while (pending.length) {
8570
+ const item2 = pending.pop();
8571
+ if (item2 !== node && !(item2.namespaceURI === NS.a && item2.localName === "ext") && !(item2.namespaceURI === "http://schemas.microsoft.com/office/drawing/2010/main" && (["imgProps", "imgLayer", "imgEffect", "useLocalDpi"].includes(item2.localName) || ARTISTIC_PRIMARY_ATTRIBUTE[item2.localName])))
8572
+ unhandled.push(item2.localName);
8573
+ if (item2.namespaceURI === "http://schemas.microsoft.com/office/drawing/2010/main" && item2.localName.startsWith("artistic"))
8574
+ found.push(item2);
8575
+ pending.push(...elements(item2));
8576
+ }
8577
+ if (found.length !== 1) return void 0;
8578
+ const effect = found[0];
8579
+ const key = ARTISTIC_PRIMARY_ATTRIBUTE[effect.localName];
8580
+ if (!key) return void 0;
8581
+ const raw2 = key ? effect.getAttribute(key) : null;
8582
+ const n = raw2 === null ? 0 : Number(raw2);
8583
+ if (!Number.isFinite(n)) return void 0;
8584
+ return {
8585
+ kind: "artistic",
8586
+ name: effect.localName,
8587
+ radius: effect.localName === "artisticBlur" ? n : n / 1e3,
8588
+ baked: true,
8589
+ ...unhandled.length ? { unhandled } : {}
8590
+ };
8817
8591
  }
8818
8592
 
8819
8593
  // drawingml/ordered-color-transforms.ts
@@ -9039,58 +8813,237 @@ function resolveDrawingColor(color, theme, options) {
9039
8813
  };
9040
8814
  }
9041
8815
 
9042
- // drawingml/picture-crop.ts
9043
- var SIDES5 = { l: "cropLeft", t: "cropTop", r: "cropRight", b: "cropBottom" };
9044
- function parsePictureCrop(blipFill) {
9045
- const rect2 = first(blipFill, "srcRect", NS.a);
9046
- if (!rect2) return void 0;
9047
- const result = {};
9048
- for (const [attr3, key] of Object.entries(SIDES5)) {
9049
- const raw2 = rect2.getAttribute(attr3);
9050
- if (raw2 === null || !raw2.trim()) continue;
9051
- const percent = raw2.endsWith("%");
9052
- const value = Number(percent ? raw2.slice(0, -1) : raw2) / (percent ? 100 : 1e5);
9053
- if (Number.isFinite(value)) result[key] = value;
8816
+ // drawingml/write-color.ts
8817
+ var ELEMENTS = {
8818
+ srgb: "srgbClr",
8819
+ scheme: "schemeClr",
8820
+ system: "sysClr",
8821
+ preset: "prstClr",
8822
+ scrgb: "scrgbClr",
8823
+ hsl: "hslClr"
8824
+ };
8825
+ function drawingColorXml(color) {
8826
+ const local = ELEMENTS[color.kind];
8827
+ const doc = parseXml(`<a:${local} xmlns:a="${NS.a}"/>`);
8828
+ const root = doc.documentElement;
8829
+ if (color.kind === "scrgb" || color.kind === "hsl") {
8830
+ const keys = color.kind === "scrgb" ? ["r", "g", "b"] : ["hue", "sat", "lum"];
8831
+ const values = color.value.split(",");
8832
+ keys.forEach((key, i2) => root.setAttribute(key, values[i2] ?? "0"));
8833
+ } else root.setAttribute("val", color.value);
8834
+ if (color.fallback !== void 0 && color.kind === "system")
8835
+ root.setAttribute("lastClr", color.fallback);
8836
+ for (const transform7 of color.transforms) {
8837
+ if (!/^[A-Za-z_][\w.-]*$/.test(transform7.name))
8838
+ throw new Error(`Invalid DrawingML transform ${transform7.name}`);
8839
+ const node = doc.createElementNS(NS.a, `a:${transform7.name}`);
8840
+ if (transform7.value !== "") node.setAttribute("val", transform7.value);
8841
+ root.appendChild(node);
9054
8842
  }
9055
- return result;
8843
+ return buildXml(doc);
9056
8844
  }
9057
- function applyPictureCrop(blipFill, crop) {
9058
- let rect2 = first(blipFill, "srcRect", NS.a);
9059
- if (!rect2 && crop && Object.values(crop).some((value) => value !== void 0)) {
9060
- rect2 = blipFill.ownerDocument.createElementNS(NS.a, "a:srcRect");
9061
- const blip = first(blipFill, "blip", NS.a);
9062
- blipFill.insertBefore(rect2, blip?.nextSibling ?? blipFill.firstChild);
8845
+
8846
+ // drawingml/patch-color.ts
8847
+ function patchDrawingColorIn(container2, color) {
8848
+ const old = elements(container2).find((node) => parseDrawingColor(node));
8849
+ const before = parseDrawingColorIn(container2);
8850
+ if (!old || !before || before.kind !== color.kind) {
8851
+ const next = container2.ownerDocument.importNode(
8852
+ parseXml(drawingColorXml(color)).documentElement,
8853
+ true
8854
+ );
8855
+ if (old) container2.replaceChild(next, old);
8856
+ else container2.insertBefore(next, container2.firstChild);
8857
+ return;
9063
8858
  }
9064
- if (!rect2) return;
9065
- for (const [attr3, key] of Object.entries(SIDES5)) {
9066
- const value = crop?.[key];
9067
- if (value === void 0) rect2.removeAttribute(attr3);
9068
- else {
9069
- if (!Number.isFinite(value)) throw new RangeError("Picture crop must be finite");
9070
- rect2.setAttribute(attr3, String(Math.round(value * 1e5)));
9071
- }
8859
+ if (before.value !== color.value) {
8860
+ if (color.kind === "scrgb" || color.kind === "hsl") {
8861
+ const keys = color.kind === "scrgb" ? ["r", "g", "b"] : ["hue", "sat", "lum"];
8862
+ const values = color.value.split(",");
8863
+ keys.forEach((key, index) => old.setAttribute(key, values[index] ?? "0"));
8864
+ } else old.setAttribute("val", color.value);
8865
+ }
8866
+ if (before.fallback !== color.fallback && color.kind === "system") {
8867
+ if (color.fallback === void 0) old.removeAttribute("lastClr");
8868
+ else old.setAttribute("lastClr", color.fallback);
9072
8869
  }
8870
+ const originals = elements(old);
8871
+ color.transforms.forEach((transform7, index) => {
8872
+ const source2 = originals[index];
8873
+ if (source2?.localName === transform7.name) {
8874
+ if (before.transforms[index]?.value !== transform7.value) {
8875
+ if (transform7.value === "") source2.removeAttribute("val");
8876
+ else source2.setAttribute("val", transform7.value);
8877
+ }
8878
+ return;
8879
+ }
8880
+ if (!/^[A-Za-z_][\w.-]*$/u.test(transform7.name))
8881
+ throw new Error("Invalid DrawingML colour transform");
8882
+ const next = old.ownerDocument.createElementNS(NS.a, `a:${transform7.name}`);
8883
+ if (transform7.value !== "") next.setAttribute("val", transform7.value);
8884
+ if (source2) old.replaceChild(next, source2);
8885
+ else old.appendChild(next);
8886
+ });
8887
+ for (const extra of originals.slice(color.transforms.length)) old.removeChild(extra);
9073
8888
  }
9074
8889
 
9075
- // drawingml/picture-effects.ts
9076
- function picturePercentage(value) {
9077
- const text = String(value ?? "").trim();
9078
- if (!text) return void 0;
9079
- const percent = text.endsWith("%");
9080
- const n = Number(percent ? text.slice(0, -1) : text) / (percent ? 100 : 1e5);
9081
- return Number.isFinite(n) ? n : void 0;
9082
- }
9083
- function readPictureEffect(name, attribute2) {
9084
- if (name === "grayscl") return { kind: "grayscale" };
9085
- if (name === "lum") {
9086
- const brightness = picturePercentage(attribute2("bright"));
9087
- const contrast = picturePercentage(attribute2("contrast"));
9088
- for (const [name2, value] of [
9089
- ["bright", brightness],
9090
- ["contrast", contrast]
9091
- ]) {
9092
- const raw2 = attribute2(name2);
9093
- if (raw2 !== void 0 && raw2 !== null && (value === void 0 || Math.abs(value) > 1))
8890
+ // drawingml/picture-standard-effects.ts
8891
+ var attrs = {
8892
+ biLevel: { threshold: "thresh" },
8893
+ alphaRepl: { amount: "a" },
8894
+ alphaBiLevel: { threshold: "thresh" },
8895
+ hsl: { hue: "hue", saturation: "sat", luminance: "lum" },
8896
+ tint: { hue: "hue", amount: "amt" },
8897
+ blur: { radiusEmu: "rad" }
8898
+ };
8899
+ function parseStandardPictureEffect(node) {
8900
+ const name = node.localName;
8901
+ if (![
8902
+ "biLevel",
8903
+ "alphaInv",
8904
+ "alphaCeiling",
8905
+ "alphaFloor",
8906
+ "alphaRepl",
8907
+ "alphaBiLevel",
8908
+ "alphaMod",
8909
+ "duotone",
8910
+ "clrRepl",
8911
+ "clrChange",
8912
+ "hsl",
8913
+ "tint",
8914
+ "blur"
8915
+ ].includes(name))
8916
+ return void 0;
8917
+ const values = {};
8918
+ for (const [key, attribute2] of Object.entries(attrs[name] ?? {})) {
8919
+ const raw2 = node.getAttribute(attribute2);
8920
+ if (raw2 === null) continue;
8921
+ const percent = raw2.endsWith("%");
8922
+ const n = Number(percent ? raw2.slice(0, -1) : raw2) / (key === "hue" ? 6e4 : key === "radiusEmu" ? 1 : percent ? 100 : 1e5);
8923
+ if (!Number.isFinite(n) || key === "hue" && (n < 0 || n >= 360) || key === "threshold" && (n < 0 || n > 1) || key === "radiusEmu" && (!Number.isSafeInteger(n) || n < 0) || ["saturation", "luminance", "amount"].includes(key) && name !== "alphaMod" && (n < (name === "alphaRepl" ? 0 : -1) || n > 1))
8924
+ return void 0;
8925
+ values[key] = n;
8926
+ }
8927
+ if (["biLevel", "alphaBiLevel"].includes(name) && values.threshold === void 0)
8928
+ return void 0;
8929
+ if (name === "alphaRepl" && values.amount === void 0) return void 0;
8930
+ if (name === "alphaMod") {
8931
+ const cont = first(node, "cont", NS.a);
8932
+ const nested = cont ? elements(cont) : [];
8933
+ if (nested.length !== 1 || nested[0]?.localName !== "alphaModFix") return void 0;
8934
+ const raw2 = nested[0].getAttribute("amt") ?? "100000";
8935
+ const n = Number(raw2.endsWith("%") ? raw2.slice(0, -1) : raw2) / (raw2.endsWith("%") ? 100 : 1e5);
8936
+ if (!Number.isFinite(n) || n < 0) return void 0;
8937
+ values.amount = n;
8938
+ }
8939
+ let colors = [];
8940
+ if (name === "duotone") {
8941
+ const candidates = elements(node).filter(
8942
+ (item2) => item2.namespaceURI === NS.a && /Clr$/.test(item2.localName)
8943
+ );
8944
+ colors = candidates.map((item2) => parseDrawingColor(item2)).filter((item2) => Boolean(item2));
8945
+ if (colors.length !== 2) return void 0;
8946
+ }
8947
+ if (name === "clrRepl") {
8948
+ const color = parseDrawingColorIn(node);
8949
+ if (!color) return void 0;
8950
+ colors = [color];
8951
+ }
8952
+ if (name === "clrChange") {
8953
+ const from = parseDrawingColorIn(first(node, "clrFrom", NS.a)), to = parseDrawingColorIn(first(node, "clrTo", NS.a));
8954
+ if (!from || !to) return void 0;
8955
+ colors = [from, to];
8956
+ }
8957
+ if (name === "alphaInv") {
8958
+ const color = parseDrawingColorIn(node);
8959
+ if (color) colors = [color];
8960
+ }
8961
+ return {
8962
+ kind: "standard",
8963
+ name,
8964
+ ...Object.keys(values).length ? { values } : {},
8965
+ ...colors.length ? { colors } : {},
8966
+ ...name === "clrChange" && node.hasAttribute("useA") ? { useAlpha: !["0", "false"].includes(node.getAttribute("useA") ?? "") } : {},
8967
+ ...name === "blur" && node.hasAttribute("grow") ? { grow: !["0", "false"].includes(node.getAttribute("grow") ?? "") } : {}
8968
+ };
8969
+ }
8970
+ function applyStandardPictureEffect(node, effect) {
8971
+ const doc = node.ownerDocument, before = parseStandardPictureEffect(node);
8972
+ for (const [key, value] of Object.entries(effect.values ?? {})) {
8973
+ if (!Number.isFinite(value) || key === "hue" && (value < 0 || value >= 360) || key === "threshold" && (value < 0 || value > 1) || key === "radiusEmu" && (!Number.isSafeInteger(value) || value < 0) || key === "amount" && effect.name === "alphaMod" && value < 0 || ["saturation", "luminance", "amount"].includes(key) && effect.name !== "alphaMod" && (value < (effect.name === "alphaRepl" ? 0 : -1) || value > 1))
8974
+ throw new RangeError("Invalid picture effect values");
8975
+ }
8976
+ const count = effect.colors?.length ?? 0;
8977
+ if (["duotone", "clrChange"].includes(effect.name) && count !== 2 || effect.name === "clrRepl" && count !== 1 || effect.name === "alphaInv" && count > 1)
8978
+ throw new RangeError("Invalid picture effect colours");
8979
+ for (const [key, attribute2] of Object.entries(attrs[effect.name] ?? {})) {
8980
+ const value = effect.values?.[key];
8981
+ if (value === before?.values?.[key]) continue;
8982
+ if (value === void 0) node.removeAttribute(attribute2);
8983
+ else
8984
+ node.setAttribute(
8985
+ attribute2,
8986
+ String(Math.round(value * (key === "hue" ? 6e4 : key === "radiusEmu" ? 1 : 1e5)))
8987
+ );
8988
+ }
8989
+ if (effect.name === "alphaMod" && effect.values?.amount !== before?.values?.amount) {
8990
+ const cont = first(node, "cont", NS.a) ?? doc.createElementNS(NS.a, "a:cont");
8991
+ const fix = first(cont, "alphaModFix", NS.a) ?? doc.createElementNS(NS.a, "a:alphaModFix");
8992
+ fix.setAttribute("amt", String(Math.round((effect.values?.amount ?? 1) * 1e5)));
8993
+ if (!fix.parentNode) cont.appendChild(fix);
8994
+ if (!cont.parentNode) node.appendChild(cont);
8995
+ }
8996
+ if (effect.useAlpha !== before?.useAlpha) {
8997
+ if (effect.useAlpha === void 0) node.removeAttribute("useA");
8998
+ else node.setAttribute("useA", effect.useAlpha ? "1" : "0");
8999
+ }
9000
+ if (effect.grow !== before?.grow) {
9001
+ if (effect.grow === void 0) node.removeAttribute("grow");
9002
+ else node.setAttribute("grow", effect.grow ? "1" : "0");
9003
+ }
9004
+ if (JSON.stringify(effect.colors) !== JSON.stringify(before?.colors)) {
9005
+ if (effect.name === "duotone") {
9006
+ const old = elements(node).filter(
9007
+ (item2) => item2.namespaceURI === NS.a && /Clr$/.test(item2.localName)
9008
+ );
9009
+ for (let i2 = 0; i2 < (effect.colors?.length ?? 0); i2++) {
9010
+ const holder = doc.createElementNS(NS.a, "a:holder");
9011
+ if (old[i2]) holder.appendChild(doc.importNode(old[i2], true));
9012
+ patchDrawingColorIn(holder, effect.colors[i2]);
9013
+ const next = elements(holder)[0];
9014
+ if (old[i2]) node.replaceChild(next, old[i2]);
9015
+ else node.insertBefore(next, first(node, "extLst", NS.a) ?? null);
9016
+ }
9017
+ } else if (effect.name === "clrChange") {
9018
+ for (const [i2, name] of ["clrFrom", "clrTo"].entries()) {
9019
+ const holder = first(node, name, NS.a) ?? doc.createElementNS(NS.a, `a:${name}`);
9020
+ if (effect.colors?.[i2]) patchDrawingColorIn(holder, effect.colors[i2]);
9021
+ if (!holder.parentNode) node.insertBefore(holder, first(node, "extLst", NS.a) ?? null);
9022
+ }
9023
+ } else if (effect.colors?.[0]) patchDrawingColorIn(node, effect.colors[0]);
9024
+ }
9025
+ if (!parseStandardPictureEffect(node)) throw new RangeError("Invalid picture effect values");
9026
+ }
9027
+
9028
+ // drawingml/picture-effects.ts
9029
+ function picturePercentage(value) {
9030
+ const text = String(value ?? "").trim();
9031
+ if (!text) return void 0;
9032
+ const percent = text.endsWith("%");
9033
+ const n = Number(percent ? text.slice(0, -1) : text) / (percent ? 100 : 1e5);
9034
+ return Number.isFinite(n) ? n : void 0;
9035
+ }
9036
+ function readPictureEffect(name, attribute2) {
9037
+ if (name === "grayscl") return { kind: "grayscale" };
9038
+ if (name === "lum") {
9039
+ const brightness = picturePercentage(attribute2("bright"));
9040
+ const contrast = picturePercentage(attribute2("contrast"));
9041
+ for (const [name2, value] of [
9042
+ ["bright", brightness],
9043
+ ["contrast", contrast]
9044
+ ]) {
9045
+ const raw2 = attribute2(name2);
9046
+ if (raw2 !== void 0 && raw2 !== null && (value === void 0 || Math.abs(value) > 1))
9094
9047
  return void 0;
9095
9048
  }
9096
9049
  return {
@@ -9104,74 +9057,525 @@ function readPictureEffect(name, attribute2) {
9104
9057
  const amount = raw2 === void 0 || raw2 === null ? 1 : picturePercentage(raw2);
9105
9058
  if (amount !== void 0 && amount >= 0) return { kind: "alphaModFix", amount };
9106
9059
  }
9107
- return void 0;
9108
- }
9109
- function parsePictureEffects(blip) {
9110
- if (!blip) return [];
9111
- return elements(blip).map((node) => ({
9112
- ...(node.namespaceURI === NS.a ? readPictureEffect(node.localName, (name) => node.getAttribute(name)) : void 0) ?? { kind: "unsupported", name: node.localName },
9113
- sourceXml: buildXml(node)
9114
- }));
9115
- }
9116
- function applyPictureEffects(blip, effects) {
9117
- if (JSON.stringify(parsePictureEffects(blip)) === JSON.stringify(effects)) return;
9118
- const nodes = effects.map((effect) => {
9119
- const name = effect.kind === "grayscale" ? "grayscl" : effect.kind === "luminance" ? "lum" : effect.kind === "unsupported" ? effect.name : effect.kind;
9120
- const source2 = effect.sourceXml ? parseXml(effect.sourceXml).documentElement : void 0;
9121
- if (effect.kind === "unsupported" && !source2)
9122
- throw new Error("An unsupported picture effect needs source XML");
9123
- const node = source2 ? blip.ownerDocument.importNode(source2, true) : blip.ownerDocument.createElementNS(NS.a, `a:${name}`);
9124
- if (effect.kind !== "unsupported" && (node.namespaceURI !== NS.a || node.localName !== name))
9125
- throw new Error("Picture effect source does not match its kind");
9126
- const set2 = (name2, value) => {
9127
- const original = picturePercentage(node.getAttribute(name2));
9128
- if (value === void 0) node.removeAttribute(name2);
9129
- else if (value !== original) {
9130
- if (!Number.isFinite(value)) throw new RangeError("Picture effect must be finite");
9131
- node.setAttribute(name2, String(Math.round(value * 1e5)));
9132
- }
9133
- };
9134
- if (effect.kind === "luminance") {
9135
- if ([effect.brightness, effect.contrast].some(
9136
- (value) => value !== void 0 && (!Number.isFinite(value) || Math.abs(value) > 1)
9060
+ return void 0;
9061
+ }
9062
+ function parsePictureEffects(blip) {
9063
+ if (!blip) return [];
9064
+ return elements(blip).map((node) => ({
9065
+ ...(node.namespaceURI === NS.a ? readPictureEffect(node.localName, (name) => node.getAttribute(name)) ?? parseStandardPictureEffect(node) ?? parseArtisticPictureExtension(node) : void 0) ?? { kind: "unsupported", name: node.localName },
9066
+ sourceXml: buildXml(node)
9067
+ }));
9068
+ }
9069
+ function applyPictureEffects(blip, effects) {
9070
+ if (JSON.stringify(parsePictureEffects(blip)) === JSON.stringify(effects)) return;
9071
+ const nodes = effects.map((effect) => {
9072
+ const name = effect.kind === "grayscale" ? "grayscl" : effect.kind === "luminance" ? "lum" : effect.kind === "unsupported" ? effect.name : effect.kind === "artistic" ? "extLst" : effect.kind === "standard" ? effect.name : effect.kind;
9073
+ if (effect.kind === "artistic") {
9074
+ const before = effect.sourceXml ? parseArtisticPictureExtension(parseXml(effect.sourceXml).documentElement) : void 0;
9075
+ if (!effect.baked || !before || before.name !== effect.name || before.radius !== effect.radius)
9076
+ throw new Error("Artistic authoring requires a host-generated baked picture cache");
9077
+ }
9078
+ const source2 = effect.sourceXml ? parseXml(effect.sourceXml).documentElement : void 0;
9079
+ if (effect.kind === "unsupported" && !source2)
9080
+ throw new Error("An unsupported picture effect needs source XML");
9081
+ const node = source2 ? blip.ownerDocument.importNode(source2, true) : blip.ownerDocument.createElementNS(NS.a, `a:${name}`);
9082
+ if (effect.kind !== "unsupported" && (node.namespaceURI !== NS.a || node.localName !== name))
9083
+ throw new Error("Picture effect source does not match its kind");
9084
+ const set2 = (name2, value) => {
9085
+ const original = picturePercentage(node.getAttribute(name2));
9086
+ if (value === void 0) node.removeAttribute(name2);
9087
+ else if (value !== original) {
9088
+ if (!Number.isFinite(value)) throw new RangeError("Picture effect must be finite");
9089
+ node.setAttribute(name2, String(Math.round(value * 1e5)));
9090
+ }
9091
+ };
9092
+ if (effect.kind === "luminance") {
9093
+ if ([effect.brightness, effect.contrast].some(
9094
+ (value) => value !== void 0 && (!Number.isFinite(value) || Math.abs(value) > 1)
9095
+ ))
9096
+ throw new RangeError("Picture luminance must be between -1 and 1");
9097
+ set2("bright", effect.brightness);
9098
+ set2("contrast", effect.contrast);
9099
+ }
9100
+ if (effect.kind === "alphaModFix") {
9101
+ if (effect.amount < 0) throw new RangeError("Picture alpha must be nonnegative");
9102
+ set2("amt", effect.amount);
9103
+ }
9104
+ if (effect.kind === "standard") applyStandardPictureEffect(node, effect);
9105
+ return node;
9106
+ });
9107
+ for (const node of elements(blip)) blip.removeChild(node);
9108
+ for (const node of nodes) blip.appendChild(node);
9109
+ }
9110
+
9111
+ // drawingml/picture-layout.ts
9112
+ function parsePictureLayout(fill) {
9113
+ const out = {};
9114
+ const rot = fill.getAttribute("rotWithShape");
9115
+ if (rot !== null) out.rotWithShape = rot !== "0" && rot !== "false";
9116
+ const dpi = Number(fill.getAttribute("dpi"));
9117
+ if (fill.hasAttribute("dpi") && Number.isFinite(dpi) && dpi > 0) out.dpi = dpi;
9118
+ const tile = first(fill, "tile", NS.a);
9119
+ if (tile) {
9120
+ const value = {};
9121
+ for (const [key, attr3] of [
9122
+ ["scaleX", "sx"],
9123
+ ["scaleY", "sy"]
9124
+ ]) {
9125
+ const n = picturePercentage(tile.getAttribute(attr3));
9126
+ if (n !== void 0) value[key] = n;
9127
+ }
9128
+ for (const [key, attr3] of [
9129
+ ["offsetXEmu", "tx"],
9130
+ ["offsetYEmu", "ty"]
9131
+ ]) {
9132
+ const raw2 = tile.getAttribute(attr3);
9133
+ const n = raw2 === null ? NaN : Number(raw2);
9134
+ if (Number.isSafeInteger(n)) value[key] = n;
9135
+ }
9136
+ const alignment = tile.getAttribute("algn");
9137
+ if (alignment) value.alignment = alignment;
9138
+ const flip = tile.getAttribute("flip");
9139
+ if (flip && ["none", "x", "y", "xy"].includes(flip))
9140
+ value.flip = flip;
9141
+ out.tile = value;
9142
+ }
9143
+ const rect2 = first(first(fill, "stretch", NS.a), "fillRect", NS.a);
9144
+ if (rect2)
9145
+ out.fillRect = {
9146
+ l: picturePercentage(rect2.getAttribute("l")) ?? 0,
9147
+ t: picturePercentage(rect2.getAttribute("t")) ?? 0,
9148
+ r: picturePercentage(rect2.getAttribute("r")) ?? 0,
9149
+ b: picturePercentage(rect2.getAttribute("b")) ?? 0
9150
+ };
9151
+ return out;
9152
+ }
9153
+ function applyPictureLayout(fill, layout2) {
9154
+ const before = parsePictureLayout(fill);
9155
+ const attr3 = (node, name, value, old) => {
9156
+ if (value === old) return;
9157
+ if (value === void 0) node.removeAttribute(name);
9158
+ else node.setAttribute(name, String(value));
9159
+ };
9160
+ if (layout2.rotWithShape !== before.rotWithShape)
9161
+ attr3(
9162
+ fill,
9163
+ "rotWithShape",
9164
+ layout2.rotWithShape === void 0 ? void 0 : layout2.rotWithShape ? "1" : "0",
9165
+ void 0
9166
+ );
9167
+ if (layout2.dpi !== before.dpi) {
9168
+ if (layout2.dpi !== void 0 && (!Number.isSafeInteger(layout2.dpi) || layout2.dpi <= 0))
9169
+ throw new RangeError("Invalid picture DPI");
9170
+ attr3(fill, "dpi", layout2.dpi, void 0);
9171
+ }
9172
+ const make = (parent, name) => {
9173
+ const old = first(parent, name, NS.a);
9174
+ if (old) return old;
9175
+ const node = fill.ownerDocument.createElementNS(NS.a, `a:${name}`);
9176
+ parent.insertBefore(node, first(parent, "extLst", NS.a) ?? null);
9177
+ return node;
9178
+ };
9179
+ if (layout2.tile) {
9180
+ const stretch = first(fill, "stretch", NS.a);
9181
+ if (stretch) fill.removeChild(stretch);
9182
+ const tile = make(fill, "tile");
9183
+ for (const [key, name] of [
9184
+ ["scaleX", "sx"],
9185
+ ["scaleY", "sy"],
9186
+ ["offsetXEmu", "tx"],
9187
+ ["offsetYEmu", "ty"]
9188
+ ]) {
9189
+ const n = layout2.tile[key];
9190
+ if (n !== void 0 && (!Number.isFinite(n) || (name === "sx" || name === "sy" ? n <= 0 : !Number.isSafeInteger(n))))
9191
+ throw new RangeError("Invalid picture tile");
9192
+ if (n !== before.tile?.[key])
9193
+ attr3(
9194
+ tile,
9195
+ name,
9196
+ n === void 0 ? void 0 : Math.round(n * (name === "sx" || name === "sy" ? 1e5 : 1)),
9197
+ void 0
9198
+ );
9199
+ }
9200
+ if (layout2.tile.alignment !== before.tile?.alignment) {
9201
+ if (layout2.tile.alignment && !["tl", "t", "tr", "l", "ctr", "r", "bl", "b", "br"].includes(layout2.tile.alignment))
9202
+ throw new RangeError("Invalid picture tile alignment");
9203
+ attr3(tile, "algn", layout2.tile.alignment, void 0);
9204
+ }
9205
+ if (layout2.tile.flip !== void 0 && !["none", "x", "y", "xy"].includes(layout2.tile.flip))
9206
+ throw new RangeError("Invalid picture tile flip");
9207
+ if (layout2.tile.flip !== before.tile?.flip) attr3(tile, "flip", layout2.tile.flip, void 0);
9208
+ } else if (before.tile || layout2.fillRect) {
9209
+ const tile = first(fill, "tile", NS.a);
9210
+ if (tile) fill.removeChild(tile);
9211
+ const rect2 = make(make(fill, "stretch"), "fillRect");
9212
+ for (const key of ["l", "t", "r", "b"]) {
9213
+ const n = layout2.fillRect?.[key];
9214
+ if (n !== void 0 && !Number.isFinite(n))
9215
+ throw new RangeError("Invalid picture fill rectangle");
9216
+ if (n !== before.fillRect?.[key])
9217
+ attr3(rect2, key, n === void 0 ? void 0 : Math.round(n * 1e5), void 0);
9218
+ }
9219
+ }
9220
+ }
9221
+
9222
+ // drawingml/picture-fill.ts
9223
+ function parseDrawingPictureFill(fill) {
9224
+ const blip = first(fill, "blip", NS.a);
9225
+ const relId = blip?.getAttributeNS(NS.r, "embed") || blip?.getAttribute("r:embed") || void 0;
9226
+ const linkRelId = blip?.getAttributeNS(NS.r, "link") || void 0;
9227
+ const crop = parsePictureCrop(fill);
9228
+ const effects = parsePictureEffects(blip);
9229
+ const layout2 = parsePictureLayout(fill);
9230
+ const unsupported2 = [];
9231
+ const tile = first(fill, "tile", NS.a), stretch = first(fill, "stretch", NS.a);
9232
+ if (tile && stretch) unsupported2.push("tile/stretch-choice");
9233
+ if (tile) {
9234
+ for (const [attr3, key] of [
9235
+ ["sx", "scaleX"],
9236
+ ["sy", "scaleY"],
9237
+ ["tx", "offsetXEmu"],
9238
+ ["ty", "offsetYEmu"]
9239
+ ])
9240
+ if (tile.hasAttribute(attr3) && (layout2.tile?.[key] === void 0 || (attr3 === "sx" || attr3 === "sy") && layout2.tile[key] <= 0))
9241
+ unsupported2.push(`tile:${attr3}`);
9242
+ if (tile.hasAttribute("algn") && !["tl", "t", "tr", "l", "ctr", "r", "bl", "b", "br"].includes(tile.getAttribute("algn") ?? ""))
9243
+ unsupported2.push("tile:algn");
9244
+ if (tile.hasAttribute("flip") && !layout2.tile?.flip) unsupported2.push("tile:flip");
9245
+ }
9246
+ const rect2 = first(stretch, "fillRect", NS.a);
9247
+ if (rect2)
9248
+ for (const key of ["l", "t", "r", "b"]) {
9249
+ const raw2 = rect2.getAttribute(key);
9250
+ if (raw2 !== null && !/^[-+]?(?:\d+\.?\d*|\.\d+)%?$/.test(raw2))
9251
+ unsupported2.push(`fillRect:${key}`);
9252
+ }
9253
+ if (fill.hasAttribute("rotWithShape") && !["0", "1", "true", "false"].includes(fill.getAttribute("rotWithShape") ?? ""))
9254
+ unsupported2.push("rotWithShape");
9255
+ return {
9256
+ kind: "picture",
9257
+ sourceXml: buildXml(fill),
9258
+ ...relId ? { relId } : {},
9259
+ ...linkRelId ? { linkRelId } : {},
9260
+ ...crop ? { crop } : {},
9261
+ ...effects.length ? { effects } : {},
9262
+ ...Object.keys(layout2).length ? { layout: layout2 } : {},
9263
+ ...unsupported2.length ? { unsupportedPicture: unsupported2 } : {}
9264
+ };
9265
+ }
9266
+
9267
+ // drawingml/image-content-type.ts
9268
+ function imageContentType(partName) {
9269
+ const extension = partName.split(".").pop()?.toLowerCase();
9270
+ const known = {
9271
+ png: "image/png",
9272
+ jpg: "image/jpeg",
9273
+ jpeg: "image/jpeg",
9274
+ gif: "image/gif",
9275
+ bmp: "image/bmp",
9276
+ svg: "image/svg+xml",
9277
+ tif: "image/tiff",
9278
+ tiff: "image/tiff",
9279
+ emf: "image/x-emf",
9280
+ wmf: "image/x-wmf"
9281
+ };
9282
+ return extension && known[extension] || "application/octet-stream";
9283
+ }
9284
+
9285
+ // docx/package-parts.ts
9286
+ function resolveInternalTarget(target) {
9287
+ if (target.startsWith("/")) return target.replace(/^\//, "");
9288
+ return `word/${target.replace(/^\.\//, "")}`;
9289
+ }
9290
+
9291
+ // docx/defined-props.ts
9292
+ function definedProps(source2) {
9293
+ return Object.fromEntries(Object.entries(source2).filter(([, value]) => value !== void 0));
9294
+ }
9295
+
9296
+ // docx/watermark.ts
9297
+ var VML_NS = "urn:schemas-microsoft-com:vml";
9298
+ var OFFICE_NS = "urn:schemas-microsoft-com:office:office";
9299
+ var WORD10_NS = "urn:schemas-microsoft-com:office:word";
9300
+ var NAMED = {
9301
+ silver: "#c0c0c0",
9302
+ gray: "#808080",
9303
+ grey: "#808080",
9304
+ black: "#000000",
9305
+ white: "#ffffff",
9306
+ red: "#ff0000",
9307
+ blue: "#0000ff",
9308
+ green: "#008000",
9309
+ yellow: "#ffff00"
9310
+ };
9311
+ var POINT_TO_PX = 96 / 72;
9312
+ var WATERMARK_PREFIX = "PowerPlusWaterMarkObject";
9313
+ var DEFAULT_WATERMARK_COLOR = "#c0c0c0";
9314
+ function colorOf(value) {
9315
+ const text = (value ?? "").trim().toLowerCase().split(/\s/)[0] ?? "";
9316
+ if (NAMED[text]) return NAMED[text];
9317
+ const hex = /^#?([0-9a-f]{6})$/.exec(text);
9318
+ return hex ? `#${hex[1]}` : DEFAULT_WATERMARK_COLOR;
9319
+ }
9320
+ function parseWatermarkShape(shape) {
9321
+ if (!shape || !(shape.getAttribute("id") ?? "").startsWith(WATERMARK_PREFIX)) return void 0;
9322
+ const path3 = Array.from(shape.getElementsByTagNameNS(VML_NS, "textpath"))[0];
9323
+ if (!path3) return void 0;
9324
+ const style = shape.getAttribute("style") ?? "";
9325
+ const fill = Array.from(shape.getElementsByTagNameNS(VML_NS, "fill"))[0];
9326
+ const opacity = fill?.getAttribute("opacity");
9327
+ const family = /font-family:\s*(?:&quot;|"|')?([^;"'&]+)/i.exec(
9328
+ path3.getAttribute("style") ?? ""
9329
+ )?.[1];
9330
+ const width = /width:\s*([\d.]+)pt/i.exec(style);
9331
+ const height = /height:\s*([\d.]+)pt/i.exec(style);
9332
+ const rotation2 = /rotation:\s*(-?[\d.]+)/i.exec(style);
9333
+ const spec = {
9334
+ text: path3.getAttribute("string") ?? "",
9335
+ color: colorOf(shape.getAttribute("fillcolor")),
9336
+ semitransparent: opacity !== null && opacity !== "" && opacity !== "1",
9337
+ layout: rotation2 && Math.abs(Number(rotation2[1]) % 360) > 1 ? "diagonal" : "horizontal",
9338
+ ...family ? { fontFamily: family.trim() } : {}
9339
+ };
9340
+ return {
9341
+ relId: "",
9342
+ partName: "",
9343
+ contentType: "application/octet-stream",
9344
+ widthPx: width ? Math.round(Number(width[1]) * POINT_TO_PX) : 0,
9345
+ heightPx: height ? Math.round(Number(height[1]) * POINT_TO_PX) : 0,
9346
+ unsupported: "Watermark",
9347
+ watermark: spec
9348
+ };
9349
+ }
9350
+ function watermarkSizePt(spec) {
9351
+ const chars = Math.max(1, [...spec.text].length);
9352
+ const width = Math.min(spec.layout === "diagonal" ? 527 : 468, Math.max(150, chars * 44));
9353
+ return { width, height: Math.round(width / (chars * 0.55) * 100) / 100 };
9354
+ }
9355
+ var FORMULAS = [
9356
+ "sum #0 0 10800",
9357
+ "prod #0 2 1",
9358
+ "sum 21600 0 @1",
9359
+ "sum 0 0 @2",
9360
+ "sum 21600 0 @3",
9361
+ "if @0 @3 0",
9362
+ "if @0 21600 @1",
9363
+ "if @0 0 @2",
9364
+ "if @0 @4 21600",
9365
+ "mid @5 @6",
9366
+ "mid @8 @5",
9367
+ "mid @7 @8",
9368
+ "mid @6 @7",
9369
+ "sum @6 0 @5"
9370
+ ];
9371
+ function buildWatermarkRun(doc, spec, uniqueId) {
9372
+ const v = (name) => makeNS(doc, VML_NS, `v:${name}`);
9373
+ const run2 = makeW(doc, "r");
9374
+ const props = makeW(doc, "rPr");
9375
+ props.appendChild(makeW(doc, "noProof"));
9376
+ run2.appendChild(props);
9377
+ const pict = makeW(doc, "pict");
9378
+ const type = v("shapetype");
9379
+ type.setAttribute("id", "_x0000_t136");
9380
+ type.setAttribute("coordsize", "21600,21600");
9381
+ type.setAttributeNS(OFFICE_NS, "o:spt", "136");
9382
+ type.setAttribute("adj", "10800");
9383
+ type.setAttribute("path", "m@7,l@8,m@5,21600l@6,21600e");
9384
+ const formulas = v("formulas");
9385
+ for (const eqn of FORMULAS) {
9386
+ const f6 = v("f");
9387
+ f6.setAttribute("eqn", eqn);
9388
+ formulas.appendChild(f6);
9389
+ }
9390
+ const path3 = v("path");
9391
+ path3.setAttribute("textpathok", "t");
9392
+ path3.setAttributeNS(OFFICE_NS, "o:connecttype", "custom");
9393
+ path3.setAttributeNS(OFFICE_NS, "o:connectlocs", "@9,0;@10,10800;@11,21600;@12,10800");
9394
+ path3.setAttributeNS(OFFICE_NS, "o:connectangles", "270,180,90,0");
9395
+ const typePath = v("textpath");
9396
+ typePath.setAttribute("on", "t");
9397
+ typePath.setAttribute("fitshape", "t");
9398
+ const handles = v("handles");
9399
+ const handle = v("h");
9400
+ handle.setAttribute("position", "#0,bottomRight");
9401
+ handle.setAttribute("xrange", "6629,14971");
9402
+ handles.appendChild(handle);
9403
+ const lock = makeNS(doc, OFFICE_NS, "o:lock");
9404
+ lock.setAttributeNS(VML_NS, "v:ext", "edit");
9405
+ lock.setAttribute("text", "t");
9406
+ lock.setAttribute("shapetype", "t");
9407
+ for (const child8 of [formulas, path3, typePath, handles, lock]) type.appendChild(child8);
9408
+ const size = watermarkSizePt(spec);
9409
+ const shape = v("shape");
9410
+ shape.setAttribute("id", `${WATERMARK_PREFIX}${uniqueId}`);
9411
+ shape.setAttributeNS(OFFICE_NS, "o:spid", `_x0000_s${2048 + (Number(uniqueId) || 1)}`);
9412
+ shape.setAttribute("type", "#_x0000_t136");
9413
+ shape.setAttribute(
9414
+ "style",
9415
+ `position:absolute;margin-left:0;margin-top:0;width:${size.width}pt;height:${size.height}pt;${spec.layout === "diagonal" ? "rotation:315;" : ""}z-index:-251658752;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin`
9416
+ );
9417
+ shape.setAttributeNS(OFFICE_NS, "o:allowincell", "f");
9418
+ shape.setAttribute("fillcolor", spec.color.replace(/^#/, "").toLowerCase());
9419
+ shape.setAttribute("stroked", "f");
9420
+ const fill = v("fill");
9421
+ fill.setAttribute("opacity", spec.semitransparent ? ".5" : "1");
9422
+ const text = v("textpath");
9423
+ text.setAttribute("style", `font-family:"${spec.fontFamily ?? "Calibri"}";font-size:1pt`);
9424
+ text.setAttribute("string", spec.text);
9425
+ const wrap2 = makeNS(doc, WORD10_NS, "w10:wrap");
9426
+ wrap2.setAttribute("anchorx", "margin");
9427
+ wrap2.setAttribute("anchory", "margin");
9428
+ for (const child8 of [fill, text, wrap2]) shape.appendChild(child8);
9429
+ pict.appendChild(type);
9430
+ pict.appendChild(shape);
9431
+ run2.appendChild(pict);
9432
+ return run2;
9433
+ }
9434
+
9435
+ // docx/write-text-box.ts
9436
+ var A_NS = "http://schemas.openxmlformats.org/drawingml/2006/main";
9437
+ var WP_NS = "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing";
9438
+ var WPS_NS = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
9439
+ var W_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
9440
+ var SHAPE_GRAPHIC_URI = WPS_NS;
9441
+ var el = (doc, ns, name) => makeNS(doc, ns, name);
9442
+ var add = (parent, ...items) => {
9443
+ for (const item2 of items) parent.appendChild(item2);
9444
+ return parent;
9445
+ };
9446
+ var emu = (px2) => String(Math.max(1, Math.round(px2 * EMU_PER_PIXEL)));
9447
+ var descendants2 = (root, ns, local) => Array.from(root.getElementsByTagNameNS(ns, local));
9448
+ function paragraphsFor(doc, lines2) {
9449
+ return (lines2.length ? lines2 : [""]).map((line2) => {
9450
+ const paragraph2 = makeW(doc, "p");
9451
+ if (line2) {
9452
+ const run2 = makeW(doc, "r");
9453
+ const text = makeW(doc, "t");
9454
+ if (/^\s|\s$/.test(line2))
9455
+ text.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:space", "preserve");
9456
+ text.textContent = line2;
9457
+ add(run2, text);
9458
+ add(paragraph2, run2);
9459
+ }
9460
+ return paragraph2;
9461
+ });
9462
+ }
9463
+ function outline(doc, border) {
9464
+ const ln = el(doc, A_NS, "a:ln");
9465
+ if (!border) return add(ln, el(doc, A_NS, "a:noFill"));
9466
+ ln.setAttribute("w", "9525");
9467
+ const color = el(doc, A_NS, "a:srgbClr");
9468
+ color.setAttribute("val", "000000");
9469
+ return add(ln, add(el(doc, A_NS, "a:solidFill"), color));
9470
+ }
9471
+ function buildTextBoxDrawing(doc, image, docPrId) {
9472
+ const drawing = makeW(doc, "drawing");
9473
+ const inline = el(doc, WP_NS, "wp:inline");
9474
+ for (const side of ["distT", "distB", "distL", "distR"]) inline.setAttribute(side, "0");
9475
+ const extent = el(doc, WP_NS, "wp:extent");
9476
+ extent.setAttribute("cx", emu(image.widthPx));
9477
+ extent.setAttribute("cy", emu(image.heightPx));
9478
+ const effect = el(doc, WP_NS, "wp:effectExtent");
9479
+ for (const side of ["l", "t", "r", "b"]) effect.setAttribute(side, "0");
9480
+ const docPr = el(doc, WP_NS, "wp:docPr");
9481
+ docPr.setAttribute("id", docPrId);
9482
+ docPr.setAttribute("name", `Text Box ${docPrId}`);
9483
+ if (image.altText) docPr.setAttribute("descr", image.altText);
9484
+ const wsp = el(doc, WPS_NS, "wps:wsp");
9485
+ const cNvSpPr = el(doc, WPS_NS, "wps:cNvSpPr");
9486
+ cNvSpPr.setAttribute("txBox", "1");
9487
+ const xfrm = el(doc, A_NS, "a:xfrm");
9488
+ const off = el(doc, A_NS, "a:off");
9489
+ off.setAttribute("x", "0");
9490
+ off.setAttribute("y", "0");
9491
+ const ext = el(doc, A_NS, "a:ext");
9492
+ ext.setAttribute("cx", emu(image.widthPx));
9493
+ ext.setAttribute("cy", emu(image.heightPx));
9494
+ const geometry2 = el(doc, A_NS, "a:prstGeom");
9495
+ geometry2.setAttribute("prst", "rect");
9496
+ add(geometry2, el(doc, A_NS, "a:avLst"));
9497
+ const fillColor = el(doc, A_NS, "a:srgbClr");
9498
+ fillColor.setAttribute("val", "FFFFFF");
9499
+ const spPr = add(
9500
+ el(doc, WPS_NS, "wps:spPr"),
9501
+ add(xfrm, off, ext),
9502
+ geometry2,
9503
+ add(el(doc, A_NS, "a:solidFill"), fillColor),
9504
+ outline(doc, image.textBoxBorder !== false)
9505
+ );
9506
+ const content = add(
9507
+ el(doc, W_NS, "w:txbxContent"),
9508
+ ...paragraphsFor(doc, image.textBoxText ?? [])
9509
+ );
9510
+ const body = el(doc, WPS_NS, "wps:bodyPr");
9511
+ for (const [name, value] of [
9512
+ ["rot", "0"],
9513
+ ["vert", "horz"],
9514
+ ["wrap", "square"],
9515
+ ["lIns", "91440"],
9516
+ ["tIns", "45720"],
9517
+ ["rIns", "91440"],
9518
+ ["bIns", "45720"],
9519
+ ["anchor", "t"],
9520
+ ["anchorCtr", "0"]
9521
+ ])
9522
+ body.setAttribute(name, value);
9523
+ add(body, el(doc, A_NS, "a:noAutofit"));
9524
+ add(wsp, cNvSpPr, spPr, add(el(doc, WPS_NS, "wps:txbx"), content), body);
9525
+ const graphicData = el(doc, A_NS, "a:graphicData");
9526
+ graphicData.setAttribute("uri", SHAPE_GRAPHIC_URI);
9527
+ add(
9528
+ inline,
9529
+ extent,
9530
+ effect,
9531
+ docPr,
9532
+ el(doc, WP_NS, "wp:cNvGraphicFramePr"),
9533
+ add(el(doc, A_NS, "a:graphic"), add(graphicData, wsp))
9534
+ );
9535
+ return add(drawing, inline);
9536
+ }
9537
+ function isSimpleTextBox(graphicData, anchored) {
9538
+ if (!graphicData || anchored) return false;
9539
+ const content = descendants2(graphicData, W_NS, "txbxContent")[0];
9540
+ if (!content) return false;
9541
+ const plain = (node, allowed) => Array.from(node.childNodes).filter(isElement).every((child8) => child8.namespaceURI === W_NS && allowed.includes(child8.localName));
9542
+ return plain(content, ["p"]) && descendants2(content, W_NS, "p").every(
9543
+ (paragraph2) => plain(paragraph2, ["r"]) && descendants2(paragraph2, W_NS, "r").every((run2) => plain(run2, ["t"]))
9544
+ );
9545
+ }
9546
+ function textBoxHasBorder(graphicData) {
9547
+ const spPr = graphicData && descendants2(graphicData, WPS_NS, "spPr")[0];
9548
+ const ln = spPr && Array.from(spPr.getElementsByTagNameNS(A_NS, "ln"))[0];
9549
+ return Boolean(ln && !ln.getElementsByTagNameNS(A_NS, "noFill").length);
9550
+ }
9551
+ function patchTextBox(doc, drawing, image, base) {
9552
+ if (image.widthPx !== base.widthPx || image.heightPx !== base.heightPx)
9553
+ for (const node of [
9554
+ ...descendants2(drawing, WP_NS, "extent"),
9555
+ ...descendants2(drawing, A_NS, "ext").filter(
9556
+ (ext) => ext.parentNode?.localName === "xfrm"
9557
+ )
9558
+ ]) {
9559
+ node.setAttribute("cx", emu(image.widthPx));
9560
+ node.setAttribute("cy", emu(image.heightPx));
9561
+ }
9562
+ if (JSON.stringify(image.textBoxText) !== JSON.stringify(base.textBoxText)) {
9563
+ const content = descendants2(drawing, W_NS, "txbxContent")[0];
9564
+ if (content) {
9565
+ for (const child8 of Array.from(content.childNodes)) content.removeChild(child8);
9566
+ add(content, ...paragraphsFor(doc, image.textBoxText ?? []));
9567
+ }
9568
+ }
9569
+ if (image.textBoxBorder !== false !== (base.textBoxBorder !== false)) {
9570
+ const spPr = descendants2(drawing, WPS_NS, "spPr")[0];
9571
+ if (spPr) {
9572
+ for (const old of Array.from(spPr.childNodes).filter(
9573
+ (node) => isElement(node) && node.localName === "ln"
9137
9574
  ))
9138
- throw new RangeError("Picture luminance must be between -1 and 1");
9139
- set2("bright", effect.brightness);
9140
- set2("contrast", effect.contrast);
9141
- }
9142
- if (effect.kind === "alphaModFix") {
9143
- if (effect.amount < 0) throw new RangeError("Picture alpha must be nonnegative");
9144
- set2("amt", effect.amount);
9575
+ spPr.removeChild(old);
9576
+ spPr.appendChild(outline(doc, image.textBoxBorder !== false));
9145
9577
  }
9146
- return node;
9147
- });
9148
- for (const node of elements(blip)) blip.removeChild(node);
9149
- for (const node of nodes) blip.appendChild(node);
9150
- }
9151
-
9152
- // drawingml/picture-fill.ts
9153
- function parseDrawingPictureFill(fill) {
9154
- const blip = first(fill, "blip", NS.a);
9155
- const relId = blip?.getAttributeNS(NS.r, "embed") || blip?.getAttribute("r:embed") || void 0;
9156
- const linkRelId = blip?.getAttributeNS(NS.r, "link") || void 0;
9157
- const crop = parsePictureCrop(fill);
9158
- const effects = parsePictureEffects(blip);
9159
- const tile = first(fill, "tile", NS.a);
9160
- const rect2 = first(first(fill, "stretch", NS.a), "fillRect", NS.a);
9161
- const unsupported2 = [
9162
- ...tile ? ["tile"] : [],
9163
- ...rect2 && ["l", "t", "r", "b"].some((key) => Number(rect2.getAttribute(key) ?? 0) !== 0) ? ["fillRect"] : [],
9164
- ...fill.getAttribute("rotWithShape") === "0" || fill.getAttribute("rotWithShape") === "false" ? ["rotWithShape"] : []
9165
- ];
9166
- return {
9167
- kind: "picture",
9168
- sourceXml: buildXml(fill),
9169
- ...relId ? { relId } : {},
9170
- ...linkRelId ? { linkRelId } : {},
9171
- ...crop ? { crop } : {},
9172
- ...effects.length ? { effects } : {},
9173
- ...unsupported2.length ? { unsupportedPicture: unsupported2 } : {}
9174
- };
9578
+ }
9175
9579
  }
9176
9580
 
9177
9581
  // drawingml/drawing-fill.ts
@@ -9714,80 +10118,6 @@ function parseDrawingGeometry(spPr) {
9714
10118
  return { geometry: geometry2, ...Object.keys(adjustments).length > 0 ? { adjustments } : {} };
9715
10119
  }
9716
10120
 
9717
- // drawingml/write-color.ts
9718
- var ELEMENTS = {
9719
- srgb: "srgbClr",
9720
- scheme: "schemeClr",
9721
- system: "sysClr",
9722
- preset: "prstClr",
9723
- scrgb: "scrgbClr",
9724
- hsl: "hslClr"
9725
- };
9726
- function drawingColorXml(color) {
9727
- const local = ELEMENTS[color.kind];
9728
- const doc = parseXml(`<a:${local} xmlns:a="${NS.a}"/>`);
9729
- const root = doc.documentElement;
9730
- if (color.kind === "scrgb" || color.kind === "hsl") {
9731
- const keys = color.kind === "scrgb" ? ["r", "g", "b"] : ["hue", "sat", "lum"];
9732
- const values = color.value.split(",");
9733
- keys.forEach((key, i2) => root.setAttribute(key, values[i2] ?? "0"));
9734
- } else root.setAttribute("val", color.value);
9735
- if (color.fallback !== void 0 && color.kind === "system")
9736
- root.setAttribute("lastClr", color.fallback);
9737
- for (const transform7 of color.transforms) {
9738
- if (!/^[A-Za-z_][\w.-]*$/.test(transform7.name))
9739
- throw new Error(`Invalid DrawingML transform ${transform7.name}`);
9740
- const node = doc.createElementNS(NS.a, `a:${transform7.name}`);
9741
- if (transform7.value !== "") node.setAttribute("val", transform7.value);
9742
- root.appendChild(node);
9743
- }
9744
- return buildXml(doc);
9745
- }
9746
-
9747
- // drawingml/patch-color.ts
9748
- function patchDrawingColorIn(container2, color) {
9749
- const old = elements(container2).find((node) => parseDrawingColor(node));
9750
- const before = parseDrawingColorIn(container2);
9751
- if (!old || !before || before.kind !== color.kind) {
9752
- const next = container2.ownerDocument.importNode(
9753
- parseXml(drawingColorXml(color)).documentElement,
9754
- true
9755
- );
9756
- if (old) container2.replaceChild(next, old);
9757
- else container2.insertBefore(next, container2.firstChild);
9758
- return;
9759
- }
9760
- if (before.value !== color.value) {
9761
- if (color.kind === "scrgb" || color.kind === "hsl") {
9762
- const keys = color.kind === "scrgb" ? ["r", "g", "b"] : ["hue", "sat", "lum"];
9763
- const values = color.value.split(",");
9764
- keys.forEach((key, index) => old.setAttribute(key, values[index] ?? "0"));
9765
- } else old.setAttribute("val", color.value);
9766
- }
9767
- if (before.fallback !== color.fallback && color.kind === "system") {
9768
- if (color.fallback === void 0) old.removeAttribute("lastClr");
9769
- else old.setAttribute("lastClr", color.fallback);
9770
- }
9771
- const originals = elements(old);
9772
- color.transforms.forEach((transform7, index) => {
9773
- const source2 = originals[index];
9774
- if (source2?.localName === transform7.name) {
9775
- if (before.transforms[index]?.value !== transform7.value) {
9776
- if (transform7.value === "") source2.removeAttribute("val");
9777
- else source2.setAttribute("val", transform7.value);
9778
- }
9779
- return;
9780
- }
9781
- if (!/^[A-Za-z_][\w.-]*$/u.test(transform7.name))
9782
- throw new Error("Invalid DrawingML colour transform");
9783
- const next = old.ownerDocument.createElementNS(NS.a, `a:${transform7.name}`);
9784
- if (transform7.value !== "") next.setAttribute("val", transform7.value);
9785
- if (source2) old.replaceChild(next, source2);
9786
- else old.appendChild(next);
9787
- });
9788
- for (const extra of originals.slice(color.transforms.length)) old.removeChild(extra);
9789
- }
9790
-
9791
10121
  // drawingml/write-pattern-picture.ts
9792
10122
  function drawingPatternPictureXml(fill) {
9793
10123
  const name = fill.kind === "pattern" ? "pattFill" : "blipFill";
@@ -9849,7 +10179,8 @@ function drawingPatternPictureXml(fill) {
9849
10179
  applyPictureCrop(root, fill.crop);
9850
10180
  if (fill.effects !== void 0 && JSON.stringify(before?.kind === "picture" ? before.effects ?? [] : []) !== JSON.stringify(fill.effects ?? []))
9851
10181
  applyPictureEffects(blip, fill.effects ?? []);
9852
- if (!fill.sourceXml) {
10182
+ if (fill.layout !== void 0) applyPictureLayout(root, fill.layout);
10183
+ if (!fill.sourceXml && !fill.layout?.tile && !first(root, "stretch", NS.a)) {
9853
10184
  const stretch = doc.createElementNS(NS.a, "a:stretch");
9854
10185
  stretch.appendChild(doc.createElementNS(NS.a, "a:fillRect"));
9855
10186
  root.appendChild(stretch);
@@ -21109,7 +21440,7 @@ function isSpace(ch) {
21109
21440
  return ch === " " || ch === " " || ch === "\n" || ch === "\r";
21110
21441
  }
21111
21442
  function parseAttributes(source2) {
21112
- const attrs2 = {};
21443
+ const attrs3 = {};
21113
21444
  let i2 = 0;
21114
21445
  const n = source2.length;
21115
21446
  while (i2 < n) {
@@ -21144,9 +21475,9 @@ function parseAttributes(source2) {
21144
21475
  if (name === "xmlns" || name.startsWith("xmlns:")) {
21145
21476
  continue;
21146
21477
  }
21147
- attrs2[localName(name)] = decodeEntities(value);
21478
+ attrs3[localName(name)] = decodeEntities(value);
21148
21479
  }
21149
- return attrs2;
21480
+ return attrs3;
21150
21481
  }
21151
21482
  function tagEnd2(xml, from) {
21152
21483
  let quote = "";
@@ -21272,14 +21603,14 @@ function numOrNaN(value) {
21272
21603
  function relation(value) {
21273
21604
  return value === "ch" || value === "des" ? value : "self";
21274
21605
  }
21275
- function parseIterator(attrs2) {
21606
+ function parseIterator(attrs3) {
21276
21607
  return {
21277
- axis: list(attrs2.axis),
21278
- ptType: list(attrs2.ptType),
21279
- hideLastTrans: list(attrs2.hideLastTrans).map((v) => v === "1" || v === "true"),
21280
- st: numberList(attrs2.st),
21281
- cnt: numberList(attrs2.cnt),
21282
- step: numberList(attrs2.step)
21608
+ axis: list(attrs3.axis),
21609
+ ptType: list(attrs3.ptType),
21610
+ hideLastTrans: list(attrs3.hideLastTrans).map((v) => v === "1" || v === "true"),
21611
+ st: numberList(attrs3.st),
21612
+ cnt: numberList(attrs3.cnt),
21613
+ step: numberList(attrs3.step)
21283
21614
  };
21284
21615
  }
21285
21616
  function parseAlgorithm(element4) {
@@ -21310,41 +21641,41 @@ function parseShape2(element4) {
21310
21641
  adj
21311
21642
  };
21312
21643
  }
21313
- function parseConstraint(attrs2) {
21314
- const op2 = attrs2.op;
21644
+ function parseConstraint(attrs3) {
21645
+ const op2 = attrs3.op;
21315
21646
  return {
21316
- type: attrs2.type ?? "none",
21317
- for: relation(attrs2.for),
21318
- forName: attrs2.forName || void 0,
21319
- ptType: attrs2.ptType ?? "all",
21320
- refType: attrs2.refType ?? "none",
21321
- refFor: relation(attrs2.refFor),
21322
- refForName: attrs2.refForName || void 0,
21323
- refPtType: attrs2.refPtType ?? "all",
21647
+ type: attrs3.type ?? "none",
21648
+ for: relation(attrs3.for),
21649
+ forName: attrs3.forName || void 0,
21650
+ ptType: attrs3.ptType ?? "all",
21651
+ refType: attrs3.refType ?? "none",
21652
+ refFor: relation(attrs3.refFor),
21653
+ refForName: attrs3.refForName || void 0,
21654
+ refPtType: attrs3.refPtType ?? "all",
21324
21655
  op: op2 === "equ" || op2 === "gte" || op2 === "lte" ? op2 : "none",
21325
- val: num(attrs2.val, 0),
21326
- hasVal: attrs2.val !== void 0,
21327
- fact: num(attrs2.fact, 1)
21656
+ val: num(attrs3.val, 0),
21657
+ hasVal: attrs3.val !== void 0,
21658
+ fact: num(attrs3.fact, 1)
21328
21659
  };
21329
21660
  }
21330
- function parseRule(attrs2) {
21661
+ function parseRule(attrs3) {
21331
21662
  return {
21332
- type: attrs2.type ?? "none",
21333
- for: relation(attrs2.for),
21334
- forName: attrs2.forName || void 0,
21335
- ptType: attrs2.ptType ?? "all",
21336
- val: numOrNaN(attrs2.val),
21337
- fact: numOrNaN(attrs2.fact),
21338
- max: numOrNaN(attrs2.max)
21663
+ type: attrs3.type ?? "none",
21664
+ for: relation(attrs3.for),
21665
+ forName: attrs3.forName || void 0,
21666
+ ptType: attrs3.ptType ?? "all",
21667
+ val: numOrNaN(attrs3.val),
21668
+ fact: numOrNaN(attrs3.fact),
21669
+ max: numOrNaN(attrs3.max)
21339
21670
  };
21340
21671
  }
21341
- function parseCondition(attrs2) {
21672
+ function parseCondition(attrs3) {
21342
21673
  return {
21343
- ...parseIterator(attrs2),
21344
- func: attrs2.func ?? "cnt",
21345
- arg: attrs2.arg,
21346
- op: attrs2.op ?? "equ",
21347
- val: attrs2.val ?? ""
21674
+ ...parseIterator(attrs3),
21675
+ func: attrs3.func ?? "cnt",
21676
+ arg: attrs3.arg,
21677
+ op: attrs3.op ?? "equ",
21678
+ val: attrs3.val ?? ""
21348
21679
  };
21349
21680
  }
21350
21681
  function parseBody(element4, state) {
@@ -25445,7 +25776,13 @@ function buildRenderedNode(node, index, nodeById, palette, style, mergedSourceId
25445
25776
  fontSize: 0,
25446
25777
  textX: x + width / 2,
25447
25778
  textY: y + height / 2,
25448
- nodeId: primary?.id,
25779
+ // Picture roles often omit presOf: they present the current point's image, not its text.
25780
+ nodeId: primary?.id ?? (node.shape?.blipPhldr ? node.point.source?.id : void 0),
25781
+ picturePlaceholder: node.shape?.blipPhldr,
25782
+ layoutRole: node.name,
25783
+ contextNodeId: node.point.source?.id,
25784
+ textAlign: ["l", "ctr", "r"].includes(node.alg.params.parTxLTRAlign ?? "") ? node.alg.params.parTxLTRAlign : void 0,
25785
+ textVerticalAnchor: ["t", "ctr", "b"].includes(node.alg.params.txAnchorVert ?? "") ? node.alg.params.txAnchorVert : void 0,
25449
25786
  rotation: transform7.rotation === 0 ? void 0 : transform7.rotation,
25450
25787
  presetOverride: node.shape?.type ?? "roundRect",
25451
25788
  foldedNodeIds: foldedNodeIds.length > 0 ? foldedNodeIds : void 0,
@@ -27219,7 +27556,7 @@ function connectionLabel(connection, transitionText) {
27219
27556
  function textBodyParagraphs(body) {
27220
27557
  if (!body) return [];
27221
27558
  return children(body, "p", NS.a).map(
27222
- (paragraph2) => descendants2(paragraph2, "t").map((run2) => run2.textContent ?? "").join("")
27559
+ (paragraph2) => descendants(paragraph2, "t").map((run2) => run2.textContent ?? "").join("")
27223
27560
  );
27224
27561
  }
27225
27562
  function parsePoint(element4) {
@@ -27307,15 +27644,15 @@ function parseDiagramDataModel(source2, part) {
27307
27644
  if ((!connection.type || connection.type === "parOf") && !parentById.has(connection.destId))
27308
27645
  parentById.set(connection.destId, connection.sourceId);
27309
27646
  }
27310
- const ext = descendants2(root, "dataModelExt")[0];
27647
+ const ext = descendants(root, "dataModelExt")[0];
27311
27648
  const drawingRelId = stringAttribute(ext, "relId");
27312
- const generated2 = descendants2(root, "generatedCache").find(
27649
+ const generated2 = descendants(root, "generatedCache").find(
27313
27650
  (node) => node.namespaceURI === GENERATED_DIAGRAM_CACHE_NS
27314
27651
  );
27315
27652
  const generatedCacheDigest = generated2?.getAttribute("drawingSha256");
27316
27653
  return {
27317
27654
  points,
27318
- ...descendants2(root, "generatedCache").some(
27655
+ ...descendants(root, "generatedCache").some(
27319
27656
  (node) => node.namespaceURI === GENERATED_DIAGRAM_CACHE_NS
27320
27657
  ) ? { generatedCache: true } : {},
27321
27658
  ...generatedCacheDigest ? { generatedCacheDigest } : {},
@@ -27459,7 +27796,7 @@ function parseDiagramLayoutSummary(source2) {
27459
27796
  ...header,
27460
27797
  ...family ? { family } : {},
27461
27798
  ...rootAlgorithm ? { rootAlgorithm } : {},
27462
- layoutNodeCount: descendants2(root, "layoutNode").length
27799
+ layoutNodeCount: descendants(root, "layoutNode").length
27463
27800
  };
27464
27801
  }
27465
27802
 
@@ -27578,6 +27915,203 @@ function approximateDiagramDrawingFromNodes(input) {
27578
27915
  });
27579
27916
  }
27580
27917
 
27918
+ // diagram/picture-layout.ts
27919
+ var DIAGRAM_PICTURE_SOURCE_NS = "urn:ooxml-core:diagram-picture-sources:1";
27920
+ function remapFill(fill, id) {
27921
+ if (!fill.sourceXml) return { ...fill, relId: id };
27922
+ const node = parseXml(fill.sourceXml).documentElement;
27923
+ const blip = first(node, "blip", NS.a);
27924
+ if (blip) {
27925
+ blip.setAttributeNS(NS.r, "r:embed", id);
27926
+ blip.removeAttributeNS(NS.r, "link");
27927
+ }
27928
+ return { ...fill, relId: id, sourceXml: buildXml(node) };
27929
+ }
27930
+ function captureDiagramPictures(model, dataXml2, dataParts, drawing) {
27931
+ const pictures = [];
27932
+ const parts = { ...dataParts };
27933
+ const add4 = (source2, owner) => {
27934
+ const part = source2.fill.relId ? owner[source2.fill.relId] : void 0;
27935
+ if (!part) return;
27936
+ let id = Object.keys(parts).find((key) => parts[key] === part);
27937
+ if (!id) {
27938
+ let index = 1;
27939
+ while (Object.hasOwn(parts, `ooxmlDiagramPicture${index}`)) index++;
27940
+ id = `ooxmlDiagramPicture${index}`;
27941
+ parts[id] = part;
27942
+ }
27943
+ const entry2 = { ...source2, fill: remapFill(source2.fill, id) };
27944
+ const existing = pictures.findIndex(
27945
+ (item2) => item2.nodeId === entry2.nodeId && (item2.role === entry2.role && item2.styleLabel === entry2.styleLabel || !item2.role && !item2.styleLabel && item2.fill.relId === entry2.fill.relId)
27946
+ );
27947
+ if (existing < 0) pictures.push(entry2);
27948
+ else pictures[existing] = entry2;
27949
+ };
27950
+ const root = parseXml(dataXml2).documentElement;
27951
+ const saved = root.getElementsByTagNameNS(DIAGRAM_PICTURE_SOURCE_NS, "picture");
27952
+ for (const element4 of saved) {
27953
+ const nodeId = element4.getAttribute("nodeId");
27954
+ const fill = first(element4, "blipFill", NS.a);
27955
+ if (nodeId && fill && model.nodes.some((node) => node.modelId === nodeId))
27956
+ add4(
27957
+ {
27958
+ nodeId,
27959
+ fill: parseDrawingPictureFill(fill),
27960
+ ...element4.getAttribute("role") ? { role: element4.getAttribute("role") } : {},
27961
+ ...element4.getAttribute("styleLabel") ? { styleLabel: element4.getAttribute("styleLabel") } : {}
27962
+ },
27963
+ dataParts
27964
+ );
27965
+ }
27966
+ for (const point of model.points) {
27967
+ if (point.fill?.kind !== "picture") continue;
27968
+ const nodeId = point.type === "pres" ? point.presAssocId : point.modelId;
27969
+ if (nodeId && model.nodes.some((node) => node.modelId === nodeId) && !pictures.some((item2) => item2.nodeId === nodeId))
27970
+ add4(
27971
+ {
27972
+ nodeId,
27973
+ fill: point.fill,
27974
+ ...point.presName ? { role: point.presName } : {},
27975
+ ...point.presStyleLabel ? { styleLabel: point.presStyleLabel } : {}
27976
+ },
27977
+ dataParts
27978
+ );
27979
+ }
27980
+ for (const shape of drawing?.shapes ?? []) {
27981
+ if (shape.fill?.kind !== "picture") continue;
27982
+ const point = model.points.find((point2) => point2.modelId === shape.modelId);
27983
+ const nodeId = shape.sourceNodeId ?? (point?.type === "pres" ? point.presAssocId : point?.modelId);
27984
+ const part = shape.fill.relId ? drawing?.pictureParts?.[shape.fill.relId] : void 0;
27985
+ if (saved.length && pictures.some(
27986
+ (item2) => item2.nodeId === nodeId && item2.fill.relId && parts[item2.fill.relId] === part && item2.role !== point?.presName && item2.styleLabel !== point?.presStyleLabel
27987
+ ))
27988
+ continue;
27989
+ if (nodeId && model.nodes.some((node) => node.modelId === nodeId))
27990
+ add4(
27991
+ {
27992
+ nodeId,
27993
+ fill: shape.fill,
27994
+ ...point?.presName ? { role: point.presName } : {},
27995
+ ...point?.presStyleLabel ? { styleLabel: point.presStyleLabel } : {}
27996
+ },
27997
+ drawing?.pictureParts ?? {}
27998
+ );
27999
+ }
28000
+ return pictures.length ? { pictures, pictureParts: parts } : {};
28001
+ }
28002
+ function applyDiagramPictureSources(drawing, nodes, source2, issues, liveNodeIds) {
28003
+ if (!source2?.pictures?.length) return;
28004
+ if (source2.pictureParts) drawing.pictureParts = { ...source2.pictureParts };
28005
+ const used = /* @__PURE__ */ new Set();
28006
+ nodes.forEach((node, index) => {
28007
+ if (!node.picturePlaceholder || !node.nodeId) return;
28008
+ const shape = drawing.shapes[index];
28009
+ if (!shape) return;
28010
+ const candidates = source2.pictures.filter((picture2) => picture2.nodeId === node.nodeId);
28011
+ const matching = candidates.filter(
28012
+ (picture2) => picture2.role === node.layoutRole || !!picture2.styleLabel && picture2.styleLabel === node.styleLabel
28013
+ );
28014
+ const picture = matching.length === 1 ? matching[0] : candidates.length === 1 ? candidates[0] : void 0;
28015
+ if (picture) {
28016
+ shape.fill = structuredClone(picture.fill);
28017
+ delete shape.text;
28018
+ delete shape.body;
28019
+ used.add(picture);
28020
+ } else if (candidates.length)
28021
+ issues.push({
28022
+ code: "DIAGRAM_PICTURE_AMBIGUOUS",
28023
+ message: `Picture role ${node.layoutRole ?? node.key} has multiple source pictures; no arbitrary assignment was made.`
28024
+ });
28025
+ });
28026
+ if (source2.pictures.some(
28027
+ (picture) => (!liveNodeIds || liveNodeIds.has(picture.nodeId)) && !used.has(picture)
28028
+ ))
28029
+ issues.push({
28030
+ code: "DIAGRAM_PICTURE_LAYOUT_UNSUPPORTED",
28031
+ message: "Some retained pictures have no matching image placeholder in this layout. Their source associations are preserved for a compatible layout."
28032
+ });
28033
+ }
28034
+ function withDiagramPictureSources(dataXml2, source2) {
28035
+ if (!source2?.pictures?.length) return dataXml2;
28036
+ const doc = parseXml(dataXml2);
28037
+ const root = doc.documentElement;
28038
+ const points = first(root, "ptLst", NS.dgm);
28039
+ const live = children(points ?? root, "pt", NS.dgm).filter(
28040
+ (point) => !["doc", "pres", "parTrans", "sibTrans"].includes(point.getAttribute("type") ?? "node")
28041
+ );
28042
+ for (const element4 of [...root.getElementsByTagNameNS(DIAGRAM_PICTURE_SOURCE_NS, "pictures")]) {
28043
+ const extension2 = element4.parentNode;
28044
+ if (extension2?.parentNode) extension2.parentNode.removeChild(extension2);
28045
+ }
28046
+ const retained = source2.pictures.filter(
28047
+ (picture) => live.some((point) => point.getAttribute("modelId") === picture.nodeId)
28048
+ );
28049
+ if (!retained.length) return buildXml(doc);
28050
+ const list2 = first(root, "extLst", NS.dgm) ?? doc.createElementNS(NS.dgm, "dgm:extLst");
28051
+ if (!list2.parentNode) root.appendChild(list2);
28052
+ const extension = doc.createElementNS(NS.a, "a:ext");
28053
+ extension.setAttribute("uri", DIAGRAM_PICTURE_SOURCE_NS);
28054
+ const payload = doc.createElementNS(DIAGRAM_PICTURE_SOURCE_NS, "op:pictures");
28055
+ extension.appendChild(payload);
28056
+ list2.appendChild(extension);
28057
+ for (const picture of retained) {
28058
+ if (!picture.fill.sourceXml)
28059
+ throw new Error("A retained SmartArt picture needs source fill XML");
28060
+ const element4 = doc.createElementNS(DIAGRAM_PICTURE_SOURCE_NS, "op:picture");
28061
+ element4.setAttribute("nodeId", picture.nodeId);
28062
+ if (picture.role) element4.setAttribute("role", picture.role);
28063
+ if (picture.styleLabel) element4.setAttribute("styleLabel", picture.styleLabel);
28064
+ const fill = parseXml(picture.fill.sourceXml).documentElement;
28065
+ element4.appendChild(doc.importNode(fill, true));
28066
+ payload.appendChild(element4);
28067
+ const presentations = children(points ?? root, "pt", NS.dgm).filter((point) => {
28068
+ const props = first(point, "prSet", NS.dgm);
28069
+ return point.getAttribute("type") === "pres" && props?.getAttribute("presAssocID") === picture.nodeId && (picture.role && props.getAttribute("presName") === picture.role || picture.styleLabel && props.getAttribute("presStyleLbl") === picture.styleLabel);
28070
+ });
28071
+ if (presentations.length === 1) {
28072
+ const point = presentations[0];
28073
+ const props = first(point, "spPr", NS.dgm) ?? doc.createElementNS(NS.dgm, "dgm:spPr");
28074
+ if (!props.parentNode) point.appendChild(props);
28075
+ for (const old of [...props.childNodes].filter((node) => node.nodeType === 1).filter(
28076
+ (node) => node.namespaceURI === NS.a && ["blipFill", "solidFill", "gradFill", "pattFill", "noFill", "grpFill"].includes(
28077
+ node.localName
28078
+ )
28079
+ ))
28080
+ props.removeChild(old);
28081
+ props.insertBefore(doc.importNode(fill, true), props.firstChild);
28082
+ }
28083
+ }
28084
+ return buildXml(doc);
28085
+ }
28086
+ function diagramPictureRelationships(owner, source2, existing) {
28087
+ if (!source2?.pictures?.length || !source2.pictureParts) return existing;
28088
+ const rels = parseRelationships(existing);
28089
+ for (const [id, part] of Object.entries(source2.pictureParts)) {
28090
+ const previous = rels.get(id);
28091
+ if (previous && (previous.mode === "External" || resolvePartPath(owner, previous.target) !== part))
28092
+ throw new Error(`Conflicting SmartArt picture relationship: ${id}`);
28093
+ rels.set(id, { id, type: RELATIONSHIP_TYPES.image, target: `/${part}`, mode: "Internal" });
28094
+ }
28095
+ return buildRelationshipsXml(rels);
28096
+ }
28097
+
28098
+ // diagram/layout-role-style.ts
28099
+ function applyDiagramRoleColors(shape, role, index, minorFont) {
28100
+ const at = (colors) => colors[index % colors.length];
28101
+ const fill = role && at(role.fill.colors);
28102
+ if (fill && shape.fill?.kind !== "none" && shape.fill?.kind !== "picture")
28103
+ shape.fill = { kind: "solid", color: structuredClone(fill) };
28104
+ const line2 = role && at(role.line.colors);
28105
+ if (line2 && shape.line) shape.line.fill = { kind: "solid", color: structuredClone(line2) };
28106
+ const text = role && at(role.textFill.colors);
28107
+ for (const paragraph2 of shape.text?.paragraphs ?? []) {
28108
+ for (const run2 of paragraph2.runs) {
28109
+ if (!run2.color && text) run2.color = structuredClone(text);
28110
+ if (!run2.typeface && minorFont) run2.typeface = minorFont;
28111
+ }
28112
+ }
28113
+ }
28114
+
27581
28115
  // diagram/layout-preview.ts
27582
28116
  function diagramLayoutData(input) {
27583
28117
  const original = input.source?.dataXml ? parseDiagramDataModel(input.source.dataXml) : void 0;
@@ -27623,7 +28157,7 @@ function diagramLayoutData(input) {
27623
28157
  data.layoutDefinition = { rootNode: {}, rawXmlText: input.source.layoutXml };
27624
28158
  if (input.source?.dataXml) {
27625
28159
  const root = parseXml(input.source.dataXml).documentElement;
27626
- const vars = descendants2(root, "presLayoutVars")[0];
28160
+ const vars = descendants(root, "presLayoutVars")[0];
27627
28161
  const direction = first(vars, "dir", NS.dgm)?.getAttribute("val");
27628
28162
  const values = {};
27629
28163
  if (direction === "norm" || direction === "rev") values.direction = direction;
@@ -27681,7 +28215,7 @@ function previewDiagramLayout(input) {
27681
28215
  const computed = runEngineLayout(data, box, data.nodes, palette, intensity);
27682
28216
  if (computed) {
27683
28217
  const result = applyCustomLayoutOverrides(computed, data.nodes, box);
27684
- const declaresConnectors = input.source?.layoutXml && descendants2(parseXml(input.source.layoutXml).documentElement, "alg").some(
28218
+ const declaresConnectors = input.source?.layoutXml && descendants(parseXml(input.source.layoutXml).documentElement, "alg").some(
27685
28219
  (algorithm) => algorithm.getAttribute("type") === "conn"
27686
28220
  );
27687
28221
  if (declaresConnectors && data.nodes.some((node) => node.parentId) && !result.nodes.some((node) => /connector|^line(?:Inv)?$/i.test(node.presetOverride ?? "")))
@@ -27723,6 +28257,8 @@ function previewDiagramLayout(input) {
27723
28257
  ];
27724
28258
  });
27725
28259
  const drawing2 = diagramDrawingFromViews(views);
28260
+ drawing2.extentEmu = { ...input.extentEmu };
28261
+ const colors = input.source?.colorsXml ? parseDiagramColors(input.source.colorsXml) : void 0;
27726
28262
  const quickStyle = input.source?.quickStyleXml ? parseDiagramQuickStyle(input.source.quickStyleXml) : void 0;
27727
28263
  const originalModel = input.source?.dataXml ? parseDiagramDataModel(input.source.dataXml) : void 0;
27728
28264
  result.nodes.forEach((node, index) => {
@@ -27733,7 +28269,9 @@ function previewDiagramLayout(input) {
27733
28269
  shape.style = label;
27734
28270
  shape.has3d = label.requires3d ?? label.hasShape3d;
27735
28271
  }
27736
- if (node.nodeId) shape.sourceNodeId = node.nodeId;
28272
+ const contextNodeId = node.nodeId ?? node.contextNodeId;
28273
+ if (contextNodeId) shape.sourceNodeId = contextNodeId;
28274
+ if (node.layoutRole) shape.sourceLayoutRole = node.layoutRole;
27737
28275
  if (node.styleLabel) shape.sourceStyleLabel = node.styleLabel;
27738
28276
  if (node.foldedNodeIds?.length) shape.foldedNodeIds = node.foldedNodeIds;
27739
28277
  const sourceNode = data.nodes.find((entry2) => entry2.id === node.nodeId);
@@ -27746,15 +28284,36 @@ function previewDiagramLayout(input) {
27746
28284
  if (fill) shape.fill = fill;
27747
28285
  }
27748
28286
  const direct = originalModel?.nodes.find((entry2) => entry2.modelId === node.nodeId);
27749
- if (direct?.fill) shape.fill = direct.fill;
27750
- if (direct?.line) shape.line = { ...shape.line, ...direct.line };
27751
28287
  const sourceIds = [node.nodeId, ...node.foldedNodeIds ?? []];
27752
28288
  const textNodes = sourceIds.flatMap((id) => {
27753
28289
  const source2 = input.nodes.find((entry2) => entry2.id === id);
27754
28290
  return source2 ? [source2] : [];
27755
28291
  });
27756
28292
  if (textNodes.length) shape.text = diagramPreviewText(textNodes, node.fontSize);
28293
+ if (shape.text) {
28294
+ if (node.textVerticalAnchor) shape.text.anchor = node.textVerticalAnchor;
28295
+ for (const paragraph2 of shape.text.paragraphs)
28296
+ if (!paragraph2.align && node.textAlign) paragraph2.align = node.textAlign;
28297
+ }
28298
+ applyDiagramRoleColors(
28299
+ shape,
28300
+ colors?.labels.find((label2) => label2.name === node.styleLabel),
28301
+ Math.max(
28302
+ 0,
28303
+ input.nodes.findIndex((entry2) => entry2.id === contextNodeId)
28304
+ ),
28305
+ input.minorFont
28306
+ );
28307
+ if (direct?.fill && direct.fill.kind !== "picture") shape.fill = direct.fill;
28308
+ if (direct?.line) shape.line = { ...shape.line, ...direct.line };
27757
28309
  });
28310
+ applyDiagramPictureSources(
28311
+ drawing2,
28312
+ result.nodes,
28313
+ input.source,
28314
+ issues,
28315
+ new Set(input.nodes.map((node) => node.id))
28316
+ );
27758
28317
  return { drawing: drawing2, mode: "interpreted", issues };
27759
28318
  }
27760
28319
  } catch (error) {
@@ -27795,16 +28354,16 @@ function resolveDiagramDrawingStyles(drawing, scheme2) {
27795
28354
 
27796
28355
  // diagram/write/cache.ts
27797
28356
  var DSP2 = "http://schemas.microsoft.com/office/drawing/2008/diagram";
27798
- function add2(parent, namespace, name, attrs2 = {}) {
28357
+ function add2(parent, namespace, name, attrs3 = {}) {
27799
28358
  const child8 = parent.ownerDocument.createElementNS(namespace, name);
27800
- for (const [key, value] of Object.entries(attrs2)) child8.setAttribute(key, value);
28359
+ for (const [key, value] of Object.entries(attrs3)) child8.setAttribute(key, value);
27801
28360
  parent.appendChild(child8);
27802
28361
  return child8;
27803
28362
  }
27804
28363
  function withDiagramDrawingRelationship(xml, relationshipId) {
27805
28364
  const doc = parseXml(xml);
27806
28365
  const model = doc.documentElement;
27807
- let extension = descendants2(model, "dataModelExt").find((node) => node.namespaceURI === DSP2);
28366
+ let extension = descendants(model, "dataModelExt").find((node) => node.namespaceURI === DSP2);
27808
28367
  if (!extension) {
27809
28368
  const extLst = first(model, "extLst", NS.dgm) ?? add2(model, NS.dgm, "dgm:extLst");
27810
28369
  extension = add2(add2(extLst, NS.a, "a:ext", { uri: DSP2 }), DSP2, "dsp:dataModelExt", {
@@ -27815,6 +28374,7 @@ function withDiagramDrawingRelationship(xml, relationshipId) {
27815
28374
  return buildXml(doc);
27816
28375
  }
27817
28376
  function buildGeneratedDiagramCache(dataXml2, input) {
28377
+ dataXml2 = withDiagramPictureSources(dataXml2, input.source);
27818
28378
  const source2 = { ...input.source, dataXml: dataXml2 };
27819
28379
  const model = parseDiagramDataModel(dataXml2);
27820
28380
  const scheme2 = { ...DEFAULT_GENERATED_DIAGRAM_SCHEME, ...input.scheme };
@@ -27841,7 +28401,10 @@ function buildGeneratedDiagramCache(dataXml2, input) {
27841
28401
  }
27842
28402
  for (const shape of drawing.shapes) {
27843
28403
  if (shape.has3d || shape.foldedNodeIds?.length) return void 0;
27844
- if (shape.fill && !["none", "solid", "gradient"].includes(shape.fill.kind)) return void 0;
28404
+ if (shape.fill && !["none", "solid", "gradient", "picture"].includes(shape.fill.kind))
28405
+ return void 0;
28406
+ if (shape.fill?.kind === "picture" && (!shape.fill.relId || !drawing.pictureParts?.[shape.fill.relId]))
28407
+ return void 0;
27845
28408
  if (shape.fill?.kind === "gradient" && shape.fill.path && !["circle", "rect"].includes(shape.fill.path))
27846
28409
  return void 0;
27847
28410
  if (shape.effects?.effects.some(
@@ -27914,12 +28477,12 @@ function buildGeneratedDiagramCache(dataXml2, input) {
27914
28477
  } catch {
27915
28478
  return void 0;
27916
28479
  }
27917
- const oldMarkers = descendants2(root, "generatedCache").filter(
28480
+ const oldMarkers = descendants(root, "generatedCache").filter(
27918
28481
  (node) => node.namespaceURI === GENERATED_DIAGRAM_CACHE_NS
27919
28482
  );
27920
28483
  const oldIds = new Set(
27921
28484
  oldMarkers.flatMap(
27922
- (marker2) => descendants2(marker2, "shape").map((node) => node.getAttribute("id"))
28485
+ (marker2) => descendants(marker2, "shape").map((node) => node.getAttribute("id"))
27923
28486
  )
27924
28487
  );
27925
28488
  for (const point of children(points, "pt", NS.dgm))
@@ -27948,12 +28511,15 @@ function buildGeneratedDiagramCache(dataXml2, input) {
27948
28511
  const point = add2(points, NS.dgm, "dgm:pt", { modelId: id, type: "pres" });
27949
28512
  add2(point, NS.dgm, "dgm:prSet", {
27950
28513
  ...shape.sourceNodeId ? { presAssocID: shape.sourceNodeId } : {},
27951
- presName: "node",
28514
+ presName: shape.sourceLayoutRole ?? "node",
27952
28515
  presStyleLbl: shape.sourceStyleLabel ?? "node1",
27953
28516
  presStyleIdx: String(index),
27954
28517
  presStyleCnt: String(drawing.shapes.length)
27955
28518
  });
27956
- add2(point, NS.dgm, "dgm:spPr");
28519
+ const properties = add2(point, NS.dgm, "dgm:spPr");
28520
+ if (shape.fill?.kind === "picture" && shape.fill.sourceXml) {
28521
+ properties.appendChild(doc.importNode(parseXml(shape.fill.sourceXml).documentElement, true));
28522
+ }
27957
28523
  if (shape.sourceNodeId)
27958
28524
  add2(connections, NS.dgm, "dgm:cxn", {
27959
28525
  modelId: createOfficeGuid(),
@@ -27966,7 +28532,11 @@ function buildGeneratedDiagramCache(dataXml2, input) {
27966
28532
  });
27967
28533
  add2(marker, GENERATED_DIAGRAM_CACHE_NS, "oc:shape", { id });
27968
28534
  });
27969
- return { dataXml: buildXml(doc), drawingXml: serialized.xml };
28535
+ return {
28536
+ dataXml: buildXml(doc),
28537
+ drawingXml: serialized.xml,
28538
+ ...drawing.pictureParts ? { pictureParts: drawing.pictureParts } : {}
28539
+ };
27970
28540
  }
27971
28541
 
27972
28542
  // diagram/relationships.ts
@@ -28231,6 +28801,29 @@ async function loadDiagram(hostPart, relationshipIds, host) {
28231
28801
  code: "DIAGRAM_DRAWING_ABSENT",
28232
28802
  message: "The package has no cached drawing for this diagram; its layout can only be recomputed from the layout definition."
28233
28803
  });
28804
+ if (data && layoutSource.dataXml) {
28805
+ let pictureParts = {};
28806
+ if (paths.data) {
28807
+ const owner = paths.data;
28808
+ try {
28809
+ const entries = await host.readRelationshipEntries(diagramRelationshipsPart(owner));
28810
+ pictureParts = Object.fromEntries(
28811
+ (entries ?? []).filter(
28812
+ (entry2) => entry2.type.endsWith("/image") && entry2.mode !== "External" && !/^[a-z][a-z0-9+.-]*:/i.test(entry2.target)
28813
+ ).map((entry2) => [entry2.id, host.resolvePath(owner, entry2.target)])
28814
+ );
28815
+ } catch {
28816
+ issues.push({
28817
+ code: "DIAGRAM_PICTURE_RELATIONSHIPS_UNREADABLE",
28818
+ message: "Picture relationships in the diagram data could not be read."
28819
+ });
28820
+ }
28821
+ }
28822
+ Object.assign(
28823
+ layoutSource,
28824
+ captureDiagramPictures(data, layoutSource.dataXml, pictureParts, drawing)
28825
+ );
28826
+ }
28234
28827
  return {
28235
28828
  layoutSource,
28236
28829
  ...generatedCache ? { generatedCache: true } : {},
@@ -30602,8 +31195,8 @@ function attributes(entries) {
30602
31195
  return ` ${name}="${text}"`;
30603
31196
  }).join("");
30604
31197
  }
30605
- var cxElement = (local, content = "", attrs2 = "") => content ? `<cx:${local}${attrs2}>${content}</cx:${local}>` : `<cx:${local}${attrs2}/>`;
30606
- var cxText = (local, text, attrs2 = "") => text === void 0 ? "" : `<cx:${local}${attrs2}>${escapeText2(text)}</cx:${local}>`;
31198
+ var cxElement = (local, content = "", attrs3 = "") => content ? `<cx:${local}${attrs3}>${content}</cx:${local}>` : `<cx:${local}${attrs3}/>`;
31199
+ var cxText = (local, text, attrs3 = "") => text === void 0 ? "" : `<cx:${local}${attrs3}>${escapeText2(text)}</cx:${local}>`;
30607
31200
  var cxVal = (local, value) => value === void 0 ? "" : `<cx:${local}${attributes([["val", value]])}/>`;
30608
31201
  var formulaXml = (local, formula2) => formula2 ? cxText(local, formula2.formula, attributes([["dir", formula2.direction]])) : "";
30609
31202
  var shapeXml = (context, shape) => shape ? cxElement("spPr", shapePropertiesInnerXml(context, shape)) : "";
@@ -31654,6 +32247,54 @@ async function appendChartExWorkbookData(bytes, before, after) {
31654
32247
  return { bytes: result.bytes, space: layout2.space };
31655
32248
  }
31656
32249
 
32250
+ // chart/render/chart-title-text.ts
32251
+ function chartRunStyle(run2) {
32252
+ return {
32253
+ ...run2.sizePt === void 0 ? {} : { fontSize: run2.sizePt },
32254
+ ...run2.bold === void 0 ? {} : { bold: run2.bold },
32255
+ ...run2.italic === void 0 ? {} : { italic: run2.italic },
32256
+ ...run2.underline === void 0 ? {} : { underline: run2.underline },
32257
+ ...run2.typeface === void 0 ? {} : { typeface: run2.typeface },
32258
+ ...run2.color === void 0 ? {} : { textColor: run2.color }
32259
+ };
32260
+ }
32261
+
32262
+ // chart/render/summary-ex-formatting.ts
32263
+ function textStyle(body) {
32264
+ const paragraph2 = body?.paragraphs[0];
32265
+ return {
32266
+ ...chartRunStyle(paragraph2?.defaultProperties ?? {}),
32267
+ ...chartRunStyle(paragraph2?.runs[0] ?? {})
32268
+ };
32269
+ }
32270
+ function chartExFormatting(space) {
32271
+ return {
32272
+ builtInStyle: 2,
32273
+ sourceXml: "",
32274
+ entries: {
32275
+ title: {
32276
+ fontSize: 18,
32277
+ bold: false,
32278
+ textColor: {
32279
+ kind: "scheme",
32280
+ value: "tx1",
32281
+ transforms: []
32282
+ },
32283
+ ...textStyle(space.title?.txPr),
32284
+ ...textStyle(space.title?.tx?.rich),
32285
+ ...space.title?.tx?.rich ? { textBody: space.title.tx.rich } : {},
32286
+ sourceXml: ""
32287
+ },
32288
+ legend: { fontSize: 12, ...textStyle(space.legend?.txPr), sourceXml: "" },
32289
+ categoryAxis: {
32290
+ fontSize: 10,
32291
+ ...textStyle(space.plotArea.axes.find((a2) => a2.scaling?.kind === "cat")?.txPr),
32292
+ sourceXml: ""
32293
+ }
32294
+ }
32295
+ };
32296
+ }
32297
+
31657
32298
  // chart/render/summary-ex-series.ts
31658
32299
  var level2 = (source2) => ({
31659
32300
  ...source2.visibility?.value === void 0 ? {} : { showValue: source2.visibility.value },
@@ -31666,6 +32307,7 @@ var level2 = (source2) => ({
31666
32307
  function chartExSeriesPaint(source2, series, defaultValues = false) {
31667
32308
  const fill = source2.spPr?.fill;
31668
32309
  if (fill) series.fill = fill;
32310
+ if (source2.spPr?.line) series.line = source2.spPr.line;
31669
32311
  const points = {};
31670
32312
  const fills = {};
31671
32313
  for (const point of source2.dataPoints) {
@@ -31749,34 +32391,13 @@ function chartExSummary(source2) {
31749
32391
  if (!isChartExRoot(root)) return void 0;
31750
32392
  return chartExSummaryFromModel(parseChartExSpace(root).chartExSpace);
31751
32393
  }
31752
- function chartExFormatting() {
31753
- return {
31754
- builtInStyle: 2,
31755
- sourceXml: "",
31756
- entries: {
31757
- title: {
31758
- fontSize: 14,
31759
- bold: false,
31760
- textColor: {
31761
- kind: "scheme",
31762
- value: "tx1",
31763
- transforms: [
31764
- { name: "lumMod", value: "65000" },
31765
- { name: "lumOff", value: "35000" }
31766
- ]
31767
- },
31768
- sourceXml: ""
31769
- }
31770
- }
31771
- };
31772
- }
31773
32394
  function summarySeries(space, source2, chartType) {
31774
32395
  const data = seriesData(space, source2);
31775
32396
  const categories = dimension(data, "strDim", "cat");
31776
32397
  const values = dimension(
31777
32398
  data,
31778
32399
  "numDim",
31779
- chartType === "treemap" || chartType === "sunburst" ? "size" : "val"
32400
+ chartType === "treemap" || chartType === "sunburst" ? "size" : chartType === "regionMap" ? "colorVal" : "val"
31780
32401
  );
31781
32402
  const series = {
31782
32403
  categories: categories?.points ?? [],
@@ -31785,11 +32406,24 @@ function summarySeries(space, source2, chartType) {
31785
32406
  ),
31786
32407
  ...seriesFill(source2)
31787
32408
  };
31788
- if (chartType === "funnel" || chartType === "boxWhisker") {
32409
+ if (chartType === "funnel" || chartType === "boxWhisker" || chartType === "regionMap") {
31789
32410
  chartExSeriesPaint(source2, series, chartType === "funnel" && source2.dataLabels !== void 0);
31790
32411
  if (source2.hidden !== void 0) series.hidden = source2.hidden;
31791
32412
  }
31792
32413
  if (chartType === "boxWhisker") series.boxWhisker = source2.layoutProperties ?? {};
32414
+ if (chartType === "regionMap") {
32415
+ const geo = source2.layoutProperties?.geography;
32416
+ series.regionMap = {
32417
+ ...geo,
32418
+ ...geo?.geoCacheXml ? { geographyCacheXml: geo.geoCacheXml } : {},
32419
+ ...dimension(data, "strDim", "entityId") ? { entityIds: dimension(data, "strDim", "entityId").points } : {},
32420
+ ...source2.layoutProperties?.regionLabelLayout ? {
32421
+ regionLabelLayout: source2.layoutProperties.regionLabelLayout
32422
+ } : {},
32423
+ ...source2.valueColorsXml ? { valueColorsXml: source2.valueColorsXml } : {},
32424
+ ...source2.valueColorPositionsXml ? { valueColorPositionsXml: source2.valueColorPositionsXml } : {}
32425
+ };
32426
+ }
31793
32427
  const name = source2.tx?.value?.trim();
31794
32428
  if (name) series.name = name;
31795
32429
  const nameRef = source2.tx?.formula?.formula.trim();
@@ -31802,7 +32436,7 @@ function chartExSummaryFromModel(space) {
31802
32436
  const all = space.plotArea.series;
31803
32437
  const primary = all.find((s) => s.layoutId !== "paretoLine") ?? all[0];
31804
32438
  const layoutId = primary?.layoutId ?? "";
31805
- const chartType = layoutId === "waterfall" ? "waterfall" : layoutId === "clusteredColumn" ? "histogram" : layoutId === "treemap" || layoutId === "sunburst" || layoutId === "funnel" || layoutId === "boxWhisker" ? layoutId : void 0;
32439
+ const chartType = layoutId === "waterfall" ? "waterfall" : layoutId === "clusteredColumn" ? "histogram" : layoutId === "treemap" || layoutId === "sunburst" || layoutId === "funnel" || layoutId === "boxWhisker" || layoutId === "regionMap" ? layoutId : void 0;
31806
32440
  if (!primary || !chartType) return { layoutId };
31807
32441
  const series = summarySeries(space, primary, chartType);
31808
32442
  const layout2 = primary.layoutProperties;
@@ -31840,7 +32474,12 @@ function chartExSummaryFromModel(space) {
31840
32474
  ];
31841
32475
  });
31842
32476
  }
31843
- summary.formatting = chartExFormatting();
32477
+ if (chartType === "funnel") {
32478
+ const cat = space.plotArea.axes.find((axis) => axis.scaling?.kind === "cat")?.scaling;
32479
+ if (cat?.kind === "cat" && typeof cat.gapWidth === "number")
32480
+ summary.funnelGapWidth = cat.gapWidth;
32481
+ }
32482
+ summary.formatting = chartExFormatting(space);
31844
32483
  const title = titleOf(space);
31845
32484
  if (title) summary.title = title;
31846
32485
  const position2 = legend?.position;
@@ -32037,11 +32676,11 @@ function warningsFor(document) {
32037
32676
  ],
32038
32677
  [
32039
32678
  ["rPrChange"],
32040
- "Formatting-change revisions retain their prior run-properties snapshots and support acceptance and rejection; recording new formatting changes and showing prior formatting in Original display are not supported yet."
32679
+ "Formatting-change revisions retain their prior run-properties snapshots and support acceptance, rejection and Original display; supported run-formatting changes are recorded as new revisions, other formatting edits are not."
32041
32680
  ],
32042
32681
  [
32043
32682
  ["pPrChange"],
32044
- "Paragraph-formatting-change revisions retain their prior properties snapshots and support acceptance and rejection; recording new paragraph formatting changes and showing prior formatting in Original display are not supported yet."
32683
+ "Paragraph-formatting-change revisions retain their prior properties snapshots and support acceptance, rejection and Original display; pure paragraph-formatting changes are recorded as new revisions, and revised paragraph-mark merging is not shown yet."
32045
32684
  ],
32046
32685
  [
32047
32686
  ["ffData"],
@@ -32336,6 +32975,7 @@ function parseModernDrawing(node, context) {
32336
32975
  if (picture)
32337
32976
  return {
32338
32977
  ...picture,
32978
+ ...blip?.parentNode ? { pictureFill: parseDrawingPictureFill(blip.parentNode) } : {},
32339
32979
  widthPx,
32340
32980
  heightPx,
32341
32981
  ...definedProps({ altText, title, anchored }),
@@ -32439,7 +33079,7 @@ var add3 = (parent, ...items) => {
32439
33079
  };
32440
33080
  var emu3 = (px2) => String(Math.max(1, Math.round(px2 * EMU_PER_PIXEL)));
32441
33081
  var emuOffset = (px2) => String(Math.round(px2 * EMU_PER_PIXEL));
32442
- var attrs = (element4, values) => {
33082
+ var attrs2 = (element4, values) => {
32443
33083
  for (const [name, value] of Object.entries(values)) element4.setAttribute(name, value);
32444
33084
  return element4;
32445
33085
  };
@@ -32492,9 +33132,9 @@ function textParagraphs(doc, lines2, color) {
32492
33132
  }
32493
33133
  function shapeStyle(doc) {
32494
33134
  const ref = (name, idx, scheme2, shade) => {
32495
- const node = attrs(el2(doc, A_NS2, `a:${name}`), { idx });
32496
- const color = attrs(el2(doc, A_NS2, "a:schemeClr"), { val: scheme2 });
32497
- if (shade) add3(color, attrs(el2(doc, A_NS2, "a:shade"), { val: shade }));
33135
+ const node = attrs2(el2(doc, A_NS2, `a:${name}`), { idx });
33136
+ const color = attrs2(el2(doc, A_NS2, "a:schemeClr"), { val: scheme2 });
33137
+ if (shade) add3(color, attrs2(el2(doc, A_NS2, "a:shade"), { val: shade }));
32498
33138
  return add3(node, color);
32499
33139
  };
32500
33140
  return add3(
@@ -32508,17 +33148,17 @@ function shapeStyle(doc) {
32508
33148
  function wrapElement(doc, placement) {
32509
33149
  switch (placement.wrap) {
32510
33150
  case "square":
32511
- return attrs(el2(doc, WP_NS3, "wp:wrapSquare"), { wrapText: "bothSides" });
33151
+ return attrs2(el2(doc, WP_NS3, "wp:wrapSquare"), { wrapText: "bothSides" });
32512
33152
  case "tight":
32513
33153
  case "through": {
32514
- const wrap2 = attrs(
33154
+ const wrap2 = attrs2(
32515
33155
  el2(doc, WP_NS3, `wp:wrap${placement.wrap === "tight" ? "Tight" : "Through"}`),
32516
33156
  {
32517
33157
  wrapText: "bothSides"
32518
33158
  }
32519
33159
  );
32520
- const polygon = attrs(el2(doc, WP_NS3, "wp:wrapPolygon"), { edited: "0" });
32521
- const point = (name, x, y) => attrs(el2(doc, WP_NS3, `wp:${name}`), { x, y });
33160
+ const polygon = attrs2(el2(doc, WP_NS3, "wp:wrapPolygon"), { edited: "0" });
33161
+ const point = (name, x, y) => attrs2(el2(doc, WP_NS3, `wp:${name}`), { x, y });
32522
33162
  return add3(
32523
33163
  wrap2,
32524
33164
  add3(
@@ -32538,7 +33178,7 @@ function wrapElement(doc, placement) {
32538
33178
  }
32539
33179
  }
32540
33180
  function position(doc, axis, relativeFrom, align, offsetPx) {
32541
- const node = attrs(el2(doc, WP_NS3, `wp:position${axis}`), { relativeFrom });
33181
+ const node = attrs2(el2(doc, WP_NS3, `wp:position${axis}`), { relativeFrom });
32542
33182
  if (align) {
32543
33183
  const a2 = el2(doc, WP_NS3, "wp:align");
32544
33184
  a2.textContent = align;
@@ -32549,10 +33189,10 @@ function position(doc, axis, relativeFrom, align, offsetPx) {
32549
33189
  return add3(node, offset);
32550
33190
  }
32551
33191
  function geometry(doc, spec) {
32552
- const prst = attrs(el2(doc, A_NS2, "a:prstGeom"), { prst: spec.preset });
33192
+ const prst = attrs2(el2(doc, A_NS2, "a:prstGeom"), { prst: spec.preset });
32553
33193
  const avLst = el2(doc, A_NS2, "a:avLst");
32554
33194
  for (const [name, value] of Object.entries(spec.adjustments ?? {}))
32555
- add3(avLst, attrs(el2(doc, A_NS2, "a:gd"), { name, fmla: `val ${Math.round(value)}` }));
33195
+ add3(avLst, attrs2(el2(doc, A_NS2, "a:gd"), { name, fmla: `val ${Math.round(value)}` }));
32556
33196
  const nodes = spec.customGeometryXml ? importFragment(doc, spec.customGeometryXml) : [add3(prst, avLst)];
32557
33197
  if (spec.fill) {
32558
33198
  const xml = drawingFillXml(spec.fill);
@@ -32568,7 +33208,7 @@ function buildShapeDrawing(doc, image, identity, relativeHeight = 251658240) {
32568
33208
  const anchored = Boolean(image.anchored);
32569
33209
  const holder = el2(doc, WP_NS3, anchored ? "wp:anchor" : "wp:inline");
32570
33210
  if (anchored) {
32571
- attrs(holder, {
33211
+ attrs2(holder, {
32572
33212
  distT: "0",
32573
33213
  distB: "0",
32574
33214
  distL: "114300",
@@ -32582,7 +33222,7 @@ function buildShapeDrawing(doc, image, identity, relativeHeight = 251658240) {
32582
33222
  });
32583
33223
  add3(
32584
33224
  holder,
32585
- attrs(el2(doc, WP_NS3, "wp:simplePos"), { x: "0", y: "0" }),
33225
+ attrs2(el2(doc, WP_NS3, "wp:simplePos"), { x: "0", y: "0" }),
32586
33226
  position(
32587
33227
  doc,
32588
33228
  "H",
@@ -32601,24 +33241,24 @@ function buildShapeDrawing(doc, image, identity, relativeHeight = 251658240) {
32601
33241
  } else for (const side of ["distT", "distB", "distL", "distR"]) holder.setAttribute(side, "0");
32602
33242
  add3(
32603
33243
  holder,
32604
- attrs(el2(doc, WP_NS3, "wp:extent"), { cx: emu3(image.widthPx), cy: emu3(image.heightPx) }),
32605
- attrs(el2(doc, WP_NS3, "wp:effectExtent"), { l: "0", t: "0", r: "0", b: "0" })
33244
+ attrs2(el2(doc, WP_NS3, "wp:extent"), { cx: emu3(image.widthPx), cy: emu3(image.heightPx) }),
33245
+ attrs2(el2(doc, WP_NS3, "wp:effectExtent"), { l: "0", t: "0", r: "0", b: "0" })
32606
33246
  );
32607
33247
  if (anchored) add3(holder, wrapElement(doc, placement ?? { wrap: "none" }));
32608
- const docPr = attrs(el2(doc, WP_NS3, "wp:docPr"), {
33248
+ const docPr = attrs2(el2(doc, WP_NS3, "wp:docPr"), {
32609
33249
  id: identity.id,
32610
33250
  name: identity.name ?? `Shape ${identity.id}`
32611
33251
  });
32612
33252
  if (identity.descr) docPr.setAttribute("descr", identity.descr);
32613
33253
  if (identity.title) docPr.setAttribute("title", identity.title);
32614
- const xfrm = attrs(el2(doc, A_NS2, "a:xfrm"), {});
33254
+ const xfrm = attrs2(el2(doc, A_NS2, "a:xfrm"), {});
32615
33255
  if (spec.rotation) xfrm.setAttribute("rot", String(Math.round(spec.rotation * 6e4)));
32616
33256
  if (spec.flipH) xfrm.setAttribute("flipH", "1");
32617
33257
  if (spec.flipV) xfrm.setAttribute("flipV", "1");
32618
33258
  add3(
32619
33259
  xfrm,
32620
- attrs(el2(doc, A_NS2, "a:off"), { x: "0", y: "0" }),
32621
- attrs(el2(doc, A_NS2, "a:ext"), { cx: emu3(image.widthPx), cy: emu3(image.heightPx) })
33260
+ attrs2(el2(doc, A_NS2, "a:off"), { x: "0", y: "0" }),
33261
+ attrs2(el2(doc, A_NS2, "a:ext"), { cx: emu3(image.widthPx), cy: emu3(image.heightPx) })
32622
33262
  );
32623
33263
  const spPr = add3(el2(doc, WPS_NS2, "wps:spPr"), xfrm, ...geometry(doc, spec));
32624
33264
  const wsp = add3(
@@ -32634,7 +33274,7 @@ function buildShapeDrawing(doc, image, identity, relativeHeight = 251658240) {
32634
33274
  );
32635
33275
  add3(wsp, add3(el2(doc, WPS_NS2, "wps:txbx"), content));
32636
33276
  }
32637
- const body = attrs(el2(doc, WPS_NS2, "wps:bodyPr"), {
33277
+ const body = attrs2(el2(doc, WPS_NS2, "wps:bodyPr"), {
32638
33278
  rot: "0",
32639
33279
  vert: "horz",
32640
33280
  wrap: "square",
@@ -32646,7 +33286,7 @@ function buildShapeDrawing(doc, image, identity, relativeHeight = 251658240) {
32646
33286
  anchorCtr: "0"
32647
33287
  });
32648
33288
  add3(wsp, add3(body, el2(doc, A_NS2, "a:noAutofit")));
32649
- const graphicData = attrs(el2(doc, A_NS2, "a:graphicData"), { uri: WPS_NS2 });
33289
+ const graphicData = attrs2(el2(doc, A_NS2, "a:graphicData"), { uri: WPS_NS2 });
32650
33290
  add3(
32651
33291
  holder,
32652
33292
  docPr,
@@ -32762,9 +33402,9 @@ function clearNonProperties(node, keep) {
32762
33402
  var A_NS5 = "http://schemas.openxmlformats.org/drawingml/2006/main";
32763
33403
  var WP_NS5 = "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing";
32764
33404
  var C_NS = "http://schemas.openxmlformats.org/drawingml/2006/chart";
32765
- function child7(parent, ns, name, attrs2 = {}) {
33405
+ function child7(parent, ns, name, attrs3 = {}) {
32766
33406
  const node = makeNS(parent.ownerDocument, ns, name);
32767
- for (const [key, value] of Object.entries(attrs2)) node.setAttribute(key, value);
33407
+ for (const [key, value] of Object.entries(attrs3)) node.setAttribute(key, value);
32768
33408
  parent.appendChild(node);
32769
33409
  return node;
32770
33410
  }
@@ -33248,6 +33888,19 @@ async function applyDiagramEdits(zip, blocks, baseBlocks, pendingMedia) {
33248
33888
  ...relaid && layoutId ? { layout: { uniqueId: layoutId, category: diagram.layout?.family } } : {}
33249
33889
  })
33250
33890
  );
33891
+ if (diagram.layoutSource?.pictures?.length) {
33892
+ zip.file(
33893
+ partName,
33894
+ withDiagramPictureSources(await zip.file(partName).async("string"), diagram.layoutSource)
33895
+ );
33896
+ const relsName = relationshipsPartFor2(partName);
33897
+ const rels = diagramPictureRelationships(
33898
+ partName,
33899
+ diagram.layoutSource,
33900
+ await zip.file(relsName)?.async("string")
33901
+ );
33902
+ if (rels) zip.file(relsName, rels);
33903
+ }
33251
33904
  if (drawing) await dropDrawingPart(zip, drawing.relId, drawing.partName, drawing.ownerPart);
33252
33905
  }
33253
33906
  }
@@ -33260,9 +33913,9 @@ var EMU_PER_PIXEL2 = 9525;
33260
33913
  function isSameDiagram(base, next) {
33261
33914
  return Boolean(base?.parts.data?.partName) && base?.parts.data?.partName === next.parts.data?.partName && !next.inserted;
33262
33915
  }
33263
- function el3(doc, ns, qualified, attrs2 = {}) {
33916
+ function el3(doc, ns, qualified, attrs3 = {}) {
33264
33917
  const node = makeNS(doc, ns, qualified);
33265
- for (const [name, value] of Object.entries(attrs2)) node.setAttribute(name, value);
33918
+ for (const [name, value] of Object.entries(attrs3)) node.setAttribute(name, value);
33266
33919
  return node;
33267
33920
  }
33268
33921
  function buildInsertedDiagramDrawing(doc, diagram, widthPx, heightPx, allocator) {
@@ -33412,6 +34065,9 @@ function buildInlineDrawing(doc, image, relId, docPrId, svgRelId) {
33412
34065
  stretch.appendChild(el4(doc, A_NS7, "a:fillRect"));
33413
34066
  const blipFill = el4(doc, PIC_NS, "pic:blipFill");
33414
34067
  appendAll(blipFill, blip, stretch);
34068
+ if (image.pictureFill?.crop) applyPictureCrop(blipFill, image.pictureFill.crop);
34069
+ if (image.pictureFill?.effects) applyPictureEffects(blip, image.pictureFill.effects);
34070
+ if (image.pictureFill?.layout) applyPictureLayout(blipFill, image.pictureFill.layout);
33415
34071
  const xfrm = el4(doc, A_NS7, "a:xfrm");
33416
34072
  const off = el4(doc, A_NS7, "a:off");
33417
34073
  off.setAttribute("x", "0");
@@ -33498,6 +34154,16 @@ function createImageRun(doc, image, base, old, allocator) {
33498
34154
  return node;
33499
34155
  }
33500
34156
  if (base && oldDrawing && sameUnderlyingImage(base, image)) {
34157
+ if (image.pictureFill && JSON.stringify(image.pictureFill) !== JSON.stringify(base.pictureFill)) {
34158
+ const fill = oldDrawing.getElementsByTagNameNS(PIC_NS, "blipFill")[0];
34159
+ const blip = fill?.getElementsByTagNameNS(A_NS7, "blip")[0];
34160
+ if (fill && image.pictureFill.crop !== void 0)
34161
+ applyPictureCrop(fill, image.pictureFill.crop);
34162
+ if (blip && image.pictureFill.effects !== void 0)
34163
+ applyPictureEffects(blip, image.pictureFill.effects);
34164
+ if (fill && image.pictureFill.layout !== void 0)
34165
+ applyPictureLayout(fill, image.pictureFill.layout);
34166
+ }
33501
34167
  if (image.widthPx !== base.widthPx || image.heightPx !== base.heightPx)
33502
34168
  updateExtent(oldDrawing, image.widthPx, image.heightPx);
33503
34169
  if (image.altText !== base.altText || image.title !== base.title)
@@ -37586,6 +38252,7 @@ async function applyGeneratedDiagramCaches(zip, blocks, baseBlocks, theme) {
37586
38252
  const colorsXml = await read("colors");
37587
38253
  const quickStyleXml = await read("quickStyle");
37588
38254
  const source2 = {
38255
+ ...diagram.layoutSource,
37589
38256
  ...layoutXml3 ? { layoutXml: layoutXml3 } : {},
37590
38257
  ...colorsXml ? { colorsXml } : {},
37591
38258
  ...quickStyleXml ? { quickStyleXml } : {}
@@ -37610,6 +38277,8 @@ async function applyGeneratedDiagramCaches(zip, blocks, baseBlocks, theme) {
37610
38277
  );
37611
38278
  zip.file(name, withDiagramDrawingRelationship(cache.dataXml, relationship2));
37612
38279
  zip.file(drawingName, cache.drawingXml);
38280
+ const pictureRels = diagramPictureRelationships(drawingName, diagram.layoutSource);
38281
+ if (pictureRels) zip.file(drawingName.replace(/([^/]+)$/, "_rels/$1.rels"), pictureRels);
37613
38282
  await ensureContentTypeOverride(zip, drawingName, DIAGRAM_CONTENT_TYPES.drawing);
37614
38283
  }
37615
38284
  }
@@ -39009,7 +39678,8 @@ async function readPackage(input) {
39009
39678
  for (const part of [
39010
39679
  run2.image?.partName,
39011
39680
  run2.image?.svgPartName,
39012
- ...Object.values(run2.image?.diagram?.drawing?.pictureParts ?? {})
39681
+ ...Object.values(run2.image?.diagram?.drawing?.pictureParts ?? {}),
39682
+ ...Object.values(run2.image?.diagram?.layoutSource?.pictureParts ?? {})
39013
39683
  ])
39014
39684
  if (part) imagePartNames.add(part);
39015
39685
  });