@_vrsen/openswarm 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (316) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +152 -0
  3. package/bin/openswarm.js +38 -0
  4. package/config.py +34 -0
  5. package/data_analyst_agent/.cursor/rules/data_analyst.mdc +43 -0
  6. package/data_analyst_agent/__init__.py +3 -0
  7. package/data_analyst_agent/__pycache__/__init__.cpython-312.pyc +0 -0
  8. package/data_analyst_agent/__pycache__/data_analyst_agent.cpython-312.pyc +0 -0
  9. package/data_analyst_agent/data_analyst_agent.py +45 -0
  10. package/data_analyst_agent/instructions.md +173 -0
  11. package/data_analyst_agent/test_files/test_file.csv +21 -0
  12. package/data_analyst_agent/tools/__init__.py +6 -0
  13. package/deep_research/__init__.py +1 -0
  14. package/deep_research/__pycache__/__init__.cpython-312.pyc +0 -0
  15. package/deep_research/__pycache__/deep_research.cpython-312.pyc +0 -0
  16. package/deep_research/deep_research.py +27 -0
  17. package/deep_research/instructions.md +104 -0
  18. package/deep_research/tools/__init__.py +1 -0
  19. package/docs_agent/__init__.py +3 -0
  20. package/docs_agent/__pycache__/__init__.cpython-312.pyc +0 -0
  21. package/docs_agent/__pycache__/docs_agent.cpython-312.pyc +0 -0
  22. package/docs_agent/docs_agent.py +61 -0
  23. package/docs_agent/instructions.md +418 -0
  24. package/docs_agent/tools/ConvertDocument.py +323 -0
  25. package/docs_agent/tools/CreateDocument.py +287 -0
  26. package/docs_agent/tools/ListDocuments.py +134 -0
  27. package/docs_agent/tools/ModifyDocument.py +247 -0
  28. package/docs_agent/tools/RestoreDocument.py +79 -0
  29. package/docs_agent/tools/ViewDocument.py +153 -0
  30. package/docs_agent/tools/__init__.py +1 -0
  31. package/docs_agent/tools/__pycache__/ConvertDocument.cpython-312.pyc +0 -0
  32. package/docs_agent/tools/__pycache__/CreateDocument.cpython-312.pyc +0 -0
  33. package/docs_agent/tools/__pycache__/ListDocuments.cpython-312.pyc +0 -0
  34. package/docs_agent/tools/__pycache__/ModifyDocument.cpython-312.pyc +0 -0
  35. package/docs_agent/tools/__pycache__/RestoreDocument.cpython-312.pyc +0 -0
  36. package/docs_agent/tools/__pycache__/ViewDocument.cpython-312.pyc +0 -0
  37. package/docs_agent/tools/__pycache__/__init__.cpython-312.pyc +0 -0
  38. package/docs_agent/tools/utils/__init__.py +1 -0
  39. package/docs_agent/tools/utils/__pycache__/__init__.cpython-312.pyc +0 -0
  40. package/docs_agent/tools/utils/__pycache__/doc_file_utils.cpython-312.pyc +0 -0
  41. package/docs_agent/tools/utils/__pycache__/html_docx_blocks.cpython-312.pyc +0 -0
  42. package/docs_agent/tools/utils/__pycache__/html_docx_constants.cpython-312.pyc +0 -0
  43. package/docs_agent/tools/utils/__pycache__/html_docx_core.cpython-312.pyc +0 -0
  44. package/docs_agent/tools/utils/__pycache__/html_docx_css.cpython-312.pyc +0 -0
  45. package/docs_agent/tools/utils/__pycache__/html_docx_images.cpython-312.pyc +0 -0
  46. package/docs_agent/tools/utils/__pycache__/html_docx_page.cpython-312.pyc +0 -0
  47. package/docs_agent/tools/utils/__pycache__/html_docx_paragraphs.cpython-312.pyc +0 -0
  48. package/docs_agent/tools/utils/__pycache__/html_docx_playwright.cpython-312.pyc +0 -0
  49. package/docs_agent/tools/utils/__pycache__/html_docx_selectors.cpython-312.pyc +0 -0
  50. package/docs_agent/tools/utils/__pycache__/html_docx_shared.cpython-312.pyc +0 -0
  51. package/docs_agent/tools/utils/__pycache__/html_validation.cpython-312.pyc +0 -0
  52. package/docs_agent/tools/utils/doc_file_utils.py +29 -0
  53. package/docs_agent/tools/utils/html_docx_blocks.py +262 -0
  54. package/docs_agent/tools/utils/html_docx_constants.py +78 -0
  55. package/docs_agent/tools/utils/html_docx_core.py +138 -0
  56. package/docs_agent/tools/utils/html_docx_css.py +262 -0
  57. package/docs_agent/tools/utils/html_docx_images.py +293 -0
  58. package/docs_agent/tools/utils/html_docx_page.py +185 -0
  59. package/docs_agent/tools/utils/html_docx_paragraphs.py +342 -0
  60. package/docs_agent/tools/utils/html_docx_playwright.py +184 -0
  61. package/docs_agent/tools/utils/html_docx_selectors.py +196 -0
  62. package/docs_agent/tools/utils/html_docx_shared.py +23 -0
  63. package/docs_agent/tools/utils/html_docx_tables.py +942 -0
  64. package/docs_agent/tools/utils/html_validation.py +102 -0
  65. package/helpers.py +59 -0
  66. package/image_generation_agent/__init__.py +1 -0
  67. package/image_generation_agent/__pycache__/__init__.cpython-312.pyc +0 -0
  68. package/image_generation_agent/__pycache__/image_generation_agent.cpython-312.pyc +0 -0
  69. package/image_generation_agent/image_generation_agent.py +31 -0
  70. package/image_generation_agent/instructions.md +80 -0
  71. package/image_generation_agent/tools/CombineImages.py +211 -0
  72. package/image_generation_agent/tools/EditImages.py +200 -0
  73. package/image_generation_agent/tools/GenerateImages.py +184 -0
  74. package/image_generation_agent/tools/RemoveBackground.py +108 -0
  75. package/image_generation_agent/tools/__init__.py +2 -0
  76. package/image_generation_agent/tools/__pycache__/CombineImages.cpython-312.pyc +0 -0
  77. package/image_generation_agent/tools/__pycache__/EditImages.cpython-312.pyc +0 -0
  78. package/image_generation_agent/tools/__pycache__/GenerateImages.cpython-312.pyc +0 -0
  79. package/image_generation_agent/tools/__pycache__/RemoveBackground.cpython-312.pyc +0 -0
  80. package/image_generation_agent/tools/utils/__init__.py +2 -0
  81. package/image_generation_agent/tools/utils/__pycache__/__init__.cpython-312.pyc +0 -0
  82. package/image_generation_agent/tools/utils/__pycache__/image_io.cpython-312.pyc +0 -0
  83. package/image_generation_agent/tools/utils/image_io.py +308 -0
  84. package/onboard.py +325 -0
  85. package/orchestrator/__init__.py +3 -0
  86. package/orchestrator/__pycache__/__init__.cpython-312.pyc +0 -0
  87. package/orchestrator/__pycache__/orchestrator.cpython-312.pyc +0 -0
  88. package/orchestrator/instructions.md +90 -0
  89. package/orchestrator/orchestrator.py +33 -0
  90. package/package.json +49 -0
  91. package/patches/__init__.py +1 -0
  92. package/patches/__pycache__/__init__.cpython-312.pyc +0 -0
  93. package/patches/__pycache__/patch_agency_swarm_dual_comms.cpython-312.pyc +0 -0
  94. package/patches/__pycache__/patch_file_attachment_refs.cpython-312.pyc +0 -0
  95. package/patches/__pycache__/patch_ipython_interpreter_composio.cpython-312.pyc +0 -0
  96. package/patches/dom-to-pptx+1.1.5.patch +133440 -0
  97. package/patches/patch_agency_swarm_dual_comms.py +199 -0
  98. package/patches/patch_file_attachment_refs.py +74 -0
  99. package/patches/patch_ipython_interpreter_composio.py +54 -0
  100. package/pyproject.toml +67 -0
  101. package/run.py +343 -0
  102. package/server.py +26 -0
  103. package/shared_instructions.md +119 -0
  104. package/shared_tools/CopyFile.py +68 -0
  105. package/shared_tools/ExecuteTool.py +184 -0
  106. package/shared_tools/FindTools.py +101 -0
  107. package/shared_tools/ManageConnections.py +43 -0
  108. package/shared_tools/SearchTools.py +44 -0
  109. package/shared_tools/__init__.py +7 -0
  110. package/shared_tools/__pycache__/CopyFile.cpython-312.pyc +0 -0
  111. package/shared_tools/__pycache__/ExecuteTool.cpython-312.pyc +0 -0
  112. package/shared_tools/__pycache__/FindTools.cpython-312.pyc +0 -0
  113. package/shared_tools/__pycache__/ManageConnections.cpython-312.pyc +0 -0
  114. package/shared_tools/__pycache__/SearchTools.cpython-312.pyc +0 -0
  115. package/shared_tools/__pycache__/__init__.cpython-312.pyc +0 -0
  116. package/slides_agent/.cursor/rules/slides-agent-workflow.mdc +9 -0
  117. package/slides_agent/__init__.py +1 -0
  118. package/slides_agent/__pycache__/__init__.cpython-312.pyc +0 -0
  119. package/slides_agent/__pycache__/slides_agent.cpython-312.pyc +0 -0
  120. package/slides_agent/instructions.md +298 -0
  121. package/slides_agent/pptx/SKILL.md +528 -0
  122. package/slides_agent/pptx/html2pptx.md +625 -0
  123. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
  124. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
  125. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
  126. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
  127. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
  128. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
  129. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
  130. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
  131. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
  132. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
  133. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
  134. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
  135. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
  136. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
  137. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
  138. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
  139. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
  140. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
  141. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
  142. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
  143. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
  144. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
  145. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
  146. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
  147. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
  148. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
  149. package/slides_agent/pptx/ooxml/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
  150. package/slides_agent/pptx/ooxml/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
  151. package/slides_agent/pptx/ooxml/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
  152. package/slides_agent/pptx/ooxml/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
  153. package/slides_agent/pptx/ooxml/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
  154. package/slides_agent/pptx/ooxml/schemas/mce/mc.xsd +75 -0
  155. package/slides_agent/pptx/ooxml/schemas/microsoft/wml-2010.xsd +560 -0
  156. package/slides_agent/pptx/ooxml/schemas/microsoft/wml-2012.xsd +67 -0
  157. package/slides_agent/pptx/ooxml/schemas/microsoft/wml-2018.xsd +14 -0
  158. package/slides_agent/pptx/ooxml/schemas/microsoft/wml-cex-2018.xsd +20 -0
  159. package/slides_agent/pptx/ooxml/schemas/microsoft/wml-cid-2016.xsd +13 -0
  160. package/slides_agent/pptx/ooxml/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
  161. package/slides_agent/pptx/ooxml/schemas/microsoft/wml-symex-2015.xsd +8 -0
  162. package/slides_agent/pptx/ooxml/scripts/pack.py +169 -0
  163. package/slides_agent/pptx/ooxml/scripts/unpack.py +29 -0
  164. package/slides_agent/pptx/ooxml/scripts/validate.py +69 -0
  165. package/slides_agent/pptx/ooxml/scripts/validation/__init__.py +15 -0
  166. package/slides_agent/pptx/ooxml/scripts/validation/base.py +951 -0
  167. package/slides_agent/pptx/ooxml/scripts/validation/docx.py +274 -0
  168. package/slides_agent/pptx/ooxml/scripts/validation/pptx.py +315 -0
  169. package/slides_agent/pptx/ooxml/scripts/validation/redlining.py +279 -0
  170. package/slides_agent/pptx/ooxml.md +427 -0
  171. package/slides_agent/pptx/scripts/html2pptx.js +1092 -0
  172. package/slides_agent/pptx/scripts/inventory.py +1020 -0
  173. package/slides_agent/pptx/scripts/rearrange.py +231 -0
  174. package/slides_agent/pptx/scripts/replace.py +385 -0
  175. package/slides_agent/pptx/scripts/thumbnail.py +451 -0
  176. package/slides_agent/slides_agent.py +109 -0
  177. package/slides_agent/test_deck/_theme.css +92 -0
  178. package/slides_agent/test_deck/assets/placeholder.svg +11 -0
  179. package/slides_agent/test_deck/slide_01_title.html +10 -0
  180. package/slides_agent/test_deck/slide_02_image_split.html +23 -0
  181. package/slides_agent/test_deck/slide_03_kpi.html +21 -0
  182. package/slides_agent/tools/ApplyPptxTextReplacements.py +91 -0
  183. package/slides_agent/tools/BuildPptxFromHtmlSlides.py +221 -0
  184. package/slides_agent/tools/CheckSlide.py +218 -0
  185. package/slides_agent/tools/CheckSlideCanvasOverflow.py +221 -0
  186. package/slides_agent/tools/CreateImageMontage.py +261 -0
  187. package/slides_agent/tools/CreatePptxThumbnailGrid.py +168 -0
  188. package/slides_agent/tools/DeleteSlide.py +78 -0
  189. package/slides_agent/tools/DownloadImage.py +79 -0
  190. package/slides_agent/tools/EnsureRasterImage.py +157 -0
  191. package/slides_agent/tools/ExtractPptxTextInventory.py +104 -0
  192. package/slides_agent/tools/GenerateImage.py +189 -0
  193. package/slides_agent/tools/ImageSearch.py +127 -0
  194. package/slides_agent/tools/InsertNewSlides.py +393 -0
  195. package/slides_agent/tools/ManageTheme.py +112 -0
  196. package/slides_agent/tools/ModifySlide.py +563 -0
  197. package/slides_agent/tools/ReadSlide.py +26 -0
  198. package/slides_agent/tools/RearrangePptxSlidesFromTemplate.py +114 -0
  199. package/slides_agent/tools/RestoreSnapshot.py +89 -0
  200. package/slides_agent/tools/SlideScreenshot.py +66 -0
  201. package/slides_agent/tools/__init__.py +54 -0
  202. package/slides_agent/tools/__pycache__/ApplyPptxTextReplacements.cpython-312.pyc +0 -0
  203. package/slides_agent/tools/__pycache__/BuildPptxFromHtmlSlides.cpython-312.pyc +0 -0
  204. package/slides_agent/tools/__pycache__/CheckSlide.cpython-312.pyc +0 -0
  205. package/slides_agent/tools/__pycache__/CheckSlideCanvasOverflow.cpython-312.pyc +0 -0
  206. package/slides_agent/tools/__pycache__/CreateImageMontage.cpython-312.pyc +0 -0
  207. package/slides_agent/tools/__pycache__/CreatePptxThumbnailGrid.cpython-312.pyc +0 -0
  208. package/slides_agent/tools/__pycache__/DeleteSlide.cpython-312.pyc +0 -0
  209. package/slides_agent/tools/__pycache__/DownloadImage.cpython-312.pyc +0 -0
  210. package/slides_agent/tools/__pycache__/EnsureRasterImage.cpython-312.pyc +0 -0
  211. package/slides_agent/tools/__pycache__/ExtractPptxTextInventory.cpython-312.pyc +0 -0
  212. package/slides_agent/tools/__pycache__/GenerateImage.cpython-312.pyc +0 -0
  213. package/slides_agent/tools/__pycache__/ImageSearch.cpython-312.pyc +0 -0
  214. package/slides_agent/tools/__pycache__/InsertNewSlides.cpython-312.pyc +0 -0
  215. package/slides_agent/tools/__pycache__/ManageTheme.cpython-312.pyc +0 -0
  216. package/slides_agent/tools/__pycache__/ModifySlide.cpython-312.pyc +0 -0
  217. package/slides_agent/tools/__pycache__/ReadSlide.cpython-312.pyc +0 -0
  218. package/slides_agent/tools/__pycache__/RearrangePptxSlidesFromTemplate.cpython-312.pyc +0 -0
  219. package/slides_agent/tools/__pycache__/RestoreSnapshot.cpython-312.pyc +0 -0
  220. package/slides_agent/tools/__pycache__/SlideScreenshot.cpython-312.pyc +0 -0
  221. package/slides_agent/tools/__pycache__/__init__.cpython-312.pyc +0 -0
  222. package/slides_agent/tools/__pycache__/slide_file_utils.cpython-312.pyc +0 -0
  223. package/slides_agent/tools/__pycache__/slide_html_utils.cpython-312.pyc +0 -0
  224. package/slides_agent/tools/__pycache__/template_registry.cpython-312.pyc +0 -0
  225. package/slides_agent/tools/deck_utils.py +31 -0
  226. package/slides_agent/tools/html2pptx_runner.js +1183 -0
  227. package/slides_agent/tools/html_writer_instructions.md +149 -0
  228. package/slides_agent/tools/slide_file_utils.py +108 -0
  229. package/slides_agent/tools/slide_html_utils.py +354 -0
  230. package/slides_agent/tools/template_registry.py +55 -0
  231. package/swarm.py +82 -0
  232. package/video_generation_agent/__init__.py +1 -0
  233. package/video_generation_agent/__pycache__/__init__.cpython-312.pyc +0 -0
  234. package/video_generation_agent/__pycache__/video_generation_agent.cpython-312.pyc +0 -0
  235. package/video_generation_agent/instructions.md +178 -0
  236. package/video_generation_agent/tools/AddSubtitles.py +425 -0
  237. package/video_generation_agent/tools/CombineImages.py +166 -0
  238. package/video_generation_agent/tools/CombineVideos.py +113 -0
  239. package/video_generation_agent/tools/EditAudio.py +297 -0
  240. package/video_generation_agent/tools/EditImage.py +144 -0
  241. package/video_generation_agent/tools/EditVideoContent.py +369 -0
  242. package/video_generation_agent/tools/GenerateImage.py +133 -0
  243. package/video_generation_agent/tools/GenerateVideo.py +556 -0
  244. package/video_generation_agent/tools/TrimVideo.py +233 -0
  245. package/video_generation_agent/tools/__init__.py +1 -0
  246. package/video_generation_agent/tools/__pycache__/AddSubtitles.cpython-312.pyc +0 -0
  247. package/video_generation_agent/tools/__pycache__/CombineImages.cpython-312.pyc +0 -0
  248. package/video_generation_agent/tools/__pycache__/CombineVideos.cpython-312.pyc +0 -0
  249. package/video_generation_agent/tools/__pycache__/EditAudio.cpython-312.pyc +0 -0
  250. package/video_generation_agent/tools/__pycache__/EditImage.cpython-312.pyc +0 -0
  251. package/video_generation_agent/tools/__pycache__/EditVideoContent.cpython-312.pyc +0 -0
  252. package/video_generation_agent/tools/__pycache__/GenerateImage.cpython-312.pyc +0 -0
  253. package/video_generation_agent/tools/__pycache__/GenerateVideo.cpython-312.pyc +0 -0
  254. package/video_generation_agent/tools/__pycache__/TrimVideo.cpython-312.pyc +0 -0
  255. package/video_generation_agent/tools/utils/__init__.py +1 -0
  256. package/video_generation_agent/tools/utils/__pycache__/__init__.cpython-312.pyc +0 -0
  257. package/video_generation_agent/tools/utils/__pycache__/image_utils.cpython-312.pyc +0 -0
  258. package/video_generation_agent/tools/utils/__pycache__/video_utils.cpython-312.pyc +0 -0
  259. package/video_generation_agent/tools/utils/image_utils.py +174 -0
  260. package/video_generation_agent/tools/utils/video_utils.py +522 -0
  261. package/video_generation_agent/video_generation_agent.py +26 -0
  262. package/virtual_assistant/__init__.py +1 -0
  263. package/virtual_assistant/__pycache__/__init__.cpython-312.pyc +0 -0
  264. package/virtual_assistant/__pycache__/virtual_assistant.cpython-312.pyc +0 -0
  265. package/virtual_assistant/instructions.md +206 -0
  266. package/virtual_assistant/tools/AddLabelToEmail.py +154 -0
  267. package/virtual_assistant/tools/CheckEventsForDate.py +218 -0
  268. package/virtual_assistant/tools/CheckUnreadSlackMessages.py +216 -0
  269. package/virtual_assistant/tools/CreateCalendarEvent.py +261 -0
  270. package/virtual_assistant/tools/DeleteCalendarEvent.py +137 -0
  271. package/virtual_assistant/tools/DeleteDraft.py +95 -0
  272. package/virtual_assistant/tools/DraftEmail.py +239 -0
  273. package/virtual_assistant/tools/EditFile.py +113 -0
  274. package/virtual_assistant/tools/FindEmails.py +330 -0
  275. package/virtual_assistant/tools/GetCurrentTime.py +69 -0
  276. package/virtual_assistant/tools/GetSlackUserInfo.py +117 -0
  277. package/virtual_assistant/tools/ListDirectory.py +113 -0
  278. package/virtual_assistant/tools/ListSkills.py +94 -0
  279. package/virtual_assistant/tools/ManageLabels.py +295 -0
  280. package/virtual_assistant/tools/ProductSearch.py +254 -0
  281. package/virtual_assistant/tools/ReadEmail.py +251 -0
  282. package/virtual_assistant/tools/ReadFile.py +108 -0
  283. package/virtual_assistant/tools/ReadSlackMessages.py +191 -0
  284. package/virtual_assistant/tools/RemoveLabelFromEmail.py +137 -0
  285. package/virtual_assistant/tools/RescheduleCalendarEvent.py +227 -0
  286. package/virtual_assistant/tools/ScholarSearch.py +216 -0
  287. package/virtual_assistant/tools/SendDraft.py +101 -0
  288. package/virtual_assistant/tools/SendSlackMessage.py +148 -0
  289. package/virtual_assistant/tools/WriteFile.py +95 -0
  290. package/virtual_assistant/tools/__init__.py +1 -0
  291. package/virtual_assistant/tools/__pycache__/AddLabelToEmail.cpython-312.pyc +0 -0
  292. package/virtual_assistant/tools/__pycache__/CheckEventsForDate.cpython-312.pyc +0 -0
  293. package/virtual_assistant/tools/__pycache__/CheckUnreadSlackMessages.cpython-312.pyc +0 -0
  294. package/virtual_assistant/tools/__pycache__/CreateCalendarEvent.cpython-312.pyc +0 -0
  295. package/virtual_assistant/tools/__pycache__/DeleteCalendarEvent.cpython-312.pyc +0 -0
  296. package/virtual_assistant/tools/__pycache__/DeleteDraft.cpython-312.pyc +0 -0
  297. package/virtual_assistant/tools/__pycache__/DraftEmail.cpython-312.pyc +0 -0
  298. package/virtual_assistant/tools/__pycache__/EditFile.cpython-312.pyc +0 -0
  299. package/virtual_assistant/tools/__pycache__/FindEmails.cpython-312.pyc +0 -0
  300. package/virtual_assistant/tools/__pycache__/GetCurrentTime.cpython-312.pyc +0 -0
  301. package/virtual_assistant/tools/__pycache__/GetSlackUserInfo.cpython-312.pyc +0 -0
  302. package/virtual_assistant/tools/__pycache__/ListDirectory.cpython-312.pyc +0 -0
  303. package/virtual_assistant/tools/__pycache__/ListSkills.cpython-312.pyc +0 -0
  304. package/virtual_assistant/tools/__pycache__/ManageLabels.cpython-312.pyc +0 -0
  305. package/virtual_assistant/tools/__pycache__/ProductSearch.cpython-312.pyc +0 -0
  306. package/virtual_assistant/tools/__pycache__/ReadEmail.cpython-312.pyc +0 -0
  307. package/virtual_assistant/tools/__pycache__/ReadFile.cpython-312.pyc +0 -0
  308. package/virtual_assistant/tools/__pycache__/ReadSlackMessages.cpython-312.pyc +0 -0
  309. package/virtual_assistant/tools/__pycache__/RemoveLabelFromEmail.cpython-312.pyc +0 -0
  310. package/virtual_assistant/tools/__pycache__/RescheduleCalendarEvent.cpython-312.pyc +0 -0
  311. package/virtual_assistant/tools/__pycache__/ScholarSearch.cpython-312.pyc +0 -0
  312. package/virtual_assistant/tools/__pycache__/SendDraft.cpython-312.pyc +0 -0
  313. package/virtual_assistant/tools/__pycache__/SendSlackMessage.cpython-312.pyc +0 -0
  314. package/virtual_assistant/tools/__pycache__/WriteFile.cpython-312.pyc +0 -0
  315. package/virtual_assistant/tools/__pycache__/__init__.cpython-312.pyc +0 -0
  316. package/virtual_assistant/virtual_assistant.py +52 -0
