@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
|
@@ -4,19 +4,228 @@ 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, paragraphPropertySourceState, 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 sameState = (left, right) => left.length === right.length && left.every((value, index) => value === right[index]);
|
|
18
|
+
const recordOf = (input, settled) => input.type === "paragraph" ? {
|
|
19
|
+
input,
|
|
20
|
+
settled,
|
|
21
|
+
sourceState: paragraphPropertySourceState(input),
|
|
22
|
+
snapshotToken: paragraphPropertySnapshotToken(input)
|
|
23
|
+
} : {
|
|
24
|
+
input,
|
|
25
|
+
settled,
|
|
26
|
+
sourceState: void 0,
|
|
27
|
+
snapshotToken: void 0
|
|
28
|
+
};
|
|
29
|
+
/** Whether normalizing `block` again would leave it, its facts and its registration as they are. */
|
|
30
|
+
const stillSettled = (block, record) => record.settled && block === record.input && (block.type !== "paragraph" || record.sourceState !== void 0 && sameState(record.sourceState, paragraphPropertySourceState(block)) && paragraphPropertySnapshotToken(block) === record.snapshotToken);
|
|
31
|
+
const storyKey = (story) => {
|
|
32
|
+
if (story === OP_STORIES.MAIN) return story;
|
|
33
|
+
return "rId" in story ? `${story.kind}:${story.rId}` : `${story.kind}:${String(story.id)}`;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Normalized blocks kept across the normalizations of one session.
|
|
37
|
+
*
|
|
38
|
+
* Normalizing a block reads the block, the package's styles and numbering,
|
|
39
|
+
* and the list counters the blocks before it advanced. A block an edit left
|
|
40
|
+
* the same object, with the same kept facts and snapshot registration, that
|
|
41
|
+
* normalized to itself before, normalizes to itself again from the same
|
|
42
|
+
* counters. So a story is normalized again from the last checkpoint before
|
|
43
|
+
* its first changed block, and only until the counters after its last
|
|
44
|
+
* changed block match those the earlier run had at that place.
|
|
45
|
+
*/
|
|
46
|
+
var ListNormalizationCache = class {
|
|
47
|
+
inputs;
|
|
48
|
+
runs = /* @__PURE__ */ new Map();
|
|
49
|
+
spacing;
|
|
50
|
+
constructor({ checkpointSpacing = CHECKPOINT_SPACING } = {}) {
|
|
51
|
+
this.spacing = checkpointSpacing;
|
|
52
|
+
}
|
|
53
|
+
/** Start over when the package inputs are not the ones the kept runs read. */
|
|
54
|
+
use(inputs) {
|
|
55
|
+
if (this.inputs !== void 0 && this.inputs.styles === inputs.styles && this.inputs.numbering === inputs.numbering) return;
|
|
56
|
+
this.inputs = inputs;
|
|
57
|
+
this.runs = /* @__PURE__ */ new Map();
|
|
58
|
+
}
|
|
59
|
+
/** The blocks of one story normalized, from `counters` as a fresh story starts them. */
|
|
60
|
+
story(key, blocks, counters, normalize) {
|
|
61
|
+
const old = this.runs.get(key);
|
|
62
|
+
const oldRecords = old?.records ?? [];
|
|
63
|
+
const oldCheckpoints = old?.checkpoints ?? /* @__PURE__ */ new Map();
|
|
64
|
+
const length = blocks.length;
|
|
65
|
+
const shift = length - oldRecords.length;
|
|
66
|
+
const settledAt = (index, oldIndex) => {
|
|
67
|
+
const record = oldRecords[oldIndex];
|
|
68
|
+
const block = blocks[index];
|
|
69
|
+
return record !== void 0 && block !== void 0 && stillSettled(block, record);
|
|
70
|
+
};
|
|
71
|
+
let prefix = 0;
|
|
72
|
+
while (prefix < length && settledAt(prefix, prefix)) prefix += 1;
|
|
73
|
+
let suffix = 0;
|
|
74
|
+
while (suffix < length - prefix && suffix < oldRecords.length - prefix && settledAt(length - 1 - suffix, oldRecords.length - 1 - suffix)) suffix += 1;
|
|
75
|
+
const outputs = [];
|
|
76
|
+
const records = [];
|
|
77
|
+
const checkpoints = /* @__PURE__ */ new Map();
|
|
78
|
+
const keep = (from, to, offset) => {
|
|
79
|
+
for (let index = from; index < to; index += 1) {
|
|
80
|
+
const record = oldRecords[index - offset] ?? panic("A kept list normalization lost a block.");
|
|
81
|
+
outputs.push(record.input);
|
|
82
|
+
records.push(record);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
let start = 0;
|
|
86
|
+
for (const index of oldCheckpoints.keys()) if (index <= prefix && index > start) start = index;
|
|
87
|
+
const resumed = oldCheckpoints.get(start);
|
|
88
|
+
if (start > 0 && resumed !== void 0) {
|
|
89
|
+
restoreListCounters(counters, resumed);
|
|
90
|
+
keep(0, start, 0);
|
|
91
|
+
for (const [index, snapshot] of oldCheckpoints) if (index <= start) checkpoints.set(index, snapshot);
|
|
92
|
+
} else start = 0;
|
|
93
|
+
for (let index = start; index < length; index += 1) {
|
|
94
|
+
const oldIndex = index - shift;
|
|
95
|
+
const earlier = index >= length - suffix ? oldCheckpoints.get(oldIndex) : void 0;
|
|
96
|
+
const here = earlier !== void 0 || index % this.spacing === 0 ? snapshotListCounters(counters) : void 0;
|
|
97
|
+
if (earlier !== void 0 && here !== void 0 && sameListCounters(earlier, here)) {
|
|
98
|
+
keep(index, length, shift);
|
|
99
|
+
for (const [at, snapshot] of oldCheckpoints) if (at >= oldIndex) checkpoints.set(at + shift, snapshot);
|
|
100
|
+
this.runs.set(key, {
|
|
101
|
+
records,
|
|
102
|
+
checkpoints
|
|
103
|
+
});
|
|
104
|
+
return outputs;
|
|
105
|
+
}
|
|
106
|
+
if (here !== void 0 && index % this.spacing === 0) checkpoints.set(index, here);
|
|
107
|
+
const block = blocks[index] ?? panic("A story lost a block.");
|
|
108
|
+
const { output, settled } = normalize(block);
|
|
109
|
+
outputs.push(output);
|
|
110
|
+
records.push(recordOf(block, settled));
|
|
111
|
+
}
|
|
112
|
+
this.runs.set(key, {
|
|
113
|
+
records,
|
|
114
|
+
checkpoints
|
|
115
|
+
});
|
|
116
|
+
return outputs;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* One block of a story with its list rendering normalized, the counters
|
|
121
|
+
* advanced past it. The block is returned itself when nothing changed.
|
|
122
|
+
*/
|
|
123
|
+
const normalizeBlock = (paragraph, { styles, story, recordInverse }, counters) => {
|
|
124
|
+
const { numbering } = counters;
|
|
125
|
+
if (paragraph.type !== "paragraph") return paragraph;
|
|
126
|
+
registerParagraphPropertySnapshot({
|
|
127
|
+
paragraph,
|
|
128
|
+
snapshot: paragraphFormattingWithAuthoredIndentation(paragraph)
|
|
129
|
+
});
|
|
130
|
+
const formatting = paragraph.formatting;
|
|
131
|
+
const next = cloneParagraphWithPropertySource(paragraph, {});
|
|
132
|
+
const styleNumbering = formatting?.styleId ? styles.resolveParagraphStyle(formatting.styleId).paragraphFormatting?.numPr : void 0;
|
|
133
|
+
if (styleNumbering !== void 0 && (formatting?.numPr === void 0 || formatting.numPr.kind === "levelOnly")) next.formatting = {
|
|
134
|
+
...formatting,
|
|
135
|
+
numPrFromStyle: styleNumbering
|
|
136
|
+
};
|
|
137
|
+
if (formatting?.numPrFromStyle !== void 0 && (formatting.styleId !== void 0 && styleNumbering === void 0 || formatting.numPr?.kind === "reference" || formatting.numPr?.kind === "none")) {
|
|
138
|
+
next.formatting = { ...formatting };
|
|
139
|
+
delete next.formatting.numPrFromStyle;
|
|
140
|
+
}
|
|
141
|
+
if (canonicalJson(next.formatting?.numPrFromStyle) !== canonicalJson(formatting?.numPrFromStyle)) recordInverse(() => ({
|
|
142
|
+
type: DOCUMENT_OP_TYPES.SET_PARAGRAPH_PROPS,
|
|
143
|
+
story,
|
|
144
|
+
blockId: paragraph.paraId ?? panic("List normalization requires paragraph identities."),
|
|
145
|
+
patch: { numPrFromStyle: formatting?.numPrFromStyle ?? null },
|
|
146
|
+
whenEmpty: formatting === void 0 ? EMPTY_PROPERTY_SETS.OMIT : EMPTY_PROPERTY_SETS.KEEP
|
|
147
|
+
}));
|
|
148
|
+
const numPr = effectiveParagraphNumberingReference(paragraphNumberingSourcesFromBoundary({
|
|
149
|
+
numPr: next.formatting?.numPr,
|
|
150
|
+
numPrFromStyle: next.formatting?.numPrFromStyle
|
|
151
|
+
}));
|
|
152
|
+
if (paragraph.listRendering === void 0 && formatting?.numPrFromStyle === void 0 && next.formatting?.numPrFromStyle === void 0 && (numPr?.kind !== "reference" || numbering === null)) {
|
|
153
|
+
computeListMarker(paragraph, counters);
|
|
154
|
+
return paragraph;
|
|
155
|
+
}
|
|
156
|
+
const definition = numPr?.kind === "reference" && numbering !== null ? computeListRendering(numPr, numbering) : null;
|
|
157
|
+
const cached = paragraph.listRendering;
|
|
158
|
+
const rendering = definition !== null && cached !== void 0 && listRenderingDefinitionsMatch(cached, definition) ? { ...cached } : definition;
|
|
159
|
+
const authoredFormatting = paragraphFormattingWithAuthoredIndentation(next);
|
|
160
|
+
const authored = paragraphIndentationFromFormatting(authoredFormatting);
|
|
161
|
+
const inheritance = listIndentationProvenancePatch({
|
|
162
|
+
direct: authored,
|
|
163
|
+
styleFormatting: styles.resolveParagraphStyle(next.formatting?.styleId).paragraphFormatting,
|
|
164
|
+
numberingSource: next.formatting?.numPr?.kind === "reference" || next.formatting?.numPrFromStyle === void 0 ? "paragraph" : "style",
|
|
165
|
+
numPr: numPr?.kind === "reference" ? {
|
|
166
|
+
numId: numPr.numId,
|
|
167
|
+
ilvl: numPr.ilvl ?? 0
|
|
168
|
+
} : void 0,
|
|
169
|
+
numbering
|
|
170
|
+
});
|
|
171
|
+
assignParagraphIndentationProjection({
|
|
172
|
+
paragraph: next,
|
|
173
|
+
authored: authoredFormatting,
|
|
174
|
+
inherited: paragraphIndentationFromFormatting(inheritance._resolvedFormatting) ?? {}
|
|
175
|
+
});
|
|
176
|
+
if (canonicalJson(paragraphIndentationFromFormatting(next.formatting)) !== canonicalJson(paragraphIndentationFromFormatting(formatting))) recordInverse(() => ({
|
|
177
|
+
type: DOCUMENT_OP_TYPES.SET_PARAGRAPH_PROPS,
|
|
178
|
+
story,
|
|
179
|
+
blockId: paragraph.paraId ?? panic("Canonical numbering normalization requires paragraph identities."),
|
|
180
|
+
patch: {
|
|
181
|
+
indentLeft: formatting?.indentLeft ?? null,
|
|
182
|
+
indentRight: formatting?.indentRight ?? null,
|
|
183
|
+
indentFirstLine: formatting?.indentFirstLine ?? null,
|
|
184
|
+
hangingIndent: formatting?.hangingIndent ?? null
|
|
185
|
+
},
|
|
186
|
+
whenEmpty: formatting === void 0 ? EMPTY_PROPERTY_SETS.OMIT : EMPTY_PROPERTY_SETS.KEEP
|
|
187
|
+
}));
|
|
188
|
+
if (rendering === null) delete next.listRendering;
|
|
189
|
+
else {
|
|
190
|
+
const fields = foldListNumberFields(paragraph.content.map(unfoldedListNumberContent), () => void 0).fieldCount;
|
|
191
|
+
if (fields === 0) delete rendering.implicitChildLevelAdvances;
|
|
192
|
+
else rendering.implicitChildLevelAdvances = fields;
|
|
193
|
+
const template = rendering.markerTemplate ?? rendering.marker;
|
|
194
|
+
const fold = planParagraphListNumberFold(paragraph.content, !rendering.isBullet && template !== "" && !template.includes(" "));
|
|
195
|
+
if (fold.suffix === void 0) delete rendering.foldedMarkerSuffix;
|
|
196
|
+
else rendering.foldedMarkerSuffix = fold.suffix;
|
|
197
|
+
const child = numbering?.getLevel(rendering.numId, rendering.level + 1)?.pPr;
|
|
198
|
+
if (fold.suffix !== void 0 && child?.hangingIndent === true && child.indentFirstLine !== void 0 && child.indentFirstLine < 0) rendering.markerSecondSlotOffsetTwips = -child.indentFirstLine;
|
|
199
|
+
else delete rendering.markerSecondSlotOffsetTwips;
|
|
200
|
+
rendering.marker = rendering.foldedMarkerSuffix !== void 0 && !template.includes(" ") ? `${template}\t${rendering.foldedMarkerSuffix}` : template;
|
|
201
|
+
next.listRendering = rendering;
|
|
202
|
+
}
|
|
203
|
+
computeListMarker(next, counters);
|
|
204
|
+
registerParagraphPropertySnapshot({
|
|
205
|
+
paragraph: next,
|
|
206
|
+
snapshot: authoredFormatting
|
|
207
|
+
});
|
|
208
|
+
if (finalizeParagraphFormatting(next.formatting) === void 0) delete next.formatting;
|
|
209
|
+
if (finalizeParagraphFormatting(formatting) === formatting && sameParagraphIndentationProjection({
|
|
210
|
+
left: next,
|
|
211
|
+
right: paragraph
|
|
212
|
+
}) && canonicalJson(next.formatting) === canonicalJson(formatting) && canonicalJson(next.listRendering) === canonicalJson(cached)) return paragraph;
|
|
213
|
+
return next;
|
|
214
|
+
};
|
|
215
|
+
const normalizeListModelRendering = (document, { inverse: inverseMode = "record", cache } = {}) => {
|
|
17
216
|
const inverse = [];
|
|
18
|
-
|
|
19
|
-
const
|
|
217
|
+
let recorded = 0;
|
|
218
|
+
const recordInverse = (operation) => {
|
|
219
|
+
recorded += 1;
|
|
220
|
+
if (inverseMode === "record") inverse.unshift(operation());
|
|
221
|
+
};
|
|
222
|
+
const packageInputs = {
|
|
223
|
+
styles: document.package.styles,
|
|
224
|
+
numbering: document.package.numbering
|
|
225
|
+
};
|
|
226
|
+
cache?.use(packageInputs);
|
|
227
|
+
const styles = createStyleResolver(packageInputs.styles);
|
|
228
|
+
const numbering = packageInputs.numbering === void 0 ? null : getCachedNumberingMap(packageInputs.numbering);
|
|
20
229
|
const normalizeBody = (body, story) => {
|
|
21
230
|
const counters = {
|
|
22
231
|
numbering,
|
|
@@ -29,96 +238,18 @@ const normalizeListModelRendering = (document) => {
|
|
|
29
238
|
numId: null
|
|
30
239
|
}
|
|
31
240
|
};
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
numPrFromStyle: styleNumbering
|
|
241
|
+
const inputs = {
|
|
242
|
+
styles,
|
|
243
|
+
story,
|
|
244
|
+
recordInverse
|
|
245
|
+
};
|
|
246
|
+
const content = cache === void 0 ? body.content.map((block) => normalizeBlock(block, inputs, counters)) : cache.story(storyKey(story), body.content, counters, (block) => {
|
|
247
|
+
const before = recorded;
|
|
248
|
+
const output = normalizeBlock(block, inputs, counters);
|
|
249
|
+
return {
|
|
250
|
+
output,
|
|
251
|
+
settled: output === block && recorded === before
|
|
44
252
|
};
|
|
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
253
|
});
|
|
123
254
|
return content.every((paragraph, index) => paragraph === body.content[index]) ? body : {
|
|
124
255
|
...body,
|
|
@@ -166,4 +297,4 @@ const normalizeListModelRendering = (document) => {
|
|
|
166
297
|
}
|
|
167
298
|
};
|
|
168
299
|
};
|
|
169
|
-
export { normalizeListModelRendering };
|
|
300
|
+
export { ListNormalizationCache, normalizeListModelRendering };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ZipArchive } from "@stll/docx-core/zip";
|
|
2
|
+
/**
|
|
3
|
+
* Moves the main document to the standard path. Returns whether it moved.
|
|
4
|
+
* What is not a word processing main part, a theme package say, stays put.
|
|
5
|
+
*/
|
|
6
|
+
export declare const moveMainDocumentToStandardPath: (zip: ZipArchive) => Promise<boolean>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { resolvePackageRelationshipTarget } from "./packageParts.js";
|
|
2
|
+
// src/docx/mainDocumentPart.ts
|
|
3
|
+
const STANDARD_PATH = "word/document.xml";
|
|
4
|
+
const STANDARD_RELATIONSHIPS_PATH = "word/_rels/document.xml.rels";
|
|
5
|
+
const PACKAGE_RELATIONSHIPS_PATH = "_rels/.rels";
|
|
6
|
+
const CONTENT_TYPES_PATH = "[content_types].xml";
|
|
7
|
+
const OFFICE_DOCUMENT_TYPE = /\/officeDocument["']/u;
|
|
8
|
+
const WORD_MAIN_CONTENT_TYPE = /wordprocessingml\.[a-z.]*main\+xml/iu;
|
|
9
|
+
const entryNamed = (zip, lowerPath) => zip.paths().find((path) => path.toLowerCase() === lowerPath);
|
|
10
|
+
const relationshipsPathOf = (part) => {
|
|
11
|
+
const slash = part.lastIndexOf("/");
|
|
12
|
+
return `${part.slice(0, slash + 1)}_rels/${part.slice(slash + 1)}.rels`;
|
|
13
|
+
};
|
|
14
|
+
/** A relationship's relative target as an absolute part name. */
|
|
15
|
+
const absolutePartPath = (directory, relative) => {
|
|
16
|
+
const segments = [];
|
|
17
|
+
for (const segment of `${directory}${relative}`.split("/")) if (segment === "..") segments.pop();
|
|
18
|
+
else if (segment !== "" && segment !== ".") segments.push(segment);
|
|
19
|
+
return `/${segments.join("/")}`;
|
|
20
|
+
};
|
|
21
|
+
const escapeForRegExp = (text) => text.replaceAll(/[.*+?^${}()|[\]\\]/gu, String.raw`\$&`);
|
|
22
|
+
const targetOf = (element) => /\bTarget\s*=\s*["']([^"']+)["']/u.exec(element)?.[1] ?? null;
|
|
23
|
+
/**
|
|
24
|
+
* Moves the main document to the standard path. Returns whether it moved.
|
|
25
|
+
* What is not a word processing main part, a theme package say, stays put.
|
|
26
|
+
*/
|
|
27
|
+
const moveMainDocumentToStandardPath = async (zip) => {
|
|
28
|
+
const packagePath = entryNamed(zip, PACKAGE_RELATIONSHIPS_PATH);
|
|
29
|
+
const contentTypesPath = entryNamed(zip, CONTENT_TYPES_PATH);
|
|
30
|
+
if (packagePath === void 0 || contentTypesPath === void 0) return false;
|
|
31
|
+
const packageXml = await zip.entry(packagePath)?.text();
|
|
32
|
+
const contentTypes = await zip.entry(contentTypesPath)?.text();
|
|
33
|
+
if (packageXml === void 0 || contentTypes === void 0) return false;
|
|
34
|
+
const relationship = [...packageXml.matchAll(/<(?:\w+:)?Relationship\b[^>]*>/gu)].map(([element]) => element).find((element) => OFFICE_DOCUMENT_TYPE.test(element));
|
|
35
|
+
const target = relationship && targetOf(relationship);
|
|
36
|
+
if (!relationship || !target) return false;
|
|
37
|
+
const lowerPath = resolvePackageRelationshipTarget(target, PACKAGE_RELATIONSHIPS_PATH);
|
|
38
|
+
if (lowerPath === void 0 || lowerPath === STANDARD_PATH) return false;
|
|
39
|
+
const part = entryNamed(zip, lowerPath);
|
|
40
|
+
if (part === void 0) return false;
|
|
41
|
+
const override = new RegExp(String.raw`<(?:\w+:)?Override\b[^>]*PartName\s*=\s*["']/${escapeForRegExp(part)}["'][^>]*>`, "iu");
|
|
42
|
+
const declared = override.exec(contentTypes)?.[0];
|
|
43
|
+
if (declared === void 0 || !WORD_MAIN_CONTENT_TYPE.test(declared)) return false;
|
|
44
|
+
const bytes = await zip.entry(part)?.bytes();
|
|
45
|
+
if (bytes === void 0) return false;
|
|
46
|
+
const relationshipsPath = entryNamed(zip, relationshipsPathOf(part).toLowerCase());
|
|
47
|
+
const relationships = relationshipsPath === void 0 ? void 0 : await zip.entry(relationshipsPath)?.text();
|
|
48
|
+
const directory = part.slice(0, part.lastIndexOf("/") + 1);
|
|
49
|
+
const anchored = relationships === void 0 || directory === "word/" ? relationships : relationships.replaceAll(/<(?:\w+:)?Relationship\b[^>]*>/gu, (element) => /TargetMode\s*=\s*["']External["']/iu.test(element) ? element : element.replace(/\bTarget\s*=\s*(["'])(?!\/)([^"']+)\1/u, (_match, quote, relative) => {
|
|
50
|
+
return `Target=${quote}${absolutePartPath(directory, relative)}${quote}`;
|
|
51
|
+
}));
|
|
52
|
+
zip.delete(part);
|
|
53
|
+
if (relationshipsPath !== void 0) zip.delete(relationshipsPath);
|
|
54
|
+
const replaced = entryNamed(zip, STANDARD_PATH);
|
|
55
|
+
if (replaced !== void 0) zip.delete(replaced);
|
|
56
|
+
const replacedRelationships = entryNamed(zip, STANDARD_RELATIONSHIPS_PATH);
|
|
57
|
+
if (replacedRelationships !== void 0) zip.delete(replacedRelationships);
|
|
58
|
+
zip.set(STANDARD_PATH, bytes);
|
|
59
|
+
if (anchored !== void 0) zip.set(STANDARD_RELATIONSHIPS_PATH, anchored);
|
|
60
|
+
zip.set(packagePath, packageXml.replace(relationship, relationship.replace(/\bTarget\s*=\s*(["'])[^"']+\1/u, `Target="${STANDARD_PATH}"`)));
|
|
61
|
+
const standardOverride = new RegExp(String.raw`<(?:\w+:)?Override\b[^>]*PartName\s*=\s*["']/${escapeForRegExp(STANDARD_PATH)}["'][^>]*>`, "iu");
|
|
62
|
+
zip.set(contentTypesPath, contentTypes.replace(standardOverride, "").replace(override, declared.replace(/PartName\s*=\s*(["'])[^"']+\1/u, `PartName="/${STANDARD_PATH}"`)));
|
|
63
|
+
return true;
|
|
64
|
+
};
|
|
65
|
+
export { moveMainDocumentToStandardPath };
|
|
@@ -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)
|
|
@@ -41,7 +41,7 @@ export type PackageReferenceRepair = {
|
|
|
41
41
|
* already-reconciled package therefore reports nothing and changes nothing,
|
|
42
42
|
* which is what the repack tests assert about their own output.
|
|
43
43
|
*/
|
|
44
|
-
export declare const reconcilePackageReferences: (zip: ZipArchive, compressionLevel: number) => Promise<PackageReferenceRepair>;
|
|
44
|
+
export declare const reconcilePackageReferences: (zip: ZipArchive, compressionLevel: number, source?: ZipArchive) => Promise<PackageReferenceRepair>;
|
|
45
45
|
/**
|
|
46
46
|
* What {@link checkPackageIntegrity} found wrong with a package. Both fields
|
|
47
47
|
* are empty for a package where every internal relationship resolves and
|
|
@@ -102,7 +102,11 @@ const removeUnsafeEntries = (zip) => {
|
|
|
102
102
|
};
|
|
103
103
|
const presentPartPaths = (zip) => {
|
|
104
104
|
const present = /* @__PURE__ */ new Set();
|
|
105
|
-
for (const path of zip.paths())
|
|
105
|
+
for (const path of zip.paths()) {
|
|
106
|
+
present.add(normalizePartPath(path));
|
|
107
|
+
const decoded = decodePartName(path);
|
|
108
|
+
if (decoded !== void 0) present.add(normalizePartPath(decoded));
|
|
109
|
+
}
|
|
106
110
|
return present;
|
|
107
111
|
};
|
|
108
112
|
const isPresent = (present, partPath) => present.has(normalizePartPath(partPath)) || present.has(normalizePartPath(decodePartName(partPath) ?? ""));
|
|
@@ -143,8 +147,10 @@ const writePart = ({ zip, path, xml, compressionLevel }) => {
|
|
|
143
147
|
* already-reconciled package therefore reports nothing and changes nothing,
|
|
144
148
|
* which is what the repack tests assert about their own output.
|
|
145
149
|
*/
|
|
146
|
-
const reconcilePackageReferences = async (zip, compressionLevel) => {
|
|
150
|
+
const reconcilePackageReferences = async (zip, compressionLevel, source) => {
|
|
147
151
|
const present = presentPartPaths(zip);
|
|
152
|
+
const sourceParts = source ? presentPartPaths(source) : null;
|
|
153
|
+
const danglingInSource = (partPath) => sourceParts !== null && partPath !== "" && !isPresent(sourceParts, partPath);
|
|
148
154
|
const repair = {
|
|
149
155
|
danglingRelationships: [],
|
|
150
156
|
danglingOverrides: [],
|
|
@@ -155,7 +161,7 @@ const reconcilePackageReferences = async (zip, compressionLevel) => {
|
|
|
155
161
|
let dropped = false;
|
|
156
162
|
const pruned = xml.replaceAll(RELATIONSHIP_ELEMENT, (element) => {
|
|
157
163
|
const target = relationshipTarget(element, path);
|
|
158
|
-
if (target === null || present
|
|
164
|
+
if (target === null || isPresent(present, target) || danglingInSource(target)) return element;
|
|
159
165
|
repair.danglingRelationships.push(target || TARGET_ATTRIBUTE.exec(element)?.groups?.["value"] || "");
|
|
160
166
|
dropped = true;
|
|
161
167
|
const id = RELATIONSHIP_ID_ATTRIBUTE.exec(element)?.groups?.["value"];
|
|
@@ -201,7 +207,7 @@ const reconcilePackageReferences = async (zip, compressionLevel) => {
|
|
|
201
207
|
let droppedOverride = false;
|
|
202
208
|
const prunedContentTypes = (await contentTypes.bytes().then((bytes) => decodeText(bytes, { ignoreBOM: true }))).replaceAll(CONTENT_TYPE_ELEMENT, (element) => {
|
|
203
209
|
const partName = PART_NAME_ATTRIBUTE.exec(element)?.groups?.["value"];
|
|
204
|
-
if (partName === void 0 || isPresent(present, partName)) return element;
|
|
210
|
+
if (partName === void 0 || isPresent(present, partName) || danglingInSource(partName)) return element;
|
|
205
211
|
repair.danglingOverrides.push(normalizePartPath(decodePartName(partName) ?? partName));
|
|
206
212
|
droppedOverride = true;
|
|
207
213
|
return "";
|