@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,1237 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseTextStory
|
|
3
|
+
} from "./chunk-KLMXQVYK.js";
|
|
4
|
+
import {
|
|
5
|
+
createEditorSurfaceSnapshot,
|
|
6
|
+
resolveSectionVariants,
|
|
7
|
+
sectionSupportsStoryTarget,
|
|
8
|
+
storyTargetKey
|
|
9
|
+
} from "./chunk-EILUG3VB.js";
|
|
10
|
+
import {
|
|
11
|
+
createSelectionSnapshot
|
|
12
|
+
} from "./chunk-5FN54NDH.js";
|
|
13
|
+
import {
|
|
14
|
+
MAIN_STORY_TARGET,
|
|
15
|
+
createDetachedAnchor,
|
|
16
|
+
mapAnchor,
|
|
17
|
+
normalizeRange
|
|
18
|
+
} from "./chunk-EBI3BX6U.js";
|
|
19
|
+
|
|
20
|
+
// src/core/selection/review-anchors.ts
|
|
21
|
+
function detachReviewAnchor(lastKnownRange, reason) {
|
|
22
|
+
return createDetachedAnchor(lastKnownRange, reason);
|
|
23
|
+
}
|
|
24
|
+
function mapReviewAnchor(anchor, mapping) {
|
|
25
|
+
return mapAnchor(anchor, mapping);
|
|
26
|
+
}
|
|
27
|
+
function getAnchorRange(anchor) {
|
|
28
|
+
if (anchor.kind === "range") {
|
|
29
|
+
return normalizeRange(anchor.range);
|
|
30
|
+
}
|
|
31
|
+
if (anchor.kind === "node") {
|
|
32
|
+
return { from: anchor.at, to: anchor.at };
|
|
33
|
+
}
|
|
34
|
+
return normalizeRange(anchor.lastKnownRange);
|
|
35
|
+
}
|
|
36
|
+
function mappingTouchesAnchorContent(anchor, mapping) {
|
|
37
|
+
const range = getAnchorRange(anchor);
|
|
38
|
+
if (range.from === range.to) {
|
|
39
|
+
return mapping.steps.some(
|
|
40
|
+
(step) => step.from <= range.from && step.to >= range.to
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return mapping.steps.some(
|
|
44
|
+
(step) => step.from < range.to && step.to > range.from
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
function rangeStaysWithinSingleParagraph(content, range) {
|
|
48
|
+
const normalized = normalizeRange(range);
|
|
49
|
+
if (normalized.from === normalized.to) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
const surfaceBlocks = readSurfaceBlocks(content);
|
|
53
|
+
if (surfaceBlocks) {
|
|
54
|
+
return surfaceBlocks.some(
|
|
55
|
+
(block) => block.kind === "paragraph" && normalized.from >= block.from && normalized.to <= block.to
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
const story = parseTextStory(content);
|
|
59
|
+
const upperBound = Math.min(normalized.to, story.units.length);
|
|
60
|
+
for (let index = Math.max(0, normalized.from); index < upperBound; index += 1) {
|
|
61
|
+
const unit = story.units[index];
|
|
62
|
+
if (!unit) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (unit.kind === "paragraph_break" || unit.kind === "opaque_block") {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
function canCreateDocxCommentAnchor(content, anchor) {
|
|
72
|
+
if (anchor.kind !== "range") {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
const normalized = normalizeRange(anchor.range);
|
|
76
|
+
if (normalized.from === normalized.to) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
return rangeStaysWithinSingleParagraph(content, normalized);
|
|
80
|
+
}
|
|
81
|
+
function readSurfaceBlocks(content) {
|
|
82
|
+
if (!content || typeof content !== "object" || !("blocks" in content)) {
|
|
83
|
+
return void 0;
|
|
84
|
+
}
|
|
85
|
+
const blocks = content.blocks;
|
|
86
|
+
if (!Array.isArray(blocks)) {
|
|
87
|
+
return void 0;
|
|
88
|
+
}
|
|
89
|
+
const normalized = flattenSurfaceBlocks(blocks);
|
|
90
|
+
return normalized.length > 0 ? normalized : void 0;
|
|
91
|
+
}
|
|
92
|
+
function flattenSurfaceBlocks(blocks) {
|
|
93
|
+
const flattened = [];
|
|
94
|
+
for (const block of blocks) {
|
|
95
|
+
if (!block || typeof block !== "object" || typeof block.kind !== "string" || typeof block.from !== "number" || typeof block.to !== "number") {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
flattened.push({
|
|
99
|
+
kind: block.kind,
|
|
100
|
+
from: block.from,
|
|
101
|
+
to: block.to
|
|
102
|
+
});
|
|
103
|
+
if (block.kind === "table" && Array.isArray(block.rows)) {
|
|
104
|
+
for (const row of block.rows) {
|
|
105
|
+
for (const cell of row.cells ?? []) {
|
|
106
|
+
if (cell && typeof cell === "object" && Array.isArray(cell.content)) {
|
|
107
|
+
flattened.push(...flattenSurfaceBlocks(cell.content));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (block.kind === "sdt_block" && Array.isArray(block.children)) {
|
|
113
|
+
flattened.push(...flattenSurfaceBlocks(block.children));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return flattened;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/runtime/document-layout.ts
|
|
120
|
+
function buildResolvedSections(document) {
|
|
121
|
+
const mainSurface = createEditorSurfaceSnapshot(
|
|
122
|
+
document,
|
|
123
|
+
createSelectionSnapshot(0, 0),
|
|
124
|
+
MAIN_STORY_TARGET
|
|
125
|
+
);
|
|
126
|
+
const sections = [];
|
|
127
|
+
let sectionStart = 0;
|
|
128
|
+
let sectionIndex = 0;
|
|
129
|
+
for (const [index, block] of document.content.children.entries()) {
|
|
130
|
+
if (block.type !== "section_break") {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const surfaceBlock = mainSurface.blocks[index];
|
|
134
|
+
sections.push({
|
|
135
|
+
index: sectionIndex,
|
|
136
|
+
start: sectionStart,
|
|
137
|
+
end: surfaceBlock?.from ?? sectionStart,
|
|
138
|
+
properties: block.sectionProperties
|
|
139
|
+
});
|
|
140
|
+
sectionStart = surfaceBlock?.to ?? sectionStart;
|
|
141
|
+
sectionIndex += 1;
|
|
142
|
+
}
|
|
143
|
+
sections.push({
|
|
144
|
+
index: sectionIndex,
|
|
145
|
+
start: sectionStart,
|
|
146
|
+
end: mainSurface.storySize,
|
|
147
|
+
properties: document.subParts?.finalSectionProperties
|
|
148
|
+
});
|
|
149
|
+
return sections;
|
|
150
|
+
}
|
|
151
|
+
function findSectionForPosition(sections, position) {
|
|
152
|
+
for (const section of sections) {
|
|
153
|
+
if (position < section.end) {
|
|
154
|
+
return section;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return sections[sections.length - 1] ?? {
|
|
158
|
+
index: 0,
|
|
159
|
+
start: 0,
|
|
160
|
+
end: 0
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function buildPageLayoutSnapshot(sectionIndex, properties, subParts) {
|
|
164
|
+
const pageSize = properties?.pageSize ?? {
|
|
165
|
+
width: 12240,
|
|
166
|
+
height: 15840,
|
|
167
|
+
orientation: "portrait"
|
|
168
|
+
};
|
|
169
|
+
const margins = properties?.pageMargins ?? {
|
|
170
|
+
top: 1440,
|
|
171
|
+
right: 1440,
|
|
172
|
+
bottom: 1440,
|
|
173
|
+
left: 1440,
|
|
174
|
+
header: 720,
|
|
175
|
+
footer: 720,
|
|
176
|
+
gutter: 0
|
|
177
|
+
};
|
|
178
|
+
const columns = properties?.columns;
|
|
179
|
+
const explicitColumns = columns?.columns ?? [];
|
|
180
|
+
const differentOddEvenPages = Boolean(subParts?.settings?.evenAndOddHeaders);
|
|
181
|
+
return {
|
|
182
|
+
sectionIndex,
|
|
183
|
+
...properties?.sectionType ? { sectionType: properties.sectionType } : {},
|
|
184
|
+
pageWidth: pageSize.width,
|
|
185
|
+
pageHeight: pageSize.height,
|
|
186
|
+
marginTop: margins.top,
|
|
187
|
+
marginBottom: margins.bottom,
|
|
188
|
+
marginLeft: margins.left,
|
|
189
|
+
marginRight: margins.right,
|
|
190
|
+
headerMargin: margins.header ?? 720,
|
|
191
|
+
footerMargin: margins.footer ?? 720,
|
|
192
|
+
gutter: margins.gutter ?? 0,
|
|
193
|
+
orientation: pageSize.orientation ?? "portrait",
|
|
194
|
+
columns: explicitColumns.length > 0 ? explicitColumns.length : columns?.count ?? 1,
|
|
195
|
+
differentFirstPage: Boolean(properties?.titlePage),
|
|
196
|
+
differentOddEvenPages,
|
|
197
|
+
...properties?.pageNumbering ? {
|
|
198
|
+
pageNumbering: {
|
|
199
|
+
...properties.pageNumbering.format ? { format: properties.pageNumbering.format } : {},
|
|
200
|
+
...properties.pageNumbering.start !== void 0 ? { start: properties.pageNumbering.start } : {},
|
|
201
|
+
...properties.pageNumbering.chapStyle ? { chapterStyle: properties.pageNumbering.chapStyle } : {},
|
|
202
|
+
...properties.pageNumbering.chapSep ? { chapterSeparator: properties.pageNumbering.chapSep } : {}
|
|
203
|
+
}
|
|
204
|
+
} : {},
|
|
205
|
+
...properties?.lineNumbering ? {
|
|
206
|
+
lineNumbering: {
|
|
207
|
+
...properties.lineNumbering.countBy !== void 0 ? { countBy: properties.lineNumbering.countBy } : {},
|
|
208
|
+
...properties.lineNumbering.start !== void 0 ? { start: properties.lineNumbering.start } : {},
|
|
209
|
+
...properties.lineNumbering.distance !== void 0 ? { distance: properties.lineNumbering.distance } : {},
|
|
210
|
+
...properties.lineNumbering.restart ? { restart: properties.lineNumbering.restart } : {}
|
|
211
|
+
}
|
|
212
|
+
} : {},
|
|
213
|
+
...properties?.pageBorders ? {
|
|
214
|
+
pageBorders: {
|
|
215
|
+
...properties.pageBorders.top ? { top: { ...properties.pageBorders.top } } : {},
|
|
216
|
+
...properties.pageBorders.left ? { left: { ...properties.pageBorders.left } } : {},
|
|
217
|
+
...properties.pageBorders.bottom ? { bottom: { ...properties.pageBorders.bottom } } : {},
|
|
218
|
+
...properties.pageBorders.right ? { right: { ...properties.pageBorders.right } } : {},
|
|
219
|
+
...properties.pageBorders.offsetFrom ? { offsetFrom: properties.pageBorders.offsetFrom } : {},
|
|
220
|
+
...properties.pageBorders.display ? { display: properties.pageBorders.display } : {},
|
|
221
|
+
...properties.pageBorders.zOrder ? { zOrder: properties.pageBorders.zOrder } : {}
|
|
222
|
+
}
|
|
223
|
+
} : {},
|
|
224
|
+
...properties?.documentGrid ? {
|
|
225
|
+
documentGrid: {
|
|
226
|
+
...properties.documentGrid.type ? { type: properties.documentGrid.type } : {},
|
|
227
|
+
...properties.documentGrid.linePitch !== void 0 ? { linePitch: properties.documentGrid.linePitch } : {},
|
|
228
|
+
...properties.documentGrid.charSpace !== void 0 ? { charSpace: properties.documentGrid.charSpace } : {}
|
|
229
|
+
}
|
|
230
|
+
} : {},
|
|
231
|
+
columnDefinitions: explicitColumns,
|
|
232
|
+
equalWidthColumns: columns?.equalWidth ?? (explicitColumns.length === 0 || explicitColumns.length <= 1),
|
|
233
|
+
columnSeparator: Boolean(columns?.separator),
|
|
234
|
+
headerVariants: resolveSectionVariants(
|
|
235
|
+
"header",
|
|
236
|
+
sectionIndex,
|
|
237
|
+
properties?.headerReferences,
|
|
238
|
+
subParts?.headers ?? []
|
|
239
|
+
),
|
|
240
|
+
footerVariants: resolveSectionVariants(
|
|
241
|
+
"footer",
|
|
242
|
+
sectionIndex,
|
|
243
|
+
properties?.footerReferences,
|
|
244
|
+
subParts?.footers ?? []
|
|
245
|
+
)
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function resolveSectionForStoryTarget(document, sections, target) {
|
|
249
|
+
if (target.kind === "main" || sections.length === 0) {
|
|
250
|
+
return sections[0];
|
|
251
|
+
}
|
|
252
|
+
if (target.kind === "header") {
|
|
253
|
+
if (target.sectionIndex !== void 0) {
|
|
254
|
+
const section = sections.find((candidate) => candidate.index === target.sectionIndex);
|
|
255
|
+
return section && sectionSupportsStoryTarget(document, target.sectionIndex, target) ? section : void 0;
|
|
256
|
+
}
|
|
257
|
+
return findSectionByStoryReference(
|
|
258
|
+
document,
|
|
259
|
+
sections,
|
|
260
|
+
target,
|
|
261
|
+
"header"
|
|
262
|
+
) ?? sections[0];
|
|
263
|
+
}
|
|
264
|
+
if (target.kind === "footer") {
|
|
265
|
+
if (target.sectionIndex !== void 0) {
|
|
266
|
+
const section = sections.find((candidate) => candidate.index === target.sectionIndex);
|
|
267
|
+
return section && sectionSupportsStoryTarget(document, target.sectionIndex, target) ? section : void 0;
|
|
268
|
+
}
|
|
269
|
+
return findSectionByStoryReference(
|
|
270
|
+
document,
|
|
271
|
+
sections,
|
|
272
|
+
target,
|
|
273
|
+
"footer"
|
|
274
|
+
) ?? sections[0];
|
|
275
|
+
}
|
|
276
|
+
return void 0;
|
|
277
|
+
}
|
|
278
|
+
function resolveActiveSection(state, activeStory, sections, storySelections) {
|
|
279
|
+
if (sections.length === 0) {
|
|
280
|
+
return void 0;
|
|
281
|
+
}
|
|
282
|
+
if (activeStory.kind === "main") {
|
|
283
|
+
return findSectionForPosition(sections, state.selection.head);
|
|
284
|
+
}
|
|
285
|
+
const referencedSection = resolveSectionForStoryTarget(
|
|
286
|
+
state.document,
|
|
287
|
+
sections,
|
|
288
|
+
activeStory
|
|
289
|
+
);
|
|
290
|
+
if (referencedSection) {
|
|
291
|
+
return referencedSection;
|
|
292
|
+
}
|
|
293
|
+
const mainSelection = storySelections?.get(storyTargetKey(MAIN_STORY_TARGET)) ?? state.selection;
|
|
294
|
+
return findSectionForPosition(sections, mainSelection.head);
|
|
295
|
+
}
|
|
296
|
+
function findSectionByStoryReference(document, sections, target, kind) {
|
|
297
|
+
const propertyKey = kind === "header" ? "headerReferences" : "footerReferences";
|
|
298
|
+
const documents = kind === "header" ? document.subParts?.headers ?? [] : document.subParts?.footers ?? [];
|
|
299
|
+
return sections.find(
|
|
300
|
+
(section) => section.properties?.[propertyKey]?.some(
|
|
301
|
+
(ref) => ref.relationshipId === target.relationshipId && ref.variant === target.variant
|
|
302
|
+
)
|
|
303
|
+
) ?? sections.find(
|
|
304
|
+
(section) => documents.some(
|
|
305
|
+
(entry) => entry.relationshipId === target.relationshipId && entry.variant === target.variant && entry.sectionIndex === section.index
|
|
306
|
+
)
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// src/runtime/view-state.ts
|
|
311
|
+
var MIN_ZOOM_PERCENT = 50;
|
|
312
|
+
var MAX_ZOOM_PERCENT = 200;
|
|
313
|
+
var DEFAULT_VIEW_STATE = {
|
|
314
|
+
viewMode: "editing",
|
|
315
|
+
documentMode: "editing",
|
|
316
|
+
workspaceMode: "canvas",
|
|
317
|
+
zoomLevel: 100,
|
|
318
|
+
isFocused: false,
|
|
319
|
+
caretAffinity: "none",
|
|
320
|
+
activePageRegion: null,
|
|
321
|
+
activeObjectFrame: null
|
|
322
|
+
};
|
|
323
|
+
function createViewState(initial) {
|
|
324
|
+
return { ...DEFAULT_VIEW_STATE, ...initial };
|
|
325
|
+
}
|
|
326
|
+
function setViewMode(state, mode) {
|
|
327
|
+
if (state.viewMode === mode) return state;
|
|
328
|
+
return { ...state, viewMode: mode };
|
|
329
|
+
}
|
|
330
|
+
function setDocumentMode(state, mode) {
|
|
331
|
+
if (state.documentMode === mode) return state;
|
|
332
|
+
return { ...state, documentMode: mode };
|
|
333
|
+
}
|
|
334
|
+
function setWorkspaceMode(state, workspaceMode) {
|
|
335
|
+
if (state.workspaceMode === workspaceMode) {
|
|
336
|
+
return state;
|
|
337
|
+
}
|
|
338
|
+
return { ...state, workspaceMode };
|
|
339
|
+
}
|
|
340
|
+
function setZoomLevel(state, zoomLevel) {
|
|
341
|
+
const normalizedZoom = normalizeZoomLevel(zoomLevel, state.zoomLevel);
|
|
342
|
+
if (state.zoomLevel === normalizedZoom) {
|
|
343
|
+
return state;
|
|
344
|
+
}
|
|
345
|
+
return { ...state, zoomLevel: normalizedZoom };
|
|
346
|
+
}
|
|
347
|
+
function setFocused(state, focused) {
|
|
348
|
+
if (state.isFocused === focused) return state;
|
|
349
|
+
return { ...state, isFocused: focused };
|
|
350
|
+
}
|
|
351
|
+
function deriveActiveListContext(surface, selectionHead, numberingCatalog) {
|
|
352
|
+
if (!surface) return null;
|
|
353
|
+
const block = findBlockAtPosition(surface.blocks, selectionHead);
|
|
354
|
+
if (!block || block.kind !== "paragraph" || !block.numbering) return null;
|
|
355
|
+
const isOrdered = resolveListOrdering(block.numbering, numberingCatalog);
|
|
356
|
+
return {
|
|
357
|
+
numberingInstanceId: block.numbering.numberingInstanceId,
|
|
358
|
+
level: block.numbering.level,
|
|
359
|
+
isOrdered,
|
|
360
|
+
...block.numberingPrefix ? { markerText: block.numberingPrefix } : {}
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
function deriveActiveNoteContext(activeStory, mainSurface) {
|
|
364
|
+
if (activeStory.kind !== "footnote" && activeStory.kind !== "endnote") {
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
const referencePosition = findNoteReferencePosition(mainSurface, activeStory);
|
|
368
|
+
return {
|
|
369
|
+
noteKind: activeStory.kind,
|
|
370
|
+
noteId: activeStory.noteId,
|
|
371
|
+
referencePosition
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
function deriveLayoutMeasurement(surface, selectionOrPosition, viewState) {
|
|
375
|
+
const selectionHead = typeof selectionOrPosition === "number" ? selectionOrPosition : selectionOrPosition.activeRange.kind === "node" ? selectionOrPosition.activeRange.at : selectionOrPosition.head;
|
|
376
|
+
const block = surface ? findBlockAtPosition(surface.blocks, selectionHead) : null;
|
|
377
|
+
const tabStops = block?.kind === "paragraph" && block.tabStops ? block.tabStops : [];
|
|
378
|
+
const listMarkerLane = deriveListMarkerLane(block);
|
|
379
|
+
return {
|
|
380
|
+
pageRegions: viewState.activePageRegion ? [viewState.activePageRegion] : [],
|
|
381
|
+
caretAffinity: viewState.caretAffinity,
|
|
382
|
+
tabStops,
|
|
383
|
+
listMarkerLane: listMarkerLane ?? void 0,
|
|
384
|
+
objectFrame: viewState.activeObjectFrame ?? void 0
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
function createEditorViewStateSnapshot(viewState, activeStory, selection, surface, mainSurface, pageLayout, numberingCatalog) {
|
|
388
|
+
const selectionPosition = selection.activeRange.kind === "node" ? selection.activeRange.at : selection.head;
|
|
389
|
+
const derivedViewState = deriveInteractionViewState(
|
|
390
|
+
viewState,
|
|
391
|
+
activeStory,
|
|
392
|
+
selection,
|
|
393
|
+
surface,
|
|
394
|
+
pageLayout
|
|
395
|
+
);
|
|
396
|
+
const activeListContext = deriveActiveListContext(surface, selectionPosition, numberingCatalog);
|
|
397
|
+
const activeNoteContext = deriveActiveNoteContext(activeStory, mainSurface);
|
|
398
|
+
const measurement = deriveLayoutMeasurement(surface, selection, derivedViewState);
|
|
399
|
+
return {
|
|
400
|
+
viewMode: derivedViewState.viewMode,
|
|
401
|
+
documentMode: derivedViewState.documentMode,
|
|
402
|
+
workspaceMode: derivedViewState.workspaceMode,
|
|
403
|
+
zoomLevel: derivedViewState.zoomLevel,
|
|
404
|
+
activeStory,
|
|
405
|
+
selection,
|
|
406
|
+
caretAffinity: derivedViewState.caretAffinity,
|
|
407
|
+
activeListContext,
|
|
408
|
+
activeNoteContext,
|
|
409
|
+
activePageRegion: derivedViewState.activePageRegion,
|
|
410
|
+
activeObjectFrame: derivedViewState.activeObjectFrame,
|
|
411
|
+
measurement,
|
|
412
|
+
isFocused: derivedViewState.isFocused
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
function findBlockAtPosition(blocks, position) {
|
|
416
|
+
for (const block of blocks) {
|
|
417
|
+
if (position >= block.from && position <= block.to) {
|
|
418
|
+
if (block.kind === "sdt_block") {
|
|
419
|
+
const inner = findBlockAtPosition(block.children, position);
|
|
420
|
+
if (inner) return inner;
|
|
421
|
+
}
|
|
422
|
+
if (block.kind === "table") {
|
|
423
|
+
for (const row of block.rows) {
|
|
424
|
+
for (const cell of row.cells) {
|
|
425
|
+
const inner = findBlockAtPosition(cell.content, position);
|
|
426
|
+
if (inner) return inner;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return block;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
function resolveListOrdering(numbering, numberingCatalog) {
|
|
436
|
+
if (!numberingCatalog) {
|
|
437
|
+
return true;
|
|
438
|
+
}
|
|
439
|
+
const instance = numberingCatalog.instances[numbering.numberingInstanceId];
|
|
440
|
+
const definition = instance ? numberingCatalog.abstractDefinitions[instance.abstractNumberingId] : void 0;
|
|
441
|
+
const levelDefinition = definition?.levels.find((level) => level.level === numbering.level);
|
|
442
|
+
if (!levelDefinition) {
|
|
443
|
+
return true;
|
|
444
|
+
}
|
|
445
|
+
return levelDefinition.format !== "bullet";
|
|
446
|
+
}
|
|
447
|
+
function deriveInteractionViewState(viewState, activeStory, selection, surface, pageLayout) {
|
|
448
|
+
const activePageRegion = deriveActivePageRegion(activeStory, pageLayout) ?? viewState.activePageRegion;
|
|
449
|
+
const activeObjectFrame = deriveActiveObjectFrame(surface, selection);
|
|
450
|
+
const caretAffinity = deriveCaretAffinity(surface, selection);
|
|
451
|
+
return {
|
|
452
|
+
...viewState,
|
|
453
|
+
caretAffinity,
|
|
454
|
+
activePageRegion,
|
|
455
|
+
activeObjectFrame
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
function deriveActivePageRegion(activeStory, pageLayout) {
|
|
459
|
+
if (!pageLayout) {
|
|
460
|
+
return null;
|
|
461
|
+
}
|
|
462
|
+
const sectionIndex = pageLayout?.sectionIndex ?? 0;
|
|
463
|
+
switch (activeStory.kind) {
|
|
464
|
+
case "header":
|
|
465
|
+
return { region: "header", sectionIndex, columnIndex: 0 };
|
|
466
|
+
case "footer":
|
|
467
|
+
return { region: "footer", sectionIndex, columnIndex: 0 };
|
|
468
|
+
default:
|
|
469
|
+
return { region: "body", sectionIndex, columnIndex: 0 };
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
function deriveActiveObjectFrame(surface, selection) {
|
|
473
|
+
if (!surface) {
|
|
474
|
+
return null;
|
|
475
|
+
}
|
|
476
|
+
const position = selection.activeRange.kind === "node" ? selection.activeRange.at : selection.head;
|
|
477
|
+
const block = findBlockAtPosition(surface.blocks, position);
|
|
478
|
+
if (!block || block.kind !== "paragraph") {
|
|
479
|
+
return null;
|
|
480
|
+
}
|
|
481
|
+
const segment = findObjectSegmentAtPosition(block.segments, position);
|
|
482
|
+
if (!segment) {
|
|
483
|
+
return null;
|
|
484
|
+
}
|
|
485
|
+
if (segment.kind === "image") {
|
|
486
|
+
return {
|
|
487
|
+
kind: "image",
|
|
488
|
+
anchorPos: segment.from,
|
|
489
|
+
display: segment.display === "floating" ? "floating" : "inline"
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
const objectKind = inferOpaqueObjectKind(segment);
|
|
493
|
+
if (!objectKind) {
|
|
494
|
+
return null;
|
|
495
|
+
}
|
|
496
|
+
return {
|
|
497
|
+
kind: objectKind,
|
|
498
|
+
anchorPos: segment.from,
|
|
499
|
+
display: "inline"
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
function deriveCaretAffinity(surface, selection) {
|
|
503
|
+
if (selection.activeRange.kind === "node") {
|
|
504
|
+
return selection.activeRange.assoc < 0 ? "backward" : "forward";
|
|
505
|
+
}
|
|
506
|
+
if (!selection.isCollapsed || !surface) {
|
|
507
|
+
return "none";
|
|
508
|
+
}
|
|
509
|
+
const block = findBlockAtPosition(surface.blocks, selection.head);
|
|
510
|
+
if (!block || block.kind !== "paragraph") {
|
|
511
|
+
return "none";
|
|
512
|
+
}
|
|
513
|
+
for (const segment of block.segments) {
|
|
514
|
+
if (!isObjectLikeSegment(segment)) {
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
if (selection.head === segment.from) {
|
|
518
|
+
return "forward";
|
|
519
|
+
}
|
|
520
|
+
if (selection.head === segment.to) {
|
|
521
|
+
return "backward";
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
return "none";
|
|
525
|
+
}
|
|
526
|
+
function findNoteReferencePosition(mainSurface, target) {
|
|
527
|
+
if (!mainSurface) return 0;
|
|
528
|
+
for (const block of mainSurface.blocks) {
|
|
529
|
+
if (block.kind === "paragraph") {
|
|
530
|
+
for (const segment of block.segments) {
|
|
531
|
+
if (segment.kind === "note_ref" && segment.noteKind === target.kind && segment.noteId === target.noteId) {
|
|
532
|
+
return segment.from;
|
|
533
|
+
}
|
|
534
|
+
if (segment.kind === "opaque_inline" && segment.label.toLowerCase().includes(target.kind) && segment.detail.includes(target.noteId)) {
|
|
535
|
+
return segment.from;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
return 0;
|
|
541
|
+
}
|
|
542
|
+
function normalizeZoomLevel(zoomLevel, currentZoom) {
|
|
543
|
+
if (zoomLevel === "pageWidth" || zoomLevel === "onePage") {
|
|
544
|
+
return zoomLevel;
|
|
545
|
+
}
|
|
546
|
+
if (!Number.isFinite(zoomLevel) || zoomLevel <= 0) {
|
|
547
|
+
return currentZoom;
|
|
548
|
+
}
|
|
549
|
+
return Math.max(
|
|
550
|
+
MIN_ZOOM_PERCENT,
|
|
551
|
+
Math.min(MAX_ZOOM_PERCENT, Math.round(zoomLevel))
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
function findObjectSegmentAtPosition(segments, position) {
|
|
555
|
+
for (const segment of segments) {
|
|
556
|
+
if (!isObjectLikeSegment(segment)) {
|
|
557
|
+
continue;
|
|
558
|
+
}
|
|
559
|
+
if (position >= segment.from && position <= segment.to) {
|
|
560
|
+
return segment;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
return null;
|
|
564
|
+
}
|
|
565
|
+
function isObjectLikeSegment(segment) {
|
|
566
|
+
if (segment.kind === "image") {
|
|
567
|
+
return true;
|
|
568
|
+
}
|
|
569
|
+
if (segment.kind !== "opaque_inline") {
|
|
570
|
+
return false;
|
|
571
|
+
}
|
|
572
|
+
return inferOpaqueObjectKind(segment) !== null;
|
|
573
|
+
}
|
|
574
|
+
function inferOpaqueObjectKind(segment) {
|
|
575
|
+
if (segment.label === "Text box") {
|
|
576
|
+
return "textbox";
|
|
577
|
+
}
|
|
578
|
+
if (segment.label === "Drawing shape") {
|
|
579
|
+
return "shape";
|
|
580
|
+
}
|
|
581
|
+
if (segment.label === "Legacy VML drawing") {
|
|
582
|
+
return segment.detail.includes("#_x0000_t202") ? "textbox" : "shape";
|
|
583
|
+
}
|
|
584
|
+
return null;
|
|
585
|
+
}
|
|
586
|
+
function deriveListMarkerLane(block) {
|
|
587
|
+
if (!block || block.kind !== "paragraph" || !block.numbering) return null;
|
|
588
|
+
const indent = block.indentation?.hanging ?? block.indentation?.left ?? 360;
|
|
589
|
+
return {
|
|
590
|
+
indent,
|
|
591
|
+
markerWidth: Math.min(indent, 360)
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// src/runtime/page-layout-estimation.ts
|
|
596
|
+
var DEFAULT_FONT_SIZE_POINTS = 12;
|
|
597
|
+
var DEFAULT_LINE_HEIGHT_TWIPS = 280;
|
|
598
|
+
var MIN_BLOCK_HEIGHT_TWIPS = 240;
|
|
599
|
+
var TABLE_ROW_PADDING_TWIPS = 120;
|
|
600
|
+
var DEFAULT_PAGE_ESTIMATE_PX_PER_TWIP = 1 / 15;
|
|
601
|
+
function estimateBlockHeight(block, columnWidth) {
|
|
602
|
+
if (!block) {
|
|
603
|
+
return 0;
|
|
604
|
+
}
|
|
605
|
+
switch (block.kind) {
|
|
606
|
+
case "paragraph":
|
|
607
|
+
return estimateParagraphHeight(block, columnWidth);
|
|
608
|
+
case "table":
|
|
609
|
+
return estimateTableHeight(block, columnWidth);
|
|
610
|
+
case "sdt_block":
|
|
611
|
+
return Math.max(
|
|
612
|
+
MIN_BLOCK_HEIGHT_TWIPS,
|
|
613
|
+
block.children.reduce((total, child) => total + estimateBlockHeight(child, columnWidth), 0)
|
|
614
|
+
);
|
|
615
|
+
case "opaque_block":
|
|
616
|
+
return block.label === "Section break" ? 0 : MIN_BLOCK_HEIGHT_TWIPS;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
function estimateParagraphHeight(block, columnWidth) {
|
|
620
|
+
const lineHeight = estimateParagraphLineHeight(block);
|
|
621
|
+
const lineCount = estimateParagraphLineCount(block, columnWidth);
|
|
622
|
+
const spacingBefore = block.spacing?.before ?? 0;
|
|
623
|
+
const spacingAfter = block.spacing?.after ?? 0;
|
|
624
|
+
return Math.max(
|
|
625
|
+
MIN_BLOCK_HEIGHT_TWIPS,
|
|
626
|
+
lineHeight * lineCount + spacingBefore + spacingAfter
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
function estimateParagraphLineHeight(block) {
|
|
630
|
+
const explicitLine = block.spacing?.line;
|
|
631
|
+
if (typeof explicitLine === "number" && explicitLine > 0) {
|
|
632
|
+
return explicitLine;
|
|
633
|
+
}
|
|
634
|
+
const fontSizeHalfPoints = block.segments.find(
|
|
635
|
+
(segment) => segment.kind === "text" && typeof segment.markAttrs?.fontSize === "number"
|
|
636
|
+
)?.markAttrs?.fontSize;
|
|
637
|
+
const fontSizePoints = typeof fontSizeHalfPoints === "number" ? fontSizeHalfPoints / 2 : DEFAULT_FONT_SIZE_POINTS;
|
|
638
|
+
return Math.max(
|
|
639
|
+
DEFAULT_LINE_HEIGHT_TWIPS,
|
|
640
|
+
Math.round(fontSizePoints * 20 * 1.35)
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
function estimateParagraphLineCount(block, columnWidth) {
|
|
644
|
+
const averageCharWidth = estimateAverageCharWidth(block);
|
|
645
|
+
const charsPerLine = Math.max(12, Math.floor(columnWidth / averageCharWidth));
|
|
646
|
+
let lineCount = 1;
|
|
647
|
+
let currentLineChars = estimatedPrefixLength(block);
|
|
648
|
+
for (const segment of block.segments) {
|
|
649
|
+
switch (segment.kind) {
|
|
650
|
+
case "text":
|
|
651
|
+
currentLineChars += Array.from(segment.text).length;
|
|
652
|
+
while (currentLineChars > charsPerLine) {
|
|
653
|
+
lineCount += 1;
|
|
654
|
+
currentLineChars -= charsPerLine;
|
|
655
|
+
}
|
|
656
|
+
break;
|
|
657
|
+
case "tab":
|
|
658
|
+
currentLineChars += 4;
|
|
659
|
+
break;
|
|
660
|
+
case "hard_break":
|
|
661
|
+
lineCount += 1;
|
|
662
|
+
currentLineChars = 0;
|
|
663
|
+
break;
|
|
664
|
+
case "image":
|
|
665
|
+
lineCount += Math.max(1, Math.round(segment.display === "floating" ? 2 : 1));
|
|
666
|
+
currentLineChars = 0;
|
|
667
|
+
break;
|
|
668
|
+
case "note_ref":
|
|
669
|
+
currentLineChars += 1;
|
|
670
|
+
break;
|
|
671
|
+
case "opaque_inline":
|
|
672
|
+
if (segment.presentation !== "quiet-marker") {
|
|
673
|
+
currentLineChars += segment.label.length > 0 ? 1 : 0;
|
|
674
|
+
}
|
|
675
|
+
break;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
return Math.max(1, lineCount);
|
|
679
|
+
}
|
|
680
|
+
function getUsablePageHeight(layout) {
|
|
681
|
+
return Math.max(
|
|
682
|
+
1440,
|
|
683
|
+
layout.pageHeight - layout.marginTop - layout.marginBottom
|
|
684
|
+
);
|
|
685
|
+
}
|
|
686
|
+
function getUsableColumnMetrics(layout) {
|
|
687
|
+
const usableWidth = Math.max(
|
|
688
|
+
1440,
|
|
689
|
+
layout.pageWidth - layout.marginLeft - layout.marginRight - layout.gutter
|
|
690
|
+
);
|
|
691
|
+
const columnCount = Math.max(1, layout.columns);
|
|
692
|
+
if (!layout.equalWidthColumns && layout.columnDefinitions.length > 0) {
|
|
693
|
+
return layout.columnDefinitions.map((column, index) => ({
|
|
694
|
+
width: Math.max(720, column.width),
|
|
695
|
+
space: index < layout.columnDefinitions.length - 1 ? Math.max(0, column.space ?? 0) : 0
|
|
696
|
+
}));
|
|
697
|
+
}
|
|
698
|
+
const width = columnCount <= 1 ? usableWidth : Math.max(720, Math.floor(usableWidth / columnCount));
|
|
699
|
+
return Array.from({ length: columnCount }, () => ({
|
|
700
|
+
width,
|
|
701
|
+
space: 0
|
|
702
|
+
}));
|
|
703
|
+
}
|
|
704
|
+
function getUsableColumnWidth(layout) {
|
|
705
|
+
return getUsableColumnMetrics(layout)[0]?.width ?? 1440;
|
|
706
|
+
}
|
|
707
|
+
function estimateTableHeight(block, columnWidth) {
|
|
708
|
+
let totalHeight = 0;
|
|
709
|
+
for (const row of block.rows) {
|
|
710
|
+
const explicitHeight = row.height ?? 0;
|
|
711
|
+
if (explicitHeight > 0) {
|
|
712
|
+
totalHeight += explicitHeight;
|
|
713
|
+
continue;
|
|
714
|
+
}
|
|
715
|
+
let rowHeight = MIN_BLOCK_HEIGHT_TWIPS;
|
|
716
|
+
for (const cell of row.cells) {
|
|
717
|
+
const cellHeight = cell.content.reduce(
|
|
718
|
+
(total, child) => total + estimateBlockHeight(child, columnWidth),
|
|
719
|
+
0
|
|
720
|
+
);
|
|
721
|
+
rowHeight = Math.max(rowHeight, cellHeight + TABLE_ROW_PADDING_TWIPS);
|
|
722
|
+
}
|
|
723
|
+
totalHeight += rowHeight;
|
|
724
|
+
}
|
|
725
|
+
return Math.max(MIN_BLOCK_HEIGHT_TWIPS, totalHeight);
|
|
726
|
+
}
|
|
727
|
+
function estimateAverageCharWidth(block) {
|
|
728
|
+
const fontSizeHalfPoints = block.segments.find(
|
|
729
|
+
(segment) => segment.kind === "text" && typeof segment.markAttrs?.fontSize === "number"
|
|
730
|
+
)?.markAttrs?.fontSize;
|
|
731
|
+
const fontSizePoints = typeof fontSizeHalfPoints === "number" ? fontSizeHalfPoints / 2 : DEFAULT_FONT_SIZE_POINTS;
|
|
732
|
+
return Math.max(96, Math.round(fontSizePoints * 12));
|
|
733
|
+
}
|
|
734
|
+
function estimatedPrefixLength(block) {
|
|
735
|
+
const prefix = block.numberingPrefix ?? "";
|
|
736
|
+
const suffix = block.numberingSuffix === "space" ? 1 : block.numberingSuffix === "tab" ? 4 : 0;
|
|
737
|
+
return prefix.length + suffix;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
// src/runtime/document-navigation.ts
|
|
741
|
+
var MIN_BLOCK_HEIGHT_TWIPS2 = 240;
|
|
742
|
+
var FOOTNOTE_REFERENCE_RESERVATION_TWIPS = 180;
|
|
743
|
+
var navigationBaseCache = /* @__PURE__ */ new WeakMap();
|
|
744
|
+
function createDocumentNavigationSnapshot(document, selectionHead, activeStory) {
|
|
745
|
+
const base = getNavigationBaseSnapshot(document);
|
|
746
|
+
const navigationContext = resolveActiveNavigationContext(
|
|
747
|
+
document,
|
|
748
|
+
base.pages,
|
|
749
|
+
base.sections,
|
|
750
|
+
base.mainSurface,
|
|
751
|
+
selectionHead,
|
|
752
|
+
activeStory
|
|
753
|
+
);
|
|
754
|
+
return {
|
|
755
|
+
pageCount: base.pages.length,
|
|
756
|
+
pages: base.pages,
|
|
757
|
+
headings: base.headings,
|
|
758
|
+
activePageIndex: navigationContext.activePageIndex,
|
|
759
|
+
activeSectionIndex: navigationContext.activeSectionIndex
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
function getNavigationBaseSnapshot(document) {
|
|
763
|
+
const cached = navigationBaseCache.get(document.content);
|
|
764
|
+
if (cached && cached.styles === document.styles && cached.subParts === document.subParts) {
|
|
765
|
+
return cached;
|
|
766
|
+
}
|
|
767
|
+
const mainSurface = createEditorSurfaceSnapshot(
|
|
768
|
+
document,
|
|
769
|
+
createSelectionSnapshot(0, 0),
|
|
770
|
+
MAIN_STORY_TARGET
|
|
771
|
+
);
|
|
772
|
+
const sections = buildResolvedSections(document);
|
|
773
|
+
const pages = buildPageStack(document, sections, mainSurface);
|
|
774
|
+
const headings = buildHeadingOutline(document, mainSurface, sections, pages);
|
|
775
|
+
const next = {
|
|
776
|
+
mainSurface,
|
|
777
|
+
sections,
|
|
778
|
+
pages,
|
|
779
|
+
headings,
|
|
780
|
+
styles: document.styles,
|
|
781
|
+
subParts: document.subParts
|
|
782
|
+
};
|
|
783
|
+
navigationBaseCache.set(document.content, next);
|
|
784
|
+
return next;
|
|
785
|
+
}
|
|
786
|
+
function findPageForOffset(pages, offset) {
|
|
787
|
+
for (let i = 0; i < pages.length; i++) {
|
|
788
|
+
if (offset < pages[i].endOffset) {
|
|
789
|
+
return i;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
return Math.max(0, pages.length - 1);
|
|
793
|
+
}
|
|
794
|
+
function findSectionForOffset(sections, offset) {
|
|
795
|
+
return sections.length > 0 ? findSectionForPosition(sections, offset).index : 0;
|
|
796
|
+
}
|
|
797
|
+
function buildPageStack(document, sections, mainSurface) {
|
|
798
|
+
const pages = [];
|
|
799
|
+
let globalPageIndex = 0;
|
|
800
|
+
for (const section of sections) {
|
|
801
|
+
const layout = buildPageLayoutSnapshot(
|
|
802
|
+
section.index,
|
|
803
|
+
section.properties ?? document.subParts?.finalSectionProperties,
|
|
804
|
+
document.subParts
|
|
805
|
+
);
|
|
806
|
+
const sectionBlocks = collectSectionBlocks(mainSurface.blocks, section.start, section.end);
|
|
807
|
+
const paginated = paginateSectionBlocks(
|
|
808
|
+
section,
|
|
809
|
+
sectionBlocks,
|
|
810
|
+
layout,
|
|
811
|
+
document.subParts?.footnoteCollection
|
|
812
|
+
);
|
|
813
|
+
for (const page of paginated) {
|
|
814
|
+
pages.push({
|
|
815
|
+
...page,
|
|
816
|
+
pageIndex: globalPageIndex
|
|
817
|
+
});
|
|
818
|
+
globalPageIndex += 1;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
if (pages.length === 0) {
|
|
822
|
+
pages.push({
|
|
823
|
+
pageIndex: 0,
|
|
824
|
+
sectionIndex: 0,
|
|
825
|
+
pageInSection: 0,
|
|
826
|
+
startOffset: 0,
|
|
827
|
+
endOffset: mainSurface.storySize,
|
|
828
|
+
layout: buildPageLayoutSnapshot(
|
|
829
|
+
0,
|
|
830
|
+
document.subParts?.finalSectionProperties,
|
|
831
|
+
document.subParts
|
|
832
|
+
)
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
return pages;
|
|
836
|
+
}
|
|
837
|
+
function collectSectionBlocks(blocks, start, end) {
|
|
838
|
+
return blocks.filter((block) => block.to > start && block.from < end);
|
|
839
|
+
}
|
|
840
|
+
function paginateSectionBlocks(section, blocks, layout, footnotes) {
|
|
841
|
+
if (blocks.length === 0) {
|
|
842
|
+
return [
|
|
843
|
+
{
|
|
844
|
+
sectionIndex: section.index,
|
|
845
|
+
pageInSection: 0,
|
|
846
|
+
startOffset: section.start,
|
|
847
|
+
endOffset: section.end,
|
|
848
|
+
layout
|
|
849
|
+
}
|
|
850
|
+
];
|
|
851
|
+
}
|
|
852
|
+
const pages = [];
|
|
853
|
+
const usableHeight = getUsablePageHeight(layout);
|
|
854
|
+
const columnMetrics = getUsableColumnMetrics(layout);
|
|
855
|
+
const maxColumns = Math.max(1, columnMetrics.length);
|
|
856
|
+
let pageStart = section.start;
|
|
857
|
+
let columnHeight = 0;
|
|
858
|
+
let columnIndex = 0;
|
|
859
|
+
let pageInSection = 0;
|
|
860
|
+
let reservedNoteHeight = 0;
|
|
861
|
+
const reservedNotes = /* @__PURE__ */ new Set();
|
|
862
|
+
const pushPage = (endOffset) => {
|
|
863
|
+
const boundedEnd = Math.max(pageStart, Math.min(endOffset, section.end));
|
|
864
|
+
if (boundedEnd === pageStart && pages.length > 0) {
|
|
865
|
+
return;
|
|
866
|
+
}
|
|
867
|
+
pages.push({
|
|
868
|
+
sectionIndex: section.index,
|
|
869
|
+
pageInSection,
|
|
870
|
+
startOffset: pageStart,
|
|
871
|
+
endOffset: boundedEnd,
|
|
872
|
+
layout
|
|
873
|
+
});
|
|
874
|
+
pageInSection += 1;
|
|
875
|
+
pageStart = boundedEnd;
|
|
876
|
+
columnHeight = 0;
|
|
877
|
+
columnIndex = 0;
|
|
878
|
+
reservedNoteHeight = 0;
|
|
879
|
+
reservedNotes.clear();
|
|
880
|
+
};
|
|
881
|
+
for (let index = 0; index < blocks.length; index += 1) {
|
|
882
|
+
const block = blocks[index];
|
|
883
|
+
const nextBoundary = blocks[index + 1]?.from ?? section.end;
|
|
884
|
+
while (true) {
|
|
885
|
+
const columnWidth = columnMetrics[Math.min(columnIndex, columnMetrics.length - 1)]?.width ?? getUsableColumnWidth(layout);
|
|
886
|
+
const baseHeight = estimateBlockHeight(block, columnWidth);
|
|
887
|
+
const keepWithNextHeight = block.kind === "paragraph" && block.keepNext ? baseHeight + estimateBlockHeight(blocks[index + 1], columnWidth) : baseHeight;
|
|
888
|
+
const noteHeight = estimateFootnoteReservation(block, footnotes, columnWidth, reservedNotes);
|
|
889
|
+
const projectedHeight = columnHeight + keepWithNextHeight + reservedNoteHeight + noteHeight;
|
|
890
|
+
if (block.kind === "paragraph" && block.pageBreakBefore && pageStart < block.from) {
|
|
891
|
+
pushPage(block.from);
|
|
892
|
+
continue;
|
|
893
|
+
}
|
|
894
|
+
if (projectedHeight > usableHeight && pageStart < block.from) {
|
|
895
|
+
if (columnIndex < maxColumns - 1) {
|
|
896
|
+
columnIndex += 1;
|
|
897
|
+
columnHeight = 0;
|
|
898
|
+
reservedNoteHeight = 0;
|
|
899
|
+
reservedNotes.clear();
|
|
900
|
+
continue;
|
|
901
|
+
}
|
|
902
|
+
pushPage(block.from);
|
|
903
|
+
continue;
|
|
904
|
+
}
|
|
905
|
+
const effectiveNoteHeight = estimateFootnoteReservation(
|
|
906
|
+
block,
|
|
907
|
+
footnotes,
|
|
908
|
+
columnWidth,
|
|
909
|
+
reservedNotes
|
|
910
|
+
);
|
|
911
|
+
columnHeight += baseHeight;
|
|
912
|
+
reservedNoteHeight += effectiveNoteHeight;
|
|
913
|
+
currentPageNoteIds(block).forEach((noteKey) => reservedNotes.add(noteKey));
|
|
914
|
+
if (hasColumnBreak(block)) {
|
|
915
|
+
if (columnIndex < maxColumns - 1) {
|
|
916
|
+
columnIndex += 1;
|
|
917
|
+
columnHeight = 0;
|
|
918
|
+
reservedNoteHeight = 0;
|
|
919
|
+
reservedNotes.clear();
|
|
920
|
+
} else {
|
|
921
|
+
pushPage(nextBoundary);
|
|
922
|
+
}
|
|
923
|
+
break;
|
|
924
|
+
}
|
|
925
|
+
if (index === blocks.length - 1) {
|
|
926
|
+
pushPage(section.end);
|
|
927
|
+
}
|
|
928
|
+
break;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
return pages.length > 0 ? pages : [
|
|
932
|
+
{
|
|
933
|
+
sectionIndex: section.index,
|
|
934
|
+
pageInSection: 0,
|
|
935
|
+
startOffset: section.start,
|
|
936
|
+
endOffset: section.end,
|
|
937
|
+
layout
|
|
938
|
+
}
|
|
939
|
+
];
|
|
940
|
+
}
|
|
941
|
+
function resolveActiveNavigationContext(document, pages, sections, mainSurface, selectionHead, activeStory) {
|
|
942
|
+
if (activeStory.kind === "main") {
|
|
943
|
+
const activePageIndex = findPageForOffset(pages, selectionHead);
|
|
944
|
+
return {
|
|
945
|
+
activePageIndex,
|
|
946
|
+
activeSectionIndex: pages[activePageIndex]?.sectionIndex ?? 0
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
if (activeStory.kind === "header" || activeStory.kind === "footer") {
|
|
950
|
+
const section = resolveSectionForStoryTarget(document, sections, activeStory);
|
|
951
|
+
if (section) {
|
|
952
|
+
return {
|
|
953
|
+
activePageIndex: findFirstPageIndexForSection(pages, section.index),
|
|
954
|
+
activeSectionIndex: section.index
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
if (activeStory.kind === "footnote" || activeStory.kind === "endnote") {
|
|
959
|
+
const referencePosition = findNoteReferencePosition(mainSurface, activeStory);
|
|
960
|
+
const activePageIndex = findPageForOffset(pages, referencePosition);
|
|
961
|
+
return {
|
|
962
|
+
activePageIndex,
|
|
963
|
+
activeSectionIndex: pages[activePageIndex]?.sectionIndex ?? findSectionForOffset(sections, referencePosition)
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
return {
|
|
967
|
+
activePageIndex: 0,
|
|
968
|
+
activeSectionIndex: 0
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
function findFirstPageIndexForSection(pages, sectionIndex) {
|
|
972
|
+
const match = pages.findIndex((page) => page.sectionIndex === sectionIndex);
|
|
973
|
+
return match >= 0 ? match : 0;
|
|
974
|
+
}
|
|
975
|
+
function estimateFootnoteReservation(block, footnotes, columnWidth, reservedNotes) {
|
|
976
|
+
if (!footnotes || block.kind !== "paragraph") {
|
|
977
|
+
return 0;
|
|
978
|
+
}
|
|
979
|
+
let reservation = 0;
|
|
980
|
+
for (const noteKey of currentPageNoteIds(block)) {
|
|
981
|
+
if (reservedNotes.has(noteKey)) {
|
|
982
|
+
continue;
|
|
983
|
+
}
|
|
984
|
+
const [noteKind, noteId] = noteKey.split(":");
|
|
985
|
+
const noteCollection = noteKind === "endnote" ? footnotes.endnotes : footnotes.footnotes;
|
|
986
|
+
const note = noteCollection[noteId];
|
|
987
|
+
reservation += FOOTNOTE_REFERENCE_RESERVATION_TWIPS;
|
|
988
|
+
if (note) {
|
|
989
|
+
reservation += note.blocks.reduce(
|
|
990
|
+
(total, child) => total + estimateCanonicalNoteBlockHeight(child, columnWidth),
|
|
991
|
+
0
|
|
992
|
+
);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
return reservation;
|
|
996
|
+
}
|
|
997
|
+
function estimateCanonicalNoteBlockHeight(block, columnWidth) {
|
|
998
|
+
switch (block.type) {
|
|
999
|
+
case "paragraph":
|
|
1000
|
+
return estimateParagraphHeight(
|
|
1001
|
+
{
|
|
1002
|
+
blockId: "note",
|
|
1003
|
+
kind: "paragraph",
|
|
1004
|
+
from: 0,
|
|
1005
|
+
to: 0,
|
|
1006
|
+
...block.styleId ? { styleId: block.styleId } : {},
|
|
1007
|
+
segments: createEstimatedNoteSegments(block.children)
|
|
1008
|
+
},
|
|
1009
|
+
columnWidth
|
|
1010
|
+
);
|
|
1011
|
+
case "table":
|
|
1012
|
+
return MIN_BLOCK_HEIGHT_TWIPS2 * Math.max(1, block.rows.length);
|
|
1013
|
+
default:
|
|
1014
|
+
return MIN_BLOCK_HEIGHT_TWIPS2;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
function createEstimatedNoteSegments(children) {
|
|
1018
|
+
const segments = [];
|
|
1019
|
+
children.forEach((child, index) => {
|
|
1020
|
+
if (child.type === "text") {
|
|
1021
|
+
segments.push({
|
|
1022
|
+
segmentId: `note-${index}`,
|
|
1023
|
+
kind: "text",
|
|
1024
|
+
from: 0,
|
|
1025
|
+
to: Array.from(child.text).length,
|
|
1026
|
+
text: child.text
|
|
1027
|
+
});
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
if (child.type === "hard_break" || child.type === "tab") {
|
|
1031
|
+
segments.push({
|
|
1032
|
+
segmentId: `note-${index}`,
|
|
1033
|
+
kind: child.type,
|
|
1034
|
+
from: 0,
|
|
1035
|
+
to: 1
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
});
|
|
1039
|
+
return segments;
|
|
1040
|
+
}
|
|
1041
|
+
function currentPageNoteIds(block) {
|
|
1042
|
+
const notes = /* @__PURE__ */ new Set();
|
|
1043
|
+
if (block.kind !== "paragraph") {
|
|
1044
|
+
return notes;
|
|
1045
|
+
}
|
|
1046
|
+
for (const segment of block.segments) {
|
|
1047
|
+
if (segment.kind === "note_ref" && segment.noteId) {
|
|
1048
|
+
notes.add(`${segment.noteKind}:${segment.noteId}`);
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
return notes;
|
|
1052
|
+
}
|
|
1053
|
+
function hasColumnBreak(block) {
|
|
1054
|
+
return block.kind === "paragraph" && block.segments.some(
|
|
1055
|
+
(segment) => segment.kind === "opaque_inline" && segment.label === "Column break"
|
|
1056
|
+
);
|
|
1057
|
+
}
|
|
1058
|
+
var HEADING_STYLE_PATTERN = /^heading\s*(\d+)$/i;
|
|
1059
|
+
function headingLevelFromStyleId(styleId) {
|
|
1060
|
+
if (!styleId) return null;
|
|
1061
|
+
const match = HEADING_STYLE_PATTERN.exec(styleId);
|
|
1062
|
+
if (match) {
|
|
1063
|
+
const level = parseInt(match[1], 10);
|
|
1064
|
+
return level >= 1 && level <= 9 ? level : null;
|
|
1065
|
+
}
|
|
1066
|
+
return null;
|
|
1067
|
+
}
|
|
1068
|
+
function buildHeadingOutline(document, mainSurface, sections, pages) {
|
|
1069
|
+
const headings = [];
|
|
1070
|
+
for (const block of mainSurface.blocks) {
|
|
1071
|
+
if (block.kind !== "paragraph") continue;
|
|
1072
|
+
const outlineLevel = block.outlineLevel;
|
|
1073
|
+
const styleLevel = resolveHeadingLevelFromStyle(document, block.styleId);
|
|
1074
|
+
const level = outlineLevel !== void 0 && outlineLevel >= 0 ? outlineLevel + 1 : styleLevel;
|
|
1075
|
+
if (level === null) continue;
|
|
1076
|
+
const text = extractParagraphText(block);
|
|
1077
|
+
if (!text.trim()) continue;
|
|
1078
|
+
const offset = block.from;
|
|
1079
|
+
const pageIndex = findPageForOffset(pages, offset);
|
|
1080
|
+
const sectionIndex = findSectionForOffset(sections, offset);
|
|
1081
|
+
headings.push({
|
|
1082
|
+
headingId: `heading-${block.blockId}-${offset}`,
|
|
1083
|
+
level,
|
|
1084
|
+
text: text.trim(),
|
|
1085
|
+
offset,
|
|
1086
|
+
pageIndex,
|
|
1087
|
+
sectionIndex
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
1090
|
+
return headings;
|
|
1091
|
+
}
|
|
1092
|
+
function resolveHeadingLevelFromStyle(document, styleId) {
|
|
1093
|
+
if (!styleId) {
|
|
1094
|
+
return null;
|
|
1095
|
+
}
|
|
1096
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1097
|
+
let currentStyleId = styleId;
|
|
1098
|
+
while (currentStyleId && !visited.has(currentStyleId)) {
|
|
1099
|
+
visited.add(currentStyleId);
|
|
1100
|
+
const style = document.styles.paragraphs[currentStyleId];
|
|
1101
|
+
if (!style) {
|
|
1102
|
+
break;
|
|
1103
|
+
}
|
|
1104
|
+
if (typeof style.outlineLevel === "number" && style.outlineLevel >= 0 && style.outlineLevel <= 8) {
|
|
1105
|
+
return style.outlineLevel + 1;
|
|
1106
|
+
}
|
|
1107
|
+
currentStyleId = style.basedOn;
|
|
1108
|
+
}
|
|
1109
|
+
return headingLevelFromStyleId(styleId);
|
|
1110
|
+
}
|
|
1111
|
+
function extractParagraphText(block) {
|
|
1112
|
+
let text = "";
|
|
1113
|
+
for (const segment of block.segments) {
|
|
1114
|
+
switch (segment.kind) {
|
|
1115
|
+
case "text":
|
|
1116
|
+
text += segment.text;
|
|
1117
|
+
break;
|
|
1118
|
+
case "tab":
|
|
1119
|
+
text += " ";
|
|
1120
|
+
break;
|
|
1121
|
+
case "hard_break":
|
|
1122
|
+
text += "\n";
|
|
1123
|
+
break;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
return text;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
// src/ui-tailwind/editor-surface/perf-probe.ts
|
|
1130
|
+
function startPerfProbe(kind) {
|
|
1131
|
+
const state = getEnabledState();
|
|
1132
|
+
if (!state) {
|
|
1133
|
+
return null;
|
|
1134
|
+
}
|
|
1135
|
+
const token = `${kind}-${state.nextToken ?? 0}`;
|
|
1136
|
+
state.nextToken = (state.nextToken ?? 0) + 1;
|
|
1137
|
+
state.pending ??= {};
|
|
1138
|
+
state.pending[token] = {
|
|
1139
|
+
kind,
|
|
1140
|
+
startedAt: performance.now()
|
|
1141
|
+
};
|
|
1142
|
+
return token;
|
|
1143
|
+
}
|
|
1144
|
+
function finishPerfProbe(token) {
|
|
1145
|
+
if (!token) {
|
|
1146
|
+
return null;
|
|
1147
|
+
}
|
|
1148
|
+
const state = getEnabledState();
|
|
1149
|
+
if (!state?.pending?.[token]) {
|
|
1150
|
+
return null;
|
|
1151
|
+
}
|
|
1152
|
+
const pending = state.pending[token];
|
|
1153
|
+
delete state.pending[token];
|
|
1154
|
+
const sample = {
|
|
1155
|
+
token,
|
|
1156
|
+
kind: pending.kind,
|
|
1157
|
+
durationMs: performance.now() - pending.startedAt,
|
|
1158
|
+
recordedAt: Date.now()
|
|
1159
|
+
};
|
|
1160
|
+
pushSample(state, sample);
|
|
1161
|
+
return sample;
|
|
1162
|
+
}
|
|
1163
|
+
function recordPerfSample(kind, durationMs = 0) {
|
|
1164
|
+
const state = getEnabledState();
|
|
1165
|
+
if (!state) {
|
|
1166
|
+
return null;
|
|
1167
|
+
}
|
|
1168
|
+
const token = `${kind}-${state.nextToken ?? 0}`;
|
|
1169
|
+
state.nextToken = (state.nextToken ?? 0) + 1;
|
|
1170
|
+
const sample = {
|
|
1171
|
+
token,
|
|
1172
|
+
kind,
|
|
1173
|
+
durationMs,
|
|
1174
|
+
recordedAt: Date.now()
|
|
1175
|
+
};
|
|
1176
|
+
pushSample(state, sample);
|
|
1177
|
+
return sample;
|
|
1178
|
+
}
|
|
1179
|
+
function incrementInvalidationCounter(counter, amount = 1) {
|
|
1180
|
+
const state = getEnabledState();
|
|
1181
|
+
if (!state) {
|
|
1182
|
+
return 0;
|
|
1183
|
+
}
|
|
1184
|
+
state.invalidationCounts ??= {};
|
|
1185
|
+
state.invalidationCounts[counter] = (state.invalidationCounts[counter] ?? 0) + amount;
|
|
1186
|
+
return state.invalidationCounts[counter];
|
|
1187
|
+
}
|
|
1188
|
+
function getEnabledState() {
|
|
1189
|
+
if (typeof window === "undefined") {
|
|
1190
|
+
return null;
|
|
1191
|
+
}
|
|
1192
|
+
const state = window.__DOCX_REACT_PERF_PROBE__;
|
|
1193
|
+
if (!state?.enabled) {
|
|
1194
|
+
return null;
|
|
1195
|
+
}
|
|
1196
|
+
return state;
|
|
1197
|
+
}
|
|
1198
|
+
function pushSample(state, sample) {
|
|
1199
|
+
state.samples ??= [];
|
|
1200
|
+
state.samples.push(sample);
|
|
1201
|
+
const maxSamples = state.maxSamples ?? 20;
|
|
1202
|
+
if (state.samples.length > maxSamples) {
|
|
1203
|
+
state.samples.splice(0, state.samples.length - maxSamples);
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
export {
|
|
1208
|
+
detachReviewAnchor,
|
|
1209
|
+
mapReviewAnchor,
|
|
1210
|
+
getAnchorRange,
|
|
1211
|
+
mappingTouchesAnchorContent,
|
|
1212
|
+
rangeStaysWithinSingleParagraph,
|
|
1213
|
+
canCreateDocxCommentAnchor,
|
|
1214
|
+
DEFAULT_PAGE_ESTIMATE_PX_PER_TWIP,
|
|
1215
|
+
estimateBlockHeight,
|
|
1216
|
+
estimateParagraphLineHeight,
|
|
1217
|
+
estimateParagraphLineCount,
|
|
1218
|
+
getUsableColumnWidth,
|
|
1219
|
+
buildResolvedSections,
|
|
1220
|
+
buildPageLayoutSnapshot,
|
|
1221
|
+
resolveSectionForStoryTarget,
|
|
1222
|
+
resolveActiveSection,
|
|
1223
|
+
createViewState,
|
|
1224
|
+
setViewMode,
|
|
1225
|
+
setDocumentMode,
|
|
1226
|
+
setWorkspaceMode,
|
|
1227
|
+
setZoomLevel,
|
|
1228
|
+
setFocused,
|
|
1229
|
+
createEditorViewStateSnapshot,
|
|
1230
|
+
createDocumentNavigationSnapshot,
|
|
1231
|
+
findPageForOffset,
|
|
1232
|
+
startPerfProbe,
|
|
1233
|
+
finishPerfProbe,
|
|
1234
|
+
recordPerfSample,
|
|
1235
|
+
incrementInvalidationCounter
|
|
1236
|
+
};
|
|
1237
|
+
//# sourceMappingURL=chunk-GBVOWFIK.js.map
|