@officedk/pptxdk 0.1.0 → 0.2.1

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 (338) hide show
  1. package/dist/build.d.ts +14 -76
  2. package/dist/build.js +69 -97
  3. package/dist/cli.js +1 -1
  4. package/dist/core/dist/capabilities/audio/audio-declaration.js +7 -0
  5. package/dist/core/dist/capabilities/audio/audio-source.js +172 -0
  6. package/dist/core/dist/capabilities/audio/entry.js +122 -0
  7. package/dist/core/dist/capabilities/box/box-codegen.js +83 -0
  8. package/dist/core/dist/capabilities/box/box-declaration.js +32 -0
  9. package/dist/{capabilities/dist → core/dist/capabilities}/box/box.js +32 -29
  10. package/dist/core/dist/capabilities/box/entry.js +2 -0
  11. package/dist/{capabilities/dist → core/dist/capabilities}/chart/chart-codegen.js +17 -22
  12. package/dist/{capabilities/dist → core/dist/capabilities}/chart/chart-declaration.js +2 -2
  13. package/dist/{capabilities/dist → core/dist/capabilities}/chart/chart-import.js +1025 -471
  14. package/dist/{capabilities/dist → core/dist/capabilities}/chart/chart-labels.js +30 -3
  15. package/dist/{capabilities/dist → core/dist/capabilities}/chart/chart-model.js +3 -3
  16. package/dist/{capabilities/dist/chart/preview/number-format.js → core/dist/capabilities/chart/chart-number-format.js} +1 -1
  17. package/dist/{capabilities/dist → core/dist/capabilities}/chart/chart-schemas.js +216 -212
  18. package/dist/{capabilities/dist → core/dist/capabilities}/chart/chart-xml.js +41 -36
  19. package/dist/{capabilities/dist → core/dist/capabilities}/chart/chart.js +228 -171
  20. package/dist/core/dist/capabilities/chart/entry.js +2 -0
  21. package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/axes-and-grid.js +23 -10
  22. package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/bar-column.js +1 -1
  23. package/dist/core/dist/capabilities/chart/preview/data-labels.js +474 -0
  24. package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/error-bars.js +3 -1
  25. package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/index.js +30 -9
  26. package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/layout.js +160 -89
  27. package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/legend.js +4 -4
  28. package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/line-area.js +4 -4
  29. package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/markers.js +1 -1
  30. package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/pie-doughnut.js +39 -60
  31. package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/scales.js +1 -1
  32. package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/scatter.js +3 -3
  33. package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/style.js +15 -3
  34. package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/text-render.js +34 -24
  35. package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/trendlines.js +5 -5
  36. package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/types.js +1 -1
  37. package/dist/core/dist/capabilities/comment/comment-codegen.js +25 -0
  38. package/dist/core/dist/capabilities/comment/comment-declaration.js +37 -0
  39. package/dist/core/dist/capabilities/comment/comment-import.js +176 -0
  40. package/dist/core/dist/capabilities/comment/comment.js +141 -0
  41. package/dist/core/dist/capabilities/comment/entry.js +1 -0
  42. package/dist/core/dist/capabilities/footer-placeholder/entry.js +2 -0
  43. package/dist/core/dist/capabilities/footer-placeholder/footer-placeholder-codegen.js +16 -0
  44. package/dist/{capabilities/dist/masters → core/dist/capabilities/footer-placeholder}/footer-placeholder.js +194 -133
  45. package/dist/core/dist/capabilities/footer-placeholder/print-header-footer-import.js +121 -0
  46. package/dist/core/dist/capabilities/footer-placeholder/print-header-footer.js +123 -0
  47. package/dist/core/dist/capabilities/group/entry.js +2 -0
  48. package/dist/core/dist/capabilities/group/group-codegen.js +73 -0
  49. package/dist/core/dist/capabilities/group/group-declaration.js +41 -0
  50. package/dist/core/dist/capabilities/group/group-import.js +608 -0
  51. package/dist/{capabilities/dist → core/dist/capabilities}/group/group-xml.js +4 -3
  52. package/dist/core/dist/capabilities/group/group.js +260 -0
  53. package/dist/core/dist/capabilities/image/entry.js +4 -0
  54. package/dist/core/dist/capabilities/image/image-codegen.js +59 -0
  55. package/dist/core/dist/capabilities/image/image-declaration.js +8 -0
  56. package/dist/core/dist/capabilities/image/image-import.js +26 -0
  57. package/dist/core/dist/capabilities/image/image.js +57 -0
  58. package/dist/core/dist/capabilities/line/entry.js +3 -0
  59. package/dist/core/dist/capabilities/line/line-codegen.js +88 -0
  60. package/dist/core/dist/capabilities/line/line-declaration.js +78 -0
  61. package/dist/core/dist/capabilities/line/line-import.js +424 -0
  62. package/dist/core/dist/capabilities/line/line-xml.js +9 -0
  63. package/dist/core/dist/capabilities/line/line.js +329 -0
  64. package/dist/core/dist/capabilities/masters/entry.js +1 -0
  65. package/dist/core/dist/capabilities/masters/masters-codegen.js +50 -0
  66. package/dist/{capabilities/dist → core/dist/capabilities}/masters/masters.js +35 -47
  67. package/dist/core/dist/capabilities/motion/entry.js +5 -0
  68. package/dist/{capabilities/dist → core/dist/capabilities}/motion/motion-codegen.js +97 -51
  69. package/dist/{capabilities/dist → core/dist/capabilities}/motion/motion-import.js +653 -102
  70. package/dist/{capabilities/dist → core/dist/capabilities}/motion/motion-plan.js +317 -163
  71. package/dist/{capabilities/dist → core/dist/capabilities}/motion/motion-query.js +9 -6
  72. package/dist/{capabilities/dist → core/dist/capabilities}/motion/motion.js +357 -108
  73. package/dist/core/dist/capabilities/notes/entry.js +2 -0
  74. package/dist/{capabilities/dist → core/dist/capabilities}/notes/notes-codegen.js +5 -7
  75. package/dist/{capabilities/dist → core/dist/capabilities}/notes/notes-declaration.js +2 -2
  76. package/dist/{capabilities/dist → core/dist/capabilities}/notes/notes-import.js +16 -13
  77. package/dist/{capabilities/dist → core/dist/capabilities}/notes/notes-schemas.js +12 -9
  78. package/dist/{capabilities/dist → core/dist/capabilities}/notes/notes.js +20 -42
  79. package/dist/{import/dist/sections.js → core/dist/capabilities/notes/sections-import.js} +5 -5
  80. package/dist/core/dist/capabilities/placeholder/entry.js +3 -0
  81. package/dist/core/dist/capabilities/placeholder/placeholder-codegen.js +44 -0
  82. package/dist/core/dist/capabilities/placeholder/placeholder-schemas.js +31 -0
  83. package/dist/core/dist/capabilities/placeholder/placeholder.js +394 -0
  84. package/dist/core/dist/capabilities/shape/entry.js +6 -0
  85. package/dist/core/dist/capabilities/shape/shape-codegen.js +112 -0
  86. package/dist/core/dist/capabilities/shape/shape-import.js +152 -0
  87. package/dist/{capabilities/dist → core/dist/capabilities}/shape/shape-xml.js +1 -1
  88. package/dist/{capabilities/dist → core/dist/capabilities}/shape/shape.js +100 -103
  89. package/dist/core/dist/capabilities/shared/container-slots.js +59 -0
  90. package/dist/core/dist/capabilities/shared/date-time.js +98 -0
  91. package/dist/core/dist/capabilities/shared/font/font-embedding.js +118 -0
  92. package/dist/core/dist/capabilities/shared/font/font-engine.js +855 -0
  93. package/dist/core/dist/capabilities/shared/font/font-import.js +805 -0
  94. package/dist/{capabilities/dist → core/dist/capabilities/shared}/font/font-subset.js +24 -9
  95. package/dist/core/dist/capabilities/shared/font/font.js +72 -0
  96. package/dist/{capabilities/dist/shape/shape-codegen.js → core/dist/capabilities/shared/geometry-codegen.js} +4 -69
  97. package/dist/{capabilities/dist → core/dist/capabilities}/shared/geometry.js +384 -123
  98. package/dist/{capabilities/dist → core/dist/capabilities}/shared/identity.js +56 -38
  99. package/dist/core/dist/capabilities/shared/image-codegen.js +94 -0
  100. package/dist/{capabilities/dist/image → core/dist/capabilities/shared}/image-decode.js +17 -56
  101. package/dist/{capabilities/dist/image → core/dist/capabilities/shared}/image-schemas.js +49 -61
  102. package/dist/core/dist/capabilities/shared/line-match.js +78 -0
  103. package/dist/core/dist/capabilities/shared/media-codegen.js +86 -0
  104. package/dist/core/dist/capabilities/shared/media-import.js +156 -0
  105. package/dist/core/dist/capabilities/shared/media-placement.js +20 -0
  106. package/dist/core/dist/capabilities/shared/media-poster.js +50 -0
  107. package/dist/core/dist/capabilities/shared/media-schemas.js +60 -0
  108. package/dist/core/dist/capabilities/shared/media-source.js +107 -0
  109. package/dist/core/dist/capabilities/shared/media-trim.js +102 -0
  110. package/dist/core/dist/capabilities/shared/media.js +134 -0
  111. package/dist/{capabilities/dist → core/dist/capabilities}/shared/morph-api.js +5 -5
  112. package/dist/core/dist/capabilities/shared/motion-api.js +770 -0
  113. package/dist/core/dist/capabilities/shared/motion-schemas.js +353 -0
  114. package/dist/{capabilities/dist/image/image-import.js → core/dist/capabilities/shared/picture-import.js} +313 -168
  115. package/dist/core/dist/capabilities/shared/picture-xml.js +13 -0
  116. package/dist/core/dist/capabilities/shared/picture.js +510 -0
  117. package/dist/core/dist/capabilities/shared/placeholder-import.js +268 -0
  118. package/dist/core/dist/capabilities/shared/placeholder-roles.js +42 -0
  119. package/dist/{capabilities/dist → core/dist/capabilities}/shared/preset-definitions.js +1221 -188
  120. package/dist/core/dist/capabilities/shared/print-xml.js +77 -0
  121. package/dist/core/dist/capabilities/shared/rich-text-codegen.js +119 -0
  122. package/dist/core/dist/capabilities/shared/rich-text-import.js +472 -0
  123. package/dist/core/dist/capabilities/shared/shape-declaration.js +45 -0
  124. package/dist/{capabilities/dist → core/dist/capabilities}/shared/style-inheritance.js +26 -24
  125. package/dist/core/dist/capabilities/shared/text-declaration.js +31 -0
  126. package/dist/core/dist/capabilities/shared/text-schemas.js +241 -0
  127. package/dist/core/dist/capabilities/shared/text-service.js +2563 -0
  128. package/dist/{capabilities/dist → core/dist/capabilities}/shared/visual.js +441 -137
  129. package/dist/core/dist/capabilities/slide-background/entry.js +1 -0
  130. package/dist/core/dist/capabilities/slide-background/slide-background-codegen.js +15 -0
  131. package/dist/{capabilities/dist → core/dist/capabilities}/slide-background/slide-background-import.js +12 -7
  132. package/dist/core/dist/capabilities/slide-background/slide-background-xml.js +33 -0
  133. package/dist/{capabilities/dist → core/dist/capabilities}/slide-background/slide-background.js +61 -50
  134. package/dist/core/dist/capabilities/table/entry.js +2 -0
  135. package/dist/core/dist/capabilities/table/table-codegen.js +118 -0
  136. package/dist/{capabilities/dist → core/dist/capabilities}/table/table-declaration.js +2 -2
  137. package/dist/{capabilities/dist → core/dist/capabilities}/table/table-import.js +116 -84
  138. package/dist/core/dist/capabilities/table/table-schemas.js +337 -0
  139. package/dist/{capabilities/dist → core/dist/capabilities}/table/table-xml.js +13 -15
  140. package/dist/{capabilities/dist → core/dist/capabilities}/table/table.js +284 -192
  141. package/dist/core/dist/capabilities/text/entry.js +3 -0
  142. package/dist/core/dist/capabilities/text/text-codegen.js +66 -0
  143. package/dist/core/dist/capabilities/text/text-import.js +468 -0
  144. package/dist/{capabilities/dist → core/dist/capabilities}/text/text-xml.js +3 -4
  145. package/dist/{capabilities/dist → core/dist/capabilities}/text/text.js +103 -111
  146. package/dist/core/dist/capabilities/transition/entry.js +3 -0
  147. package/dist/{capabilities/dist → core/dist/capabilities}/transition/transition-api.js +13 -16
  148. package/dist/{capabilities/dist → core/dist/capabilities}/transition/transition-codegen.js +2 -3
  149. package/dist/{capabilities/dist → core/dist/capabilities}/transition/transition-import.js +25 -27
  150. package/dist/{capabilities/dist → core/dist/capabilities}/transition/transition.js +23 -23
  151. package/dist/core/dist/capabilities/video/entry.js +77 -0
  152. package/dist/core/dist/capabilities/video/video-declaration.js +7 -0
  153. package/dist/core/dist/capabilities/video/video-source.js +42 -0
  154. package/dist/{codegen/dist → core/dist/codegen}/assets.js +16 -10
  155. package/dist/{codegen/dist → core/dist/codegen}/codegen.js +152 -140
  156. package/dist/{codegen/dist → core/dist/codegen}/identifiers.js +27 -1
  157. package/dist/{codegen/dist → core/dist/codegen}/index.js +2 -2
  158. package/dist/{codegen/dist → core/dist/codegen}/printer.js +23 -4
  159. package/dist/core/dist/document/all.js +41 -0
  160. package/dist/core/dist/document/default.js +10 -0
  161. package/dist/core/dist/document/document.js +218 -0
  162. package/dist/core/dist/document/index.js +62 -0
  163. package/dist/core/dist/document/stages.js +54 -0
  164. package/dist/{emit/dist → core/dist/emit}/emit.js +173 -90
  165. package/dist/core/dist/emit/index.js +6 -0
  166. package/dist/core/dist/emit/ooxml.js +241 -0
  167. package/dist/core/dist/import/import.js +547 -0
  168. package/dist/core/dist/import/index.js +19 -0
  169. package/dist/{import/dist → core/dist/import}/masters.js +404 -328
  170. package/dist/core/dist/import/media-timing.js +233 -0
  171. package/dist/{import/dist → core/dist/import}/notes-masters.js +48 -45
  172. package/dist/core/dist/index.js +47 -15
  173. package/dist/core/dist/{author-ids.js → kernel/author-ids.js} +9 -6
  174. package/dist/core/dist/{author-schemas.js → kernel/author-schemas.js} +105 -127
  175. package/dist/core/dist/{block-flex-layout.js → kernel/block-flex-layout.js} +225 -142
  176. package/dist/core/dist/kernel/build.js +4 -0
  177. package/dist/core/dist/kernel/capability.js +17 -0
  178. package/dist/core/dist/kernel/codegen.js +97 -0
  179. package/dist/core/dist/kernel/container-slots.js +104 -0
  180. package/dist/core/dist/kernel/date-time-format.js +18 -0
  181. package/dist/core/dist/kernel/declaration-snapshot.js +68 -0
  182. package/dist/core/dist/{declaration.js → kernel/declaration.js} +3 -2
  183. package/dist/core/dist/kernel/diagnostics.js +370 -0
  184. package/dist/core/dist/kernel/document-internals.js +26 -0
  185. package/dist/core/dist/{document.js → kernel/document.js} +23 -13
  186. package/dist/core/dist/kernel/drawing-units.js +14 -0
  187. package/dist/core/dist/kernel/font-seal.js +204 -0
  188. package/dist/core/dist/{geometry-schemas.js → kernel/geometry-schemas.js} +21 -18
  189. package/dist/core/dist/{grid-layout.js → kernel/grid-layout.js} +177 -72
  190. package/dist/core/dist/{host.js → kernel/host.js} +1 -1
  191. package/dist/core/dist/kernel/index.js +24 -0
  192. package/dist/core/dist/kernel/input-values.js +62 -0
  193. package/dist/core/dist/kernel/layout-definition.js +7 -0
  194. package/dist/core/dist/{layout-protocol.js → kernel/layout-protocol.js} +5 -10
  195. package/dist/core/dist/{layout-schemas.js → kernel/layout-schemas.js} +33 -44
  196. package/dist/core/dist/kernel/layout.js +339 -0
  197. package/dist/core/dist/kernel/masters.js +171 -0
  198. package/dist/core/dist/{morph.js → kernel/morph.js} +1 -1
  199. package/dist/core/dist/kernel/placeholders.js +289 -0
  200. package/dist/{import/dist → core/dist/kernel/pptx-read}/alternate-content.js +1 -1
  201. package/dist/{import/dist → core/dist/kernel/pptx-read}/diagnostics.js +33 -29
  202. package/dist/core/dist/kernel/pptx-read/drawing-list-import.js +251 -0
  203. package/dist/{import/dist → core/dist/kernel/pptx-read}/fonts.js +71 -12
  204. package/dist/core/dist/kernel/pptx-read/index.js +15 -0
  205. package/dist/{import/dist → core/dist/kernel/pptx-read}/mechanism.js +1 -1
  206. package/dist/core/dist/kernel/pptx-read/media.js +26 -0
  207. package/dist/{import/dist → core/dist/kernel/pptx-read}/namespaces.js +6 -7
  208. package/dist/{import/dist → core/dist/kernel/pptx-read}/opc.js +62 -13
  209. package/dist/{import/dist → core/dist/kernel/pptx-read}/resources.js +1 -1
  210. package/dist/core/dist/kernel/pptx-read/shape-tree.js +57 -0
  211. package/dist/{import/dist → core/dist/kernel/pptx-read}/themes.js +182 -41
  212. package/dist/{import/dist → core/dist/kernel/pptx-read}/visual.js +175 -88
  213. package/dist/core/dist/kernel/pptx-read/xml-fragments.js +320 -0
  214. package/dist/{import/dist → core/dist/kernel/pptx-read}/xml-reader.js +8 -1
  215. package/dist/{emit/dist → core/dist/kernel/pptx-write}/shape-tree.js +1 -1
  216. package/dist/core/dist/kernel/pptx-write/timing.js +52 -0
  217. package/dist/{emit/dist/ooxml.js → core/dist/kernel/pptx-write/xml.js} +133 -290
  218. package/dist/core/dist/{query.js → kernel/query.js} +76 -37
  219. package/dist/core/dist/{resolution.js → kernel/resolution.js} +2 -1
  220. package/dist/core/dist/kernel/resolve-work.js +58 -0
  221. package/dist/core/dist/{resolve.js → kernel/resolve.js} +797 -409
  222. package/dist/core/dist/kernel/resource-source.js +11 -0
  223. package/dist/core/dist/kernel/stage-options.js +312 -0
  224. package/dist/core/dist/{theme.js → kernel/theme.js} +399 -289
  225. package/dist/core/dist/kernel/transform-geometry.js +72 -0
  226. package/dist/core/dist/kernel/xml-values.js +13 -0
  227. package/dist/document-C0lPlH-L.d.ts +1442 -0
  228. package/dist/index-B9_OUeA-.d.ts +2238 -0
  229. package/dist/index-BJEzQxWV.d.ts +75 -0
  230. package/dist/index-DA9flrlR.d.ts +146 -0
  231. package/dist/index-GSt0t9VO.d.ts +54 -0
  232. package/dist/index.d.ts +7 -7
  233. package/dist/index.js +75 -61
  234. package/dist/node.d.ts +37 -35
  235. package/dist/node.js +125 -51
  236. package/dist/pptxdk/src/cli-commands.js +79 -81
  237. package/dist/pptxdk/src/compose.js +32 -24
  238. package/dist/pptxdk/src/preview-result.js +24 -0
  239. package/dist/{capabilities/dist/image → preview/dist}/gif-decoder.js +5 -5
  240. package/dist/preview/dist/index.js +229 -77
  241. package/dist/preview/dist/options.js +17 -26
  242. package/dist/preview/dist/raster.js +66 -0
  243. package/dist/preview/dist/svg-guard.js +1090 -0
  244. package/dist/preview.d.ts +6 -3
  245. package/dist/preview.js +8 -24
  246. package/dist/react/dist/append.js +3 -3
  247. package/dist/react/dist/author/audio-elements.js +14 -0
  248. package/dist/{capabilities/dist/box → react/dist/author}/box-elements.js +5 -3
  249. package/dist/react/dist/author/chart-elements.js +14 -0
  250. package/dist/react/dist/author/comment-elements.js +15 -0
  251. package/dist/react/dist/author/group-elements.js +14 -0
  252. package/dist/react/dist/author/image-elements.js +14 -0
  253. package/dist/react/dist/author/line-elements.js +14 -0
  254. package/dist/{capabilities/dist/motion → react/dist/author}/motion-elements.js +6 -4
  255. package/dist/react/dist/author/notes-elements.js +14 -0
  256. package/dist/react/dist/author/placeholder-elements.js +14 -0
  257. package/dist/react/dist/author/shape-elements.js +14 -0
  258. package/dist/{capabilities/dist/table → react/dist/author}/table-elements.js +6 -4
  259. package/dist/react/dist/author/text-elements.js +64 -0
  260. package/dist/react/dist/author/video-elements.js +14 -0
  261. package/dist/react/dist/document-adapter.js +376 -37
  262. package/dist/react/dist/elements.js +30 -4
  263. package/dist/react/dist/from-vanilla.js +57 -0
  264. package/dist/react/dist/index.js +47 -12
  265. package/dist/react/dist/mount.js +34 -0
  266. package/dist/react/dist/reconciler.js +26 -26
  267. package/dist/react.d.ts +174 -50
  268. package/dist/react.js +31 -27
  269. package/dist/stages-DYHSHKt4.d.ts +80 -0
  270. package/dist/vanilla.d.ts +4 -4
  271. package/dist/vanilla.js +14 -14
  272. package/package.json +6 -8
  273. package/README.md +0 -49
  274. package/dist/capabilities/dist/all.js +0 -32
  275. package/dist/capabilities/dist/box/box-codegen.js +0 -51
  276. package/dist/capabilities/dist/box/box-declaration.js +0 -31
  277. package/dist/capabilities/dist/chart/chart-elements.js +0 -12
  278. package/dist/capabilities/dist/chart/preview/data-labels.js +0 -334
  279. package/dist/capabilities/dist/document.js +0 -148
  280. package/dist/capabilities/dist/font/font-embedding.js +0 -289
  281. package/dist/capabilities/dist/font/font-family.js +0 -10
  282. package/dist/capabilities/dist/font/font-import.js +0 -302
  283. package/dist/capabilities/dist/font/font.js +0 -25
  284. package/dist/capabilities/dist/group/group-codegen.js +0 -51
  285. package/dist/capabilities/dist/group/group-declaration.js +0 -42
  286. package/dist/capabilities/dist/group/group-elements.js +0 -12
  287. package/dist/capabilities/dist/group/group-import.js +0 -319
  288. package/dist/capabilities/dist/group/group.js +0 -211
  289. package/dist/capabilities/dist/image/image-codegen.js +0 -94
  290. package/dist/capabilities/dist/image/image-declaration.js +0 -8
  291. package/dist/capabilities/dist/image/image-elements.js +0 -12
  292. package/dist/capabilities/dist/image/image-xml.js +0 -12
  293. package/dist/capabilities/dist/image/image.js +0 -472
  294. package/dist/capabilities/dist/masters/masters-codegen.js +0 -21
  295. package/dist/capabilities/dist/motion/motion-api.js +0 -527
  296. package/dist/capabilities/dist/motion/motion-schemas.js +0 -216
  297. package/dist/capabilities/dist/notes/notes-elements.js +0 -12
  298. package/dist/capabilities/dist/notes/notes-xml.js +0 -38
  299. package/dist/capabilities/dist/placeholder/placeholder-codegen.js +0 -23
  300. package/dist/capabilities/dist/placeholder/placeholder-elements.js +0 -12
  301. package/dist/capabilities/dist/placeholder/placeholder.js +0 -292
  302. package/dist/capabilities/dist/shape/shape-declaration.js +0 -57
  303. package/dist/capabilities/dist/shape/shape-elements.js +0 -12
  304. package/dist/capabilities/dist/shape/shape-import.js +0 -579
  305. package/dist/capabilities/dist/shared/placeholder-import.js +0 -113
  306. package/dist/capabilities/dist/shared/style-parse.js +0 -11
  307. package/dist/capabilities/dist/shared/text-schemas.js +0 -216
  308. package/dist/capabilities/dist/shared/text-service.js +0 -1883
  309. package/dist/capabilities/dist/slide-background/slide-background-codegen.js +0 -44
  310. package/dist/capabilities/dist/slide-background/slide-background-xml.js +0 -21
  311. package/dist/capabilities/dist/table/table-codegen.js +0 -81
  312. package/dist/capabilities/dist/table/table-schemas.js +0 -279
  313. package/dist/capabilities/dist/text/text-codegen.js +0 -129
  314. package/dist/capabilities/dist/text/text-declaration.js +0 -19
  315. package/dist/capabilities/dist/text/text-elements.js +0 -38
  316. package/dist/capabilities/dist/text/text-import.js +0 -1077
  317. package/dist/capability-D_xeNVIw.d.ts +0 -29496
  318. package/dist/codegen/dist/types.js +0 -49
  319. package/dist/core/dist/build.js +0 -4
  320. package/dist/core/dist/capability.js +0 -13
  321. package/dist/core/dist/diagnostics.js +0 -21
  322. package/dist/core/dist/document-internals.js +0 -13
  323. package/dist/core/dist/input-values.js +0 -45
  324. package/dist/core/dist/layout.js +0 -299
  325. package/dist/core/dist/masters.js +0 -169
  326. package/dist/core/dist/placeholders.js +0 -213
  327. package/dist/core/dist/stage-options.js +0 -67
  328. package/dist/document-BHPUODPP.d.ts +0 -27759
  329. package/dist/emit/dist/index.js +0 -5
  330. package/dist/import/dist/import.js +0 -504
  331. package/dist/import/dist/index.js +0 -16
  332. package/dist/import/dist/xml-fragments.js +0 -36
  333. package/dist/index-B5m3hqjC.d.ts +0 -7
  334. package/dist/index-CCy-Yo8G.d.ts +0 -1208
  335. package/dist/index-DpxcZ4Gs.d.ts +0 -725
  336. package/dist/pptxdk/src/slide.js +0 -9
  337. package/dist/preview-Cfw0QdMM.d.ts +0 -86
  338. package/dist/transition-Cips9wma.d.ts +0 -82