@@ -0,0 +1,1092 @@
1
+ // prettier-ignore-file
2
+ /* eslint-disable */
3
+ // @ts-nocheck
4
+ // DO NOT FORMAT THIS FILE - Contains sensitive optional chaining syntax
5
+
6
+ /**
7
+ * html2pptx - Convert HTML slide to pptxgenjs slide with positioned elements
8
+ *
9
+ * USAGE:
10
+ * const pptx = new pptxgen();
11
+ * pptx.layout = 'LAYOUT_16x9'; // Must match HTML body dimensions
12
+ *
13
+ * const { slide, placeholders } = await html2pptx('slide.html', pptx);
14
+ * slide.addChart(pptx.charts.LINE, data, placeholders[0]);
15
+ *
16
+ * await pptx.writeFile('output.pptx');
17
+ *
18
+ * FEATURES:
19
+ * - Converts HTML to PowerPoint with accurate positioning
20
+ * - Supports text, images, shapes, and bullet lists
21
+ * - Extracts placeholder elements (class="placeholder") with positions
22
+ * - Handles CSS gradients, borders, and margins
23
+ *
24
+ * VALIDATION:
25
+ * - Uses body width/height from HTML for viewport sizing
26
+ * - Throws error if HTML dimensions don't match presentation layout
27
+ * - Throws error if content overflows body (with overflow details)
28
+ *
29
+ * RETURNS:
30
+ * { slide, placeholders } where placeholders is an array of { id, x, y, w, h }
31
+ */
32
+
33
+ const path = require('path');
34
+ // Isolate Node.js Playwright browsers from Python Playwright to prevent
35
+ // npm's cleanup from deleting Python's browser binaries.
36
+ if (!process.env.PLAYWRIGHT_BROWSERS_PATH) {
37
+ process.env.PLAYWRIGHT_BROWSERS_PATH = path.join(__dirname, '..', '..', '.playwright-browsers');
38
+ }
39
+ const { chromium } = require('playwright');
40
+ const sharp = require('sharp');
41
+
42
+ const PT_PER_PX = 0.75;
43
+ const PX_PER_IN = 96;
44
+ const EMU_PER_IN = 914400;
45
+
46
+ // Helper: Get body dimensions and check for overflow
47
+ async function getBodyDimensions(page) {
48
+ const bodyDimensions = await page.evaluate(() => {
49
+ const body = document.body;
50
+ const style = window.getComputedStyle(body);
51
+
52
+ return {
53
+ width: parseFloat(style.width),
54
+ height: parseFloat(style.height),
55
+ scrollWidth: body.scrollWidth,
56
+ scrollHeight: body.scrollHeight
57
+ };
58
+ });
59
+
60
+ const errors = [];
61
+ const widthOverflowPx = Math.max(0, bodyDimensions.scrollWidth - bodyDimensions.width - 1);
62
+ const heightOverflowPx = Math.max(0, bodyDimensions.scrollHeight - bodyDimensions.height - 1);
63
+
64
+ const widthOverflowPt = widthOverflowPx * PT_PER_PX;
65
+ const heightOverflowPt = heightOverflowPx * PT_PER_PX;
66
+
67
+ if (widthOverflowPt > 0 || heightOverflowPt > 0) {
68
+ const directions = [];
69
+ if (widthOverflowPt > 0) directions.push(`${widthOverflowPt.toFixed(1)}pt horizontally`);
70
+ if (heightOverflowPt > 0) directions.push(`${heightOverflowPt.toFixed(1)}pt vertically`);
71
+ const reminder = heightOverflowPt > 0 ? ' (Remember: leave 0.5" margin at bottom of slide)' : '';
72
+ errors.push(`HTML content overflows body by ${directions.join(' and ')}${reminder}`);
73
+ }
74
+
75
+ return {...bodyDimensions, errors };
76
+ }
77
+
78
+ // Helper: Validate dimensions match presentation layout
79
+ function validateDimensions(bodyDimensions, pres) {
80
+ const errors = [];
81
+ const widthInches = bodyDimensions.width / PX_PER_IN;
82
+ const heightInches = bodyDimensions.height / PX_PER_IN;
83
+
84
+ if (pres.presLayout) {
85
+ const layoutWidth = pres.presLayout.width / EMU_PER_IN;
86
+ const layoutHeight = pres.presLayout.height / EMU_PER_IN;
87
+
88
+ if (Math.abs(layoutWidth - widthInches) > 0.1 || Math.abs(layoutHeight - heightInches) > 0.1) {
89
+ errors.push(
90
+ `HTML dimensions (${widthInches.toFixed(1)}" × ${heightInches.toFixed(1)}") ` +
91
+ `don't match presentation layout (${layoutWidth.toFixed(1)}" × ${layoutHeight.toFixed(1)}")`
92
+ );
93
+ }
94
+ }
95
+ return errors;
96
+ }
97
+
98
+ function validateTextBoxPosition(slideData, bodyDimensions) {
99
+ const errors = [];
100
+ const slideHeightInches = bodyDimensions.height / PX_PER_IN;
101
+ const minBottomMargin = 0.5; // 0.5 inches from bottom
102
+
103
+ for (const el of slideData.elements) {
104
+ // Check text elements (p, h1-h6, list)
105
+ if (['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'list'].includes(el.type)) {
106
+ const fontSize = el.style?.fontSize || 0;
107
+ const bottomEdge = el.position.y + el.position.h;
108
+ const distanceFromBottom = slideHeightInches - bottomEdge;
109
+
110
+ if (fontSize > 12 && distanceFromBottom < minBottomMargin) {
111
+ const getText = () => {
112
+ if (typeof el.text === 'string') return el.text;
113
+ if (Array.isArray(el.text)) return el.text.find(t => t.text)?.text || '';
114
+ if (Array.isArray(el.items)) return el.items.find(item => item.text)?.text || '';
115
+ return '';
116
+ };
117
+ const textPrefix = getText().substring(0, 50) + (getText().length > 50 ? '...' : '');
118
+
119
+ errors.push(
120
+ `Text box "${textPrefix}" ends too close to bottom edge ` +
121
+ `(${distanceFromBottom.toFixed(2)}" from bottom, minimum ${minBottomMargin}" required)`
122
+ );
123
+ }
124
+ }
125
+ }
126
+
127
+ return errors;
128
+ }
129
+
130
+ // Helper: Add background to slide
131
+ async function addBackground(slideData, targetSlide, tmpDir) {
132
+ if (slideData.background.type === 'image' && slideData.background.path) {
133
+ targetSlide.background = { path: slideData.background.path };
134
+ } else if (slideData.background.type === 'color' && slideData.background.value) {
135
+ targetSlide.background = { color: slideData.background.value };
136
+ }
137
+ }
138
+
139
+ // Helper: Add elements to slide
140
+ function addElements(slideData, targetSlide, pres) {
141
+ for (const el of slideData.elements) {
142
+ if (el.type === 'image') {
143
+ const imageOptions = {
144
+ path: el.src,
145
+ x: el.position.x,
146
+ y: el.position.y,
147
+ w: el.position.w,
148
+ h: el.position.h
149
+ };
150
+ if (el.transparency !== null && el.transparency !== undefined) {
151
+ imageOptions.transparency = el.transparency;
152
+ }
153
+ targetSlide.addImage(imageOptions);
154
+ } else if (el.type === 'line') {
155
+ targetSlide.addShape(pres.ShapeType.line, {
156
+ x: el.x1,
157
+ y: el.y1,
158
+ w: el.x2 - el.x1,
159
+ h: el.y2 - el.y1,
160
+ line: { color: el.color, width: el.width }
161
+ });
162
+ } else if (el.type === 'shape') {
163
+ const shapeOptions = {
164
+ x: el.position.x,
165
+ y: el.position.y,
166
+ w: el.position.w,
167
+ h: el.position.h,
168
+ shape: el.shape.rectRadius > 0 ? pres.ShapeType.roundRect : pres.ShapeType.rect
169
+ };
170
+
171
+ if (el.shape.fill) {
172
+ shapeOptions.fill = { color: el.shape.fill };
173
+ if (el.shape.transparency != null) shapeOptions.fill.transparency = el.shape.transparency;
174
+ }
175
+ if (el.shape.line) shapeOptions.line = el.shape.line;
176
+ if (el.shape.rectRadius > 0) shapeOptions.rectRadius = el.shape.rectRadius;
177
+ if (el.shape.shadow) shapeOptions.shadow = el.shape.shadow;
178
+
179
+ targetSlide.addText(el.text || '', shapeOptions);
180
+ } else if (el.type === 'list') {
181
+ const listOptions = {
182
+ x: el.position.x,
183
+ y: el.position.y,
184
+ w: el.position.w,
185
+ h: el.position.h,
186
+ fontSize: el.style.fontSize,
187
+ fontFace: el.style.fontFace,
188
+ color: el.style.color,
189
+ align: el.style.align,
190
+ valign: 'top',
191
+ lineSpacing: el.style.lineSpacing,
192
+ paraSpaceBefore: el.style.paraSpaceBefore,
193
+ paraSpaceAfter: el.style.paraSpaceAfter,
194
+ margin: el.style.margin
195
+ };
196
+ if (el.style.margin) listOptions.margin = el.style.margin;
197
+ targetSlide.addText(el.items, listOptions);
198
+ } else {
199
+ // Check if text is single-line (height suggests one line)
200
+ const lineHeight = el.style.lineSpacing || el.style.fontSize * 1.2;
201
+ const isSingleLine = el.position.h <= lineHeight * 1.5;
202
+
203
+ let adjustedX = el.position.x;
204
+ let adjustedW = el.position.w;
205
+
206
+ // Make single-line text 2% wider to account for underestimate
207
+ if (isSingleLine) {
208
+ const widthIncrease = el.position.w * 0.02;
209
+ const align = el.style.align;
210
+
211
+ if (align === 'center') {
212
+ // Center: expand both sides
213
+ adjustedX = el.position.x - (widthIncrease / 2);
214
+ adjustedW = el.position.w + widthIncrease;
215
+ } else if (align === 'right') {
216
+ // Right: expand to the left
217
+ adjustedX = el.position.x - widthIncrease;
218
+ adjustedW = el.position.w + widthIncrease;
219
+ } else {
220
+ // Left (default): expand to the right
221
+ adjustedW = el.position.w + widthIncrease;
222
+ }
223
+ }
224
+
225
+ const textOptions = {
226
+ x: adjustedX,
227
+ y: el.position.y,
228
+ w: adjustedW,
229
+ h: el.position.h,
230
+ fontSize: el.style.fontSize,
231
+ fontFace: el.style.fontFace,
232
+ color: el.style.color,
233
+ bold: el.style.bold,
234
+ italic: el.style.italic,
235
+ underline: el.style.underline,
236
+ valign: 'top',
237
+ lineSpacing: el.style.lineSpacing,
238
+ paraSpaceBefore: el.style.paraSpaceBefore,
239
+ paraSpaceAfter: el.style.paraSpaceAfter,
240
+ inset: 0 // Remove default PowerPoint internal padding
241
+ };
242
+
243
+ if (el.style.align) textOptions.align = el.style.align;
244
+ if (el.style.margin) textOptions.margin = el.style.margin;
245
+ if (el.style.rotate !== undefined) textOptions.rotate = el.style.rotate;
246
+ if (el.style.transparency !== null && el.style.transparency !== undefined) textOptions.transparency = el.style.transparency;
247
+
248
+ targetSlide.addText(el.text, textOptions);
249
+ }
250
+ }
251
+ }
252
+
253
+ // Helper: Extract slide data from HTML page
254
+ async function extractSlideData(page, htmlDir) {
255
+ return await page.evaluate((htmlDir) => {
256
+ const PT_PER_PX = 0.75;
257
+ const PX_PER_IN = 96;
258
+
259
+ // Fonts that are single-weight and should not have bold applied
260
+ // (applying bold causes PowerPoint to use faux bold which makes text wider)
261
+ const SINGLE_WEIGHT_FONTS = ['impact'];
262
+
263
+ // Helper: Check if a font should skip bold formatting
264
+ const shouldSkipBold = (fontFamily) => {
265
+ if (!fontFamily) return false;
266
+ const normalizedFont = fontFamily.toLowerCase().replace(/['"]/g, '').split(',')[0].trim();
267
+ return SINGLE_WEIGHT_FONTS.includes(normalizedFont);
268
+ };
269
+
270
+ // Unit conversion helpers
271
+ const pxToInch = (px) => px / PX_PER_IN;
272
+ const pxToPoints = (pxStr) => parseFloat(pxStr) * PT_PER_PX;
273
+
274
+ // Path resolution helper: resolve relative paths to absolute
275
+ const resolvePath = (urlPath) => {
276
+ if (!urlPath) return urlPath;
277
+
278
+ // Handle file:// URLs from browser (strip protocol properly)
279
+ if (urlPath.startsWith('file://')) {
280
+ // file:///D:/path -> D:/path (Windows)
281
+ // file:///C:/path -> C:/path (Windows)
282
+ // file:///path -> /path (Unix)
283
+ let localPath = urlPath.replace(/^file:\/\/\//, '');
284
+ // Handle file://path (two slashes)
285
+ if (localPath === urlPath.substring(7)) {
286
+ localPath = urlPath.replace(/^file:\/\//, '');
287
+ }
288
+ return localPath;
289
+ }
290
+
291
+ // Already absolute HTTP/HTTPS/data URLs
292
+ if (urlPath.startsWith('http://') || urlPath.startsWith('https://') || urlPath.startsWith('data:')) {
293
+ return urlPath;
294
+ }
295
+
296
+ // Already absolute Windows path (C:\, D:\, etc.)
297
+ if (/^[A-Za-z]:[\\/]/.test(urlPath)) {
298
+ return urlPath;
299
+ }
300
+
301
+ // Already absolute Unix path
302
+ if (urlPath.startsWith('/')) {
303
+ return urlPath;
304
+ }
305
+
306
+ // Relative path - join with htmlDir
307
+ const separator = htmlDir.includes('\\') ? '\\' : '/';
308
+ return htmlDir + separator + urlPath.replace(/^\.\//, '').replace(/^\.\\/, '');
309
+ };
310
+
311
+ const rgbToHex = (rgbStr) => {
312
+ // Handle transparent backgrounds by defaulting to white
313
+ if (rgbStr === 'rgba(0, 0, 0, 0)' || rgbStr === 'transparent') return 'FFFFFF';
314
+
315
+ const match = rgbStr.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
316
+ if (!match) return 'FFFFFF';
317
+ return match.slice(1).map(n => parseInt(n).toString(16).padStart(2, '0')).join('');
318
+ };
319
+
320
+ const extractAlpha = (rgbStr) => {
321
+ const match = rgbStr.match(/rgba\((\d+),\s*(\d+),\s*(\d+),\s*([\d.]+)\)/);
322
+ if (!match || !match[4]) return null;
323
+ const alpha = parseFloat(match[4]);
324
+ return Math.round((1 - alpha) * 100);
325
+ };
326
+
327
+ const applyTextTransform = (text, textTransform) => {
328
+ if (textTransform === 'uppercase') return text.toUpperCase();
329
+ if (textTransform === 'lowercase') return text.toLowerCase();
330
+ if (textTransform === 'capitalize') {
331
+ return text.replace(/\b\w/g, c => c.toUpperCase());
332
+ }
333
+ return text;
334
+ };
335
+
336
+ // Extract rotation angle from CSS transform and writing-mode
337
+ const getRotation = (transform, writingMode) => {
338
+ let angle = 0;
339
+
340
+ // Handle writing-mode first
341
+ // PowerPoint: 90° = text rotated 90° clockwise (reads top to bottom, letters upright)
342
+ // PowerPoint: 270° = text rotated 270° clockwise (reads bottom to top, letters upright)
343
+ if (writingMode === 'vertical-rl') {
344
+ // vertical-rl alone = text reads top to bottom = 90° in PowerPoint
345
+ angle = 90;
346
+ } else if (writingMode === 'vertical-lr') {
347
+ // vertical-lr alone = text reads bottom to top = 270° in PowerPoint
348
+ angle = 270;
349
+ }
350
+
351
+ // Then add any transform rotation
352
+ if (transform && transform !== 'none') {
353
+ // Try to match rotate() function
354
+ const rotateMatch = transform.match(/rotate\((-?\d+(?:\.\d+)?)deg\)/);
355
+ if (rotateMatch) {
356
+ angle += parseFloat(rotateMatch[1]);
357
+ } else {
358
+ // Browser may compute as matrix - extract rotation from matrix
359
+ const matrixMatch = transform.match(/matrix\(([^)]+)\)/);
360
+ if (matrixMatch) {
361
+ const values = matrixMatch[1].split(',').map(parseFloat);
362
+ // matrix(a, b, c, d, e, f) where rotation = atan2(b, a)
363
+ const matrixAngle = Math.atan2(values[1], values[0]) * (180 / Math.PI);
364
+ angle += Math.round(matrixAngle);
365
+ }
366
+ }
367
+ }
368
+
369
+ // Normalize to 0-359 range
370
+ angle = angle % 360;
371
+ if (angle < 0) angle += 360;
372
+
373
+ return angle === 0 ? null : angle;
374
+ };
375
+
376
+ // Get position/dimensions accounting for rotation
377
+ const getPositionAndSize = (el, rect, rotation) => {
378
+ if (rotation === null) {
379
+ return { x: rect.left, y: rect.top, w: rect.width, h: rect.height };
380
+ }
381
+
382
+ // For 90° or 270° rotations, swap width and height
383
+ // because PowerPoint applies rotation to the original (unrotated) box
384
+ const isVertical = rotation === 90 || rotation === 270;
385
+
386
+ if (isVertical) {
387
+ // The browser shows us the rotated dimensions (tall box for vertical text)
388
+ // But PowerPoint needs the pre-rotation dimensions (wide box that will be rotated)
389
+ // So we swap: browser's height becomes PPT's width, browser's width becomes PPT's height
390
+ const centerX = rect.left + rect.width / 2;
391
+ const centerY = rect.top + rect.height / 2;
392
+
393
+ return {
394
+ x: centerX - rect.height / 2,
395
+ y: centerY - rect.width / 2,
396
+ w: rect.height,
397
+ h: rect.width
398
+ };
399
+ }
400
+
401
+ // For other rotations, use element's offset dimensions
402
+ const centerX = rect.left + rect.width / 2;
403
+ const centerY = rect.top + rect.height / 2;
404
+ return {
405
+ x: centerX - el.offsetWidth / 2,
406
+ y: centerY - el.offsetHeight / 2,
407
+ w: el.offsetWidth,
408
+ h: el.offsetHeight
409
+ };
410
+ };
411
+
412
+ // Parse CSS box-shadow into PptxGenJS shadow properties
413
+ const parseBoxShadow = (boxShadow) => {
414
+ if (!boxShadow || boxShadow === 'none') return null;
415
+
416
+ // Browser computed style format: "rgba(0, 0, 0, 0.3) 2px 2px 8px 0px [inset]"
417
+ // CSS format: "[inset] 2px 2px 8px 0px rgba(0, 0, 0, 0.3)"
418
+
419
+ const insetMatch = boxShadow.match(/inset/);
420
+
421
+ // IMPORTANT: PptxGenJS/PowerPoint doesn't properly support inset shadows
422
+ // Only process outer shadows to avoid file corruption
423
+ if (insetMatch) return null;
424
+
425
+ // Extract color first (rgba or rgb at start)
426
+ const colorMatch = boxShadow.match(/rgba?\([^)]+\)/);
427
+
428
+ // Extract numeric values (handles both px and pt units)
429
+ const parts = boxShadow.match(/([-\d.]+)(px|pt)/g);
430
+
431
+ if (!parts || parts.length < 2) return null;
432
+
433
+ const offsetX = parseFloat(parts[0]);
434
+ const offsetY = parseFloat(parts[1]);
435
+ const blur = parts.length > 2 ? parseFloat(parts[2]) : 0;
436
+
437
+ // Calculate angle from offsets (in degrees, 0 = right, 90 = down)
438
+ let angle = 0;
439
+ if (offsetX !== 0 || offsetY !== 0) {
440
+ angle = Math.atan2(offsetY, offsetX) * (180 / Math.PI);
441
+ if (angle < 0) angle += 360;
442
+ }
443
+
444
+ // Calculate offset distance (hypotenuse)
445
+ const offset = Math.sqrt(offsetX * offsetX + offsetY * offsetY) * PT_PER_PX;
446
+
447
+ // Extract opacity from rgba
448
+ let opacity = 0.5;
449
+ if (colorMatch) {
450
+ const opacityMatch = colorMatch[0].match(/[\d.]+\)$/);
451
+ if (opacityMatch) {
452
+ opacity = parseFloat(opacityMatch[0].replace(')', ''));
453
+ }
454
+ }
455
+
456
+ return {
457
+ type: 'outer',
458
+ angle: Math.round(angle),
459
+ blur: blur * 0.75, // Convert to points
460
+ color: colorMatch ? rgbToHex(colorMatch[0]) : '000000',
461
+ offset: offset,
462
+ opacity
463
+ };
464
+ };
465
+
466
+ // Parse inline formatting tags (<b>, <i>, <u>, <strong>, <em>, <span>) into text runs
467
+ const parseInlineFormatting = (element, baseOptions = {}, runs = [], baseTextTransform = (x) => x) => {
468
+ let prevNodeIsText = false;
469
+
470
+ element.childNodes.forEach((node) => {
471
+ let textTransform = baseTextTransform;
472
+
473
+ const isText = node.nodeType === Node.TEXT_NODE || node.tagName === 'BR';
474
+ if (isText) {
475
+ const text = node.tagName === 'BR' ? '\n' : textTransform(node.textContent.replace(/\s+/g, ' '));
476
+ const prevRun = runs[runs.length - 1];
477
+ if (prevNodeIsText && prevRun) {
478
+ prevRun.text += text;
479
+ } else {
480
+ runs.push({ text, options: {...baseOptions } });
481
+ }
482
+
483
+ } else if (node.nodeType === Node.ELEMENT_NODE && node.textContent.trim()) {
484
+ const options = {...baseOptions };
485
+ const computed = window.getComputedStyle(node);
486
+
487
+ // Handle inline elements with computed styles
488
+ if (node.tagName === 'SPAN' || node.tagName === 'B' || node.tagName === 'STRONG' || node.tagName === 'I' || node.tagName === 'EM' || node.tagName === 'U') {
489
+ const isBold = computed.fontWeight === 'bold' || parseInt(computed.fontWeight) >= 600;
490
+ if (isBold && !shouldSkipBold(computed.fontFamily)) options.bold = true;
491
+ if (computed.fontStyle === 'italic') options.italic = true;
492
+ if (computed.textDecoration && computed.textDecoration.includes('underline')) options.underline = true;
493
+ if (computed.color && computed.color !== 'rgb(0, 0, 0)') {
494
+ options.color = rgbToHex(computed.color);
495
+ const transparency = extractAlpha(computed.color);
496
+ if (transparency !== null) options.transparency = transparency;
497
+ }
498
+ if (computed.fontSize) options.fontSize = pxToPoints(computed.fontSize);
499
+
500
+ // Apply text-transform on the span element itself
501
+ if (computed.textTransform && computed.textTransform !== 'none') {
502
+ const transformStr = computed.textTransform;
503
+ textTransform = (text) => applyTextTransform(text, transformStr);
504
+ }
505
+
506
+ // Validate: Check for margins on inline elements
507
+ if (computed.marginLeft && parseFloat(computed.marginLeft) > 0) {
508
+ errors.push(`Inline element <${node.tagName.toLowerCase()}> has margin-left which is not supported in PowerPoint. Remove margin from inline elements.`);
509
+ }
510
+ if (computed.marginRight && parseFloat(computed.marginRight) > 0) {
511
+ errors.push(`Inline element <${node.tagName.toLowerCase()}> has margin-right which is not supported in PowerPoint. Remove margin from inline elements.`);
512
+ }
513
+ if (computed.marginTop && parseFloat(computed.marginTop) > 0) {
514
+ errors.push(`Inline element <${node.tagName.toLowerCase()}> has margin-top which is not supported in PowerPoint. Remove margin from inline elements.`);
515
+ }
516
+ if (computed.marginBottom && parseFloat(computed.marginBottom) > 0) {
517
+ errors.push(`Inline element <${node.tagName.toLowerCase()}> has margin-bottom which is not supported in PowerPoint. Remove margin from inline elements.`);
518
+ }
519
+
520
+ // Recursively process the child node. This will flatten nested spans into multiple runs.
521
+ parseInlineFormatting(node, options, runs, textTransform);
522
+ }
523
+ }
524
+
525
+ prevNodeIsText = isText;
526
+ });
527
+
528
+ // Trim leading space from first run and trailing space from last run
529
+ if (runs.length > 0) {
530
+ runs[0].text = runs[0].text.replace(/^\s+/, '');
531
+ runs[runs.length - 1].text = runs[runs.length - 1].text.replace(/\s+$/, '');
532
+ }
533
+
534
+ return runs.filter(r => r.text.length > 0);
535
+ };
536
+
537
+ // Extract background from body (image or color)
538
+ const body = document.body;
539
+ const bodyStyle = window.getComputedStyle(body);
540
+ const bgImage = bodyStyle.backgroundImage;
541
+ const bgColor = bodyStyle.backgroundColor;
542
+
543
+ // Collect validation errors
544
+ const errors = [];
545
+
546
+ // Validate: Check for CSS gradients
547
+ if (bgImage && (bgImage.includes('linear-gradient') || bgImage.includes('radial-gradient'))) {
548
+ errors.push(
549
+ 'CSS gradients are not supported. Use Sharp to rasterize gradients as PNG images first, ' +
550
+ 'then reference with background-image: url(\'gradient.png\')'
551
+ );
552
+ }
553
+
554
+ let background;
555
+ if (bgImage && bgImage !== 'none') {
556
+ // Extract URL from url("...") or url(...)
557
+ const urlMatch = bgImage.match(/url\(["']?([^"')]+)["']?\)/);
558
+ if (urlMatch) {
559
+ background = {
560
+ type: 'image',
561
+ path: resolvePath(urlMatch[1])
562
+ };
563
+ } else {
564
+ background = {
565
+ type: 'color',
566
+ value: rgbToHex(bgColor)
567
+ };
568
+ }
569
+ } else {
570
+ background = {
571
+ type: 'color',
572
+ value: rgbToHex(bgColor)
573
+ };
574
+ }
575
+
576
+ // Process all elements
577
+ const elements = [];
578
+ const placeholders = [];
579
+ const textTags = ['P', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'UL', 'OL', 'LI'];
580
+ const processed = new Set();
581
+
582
+ document.querySelectorAll('*').forEach((el) => {
583
+ if (processed.has(el)) return;
584
+
585
+ // Validate text elements don't have backgrounds, borders, or shadows
586
+ if (textTags.includes(el.tagName)) {
587
+ const computed = window.getComputedStyle(el);
588
+ const hasBg = computed.backgroundColor && computed.backgroundColor !== 'rgba(0, 0, 0, 0)';
589
+ const hasBorder = (computed.borderWidth && parseFloat(computed.borderWidth) > 0) ||
590
+ (computed.borderTopWidth && parseFloat(computed.borderTopWidth) > 0) ||
591
+ (computed.borderRightWidth && parseFloat(computed.borderRightWidth) > 0) ||
592
+ (computed.borderBottomWidth && parseFloat(computed.borderBottomWidth) > 0) ||
593
+ (computed.borderLeftWidth && parseFloat(computed.borderLeftWidth) > 0);
594
+ const hasShadow = computed.boxShadow && computed.boxShadow !== 'none';
595
+
596
+ if (hasBg || hasBorder || hasShadow) {
597
+ errors.push(
598
+ `Text element <${el.tagName.toLowerCase()}> has ${hasBg ? 'background' : hasBorder ? 'border' : 'shadow'}. ` +
599
+ 'Backgrounds, borders, and shadows are only supported on <div> elements, not text elements.'
600
+ );
601
+ return;
602
+ }
603
+ }
604
+
605
+ // Extract placeholder elements (for charts, etc.)
606
+ if (el.className && (typeof el.className === 'string' ? el.className.includes('placeholder') : el.classList.contains('placeholder'))) {
607
+ const rect = el.getBoundingClientRect();
608
+ if (rect.width === 0 || rect.height === 0) {
609
+ errors.push(
610
+ `Placeholder "${el.id || 'unnamed'}" has ${rect.width === 0 ? 'width: 0' : 'height: 0'}. Check the layout CSS.`
611
+ );
612
+ } else {
613
+ placeholders.push({
614
+ id: el.id || `placeholder-${placeholders.length}`,
615
+ x: pxToInch(rect.left),
616
+ y: pxToInch(rect.top),
617
+ w: pxToInch(rect.width),
618
+ h: pxToInch(rect.height)
619
+ });
620
+ }
621
+ processed.add(el);
622
+ return;
623
+ }
624
+
625
+ // Extract images
626
+ if (el.tagName === 'IMG') {
627
+ const rect = el.getBoundingClientRect();
628
+ if (rect.width > 0 && rect.height > 0) {
629
+ const computed = window.getComputedStyle(el);
630
+ const cssOpacity = parseFloat(computed.opacity);
631
+ const transparency = cssOpacity < 1 ? Math.round((1 - cssOpacity) * 100) : null;
632
+
633
+ elements.push({
634
+ type: 'image',
635
+ src: resolvePath(el.src),
636
+ position: {
637
+ x: pxToInch(rect.left),
638
+ y: pxToInch(rect.top),
639
+ w: pxToInch(rect.width),
640
+ h: pxToInch(rect.height)
641
+ },
642
+ transparency: transparency
643
+ });
644
+ processed.add(el);
645
+ return;
646
+ }
647
+ }
648
+
649
+ // Extract DIVs with backgrounds/borders as shapes
650
+ const isContainer = el.tagName === 'DIV' && !textTags.includes(el.tagName);
651
+ if (isContainer) {
652
+ const computed = window.getComputedStyle(el);
653
+ const hasBg = computed.backgroundColor && computed.backgroundColor !== 'rgba(0, 0, 0, 0)';
654
+
655
+ // Validate: Check for unwrapped text content in DIV
656
+ for (const node of el.childNodes) {
657
+ if (node.nodeType === Node.TEXT_NODE) {
658
+ const text = node.textContent.trim();
659
+ if (text) {
660
+ errors.push(
661
+ `DIV element contains unwrapped text "${text.substring(0, 50)}${text.length > 50 ? '...' : ''}". ` +
662
+ 'All text must be wrapped in <p>, <h1>-<h6>, <ul>, or <ol> tags to appear in PowerPoint.'
663
+ );
664
+ }
665
+ }
666
+ }
667
+
668
+ // Check for background images on shapes
669
+ const bgImage = computed.backgroundImage;
670
+ let hasBgImage = false;
671
+ let bgImageUrl = null;
672
+
673
+ if (bgImage && bgImage !== 'none') {
674
+ // Extract URL from url("...") or url(...)
675
+ const urlMatch = bgImage.match(/url\(["']?([^"')]+)["']?\)/);
676
+ if (urlMatch) {
677
+ hasBgImage = true;
678
+ bgImageUrl = urlMatch[1];
679
+
680
+ // Add background image as a separate image element (will be layered behind the shape)
681
+ const rect = el.getBoundingClientRect();
682
+ if (rect.width > 0 && rect.height > 0) {
683
+ const cssOpacity = parseFloat(computed.opacity);
684
+ const transparency = cssOpacity < 1 ? Math.round((1 - cssOpacity) * 100) : null;
685
+
686
+ elements.push({
687
+ type: 'image',
688
+ src: resolvePath(bgImageUrl),
689
+ position: {
690
+ x: pxToInch(rect.left),
691
+ y: pxToInch(rect.top),
692
+ w: pxToInch(rect.width),
693
+ h: pxToInch(rect.height)
694
+ },
695
+ transparency: transparency
696
+ });
697
+ }
698
+ }
699
+ }
700
+
701
+ // Check for borders - both uniform and partial
702
+ const borderTop = computed.borderTopWidth;
703
+ const borderRight = computed.borderRightWidth;
704
+ const borderBottom = computed.borderBottomWidth;
705
+ const borderLeft = computed.borderLeftWidth;
706
+ const borders = [borderTop, borderRight, borderBottom, borderLeft].map(b => parseFloat(b) || 0);
707
+ const hasBorder = borders.some(b => b > 0);
708
+ const hasUniformBorder = hasBorder && borders.every(b => b === borders[0]);
709
+ const borderLines = [];
710
+
711
+ if (hasBorder && !hasUniformBorder) {
712
+ const rect = el.getBoundingClientRect();
713
+ const x = pxToInch(rect.left);
714
+ const y = pxToInch(rect.top);
715
+ const w = pxToInch(rect.width);
716
+ const h = pxToInch(rect.height);
717
+
718
+ // Collect lines to add after shape (inset by half the line width to center on edge)
719
+ if (parseFloat(borderTop) > 0) {
720
+ const widthPt = pxToPoints(borderTop);
721
+ const inset = (widthPt / 72) / 2; // Convert points to inches, then half
722
+ borderLines.push({
723
+ type: 'line',
724
+ x1: x,
725
+ y1: y + inset,
726
+ x2: x + w,
727
+ y2: y + inset,
728
+ width: widthPt,
729
+ color: rgbToHex(computed.borderTopColor)
730
+ });
731
+ }
732
+ if (parseFloat(borderRight) > 0) {
733
+ const widthPt = pxToPoints(borderRight);
734
+ const inset = (widthPt / 72) / 2;
735
+ borderLines.push({
736
+ type: 'line',
737
+ x1: x + w - inset,
738
+ y1: y,
739
+ x2: x + w - inset,
740
+ y2: y + h,
741
+ width: widthPt,
742
+ color: rgbToHex(computed.borderRightColor)
743
+ });
744
+ }
745
+ if (parseFloat(borderBottom) > 0) {
746
+ const widthPt = pxToPoints(borderBottom);
747
+ const inset = (widthPt / 72) / 2;
748
+ borderLines.push({
749
+ type: 'line',
750
+ x1: x,
751
+ y1: y + h - inset,
752
+ x2: x + w,
753
+ y2: y + h - inset,
754
+ width: widthPt,
755
+ color: rgbToHex(computed.borderBottomColor)
756
+ });
757
+ }
758
+ if (parseFloat(borderLeft) > 0) {
759
+ const widthPt = pxToPoints(borderLeft);
760
+ const inset = (widthPt / 72) / 2;
761
+ borderLines.push({
762
+ type: 'line',
763
+ x1: x + inset,
764
+ y1: y,
765
+ x2: x + inset,
766
+ y2: y + h,
767
+ width: widthPt,
768
+ color: rgbToHex(computed.borderLeftColor)
769
+ });
770
+ }
771
+ }
772
+
773
+ if (hasBg || hasBorder || hasBgImage) {
774
+ const rect = el.getBoundingClientRect();
775
+ if (rect.width > 0 && rect.height > 0) {
776
+ const shadow = parseBoxShadow(computed.boxShadow);
777
+
778
+ // Only add shape if there's background color or uniform border
779
+ // (background images are already added as separate image elements above)
780
+ if (hasBg || hasUniformBorder) {
781
+ elements.push({
782
+ type: 'shape',
783
+ text: '', // Shape only - child text elements render on top
784
+ position: {
785
+ x: pxToInch(rect.left),
786
+ y: pxToInch(rect.top),
787
+ w: pxToInch(rect.width),
788
+ h: pxToInch(rect.height)
789
+ },
790
+ shape: {
791
+ fill: hasBg ? rgbToHex(computed.backgroundColor) : null,
792
+ transparency: hasBg ? (() => {
793
+ // Combine alpha from rgba() and CSS opacity property
794
+ const alphaFromRgba = extractAlpha(computed.backgroundColor);
795
+ const cssOpacity = parseFloat(computed.opacity);
796
+
797
+ if (alphaFromRgba !== null && cssOpacity < 1) {
798
+ // Both exist: multiply them (e.g., rgba alpha 0.5 * opacity 0.5 = 0.25 final)
799
+ const finalAlpha = (1 - alphaFromRgba / 100) * cssOpacity;
800
+ return Math.round((1 - finalAlpha) * 100);
801
+ } else if (cssOpacity < 1) {
802
+ // Only CSS opacity exists
803
+ return Math.round((1 - cssOpacity) * 100);
804
+ }
805
+ return alphaFromRgba;
806
+ })() : null,
807
+ line: hasUniformBorder ? {
808
+ color: rgbToHex(computed.borderColor),
809
+ width: pxToPoints(computed.borderWidth)
810
+ } : null,
811
+ // Convert border-radius to rectRadius (in inches)
812
+ // % values: 50%+ = circle (1), <50% = percentage of min dimension
813
+ // pt values: divide by 72 (72pt = 1 inch)
814
+ // px values: divide by 96 (96px = 1 inch)
815
+ rectRadius: (() => {
816
+ const radius = computed.borderRadius;
817
+ const radiusValue = parseFloat(radius);
818
+ if (radiusValue === 0) return 0;
819
+
820
+ if (radius.includes('%')) {
821
+ if (radiusValue >= 50) {
822
+ // For perfect circles (50%+ radius on square shapes),
823
+ // use half the dimension in inches instead of rectRadius: 1
824
+ // This ensures PptxGenJS creates a true circle
825
+ const isSquare = Math.abs(rect.width - rect.height) < 2;
826
+ if (isSquare) {
827
+ return pxToInch(Math.min(rect.width, rect.height) / 2);
828
+ }
829
+ return 1;
830
+ }
831
+ // Calculate percentage of smaller dimension
832
+ const minDim = Math.min(rect.width, rect.height);
833
+ return (radiusValue / 100) * pxToInch(minDim);
834
+ }
835
+
836
+ if (radius.includes('pt')) return radiusValue / 72;
837
+ return radiusValue / PX_PER_IN;
838
+ })(),
839
+ shadow: shadow
840
+ }
841
+ });
842
+ }
843
+
844
+ // Add partial border lines
845
+ elements.push(...borderLines);
846
+
847
+ processed.add(el);
848
+ return;
849
+ }
850
+ }
851
+ }
852
+
853
+ // Extract bullet lists as single text block
854
+ if (el.tagName === 'UL' || el.tagName === 'OL') {
855
+ const rect = el.getBoundingClientRect();
856
+ if (rect.width === 0 || rect.height === 0) return;
857
+
858
+ const liElements = Array.from(el.querySelectorAll('li'));
859
+ const items = [];
860
+ const ulComputed = window.getComputedStyle(el);
861
+ const ulPaddingLeftPt = pxToPoints(ulComputed.paddingLeft);
862
+
863
+ // Split: margin-left for bullet position, indent for text position
864
+ // margin-left + indent = ul padding-left
865
+ const marginLeft = ulPaddingLeftPt * 0.5;
866
+ const textIndent = ulPaddingLeftPt * 0.5;
867
+
868
+ liElements.forEach((li, idx) => {
869
+ const isLast = idx === liElements.length - 1;
870
+ const runs = parseInlineFormatting(li, { breakLine: false });
871
+ // Clean manual bullets from first run
872
+ if (runs.length > 0) {
873
+ runs[0].text = runs[0].text.replace(/^[•\-\*▪▸]\s*/, '');
874
+ runs[0].options.bullet = { indent: textIndent };
875
+ }
876
+ // Set breakLine on last run
877
+ if (runs.length > 0 && !isLast) {
878
+ runs[runs.length - 1].options.breakLine = true;
879
+ }
880
+ items.push(...runs);
881
+ });
882
+
883
+ const computed = window.getComputedStyle(liElements[0] || el);
884
+
885
+ elements.push({
886
+ type: 'list',
887
+ items: items,
888
+ position: {
889
+ x: pxToInch(rect.left),
890
+ y: pxToInch(rect.top),
891
+ w: pxToInch(rect.width),
892
+ h: pxToInch(rect.height)
893
+ },
894
+ style: {
895
+ fontSize: pxToPoints(computed.fontSize),
896
+ fontFace: computed.fontFamily.split(',')[0].replace(/['"]/g, '').trim(),
897
+ color: rgbToHex(computed.color),
898
+ transparency: extractAlpha(computed.color),
899
+ align: computed.textAlign === 'start' ? 'left' : computed.textAlign,
900
+ lineSpacing: computed.lineHeight && computed.lineHeight !== 'normal' ? pxToPoints(computed.lineHeight) : null,
901
+ paraSpaceBefore: 0,
902
+ paraSpaceAfter: pxToPoints(computed.marginBottom),
903
+ // PptxGenJS margin array is [left, right, bottom, top]
904
+ margin: [marginLeft, 0, 0, 0]
905
+ }
906
+ });
907
+
908
+ liElements.forEach(li => processed.add(li));
909
+ processed.add(el);
910
+ return;
911
+ }
912
+
913
+ // Extract text elements (P, H1, H2, etc.)
914
+ if (!textTags.includes(el.tagName)) return;
915
+
916
+ const rect = el.getBoundingClientRect();
917
+ const text = el.textContent.trim();
918
+ if (rect.width === 0 || rect.height === 0 || !text) return;
919
+
920
+ // Validate: Check for manual bullet symbols in text elements (not in lists)
921
+ if (el.tagName !== 'LI' && /^[•\-\*▪▸○●◆◇■□]\s/.test(text.trimStart())) {
922
+ errors.push(
923
+ `Text element <${el.tagName.toLowerCase()}> starts with bullet symbol "${text.substring(0, 20)}...". ` +
924
+ 'Use <ul> or <ol> lists instead of manual bullet symbols.'
925
+ );
926
+ return;
927
+ }
928
+
929
+ const computed = window.getComputedStyle(el);
930
+ const rotation = getRotation(computed.transform, computed.writingMode);
931
+ const { x, y, w, h } = getPositionAndSize(el, rect, rotation);
932
+
933
+ const baseStyle = {
934
+ fontSize: pxToPoints(computed.fontSize),
935
+ fontFace: computed.fontFamily.split(',')[0].replace(/['"]/g, '').trim(),
936
+ color: rgbToHex(computed.color),
937
+ align: computed.textAlign === 'start' ? 'left' : computed.textAlign,
938
+ lineSpacing: pxToPoints(computed.lineHeight),
939
+ paraSpaceBefore: pxToPoints(computed.marginTop),
940
+ paraSpaceAfter: pxToPoints(computed.marginBottom),
941
+ // PptxGenJS margin array is [left, right, bottom, top] (not [top, right, bottom, left] as documented)
942
+ margin: [
943
+ pxToPoints(computed.paddingLeft),
944
+ pxToPoints(computed.paddingRight),
945
+ pxToPoints(computed.paddingBottom),
946
+ pxToPoints(computed.paddingTop)
947
+ ]
948
+ };
949
+
950
+ const transparency = extractAlpha(computed.color);
951
+ if (transparency !== null) baseStyle.transparency = transparency;
952
+
953
+ if (rotation !== null) baseStyle.rotate = rotation;
954
+
955
+ const hasFormatting = el.querySelector('b, i, u, strong, em, span, br');
956
+
957
+ if (hasFormatting) {
958
+ // Text with inline formatting
959
+ const transformStr = computed.textTransform;
960
+ const runs = parseInlineFormatting(el, {}, [], (str) => applyTextTransform(str, transformStr));
961
+
962
+ // Adjust lineSpacing based on largest fontSize in runs
963
+ const adjustedStyle = {...baseStyle };
964
+ if (adjustedStyle.lineSpacing) {
965
+ const maxFontSize = Math.max(
966
+ adjustedStyle.fontSize,
967
+ ...runs.map(r => r.options?.fontSize || 0)
968
+ );
969
+ if (maxFontSize > adjustedStyle.fontSize) {
970
+ const lineHeightMultiplier = adjustedStyle.lineSpacing / adjustedStyle.fontSize;
971
+ adjustedStyle.lineSpacing = maxFontSize * lineHeightMultiplier;
972
+ }
973
+ }
974
+
975
+ elements.push({
976
+ type: el.tagName.toLowerCase(),
977
+ text: runs,
978
+ position: { x: pxToInch(x), y: pxToInch(y), w: pxToInch(w), h: pxToInch(h) },
979
+ style: adjustedStyle
980
+ });
981
+ } else {
982
+ // Plain text - inherit CSS formatting
983
+ const textTransform = computed.textTransform;
984
+ const transformedText = applyTextTransform(text, textTransform);
985
+
986
+ const isBold = computed.fontWeight === 'bold' || parseInt(computed.fontWeight) >= 600;
987
+
988
+ elements.push({
989
+ type: el.tagName.toLowerCase(),
990
+ text: transformedText,
991
+ position: { x: pxToInch(x), y: pxToInch(y), w: pxToInch(w), h: pxToInch(h) },
992
+ style: {
993
+ ...baseStyle,
994
+ bold: isBold && !shouldSkipBold(computed.fontFamily),
995
+ italic: computed.fontStyle === 'italic',
996
+ underline: computed.textDecoration.includes('underline')
997
+ }
998
+ });
999
+ }
1000
+
1001
+ processed.add(el);
1002
+ });
1003
+
1004
+ return { background, elements, placeholders, errors };
1005
+ }, htmlDir);
1006
+ }
1007
+
1008
+ async function html2pptx(htmlFile, pres, options = {}) {
1009
+ const {
1010
+ tmpDir = process.env.TMPDIR || '/tmp',
1011
+ slide = null
1012
+ } = options;
1013
+
1014
+ try {
1015
+ // Use Chrome on macOS, default Chromium on Unix
1016
+ const launchOptions = { env: { TMPDIR: tmpDir } };
1017
+ if (process.platform === 'darwin') {
1018
+ launchOptions.channel = 'chrome';
1019
+ }
1020
+
1021
+ const browser = await chromium.launch(launchOptions);
1022
+
1023
+ let bodyDimensions;
1024
+ let slideData;
1025
+
1026
+ const filePath = path.isAbsolute(htmlFile) ? htmlFile : path.join(process.cwd(), htmlFile);
1027
+ const htmlDir = path.dirname(filePath);
1028
+ const validationErrors = [];
1029
+
1030
+ try {
1031
+ const page = await browser.newPage();
1032
+ page.on('console', (msg) => {
1033
+ // Log the message text to your test runner's console
1034
+ console.log(`Browser console: ${msg.text()}`);
1035
+ });
1036
+
1037
+ await page.goto(`file://${filePath}`);
1038
+
1039
+ bodyDimensions = await getBodyDimensions(page);
1040
+
1041
+ await page.setViewportSize({
1042
+ width: Math.round(bodyDimensions.width),
1043
+ height: Math.round(bodyDimensions.height)
1044
+ });
1045
+
1046
+ slideData = await extractSlideData(page, htmlDir);
1047
+ } finally {
1048
+ await browser.close();
1049
+ }
1050
+
1051
+ // Collect all validation errors
1052
+ if (bodyDimensions.errors && bodyDimensions.errors.length > 0) {
1053
+ validationErrors.push(...bodyDimensions.errors);
1054
+ }
1055
+
1056
+ const dimensionErrors = validateDimensions(bodyDimensions, pres);
1057
+ if (dimensionErrors.length > 0) {
1058
+ validationErrors.push(...dimensionErrors);
1059
+ }
1060
+
1061
+ const textBoxPositionErrors = validateTextBoxPosition(slideData, bodyDimensions);
1062
+ if (textBoxPositionErrors.length > 0) {
1063
+ validationErrors.push(...textBoxPositionErrors);
1064
+ }
1065
+
1066
+ if (slideData.errors && slideData.errors.length > 0) {
1067
+ validationErrors.push(...slideData.errors);
1068
+ }
1069
+
1070
+ // Throw all errors at once if any exist
1071
+ if (validationErrors.length > 0) {
1072
+ const errorMessage = validationErrors.length === 1 ?
1073
+ validationErrors[0] :
1074
+ `Multiple validation errors found:\n${validationErrors.map((e, i) => ` ${i + 1}. ${e}`).join('\n')}`;
1075
+ throw new Error(errorMessage);
1076
+ }
1077
+
1078
+ const targetSlide = slide || pres.addSlide();
1079
+
1080
+ await addBackground(slideData, targetSlide, tmpDir);
1081
+ addElements(slideData, targetSlide, pres);
1082
+
1083
+ return { slide: targetSlide, placeholders: slideData.placeholders };
1084
+ } catch (error) {
1085
+ if (!error.message.startsWith(htmlFile)) {
1086
+ throw new Error(`${htmlFile}: ${error.message}`);
1087
+ }
1088
+ throw error;
1089
+ }
1090
+ }
1091
+
1092
+ module.exports = html2pptx;