@wonderwhy-er/desktop-commander 0.2.37 → 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.
- package/README.md +290 -100
- package/dist/command-manager.js +6 -3
- package/dist/config-field-definitions.d.ts +41 -0
- package/dist/config-field-definitions.js +37 -0
- package/dist/config-manager.d.ts +2 -0
- package/dist/config-manager.js +22 -2
- package/dist/handlers/filesystem-handlers.d.ts +5 -0
- package/dist/handlers/filesystem-handlers.js +19 -12
- package/dist/remote-device/desktop-commander-integration.js +1 -1
- package/dist/remote-device/remote-channel.js +1 -1
- package/dist/search-manager.js +31 -38
- package/dist/server.js +11 -4
- package/dist/terminal-manager.js +4 -2
- package/dist/tools/config.d.ts +71 -0
- package/dist/tools/config.js +117 -2
- package/dist/tools/edit.js +34 -1
- package/dist/tools/filesystem.js +91 -3
- package/dist/tools/improved-process-tools.js +2 -1
- package/dist/tools/schemas.d.ts +3 -0
- package/dist/tools/schemas.js +1 -0
- package/dist/types.d.ts +0 -1
- package/dist/ui/config-editor/app.d.ts +43 -0
- package/dist/ui/config-editor/app.js +840 -0
- package/dist/ui/config-editor/array-modal.d.ts +19 -0
- package/dist/ui/config-editor/array-modal.js +185 -0
- package/dist/ui/config-editor/config-editor-runtime.js +150 -0
- package/dist/ui/config-editor/index.html +13 -0
- package/dist/ui/config-editor/main.js +2 -0
- package/dist/ui/config-editor/src/App.d.ts +43 -0
- package/dist/ui/config-editor/src/App.js +840 -0
- package/dist/ui/config-editor/src/array-modal.d.ts +19 -0
- package/dist/ui/config-editor/src/array-modal.js +185 -0
- package/dist/ui/config-editor/src/components/layout.d.ts +4 -0
- package/dist/ui/config-editor/src/components/layout.js +83 -0
- package/dist/ui/config-editor/src/components/toolbar.d.ts +1 -0
- package/dist/ui/config-editor/src/components/toolbar.js +21 -0
- package/dist/ui/config-editor/src/config-values.d.ts +6 -0
- package/dist/ui/config-editor/src/config-values.js +61 -0
- package/dist/ui/config-editor/src/contracts.d.ts +14 -0
- package/dist/ui/config-editor/src/contracts.js +3 -0
- package/dist/ui/config-editor/src/directory-browser.d.ts +6 -0
- package/dist/ui/config-editor/src/directory-browser.js +71 -0
- package/dist/ui/config-editor/src/layout.d.ts +5 -0
- package/dist/ui/config-editor/src/layout.js +90 -0
- package/dist/ui/config-editor/src/main.js +2 -0
- package/dist/ui/config-editor/src/parsing.d.ts +5 -0
- package/dist/ui/config-editor/src/parsing.js +50 -0
- package/dist/ui/config-editor/src/toolbar.d.ts +1 -0
- package/dist/ui/config-editor/src/toolbar.js +18 -0
- package/dist/ui/config-editor/src/types.d.ts +17 -0
- package/dist/ui/config-editor/src/types.js +3 -0
- package/dist/ui/config-editor/src/utils/config-values.d.ts +9 -0
- package/dist/ui/config-editor/src/utils/config-values.js +61 -0
- package/dist/ui/config-editor/src/utils/directory-browser.d.ts +31 -0
- package/dist/ui/config-editor/src/utils/directory-browser.js +201 -0
- package/dist/ui/config-editor/src/utils/parsing.d.ts +8 -0
- package/dist/ui/config-editor/src/utils/parsing.js +50 -0
- package/dist/ui/config-editor/styles.css +587 -0
- package/dist/ui/file-preview/app.d.ts +8 -0
- package/dist/ui/file-preview/app.js +2020 -0
- package/dist/ui/file-preview/components/code-viewer.d.ts +6 -0
- package/dist/ui/file-preview/components/code-viewer.js +73 -0
- package/dist/ui/file-preview/components/highlighting.d.ts +2 -0
- package/dist/ui/file-preview/components/highlighting.js +54 -0
- package/dist/ui/file-preview/components/html-renderer.d.ts +5 -0
- package/dist/ui/file-preview/components/html-renderer.js +47 -0
- package/dist/ui/file-preview/components/markdown-renderer.d.ts +1 -0
- package/dist/ui/file-preview/components/markdown-renderer.js +67 -0
- package/dist/ui/file-preview/components/toolbar.d.ts +6 -0
- package/dist/ui/file-preview/components/toolbar.js +75 -0
- package/dist/ui/file-preview/image-preview.d.ts +3 -0
- package/dist/ui/file-preview/image-preview.js +21 -0
- package/dist/ui/file-preview/main.js +5 -0
- package/dist/ui/file-preview/markdown/editor.d.ts +36 -0
- package/dist/ui/file-preview/markdown/editor.js +643 -0
- package/dist/ui/file-preview/markdown/linking.d.ts +9 -0
- package/dist/ui/file-preview/markdown/linking.js +210 -0
- package/dist/ui/file-preview/markdown/outline.d.ts +7 -0
- package/dist/ui/file-preview/markdown/outline.js +40 -0
- package/dist/ui/file-preview/markdown/preview.d.ts +8 -0
- package/dist/ui/file-preview/markdown/preview.js +33 -0
- package/dist/ui/file-preview/markdown/slugify.d.ts +3 -0
- package/dist/ui/file-preview/markdown/slugify.js +31 -0
- package/dist/ui/file-preview/markdown/toc.d.ts +11 -0
- package/dist/ui/file-preview/markdown/toc.js +75 -0
- package/dist/ui/file-preview/markdown/utils.d.ts +1 -0
- package/dist/ui/file-preview/markdown/utils.js +15 -0
- package/dist/ui/file-preview/markdown/workspace-controller.d.ts +25 -0
- package/dist/ui/file-preview/markdown/workspace-controller.js +40 -0
- package/dist/ui/file-preview/preview-runtime.js +399 -13969
- package/dist/ui/file-preview/shared/preview-file-types.d.ts +1 -1
- package/dist/ui/file-preview/shared/preview-file-types.js +3 -1
- package/dist/ui/file-preview/src/App.d.ts +4 -0
- package/dist/ui/file-preview/src/App.js +564 -0
- package/dist/ui/file-preview/src/components/CodeViewer.d.ts +6 -0
- package/dist/ui/file-preview/src/components/CodeViewer.js +60 -0
- package/dist/ui/file-preview/src/components/HtmlRenderer.d.ts +8 -0
- package/dist/ui/file-preview/src/components/HtmlRenderer.js +45 -0
- package/dist/ui/file-preview/src/components/MarkdownRenderer.d.ts +1 -0
- package/dist/ui/file-preview/src/components/MarkdownRenderer.js +15 -0
- package/dist/ui/file-preview/src/components/editor-toolbar.d.ts +15 -0
- package/dist/ui/file-preview/src/components/editor-toolbar.js +384 -0
- package/dist/ui/file-preview/src/components/html-renderer.d.ts +1 -5
- package/dist/ui/file-preview/src/components/html-renderer.js +11 -27
- package/dist/ui/file-preview/src/components/markdown-editor.d.ts +29 -0
- package/dist/ui/file-preview/src/components/markdown-editor.js +535 -0
- package/dist/ui/file-preview/src/components/markdown-renderer.js +47 -9
- package/dist/ui/file-preview/src/directory-controller.d.ts +8 -0
- package/dist/ui/file-preview/src/directory-controller.js +233 -0
- package/dist/ui/file-preview/src/document-layout.d.ts +20 -0
- package/dist/ui/file-preview/src/document-layout.js +109 -0
- package/dist/ui/file-preview/src/document-outline.d.ts +17 -0
- package/dist/ui/file-preview/src/document-outline.js +97 -0
- package/dist/ui/file-preview/src/document-workspace.d.ts +19 -0
- package/dist/ui/file-preview/src/document-workspace.js +33 -0
- package/dist/ui/file-preview/src/file-type-handlers.d.ts +10 -0
- package/dist/ui/file-preview/src/file-type-handlers.js +98 -0
- package/dist/ui/file-preview/src/host/external-actions.d.ts +19 -0
- package/dist/ui/file-preview/src/host/external-actions.js +94 -0
- package/dist/ui/file-preview/src/host/selection-context.d.ts +9 -0
- package/dist/ui/file-preview/src/host/selection-context.js +106 -0
- package/dist/ui/file-preview/src/markdown/block-merge.d.ts +25 -0
- package/dist/ui/file-preview/src/markdown/block-merge.js +86 -0
- package/dist/ui/file-preview/src/markdown/conflict-dialog.d.ts +40 -0
- package/dist/ui/file-preview/src/markdown/conflict-dialog.js +163 -0
- package/dist/ui/file-preview/src/markdown/controller.d.ts +38 -0
- package/dist/ui/file-preview/src/markdown/controller.js +921 -0
- package/dist/ui/file-preview/src/markdown/editor.d.ts +35 -0
- package/dist/ui/file-preview/src/markdown/editor.js +691 -0
- package/dist/ui/file-preview/src/markdown/link-modal.d.ts +13 -0
- package/dist/ui/file-preview/src/markdown/link-modal.js +213 -0
- package/dist/ui/file-preview/src/markdown/linking.d.ts +16 -0
- package/dist/ui/file-preview/src/markdown/linking.js +228 -0
- package/dist/ui/file-preview/src/markdown/outline.d.ts +2 -0
- package/dist/ui/file-preview/src/markdown/outline.js +16 -0
- package/dist/ui/file-preview/src/markdown/parser.d.ts +30 -0
- package/dist/ui/file-preview/src/markdown/parser.js +38 -0
- package/dist/ui/file-preview/src/markdown/preview.d.ts +1 -0
- package/dist/ui/file-preview/src/markdown/preview.js +20 -0
- package/dist/ui/file-preview/src/markdown/raw-editor.d.ts +8 -0
- package/dist/ui/file-preview/src/markdown/raw-editor.js +61 -0
- package/dist/ui/file-preview/src/markdown/selection-toolbar.d.ts +14 -0
- package/dist/ui/file-preview/src/markdown/selection-toolbar.js +128 -0
- package/dist/ui/file-preview/src/markdown/slugify.d.ts +3 -0
- package/dist/ui/file-preview/src/markdown/slugify.js +31 -0
- package/dist/ui/file-preview/src/markdown/toc.d.ts +11 -0
- package/dist/ui/file-preview/src/markdown/toc.js +75 -0
- package/dist/ui/file-preview/src/markdown/utils.d.ts +1 -0
- package/dist/ui/file-preview/src/markdown/utils.js +15 -0
- package/dist/ui/file-preview/src/markdown-workspace/editor.d.ts +36 -0
- package/dist/ui/file-preview/src/markdown-workspace/editor.js +643 -0
- package/dist/ui/file-preview/src/markdown-workspace/linking.d.ts +9 -0
- package/dist/ui/file-preview/src/markdown-workspace/linking.js +210 -0
- package/dist/ui/file-preview/src/markdown-workspace/outline.d.ts +7 -0
- package/dist/ui/file-preview/src/markdown-workspace/outline.js +40 -0
- package/dist/ui/file-preview/src/markdown-workspace/preview.d.ts +8 -0
- package/dist/ui/file-preview/src/markdown-workspace/preview.js +33 -0
- package/dist/ui/file-preview/src/markdown-workspace/slugify.d.ts +3 -0
- package/dist/ui/file-preview/src/markdown-workspace/slugify.js +31 -0
- package/dist/ui/file-preview/src/markdown-workspace/toc.d.ts +11 -0
- package/dist/ui/file-preview/src/markdown-workspace/toc.js +75 -0
- package/dist/ui/file-preview/src/markdown-workspace/utils.d.ts +1 -0
- package/dist/ui/file-preview/src/markdown-workspace/utils.js +15 -0
- package/dist/ui/file-preview/src/markdown-workspace/workspace-controller.d.ts +25 -0
- package/dist/ui/file-preview/src/markdown-workspace/workspace-controller.js +40 -0
- package/dist/ui/file-preview/src/model.d.ts +34 -0
- package/dist/ui/file-preview/src/panel-actions.d.ts +17 -0
- package/dist/ui/file-preview/src/panel-actions.js +182 -0
- package/dist/ui/file-preview/src/path-utils.d.ts +6 -0
- package/dist/ui/file-preview/src/path-utils.js +64 -0
- package/dist/ui/file-preview/src/payload-utils.d.ts +11 -0
- package/dist/ui/file-preview/src/payload-utils.js +94 -0
- package/dist/ui/file-preview/styles.css +1144 -277
- package/dist/ui/file-preview/types.d.ts +1 -0
- package/dist/ui/file-preview/types.js +1 -0
- package/dist/ui/resources.d.ts +7 -0
- package/dist/ui/resources.js +16 -2
- package/dist/ui/server-integration.d.ts +13 -0
- package/dist/ui/server-integration.js +31 -0
- package/dist/ui/shared/ToolHeader.d.ts +9 -0
- package/dist/ui/shared/ToolHeader.js +29 -0
- package/dist/ui/shared/app-bootstrap.d.ts +9 -0
- package/dist/ui/shared/app-bootstrap.js +15 -0
- package/dist/ui/shared/compact-row.d.ts +11 -0
- package/dist/ui/shared/compact-row.js +18 -0
- package/dist/ui/shared/guards.d.ts +1 -0
- package/dist/ui/shared/guards.js +3 -0
- package/dist/ui/shared/host-context.d.ts +15 -0
- package/dist/ui/shared/host-context.js +51 -0
- package/dist/ui/shared/host-lifecycle.d.ts +1 -0
- package/dist/ui/shared/host-lifecycle.js +8 -2
- package/dist/ui/shared/tool-bridge.d.ts +30 -0
- package/dist/ui/shared/tool-bridge.js +137 -0
- package/dist/ui/shared/tool-shell.d.ts +9 -0
- package/dist/ui/shared/tool-shell.js +46 -4
- package/dist/ui/shared/ui-event-tracker.d.ts +9 -0
- package/dist/ui/shared/ui-event-tracker.js +27 -0
- package/dist/ui/shared/widget-state.d.ts +6 -1
- package/dist/ui/shared/widget-state.js +102 -4
- package/dist/utils/capture.js +3 -3
- package/dist/utils/files/base.d.ts +2 -0
- package/dist/utils/open-browser.js +1 -1
- package/dist/utils/ui-call-context.d.ts +8 -0
- package/dist/utils/ui-call-context.js +72 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +13 -4
- package/dist/data/spec-kit-prompts.json +0 -123
- package/dist/handlers/node-handlers.d.ts +0 -6
- package/dist/handlers/node-handlers.js +0 -73
- package/dist/handlers/test-crash-handler.d.ts +0 -11
- package/dist/handlers/test-crash-handler.js +0 -26
- package/dist/http-index.d.ts +0 -45
- package/dist/http-index.js +0 -51
- package/dist/http-server-auto-tunnel.js +0 -667
- package/dist/http-server-named-tunnel.d.ts +0 -2
- package/dist/http-server-named-tunnel.js +0 -167
- package/dist/http-server-tunnel.d.ts +0 -2
- package/dist/http-server-tunnel.js +0 -111
- package/dist/http-server.d.ts +0 -2
- package/dist/http-server.js +0 -270
- package/dist/index-oauth.d.ts +0 -2
- package/dist/index-oauth.js +0 -201
- package/dist/oauth/auth-middleware.d.ts +0 -20
- package/dist/oauth/auth-middleware.js +0 -62
- package/dist/oauth/index.d.ts +0 -3
- package/dist/oauth/index.js +0 -3
- package/dist/oauth/oauth-manager.d.ts +0 -80
- package/dist/oauth/oauth-manager.js +0 -179
- package/dist/oauth/oauth-routes.d.ts +0 -3
- package/dist/oauth/oauth-routes.js +0 -377
- package/dist/oauth/provider.d.ts +0 -22
- package/dist/oauth/provider.js +0 -124
- package/dist/oauth/server.d.ts +0 -18
- package/dist/oauth/server.js +0 -160
- package/dist/oauth/types.d.ts +0 -54
- package/dist/oauth/types.js +0 -2
- package/dist/remote-device/templates/auth-success.d.ts +0 -1
- package/dist/remote-device/templates/auth-success.js +0 -30
- package/dist/setup.log +0 -275
- package/dist/test-setup.js +0 -14
- package/dist/tools/docx/builders/html-builder.d.ts +0 -17
- package/dist/tools/docx/builders/html-builder.js +0 -92
- package/dist/tools/docx/builders/image.d.ts +0 -14
- package/dist/tools/docx/builders/image.js +0 -84
- package/dist/tools/docx/builders/index.d.ts +0 -11
- package/dist/tools/docx/builders/index.js +0 -11
- package/dist/tools/docx/builders/markdown-builder.d.ts +0 -2
- package/dist/tools/docx/builders/markdown-builder.js +0 -260
- package/dist/tools/docx/builders/paragraph.d.ts +0 -12
- package/dist/tools/docx/builders/paragraph.js +0 -29
- package/dist/tools/docx/builders/table.d.ts +0 -10
- package/dist/tools/docx/builders/table.js +0 -138
- package/dist/tools/docx/builders/utils.d.ts +0 -5
- package/dist/tools/docx/builders/utils.js +0 -18
- package/dist/tools/docx/constants.d.ts +0 -32
- package/dist/tools/docx/constants.js +0 -61
- package/dist/tools/docx/converters/markdown-to-html.d.ts +0 -17
- package/dist/tools/docx/converters/markdown-to-html.js +0 -111
- package/dist/tools/docx/create.d.ts +0 -21
- package/dist/tools/docx/create.js +0 -386
- package/dist/tools/docx/dom.d.ts +0 -139
- package/dist/tools/docx/dom.js +0 -448
- package/dist/tools/docx/errors.d.ts +0 -28
- package/dist/tools/docx/errors.js +0 -48
- package/dist/tools/docx/extractors/images.d.ts +0 -14
- package/dist/tools/docx/extractors/images.js +0 -40
- package/dist/tools/docx/extractors/metadata.d.ts +0 -14
- package/dist/tools/docx/extractors/metadata.js +0 -64
- package/dist/tools/docx/extractors/sections.d.ts +0 -14
- package/dist/tools/docx/extractors/sections.js +0 -61
- package/dist/tools/docx/html.d.ts +0 -17
- package/dist/tools/docx/html.js +0 -111
- package/dist/tools/docx/index.d.ts +0 -10
- package/dist/tools/docx/index.js +0 -10
- package/dist/tools/docx/markdown.d.ts +0 -84
- package/dist/tools/docx/markdown.js +0 -507
- package/dist/tools/docx/modify.d.ts +0 -28
- package/dist/tools/docx/modify.js +0 -271
- package/dist/tools/docx/operations/handlers/index.d.ts +0 -39
- package/dist/tools/docx/operations/handlers/index.js +0 -152
- package/dist/tools/docx/operations/html-manipulator.d.ts +0 -24
- package/dist/tools/docx/operations/html-manipulator.js +0 -352
- package/dist/tools/docx/operations/index.d.ts +0 -14
- package/dist/tools/docx/operations/index.js +0 -61
- package/dist/tools/docx/operations/operation-handlers.d.ts +0 -3
- package/dist/tools/docx/operations/operation-handlers.js +0 -67
- package/dist/tools/docx/operations/preprocessor.d.ts +0 -14
- package/dist/tools/docx/operations/preprocessor.js +0 -44
- package/dist/tools/docx/operations/xml-replacer.d.ts +0 -9
- package/dist/tools/docx/operations/xml-replacer.js +0 -35
- package/dist/tools/docx/operations.d.ts +0 -13
- package/dist/tools/docx/operations.js +0 -13
- package/dist/tools/docx/ops/delete-paragraph-at-body-index.d.ts +0 -11
- package/dist/tools/docx/ops/delete-paragraph-at-body-index.js +0 -23
- package/dist/tools/docx/ops/header-replace-text-exact.d.ts +0 -13
- package/dist/tools/docx/ops/header-replace-text-exact.js +0 -55
- package/dist/tools/docx/ops/index.d.ts +0 -17
- package/dist/tools/docx/ops/index.js +0 -70
- package/dist/tools/docx/ops/insert-image-after-text.d.ts +0 -24
- package/dist/tools/docx/ops/insert-image-after-text.js +0 -128
- package/dist/tools/docx/ops/insert-paragraph-after-text.d.ts +0 -12
- package/dist/tools/docx/ops/insert-paragraph-after-text.js +0 -74
- package/dist/tools/docx/ops/insert-table-after-text.d.ts +0 -19
- package/dist/tools/docx/ops/insert-table-after-text.js +0 -57
- package/dist/tools/docx/ops/replace-hyperlink-url.d.ts +0 -12
- package/dist/tools/docx/ops/replace-hyperlink-url.js +0 -37
- package/dist/tools/docx/ops/replace-paragraph-at-body-index.d.ts +0 -9
- package/dist/tools/docx/ops/replace-paragraph-at-body-index.js +0 -25
- package/dist/tools/docx/ops/replace-paragraph-text-exact.d.ts +0 -21
- package/dist/tools/docx/ops/replace-paragraph-text-exact.js +0 -36
- package/dist/tools/docx/ops/replace-table-cell-text.d.ts +0 -25
- package/dist/tools/docx/ops/replace-table-cell-text.js +0 -85
- package/dist/tools/docx/ops/set-color-for-paragraph-exact.d.ts +0 -9
- package/dist/tools/docx/ops/set-color-for-paragraph-exact.js +0 -24
- package/dist/tools/docx/ops/set-color-for-style.d.ts +0 -13
- package/dist/tools/docx/ops/set-color-for-style.js +0 -31
- package/dist/tools/docx/ops/set-paragraph-style-at-body-index.d.ts +0 -8
- package/dist/tools/docx/ops/set-paragraph-style-at-body-index.js +0 -57
- package/dist/tools/docx/ops/table-set-cell-text.d.ts +0 -9
- package/dist/tools/docx/ops/table-set-cell-text.js +0 -40
- package/dist/tools/docx/parsers/image-extractor.d.ts +0 -18
- package/dist/tools/docx/parsers/image-extractor.js +0 -61
- package/dist/tools/docx/parsers/index.d.ts +0 -9
- package/dist/tools/docx/parsers/index.js +0 -9
- package/dist/tools/docx/parsers/paragraph-parser.d.ts +0 -2
- package/dist/tools/docx/parsers/paragraph-parser.js +0 -88
- package/dist/tools/docx/parsers/table-parser.d.ts +0 -9
- package/dist/tools/docx/parsers/table-parser.js +0 -72
- package/dist/tools/docx/parsers/xml-parser.d.ts +0 -25
- package/dist/tools/docx/parsers/xml-parser.js +0 -71
- package/dist/tools/docx/parsers/zip-reader.d.ts +0 -23
- package/dist/tools/docx/parsers/zip-reader.js +0 -52
- package/dist/tools/docx/read.d.ts +0 -27
- package/dist/tools/docx/read.js +0 -308
- package/dist/tools/docx/relationships.d.ts +0 -22
- package/dist/tools/docx/relationships.js +0 -76
- package/dist/tools/docx/structure.d.ts +0 -25
- package/dist/tools/docx/structure.js +0 -102
- package/dist/tools/docx/styled-html-parser.d.ts +0 -23
- package/dist/tools/docx/styled-html-parser.js +0 -1262
- package/dist/tools/docx/types.d.ts +0 -213
- package/dist/tools/docx/types.js +0 -5
- package/dist/tools/docx/utils/escaping.d.ts +0 -13
- package/dist/tools/docx/utils/escaping.js +0 -26
- package/dist/tools/docx/utils/images.d.ts +0 -9
- package/dist/tools/docx/utils/images.js +0 -26
- package/dist/tools/docx/utils/index.d.ts +0 -12
- package/dist/tools/docx/utils/index.js +0 -17
- package/dist/tools/docx/utils/markdown.d.ts +0 -13
- package/dist/tools/docx/utils/markdown.js +0 -32
- package/dist/tools/docx/utils/paths.d.ts +0 -15
- package/dist/tools/docx/utils/paths.js +0 -27
- package/dist/tools/docx/utils/versioning.d.ts +0 -25
- package/dist/tools/docx/utils/versioning.js +0 -55
- package/dist/tools/docx/utils.d.ts +0 -101
- package/dist/tools/docx/utils.js +0 -299
- package/dist/tools/docx/validate.d.ts +0 -33
- package/dist/tools/docx/validate.js +0 -49
- package/dist/tools/docx/validators.d.ts +0 -13
- package/dist/tools/docx/validators.js +0 -40
- package/dist/tools/docx/write.d.ts +0 -17
- package/dist/tools/docx/write.js +0 -88
- package/dist/tools/docx/xml-view-test.js +0 -63
- package/dist/tools/docx/xml-view.d.ts +0 -56
- package/dist/tools/docx/xml-view.js +0 -169
- package/dist/tools/docx/zip.d.ts +0 -21
- package/dist/tools/docx/zip.js +0 -35
- package/dist/tools/pdf-processor.js +0 -3
- package/dist/tools/search.d.ts +0 -32
- package/dist/tools/search.js +0 -202
- package/dist/ui/file-preview/src/app.d.ts +0 -4
- package/dist/ui/file-preview/src/app.js +0 -800
- package/dist/utils/crash-logger.d.ts +0 -18
- package/dist/utils/crash-logger.js +0 -44
- package/dist/utils/dedent.d.ts +0 -8
- package/dist/utils/dedent.js +0 -38
- /package/dist/{http-server-auto-tunnel.d.ts → ui/config-editor/main.d.ts} +0 -0
- /package/dist/{test-docx.d.ts → ui/config-editor/src/main.d.ts} +0 -0
- /package/dist/{tools/docx/xml-view-test.d.ts → ui/file-preview/main.d.ts} +0 -0
- /package/dist/ui/file-preview/src/components/{toolbar.d.ts → Toolbar.d.ts} +0 -0
- /package/dist/ui/file-preview/src/components/{toolbar.js → Toolbar.js} +0 -0
- /package/dist/{tools/pdf-processor.d.ts → ui/file-preview/src/model.js} +0 -0
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Legacy DOCX modification operations.
|
|
3
|
-
*
|
|
4
|
-
* These functions support the older write_file / edit_block paths that
|
|
5
|
-
* modify DOCX via simple operations (replace, insert, delete, style).
|
|
6
|
-
* They are distinct from the new patch-based writeDocxPatched pipeline.
|
|
7
|
-
*
|
|
8
|
-
* Single Responsibility: create / modify DOCX content using the legacy
|
|
9
|
-
* DocxModification interface. Delegates XML parsing and element
|
|
10
|
-
* manipulation to the shared dom.ts module.
|
|
11
|
-
*/
|
|
12
|
-
import fs from 'fs/promises';
|
|
13
|
-
import path from 'path';
|
|
14
|
-
import os from 'os';
|
|
15
|
-
import PizZip from 'pizzip';
|
|
16
|
-
import { DOMParser, XMLSerializer } from '@xmldom/xmldom';
|
|
17
|
-
import { nodeListToArray, getParagraphText, setParagraphTextMinimal, colorParagraphRuns, styleParagraphRuns, } from './dom.js';
|
|
18
|
-
// ═══════════════════════════════════════════════════════════════════════
|
|
19
|
-
// Helpers (private to this module)
|
|
20
|
-
// ═══════════════════════════════════════════════════════════════════════
|
|
21
|
-
/** Get all direct w:p children of body in document order. */
|
|
22
|
-
function getParagraphs(body) {
|
|
23
|
-
const paragraphs = [];
|
|
24
|
-
for (const child of nodeListToArray(body.childNodes)) {
|
|
25
|
-
if (child.nodeType === 1 && child.nodeName === 'w:p') {
|
|
26
|
-
paragraphs.push(child);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return paragraphs;
|
|
30
|
-
}
|
|
31
|
-
/** Parse DOCX and return { zip, dom, body }. */
|
|
32
|
-
function parseDocument(inputBuf) {
|
|
33
|
-
const zip = new PizZip(inputBuf);
|
|
34
|
-
const docFile = zip.file('word/document.xml');
|
|
35
|
-
if (!docFile)
|
|
36
|
-
throw new Error('Invalid DOCX: missing word/document.xml');
|
|
37
|
-
const dom = new DOMParser().parseFromString(docFile.asText(), 'application/xml');
|
|
38
|
-
const body = dom.getElementsByTagName('w:body').item(0);
|
|
39
|
-
if (!body)
|
|
40
|
-
throw new Error('Invalid DOCX: missing w:body');
|
|
41
|
-
return { zip, dom, body };
|
|
42
|
-
}
|
|
43
|
-
// ═══════════════════════════════════════════════════════════════════════
|
|
44
|
-
// modifyDocxContent — apply legacy modifications
|
|
45
|
-
// ═══════════════════════════════════════════════════════════════════════
|
|
46
|
-
/**
|
|
47
|
-
* Open an existing DOCX, apply an ordered list of modifications to
|
|
48
|
-
* word/document.xml, and write the result to outputPath.
|
|
49
|
-
* Every other file in the ZIP (styles, images, rels, …) is preserved.
|
|
50
|
-
*/
|
|
51
|
-
export async function modifyDocxContent(inputPath, outputPath, modifications) {
|
|
52
|
-
const inputBuf = await fs.readFile(inputPath);
|
|
53
|
-
const { zip, dom, body } = parseDocument(inputBuf);
|
|
54
|
-
for (const mod of modifications) {
|
|
55
|
-
switch (mod.type) {
|
|
56
|
-
case 'replace':
|
|
57
|
-
applyReplace(body, mod);
|
|
58
|
-
break;
|
|
59
|
-
case 'insert':
|
|
60
|
-
applyInsert(body, mod);
|
|
61
|
-
break;
|
|
62
|
-
case 'delete':
|
|
63
|
-
applyDelete(body, mod);
|
|
64
|
-
break;
|
|
65
|
-
case 'style':
|
|
66
|
-
applyStyle(body, mod);
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
const outXml = new XMLSerializer().serializeToString(dom);
|
|
71
|
-
zip.file('word/document.xml', outXml);
|
|
72
|
-
const outBuf = zip.generate({ type: 'nodebuffer' });
|
|
73
|
-
await fs.writeFile(outputPath, outBuf);
|
|
74
|
-
}
|
|
75
|
-
// ═══════════════════════════════════════════════════════════════════════
|
|
76
|
-
// replaceBodyXml — wholesale body replacement
|
|
77
|
-
// ═══════════════════════════════════════════════════════════════════════
|
|
78
|
-
/**
|
|
79
|
-
* Replace the entire w:body content of a DOCX with new body XML.
|
|
80
|
-
* Used by the body-XML replacement mode of write_file.
|
|
81
|
-
*/
|
|
82
|
-
export async function replaceBodyXml(inputPath, outputPath, newBodyXml) {
|
|
83
|
-
const tempDir = os.tmpdir();
|
|
84
|
-
const tempDocxPath = path.join(tempDir, `docx_temp_${Date.now()}_${Math.random().toString(36).substring(7)}.docx`);
|
|
85
|
-
const tempXmlPath = path.join(tempDir, `docx_dom_${Date.now()}_${Math.random().toString(36).substring(7)}.xml`);
|
|
86
|
-
try {
|
|
87
|
-
const inputBuf = await fs.readFile(inputPath);
|
|
88
|
-
await fs.writeFile(tempDocxPath, inputBuf);
|
|
89
|
-
const { zip, dom, body } = parseDocument(inputBuf);
|
|
90
|
-
await fs.writeFile(tempXmlPath, zip.file('word/document.xml').asText());
|
|
91
|
-
// Parse the new body XML
|
|
92
|
-
const newBodyDom = new DOMParser().parseFromString(`<root>${newBodyXml}</root>`, 'application/xml');
|
|
93
|
-
const newBodyElement = newBodyDom.documentElement.firstChild;
|
|
94
|
-
if (!newBodyElement || newBodyElement.nodeName !== 'w:body') {
|
|
95
|
-
throw new Error('Invalid body XML: must start with <w:body>');
|
|
96
|
-
}
|
|
97
|
-
// Import children from new body into original document
|
|
98
|
-
const doc = body.ownerDocument;
|
|
99
|
-
if (!doc)
|
|
100
|
-
throw new Error('Document owner not found');
|
|
101
|
-
while (body.firstChild)
|
|
102
|
-
body.removeChild(body.firstChild);
|
|
103
|
-
for (const child of nodeListToArray(newBodyElement.childNodes)) {
|
|
104
|
-
body.appendChild(doc.importNode(child, true));
|
|
105
|
-
}
|
|
106
|
-
const outXml = new XMLSerializer().serializeToString(dom);
|
|
107
|
-
zip.file('word/document.xml', outXml);
|
|
108
|
-
const outBuf = zip.generate({ type: 'nodebuffer' });
|
|
109
|
-
await fs.writeFile(outputPath, outBuf);
|
|
110
|
-
}
|
|
111
|
-
finally {
|
|
112
|
-
try {
|
|
113
|
-
await fs.unlink(tempDocxPath);
|
|
114
|
-
}
|
|
115
|
-
catch { /* ignore */ }
|
|
116
|
-
try {
|
|
117
|
-
await fs.unlink(tempXmlPath);
|
|
118
|
-
}
|
|
119
|
-
catch { /* ignore */ }
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
// ═══════════════════════════════════════════════════════════════════════
|
|
123
|
-
// writeDocx — create minimal DOCX from plain text
|
|
124
|
-
// ═══════════════════════════════════════════════════════════════════════
|
|
125
|
-
/**
|
|
126
|
-
* Create a brand-new minimal DOCX from a plain-text string.
|
|
127
|
-
* Double-newlines are treated as paragraph separators.
|
|
128
|
-
*/
|
|
129
|
-
export async function writeDocx(outputPath, content) {
|
|
130
|
-
if (typeof content !== 'string') {
|
|
131
|
-
throw new Error('Modifications require an existing DOCX file. Use modifyDocxContent() instead.');
|
|
132
|
-
}
|
|
133
|
-
const zip = new PizZip();
|
|
134
|
-
const escaped = (s) => s.replace(/&/g, '&')
|
|
135
|
-
.replace(/</g, '<')
|
|
136
|
-
.replace(/>/g, '>')
|
|
137
|
-
.replace(/"/g, '"')
|
|
138
|
-
.replace(/'/g, ''');
|
|
139
|
-
const docXml = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
140
|
-
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
|
|
141
|
-
<w:body>
|
|
142
|
-
${content
|
|
143
|
-
.split('\n\n')
|
|
144
|
-
.map((para) => ` <w:p>
|
|
145
|
-
<w:r>
|
|
146
|
-
<w:t>${escaped(para)}</w:t>
|
|
147
|
-
</w:r>
|
|
148
|
-
</w:p>`)
|
|
149
|
-
.join('\n')}
|
|
150
|
-
</w:body>
|
|
151
|
-
</w:document>`;
|
|
152
|
-
zip.file('word/document.xml', docXml);
|
|
153
|
-
zip.file('[Content_Types].xml', `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
154
|
-
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
|
|
155
|
-
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
|
|
156
|
-
<Default Extension="xml" ContentType="application/xml"/>
|
|
157
|
-
<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
|
|
158
|
-
</Types>`);
|
|
159
|
-
zip.folder('_rels')?.file('.rels', `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
160
|
-
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
|
161
|
-
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
|
|
162
|
-
</Relationships>`);
|
|
163
|
-
zip.folder('word')?.folder('_rels')?.file('document.xml.rels', `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
164
|
-
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
|
165
|
-
</Relationships>`);
|
|
166
|
-
const outBuf = zip.generate({ type: 'nodebuffer' });
|
|
167
|
-
await fs.writeFile(outputPath, outBuf);
|
|
168
|
-
}
|
|
169
|
-
// ═══════════════════════════════════════════════════════════════════════
|
|
170
|
-
// Private modification appliers (SRP: one function per modification type)
|
|
171
|
-
// ═══════════════════════════════════════════════════════════════════════
|
|
172
|
-
function applyReplace(body, mod) {
|
|
173
|
-
if (mod.findText === undefined)
|
|
174
|
-
return;
|
|
175
|
-
const target = mod.findText.trim();
|
|
176
|
-
for (const child of nodeListToArray(body.childNodes)) {
|
|
177
|
-
if (child.nodeType !== 1 || child.nodeName !== 'w:p')
|
|
178
|
-
continue;
|
|
179
|
-
if (getParagraphText(child).trim() !== target)
|
|
180
|
-
continue;
|
|
181
|
-
if (mod.replaceText !== undefined) {
|
|
182
|
-
setParagraphTextMinimal(child, mod.replaceText);
|
|
183
|
-
}
|
|
184
|
-
if (mod.style) {
|
|
185
|
-
if (mod.style.color)
|
|
186
|
-
colorParagraphRuns(child, mod.style.color);
|
|
187
|
-
if (mod.style.bold !== undefined || mod.style.italic !== undefined) {
|
|
188
|
-
styleParagraphRuns(child, mod.style);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
break; // first match only
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
function applyInsert(body, mod) {
|
|
195
|
-
if (mod.paragraphIndex === undefined || mod.insertText === undefined)
|
|
196
|
-
return;
|
|
197
|
-
const doc = body.ownerDocument;
|
|
198
|
-
if (!doc)
|
|
199
|
-
return;
|
|
200
|
-
const newP = doc.createElement('w:p');
|
|
201
|
-
const newR = doc.createElement('w:r');
|
|
202
|
-
const newT = doc.createElement('w:t');
|
|
203
|
-
newT.textContent = mod.insertText;
|
|
204
|
-
newR.appendChild(newT);
|
|
205
|
-
newP.appendChild(newR);
|
|
206
|
-
const paragraphs = getParagraphs(body);
|
|
207
|
-
const idx = mod.paragraphIndex < 0
|
|
208
|
-
? paragraphs.length + mod.paragraphIndex + 1
|
|
209
|
-
: mod.paragraphIndex;
|
|
210
|
-
if (idx < 0 || idx > paragraphs.length)
|
|
211
|
-
return;
|
|
212
|
-
if (idx === paragraphs.length) {
|
|
213
|
-
body.appendChild(newP);
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
let current = 0;
|
|
217
|
-
for (const child of nodeListToArray(body.childNodes)) {
|
|
218
|
-
if (child.nodeType !== 1 || child.nodeName !== 'w:p')
|
|
219
|
-
continue;
|
|
220
|
-
if (current === idx) {
|
|
221
|
-
body.insertBefore(newP, child);
|
|
222
|
-
break;
|
|
223
|
-
}
|
|
224
|
-
current++;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
function applyDelete(body, mod) {
|
|
229
|
-
if (mod.paragraphIndex === undefined)
|
|
230
|
-
return;
|
|
231
|
-
const paragraphs = getParagraphs(body);
|
|
232
|
-
const idx = mod.paragraphIndex < 0
|
|
233
|
-
? paragraphs.length + mod.paragraphIndex
|
|
234
|
-
: mod.paragraphIndex;
|
|
235
|
-
if (idx < 0 || idx >= paragraphs.length)
|
|
236
|
-
return;
|
|
237
|
-
let current = 0;
|
|
238
|
-
for (const child of nodeListToArray(body.childNodes)) {
|
|
239
|
-
if (child.nodeType !== 1 || child.nodeName !== 'w:p')
|
|
240
|
-
continue;
|
|
241
|
-
if (current === idx) {
|
|
242
|
-
body.removeChild(child);
|
|
243
|
-
break;
|
|
244
|
-
}
|
|
245
|
-
current++;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
function applyStyle(body, mod) {
|
|
249
|
-
if (mod.paragraphIndex === undefined || !mod.style)
|
|
250
|
-
return;
|
|
251
|
-
const paragraphs = getParagraphs(body);
|
|
252
|
-
const idx = mod.paragraphIndex < 0
|
|
253
|
-
? paragraphs.length + mod.paragraphIndex
|
|
254
|
-
: mod.paragraphIndex;
|
|
255
|
-
if (idx < 0 || idx >= paragraphs.length)
|
|
256
|
-
return;
|
|
257
|
-
let current = 0;
|
|
258
|
-
for (const child of nodeListToArray(body.childNodes)) {
|
|
259
|
-
if (child.nodeType !== 1 || child.nodeName !== 'w:p')
|
|
260
|
-
continue;
|
|
261
|
-
if (current === idx) {
|
|
262
|
-
if (mod.style.color)
|
|
263
|
-
colorParagraphRuns(child, mod.style.color);
|
|
264
|
-
if (mod.style.bold !== undefined || mod.style.italic !== undefined) {
|
|
265
|
-
styleParagraphRuns(child, mod.style);
|
|
266
|
-
}
|
|
267
|
-
break;
|
|
268
|
-
}
|
|
269
|
-
current++;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DOCX Operation Handlers
|
|
3
|
-
*
|
|
4
|
-
* Pure functions: HTML in → modified HTML out.
|
|
5
|
-
* Each handler corresponds to one DocxOperation type.
|
|
6
|
-
*
|
|
7
|
-
* @module docx/operations/handlers
|
|
8
|
-
*/
|
|
9
|
-
import type { DocxOperation } from '../../types.js';
|
|
10
|
-
/**
|
|
11
|
-
* Replace text in HTML while protecting base64 data URLs and other attribute values.
|
|
12
|
-
*
|
|
13
|
-
* Strategy: Temporarily extract `<img>` tags (which contain huge base64 data URLs)
|
|
14
|
-
* and replace them with placeholders, perform the text replacement,
|
|
15
|
-
* then restore the original `<img>` tags. This prevents the regex from
|
|
16
|
-
* accidentally matching / corrupting base64 image data.
|
|
17
|
-
*/
|
|
18
|
-
export declare function handleReplaceText(html: string, search: string, replace: string, matchCase?: boolean, global?: boolean): string;
|
|
19
|
-
export declare function handleAppendMarkdown(html: string, markdown: string): string;
|
|
20
|
-
export declare function handleAppendHtml(html: string, content: string): string;
|
|
21
|
-
export declare function handleInsertHtml(html: string, content: string, selector?: string, position?: 'before' | 'after' | 'inside'): string;
|
|
22
|
-
export declare function handleReplaceHtml(html: string, selector: string, content: string, replaceAll?: boolean): string;
|
|
23
|
-
export declare function handleUpdateHtml(html: string, selector: string, content?: string, attributes?: Record<string, string>, updateAll?: boolean): string;
|
|
24
|
-
/**
|
|
25
|
-
* Insert a table from markdown or a rows array.
|
|
26
|
-
* If a selector is given, the table is placed relative to that element;
|
|
27
|
-
* otherwise it is appended to the end of the document.
|
|
28
|
-
*/
|
|
29
|
-
export declare function handleInsertTable(html: string, markdownTable?: string, rows?: string[][], selector?: string, position?: 'before' | 'after' | 'inside'): string;
|
|
30
|
-
/**
|
|
31
|
-
* Insert an image into the document.
|
|
32
|
-
*
|
|
33
|
-
* By the time this handler runs, local file paths should already be converted
|
|
34
|
-
* to base64 data URLs by `preprocessOperations()` in `operations/index.ts`.
|
|
35
|
-
* html-to-docx only supports base64 data URLs and HTTP URLs.
|
|
36
|
-
*/
|
|
37
|
-
export declare function handleInsertImage(html: string, imagePath: string, altText?: string, width?: number, height?: number, baseDir?: string, selector?: string, position?: 'before' | 'after' | 'inside'): string;
|
|
38
|
-
/** Apply a single DocxOperation to HTML content, routing to the correct handler. */
|
|
39
|
-
export declare function applyOperation(html: string, operation: DocxOperation, baseDir?: string): string;
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DOCX Operation Handlers
|
|
3
|
-
*
|
|
4
|
-
* Pure functions: HTML in → modified HTML out.
|
|
5
|
-
* Each handler corresponds to one DocxOperation type.
|
|
6
|
-
*
|
|
7
|
-
* @module docx/operations/handlers
|
|
8
|
-
*/
|
|
9
|
-
import { DocxError, DocxErrorCode } from '../../errors.js';
|
|
10
|
-
import { markdownToHtml, markdownTableToHtml, buildMarkdownTableFromRows, } from '../../converters/markdown-to-html.js';
|
|
11
|
-
import { appendHtml, insertHtml, replaceHtml, updateHtml } from '../html-manipulator.js';
|
|
12
|
-
import { escapeHtmlAttribute, escapeRegExp } from '../../utils/escaping.js';
|
|
13
|
-
import { isUrl, isDataUrl, resolveImagePath } from '../../utils/paths.js';
|
|
14
|
-
import { validateImageDimensions } from '../../validators.js';
|
|
15
|
-
// ─── Text Operations ─────────────────────────────────────────────────────────
|
|
16
|
-
/**
|
|
17
|
-
* Replace text in HTML while protecting base64 data URLs and other attribute values.
|
|
18
|
-
*
|
|
19
|
-
* Strategy: Temporarily extract `<img>` tags (which contain huge base64 data URLs)
|
|
20
|
-
* and replace them with placeholders, perform the text replacement,
|
|
21
|
-
* then restore the original `<img>` tags. This prevents the regex from
|
|
22
|
-
* accidentally matching / corrupting base64 image data.
|
|
23
|
-
*/
|
|
24
|
-
export function handleReplaceText(html, search, replace, matchCase = false, global = true) {
|
|
25
|
-
if (!search?.trim())
|
|
26
|
-
return html;
|
|
27
|
-
// Extract and protect all <img> tags from text replacement
|
|
28
|
-
const imgPlaceholders = [];
|
|
29
|
-
const protectedHtml = html.replace(/<img\s[^>]*>/gi, (match) => {
|
|
30
|
-
imgPlaceholders.push(match);
|
|
31
|
-
return `\x00IMG_PLACEHOLDER_${imgPlaceholders.length - 1}\x00`;
|
|
32
|
-
});
|
|
33
|
-
// Perform the text replacement on the protected HTML
|
|
34
|
-
const flags = matchCase ? (global ? 'g' : '') : global ? 'gi' : 'i';
|
|
35
|
-
let result = protectedHtml.replace(new RegExp(escapeRegExp(search), flags), replace);
|
|
36
|
-
// Restore the original <img> tags
|
|
37
|
-
for (let i = 0; i < imgPlaceholders.length; i++) {
|
|
38
|
-
result = result.replace(`\x00IMG_PLACEHOLDER_${i}\x00`, imgPlaceholders[i]);
|
|
39
|
-
}
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
// ─── HTML / Markdown Append & Insert ─────────────────────────────────────────
|
|
43
|
-
export function handleAppendMarkdown(html, markdown) {
|
|
44
|
-
if (!markdown?.trim())
|
|
45
|
-
return html;
|
|
46
|
-
const converted = markdownToHtml(markdown);
|
|
47
|
-
return converted ? appendHtml(html, converted) : html;
|
|
48
|
-
}
|
|
49
|
-
export function handleAppendHtml(html, content) {
|
|
50
|
-
return appendHtml(html, content);
|
|
51
|
-
}
|
|
52
|
-
export function handleInsertHtml(html, content, selector, position = 'after') {
|
|
53
|
-
return insertHtml(html, content, selector, position);
|
|
54
|
-
}
|
|
55
|
-
export function handleReplaceHtml(html, selector, content, replaceAll = false) {
|
|
56
|
-
return replaceHtml(html, selector, content, replaceAll);
|
|
57
|
-
}
|
|
58
|
-
export function handleUpdateHtml(html, selector, content, attributes, updateAll = false) {
|
|
59
|
-
return updateHtml(html, selector, content, attributes, updateAll);
|
|
60
|
-
}
|
|
61
|
-
// ─── Table Insertion ─────────────────────────────────────────────────────────
|
|
62
|
-
/**
|
|
63
|
-
* Insert a table from markdown or a rows array.
|
|
64
|
-
* If a selector is given, the table is placed relative to that element;
|
|
65
|
-
* otherwise it is appended to the end of the document.
|
|
66
|
-
*/
|
|
67
|
-
export function handleInsertTable(html, markdownTable, rows, selector, position = 'after') {
|
|
68
|
-
let tableHtml = '';
|
|
69
|
-
if (markdownTable?.trim()) {
|
|
70
|
-
tableHtml = markdownTableToHtml(markdownTable);
|
|
71
|
-
}
|
|
72
|
-
else if (rows?.length) {
|
|
73
|
-
const md = buildMarkdownTableFromRows(rows);
|
|
74
|
-
if (md)
|
|
75
|
-
tableHtml = markdownTableToHtml(md);
|
|
76
|
-
}
|
|
77
|
-
if (!tableHtml)
|
|
78
|
-
return html;
|
|
79
|
-
return selector?.trim()
|
|
80
|
-
? insertHtml(html, tableHtml, selector, position)
|
|
81
|
-
: appendHtml(html, tableHtml);
|
|
82
|
-
}
|
|
83
|
-
// ─── Image Insertion ─────────────────────────────────────────────────────────
|
|
84
|
-
/**
|
|
85
|
-
* Insert an image into the document.
|
|
86
|
-
*
|
|
87
|
-
* By the time this handler runs, local file paths should already be converted
|
|
88
|
-
* to base64 data URLs by `preprocessOperations()` in `operations/index.ts`.
|
|
89
|
-
* html-to-docx only supports base64 data URLs and HTTP URLs.
|
|
90
|
-
*/
|
|
91
|
-
export function handleInsertImage(html, imagePath, altText = '', width, height, baseDir, selector, position = 'after') {
|
|
92
|
-
if (!imagePath?.trim())
|
|
93
|
-
return html;
|
|
94
|
-
if (width !== undefined || height !== undefined)
|
|
95
|
-
validateImageDimensions(width, height);
|
|
96
|
-
const trimmedPath = imagePath.trim();
|
|
97
|
-
let imageSrc;
|
|
98
|
-
if (isDataUrl(trimmedPath) || isUrl(trimmedPath)) {
|
|
99
|
-
imageSrc = trimmedPath;
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
// Fallback: should not normally occur after preprocessing
|
|
103
|
-
const resolved = resolveImagePath(trimmedPath, baseDir).replace(/\\/g, '/');
|
|
104
|
-
imageSrc = resolved.startsWith('/') ? `file://${resolved}` : `file:///${resolved}`;
|
|
105
|
-
}
|
|
106
|
-
// Build img attributes
|
|
107
|
-
const attrs = [`src="${escapeHtmlAttribute(imageSrc)}"`];
|
|
108
|
-
if (altText?.trim())
|
|
109
|
-
attrs.push(`alt="${escapeHtmlAttribute(altText.trim())}"`);
|
|
110
|
-
// Add dimensions as both attributes and inline style (for compatibility)
|
|
111
|
-
const styles = [];
|
|
112
|
-
if (width && width > 0) {
|
|
113
|
-
attrs.push(`width="${width}"`);
|
|
114
|
-
styles.push(`width:${width}px`);
|
|
115
|
-
}
|
|
116
|
-
if (height && height > 0) {
|
|
117
|
-
attrs.push(`height="${height}"`);
|
|
118
|
-
styles.push(`height:${height}px`);
|
|
119
|
-
}
|
|
120
|
-
if (styles.length > 0)
|
|
121
|
-
attrs.push(`style="${styles.join('; ')}"`);
|
|
122
|
-
const imgTag = `<p><img ${attrs.join(' ')} /></p>`;
|
|
123
|
-
return selector?.trim()
|
|
124
|
-
? insertHtml(html, imgTag, selector, position)
|
|
125
|
-
: appendHtml(html, imgTag);
|
|
126
|
-
}
|
|
127
|
-
// ─── Operation Router ────────────────────────────────────────────────────────
|
|
128
|
-
/** Apply a single DocxOperation to HTML content, routing to the correct handler. */
|
|
129
|
-
export function applyOperation(html, operation, baseDir) {
|
|
130
|
-
switch (operation.type) {
|
|
131
|
-
case 'replaceText':
|
|
132
|
-
return handleReplaceText(html, operation.search, operation.replace, operation.matchCase ?? false, operation.global ?? true);
|
|
133
|
-
case 'appendMarkdown':
|
|
134
|
-
return handleAppendMarkdown(html, operation.markdown);
|
|
135
|
-
case 'appendHtml':
|
|
136
|
-
return handleAppendHtml(html, operation.html);
|
|
137
|
-
case 'insertHtml':
|
|
138
|
-
return handleInsertHtml(html, operation.html, operation.selector, operation.position ?? 'after');
|
|
139
|
-
case 'replaceHtml':
|
|
140
|
-
return handleReplaceHtml(html, operation.selector, operation.html, operation.replaceAll ?? false);
|
|
141
|
-
case 'updateHtml':
|
|
142
|
-
return handleUpdateHtml(html, operation.selector, operation.html, operation.attributes, operation.updateAll ?? false);
|
|
143
|
-
case 'insertTable':
|
|
144
|
-
return handleInsertTable(html, operation.markdownTable, operation.rows, operation.selector, operation.position ?? 'after');
|
|
145
|
-
case 'insertImage':
|
|
146
|
-
return handleInsertImage(html, operation.imagePath, operation.altText, operation.width, operation.height, baseDir, operation.selector, operation.position ?? 'after');
|
|
147
|
-
default: {
|
|
148
|
-
const unknownOp = operation;
|
|
149
|
-
throw new DocxError(`Unknown operation type: ${unknownOp.type}`, DocxErrorCode.UNKNOWN_OPERATION, { operation: unknownOp });
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTML DOM Manipulation
|
|
3
|
-
*
|
|
4
|
-
* DOM-based insert / append / replace / update for HTML content.
|
|
5
|
-
* Uses @xmldom/xmldom as the parser (not a browser DOMParser).
|
|
6
|
-
*
|
|
7
|
-
* IMPORTANT: All public functions use `Base64Guard` to protect base64 data URLs
|
|
8
|
-
* from corruption during xmldom parse/serialize cycles. Without this, images
|
|
9
|
-
* (which are embedded as long `data:image/...;base64,...` strings in `src` attributes)
|
|
10
|
-
* can be lost or mangled by the XML serializer.
|
|
11
|
-
*
|
|
12
|
-
* @module docx/operations/html-manipulator
|
|
13
|
-
*/
|
|
14
|
-
/** Append HTML content to the end of the document body. */
|
|
15
|
-
export declare function appendHtml(html: string, content: string): string;
|
|
16
|
-
/**
|
|
17
|
-
* Insert HTML content at a specific position relative to a selector target.
|
|
18
|
-
* If no selector is given, appends to the root element.
|
|
19
|
-
*/
|
|
20
|
-
export declare function insertHtml(html: string, content: string, selector?: string, position?: 'before' | 'after' | 'inside'): string;
|
|
21
|
-
/** Replace matched elements with new HTML content. */
|
|
22
|
-
export declare function replaceHtml(html: string, selector: string, content: string, replaceAll?: boolean): string;
|
|
23
|
-
/** Update matched elements' content and/or attributes. */
|
|
24
|
-
export declare function updateHtml(html: string, selector: string, content?: string, attributes?: Record<string, string>, updateAll?: boolean): string;
|