@beyondwork/docx-react-component 1.0.27 → 1.0.29
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/dist/canonical-document-BLEbzL2J.d.cts +844 -0
- package/dist/canonical-document-BLEbzL2J.d.ts +844 -0
- package/dist/chunk-2FJS5GZM.js +763 -0
- package/dist/chunk-2FJS5GZM.js.map +1 -0
- package/{src/core/commands/section-layout-commands.ts → dist/chunk-2OQBZS3F.js} +106 -340
- package/dist/chunk-2OQBZS3F.js.map +1 -0
- package/dist/chunk-2S7W4KFO.js +127 -0
- package/dist/chunk-2S7W4KFO.js.map +1 -0
- package/dist/chunk-2TG72QSW.js +3874 -0
- package/dist/chunk-2TG72QSW.js.map +1 -0
- package/{src/core/commands/table-structure-commands.ts → dist/chunk-36QNIZBO.js} +126 -315
- package/dist/chunk-36QNIZBO.js.map +1 -0
- package/dist/chunk-4AQOYAW4.js +3069 -0
- package/dist/chunk-4AQOYAW4.js.map +1 -0
- package/dist/chunk-4D5EWJ3P.js +77 -0
- package/dist/chunk-4D5EWJ3P.js.map +1 -0
- package/dist/chunk-5FN54NDH.js +2257 -0
- package/dist/chunk-5FN54NDH.js.map +1 -0
- package/dist/chunk-BOYGQYRQ.js +7306 -0
- package/dist/chunk-BOYGQYRQ.js.map +1 -0
- package/dist/chunk-CN3XMECL.js +212 -0
- package/dist/chunk-CN3XMECL.js.map +1 -0
- package/dist/chunk-EBI3BX6U.js +164 -0
- package/dist/chunk-EBI3BX6U.js.map +1 -0
- package/dist/chunk-EILUG3VB.js +1275 -0
- package/dist/chunk-EILUG3VB.js.map +1 -0
- package/dist/chunk-FUDY333O.js +70 -0
- package/dist/chunk-FUDY333O.js.map +1 -0
- package/dist/chunk-GBVOWFIK.js +1237 -0
- package/dist/chunk-GBVOWFIK.js.map +1 -0
- package/dist/chunk-H4TQ3H3Y.js +262 -0
- package/dist/chunk-H4TQ3H3Y.js.map +1 -0
- package/{src/core/commands/style-commands.ts → dist/chunk-JGB3IXZO.js} +40 -113
- package/dist/chunk-JGB3IXZO.js.map +1 -0
- package/dist/chunk-KD2QRQPY.js +4342 -0
- package/dist/chunk-KD2QRQPY.js.map +1 -0
- package/dist/chunk-KLMXQVYK.js +369 -0
- package/dist/chunk-KLMXQVYK.js.map +1 -0
- package/dist/chunk-KZUG5KFQ.js +214 -0
- package/dist/chunk-KZUG5KFQ.js.map +1 -0
- package/{src/core/state/text-transaction.ts → dist/chunk-QDAQ4CJU.js} +79 -236
- package/dist/chunk-QDAQ4CJU.js.map +1 -0
- package/{src/legal/bookmarks.ts → dist/chunk-RMH72RZI.js} +44 -130
- package/dist/chunk-RMH72RZI.js.map +1 -0
- package/dist/chunk-SWKWQZXM.js +117 -0
- package/dist/chunk-SWKWQZXM.js.map +1 -0
- package/{src/core/commands/formatting-commands.ts → dist/chunk-TJBP2K4T.js} +196 -536
- package/dist/chunk-TJBP2K4T.js.map +1 -0
- package/dist/chunk-TLCEAQDQ.js +542 -0
- package/dist/chunk-TLCEAQDQ.js.map +1 -0
- package/{src/core/commands/text-commands.ts → dist/chunk-UZXBISGO.js} +86 -142
- package/dist/chunk-UZXBISGO.js.map +1 -0
- package/dist/chunk-WGBAKP3Q.js +3220 -0
- package/dist/chunk-WGBAKP3Q.js.map +1 -0
- package/dist/compare/index.cjs +5475 -0
- package/dist/compare/index.cjs.map +1 -0
- package/dist/compare/index.d.cts +114 -0
- package/dist/compare/index.d.ts +114 -0
- package/dist/compare/index.js +731 -0
- package/dist/compare/index.js.map +1 -0
- package/dist/core/commands/formatting-commands.cjs +828 -0
- package/dist/core/commands/formatting-commands.cjs.map +1 -0
- package/dist/core/commands/formatting-commands.d.cts +63 -0
- package/dist/core/commands/formatting-commands.d.ts +63 -0
- package/dist/core/commands/formatting-commands.js +37 -0
- package/dist/core/commands/formatting-commands.js.map +1 -0
- package/dist/core/commands/image-commands.cjs +2023 -0
- package/dist/core/commands/image-commands.cjs.map +1 -0
- package/dist/core/commands/image-commands.d.cts +58 -0
- package/dist/core/commands/image-commands.d.ts +58 -0
- package/dist/core/commands/image-commands.js +18 -0
- package/dist/core/commands/image-commands.js.map +1 -0
- package/dist/core/commands/section-layout-commands.cjs +477 -0
- package/dist/core/commands/section-layout-commands.cjs.map +1 -0
- package/dist/core/commands/section-layout-commands.d.cts +62 -0
- package/dist/core/commands/section-layout-commands.d.ts +62 -0
- package/dist/core/commands/section-layout-commands.js +21 -0
- package/dist/core/commands/section-layout-commands.js.map +1 -0
- package/dist/core/commands/style-commands.cjs +214 -0
- package/dist/core/commands/style-commands.cjs.map +1 -0
- package/dist/core/commands/style-commands.d.cts +13 -0
- package/dist/core/commands/style-commands.d.ts +13 -0
- package/dist/core/commands/style-commands.js +9 -0
- package/dist/core/commands/style-commands.js.map +1 -0
- package/dist/core/commands/table-structure-commands.cjs +1883 -0
- package/dist/core/commands/table-structure-commands.cjs.map +1 -0
- package/dist/core/commands/table-structure-commands.d.cts +59 -0
- package/dist/core/commands/table-structure-commands.d.ts +59 -0
- package/dist/core/commands/table-structure-commands.js +12 -0
- package/dist/core/commands/table-structure-commands.js.map +1 -0
- package/dist/core/commands/text-commands.cjs +2391 -0
- package/dist/core/commands/text-commands.cjs.map +1 -0
- package/dist/core/commands/text-commands.d.cts +24 -0
- package/dist/core/commands/text-commands.d.ts +24 -0
- package/dist/core/commands/text-commands.js +28 -0
- package/dist/core/commands/text-commands.js.map +1 -0
- package/dist/core/selection/mapping.cjs +200 -0
- package/dist/core/selection/mapping.cjs.map +1 -0
- package/dist/core/selection/mapping.d.cts +2 -0
- package/dist/core/selection/mapping.d.ts +2 -0
- package/dist/core/selection/mapping.js +31 -0
- package/dist/core/selection/mapping.js.map +1 -0
- package/dist/core/state/editor-state.cjs +2278 -0
- package/dist/core/state/editor-state.cjs.map +1 -0
- package/dist/core/state/editor-state.d.cts +2 -0
- package/dist/core/state/editor-state.d.ts +2 -0
- package/dist/core/state/editor-state.js +26 -0
- package/dist/core/state/editor-state.js.map +1 -0
- package/dist/index.cjs +38553 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +7856 -0
- package/dist/index.js.map +1 -0
- package/dist/io/docx-session.cjs +16236 -0
- package/dist/io/docx-session.cjs.map +1 -0
- package/dist/io/docx-session.d.cts +21 -0
- package/dist/io/docx-session.d.ts +21 -0
- package/dist/io/docx-session.js +18 -0
- package/dist/io/docx-session.js.map +1 -0
- package/dist/legal/index.cjs +3900 -0
- package/dist/legal/index.cjs.map +1 -0
- package/dist/legal/index.d.cts +86 -0
- package/dist/legal/index.d.ts +86 -0
- package/dist/legal/index.js +616 -0
- package/dist/legal/index.js.map +1 -0
- package/dist/public-types-7ZL_94cz.d.ts +1573 -0
- package/dist/public-types-CeMaDueh.d.cts +1573 -0
- package/dist/public-types.cjs +19 -0
- package/dist/public-types.cjs.map +1 -0
- package/dist/public-types.d.cts +2 -0
- package/dist/public-types.d.ts +2 -0
- package/dist/public-types.js +1 -0
- package/dist/public-types.js.map +1 -0
- package/dist/runtime/document-runtime.cjs +11140 -0
- package/dist/runtime/document-runtime.cjs.map +1 -0
- package/dist/runtime/document-runtime.d.cts +231 -0
- package/dist/runtime/document-runtime.d.ts +231 -0
- package/dist/runtime/document-runtime.js +21 -0
- package/dist/runtime/document-runtime.js.map +1 -0
- package/dist/structural-helpers-CilgOVhh.d.cts +10 -0
- package/dist/structural-helpers-q0Gd-eBN.d.ts +10 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.cjs +313 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.cjs.map +1 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +67 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +67 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.js +23 -0
- package/dist/ui-tailwind/editor-surface/search-plugin.js.map +1 -0
- package/dist/ui-tailwind/index.cjs +4833 -0
- package/dist/ui-tailwind/index.cjs.map +1 -0
- package/dist/ui-tailwind/index.d.cts +617 -0
- package/dist/ui-tailwind/index.d.ts +617 -0
- package/dist/ui-tailwind/index.js +575 -0
- package/dist/ui-tailwind/index.js.map +1 -0
- package/package.json +64 -54
- package/src/README.md +0 -85
- package/src/api/README.md +0 -26
- package/src/api/public-types.ts +0 -1418
- package/src/api/session-state.ts +0 -60
- package/src/compare/diff-engine.ts +0 -623
- package/src/compare/export-redlines.ts +0 -280
- package/src/compare/index.ts +0 -25
- package/src/compare/snapshot.ts +0 -97
- package/src/component-inventory.md +0 -99
- package/src/core/README.md +0 -10
- package/src/core/commands/README.md +0 -3
- package/src/core/commands/image-commands.ts +0 -373
- package/src/core/commands/index.ts +0 -1757
- package/src/core/commands/list-commands.ts +0 -565
- package/src/core/commands/paragraph-layout-commands.ts +0 -339
- package/src/core/commands/review-commands.ts +0 -108
- package/src/core/commands/structural-helpers.ts +0 -309
- package/src/core/schema/README.md +0 -3
- package/src/core/schema/text-schema.ts +0 -516
- package/src/core/search/search-text.ts +0 -357
- package/src/core/selection/README.md +0 -3
- package/src/core/selection/mapping.ts +0 -289
- package/src/core/selection/review-anchors.ts +0 -183
- package/src/core/state/README.md +0 -3
- package/src/core/state/editor-state.ts +0 -892
- package/src/formats/xlsx/io/parse-shared-strings.ts +0 -41
- package/src/formats/xlsx/io/parse-sheet.ts +0 -459
- package/src/formats/xlsx/io/parse-styles.ts +0 -59
- package/src/formats/xlsx/io/parse-workbook.ts +0 -75
- package/src/formats/xlsx/io/serialize-shared-strings.ts +0 -72
- package/src/formats/xlsx/io/serialize-sheet.ts +0 -333
- package/src/formats/xlsx/io/serialize-styles.ts +0 -98
- package/src/formats/xlsx/io/serialize-workbook.ts +0 -429
- package/src/formats/xlsx/io/xlsx-session.ts +0 -314
- package/src/formats/xlsx/model/cell.ts +0 -189
- package/src/formats/xlsx/model/sheet.ts +0 -326
- package/src/formats/xlsx/model/styles.ts +0 -118
- package/src/formats/xlsx/model/workbook.ts +0 -453
- package/src/formats/xlsx/runtime/cell-commands.ts +0 -567
- package/src/formats/xlsx/runtime/sheet-commands.ts +0 -206
- package/src/formats/xlsx/runtime/workbook-runtime.ts +0 -177
- package/src/formats/xlsx/runtime/workbook-transaction.ts +0 -822
- package/src/index.ts +0 -101
- package/src/io/README.md +0 -10
- package/src/io/docx-session.ts +0 -2882
- package/src/io/export/README.md +0 -3
- package/src/io/export/export-session.ts +0 -220
- package/src/io/export/minimal-docx.ts +0 -115
- package/src/io/export/reattach-preserved-parts.ts +0 -54
- package/src/io/export/serialize-comments.ts +0 -947
- package/src/io/export/serialize-footnotes.ts +0 -399
- package/src/io/export/serialize-headers-footers.ts +0 -372
- package/src/io/export/serialize-main-document.ts +0 -1376
- package/src/io/export/serialize-numbering.ts +0 -118
- package/src/io/export/serialize-revisions.ts +0 -389
- package/src/io/export/serialize-runtime-revisions.ts +0 -269
- package/src/io/export/serialize-tables.ts +0 -174
- package/src/io/export/split-review-boundaries.ts +0 -356
- package/src/io/normalize/README.md +0 -3
- package/src/io/normalize/normalize-text.ts +0 -639
- package/src/io/ooxml/README.md +0 -3
- package/src/io/ooxml/highlight-colors.ts +0 -39
- package/src/io/ooxml/numbering-sentinels.ts +0 -44
- package/src/io/ooxml/parse-comments.ts +0 -846
- package/src/io/ooxml/parse-complex-content.ts +0 -287
- package/src/io/ooxml/parse-fields.ts +0 -834
- package/src/io/ooxml/parse-footnotes.ts +0 -896
- package/src/io/ooxml/parse-headers-footers.ts +0 -1169
- package/src/io/ooxml/parse-inline-media.ts +0 -461
- package/src/io/ooxml/parse-main-document.ts +0 -2877
- package/src/io/ooxml/parse-numbering.ts +0 -432
- package/src/io/ooxml/parse-revisions.ts +0 -931
- package/src/io/ooxml/parse-settings.ts +0 -184
- package/src/io/ooxml/parse-shapes.ts +0 -296
- package/src/io/ooxml/parse-styles.ts +0 -463
- package/src/io/ooxml/parse-tables.ts +0 -618
- package/src/io/ooxml/parse-theme.ts +0 -346
- package/src/io/ooxml/part-manifest.ts +0 -136
- package/src/io/ooxml/revision-boundaries.ts +0 -351
- package/src/io/opc/README.md +0 -3
- package/src/io/opc/corrupt-package.ts +0 -166
- package/src/io/opc/docx-package.ts +0 -74
- package/src/io/opc/package-reader.ts +0 -325
- package/src/io/opc/package-writer.ts +0 -273
- package/src/io/source-package-provenance.ts +0 -241
- package/src/legal/cross-references.ts +0 -414
- package/src/legal/defined-terms.ts +0 -203
- package/src/legal/index.ts +0 -32
- package/src/legal/signature-blocks.ts +0 -259
- package/src/model/README.md +0 -3
- package/src/model/canonical-document.ts +0 -2632
- package/src/model/cds-1.0.0.ts +0 -212
- package/src/model/snapshot.ts +0 -649
- package/src/preservation/README.md +0 -3
- package/src/preservation/markup-compatibility.ts +0 -48
- package/src/preservation/opaque-fragment-store.ts +0 -89
- package/src/preservation/opaque-region.ts +0 -233
- package/src/preservation/package-preservation.ts +0 -113
- package/src/preservation/preserved-part-manifest.ts +0 -56
- package/src/preservation/relationship-retention.ts +0 -57
- package/src/preservation/store.ts +0 -185
- package/src/review/README.md +0 -16
- package/src/review/store/README.md +0 -3
- package/src/review/store/comment-anchors.ts +0 -70
- package/src/review/store/comment-remapping.ts +0 -154
- package/src/review/store/comment-store.ts +0 -331
- package/src/review/store/comment-thread.ts +0 -109
- package/src/review/store/revision-actions.ts +0 -394
- package/src/review/store/revision-store.ts +0 -312
- package/src/review/store/revision-types.ts +0 -171
- package/src/review/store/runtime-comment-store.ts +0 -43
- package/src/runtime/README.md +0 -3
- package/src/runtime/ai-action-policy.ts +0 -764
- package/src/runtime/collab-review-sync.ts +0 -254
- package/src/runtime/document-layout.ts +0 -332
- package/src/runtime/document-navigation.ts +0 -603
- package/src/runtime/document-runtime.ts +0 -3159
- package/src/runtime/document-search.ts +0 -145
- package/src/runtime/numbering-prefix.ts +0 -216
- package/src/runtime/page-layout-estimation.ts +0 -212
- package/src/runtime/read-only-diagnostics-runtime.ts +0 -241
- package/src/runtime/review-runtime.ts +0 -44
- package/src/runtime/revision-runtime.ts +0 -107
- package/src/runtime/session-capabilities.ts +0 -192
- package/src/runtime/story-context.ts +0 -164
- package/src/runtime/story-targeting.ts +0 -162
- package/src/runtime/surface-projection.ts +0 -1357
- package/src/runtime/table-commands.ts +0 -173
- package/src/runtime/table-schema.ts +0 -309
- package/src/runtime/view-state.ts +0 -477
- package/src/runtime/virtualized-rendering.ts +0 -258
- package/src/runtime/workflow-markup.ts +0 -353
- package/src/ui/README.md +0 -30
- package/src/ui/WordReviewEditor.tsx +0 -4097
- package/src/ui/browser-export.ts +0 -52
- package/src/ui/comments/README.md +0 -3
- package/src/ui/compatibility/README.md +0 -3
- package/src/ui/editor-command-bag.ts +0 -120
- package/src/ui/editor-runtime-boundary.ts +0 -1457
- package/src/ui/editor-shell-view.tsx +0 -142
- package/src/ui/editor-surface/README.md +0 -3
- package/src/ui/editor-surface-controller.tsx +0 -63
- package/src/ui/headless/comment-decoration-model.ts +0 -124
- package/src/ui/headless/preserve-editor-selection.ts +0 -5
- package/src/ui/headless/revision-decoration-model.ts +0 -128
- package/src/ui/headless/selection-helpers.ts +0 -54
- package/src/ui/headless/selection-toolbar-model.ts +0 -34
- package/src/ui/headless/use-editor-keyboard.ts +0 -103
- package/src/ui/review/README.md +0 -3
- package/src/ui/runtime-snapshot-selectors.ts +0 -197
- package/src/ui/shared/revision-filters.ts +0 -31
- package/src/ui/status/README.md +0 -3
- package/src/ui/theme/README.md +0 -3
- package/src/ui/toolbar/README.md +0 -3
- package/src/ui/workflow-surface-blocked-rails.ts +0 -94
- package/src/ui-tailwind/chrome/tw-alert-banner.tsx +0 -64
- package/src/ui-tailwind/chrome/tw-image-context-toolbar.tsx +0 -129
- package/src/ui-tailwind/chrome/tw-layout-panel.tsx +0 -114
- package/src/ui-tailwind/chrome/tw-object-context-toolbar.tsx +0 -34
- package/src/ui-tailwind/chrome/tw-page-ruler.tsx +0 -386
- package/src/ui-tailwind/chrome/tw-selection-toolbar.tsx +0 -186
- package/src/ui-tailwind/chrome/tw-suggestion-card.tsx +0 -139
- package/src/ui-tailwind/chrome/tw-table-context-toolbar.tsx +0 -128
- package/src/ui-tailwind/chrome/tw-unsaved-modal.tsx +0 -58
- package/src/ui-tailwind/chrome/use-before-unload.ts +0 -20
- package/src/ui-tailwind/editor-surface/perf-probe.ts +0 -179
- package/src/ui-tailwind/editor-surface/pm-collab-plugins.ts +0 -40
- package/src/ui-tailwind/editor-surface/pm-command-bridge.ts +0 -178
- package/src/ui-tailwind/editor-surface/pm-contextual-ui.ts +0 -31
- package/src/ui-tailwind/editor-surface/pm-decorations.ts +0 -427
- package/src/ui-tailwind/editor-surface/pm-position-map.ts +0 -123
- package/src/ui-tailwind/editor-surface/pm-schema.ts +0 -876
- package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +0 -504
- package/src/ui-tailwind/editor-surface/search-plugin.ts +0 -168
- package/src/ui-tailwind/editor-surface/surface-build-keys.ts +0 -61
- package/src/ui-tailwind/editor-surface/tw-caret.tsx +0 -12
- package/src/ui-tailwind/editor-surface/tw-editor-surface.tsx +0 -150
- package/src/ui-tailwind/editor-surface/tw-inline-token.tsx +0 -129
- package/src/ui-tailwind/editor-surface/tw-opaque-block.tsx +0 -58
- package/src/ui-tailwind/editor-surface/tw-paragraph-block.tsx +0 -151
- package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +0 -973
- package/src/ui-tailwind/editor-surface/tw-segment-view.tsx +0 -111
- package/src/ui-tailwind/editor-surface/tw-table-node-view.tsx +0 -436
- package/src/ui-tailwind/index.ts +0 -62
- package/src/ui-tailwind/page-chrome-model.ts +0 -27
- package/src/ui-tailwind/review/tw-comment-sidebar.tsx +0 -406
- package/src/ui-tailwind/review/tw-health-panel.tsx +0 -149
- package/src/ui-tailwind/review/tw-review-rail.tsx +0 -120
- package/src/ui-tailwind/review/tw-revision-sidebar.tsx +0 -164
- package/src/ui-tailwind/status/tw-status-bar.tsx +0 -61
- package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +0 -52
- package/src/ui-tailwind/toolbar/tw-toolbar.tsx +0 -1064
- package/src/ui-tailwind/tw-review-workspace.tsx +0 -1417
- package/src/validation/README.md +0 -3
- package/src/validation/compatibility-engine.ts +0 -634
- package/src/validation/compatibility-report.ts +0 -161
- package/src/validation/diagnostics.ts +0 -204
- package/src/validation/docx-comment-proof.ts +0 -707
- package/src/validation/import-diagnostics.ts +0 -128
- package/src/validation/low-priority-word-surfaces.ts +0 -373
- /package/{src → dist}/ui-tailwind/theme/editor-theme.css +0 -0
|
@@ -0,0 +1,3900 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/legal/index.ts
|
|
21
|
+
var legal_exports = {};
|
|
22
|
+
__export(legal_exports, {
|
|
23
|
+
assessBookmarkIntegrity: () => assessBookmarkIntegrity,
|
|
24
|
+
buildDefinedTermCatalog: () => buildDefinedTermCatalog,
|
|
25
|
+
collectBookmarksFromCanonicalDocument: () => collectBookmarksFromCanonicalDocument,
|
|
26
|
+
collectCrossReferencesFromCanonicalDocument: () => collectCrossReferencesFromCanonicalDocument,
|
|
27
|
+
collectDefinedTermsFromCanonicalDocument: () => collectDefinedTermsFromCanonicalDocument,
|
|
28
|
+
collectDefinedTermsFromDocumentXml: () => collectDefinedTermsFromDocumentXml,
|
|
29
|
+
detectCrossReferencePatterns: () => detectCrossReferencePatterns,
|
|
30
|
+
detectSignatureBlocksFromCanonicalDocument: () => detectSignatureBlocksFromCanonicalDocument,
|
|
31
|
+
isHiddenBookmarkName: () => isHiddenBookmarkName,
|
|
32
|
+
parseBookmarksFromDocumentXml: () => parseBookmarksFromDocumentXml,
|
|
33
|
+
parseCrossReferencesFromDocumentXml: () => parseCrossReferencesFromDocumentXml,
|
|
34
|
+
parseFieldReferenceInstruction: () => parseFieldReferenceInstruction
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(legal_exports);
|
|
37
|
+
|
|
38
|
+
// src/io/ooxml/parse-fields.ts
|
|
39
|
+
function parseFieldsFromParagraphXml(paragraphXml) {
|
|
40
|
+
const root = parseXml(paragraphXml);
|
|
41
|
+
const pEl = findFirstChild(root, "p");
|
|
42
|
+
const target = pEl ?? root;
|
|
43
|
+
const simpleFields = [];
|
|
44
|
+
const bookmarks = [];
|
|
45
|
+
for (const child of target.children) {
|
|
46
|
+
if (child.type !== "element") continue;
|
|
47
|
+
const name = localName(child.name);
|
|
48
|
+
if (name === "fldSimple") {
|
|
49
|
+
const field = parseFldSimple(child, paragraphXml);
|
|
50
|
+
if (field) simpleFields.push(field);
|
|
51
|
+
} else if (name === "bookmarkStart") {
|
|
52
|
+
const bk = parseBookmarkStart(child, paragraphXml);
|
|
53
|
+
if (bk) bookmarks.push(bk);
|
|
54
|
+
} else if (name === "bookmarkEnd") {
|
|
55
|
+
const bk = parseBookmarkEnd(child, paragraphXml);
|
|
56
|
+
if (bk) bookmarks.push(bk);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return { simpleFields, bookmarks };
|
|
60
|
+
}
|
|
61
|
+
function extractComplexFieldsFromBodyXml(bodyXml) {
|
|
62
|
+
const root = parseXml(bodyXml);
|
|
63
|
+
const results = [];
|
|
64
|
+
const bodyEl = findFirstChild(root, "body") ?? findFirstChild(root, "document");
|
|
65
|
+
const scanTarget = bodyEl ?? root;
|
|
66
|
+
for (const block of scanTarget.children) {
|
|
67
|
+
if (block.type !== "element") continue;
|
|
68
|
+
if (localName(block.name) !== "p") continue;
|
|
69
|
+
extractComplexFieldsFromParagraph(block, bodyXml, results);
|
|
70
|
+
}
|
|
71
|
+
return results;
|
|
72
|
+
}
|
|
73
|
+
function extractBookmarksFromBodyXml(bodyXml) {
|
|
74
|
+
const root = parseXml(bodyXml);
|
|
75
|
+
const results = [];
|
|
76
|
+
collectBookmarks(root, bodyXml, results);
|
|
77
|
+
return results;
|
|
78
|
+
}
|
|
79
|
+
function parseFldSimple(element, sourceXml) {
|
|
80
|
+
const instruction = (element.attributes["w:instr"] ?? element.attributes.instr ?? "").trim();
|
|
81
|
+
const contentXml = element.children.filter((c) => c.type === "element").map((c) => sourceXml.slice(c.start, c.end)).join("");
|
|
82
|
+
return {
|
|
83
|
+
type: "field",
|
|
84
|
+
fieldType: "simple",
|
|
85
|
+
instruction,
|
|
86
|
+
contentXml,
|
|
87
|
+
rawXml: sourceXml.slice(element.start, element.end)
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function parseBookmarkStart(element, sourceXml) {
|
|
91
|
+
const bookmarkId = element.attributes["w:id"] ?? element.attributes.id ?? "";
|
|
92
|
+
const name = element.attributes["w:name"] ?? element.attributes.name ?? "";
|
|
93
|
+
if (!bookmarkId) return void 0;
|
|
94
|
+
return {
|
|
95
|
+
type: "bookmark_start",
|
|
96
|
+
bookmarkId,
|
|
97
|
+
name,
|
|
98
|
+
rawXml: sourceXml.slice(element.start, element.end)
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function parseBookmarkEnd(element, sourceXml) {
|
|
102
|
+
const bookmarkId = element.attributes["w:id"] ?? element.attributes.id ?? "";
|
|
103
|
+
if (!bookmarkId) return void 0;
|
|
104
|
+
return {
|
|
105
|
+
type: "bookmark_end",
|
|
106
|
+
bookmarkId,
|
|
107
|
+
rawXml: sourceXml.slice(element.start, element.end)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
var FIELD_FAMILY_PATTERN = /^\s*(REF|PAGEREF|NOTEREF|TOC|PAGE|NUMPAGES|DATE|TIME|AUTHOR|FILENAME|MERGEFIELD|IF|SEQ|INDEX|TC|STYLEREF)\b/i;
|
|
111
|
+
var SUPPORTED_FAMILIES = /* @__PURE__ */ new Set(["REF", "PAGEREF", "NOTEREF", "TOC"]);
|
|
112
|
+
function classifyFieldInstruction(instruction) {
|
|
113
|
+
const trimmed = instruction.trim();
|
|
114
|
+
const match = FIELD_FAMILY_PATTERN.exec(trimmed);
|
|
115
|
+
if (!match) {
|
|
116
|
+
return { family: "UNKNOWN", supported: false };
|
|
117
|
+
}
|
|
118
|
+
const family = match[1].toUpperCase();
|
|
119
|
+
const supported = SUPPORTED_FAMILIES.has(family);
|
|
120
|
+
let target;
|
|
121
|
+
if (family === "REF" || family === "PAGEREF" || family === "NOTEREF") {
|
|
122
|
+
const targetMatch = /^\s*(?:REF|PAGEREF|NOTEREF)\s+(?:"([^"]+)"|(\S+))/i.exec(trimmed);
|
|
123
|
+
target = (targetMatch?.[1] ?? targetMatch?.[2])?.trim();
|
|
124
|
+
}
|
|
125
|
+
return { family, supported, target };
|
|
126
|
+
}
|
|
127
|
+
function extractComplexFieldsFromParagraph(paragraph, sourceXml, results) {
|
|
128
|
+
let state = "idle";
|
|
129
|
+
let instrParts = [];
|
|
130
|
+
let contentStart = -1;
|
|
131
|
+
let contentEnd = -1;
|
|
132
|
+
let fieldStart = -1;
|
|
133
|
+
for (const child of paragraph.children) {
|
|
134
|
+
if (child.type !== "element" || localName(child.name) !== "r") continue;
|
|
135
|
+
const fldChar = findFirstChildEl(child, "fldChar");
|
|
136
|
+
const instrText = findFirstChildEl(child, "instrText");
|
|
137
|
+
if (fldChar) {
|
|
138
|
+
const charType = (fldChar.attributes["w:fldCharType"] ?? fldChar.attributes.fldCharType ?? "").toLowerCase();
|
|
139
|
+
if (charType === "begin") {
|
|
140
|
+
state = "in-instr";
|
|
141
|
+
instrParts = [];
|
|
142
|
+
fieldStart = child.start;
|
|
143
|
+
contentStart = -1;
|
|
144
|
+
contentEnd = -1;
|
|
145
|
+
} else if (charType === "separate" && state === "in-instr") {
|
|
146
|
+
state = "in-content";
|
|
147
|
+
contentStart = child.end;
|
|
148
|
+
} else if (charType === "end") {
|
|
149
|
+
if (state === "in-content" || state === "in-instr") {
|
|
150
|
+
if (state === "in-content") {
|
|
151
|
+
contentEnd = child.start;
|
|
152
|
+
}
|
|
153
|
+
const instruction = instrParts.join("").trim();
|
|
154
|
+
const contentXml = contentStart >= 0 && contentEnd >= contentStart ? sourceXml.slice(contentStart, contentEnd) : "";
|
|
155
|
+
results.push({
|
|
156
|
+
type: "field",
|
|
157
|
+
fieldType: "complex",
|
|
158
|
+
instruction,
|
|
159
|
+
contentXml,
|
|
160
|
+
start: fieldStart,
|
|
161
|
+
end: child.end
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
state = "idle";
|
|
165
|
+
instrParts = [];
|
|
166
|
+
}
|
|
167
|
+
} else if (instrText && state === "in-instr") {
|
|
168
|
+
const text = instrText.children.filter((c) => c.type === "text").map((c) => c.text).join("");
|
|
169
|
+
instrParts.push(text);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function collectBookmarks(node, sourceXml, results) {
|
|
174
|
+
for (const child of node.children) {
|
|
175
|
+
if (child.type !== "element") continue;
|
|
176
|
+
const name = localName(child.name);
|
|
177
|
+
if (name === "bookmarkStart") {
|
|
178
|
+
const bk = parseBookmarkStart(child, sourceXml);
|
|
179
|
+
if (bk) results.push(bk);
|
|
180
|
+
} else if (name === "bookmarkEnd") {
|
|
181
|
+
const bk = parseBookmarkEnd(child, sourceXml);
|
|
182
|
+
if (bk) results.push(bk);
|
|
183
|
+
} else {
|
|
184
|
+
collectBookmarks(child, sourceXml, results);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function findFirstChild(node, childLocalName) {
|
|
189
|
+
return node.children.find(
|
|
190
|
+
(c) => c.type === "element" && localName(c.name) === childLocalName
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
function findFirstChildEl(node, childLocalName) {
|
|
194
|
+
return node.children.find(
|
|
195
|
+
(c) => c.type === "element" && localName(c.name) === childLocalName
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
function localName(name) {
|
|
199
|
+
const sep = name.indexOf(":");
|
|
200
|
+
return sep >= 0 ? name.slice(sep + 1) : name;
|
|
201
|
+
}
|
|
202
|
+
function parseXml(xml) {
|
|
203
|
+
const root = {
|
|
204
|
+
type: "element",
|
|
205
|
+
name: "__root__",
|
|
206
|
+
attributes: {},
|
|
207
|
+
children: [],
|
|
208
|
+
start: 0,
|
|
209
|
+
end: xml.length
|
|
210
|
+
};
|
|
211
|
+
const stack = [root];
|
|
212
|
+
let cursor = 0;
|
|
213
|
+
while (cursor < xml.length) {
|
|
214
|
+
if (xml.startsWith("<!--", cursor)) {
|
|
215
|
+
const end = xml.indexOf("-->", cursor);
|
|
216
|
+
cursor = end >= 0 ? end + 3 : xml.length;
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
if (xml.startsWith("<?", cursor)) {
|
|
220
|
+
const end = xml.indexOf("?>", cursor);
|
|
221
|
+
cursor = end >= 0 ? end + 2 : xml.length;
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
if (xml.startsWith("<![CDATA[", cursor)) {
|
|
225
|
+
const end = xml.indexOf("]]>", cursor);
|
|
226
|
+
const textEnd = end >= 0 ? end : xml.length;
|
|
227
|
+
stack[stack.length - 1]?.children.push({
|
|
228
|
+
type: "text",
|
|
229
|
+
text: xml.slice(cursor + 9, textEnd),
|
|
230
|
+
start: cursor,
|
|
231
|
+
end: end >= 0 ? end + 3 : xml.length
|
|
232
|
+
});
|
|
233
|
+
cursor = end >= 0 ? end + 3 : xml.length;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
if (xml[cursor] !== "<") {
|
|
237
|
+
const nextTag = xml.indexOf("<", cursor);
|
|
238
|
+
const end = nextTag >= 0 ? nextTag : xml.length;
|
|
239
|
+
const text = decodeXmlEntities(xml.slice(cursor, end));
|
|
240
|
+
if (text.length > 0) {
|
|
241
|
+
stack[stack.length - 1]?.children.push({ type: "text", text, start: cursor, end });
|
|
242
|
+
}
|
|
243
|
+
cursor = end;
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
if (xml[cursor + 1] === "/") {
|
|
247
|
+
const end = xml.indexOf(">", cursor);
|
|
248
|
+
if (end < 0) throw new Error("Malformed XML: missing >.");
|
|
249
|
+
const name2 = xml.slice(cursor + 2, end).trim();
|
|
250
|
+
const current = stack.pop();
|
|
251
|
+
if (!current || localName(current.name) !== localName(name2)) {
|
|
252
|
+
throw new Error(`Malformed XML: unexpected closing tag </${name2}>.`);
|
|
253
|
+
}
|
|
254
|
+
current.end = end + 1;
|
|
255
|
+
cursor = end + 1;
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
const tagEnd = findTagEnd(xml, cursor);
|
|
259
|
+
const tagBody = xml.slice(cursor + 1, tagEnd);
|
|
260
|
+
const selfClosing = /\/\s*$/.test(tagBody);
|
|
261
|
+
const { name, attributes } = parseTag(tagBody.replace(/\/\s*$/, "").trim());
|
|
262
|
+
const element = {
|
|
263
|
+
type: "element",
|
|
264
|
+
name,
|
|
265
|
+
attributes,
|
|
266
|
+
children: [],
|
|
267
|
+
start: cursor,
|
|
268
|
+
end: tagEnd + 1
|
|
269
|
+
};
|
|
270
|
+
stack[stack.length - 1]?.children.push(element);
|
|
271
|
+
if (!selfClosing) stack.push(element);
|
|
272
|
+
cursor = tagEnd + 1;
|
|
273
|
+
}
|
|
274
|
+
if (stack.length !== 1) throw new Error("Malformed XML: unclosed element.");
|
|
275
|
+
return root;
|
|
276
|
+
}
|
|
277
|
+
function parseTag(tagBody) {
|
|
278
|
+
let cursor = 0;
|
|
279
|
+
while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) cursor += 1;
|
|
280
|
+
const nameStart = cursor;
|
|
281
|
+
while (cursor < tagBody.length && !/\s/.test(tagBody[cursor] ?? "")) cursor += 1;
|
|
282
|
+
const name = tagBody.slice(nameStart, cursor);
|
|
283
|
+
const attributes = {};
|
|
284
|
+
while (cursor < tagBody.length) {
|
|
285
|
+
while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) cursor += 1;
|
|
286
|
+
if (cursor >= tagBody.length) break;
|
|
287
|
+
const keyStart = cursor;
|
|
288
|
+
while (cursor < tagBody.length && !/[\s=]/.test(tagBody[cursor] ?? "")) cursor += 1;
|
|
289
|
+
const key = tagBody.slice(keyStart, cursor);
|
|
290
|
+
while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) cursor += 1;
|
|
291
|
+
if (tagBody[cursor] !== "=") {
|
|
292
|
+
attributes[key] = "";
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
cursor += 1;
|
|
296
|
+
while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) cursor += 1;
|
|
297
|
+
const quote = tagBody[cursor];
|
|
298
|
+
if (quote !== `"` && quote !== `'`) throw new Error(`Malformed XML attribute ${key}.`);
|
|
299
|
+
cursor += 1;
|
|
300
|
+
const valueStart = cursor;
|
|
301
|
+
while (cursor < tagBody.length && tagBody[cursor] !== quote) cursor += 1;
|
|
302
|
+
attributes[key] = decodeXmlEntities(tagBody.slice(valueStart, cursor));
|
|
303
|
+
cursor += 1;
|
|
304
|
+
}
|
|
305
|
+
return { name, attributes };
|
|
306
|
+
}
|
|
307
|
+
function findTagEnd(xml, start) {
|
|
308
|
+
let cursor = start + 1;
|
|
309
|
+
let quote = null;
|
|
310
|
+
while (cursor < xml.length) {
|
|
311
|
+
const c = xml[cursor];
|
|
312
|
+
if (quote) {
|
|
313
|
+
if (c === quote) quote = null;
|
|
314
|
+
cursor += 1;
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
if (c === `"` || c === `'`) {
|
|
318
|
+
quote = c;
|
|
319
|
+
cursor += 1;
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
if (c === ">") return cursor;
|
|
323
|
+
cursor += 1;
|
|
324
|
+
}
|
|
325
|
+
throw new Error("Malformed XML: missing >.");
|
|
326
|
+
}
|
|
327
|
+
function decodeXmlEntities(value) {
|
|
328
|
+
return value.replace(/&(#x[0-9a-fA-F]+|#\d+|amp|lt|gt|quot|apos);/g, (match, entity) => {
|
|
329
|
+
switch (entity) {
|
|
330
|
+
case "amp":
|
|
331
|
+
return "&";
|
|
332
|
+
case "lt":
|
|
333
|
+
return "<";
|
|
334
|
+
case "gt":
|
|
335
|
+
return ">";
|
|
336
|
+
case "quot":
|
|
337
|
+
return `"`;
|
|
338
|
+
case "apos":
|
|
339
|
+
return `'`;
|
|
340
|
+
default:
|
|
341
|
+
if (entity.startsWith("#x")) return String.fromCodePoint(Number.parseInt(entity.slice(2), 16));
|
|
342
|
+
if (entity.startsWith("#")) return String.fromCodePoint(Number.parseInt(entity.slice(1), 10));
|
|
343
|
+
return match;
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// src/legal/bookmarks.ts
|
|
349
|
+
function parseBookmarksFromDocumentXml(xml) {
|
|
350
|
+
const bookmarks = extractBookmarksFromBodyXml(xml);
|
|
351
|
+
const openBookmarks = /* @__PURE__ */ new Map();
|
|
352
|
+
const results = [];
|
|
353
|
+
for (let index = 0; index < bookmarks.length; index += 1) {
|
|
354
|
+
const bookmark = bookmarks[index];
|
|
355
|
+
if (bookmark.type === "bookmark_start") {
|
|
356
|
+
const entry = {
|
|
357
|
+
bookmarkId: bookmark.bookmarkId,
|
|
358
|
+
name: bookmark.name,
|
|
359
|
+
hidden: isHiddenBookmarkName(bookmark.name),
|
|
360
|
+
startIndex: index
|
|
361
|
+
};
|
|
362
|
+
const stack2 = openBookmarks.get(bookmark.bookmarkId) ?? [];
|
|
363
|
+
stack2.push(entry);
|
|
364
|
+
openBookmarks.set(bookmark.bookmarkId, stack2);
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
const stack = openBookmarks.get(bookmark.bookmarkId);
|
|
368
|
+
const open = stack?.pop();
|
|
369
|
+
if (stack && stack.length === 0) {
|
|
370
|
+
openBookmarks.delete(bookmark.bookmarkId);
|
|
371
|
+
}
|
|
372
|
+
if (open) {
|
|
373
|
+
results.push({
|
|
374
|
+
bookmarkId: bookmark.bookmarkId,
|
|
375
|
+
name: open.name,
|
|
376
|
+
hidden: open.hidden,
|
|
377
|
+
source: "ooxml",
|
|
378
|
+
status: "paired",
|
|
379
|
+
startIndex: open.startIndex,
|
|
380
|
+
endIndex: index
|
|
381
|
+
});
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
results.push({
|
|
385
|
+
bookmarkId: bookmark.bookmarkId,
|
|
386
|
+
hidden: false,
|
|
387
|
+
source: "ooxml",
|
|
388
|
+
status: "end-only",
|
|
389
|
+
endIndex: index
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
for (const stack of openBookmarks.values()) {
|
|
393
|
+
for (const open of stack) {
|
|
394
|
+
results.push({
|
|
395
|
+
bookmarkId: open.bookmarkId,
|
|
396
|
+
name: open.name,
|
|
397
|
+
hidden: open.hidden,
|
|
398
|
+
source: "ooxml",
|
|
399
|
+
status: "start-only",
|
|
400
|
+
startIndex: open.startIndex
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return results.sort(compareBookmarks);
|
|
405
|
+
}
|
|
406
|
+
function collectBookmarksFromCanonicalDocument(document) {
|
|
407
|
+
const root = "content" in document ? document.content : document;
|
|
408
|
+
const sequence = [];
|
|
409
|
+
walkDocument(root, (node) => {
|
|
410
|
+
if (node.type === "bookmark_start" || node.type === "bookmark_end") {
|
|
411
|
+
sequence.push(node);
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
const openBookmarks = /* @__PURE__ */ new Map();
|
|
415
|
+
const results = [];
|
|
416
|
+
for (let index = 0; index < sequence.length; index += 1) {
|
|
417
|
+
const bookmark = sequence[index];
|
|
418
|
+
if (bookmark.type === "bookmark_start") {
|
|
419
|
+
const entry = {
|
|
420
|
+
bookmarkId: bookmark.bookmarkId,
|
|
421
|
+
name: bookmark.name,
|
|
422
|
+
hidden: isHiddenBookmarkName(bookmark.name),
|
|
423
|
+
startIndex: index
|
|
424
|
+
};
|
|
425
|
+
const stack2 = openBookmarks.get(bookmark.bookmarkId) ?? [];
|
|
426
|
+
stack2.push(entry);
|
|
427
|
+
openBookmarks.set(bookmark.bookmarkId, stack2);
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
const stack = openBookmarks.get(bookmark.bookmarkId);
|
|
431
|
+
const open = stack?.pop();
|
|
432
|
+
if (stack && stack.length === 0) {
|
|
433
|
+
openBookmarks.delete(bookmark.bookmarkId);
|
|
434
|
+
}
|
|
435
|
+
if (open) {
|
|
436
|
+
results.push({
|
|
437
|
+
bookmarkId: bookmark.bookmarkId,
|
|
438
|
+
name: open.name,
|
|
439
|
+
hidden: open.hidden,
|
|
440
|
+
source: "canonical",
|
|
441
|
+
status: "paired",
|
|
442
|
+
startIndex: open.startIndex,
|
|
443
|
+
endIndex: index
|
|
444
|
+
});
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
results.push({
|
|
448
|
+
bookmarkId: bookmark.bookmarkId,
|
|
449
|
+
hidden: false,
|
|
450
|
+
source: "canonical",
|
|
451
|
+
status: "end-only",
|
|
452
|
+
endIndex: index
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
for (const stack of openBookmarks.values()) {
|
|
456
|
+
for (const open of stack) {
|
|
457
|
+
results.push({
|
|
458
|
+
bookmarkId: open.bookmarkId,
|
|
459
|
+
name: open.name,
|
|
460
|
+
hidden: open.hidden,
|
|
461
|
+
source: "canonical",
|
|
462
|
+
status: "start-only",
|
|
463
|
+
startIndex: open.startIndex
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
return results.sort(compareBookmarks);
|
|
468
|
+
}
|
|
469
|
+
function isHiddenBookmarkName(name) {
|
|
470
|
+
return Boolean(name && name.startsWith("_"));
|
|
471
|
+
}
|
|
472
|
+
function assessBookmarkIntegrity(bookmarks) {
|
|
473
|
+
const pairedCount = bookmarks.filter((b) => b.status === "paired").length;
|
|
474
|
+
const startOnlyCount = bookmarks.filter((b) => b.status === "start-only").length;
|
|
475
|
+
const endOnlyCount = bookmarks.filter((b) => b.status === "end-only").length;
|
|
476
|
+
const hiddenCount = bookmarks.filter((b) => b.hidden).length;
|
|
477
|
+
const namedCount = bookmarks.filter((b) => b.name && !b.hidden).length;
|
|
478
|
+
const totalCount = bookmarks.length;
|
|
479
|
+
const unpairedCount = startOnlyCount + endOnlyCount;
|
|
480
|
+
return {
|
|
481
|
+
totalCount,
|
|
482
|
+
pairedCount,
|
|
483
|
+
startOnlyCount,
|
|
484
|
+
endOnlyCount,
|
|
485
|
+
hiddenCount,
|
|
486
|
+
namedCount,
|
|
487
|
+
integrityScore: unpairedCount === 0 ? "complete" : unpairedCount <= pairedCount ? "partial" : "degraded"
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
function compareBookmarks(left, right) {
|
|
491
|
+
return (left.startIndex ?? left.endIndex ?? Number.MAX_SAFE_INTEGER) - (right.startIndex ?? right.endIndex ?? Number.MAX_SAFE_INTEGER) || left.bookmarkId.localeCompare(right.bookmarkId);
|
|
492
|
+
}
|
|
493
|
+
function walkDocument(node, visit) {
|
|
494
|
+
visit(node);
|
|
495
|
+
if ("children" in node && Array.isArray(node.children)) {
|
|
496
|
+
for (const child of node.children) {
|
|
497
|
+
walkDocument(child, visit);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
if (node.type === "table") {
|
|
501
|
+
for (const row of node.rows) {
|
|
502
|
+
walkDocument(row, visit);
|
|
503
|
+
}
|
|
504
|
+
} else if (node.type === "table_row") {
|
|
505
|
+
for (const cell of node.cells) {
|
|
506
|
+
walkDocument(cell, visit);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// src/io/ooxml/part-manifest.ts
|
|
512
|
+
function normalizePartPath(path) {
|
|
513
|
+
const normalized = path.replace(/\\/g, "/").trim();
|
|
514
|
+
if (normalized.length === 0) {
|
|
515
|
+
throw new Error("OPC part path must not be empty.");
|
|
516
|
+
}
|
|
517
|
+
const withLeadingSlash = normalized.startsWith("/") ? normalized : `/${normalized}`;
|
|
518
|
+
const segments = withLeadingSlash.split("/");
|
|
519
|
+
const resolved = [];
|
|
520
|
+
for (const segment of segments) {
|
|
521
|
+
if (segment === "" || segment === ".") {
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
if (segment === "..") {
|
|
525
|
+
if (resolved.length === 0) {
|
|
526
|
+
throw new Error(`OPC part path escapes package root: ${path}`);
|
|
527
|
+
}
|
|
528
|
+
resolved.pop();
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
resolved.push(segment);
|
|
532
|
+
}
|
|
533
|
+
return `/${resolved.join("/")}`;
|
|
534
|
+
}
|
|
535
|
+
function resolveRelationshipTarget(sourcePartPath, relationship) {
|
|
536
|
+
if (relationship.targetMode === "external") {
|
|
537
|
+
return relationship.target;
|
|
538
|
+
}
|
|
539
|
+
if (relationship.target.startsWith("/")) {
|
|
540
|
+
return normalizePartPath(relationship.target);
|
|
541
|
+
}
|
|
542
|
+
const basePath = sourcePartPath ? normalizePartPath(sourcePartPath) : "/";
|
|
543
|
+
const baseDir = basePath === "/" ? "/" : basePath.slice(0, basePath.lastIndexOf("/") + 1);
|
|
544
|
+
return normalizePartPath(`${baseDir}${relationship.target}`);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// src/io/ooxml/parse-inline-media.ts
|
|
548
|
+
function parseInlineMediaXml(xml, relationships, mediaParts = /* @__PURE__ */ new Map(), sourcePartPath = "/word/document.xml") {
|
|
549
|
+
const root = parseXml2(xml);
|
|
550
|
+
const relationshipMap = new Map(relationships.map((relationship) => [relationship.id, relationship]));
|
|
551
|
+
const drawings = findDescendants(root, "drawing");
|
|
552
|
+
const media = [];
|
|
553
|
+
for (const drawing of drawings) {
|
|
554
|
+
const inline = findFirstDescendant(drawing, "inline");
|
|
555
|
+
const anchor = findFirstDescendant(drawing, "anchor");
|
|
556
|
+
const container = anchor ?? inline;
|
|
557
|
+
const blip = findFirstDescendant(drawing, "blip");
|
|
558
|
+
if (!container || !blip) {
|
|
559
|
+
continue;
|
|
560
|
+
}
|
|
561
|
+
const relationshipId = blip.attributes["r:embed"] ?? blip.attributes.embed;
|
|
562
|
+
if (!relationshipId) {
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
const relationship = relationshipMap.get(relationshipId);
|
|
566
|
+
if (!relationship || !relationship.type.endsWith("/image")) {
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
const packagePartName = normalizePartPath(
|
|
570
|
+
resolveRelationshipTarget(sourcePartPath, relationship)
|
|
571
|
+
);
|
|
572
|
+
const mediaPart = mediaParts.get(packagePartName);
|
|
573
|
+
const docProperties = findFirstDescendant(container, "docPr");
|
|
574
|
+
const altText = readAltText(docProperties);
|
|
575
|
+
const floating = anchor ? readFloatingProperties(anchor) : void 0;
|
|
576
|
+
const extent = findDrawingExtent(container);
|
|
577
|
+
const widthEmu = extent ? readEmuAttribute(extent, "cx") : void 0;
|
|
578
|
+
const heightEmu = extent ? readEmuAttribute(extent, "cy") : void 0;
|
|
579
|
+
media.push({
|
|
580
|
+
type: "image",
|
|
581
|
+
mediaId: `media:${packagePartName.slice(1)}`,
|
|
582
|
+
relationshipId,
|
|
583
|
+
packagePartName,
|
|
584
|
+
...mediaPart ? { contentType: mediaPart.contentType } : {},
|
|
585
|
+
filename: packagePartName.slice(packagePartName.lastIndexOf("/") + 1),
|
|
586
|
+
...altText ? { altText } : {},
|
|
587
|
+
...widthEmu !== void 0 ? { widthEmu } : {},
|
|
588
|
+
...heightEmu !== void 0 ? { heightEmu } : {},
|
|
589
|
+
...anchor ? { display: "floating" } : {},
|
|
590
|
+
...floating ? { floating } : {}
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
return media;
|
|
594
|
+
}
|
|
595
|
+
function findDrawingExtent(node) {
|
|
596
|
+
const wordProcessingExtent = findFirstDescendant(node, "extent");
|
|
597
|
+
if (wordProcessingExtent) {
|
|
598
|
+
return wordProcessingExtent;
|
|
599
|
+
}
|
|
600
|
+
const transform = findFirstDescendant(node, "xfrm");
|
|
601
|
+
if (!transform) {
|
|
602
|
+
return void 0;
|
|
603
|
+
}
|
|
604
|
+
return findFirstDescendant(transform, "ext");
|
|
605
|
+
}
|
|
606
|
+
function readFloatingProperties(node) {
|
|
607
|
+
const horizontalPosition = findFirstDescendant(node, "positionH");
|
|
608
|
+
const verticalPosition = findFirstDescendant(node, "positionV");
|
|
609
|
+
const wrap = findFirstDescendant(node, "wrapNone") ?? findFirstDescendant(node, "wrapSquare") ?? findFirstDescendant(node, "wrapTight") ?? findFirstDescendant(node, "wrapThrough") ?? findFirstDescendant(node, "wrapTopAndBottom");
|
|
610
|
+
const properties = {};
|
|
611
|
+
const horizontalAxis = readAxisPosition(horizontalPosition);
|
|
612
|
+
const verticalAxis = readAxisPosition(verticalPosition);
|
|
613
|
+
if (horizontalAxis) {
|
|
614
|
+
properties.horizontalPosition = horizontalAxis;
|
|
615
|
+
}
|
|
616
|
+
if (verticalAxis) {
|
|
617
|
+
properties.verticalPosition = verticalAxis;
|
|
618
|
+
}
|
|
619
|
+
if (wrap) {
|
|
620
|
+
const wrapName = localName2(wrap.name);
|
|
621
|
+
properties.wrap = wrapName === "wrapSquare" ? "square" : wrapName === "wrapTight" ? "tight" : wrapName === "wrapThrough" ? "through" : wrapName === "wrapTopAndBottom" ? "topAndBottom" : "none";
|
|
622
|
+
}
|
|
623
|
+
properties.behindDoc = readBooleanAttribute(node, "behindDoc");
|
|
624
|
+
properties.layoutInCell = readBooleanAttribute(node, "layoutInCell");
|
|
625
|
+
properties.allowOverlap = readBooleanAttribute(node, "allowOverlap");
|
|
626
|
+
return Object.values(properties).some((value) => value !== void 0) ? properties : void 0;
|
|
627
|
+
}
|
|
628
|
+
function readAxisPosition(node) {
|
|
629
|
+
if (!node) {
|
|
630
|
+
return void 0;
|
|
631
|
+
}
|
|
632
|
+
const align = findFirstDescendant(node, "align");
|
|
633
|
+
const posOffset = findFirstDescendant(node, "posOffset");
|
|
634
|
+
const position = {
|
|
635
|
+
...readOptionalAttribute(node, "relativeFrom") ? { relativeFrom: readOptionalAttribute(node, "relativeFrom") } : {},
|
|
636
|
+
...align && extractText(align).trim() ? { align: extractText(align).trim() } : {}
|
|
637
|
+
};
|
|
638
|
+
if (posOffset) {
|
|
639
|
+
const offset = Number.parseInt(extractText(posOffset).trim(), 10);
|
|
640
|
+
if (Number.isFinite(offset)) {
|
|
641
|
+
position.offset = offset;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
return Object.keys(position).length > 0 ? position : void 0;
|
|
645
|
+
}
|
|
646
|
+
function readAltText(node) {
|
|
647
|
+
if (!node) {
|
|
648
|
+
return void 0;
|
|
649
|
+
}
|
|
650
|
+
const description = node.attributes.descr?.trim();
|
|
651
|
+
if (description) {
|
|
652
|
+
return description;
|
|
653
|
+
}
|
|
654
|
+
const title = node.attributes.title?.trim();
|
|
655
|
+
if (title) {
|
|
656
|
+
return title;
|
|
657
|
+
}
|
|
658
|
+
const name = node.attributes.name?.trim();
|
|
659
|
+
return name || void 0;
|
|
660
|
+
}
|
|
661
|
+
function findFirstDescendant(node, local) {
|
|
662
|
+
for (const child of node.children) {
|
|
663
|
+
if (child.type !== "element") {
|
|
664
|
+
continue;
|
|
665
|
+
}
|
|
666
|
+
if (localName2(child.name) === local) {
|
|
667
|
+
return child;
|
|
668
|
+
}
|
|
669
|
+
const nested = findFirstDescendant(child, local);
|
|
670
|
+
if (nested) {
|
|
671
|
+
return nested;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
return void 0;
|
|
675
|
+
}
|
|
676
|
+
function findDescendants(node, local) {
|
|
677
|
+
const results = [];
|
|
678
|
+
for (const child of node.children) {
|
|
679
|
+
if (child.type !== "element") {
|
|
680
|
+
continue;
|
|
681
|
+
}
|
|
682
|
+
if (localName2(child.name) === local) {
|
|
683
|
+
results.push(child);
|
|
684
|
+
}
|
|
685
|
+
results.push(...findDescendants(child, local));
|
|
686
|
+
}
|
|
687
|
+
return results;
|
|
688
|
+
}
|
|
689
|
+
function localName2(name) {
|
|
690
|
+
const separatorIndex = name.indexOf(":");
|
|
691
|
+
return separatorIndex >= 0 ? name.slice(separatorIndex + 1) : name;
|
|
692
|
+
}
|
|
693
|
+
function extractText(node) {
|
|
694
|
+
return node.children.map((child) => child.type === "text" ? child.text : extractText(child)).join("");
|
|
695
|
+
}
|
|
696
|
+
function readOptionalAttribute(node, name) {
|
|
697
|
+
return node.attributes[`wp:${name}`] ?? node.attributes[`w:${name}`] ?? node.attributes[name];
|
|
698
|
+
}
|
|
699
|
+
function readEmuAttribute(node, name) {
|
|
700
|
+
const value = node.attributes[name] ?? node.attributes[`wp:${name}`];
|
|
701
|
+
if (value === void 0) return void 0;
|
|
702
|
+
const parsed = Number.parseInt(value, 10);
|
|
703
|
+
return Number.isFinite(parsed) && parsed >= 0 ? parsed : void 0;
|
|
704
|
+
}
|
|
705
|
+
function readBooleanAttribute(node, name) {
|
|
706
|
+
const value = readOptionalAttribute(node, name);
|
|
707
|
+
if (value === void 0) {
|
|
708
|
+
return void 0;
|
|
709
|
+
}
|
|
710
|
+
return value !== "0" && value !== "false" && value !== "off";
|
|
711
|
+
}
|
|
712
|
+
function parseXml2(xml) {
|
|
713
|
+
const root = {
|
|
714
|
+
type: "element",
|
|
715
|
+
name: "__root__",
|
|
716
|
+
attributes: {},
|
|
717
|
+
children: []
|
|
718
|
+
};
|
|
719
|
+
const stack = [root];
|
|
720
|
+
let cursor = 0;
|
|
721
|
+
while (cursor < xml.length) {
|
|
722
|
+
if (xml.startsWith("<!--", cursor)) {
|
|
723
|
+
const end = xml.indexOf("-->", cursor);
|
|
724
|
+
cursor = end >= 0 ? end + 3 : xml.length;
|
|
725
|
+
continue;
|
|
726
|
+
}
|
|
727
|
+
if (xml.startsWith("<?", cursor)) {
|
|
728
|
+
const end = xml.indexOf("?>", cursor);
|
|
729
|
+
cursor = end >= 0 ? end + 2 : xml.length;
|
|
730
|
+
continue;
|
|
731
|
+
}
|
|
732
|
+
if (xml[cursor] !== "<") {
|
|
733
|
+
const nextTag = xml.indexOf("<", cursor);
|
|
734
|
+
const end = nextTag >= 0 ? nextTag : xml.length;
|
|
735
|
+
const text = decodeXmlEntities2(xml.slice(cursor, end));
|
|
736
|
+
if (text.length > 0) {
|
|
737
|
+
stack[stack.length - 1]?.children.push({ type: "text", text });
|
|
738
|
+
}
|
|
739
|
+
cursor = end;
|
|
740
|
+
continue;
|
|
741
|
+
}
|
|
742
|
+
if (xml[cursor + 1] === "/") {
|
|
743
|
+
const end = xml.indexOf(">", cursor);
|
|
744
|
+
const current = stack.pop();
|
|
745
|
+
const name2 = xml.slice(cursor + 2, end).trim();
|
|
746
|
+
if (!current || localName2(current.name) !== localName2(name2)) {
|
|
747
|
+
throw new Error(`Malformed XML: unexpected closing tag </${name2}>.`);
|
|
748
|
+
}
|
|
749
|
+
cursor = end + 1;
|
|
750
|
+
continue;
|
|
751
|
+
}
|
|
752
|
+
const tagEnd = findTagEnd2(xml, cursor);
|
|
753
|
+
const tagBody = xml.slice(cursor + 1, tagEnd);
|
|
754
|
+
const selfClosing = /\/\s*$/.test(tagBody);
|
|
755
|
+
const { name, attributes } = parseTag2(tagBody.replace(/\/\s*$/, "").trim());
|
|
756
|
+
const element = {
|
|
757
|
+
type: "element",
|
|
758
|
+
name,
|
|
759
|
+
attributes,
|
|
760
|
+
children: []
|
|
761
|
+
};
|
|
762
|
+
stack[stack.length - 1]?.children.push(element);
|
|
763
|
+
if (!selfClosing) {
|
|
764
|
+
stack.push(element);
|
|
765
|
+
}
|
|
766
|
+
cursor = tagEnd + 1;
|
|
767
|
+
}
|
|
768
|
+
if (stack.length !== 1) {
|
|
769
|
+
throw new Error("Malformed XML: unclosed element.");
|
|
770
|
+
}
|
|
771
|
+
return root;
|
|
772
|
+
}
|
|
773
|
+
function parseTag2(tagBody) {
|
|
774
|
+
let cursor = 0;
|
|
775
|
+
while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
|
|
776
|
+
cursor += 1;
|
|
777
|
+
}
|
|
778
|
+
const nameStart = cursor;
|
|
779
|
+
while (cursor < tagBody.length && !/\s/.test(tagBody[cursor] ?? "")) {
|
|
780
|
+
cursor += 1;
|
|
781
|
+
}
|
|
782
|
+
const name = tagBody.slice(nameStart, cursor);
|
|
783
|
+
const attributes = {};
|
|
784
|
+
while (cursor < tagBody.length) {
|
|
785
|
+
while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
|
|
786
|
+
cursor += 1;
|
|
787
|
+
}
|
|
788
|
+
if (cursor >= tagBody.length) {
|
|
789
|
+
break;
|
|
790
|
+
}
|
|
791
|
+
const keyStart = cursor;
|
|
792
|
+
while (cursor < tagBody.length && !/[\s=]/.test(tagBody[cursor] ?? "")) {
|
|
793
|
+
cursor += 1;
|
|
794
|
+
}
|
|
795
|
+
const key = tagBody.slice(keyStart, cursor);
|
|
796
|
+
while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
|
|
797
|
+
cursor += 1;
|
|
798
|
+
}
|
|
799
|
+
if (tagBody[cursor] !== "=") {
|
|
800
|
+
attributes[key] = "";
|
|
801
|
+
continue;
|
|
802
|
+
}
|
|
803
|
+
cursor += 1;
|
|
804
|
+
while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
|
|
805
|
+
cursor += 1;
|
|
806
|
+
}
|
|
807
|
+
const quote = tagBody[cursor];
|
|
808
|
+
if (quote !== `"` && quote !== `'`) {
|
|
809
|
+
throw new Error(`Malformed XML attribute ${key}.`);
|
|
810
|
+
}
|
|
811
|
+
cursor += 1;
|
|
812
|
+
const valueStart = cursor;
|
|
813
|
+
while (cursor < tagBody.length && tagBody[cursor] !== quote) {
|
|
814
|
+
cursor += 1;
|
|
815
|
+
}
|
|
816
|
+
attributes[key] = decodeXmlEntities2(tagBody.slice(valueStart, cursor));
|
|
817
|
+
cursor += 1;
|
|
818
|
+
}
|
|
819
|
+
return { name, attributes };
|
|
820
|
+
}
|
|
821
|
+
function findTagEnd2(xml, start) {
|
|
822
|
+
let cursor = start + 1;
|
|
823
|
+
let quote = null;
|
|
824
|
+
while (cursor < xml.length) {
|
|
825
|
+
const current = xml[cursor];
|
|
826
|
+
if (quote) {
|
|
827
|
+
if (current === quote) {
|
|
828
|
+
quote = null;
|
|
829
|
+
}
|
|
830
|
+
cursor += 1;
|
|
831
|
+
continue;
|
|
832
|
+
}
|
|
833
|
+
if (current === `"` || current === `'`) {
|
|
834
|
+
quote = current;
|
|
835
|
+
cursor += 1;
|
|
836
|
+
continue;
|
|
837
|
+
}
|
|
838
|
+
if (current === ">") {
|
|
839
|
+
return cursor;
|
|
840
|
+
}
|
|
841
|
+
cursor += 1;
|
|
842
|
+
}
|
|
843
|
+
throw new Error("Malformed XML: missing >.");
|
|
844
|
+
}
|
|
845
|
+
function decodeXmlEntities2(value) {
|
|
846
|
+
return value.replace(/&(#x[0-9a-fA-F]+|#\d+|amp|lt|gt|quot|apos);/g, (match, entity) => {
|
|
847
|
+
switch (entity) {
|
|
848
|
+
case "amp":
|
|
849
|
+
return "&";
|
|
850
|
+
case "lt":
|
|
851
|
+
return "<";
|
|
852
|
+
case "gt":
|
|
853
|
+
return ">";
|
|
854
|
+
case "quot":
|
|
855
|
+
return `"`;
|
|
856
|
+
case "apos":
|
|
857
|
+
return "'";
|
|
858
|
+
default:
|
|
859
|
+
if (entity.startsWith("#x")) {
|
|
860
|
+
return String.fromCodePoint(Number.parseInt(entity.slice(2), 16));
|
|
861
|
+
}
|
|
862
|
+
if (entity.startsWith("#")) {
|
|
863
|
+
return String.fromCodePoint(Number.parseInt(entity.slice(1), 10));
|
|
864
|
+
}
|
|
865
|
+
return match;
|
|
866
|
+
}
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
// src/io/ooxml/parse-numbering.ts
|
|
871
|
+
function toCanonicalNumberingInstanceId(value) {
|
|
872
|
+
return value.startsWith("num:") ? value : `num:${value}`;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
// src/io/ooxml/parse-complex-content.ts
|
|
876
|
+
var CHART_GRAPHIC_URI = "http://schemas.openxmlformats.org/drawingml/2006/chart";
|
|
877
|
+
var CHART_GRAPHIC_URI_ALT = "http://schemas.microsoft.com/office/drawing/2007/8/2/chart";
|
|
878
|
+
var SMARTART_GRAPHIC_URI = "http://schemas.microsoft.com/office/drawing/2007/8/2/diagram";
|
|
879
|
+
var SMARTART_GRAPHIC_URI_ALT = "http://schemas.openxmlformats.org/drawingml/2006/diagram";
|
|
880
|
+
function parseComplexContentXml(drawingXml, relationships, mediaParts = /* @__PURE__ */ new Map(), sourcePartPath = "/word/document.xml") {
|
|
881
|
+
const root = parseXml3(drawingXml);
|
|
882
|
+
const relationshipMap = new Map(relationships.map((r) => [r.id, r]));
|
|
883
|
+
const altContent = findFirstDescendant2(root, "AlternateContent");
|
|
884
|
+
if (altContent) {
|
|
885
|
+
return parseAlternateContent(altContent, drawingXml, relationshipMap, mediaParts, sourcePartPath);
|
|
886
|
+
}
|
|
887
|
+
const graphicData = findFirstDescendant2(root, "graphicData");
|
|
888
|
+
if (!graphicData) {
|
|
889
|
+
return null;
|
|
890
|
+
}
|
|
891
|
+
const uri = graphicData.attributes.uri ?? graphicData.attributes["uri"] ?? "";
|
|
892
|
+
if (isChartUri(uri)) {
|
|
893
|
+
return { type: "chart_preview", rawXml: drawingXml };
|
|
894
|
+
}
|
|
895
|
+
if (isSmartArtUri(uri)) {
|
|
896
|
+
return { type: "smartart_preview", rawXml: drawingXml };
|
|
897
|
+
}
|
|
898
|
+
return null;
|
|
899
|
+
}
|
|
900
|
+
function parseAlternateContent(altContent, fullDrawingXml, relationshipMap, mediaParts, sourcePartPath) {
|
|
901
|
+
const choice = findFirstChild2(altContent, "Choice");
|
|
902
|
+
const fallback = findFirstChild2(altContent, "Fallback");
|
|
903
|
+
const choiceGraphicData = choice ? findFirstDescendant2(choice, "graphicData") : null;
|
|
904
|
+
const choiceUri = choiceGraphicData?.attributes.uri ?? "";
|
|
905
|
+
let contentType = null;
|
|
906
|
+
if (isChartUri(choiceUri)) {
|
|
907
|
+
contentType = "chart_preview";
|
|
908
|
+
} else if (isSmartArtUri(choiceUri)) {
|
|
909
|
+
contentType = "smartart_preview";
|
|
910
|
+
} else {
|
|
911
|
+
const chartRef = choice ? findFirstDescendant2(choice, "chart") : null;
|
|
912
|
+
if (chartRef) {
|
|
913
|
+
contentType = "chart_preview";
|
|
914
|
+
}
|
|
915
|
+
const dmRef = choice ? findFirstDescendant2(choice, "relIds") : null;
|
|
916
|
+
if (dmRef) {
|
|
917
|
+
contentType = "smartart_preview";
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
if (!contentType) {
|
|
921
|
+
return null;
|
|
922
|
+
}
|
|
923
|
+
let previewMediaId;
|
|
924
|
+
if (fallback) {
|
|
925
|
+
const fallbackBlip = findFirstDescendant2(fallback, "blip");
|
|
926
|
+
if (fallbackBlip) {
|
|
927
|
+
const rId = fallbackBlip.attributes["r:embed"] ?? fallbackBlip.attributes.embed ?? fallbackBlip.attributes["r:link"];
|
|
928
|
+
if (rId) {
|
|
929
|
+
const rel = relationshipMap.get(rId);
|
|
930
|
+
if (rel && rel.type.endsWith("/image")) {
|
|
931
|
+
const packagePartName = normalizePartPath(
|
|
932
|
+
resolveRelationshipTarget(sourcePartPath, rel)
|
|
933
|
+
);
|
|
934
|
+
const mediaPart = mediaParts.get(packagePartName);
|
|
935
|
+
if (mediaPart) {
|
|
936
|
+
previewMediaId = `media:${packagePartName.slice(1)}`;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
return {
|
|
943
|
+
type: contentType,
|
|
944
|
+
...previewMediaId ? { previewMediaId } : {},
|
|
945
|
+
rawXml: fullDrawingXml
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
function isChartUri(uri) {
|
|
949
|
+
return uri === CHART_GRAPHIC_URI || uri === CHART_GRAPHIC_URI_ALT;
|
|
950
|
+
}
|
|
951
|
+
function isSmartArtUri(uri) {
|
|
952
|
+
return uri === SMARTART_GRAPHIC_URI || uri === SMARTART_GRAPHIC_URI_ALT || uri.includes("diagram") || uri.includes("dgm");
|
|
953
|
+
}
|
|
954
|
+
function findFirstChild2(node, local) {
|
|
955
|
+
for (const child of node.children) {
|
|
956
|
+
if (child.type === "element" && localName3(child.name) === local) {
|
|
957
|
+
return child;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
return void 0;
|
|
961
|
+
}
|
|
962
|
+
function findFirstDescendant2(node, local) {
|
|
963
|
+
for (const child of node.children) {
|
|
964
|
+
if (child.type !== "element") continue;
|
|
965
|
+
if (localName3(child.name) === local) return child;
|
|
966
|
+
const nested = findFirstDescendant2(child, local);
|
|
967
|
+
if (nested) return nested;
|
|
968
|
+
}
|
|
969
|
+
return void 0;
|
|
970
|
+
}
|
|
971
|
+
function localName3(name) {
|
|
972
|
+
const i = name.indexOf(":");
|
|
973
|
+
return i >= 0 ? name.slice(i + 1) : name;
|
|
974
|
+
}
|
|
975
|
+
function parseXml3(xml) {
|
|
976
|
+
const root = { type: "element", name: "__root__", attributes: {}, children: [] };
|
|
977
|
+
const stack = [root];
|
|
978
|
+
let cursor = 0;
|
|
979
|
+
while (cursor < xml.length) {
|
|
980
|
+
if (xml.startsWith("<!--", cursor)) {
|
|
981
|
+
const end = xml.indexOf("-->", cursor);
|
|
982
|
+
cursor = end >= 0 ? end + 3 : xml.length;
|
|
983
|
+
continue;
|
|
984
|
+
}
|
|
985
|
+
if (xml.startsWith("<?", cursor)) {
|
|
986
|
+
const end = xml.indexOf("?>", cursor);
|
|
987
|
+
cursor = end >= 0 ? end + 2 : xml.length;
|
|
988
|
+
continue;
|
|
989
|
+
}
|
|
990
|
+
if (xml[cursor] !== "<") {
|
|
991
|
+
const nextTag = xml.indexOf("<", cursor);
|
|
992
|
+
const end = nextTag >= 0 ? nextTag : xml.length;
|
|
993
|
+
const text = xml.slice(cursor, end);
|
|
994
|
+
if (text.length > 0) {
|
|
995
|
+
stack[stack.length - 1]?.children.push({ type: "text", text });
|
|
996
|
+
}
|
|
997
|
+
cursor = end;
|
|
998
|
+
continue;
|
|
999
|
+
}
|
|
1000
|
+
if (xml[cursor + 1] === "/") {
|
|
1001
|
+
const end = xml.indexOf(">", cursor);
|
|
1002
|
+
stack.pop();
|
|
1003
|
+
cursor = end + 1;
|
|
1004
|
+
continue;
|
|
1005
|
+
}
|
|
1006
|
+
const tagEnd = findTagEnd3(xml, cursor);
|
|
1007
|
+
const tagBody = xml.slice(cursor + 1, tagEnd);
|
|
1008
|
+
const selfClosing = /\/\s*$/.test(tagBody);
|
|
1009
|
+
const { name, attributes } = parseTag3(tagBody.replace(/\/\s*$/, "").trim());
|
|
1010
|
+
const element = { type: "element", name, attributes, children: [] };
|
|
1011
|
+
stack[stack.length - 1]?.children.push(element);
|
|
1012
|
+
if (!selfClosing) stack.push(element);
|
|
1013
|
+
cursor = tagEnd + 1;
|
|
1014
|
+
}
|
|
1015
|
+
return root;
|
|
1016
|
+
}
|
|
1017
|
+
function parseTag3(tagBody) {
|
|
1018
|
+
let cursor = 0;
|
|
1019
|
+
while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) cursor++;
|
|
1020
|
+
const nameStart = cursor;
|
|
1021
|
+
while (cursor < tagBody.length && !/\s/.test(tagBody[cursor] ?? "")) cursor++;
|
|
1022
|
+
const name = tagBody.slice(nameStart, cursor);
|
|
1023
|
+
const attributes = {};
|
|
1024
|
+
while (cursor < tagBody.length) {
|
|
1025
|
+
while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) cursor++;
|
|
1026
|
+
if (cursor >= tagBody.length) break;
|
|
1027
|
+
const keyStart = cursor;
|
|
1028
|
+
while (cursor < tagBody.length && !/[\s=]/.test(tagBody[cursor] ?? "")) cursor++;
|
|
1029
|
+
const key = tagBody.slice(keyStart, cursor);
|
|
1030
|
+
while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) cursor++;
|
|
1031
|
+
if (tagBody[cursor] !== "=") {
|
|
1032
|
+
attributes[key] = "";
|
|
1033
|
+
continue;
|
|
1034
|
+
}
|
|
1035
|
+
cursor++;
|
|
1036
|
+
while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) cursor++;
|
|
1037
|
+
const quote = tagBody[cursor];
|
|
1038
|
+
if (quote !== `"` && quote !== `'`) break;
|
|
1039
|
+
cursor++;
|
|
1040
|
+
const valueStart = cursor;
|
|
1041
|
+
while (cursor < tagBody.length && tagBody[cursor] !== quote) cursor++;
|
|
1042
|
+
attributes[key] = tagBody.slice(valueStart, cursor);
|
|
1043
|
+
cursor++;
|
|
1044
|
+
}
|
|
1045
|
+
return { name, attributes };
|
|
1046
|
+
}
|
|
1047
|
+
function findTagEnd3(xml, start) {
|
|
1048
|
+
let cursor = start + 1;
|
|
1049
|
+
let quote = null;
|
|
1050
|
+
while (cursor < xml.length) {
|
|
1051
|
+
const c = xml[cursor];
|
|
1052
|
+
if (quote) {
|
|
1053
|
+
if (c === quote) quote = null;
|
|
1054
|
+
cursor++;
|
|
1055
|
+
continue;
|
|
1056
|
+
}
|
|
1057
|
+
if (c === `"` || c === `'`) {
|
|
1058
|
+
quote = c;
|
|
1059
|
+
cursor++;
|
|
1060
|
+
continue;
|
|
1061
|
+
}
|
|
1062
|
+
if (c === ">") return cursor;
|
|
1063
|
+
cursor++;
|
|
1064
|
+
}
|
|
1065
|
+
return xml.length - 1;
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
// src/io/ooxml/parse-shapes.ts
|
|
1069
|
+
var WPS_SHAPE_GRAPHIC_URI = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
|
|
1070
|
+
function parseShapeXml(drawingXml) {
|
|
1071
|
+
const root = parseXml4(drawingXml);
|
|
1072
|
+
const graphicData = findFirstDescendant3(root, "graphicData");
|
|
1073
|
+
if (!graphicData) return null;
|
|
1074
|
+
const uri = graphicData.attributes.uri ?? "";
|
|
1075
|
+
if (uri !== WPS_SHAPE_GRAPHIC_URI) return null;
|
|
1076
|
+
const wsp = findFirstDescendant3(root, "wsp");
|
|
1077
|
+
if (!wsp) return null;
|
|
1078
|
+
const spPr = findFirstChild3(wsp, "spPr");
|
|
1079
|
+
const prstGeom = spPr ? findFirstDescendant3(spPr, "prstGeom") : null;
|
|
1080
|
+
const prst = prstGeom?.attributes.prst ?? prstGeom?.attributes["prst"] ?? void 0;
|
|
1081
|
+
const txbx = findFirstChild3(wsp, "txbx");
|
|
1082
|
+
const txbxContent = txbx ? findFirstDescendant3(txbx, "txbxContent") : null;
|
|
1083
|
+
const text = txbxContent ? extractAllText(txbxContent).trim() || void 0 : void 0;
|
|
1084
|
+
if (prst && /^text/i.test(prst)) {
|
|
1085
|
+
return {
|
|
1086
|
+
type: "wordart",
|
|
1087
|
+
text: text ?? "",
|
|
1088
|
+
...prst ? { geometry: prst } : {},
|
|
1089
|
+
rawXml: drawingXml
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
const isTextBox = Boolean(txbxContent && (!prst || prst === "rect"));
|
|
1093
|
+
const txbxContentXml = txbxContent ? extractRawXml(txbxContent, drawingXml) : void 0;
|
|
1094
|
+
return {
|
|
1095
|
+
type: "shape",
|
|
1096
|
+
...isTextBox ? { isTextBox: true } : {},
|
|
1097
|
+
...text ? { text } : {},
|
|
1098
|
+
...txbxContentXml ? { txbxContentXml } : {},
|
|
1099
|
+
...prst ? { geometry: prst } : {},
|
|
1100
|
+
rawXml: drawingXml
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
function parseVmlXml(pictXml) {
|
|
1104
|
+
const root = parseXml4(pictXml);
|
|
1105
|
+
const vShape = findFirstDescendant3(root, "shape");
|
|
1106
|
+
const vRect = findFirstDescendant3(root, "rect");
|
|
1107
|
+
const vTextbox = findFirstDescendant3(root, "textbox");
|
|
1108
|
+
const vmlNode = vShape ?? vRect ?? vTextbox;
|
|
1109
|
+
if (!vmlNode) return null;
|
|
1110
|
+
const shapeType = vShape?.attributes.type ?? vShape?.attributes["type"] ?? void 0;
|
|
1111
|
+
let text;
|
|
1112
|
+
const textboxNode = findFirstDescendant3(vmlNode, "textbox") ?? (localName4(vmlNode.name) === "textbox" ? vmlNode : null);
|
|
1113
|
+
if (textboxNode) {
|
|
1114
|
+
const txbxContent = findFirstDescendant3(textboxNode, "txbxContent");
|
|
1115
|
+
if (txbxContent) {
|
|
1116
|
+
text = extractAllText(txbxContent).trim() || void 0;
|
|
1117
|
+
} else {
|
|
1118
|
+
text = extractAllText(textboxNode).trim() || void 0;
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
return {
|
|
1122
|
+
type: "vml_shape",
|
|
1123
|
+
...shapeType ? { shapeType } : {},
|
|
1124
|
+
...text ? { text } : {},
|
|
1125
|
+
rawXml: pictXml
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
function extractRawXml(node, sourceXml) {
|
|
1129
|
+
const tagName = node.name;
|
|
1130
|
+
const openIdx = sourceXml.indexOf(`<${tagName}`);
|
|
1131
|
+
if (openIdx < 0) return void 0;
|
|
1132
|
+
const closeTag = `</${tagName}>`;
|
|
1133
|
+
const closeIdx = sourceXml.indexOf(closeTag, openIdx);
|
|
1134
|
+
if (closeIdx < 0) return void 0;
|
|
1135
|
+
return sourceXml.slice(openIdx, closeIdx + closeTag.length);
|
|
1136
|
+
}
|
|
1137
|
+
function extractAllText(node) {
|
|
1138
|
+
return node.children.map((child) => {
|
|
1139
|
+
if (child.type === "text") return child.text;
|
|
1140
|
+
if (child.type === "element" && localName4(child.name) === "t") {
|
|
1141
|
+
return extractAllText(child);
|
|
1142
|
+
}
|
|
1143
|
+
return extractAllText(child);
|
|
1144
|
+
}).join("");
|
|
1145
|
+
}
|
|
1146
|
+
function findFirstChild3(node, local) {
|
|
1147
|
+
for (const child of node.children) {
|
|
1148
|
+
if (child.type === "element" && localName4(child.name) === local) return child;
|
|
1149
|
+
}
|
|
1150
|
+
return void 0;
|
|
1151
|
+
}
|
|
1152
|
+
function findFirstDescendant3(node, local) {
|
|
1153
|
+
for (const child of node.children) {
|
|
1154
|
+
if (child.type !== "element") continue;
|
|
1155
|
+
if (localName4(child.name) === local) return child;
|
|
1156
|
+
const nested = findFirstDescendant3(child, local);
|
|
1157
|
+
if (nested) return nested;
|
|
1158
|
+
}
|
|
1159
|
+
return void 0;
|
|
1160
|
+
}
|
|
1161
|
+
function localName4(name) {
|
|
1162
|
+
const i = name.indexOf(":");
|
|
1163
|
+
return i >= 0 ? name.slice(i + 1) : name;
|
|
1164
|
+
}
|
|
1165
|
+
function parseXml4(xml) {
|
|
1166
|
+
const root = { type: "element", name: "__root__", attributes: {}, children: [] };
|
|
1167
|
+
const stack = [root];
|
|
1168
|
+
let cursor = 0;
|
|
1169
|
+
while (cursor < xml.length) {
|
|
1170
|
+
if (xml.startsWith("<!--", cursor)) {
|
|
1171
|
+
const end = xml.indexOf("-->", cursor);
|
|
1172
|
+
cursor = end >= 0 ? end + 3 : xml.length;
|
|
1173
|
+
continue;
|
|
1174
|
+
}
|
|
1175
|
+
if (xml.startsWith("<?", cursor)) {
|
|
1176
|
+
const end = xml.indexOf("?>", cursor);
|
|
1177
|
+
cursor = end >= 0 ? end + 2 : xml.length;
|
|
1178
|
+
continue;
|
|
1179
|
+
}
|
|
1180
|
+
if (xml[cursor] !== "<") {
|
|
1181
|
+
const nextTag = xml.indexOf("<", cursor);
|
|
1182
|
+
const end = nextTag >= 0 ? nextTag : xml.length;
|
|
1183
|
+
const text = xml.slice(cursor, end);
|
|
1184
|
+
if (text.length > 0) stack[stack.length - 1]?.children.push({ type: "text", text });
|
|
1185
|
+
cursor = end;
|
|
1186
|
+
continue;
|
|
1187
|
+
}
|
|
1188
|
+
if (xml[cursor + 1] === "/") {
|
|
1189
|
+
const end = xml.indexOf(">", cursor);
|
|
1190
|
+
stack.pop();
|
|
1191
|
+
cursor = end + 1;
|
|
1192
|
+
continue;
|
|
1193
|
+
}
|
|
1194
|
+
const tagEnd = findTagEnd4(xml, cursor);
|
|
1195
|
+
const tagBody = xml.slice(cursor + 1, tagEnd);
|
|
1196
|
+
const selfClosing = /\/\s*$/.test(tagBody);
|
|
1197
|
+
const { name, attributes } = parseTag4(tagBody.replace(/\/\s*$/, "").trim());
|
|
1198
|
+
const element = { type: "element", name, attributes, children: [] };
|
|
1199
|
+
stack[stack.length - 1]?.children.push(element);
|
|
1200
|
+
if (!selfClosing) stack.push(element);
|
|
1201
|
+
cursor = tagEnd + 1;
|
|
1202
|
+
}
|
|
1203
|
+
return root;
|
|
1204
|
+
}
|
|
1205
|
+
function parseTag4(tagBody) {
|
|
1206
|
+
let cursor = 0;
|
|
1207
|
+
while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) cursor++;
|
|
1208
|
+
const nameStart = cursor;
|
|
1209
|
+
while (cursor < tagBody.length && !/\s/.test(tagBody[cursor] ?? "")) cursor++;
|
|
1210
|
+
const name = tagBody.slice(nameStart, cursor);
|
|
1211
|
+
const attributes = {};
|
|
1212
|
+
while (cursor < tagBody.length) {
|
|
1213
|
+
while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) cursor++;
|
|
1214
|
+
if (cursor >= tagBody.length) break;
|
|
1215
|
+
const keyStart = cursor;
|
|
1216
|
+
while (cursor < tagBody.length && !/[\s=]/.test(tagBody[cursor] ?? "")) cursor++;
|
|
1217
|
+
const key = tagBody.slice(keyStart, cursor);
|
|
1218
|
+
while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) cursor++;
|
|
1219
|
+
if (tagBody[cursor] !== "=") {
|
|
1220
|
+
attributes[key] = "";
|
|
1221
|
+
continue;
|
|
1222
|
+
}
|
|
1223
|
+
cursor++;
|
|
1224
|
+
while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) cursor++;
|
|
1225
|
+
const quote = tagBody[cursor];
|
|
1226
|
+
if (quote !== `"` && quote !== `'`) break;
|
|
1227
|
+
cursor++;
|
|
1228
|
+
const valueStart = cursor;
|
|
1229
|
+
while (cursor < tagBody.length && tagBody[cursor] !== quote) cursor++;
|
|
1230
|
+
attributes[key] = tagBody.slice(valueStart, cursor);
|
|
1231
|
+
cursor++;
|
|
1232
|
+
}
|
|
1233
|
+
return { name, attributes };
|
|
1234
|
+
}
|
|
1235
|
+
function findTagEnd4(xml, start) {
|
|
1236
|
+
let cursor = start + 1;
|
|
1237
|
+
let quote = null;
|
|
1238
|
+
while (cursor < xml.length) {
|
|
1239
|
+
const c = xml[cursor];
|
|
1240
|
+
if (quote) {
|
|
1241
|
+
if (c === quote) quote = null;
|
|
1242
|
+
cursor++;
|
|
1243
|
+
continue;
|
|
1244
|
+
}
|
|
1245
|
+
if (c === `"` || c === `'`) {
|
|
1246
|
+
quote = c;
|
|
1247
|
+
cursor++;
|
|
1248
|
+
continue;
|
|
1249
|
+
}
|
|
1250
|
+
if (c === ">") return cursor;
|
|
1251
|
+
cursor++;
|
|
1252
|
+
}
|
|
1253
|
+
return xml.length - 1;
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
// src/io/ooxml/highlight-colors.ts
|
|
1257
|
+
var HIGHLIGHT_COLOR_MAP = {
|
|
1258
|
+
black: "000000",
|
|
1259
|
+
blue: "0000FF",
|
|
1260
|
+
cyan: "00FFFF",
|
|
1261
|
+
darkBlue: "000080",
|
|
1262
|
+
darkCyan: "008080",
|
|
1263
|
+
darkGray: "808080",
|
|
1264
|
+
darkGreen: "008000",
|
|
1265
|
+
darkMagenta: "800080",
|
|
1266
|
+
darkRed: "8B0000",
|
|
1267
|
+
darkYellow: "808000",
|
|
1268
|
+
green: "00FF00",
|
|
1269
|
+
lightGray: "C0C0C0",
|
|
1270
|
+
magenta: "FF00FF",
|
|
1271
|
+
red: "FF0000",
|
|
1272
|
+
white: "FFFFFF",
|
|
1273
|
+
yellow: "FFFF00"
|
|
1274
|
+
};
|
|
1275
|
+
function resolveHighlightColor(value) {
|
|
1276
|
+
if (!value || value === "none") {
|
|
1277
|
+
return void 0;
|
|
1278
|
+
}
|
|
1279
|
+
const normalizedValue = value;
|
|
1280
|
+
const color = HIGHLIGHT_COLOR_MAP[normalizedValue];
|
|
1281
|
+
if (!color) {
|
|
1282
|
+
return void 0;
|
|
1283
|
+
}
|
|
1284
|
+
return {
|
|
1285
|
+
color,
|
|
1286
|
+
val: normalizedValue
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
// src/io/ooxml/parse-main-document.ts
|
|
1291
|
+
var HYPERLINK_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
|
|
1292
|
+
function parseMainDocumentXml(xml, relationships = [], mediaParts = /* @__PURE__ */ new Map(), sourcePartPath = "/word/document.xml") {
|
|
1293
|
+
const root = parseXml5(xml);
|
|
1294
|
+
const documentElement = findChildElement(root, "document");
|
|
1295
|
+
const bodyElement = findChildElement(documentElement, "body");
|
|
1296
|
+
const relationshipMap = new Map(relationships.map((relationship) => [relationship.id, relationship]));
|
|
1297
|
+
const allBlocks = bodyElement.children.filter((node) => node.type === "element").map((node) => parseBodyChild(node, xml, relationshipMap, relationships, mediaParts, sourcePartPath));
|
|
1298
|
+
let finalSectionProperties;
|
|
1299
|
+
const blocks = [];
|
|
1300
|
+
for (let i = 0; i < allBlocks.length; i++) {
|
|
1301
|
+
const block = allBlocks[i];
|
|
1302
|
+
if (block.type === "section_break" && i === allBlocks.length - 1) {
|
|
1303
|
+
finalSectionProperties = block.sectionProperties;
|
|
1304
|
+
} else {
|
|
1305
|
+
blocks.push(block);
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
return { blocks, finalSectionProperties };
|
|
1309
|
+
}
|
|
1310
|
+
function parseBodyChild(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath) {
|
|
1311
|
+
const nodeType = localName5(node.name);
|
|
1312
|
+
if (nodeType === "tbl") {
|
|
1313
|
+
const rawTableXml = sourceXml.slice(node.start, node.end);
|
|
1314
|
+
if (tableRequiresOpaquePreservation(rawTableXml)) {
|
|
1315
|
+
return {
|
|
1316
|
+
type: "opaque_block",
|
|
1317
|
+
rawXml: rawTableXml
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
try {
|
|
1321
|
+
return parseTableElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath);
|
|
1322
|
+
} catch {
|
|
1323
|
+
return {
|
|
1324
|
+
type: "opaque_block",
|
|
1325
|
+
rawXml: rawTableXml
|
|
1326
|
+
};
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
if (nodeType === "sdt") {
|
|
1330
|
+
return parseSdtElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath);
|
|
1331
|
+
}
|
|
1332
|
+
if (nodeType === "customXml") {
|
|
1333
|
+
return parseCustomXmlElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath);
|
|
1334
|
+
}
|
|
1335
|
+
if (nodeType === "altChunk") {
|
|
1336
|
+
return parseAltChunkElement(node, sourceXml);
|
|
1337
|
+
}
|
|
1338
|
+
if (nodeType === "sectPr") {
|
|
1339
|
+
return parseSectionBreakElement(node, sourceXml);
|
|
1340
|
+
}
|
|
1341
|
+
if (nodeType !== "p") {
|
|
1342
|
+
return {
|
|
1343
|
+
type: "opaque_block",
|
|
1344
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
1345
|
+
};
|
|
1346
|
+
}
|
|
1347
|
+
let styleId;
|
|
1348
|
+
let numbering;
|
|
1349
|
+
let alignment;
|
|
1350
|
+
let spacing;
|
|
1351
|
+
let contextualSpacing;
|
|
1352
|
+
let indentation;
|
|
1353
|
+
let tabStops;
|
|
1354
|
+
let keepNext;
|
|
1355
|
+
let keepLines;
|
|
1356
|
+
let outlineLevel;
|
|
1357
|
+
let pageBreakBefore;
|
|
1358
|
+
let widowControl;
|
|
1359
|
+
let borders;
|
|
1360
|
+
let shading;
|
|
1361
|
+
let bidi;
|
|
1362
|
+
let suppressLineNumbers;
|
|
1363
|
+
let cnfStyle;
|
|
1364
|
+
let sectionProperties;
|
|
1365
|
+
let sectionPropertiesXml;
|
|
1366
|
+
let paragraphSupported = true;
|
|
1367
|
+
const children = [];
|
|
1368
|
+
let activeComplexField = null;
|
|
1369
|
+
for (const child of node.children) {
|
|
1370
|
+
if (child.type !== "element") {
|
|
1371
|
+
continue;
|
|
1372
|
+
}
|
|
1373
|
+
switch (localName5(child.name)) {
|
|
1374
|
+
case "pPr":
|
|
1375
|
+
styleId = readParagraphStyleId(child);
|
|
1376
|
+
numbering = readParagraphNumbering(child);
|
|
1377
|
+
alignment = readParagraphAlignment(child);
|
|
1378
|
+
spacing = readParagraphSpacing(child);
|
|
1379
|
+
contextualSpacing = readOptionalOnOffParagraphProperty(child, "contextualSpacing");
|
|
1380
|
+
indentation = readParagraphIndentation(child);
|
|
1381
|
+
tabStops = readParagraphTabStops(child);
|
|
1382
|
+
keepNext = readOnOffParagraphProperty(child, "keepNext");
|
|
1383
|
+
keepLines = readOnOffParagraphProperty(child, "keepLines");
|
|
1384
|
+
outlineLevel = readParagraphOutlineLevel(child);
|
|
1385
|
+
pageBreakBefore = readOnOffParagraphProperty(child, "pageBreakBefore");
|
|
1386
|
+
widowControl = readOnOffParagraphProperty(child, "widowControl");
|
|
1387
|
+
borders = readParagraphBorders(child);
|
|
1388
|
+
shading = readParagraphShading(child);
|
|
1389
|
+
bidi = readOnOffParagraphProperty(child, "bidi");
|
|
1390
|
+
suppressLineNumbers = readOnOffParagraphProperty(child, "suppressLineNumbers");
|
|
1391
|
+
cnfStyle = readParagraphCnfStyle(child);
|
|
1392
|
+
sectionProperties = readSectionPropertiesFromPPr(child);
|
|
1393
|
+
sectionPropertiesXml = readSectionPropertiesXmlFromPPr(child, sourceXml);
|
|
1394
|
+
paragraphSupported = paragraphSupported && supportsParagraphProperties(child);
|
|
1395
|
+
break;
|
|
1396
|
+
case "r":
|
|
1397
|
+
activeComplexField = appendParagraphRunNodes(
|
|
1398
|
+
child,
|
|
1399
|
+
children,
|
|
1400
|
+
activeComplexField,
|
|
1401
|
+
sourceXml,
|
|
1402
|
+
relationships,
|
|
1403
|
+
mediaParts,
|
|
1404
|
+
sourcePartPath
|
|
1405
|
+
);
|
|
1406
|
+
break;
|
|
1407
|
+
case "hyperlink": {
|
|
1408
|
+
flushActiveComplexField(children, () => {
|
|
1409
|
+
activeComplexField = null;
|
|
1410
|
+
}, activeComplexField);
|
|
1411
|
+
const hyperlink = parseHyperlink(child, sourceXml, relationshipMap);
|
|
1412
|
+
children.push(hyperlink);
|
|
1413
|
+
break;
|
|
1414
|
+
}
|
|
1415
|
+
case "ins":
|
|
1416
|
+
case "del": {
|
|
1417
|
+
flushActiveComplexField(children, () => {
|
|
1418
|
+
activeComplexField = null;
|
|
1419
|
+
}, activeComplexField);
|
|
1420
|
+
children.push(...parseRevisionContainer(child, sourceXml, relationshipMap));
|
|
1421
|
+
break;
|
|
1422
|
+
}
|
|
1423
|
+
case "commentRangeStart":
|
|
1424
|
+
case "commentRangeEnd":
|
|
1425
|
+
break;
|
|
1426
|
+
case "bookmarkStart": {
|
|
1427
|
+
const bkId = child.attributes["w:id"] ?? child.attributes.id ?? "";
|
|
1428
|
+
const bkName = child.attributes["w:name"] ?? child.attributes.name ?? "";
|
|
1429
|
+
if (bkId) {
|
|
1430
|
+
const bookmarkNode = {
|
|
1431
|
+
type: "bookmark_start",
|
|
1432
|
+
bookmarkId: bkId,
|
|
1433
|
+
name: bkName,
|
|
1434
|
+
rawXml: sourceXml.slice(child.start, child.end)
|
|
1435
|
+
};
|
|
1436
|
+
flushActiveComplexField(children, () => {
|
|
1437
|
+
activeComplexField = null;
|
|
1438
|
+
}, activeComplexField);
|
|
1439
|
+
children.push(bookmarkNode);
|
|
1440
|
+
} else {
|
|
1441
|
+
flushActiveComplexField(children, () => {
|
|
1442
|
+
activeComplexField = null;
|
|
1443
|
+
}, activeComplexField);
|
|
1444
|
+
children.push({ type: "opaque_inline", rawXml: sourceXml.slice(child.start, child.end) });
|
|
1445
|
+
}
|
|
1446
|
+
break;
|
|
1447
|
+
}
|
|
1448
|
+
case "bookmarkEnd": {
|
|
1449
|
+
const bkEndId = child.attributes["w:id"] ?? child.attributes.id ?? "";
|
|
1450
|
+
if (bkEndId) {
|
|
1451
|
+
const bookmarkNode = {
|
|
1452
|
+
type: "bookmark_end",
|
|
1453
|
+
bookmarkId: bkEndId,
|
|
1454
|
+
rawXml: sourceXml.slice(child.start, child.end)
|
|
1455
|
+
};
|
|
1456
|
+
flushActiveComplexField(children, () => {
|
|
1457
|
+
activeComplexField = null;
|
|
1458
|
+
}, activeComplexField);
|
|
1459
|
+
children.push(bookmarkNode);
|
|
1460
|
+
} else {
|
|
1461
|
+
flushActiveComplexField(children, () => {
|
|
1462
|
+
activeComplexField = null;
|
|
1463
|
+
}, activeComplexField);
|
|
1464
|
+
children.push({ type: "opaque_inline", rawXml: sourceXml.slice(child.start, child.end) });
|
|
1465
|
+
}
|
|
1466
|
+
break;
|
|
1467
|
+
}
|
|
1468
|
+
case "fldSimple": {
|
|
1469
|
+
flushActiveComplexField(children, () => {
|
|
1470
|
+
activeComplexField = null;
|
|
1471
|
+
}, activeComplexField);
|
|
1472
|
+
const fieldInstr = child.attributes["w:instr"] ?? child.attributes.instr ?? "";
|
|
1473
|
+
const fieldContentXml = child.children.filter((c) => c.type === "element").map((c) => sourceXml.slice(c.start, c.end)).join("");
|
|
1474
|
+
children.push({
|
|
1475
|
+
type: "field",
|
|
1476
|
+
fieldType: "simple",
|
|
1477
|
+
instruction: fieldInstr,
|
|
1478
|
+
contentXml: fieldContentXml,
|
|
1479
|
+
rawXml: sourceXml.slice(child.start, child.end)
|
|
1480
|
+
});
|
|
1481
|
+
break;
|
|
1482
|
+
}
|
|
1483
|
+
case "proofErr":
|
|
1484
|
+
flushActiveComplexField(children, () => {
|
|
1485
|
+
activeComplexField = null;
|
|
1486
|
+
}, activeComplexField);
|
|
1487
|
+
children.push({
|
|
1488
|
+
type: "opaque_inline",
|
|
1489
|
+
rawXml: sourceXml.slice(child.start, child.end)
|
|
1490
|
+
});
|
|
1491
|
+
break;
|
|
1492
|
+
case "permStart":
|
|
1493
|
+
flushActiveComplexField(children, () => {
|
|
1494
|
+
activeComplexField = null;
|
|
1495
|
+
}, activeComplexField);
|
|
1496
|
+
children.push(parsePermStartNode(child, sourceXml));
|
|
1497
|
+
break;
|
|
1498
|
+
case "permEnd":
|
|
1499
|
+
flushActiveComplexField(children, () => {
|
|
1500
|
+
activeComplexField = null;
|
|
1501
|
+
}, activeComplexField);
|
|
1502
|
+
children.push(parsePermEndNode(child, sourceXml));
|
|
1503
|
+
break;
|
|
1504
|
+
case "footnoteReference": {
|
|
1505
|
+
flushActiveComplexField(children, () => {
|
|
1506
|
+
activeComplexField = null;
|
|
1507
|
+
}, activeComplexField);
|
|
1508
|
+
const noteId = child.attributes["w:id"] ?? child.attributes.id ?? "";
|
|
1509
|
+
if (noteId) {
|
|
1510
|
+
children.push({
|
|
1511
|
+
type: "footnote_ref",
|
|
1512
|
+
noteId,
|
|
1513
|
+
noteKind: "footnote"
|
|
1514
|
+
});
|
|
1515
|
+
}
|
|
1516
|
+
break;
|
|
1517
|
+
}
|
|
1518
|
+
case "endnoteReference": {
|
|
1519
|
+
flushActiveComplexField(children, () => {
|
|
1520
|
+
activeComplexField = null;
|
|
1521
|
+
}, activeComplexField);
|
|
1522
|
+
const noteId = child.attributes["w:id"] ?? child.attributes.id ?? "";
|
|
1523
|
+
if (noteId) {
|
|
1524
|
+
children.push({
|
|
1525
|
+
type: "footnote_ref",
|
|
1526
|
+
noteId,
|
|
1527
|
+
noteKind: "endnote"
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
break;
|
|
1531
|
+
}
|
|
1532
|
+
default:
|
|
1533
|
+
flushActiveComplexField(children, () => {
|
|
1534
|
+
activeComplexField = null;
|
|
1535
|
+
}, activeComplexField);
|
|
1536
|
+
children.push({
|
|
1537
|
+
type: "opaque_inline",
|
|
1538
|
+
rawXml: sourceXml.slice(child.start, child.end)
|
|
1539
|
+
});
|
|
1540
|
+
break;
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
flushActiveComplexField(children, () => {
|
|
1544
|
+
activeComplexField = null;
|
|
1545
|
+
}, activeComplexField);
|
|
1546
|
+
if (!paragraphSupported) {
|
|
1547
|
+
return {
|
|
1548
|
+
type: "opaque_block",
|
|
1549
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
1550
|
+
};
|
|
1551
|
+
}
|
|
1552
|
+
return {
|
|
1553
|
+
type: "paragraph",
|
|
1554
|
+
styleId,
|
|
1555
|
+
...numbering ? { numbering } : {},
|
|
1556
|
+
...alignment ? { alignment } : {},
|
|
1557
|
+
...spacing ? { spacing } : {},
|
|
1558
|
+
...contextualSpacing !== void 0 ? { contextualSpacing } : {},
|
|
1559
|
+
...indentation ? { indentation } : {},
|
|
1560
|
+
...tabStops && tabStops.length > 0 ? { tabStops } : {},
|
|
1561
|
+
...keepNext ? { keepNext } : {},
|
|
1562
|
+
...keepLines ? { keepLines } : {},
|
|
1563
|
+
...outlineLevel !== void 0 ? { outlineLevel } : {},
|
|
1564
|
+
...pageBreakBefore ? { pageBreakBefore } : {},
|
|
1565
|
+
...widowControl ? { widowControl } : {},
|
|
1566
|
+
...borders ? { borders } : {},
|
|
1567
|
+
...shading ? { shading } : {},
|
|
1568
|
+
...bidi ? { bidi } : {},
|
|
1569
|
+
...suppressLineNumbers ? { suppressLineNumbers } : {},
|
|
1570
|
+
...cnfStyle ? { cnfStyle } : {},
|
|
1571
|
+
...sectionProperties ? { sectionProperties } : {},
|
|
1572
|
+
...sectionPropertiesXml ? { sectionPropertiesXml } : {},
|
|
1573
|
+
children,
|
|
1574
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
1575
|
+
};
|
|
1576
|
+
}
|
|
1577
|
+
function appendParagraphRunNodes(node, children, activeComplexField, sourceXml, relationships, mediaParts, sourcePartPath) {
|
|
1578
|
+
const hasFieldMarkers = node.children.some(
|
|
1579
|
+
(child) => child.type === "element" && (localName5(child.name) === "fldChar" || localName5(child.name) === "instrText")
|
|
1580
|
+
);
|
|
1581
|
+
if (activeComplexField?.mode === "result" && !hasFieldMarkers) {
|
|
1582
|
+
const run = parseRunContentOnly(node, sourceXml);
|
|
1583
|
+
if (run.supported && run.nodes.every(
|
|
1584
|
+
(child) => child.type === "text" || child.type === "hard_break" || child.type === "tab"
|
|
1585
|
+
)) {
|
|
1586
|
+
activeComplexField.children.push(...run.nodes);
|
|
1587
|
+
return activeComplexField;
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
if (!hasFieldMarkers) {
|
|
1591
|
+
children.push(...parseRun(node, sourceXml, relationships, mediaParts, sourcePartPath));
|
|
1592
|
+
return activeComplexField;
|
|
1593
|
+
}
|
|
1594
|
+
for (const child of node.children) {
|
|
1595
|
+
if (child.type !== "element") {
|
|
1596
|
+
continue;
|
|
1597
|
+
}
|
|
1598
|
+
const name = localName5(child.name);
|
|
1599
|
+
if (name === "fldChar") {
|
|
1600
|
+
const fldType = child.attributes["w:fldCharType"] ?? child.attributes.fldCharType;
|
|
1601
|
+
if (fldType === "begin") {
|
|
1602
|
+
activeComplexField = { instruction: "", children: [], mode: "instruction" };
|
|
1603
|
+
} else if (fldType === "separate" && activeComplexField) {
|
|
1604
|
+
activeComplexField.mode = "result";
|
|
1605
|
+
} else if (fldType === "end" && activeComplexField) {
|
|
1606
|
+
flushActiveComplexField(children, () => {
|
|
1607
|
+
activeComplexField = null;
|
|
1608
|
+
}, activeComplexField);
|
|
1609
|
+
}
|
|
1610
|
+
continue;
|
|
1611
|
+
}
|
|
1612
|
+
if (name === "instrText") {
|
|
1613
|
+
const instruction = child.children.filter((entry) => entry.type === "text").map((entry) => entry.text).join("");
|
|
1614
|
+
if (activeComplexField) {
|
|
1615
|
+
activeComplexField.instruction += instruction;
|
|
1616
|
+
} else if (instruction.trim().length > 0) {
|
|
1617
|
+
children.push({
|
|
1618
|
+
type: "field",
|
|
1619
|
+
fieldType: "complex",
|
|
1620
|
+
instruction,
|
|
1621
|
+
children: [],
|
|
1622
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
1623
|
+
});
|
|
1624
|
+
}
|
|
1625
|
+
continue;
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
return activeComplexField;
|
|
1629
|
+
}
|
|
1630
|
+
function flushActiveComplexField(children, reset, activeComplexField) {
|
|
1631
|
+
if (!activeComplexField || activeComplexField.instruction.trim().length === 0) {
|
|
1632
|
+
return;
|
|
1633
|
+
}
|
|
1634
|
+
children.push({
|
|
1635
|
+
type: "field",
|
|
1636
|
+
fieldType: "complex",
|
|
1637
|
+
instruction: activeComplexField.instruction,
|
|
1638
|
+
children: activeComplexField.children,
|
|
1639
|
+
rawXml: ""
|
|
1640
|
+
});
|
|
1641
|
+
reset();
|
|
1642
|
+
}
|
|
1643
|
+
function parseTableElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath) {
|
|
1644
|
+
let styleId;
|
|
1645
|
+
let tblLook;
|
|
1646
|
+
let propertiesXml;
|
|
1647
|
+
let gridColumns = [];
|
|
1648
|
+
const rows = [];
|
|
1649
|
+
for (const child of node.children) {
|
|
1650
|
+
if (child.type !== "element") continue;
|
|
1651
|
+
switch (localName5(child.name)) {
|
|
1652
|
+
case "tblPr": {
|
|
1653
|
+
propertiesXml = sourceXml.slice(child.start, child.end);
|
|
1654
|
+
styleId = readTableStyleId(child);
|
|
1655
|
+
tblLook = readTableLook(child);
|
|
1656
|
+
break;
|
|
1657
|
+
}
|
|
1658
|
+
case "tblGrid": {
|
|
1659
|
+
gridColumns = readTableGridColumns(child);
|
|
1660
|
+
break;
|
|
1661
|
+
}
|
|
1662
|
+
case "tr": {
|
|
1663
|
+
rows.push(parseTableRowElement(child, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath));
|
|
1664
|
+
break;
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
return {
|
|
1669
|
+
type: "table",
|
|
1670
|
+
...styleId ? { styleId } : {},
|
|
1671
|
+
...tblLook ? { tblLook } : {},
|
|
1672
|
+
...propertiesXml ? { propertiesXml } : {},
|
|
1673
|
+
gridColumns,
|
|
1674
|
+
rows,
|
|
1675
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
1676
|
+
};
|
|
1677
|
+
}
|
|
1678
|
+
function parseTableRowElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath) {
|
|
1679
|
+
let propertiesXml;
|
|
1680
|
+
let gridBefore;
|
|
1681
|
+
let widthBefore;
|
|
1682
|
+
let gridAfter;
|
|
1683
|
+
let widthAfter;
|
|
1684
|
+
const cells = [];
|
|
1685
|
+
for (const child of node.children) {
|
|
1686
|
+
if (child.type !== "element") continue;
|
|
1687
|
+
switch (localName5(child.name)) {
|
|
1688
|
+
case "trPr":
|
|
1689
|
+
propertiesXml = sourceXml.slice(child.start, child.end);
|
|
1690
|
+
gridBefore = readTableRowGridPosition(child, "gridBefore");
|
|
1691
|
+
widthBefore = readTableRowWidth(child, "wBefore");
|
|
1692
|
+
gridAfter = readTableRowGridPosition(child, "gridAfter");
|
|
1693
|
+
widthAfter = readTableRowWidth(child, "wAfter");
|
|
1694
|
+
break;
|
|
1695
|
+
case "tc":
|
|
1696
|
+
cells.push(parseTableCellElement(child, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath));
|
|
1697
|
+
break;
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
return {
|
|
1701
|
+
type: "table_row",
|
|
1702
|
+
...propertiesXml ? { propertiesXml } : {},
|
|
1703
|
+
...gridBefore !== void 0 ? { gridBefore } : {},
|
|
1704
|
+
...widthBefore ? { widthBefore } : {},
|
|
1705
|
+
...gridAfter !== void 0 ? { gridAfter } : {},
|
|
1706
|
+
...widthAfter ? { widthAfter } : {},
|
|
1707
|
+
cells,
|
|
1708
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
1709
|
+
};
|
|
1710
|
+
}
|
|
1711
|
+
function parseTableCellElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath) {
|
|
1712
|
+
let propertiesXml;
|
|
1713
|
+
let gridSpan;
|
|
1714
|
+
let verticalMerge;
|
|
1715
|
+
const children = [];
|
|
1716
|
+
for (const child of node.children) {
|
|
1717
|
+
if (child.type !== "element") continue;
|
|
1718
|
+
switch (localName5(child.name)) {
|
|
1719
|
+
case "tcPr": {
|
|
1720
|
+
propertiesXml = sourceXml.slice(child.start, child.end);
|
|
1721
|
+
gridSpan = readCellGridSpan(child);
|
|
1722
|
+
verticalMerge = readCellVerticalMerge(child);
|
|
1723
|
+
break;
|
|
1724
|
+
}
|
|
1725
|
+
default: {
|
|
1726
|
+
children.push(parseBodyChild(child, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath));
|
|
1727
|
+
break;
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
return {
|
|
1732
|
+
type: "table_cell",
|
|
1733
|
+
...propertiesXml ? { propertiesXml } : {},
|
|
1734
|
+
...gridSpan ? { gridSpan } : {},
|
|
1735
|
+
...verticalMerge ? { verticalMerge } : {},
|
|
1736
|
+
children,
|
|
1737
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
1738
|
+
};
|
|
1739
|
+
}
|
|
1740
|
+
function parseSdtElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath) {
|
|
1741
|
+
const propertiesNode = node.children.find(
|
|
1742
|
+
(child) => child.type === "element" && localName5(child.name) === "sdtPr"
|
|
1743
|
+
);
|
|
1744
|
+
const contentNode = node.children.find(
|
|
1745
|
+
(child) => child.type === "element" && localName5(child.name) === "sdtContent"
|
|
1746
|
+
);
|
|
1747
|
+
if (!contentNode) {
|
|
1748
|
+
return {
|
|
1749
|
+
type: "opaque_block",
|
|
1750
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1753
|
+
const children = contentNode.children.filter((child) => child.type === "element").map((child) => parseBodyChild(child, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath));
|
|
1754
|
+
return {
|
|
1755
|
+
type: "sdt",
|
|
1756
|
+
properties: readSdtProperties(propertiesNode, sourceXml),
|
|
1757
|
+
children,
|
|
1758
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
1759
|
+
};
|
|
1760
|
+
}
|
|
1761
|
+
function parseCustomXmlElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath) {
|
|
1762
|
+
const uri = readOptionalAttribute2(node, "uri");
|
|
1763
|
+
const element = readOptionalAttribute2(node, "element");
|
|
1764
|
+
if (!uri && !element) {
|
|
1765
|
+
return {
|
|
1766
|
+
type: "opaque_block",
|
|
1767
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
1768
|
+
};
|
|
1769
|
+
}
|
|
1770
|
+
const children = node.children.filter(
|
|
1771
|
+
(child) => child.type === "element" && localName5(child.name) !== "customXmlPr"
|
|
1772
|
+
).map((child) => parseBodyChild(child, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath));
|
|
1773
|
+
return {
|
|
1774
|
+
type: "custom_xml",
|
|
1775
|
+
...uri ? { uri } : {},
|
|
1776
|
+
...element ? { element } : {},
|
|
1777
|
+
children,
|
|
1778
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
1779
|
+
};
|
|
1780
|
+
}
|
|
1781
|
+
function parseAltChunkElement(node, sourceXml) {
|
|
1782
|
+
const relationshipId = readOptionalAttribute2(node, "id");
|
|
1783
|
+
if (!relationshipId) {
|
|
1784
|
+
return {
|
|
1785
|
+
type: "opaque_block",
|
|
1786
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
1787
|
+
};
|
|
1788
|
+
}
|
|
1789
|
+
return {
|
|
1790
|
+
type: "alt_chunk",
|
|
1791
|
+
relationshipId,
|
|
1792
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
1793
|
+
};
|
|
1794
|
+
}
|
|
1795
|
+
function readSdtProperties(node, sourceXml) {
|
|
1796
|
+
if (!node) {
|
|
1797
|
+
return {};
|
|
1798
|
+
}
|
|
1799
|
+
const properties = {
|
|
1800
|
+
propertiesXml: sourceXml.slice(node.start, node.end)
|
|
1801
|
+
};
|
|
1802
|
+
for (const child of node.children) {
|
|
1803
|
+
if (child.type !== "element") {
|
|
1804
|
+
continue;
|
|
1805
|
+
}
|
|
1806
|
+
const name = localName5(child.name);
|
|
1807
|
+
if (name === "alias") {
|
|
1808
|
+
properties.alias = readOptionalAttribute2(child, "val");
|
|
1809
|
+
continue;
|
|
1810
|
+
}
|
|
1811
|
+
if (name === "tag") {
|
|
1812
|
+
properties.tag = readOptionalAttribute2(child, "val");
|
|
1813
|
+
continue;
|
|
1814
|
+
}
|
|
1815
|
+
if (name === "lock") {
|
|
1816
|
+
properties.lock = readOptionalAttribute2(child, "val");
|
|
1817
|
+
continue;
|
|
1818
|
+
}
|
|
1819
|
+
if (name === "showingPlcHdr") {
|
|
1820
|
+
const val = readOptionalAttribute2(child, "val");
|
|
1821
|
+
properties.showingPlcHdr = val !== "false" && val !== "0";
|
|
1822
|
+
continue;
|
|
1823
|
+
}
|
|
1824
|
+
if (name === "checkbox") {
|
|
1825
|
+
properties.sdtType = "checkbox";
|
|
1826
|
+
const checkedNode = findFirstDescendant4(child, "checked");
|
|
1827
|
+
const checkedVal = checkedNode ? readOptionalAttribute2(checkedNode, "val") ?? "0" : "0";
|
|
1828
|
+
const checkedCharNode = findFirstDescendant4(child, "checkedState");
|
|
1829
|
+
const uncheckedCharNode = findFirstDescendant4(child, "uncheckedState");
|
|
1830
|
+
properties.checkbox = {
|
|
1831
|
+
checked: checkedVal === "1" || checkedVal === "true",
|
|
1832
|
+
...checkedCharNode ? { checkedChar: readOptionalAttribute2(checkedCharNode, "val") } : {},
|
|
1833
|
+
...uncheckedCharNode ? { uncheckedChar: readOptionalAttribute2(uncheckedCharNode, "val") } : {}
|
|
1834
|
+
};
|
|
1835
|
+
continue;
|
|
1836
|
+
}
|
|
1837
|
+
if (name === "date") {
|
|
1838
|
+
properties.sdtType = "date";
|
|
1839
|
+
const fullDate = readOptionalAttribute2(child, "fullDate");
|
|
1840
|
+
const dateFormatNode = findFirstChild4(child, "dateFormat");
|
|
1841
|
+
const lidNode = findFirstChild4(child, "lid");
|
|
1842
|
+
properties.datePicker = {
|
|
1843
|
+
...fullDate ? { fullDate } : {},
|
|
1844
|
+
...dateFormatNode ? { dateFormat: readOptionalAttribute2(dateFormatNode, "val") } : {},
|
|
1845
|
+
...lidNode ? { lid: readOptionalAttribute2(lidNode, "val") } : {}
|
|
1846
|
+
};
|
|
1847
|
+
continue;
|
|
1848
|
+
}
|
|
1849
|
+
if (name === "dropDownList") {
|
|
1850
|
+
properties.sdtType = "dropDownList";
|
|
1851
|
+
properties.dropdownList = readSdtListItems(child);
|
|
1852
|
+
continue;
|
|
1853
|
+
}
|
|
1854
|
+
if (name === "comboBox") {
|
|
1855
|
+
properties.sdtType = "comboBox";
|
|
1856
|
+
properties.comboBox = readSdtListItems(child);
|
|
1857
|
+
continue;
|
|
1858
|
+
}
|
|
1859
|
+
if (name === "text") {
|
|
1860
|
+
properties.sdtType = "plainText";
|
|
1861
|
+
continue;
|
|
1862
|
+
}
|
|
1863
|
+
if (name === "richText") {
|
|
1864
|
+
properties.sdtType = "richText";
|
|
1865
|
+
continue;
|
|
1866
|
+
}
|
|
1867
|
+
if (!properties.sdtType && name !== "id" && name !== "placeholder" && name !== "showingPlcHdr" && name !== "rPr") {
|
|
1868
|
+
properties.sdtType = name;
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
return properties;
|
|
1872
|
+
}
|
|
1873
|
+
function readSdtListItems(node) {
|
|
1874
|
+
const items = [];
|
|
1875
|
+
for (const child of node.children) {
|
|
1876
|
+
if (child.type !== "element" || localName5(child.name) !== "listItem") continue;
|
|
1877
|
+
const value = readOptionalAttribute2(child, "value") ?? "";
|
|
1878
|
+
const displayText = readOptionalAttribute2(child, "displayText");
|
|
1879
|
+
items.push({ value, ...displayText ? { displayText } : {} });
|
|
1880
|
+
}
|
|
1881
|
+
return items;
|
|
1882
|
+
}
|
|
1883
|
+
function findFirstChild4(node, local) {
|
|
1884
|
+
for (const child of node.children) {
|
|
1885
|
+
if (child.type === "element" && localName5(child.name) === local) return child;
|
|
1886
|
+
}
|
|
1887
|
+
return void 0;
|
|
1888
|
+
}
|
|
1889
|
+
function findFirstDescendant4(node, local) {
|
|
1890
|
+
for (const child of node.children) {
|
|
1891
|
+
if (child.type !== "element") continue;
|
|
1892
|
+
if (localName5(child.name) === local) return child;
|
|
1893
|
+
const nested = findFirstDescendant4(child, local);
|
|
1894
|
+
if (nested) return nested;
|
|
1895
|
+
}
|
|
1896
|
+
return void 0;
|
|
1897
|
+
}
|
|
1898
|
+
function readTableStyleId(node) {
|
|
1899
|
+
for (const child of node.children) {
|
|
1900
|
+
if (child.type !== "element" || localName5(child.name) !== "tblStyle") continue;
|
|
1901
|
+
const styleId = child.attributes["w:val"] ?? child.attributes.val;
|
|
1902
|
+
if (styleId) return styleId;
|
|
1903
|
+
}
|
|
1904
|
+
return void 0;
|
|
1905
|
+
}
|
|
1906
|
+
function readTableLook(node) {
|
|
1907
|
+
const tblLookNode = node.children.find(
|
|
1908
|
+
(child) => child.type === "element" && localName5(child.name) === "tblLook"
|
|
1909
|
+
);
|
|
1910
|
+
if (!tblLookNode) {
|
|
1911
|
+
return void 0;
|
|
1912
|
+
}
|
|
1913
|
+
const tableLook = {};
|
|
1914
|
+
const val = tblLookNode.attributes["w:val"] ?? tblLookNode.attributes.val;
|
|
1915
|
+
if (val) {
|
|
1916
|
+
tableLook.val = val;
|
|
1917
|
+
}
|
|
1918
|
+
for (const [attribute, key] of [
|
|
1919
|
+
["w:firstRow", "firstRow"],
|
|
1920
|
+
["w:lastRow", "lastRow"],
|
|
1921
|
+
["w:firstColumn", "firstColumn"],
|
|
1922
|
+
["w:lastColumn", "lastColumn"],
|
|
1923
|
+
["w:noHBand", "noHBand"],
|
|
1924
|
+
["w:noVBand", "noVBand"]
|
|
1925
|
+
]) {
|
|
1926
|
+
const fallback = attribute.replace("w:", "");
|
|
1927
|
+
const raw = tblLookNode.attributes[attribute] ?? tblLookNode.attributes[fallback];
|
|
1928
|
+
if (raw !== void 0) {
|
|
1929
|
+
tableLook[key] = raw !== "0" && raw !== "false" && raw !== "off";
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
return Object.keys(tableLook).length > 0 ? tableLook : void 0;
|
|
1933
|
+
}
|
|
1934
|
+
function readTableGridColumns(node) {
|
|
1935
|
+
return node.children.filter((child) => child.type === "element" && localName5(child.name) === "gridCol").map((child) => {
|
|
1936
|
+
const raw = child.attributes["w:w"] ?? child.attributes.w ?? "0";
|
|
1937
|
+
const value = Number.parseInt(raw, 10);
|
|
1938
|
+
return Number.isFinite(value) && value > 0 ? value : 0;
|
|
1939
|
+
});
|
|
1940
|
+
}
|
|
1941
|
+
function tableRequiresOpaquePreservation(rawXml) {
|
|
1942
|
+
if (/<w:(ins|del|rPrChange|pPrChange|tblPrChange|trPrChange|tcPrChange|sectPrChange|cellIns|cellDel|cellMerge|smartTag|tblCellSpacing)\b/.test(rawXml)) {
|
|
1943
|
+
return true;
|
|
1944
|
+
}
|
|
1945
|
+
const simpleInstructions = [...rawXml.matchAll(/\bw:instr="([^"]*)"/g)].map((match) => match[1] ?? "");
|
|
1946
|
+
const complexInstructions = extractComplexFieldInstructions(rawXml);
|
|
1947
|
+
for (const instruction of [...simpleInstructions, ...complexInstructions]) {
|
|
1948
|
+
const classification = classifyFieldInstruction(instruction);
|
|
1949
|
+
if (!isSafeMainStoryTableFieldFamily(classification.family)) {
|
|
1950
|
+
return true;
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
return false;
|
|
1954
|
+
}
|
|
1955
|
+
function isSafeMainStoryTableFieldFamily(family) {
|
|
1956
|
+
return family === "REF" || family === "PAGEREF" || family === "NOTEREF" || family === "TOC" || family === "PAGE" || family === "NUMPAGES";
|
|
1957
|
+
}
|
|
1958
|
+
function extractComplexFieldInstructions(rawXml) {
|
|
1959
|
+
const tokenPattern = /<(?:\w+:)?fldChar\b[^>]*?(?:\w+:)?fldCharType="(begin|separate|end)"[^>]*?(?:\/>|>[\s\S]*?<\/(?:\w+:)?fldChar>)|<(?:\w+:)?instrText\b[^>]*>([\s\S]*?)<\/(?:\w+:)?instrText>/gu;
|
|
1960
|
+
const instructions = [];
|
|
1961
|
+
let activeInstruction = "";
|
|
1962
|
+
let capturingInstruction = false;
|
|
1963
|
+
for (const match of rawXml.matchAll(tokenPattern)) {
|
|
1964
|
+
const fldCharType = match[1];
|
|
1965
|
+
const instrText = match[2];
|
|
1966
|
+
if (fldCharType === "begin") {
|
|
1967
|
+
activeInstruction = "";
|
|
1968
|
+
capturingInstruction = true;
|
|
1969
|
+
continue;
|
|
1970
|
+
}
|
|
1971
|
+
if (fldCharType === "separate" || fldCharType === "end") {
|
|
1972
|
+
if (capturingInstruction && activeInstruction.trim().length > 0) {
|
|
1973
|
+
instructions.push(activeInstruction);
|
|
1974
|
+
}
|
|
1975
|
+
activeInstruction = "";
|
|
1976
|
+
capturingInstruction = false;
|
|
1977
|
+
continue;
|
|
1978
|
+
}
|
|
1979
|
+
if (capturingInstruction && instrText !== void 0) {
|
|
1980
|
+
activeInstruction += decodeXmlEntities3(instrText);
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
return instructions;
|
|
1984
|
+
}
|
|
1985
|
+
function readTableRowGridPosition(node, local) {
|
|
1986
|
+
const positionNode = node.children.find(
|
|
1987
|
+
(child) => child.type === "element" && localName5(child.name) === local
|
|
1988
|
+
);
|
|
1989
|
+
if (!positionNode) return void 0;
|
|
1990
|
+
const raw = positionNode.attributes["w:val"] ?? positionNode.attributes.val;
|
|
1991
|
+
const value = Number.parseInt(raw ?? "", 10);
|
|
1992
|
+
return Number.isFinite(value) && value > 0 ? value : 0;
|
|
1993
|
+
}
|
|
1994
|
+
function readTableRowWidth(node, local) {
|
|
1995
|
+
const widthNode = node.children.find(
|
|
1996
|
+
(child) => child.type === "element" && localName5(child.name) === local
|
|
1997
|
+
);
|
|
1998
|
+
if (!widthNode) return void 0;
|
|
1999
|
+
const rawValue = widthNode.attributes["w:w"] ?? widthNode.attributes.w;
|
|
2000
|
+
const value = Number.parseInt(rawValue ?? "", 10);
|
|
2001
|
+
if (!Number.isFinite(value)) {
|
|
2002
|
+
return void 0;
|
|
2003
|
+
}
|
|
2004
|
+
const rawType = (widthNode.attributes["w:type"] ?? widthNode.attributes.type ?? "dxa").toLowerCase();
|
|
2005
|
+
const type = rawType === "auto" ? "auto" : rawType === "pct" ? "pct" : rawType === "nil" ? "nil" : "dxa";
|
|
2006
|
+
return { value, type };
|
|
2007
|
+
}
|
|
2008
|
+
function readCellGridSpan(node) {
|
|
2009
|
+
const gridSpanNode = node.children.find(
|
|
2010
|
+
(child) => child.type === "element" && localName5(child.name) === "gridSpan"
|
|
2011
|
+
);
|
|
2012
|
+
if (!gridSpanNode) return void 0;
|
|
2013
|
+
const raw = gridSpanNode.attributes["w:val"] ?? gridSpanNode.attributes.val;
|
|
2014
|
+
const value = Number.parseInt(raw ?? "0", 10);
|
|
2015
|
+
return Number.isFinite(value) && value > 1 ? value : void 0;
|
|
2016
|
+
}
|
|
2017
|
+
function readCellVerticalMerge(node) {
|
|
2018
|
+
const vMergeNode = node.children.find(
|
|
2019
|
+
(child) => child.type === "element" && localName5(child.name) === "vMerge"
|
|
2020
|
+
);
|
|
2021
|
+
if (!vMergeNode) return void 0;
|
|
2022
|
+
const raw = (vMergeNode.attributes["w:val"] ?? vMergeNode.attributes.val ?? "continue").toLowerCase();
|
|
2023
|
+
return raw === "restart" ? "restart" : "continue";
|
|
2024
|
+
}
|
|
2025
|
+
function readParagraphAlignment(node) {
|
|
2026
|
+
const jcNode = node.children.find(
|
|
2027
|
+
(child) => child.type === "element" && localName5(child.name) === "jc"
|
|
2028
|
+
);
|
|
2029
|
+
if (!jcNode) return void 0;
|
|
2030
|
+
const val = (jcNode.attributes["w:val"] ?? jcNode.attributes.val ?? "").toLowerCase();
|
|
2031
|
+
if (val === "left" || val === "center" || val === "right" || val === "both" || val === "distribute") {
|
|
2032
|
+
return val;
|
|
2033
|
+
}
|
|
2034
|
+
return void 0;
|
|
2035
|
+
}
|
|
2036
|
+
function readParagraphSpacing(node) {
|
|
2037
|
+
const spacingNode = node.children.find(
|
|
2038
|
+
(child) => child.type === "element" && localName5(child.name) === "spacing"
|
|
2039
|
+
);
|
|
2040
|
+
if (!spacingNode) return void 0;
|
|
2041
|
+
const spacing = {};
|
|
2042
|
+
const before = spacingNode.attributes["w:before"] ?? spacingNode.attributes.before;
|
|
2043
|
+
const after = spacingNode.attributes["w:after"] ?? spacingNode.attributes.after;
|
|
2044
|
+
const line = spacingNode.attributes["w:line"] ?? spacingNode.attributes.line;
|
|
2045
|
+
const lineRule = spacingNode.attributes["w:lineRule"] ?? spacingNode.attributes.lineRule;
|
|
2046
|
+
if (before !== void 0) {
|
|
2047
|
+
const v = Number.parseInt(before, 10);
|
|
2048
|
+
if (Number.isFinite(v)) spacing.before = v;
|
|
2049
|
+
}
|
|
2050
|
+
if (after !== void 0) {
|
|
2051
|
+
const v = Number.parseInt(after, 10);
|
|
2052
|
+
if (Number.isFinite(v)) spacing.after = v;
|
|
2053
|
+
}
|
|
2054
|
+
if (line !== void 0) {
|
|
2055
|
+
const v = Number.parseInt(line, 10);
|
|
2056
|
+
if (Number.isFinite(v)) spacing.line = v;
|
|
2057
|
+
}
|
|
2058
|
+
if (lineRule !== void 0) {
|
|
2059
|
+
const lr = lineRule.toLowerCase();
|
|
2060
|
+
if (lr === "auto" || lr === "exact") {
|
|
2061
|
+
spacing.lineRule = lr;
|
|
2062
|
+
} else if (lr === "atleast") {
|
|
2063
|
+
spacing.lineRule = "atLeast";
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
if (spacing.before === void 0 && spacing.after === void 0 && spacing.line === void 0 && spacing.lineRule === void 0) {
|
|
2067
|
+
return void 0;
|
|
2068
|
+
}
|
|
2069
|
+
return spacing;
|
|
2070
|
+
}
|
|
2071
|
+
function readParagraphIndentation(node) {
|
|
2072
|
+
const indNode = node.children.find(
|
|
2073
|
+
(child) => child.type === "element" && localName5(child.name) === "ind"
|
|
2074
|
+
);
|
|
2075
|
+
if (!indNode) return void 0;
|
|
2076
|
+
const indentation = {};
|
|
2077
|
+
const left = indNode.attributes["w:left"] ?? indNode.attributes.left;
|
|
2078
|
+
const right = indNode.attributes["w:right"] ?? indNode.attributes.right;
|
|
2079
|
+
const firstLine = indNode.attributes["w:firstLine"] ?? indNode.attributes.firstLine;
|
|
2080
|
+
const hanging = indNode.attributes["w:hanging"] ?? indNode.attributes.hanging;
|
|
2081
|
+
if (left !== void 0) {
|
|
2082
|
+
const v = Number.parseInt(left, 10);
|
|
2083
|
+
if (Number.isFinite(v)) indentation.left = v;
|
|
2084
|
+
}
|
|
2085
|
+
if (right !== void 0) {
|
|
2086
|
+
const v = Number.parseInt(right, 10);
|
|
2087
|
+
if (Number.isFinite(v)) indentation.right = v;
|
|
2088
|
+
}
|
|
2089
|
+
if (firstLine !== void 0) {
|
|
2090
|
+
const v = Number.parseInt(firstLine, 10);
|
|
2091
|
+
if (Number.isFinite(v)) indentation.firstLine = v;
|
|
2092
|
+
}
|
|
2093
|
+
if (hanging !== void 0) {
|
|
2094
|
+
const v = Number.parseInt(hanging, 10);
|
|
2095
|
+
if (Number.isFinite(v)) indentation.hanging = v;
|
|
2096
|
+
}
|
|
2097
|
+
if (indentation.left === void 0 && indentation.right === void 0 && indentation.firstLine === void 0 && indentation.hanging === void 0) {
|
|
2098
|
+
return void 0;
|
|
2099
|
+
}
|
|
2100
|
+
return indentation;
|
|
2101
|
+
}
|
|
2102
|
+
function readParagraphTabStops(node) {
|
|
2103
|
+
const tabsNode = node.children.find(
|
|
2104
|
+
(child) => child.type === "element" && localName5(child.name) === "tabs"
|
|
2105
|
+
);
|
|
2106
|
+
if (!tabsNode) return void 0;
|
|
2107
|
+
const tabStops = [];
|
|
2108
|
+
for (const child of tabsNode.children) {
|
|
2109
|
+
if (child.type !== "element" || localName5(child.name) !== "tab") continue;
|
|
2110
|
+
const pos = child.attributes["w:pos"] ?? child.attributes.pos;
|
|
2111
|
+
const val = (child.attributes["w:val"] ?? child.attributes.val ?? "left").toLowerCase();
|
|
2112
|
+
const leader = (child.attributes["w:leader"] ?? child.attributes.leader ?? "none").toLowerCase();
|
|
2113
|
+
if (pos === void 0) continue;
|
|
2114
|
+
const position = Number.parseInt(pos, 10);
|
|
2115
|
+
if (!Number.isFinite(position)) continue;
|
|
2116
|
+
const align = ["left", "center", "right", "decimal", "bar", "clear"].includes(
|
|
2117
|
+
val
|
|
2118
|
+
) ? val : "left";
|
|
2119
|
+
const leaderValue = leader === "none" || leader === "dot" || leader === "hyphen" || leader === "underscore" || leader === "heavy" ? leader : leader === "middledot" ? "middleDot" : void 0;
|
|
2120
|
+
tabStops.push({
|
|
2121
|
+
position,
|
|
2122
|
+
align,
|
|
2123
|
+
...leaderValue && leaderValue !== "none" ? { leader: leaderValue } : {}
|
|
2124
|
+
});
|
|
2125
|
+
}
|
|
2126
|
+
return tabStops.length > 0 ? tabStops : void 0;
|
|
2127
|
+
}
|
|
2128
|
+
function readOnOffParagraphProperty(node, name) {
|
|
2129
|
+
const propNode = node.children.find(
|
|
2130
|
+
(child) => child.type === "element" && localName5(child.name) === name
|
|
2131
|
+
);
|
|
2132
|
+
if (!propNode) return void 0;
|
|
2133
|
+
const val = (propNode.attributes["w:val"] ?? propNode.attributes.val ?? "true").toLowerCase();
|
|
2134
|
+
return val !== "false" && val !== "0" && val !== "off" ? true : void 0;
|
|
2135
|
+
}
|
|
2136
|
+
function readOptionalOnOffParagraphProperty(node, name) {
|
|
2137
|
+
const propNode = node.children.find(
|
|
2138
|
+
(child) => child.type === "element" && localName5(child.name) === name
|
|
2139
|
+
);
|
|
2140
|
+
if (!propNode) return void 0;
|
|
2141
|
+
const val = (propNode.attributes["w:val"] ?? propNode.attributes.val ?? "true").toLowerCase();
|
|
2142
|
+
return val !== "false" && val !== "0" && val !== "off";
|
|
2143
|
+
}
|
|
2144
|
+
function readParagraphOutlineLevel(node) {
|
|
2145
|
+
const propNode = node.children.find(
|
|
2146
|
+
(child) => child.type === "element" && localName5(child.name) === "outlineLvl"
|
|
2147
|
+
);
|
|
2148
|
+
if (!propNode) return void 0;
|
|
2149
|
+
const val = propNode.attributes["w:val"] ?? propNode.attributes.val;
|
|
2150
|
+
if (val === void 0) return void 0;
|
|
2151
|
+
const level = Number.parseInt(val, 10);
|
|
2152
|
+
return Number.isFinite(level) ? level : void 0;
|
|
2153
|
+
}
|
|
2154
|
+
function readParagraphBorders(node) {
|
|
2155
|
+
const borderContainer = node.children.find(
|
|
2156
|
+
(child) => child.type === "element" && localName5(child.name) === "pBdr"
|
|
2157
|
+
);
|
|
2158
|
+
if (!borderContainer) {
|
|
2159
|
+
return void 0;
|
|
2160
|
+
}
|
|
2161
|
+
const borders = {};
|
|
2162
|
+
for (const [name, key] of [
|
|
2163
|
+
["top", "top"],
|
|
2164
|
+
["left", "left"],
|
|
2165
|
+
["bottom", "bottom"],
|
|
2166
|
+
["right", "right"],
|
|
2167
|
+
["bar", "bar"],
|
|
2168
|
+
["between", "between"]
|
|
2169
|
+
]) {
|
|
2170
|
+
const borderNode = borderContainer.children.find(
|
|
2171
|
+
(child) => child.type === "element" && localName5(child.name) === name
|
|
2172
|
+
);
|
|
2173
|
+
if (borderNode) {
|
|
2174
|
+
const border = readBorder(borderNode);
|
|
2175
|
+
if (border) {
|
|
2176
|
+
borders[key] = border;
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
return Object.keys(borders).length > 0 ? borders : void 0;
|
|
2181
|
+
}
|
|
2182
|
+
function readParagraphShading(node) {
|
|
2183
|
+
const shadingNode = node.children.find(
|
|
2184
|
+
(child) => child.type === "element" && localName5(child.name) === "shd"
|
|
2185
|
+
);
|
|
2186
|
+
if (!shadingNode) {
|
|
2187
|
+
return void 0;
|
|
2188
|
+
}
|
|
2189
|
+
const shading = {};
|
|
2190
|
+
const fill = shadingNode.attributes["w:fill"] ?? shadingNode.attributes.fill;
|
|
2191
|
+
const color = shadingNode.attributes["w:color"] ?? shadingNode.attributes.color;
|
|
2192
|
+
const val = shadingNode.attributes["w:val"] ?? shadingNode.attributes.val;
|
|
2193
|
+
if (fill) shading.fill = fill;
|
|
2194
|
+
if (color) shading.color = color;
|
|
2195
|
+
if (val) shading.val = val;
|
|
2196
|
+
return Object.keys(shading).length > 0 ? shading : void 0;
|
|
2197
|
+
}
|
|
2198
|
+
function readParagraphCnfStyle(node) {
|
|
2199
|
+
const cnfStyleNode = node.children.find(
|
|
2200
|
+
(child) => child.type === "element" && localName5(child.name) === "cnfStyle"
|
|
2201
|
+
);
|
|
2202
|
+
return cnfStyleNode?.attributes["w:val"] ?? cnfStyleNode?.attributes.val;
|
|
2203
|
+
}
|
|
2204
|
+
function readBorder(node) {
|
|
2205
|
+
const border = {};
|
|
2206
|
+
const value = node.attributes["w:val"] ?? node.attributes.val;
|
|
2207
|
+
const size = node.attributes["w:sz"] ?? node.attributes.sz;
|
|
2208
|
+
const space = node.attributes["w:space"] ?? node.attributes.space;
|
|
2209
|
+
const color = node.attributes["w:color"] ?? node.attributes.color;
|
|
2210
|
+
if (value) border.value = value;
|
|
2211
|
+
if (size !== void 0) {
|
|
2212
|
+
const parsedSize = Number.parseInt(size, 10);
|
|
2213
|
+
if (Number.isFinite(parsedSize)) border.size = parsedSize;
|
|
2214
|
+
}
|
|
2215
|
+
if (space !== void 0) {
|
|
2216
|
+
const parsedSpace = Number.parseInt(space, 10);
|
|
2217
|
+
if (Number.isFinite(parsedSpace)) border.space = parsedSpace;
|
|
2218
|
+
}
|
|
2219
|
+
if (color) border.color = color;
|
|
2220
|
+
return Object.keys(border).length > 0 ? border : void 0;
|
|
2221
|
+
}
|
|
2222
|
+
function readParagraphStyleId(node) {
|
|
2223
|
+
for (const child of node.children) {
|
|
2224
|
+
if (child.type !== "element" || localName5(child.name) !== "pStyle") {
|
|
2225
|
+
continue;
|
|
2226
|
+
}
|
|
2227
|
+
const styleId = child.attributes["w:val"] ?? child.attributes.val;
|
|
2228
|
+
if (styleId) {
|
|
2229
|
+
return styleId;
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
return void 0;
|
|
2233
|
+
}
|
|
2234
|
+
function readParagraphNumbering(node) {
|
|
2235
|
+
const numberingProperties = node.children.find(
|
|
2236
|
+
(child) => child.type === "element" && localName5(child.name) === "numPr"
|
|
2237
|
+
);
|
|
2238
|
+
if (!numberingProperties) {
|
|
2239
|
+
return void 0;
|
|
2240
|
+
}
|
|
2241
|
+
const levelNode = numberingProperties.children.find(
|
|
2242
|
+
(child) => child.type === "element" && localName5(child.name) === "ilvl"
|
|
2243
|
+
);
|
|
2244
|
+
const instanceNode = numberingProperties.children.find(
|
|
2245
|
+
(child) => child.type === "element" && localName5(child.name) === "numId"
|
|
2246
|
+
);
|
|
2247
|
+
const rawLevel = levelNode?.attributes["w:val"] ?? levelNode?.attributes.val;
|
|
2248
|
+
const rawInstanceId = instanceNode?.attributes["w:val"] ?? instanceNode?.attributes.val;
|
|
2249
|
+
if (!rawInstanceId || rawLevel === void 0 || !/^-?\d+$/.test(rawLevel)) {
|
|
2250
|
+
return void 0;
|
|
2251
|
+
}
|
|
2252
|
+
return {
|
|
2253
|
+
numberingInstanceId: toCanonicalNumberingInstanceId(rawInstanceId),
|
|
2254
|
+
level: Number.parseInt(rawLevel, 10)
|
|
2255
|
+
};
|
|
2256
|
+
}
|
|
2257
|
+
function parseRun(node, sourceXml, relationships, mediaParts, sourcePartPath) {
|
|
2258
|
+
const marksResult = readRunMarks(node, sourceXml);
|
|
2259
|
+
if (!marksResult.supported) {
|
|
2260
|
+
return [
|
|
2261
|
+
{
|
|
2262
|
+
type: "opaque_inline",
|
|
2263
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
2264
|
+
}
|
|
2265
|
+
];
|
|
2266
|
+
}
|
|
2267
|
+
const marks = marksResult.marks;
|
|
2268
|
+
const result = [];
|
|
2269
|
+
let encounteredUnsupportedChild = false;
|
|
2270
|
+
for (const child of node.children) {
|
|
2271
|
+
if (child.type !== "element") {
|
|
2272
|
+
continue;
|
|
2273
|
+
}
|
|
2274
|
+
switch (localName5(child.name)) {
|
|
2275
|
+
case "rPr":
|
|
2276
|
+
break;
|
|
2277
|
+
case "t": {
|
|
2278
|
+
const text = child.children.filter((entry) => entry.type === "text").map((entry) => entry.text).join("");
|
|
2279
|
+
result.push({
|
|
2280
|
+
type: "text",
|
|
2281
|
+
text,
|
|
2282
|
+
...marks.length > 0 ? { marks } : {}
|
|
2283
|
+
});
|
|
2284
|
+
break;
|
|
2285
|
+
}
|
|
2286
|
+
case "tab":
|
|
2287
|
+
result.push({ type: "tab" });
|
|
2288
|
+
break;
|
|
2289
|
+
case "sym": {
|
|
2290
|
+
const symbol = parseSymbolNode(child, marks);
|
|
2291
|
+
if (!symbol) {
|
|
2292
|
+
encounteredUnsupportedChild = true;
|
|
2293
|
+
result.push({
|
|
2294
|
+
type: "opaque_inline",
|
|
2295
|
+
rawXml: sourceXml.slice(child.start, child.end)
|
|
2296
|
+
});
|
|
2297
|
+
break;
|
|
2298
|
+
}
|
|
2299
|
+
result.push(symbol);
|
|
2300
|
+
break;
|
|
2301
|
+
}
|
|
2302
|
+
case "br":
|
|
2303
|
+
if (isColumnBreak(child)) {
|
|
2304
|
+
result.push({ type: "column_break" });
|
|
2305
|
+
} else if (isSimpleLineBreak(child)) {
|
|
2306
|
+
result.push({ type: "hard_break" });
|
|
2307
|
+
} else {
|
|
2308
|
+
result.push({
|
|
2309
|
+
type: "opaque_inline",
|
|
2310
|
+
rawXml: sourceXml.slice(child.start, child.end)
|
|
2311
|
+
});
|
|
2312
|
+
}
|
|
2313
|
+
break;
|
|
2314
|
+
case "drawing": {
|
|
2315
|
+
const drawingXml = sourceXml.slice(child.start, child.end);
|
|
2316
|
+
try {
|
|
2317
|
+
const complexContent = parseComplexContentXml(
|
|
2318
|
+
drawingXml,
|
|
2319
|
+
relationships,
|
|
2320
|
+
mediaParts,
|
|
2321
|
+
sourcePartPath
|
|
2322
|
+
);
|
|
2323
|
+
if (complexContent) {
|
|
2324
|
+
result.push(complexContent);
|
|
2325
|
+
break;
|
|
2326
|
+
}
|
|
2327
|
+
} catch {
|
|
2328
|
+
}
|
|
2329
|
+
try {
|
|
2330
|
+
const shapeResult = parseShapeXml(drawingXml);
|
|
2331
|
+
if (shapeResult) {
|
|
2332
|
+
result.push(shapeResult);
|
|
2333
|
+
break;
|
|
2334
|
+
}
|
|
2335
|
+
} catch {
|
|
2336
|
+
}
|
|
2337
|
+
const parsedMedia = parseInlineMediaXml(
|
|
2338
|
+
drawingXml,
|
|
2339
|
+
relationships,
|
|
2340
|
+
mediaParts,
|
|
2341
|
+
sourcePartPath
|
|
2342
|
+
);
|
|
2343
|
+
if (parsedMedia.length === 0) {
|
|
2344
|
+
encounteredUnsupportedChild = true;
|
|
2345
|
+
result.push({
|
|
2346
|
+
type: "opaque_inline",
|
|
2347
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
2348
|
+
});
|
|
2349
|
+
break;
|
|
2350
|
+
}
|
|
2351
|
+
const semanticChildren = node.children.filter(
|
|
2352
|
+
(entry) => entry.type === "element" && localName5(entry.name) !== "rPr"
|
|
2353
|
+
);
|
|
2354
|
+
const placementXml = semanticChildren.length === 1 ? sourceXml.slice(node.start, node.end) : sourceXml.slice(child.start, child.end);
|
|
2355
|
+
result.push(
|
|
2356
|
+
...parsedMedia.map((media) => ({
|
|
2357
|
+
type: "image",
|
|
2358
|
+
mediaId: media.mediaId,
|
|
2359
|
+
relationshipId: media.relationshipId,
|
|
2360
|
+
packagePartName: media.packagePartName,
|
|
2361
|
+
contentType: media.contentType,
|
|
2362
|
+
filename: media.filename,
|
|
2363
|
+
...media.altText ? { altText: media.altText } : {},
|
|
2364
|
+
...media.widthEmu !== void 0 ? { widthEmu: media.widthEmu } : {},
|
|
2365
|
+
...media.heightEmu !== void 0 ? { heightEmu: media.heightEmu } : {},
|
|
2366
|
+
placementXml,
|
|
2367
|
+
...media.display ? { display: media.display } : {},
|
|
2368
|
+
...media.floating ? { floating: media.floating } : {}
|
|
2369
|
+
}))
|
|
2370
|
+
);
|
|
2371
|
+
break;
|
|
2372
|
+
}
|
|
2373
|
+
case "pict": {
|
|
2374
|
+
const pictXml = sourceXml.slice(child.start, child.end);
|
|
2375
|
+
try {
|
|
2376
|
+
const vmlResult = parseVmlXml(pictXml);
|
|
2377
|
+
if (vmlResult) {
|
|
2378
|
+
result.push({
|
|
2379
|
+
...vmlResult,
|
|
2380
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
2381
|
+
});
|
|
2382
|
+
break;
|
|
2383
|
+
}
|
|
2384
|
+
} catch {
|
|
2385
|
+
}
|
|
2386
|
+
encounteredUnsupportedChild = true;
|
|
2387
|
+
result.push({
|
|
2388
|
+
type: "opaque_inline",
|
|
2389
|
+
rawXml: pictXml
|
|
2390
|
+
});
|
|
2391
|
+
break;
|
|
2392
|
+
}
|
|
2393
|
+
case "commentReference":
|
|
2394
|
+
break;
|
|
2395
|
+
case "footnoteReference": {
|
|
2396
|
+
const noteId = child.attributes["w:id"] ?? child.attributes.id ?? "";
|
|
2397
|
+
if (noteId) {
|
|
2398
|
+
result.push({
|
|
2399
|
+
type: "footnote_ref",
|
|
2400
|
+
noteId,
|
|
2401
|
+
noteKind: "footnote"
|
|
2402
|
+
});
|
|
2403
|
+
}
|
|
2404
|
+
break;
|
|
2405
|
+
}
|
|
2406
|
+
case "endnoteReference": {
|
|
2407
|
+
const noteId = child.attributes["w:id"] ?? child.attributes.id ?? "";
|
|
2408
|
+
if (noteId) {
|
|
2409
|
+
result.push({
|
|
2410
|
+
type: "footnote_ref",
|
|
2411
|
+
noteId,
|
|
2412
|
+
noteKind: "endnote"
|
|
2413
|
+
});
|
|
2414
|
+
}
|
|
2415
|
+
break;
|
|
2416
|
+
}
|
|
2417
|
+
case "lastRenderedPageBreak":
|
|
2418
|
+
case "proofErr":
|
|
2419
|
+
result.push({
|
|
2420
|
+
type: "opaque_inline",
|
|
2421
|
+
rawXml: sourceXml.slice(child.start, child.end)
|
|
2422
|
+
});
|
|
2423
|
+
break;
|
|
2424
|
+
default:
|
|
2425
|
+
encounteredUnsupportedChild = true;
|
|
2426
|
+
result.push({
|
|
2427
|
+
type: "opaque_inline",
|
|
2428
|
+
rawXml: sourceXml.slice(child.start, child.end)
|
|
2429
|
+
});
|
|
2430
|
+
break;
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
if (encounteredUnsupportedChild && result.every((child) => child.type === "opaque_inline")) {
|
|
2434
|
+
return [
|
|
2435
|
+
{
|
|
2436
|
+
type: "opaque_inline",
|
|
2437
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
2438
|
+
}
|
|
2439
|
+
];
|
|
2440
|
+
}
|
|
2441
|
+
return result;
|
|
2442
|
+
}
|
|
2443
|
+
function parseRevisionContainer(node, sourceXml, relationshipMap) {
|
|
2444
|
+
const result = [];
|
|
2445
|
+
const allowsDeletedText = localName5(node.name) === "del";
|
|
2446
|
+
for (const child of node.children) {
|
|
2447
|
+
if (child.type !== "element") {
|
|
2448
|
+
continue;
|
|
2449
|
+
}
|
|
2450
|
+
switch (localName5(child.name)) {
|
|
2451
|
+
case "r": {
|
|
2452
|
+
const run = parseRunContentOnly(child, sourceXml, {
|
|
2453
|
+
allowDeletedText: allowsDeletedText,
|
|
2454
|
+
preserveUnsupportedReviewMarkup: true
|
|
2455
|
+
});
|
|
2456
|
+
if (!run.supported) {
|
|
2457
|
+
return [
|
|
2458
|
+
{
|
|
2459
|
+
type: "opaque_inline",
|
|
2460
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
2461
|
+
}
|
|
2462
|
+
];
|
|
2463
|
+
}
|
|
2464
|
+
result.push(...run.nodes);
|
|
2465
|
+
break;
|
|
2466
|
+
}
|
|
2467
|
+
case "hyperlink": {
|
|
2468
|
+
const hyperlink = parseHyperlink(child, sourceXml, relationshipMap, {
|
|
2469
|
+
allowDeletedText: allowsDeletedText,
|
|
2470
|
+
preserveUnsupportedReviewMarkup: true
|
|
2471
|
+
});
|
|
2472
|
+
if (hyperlink.type === "opaque_inline") {
|
|
2473
|
+
return [
|
|
2474
|
+
{
|
|
2475
|
+
type: "opaque_inline",
|
|
2476
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
2477
|
+
}
|
|
2478
|
+
];
|
|
2479
|
+
}
|
|
2480
|
+
result.push(hyperlink);
|
|
2481
|
+
break;
|
|
2482
|
+
}
|
|
2483
|
+
case "commentRangeStart":
|
|
2484
|
+
case "commentRangeEnd":
|
|
2485
|
+
case "bookmarkStart":
|
|
2486
|
+
case "bookmarkEnd":
|
|
2487
|
+
case "proofErr":
|
|
2488
|
+
case "lastRenderedPageBreak":
|
|
2489
|
+
return [
|
|
2490
|
+
{
|
|
2491
|
+
type: "opaque_inline",
|
|
2492
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
2493
|
+
}
|
|
2494
|
+
];
|
|
2495
|
+
case "permStart":
|
|
2496
|
+
result.push(parsePermStartNode(child, sourceXml));
|
|
2497
|
+
break;
|
|
2498
|
+
case "permEnd":
|
|
2499
|
+
result.push(parsePermEndNode(child, sourceXml));
|
|
2500
|
+
break;
|
|
2501
|
+
default:
|
|
2502
|
+
return [
|
|
2503
|
+
{
|
|
2504
|
+
type: "opaque_inline",
|
|
2505
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
2506
|
+
}
|
|
2507
|
+
];
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2510
|
+
return result;
|
|
2511
|
+
}
|
|
2512
|
+
function parseHyperlink(node, sourceXml, relationshipMap, options = {}) {
|
|
2513
|
+
const relationshipId = node.attributes["r:id"] ?? node.attributes.id;
|
|
2514
|
+
const anchor = node.attributes["w:anchor"] ?? node.attributes.anchor;
|
|
2515
|
+
let href;
|
|
2516
|
+
if (relationshipId) {
|
|
2517
|
+
const relationship = relationshipMap.get(relationshipId);
|
|
2518
|
+
if (relationship && relationship.type === HYPERLINK_RELATIONSHIP_TYPE && relationship.targetMode === "external") {
|
|
2519
|
+
href = relationship.target;
|
|
2520
|
+
}
|
|
2521
|
+
} else if (anchor) {
|
|
2522
|
+
href = `#${anchor}`;
|
|
2523
|
+
}
|
|
2524
|
+
if (!href) {
|
|
2525
|
+
return {
|
|
2526
|
+
type: "opaque_inline",
|
|
2527
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
2528
|
+
};
|
|
2529
|
+
}
|
|
2530
|
+
const children = [];
|
|
2531
|
+
for (const child of node.children) {
|
|
2532
|
+
if (child.type !== "element") {
|
|
2533
|
+
continue;
|
|
2534
|
+
}
|
|
2535
|
+
if (localName5(child.name) !== "r") {
|
|
2536
|
+
return {
|
|
2537
|
+
type: "opaque_inline",
|
|
2538
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
2539
|
+
};
|
|
2540
|
+
}
|
|
2541
|
+
const run = parseRunContentOnly(child, sourceXml, {
|
|
2542
|
+
allowDeletedText: options.allowDeletedText,
|
|
2543
|
+
preserveUnsupportedReviewMarkup: options.preserveUnsupportedReviewMarkup
|
|
2544
|
+
});
|
|
2545
|
+
if (!run.supported) {
|
|
2546
|
+
return {
|
|
2547
|
+
type: "opaque_inline",
|
|
2548
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
2549
|
+
};
|
|
2550
|
+
}
|
|
2551
|
+
children.push(...run.nodes);
|
|
2552
|
+
}
|
|
2553
|
+
return {
|
|
2554
|
+
type: "hyperlink",
|
|
2555
|
+
href,
|
|
2556
|
+
children,
|
|
2557
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
2558
|
+
};
|
|
2559
|
+
}
|
|
2560
|
+
function parseRunContentOnly(node, _sourceXml, options = {}) {
|
|
2561
|
+
const marksResult = readRunMarks(node, _sourceXml);
|
|
2562
|
+
if (!marksResult.supported) {
|
|
2563
|
+
return { nodes: [], supported: false };
|
|
2564
|
+
}
|
|
2565
|
+
const marks = marksResult.marks;
|
|
2566
|
+
const nodes = [];
|
|
2567
|
+
for (const child of node.children) {
|
|
2568
|
+
if (child.type !== "element") {
|
|
2569
|
+
continue;
|
|
2570
|
+
}
|
|
2571
|
+
switch (localName5(child.name)) {
|
|
2572
|
+
case "rPr":
|
|
2573
|
+
break;
|
|
2574
|
+
case "t": {
|
|
2575
|
+
const text = child.children.filter((entry) => entry.type === "text").map((entry) => entry.text).join("");
|
|
2576
|
+
nodes.push({
|
|
2577
|
+
type: "text",
|
|
2578
|
+
text,
|
|
2579
|
+
...marks.length > 0 ? { marks } : {}
|
|
2580
|
+
});
|
|
2581
|
+
break;
|
|
2582
|
+
}
|
|
2583
|
+
case "delText":
|
|
2584
|
+
case "delInstrText":
|
|
2585
|
+
if (!options.allowDeletedText) {
|
|
2586
|
+
return { nodes: [], supported: false };
|
|
2587
|
+
}
|
|
2588
|
+
nodes.push({
|
|
2589
|
+
type: "text",
|
|
2590
|
+
text: child.children.filter((entry) => entry.type === "text").map((entry) => entry.text).join(""),
|
|
2591
|
+
...marks.length > 0 ? { marks } : {}
|
|
2592
|
+
});
|
|
2593
|
+
break;
|
|
2594
|
+
case "tab":
|
|
2595
|
+
nodes.push({ type: "tab" });
|
|
2596
|
+
break;
|
|
2597
|
+
case "sym": {
|
|
2598
|
+
const symbol = parseSymbolNode(child, marks);
|
|
2599
|
+
if (!symbol) {
|
|
2600
|
+
return { nodes: [], supported: false };
|
|
2601
|
+
}
|
|
2602
|
+
nodes.push(symbol);
|
|
2603
|
+
break;
|
|
2604
|
+
}
|
|
2605
|
+
case "br":
|
|
2606
|
+
if (isColumnBreak(child)) {
|
|
2607
|
+
nodes.push({ type: "column_break" });
|
|
2608
|
+
break;
|
|
2609
|
+
}
|
|
2610
|
+
if (!isSimpleLineBreak(child)) {
|
|
2611
|
+
return { nodes: [], supported: false };
|
|
2612
|
+
}
|
|
2613
|
+
nodes.push({ type: "hard_break" });
|
|
2614
|
+
break;
|
|
2615
|
+
case "commentReference":
|
|
2616
|
+
case "lastRenderedPageBreak":
|
|
2617
|
+
case "proofErr":
|
|
2618
|
+
if (options.preserveUnsupportedReviewMarkup) {
|
|
2619
|
+
return { nodes: [], supported: false };
|
|
2620
|
+
}
|
|
2621
|
+
break;
|
|
2622
|
+
default:
|
|
2623
|
+
return { nodes: [], supported: false };
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2626
|
+
return { nodes, supported: true };
|
|
2627
|
+
}
|
|
2628
|
+
function readRunMarks(node, sourceXml) {
|
|
2629
|
+
const properties = node.children.find(
|
|
2630
|
+
(child) => child.type === "element" && localName5(child.name) === "rPr"
|
|
2631
|
+
);
|
|
2632
|
+
if (!properties) {
|
|
2633
|
+
return { marks: [], supported: true };
|
|
2634
|
+
}
|
|
2635
|
+
if (properties.children.some(
|
|
2636
|
+
(child) => child.type === "element" && DISALLOWED_RUN_PROPERTY_NAMES.has(localName5(child.name))
|
|
2637
|
+
)) {
|
|
2638
|
+
return {
|
|
2639
|
+
marks: [],
|
|
2640
|
+
supported: false
|
|
2641
|
+
};
|
|
2642
|
+
}
|
|
2643
|
+
const marks = [];
|
|
2644
|
+
if (hasOnOffProperty(properties, "b")) {
|
|
2645
|
+
marks.push({ type: "bold" });
|
|
2646
|
+
}
|
|
2647
|
+
if (hasOnOffProperty(properties, "i")) {
|
|
2648
|
+
marks.push({ type: "italic" });
|
|
2649
|
+
}
|
|
2650
|
+
if (hasUnderlineProperty(properties)) {
|
|
2651
|
+
marks.push({ type: "underline" });
|
|
2652
|
+
}
|
|
2653
|
+
if (hasOnOffProperty(properties, "strike")) {
|
|
2654
|
+
marks.push({ type: "strikethrough" });
|
|
2655
|
+
}
|
|
2656
|
+
if (hasOnOffProperty(properties, "dstrike")) {
|
|
2657
|
+
marks.push({ type: "doubleStrikethrough" });
|
|
2658
|
+
}
|
|
2659
|
+
if (hasOnOffProperty(properties, "vanish")) {
|
|
2660
|
+
marks.push({ type: "vanish" });
|
|
2661
|
+
}
|
|
2662
|
+
const langMark = readRunLang(properties);
|
|
2663
|
+
if (langMark) {
|
|
2664
|
+
marks.push(langMark);
|
|
2665
|
+
}
|
|
2666
|
+
const backgroundColorMark = readRunBackgroundColor(properties);
|
|
2667
|
+
if (backgroundColorMark) {
|
|
2668
|
+
marks.push(backgroundColorMark);
|
|
2669
|
+
}
|
|
2670
|
+
const highlightMark = readRunHighlight(properties);
|
|
2671
|
+
if (highlightMark) {
|
|
2672
|
+
marks.push(highlightMark);
|
|
2673
|
+
}
|
|
2674
|
+
const charSpacingMark = readNumericRunMark(properties, "spacing", "charSpacing");
|
|
2675
|
+
if (charSpacingMark) {
|
|
2676
|
+
marks.push(charSpacingMark);
|
|
2677
|
+
}
|
|
2678
|
+
const kerningMark = readNumericRunMark(properties, "kern", "kerning");
|
|
2679
|
+
if (kerningMark) {
|
|
2680
|
+
marks.push(kerningMark);
|
|
2681
|
+
}
|
|
2682
|
+
const positionMark = readNumericRunMark(properties, "position", "position");
|
|
2683
|
+
if (positionMark) {
|
|
2684
|
+
marks.push(positionMark);
|
|
2685
|
+
}
|
|
2686
|
+
if (hasOnOffProperty(properties, "emboss")) {
|
|
2687
|
+
marks.push({ type: "emboss" });
|
|
2688
|
+
}
|
|
2689
|
+
if (hasOnOffProperty(properties, "imprint")) {
|
|
2690
|
+
marks.push({ type: "imprint" });
|
|
2691
|
+
}
|
|
2692
|
+
if (hasOnOffProperty(properties, "shadow")) {
|
|
2693
|
+
marks.push({ type: "shadow" });
|
|
2694
|
+
}
|
|
2695
|
+
const textFillMark = readRunTextFill(properties, sourceXml);
|
|
2696
|
+
if (textFillMark) {
|
|
2697
|
+
marks.push(textFillMark);
|
|
2698
|
+
}
|
|
2699
|
+
const rFontsNode = properties.children.find(
|
|
2700
|
+
(child) => child.type === "element" && localName5(child.name) === "rFonts"
|
|
2701
|
+
);
|
|
2702
|
+
if (rFontsNode) {
|
|
2703
|
+
const family = rFontsNode.attributes["w:ascii"] ?? rFontsNode.attributes["w:hAnsi"] ?? rFontsNode.attributes.ascii ?? rFontsNode.attributes.hAnsi;
|
|
2704
|
+
if (family) {
|
|
2705
|
+
marks.push({ type: "fontFamily", val: family });
|
|
2706
|
+
}
|
|
2707
|
+
}
|
|
2708
|
+
const szNode = properties.children.find(
|
|
2709
|
+
(child) => child.type === "element" && localName5(child.name) === "sz"
|
|
2710
|
+
);
|
|
2711
|
+
if (szNode) {
|
|
2712
|
+
const szVal = szNode.attributes["w:val"] ?? szNode.attributes.val;
|
|
2713
|
+
if (szVal) {
|
|
2714
|
+
const size = Number.parseInt(szVal, 10);
|
|
2715
|
+
if (Number.isFinite(size) && size > 0) {
|
|
2716
|
+
marks.push({ type: "fontSize", val: size });
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
const colorNode = properties.children.find(
|
|
2721
|
+
(child) => child.type === "element" && localName5(child.name) === "color"
|
|
2722
|
+
);
|
|
2723
|
+
if (colorNode) {
|
|
2724
|
+
const colorVal = colorNode.attributes["w:val"] ?? colorNode.attributes.val;
|
|
2725
|
+
if (colorVal && colorVal !== "auto") {
|
|
2726
|
+
marks.push({ type: "textColor", color: colorVal });
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
if (hasOnOffProperty(properties, "smallCaps")) {
|
|
2730
|
+
marks.push({ type: "smallCaps" });
|
|
2731
|
+
}
|
|
2732
|
+
if (hasOnOffProperty(properties, "caps")) {
|
|
2733
|
+
marks.push({ type: "allCaps" });
|
|
2734
|
+
}
|
|
2735
|
+
return {
|
|
2736
|
+
marks,
|
|
2737
|
+
supported: true
|
|
2738
|
+
};
|
|
2739
|
+
}
|
|
2740
|
+
function readRunLang(properties) {
|
|
2741
|
+
const langNode = properties.children.find(
|
|
2742
|
+
(child) => child.type === "element" && localName5(child.name) === "lang"
|
|
2743
|
+
);
|
|
2744
|
+
if (!langNode) return void 0;
|
|
2745
|
+
const val = langNode.attributes["w:val"] ?? langNode.attributes.val ?? langNode.attributes["w:bidi"] ?? langNode.attributes.bidi;
|
|
2746
|
+
if (!val) return void 0;
|
|
2747
|
+
return { type: "lang", val };
|
|
2748
|
+
}
|
|
2749
|
+
function readRunBackgroundColor(properties) {
|
|
2750
|
+
const shadingNode = properties.children.find(
|
|
2751
|
+
(child) => child.type === "element" && localName5(child.name) === "shd"
|
|
2752
|
+
);
|
|
2753
|
+
if (!shadingNode) {
|
|
2754
|
+
return void 0;
|
|
2755
|
+
}
|
|
2756
|
+
const fill = shadingNode.attributes["w:fill"] ?? shadingNode.attributes.fill;
|
|
2757
|
+
if (!fill || fill === "auto") {
|
|
2758
|
+
return void 0;
|
|
2759
|
+
}
|
|
2760
|
+
return { type: "backgroundColor", color: fill };
|
|
2761
|
+
}
|
|
2762
|
+
function readRunHighlight(properties) {
|
|
2763
|
+
const highlightNode = properties.children.find(
|
|
2764
|
+
(child) => child.type === "element" && localName5(child.name) === "highlight"
|
|
2765
|
+
);
|
|
2766
|
+
if (!highlightNode) {
|
|
2767
|
+
return void 0;
|
|
2768
|
+
}
|
|
2769
|
+
const highlightValue = highlightNode.attributes["w:val"] ?? highlightNode.attributes.val;
|
|
2770
|
+
const resolvedHighlight = resolveHighlightColor(highlightValue);
|
|
2771
|
+
if (!resolvedHighlight) {
|
|
2772
|
+
return void 0;
|
|
2773
|
+
}
|
|
2774
|
+
return {
|
|
2775
|
+
type: "highlight",
|
|
2776
|
+
color: resolvedHighlight.color,
|
|
2777
|
+
val: resolvedHighlight.val
|
|
2778
|
+
};
|
|
2779
|
+
}
|
|
2780
|
+
function readNumericRunMark(properties, elementName, markType) {
|
|
2781
|
+
const propertyNode = properties.children.find(
|
|
2782
|
+
(child) => child.type === "element" && localName5(child.name) === elementName
|
|
2783
|
+
);
|
|
2784
|
+
if (!propertyNode) {
|
|
2785
|
+
return void 0;
|
|
2786
|
+
}
|
|
2787
|
+
const rawValue = propertyNode.attributes["w:val"] ?? propertyNode.attributes.val;
|
|
2788
|
+
if (rawValue === void 0) {
|
|
2789
|
+
return void 0;
|
|
2790
|
+
}
|
|
2791
|
+
const value = Number.parseInt(rawValue, 10);
|
|
2792
|
+
if (!Number.isFinite(value)) {
|
|
2793
|
+
return void 0;
|
|
2794
|
+
}
|
|
2795
|
+
return { type: markType, val: value };
|
|
2796
|
+
}
|
|
2797
|
+
function readRunTextFill(properties, sourceXml) {
|
|
2798
|
+
const textFillNode = properties.children.find(
|
|
2799
|
+
(child) => child.type === "element" && localName5(child.name) === "textFill"
|
|
2800
|
+
);
|
|
2801
|
+
if (!textFillNode) {
|
|
2802
|
+
return void 0;
|
|
2803
|
+
}
|
|
2804
|
+
return {
|
|
2805
|
+
type: "textFill",
|
|
2806
|
+
xml: sourceXml.slice(textFillNode.start, textFillNode.end)
|
|
2807
|
+
};
|
|
2808
|
+
}
|
|
2809
|
+
function parseSymbolNode(node, marks) {
|
|
2810
|
+
const char = node.attributes["w:char"] ?? node.attributes.char;
|
|
2811
|
+
if (!char) {
|
|
2812
|
+
return void 0;
|
|
2813
|
+
}
|
|
2814
|
+
const font = node.attributes["w:font"] ?? node.attributes.font;
|
|
2815
|
+
return {
|
|
2816
|
+
type: "symbol",
|
|
2817
|
+
char,
|
|
2818
|
+
...font ? { font } : {},
|
|
2819
|
+
...marks.length > 0 ? { marks } : {}
|
|
2820
|
+
};
|
|
2821
|
+
}
|
|
2822
|
+
function supportsParagraphProperties(node) {
|
|
2823
|
+
for (const child of node.children) {
|
|
2824
|
+
if (child.type !== "element") {
|
|
2825
|
+
continue;
|
|
2826
|
+
}
|
|
2827
|
+
const name = localName5(child.name);
|
|
2828
|
+
if (name === "pPrChange") {
|
|
2829
|
+
return false;
|
|
2830
|
+
}
|
|
2831
|
+
if (name === "rPr") {
|
|
2832
|
+
if (child.children.some(
|
|
2833
|
+
(entry) => entry.type === "element" && DISALLOWED_PARAGRAPH_PROPERTY_NAMES.has(localName5(entry.name))
|
|
2834
|
+
)) {
|
|
2835
|
+
return false;
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
}
|
|
2839
|
+
return true;
|
|
2840
|
+
}
|
|
2841
|
+
var DISALLOWED_RUN_PROPERTY_NAMES = /* @__PURE__ */ new Set(["rPrChange"]);
|
|
2842
|
+
var DISALLOWED_PARAGRAPH_PROPERTY_NAMES = /* @__PURE__ */ new Set(["pPrChange", "rPrChange"]);
|
|
2843
|
+
function hasOnOffProperty(properties, propertyName) {
|
|
2844
|
+
const property = properties.children.find(
|
|
2845
|
+
(child) => child.type === "element" && localName5(child.name) === propertyName
|
|
2846
|
+
);
|
|
2847
|
+
if (!property) {
|
|
2848
|
+
return false;
|
|
2849
|
+
}
|
|
2850
|
+
const value = (property.attributes["w:val"] ?? property.attributes.val ?? "true").toLowerCase();
|
|
2851
|
+
return value !== "false" && value !== "0" && value !== "off";
|
|
2852
|
+
}
|
|
2853
|
+
function hasUnderlineProperty(properties) {
|
|
2854
|
+
const property = properties.children.find(
|
|
2855
|
+
(child) => child.type === "element" && localName5(child.name) === "u"
|
|
2856
|
+
);
|
|
2857
|
+
if (!property) {
|
|
2858
|
+
return false;
|
|
2859
|
+
}
|
|
2860
|
+
const value = (property.attributes["w:val"] ?? property.attributes.val ?? "single").toLowerCase();
|
|
2861
|
+
return value !== "none";
|
|
2862
|
+
}
|
|
2863
|
+
function isSimpleLineBreak(node) {
|
|
2864
|
+
const value = (node.attributes["w:type"] ?? node.attributes.type ?? "textWrapping").toLowerCase();
|
|
2865
|
+
return value === "textwrapping" || value === "line";
|
|
2866
|
+
}
|
|
2867
|
+
function isColumnBreak(node) {
|
|
2868
|
+
const value = (node.attributes["w:type"] ?? node.attributes.type ?? "").toLowerCase();
|
|
2869
|
+
return value === "column";
|
|
2870
|
+
}
|
|
2871
|
+
function findChildElement(node, childLocalName) {
|
|
2872
|
+
const child = node.children.find(
|
|
2873
|
+
(entry) => entry.type === "element" && localName5(entry.name) === childLocalName
|
|
2874
|
+
);
|
|
2875
|
+
if (!child) {
|
|
2876
|
+
throw new Error(`Expected <${childLocalName}> element in main document XML.`);
|
|
2877
|
+
}
|
|
2878
|
+
return child;
|
|
2879
|
+
}
|
|
2880
|
+
function localName5(name) {
|
|
2881
|
+
const separatorIndex = name.indexOf(":");
|
|
2882
|
+
return separatorIndex >= 0 ? name.slice(separatorIndex + 1) : name;
|
|
2883
|
+
}
|
|
2884
|
+
function readOptionalAttribute2(node, name) {
|
|
2885
|
+
return node.attributes[`w:${name}`] ?? node.attributes[`r:${name}`] ?? node.attributes[name];
|
|
2886
|
+
}
|
|
2887
|
+
function parseXml5(xml) {
|
|
2888
|
+
const root = {
|
|
2889
|
+
type: "element",
|
|
2890
|
+
name: "__root__",
|
|
2891
|
+
attributes: {},
|
|
2892
|
+
children: [],
|
|
2893
|
+
start: 0,
|
|
2894
|
+
end: xml.length
|
|
2895
|
+
};
|
|
2896
|
+
const stack = [root];
|
|
2897
|
+
let cursor = 0;
|
|
2898
|
+
while (cursor < xml.length) {
|
|
2899
|
+
if (xml.startsWith("<!--", cursor)) {
|
|
2900
|
+
const end = xml.indexOf("-->", cursor);
|
|
2901
|
+
cursor = end >= 0 ? end + 3 : xml.length;
|
|
2902
|
+
continue;
|
|
2903
|
+
}
|
|
2904
|
+
if (xml.startsWith("<?", cursor)) {
|
|
2905
|
+
const end = xml.indexOf("?>", cursor);
|
|
2906
|
+
cursor = end >= 0 ? end + 2 : xml.length;
|
|
2907
|
+
continue;
|
|
2908
|
+
}
|
|
2909
|
+
if (xml.startsWith("<![CDATA[", cursor)) {
|
|
2910
|
+
const end = xml.indexOf("]]>", cursor);
|
|
2911
|
+
const textEnd = end >= 0 ? end : xml.length;
|
|
2912
|
+
stack[stack.length - 1]?.children.push({
|
|
2913
|
+
type: "text",
|
|
2914
|
+
text: xml.slice(cursor + 9, textEnd),
|
|
2915
|
+
start: cursor,
|
|
2916
|
+
end: end >= 0 ? end + 3 : xml.length
|
|
2917
|
+
});
|
|
2918
|
+
cursor = end >= 0 ? end + 3 : xml.length;
|
|
2919
|
+
continue;
|
|
2920
|
+
}
|
|
2921
|
+
const currentChar = xml[cursor];
|
|
2922
|
+
if (currentChar !== "<") {
|
|
2923
|
+
const nextTag = xml.indexOf("<", cursor);
|
|
2924
|
+
const end = nextTag >= 0 ? nextTag : xml.length;
|
|
2925
|
+
const text = decodeXmlEntities3(xml.slice(cursor, end));
|
|
2926
|
+
if (text.length > 0) {
|
|
2927
|
+
stack[stack.length - 1]?.children.push({
|
|
2928
|
+
type: "text",
|
|
2929
|
+
text,
|
|
2930
|
+
start: cursor,
|
|
2931
|
+
end
|
|
2932
|
+
});
|
|
2933
|
+
}
|
|
2934
|
+
cursor = end;
|
|
2935
|
+
continue;
|
|
2936
|
+
}
|
|
2937
|
+
if (xml[cursor + 1] === "/") {
|
|
2938
|
+
const end = xml.indexOf(">", cursor);
|
|
2939
|
+
if (end < 0) {
|
|
2940
|
+
throw new Error("Malformed XML: missing closing >.");
|
|
2941
|
+
}
|
|
2942
|
+
const name2 = xml.slice(cursor + 2, end).trim();
|
|
2943
|
+
const current = stack.pop();
|
|
2944
|
+
if (!current || localName5(current.name) !== localName5(name2)) {
|
|
2945
|
+
throw new Error(`Malformed XML: unexpected closing tag </${name2}>.`);
|
|
2946
|
+
}
|
|
2947
|
+
current.end = end + 1;
|
|
2948
|
+
cursor = end + 1;
|
|
2949
|
+
continue;
|
|
2950
|
+
}
|
|
2951
|
+
const tagEnd = findTagEnd5(xml, cursor);
|
|
2952
|
+
const tagBody = xml.slice(cursor + 1, tagEnd);
|
|
2953
|
+
const selfClosing = /\/\s*$/.test(tagBody);
|
|
2954
|
+
const { name, attributes } = parseTag5(tagBody.replace(/\/\s*$/, "").trim());
|
|
2955
|
+
const element = {
|
|
2956
|
+
type: "element",
|
|
2957
|
+
name,
|
|
2958
|
+
attributes,
|
|
2959
|
+
children: [],
|
|
2960
|
+
start: cursor,
|
|
2961
|
+
end: tagEnd + 1
|
|
2962
|
+
};
|
|
2963
|
+
stack[stack.length - 1]?.children.push(element);
|
|
2964
|
+
if (!selfClosing) {
|
|
2965
|
+
stack.push(element);
|
|
2966
|
+
}
|
|
2967
|
+
cursor = tagEnd + 1;
|
|
2968
|
+
}
|
|
2969
|
+
if (stack.length !== 1) {
|
|
2970
|
+
throw new Error("Malformed XML: unclosed element in main document XML.");
|
|
2971
|
+
}
|
|
2972
|
+
return root;
|
|
2973
|
+
}
|
|
2974
|
+
function parseTag5(tagBody) {
|
|
2975
|
+
let cursor = 0;
|
|
2976
|
+
while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
|
|
2977
|
+
cursor += 1;
|
|
2978
|
+
}
|
|
2979
|
+
const nameStart = cursor;
|
|
2980
|
+
while (cursor < tagBody.length && !/\s/.test(tagBody[cursor] ?? "")) {
|
|
2981
|
+
cursor += 1;
|
|
2982
|
+
}
|
|
2983
|
+
const name = tagBody.slice(nameStart, cursor);
|
|
2984
|
+
const attributes = {};
|
|
2985
|
+
while (cursor < tagBody.length) {
|
|
2986
|
+
while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
|
|
2987
|
+
cursor += 1;
|
|
2988
|
+
}
|
|
2989
|
+
if (cursor >= tagBody.length) {
|
|
2990
|
+
break;
|
|
2991
|
+
}
|
|
2992
|
+
const keyStart = cursor;
|
|
2993
|
+
while (cursor < tagBody.length && !/[\s=]/.test(tagBody[cursor] ?? "")) {
|
|
2994
|
+
cursor += 1;
|
|
2995
|
+
}
|
|
2996
|
+
const key = tagBody.slice(keyStart, cursor);
|
|
2997
|
+
while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
|
|
2998
|
+
cursor += 1;
|
|
2999
|
+
}
|
|
3000
|
+
if (tagBody[cursor] !== "=") {
|
|
3001
|
+
attributes[key] = "";
|
|
3002
|
+
continue;
|
|
3003
|
+
}
|
|
3004
|
+
cursor += 1;
|
|
3005
|
+
while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
|
|
3006
|
+
cursor += 1;
|
|
3007
|
+
}
|
|
3008
|
+
const quote = tagBody[cursor];
|
|
3009
|
+
if (quote !== `"` && quote !== `'`) {
|
|
3010
|
+
throw new Error(`Malformed XML attribute ${key}.`);
|
|
3011
|
+
}
|
|
3012
|
+
cursor += 1;
|
|
3013
|
+
const valueStart = cursor;
|
|
3014
|
+
while (cursor < tagBody.length && tagBody[cursor] !== quote) {
|
|
3015
|
+
cursor += 1;
|
|
3016
|
+
}
|
|
3017
|
+
const rawValue = tagBody.slice(valueStart, cursor);
|
|
3018
|
+
attributes[key] = decodeXmlEntities3(rawValue);
|
|
3019
|
+
cursor += 1;
|
|
3020
|
+
}
|
|
3021
|
+
return { name, attributes };
|
|
3022
|
+
}
|
|
3023
|
+
function findTagEnd5(xml, start) {
|
|
3024
|
+
let cursor = start + 1;
|
|
3025
|
+
let quote = null;
|
|
3026
|
+
while (cursor < xml.length) {
|
|
3027
|
+
const current = xml[cursor];
|
|
3028
|
+
if (quote) {
|
|
3029
|
+
if (current === quote) {
|
|
3030
|
+
quote = null;
|
|
3031
|
+
}
|
|
3032
|
+
cursor += 1;
|
|
3033
|
+
continue;
|
|
3034
|
+
}
|
|
3035
|
+
if (current === `"` || current === `'`) {
|
|
3036
|
+
quote = current;
|
|
3037
|
+
cursor += 1;
|
|
3038
|
+
continue;
|
|
3039
|
+
}
|
|
3040
|
+
if (current === ">") {
|
|
3041
|
+
return cursor;
|
|
3042
|
+
}
|
|
3043
|
+
cursor += 1;
|
|
3044
|
+
}
|
|
3045
|
+
throw new Error("Malformed XML: missing >.");
|
|
3046
|
+
}
|
|
3047
|
+
function decodeXmlEntities3(value) {
|
|
3048
|
+
return value.replace(/&(#x[0-9a-fA-F]+|#\d+|amp|lt|gt|quot|apos);/g, (match, entity) => {
|
|
3049
|
+
switch (entity) {
|
|
3050
|
+
case "amp":
|
|
3051
|
+
return "&";
|
|
3052
|
+
case "lt":
|
|
3053
|
+
return "<";
|
|
3054
|
+
case "gt":
|
|
3055
|
+
return ">";
|
|
3056
|
+
case "quot":
|
|
3057
|
+
return `"`;
|
|
3058
|
+
case "apos":
|
|
3059
|
+
return "'";
|
|
3060
|
+
default:
|
|
3061
|
+
if (entity.startsWith("#x")) {
|
|
3062
|
+
return String.fromCodePoint(Number.parseInt(entity.slice(2), 16));
|
|
3063
|
+
}
|
|
3064
|
+
if (entity.startsWith("#")) {
|
|
3065
|
+
return String.fromCodePoint(Number.parseInt(entity.slice(1), 10));
|
|
3066
|
+
}
|
|
3067
|
+
return match;
|
|
3068
|
+
}
|
|
3069
|
+
});
|
|
3070
|
+
}
|
|
3071
|
+
function parseSectionBreakElement(node, sourceXml) {
|
|
3072
|
+
const props = parseSectionPropertiesFromElement(node);
|
|
3073
|
+
return {
|
|
3074
|
+
type: "section_break",
|
|
3075
|
+
sectionPropertiesXml: sourceXml.slice(node.start, node.end),
|
|
3076
|
+
sectionProperties: props
|
|
3077
|
+
};
|
|
3078
|
+
}
|
|
3079
|
+
function readSectionPropertiesFromPPr(pPrNode) {
|
|
3080
|
+
for (const child of pPrNode.children) {
|
|
3081
|
+
if (child.type === "element" && localName5(child.name) === "sectPr") {
|
|
3082
|
+
return parseSectionPropertiesFromElement(child);
|
|
3083
|
+
}
|
|
3084
|
+
}
|
|
3085
|
+
return void 0;
|
|
3086
|
+
}
|
|
3087
|
+
function readSectionPropertiesXmlFromPPr(pPrNode, sourceXml) {
|
|
3088
|
+
for (const child of pPrNode.children) {
|
|
3089
|
+
if (child.type === "element" && localName5(child.name) === "sectPr") {
|
|
3090
|
+
return sourceXml.slice(child.start, child.end);
|
|
3091
|
+
}
|
|
3092
|
+
}
|
|
3093
|
+
return void 0;
|
|
3094
|
+
}
|
|
3095
|
+
function parseSectionPropertiesFromElement(node) {
|
|
3096
|
+
const props = {};
|
|
3097
|
+
for (const child of node.children) {
|
|
3098
|
+
if (child.type !== "element") continue;
|
|
3099
|
+
const name = localName5(child.name);
|
|
3100
|
+
switch (name) {
|
|
3101
|
+
case "pgSz": {
|
|
3102
|
+
const w = safeParseInt(child.attributes["w:w"]);
|
|
3103
|
+
const h = safeParseInt(child.attributes["w:h"]);
|
|
3104
|
+
if (w !== void 0 && h !== void 0) {
|
|
3105
|
+
const pageSize = { width: w, height: h };
|
|
3106
|
+
const orient = child.attributes["w:orient"];
|
|
3107
|
+
if (orient === "landscape" || orient === "portrait") {
|
|
3108
|
+
pageSize.orientation = orient;
|
|
3109
|
+
}
|
|
3110
|
+
props.pageSize = pageSize;
|
|
3111
|
+
}
|
|
3112
|
+
break;
|
|
3113
|
+
}
|
|
3114
|
+
case "pgMar": {
|
|
3115
|
+
const top = safeParseInt(child.attributes["w:top"]);
|
|
3116
|
+
const right = safeParseInt(child.attributes["w:right"]);
|
|
3117
|
+
const bottom = safeParseInt(child.attributes["w:bottom"]);
|
|
3118
|
+
const left = safeParseInt(child.attributes["w:left"]);
|
|
3119
|
+
if (top !== void 0 && right !== void 0 && bottom !== void 0 && left !== void 0) {
|
|
3120
|
+
const margins = { top, right, bottom, left };
|
|
3121
|
+
const header = safeParseInt(child.attributes["w:header"]);
|
|
3122
|
+
const footer = safeParseInt(child.attributes["w:footer"]);
|
|
3123
|
+
const gutter = safeParseInt(child.attributes["w:gutter"]);
|
|
3124
|
+
if (header !== void 0) margins.header = header;
|
|
3125
|
+
if (footer !== void 0) margins.footer = footer;
|
|
3126
|
+
if (gutter !== void 0) margins.gutter = gutter;
|
|
3127
|
+
props.pageMargins = margins;
|
|
3128
|
+
}
|
|
3129
|
+
break;
|
|
3130
|
+
}
|
|
3131
|
+
case "cols": {
|
|
3132
|
+
const columns = {};
|
|
3133
|
+
const num = safeParseInt(child.attributes["w:num"]);
|
|
3134
|
+
const space = safeParseInt(child.attributes["w:space"]);
|
|
3135
|
+
const equalWidth = child.attributes["w:equalWidth"];
|
|
3136
|
+
const sep = child.attributes["w:sep"];
|
|
3137
|
+
if (num !== void 0) columns.count = num;
|
|
3138
|
+
if (space !== void 0) columns.space = space;
|
|
3139
|
+
if (equalWidth !== void 0) columns.equalWidth = equalWidth !== "0" && equalWidth !== "false";
|
|
3140
|
+
if (sep === "1" || sep === "true") columns.separator = true;
|
|
3141
|
+
const colDefs = [];
|
|
3142
|
+
for (const colChild of child.children) {
|
|
3143
|
+
if (colChild.type === "element" && localName5(colChild.name) === "col") {
|
|
3144
|
+
const colW = safeParseInt(colChild.attributes["w:w"]);
|
|
3145
|
+
const colSpace = safeParseInt(colChild.attributes["w:space"]);
|
|
3146
|
+
if (colW !== void 0) {
|
|
3147
|
+
colDefs.push(colSpace !== void 0 ? { width: colW, space: colSpace } : { width: colW });
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
if (colDefs.length > 0) columns.columns = colDefs;
|
|
3152
|
+
if (Object.keys(columns).length > 0) props.columns = columns;
|
|
3153
|
+
break;
|
|
3154
|
+
}
|
|
3155
|
+
case "pgNumType": {
|
|
3156
|
+
const numbering = {};
|
|
3157
|
+
const fmt = child.attributes["w:fmt"];
|
|
3158
|
+
const start = safeParseInt(child.attributes["w:start"]);
|
|
3159
|
+
const chapStyle = child.attributes["w:chapStyle"];
|
|
3160
|
+
const chapSep = child.attributes["w:chapSep"];
|
|
3161
|
+
if (fmt) numbering.format = fmt;
|
|
3162
|
+
if (start !== void 0) numbering.start = start;
|
|
3163
|
+
if (chapStyle) numbering.chapStyle = chapStyle;
|
|
3164
|
+
if (chapSep) numbering.chapSep = chapSep;
|
|
3165
|
+
if (Object.keys(numbering).length > 0) props.pageNumbering = numbering;
|
|
3166
|
+
break;
|
|
3167
|
+
}
|
|
3168
|
+
case "lnNumType": {
|
|
3169
|
+
const lineNumbering = {};
|
|
3170
|
+
const countBy = safeParseInt(child.attributes["w:countBy"]);
|
|
3171
|
+
const start = safeParseInt(child.attributes["w:start"]);
|
|
3172
|
+
const distance = safeParseInt(child.attributes["w:distance"]);
|
|
3173
|
+
const restart = child.attributes["w:restart"];
|
|
3174
|
+
if (countBy !== void 0) lineNumbering.countBy = countBy;
|
|
3175
|
+
if (start !== void 0) lineNumbering.start = start;
|
|
3176
|
+
if (distance !== void 0) lineNumbering.distance = distance;
|
|
3177
|
+
if (restart === "newPage" || restart === "newSection" || restart === "continuous") {
|
|
3178
|
+
lineNumbering.restart = restart;
|
|
3179
|
+
}
|
|
3180
|
+
if (Object.keys(lineNumbering).length > 0) {
|
|
3181
|
+
props.lineNumbering = lineNumbering;
|
|
3182
|
+
}
|
|
3183
|
+
break;
|
|
3184
|
+
}
|
|
3185
|
+
case "pgBorders": {
|
|
3186
|
+
const pageBorders = {};
|
|
3187
|
+
const offsetFrom = child.attributes["w:offsetFrom"];
|
|
3188
|
+
const display = child.attributes["w:display"];
|
|
3189
|
+
const zOrder = child.attributes["w:zOrder"];
|
|
3190
|
+
if (offsetFrom === "page" || offsetFrom === "text") {
|
|
3191
|
+
pageBorders.offsetFrom = offsetFrom;
|
|
3192
|
+
}
|
|
3193
|
+
if (display === "allPages" || display === "firstPage" || display === "notFirstPage") {
|
|
3194
|
+
pageBorders.display = display;
|
|
3195
|
+
}
|
|
3196
|
+
if (zOrder === "front" || zOrder === "back") {
|
|
3197
|
+
pageBorders.zOrder = zOrder;
|
|
3198
|
+
}
|
|
3199
|
+
for (const borderChild of child.children) {
|
|
3200
|
+
if (borderChild.type !== "element") continue;
|
|
3201
|
+
const borderName = localName5(borderChild.name);
|
|
3202
|
+
const border = parseBorderSpec(borderChild);
|
|
3203
|
+
if (!border) continue;
|
|
3204
|
+
if (borderName === "top" || borderName === "left" || borderName === "bottom" || borderName === "right") {
|
|
3205
|
+
pageBorders[borderName] = border;
|
|
3206
|
+
}
|
|
3207
|
+
}
|
|
3208
|
+
if (Object.keys(pageBorders).length > 0) {
|
|
3209
|
+
props.pageBorders = pageBorders;
|
|
3210
|
+
}
|
|
3211
|
+
break;
|
|
3212
|
+
}
|
|
3213
|
+
case "docGrid": {
|
|
3214
|
+
const documentGrid = {};
|
|
3215
|
+
const type = child.attributes["w:type"];
|
|
3216
|
+
const linePitch = safeParseInt(child.attributes["w:linePitch"]);
|
|
3217
|
+
const charSpace = safeParseInt(child.attributes["w:charSpace"]);
|
|
3218
|
+
if (type === "default" || type === "lines" || type === "linesAndChars" || type === "snapToChars") {
|
|
3219
|
+
documentGrid.type = type;
|
|
3220
|
+
}
|
|
3221
|
+
if (linePitch !== void 0) documentGrid.linePitch = linePitch;
|
|
3222
|
+
if (charSpace !== void 0) documentGrid.charSpace = charSpace;
|
|
3223
|
+
if (Object.keys(documentGrid).length > 0) {
|
|
3224
|
+
props.documentGrid = documentGrid;
|
|
3225
|
+
}
|
|
3226
|
+
break;
|
|
3227
|
+
}
|
|
3228
|
+
case "headerReference": {
|
|
3229
|
+
const variant = child.attributes["w:type"];
|
|
3230
|
+
const rId = child.attributes["r:id"];
|
|
3231
|
+
if (variant && rId) {
|
|
3232
|
+
if (!props.headerReferences) props.headerReferences = [];
|
|
3233
|
+
props.headerReferences.push({ variant, relationshipId: rId });
|
|
3234
|
+
}
|
|
3235
|
+
break;
|
|
3236
|
+
}
|
|
3237
|
+
case "footerReference": {
|
|
3238
|
+
const variant = child.attributes["w:type"];
|
|
3239
|
+
const rId = child.attributes["r:id"];
|
|
3240
|
+
if (variant && rId) {
|
|
3241
|
+
if (!props.footerReferences) props.footerReferences = [];
|
|
3242
|
+
props.footerReferences.push({ variant, relationshipId: rId });
|
|
3243
|
+
}
|
|
3244
|
+
break;
|
|
3245
|
+
}
|
|
3246
|
+
case "type": {
|
|
3247
|
+
const val = child.attributes["w:val"];
|
|
3248
|
+
if (val === "continuous" || val === "nextPage" || val === "evenPage" || val === "oddPage" || val === "nextColumn") {
|
|
3249
|
+
props.sectionType = val;
|
|
3250
|
+
}
|
|
3251
|
+
break;
|
|
3252
|
+
}
|
|
3253
|
+
case "titlePg": {
|
|
3254
|
+
const val = child.attributes["w:val"];
|
|
3255
|
+
props.titlePage = val !== "false" && val !== "0";
|
|
3256
|
+
break;
|
|
3257
|
+
}
|
|
3258
|
+
}
|
|
3259
|
+
}
|
|
3260
|
+
return props;
|
|
3261
|
+
}
|
|
3262
|
+
function safeParseInt(value) {
|
|
3263
|
+
if (value === void 0) return void 0;
|
|
3264
|
+
const n = Number.parseInt(value, 10);
|
|
3265
|
+
return Number.isFinite(n) ? n : void 0;
|
|
3266
|
+
}
|
|
3267
|
+
function parseBorderSpec(node) {
|
|
3268
|
+
const border = {};
|
|
3269
|
+
const value = node.attributes["w:val"];
|
|
3270
|
+
const size = safeParseInt(node.attributes["w:sz"]);
|
|
3271
|
+
const space = safeParseInt(node.attributes["w:space"]);
|
|
3272
|
+
const color = node.attributes["w:color"];
|
|
3273
|
+
if (value) border.value = value;
|
|
3274
|
+
if (size !== void 0) border.size = size;
|
|
3275
|
+
if (space !== void 0) border.space = space;
|
|
3276
|
+
if (color) border.color = color;
|
|
3277
|
+
return Object.keys(border).length > 0 ? border : void 0;
|
|
3278
|
+
}
|
|
3279
|
+
function parsePermStartNode(node, sourceXml) {
|
|
3280
|
+
const rangeId = node.attributes["w:id"] ?? node.attributes.id ?? "";
|
|
3281
|
+
const edGrp = node.attributes["w:edGrp"] ?? node.attributes.edGrp;
|
|
3282
|
+
const ed = node.attributes["w:ed"] ?? node.attributes.ed;
|
|
3283
|
+
return {
|
|
3284
|
+
type: "perm_start",
|
|
3285
|
+
rangeId,
|
|
3286
|
+
...edGrp ? { editorGroup: edGrp } : {},
|
|
3287
|
+
...ed ? { editor: ed } : {},
|
|
3288
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
3289
|
+
};
|
|
3290
|
+
}
|
|
3291
|
+
function parsePermEndNode(node, sourceXml) {
|
|
3292
|
+
return {
|
|
3293
|
+
type: "perm_end",
|
|
3294
|
+
rangeId: node.attributes["w:id"] ?? node.attributes.id ?? "",
|
|
3295
|
+
rawXml: sourceXml.slice(node.start, node.end)
|
|
3296
|
+
};
|
|
3297
|
+
}
|
|
3298
|
+
|
|
3299
|
+
// src/legal/cross-references.ts
|
|
3300
|
+
var CROSS_REFERENCE_PATTERN = /\b(Section|Clause|Article|Schedule|Exhibit|Appendix)\s+(\d+(?:\.\d+)*|[A-Z]-\d+|[A-Z])(?=[^A-Za-z0-9]|$)/g;
|
|
3301
|
+
var W_REF_PATTERN = /<w:ref\b([^>]*)\/?>/g;
|
|
3302
|
+
var ATTRIBUTE_PATTERN = /(?:^|\s)(?:w:)?([A-Za-z][\w-]*)="([^"]*)"/g;
|
|
3303
|
+
var COMPLEX_FIELD_PATTERN = /<w:instrText\b[^>]*>([\s\S]*?)<\/w:instrText>[\s\S]*?<w:fldChar\b[^>]*w:fldCharType="separate"[^>]*\/>[\s\S]*?<w:t\b[^>]*>([\s\S]*?)<\/w:t>[\s\S]*?<w:fldChar\b[^>]*w:fldCharType="end"[^>]*\/>/g;
|
|
3304
|
+
function parseCrossReferencesFromDocumentXml(xml) {
|
|
3305
|
+
const parsed = parseMainDocumentXml(xml);
|
|
3306
|
+
const results = [];
|
|
3307
|
+
parsed.blocks.forEach((block, paragraphIndex) => {
|
|
3308
|
+
if (block.type !== "paragraph") {
|
|
3309
|
+
return;
|
|
3310
|
+
}
|
|
3311
|
+
for (const child of block.children) {
|
|
3312
|
+
if (child.type === "hyperlink" && child.href.startsWith("#")) {
|
|
3313
|
+
results.push({
|
|
3314
|
+
source: "hyperlink",
|
|
3315
|
+
kind: "bookmark",
|
|
3316
|
+
target: child.href.slice(1),
|
|
3317
|
+
label: flattenInlineText(child.children).trim() || child.href.slice(1),
|
|
3318
|
+
paragraphIndex,
|
|
3319
|
+
confidence: "high"
|
|
3320
|
+
});
|
|
3321
|
+
}
|
|
3322
|
+
}
|
|
3323
|
+
const { simpleFields } = parseFieldsFromParagraphXml(block.rawXml);
|
|
3324
|
+
for (const field of simpleFields) {
|
|
3325
|
+
const reference = parseFieldReferenceInstruction(field.instruction);
|
|
3326
|
+
if (!reference) {
|
|
3327
|
+
continue;
|
|
3328
|
+
}
|
|
3329
|
+
results.push({
|
|
3330
|
+
source: "field",
|
|
3331
|
+
kind: "bookmark",
|
|
3332
|
+
target: reference.target,
|
|
3333
|
+
instruction: reference.instruction,
|
|
3334
|
+
label: stripXml(field.contentXml) || reference.target,
|
|
3335
|
+
paragraphIndex,
|
|
3336
|
+
confidence: "high"
|
|
3337
|
+
});
|
|
3338
|
+
}
|
|
3339
|
+
for (const pattern of detectCrossReferencePatterns(flattenParagraphText(block))) {
|
|
3340
|
+
results.push({
|
|
3341
|
+
source: "text-pattern",
|
|
3342
|
+
kind: pattern.kind,
|
|
3343
|
+
target: pattern.targetHint,
|
|
3344
|
+
label: pattern.label,
|
|
3345
|
+
paragraphIndex,
|
|
3346
|
+
confidence: "medium"
|
|
3347
|
+
});
|
|
3348
|
+
}
|
|
3349
|
+
});
|
|
3350
|
+
for (const field of extractComplexFieldsFromBodyXml(xml)) {
|
|
3351
|
+
const reference = parseFieldReferenceInstruction(field.instruction);
|
|
3352
|
+
if (!reference) {
|
|
3353
|
+
continue;
|
|
3354
|
+
}
|
|
3355
|
+
results.push({
|
|
3356
|
+
source: "field",
|
|
3357
|
+
kind: "bookmark",
|
|
3358
|
+
target: reference.target,
|
|
3359
|
+
instruction: reference.instruction,
|
|
3360
|
+
label: stripXml(field.contentXml) || reference.target,
|
|
3361
|
+
confidence: "high"
|
|
3362
|
+
});
|
|
3363
|
+
}
|
|
3364
|
+
for (const field of extractComplexFieldsWithRegex(xml)) {
|
|
3365
|
+
const reference = parseFieldReferenceInstruction(field.instruction);
|
|
3366
|
+
if (!reference) {
|
|
3367
|
+
continue;
|
|
3368
|
+
}
|
|
3369
|
+
results.push({
|
|
3370
|
+
source: "field",
|
|
3371
|
+
kind: "bookmark",
|
|
3372
|
+
target: reference.target,
|
|
3373
|
+
instruction: reference.instruction,
|
|
3374
|
+
label: field.label || reference.target,
|
|
3375
|
+
confidence: "high"
|
|
3376
|
+
});
|
|
3377
|
+
}
|
|
3378
|
+
for (const element of extractWRefElements(xml)) {
|
|
3379
|
+
results.push({
|
|
3380
|
+
source: "w:ref",
|
|
3381
|
+
kind: "bookmark",
|
|
3382
|
+
target: element.target,
|
|
3383
|
+
label: element.label || element.target || "w:ref",
|
|
3384
|
+
confidence: element.target ? "high" : "medium"
|
|
3385
|
+
});
|
|
3386
|
+
}
|
|
3387
|
+
return dedupeCrossReferences(results);
|
|
3388
|
+
}
|
|
3389
|
+
function collectCrossReferencesFromCanonicalDocument(document) {
|
|
3390
|
+
const root = "content" in document ? document.content : document;
|
|
3391
|
+
const results = [];
|
|
3392
|
+
let paragraphIndex = -1;
|
|
3393
|
+
walkDocument2(root, (node) => {
|
|
3394
|
+
if (node.type === "paragraph") {
|
|
3395
|
+
paragraphIndex += 1;
|
|
3396
|
+
for (const child of node.children) {
|
|
3397
|
+
if (child.type === "hyperlink" && child.href.startsWith("#")) {
|
|
3398
|
+
results.push({
|
|
3399
|
+
source: "hyperlink",
|
|
3400
|
+
kind: "bookmark",
|
|
3401
|
+
target: child.href.slice(1),
|
|
3402
|
+
label: flattenInlineText(child.children).trim() || child.href.slice(1),
|
|
3403
|
+
paragraphIndex,
|
|
3404
|
+
confidence: "high"
|
|
3405
|
+
});
|
|
3406
|
+
continue;
|
|
3407
|
+
}
|
|
3408
|
+
if (child.type === "field") {
|
|
3409
|
+
const reference = parseFieldReferenceInstruction(child.instruction);
|
|
3410
|
+
if (!reference) {
|
|
3411
|
+
continue;
|
|
3412
|
+
}
|
|
3413
|
+
results.push({
|
|
3414
|
+
source: "field",
|
|
3415
|
+
kind: "bookmark",
|
|
3416
|
+
target: reference.target,
|
|
3417
|
+
instruction: reference.instruction,
|
|
3418
|
+
label: flattenInlineText(child.children).trim() || reference.target,
|
|
3419
|
+
paragraphIndex,
|
|
3420
|
+
confidence: "high"
|
|
3421
|
+
});
|
|
3422
|
+
}
|
|
3423
|
+
}
|
|
3424
|
+
for (const pattern of detectCrossReferencePatterns(flattenParagraphText(node))) {
|
|
3425
|
+
results.push({
|
|
3426
|
+
source: "text-pattern",
|
|
3427
|
+
kind: pattern.kind,
|
|
3428
|
+
target: pattern.targetHint,
|
|
3429
|
+
label: pattern.label,
|
|
3430
|
+
paragraphIndex,
|
|
3431
|
+
confidence: "medium"
|
|
3432
|
+
});
|
|
3433
|
+
}
|
|
3434
|
+
}
|
|
3435
|
+
});
|
|
3436
|
+
return dedupeCrossReferences(results);
|
|
3437
|
+
}
|
|
3438
|
+
function detectCrossReferencePatterns(text) {
|
|
3439
|
+
const matches = [];
|
|
3440
|
+
for (const match of text.matchAll(CROSS_REFERENCE_PATTERN)) {
|
|
3441
|
+
const referenceType = match[1]?.toLowerCase();
|
|
3442
|
+
const target = match[2];
|
|
3443
|
+
const label = `${match[1]} ${target}`.trim();
|
|
3444
|
+
if (!referenceType || !target) {
|
|
3445
|
+
continue;
|
|
3446
|
+
}
|
|
3447
|
+
matches.push({
|
|
3448
|
+
kind: referenceType,
|
|
3449
|
+
label,
|
|
3450
|
+
targetHint: target
|
|
3451
|
+
});
|
|
3452
|
+
}
|
|
3453
|
+
return matches;
|
|
3454
|
+
}
|
|
3455
|
+
function parseFieldReferenceInstruction(instruction) {
|
|
3456
|
+
const trimmedInstruction = instruction.trim().replace(/\s+/g, " ");
|
|
3457
|
+
const match = /^(REF|PAGEREF|NOTEREF)\s+(?:"([^"]+)"|([^\s\\]+))/i.exec(trimmedInstruction);
|
|
3458
|
+
if (!match) {
|
|
3459
|
+
return void 0;
|
|
3460
|
+
}
|
|
3461
|
+
return {
|
|
3462
|
+
kind: match[1].toUpperCase(),
|
|
3463
|
+
target: (match[2] ?? match[3] ?? "").trim(),
|
|
3464
|
+
instruction: trimmedInstruction
|
|
3465
|
+
};
|
|
3466
|
+
}
|
|
3467
|
+
function extractWRefElements(xml) {
|
|
3468
|
+
const matches = [];
|
|
3469
|
+
for (const match of xml.matchAll(W_REF_PATTERN)) {
|
|
3470
|
+
const attributes = readAttributes(match[1] ?? "");
|
|
3471
|
+
matches.push({
|
|
3472
|
+
target: attributes.anchor ?? attributes.name ?? attributes.id,
|
|
3473
|
+
label: attributes.displayText ?? attributes.text
|
|
3474
|
+
});
|
|
3475
|
+
}
|
|
3476
|
+
return matches;
|
|
3477
|
+
}
|
|
3478
|
+
function extractComplexFieldsWithRegex(xml) {
|
|
3479
|
+
const matches = [];
|
|
3480
|
+
for (const match of xml.matchAll(COMPLEX_FIELD_PATTERN)) {
|
|
3481
|
+
const instruction = stripXml(match[1] ?? "");
|
|
3482
|
+
const label = stripXml(match[2] ?? "");
|
|
3483
|
+
if (!instruction) {
|
|
3484
|
+
continue;
|
|
3485
|
+
}
|
|
3486
|
+
matches.push({ instruction, label });
|
|
3487
|
+
}
|
|
3488
|
+
return matches;
|
|
3489
|
+
}
|
|
3490
|
+
function readAttributes(source) {
|
|
3491
|
+
const attributes = {};
|
|
3492
|
+
for (const match of source.matchAll(ATTRIBUTE_PATTERN)) {
|
|
3493
|
+
const [, key, value] = match;
|
|
3494
|
+
attributes[key] = value;
|
|
3495
|
+
}
|
|
3496
|
+
return attributes;
|
|
3497
|
+
}
|
|
3498
|
+
function stripXml(xml) {
|
|
3499
|
+
return xml.replace(/<[^>]+>/g, "").replace(/\s+/g, " ").trim();
|
|
3500
|
+
}
|
|
3501
|
+
function flattenParagraphText(paragraph) {
|
|
3502
|
+
return paragraph.children.map((child) => {
|
|
3503
|
+
switch (child.type) {
|
|
3504
|
+
case "text":
|
|
3505
|
+
return child.text;
|
|
3506
|
+
case "hyperlink":
|
|
3507
|
+
return flattenInlineText(child.children);
|
|
3508
|
+
case "field":
|
|
3509
|
+
return child.children ? flattenInlineText(child.children) : "";
|
|
3510
|
+
case "tab":
|
|
3511
|
+
return " ";
|
|
3512
|
+
case "hard_break":
|
|
3513
|
+
case "column_break":
|
|
3514
|
+
return "\n";
|
|
3515
|
+
default:
|
|
3516
|
+
return "";
|
|
3517
|
+
}
|
|
3518
|
+
}).join("");
|
|
3519
|
+
}
|
|
3520
|
+
function flattenInlineText(children) {
|
|
3521
|
+
return children.map((child) => {
|
|
3522
|
+
if (child.type === "text") {
|
|
3523
|
+
return child.text;
|
|
3524
|
+
}
|
|
3525
|
+
if (child.type === "tab") {
|
|
3526
|
+
return " ";
|
|
3527
|
+
}
|
|
3528
|
+
if (child.type === "hard_break" || child.type === "column_break") {
|
|
3529
|
+
return "\n";
|
|
3530
|
+
}
|
|
3531
|
+
return "";
|
|
3532
|
+
}).join("");
|
|
3533
|
+
}
|
|
3534
|
+
function dedupeCrossReferences(references) {
|
|
3535
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3536
|
+
const deduped = [];
|
|
3537
|
+
for (const reference of references) {
|
|
3538
|
+
const key = [
|
|
3539
|
+
reference.source,
|
|
3540
|
+
reference.kind,
|
|
3541
|
+
reference.target ?? "",
|
|
3542
|
+
reference.label,
|
|
3543
|
+
String(reference.paragraphIndex ?? -1)
|
|
3544
|
+
].join("|");
|
|
3545
|
+
if (seen.has(key)) {
|
|
3546
|
+
continue;
|
|
3547
|
+
}
|
|
3548
|
+
seen.add(key);
|
|
3549
|
+
deduped.push(reference);
|
|
3550
|
+
}
|
|
3551
|
+
return deduped;
|
|
3552
|
+
}
|
|
3553
|
+
function walkDocument2(node, visit) {
|
|
3554
|
+
visit(node);
|
|
3555
|
+
if ("children" in node && Array.isArray(node.children)) {
|
|
3556
|
+
for (const child of node.children) {
|
|
3557
|
+
walkDocument2(child, visit);
|
|
3558
|
+
}
|
|
3559
|
+
}
|
|
3560
|
+
if (node.type === "table") {
|
|
3561
|
+
for (const row of node.rows) {
|
|
3562
|
+
walkDocument2(row, visit);
|
|
3563
|
+
}
|
|
3564
|
+
} else if (node.type === "table_row") {
|
|
3565
|
+
for (const cell of node.cells) {
|
|
3566
|
+
walkDocument2(cell, visit);
|
|
3567
|
+
}
|
|
3568
|
+
}
|
|
3569
|
+
}
|
|
3570
|
+
|
|
3571
|
+
// src/legal/defined-terms.ts
|
|
3572
|
+
var QUOTED_DEFINITION_PATTERN = /["“]([A-Z][A-Za-z0-9]*(?:[ -][A-Z][A-Za-z0-9]*){0,5})["”]\s+(?:means|has the meaning(?: set forth)?|shall mean|refers to)\b/g;
|
|
3573
|
+
var BARE_DEFINITION_PATTERN = /\b([A-Z][A-Za-z0-9]*(?:\s+[A-Z][A-Za-z0-9]*){0,5})\s+(?:means|has the meaning(?: set forth)?|shall mean|refers to)\b/g;
|
|
3574
|
+
var BLOCKED_BARE_TERMS = /* @__PURE__ */ new Set([
|
|
3575
|
+
"This Agreement",
|
|
3576
|
+
"Such Term",
|
|
3577
|
+
"The Company",
|
|
3578
|
+
"This Section",
|
|
3579
|
+
"This Clause"
|
|
3580
|
+
]);
|
|
3581
|
+
function collectDefinedTermsFromDocumentXml(xml) {
|
|
3582
|
+
const parsed = parseMainDocumentXml(xml);
|
|
3583
|
+
const paragraphs = parsed.blocks.filter((block) => block.type === "paragraph").map((block) => flattenParagraphText2(block));
|
|
3584
|
+
return buildDefinedTermCatalog(paragraphs);
|
|
3585
|
+
}
|
|
3586
|
+
function collectDefinedTermsFromCanonicalDocument(document) {
|
|
3587
|
+
const root = "content" in document ? document.content : document;
|
|
3588
|
+
const paragraphs = [];
|
|
3589
|
+
walkDocument3(root, (node) => {
|
|
3590
|
+
if (node.type === "paragraph") {
|
|
3591
|
+
paragraphs.push(flattenParagraphText2(node));
|
|
3592
|
+
}
|
|
3593
|
+
});
|
|
3594
|
+
return buildDefinedTermCatalog(paragraphs);
|
|
3595
|
+
}
|
|
3596
|
+
function buildDefinedTermCatalog(paragraphs) {
|
|
3597
|
+
const terms = /* @__PURE__ */ new Map();
|
|
3598
|
+
paragraphs.forEach((paragraph, paragraphIndex) => {
|
|
3599
|
+
for (const candidate of extractDefinitionCandidates(paragraph)) {
|
|
3600
|
+
const normalized = normalizeTerm(candidate.term);
|
|
3601
|
+
const existing = terms.get(normalized) ?? {
|
|
3602
|
+
term: candidate.term,
|
|
3603
|
+
normalizedTerm: normalized,
|
|
3604
|
+
definitionStyle: candidate.definitionStyle,
|
|
3605
|
+
definitions: [],
|
|
3606
|
+
references: []
|
|
3607
|
+
};
|
|
3608
|
+
if (!terms.has(normalized)) {
|
|
3609
|
+
terms.set(normalized, existing);
|
|
3610
|
+
}
|
|
3611
|
+
existing.definitions.push({
|
|
3612
|
+
paragraphIndex,
|
|
3613
|
+
label: candidate.term,
|
|
3614
|
+
kind: "definition"
|
|
3615
|
+
});
|
|
3616
|
+
}
|
|
3617
|
+
});
|
|
3618
|
+
paragraphs.forEach((paragraph, paragraphIndex) => {
|
|
3619
|
+
for (const term of terms.values()) {
|
|
3620
|
+
const references = findTermReferences(paragraph, term.term);
|
|
3621
|
+
if (references === 0) {
|
|
3622
|
+
continue;
|
|
3623
|
+
}
|
|
3624
|
+
const hasDefinitionInParagraph = term.definitions.some(
|
|
3625
|
+
(definition) => definition.paragraphIndex === paragraphIndex
|
|
3626
|
+
);
|
|
3627
|
+
const referenceCount = hasDefinitionInParagraph ? 0 : references;
|
|
3628
|
+
for (let count = 0; count < referenceCount; count += 1) {
|
|
3629
|
+
term.references.push({
|
|
3630
|
+
paragraphIndex,
|
|
3631
|
+
label: term.term,
|
|
3632
|
+
kind: "reference"
|
|
3633
|
+
});
|
|
3634
|
+
}
|
|
3635
|
+
}
|
|
3636
|
+
});
|
|
3637
|
+
return Array.from(terms.values()).sort((left, right) => left.term.localeCompare(right.term));
|
|
3638
|
+
}
|
|
3639
|
+
function extractDefinitionCandidates(paragraph) {
|
|
3640
|
+
const candidates = [];
|
|
3641
|
+
for (const match of paragraph.matchAll(QUOTED_DEFINITION_PATTERN)) {
|
|
3642
|
+
const term = match[1]?.trim();
|
|
3643
|
+
if (!term) {
|
|
3644
|
+
continue;
|
|
3645
|
+
}
|
|
3646
|
+
candidates.push({
|
|
3647
|
+
term,
|
|
3648
|
+
definitionStyle: "quoted"
|
|
3649
|
+
});
|
|
3650
|
+
}
|
|
3651
|
+
for (const match of paragraph.matchAll(BARE_DEFINITION_PATTERN)) {
|
|
3652
|
+
const term = match[1]?.trim();
|
|
3653
|
+
if (!term || BLOCKED_BARE_TERMS.has(term) || isQuotedTerm(term, paragraph)) {
|
|
3654
|
+
continue;
|
|
3655
|
+
}
|
|
3656
|
+
candidates.push({
|
|
3657
|
+
term,
|
|
3658
|
+
definitionStyle: "bare"
|
|
3659
|
+
});
|
|
3660
|
+
}
|
|
3661
|
+
return candidates;
|
|
3662
|
+
}
|
|
3663
|
+
function normalizeTerm(term) {
|
|
3664
|
+
return term.trim().replace(/\s+/g, " ").toLowerCase();
|
|
3665
|
+
}
|
|
3666
|
+
function isQuotedTerm(term, paragraph) {
|
|
3667
|
+
return paragraph.includes(`"${term}"`) || paragraph.includes(`\u201C${term}\u201D`);
|
|
3668
|
+
}
|
|
3669
|
+
function findTermReferences(paragraph, term) {
|
|
3670
|
+
const escapedTerm = escapeRegExp(term);
|
|
3671
|
+
const pattern = new RegExp(`(?:^|[^A-Za-z0-9])(?:"|\u201C)?(${escapedTerm})(?:"|\u201D)?(?=[^A-Za-z0-9]|$)`, "g");
|
|
3672
|
+
return Array.from(paragraph.matchAll(pattern)).length;
|
|
3673
|
+
}
|
|
3674
|
+
function escapeRegExp(value) {
|
|
3675
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3676
|
+
}
|
|
3677
|
+
function flattenParagraphText2(paragraph) {
|
|
3678
|
+
return paragraph.children.map((child) => {
|
|
3679
|
+
switch (child.type) {
|
|
3680
|
+
case "text":
|
|
3681
|
+
return child.text;
|
|
3682
|
+
case "hyperlink":
|
|
3683
|
+
case "field":
|
|
3684
|
+
return child.children.map((nested) => nested.type === "text" ? nested.text : nested.type === "tab" ? " " : "").join("");
|
|
3685
|
+
case "tab":
|
|
3686
|
+
return " ";
|
|
3687
|
+
case "hard_break":
|
|
3688
|
+
case "column_break":
|
|
3689
|
+
return "\n";
|
|
3690
|
+
default:
|
|
3691
|
+
return "";
|
|
3692
|
+
}
|
|
3693
|
+
}).join("");
|
|
3694
|
+
}
|
|
3695
|
+
function walkDocument3(node, visit) {
|
|
3696
|
+
visit(node);
|
|
3697
|
+
if ("children" in node && Array.isArray(node.children)) {
|
|
3698
|
+
for (const child of node.children) {
|
|
3699
|
+
walkDocument3(child, visit);
|
|
3700
|
+
}
|
|
3701
|
+
}
|
|
3702
|
+
if (node.type === "table") {
|
|
3703
|
+
for (const row of node.rows) {
|
|
3704
|
+
walkDocument3(row, visit);
|
|
3705
|
+
}
|
|
3706
|
+
} else if (node.type === "table_row") {
|
|
3707
|
+
for (const cell of node.cells) {
|
|
3708
|
+
walkDocument3(cell, visit);
|
|
3709
|
+
}
|
|
3710
|
+
}
|
|
3711
|
+
}
|
|
3712
|
+
|
|
3713
|
+
// src/legal/signature-blocks.ts
|
|
3714
|
+
var EXECUTION_TRIGGER_PATTERN = /\b(?:IN WITNESS WHEREOF|EXECUTED|AGREED AND ACCEPTED|SIGNATURES FOLLOW)\b/i;
|
|
3715
|
+
var ROLE_LINE_PATTERN = /^\s*(?:By|Name|Title|Date|Witness|Authorized Signatory|Signature)\s*[:\-]?\s*/i;
|
|
3716
|
+
var PARTY_LABEL_PATTERN = /^(?:(?:The |)[A-Z][A-Za-z0-9 ,.'&()-]{2,60})\s*$/;
|
|
3717
|
+
var WITNESS_PATTERN = /\bWITNESS(?:ED|ES)?\b/i;
|
|
3718
|
+
var NOTARY_PATTERN = /\bNOTARY\s+PUBLIC\b/i;
|
|
3719
|
+
var UNDERLINE_PLACEHOLDER_PATTERN = /_{4,}|\.{4,}/;
|
|
3720
|
+
function detectSignatureBlocksFromCanonicalDocument(document) {
|
|
3721
|
+
const root = "content" in document ? document.content : document;
|
|
3722
|
+
const paragraphs = [];
|
|
3723
|
+
const warnings = [];
|
|
3724
|
+
walkBlocks(root, (node) => {
|
|
3725
|
+
if (node.type === "paragraph") {
|
|
3726
|
+
paragraphs.push({ text: flattenParagraphText3(node), node });
|
|
3727
|
+
}
|
|
3728
|
+
});
|
|
3729
|
+
const candidates = findSignatureBlockCandidates(paragraphs);
|
|
3730
|
+
const hasPreservation = "preservation" in document && document.preservation !== void 0;
|
|
3731
|
+
const preservationSafe = hasPreservation ? !hasOpaqueFragmentsInSignatureRanges(
|
|
3732
|
+
document,
|
|
3733
|
+
candidates
|
|
3734
|
+
) : true;
|
|
3735
|
+
if (!preservationSafe) {
|
|
3736
|
+
warnings.push(
|
|
3737
|
+
"One or more signature block regions overlap with preserve-only opaque fragments. Export fidelity may be degraded."
|
|
3738
|
+
);
|
|
3739
|
+
}
|
|
3740
|
+
return {
|
|
3741
|
+
reportVersion: "signature-block-report/1",
|
|
3742
|
+
candidates,
|
|
3743
|
+
preservationSafe,
|
|
3744
|
+
warnings
|
|
3745
|
+
};
|
|
3746
|
+
}
|
|
3747
|
+
function findSignatureBlockCandidates(paragraphs) {
|
|
3748
|
+
const candidates = [];
|
|
3749
|
+
let index = 0;
|
|
3750
|
+
while (index < paragraphs.length) {
|
|
3751
|
+
const text = paragraphs[index].text;
|
|
3752
|
+
if (EXECUTION_TRIGGER_PATTERN.test(text)) {
|
|
3753
|
+
const block = scanSignatureBlock(paragraphs, index);
|
|
3754
|
+
if (block) {
|
|
3755
|
+
candidates.push(block);
|
|
3756
|
+
index = block.endIndex + 1;
|
|
3757
|
+
continue;
|
|
3758
|
+
}
|
|
3759
|
+
}
|
|
3760
|
+
index += 1;
|
|
3761
|
+
}
|
|
3762
|
+
return candidates;
|
|
3763
|
+
}
|
|
3764
|
+
function scanSignatureBlock(paragraphs, triggerIndex) {
|
|
3765
|
+
const parties = [];
|
|
3766
|
+
let endIndex = triggerIndex;
|
|
3767
|
+
let kind = "execution-block";
|
|
3768
|
+
let hasSignatureContent = false;
|
|
3769
|
+
for (let index = triggerIndex + 1; index < paragraphs.length && index <= triggerIndex + 40; index += 1) {
|
|
3770
|
+
const text = paragraphs[index].text.trim();
|
|
3771
|
+
if (text.length === 0) {
|
|
3772
|
+
endIndex = index;
|
|
3773
|
+
continue;
|
|
3774
|
+
}
|
|
3775
|
+
if (WITNESS_PATTERN.test(text)) {
|
|
3776
|
+
kind = "witness-block";
|
|
3777
|
+
}
|
|
3778
|
+
if (NOTARY_PATTERN.test(text)) {
|
|
3779
|
+
kind = "notary-block";
|
|
3780
|
+
}
|
|
3781
|
+
if (ROLE_LINE_PATTERN.test(text)) {
|
|
3782
|
+
hasSignatureContent = true;
|
|
3783
|
+
endIndex = index;
|
|
3784
|
+
continue;
|
|
3785
|
+
}
|
|
3786
|
+
if (UNDERLINE_PLACEHOLDER_PATTERN.test(text)) {
|
|
3787
|
+
hasSignatureContent = true;
|
|
3788
|
+
endIndex = index;
|
|
3789
|
+
continue;
|
|
3790
|
+
}
|
|
3791
|
+
if (PARTY_LABEL_PATTERN.test(text) && !isBodyParagraph(text)) {
|
|
3792
|
+
parties.push({
|
|
3793
|
+
roleLabel: text.trim(),
|
|
3794
|
+
paragraphIndex: index
|
|
3795
|
+
});
|
|
3796
|
+
hasSignatureContent = true;
|
|
3797
|
+
endIndex = index;
|
|
3798
|
+
continue;
|
|
3799
|
+
}
|
|
3800
|
+
if (hasSignatureContent && isBodyParagraph(text)) {
|
|
3801
|
+
break;
|
|
3802
|
+
}
|
|
3803
|
+
endIndex = index;
|
|
3804
|
+
}
|
|
3805
|
+
if (!hasSignatureContent) {
|
|
3806
|
+
return void 0;
|
|
3807
|
+
}
|
|
3808
|
+
return {
|
|
3809
|
+
startIndex: triggerIndex,
|
|
3810
|
+
endIndex,
|
|
3811
|
+
kind,
|
|
3812
|
+
parties,
|
|
3813
|
+
confidence: parties.length > 0 ? "high" : "medium"
|
|
3814
|
+
};
|
|
3815
|
+
}
|
|
3816
|
+
function isBodyParagraph(text) {
|
|
3817
|
+
return text.length > 120 && /[.;]/.test(text);
|
|
3818
|
+
}
|
|
3819
|
+
function hasOpaqueFragmentsInSignatureRanges(document, candidates) {
|
|
3820
|
+
if (candidates.length === 0) {
|
|
3821
|
+
return false;
|
|
3822
|
+
}
|
|
3823
|
+
const opaqueCount = Object.keys(document.preservation.opaqueFragments).length;
|
|
3824
|
+
if (opaqueCount === 0) {
|
|
3825
|
+
return false;
|
|
3826
|
+
}
|
|
3827
|
+
let paragraphIndex = 0;
|
|
3828
|
+
const opaqueIndices = /* @__PURE__ */ new Set();
|
|
3829
|
+
for (const block of document.content.children) {
|
|
3830
|
+
if (block.type === "paragraph") {
|
|
3831
|
+
paragraphIndex += 1;
|
|
3832
|
+
continue;
|
|
3833
|
+
}
|
|
3834
|
+
if (block.type === "opaque_block") {
|
|
3835
|
+
opaqueIndices.add(paragraphIndex);
|
|
3836
|
+
}
|
|
3837
|
+
paragraphIndex += 1;
|
|
3838
|
+
}
|
|
3839
|
+
return candidates.some((candidate) => {
|
|
3840
|
+
for (let index = candidate.startIndex; index <= candidate.endIndex; index += 1) {
|
|
3841
|
+
if (opaqueIndices.has(index)) {
|
|
3842
|
+
return true;
|
|
3843
|
+
}
|
|
3844
|
+
}
|
|
3845
|
+
return false;
|
|
3846
|
+
});
|
|
3847
|
+
}
|
|
3848
|
+
function flattenParagraphText3(paragraph) {
|
|
3849
|
+
return paragraph.children.map((child) => {
|
|
3850
|
+
switch (child.type) {
|
|
3851
|
+
case "text":
|
|
3852
|
+
return child.text;
|
|
3853
|
+
case "hyperlink":
|
|
3854
|
+
case "field":
|
|
3855
|
+
return child.children.map(
|
|
3856
|
+
(nested) => nested.type === "text" ? nested.text : nested.type === "tab" ? " " : ""
|
|
3857
|
+
).join("");
|
|
3858
|
+
case "tab":
|
|
3859
|
+
return " ";
|
|
3860
|
+
case "hard_break":
|
|
3861
|
+
case "column_break":
|
|
3862
|
+
return "\n";
|
|
3863
|
+
default:
|
|
3864
|
+
return "";
|
|
3865
|
+
}
|
|
3866
|
+
}).join("");
|
|
3867
|
+
}
|
|
3868
|
+
function walkBlocks(node, visit) {
|
|
3869
|
+
visit(node);
|
|
3870
|
+
if ("children" in node && Array.isArray(node.children)) {
|
|
3871
|
+
for (const child of node.children) {
|
|
3872
|
+
walkBlocks(child, visit);
|
|
3873
|
+
}
|
|
3874
|
+
}
|
|
3875
|
+
if (node.type === "table") {
|
|
3876
|
+
for (const row of node.rows) {
|
|
3877
|
+
walkBlocks(row, visit);
|
|
3878
|
+
}
|
|
3879
|
+
} else if (node.type === "table_row") {
|
|
3880
|
+
for (const cell of node.cells) {
|
|
3881
|
+
walkBlocks(cell, visit);
|
|
3882
|
+
}
|
|
3883
|
+
}
|
|
3884
|
+
}
|
|
3885
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
3886
|
+
0 && (module.exports = {
|
|
3887
|
+
assessBookmarkIntegrity,
|
|
3888
|
+
buildDefinedTermCatalog,
|
|
3889
|
+
collectBookmarksFromCanonicalDocument,
|
|
3890
|
+
collectCrossReferencesFromCanonicalDocument,
|
|
3891
|
+
collectDefinedTermsFromCanonicalDocument,
|
|
3892
|
+
collectDefinedTermsFromDocumentXml,
|
|
3893
|
+
detectCrossReferencePatterns,
|
|
3894
|
+
detectSignatureBlocksFromCanonicalDocument,
|
|
3895
|
+
isHiddenBookmarkName,
|
|
3896
|
+
parseBookmarksFromDocumentXml,
|
|
3897
|
+
parseCrossReferencesFromDocumentXml,
|
|
3898
|
+
parseFieldReferenceInstruction
|
|
3899
|
+
});
|
|
3900
|
+
//# sourceMappingURL=index.cjs.map
|