opensentinel 2.1.1 → 3.1.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 (268) hide show
  1. package/README.md +354 -283
  2. package/dist/archiver-AVNBYCKQ.js +15340 -0
  3. package/dist/archiver-AVNBYCKQ.js.map +1 -0
  4. package/dist/audit-logger-OBPR7CRO.js +22 -0
  5. package/dist/auth-UOX5K2BE.js +18 -0
  6. package/dist/autonomy-ZXDBDQUJ.js +86 -0
  7. package/dist/autonomy-ZXDBDQUJ.js.map +1 -0
  8. package/dist/aws-s3-Q4LLZZPD.js +146 -0
  9. package/dist/aws-s3-Q4LLZZPD.js.map +1 -0
  10. package/dist/backup-restore-PZ7CYYB7.js +16 -0
  11. package/dist/blocks-R3PODY47.js +23 -0
  12. package/dist/bot-QRARP4UN.js +36 -0
  13. package/dist/brain-7XLLM3KC.js +56 -0
  14. package/dist/camera-monitor-M5CYKUU4.js +335 -0
  15. package/dist/camera-monitor-M5CYKUU4.js.map +1 -0
  16. package/dist/{charts-MMXM6BWW.js → charts-V7ARZNKF.js} +2 -2
  17. package/dist/chunk-22VGGA7S.js +330 -0
  18. package/dist/chunk-22VGGA7S.js.map +1 -0
  19. package/dist/chunk-35WYTA3C.js +382 -0
  20. package/dist/chunk-35WYTA3C.js.map +1 -0
  21. package/dist/chunk-3E2PSU2C.js +146 -0
  22. package/dist/chunk-3E2PSU2C.js.map +1 -0
  23. package/dist/{chunk-L3F43VPB.js → chunk-4GLYY4NN.js} +2 -2
  24. package/dist/{chunk-L3F43VPB.js.map → chunk-4GLYY4NN.js.map} +1 -1
  25. package/dist/{chunk-L3PDU3XN.js → chunk-4UOE5TUZ.js} +4 -4
  26. package/dist/{chunk-6SNHU3CY.js → chunk-66OJ3WB4.js} +2 -2
  27. package/dist/chunk-6KONMXQ6.js +297 -0
  28. package/dist/chunk-6KONMXQ6.js.map +1 -0
  29. package/dist/chunk-6PMVAAA7.js +196 -0
  30. package/dist/chunk-6PMVAAA7.js.map +1 -0
  31. package/dist/chunk-766ASQWE.js +32620 -0
  32. package/dist/chunk-766ASQWE.js.map +1 -0
  33. package/dist/chunk-7WQO5J2M.js +29 -0
  34. package/dist/chunk-7WQO5J2M.js.map +1 -0
  35. package/dist/chunk-APHSRMBS.js +148 -0
  36. package/dist/chunk-APHSRMBS.js.map +1 -0
  37. package/dist/{chunk-4LVWXUNC.js → chunk-AYUKPTSM.js} +57 -39
  38. package/dist/chunk-AYUKPTSM.js.map +1 -0
  39. package/dist/chunk-BIPYADGB.js +84 -0
  40. package/dist/chunk-BIPYADGB.js.map +1 -0
  41. package/dist/chunk-BRBWNV65.js +457 -0
  42. package/dist/chunk-BRBWNV65.js.map +1 -0
  43. package/dist/chunk-BXZ6EA52.js +382 -0
  44. package/dist/chunk-BXZ6EA52.js.map +1 -0
  45. package/dist/chunk-EVE7MIIY.js +290 -0
  46. package/dist/chunk-EVE7MIIY.js.map +1 -0
  47. package/dist/chunk-F3TTNID2.js +138 -0
  48. package/dist/chunk-F3TTNID2.js.map +1 -0
  49. package/dist/chunk-H5RQOFO2.js +190 -0
  50. package/dist/chunk-H5RQOFO2.js.map +1 -0
  51. package/dist/chunk-HN3F4WSW.js +145 -0
  52. package/dist/chunk-HN3F4WSW.js.map +1 -0
  53. package/dist/{chunk-6DRDKB45.js → chunk-I6BDYQIG.js} +20 -9
  54. package/dist/chunk-I6BDYQIG.js.map +1 -0
  55. package/dist/chunk-IZJMVV7O.js +347 -0
  56. package/dist/chunk-IZJMVV7O.js.map +1 -0
  57. package/dist/chunk-KM22GV7G.js +211 -0
  58. package/dist/chunk-KM22GV7G.js.map +1 -0
  59. package/dist/chunk-MGFBLVR7.js +103 -0
  60. package/dist/chunk-MGFBLVR7.js.map +1 -0
  61. package/dist/chunk-MQJ2ECQT.js +228 -0
  62. package/dist/chunk-MQJ2ECQT.js.map +1 -0
  63. package/dist/{chunk-F6QUZQGI.js → chunk-MXAPLSJ5.js} +2 -2
  64. package/dist/{chunk-GK3E2I7A.js → chunk-NHMBTUMW.js} +2 -2
  65. package/dist/chunk-NPRTSZIF.js +131 -0
  66. package/dist/chunk-NPRTSZIF.js.map +1 -0
  67. package/dist/chunk-O7IH7JTI.js +1898 -0
  68. package/dist/chunk-O7IH7JTI.js.map +1 -0
  69. package/dist/chunk-OCVQGBJK.js +293 -0
  70. package/dist/chunk-OCVQGBJK.js.map +1 -0
  71. package/dist/chunk-P6QINGFL.js +332 -0
  72. package/dist/chunk-P6QINGFL.js.map +1 -0
  73. package/dist/chunk-PHDZKPNE.js +91 -0
  74. package/dist/chunk-PHDZKPNE.js.map +1 -0
  75. package/dist/chunk-PLDDJCW6.js +49 -0
  76. package/dist/chunk-PTGTGXV2.js +164 -0
  77. package/dist/chunk-PTGTGXV2.js.map +1 -0
  78. package/dist/chunk-REMIY4U2.js +171 -0
  79. package/dist/chunk-REMIY4U2.js.map +1 -0
  80. package/dist/chunk-RZ4YESBG.js +141 -0
  81. package/dist/chunk-RZ4YESBG.js.map +1 -0
  82. package/dist/chunk-SAX5MHK4.js +111 -0
  83. package/dist/chunk-SAX5MHK4.js.map +1 -0
  84. package/dist/{chunk-GVJVEWHI.js → chunk-SJSUSJ47.js} +2 -2
  85. package/dist/chunk-SPPMCAKG.js +777 -0
  86. package/dist/chunk-SPPMCAKG.js.map +1 -0
  87. package/dist/chunk-SVAPX2XN.js +2441 -0
  88. package/dist/chunk-SVAPX2XN.js.map +1 -0
  89. package/dist/chunk-TVEWKIK3.js +452 -0
  90. package/dist/chunk-TVEWKIK3.js.map +1 -0
  91. package/dist/{chunk-HH2HBTQM.js → chunk-TYAGMJNV.js} +5 -5
  92. package/dist/{chunk-JXUP2X7V.js → chunk-VEHFVBLI.js} +2 -2
  93. package/dist/chunk-VNX5GMTN.js +128 -0
  94. package/dist/chunk-VNX5GMTN.js.map +1 -0
  95. package/dist/chunk-VRD5CYRL.js +1568 -0
  96. package/dist/chunk-VRD5CYRL.js.map +1 -0
  97. package/dist/chunk-WLUHNG6X.js +122 -0
  98. package/dist/chunk-WLUHNG6X.js.map +1 -0
  99. package/dist/chunk-WRAKK6K6.js +265 -0
  100. package/dist/chunk-WRAKK6K6.js.map +1 -0
  101. package/dist/chunk-XKYRH4FM.js +681 -0
  102. package/dist/chunk-XKYRH4FM.js.map +1 -0
  103. package/dist/{chunk-GUBEEYDW.js → chunk-XMCVRVTF.js} +2 -2
  104. package/dist/{chunk-GUBEEYDW.js.map → chunk-XMCVRVTF.js.map} +1 -1
  105. package/dist/chunk-ZLZKF2PM.js +310 -0
  106. package/dist/chunk-ZLZKF2PM.js.map +1 -0
  107. package/dist/cli.js +5 -1
  108. package/dist/cli.js.map +1 -1
  109. package/dist/client-ZQSFPMOB.js +21 -0
  110. package/dist/clipboard-manager-TEO2GEDN.js +24 -0
  111. package/dist/commands/setup.js +3 -3
  112. package/dist/commands/setup.js.map +1 -1
  113. package/dist/commands/start.js +3 -3
  114. package/dist/commands/status.js +2 -2
  115. package/dist/commands/stop.js +2 -2
  116. package/dist/commands/utils.js +2 -2
  117. package/dist/cron-explain-HHQKPD3M.js +16 -0
  118. package/dist/crypto-4AP47IKC.js +14 -0
  119. package/dist/crypto-4AP47IKC.js.map +1 -0
  120. package/dist/databases-37X4CI2Y.js +21 -0
  121. package/dist/databases-37X4CI2Y.js.map +1 -0
  122. package/dist/discord-B3HUPGQ6.js +70 -0
  123. package/dist/discord-B3HUPGQ6.js.map +1 -0
  124. package/dist/dist-UISMLMFN.js +21847 -0
  125. package/dist/dist-UISMLMFN.js.map +1 -0
  126. package/dist/email-K7LO2IPB.js +268 -0
  127. package/dist/email-K7LO2IPB.js.map +1 -0
  128. package/dist/enhanced-retrieval-DNLLEM4Z.js +753 -0
  129. package/dist/enhanced-retrieval-DNLLEM4Z.js.map +1 -0
  130. package/dist/enrichment-pipeline-MNHNW65K.js +13 -0
  131. package/dist/enrichment-pipeline-MNHNW65K.js.map +1 -0
  132. package/dist/entity-resolution-Y3IUWEAT.js +24 -0
  133. package/dist/entity-resolution-Y3IUWEAT.js.map +1 -0
  134. package/dist/env-IWXUVTCB.js +12 -0
  135. package/dist/env-IWXUVTCB.js.map +1 -0
  136. package/dist/google-workspace-DKWUVNGC.js +169 -0
  137. package/dist/google-workspace-DKWUVNGC.js.map +1 -0
  138. package/dist/hash-tool-ULQYD7B5.js +22 -0
  139. package/dist/hash-tool-ULQYD7B5.js.map +1 -0
  140. package/dist/heartbeat-monitor-GCISLXI3.js +22 -0
  141. package/dist/heartbeat-monitor-GCISLXI3.js.map +1 -0
  142. package/dist/image-generation-OSU7FP6F.js +486 -0
  143. package/dist/image-generation-OSU7FP6F.js.map +1 -0
  144. package/dist/imessage-NGA2XF2V.js +35 -0
  145. package/dist/imessage-NGA2XF2V.js.map +1 -0
  146. package/dist/inbox-summarizer-NRI4S7IF.js +47 -0
  147. package/dist/inbox-summarizer-NRI4S7IF.js.map +1 -0
  148. package/dist/incident-response-C5J7Q6DT.js +244 -0
  149. package/dist/incident-response-C5J7Q6DT.js.map +1 -0
  150. package/dist/inventory-manager-352OHXWD.js +24 -0
  151. package/dist/inventory-manager-352OHXWD.js.map +1 -0
  152. package/dist/jira-GSGDBMIG.js +199 -0
  153. package/dist/jira-GSGDBMIG.js.map +1 -0
  154. package/dist/json-tool-QE2SYHEG.js +26 -0
  155. package/dist/json-tool-QE2SYHEG.js.map +1 -0
  156. package/dist/key-rotation-DPHU4ZTB.js +18 -0
  157. package/dist/key-rotation-DPHU4ZTB.js.map +1 -0
  158. package/dist/lib.d.ts +603 -11
  159. package/dist/lib.js +161 -35
  160. package/dist/lib.js.map +1 -1
  161. package/dist/mailchimp-KKNF6QJ7.js +152 -0
  162. package/dist/mailchimp-KKNF6QJ7.js.map +1 -0
  163. package/dist/matrix-QVHG76I7.js +279 -0
  164. package/dist/matrix-QVHG76I7.js.map +1 -0
  165. package/dist/{mcp-LS7Q3Z5W.js → mcp-3JI6W7ZE.js} +3 -3
  166. package/dist/mcp-3JI6W7ZE.js.map +1 -0
  167. package/dist/microsoft365-UCBKJHNX.js +164 -0
  168. package/dist/microsoft365-UCBKJHNX.js.map +1 -0
  169. package/dist/ocr-AC7NPX33.js +22 -0
  170. package/dist/ocr-AC7NPX33.js.map +1 -0
  171. package/dist/ollama-BOAMSPLJ.js +8 -0
  172. package/dist/ollama-BOAMSPLJ.js.map +1 -0
  173. package/dist/pages-MI523RB7.js +26 -0
  174. package/dist/pages-MI523RB7.js.map +1 -0
  175. package/dist/pair-JDFTERIK.js +24 -0
  176. package/dist/pair-JDFTERIK.js.map +1 -0
  177. package/dist/pairing-IFQYCPNS.js +10 -0
  178. package/dist/pairing-IFQYCPNS.js.map +1 -0
  179. package/dist/pdf-ALQVOEJR.js +17 -0
  180. package/dist/pdf-ALQVOEJR.js.map +1 -0
  181. package/dist/presentations-DSV5IHG5.js +1002 -0
  182. package/dist/presentations-DSV5IHG5.js.map +1 -0
  183. package/dist/prometheus-JNT2BD4L.js +10 -0
  184. package/dist/prometheus-JNT2BD4L.js.map +1 -0
  185. package/dist/providers-J4LYPHDR.js +19 -0
  186. package/dist/providers-J4LYPHDR.js.map +1 -0
  187. package/dist/qr-code-WIX4PB4U.js +16 -0
  188. package/dist/qr-code-WIX4PB4U.js.map +1 -0
  189. package/dist/quickbooks-XB4NII2S.js +190 -0
  190. package/dist/quickbooks-XB4NII2S.js.map +1 -0
  191. package/dist/regex-tool-W4ABRKGK.js +24 -0
  192. package/dist/regex-tool-W4ABRKGK.js.map +1 -0
  193. package/dist/scheduler-VK4WFERV.js +63 -0
  194. package/dist/scheduler-VK4WFERV.js.map +1 -0
  195. package/dist/search-BCLBO5E3.js +25 -0
  196. package/dist/search-BCLBO5E3.js.map +1 -0
  197. package/dist/sendgrid-RNXCAFKM.js +152 -0
  198. package/dist/sendgrid-RNXCAFKM.js.map +1 -0
  199. package/dist/shopify-NCXYJB4R.js +171 -0
  200. package/dist/shopify-NCXYJB4R.js.map +1 -0
  201. package/dist/signal-6CGDFYL2.js +35 -0
  202. package/dist/signal-6CGDFYL2.js.map +1 -0
  203. package/dist/slack-IZQWIKOH.js +75 -0
  204. package/dist/slack-IZQWIKOH.js.map +1 -0
  205. package/dist/sms-M3JIOTCW.js +23 -0
  206. package/dist/sms-M3JIOTCW.js.map +1 -0
  207. package/dist/{src-K7GASHRH.js → src-VYUE6LRA.js} +138 -32
  208. package/dist/src-VYUE6LRA.js.map +1 -0
  209. package/dist/stocks-XXWBPOCU.js +14 -0
  210. package/dist/stocks-XXWBPOCU.js.map +1 -0
  211. package/dist/text-transform-6SGUA5Z4.js +22 -0
  212. package/dist/text-transform-6SGUA5Z4.js.map +1 -0
  213. package/dist/tools-2RLEI2N6.js +38 -0
  214. package/dist/tools-2RLEI2N6.js.map +1 -0
  215. package/dist/tunnel-IWMXUML4.js +301 -0
  216. package/dist/tunnel-IWMXUML4.js.map +1 -0
  217. package/dist/twilio-53GEW5JT.js +139 -0
  218. package/dist/twilio-53GEW5JT.js.map +1 -0
  219. package/dist/unit-converter-ZYXMEZOE.js +14 -0
  220. package/dist/unit-converter-ZYXMEZOE.js.map +1 -0
  221. package/dist/whatsapp-LFX6YKCM.js +35 -0
  222. package/dist/whatsapp-LFX6YKCM.js.map +1 -0
  223. package/dist/word-document-7B6SJMAY.js +902 -0
  224. package/dist/word-document-7B6SJMAY.js.map +1 -0
  225. package/dist/xero-QYO66D45.js +162 -0
  226. package/dist/xero-QYO66D45.js.map +1 -0
  227. package/dist/zapier-webhook-TBZ5YF2A.js +106 -0
  228. package/dist/zapier-webhook-TBZ5YF2A.js.map +1 -0
  229. package/drizzle/0002_mushy_master_mold.sql +140 -0
  230. package/drizzle/meta/0002_snapshot.json +3637 -0
  231. package/drizzle/meta/_journal.json +7 -0
  232. package/package.json +100 -98
  233. package/dist/bot-KJ26BG56.js +0 -15
  234. package/dist/chunk-4LVWXUNC.js.map +0 -1
  235. package/dist/chunk-4TG2IG5K.js +0 -5249
  236. package/dist/chunk-4TG2IG5K.js.map +0 -1
  237. package/dist/chunk-6DRDKB45.js.map +0 -1
  238. package/dist/chunk-CI6Q63MM.js +0 -1613
  239. package/dist/chunk-CI6Q63MM.js.map +0 -1
  240. package/dist/chunk-KHNYJY2Z.js +0 -178
  241. package/dist/chunk-KHNYJY2Z.js.map +0 -1
  242. package/dist/chunk-NSBPE2FW.js +0 -17
  243. package/dist/discord-ZOJFTVTB.js +0 -49
  244. package/dist/imessage-JFRB6EJ7.js +0 -14
  245. package/dist/scheduler-EZ7CZMCS.js +0 -42
  246. package/dist/signal-T3MCSULM.js +0 -14
  247. package/dist/slack-N2M4FHAJ.js +0 -54
  248. package/dist/src-K7GASHRH.js.map +0 -1
  249. package/dist/tools-24GZHYRF.js +0 -16
  250. package/dist/whatsapp-VCRUPAO5.js +0 -14
  251. /package/dist/{bot-KJ26BG56.js.map → audit-logger-OBPR7CRO.js.map} +0 -0
  252. /package/dist/{chunk-NSBPE2FW.js.map → auth-UOX5K2BE.js.map} +0 -0
  253. /package/dist/{discord-ZOJFTVTB.js.map → backup-restore-PZ7CYYB7.js.map} +0 -0
  254. /package/dist/{imessage-JFRB6EJ7.js.map → blocks-R3PODY47.js.map} +0 -0
  255. /package/dist/{mcp-LS7Q3Z5W.js.map → bot-QRARP4UN.js.map} +0 -0
  256. /package/dist/{scheduler-EZ7CZMCS.js.map → brain-7XLLM3KC.js.map} +0 -0
  257. /package/dist/{charts-MMXM6BWW.js.map → charts-V7ARZNKF.js.map} +0 -0
  258. /package/dist/{chunk-L3PDU3XN.js.map → chunk-4UOE5TUZ.js.map} +0 -0
  259. /package/dist/{chunk-6SNHU3CY.js.map → chunk-66OJ3WB4.js.map} +0 -0
  260. /package/dist/{chunk-F6QUZQGI.js.map → chunk-MXAPLSJ5.js.map} +0 -0
  261. /package/dist/{chunk-GK3E2I7A.js.map → chunk-NHMBTUMW.js.map} +0 -0
  262. /package/dist/{signal-T3MCSULM.js.map → chunk-PLDDJCW6.js.map} +0 -0
  263. /package/dist/{chunk-GVJVEWHI.js.map → chunk-SJSUSJ47.js.map} +0 -0
  264. /package/dist/{chunk-HH2HBTQM.js.map → chunk-TYAGMJNV.js.map} +0 -0
  265. /package/dist/{chunk-JXUP2X7V.js.map → chunk-VEHFVBLI.js.map} +0 -0
  266. /package/dist/{slack-N2M4FHAJ.js.map → client-ZQSFPMOB.js.map} +0 -0
  267. /package/dist/{tools-24GZHYRF.js.map → clipboard-manager-TEO2GEDN.js.map} +0 -0
  268. /package/dist/{whatsapp-VCRUPAO5.js.map → cron-explain-HHQKPD3M.js.map} +0 -0
