@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
|
@@ -1,8 +1,51 @@
|
|
|
1
1
|
import { document_d_exports } from "../types/document.js";
|
|
2
|
+
import { ComputeListMarkerOptions } from "./listMarkerComputation.js";
|
|
2
3
|
import { DocumentOp } from "@stll/docx-core/ops";
|
|
3
4
|
type CanonicalListNormalization = {
|
|
4
5
|
document: document_d_exports.Document;
|
|
5
6
|
inverse: DocumentOp[];
|
|
6
7
|
};
|
|
7
|
-
|
|
8
|
+
/** The package fields a block's normalization reads; the rest of it is never read. */
|
|
9
|
+
type ListNormalizationPackageInputs = Pick<document_d_exports.Document["package"], "styles" | "numbering">;
|
|
10
|
+
/**
|
|
11
|
+
* Normalized blocks kept across the normalizations of one session.
|
|
12
|
+
*
|
|
13
|
+
* Normalizing a block reads the block, the package's styles and numbering,
|
|
14
|
+
* and the list counters the blocks before it advanced. A block an edit left
|
|
15
|
+
* the same object, with the same kept facts and snapshot registration, that
|
|
16
|
+
* normalized to itself before, normalizes to itself again from the same
|
|
17
|
+
* counters. So a story is normalized again from the last checkpoint before
|
|
18
|
+
* its first changed block, and only until the counters after its last
|
|
19
|
+
* changed block match those the earlier run had at that place.
|
|
20
|
+
*/
|
|
21
|
+
export declare class ListNormalizationCache {
|
|
22
|
+
private inputs;
|
|
23
|
+
private runs;
|
|
24
|
+
private readonly spacing;
|
|
25
|
+
constructor({ checkpointSpacing }?: {
|
|
26
|
+
checkpointSpacing?: number;
|
|
27
|
+
});
|
|
28
|
+
/** Start over when the package inputs are not the ones the kept runs read. */
|
|
29
|
+
use(inputs: ListNormalizationPackageInputs): void;
|
|
30
|
+
/** The blocks of one story normalized, from `counters` as a fresh story starts them. */
|
|
31
|
+
story(key: string, blocks: readonly document_d_exports.BlockContent[], counters: ComputeListMarkerOptions, normalize: (block: document_d_exports.BlockContent) => {
|
|
32
|
+
output: document_d_exports.BlockContent;
|
|
33
|
+
settled: boolean;
|
|
34
|
+
}): document_d_exports.BlockContent[];
|
|
35
|
+
}
|
|
36
|
+
type ListNormalizationOptions = {
|
|
37
|
+
/**
|
|
38
|
+
* Whether to build the operations that undo the normalization. Only an edit
|
|
39
|
+
* session needs them, and they name paragraphs by identity; a save that only
|
|
40
|
+
* writes the normalized document must work on a package whose paragraphs
|
|
41
|
+
* carry none.
|
|
42
|
+
*/
|
|
43
|
+
inverse?: "record" | "omit";
|
|
44
|
+
/**
|
|
45
|
+
* Blocks an earlier normalization of the same session left as they were,
|
|
46
|
+
* reused where the counters before them are the same.
|
|
47
|
+
*/
|
|
48
|
+
cache?: ListNormalizationCache;
|
|
49
|
+
};
|
|
50
|
+
export declare const normalizeListModelRendering: (document: document_d_exports.Document, { inverse: inverseMode, cache }?: ListNormalizationOptions) => CanonicalListNormalization;
|
|
8
51
|
export {};
|
|
@@ -4,19 +4,227 @@ import { listIndentationProvenancePatch } from "../prosemirror/styles/resolvedSt
|
|
|
4
4
|
import { createStyleResolver } from "../prosemirror/styles/styleResolver.js";
|
|
5
5
|
import { canonicalJson } from "../utils/canonicalJson.js";
|
|
6
6
|
import { foldListNumberFields, planParagraphListNumberFold, unfoldedListNumberContent } from "./foldedListNumberFields.js";
|
|
7
|
-
import { computeListMarker } from "./listMarkerComputation.js";
|
|
7
|
+
import { computeListMarker, restoreListCounters, sameListCounters, snapshotListCounters } from "./listMarkerComputation.js";
|
|
8
8
|
import { listRenderingDefinitionsMatch } from "./listRendering.js";
|
|
9
9
|
import { computeListRendering, getCachedNumberingMap } from "./numberingParser.js";
|
|
10
|
-
import { assignParagraphIndentationProjection, cloneParagraphWithPropertySource, paragraphFormattingWithAuthoredIndentation, sameParagraphIndentationProjection } from "./paragraphPropertySource.js";
|
|
10
|
+
import { assignParagraphIndentationProjection, cloneParagraphWithPropertySource, paragraphFormattingWithAuthoredIndentation, paragraphPropertySourceStamp, paragraphPropertySourceStampMatches, sameParagraphIndentationProjection } from "./paragraphPropertySource.js";
|
|
11
11
|
import { panic } from "better-result";
|
|
12
12
|
import { finalizeParagraphFormatting } from "@stll/docx-core/model";
|
|
13
|
-
import { DOCUMENT_OP_TYPES, EMPTY_PROPERTY_SETS, OP_STORIES, registerParagraphPropertySnapshot, withBodyContent } from "@stll/docx-core/ops";
|
|
13
|
+
import { DOCUMENT_OP_TYPES, EMPTY_PROPERTY_SETS, OP_STORIES, paragraphPropertySnapshotToken, registerParagraphPropertySnapshot, withBodyContent } from "@stll/docx-core/ops";
|
|
14
14
|
// src/docx/listModelNormalization.ts
|
|
15
15
|
/** Canonical edits retain authored fields; list rendering follows the current numbering. */
|
|
16
|
-
const
|
|
16
|
+
const CHECKPOINT_SPACING = 32;
|
|
17
|
+
const recordOf = (input, settled) => input.type === "paragraph" ? {
|
|
18
|
+
input,
|
|
19
|
+
settled,
|
|
20
|
+
sourceStamp: paragraphPropertySourceStamp(input),
|
|
21
|
+
snapshotToken: paragraphPropertySnapshotToken(input)
|
|
22
|
+
} : {
|
|
23
|
+
input,
|
|
24
|
+
settled,
|
|
25
|
+
sourceStamp: void 0,
|
|
26
|
+
snapshotToken: void 0
|
|
27
|
+
};
|
|
28
|
+
/** Whether normalizing `block` again would leave it, its facts and its registration as they are. */
|
|
29
|
+
const stillSettled = (block, record) => record.settled && block === record.input && (block.type !== "paragraph" || record.sourceStamp !== void 0 && paragraphPropertySourceStampMatches(block, record.sourceStamp) && paragraphPropertySnapshotToken(block) === record.snapshotToken);
|
|
30
|
+
const storyKey = (story) => {
|
|
31
|
+
if (story === OP_STORIES.MAIN) return story;
|
|
32
|
+
return "rId" in story ? `${story.kind}:${story.rId}` : `${story.kind}:${String(story.id)}`;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Normalized blocks kept across the normalizations of one session.
|
|
36
|
+
*
|
|
37
|
+
* Normalizing a block reads the block, the package's styles and numbering,
|
|
38
|
+
* and the list counters the blocks before it advanced. A block an edit left
|
|
39
|
+
* the same object, with the same kept facts and snapshot registration, that
|
|
40
|
+
* normalized to itself before, normalizes to itself again from the same
|
|
41
|
+
* counters. So a story is normalized again from the last checkpoint before
|
|
42
|
+
* its first changed block, and only until the counters after its last
|
|
43
|
+
* changed block match those the earlier run had at that place.
|
|
44
|
+
*/
|
|
45
|
+
var ListNormalizationCache = class {
|
|
46
|
+
inputs;
|
|
47
|
+
runs = /* @__PURE__ */ new Map();
|
|
48
|
+
spacing;
|
|
49
|
+
constructor({ checkpointSpacing = CHECKPOINT_SPACING } = {}) {
|
|
50
|
+
this.spacing = checkpointSpacing;
|
|
51
|
+
}
|
|
52
|
+
/** Start over when the package inputs are not the ones the kept runs read. */
|
|
53
|
+
use(inputs) {
|
|
54
|
+
if (this.inputs !== void 0 && this.inputs.styles === inputs.styles && this.inputs.numbering === inputs.numbering) return;
|
|
55
|
+
this.inputs = inputs;
|
|
56
|
+
this.runs = /* @__PURE__ */ new Map();
|
|
57
|
+
}
|
|
58
|
+
/** The blocks of one story normalized, from `counters` as a fresh story starts them. */
|
|
59
|
+
story(key, blocks, counters, normalize) {
|
|
60
|
+
const old = this.runs.get(key);
|
|
61
|
+
const oldRecords = old?.records ?? [];
|
|
62
|
+
const oldCheckpoints = old?.checkpoints ?? /* @__PURE__ */ new Map();
|
|
63
|
+
const length = blocks.length;
|
|
64
|
+
const shift = length - oldRecords.length;
|
|
65
|
+
const settledAt = (index, oldIndex) => {
|
|
66
|
+
const record = oldRecords[oldIndex];
|
|
67
|
+
const block = blocks[index];
|
|
68
|
+
return record !== void 0 && block !== void 0 && stillSettled(block, record);
|
|
69
|
+
};
|
|
70
|
+
let prefix = 0;
|
|
71
|
+
while (prefix < length && settledAt(prefix, prefix)) prefix += 1;
|
|
72
|
+
let suffix = 0;
|
|
73
|
+
while (suffix < length - prefix && suffix < oldRecords.length - prefix && settledAt(length - 1 - suffix, oldRecords.length - 1 - suffix)) suffix += 1;
|
|
74
|
+
const outputs = [];
|
|
75
|
+
const records = [];
|
|
76
|
+
const checkpoints = /* @__PURE__ */ new Map();
|
|
77
|
+
const keep = (from, to, offset) => {
|
|
78
|
+
for (let index = from; index < to; index += 1) {
|
|
79
|
+
const record = oldRecords[index - offset] ?? panic("A kept list normalization lost a block.");
|
|
80
|
+
outputs.push(record.input);
|
|
81
|
+
records.push(record);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
let start = 0;
|
|
85
|
+
for (const index of oldCheckpoints.keys()) if (index <= prefix && index > start) start = index;
|
|
86
|
+
const resumed = oldCheckpoints.get(start);
|
|
87
|
+
if (start > 0 && resumed !== void 0) {
|
|
88
|
+
restoreListCounters(counters, resumed);
|
|
89
|
+
keep(0, start, 0);
|
|
90
|
+
for (const [index, snapshot] of oldCheckpoints) if (index <= start) checkpoints.set(index, snapshot);
|
|
91
|
+
} else start = 0;
|
|
92
|
+
for (let index = start; index < length; index += 1) {
|
|
93
|
+
const oldIndex = index - shift;
|
|
94
|
+
const earlier = index >= length - suffix ? oldCheckpoints.get(oldIndex) : void 0;
|
|
95
|
+
const here = earlier !== void 0 || index % this.spacing === 0 ? snapshotListCounters(counters) : void 0;
|
|
96
|
+
if (earlier !== void 0 && here !== void 0 && sameListCounters(earlier, here)) {
|
|
97
|
+
keep(index, length, shift);
|
|
98
|
+
for (const [at, snapshot] of oldCheckpoints) if (at >= oldIndex) checkpoints.set(at + shift, snapshot);
|
|
99
|
+
this.runs.set(key, {
|
|
100
|
+
records,
|
|
101
|
+
checkpoints
|
|
102
|
+
});
|
|
103
|
+
return outputs;
|
|
104
|
+
}
|
|
105
|
+
if (here !== void 0 && index % this.spacing === 0) checkpoints.set(index, here);
|
|
106
|
+
const block = blocks[index] ?? panic("A story lost a block.");
|
|
107
|
+
const { output, settled } = normalize(block);
|
|
108
|
+
outputs.push(output);
|
|
109
|
+
records.push(recordOf(block, settled));
|
|
110
|
+
}
|
|
111
|
+
this.runs.set(key, {
|
|
112
|
+
records,
|
|
113
|
+
checkpoints
|
|
114
|
+
});
|
|
115
|
+
return outputs;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* One block of a story with its list rendering normalized, the counters
|
|
120
|
+
* advanced past it. The block is returned itself when nothing changed.
|
|
121
|
+
*/
|
|
122
|
+
const normalizeBlock = (paragraph, { styles, story, recordInverse }, counters) => {
|
|
123
|
+
const { numbering } = counters;
|
|
124
|
+
if (paragraph.type !== "paragraph") return paragraph;
|
|
125
|
+
registerParagraphPropertySnapshot({
|
|
126
|
+
paragraph,
|
|
127
|
+
snapshot: paragraphFormattingWithAuthoredIndentation(paragraph)
|
|
128
|
+
});
|
|
129
|
+
const formatting = paragraph.formatting;
|
|
130
|
+
const next = cloneParagraphWithPropertySource(paragraph, {});
|
|
131
|
+
const styleNumbering = formatting?.styleId ? styles.resolveParagraphStyle(formatting.styleId).paragraphFormatting?.numPr : void 0;
|
|
132
|
+
if (styleNumbering !== void 0 && (formatting?.numPr === void 0 || formatting.numPr.kind === "levelOnly")) next.formatting = {
|
|
133
|
+
...formatting,
|
|
134
|
+
numPrFromStyle: styleNumbering
|
|
135
|
+
};
|
|
136
|
+
if (formatting?.numPrFromStyle !== void 0 && (formatting.styleId !== void 0 && styleNumbering === void 0 || formatting.numPr?.kind === "reference" || formatting.numPr?.kind === "none")) {
|
|
137
|
+
next.formatting = { ...formatting };
|
|
138
|
+
delete next.formatting.numPrFromStyle;
|
|
139
|
+
}
|
|
140
|
+
if (canonicalJson(next.formatting?.numPrFromStyle) !== canonicalJson(formatting?.numPrFromStyle)) recordInverse(() => ({
|
|
141
|
+
type: DOCUMENT_OP_TYPES.SET_PARAGRAPH_PROPS,
|
|
142
|
+
story,
|
|
143
|
+
blockId: paragraph.paraId ?? panic("List normalization requires paragraph identities."),
|
|
144
|
+
patch: { numPrFromStyle: formatting?.numPrFromStyle ?? null },
|
|
145
|
+
whenEmpty: formatting === void 0 ? EMPTY_PROPERTY_SETS.OMIT : EMPTY_PROPERTY_SETS.KEEP
|
|
146
|
+
}));
|
|
147
|
+
const numPr = effectiveParagraphNumberingReference(paragraphNumberingSourcesFromBoundary({
|
|
148
|
+
numPr: next.formatting?.numPr,
|
|
149
|
+
numPrFromStyle: next.formatting?.numPrFromStyle
|
|
150
|
+
}));
|
|
151
|
+
if (paragraph.listRendering === void 0 && formatting?.numPrFromStyle === void 0 && next.formatting?.numPrFromStyle === void 0 && (numPr?.kind !== "reference" || numbering === null)) {
|
|
152
|
+
computeListMarker(paragraph, counters);
|
|
153
|
+
return paragraph;
|
|
154
|
+
}
|
|
155
|
+
const definition = numPr?.kind === "reference" && numbering !== null ? computeListRendering(numPr, numbering) : null;
|
|
156
|
+
const cached = paragraph.listRendering;
|
|
157
|
+
const rendering = definition !== null && cached !== void 0 && listRenderingDefinitionsMatch(cached, definition) ? { ...cached } : definition;
|
|
158
|
+
const authoredFormatting = paragraphFormattingWithAuthoredIndentation(next);
|
|
159
|
+
const authored = paragraphIndentationFromFormatting(authoredFormatting);
|
|
160
|
+
const inheritance = listIndentationProvenancePatch({
|
|
161
|
+
direct: authored,
|
|
162
|
+
styleFormatting: styles.resolveParagraphStyle(next.formatting?.styleId).paragraphFormatting,
|
|
163
|
+
numberingSource: next.formatting?.numPr?.kind === "reference" || next.formatting?.numPrFromStyle === void 0 ? "paragraph" : "style",
|
|
164
|
+
numPr: numPr?.kind === "reference" ? {
|
|
165
|
+
numId: numPr.numId,
|
|
166
|
+
ilvl: numPr.ilvl ?? 0
|
|
167
|
+
} : void 0,
|
|
168
|
+
numbering
|
|
169
|
+
});
|
|
170
|
+
assignParagraphIndentationProjection({
|
|
171
|
+
paragraph: next,
|
|
172
|
+
authored: authoredFormatting,
|
|
173
|
+
inherited: paragraphIndentationFromFormatting(inheritance._resolvedFormatting) ?? {}
|
|
174
|
+
});
|
|
175
|
+
if (canonicalJson(paragraphIndentationFromFormatting(next.formatting)) !== canonicalJson(paragraphIndentationFromFormatting(formatting))) recordInverse(() => ({
|
|
176
|
+
type: DOCUMENT_OP_TYPES.SET_PARAGRAPH_PROPS,
|
|
177
|
+
story,
|
|
178
|
+
blockId: paragraph.paraId ?? panic("Canonical numbering normalization requires paragraph identities."),
|
|
179
|
+
patch: {
|
|
180
|
+
indentLeft: formatting?.indentLeft ?? null,
|
|
181
|
+
indentRight: formatting?.indentRight ?? null,
|
|
182
|
+
indentFirstLine: formatting?.indentFirstLine ?? null,
|
|
183
|
+
hangingIndent: formatting?.hangingIndent ?? null
|
|
184
|
+
},
|
|
185
|
+
whenEmpty: formatting === void 0 ? EMPTY_PROPERTY_SETS.OMIT : EMPTY_PROPERTY_SETS.KEEP
|
|
186
|
+
}));
|
|
187
|
+
if (rendering === null) delete next.listRendering;
|
|
188
|
+
else {
|
|
189
|
+
const fields = foldListNumberFields(paragraph.content.map(unfoldedListNumberContent), () => void 0).fieldCount;
|
|
190
|
+
if (fields === 0) delete rendering.implicitChildLevelAdvances;
|
|
191
|
+
else rendering.implicitChildLevelAdvances = fields;
|
|
192
|
+
const template = rendering.markerTemplate ?? rendering.marker;
|
|
193
|
+
const fold = planParagraphListNumberFold(paragraph.content, !rendering.isBullet && template !== "" && !template.includes(" "));
|
|
194
|
+
if (fold.suffix === void 0) delete rendering.foldedMarkerSuffix;
|
|
195
|
+
else rendering.foldedMarkerSuffix = fold.suffix;
|
|
196
|
+
const child = numbering?.getLevel(rendering.numId, rendering.level + 1)?.pPr;
|
|
197
|
+
if (fold.suffix !== void 0 && child?.hangingIndent === true && child.indentFirstLine !== void 0 && child.indentFirstLine < 0) rendering.markerSecondSlotOffsetTwips = -child.indentFirstLine;
|
|
198
|
+
else delete rendering.markerSecondSlotOffsetTwips;
|
|
199
|
+
rendering.marker = rendering.foldedMarkerSuffix !== void 0 && !template.includes(" ") ? `${template}\t${rendering.foldedMarkerSuffix}` : template;
|
|
200
|
+
next.listRendering = rendering;
|
|
201
|
+
}
|
|
202
|
+
computeListMarker(next, counters);
|
|
203
|
+
registerParagraphPropertySnapshot({
|
|
204
|
+
paragraph: next,
|
|
205
|
+
snapshot: authoredFormatting
|
|
206
|
+
});
|
|
207
|
+
if (finalizeParagraphFormatting(next.formatting) === void 0) delete next.formatting;
|
|
208
|
+
if (finalizeParagraphFormatting(formatting) === formatting && sameParagraphIndentationProjection({
|
|
209
|
+
left: next,
|
|
210
|
+
right: paragraph
|
|
211
|
+
}) && canonicalJson(next.formatting) === canonicalJson(formatting) && canonicalJson(next.listRendering) === canonicalJson(cached)) return paragraph;
|
|
212
|
+
return next;
|
|
213
|
+
};
|
|
214
|
+
const normalizeListModelRendering = (document, { inverse: inverseMode = "record", cache } = {}) => {
|
|
17
215
|
const inverse = [];
|
|
18
|
-
|
|
19
|
-
const
|
|
216
|
+
let recorded = 0;
|
|
217
|
+
const recordInverse = (operation) => {
|
|
218
|
+
recorded += 1;
|
|
219
|
+
if (inverseMode === "record") inverse.unshift(operation());
|
|
220
|
+
};
|
|
221
|
+
const packageInputs = {
|
|
222
|
+
styles: document.package.styles,
|
|
223
|
+
numbering: document.package.numbering
|
|
224
|
+
};
|
|
225
|
+
cache?.use(packageInputs);
|
|
226
|
+
const styles = createStyleResolver(packageInputs.styles);
|
|
227
|
+
const numbering = packageInputs.numbering === void 0 ? null : getCachedNumberingMap(packageInputs.numbering);
|
|
20
228
|
const normalizeBody = (body, story) => {
|
|
21
229
|
const counters = {
|
|
22
230
|
numbering,
|
|
@@ -29,96 +237,18 @@ const normalizeListModelRendering = (document) => {
|
|
|
29
237
|
numId: null
|
|
30
238
|
}
|
|
31
239
|
};
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
numPrFromStyle: styleNumbering
|
|
240
|
+
const inputs = {
|
|
241
|
+
styles,
|
|
242
|
+
story,
|
|
243
|
+
recordInverse
|
|
244
|
+
};
|
|
245
|
+
const content = cache === void 0 ? body.content.map((block) => normalizeBlock(block, inputs, counters)) : cache.story(storyKey(story), body.content, counters, (block) => {
|
|
246
|
+
const before = recorded;
|
|
247
|
+
const output = normalizeBlock(block, inputs, counters);
|
|
248
|
+
return {
|
|
249
|
+
output,
|
|
250
|
+
settled: output === block && recorded === before
|
|
44
251
|
};
|
|
45
|
-
if (formatting?.numPrFromStyle !== void 0 && (formatting.styleId !== void 0 && styleNumbering === void 0 || formatting.numPr?.kind === "reference" || formatting.numPr?.kind === "none")) {
|
|
46
|
-
next.formatting = { ...formatting };
|
|
47
|
-
delete next.formatting.numPrFromStyle;
|
|
48
|
-
}
|
|
49
|
-
if (canonicalJson(next.formatting?.numPrFromStyle) !== canonicalJson(formatting?.numPrFromStyle)) inverse.unshift({
|
|
50
|
-
type: DOCUMENT_OP_TYPES.SET_PARAGRAPH_PROPS,
|
|
51
|
-
story,
|
|
52
|
-
blockId: paragraph.paraId ?? panic("List normalization requires paragraph identities."),
|
|
53
|
-
patch: { numPrFromStyle: formatting?.numPrFromStyle ?? null },
|
|
54
|
-
whenEmpty: formatting === void 0 ? EMPTY_PROPERTY_SETS.OMIT : EMPTY_PROPERTY_SETS.KEEP
|
|
55
|
-
});
|
|
56
|
-
const numPr = effectiveParagraphNumberingReference(paragraphNumberingSourcesFromBoundary({
|
|
57
|
-
numPr: next.formatting?.numPr,
|
|
58
|
-
numPrFromStyle: next.formatting?.numPrFromStyle
|
|
59
|
-
}));
|
|
60
|
-
if (paragraph.listRendering === void 0 && formatting?.numPrFromStyle === void 0 && next.formatting?.numPrFromStyle === void 0 && (numPr?.kind !== "reference" || numbering === null)) {
|
|
61
|
-
computeListMarker(paragraph, counters);
|
|
62
|
-
return paragraph;
|
|
63
|
-
}
|
|
64
|
-
const definition = numPr?.kind === "reference" && numbering !== null ? computeListRendering(numPr, numbering) : null;
|
|
65
|
-
const cached = paragraph.listRendering;
|
|
66
|
-
const rendering = definition !== null && cached !== void 0 && listRenderingDefinitionsMatch(cached, definition) ? { ...cached } : definition;
|
|
67
|
-
const authoredFormatting = paragraphFormattingWithAuthoredIndentation(next);
|
|
68
|
-
const authored = paragraphIndentationFromFormatting(authoredFormatting);
|
|
69
|
-
const inheritance = listIndentationProvenancePatch({
|
|
70
|
-
direct: authored,
|
|
71
|
-
styleFormatting: styles.resolveParagraphStyle(next.formatting?.styleId).paragraphFormatting,
|
|
72
|
-
numberingSource: next.formatting?.numPr?.kind === "reference" || next.formatting?.numPrFromStyle === void 0 ? "paragraph" : "style",
|
|
73
|
-
numPr: numPr?.kind === "reference" ? {
|
|
74
|
-
numId: numPr.numId,
|
|
75
|
-
ilvl: numPr.ilvl ?? 0
|
|
76
|
-
} : void 0,
|
|
77
|
-
numbering
|
|
78
|
-
});
|
|
79
|
-
assignParagraphIndentationProjection({
|
|
80
|
-
paragraph: next,
|
|
81
|
-
authored: authoredFormatting,
|
|
82
|
-
inherited: paragraphIndentationFromFormatting(inheritance._resolvedFormatting) ?? {}
|
|
83
|
-
});
|
|
84
|
-
if (canonicalJson(paragraphIndentationFromFormatting(next.formatting)) !== canonicalJson(paragraphIndentationFromFormatting(formatting))) inverse.unshift({
|
|
85
|
-
type: DOCUMENT_OP_TYPES.SET_PARAGRAPH_PROPS,
|
|
86
|
-
story,
|
|
87
|
-
blockId: paragraph.paraId ?? panic("Canonical numbering normalization requires paragraph identities."),
|
|
88
|
-
patch: {
|
|
89
|
-
indentLeft: formatting?.indentLeft ?? null,
|
|
90
|
-
indentRight: formatting?.indentRight ?? null,
|
|
91
|
-
indentFirstLine: formatting?.indentFirstLine ?? null,
|
|
92
|
-
hangingIndent: formatting?.hangingIndent ?? null
|
|
93
|
-
},
|
|
94
|
-
whenEmpty: formatting === void 0 ? EMPTY_PROPERTY_SETS.OMIT : EMPTY_PROPERTY_SETS.KEEP
|
|
95
|
-
});
|
|
96
|
-
if (rendering === null) delete next.listRendering;
|
|
97
|
-
else {
|
|
98
|
-
const fields = foldListNumberFields(paragraph.content.map(unfoldedListNumberContent), () => void 0).fieldCount;
|
|
99
|
-
if (fields === 0) delete rendering.implicitChildLevelAdvances;
|
|
100
|
-
else rendering.implicitChildLevelAdvances = fields;
|
|
101
|
-
const template = rendering.markerTemplate ?? rendering.marker;
|
|
102
|
-
const fold = planParagraphListNumberFold(paragraph.content, !rendering.isBullet && template !== "" && !template.includes(" "));
|
|
103
|
-
if (fold.suffix === void 0) delete rendering.foldedMarkerSuffix;
|
|
104
|
-
else rendering.foldedMarkerSuffix = fold.suffix;
|
|
105
|
-
const child = numbering?.getLevel(rendering.numId, rendering.level + 1)?.pPr;
|
|
106
|
-
if (fold.suffix !== void 0 && child?.hangingIndent === true && child.indentFirstLine !== void 0 && child.indentFirstLine < 0) rendering.markerSecondSlotOffsetTwips = -child.indentFirstLine;
|
|
107
|
-
else delete rendering.markerSecondSlotOffsetTwips;
|
|
108
|
-
rendering.marker = rendering.foldedMarkerSuffix !== void 0 && !template.includes(" ") ? `${template}\t${rendering.foldedMarkerSuffix}` : template;
|
|
109
|
-
next.listRendering = rendering;
|
|
110
|
-
}
|
|
111
|
-
computeListMarker(next, counters);
|
|
112
|
-
registerParagraphPropertySnapshot({
|
|
113
|
-
paragraph: next,
|
|
114
|
-
snapshot: authoredFormatting
|
|
115
|
-
});
|
|
116
|
-
if (finalizeParagraphFormatting(next.formatting) === void 0) delete next.formatting;
|
|
117
|
-
if (finalizeParagraphFormatting(formatting) === formatting && sameParagraphIndentationProjection({
|
|
118
|
-
left: next,
|
|
119
|
-
right: paragraph
|
|
120
|
-
}) && canonicalJson(next.formatting) === canonicalJson(formatting) && canonicalJson(next.listRendering) === canonicalJson(cached)) return paragraph;
|
|
121
|
-
return next;
|
|
122
252
|
});
|
|
123
253
|
return content.every((paragraph, index) => paragraph === body.content[index]) ? body : {
|
|
124
254
|
...body,
|
|
@@ -166,4 +296,4 @@ const normalizeListModelRendering = (document) => {
|
|
|
166
296
|
}
|
|
167
297
|
};
|
|
168
298
|
};
|
|
169
|
-
export { normalizeListModelRendering };
|
|
299
|
+
export { ListNormalizationCache, normalizeListModelRendering };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NumberingIdsInUse } from "./numberingIds.js";
|
|
2
1
|
import { document_d_exports } from "../types/document.js";
|
|
2
|
+
import { NumberingIdsInUse } from "./numberingIds.js";
|
|
3
3
|
/** The two kinds of list a command can create. */
|
|
4
4
|
export declare const LIST_KINDS: readonly ["bullet", "numbered"];
|
|
5
5
|
export type ListKind = (typeof LIST_KINDS)[number];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createNumberingIdAllocator, mintNumberingId } from "./numberingIds.js";
|
|
1
|
+
import { createNumberingIdAllocator, mintNumberingId, numberingNumIdsTaken } from "./numberingIds.js";
|
|
2
2
|
import { NUMBER_FORMATS } from "@stll/docx-core/model";
|
|
3
3
|
// src/docx/listNumberingInstances.ts
|
|
4
4
|
/**
|
|
@@ -119,7 +119,7 @@ const EMPTY_DEFINITIONS = {
|
|
|
119
119
|
/** A fresh `w:numId` for `definitions`; zero is reserved for "no numbering". */
|
|
120
120
|
const nextNumId = (definitions, elsewhere) => mintNumberingId({
|
|
121
121
|
kind: "num",
|
|
122
|
-
existingIds: [...(definitions
|
|
122
|
+
existingIds: [...numberingNumIdsTaken(definitions), ...elsewhere.numIds]
|
|
123
123
|
});
|
|
124
124
|
/** A fresh `w:abstractNumId` for `definitions`. */
|
|
125
125
|
const nextAbstractNumId = (definitions, elsewhere) => mintNumberingId({
|
|
@@ -27,4 +27,18 @@ type BlockMoveRangeMarkerHandlers = {
|
|
|
27
27
|
readonly moveToRangeEnd: BlockMoveRangeMarkerHandler;
|
|
28
28
|
};
|
|
29
29
|
export declare const BLOCK_MOVE_RANGE_MARKER_HANDLERS: BlockMoveRangeMarkerHandlers;
|
|
30
|
+
type BlockCommentRangeMarkerHandler = (child: XmlElement, walk: {
|
|
31
|
+
modelled: document_d_exports.BlockContent[];
|
|
32
|
+
}) => void;
|
|
33
|
+
/**
|
|
34
|
+
* A comment's range markers between blocks, as every block container reads
|
|
35
|
+
* them: beside a content control (`w:displacedByCustomXml`) or between two
|
|
36
|
+
* paragraphs. Typed blocks, as move range and bookmark markers are, so every
|
|
37
|
+
* reader that pairs a comment's start with its end sees both halves.
|
|
38
|
+
*/
|
|
39
|
+
type BlockCommentRangeMarkerHandlers = {
|
|
40
|
+
readonly commentRangeStart: BlockCommentRangeMarkerHandler;
|
|
41
|
+
readonly commentRangeEnd: BlockCommentRangeMarkerHandler;
|
|
42
|
+
};
|
|
43
|
+
export declare const BLOCK_COMMENT_RANGE_MARKER_HANDLERS: BlockCommentRangeMarkerHandlers;
|
|
30
44
|
export {};
|
|
@@ -74,4 +74,18 @@ const BLOCK_MOVE_RANGE_MARKER_HANDLERS = {
|
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
|
-
|
|
77
|
+
const BLOCK_COMMENT_RANGE_MARKER_HANDLERS = {
|
|
78
|
+
commentRangeStart: (child, { modelled }) => {
|
|
79
|
+
modelled.push({
|
|
80
|
+
type: "commentRangeStart",
|
|
81
|
+
...parseMarkupRangeMarker(child)
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
commentRangeEnd: (child, { modelled }) => {
|
|
85
|
+
modelled.push({
|
|
86
|
+
type: "commentRangeEnd",
|
|
87
|
+
...parseMarkupRangeMarker(child)
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
export { BLOCK_COMMENT_RANGE_MARKER_HANDLERS, BLOCK_MOVE_RANGE_MARKER_HANDLERS, parseBookmarkRangeMarker, parseCopyOriginMarker, parseMarkupRangeMarker, parseMoveBookmarkMarker };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { decodeText } from "../utils/textEncoding.js";
|
|
2
2
|
import "./archiveInflation.js";
|
|
3
|
+
import { resolvePackageRelationshipTarget } from "./packageParts.js";
|
|
4
|
+
import { RELATIONSHIP_TYPES, parseRelationships } from "./relsParser.js";
|
|
3
5
|
import { elementToXml, getLocalName, parseXmlDocument } from "./xmlParser.js";
|
|
4
6
|
import { Result, TaggedError } from "better-result";
|
|
5
7
|
import { ZipArchive, ZipError } from "@stll/docx-core/zip";
|
|
@@ -81,13 +83,31 @@ const loadPrivacyArchive = async (buffer) => {
|
|
|
81
83
|
cause
|
|
82
84
|
});
|
|
83
85
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
return read.value;
|
|
87
|
+
};
|
|
88
|
+
const PACKAGE_RELATIONSHIPS_PATH = "_rels/.rels";
|
|
89
|
+
/**
|
|
90
|
+
* Every part that holds core properties: the one the package relationship
|
|
91
|
+
* selects, which is the one a package reader follows, and the conventional
|
|
92
|
+
* `docProps/core.xml`. Each is size-checked before it is read.
|
|
93
|
+
*/
|
|
94
|
+
const findCorePropertiesEntries = async (zip) => {
|
|
95
|
+
const paths = /* @__PURE__ */ new Set([CORE_PROPERTIES_PATH_LOWER]);
|
|
96
|
+
const packageRelationships = findZipEntryCaseInsensitive(zip, PACKAGE_RELATIONSHIPS_PATH);
|
|
97
|
+
if (packageRelationships) {
|
|
98
|
+
const relationships = parseRelationships(await readBoundedPart(packageRelationships));
|
|
99
|
+
for (const { type, target, targetMode } of relationships.values()) {
|
|
100
|
+
if (type !== RELATIONSHIP_TYPES.coreProperties || targetMode === "External") continue;
|
|
101
|
+
const path = resolvePackageRelationshipTarget(target, PACKAGE_RELATIONSHIPS_PATH);
|
|
102
|
+
if (path !== void 0) paths.add(path);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const entries = /* @__PURE__ */ new Map();
|
|
106
|
+
for (const path of paths) {
|
|
107
|
+
const entry = findZipEntryCaseInsensitive(zip, path);
|
|
108
|
+
if (entry) entries.set(entry.path, entry);
|
|
109
|
+
}
|
|
110
|
+
return [...entries.values()];
|
|
91
111
|
};
|
|
92
112
|
const rewriteCorePropertiesPrivacy = (xml, transforms) => {
|
|
93
113
|
const root = parseXmlDocument(xml);
|
|
@@ -112,10 +132,14 @@ const rewriteCorePropertiesPrivacy = (xml, transforms) => {
|
|
|
112
132
|
};
|
|
113
133
|
};
|
|
114
134
|
/**
|
|
115
|
-
* Read
|
|
116
|
-
*
|
|
135
|
+
* Read a core-properties or package-relationships part: its declared size is
|
|
136
|
+
* checked first, and inflation stops at that size.
|
|
117
137
|
*/
|
|
118
|
-
const
|
|
138
|
+
const readBoundedPart = async (entry) => {
|
|
139
|
+
if (entry.size > MAX_CORE_PROPERTIES_BYTES) throw new FolioDocumentPrivacyArchiveError({
|
|
140
|
+
message: "Document privacy core properties exceeded the part-size limit",
|
|
141
|
+
reason: "core-properties-too-large"
|
|
142
|
+
});
|
|
119
143
|
const read = await Result.tryPromise({
|
|
120
144
|
try: async () => await entry.bytes(),
|
|
121
145
|
catch: (cause) => cause
|
|
@@ -137,28 +161,25 @@ const readCoreProperties = async (entry) => {
|
|
|
137
161
|
const rewriteDocxMetadataPrivacy = async (buffer, { transforms }) => {
|
|
138
162
|
const appliedTransforms = resolveFolioDocumentPrivacyTransforms(transforms);
|
|
139
163
|
const zip = await loadPrivacyArchive(buffer);
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const rewritten = rewriteCorePropertiesPrivacy(await readCoreProperties(coreProperties), appliedTransforms);
|
|
149
|
-
if (rewritten.removedMetadataProperties.length === 0) return {
|
|
164
|
+
const removedPropertySet = /* @__PURE__ */ new Set();
|
|
165
|
+
for (const coreProperties of await findCorePropertiesEntries(zip)) {
|
|
166
|
+
const rewritten = rewriteCorePropertiesPrivacy(await readBoundedPart(coreProperties), appliedTransforms);
|
|
167
|
+
if (rewritten.removedMetadataProperties.length === 0) continue;
|
|
168
|
+
for (const property of rewritten.removedMetadataProperties) removedPropertySet.add(property);
|
|
169
|
+
zip.set(coreProperties.path, rewritten.xml);
|
|
170
|
+
}
|
|
171
|
+
if (removedPropertySet.size === 0) return {
|
|
150
172
|
buffer,
|
|
151
173
|
privacyReport: {
|
|
152
174
|
appliedTransforms,
|
|
153
175
|
removedMetadataProperties: []
|
|
154
176
|
}
|
|
155
177
|
};
|
|
156
|
-
zip.set(coreProperties.path, rewritten.xml);
|
|
157
178
|
return {
|
|
158
179
|
buffer: (await zip.generate()).buffer,
|
|
159
180
|
privacyReport: {
|
|
160
181
|
appliedTransforms,
|
|
161
|
-
removedMetadataProperties:
|
|
182
|
+
removedMetadataProperties: FOLIO_DOCUMENT_METADATA_PROPERTIES.filter((property) => removedPropertySet.has(property))
|
|
162
183
|
}
|
|
163
184
|
};
|
|
164
185
|
};
|
|
@@ -60,6 +60,8 @@ const normalizeCellBlock = (block, styles) => {
|
|
|
60
60
|
case "preservedBlock":
|
|
61
61
|
case "bookmarkStart":
|
|
62
62
|
case "bookmarkEnd":
|
|
63
|
+
case "commentRangeStart":
|
|
64
|
+
case "commentRangeEnd":
|
|
63
65
|
case "moveFromRangeStart":
|
|
64
66
|
case "moveFromRangeEnd":
|
|
65
67
|
case "moveToRangeStart":
|
|
@@ -70,7 +72,7 @@ const normalizeCellBlock = (block, styles) => {
|
|
|
70
72
|
const normalizeBlocks = (blocks, styles) => blocks.map((block) => {
|
|
71
73
|
if (block.type === "paragraph") return normalizeParagraph(block, styles);
|
|
72
74
|
if (block.type === "table") return normalizeTable(block, styles);
|
|
73
|
-
if (block.type === "preservedBlock" || block.type === "bookmarkStart" || block.type === "bookmarkEnd" || block.type === "moveFromRangeStart" || block.type === "moveFromRangeEnd" || block.type === "moveToRangeStart" || block.type === "moveToRangeEnd") return block;
|
|
75
|
+
if (block.type === "preservedBlock" || block.type === "bookmarkStart" || block.type === "bookmarkEnd" || block.type === "commentRangeStart" || block.type === "commentRangeEnd" || block.type === "moveFromRangeStart" || block.type === "moveFromRangeEnd" || block.type === "moveToRangeStart" || block.type === "moveToRangeEnd") return block;
|
|
74
76
|
return {
|
|
75
77
|
...block,
|
|
76
78
|
content: normalizeBlocks(block.content, styles)
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { document_d_exports } from "../types/document.js";
|
|
2
|
+
/**
|
|
3
|
+
* Every `w:numId` `definitions` holds: the instances it defines and the ids a
|
|
4
|
+
* paragraph or style names without a definition, which a new list never takes.
|
|
5
|
+
*/
|
|
6
|
+
export declare const numberingNumIdsTaken: (definitions: document_d_exports.NumberingDefinitions | null | undefined) => number[];
|
|
1
7
|
type NumberingKind = "num" | "abstract";
|
|
2
8
|
/**
|
|
3
9
|
* Numbering ids (`w:num`, `w:abstractNum`) defined outside the numbering a
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { createNumericIdAllocator } from "./numericIdAllocator.js";
|
|
2
2
|
// src/docx/numberingIds.ts
|
|
3
|
+
/**
|
|
4
|
+
* Every `w:numId` `definitions` holds: the instances it defines and the ids a
|
|
5
|
+
* paragraph or style names without a definition, which a new list never takes.
|
|
6
|
+
*/
|
|
7
|
+
const numberingNumIdsTaken = (definitions) => [...(definitions?.nums ?? []).map(({ numId }) => numId), ...definitions?.danglingNumIds ?? []];
|
|
3
8
|
const NO_NUMBERING_IDS_IN_USE = {
|
|
4
9
|
numIds: /* @__PURE__ */ new Set(),
|
|
5
10
|
abstractNumIds: /* @__PURE__ */ new Set()
|
|
@@ -16,4 +21,4 @@ const createNumberingIdAllocator = (kind, existingIds) => {
|
|
|
16
21
|
const mintNumberingId = ({ kind, existingIds }) => {
|
|
17
22
|
return createNumberingIdAllocator(kind, existingIds).next();
|
|
18
23
|
};
|
|
19
|
-
export { NO_NUMBERING_IDS_IN_USE, createNumberingIdAllocator, mintNumberingId };
|
|
24
|
+
export { NO_NUMBERING_IDS_IN_USE, createNumberingIdAllocator, mintNumberingId, numberingNumIdsTaken };
|
|
@@ -13,6 +13,8 @@ type NormalizeNumberingReferencesInput = {
|
|
|
13
13
|
};
|
|
14
14
|
type NormalizeNumberingReferencesResult = {
|
|
15
15
|
unnumberedDanglingReferences: number;
|
|
16
|
+
/** The ids the repaired references named. */
|
|
17
|
+
danglingNumIds: ReadonlySet<number>;
|
|
16
18
|
};
|
|
17
19
|
export declare const normalizeNumberingReferences: ({ documentBody, numbering, headers, footers, footnotes, endnotes }: NormalizeNumberingReferencesInput) => NormalizeNumberingReferencesResult;
|
|
18
20
|
type NormalizeStyleNumberingReferencesInput = {
|
|
@@ -22,6 +24,8 @@ type NormalizeStyleNumberingReferencesInput = {
|
|
|
22
24
|
type NormalizeStyleNumberingReferencesResult = {
|
|
23
25
|
/** Style ids whose dangling reference became the "no numbering" sentinel. */
|
|
24
26
|
unnumberedStyleIds: string[];
|
|
27
|
+
/** The ids the repaired references named. */
|
|
28
|
+
danglingNumIds: ReadonlySet<number>;
|
|
25
29
|
};
|
|
26
30
|
export declare const normalizeStyleNumberingReferences: ({ styles, numbering }: NormalizeStyleNumberingReferencesInput) => NormalizeStyleNumberingReferencesResult;
|
|
27
31
|
export {};
|