@wonderwhy-er/desktop-commander 0.2.38 → 0.2.39

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 (364) hide show
  1. package/README.md +53 -2
  2. package/dist/handlers/filesystem-handlers.d.ts +5 -0
  3. package/dist/handlers/filesystem-handlers.js +14 -2
  4. package/dist/remote-device/desktop-commander-integration.js +1 -1
  5. package/dist/search-manager.js +31 -38
  6. package/dist/server.js +8 -3
  7. package/dist/terminal-manager.js +4 -2
  8. package/dist/tools/edit.js +34 -1
  9. package/dist/tools/filesystem.js +91 -3
  10. package/dist/tools/improved-process-tools.js +2 -1
  11. package/dist/ui/config-editor/app.js +840 -0
  12. package/dist/ui/config-editor/array-modal.d.ts +19 -0
  13. package/dist/ui/config-editor/array-modal.js +185 -0
  14. package/dist/ui/config-editor/config-editor-runtime.js +65 -14096
  15. package/dist/ui/config-editor/main.js +2 -0
  16. package/dist/ui/config-editor/src/App.d.ts +43 -0
  17. package/dist/ui/config-editor/src/components/layout.d.ts +4 -0
  18. package/dist/ui/config-editor/src/components/layout.js +83 -0
  19. package/dist/ui/config-editor/src/components/toolbar.d.ts +1 -0
  20. package/dist/ui/config-editor/src/components/toolbar.js +21 -0
  21. package/dist/ui/config-editor/src/config-values.d.ts +6 -0
  22. package/dist/ui/config-editor/src/config-values.js +61 -0
  23. package/dist/ui/config-editor/src/contracts.d.ts +14 -0
  24. package/dist/ui/config-editor/src/contracts.js +3 -0
  25. package/dist/ui/config-editor/src/directory-browser.d.ts +6 -0
  26. package/dist/ui/config-editor/src/directory-browser.js +71 -0
  27. package/dist/ui/config-editor/src/layout.d.ts +5 -0
  28. package/dist/ui/config-editor/src/layout.js +90 -0
  29. package/dist/ui/config-editor/src/parsing.d.ts +5 -0
  30. package/dist/ui/config-editor/src/parsing.js +50 -0
  31. package/dist/ui/config-editor/src/toolbar.d.ts +1 -0
  32. package/dist/ui/config-editor/src/toolbar.js +18 -0
  33. package/dist/ui/config-editor/src/types.d.ts +17 -0
  34. package/dist/ui/config-editor/src/types.js +3 -0
  35. package/dist/ui/config-editor/src/utils/config-values.d.ts +9 -0
  36. package/dist/ui/config-editor/src/utils/config-values.js +61 -0
  37. package/dist/ui/config-editor/src/utils/directory-browser.d.ts +31 -0
  38. package/dist/ui/config-editor/src/utils/directory-browser.js +201 -0
  39. package/dist/ui/config-editor/src/utils/parsing.d.ts +8 -0
  40. package/dist/ui/config-editor/src/utils/parsing.js +50 -0
  41. package/dist/ui/config-editor/styles.css +2 -1
  42. package/dist/ui/file-preview/{src/app.d.ts → app.d.ts} +1 -1
  43. package/dist/ui/file-preview/app.js +2020 -0
  44. package/dist/ui/file-preview/components/code-viewer.d.ts +6 -0
  45. package/dist/ui/file-preview/components/code-viewer.js +73 -0
  46. package/dist/ui/file-preview/components/highlighting.d.ts +2 -0
  47. package/dist/ui/file-preview/components/highlighting.js +54 -0
  48. package/dist/ui/file-preview/components/html-renderer.d.ts +5 -0
  49. package/dist/ui/file-preview/components/html-renderer.js +47 -0
  50. package/dist/ui/file-preview/components/markdown-renderer.d.ts +1 -0
  51. package/dist/ui/file-preview/components/markdown-renderer.js +67 -0
  52. package/dist/ui/file-preview/components/toolbar.d.ts +6 -0
  53. package/dist/ui/file-preview/components/toolbar.js +75 -0
  54. package/dist/ui/file-preview/image-preview.d.ts +3 -0
  55. package/dist/ui/file-preview/image-preview.js +21 -0
  56. package/dist/ui/file-preview/main.js +5 -0
  57. package/dist/ui/file-preview/markdown/editor.d.ts +36 -0
  58. package/dist/ui/file-preview/markdown/editor.js +643 -0
  59. package/dist/ui/file-preview/markdown/linking.d.ts +9 -0
  60. package/dist/ui/file-preview/markdown/linking.js +210 -0
  61. package/dist/ui/file-preview/markdown/outline.d.ts +7 -0
  62. package/dist/ui/file-preview/markdown/outline.js +40 -0
  63. package/dist/ui/file-preview/markdown/preview.d.ts +8 -0
  64. package/dist/ui/file-preview/markdown/preview.js +33 -0
  65. package/dist/ui/file-preview/markdown/slugify.d.ts +3 -0
  66. package/dist/ui/file-preview/markdown/slugify.js +31 -0
  67. package/dist/ui/file-preview/markdown/toc.d.ts +11 -0
  68. package/dist/ui/file-preview/markdown/toc.js +75 -0
  69. package/dist/ui/file-preview/markdown/utils.d.ts +1 -0
  70. package/dist/ui/file-preview/markdown/utils.js +15 -0
  71. package/dist/ui/file-preview/markdown/workspace-controller.d.ts +25 -0
  72. package/dist/ui/file-preview/markdown/workspace-controller.js +40 -0
  73. package/dist/ui/file-preview/preview-runtime.js +384 -26533
  74. package/dist/ui/file-preview/shared/preview-file-types.d.ts +1 -1
  75. package/dist/ui/file-preview/src/App.d.ts +4 -0
  76. package/dist/ui/file-preview/src/App.js +564 -0
  77. package/dist/ui/file-preview/src/components/CodeViewer.d.ts +6 -0
  78. package/dist/ui/file-preview/src/components/CodeViewer.js +60 -0
  79. package/dist/ui/file-preview/src/components/HtmlRenderer.d.ts +8 -0
  80. package/dist/ui/file-preview/src/components/HtmlRenderer.js +45 -0
  81. package/dist/ui/file-preview/src/components/MarkdownRenderer.d.ts +1 -0
  82. package/dist/ui/file-preview/src/components/MarkdownRenderer.js +15 -0
  83. package/dist/ui/file-preview/src/components/editor-toolbar.d.ts +15 -0
  84. package/dist/ui/file-preview/src/components/editor-toolbar.js +384 -0
  85. package/dist/ui/file-preview/src/components/markdown-editor.d.ts +29 -0
  86. package/dist/ui/file-preview/src/components/markdown-editor.js +535 -0
  87. package/dist/ui/file-preview/src/components/markdown-renderer.js +47 -9
  88. package/dist/ui/file-preview/src/directory-controller.d.ts +8 -0
  89. package/dist/ui/file-preview/src/directory-controller.js +233 -0
  90. package/dist/ui/file-preview/src/document-layout.d.ts +20 -0
  91. package/dist/ui/file-preview/src/document-layout.js +109 -0
  92. package/dist/ui/file-preview/src/document-outline.d.ts +17 -0
  93. package/dist/ui/file-preview/src/document-outline.js +97 -0
  94. package/dist/ui/file-preview/src/document-workspace.d.ts +19 -0
  95. package/dist/ui/file-preview/src/document-workspace.js +33 -0
  96. package/dist/ui/file-preview/src/file-type-handlers.d.ts +10 -0
  97. package/dist/ui/file-preview/src/file-type-handlers.js +98 -0
  98. package/dist/ui/file-preview/src/host/external-actions.d.ts +19 -0
  99. package/dist/ui/file-preview/src/host/external-actions.js +94 -0
  100. package/dist/ui/file-preview/src/host/selection-context.d.ts +9 -0
  101. package/dist/ui/file-preview/src/host/selection-context.js +106 -0
  102. package/dist/ui/file-preview/src/markdown/block-merge.d.ts +25 -0
  103. package/dist/ui/file-preview/src/markdown/block-merge.js +86 -0
  104. package/dist/ui/file-preview/src/markdown/conflict-dialog.d.ts +40 -0
  105. package/dist/ui/file-preview/src/markdown/conflict-dialog.js +163 -0
  106. package/dist/ui/file-preview/src/markdown/controller.d.ts +38 -0
  107. package/dist/ui/file-preview/src/markdown/controller.js +921 -0
  108. package/dist/ui/file-preview/src/markdown/editor.d.ts +35 -0
  109. package/dist/ui/file-preview/src/markdown/editor.js +691 -0
  110. package/dist/ui/file-preview/src/markdown/link-modal.d.ts +13 -0
  111. package/dist/ui/file-preview/src/markdown/link-modal.js +213 -0
  112. package/dist/ui/file-preview/src/markdown/linking.d.ts +16 -0
  113. package/dist/ui/file-preview/src/markdown/linking.js +228 -0
  114. package/dist/ui/file-preview/src/markdown/outline.d.ts +2 -0
  115. package/dist/ui/file-preview/src/markdown/outline.js +16 -0
  116. package/dist/ui/file-preview/src/markdown/parser.d.ts +30 -0
  117. package/dist/ui/file-preview/src/markdown/parser.js +38 -0
  118. package/dist/ui/file-preview/src/markdown/preview.d.ts +1 -0
  119. package/dist/ui/file-preview/src/markdown/preview.js +20 -0
  120. package/dist/ui/file-preview/src/markdown/raw-editor.d.ts +8 -0
  121. package/dist/ui/file-preview/src/markdown/raw-editor.js +61 -0
  122. package/dist/ui/file-preview/src/markdown/selection-toolbar.d.ts +14 -0
  123. package/dist/ui/file-preview/src/markdown/selection-toolbar.js +128 -0
  124. package/dist/ui/file-preview/src/markdown/slugify.d.ts +3 -0
  125. package/dist/ui/file-preview/src/markdown/slugify.js +31 -0
  126. package/dist/ui/file-preview/src/markdown/toc.d.ts +11 -0
  127. package/dist/ui/file-preview/src/markdown/toc.js +75 -0
  128. package/dist/ui/file-preview/src/markdown/utils.d.ts +1 -0
  129. package/dist/ui/file-preview/src/markdown/utils.js +15 -0
  130. package/dist/ui/file-preview/src/markdown-workspace/editor.d.ts +36 -0
  131. package/dist/ui/file-preview/src/markdown-workspace/editor.js +643 -0
  132. package/dist/ui/file-preview/src/markdown-workspace/linking.d.ts +9 -0
  133. package/dist/ui/file-preview/src/markdown-workspace/linking.js +210 -0
  134. package/dist/ui/file-preview/src/markdown-workspace/outline.d.ts +7 -0
  135. package/dist/ui/file-preview/src/markdown-workspace/outline.js +40 -0
  136. package/dist/ui/file-preview/src/markdown-workspace/preview.d.ts +8 -0
  137. package/dist/ui/file-preview/src/markdown-workspace/preview.js +33 -0
  138. package/dist/ui/file-preview/src/markdown-workspace/slugify.d.ts +3 -0
  139. package/dist/ui/file-preview/src/markdown-workspace/slugify.js +31 -0
  140. package/dist/ui/file-preview/src/markdown-workspace/toc.d.ts +11 -0
  141. package/dist/ui/file-preview/src/markdown-workspace/toc.js +75 -0
  142. package/dist/ui/file-preview/src/markdown-workspace/utils.d.ts +1 -0
  143. package/dist/ui/file-preview/src/markdown-workspace/utils.js +15 -0
  144. package/dist/ui/file-preview/src/markdown-workspace/workspace-controller.d.ts +25 -0
  145. package/dist/ui/file-preview/src/markdown-workspace/workspace-controller.js +40 -0
  146. package/dist/ui/file-preview/src/model.d.ts +34 -0
  147. package/dist/ui/file-preview/src/panel-actions.d.ts +17 -0
  148. package/dist/ui/file-preview/src/panel-actions.js +182 -0
  149. package/dist/ui/file-preview/src/path-utils.d.ts +6 -0
  150. package/dist/ui/file-preview/src/path-utils.js +64 -0
  151. package/dist/ui/file-preview/src/payload-utils.d.ts +11 -0
  152. package/dist/ui/file-preview/src/payload-utils.js +94 -0
  153. package/dist/ui/file-preview/styles.css +1066 -233
  154. package/dist/ui/file-preview/types.d.ts +1 -0
  155. package/dist/ui/server-integration.d.ts +13 -0
  156. package/dist/ui/server-integration.js +31 -0
  157. package/dist/ui/shared/ToolHeader.d.ts +9 -0
  158. package/dist/ui/shared/ToolHeader.js +29 -0
  159. package/dist/ui/shared/app-bootstrap.d.ts +9 -0
  160. package/dist/ui/shared/app-bootstrap.js +15 -0
  161. package/dist/ui/shared/guards.d.ts +1 -0
  162. package/dist/ui/shared/guards.js +3 -0
  163. package/dist/ui/shared/host-lifecycle.d.ts +1 -0
  164. package/dist/ui/shared/host-lifecycle.js +8 -2
  165. package/dist/ui/shared/widget-state.d.ts +6 -1
  166. package/dist/ui/shared/widget-state.js +102 -4
  167. package/dist/utils/files/base.d.ts +2 -0
  168. package/dist/utils/open-browser.js +1 -1
  169. package/dist/utils/ui-call-context.d.ts +8 -0
  170. package/dist/utils/ui-call-context.js +72 -0
  171. package/dist/version.d.ts +1 -1
  172. package/dist/version.js +1 -1
  173. package/package.json +6 -1
  174. package/dist/data/spec-kit-prompts.json +0 -123
  175. package/dist/handlers/macos-control-handlers.d.ts +0 -16
  176. package/dist/handlers/macos-control-handlers.js +0 -81
  177. package/dist/handlers/node-handlers.d.ts +0 -6
  178. package/dist/handlers/node-handlers.js +0 -73
  179. package/dist/handlers/test-crash-handler.d.ts +0 -11
  180. package/dist/handlers/test-crash-handler.js +0 -26
  181. package/dist/http-index.d.ts +0 -45
  182. package/dist/http-index.js +0 -51
  183. package/dist/http-server-auto-tunnel.js +0 -667
  184. package/dist/http-server-named-tunnel.d.ts +0 -2
  185. package/dist/http-server-named-tunnel.js +0 -167
  186. package/dist/http-server-tunnel.d.ts +0 -2
  187. package/dist/http-server-tunnel.js +0 -111
  188. package/dist/http-server.d.ts +0 -2
  189. package/dist/http-server.js +0 -270
  190. package/dist/index-oauth.d.ts +0 -2
  191. package/dist/index-oauth.js +0 -201
  192. package/dist/lib.d.ts +0 -10
  193. package/dist/lib.js +0 -10
  194. package/dist/oauth/auth-middleware.d.ts +0 -20
  195. package/dist/oauth/auth-middleware.js +0 -62
  196. package/dist/oauth/index.d.ts +0 -3
  197. package/dist/oauth/index.js +0 -3
  198. package/dist/oauth/oauth-manager.d.ts +0 -80
  199. package/dist/oauth/oauth-manager.js +0 -179
  200. package/dist/oauth/oauth-routes.d.ts +0 -3
  201. package/dist/oauth/oauth-routes.js +0 -377
  202. package/dist/oauth/provider.d.ts +0 -22
  203. package/dist/oauth/provider.js +0 -124
  204. package/dist/oauth/server.d.ts +0 -18
  205. package/dist/oauth/server.js +0 -160
  206. package/dist/oauth/types.d.ts +0 -54
  207. package/dist/oauth/types.js +0 -2
  208. package/dist/remote-device/templates/auth-success.d.ts +0 -1
  209. package/dist/remote-device/templates/auth-success.js +0 -30
  210. package/dist/setup.log +0 -275
  211. package/dist/test-setup.js +0 -14
  212. package/dist/tools/docx/builders/html-builder.d.ts +0 -17
  213. package/dist/tools/docx/builders/html-builder.js +0 -92
  214. package/dist/tools/docx/builders/image.d.ts +0 -14
  215. package/dist/tools/docx/builders/image.js +0 -84
  216. package/dist/tools/docx/builders/index.d.ts +0 -11
  217. package/dist/tools/docx/builders/index.js +0 -11
  218. package/dist/tools/docx/builders/markdown-builder.d.ts +0 -2
  219. package/dist/tools/docx/builders/markdown-builder.js +0 -260
  220. package/dist/tools/docx/builders/paragraph.d.ts +0 -12
  221. package/dist/tools/docx/builders/paragraph.js +0 -29
  222. package/dist/tools/docx/builders/table.d.ts +0 -10
  223. package/dist/tools/docx/builders/table.js +0 -138
  224. package/dist/tools/docx/builders/utils.d.ts +0 -5
  225. package/dist/tools/docx/builders/utils.js +0 -18
  226. package/dist/tools/docx/constants.d.ts +0 -32
  227. package/dist/tools/docx/constants.js +0 -61
  228. package/dist/tools/docx/converters/markdown-to-html.d.ts +0 -17
  229. package/dist/tools/docx/converters/markdown-to-html.js +0 -111
  230. package/dist/tools/docx/create.d.ts +0 -21
  231. package/dist/tools/docx/create.js +0 -386
  232. package/dist/tools/docx/dom.d.ts +0 -139
  233. package/dist/tools/docx/dom.js +0 -448
  234. package/dist/tools/docx/errors.d.ts +0 -28
  235. package/dist/tools/docx/errors.js +0 -48
  236. package/dist/tools/docx/extractors/images.d.ts +0 -14
  237. package/dist/tools/docx/extractors/images.js +0 -40
  238. package/dist/tools/docx/extractors/metadata.d.ts +0 -14
  239. package/dist/tools/docx/extractors/metadata.js +0 -64
  240. package/dist/tools/docx/extractors/sections.d.ts +0 -14
  241. package/dist/tools/docx/extractors/sections.js +0 -61
  242. package/dist/tools/docx/html.d.ts +0 -17
  243. package/dist/tools/docx/html.js +0 -111
  244. package/dist/tools/docx/index.d.ts +0 -10
  245. package/dist/tools/docx/index.js +0 -10
  246. package/dist/tools/docx/markdown.d.ts +0 -84
  247. package/dist/tools/docx/markdown.js +0 -507
  248. package/dist/tools/docx/modify.d.ts +0 -28
  249. package/dist/tools/docx/modify.js +0 -271
  250. package/dist/tools/docx/operations/handlers/index.d.ts +0 -39
  251. package/dist/tools/docx/operations/handlers/index.js +0 -152
  252. package/dist/tools/docx/operations/html-manipulator.d.ts +0 -24
  253. package/dist/tools/docx/operations/html-manipulator.js +0 -352
  254. package/dist/tools/docx/operations/index.d.ts +0 -14
  255. package/dist/tools/docx/operations/index.js +0 -61
  256. package/dist/tools/docx/operations/operation-handlers.d.ts +0 -3
  257. package/dist/tools/docx/operations/operation-handlers.js +0 -67
  258. package/dist/tools/docx/operations/preprocessor.d.ts +0 -14
  259. package/dist/tools/docx/operations/preprocessor.js +0 -44
  260. package/dist/tools/docx/operations/xml-replacer.d.ts +0 -9
  261. package/dist/tools/docx/operations/xml-replacer.js +0 -35
  262. package/dist/tools/docx/operations.d.ts +0 -13
  263. package/dist/tools/docx/operations.js +0 -13
  264. package/dist/tools/docx/ops/delete-paragraph-at-body-index.d.ts +0 -11
  265. package/dist/tools/docx/ops/delete-paragraph-at-body-index.js +0 -23
  266. package/dist/tools/docx/ops/header-replace-text-exact.d.ts +0 -13
  267. package/dist/tools/docx/ops/header-replace-text-exact.js +0 -55
  268. package/dist/tools/docx/ops/index.d.ts +0 -17
  269. package/dist/tools/docx/ops/index.js +0 -70
  270. package/dist/tools/docx/ops/insert-image-after-text.d.ts +0 -24
  271. package/dist/tools/docx/ops/insert-image-after-text.js +0 -128
  272. package/dist/tools/docx/ops/insert-paragraph-after-text.d.ts +0 -12
  273. package/dist/tools/docx/ops/insert-paragraph-after-text.js +0 -74
  274. package/dist/tools/docx/ops/insert-table-after-text.d.ts +0 -19
  275. package/dist/tools/docx/ops/insert-table-after-text.js +0 -57
  276. package/dist/tools/docx/ops/replace-hyperlink-url.d.ts +0 -12
  277. package/dist/tools/docx/ops/replace-hyperlink-url.js +0 -37
  278. package/dist/tools/docx/ops/replace-paragraph-at-body-index.d.ts +0 -9
  279. package/dist/tools/docx/ops/replace-paragraph-at-body-index.js +0 -25
  280. package/dist/tools/docx/ops/replace-paragraph-text-exact.d.ts +0 -21
  281. package/dist/tools/docx/ops/replace-paragraph-text-exact.js +0 -36
  282. package/dist/tools/docx/ops/replace-table-cell-text.d.ts +0 -25
  283. package/dist/tools/docx/ops/replace-table-cell-text.js +0 -85
  284. package/dist/tools/docx/ops/set-color-for-paragraph-exact.d.ts +0 -9
  285. package/dist/tools/docx/ops/set-color-for-paragraph-exact.js +0 -24
  286. package/dist/tools/docx/ops/set-color-for-style.d.ts +0 -13
  287. package/dist/tools/docx/ops/set-color-for-style.js +0 -31
  288. package/dist/tools/docx/ops/set-paragraph-style-at-body-index.d.ts +0 -8
  289. package/dist/tools/docx/ops/set-paragraph-style-at-body-index.js +0 -57
  290. package/dist/tools/docx/ops/table-set-cell-text.d.ts +0 -9
  291. package/dist/tools/docx/ops/table-set-cell-text.js +0 -40
  292. package/dist/tools/docx/parsers/image-extractor.d.ts +0 -18
  293. package/dist/tools/docx/parsers/image-extractor.js +0 -61
  294. package/dist/tools/docx/parsers/index.d.ts +0 -9
  295. package/dist/tools/docx/parsers/index.js +0 -9
  296. package/dist/tools/docx/parsers/paragraph-parser.d.ts +0 -2
  297. package/dist/tools/docx/parsers/paragraph-parser.js +0 -88
  298. package/dist/tools/docx/parsers/table-parser.d.ts +0 -9
  299. package/dist/tools/docx/parsers/table-parser.js +0 -72
  300. package/dist/tools/docx/parsers/xml-parser.d.ts +0 -25
  301. package/dist/tools/docx/parsers/xml-parser.js +0 -71
  302. package/dist/tools/docx/parsers/zip-reader.d.ts +0 -23
  303. package/dist/tools/docx/parsers/zip-reader.js +0 -52
  304. package/dist/tools/docx/read.d.ts +0 -27
  305. package/dist/tools/docx/read.js +0 -308
  306. package/dist/tools/docx/relationships.d.ts +0 -22
  307. package/dist/tools/docx/relationships.js +0 -76
  308. package/dist/tools/docx/structure.d.ts +0 -25
  309. package/dist/tools/docx/structure.js +0 -102
  310. package/dist/tools/docx/styled-html-parser.d.ts +0 -23
  311. package/dist/tools/docx/styled-html-parser.js +0 -1262
  312. package/dist/tools/docx/types.d.ts +0 -213
  313. package/dist/tools/docx/types.js +0 -5
  314. package/dist/tools/docx/utils/escaping.d.ts +0 -13
  315. package/dist/tools/docx/utils/escaping.js +0 -26
  316. package/dist/tools/docx/utils/images.d.ts +0 -9
  317. package/dist/tools/docx/utils/images.js +0 -26
  318. package/dist/tools/docx/utils/index.d.ts +0 -12
  319. package/dist/tools/docx/utils/index.js +0 -17
  320. package/dist/tools/docx/utils/markdown.d.ts +0 -13
  321. package/dist/tools/docx/utils/markdown.js +0 -32
  322. package/dist/tools/docx/utils/paths.d.ts +0 -15
  323. package/dist/tools/docx/utils/paths.js +0 -27
  324. package/dist/tools/docx/utils/versioning.d.ts +0 -25
  325. package/dist/tools/docx/utils/versioning.js +0 -55
  326. package/dist/tools/docx/utils.d.ts +0 -101
  327. package/dist/tools/docx/utils.js +0 -299
  328. package/dist/tools/docx/validate.d.ts +0 -33
  329. package/dist/tools/docx/validate.js +0 -49
  330. package/dist/tools/docx/validators.d.ts +0 -13
  331. package/dist/tools/docx/validators.js +0 -40
  332. package/dist/tools/docx/write.d.ts +0 -17
  333. package/dist/tools/docx/write.js +0 -88
  334. package/dist/tools/docx/xml-view-test.js +0 -63
  335. package/dist/tools/docx/xml-view.d.ts +0 -56
  336. package/dist/tools/docx/xml-view.js +0 -169
  337. package/dist/tools/docx/zip.d.ts +0 -21
  338. package/dist/tools/docx/zip.js +0 -35
  339. package/dist/tools/macos-control/ax-adapter.d.ts +0 -55
  340. package/dist/tools/macos-control/ax-adapter.js +0 -438
  341. package/dist/tools/macos-control/cdp-adapter.d.ts +0 -23
  342. package/dist/tools/macos-control/cdp-adapter.js +0 -402
  343. package/dist/tools/macos-control/orchestrator.d.ts +0 -77
  344. package/dist/tools/macos-control/orchestrator.js +0 -136
  345. package/dist/tools/macos-control/role-aliases.d.ts +0 -5
  346. package/dist/tools/macos-control/role-aliases.js +0 -34
  347. package/dist/tools/macos-control/types.d.ts +0 -129
  348. package/dist/tools/pdf-processor.d.ts +0 -1
  349. package/dist/tools/pdf-processor.js +0 -3
  350. package/dist/tools/search.d.ts +0 -32
  351. package/dist/tools/search.js +0 -202
  352. package/dist/ui/file-preview/src/app.js +0 -714
  353. package/dist/utils/crash-logger.d.ts +0 -18
  354. package/dist/utils/crash-logger.js +0 -44
  355. package/dist/utils/dedent.d.ts +0 -8
  356. package/dist/utils/dedent.js +0 -38
  357. /package/dist/ui/config-editor/{src/app.d.ts → app.d.ts} +0 -0
  358. /package/dist/{http-server-auto-tunnel.d.ts → ui/config-editor/main.d.ts} +0 -0
  359. /package/dist/ui/config-editor/src/{app.js → App.js} +0 -0
  360. /package/dist/{test-docx.d.ts → ui/file-preview/main.d.ts} +0 -0
  361. /package/dist/ui/file-preview/src/components/{toolbar.d.ts → Toolbar.d.ts} +0 -0
  362. /package/dist/ui/file-preview/src/components/{toolbar.js → Toolbar.js} +0 -0
  363. /package/dist/{tools/docx/xml-view-test.d.ts → ui/file-preview/src/model.js} +0 -0
  364. /package/dist/{tools/macos-control → ui/file-preview}/types.js +0 -0
