@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.
- package/README.md +53 -2
- package/dist/handlers/filesystem-handlers.d.ts +5 -0
- package/dist/handlers/filesystem-handlers.js +14 -2
- package/dist/remote-device/desktop-commander-integration.js +1 -1
- package/dist/search-manager.js +31 -38
- package/dist/server.js +8 -3
- package/dist/terminal-manager.js +4 -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/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 +65 -14096
- 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/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/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 +2 -1
- package/dist/ui/file-preview/{src/app.d.ts → app.d.ts} +1 -1
- 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 +384 -26533
- package/dist/ui/file-preview/shared/preview-file-types.d.ts +1 -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/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 +1066 -233
- package/dist/ui/file-preview/types.d.ts +1 -0
- 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/guards.d.ts +1 -0
- package/dist/ui/shared/guards.js +3 -0
- package/dist/ui/shared/host-lifecycle.d.ts +1 -0
- package/dist/ui/shared/host-lifecycle.js +8 -2
- package/dist/ui/shared/widget-state.d.ts +6 -1
- package/dist/ui/shared/widget-state.js +102 -4
- 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 +6 -1
- package/dist/data/spec-kit-prompts.json +0 -123
- package/dist/handlers/macos-control-handlers.d.ts +0 -16
- package/dist/handlers/macos-control-handlers.js +0 -81
- 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/lib.d.ts +0 -10
- package/dist/lib.js +0 -10
- 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/macos-control/ax-adapter.d.ts +0 -55
- package/dist/tools/macos-control/ax-adapter.js +0 -438
- package/dist/tools/macos-control/cdp-adapter.d.ts +0 -23
- package/dist/tools/macos-control/cdp-adapter.js +0 -402
- package/dist/tools/macos-control/orchestrator.d.ts +0 -77
- package/dist/tools/macos-control/orchestrator.js +0 -136
- package/dist/tools/macos-control/role-aliases.d.ts +0 -5
- package/dist/tools/macos-control/role-aliases.js +0 -34
- package/dist/tools/macos-control/types.d.ts +0 -129
- package/dist/tools/pdf-processor.d.ts +0 -1
- 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.js +0 -714
- 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/ui/config-editor/{src/app.d.ts → app.d.ts} +0 -0
- /package/dist/{http-server-auto-tunnel.d.ts → ui/config-editor/main.d.ts} +0 -0
- /package/dist/ui/config-editor/src/{app.js → App.js} +0 -0
- /package/dist/{test-docx.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/docx/xml-view-test.d.ts → ui/file-preview/src/model.js} +0 -0
- /package/dist/{tools/macos-control → ui/file-preview}/types.js +0 -0
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Image builder — creates w:drawing elements and manages image relationships.
|
|
3
|
-
*/
|
|
4
|
-
import fs from 'fs/promises';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import { DOMParser } from '@xmldom/xmldom';
|
|
7
|
-
import { addImageRelationship, ensureContentType } from '../relationships.js';
|
|
8
|
-
import { escapeXmlAttr } from './utils.js';
|
|
9
|
-
import { pixelsToEmu, DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT, NAMESPACES } from '../constants.js';
|
|
10
|
-
/**
|
|
11
|
-
* Build an image element and add it to the ZIP archive.
|
|
12
|
-
*
|
|
13
|
-
* @param doc The XML document
|
|
14
|
-
* @param zip The DOCX ZIP archive
|
|
15
|
-
* @param spec The image specification (from content or operation)
|
|
16
|
-
* @returns A w:p element containing the image drawing
|
|
17
|
-
*/
|
|
18
|
-
export async function buildImageElement(doc, zip, spec) {
|
|
19
|
-
// Validate image exists
|
|
20
|
-
try {
|
|
21
|
-
await fs.access(spec.imagePath);
|
|
22
|
-
}
|
|
23
|
-
catch {
|
|
24
|
-
throw new Error(`Image file not found: ${spec.imagePath}`);
|
|
25
|
-
}
|
|
26
|
-
// Read image
|
|
27
|
-
const imgBuffer = await fs.readFile(spec.imagePath);
|
|
28
|
-
const ext = path.extname(spec.imagePath).toLowerCase();
|
|
29
|
-
const baseName = path.basename(spec.imagePath);
|
|
30
|
-
// Find next available media filename
|
|
31
|
-
let mediaIndex = 1;
|
|
32
|
-
while (zip.file(`word/media/image${mediaIndex}${ext}`)) {
|
|
33
|
-
mediaIndex++;
|
|
34
|
-
}
|
|
35
|
-
const mediaFileName = `image${mediaIndex}${ext}`;
|
|
36
|
-
// Add image to ZIP
|
|
37
|
-
zip.file(`word/media/${mediaFileName}`, imgBuffer);
|
|
38
|
-
// Add relationship
|
|
39
|
-
const rId = addImageRelationship(zip, mediaFileName);
|
|
40
|
-
// Ensure Content_Types entry
|
|
41
|
-
ensureContentType(zip, ext);
|
|
42
|
-
// Compute dimensions (EMU)
|
|
43
|
-
const widthPx = spec.width ?? DEFAULT_IMAGE_WIDTH;
|
|
44
|
-
const heightPx = spec.height ?? DEFAULT_IMAGE_HEIGHT;
|
|
45
|
-
const widthEmu = pixelsToEmu(widthPx);
|
|
46
|
-
const heightEmu = pixelsToEmu(heightPx);
|
|
47
|
-
// Build drawing XML
|
|
48
|
-
const altText = spec.altText ?? baseName;
|
|
49
|
-
const drawingXmlStr = buildDrawingXml(rId, widthEmu, heightEmu, altText, mediaFileName);
|
|
50
|
-
// Parse drawing XML into a paragraph
|
|
51
|
-
const drawingFragment = new DOMParser().parseFromString(`<w:p xmlns:w="${NAMESPACES.W}">` +
|
|
52
|
-
`<w:r>${drawingXmlStr}</w:r></w:p>`, 'application/xml');
|
|
53
|
-
return doc.importNode(drawingFragment.documentElement, true);
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Build the inline w:drawing XML for an image reference.
|
|
57
|
-
*/
|
|
58
|
-
function buildDrawingXml(rId, widthEmu, heightEmu, altText, fileName) {
|
|
59
|
-
return (`<w:drawing xmlns:w="${NAMESPACES.W}">` +
|
|
60
|
-
`<wp:inline distT="0" distB="0" distL="0" distR="0" ` +
|
|
61
|
-
`xmlns:wp="${NAMESPACES.WP}">` +
|
|
62
|
-
`<wp:extent cx="${widthEmu}" cy="${heightEmu}"/>` +
|
|
63
|
-
`<wp:docPr id="1" name="${fileName}" descr="${escapeXmlAttr(altText)}"/>` +
|
|
64
|
-
`<a:graphic xmlns:a="${NAMESPACES.A}">` +
|
|
65
|
-
`<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">` +
|
|
66
|
-
`<pic:pic xmlns:pic="${NAMESPACES.PIC}">` +
|
|
67
|
-
`<pic:nvPicPr>` +
|
|
68
|
-
`<pic:cNvPr id="0" name="${fileName}" descr="${escapeXmlAttr(altText)}"/>` +
|
|
69
|
-
`<pic:cNvPicPr/>` +
|
|
70
|
-
`</pic:nvPicPr>` +
|
|
71
|
-
`<pic:blipFill>` +
|
|
72
|
-
`<a:blip r:embed="${rId}" xmlns:r="${NAMESPACES.R}"/>` +
|
|
73
|
-
`<a:stretch><a:fillRect/></a:stretch>` +
|
|
74
|
-
`</pic:blipFill>` +
|
|
75
|
-
`<pic:spPr>` +
|
|
76
|
-
`<a:xfrm><a:off x="0" y="0"/><a:ext cx="${widthEmu}" cy="${heightEmu}"/></a:xfrm>` +
|
|
77
|
-
`<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>` +
|
|
78
|
-
`</pic:spPr>` +
|
|
79
|
-
`</pic:pic>` +
|
|
80
|
-
`</a:graphicData>` +
|
|
81
|
-
`</a:graphic>` +
|
|
82
|
-
`</wp:inline>` +
|
|
83
|
-
`</w:drawing>`);
|
|
84
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DOCX element builders — Single Responsibility: build XML elements
|
|
3
|
-
* for paragraphs, tables, and images.
|
|
4
|
-
*
|
|
5
|
-
* These builders are shared between create.ts and ops/ modules to
|
|
6
|
-
* eliminate code duplication and ensure consistency.
|
|
7
|
-
*/
|
|
8
|
-
export { buildParagraph } from './paragraph.js';
|
|
9
|
-
export { buildTable } from './table.js';
|
|
10
|
-
export { buildImageElement } from './image.js';
|
|
11
|
-
export { escapeXml, escapeXmlAttr } from './utils.js';
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DOCX element builders — Single Responsibility: build XML elements
|
|
3
|
-
* for paragraphs, tables, and images.
|
|
4
|
-
*
|
|
5
|
-
* These builders are shared between create.ts and ops/ modules to
|
|
6
|
-
* eliminate code duplication and ensure consistency.
|
|
7
|
-
*/
|
|
8
|
-
export { buildParagraph } from './paragraph.js';
|
|
9
|
-
export { buildTable } from './table.js';
|
|
10
|
-
export { buildImageElement } from './image.js';
|
|
11
|
-
export { escapeXml, escapeXmlAttr } from './utils.js';
|
|
@@ -1,260 +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 { AlignmentType, Document, HeadingLevel, Paragraph, Table, TableCell, TableRow, TextRun, WidthType, Packer, } = docx;
|
|
6
|
-
import { DocxErrorCode, withErrorContext } from '../errors.js';
|
|
7
|
-
import { normalizeLineEndings, prepareImageForDocx, createImageRun, } from '../utils.js';
|
|
8
|
-
export async function createDocxFromMarkdown(markdown, options = {}) {
|
|
9
|
-
return withErrorContext(async () => {
|
|
10
|
-
const children = [];
|
|
11
|
-
const baseDir = options.baseDir;
|
|
12
|
-
const lines = normalizeLineEndings(markdown).split('\n');
|
|
13
|
-
let i = 0;
|
|
14
|
-
while (i < lines.length) {
|
|
15
|
-
const rawLine = lines[i];
|
|
16
|
-
const line = rawLine.trimEnd();
|
|
17
|
-
// Skip empty lines
|
|
18
|
-
if (!line.trim()) {
|
|
19
|
-
i++;
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
// 1) Markdown table detection
|
|
23
|
-
const isHeader = isTableHeaderLine(line);
|
|
24
|
-
const hasSeparator = i + 1 < lines.length && isTableSeparatorLine(lines[i + 1]);
|
|
25
|
-
if (isHeader && hasSeparator) {
|
|
26
|
-
const tableLines = [line];
|
|
27
|
-
i++;
|
|
28
|
-
tableLines.push(lines[i]); // Add separator line
|
|
29
|
-
i++;
|
|
30
|
-
// Collect all subsequent table rows
|
|
31
|
-
while (i < lines.length) {
|
|
32
|
-
const nextLine = lines[i].trim();
|
|
33
|
-
if (!nextLine || !isTableRowLine(nextLine)) {
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
tableLines.push(nextLine);
|
|
37
|
-
i++;
|
|
38
|
-
}
|
|
39
|
-
try {
|
|
40
|
-
const table = createTableFromMarkdown(tableLines);
|
|
41
|
-
children.push(table);
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
console.error('[DOCX Build] Failed to create table:', error);
|
|
45
|
-
// Fallback: add table lines as plain text
|
|
46
|
-
for (const tableLine of tableLines) {
|
|
47
|
-
children.push(new Paragraph({ text: tableLine }));
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
// 2) Images
|
|
53
|
-
const imageMatch = line.match(/!\[([^\]]*)\]\(([^)]+)\)/);
|
|
54
|
-
if (imageMatch) {
|
|
55
|
-
const altText = imageMatch[1] || '';
|
|
56
|
-
const src = imageMatch[2];
|
|
57
|
-
try {
|
|
58
|
-
const imageData = await prepareImageForDocx(src, altText, baseDir);
|
|
59
|
-
const imageRun = createImageRun(imageData);
|
|
60
|
-
const paragraph = new Paragraph({
|
|
61
|
-
children: [imageRun],
|
|
62
|
-
alignment: AlignmentType.CENTER,
|
|
63
|
-
});
|
|
64
|
-
children.push(paragraph);
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
console.warn(`Failed to embed image ${src}:`, error);
|
|
68
|
-
children.push(new Paragraph({
|
|
69
|
-
text: `[Image: ${altText || src}]`,
|
|
70
|
-
}));
|
|
71
|
-
}
|
|
72
|
-
i++;
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
// 3) Headings
|
|
76
|
-
const headingMatch = line.match(/^(#{1,6})\s+(.+)$/);
|
|
77
|
-
if (headingMatch) {
|
|
78
|
-
const level = headingMatch[1].length;
|
|
79
|
-
const text = headingMatch[2].trim();
|
|
80
|
-
const textRuns = parseInlineFormatting(text);
|
|
81
|
-
const heading = new Paragraph({
|
|
82
|
-
children: textRuns,
|
|
83
|
-
heading: getHeadingLevel(level),
|
|
84
|
-
});
|
|
85
|
-
children.push(heading);
|
|
86
|
-
i++;
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
// 4) Regular paragraphs
|
|
90
|
-
const textRuns = parseInlineFormatting(rawLine);
|
|
91
|
-
const paragraph = new Paragraph({
|
|
92
|
-
children: textRuns,
|
|
93
|
-
});
|
|
94
|
-
children.push(paragraph);
|
|
95
|
-
i++;
|
|
96
|
-
}
|
|
97
|
-
const doc = new Document({
|
|
98
|
-
sections: [{
|
|
99
|
-
properties: {},
|
|
100
|
-
children: children,
|
|
101
|
-
}],
|
|
102
|
-
});
|
|
103
|
-
return await Packer.toBuffer(doc);
|
|
104
|
-
}, DocxErrorCode.DOCX_CREATE_FAILED, { markdownLength: markdown.length });
|
|
105
|
-
}
|
|
106
|
-
// ============================================================================
|
|
107
|
-
// Helper Functions
|
|
108
|
-
// ============================================================================
|
|
109
|
-
function isTableHeaderLine(line) {
|
|
110
|
-
const trimmed = line.trim();
|
|
111
|
-
if (!trimmed.includes('|'))
|
|
112
|
-
return false;
|
|
113
|
-
const startsWithPipe = trimmed.startsWith('|');
|
|
114
|
-
const endsWithPipe = trimmed.endsWith('|');
|
|
115
|
-
const pipeCount = (trimmed.match(/\|/g) || []).length;
|
|
116
|
-
if (startsWithPipe && endsWithPipe) {
|
|
117
|
-
return pipeCount >= 2;
|
|
118
|
-
}
|
|
119
|
-
return pipeCount >= 1;
|
|
120
|
-
}
|
|
121
|
-
function isTableSeparatorLine(line) {
|
|
122
|
-
const trimmed = line.trim();
|
|
123
|
-
if (!trimmed.includes('|'))
|
|
124
|
-
return false;
|
|
125
|
-
let content = trimmed;
|
|
126
|
-
if (content.startsWith('|'))
|
|
127
|
-
content = content.substring(1);
|
|
128
|
-
if (content.endsWith('|'))
|
|
129
|
-
content = content.substring(0, content.length - 1);
|
|
130
|
-
const parts = content.split('|');
|
|
131
|
-
let validParts = 0;
|
|
132
|
-
for (const part of parts) {
|
|
133
|
-
const cleaned = part.trim();
|
|
134
|
-
if (cleaned.length === 0)
|
|
135
|
-
continue;
|
|
136
|
-
if (/^:?-+:?$/.test(cleaned)) {
|
|
137
|
-
validParts++;
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return validParts > 0;
|
|
144
|
-
}
|
|
145
|
-
function isTableRowLine(line) {
|
|
146
|
-
const trimmed = line.trim();
|
|
147
|
-
if (!trimmed.includes('|'))
|
|
148
|
-
return false;
|
|
149
|
-
if (isTableSeparatorLine(trimmed))
|
|
150
|
-
return false;
|
|
151
|
-
const pipeCount = (trimmed.match(/\|/g) || []).length;
|
|
152
|
-
return pipeCount >= 1;
|
|
153
|
-
}
|
|
154
|
-
function splitTableRow(line) {
|
|
155
|
-
const trimmed = line.trim();
|
|
156
|
-
let withoutBorders = trimmed;
|
|
157
|
-
if (withoutBorders.startsWith('|')) {
|
|
158
|
-
withoutBorders = withoutBorders.substring(1);
|
|
159
|
-
}
|
|
160
|
-
if (withoutBorders.endsWith('|')) {
|
|
161
|
-
withoutBorders = withoutBorders.substring(0, withoutBorders.length - 1);
|
|
162
|
-
}
|
|
163
|
-
return withoutBorders.split('|').map(cell => cell.trim());
|
|
164
|
-
}
|
|
165
|
-
function createTableFromMarkdown(lines) {
|
|
166
|
-
if (lines.length < 2) {
|
|
167
|
-
return new Table({ rows: [] });
|
|
168
|
-
}
|
|
169
|
-
const headerCells = splitTableRow(lines[0]);
|
|
170
|
-
const rows = [];
|
|
171
|
-
// Header row
|
|
172
|
-
rows.push(new TableRow({
|
|
173
|
-
children: headerCells.map((cell) => {
|
|
174
|
-
const textRuns = parseInlineFormatting(cell.trim());
|
|
175
|
-
textRuns.forEach(run => {
|
|
176
|
-
run.bold = true;
|
|
177
|
-
});
|
|
178
|
-
return new TableCell({
|
|
179
|
-
children: [
|
|
180
|
-
new Paragraph({
|
|
181
|
-
children: textRuns,
|
|
182
|
-
alignment: AlignmentType.CENTER,
|
|
183
|
-
}),
|
|
184
|
-
],
|
|
185
|
-
});
|
|
186
|
-
}),
|
|
187
|
-
}));
|
|
188
|
-
// Data rows (skip separator at index 1)
|
|
189
|
-
for (let i = 2; i < lines.length; i++) {
|
|
190
|
-
const cells = splitTableRow(lines[i]);
|
|
191
|
-
rows.push(new TableRow({
|
|
192
|
-
children: cells.map((cell) => {
|
|
193
|
-
const textRuns = parseInlineFormatting(cell.trim());
|
|
194
|
-
return new TableCell({
|
|
195
|
-
children: [
|
|
196
|
-
new Paragraph({
|
|
197
|
-
children: textRuns,
|
|
198
|
-
}),
|
|
199
|
-
],
|
|
200
|
-
});
|
|
201
|
-
}),
|
|
202
|
-
}));
|
|
203
|
-
}
|
|
204
|
-
return new Table({
|
|
205
|
-
width: { size: 100, type: WidthType.PERCENTAGE },
|
|
206
|
-
rows,
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
function parseInlineFormatting(text) {
|
|
210
|
-
const runs = [];
|
|
211
|
-
let currentText = '';
|
|
212
|
-
let i = 0;
|
|
213
|
-
while (i < text.length) {
|
|
214
|
-
// Check for **bold**
|
|
215
|
-
if (text.substring(i, i + 2) === '**') {
|
|
216
|
-
if (currentText) {
|
|
217
|
-
runs.push(new TextRun({ text: currentText }));
|
|
218
|
-
currentText = '';
|
|
219
|
-
}
|
|
220
|
-
const closeIndex = text.indexOf('**', i + 2);
|
|
221
|
-
if (closeIndex !== -1) {
|
|
222
|
-
const boldText = text.substring(i + 2, closeIndex);
|
|
223
|
-
runs.push(new TextRun({ text: boldText, bold: true }));
|
|
224
|
-
i = closeIndex + 2;
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
// Check for *italic*
|
|
229
|
-
if (text[i] === '*' && text[i + 1] !== '*') {
|
|
230
|
-
if (currentText) {
|
|
231
|
-
runs.push(new TextRun({ text: currentText }));
|
|
232
|
-
currentText = '';
|
|
233
|
-
}
|
|
234
|
-
const closeIndex = text.indexOf('*', i + 1);
|
|
235
|
-
if (closeIndex !== -1) {
|
|
236
|
-
const italicText = text.substring(i + 1, closeIndex);
|
|
237
|
-
runs.push(new TextRun({ text: italicText, italics: true }));
|
|
238
|
-
i = closeIndex + 1;
|
|
239
|
-
continue;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
currentText += text[i];
|
|
243
|
-
i++;
|
|
244
|
-
}
|
|
245
|
-
if (currentText) {
|
|
246
|
-
runs.push(new TextRun({ text: currentText }));
|
|
247
|
-
}
|
|
248
|
-
return runs.length > 0 ? runs : [new TextRun({ text: text })];
|
|
249
|
-
}
|
|
250
|
-
function getHeadingLevel(level) {
|
|
251
|
-
const levelMap = {
|
|
252
|
-
1: HeadingLevel.HEADING_1,
|
|
253
|
-
2: HeadingLevel.HEADING_2,
|
|
254
|
-
3: HeadingLevel.HEADING_3,
|
|
255
|
-
4: HeadingLevel.HEADING_4,
|
|
256
|
-
5: HeadingLevel.HEADING_5,
|
|
257
|
-
6: HeadingLevel.HEADING_6,
|
|
258
|
-
};
|
|
259
|
-
return levelMap[level] ?? HeadingLevel.HEADING_1;
|
|
260
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Paragraph builder — creates w:p elements with optional styles.
|
|
3
|
-
*/
|
|
4
|
-
import type { DocxContentParagraph } from '../types.js';
|
|
5
|
-
/**
|
|
6
|
-
* Build a paragraph element from content structure.
|
|
7
|
-
*
|
|
8
|
-
* @param doc The XML document
|
|
9
|
-
* @param item The paragraph content item
|
|
10
|
-
* @returns A w:p element
|
|
11
|
-
*/
|
|
12
|
-
export declare function buildParagraph(doc: Document, item: DocxContentParagraph): Element;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Paragraph builder — creates w:p elements with optional styles.
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Build a paragraph element from content structure.
|
|
6
|
-
*
|
|
7
|
-
* @param doc The XML document
|
|
8
|
-
* @param item The paragraph content item
|
|
9
|
-
* @returns A w:p element
|
|
10
|
-
*/
|
|
11
|
-
export function buildParagraph(doc, item) {
|
|
12
|
-
const p = doc.createElement('w:p');
|
|
13
|
-
// Set style if provided
|
|
14
|
-
if (item.style) {
|
|
15
|
-
const pPr = doc.createElement('w:pPr');
|
|
16
|
-
const pStyle = doc.createElement('w:pStyle');
|
|
17
|
-
pStyle.setAttribute('w:val', item.style);
|
|
18
|
-
pPr.appendChild(pStyle);
|
|
19
|
-
p.appendChild(pPr);
|
|
20
|
-
}
|
|
21
|
-
// Add text run
|
|
22
|
-
const r = doc.createElement('w:r');
|
|
23
|
-
const t = doc.createElement('w:t');
|
|
24
|
-
t.setAttribute('xml:space', 'preserve');
|
|
25
|
-
t.textContent = item.text;
|
|
26
|
-
r.appendChild(t);
|
|
27
|
-
p.appendChild(r);
|
|
28
|
-
return p;
|
|
29
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Table builder — creates w:tbl elements with headers, rows, and styling.
|
|
3
|
-
* Supports multiple paragraphs per cell with different styles.
|
|
4
|
-
*/
|
|
5
|
-
import type { DocxContentTable, InsertTableOp } from '../types.js';
|
|
6
|
-
/**
|
|
7
|
-
* Build a table element from content structure or operation.
|
|
8
|
-
* Supports cells with multiple paragraphs, each with its own style.
|
|
9
|
-
*/
|
|
10
|
-
export declare function buildTable(doc: Document, spec: DocxContentTable | InsertTableOp): Element;
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Table builder — creates w:tbl elements with headers, rows, and styling.
|
|
3
|
-
* Supports multiple paragraphs per cell with different styles.
|
|
4
|
-
*/
|
|
5
|
-
import { buildParagraph } from './paragraph.js';
|
|
6
|
-
/**
|
|
7
|
-
* Build a table element from content structure or operation.
|
|
8
|
-
* Supports cells with multiple paragraphs, each with its own style.
|
|
9
|
-
*/
|
|
10
|
-
export function buildTable(doc, spec) {
|
|
11
|
-
const tbl = doc.createElement('w:tbl');
|
|
12
|
-
// Table properties
|
|
13
|
-
const tblPr = doc.createElement('w:tblPr');
|
|
14
|
-
if (spec.style) {
|
|
15
|
-
const tblStyle = doc.createElement('w:tblStyle');
|
|
16
|
-
tblStyle.setAttribute('w:val', spec.style);
|
|
17
|
-
tblPr.appendChild(tblStyle);
|
|
18
|
-
}
|
|
19
|
-
const tblW = doc.createElement('w:tblW');
|
|
20
|
-
tblW.setAttribute('w:w', '0');
|
|
21
|
-
tblW.setAttribute('w:type', 'auto');
|
|
22
|
-
tblPr.appendChild(tblW);
|
|
23
|
-
// Table borders
|
|
24
|
-
const tblBorders = doc.createElement('w:tblBorders');
|
|
25
|
-
for (const side of ['top', 'left', 'bottom', 'right', 'insideH', 'insideV']) {
|
|
26
|
-
const border = doc.createElement(`w:${side}`);
|
|
27
|
-
border.setAttribute('w:val', 'single');
|
|
28
|
-
border.setAttribute('w:sz', '4');
|
|
29
|
-
border.setAttribute('w:space', '0');
|
|
30
|
-
border.setAttribute('w:color', '000000');
|
|
31
|
-
tblBorders.appendChild(border);
|
|
32
|
-
}
|
|
33
|
-
tblPr.appendChild(tblBorders);
|
|
34
|
-
tbl.appendChild(tblPr);
|
|
35
|
-
// Determine column count
|
|
36
|
-
const colCount = spec.headers
|
|
37
|
-
? spec.headers.length
|
|
38
|
-
: spec.rows.length > 0
|
|
39
|
-
? spec.rows[0].length
|
|
40
|
-
: 0;
|
|
41
|
-
// Table grid
|
|
42
|
-
if (colCount > 0) {
|
|
43
|
-
const tblGrid = doc.createElement('w:tblGrid');
|
|
44
|
-
for (let c = 0; c < colCount; c++) {
|
|
45
|
-
const gridCol = doc.createElement('w:gridCol');
|
|
46
|
-
const w = spec.colWidths?.[c] ?? Math.floor(9000 / colCount);
|
|
47
|
-
gridCol.setAttribute('w:w', String(w));
|
|
48
|
-
tblGrid.appendChild(gridCol);
|
|
49
|
-
}
|
|
50
|
-
tbl.appendChild(tblGrid);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Build a cell from content.
|
|
54
|
-
* Content can be:
|
|
55
|
-
* - A string: creates one paragraph with that text
|
|
56
|
-
* - An array of DocxContentParagraph: creates multiple paragraphs, each with its own style
|
|
57
|
-
*/
|
|
58
|
-
const buildCell = (content, isHeader, widthTwips) => {
|
|
59
|
-
const tc = doc.createElement('w:tc');
|
|
60
|
-
// Cell properties (width)
|
|
61
|
-
if (widthTwips) {
|
|
62
|
-
const tcPr = doc.createElement('w:tcPr');
|
|
63
|
-
const tcW = doc.createElement('w:tcW');
|
|
64
|
-
tcW.setAttribute('w:w', String(widthTwips));
|
|
65
|
-
tcW.setAttribute('w:type', 'dxa');
|
|
66
|
-
tcPr.appendChild(tcW);
|
|
67
|
-
tc.appendChild(tcPr);
|
|
68
|
-
}
|
|
69
|
-
// Handle content: string or array of paragraphs
|
|
70
|
-
if (typeof content === 'string') {
|
|
71
|
-
// Simple case: single paragraph
|
|
72
|
-
const p = doc.createElement('w:p');
|
|
73
|
-
const r = doc.createElement('w:r');
|
|
74
|
-
// Header cells get bold
|
|
75
|
-
if (isHeader) {
|
|
76
|
-
const rPr = doc.createElement('w:rPr');
|
|
77
|
-
const b = doc.createElement('w:b');
|
|
78
|
-
rPr.appendChild(b);
|
|
79
|
-
r.appendChild(rPr);
|
|
80
|
-
}
|
|
81
|
-
const t = doc.createElement('w:t');
|
|
82
|
-
t.setAttribute('xml:space', 'preserve');
|
|
83
|
-
t.textContent = content;
|
|
84
|
-
r.appendChild(t);
|
|
85
|
-
p.appendChild(r);
|
|
86
|
-
tc.appendChild(p);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
// Complex case: multiple paragraphs with different styles
|
|
90
|
-
for (const paraSpec of content) {
|
|
91
|
-
const p = buildParagraph(doc, paraSpec);
|
|
92
|
-
// If header and first paragraph, ensure bold on runs
|
|
93
|
-
if (isHeader) {
|
|
94
|
-
const runs = p.getElementsByTagName('w:r');
|
|
95
|
-
for (let i = 0; i < runs.length; i++) {
|
|
96
|
-
const run = runs.item(i);
|
|
97
|
-
let rPr = run.getElementsByTagName('w:rPr').item(0);
|
|
98
|
-
if (!rPr) {
|
|
99
|
-
rPr = doc.createElement('w:rPr');
|
|
100
|
-
if (run.firstChild) {
|
|
101
|
-
run.insertBefore(rPr, run.firstChild);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
run.appendChild(rPr);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
// Add bold if not already present
|
|
108
|
-
if (!rPr.getElementsByTagName('w:b').length) {
|
|
109
|
-
const b = doc.createElement('w:b');
|
|
110
|
-
rPr.appendChild(b);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
tc.appendChild(p);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return tc;
|
|
118
|
-
};
|
|
119
|
-
// Header row
|
|
120
|
-
if (spec.headers && spec.headers.length > 0) {
|
|
121
|
-
const tr = doc.createElement('w:tr');
|
|
122
|
-
for (let i = 0; i < spec.headers.length; i++) {
|
|
123
|
-
const width = spec.colWidths?.[i];
|
|
124
|
-
tr.appendChild(buildCell(spec.headers[i], true, width));
|
|
125
|
-
}
|
|
126
|
-
tbl.appendChild(tr);
|
|
127
|
-
}
|
|
128
|
-
// Data rows
|
|
129
|
-
for (const row of spec.rows) {
|
|
130
|
-
const tr = doc.createElement('w:tr');
|
|
131
|
-
for (let i = 0; i < row.length; i++) {
|
|
132
|
-
const width = spec.colWidths?.[i];
|
|
133
|
-
tr.appendChild(buildCell(row[i], false, width));
|
|
134
|
-
}
|
|
135
|
-
tbl.appendChild(tr);
|
|
136
|
-
}
|
|
137
|
-
return tbl;
|
|
138
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* XML escaping utilities.
|
|
3
|
-
*/
|
|
4
|
-
export function escapeXml(s) {
|
|
5
|
-
return s
|
|
6
|
-
.replace(/&/g, '&')
|
|
7
|
-
.replace(/</g, '<')
|
|
8
|
-
.replace(/>/g, '>')
|
|
9
|
-
.replace(/"/g, '"')
|
|
10
|
-
.replace(/'/g, ''');
|
|
11
|
-
}
|
|
12
|
-
export function escapeXmlAttr(s) {
|
|
13
|
-
return s
|
|
14
|
-
.replace(/&/g, '&')
|
|
15
|
-
.replace(/"/g, '"')
|
|
16
|
-
.replace(/</g, '<')
|
|
17
|
-
.replace(/>/g, '>');
|
|
18
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DOCX constants — shared values used across the module.
|
|
3
|
-
*/
|
|
4
|
-
export declare const IMAGE_MIME_TYPES: Record<string, string>;
|
|
5
|
-
export declare function getMimeType(ext: string): string;
|
|
6
|
-
/**
|
|
7
|
-
* Convert pixels to EMU (English Metric Units).
|
|
8
|
-
* 1 inch = 914400 EMU, 1 px ≈ 9525 EMU (at 96 DPI)
|
|
9
|
-
*/
|
|
10
|
-
export declare const PX_TO_EMU = 9525;
|
|
11
|
-
export declare function pixelsToEmu(px: number): number;
|
|
12
|
-
export declare const NAMESPACES: {
|
|
13
|
-
readonly W: "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
14
|
-
readonly WP: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing";
|
|
15
|
-
readonly A: "http://schemas.openxmlformats.org/drawingml/2006/main";
|
|
16
|
-
readonly PIC: "http://schemas.openxmlformats.org/drawingml/2006/picture";
|
|
17
|
-
readonly R: "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
|
|
18
|
-
readonly RELS: "http://schemas.openxmlformats.org/package/2006/relationships";
|
|
19
|
-
};
|
|
20
|
-
export declare const DEFAULT_IMAGE_WIDTH = 300;
|
|
21
|
-
export declare const DEFAULT_IMAGE_HEIGHT = 200;
|
|
22
|
-
export declare const DOCX_PATHS: {
|
|
23
|
-
readonly CONTENT_TYPES: "[Content_Types].xml";
|
|
24
|
-
readonly DOCUMENT_XML: "word/document.xml";
|
|
25
|
-
readonly DOCUMENT_RELS: "word/_rels/document.xml.rels";
|
|
26
|
-
readonly ROOT_RELS: "_rels/.rels";
|
|
27
|
-
readonly STYLES_XML: "word/styles.xml";
|
|
28
|
-
readonly SETTINGS_XML: "word/settings.xml";
|
|
29
|
-
readonly WEB_SETTINGS_XML: "word/webSettings.xml";
|
|
30
|
-
readonly FONT_TABLE_XML: "word/fontTable.xml";
|
|
31
|
-
readonly MEDIA_FOLDER: "word/media";
|
|
32
|
-
};
|