@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,2023 @@
|
|
|
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/core/commands/image-commands.ts
|
|
21
|
+
var image_commands_exports = {};
|
|
22
|
+
__export(image_commands_exports, {
|
|
23
|
+
insertImage: () => insertImage,
|
|
24
|
+
repositionFloatingImage: () => repositionFloatingImage,
|
|
25
|
+
resizeImage: () => resizeImage
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(image_commands_exports);
|
|
28
|
+
|
|
29
|
+
// src/core/schema/text-schema.ts
|
|
30
|
+
function parseTextStory(content) {
|
|
31
|
+
const root = normalizeDocumentRoot(content);
|
|
32
|
+
const firstParagraphNode = root.children.find(isParagraphNode);
|
|
33
|
+
const firstParagraph = firstParagraphNode ? extractParagraphProperties(firstParagraphNode) : cloneParagraphProperties(EMPTY_PARAGRAPH_PROPERTIES);
|
|
34
|
+
const units = [];
|
|
35
|
+
for (let index = 0; index < root.children.length; index += 1) {
|
|
36
|
+
const block = root.children[index];
|
|
37
|
+
const nextBlock = root.children[index + 1];
|
|
38
|
+
if (isParagraphNode(block)) {
|
|
39
|
+
units.push(...flattenInlineNodes(block.children));
|
|
40
|
+
if (isParagraphNode(nextBlock)) {
|
|
41
|
+
units.push({
|
|
42
|
+
kind: "paragraph_break",
|
|
43
|
+
nextParagraph: extractParagraphProperties(nextBlock)
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (block.type !== "opaque_block") {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
units.push({
|
|
52
|
+
kind: "opaque_block",
|
|
53
|
+
fragmentId: block.fragmentId,
|
|
54
|
+
warningId: block.warningId,
|
|
55
|
+
...isParagraphNode(nextBlock) ? { nextParagraph: extractParagraphProperties(nextBlock) } : {}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
firstParagraph,
|
|
60
|
+
units,
|
|
61
|
+
size: units.length
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function serializeTextStory(story) {
|
|
65
|
+
const blocks = [];
|
|
66
|
+
let currentParagraph = createParagraph(story.firstParagraph);
|
|
67
|
+
let currentHyperlink;
|
|
68
|
+
let activeTextBuffer;
|
|
69
|
+
const ensureCurrentParagraph = () => {
|
|
70
|
+
if (!currentParagraph) {
|
|
71
|
+
currentParagraph = createParagraph(EMPTY_PARAGRAPH_PROPERTIES);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const flushTextBuffer = () => {
|
|
75
|
+
if (!activeTextBuffer || activeTextBuffer.text.length === 0) {
|
|
76
|
+
activeTextBuffer = void 0;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const textNode = {
|
|
80
|
+
type: "text",
|
|
81
|
+
text: activeTextBuffer.text,
|
|
82
|
+
...activeTextBuffer.marks ? { marks: cloneMarks(activeTextBuffer.marks) } : {}
|
|
83
|
+
};
|
|
84
|
+
ensureCurrentParagraph();
|
|
85
|
+
if (activeTextBuffer.hyperlinkHref) {
|
|
86
|
+
if (!currentHyperlink || currentHyperlink.href !== activeTextBuffer.hyperlinkHref) {
|
|
87
|
+
flushHyperlink();
|
|
88
|
+
currentHyperlink = {
|
|
89
|
+
type: "hyperlink",
|
|
90
|
+
href: activeTextBuffer.hyperlinkHref,
|
|
91
|
+
children: []
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
currentHyperlink.children.push(textNode);
|
|
95
|
+
} else {
|
|
96
|
+
flushHyperlink();
|
|
97
|
+
currentParagraph.children.push(textNode);
|
|
98
|
+
}
|
|
99
|
+
activeTextBuffer = void 0;
|
|
100
|
+
};
|
|
101
|
+
const flushHyperlink = () => {
|
|
102
|
+
if (currentHyperlink) {
|
|
103
|
+
ensureCurrentParagraph();
|
|
104
|
+
currentParagraph.children.push(currentHyperlink);
|
|
105
|
+
currentHyperlink = void 0;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const flushParagraph = () => {
|
|
109
|
+
flushTextBuffer();
|
|
110
|
+
flushHyperlink();
|
|
111
|
+
if (!currentParagraph) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
blocks.push(currentParagraph);
|
|
115
|
+
currentParagraph = void 0;
|
|
116
|
+
};
|
|
117
|
+
const pushInlineNode = (node, hyperlinkHref) => {
|
|
118
|
+
flushTextBuffer();
|
|
119
|
+
ensureCurrentParagraph();
|
|
120
|
+
if (hyperlinkHref) {
|
|
121
|
+
if (!currentHyperlink || currentHyperlink.href !== hyperlinkHref) {
|
|
122
|
+
flushHyperlink();
|
|
123
|
+
currentHyperlink = {
|
|
124
|
+
type: "hyperlink",
|
|
125
|
+
href: hyperlinkHref,
|
|
126
|
+
children: []
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
currentHyperlink.children.push(node);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
flushHyperlink();
|
|
133
|
+
currentParagraph.children.push(node);
|
|
134
|
+
};
|
|
135
|
+
for (const unit of story.units) {
|
|
136
|
+
if (unit.kind === "paragraph_break") {
|
|
137
|
+
flushParagraph();
|
|
138
|
+
currentParagraph = createParagraph(unit.nextParagraph);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (unit.kind === "opaque_block") {
|
|
142
|
+
flushParagraph();
|
|
143
|
+
blocks.push({
|
|
144
|
+
type: "opaque_block",
|
|
145
|
+
fragmentId: unit.fragmentId,
|
|
146
|
+
warningId: unit.warningId
|
|
147
|
+
});
|
|
148
|
+
currentParagraph = unit.nextParagraph ? createParagraph(unit.nextParagraph) : void 0;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (unit.kind === "text") {
|
|
152
|
+
const shouldExtendBuffer = activeTextBuffer && activeTextBuffer.hyperlinkHref === unit.hyperlinkHref && haveEqualMarks(activeTextBuffer.marks, unit.marks);
|
|
153
|
+
if (shouldExtendBuffer && activeTextBuffer) {
|
|
154
|
+
activeTextBuffer.text += unit.value;
|
|
155
|
+
} else {
|
|
156
|
+
flushTextBuffer();
|
|
157
|
+
activeTextBuffer = {
|
|
158
|
+
text: unit.value,
|
|
159
|
+
...unit.marks ? { marks: cloneMarks(unit.marks) } : {},
|
|
160
|
+
...unit.hyperlinkHref ? { hyperlinkHref: unit.hyperlinkHref } : {}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
switch (unit.kind) {
|
|
166
|
+
case "tab":
|
|
167
|
+
pushInlineNode({ type: "tab" }, unit.hyperlinkHref);
|
|
168
|
+
break;
|
|
169
|
+
case "hard_break":
|
|
170
|
+
pushInlineNode({ type: "hard_break" }, unit.hyperlinkHref);
|
|
171
|
+
break;
|
|
172
|
+
case "image":
|
|
173
|
+
pushInlineNode({
|
|
174
|
+
type: "image",
|
|
175
|
+
mediaId: unit.mediaId,
|
|
176
|
+
...unit.altText ? { altText: unit.altText } : {}
|
|
177
|
+
});
|
|
178
|
+
break;
|
|
179
|
+
case "opaque_inline":
|
|
180
|
+
pushInlineNode({
|
|
181
|
+
type: "opaque_inline",
|
|
182
|
+
fragmentId: unit.fragmentId,
|
|
183
|
+
warningId: unit.warningId
|
|
184
|
+
});
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
flushParagraph();
|
|
189
|
+
if (blocks.length === 0) {
|
|
190
|
+
blocks.push(createParagraph(story.firstParagraph));
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
type: "doc",
|
|
194
|
+
children: blocks
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
function cloneStoryUnit(unit) {
|
|
198
|
+
switch (unit.kind) {
|
|
199
|
+
case "text":
|
|
200
|
+
return {
|
|
201
|
+
kind: "text",
|
|
202
|
+
value: unit.value,
|
|
203
|
+
...unit.marks ? { marks: cloneMarks(unit.marks) } : {},
|
|
204
|
+
...unit.hyperlinkHref ? { hyperlinkHref: unit.hyperlinkHref } : {}
|
|
205
|
+
};
|
|
206
|
+
case "tab":
|
|
207
|
+
return {
|
|
208
|
+
kind: "tab",
|
|
209
|
+
...unit.hyperlinkHref ? { hyperlinkHref: unit.hyperlinkHref } : {}
|
|
210
|
+
};
|
|
211
|
+
case "hard_break":
|
|
212
|
+
return {
|
|
213
|
+
kind: "hard_break",
|
|
214
|
+
...unit.hyperlinkHref ? { hyperlinkHref: unit.hyperlinkHref } : {}
|
|
215
|
+
};
|
|
216
|
+
case "image":
|
|
217
|
+
return {
|
|
218
|
+
kind: "image",
|
|
219
|
+
mediaId: unit.mediaId,
|
|
220
|
+
...unit.altText ? { altText: unit.altText } : {}
|
|
221
|
+
};
|
|
222
|
+
case "opaque_inline":
|
|
223
|
+
return {
|
|
224
|
+
kind: "opaque_inline",
|
|
225
|
+
fragmentId: unit.fragmentId,
|
|
226
|
+
warningId: unit.warningId
|
|
227
|
+
};
|
|
228
|
+
case "opaque_block":
|
|
229
|
+
return {
|
|
230
|
+
kind: "opaque_block",
|
|
231
|
+
fragmentId: unit.fragmentId,
|
|
232
|
+
warningId: unit.warningId,
|
|
233
|
+
...unit.nextParagraph ? { nextParagraph: cloneParagraphProperties(unit.nextParagraph) } : {}
|
|
234
|
+
};
|
|
235
|
+
case "paragraph_break":
|
|
236
|
+
return {
|
|
237
|
+
kind: "paragraph_break",
|
|
238
|
+
nextParagraph: cloneParagraphProperties(unit.nextParagraph)
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function cloneParagraphProperties(properties) {
|
|
243
|
+
return {
|
|
244
|
+
...properties.styleId ? { styleId: properties.styleId } : {},
|
|
245
|
+
...properties.numbering ? {
|
|
246
|
+
numbering: {
|
|
247
|
+
numberingInstanceId: properties.numbering.numberingInstanceId,
|
|
248
|
+
level: properties.numbering.level
|
|
249
|
+
}
|
|
250
|
+
} : {}
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
function normalizeDocumentRoot(content) {
|
|
254
|
+
if (isDocumentRootNode(content)) {
|
|
255
|
+
return content;
|
|
256
|
+
}
|
|
257
|
+
if (Array.isArray(content)) {
|
|
258
|
+
return {
|
|
259
|
+
type: "doc",
|
|
260
|
+
children: content.filter(
|
|
261
|
+
(block) => isParagraphNode(block) || isOpaqueBlockNode(block)
|
|
262
|
+
)
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
return {
|
|
266
|
+
type: "doc",
|
|
267
|
+
children: [createEmptyParagraph()]
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
function flattenInlineNodes(nodes, hyperlinkHref) {
|
|
271
|
+
const units = [];
|
|
272
|
+
for (const node of nodes) {
|
|
273
|
+
switch (node.type) {
|
|
274
|
+
case "text":
|
|
275
|
+
for (const character of Array.from(node.text)) {
|
|
276
|
+
units.push({
|
|
277
|
+
kind: "text",
|
|
278
|
+
value: character,
|
|
279
|
+
...node.marks ? { marks: cloneMarks(node.marks) } : {},
|
|
280
|
+
...hyperlinkHref ? { hyperlinkHref } : {}
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
break;
|
|
284
|
+
case "tab":
|
|
285
|
+
units.push({
|
|
286
|
+
kind: "tab",
|
|
287
|
+
...hyperlinkHref ? { hyperlinkHref } : {}
|
|
288
|
+
});
|
|
289
|
+
break;
|
|
290
|
+
case "hard_break":
|
|
291
|
+
units.push({
|
|
292
|
+
kind: "hard_break",
|
|
293
|
+
...hyperlinkHref ? { hyperlinkHref } : {}
|
|
294
|
+
});
|
|
295
|
+
break;
|
|
296
|
+
case "hyperlink":
|
|
297
|
+
units.push(...flattenInlineNodes(node.children, node.href));
|
|
298
|
+
break;
|
|
299
|
+
case "image":
|
|
300
|
+
units.push({
|
|
301
|
+
kind: "image",
|
|
302
|
+
mediaId: node.mediaId,
|
|
303
|
+
...node.altText ? { altText: node.altText } : {}
|
|
304
|
+
});
|
|
305
|
+
break;
|
|
306
|
+
case "opaque_inline":
|
|
307
|
+
units.push({
|
|
308
|
+
kind: "opaque_inline",
|
|
309
|
+
fragmentId: node.fragmentId,
|
|
310
|
+
warningId: node.warningId
|
|
311
|
+
});
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return units;
|
|
316
|
+
}
|
|
317
|
+
function extractParagraphProperties(paragraph) {
|
|
318
|
+
return {
|
|
319
|
+
...paragraph.styleId ? { styleId: paragraph.styleId } : {},
|
|
320
|
+
...paragraph.numbering ? {
|
|
321
|
+
numbering: {
|
|
322
|
+
numberingInstanceId: paragraph.numbering.numberingInstanceId,
|
|
323
|
+
level: paragraph.numbering.level
|
|
324
|
+
}
|
|
325
|
+
} : {}
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function createParagraph(properties) {
|
|
329
|
+
return {
|
|
330
|
+
type: "paragraph",
|
|
331
|
+
...properties.styleId ? { styleId: properties.styleId } : {},
|
|
332
|
+
...properties.numbering ? {
|
|
333
|
+
numbering: {
|
|
334
|
+
numberingInstanceId: properties.numbering.numberingInstanceId,
|
|
335
|
+
level: properties.numbering.level
|
|
336
|
+
}
|
|
337
|
+
} : {},
|
|
338
|
+
children: []
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function createEmptyParagraph() {
|
|
342
|
+
return {
|
|
343
|
+
type: "paragraph",
|
|
344
|
+
children: []
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
var EMPTY_PARAGRAPH_PROPERTIES = {};
|
|
348
|
+
function cloneMarks(marks) {
|
|
349
|
+
return marks.map((mark) => ({ ...mark }));
|
|
350
|
+
}
|
|
351
|
+
function haveEqualMarks(left, right) {
|
|
352
|
+
if (!left && !right) {
|
|
353
|
+
return true;
|
|
354
|
+
}
|
|
355
|
+
if (!left || !right || left.length !== right.length) {
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
return left.every((mark, index) => mark.type === right[index]?.type);
|
|
359
|
+
}
|
|
360
|
+
function isDocumentRootNode(value) {
|
|
361
|
+
return Boolean(value) && typeof value === "object" && value.type === "doc";
|
|
362
|
+
}
|
|
363
|
+
function isParagraphNode(value) {
|
|
364
|
+
return Boolean(value) && typeof value === "object" && value.type === "paragraph";
|
|
365
|
+
}
|
|
366
|
+
function isOpaqueBlockNode(value) {
|
|
367
|
+
return Boolean(value) && typeof value === "object" && value.type === "opaque_block";
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// src/core/selection/mapping.ts
|
|
371
|
+
var DEFAULT_BOUNDARY_ASSOC = {
|
|
372
|
+
start: 1,
|
|
373
|
+
end: -1
|
|
374
|
+
};
|
|
375
|
+
function createRangeAnchor(from, to = from, assoc = DEFAULT_BOUNDARY_ASSOC) {
|
|
376
|
+
return {
|
|
377
|
+
kind: "range",
|
|
378
|
+
range: normalizeRange({ from, to }),
|
|
379
|
+
assoc
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
function normalizeRange(range) {
|
|
383
|
+
return range.from <= range.to ? { from: range.from, to: range.to } : { from: range.to, to: range.from };
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// src/core/state/editor-state.ts
|
|
387
|
+
function createSelectionSnapshot(anchor = 0, head = anchor) {
|
|
388
|
+
return {
|
|
389
|
+
anchor,
|
|
390
|
+
head,
|
|
391
|
+
isCollapsed: anchor === head,
|
|
392
|
+
activeRange: createRangeAnchor(anchor, head, DEFAULT_BOUNDARY_ASSOC)
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// src/preservation/store.ts
|
|
397
|
+
function getOpaqueFragment(store, fragmentId) {
|
|
398
|
+
return normalizeOpaqueFragmentMap(store)[fragmentId];
|
|
399
|
+
}
|
|
400
|
+
function describeOpaqueFragment(fragment) {
|
|
401
|
+
const xml = fragment.payloadReference;
|
|
402
|
+
const detail = createDetail(fragment);
|
|
403
|
+
if (/\b(?:w:)?sectPr\b/u.test(xml)) {
|
|
404
|
+
return {
|
|
405
|
+
featureKey: "sections",
|
|
406
|
+
label: "Section properties",
|
|
407
|
+
detail
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
if (/\b(?:w:)?tbl\b/u.test(xml)) {
|
|
411
|
+
return {
|
|
412
|
+
featureKey: "tables",
|
|
413
|
+
label: "Preserved table structure",
|
|
414
|
+
detail
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
if (/\b(?:w:)?hdr\b|\b(?:w:)?ftr\b/u.test(xml)) {
|
|
418
|
+
return {
|
|
419
|
+
featureKey: "headers-footers",
|
|
420
|
+
label: "Header or footer content",
|
|
421
|
+
detail
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
if (/\b(?:w:)?fldSimple\b|\b(?:w:)?fldChar\b|\b(?:w:)?instrText\b/u.test(xml)) {
|
|
425
|
+
return {
|
|
426
|
+
featureKey: "fields",
|
|
427
|
+
label: "Word field content",
|
|
428
|
+
detail
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
if (/\b(?:w:)?sdt\b/u.test(xml)) {
|
|
432
|
+
return {
|
|
433
|
+
featureKey: "content-controls",
|
|
434
|
+
label: "Content control",
|
|
435
|
+
detail
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
if (/\b(?:w:)?customXml\b/u.test(xml)) {
|
|
439
|
+
return {
|
|
440
|
+
featureKey: "custom-xml",
|
|
441
|
+
label: "Custom XML wrapper",
|
|
442
|
+
detail
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
if (/\b(?:w:)?altChunk\b/u.test(xml)) {
|
|
446
|
+
return {
|
|
447
|
+
featureKey: "alt-chunk",
|
|
448
|
+
label: "Alternate content import",
|
|
449
|
+
detail
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
if (/\b(?:w:)?object\b|\b(?:o:)?OLEObject\b/u.test(xml)) {
|
|
453
|
+
return {
|
|
454
|
+
featureKey: "embedded-objects",
|
|
455
|
+
label: "Embedded object",
|
|
456
|
+
detail
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
if (/\b(?:mc:)?AlternateContent\b/u.test(xml)) {
|
|
460
|
+
return {
|
|
461
|
+
featureKey: "alternate-content",
|
|
462
|
+
label: "Markup compatibility block",
|
|
463
|
+
detail
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
return {
|
|
467
|
+
featureKey: "unknown-ooxml",
|
|
468
|
+
label: "Unsupported OOXML fragment",
|
|
469
|
+
detail
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
function createDetail(fragment) {
|
|
473
|
+
const detail = [
|
|
474
|
+
`Preserved whole-unit from ${fragment.lastKnownRange.from}-${fragment.lastKnownRange.to}.`,
|
|
475
|
+
fragment.packagePartName ? `Part ${fragment.packagePartName}.` : null,
|
|
476
|
+
fragment.relationshipId ? `Relationship ${fragment.relationshipId}.` : null
|
|
477
|
+
].filter(Boolean).join(" ");
|
|
478
|
+
return detail.length > 0 ? detail : "Preserved whole-unit to keep unsupported OOXML intact.";
|
|
479
|
+
}
|
|
480
|
+
function normalizeOpaqueFragmentMap(store) {
|
|
481
|
+
return store && typeof store === "object" && store.opaqueFragments && typeof store.opaqueFragments === "object" ? store.opaqueFragments : {};
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// src/runtime/story-context.ts
|
|
485
|
+
function collectSectionContexts(document) {
|
|
486
|
+
const sections = [];
|
|
487
|
+
let sectionIndex = 0;
|
|
488
|
+
for (const block of document.content.children) {
|
|
489
|
+
if (block.type !== "section_break") {
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
sections.push({
|
|
493
|
+
index: sectionIndex,
|
|
494
|
+
properties: block.sectionProperties
|
|
495
|
+
});
|
|
496
|
+
sectionIndex += 1;
|
|
497
|
+
}
|
|
498
|
+
sections.push({
|
|
499
|
+
index: sectionIndex,
|
|
500
|
+
properties: document.subParts?.finalSectionProperties
|
|
501
|
+
});
|
|
502
|
+
return sections;
|
|
503
|
+
}
|
|
504
|
+
function resolveSectionVariants(kind, sectionIndex, explicitReferences, documents) {
|
|
505
|
+
if (explicitReferences && explicitReferences.length > 0) {
|
|
506
|
+
return explicitReferences.map((ref) => ({
|
|
507
|
+
variant: ref.variant,
|
|
508
|
+
relationshipId: ref.relationshipId
|
|
509
|
+
}));
|
|
510
|
+
}
|
|
511
|
+
return documents.filter(
|
|
512
|
+
(entry) => entry.sectionIndex === void 0 || entry.sectionIndex === sectionIndex
|
|
513
|
+
).map((entry) => ({
|
|
514
|
+
variant: entry.variant,
|
|
515
|
+
relationshipId: entry.relationshipId
|
|
516
|
+
}));
|
|
517
|
+
}
|
|
518
|
+
function findHeaderFooterDocumentEntry(document, target) {
|
|
519
|
+
const documents = target.kind === "header" ? document.subParts?.headers ?? [] : document.subParts?.footers ?? [];
|
|
520
|
+
const matches = documents.filter(
|
|
521
|
+
(entry) => entry.relationshipId === target.relationshipId && entry.variant === target.variant
|
|
522
|
+
);
|
|
523
|
+
if (matches.length === 0) {
|
|
524
|
+
return void 0;
|
|
525
|
+
}
|
|
526
|
+
if (target.sectionIndex !== void 0) {
|
|
527
|
+
return matches.find((entry) => entry.sectionIndex === target.sectionIndex) ?? matches.find((entry) => entry.sectionIndex === void 0) ?? matches[0];
|
|
528
|
+
}
|
|
529
|
+
return matches[0];
|
|
530
|
+
}
|
|
531
|
+
function sectionSupportsStoryTarget(document, sectionIndex, target) {
|
|
532
|
+
if (!findHeaderFooterDocumentEntry(document, target)) {
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
const section = collectSectionContexts(document).find(
|
|
536
|
+
(candidate) => candidate.index === sectionIndex
|
|
537
|
+
);
|
|
538
|
+
if (!section) {
|
|
539
|
+
return false;
|
|
540
|
+
}
|
|
541
|
+
const variants = resolveSectionVariants(
|
|
542
|
+
target.kind,
|
|
543
|
+
sectionIndex,
|
|
544
|
+
target.kind === "header" ? section.properties?.headerReferences : section.properties?.footerReferences,
|
|
545
|
+
target.kind === "header" ? document.subParts?.headers ?? [] : document.subParts?.footers ?? []
|
|
546
|
+
);
|
|
547
|
+
return variants.some(
|
|
548
|
+
(variant) => variant.relationshipId === target.relationshipId && variant.variant === target.variant
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
function normalizeHeaderFooterTarget(document, target, preferredSectionIndex) {
|
|
552
|
+
if (!findHeaderFooterDocumentEntry(document, target)) {
|
|
553
|
+
return void 0;
|
|
554
|
+
}
|
|
555
|
+
if (target.sectionIndex !== void 0) {
|
|
556
|
+
return sectionSupportsStoryTarget(document, target.sectionIndex, target) ? target : void 0;
|
|
557
|
+
}
|
|
558
|
+
const candidateIndexes = collectSectionContexts(document).map((section) => section.index).filter(
|
|
559
|
+
(sectionIndex) => sectionSupportsStoryTarget(document, sectionIndex, target)
|
|
560
|
+
);
|
|
561
|
+
if (candidateIndexes.length === 0) {
|
|
562
|
+
return void 0;
|
|
563
|
+
}
|
|
564
|
+
const resolvedSectionIndex = preferredSectionIndex !== void 0 && candidateIndexes.includes(preferredSectionIndex) ? preferredSectionIndex : candidateIndexes[0];
|
|
565
|
+
return {
|
|
566
|
+
...target,
|
|
567
|
+
sectionIndex: resolvedSectionIndex
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// src/runtime/story-targeting.ts
|
|
572
|
+
function getStoryBlocks(document, target) {
|
|
573
|
+
if (target.kind === "main") {
|
|
574
|
+
return document.content.children;
|
|
575
|
+
}
|
|
576
|
+
const subParts = document.subParts;
|
|
577
|
+
if (!subParts) {
|
|
578
|
+
return [];
|
|
579
|
+
}
|
|
580
|
+
switch (target.kind) {
|
|
581
|
+
case "header": {
|
|
582
|
+
const resolvedTarget = normalizeHeaderFooterTarget(document, target);
|
|
583
|
+
return (resolvedTarget && findHeaderFooterDocumentEntry(document, resolvedTarget)?.blocks) ?? [];
|
|
584
|
+
}
|
|
585
|
+
case "footer": {
|
|
586
|
+
const resolvedTarget = normalizeHeaderFooterTarget(document, target);
|
|
587
|
+
return (resolvedTarget && findHeaderFooterDocumentEntry(document, resolvedTarget)?.blocks) ?? [];
|
|
588
|
+
}
|
|
589
|
+
case "footnote":
|
|
590
|
+
return subParts.footnoteCollection?.footnotes[target.noteId]?.blocks ?? [];
|
|
591
|
+
case "endnote":
|
|
592
|
+
return subParts.footnoteCollection?.endnotes[target.noteId]?.blocks ?? [];
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// src/runtime/numbering-prefix.ts
|
|
597
|
+
var DEFAULT_START_AT = 1;
|
|
598
|
+
function createNumberingPrefixResolver(catalog) {
|
|
599
|
+
const sequenceStates = /* @__PURE__ */ new Map();
|
|
600
|
+
function resolveInternal(numbering) {
|
|
601
|
+
if (!numbering) {
|
|
602
|
+
return null;
|
|
603
|
+
}
|
|
604
|
+
const instance = catalog.instances[numbering.numberingInstanceId];
|
|
605
|
+
if (!instance) {
|
|
606
|
+
return null;
|
|
607
|
+
}
|
|
608
|
+
const definition = catalog.abstractDefinitions[instance.abstractNumberingId];
|
|
609
|
+
if (!definition) {
|
|
610
|
+
return null;
|
|
611
|
+
}
|
|
612
|
+
const levelDefinitions = new Map(
|
|
613
|
+
definition.levels.map((level) => [level.level, level])
|
|
614
|
+
);
|
|
615
|
+
const levelDefinition = levelDefinitions.get(numbering.level);
|
|
616
|
+
if (!levelDefinition || levelDefinition.format === "none") {
|
|
617
|
+
return null;
|
|
618
|
+
}
|
|
619
|
+
const sequenceState = getSequenceState(sequenceStates, numbering.numberingInstanceId);
|
|
620
|
+
advanceSequence(sequenceState, numbering.level, levelDefinitions, instance.overrides);
|
|
621
|
+
const effectiveLevelDefs = levelDefinition.isLegalNumbering ? new Map(Array.from(levelDefinitions.entries()).map(([k, v]) => [k, { ...v, format: "decimal" }])) : levelDefinitions;
|
|
622
|
+
const text = renderLevelText(levelDefinition.text, sequenceState.counters, effectiveLevelDefs);
|
|
623
|
+
if (text === null) return null;
|
|
624
|
+
return { text, suffix: levelDefinition.suffix };
|
|
625
|
+
}
|
|
626
|
+
return {
|
|
627
|
+
resolve(numbering) {
|
|
628
|
+
const result = resolveInternal(numbering);
|
|
629
|
+
return result?.text ?? null;
|
|
630
|
+
},
|
|
631
|
+
resolveDetailed(numbering) {
|
|
632
|
+
return resolveInternal(numbering);
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
function getSequenceState(states, numberingInstanceId) {
|
|
637
|
+
const existing = states.get(numberingInstanceId);
|
|
638
|
+
if (existing) {
|
|
639
|
+
return existing;
|
|
640
|
+
}
|
|
641
|
+
const created = {
|
|
642
|
+
counters: [],
|
|
643
|
+
lastLevel: null
|
|
644
|
+
};
|
|
645
|
+
states.set(numberingInstanceId, created);
|
|
646
|
+
return created;
|
|
647
|
+
}
|
|
648
|
+
function advanceSequence(state, currentLevel, levelDefinitions, overrides) {
|
|
649
|
+
if (state.lastLevel !== null && currentLevel <= state.lastLevel) {
|
|
650
|
+
state.counters.length = currentLevel + 1;
|
|
651
|
+
}
|
|
652
|
+
const startAt = getLevelStartAt(currentLevel, levelDefinitions, overrides);
|
|
653
|
+
const currentValue = state.counters[currentLevel];
|
|
654
|
+
state.counters[currentLevel] = currentValue === void 0 ? startAt : currentValue + 1;
|
|
655
|
+
state.lastLevel = currentLevel;
|
|
656
|
+
}
|
|
657
|
+
function getLevelStartAt(level, levelDefinitions, overrides) {
|
|
658
|
+
const override = overrides.find((entry) => entry.level === level);
|
|
659
|
+
if (override?.startAt !== void 0) {
|
|
660
|
+
return override.startAt;
|
|
661
|
+
}
|
|
662
|
+
return levelDefinitions.get(level)?.startAt ?? DEFAULT_START_AT;
|
|
663
|
+
}
|
|
664
|
+
function renderLevelText(text, counters, levelDefinitions) {
|
|
665
|
+
if (!text) {
|
|
666
|
+
return null;
|
|
667
|
+
}
|
|
668
|
+
if (!text.includes("%")) {
|
|
669
|
+
return text;
|
|
670
|
+
}
|
|
671
|
+
const rendered = text.replace(/%([1-9])/g, (_match, token) => {
|
|
672
|
+
const level = Number.parseInt(token, 10) - 1;
|
|
673
|
+
const counter = counters[level];
|
|
674
|
+
if (counter === void 0) {
|
|
675
|
+
return "";
|
|
676
|
+
}
|
|
677
|
+
const format = levelDefinitions.get(level)?.format ?? "decimal";
|
|
678
|
+
return formatCounter(counter, format);
|
|
679
|
+
});
|
|
680
|
+
return rendered.trim().length > 0 ? rendered : null;
|
|
681
|
+
}
|
|
682
|
+
function formatCounter(value, format) {
|
|
683
|
+
switch (format) {
|
|
684
|
+
case "decimal":
|
|
685
|
+
return String(value);
|
|
686
|
+
case "decimalZero":
|
|
687
|
+
return String(value).padStart(2, "0");
|
|
688
|
+
case "upperLetter":
|
|
689
|
+
return toAlphabetic(value).toUpperCase();
|
|
690
|
+
case "lowerLetter":
|
|
691
|
+
return toAlphabetic(value).toLowerCase();
|
|
692
|
+
case "upperRoman":
|
|
693
|
+
return toRoman(value).toUpperCase();
|
|
694
|
+
case "lowerRoman":
|
|
695
|
+
return toRoman(value).toLowerCase();
|
|
696
|
+
case "none":
|
|
697
|
+
return "";
|
|
698
|
+
default:
|
|
699
|
+
return String(value);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
function toAlphabetic(value) {
|
|
703
|
+
if (value <= 0) {
|
|
704
|
+
return String(value);
|
|
705
|
+
}
|
|
706
|
+
let remainder = value;
|
|
707
|
+
let result = "";
|
|
708
|
+
while (remainder > 0) {
|
|
709
|
+
remainder -= 1;
|
|
710
|
+
result = String.fromCharCode(65 + remainder % 26) + result;
|
|
711
|
+
remainder = Math.floor(remainder / 26);
|
|
712
|
+
}
|
|
713
|
+
return result;
|
|
714
|
+
}
|
|
715
|
+
function toRoman(value) {
|
|
716
|
+
if (value <= 0 || value >= 4e3) {
|
|
717
|
+
return String(value);
|
|
718
|
+
}
|
|
719
|
+
const numerals = [
|
|
720
|
+
[1e3, "M"],
|
|
721
|
+
[900, "CM"],
|
|
722
|
+
[500, "D"],
|
|
723
|
+
[400, "CD"],
|
|
724
|
+
[100, "C"],
|
|
725
|
+
[90, "XC"],
|
|
726
|
+
[50, "L"],
|
|
727
|
+
[40, "XL"],
|
|
728
|
+
[10, "X"],
|
|
729
|
+
[9, "IX"],
|
|
730
|
+
[5, "V"],
|
|
731
|
+
[4, "IV"],
|
|
732
|
+
[1, "I"]
|
|
733
|
+
];
|
|
734
|
+
let remaining = value;
|
|
735
|
+
let result = "";
|
|
736
|
+
for (const [amount, numeral] of numerals) {
|
|
737
|
+
while (remaining >= amount) {
|
|
738
|
+
remaining -= amount;
|
|
739
|
+
result += numeral;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
return result;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
// src/runtime/surface-projection.ts
|
|
746
|
+
function createEditorSurfaceSnapshot(document, _selection, activeStory = { kind: "main" }) {
|
|
747
|
+
const root = normalizeDocumentRoot2({
|
|
748
|
+
type: "doc",
|
|
749
|
+
children: [...getStoryBlocks(document, activeStory)]
|
|
750
|
+
});
|
|
751
|
+
const blocks = [];
|
|
752
|
+
const lockedFragmentIds = [];
|
|
753
|
+
const numberingPrefixResolver = createNumberingPrefixResolver(document.numbering);
|
|
754
|
+
let cursor = 0;
|
|
755
|
+
const counters = {
|
|
756
|
+
paragraph: 0,
|
|
757
|
+
table: 0,
|
|
758
|
+
opaque: 0,
|
|
759
|
+
sdt: 0,
|
|
760
|
+
customXml: 0,
|
|
761
|
+
altChunk: 0
|
|
762
|
+
};
|
|
763
|
+
for (let index = 0; index < root.children.length; index += 1) {
|
|
764
|
+
const surfaceBlock = createSurfaceBlock(
|
|
765
|
+
root.children[index],
|
|
766
|
+
document,
|
|
767
|
+
cursor,
|
|
768
|
+
counters,
|
|
769
|
+
numberingPrefixResolver
|
|
770
|
+
);
|
|
771
|
+
blocks.push(surfaceBlock.block);
|
|
772
|
+
lockedFragmentIds.push(...surfaceBlock.lockedFragmentIds);
|
|
773
|
+
cursor = surfaceBlock.nextCursor;
|
|
774
|
+
if (index < root.children.length - 1 && root.children[index + 1]?.type === "paragraph") {
|
|
775
|
+
cursor += 1;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
const secondaryStories = createSecondaryStorySurfaces(document);
|
|
779
|
+
return {
|
|
780
|
+
storySize: cursor,
|
|
781
|
+
plainText: createPlainText(blocks),
|
|
782
|
+
blocks,
|
|
783
|
+
lockedFragmentIds,
|
|
784
|
+
secondaryStories
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
function createSurfaceBlock(block, document, cursor, counters, numberingPrefixResolver) {
|
|
788
|
+
if (block.type === "opaque_block") {
|
|
789
|
+
const fragment = getOpaqueFragment(document.preservation, block.fragmentId);
|
|
790
|
+
const descriptor = fragment ? describeOpaqueFragment(fragment) : null;
|
|
791
|
+
const blockId = `opaque-${counters.opaque}`;
|
|
792
|
+
counters.opaque += 1;
|
|
793
|
+
return {
|
|
794
|
+
block: {
|
|
795
|
+
blockId,
|
|
796
|
+
kind: "opaque_block",
|
|
797
|
+
from: cursor,
|
|
798
|
+
to: cursor + 1,
|
|
799
|
+
fragmentId: block.fragmentId,
|
|
800
|
+
warningId: block.warningId,
|
|
801
|
+
label: descriptor?.label ?? "Unsupported OOXML fragment",
|
|
802
|
+
detail: descriptor?.detail ?? "Locked whole-unit to keep unsupported OOXML intact through export.",
|
|
803
|
+
state: "locked-preserve-only"
|
|
804
|
+
},
|
|
805
|
+
lockedFragmentIds: [block.fragmentId],
|
|
806
|
+
nextCursor: cursor + 1
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
if (block.type === "table") {
|
|
810
|
+
const tableIndex = counters.table;
|
|
811
|
+
counters.table += 1;
|
|
812
|
+
return createTableBlock(
|
|
813
|
+
tableIndex,
|
|
814
|
+
block,
|
|
815
|
+
document,
|
|
816
|
+
cursor,
|
|
817
|
+
counters,
|
|
818
|
+
numberingPrefixResolver
|
|
819
|
+
);
|
|
820
|
+
}
|
|
821
|
+
if (block.type === "sdt") {
|
|
822
|
+
const sdtIndex = counters.sdt;
|
|
823
|
+
counters.sdt += 1;
|
|
824
|
+
return createSdtBlock(
|
|
825
|
+
sdtIndex,
|
|
826
|
+
block,
|
|
827
|
+
document,
|
|
828
|
+
cursor,
|
|
829
|
+
counters,
|
|
830
|
+
numberingPrefixResolver
|
|
831
|
+
);
|
|
832
|
+
}
|
|
833
|
+
if (block.type === "custom_xml") {
|
|
834
|
+
const blockId = `custom-xml-${counters.customXml}`;
|
|
835
|
+
counters.customXml += 1;
|
|
836
|
+
return {
|
|
837
|
+
block: {
|
|
838
|
+
blockId,
|
|
839
|
+
kind: "opaque_block",
|
|
840
|
+
from: cursor,
|
|
841
|
+
to: cursor + 1,
|
|
842
|
+
fragmentId: blockId,
|
|
843
|
+
warningId: blockId,
|
|
844
|
+
label: "Custom XML block",
|
|
845
|
+
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.",
|
|
846
|
+
state: "locked-preserve-only"
|
|
847
|
+
},
|
|
848
|
+
lockedFragmentIds: [],
|
|
849
|
+
nextCursor: cursor + 1
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
if (block.type === "alt_chunk") {
|
|
853
|
+
const blockId = `alt-chunk-${counters.altChunk}`;
|
|
854
|
+
counters.altChunk += 1;
|
|
855
|
+
return {
|
|
856
|
+
block: {
|
|
857
|
+
blockId,
|
|
858
|
+
kind: "opaque_block",
|
|
859
|
+
from: cursor,
|
|
860
|
+
to: cursor + 1,
|
|
861
|
+
fragmentId: blockId,
|
|
862
|
+
warningId: blockId,
|
|
863
|
+
label: "AltChunk import",
|
|
864
|
+
detail: `Alternate content import remains read-only through relationship ${block.relationshipId}.`,
|
|
865
|
+
state: "locked-preserve-only"
|
|
866
|
+
},
|
|
867
|
+
lockedFragmentIds: [],
|
|
868
|
+
nextCursor: cursor + 1
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
if (block.type === "section_break") {
|
|
872
|
+
const blockId = `section-break-${counters.opaque}`;
|
|
873
|
+
counters.opaque += 1;
|
|
874
|
+
return {
|
|
875
|
+
block: {
|
|
876
|
+
blockId,
|
|
877
|
+
kind: "opaque_block",
|
|
878
|
+
from: cursor,
|
|
879
|
+
to: cursor + 1,
|
|
880
|
+
fragmentId: blockId,
|
|
881
|
+
warningId: blockId,
|
|
882
|
+
label: "Section break",
|
|
883
|
+
detail: "Section properties preserved as a read-only boundary.",
|
|
884
|
+
state: "locked-preserve-only"
|
|
885
|
+
},
|
|
886
|
+
lockedFragmentIds: [],
|
|
887
|
+
nextCursor: cursor + 1
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
const paragraphIndex = counters.paragraph;
|
|
891
|
+
counters.paragraph += 1;
|
|
892
|
+
return createParagraphBlock(
|
|
893
|
+
paragraphIndex,
|
|
894
|
+
block,
|
|
895
|
+
document,
|
|
896
|
+
cursor,
|
|
897
|
+
numberingPrefixResolver
|
|
898
|
+
);
|
|
899
|
+
}
|
|
900
|
+
function createTableBlock(tableIndex, table, document, cursor, counters, numberingPrefixResolver) {
|
|
901
|
+
const lockedFragmentIds = [];
|
|
902
|
+
let innerCursor = cursor;
|
|
903
|
+
const rows = [];
|
|
904
|
+
const rowSpans = computeTableRowSpans(table);
|
|
905
|
+
for (const [rowIndex, row] of table.rows.entries()) {
|
|
906
|
+
const cells = [];
|
|
907
|
+
for (const [cellIndex, cell] of row.cells.entries()) {
|
|
908
|
+
const cellContent = [];
|
|
909
|
+
for (const child of cell.children) {
|
|
910
|
+
const result = createSurfaceBlock(
|
|
911
|
+
child,
|
|
912
|
+
document,
|
|
913
|
+
innerCursor,
|
|
914
|
+
counters,
|
|
915
|
+
numberingPrefixResolver
|
|
916
|
+
);
|
|
917
|
+
cellContent.push(result.block);
|
|
918
|
+
lockedFragmentIds.push(...result.lockedFragmentIds);
|
|
919
|
+
innerCursor = result.nextCursor;
|
|
920
|
+
}
|
|
921
|
+
const cellBorders = resolveCellBorderStyles(cell.borders);
|
|
922
|
+
cells.push({
|
|
923
|
+
gridSpan: cell.gridSpan ?? 1,
|
|
924
|
+
verticalMerge: cell.verticalMerge ?? null,
|
|
925
|
+
colspan: cell.gridSpan ?? 1,
|
|
926
|
+
rowspan: rowSpans.get(`${rowIndex}:${cellIndex}`) ?? 1,
|
|
927
|
+
...cell.shading?.fill ? { backgroundColor: `#${cell.shading.fill}` } : {},
|
|
928
|
+
...cell.verticalAlign ? { verticalAlign: cell.verticalAlign } : {},
|
|
929
|
+
...cellBorders.borderTop ? { borderTop: cellBorders.borderTop } : {},
|
|
930
|
+
...cellBorders.borderRight ? { borderRight: cellBorders.borderRight } : {},
|
|
931
|
+
...cellBorders.borderBottom ? { borderBottom: cellBorders.borderBottom } : {},
|
|
932
|
+
...cellBorders.borderLeft ? { borderLeft: cellBorders.borderLeft } : {},
|
|
933
|
+
content: cellContent
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
rows.push({
|
|
937
|
+
cells,
|
|
938
|
+
...row.gridBefore !== void 0 ? { gridBefore: row.gridBefore } : {},
|
|
939
|
+
...row.gridAfter !== void 0 ? { gridAfter: row.gridAfter } : {},
|
|
940
|
+
...row.height !== void 0 ? { height: row.height } : {},
|
|
941
|
+
...row.heightRule ? { heightRule: row.heightRule } : {},
|
|
942
|
+
...row.isHeader ? { isHeader: row.isHeader } : {}
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
return {
|
|
946
|
+
block: {
|
|
947
|
+
blockId: `table-${tableIndex}`,
|
|
948
|
+
kind: "table",
|
|
949
|
+
from: cursor,
|
|
950
|
+
to: innerCursor,
|
|
951
|
+
styleId: table.styleId,
|
|
952
|
+
gridColumns: table.gridColumns,
|
|
953
|
+
...table.alignment ? { alignment: table.alignment } : {},
|
|
954
|
+
...table.tblLook ? { tblLook: table.tblLook } : {},
|
|
955
|
+
rows
|
|
956
|
+
},
|
|
957
|
+
lockedFragmentIds,
|
|
958
|
+
nextCursor: innerCursor
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
function computeTableRowSpans(table) {
|
|
962
|
+
const positionedRows = table.rows.map((row) => {
|
|
963
|
+
let startColumn = 0;
|
|
964
|
+
return row.cells.map((cell, cellIndex) => {
|
|
965
|
+
const width = cell.gridSpan ?? 1;
|
|
966
|
+
const positionedCell = {
|
|
967
|
+
cell,
|
|
968
|
+
cellIndex,
|
|
969
|
+
startColumn,
|
|
970
|
+
endColumn: startColumn + width - 1
|
|
971
|
+
};
|
|
972
|
+
startColumn += width;
|
|
973
|
+
return positionedCell;
|
|
974
|
+
});
|
|
975
|
+
});
|
|
976
|
+
const rowSpans = /* @__PURE__ */ new Map();
|
|
977
|
+
for (const [rowIndex, row] of positionedRows.entries()) {
|
|
978
|
+
for (const positionedCell of row) {
|
|
979
|
+
if (positionedCell.cell.verticalMerge !== "restart") {
|
|
980
|
+
rowSpans.set(`${rowIndex}:${positionedCell.cellIndex}`, 1);
|
|
981
|
+
continue;
|
|
982
|
+
}
|
|
983
|
+
let rowspan = 1;
|
|
984
|
+
for (let nextRowIndex = rowIndex + 1; nextRowIndex < positionedRows.length; nextRowIndex += 1) {
|
|
985
|
+
const continuedCell = positionedRows[nextRowIndex]?.find(
|
|
986
|
+
(candidate) => candidate.cell.verticalMerge === "continue" && candidate.startColumn === positionedCell.startColumn && candidate.endColumn === positionedCell.endColumn
|
|
987
|
+
);
|
|
988
|
+
if (!continuedCell) {
|
|
989
|
+
break;
|
|
990
|
+
}
|
|
991
|
+
rowspan += 1;
|
|
992
|
+
}
|
|
993
|
+
rowSpans.set(`${rowIndex}:${positionedCell.cellIndex}`, rowspan);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
return rowSpans;
|
|
997
|
+
}
|
|
998
|
+
function resolveCellBorderStyles(borders) {
|
|
999
|
+
if (!borders) return {};
|
|
1000
|
+
const result = {};
|
|
1001
|
+
const sides = [["top", "borderTop"], ["right", "borderRight"], ["bottom", "borderBottom"], ["left", "borderLeft"]];
|
|
1002
|
+
for (const [side, key] of sides) {
|
|
1003
|
+
const spec = borders[side];
|
|
1004
|
+
if (!spec || spec.value === "none" || spec.value === "nil") continue;
|
|
1005
|
+
const width = spec.size ? `${Math.max(1, Math.round(spec.size / 8))}px` : "1px";
|
|
1006
|
+
const style = spec.value === "double" ? "double" : spec.value === "dashed" || spec.value === "dashSmallGap" ? "dashed" : spec.value === "dotted" ? "dotted" : "solid";
|
|
1007
|
+
const color = spec.color && spec.color !== "auto" ? `#${spec.color}` : "currentColor";
|
|
1008
|
+
result[key] = `${width} ${style} ${color}`;
|
|
1009
|
+
}
|
|
1010
|
+
return result;
|
|
1011
|
+
}
|
|
1012
|
+
function createSdtBlock(sdtIndex, block, document, cursor, counters, numberingPrefixResolver) {
|
|
1013
|
+
const children = [];
|
|
1014
|
+
const lockedFragmentIds = [];
|
|
1015
|
+
let innerCursor = cursor;
|
|
1016
|
+
for (const child of block.children) {
|
|
1017
|
+
const result = createSurfaceBlock(
|
|
1018
|
+
child,
|
|
1019
|
+
document,
|
|
1020
|
+
innerCursor,
|
|
1021
|
+
counters,
|
|
1022
|
+
numberingPrefixResolver
|
|
1023
|
+
);
|
|
1024
|
+
children.push(result.block);
|
|
1025
|
+
lockedFragmentIds.push(...result.lockedFragmentIds);
|
|
1026
|
+
innerCursor = result.nextCursor;
|
|
1027
|
+
}
|
|
1028
|
+
return {
|
|
1029
|
+
block: {
|
|
1030
|
+
blockId: `sdt-${sdtIndex}`,
|
|
1031
|
+
kind: "sdt_block",
|
|
1032
|
+
from: cursor,
|
|
1033
|
+
to: innerCursor,
|
|
1034
|
+
...block.properties.sdtType ? { sdtType: block.properties.sdtType } : {},
|
|
1035
|
+
...block.properties.alias ? { alias: block.properties.alias } : {},
|
|
1036
|
+
...block.properties.tag ? { tag: block.properties.tag } : {},
|
|
1037
|
+
...block.properties.lock ? { lock: block.properties.lock } : {},
|
|
1038
|
+
...block.properties.checkbox ? { checkboxChecked: block.properties.checkbox.checked } : {},
|
|
1039
|
+
...block.properties.datePicker?.fullDate ? { dateValue: block.properties.datePicker.fullDate } : {},
|
|
1040
|
+
...block.properties.dropdownList ? { dropdownItems: block.properties.dropdownList } : {},
|
|
1041
|
+
...block.properties.comboBox ? { comboBoxItems: block.properties.comboBox } : {},
|
|
1042
|
+
...block.properties.showingPlcHdr ? { showingPlcHdr: true } : {},
|
|
1043
|
+
children
|
|
1044
|
+
},
|
|
1045
|
+
lockedFragmentIds,
|
|
1046
|
+
nextCursor: innerCursor
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
function createParagraphBlock(paragraphIndex, paragraph, document, start, numberingPrefixResolver) {
|
|
1050
|
+
const accumulator = {
|
|
1051
|
+
blockId: `paragraph-${paragraphIndex}`,
|
|
1052
|
+
kind: "paragraph",
|
|
1053
|
+
from: start,
|
|
1054
|
+
to: start,
|
|
1055
|
+
...paragraph.styleId ? { styleId: paragraph.styleId } : {},
|
|
1056
|
+
...paragraph.numbering ? { numbering: paragraph.numbering } : {},
|
|
1057
|
+
...paragraph.numbering ? (() => {
|
|
1058
|
+
const detailed = numberingPrefixResolver.resolveDetailed(paragraph.numbering);
|
|
1059
|
+
return detailed ? {
|
|
1060
|
+
numberingPrefix: detailed.text,
|
|
1061
|
+
...detailed.suffix ? { numberingSuffix: detailed.suffix } : {}
|
|
1062
|
+
} : {};
|
|
1063
|
+
})() : {},
|
|
1064
|
+
...paragraph.alignment ? { alignment: paragraph.alignment } : {},
|
|
1065
|
+
...paragraph.spacing ? { spacing: paragraph.spacing } : {},
|
|
1066
|
+
...paragraph.contextualSpacing !== void 0 ? { contextualSpacing: paragraph.contextualSpacing } : {},
|
|
1067
|
+
...paragraph.indentation ? { indentation: paragraph.indentation } : {},
|
|
1068
|
+
...paragraph.borders ? { borders: paragraph.borders } : {},
|
|
1069
|
+
...paragraph.shading ? { shading: paragraph.shading } : {},
|
|
1070
|
+
...paragraph.tabStops && paragraph.tabStops.length > 0 ? { tabStops: paragraph.tabStops.map((tabStop) => toSurfaceTabStop(tabStop)) } : {},
|
|
1071
|
+
...paragraph.keepNext ? { keepNext: true } : {},
|
|
1072
|
+
...paragraph.keepLines ? { keepLines: true } : {},
|
|
1073
|
+
...paragraph.pageBreakBefore ? { pageBreakBefore: true } : {},
|
|
1074
|
+
...paragraph.outlineLevel !== void 0 ? { outlineLevel: paragraph.outlineLevel } : {},
|
|
1075
|
+
...paragraph.bidi ? { bidi: true } : {},
|
|
1076
|
+
...paragraph.suppressLineNumbers ? { suppressLineNumbers: true } : {},
|
|
1077
|
+
segments: []
|
|
1078
|
+
};
|
|
1079
|
+
const lockedFragmentIds = [];
|
|
1080
|
+
let cursor = start;
|
|
1081
|
+
const children = Array.isArray(paragraph.children) ? paragraph.children : [];
|
|
1082
|
+
for (const child of children) {
|
|
1083
|
+
const result = appendInlineSegments(accumulator, child, document, cursor);
|
|
1084
|
+
cursor = result.nextCursor;
|
|
1085
|
+
lockedFragmentIds.push(...result.lockedFragmentIds);
|
|
1086
|
+
}
|
|
1087
|
+
accumulator.to = cursor;
|
|
1088
|
+
return {
|
|
1089
|
+
block: accumulator,
|
|
1090
|
+
nextCursor: cursor,
|
|
1091
|
+
lockedFragmentIds
|
|
1092
|
+
};
|
|
1093
|
+
}
|
|
1094
|
+
function appendInlineSegments(paragraph, node, document, start, hyperlinkHref) {
|
|
1095
|
+
switch (node.type) {
|
|
1096
|
+
case "text":
|
|
1097
|
+
paragraph.segments.push({
|
|
1098
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
1099
|
+
kind: "text",
|
|
1100
|
+
from: start,
|
|
1101
|
+
to: start + Array.from(node.text).length,
|
|
1102
|
+
text: node.text,
|
|
1103
|
+
...node.marks ? (() => {
|
|
1104
|
+
const result = cloneMarks2(node.marks);
|
|
1105
|
+
return {
|
|
1106
|
+
...result.marks.length > 0 ? { marks: result.marks } : {},
|
|
1107
|
+
...result.markAttrs ? { markAttrs: result.markAttrs } : {}
|
|
1108
|
+
};
|
|
1109
|
+
})() : {},
|
|
1110
|
+
...hyperlinkHref ? { hyperlinkHref } : {}
|
|
1111
|
+
});
|
|
1112
|
+
return { nextCursor: start + Array.from(node.text).length, lockedFragmentIds: [] };
|
|
1113
|
+
case "tab":
|
|
1114
|
+
paragraph.segments.push({
|
|
1115
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
1116
|
+
kind: "tab",
|
|
1117
|
+
from: start,
|
|
1118
|
+
to: start + 1,
|
|
1119
|
+
...hyperlinkHref ? { hyperlinkHref } : {}
|
|
1120
|
+
});
|
|
1121
|
+
return { nextCursor: start + 1, lockedFragmentIds: [] };
|
|
1122
|
+
case "hard_break":
|
|
1123
|
+
paragraph.segments.push({
|
|
1124
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
1125
|
+
kind: "hard_break",
|
|
1126
|
+
from: start,
|
|
1127
|
+
to: start + 1,
|
|
1128
|
+
...hyperlinkHref ? { hyperlinkHref } : {}
|
|
1129
|
+
});
|
|
1130
|
+
return { nextCursor: start + 1, lockedFragmentIds: [] };
|
|
1131
|
+
case "hyperlink": {
|
|
1132
|
+
let cursor = start;
|
|
1133
|
+
for (const child of node.children) {
|
|
1134
|
+
const result = appendInlineSegments(paragraph, child, document, cursor, node.href);
|
|
1135
|
+
cursor = result.nextCursor;
|
|
1136
|
+
}
|
|
1137
|
+
return { nextCursor: cursor, lockedFragmentIds: [] };
|
|
1138
|
+
}
|
|
1139
|
+
case "image":
|
|
1140
|
+
paragraph.segments.push({
|
|
1141
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
1142
|
+
kind: "image",
|
|
1143
|
+
from: start,
|
|
1144
|
+
to: start + 1,
|
|
1145
|
+
mediaId: node.mediaId,
|
|
1146
|
+
altText: node.altText,
|
|
1147
|
+
state: hasMediaItem(document.media, node.mediaId) ? "editable" : "missing",
|
|
1148
|
+
...node.display ? { display: node.display } : {},
|
|
1149
|
+
detail: node.display === "floating" ? createFloatingImageDetail(node.altText, node.floating) : node.altText ? `Alt text ${node.altText}.` : "Inline image remains a whole-unit render surface."
|
|
1150
|
+
});
|
|
1151
|
+
return { nextCursor: start + 1, lockedFragmentIds: [] };
|
|
1152
|
+
case "opaque_inline": {
|
|
1153
|
+
const fragment = getOpaqueFragment(document.preservation, node.fragmentId);
|
|
1154
|
+
const descriptor = fragment ? describeOpaqueFragment(fragment) : null;
|
|
1155
|
+
const preview = fragment ? describePreservedInlinePreview(fragment.payloadReference) : null;
|
|
1156
|
+
paragraph.segments.push({
|
|
1157
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
1158
|
+
kind: "opaque_inline",
|
|
1159
|
+
from: start,
|
|
1160
|
+
to: start + 1,
|
|
1161
|
+
fragmentId: node.fragmentId,
|
|
1162
|
+
warningId: node.warningId,
|
|
1163
|
+
label: preview?.label ?? descriptor?.label ?? "Unsupported inline OOXML",
|
|
1164
|
+
detail: preview?.detail ?? descriptor?.detail ?? "Locked whole-unit to keep unsupported inline OOXML intact through export.",
|
|
1165
|
+
...preview?.presentation ? { presentation: preview.presentation } : {},
|
|
1166
|
+
state: "locked-preserve-only"
|
|
1167
|
+
});
|
|
1168
|
+
return { nextCursor: start + 1, lockedFragmentIds: [node.fragmentId] };
|
|
1169
|
+
}
|
|
1170
|
+
case "chart_preview":
|
|
1171
|
+
return appendComplexPreviewSegment(paragraph, node, start, "Embedded chart", createChartDetail(node));
|
|
1172
|
+
case "smartart_preview":
|
|
1173
|
+
return appendComplexPreviewSegment(paragraph, node, start, "SmartArt diagram", createSmartArtDetail(node));
|
|
1174
|
+
case "shape":
|
|
1175
|
+
return appendComplexPreviewSegment(
|
|
1176
|
+
paragraph,
|
|
1177
|
+
node,
|
|
1178
|
+
start,
|
|
1179
|
+
node.isTextBox ? "Text box" : "Drawing shape",
|
|
1180
|
+
createShapeDetail(node)
|
|
1181
|
+
);
|
|
1182
|
+
case "wordart":
|
|
1183
|
+
return appendComplexPreviewSegment(paragraph, node, start, "WordArt", createWordArtDetail(node));
|
|
1184
|
+
case "vml_shape":
|
|
1185
|
+
return appendComplexPreviewSegment(paragraph, node, start, "Legacy VML drawing", createVmlDetail(node));
|
|
1186
|
+
case "symbol":
|
|
1187
|
+
paragraph.segments.push({
|
|
1188
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
1189
|
+
kind: "text",
|
|
1190
|
+
from: start,
|
|
1191
|
+
to: start + 1,
|
|
1192
|
+
text: node.char ? String.fromCodePoint(parseInt(node.char, 16)) : "\uFFFD"
|
|
1193
|
+
});
|
|
1194
|
+
return { nextCursor: start + 1, lockedFragmentIds: [] };
|
|
1195
|
+
case "column_break":
|
|
1196
|
+
paragraph.segments.push({
|
|
1197
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
1198
|
+
kind: "opaque_inline",
|
|
1199
|
+
from: start,
|
|
1200
|
+
to: start + 1,
|
|
1201
|
+
fragmentId: "",
|
|
1202
|
+
warningId: "",
|
|
1203
|
+
label: "Column break",
|
|
1204
|
+
detail: "Column break marker preserved for export.",
|
|
1205
|
+
state: "locked-preserve-only"
|
|
1206
|
+
});
|
|
1207
|
+
return { nextCursor: start + 1, lockedFragmentIds: [] };
|
|
1208
|
+
case "footnote_ref":
|
|
1209
|
+
paragraph.segments.push({
|
|
1210
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
1211
|
+
kind: "note_ref",
|
|
1212
|
+
from: start,
|
|
1213
|
+
to: start + 1,
|
|
1214
|
+
noteKind: node.noteKind ?? "footnote",
|
|
1215
|
+
noteId: node.noteId ?? "",
|
|
1216
|
+
label: node.noteId ?? "*"
|
|
1217
|
+
});
|
|
1218
|
+
return { nextCursor: start + 1, lockedFragmentIds: [] };
|
|
1219
|
+
case "field": {
|
|
1220
|
+
const isSupportedField = node.fieldFamily === "REF" || node.fieldFamily === "PAGEREF" || node.fieldFamily === "NOTEREF" || node.fieldFamily === "TOC";
|
|
1221
|
+
if (node.children && node.children.length > 0) {
|
|
1222
|
+
let cursor = start;
|
|
1223
|
+
const lockedIds = [];
|
|
1224
|
+
for (const child of node.children) {
|
|
1225
|
+
const result = appendInlineSegments(paragraph, child, document, cursor);
|
|
1226
|
+
cursor = result.nextCursor;
|
|
1227
|
+
lockedIds.push(...result.lockedFragmentIds);
|
|
1228
|
+
}
|
|
1229
|
+
return { nextCursor: cursor, lockedFragmentIds: lockedIds };
|
|
1230
|
+
}
|
|
1231
|
+
if (isSupportedField) {
|
|
1232
|
+
const fieldLabel = node.fieldFamily === "TOC" ? "Table of Contents" : `${node.fieldFamily ?? "Field"}: ${node.fieldTarget ?? node.instruction.trim()}`;
|
|
1233
|
+
paragraph.segments.push({
|
|
1234
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
1235
|
+
kind: "field_ref",
|
|
1236
|
+
from: start,
|
|
1237
|
+
to: start + 1,
|
|
1238
|
+
fieldFamily: node.fieldFamily,
|
|
1239
|
+
fieldTarget: node.fieldTarget,
|
|
1240
|
+
instruction: node.instruction,
|
|
1241
|
+
refreshStatus: node.refreshStatus ?? "stale",
|
|
1242
|
+
label: fieldLabel
|
|
1243
|
+
});
|
|
1244
|
+
return { nextCursor: start + 1, lockedFragmentIds: [] };
|
|
1245
|
+
}
|
|
1246
|
+
paragraph.segments.push({
|
|
1247
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
1248
|
+
kind: "opaque_inline",
|
|
1249
|
+
from: start,
|
|
1250
|
+
to: start + 1,
|
|
1251
|
+
fragmentId: "",
|
|
1252
|
+
warningId: "",
|
|
1253
|
+
label: "Field",
|
|
1254
|
+
detail: `Preserve-only field: ${node.instruction.trim()}`,
|
|
1255
|
+
state: "locked-preserve-only"
|
|
1256
|
+
});
|
|
1257
|
+
return { nextCursor: start + 1, lockedFragmentIds: [] };
|
|
1258
|
+
}
|
|
1259
|
+
case "bookmark_start":
|
|
1260
|
+
case "bookmark_end":
|
|
1261
|
+
return { nextCursor: start, lockedFragmentIds: [] };
|
|
1262
|
+
default:
|
|
1263
|
+
return { nextCursor: start + 1, lockedFragmentIds: [] };
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
function appendComplexPreviewSegment(paragraph, node, start, label, detail) {
|
|
1267
|
+
paragraph.segments.push({
|
|
1268
|
+
segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
|
|
1269
|
+
kind: "opaque_inline",
|
|
1270
|
+
from: start,
|
|
1271
|
+
to: start + 1,
|
|
1272
|
+
fragmentId: `complex:${label.replace(/\s/g, "-").toLowerCase()}:${start}`,
|
|
1273
|
+
warningId: `warning:complex-preview:${start}`,
|
|
1274
|
+
label,
|
|
1275
|
+
detail,
|
|
1276
|
+
state: "locked-preserve-only"
|
|
1277
|
+
});
|
|
1278
|
+
return { nextCursor: start + 1, lockedFragmentIds: [] };
|
|
1279
|
+
}
|
|
1280
|
+
function createChartDetail(node) {
|
|
1281
|
+
const parts = ["Embedded chart."];
|
|
1282
|
+
if (node.previewMediaId) {
|
|
1283
|
+
parts.push(`Preview available via fallback image (${node.previewMediaId}).`);
|
|
1284
|
+
} else {
|
|
1285
|
+
parts.push("No fallback preview image found; chart data preserved in package.");
|
|
1286
|
+
}
|
|
1287
|
+
parts.push("Edit in Word to modify chart data. Original DrawingML preserved for lossless export.");
|
|
1288
|
+
return parts.join(" ");
|
|
1289
|
+
}
|
|
1290
|
+
function createSmartArtDetail(node) {
|
|
1291
|
+
const parts = ["SmartArt diagram."];
|
|
1292
|
+
if (node.previewMediaId) {
|
|
1293
|
+
parts.push(`Preview available via fallback image (${node.previewMediaId}).`);
|
|
1294
|
+
} else {
|
|
1295
|
+
parts.push("No fallback preview image found; diagram structure preserved in package.");
|
|
1296
|
+
}
|
|
1297
|
+
parts.push("Edit in Word to modify diagram layout and content. Original DrawingML preserved for lossless export.");
|
|
1298
|
+
return parts.join(" ");
|
|
1299
|
+
}
|
|
1300
|
+
function createShapeDetail(node) {
|
|
1301
|
+
if (node.isTextBox) {
|
|
1302
|
+
const parts2 = ["Text box."];
|
|
1303
|
+
if (node.text) parts2.push(`Content: "${node.text}".`);
|
|
1304
|
+
parts2.push("Text content is visible; formatting and geometry preserved for export.");
|
|
1305
|
+
return parts2.join(" ");
|
|
1306
|
+
}
|
|
1307
|
+
const parts = ["Drawing shape."];
|
|
1308
|
+
if (node.geometry) parts.push(`Geometry: ${node.geometry}.`);
|
|
1309
|
+
if (node.text) parts.push(`Text content: "${node.text}".`);
|
|
1310
|
+
parts.push("Visual geometry is preview-only. Original DrawingML preserved for export.");
|
|
1311
|
+
return parts.join(" ");
|
|
1312
|
+
}
|
|
1313
|
+
function createWordArtDetail(node) {
|
|
1314
|
+
const parts = ["WordArt decorative text."];
|
|
1315
|
+
if (node.text) parts.push(`Text: "${node.text}".`);
|
|
1316
|
+
if (node.geometry) parts.push(`Effect: ${node.geometry}.`);
|
|
1317
|
+
parts.push("Text effect is preview-only. Edit in Word for full formatting. Original DrawingML preserved for export.");
|
|
1318
|
+
return parts.join(" ");
|
|
1319
|
+
}
|
|
1320
|
+
function createVmlDetail(node) {
|
|
1321
|
+
const parts = ["Legacy VML drawing."];
|
|
1322
|
+
if (node.shapeType) parts.push(`Type: ${node.shapeType}.`);
|
|
1323
|
+
if (node.text) parts.push(`Text content: "${node.text}".`);
|
|
1324
|
+
parts.push("VML content is preview-only. Edit in Word for full control. Original VML XML preserved for export.");
|
|
1325
|
+
return parts.join(" ");
|
|
1326
|
+
}
|
|
1327
|
+
function createPlainText(blocks) {
|
|
1328
|
+
const text = [];
|
|
1329
|
+
for (const block of blocks) {
|
|
1330
|
+
if (block.kind === "opaque_block") {
|
|
1331
|
+
if (block.fragmentId.startsWith("preview:")) {
|
|
1332
|
+
continue;
|
|
1333
|
+
}
|
|
1334
|
+
text.push("\uFFFA");
|
|
1335
|
+
continue;
|
|
1336
|
+
}
|
|
1337
|
+
if (block.kind === "table") {
|
|
1338
|
+
for (const row of block.rows) {
|
|
1339
|
+
for (const cell of row.cells) {
|
|
1340
|
+
text.push(createPlainText(cell.content));
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
continue;
|
|
1344
|
+
}
|
|
1345
|
+
if (block.kind === "sdt_block") {
|
|
1346
|
+
text.push(createPlainText(block.children));
|
|
1347
|
+
continue;
|
|
1348
|
+
}
|
|
1349
|
+
for (const segment of block.segments) {
|
|
1350
|
+
switch (segment.kind) {
|
|
1351
|
+
case "text":
|
|
1352
|
+
text.push(segment.text);
|
|
1353
|
+
break;
|
|
1354
|
+
case "tab":
|
|
1355
|
+
text.push(" ");
|
|
1356
|
+
break;
|
|
1357
|
+
case "hard_break":
|
|
1358
|
+
text.push("\n");
|
|
1359
|
+
break;
|
|
1360
|
+
case "image":
|
|
1361
|
+
text.push("\uFFFC");
|
|
1362
|
+
break;
|
|
1363
|
+
case "opaque_inline":
|
|
1364
|
+
text.push("\uFFF9");
|
|
1365
|
+
break;
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
return text.join("");
|
|
1370
|
+
}
|
|
1371
|
+
function createSecondaryStorySurfaces(document) {
|
|
1372
|
+
const surfaces = [];
|
|
1373
|
+
const subParts = document.subParts;
|
|
1374
|
+
if (!subParts) {
|
|
1375
|
+
return surfaces;
|
|
1376
|
+
}
|
|
1377
|
+
const numberingPrefixResolver = createNumberingPrefixResolver(document.numbering);
|
|
1378
|
+
for (const section of collectSectionContexts(document)) {
|
|
1379
|
+
const headerVariants = resolveSectionVariants(
|
|
1380
|
+
"header",
|
|
1381
|
+
section.index,
|
|
1382
|
+
section.properties?.headerReferences,
|
|
1383
|
+
subParts.headers ?? []
|
|
1384
|
+
);
|
|
1385
|
+
for (const headerVariant of headerVariants) {
|
|
1386
|
+
const target = {
|
|
1387
|
+
kind: "header",
|
|
1388
|
+
relationshipId: headerVariant.relationshipId,
|
|
1389
|
+
variant: headerVariant.variant,
|
|
1390
|
+
sectionIndex: section.index
|
|
1391
|
+
};
|
|
1392
|
+
const header = findHeaderFooterDocumentEntry(document, target);
|
|
1393
|
+
if (!header) {
|
|
1394
|
+
continue;
|
|
1395
|
+
}
|
|
1396
|
+
surfaces.push(
|
|
1397
|
+
createStorySurface(
|
|
1398
|
+
target,
|
|
1399
|
+
`Header \xB7 ${headerVariant.variant}`,
|
|
1400
|
+
header.blocks,
|
|
1401
|
+
document,
|
|
1402
|
+
numberingPrefixResolver
|
|
1403
|
+
)
|
|
1404
|
+
);
|
|
1405
|
+
}
|
|
1406
|
+
const footerVariants = resolveSectionVariants(
|
|
1407
|
+
"footer",
|
|
1408
|
+
section.index,
|
|
1409
|
+
section.properties?.footerReferences,
|
|
1410
|
+
subParts.footers ?? []
|
|
1411
|
+
);
|
|
1412
|
+
for (const footerVariant of footerVariants) {
|
|
1413
|
+
const target = {
|
|
1414
|
+
kind: "footer",
|
|
1415
|
+
relationshipId: footerVariant.relationshipId,
|
|
1416
|
+
variant: footerVariant.variant,
|
|
1417
|
+
sectionIndex: section.index
|
|
1418
|
+
};
|
|
1419
|
+
const footer = findHeaderFooterDocumentEntry(document, target);
|
|
1420
|
+
if (!footer) {
|
|
1421
|
+
continue;
|
|
1422
|
+
}
|
|
1423
|
+
surfaces.push(
|
|
1424
|
+
createStorySurface(
|
|
1425
|
+
target,
|
|
1426
|
+
`Footer \xB7 ${footerVariant.variant}`,
|
|
1427
|
+
footer.blocks,
|
|
1428
|
+
document,
|
|
1429
|
+
numberingPrefixResolver
|
|
1430
|
+
)
|
|
1431
|
+
);
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
const footnotes = Object.values(subParts.footnoteCollection?.footnotes ?? {}).sort(compareNoteIds);
|
|
1435
|
+
for (const note of footnotes) {
|
|
1436
|
+
const target = { kind: "footnote", noteId: note.noteId };
|
|
1437
|
+
surfaces.push(createStorySurface(target, `Footnote ${note.noteId}`, note.blocks, document, numberingPrefixResolver));
|
|
1438
|
+
}
|
|
1439
|
+
const endnotes = Object.values(subParts.footnoteCollection?.endnotes ?? {}).sort(compareNoteIds);
|
|
1440
|
+
for (const note of endnotes) {
|
|
1441
|
+
const target = { kind: "endnote", noteId: note.noteId };
|
|
1442
|
+
surfaces.push(createStorySurface(target, `Endnote ${note.noteId}`, note.blocks, document, numberingPrefixResolver));
|
|
1443
|
+
}
|
|
1444
|
+
return surfaces;
|
|
1445
|
+
}
|
|
1446
|
+
function createStorySurface(target, label, blocks, document, numberingPrefixResolver) {
|
|
1447
|
+
const surfaceBlocks = [];
|
|
1448
|
+
let cursor = 0;
|
|
1449
|
+
const counters = {
|
|
1450
|
+
paragraph: 0,
|
|
1451
|
+
table: 0,
|
|
1452
|
+
opaque: 0,
|
|
1453
|
+
sdt: 0,
|
|
1454
|
+
customXml: 0,
|
|
1455
|
+
altChunk: 0
|
|
1456
|
+
};
|
|
1457
|
+
for (let index = 0; index < blocks.length; index += 1) {
|
|
1458
|
+
const surfaceBlock = createSurfaceBlock(
|
|
1459
|
+
blocks[index],
|
|
1460
|
+
document,
|
|
1461
|
+
cursor,
|
|
1462
|
+
counters,
|
|
1463
|
+
numberingPrefixResolver
|
|
1464
|
+
);
|
|
1465
|
+
surfaceBlocks.push(surfaceBlock.block);
|
|
1466
|
+
cursor = surfaceBlock.nextCursor;
|
|
1467
|
+
if (index < blocks.length - 1 && blocks[index + 1]?.type === "paragraph") {
|
|
1468
|
+
cursor += 1;
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
return {
|
|
1472
|
+
target,
|
|
1473
|
+
label,
|
|
1474
|
+
storySize: cursor,
|
|
1475
|
+
blocks: surfaceBlocks
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1478
|
+
function compareNoteIds(left, right) {
|
|
1479
|
+
return Number.parseInt(left.noteId, 10) - Number.parseInt(right.noteId, 10);
|
|
1480
|
+
}
|
|
1481
|
+
function toSurfaceTabStop(tabStop) {
|
|
1482
|
+
return {
|
|
1483
|
+
pos: tabStop.position,
|
|
1484
|
+
...tabStop.align ? { val: tabStop.align } : {},
|
|
1485
|
+
...tabStop.leader ? { leader: tabStop.leader } : {}
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
1488
|
+
function describePreservedInlinePreview(payloadReference) {
|
|
1489
|
+
if (/\b(?:w:)?proofErr\b/u.test(payloadReference)) {
|
|
1490
|
+
const proofType = /\bw:type="([^"]+)"/u.exec(payloadReference)?.[1];
|
|
1491
|
+
return {
|
|
1492
|
+
label: "Proofing marker",
|
|
1493
|
+
detail: proofType && proofType.trim().length > 0 ? `Word proofing marker (${proofType}) preserved for export safety.` : "Word proofing marker preserved for export safety.",
|
|
1494
|
+
presentation: "quiet-marker"
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1497
|
+
if (/\b(?:w:)?lastRenderedPageBreak\b/u.test(payloadReference)) {
|
|
1498
|
+
return {
|
|
1499
|
+
label: "Rendered page break",
|
|
1500
|
+
detail: "Word rendered page-break marker preserved for export safety.",
|
|
1501
|
+
presentation: "quiet-marker"
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1504
|
+
if (/\b(?:w:)?permStart\b/u.test(payloadReference)) {
|
|
1505
|
+
const editorGroup = /\bw:edGrp="([^"]+)"/u.exec(payloadReference)?.[1];
|
|
1506
|
+
return {
|
|
1507
|
+
label: "Protected range start",
|
|
1508
|
+
detail: editorGroup && editorGroup.trim().length > 0 ? `Protected range start for ${editorGroup} preserved for export safety.` : "Protected range start preserved for export safety.",
|
|
1509
|
+
presentation: "quiet-marker"
|
|
1510
|
+
};
|
|
1511
|
+
}
|
|
1512
|
+
if (/\b(?:w:)?permEnd\b/u.test(payloadReference)) {
|
|
1513
|
+
return {
|
|
1514
|
+
label: "Protected range end",
|
|
1515
|
+
detail: "Protected range end preserved for export safety.",
|
|
1516
|
+
presentation: "quiet-marker"
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1519
|
+
if (/\b(?:w:)?bookmarkStart\b/u.test(payloadReference)) {
|
|
1520
|
+
const name = /\bw:name="([^"]+)"/u.exec(payloadReference)?.[1];
|
|
1521
|
+
return {
|
|
1522
|
+
label: name ? `Bookmark \xB7 ${name}` : "Bookmark",
|
|
1523
|
+
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."
|
|
1524
|
+
};
|
|
1525
|
+
}
|
|
1526
|
+
if (/\b(?:w:)?bookmarkEnd\b/u.test(payloadReference)) {
|
|
1527
|
+
return {
|
|
1528
|
+
label: "Bookmark end",
|
|
1529
|
+
detail: "Bookmark end marker is preserved as a read-only inline token for export safety."
|
|
1530
|
+
};
|
|
1531
|
+
}
|
|
1532
|
+
if (/\b(?:w:)?fldSimple\b|\b(?:w:)?fldChar\b|\b(?:w:)?instrText\b/u.test(payloadReference)) {
|
|
1533
|
+
const simpleInstruction = /\bw:instr="([^"]*)"/u.exec(payloadReference)?.[1];
|
|
1534
|
+
const complexInstruction = [...payloadReference.matchAll(/<(?:\w+:)?instrText\b[^>]*>([\s\S]*?)<\/(?:\w+:)?instrText>/gu)].map((match) => decodeXmlEntities(match[1] ?? "")).join("").trim();
|
|
1535
|
+
const instruction = (simpleInstruction ?? complexInstruction ?? "").trim();
|
|
1536
|
+
const family = /^([A-Z]+)/i.exec(instruction)?.[1]?.toUpperCase();
|
|
1537
|
+
const label = family === "TOC" ? "Table of Contents field" : family ? `${family} field` : "Field";
|
|
1538
|
+
return {
|
|
1539
|
+
label,
|
|
1540
|
+
detail: instruction.length > 0 ? `Read-only field preserved for export safety. Instruction: ${instruction}.` : "Read-only field preserved for export safety."
|
|
1541
|
+
};
|
|
1542
|
+
}
|
|
1543
|
+
return null;
|
|
1544
|
+
}
|
|
1545
|
+
function decodeXmlEntities(text) {
|
|
1546
|
+
return text.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&");
|
|
1547
|
+
}
|
|
1548
|
+
function cloneMarks2(marks) {
|
|
1549
|
+
const supported = [];
|
|
1550
|
+
const attrs = {};
|
|
1551
|
+
let shadingColor;
|
|
1552
|
+
let highlightColor;
|
|
1553
|
+
for (const mark of marks) {
|
|
1554
|
+
switch (mark.type) {
|
|
1555
|
+
case "bold":
|
|
1556
|
+
case "italic":
|
|
1557
|
+
case "underline":
|
|
1558
|
+
case "strikethrough":
|
|
1559
|
+
case "doubleStrikethrough":
|
|
1560
|
+
case "vanish":
|
|
1561
|
+
case "emboss":
|
|
1562
|
+
case "imprint":
|
|
1563
|
+
case "shadow":
|
|
1564
|
+
supported.push(mark.type);
|
|
1565
|
+
break;
|
|
1566
|
+
case "position":
|
|
1567
|
+
if (mark.val > 0) supported.push("superscript");
|
|
1568
|
+
else if (mark.val < 0) supported.push("subscript");
|
|
1569
|
+
break;
|
|
1570
|
+
case "backgroundColor":
|
|
1571
|
+
shadingColor = mark.color;
|
|
1572
|
+
break;
|
|
1573
|
+
case "highlight":
|
|
1574
|
+
highlightColor = mark.color;
|
|
1575
|
+
break;
|
|
1576
|
+
case "charSpacing":
|
|
1577
|
+
attrs.charSpacing = mark.val;
|
|
1578
|
+
break;
|
|
1579
|
+
case "kerning":
|
|
1580
|
+
attrs.kerning = mark.val;
|
|
1581
|
+
break;
|
|
1582
|
+
case "textFill":
|
|
1583
|
+
attrs.textFill = mark.xml;
|
|
1584
|
+
break;
|
|
1585
|
+
case "fontFamily":
|
|
1586
|
+
attrs.fontFamily = mark.val;
|
|
1587
|
+
break;
|
|
1588
|
+
case "fontSize":
|
|
1589
|
+
attrs.fontSize = mark.val;
|
|
1590
|
+
break;
|
|
1591
|
+
case "textColor":
|
|
1592
|
+
attrs.textColor = mark.color;
|
|
1593
|
+
break;
|
|
1594
|
+
case "smallCaps":
|
|
1595
|
+
supported.push("smallCaps");
|
|
1596
|
+
break;
|
|
1597
|
+
case "allCaps":
|
|
1598
|
+
supported.push("allCaps");
|
|
1599
|
+
break;
|
|
1600
|
+
case "lang":
|
|
1601
|
+
break;
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
if (highlightColor || shadingColor) {
|
|
1605
|
+
attrs.backgroundColor = highlightColor ?? shadingColor;
|
|
1606
|
+
}
|
|
1607
|
+
const hasAttrs = Object.keys(attrs).length > 0;
|
|
1608
|
+
return hasAttrs ? { marks: supported, markAttrs: attrs } : { marks: supported };
|
|
1609
|
+
}
|
|
1610
|
+
function normalizeDocumentRoot2(content) {
|
|
1611
|
+
if (content && typeof content === "object" && (content.type === "doc" || content.type === "document_root")) {
|
|
1612
|
+
return content;
|
|
1613
|
+
}
|
|
1614
|
+
if (Array.isArray(content)) {
|
|
1615
|
+
return {
|
|
1616
|
+
type: "doc",
|
|
1617
|
+
children: content.filter(
|
|
1618
|
+
(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")
|
|
1619
|
+
)
|
|
1620
|
+
};
|
|
1621
|
+
}
|
|
1622
|
+
return {
|
|
1623
|
+
type: "doc",
|
|
1624
|
+
children: [{ type: "paragraph", children: [] }]
|
|
1625
|
+
};
|
|
1626
|
+
}
|
|
1627
|
+
function createFloatingImageDetail(altText, floating) {
|
|
1628
|
+
const parts = [altText ? `Alt text ${altText}.` : "Floating image rendered inline in the editor."];
|
|
1629
|
+
if (floating?.wrap) {
|
|
1630
|
+
parts.push(`Wrap ${floating.wrap}.`);
|
|
1631
|
+
}
|
|
1632
|
+
if (floating?.horizontalPosition?.align || floating?.horizontalPosition?.offset !== void 0) {
|
|
1633
|
+
parts.push(
|
|
1634
|
+
`Horizontal ${floating.horizontalPosition.align ?? floating.horizontalPosition.offset}.`
|
|
1635
|
+
);
|
|
1636
|
+
}
|
|
1637
|
+
if (floating?.verticalPosition?.align || floating?.verticalPosition?.offset !== void 0) {
|
|
1638
|
+
parts.push(
|
|
1639
|
+
`Vertical ${floating.verticalPosition.align ?? floating.verticalPosition.offset}.`
|
|
1640
|
+
);
|
|
1641
|
+
}
|
|
1642
|
+
return parts.join(" ");
|
|
1643
|
+
}
|
|
1644
|
+
function hasMediaItem(media, mediaId) {
|
|
1645
|
+
return mediaId in media.items;
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1648
|
+
// src/core/state/text-transaction.ts
|
|
1649
|
+
var TextTransactionError = class extends Error {
|
|
1650
|
+
code;
|
|
1651
|
+
constructor(code, message) {
|
|
1652
|
+
super(message);
|
|
1653
|
+
this.name = "TextTransactionError";
|
|
1654
|
+
this.code = code;
|
|
1655
|
+
}
|
|
1656
|
+
};
|
|
1657
|
+
|
|
1658
|
+
// src/core/commands/structural-helpers.ts
|
|
1659
|
+
function resolveParagraphScope(document, selection) {
|
|
1660
|
+
const root = asDocumentRoot(document);
|
|
1661
|
+
if (!root) {
|
|
1662
|
+
return null;
|
|
1663
|
+
}
|
|
1664
|
+
const surface = createEditorSurfaceSnapshot(document, selection);
|
|
1665
|
+
const selectionFrom = Math.min(selection.anchor, selection.head);
|
|
1666
|
+
const selectionTo = Math.max(selection.anchor, selection.head);
|
|
1667
|
+
for (let blockIndex = 0; blockIndex < root.children.length; blockIndex += 1) {
|
|
1668
|
+
const block = root.children[blockIndex];
|
|
1669
|
+
const surfaceBlock = surface.blocks[blockIndex];
|
|
1670
|
+
if (!surfaceBlock) {
|
|
1671
|
+
continue;
|
|
1672
|
+
}
|
|
1673
|
+
if (block.type === "paragraph" && surfaceBlock.kind === "paragraph" && selectionWithinRange(selectionFrom, selectionTo, surfaceBlock.from, surfaceBlock.to)) {
|
|
1674
|
+
return {
|
|
1675
|
+
kind: "top-level",
|
|
1676
|
+
blockIndex,
|
|
1677
|
+
paragraph: cloneParagraph(block),
|
|
1678
|
+
paragraphStart: surfaceBlock.from
|
|
1679
|
+
};
|
|
1680
|
+
}
|
|
1681
|
+
if (block.type !== "table" || surfaceBlock.kind !== "table") {
|
|
1682
|
+
continue;
|
|
1683
|
+
}
|
|
1684
|
+
for (let rowIndex = 0; rowIndex < block.rows.length; rowIndex += 1) {
|
|
1685
|
+
const row = block.rows[rowIndex];
|
|
1686
|
+
const surfaceRow = surfaceBlock.rows[rowIndex];
|
|
1687
|
+
if (!surfaceRow) {
|
|
1688
|
+
continue;
|
|
1689
|
+
}
|
|
1690
|
+
for (let cellIndex = 0; cellIndex < row.cells.length; cellIndex += 1) {
|
|
1691
|
+
const cell = row.cells[cellIndex];
|
|
1692
|
+
const surfaceCell = surfaceRow.cells[cellIndex];
|
|
1693
|
+
if (!surfaceCell) {
|
|
1694
|
+
continue;
|
|
1695
|
+
}
|
|
1696
|
+
for (let childIndex = 0; childIndex < cell.children.length; childIndex += 1) {
|
|
1697
|
+
const child = cell.children[childIndex];
|
|
1698
|
+
const surfaceChild = surfaceCell.content[childIndex];
|
|
1699
|
+
if (child?.type === "paragraph" && surfaceChild?.kind === "paragraph" && selectionWithinRange(selectionFrom, selectionTo, surfaceChild.from, surfaceChild.to)) {
|
|
1700
|
+
return {
|
|
1701
|
+
kind: "table-cell",
|
|
1702
|
+
tableBlockIndex: blockIndex,
|
|
1703
|
+
rowIndex,
|
|
1704
|
+
cellIndex,
|
|
1705
|
+
childIndex,
|
|
1706
|
+
paragraph: cloneParagraph(child),
|
|
1707
|
+
paragraphStart: surfaceChild.from
|
|
1708
|
+
};
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
return null;
|
|
1715
|
+
}
|
|
1716
|
+
function replaceParagraphScope(document, scope, replacementParagraphs) {
|
|
1717
|
+
const root = asDocumentRoot(document);
|
|
1718
|
+
if (!root) {
|
|
1719
|
+
return document;
|
|
1720
|
+
}
|
|
1721
|
+
const nextRoot = scope.kind === "top-level" ? {
|
|
1722
|
+
...root,
|
|
1723
|
+
children: [
|
|
1724
|
+
...root.children.slice(0, scope.blockIndex),
|
|
1725
|
+
...replacementParagraphs,
|
|
1726
|
+
...root.children.slice(scope.blockIndex + 1)
|
|
1727
|
+
]
|
|
1728
|
+
} : {
|
|
1729
|
+
...root,
|
|
1730
|
+
children: root.children.map((child, blockIndex) => {
|
|
1731
|
+
if (blockIndex !== scope.tableBlockIndex || child.type !== "table") {
|
|
1732
|
+
return child;
|
|
1733
|
+
}
|
|
1734
|
+
return {
|
|
1735
|
+
...child,
|
|
1736
|
+
rows: child.rows.map((row, rowIndex) => {
|
|
1737
|
+
if (rowIndex !== scope.rowIndex) {
|
|
1738
|
+
return row;
|
|
1739
|
+
}
|
|
1740
|
+
return {
|
|
1741
|
+
...row,
|
|
1742
|
+
cells: row.cells.map((cell, cellIndex) => {
|
|
1743
|
+
if (cellIndex !== scope.cellIndex) {
|
|
1744
|
+
return cell;
|
|
1745
|
+
}
|
|
1746
|
+
return {
|
|
1747
|
+
...cell,
|
|
1748
|
+
children: [
|
|
1749
|
+
...cell.children.slice(0, scope.childIndex),
|
|
1750
|
+
...replacementParagraphs,
|
|
1751
|
+
...cell.children.slice(scope.childIndex + 1)
|
|
1752
|
+
]
|
|
1753
|
+
};
|
|
1754
|
+
})
|
|
1755
|
+
};
|
|
1756
|
+
})
|
|
1757
|
+
};
|
|
1758
|
+
})
|
|
1759
|
+
};
|
|
1760
|
+
return {
|
|
1761
|
+
...document,
|
|
1762
|
+
content: nextRoot
|
|
1763
|
+
};
|
|
1764
|
+
}
|
|
1765
|
+
function asDocumentRoot(document) {
|
|
1766
|
+
const root = document.content;
|
|
1767
|
+
if (!root || root.type !== "doc" || !Array.isArray(root.children)) {
|
|
1768
|
+
return null;
|
|
1769
|
+
}
|
|
1770
|
+
return root;
|
|
1771
|
+
}
|
|
1772
|
+
function selectionWithinRange(selectionFrom, selectionTo, rangeFrom, rangeTo) {
|
|
1773
|
+
return selectionFrom >= rangeFrom && selectionTo <= rangeTo;
|
|
1774
|
+
}
|
|
1775
|
+
function cloneParagraph(paragraph) {
|
|
1776
|
+
return structuredClone(paragraph);
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
// src/core/commands/image-commands.ts
|
|
1780
|
+
function insertImage(document, selection, _data, mimeType, _width, _height, context = { timestamp: (/* @__PURE__ */ new Date()).toISOString() }) {
|
|
1781
|
+
const scope = resolveParagraphScope(document, selection);
|
|
1782
|
+
if (!scope) {
|
|
1783
|
+
throw new TextTransactionError(
|
|
1784
|
+
"unsupported_content",
|
|
1785
|
+
"Image insertion is only supported when the selection stays within one paragraph-backed scope."
|
|
1786
|
+
);
|
|
1787
|
+
}
|
|
1788
|
+
const localDocument = {
|
|
1789
|
+
...document,
|
|
1790
|
+
content: {
|
|
1791
|
+
type: "doc",
|
|
1792
|
+
children: [scope.paragraph]
|
|
1793
|
+
}
|
|
1794
|
+
};
|
|
1795
|
+
const localSelection = createSelectionSnapshot(
|
|
1796
|
+
selection.anchor - scope.paragraphStart,
|
|
1797
|
+
selection.head - scope.paragraphStart
|
|
1798
|
+
);
|
|
1799
|
+
const localResult = insertImageIntoParagraph(
|
|
1800
|
+
localDocument,
|
|
1801
|
+
localSelection,
|
|
1802
|
+
_data,
|
|
1803
|
+
mimeType,
|
|
1804
|
+
_width,
|
|
1805
|
+
_height,
|
|
1806
|
+
context
|
|
1807
|
+
);
|
|
1808
|
+
const nextDocument = replaceParagraphScope(
|
|
1809
|
+
{
|
|
1810
|
+
...document,
|
|
1811
|
+
media: localResult.document.media
|
|
1812
|
+
},
|
|
1813
|
+
scope,
|
|
1814
|
+
[
|
|
1815
|
+
{
|
|
1816
|
+
...scope.paragraph,
|
|
1817
|
+
children: localResult.document.content.type === "doc" ? localResult.document.content.children.find(
|
|
1818
|
+
(block) => block.type === "paragraph"
|
|
1819
|
+
)?.children ?? scope.paragraph.children : scope.paragraph.children
|
|
1820
|
+
}
|
|
1821
|
+
]
|
|
1822
|
+
);
|
|
1823
|
+
return {
|
|
1824
|
+
...localResult,
|
|
1825
|
+
document: {
|
|
1826
|
+
...nextDocument,
|
|
1827
|
+
updatedAt: context.timestamp,
|
|
1828
|
+
media: localResult.document.media
|
|
1829
|
+
},
|
|
1830
|
+
selection: createSelectionSnapshot(
|
|
1831
|
+
localResult.selection.anchor + scope.paragraphStart,
|
|
1832
|
+
localResult.selection.head + scope.paragraphStart
|
|
1833
|
+
),
|
|
1834
|
+
mapping: {
|
|
1835
|
+
...localResult.mapping,
|
|
1836
|
+
steps: localResult.mapping.steps.map((step) => ({
|
|
1837
|
+
...step,
|
|
1838
|
+
from: step.from + scope.paragraphStart,
|
|
1839
|
+
to: step.to + scope.paragraphStart
|
|
1840
|
+
}))
|
|
1841
|
+
}
|
|
1842
|
+
};
|
|
1843
|
+
}
|
|
1844
|
+
function insertImageIntoParagraph(document, selection, _data, mimeType, width, height, context = { timestamp: (/* @__PURE__ */ new Date()).toISOString() }) {
|
|
1845
|
+
const story = parseTextStory(document.content);
|
|
1846
|
+
const from = Math.min(selection.anchor, selection.head);
|
|
1847
|
+
const to = Math.max(selection.anchor, selection.head);
|
|
1848
|
+
if (from > story.size || to > story.size) {
|
|
1849
|
+
throw new TextTransactionError(
|
|
1850
|
+
"invalid_selection",
|
|
1851
|
+
`Selection ${from}-${to} exceeds story size ${story.size}.`
|
|
1852
|
+
);
|
|
1853
|
+
}
|
|
1854
|
+
const rangeUnits = story.units.slice(from, to);
|
|
1855
|
+
const protectedUnit = rangeUnits.find(
|
|
1856
|
+
(unit) => unit.kind === "opaque_inline" || unit.kind === "opaque_block" || unit.kind === "image"
|
|
1857
|
+
);
|
|
1858
|
+
if (protectedUnit) {
|
|
1859
|
+
throw new TextTransactionError(
|
|
1860
|
+
"unsupported_content",
|
|
1861
|
+
`Image insertion range crosses protected ${protectedUnit.kind} content.`
|
|
1862
|
+
);
|
|
1863
|
+
}
|
|
1864
|
+
const ext = mimeTypeToExtension(mimeType);
|
|
1865
|
+
const timestamp = context.timestamp.replace(/[^0-9]/g, "").slice(0, 14);
|
|
1866
|
+
const mediaId = `media:img-${timestamp}`;
|
|
1867
|
+
const packagePartName = `/word/media/${mediaId.replace("media:", "")}.${ext}`;
|
|
1868
|
+
const mediaItem = {
|
|
1869
|
+
mediaId,
|
|
1870
|
+
contentType: mimeType,
|
|
1871
|
+
filename: `${mediaId.replace("media:", "")}.${ext}`,
|
|
1872
|
+
packagePartName,
|
|
1873
|
+
...context.altText ? { altText: context.altText } : {},
|
|
1874
|
+
...context.display ? { display: context.display } : {}
|
|
1875
|
+
};
|
|
1876
|
+
const existingItems = document.media && "items" in document.media ? document.media.items : {};
|
|
1877
|
+
const updatedMedia = {
|
|
1878
|
+
items: {
|
|
1879
|
+
...existingItems,
|
|
1880
|
+
[mediaId]: mediaItem
|
|
1881
|
+
}
|
|
1882
|
+
};
|
|
1883
|
+
const nextUnits = [
|
|
1884
|
+
...story.units.slice(0, from).map(cloneStoryUnit),
|
|
1885
|
+
{
|
|
1886
|
+
kind: "image",
|
|
1887
|
+
mediaId,
|
|
1888
|
+
...context.altText ? { altText: context.altText } : {}
|
|
1889
|
+
},
|
|
1890
|
+
...story.units.slice(to).map(cloneStoryUnit)
|
|
1891
|
+
];
|
|
1892
|
+
const nextStory = {
|
|
1893
|
+
firstParagraph: cloneParagraphProperties(story.firstParagraph),
|
|
1894
|
+
units: nextUnits,
|
|
1895
|
+
size: nextUnits.length
|
|
1896
|
+
};
|
|
1897
|
+
const caret = from + 1;
|
|
1898
|
+
return {
|
|
1899
|
+
document: {
|
|
1900
|
+
...document,
|
|
1901
|
+
updatedAt: context.timestamp,
|
|
1902
|
+
media: updatedMedia,
|
|
1903
|
+
content: serializeTextStory(nextStory)
|
|
1904
|
+
},
|
|
1905
|
+
selection: createSelectionSnapshot(caret, caret),
|
|
1906
|
+
mapping: {
|
|
1907
|
+
steps: [{ from, to, insertSize: 1 }]
|
|
1908
|
+
},
|
|
1909
|
+
mediaId
|
|
1910
|
+
};
|
|
1911
|
+
}
|
|
1912
|
+
var MIN_DIMENSION_EMU = 91440;
|
|
1913
|
+
var MAX_DIMENSION_EMU = 27432e3;
|
|
1914
|
+
function clampDimension(value) {
|
|
1915
|
+
return Math.max(MIN_DIMENSION_EMU, Math.min(MAX_DIMENSION_EMU, Math.round(value)));
|
|
1916
|
+
}
|
|
1917
|
+
function resizeImage(document, mediaId, dimensions, timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
1918
|
+
const media = document.media;
|
|
1919
|
+
if (!media?.items[mediaId]) {
|
|
1920
|
+
throw new TextTransactionError(
|
|
1921
|
+
"invalid_selection",
|
|
1922
|
+
`Media item ${mediaId} does not exist in the catalog.`
|
|
1923
|
+
);
|
|
1924
|
+
}
|
|
1925
|
+
const clamped = {
|
|
1926
|
+
widthEmu: clampDimension(dimensions.widthEmu),
|
|
1927
|
+
heightEmu: clampDimension(dimensions.heightEmu)
|
|
1928
|
+
};
|
|
1929
|
+
const updatedItem = {
|
|
1930
|
+
...media.items[mediaId],
|
|
1931
|
+
widthEmu: clamped.widthEmu,
|
|
1932
|
+
heightEmu: clamped.heightEmu
|
|
1933
|
+
};
|
|
1934
|
+
return {
|
|
1935
|
+
document: {
|
|
1936
|
+
...document,
|
|
1937
|
+
updatedAt: timestamp,
|
|
1938
|
+
media: {
|
|
1939
|
+
items: {
|
|
1940
|
+
...media.items,
|
|
1941
|
+
[mediaId]: updatedItem
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
},
|
|
1945
|
+
dimensions: clamped
|
|
1946
|
+
};
|
|
1947
|
+
}
|
|
1948
|
+
function repositionFloatingImage(document, mediaId, offsets, timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
1949
|
+
const blocks = document.content.children;
|
|
1950
|
+
let found = false;
|
|
1951
|
+
const nextBlocks = blocks.map((block) => {
|
|
1952
|
+
if (block.type !== "paragraph") return block;
|
|
1953
|
+
const nextChildren = block.children.map((child) => {
|
|
1954
|
+
if (child.type !== "image" || child.mediaId !== mediaId) return child;
|
|
1955
|
+
if (child.display !== "floating") {
|
|
1956
|
+
throw new TextTransactionError(
|
|
1957
|
+
"unsupported_content",
|
|
1958
|
+
`Image ${mediaId} is not floating \u2014 reposition requires display: "floating".`
|
|
1959
|
+
);
|
|
1960
|
+
}
|
|
1961
|
+
found = true;
|
|
1962
|
+
const prevFloating = child.floating ?? {};
|
|
1963
|
+
return {
|
|
1964
|
+
...child,
|
|
1965
|
+
floating: {
|
|
1966
|
+
...prevFloating,
|
|
1967
|
+
...offsets.horizontalOffsetEmu !== void 0 ? {
|
|
1968
|
+
horizontalPosition: {
|
|
1969
|
+
...prevFloating.horizontalPosition,
|
|
1970
|
+
offset: offsets.horizontalOffsetEmu
|
|
1971
|
+
}
|
|
1972
|
+
} : {},
|
|
1973
|
+
...offsets.verticalOffsetEmu !== void 0 ? {
|
|
1974
|
+
verticalPosition: {
|
|
1975
|
+
...prevFloating.verticalPosition,
|
|
1976
|
+
offset: offsets.verticalOffsetEmu
|
|
1977
|
+
}
|
|
1978
|
+
} : {}
|
|
1979
|
+
}
|
|
1980
|
+
};
|
|
1981
|
+
});
|
|
1982
|
+
return { ...block, children: nextChildren };
|
|
1983
|
+
});
|
|
1984
|
+
if (!found) {
|
|
1985
|
+
throw new TextTransactionError(
|
|
1986
|
+
"invalid_selection",
|
|
1987
|
+
`No floating image with mediaId ${mediaId} found in document content.`
|
|
1988
|
+
);
|
|
1989
|
+
}
|
|
1990
|
+
return {
|
|
1991
|
+
document: {
|
|
1992
|
+
...document,
|
|
1993
|
+
updatedAt: timestamp,
|
|
1994
|
+
content: { ...document.content, children: nextBlocks }
|
|
1995
|
+
}
|
|
1996
|
+
};
|
|
1997
|
+
}
|
|
1998
|
+
function mimeTypeToExtension(mimeType) {
|
|
1999
|
+
switch (mimeType.toLowerCase()) {
|
|
2000
|
+
case "image/png":
|
|
2001
|
+
return "png";
|
|
2002
|
+
case "image/jpeg":
|
|
2003
|
+
case "image/jpg":
|
|
2004
|
+
return "jpg";
|
|
2005
|
+
case "image/gif":
|
|
2006
|
+
return "gif";
|
|
2007
|
+
case "image/webp":
|
|
2008
|
+
return "webp";
|
|
2009
|
+
case "image/svg+xml":
|
|
2010
|
+
return "svg";
|
|
2011
|
+
case "image/bmp":
|
|
2012
|
+
return "bmp";
|
|
2013
|
+
default:
|
|
2014
|
+
return "bin";
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2018
|
+
0 && (module.exports = {
|
|
2019
|
+
insertImage,
|
|
2020
|
+
repositionFloatingImage,
|
|
2021
|
+
resizeImage
|
|
2022
|
+
});
|
|
2023
|
+
//# sourceMappingURL=image-commands.cjs.map
|