@@ -0,0 +1,2563 @@
1
+ import { componentLabel } from "../../kernel/declaration.js";
2
+ import { CapabilityError } from "../../kernel/diagnostics.js";
3
+ import { paragraphIndentToEmu, pxToEmu } from "../../kernel/drawing-units.js";
4
+ import { hasFontFaceBytes, peekFontFaceResource, resolveFontClassification } from "../../kernel/font-seal.js";
5
+ import { isFont, isTextGradient, textStyleKeys, validateTextStyle } from "../../kernel/theme.js";
6
+ import { maximumParagraphIndentPx } from "../../kernel/placeholders.js";
7
+ import { formatDateTime } from "./date-time.js";
8
+ import { paddingStyleKeys } from "../../kernel/block-flex-layout.js";
9
+ import { fontPresentationContributions, requiresFontGlyph, requiresVisibleFontGlyph } from "./font/font-embedding.js";
10
+ import { findMissingFontGlyphs, fontFaceCoversCodePoint, isTrueTypeFontEmbeddable, openMeasureFontFace, resolveDeclaredFaceSlot, shapeFontAdvances, shapeFontOutlines, unkernedFontAdvances, validateFontFaceResource } from "./font/font-engine.js";
11
+ import { parseStepDeclarationProps, pickMotionProps, validateMotionFlag } from "./motion-api.js";
12
+ import { motionPropKeySet } from "./motion-schemas.js";
13
+ import "../../kernel/capability.js";
14
+ import { textDecorationAttributes, textFillXml, textStrokeXml, xmlEscape } from "../../kernel/pptx-write/xml.js";
15
+ import { referenceDateTimestamp } from "../../kernel/stage-options.js";
16
+ import { hasLocalDeclaration, localDeclaredKeySet, resolvePlaceholderBaseTextStyle, resolvePlaceholderLevelTextStyle } from "./style-inheritance.js";
17
+ import { dateTimeAuthorPropsKeys, dateTimeAuthorPropsObjectSchema, isInlineRichTextNodeType, isInlineTextFieldNodeType, parseBaselineShiftThousandths, parseParagraphStyle, parseRunStyle, parseTextInsets, spanAuthorPropsKeys } from "./text-schemas.js";
18
+ import { borderAttributes, gradientDefSvg, resolveGradientSpec, resolveShadow, resolveTextStroke, textShadowXml } from "./visual.js";
19
+ import LineBreakerImplementation from "linebreak";
20
+ // ../core/dist/capabilities/shared/text-service.js
21
+ /**
22
+ * Author metadata accepted on paragraphs and inline text declarations declarations.
23
+ *
24
+ * Scoped id validation belongs to the formal build around these nodes; the shared text parser must
25
+ * skip the field while resolving styles instead of reporting it as an unimplemented parameter.
26
+ */
27
+ const textAuthorMetadataKeys = /* @__PURE__ */ new Set(["id"]);
28
+ const spanAllowedPropKeySet = new Set(spanAuthorPropsKeys);
29
+ const dateTimeAllowedPropKeySet = new Set(dateTimeAuthorPropsKeys);
30
+ const LineBreaker = LineBreakerImplementation;
31
+ const graphemes = new Intl.Segmenter(void 0, { granularity: "grapheme" });
32
+ const defaultTextStyle = Object.freeze({
33
+ fontFamily: "minor",
34
+ eastAsianFontFamily: "minor",
35
+ fontSize: 24,
36
+ fontWeight: "normal",
37
+ fontStyle: "normal",
38
+ color: "tx1"
39
+ });
40
+ function record(value) {
41
+ return typeof value === "object" && value !== null && !Array.isArray(value);
42
+ }
43
+ function escapedXml(value, field) {
44
+ try {
45
+ return xmlEscape(value);
46
+ } catch {
47
+ throw new CapabilityError("invalid-xml-character", "Text content or font name contains characters not allowed in XML 1.0", void 0, { field });
48
+ }
49
+ }
50
+ function isHostText(child) {
51
+ return child.type === "#text" && "text" in child;
52
+ }
53
+ function hostChild(value) {
54
+ if (!record(value) || typeof value["type"] !== "string") return false;
55
+ if (value["type"] === "#text") return typeof value["text"] === "string";
56
+ return value["type"].trim() !== "" && record(value["props"]) && Array.isArray(value["children"]);
57
+ }
58
+ function styleRecord(value, label) {
59
+ if (value === void 0) return {};
60
+ if (!record(value)) throw new CapabilityError("invalid-style", `${label} must be an object`);
61
+ return value;
62
+ }
63
+ function onlyKnownKeys(value, allowed, label) {
64
+ const unknown = Object.keys(value).find((key) => !allowed.includes(key));
65
+ if (unknown !== void 0) throw new CapabilityError("unknown-style-property", `${label} contains unimplemented style ${unknown}`);
66
+ }
67
+ function positiveLength(value, label) {
68
+ let pixels;
69
+ if (typeof value === "number") pixels = value;
70
+ else if (typeof value === "string") {
71
+ const match = /^(\d+(?:\.\d+)?)(px|pt)$/u.exec(value);
72
+ if (match === null) throw new CapabilityError("invalid-text-length", `${label} must be a positive pixel value or px/pt length`);
73
+ const amount = Number(match[1]);
74
+ pixels = match[2] === "pt" ? amount * 4 / 3 : amount;
75
+ } else throw new CapabilityError("invalid-text-length", `${label} must be a positive pixel value or px/pt length`);
76
+ if (!Number.isFinite(pixels) || pixels <= 0) throw new CapabilityError("invalid-text-length", `${label} must be greater than 0`);
77
+ return pixels;
78
+ }
79
+ const lineHeightPercentPattern = /^(\d+(?:\.\d+)?)%$/u;
80
+ function isLineHeightPercent(value) {
81
+ return typeof value === "string" && value.endsWith("%");
82
+ }
83
+ function lineHeightPercentThousandths(value) {
84
+ const match = lineHeightPercentPattern.exec(value);
85
+ if (match === null) throw new CapabilityError("invalid-text-length", "lineHeight percentage must be greater than 0% and within DrawingML ST_TextSpacingPercent range (up to 13200%)");
86
+ const pct = Number(match[1]);
87
+ const thousandths = Math.round(pct * 1e3);
88
+ if (!Number.isFinite(pct) || thousandths < 1 || thousandths > 132e5) throw new CapabilityError("invalid-text-length", "lineHeight percentage must be greater than 0% and within DrawingML ST_TextSpacingPercent range (up to 13200%)");
89
+ return thousandths;
90
+ }
91
+ function lineSpacingXml(value) {
92
+ if (value === void 0) return "";
93
+ if (isLineHeightPercent(value)) return `<a:lnSpc><a:spcPct val="${lineHeightPercentThousandths(value)}"/></a:lnSpc>`;
94
+ return `<a:lnSpc><a:spcPts val="${spacingCentipoints(positiveLength(value, "lineHeight"), "lineHeight")}"/></a:lnSpc>`;
95
+ }
96
+ function centipoints(value) {
97
+ return Math.round(value * 100);
98
+ }
99
+ function spacingCentipoints(pixels, label) {
100
+ const value = Math.round(pixels * 75);
101
+ if (value < 0 || value > 158400) throw new CapabilityError(label === "lineHeight" ? "invalid-text-length" : "invalid-paragraph-spacing", `${label} converted value must be within DrawingML range of 0 to 1584pt`);
102
+ return value;
103
+ }
104
+ function letterSpacingCentipoints(value) {
105
+ const points = Math.round(value * 75);
106
+ if (!Number.isFinite(value) || points < -4e5 || points > 4e5) throw new CapabilityError("invalid-letter-spacing", "letterSpacing converted value must be within DrawingML range of -4000 to 4000pt");
107
+ return points;
108
+ }
109
+ function fontSizePoints(value) {
110
+ let points;
111
+ if (value === void 0) points = positiveLength(defaultTextStyle.fontSize, "fontSize") * .75;
112
+ else if (typeof value === "string" && value.endsWith("pt")) {
113
+ points = Number(value.slice(0, -2));
114
+ if (!Number.isFinite(points) || points <= 0) throw new CapabilityError("invalid-font-size", "fontSize must be greater than 0");
115
+ } else points = positiveLength(value, "fontSize") * .75;
116
+ const serialized = centipoints(points);
117
+ if (serialized < 100 || serialized > 4e5) throw new CapabilityError("invalid-font-size", "fontSize converted value must be within DrawingML range of 1 to 4000pt");
118
+ return serialized / 100;
119
+ }
120
+ function weightValue(value) {
121
+ if (value === void 0 || value === "normal") return 400;
122
+ if (value === "bold") return 700;
123
+ return value;
124
+ }
125
+ function fontFamilyValue(value) {
126
+ if (value === void 0) return { family: "Aptos" };
127
+ return typeof value === "string" ? { family: value } : value;
128
+ }
129
+ function normalizedFontsForReference(fontRef, fontWeight, fontStyle) {
130
+ const family = fontFamilyValue(fontRef);
131
+ const weight = weightValue(fontWeight);
132
+ const faceStyle = fontStyle ?? "normal";
133
+ const providedFaces = (family.faces ?? []).filter((candidate) => {
134
+ const slot = resolveDeclaredFaceSlot(candidate);
135
+ if (slot.matchAnyWeightOnFvarOrCorrupt) return candidate.style === void 0 || slot.style === faceStyle;
136
+ return slot.weight === weight && slot.style === faceStyle;
137
+ }).filter((candidate) => hasFontFaceBytes(candidate));
138
+ if (providedFaces.length === 0) return [{
139
+ family: family.family,
140
+ weight,
141
+ style: faceStyle,
142
+ substitute: family.substitute ?? false,
143
+ embeddable: family.embeddable ?? true,
144
+ hasResource: false,
145
+ identity: "missing"
146
+ }];
147
+ return providedFaces.flatMap((face) => {
148
+ const faceResource = peekFontFaceResource(face);
149
+ if (faceResource === void 0) return [];
150
+ return [{
151
+ family: family.family,
152
+ weight,
153
+ style: faceStyle,
154
+ substitute: family.substitute ?? false,
155
+ embeddable: family.embeddable ?? true,
156
+ hasResource: true,
157
+ identity: faceResource.sha256,
158
+ data: faceResource.bytes
159
+ }];
160
+ });
161
+ }
162
+ function normalizedFonts(style) {
163
+ return normalizedFontsForReference(style.fontFamily, style.fontWeight, style.fontStyle);
164
+ }
165
+ function isEastAsianCodePoint(cp) {
166
+ return cp >= 11904 && cp <= 12031 || cp >= 12032 && cp <= 12255 || cp >= 12272 && cp <= 12351 || cp >= 12352 && cp <= 12543 || cp >= 12544 && cp <= 12591 || cp >= 12592 && cp <= 12687 || cp >= 12704 && cp <= 12735 || cp >= 12784 && cp <= 12799 || cp >= 12800 && cp <= 13311 || cp >= 13312 && cp <= 19903 || cp >= 19968 && cp <= 40959 || cp >= 4352 && cp <= 4607 || cp >= 43360 && cp <= 43391 || cp >= 44032 && cp <= 55295 || cp >= 63744 && cp <= 64255 || cp >= 65040 && cp <= 65055 || cp >= 65072 && cp <= 65135 || cp >= 65281 && cp <= 65376 || cp >= 65377 && cp <= 65503 || cp >= 65504 && cp <= 65510 || cp >= 110592 && cp <= 110959 || cp >= 131072 && cp <= 205743;
167
+ }
168
+ /**
169
+ * East Asian ambiguous punctuation and symbols (UAX #11 subset) routed to the East Asian
170
+ * font slot under `zh*`/`ja*`/`ko*` `lang` or adjacent East Asian context when covered by
171
+ * the EA face. Excludes Greek, Cyrillic, ASCII, `U+2013` (`–`), `U+00B7` (`·`), and `U+00B0` (`°`).
172
+ */
173
+ function isAmbiguousEastAsianCodePoint(cp) {
174
+ return cp === 161 || cp === 164 || cp >= 167 && cp <= 168 || cp === 170 || cp >= 173 && cp <= 174 || cp >= 177 && cp <= 180 || cp === 182 || cp >= 184 && cp <= 186 || cp >= 188 && cp <= 191 || cp === 215 || cp === 247 || cp >= 8212 && cp <= 8214 || cp >= 8216 && cp <= 8223 || cp >= 8224 && cp <= 8225 || cp >= 8229 && cp <= 8230 || cp === 8240 || cp >= 8242 && cp <= 8243 || cp === 8245 || cp === 8251 || cp === 8451 || cp === 8453 || cp === 8457 || cp === 8470 || cp === 8481 || cp === 8491 || cp >= 8544 && cp <= 8555 || cp >= 8560 && cp <= 8569 || cp >= 8592 && cp <= 8601 || cp >= 8632 && cp <= 8633 || cp === 8658 || cp === 8660 || cp === 8679 || cp === 8704 || cp >= 8706 && cp <= 8707 || cp >= 8711 && cp <= 8712 || cp === 8715 || cp === 8719 || cp === 8721 || cp === 8725 || cp === 8730 || cp >= 8733 && cp <= 8736 || cp === 8739 || cp === 8741 || cp >= 8743 && cp <= 8748 || cp === 8750 || cp >= 8756 && cp <= 8759 || cp >= 8764 && cp <= 8765 || cp === 8776 || cp === 8780 || cp === 8786 || cp >= 8800 && cp <= 8801 || cp >= 8804 && cp <= 8807 || cp >= 8810 && cp <= 8811 || cp >= 8814 && cp <= 8815 || cp >= 8834 && cp <= 8835 || cp >= 8838 && cp <= 8839 || cp === 8853 || cp === 8857 || cp === 8869 || cp === 8895 || cp === 8978 || cp >= 9312 && cp <= 9449 || cp >= 9451 && cp <= 9471 || cp >= 9472 && cp <= 9587 || cp >= 9600 && cp <= 9621 || cp >= 9632 && cp <= 9633 || cp >= 9635 && cp <= 9641 || cp >= 9650 && cp <= 9651 || cp >= 9654 && cp <= 9655 || cp >= 9660 && cp <= 9661 || cp >= 9664 && cp <= 9665 || cp >= 9670 && cp <= 9672 || cp === 9675 || cp >= 9678 && cp <= 9681 || cp >= 9698 && cp <= 9701 || cp === 9711 || cp >= 9733 && cp <= 9734 || cp === 9737 || cp >= 9742 && cp <= 9743 || cp === 9756 || cp === 9758 || cp === 9792 || cp === 9794 || cp >= 9824 && cp <= 9825 || cp >= 9827 && cp <= 9829 || cp >= 9831 && cp <= 9834 || cp >= 9836 && cp <= 9837 || cp === 9839 || cp >= 10102 && cp <= 10111;
175
+ }
176
+ const eastAsianLangPattern = /^(?:zh|ja|ko)(?:$|-)/iu;
177
+ function isNeutralScriptChar(ch, cp) {
178
+ return cp !== 12288 && /^[\p{White_Space}\p{Cc}\p{Default_Ignorable_Code_Point}]$/u.test(ch);
179
+ }
180
+ function sameFontReference(left, right) {
181
+ if (left === right) return true;
182
+ if (left === void 0 || right === void 0) return false;
183
+ if (typeof left === "string" && typeof right === "string") return left === right;
184
+ return false;
185
+ }
186
+ function effectiveEastAsianRunStyle(style) {
187
+ if (style.eastAsianFontFamily === void 0 || sameFontReference(style.eastAsianFontFamily, style.fontFamily)) return style;
188
+ return {
189
+ ...style,
190
+ fontFamily: style.eastAsianFontFamily,
191
+ themeFont: style.eastAsianThemeFont
192
+ };
193
+ }
194
+ function createEastAsianCoverageChecker(style) {
195
+ if (style.eastAsianFontFamily === void 0) return void 0;
196
+ const fonts = normalizedFontsForReference(style.eastAsianFontFamily, style.fontWeight, style.fontStyle).filter((font) => font.hasResource && font.data !== void 0);
197
+ if (fonts.length === 0) return void 0;
198
+ const faces = [];
199
+ for (const font of fonts) try {
200
+ faces.push(validateFontFaceResource({
201
+ family: font.family,
202
+ weight: font.weight,
203
+ style: font.style,
204
+ substitute: font.substitute,
205
+ data: font.data,
206
+ identity: font.identity
207
+ }));
208
+ } catch {
209
+ return;
210
+ }
211
+ return (cp) => faces.some((face) => fontFaceCoversCodePoint(face, cp));
212
+ }
213
+ /**
214
+ * Segments all runs of a single paragraph into effective Latin / East Asian script segments.
215
+ *
216
+ * Uses paragraph-wide strong-script context so ambiguous East Asian punctuation in undeclared-`lang`
217
+ * runs and boundary neutral whitespace between East Asian and Latin/digit runs match native DrawingML
218
+ * slot selection across measurement, preview, FontUsage, and font subsetting.
219
+ */
220
+ function splitParagraphRunsForEffectiveScripts(runs) {
221
+ const runMeta = runs.map((run) => {
222
+ const eaStyle = effectiveEastAsianRunStyle(run.style);
223
+ const hasDistinctEa = eaStyle !== run.style;
224
+ return {
225
+ run,
226
+ eaStyle,
227
+ hasDistinctEa,
228
+ coversEa: hasDistinctEa ? createEastAsianCoverageChecker(run.style) : void 0
229
+ };
230
+ });
231
+ const chars = [];
232
+ for (let runIndex = 0; runIndex < runMeta.length; runIndex += 1) {
233
+ const { run } = runMeta[runIndex];
234
+ for (const ch of run.text) {
235
+ const cp = ch.codePointAt(0);
236
+ if (cp === void 0) continue;
237
+ const isNeutral = isNeutralScriptChar(ch, cp);
238
+ const definiteScript = isNeutral ? void 0 : isEastAsianCodePoint(cp) ? "ea" : isAmbiguousEastAsianCodePoint(cp) ? void 0 : "latin";
239
+ chars.push({
240
+ runIndex,
241
+ ch,
242
+ cp,
243
+ isNeutral,
244
+ definiteScript,
245
+ resolvedScript: definiteScript
246
+ });
247
+ }
248
+ }
249
+ const n = chars.length;
250
+ const prevStrong = Array.from({ length: n });
251
+ let lastStrong;
252
+ for (let i = 0; i < n; i += 1) {
253
+ prevStrong[i] = lastStrong;
254
+ const def = chars[i].definiteScript;
255
+ if (def !== void 0) lastStrong = def;
256
+ }
257
+ const nextStrong = Array.from({ length: n });
258
+ let upcomingStrong;
259
+ for (let i = n - 1; i >= 0; i -= 1) {
260
+ nextStrong[i] = upcomingStrong;
261
+ const def = chars[i].definiteScript;
262
+ if (def !== void 0) upcomingStrong = def;
263
+ }
264
+ for (let i = 0; i < n; i += 1) {
265
+ const entry = chars[i];
266
+ if (entry.isNeutral) continue;
267
+ const meta = runMeta[entry.runIndex];
268
+ if (!meta.hasDistinctEa) {
269
+ entry.resolvedScript = "latin";
270
+ continue;
271
+ }
272
+ if (entry.definiteScript !== void 0) {
273
+ entry.resolvedScript = entry.definiteScript;
274
+ continue;
275
+ }
276
+ const lang = meta.run.style.lang;
277
+ let candidate;
278
+ if (lang !== void 0) candidate = eastAsianLangPattern.test(lang) ? "ea" : "latin";
279
+ else candidate = prevStrong[i] === "ea" || nextStrong[i] === "ea" ? "ea" : "latin";
280
+ if (candidate === "ea" && meta.coversEa !== void 0) entry.resolvedScript = meta.coversEa(entry.cp) ? "ea" : "latin";
281
+ else entry.resolvedScript = candidate;
282
+ }
283
+ const prevResolved = Array.from({ length: n });
284
+ let lastResolved;
285
+ for (let i = 0; i < n; i += 1) {
286
+ prevResolved[i] = lastResolved;
287
+ if (!chars[i].isNeutral) lastResolved = chars[i].resolvedScript;
288
+ }
289
+ const nextResolved = Array.from({ length: n });
290
+ let upcomingResolved;
291
+ for (let i = n - 1; i >= 0; i -= 1) {
292
+ nextResolved[i] = upcomingResolved;
293
+ if (!chars[i].isNeutral) upcomingResolved = chars[i].resolvedScript;
294
+ }
295
+ for (let i = 0; i < n; i += 1) {
296
+ const entry = chars[i];
297
+ if (!entry.isNeutral) continue;
298
+ const prev = prevResolved[i];
299
+ const next = nextResolved[i];
300
+ if (prev === "latin" || next === "latin") entry.resolvedScript = "latin";
301
+ else if (prev === "ea" || next === "ea") entry.resolvedScript = "ea";
302
+ else entry.resolvedScript = "latin";
303
+ }
304
+ const perRun = runMeta.map(() => []);
305
+ let charPos = 0;
306
+ for (let runIndex = 0; runIndex < runMeta.length; runIndex += 1) {
307
+ const { run, eaStyle, hasDistinctEa } = runMeta[runIndex];
308
+ if (run.text === "" || !hasDistinctEa) {
309
+ perRun[runIndex].push({
310
+ script: "latin",
311
+ text: run.text,
312
+ style: run.style
313
+ });
314
+ while (charPos < n && chars[charPos].runIndex === runIndex) charPos += 1;
315
+ continue;
316
+ }
317
+ let activeScript;
318
+ let buffer = "";
319
+ while (charPos < n && chars[charPos].runIndex === runIndex) {
320
+ const entry = chars[charPos];
321
+ const script = entry.resolvedScript ?? "latin";
322
+ if (activeScript === void 0) {
323
+ activeScript = script;
324
+ buffer = entry.ch;
325
+ } else if (script === activeScript) buffer += entry.ch;
326
+ else {
327
+ perRun[runIndex].push({
328
+ script: activeScript,
329
+ text: buffer,
330
+ style: activeScript === "ea" ? eaStyle : run.style
331
+ });
332
+ activeScript = script;
333
+ buffer = entry.ch;
334
+ }
335
+ charPos += 1;
336
+ }
337
+ if (activeScript !== void 0 && buffer !== "") perRun[runIndex].push({
338
+ script: activeScript,
339
+ text: buffer,
340
+ style: activeScript === "ea" ? eaStyle : run.style
341
+ });
342
+ }
343
+ return perRun;
344
+ }
345
+ function splitRunForEffectiveScripts(text, style) {
346
+ return splitParagraphRunsForEffectiveScripts([{
347
+ text,
348
+ style
349
+ }])[0];
350
+ }
351
+ function hasIndependentThemeMinorEa(theme) {
352
+ if (theme.theme.fonts.minorEastAsian !== void 0) return true;
353
+ const ea = theme.resolveEastAsianFont("minor");
354
+ const lt = theme.resolveFont("minor");
355
+ return (ea.font ?? ea.family) !== (lt.font ?? lt.family);
356
+ }
357
+ function validateRunStyle(style) {
358
+ const { themeFont: _themeFont, eastAsianThemeFont: _eastAsianThemeFont, color, baselineShift, ...rest } = style;
359
+ validateTextStyle({
360
+ ...rest,
361
+ ...color !== void 0 && !isResolvedColor(color) ? { color } : {}
362
+ });
363
+ if (baselineShift !== void 0 && parseBaselineShiftThousandths(baselineShift) === void 0) throw new CapabilityError("invalid-baseline-shift", "baselineShift must be a non-zero finite percentage string within DrawingML ST_Percentage range", void 0, { field: "style.baselineShift" });
364
+ return style;
365
+ }
366
+ function mergeRunStyle(parent, child, theme) {
367
+ const declared = Object.fromEntries(Object.entries(child).filter(([, value]) => value !== void 0));
368
+ if (child.fontFamily !== void 0) {
369
+ const font = theme.resolveFont(child.fontFamily);
370
+ declared["fontFamily"] = font.font ?? font.family;
371
+ if (child.themeFont === void 0 && font.themeFont === void 0) delete declared["themeFont"];
372
+ else declared["themeFont"] = child.themeFont ?? font.themeFont;
373
+ }
374
+ if (child.eastAsianFontFamily !== void 0) {
375
+ const eaFont = theme.resolveEastAsianFont(child.eastAsianFontFamily);
376
+ declared["eastAsianFontFamily"] = eaFont.font ?? eaFont.family;
377
+ if (child.eastAsianThemeFont === void 0 && eaFont.themeFont === void 0) delete declared["eastAsianThemeFont"];
378
+ else declared["eastAsianThemeFont"] = child.eastAsianThemeFont ?? eaFont.themeFont;
379
+ }
380
+ if (child.color !== void 0 && !isResolvedColor(child.color)) declared["color"] = resolveRunColor(theme, child.color);
381
+ if (child.lang !== void 0) declared["lang"] = child.lang;
382
+ const merged = {
383
+ ...parent,
384
+ ...declared
385
+ };
386
+ if (child.textShadow === "none") delete merged.textShadow;
387
+ if (child.fontFamily !== void 0 && declared["themeFont"] === void 0) delete merged.themeFont;
388
+ if (child.eastAsianFontFamily !== void 0 && declared["eastAsianThemeFont"] === void 0) delete merged.eastAsianThemeFont;
389
+ return validateRunStyle(merged);
390
+ }
391
+ function isResolvedColor(value) {
392
+ return record(value) && typeof value["hex"] === "string";
393
+ }
394
+ function outputBold(font) {
395
+ const fallback = font.weight >= 600;
396
+ if (!font.hasResource || font.substitute || font.data === void 0) return fallback;
397
+ try {
398
+ return validateFontFaceResource({
399
+ family: font.family,
400
+ weight: font.weight,
401
+ style: font.style,
402
+ substitute: font.substitute,
403
+ data: font.data,
404
+ identity: font.identity
405
+ }).os2Bold;
406
+ } catch {
407
+ return fallback;
408
+ }
409
+ }
410
+ function mergeLocalRunDeclared(parent, child, theme) {
411
+ const declared = { ...parent };
412
+ for (const [key, value] of Object.entries(child)) {
413
+ if (!Object.hasOwn(child, key) || value === void 0) continue;
414
+ declared[key] = value;
415
+ }
416
+ if (hasLocalDeclaration(child, "fontFamily")) {
417
+ const resolved = theme.resolveFont(child["fontFamily"]);
418
+ declared["fontFamily"] = resolved.font ?? resolved.family;
419
+ if (resolved.themeFont === void 0) delete declared["themeFont"];
420
+ else declared["themeFont"] = resolved.themeFont;
421
+ }
422
+ if (hasLocalDeclaration(child, "eastAsianFontFamily")) {
423
+ const resolvedEa = theme.resolveEastAsianFont(child["eastAsianFontFamily"]);
424
+ declared["eastAsianFontFamily"] = resolvedEa.font ?? resolvedEa.family;
425
+ if (resolvedEa.themeFont === void 0) delete declared["eastAsianThemeFont"];
426
+ else declared["eastAsianThemeFont"] = resolvedEa.themeFont;
427
+ }
428
+ if (hasLocalDeclaration(child, "color") && !isResolvedColor(child["color"])) declared["color"] = resolveRunColor(theme, child["color"]);
429
+ return declared;
430
+ }
431
+ function resolveRunStyleFromRecord(style, theme) {
432
+ const font = theme.resolveFont(style["fontFamily"] ?? defaultTextStyle.fontFamily);
433
+ const rawEa = style["eastAsianFontFamily"];
434
+ const eaFont = rawEa !== void 0 ? theme.resolveEastAsianFont(rawEa) : hasIndependentThemeMinorEa(theme) ? theme.resolveEastAsianFont("minor") : font.themeFont !== void 0 ? theme.resolveEastAsianFont(font.themeFont) : void 0;
435
+ const includeEa = rawEa !== void 0 || hasIndependentThemeMinorEa(theme) || eaFont !== void 0 && (eaFont.font ?? eaFont.family) !== (font.font ?? font.family);
436
+ const rawColor = style["color"];
437
+ const color = rawColor === void 0 ? resolveRunColor(theme, defaultTextStyle.color) : isResolvedColor(rawColor) ? rawColor : resolveRunColor(theme, rawColor);
438
+ return validateRunStyle({
439
+ fontFamily: font.font ?? font.family,
440
+ ...includeEa && eaFont !== void 0 ? {
441
+ eastAsianFontFamily: eaFont.font ?? eaFont.family,
442
+ ...eaFont.themeFont === void 0 ? {} : { eastAsianThemeFont: eaFont.themeFont }
443
+ } : {},
444
+ fontSize: style["fontSize"] ?? defaultTextStyle.fontSize,
445
+ fontWeight: style["fontWeight"] ?? defaultTextStyle.fontWeight,
446
+ fontStyle: style["fontStyle"] ?? defaultTextStyle.fontStyle,
447
+ color,
448
+ ...font.themeFont === void 0 ? {} : { themeFont: font.themeFont },
449
+ ...style["letterSpacing"] === void 0 ? {} : { letterSpacing: style["letterSpacing"] },
450
+ ...style["textTransform"] === void 0 ? {} : { textTransform: style["textTransform"] },
451
+ ...style["textDecoration"] === void 0 ? {} : { textDecoration: style["textDecoration"] },
452
+ textStroke: style["textStroke"],
453
+ ...style["textShadow"] === void 0 || style["textShadow"] === "none" ? {} : { textShadow: style["textShadow"] },
454
+ ...style["lang"] === void 0 ? {} : { lang: style["lang"] }
455
+ });
456
+ }
457
+ function readPlaceholderTextStyle(value, label, placeholder) {
458
+ const props = styleRecord(value, label);
459
+ onlyKnownKeys(props, [...textStyleKeys], label);
460
+ const localDeclaredStyle = {};
461
+ for (const key of textStyleKeys) if (hasLocalDeclaration(props, key)) localDeclaredStyle[key] = props[key];
462
+ const effectiveBase = resolvePlaceholderBaseTextStyle(placeholder, localDeclaredStyle);
463
+ const masterTheme = placeholder.masterTheme;
464
+ const eaDeclared = effectiveBase["eastAsianFontFamily"] !== void 0;
465
+ const merged = {
466
+ ...defaultTextStyle,
467
+ ...effectiveBase
468
+ };
469
+ const font = masterTheme.resolveFont(merged.fontFamily ?? defaultTextStyle.fontFamily);
470
+ const eaFont = eaDeclared ? masterTheme.resolveEastAsianFont(effectiveBase["eastAsianFontFamily"]) : hasIndependentThemeMinorEa(masterTheme) ? masterTheme.resolveEastAsianFont("minor") : font.themeFont !== void 0 ? masterTheme.resolveEastAsianFont(font.themeFont) : void 0;
471
+ const includeEa = eaDeclared || hasIndependentThemeMinorEa(masterTheme) || eaFont !== void 0 && (eaFont.font ?? eaFont.family) !== (font.font ?? font.family);
472
+ if (merged.color !== void 0 && !isResolvedColor(merged.color)) resolveRunColor(masterTheme, merged.color);
473
+ validateTextStyle({
474
+ ...merged,
475
+ fontFamily: font.font ?? font.family,
476
+ ...includeEa && eaFont !== void 0 ? { eastAsianFontFamily: eaFont.font ?? eaFont.family } : { eastAsianFontFamily: void 0 },
477
+ ...isResolvedColor(merged.color) ? { color: void 0 } : {}
478
+ }, masterTheme);
479
+ const result = {
480
+ ...merged,
481
+ fontFamily: font.font ?? font.family,
482
+ ...includeEa && eaFont !== void 0 ? {
483
+ eastAsianFontFamily: eaFont.font ?? eaFont.family,
484
+ ...eaFont.themeFont === void 0 ? {} : { eastAsianThemeFont: eaFont.themeFont }
485
+ } : { eastAsianFontFamily: void 0 },
486
+ ...font.themeFont === void 0 ? {} : { themeFont: font.themeFont }
487
+ };
488
+ if (result.textShadow === "none") delete result.textShadow;
489
+ return {
490
+ style: result,
491
+ localDeclaredStyle
492
+ };
493
+ }
494
+ function readTextStyle(value, label, theme, preserveShadowReset = false) {
495
+ const props = styleRecord(value, label);
496
+ onlyKnownKeys(props, [...textStyleKeys], label);
497
+ const rawCombined = {
498
+ ...theme.textStyle,
499
+ ...props
500
+ };
501
+ const eaDeclared = rawCombined["eastAsianFontFamily"] !== void 0;
502
+ const style = {
503
+ ...defaultTextStyle,
504
+ ...theme.textStyle,
505
+ ...props
506
+ };
507
+ const font = theme.resolveFont(style.fontFamily ?? defaultTextStyle.fontFamily);
508
+ const eaFont = eaDeclared ? theme.resolveEastAsianFont(rawCombined["eastAsianFontFamily"]) : hasIndependentThemeMinorEa(theme) ? theme.resolveEastAsianFont("minor") : font.themeFont !== void 0 ? theme.resolveEastAsianFont(font.themeFont) : void 0;
509
+ const includeEa = eaDeclared || hasIndependentThemeMinorEa(theme) || eaFont !== void 0 && (eaFont.font ?? eaFont.family) !== (font.font ?? font.family);
510
+ if (style.color !== void 0 && !isResolvedColor(style.color)) resolveRunColor(theme, style.color);
511
+ validateTextStyle({
512
+ ...style,
513
+ fontFamily: font.font ?? font.family,
514
+ ...includeEa && eaFont !== void 0 ? { eastAsianFontFamily: eaFont.font ?? eaFont.family } : { eastAsianFontFamily: void 0 },
515
+ ...isResolvedColor(style.color) ? { color: void 0 } : {}
516
+ }, theme);
517
+ const result = {
518
+ ...style,
519
+ fontFamily: font.font ?? font.family,
520
+ ...includeEa && eaFont !== void 0 ? {
521
+ eastAsianFontFamily: eaFont.font ?? eaFont.family,
522
+ ...eaFont.themeFont === void 0 ? {} : { eastAsianThemeFont: eaFont.themeFont }
523
+ } : { eastAsianFontFamily: void 0 },
524
+ ...font.themeFont === void 0 ? {} : { themeFont: font.themeFont }
525
+ };
526
+ if (!preserveShadowReset && result.textShadow === "none") delete result.textShadow;
527
+ return result;
528
+ }
529
+ function collectRuns(children, style, runs, theme, fields, parentPath, localDeclared, firstIndex = 0) {
530
+ for (const [index, child] of children.entries()) {
531
+ if (!hostChild(child)) throw new CapabilityError("invalid-text-child", "Text content tree contains invalid nodes");
532
+ if (isHostText(child)) {
533
+ if (child.text !== "") runs.push({
534
+ text: child.text,
535
+ style,
536
+ ...localDeclared === void 0 ? {} : { localDeclared }
537
+ });
538
+ continue;
539
+ }
540
+ if (!isInlineRichTextNodeType(child.type)) throw new CapabilityError("unsupported-text-child", `${child.type} cannot be used as text paragraph or run`);
541
+ const label = componentLabel(child, firstIndex + index);
542
+ const path = parentPath === "" ? label : `${parentPath}/${label}`;
543
+ const allowedInlineKeys = child.type === "date-time" ? dateTimeAllowedPropKeySet : spanAllowedPropKeySet;
544
+ const unknown = Object.keys(child.props).find((key) => !allowedInlineKeys.has(key));
545
+ if (unknown !== void 0) throw new CapabilityError("unknown-parameter", `Span contains unimplemented parameter ${unknown}`, path, {
546
+ prop: unknown,
547
+ field: unknown
548
+ });
549
+ const parsedSpanStyle = parseRunStyle(child.props["style"], path, theme);
550
+ let spanStyle = parsedSpanStyle;
551
+ if (child.type === "sup" || child.type === "sub") {
552
+ const defaultShift = child.type === "sup" ? "30%" : "-25%";
553
+ const expectedMilli = child.type === "sup" ? 3e4 : -25e3;
554
+ const tagLabel = child.type === "sup" ? "Sup" : "Sub";
555
+ if (parsedSpanStyle.baselineShift !== void 0) {
556
+ if (parseBaselineShiftThousandths(parsedSpanStyle.baselineShift) !== expectedMilli) throw new CapabilityError("conflicting-baseline-shift", `${tagLabel} cannot declare conflicting baselineShift ${parsedSpanStyle.baselineShift}`, void 0, { field: "style.baselineShift" });
557
+ }
558
+ if (style.baselineShift !== void 0) {
559
+ if (parseBaselineShiftThousandths(style.baselineShift) !== expectedMilli) throw new CapabilityError("conflicting-baseline-shift", `${tagLabel} cannot be nested inside conflicting baselineShift ${style.baselineShift}`, void 0, { field: "style.baselineShift" });
560
+ }
561
+ spanStyle = {
562
+ ...parsedSpanStyle,
563
+ baselineShift: defaultShift
564
+ };
565
+ } else if (parsedSpanStyle.baselineShift !== void 0 && style.baselineShift !== void 0) {
566
+ if (parseBaselineShiftThousandths(parsedSpanStyle.baselineShift) !== parseBaselineShiftThousandths(style.baselineShift)) throw new CapabilityError("conflicting-baseline-shift", `Nested baselineShift ${parsedSpanStyle.baselineShift} conflicts with inherited ${style.baselineShift}`, void 0, { field: "style.baselineShift" });
567
+ }
568
+ const nextStyle = mergeRunStyle(style, spanStyle, theme);
569
+ const nextLocalDeclared = localDeclared === void 0 ? void 0 : mergeLocalRunDeclared(localDeclared, spanStyle, theme);
570
+ if (isInlineTextFieldNodeType(child.type)) {
571
+ const isDateTime = child.type === "date-time";
572
+ if (child.children.length > 0) throw new CapabilityError(isDateTime ? "invalid-date-time" : "invalid-slide-number", `${isDateTime ? "DateTime" : "SlideNumber"} cannot contain children`, path);
573
+ const format = isDateTime ? dateTimeAuthorPropsObjectSchema.shape.format.safeParse(child.props["format"]) : void 0;
574
+ if (format?.success === false) throw new CapabilityError("invalid-date-time", "DateTime.format must be a supported date/time format", path, { field: "format" });
575
+ const resolvedFormat = format?.data ?? "datetimeFigureOut";
576
+ runs.push({
577
+ text: format === void 0 ? String(fields.slideNumber) : formatDateTime(resolvedFormat, referenceDateTimestamp(fields.referenceDate), nextStyle.lang),
578
+ style: nextStyle,
579
+ ...nextLocalDeclared === void 0 ? {} : { localDeclared: nextLocalDeclared },
580
+ field: {
581
+ id: fields.createId?.() ?? "00000000-0000-4000-8000-000000000001",
582
+ type: format === void 0 ? "slidenum" : resolvedFormat
583
+ }
584
+ });
585
+ continue;
586
+ }
587
+ collectRuns(child.children, nextStyle, runs, theme, fields, path, nextLocalDeclared);
588
+ }
589
+ }
590
+ function resolveDecoration(value) {
591
+ return value ?? "none";
592
+ }
593
+ function resolveTransform(value) {
594
+ return value ?? "none";
595
+ }
596
+ function resolveTextShadowModel(theme, value) {
597
+ if (value === void 0 || value === "none") return { kind: "none" };
598
+ return {
599
+ kind: "shadow",
600
+ shadow: resolveShadow(theme, value, "textShadow")
601
+ };
602
+ }
603
+ function resolveAlign(value, fallback = "left") {
604
+ return value ?? fallback;
605
+ }
606
+ const verticalAlignOffsets = {
607
+ top: 0,
608
+ middle: .5,
609
+ bottom: 1
610
+ };
611
+ const bodyAnchors = {
612
+ top: "t",
613
+ middle: "ctr",
614
+ bottom: "b"
615
+ };
616
+ function resolveVerticalAlign(value) {
617
+ return value ?? "top";
618
+ }
619
+ function resolveListModel(value) {
620
+ if (value === void 0) return void 0;
621
+ switch (value.type) {
622
+ case "bullet": return {
623
+ type: "bullet",
624
+ character: value.character ?? "•",
625
+ level: value.level ?? 0
626
+ };
627
+ case "number": return {
628
+ type: "number",
629
+ style: value.style ?? "arabicPeriod",
630
+ startAt: value.startAt ?? 1,
631
+ level: value.level ?? 0
632
+ };
633
+ default: return value;
634
+ }
635
+ }
636
+ function transformAttribute(transform) {
637
+ switch (transform) {
638
+ case "none": return [];
639
+ case "uppercase": return ["cap=\"all\""];
640
+ default: return transform;
641
+ }
642
+ }
643
+ function fontClassificationAttrsForRun(fontRef, themeFont, weight, faceStyle) {
644
+ if (themeFont !== void 0 || !isFont(fontRef)) return "";
645
+ const cls = resolveFontClassification(fontRef, weightValue(weight), faceStyle ?? "normal");
646
+ if (cls === void 0) return "";
647
+ return `${cls.panose === void 0 ? "" : ` panose="${cls.panose}"`} pitchFamily="${cls.pitchFamily}"`;
648
+ }
649
+ function runFontSlotsXml(style, differential = false) {
650
+ const hasLatin = style.fontFamily !== void 0 || style.themeFont !== void 0;
651
+ const hasEa = style.eastAsianFontFamily !== void 0 || style.eastAsianThemeFont !== void 0;
652
+ let latinXml = "";
653
+ let csXml = "";
654
+ if (!differential || hasLatin) {
655
+ const latinFont = normalizedFonts(style)[0];
656
+ const latinClsAttrs = fontClassificationAttrsForRun(style.fontFamily, style.themeFont, style.fontWeight, style.fontStyle);
657
+ const latinTypeface = style.themeFont === "major" ? "+mj-lt" : style.themeFont === "minor" ? "+mn-lt" : latinFont.family;
658
+ const csTypeface = style.themeFont === "major" ? "+mj-cs" : style.themeFont === "minor" ? "+mn-cs" : latinFont.family;
659
+ latinXml = `<a:latin typeface="${escapedXml(latinTypeface, "style.fontFamily")}"${latinClsAttrs}/>`;
660
+ csXml = `<a:cs typeface="${escapedXml(csTypeface, "style.fontFamily")}"/>`;
661
+ }
662
+ let eaXml = "";
663
+ if (!differential || hasEa) {
664
+ const eaRef = hasEa ? style.eastAsianFontFamily : style.fontFamily;
665
+ const eaTheme = hasEa ? style.eastAsianThemeFont : style.themeFont;
666
+ const eaFont = normalizedFontsForReference(eaRef, style.fontWeight, style.fontStyle)[0];
667
+ const eaClsAttrs = fontClassificationAttrsForRun(eaRef, eaTheme, style.fontWeight, style.fontStyle);
668
+ eaXml = `<a:ea typeface="${escapedXml(eaTheme === "major" ? "+mj-ea" : eaTheme === "minor" ? "+mn-ea" : eaFont.family, "style.eastAsianFontFamily")}"${eaClsAttrs}/>`;
669
+ }
670
+ return `${latinXml}${eaXml}${csXml}`;
671
+ }
672
+ function resolveRunColor(theme, fill) {
673
+ if (!isTextGradient(fill)) return theme.resolveColor(fill);
674
+ resolveGradientSpec(theme, fill, void 0, "style.color");
675
+ return fill;
676
+ }
677
+ function runPropertiesXml(style, tag, theme, mode = "resolved") {
678
+ const shadowXml = style.textShadow === "none" ? "<a:effectLst/>" : textShadowXml(theme, style.textShadow);
679
+ const includeKern = tag === "a:rPr" || tag === "a:defRPr";
680
+ if (mode === "differential") {
681
+ const attributes = [];
682
+ if (style.lang !== void 0) attributes.push(`lang="${escapedXml(style.lang, "style.lang")}"`);
683
+ if (style.fontSize !== void 0) attributes.push(`sz="${centipoints(fontSizePoints(style.fontSize))}"`);
684
+ if (style.fontWeight !== void 0) {
685
+ const font = normalizedFonts(style)[0];
686
+ attributes.push(`b="${outputBold(font) ? 1 : 0}"`);
687
+ }
688
+ if (style.fontStyle !== void 0) attributes.push(`i="${style.fontStyle === "italic" ? 1 : 0}"`);
689
+ attributes.push(...textDecorationAttributes(style.textDecoration));
690
+ if (includeKern && style.fontSize !== void 0) attributes.push("kern=\"100\"");
691
+ if (style.textTransform !== void 0) attributes.push(...transformAttribute(resolveTransform(style.textTransform)));
692
+ if (style.letterSpacing !== void 0) attributes.push(`spc="${letterSpacingCentipoints(style.letterSpacing)}"`);
693
+ if (style.baselineShift !== void 0) {
694
+ const baseline = parseBaselineShiftThousandths(style.baselineShift);
695
+ if (baseline !== void 0) attributes.push(`baseline="${baseline}"`);
696
+ }
697
+ const fillXml = style.color === void 0 ? "" : textFillXml(theme, style.color);
698
+ const strokeXml = textStrokeXml(theme, style.textStroke);
699
+ const fontXml = style.fontFamily !== void 0 || style.themeFont !== void 0 || style.eastAsianFontFamily !== void 0 || style.eastAsianThemeFont !== void 0 ? runFontSlotsXml(style, true) : "";
700
+ const attrText = attributes.length === 0 ? "" : ` ${attributes.join(" ")}`;
701
+ const childrenXml = `${strokeXml}${fillXml}${shadowXml}${fontXml}`;
702
+ return childrenXml === "" ? `<${tag}${attrText}/>` : `<${tag}${attrText}>${childrenXml}</${tag}>`;
703
+ }
704
+ const font = normalizedFonts(style)[0];
705
+ const points = fontSizePoints(style.fontSize);
706
+ const bold = outputBold(font);
707
+ const strokeXml = textStrokeXml(theme, style.textStroke);
708
+ const fontSlots = runFontSlotsXml(style);
709
+ const transform = resolveTransform(style.textTransform);
710
+ const baselineAttr = style.baselineShift === void 0 ? [] : (() => {
711
+ const baseline = parseBaselineShiftThousandths(style.baselineShift);
712
+ return baseline === void 0 ? [] : [`baseline="${baseline}"`];
713
+ })();
714
+ const chartDefault = mode === "chart-default";
715
+ return `<${tag} ${[
716
+ ...style.lang !== void 0 ? [`lang="${escapedXml(style.lang, "style.lang")}"`] : [],
717
+ `sz="${centipoints(points)}"`,
718
+ `b="${bold ? 1 : 0}"`,
719
+ `i="${font.style === "italic" ? 1 : 0}"`,
720
+ ...textDecorationAttributes(style.textDecoration),
721
+ ...includeKern ? ["kern=\"100\""] : [],
722
+ ...transformAttribute(transform),
723
+ ...chartDefault && style.textTransform === "none" ? ["cap=\"none\""] : [],
724
+ ...style.letterSpacing === void 0 || !chartDefault && style.letterSpacing === 0 ? [] : [`spc="${letterSpacingCentipoints(style.letterSpacing)}"`],
725
+ ...baselineAttr
726
+ ].join(" ")}>${strokeXml}${textFillXml(theme, style.color ?? "dk1")}${shadowXml}${fontSlots}</${tag}>`;
727
+ }
728
+ function displayedText(run) {
729
+ return run.style.textTransform === "uppercase" ? run.text.toUpperCase() : run.text;
730
+ }
731
+ /** Emits a native text field using a fresh or preallocated field GUID. */
732
+ function emitTextFieldRunXml(run, theme, createFieldId, differential = false) {
733
+ const fieldId = createFieldId !== void 0 ? createFieldId() : run.field?.id ?? "00000000-0000-4000-8000-000000000001";
734
+ const fieldType = run.field?.type ?? "slidenum";
735
+ const rPr = differential ? runPropertiesXml(run.localDeclared ?? {}, "a:rPr", theme, "differential") : runPropertiesXml(run.style, "a:rPr", theme);
736
+ return `<a:fld id="${escapedXml(fieldId)}" type="${fieldType}">${rPr}<a:t>${escapedXml(run.text)}</a:t></a:fld>`;
737
+ }
738
+ function runXml(run, theme, differential = false) {
739
+ if (run.field !== void 0) return emitTextFieldRunXml(run, theme, void 0, differential);
740
+ const text = escapedXml(run.text);
741
+ return `<a:r>${differential ? runPropertiesXml(run.localDeclared ?? {}, "a:rPr", theme, "differential") : runPropertiesXml(run.style, "a:rPr", theme)}<a:t xml:space="preserve">${text}</a:t></a:r>`;
742
+ }
743
+ function textResourceClaims(runGroups, declaredFonts = []) {
744
+ const used = /* @__PURE__ */ new Map();
745
+ const includeFont = (font, text) => {
746
+ const key = `${font.family.toLocaleLowerCase("en-US")}\u0000${font.weight}\u0000${font.style}`;
747
+ const entry = used.get(key) ?? {
748
+ fonts: [],
749
+ fontPolicies: /* @__PURE__ */ new Map(),
750
+ text: []
751
+ };
752
+ if (!entry.fonts.some(({ identity }) => identity === font.identity)) entry.fonts.push(font);
753
+ const policyKey = `${font.identity}\u0000${font.substitute ? 1 : 0}\u0000${font.embeddable ? 1 : 0}`;
754
+ entry.fontPolicies.set(policyKey, font);
755
+ if (text !== void 0) entry.text.push(text);
756
+ used.set(key, entry);
757
+ };
758
+ for (const font of declaredFonts) includeFont(font);
759
+ for (const runs of runGroups) {
760
+ const segmentedRuns = splitParagraphRunsForEffectiveScripts(runs.map((run) => ({
761
+ text: displayedText(run) + (run.field?.type === "slidenum" ? "0123456789" : ""),
762
+ style: run.style
763
+ })));
764
+ for (const scriptSegments of segmentedRuns) for (const seg of scriptSegments) for (const font of normalizedFonts(seg.style)) includeFont(font, seg.text);
765
+ }
766
+ const resourceClaims = [];
767
+ const fontUses = [];
768
+ const fontUsages = [];
769
+ const missingGlyphErrors = [];
770
+ const missingResourceMap = /* @__PURE__ */ new Map();
771
+ const missingGlyphSets = /* @__PURE__ */ new Map();
772
+ const missingGlyphFonts = /* @__PURE__ */ new Map();
773
+ const referencedFontMap = /* @__PURE__ */ new Map();
774
+ for (const [key, entry] of used) {
775
+ for (const font of entry.fontPolicies.values()) fontUses.push({
776
+ family: font.family,
777
+ weight: font.weight,
778
+ style: font.style,
779
+ claimKey: key,
780
+ identity: font.identity,
781
+ ...font.data === void 0 ? {} : { bytes: font.data },
782
+ substitute: font.substitute,
783
+ embeddable: font.embeddable,
784
+ bold: outputBold(font),
785
+ italic: font.style === "italic"
786
+ });
787
+ for (const font of entry.fonts) {
788
+ if (!referencedFontMap.has(key)) referencedFontMap.set(key, {
789
+ family: font.family,
790
+ weight: font.weight,
791
+ style: font.style
792
+ });
793
+ if (!font.hasResource) {
794
+ fontUsages.push({
795
+ family: font.family,
796
+ weight: font.weight,
797
+ style: font.style,
798
+ hasResource: false,
799
+ ...font.substitute ? { substitute: true } : {}
800
+ });
801
+ if (!missingResourceMap.has(key)) missingResourceMap.set(key, {
802
+ family: font.family,
803
+ weight: font.weight,
804
+ style: font.style
805
+ });
806
+ } else {
807
+ const validatedFace = validateFontFaceResource({
808
+ family: font.family,
809
+ weight: font.weight,
810
+ style: font.style,
811
+ substitute: font.substitute,
812
+ data: font.data,
813
+ identity: font.identity
814
+ });
815
+ resourceClaims.push({
816
+ kind: "font-face",
817
+ key,
818
+ identity: font.identity,
819
+ characters: entry.text.join("")
820
+ });
821
+ const missing = findMissingFontGlyphs(validatedFace, entry.text.join(""), requiresVisibleFontGlyph);
822
+ const embeddable = isTrueTypeFontEmbeddable(font.data, font.family, font.substitute, font.embeddable, font.identity);
823
+ fontUsages.push({
824
+ family: font.family,
825
+ weight: font.weight,
826
+ style: font.style,
827
+ hasResource: true,
828
+ ...font.substitute ? { substitute: true } : {},
829
+ embeddable,
830
+ ...missing.length > 0 ? { missingGlyphs: missing } : {}
831
+ });
832
+ if (missing.length > 0) {
833
+ const set = missingGlyphSets.get(key) ?? /* @__PURE__ */ new Set();
834
+ for (const ch of missing) set.add(ch);
835
+ missingGlyphSets.set(key, set);
836
+ if (!missingGlyphFonts.has(key)) missingGlyphFonts.set(key, {
837
+ family: font.family,
838
+ weight: font.weight,
839
+ style: font.style
840
+ });
841
+ const shown = missing.slice(0, 10).join(" ");
842
+ const extra = missing.length - 10;
843
+ const message = `${font.family} is missing glyphs for characters ${shown}${extra > 0 ? `, and ${extra} more characters` : ""}`;
844
+ missingGlyphErrors.push({
845
+ message,
846
+ font: {
847
+ family: font.family,
848
+ weight: font.weight,
849
+ style: font.style
850
+ },
851
+ characters: missing
852
+ });
853
+ }
854
+ }
855
+ }
856
+ }
857
+ return {
858
+ resourceClaims,
859
+ fontUses,
860
+ fontUsages,
861
+ missingGlyphErrors,
862
+ unmeasuredIssues: {
863
+ missingResourceFonts: [...missingResourceMap.values()],
864
+ missingGlyphFonts: [...missingGlyphFonts.entries()].map(([key, descriptor]) => ({
865
+ ...descriptor,
866
+ missingGlyphs: [...missingGlyphSets.get(key) ?? []]
867
+ })),
868
+ referencedFonts: [...referencedFontMap.values()]
869
+ }
870
+ };
871
+ }
872
+ /** Claims explicitly declared theme faces without attributing text characters to them. */
873
+ function declaredFontResourceClaims(font) {
874
+ const faces = font.faces ?? [];
875
+ return textResourceClaims([], faces.length === 0 ? normalizedFontsForReference(font, void 0, void 0) : faces.flatMap((face) => {
876
+ const { weight, style } = resolveDeclaredFaceSlot(face);
877
+ return normalizedFontsForReference(font, weight, style);
878
+ }));
879
+ }
880
+ function alignmentValue(value) {
881
+ if (value === void 0) return void 0;
882
+ switch (value) {
883
+ case "left": return "l";
884
+ case "center": return "ctr";
885
+ case "right": return "r";
886
+ case "justify": return "just";
887
+ default: return value;
888
+ }
889
+ }
890
+ function paragraphXml(paragraph, theme, differential = false) {
891
+ const style = differential ? paragraph.localStyle ?? {} : paragraph.style;
892
+ const { runs } = paragraph;
893
+ const attributes = [];
894
+ const align = alignmentValue(style.align);
895
+ if (align !== void 0) attributes.push(`algn="${align}"`);
896
+ if (paragraphBaseDirection(runs.map((run) => displayedText(run)).join("")) === "rtl") attributes.push("rtl=\"1\"");
897
+ const resolvedList = resolveListModel(style.list);
898
+ if (resolvedList !== void 0) attributes.push(`lvl="${resolvedList.level}"`);
899
+ if (style.marginLeft !== void 0 || !differential && paragraph.resolvedListIndent !== void 0) {
900
+ const marginLeft = style.marginLeft ?? paragraph.resolvedListIndent.marginLeft;
901
+ attributes.push(`marL="${paragraphIndentToEmu(marginLeft)}"`);
902
+ }
903
+ if (style.indent !== void 0 || !differential && paragraph.resolvedListIndent !== void 0) {
904
+ const indent = style.indent ?? paragraph.resolvedListIndent.indent;
905
+ attributes.push(`indent="${paragraphIndentToEmu(indent)}"`);
906
+ }
907
+ const lineSpacing = lineSpacingXml(style.lineHeight);
908
+ const spacingAfter = style.spacingAfter === void 0 || style.spacingAfter === 0 ? "" : `<a:spcAft><a:spcPts val="${spacingCentipoints(style.spacingAfter, "spacingAfter")}"/></a:spcAft>`;
909
+ let list = "";
910
+ if (resolvedList !== void 0) switch (resolvedList.type) {
911
+ case "bullet":
912
+ list = `<a:buChar char="${xmlEscape(resolvedList.character)}"/>`;
913
+ break;
914
+ case "number":
915
+ list = `<a:buAutoNum type="${resolvedList.style}" startAt="${resolvedList.startAt}"/>`;
916
+ break;
917
+ default: return resolvedList;
918
+ }
919
+ const endStyle = differential ? paragraph.localEndStyle ?? {} : paragraph.endStyle;
920
+ let defRPr = "";
921
+ if (runs.length === 0) {
922
+ const candidate = runPropertiesXml(endStyle, "a:defRPr", theme, differential ? "differential" : "resolved");
923
+ defRPr = differential && candidate === "<a:defRPr/>" ? "" : candidate;
924
+ }
925
+ const pPrChildren = `${lineSpacing}${spacingAfter}${list}${defRPr}`;
926
+ const pPr = attributes.length + pPrChildren.length === 0 ? "" : `<a:pPr${attributes.length === 0 ? "" : ` ${attributes.join(" ")}`}${pPrChildren.length === 0 ? "/>" : `>${pPrChildren}</a:pPr>`}`;
927
+ const endProperties = runs.length === 0 ? runPropertiesXml(endStyle, "a:endParaRPr", theme, differential ? "differential" : "resolved") : "";
928
+ return `<a:p>${pPr}${runs.map((run) => runXml(run, theme, differential)).join("")}${endProperties}</a:p>`;
929
+ }
930
+ function normalizeParagraphs(children, textStyle, theme, fields, placeholder, localSlideDeclaredStyle, allowParagraphMotion = false) {
931
+ const baseRunStyle = {
932
+ fontFamily: textStyle.fontFamily,
933
+ ...textStyle.eastAsianFontFamily === void 0 ? {} : { eastAsianFontFamily: textStyle.eastAsianFontFamily },
934
+ fontSize: textStyle.fontSize,
935
+ fontWeight: textStyle.fontWeight,
936
+ fontStyle: textStyle.fontStyle,
937
+ color: textStyle.color,
938
+ themeFont: textStyle.themeFont,
939
+ ...textStyle.eastAsianThemeFont === void 0 ? {} : { eastAsianThemeFont: textStyle.eastAsianThemeFont },
940
+ letterSpacing: textStyle.letterSpacing,
941
+ textTransform: textStyle.textTransform,
942
+ textDecoration: textStyle.textDecoration,
943
+ textShadow: textStyle.textShadow,
944
+ textStroke: textStyle.textStroke,
945
+ lang: textStyle.lang
946
+ };
947
+ validateRunStyle(baseRunStyle);
948
+ const localSlideRunDeclared = placeholder === void 0 ? void 0 : mergeLocalRunDeclared({}, localSlideDeclaredStyle ?? {}, placeholder.masterTheme);
949
+ const localSlidePStyle = placeholder === void 0 ? void 0 : {
950
+ ...hasLocalDeclaration(localSlideDeclaredStyle, "lineHeight") ? { lineHeight: localSlideDeclaredStyle["lineHeight"] } : {},
951
+ ...hasLocalDeclaration(localSlideDeclaredStyle, "align") ? { align: localSlideDeclaredStyle["align"] } : {},
952
+ ...hasLocalDeclaration(localSlideDeclaredStyle, "spacingAfter") ? { spacingAfter: localSlideDeclaredStyle["spacingAfter"] } : {}
953
+ };
954
+ const paragraphs = [];
955
+ const paragraphMotions = [];
956
+ let inline = [];
957
+ const baseParagraphStyle = {
958
+ ...textStyle.lineHeight === void 0 ? {} : { lineHeight: textStyle.lineHeight },
959
+ ...textStyle.align === void 0 ? {} : { align: textStyle.align },
960
+ ...textStyle.spacingAfter === void 0 ? {} : { spacingAfter: textStyle.spacingAfter },
961
+ ...textStyle.lang === void 0 ? {} : { lang: textStyle.lang }
962
+ };
963
+ const flushInline = () => {
964
+ if (inline.length > 0) {
965
+ paragraphs.push({
966
+ runs: inline,
967
+ style: baseParagraphStyle,
968
+ ...localSlidePStyle === void 0 ? {} : { localStyle: localSlidePStyle },
969
+ endStyle: baseRunStyle,
970
+ ...localSlideRunDeclared === void 0 ? {} : { localEndStyle: localSlideRunDeclared },
971
+ wrap: textStyle.textWrap ?? "normal"
972
+ });
973
+ inline = [];
974
+ }
975
+ };
976
+ const appendParagraphNode = (node, path, currentStep) => {
977
+ flushInline();
978
+ const unknown = Object.keys(node.props).find((key) => key !== "style" && !textAuthorMetadataKeys.has(key) && !(allowParagraphMotion && motionPropKeySet.has(key)));
979
+ if (unknown !== void 0) {
980
+ if (motionPropKeySet.has(unknown)) throw new CapabilityError("unsupported-motion-host", "Paragraph motion properties are only supported inside page-level Text and Shape");
981
+ throw new CapabilityError("unknown-parameter", `P contains unimplemented parameter ${unknown}`, path, {
982
+ prop: unknown,
983
+ field: unknown
984
+ });
985
+ }
986
+ if (allowParagraphMotion) {
987
+ const motionProps = pickMotionProps(node.props);
988
+ validateMotionFlag(motionProps["motion"], path);
989
+ if (Object.keys(motionProps).length > 0) paragraphMotions.push({
990
+ paragraphIndex: paragraphs.length,
991
+ path,
992
+ props: motionProps,
993
+ ...currentStep === void 0 ? {} : { step: currentStep }
994
+ });
995
+ }
996
+ const effectiveTheme = placeholder?.masterTheme ?? theme;
997
+ const localPStyle = parseParagraphStyle(node.props["style"], path, effectiveTheme);
998
+ const rawLevel = localPStyle.list?.level ?? 0;
999
+ const levelBase = placeholder === void 0 ? void 0 : resolvePlaceholderLevelTextStyle(placeholder, rawLevel, localSlideDeclaredStyle);
1000
+ const effectiveBaseP = levelBase === void 0 ? baseParagraphStyle : {
1001
+ ...levelBase.lineHeight === void 0 ? {} : { lineHeight: levelBase.lineHeight },
1002
+ ...levelBase.align === void 0 ? {} : { align: levelBase.align },
1003
+ ...levelBase.spacingAfter === void 0 ? {} : { spacingAfter: levelBase.spacingAfter },
1004
+ ...levelBase.lang === void 0 ? {} : { lang: levelBase.lang },
1005
+ ...levelBase.list === void 0 ? {} : { list: levelBase.list }
1006
+ };
1007
+ const levelRunBase = levelBase === void 0 ? baseRunStyle : resolveRunStyleFromRecord(levelBase, effectiveTheme);
1008
+ const style = {
1009
+ ...effectiveBaseP,
1010
+ ...localPStyle
1011
+ };
1012
+ const paragraphRunStyle = mergeRunStyle(levelRunBase, {
1013
+ fontFamily: style.fontFamily,
1014
+ eastAsianFontFamily: style.eastAsianFontFamily,
1015
+ fontSize: style.fontSize,
1016
+ fontWeight: style.fontWeight,
1017
+ fontStyle: style.fontStyle,
1018
+ color: style.color,
1019
+ letterSpacing: style.letterSpacing,
1020
+ textTransform: style.textTransform,
1021
+ textDecoration: style.textDecoration,
1022
+ textShadow: style.textShadow,
1023
+ textStroke: style.textStroke,
1024
+ lang: style.lang
1025
+ }, effectiveTheme);
1026
+ const mergedLocalPStyle = placeholder === void 0 ? void 0 : {
1027
+ ...localSlidePStyle,
1028
+ ...localPStyle
1029
+ };
1030
+ const localPRunDeclared = placeholder === void 0 ? void 0 : mergeLocalRunDeclared(localSlideRunDeclared ?? {}, localPStyle, effectiveTheme);
1031
+ const runs = [];
1032
+ collectRuns(node.children, paragraphRunStyle, runs, effectiveTheme, fields, path, localPRunDeclared);
1033
+ paragraphs.push({
1034
+ runs,
1035
+ style,
1036
+ ...mergedLocalPStyle === void 0 ? {} : { localStyle: mergedLocalPStyle },
1037
+ endStyle: paragraphRunStyle,
1038
+ ...localPRunDeclared === void 0 ? {} : { localEndStyle: localPRunDeclared },
1039
+ wrap: textStyle.textWrap ?? "normal"
1040
+ });
1041
+ };
1042
+ for (const [index, child] of children.entries()) {
1043
+ if (!hostChild(child)) throw new CapabilityError("invalid-text-child", "Text content tree contains invalid nodes");
1044
+ if (isHostText(child) || isInlineRichTextNodeType(child.type)) {
1045
+ collectRuns([child], baseRunStyle, inline, theme, fields, "", localSlideRunDeclared, index);
1046
+ continue;
1047
+ }
1048
+ if (child.type === "motion-step") {
1049
+ if (!allowParagraphMotion) throw new CapabilityError("unsupported-text-child", "Step cannot be used directly inside this text container");
1050
+ flushInline();
1051
+ const stepPath = componentLabel(child, index);
1052
+ const step = parseStepDeclarationProps(child.props, stepPath);
1053
+ for (const [nestedIndex, nested] of child.children.entries()) {
1054
+ if (!hostChild(nested) || isHostText(nested) || nested.type !== "paragraph") throw new CapabilityError("unsupported-text-child", "Step inside Text or Shape can only contain P paragraphs");
1055
+ appendParagraphNode(nested, `${stepPath}/${componentLabel(nested, nestedIndex)}`, step);
1056
+ }
1057
+ continue;
1058
+ }
1059
+ if (child.type !== "paragraph") throw new CapabilityError("unsupported-text-child", `${child.type} cannot be used directly in text box`);
1060
+ appendParagraphNode(child, componentLabel(child, index));
1061
+ }
1062
+ flushInline();
1063
+ if (paragraphs.length === 0) paragraphs.push({
1064
+ runs: [],
1065
+ style: baseParagraphStyle,
1066
+ ...localSlidePStyle === void 0 ? {} : { localStyle: localSlidePStyle },
1067
+ endStyle: baseRunStyle,
1068
+ ...localSlideRunDeclared === void 0 ? {} : { localEndStyle: localSlideRunDeclared },
1069
+ wrap: textStyle.textWrap ?? "normal"
1070
+ });
1071
+ return {
1072
+ paragraphs,
1073
+ paragraphMotions
1074
+ };
1075
+ }
1076
+ function fontDetailsFromSource(source) {
1077
+ return { font: {
1078
+ family: source.family,
1079
+ weight: source.weight,
1080
+ style: source.style
1081
+ } };
1082
+ }
1083
+ function fontDetailsFromRunStyle(style) {
1084
+ const normalized = normalizedFonts(style)[0];
1085
+ if (normalized !== void 0) return {
1086
+ family: normalized.family,
1087
+ weight: normalized.weight,
1088
+ style: normalized.style
1089
+ };
1090
+ return {
1091
+ family: fontFamilyValue(style.fontFamily).family,
1092
+ weight: weightValue(style.fontWeight),
1093
+ style: style.fontStyle ?? "normal"
1094
+ };
1095
+ }
1096
+ function measureFace(source) {
1097
+ if (!source.hasResource || source.data === void 0) throw new CapabilityError("font-measurement-unavailable", `Content-sized text is missing explicit font resource for ${source.family} ${source.weight} ${source.style}`, void 0, fontDetailsFromSource(source));
1098
+ return openMeasureFontFace({
1099
+ family: source.family,
1100
+ weight: source.weight,
1101
+ style: source.style,
1102
+ substitute: source.substitute,
1103
+ data: source.data,
1104
+ identity: source.identity
1105
+ });
1106
+ }
1107
+ function measureRunFace(style) {
1108
+ const candidates = normalizedFonts(style).filter((candidate) => candidate.hasResource);
1109
+ const unique = candidates.filter((candidate, index) => candidates.findIndex((other) => other.identity === candidate.identity) === index);
1110
+ if (unique.length !== 1) {
1111
+ const descriptor = fontDetailsFromRunStyle(style);
1112
+ throw new CapabilityError(unique.length === 0 ? "font-measurement-unavailable" : "conflicting-resource", unique.length === 0 ? "Content-sized text must provide a font file for each actually used weight and style" : "Multiple metrics files found for the same font weight and style; cannot determine measurement basis", void 0, {
1113
+ font: descriptor,
1114
+ ...unique.length === 0 ? {} : { reason: "conflicting-resource" }
1115
+ });
1116
+ }
1117
+ return measureFace(unique[0]);
1118
+ }
1119
+ function missingCharacters(face, text) {
1120
+ return findMissingFontGlyphs(face, text, requiresVisibleFontGlyph);
1121
+ }
1122
+ function pieceWidthPoints(face, advances, points, tenths, bold) {
1123
+ const nativeEighthPointGrid = 8;
1124
+ const twipsPerPoint = 20;
1125
+ let unitsSum = 0;
1126
+ let glyphEighth = 0;
1127
+ let twips = 0;
1128
+ for (const xAdvance of advances) {
1129
+ unitsSum += xAdvance;
1130
+ const advance = xAdvance / face.unitsPerEm * points;
1131
+ glyphEighth += Math.round(advance * nativeEighthPointGrid) / nativeEighthPointGrid;
1132
+ const tenthAdvance = xAdvance / face.unitsPerEm * tenths;
1133
+ twips += Math.round(tenthAdvance * twipsPerPoint) / twipsPerPoint + (bold ? 1 / twipsPerPoint : 0);
1134
+ }
1135
+ const natural = unitsSum / face.unitsPerEm * points;
1136
+ const eighthCeil = Math.ceil(natural * nativeEighthPointGrid) / nativeEighthPointGrid;
1137
+ return Math.max(natural, eighthCeil, glyphEighth, twips);
1138
+ }
1139
+ function rangeWidth(pieces, text, start, end) {
1140
+ let widthPx = 0;
1141
+ let spacing = 0;
1142
+ let pendingNegativeTracking = 0;
1143
+ for (const piece of pieces) {
1144
+ const from = Math.max(start, piece.start);
1145
+ const to = Math.min(end, piece.end);
1146
+ if (from >= to) continue;
1147
+ const source = text.slice(from, to);
1148
+ const transformed = piece.style.textTransform === "uppercase" ? source.toUpperCase() : source;
1149
+ const visible = Array.from(transformed).filter(requiresFontGlyph).join("");
1150
+ if (visible === "") continue;
1151
+ const face = piece.face;
1152
+ const unscaledPoints = fontSizePoints(piece.style.fontSize);
1153
+ const points = piece.style.baselineShift !== void 0 && parseBaselineShiftThousandths(piece.style.baselineShift) !== void 0 ? unscaledPoints * (2 / 3) : unscaledPoints;
1154
+ const tenths = Math.ceil(centipoints(points) / 10) / 10;
1155
+ const shapedPt = pieceWidthPoints(face, shapeFontAdvances(face, visible), points, tenths, piece.bold);
1156
+ const unkernedPt = pieceWidthPoints(face, unkernedFontAdvances(face, visible), points, tenths, piece.bold);
1157
+ widthPx += Math.max(shapedPt, unkernedPt) * (4 / 3);
1158
+ const pieceTracking = piece.style.letterSpacing ?? 0;
1159
+ const visibleCount = Array.from(graphemes.segment(visible)).length;
1160
+ if (visibleCount > 0) {
1161
+ if (pendingNegativeTracking < 0) {
1162
+ spacing += pendingNegativeTracking;
1163
+ pendingNegativeTracking = 0;
1164
+ }
1165
+ if (pieceTracking > 0) spacing += pieceTracking * visibleCount;
1166
+ else if (pieceTracking < 0) {
1167
+ spacing += pieceTracking * (visibleCount - 1);
1168
+ pendingNegativeTracking = pieceTracking;
1169
+ }
1170
+ }
1171
+ }
1172
+ return widthPx + spacing;
1173
+ }
1174
+ function trimLineEnd(text, start, end) {
1175
+ let trimmed = end;
1176
+ while (trimmed > start && /\s/u.test(text[trimmed - 1] ?? "")) trimmed -= 1;
1177
+ return trimmed;
1178
+ }
1179
+ function graphemeEnds(text, start, end) {
1180
+ const result = [];
1181
+ for (const segment of graphemes.segment(text)) {
1182
+ const boundary = segment.index + segment.segment.length;
1183
+ if (boundary > start && boundary <= end) result.push(boundary);
1184
+ }
1185
+ return result;
1186
+ }
1187
+ function trimMandatoryBreakEnd(text, start, end) {
1188
+ let trimmed = end;
1189
+ while (trimmed > start && /[\n\r\v\f\u0085\u2028\u2029]/u.test(text[trimmed - 1] ?? "")) trimmed -= 1;
1190
+ return trimmed;
1191
+ }
1192
+ function wrapParagraph(text, pieces, width, firstLineWidth = width) {
1193
+ if (text === "") return {
1194
+ lines: [{
1195
+ start: 0,
1196
+ end: 0,
1197
+ width: 0
1198
+ }],
1199
+ width: 0
1200
+ };
1201
+ const breaks = [];
1202
+ const breaker = new LineBreaker(text);
1203
+ let position = 0;
1204
+ for (let next = breaker.nextBreak(); next !== null; next = breaker.nextBreak()) {
1205
+ if (next.position > position) breaks.push(next);
1206
+ position = next.position;
1207
+ }
1208
+ if (position < text.length) breaks.push({
1209
+ position: text.length,
1210
+ required: false
1211
+ });
1212
+ const lines = [];
1213
+ const epsilon = .01;
1214
+ const lineWidth = () => lines.length === 0 ? firstLineWidth : width;
1215
+ let lineStart = 0;
1216
+ let lineEnd = 0;
1217
+ let unitStart = 0;
1218
+ let endedWithRequiredBreak = false;
1219
+ for (const lineBreak of breaks) {
1220
+ const unitEnd = lineBreak.position;
1221
+ const breakContentEnd = trimMandatoryBreakEnd(text, unitStart, unitEnd);
1222
+ const required = lineBreak.required || breakContentEnd < unitEnd;
1223
+ if (rangeWidth(pieces, text, lineStart, trimLineEnd(text, lineStart, unitEnd)) <= lineWidth() + epsilon) {
1224
+ lineEnd = unitEnd;
1225
+ if (required) {
1226
+ lines.push({
1227
+ start: lineStart,
1228
+ end: lineEnd
1229
+ });
1230
+ lineStart = unitEnd;
1231
+ lineEnd = unitEnd;
1232
+ }
1233
+ unitStart = unitEnd;
1234
+ endedWithRequiredBreak = required;
1235
+ continue;
1236
+ }
1237
+ if (lineEnd > lineStart) {
1238
+ lines.push({
1239
+ start: lineStart,
1240
+ end: lineEnd
1241
+ });
1242
+ lineStart = unitStart;
1243
+ lineEnd = unitStart;
1244
+ }
1245
+ if (rangeWidth(pieces, text, unitStart, trimLineEnd(text, unitStart, unitEnd)) <= lineWidth() + epsilon) lineEnd = unitEnd;
1246
+ else {
1247
+ let chunkStart = unitStart;
1248
+ let previous = chunkStart;
1249
+ const fallbackEnd = required ? breakContentEnd : unitEnd;
1250
+ for (const boundary of graphemeEnds(text, unitStart, fallbackEnd)) {
1251
+ if (rangeWidth(pieces, text, chunkStart, trimLineEnd(text, chunkStart, boundary)) > lineWidth() + epsilon && previous > chunkStart) {
1252
+ lines.push({
1253
+ start: chunkStart,
1254
+ end: previous
1255
+ });
1256
+ chunkStart = previous;
1257
+ }
1258
+ if (rangeWidth(pieces, text, chunkStart, trimLineEnd(text, chunkStart, boundary)) > lineWidth() + epsilon && previous === chunkStart) {
1259
+ lines.push({
1260
+ start: chunkStart,
1261
+ end: boundary
1262
+ });
1263
+ chunkStart = boundary;
1264
+ }
1265
+ previous = boundary;
1266
+ }
1267
+ lineStart = chunkStart;
1268
+ lineEnd = fallbackEnd;
1269
+ }
1270
+ if (required) {
1271
+ if (lineEnd > lineStart) lines.push({
1272
+ start: lineStart,
1273
+ end: lineEnd
1274
+ });
1275
+ lineStart = unitEnd;
1276
+ lineEnd = unitEnd;
1277
+ }
1278
+ unitStart = unitEnd;
1279
+ endedWithRequiredBreak = required;
1280
+ }
1281
+ if (lineStart < text.length || lineEnd > lineStart || lines.length === 0) lines.push({
1282
+ start: lineStart,
1283
+ end: text.length
1284
+ });
1285
+ else if (endedWithRequiredBreak) lines.push({
1286
+ start: text.length,
1287
+ end: text.length
1288
+ });
1289
+ const lineWidths = lines.map(({ start, end }) => rangeWidth(pieces, text, start, trimLineEnd(text, start, end)));
1290
+ return {
1291
+ lines: lines.map((line, index) => ({
1292
+ ...line,
1293
+ width: lineWidths[index]
1294
+ })),
1295
+ width: Math.max(0, ...lineWidths)
1296
+ };
1297
+ }
1298
+ function paragraphLineHeight(paragraph) {
1299
+ if (paragraph.style.lineHeight !== void 0 && !isLineHeightPercent(paragraph.style.lineHeight)) return spacingCentipoints(positiveLength(paragraph.style.lineHeight, "lineHeight"), "lineHeight") / 75;
1300
+ const styles = paragraph.runs.length > 0 ? splitParagraphRunsForEffectiveScripts(paragraph.runs.map((run) => ({
1301
+ text: displayedText(run),
1302
+ style: run.style
1303
+ }))).flatMap((segments, idx) => paragraph.runs[idx].text === "" ? [paragraph.runs[idx].style] : segments.map((seg) => seg.style)) : [paragraph.endStyle];
1304
+ let maximum = 0;
1305
+ for (const style of styles) {
1306
+ const face = measureRunFace(style);
1307
+ const lineHeight = (face.ascent - face.descent + face.lineGap) / face.unitsPerEm * fontSizePoints(style.fontSize) * (4 / 3);
1308
+ if (!Number.isFinite(lineHeight) || lineHeight <= 0) throw new CapabilityError("font-metrics-invalid", "Font line metrics must produce a finite positive value", void 0, {
1309
+ font: fontDetailsFromRunStyle(style),
1310
+ reason: "font-metrics-invalid"
1311
+ });
1312
+ maximum = Math.max(maximum, lineHeight);
1313
+ }
1314
+ if (maximum === 0) throw new CapabilityError("font-measurement-unavailable", "Content-sized text is missing font to determine line spacing", void 0, { font: fontDetailsFromRunStyle(paragraph.endStyle) });
1315
+ if (paragraph.style.lineHeight !== void 0) {
1316
+ const factor = lineHeightPercentThousandths(paragraph.style.lineHeight) / 1e5;
1317
+ const scaled = maximum * factor;
1318
+ if (!Number.isFinite(scaled) || scaled <= 0) throw new CapabilityError("font-metrics-invalid", "Font line metrics must produce a finite positive value");
1319
+ return scaled;
1320
+ }
1321
+ return spacingCentipoints(maximum, "lineHeight") / 75;
1322
+ }
1323
+ function paragraphBaseline(paragraph) {
1324
+ if (paragraph.runs.length !== 1 || paragraph.runs[0].text === "") return;
1325
+ const run = paragraph.runs[0];
1326
+ const segments = splitParagraphRunsForEffectiveScripts([{
1327
+ text: displayedText(run),
1328
+ style: run.style
1329
+ }])[0];
1330
+ if (segments.length !== 1) return;
1331
+ const style = segments[0].style;
1332
+ const face = measureRunFace(style);
1333
+ const fontSize = fontSizePoints(style.fontSize) * (4 / 3);
1334
+ const naturalLineHeight = (face.ascent - face.descent + face.lineGap) / face.unitsPerEm * fontSize;
1335
+ const leading = (paragraphLineHeight(paragraph) - naturalLineHeight) / 2;
1336
+ return face.ascent / face.unitsPerEm * fontSize + leading;
1337
+ }
1338
+ function paragraphPieces(paragraph) {
1339
+ const sourceRuns = paragraph.runs.length > 0 ? paragraph.runs : [{
1340
+ text: "",
1341
+ style: paragraph.endStyle
1342
+ }];
1343
+ const pieces = [];
1344
+ let start = 0;
1345
+ const segmentedRuns = splitParagraphRunsForEffectiveScripts(sourceRuns.map((run) => ({
1346
+ text: displayedText(run),
1347
+ style: run.style
1348
+ })));
1349
+ for (let runIndex = 0; runIndex < segmentedRuns.length; runIndex += 1) {
1350
+ const segments = segmentedRuns[runIndex];
1351
+ const bold = outputBold(normalizedFonts(sourceRuns[runIndex].style)[0]);
1352
+ for (const seg of segments) {
1353
+ const face = measureRunFace(seg.style);
1354
+ const letterSpacing = seg.style.letterSpacing === void 0 ? void 0 : letterSpacingCentipoints(seg.style.letterSpacing) / 75;
1355
+ const measureStyle = letterSpacing === void 0 ? seg.style : {
1356
+ ...seg.style,
1357
+ letterSpacing
1358
+ };
1359
+ pieces.push({
1360
+ text: seg.text,
1361
+ style: measureStyle,
1362
+ start,
1363
+ end: start + seg.text.length,
1364
+ face,
1365
+ bold
1366
+ });
1367
+ start += seg.text.length;
1368
+ }
1369
+ }
1370
+ return {
1371
+ text: pieces.map((piece) => piece.text).join(""),
1372
+ pieces
1373
+ };
1374
+ }
1375
+ function computeDefaultListIndentMetrics(paragraph) {
1376
+ const resolvedList = resolveListModel(paragraph.style.list);
1377
+ if (resolvedList === void 0) return void 0;
1378
+ const baseFontPx = fontSizePoints((paragraph.runs[0]?.style ?? paragraph.endStyle).fontSize) * 4 / 3;
1379
+ const hangingIndent = Math.min(maximumParagraphIndentPx, Math.max(baseFontPx * 1.25, 20));
1380
+ const contentIndent = Math.min(maximumParagraphIndentPx, resolvedList.level * (baseFontPx * 1.5) + hangingIndent);
1381
+ return {
1382
+ levelIndent: contentIndent - hangingIndent,
1383
+ hangingIndent,
1384
+ contentIndent,
1385
+ baseFontPx
1386
+ };
1387
+ }
1388
+ function listIndentMetrics(paragraph) {
1389
+ const defaults = computeDefaultListIndentMetrics(paragraph);
1390
+ if (defaults === void 0) return {
1391
+ levelIndent: 0,
1392
+ hangingIndent: 0,
1393
+ contentIndent: paragraph.style.marginLeft ?? 0,
1394
+ baseFontPx: 0
1395
+ };
1396
+ if (paragraph.resolvedListIndent !== void 0) {
1397
+ const hangingIndent = -paragraph.resolvedListIndent.indent;
1398
+ const contentIndent = Math.max(0, paragraph.resolvedListIndent.marginLeft);
1399
+ return {
1400
+ levelIndent: Math.max(0, contentIndent - hangingIndent),
1401
+ hangingIndent,
1402
+ contentIndent,
1403
+ baseFontPx: defaults.baseFontPx
1404
+ };
1405
+ }
1406
+ return defaults;
1407
+ }
1408
+ /** Returns the width of the widest unbreakable span, including list indentation. */
1409
+ function measureParagraphMinContentWidth(paragraph) {
1410
+ const { text, pieces } = paragraphPieces(paragraph);
1411
+ const { contentIndent } = listIndentMetrics(paragraph);
1412
+ if (text === "") return contentIndent;
1413
+ if (paragraph.wrap === "nowrap") return wrapParagraph(text, pieces, Number.MAX_VALUE).width + contentIndent;
1414
+ const breaker = new LineBreaker(text);
1415
+ let start = 0;
1416
+ let widest = 0;
1417
+ for (let next = breaker.nextBreak(); next !== null; next = breaker.nextBreak()) {
1418
+ const contentEnd = trimMandatoryBreakEnd(text, start, next.position);
1419
+ widest = Math.max(widest, rangeWidth(pieces, text, start, trimLineEnd(text, start, contentEnd)));
1420
+ start = next.position;
1421
+ }
1422
+ return widest + contentIndent;
1423
+ }
1424
+ function paragraphMeasurement(paragraph, width) {
1425
+ const { text, pieces } = paragraphPieces(paragraph);
1426
+ const { contentIndent } = listIndentMetrics(paragraph);
1427
+ const wrapWidth = paragraph.wrap === "nowrap" ? Number.MAX_VALUE : Math.max(1, width - contentIndent);
1428
+ const firstLineIndent = paragraph.style.list === void 0 ? paragraph.style.indent ?? 0 : 0;
1429
+ const wrapped = wrapParagraph(text, pieces, wrapWidth, paragraph.wrap === "nowrap" ? wrapWidth : Math.max(1, width - contentIndent - firstLineIndent));
1430
+ const spacingAfter = paragraph.style.spacingAfter === void 0 ? 0 : spacingCentipoints(paragraph.style.spacingAfter, "spacingAfter") / 75;
1431
+ return {
1432
+ lineCount: wrapped.lines.length,
1433
+ lines: wrapped.lines,
1434
+ text,
1435
+ pieces,
1436
+ width: Math.max(...wrapped.lines.map((line, index) => line.width + contentIndent + (index === 0 ? firstLineIndent : 0))),
1437
+ lineHeight: paragraphLineHeight(paragraph),
1438
+ spacingAfter
1439
+ };
1440
+ }
1441
+ function assertParagraphsHaveVisibleGlyphs(paragraphs) {
1442
+ for (const paragraph of paragraphs) {
1443
+ const segmentedRuns = splitParagraphRunsForEffectiveScripts(paragraph.runs.map((run) => ({
1444
+ text: displayedText(run) + (run.field?.type === "slidenum" ? "0123456789" : ""),
1445
+ style: run.style
1446
+ })));
1447
+ for (const segments of segmentedRuns) for (const seg of segments) {
1448
+ if (!Array.from(seg.text).some(requiresVisibleFontGlyph)) continue;
1449
+ const missing = missingCharacters(measureRunFace(seg.style), seg.text);
1450
+ if (missing.length > 0) {
1451
+ const font = fontDetailsFromRunStyle(seg.style);
1452
+ const shown = missing.slice(0, 10).join(" ");
1453
+ const extra = missing.length - 10;
1454
+ throw new CapabilityError("font-missing-glyph", `${font.family} is missing glyphs for characters ${shown}${extra > 0 ? `, and ${extra} more characters` : ""}`, void 0, {
1455
+ font,
1456
+ characters: missing
1457
+ });
1458
+ }
1459
+ }
1460
+ const list = paragraph.style.list;
1461
+ if (list !== void 0) {
1462
+ const markerText = list.type === "bullet" ? list.character ?? "•" : "0123456789.";
1463
+ const markerStyle = paragraph.runs[0]?.style ?? paragraph.endStyle;
1464
+ for (const seg of splitRunForEffectiveScripts(markerText, markerStyle)) {
1465
+ const missing = missingCharacters(measureRunFace(seg.style), seg.text);
1466
+ if (missing.length > 0) {
1467
+ const font = fontDetailsFromRunStyle(seg.style);
1468
+ const shown = missing.slice(0, 10).join(" ");
1469
+ const extra = missing.length - 10;
1470
+ throw new CapabilityError("font-missing-glyph", `${font.family} is missing glyphs for characters ${shown}${extra > 0 ? `, and ${extra} more characters` : ""}`, void 0, {
1471
+ font,
1472
+ characters: missing
1473
+ });
1474
+ }
1475
+ }
1476
+ }
1477
+ }
1478
+ }
1479
+ /** Measures shaped line ranges for reuse by static outline drawing. */
1480
+ function measureParagraphs(paragraphs, width = Number.POSITIVE_INFINITY) {
1481
+ assertParagraphsHaveVisibleGlyphs(paragraphs);
1482
+ const measured = paragraphs.map((paragraph) => paragraphMeasurement(paragraph, width));
1483
+ let height = 0;
1484
+ measured.forEach((paragraph, index) => {
1485
+ height += paragraph.lineCount * paragraph.lineHeight;
1486
+ if (index < measured.length - 1) height += paragraph.spacingAfter;
1487
+ });
1488
+ return {
1489
+ width: Math.max(0, ...measured.map((paragraph) => paragraph.width)),
1490
+ height,
1491
+ paragraphs: measured
1492
+ };
1493
+ }
1494
+ function roundSvgNumber(value) {
1495
+ const rounded = Math.round(value * 1e6) / 1e6;
1496
+ return Object.is(rounded, -0) ? "0" : String(rounded);
1497
+ }
1498
+ function decorationForSegment(decoration, face, fontPx, startX, endX, color, textShadow, textStroke) {
1499
+ if (endX <= startX) return void 0;
1500
+ const unitsPerEm = face.unitsPerEm;
1501
+ switch (decoration) {
1502
+ case "none": return;
1503
+ case "underline": {
1504
+ const thickness = Math.max(1, face.underlineThickness ? face.underlineThickness / unitsPerEm * fontPx : fontPx * .07);
1505
+ return {
1506
+ x: startX,
1507
+ y: (face.underlinePosition ? -face.underlinePosition / unitsPerEm * fontPx : fontPx * .12) - thickness / 2,
1508
+ width: endX - startX,
1509
+ height: thickness,
1510
+ color,
1511
+ ...textShadow === void 0 ? {} : { textShadow },
1512
+ textStroke
1513
+ };
1514
+ }
1515
+ case "line-through": {
1516
+ const thickness = Math.max(1, face.yStrikeoutSize ? face.yStrikeoutSize / unitsPerEm * fontPx : fontPx * .07);
1517
+ return {
1518
+ x: startX,
1519
+ y: -(face.yStrikeoutPosition ? face.yStrikeoutPosition / unitsPerEm * fontPx : fontPx * .3) - thickness / 2,
1520
+ width: endX - startX,
1521
+ height: thickness,
1522
+ color,
1523
+ ...textShadow === void 0 ? {} : { textShadow },
1524
+ textStroke
1525
+ };
1526
+ }
1527
+ default: return decoration;
1528
+ }
1529
+ }
1530
+ function bidiCharType(ch) {
1531
+ if (ch === "‏") return "R";
1532
+ if (ch === "‎") return "L";
1533
+ if (/^\p{Mark}$/u.test(ch)) return "NSM";
1534
+ if (/^[\u0660-\u0669\u06F0-\u06F9]$/u.test(ch)) return "AN";
1535
+ if (/^\p{Nd}$/u.test(ch)) return "EN";
1536
+ if (/^[\p{Script=Arabic}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Nko}\uFB50-\uFDFF\uFE70-\uFEFF]$/u.test(ch) && /^\p{Letter}$/u.test(ch)) return "AL";
1537
+ if (/^[\p{Script=Hebrew}\uFB1D-\uFB4F]$/u.test(ch) && /^\p{Letter}$/u.test(ch)) return "R";
1538
+ if (/^\p{Letter}$/u.test(ch)) return "L";
1539
+ if (ch === "+" || ch === "-" || ch === "−") return "ES";
1540
+ if (ch === "," || ch === "." || ch === ":" || ch === "/") return "CS";
1541
+ if (ch === "%" || /^\p{Sc}$/u.test(ch)) return "ET";
1542
+ return "ON";
1543
+ }
1544
+ function paragraphBaseDirection(text) {
1545
+ for (const ch of text) {
1546
+ const type = bidiCharType(ch);
1547
+ if (type === "R" || type === "AL") return "rtl";
1548
+ if (type === "L") return "ltr";
1549
+ }
1550
+ return "ltr";
1551
+ }
1552
+ function computeLineBidiLevels(lineText, baseOffset, baseDir) {
1553
+ const cps = [];
1554
+ let offset = baseOffset;
1555
+ for (const ch of lineText) {
1556
+ cps.push({
1557
+ start: offset,
1558
+ end: offset + ch.length,
1559
+ ch
1560
+ });
1561
+ offset += ch.length;
1562
+ }
1563
+ const n = cps.length;
1564
+ if (n === 0) return [];
1565
+ const embeddingLevel = baseDir === "rtl" ? 1 : 0;
1566
+ const dirStrong = embeddingLevel === 0 ? "L" : "R";
1567
+ const types = cps.map((cp) => bidiCharType(cp.ch));
1568
+ let prevW1 = dirStrong;
1569
+ for (let i = 0; i < n; i += 1) if (types[i] === "NSM") types[i] = prevW1;
1570
+ else prevW1 = types[i];
1571
+ let lastStrongW2 = dirStrong;
1572
+ for (let i = 0; i < n; i += 1) {
1573
+ const t = types[i];
1574
+ if (t === "L" || t === "R" || t === "AL") lastStrongW2 = t;
1575
+ else if (t === "EN" && lastStrongW2 === "AL") types[i] = "AN";
1576
+ }
1577
+ for (let i = 0; i < n; i += 1) if (types[i] === "AL") types[i] = "R";
1578
+ for (let i = 1; i < n - 1; i += 1) {
1579
+ const t = types[i];
1580
+ const prev = types[i - 1];
1581
+ const next = types[i + 1];
1582
+ if (t === "ES" && prev === "EN" && next === "EN") types[i] = "EN";
1583
+ else if (t === "CS" && (prev === "EN" && next === "EN" || prev === "AN" && next === "AN")) types[i] = prev;
1584
+ }
1585
+ for (let i = 0; i < n; i += 1) {
1586
+ if (types[i] !== "ET") continue;
1587
+ let end = i;
1588
+ while (end < n && types[end] === "ET") end += 1;
1589
+ const prevEn = i > 0 && types[i - 1] === "EN";
1590
+ const nextEn = end < n && types[end] === "EN";
1591
+ if (prevEn || nextEn) for (let k = i; k < end; k += 1) types[k] = "EN";
1592
+ i = end - 1;
1593
+ }
1594
+ for (let i = 0; i < n; i += 1) {
1595
+ const t = types[i];
1596
+ if (t === "ES" || t === "ET" || t === "CS") types[i] = "ON";
1597
+ }
1598
+ let lastStrongW7 = dirStrong;
1599
+ for (let i = 0; i < n; i += 1) {
1600
+ const t = types[i];
1601
+ if (t === "L" || t === "R") lastStrongW7 = t;
1602
+ else if (t === "EN" && lastStrongW7 === "L") types[i] = "L";
1603
+ }
1604
+ const neutralEffective = (t) => {
1605
+ if (t === "L") return "L";
1606
+ if (t === "R" || t === "EN" || t === "AN") return "R";
1607
+ };
1608
+ for (let i = 0; i < n; i += 1) {
1609
+ if (types[i] !== "ON") continue;
1610
+ let end = i;
1611
+ while (end < n && types[end] === "ON") end += 1;
1612
+ const leftSide = i === 0 ? dirStrong : neutralEffective(types[i - 1]) ?? dirStrong;
1613
+ const resolved = leftSide === (end === n ? dirStrong : neutralEffective(types[end]) ?? dirStrong) ? leftSide : dirStrong;
1614
+ for (let k = i; k < end; k += 1) types[k] = resolved;
1615
+ i = end - 1;
1616
+ }
1617
+ return cps.map((cp, index) => {
1618
+ const t = types[index];
1619
+ let level;
1620
+ if (embeddingLevel === 0) level = t === "L" ? 0 : t === "R" ? 1 : 2;
1621
+ else level = t === "R" ? 1 : 2;
1622
+ return {
1623
+ start: cp.start,
1624
+ end: cp.end,
1625
+ level
1626
+ };
1627
+ });
1628
+ }
1629
+ function buildVisualLineSegments(text, lineStart, trimmedEnd, pieces, baseDir) {
1630
+ if (lineStart >= trimmedEnd) return [];
1631
+ const spans = computeLineBidiLevels(text.slice(lineStart, trimmedEnd), lineStart, baseDir);
1632
+ const segments = [];
1633
+ let spanIdx = 0;
1634
+ for (const piece of pieces) {
1635
+ const pStart = Math.max(lineStart, piece.start);
1636
+ const pEnd = Math.min(trimmedEnd, piece.end);
1637
+ if (pStart >= pEnd) continue;
1638
+ while (spanIdx < spans.length && spans[spanIdx].end <= pStart) spanIdx += 1;
1639
+ let segStart = pStart;
1640
+ let currentLevel;
1641
+ while (spanIdx < spans.length && spans[spanIdx].start < pEnd) {
1642
+ const sp = spans[spanIdx];
1643
+ if (currentLevel === void 0) {
1644
+ currentLevel = sp.level;
1645
+ segStart = Math.max(pStart, sp.start);
1646
+ } else if (sp.level !== currentLevel) {
1647
+ const segEnd = Math.min(pEnd, sp.start);
1648
+ if (segEnd > segStart) segments.push({
1649
+ text: text.slice(segStart, segEnd),
1650
+ piece,
1651
+ level: currentLevel,
1652
+ isRtl: currentLevel % 2 === 1
1653
+ });
1654
+ currentLevel = sp.level;
1655
+ segStart = segEnd;
1656
+ }
1657
+ if (sp.end <= pEnd) spanIdx += 1;
1658
+ else break;
1659
+ }
1660
+ if (currentLevel !== void 0 && pEnd > segStart) segments.push({
1661
+ text: text.slice(segStart, pEnd),
1662
+ piece,
1663
+ level: currentLevel,
1664
+ isRtl: currentLevel % 2 === 1
1665
+ });
1666
+ }
1667
+ const maxLevel = Math.max(0, ...segments.map((seg) => seg.level));
1668
+ for (let lvl = maxLevel; lvl >= 1; lvl -= 1) {
1669
+ let i = 0;
1670
+ while (i < segments.length) {
1671
+ if (segments[i].level < lvl) {
1672
+ i += 1;
1673
+ continue;
1674
+ }
1675
+ let j = i;
1676
+ while (j < segments.length && segments[j].level >= lvl) j += 1;
1677
+ let left = i;
1678
+ let right = j - 1;
1679
+ while (left < right) {
1680
+ const tmp = segments[left];
1681
+ segments[left] = segments[right];
1682
+ segments[right] = tmp;
1683
+ left += 1;
1684
+ right -= 1;
1685
+ }
1686
+ i = j;
1687
+ }
1688
+ }
1689
+ return segments;
1690
+ }
1691
+ function shapeSegmentOutlines(face, text, isRtl, lang) {
1692
+ const visible = Array.from(text).filter(requiresFontGlyph).join("");
1693
+ if (visible === "") return [];
1694
+ return shapeFontOutlines(face, visible, isRtl, lang);
1695
+ }
1696
+ /**
1697
+ * Converts font-measurement/outline unavailability errors encountered during paint()
1698
+ * into `preview-missing-font` or `preview-unsupported-font` while preserving `resolve()` error semantics.
1699
+ */
1700
+ function withPreviewFontBoundary(fn) {
1701
+ try {
1702
+ return fn();
1703
+ } catch (error) {
1704
+ if (error instanceof CapabilityError) {
1705
+ if (error.code === "preview-missing-font" || error.code === "preview-unsupported-font" || error.code === "preview-missing-glyph") throw error;
1706
+ if (error.code === "font-measurement-unavailable") throw new CapabilityError("preview-missing-font", "Preview requires an explicit monochrome outline font file for each used font weight and style", error.path, error.details);
1707
+ if (error.code === "font-missing-glyph") throw new CapabilityError("preview-missing-glyph", error.message, error.path, error.details);
1708
+ if (error.code === "font-format-unsupported" || error.code === "unsupported-font-format" || error.code === "font-substitution-required" || error.code === "font-face-mismatch" || error.code === "font-weight-mismatch" || error.code === "font-style-mismatch" || error.code === "font-metrics-invalid" || error.code === "conflicting-resource") throw new CapabilityError("preview-unsupported-font", error.message, error.path, error.details);
1709
+ }
1710
+ throw error;
1711
+ }
1712
+ }
1713
+ /**
1714
+ * Extracts vector glyph outlines for one paragraph using its formal measurement / line-break ranges.
1715
+ * Coordinates are relative to each line's baseline, in pixels.
1716
+ */
1717
+ function previewParagraphOutlines(paragraph, widthOrMeasured) {
1718
+ const { measured, text, pieces, baseDir } = withPreviewFontBoundary(() => {
1719
+ const resolvedMeasured = typeof widthOrMeasured === "number" ? paragraphMeasurement(paragraph, widthOrMeasured) : widthOrMeasured;
1720
+ for (const piece of resolvedMeasured.pieces) if (piece.face.hasColorOrBitmapTable) throw new CapabilityError("preview-unsupported-font", "Preview requires monochrome outline fonts", void 0, {
1721
+ font: fontDetailsFromRunStyle(piece.style),
1722
+ reason: "color-or-bitmap-font"
1723
+ });
1724
+ return {
1725
+ measured: resolvedMeasured,
1726
+ text: resolvedMeasured.text,
1727
+ pieces: resolvedMeasured.pieces,
1728
+ baseDir: paragraphBaseDirection(resolvedMeasured.text)
1729
+ };
1730
+ });
1731
+ return {
1732
+ lines: measured.lines.map((line, lineIndex) => {
1733
+ let cursor = 0;
1734
+ let pendingTracking = 0;
1735
+ const glyphs = [];
1736
+ const decorations = [];
1737
+ let ascent = 0;
1738
+ let descent = 0;
1739
+ const trimmedEnd = trimLineEnd(text, line.start, line.end);
1740
+ buildVisualLineSegments(text, line.start, trimmedEnd, pieces, baseDir).forEach((seg, segIndex) => {
1741
+ const { piece } = seg;
1742
+ const missing = missingCharacters(piece.face, seg.text);
1743
+ if (missing.length > 0) throw new CapabilityError("preview-missing-glyph", "Preview requires every visible glyph in the supplied font", void 0, {
1744
+ font: fontDetailsFromRunStyle(piece.style),
1745
+ characters: missing
1746
+ });
1747
+ const shaped = shapeSegmentOutlines(piece.face, seg.text, seg.isRtl, piece.style.lang);
1748
+ if (shaped.length === 0) return;
1749
+ const face = piece.face;
1750
+ const unscaledFontPx = fontSizePoints(piece.style.fontSize) * 4 / 3;
1751
+ const baselineMilli = piece.style.baselineShift !== void 0 ? parseBaselineShiftThousandths(piece.style.baselineShift) : void 0;
1752
+ const fontPx = baselineMilli !== void 0 ? unscaledFontPx * (2 / 3) : unscaledFontPx;
1753
+ const scale = fontPx / face.unitsPerEm;
1754
+ const unscaledScale = unscaledFontPx / face.unitsPerEm;
1755
+ const baselineShiftPx = baselineMilli !== void 0 ? -(baselineMilli / 1e5) * unscaledFontPx : 0;
1756
+ const trackingPx = piece.style.letterSpacing ?? 0;
1757
+ ascent = Math.max(ascent, face.ascent * unscaledScale);
1758
+ descent = Math.max(descent, -face.descent * unscaledScale);
1759
+ let segStartX;
1760
+ let segEndX = cursor;
1761
+ const glyphStart = glyphs.length;
1762
+ let lastCluster;
1763
+ let clusterHadAdvance = false;
1764
+ for (const item of shaped) {
1765
+ if (lastCluster !== void 0 && item.cluster !== lastCluster) {
1766
+ if (clusterHadAdvance && pendingTracking !== 0) {
1767
+ cursor += pendingTracking;
1768
+ pendingTracking = 0;
1769
+ }
1770
+ clusterHadAdvance = false;
1771
+ } else if (lastCluster === void 0 && pendingTracking !== 0) {
1772
+ cursor += pendingTracking;
1773
+ pendingTracking = 0;
1774
+ }
1775
+ lastCluster = item.cluster;
1776
+ if (segStartX === void 0) segStartX = cursor;
1777
+ glyphs.push({
1778
+ path: item.path,
1779
+ x: cursor + item.xOffset * scale,
1780
+ y: baselineShiftPx - item.yOffset * scale,
1781
+ scale,
1782
+ color: piece.style.color,
1783
+ textStroke: piece.style.textStroke,
1784
+ advance: item.xAdvance * scale,
1785
+ ascent: face.ascent * scale,
1786
+ descent: Math.abs(face.descent * scale),
1787
+ ...piece.style.textShadow === void 0 ? {} : { textShadow: piece.style.textShadow },
1788
+ isSpace: item.isSpace && item.xAdvance > 0,
1789
+ clusterKey: `${segIndex}:${item.cluster}`
1790
+ });
1791
+ cursor += item.xAdvance * scale;
1792
+ segEndX = cursor;
1793
+ if (item.xAdvance > 0) {
1794
+ clusterHadAdvance = true;
1795
+ pendingTracking = trackingPx;
1796
+ }
1797
+ }
1798
+ const glyphEnd = glyphs.length;
1799
+ if (segStartX !== void 0 && glyphEnd > glyphStart) {
1800
+ const decoration = decorationForSegment(resolveDecoration(piece.style.textDecoration), face, fontPx, segStartX, segEndX, piece.style.color, piece.style.textShadow, piece.style.textStroke);
1801
+ if (decoration !== void 0) decorations.push({
1802
+ ...decoration,
1803
+ y: decoration.y + baselineShiftPx,
1804
+ glyphStart,
1805
+ glyphEnd
1806
+ });
1807
+ }
1808
+ });
1809
+ if (glyphs.length === 0 && pieces.length > 0) {
1810
+ const fallbackPiece = pieces[0];
1811
+ const fallbackFace = fallbackPiece.face;
1812
+ const fallbackScale = fontSizePoints(fallbackPiece.style.fontSize) * 4 / (3 * fallbackFace.unitsPerEm);
1813
+ ascent = fallbackFace.ascent * fallbackScale;
1814
+ descent = -fallbackFace.descent * fallbackScale;
1815
+ }
1816
+ const endsWithMandatoryBreak = trimMandatoryBreakEnd(text, line.start, line.end) < line.end || line.end < text.length && /[\n\r\v\f\u0085\u2028\u2029]/u.test(text[line.end] ?? "");
1817
+ const canJustify = lineIndex < measured.lines.length - 1 && !endsWithMandatoryBreak;
1818
+ return {
1819
+ ...line,
1820
+ glyphs,
1821
+ ...decorations.length === 0 ? {} : { decorations },
1822
+ ascent,
1823
+ descent,
1824
+ advance: cursor,
1825
+ canJustify
1826
+ };
1827
+ }),
1828
+ lineHeight: measured.lineHeight,
1829
+ spacingAfter: measured.spacingAfter,
1830
+ baseDir
1831
+ };
1832
+ }
1833
+ function applyJustifyLine(line, availableWidth) {
1834
+ const slack = availableWidth - line.advance;
1835
+ if (!line.canJustify || slack <= .01 || line.glyphs.length <= 1) return {
1836
+ glyphs: line.glyphs,
1837
+ decorations: line.decorations,
1838
+ advance: line.advance
1839
+ };
1840
+ const count = line.glyphs.length;
1841
+ const deltaBefore = Array.from({ length: count }).fill(0);
1842
+ const spaceCount = line.glyphs.filter((g) => g.isSpace === true).length;
1843
+ if (spaceCount > 0) {
1844
+ const extraPerSpace = slack / spaceCount;
1845
+ let cumulative = 0;
1846
+ for (let i = 0; i < count; i += 1) {
1847
+ deltaBefore[i] = cumulative;
1848
+ if (line.glyphs[i].isSpace === true) cumulative += extraPerSpace;
1849
+ }
1850
+ } else {
1851
+ let clusterTransitions = 0;
1852
+ for (let i = 1; i < count; i += 1) if (line.glyphs[i].clusterKey !== line.glyphs[i - 1].clusterKey) clusterTransitions += 1;
1853
+ if (clusterTransitions <= 0) return {
1854
+ glyphs: line.glyphs,
1855
+ decorations: line.decorations,
1856
+ advance: line.advance
1857
+ };
1858
+ const extraPerCluster = slack / clusterTransitions;
1859
+ let cumulative = 0;
1860
+ for (let i = 1; i < count; i += 1) {
1861
+ if (line.glyphs[i].clusterKey !== line.glyphs[i - 1].clusterKey) cumulative += extraPerCluster;
1862
+ deltaBefore[i] = cumulative;
1863
+ }
1864
+ }
1865
+ return {
1866
+ glyphs: line.glyphs.map((glyph, index) => ({
1867
+ ...glyph,
1868
+ x: glyph.x + deltaBefore[index]
1869
+ })),
1870
+ decorations: line.decorations?.map((deco) => {
1871
+ const gStart = deco.glyphStart ?? 0;
1872
+ const gEnd = deco.glyphEnd ?? count;
1873
+ const startDelta = deltaBefore[gStart] ?? 0;
1874
+ const endDelta = gEnd < count ? deltaBefore[gEnd] ?? 0 : deltaBefore[Math.max(gStart, gEnd - 1)] ?? 0;
1875
+ return {
1876
+ ...deco,
1877
+ x: deco.x + startDelta,
1878
+ width: deco.width + (endDelta - startDelta)
1879
+ };
1880
+ }),
1881
+ advance: availableWidth
1882
+ };
1883
+ }
1884
+ function shapeListPrefix(paragraph, prefixText) {
1885
+ const segments = splitRunForEffectiveScripts(prefixText, paragraph.runs[0]?.style ?? paragraph.endStyle);
1886
+ let cursor = 0;
1887
+ const glyphs = [];
1888
+ for (const seg of segments) {
1889
+ const prefixFace = withPreviewFontBoundary(() => {
1890
+ const face = measureRunFace(seg.style);
1891
+ if (face.hasColorOrBitmapTable) throw new CapabilityError("preview-unsupported-font", "Preview requires monochrome outline fonts", void 0, {
1892
+ font: fontDetailsFromRunStyle(seg.style),
1893
+ reason: "color-or-bitmap-font"
1894
+ });
1895
+ return face;
1896
+ });
1897
+ const missingPrefix = missingCharacters(prefixFace, seg.text);
1898
+ if (missingPrefix.length > 0) throw new CapabilityError("preview-missing-glyph", "Preview requires every visible glyph in the supplied font", void 0, {
1899
+ font: fontDetailsFromRunStyle(seg.style),
1900
+ characters: missingPrefix
1901
+ });
1902
+ const shaped = shapeSegmentOutlines(prefixFace, seg.text, false, seg.style.lang);
1903
+ const scale = fontSizePoints(seg.style.fontSize) * 4 / (3 * prefixFace.unitsPerEm);
1904
+ for (const item of shaped) {
1905
+ glyphs.push({
1906
+ path: item.path,
1907
+ x: cursor + item.xOffset * scale,
1908
+ y: -item.yOffset * scale,
1909
+ scale,
1910
+ color: seg.style.color,
1911
+ textStroke: seg.style.textStroke,
1912
+ advance: item.xAdvance * scale,
1913
+ ascent: prefixFace.ascent * scale,
1914
+ descent: Math.abs(prefixFace.descent * scale),
1915
+ ...seg.style.textShadow === void 0 ? {} : { textShadow: seg.style.textShadow }
1916
+ });
1917
+ cursor += item.xAdvance * scale;
1918
+ }
1919
+ }
1920
+ return {
1921
+ glyphs,
1922
+ advance: cursor
1923
+ };
1924
+ }
1925
+ /**
1926
+ * Positions paragraph glyph outlines inside a compiled box with insets, horizontal alignment,
1927
+ * and vertical alignment. Reuses pre-computed formal build line measurements when provided.
1928
+ */
1929
+ function previewTextBoxOutlines(options) {
1930
+ const { paragraphs, box, insets = {
1931
+ top: 0,
1932
+ right: 0,
1933
+ bottom: 0,
1934
+ left: 0
1935
+ }, verticalAlign: rawVerticalAlign, measuredLayout } = options;
1936
+ const verticalAlign = resolveVerticalAlign(rawVerticalAlign);
1937
+ const innerWidth = Math.max(0, box.width - insets.left - insets.right);
1938
+ const useBoundMeasurement = measuredLayout !== void 0 && measuredLayout.paragraphs.length === paragraphs.length;
1939
+ const outlinedParagraphs = paragraphs.map((paragraph, index) => ({
1940
+ paragraph,
1941
+ layout: previewParagraphOutlines(paragraph, useBoundMeasurement ? measuredLayout.paragraphs[index] : innerWidth)
1942
+ }));
1943
+ const totalHeight = outlinedParagraphs.reduce((total, { layout }, index) => total + layout.lines.length * layout.lineHeight + (index < outlinedParagraphs.length - 1 ? layout.spacingAfter : 0), 0);
1944
+ const freeHeight = box.height - insets.top - insets.bottom - totalHeight;
1945
+ const verticalOffset = verticalAlignOffsets[verticalAlign];
1946
+ let top = box.y + insets.top + (verticalOffset === 0 ? 0 : freeHeight * verticalOffset);
1947
+ const activeNumberSeq = /* @__PURE__ */ new Map();
1948
+ return outlinedParagraphs.flatMap(({ paragraph, layout }) => {
1949
+ const resolvedList = resolveListModel(paragraph.style.list);
1950
+ let prefixText;
1951
+ if (resolvedList === void 0) activeNumberSeq.clear();
1952
+ else switch (resolvedList.type) {
1953
+ case "bullet":
1954
+ for (const key of activeNumberSeq.keys()) if (key >= resolvedList.level) activeNumberSeq.delete(key);
1955
+ prefixText = resolvedList.character;
1956
+ break;
1957
+ case "number": {
1958
+ for (const key of activeNumberSeq.keys()) if (key > resolvedList.level) activeNumberSeq.delete(key);
1959
+ const existing = activeNumberSeq.get(resolvedList.level);
1960
+ if (existing !== void 0 && existing.startAt === resolvedList.startAt) existing.current += 1;
1961
+ else activeNumberSeq.set(resolvedList.level, {
1962
+ startAt: resolvedList.startAt,
1963
+ current: resolvedList.startAt
1964
+ });
1965
+ prefixText = `${activeNumberSeq.get(resolvedList.level).current}.`;
1966
+ break;
1967
+ }
1968
+ default: return resolvedList;
1969
+ }
1970
+ const listPrefix = prefixText === void 0 ? void 0 : shapeListPrefix(paragraph, prefixText);
1971
+ const listIndent = listIndentMetrics(paragraph);
1972
+ const align = resolveAlign(paragraph.style.align, layout.baseDir === "rtl" ? "right" : "left");
1973
+ const lines = layout.lines.map((line, lineIndex) => {
1974
+ const firstLineIndent = lineIndex === 0 && resolvedList === void 0 ? paragraph.style.indent ?? 0 : 0;
1975
+ const contentIndent = listIndent.contentIndent + firstLineIndent;
1976
+ const availableLineWidth = Math.max(1, innerWidth - contentIndent);
1977
+ const justified = align === "justify" ? applyJustifyLine(line, availableLineWidth) : {
1978
+ glyphs: line.glyphs,
1979
+ decorations: line.decorations,
1980
+ advance: line.advance
1981
+ };
1982
+ let horizontalOffset;
1983
+ let prefixOffset = 0;
1984
+ if (layout.baseDir === "rtl" && resolvedList !== void 0) switch (align) {
1985
+ case "center":
1986
+ horizontalOffset = (availableLineWidth - justified.advance) / 2;
1987
+ prefixOffset = horizontalOffset + justified.advance + .4 * listIndent.baseFontPx;
1988
+ break;
1989
+ case "left":
1990
+ case "justify":
1991
+ horizontalOffset = 0;
1992
+ prefixOffset = innerWidth - listIndent.levelIndent - (listPrefix?.advance ?? 0);
1993
+ break;
1994
+ case "right":
1995
+ horizontalOffset = availableLineWidth - justified.advance;
1996
+ prefixOffset = innerWidth - listIndent.levelIndent - (listPrefix?.advance ?? 0);
1997
+ break;
1998
+ default: return align;
1999
+ }
2000
+ else switch (align) {
2001
+ case "center":
2002
+ horizontalOffset = contentIndent + (availableLineWidth - justified.advance) / 2;
2003
+ prefixOffset = horizontalOffset - (listPrefix?.advance ?? 0) - .4 * listIndent.baseFontPx;
2004
+ break;
2005
+ case "right":
2006
+ horizontalOffset = contentIndent + (availableLineWidth - justified.advance);
2007
+ prefixOffset = horizontalOffset - (listPrefix?.advance ?? 0) - .4 * listIndent.baseFontPx;
2008
+ break;
2009
+ case "left":
2010
+ case "justify":
2011
+ horizontalOffset = contentIndent;
2012
+ prefixOffset = listIndent.levelIndent;
2013
+ break;
2014
+ default: return align;
2015
+ }
2016
+ const left = box.x + insets.left + horizontalOffset;
2017
+ const baseline = top + line.ascent + (layout.lineHeight - line.ascent - line.descent) / 2;
2018
+ top += layout.lineHeight;
2019
+ const prefixGlyphs = lineIndex === 0 && listPrefix !== void 0 ? listPrefix.glyphs.map((glyph) => ({
2020
+ ...glyph,
2021
+ x: box.x + insets.left + prefixOffset + glyph.x,
2022
+ y: baseline + glyph.y
2023
+ })) : [];
2024
+ return {
2025
+ start: line.start,
2026
+ end: line.end,
2027
+ baseline,
2028
+ glyphs: [...prefixGlyphs, ...justified.glyphs.map((glyph) => ({
2029
+ ...glyph,
2030
+ x: left + glyph.x,
2031
+ y: baseline + glyph.y
2032
+ }))],
2033
+ ...justified.decorations === void 0 ? {} : { decorations: justified.decorations.map((deco) => ({
2034
+ ...deco,
2035
+ x: left + deco.x,
2036
+ y: baseline + deco.y
2037
+ })) }
2038
+ };
2039
+ });
2040
+ top += layout.spacingAfter;
2041
+ return lines;
2042
+ });
2043
+ }
2044
+ function textFillAttributes(fill, theme, gradientPaint) {
2045
+ if (isTextGradient(fill)) return `fill="url(#${gradientPaint(fill)})"`;
2046
+ const color = isResolvedColor(fill) ? fill : theme.resolveColor(fill ?? "tx1");
2047
+ return `fill="#${color.hex}" fill-opacity="${color.alpha ?? 1}"`;
2048
+ }
2049
+ function textStrokeAttributes(value, theme) {
2050
+ const outline = resolveTextStroke(theme, value);
2051
+ return outline === void 0 ? "" : ` ${borderAttributes(outline)}`;
2052
+ }
2053
+ /** Font outlines use absolute M/L/Q/C/Z commands in an upward-positive coordinate system. */
2054
+ function screenGlyphPath(glyph) {
2055
+ let position = 0;
2056
+ return glyph.path.replace(/([MLQCZ])|(-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)/giu, (_, command, coordinate) => {
2057
+ if (command !== void 0) {
2058
+ position = 0;
2059
+ return command;
2060
+ }
2061
+ const value = Number(coordinate) * glyph.scale;
2062
+ return ` ${roundSvgNumber(position++ % 2 === 0 ? glyph.x + value : glyph.y - value)}`;
2063
+ });
2064
+ }
2065
+ function renderGlyphPathSvg(glyph, theme, gradientPaint) {
2066
+ if (glyph.path === "") return "";
2067
+ const fill = textFillAttributes(glyph.color, theme, gradientPaint);
2068
+ const stroke = textStrokeAttributes(glyph.textStroke, theme);
2069
+ if (isTextGradient(glyph.color) || stroke !== "") return `<path d="${screenGlyphPath(glyph)}" ${fill}${stroke}/>`;
2070
+ return `<path d="${xmlEscape(glyph.path)}" ${fill} transform="translate(${glyph.x} ${glyph.y}) scale(${glyph.scale} ${-glyph.scale})"/>`;
2071
+ }
2072
+ function renderDecorationRectSvg(deco, theme, gradientPaint) {
2073
+ const fill = textFillAttributes(deco.color, theme, gradientPaint);
2074
+ const stroke = textStrokeAttributes(deco.textStroke, theme);
2075
+ return `<rect x="${roundSvgNumber(deco.x)}" y="${roundSvgNumber(deco.y)}" width="${roundSvgNumber(deco.width)}" height="${roundSvgNumber(deco.height)}" ${fill}${stroke}/>`;
2076
+ }
2077
+ /** Renders box-level positioned glyph outlines into SVG path fragments without importing textCapability. */
2078
+ function renderTextOutlinesSvg(options) {
2079
+ const { theme, idPrefix = "txt", rotate = 0, ...layoutOptions } = options;
2080
+ const lines = previewTextBoxOutlines(layoutOptions);
2081
+ const defs = [];
2082
+ const gradientBounds = /* @__PURE__ */ new Map();
2083
+ const includeGradientBounds = (color, x1, y1, x2, y2) => {
2084
+ if (!isTextGradient(color)) return;
2085
+ const key = JSON.stringify(color);
2086
+ const bounds = gradientBounds.get(key);
2087
+ if (bounds === void 0) gradientBounds.set(key, {
2088
+ gradient: color,
2089
+ x1,
2090
+ y1,
2091
+ x2,
2092
+ y2
2093
+ });
2094
+ else {
2095
+ bounds.x1 = Math.min(bounds.x1, x1);
2096
+ bounds.y1 = Math.min(bounds.y1, y1);
2097
+ bounds.x2 = Math.max(bounds.x2, x2);
2098
+ bounds.y2 = Math.max(bounds.y2, y2);
2099
+ }
2100
+ };
2101
+ for (const line of lines) {
2102
+ for (const glyph of line.glyphs) includeGradientBounds(glyph.color, glyph.x, glyph.y - glyph.ascent, glyph.x + glyph.advance, glyph.y + glyph.descent);
2103
+ for (const deco of line.decorations ?? []) includeGradientBounds(deco.color, deco.x, deco.y, deco.x + deco.width, deco.y + deco.height);
2104
+ }
2105
+ const gradientIds = /* @__PURE__ */ new Map();
2106
+ for (const [key, { gradient, x1, y1, x2, y2 }] of gradientBounds) {
2107
+ const id = `${idPrefix}-text-fill-${gradientIds.size}`;
2108
+ gradientIds.set(key, id);
2109
+ defs.push(gradientDefSvg(id, resolveGradientSpec(theme, gradient, void 0, "style.color"), {
2110
+ x: x1,
2111
+ y: y1,
2112
+ width: Math.max(1, x2 - x1),
2113
+ height: Math.max(1, y2 - y1)
2114
+ }));
2115
+ }
2116
+ const gradientPaint = (gradient) => gradientIds.get(JSON.stringify(gradient));
2117
+ const shadowFilterIds = /* @__PURE__ */ new Map();
2118
+ let shadowIndex = 0;
2119
+ const filterIdForShadow = (rawShadow) => {
2120
+ const resolved = resolveTextShadowModel(theme, rawShadow);
2121
+ switch (resolved.kind) {
2122
+ case "none": return;
2123
+ case "shadow": {
2124
+ const { shadow } = resolved;
2125
+ const rad = shadow.angle * Math.PI / 180;
2126
+ const worldDx = shadow.distance * Math.cos(rad);
2127
+ const worldDy = shadow.distance * Math.sin(rad);
2128
+ const rotRad = -rotate * Math.PI / 180;
2129
+ const localDx = worldDx * Math.cos(rotRad) - worldDy * Math.sin(rotRad);
2130
+ const localDy = worldDx * Math.sin(rotRad) + worldDy * Math.cos(rotRad);
2131
+ const sigma = shadow.blur / 2;
2132
+ const alpha = shadow.color.alpha ?? 1;
2133
+ const key = `${shadow.color.hex}:${roundSvgNumber(alpha)}:${roundSvgNumber(sigma)}:${roundSvgNumber(localDx)}:${roundSvgNumber(localDy)}`;
2134
+ const existing = shadowFilterIds.get(key);
2135
+ if (existing !== void 0) return existing;
2136
+ const id = `${idPrefix}-tshdw-${shadowIndex++}`;
2137
+ shadowFilterIds.set(key, id);
2138
+ const pad = shadow.blur * 3 + Math.abs(localDx) + Math.abs(localDy) + 64;
2139
+ const fx = roundSvgNumber(options.box.x - pad);
2140
+ const fy = roundSvgNumber(options.box.y - pad);
2141
+ const fw = roundSvgNumber(options.box.width + pad * 2);
2142
+ const fh = roundSvgNumber(options.box.height + pad * 2);
2143
+ defs.push(`<filter id="${id}" filterUnits="userSpaceOnUse" x="${fx}" y="${fy}" width="${fw}" height="${fh}"><feDropShadow dx="${roundSvgNumber(localDx)}" dy="${roundSvgNumber(localDy)}" stdDeviation="${roundSvgNumber(sigma)}" flood-color="#${shadow.color.hex}" flood-opacity="${roundSvgNumber(alpha)}"/></filter>`);
2144
+ return id;
2145
+ }
2146
+ default: return resolved;
2147
+ }
2148
+ };
2149
+ const parts = [];
2150
+ let activeFilter;
2151
+ let activeGroup = [];
2152
+ const flushGroup = () => {
2153
+ if (activeGroup.length === 0) return;
2154
+ const joined = activeGroup.join("");
2155
+ parts.push(activeFilter === void 0 ? joined : `<g filter="url(#${activeFilter})">${joined}</g>`);
2156
+ activeGroup = [];
2157
+ };
2158
+ const pushElement = (elementSvg, rawShadow) => {
2159
+ if (elementSvg === "") return;
2160
+ const filterId = filterIdForShadow(rawShadow);
2161
+ if (filterId !== activeFilter) {
2162
+ flushGroup();
2163
+ activeFilter = filterId;
2164
+ }
2165
+ activeGroup.push(elementSvg);
2166
+ };
2167
+ for (const line of lines) {
2168
+ for (const glyph of line.glyphs) pushElement(renderGlyphPathSvg(glyph, theme, gradientPaint), glyph.textShadow);
2169
+ for (const deco of line.decorations ?? []) pushElement(renderDecorationRectSvg(deco, theme, gradientPaint), deco.textShadow);
2170
+ }
2171
+ flushGroup();
2172
+ return `${defs.length > 0 ? `<defs>${defs.join("")}</defs>` : ""}${parts.join("")}`;
2173
+ }
2174
+ const alignF32Buf = /* @__PURE__ */ new Float32Array(1);
2175
+ const alignU32Buf = new Uint32Array(alignF32Buf.buffer);
2176
+ function ceilFloat32ForOuterEmu(value) {
2177
+ if (!(value > 0) || !Number.isFinite(value)) return value;
2178
+ alignF32Buf[0] = value;
2179
+ if (alignF32Buf[0] < value) alignU32Buf[0] = alignU32Buf[0] + 1;
2180
+ return alignF32Buf[0];
2181
+ }
2182
+ /**
2183
+ * Aligns a measured inner text width upward to the smallest pixel value whose
2184
+ * outer `Math.round(outerPx * 9525)` minus emitted `lIns`/`rIns` EMU insets is
2185
+ * at least `Math.ceil(rawInnerWidthPx * 9525 - 1e-9)`, accounting for Yoga's
2186
+ * float32 rounding of both the inner width and horizontal padding insets.
2187
+ */
2188
+ function alignMeasuredTextWidthForOuterEmu(rawInnerWidthPx, leftInsetPx, rightInsetPx) {
2189
+ const requiredOuterEmu = Math.max(0, Math.ceil(rawInnerWidthPx * 9525 - 1e-9)) + (Math.round(leftInsetPx * 9525) + Math.round(rightInsetPx * 9525));
2190
+ let candidate = Math.max(0, requiredOuterEmu / 9525 - leftInsetPx - rightInsetPx);
2191
+ const leftF32 = Math.fround(leftInsetPx);
2192
+ const rightF32 = Math.fround(rightInsetPx);
2193
+ for (let step = 0; step < 8; step += 1) {
2194
+ const innerF32 = ceilFloat32ForOuterEmu(candidate);
2195
+ const okLeftFirst = Math.round(Math.fround(Math.fround(innerF32 + leftF32) + rightF32) * 9525) >= requiredOuterEmu;
2196
+ const okInsetsFirst = Math.round(Math.fround(Math.fround(leftF32 + rightF32) + innerF32) * 9525) >= requiredOuterEmu;
2197
+ const okF64 = Math.round((innerF32 + leftInsetPx + rightInsetPx) * 9525) >= requiredOuterEmu;
2198
+ if (okLeftFirst && okInsetsFirst && okF64) return candidate;
2199
+ alignF32Buf[0] = innerF32 === 0 ? 0 : innerF32;
2200
+ alignU32Buf[0] = alignU32Buf[0] + 1;
2201
+ candidate = alignF32Buf[0];
2202
+ }
2203
+ return candidate;
2204
+ }
2205
+ /**
2206
+ * Applies outer-EMU width alignment to both `width` and `minContentWidth` of a
2207
+ * text layout measurement unless the solver requested an exact width.
2208
+ */
2209
+ function alignMeasuredTextWidthsForOuterEmu(measured, insets, request) {
2210
+ if (request.widthMode === "exactly") return {
2211
+ width: measured.width,
2212
+ minContentWidth: measured.minContentWidth
2213
+ };
2214
+ const alignedWidth = alignMeasuredTextWidthForOuterEmu(measured.width, insets.left, insets.right);
2215
+ return {
2216
+ width: request.availableWidth !== void 0 && measured.width <= request.availableWidth && alignedWidth > request.availableWidth ? request.availableWidth : alignedWidth,
2217
+ minContentWidth: alignMeasuredTextWidthForOuterEmu(measured.minContentWidth, insets.left, insets.right)
2218
+ };
2219
+ }
2220
+ /** Returns layout dimensions based on actual fonts and line breaking rules from normalized paragraphs. */
2221
+ function measureTextLayoutFromParagraphs(paragraphs, style, availableWidth) {
2222
+ const measured = measureParagraphs(paragraphs, availableWidth ?? Number.POSITIVE_INFINITY);
2223
+ const minContentWidth = Math.max(0, ...paragraphs.map(measureParagraphMinContentWidth));
2224
+ let baseline;
2225
+ if (style.verticalAlign === void 0 || style.verticalAlign === "top") {
2226
+ if (paragraphs[0] === void 0) baseline = void 0;
2227
+ else try {
2228
+ baseline = paragraphBaseline(paragraphs[0]) ?? "unavailable";
2229
+ } catch {
2230
+ baseline = "unavailable";
2231
+ }
2232
+ }
2233
+ return {
2234
+ width: measured.width,
2235
+ height: measured.height,
2236
+ minContentWidth,
2237
+ minContentHeight: measured.height,
2238
+ ...baseline === void 0 ? {} : { baseline }
2239
+ };
2240
+ }
2241
+ function bodyAnchor(verticalAlign) {
2242
+ return bodyAnchors[resolveVerticalAlign(verticalAlign)];
2243
+ }
2244
+ function textInsets(value, placeholder) {
2245
+ if (placeholder === void 0) return parseTextInsets(value);
2246
+ const effective = {};
2247
+ const layers = [
2248
+ placeholder.masterPlaceholder?.style,
2249
+ placeholder.layoutPlaceholder?.style,
2250
+ record(value) ? value : void 0
2251
+ ];
2252
+ for (const layer of layers) {
2253
+ if (layer === void 0) continue;
2254
+ for (const key of paddingStyleKeys) if (hasLocalDeclaration(layer, key)) {
2255
+ if (key === "padding") {
2256
+ delete effective["paddingTop"];
2257
+ delete effective["paddingRight"];
2258
+ delete effective["paddingBottom"];
2259
+ delete effective["paddingLeft"];
2260
+ }
2261
+ effective[key] = layer[key];
2262
+ }
2263
+ }
2264
+ return parseTextInsets(effective);
2265
+ }
2266
+ /** Parses text children, validates element structure, and resolves paragraphs and text styles once. */
2267
+ function parseTextContent(children, styleValue, theme, fields = { slideNumber: 1 }, label = "Text.style", placeholder, fullSlideStyle, options) {
2268
+ const allowParagraphMotion = options?.allowParagraphMotion === true;
2269
+ if (placeholder === void 0) {
2270
+ const style = readTextStyle(styleValue, label, theme);
2271
+ const { paragraphs, paragraphMotions } = normalizeParagraphs(children, style, theme, fields, void 0, void 0, allowParagraphMotion);
2272
+ return {
2273
+ paragraphs,
2274
+ paragraphMotions,
2275
+ style
2276
+ };
2277
+ }
2278
+ const { style, localDeclaredStyle } = readPlaceholderTextStyle(styleValue, label, placeholder);
2279
+ const fullRecord = record(fullSlideStyle) ? fullSlideStyle : void 0;
2280
+ const localBodyDeclared = localDeclaredKeySet(fullRecord, [
2281
+ "textWrap",
2282
+ "verticalAlign",
2283
+ ...paddingStyleKeys
2284
+ ]);
2285
+ const { paragraphs, paragraphMotions } = normalizeParagraphs(children, style, placeholder.masterTheme, fields, placeholder, localDeclaredStyle, allowParagraphMotion);
2286
+ return {
2287
+ paragraphs,
2288
+ paragraphMotions,
2289
+ style,
2290
+ localBodyDeclared
2291
+ };
2292
+ }
2293
+ const parseTextParagraphs = parseTextContent;
2294
+ function validateEmittableParagraphs(paragraphs, theme) {
2295
+ for (const paragraph of paragraphs) {
2296
+ if (paragraph.style.list?.type === "bullet") escapedXml(paragraph.style.list.character ?? "•", "style.list.character");
2297
+ if (paragraph.runs.length === 0) {
2298
+ for (const font of normalizedFonts(paragraph.endStyle)) escapedXml(font.family, "style.fontFamily");
2299
+ if (paragraph.endStyle.eastAsianFontFamily !== void 0) for (const eaFont of normalizedFontsForReference(paragraph.endStyle.eastAsianFontFamily, paragraph.endStyle.fontWeight, paragraph.endStyle.fontStyle)) escapedXml(eaFont.family, "style.eastAsianFontFamily");
2300
+ if (paragraph.endStyle.lang !== void 0) escapedXml(paragraph.endStyle.lang, "style.lang");
2301
+ if (paragraph.endStyle.textShadow !== void 0 && paragraph.endStyle.textShadow !== "none") textShadowXml(theme, paragraph.endStyle.textShadow);
2302
+ centipoints(fontSizePoints(paragraph.endStyle.fontSize));
2303
+ continue;
2304
+ }
2305
+ for (const run of paragraph.runs) {
2306
+ escapedXml(run.text);
2307
+ for (const font of normalizedFonts(run.style)) escapedXml(font.family, "style.fontFamily");
2308
+ if (run.style.eastAsianFontFamily !== void 0) for (const eaFont of normalizedFontsForReference(run.style.eastAsianFontFamily, run.style.fontWeight, run.style.fontStyle)) escapedXml(eaFont.family, "style.eastAsianFontFamily");
2309
+ if (run.style.lang !== void 0) escapedXml(run.style.lang, "style.lang");
2310
+ if (run.style.textShadow !== void 0 && run.style.textShadow !== "none") textShadowXml(theme, run.style.textShadow);
2311
+ }
2312
+ }
2313
+ }
2314
+ const TEXT_FIT_EPSILON = .01;
2315
+ /** Computes tri-state TextMetrics from a resolved text body and its finalized available content dimensions. */
2316
+ function computeTextMetrics(resolved, availableWidth, availableHeight) {
2317
+ const { missingResourceFonts, missingGlyphFonts, referencedFonts } = resolved.unmeasuredIssues;
2318
+ if (missingResourceFonts.length > 0) return {
2319
+ status: "unmeasured",
2320
+ reason: "missing-font-resource",
2321
+ fonts: missingResourceFonts
2322
+ };
2323
+ if (missingGlyphFonts.length > 0) return {
2324
+ status: "unmeasured",
2325
+ reason: "missing-glyphs",
2326
+ fonts: missingGlyphFonts
2327
+ };
2328
+ if (resolved.measuredLayout === void 0) return {
2329
+ status: "unmeasured",
2330
+ reason: "missing-font-resource",
2331
+ fonts: referencedFonts
2332
+ };
2333
+ const available = {
2334
+ width: Math.max(0, availableWidth),
2335
+ height: Math.max(0, availableHeight)
2336
+ };
2337
+ const content = {
2338
+ width: resolved.measuredLayout.width,
2339
+ height: resolved.measuredLayout.height,
2340
+ lineCount: resolved.measuredLayout.paragraphs.reduce((sum, paragraph) => sum + paragraph.lineCount, 0)
2341
+ };
2342
+ return {
2343
+ status: "measured",
2344
+ available,
2345
+ content,
2346
+ fits: content.width <= available.width + TEXT_FIT_EPSILON && content.height <= available.height + TEXT_FIT_EPSILON
2347
+ };
2348
+ }
2349
+ /**
2350
+ * Resolves text layout, wrapping metrics, overset diagnostics, plain-text observations,
2351
+ * and font resource claims from pre-parsed paragraphs without assigning emit-only field IDs.
2352
+ */
2353
+ function resolveTextBody(rawParagraphs, style, theme, verticalAlign = "top", layout, destination = "text-box", placeholderOptions) {
2354
+ const paragraphs = placeholderOptions?.isPlaceholder === true ? rawParagraphs : rawParagraphs.map((paragraph) => {
2355
+ const metrics = computeDefaultListIndentMetrics(paragraph);
2356
+ return metrics === void 0 ? paragraph : {
2357
+ ...paragraph,
2358
+ resolvedListIndent: {
2359
+ marginLeft: paragraph.style.marginLeft ?? metrics.contentIndent,
2360
+ indent: paragraph.style.indent ?? -metrics.hangingIndent
2361
+ }
2362
+ };
2363
+ });
2364
+ const runGroups = paragraphs.map((paragraph) => paragraph.runs.length > 0 ? paragraph.runs : [{
2365
+ text: "",
2366
+ style: paragraph.endStyle
2367
+ }]);
2368
+ const listRunGroups = paragraphs.flatMap((paragraph) => {
2369
+ const list = paragraph.style.list;
2370
+ if (list === void 0) return [];
2371
+ return [[{
2372
+ text: list.type === "bullet" ? list.character ?? "•" : "0123456789.",
2373
+ style: paragraph.runs[0]?.style ?? paragraph.endStyle
2374
+ }]];
2375
+ });
2376
+ const { resourceClaims, fontUses, fontUsages, missingGlyphErrors, unmeasuredIssues } = textResourceClaims([...runGroups, ...listRunGroups]);
2377
+ let measured;
2378
+ let measurementError;
2379
+ if (layout !== void 0) try {
2380
+ measured = measureParagraphs(paragraphs, layout.width === "max-content" ? Number.MAX_VALUE : layout.width);
2381
+ } catch (error) {
2382
+ if (layout.contentSized === true) throw error;
2383
+ if (error instanceof CapabilityError) measurementError = error;
2384
+ }
2385
+ if (layout?.contentSized === true && measured === void 0) {
2386
+ const missingFont = unmeasuredIssues.missingResourceFonts[0] ?? unmeasuredIssues.referencedFonts[0];
2387
+ throw new CapabilityError("font-measurement-unavailable", "Content-sized text is missing complete font measurement basis", void 0, missingFont === void 0 ? void 0 : {
2388
+ font: missingFont,
2389
+ reason: "missing-resource"
2390
+ });
2391
+ }
2392
+ const outputParagraphs = layout?.contentSized === true && measured !== void 0 ? paragraphs.map((paragraph, index) => paragraph.style.lineHeight !== void 0 ? paragraph : {
2393
+ ...paragraph,
2394
+ style: {
2395
+ ...paragraph.style,
2396
+ lineHeight: measured.paragraphs[index].lineHeight
2397
+ }
2398
+ }) : paragraphs;
2399
+ validateEmittableParagraphs(outputParagraphs, theme);
2400
+ const text = outputParagraphs.map(({ runs: paragraphRuns }) => paragraphRuns.map(({ text: part }) => part).join("")).join("\n");
2401
+ const textMetrics = layout === void 0 ? void 0 : computeTextMetrics({
2402
+ ...measured === void 0 ? {} : { measuredLayout: measured },
2403
+ unmeasuredIssues
2404
+ }, layout.width === "max-content" ? measured?.width ?? 0 : layout.width, layout.height ?? measured?.height ?? 0);
2405
+ return {
2406
+ paragraphs: outputParagraphs,
2407
+ style,
2408
+ verticalAlign,
2409
+ ...layout === void 0 ? {} : { layout },
2410
+ destination,
2411
+ ...placeholderOptions?.isPlaceholder === true ? { isPlaceholder: true } : {},
2412
+ ...placeholderOptions?.localBodyDeclared === void 0 ? {} : { localBodyDeclared: placeholderOptions.localBodyDeclared },
2413
+ text,
2414
+ paragraphCount: outputParagraphs.length,
2415
+ resourceClaims,
2416
+ fontUses,
2417
+ fontUsages,
2418
+ ...measured === void 0 ? {} : {
2419
+ measurement: {
2420
+ width: measured.width,
2421
+ height: measured.height
2422
+ },
2423
+ measuredLayout: measured
2424
+ },
2425
+ ...measurementError === void 0 ? {} : { measurementError },
2426
+ missingGlyphErrors,
2427
+ unmeasuredIssues,
2428
+ ...textMetrics === void 0 ? {} : { textMetrics }
2429
+ };
2430
+ }
2431
+ /**
2432
+ * Emits PresentationML txBody XML and font embedding contributions from resolved text facts.
2433
+ * Preserves native paragraph/run structure without converting soft wraps into hard line breaks.
2434
+ */
2435
+ function emitTextBody(resolved, theme, options = {}) {
2436
+ const { createFieldId, embedFonts } = options;
2437
+ if ((embedFonts === "full" || embedFonts === "subset") && resolved.missingGlyphErrors.length > 0) {
2438
+ const issue = resolved.missingGlyphErrors[0];
2439
+ throw new CapabilityError("font-missing-glyph", issue.message, void 0, {
2440
+ font: issue.font,
2441
+ characters: issue.characters
2442
+ });
2443
+ }
2444
+ const emittedParagraphs = createFieldId !== void 0 ? resolved.paragraphs.map((paragraph) => ({
2445
+ ...paragraph,
2446
+ runs: paragraph.runs.map((run) => run.field !== void 0 ? {
2447
+ ...run,
2448
+ field: {
2449
+ ...run.field,
2450
+ id: createFieldId()
2451
+ }
2452
+ } : run)
2453
+ })) : resolved.paragraphs;
2454
+ const { style, verticalAlign, layout, destination, isPlaceholder } = resolved;
2455
+ let xml;
2456
+ if (destination === "table-cell") xml = `<a:txBody><a:bodyPr/><a:lstStyle/>${emittedParagraphs.map((paragraph) => paragraphXml(paragraph, theme)).join("")}</a:txBody>`;
2457
+ else if (isPlaceholder) {
2458
+ const localBody = resolved.localBodyDeclared ?? /* @__PURE__ */ new Set();
2459
+ const bodyAttrs = [];
2460
+ if (localBody.has("textWrap")) bodyAttrs.push(`wrap="${style.textWrap === "nowrap" ? "none" : "square"}"`);
2461
+ if (paddingStyleKeys.some((key) => localBody.has(key)) && layout?.insets !== void 0) bodyAttrs.push(`lIns="${pxToEmu(layout.insets.left)}"`, `tIns="${pxToEmu(layout.insets.top)}"`, `rIns="${pxToEmu(layout.insets.right)}"`, `bIns="${pxToEmu(layout.insets.bottom)}"`);
2462
+ if (localBody.has("verticalAlign")) bodyAttrs.push(`anchor="${bodyAnchor(style.verticalAlign ?? verticalAlign)}"`);
2463
+ xml = `<p:txBody>${bodyAttrs.length === 0 ? "<a:bodyPr/>" : `<a:bodyPr ${bodyAttrs.join(" ")}/>`}<a:lstStyle/>${emittedParagraphs.map((paragraph) => paragraphXml(paragraph, theme, true)).join("")}</p:txBody>`;
2464
+ } else xml = `<p:txBody><a:bodyPr wrap="${style.textWrap === "nowrap" ? "none" : "square"}" lIns="${pxToEmu(layout?.insets?.left ?? 0)}" tIns="${pxToEmu(layout?.insets?.top ?? 0)}" rIns="${pxToEmu(layout?.insets?.right ?? 0)}" bIns="${pxToEmu(layout?.insets?.bottom ?? 0)}" anchor="${bodyAnchor(style.verticalAlign ?? verticalAlign)}"><a:noAutofit/></a:bodyPr><a:lstStyle/>${emittedParagraphs.map((paragraph) => paragraphXml(paragraph, theme)).join("")}</p:txBody>`;
2465
+ return {
2466
+ xml,
2467
+ presentationContributions: fontPresentationContributions(resolved.fontUses, embedFonts)
2468
+ };
2469
+ }
2470
+ /** Generates shared font styles for native chart text and registers font claims based on actual categories, series, and label text. */
2471
+ function writeChartTextProperties(styleValue, texts, label, theme, customText) {
2472
+ const style = readTextStyle(styleValue, label, theme, true);
2473
+ const runStyle = {
2474
+ fontFamily: style.fontFamily,
2475
+ ...style.eastAsianFontFamily === void 0 ? {} : { eastAsianFontFamily: style.eastAsianFontFamily },
2476
+ fontSize: style.fontSize,
2477
+ fontWeight: style.fontWeight,
2478
+ fontStyle: style.fontStyle,
2479
+ color: style.color,
2480
+ themeFont: style.themeFont,
2481
+ ...style.eastAsianThemeFont === void 0 ? {} : { eastAsianThemeFont: style.eastAsianThemeFont },
2482
+ letterSpacing: style.letterSpacing,
2483
+ textTransform: style.textTransform,
2484
+ textDecoration: style.textDecoration,
2485
+ textShadow: style.textShadow,
2486
+ textStroke: style.textStroke,
2487
+ lang: style.lang
2488
+ };
2489
+ validateRunStyle(runStyle);
2490
+ const runGroups = texts.map((text) => [{
2491
+ text,
2492
+ style: runStyle
2493
+ }]);
2494
+ for (const text of texts) escapedXml(text);
2495
+ const { resourceClaims, fontUses, fontUsages, missingGlyphErrors } = textResourceClaims(runGroups);
2496
+ const defaultProperties = runPropertiesXml(runStyle, "a:defRPr", theme, "chart-default");
2497
+ const outputText = texts.join("\n");
2498
+ const lineSpacing = lineSpacingXml(style.lineHeight);
2499
+ const alignment = alignmentValue(style.align);
2500
+ const paragraphAlignment = alignment === void 0 ? "" : ` algn="${alignment}"`;
2501
+ const spacingAfter = style.spacingAfter === void 0 ? "" : `<a:spcAft><a:spcPts val="${spacingCentipoints(style.spacingAfter, "spacingAfter")}"/></a:spcAft>`;
2502
+ const endParaLang = runStyle.lang !== void 0 ? ` lang="${escapedXml(runStyle.lang, "style.lang")}"` : "";
2503
+ const body = `<a:bodyPr anchor="${bodyAnchor(style.verticalAlign)}"/><a:lstStyle/>`;
2504
+ const paragraphProperties = `<a:pPr${paragraphAlignment}>${lineSpacing}${spacingAfter}${defaultProperties}</a:pPr>`;
2505
+ const endParagraph = `<a:endParaRPr${endParaLang}/>`;
2506
+ let customTextXml;
2507
+ if (customText !== void 0) {
2508
+ const runProperties = runPropertiesXml(runStyle, "a:rPr", theme, "chart-default");
2509
+ customTextXml = `<c:tx><c:rich>${body}${customText.split("\n").map((line) => `<a:p>${paragraphProperties}<a:r>${runProperties}<a:t>${escapedXml(line)}</a:t></a:r>${endParagraph}</a:p>`).join("")}</c:rich></c:tx>`;
2510
+ }
2511
+ return {
2512
+ xml: `<c:txPr>${body}<a:p>${paragraphProperties}${endParagraph}</a:p></c:txPr>`,
2513
+ ...customTextXml === void 0 ? {} : { customTextXml },
2514
+ text: outputText,
2515
+ resourceClaims,
2516
+ fontUses,
2517
+ fontUsages,
2518
+ missingGlyphErrors
2519
+ };
2520
+ }
2521
+ /** Emits a native chart or axis title with actual run properties, not canvas text. */
2522
+ function writeChartTitle(text, styleValue, label, theme, rotationDegrees) {
2523
+ const style = readTextStyle(styleValue, label, theme);
2524
+ const runStyle = {
2525
+ fontFamily: style.fontFamily,
2526
+ ...style.eastAsianFontFamily === void 0 ? {} : { eastAsianFontFamily: style.eastAsianFontFamily },
2527
+ fontSize: style.fontSize,
2528
+ fontWeight: style.fontWeight,
2529
+ fontStyle: style.fontStyle,
2530
+ color: style.color,
2531
+ themeFont: style.themeFont,
2532
+ ...style.eastAsianThemeFont === void 0 ? {} : { eastAsianThemeFont: style.eastAsianThemeFont },
2533
+ letterSpacing: style.letterSpacing,
2534
+ textTransform: style.textTransform,
2535
+ textDecoration: style.textDecoration,
2536
+ textShadow: style.textShadow,
2537
+ textStroke: style.textStroke,
2538
+ lang: style.lang
2539
+ };
2540
+ validateRunStyle(runStyle);
2541
+ const escapedText = escapedXml(text);
2542
+ const { resourceClaims, fontUses, fontUsages, missingGlyphErrors } = textResourceClaims([[{
2543
+ text,
2544
+ style: runStyle
2545
+ }]]);
2546
+ const runProperties = runPropertiesXml(runStyle, "a:rPr", theme);
2547
+ const defaultProperties = runPropertiesXml(runStyle, "a:defRPr", theme);
2548
+ const lineSpacing = lineSpacingXml(style.lineHeight);
2549
+ const alignment = alignmentValue(style.align);
2550
+ const paragraphAlignment = alignment === void 0 ? "" : ` algn="${alignment}"`;
2551
+ const spacingAfter = style.spacingAfter === void 0 || style.spacingAfter === 0 ? "" : `<a:spcAft><a:spcPts val="${spacingCentipoints(style.spacingAfter, "spacingAfter")}"/></a:spcAft>`;
2552
+ const endParaLang = runStyle.lang !== void 0 ? ` lang="${escapedXml(runStyle.lang, "style.lang")}"` : "";
2553
+ const bodyProperties = `<a:bodyPr${rotationDegrees !== void 0 && rotationDegrees !== 0 ? ` rot="${Math.round(rotationDegrees * 6e4)}"` : ""} anchor="${bodyAnchor(style.verticalAlign)}"/>`;
2554
+ return {
2555
+ xml: `<c:title><c:tx><c:rich>${bodyProperties}<a:lstStyle/><a:p><a:pPr${paragraphAlignment}>${lineSpacing}${spacingAfter}${defaultProperties}</a:pPr><a:r>${runProperties}<a:t>${escapedText}</a:t></a:r><a:endParaRPr${endParaLang}/></a:p></c:rich></c:tx><c:overlay val="0"/><c:txPr>${bodyProperties}<a:lstStyle/><a:p><a:pPr${paragraphAlignment}>${lineSpacing}${spacingAfter}${defaultProperties}</a:pPr><a:endParaRPr${endParaLang}/></a:p></c:txPr></c:title>`,
2556
+ text,
2557
+ resourceClaims,
2558
+ fontUses,
2559
+ fontUsages,
2560
+ missingGlyphErrors
2561
+ };
2562
+ }
2563
+ export { alignMeasuredTextWidthForOuterEmu, alignMeasuredTextWidthsForOuterEmu, computeTextMetrics, declaredFontResourceClaims, emitTextBody, emitTextFieldRunXml, measureParagraphMinContentWidth, measureParagraphs, measureTextLayoutFromParagraphs, parseTextContent, parseTextParagraphs, previewParagraphOutlines, previewTextBoxOutlines, renderTextOutlinesSvg, resolveTextBody, textInsets, withPreviewFontBoundary, writeChartTextProperties, writeChartTitle };