@wonderwhy-er/desktop-commander 0.2.38 → 0.2.40

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 (263) 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 +9 -4
  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/config-editor-runtime.js +65 -14096
  12. package/dist/ui/config-editor/styles.css +2 -1
  13. package/dist/ui/file-preview/preview-runtime.js +435 -26533
  14. package/dist/ui/file-preview/shared/preview-file-types.d.ts +1 -1
  15. package/dist/ui/file-preview/src/app.d.ts +1 -5
  16. package/dist/ui/file-preview/src/app.js +384 -534
  17. package/dist/ui/file-preview/src/components/markdown-renderer.js +47 -9
  18. package/dist/ui/file-preview/src/directory-controller.d.ts +8 -0
  19. package/dist/ui/file-preview/src/directory-controller.js +233 -0
  20. package/dist/ui/file-preview/src/document-layout.d.ts +20 -0
  21. package/dist/ui/file-preview/src/document-layout.js +109 -0
  22. package/dist/ui/file-preview/src/document-outline.d.ts +17 -0
  23. package/dist/ui/file-preview/src/document-outline.js +97 -0
  24. package/dist/ui/file-preview/src/document-workspace.d.ts +19 -0
  25. package/dist/ui/file-preview/src/document-workspace.js +33 -0
  26. package/dist/ui/file-preview/src/file-type-handlers.d.ts +10 -0
  27. package/dist/ui/file-preview/src/file-type-handlers.js +98 -0
  28. package/dist/ui/file-preview/src/host/external-actions.d.ts +19 -0
  29. package/dist/ui/file-preview/src/host/external-actions.js +94 -0
  30. package/dist/ui/file-preview/src/host/selection-context.d.ts +9 -0
  31. package/dist/ui/file-preview/src/host/selection-context.js +106 -0
  32. package/dist/ui/file-preview/src/markdown/conflict-dialog.d.ts +40 -0
  33. package/dist/ui/file-preview/src/markdown/conflict-dialog.js +163 -0
  34. package/dist/ui/file-preview/src/markdown/controller.d.ts +44 -0
  35. package/dist/ui/file-preview/src/markdown/controller.js +1040 -0
  36. package/dist/ui/file-preview/src/markdown/editor.d.ts +131 -0
  37. package/dist/ui/file-preview/src/markdown/editor.js +1479 -0
  38. package/dist/ui/file-preview/src/markdown/linking.d.ts +16 -0
  39. package/dist/ui/file-preview/src/markdown/linking.js +228 -0
  40. package/dist/ui/file-preview/src/markdown/outline.d.ts +2 -0
  41. package/dist/ui/file-preview/src/markdown/outline.js +16 -0
  42. package/dist/ui/file-preview/src/markdown/parser.d.ts +30 -0
  43. package/dist/ui/file-preview/src/markdown/parser.js +38 -0
  44. package/dist/ui/file-preview/src/markdown/preview.d.ts +1 -0
  45. package/dist/ui/file-preview/src/markdown/preview.js +20 -0
  46. package/dist/ui/file-preview/src/markdown/slugify.d.ts +3 -0
  47. package/dist/ui/file-preview/src/markdown/slugify.js +31 -0
  48. package/dist/ui/file-preview/src/markdown/utils.d.ts +1 -0
  49. package/dist/ui/file-preview/src/markdown/utils.js +15 -0
  50. package/dist/ui/file-preview/src/model.d.ts +35 -0
  51. package/dist/ui/file-preview/src/panel-actions.d.ts +17 -0
  52. package/dist/ui/file-preview/src/panel-actions.js +182 -0
  53. package/dist/ui/file-preview/src/path-utils.d.ts +6 -0
  54. package/dist/ui/file-preview/src/path-utils.js +64 -0
  55. package/dist/ui/file-preview/src/payload-utils.d.ts +11 -0
  56. package/dist/ui/file-preview/src/payload-utils.js +94 -0
  57. package/dist/ui/file-preview/styles.css +1066 -233
  58. package/dist/ui/shared/widget-state.d.ts +6 -1
  59. package/dist/ui/shared/widget-state.js +102 -4
  60. package/dist/utils/capture.js +1 -1
  61. package/dist/utils/files/base.d.ts +2 -0
  62. package/dist/utils/open-browser.js +1 -1
  63. package/dist/utils/toolHistory.d.ts +13 -0
  64. package/dist/utils/toolHistory.js +65 -0
  65. package/dist/version.d.ts +1 -1
  66. package/dist/version.js +1 -1
  67. package/package.json +12 -1
  68. package/dist/data/spec-kit-prompts.json +0 -123
  69. package/dist/handlers/macos-control-handlers.d.ts +0 -16
  70. package/dist/handlers/macos-control-handlers.js +0 -81
  71. package/dist/handlers/node-handlers.d.ts +0 -6
  72. package/dist/handlers/node-handlers.js +0 -73
  73. package/dist/handlers/test-crash-handler.d.ts +0 -11
  74. package/dist/handlers/test-crash-handler.js +0 -26
  75. package/dist/http-index.d.ts +0 -45
  76. package/dist/http-index.js +0 -51
  77. package/dist/http-server-auto-tunnel.js +0 -667
  78. package/dist/http-server-named-tunnel.d.ts +0 -2
  79. package/dist/http-server-named-tunnel.js +0 -167
  80. package/dist/http-server-tunnel.d.ts +0 -2
  81. package/dist/http-server-tunnel.js +0 -111
  82. package/dist/http-server.d.ts +0 -2
  83. package/dist/http-server.js +0 -270
  84. package/dist/index-oauth.d.ts +0 -2
  85. package/dist/index-oauth.js +0 -201
  86. package/dist/lib.d.ts +0 -10
  87. package/dist/lib.js +0 -10
  88. package/dist/oauth/auth-middleware.d.ts +0 -20
  89. package/dist/oauth/auth-middleware.js +0 -62
  90. package/dist/oauth/index.d.ts +0 -3
  91. package/dist/oauth/index.js +0 -3
  92. package/dist/oauth/oauth-manager.d.ts +0 -80
  93. package/dist/oauth/oauth-manager.js +0 -179
  94. package/dist/oauth/oauth-routes.d.ts +0 -3
  95. package/dist/oauth/oauth-routes.js +0 -377
  96. package/dist/oauth/provider.d.ts +0 -22
  97. package/dist/oauth/provider.js +0 -124
  98. package/dist/oauth/server.d.ts +0 -18
  99. package/dist/oauth/server.js +0 -160
  100. package/dist/oauth/types.d.ts +0 -54
  101. package/dist/oauth/types.js +0 -2
  102. package/dist/remote-device/templates/auth-success.d.ts +0 -1
  103. package/dist/remote-device/templates/auth-success.js +0 -30
  104. package/dist/setup.log +0 -275
  105. package/dist/test-docx.d.ts +0 -1
  106. package/dist/test-setup.js +0 -14
  107. package/dist/tools/docx/builders/html-builder.d.ts +0 -17
  108. package/dist/tools/docx/builders/html-builder.js +0 -92
  109. package/dist/tools/docx/builders/image.d.ts +0 -14
  110. package/dist/tools/docx/builders/image.js +0 -84
  111. package/dist/tools/docx/builders/index.d.ts +0 -11
  112. package/dist/tools/docx/builders/index.js +0 -11
  113. package/dist/tools/docx/builders/markdown-builder.d.ts +0 -2
  114. package/dist/tools/docx/builders/markdown-builder.js +0 -260
  115. package/dist/tools/docx/builders/paragraph.d.ts +0 -12
  116. package/dist/tools/docx/builders/paragraph.js +0 -29
  117. package/dist/tools/docx/builders/table.d.ts +0 -10
  118. package/dist/tools/docx/builders/table.js +0 -138
  119. package/dist/tools/docx/builders/utils.d.ts +0 -5
  120. package/dist/tools/docx/builders/utils.js +0 -18
  121. package/dist/tools/docx/constants.d.ts +0 -32
  122. package/dist/tools/docx/constants.js +0 -61
  123. package/dist/tools/docx/converters/markdown-to-html.d.ts +0 -17
  124. package/dist/tools/docx/converters/markdown-to-html.js +0 -111
  125. package/dist/tools/docx/create.d.ts +0 -21
  126. package/dist/tools/docx/create.js +0 -386
  127. package/dist/tools/docx/dom.d.ts +0 -139
  128. package/dist/tools/docx/dom.js +0 -448
  129. package/dist/tools/docx/errors.d.ts +0 -28
  130. package/dist/tools/docx/errors.js +0 -48
  131. package/dist/tools/docx/extractors/images.d.ts +0 -14
  132. package/dist/tools/docx/extractors/images.js +0 -40
  133. package/dist/tools/docx/extractors/metadata.d.ts +0 -14
  134. package/dist/tools/docx/extractors/metadata.js +0 -64
  135. package/dist/tools/docx/extractors/sections.d.ts +0 -14
  136. package/dist/tools/docx/extractors/sections.js +0 -61
  137. package/dist/tools/docx/html.d.ts +0 -17
  138. package/dist/tools/docx/html.js +0 -111
  139. package/dist/tools/docx/index.d.ts +0 -10
  140. package/dist/tools/docx/index.js +0 -10
  141. package/dist/tools/docx/markdown.d.ts +0 -84
  142. package/dist/tools/docx/markdown.js +0 -507
  143. package/dist/tools/docx/modify.d.ts +0 -28
  144. package/dist/tools/docx/modify.js +0 -271
  145. package/dist/tools/docx/operations/handlers/index.d.ts +0 -39
  146. package/dist/tools/docx/operations/handlers/index.js +0 -152
  147. package/dist/tools/docx/operations/html-manipulator.d.ts +0 -24
  148. package/dist/tools/docx/operations/html-manipulator.js +0 -352
  149. package/dist/tools/docx/operations/index.d.ts +0 -14
  150. package/dist/tools/docx/operations/index.js +0 -61
  151. package/dist/tools/docx/operations/operation-handlers.d.ts +0 -3
  152. package/dist/tools/docx/operations/operation-handlers.js +0 -67
  153. package/dist/tools/docx/operations/preprocessor.d.ts +0 -14
  154. package/dist/tools/docx/operations/preprocessor.js +0 -44
  155. package/dist/tools/docx/operations/xml-replacer.d.ts +0 -9
  156. package/dist/tools/docx/operations/xml-replacer.js +0 -35
  157. package/dist/tools/docx/operations.d.ts +0 -13
  158. package/dist/tools/docx/operations.js +0 -13
  159. package/dist/tools/docx/ops/delete-paragraph-at-body-index.d.ts +0 -11
  160. package/dist/tools/docx/ops/delete-paragraph-at-body-index.js +0 -23
  161. package/dist/tools/docx/ops/header-replace-text-exact.d.ts +0 -13
  162. package/dist/tools/docx/ops/header-replace-text-exact.js +0 -55
  163. package/dist/tools/docx/ops/index.d.ts +0 -17
  164. package/dist/tools/docx/ops/index.js +0 -70
  165. package/dist/tools/docx/ops/insert-image-after-text.d.ts +0 -24
  166. package/dist/tools/docx/ops/insert-image-after-text.js +0 -128
  167. package/dist/tools/docx/ops/insert-paragraph-after-text.d.ts +0 -12
  168. package/dist/tools/docx/ops/insert-paragraph-after-text.js +0 -74
  169. package/dist/tools/docx/ops/insert-table-after-text.d.ts +0 -19
  170. package/dist/tools/docx/ops/insert-table-after-text.js +0 -57
  171. package/dist/tools/docx/ops/replace-hyperlink-url.d.ts +0 -12
  172. package/dist/tools/docx/ops/replace-hyperlink-url.js +0 -37
  173. package/dist/tools/docx/ops/replace-paragraph-at-body-index.d.ts +0 -9
  174. package/dist/tools/docx/ops/replace-paragraph-at-body-index.js +0 -25
  175. package/dist/tools/docx/ops/replace-paragraph-text-exact.d.ts +0 -21
  176. package/dist/tools/docx/ops/replace-paragraph-text-exact.js +0 -36
  177. package/dist/tools/docx/ops/replace-table-cell-text.d.ts +0 -25
  178. package/dist/tools/docx/ops/replace-table-cell-text.js +0 -85
  179. package/dist/tools/docx/ops/set-color-for-paragraph-exact.d.ts +0 -9
  180. package/dist/tools/docx/ops/set-color-for-paragraph-exact.js +0 -24
  181. package/dist/tools/docx/ops/set-color-for-style.d.ts +0 -13
  182. package/dist/tools/docx/ops/set-color-for-style.js +0 -31
  183. package/dist/tools/docx/ops/set-paragraph-style-at-body-index.d.ts +0 -8
  184. package/dist/tools/docx/ops/set-paragraph-style-at-body-index.js +0 -57
  185. package/dist/tools/docx/ops/table-set-cell-text.d.ts +0 -9
  186. package/dist/tools/docx/ops/table-set-cell-text.js +0 -40
  187. package/dist/tools/docx/parsers/image-extractor.d.ts +0 -18
  188. package/dist/tools/docx/parsers/image-extractor.js +0 -61
  189. package/dist/tools/docx/parsers/index.d.ts +0 -9
  190. package/dist/tools/docx/parsers/index.js +0 -9
  191. package/dist/tools/docx/parsers/paragraph-parser.d.ts +0 -2
  192. package/dist/tools/docx/parsers/paragraph-parser.js +0 -88
  193. package/dist/tools/docx/parsers/table-parser.d.ts +0 -9
  194. package/dist/tools/docx/parsers/table-parser.js +0 -72
  195. package/dist/tools/docx/parsers/xml-parser.d.ts +0 -25
  196. package/dist/tools/docx/parsers/xml-parser.js +0 -71
  197. package/dist/tools/docx/parsers/zip-reader.d.ts +0 -23
  198. package/dist/tools/docx/parsers/zip-reader.js +0 -52
  199. package/dist/tools/docx/read.d.ts +0 -27
  200. package/dist/tools/docx/read.js +0 -308
  201. package/dist/tools/docx/relationships.d.ts +0 -22
  202. package/dist/tools/docx/relationships.js +0 -76
  203. package/dist/tools/docx/structure.d.ts +0 -25
  204. package/dist/tools/docx/structure.js +0 -102
  205. package/dist/tools/docx/styled-html-parser.d.ts +0 -23
  206. package/dist/tools/docx/styled-html-parser.js +0 -1262
  207. package/dist/tools/docx/types.d.ts +0 -213
  208. package/dist/tools/docx/types.js +0 -5
  209. package/dist/tools/docx/utils/escaping.d.ts +0 -13
  210. package/dist/tools/docx/utils/escaping.js +0 -26
  211. package/dist/tools/docx/utils/images.d.ts +0 -9
  212. package/dist/tools/docx/utils/images.js +0 -26
  213. package/dist/tools/docx/utils/index.d.ts +0 -12
  214. package/dist/tools/docx/utils/index.js +0 -17
  215. package/dist/tools/docx/utils/markdown.d.ts +0 -13
  216. package/dist/tools/docx/utils/markdown.js +0 -32
  217. package/dist/tools/docx/utils/paths.d.ts +0 -15
  218. package/dist/tools/docx/utils/paths.js +0 -27
  219. package/dist/tools/docx/utils/versioning.d.ts +0 -25
  220. package/dist/tools/docx/utils/versioning.js +0 -55
  221. package/dist/tools/docx/utils.d.ts +0 -101
  222. package/dist/tools/docx/utils.js +0 -299
  223. package/dist/tools/docx/validate.d.ts +0 -33
  224. package/dist/tools/docx/validate.js +0 -49
  225. package/dist/tools/docx/validators.d.ts +0 -13
  226. package/dist/tools/docx/validators.js +0 -40
  227. package/dist/tools/docx/write.d.ts +0 -17
  228. package/dist/tools/docx/write.js +0 -88
  229. package/dist/tools/docx/xml-view-test.d.ts +0 -1
  230. package/dist/tools/docx/xml-view-test.js +0 -63
  231. package/dist/tools/docx/xml-view.d.ts +0 -56
  232. package/dist/tools/docx/xml-view.js +0 -169
  233. package/dist/tools/docx/zip.d.ts +0 -21
  234. package/dist/tools/docx/zip.js +0 -35
  235. package/dist/tools/macos-control/ax-adapter.d.ts +0 -55
  236. package/dist/tools/macos-control/ax-adapter.js +0 -438
  237. package/dist/tools/macos-control/cdp-adapter.d.ts +0 -23
  238. package/dist/tools/macos-control/cdp-adapter.js +0 -402
  239. package/dist/tools/macos-control/orchestrator.d.ts +0 -77
  240. package/dist/tools/macos-control/orchestrator.js +0 -136
  241. package/dist/tools/macos-control/role-aliases.d.ts +0 -5
  242. package/dist/tools/macos-control/role-aliases.js +0 -34
  243. package/dist/tools/macos-control/types.d.ts +0 -129
  244. package/dist/tools/macos-control/types.js +0 -1
  245. package/dist/tools/pdf-processor.d.ts +0 -1
  246. package/dist/tools/pdf-processor.js +0 -3
  247. package/dist/tools/search.d.ts +0 -32
  248. package/dist/tools/search.js +0 -202
  249. package/dist/ui/file-preview/src/components/toolbar.d.ts +0 -6
  250. package/dist/ui/file-preview/src/components/toolbar.js +0 -75
  251. package/dist/ui/shared/host-lifecycle.d.ts +0 -16
  252. package/dist/ui/shared/host-lifecycle.js +0 -35
  253. package/dist/ui/shared/rpc-client.d.ts +0 -14
  254. package/dist/ui/shared/rpc-client.js +0 -72
  255. package/dist/ui/shared/theme-adaptation.d.ts +0 -10
  256. package/dist/ui/shared/theme-adaptation.js +0 -118
  257. package/dist/ui/shared/tool-header.d.ts +0 -9
  258. package/dist/ui/shared/tool-header.js +0 -25
  259. package/dist/utils/crash-logger.d.ts +0 -18
  260. package/dist/utils/crash-logger.js +0 -44
  261. package/dist/utils/dedent.d.ts +0 -8
  262. package/dist/utils/dedent.js +0 -38
  263. /package/dist/{http-server-auto-tunnel.d.ts → ui/file-preview/src/model.js} +0 -0
