@xiaoso/dsh-tool-plus 0.1.6 → 0.1.7-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD_PARTY_NOTICES.md +9 -3
- package/lib/{abort-Cwwm4Err.mjs → abort-Caqff3M6.mjs} +2 -2
- package/lib/alibaba-coding-plan-DTupMiAi.mjs +73 -0
- package/lib/alibaba-token-plan-CHGyWOfX.mjs +46 -0
- package/lib/alibaba-token-plan-Dj3OZhEE.mjs +82 -0
- package/lib/{amazon-bedrock-TVMpUTRG.mjs → amazon-bedrock-DbFSYXfJ.mjs} +117 -38
- package/lib/{anthropic-BL6LFDQS.mjs → anthropic-CTJ3IQVa.mjs} +675 -166
- package/lib/anthropic-CXfWlp-x.mjs +105 -0
- package/lib/{aws-credentials-B20dliS7.mjs → anthropic-wire-CKuhDwZ1.mjs} +74 -14
- package/lib/{api-key-login-CIDnXeYd.mjs → api-key-validation-CGCJFbFr.mjs} +27 -68
- package/lib/{azure-openai-responses-BkhsLmN3.mjs → azure-openai-responses-ChFbWaGj.mjs} +27 -16
- package/lib/{browser-render-CmgvSNte.mjs → browser-render-9o0Rknop.mjs} +4 -4
- package/lib/bun-shim.mjs +71 -2
- package/lib/{bundled-references-ChZSPDFw.mjs → bundled-references-DY3EJxZV.mjs} +6 -5
- package/lib/cline-pass-Bwg3esu9.mjs +44 -0
- package/lib/cloudflare-ai-gateway-BupNXyKK.mjs +35 -0
- package/lib/cloudflare-ai-gateway-EWo0VkP5.mjs +44 -0
- package/lib/collapse-DOR8sOGf.mjs +2304 -0
- package/lib/coreweave-C82HrLpb.mjs +31 -0
- package/lib/coreweave-Ct8cF-da.mjs +14 -0
- package/lib/{cursor-B6HcmplF.mjs → cursor-B95LzVWV.mjs} +11 -3
- package/lib/{cursor-CRpLpaZ3.mjs → cursor-DJV_dcgB.mjs} +887 -1784
- package/lib/{cursor-B8m6SqAH.mjs → cursor-LKGjucn2.mjs} +48 -38
- package/lib/cursor-proto-B8Wj8bv9.mjs +10513 -0
- package/lib/{deterministic-id-D-yIV_eI.mjs → deterministic-id-CUEIMSqR.mjs} +1 -1
- package/lib/devin-BMTdx_hx.mjs +316 -0
- package/lib/{devin-DUAfvBsW.mjs → devin-DSp0Rw_E.mjs} +172 -86
- package/lib/devin-ExGIghmx.mjs +69 -0
- package/lib/devin-proto-Br8fdyNl.mjs +2888 -0
- package/lib/{dom-CawWi8fa.mjs → dom-DG3sPESc.mjs} +8 -8
- package/lib/effort-BdtQMN-_.mjs +23 -0
- package/lib/{error-C-f_Wnw4.mjs → error-CORgGg5a.mjs} +275 -154
- package/lib/{event-stream-Dh2guZxS.mjs → event-stream-ulcDenZD.mjs} +20 -4
- package/lib/{gemini-headers-DKUShltF.mjs → gemini-headers-Co9cVvex.mjs} +2 -2
- package/lib/{github-copilot-suDymKrx.mjs → github-copilot-Dstq1D3s.mjs} +69 -29
- package/lib/github-copilot-headers-DOh1gt_w.mjs +312 -0
- package/lib/gitlab-duo-DSCMrU0m.mjs +11 -0
- package/lib/google-CtsKkOQK.mjs +38 -0
- package/lib/google-antigravity-z-5KsEci.mjs +252 -0
- package/lib/{google-auth-DYJLM792.mjs → google-auth-ieLBaneO.mjs} +4 -4
- package/lib/{google-gemini-cli-8BT513Ul.mjs → google-gemini-cli-C6NE5mWz.mjs} +28 -54
- package/lib/{google-gemini-cli-D6cSmfvB.mjs → google-gemini-cli-CAIPSl7e.mjs} +23 -29
- package/lib/google-oauth-shared-DhMllAkt.mjs +53 -0
- package/lib/{google-shared-CVbHK5vZ.mjs → google-shared-B0aNCYEH.mjs} +140 -44
- package/lib/{google-validation-Cgbn3tWJ.mjs → google-validation-BEkNs-Bx.mjs} +1 -1
- package/lib/{google-vertex-Bui-ypAe.mjs → google-vertex-Bbd1tYNc.mjs} +8 -8
- package/lib/hosts-00rjRzUD.mjs +203 -0
- package/lib/id-AL5obQzR.mjs +71 -0
- package/lib/{idle-iterator-CYAxUkSD.mjs → idle-iterator-DlUkEfzW.mjs} +3 -3
- package/lib/index.mjs +598 -5275
- package/lib/kilo-ChJL54wq.mjs +81 -0
- package/lib/kimi-C2c_Zq8A.mjs +67 -0
- package/lib/{launch-BmgEUycu.mjs → launch-DKDH71En.mjs} +1 -1
- package/lib/markit-CmRfm4E2.mjs +9885 -0
- package/lib/models-DnXMYGcJ.mjs +381604 -0
- package/lib/muse-code-Di1VZmB1.mjs +143 -0
- package/lib/{ollama-Df9ce-Cp.mjs → ollama-B8ic3sEp.mjs} +15 -30
- package/lib/{openai-codex-CAVI3Me-.mjs → openai-codex-DuJNC99x.mjs} +29 -99
- package/lib/{openai-codex-responses-BcnOotRB.mjs → openai-codex-responses-BL29nh9K.mjs} +204 -116
- package/lib/{openai-completions-Bq4WT47M.mjs → openai-completions-BK2f2dBv.mjs} +152 -82
- package/lib/openai-configuration-update-xMYUjaK_.mjs +150 -0
- package/lib/{openai-reasoning-fallback-DXsfiSXO.mjs → openai-reasoning-fallback-BdB3RCbj.mjs} +106 -12
- package/lib/{openai-responses-Mq_-PjvE.mjs → openai-responses-CGQPlIIy.mjs} +76 -82
- package/lib/{perplexity-XgLF73E7.mjs → perplexity-TBjz3VMB.mjs} +52 -9
- package/lib/{pkce-BlQikGPu.mjs → pkce-BYjmugmw.mjs} +1 -1
- package/lib/protobuf-aab1UGVn.mjs +717 -0
- package/lib/{provider-response-C6vcbQyO.mjs → provider-response-SqKSkkUc.mjs} +1 -1
- package/lib/{proxy-D9lm7ONA.mjs → proxy-5nWqRL1f.mjs} +45 -5
- package/lib/{readability-Cpm-ocau.mjs → readability-uGhqb4GC.mjs} +2 -2
- package/lib/reference-CtvM4zLU.mjs +114 -0
- package/lib/{request-debug-HJMoJncL.mjs → request-debug-NQN0BjHH.mjs} +1 -1
- package/lib/{sanitize-text-CfcXzw5X.mjs → sanitize-text-BCf5KmCf.mjs} +1 -1
- package/lib/{scrapers-Cg5w77td.mjs → scrapers-BpqEnqNM.mjs} +12 -12
- package/lib/{src-BcD0_rQR.mjs → src-BwW51vA5.mjs} +979 -388
- package/lib/{sse-debug-CYdjOC96.mjs → sse-debug-B-tkLCPW.mjs} +1 -1
- package/lib/{stream-Bjq8wjfr.mjs → stream-B_7qN-bA.mjs} +3802 -2623
- package/lib/stream-markup-healing-DKT1lnkW.mjs +267 -0
- package/lib/{strict-tool-validation-imVLUcbI.mjs → strict-tool-validation-CBTz1dAA.mjs} +2 -2
- package/lib/taxonomy-DSIM99rS.mjs +15392 -0
- package/lib/{stream-markup-healing-DZ6bVDxH.mjs → thinking-CiLa2LFB.mjs} +31 -186
- package/lib/{turndown-DN7ByzEI.mjs → turndown-DrX1M4WG.mjs} +4 -4
- package/lib/{type-guards-B9VVjRDK.mjs → type-guards-CttAANEx.mjs} +1 -1
- package/lib/types/client/BashPlusCard.d.ts +53 -0
- package/lib/types/client/ToolPlusSection.d.ts +36 -0
- package/lib/types/client/forms.d.ts +42 -0
- package/lib/types/client/index.d.ts +29 -0
- package/lib/types/client/locales.d.ts +19 -0
- package/lib/types/client/rm-safe-status-text.d.ts +15 -0
- package/lib/types/client/rows.d.ts +107 -0
- package/lib/types/client/web-connection-rpc.d.ts +22 -0
- package/lib/types/config/fields.d.ts +85 -0
- package/lib/types/config/omp-settings.d.ts +21 -0
- package/lib/types/config/settings.d.ts +212 -0
- package/lib/types/config/truncate.d.ts +27 -0
- package/lib/types/host/browser-probe-rpc.d.ts +29 -0
- package/lib/types/index.d.ts +6 -0
- package/lib/types/tools/ast-edit/adapter/index.d.ts +26 -0
- package/lib/types/tools/ast-edit/adapter/sdk.d.ts +49 -0
- package/lib/types/tools/ast-grep/adapter/index.d.ts +31 -0
- package/lib/types/tools/ast-grep/adapter/sdk.d.ts +44 -0
- package/lib/types/tools/bash/adapter/spill.d.ts +34 -0
- package/lib/types/tools/bash/background.d.ts +40 -0
- package/lib/types/tools/bash/bash-executor.d.ts +102 -0
- package/lib/types/tools/bash/bash-interceptor.d.ts +33 -0
- package/lib/types/tools/bash/cd-workdir.d.ts +35 -0
- package/lib/types/tools/bash/logger.d.ts +18 -0
- package/lib/types/tools/bash/non-interactive-env.d.ts +5 -0
- package/lib/types/tools/bash/render.d.ts +46 -0
- package/lib/types/tools/bash/rm-safe-status.d.ts +62 -0
- package/lib/types/tools/bash/rm-safe.d.ts +18 -0
- package/lib/types/tools/bash/sanitize-text.d.ts +34 -0
- package/lib/types/tools/bash/shell-snapshot.d.ts +31 -0
- package/lib/types/tools/bash/shell-tokenize.d.ts +60 -0
- package/lib/types/tools/bash/streaming-output.d.ts +32 -0
- package/lib/types/tools/bash/trash-cli-main.d.ts +1 -0
- package/lib/types/tools/bash/trash-cli.d.ts +77 -0
- package/lib/types/tools/bash/types.d.ts +107 -0
- package/lib/types/tools/bash/which.d.ts +20 -0
- package/lib/types/tools/bash/windows-shell.d.ts +31 -0
- package/lib/types/tools/bash/yield.d.ts +71 -0
- package/lib/types/tools/edit/adapter/index.d.ts +57 -0
- package/lib/types/tools/edit/adapter/tools/auto-generated-guard.d.ts +10 -0
- package/lib/types/tools/edit/adapter/tools/output-meta.d.ts +34 -0
- package/lib/types/tools/edit/adapter/tools/plan-mode-guard.d.ts +21 -0
- package/lib/types/tools/glob/adapter/index.d.ts +52 -0
- package/lib/types/tools/grep/adapter/index.d.ts +53 -0
- package/lib/types/tools/grep/adapter/match-path.d.ts +1 -0
- package/lib/types/tools/hashline/native/diff-preview.d.ts +37 -0
- package/lib/types/tools/hashline/native/index.d.ts +109 -0
- package/lib/types/tools/hashline/native/normalize.d.ts +29 -0
- package/lib/types/tools/hashline/native/policy.d.ts +98 -0
- package/lib/types/tools/hashline/native/writer.d.ts +42 -0
- package/lib/types/tools/omp/browser/launch.d.ts +28 -0
- package/lib/types/tools/omp/browser/readable.d.ts +17 -0
- package/lib/types/tools/omp/config/settings-schema.d.ts +12 -0
- package/lib/types/tools/omp/config/settings.d.ts +59 -0
- package/lib/types/tools/omp/edit/apply-patch/parser.d.ts +34 -0
- package/lib/types/tools/omp/edit/details.d.ts +54 -0
- package/lib/types/tools/omp/edit/diff.d.ts +60 -0
- package/lib/types/tools/omp/edit/dispatch.d.ts +43 -0
- package/lib/types/tools/omp/edit/file-snapshot-store.d.ts +81 -0
- package/lib/types/tools/omp/edit/hashline/execute.d.ts +40 -0
- package/lib/types/tools/omp/edit/hashline/params.d.ts +6 -0
- package/lib/types/tools/omp/edit/modes/apply-patch.d.ts +25 -0
- package/lib/types/tools/omp/edit/modes/patch.d.ts +109 -0
- package/lib/types/tools/omp/edit/modes/replace.d.ts +151 -0
- package/lib/types/tools/omp/edit/normalize.d.ts +31 -0
- package/lib/types/tools/omp/edit/notebook.d.ts +50 -0
- package/lib/types/tools/omp/edit/read-file.d.ts +2 -0
- package/lib/types/tools/omp/edit/snapshot-details.d.ts +33 -0
- package/lib/types/tools/omp/extensibility/skills.d.ts +22 -0
- package/lib/types/tools/omp/internal-urls/index.d.ts +100 -0
- package/lib/types/tools/omp/internal-urls/local-protocol.d.ts +12 -0
- package/lib/types/tools/omp/internal-urls/parse.d.ts +31 -0
- package/lib/types/tools/omp/internal-urls/types.d.ts +189 -0
- package/lib/types/tools/omp/internal-urls/xd-protocol.d.ts +19 -0
- package/lib/types/tools/omp/markit/converters/docx.d.ts +6 -0
- package/lib/types/tools/omp/markit/converters/epub.d.ts +15 -0
- package/lib/types/tools/omp/markit/converters/pdf/index.d.ts +7 -0
- package/lib/types/tools/omp/markit/converters/pptx.d.ts +57 -0
- package/lib/types/tools/omp/markit/converters/xlsx.d.ts +25 -0
- package/lib/types/tools/omp/markit/index.d.ts +2 -0
- package/lib/types/tools/omp/markit/registry.d.ts +16 -0
- package/lib/types/tools/omp/markit/types.d.ts +30 -0
- package/lib/types/tools/omp/sdk.d.ts +103 -0
- package/lib/types/tools/omp/session/agent-storage.d.ts +154 -0
- package/lib/types/tools/omp/session/streaming-output.d.ts +244 -0
- package/lib/types/tools/omp/task/spawn-policy.d.ts +22 -0
- package/lib/types/tools/omp/tools/approval.d.ts +62 -0
- package/lib/types/tools/omp/tools/ast-edit.d.ts +73 -0
- package/lib/types/tools/omp/tools/ast-grep.d.ts +61 -0
- package/lib/types/tools/omp/tools/auto-generated-guard.d.ts +20 -0
- package/lib/types/tools/omp/tools/conflict-detect.d.ts +237 -0
- package/lib/types/tools/omp/tools/fetch.d.ts +103 -0
- package/lib/types/tools/omp/tools/file-recorder.d.ts +13 -0
- package/lib/types/tools/omp/tools/fs-cache-invalidation.d.ts +15 -0
- package/lib/types/tools/omp/tools/glob.d.ts +86 -0
- package/lib/types/tools/omp/tools/grep.d.ts +102 -0
- package/lib/types/tools/omp/tools/grouped-file-output.d.ts +70 -0
- package/lib/types/tools/omp/tools/index.d.ts +23 -0
- package/lib/types/tools/omp/tools/list-limit.d.ts +12 -0
- package/lib/types/tools/omp/tools/match-line-format.d.ts +11 -0
- package/lib/types/tools/omp/tools/output-meta.d.ts +160 -0
- package/lib/types/tools/omp/tools/path-utils.d.ts +326 -0
- package/lib/types/tools/omp/tools/plan-mode-guard.d.ts +33 -0
- package/lib/types/tools/omp/tools/read-archive.d.ts +16 -0
- package/lib/types/tools/omp/tools/read-format.d.ts +104 -0
- package/lib/types/tools/omp/tools/read-path-resolution.d.ts +19 -0
- package/lib/types/tools/omp/tools/read-selector.d.ts +27 -0
- package/lib/types/tools/omp/tools/read-sqlite.d.ts +16 -0
- package/lib/types/tools/omp/tools/read-summary.d.ts +15 -0
- package/lib/types/tools/omp/tools/read.d.ts +70 -0
- package/lib/types/tools/omp/tools/render-utils.d.ts +28 -0
- package/lib/types/tools/omp/tools/report-tool-issue.d.ts +149 -0
- package/lib/types/tools/omp/tools/resolve.d.ts +127 -0
- package/lib/types/tools/omp/tools/sqlite-reader.d.ts +114 -0
- package/lib/types/tools/omp/tools/tool-errors.d.ts +33 -0
- package/lib/types/tools/omp/tools/tool-result.d.ts +33 -0
- package/lib/types/tools/omp/tools/tool-timeouts.d.ts +57 -0
- package/lib/types/tools/omp/tools/write.d.ts +53 -0
- package/lib/types/tools/omp/tools/writethrough.d.ts +24 -0
- package/lib/types/tools/omp/utils/block-context.d.ts +35 -0
- package/lib/types/tools/omp/utils/cpuprofile.d.ts +51 -0
- package/lib/types/tools/omp/utils/edit-mode.d.ts +13 -0
- package/lib/types/tools/omp/utils/file-display-mode.d.ts +27 -0
- package/lib/types/tools/omp/utils/image-loading.d.ts +51 -0
- package/lib/types/tools/omp/utils/image-resize.d.ts +42 -0
- package/lib/types/tools/omp/utils/lang-from-path.d.ts +9 -0
- package/lib/types/tools/omp/utils/markit-cache.d.ts +23 -0
- package/lib/types/tools/omp/utils/markit.d.ts +30 -0
- package/lib/types/tools/omp/utils/profile-tree.d.ts +47 -0
- package/lib/types/tools/omp/utils/sample-profile.d.ts +67 -0
- package/lib/types/tools/omp/utils/sixel.d.ts +21 -0
- package/lib/types/tools/omp/utils/tools-manager.d.ts +11 -0
- package/lib/types/tools/omp/utils/turndown.d.ts +15 -0
- package/lib/types/tools/omp/utils/zip.d.ts +129 -0
- package/lib/types/tools/omp/web/browser-render.d.ts +50 -0
- package/lib/types/tools/omp/web/parallel.d.ts +68 -0
- package/lib/types/tools/omp/web/scrapers/artifacthub.d.ts +6 -0
- package/lib/types/tools/omp/web/scrapers/arxiv.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/aur.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/biorxiv.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/bluesky.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/brew.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/cheatsh.d.ts +8 -0
- package/lib/types/tools/omp/web/scrapers/chocolatey.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/choosealicense.d.ts +2 -0
- package/lib/types/tools/omp/web/scrapers/cisa-kev.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/clojars.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/coingecko.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/crates-io.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/crossref.d.ts +2 -0
- package/lib/types/tools/omp/web/scrapers/devto.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/discogs.d.ts +8 -0
- package/lib/types/tools/omp/web/scrapers/discourse.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/dockerhub.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/docs-rs.d.ts +9 -0
- package/lib/types/tools/omp/web/scrapers/fdroid.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/firefox-addons.d.ts +2 -0
- package/lib/types/tools/omp/web/scrapers/flathub.d.ts +2 -0
- package/lib/types/tools/omp/web/scrapers/github-gist.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/github.d.ts +34 -0
- package/lib/types/tools/omp/web/scrapers/gitlab.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/go-pkg.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/hackage.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/hackernews.d.ts +2 -0
- package/lib/types/tools/omp/web/scrapers/hex.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/huggingface.d.ts +2 -0
- package/lib/types/tools/omp/web/scrapers/iacr.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/index.d.ts +84 -0
- package/lib/types/tools/omp/web/scrapers/jetbrains-marketplace.d.ts +2 -0
- package/lib/types/tools/omp/web/scrapers/lemmy.d.ts +2 -0
- package/lib/types/tools/omp/web/scrapers/lobsters.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/mastodon.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/maven.d.ts +6 -0
- package/lib/types/tools/omp/web/scrapers/mdn.d.ts +2 -0
- package/lib/types/tools/omp/web/scrapers/metacpan.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/musicbrainz.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/npm.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/nuget.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/nvd.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/ollama.d.ts +2 -0
- package/lib/types/tools/omp/web/scrapers/open-vsx.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/opencorporates.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/openlibrary.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/orcid.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/osv.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/packagist.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/pub-dev.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/pubmed.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/pypi.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/rawg.d.ts +2 -0
- package/lib/types/tools/omp/web/scrapers/readthedocs.d.ts +2 -0
- package/lib/types/tools/omp/web/scrapers/reddit.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/repology.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/rfc.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/rubygems.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/searchcode.d.ts +2 -0
- package/lib/types/tools/omp/web/scrapers/sec-edgar.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/semantic-scholar.d.ts +2 -0
- package/lib/types/tools/omp/web/scrapers/snapcraft.d.ts +2 -0
- package/lib/types/tools/omp/web/scrapers/sourcegraph.d.ts +2 -0
- package/lib/types/tools/omp/web/scrapers/spdx.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/spotify.d.ts +8 -0
- package/lib/types/tools/omp/web/scrapers/stackoverflow.d.ts +6 -0
- package/lib/types/tools/omp/web/scrapers/terraform.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/tldr.d.ts +7 -0
- package/lib/types/tools/omp/web/scrapers/twitter.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/types.d.ts +90 -0
- package/lib/types/tools/omp/web/scrapers/utils.d.ts +26 -0
- package/lib/types/tools/omp/web/scrapers/vimeo.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/vscode-marketplace.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/w3c.d.ts +2 -0
- package/lib/types/tools/omp/web/scrapers/wikidata.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/wikipedia.d.ts +5 -0
- package/lib/types/tools/omp/web/scrapers/youtube.d.ts +5 -0
- package/lib/types/tools/omp/web/search/providers/utils.d.ts +49 -0
- package/lib/types/tools/omp/web/search/types.d.ts +501 -0
- package/lib/types/tools/omp/web/search/utils.d.ts +4 -0
- package/lib/types/tools/omp/workspace-tree.d.ts +42 -0
- package/lib/types/tools/read/adapter/index.d.ts +49 -0
- package/lib/types/tools/read/adapter/internal-urls/artifact-protocol.d.ts +15 -0
- package/lib/types/tools/read/adapter/internal-urls/registry-helpers.d.ts +44 -0
- package/lib/types/tools/read/adapter/registry/agent-registry.d.ts +29 -0
- package/lib/types/tools/shared/auto-generated-guard.dsh.d.ts +16 -0
- package/lib/types/tools/shared/browser-detect.d.ts +54 -0
- package/lib/types/tools/shared/browser-rpc-channel.d.ts +40 -0
- package/lib/types/tools/shared/bun-ffi-shim.d.ts +13 -0
- package/lib/types/tools/shared/bun-named-shim.d.ts +42 -0
- package/lib/types/tools/shared/bun-shim.d.ts +138 -0
- package/lib/types/tools/shared/bun-sqlite-shim.d.ts +49 -0
- package/lib/types/tools/shared/fs-promises-shim.d.ts +15 -0
- package/lib/types/tools/shared/image-bridge.d.ts +98 -0
- package/lib/types/tools/shared/omp-prompt.d.ts +47 -0
- package/lib/types/tools/shared/sandbox-policy.d.ts +38 -0
- package/lib/types/tools/shared/session-state.d.ts +51 -0
- package/lib/types/tools/shared/tool-errors.d.ts +33 -0
- package/lib/types/tools/shared/win-path-fixes.d.ts +16 -0
- package/lib/types/tools/write/adapter/index.d.ts +31 -0
- package/lib/{types-DX_bvuus.mjs → types-PVueGi9S.mjs} +2 -2
- package/lib/{utils-C-dSORPa.mjs → utils-B7A3Eu4L.mjs} +2364 -2676
- package/lib/{utils-Cp2Mxf_U.mjs → utils-CUPhpw9A.mjs} +413 -134
- package/lib/{utils-CQHPEQ3W.mjs → utils-DeWqNWV8.mjs} +2 -2
- package/lib/{vision-guard-mBmtAHx0.mjs → vision-guard-_XwsL1DF.mjs} +14 -29
- package/lib/xai-oauth-CXhnz0gO.mjs +210 -0
- package/lib/{xiaomi-7mE345KX.mjs → xiaomi-psoUItal.mjs} +8 -37
- package/lib/{zai-CeNpMV3W.mjs → zai-ApJ8HBgT.mjs} +8 -71
- package/lib/{zip-BK7UHCwX.mjs → zip-Kd602XNe.mjs} +1 -1
- package/package.json +12 -12
- package/presets/package.json +1 -1
- package/presets/tool-plus-ptc/agent.cordis.yml +1 -1
- package/presets/tool-plus-standard/agent.cordis.yml +1 -1
- package/scripts/patch-pi-natives.mjs +108 -108
- package/lib/agent_pb-Rizyt9Zg.mjs +0 -805
- package/lib/anthropic-CDmj476p.mjs +0 -262
- package/lib/api_server_pb-CDZgLMta.mjs +0 -252
- package/lib/callback-server-CFJK-jvK.mjs +0 -398
- package/lib/codex-P1dGpX7G.mjs +0 -54
- package/lib/device-code-CuXTWYwY.mjs +0 -51
- package/lib/devin-BcQwht1W.mjs +0 -114
- package/lib/devin-BvMfGevz.mjs +0 -95
- package/lib/github-copilot-B3kQl0g0.mjs +0 -104
- package/lib/gitlab-duo-BriUTP8k.mjs +0 -155
- package/lib/gitlab-duo-workflow-wK5Ljzmc.mjs +0 -91
- package/lib/google-CE5tFDod.mjs +0 -30
- package/lib/google-antigravity-C1jgNljz.mjs +0 -198
- package/lib/google-oauth-shared-BLVTvokk.mjs +0 -147
- package/lib/grammar-D-NqNUxQ.mjs +0 -49
- package/lib/identity-HNO1Oe9B.mjs +0 -219
- package/lib/kimi-DgcUpPtK.mjs +0 -236
- package/lib/markit-DtGoRE6M.mjs +0 -1417
- package/lib/minimax-code-Y3h5li9N.mjs +0 -53
- package/lib/models-DRA2c_8U.mjs +0 -104660
- package/lib/opencode-BsVw9rCD.mjs +0 -38
- package/lib/to-binary-B1BEBIPC.mjs +0 -6002
- package/lib/wafer-BlhWLweO.mjs +0 -17
- package/lib/xai-oauth-5pORHUrg.mjs +0 -446
package/lib/markit-DtGoRE6M.mjs
DELETED
|
@@ -1,1417 +0,0 @@
|
|
|
1
|
-
import { installBunShim as __installBunShim } from "./bun-shim.mjs";
|
|
2
|
-
__installBunShim();
|
|
3
|
-
import { n as fs_promises_shim_exports } from "./fs-promises-shim-Bx0fpxuk.mjs";
|
|
4
|
-
import { l as unzip, u as unzipText } from "./zip-BK7UHCwX.mjs";
|
|
5
|
-
import { n as normalizeTablesHtml, t as createTurndown } from "./turndown-DN7ByzEI.mjs";
|
|
6
|
-
import { pdfToMarkdown } from "@oh-my-pi/pi-natives";
|
|
7
|
-
import * as path from "node:path";
|
|
8
|
-
import * as zlib from "node:zlib";
|
|
9
|
-
//#region node_modules/.pnpm/@oh-my-pi+pi-utils@17.3.5/node_modules/@oh-my-pi/pi-utils/src/docx/xml.ts
|
|
10
|
-
const ENTITY_PATTERN = /&(?:#x[\da-fA-F]+|#\d+|amp|apos|gt|lt|quot);/g;
|
|
11
|
-
const ATTRIBUTE_PATTERN = /([^\s=]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;
|
|
12
|
-
function decodeEntities(value) {
|
|
13
|
-
return value.replace(ENTITY_PATTERN, (entity) => {
|
|
14
|
-
switch (entity) {
|
|
15
|
-
case "&": return "&";
|
|
16
|
-
case "'": return "'";
|
|
17
|
-
case ">": return ">";
|
|
18
|
-
case "<": return "<";
|
|
19
|
-
case """: return "\"";
|
|
20
|
-
default: {
|
|
21
|
-
const hexadecimal = entity[2] === "x";
|
|
22
|
-
const digits = entity.slice(hexadecimal ? 3 : 2, -1);
|
|
23
|
-
const codePoint = Number.parseInt(digits, hexadecimal ? 16 : 10);
|
|
24
|
-
return Number.isFinite(codePoint) ? String.fromCodePoint(codePoint) : entity;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
/** Return the namespace-independent part of an XML qualified name. */
|
|
30
|
-
function localName(name) {
|
|
31
|
-
const colon = name.indexOf(":");
|
|
32
|
-
return colon === -1 ? name : name.slice(colon + 1);
|
|
33
|
-
}
|
|
34
|
-
/** Parse XML into a small namespace-tolerant element tree. */
|
|
35
|
-
function parseXml(source) {
|
|
36
|
-
const synthetic = {
|
|
37
|
-
name: "#document",
|
|
38
|
-
attributes: /* @__PURE__ */ new Map(),
|
|
39
|
-
children: []
|
|
40
|
-
};
|
|
41
|
-
const stack = [synthetic];
|
|
42
|
-
let offset = 0;
|
|
43
|
-
while (offset < source.length) {
|
|
44
|
-
const lessThan = source.indexOf("<", offset);
|
|
45
|
-
if (lessThan === -1) {
|
|
46
|
-
const value = decodeEntities(source.slice(offset));
|
|
47
|
-
if (value) stack[stack.length - 1].children.push({
|
|
48
|
-
kind: "text",
|
|
49
|
-
value
|
|
50
|
-
});
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
if (lessThan > offset) {
|
|
54
|
-
const value = decodeEntities(source.slice(offset, lessThan));
|
|
55
|
-
if (value) stack[stack.length - 1].children.push({
|
|
56
|
-
kind: "text",
|
|
57
|
-
value
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
if (source.startsWith("<!--", lessThan)) {
|
|
61
|
-
const end = source.indexOf("-->", lessThan + 4);
|
|
62
|
-
if (end === -1) throw new Error("Invalid XML: unterminated comment");
|
|
63
|
-
offset = end + 3;
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
if (source.startsWith("<![CDATA[", lessThan)) {
|
|
67
|
-
const end = source.indexOf("]]>", lessThan + 9);
|
|
68
|
-
if (end === -1) throw new Error("Invalid XML: unterminated CDATA section");
|
|
69
|
-
stack[stack.length - 1].children.push({
|
|
70
|
-
kind: "text",
|
|
71
|
-
value: source.slice(lessThan + 9, end)
|
|
72
|
-
});
|
|
73
|
-
offset = end + 3;
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
if (source.startsWith("<?", lessThan)) {
|
|
77
|
-
const end = source.indexOf("?>", lessThan + 2);
|
|
78
|
-
if (end === -1) throw new Error("Invalid XML: unterminated processing instruction");
|
|
79
|
-
offset = end + 2;
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
if (source.startsWith("<!", lessThan)) {
|
|
83
|
-
const end = source.indexOf(">", lessThan + 2);
|
|
84
|
-
if (end === -1) throw new Error("Invalid XML: unterminated declaration");
|
|
85
|
-
offset = end + 1;
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
const end = source.indexOf(">", lessThan + 1);
|
|
89
|
-
if (end === -1) throw new Error("Invalid XML: unterminated tag");
|
|
90
|
-
const raw = source.slice(lessThan + 1, end).trim();
|
|
91
|
-
if (raw.startsWith("/")) {
|
|
92
|
-
if (stack.length === 1) throw new Error("Invalid XML: unexpected closing tag");
|
|
93
|
-
const closingName = raw.slice(1).trim();
|
|
94
|
-
const completed = stack.pop();
|
|
95
|
-
if (!completed || completed.name !== closingName) throw new Error(`Invalid XML: mismatched closing tag ${closingName}`);
|
|
96
|
-
stack[stack.length - 1].children.push({
|
|
97
|
-
kind: "element",
|
|
98
|
-
name: completed.name,
|
|
99
|
-
attributes: completed.attributes,
|
|
100
|
-
children: completed.children
|
|
101
|
-
});
|
|
102
|
-
} else {
|
|
103
|
-
const selfClosing = raw.endsWith("/");
|
|
104
|
-
const tag = selfClosing ? raw.slice(0, -1).trim() : raw;
|
|
105
|
-
const whitespace = tag.search(/\s/);
|
|
106
|
-
const name = whitespace === -1 ? tag : tag.slice(0, whitespace);
|
|
107
|
-
const attributes = /* @__PURE__ */ new Map();
|
|
108
|
-
ATTRIBUTE_PATTERN.lastIndex = whitespace === -1 ? tag.length : whitespace;
|
|
109
|
-
for (let match = ATTRIBUTE_PATTERN.exec(tag); match; match = ATTRIBUTE_PATTERN.exec(tag)) attributes.set(match[1], decodeEntities(match[2] ?? match[3] ?? ""));
|
|
110
|
-
const pending = {
|
|
111
|
-
name,
|
|
112
|
-
attributes,
|
|
113
|
-
children: []
|
|
114
|
-
};
|
|
115
|
-
if (selfClosing) stack[stack.length - 1].children.push({
|
|
116
|
-
kind: "element",
|
|
117
|
-
...pending
|
|
118
|
-
});
|
|
119
|
-
else stack.push(pending);
|
|
120
|
-
}
|
|
121
|
-
offset = end + 1;
|
|
122
|
-
}
|
|
123
|
-
if (stack.length !== 1) throw new Error(`Invalid XML: unclosed tag ${stack[stack.length - 1].name}`);
|
|
124
|
-
const roots = synthetic.children.filter((node) => node.kind === "element");
|
|
125
|
-
if (roots.length !== 1) throw new Error("Invalid XML: expected one root element");
|
|
126
|
-
return roots[0];
|
|
127
|
-
}
|
|
128
|
-
/** Return direct element children, optionally filtered by local name. */
|
|
129
|
-
function childElements(element, name) {
|
|
130
|
-
return element.children.filter((node) => node.kind === "element" && (name === void 0 || localName(node.name) === name));
|
|
131
|
-
}
|
|
132
|
-
/** Return the first direct child with the given local name. */
|
|
133
|
-
function firstChild(element, name) {
|
|
134
|
-
if (!element) return void 0;
|
|
135
|
-
return element.children.find((node) => node.kind === "element" && localName(node.name) === name);
|
|
136
|
-
}
|
|
137
|
-
/** Return an attribute by qualified or namespace-independent name. */
|
|
138
|
-
function attribute(element, name) {
|
|
139
|
-
if (!element) return void 0;
|
|
140
|
-
const exact = element.attributes.get(name);
|
|
141
|
-
if (exact !== void 0) return exact;
|
|
142
|
-
for (const [attributeName, value] of element.attributes) if (localName(attributeName) === localName(name)) return value;
|
|
143
|
-
}
|
|
144
|
-
/** Return all descendant elements with a given local name. */
|
|
145
|
-
function descendants(element, name) {
|
|
146
|
-
const matches = [];
|
|
147
|
-
for (const child of childElements(element)) {
|
|
148
|
-
if (localName(child.name) === name) matches.push(child);
|
|
149
|
-
matches.push(...descendants(child, name));
|
|
150
|
-
}
|
|
151
|
-
return matches;
|
|
152
|
-
}
|
|
153
|
-
//#endregion
|
|
154
|
-
//#region node_modules/.pnpm/@oh-my-pi+pi-utils@17.3.5/node_modules/@oh-my-pi/pi-utils/src/docx/zip.ts
|
|
155
|
-
const LOCAL_FILE_SIGNATURE = 67324752;
|
|
156
|
-
const CENTRAL_FILE_SIGNATURE = 33639248;
|
|
157
|
-
const END_SIGNATURE = 101010256;
|
|
158
|
-
const MAX_END_SEARCH = 65557;
|
|
159
|
-
const UTF8 = new TextDecoder();
|
|
160
|
-
function view(bytes) {
|
|
161
|
-
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
162
|
-
}
|
|
163
|
-
function findEndRecord(bytes) {
|
|
164
|
-
const data = view(bytes);
|
|
165
|
-
for (let offset = bytes.byteLength - 22, limit = Math.max(0, bytes.byteLength - MAX_END_SEARCH); offset >= limit; offset--) if (data.getUint32(offset, true) === END_SIGNATURE) return offset;
|
|
166
|
-
throw new Error("Invalid DOCX: missing ZIP end record");
|
|
167
|
-
}
|
|
168
|
-
/** Decode a ZIP package by walking its central directory. */
|
|
169
|
-
function readZip(bytes) {
|
|
170
|
-
if (bytes.byteLength < 22) throw new Error("Invalid DOCX: truncated ZIP package");
|
|
171
|
-
const data = view(bytes);
|
|
172
|
-
const endOffset = findEndRecord(bytes);
|
|
173
|
-
const entryCount = data.getUint16(endOffset + 10, true);
|
|
174
|
-
const centralSize = data.getUint32(endOffset + 12, true);
|
|
175
|
-
const centralOffset = data.getUint32(endOffset + 16, true);
|
|
176
|
-
if (entryCount === 65535 || centralSize === 4294967295 || centralOffset === 4294967295) throw new Error("Invalid DOCX: ZIP64 packages are not supported");
|
|
177
|
-
if (centralOffset + centralSize > bytes.byteLength) throw new Error("Invalid DOCX: truncated ZIP central directory");
|
|
178
|
-
const entries = /* @__PURE__ */ new Map();
|
|
179
|
-
let offset = centralOffset;
|
|
180
|
-
for (let index = 0; index < entryCount; index++) {
|
|
181
|
-
if (offset + 46 > bytes.byteLength || data.getUint32(offset, true) !== CENTRAL_FILE_SIGNATURE) throw new Error("Invalid DOCX: malformed ZIP central directory");
|
|
182
|
-
const flags = data.getUint16(offset + 8, true);
|
|
183
|
-
const method = data.getUint16(offset + 10, true);
|
|
184
|
-
const compressedSize = data.getUint32(offset + 20, true);
|
|
185
|
-
const uncompressedSize = data.getUint32(offset + 24, true);
|
|
186
|
-
const nameLength = data.getUint16(offset + 28, true);
|
|
187
|
-
const extraLength = data.getUint16(offset + 30, true);
|
|
188
|
-
const commentLength = data.getUint16(offset + 32, true);
|
|
189
|
-
const localOffset = data.getUint32(offset + 42, true);
|
|
190
|
-
const entryEnd = offset + 46 + nameLength + extraLength + commentLength;
|
|
191
|
-
if (entryEnd > bytes.byteLength) throw new Error("Invalid DOCX: truncated ZIP entry");
|
|
192
|
-
const name = UTF8.decode(bytes.subarray(offset + 46, offset + 46 + nameLength)).replaceAll("\\", "/");
|
|
193
|
-
if ((flags & 1) !== 0) throw new Error(`Invalid DOCX: encrypted ZIP member ${name}`);
|
|
194
|
-
if (localOffset + 30 > bytes.byteLength || data.getUint32(localOffset, true) !== LOCAL_FILE_SIGNATURE) throw new Error(`Invalid DOCX: missing local header for ${name}`);
|
|
195
|
-
const localNameLength = data.getUint16(localOffset + 26, true);
|
|
196
|
-
const localExtraLength = data.getUint16(localOffset + 28, true);
|
|
197
|
-
const payloadOffset = localOffset + 30 + localNameLength + localExtraLength;
|
|
198
|
-
const payloadEnd = payloadOffset + compressedSize;
|
|
199
|
-
if (payloadEnd > bytes.byteLength) throw new Error(`Invalid DOCX: truncated ZIP member ${name}`);
|
|
200
|
-
const compressed = bytes.subarray(payloadOffset, payloadEnd);
|
|
201
|
-
let decoded;
|
|
202
|
-
if (method === 0) decoded = compressed;
|
|
203
|
-
else if (method === 8) decoded = zlib.inflateRawSync(compressed, { maxOutputLength: Math.max(uncompressedSize, 1) });
|
|
204
|
-
else throw new Error(`Invalid DOCX: unsupported ZIP compression method ${method}`);
|
|
205
|
-
if (decoded.byteLength !== uncompressedSize) throw new Error(`Invalid DOCX: size mismatch for ZIP member ${name}`);
|
|
206
|
-
if (name && !name.endsWith("/")) entries.set(name, decoded);
|
|
207
|
-
offset = entryEnd;
|
|
208
|
-
}
|
|
209
|
-
return entries;
|
|
210
|
-
}
|
|
211
|
-
/** Decode a ZIP member as UTF-8 text. */
|
|
212
|
-
function readZipText(entries, name) {
|
|
213
|
-
const bytes = entries.get(name);
|
|
214
|
-
return bytes ? UTF8.decode(bytes) : void 0;
|
|
215
|
-
}
|
|
216
|
-
//#endregion
|
|
217
|
-
//#region node_modules/.pnpm/@oh-my-pi+pi-utils@17.3.5/node_modules/@oh-my-pi/pi-utils/src/docx/converter.ts
|
|
218
|
-
/** Mammoth-shaped helpers for configuring embedded image conversion. */
|
|
219
|
-
const images = {
|
|
220
|
-
/** Wrap an image-to-attributes callback for `convertToHtml`. */
|
|
221
|
-
imgElement(convert) {
|
|
222
|
-
return { convert };
|
|
223
|
-
} };
|
|
224
|
-
const IMAGE_CONTENT_TYPE_BY_EXTENSION = {
|
|
225
|
-
bmp: "image/bmp",
|
|
226
|
-
gif: "image/gif",
|
|
227
|
-
jpeg: "image/jpeg",
|
|
228
|
-
jpg: "image/jpeg",
|
|
229
|
-
png: "image/png",
|
|
230
|
-
svg: "image/svg+xml",
|
|
231
|
-
tif: "image/tiff",
|
|
232
|
-
tiff: "image/tiff",
|
|
233
|
-
webp: "image/webp"
|
|
234
|
-
};
|
|
235
|
-
function escapeText(value) {
|
|
236
|
-
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
237
|
-
}
|
|
238
|
-
function escapeAttribute(value) {
|
|
239
|
-
return escapeText(value).replaceAll("\"", """);
|
|
240
|
-
}
|
|
241
|
-
function enabled(property) {
|
|
242
|
-
if (!property) return void 0;
|
|
243
|
-
const value = attribute(property, "w:val")?.toLowerCase();
|
|
244
|
-
return value !== "0" && value !== "false" && value !== "off" && value !== "none";
|
|
245
|
-
}
|
|
246
|
-
function formattingFromProperties(properties) {
|
|
247
|
-
if (!properties) return {};
|
|
248
|
-
const vertical = attribute(firstChild(properties, "vertAlign"), "w:val");
|
|
249
|
-
return {
|
|
250
|
-
bold: enabled(firstChild(properties, "b")),
|
|
251
|
-
italic: enabled(firstChild(properties, "i")),
|
|
252
|
-
strike: enabled(firstChild(properties, "strike")) ?? enabled(firstChild(properties, "dstrike")),
|
|
253
|
-
vertical: vertical === "subscript" || vertical === "superscript" ? vertical : void 0
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
function mergeFormatting(base, override) {
|
|
257
|
-
return {
|
|
258
|
-
bold: override.bold ?? base.bold,
|
|
259
|
-
italic: override.italic ?? base.italic,
|
|
260
|
-
strike: override.strike ?? base.strike,
|
|
261
|
-
vertical: override.vertical ?? base.vertical
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
function parseNumberingReference(properties) {
|
|
265
|
-
const numberProperties = firstChild(properties, "numPr");
|
|
266
|
-
const id = attribute(firstChild(numberProperties, "numId"), "w:val");
|
|
267
|
-
if (!id || id === "0") return void 0;
|
|
268
|
-
const rawLevel = attribute(firstChild(numberProperties, "ilvl"), "w:val");
|
|
269
|
-
return {
|
|
270
|
-
id,
|
|
271
|
-
level: rawLevel ? Number.parseInt(rawLevel, 10) || 0 : 0
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
function parseStyles(xml) {
|
|
275
|
-
const styles = /* @__PURE__ */ new Map();
|
|
276
|
-
if (!xml) return styles;
|
|
277
|
-
const root = parseXml(xml);
|
|
278
|
-
for (const element of childElements(root, "style")) {
|
|
279
|
-
const id = attribute(element, "w:styleId");
|
|
280
|
-
const rawType = attribute(element, "w:type");
|
|
281
|
-
if (!id || rawType !== "paragraph" && rawType !== "character") continue;
|
|
282
|
-
styles.set(id, {
|
|
283
|
-
id,
|
|
284
|
-
type: rawType,
|
|
285
|
-
name: attribute(firstChild(element, "name"), "w:val") ?? id,
|
|
286
|
-
basedOn: attribute(firstChild(element, "basedOn"), "w:val"),
|
|
287
|
-
formatting: formattingFromProperties(firstChild(element, "rPr")),
|
|
288
|
-
numbering: parseNumberingReference(firstChild(element, "pPr")),
|
|
289
|
-
isDefault: attribute(element, "w:default") === "1" || attribute(element, "w:default") === "true"
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
return styles;
|
|
293
|
-
}
|
|
294
|
-
function resolveStyleFormatting(style, styles, visited = /* @__PURE__ */ new Set()) {
|
|
295
|
-
if (!style || visited.has(style.id)) return {};
|
|
296
|
-
visited.add(style.id);
|
|
297
|
-
return mergeFormatting(style.basedOn ? resolveStyleFormatting(styles.get(style.basedOn), styles, visited) : {}, style.formatting);
|
|
298
|
-
}
|
|
299
|
-
function resolveStyleNumbering(style, styles, visited = /* @__PURE__ */ new Set()) {
|
|
300
|
-
if (!style || visited.has(style.id)) return void 0;
|
|
301
|
-
visited.add(style.id);
|
|
302
|
-
return style.numbering ?? (style.basedOn ? resolveStyleNumbering(styles.get(style.basedOn), styles, visited) : void 0);
|
|
303
|
-
}
|
|
304
|
-
function parseRelationships(xml) {
|
|
305
|
-
const relationships = /* @__PURE__ */ new Map();
|
|
306
|
-
if (!xml) return relationships;
|
|
307
|
-
const root = parseXml(xml);
|
|
308
|
-
for (const element of childElements(root, "Relationship")) {
|
|
309
|
-
const id = attribute(element, "Id");
|
|
310
|
-
const target = attribute(element, "Target");
|
|
311
|
-
if (!id || !target) continue;
|
|
312
|
-
relationships.set(id, {
|
|
313
|
-
target,
|
|
314
|
-
type: attribute(element, "Type") ?? "",
|
|
315
|
-
external: attribute(element, "TargetMode") === "External"
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
return relationships;
|
|
319
|
-
}
|
|
320
|
-
function parseContentTypes(xml) {
|
|
321
|
-
const types = /* @__PURE__ */ new Map();
|
|
322
|
-
if (!xml) return types;
|
|
323
|
-
const root = parseXml(xml);
|
|
324
|
-
for (const element of childElements(root)) if (localName(element.name) === "Default") {
|
|
325
|
-
const extension = attribute(element, "Extension")?.toLowerCase();
|
|
326
|
-
const contentType = attribute(element, "ContentType");
|
|
327
|
-
if (extension && contentType) types.set(`.${extension}`, contentType);
|
|
328
|
-
} else if (localName(element.name) === "Override") {
|
|
329
|
-
const part = attribute(element, "PartName");
|
|
330
|
-
const contentType = attribute(element, "ContentType");
|
|
331
|
-
if (part && contentType) types.set(part.startsWith("/") ? part.slice(1) : part, contentType);
|
|
332
|
-
}
|
|
333
|
-
return types;
|
|
334
|
-
}
|
|
335
|
-
function parseNumbering(xml) {
|
|
336
|
-
const result = /* @__PURE__ */ new Map();
|
|
337
|
-
if (!xml) return result;
|
|
338
|
-
const root = parseXml(xml);
|
|
339
|
-
const abstractLevels = /* @__PURE__ */ new Map();
|
|
340
|
-
for (const abstract of childElements(root, "abstractNum")) {
|
|
341
|
-
const id = attribute(abstract, "w:abstractNumId");
|
|
342
|
-
if (!id) continue;
|
|
343
|
-
const levels = /* @__PURE__ */ new Map();
|
|
344
|
-
for (const level of childElements(abstract, "lvl")) {
|
|
345
|
-
const index = Number.parseInt(attribute(level, "w:ilvl") ?? "0", 10) || 0;
|
|
346
|
-
levels.set(index, { ordered: attribute(firstChild(level, "numFmt"), "w:val") !== "bullet" });
|
|
347
|
-
}
|
|
348
|
-
abstractLevels.set(id, levels);
|
|
349
|
-
}
|
|
350
|
-
for (const number of childElements(root, "num")) {
|
|
351
|
-
const id = attribute(number, "w:numId");
|
|
352
|
-
const abstractId = attribute(firstChild(number, "abstractNumId"), "w:val");
|
|
353
|
-
if (id && abstractId) result.set(id, abstractLevels.get(abstractId) ?? /* @__PURE__ */ new Map());
|
|
354
|
-
}
|
|
355
|
-
return result;
|
|
356
|
-
}
|
|
357
|
-
function parseFootnotes(xml) {
|
|
358
|
-
const notes = /* @__PURE__ */ new Map();
|
|
359
|
-
if (!xml) return notes;
|
|
360
|
-
for (const element of childElements(parseXml(xml), "footnote")) {
|
|
361
|
-
const id = attribute(element, "w:id");
|
|
362
|
-
if (id && !id.startsWith("-")) notes.set(id, element);
|
|
363
|
-
}
|
|
364
|
-
return notes;
|
|
365
|
-
}
|
|
366
|
-
function parseCustomStyles(styleMap) {
|
|
367
|
-
const lines = typeof styleMap === "string" ? styleMap.split("\n") : styleMap ?? [];
|
|
368
|
-
const mappings = [];
|
|
369
|
-
for (const line of lines) {
|
|
370
|
-
const match = /^\s*(p|r)\s*\[style-name\s*=\s*['"]([^'"]+)['"]\]\s*=>\s*([\w-]+)/i.exec(line);
|
|
371
|
-
if (!match) continue;
|
|
372
|
-
mappings.push({
|
|
373
|
-
kind: match[1].toLowerCase() === "p" ? "paragraph" : "character",
|
|
374
|
-
styleName: match[2],
|
|
375
|
-
tag: match[3]
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
return mappings;
|
|
379
|
-
}
|
|
380
|
-
function styleMapping(context, style, kind) {
|
|
381
|
-
if (!style) return void 0;
|
|
382
|
-
return context.customStyles.find((mapping) => mapping.kind === kind && mapping.styleName === style.name);
|
|
383
|
-
}
|
|
384
|
-
function warnUnrecognisedStyle(context, styleId, style, kind) {
|
|
385
|
-
const key = `${kind}:${styleId}`;
|
|
386
|
-
if (context.warnedStyles.has(key)) return;
|
|
387
|
-
context.warnedStyles.add(key);
|
|
388
|
-
const name = style?.name ?? styleId;
|
|
389
|
-
context.messages.push({
|
|
390
|
-
type: "warning",
|
|
391
|
-
message: `Unrecognised ${kind} style: '${name}' (Style ID: ${styleId})`
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
function paragraphTag(context, styleId) {
|
|
395
|
-
if (!styleId) return "p";
|
|
396
|
-
const style = context.styles.get(styleId);
|
|
397
|
-
const custom = styleMapping(context, style, "paragraph");
|
|
398
|
-
if (custom) return custom.tag;
|
|
399
|
-
const heading = context.includeDefaultStyleMap ? /^(?:heading\s*|heading)([1-6])$/i.exec(style?.name ?? styleId) : null;
|
|
400
|
-
if (heading) return `h${heading[1]}`;
|
|
401
|
-
if (!style?.isDefault && (style?.name.toLowerCase() ?? styleId.toLowerCase()) !== "normal") warnUnrecognisedStyle(context, styleId, style, "paragraph");
|
|
402
|
-
return "p";
|
|
403
|
-
}
|
|
404
|
-
function relationshipPath(target) {
|
|
405
|
-
if (target.startsWith("/")) return target.slice(1);
|
|
406
|
-
return path.posix.normalize(path.posix.join("word", target));
|
|
407
|
-
}
|
|
408
|
-
function renderFormatting(value, formatting) {
|
|
409
|
-
let html = value;
|
|
410
|
-
if (formatting.strike) html = `<s>${html}</s>`;
|
|
411
|
-
if (formatting.vertical === "subscript") html = `<sub>${html}</sub>`;
|
|
412
|
-
if (formatting.vertical === "superscript") html = `<sup>${html}</sup>`;
|
|
413
|
-
if (formatting.italic) html = `<em>${html}</em>`;
|
|
414
|
-
if (formatting.bold) html = `<strong>${html}</strong>`;
|
|
415
|
-
return html;
|
|
416
|
-
}
|
|
417
|
-
async function renderImage(element, context) {
|
|
418
|
-
const blip = descendants(element, "blip")[0];
|
|
419
|
-
const relationshipId = attribute(blip, "r:embed");
|
|
420
|
-
const relationship = relationshipId ? context.relationships.get(relationshipId) : void 0;
|
|
421
|
-
if (!relationship || relationship.external) return "";
|
|
422
|
-
const memberPath = relationshipPath(relationship.target);
|
|
423
|
-
const bytes = context.entries.get(memberPath);
|
|
424
|
-
if (!bytes) {
|
|
425
|
-
context.messages.push({
|
|
426
|
-
type: "warning",
|
|
427
|
-
message: `Could not find image ${memberPath}`
|
|
428
|
-
});
|
|
429
|
-
return "";
|
|
430
|
-
}
|
|
431
|
-
const documentProperties = descendants(element, "docPr")[0];
|
|
432
|
-
const altText = attribute(documentProperties, "descr") ?? attribute(documentProperties, "title") ?? "";
|
|
433
|
-
const extension = path.posix.extname(memberPath).toLowerCase();
|
|
434
|
-
const image = {
|
|
435
|
-
contentType: context.contentTypes.get(memberPath) ?? context.contentTypes.get(extension) ?? IMAGE_CONTENT_TYPE_BY_EXTENSION[extension.slice(1)] ?? "application/octet-stream",
|
|
436
|
-
altText,
|
|
437
|
-
async read(encoding) {
|
|
438
|
-
if (encoding !== "base64") throw new Error(`Unsupported image encoding: ${encoding}`);
|
|
439
|
-
return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
const converted = await context.convertImage.convert(image);
|
|
443
|
-
const attributes = Object.entries(converted).filter((entry) => typeof entry[1] === "string").sort(([left], [right]) => left.localeCompare(right)).map(([name, value]) => `${name}="${escapeAttribute(value)}"`).join(" ");
|
|
444
|
-
return attributes ? `<img ${attributes} />` : "<img />";
|
|
445
|
-
}
|
|
446
|
-
function renderFootnoteReference(element, context) {
|
|
447
|
-
const id = attribute(element, "w:id");
|
|
448
|
-
if (!id || !context.footnotes.has(id)) return "";
|
|
449
|
-
let ordinal = context.footnoteOrdinals.get(id);
|
|
450
|
-
if (ordinal === void 0) {
|
|
451
|
-
ordinal = context.usedFootnotes.length + 1;
|
|
452
|
-
context.footnoteOrdinals.set(id, ordinal);
|
|
453
|
-
context.usedFootnotes.push({
|
|
454
|
-
id,
|
|
455
|
-
ordinal
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
return `<sup><a href="#footnote-${escapeAttribute(id)}" id="footnote-ref-${escapeAttribute(id)}">[${ordinal}]</a></sup>`;
|
|
459
|
-
}
|
|
460
|
-
async function renderInlineChildren(element, context) {
|
|
461
|
-
let html = "";
|
|
462
|
-
for (const child of element.children) {
|
|
463
|
-
if (child.kind === "text") continue;
|
|
464
|
-
const name = localName(child.name);
|
|
465
|
-
if (name === "r") html += await renderRun(child, context);
|
|
466
|
-
else if (name === "hyperlink") {
|
|
467
|
-
const contents = await renderInlineChildren(child, context);
|
|
468
|
-
const relationshipId = attribute(child, "r:id");
|
|
469
|
-
const anchor = attribute(child, "w:anchor");
|
|
470
|
-
const target = relationshipId ? context.relationships.get(relationshipId)?.target : anchor ? `#${anchor}` : void 0;
|
|
471
|
-
html += target ? `<a href="${escapeAttribute(target)}">${contents}</a>` : contents;
|
|
472
|
-
} else if (name !== "del") html += await renderInlineChildren(child, context);
|
|
473
|
-
}
|
|
474
|
-
return html;
|
|
475
|
-
}
|
|
476
|
-
async function renderRun(run, context) {
|
|
477
|
-
const properties = firstChild(run, "rPr");
|
|
478
|
-
const styleId = attribute(firstChild(properties, "rStyle"), "w:val");
|
|
479
|
-
const style = styleId ? context.styles.get(styleId) : void 0;
|
|
480
|
-
const custom = styleMapping(context, style, "character");
|
|
481
|
-
let formatting = mergeFormatting(resolveStyleFormatting(style, context.styles), formattingFromProperties(properties));
|
|
482
|
-
if (styleId && !custom) {
|
|
483
|
-
if (context.includeDefaultStyleMap && (style?.name ?? styleId).toLowerCase() === "strong") formatting = {
|
|
484
|
-
...formatting,
|
|
485
|
-
bold: true
|
|
486
|
-
};
|
|
487
|
-
else warnUnrecognisedStyle(context, styleId, style, "run");
|
|
488
|
-
}
|
|
489
|
-
let value = "";
|
|
490
|
-
for (const child of childElements(run)) {
|
|
491
|
-
const name = localName(child.name);
|
|
492
|
-
if (name === "t" || name === "instrText") {
|
|
493
|
-
for (const node of child.children) if (node.kind === "text") value += escapeText(node.value);
|
|
494
|
-
} else if (name === "tab") value += " ";
|
|
495
|
-
else if (name === "br") {
|
|
496
|
-
if (attribute(child, "w:type") !== "page") value += "<br />";
|
|
497
|
-
} else if (name === "noBreakHyphen") value += "‑";
|
|
498
|
-
else if (name === "softHyphen") value += "";
|
|
499
|
-
else if (name === "drawing" || name === "pict") value += await renderImage(child, context);
|
|
500
|
-
else if (name === "footnoteReference") value += renderFootnoteReference(child, context);
|
|
501
|
-
}
|
|
502
|
-
let html = renderFormatting(value, formatting);
|
|
503
|
-
if (custom) html = `<${custom.tag}>${html}</${custom.tag}>`;
|
|
504
|
-
return html;
|
|
505
|
-
}
|
|
506
|
-
async function parseParagraph(element, context) {
|
|
507
|
-
const properties = firstChild(element, "pPr");
|
|
508
|
-
const styleId = attribute(firstChild(properties, "pStyle"), "w:val");
|
|
509
|
-
const style = styleId ? context.styles.get(styleId) : void 0;
|
|
510
|
-
const tag = paragraphTag(context, styleId);
|
|
511
|
-
const numberingReference = parseNumberingReference(properties) ?? resolveStyleNumbering(style, context.styles);
|
|
512
|
-
const html = await renderInlineChildren(element, context);
|
|
513
|
-
if (!html && !numberingReference) return void 0;
|
|
514
|
-
const numberingLevel = numberingReference ? context.numbering.get(numberingReference.id)?.get(numberingReference.level) : void 0;
|
|
515
|
-
return {
|
|
516
|
-
kind: "paragraph",
|
|
517
|
-
html,
|
|
518
|
-
tag,
|
|
519
|
-
list: numberingReference ? {
|
|
520
|
-
level: numberingReference.level,
|
|
521
|
-
ordered: numberingLevel?.ordered ?? true
|
|
522
|
-
} : void 0
|
|
523
|
-
};
|
|
524
|
-
}
|
|
525
|
-
function renderList(items, start, level) {
|
|
526
|
-
const ordered = items[start].list?.ordered ?? true;
|
|
527
|
-
const tag = ordered ? "ol" : "ul";
|
|
528
|
-
let html = `<${tag}>`;
|
|
529
|
-
let index = start;
|
|
530
|
-
while (index < items.length) {
|
|
531
|
-
const item = items[index];
|
|
532
|
-
const list = item.list;
|
|
533
|
-
if (!list || list.level < level || list.level === level && list.ordered !== ordered) break;
|
|
534
|
-
if (list.level > level) break;
|
|
535
|
-
html += `<li>${item.html}`;
|
|
536
|
-
index++;
|
|
537
|
-
while (index < items.length && (items[index].list?.level ?? -1) > level) {
|
|
538
|
-
const nested = renderList(items, index, items[index].list?.level ?? level + 1);
|
|
539
|
-
html += nested.html;
|
|
540
|
-
index = nested.next;
|
|
541
|
-
}
|
|
542
|
-
html += "</li>";
|
|
543
|
-
}
|
|
544
|
-
html += `</${tag}>`;
|
|
545
|
-
return {
|
|
546
|
-
html,
|
|
547
|
-
next: index
|
|
548
|
-
};
|
|
549
|
-
}
|
|
550
|
-
function renderBlocks(blocks) {
|
|
551
|
-
let html = "";
|
|
552
|
-
for (let index = 0; index < blocks.length;) {
|
|
553
|
-
const block = blocks[index];
|
|
554
|
-
if (block.kind === "html") {
|
|
555
|
-
html += block.html;
|
|
556
|
-
index++;
|
|
557
|
-
continue;
|
|
558
|
-
}
|
|
559
|
-
if (!block.list) {
|
|
560
|
-
html += `<${block.tag}>${block.html}</${block.tag}>`;
|
|
561
|
-
index++;
|
|
562
|
-
continue;
|
|
563
|
-
}
|
|
564
|
-
const listItems = [];
|
|
565
|
-
while (index < blocks.length) {
|
|
566
|
-
const candidate = blocks[index];
|
|
567
|
-
if (candidate.kind !== "paragraph" || !candidate.list) break;
|
|
568
|
-
listItems.push(candidate);
|
|
569
|
-
index++;
|
|
570
|
-
}
|
|
571
|
-
for (let itemIndex = 0; itemIndex < listItems.length;) {
|
|
572
|
-
const rendered = renderList(listItems, itemIndex, listItems[itemIndex].list?.level ?? 0);
|
|
573
|
-
html += rendered.html;
|
|
574
|
-
itemIndex = rendered.next;
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
return html;
|
|
578
|
-
}
|
|
579
|
-
async function parseTableCell(element, context) {
|
|
580
|
-
const properties = firstChild(element, "tcPr");
|
|
581
|
-
const span = Number.parseInt(attribute(firstChild(properties, "gridSpan"), "w:val") ?? "1", 10) || 1;
|
|
582
|
-
const verticalMerge = firstChild(properties, "vMerge");
|
|
583
|
-
const mergeValue = attribute(verticalMerge, "w:val");
|
|
584
|
-
const merge = verticalMerge ? mergeValue === "restart" ? "restart" : "continue" : void 0;
|
|
585
|
-
return {
|
|
586
|
-
html: renderBlocks(await parseBlocks(childElements(element), context)),
|
|
587
|
-
columnSpan: span,
|
|
588
|
-
merge
|
|
589
|
-
};
|
|
590
|
-
}
|
|
591
|
-
async function renderTable(element, context) {
|
|
592
|
-
const rows = [];
|
|
593
|
-
let active = /* @__PURE__ */ new Map();
|
|
594
|
-
for (const rowElement of childElements(element, "tr")) {
|
|
595
|
-
const row = [];
|
|
596
|
-
const nextActive = /* @__PURE__ */ new Map();
|
|
597
|
-
let column = 0;
|
|
598
|
-
const extended = /* @__PURE__ */ new Set();
|
|
599
|
-
for (const cellElement of childElements(rowElement, "tc")) {
|
|
600
|
-
const raw = await parseTableCell(cellElement, context);
|
|
601
|
-
if (raw.merge === "continue") {
|
|
602
|
-
const origin = active.get(column);
|
|
603
|
-
if (origin) {
|
|
604
|
-
if (!extended.has(origin)) {
|
|
605
|
-
origin.rowSpan++;
|
|
606
|
-
extended.add(origin);
|
|
607
|
-
}
|
|
608
|
-
for (let offset = 0; offset < raw.columnSpan; offset++) nextActive.set(column + offset, origin);
|
|
609
|
-
column += raw.columnSpan;
|
|
610
|
-
continue;
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
const cell = {
|
|
614
|
-
html: raw.html,
|
|
615
|
-
columnSpan: raw.columnSpan,
|
|
616
|
-
rowSpan: 1
|
|
617
|
-
};
|
|
618
|
-
row.push(cell);
|
|
619
|
-
if (raw.merge === "restart") for (let offset = 0; offset < raw.columnSpan; offset++) nextActive.set(column + offset, cell);
|
|
620
|
-
column += raw.columnSpan;
|
|
621
|
-
}
|
|
622
|
-
rows.push(row);
|
|
623
|
-
active = nextActive;
|
|
624
|
-
}
|
|
625
|
-
let html = "<table>";
|
|
626
|
-
for (const row of rows) {
|
|
627
|
-
html += "<tr>";
|
|
628
|
-
for (const cell of row) {
|
|
629
|
-
const columnSpan = cell.columnSpan > 1 ? ` colspan="${cell.columnSpan}"` : "";
|
|
630
|
-
const rowSpan = cell.rowSpan > 1 ? ` rowspan="${cell.rowSpan}"` : "";
|
|
631
|
-
html += `<td${columnSpan}${rowSpan}>${cell.html}</td>`;
|
|
632
|
-
}
|
|
633
|
-
html += "</tr>";
|
|
634
|
-
}
|
|
635
|
-
return `${html}</table>`;
|
|
636
|
-
}
|
|
637
|
-
async function parseBlocks(elements, context) {
|
|
638
|
-
const blocks = [];
|
|
639
|
-
for (const element of elements) {
|
|
640
|
-
const name = localName(element.name);
|
|
641
|
-
if (name === "p") {
|
|
642
|
-
const paragraph = await parseParagraph(element, context);
|
|
643
|
-
if (paragraph) blocks.push(paragraph);
|
|
644
|
-
} else if (name === "tbl") blocks.push({
|
|
645
|
-
kind: "html",
|
|
646
|
-
html: await renderTable(element, context)
|
|
647
|
-
});
|
|
648
|
-
else if (name === "sdt" || name === "customXml") blocks.push(...await parseBlocks(childElements(element), context));
|
|
649
|
-
}
|
|
650
|
-
return blocks;
|
|
651
|
-
}
|
|
652
|
-
async function renderFootnotes(context) {
|
|
653
|
-
if (context.usedFootnotes.length === 0) return "";
|
|
654
|
-
let html = "<ol>";
|
|
655
|
-
for (const note of context.usedFootnotes) {
|
|
656
|
-
const element = context.footnotes.get(note.id);
|
|
657
|
-
if (!element) continue;
|
|
658
|
-
let contents = renderBlocks(await parseBlocks(childElements(element), context));
|
|
659
|
-
const backlink = `<a href="#footnote-ref-${escapeAttribute(note.id)}">↑</a>`;
|
|
660
|
-
const lastParagraph = contents.lastIndexOf("</p>");
|
|
661
|
-
if (lastParagraph === -1) contents += backlink;
|
|
662
|
-
else contents = `${contents.slice(0, lastParagraph)} ${backlink}${contents.slice(lastParagraph)}`;
|
|
663
|
-
html += `<li id="footnote-${escapeAttribute(note.id)}">${contents}</li>`;
|
|
664
|
-
}
|
|
665
|
-
return `${html}</ol>`;
|
|
666
|
-
}
|
|
667
|
-
function defaultImageConverter() {
|
|
668
|
-
return images.imgElement(async (image) => ({
|
|
669
|
-
alt: image.altText,
|
|
670
|
-
src: `data:${image.contentType};base64,${await image.read("base64")}`
|
|
671
|
-
}));
|
|
672
|
-
}
|
|
673
|
-
/** Convert a DOCX buffer or path to mammoth-compatible HTML. */
|
|
674
|
-
async function convertToHtml(input, options = {}) {
|
|
675
|
-
const entries = readZip("buffer" in input && input.buffer ? input.buffer : await fs_promises_shim_exports.readFile(input.path));
|
|
676
|
-
const documentXml = readZipText(entries, "word/document.xml");
|
|
677
|
-
if (!documentXml) throw new Error("Invalid DOCX: missing word/document.xml");
|
|
678
|
-
const context = {
|
|
679
|
-
entries,
|
|
680
|
-
relationships: parseRelationships(readZipText(entries, "word/_rels/document.xml.rels")),
|
|
681
|
-
contentTypes: parseContentTypes(readZipText(entries, "[Content_Types].xml")),
|
|
682
|
-
styles: parseStyles(readZipText(entries, "word/styles.xml")),
|
|
683
|
-
numbering: parseNumbering(readZipText(entries, "word/numbering.xml")),
|
|
684
|
-
messages: [],
|
|
685
|
-
warnedStyles: /* @__PURE__ */ new Set(),
|
|
686
|
-
customStyles: parseCustomStyles(options.styleMap),
|
|
687
|
-
includeDefaultStyleMap: options.includeDefaultStyleMap !== false,
|
|
688
|
-
convertImage: options.convertImage ?? defaultImageConverter(),
|
|
689
|
-
footnotes: parseFootnotes(readZipText(entries, "word/footnotes.xml")),
|
|
690
|
-
usedFootnotes: [],
|
|
691
|
-
footnoteOrdinals: /* @__PURE__ */ new Map()
|
|
692
|
-
};
|
|
693
|
-
const body = firstChild(parseXml(documentXml), "body");
|
|
694
|
-
if (!body) throw new Error("Invalid DOCX: missing document body");
|
|
695
|
-
return {
|
|
696
|
-
value: renderBlocks(await parseBlocks(childElements(body), context)) + await renderFootnotes(context),
|
|
697
|
-
messages: context.messages
|
|
698
|
-
};
|
|
699
|
-
}
|
|
700
|
-
//#endregion
|
|
701
|
-
//#region node_modules/.pnpm/@oh-my-pi+pi-utils@17.3.5/node_modules/@oh-my-pi/pi-utils/src/docx.ts
|
|
702
|
-
/** Mammoth-shaped default export for drop-in consumer imports. */
|
|
703
|
-
const docx = {
|
|
704
|
-
convertToHtml,
|
|
705
|
-
images
|
|
706
|
-
};
|
|
707
|
-
//#endregion
|
|
708
|
-
//#region src/tools/omp/markit/converters/docx.ts
|
|
709
|
-
const EXTENSIONS$4 = [".docx"];
|
|
710
|
-
const MIMETYPES$4 = ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"];
|
|
711
|
-
var DocxConverter = class {
|
|
712
|
-
name = "docx";
|
|
713
|
-
accepts(streamInfo) {
|
|
714
|
-
if (streamInfo.extension && EXTENSIONS$4.includes(streamInfo.extension)) return true;
|
|
715
|
-
if (streamInfo.mimetype && MIMETYPES$4.some((m) => streamInfo.mimetype?.startsWith(m))) return true;
|
|
716
|
-
return false;
|
|
717
|
-
}
|
|
718
|
-
async convert(input, streamInfo) {
|
|
719
|
-
const imageDir = streamInfo.imageDir;
|
|
720
|
-
let imageCount = 0;
|
|
721
|
-
const convertImage = imageDir ? docx.images.imgElement((image) => {
|
|
722
|
-
imageCount++;
|
|
723
|
-
const ext = (image.contentType?.split("/")[1] || "png").replace("jpeg", "jpg");
|
|
724
|
-
const filename = `image_${imageCount}.${ext}`;
|
|
725
|
-
const filepath = path.join(imageDir, filename);
|
|
726
|
-
return image.read("base64").then(async (base64) => {
|
|
727
|
-
await Bun.write(filepath, Buffer.from(base64, "base64"));
|
|
728
|
-
return {
|
|
729
|
-
src: filepath,
|
|
730
|
-
alt: `image_${imageCount}`
|
|
731
|
-
};
|
|
732
|
-
});
|
|
733
|
-
}) : docx.images.imgElement((image) => {
|
|
734
|
-
imageCount++;
|
|
735
|
-
const contentType = image.contentType || "image/png";
|
|
736
|
-
return image.read("base64").then((base64) => {
|
|
737
|
-
return {
|
|
738
|
-
src: `data:${contentType};base64,${base64.slice(0, 0)}`,
|
|
739
|
-
alt: `image_${imageCount}`
|
|
740
|
-
};
|
|
741
|
-
});
|
|
742
|
-
});
|
|
743
|
-
const { value: html } = await docx.convertToHtml({ buffer: input }, { convertImage });
|
|
744
|
-
let markdown = createTurndown().turndown(normalizeTablesHtml(html));
|
|
745
|
-
if (!imageDir) markdown = markdown.replace(/!\[([^\]]*)\]\(data:[^)]*\)/g, "<!-- image: $1 -->");
|
|
746
|
-
return { markdown: markdown.trim() };
|
|
747
|
-
}
|
|
748
|
-
};
|
|
749
|
-
//#endregion
|
|
750
|
-
//#region node_modules/.pnpm/@oh-my-pi+pi-utils@17.3.5/node_modules/@oh-my-pi/pi-utils/src/xml.ts
|
|
751
|
-
const STANDARD_ENTITIES = {
|
|
752
|
-
amp: "&",
|
|
753
|
-
apos: "'",
|
|
754
|
-
gt: ">",
|
|
755
|
-
lt: "<",
|
|
756
|
-
quot: "\""
|
|
757
|
-
};
|
|
758
|
-
/** Parses XML into the object shape used by the document converters. */
|
|
759
|
-
var XMLParser = class {
|
|
760
|
-
#settings;
|
|
761
|
-
constructor(options = {}) {
|
|
762
|
-
this.#settings = {
|
|
763
|
-
ignoreAttributes: options.ignoreAttributes ?? true,
|
|
764
|
-
attributeNamePrefix: options.attributeNamePrefix ?? "@_",
|
|
765
|
-
textNodeName: options.textNodeName ?? "#text",
|
|
766
|
-
trimValues: options.trimValues ?? true,
|
|
767
|
-
parseTagValue: options.parseTagValue ?? true,
|
|
768
|
-
parseAttributeValue: options.parseAttributeValue ?? false,
|
|
769
|
-
processEntities: options.processEntities !== false,
|
|
770
|
-
maxTotalExpansions: typeof options.processEntities === "object" ? options.processEntities.maxTotalExpansions ?? 1e5 : 1e5,
|
|
771
|
-
isArray: options.isArray
|
|
772
|
-
};
|
|
773
|
-
}
|
|
774
|
-
/** Parses one XML document. */
|
|
775
|
-
parse(xml) {
|
|
776
|
-
return new XmlReader(xml, this.#settings).parseDocument();
|
|
777
|
-
}
|
|
778
|
-
};
|
|
779
|
-
var XmlReader = class {
|
|
780
|
-
#xml;
|
|
781
|
-
#settings;
|
|
782
|
-
#entities = /* @__PURE__ */ new Map();
|
|
783
|
-
#position = 0;
|
|
784
|
-
#expansions = 0;
|
|
785
|
-
constructor(xml, settings) {
|
|
786
|
-
this.#xml = xml.charCodeAt(0) === 65279 ? xml.slice(1) : xml;
|
|
787
|
-
this.#settings = settings;
|
|
788
|
-
}
|
|
789
|
-
parseDocument() {
|
|
790
|
-
const document = {};
|
|
791
|
-
while (this.#position < this.#xml.length) {
|
|
792
|
-
if (this.#xml.startsWith("<!--", this.#position)) {
|
|
793
|
-
this.#skipThrough("-->");
|
|
794
|
-
continue;
|
|
795
|
-
}
|
|
796
|
-
if (this.#xml.startsWith("<!DOCTYPE", this.#position)) {
|
|
797
|
-
this.#readDoctype();
|
|
798
|
-
continue;
|
|
799
|
-
}
|
|
800
|
-
if (this.#xml.startsWith("<?", this.#position)) {
|
|
801
|
-
this.#readProcessingInstruction(document);
|
|
802
|
-
continue;
|
|
803
|
-
}
|
|
804
|
-
if (this.#xml[this.#position] === "<") {
|
|
805
|
-
const element = this.#readElement("");
|
|
806
|
-
this.#addValue(document, element.name, element.name, element.value, element.leaf, null);
|
|
807
|
-
continue;
|
|
808
|
-
}
|
|
809
|
-
this.#position++;
|
|
810
|
-
}
|
|
811
|
-
return document;
|
|
812
|
-
}
|
|
813
|
-
#readElement(parentPath) {
|
|
814
|
-
this.#position++;
|
|
815
|
-
const name = this.#readName();
|
|
816
|
-
const path = parentPath ? `${parentPath}.${name}` : name;
|
|
817
|
-
const attributes = [];
|
|
818
|
-
let selfClosing = false;
|
|
819
|
-
while (this.#position < this.#xml.length) {
|
|
820
|
-
this.#skipWhitespace();
|
|
821
|
-
if (this.#xml.startsWith("/>", this.#position)) {
|
|
822
|
-
this.#position += 2;
|
|
823
|
-
selfClosing = true;
|
|
824
|
-
break;
|
|
825
|
-
}
|
|
826
|
-
if (this.#xml[this.#position] === ">") {
|
|
827
|
-
this.#position++;
|
|
828
|
-
break;
|
|
829
|
-
}
|
|
830
|
-
const attributeName = this.#readName();
|
|
831
|
-
this.#skipWhitespace();
|
|
832
|
-
let value = "true";
|
|
833
|
-
if (this.#xml[this.#position] === "=") {
|
|
834
|
-
this.#position++;
|
|
835
|
-
this.#skipWhitespace();
|
|
836
|
-
value = this.#readAttributeValue();
|
|
837
|
-
}
|
|
838
|
-
attributes.push([attributeName, value]);
|
|
839
|
-
}
|
|
840
|
-
const children = {};
|
|
841
|
-
let text = "";
|
|
842
|
-
let hasChildren = false;
|
|
843
|
-
if (!selfClosing) while (this.#position < this.#xml.length) {
|
|
844
|
-
if (this.#xml.startsWith(`</${name}`, this.#position)) {
|
|
845
|
-
this.#position += name.length + 2;
|
|
846
|
-
const close = this.#xml.indexOf(">", this.#position);
|
|
847
|
-
this.#position = close < 0 ? this.#xml.length : close + 1;
|
|
848
|
-
break;
|
|
849
|
-
}
|
|
850
|
-
if (this.#xml.startsWith("<![CDATA[", this.#position)) {
|
|
851
|
-
const end = this.#xml.indexOf("]]>", this.#position + 9);
|
|
852
|
-
const normalized = this.#xml.slice(this.#position + 9, end < 0 ? this.#xml.length : end);
|
|
853
|
-
text += this.#settings.parseTagValue ? String(coerceValue(normalized)) : normalized;
|
|
854
|
-
this.#position = end < 0 ? this.#xml.length : end + 3;
|
|
855
|
-
continue;
|
|
856
|
-
}
|
|
857
|
-
if (this.#xml.startsWith("<!--", this.#position)) {
|
|
858
|
-
this.#skipThrough("-->");
|
|
859
|
-
continue;
|
|
860
|
-
}
|
|
861
|
-
if (this.#xml.startsWith("<?", this.#position)) {
|
|
862
|
-
this.#skipThrough("?>");
|
|
863
|
-
continue;
|
|
864
|
-
}
|
|
865
|
-
if (this.#xml[this.#position] === "<") {
|
|
866
|
-
const child = this.#readElement(path);
|
|
867
|
-
hasChildren = true;
|
|
868
|
-
this.#addValue(children, child.name, `${path}.${child.name}`, child.value, child.leaf, null);
|
|
869
|
-
continue;
|
|
870
|
-
}
|
|
871
|
-
const next = this.#xml.indexOf("<", this.#position);
|
|
872
|
-
const end = next < 0 ? this.#xml.length : next;
|
|
873
|
-
const normalized = this.#normalizeText(this.#xml.slice(this.#position, end), true);
|
|
874
|
-
text += this.#settings.parseTagValue ? String(coerceValue(normalized)) : normalized;
|
|
875
|
-
this.#position = end;
|
|
876
|
-
}
|
|
877
|
-
const hasAttributes = !this.#settings.ignoreAttributes && attributes.length > 0;
|
|
878
|
-
const parsedText = this.#settings.parseTagValue ? coerceValue(text) : text;
|
|
879
|
-
if (!hasChildren && !hasAttributes) return {
|
|
880
|
-
name,
|
|
881
|
-
value: parsedText,
|
|
882
|
-
leaf: true
|
|
883
|
-
};
|
|
884
|
-
if (text !== "") children[this.#settings.textNodeName] = parsedText;
|
|
885
|
-
if (hasAttributes) for (const [attributeName, raw] of attributes) {
|
|
886
|
-
const key = `${this.#settings.attributeNamePrefix}${attributeName}`;
|
|
887
|
-
const value = this.#settings.parseAttributeValue ? coerceValue(raw) : raw;
|
|
888
|
-
this.#addValue(children, key, `${path}.${attributeName}`, value, true, true);
|
|
889
|
-
}
|
|
890
|
-
return {
|
|
891
|
-
name,
|
|
892
|
-
value: children,
|
|
893
|
-
leaf: !hasChildren
|
|
894
|
-
};
|
|
895
|
-
}
|
|
896
|
-
#readAttributeValue() {
|
|
897
|
-
const quote = this.#xml[this.#position];
|
|
898
|
-
if (quote === "\"" || quote === "'") {
|
|
899
|
-
const start = ++this.#position;
|
|
900
|
-
const end = this.#xml.indexOf(quote, start);
|
|
901
|
-
this.#position = end < 0 ? this.#xml.length : end + 1;
|
|
902
|
-
return this.#normalizeText(this.#xml.slice(start, end < 0 ? this.#xml.length : end), true);
|
|
903
|
-
}
|
|
904
|
-
const start = this.#position;
|
|
905
|
-
while (this.#position < this.#xml.length && !/[\s>]/.test(this.#xml[this.#position])) this.#position++;
|
|
906
|
-
return this.#normalizeText(this.#xml.slice(start, this.#position), true);
|
|
907
|
-
}
|
|
908
|
-
#readProcessingInstruction(target) {
|
|
909
|
-
this.#position += 2;
|
|
910
|
-
const name = this.#readName();
|
|
911
|
-
const bodyStart = this.#position;
|
|
912
|
-
const end = this.#xml.indexOf("?>", bodyStart);
|
|
913
|
-
const body = this.#xml.slice(bodyStart, end < 0 ? this.#xml.length : end);
|
|
914
|
-
this.#position = end < 0 ? this.#xml.length : end + 2;
|
|
915
|
-
const value = {};
|
|
916
|
-
let hasAttribute = false;
|
|
917
|
-
for (const match of body.matchAll(/([^\s=]+)\s*=\s*(["'])(.*?)\2/g)) if (!this.#settings.ignoreAttributes) {
|
|
918
|
-
value[`${this.#settings.attributeNamePrefix}${match[1]}`] = this.#normalizeText(match[3], true);
|
|
919
|
-
hasAttribute = true;
|
|
920
|
-
}
|
|
921
|
-
target[`?${name}`] = hasAttribute ? value : "";
|
|
922
|
-
}
|
|
923
|
-
#readDoctype() {
|
|
924
|
-
const start = this.#position;
|
|
925
|
-
let bracketDepth = 0;
|
|
926
|
-
let quote = "";
|
|
927
|
-
while (this.#position < this.#xml.length) {
|
|
928
|
-
const char = this.#xml[this.#position++];
|
|
929
|
-
if (quote) {
|
|
930
|
-
if (char === quote) quote = "";
|
|
931
|
-
} else if (char === "\"" || char === "'") quote = char;
|
|
932
|
-
else if (char === "[") bracketDepth++;
|
|
933
|
-
else if (char === "]") bracketDepth--;
|
|
934
|
-
else if (char === ">" && bracketDepth === 0) break;
|
|
935
|
-
}
|
|
936
|
-
const declaration = this.#xml.slice(start, this.#position);
|
|
937
|
-
for (const match of declaration.matchAll(/<!ENTITY\s+([^\s]+)\s+(["'])(.*?)\2\s*>/gs)) this.#entities.set(match[1], match[3]);
|
|
938
|
-
}
|
|
939
|
-
#normalizeText(value, entities) {
|
|
940
|
-
let normalized = this.#settings.trimValues ? value.trim() : value;
|
|
941
|
-
if (entities && this.#settings.processEntities && normalized.includes("&")) normalized = this.#expandEntities(normalized);
|
|
942
|
-
return normalized;
|
|
943
|
-
}
|
|
944
|
-
#expandEntities(value, stack) {
|
|
945
|
-
return value.replace(/&([A-Za-z_:][\w.:-]*);/g, (whole, name) => {
|
|
946
|
-
const standard = STANDARD_ENTITIES[name];
|
|
947
|
-
if (standard !== void 0) return standard;
|
|
948
|
-
const replacement = this.#entities.get(name);
|
|
949
|
-
if (replacement === void 0 || stack?.has(name)) return whole;
|
|
950
|
-
this.#expansions++;
|
|
951
|
-
if (this.#expansions > this.#settings.maxTotalExpansions) throw new Error("Entity expansion limit exceeded");
|
|
952
|
-
const nextStack = new Set(stack);
|
|
953
|
-
nextStack.add(name);
|
|
954
|
-
return this.#expandEntities(replacement, nextStack);
|
|
955
|
-
});
|
|
956
|
-
}
|
|
957
|
-
#addValue(target, name, path, value, leaf, attribute) {
|
|
958
|
-
if (Object.hasOwn(target, name)) {
|
|
959
|
-
const current = target[name];
|
|
960
|
-
if (Array.isArray(current)) current.push(value);
|
|
961
|
-
else target[name] = [current, value];
|
|
962
|
-
return;
|
|
963
|
-
}
|
|
964
|
-
target[name] = this.#settings.isArray?.(name, path, leaf, attribute) ?? false ? [value] : value;
|
|
965
|
-
}
|
|
966
|
-
#readName() {
|
|
967
|
-
const start = this.#position;
|
|
968
|
-
while (this.#position < this.#xml.length && !/[\s/>=]/.test(this.#xml[this.#position])) this.#position++;
|
|
969
|
-
return this.#xml.slice(start, this.#position);
|
|
970
|
-
}
|
|
971
|
-
#skipWhitespace() {
|
|
972
|
-
while (this.#position < this.#xml.length && /\s/.test(this.#xml[this.#position])) this.#position++;
|
|
973
|
-
}
|
|
974
|
-
#skipThrough(marker) {
|
|
975
|
-
const end = this.#xml.indexOf(marker, this.#position + marker.length);
|
|
976
|
-
this.#position = end < 0 ? this.#xml.length : end + marker.length;
|
|
977
|
-
}
|
|
978
|
-
};
|
|
979
|
-
function coerceValue(value) {
|
|
980
|
-
if (value === "true") return true;
|
|
981
|
-
if (value === "false") return false;
|
|
982
|
-
if (value !== "" && /^[+-]?(?:0[xX][\da-fA-F]+|(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?)$/.test(value)) return Number(value);
|
|
983
|
-
return value;
|
|
984
|
-
}
|
|
985
|
-
//#endregion
|
|
986
|
-
//#region src/tools/omp/markit/converters/epub.ts
|
|
987
|
-
const EXTENSIONS$3 = [".epub"];
|
|
988
|
-
const MIMETYPES$3 = [
|
|
989
|
-
"application/epub",
|
|
990
|
-
"application/epub+zip",
|
|
991
|
-
"application/x-epub+zip"
|
|
992
|
-
];
|
|
993
|
-
var EpubConverter = class {
|
|
994
|
-
name = "epub";
|
|
995
|
-
accepts(streamInfo) {
|
|
996
|
-
if (streamInfo.extension && EXTENSIONS$3.includes(streamInfo.extension)) return true;
|
|
997
|
-
if (streamInfo.mimetype && MIMETYPES$3.some((m) => streamInfo.mimetype?.startsWith(m))) return true;
|
|
998
|
-
return false;
|
|
999
|
-
}
|
|
1000
|
-
async convert(input, _streamInfo) {
|
|
1001
|
-
const entries = unzip(input);
|
|
1002
|
-
const parser = new XMLParser({
|
|
1003
|
-
ignoreAttributes: false,
|
|
1004
|
-
attributeNamePrefix: "@_",
|
|
1005
|
-
textNodeName: "#text",
|
|
1006
|
-
processEntities: { maxTotalExpansions: 1e6 }
|
|
1007
|
-
});
|
|
1008
|
-
const containerXml = unzipText(entries, "META-INF/container.xml");
|
|
1009
|
-
if (!containerXml) throw new Error("Invalid EPUB: missing container.xml");
|
|
1010
|
-
const rootfile = parser.parse(containerXml).container?.rootfiles?.rootfile;
|
|
1011
|
-
const opfPath = Array.isArray(rootfile) ? rootfile[0]["@_full-path"] : rootfile?.["@_full-path"];
|
|
1012
|
-
if (!opfPath) throw new Error("Invalid EPUB: missing rootfile path");
|
|
1013
|
-
const opfXml = unzipText(entries, opfPath);
|
|
1014
|
-
if (!opfXml) throw new Error("Invalid EPUB: missing content.opf");
|
|
1015
|
-
const opf = parser.parse(opfXml);
|
|
1016
|
-
const meta = opf.package?.metadata ?? {};
|
|
1017
|
-
const metadata = {
|
|
1018
|
-
title: this.getText(meta["dc:title"]),
|
|
1019
|
-
authors: this.getTextArray(meta["dc:creator"]).join(", ") || void 0,
|
|
1020
|
-
language: this.getText(meta["dc:language"]),
|
|
1021
|
-
publisher: this.getText(meta["dc:publisher"]),
|
|
1022
|
-
date: this.getText(meta["dc:date"]),
|
|
1023
|
-
description: this.getText(meta["dc:description"])
|
|
1024
|
-
};
|
|
1025
|
-
const manifestItems = opf.package?.manifest?.item;
|
|
1026
|
-
const itemList = Array.isArray(manifestItems) ? manifestItems : manifestItems ? [manifestItems] : [];
|
|
1027
|
-
const manifest = /* @__PURE__ */ new Map();
|
|
1028
|
-
for (const item of itemList) manifest.set(item["@_id"], item["@_href"]);
|
|
1029
|
-
const spineItems = opf.package?.spine?.itemref;
|
|
1030
|
-
const spineOrder = (Array.isArray(spineItems) ? spineItems : spineItems ? [spineItems] : []).map((s) => s["@_idref"]);
|
|
1031
|
-
const basePath = opfPath.includes("/") ? opfPath.substring(0, opfPath.lastIndexOf("/")) : "";
|
|
1032
|
-
const turndown = createTurndown();
|
|
1033
|
-
const sections = [];
|
|
1034
|
-
const metaLines = [];
|
|
1035
|
-
for (const key in metadata) {
|
|
1036
|
-
const value = metadata[key];
|
|
1037
|
-
if (value) metaLines.push(`**${key.charAt(0).toUpperCase() + key.slice(1)}:** ${value}`);
|
|
1038
|
-
}
|
|
1039
|
-
if (metaLines.length > 0) sections.push(metaLines.join("\n"));
|
|
1040
|
-
for (const idref of spineOrder) {
|
|
1041
|
-
const href = manifest.get(idref);
|
|
1042
|
-
if (!href) continue;
|
|
1043
|
-
const filePath = basePath ? `${basePath}/${href}` : href;
|
|
1044
|
-
const html = unzipText(entries, filePath);
|
|
1045
|
-
if (!html) continue;
|
|
1046
|
-
const cleaned = html.replace(/<script[\s\S]*?<\/script>/gi, "").replace(/<style[\s\S]*?<\/style>/gi, "");
|
|
1047
|
-
const md = turndown.turndown(normalizeTablesHtml(cleaned)).trim();
|
|
1048
|
-
if (md) sections.push(md);
|
|
1049
|
-
}
|
|
1050
|
-
return {
|
|
1051
|
-
markdown: sections.join("\n\n").trim(),
|
|
1052
|
-
title: metadata.title
|
|
1053
|
-
};
|
|
1054
|
-
}
|
|
1055
|
-
getText(node) {
|
|
1056
|
-
if (!node) return void 0;
|
|
1057
|
-
if (typeof node === "string") return node;
|
|
1058
|
-
if (node["#text"]) return String(node["#text"]);
|
|
1059
|
-
if (Array.isArray(node)) return this.getText(node[0]);
|
|
1060
|
-
}
|
|
1061
|
-
getTextArray(node) {
|
|
1062
|
-
if (!node) return [];
|
|
1063
|
-
return (Array.isArray(node) ? node : [node]).map((n) => this.getText(n)).filter(Boolean);
|
|
1064
|
-
}
|
|
1065
|
-
};
|
|
1066
|
-
//#endregion
|
|
1067
|
-
//#region src/tools/omp/markit/converters/pdf/index.ts
|
|
1068
|
-
const EXTENSIONS$2 = [".pdf"];
|
|
1069
|
-
const MIMETYPES$2 = ["application/pdf", "application/x-pdf"];
|
|
1070
|
-
/** Converts PDF buffers to Markdown through the native `pdf-inspector` bridge. */
|
|
1071
|
-
var PdfConverter = class {
|
|
1072
|
-
name = "pdf";
|
|
1073
|
-
accepts(streamInfo) {
|
|
1074
|
-
if (streamInfo.extension && EXTENSIONS$2.includes(streamInfo.extension)) return true;
|
|
1075
|
-
if (streamInfo.mimetype && MIMETYPES$2.some((m) => streamInfo.mimetype?.startsWith(m))) return true;
|
|
1076
|
-
return false;
|
|
1077
|
-
}
|
|
1078
|
-
async convert(input, _streamInfo) {
|
|
1079
|
-
const result = await pdfToMarkdown(input);
|
|
1080
|
-
const notice = result.pagesNeedingOcr.length > 0 ? `Text extraction is incomplete for PDF pages ${result.pagesNeedingOcr.join(", ")}. Those pages likely contain scanned or image content that requires OCR.` : void 0;
|
|
1081
|
-
const conversion = { markdown: notice ? [result.markdown, notice].filter(Boolean).join("\n\n") : result.markdown };
|
|
1082
|
-
if (result.title !== void 0) conversion.title = result.title;
|
|
1083
|
-
return conversion;
|
|
1084
|
-
}
|
|
1085
|
-
};
|
|
1086
|
-
//#endregion
|
|
1087
|
-
//#region src/tools/omp/markit/converters/pptx.ts
|
|
1088
|
-
const EXTENSIONS$1 = [".pptx"];
|
|
1089
|
-
const MIMETYPES$1 = ["application/vnd.openxmlformats-officedocument.presentationml.presentation"];
|
|
1090
|
-
var PptxConverter = class {
|
|
1091
|
-
name = "pptx";
|
|
1092
|
-
accepts(streamInfo) {
|
|
1093
|
-
if (streamInfo.extension && EXTENSIONS$1.includes(streamInfo.extension)) return true;
|
|
1094
|
-
if (streamInfo.mimetype && MIMETYPES$1.some((m) => streamInfo.mimetype?.startsWith(m))) return true;
|
|
1095
|
-
return false;
|
|
1096
|
-
}
|
|
1097
|
-
async convert(input, streamInfo) {
|
|
1098
|
-
const entries = unzip(input);
|
|
1099
|
-
const parser = new XMLParser({
|
|
1100
|
-
ignoreAttributes: false,
|
|
1101
|
-
attributeNamePrefix: "@_",
|
|
1102
|
-
textNodeName: "#text",
|
|
1103
|
-
processEntities: { maxTotalExpansions: 1e6 }
|
|
1104
|
-
});
|
|
1105
|
-
const presXml = unzipText(entries, "ppt/presentation.xml");
|
|
1106
|
-
if (!presXml) throw new Error("Invalid PPTX: missing presentation.xml");
|
|
1107
|
-
const sldIdList = parser.parse(presXml)["p:presentation"]?.["p:sldIdLst"]?.["p:sldId"];
|
|
1108
|
-
const sldIds = Array.isArray(sldIdList) ? sldIdList : sldIdList ? [sldIdList] : [];
|
|
1109
|
-
const relsXml = unzipText(entries, "ppt/_rels/presentation.xml.rels");
|
|
1110
|
-
const relList = (relsXml ? parser.parse(relsXml) : null)?.Relationships?.Relationship;
|
|
1111
|
-
const relArray = Array.isArray(relList) ? relList : relList ? [relList] : [];
|
|
1112
|
-
const relMap = /* @__PURE__ */ new Map();
|
|
1113
|
-
for (const r of relArray) relMap.set(r["@_Id"], r["@_Target"]);
|
|
1114
|
-
const slidePaths = [];
|
|
1115
|
-
for (const sld of sldIds) {
|
|
1116
|
-
const rId = sld["@_r:id"];
|
|
1117
|
-
const target = relMap.get(rId);
|
|
1118
|
-
if (target) slidePaths.push(`ppt/${target}`);
|
|
1119
|
-
}
|
|
1120
|
-
if (slidePaths.length === 0) {
|
|
1121
|
-
const slideFiles = Object.keys(entries).filter((f) => /^ppt\/slides\/slide\d+\.xml$/.test(f)).sort((a, b) => {
|
|
1122
|
-
return parseInt(a.match(/slide(\d+)/)?.[1] || "0", 10) - parseInt(b.match(/slide(\d+)/)?.[1] || "0", 10);
|
|
1123
|
-
});
|
|
1124
|
-
slidePaths.push(...slideFiles);
|
|
1125
|
-
}
|
|
1126
|
-
const imageDir = streamInfo.imageDir;
|
|
1127
|
-
const sections = [];
|
|
1128
|
-
let imageCount = 0;
|
|
1129
|
-
for (let i = 0; i < slidePaths.length; i++) {
|
|
1130
|
-
const slideXml = unzipText(entries, slidePaths[i]);
|
|
1131
|
-
if (!slideXml) continue;
|
|
1132
|
-
const spTree = parser.parse(slideXml)["p:sld"]?.["p:cSld"]?.["p:spTree"];
|
|
1133
|
-
if (!spTree) continue;
|
|
1134
|
-
const slideRelsPath = `${slidePaths[i].replace("slides/slide", "slides/_rels/slide")}.rels`;
|
|
1135
|
-
const slideRelsXml = unzipText(entries, slideRelsPath);
|
|
1136
|
-
const slideRelMap = /* @__PURE__ */ new Map();
|
|
1137
|
-
if (slideRelsXml) {
|
|
1138
|
-
const relItems = toList(parser.parse(slideRelsXml)?.Relationships?.Relationship);
|
|
1139
|
-
for (const r of relItems) slideRelMap.set(r["@_Id"], r["@_Target"]);
|
|
1140
|
-
}
|
|
1141
|
-
const slideLines = [`<!-- Slide ${i + 1} -->`];
|
|
1142
|
-
const shapes = spTree["p:sp"];
|
|
1143
|
-
const shapeList = Array.isArray(shapes) ? shapes : shapes ? [shapes] : [];
|
|
1144
|
-
let isTitle = true;
|
|
1145
|
-
for (const shape of shapeList) {
|
|
1146
|
-
const text = this.extractText(shape);
|
|
1147
|
-
if (!text) continue;
|
|
1148
|
-
if (isTitle) {
|
|
1149
|
-
slideLines.push(`# ${text}`);
|
|
1150
|
-
isTitle = false;
|
|
1151
|
-
} else slideLines.push(text);
|
|
1152
|
-
}
|
|
1153
|
-
const pics = toList(spTree["p:pic"]);
|
|
1154
|
-
for (const pic of pics) {
|
|
1155
|
-
const rEmbed = pic["p:blipFill"]?.["a:blip"]?.["@_r:embed"];
|
|
1156
|
-
if (!rEmbed) continue;
|
|
1157
|
-
const target = slideRelMap.get(rEmbed);
|
|
1158
|
-
if (!target) continue;
|
|
1159
|
-
const normalizedPath = (target.startsWith("/") ? target.slice(1) : `ppt/slides/${target}`).split("/").reduce((parts, seg) => {
|
|
1160
|
-
if (seg === "..") parts.pop();
|
|
1161
|
-
else parts.push(seg);
|
|
1162
|
-
return parts;
|
|
1163
|
-
}, []).join("/");
|
|
1164
|
-
const buf = entries[normalizedPath];
|
|
1165
|
-
if (!buf) continue;
|
|
1166
|
-
imageCount++;
|
|
1167
|
-
const name = pic["p:nvSpPr"]?.["p:cNvPr"]?.["@_name"] || pic["p:nvPicPr"]?.["p:cNvPr"]?.["@_name"] || `image_${imageCount}`;
|
|
1168
|
-
if (imageDir) try {
|
|
1169
|
-
const ext = normalizedPath.split(".").pop() || "png";
|
|
1170
|
-
const filename = `slide${i + 1}_${imageCount}.${ext}`;
|
|
1171
|
-
const filepath = path.join(imageDir, filename);
|
|
1172
|
-
await Bun.write(filepath, buf);
|
|
1173
|
-
slideLines.push(``);
|
|
1174
|
-
} catch {
|
|
1175
|
-
slideLines.push(`<!-- image: ${name} (slide ${i + 1}) -->`);
|
|
1176
|
-
}
|
|
1177
|
-
else slideLines.push(`<!-- image: ${name} (slide ${i + 1}) -->`);
|
|
1178
|
-
}
|
|
1179
|
-
const graphicFrames = spTree["p:graphicFrame"];
|
|
1180
|
-
const gfList = Array.isArray(graphicFrames) ? graphicFrames : graphicFrames ? [graphicFrames] : [];
|
|
1181
|
-
for (const gf of gfList) {
|
|
1182
|
-
const table = this.extractTable(gf);
|
|
1183
|
-
if (table) slideLines.push(table);
|
|
1184
|
-
}
|
|
1185
|
-
const noteFile = slidePaths[i].replace("slides/slide", "notesSlides/notesSlide");
|
|
1186
|
-
const noteXml = unzipText(entries, noteFile);
|
|
1187
|
-
if (noteXml) {
|
|
1188
|
-
const noteSpTree = parser.parse(noteXml)["p:notes"]?.["p:cSld"]?.["p:spTree"];
|
|
1189
|
-
if (noteSpTree) {
|
|
1190
|
-
const noteShapes = noteSpTree["p:sp"];
|
|
1191
|
-
const noteList = Array.isArray(noteShapes) ? noteShapes : noteShapes ? [noteShapes] : [];
|
|
1192
|
-
const noteTexts = [];
|
|
1193
|
-
for (const ns of noteList) {
|
|
1194
|
-
if (ns["p:nvSpPr"]?.["p:nvPr"]?.["p:ph"]?.["@_type"] === "sldImg") continue;
|
|
1195
|
-
const t = this.extractText(ns);
|
|
1196
|
-
if (t) noteTexts.push(t);
|
|
1197
|
-
}
|
|
1198
|
-
if (noteTexts.length > 0) {
|
|
1199
|
-
slideLines.push("\n### Notes:");
|
|
1200
|
-
slideLines.push(noteTexts.join("\n"));
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
sections.push(slideLines.join("\n"));
|
|
1205
|
-
}
|
|
1206
|
-
return { markdown: sections.join("\n\n").trim() };
|
|
1207
|
-
}
|
|
1208
|
-
extractText(shape) {
|
|
1209
|
-
const txBody = shape["p:txBody"];
|
|
1210
|
-
if (!txBody) return "";
|
|
1211
|
-
const paragraphs = txBody["a:p"];
|
|
1212
|
-
const pList = Array.isArray(paragraphs) ? paragraphs : paragraphs ? [paragraphs] : [];
|
|
1213
|
-
const lines = [];
|
|
1214
|
-
for (const p of pList) {
|
|
1215
|
-
const runs = p["a:r"];
|
|
1216
|
-
const rList = Array.isArray(runs) ? runs : runs ? [runs] : [];
|
|
1217
|
-
const parts = [];
|
|
1218
|
-
for (const r of rList) {
|
|
1219
|
-
const t = r["a:t"];
|
|
1220
|
-
if (t != null) parts.push(typeof t === "object" ? t["#text"] || "" : String(t));
|
|
1221
|
-
}
|
|
1222
|
-
if (parts.length > 0) lines.push(parts.join(""));
|
|
1223
|
-
}
|
|
1224
|
-
return lines.join("\n").trim();
|
|
1225
|
-
}
|
|
1226
|
-
extractTable(gf) {
|
|
1227
|
-
const tbl = gf?.["a:graphic"]?.["a:graphicData"]?.["a:tbl"];
|
|
1228
|
-
if (!tbl) return null;
|
|
1229
|
-
const rows = tbl["a:tr"];
|
|
1230
|
-
const rowList = Array.isArray(rows) ? rows : rows ? [rows] : [];
|
|
1231
|
-
if (rowList.length === 0) return null;
|
|
1232
|
-
const mdRows = [];
|
|
1233
|
-
for (const row of rowList) {
|
|
1234
|
-
const cells = row["a:tc"];
|
|
1235
|
-
const cellList = Array.isArray(cells) ? cells : cells ? [cells] : [];
|
|
1236
|
-
const cellTexts = [];
|
|
1237
|
-
for (const cell of cellList) {
|
|
1238
|
-
const txBody = cell["a:txBody"];
|
|
1239
|
-
if (!txBody) {
|
|
1240
|
-
cellTexts.push("");
|
|
1241
|
-
continue;
|
|
1242
|
-
}
|
|
1243
|
-
const paragraphs = txBody["a:p"];
|
|
1244
|
-
const pList = Array.isArray(paragraphs) ? paragraphs : paragraphs ? [paragraphs] : [];
|
|
1245
|
-
const parts = [];
|
|
1246
|
-
for (const p of pList) {
|
|
1247
|
-
const runs = p["a:r"];
|
|
1248
|
-
const rList = Array.isArray(runs) ? runs : runs ? [runs] : [];
|
|
1249
|
-
for (const r of rList) {
|
|
1250
|
-
const t = r["a:t"];
|
|
1251
|
-
if (t != null) parts.push(typeof t === "object" ? t["#text"] || "" : String(t));
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
cellTexts.push(parts.join(" "));
|
|
1255
|
-
}
|
|
1256
|
-
mdRows.push(cellTexts);
|
|
1257
|
-
}
|
|
1258
|
-
if (mdRows.length === 0) return null;
|
|
1259
|
-
const [header, ...body] = mdRows;
|
|
1260
|
-
const lines = [];
|
|
1261
|
-
lines.push(`| ${header.join(" | ")} |`);
|
|
1262
|
-
lines.push(`| ${header.map(() => "---").join(" | ")} |`);
|
|
1263
|
-
for (const row of body) {
|
|
1264
|
-
while (row.length < header.length) row.push("");
|
|
1265
|
-
lines.push(`| ${row.join(" | ")} |`);
|
|
1266
|
-
}
|
|
1267
|
-
return lines.join("\n");
|
|
1268
|
-
}
|
|
1269
|
-
};
|
|
1270
|
-
function toList(val) {
|
|
1271
|
-
if (!val) return [];
|
|
1272
|
-
return Array.isArray(val) ? val : [val];
|
|
1273
|
-
}
|
|
1274
|
-
//#endregion
|
|
1275
|
-
//#region src/tools/omp/markit/converters/xlsx.ts
|
|
1276
|
-
const EXTENSIONS = [".xlsx"];
|
|
1277
|
-
const MIMETYPES = ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"];
|
|
1278
|
-
var XlsxConverter = class {
|
|
1279
|
-
name = "xlsx";
|
|
1280
|
-
accepts(streamInfo) {
|
|
1281
|
-
if (streamInfo.extension && EXTENSIONS.includes(streamInfo.extension)) return true;
|
|
1282
|
-
if (streamInfo.mimetype && MIMETYPES.some((m) => streamInfo.mimetype?.startsWith(m))) return true;
|
|
1283
|
-
return false;
|
|
1284
|
-
}
|
|
1285
|
-
async convert(input, _streamInfo) {
|
|
1286
|
-
const entries = unzip(input);
|
|
1287
|
-
const parser = new XMLParser({
|
|
1288
|
-
ignoreAttributes: false,
|
|
1289
|
-
attributeNamePrefix: "@_",
|
|
1290
|
-
textNodeName: "#text",
|
|
1291
|
-
processEntities: { maxTotalExpansions: 1e6 }
|
|
1292
|
-
});
|
|
1293
|
-
const ssXml = unzipText(entries, "xl/sharedStrings.xml");
|
|
1294
|
-
const siList = (ssXml ? parser.parse(ssXml) : null)?.sst?.si;
|
|
1295
|
-
const shared = toArray(siList);
|
|
1296
|
-
const wbXml = unzipText(entries, "xl/workbook.xml");
|
|
1297
|
-
if (!wbXml) throw new Error("Invalid XLSX: missing workbook.xml");
|
|
1298
|
-
const sheets = toArray(parser.parse(wbXml).workbook?.sheets?.sheet);
|
|
1299
|
-
const relsXml = unzipText(entries, "xl/_rels/workbook.xml.rels");
|
|
1300
|
-
const relList = toArray((relsXml ? parser.parse(relsXml) : null)?.Relationships?.Relationship);
|
|
1301
|
-
const relMap = /* @__PURE__ */ new Map();
|
|
1302
|
-
for (const r of relList) relMap.set(r["@_Id"], r["@_Target"]);
|
|
1303
|
-
const sections = [];
|
|
1304
|
-
for (const sheet of sheets) {
|
|
1305
|
-
const sheetName = sheet["@_name"];
|
|
1306
|
-
const rId = sheet["@_r:id"];
|
|
1307
|
-
const target = relMap.get(rId);
|
|
1308
|
-
if (!target) continue;
|
|
1309
|
-
const sheetPath = target.startsWith("/") ? target.slice(1) : `xl/${target}`;
|
|
1310
|
-
const sheetXml = unzipText(entries, sheetPath);
|
|
1311
|
-
if (!sheetXml) continue;
|
|
1312
|
-
const rows = toArray(parser.parse(sheetXml).worksheet?.sheetData?.row);
|
|
1313
|
-
if (rows.length === 0) continue;
|
|
1314
|
-
const tableRows = [];
|
|
1315
|
-
for (const row of rows) {
|
|
1316
|
-
const cells = toArray(row.c);
|
|
1317
|
-
const values = [];
|
|
1318
|
-
for (const cell of cells) values.push(this.getCellValue(cell, shared));
|
|
1319
|
-
tableRows.push(values);
|
|
1320
|
-
}
|
|
1321
|
-
if (tableRows.length === 0) continue;
|
|
1322
|
-
const maxCols = Math.max(...tableRows.map((r) => r.length));
|
|
1323
|
-
for (const row of tableRows) while (row.length < maxCols) row.push("");
|
|
1324
|
-
sections.push(`## ${sheetName}`);
|
|
1325
|
-
const [header, ...body] = tableRows;
|
|
1326
|
-
const lines = [];
|
|
1327
|
-
lines.push(`| ${header.join(" | ")} |`);
|
|
1328
|
-
lines.push(`| ${header.map(() => "---").join(" | ")} |`);
|
|
1329
|
-
for (const row of body) lines.push(`| ${row.join(" | ")} |`);
|
|
1330
|
-
sections.push(lines.join("\n"));
|
|
1331
|
-
}
|
|
1332
|
-
return { markdown: sections.join("\n\n") };
|
|
1333
|
-
}
|
|
1334
|
-
getCellValue(cell, shared) {
|
|
1335
|
-
if (cell["@_t"] === "s") return this.getSharedString(shared, Number(cell.v));
|
|
1336
|
-
if (cell["@_t"] === "inlineStr") {
|
|
1337
|
-
const is = cell.is;
|
|
1338
|
-
if (!is) return "";
|
|
1339
|
-
if (is.t != null) return textValue(is.t);
|
|
1340
|
-
if (is.r) return toArray(is.r).map((r) => textValue(r.t)).join("");
|
|
1341
|
-
return "";
|
|
1342
|
-
}
|
|
1343
|
-
if (cell["@_t"] === "b") return cell.v === 1 || cell.v === "1" ? "TRUE" : "FALSE";
|
|
1344
|
-
if (cell.v != null) return String(cell.v);
|
|
1345
|
-
return "";
|
|
1346
|
-
}
|
|
1347
|
-
getSharedString(shared, idx) {
|
|
1348
|
-
const si = shared[idx];
|
|
1349
|
-
if (!si) return "";
|
|
1350
|
-
if (si.t != null) return textValue(si.t);
|
|
1351
|
-
if (si.r) return toArray(si.r).map((r) => textValue(r.t)).join("");
|
|
1352
|
-
return "";
|
|
1353
|
-
}
|
|
1354
|
-
};
|
|
1355
|
-
function textValue(t) {
|
|
1356
|
-
if (t == null) return "";
|
|
1357
|
-
if (typeof t === "object") return t["#text"] || "";
|
|
1358
|
-
return String(t);
|
|
1359
|
-
}
|
|
1360
|
-
function toArray(val) {
|
|
1361
|
-
if (!val) return [];
|
|
1362
|
-
return Array.isArray(val) ? val : [val];
|
|
1363
|
-
}
|
|
1364
|
-
//#endregion
|
|
1365
|
-
//#region src/tools/omp/markit/registry.ts
|
|
1366
|
-
/**
|
|
1367
|
-
* In-house document → markdown engine (replaces the `markit-ai` package).
|
|
1368
|
-
*
|
|
1369
|
-
* Only the document converters omp routes are registered (pdf, docx, pptx,
|
|
1370
|
-
* xlsx, epub). The first converter whose `accepts()` returns true and whose
|
|
1371
|
-
* `convert()` succeeds wins.
|
|
1372
|
-
*/
|
|
1373
|
-
var Markit = class {
|
|
1374
|
-
#converters;
|
|
1375
|
-
#options;
|
|
1376
|
-
constructor(options = {}) {
|
|
1377
|
-
this.#options = options;
|
|
1378
|
-
this.#converters = [
|
|
1379
|
-
new PdfConverter(),
|
|
1380
|
-
new DocxConverter(),
|
|
1381
|
-
new PptxConverter(),
|
|
1382
|
-
new XlsxConverter(),
|
|
1383
|
-
new EpubConverter()
|
|
1384
|
-
];
|
|
1385
|
-
}
|
|
1386
|
-
async convertFile(filePath, extra) {
|
|
1387
|
-
const buffer = Buffer.from(await Bun.file(filePath).arrayBuffer());
|
|
1388
|
-
const streamInfo = {
|
|
1389
|
-
localPath: filePath,
|
|
1390
|
-
extension: path.extname(filePath).toLowerCase(),
|
|
1391
|
-
filename: path.basename(filePath),
|
|
1392
|
-
...extra
|
|
1393
|
-
};
|
|
1394
|
-
return this.convert(buffer, streamInfo);
|
|
1395
|
-
}
|
|
1396
|
-
async convert(input, streamInfo) {
|
|
1397
|
-
const errors = [];
|
|
1398
|
-
for (const converter of this.#converters) {
|
|
1399
|
-
if (!converter.accepts(streamInfo)) continue;
|
|
1400
|
-
try {
|
|
1401
|
-
return await converter.convert(input, streamInfo, this.#options);
|
|
1402
|
-
} catch (err) {
|
|
1403
|
-
errors.push({
|
|
1404
|
-
converter: converter.name,
|
|
1405
|
-
error: err instanceof Error ? err : new Error(String(err))
|
|
1406
|
-
});
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1409
|
-
if (errors.length > 0) {
|
|
1410
|
-
const details = errors.map((e) => ` ${e.converter}: ${e.error.message}`).join("\n");
|
|
1411
|
-
throw new Error(`Conversion failed:\n${details}`);
|
|
1412
|
-
}
|
|
1413
|
-
throw new Error(`Unsupported format: ${streamInfo.extension || streamInfo.mimetype || "unknown"}`);
|
|
1414
|
-
}
|
|
1415
|
-
};
|
|
1416
|
-
//#endregion
|
|
1417
|
-
export { Markit };
|