@beyondwork/docx-react-component 1.0.28 → 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 +61 -41
- package/src/README.md +0 -85
- package/src/api/README.md +0 -26
- package/src/api/public-types.ts +0 -1421
- 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/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 -4086
- 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 -61
- 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-command-bridge.ts +0 -184
- 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 -944
- 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,1275 @@
|
|
|
1
|
+
import {
|
|
2
|
+
describeOpaqueFragment,
|
|
3
|
+
getOpaqueFragment
|
|
4
|
+
} from "./chunk-SWKWQZXM.js";
|
|
5
|
+
|
|
6
|
+
// src/runtime/story-context.ts
|
|
7
|
+
function collectSectionContexts(document) {
|
|
8
|
+
const sections = [];
|
|
9
|
+
let sectionIndex = 0;
|
|
10
|
+
for (const block of document.content.children) {
|
|
11
|
+
if (block.type !== "section_break") {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
sections.push({
|
|
15
|
+
index: sectionIndex,
|
|
16
|
+
properties: block.sectionProperties
|
|
17
|
+
});
|
|
18
|
+
sectionIndex += 1;
|
|
19
|
+
}
|
|
20
|
+
sections.push({
|
|
21
|
+
index: sectionIndex,
|
|
22
|
+
properties: document.subParts?.finalSectionProperties
|
|
23
|
+
});
|
|
24
|
+
return sections;
|
|
25
|
+
}
|
|
26
|
+
function resolveSectionVariants(kind, sectionIndex, explicitReferences, documents) {
|
|
27
|
+
if (explicitReferences && explicitReferences.length > 0) {
|
|
28
|
+
return explicitReferences.map((ref) => ({
|
|
29
|
+
variant: ref.variant,
|
|
30
|
+
relationshipId: ref.relationshipId
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
return documents.filter(
|
|
34
|
+
(entry) => entry.sectionIndex === void 0 || entry.sectionIndex === sectionIndex
|
|
35
|
+
).map((entry) => ({
|
|
36
|
+
variant: entry.variant,
|
|
37
|
+
relationshipId: entry.relationshipId
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
function findHeaderFooterDocumentEntry(document, target) {
|
|
41
|
+
const documents = target.kind === "header" ? document.subParts?.headers ?? [] : document.subParts?.footers ?? [];
|
|
42
|
+
const matches = documents.filter(
|
|
43
|
+
(entry) => entry.relationshipId === target.relationshipId && entry.variant === target.variant
|
|
44
|
+
);
|
|
45
|
+
if (matches.length === 0) {
|
|
46
|
+
return void 0;
|
|
47
|
+
}
|
|
48
|
+
if (target.sectionIndex !== void 0) {
|
|
49
|
+
return matches.find((entry) => entry.sectionIndex === target.sectionIndex) ?? matches.find((entry) => entry.sectionIndex === void 0) ?? matches[0];
|
|
50
|
+
}
|
|
51
|
+
return matches[0];
|
|
52
|
+
}
|
|
53
|
+
function sectionSupportsStoryTarget(document, sectionIndex, target) {
|
|
54
|
+
if (!findHeaderFooterDocumentEntry(document, target)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
const section = collectSectionContexts(document).find(
|
|
58
|
+
(candidate) => candidate.index === sectionIndex
|
|
59
|
+
);
|
|
60
|
+
if (!section) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const variants = resolveSectionVariants(
|
|
64
|
+
target.kind,
|
|
65
|
+
sectionIndex,
|
|
66
|
+
target.kind === "header" ? section.properties?.headerReferences : section.properties?.footerReferences,
|
|
67
|
+
target.kind === "header" ? document.subParts?.headers ?? [] : document.subParts?.footers ?? []
|
|
68
|
+
);
|
|
69
|
+
return variants.some(
|
|
70
|
+
(variant) => variant.relationshipId === target.relationshipId && variant.variant === target.variant
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
function normalizeHeaderFooterTarget(document, target, preferredSectionIndex) {
|
|
74
|
+
if (!findHeaderFooterDocumentEntry(document, target)) {
|
|
75
|
+
return void 0;
|
|
76
|
+
}
|
|
77
|
+
if (target.sectionIndex !== void 0) {
|
|
78
|
+
return sectionSupportsStoryTarget(document, target.sectionIndex, target) ? target : void 0;
|
|
79
|
+
}
|
|
80
|
+
const candidateIndexes = collectSectionContexts(document).map((section) => section.index).filter(
|
|
81
|
+
(sectionIndex) => sectionSupportsStoryTarget(document, sectionIndex, target)
|
|
82
|
+
);
|
|
83
|
+
if (candidateIndexes.length === 0) {
|
|
84
|
+
return void 0;
|
|
85
|
+
}
|
|
86
|
+
const resolvedSectionIndex = preferredSectionIndex !== void 0 && candidateIndexes.includes(preferredSectionIndex) ? preferredSectionIndex : candidateIndexes[0];
|
|
87
|
+
return {
|
|
88
|
+
...target,
|
|
89
|
+
sectionIndex: resolvedSectionIndex
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/runtime/story-targeting.ts
|
|
94
|
+
function storyTargetKey(target) {
|
|
95
|
+
switch (target.kind) {
|
|
96
|
+
case "main":
|
|
97
|
+
return "main";
|
|
98
|
+
case "header":
|
|
99
|
+
return `header:${target.relationshipId}:${target.variant}:${target.sectionIndex ?? "*"}`;
|
|
100
|
+
case "footer":
|
|
101
|
+
return `footer:${target.relationshipId}:${target.variant}:${target.sectionIndex ?? "*"}`;
|
|
102
|
+
case "footnote":
|
|
103
|
+
return `footnote:${target.noteId}`;
|
|
104
|
+
case "endnote":
|
|
105
|
+
return `endnote:${target.noteId}`;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function getStoryBlocks(document, target) {
|
|
109
|
+
if (target.kind === "main") {
|
|
110
|
+
return document.content.children;
|
|
111
|
+
}
|
|
112
|
+
const subParts = document.subParts;
|
|
113
|
+
if (!subParts) {
|
|
114
|
+
return [];
|
|
115
|
+
}
|
|
116
|
+
switch (target.kind) {
|
|
117
|
+
case "header": {
|
|
118
|
+
const resolvedTarget = normalizeHeaderFooterTarget(document, target);
|
|
119
|
+
return (resolvedTarget && findHeaderFooterDocumentEntry(document, resolvedTarget)?.blocks) ?? [];
|
|
120
|
+
}
|
|
121
|
+
case "footer": {
|
|
122
|
+
const resolvedTarget = normalizeHeaderFooterTarget(document, target);
|
|
123
|
+
return (resolvedTarget && findHeaderFooterDocumentEntry(document, resolvedTarget)?.blocks) ?? [];
|
|
124
|
+
}
|
|
125
|
+
case "footnote":
|
|
126
|
+
return subParts.footnoteCollection?.footnotes[target.noteId]?.blocks ?? [];
|
|
127
|
+
case "endnote":
|
|
128
|
+
return subParts.footnoteCollection?.endnotes[target.noteId]?.blocks ?? [];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function replaceStoryBlocks(document, target, blocks) {
|
|
132
|
+
if (target.kind === "main") {
|
|
133
|
+
return {
|
|
134
|
+
...document,
|
|
135
|
+
content: {
|
|
136
|
+
...document.content,
|
|
137
|
+
children: [...blocks]
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (!document.subParts) {
|
|
142
|
+
return document;
|
|
143
|
+
}
|
|
144
|
+
switch (target.kind) {
|
|
145
|
+
case "header": {
|
|
146
|
+
const resolvedTarget = normalizeHeaderFooterTarget(document, target);
|
|
147
|
+
const matchedEntry = resolvedTarget ? findHeaderFooterDocumentEntry(document, resolvedTarget) : void 0;
|
|
148
|
+
if (!matchedEntry) {
|
|
149
|
+
return document;
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
...document,
|
|
153
|
+
subParts: {
|
|
154
|
+
...document.subParts,
|
|
155
|
+
headers: document.subParts.headers.map(
|
|
156
|
+
(header) => header.relationshipId === matchedEntry.relationshipId && header.variant === matchedEntry.variant && header.partPath === matchedEntry.partPath ? { ...header, blocks: [...blocks] } : header
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
case "footer": {
|
|
162
|
+
const resolvedTarget = normalizeHeaderFooterTarget(document, target);
|
|
163
|
+
const matchedEntry = resolvedTarget ? findHeaderFooterDocumentEntry(document, resolvedTarget) : void 0;
|
|
164
|
+
if (!matchedEntry) {
|
|
165
|
+
return document;
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
...document,
|
|
169
|
+
subParts: {
|
|
170
|
+
...document.subParts,
|
|
171
|
+
footers: document.subParts.footers.map(
|
|
172
|
+
(footer) => footer.relationshipId === matchedEntry.relationshipId && footer.variant === matchedEntry.variant && footer.partPath === matchedEntry.partPath ? { ...footer, blocks: [...blocks] } : footer
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
case "footnote":
|
|
178
|
+
return !document.subParts.footnoteCollection?.footnotes[target.noteId] ? document : {
|
|
179
|
+
...document,
|
|
180
|
+
subParts: {
|
|
181
|
+
...document.subParts,
|
|
182
|
+
footnoteCollection: {
|
|
183
|
+
...document.subParts.footnoteCollection,
|
|
184
|
+
footnotes: {
|
|
185
|
+
...document.subParts.footnoteCollection.footnotes,
|
|
186
|
+
[target.noteId]: {
|
|
187
|
+
...document.subParts.footnoteCollection.footnotes[target.noteId],
|
|
188
|
+
blocks: [...blocks]
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
case "endnote":
|
|
195
|
+
return !document.subParts.footnoteCollection?.endnotes[target.noteId] ? document : {
|
|
196
|
+
...document,
|
|
197
|
+
subParts: {
|
|
198
|
+
...document.subParts,
|
|
199
|
+
footnoteCollection: {
|
|
200
|
+
...document.subParts.footnoteCollection,
|
|
201
|
+
endnotes: {
|
|
202
|
+
...document.subParts.footnoteCollection.endnotes,
|
|
203
|
+
[target.noteId]: {
|
|
204
|
+
...document.subParts.footnoteCollection.endnotes[target.noteId],
|
|
205
|
+
blocks: [...blocks]
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// src/runtime/numbering-prefix.ts
|
|
215
|
+
var DEFAULT_START_AT = 1;
|
|
216
|
+
function createNumberingPrefixResolver(catalog) {
|
|
217
|
+
const sequenceStates = /* @__PURE__ */ new Map();
|
|
218
|
+
function resolveInternal(numbering) {
|
|
219
|
+
if (!numbering) {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
const instance = catalog.instances[numbering.numberingInstanceId];
|
|
223
|
+
if (!instance) {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
const definition = catalog.abstractDefinitions[instance.abstractNumberingId];
|
|
227
|
+
if (!definition) {
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
const levelDefinitions = new Map(
|
|
231
|
+
definition.levels.map((level) => [level.level, level])
|
|
232
|
+
);
|
|
233
|
+
const levelDefinition = levelDefinitions.get(numbering.level);
|
|
234
|
+
if (!levelDefinition || levelDefinition.format === "none") {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
const sequenceState = getSequenceState(sequenceStates, numbering.numberingInstanceId);
|
|
238
|
+
advanceSequence(sequenceState, numbering.level, levelDefinitions, instance.overrides);
|
|
239
|
+
const effectiveLevelDefs = levelDefinition.isLegalNumbering ? new Map(Array.from(levelDefinitions.entries()).map(([k, v]) => [k, { ...v, format: "decimal" }])) : levelDefinitions;
|
|
240
|
+
const text = renderLevelText(levelDefinition.text, sequenceState.counters, effectiveLevelDefs);
|
|
241
|
+
if (text === null) return null;
|
|
242
|
+
return { text, suffix: levelDefinition.suffix };
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
resolve(numbering) {
|
|
246
|
+
const result = resolveInternal(numbering);
|
|
247
|
+
return result?.text ?? null;
|
|
248
|
+
},
|
|
249
|
+
resolveDetailed(numbering) {
|
|
250
|
+
return resolveInternal(numbering);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function getSequenceState(states, numberingInstanceId) {
|
|
255
|
+
const existing = states.get(numberingInstanceId);
|
|
256
|
+
if (existing) {
|
|
257
|
+
return existing;
|
|
258
|
+
}
|
|
259
|
+
const created = {
|
|
260
|
+
counters: [],
|
|
261
|
+
lastLevel: null
|
|
262
|
+
};
|
|
263
|
+
states.set(numberingInstanceId, created);
|
|
264
|
+
return created;
|
|
265
|
+
}
|
|
266
|
+
function advanceSequence(state, currentLevel, levelDefinitions, overrides) {
|
|
267
|
+
if (state.lastLevel !== null && currentLevel <= state.lastLevel) {
|
|
268
|
+
state.counters.length = currentLevel + 1;
|
|
269
|
+
}
|
|
270
|
+
const startAt = getLevelStartAt(currentLevel, levelDefinitions, overrides);
|
|
271
|
+
const currentValue = state.counters[currentLevel];
|
|
272
|
+
state.counters[currentLevel] = currentValue === void 0 ? startAt : currentValue + 1;
|
|
273
|
+
state.lastLevel = currentLevel;
|
|
274
|
+
}
|
|
275
|
+
function getLevelStartAt(level, levelDefinitions, overrides) {
|
|
276
|
+
const override = overrides.find((entry) => entry.level === level);
|
|
277
|
+
if (override?.startAt !== void 0) {
|
|
278
|
+
return override.startAt;
|
|
279
|
+
}
|
|
280
|
+
return levelDefinitions.get(level)?.startAt ?? DEFAULT_START_AT;
|
|
281
|
+
}
|
|
282
|
+
function renderLevelText(text, counters, levelDefinitions) {
|
|
283
|
+
if (!text) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
if (!text.includes("%")) {
|
|
287
|
+
return text;
|
|
288
|
+
}
|
|
289
|
+
const rendered = text.replace(/%([1-9])/g, (_match, token) => {
|
|
290
|
+
const level = Number.parseInt(token, 10) - 1;
|
|
291
|
+
const counter = counters[level];
|
|
292
|
+
if (counter === void 0) {
|
|
293
|
+
return "";
|
|
294
|
+
}
|
|
295
|
+
const format = levelDefinitions.get(level)?.format ?? "decimal";
|
|
296
|
+
return formatCounter(counter, format);
|
|
297
|
+
});
|
|
298
|
+
return rendered.trim().length > 0 ? rendered : null;
|
|
299
|
+
}
|
|
300
|
+
function formatCounter(value, format) {
|
|
301
|
+
switch (format) {
|
|
302
|
+
case "decimal":
|
|
303
|
+
return String(value);
|
|
304
|
+
case "decimalZero":
|
|
305
|
+
return String(value).padStart(2, "0");
|
|
306
|
+
case "upperLetter":
|
|
307
|
+
return toAlphabetic(value).toUpperCase();
|
|
308
|
+
case "lowerLetter":
|
|
309
|
+
return toAlphabetic(value).toLowerCase();
|
|
310
|
+
case "upperRoman":
|
|
311
|
+
return toRoman(value).toUpperCase();
|
|
312
|
+
case "lowerRoman":
|
|
313
|
+
return toRoman(value).toLowerCase();
|
|
314
|
+
case "none":
|
|
315
|
+
return "";
|
|
316
|
+
default:
|
|
317
|
+
return String(value);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function toAlphabetic(value) {
|
|
321
|
+
if (value <= 0) {
|
|
322
|
+
return String(value);
|
|
323
|
+
}
|
|
324
|
+
let remainder = value;
|
|
325
|
+
let result = "";
|
|
326
|
+
while (remainder > 0) {
|
|
327
|
+
remainder -= 1;
|
|
328
|
+
result = String.fromCharCode(65 + remainder % 26) + result;
|
|
329
|
+
remainder = Math.floor(remainder / 26);
|
|
330
|
+
}
|
|
331
|
+
return result;
|
|
332
|
+
}
|
|
333
|
+
function toRoman(value) {
|
|
334
|
+
if (value <= 0 || value >= 4e3) {
|
|
335
|
+
return String(value);
|
|
336
|
+
}
|
|
337
|
+
const numerals = [
|
|
338
|
+
[1e3, "M"],
|
|
339
|
+
[900, "CM"],
|
|
340
|
+
[500, "D"],
|
|
341
|
+
[400, "CD"],
|
|
342
|
+
[100, "C"],
|
|
343
|
+
[90, "XC"],
|
|
344
|
+
[50, "L"],
|
|
345
|
+
[40, "XL"],
|
|
346
|
+
[10, "X"],
|
|
347
|
+
[9, "IX"],
|
|
348
|
+
[5, "V"],
|
|
349
|
+
[4, "IV"],
|
|
350
|
+
[1, "I"]
|
|
351
|
+
];
|
|
352
|
+
let remaining = value;
|
|
353
|
+
let result = "";
|
|
354
|
+
for (const [amount, numeral] of numerals) {
|
|
355
|
+
while (remaining >= amount) {
|
|
356
|
+
remaining -= amount;
|
|
357
|
+
result += numeral;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return result;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// src/runtime/surface-projection.ts
|
|
364
|
+
function createEditorSurfaceSnapshot(document, _selection, activeStory = { kind: "main" }) {
|
|
365
|
+
const root = normalizeDocumentRoot({
|
|
366
|
+
type: "doc",
|
|
367
|
+
children: [...getStoryBlocks(document, activeStory)]
|
|
368
|
+
});
|
|
369
|
+
const blocks = [];
|
|
370
|
+
const lockedFragmentIds = [];
|
|
371
|
+
const numberingPrefixResolver = createNumberingPrefixResolver(document.numbering);
|
|
372
|
+
let cursor = 0;
|
|
373
|
+
const counters = {
|
|
374
|
+
paragraph: 0,
|
|
375
|
+
table: 0,
|
|
376
|
+
opaque: 0,
|
|
377
|
+
sdt: 0,
|
|
378
|
+
customXml: 0,
|
|
379
|
+
altChunk: 0
|
|
380
|
+
};
|
|
381
|
+
for (let index = 0; index < root.children.length; index += 1) {
|
|
382
|
+
const surfaceBlock = createSurfaceBlock(
|
|
383
|
+
root.children[index],
|
|
384
|
+
document,
|
|
385
|
+
cursor,
|
|
386
|
+
counters,
|
|
387
|
+
numberingPrefixResolver
|
|
388
|
+
);
|
|
389
|
+
blocks.push(surfaceBlock.block);
|
|
390
|
+
lockedFragmentIds.push(...surfaceBlock.lockedFragmentIds);
|
|
391
|
+
cursor = surfaceBlock.nextCursor;
|
|
392
|
+
if (index < root.children.length - 1 && root.children[index + 1]?.type === "paragraph") {
|
|
393
|
+
cursor += 1;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
const secondaryStories = createSecondaryStorySurfaces(document);
|
|
397
|
+
return {
|
|
398
|
+
storySize: cursor,
|
|
399
|
+
plainText: createPlainText(blocks),
|
|
400
|
+
blocks,
|
|
401
|
+
lockedFragmentIds,
|
|
402
|
+
secondaryStories
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
function createSurfaceBlock(block, document, cursor, counters, numberingPrefixResolver) {
|
|
406
|
+
if (block.type === "opaque_block") {
|
|
407
|
+
const fragment = getOpaqueFragment(document.preservation, block.fragmentId);
|
|
408
|
+
const descriptor = fragment ? describeOpaqueFragment(fragment) : null;
|
|
409
|
+
const blockId = `opaque-${counters.opaque}`;
|
|
410
|
+
counters.opaque += 1;
|
|
411
|
+
return {
|
|
412
|
+
block: {
|
|
413
|
+
blockId,
|
|
414
|
+
kind: "opaque_block",
|
|
415
|
+
from: cursor,
|
|
416
|
+
to: cursor + 1,
|
|
417
|
+
fragmentId: block.fragmentId,
|
|
418
|
+
warningId: block.warningId,
|
|
419
|
+
label: descriptor?.label ?? "Unsupported OOXML fragment",
|
|
420
|
+
detail: descriptor?.detail ?? "Locked whole-unit to keep unsupported OOXML intact through export.",
|
|
421
|
+
state: "locked-preserve-only"
|
|
422
|
+
},
|
|
423
|
+
lockedFragmentIds: [block.fragmentId],
|
|
424
|
+
nextCursor: cursor + 1
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
if (block.type === "table") {
|
|
428
|
+
const tableIndex = counters.table;
|
|
429
|
+
counters.table += 1;
|
|
430
|
+
return createTableBlock(
|
|
431
|
+
tableIndex,
|
|
432
|
+
block,
|
|
433
|
+
document,
|
|
434
|
+
cursor,
|
|
435
|
+
counters,
|
|
436
|
+
numberingPrefixResolver
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
if (block.type === "sdt") {
|
|
440
|
+
const sdtIndex = counters.sdt;
|
|
441
|
+
counters.sdt += 1;
|
|
442
|
+
return createSdtBlock(
|
|
443
|
+
sdtIndex,
|
|
444
|
+
block,
|
|
445
|
+
document,
|
|
446
|
+
cursor,
|
|
447
|
+
counters,
|
|
448
|
+
numberingPrefixResolver
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
if (block.type === "custom_xml") {
|
|
452
|
+
const blockId = `custom-xml-${counters.customXml}`;
|
|
453
|
+
counters.customXml += 1;
|
|
454
|
+
return {
|
|
455
|
+
block: {
|
|
456
|
+
blockId,
|
|
457
|
+
kind: "opaque_block",
|
|
458
|
+
from: cursor,
|
|
459
|
+
to: cursor + 1,
|
|
460
|
+
fragmentId: blockId,
|
|
461
|
+
warningId: blockId,
|
|
462
|
+
label: "Custom XML block",
|
|
463
|
+
detail: block.uri || block.element ? `Custom XML wrapper ${[block.element, block.uri].filter(Boolean).join(" ")} preserved as a read-only block.` : "Custom XML wrapper preserved as a read-only block.",
|
|
464
|
+
state: "locked-preserve-only"
|
|
465
|
+
},
|
|
466
|
+
lockedFragmentIds: [],
|
|
467
|
+
nextCursor: cursor + 1
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
if (block.type === "alt_chunk") {
|
|
471
|
+
const blockId = `alt-chunk-${counters.altChunk}`;
|
|
472
|
+
counters.altChunk += 1;
|
|
473
|
+
return {
|
|
474
|
+
block: {
|
|
475
|
+
blockId,
|
|
476
|
+
kind: "opaque_block",
|
|
477
|
+
from: cursor,
|
|
478
|
+
to: cursor + 1,
|
|
479
|
+
fragmentId: blockId,
|
|
480
|
+
warningId: blockId,
|
|
481
|
+
label: "AltChunk import",
|
|
482
|
+
detail: `Alternate content import remains read-only through relationship ${block.relationshipId}.`,
|
|
483
|
+
state: "locked-preserve-only"
|
|
484
|
+
},
|
|
485
|
+
lockedFragmentIds: [],
|
|
486
|
+
nextCursor: cursor + 1
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
if (block.type === "section_break") {
|
|
490
|
+
const blockId = `section-break-${counters.opaque}`;
|
|
491
|
+
counters.opaque += 1;
|
|
492
|
+
return {
|
|
493
|
+
block: {
|
|
494
|
+
blockId,
|
|
495
|
+
kind: "opaque_block",
|
|
496
|
+
from: cursor,
|
|
497
|
+
to: cursor + 1,
|
|
498
|
+
fragmentId: blockId,
|
|
499
|
+
warningId: blockId,
|
|
500
|
+
label: "Section break",
|
|
501
|
+
detail: "Section properties preserved as a read-only boundary.",
|
|
502
|
+
state: "locked-preserve-only"
|
|
503
|
+
},
|
|
504
|
+
lockedFragmentIds: [],
|
|
505
|
+
nextCursor: cursor + 1
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
const paragraphIndex = counters.paragraph;
|
|
509
|
+
counters.paragraph += 1;
|
|
510
|
+
return createParagraphBlock(
|
|
511
|
+
paragraphIndex,
|
|
512
|
+
block,
|
|
513
|
+
document,
|
|
514
|
+
cursor,
|
|
515
|
+
numberingPrefixResolver
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
function createTableBlock(tableIndex, table, document, cursor, counters, numberingPrefixResolver) {
|
|
519
|
+
const lockedFragmentIds = [];
|
|
520
|
+
let innerCursor = cursor;
|
|
521
|
+
const rows = [];
|
|
522
|
+
const rowSpans = computeTableRowSpans(table);
|
|
523
|
+
for (const [rowIndex, row] of table.rows.entries()) {
|
|
524
|
+
const cells = [];
|
|
525
|
+
for (const [cellIndex, cell] of row.cells.entries()) {
|
|
526
|
+
const cellContent = [];
|
|
527
|
+
for (const child of cell.children) {
|
|
528
|
+
const result = createSurfaceBlock(
|
|
529
|
+
child,
|
|
530
|
+
document,
|
|
531
|
+
innerCursor,
|
|
532
|
+
counters,
|
|
533
|
+
numberingPrefixResolver
|
|
534
|
+
);
|
|
535
|
+
cellContent.push(result.block);
|
|
536
|
+
lockedFragmentIds.push(...result.lockedFragmentIds);
|
|
537
|
+
innerCursor = result.nextCursor;
|
|
538
|
+
}
|
|
539
|
+
const cellBorders = resolveCellBorderStyles(cell.borders);
|
|
540
|
+
cells.push({
|
|
541
|
+
gridSpan: cell.gridSpan ?? 1,
|
|
542
|
+
verticalMerge: cell.verticalMerge ?? null,
|
|
543
|
+
colspan: cell.gridSpan ?? 1,
|
|
544
|
+
rowspan: rowSpans.get(`${rowIndex}:${cellIndex}`) ?? 1,
|
|
545
|
+
...cell.shading?.fill ? { backgroundColor: `#${cell.shading.fill}` } : {},
|
|
546
|
+
...cell.verticalAlign ? { verticalAlign: cell.verticalAlign } : {},
|
|
547
|
+
...cellBorders.borderTop ? { borderTop: cellBorders.borderTop } : {},
|
|
548
|
+
...cellBorders.borderRight ? { borderRight: cellBorders.borderRight } : {},
|
|
549
|
+
...cellBorders.borderBottom ? { borderBottom: cellBorders.borderBottom } : {},
|
|
550
|
+
...cellBorders.borderLeft ? { borderLeft: cellBorders.borderLeft } : {},
|
|
551
|
+
content: cellContent
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
rows.push({
|
|
555
|
+
cells,
|
|
556
|
+
...row.gridBefore !== void 0 ? { gridBefore: row.gridBefore } : {},
|
|
557
|
+
...row.gridAfter !== void 0 ? { gridAfter: row.gridAfter } : {},
|
|
558
|
+
...row.height !== void 0 ? { height: row.height } : {},
|
|
559
|
+
...row.heightRule ? { heightRule: row.heightRule } : {},
|
|
560
|
+
...row.isHeader ? { isHeader: row.isHeader } : {}
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
return {
|
|
564
|
+
block: {
|
|
565
|
+
blockId: `table-${tableIndex}`,
|
|
566
|
+
kind: "table",
|
|
567
|
+
from: cursor,
|
|
568
|
+
to: innerCursor,
|
|
569
|
+
styleId: table.styleId,
|
|
570
|
+
gridColumns: table.gridColumns,
|
|
571
|
+
...table.alignment ? { alignment: table.alignment } : {},
|
|
572
|
+
...table.tblLook ? { tblLook: table.tblLook } : {},
|
|
573
|
+
rows
|
|
574
|
+
},
|
|
575
|
+
lockedFragmentIds,
|
|
576
|
+
nextCursor: innerCursor
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
function computeTableRowSpans(table) {
|
|
580
|
+
const positionedRows = table.rows.map((row) => {
|
|
581
|
+
let startColumn = 0;
|
|
582
|
+
return row.cells.map((cell, cellIndex) => {
|
|
583
|
+
const width = cell.gridSpan ?? 1;
|
|
584
|
+
const positionedCell = {
|
|
585
|
+
cell,
|
|
586
|
+
cellIndex,
|
|
587
|
+
startColumn,
|
|
588
|
+
endColumn: startColumn + width - 1
|
|
589
|
+
};
|
|
590
|
+
startColumn += width;
|
|
591
|
+
return positionedCell;
|
|
592
|
+
});
|
|
593
|
+
});
|
|
594
|
+
const rowSpans = /* @__PURE__ */ new Map();
|
|
595
|
+
for (const [rowIndex, row] of positionedRows.entries()) {
|
|
596
|
+
for (const positionedCell of row) {
|
|
597
|
+
if (positionedCell.cell.verticalMerge !== "restart") {
|
|
598
|
+
rowSpans.set(`${rowIndex}:${positionedCell.cellIndex}`, 1);
|
|
599
|
+
continue;
|
|
600
|
+
}
|
|
601
|
+
let rowspan = 1;
|
|
602
|
+
for (let nextRowIndex = rowIndex + 1; nextRowIndex < positionedRows.length; nextRowIndex += 1) {
|
|
603
|
+
const continuedCell = positionedRows[nextRowIndex]?.find(
|
|
604
|
+
(candidate) => candidate.cell.verticalMerge === "continue" && candidate.startColumn === positionedCell.startColumn && candidate.endColumn === positionedCell.endColumn
|
|
605
|
+
);
|
|
606
|
+
if (!continuedCell) {
|
|
607
|
+
break;
|
|
608
|
+
}
|
|
609
|
+
rowspan += 1;
|
|
610
|
+
}
|
|
611
|
+
rowSpans.set(`${rowIndex}:${positionedCell.cellIndex}`, rowspan);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
return rowSpans;
|
|
615
|
+
}
|
|
616
|
+
function resolveCellBorderStyles(borders) {
|
|
617
|
+
if (!borders) return {};
|
|
618
|
+
const result = {};
|
|
619
|
+
const sides = [["top", "borderTop"], ["right", "borderRight"], ["bottom", "borderBottom"], ["left", "borderLeft"]];
|
|
620
|
+
for (const [side, key] of sides) {
|
|
621
|
+
const spec = borders[side];
|
|
622
|
+
if (!spec || spec.value === "none" || spec.value === "nil") continue;
|
|
623
|
+
const width = spec.size ? `${Math.max(1, Math.round(spec.size / 8))}px` : "1px";
|
|
624
|
+
const style = spec.value === "double" ? "double" : spec.value === "dashed" || spec.value === "dashSmallGap" ? "dashed" : spec.value === "dotted" ? "dotted" : "solid";
|
|
625
|
+
const color = spec.color && spec.color !== "auto" ? `#${spec.color}` : "currentColor";
|
|
626
|
+
result[key] = `${width} ${style} ${color}`;
|
|
627
|
+
}
|
|
628
|
+
return result;
|
|
629
|
+
}
|
|
630
|
+
function createSdtBlock(sdtIndex, block, document, cursor, counters, numberingPrefixResolver) {
|
|
631
|
+
const children = [];
|
|
632
|
+
const lockedFragmentIds = [];
|
|
633
|
+
let innerCursor = cursor;
|
|
634
|
+
for (const child of block.children) {
|
|
635
|
+
const result = createSurfaceBlock(
|
|
636
|
+
child,
|
|
637
|
+
document,
|
|
638
|
+
innerCursor,
|
|
639
|
+
counters,
|
|
640
|
+
numberingPrefixResolver
|
|
641
|
+
);
|
|
642
|
+
children.push(result.block);
|
|
643
|
+
lockedFragmentIds.push(...result.lockedFragmentIds);
|
|
644
|
+
innerCursor = result.nextCursor;
|
|
645
|
+
}
|
|
646
|
+
return {
|
|
647
|
+
block: {
|
|
648
|
+
blockId: `sdt-${sdtIndex}`,
|
|
649
|
+
kind: "sdt_block",
|
|
650
|
+
from: cursor,
|
|
651
|
+
to: innerCursor,
|
|
652
|
+
...block.properties.sdtType ? { sdtType: block.properties.sdtType } : {},
|
|
653
|
+
...block.properties.alias ? { alias: block.properties.alias } : {},
|
|
654
|
+
...block.properties.tag ? { tag: block.properties.tag } : {},
|
|
655
|
+
...block.properties.lock ? { lock: block.properties.lock } : {},
|
|
656
|
+
...block.properties.checkbox ? { checkboxChecked: block.properties.checkbox.checked } : {},
|
|
657
|
+
...block.properties.datePicker?.fullDate ? { dateValue: block.properties.datePicker.fullDate } : {},
|
|
658
|
+
...block.properties.dropdownList ? { dropdownItems: block.properties.dropdownList } : {},
|
|
659
|
+
...block.properties.comboBox ? { comboBoxItems: block.properties.comboBox } : {},
|
|
660
|
+
...block.properties.showingPlcHdr ? { showingPlcHdr: true } : {},
|
|
661
|
+
children
|
|
662
|
+
},
|
|
663
|
+
lockedFragmentIds,
|
|
664
|
+
nextCursor: innerCursor
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
function createParagraphBlock(paragraphIndex, paragraph, document, start, numberingPrefixResolver) {
|
|
668
|
+
const accumulator = {
|
|
669
|
+
blockId: `paragraph-${paragraphIndex}`,
|
|
670
|
+
kind: "paragraph",
|
|
671
|
+
from: start,
|
|
672
|
+
to: start,
|
|
673
|
+
...paragraph.styleId ? { styleId: paragraph.styleId } : {},
|
|
674
|
+
...paragraph.numbering ? { numbering: paragraph.numbering } : {},
|
|
675
|
+
...paragraph.numbering ? (() => {
|
|
676
|
+
const detailed = numberingPrefixResolver.resolveDetailed(paragraph.numbering);
|
|
677
|
+
return detailed ? {
|
|
678
|
+
numberingPrefix: detailed.text,
|
|
679
|
+
...detailed.suffix ? { numberingSuffix: detailed.suffix } : {}
|
|
680
|
+
} : {};
|
|
681
|
+
})() : {},
|
|
682
|
+
...paragraph.alignment ? { alignment: paragraph.alignment } : {},
|
|
683
|
+
...paragraph.spacing ? { spacing: paragraph.spacing } : {},
|
|
684
|
+
...paragraph.contextualSpacing !== void 0 ? { contextualSpacing: paragraph.contextualSpacing } : {},
|
|
685
|
+
...paragraph.indentation ? { indentation: paragraph.indentation } : {},
|
|
686
|
+
...paragraph.borders ? { borders: paragraph.borders } : {},
|
|
687
|
+
...paragraph.shading ? { shading: paragraph.shading } : {},
|
|
688
|
+
...paragraph.tabStops && paragraph.tabStops.length > 0 ? { tabStops: paragraph.tabStops.map((tabStop) => toSurfaceTabStop(tabStop)) } : {},
|
|
689
|
+
...paragraph.keepNext ? { keepNext: true } : {},
|
|
690
|
+
...paragraph.keepLines ? { keepLines: true } : {},
|
|
691
|
+
...paragraph.pageBreakBefore ? { pageBreakBefore: true } : {},
|
|
692
|
+
...paragraph.outlineLevel !== void 0 ? { outlineLevel: paragraph.outlineLevel } : {},
|
|
693
|
+
...paragraph.bidi ? { bidi: true } : {},
|
|
694
|
+
...paragraph.suppressLineNumbers ? { suppressLineNumbers: true } : {},
|
|
695
|
+
segments: []
|
|
696
|
+
};
|
|
697
|
+
const lockedFragmentIds = [];
|
|
698
|
+
let cursor = start;
|
|
699
|
+
const children = Array.isArray(paragraph.children) ? paragraph.children : [];
|
|
700
|
+
for (const child of children) {
|
|
701
|
+
const result = appendInlineSegments(accumulator, child, document, cursor);
|
|
702
|
+
cursor = result.nextCursor;
|
|
703
|
+
lockedFragmentIds.push(...result.lockedFragmentIds);
|
|
704
|
+
}
|
|
705
|
+
accumulator.to = cursor;
|
|
706
|
+
return {
|
|
707
|
+
block: accumulator,
|
|
708
|
+
nextCursor: cursor,
|
|
709
|
+
lockedFragmentIds
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
function appendInlineSegments(paragraph, node, document, start, hyperlinkHref) {
|
|
713
|
+
switch (node.type) {
|
|
714
|
+
case "text":
|
|
715
|
+
paragraph.segments.push({
|
|
716
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
717
|
+
kind: "text",
|
|
718
|
+
from: start,
|
|
719
|
+
to: start + Array.from(node.text).length,
|
|
720
|
+
text: node.text,
|
|
721
|
+
...node.marks ? (() => {
|
|
722
|
+
const result = cloneMarks(node.marks);
|
|
723
|
+
return {
|
|
724
|
+
...result.marks.length > 0 ? { marks: result.marks } : {},
|
|
725
|
+
...result.markAttrs ? { markAttrs: result.markAttrs } : {}
|
|
726
|
+
};
|
|
727
|
+
})() : {},
|
|
728
|
+
...hyperlinkHref ? { hyperlinkHref } : {}
|
|
729
|
+
});
|
|
730
|
+
return { nextCursor: start + Array.from(node.text).length, lockedFragmentIds: [] };
|
|
731
|
+
case "tab":
|
|
732
|
+
paragraph.segments.push({
|
|
733
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
734
|
+
kind: "tab",
|
|
735
|
+
from: start,
|
|
736
|
+
to: start + 1,
|
|
737
|
+
...hyperlinkHref ? { hyperlinkHref } : {}
|
|
738
|
+
});
|
|
739
|
+
return { nextCursor: start + 1, lockedFragmentIds: [] };
|
|
740
|
+
case "hard_break":
|
|
741
|
+
paragraph.segments.push({
|
|
742
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
743
|
+
kind: "hard_break",
|
|
744
|
+
from: start,
|
|
745
|
+
to: start + 1,
|
|
746
|
+
...hyperlinkHref ? { hyperlinkHref } : {}
|
|
747
|
+
});
|
|
748
|
+
return { nextCursor: start + 1, lockedFragmentIds: [] };
|
|
749
|
+
case "hyperlink": {
|
|
750
|
+
let cursor = start;
|
|
751
|
+
for (const child of node.children) {
|
|
752
|
+
const result = appendInlineSegments(paragraph, child, document, cursor, node.href);
|
|
753
|
+
cursor = result.nextCursor;
|
|
754
|
+
}
|
|
755
|
+
return { nextCursor: cursor, lockedFragmentIds: [] };
|
|
756
|
+
}
|
|
757
|
+
case "image":
|
|
758
|
+
paragraph.segments.push({
|
|
759
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
760
|
+
kind: "image",
|
|
761
|
+
from: start,
|
|
762
|
+
to: start + 1,
|
|
763
|
+
mediaId: node.mediaId,
|
|
764
|
+
altText: node.altText,
|
|
765
|
+
state: hasMediaItem(document.media, node.mediaId) ? "editable" : "missing",
|
|
766
|
+
...node.display ? { display: node.display } : {},
|
|
767
|
+
detail: node.display === "floating" ? createFloatingImageDetail(node.altText, node.floating) : node.altText ? `Alt text ${node.altText}.` : "Inline image remains a whole-unit render surface."
|
|
768
|
+
});
|
|
769
|
+
return { nextCursor: start + 1, lockedFragmentIds: [] };
|
|
770
|
+
case "opaque_inline": {
|
|
771
|
+
const fragment = getOpaqueFragment(document.preservation, node.fragmentId);
|
|
772
|
+
const descriptor = fragment ? describeOpaqueFragment(fragment) : null;
|
|
773
|
+
const preview = fragment ? describePreservedInlinePreview(fragment.payloadReference) : null;
|
|
774
|
+
paragraph.segments.push({
|
|
775
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
776
|
+
kind: "opaque_inline",
|
|
777
|
+
from: start,
|
|
778
|
+
to: start + 1,
|
|
779
|
+
fragmentId: node.fragmentId,
|
|
780
|
+
warningId: node.warningId,
|
|
781
|
+
label: preview?.label ?? descriptor?.label ?? "Unsupported inline OOXML",
|
|
782
|
+
detail: preview?.detail ?? descriptor?.detail ?? "Locked whole-unit to keep unsupported inline OOXML intact through export.",
|
|
783
|
+
...preview?.presentation ? { presentation: preview.presentation } : {},
|
|
784
|
+
state: "locked-preserve-only"
|
|
785
|
+
});
|
|
786
|
+
return { nextCursor: start + 1, lockedFragmentIds: [node.fragmentId] };
|
|
787
|
+
}
|
|
788
|
+
case "chart_preview":
|
|
789
|
+
return appendComplexPreviewSegment(paragraph, node, start, "Embedded chart", createChartDetail(node));
|
|
790
|
+
case "smartart_preview":
|
|
791
|
+
return appendComplexPreviewSegment(paragraph, node, start, "SmartArt diagram", createSmartArtDetail(node));
|
|
792
|
+
case "shape":
|
|
793
|
+
return appendComplexPreviewSegment(
|
|
794
|
+
paragraph,
|
|
795
|
+
node,
|
|
796
|
+
start,
|
|
797
|
+
node.isTextBox ? "Text box" : "Drawing shape",
|
|
798
|
+
createShapeDetail(node)
|
|
799
|
+
);
|
|
800
|
+
case "wordart":
|
|
801
|
+
return appendComplexPreviewSegment(paragraph, node, start, "WordArt", createWordArtDetail(node));
|
|
802
|
+
case "vml_shape":
|
|
803
|
+
return appendComplexPreviewSegment(paragraph, node, start, "Legacy VML drawing", createVmlDetail(node));
|
|
804
|
+
case "symbol":
|
|
805
|
+
paragraph.segments.push({
|
|
806
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
807
|
+
kind: "text",
|
|
808
|
+
from: start,
|
|
809
|
+
to: start + 1,
|
|
810
|
+
text: node.char ? String.fromCodePoint(parseInt(node.char, 16)) : "\uFFFD"
|
|
811
|
+
});
|
|
812
|
+
return { nextCursor: start + 1, lockedFragmentIds: [] };
|
|
813
|
+
case "column_break":
|
|
814
|
+
paragraph.segments.push({
|
|
815
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
816
|
+
kind: "opaque_inline",
|
|
817
|
+
from: start,
|
|
818
|
+
to: start + 1,
|
|
819
|
+
fragmentId: "",
|
|
820
|
+
warningId: "",
|
|
821
|
+
label: "Column break",
|
|
822
|
+
detail: "Column break marker preserved for export.",
|
|
823
|
+
state: "locked-preserve-only"
|
|
824
|
+
});
|
|
825
|
+
return { nextCursor: start + 1, lockedFragmentIds: [] };
|
|
826
|
+
case "footnote_ref":
|
|
827
|
+
paragraph.segments.push({
|
|
828
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
829
|
+
kind: "note_ref",
|
|
830
|
+
from: start,
|
|
831
|
+
to: start + 1,
|
|
832
|
+
noteKind: node.noteKind ?? "footnote",
|
|
833
|
+
noteId: node.noteId ?? "",
|
|
834
|
+
label: node.noteId ?? "*"
|
|
835
|
+
});
|
|
836
|
+
return { nextCursor: start + 1, lockedFragmentIds: [] };
|
|
837
|
+
case "field": {
|
|
838
|
+
const isSupportedField = node.fieldFamily === "REF" || node.fieldFamily === "PAGEREF" || node.fieldFamily === "NOTEREF" || node.fieldFamily === "TOC";
|
|
839
|
+
if (node.children && node.children.length > 0) {
|
|
840
|
+
let cursor = start;
|
|
841
|
+
const lockedIds = [];
|
|
842
|
+
for (const child of node.children) {
|
|
843
|
+
const result = appendInlineSegments(paragraph, child, document, cursor);
|
|
844
|
+
cursor = result.nextCursor;
|
|
845
|
+
lockedIds.push(...result.lockedFragmentIds);
|
|
846
|
+
}
|
|
847
|
+
return { nextCursor: cursor, lockedFragmentIds: lockedIds };
|
|
848
|
+
}
|
|
849
|
+
if (isSupportedField) {
|
|
850
|
+
const fieldLabel = node.fieldFamily === "TOC" ? "Table of Contents" : `${node.fieldFamily ?? "Field"}: ${node.fieldTarget ?? node.instruction.trim()}`;
|
|
851
|
+
paragraph.segments.push({
|
|
852
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
853
|
+
kind: "field_ref",
|
|
854
|
+
from: start,
|
|
855
|
+
to: start + 1,
|
|
856
|
+
fieldFamily: node.fieldFamily,
|
|
857
|
+
fieldTarget: node.fieldTarget,
|
|
858
|
+
instruction: node.instruction,
|
|
859
|
+
refreshStatus: node.refreshStatus ?? "stale",
|
|
860
|
+
label: fieldLabel
|
|
861
|
+
});
|
|
862
|
+
return { nextCursor: start + 1, lockedFragmentIds: [] };
|
|
863
|
+
}
|
|
864
|
+
paragraph.segments.push({
|
|
865
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
866
|
+
kind: "opaque_inline",
|
|
867
|
+
from: start,
|
|
868
|
+
to: start + 1,
|
|
869
|
+
fragmentId: "",
|
|
870
|
+
warningId: "",
|
|
871
|
+
label: "Field",
|
|
872
|
+
detail: `Preserve-only field: ${node.instruction.trim()}`,
|
|
873
|
+
state: "locked-preserve-only"
|
|
874
|
+
});
|
|
875
|
+
return { nextCursor: start + 1, lockedFragmentIds: [] };
|
|
876
|
+
}
|
|
877
|
+
case "bookmark_start":
|
|
878
|
+
case "bookmark_end":
|
|
879
|
+
return { nextCursor: start, lockedFragmentIds: [] };
|
|
880
|
+
default:
|
|
881
|
+
return { nextCursor: start + 1, lockedFragmentIds: [] };
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
function appendComplexPreviewSegment(paragraph, node, start, label, detail) {
|
|
885
|
+
paragraph.segments.push({
|
|
886
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
887
|
+
kind: "opaque_inline",
|
|
888
|
+
from: start,
|
|
889
|
+
to: start + 1,
|
|
890
|
+
fragmentId: `complex:${label.replace(/\s/g, "-").toLowerCase()}:${start}`,
|
|
891
|
+
warningId: `warning:complex-preview:${start}`,
|
|
892
|
+
label,
|
|
893
|
+
detail,
|
|
894
|
+
state: "locked-preserve-only"
|
|
895
|
+
});
|
|
896
|
+
return { nextCursor: start + 1, lockedFragmentIds: [] };
|
|
897
|
+
}
|
|
898
|
+
function createChartDetail(node) {
|
|
899
|
+
const parts = ["Embedded chart."];
|
|
900
|
+
if (node.previewMediaId) {
|
|
901
|
+
parts.push(`Preview available via fallback image (${node.previewMediaId}).`);
|
|
902
|
+
} else {
|
|
903
|
+
parts.push("No fallback preview image found; chart data preserved in package.");
|
|
904
|
+
}
|
|
905
|
+
parts.push("Edit in Word to modify chart data. Original DrawingML preserved for lossless export.");
|
|
906
|
+
return parts.join(" ");
|
|
907
|
+
}
|
|
908
|
+
function createSmartArtDetail(node) {
|
|
909
|
+
const parts = ["SmartArt diagram."];
|
|
910
|
+
if (node.previewMediaId) {
|
|
911
|
+
parts.push(`Preview available via fallback image (${node.previewMediaId}).`);
|
|
912
|
+
} else {
|
|
913
|
+
parts.push("No fallback preview image found; diagram structure preserved in package.");
|
|
914
|
+
}
|
|
915
|
+
parts.push("Edit in Word to modify diagram layout and content. Original DrawingML preserved for lossless export.");
|
|
916
|
+
return parts.join(" ");
|
|
917
|
+
}
|
|
918
|
+
function createShapeDetail(node) {
|
|
919
|
+
if (node.isTextBox) {
|
|
920
|
+
const parts2 = ["Text box."];
|
|
921
|
+
if (node.text) parts2.push(`Content: "${node.text}".`);
|
|
922
|
+
parts2.push("Text content is visible; formatting and geometry preserved for export.");
|
|
923
|
+
return parts2.join(" ");
|
|
924
|
+
}
|
|
925
|
+
const parts = ["Drawing shape."];
|
|
926
|
+
if (node.geometry) parts.push(`Geometry: ${node.geometry}.`);
|
|
927
|
+
if (node.text) parts.push(`Text content: "${node.text}".`);
|
|
928
|
+
parts.push("Visual geometry is preview-only. Original DrawingML preserved for export.");
|
|
929
|
+
return parts.join(" ");
|
|
930
|
+
}
|
|
931
|
+
function createWordArtDetail(node) {
|
|
932
|
+
const parts = ["WordArt decorative text."];
|
|
933
|
+
if (node.text) parts.push(`Text: "${node.text}".`);
|
|
934
|
+
if (node.geometry) parts.push(`Effect: ${node.geometry}.`);
|
|
935
|
+
parts.push("Text effect is preview-only. Edit in Word for full formatting. Original DrawingML preserved for export.");
|
|
936
|
+
return parts.join(" ");
|
|
937
|
+
}
|
|
938
|
+
function createVmlDetail(node) {
|
|
939
|
+
const parts = ["Legacy VML drawing."];
|
|
940
|
+
if (node.shapeType) parts.push(`Type: ${node.shapeType}.`);
|
|
941
|
+
if (node.text) parts.push(`Text content: "${node.text}".`);
|
|
942
|
+
parts.push("VML content is preview-only. Edit in Word for full control. Original VML XML preserved for export.");
|
|
943
|
+
return parts.join(" ");
|
|
944
|
+
}
|
|
945
|
+
function createPlainText(blocks) {
|
|
946
|
+
const text = [];
|
|
947
|
+
for (const block of blocks) {
|
|
948
|
+
if (block.kind === "opaque_block") {
|
|
949
|
+
if (block.fragmentId.startsWith("preview:")) {
|
|
950
|
+
continue;
|
|
951
|
+
}
|
|
952
|
+
text.push("\uFFFA");
|
|
953
|
+
continue;
|
|
954
|
+
}
|
|
955
|
+
if (block.kind === "table") {
|
|
956
|
+
for (const row of block.rows) {
|
|
957
|
+
for (const cell of row.cells) {
|
|
958
|
+
text.push(createPlainText(cell.content));
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
continue;
|
|
962
|
+
}
|
|
963
|
+
if (block.kind === "sdt_block") {
|
|
964
|
+
text.push(createPlainText(block.children));
|
|
965
|
+
continue;
|
|
966
|
+
}
|
|
967
|
+
for (const segment of block.segments) {
|
|
968
|
+
switch (segment.kind) {
|
|
969
|
+
case "text":
|
|
970
|
+
text.push(segment.text);
|
|
971
|
+
break;
|
|
972
|
+
case "tab":
|
|
973
|
+
text.push(" ");
|
|
974
|
+
break;
|
|
975
|
+
case "hard_break":
|
|
976
|
+
text.push("\n");
|
|
977
|
+
break;
|
|
978
|
+
case "image":
|
|
979
|
+
text.push("\uFFFC");
|
|
980
|
+
break;
|
|
981
|
+
case "opaque_inline":
|
|
982
|
+
text.push("\uFFF9");
|
|
983
|
+
break;
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
return text.join("");
|
|
988
|
+
}
|
|
989
|
+
function createSecondaryStorySurfaces(document) {
|
|
990
|
+
const surfaces = [];
|
|
991
|
+
const subParts = document.subParts;
|
|
992
|
+
if (!subParts) {
|
|
993
|
+
return surfaces;
|
|
994
|
+
}
|
|
995
|
+
const numberingPrefixResolver = createNumberingPrefixResolver(document.numbering);
|
|
996
|
+
for (const section of collectSectionContexts(document)) {
|
|
997
|
+
const headerVariants = resolveSectionVariants(
|
|
998
|
+
"header",
|
|
999
|
+
section.index,
|
|
1000
|
+
section.properties?.headerReferences,
|
|
1001
|
+
subParts.headers ?? []
|
|
1002
|
+
);
|
|
1003
|
+
for (const headerVariant of headerVariants) {
|
|
1004
|
+
const target = {
|
|
1005
|
+
kind: "header",
|
|
1006
|
+
relationshipId: headerVariant.relationshipId,
|
|
1007
|
+
variant: headerVariant.variant,
|
|
1008
|
+
sectionIndex: section.index
|
|
1009
|
+
};
|
|
1010
|
+
const header = findHeaderFooterDocumentEntry(document, target);
|
|
1011
|
+
if (!header) {
|
|
1012
|
+
continue;
|
|
1013
|
+
}
|
|
1014
|
+
surfaces.push(
|
|
1015
|
+
createStorySurface(
|
|
1016
|
+
target,
|
|
1017
|
+
`Header \xB7 ${headerVariant.variant}`,
|
|
1018
|
+
header.blocks,
|
|
1019
|
+
document,
|
|
1020
|
+
numberingPrefixResolver
|
|
1021
|
+
)
|
|
1022
|
+
);
|
|
1023
|
+
}
|
|
1024
|
+
const footerVariants = resolveSectionVariants(
|
|
1025
|
+
"footer",
|
|
1026
|
+
section.index,
|
|
1027
|
+
section.properties?.footerReferences,
|
|
1028
|
+
subParts.footers ?? []
|
|
1029
|
+
);
|
|
1030
|
+
for (const footerVariant of footerVariants) {
|
|
1031
|
+
const target = {
|
|
1032
|
+
kind: "footer",
|
|
1033
|
+
relationshipId: footerVariant.relationshipId,
|
|
1034
|
+
variant: footerVariant.variant,
|
|
1035
|
+
sectionIndex: section.index
|
|
1036
|
+
};
|
|
1037
|
+
const footer = findHeaderFooterDocumentEntry(document, target);
|
|
1038
|
+
if (!footer) {
|
|
1039
|
+
continue;
|
|
1040
|
+
}
|
|
1041
|
+
surfaces.push(
|
|
1042
|
+
createStorySurface(
|
|
1043
|
+
target,
|
|
1044
|
+
`Footer \xB7 ${footerVariant.variant}`,
|
|
1045
|
+
footer.blocks,
|
|
1046
|
+
document,
|
|
1047
|
+
numberingPrefixResolver
|
|
1048
|
+
)
|
|
1049
|
+
);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
const footnotes = Object.values(subParts.footnoteCollection?.footnotes ?? {}).sort(compareNoteIds);
|
|
1053
|
+
for (const note of footnotes) {
|
|
1054
|
+
const target = { kind: "footnote", noteId: note.noteId };
|
|
1055
|
+
surfaces.push(createStorySurface(target, `Footnote ${note.noteId}`, note.blocks, document, numberingPrefixResolver));
|
|
1056
|
+
}
|
|
1057
|
+
const endnotes = Object.values(subParts.footnoteCollection?.endnotes ?? {}).sort(compareNoteIds);
|
|
1058
|
+
for (const note of endnotes) {
|
|
1059
|
+
const target = { kind: "endnote", noteId: note.noteId };
|
|
1060
|
+
surfaces.push(createStorySurface(target, `Endnote ${note.noteId}`, note.blocks, document, numberingPrefixResolver));
|
|
1061
|
+
}
|
|
1062
|
+
return surfaces;
|
|
1063
|
+
}
|
|
1064
|
+
function createStorySurface(target, label, blocks, document, numberingPrefixResolver) {
|
|
1065
|
+
const surfaceBlocks = [];
|
|
1066
|
+
let cursor = 0;
|
|
1067
|
+
const counters = {
|
|
1068
|
+
paragraph: 0,
|
|
1069
|
+
table: 0,
|
|
1070
|
+
opaque: 0,
|
|
1071
|
+
sdt: 0,
|
|
1072
|
+
customXml: 0,
|
|
1073
|
+
altChunk: 0
|
|
1074
|
+
};
|
|
1075
|
+
for (let index = 0; index < blocks.length; index += 1) {
|
|
1076
|
+
const surfaceBlock = createSurfaceBlock(
|
|
1077
|
+
blocks[index],
|
|
1078
|
+
document,
|
|
1079
|
+
cursor,
|
|
1080
|
+
counters,
|
|
1081
|
+
numberingPrefixResolver
|
|
1082
|
+
);
|
|
1083
|
+
surfaceBlocks.push(surfaceBlock.block);
|
|
1084
|
+
cursor = surfaceBlock.nextCursor;
|
|
1085
|
+
if (index < blocks.length - 1 && blocks[index + 1]?.type === "paragraph") {
|
|
1086
|
+
cursor += 1;
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
return {
|
|
1090
|
+
target,
|
|
1091
|
+
label,
|
|
1092
|
+
storySize: cursor,
|
|
1093
|
+
blocks: surfaceBlocks
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
function compareNoteIds(left, right) {
|
|
1097
|
+
return Number.parseInt(left.noteId, 10) - Number.parseInt(right.noteId, 10);
|
|
1098
|
+
}
|
|
1099
|
+
function toSurfaceTabStop(tabStop) {
|
|
1100
|
+
return {
|
|
1101
|
+
pos: tabStop.position,
|
|
1102
|
+
...tabStop.align ? { val: tabStop.align } : {},
|
|
1103
|
+
...tabStop.leader ? { leader: tabStop.leader } : {}
|
|
1104
|
+
};
|
|
1105
|
+
}
|
|
1106
|
+
function describePreservedInlinePreview(payloadReference) {
|
|
1107
|
+
if (/\b(?:w:)?proofErr\b/u.test(payloadReference)) {
|
|
1108
|
+
const proofType = /\bw:type="([^"]+)"/u.exec(payloadReference)?.[1];
|
|
1109
|
+
return {
|
|
1110
|
+
label: "Proofing marker",
|
|
1111
|
+
detail: proofType && proofType.trim().length > 0 ? `Word proofing marker (${proofType}) preserved for export safety.` : "Word proofing marker preserved for export safety.",
|
|
1112
|
+
presentation: "quiet-marker"
|
|
1113
|
+
};
|
|
1114
|
+
}
|
|
1115
|
+
if (/\b(?:w:)?lastRenderedPageBreak\b/u.test(payloadReference)) {
|
|
1116
|
+
return {
|
|
1117
|
+
label: "Rendered page break",
|
|
1118
|
+
detail: "Word rendered page-break marker preserved for export safety.",
|
|
1119
|
+
presentation: "quiet-marker"
|
|
1120
|
+
};
|
|
1121
|
+
}
|
|
1122
|
+
if (/\b(?:w:)?permStart\b/u.test(payloadReference)) {
|
|
1123
|
+
const editorGroup = /\bw:edGrp="([^"]+)"/u.exec(payloadReference)?.[1];
|
|
1124
|
+
return {
|
|
1125
|
+
label: "Protected range start",
|
|
1126
|
+
detail: editorGroup && editorGroup.trim().length > 0 ? `Protected range start for ${editorGroup} preserved for export safety.` : "Protected range start preserved for export safety.",
|
|
1127
|
+
presentation: "quiet-marker"
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
if (/\b(?:w:)?permEnd\b/u.test(payloadReference)) {
|
|
1131
|
+
return {
|
|
1132
|
+
label: "Protected range end",
|
|
1133
|
+
detail: "Protected range end preserved for export safety.",
|
|
1134
|
+
presentation: "quiet-marker"
|
|
1135
|
+
};
|
|
1136
|
+
}
|
|
1137
|
+
if (/\b(?:w:)?bookmarkStart\b/u.test(payloadReference)) {
|
|
1138
|
+
const name = /\bw:name="([^"]+)"/u.exec(payloadReference)?.[1];
|
|
1139
|
+
return {
|
|
1140
|
+
label: name ? `Bookmark \xB7 ${name}` : "Bookmark",
|
|
1141
|
+
detail: name ? `Bookmark anchor "${name}" is preserved as a read-only inline token for export safety.` : "Bookmark anchor is preserved as a read-only inline token for export safety."
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
if (/\b(?:w:)?bookmarkEnd\b/u.test(payloadReference)) {
|
|
1145
|
+
return {
|
|
1146
|
+
label: "Bookmark end",
|
|
1147
|
+
detail: "Bookmark end marker is preserved as a read-only inline token for export safety."
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1150
|
+
if (/\b(?:w:)?fldSimple\b|\b(?:w:)?fldChar\b|\b(?:w:)?instrText\b/u.test(payloadReference)) {
|
|
1151
|
+
const simpleInstruction = /\bw:instr="([^"]*)"/u.exec(payloadReference)?.[1];
|
|
1152
|
+
const complexInstruction = [...payloadReference.matchAll(/<(?:\w+:)?instrText\b[^>]*>([\s\S]*?)<\/(?:\w+:)?instrText>/gu)].map((match) => decodeXmlEntities(match[1] ?? "")).join("").trim();
|
|
1153
|
+
const instruction = (simpleInstruction ?? complexInstruction ?? "").trim();
|
|
1154
|
+
const family = /^([A-Z]+)/i.exec(instruction)?.[1]?.toUpperCase();
|
|
1155
|
+
const label = family === "TOC" ? "Table of Contents field" : family ? `${family} field` : "Field";
|
|
1156
|
+
return {
|
|
1157
|
+
label,
|
|
1158
|
+
detail: instruction.length > 0 ? `Read-only field preserved for export safety. Instruction: ${instruction}.` : "Read-only field preserved for export safety."
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1161
|
+
return null;
|
|
1162
|
+
}
|
|
1163
|
+
function decodeXmlEntities(text) {
|
|
1164
|
+
return text.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&");
|
|
1165
|
+
}
|
|
1166
|
+
function cloneMarks(marks) {
|
|
1167
|
+
const supported = [];
|
|
1168
|
+
const attrs = {};
|
|
1169
|
+
let shadingColor;
|
|
1170
|
+
let highlightColor;
|
|
1171
|
+
for (const mark of marks) {
|
|
1172
|
+
switch (mark.type) {
|
|
1173
|
+
case "bold":
|
|
1174
|
+
case "italic":
|
|
1175
|
+
case "underline":
|
|
1176
|
+
case "strikethrough":
|
|
1177
|
+
case "doubleStrikethrough":
|
|
1178
|
+
case "vanish":
|
|
1179
|
+
case "emboss":
|
|
1180
|
+
case "imprint":
|
|
1181
|
+
case "shadow":
|
|
1182
|
+
supported.push(mark.type);
|
|
1183
|
+
break;
|
|
1184
|
+
case "position":
|
|
1185
|
+
if (mark.val > 0) supported.push("superscript");
|
|
1186
|
+
else if (mark.val < 0) supported.push("subscript");
|
|
1187
|
+
break;
|
|
1188
|
+
case "backgroundColor":
|
|
1189
|
+
shadingColor = mark.color;
|
|
1190
|
+
break;
|
|
1191
|
+
case "highlight":
|
|
1192
|
+
highlightColor = mark.color;
|
|
1193
|
+
break;
|
|
1194
|
+
case "charSpacing":
|
|
1195
|
+
attrs.charSpacing = mark.val;
|
|
1196
|
+
break;
|
|
1197
|
+
case "kerning":
|
|
1198
|
+
attrs.kerning = mark.val;
|
|
1199
|
+
break;
|
|
1200
|
+
case "textFill":
|
|
1201
|
+
attrs.textFill = mark.xml;
|
|
1202
|
+
break;
|
|
1203
|
+
case "fontFamily":
|
|
1204
|
+
attrs.fontFamily = mark.val;
|
|
1205
|
+
break;
|
|
1206
|
+
case "fontSize":
|
|
1207
|
+
attrs.fontSize = mark.val;
|
|
1208
|
+
break;
|
|
1209
|
+
case "textColor":
|
|
1210
|
+
attrs.textColor = mark.color;
|
|
1211
|
+
break;
|
|
1212
|
+
case "smallCaps":
|
|
1213
|
+
supported.push("smallCaps");
|
|
1214
|
+
break;
|
|
1215
|
+
case "allCaps":
|
|
1216
|
+
supported.push("allCaps");
|
|
1217
|
+
break;
|
|
1218
|
+
case "lang":
|
|
1219
|
+
break;
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
if (highlightColor || shadingColor) {
|
|
1223
|
+
attrs.backgroundColor = highlightColor ?? shadingColor;
|
|
1224
|
+
}
|
|
1225
|
+
const hasAttrs = Object.keys(attrs).length > 0;
|
|
1226
|
+
return hasAttrs ? { marks: supported, markAttrs: attrs } : { marks: supported };
|
|
1227
|
+
}
|
|
1228
|
+
function normalizeDocumentRoot(content) {
|
|
1229
|
+
if (content && typeof content === "object" && (content.type === "doc" || content.type === "document_root")) {
|
|
1230
|
+
return content;
|
|
1231
|
+
}
|
|
1232
|
+
if (Array.isArray(content)) {
|
|
1233
|
+
return {
|
|
1234
|
+
type: "doc",
|
|
1235
|
+
children: content.filter(
|
|
1236
|
+
(value) => Boolean(value) && typeof value === "object" && (value.type === "paragraph" || value.type === "table" || value.type === "sdt" || value.type === "custom_xml" || value.type === "alt_chunk" || value.type === "opaque_block")
|
|
1237
|
+
)
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
return {
|
|
1241
|
+
type: "doc",
|
|
1242
|
+
children: [{ type: "paragraph", children: [] }]
|
|
1243
|
+
};
|
|
1244
|
+
}
|
|
1245
|
+
function createFloatingImageDetail(altText, floating) {
|
|
1246
|
+
const parts = [altText ? `Alt text ${altText}.` : "Floating image rendered inline in the editor."];
|
|
1247
|
+
if (floating?.wrap) {
|
|
1248
|
+
parts.push(`Wrap ${floating.wrap}.`);
|
|
1249
|
+
}
|
|
1250
|
+
if (floating?.horizontalPosition?.align || floating?.horizontalPosition?.offset !== void 0) {
|
|
1251
|
+
parts.push(
|
|
1252
|
+
`Horizontal ${floating.horizontalPosition.align ?? floating.horizontalPosition.offset}.`
|
|
1253
|
+
);
|
|
1254
|
+
}
|
|
1255
|
+
if (floating?.verticalPosition?.align || floating?.verticalPosition?.offset !== void 0) {
|
|
1256
|
+
parts.push(
|
|
1257
|
+
`Vertical ${floating.verticalPosition.align ?? floating.verticalPosition.offset}.`
|
|
1258
|
+
);
|
|
1259
|
+
}
|
|
1260
|
+
return parts.join(" ");
|
|
1261
|
+
}
|
|
1262
|
+
function hasMediaItem(media, mediaId) {
|
|
1263
|
+
return mediaId in media.items;
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
export {
|
|
1267
|
+
resolveSectionVariants,
|
|
1268
|
+
sectionSupportsStoryTarget,
|
|
1269
|
+
normalizeHeaderFooterTarget,
|
|
1270
|
+
storyTargetKey,
|
|
1271
|
+
getStoryBlocks,
|
|
1272
|
+
replaceStoryBlocks,
|
|
1273
|
+
createEditorSurfaceSnapshot
|
|
1274
|
+
};
|
|
1275
|
+
//# sourceMappingURL=chunk-EILUG3VB.js.map
|