@@ -1,23 +0,0 @@
1
- /**
2
- * ZIP File Reader
3
- * Utilities for reading files from DOCX ZIP archives
4
- */
5
- declare const PizZip: any;
6
- export type ZipArchive = InstanceType<typeof PizZip>;
7
- /**
8
- * Create a ZIP archive from a buffer
9
- */
10
- export declare function createZipFromBuffer(buffer: Buffer): ZipArchive;
11
- /**
12
- * Read a text file from a ZIP archive
13
- */
14
- export declare function readZipFileText(zip: ZipArchive, filePath: string): string | null;
15
- /**
16
- * Read a binary file from a ZIP archive as Buffer
17
- */
18
- export declare function readZipFileBuffer(zip: ZipArchive, filePath: string): Buffer | null;
19
- /**
20
- * Check if a file exists in the ZIP archive
21
- */
22
- export declare function zipFileExists(zip: ZipArchive, filePath: string): boolean;
23
- export {};
@@ -1,52 +0,0 @@
1
- /**
2
- * ZIP File Reader
3
- * Utilities for reading files from DOCX ZIP archives
4
- */
5
- import { createRequire } from 'module';
6
- const require = createRequire(import.meta.url);
7
- const PizZip = require('pizzip');
8
- /**
9
- * Create a ZIP archive from a buffer
10
- */
11
- export function createZipFromBuffer(buffer) {
12
- return new PizZip(buffer);
13
- }
14
- /**
15
- * Read a text file from a ZIP archive
16
- */
17
- export function readZipFileText(zip, filePath) {
18
- const file = zip.file(filePath);
19
- if (!file)
20
- return null;
21
- if (typeof file.asText === 'function') {
22
- return file.asText();
23
- }
24
- if (typeof file.asBinary === 'function') {
25
- return Buffer.from(file.asBinary(), 'binary').toString('utf8');
26
- }
27
- return null;
28
- }
29
- /**
30
- * Read a binary file from a ZIP archive as Buffer
31
- */
32
- export function readZipFileBuffer(zip, filePath) {
33
- const file = zip.file(filePath);
34
- if (!file)
35
- return null;
36
- if (typeof file.asUint8Array === 'function') {
37
- return Buffer.from(file.asUint8Array());
38
- }
39
- if (typeof file.asNodeBuffer === 'function') {
40
- return file.asNodeBuffer();
41
- }
42
- if (typeof file.asBinary === 'function') {
43
- return Buffer.from(file.asBinary(), 'binary');
44
- }
45
- return null;
46
- }
47
- /**
48
- * Check if a file exists in the ZIP archive
49
- */
50
- export function zipFileExists(zip, filePath) {
51
- return zip.file(filePath) !== null;
52
- }
@@ -1,27 +0,0 @@
1
- /**
2
- * DOCX reading utilities
3
- * Extracts text, metadata, and compact outlines from DOCX files.
4
- */
5
- import type { DocxMetadata, DocxParagraph, ReadDocxResult } from './types.js';
6
- /**
7
- * Return a token-efficient outline of a DOCX file.
8
- * Extracts paragraphs, tables (with full cell content), and images (references only, not binary).
9
- * Every element gets a bodyChildIndex (among ALL w:body children).
10
- */
11
- export declare function readDocxOutline(filePath: string): Promise<ReadDocxResult>;
12
- /** Extract plain text from DOCX. */
13
- export declare function extractTextFromDocx(path: string): Promise<string>;
14
- /** Get comprehensive metadata. */
15
- export declare function getDocxMetadata(path: string): Promise<DocxMetadata>;
16
- /** Extract body XML. */
17
- export declare function extractBodyXml(path: string): Promise<string>;
18
- /** Read DOCX file with optional pagination. */
19
- export declare function readDocx(path: string, options?: {
20
- offset?: number;
21
- length?: number;
22
- }): Promise<{
23
- text: string;
24
- paragraphs: DocxParagraph[];
25
- metadata: DocxMetadata;
26
- bodyXml: string;
27
- }>;
@@ -1,308 +0,0 @@
1
- /**
2
- * DOCX reading utilities
3
- * Extracts text, metadata, and compact outlines from DOCX files.
4
- */
5
- import fs from 'fs/promises';
6
- import PizZip from 'pizzip';
7
- import { DOMParser, XMLSerializer } from '@xmldom/xmldom';
8
- import { nodeListToArray, getParagraphText, getParagraphStyle, getBody, getBodyChildren, getAllBodyTables, countImages, getTableContent, getTableStyle, getImageReference, } from './dom.js';
9
- // ═══════════════════════════════════════════════════════════════════════
10
- // Internal helpers
11
- // ═══════════════════════════════════════════════════════════════════════
12
- async function loadDocx(path) {
13
- const inputBuf = await fs.readFile(path);
14
- return new PizZip(inputBuf);
15
- }
16
- // ═══════════════════════════════════════════════════════════════════════
17
- // readDocxOutline — compact JSON outline (used by read_docx tool)
18
- // ═══════════════════════════════════════════════════════════════════════
19
- /**
20
- * Extract image relationship mappings from word/_rels/document.xml.rels.
21
- * Returns a map of rId -> mediaPath (e.g., "rId1" -> "word/media/image1.png").
22
- */
23
- function extractImageRelationships(zip) {
24
- const relsPath = 'word/_rels/document.xml.rels';
25
- const relsFile = zip.file(relsPath);
26
- if (!relsFile)
27
- return new Map();
28
- const relsXml = relsFile.asText();
29
- const relsDom = new DOMParser().parseFromString(relsXml, 'application/xml');
30
- const relationships = relsDom.getElementsByTagName('Relationship');
31
- const imageMap = new Map();
32
- for (const rel of nodeListToArray(relationships)) {
33
- const relEl = rel;
34
- const type = relEl.getAttribute('Type');
35
- const id = relEl.getAttribute('Id');
36
- const target = relEl.getAttribute('Target');
37
- // Check if it's an image relationship
38
- if (type &&
39
- type.includes('/image') &&
40
- id &&
41
- target &&
42
- target.startsWith('media/')) {
43
- imageMap.set(id, `word/${target}`);
44
- }
45
- }
46
- return imageMap;
47
- }
48
- /**
49
- * Extract alt text from wp:docPr/@descr or pic:cNvPr/@descr in a drawing element.
50
- */
51
- function getImageAltText(drawing) {
52
- // Try wp:docPr/@descr first
53
- const docPr = drawing.getElementsByTagName('wp:docPr').item(0);
54
- if (docPr) {
55
- const descr = docPr.getAttribute('descr');
56
- if (descr)
57
- return descr;
58
- }
59
- // Fall back to pic:cNvPr/@descr
60
- const cNvPr = drawing.getElementsByTagName('pic:cNvPr').item(0);
61
- if (cNvPr) {
62
- const descr = cNvPr.getAttribute('descr');
63
- if (descr)
64
- return descr;
65
- }
66
- return undefined;
67
- }
68
- /**
69
- * Return a token-efficient outline of a DOCX file.
70
- * Extracts paragraphs, tables (with full cell content), and images (references only, not binary).
71
- * Every element gets a bodyChildIndex (among ALL w:body children).
72
- */
73
- export async function readDocxOutline(filePath) {
74
- const zip = await loadDocx(filePath);
75
- const docFile = zip.file('word/document.xml');
76
- if (!docFile)
77
- throw new Error('Invalid DOCX: missing word/document.xml');
78
- const xmlStr = docFile.asText();
79
- const dom = new DOMParser().parseFromString(xmlStr, 'application/xml');
80
- const body = getBody(dom);
81
- const children = getBodyChildren(body);
82
- // Extract image relationships (rId -> mediaPath)
83
- const imageRelationships = extractImageRelationships(zip);
84
- const paragraphs = [];
85
- const tables = [];
86
- const images = [];
87
- const stylesSet = new Set();
88
- let paragraphIndex = 0;
89
- let tableIndex = 0;
90
- let imageIndex = 0;
91
- for (let i = 0; i < children.length; i++) {
92
- const child = children[i];
93
- if (child.nodeName === 'w:p') {
94
- // Extract paragraph
95
- const text = getParagraphText(child).trim();
96
- const style = getParagraphStyle(child);
97
- if (style)
98
- stylesSet.add(style);
99
- paragraphs.push({
100
- bodyChildIndex: i,
101
- paragraphIndex,
102
- style,
103
- text,
104
- });
105
- paragraphIndex++;
106
- // Check if paragraph contains an image (w:drawing)
107
- const drawings = child.getElementsByTagName('w:drawing');
108
- for (let d = 0; d < drawings.length; d++) {
109
- const drawing = drawings.item(d);
110
- const imgRef = getImageReference(drawing);
111
- if (imgRef.rId) {
112
- const mediaPath = imageRelationships.get(imgRef.rId);
113
- if (mediaPath) {
114
- const altText = getImageAltText(drawing);
115
- images.push({
116
- bodyChildIndex: i,
117
- imageIndex,
118
- mediaPath,
119
- rId: imgRef.rId,
120
- altText,
121
- });
122
- imageIndex++;
123
- }
124
- }
125
- }
126
- }
127
- else if (child.nodeName === 'w:tbl') {
128
- // Extract table content (direct table in body)
129
- const tableContent = getTableContent(child);
130
- const style = getTableStyle(child);
131
- if (style)
132
- stylesSet.add(style);
133
- tables.push({
134
- bodyChildIndex: i,
135
- tableIndex,
136
- style,
137
- headers: tableContent.headers,
138
- rows: tableContent.rows,
139
- });
140
- tableIndex++;
141
- }
142
- else if (child.nodeName === 'w:sdt') {
143
- // Structured document tag: look inside w:sdtContent for tables that
144
- // are logically at this body position.
145
- const sdtContent = child.getElementsByTagName('w:sdtContent').item(0);
146
- if (sdtContent) {
147
- for (const sdtChild of nodeListToArray(sdtContent.childNodes)) {
148
- if (sdtChild.nodeType === 1 &&
149
- sdtChild.nodeName === 'w:tbl') {
150
- const tbl = sdtChild;
151
- const tableContent = getTableContent(tbl);
152
- const style = getTableStyle(tbl);
153
- if (style)
154
- stylesSet.add(style);
155
- tables.push({
156
- bodyChildIndex: i,
157
- tableIndex,
158
- style,
159
- headers: tableContent.headers,
160
- rows: tableContent.rows,
161
- });
162
- tableIndex++;
163
- }
164
- }
165
- }
166
- }
167
- }
168
- return {
169
- path: filePath,
170
- paragraphs,
171
- tables,
172
- images,
173
- stylesSeen: [...stylesSet].sort(),
174
- counts: {
175
- // Table count should reflect all logical tables, including those
176
- // wrapped in SDTs, so we reuse the same helper used by ops.
177
- tables: getAllBodyTables(body).length,
178
- images: countImages(body),
179
- bodyChildren: children.length,
180
- },
181
- };
182
- }
183
- // ═══════════════════════════════════════════════════════════════════════
184
- // Legacy read functions (used by read_file handler / file handler)
185
- // ═══════════════════════════════════════════════════════════════════════
186
- /** Extract plain text from DOCX. */
187
- export async function extractTextFromDocx(path) {
188
- const zip = await loadDocx(path);
189
- const docFile = zip.file('word/document.xml');
190
- if (!docFile)
191
- throw new Error('Invalid DOCX: missing word/document.xml');
192
- const xmlStr = docFile.asText();
193
- const dom = new DOMParser().parseFromString(xmlStr, 'application/xml');
194
- const body = dom.getElementsByTagName('w:body').item(0);
195
- if (!body)
196
- throw new Error('Invalid DOCX: missing w:body');
197
- const paragraphs = [];
198
- for (const child of nodeListToArray(body.childNodes)) {
199
- if (child.nodeType !== 1)
200
- continue;
201
- if (child.nodeName !== 'w:p')
202
- continue;
203
- const text = getParagraphText(child).trim();
204
- if (text)
205
- paragraphs.push(text);
206
- }
207
- return paragraphs.join('\n\n');
208
- }
209
- /** Extract paragraphs from DOCX. */
210
- async function extractParagraphs(path) {
211
- const zip = await loadDocx(path);
212
- const docFile = zip.file('word/document.xml');
213
- if (!docFile)
214
- throw new Error('Invalid DOCX: missing word/document.xml');
215
- const xmlStr = docFile.asText();
216
- const dom = new DOMParser().parseFromString(xmlStr, 'application/xml');
217
- const body = dom.getElementsByTagName('w:body').item(0);
218
- if (!body)
219
- throw new Error('Invalid DOCX: missing w:body');
220
- const paragraphs = [];
221
- let index = 0;
222
- for (const child of nodeListToArray(body.childNodes)) {
223
- if (child.nodeType !== 1)
224
- continue;
225
- if (child.nodeName !== 'w:p')
226
- continue;
227
- const text = getParagraphText(child).trim();
228
- paragraphs.push({ index, text, hasText: text.length > 0 });
229
- index++;
230
- }
231
- return paragraphs;
232
- }
233
- /** Get core properties from DOCX. */
234
- async function getCoreProperties(zip) {
235
- const corePropsFile = zip.file('docProps/core.xml');
236
- if (!corePropsFile)
237
- return {};
238
- const xmlStr = corePropsFile.asText();
239
- const dom = new DOMParser().parseFromString(xmlStr, 'application/xml');
240
- const getProperty = (name) => {
241
- const elements = dom.getElementsByTagName(name);
242
- if (elements.length > 0)
243
- return elements[0].textContent || undefined;
244
- return undefined;
245
- };
246
- return {
247
- title: getProperty('dc:title'),
248
- author: getProperty('dc:creator'),
249
- subject: getProperty('dc:subject'),
250
- creator: getProperty('cp:creator'),
251
- };
252
- }
253
- /** Get comprehensive metadata. */
254
- export async function getDocxMetadata(path) {
255
- const zip = await loadDocx(path);
256
- const paragraphs = await extractParagraphs(path);
257
- const coreProps = await getCoreProperties(zip);
258
- const fullText = paragraphs.map((p) => p.text).join(' ');
259
- const wordCount = fullText.split(/\s+/).filter((w) => w.length > 0).length;
260
- return { ...coreProps, paragraphCount: paragraphs.length, wordCount };
261
- }
262
- /** Extract body XML. */
263
- export async function extractBodyXml(path) {
264
- const inputBuf = await fs.readFile(path);
265
- const zip = new PizZip(inputBuf);
266
- const docFile = zip.file('word/document.xml');
267
- if (!docFile)
268
- throw new Error('Invalid DOCX: missing word/document.xml');
269
- const xmlStr = docFile.asText();
270
- const dom = new DOMParser().parseFromString(xmlStr, 'application/xml');
271
- const body = dom.getElementsByTagName('w:body').item(0);
272
- if (!body)
273
- throw new Error('Invalid DOCX: missing w:body');
274
- return new XMLSerializer().serializeToString(body);
275
- }
276
- /** Read DOCX file with optional pagination. */
277
- export async function readDocx(path, options) {
278
- const zip = await loadDocx(path);
279
- const docFile = zip.file('word/document.xml');
280
- if (!docFile)
281
- throw new Error('Invalid DOCX: missing word/document.xml');
282
- const xmlStr = docFile.asText();
283
- const dom = new DOMParser().parseFromString(xmlStr, 'application/xml');
284
- const body = dom.getElementsByTagName('w:body').item(0);
285
- if (!body)
286
- throw new Error('Invalid DOCX: missing w:body');
287
- const allParagraphs = [];
288
- let index = 0;
289
- for (const child of nodeListToArray(body.childNodes)) {
290
- if (child.nodeType !== 1)
291
- continue;
292
- if (child.nodeName !== 'w:p')
293
- continue;
294
- const text = getParagraphText(child).trim();
295
- allParagraphs.push({ index, text, hasText: text.length > 0 });
296
- index++;
297
- }
298
- let paragraphs = allParagraphs;
299
- if (options?.offset !== undefined || options?.length !== undefined) {
300
- const offset = options.offset || 0;
301
- const length = options.length !== undefined ? options.length : allParagraphs.length;
302
- paragraphs = allParagraphs.slice(offset, offset + length);
303
- }
304
- const metadata = await getDocxMetadata(path);
305
- const text = paragraphs.map((p) => p.text).join('\n\n');
306
- const bodyXml = new XMLSerializer().serializeToString(body);
307
- return { text, paragraphs, metadata, bodyXml };
308
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * DOCX relationship management — Single Responsibility: manage relationships
3
- * in word/_rels/document.xml.rels and Content_Types.xml.
4
- *
5
- * Used for adding images, hyperlinks, and other external resources.
6
- */
7
- import PizZip from 'pizzip';
8
- /**
9
- * Add an image relationship to word/_rels/document.xml.rels and return the rId.
10
- *
11
- * @param zip The DOCX ZIP archive
12
- * @param mediaFileName The filename in word/media/ (e.g., "image1.png")
13
- * @returns The relationship ID (e.g., "rId1")
14
- */
15
- export declare function addImageRelationship(zip: PizZip, mediaFileName: string): string;
16
- /**
17
- * Ensure the Content_Types.xml has a Default entry for the given file extension.
18
- *
19
- * @param zip The DOCX ZIP archive
20
- * @param ext The file extension (e.g., ".png")
21
- */
22
- export declare function ensureContentType(zip: PizZip, ext: string): void;
@@ -1,76 +0,0 @@
1
- /**
2
- * DOCX relationship management — Single Responsibility: manage relationships
3
- * in word/_rels/document.xml.rels and Content_Types.xml.
4
- *
5
- * Used for adding images, hyperlinks, and other external resources.
6
- */
7
- import { DOMParser, XMLSerializer } from '@xmldom/xmldom';
8
- import { nodeListToArray } from './dom.js';
9
- import { getMimeType } from './constants.js';
10
- import { DOCX_PATHS, NAMESPACES } from './constants.js';
11
- /**
12
- * Add an image relationship to word/_rels/document.xml.rels and return the rId.
13
- *
14
- * @param zip The DOCX ZIP archive
15
- * @param mediaFileName The filename in word/media/ (e.g., "image1.png")
16
- * @returns The relationship ID (e.g., "rId1")
17
- */
18
- export function addImageRelationship(zip, mediaFileName) {
19
- const relsPath = DOCX_PATHS.DOCUMENT_RELS;
20
- let relsEntry = zip.file(relsPath);
21
- // Create .rels file if it doesn't exist
22
- if (!relsEntry) {
23
- const emptyRels = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
24
- `<Relationships xmlns="${NAMESPACES.RELS}"></Relationships>`;
25
- zip.file(relsPath, emptyRels);
26
- relsEntry = zip.file(relsPath);
27
- }
28
- const relsXml = relsEntry.asText();
29
- const relsDom = new DOMParser().parseFromString(relsXml, 'application/xml');
30
- const relationships = relsDom.getElementsByTagName('Relationship');
31
- // Find max existing rId
32
- let maxId = 0;
33
- for (const rel of nodeListToArray(relationships)) {
34
- const id = rel.getAttribute('Id') || '';
35
- const match = id.match(/^rId(\d+)$/);
36
- if (match) {
37
- maxId = Math.max(maxId, parseInt(match[1], 10));
38
- }
39
- }
40
- const newRId = `rId${maxId + 1}`;
41
- // Create new Relationship element
42
- const newRel = relsDom.createElement('Relationship');
43
- newRel.setAttribute('Id', newRId);
44
- newRel.setAttribute('Type', `${NAMESPACES.R}/image`);
45
- newRel.setAttribute('Target', `media/${mediaFileName}`);
46
- relsDom.documentElement.appendChild(newRel);
47
- // Write back
48
- const newRelsXml = new XMLSerializer().serializeToString(relsDom);
49
- zip.file(relsPath, newRelsXml);
50
- return newRId;
51
- }
52
- /**
53
- * Ensure the Content_Types.xml has a Default entry for the given file extension.
54
- *
55
- * @param zip The DOCX ZIP archive
56
- * @param ext The file extension (e.g., ".png")
57
- */
58
- export function ensureContentType(zip, ext) {
59
- const ctPath = DOCX_PATHS.CONTENT_TYPES;
60
- const ctEntry = zip.file(ctPath);
61
- if (!ctEntry)
62
- return;
63
- const ctXml = ctEntry.asText();
64
- const extNoDot = ext.replace(/^\./, '');
65
- // Check if already present
66
- if (ctXml.includes(`Extension="${extNoDot}"`))
67
- return;
68
- const ctDom = new DOMParser().parseFromString(ctXml, 'application/xml');
69
- const types = ctDom.documentElement;
70
- const defaultEl = ctDom.createElement('Default');
71
- defaultEl.setAttribute('Extension', extNoDot);
72
- defaultEl.setAttribute('ContentType', getMimeType(ext));
73
- types.appendChild(defaultEl);
74
- const newCtXml = new XMLSerializer().serializeToString(ctDom);
75
- zip.file(ctPath, newCtXml);
76
- }
@@ -1,25 +0,0 @@
1
- /**
2
- * DOCX Structure Parser and Builder
3
- *
4
- * Provides structure-preserving parsing and building of DOCX files.
5
- * This approach maintains tables, images, and formatting at the DOCX element level,
6
- * avoiding lossy markdown round-trips.
7
- */
8
- import type { DocxStructure, DocxElement } from './types.js';
9
- export type { DocxElement, DocxStructure };
10
- /**
11
- * Parse a DOCX file into structured elements that can be manipulated and rebuilt
12
- *
13
- * @param buffer - DOCX file buffer
14
- * @returns Structured representation of the DOCX document
15
- * @throws {DocxError} If the DOCX file is invalid or cannot be parsed
16
- */
17
- export declare function parseDocxStructure(buffer: Buffer): Promise<DocxStructure>;
18
- /**
19
- * Build a DOCX file from structured elements
20
- *
21
- * @param structure - Structured DOCX representation
22
- * @returns Buffer containing the DOCX file
23
- * @throws {DocxError} If document building fails
24
- */
25
- export declare function buildDocxFromStructure(structure: DocxStructure): Promise<Buffer>;
@@ -1,102 +0,0 @@
1
- /**
2
- * DOCX Structure Parser and Builder
3
- *
4
- * Provides structure-preserving parsing and building of DOCX files.
5
- * This approach maintains tables, images, and formatting at the DOCX element level,
6
- * avoiding lossy markdown round-trips.
7
- */
8
- import { createRequire } from 'module';
9
- const require = createRequire(import.meta.url);
10
- // @ts-ignore
11
- import * as docx from 'docx';
12
- const { Document, Packer } = docx;
13
- import { DocxError, DocxErrorCode, withErrorContext } from './errors.js';
14
- import { createZipFromBuffer, readZipFileText, } from './parsers/zip-reader.js';
15
- import { parseXml, getElementChildren, extractRelationshipMap, getHeadingLevelFromParagraph, } from './parsers/xml-parser.js';
16
- import { extractImagesFromZip } from './parsers/image-extractor.js';
17
- import { parseParagraphElement } from './parsers/paragraph-parser.js';
18
- import { parseTableElement } from './parsers/table-parser.js';
19
- /**
20
- * Parse a DOCX file into structured elements that can be manipulated and rebuilt
21
- *
22
- * @param buffer - DOCX file buffer
23
- * @returns Structured representation of the DOCX document
24
- * @throws {DocxError} If the DOCX file is invalid or cannot be parsed
25
- */
26
- export async function parseDocxStructure(buffer) {
27
- return withErrorContext(async () => {
28
- const zip = createZipFromBuffer(buffer);
29
- const documentXml = readZipFileText(zip, 'word/document.xml');
30
- if (!documentXml) {
31
- throw new DocxError('Invalid DOCX file: word/document.xml not found', DocxErrorCode.INVALID_DOCX, {});
32
- }
33
- const relsXml = readZipFileText(zip, 'word/_rels/document.xml.rels');
34
- const relMap = extractRelationshipMap(relsXml);
35
- // Extract all images
36
- const images = extractImagesFromZip(zip, relMap);
37
- // Parse document body
38
- const doc = parseXml(documentXml);
39
- const body = doc.getElementsByTagName('w:body')[0];
40
- if (!body) {
41
- throw new DocxError('Invalid DOCX file: <w:body> not found', DocxErrorCode.INVALID_DOCX_XML, {});
42
- }
43
- // Parse all elements
44
- const elements = [];
45
- const children = getElementChildren(body);
46
- for (const child of children) {
47
- const nodeName = child.nodeName;
48
- if (nodeName === 'w:p') {
49
- const headingLevel = getHeadingLevelFromParagraph(child);
50
- const para = parseParagraphElement(child, images, headingLevel);
51
- if (para) {
52
- if (headingLevel) {
53
- elements.push({
54
- type: 'heading',
55
- level: headingLevel,
56
- content: para,
57
- });
58
- }
59
- else {
60
- elements.push({
61
- type: 'paragraph',
62
- content: para,
63
- });
64
- }
65
- }
66
- }
67
- else if (nodeName === 'w:tbl') {
68
- const table = parseTableElement(child, images);
69
- if (table) {
70
- elements.push({
71
- type: 'table',
72
- content: table,
73
- });
74
- }
75
- }
76
- }
77
- return {
78
- elements,
79
- images,
80
- relationships: relMap,
81
- };
82
- }, DocxErrorCode.DOCX_READ_FAILED, { bufferSize: buffer.length });
83
- }
84
- /**
85
- * Build a DOCX file from structured elements
86
- *
87
- * @param structure - Structured DOCX representation
88
- * @returns Buffer containing the DOCX file
89
- * @throws {DocxError} If document building fails
90
- */
91
- export async function buildDocxFromStructure(structure) {
92
- return withErrorContext(async () => {
93
- const children = structure.elements.map(el => el.content);
94
- const doc = new Document({
95
- sections: [{
96
- properties: {},
97
- children: children,
98
- }],
99
- });
100
- return await Packer.toBuffer(doc);
101
- }, DocxErrorCode.DOCX_CREATE_FAILED, { elementCount: structure.elements.length });
102
- }
@@ -1,23 +0,0 @@
1
- /**
2
- * Direct DOCX XML → Styled HTML Parser
3
- *
4
- * Parses the raw DOCX XML and produces HTML with full inline style preservation
5
- * (font colours, sizes, families, text alignment, highlights, bold/italic/underline,
6
- * images, hyperlinks, tables, and lists).
7
- *
8
- * mammoth.js deliberately strips visual styling; this parser fills that gap.
9
- *
10
- * @module docx/styled-html-parser
11
- */
12
- import type { DocxImage, DocxDocumentDefaults } from './types.js';
13
- /**
14
- * Convert a DOCX buffer to styled HTML by parsing the DOCX XML directly.
15
- *
16
- * Bypasses mammoth.js to preserve all inline styles (colours, fonts, sizes,
17
- * alignment, highlights, bold/italic/underline, images, hyperlinks, tables).
18
- */
19
- export declare function convertDocxToStyledHtml(buffer: Buffer, includeImages?: boolean): Promise<{
20
- html: string;
21
- images: DocxImage[];
22
- documentDefaults: DocxDocumentDefaults;
23
- }>;