@stll/folio-core 0.66.2 → 0.68.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 +138 -17
- package/dist/ai-edits/batch-claims.js +5 -3
- package/dist/ai-edits/clean-text.js +4 -1
- package/dist/ai-edits/headless.d.ts +36 -21
- package/dist/ai-edits/headless.js +104 -34
- package/dist/ai-edits/index.d.ts +2 -2
- package/dist/ai-edits/note-references.d.ts +6 -0
- package/dist/ai-edits/note-references.js +7 -1
- package/dist/ai-edits/read.d.ts +19 -0
- package/dist/ai-edits/read.js +6 -4
- package/dist/ai-edits/snapshot.d.ts +6 -0
- package/dist/ai-edits/snapshot.js +32 -17
- package/dist/ai-edits/table-cell-mutations.js +3 -2
- package/dist/ai-edits/table-row-column-mutations.js +20 -6
- 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 +29 -12
- package/dist/controller/canonicalComposition.d.ts +1 -1
- package/dist/controller/canonicalComposition.js +77 -19
- package/dist/controller/canonicalInlineProjection.d.ts +35 -10
- package/dist/controller/canonicalInlineProjection.js +192 -28
- package/dist/controller/canonicalInput.d.ts +2 -2
- package/dist/controller/canonicalInput.js +47 -2
- package/dist/controller/canonicalListRendering.d.ts +2 -1
- package/dist/controller/canonicalListRendering.js +1 -1
- package/dist/controller/canonicalLockGuard.d.ts +8 -0
- package/dist/controller/canonicalLockGuard.js +88 -0
- package/dist/controller/canonicalPublicOperations.d.ts +12 -4
- package/dist/controller/canonicalPublicOperations.js +274 -20
- package/dist/controller/canonicalSession.d.ts +87 -7
- package/dist/controller/canonicalSession.js +328 -75
- package/dist/controller/canonicalStoryEditor.d.ts +3 -2
- package/dist/controller/canonicalStoryEditor.js +4 -3
- 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 +1 -0
- package/dist/controller/headerFooterEditorManager.d.ts +2 -2
- package/dist/controller/headerFooterEditorManager.js +5 -5
- package/dist/controller/hiddenEditorApi.d.ts +6 -0
- package/dist/controller/hiddenEditorApi.js +1 -0
- package/dist/controller/hiddenEditorManager.d.ts +10 -3
- package/dist/controller/hiddenEditorManager.js +94 -38
- package/dist/controller/layoutPipeline.d.ts +2 -0
- package/dist/controller/layoutPipeline.js +55 -18
- package/dist/controller/layoutSession.d.ts +1 -0
- package/dist/controller/noteEditorManager.d.ts +2 -2
- package/dist/controller/noteEditorManager.js +5 -5
- package/dist/display-list/build/pageFurniture.js +41 -19
- package/dist/display-list/build/tablePrimitives.d.ts +3 -1
- package/dist/display-list/build/tablePrimitives.js +49 -14
- package/dist/display-list/dom/renderDisplayListToDom.js +4 -4
- package/dist/document-operations.d.ts +8 -0
- 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 +5 -1
- package/dist/docx/canonicalSessionInput.d.ts +5 -1
- package/dist/docx/canonicalSessionInput.js +7 -2
- package/dist/docx/chartPreview.d.ts +4 -1
- package/dist/docx/chartPreview.js +26 -15
- package/dist/docx/commentAnchorIndex.d.ts +21 -5
- package/dist/docx/commentAnchorIndex.js +39 -11
- 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/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 +17 -0
- package/dist/docx/hostCommentThreads.js +49 -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 +227 -96
- package/dist/docx/mainDocumentPart.d.ts +6 -0
- package/dist/docx/mainDocumentPart.js +65 -0
- 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/packageParts.d.ts +1 -1
- package/dist/docx/packageParts.js +10 -4
- package/dist/docx/paragraphParser.js +159 -48
- package/dist/docx/paragraphPropertySource.d.ts +7 -0
- package/dist/docx/paragraphPropertySource.js +22 -1
- 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 +6 -0
- package/dist/docx/previewBudget.d.ts +6 -0
- package/dist/docx/previewBudget.js +7 -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 +110 -25
- package/dist/docx/rezip.d.ts +6 -0
- package/dist/docx/rezip.js +42 -25
- 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 +3 -1
- 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/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/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/shapeAlternateContent.js +19 -0
- package/dist/docx/splitRevisionPieces.d.ts +10 -0
- package/dist/docx/splitRevisionPieces.js +14 -0
- package/dist/docx/storyBlockReplay.js +4 -0
- package/dist/docx/structuralXmlPatch.js +19 -7
- 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/unzip.js +2 -0
- package/dist/docx/verticalMergeProjection.js +1 -1
- 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/pageBreakRunSourceDescendantIndex.d.ts +5 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
- package/dist/internal/revisionResolutionInline.js +1 -2
- package/dist/internal/wholeStoryRevisionResolution.js +57 -12
- package/dist/layout-bridge/convert/altChunkPlaceholder.d.ts +10 -0
- package/dist/layout-bridge/convert/altChunkPlaceholder.js +70 -0
- package/dist/layout-bridge/convert/fixedTableColumnWidths.js +2 -1
- package/dist/layout-bridge/convert/flowConversionShared.d.ts +10 -0
- package/dist/layout-bridge/convert/flowConversionShared.js +11 -1
- package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
- package/dist/layout-bridge/convert/footnoteLayout.js +4 -1
- package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
- package/dist/layout-bridge/convert/headerFooterLayout.js +6 -1
- package/dist/layout-bridge/convert/tableConversion.js +25 -10
- package/dist/layout-bridge/convert/toFlowBlocks.js +4 -0
- package/dist/layout-bridge/engine/blockIndex.d.ts +7 -0
- package/dist/layout-bridge/engine/blockIndex.js +12 -0
- package/dist/layout-bridge/engine/clickToPosition.js +5 -1
- package/dist/layout-bridge/engine/hitTest.js +9 -10
- package/dist/layout-bridge/engine/selectionRects.js +6 -6
- 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.js +10 -5
- package/dist/layout-engine/measure/measureParagraph.js +1 -1
- package/dist/layout-engine/measure/tableCellFloating.d.ts +2 -0
- package/dist/layout-engine/measure/tableCellFloating.js +1 -0
- package/dist/layout-engine/measure/tableVisibleBand.d.ts +16 -0
- package/dist/layout-engine/measure/tableVisibleBand.js +28 -0
- package/dist/layout-engine/tableLayout.js +34 -7
- package/dist/layout-engine/tableRowBreak.d.ts +46 -0
- package/dist/layout-engine/tableRowBreak.js +193 -36
- package/dist/layout-engine/types.d.ts +43 -3
- package/dist/layout-painter/previewSvg.d.ts +8 -0
- package/dist/layout-painter/previewSvg.js +47 -0
- package/dist/layout-painter/renderImage.js +2 -1
- package/dist/layout-painter/renderPage.d.ts +5 -4
- package/dist/layout-painter/renderPage.js +52 -20
- package/dist/layout-painter/renderParagraph.js +3 -2
- package/dist/layout-painter/renderTable.d.ts +5 -2
- package/dist/layout-painter/renderTable.js +39 -22
- 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/pdf/images.d.ts +17 -1
- package/dist/pdf/images.js +22 -4
- package/dist/pdf/writePdf.js +4 -2
- package/dist/prosemirror/anchoredTextBoxes.d.ts +2 -1
- package/dist/prosemirror/attrs/index.js +1 -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 +25 -0
- package/dist/prosemirror/commands/comments.js +122 -18
- package/dist/prosemirror/commands/deleteBesideInlineAnchor.d.ts +9 -0
- package/dist/prosemirror/commands/deleteBesideInlineAnchor.js +36 -0
- package/dist/prosemirror/commands/formatting.d.ts +1 -1
- package/dist/prosemirror/commands/index.d.ts +1 -1
- package/dist/prosemirror/commands/pastePlainText.d.ts +6 -0
- package/dist/prosemirror/commands/pastePlainText.js +13 -3
- package/dist/prosemirror/commands/resolveAllTableChanges.js +30 -2
- 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/commentReferenceIntegrity.d.ts +8 -2
- package/dist/prosemirror/commentReferenceIntegrity.js +22 -8
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
- package/dist/prosemirror/conversion/fromProseDoc.js +115 -35
- package/dist/prosemirror/conversion/index.d.ts +1 -1
- package/dist/prosemirror/conversion/toProseDoc.d.ts +128 -1
- package/dist/prosemirror/conversion/toProseDoc.js +325 -55
- package/dist/prosemirror/extensions/StarterKit.js +2 -0
- package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
- package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +3 -1
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +8 -9
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +46 -11
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -2
- package/dist/prosemirror/extensions/features/BidiShortcutExtension.js +2 -3
- package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/ListExtension.js +22 -1
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
- package/dist/prosemirror/extensions/marks/CommentExtension.js +6 -3
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +5 -0
- package/dist/prosemirror/extensions/marks/TextColorExtension.js +1 -1
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +8 -4
- package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +4 -0
- package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.js +49 -0
- package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +5 -1
- package/dist/prosemirror/extensions/nodes/CommentRangeBoundaryExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +4 -3
- package/dist/prosemirror/extensions/nodes/ImageExtension.js +12 -3
- package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/RenderedPageBreakExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.js +119 -38
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +1 -1
- package/dist/prosemirror/extensions/nodes/inlineAnchorDom.d.ts +11 -0
- package/dist/prosemirror/extensions/nodes/inlineAnchorDom.js +21 -0
- package/dist/prosemirror/index.d.ts +2 -2
- 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/noteReferenceReview.js +2 -2
- package/dist/prosemirror/plugins/documentNumbering.js +4 -1
- package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -8
- package/dist/prosemirror/plugins/suggestionMode.js +195 -30
- 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/rowGridOmissions.d.ts +11 -0
- package/dist/prosemirror/rowGridOmissions.js +21 -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/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 +6 -0
- package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
- package/dist/prosemirror/tableGridMutation.d.ts +19 -2
- package/dist/prosemirror/tableGridMutation.js +118 -15
- package/dist/prosemirror/tablePositionedBookmarks.d.ts +2 -0
- package/dist/prosemirror/tablePositionedBookmarks.js +80 -0
- package/dist/prosemirror/validation.js +2 -1
- package/dist/redline.js +23 -9
- package/dist/server.d.ts +2 -2
- package/dist/style-sets/extract.js +2 -2
- package/dist/types/canonicalCapabilities.d.ts +29 -8
- package/dist/types/canonicalCapabilities.js +13 -9
- package/dist/utils/cssString.d.ts +7 -0
- package/dist/utils/cssString.js +9 -0
- package/dist/utils/fontResolver.js +4 -1
- 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 -2
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { spliceXml } from "./selectiveXmlPatch.js";
|
|
2
|
+
import { WORDPROCESSINGML_NAMESPACE_URIS, getLocalName, getNamespaceUri, resolveAttributeNamespaceUri } from "./xmlParser.js";
|
|
3
|
+
import { scanStreamingXmlElements } from "@stll/docx-core/xml";
|
|
4
|
+
import { ZipArchive } from "@stll/docx-core/zip";
|
|
5
|
+
// src/docx/ensureUniqueControlIds.ts
|
|
6
|
+
/**
|
|
7
|
+
* Headless `w:sdtPr/w:id` normalization for a `.docx` buffer.
|
|
8
|
+
*
|
|
9
|
+
* A content control names itself by `w:id`, and the package model holds
|
|
10
|
+
* every control by that id. A package can repeat one: a producer that copied
|
|
11
|
+
* a control, or merged two documents, wrote the same id twice. The first
|
|
12
|
+
* control in document order keeps its id; each later control carrying it gets
|
|
13
|
+
* an id the package does not use. Every control is kept, and so is everything
|
|
14
|
+
* else in the part.
|
|
15
|
+
*
|
|
16
|
+
* Alternate content (`mc:Fallback`) restates the controls of its `mc:Choice`
|
|
17
|
+
* under the same ids for older readers, and the parser reads one of the two,
|
|
18
|
+
* so a fallback's ids are reserved but never counted as a repeat.
|
|
19
|
+
*/
|
|
20
|
+
const MC_NAMESPACE_URI = "http://schemas.openxmlformats.org/markup-compatibility/2006";
|
|
21
|
+
const DIGITAL_SIGNATURE_PART_PREFIX = "_xmlsignatures/";
|
|
22
|
+
/** The story parts: the body, headers, footers, notes and comments. */
|
|
23
|
+
const STORY_PART_PATTERN = /^word\/[^/]+\.xml$/iu;
|
|
24
|
+
const isWordprocessing = (element, localName) => getLocalName(element.name ?? "") === localName && WORDPROCESSINGML_NAMESPACE_URIS.has(getNamespaceUri(element) ?? "");
|
|
25
|
+
/** Every control id a part carries, in document order. */
|
|
26
|
+
const controlIdsIn = (xml) => {
|
|
27
|
+
const out = [];
|
|
28
|
+
const fallbacks = /* @__PURE__ */ new WeakSet();
|
|
29
|
+
return scanStreamingXmlElements(xml, ({ element, attributeValueSpans, parent }) => {
|
|
30
|
+
const inFallback = parent !== void 0 && fallbacks.has(parent) || getLocalName(element.name ?? "") === "Fallback" && getNamespaceUri(element) === MC_NAMESPACE_URI;
|
|
31
|
+
if (inFallback) fallbacks.add(element);
|
|
32
|
+
if (parent === void 0 || !isWordprocessing(element, "id") || !isWordprocessing(parent, "sdtPr")) return;
|
|
33
|
+
for (const [name, span] of attributeValueSpans) {
|
|
34
|
+
if (getLocalName(name) !== "val" || !WORDPROCESSINGML_NAMESPACE_URIS.has(resolveAttributeNamespaceUri(element, name) ?? "")) continue;
|
|
35
|
+
const value = Number(element.attributes?.[name]);
|
|
36
|
+
if (Number.isInteger(value)) out.push({
|
|
37
|
+
start: span.start,
|
|
38
|
+
end: span.end,
|
|
39
|
+
value,
|
|
40
|
+
inFallback
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}).status === "scanned" ? out : void 0;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Give each content control after the first carrying an id an id of its own.
|
|
47
|
+
* A signed package, or a part that does not scan, is left as it is.
|
|
48
|
+
*/
|
|
49
|
+
const ensureUniqueControlIds = async (docx) => {
|
|
50
|
+
const zip = await ZipArchive.read(docx);
|
|
51
|
+
const entries = zip.entries();
|
|
52
|
+
if (entries.some(({ path }) => path.toLowerCase().startsWith(DIGITAL_SIGNATURE_PART_PREFIX))) return {
|
|
53
|
+
docx,
|
|
54
|
+
reminted: 0
|
|
55
|
+
};
|
|
56
|
+
const parts = entries.map(({ path }) => path).filter((path) => STORY_PART_PATTERN.test(path)).sort((a, b) => {
|
|
57
|
+
const body = (path) => path.toLowerCase() === "word/document.xml" ? 0 : 1;
|
|
58
|
+
return body(a) - body(b) || a.localeCompare(b);
|
|
59
|
+
});
|
|
60
|
+
const texts = /* @__PURE__ */ new Map();
|
|
61
|
+
const ids = /* @__PURE__ */ new Map();
|
|
62
|
+
const taken = /* @__PURE__ */ new Set();
|
|
63
|
+
for (const path of parts) {
|
|
64
|
+
const xml = await zip.entry(path)?.text();
|
|
65
|
+
if (xml === void 0 || !xml.includes("sdtPr")) continue;
|
|
66
|
+
const found = controlIdsIn(xml);
|
|
67
|
+
if (found === void 0) continue;
|
|
68
|
+
texts.set(path, xml);
|
|
69
|
+
ids.set(path, found);
|
|
70
|
+
for (const { value } of found) taken.add(value);
|
|
71
|
+
}
|
|
72
|
+
let next = 1;
|
|
73
|
+
const fresh = () => {
|
|
74
|
+
while (taken.has(next)) next += 1;
|
|
75
|
+
taken.add(next);
|
|
76
|
+
return next;
|
|
77
|
+
};
|
|
78
|
+
const seen = /* @__PURE__ */ new Set();
|
|
79
|
+
let reminted = 0;
|
|
80
|
+
for (const [path, found] of ids) {
|
|
81
|
+
const edits = [];
|
|
82
|
+
for (const { start, end, value, inFallback } of found) {
|
|
83
|
+
if (inFallback) continue;
|
|
84
|
+
if (!seen.has(value)) {
|
|
85
|
+
seen.add(value);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
edits.push({
|
|
89
|
+
start,
|
|
90
|
+
end,
|
|
91
|
+
newXml: String(fresh())
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (edits.length === 0) continue;
|
|
95
|
+
const patched = spliceXml(texts.get(path), edits);
|
|
96
|
+
if (patched === null) continue;
|
|
97
|
+
const source = zip.entry(path);
|
|
98
|
+
zip.set(path, patched, source ? { modified: source.modified } : {});
|
|
99
|
+
reminted += edits.length;
|
|
100
|
+
}
|
|
101
|
+
if (reminted === 0) return {
|
|
102
|
+
docx,
|
|
103
|
+
reminted
|
|
104
|
+
};
|
|
105
|
+
return {
|
|
106
|
+
docx: await zip.generate({ level: 6 }),
|
|
107
|
+
reminted
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
export { ensureUniqueControlIds };
|
|
@@ -26,6 +26,13 @@ export declare const refreshHeaderFooterVerbatimFingerprint: (hf: document_d_exp
|
|
|
26
26
|
export declare const clearHeaderFooterVerbatimXml: (hf: document_d_exports.HeaderFooter) => void;
|
|
27
27
|
/** Capture parsed resources on the same trusted handle, including an absent main part. */
|
|
28
28
|
export declare const captureDocumentSourceBaseline: (document: document_d_exports.Document, xml: string | undefined) => void;
|
|
29
|
+
/** The numbering instance and abstract definition ids the source package had. */
|
|
30
|
+
export type SourceNumberingIds = {
|
|
31
|
+
readonly nums: ReadonlySet<number>;
|
|
32
|
+
readonly abstractNums: ReadonlySet<number>;
|
|
33
|
+
};
|
|
34
|
+
/** The numbering ids the parsed source had, or `undefined` without a capture. */
|
|
35
|
+
export declare const getDocumentSourceNumberingIds: (document: document_d_exports.Document) => SourceNumberingIds | undefined;
|
|
29
36
|
/** Read the identity-stable, deeply frozen stylesheet without cloning or body comparison. */
|
|
30
37
|
export declare const getDocumentSourceStyles: (document: document_d_exports.Document, liveStyles?: document_d_exports.Document["package"]["styles"]) => {
|
|
31
38
|
readonly type: "missing";
|
|
@@ -160,11 +160,16 @@ const captureDocumentSourceBaseline = (document, xml) => {
|
|
|
160
160
|
const resourceStyles = structuredClone(document.package.styles);
|
|
161
161
|
freezeSourceStyles(resourceStyles);
|
|
162
162
|
const styleIds = new Set(resourceStyles?.styles.map(({ styleId }) => styleId));
|
|
163
|
+
const numberingIds = {
|
|
164
|
+
nums: new Set(document.package.numbering?.nums.map(({ numId }) => numId)),
|
|
165
|
+
abstractNums: new Set(document.package.numbering?.abstractNums.map(({ abstractNumId }) => abstractNumId))
|
|
166
|
+
};
|
|
163
167
|
if (xml === void 0) contentBaselines.set(handle, {
|
|
164
168
|
type: "body",
|
|
165
169
|
kind: "noMainPart",
|
|
166
170
|
resourceStyles,
|
|
167
|
-
styleIds
|
|
171
|
+
styleIds,
|
|
172
|
+
numberingIds
|
|
168
173
|
});
|
|
169
174
|
else contentBaselines.set(handle, {
|
|
170
175
|
type: "body",
|
|
@@ -174,6 +179,7 @@ const captureDocumentSourceBaseline = (document, xml) => {
|
|
|
174
179
|
body: structuredClone(document.package.document),
|
|
175
180
|
resourceStyles,
|
|
176
181
|
styleIds,
|
|
182
|
+
numberingIds,
|
|
177
183
|
resourceRelationships: structuredClone(document.package.relationships),
|
|
178
184
|
resourceMedia: new Map([...document.package.media ?? []].map(([path, media]) => [path, {
|
|
179
185
|
data: media.data,
|
|
@@ -203,6 +209,11 @@ const readDocumentSourceCapture = (document) => {
|
|
|
203
209
|
baseline
|
|
204
210
|
};
|
|
205
211
|
};
|
|
212
|
+
/** The numbering ids the parsed source had, or `undefined` without a capture. */
|
|
213
|
+
const getDocumentSourceNumberingIds = (document) => {
|
|
214
|
+
const source = readDocumentSourceCapture(document);
|
|
215
|
+
return source.type === "captured" ? source.baseline.numberingIds : void 0;
|
|
216
|
+
};
|
|
206
217
|
/** Read the identity-stable, deeply frozen stylesheet without cloning or body comparison. */
|
|
207
218
|
const getDocumentSourceStyles = (document, liveStyles) => {
|
|
208
219
|
const source = readDocumentSourceCapture(document);
|
|
@@ -239,4 +250,4 @@ const getDocumentSourceBaseline = (document) => {
|
|
|
239
250
|
resourceMedia: baseline.resourceMedia
|
|
240
251
|
};
|
|
241
252
|
};
|
|
242
|
-
export { assignHeaderFooterVerbatimXml, canReplayHeaderFooterBlocks, canReplayHeaderFooterVerbatim, captureDocumentSourceBaseline, captureHeaderFooterPackageBaselines, clearHeaderFooterVerbatimXml, copyHeaderFooterBaselineHandles, copyHeaderFooterPackageBaselines, getDocumentSourceBaseline, getDocumentSourceStyles, getHeaderFooterSourceBaseline, getHeaderFooterVerbatimXml, refreshHeaderFooterVerbatimFingerprint };
|
|
253
|
+
export { assignHeaderFooterVerbatimXml, canReplayHeaderFooterBlocks, canReplayHeaderFooterVerbatim, captureDocumentSourceBaseline, captureHeaderFooterPackageBaselines, clearHeaderFooterVerbatimXml, copyHeaderFooterBaselineHandles, copyHeaderFooterPackageBaselines, getDocumentSourceBaseline, getDocumentSourceNumberingIds, getDocumentSourceStyles, getHeaderFooterSourceBaseline, getHeaderFooterVerbatimXml, refreshHeaderFooterVerbatimFingerprint };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { document_d_exports } from "../types/document.js";
|
|
2
|
+
import { Comment } from "../types/content.js";
|
|
3
|
+
export declare function getCommentParentId(comment: Comment): number | null | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* The comments whose reply chain reaches a top-level comment.
|
|
6
|
+
*
|
|
7
|
+
* Every top-level comment is kept, whether or not its anchor survives:
|
|
8
|
+
* documents without reply-thread metadata deliver replies as top-level
|
|
9
|
+
* comments, and dropping unanchored ones would drop those replies. Replies
|
|
10
|
+
* whose parent chain does not reach a kept top-level comment are dropped.
|
|
11
|
+
*/
|
|
12
|
+
export declare function pruneOrphanedComments(comments: readonly Comment[], _referencedIds?: ReadonlySet<number>): Comment[];
|
|
13
|
+
/**
|
|
14
|
+
* `document` with its body's comment threads replaced by the host's. The body
|
|
15
|
+
* and package are copied, so the document passed in is left as it was.
|
|
16
|
+
*/
|
|
17
|
+
export declare function withHostCommentThreads(document: document_d_exports.Document, comments: readonly Comment[]): document_d_exports.Document;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { setDocumentBodyComments } from "./canonicalModel.js";
|
|
2
|
+
// src/docx/hostCommentThreads.ts
|
|
3
|
+
function getCommentParentId(comment) {
|
|
4
|
+
return comment.parentId;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The comments whose reply chain reaches a top-level comment.
|
|
8
|
+
*
|
|
9
|
+
* Every top-level comment is kept, whether or not its anchor survives:
|
|
10
|
+
* documents without reply-thread metadata deliver replies as top-level
|
|
11
|
+
* comments, and dropping unanchored ones would drop those replies. Replies
|
|
12
|
+
* whose parent chain does not reach a kept top-level comment are dropped.
|
|
13
|
+
*/
|
|
14
|
+
function pruneOrphanedComments(comments, _referencedIds) {
|
|
15
|
+
const keptIds = /* @__PURE__ */ new Set();
|
|
16
|
+
for (const comment of comments) {
|
|
17
|
+
const parentId = getCommentParentId(comment);
|
|
18
|
+
if (parentId === null || parentId === void 0) keptIds.add(comment.id);
|
|
19
|
+
}
|
|
20
|
+
let addedThisPass = true;
|
|
21
|
+
while (addedThisPass) {
|
|
22
|
+
addedThisPass = false;
|
|
23
|
+
for (const comment of comments) {
|
|
24
|
+
if (keptIds.has(comment.id)) continue;
|
|
25
|
+
const parentId = getCommentParentId(comment);
|
|
26
|
+
if (parentId !== null && parentId !== void 0 && keptIds.has(parentId)) {
|
|
27
|
+
keptIds.add(comment.id);
|
|
28
|
+
addedThisPass = true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return comments.filter((comment) => keptIds.has(comment.id));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* `document` with its body's comment threads replaced by the host's. The body
|
|
36
|
+
* and package are copied, so the document passed in is left as it was.
|
|
37
|
+
*/
|
|
38
|
+
function withHostCommentThreads(document, comments) {
|
|
39
|
+
const body = { ...document.package.document };
|
|
40
|
+
setDocumentBodyComments(body, pruneOrphanedComments(comments));
|
|
41
|
+
return {
|
|
42
|
+
...document,
|
|
43
|
+
package: {
|
|
44
|
+
...document.package,
|
|
45
|
+
document: body
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export { getCommentParentId, pruneOrphanedComments, withHostCommentThreads };
|
|
@@ -8,6 +8,7 @@ import { standalonePreviewLedger } from "./previewBudget.js";
|
|
|
8
8
|
import { RELATIONSHIP_TYPES, resolveRelationshipIdOfType } from "./relsParser.js";
|
|
9
9
|
import { parseRun } from "./runParser.js";
|
|
10
10
|
import { runHoldsPayload } from "./runPayload.js";
|
|
11
|
+
import { tagSplitPiece } from "./splitRevisionPieces.js";
|
|
11
12
|
import { WORDPROCESSINGML_NAMESPACE_URIS, findChildren, getAttribute, getAttributeByNamespaceUri, mergeXmlnsDeclarations, parseNumericAttribute, parseOnOffAttribute } from "./xmlParser.js";
|
|
12
13
|
import { isValidOoxmlNumericId } from "@stll/docx-core";
|
|
13
14
|
// src/docx/hyperlinkParser.ts
|
|
@@ -278,7 +279,9 @@ const parseLinkedInlineWrapper = (element, node, context) => {
|
|
|
278
279
|
}
|
|
279
280
|
}
|
|
280
281
|
});
|
|
281
|
-
|
|
282
|
+
const wrapper = inlineWrapperOf(element, node, withPreservedChildren(content, preserved, preservedInlineCapture));
|
|
283
|
+
tagSplitPiece(node, wrapper);
|
|
284
|
+
return wrapper;
|
|
282
285
|
};
|
|
283
286
|
/**
|
|
284
287
|
* Get the display text of a hyperlink
|
|
@@ -353,7 +356,11 @@ function getHyperlinkRuns(hyperlink) {
|
|
|
353
356
|
runs.push(item);
|
|
354
357
|
continue;
|
|
355
358
|
}
|
|
356
|
-
if (item.type === "inlineWrapper")
|
|
359
|
+
if (item.type === "inlineWrapper") {
|
|
360
|
+
collect(item.content);
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
if (item.type === "complexField") runs.push(...item.fieldResult);
|
|
357
364
|
}
|
|
358
365
|
};
|
|
359
366
|
collect(hyperlink.children);
|
|
@@ -110,7 +110,7 @@ export declare const HYPERLINK_CONTENT: {
|
|
|
110
110
|
readonly inlineWrapper: true;
|
|
111
111
|
readonly preservedInline: true;
|
|
112
112
|
readonly run: true;
|
|
113
|
-
readonly complexField:
|
|
113
|
+
readonly complexField: true;
|
|
114
114
|
readonly deletion: false;
|
|
115
115
|
readonly hyperlink: false;
|
|
116
116
|
readonly inlineSdt: false;
|
|
@@ -155,6 +155,13 @@ export declare const SIMPLE_FIELD_CONTENT: {
|
|
|
155
155
|
readonly moveToRangeStart: false;
|
|
156
156
|
readonly simpleField: false;
|
|
157
157
|
};
|
|
158
|
+
/**
|
|
159
|
+
* Every paragraph content kind is a tracked change child. The reader keeps a
|
|
160
|
+
* tracked change whole on this: its resolution joins describe the one wrapper.
|
|
161
|
+
* A model kind outside `TrackedRunContent` turns this type to `never`, so the
|
|
162
|
+
* build fails until reading such a change is designed.
|
|
163
|
+
*/
|
|
164
|
+
export declare const EVERY_PARAGRAPH_CONTENT_IS_TRACKED_CHILD: (typeof TRACKED_CHANGE_WRAPPER_CONTENT)[document_d_exports.ParagraphContent["type"]] extends true ? true : never;
|
|
158
165
|
/**
|
|
159
166
|
* Whether a revision wrapper keeps this content inside itself.
|
|
160
167
|
*
|
|
@@ -110,7 +110,7 @@ const HYPERLINK_CONTENT = {
|
|
|
110
110
|
inlineWrapper: true,
|
|
111
111
|
preservedInline: true,
|
|
112
112
|
run: true,
|
|
113
|
-
complexField:
|
|
113
|
+
complexField: true,
|
|
114
114
|
deletion: false,
|
|
115
115
|
hyperlink: false,
|
|
116
116
|
inlineSdt: false,
|
|
@@ -156,6 +156,13 @@ const SIMPLE_FIELD_CONTENT = {
|
|
|
156
156
|
simpleField: false
|
|
157
157
|
};
|
|
158
158
|
/**
|
|
159
|
+
* Every paragraph content kind is a tracked change child. The reader keeps a
|
|
160
|
+
* tracked change whole on this: its resolution joins describe the one wrapper.
|
|
161
|
+
* A model kind outside `TrackedRunContent` turns this type to `never`, so the
|
|
162
|
+
* build fails until reading such a change is designed.
|
|
163
|
+
*/
|
|
164
|
+
const EVERY_PARAGRAPH_CONTENT_IS_TRACKED_CHILD = true;
|
|
165
|
+
/**
|
|
159
166
|
* Whether a revision wrapper keeps this content inside itself.
|
|
160
167
|
*
|
|
161
168
|
* Generic in the input so a caller that has already narrowed its content
|
|
@@ -169,4 +176,4 @@ const isInlineSdtContent = (content) => INLINE_SDT_CONTENT[content.type];
|
|
|
169
176
|
const isHyperlinkContent = (content) => HYPERLINK_CONTENT[content.type];
|
|
170
177
|
/** Whether a `w:fldSimple` keeps this content inside itself. */
|
|
171
178
|
const isSimpleFieldContent = (content) => SIMPLE_FIELD_CONTENT[content.type];
|
|
172
|
-
export { HYPERLINK_CONTENT, INLINE_SDT_CONTENT, SIMPLE_FIELD_CONTENT, TRACKED_CHANGE_WRAPPER_CONTENT, isHyperlinkContent, isInlineSdtContent, isSimpleFieldContent, isTrackedChangeWrapperChild };
|
|
179
|
+
export { EVERY_PARAGRAPH_CONTENT_IS_TRACKED_CHILD, HYPERLINK_CONTENT, INLINE_SDT_CONTENT, SIMPLE_FIELD_CONTENT, TRACKED_CHANGE_WRAPPER_CONTENT, isHyperlinkContent, isInlineSdtContent, isSimpleFieldContent, isTrackedChangeWrapperChild };
|
|
@@ -12,4 +12,38 @@ export type ComputeListMarkerOptions = {
|
|
|
12
12
|
restartedNumIds: Set<number>;
|
|
13
13
|
previousList: PreviousListState;
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* What each field of the marker counters depends on: the package alone, or
|
|
17
|
+
* the paragraphs of the story before the current one. Total over the fields:
|
|
18
|
+
* one added does not compile until it is placed, and the story half is what
|
|
19
|
+
* a snapshot copies.
|
|
20
|
+
*/
|
|
21
|
+
declare const LIST_COUNTER_DEPENDENCY: {
|
|
22
|
+
readonly numbering: "package";
|
|
23
|
+
readonly listCounters: "story";
|
|
24
|
+
readonly abstractCounters: "story";
|
|
25
|
+
readonly restartedNumIds: "story";
|
|
26
|
+
readonly previousList: "story";
|
|
27
|
+
};
|
|
28
|
+
type CounterDependency = typeof LIST_COUNTER_DEPENDENCY;
|
|
29
|
+
type StoryCounterField = { [K in keyof CounterDependency]: CounterDependency[K] extends "story" ? K : never; }[keyof CounterDependency];
|
|
30
|
+
/**
|
|
31
|
+
* The story half of the marker counters at one paragraph, copied. Counter
|
|
32
|
+
* arrays are shared between a list instance and its abstract list, and a
|
|
33
|
+
* later paragraph advances the shared array, so the copy names each array by
|
|
34
|
+
* its index in `arrays` and keeps which entries share one.
|
|
35
|
+
*/
|
|
36
|
+
export type ListCounterSnapshot = {
|
|
37
|
+
readonly arrays: readonly (readonly number[])[];
|
|
38
|
+
readonly listCounters: readonly (readonly [number, number])[];
|
|
39
|
+
readonly abstractCounters: readonly (readonly [number, number])[];
|
|
40
|
+
readonly restartedNumIds: readonly number[];
|
|
41
|
+
readonly previousList: Readonly<PreviousListState>;
|
|
42
|
+
} & Record<StoryCounterField, unknown>;
|
|
43
|
+
export declare const snapshotListCounters: (counters: ComputeListMarkerOptions) => ListCounterSnapshot;
|
|
44
|
+
/** Put the story half of `counters` back as the snapshot copied it. */
|
|
45
|
+
export declare const restoreListCounters: (counters: ComputeListMarkerOptions, snapshot: ListCounterSnapshot) => void;
|
|
46
|
+
/** Whether two snapshots hold the same counters, shared the same way, in the same order. */
|
|
47
|
+
export declare const sameListCounters: (left: ListCounterSnapshot, right: ListCounterSnapshot) => boolean;
|
|
48
|
+
export declare const computeListMarker: (paragraph: document_d_exports.Paragraph, { numbering, listCounters, abstractCounters, restartedNumIds, previousList }: ComputeListMarkerOptions) => void;
|
|
49
|
+
export {};
|
|
@@ -1,7 +1,45 @@
|
|
|
1
1
|
import { bulletMarkerFontName, convertBulletToUnicode } from "./bulletMarkers.js";
|
|
2
2
|
import { resolveListTemplate } from "./listTemplate.js";
|
|
3
3
|
import { isNumberingReference } from "./numberingReference.js";
|
|
4
|
+
import { panic } from "better-result";
|
|
4
5
|
// src/docx/listMarkerComputation.ts
|
|
6
|
+
/** Marker counters shared by parsing and canonical model normalization. */
|
|
7
|
+
const snapshotListCounters = (counters) => {
|
|
8
|
+
const indices = /* @__PURE__ */ new Map();
|
|
9
|
+
const arrays = [];
|
|
10
|
+
const indexOf = (values) => {
|
|
11
|
+
const known = indices.get(values);
|
|
12
|
+
if (known !== void 0) return known;
|
|
13
|
+
indices.set(values, arrays.length);
|
|
14
|
+
arrays.push([...values]);
|
|
15
|
+
return arrays.length - 1;
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
listCounters: [...counters.listCounters].map(([numId, values]) => [numId, indexOf(values)]),
|
|
19
|
+
abstractCounters: [...counters.abstractCounters].map(([abstractNumId, values]) => [abstractNumId, indexOf(values)]),
|
|
20
|
+
arrays,
|
|
21
|
+
restartedNumIds: [...counters.restartedNumIds],
|
|
22
|
+
previousList: { ...counters.previousList }
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/** Put the story half of `counters` back as the snapshot copied it. */
|
|
26
|
+
const restoreListCounters = (counters, snapshot) => {
|
|
27
|
+
const arrays = snapshot.arrays.map((values) => [...values]);
|
|
28
|
+
const arrayAt = (index) => arrays[index] ?? panic("A list counter snapshot lost an array.");
|
|
29
|
+
const story = {
|
|
30
|
+
listCounters: new Map(snapshot.listCounters.map(([numId, index]) => [numId, arrayAt(index)])),
|
|
31
|
+
abstractCounters: new Map(snapshot.abstractCounters.map(([abstractNumId, index]) => [abstractNumId, arrayAt(index)])),
|
|
32
|
+
restartedNumIds: new Set(snapshot.restartedNumIds),
|
|
33
|
+
previousList: { ...snapshot.previousList }
|
|
34
|
+
};
|
|
35
|
+
Object.assign(counters, story);
|
|
36
|
+
};
|
|
37
|
+
const samePairs = (left, right) => left.length === right.length && left.every(([key, index], at) => right[at]?.[0] === key && right[at]?.[1] === index);
|
|
38
|
+
/** Whether two snapshots hold the same counters, shared the same way, in the same order. */
|
|
39
|
+
const sameListCounters = (left, right) => left.previousList.abstractNumId === right.previousList.abstractNumId && left.previousList.fromStyle === right.previousList.fromStyle && left.previousList.numId === right.previousList.numId && left.restartedNumIds.length === right.restartedNumIds.length && left.restartedNumIds.every((numId, at) => right.restartedNumIds[at] === numId) && samePairs(left.listCounters, right.listCounters) && samePairs(left.abstractCounters, right.abstractCounters) && left.arrays.length === right.arrays.length && left.arrays.every((values, at) => {
|
|
40
|
+
const other = right.arrays[at];
|
|
41
|
+
return other !== void 0 && values.length === other.length && values.every((value, index) => Object.is(value, other[index]));
|
|
42
|
+
});
|
|
5
43
|
const computeListMarker = (paragraph, { numbering, listCounters, abstractCounters, restartedNumIds, previousList }) => {
|
|
6
44
|
const listRendering = paragraph.listRendering;
|
|
7
45
|
if (!listRendering || !numbering) {
|
|
@@ -68,4 +106,4 @@ const computeListMarker = (paragraph, { numbering, listCounters, abstractCounter
|
|
|
68
106
|
forceDecimal: currentLevelInfo?.isLgl === true || listRendering.isLegal === true
|
|
69
107
|
});
|
|
70
108
|
};
|
|
71
|
-
export { computeListMarker };
|
|
109
|
+
export { computeListMarker, restoreListCounters, sameListCounters, snapshotListCounters };
|
|
@@ -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 {};
|