@stll/folio-core 0.67.0 → 0.69.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai-edits/apply.d.ts +9 -1
- package/dist/ai-edits/apply.js +94 -8
- package/dist/ai-edits/headless.d.ts +36 -21
- package/dist/ai-edits/headless.js +106 -36
- package/dist/ai-edits/index.d.ts +2 -2
- package/dist/ai-edits/newListNumbering.d.ts +14 -1
- package/dist/ai-edits/newListNumbering.js +24 -1
- package/dist/ai-edits/note-references.d.ts +6 -0
- package/dist/ai-edits/note-references.js +7 -1
- package/dist/ai-edits/pending-suggestions.js +2 -2
- package/dist/ai-edits/read.d.ts +19 -0
- package/dist/ai-edits/snapshot.d.ts +6 -0
- package/dist/ai-edits/snapshot.js +8 -3
- package/dist/ai-edits/types.d.ts +9 -1
- package/dist/ai-suggestions/apply.js +13 -4
- package/dist/compare/compare.js +2 -1
- package/dist/compare/inserted-resource-snapshot.d.ts +4 -1
- package/dist/compare/inserted-resource-snapshot.js +7 -3
- package/dist/controller/canonicalClipboard.js +31 -14
- package/dist/controller/canonicalComposition.js +35 -6
- package/dist/controller/canonicalInlineProjection.d.ts +35 -10
- package/dist/controller/canonicalInlineProjection.js +192 -28
- package/dist/controller/canonicalInput.d.ts +2 -1
- package/dist/controller/canonicalInput.js +32 -7
- package/dist/controller/canonicalListRendering.d.ts +2 -1
- package/dist/controller/canonicalListRendering.js +1 -1
- package/dist/controller/canonicalLockGuard.d.ts +23 -0
- package/dist/controller/canonicalLockGuard.js +133 -0
- package/dist/controller/canonicalProjectionBlocks.d.ts +79 -0
- package/dist/controller/canonicalProjectionBlocks.js +75 -0
- package/dist/controller/canonicalPublicOperations.d.ts +12 -4
- package/dist/controller/canonicalPublicOperations.js +676 -46
- package/dist/controller/canonicalSeedContent.d.ts +12 -0
- package/dist/controller/canonicalSeedContent.js +131 -0
- package/dist/controller/canonicalSession.d.ts +133 -21
- package/dist/controller/canonicalSession.js +738 -205
- package/dist/controller/canonicalSourceNormalization.d.ts +21 -0
- package/dist/controller/canonicalSourceNormalization.js +148 -0
- package/dist/controller/canonicalStoryEditor.d.ts +4 -3
- package/dist/controller/canonicalStoryEditor.js +20 -15
- package/dist/controller/canonicalStructure.d.ts +2 -1
- package/dist/controller/canonicalStructure.js +129 -7
- package/dist/controller/contentControlWidgetController.d.ts +5 -0
- package/dist/controller/contentControlWidgetController.js +13 -1
- package/dist/controller/folioEditor.js +4 -0
- package/dist/controller/headerFooterEditorManager.d.ts +7 -2
- package/dist/controller/headerFooterEditorManager.js +11 -6
- package/dist/controller/hiddenEditorApi.d.ts +17 -2
- package/dist/controller/hiddenEditorApi.js +4 -0
- package/dist/controller/hiddenEditorManager.d.ts +11 -3
- package/dist/controller/hiddenEditorManager.js +157 -48
- package/dist/controller/layoutPipeline.js +50 -16
- package/dist/controller/layoutSession.d.ts +3 -0
- package/dist/controller/layoutSession.js +3 -1
- package/dist/controller/noteEditorManager.d.ts +7 -2
- package/dist/controller/noteEditorManager.js +11 -6
- package/dist/display-list/build/pageFurniture.js +41 -19
- package/dist/display-list/build/tablePrimitives.js +23 -4
- package/dist/display-list/dom/renderDisplayListToDom.js +13 -11
- package/dist/document-operations.d.ts +9 -1
- package/dist/document-operations.js +4 -3
- package/dist/docx/blockContentParser.d.ts +7 -3
- package/dist/docx/blockContentParser.js +2 -3
- package/dist/docx/blockPlainText.js +2 -0
- package/dist/docx/bookmarkRangeJoin.d.ts +6 -0
- package/dist/docx/bookmarkRangeJoin.js +43 -0
- package/dist/docx/canonicalSave.js +11 -2
- package/dist/docx/canonicalSessionInput.d.ts +5 -1
- package/dist/docx/canonicalSessionInput.js +7 -2
- package/dist/docx/commentAnchorIndex.d.ts +40 -5
- package/dist/docx/commentAnchorIndex.js +94 -12
- package/dist/docx/commentRangeIntegrity.js +30 -24
- package/dist/docx/commentRangeJoin.d.ts +4 -0
- package/dist/docx/commentRangeJoin.js +26 -12
- package/dist/docx/commentReferenceCompletion.js +5 -4
- package/dist/docx/commentReferenceNormalization.js +40 -18
- package/dist/docx/compatibility.js +9 -2
- package/dist/docx/containerChildren.js +22 -1
- package/dist/docx/contentTypeRegistry.js +1 -1
- package/dist/docx/encryption/compoundFile.js +9 -1
- package/dist/docx/encryption/encryptionInfo.js +16 -2
- package/dist/docx/ensureParaIds.js +46 -7
- package/dist/docx/ensureUniqueControlIds.d.ts +25 -0
- package/dist/docx/ensureUniqueControlIds.js +110 -0
- package/dist/docx/headerFooterVerbatim.d.ts +7 -0
- package/dist/docx/headerFooterVerbatim.js +13 -2
- package/dist/docx/hostCommentThreads.d.ts +27 -0
- package/dist/docx/hostCommentThreads.js +72 -0
- package/dist/docx/hyperlinkParser.js +9 -2
- package/dist/docx/inlineWrapperContent.d.ts +8 -1
- package/dist/docx/inlineWrapperContent.js +9 -2
- package/dist/docx/listMarkerComputation.d.ts +35 -1
- package/dist/docx/listMarkerComputation.js +39 -1
- package/dist/docx/listModelNormalization.d.ts +44 -1
- package/dist/docx/listModelNormalization.js +226 -96
- package/dist/docx/listNumberingInstances.d.ts +1 -1
- package/dist/docx/listNumberingInstances.js +2 -2
- package/dist/docx/markupRangeMarker.d.ts +14 -0
- package/dist/docx/markupRangeMarker.js +15 -1
- package/dist/docx/metadataPrivacy.js +43 -22
- package/dist/docx/normalizeBaseDirection.js +3 -1
- package/dist/docx/numberingIds.d.ts +6 -0
- package/dist/docx/numberingIds.js +6 -1
- package/dist/docx/numberingReferenceNormalization.d.ts +4 -0
- package/dist/docx/numberingReferenceNormalization.js +12 -2
- package/dist/docx/paragraphParser.js +159 -48
- package/dist/docx/paragraphPropertySource.d.ts +29 -0
- package/dist/docx/paragraphPropertySource.js +106 -16
- package/dist/docx/paragraphTextBoxEnrichment.js +2 -1
- package/dist/docx/paragraphTraversal.js +2 -0
- package/dist/docx/parseWarningMessage.js +2 -1
- package/dist/docx/parser.js +8 -0
- package/dist/docx/removeHeaderFooterParts.js +1 -1
- package/dist/docx/renderedPageBreakNormalization.js +1 -1
- package/dist/docx/reviewProvenanceDiagnostics.d.ts +7 -0
- package/dist/docx/reviewProvenanceDiagnostics.js +39 -0
- package/dist/docx/reviewResolutionProvenance.d.ts +29 -3
- package/dist/docx/reviewResolutionProvenance.js +171 -33
- package/dist/docx/rezip.d.ts +6 -0
- package/dist/docx/rezip.js +38 -21
- package/dist/docx/selectiveSave.js +6 -10
- package/dist/docx/selectiveXmlPatch.d.ts +5 -4
- package/dist/docx/selectiveXmlPatch.js +11 -7
- package/dist/docx/serializer/documentSerializer.js +5 -2
- package/dist/docx/serializer/headerFooterSerializer.js +3 -1
- package/dist/docx/serializer/markupRangeAttributes.d.ts +6 -1
- package/dist/docx/serializer/markupRangeAttributes.js +6 -1
- package/dist/docx/serializer/noteSerializer.d.ts +17 -4
- package/dist/docx/serializer/noteSerializer.js +23 -16
- package/dist/docx/serializer/paragraphSerializer.js +56 -12
- package/dist/docx/serializer/partNamespaces.d.ts +1 -1
- package/dist/docx/serializer/partNamespaces.js +1 -1
- package/dist/docx/serializer/runSerializer.d.ts +1 -3
- package/dist/docx/serializer/runSerializer.js +2 -2
- package/dist/docx/serializer/tableSerializer.d.ts +4 -0
- package/dist/docx/serializer/tableSerializer.js +4 -2
- package/dist/docx/server/applyDocxXmlPatchProposal.js +8 -4
- package/dist/docx/server/build.d.ts +1 -1
- package/dist/docx/server/createBilingualDocument.js +27 -5
- package/dist/docx/server/migrateYjsAttrSchema.js +4 -0
- package/dist/docx/sessionListPruning.d.ts +2 -0
- package/dist/docx/sessionListPruning.js +50 -0
- package/dist/docx/splitRevisionPieces.d.ts +10 -0
- package/dist/docx/splitRevisionPieces.js +14 -0
- package/dist/docx/storyBlockReplay.js +19 -2
- package/dist/docx/structuralXmlPatch.js +44 -11
- package/dist/docx/tableParser.d.ts +6 -2
- package/dist/docx/tableParser.js +2 -3
- package/dist/docx/textBoxContentParser.d.ts +11 -0
- package/dist/docx/textBoxContentParser.js +51 -0
- package/dist/docx/textBoxParser.d.ts +0 -5
- package/dist/docx/textBoxParser.js +1 -23
- package/dist/docx/verticalMergeProjection.js +1 -1
- package/dist/docx/xmlParser.d.ts +1 -1
- package/dist/docx/xmlParser.js +2 -3
- package/dist/fonts/fontsourceFaces.d.ts +2 -8
- package/dist/fonts/fontsourceFaces.js +1 -7
- package/dist/i18n/messages/ar.gen.js +3 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +51 -0
- package/dist/i18n/messages/catalogs.gen.js +51 -0
- package/dist/i18n/messages/cs.gen.js +3 -0
- package/dist/i18n/messages/de.gen.js +3 -0
- package/dist/i18n/messages/en.gen.js +3 -0
- package/dist/i18n/messages/es.gen.js +3 -0
- package/dist/i18n/messages/et.gen.js +3 -0
- package/dist/i18n/messages/fr.gen.js +3 -0
- package/dist/i18n/messages/he.gen.js +3 -0
- package/dist/i18n/messages/hi.gen.js +3 -0
- package/dist/i18n/messages/hu.gen.js +3 -0
- package/dist/i18n/messages/lt.gen.js +3 -0
- package/dist/i18n/messages/lv.gen.js +3 -0
- package/dist/i18n/messages/messages.gen.d.ts +3 -0
- package/dist/i18n/messages/pl.gen.js +3 -0
- package/dist/i18n/messages/pt-BR.gen.js +3 -0
- package/dist/i18n/messages/sk.gen.js +3 -0
- package/dist/i18n/messages/tr.gen.js +3 -0
- package/dist/i18n/messages/zh-CN.gen.js +3 -0
- package/dist/internal/acceptedBlockProjection.js +2 -0
- package/dist/internal/pageBreakRunDescendantIndex.d.ts +7 -2
- package/dist/internal/pageBreakRunDescendantIndex.js +12 -3
- package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +5 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
- package/dist/internal/revisionResolutionInline.js +1 -2
- package/dist/internal/subtreeHolds.d.ts +12 -0
- package/dist/internal/subtreeHolds.js +25 -0
- package/dist/internal/wholeStoryRevisionResolution.js +1 -1
- package/dist/layout-bridge/cellSelectionHighlight.js +3 -3
- package/dist/layout-bridge/convert/flowBlockPostprocessing.js +20 -12
- package/dist/layout-bridge/convert/flowConversionShared.d.ts +15 -1
- package/dist/layout-bridge/convert/flowConversionShared.js +9 -1
- package/dist/layout-bridge/convert/paragraphAttrs.d.ts +15 -4
- package/dist/layout-bridge/convert/paragraphAttrs.js +11 -4
- package/dist/layout-bridge/convert/paragraphBlockCache.d.ts +26 -0
- package/dist/layout-bridge/convert/paragraphBlockCache.js +137 -0
- package/dist/layout-bridge/convert/paragraphConversion.d.ts +12 -2
- package/dist/layout-bridge/convert/paragraphConversion.js +37 -5
- package/dist/layout-bridge/convert/paragraphRuns.d.ts +2 -2
- package/dist/layout-bridge/convert/sectionBoundaries.js +16 -0
- package/dist/layout-bridge/convert/tableConversion.js +19 -8
- package/dist/layout-bridge/convert/toFlowBlocks.js +144 -15
- package/dist/layout-bridge/convert/topLevelConversion.d.ts +74 -0
- package/dist/layout-bridge/convert/topLevelConversion.js +109 -0
- package/dist/layout-bridge/dom/clickToPositionDom.js +41 -40
- package/dist/layout-bridge/dom/findBodyPmSpans.js +4 -3
- package/dist/layout-bridge/dom/findHfPmSpans.js +10 -15
- package/dist/layout-bridge/dom/imeCaretAnchor.d.ts +8 -0
- package/dist/layout-bridge/dom/imeCaretAnchor.js +71 -7
- package/dist/layout-bridge/dom/textStreamDom.js +3 -2
- package/dist/layout-bridge/engine/blockIndex.d.ts +7 -0
- package/dist/layout-bridge/engine/blockIndex.js +12 -0
- package/dist/layout-bridge/engine/hitTest.js +9 -10
- package/dist/layout-bridge/engine/selectionRects.js +6 -6
- package/dist/layout-bridge/headerFooterLayout.js +12 -11
- package/dist/layout-bridge/tableInsertHover.js +2 -1
- package/dist/layout-engine/footnoteContinuation.d.ts +36 -0
- package/dist/layout-engine/footnoteContinuation.js +210 -0
- package/dist/layout-engine/index.d.ts +2 -2
- package/dist/layout-engine/index.js +7 -2
- package/dist/layout-engine/measure/cache.d.ts +2 -0
- package/dist/layout-engine/measure/cache.js +16 -6
- package/dist/layout-engine/measure/measureParagraph.js +1 -1
- package/dist/layout-engine/measure/paragraphKeyMemo.d.ts +8 -0
- package/dist/layout-engine/measure/paragraphKeyMemo.js +92 -0
- package/dist/layout-engine/tableLayout.js +29 -5
- package/dist/layout-engine/tableRowBreak.d.ts +36 -0
- package/dist/layout-engine/tableRowBreak.js +43 -1
- package/dist/layout-engine/types.d.ts +42 -1
- package/dist/layout-painter/imageLayout.js +2 -1
- package/dist/layout-painter/pageShellStyles.d.ts +10 -0
- package/dist/layout-painter/pageShellStyles.js +32 -0
- package/dist/layout-painter/reconcileRenderedContent.d.ts +19 -0
- package/dist/layout-painter/reconcileRenderedContent.js +117 -0
- package/dist/layout-painter/renderFragment.js +4 -6
- package/dist/layout-painter/renderImage.js +2 -2
- package/dist/layout-painter/renderPage.d.ts +4 -4
- package/dist/layout-painter/renderPage.js +54 -46
- package/dist/layout-painter/renderParagraph.js +3 -3
- package/dist/layout-painter/renderTable.js +16 -16
- package/dist/layout-painter/renderTextBox.js +2 -2
- package/dist/layout-painter/sdtBoundary.js +3 -2
- package/dist/managers/AutoSaveManager.d.ts +5 -1
- package/dist/managers/FindReplaceManager.js +3 -10
- package/dist/markdown/escape.d.ts +20 -1
- package/dist/markdown/escape.js +43 -1
- package/dist/markdown/renderBlock.js +4 -1
- package/dist/markdown/renderParagraph.js +13 -27
- package/dist/markdown/renderTable.js +6 -2
- package/dist/markdown/trailers.js +1 -0
- package/dist/paged-layout/blockGeometry.js +3 -2
- package/dist/paged-layout/editorScrollRoot.d.ts +9 -0
- package/dist/paged-layout/editorScrollRoot.js +10 -1
- package/dist/paged-layout/rangeProjection.js +5 -4
- package/dist/paged-layout/scrollToPmPosition.js +3 -3
- package/dist/paged-layout/selectionViewportRect.d.ts +6 -0
- package/dist/paged-layout/selectionViewportRect.js +8 -2
- package/dist/pdf/images.d.ts +17 -1
- package/dist/pdf/images.js +22 -4
- package/dist/pdf/writePdf.js +4 -2
- package/dist/prosemirror/attrs/index.js +2 -0
- package/dist/prosemirror/canonicalCommands.d.ts +39 -1
- package/dist/prosemirror/canonicalTableCommands.d.ts +28 -0
- package/dist/prosemirror/canonicalTableCommands.js +362 -0
- package/dist/prosemirror/commands/comments.d.ts +30 -2
- package/dist/prosemirror/commands/comments.js +189 -18
- package/dist/prosemirror/commands/formatting.d.ts +1 -1
- package/dist/prosemirror/commands/index.d.ts +1 -1
- package/dist/prosemirror/commentIdAllocator.js +2 -2
- package/dist/prosemirror/commentRangeBoundaryAttrs.d.ts +6 -0
- package/dist/prosemirror/commentRangeBoundaryAttrs.js +9 -3
- package/dist/prosemirror/commentRecords.d.ts +137 -0
- package/dist/prosemirror/commentRecords.js +400 -0
- package/dist/prosemirror/commentReferenceIntegrity.js +3 -4
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
- package/dist/prosemirror/conversion/fromProseDoc.js +85 -34
- package/dist/prosemirror/conversion/index.d.ts +2 -2
- package/dist/prosemirror/conversion/toProseDoc.d.ts +140 -4
- package/dist/prosemirror/conversion/toProseDoc.js +432 -76
- package/dist/prosemirror/extensions/StarterKit.js +2 -0
- package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +23 -1
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +61 -32
- package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
- package/dist/prosemirror/extensions/marks/CommentExtension.js +8 -3
- package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +4 -0
- package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.js +49 -0
- package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +3 -1
- package/dist/prosemirror/extensions/nodes/ImageExtension.js +12 -3
- package/dist/prosemirror/extensions/nodes/TableExtension.js +32 -31
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +1 -1
- package/dist/prosemirror/index.d.ts +3 -3
- package/dist/prosemirror/listLabels.js +3 -2
- package/dist/prosemirror/listNumbering.d.ts +6 -0
- package/dist/prosemirror/listNumbering.js +12 -9
- package/dist/prosemirror/lockedControls.d.ts +13 -0
- package/dist/prosemirror/lockedControls.js +106 -0
- package/dist/prosemirror/markupViewProjection.js +1 -1
- package/dist/prosemirror/nativeSelection.d.ts +33 -0
- package/dist/prosemirror/nativeSelection.js +74 -0
- package/dist/prosemirror/noteReferenceReview.js +2 -2
- package/dist/prosemirror/numberedRefFields.d.ts +2 -0
- package/dist/prosemirror/numberedRefFields.js +16 -5
- package/dist/prosemirror/paragraphMarkJoin.d.ts +6 -8
- package/dist/prosemirror/paragraphMarkJoin.js +155 -16
- package/dist/prosemirror/plugins/contentControlWidgets.js +2 -2
- package/dist/prosemirror/plugins/documentNumbering.js +37 -15
- package/dist/prosemirror/plugins/suggestionMode.js +33 -10
- package/dist/prosemirror/plugins/templatePreviewValues.js +16 -1
- package/dist/prosemirror/rebaseParagraphRuns.js +1 -1
- package/dist/prosemirror/replacedAnnotations.js +1 -0
- package/dist/prosemirror/runFormattingFromMarks.d.ts +0 -1
- package/dist/prosemirror/runFormattingFromMarks.js +2 -4
- package/dist/prosemirror/runFormattingReconciliation.js +2 -2
- package/dist/prosemirror/runIdentityAcrossRevisions.d.ts +23 -1
- package/dist/prosemirror/runIdentityAcrossRevisions.js +57 -8
- package/dist/prosemirror/runPropertyChangeResolution.js +1 -2
- package/dist/prosemirror/runStyleFormatting.d.ts +14 -4
- package/dist/prosemirror/runStyleFormatting.js +16 -13
- package/dist/prosemirror/schema/marks.d.ts +13 -1
- package/dist/prosemirror/storyListNumbering.js +7 -2
- package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
- package/dist/prosemirror/tableResize.d.ts +10 -9
- package/dist/prosemirror/tableResize.js +60 -49
- package/dist/prosemirror/textInput.d.ts +30 -1
- package/dist/prosemirror/textInput.js +144 -17
- package/dist/prosemirror/utils/visualLineNavigation.js +20 -18
- package/dist/prosemirror/validation.d.ts +19 -0
- package/dist/prosemirror/validation.js +79 -5
- package/dist/redline.js +23 -9
- package/dist/render-dom/HeaderFooterSelectionOverlay.js +5 -4
- package/dist/render-dom/RenderedDomContext.js +7 -6
- package/dist/server.d.ts +2 -2
- package/dist/style-sets/extract.js +2 -2
- package/dist/types/canonicalCapabilities.d.ts +38 -16
- package/dist/types/canonicalCapabilities.js +21 -18
- package/dist/utils/cssString.d.ts +7 -0
- package/dist/utils/cssString.js +9 -0
- package/dist/utils/findMatchView.js +4 -3
- package/dist/utils/fontResolver.js +4 -1
- package/dist/utils/formatToStyle.d.ts +1 -1
- package/dist/utils/mergeDocumentContent.js +2 -2
- package/dist/utils/paintedPositions.d.ts +60 -0
- package/dist/utils/paintedPositions.js +101 -0
- package/dist/utils/replaceText.d.ts +11 -0
- package/dist/utils/replaceText.js +39 -7
- package/dist/version-comparison.d.ts +9 -1
- package/dist/version-comparison.js +11 -5
- package/package.json +2 -3
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { documentFontFactsCacheIdentity } from "../../fonts/documentFontFacts.js";
|
|
2
|
+
import { noteParagraphOrigin } from "../../layout-engine/measure/paragraphKeyMemo.js";
|
|
3
|
+
import { getParagraphFrame, setParagraphFrame } from "../../utils/paragraphFrame.js";
|
|
4
|
+
// src/layout-bridge/convert/paragraphBlockCache.ts
|
|
5
|
+
/** Maps holding the same values under the same keys. */
|
|
6
|
+
const sameEntries = (left, right) => left === right || left !== void 0 && right !== void 0 && left.size === right.size && [...left].every(([key, value]) => right.has(key) && right.get(key) === value);
|
|
7
|
+
const sameMembers = (left, right) => left === right || left !== void 0 && right !== void 0 && left.size === right.size && [...left].every((member) => right.has(member));
|
|
8
|
+
/** Objects holding the same values under the same keys, one level deep. */
|
|
9
|
+
const sameFields = (left, right) => {
|
|
10
|
+
if (left === right) return true;
|
|
11
|
+
if (left === void 0 || right === void 0) return false;
|
|
12
|
+
const keys = Object.keys(left);
|
|
13
|
+
return keys.length === Object.keys(right).length && keys.every((key) => Object.hasOwn(right, key) && Reflect.get(left, key) === Reflect.get(right, key));
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Every conversion option a paragraph's block can depend on, and how two
|
|
17
|
+
* of its values are compared. Counter state is the one order-dependent input
|
|
18
|
+
* and enters only as the list marker; the cache itself is not an input. A
|
|
19
|
+
* layout run builds some of these afresh from the same document, so they
|
|
20
|
+
* compare by content.
|
|
21
|
+
*/
|
|
22
|
+
const CONVERSION_CONSTANTS = {
|
|
23
|
+
altChunkMarkerText: (left, right) => left.altChunkMarkerText === right.altChunkMarkerText,
|
|
24
|
+
altChunkContent: (left, right) => left.altChunkContent === right.altChunkContent,
|
|
25
|
+
showCommentHighlights: (left, right) => left.showCommentHighlights === right.showCommentHighlights,
|
|
26
|
+
embeddedFontFamilyMap: (left, right) => left.embeddedFontFamilyMap === right.embeddedFontFamilyMap,
|
|
27
|
+
documentFontFacts: (left, right) => documentFontFactsCacheIdentity(left.documentFontFacts) === documentFontFactsCacheIdentity(right.documentFontFacts),
|
|
28
|
+
defaultFont: (left, right) => left.defaultFont === right.defaultFont,
|
|
29
|
+
defaultSize: (left, right) => left.defaultSize === right.defaultSize,
|
|
30
|
+
theme: (left, right) => left.theme === right.theme,
|
|
31
|
+
styles: (left, right) => left.styles === right.styles,
|
|
32
|
+
fontAlternates: (left, right) => sameEntries(left.fontAlternates, right.fontAlternates),
|
|
33
|
+
pageContentHeight: (left, right) => left.pageContentHeight === right.pageContentHeight,
|
|
34
|
+
splitPageBreakAndParagraphMark: (left, right) => left.splitPageBreakAndParagraphMark === right.splitPageBreakAndParagraphMark,
|
|
35
|
+
defaultTabStopTwips: (left, right) => left.defaultTabStopTwips === right.defaultTabStopTwips,
|
|
36
|
+
lineBreakRules: (left, right) => sameFields(left.lineBreakRules, right.lineBreakRules),
|
|
37
|
+
justificationCompatibility: (left, right) => sameFields(left.justificationCompatibility, right.justificationCompatibility),
|
|
38
|
+
tableIndentCompatibility: (left, right) => sameFields(left.tableIndentCompatibility, right.tableIndentCompatibility),
|
|
39
|
+
forceAnchorLayoutInCell: (left, right) => left.forceAnchorLayoutInCell === right.forceAnchorLayoutInCell,
|
|
40
|
+
automaticHyphenation: (left, right) => sameFields(left.automaticHyphenation, right.automaticHyphenation),
|
|
41
|
+
finalSectionDocumentGridLinePitchTwips: (left, right) => left.finalSectionDocumentGridLinePitchTwips === right.finalSectionDocumentGridLinePitchTwips,
|
|
42
|
+
noteReferenceMarkText: (left, right) => left.noteReferenceMarkText === right.noteReferenceMarkText,
|
|
43
|
+
trailingEndnoteIds: (left, right) => sameMembers(left.trailingEndnoteIds, right.trailingEndnoteIds)
|
|
44
|
+
};
|
|
45
|
+
const CONSTANT_KEYS = Object.keys(CONVERSION_CONSTANTS);
|
|
46
|
+
const movedRun = (run, delta) => ({
|
|
47
|
+
...run,
|
|
48
|
+
...run.pmStart === void 0 ? {} : { pmStart: run.pmStart + delta },
|
|
49
|
+
...run.pmEnd === void 0 ? {} : { pmEnd: run.pmEnd + delta }
|
|
50
|
+
});
|
|
51
|
+
/**
|
|
52
|
+
* A copy of `block` moved by `delta`, under `id`. The copy owns its top-level
|
|
53
|
+
* fields, attributes and runs, which conversion stamps after a paragraph is
|
|
54
|
+
* converted; the nested values it shares are never written after conversion.
|
|
55
|
+
*/
|
|
56
|
+
const movedBlock = (block, delta, id) => {
|
|
57
|
+
const moved = {
|
|
58
|
+
...block,
|
|
59
|
+
id,
|
|
60
|
+
runs: block.runs.map((run) => movedRun(run, delta)),
|
|
61
|
+
attrs: { ...block.attrs },
|
|
62
|
+
...block.pmStart === void 0 ? {} : { pmStart: block.pmStart + delta },
|
|
63
|
+
...block.pmEnd === void 0 ? {} : { pmEnd: block.pmEnd + delta }
|
|
64
|
+
};
|
|
65
|
+
const frame = getParagraphFrame(block);
|
|
66
|
+
if (frame !== void 0) setParagraphFrame(moved, frame);
|
|
67
|
+
return moved;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Whether converting `node` reads anything besides itself, the constants and
|
|
71
|
+
* its list marker: a field may show another paragraph's number, and a text box
|
|
72
|
+
* anchor records which block holds it.
|
|
73
|
+
*/
|
|
74
|
+
const readsOtherBlocks = (node) => {
|
|
75
|
+
let reads = false;
|
|
76
|
+
node.descendants((child) => {
|
|
77
|
+
if (reads) return false;
|
|
78
|
+
if (child.type.name === "field" || child.type.name === "structuredField" || child.type.name === "textBoxAnchor") {
|
|
79
|
+
reads = true;
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
});
|
|
84
|
+
return reads;
|
|
85
|
+
};
|
|
86
|
+
var ParagraphBlockCache = class {
|
|
87
|
+
constants;
|
|
88
|
+
paragraphs = /* @__PURE__ */ new WeakMap();
|
|
89
|
+
conversion;
|
|
90
|
+
/** Start over unless every conversion constant converts as the one the kept blocks were converted with. */
|
|
91
|
+
use(options) {
|
|
92
|
+
const kept = this.constants;
|
|
93
|
+
this.constants = options;
|
|
94
|
+
if (kept !== void 0 && kept.numberingTabIgnoresIndent === options.numberingTabIgnoresIndent && CONSTANT_KEYS.every((key) => CONVERSION_CONSTANTS[key](kept, options))) return;
|
|
95
|
+
this.paragraphs = /* @__PURE__ */ new WeakMap();
|
|
96
|
+
this.conversion = void 0;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The last conversion, when it converted a document with the same document
|
|
100
|
+
* attributes under the constants `use` was last given.
|
|
101
|
+
*/
|
|
102
|
+
lastConversion(doc) {
|
|
103
|
+
const conversion = this.conversion;
|
|
104
|
+
return conversion !== void 0 && conversion.doc.sameMarkup(doc) ? conversion : void 0;
|
|
105
|
+
}
|
|
106
|
+
/** Keep what converting each top-level node gave, for the next conversion. */
|
|
107
|
+
recordConversion(conversion) {
|
|
108
|
+
this.conversion = conversion;
|
|
109
|
+
}
|
|
110
|
+
/** The block converting `node` at `pmStart` with `listMarker` gives, under `id`. */
|
|
111
|
+
take(node, pmStart, listMarker, id) {
|
|
112
|
+
const kept = this.paragraphs.get(node);
|
|
113
|
+
if (!kept || kept.listMarker !== listMarker) return void 0;
|
|
114
|
+
const moved = movedBlock(kept.block, pmStart - kept.pmStart, id());
|
|
115
|
+
noteParagraphOrigin(moved, kept.block);
|
|
116
|
+
return moved;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Keep the block converting `node` at `pmStart` gave, unless converting it
|
|
120
|
+
* read other blocks. Call before anything else writes to `block`.
|
|
121
|
+
*/
|
|
122
|
+
keep(node, pmStart, listMarker, block) {
|
|
123
|
+
if (this.paragraphs.get(node) === null) return;
|
|
124
|
+
if (readsOtherBlocks(node)) {
|
|
125
|
+
this.paragraphs.set(node, null);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const kept = movedBlock(block, 0, block.id);
|
|
129
|
+
noteParagraphOrigin(block, kept);
|
|
130
|
+
this.paragraphs.set(node, {
|
|
131
|
+
listMarker,
|
|
132
|
+
pmStart,
|
|
133
|
+
block: kept
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
export { ParagraphBlockCache };
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { ParagraphAttrs } from "../../prosemirror/schema/nodes.js";
|
|
2
2
|
import { ParagraphAttrs as ParagraphAttrs$1, ParagraphBlock } from "../../layout-engine/types.js";
|
|
3
|
-
import { FlowConversionOptions } from "./flowConversionShared.js";
|
|
3
|
+
import { CounterFreeFlowConversionOptions, FlowConversionOptions } from "./flowConversionShared.js";
|
|
4
|
+
import { ParagraphListMarker } from "./paragraphAttrs.js";
|
|
4
5
|
import { PageBreakRunProjection } from "./paragraphRuns.js";
|
|
5
6
|
import { Node } from "prosemirror-model";
|
|
6
7
|
export declare function hasVisibleParagraphPayload(attrs: ParagraphAttrs$1): boolean;
|
|
7
8
|
/** Whether any `w:pBdr` side draws a rule (`none`/`nil` sides draw nothing). */
|
|
8
9
|
export declare function drawsParagraphBorder(borders: ParagraphAttrs["borders"]): boolean;
|
|
9
|
-
|
|
10
|
+
/** Convert a paragraph node, advancing the list counters past it. */
|
|
11
|
+
export declare function convertParagraph(node: Node, startPos: number, options: FlowConversionOptions, pageBreaks?: PageBreakRunProjection[]): ParagraphBlock;
|
|
12
|
+
/** Advance the list counters past a paragraph and return the marker they give it. */
|
|
13
|
+
export declare function paragraphListMarker(node: Node, options: Pick<FlowConversionOptions, "listCounterStreams">): ParagraphListMarker;
|
|
14
|
+
/**
|
|
15
|
+
* Convert a paragraph node given the marker the list counters give it. The
|
|
16
|
+
* options carry no counter state, so the marker is the only input that
|
|
17
|
+
* depends on the paragraphs before it.
|
|
18
|
+
*/
|
|
19
|
+
export declare function convertParagraphWithListMarker(node: Node, startPos: number, options: CounterFreeFlowConversionOptions, listMarker: ParagraphListMarker, pageBreaks?: PageBreakRunProjection[]): ParagraphBlock;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { getFontAlternate } from "../../fonts/fontAlternates.js";
|
|
2
|
-
import { expectParagraphAttrs } from "../../prosemirror/attrs/index.js";
|
|
2
|
+
import { expectParagraphAttrs, expectRunPropertyChangeMarkAttrs } from "../../prosemirror/attrs/index.js";
|
|
3
3
|
import { expectBookmarkBoundaryAttrs } from "../../prosemirror/bookmarkBoundaryAttrs.js";
|
|
4
|
+
import { advanceVisibleListMarker } from "../../prosemirror/listMarker.js";
|
|
4
5
|
import { expectTextBoxAnchorAttrs } from "../../prosemirror/textBoxAnchorAttrs.js";
|
|
5
6
|
import { setParagraphFrame } from "../../utils/paragraphFrame.js";
|
|
6
7
|
import { nextBlockId, twipsToPixels } from "./flowConversionShared.js";
|
|
7
|
-
import {
|
|
8
|
+
import { paragraphAttrsWithListMarker } from "./paragraphAttrs.js";
|
|
8
9
|
import { resolveParagraphMarkFormatting, resolveParagraphMarkOwnFormatting } from "./paragraphMarkFormatting.js";
|
|
9
10
|
import { paragraphToRuns } from "./paragraphRuns.js";
|
|
10
11
|
import { resolveEastAsiaThemeFont, resolveWesternThemeFont } from "./textFormattingConversion.js";
|
|
@@ -46,17 +47,48 @@ function drawsParagraphBorder(borders) {
|
|
|
46
47
|
borders.bar
|
|
47
48
|
].some((border) => border?.style !== void 0 && !statesNoBorder(border.style));
|
|
48
49
|
}
|
|
50
|
+
/** Convert a paragraph node, advancing the list counters past it. */
|
|
49
51
|
function convertParagraph(node, startPos, options, pageBreaks) {
|
|
52
|
+
return convertParagraphWithListMarker(node, startPos, options, paragraphListMarker(node, options), pageBreaks);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Whether a paragraph holds a pending formatting change: a recorded change of
|
|
56
|
+
* its own properties, or a run whose mark records a change of its run
|
|
57
|
+
* properties, as the review list lists them.
|
|
58
|
+
*/
|
|
59
|
+
const holdsFormattingRevision = (node, pmAttrs) => {
|
|
60
|
+
if ((pmAttrs._propertyChanges?.length ?? 0) > 0) return true;
|
|
61
|
+
const runPropertyChange = node.type.schema.marks["runPropertyChange"];
|
|
62
|
+
if (runPropertyChange === void 0) return false;
|
|
63
|
+
let found = false;
|
|
64
|
+
node.descendants((child) => {
|
|
65
|
+
if (found) return false;
|
|
66
|
+
const mark = runPropertyChange.isInSet(child.marks);
|
|
67
|
+
if (mark && expectRunPropertyChangeMarkAttrs(mark).changes.length > 0) found = true;
|
|
68
|
+
return !found;
|
|
69
|
+
});
|
|
70
|
+
return found;
|
|
71
|
+
};
|
|
72
|
+
/** Advance the list counters past a paragraph and return the marker they give it. */
|
|
73
|
+
function paragraphListMarker(node, options) {
|
|
74
|
+
return advanceVisibleListMarker(expectParagraphAttrs(node), options.listCounterStreams).marker;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Convert a paragraph node given the marker the list counters give it. The
|
|
78
|
+
* options carry no counter state, so the marker is the only input that
|
|
79
|
+
* depends on the paragraphs before it.
|
|
80
|
+
*/
|
|
81
|
+
function convertParagraphWithListMarker(node, startPos, options, listMarker, pageBreaks) {
|
|
50
82
|
const pmAttrs = expectParagraphAttrs(node);
|
|
51
83
|
const runs = paragraphToRuns(node, startPos, options, pageBreaks);
|
|
52
|
-
const attrs =
|
|
84
|
+
const attrs = paragraphAttrsWithListMarker(pmAttrs, listMarker, {
|
|
53
85
|
theme: options.theme,
|
|
54
86
|
fontAlternates: options.fontAlternates,
|
|
55
|
-
listCounterStreams: options.listCounterStreams,
|
|
56
87
|
defaultTabStopTwips: options.defaultTabStopTwips,
|
|
57
88
|
paragraphMarkFormatting: () => resolveParagraphMarkFormatting(pmAttrs, options.styleResolver)
|
|
58
89
|
});
|
|
59
90
|
if (options.numberingTabIgnoresIndent && attrs.listMarker !== void 0) attrs.listNumberingTabIgnoresIndent = true;
|
|
91
|
+
if (holdsFormattingRevision(node, pmAttrs)) attrs.formattingRevision = true;
|
|
60
92
|
if (options.defaultFont !== void 0) attrs.defaultFontFamily ??= options.defaultFont;
|
|
61
93
|
const defaultFonts = options.styles?.docDefaults?.rPr?.fontFamily;
|
|
62
94
|
const defaultEastAsiaFont = defaultFonts ? resolveEastAsiaThemeFont(defaultFonts, options.theme) : void 0;
|
|
@@ -122,4 +154,4 @@ function convertParagraph(node, startPos, options, pageBreaks) {
|
|
|
122
154
|
});
|
|
123
155
|
return block;
|
|
124
156
|
}
|
|
125
|
-
export { convertParagraph, drawsParagraphBorder, hasVisibleParagraphPayload };
|
|
157
|
+
export { convertParagraph, convertParagraphWithListMarker, drawsParagraphBorder, hasVisibleParagraphPayload, paragraphListMarker };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Run, RunFormatting } from "../../layout-engine/types.js";
|
|
2
|
-
import {
|
|
2
|
+
import { CounterFreeFlowConversionOptions } from "./flowConversionShared.js";
|
|
3
3
|
import { Node } from "prosemirror-model";
|
|
4
4
|
/**
|
|
5
5
|
* Convert a paragraph node to runs.
|
|
@@ -9,4 +9,4 @@ export type PageBreakRunProjection = {
|
|
|
9
9
|
pmEnd: number;
|
|
10
10
|
trackedChange?: Pick<RunFormatting, "isInsertion" | "changeAuthor" | "changeDate" | "changeRevisionId" | "isSuggestion" | "suggestionId">;
|
|
11
11
|
};
|
|
12
|
-
export declare function paragraphToRuns(node: Node, startPos: number, _options:
|
|
12
|
+
export declare function paragraphToRuns(node: Node, startPos: number, _options: CounterFreeFlowConversionOptions, pageBreaks?: PageBreakRunProjection[]): Run[];
|
|
@@ -69,6 +69,11 @@ function coalesceTrailingPageBreakBeforeContinuousSection(blocks, splitPageBreak
|
|
|
69
69
|
function readFinalSectionStart(doc) {
|
|
70
70
|
return parseSectionBreakType(doc.attrs["_finalSectionStart"]) ?? void 0;
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Each block as last stamped with a line pitch. A block kept from an earlier
|
|
74
|
+
* conversion is never written, so stamping it again gives the same block.
|
|
75
|
+
*/
|
|
76
|
+
const griddedBlocks = /* @__PURE__ */ new WeakMap();
|
|
72
77
|
function applySectionDocumentGrid(blocks, { finalLinePitchTwips, tableCellLinePitch }) {
|
|
73
78
|
const result = [...blocks];
|
|
74
79
|
let sectionStart = 0;
|
|
@@ -76,6 +81,17 @@ function applySectionDocumentGrid(blocks, { finalLinePitchTwips, tableCellLinePi
|
|
|
76
81
|
if (linePitchTwips === void 0 || linePitchTwips <= 0) return;
|
|
77
82
|
const linePitch = twipsToPixels(linePitchTwips);
|
|
78
83
|
const stampBlock = (block) => {
|
|
84
|
+
const stamped = griddedBlocks.get(block);
|
|
85
|
+
if (stamped !== void 0 && stamped.linePitch === linePitch && stamped.tableCellLinePitch === tableCellLinePitch) return stamped.block;
|
|
86
|
+
const gridded = stampBlockWithoutMemo(block);
|
|
87
|
+
griddedBlocks.set(block, {
|
|
88
|
+
linePitch,
|
|
89
|
+
tableCellLinePitch,
|
|
90
|
+
block: gridded
|
|
91
|
+
});
|
|
92
|
+
return gridded;
|
|
93
|
+
};
|
|
94
|
+
const stampBlockWithoutMemo = (block) => {
|
|
79
95
|
if (block.kind === "paragraph") return {
|
|
80
96
|
...block,
|
|
81
97
|
attrs: {
|
|
@@ -243,14 +243,25 @@ function convertTable(node, startPos, options) {
|
|
|
243
243
|
function convertTextBoxNode(node, startPos, opts) {
|
|
244
244
|
const attrs = expectTextBoxAttrs(node);
|
|
245
245
|
const contentBlocks = [];
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
246
|
+
const convertBoxChildren = (container, containerStart) => {
|
|
247
|
+
container.forEach((child, offset) => {
|
|
248
|
+
const childPos = containerStart + offset;
|
|
249
|
+
switch (child.type.name) {
|
|
250
|
+
case "paragraph":
|
|
251
|
+
contentBlocks.push(convertParagraph(child, childPos, opts));
|
|
252
|
+
break;
|
|
253
|
+
case "table":
|
|
254
|
+
contentBlocks.push(convertTable(child, childPos, opts));
|
|
255
|
+
break;
|
|
256
|
+
case "preservedBlock":
|
|
257
|
+
contentBlocks.push(...convertAltChunkPlaceholder(child, childPos, opts));
|
|
258
|
+
break;
|
|
259
|
+
case "blockSdt":
|
|
260
|
+
case "blockCustomXml": convertBoxChildren(child, childPos + 1);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
convertBoxChildren(node, startPos + 1);
|
|
254
265
|
const textBox = {
|
|
255
266
|
kind: "textBox",
|
|
256
267
|
id: nextBlockId(),
|
|
@@ -12,14 +12,15 @@ import { getColumns } from "../sectionColumns.js";
|
|
|
12
12
|
import { convertAltChunkPlaceholder } from "./altChunkPlaceholder.js";
|
|
13
13
|
import { mergeRunInParagraphs, reserveLeadingEmptyOutlineHeight, suppressFinalEmptyParagraphAfterTable, suppressFinalParagraphInRepeatedEmptySuffix } from "./flowBlockPostprocessing.js";
|
|
14
14
|
import { convertBorderSpecToLayout } from "./flowBorders.js";
|
|
15
|
-
import { nextBlockId, resetBlockIdCounter, twipsToPixels } from "./flowConversionShared.js";
|
|
15
|
+
import { blockIdsHandedOut, nextBlockId, resetBlockIdCounter, skipBlockIds, twipsToPixels } from "./flowConversionShared.js";
|
|
16
16
|
import { convertImage } from "./imageConversion.js";
|
|
17
17
|
import { collectNoteRefs } from "./noteReferences.js";
|
|
18
18
|
import { splitParagraphAtPageBreaks } from "./pageBreakSplitting.js";
|
|
19
|
-
import {
|
|
19
|
+
import { convertParagraphWithListMarker, drawsParagraphBorder, paragraphListMarker } from "./paragraphConversion.js";
|
|
20
20
|
import { groupParagraphFrames } from "./paragraphFrames.js";
|
|
21
21
|
import { applySectionDocumentGrid, applySectionStartsToBoundaries, coalesceTrailingPageBreakBeforeContinuousSection, getLastMapKey, readFinalSectionStart } from "./sectionBoundaries.js";
|
|
22
22
|
import { convertTable, convertTextBoxNode } from "./tableConversion.js";
|
|
23
|
+
import { convertsWithOtherNodes, freezeKeptBlock, freezesKeptBlocks, restoreListCounterState, sameCheckpoint, takeCheckpoint } from "./topLevelConversion.js";
|
|
23
24
|
// src/layout-bridge/convert/toFlowBlocks.ts
|
|
24
25
|
/**
|
|
25
26
|
* Word's layout fallback when an imported OOXML style hierarchy never supplies
|
|
@@ -88,6 +89,13 @@ function toFlowBlocks(doc, options = {}) {
|
|
|
88
89
|
originalListCounterState: cloneListCounterState(originalListCounterState)
|
|
89
90
|
})
|
|
90
91
|
};
|
|
92
|
+
const paragraphBlocks = options.paragraphBlocks;
|
|
93
|
+
paragraphBlocks?.use(opts);
|
|
94
|
+
const seeded = options.listCounters !== void 0 || options.listAbstractCounters !== void 0 || options.listSeenNumIds !== void 0 || options.originalListCounters !== void 0 || options.originalListAbstractCounters !== void 0 || options.originalListSeenNumIds !== void 0;
|
|
95
|
+
/** Whether this conversion is kept for the next one. */
|
|
96
|
+
const recording = paragraphBlocks !== void 0 && !seeded;
|
|
97
|
+
const lastConversion = recording ? paragraphBlocks?.lastConversion(doc) : void 0;
|
|
98
|
+
const hasFontResolutionContext = options.embeddedFontFamilyMap !== void 0 || options.documentFontFacts !== void 0;
|
|
91
99
|
const blocks = [];
|
|
92
100
|
const offset = 0;
|
|
93
101
|
let lastSectionMarginsTwips = {
|
|
@@ -109,11 +117,24 @@ function toFlowBlocks(doc, options = {}) {
|
|
|
109
117
|
};
|
|
110
118
|
const trackedPush = (block) => {
|
|
111
119
|
tagBlockWithSdtStack(block);
|
|
120
|
+
if (hasFontResolutionContext) attachFontResolutionContext(block, options);
|
|
112
121
|
blocks.push(block);
|
|
113
122
|
};
|
|
123
|
+
/** The marker of the last paragraph projected whole. */
|
|
124
|
+
let projectedMarker;
|
|
114
125
|
const pushParagraphProjection = (node, pos, stripLeadingLineBreak = false) => {
|
|
126
|
+
const listMarker = paragraphListMarker(node, opts);
|
|
127
|
+
if (!stripLeadingLineBreak) {
|
|
128
|
+
projectedMarker = { marker: listMarker };
|
|
129
|
+
const kept = paragraphBlocks?.take(node, pos, listMarker, nextBlockId);
|
|
130
|
+
if (kept) {
|
|
131
|
+
trackedPush(kept);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
115
135
|
const pageBreaks = [];
|
|
116
|
-
const paragraph =
|
|
136
|
+
const paragraph = convertParagraphWithListMarker(node, pos, opts, listMarker, pageBreaks);
|
|
137
|
+
if (!stripLeadingLineBreak && pageBreaks.length === 0) paragraphBlocks?.keep(node, pos, listMarker, paragraph);
|
|
117
138
|
if (stripLeadingLineBreak && paragraph.runs.at(0)?.kind === "lineBreak") paragraph.runs.shift();
|
|
118
139
|
const projected = splitParagraphAtPageBreaks({
|
|
119
140
|
pageBreaks,
|
|
@@ -168,6 +189,7 @@ function toFlowBlocks(doc, options = {}) {
|
|
|
168
189
|
return;
|
|
169
190
|
}
|
|
170
191
|
tagBlockWithSdtStack(textBox);
|
|
192
|
+
if (hasFontResolutionContext) attachFontResolutionContext(textBox, options);
|
|
171
193
|
const heldBack = textBoxesBeforePageBreak.get(pageBreak);
|
|
172
194
|
if (heldBack) heldBack.push(textBox);
|
|
173
195
|
else textBoxesBeforePageBreak.set(pageBreak, [textBox]);
|
|
@@ -402,8 +424,107 @@ function toFlowBlocks(doc, options = {}) {
|
|
|
402
424
|
}
|
|
403
425
|
}
|
|
404
426
|
};
|
|
405
|
-
|
|
406
|
-
|
|
427
|
+
let pending;
|
|
428
|
+
/** The live state as a checkpoint, `previous` itself when it holds the same. */
|
|
429
|
+
const checkpoint = (previous) => {
|
|
430
|
+
const live = takeLiveCheckpointView();
|
|
431
|
+
return previous !== void 0 && sameCheckpoint(live, previous) ? previous : takeCheckpoint(listCounterState, originalListCounterState, lastSectionMarginsTwips, blocks.length - sectionStartBlockCount);
|
|
432
|
+
};
|
|
433
|
+
/** The live state, read in place: valid until the next node converts. */
|
|
434
|
+
const takeLiveCheckpointView = () => ({
|
|
435
|
+
final: listCounterState,
|
|
436
|
+
original: originalListCounterState,
|
|
437
|
+
margins: lastSectionMarginsTwips,
|
|
438
|
+
sectionBlocks: blocks.length - sectionStartBlockCount
|
|
439
|
+
});
|
|
440
|
+
const startsFrom = (state) => sameCheckpoint(pending ?? takeLiveCheckpointView(), state);
|
|
441
|
+
const bringLiveStateUpToDate = () => {
|
|
442
|
+
const state = pending;
|
|
443
|
+
if (state === void 0) return void 0;
|
|
444
|
+
restoreListCounterState(listCounterState, state.final);
|
|
445
|
+
restoreListCounterState(originalListCounterState, state.original);
|
|
446
|
+
lastSectionMarginsTwips = state.margins;
|
|
447
|
+
sectionStartBlockCount = blocks.length - state.sectionBlocks;
|
|
448
|
+
pending = void 0;
|
|
449
|
+
return state;
|
|
450
|
+
};
|
|
451
|
+
const kept = lastConversion?.nodes ?? [];
|
|
452
|
+
const nodeCount = doc.childCount;
|
|
453
|
+
let keptStart = 0;
|
|
454
|
+
while (keptStart < nodeCount && keptStart < kept.length && kept[keptStart]?.node === doc.child(keptStart)) keptStart += 1;
|
|
455
|
+
let keptEnd = 0;
|
|
456
|
+
while (keptEnd < nodeCount - keptStart && keptEnd < kept.length - keptStart && kept[kept.length - 1 - keptEnd]?.node === doc.child(nodeCount - 1 - keptEnd)) keptEnd += 1;
|
|
457
|
+
const keptIndex = (index) => {
|
|
458
|
+
if (index < keptStart) return index;
|
|
459
|
+
if (index >= nodeCount - keptEnd) return index - nodeCount + kept.length;
|
|
460
|
+
};
|
|
461
|
+
const stateAfter = (index) => kept[index + 1]?.before ?? lastConversion?.end;
|
|
462
|
+
const converted = [];
|
|
463
|
+
let lastBefore;
|
|
464
|
+
let pos = offset;
|
|
465
|
+
for (let index = 0; index < nodeCount; index += 1) {
|
|
466
|
+
const node = doc.child(index);
|
|
467
|
+
const keptAt = keptIndex(index);
|
|
468
|
+
const previous = keptAt === void 0 ? void 0 : kept[keptAt];
|
|
469
|
+
const firstBlockId = blockIdsHandedOut();
|
|
470
|
+
if (keptAt !== void 0 && previous !== void 0 && !convertsWithOtherNodes(node) && startsFrom(previous.before)) {
|
|
471
|
+
if (previous.pos === pos && previous.firstBlockId === firstBlockId && previous.firstSdt === sdtSeq) {
|
|
472
|
+
for (const block of previous.blocks) blocks.push(block);
|
|
473
|
+
skipBlockIds(previous.blockIds);
|
|
474
|
+
sdtSeq += previous.sdts;
|
|
475
|
+
converted.push(previous);
|
|
476
|
+
lastBefore = previous.before;
|
|
477
|
+
pending = stateAfter(keptAt);
|
|
478
|
+
pos += node.nodeSize;
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
481
|
+
const moved = previous.paragraphMarker !== void 0 && previous.blockIds === 1 && previous.sdts === 0 ? paragraphBlocks?.take(node, pos, previous.paragraphMarker.marker, nextBlockId) : void 0;
|
|
482
|
+
if (moved !== void 0) {
|
|
483
|
+
trackedPush(moved);
|
|
484
|
+
converted.push({
|
|
485
|
+
...previous,
|
|
486
|
+
pos,
|
|
487
|
+
firstBlockId,
|
|
488
|
+
firstSdt: sdtSeq,
|
|
489
|
+
blocks: [moved]
|
|
490
|
+
});
|
|
491
|
+
lastBefore = previous.before;
|
|
492
|
+
pending = stateAfter(keptAt);
|
|
493
|
+
pos += node.nodeSize;
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
const resumed = bringLiveStateUpToDate();
|
|
498
|
+
if (!recording) {
|
|
499
|
+
visit(node, pos);
|
|
500
|
+
pos += node.nodeSize;
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
const before = resumed ?? checkpoint(lastBefore);
|
|
504
|
+
const firstSdt = sdtSeq;
|
|
505
|
+
const firstBlock = blocks.length;
|
|
506
|
+
projectedMarker = void 0;
|
|
507
|
+
visit(node, pos);
|
|
508
|
+
const projected = blocks.slice(firstBlock);
|
|
509
|
+
const blockIds = blockIdsHandedOut() - firstBlockId;
|
|
510
|
+
converted.push({
|
|
511
|
+
node,
|
|
512
|
+
pos,
|
|
513
|
+
firstBlockId,
|
|
514
|
+
blockIds,
|
|
515
|
+
firstSdt,
|
|
516
|
+
sdts: sdtSeq - firstSdt,
|
|
517
|
+
before,
|
|
518
|
+
blocks: projected,
|
|
519
|
+
...projectedMarker !== void 0 && node.type.name === "paragraph" && projected.length === 1 && projected[0]?.kind === "paragraph" ? { paragraphMarker: projectedMarker } : {}
|
|
520
|
+
});
|
|
521
|
+
lastBefore = before;
|
|
522
|
+
pos += node.nodeSize;
|
|
523
|
+
}
|
|
524
|
+
if (recording) paragraphBlocks?.recordConversion({
|
|
525
|
+
doc,
|
|
526
|
+
nodes: converted,
|
|
527
|
+
end: pending ?? checkpoint(lastBefore)
|
|
407
528
|
});
|
|
408
529
|
releaseTextBoxesBeforePageBreaks();
|
|
409
530
|
reserveLeadingEmptyOutlineHeight(blocks);
|
|
@@ -421,12 +542,19 @@ function toFlowBlocks(doc, options = {}) {
|
|
|
421
542
|
const boundaryBlocks = applySectionStartsToBoundaries(griddedBlocks, readFinalSectionStart(doc));
|
|
422
543
|
const reconciledBlocks = coalesceTrailingPageBreakBeforeContinuousSection(boundaryBlocks, options.splitPageBreakAndParagraphMark === true, sectionBreaksWithoutMarker);
|
|
423
544
|
const result = groupParagraphFrames(reconciledBlocks, nextBlockId);
|
|
424
|
-
if (
|
|
545
|
+
if (recording && freezesKeptBlocks()) {
|
|
546
|
+
for (const node of converted) for (const block of node.blocks) freezeKeptBlock(block);
|
|
547
|
+
for (const block of result) freezeKeptBlock(block);
|
|
548
|
+
}
|
|
425
549
|
return result;
|
|
426
550
|
}
|
|
427
|
-
/**
|
|
428
|
-
|
|
429
|
-
|
|
551
|
+
/**
|
|
552
|
+
* Attach editor-owned resolution to a freshly derived block without changing
|
|
553
|
+
* authored data. Blocks kept from an earlier conversion under the same
|
|
554
|
+
* constants already carry it.
|
|
555
|
+
*/
|
|
556
|
+
const attachFontResolutionContext = (block, options) => {
|
|
557
|
+
switch (block.kind) {
|
|
430
558
|
case "paragraph":
|
|
431
559
|
for (const run of block.runs) if (run.kind !== "image" && run.kind !== "lineBreak") {
|
|
432
560
|
if (options.embeddedFontFamilyMap !== void 0) run.embeddedFontFamilyMap = options.embeddedFontFamilyMap;
|
|
@@ -435,16 +563,17 @@ const attachFontResolutionContext = (blocks, options) => {
|
|
|
435
563
|
block.attrs ??= {};
|
|
436
564
|
if (options.embeddedFontFamilyMap !== void 0) block.attrs.embeddedFontFamilyMap = options.embeddedFontFamilyMap;
|
|
437
565
|
if (options.documentFontFacts !== void 0) block.attrs.documentFontFacts = options.documentFontFacts;
|
|
438
|
-
if (block.attrs.listMarkerFormatting) {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
566
|
+
if (block.attrs.listMarkerFormatting) block.attrs.listMarkerFormatting = {
|
|
567
|
+
...block.attrs.listMarkerFormatting,
|
|
568
|
+
...options.embeddedFontFamilyMap === void 0 ? {} : { embeddedFontFamilyMap: options.embeddedFontFamilyMap },
|
|
569
|
+
...options.documentFontFacts === void 0 ? {} : { documentFontFacts: options.documentFontFacts }
|
|
570
|
+
};
|
|
442
571
|
break;
|
|
443
572
|
case "table":
|
|
444
|
-
for (const row of block.rows) for (const cell of row.cells)
|
|
573
|
+
for (const row of block.rows) for (const cell of row.cells) for (const cellBlock of cell.blocks) attachFontResolutionContext(cellBlock, options);
|
|
445
574
|
break;
|
|
446
575
|
case "textBox":
|
|
447
|
-
|
|
576
|
+
for (const contentBlock of block.content) attachFontResolutionContext(contentBlock, options);
|
|
448
577
|
break;
|
|
449
578
|
case "image":
|
|
450
579
|
case "sectionBreak":
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ListCounterState } from "../../prosemirror/listMarker.js";
|
|
2
|
+
import { FlowBlock } from "../../layout-engine/types.js";
|
|
3
|
+
import { ParagraphListMarker } from "./paragraphAttrs.js";
|
|
4
|
+
import { Node } from "prosemirror-model";
|
|
5
|
+
/** Margins, in twips, of the last section that authored them. */
|
|
6
|
+
export type SectionMarginsTwips = {
|
|
7
|
+
readonly top: number;
|
|
8
|
+
readonly bottom: number;
|
|
9
|
+
readonly left: number;
|
|
10
|
+
readonly right: number;
|
|
11
|
+
};
|
|
12
|
+
/** The state converting a top-level node starts from, besides ids. */
|
|
13
|
+
export type ConversionCheckpoint = {
|
|
14
|
+
readonly final: ListCounterState;
|
|
15
|
+
readonly original: ListCounterState;
|
|
16
|
+
readonly margins: SectionMarginsTwips;
|
|
17
|
+
/** Blocks the current section has projected so far. */
|
|
18
|
+
readonly sectionBlocks: number;
|
|
19
|
+
};
|
|
20
|
+
/** One top-level node's conversion. */
|
|
21
|
+
export type TopLevelConversion = {
|
|
22
|
+
readonly node: Node;
|
|
23
|
+
readonly pos: number;
|
|
24
|
+
/** Block ids handed out before the node was converted. */
|
|
25
|
+
readonly firstBlockId: number;
|
|
26
|
+
readonly blockIds: number;
|
|
27
|
+
/** Content control ids handed out before the node was converted. */
|
|
28
|
+
readonly firstSdt: number;
|
|
29
|
+
readonly sdts: number;
|
|
30
|
+
readonly before: ConversionCheckpoint;
|
|
31
|
+
/** The blocks the node projected, before the passes over the whole list. */
|
|
32
|
+
readonly blocks: readonly FlowBlock[];
|
|
33
|
+
/** For a node that converted to one paragraph block: the marker it had. */
|
|
34
|
+
readonly paragraphMarker?: {
|
|
35
|
+
readonly marker: ParagraphListMarker;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export type RecordedConversion = {
|
|
39
|
+
readonly doc: Node;
|
|
40
|
+
readonly nodes: readonly TopLevelConversion[];
|
|
41
|
+
/** The state the last node left. */
|
|
42
|
+
readonly end: ConversionCheckpoint;
|
|
43
|
+
};
|
|
44
|
+
export type KeptBlockFlags = {
|
|
45
|
+
/** Freeze every block a kept conversion keeps or hands out. */
|
|
46
|
+
enabled?: boolean;
|
|
47
|
+
};
|
|
48
|
+
declare global {
|
|
49
|
+
var __folioFreezeKeptBlocks: KeptBlockFlags | undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Whether kept conversions freeze their blocks. Tests set it, so code that
|
|
53
|
+
* writes to a block handed out again fails where it writes instead of
|
|
54
|
+
* changing what a later conversion hands out.
|
|
55
|
+
*/
|
|
56
|
+
export declare const freezesKeptBlocks: () => boolean;
|
|
57
|
+
/** Freeze every plain object and array `value` holds, and `value`. */
|
|
58
|
+
export declare const freezeKeptBlock: (value: unknown) => void;
|
|
59
|
+
/** Whether converting `node` reads anything besides itself and the state before it. */
|
|
60
|
+
export declare const convertsWithOtherNodes: (node: Node) => boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Two counter states that number every paragraph after them alike. Advancing
|
|
63
|
+
* a list writes one array that a numbering instance and its abstract
|
|
64
|
+
* definition may both hold, so which arrays are shared is compared too.
|
|
65
|
+
*/
|
|
66
|
+
export declare const sameListCounterState: (left: ListCounterState, right: ListCounterState) => boolean;
|
|
67
|
+
export declare const sameCheckpoint: (left: ConversionCheckpoint, right: ConversionCheckpoint) => boolean;
|
|
68
|
+
export declare const takeCheckpoint: (final: ListCounterState, original: ListCounterState, margins: SectionMarginsTwips, sectionBlocks: number) => ConversionCheckpoint;
|
|
69
|
+
/**
|
|
70
|
+
* Make `target` the state `source` holds, in place: the conversion options
|
|
71
|
+
* hold `target`'s maps and sets themselves. Arrays `source` shares stay
|
|
72
|
+
* shared in `target`, and `source` is never written.
|
|
73
|
+
*/
|
|
74
|
+
export declare const restoreListCounterState: (target: ListCounterState, source: ListCounterState) => void;
|