@@ -1,85 +0,0 @@
1
- /**
2
- * Op: replace_table_cell_text
3
- *
4
- * Goal: Replace the "logical value" of a cell while preserving layout and styles.
5
- *
6
- * Matching strategy (tried in order):
7
- * 1. Match by full cell text (all paragraphs joined with spaces)
8
- * 2. Match by first paragraph text only
9
- *
10
- * When the caller passes FULL cell text in `from` / `to` (common for LLMs), we
11
- * interpret the change like this:
12
- *
13
- * from: "<OLD_TITLE> <SUBTITLE ...>"
14
- * to: "<NEW_TITLE> <SUBTITLE ...>"
15
- *
16
- * i.e. only the *title* (first paragraph) changed, the rest of the cell content
17
- * stayed the same. We detect the unchanged suffix and compute NEW_TITLE by
18
- * stripping that suffix from `to`. Then we only change the first paragraph text,
19
- * keeping all other paragraphs (subtitle, etc.) exactly as they were.
20
- *
21
- * If we cannot safely detect that pattern, we fall back to treating `from`/`to`
22
- * as simple first‑paragraph values.
23
- */
24
- import { getAllBodyTables, nodeListToArray, getCellText, getParagraphText, setCellTextPreservingStyles } from '../dom.js';
25
- export function applyReplaceTableCellText(body, op) {
26
- const target = op.from.trim();
27
- // Find all logical tables in the body, including those inside SDTs.
28
- const tables = getAllBodyTables(body);
29
- // Search through all tables
30
- for (const table of tables) {
31
- // Get all rows
32
- const rows = [];
33
- for (const child of nodeListToArray(table.childNodes)) {
34
- if (child.nodeType === 1 && child.nodeName === 'w:tr') {
35
- rows.push(child);
36
- }
37
- }
38
- // Search through all cells in all rows
39
- for (const row of rows) {
40
- const cells = [];
41
- for (const child of nodeListToArray(row.childNodes)) {
42
- if (child.nodeType === 1 && child.nodeName === 'w:tc') {
43
- cells.push(child);
44
- }
45
- }
46
- for (const cell of cells) {
47
- const cellText = getCellText(cell).trim();
48
- // Strategy 1: full cell text match — try to detect a "title-only" change
49
- if (cellText === target) {
50
- const paragraphs = cell.getElementsByTagName('w:p');
51
- if (paragraphs.length > 0) {
52
- const firstP = paragraphs.item(0);
53
- const firstPText = getParagraphText(firstP).trim();
54
- // Cell's "suffix" is everything after the first paragraph text
55
- const suffixFrom = cellText.slice(firstPText.length).trimStart();
56
- const toTrimmed = op.to.trim();
57
- let newFirstText = toTrimmed;
58
- if (suffixFrom.length > 0 && toTrimmed.endsWith(suffixFrom)) {
59
- // Common LLM pattern:
60
- // from: "<OLD_TITLE> <SUFFIX>"
61
- // to: "<NEW_TITLE> <SUFFIX>"
62
- // Extract "<NEW_TITLE>" by removing the unchanged suffix.
63
- newFirstText = toTrimmed
64
- .slice(0, toTrimmed.length - suffixFrom.length)
65
- .trimEnd();
66
- }
67
- setCellTextPreservingStyles(cell, newFirstText);
68
- return { op, status: 'applied', matched: 1 };
69
- }
70
- }
71
- // Strategy 2: match by first paragraph text only
72
- const paragraphs = cell.getElementsByTagName('w:p');
73
- if (paragraphs.length > 0) {
74
- const firstP = paragraphs.item(0);
75
- const firstParagraphText = getParagraphText(firstP).trim();
76
- if (firstParagraphText === target) {
77
- setCellTextPreservingStyles(cell, op.to);
78
- return { op, status: 'applied', matched: 1 };
79
- }
80
- }
81
- }
82
- }
83
- }
84
- return { op, status: 'skipped', matched: 0, reason: 'no_match' };
85
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * Op: set_color_for_paragraph_exact
3
- *
4
- * Find FIRST paragraph whose trimmed text === `text` **anywhere in the body**,
5
- * including paragraphs inside tables and other containers.
6
- * Apply run-level colour to every w:r in that paragraph.
7
- */
8
- import type { SetColorForParagraphExactOp, OpResult } from '../types.js';
9
- export declare function applySetColorForParagraphExact(body: Element, op: SetColorForParagraphExactOp): OpResult;
@@ -1,24 +0,0 @@
1
- /**
2
- * Op: set_color_for_paragraph_exact
3
- *
4
- * Find FIRST paragraph whose trimmed text === `text` **anywhere in the body**,
5
- * including paragraphs inside tables and other containers.
6
- * Apply run-level colour to every w:r in that paragraph.
7
- */
8
- import { getParagraphText, ensureRunColor } from '../dom.js';
9
- export function applySetColorForParagraphExact(body, op) {
10
- const target = op.text.trim();
11
- // Traverse **all** paragraphs in the body, not just direct children.
12
- const paragraphs = body.getElementsByTagName('w:p');
13
- for (let i = 0; i < paragraphs.length; i++) {
14
- const p = paragraphs.item(i);
15
- if (getParagraphText(p).trim() !== target)
16
- continue;
17
- const runs = p.getElementsByTagName('w:r');
18
- for (let i = 0; i < runs.length; i++) {
19
- ensureRunColor(runs.item(i), op.color);
20
- }
21
- return { op, status: 'applied', matched: 1 };
22
- }
23
- return { op, status: 'skipped', matched: 0, reason: 'no_match' };
24
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * Op: set_color_for_style
3
- *
4
- * For every paragraph whose w:pPr/w:pStyle/@w:val === style,
5
- * set run-level colour on every w:r in that paragraph.
6
- *
7
- * This now includes paragraphs inside tables and other containers,
8
- * not just direct w:p children of w:body.
9
- *
10
- * Does NOT modify word/styles.xml — only in-document run formatting.
11
- */
12
- import type { SetColorForStyleOp, OpResult } from '../types.js';
13
- export declare function applySetColorForStyle(body: Element, op: SetColorForStyleOp): OpResult;
@@ -1,31 +0,0 @@
1
- /**
2
- * Op: set_color_for_style
3
- *
4
- * For every paragraph whose w:pPr/w:pStyle/@w:val === style,
5
- * set run-level colour on every w:r in that paragraph.
6
- *
7
- * This now includes paragraphs inside tables and other containers,
8
- * not just direct w:p children of w:body.
9
- *
10
- * Does NOT modify word/styles.xml — only in-document run formatting.
11
- */
12
- import { getParagraphStyle, ensureRunColor } from '../dom.js';
13
- export function applySetColorForStyle(body, op) {
14
- // Traverse **all** paragraphs in the body.
15
- const paragraphs = body.getElementsByTagName('w:p');
16
- let matched = 0;
17
- for (let i = 0; i < paragraphs.length; i++) {
18
- const p = paragraphs.item(i);
19
- if (getParagraphStyle(p) !== op.style)
20
- continue;
21
- const runs = p.getElementsByTagName('w:r');
22
- for (let i = 0; i < runs.length; i++) {
23
- ensureRunColor(runs.item(i), op.color);
24
- }
25
- matched++;
26
- }
27
- if (matched === 0) {
28
- return { op, status: 'skipped', matched: 0, reason: 'no_match' };
29
- }
30
- return { op, status: 'applied', matched };
31
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Op: set_paragraph_style_at_body_index
3
- *
4
- * Set (or replace) the paragraph style (w:pPr/w:pStyle) at a given
5
- * bodyChildIndex. Skips if the child is not a w:p.
6
- */
7
- import type { SetParagraphStyleAtBodyIndexOp, OpResult } from '../types.js';
8
- export declare function applySetParagraphStyleAtBodyIndex(body: Element, op: SetParagraphStyleAtBodyIndexOp): OpResult;
@@ -1,57 +0,0 @@
1
- /**
2
- * Op: set_paragraph_style_at_body_index
3
- *
4
- * Set (or replace) the paragraph style (w:pPr/w:pStyle) at a given
5
- * bodyChildIndex. Skips if the child is not a w:p.
6
- */
7
- import { getBodyChildren, nodeListToArray } from '../dom.js';
8
- export function applySetParagraphStyleAtBodyIndex(body, op) {
9
- const children = getBodyChildren(body);
10
- const idx = op.bodyChildIndex;
11
- if (idx < 0 || idx >= children.length) {
12
- return { op, status: 'skipped', matched: 0, reason: 'index_out_of_range' };
13
- }
14
- const child = children[idx];
15
- if (child.nodeName !== 'w:p') {
16
- return { op, status: 'skipped', matched: 0, reason: 'not_a_paragraph' };
17
- }
18
- const doc = child.ownerDocument;
19
- if (!doc)
20
- return { op, status: 'skipped', matched: 0, reason: 'no_owner_document' };
21
- // Find or create w:pPr
22
- let pPr = null;
23
- for (const n of nodeListToArray(child.childNodes)) {
24
- if (n.nodeType === 1 && n.nodeName === 'w:pPr') {
25
- pPr = n;
26
- break;
27
- }
28
- }
29
- if (!pPr) {
30
- pPr = doc.createElement('w:pPr');
31
- if (child.firstChild) {
32
- child.insertBefore(pPr, child.firstChild);
33
- }
34
- else {
35
- child.appendChild(pPr);
36
- }
37
- }
38
- // Find or create w:pStyle inside pPr
39
- let pStyle = null;
40
- for (const n of nodeListToArray(pPr.childNodes)) {
41
- if (n.nodeType === 1 && n.nodeName === 'w:pStyle') {
42
- pStyle = n;
43
- break;
44
- }
45
- }
46
- if (!pStyle) {
47
- pStyle = doc.createElement('w:pStyle');
48
- if (pPr.firstChild) {
49
- pPr.insertBefore(pStyle, pPr.firstChild);
50
- }
51
- else {
52
- pPr.appendChild(pStyle);
53
- }
54
- }
55
- pStyle.setAttribute('w:val', op.style);
56
- return { op, status: 'applied', matched: 1 };
57
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * Op: table_set_cell_text
3
- *
4
- * Set the text content of a specific table cell.
5
- * Targets by: tableIndex (0-based among w:tbl in body), row, col.
6
- * Applies minimal text replacement inside the cell's first paragraph.
7
- */
8
- import type { TableSetCellTextOp, OpResult } from '../types.js';
9
- export declare function applyTableSetCellText(body: Element, op: TableSetCellTextOp): OpResult;
@@ -1,40 +0,0 @@
1
- /**
2
- * Op: table_set_cell_text
3
- *
4
- * Set the text content of a specific table cell.
5
- * Targets by: tableIndex (0-based among w:tbl in body), row, col.
6
- * Applies minimal text replacement inside the cell's first paragraph.
7
- */
8
- import { getAllBodyTables, nodeListToArray, setCellTextPreservingStyles } from '../dom.js';
9
- export function applyTableSetCellText(body, op) {
10
- // Find the n‑th logical table in the body, including tables inside SDTs.
11
- const tables = getAllBodyTables(body);
12
- if (op.tableIndex < 0 || op.tableIndex >= tables.length) {
13
- return { op, status: 'skipped', matched: 0, reason: 'table_not_found' };
14
- }
15
- const table = tables[op.tableIndex];
16
- // Find the n-th w:tr
17
- const rows = [];
18
- for (const child of nodeListToArray(table.childNodes)) {
19
- if (child.nodeType === 1 && child.nodeName === 'w:tr') {
20
- rows.push(child);
21
- }
22
- }
23
- if (op.row < 0 || op.row >= rows.length) {
24
- return { op, status: 'skipped', matched: 0, reason: 'row_out_of_range' };
25
- }
26
- // Find the n-th w:tc in the row
27
- const cells = [];
28
- for (const child of nodeListToArray(rows[op.row].childNodes)) {
29
- if (child.nodeType === 1 && child.nodeName === 'w:tc') {
30
- cells.push(child);
31
- }
32
- }
33
- if (op.col < 0 || op.col >= cells.length) {
34
- return { op, status: 'skipped', matched: 0, reason: 'col_out_of_range' };
35
- }
36
- const cell = cells[op.col];
37
- // Replace cell text while preserving ALL styles (colors, bold, italic, etc.)
38
- setCellTextPreservingStyles(cell, op.text);
39
- return { op, status: 'applied', matched: 1 };
40
- }
@@ -1,18 +0,0 @@
1
- /**
2
- * Image Extractor
3
- * Utilities for extracting and handling images from DOCX files
4
- */
5
- import type { ZipArchive } from './zip-reader.js';
6
- import type { DocxRelationship } from '../types.js';
7
- /**
8
- * Get MIME type from file extension or target path
9
- */
10
- export declare function getMimeTypeForTarget(target: string): string;
11
- /**
12
- * Extract all images from a DOCX ZIP archive
13
- */
14
- export declare function extractImagesFromZip(zip: ZipArchive, relMap: Map<string, DocxRelationship>): Map<string, Buffer>;
15
- /**
16
- * Resolve image relationship ID from drawing or pict element
17
- */
18
- export declare function resolveImageRelId(element: Element): string | null;
@@ -1,61 +0,0 @@
1
- /**
2
- * Image Extractor
3
- * Utilities for extracting and handling images from DOCX files
4
- */
5
- import path from 'path';
6
- import { readZipFileBuffer } from './zip-reader.js';
7
- /**
8
- * Get MIME type from file extension or target path
9
- */
10
- export function getMimeTypeForTarget(target) {
11
- const ext = path.extname(target).toLowerCase();
12
- const mimeTypes = {
13
- '.png': 'image/png',
14
- '.jpg': 'image/jpeg',
15
- '.jpeg': 'image/jpeg',
16
- '.gif': 'image/gif',
17
- '.bmp': 'image/bmp',
18
- '.webp': 'image/webp',
19
- '.svg': 'image/svg+xml',
20
- };
21
- return mimeTypes[ext] || 'application/octet-stream';
22
- }
23
- /**
24
- * Extract all images from a DOCX ZIP archive
25
- */
26
- export function extractImagesFromZip(zip, relMap) {
27
- const images = new Map();
28
- for (const [relId, rel] of relMap.entries()) {
29
- if (!rel.type.includes('/image'))
30
- continue;
31
- const targetPath = rel.target.startsWith('word/')
32
- ? rel.target
33
- : `word/${rel.target.replace(/^\/?/, '')}`;
34
- const imgBuffer = readZipFileBuffer(zip, targetPath);
35
- if (imgBuffer) {
36
- images.set(relId, imgBuffer);
37
- }
38
- }
39
- return images;
40
- }
41
- /**
42
- * Resolve image relationship ID from drawing or pict element
43
- */
44
- export function resolveImageRelId(element) {
45
- // Try drawing element first (newer format)
46
- const blips = element.getElementsByTagName('a:blip');
47
- for (let i = 0; i < blips.length; i++) {
48
- const blip = blips[i];
49
- const relId = blip.getAttribute('r:embed') || blip.getAttribute('embed');
50
- if (relId)
51
- return relId;
52
- }
53
- // Try pict element (older format)
54
- const imagedata = element.getElementsByTagName('v:imagedata');
55
- for (let i = 0; i < imagedata.length; i++) {
56
- const relId = imagedata[i].getAttribute('r:id') || imagedata[i].getAttribute('id');
57
- if (relId)
58
- return relId;
59
- }
60
- return null;
61
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * DOCX Parsers
3
- * Centralized exports for all parsing utilities
4
- */
5
- export * from './zip-reader.js';
6
- export * from './xml-parser.js';
7
- export * from './image-extractor.js';
8
- export * from './paragraph-parser.js';
9
- export * from './table-parser.js';
@@ -1,9 +0,0 @@
1
- /**
2
- * DOCX Parsers
3
- * Centralized exports for all parsing utilities
4
- */
5
- export * from './zip-reader.js';
6
- export * from './xml-parser.js';
7
- export * from './image-extractor.js';
8
- export * from './paragraph-parser.js';
9
- export * from './table-parser.js';
@@ -1,2 +0,0 @@
1
- import type { DocxParagraph } from '../types.js';
2
- export declare function parseParagraphElement(paragraph: Element, images: Map<string, Buffer>, headingLevel: number | null): DocxParagraph | null;
@@ -1,88 +0,0 @@
1
- import { createRequire } from 'module';
2
- const require = createRequire(import.meta.url);
3
- // @ts-ignore
4
- import * as docx from 'docx';
5
- const { Paragraph, TextRun, ImageRun, HeadingLevel } = docx;
6
- import { getElementChildren } from './xml-parser.js';
7
- import { resolveImageRelId } from './image-extractor.js';
8
- export function parseParagraphElement(paragraph, images, headingLevel) {
9
- const runs = extractRunsFromParagraph(paragraph, images);
10
- if (runs.length === 0) {
11
- return null;
12
- }
13
- return new Paragraph({
14
- children: runs,
15
- heading: headingLevel ? getDocxHeadingLevel(headingLevel) : undefined,
16
- });
17
- }
18
- function extractRunsFromParagraph(paragraph, images) {
19
- const runs = [];
20
- const children = getElementChildren(paragraph);
21
- for (const child of children) {
22
- const nodeName = child.nodeName;
23
- if (nodeName === 'w:r') {
24
- const textRuns = extractTextRun(child, images);
25
- runs.push(...textRuns);
26
- }
27
- else if (nodeName === 'w:hyperlink') {
28
- const linkRuns = child.getElementsByTagName('w:r');
29
- for (let i = 0; i < linkRuns.length; i++) {
30
- const textRuns = extractTextRun(linkRuns[i], images);
31
- runs.push(...textRuns);
32
- }
33
- }
34
- }
35
- return runs;
36
- }
37
- function extractTextRun(run, images) {
38
- const runs = [];
39
- const rPr = run.getElementsByTagName('w:rPr')[0];
40
- const isBold = rPr?.getElementsByTagName('w:b').length > 0;
41
- const isItalic = rPr?.getElementsByTagName('w:i').length > 0;
42
- const children = getElementChildren(run);
43
- for (const child of children) {
44
- const nodeName = child.nodeName;
45
- if (nodeName === 'w:t') {
46
- const text = child.textContent || '';
47
- if (text) {
48
- runs.push(new TextRun({
49
- text,
50
- bold: isBold,
51
- italics: isItalic,
52
- }));
53
- }
54
- }
55
- else if (nodeName === 'w:tab') {
56
- runs.push(new TextRun({ text: '\t' }));
57
- }
58
- else if (nodeName === 'w:br') {
59
- runs.push(new TextRun({ text: '\n', break: 1 }));
60
- }
61
- else if (nodeName === 'w:drawing' || nodeName === 'w:pict') {
62
- const relId = resolveImageRelId(child);
63
- if (relId && images.has(relId)) {
64
- try {
65
- runs.push(new ImageRun({
66
- data: images.get(relId),
67
- transformation: { width: 600, height: 400 },
68
- }));
69
- }
70
- catch (err) {
71
- // Skip invalid images
72
- }
73
- }
74
- }
75
- }
76
- return runs;
77
- }
78
- function getDocxHeadingLevel(level) {
79
- const levelMap = {
80
- 1: HeadingLevel.HEADING_1,
81
- 2: HeadingLevel.HEADING_2,
82
- 3: HeadingLevel.HEADING_3,
83
- 4: HeadingLevel.HEADING_4,
84
- 5: HeadingLevel.HEADING_5,
85
- 6: HeadingLevel.HEADING_6,
86
- };
87
- return levelMap[level] ?? HeadingLevel.HEADING_1;
88
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * Table Parser
3
- * Parses DOCX table elements to DOCX library Table objects
4
- */
5
- import type { DocxTable } from '../types.js';
6
- /**
7
- * Parse a table element to DOCX Table
8
- */
9
- export declare function parseTableElement(table: Element, images: Map<string, Buffer>): DocxTable | null;
@@ -1,72 +0,0 @@
1
- /**
2
- * Table Parser
3
- * Parses DOCX table elements to DOCX library Table objects
4
- */
5
- import { createRequire } from 'module';
6
- const require = createRequire(import.meta.url);
7
- // @ts-ignore
8
- import * as docx from 'docx';
9
- const { Table, TableRow, TableCell, Paragraph, WidthType } = docx;
10
- import { parseParagraphElement } from './paragraph-parser.js';
11
- /**
12
- * Parse a table element to DOCX Table
13
- */
14
- export function parseTableElement(table, images) {
15
- const rows = [];
16
- const rowNodes = table.getElementsByTagName('w:tr');
17
- for (let i = 0; i < rowNodes.length; i++) {
18
- const rowNode = rowNodes[i];
19
- const row = parseTableRow(rowNode, images);
20
- if (row) {
21
- rows.push(row);
22
- }
23
- }
24
- if (rows.length === 0) {
25
- return null;
26
- }
27
- return new Table({
28
- width: { size: 100, type: WidthType.PERCENTAGE },
29
- rows,
30
- });
31
- }
32
- /**
33
- * Parse a table row element
34
- */
35
- function parseTableRow(rowNode, images) {
36
- const cells = [];
37
- const cellNodes = rowNode.getElementsByTagName('w:tc');
38
- for (let j = 0; j < cellNodes.length; j++) {
39
- const cellNode = cellNodes[j];
40
- const cell = parseTableCell(cellNode, images);
41
- if (cell) {
42
- cells.push(cell);
43
- }
44
- }
45
- if (cells.length === 0) {
46
- return null;
47
- }
48
- return new TableRow({
49
- children: cells,
50
- });
51
- }
52
- /**
53
- * Parse a table cell element
54
- */
55
- function parseTableCell(cellNode, images) {
56
- const cellParagraphs = [];
57
- const paragraphNodes = cellNode.getElementsByTagName('w:p');
58
- for (let k = 0; k < paragraphNodes.length; k++) {
59
- const paraNode = paragraphNodes[k];
60
- const para = parseParagraphElement(paraNode, images, null);
61
- if (para) {
62
- cellParagraphs.push(para);
63
- }
64
- }
65
- // Ensure at least one paragraph per cell
66
- if (cellParagraphs.length === 0) {
67
- cellParagraphs.push(new Paragraph({ text: '' }));
68
- }
69
- return new TableCell({
70
- children: cellParagraphs,
71
- });
72
- }
@@ -1,25 +0,0 @@
1
- /**
2
- * XML Parser Utilities
3
- * Helper functions for parsing DOCX XML content
4
- */
5
- import type { DocxRelationship } from '../types.js';
6
- /**
7
- * Get all element children of a node
8
- */
9
- export declare function getElementChildren(node: Node): Element[];
10
- /**
11
- * Get attribute value, checking both direct and namespaced attributes
12
- */
13
- export declare function getAttributeValue(node: Element, name: string): string | null;
14
- /**
15
- * Parse XML string to Document
16
- */
17
- export declare function parseXml(xml: string): Document;
18
- /**
19
- * Extract relationship map from relationships XML
20
- */
21
- export declare function extractRelationshipMap(relsXml: string | null): Map<string, DocxRelationship>;
22
- /**
23
- * Get heading level from paragraph element
24
- */
25
- export declare function getHeadingLevelFromParagraph(paragraph: Element): number | null;
@@ -1,71 +0,0 @@
1
- /**
2
- * XML Parser Utilities
3
- * Helper functions for parsing DOCX XML content
4
- */
5
- import { createRequire } from 'module';
6
- const require = createRequire(import.meta.url);
7
- const { DOMParser } = require('@xmldom/xmldom');
8
- /**
9
- * Get all element children of a node
10
- */
11
- export function getElementChildren(node) {
12
- const children = [];
13
- for (let i = 0; i < node.childNodes.length; i++) {
14
- const child = node.childNodes[i];
15
- if (child.nodeType === 1) { // ELEMENT_NODE
16
- children.push(child);
17
- }
18
- }
19
- return children;
20
- }
21
- /**
22
- * Get attribute value, checking both direct and namespaced attributes
23
- */
24
- export function getAttributeValue(node, name) {
25
- return node.getAttribute(name) || node.getAttribute(`w:${name}`) || null;
26
- }
27
- /**
28
- * Parse XML string to Document
29
- */
30
- export function parseXml(xml) {
31
- const parser = new DOMParser();
32
- return parser.parseFromString(xml, 'application/xml');
33
- }
34
- /**
35
- * Extract relationship map from relationships XML
36
- */
37
- export function extractRelationshipMap(relsXml) {
38
- const relMap = new Map();
39
- if (!relsXml)
40
- return relMap;
41
- const relDoc = parseXml(relsXml);
42
- const rels = relDoc.getElementsByTagName('Relationship');
43
- for (let i = 0; i < rels.length; i++) {
44
- const rel = rels[i];
45
- const id = rel.getAttribute('Id');
46
- const type = rel.getAttribute('Type') || '';
47
- const target = rel.getAttribute('Target') || '';
48
- if (id && target) {
49
- relMap.set(id, { target, type });
50
- }
51
- }
52
- return relMap;
53
- }
54
- /**
55
- * Get heading level from paragraph element
56
- */
57
- export function getHeadingLevelFromParagraph(paragraph) {
58
- const pPr = paragraph.getElementsByTagName('w:pPr')[0];
59
- if (!pPr)
60
- return null;
61
- const pStyle = pPr.getElementsByTagName('w:pStyle')[0];
62
- if (!pStyle)
63
- return null;
64
- const styleVal = getAttributeValue(pStyle, 'val');
65
- if (!styleVal)
66
- return null;
67
- const match = styleVal.match(/heading\s*([1-6])/i);
68
- if (!match)
69
- return null;
70
- return Number(match[1]);
71
- }