@@ -0,0 +1,902 @@
1
+ import {
2
+ isPathAllowed
3
+ } from "./chunk-CQ4JURG7.js";
4
+ import "./chunk-PLDDJCW6.js";
5
+
6
+ // src/tools/file-generation/word-document.ts
7
+ import { join } from "path";
8
+ import { tmpdir } from "os";
9
+ import { randomBytes } from "crypto";
10
+ import { writeFile, mkdir } from "fs/promises";
11
+ import { dirname } from "path";
12
+ var DEFAULT_OPTIONS = {
13
+ orientation: "portrait",
14
+ margins: { top: 1440, right: 1440, bottom: 1440, left: 1440 }
15
+ // 1 inch in twips
16
+ };
17
+ function getTempPath() {
18
+ const id = randomBytes(8).toString("hex");
19
+ return join(tmpdir(), `sentinel-doc-${id}.docx`);
20
+ }
21
+ function escapeXml(str) {
22
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
23
+ }
24
+ function generateDocumentXml(elements, options) {
25
+ const orientation = options.orientation || "portrait";
26
+ const margins = options.margins || DEFAULT_OPTIONS.margins;
27
+ let bodyContent = "";
28
+ for (const element of elements) {
29
+ bodyContent += generateElementXml(element);
30
+ }
31
+ const sectionProps = `
32
+ <w:sectPr>
33
+ <w:pgSz w:w="${orientation === "portrait" ? "12240" : "15840"}" w:h="${orientation === "portrait" ? "15840" : "12240"}" ${orientation === "landscape" ? 'w:orient="landscape"' : ""}/>
34
+ <w:pgMar w:top="${margins.top}" w:right="${margins.right}" w:bottom="${margins.bottom}" w:left="${margins.left}" w:header="720" w:footer="720" w:gutter="0"/>
35
+ </w:sectPr>
36
+ `;
37
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
38
+ <w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
39
+ xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
40
+ xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
41
+ xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
42
+ xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
43
+ <w:body>
44
+ ${bodyContent}
45
+ ${sectionProps}
46
+ </w:body>
47
+ </w:document>`;
48
+ }
49
+ function generateElementXml(element) {
50
+ switch (element.type) {
51
+ case "paragraph":
52
+ return generateParagraphXml(element);
53
+ case "heading":
54
+ return generateHeadingXml(element);
55
+ case "bullet-list":
56
+ return generateBulletListXml(element);
57
+ case "numbered-list":
58
+ return generateNumberedListXml(element);
59
+ case "table":
60
+ return generateTableXml(element);
61
+ case "page-break":
62
+ return generatePageBreakXml();
63
+ case "horizontal-rule":
64
+ return generateHorizontalRuleXml();
65
+ case "toc":
66
+ return generateTocXml(element);
67
+ case "image":
68
+ return generateImagePlaceholderXml(element);
69
+ default:
70
+ return "";
71
+ }
72
+ }
73
+ function generateParagraphXml(paragraph) {
74
+ const alignment = getAlignmentValue(paragraph.alignment);
75
+ const spacing = paragraph.spacing;
76
+ const indent = paragraph.indent;
77
+ let pPr = "<w:pPr>";
78
+ if (alignment) {
79
+ pPr += `<w:jc w:val="${alignment}"/>`;
80
+ }
81
+ if (spacing) {
82
+ pPr += `<w:spacing ${spacing.before ? `w:before="${spacing.before}"` : ""} ${spacing.after ? `w:after="${spacing.after}"` : ""} ${spacing.line ? `w:line="${spacing.line}"` : ""}/>`;
83
+ }
84
+ if (indent) {
85
+ pPr += `<w:ind ${indent.left ? `w:left="${indent.left}"` : ""} ${indent.right ? `w:right="${indent.right}"` : ""} ${indent.firstLine ? `w:firstLine="${indent.firstLine}"` : ""}/>`;
86
+ }
87
+ pPr += "</w:pPr>";
88
+ let runs = "";
89
+ if (typeof paragraph.content === "string") {
90
+ runs = `<w:r><w:t xml:space="preserve">${escapeXml(paragraph.content)}</w:t></w:r>`;
91
+ } else {
92
+ for (const run of paragraph.content) {
93
+ runs += generateTextRunXml(run);
94
+ }
95
+ }
96
+ return `<w:p>${pPr}${runs}</w:p>`;
97
+ }
98
+ function generateTextRunXml(run) {
99
+ let rPr = "<w:rPr>";
100
+ if (run.bold) rPr += "<w:b/>";
101
+ if (run.italic) rPr += "<w:i/>";
102
+ if (run.underline) rPr += '<w:u w:val="single"/>';
103
+ if (run.strike) rPr += "<w:strike/>";
104
+ if (run.color) rPr += `<w:color w:val="${run.color.replace("#", "")}"/>`;
105
+ if (run.size) rPr += `<w:sz w:val="${run.size * 2}"/>`;
106
+ if (run.font) rPr += `<w:rFonts w:ascii="${run.font}" w:hAnsi="${run.font}"/>`;
107
+ if (run.highlight) rPr += `<w:highlight w:val="${run.highlight}"/>`;
108
+ rPr += "</w:rPr>";
109
+ return `<w:r>${rPr}<w:t xml:space="preserve">${escapeXml(run.text)}</w:t></w:r>`;
110
+ }
111
+ function generateHeadingXml(heading) {
112
+ const styleId = `Heading${heading.level}`;
113
+ const alignment = getAlignmentValue(heading.alignment);
114
+ let pPr = `<w:pPr><w:pStyle w:val="${styleId}"/>`;
115
+ if (alignment) {
116
+ pPr += `<w:jc w:val="${alignment}"/>`;
117
+ }
118
+ pPr += "</w:pPr>";
119
+ return `<w:p>${pPr}<w:r><w:t>${escapeXml(heading.text)}</w:t></w:r></w:p>`;
120
+ }
121
+ function generateBulletListXml(list) {
122
+ const level = list.level || 0;
123
+ let xml = "";
124
+ for (const item of list.items) {
125
+ xml += `<w:p>
126
+ <w:pPr>
127
+ <w:pStyle w:val="ListParagraph"/>
128
+ <w:numPr>
129
+ <w:ilvl w:val="${level}"/>
130
+ <w:numId w:val="1"/>
131
+ </w:numPr>
132
+ </w:pPr>
133
+ <w:r><w:t>${escapeXml(item)}</w:t></w:r>
134
+ </w:p>`;
135
+ }
136
+ return xml;
137
+ }
138
+ function generateNumberedListXml(list) {
139
+ let xml = "";
140
+ for (const item of list.items) {
141
+ xml += `<w:p>
142
+ <w:pPr>
143
+ <w:pStyle w:val="ListParagraph"/>
144
+ <w:numPr>
145
+ <w:ilvl w:val="0"/>
146
+ <w:numId w:val="2"/>
147
+ </w:numPr>
148
+ </w:pPr>
149
+ <w:r><w:t>${escapeXml(item)}</w:t></w:r>
150
+ </w:p>`;
151
+ }
152
+ return xml;
153
+ }
154
+ function generateTableXml(table) {
155
+ const columnCount = table.headers?.length || table.rows[0]?.length || 1;
156
+ const defaultWidth = Math.floor(9e3 / columnCount);
157
+ let xml = `<w:tbl>
158
+ <w:tblPr>
159
+ <w:tblStyle w:val="TableGrid"/>
160
+ <w:tblW w:w="0" w:type="auto"/>
161
+ <w:tblBorders>
162
+ <w:top w:val="single" w:sz="4" w:space="0" w:color="auto"/>
163
+ <w:left w:val="single" w:sz="4" w:space="0" w:color="auto"/>
164
+ <w:bottom w:val="single" w:sz="4" w:space="0" w:color="auto"/>
165
+ <w:right w:val="single" w:sz="4" w:space="0" w:color="auto"/>
166
+ <w:insideH w:val="single" w:sz="4" w:space="0" w:color="auto"/>
167
+ <w:insideV w:val="single" w:sz="4" w:space="0" w:color="auto"/>
168
+ </w:tblBorders>
169
+ </w:tblPr>
170
+ <w:tblGrid>`;
171
+ for (let i = 0; i < columnCount; i++) {
172
+ const width = table.widths?.[i] || defaultWidth;
173
+ xml += `<w:gridCol w:w="${width}"/>`;
174
+ }
175
+ xml += "</w:tblGrid>";
176
+ if (table.headers) {
177
+ xml += "<w:tr>";
178
+ for (const cell of table.headers) {
179
+ xml += generateTableCellXml(cell, true);
180
+ }
181
+ xml += "</w:tr>";
182
+ }
183
+ for (const row of table.rows) {
184
+ xml += "<w:tr>";
185
+ for (const cell of row) {
186
+ xml += generateTableCellXml(cell, false);
187
+ }
188
+ xml += "</w:tr>";
189
+ }
190
+ xml += "</w:tbl>";
191
+ return xml;
192
+ }
193
+ function generateTableCellXml(cell, isHeader) {
194
+ const cellData = typeof cell === "string" ? { content: cell } : cell;
195
+ let tcPr = "<w:tcPr>";
196
+ if (cellData.backgroundColor) {
197
+ tcPr += `<w:shd w:val="clear" w:color="auto" w:fill="${cellData.backgroundColor.replace("#", "")}"/>`;
198
+ }
199
+ if (cellData.colSpan && cellData.colSpan > 1) {
200
+ tcPr += `<w:gridSpan w:val="${cellData.colSpan}"/>`;
201
+ }
202
+ tcPr += "</w:tcPr>";
203
+ const bold = isHeader || cellData.bold;
204
+ const alignment = getAlignmentValue(cellData.alignment || (isHeader ? "center" : "left"));
205
+ return `<w:tc>
206
+ ${tcPr}
207
+ <w:p>
208
+ <w:pPr>${alignment ? `<w:jc w:val="${alignment}"/>` : ""}</w:pPr>
209
+ <w:r>
210
+ ${bold ? "<w:rPr><w:b/></w:rPr>" : ""}
211
+ <w:t>${escapeXml(cellData.content)}</w:t>
212
+ </w:r>
213
+ </w:p>
214
+ </w:tc>`;
215
+ }
216
+ function generatePageBreakXml() {
217
+ return '<w:p><w:r><w:br w:type="page"/></w:r></w:p>';
218
+ }
219
+ function generateHorizontalRuleXml() {
220
+ return `<w:p>
221
+ <w:pPr>
222
+ <w:pBdr>
223
+ <w:bottom w:val="single" w:sz="12" w:space="1" w:color="auto"/>
224
+ </w:pBdr>
225
+ </w:pPr>
226
+ </w:p>`;
227
+ }
228
+ function generateTocXml(toc) {
229
+ const title = toc.title || "Table of Contents";
230
+ return `<w:p>
231
+ <w:pPr><w:pStyle w:val="TOCHeading"/></w:pPr>
232
+ <w:r><w:t>${escapeXml(title)}</w:t></w:r>
233
+ </w:p>
234
+ <w:p>
235
+ <w:r>
236
+ <w:fldChar w:fldCharType="begin"/>
237
+ </w:r>
238
+ <w:r>
239
+ <w:instrText xml:space="preserve"> TOC \\o "1-${toc.maxLevel || 3}" \\h \\z \\u </w:instrText>
240
+ </w:r>
241
+ <w:r>
242
+ <w:fldChar w:fldCharType="separate"/>
243
+ </w:r>
244
+ <w:r>
245
+ <w:t>[Table of Contents - Update field to populate]</w:t>
246
+ </w:r>
247
+ <w:r>
248
+ <w:fldChar w:fldCharType="end"/>
249
+ </w:r>
250
+ </w:p>`;
251
+ }
252
+ function generateImagePlaceholderXml(image) {
253
+ const alignment = getAlignmentValue(image.alignment || "center");
254
+ const caption = image.caption || `[Image: ${image.path}]`;
255
+ return `<w:p>
256
+ <w:pPr>${alignment ? `<w:jc w:val="${alignment}"/>` : ""}</w:pPr>
257
+ <w:r>
258
+ <w:rPr><w:i/></w:rPr>
259
+ <w:t>${escapeXml(caption)}</w:t>
260
+ </w:r>
261
+ </w:p>`;
262
+ }
263
+ function getAlignmentValue(alignment) {
264
+ switch (alignment) {
265
+ case "left":
266
+ return "left";
267
+ case "center":
268
+ return "center";
269
+ case "right":
270
+ return "right";
271
+ case "justify":
272
+ return "both";
273
+ default:
274
+ return null;
275
+ }
276
+ }
277
+ function generateStylesXml() {
278
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
279
+ <w:styles xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
280
+ <w:docDefaults>
281
+ <w:rPrDefault>
282
+ <w:rPr>
283
+ <w:rFonts w:ascii="Calibri" w:hAnsi="Calibri" w:eastAsia="Calibri" w:cs="Calibri"/>
284
+ <w:sz w:val="22"/>
285
+ </w:rPr>
286
+ </w:rPrDefault>
287
+ <w:pPrDefault>
288
+ <w:pPr>
289
+ <w:spacing w:after="160" w:line="259" w:lineRule="auto"/>
290
+ </w:pPr>
291
+ </w:pPrDefault>
292
+ </w:docDefaults>
293
+ <w:style w:type="paragraph" w:styleId="Normal" w:default="1">
294
+ <w:name w:val="Normal"/>
295
+ </w:style>
296
+ <w:style w:type="paragraph" w:styleId="Heading1">
297
+ <w:name w:val="heading 1"/>
298
+ <w:basedOn w:val="Normal"/>
299
+ <w:next w:val="Normal"/>
300
+ <w:pPr><w:spacing w:before="240" w:after="0"/><w:outlineLvl w:val="0"/></w:pPr>
301
+ <w:rPr><w:rFonts w:ascii="Calibri Light" w:hAnsi="Calibri Light"/><w:b/><w:color w:val="2F5496"/><w:sz w:val="32"/></w:rPr>
302
+ </w:style>
303
+ <w:style w:type="paragraph" w:styleId="Heading2">
304
+ <w:name w:val="heading 2"/>
305
+ <w:basedOn w:val="Normal"/>
306
+ <w:next w:val="Normal"/>
307
+ <w:pPr><w:spacing w:before="200" w:after="0"/><w:outlineLvl w:val="1"/></w:pPr>
308
+ <w:rPr><w:rFonts w:ascii="Calibri Light" w:hAnsi="Calibri Light"/><w:b/><w:color w:val="2F5496"/><w:sz w:val="26"/></w:rPr>
309
+ </w:style>
310
+ <w:style w:type="paragraph" w:styleId="Heading3">
311
+ <w:name w:val="heading 3"/>
312
+ <w:basedOn w:val="Normal"/>
313
+ <w:next w:val="Normal"/>
314
+ <w:pPr><w:spacing w:before="160" w:after="0"/><w:outlineLvl w:val="2"/></w:pPr>
315
+ <w:rPr><w:rFonts w:ascii="Calibri Light" w:hAnsi="Calibri Light"/><w:b/><w:color w:val="1F3763"/><w:sz w:val="24"/></w:rPr>
316
+ </w:style>
317
+ <w:style w:type="paragraph" w:styleId="Heading4">
318
+ <w:name w:val="heading 4"/>
319
+ <w:basedOn w:val="Normal"/>
320
+ <w:next w:val="Normal"/>
321
+ <w:pPr><w:spacing w:before="120" w:after="0"/><w:outlineLvl w:val="3"/></w:pPr>
322
+ <w:rPr><w:rFonts w:ascii="Calibri Light" w:hAnsi="Calibri Light"/><w:i/><w:color w:val="2F5496"/></w:rPr>
323
+ </w:style>
324
+ <w:style w:type="paragraph" w:styleId="Heading5">
325
+ <w:name w:val="heading 5"/>
326
+ <w:basedOn w:val="Normal"/>
327
+ <w:next w:val="Normal"/>
328
+ <w:pPr><w:spacing w:before="80" w:after="0"/><w:outlineLvl w:val="4"/></w:pPr>
329
+ <w:rPr><w:color w:val="2F5496"/></w:rPr>
330
+ </w:style>
331
+ <w:style w:type="paragraph" w:styleId="Heading6">
332
+ <w:name w:val="heading 6"/>
333
+ <w:basedOn w:val="Normal"/>
334
+ <w:next w:val="Normal"/>
335
+ <w:pPr><w:spacing w:before="40" w:after="0"/><w:outlineLvl w:val="5"/></w:pPr>
336
+ <w:rPr><w:color w:val="1F3763"/></w:rPr>
337
+ </w:style>
338
+ <w:style w:type="paragraph" w:styleId="ListParagraph">
339
+ <w:name w:val="List Paragraph"/>
340
+ <w:basedOn w:val="Normal"/>
341
+ <w:pPr><w:ind w:left="720"/></w:pPr>
342
+ </w:style>
343
+ <w:style w:type="paragraph" w:styleId="TOCHeading">
344
+ <w:name w:val="TOC Heading"/>
345
+ <w:basedOn w:val="Heading1"/>
346
+ <w:next w:val="Normal"/>
347
+ <w:pPr><w:outlineLvl w:val="9"/></w:pPr>
348
+ </w:style>
349
+ <w:style w:type="table" w:styleId="TableGrid">
350
+ <w:name w:val="Table Grid"/>
351
+ <w:tblPr>
352
+ <w:tblBorders>
353
+ <w:top w:val="single" w:sz="4" w:space="0" w:color="auto"/>
354
+ <w:left w:val="single" w:sz="4" w:space="0" w:color="auto"/>
355
+ <w:bottom w:val="single" w:sz="4" w:space="0" w:color="auto"/>
356
+ <w:right w:val="single" w:sz="4" w:space="0" w:color="auto"/>
357
+ <w:insideH w:val="single" w:sz="4" w:space="0" w:color="auto"/>
358
+ <w:insideV w:val="single" w:sz="4" w:space="0" w:color="auto"/>
359
+ </w:tblBorders>
360
+ </w:tblPr>
361
+ </w:style>
362
+ </w:styles>`;
363
+ }
364
+ function generateNumberingXml() {
365
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
366
+ <w:numbering xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
367
+ <!-- Bullet list definition -->
368
+ <w:abstractNum w:abstractNumId="0">
369
+ <w:lvl w:ilvl="0">
370
+ <w:start w:val="1"/>
371
+ <w:numFmt w:val="bullet"/>
372
+ <w:lvlText w:val=""/>
373
+ <w:lvlJc w:val="left"/>
374
+ <w:pPr><w:ind w:left="720" w:hanging="360"/></w:pPr>
375
+ <w:rPr><w:rFonts w:ascii="Symbol" w:hAnsi="Symbol" w:hint="default"/></w:rPr>
376
+ </w:lvl>
377
+ <w:lvl w:ilvl="1">
378
+ <w:start w:val="1"/>
379
+ <w:numFmt w:val="bullet"/>
380
+ <w:lvlText w:val="o"/>
381
+ <w:lvlJc w:val="left"/>
382
+ <w:pPr><w:ind w:left="1440" w:hanging="360"/></w:pPr>
383
+ <w:rPr><w:rFonts w:ascii="Courier New" w:hAnsi="Courier New" w:hint="default"/></w:rPr>
384
+ </w:lvl>
385
+ <w:lvl w:ilvl="2">
386
+ <w:start w:val="1"/>
387
+ <w:numFmt w:val="bullet"/>
388
+ <w:lvlText w:val=""/>
389
+ <w:lvlJc w:val="left"/>
390
+ <w:pPr><w:ind w:left="2160" w:hanging="360"/></w:pPr>
391
+ <w:rPr><w:rFonts w:ascii="Wingdings" w:hAnsi="Wingdings" w:hint="default"/></w:rPr>
392
+ </w:lvl>
393
+ </w:abstractNum>
394
+ <!-- Numbered list definition -->
395
+ <w:abstractNum w:abstractNumId="1">
396
+ <w:lvl w:ilvl="0">
397
+ <w:start w:val="1"/>
398
+ <w:numFmt w:val="decimal"/>
399
+ <w:lvlText w:val="%1."/>
400
+ <w:lvlJc w:val="left"/>
401
+ <w:pPr><w:ind w:left="720" w:hanging="360"/></w:pPr>
402
+ </w:lvl>
403
+ <w:lvl w:ilvl="1">
404
+ <w:start w:val="1"/>
405
+ <w:numFmt w:val="lowerLetter"/>
406
+ <w:lvlText w:val="%2."/>
407
+ <w:lvlJc w:val="left"/>
408
+ <w:pPr><w:ind w:left="1440" w:hanging="360"/></w:pPr>
409
+ </w:lvl>
410
+ <w:lvl w:ilvl="2">
411
+ <w:start w:val="1"/>
412
+ <w:numFmt w:val="lowerRoman"/>
413
+ <w:lvlText w:val="%3."/>
414
+ <w:lvlJc w:val="left"/>
415
+ <w:pPr><w:ind w:left="2160" w:hanging="360"/></w:pPr>
416
+ </w:lvl>
417
+ </w:abstractNum>
418
+ <w:num w:numId="1"><w:abstractNumId w:val="0"/></w:num>
419
+ <w:num w:numId="2"><w:abstractNumId w:val="1"/></w:num>
420
+ </w:numbering>`;
421
+ }
422
+ function generateContentTypesXml() {
423
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
424
+ <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
425
+ <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
426
+ <Default Extension="xml" ContentType="application/xml"/>
427
+ <Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
428
+ <Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/>
429
+ <Override PartName="/word/numbering.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"/>
430
+ <Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>
431
+ <Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>
432
+ </Types>`;
433
+ }
434
+ function generateRootRelsXml() {
435
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
436
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
437
+ <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
438
+ <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
439
+ <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
440
+ </Relationships>`;
441
+ }
442
+ function generateDocumentRelsXml() {
443
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
444
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
445
+ <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>
446
+ <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" Target="numbering.xml"/>
447
+ </Relationships>`;
448
+ }
449
+ function generateCorePropsXml(options) {
450
+ const now = (/* @__PURE__ */ new Date()).toISOString();
451
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
452
+ <cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
453
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
454
+ xmlns:dcterms="http://purl.org/dc/terms/"
455
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
456
+ ${options.title ? `<dc:title>${escapeXml(options.title)}</dc:title>` : ""}
457
+ ${options.author ? `<dc:creator>${escapeXml(options.author)}</dc:creator>` : "<dc:creator>OpenSentinel</dc:creator>"}
458
+ ${options.subject ? `<dc:subject>${escapeXml(options.subject)}</dc:subject>` : ""}
459
+ ${options.description ? `<dc:description>${escapeXml(options.description)}</dc:description>` : ""}
460
+ ${options.keywords ? `<cp:keywords>${escapeXml(options.keywords.join(", "))}</cp:keywords>` : ""}
461
+ <dcterms:created xsi:type="dcterms:W3CDTF">${now}</dcterms:created>
462
+ <dcterms:modified xsi:type="dcterms:W3CDTF">${now}</dcterms:modified>
463
+ </cp:coreProperties>`;
464
+ }
465
+ function generateAppPropsXml() {
466
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
467
+ <Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties">
468
+ <Application>OpenSentinel Document Generator</Application>
469
+ <AppVersion>1.0</AppVersion>
470
+ </Properties>`;
471
+ }
472
+ async function generateWordDocument(elements, filename, options = {}) {
473
+ const filePath = filename ? isPathAllowed(filename) ? filename : join(tmpdir(), filename) : getTempPath();
474
+ try {
475
+ await mkdir(dirname(filePath), { recursive: true });
476
+ try {
477
+ const docx = await import("./dist-UISMLMFN.js");
478
+ return await generateWithDocxLibrary(elements, filePath, options, docx);
479
+ } catch {
480
+ console.log("[WordDocument] docx library not available, using raw OOXML generation");
481
+ return await generateRawDocx(elements, filePath, options);
482
+ }
483
+ } catch (error) {
484
+ return {
485
+ success: false,
486
+ error: error instanceof Error ? error.message : String(error)
487
+ };
488
+ }
489
+ }
490
+ async function generateWithDocxLibrary(elements, filePath, options, docx) {
491
+ const { Document, Packer, Paragraph, TextRun, HeadingLevel, AlignmentType, Table, TableRow, TableCell, WidthType, BorderStyle, PageBreak } = docx;
492
+ const children = [];
493
+ for (const element of elements) {
494
+ switch (element.type) {
495
+ case "paragraph": {
496
+ const runs = [];
497
+ if (typeof element.content === "string") {
498
+ runs.push(new TextRun(element.content));
499
+ } else {
500
+ for (const run of element.content) {
501
+ runs.push(
502
+ new TextRun({
503
+ text: run.text,
504
+ bold: run.bold,
505
+ italics: run.italic,
506
+ underline: run.underline ? {} : void 0,
507
+ strike: run.strike,
508
+ color: run.color?.replace("#", ""),
509
+ size: run.size ? run.size * 2 : void 0,
510
+ font: run.font,
511
+ highlight: run.highlight
512
+ })
513
+ );
514
+ }
515
+ }
516
+ children.push(
517
+ new Paragraph({
518
+ children: runs,
519
+ alignment: getDocxAlignment(element.alignment, AlignmentType),
520
+ spacing: element.spacing ? {
521
+ before: element.spacing.before,
522
+ after: element.spacing.after,
523
+ line: element.spacing.line
524
+ } : void 0,
525
+ indent: element.indent ? {
526
+ left: element.indent.left,
527
+ right: element.indent.right,
528
+ firstLine: element.indent.firstLine
529
+ } : void 0
530
+ })
531
+ );
532
+ break;
533
+ }
534
+ case "heading": {
535
+ const headingLevelMap = {
536
+ 1: HeadingLevel.HEADING_1,
537
+ 2: HeadingLevel.HEADING_2,
538
+ 3: HeadingLevel.HEADING_3,
539
+ 4: HeadingLevel.HEADING_4,
540
+ 5: HeadingLevel.HEADING_5,
541
+ 6: HeadingLevel.HEADING_6
542
+ };
543
+ children.push(
544
+ new Paragraph({
545
+ text: element.text,
546
+ heading: headingLevelMap[element.level],
547
+ alignment: getDocxAlignment(element.alignment, AlignmentType)
548
+ })
549
+ );
550
+ break;
551
+ }
552
+ case "bullet-list": {
553
+ for (const item of element.items) {
554
+ children.push(
555
+ new Paragraph({
556
+ text: item,
557
+ bullet: { level: element.level || 0 }
558
+ })
559
+ );
560
+ }
561
+ break;
562
+ }
563
+ case "numbered-list": {
564
+ for (let i = 0; i < element.items.length; i++) {
565
+ children.push(
566
+ new Paragraph({
567
+ text: element.items[i],
568
+ numbering: {
569
+ reference: "default-numbering",
570
+ level: 0
571
+ }
572
+ })
573
+ );
574
+ }
575
+ break;
576
+ }
577
+ case "table": {
578
+ const rows = [];
579
+ if (element.headers) {
580
+ rows.push(
581
+ new TableRow({
582
+ children: element.headers.map((cell) => {
583
+ const cellData = typeof cell === "string" ? { content: cell } : cell;
584
+ return new TableCell({
585
+ children: [
586
+ new Paragraph({
587
+ children: [
588
+ new TextRun({ text: cellData.content, bold: true })
589
+ ],
590
+ alignment: AlignmentType.CENTER
591
+ })
592
+ ],
593
+ shading: cellData.backgroundColor ? { fill: cellData.backgroundColor.replace("#", "") } : { fill: "E0E0E0" }
594
+ });
595
+ }),
596
+ tableHeader: true
597
+ })
598
+ );
599
+ }
600
+ for (const row of element.rows) {
601
+ rows.push(
602
+ new TableRow({
603
+ children: row.map((cell) => {
604
+ const cellData = typeof cell === "string" ? { content: cell } : cell;
605
+ return new TableCell({
606
+ children: [
607
+ new Paragraph({
608
+ children: [
609
+ new TextRun({
610
+ text: cellData.content,
611
+ bold: cellData.bold
612
+ })
613
+ ],
614
+ alignment: getDocxAlignment(cellData.alignment, AlignmentType)
615
+ })
616
+ ],
617
+ shading: cellData.backgroundColor ? { fill: cellData.backgroundColor.replace("#", "") } : void 0,
618
+ columnSpan: cellData.colSpan,
619
+ rowSpan: cellData.rowSpan
620
+ });
621
+ })
622
+ })
623
+ );
624
+ }
625
+ children.push(
626
+ new Table({
627
+ rows,
628
+ width: { size: 100, type: WidthType.PERCENTAGE }
629
+ })
630
+ );
631
+ break;
632
+ }
633
+ case "page-break": {
634
+ children.push(
635
+ new Paragraph({
636
+ children: [new PageBreak()]
637
+ })
638
+ );
639
+ break;
640
+ }
641
+ case "horizontal-rule": {
642
+ children.push(
643
+ new Paragraph({
644
+ border: {
645
+ bottom: {
646
+ color: "auto",
647
+ space: 1,
648
+ style: BorderStyle.SINGLE,
649
+ size: 12
650
+ }
651
+ }
652
+ })
653
+ );
654
+ break;
655
+ }
656
+ case "toc": {
657
+ children.push(
658
+ new Paragraph({
659
+ text: element.title || "Table of Contents",
660
+ heading: HeadingLevel.HEADING_1
661
+ })
662
+ );
663
+ children.push(
664
+ new Paragraph({
665
+ text: "[Update field to generate Table of Contents]"
666
+ })
667
+ );
668
+ break;
669
+ }
670
+ case "image": {
671
+ children.push(
672
+ new Paragraph({
673
+ text: element.caption || `[Image: ${element.path}]`,
674
+ alignment: getDocxAlignment(element.alignment, AlignmentType)
675
+ })
676
+ );
677
+ break;
678
+ }
679
+ }
680
+ }
681
+ const doc = new Document({
682
+ title: options.title,
683
+ creator: options.author || "OpenSentinel",
684
+ subject: options.subject,
685
+ description: options.description,
686
+ keywords: options.keywords?.join(", "),
687
+ sections: [
688
+ {
689
+ properties: {
690
+ page: {
691
+ size: {
692
+ orientation: options.orientation === "landscape" ? docx.PageOrientation.LANDSCAPE : docx.PageOrientation.PORTRAIT
693
+ },
694
+ margin: options.margins ? {
695
+ top: options.margins.top,
696
+ right: options.margins.right,
697
+ bottom: options.margins.bottom,
698
+ left: options.margins.left
699
+ } : void 0
700
+ }
701
+ },
702
+ children
703
+ }
704
+ ],
705
+ numbering: {
706
+ config: [
707
+ {
708
+ reference: "default-numbering",
709
+ levels: [
710
+ {
711
+ level: 0,
712
+ format: docx.LevelFormat.DECIMAL,
713
+ text: "%1.",
714
+ alignment: AlignmentType.START
715
+ }
716
+ ]
717
+ }
718
+ ]
719
+ }
720
+ });
721
+ const buffer = await Packer.toBuffer(doc);
722
+ await writeFile(filePath, buffer);
723
+ return { success: true, filePath };
724
+ }
725
+ function getDocxAlignment(alignment, AlignmentType) {
726
+ switch (alignment) {
727
+ case "left":
728
+ return AlignmentType.LEFT;
729
+ case "center":
730
+ return AlignmentType.CENTER;
731
+ case "right":
732
+ return AlignmentType.RIGHT;
733
+ case "justify":
734
+ return AlignmentType.JUSTIFIED;
735
+ default:
736
+ return void 0;
737
+ }
738
+ }
739
+ async function generateRawDocx(elements, filePath, options) {
740
+ const finalOptions = { ...DEFAULT_OPTIONS, ...options };
741
+ try {
742
+ const archiver = await import("./archiver-AVNBYCKQ.js");
743
+ const fs = await import("fs");
744
+ const output = fs.createWriteStream(filePath);
745
+ const archive = archiver.default("zip", { zlib: { level: 9 } });
746
+ return new Promise((resolve) => {
747
+ output.on("close", () => {
748
+ resolve({ success: true, filePath });
749
+ });
750
+ archive.on("error", (err) => {
751
+ resolve({ success: false, error: err.message });
752
+ });
753
+ archive.pipe(output);
754
+ archive.append(generateContentTypesXml(), { name: "[Content_Types].xml" });
755
+ archive.append(generateRootRelsXml(), { name: "_rels/.rels" });
756
+ archive.append(generateDocumentXml(elements, finalOptions), { name: "word/document.xml" });
757
+ archive.append(generateStylesXml(), { name: "word/styles.xml" });
758
+ archive.append(generateNumberingXml(), { name: "word/numbering.xml" });
759
+ archive.append(generateDocumentRelsXml(), { name: "word/_rels/document.xml.rels" });
760
+ archive.append(generateCorePropsXml(finalOptions), { name: "docProps/core.xml" });
761
+ archive.append(generateAppPropsXml(), { name: "docProps/app.xml" });
762
+ archive.finalize();
763
+ });
764
+ } catch {
765
+ const xmlPath = filePath.replace(".docx", ".xml");
766
+ const documentXml = generateDocumentXml(elements, finalOptions);
767
+ await writeFile(xmlPath, documentXml, "utf-8");
768
+ return {
769
+ success: true,
770
+ filePath: xmlPath
771
+ };
772
+ }
773
+ }
774
+ async function generateWordFromMarkdown(markdown, filename, options) {
775
+ const elements = parseMarkdownToElements(markdown);
776
+ return generateWordDocument(elements, filename, options);
777
+ }
778
+ function parseMarkdownToElements(markdown) {
779
+ const elements = [];
780
+ const lines = markdown.split("\n");
781
+ let i = 0;
782
+ while (i < lines.length) {
783
+ const line = lines[i];
784
+ const headerMatch = line.match(/^(#{1,6})\s+(.+)$/);
785
+ if (headerMatch) {
786
+ elements.push({
787
+ type: "heading",
788
+ level: headerMatch[1].length,
789
+ text: headerMatch[2].trim()
790
+ });
791
+ i++;
792
+ continue;
793
+ }
794
+ if (/^(-{3,}|\*{3,}|_{3,})$/.test(line.trim())) {
795
+ elements.push({ type: "horizontal-rule" });
796
+ i++;
797
+ continue;
798
+ }
799
+ if (/^[-*+]\s+/.test(line)) {
800
+ const items = [];
801
+ while (i < lines.length && /^[-*+]\s+/.test(lines[i])) {
802
+ items.push(lines[i].replace(/^[-*+]\s+/, "").trim());
803
+ i++;
804
+ }
805
+ elements.push({ type: "bullet-list", items });
806
+ continue;
807
+ }
808
+ if (/^\d+\.\s+/.test(line)) {
809
+ const items = [];
810
+ while (i < lines.length && /^\d+\.\s+/.test(lines[i])) {
811
+ items.push(lines[i].replace(/^\d+\.\s+/, "").trim());
812
+ i++;
813
+ }
814
+ elements.push({ type: "numbered-list", items });
815
+ continue;
816
+ }
817
+ if (line.trim() === "") {
818
+ i++;
819
+ continue;
820
+ }
821
+ let paragraphText = "";
822
+ while (i < lines.length && lines[i].trim() !== "" && !/^(#{1,6}|[-*+]|\d+\.)\s+/.test(lines[i])) {
823
+ paragraphText += (paragraphText ? " " : "") + lines[i].trim();
824
+ i++;
825
+ }
826
+ if (paragraphText) {
827
+ const runs = parseInlineFormatting(paragraphText);
828
+ elements.push({
829
+ type: "paragraph",
830
+ content: runs.length === 1 && !runs[0].bold && !runs[0].italic ? paragraphText : runs
831
+ });
832
+ }
833
+ }
834
+ return elements;
835
+ }
836
+ function parseInlineFormatting(text) {
837
+ const runs = [];
838
+ let remaining = text;
839
+ while (remaining.length > 0) {
840
+ const boldItalicMatch = remaining.match(/^\*\*\*(.+?)\*\*\*/);
841
+ if (boldItalicMatch) {
842
+ runs.push({ text: boldItalicMatch[1], bold: true, italic: true });
843
+ remaining = remaining.slice(boldItalicMatch[0].length);
844
+ continue;
845
+ }
846
+ const boldMatch = remaining.match(/^\*\*(.+?)\*\*/);
847
+ if (boldMatch) {
848
+ runs.push({ text: boldMatch[1], bold: true });
849
+ remaining = remaining.slice(boldMatch[0].length);
850
+ continue;
851
+ }
852
+ const italicMatch = remaining.match(/^\*(.+?)\*/);
853
+ if (italicMatch) {
854
+ runs.push({ text: italicMatch[1], italic: true });
855
+ remaining = remaining.slice(italicMatch[0].length);
856
+ continue;
857
+ }
858
+ const strikeMatch = remaining.match(/^~~(.+?)~~/);
859
+ if (strikeMatch) {
860
+ runs.push({ text: strikeMatch[1], strike: true });
861
+ remaining = remaining.slice(strikeMatch[0].length);
862
+ continue;
863
+ }
864
+ const codeMatch = remaining.match(/^`(.+?)`/);
865
+ if (codeMatch) {
866
+ runs.push({ text: codeMatch[1], font: "Courier New" });
867
+ remaining = remaining.slice(codeMatch[0].length);
868
+ continue;
869
+ }
870
+ const nextFormat = remaining.search(/(\*\*\*|\*\*|\*|~~|`)/);
871
+ if (nextFormat === -1) {
872
+ runs.push({ text: remaining });
873
+ break;
874
+ } else if (nextFormat === 0) {
875
+ runs.push({ text: remaining[0] });
876
+ remaining = remaining.slice(1);
877
+ } else {
878
+ runs.push({ text: remaining.slice(0, nextFormat) });
879
+ remaining = remaining.slice(nextFormat);
880
+ }
881
+ }
882
+ return runs;
883
+ }
884
+ async function generateWord(content, filename, options) {
885
+ const contentType = options?.contentType || "markdown";
886
+ if (contentType === "elements" || Array.isArray(content)) {
887
+ return generateWordDocument(content, filename, options);
888
+ }
889
+ return generateWordFromMarkdown(content, filename, options);
890
+ }
891
+ var word_document_default = {
892
+ generateWord,
893
+ generateWordDocument,
894
+ generateWordFromMarkdown
895
+ };
896
+ export {
897
+ word_document_default as default,
898
+ generateWord,
899
+ generateWordDocument,
900
+ generateWordFromMarkdown
901
+ };
902
+ //# sourceMappingURL=word-document-7B6SJMAY.js.map