@stll/folio-core 0.67.0 → 0.69.0
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/ai-edits/apply.d.ts +9 -1
- package/dist/ai-edits/apply.js +94 -8
- package/dist/ai-edits/headless.d.ts +36 -21
- package/dist/ai-edits/headless.js +106 -36
- package/dist/ai-edits/index.d.ts +2 -2
- package/dist/ai-edits/newListNumbering.d.ts +14 -1
- package/dist/ai-edits/newListNumbering.js +24 -1
- package/dist/ai-edits/note-references.d.ts +6 -0
- package/dist/ai-edits/note-references.js +7 -1
- package/dist/ai-edits/pending-suggestions.js +2 -2
- package/dist/ai-edits/read.d.ts +19 -0
- package/dist/ai-edits/snapshot.d.ts +6 -0
- package/dist/ai-edits/snapshot.js +8 -3
- package/dist/ai-edits/types.d.ts +9 -1
- package/dist/ai-suggestions/apply.js +13 -4
- package/dist/compare/compare.js +2 -1
- package/dist/compare/inserted-resource-snapshot.d.ts +4 -1
- package/dist/compare/inserted-resource-snapshot.js +7 -3
- package/dist/controller/canonicalClipboard.js +31 -14
- package/dist/controller/canonicalComposition.js +35 -6
- package/dist/controller/canonicalInlineProjection.d.ts +35 -10
- package/dist/controller/canonicalInlineProjection.js +192 -28
- package/dist/controller/canonicalInput.d.ts +2 -1
- package/dist/controller/canonicalInput.js +32 -7
- package/dist/controller/canonicalListRendering.d.ts +2 -1
- package/dist/controller/canonicalListRendering.js +1 -1
- package/dist/controller/canonicalLockGuard.d.ts +23 -0
- package/dist/controller/canonicalLockGuard.js +133 -0
- package/dist/controller/canonicalProjectionBlocks.d.ts +79 -0
- package/dist/controller/canonicalProjectionBlocks.js +75 -0
- package/dist/controller/canonicalPublicOperations.d.ts +12 -4
- package/dist/controller/canonicalPublicOperations.js +676 -46
- package/dist/controller/canonicalSeedContent.d.ts +12 -0
- package/dist/controller/canonicalSeedContent.js +131 -0
- package/dist/controller/canonicalSession.d.ts +133 -21
- package/dist/controller/canonicalSession.js +738 -205
- package/dist/controller/canonicalSourceNormalization.d.ts +21 -0
- package/dist/controller/canonicalSourceNormalization.js +148 -0
- package/dist/controller/canonicalStoryEditor.d.ts +4 -3
- package/dist/controller/canonicalStoryEditor.js +20 -15
- package/dist/controller/canonicalStructure.d.ts +2 -1
- package/dist/controller/canonicalStructure.js +129 -7
- package/dist/controller/contentControlWidgetController.d.ts +5 -0
- package/dist/controller/contentControlWidgetController.js +13 -1
- package/dist/controller/folioEditor.js +4 -0
- package/dist/controller/headerFooterEditorManager.d.ts +7 -2
- package/dist/controller/headerFooterEditorManager.js +11 -6
- package/dist/controller/hiddenEditorApi.d.ts +17 -2
- package/dist/controller/hiddenEditorApi.js +4 -0
- package/dist/controller/hiddenEditorManager.d.ts +11 -3
- package/dist/controller/hiddenEditorManager.js +157 -48
- package/dist/controller/layoutPipeline.js +50 -16
- package/dist/controller/layoutSession.d.ts +3 -0
- package/dist/controller/layoutSession.js +3 -1
- package/dist/controller/noteEditorManager.d.ts +7 -2
- package/dist/controller/noteEditorManager.js +11 -6
- package/dist/display-list/build/pageFurniture.js +41 -19
- package/dist/display-list/build/tablePrimitives.js +23 -4
- package/dist/display-list/dom/renderDisplayListToDom.js +13 -11
- package/dist/document-operations.d.ts +9 -1
- package/dist/document-operations.js +4 -3
- package/dist/docx/blockContentParser.d.ts +7 -3
- package/dist/docx/blockContentParser.js +2 -3
- package/dist/docx/blockPlainText.js +2 -0
- package/dist/docx/bookmarkRangeJoin.d.ts +6 -0
- package/dist/docx/bookmarkRangeJoin.js +43 -0
- package/dist/docx/canonicalSave.js +11 -2
- package/dist/docx/canonicalSessionInput.d.ts +5 -1
- package/dist/docx/canonicalSessionInput.js +7 -2
- package/dist/docx/commentAnchorIndex.d.ts +40 -5
- package/dist/docx/commentAnchorIndex.js +94 -12
- package/dist/docx/commentRangeIntegrity.js +30 -24
- package/dist/docx/commentRangeJoin.d.ts +4 -0
- package/dist/docx/commentRangeJoin.js +26 -12
- package/dist/docx/commentReferenceCompletion.js +5 -4
- package/dist/docx/commentReferenceNormalization.js +40 -18
- package/dist/docx/compatibility.js +9 -2
- package/dist/docx/containerChildren.js +22 -1
- package/dist/docx/contentTypeRegistry.js +1 -1
- package/dist/docx/encryption/compoundFile.js +9 -1
- package/dist/docx/encryption/encryptionInfo.js +16 -2
- package/dist/docx/ensureParaIds.js +46 -7
- package/dist/docx/ensureUniqueControlIds.d.ts +25 -0
- package/dist/docx/ensureUniqueControlIds.js +110 -0
- package/dist/docx/headerFooterVerbatim.d.ts +7 -0
- package/dist/docx/headerFooterVerbatim.js +13 -2
- package/dist/docx/hostCommentThreads.d.ts +27 -0
- package/dist/docx/hostCommentThreads.js +72 -0
- package/dist/docx/hyperlinkParser.js +9 -2
- package/dist/docx/inlineWrapperContent.d.ts +8 -1
- package/dist/docx/inlineWrapperContent.js +9 -2
- package/dist/docx/listMarkerComputation.d.ts +35 -1
- package/dist/docx/listMarkerComputation.js +39 -1
- package/dist/docx/listModelNormalization.d.ts +44 -1
- package/dist/docx/listModelNormalization.js +226 -96
- package/dist/docx/listNumberingInstances.d.ts +1 -1
- package/dist/docx/listNumberingInstances.js +2 -2
- package/dist/docx/markupRangeMarker.d.ts +14 -0
- package/dist/docx/markupRangeMarker.js +15 -1
- package/dist/docx/metadataPrivacy.js +43 -22
- package/dist/docx/normalizeBaseDirection.js +3 -1
- package/dist/docx/numberingIds.d.ts +6 -0
- package/dist/docx/numberingIds.js +6 -1
- package/dist/docx/numberingReferenceNormalization.d.ts +4 -0
- package/dist/docx/numberingReferenceNormalization.js +12 -2
- package/dist/docx/paragraphParser.js +159 -48
- package/dist/docx/paragraphPropertySource.d.ts +29 -0
- package/dist/docx/paragraphPropertySource.js +106 -16
- package/dist/docx/paragraphTextBoxEnrichment.js +2 -1
- package/dist/docx/paragraphTraversal.js +2 -0
- package/dist/docx/parseWarningMessage.js +2 -1
- package/dist/docx/parser.js +8 -0
- package/dist/docx/removeHeaderFooterParts.js +1 -1
- package/dist/docx/renderedPageBreakNormalization.js +1 -1
- package/dist/docx/reviewProvenanceDiagnostics.d.ts +7 -0
- package/dist/docx/reviewProvenanceDiagnostics.js +39 -0
- package/dist/docx/reviewResolutionProvenance.d.ts +29 -3
- package/dist/docx/reviewResolutionProvenance.js +171 -33
- package/dist/docx/rezip.d.ts +6 -0
- package/dist/docx/rezip.js +38 -21
- package/dist/docx/selectiveSave.js +6 -10
- package/dist/docx/selectiveXmlPatch.d.ts +5 -4
- package/dist/docx/selectiveXmlPatch.js +11 -7
- package/dist/docx/serializer/documentSerializer.js +5 -2
- package/dist/docx/serializer/headerFooterSerializer.js +3 -1
- package/dist/docx/serializer/markupRangeAttributes.d.ts +6 -1
- package/dist/docx/serializer/markupRangeAttributes.js +6 -1
- package/dist/docx/serializer/noteSerializer.d.ts +17 -4
- package/dist/docx/serializer/noteSerializer.js +23 -16
- package/dist/docx/serializer/paragraphSerializer.js +56 -12
- package/dist/docx/serializer/partNamespaces.d.ts +1 -1
- package/dist/docx/serializer/partNamespaces.js +1 -1
- package/dist/docx/serializer/runSerializer.d.ts +1 -3
- package/dist/docx/serializer/runSerializer.js +2 -2
- package/dist/docx/serializer/tableSerializer.d.ts +4 -0
- package/dist/docx/serializer/tableSerializer.js +4 -2
- package/dist/docx/server/applyDocxXmlPatchProposal.js +8 -4
- package/dist/docx/server/build.d.ts +1 -1
- package/dist/docx/server/createBilingualDocument.js +27 -5
- package/dist/docx/server/migrateYjsAttrSchema.js +4 -0
- package/dist/docx/sessionListPruning.d.ts +2 -0
- package/dist/docx/sessionListPruning.js +50 -0
- package/dist/docx/splitRevisionPieces.d.ts +10 -0
- package/dist/docx/splitRevisionPieces.js +14 -0
- package/dist/docx/storyBlockReplay.js +19 -2
- package/dist/docx/structuralXmlPatch.js +44 -11
- package/dist/docx/tableParser.d.ts +6 -2
- package/dist/docx/tableParser.js +2 -3
- package/dist/docx/textBoxContentParser.d.ts +11 -0
- package/dist/docx/textBoxContentParser.js +51 -0
- package/dist/docx/textBoxParser.d.ts +0 -5
- package/dist/docx/textBoxParser.js +1 -23
- package/dist/docx/verticalMergeProjection.js +1 -1
- package/dist/docx/xmlParser.d.ts +1 -1
- package/dist/docx/xmlParser.js +2 -3
- package/dist/fonts/fontsourceFaces.d.ts +2 -8
- package/dist/fonts/fontsourceFaces.js +1 -7
- package/dist/i18n/messages/ar.gen.js +3 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +51 -0
- package/dist/i18n/messages/catalogs.gen.js +51 -0
- package/dist/i18n/messages/cs.gen.js +3 -0
- package/dist/i18n/messages/de.gen.js +3 -0
- package/dist/i18n/messages/en.gen.js +3 -0
- package/dist/i18n/messages/es.gen.js +3 -0
- package/dist/i18n/messages/et.gen.js +3 -0
- package/dist/i18n/messages/fr.gen.js +3 -0
- package/dist/i18n/messages/he.gen.js +3 -0
- package/dist/i18n/messages/hi.gen.js +3 -0
- package/dist/i18n/messages/hu.gen.js +3 -0
- package/dist/i18n/messages/lt.gen.js +3 -0
- package/dist/i18n/messages/lv.gen.js +3 -0
- package/dist/i18n/messages/messages.gen.d.ts +3 -0
- package/dist/i18n/messages/pl.gen.js +3 -0
- package/dist/i18n/messages/pt-BR.gen.js +3 -0
- package/dist/i18n/messages/sk.gen.js +3 -0
- package/dist/i18n/messages/tr.gen.js +3 -0
- package/dist/i18n/messages/zh-CN.gen.js +3 -0
- package/dist/internal/acceptedBlockProjection.js +2 -0
- package/dist/internal/pageBreakRunDescendantIndex.d.ts +7 -2
- package/dist/internal/pageBreakRunDescendantIndex.js +12 -3
- package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +5 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
- package/dist/internal/revisionResolutionInline.js +1 -2
- package/dist/internal/subtreeHolds.d.ts +12 -0
- package/dist/internal/subtreeHolds.js +25 -0
- package/dist/internal/wholeStoryRevisionResolution.js +1 -1
- package/dist/layout-bridge/cellSelectionHighlight.js +3 -3
- package/dist/layout-bridge/convert/flowBlockPostprocessing.js +20 -12
- package/dist/layout-bridge/convert/flowConversionShared.d.ts +15 -1
- package/dist/layout-bridge/convert/flowConversionShared.js +9 -1
- package/dist/layout-bridge/convert/paragraphAttrs.d.ts +15 -4
- package/dist/layout-bridge/convert/paragraphAttrs.js +11 -4
- package/dist/layout-bridge/convert/paragraphBlockCache.d.ts +26 -0
- package/dist/layout-bridge/convert/paragraphBlockCache.js +137 -0
- package/dist/layout-bridge/convert/paragraphConversion.d.ts +12 -2
- package/dist/layout-bridge/convert/paragraphConversion.js +37 -5
- package/dist/layout-bridge/convert/paragraphRuns.d.ts +2 -2
- package/dist/layout-bridge/convert/sectionBoundaries.js +16 -0
- package/dist/layout-bridge/convert/tableConversion.js +19 -8
- package/dist/layout-bridge/convert/toFlowBlocks.js +144 -15
- package/dist/layout-bridge/convert/topLevelConversion.d.ts +74 -0
- package/dist/layout-bridge/convert/topLevelConversion.js +109 -0
- package/dist/layout-bridge/dom/clickToPositionDom.js +41 -40
- package/dist/layout-bridge/dom/findBodyPmSpans.js +4 -3
- package/dist/layout-bridge/dom/findHfPmSpans.js +10 -15
- package/dist/layout-bridge/dom/imeCaretAnchor.d.ts +8 -0
- package/dist/layout-bridge/dom/imeCaretAnchor.js +71 -7
- package/dist/layout-bridge/dom/textStreamDom.js +3 -2
- package/dist/layout-bridge/engine/blockIndex.d.ts +7 -0
- package/dist/layout-bridge/engine/blockIndex.js +12 -0
- package/dist/layout-bridge/engine/hitTest.js +9 -10
- package/dist/layout-bridge/engine/selectionRects.js +6 -6
- package/dist/layout-bridge/headerFooterLayout.js +12 -11
- package/dist/layout-bridge/tableInsertHover.js +2 -1
- package/dist/layout-engine/footnoteContinuation.d.ts +36 -0
- package/dist/layout-engine/footnoteContinuation.js +210 -0
- package/dist/layout-engine/index.d.ts +2 -2
- package/dist/layout-engine/index.js +7 -2
- package/dist/layout-engine/measure/cache.d.ts +2 -0
- package/dist/layout-engine/measure/cache.js +16 -6
- package/dist/layout-engine/measure/measureParagraph.js +1 -1
- package/dist/layout-engine/measure/paragraphKeyMemo.d.ts +8 -0
- package/dist/layout-engine/measure/paragraphKeyMemo.js +92 -0
- package/dist/layout-engine/tableLayout.js +29 -5
- package/dist/layout-engine/tableRowBreak.d.ts +36 -0
- package/dist/layout-engine/tableRowBreak.js +43 -1
- package/dist/layout-engine/types.d.ts +42 -1
- package/dist/layout-painter/imageLayout.js +2 -1
- package/dist/layout-painter/pageShellStyles.d.ts +10 -0
- package/dist/layout-painter/pageShellStyles.js +32 -0
- package/dist/layout-painter/reconcileRenderedContent.d.ts +19 -0
- package/dist/layout-painter/reconcileRenderedContent.js +117 -0
- package/dist/layout-painter/renderFragment.js +4 -6
- package/dist/layout-painter/renderImage.js +2 -2
- package/dist/layout-painter/renderPage.d.ts +4 -4
- package/dist/layout-painter/renderPage.js +54 -46
- package/dist/layout-painter/renderParagraph.js +3 -3
- package/dist/layout-painter/renderTable.js +16 -16
- package/dist/layout-painter/renderTextBox.js +2 -2
- package/dist/layout-painter/sdtBoundary.js +3 -2
- package/dist/managers/AutoSaveManager.d.ts +5 -1
- package/dist/managers/FindReplaceManager.js +3 -10
- package/dist/markdown/escape.d.ts +20 -1
- package/dist/markdown/escape.js +43 -1
- package/dist/markdown/renderBlock.js +4 -1
- package/dist/markdown/renderParagraph.js +13 -27
- package/dist/markdown/renderTable.js +6 -2
- package/dist/markdown/trailers.js +1 -0
- package/dist/paged-layout/blockGeometry.js +3 -2
- package/dist/paged-layout/editorScrollRoot.d.ts +9 -0
- package/dist/paged-layout/editorScrollRoot.js +10 -1
- package/dist/paged-layout/rangeProjection.js +5 -4
- package/dist/paged-layout/scrollToPmPosition.js +3 -3
- package/dist/paged-layout/selectionViewportRect.d.ts +6 -0
- package/dist/paged-layout/selectionViewportRect.js +8 -2
- package/dist/pdf/images.d.ts +17 -1
- package/dist/pdf/images.js +22 -4
- package/dist/pdf/writePdf.js +4 -2
- package/dist/prosemirror/attrs/index.js +2 -0
- package/dist/prosemirror/canonicalCommands.d.ts +39 -1
- package/dist/prosemirror/canonicalTableCommands.d.ts +28 -0
- package/dist/prosemirror/canonicalTableCommands.js +362 -0
- package/dist/prosemirror/commands/comments.d.ts +30 -2
- package/dist/prosemirror/commands/comments.js +189 -18
- package/dist/prosemirror/commands/formatting.d.ts +1 -1
- package/dist/prosemirror/commands/index.d.ts +1 -1
- package/dist/prosemirror/commentIdAllocator.js +2 -2
- package/dist/prosemirror/commentRangeBoundaryAttrs.d.ts +6 -0
- package/dist/prosemirror/commentRangeBoundaryAttrs.js +9 -3
- package/dist/prosemirror/commentRecords.d.ts +137 -0
- package/dist/prosemirror/commentRecords.js +400 -0
- package/dist/prosemirror/commentReferenceIntegrity.js +3 -4
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
- package/dist/prosemirror/conversion/fromProseDoc.js +85 -34
- package/dist/prosemirror/conversion/index.d.ts +2 -2
- package/dist/prosemirror/conversion/toProseDoc.d.ts +140 -4
- package/dist/prosemirror/conversion/toProseDoc.js +432 -76
- package/dist/prosemirror/extensions/StarterKit.js +2 -0
- package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +23 -1
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +61 -32
- package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
- package/dist/prosemirror/extensions/marks/CommentExtension.js +8 -3
- package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +4 -0
- package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.js +49 -0
- package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +3 -1
- package/dist/prosemirror/extensions/nodes/ImageExtension.js +12 -3
- package/dist/prosemirror/extensions/nodes/TableExtension.js +32 -31
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +1 -1
- package/dist/prosemirror/index.d.ts +3 -3
- package/dist/prosemirror/listLabels.js +3 -2
- package/dist/prosemirror/listNumbering.d.ts +6 -0
- package/dist/prosemirror/listNumbering.js +12 -9
- package/dist/prosemirror/lockedControls.d.ts +13 -0
- package/dist/prosemirror/lockedControls.js +106 -0
- package/dist/prosemirror/markupViewProjection.js +1 -1
- package/dist/prosemirror/nativeSelection.d.ts +33 -0
- package/dist/prosemirror/nativeSelection.js +74 -0
- package/dist/prosemirror/noteReferenceReview.js +2 -2
- package/dist/prosemirror/numberedRefFields.d.ts +2 -0
- package/dist/prosemirror/numberedRefFields.js +16 -5
- package/dist/prosemirror/paragraphMarkJoin.d.ts +6 -8
- package/dist/prosemirror/paragraphMarkJoin.js +155 -16
- package/dist/prosemirror/plugins/contentControlWidgets.js +2 -2
- package/dist/prosemirror/plugins/documentNumbering.js +37 -15
- package/dist/prosemirror/plugins/suggestionMode.js +33 -10
- package/dist/prosemirror/plugins/templatePreviewValues.js +16 -1
- package/dist/prosemirror/rebaseParagraphRuns.js +1 -1
- package/dist/prosemirror/replacedAnnotations.js +1 -0
- package/dist/prosemirror/runFormattingFromMarks.d.ts +0 -1
- package/dist/prosemirror/runFormattingFromMarks.js +2 -4
- package/dist/prosemirror/runFormattingReconciliation.js +2 -2
- package/dist/prosemirror/runIdentityAcrossRevisions.d.ts +23 -1
- package/dist/prosemirror/runIdentityAcrossRevisions.js +57 -8
- package/dist/prosemirror/runPropertyChangeResolution.js +1 -2
- package/dist/prosemirror/runStyleFormatting.d.ts +14 -4
- package/dist/prosemirror/runStyleFormatting.js +16 -13
- package/dist/prosemirror/schema/marks.d.ts +13 -1
- package/dist/prosemirror/storyListNumbering.js +7 -2
- package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
- package/dist/prosemirror/tableResize.d.ts +10 -9
- package/dist/prosemirror/tableResize.js +60 -49
- package/dist/prosemirror/textInput.d.ts +30 -1
- package/dist/prosemirror/textInput.js +144 -17
- package/dist/prosemirror/utils/visualLineNavigation.js +20 -18
- package/dist/prosemirror/validation.d.ts +19 -0
- package/dist/prosemirror/validation.js +79 -5
- package/dist/redline.js +23 -9
- package/dist/render-dom/HeaderFooterSelectionOverlay.js +5 -4
- package/dist/render-dom/RenderedDomContext.js +7 -6
- package/dist/server.d.ts +2 -2
- package/dist/style-sets/extract.js +2 -2
- package/dist/types/canonicalCapabilities.d.ts +38 -16
- package/dist/types/canonicalCapabilities.js +21 -18
- package/dist/utils/cssString.d.ts +7 -0
- package/dist/utils/cssString.js +9 -0
- package/dist/utils/findMatchView.js +4 -3
- package/dist/utils/fontResolver.js +4 -1
- package/dist/utils/formatToStyle.d.ts +1 -1
- package/dist/utils/mergeDocumentContent.js +2 -2
- package/dist/utils/paintedPositions.d.ts +60 -0
- package/dist/utils/paintedPositions.js +101 -0
- package/dist/utils/replaceText.d.ts +11 -0
- package/dist/utils/replaceText.js +39 -7
- package/dist/version-comparison.d.ts +9 -1
- package/dist/version-comparison.js +11 -5
- package/package.json +2 -3
|
@@ -5,14 +5,18 @@ import { CanonicalResourceSaveRefusalError, canonicalResourceReplacementOf } fro
|
|
|
5
5
|
import { repackWithCanonicalStoryRemovals } from "./canonicalStoryRepack.js";
|
|
6
6
|
import { getDocumentSourceBaseline } from "./headerFooterVerbatim.js";
|
|
7
7
|
import { resolveSelectiveSaveFlags } from "./selectiveSaveFlags.js";
|
|
8
|
+
import { withoutUnusedSessionLists } from "./sessionListPruning.js";
|
|
8
9
|
import { Result, TaggedError } from "better-result";
|
|
10
|
+
import { idKey, packageParagraphIds, withoutPendingSuggestions } from "@stll/docx-core/ops";
|
|
9
11
|
// src/docx/canonicalSave.ts
|
|
10
12
|
const CanonicalSaveDiagnosticErrorBase = TaggedError("CanonicalSaveDiagnosticError");
|
|
11
13
|
/** Forward a fidelity fallback through the adapters' existing error channel. */
|
|
12
14
|
var CanonicalSaveDiagnosticError = class extends CanonicalSaveDiagnosticErrorBase {};
|
|
13
15
|
/** Model and change signals come from one committed snapshot, never from PM. */
|
|
14
16
|
const serializeCanonicalSave = async ({ snapshot, options, featureFlags }) => {
|
|
15
|
-
const
|
|
17
|
+
const withoutSuggestions = withoutPendingSuggestions(snapshot.document);
|
|
18
|
+
if (withoutSuggestions.isErr()) throw withoutSuggestions.error;
|
|
19
|
+
const document = withoutUnusedSessionLists(withoutUnreferencedNotes(withoutSuggestions.value));
|
|
16
20
|
const replacementPart = snapshot.structure === "changed" ? canonicalResourceReplacementOf(document) : void 0;
|
|
17
21
|
if (replacementPart) {
|
|
18
22
|
const diagnostic = {
|
|
@@ -27,6 +31,11 @@ const serializeCanonicalSave = async ({ snapshot, options, featureFlags }) => {
|
|
|
27
31
|
diagnostic
|
|
28
32
|
});
|
|
29
33
|
}
|
|
34
|
+
const heldBack = /* @__PURE__ */ new Set();
|
|
35
|
+
if (withoutSuggestions.value !== snapshot.document) {
|
|
36
|
+
const kept = new Set(packageParagraphIds(withoutSuggestions.value.package).map(idKey));
|
|
37
|
+
for (const id of packageParagraphIds(snapshot.document.package)) if (!kept.has(idKey(id))) heldBack.add(idKey(id));
|
|
38
|
+
}
|
|
30
39
|
const baseline = document.originalBuffer;
|
|
31
40
|
const flags = resolveSelectiveSaveFlags(featureFlags);
|
|
32
41
|
const diagnostics = [];
|
|
@@ -40,7 +49,7 @@ const serializeCanonicalSave = async ({ snapshot, options, featureFlags }) => {
|
|
|
40
49
|
const { attemptSelectiveSave } = await import("./selectiveSave.js");
|
|
41
50
|
selectiveBuffer = await attemptSelectiveSave(document, baseline, {
|
|
42
51
|
bodyAuthority: "canonical",
|
|
43
|
-
changedParaIds: new Set(snapshot.changedBlockIds),
|
|
52
|
+
changedParaIds: new Set(snapshot.changedBlockIds.filter((id) => !heldBack.has(idKey(id)))),
|
|
44
53
|
structuralChange: snapshot.structure === "changed",
|
|
45
54
|
hasUntrackedChanges: false,
|
|
46
55
|
maxBytes: flags.selectiveSaveMaxBytes,
|
|
@@ -5,6 +5,10 @@ export declare class CanonicalDocxInputError extends CanonicalDocxInputErrorBase
|
|
|
5
5
|
message: string;
|
|
6
6
|
cause?: unknown;
|
|
7
7
|
}> {}
|
|
8
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Canonical seeding supports plaintext packages; refuse encryption before ZIP
|
|
10
|
+
* normalization. A package that repeats a paragraph or content control id is
|
|
11
|
+
* given unique ones, every paragraph and control kept.
|
|
12
|
+
*/
|
|
9
13
|
export declare const prepareCanonicalDocxInput: (input: DocxInput) => Promise<Err<ArrayBuffer, CanonicalDocxInputError> | Ok<Uint8Array<ArrayBufferLike>, CanonicalDocxInputError>>;
|
|
10
14
|
export {};
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { toArrayBuffer } from "../utils/docxInput.js";
|
|
2
2
|
import { DOCX_CONTAINER_TYPES, detectDocxContainerType } from "./encryption/containerFormat.js";
|
|
3
3
|
import { ensureParaIds } from "./ensureParaIds.js";
|
|
4
|
+
import { ensureUniqueControlIds } from "./ensureUniqueControlIds.js";
|
|
4
5
|
import { Result, TaggedError } from "better-result";
|
|
5
6
|
// src/docx/canonicalSessionInput.ts
|
|
6
7
|
const CanonicalDocxInputErrorBase = TaggedError("CanonicalDocxInputError");
|
|
7
8
|
var CanonicalDocxInputError = class extends CanonicalDocxInputErrorBase {};
|
|
8
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Canonical seeding supports plaintext packages; refuse encryption before ZIP
|
|
11
|
+
* normalization. A package that repeats a paragraph or content control id is
|
|
12
|
+
* given unique ones, every paragraph and control kept.
|
|
13
|
+
*/
|
|
9
14
|
const prepareCanonicalDocxInput = async (input) => {
|
|
10
15
|
const bytes = await Result.tryPromise({
|
|
11
16
|
try: () => toArrayBuffer(input),
|
|
@@ -17,7 +22,7 @@ const prepareCanonicalDocxInput = async (input) => {
|
|
|
17
22
|
if (bytes.isErr()) return bytes;
|
|
18
23
|
if (detectDocxContainerType(bytes.value) === DOCX_CONTAINER_TYPES.CFB) return Result.err(new CanonicalDocxInputError({ message: "Password-protected documents are unavailable in the experimental canonical session." }));
|
|
19
24
|
return Result.tryPromise({
|
|
20
|
-
try: async () => (await ensureParaIds(bytes.value)).docx,
|
|
25
|
+
try: async () => (await ensureUniqueControlIds((await ensureParaIds(bytes.value)).docx)).docx,
|
|
21
26
|
catch: (cause) => new CanonicalDocxInputError({
|
|
22
27
|
message: cause instanceof Error ? cause.message : "Canonical document normalization failed.",
|
|
23
28
|
cause
|
|
@@ -1,17 +1,51 @@
|
|
|
1
1
|
import { document_d_exports } from "../types/document.js";
|
|
2
|
-
|
|
2
|
+
type CommentMarker = Extract<document_d_exports.ParagraphContent, {
|
|
3
|
+
type: "commentRangeStart";
|
|
4
|
+
} | {
|
|
5
|
+
type: "commentRangeEnd";
|
|
6
|
+
} | {
|
|
7
|
+
type: "commentReference";
|
|
8
|
+
}>;
|
|
9
|
+
/** A marker inside a paragraph, in the inline-content array it sits in. */
|
|
10
|
+
export type InlineCommentMarkerSlot = {
|
|
11
|
+
level: "inline";
|
|
3
12
|
/** The inline-content array the marker sits in, so a caller can splice it. */
|
|
4
13
|
content: document_d_exports.ParagraphContent[];
|
|
5
14
|
index: number;
|
|
6
|
-
item:
|
|
15
|
+
item: CommentMarker;
|
|
16
|
+
};
|
|
17
|
+
/** A range marker between blocks, in the block array it sits in. */
|
|
18
|
+
export type BlockCommentMarkerSlot = {
|
|
19
|
+
level: "block";
|
|
20
|
+
content: document_d_exports.BlockContent[];
|
|
21
|
+
index: number;
|
|
22
|
+
item: Extract<document_d_exports.BlockContent, {
|
|
7
23
|
type: "commentRangeStart";
|
|
8
24
|
} | {
|
|
9
25
|
type: "commentRangeEnd";
|
|
10
|
-
} | {
|
|
11
|
-
type: "commentReference";
|
|
12
26
|
}>;
|
|
13
27
|
};
|
|
28
|
+
export type CommentMarkerSlot = InlineCommentMarkerSlot | BlockCommentMarkerSlot;
|
|
14
29
|
export declare const visitCommentMarkers: (blocks: readonly document_d_exports.BlockContent[], visit: (slot: CommentMarkerSlot) => void) => void;
|
|
30
|
+
/** A paragraph's comment markers, in document order. */
|
|
31
|
+
export type ParagraphCommentMarkers = (paragraph: document_d_exports.Paragraph) => readonly CommentMarker[];
|
|
32
|
+
/** A paragraph's comment markers, read from all of its content. */
|
|
33
|
+
export declare const paragraphCommentMarkers: ParagraphCommentMarkers;
|
|
34
|
+
/**
|
|
35
|
+
* Each paragraph's comment markers, read once per paragraph object. Only for
|
|
36
|
+
* documents whose paragraphs are never changed in place, as a session's
|
|
37
|
+
* versions are: an edit replaces the paragraphs it changes.
|
|
38
|
+
*/
|
|
39
|
+
export declare class CommentMarkerCache {
|
|
40
|
+
private readonly known;
|
|
41
|
+
readonly read: ParagraphCommentMarkers;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Every comment marker of a story's blocks in the order
|
|
45
|
+
* {@link visitCommentMarkers} visits them, each paragraph's read through
|
|
46
|
+
* `markersOf`.
|
|
47
|
+
*/
|
|
48
|
+
export declare const visitCommentMarkerItems: (blocks: readonly document_d_exports.BlockContent[], markersOf: ParagraphCommentMarkers, visit: (item: CommentMarker | BlockCommentMarkerSlot["item"]) => void) => void;
|
|
15
49
|
/** Remove every serialized anchor record for comments whose definitions are retired. */
|
|
16
50
|
export declare const removeCommentMarkers: (blocks: readonly document_d_exports.BlockContent[], commentIds: ReadonlySet<number>) => document_d_exports.BlockContent[];
|
|
17
51
|
/**
|
|
@@ -26,4 +60,5 @@ export declare const removeCommentMarkers: (blocks: readonly document_d_exports.
|
|
|
26
60
|
* whole story: a reference that trails the end of a range three paragraphs back
|
|
27
61
|
* is still not a point comment.
|
|
28
62
|
*/
|
|
29
|
-
export declare const rangedCommentIds: (blocks: readonly document_d_exports.BlockContent[]) => ReadonlySet<number>;
|
|
63
|
+
export declare const rangedCommentIds: (blocks: readonly document_d_exports.BlockContent[]) => ReadonlySet<number>;
|
|
64
|
+
export {};
|
|
@@ -5,6 +5,7 @@ const visitCommentMarkers = (blocks, visit) => {
|
|
|
5
5
|
const visitParagraph = (paragraph) => {
|
|
6
6
|
visitInlineContentSlots(paragraph, ({ content, index, item }) => {
|
|
7
7
|
if (item.type === "commentRangeStart" || item.type === "commentRangeEnd" || item.type === "commentReference") visit({
|
|
8
|
+
level: "inline",
|
|
8
9
|
content,
|
|
9
10
|
index,
|
|
10
11
|
item
|
|
@@ -12,22 +13,99 @@ const visitCommentMarkers = (blocks, visit) => {
|
|
|
12
13
|
});
|
|
13
14
|
};
|
|
14
15
|
const visitBlock = (block) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
switch (block.type) {
|
|
17
|
+
case "paragraph":
|
|
18
|
+
visitParagraph(block);
|
|
19
|
+
return;
|
|
20
|
+
case "table":
|
|
21
|
+
for (const row of block.rows) for (const cell of row.cells) visitBlocks(cell.content);
|
|
22
|
+
return;
|
|
23
|
+
case "blockSdt":
|
|
24
|
+
case "blockCustomXml":
|
|
25
|
+
visitBlocks(block.content);
|
|
26
|
+
return;
|
|
27
|
+
case "commentRangeStart":
|
|
28
|
+
case "commentRangeEnd": return;
|
|
29
|
+
case "preservedBlock":
|
|
30
|
+
case "bookmarkStart":
|
|
31
|
+
case "bookmarkEnd":
|
|
32
|
+
case "moveFromRangeStart":
|
|
33
|
+
case "moveFromRangeEnd":
|
|
34
|
+
case "moveToRangeStart":
|
|
35
|
+
case "moveToRangeEnd": return;
|
|
36
|
+
default: return block;
|
|
22
37
|
}
|
|
23
|
-
if (block.type !== "blockSdt" && block.type !== "blockCustomXml") return;
|
|
24
|
-
visitBlocks(block.content);
|
|
25
38
|
};
|
|
26
39
|
const visitBlocks = (nested) => {
|
|
27
|
-
for (const block of nested)
|
|
40
|
+
for (const [index, block] of nested.entries()) {
|
|
41
|
+
if (block.type === "commentRangeStart" || block.type === "commentRangeEnd") {
|
|
42
|
+
visit({
|
|
43
|
+
level: "block",
|
|
44
|
+
content: nested,
|
|
45
|
+
index,
|
|
46
|
+
item: block
|
|
47
|
+
});
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
visitBlock(block);
|
|
51
|
+
}
|
|
28
52
|
};
|
|
29
53
|
visitBlocks(blocks);
|
|
30
54
|
};
|
|
55
|
+
/** A paragraph's comment markers, read from all of its content. */
|
|
56
|
+
const paragraphCommentMarkers = (paragraph) => {
|
|
57
|
+
const markers = [];
|
|
58
|
+
visitInlineContentSlots(paragraph, ({ item }) => {
|
|
59
|
+
if (item.type === "commentRangeStart" || item.type === "commentRangeEnd" || item.type === "commentReference") markers.push(item);
|
|
60
|
+
});
|
|
61
|
+
return markers;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Each paragraph's comment markers, read once per paragraph object. Only for
|
|
65
|
+
* documents whose paragraphs are never changed in place, as a session's
|
|
66
|
+
* versions are: an edit replaces the paragraphs it changes.
|
|
67
|
+
*/
|
|
68
|
+
var CommentMarkerCache = class {
|
|
69
|
+
known = /* @__PURE__ */ new WeakMap();
|
|
70
|
+
read = (paragraph) => {
|
|
71
|
+
const kept = this.known.get(paragraph);
|
|
72
|
+
if (kept !== void 0) return kept;
|
|
73
|
+
const markers = paragraphCommentMarkers(paragraph);
|
|
74
|
+
this.known.set(paragraph, markers);
|
|
75
|
+
return markers;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Every comment marker of a story's blocks in the order
|
|
80
|
+
* {@link visitCommentMarkers} visits them, each paragraph's read through
|
|
81
|
+
* `markersOf`.
|
|
82
|
+
*/
|
|
83
|
+
const visitCommentMarkerItems = (blocks, markersOf, visit) => {
|
|
84
|
+
for (const block of blocks) switch (block.type) {
|
|
85
|
+
case "commentRangeStart":
|
|
86
|
+
case "commentRangeEnd":
|
|
87
|
+
visit(block);
|
|
88
|
+
break;
|
|
89
|
+
case "paragraph":
|
|
90
|
+
for (const marker of markersOf(block)) visit(marker);
|
|
91
|
+
break;
|
|
92
|
+
case "table":
|
|
93
|
+
for (const row of block.rows) for (const cell of row.cells) visitCommentMarkerItems(cell.content, markersOf, visit);
|
|
94
|
+
break;
|
|
95
|
+
case "blockSdt":
|
|
96
|
+
case "blockCustomXml":
|
|
97
|
+
visitCommentMarkerItems(block.content, markersOf, visit);
|
|
98
|
+
break;
|
|
99
|
+
case "preservedBlock":
|
|
100
|
+
case "bookmarkStart":
|
|
101
|
+
case "bookmarkEnd":
|
|
102
|
+
case "moveFromRangeStart":
|
|
103
|
+
case "moveFromRangeEnd":
|
|
104
|
+
case "moveToRangeStart":
|
|
105
|
+
case "moveToRangeEnd": break;
|
|
106
|
+
default: return block;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
31
109
|
/** Remove every serialized anchor record for comments whose definitions are retired. */
|
|
32
110
|
const removeCommentMarkers = (blocks, commentIds) => {
|
|
33
111
|
if (commentIds.size === 0) return blocks.slice();
|
|
@@ -209,6 +287,7 @@ const removeCommentMarkers = (blocks, commentIds) => {
|
|
|
209
287
|
case "moveFromRangeEnd":
|
|
210
288
|
case "moveToRangeStart":
|
|
211
289
|
case "moveToRangeEnd":
|
|
290
|
+
case "complexField":
|
|
212
291
|
case "preservedInline": return item;
|
|
213
292
|
}
|
|
214
293
|
};
|
|
@@ -253,6 +332,8 @@ const removeCommentMarkers = (blocks, commentIds) => {
|
|
|
253
332
|
case "preservedBlock":
|
|
254
333
|
case "bookmarkStart":
|
|
255
334
|
case "bookmarkEnd":
|
|
335
|
+
case "commentRangeStart":
|
|
336
|
+
case "commentRangeEnd":
|
|
256
337
|
case "moveFromRangeStart":
|
|
257
338
|
case "moveFromRangeEnd":
|
|
258
339
|
case "moveToRangeStart":
|
|
@@ -260,7 +341,8 @@ const removeCommentMarkers = (blocks, commentIds) => {
|
|
|
260
341
|
}
|
|
261
342
|
};
|
|
262
343
|
const rebuildBlocks = (content) => rebuildArray(content, rebuildBlock);
|
|
263
|
-
|
|
344
|
+
const rebuilt = rebuildBlocks(blocks);
|
|
345
|
+
return rebuilt === blocks ? blocks.slice() : rebuilt;
|
|
264
346
|
};
|
|
265
347
|
/**
|
|
266
348
|
* Comments that open a range anywhere in these blocks.
|
|
@@ -281,4 +363,4 @@ const rangedCommentIds = (blocks) => {
|
|
|
281
363
|
});
|
|
282
364
|
return ids;
|
|
283
365
|
};
|
|
284
|
-
export { rangedCommentIds, removeCommentMarkers, visitCommentMarkers };
|
|
366
|
+
export { CommentMarkerCache, paragraphCommentMarkers, rangedCommentIds, removeCommentMarkers, visitCommentMarkerItems, visitCommentMarkers };
|
|
@@ -161,20 +161,38 @@ const withoutOrphanBlockMarkers = (blocks, validCommentIds) => {
|
|
|
161
161
|
for (const block of blocks) {
|
|
162
162
|
const nextBlock = withoutOrphanBlockMarker(block, validCommentIds);
|
|
163
163
|
if (nextBlock !== block) changed = true;
|
|
164
|
-
next.push(nextBlock);
|
|
164
|
+
if (nextBlock !== null) next.push(nextBlock);
|
|
165
165
|
}
|
|
166
166
|
return changed ? next : null;
|
|
167
167
|
};
|
|
168
|
+
/**
|
|
169
|
+
* A block with its orphaned comment markers gone, or `null` when the block is
|
|
170
|
+
* itself one: a comment range marker between blocks for a comment the save no
|
|
171
|
+
* longer holds.
|
|
172
|
+
*/
|
|
168
173
|
const withoutOrphanBlockMarker = (block, validCommentIds) => {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
174
|
+
switch (block.type) {
|
|
175
|
+
case "paragraph": return withoutOrphanParagraphMarkers(block, validCommentIds);
|
|
176
|
+
case "table": return withoutOrphanTableMarkers(block, validCommentIds);
|
|
177
|
+
case "blockSdt":
|
|
178
|
+
case "blockCustomXml": {
|
|
179
|
+
const content = withoutOrphanBlockMarkers(block.content, validCommentIds);
|
|
180
|
+
return content ? {
|
|
181
|
+
...block,
|
|
182
|
+
content
|
|
183
|
+
} : block;
|
|
184
|
+
}
|
|
185
|
+
case "commentRangeStart":
|
|
186
|
+
case "commentRangeEnd": return validCommentIds.has(block.id) ? block : null;
|
|
187
|
+
case "preservedBlock":
|
|
188
|
+
case "bookmarkStart":
|
|
189
|
+
case "bookmarkEnd":
|
|
190
|
+
case "moveFromRangeStart":
|
|
191
|
+
case "moveFromRangeEnd":
|
|
192
|
+
case "moveToRangeStart":
|
|
193
|
+
case "moveToRangeEnd": return block;
|
|
194
|
+
default: return block;
|
|
195
|
+
}
|
|
178
196
|
};
|
|
179
197
|
const withoutOrphanTableMarkers = (table, validCommentIds) => {
|
|
180
198
|
let changed = false;
|
|
@@ -216,24 +234,12 @@ const withoutOrphanTableCellBlockMarkers = (blocks, validCommentIds) => {
|
|
|
216
234
|
let changed = false;
|
|
217
235
|
const next = [];
|
|
218
236
|
for (const block of blocks) {
|
|
219
|
-
const nextBlock =
|
|
237
|
+
const nextBlock = withoutOrphanBlockMarker(block, validCommentIds);
|
|
220
238
|
if (nextBlock !== block) changed = true;
|
|
221
|
-
next.push(nextBlock);
|
|
239
|
+
if (nextBlock !== null) next.push(nextBlock);
|
|
222
240
|
}
|
|
223
241
|
return changed ? next : null;
|
|
224
242
|
};
|
|
225
|
-
const withoutOrphanTableCellBlockMarker = (block, validCommentIds) => {
|
|
226
|
-
if (block.type === "paragraph") return withoutOrphanParagraphMarkers(block, validCommentIds);
|
|
227
|
-
if (block.type === "table") return withoutOrphanTableMarkers(block, validCommentIds);
|
|
228
|
-
if (block.type === "blockSdt" || block.type === "blockCustomXml") {
|
|
229
|
-
const content = withoutOrphanTableCellBlockMarkers(block.content, validCommentIds);
|
|
230
|
-
return content ? {
|
|
231
|
-
...block,
|
|
232
|
-
content
|
|
233
|
-
} : block;
|
|
234
|
-
}
|
|
235
|
-
return block;
|
|
236
|
-
};
|
|
237
243
|
const withoutOrphanParagraphMarkers = (paragraph, validCommentIds) => {
|
|
238
244
|
let changed = false;
|
|
239
245
|
const content = [];
|
|
@@ -2,5 +2,9 @@ import { document_d_exports } from "../types/document.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Collapse each comment's range markers to its first start and its last end.
|
|
4
4
|
* Answers how many markers were dropped.
|
|
5
|
+
*
|
|
6
|
+
* A start or an end between blocks counts as one of the range's markers, so a
|
|
7
|
+
* range that opens beside a content control keeps that start and loses the
|
|
8
|
+
* one its mark wrote at the front of the first paragraph.
|
|
5
9
|
*/
|
|
6
10
|
export declare const joinCommentRangesAcrossParagraphs: (blocks: readonly document_d_exports.BlockContent[]) => number;
|
|
@@ -4,29 +4,43 @@ import { InlineContentRemovals } from "./inlineContentRemovals.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* Collapse each comment's range markers to its first start and its last end.
|
|
6
6
|
* Answers how many markers were dropped.
|
|
7
|
+
*
|
|
8
|
+
* A start or an end between blocks counts as one of the range's markers, so a
|
|
9
|
+
* range that opens beside a content control keeps that start and loses the
|
|
10
|
+
* one its mark wrote at the front of the first paragraph.
|
|
7
11
|
*/
|
|
8
12
|
const joinCommentRangesAcrossParagraphs = (blocks) => {
|
|
9
13
|
const startsById = /* @__PURE__ */ new Map();
|
|
10
14
|
const endsById = /* @__PURE__ */ new Map();
|
|
11
|
-
visitCommentMarkers(blocks, (
|
|
15
|
+
visitCommentMarkers(blocks, (slot) => {
|
|
16
|
+
const { item } = slot;
|
|
12
17
|
if (item.type === "commentReference") return;
|
|
13
18
|
const slotsById = item.type === "commentRangeStart" ? startsById : endsById;
|
|
14
19
|
const slots = slotsById.get(item.id);
|
|
15
20
|
if (slots) {
|
|
16
|
-
slots.push(
|
|
17
|
-
content,
|
|
18
|
-
index
|
|
19
|
-
});
|
|
21
|
+
slots.push(slot);
|
|
20
22
|
return;
|
|
21
23
|
}
|
|
22
|
-
slotsById.set(item.id, [
|
|
23
|
-
content,
|
|
24
|
-
index
|
|
25
|
-
}]);
|
|
24
|
+
slotsById.set(item.id, [slot]);
|
|
26
25
|
});
|
|
27
26
|
const removals = new InlineContentRemovals();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const blockRemovals = /* @__PURE__ */ new Map();
|
|
28
|
+
const remove = (slot) => {
|
|
29
|
+
if (slot.level === "inline") {
|
|
30
|
+
removals.mark(slot);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const indexes = blockRemovals.get(slot.content) ?? [];
|
|
34
|
+
indexes.push(slot.index);
|
|
35
|
+
blockRemovals.set(slot.content, indexes);
|
|
36
|
+
};
|
|
37
|
+
for (const slots of startsById.values()) for (const slot of slots.slice(1)) remove(slot);
|
|
38
|
+
for (const slots of endsById.values()) for (const slot of slots.slice(0, -1)) remove(slot);
|
|
39
|
+
let dropped = removals.apply();
|
|
40
|
+
for (const [content, indexes] of blockRemovals) for (const index of indexes.toSorted((first, second) => second - first)) {
|
|
41
|
+
content.splice(index, 1);
|
|
42
|
+
dropped += 1;
|
|
43
|
+
}
|
|
44
|
+
return dropped;
|
|
31
45
|
};
|
|
32
46
|
export { joinCommentRangesAcrossParagraphs };
|
|
@@ -7,14 +7,15 @@ import { visitCommentMarkers } from "./commentAnchorIndex.js";
|
|
|
7
7
|
const completeCommentReferences = (blocks) => {
|
|
8
8
|
const lastRangeEnds = /* @__PURE__ */ new Map();
|
|
9
9
|
const referencedIds = /* @__PURE__ */ new Set();
|
|
10
|
-
visitCommentMarkers(blocks, (
|
|
10
|
+
visitCommentMarkers(blocks, (slot) => {
|
|
11
|
+
const { item } = slot;
|
|
11
12
|
if (item.type === "commentReference") {
|
|
12
13
|
referencedIds.add(item.id);
|
|
13
14
|
return;
|
|
14
15
|
}
|
|
15
|
-
if (item.type === "commentRangeEnd") lastRangeEnds.set(item.id, {
|
|
16
|
-
content,
|
|
17
|
-
index
|
|
16
|
+
if (item.type === "commentRangeEnd" && slot.level === "inline") lastRangeEnds.set(item.id, {
|
|
17
|
+
content: slot.content,
|
|
18
|
+
index: slot.index
|
|
18
19
|
});
|
|
19
20
|
});
|
|
20
21
|
const insertionsByContent = /* @__PURE__ */ new Map();
|
|
@@ -21,8 +21,10 @@ const normalizeCommentReferences = ({ documentBody, comments, headers, footers,
|
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
if (isCommentRangeMarker(item)) rangeMarkers.push({
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
slot: {
|
|
25
|
+
content,
|
|
26
|
+
index
|
|
27
|
+
},
|
|
26
28
|
id: item.id,
|
|
27
29
|
type: item.type
|
|
28
30
|
});
|
|
@@ -32,19 +34,40 @@ const normalizeCommentReferences = ({ documentBody, comments, headers, footers,
|
|
|
32
34
|
for (const row of table.rows) for (const cell of row.cells) normalizeBlocks(cell.content);
|
|
33
35
|
};
|
|
34
36
|
const normalizeBlock = (block) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
switch (block.type) {
|
|
38
|
+
case "commentRangeStart":
|
|
39
|
+
case "commentRangeEnd":
|
|
40
|
+
if (validCommentIds.has(block.id)) rangeMarkers.push({
|
|
41
|
+
id: block.id,
|
|
42
|
+
type: block.type
|
|
43
|
+
});
|
|
44
|
+
return;
|
|
45
|
+
case "paragraph":
|
|
46
|
+
normalizeParagraph(block);
|
|
47
|
+
return;
|
|
48
|
+
case "table":
|
|
49
|
+
normalizeTable(block);
|
|
50
|
+
return;
|
|
51
|
+
case "blockSdt":
|
|
52
|
+
case "blockCustomXml":
|
|
53
|
+
normalizeBlocks(block.content);
|
|
54
|
+
return;
|
|
55
|
+
case "preservedBlock":
|
|
56
|
+
case "bookmarkStart":
|
|
57
|
+
case "bookmarkEnd":
|
|
58
|
+
case "moveFromRangeStart":
|
|
59
|
+
case "moveFromRangeEnd":
|
|
60
|
+
case "moveToRangeStart":
|
|
61
|
+
case "moveToRangeEnd": return;
|
|
62
|
+
default: return block;
|
|
42
63
|
}
|
|
43
|
-
if (block.type !== "blockSdt" && block.type !== "blockCustomXml") return;
|
|
44
|
-
normalizeBlocks(block.content);
|
|
45
64
|
};
|
|
46
65
|
const normalizeBlocks = (blocks) => {
|
|
47
66
|
for (const block of blocks) normalizeBlock(block);
|
|
67
|
+
for (const [index, block] of blocks.entries()) if ((block.type === "commentRangeStart" || block.type === "commentRangeEnd") && !validCommentIds.has(block.id)) blocks[index] = {
|
|
68
|
+
type: "preservedBlock",
|
|
69
|
+
xml: `<w:${block.type} w:id="${String(block.id)}"${block.displacedByCustomXml === void 0 ? "" : ` w:displacedByCustomXml="${block.displacedByCustomXml}"`}/>`
|
|
70
|
+
};
|
|
48
71
|
};
|
|
49
72
|
normalizeBlocks(documentBody.content);
|
|
50
73
|
for (const header of headers?.values() ?? []) normalizeBlocks(header.content);
|
|
@@ -75,32 +98,31 @@ const reanchorUnbalancedCommentRanges = (rangeMarkers) => {
|
|
|
75
98
|
for (const marker of markers) {
|
|
76
99
|
if (marker.type === "commentRangeStart") {
|
|
77
100
|
if (openStart) {
|
|
78
|
-
reanchorCommentRangeMarker(marker);
|
|
79
|
-
reanchoredCount += 1;
|
|
101
|
+
if (reanchorCommentRangeMarker(marker)) reanchoredCount += 1;
|
|
80
102
|
continue;
|
|
81
103
|
}
|
|
82
104
|
openStart = marker;
|
|
83
105
|
continue;
|
|
84
106
|
}
|
|
85
107
|
if (!openStart) {
|
|
86
|
-
reanchorCommentRangeMarker(marker);
|
|
87
|
-
reanchoredCount += 1;
|
|
108
|
+
if (reanchorCommentRangeMarker(marker)) reanchoredCount += 1;
|
|
88
109
|
continue;
|
|
89
110
|
}
|
|
90
111
|
openStart = null;
|
|
91
112
|
}
|
|
92
113
|
if (openStart) {
|
|
93
|
-
reanchorCommentRangeMarker(openStart);
|
|
94
|
-
reanchoredCount += 1;
|
|
114
|
+
if (reanchorCommentRangeMarker(openStart)) reanchoredCount += 1;
|
|
95
115
|
}
|
|
96
116
|
}
|
|
97
117
|
return reanchoredCount;
|
|
98
118
|
};
|
|
99
119
|
const reanchorCommentRangeMarker = (marker) => {
|
|
100
|
-
marker.
|
|
120
|
+
if (!marker.slot) return false;
|
|
121
|
+
marker.slot.content[marker.slot.index] = {
|
|
101
122
|
type: "commentReference",
|
|
102
123
|
id: marker.id
|
|
103
124
|
};
|
|
125
|
+
return true;
|
|
104
126
|
};
|
|
105
127
|
const isCommentMarker = (content) => content.type === "commentRangeStart" || content.type === "commentRangeEnd" || content.type === "commentReference";
|
|
106
128
|
const isCommentRangeMarker = (content) => content.type === "commentRangeStart" || content.type === "commentRangeEnd";
|
|
@@ -190,9 +190,16 @@ function inspectHyperlink(hyperlink, context) {
|
|
|
190
190
|
});
|
|
191
191
|
continue;
|
|
192
192
|
}
|
|
193
|
-
if (child.type === "inlineWrapper")
|
|
193
|
+
if (child.type === "inlineWrapper") {
|
|
194
|
+
inspectParagraphContent(child.content, {
|
|
195
|
+
...context,
|
|
196
|
+
path: `${path}.content`
|
|
197
|
+
});
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (child.type === "complexField") inspectParagraphContent([child], {
|
|
194
201
|
...context,
|
|
195
|
-
path
|
|
202
|
+
path
|
|
196
203
|
});
|
|
197
204
|
}
|
|
198
205
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TRANSITIONAL_NAMESPACE_BY_STRICT_URI } from "./strictValueEncodings.gen.js";
|
|
2
2
|
import { captureVerbatimXml } from "./verbatimCapture.js";
|
|
3
3
|
import { WORDPROCESSINGML_NAMESPACE_URIS, getChildElements, getLocalName, getNamespaceUri } from "./xmlParser.js";
|
|
4
|
+
import { OOXML_NS } from "@stll/docx-core/xml/namespaces";
|
|
4
5
|
import { SEQUENCE_CHILDREN } from "@stll/docx-core/schema";
|
|
5
6
|
// src/docx/containerChildren.ts
|
|
6
7
|
/** Keep this child's markup verbatim, in place. */
|
|
@@ -167,13 +168,33 @@ const sequenceOrdinals = (container) => {
|
|
|
167
168
|
SEQUENCE_ORDINALS.set(container, ordinals);
|
|
168
169
|
return ordinals;
|
|
169
170
|
};
|
|
171
|
+
/**
|
|
172
|
+
* Where a container's schema puts the children of its extension namespaces.
|
|
173
|
+
*
|
|
174
|
+
* The neighbour rule cannot hold for these: an edit that adds a declared
|
|
175
|
+
* property after the source's last one would land it behind the extension
|
|
176
|
+
* child, out of the order the extended schema requires. `CT_RPr` appends the
|
|
177
|
+
* `w14` run effects (`w14:ligatures`, `w14:textFill` and the rest) after
|
|
178
|
+
* every base property and before `w:rPrChange`, so they take the place of the
|
|
179
|
+
* declared child before that record.
|
|
180
|
+
*/
|
|
181
|
+
const EXTENSION_PLACEMENT = { "run-properties": {
|
|
182
|
+
namespaces: /* @__PURE__ */ new Set([OOXML_NS.w14]),
|
|
183
|
+
after: "oMath"
|
|
184
|
+
} };
|
|
170
185
|
const computeSequencePositions = (container, element) => {
|
|
171
186
|
const ordinals = sequenceOrdinals(container);
|
|
187
|
+
const extension = EXTENSION_PLACEMENT[container];
|
|
188
|
+
const extensionAt = extension === void 0 ? -1 : ordinals.get(extension.after) ?? -1;
|
|
172
189
|
const positions = /* @__PURE__ */ new Map();
|
|
173
190
|
let previous = -1;
|
|
174
191
|
for (const child of getChildElements(element)) {
|
|
175
192
|
const namespace = getNamespaceUri(child);
|
|
176
|
-
const
|
|
193
|
+
const isDeclaredNamespace = namespace === void 0 || WORDPROCESSINGML_NAMESPACE_URIS.has(namespace);
|
|
194
|
+
const isExtension = namespace !== void 0 && extension?.namespaces.has(namespace) === true && extensionAt !== -1;
|
|
195
|
+
let at = -1;
|
|
196
|
+
if (isDeclaredNamespace) at = ordinals.get(getLocalName(child.name)) ?? -1;
|
|
197
|
+
else if (isExtension) at = extensionAt;
|
|
177
198
|
if (at !== -1) previous = at;
|
|
178
199
|
positions.set(child, at === -1 ? previous : at);
|
|
179
200
|
}
|
|
@@ -3,7 +3,7 @@ import { spliceXml } from "./selectiveXmlPatch.js";
|
|
|
3
3
|
import { getAttribute, getLocalName, getNamespacePrefix, getNamespaceUri, parseXmlDocument } from "./xmlParser.js";
|
|
4
4
|
import { panic } from "better-result";
|
|
5
5
|
import { escapeXmlAttribute } from "@stll/docx-core";
|
|
6
|
-
import { OOXML_NS } from "@stll/docx-
|
|
6
|
+
import { OOXML_NS } from "@stll/docx-core/xml/namespaces";
|
|
7
7
|
// src/docx/contentTypeRegistry.ts
|
|
8
8
|
/** Register a package part without rewriting authored content-type entries. */
|
|
9
9
|
const registerContentTypeParts = (xml, parts) => {
|
|
@@ -83,6 +83,8 @@ const loadSector = (file, header, sectorId) => {
|
|
|
83
83
|
return file.subarray(offset, offset + header.sectorBytes);
|
|
84
84
|
};
|
|
85
85
|
const loadFatSectorIds = (file, header) => {
|
|
86
|
+
const physicalSectors = Math.floor(file.length / header.sectorBytes) - 1;
|
|
87
|
+
if (header.fatSectorCount > physicalSectors) throw new Error(`Declared FAT sector count ${header.fatSectorCount} exceeds the ${physicalSectors} sectors in the file`);
|
|
86
88
|
const ids = [...header.headerDifat];
|
|
87
89
|
const maxDifatSectors = Math.ceil(file.length / header.sectorBytes);
|
|
88
90
|
const stepLimit = Math.min(header.difatSectorCount, maxDifatSectors);
|
|
@@ -102,7 +104,13 @@ const loadFatSectorIds = (file, header) => {
|
|
|
102
104
|
chain = u32(view, header.sectorBytes - 4);
|
|
103
105
|
}
|
|
104
106
|
if (ids.length < header.fatSectorCount) throw new Error("DIFAT chain shorter than declared FAT sector count");
|
|
105
|
-
|
|
107
|
+
const fatSectorIds = ids.slice(0, header.fatSectorCount);
|
|
108
|
+
const listed = /* @__PURE__ */ new Set();
|
|
109
|
+
for (const id of fatSectorIds) {
|
|
110
|
+
if (listed.has(id)) throw new Error(`FAT sector ${id} listed more than once`);
|
|
111
|
+
listed.add(id);
|
|
112
|
+
}
|
|
113
|
+
return fatSectorIds;
|
|
106
114
|
};
|
|
107
115
|
const loadFat = (file, header) => {
|
|
108
116
|
const table = [];
|