@stll/folio-core 0.51.0 → 0.53.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/README.md +23 -0
- package/dist/ai-edits/apply.d.ts +26 -1
- package/dist/ai-edits/apply.js +1519 -105
- package/dist/ai-edits/batch-claims.d.ts +130 -0
- package/dist/ai-edits/batch-claims.js +244 -0
- package/dist/ai-edits/blockRange.js +9 -3
- package/dist/ai-edits/character-boundaries.d.ts +43 -0
- package/dist/ai-edits/character-boundaries.js +95 -0
- package/dist/ai-edits/clean-text.d.ts +33 -3
- package/dist/ai-edits/clean-text.js +52 -6
- package/dist/ai-edits/comment-lifecycle.d.ts +18 -0
- package/dist/ai-edits/comment-lifecycle.js +52 -0
- package/dist/ai-edits/headless.d.ts +71 -7
- package/dist/ai-edits/headless.js +381 -41
- package/dist/ai-edits/index.d.ts +2 -1
- package/dist/ai-edits/index.js +2 -1
- package/dist/ai-edits/minimal-replacement.d.ts +21 -6
- package/dist/ai-edits/minimal-replacement.js +134 -15
- package/dist/ai-edits/newListNumbering.d.ts +23 -0
- package/dist/ai-edits/newListNumbering.js +94 -0
- package/dist/ai-edits/note-references.d.ts +96 -0
- package/dist/ai-edits/note-references.js +139 -0
- package/dist/ai-edits/pending-suggestions.d.ts +79 -0
- package/dist/ai-edits/pending-suggestions.js +306 -0
- package/dist/ai-edits/read.d.ts +1 -1
- package/dist/ai-edits/read.js +56 -43
- package/dist/ai-edits/result-validation.d.ts +29 -0
- package/dist/ai-edits/result-validation.js +164 -0
- package/dist/ai-edits/snapshot.d.ts +36 -3
- package/dist/ai-edits/snapshot.js +177 -23
- package/dist/ai-edits/table-cell-mutations.d.ts +1 -1
- package/dist/ai-edits/table-cell-mutations.js +4 -1
- package/dist/ai-edits/table-geometry.d.ts +1 -1
- package/dist/ai-edits/table-row-column-mutations.d.ts +38 -16
- package/dist/ai-edits/table-row-column-mutations.js +61 -26
- package/dist/ai-edits/types.d.ts +155 -16
- package/dist/compare/compare.d.ts +1 -1
- package/dist/compare/compare.js +65 -16
- package/dist/compare/content-alignment.js +13 -2
- package/dist/compare/content-types.d.ts +7 -0
- package/dist/compare/content.d.ts +4 -1
- package/dist/compare/content.js +6 -1
- package/dist/compare/formatting.js +2 -1
- package/dist/compare/inline-atoms.d.ts +21 -4
- package/dist/compare/inline-atoms.js +138 -16
- package/dist/compare/inline-provenance.js +18 -22
- package/dist/compare/plan.js +10 -5
- package/dist/compare/scenario.js +14 -3
- package/dist/compare/section-boundary-properties.js +14 -1
- package/dist/compare/types.d.ts +4 -2
- package/dist/compare/types.js +2 -1
- package/dist/compare/verification.d.ts +1 -1
- package/dist/compare/verification.js +15 -3
- package/dist/controller/committedLayoutDiff.d.ts +25 -0
- package/dist/controller/committedLayoutDiff.js +71 -0
- package/dist/controller/contentControlWidgetController.d.ts +1 -1
- package/dist/controller/folioEditor.d.ts +1 -1
- package/dist/controller/fontReadiness.d.ts +70 -3
- package/dist/controller/fontReadiness.js +100 -10
- package/dist/controller/headerFooterEditorManager.js +6 -1
- package/dist/controller/layoutPipeline.d.ts +12 -10
- package/dist/controller/layoutPipeline.js +62 -9
- package/dist/controller/layoutRunOptions.d.ts +24 -0
- package/dist/controller/layoutRunOptions.js +17 -0
- package/dist/controller/layoutScheduler.d.ts +19 -14
- package/dist/controller/layoutScheduler.js +15 -12
- package/dist/controller/layoutSession.d.ts +26 -2
- package/dist/controller/layoutSession.js +1 -1
- package/dist/controller/noteEditorManager.js +8 -3
- package/dist/document-operations.d.ts +11 -2
- package/dist/document-operations.js +230 -21
- package/dist/docx/altChunk.d.ts +8 -0
- package/dist/docx/altChunk.js +17 -0
- package/dist/docx/attributeRemainder.d.ts +1 -1
- package/dist/docx/blockContentParser.d.ts +64 -1
- package/dist/docx/blockContentParser.js +17 -4
- package/dist/docx/blockCustomXmlShell.d.ts +7 -0
- package/dist/docx/blockCustomXmlShell.js +14 -0
- package/dist/docx/blockPlainText.js +7 -0
- package/dist/docx/commentAnchorIndex.js +1 -1
- package/dist/docx/commentRangeIntegrity.js +8 -3
- package/dist/docx/commentReferenceNormalization.js +1 -1
- package/dist/docx/commentReplyMarkers.js +20 -1
- package/dist/docx/compatibility.d.ts +1 -1
- package/dist/docx/compatibility.js +34 -13
- package/dist/docx/containerChildren.gen.d.ts +1 -1
- package/dist/docx/containerChildren.gen.js +1 -0
- package/dist/docx/documentParser.js +12 -12
- package/dist/docx/drawingIdNormalization.d.ts +3 -1
- package/dist/docx/drawingIdNormalization.js +6 -1
- package/dist/docx/ensureParaIds.js +119 -97
- package/dist/docx/footnoteParser.js +8 -4
- package/dist/docx/headerFooterParser.js +3 -3
- package/dist/docx/headerFooterReferenceNormalization.d.ts +20 -1
- package/dist/docx/headerFooterReferenceNormalization.js +52 -27
- package/dist/docx/hyperlinkParser.d.ts +1 -1
- package/dist/docx/index.d.ts +1 -1
- package/dist/docx/listNumberingInstances.d.ts +59 -0
- package/dist/docx/listNumberingInstances.js +249 -0
- package/dist/docx/normalizeBaseDirection.js +2 -1
- package/dist/docx/opaqueCarrier.d.ts +7 -0
- package/dist/docx/opaqueCarrier.js +38 -0
- package/dist/docx/packageParts.js +4 -1
- package/dist/docx/paragraphParser.js +91 -24
- package/dist/docx/paragraphPropertySource.d.ts +4 -2
- package/dist/docx/paragraphPropertySource.js +7 -1
- package/dist/docx/paragraphTraversal.js +1 -0
- package/dist/docx/parseWarningMessage.js +4 -1
- package/dist/docx/parser.js +173 -20
- package/dist/docx/rezip.js +27 -5
- package/dist/docx/sdtProperties.js +1 -1
- package/dist/docx/sdtPropertiesPatch.js +3 -0
- package/dist/docx/selectiveSave.js +16 -9
- package/dist/docx/selectiveXmlPatch.js +106 -37
- package/dist/docx/serializer/blockCustomXmlSerializer.d.ts +5 -0
- package/dist/docx/serializer/blockCustomXmlSerializer.js +4 -0
- package/dist/docx/serializer/documentSerializer.js +2 -0
- package/dist/docx/serializer/headerFooterSerializer.js +2 -0
- package/dist/docx/serializer/noteSerializer.js +3 -1
- package/dist/docx/serializer/paragraphSerializer.js +33 -9
- package/dist/docx/serializer/tableSerializer.js +25 -38
- package/dist/docx/server/createBilingualDocument.js +3 -3
- package/dist/docx/tableParser.d.ts +157 -1
- package/dist/docx/tableParser.js +89 -10
- package/dist/docx/textBoxParser.js +1 -1
- package/dist/docx/unzip.d.ts +2 -1
- package/dist/docx/unzip.js +1 -1
- package/dist/docx/wordprocessingPrefixes.d.ts +78 -0
- package/dist/docx/wordprocessingPrefixes.js +286 -0
- package/dist/generated/text_shaper.js +26 -0
- package/dist/generated/text_shaper_bg.wasm +0 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +136 -0
- package/dist/i18n/messages/catalogs.gen.js +153 -17
- package/dist/i18n/messages/messages.gen.d.ts +8 -0
- package/dist/internal/compare/inline-presentation.d.ts +2 -1
- package/dist/internal/compare/inline-presentation.js +11 -10
- package/dist/internal/headlessRevisionResolutionGuard.d.ts +2 -8
- package/dist/internal/headlessRevisionResolutionGuard.js +2 -11
- package/dist/internal/indexedPositionMap.d.ts +11 -0
- package/dist/internal/indexedPositionMap.js +42 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +2 -1
- package/dist/internal/revisionResolutionEdits.d.ts +13 -0
- package/dist/internal/revisionResolutionEdits.js +19 -0
- package/dist/internal/revisionResolutionInline.d.ts +24 -0
- package/dist/internal/{headlessRevisionResolution.js → revisionResolutionInline.js} +61 -43
- package/dist/internal/revisionResolutionStep.d.ts +34 -0
- package/dist/internal/revisionResolutionStep.js +282 -0
- package/dist/internal/revisionResolutionTracking.d.ts +11 -0
- package/dist/internal/revisionResolutionTracking.js +124 -0
- package/dist/internal/wholeStoryRevisionResolution.d.ts +56 -0
- package/dist/internal/wholeStoryRevisionResolution.js +530 -0
- package/dist/layout-bridge/convert/markupViewFlow.d.ts +20 -0
- package/dist/layout-bridge/convert/markupViewFlow.js +123 -0
- package/dist/layout-bridge/convert/tableConversion.js +1 -1
- package/dist/layout-bridge/convert/toFlowBlocks.js +10 -1
- package/dist/layout-engine/layoutInstrumentation.d.ts +9 -1
- package/dist/layout-engine/layoutInstrumentation.js +4 -1
- package/dist/layout-engine/measure/cache.d.ts +18 -1
- package/dist/layout-engine/measure/cache.js +31 -1
- package/dist/layout-engine/measure/font-metrics.worker.js +3 -7
- package/dist/layout-engine/measure/measureContainer.js +7 -47
- package/dist/layout-engine/measure/measureHelpers.d.ts +6 -1
- package/dist/layout-engine/measure/measureHelpers.js +22 -2
- package/dist/layout-engine/measure/measureWorker.js +2 -3
- package/dist/layout-engine/measure/measureWorkerProtocol.d.ts +6 -7
- package/dist/layout-engine/measure/measureWorkerProtocol.js +1 -2
- package/dist/layout-engine/types.d.ts +6 -0
- package/dist/layout-painter/renderPage.js +1 -0
- package/dist/layout-painter/renderParagraph.js +1 -1
- package/dist/managers/ContextMenuManager.js +5 -2
- package/dist/managers/types.d.ts +3 -0
- package/dist/markdown/fromMarkdown.js +2 -1
- package/dist/markdown/internals.d.ts +11 -1
- package/dist/markdown/internals.js +24 -3
- package/dist/markdown/renderBlock.js +39 -9
- package/dist/markdown/renderParagraph.d.ts +13 -1
- package/dist/markdown/renderParagraph.js +85 -38
- package/dist/markdown/renderRuns.js +3 -10
- package/dist/markdown/renderTable.js +24 -12
- package/dist/markdown/trailers.js +2 -2
- package/dist/markdown/types.d.ts +29 -7
- package/dist/paged-layout/incrementalMeasure.d.ts +1 -2
- package/dist/paged-layout/incrementalMeasure.js +1 -9
- package/dist/paged-layout/transactionDirtyRange.d.ts +1 -3
- package/dist/paged-layout/transactionDirtyRange.js +29 -41
- package/dist/panel-layout.d.ts +83 -0
- package/dist/panel-layout.js +96 -0
- package/dist/prosemirror/anchoredTextBoxes.d.ts +37 -0
- package/dist/prosemirror/anchoredTextBoxes.js +156 -0
- package/dist/prosemirror/attrs/index.d.ts +6 -2
- package/dist/prosemirror/attrs/index.js +172 -1
- package/dist/prosemirror/commands/comments.d.ts +7 -8
- package/dist/prosemirror/commands/comments.js +241 -207
- package/dist/prosemirror/commands/contentControls.d.ts +1 -1
- package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
- package/dist/prosemirror/commands/formatting.d.ts +1 -1
- package/dist/prosemirror/commands/index.d.ts +2 -2
- package/dist/prosemirror/commands/index.js +2 -2
- package/dist/prosemirror/commands/paragraph.d.ts +7 -1
- package/dist/prosemirror/commands/paragraph.js +9 -1
- package/dist/prosemirror/commands/paragraphBookmarkJoin.d.ts +13 -0
- package/dist/prosemirror/commands/paragraphBookmarkJoin.js +22 -0
- package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
- package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +40 -0
- package/dist/prosemirror/commands/resolveAllTableChanges.js +615 -0
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +15 -0
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +46 -0
- package/dist/prosemirror/commands/resolveParagraphProperties.d.ts +16 -0
- package/dist/prosemirror/commands/resolveParagraphProperties.js +59 -0
- package/dist/prosemirror/commands/sectionBreak.js +2 -1
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +8 -2
- package/dist/prosemirror/commands/tableCellMergeResolution.js +1 -1
- package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
- package/dist/prosemirror/conversion/fromProseDoc.js +181 -31
- package/dist/prosemirror/conversion/toProseDoc.js +39 -4
- package/dist/prosemirror/emptyFieldResultRuns.d.ts +18 -0
- package/dist/prosemirror/emptyFieldResultRuns.js +33 -0
- package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
- package/dist/prosemirror/extensions/ExtensionManager.js +3 -1
- package/dist/prosemirror/extensions/StarterKit.js +3 -1
- package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +12 -0
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -0
- package/dist/prosemirror/extensions/features/ListExtension.js +161 -123
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +19 -2
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +33 -20
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +31 -2
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +270 -99
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +3 -2
- package/dist/prosemirror/extensions/features/pasteCleanup.js +2 -1
- package/dist/prosemirror/extensions/features/pastedHtmlLists.d.ts +12 -0
- package/dist/prosemirror/extensions/features/pastedHtmlLists.js +126 -0
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +21 -5
- package/dist/prosemirror/extensions/marks/RunIdentityExtension.d.ts +21 -18
- package/dist/prosemirror/extensions/marks/RunIdentityExtension.js +37 -17
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +7 -2
- package/dist/prosemirror/extensions/marks/markUtils.js +8 -2
- package/dist/prosemirror/extensions/marks/noteReferenceDeletion.d.ts +10 -0
- package/dist/prosemirror/extensions/marks/noteReferenceDeletion.js +35 -0
- package/dist/prosemirror/extensions/nodes/BlockCustomXmlExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/nodes/BlockCustomXmlExtension.js +52 -0
- package/dist/prosemirror/extensions/nodes/FieldExtension.d.ts +3 -3
- package/dist/prosemirror/extensions/nodes/FieldExtension.js +50 -15
- package/dist/prosemirror/extensions/nodes/PreservedBlockExtension.js +4 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.js +19 -18
- package/dist/prosemirror/extensions/types.d.ts +4 -1
- package/dist/prosemirror/findReplaceSelection.js +1 -1
- package/dist/prosemirror/index.d.ts +3 -2
- package/dist/prosemirror/index.js +3 -2
- package/dist/prosemirror/indexedNodeLookup.d.ts +17 -0
- package/dist/prosemirror/indexedNodeLookup.js +103 -0
- package/dist/prosemirror/listAutoformatMarkers.d.ts +19 -0
- package/dist/prosemirror/listAutoformatMarkers.js +98 -0
- package/dist/prosemirror/listInstanceReferences.d.ts +12 -0
- package/dist/prosemirror/listInstanceReferences.js +72 -0
- package/dist/prosemirror/listLabels.d.ts +24 -0
- package/dist/prosemirror/listLabels.js +111 -0
- package/dist/prosemirror/listNumbering.d.ts +110 -0
- package/dist/prosemirror/listNumbering.js +345 -0
- package/dist/prosemirror/listRenderingAttrs.d.ts +11 -2
- package/dist/prosemirror/listRenderingAttrs.js +8 -1
- package/dist/prosemirror/markupViewProjection.d.ts +95 -0
- package/dist/prosemirror/markupViewProjection.js +83 -0
- package/dist/prosemirror/numberingAttr.d.ts +9 -1
- package/dist/prosemirror/numberingAttr.js +9 -1
- package/dist/prosemirror/outlineLevelAttr.js +1 -1
- package/dist/prosemirror/paragraphIndentation.d.ts +10 -1
- package/dist/prosemirror/paragraphIndentation.js +29 -7
- package/dist/prosemirror/paragraphMarkJoin.d.ts +19 -0
- package/dist/prosemirror/paragraphMarkJoin.js +24 -0
- package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
- package/dist/prosemirror/plugins/documentNumbering.d.ts +27 -1
- package/dist/prosemirror/plugins/documentNumbering.js +97 -11
- package/dist/prosemirror/plugins/documentStyles.d.ts +10 -1
- package/dist/prosemirror/plugins/documentStyles.js +14 -1
- package/dist/prosemirror/plugins/suggestionMode.d.ts +16 -2
- package/dist/prosemirror/plugins/suggestionMode.js +116 -52
- package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
- package/dist/prosemirror/plugins/transactionInvariants.d.ts +32 -0
- package/dist/prosemirror/plugins/transactionInvariants.js +86 -0
- package/dist/prosemirror/positionSweep.d.ts +24 -0
- package/dist/prosemirror/positionSweep.js +222 -0
- package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -1
- package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
- package/dist/prosemirror/replacedAnnotations.d.ts +33 -1
- package/dist/prosemirror/replacedAnnotations.js +170 -1
- package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
- package/dist/prosemirror/runStyleFormatting.d.ts +7 -1
- package/dist/prosemirror/runStyleFormatting.js +13 -7
- package/dist/prosemirror/schema/index.d.ts +2 -2
- package/dist/prosemirror/schema/index.js +3 -0
- package/dist/prosemirror/schema/nodes.d.ts +42 -11
- package/dist/prosemirror/sectionMarkEdits.d.ts +20 -0
- package/dist/prosemirror/sectionMarkEdits.js +59 -0
- package/dist/prosemirror/storyListNumbering.d.ts +17 -0
- package/dist/prosemirror/storyListNumbering.js +102 -0
- package/dist/prosemirror/tableGridMutation.d.ts +48 -2
- package/dist/prosemirror/tableGridMutation.js +106 -1
- package/dist/prosemirror/validation.js +5 -1
- package/dist/redline.js +93 -9
- package/dist/render-dom/BodySelectionOverlay.d.ts +4 -1
- package/dist/render-dom/BodySelectionOverlay.js +3 -2
- package/dist/shaping/shaper.d.ts +47 -4
- package/dist/shaping/shaper.js +46 -15
- package/dist/text-shaping.d.ts +4 -0
- package/dist/text-shaping.js +4 -0
- package/dist/utils/findReplace.js +2 -2
- package/dist/utils/mergeDocumentContent.js +1 -1
- package/dist/utils/noteReferenceLabels.d.ts +36 -0
- package/dist/utils/noteReferenceLabels.js +32 -0
- package/dist/utils/replaceText.js +1 -1
- package/dist/version-comparison.d.ts +1 -0
- package/dist/version-comparison.js +1 -0
- package/package.json +8 -2
- package/dist/internal/headlessRevisionResolution.d.ts +0 -23
|
@@ -3,7 +3,7 @@ import { expectHyperlinkMarkAttrs, expectRunPropertyChangeMarkAttrs, expectTable
|
|
|
3
3
|
import { getDocumentStyleResolver } from "../prosemirror/plugins/documentStyles.js";
|
|
4
4
|
import { applyMarksToRunFormattingRepresentation, expandRunFormattingCarrier, runFormattingCarrierReviewText } from "../prosemirror/runFormattingInlineCarriers.js";
|
|
5
5
|
import { readAuthoredRunFormatting, reconcileRunFormattingMarks } from "../prosemirror/runFormattingReconciliation.js";
|
|
6
|
-
import {
|
|
6
|
+
import { nearestParagraphRunStyleContext } from "../prosemirror/runStyleFormatting.js";
|
|
7
7
|
import { isTableCellRetainedInReviewView } from "../prosemirror/tableCellRevisionVisibility.js";
|
|
8
8
|
import { canonicalJson } from "../utils/canonicalJson.js";
|
|
9
9
|
//#region src/compare/inline-provenance.ts
|
|
@@ -19,10 +19,11 @@ const hyperlinkIdentity = (node) => {
|
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
21
|
const isInserted = (node) => node.marks.some(({ type }) => type.name === "insertion");
|
|
22
|
-
const carrierRepresentations = (carrier) => carrier.representations.map((representation) => ({
|
|
22
|
+
const carrierRepresentations = ({ carrier, paragraph }) => carrier.representations.map((representation) => ({
|
|
23
23
|
...representation,
|
|
24
24
|
from: representation.position,
|
|
25
|
-
to: representation.position + representation.node.nodeSize
|
|
25
|
+
to: representation.position + representation.node.nodeSize,
|
|
26
|
+
paragraph
|
|
26
27
|
}));
|
|
27
28
|
const targetBlockIdLookup = (anchors) => {
|
|
28
29
|
const ordered = Object.values(anchors).toSorted((left, right) => left.from - right.from || left.to - right.to);
|
|
@@ -53,7 +54,13 @@ const collectCarriers = ({ doc, targetSnapshot }) => {
|
|
|
53
54
|
const carriers = [];
|
|
54
55
|
const targetBlockIdAt = targetSnapshot ? targetBlockIdLookup(targetSnapshot.anchors) : void 0;
|
|
55
56
|
let unanchoredTargetCarrier = false;
|
|
57
|
+
const openParagraphs = [];
|
|
56
58
|
doc.descendants((node, position) => {
|
|
59
|
+
while ((openParagraphs.at(-1)?.end ?? Number.POSITIVE_INFINITY) <= position) openParagraphs.pop();
|
|
60
|
+
if (node.type.name === "paragraph") openParagraphs.push({
|
|
61
|
+
node,
|
|
62
|
+
end: position + node.nodeSize
|
|
63
|
+
});
|
|
57
64
|
if ((node.type.name === "tableCell" || node.type.name === "tableHeader") && !isTableCellRetainedInReviewView(expectTableCellAttrs(node).cellMarker?.kind, "final")) return false;
|
|
58
65
|
if (!node.isInline) return true;
|
|
59
66
|
const carrier = expandRunFormattingCarrier(node, position);
|
|
@@ -69,6 +76,7 @@ const collectCarriers = ({ doc, targetSnapshot }) => {
|
|
|
69
76
|
}
|
|
70
77
|
carriers.push({
|
|
71
78
|
carrier,
|
|
79
|
+
paragraph: openParagraphs.at(-1)?.node ?? null,
|
|
72
80
|
text: runFormattingCarrierReviewText(carrier),
|
|
73
81
|
targetBlockId
|
|
74
82
|
});
|
|
@@ -106,8 +114,8 @@ const matchCarrierStreams = ({ live, target }) => {
|
|
|
106
114
|
const targetIsText = targetCarrier.carrier.disposition === "text-run";
|
|
107
115
|
if (!liveIsText || !targetIsText) {
|
|
108
116
|
if (liveOffset !== 0 || targetOffset !== 0 || !sameCarrierShape(liveCarrier, targetCarrier)) return null;
|
|
109
|
-
const liveRepresentations = carrierRepresentations(liveCarrier
|
|
110
|
-
const targetRepresentations = carrierRepresentations(targetCarrier
|
|
117
|
+
const liveRepresentations = carrierRepresentations(liveCarrier);
|
|
118
|
+
const targetRepresentations = carrierRepresentations(targetCarrier);
|
|
111
119
|
for (const [index, liveRepresentation] of liveRepresentations.entries()) {
|
|
112
120
|
const targetRepresentation = targetRepresentations.at(index);
|
|
113
121
|
if (!targetRepresentation) return null;
|
|
@@ -123,8 +131,8 @@ const matchCarrierStreams = ({ live, target }) => {
|
|
|
123
131
|
}
|
|
124
132
|
const sharedLength = Math.min(liveText.length, targetText.length);
|
|
125
133
|
if (sharedLength === 0 || liveText.slice(0, sharedLength) !== targetText.slice(0, sharedLength)) return null;
|
|
126
|
-
const liveRepresentation = carrierRepresentations(liveCarrier
|
|
127
|
-
const targetRepresentation = carrierRepresentations(targetCarrier
|
|
134
|
+
const liveRepresentation = carrierRepresentations(liveCarrier).at(0);
|
|
135
|
+
const targetRepresentation = carrierRepresentations(targetCarrier).at(0);
|
|
128
136
|
if (!liveRepresentation || !targetRepresentation) return null;
|
|
129
137
|
matched.push({
|
|
130
138
|
live: {
|
|
@@ -152,12 +160,8 @@ const matchCarrierStreams = ({ live, target }) => {
|
|
|
152
160
|
}
|
|
153
161
|
return matched;
|
|
154
162
|
};
|
|
155
|
-
const authoredFormattingAt = ({
|
|
156
|
-
context:
|
|
157
|
-
doc,
|
|
158
|
-
pos: representation.from,
|
|
159
|
-
styleResolver
|
|
160
|
-
}),
|
|
163
|
+
const authoredFormattingAt = ({ representation, styleResolver }) => readAuthoredRunFormatting({
|
|
164
|
+
context: nearestParagraphRunStyleContext(representation.paragraph, styleResolver),
|
|
161
165
|
marks: representation.node.marks,
|
|
162
166
|
styleResolver
|
|
163
167
|
});
|
|
@@ -190,12 +194,10 @@ const matchInlineProvenance = ({ state, targetSnapshot, revisionStamp, originalR
|
|
|
190
194
|
const planned = [];
|
|
191
195
|
for (const segment of matched) {
|
|
192
196
|
const liveFormatting = authoredFormattingAt({
|
|
193
|
-
doc: state.doc,
|
|
194
197
|
representation: segment.live,
|
|
195
198
|
styleResolver: liveStyleResolver
|
|
196
199
|
});
|
|
197
200
|
const targetFormatting = authoredFormattingAt({
|
|
198
|
-
doc: targetDocument,
|
|
199
201
|
representation: segment.target,
|
|
200
202
|
styleResolver: targetStyleResolver
|
|
201
203
|
});
|
|
@@ -220,11 +222,7 @@ const matchInlineProvenance = ({ state, targetSnapshot, revisionStamp, originalR
|
|
|
220
222
|
let nextRevisionId = revisionStamp.idSeed;
|
|
221
223
|
const changedTargetBlockIds = /* @__PURE__ */ new Set();
|
|
222
224
|
for (const change of planned.toReversed()) {
|
|
223
|
-
const context =
|
|
224
|
-
doc: state.doc,
|
|
225
|
-
pos: change.live.from,
|
|
226
|
-
styleResolver: liveStyleResolver
|
|
227
|
-
});
|
|
225
|
+
const context = nearestParagraphRunStyleContext(change.live.paragraph, liveStyleResolver);
|
|
228
226
|
const formattingMarks = reconcileRunFormattingMarks({
|
|
229
227
|
authoredFormatting: change.formatting,
|
|
230
228
|
context,
|
|
@@ -321,11 +319,9 @@ const sameAuthoredInlineProvenance = (baseSnapshot, targetSnapshot) => {
|
|
|
321
319
|
const baseStyleResolver = styleResolverOf(baseSnapshot);
|
|
322
320
|
const targetStyleResolver = styleResolverOf(targetSnapshot);
|
|
323
321
|
return matched.every(({ live, target }) => hyperlinkIdentity(live.node) === hyperlinkIdentity(target.node) && canonicalJson(authoredFormattingAt({
|
|
324
|
-
doc: baseDocument,
|
|
325
322
|
representation: live,
|
|
326
323
|
styleResolver: baseStyleResolver
|
|
327
324
|
})) === canonicalJson(authoredFormattingAt({
|
|
328
|
-
doc: targetDocument,
|
|
329
325
|
representation: target,
|
|
330
326
|
styleResolver: targetStyleResolver
|
|
331
327
|
})));
|
package/dist/compare/plan.js
CHANGED
|
@@ -223,6 +223,7 @@ const shareAContainer = (left, right) => {
|
|
|
223
223
|
/** Narrow the neutral patch to the operation contract without explicit undefined fields. */
|
|
224
224
|
const toFolioAIBlockParagraphProperties = (properties) => ({
|
|
225
225
|
...properties.styleId !== void 0 && { styleId: properties.styleId },
|
|
226
|
+
...properties.outlineLevel !== void 0 && { outlineLevel: properties.outlineLevel },
|
|
226
227
|
...properties.listLevel !== void 0 && { listLevel: properties.listLevel },
|
|
227
228
|
...properties.listReference !== void 0 && { numbering: properties.listReference },
|
|
228
229
|
...properties.alignment !== void 0 && { alignment: properties.alignment },
|
|
@@ -594,18 +595,22 @@ const planStoryCompare = ({ story, baseSnapshot, targetSnapshot, maxOperations,
|
|
|
594
595
|
const moveSourceId = moveSourceByTargetBlockId.get(block.id);
|
|
595
596
|
const structuralBoundary = block.structuralBoundaries?.at(0);
|
|
596
597
|
const hardPageBreak = block.text.length === 0 && block.structuralBoundaries?.length === 1 && structuralBoundary?.type === "pageBreak" && structuralBoundary.offset === 0 ? { ...structuralBoundary.clear !== void 0 && { clear: structuralBoundary.clear } } : void 0;
|
|
597
|
-
const
|
|
598
|
-
text: block.text,
|
|
599
|
-
...(block.text.includes(" ") || block.text.includes("\n")) && { lineBreakMode: "inline" },
|
|
600
|
-
...moveSourceId !== void 0 && { moveId: moveIdOf(moveSourceId) },
|
|
601
|
-
...hardPageBreak !== void 0 && { hardPageBreak },
|
|
598
|
+
const paragraphProperties = {
|
|
602
599
|
styleId: block.styleId ?? null,
|
|
600
|
+
outlineLevel: block.directOutlineLevel ?? null,
|
|
603
601
|
listLevel: block.listLevel ?? null,
|
|
604
602
|
numbering: block.listReference ?? null,
|
|
605
603
|
alignment: block.directAlignment ?? null,
|
|
606
604
|
spacing: block.directSpacing ?? null,
|
|
607
605
|
indentation: block.directIndentation ?? null
|
|
608
606
|
};
|
|
607
|
+
const shared = {
|
|
608
|
+
text: block.text,
|
|
609
|
+
...(block.text.includes(" ") || block.text.includes("\n")) && { lineBreakMode: "inline" },
|
|
610
|
+
...moveSourceId !== void 0 && { moveId: moveIdOf(moveSourceId) },
|
|
611
|
+
...hardPageBreak !== void 0 && { hardPageBreak },
|
|
612
|
+
...paragraphProperties
|
|
613
|
+
};
|
|
609
614
|
if (anchorId !== null) {
|
|
610
615
|
operations.push({
|
|
611
616
|
id: nextOperationId(),
|
package/dist/compare/scenario.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FolioDocxReviewer } from "../ai-edits/headless.js";
|
|
2
2
|
import { createFolioAITextRangeHandle } from "../ai-edits/snapshot.js";
|
|
3
|
+
import "../document-operations.js";
|
|
3
4
|
import { CompareDocxParseError, compareDocxSerializeError } from "./types.js";
|
|
4
5
|
import { Result, panic } from "better-result";
|
|
5
6
|
//#region src/compare/scenario.ts
|
|
@@ -234,14 +235,24 @@ const applyEditScript = async (base, script) => {
|
|
|
234
235
|
operations: plan.operations
|
|
235
236
|
});
|
|
236
237
|
}
|
|
237
|
-
const { skipped } = reviewer.
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
const { skipped } = reviewer.applyDocumentOperationsToStory({
|
|
239
|
+
story: { type: "main" },
|
|
240
|
+
batch: {
|
|
241
|
+
version: 1,
|
|
242
|
+
mode: "direct",
|
|
243
|
+
operations: planned.flatMap(({ operations }) => [...operations])
|
|
244
|
+
},
|
|
245
|
+
snapshot,
|
|
246
|
+
undefinedStyles: "keep"
|
|
240
247
|
});
|
|
241
248
|
const skippedIds = new Set(skipped.map(({ id }) => id));
|
|
242
249
|
const applied = [];
|
|
243
250
|
for (const { step, operations } of planned) {
|
|
244
251
|
if (operations.some(({ id }) => skippedIds.has(id))) {
|
|
252
|
+
if (!operations.every(({ id }) => skippedIds.has(id))) panic("An edit script step was applied in part", {
|
|
253
|
+
step,
|
|
254
|
+
skipped
|
|
255
|
+
});
|
|
245
256
|
unresolved.push({
|
|
246
257
|
step,
|
|
247
258
|
reason: "refused"
|
|
@@ -12,7 +12,7 @@ const boundaryChildrenOf = (document) => {
|
|
|
12
12
|
let hasChangeHistory = false;
|
|
13
13
|
document.forEach((node, position) => {
|
|
14
14
|
if (node.type.name !== "paragraph") {
|
|
15
|
-
if (node.type.name === "preservedBlock") return;
|
|
15
|
+
if (node.type.name === "preservedBlock" || node.type.name === "blockBookmarkBoundary") return;
|
|
16
16
|
children.push({
|
|
17
17
|
type: "other",
|
|
18
18
|
nodeType: node.type.name
|
|
@@ -108,9 +108,22 @@ const boundaryParagraphEntriesOf = (document) => {
|
|
|
108
108
|
if (!children) return null;
|
|
109
109
|
return children.flatMap((child) => child.type === "paragraph" ? [child.paragraph] : []);
|
|
110
110
|
};
|
|
111
|
+
const hasSectionEndpoint = (document) => {
|
|
112
|
+
let found = false;
|
|
113
|
+
document.forEach((node) => {
|
|
114
|
+
if (node.type.name === "paragraph" && expectParagraphAttrs(node)._sectionProperties !== void 0) found = true;
|
|
115
|
+
});
|
|
116
|
+
return found;
|
|
117
|
+
};
|
|
111
118
|
/** Stage section deltas after document operations, against the accepted projection. */
|
|
112
119
|
const stageSectionBoundaryProperties = ({ state, target, originalRevisionIdSeed, revisionStamp, author, maxRanges, mapTargetProperties }) => {
|
|
113
120
|
if (!Number.isSafeInteger(maxRanges) || maxRanges < 0) return { status: "budget-exceeded" };
|
|
121
|
+
if (!hasSectionEndpoint(target)) return {
|
|
122
|
+
status: "matched",
|
|
123
|
+
transaction: state.tr,
|
|
124
|
+
nextRevisionId: revisionStamp.idSeed,
|
|
125
|
+
rangeCount: 0
|
|
126
|
+
};
|
|
114
127
|
const reviewedState = resolveAllChangesInHeadlessStateWithMapping(state, "accept");
|
|
115
128
|
const reviewed = boundaryParagraphEntriesOf(reviewedState.state.doc);
|
|
116
129
|
const targets = boundaryParagraphEntriesOf(target);
|
package/dist/compare/types.d.ts
CHANGED
|
@@ -25,7 +25,9 @@ type CompareDocxOptions = {
|
|
|
25
25
|
* redline that reads plausibly and is wrong is worse than no redline.
|
|
26
26
|
* `"emit"` returns the redline anyway, with `verification` naming every
|
|
27
27
|
* invariant that did not hold, for a caller that would rather show its best
|
|
28
|
-
* attempt and say what is missing.
|
|
28
|
+
* attempt and say what is missing. A reference to a note the base document
|
|
29
|
+
* does not have is refused either way: the redline would carry its marker
|
|
30
|
+
* as text that reads like a reference.
|
|
29
31
|
*/
|
|
30
32
|
onUnverified?: "refuse" | "emit";
|
|
31
33
|
/**
|
|
@@ -222,7 +224,7 @@ type CompareChange = {
|
|
|
222
224
|
baseBlockIds: readonly string[];
|
|
223
225
|
};
|
|
224
226
|
/** Why a part of the package is absent from `changes`. */
|
|
225
|
-
declare const COMPARE_UNSUPPORTED_REASONS: readonly ["story-missing-in-base", "story-missing-in-target", "story-not-editable"];
|
|
227
|
+
declare const COMPARE_UNSUPPORTED_REASONS: readonly ["story-missing-in-base", "story-missing-in-target", "story-not-editable", "unsupported-content"];
|
|
226
228
|
type CompareUnsupportedReason = (typeof COMPARE_UNSUPPORTED_REASONS)[number];
|
|
227
229
|
/**
|
|
228
230
|
* A package part the comparison did not cover. Reported rather than dropped so
|
package/dist/compare/types.js
CHANGED
|
@@ -10,7 +10,8 @@ const COMPARE_REVISION_FORMATS = ["word", "folio-exact"];
|
|
|
10
10
|
const COMPARE_UNSUPPORTED_REASONS = Object.freeze([
|
|
11
11
|
"story-missing-in-base",
|
|
12
12
|
"story-missing-in-target",
|
|
13
|
-
"story-not-editable"
|
|
13
|
+
"story-not-editable",
|
|
14
|
+
"unsupported-content"
|
|
14
15
|
]);
|
|
15
16
|
var InvalidCompareDocxOptionsError = class extends TaggedError("InvalidCompareDocxOptionsError") {};
|
|
16
17
|
var CompareDocxParseError = class extends TaggedError("CompareDocxParseError") {};
|
|
@@ -33,7 +33,7 @@ type CompareVerification = {
|
|
|
33
33
|
status: "unverified";
|
|
34
34
|
failures: readonly CompareVerificationFailure[];
|
|
35
35
|
};
|
|
36
|
-
type ProjectedBlock = Pick<FolioAIBlock, "text" | "table" | "styleId" | "listLevel" | "listReference" | "directAlignment" | "directSpacing" | "directIndentation" | "structuralBoundaries">;
|
|
36
|
+
type ProjectedBlock = Pick<FolioAIBlock, "kind" | "headingLevel" | "text" | "table" | "styleId" | "directOutlineLevel" | "listLevel" | "listReference" | "directAlignment" | "directSpacing" | "directIndentation" | "structuralBoundaries">;
|
|
37
37
|
type ClassifyOptions<T> = {
|
|
38
38
|
invariant: CompareVerificationInvariant;
|
|
39
39
|
story: FolioDocumentStoryHandle;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { paragraphIndentationEqual } from "../prosemirror/paragraphIndentation.js";
|
|
2
2
|
import { paragraphSpacingEqual } from "../prosemirror/paragraphSpacing.js";
|
|
3
|
+
import { sameFolioContentOutlineLevel } from "./content.js";
|
|
3
4
|
import { PARAGRAPH_MARK_CHANGE_KINDS } from "@stll/docx-core/model";
|
|
4
5
|
//#region src/compare/verification.ts
|
|
5
6
|
/**
|
|
@@ -8,10 +9,15 @@ import { PARAGRAPH_MARK_CHANGE_KINDS } from "@stll/docx-core/model";
|
|
|
8
9
|
* The check compares two block projections: what accepting the generated
|
|
9
10
|
* revisions leaves against the target, and what rejecting them leaves against
|
|
10
11
|
* the base. A projection carries each block's container, style, list level,
|
|
11
|
-
* direct alignment, spacing, indentation and text, so WHICH field diverged names
|
|
12
|
+
* direct outline level, alignment, spacing, indentation and text, so WHICH field diverged names
|
|
12
13
|
* which part of the pipeline lost the difference — and that is worth reporting
|
|
13
14
|
* as a typed cause rather than as one opaque "did not reproduce".
|
|
14
15
|
*
|
|
16
|
+
* It also carries what a reader sees those properties add up to: the block's
|
|
17
|
+
* kind and heading level. The stated properties are what an operation writes,
|
|
18
|
+
* so a projection of them alone checks the applier against its own vocabulary;
|
|
19
|
+
* the resolved classification is checked independently of how it was reached.
|
|
20
|
+
*
|
|
15
21
|
* Every `detail` string here is structural: counts, offsets, container kinds.
|
|
16
22
|
* Never a phrase of either document, because a caller may log it, put it in a
|
|
17
23
|
* report, or quote it in a review.
|
|
@@ -51,11 +57,15 @@ const sameStructuralBoundaries = (left, right) => {
|
|
|
51
57
|
for (let index = 0; index < leftLength; index++) {
|
|
52
58
|
const boundary = left[index];
|
|
53
59
|
const other = right[index];
|
|
54
|
-
if (boundary === void 0 || other === void 0 || boundary.
|
|
60
|
+
if (boundary === void 0 || other === void 0 || boundary.offset !== other.offset) return false;
|
|
61
|
+
if (boundary.type === "pageBreak") {
|
|
62
|
+
if (other.type !== "pageBreak" || boundary.clear !== other.clear) return false;
|
|
63
|
+
} else if (other.type !== "noteReference" || boundary.noteType !== other.noteType || boundary.length !== other.length) return false;
|
|
55
64
|
}
|
|
56
65
|
return true;
|
|
57
66
|
};
|
|
58
|
-
const
|
|
67
|
+
const sameClassification = (left, right) => left.kind === right.kind && left.headingLevel === right.headingLevel;
|
|
68
|
+
const sameProjectedBlock = (left, right) => sameContainer(left.table, right.table) && sameClassification(left, right) && sameStructuralBoundaries(left.structuralBoundaries, right.structuralBoundaries) && left.styleId === right.styleId && sameFolioContentOutlineLevel(left.directOutlineLevel, right.directOutlineLevel) && left.listLevel === right.listLevel && left.listReference?.numId === right.listReference?.numId && left.listReference?.level === right.listReference?.level && left.directAlignment === right.directAlignment && paragraphSpacingEqual(left.directSpacing, right.directSpacing) && paragraphIndentationEqual(left.directIndentation, right.directIndentation) && left.text === right.text;
|
|
59
69
|
const containerKind = (container) => container ? "cell" : "body";
|
|
60
70
|
const collapseWhitespace = (text) => text.replace(/\s+/gu, " ").trim();
|
|
61
71
|
const sameBlockProjection = (left, right) => left.length === right.length && left.every((entry, index) => {
|
|
@@ -172,8 +182,10 @@ const classifyProjectionMismatch = ({ invariant, story, actual, expected }) => {
|
|
|
172
182
|
if (!sameContainer(left.table, right.table)) return failure("container", `a block sits in a ${containerKind(left.table)} where it is expected in a ${containerKind(right.table)}, ${at} (${counts})`);
|
|
173
183
|
if (!sameStructuralBoundaries(left.structuralBoundaries, right.structuralBoundaries)) return failure("inline-structure", `a block's zero-width inline structure does not match ${at} (${counts})`);
|
|
174
184
|
if (left.text === right.text && left.styleId !== right.styleId) return failure("style", `the paragraph style did not move ${at} (${counts})`);
|
|
185
|
+
if (left.text === right.text && !sameFolioContentOutlineLevel(left.directOutlineLevel, right.directOutlineLevel)) return failure("style", `the direct outline level did not move ${at} (${counts})`);
|
|
175
186
|
if (left.text === right.text && left.listLevel !== right.listLevel) return failure("list-level", `the list level did not move ${at} (${counts})`);
|
|
176
187
|
if (left.text === right.text && (left.listReference?.numId !== right.listReference?.numId || left.listReference?.level !== right.listReference?.level)) return failure("list-level", `the numbering reference did not move ${at} (${counts})`);
|
|
188
|
+
if (left.text === right.text && !sameClassification(left, right)) return left.kind === "heading" || right.kind === "heading" ? failure("style", `the heading classification did not move ${at} (${counts})`) : failure("list-level", `the list membership did not move ${at} (${counts})`);
|
|
177
189
|
if (left.text === right.text && left.directAlignment !== right.directAlignment) return failure("alignment", `the direct paragraph alignment did not move ${at} (${counts})`);
|
|
178
190
|
if (left.text === right.text && !paragraphSpacingEqual(left.directSpacing, right.directSpacing)) return failure("spacing", `the direct paragraph spacing did not move ${at} (${counts})`);
|
|
179
191
|
if (left.text === right.text && !paragraphIndentationEqual(left.directIndentation, right.directIndentation)) return failure("indentation", `the direct paragraph indentation did not move ${at} (${counts})`);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DirtyRange } from "../paged-layout/incrementalMeasure.js";
|
|
2
|
+
import { LayoutTemplatePreview } from "./layoutSession.js";
|
|
3
|
+
import { Node } from "prosemirror-model";
|
|
4
|
+
//#region src/controller/committedLayoutDiff.d.ts
|
|
5
|
+
type LayoutFlowSource = {
|
|
6
|
+
doc: Node;
|
|
7
|
+
preview: LayoutTemplatePreview;
|
|
8
|
+
};
|
|
9
|
+
type CommittedLayoutDiff = {
|
|
10
|
+
type: "full";
|
|
11
|
+
} | {
|
|
12
|
+
type: "range";
|
|
13
|
+
/** In the next document's positions. */
|
|
14
|
+
range: DirtyRange;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The span of `next` whose flow blocks may differ from the ones the committed
|
|
18
|
+
* layout measured for `committed`, or `full` when no span bounds it.
|
|
19
|
+
*
|
|
20
|
+
* `full` also covers "nothing in the body flow changed": such a pass was
|
|
21
|
+
* requested for an input outside it (a header, footer or note story).
|
|
22
|
+
*/
|
|
23
|
+
declare const diffAgainstCommittedLayout: (committed: LayoutFlowSource, next: LayoutFlowSource) => CommittedLayoutDiff;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { CommittedLayoutDiff, LayoutFlowSource, diffAgainstCommittedLayout };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { templatePreviewDirtyRange } from "../layout-bridge/convert/templatePreviewFlow.js";
|
|
2
|
+
//#region src/controller/committedLayoutDiff.ts
|
|
3
|
+
const FULL = { type: "full" };
|
|
4
|
+
const diffDocuments = (before, after) => {
|
|
5
|
+
const start = before.content.findDiffStart(after.content);
|
|
6
|
+
if (start === null) return null;
|
|
7
|
+
const end = before.content.findDiffEnd(after.content);
|
|
8
|
+
if (end === null) return null;
|
|
9
|
+
const overlap = start - Math.min(end.a, end.b);
|
|
10
|
+
return overlap > 0 ? {
|
|
11
|
+
start,
|
|
12
|
+
endBefore: end.a + overlap,
|
|
13
|
+
endAfter: end.b + overlap
|
|
14
|
+
} : {
|
|
15
|
+
start,
|
|
16
|
+
endBefore: end.a,
|
|
17
|
+
endAfter: end.b
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/** Map a range of the previous document into the next one's positions. */
|
|
21
|
+
const mapRangeThroughDiff = (range, diff) => {
|
|
22
|
+
const shift = diff.endAfter - diff.endBefore;
|
|
23
|
+
const mapPosition = (pos, insideChange) => {
|
|
24
|
+
if (pos < diff.start) return pos;
|
|
25
|
+
if (pos >= diff.endBefore) return pos + shift;
|
|
26
|
+
return insideChange;
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
...range,
|
|
30
|
+
from: mapPosition(range.from, diff.start),
|
|
31
|
+
to: mapPosition(range.to, diff.endAfter)
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
const mapPreviewThroughDiff = (preview, diff) => ({
|
|
35
|
+
entries: preview.entries.map((entry) => mapRangeThroughDiff(entry, diff)),
|
|
36
|
+
hidden: preview.hidden.map((range) => mapRangeThroughDiff(range, diff))
|
|
37
|
+
});
|
|
38
|
+
const unionRanges = (first, second) => {
|
|
39
|
+
if (!first) return second;
|
|
40
|
+
if (!second) return first;
|
|
41
|
+
return {
|
|
42
|
+
from: Math.min(first.from, second.from),
|
|
43
|
+
to: Math.max(first.to, second.to)
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The span of `next` whose flow blocks may differ from the ones the committed
|
|
48
|
+
* layout measured for `committed`, or `full` when no span bounds it.
|
|
49
|
+
*
|
|
50
|
+
* `full` also covers "nothing in the body flow changed": such a pass was
|
|
51
|
+
* requested for an input outside it (a header, footer or note story).
|
|
52
|
+
*/
|
|
53
|
+
const diffAgainstCommittedLayout = (committed, next) => {
|
|
54
|
+
if (committed.preview.mode !== next.preview.mode) return FULL;
|
|
55
|
+
if (!committed.doc.sameMarkup(next.doc)) return FULL;
|
|
56
|
+
const docDiff = diffDocuments(committed.doc, next.doc);
|
|
57
|
+
let range = docDiff ? {
|
|
58
|
+
from: docDiff.start,
|
|
59
|
+
to: docDiff.endAfter
|
|
60
|
+
} : null;
|
|
61
|
+
if (committed.preview.entries !== next.preview.entries || committed.preview.hidden !== next.preview.hidden) {
|
|
62
|
+
const previousPreview = docDiff ? mapPreviewThroughDiff(committed.preview, docDiff) : committed.preview;
|
|
63
|
+
range = unionRanges(range, templatePreviewDirtyRange(previousPreview, next.preview));
|
|
64
|
+
}
|
|
65
|
+
return range ? {
|
|
66
|
+
type: "range",
|
|
67
|
+
range
|
|
68
|
+
} : FULL;
|
|
69
|
+
};
|
|
70
|
+
//#endregion
|
|
71
|
+
export { diffAgainstCommittedLayout };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ContentControlWidgetEvent } from "../prosemirror/plugins/contentControlWidgets.js";
|
|
2
1
|
import { Subscribable } from "../managers/Subscribable.js";
|
|
2
|
+
import { ContentControlWidgetEvent } from "../prosemirror/plugins/contentControlWidgets.js";
|
|
3
3
|
import { EditorView } from "prosemirror-view";
|
|
4
4
|
//#region src/controller/contentControlWidgetController.d.ts
|
|
5
5
|
type ContentControlListItem = {
|
|
@@ -3,7 +3,7 @@ import { DocxInput } from "../utils/docxInput.js";
|
|
|
3
3
|
import { Layout } from "../layout-engine/types.js";
|
|
4
4
|
import { HiddenEditorApi } from "./hiddenEditorApi.js";
|
|
5
5
|
import { FolioEditorEmitter } from "./folioEditorEvents.js";
|
|
6
|
-
import { LayoutRunOptions } from "./
|
|
6
|
+
import { LayoutRunOptions } from "./layoutRunOptions.js";
|
|
7
7
|
import { EditorState } from "prosemirror-state";
|
|
8
8
|
//#region src/controller/folioEditor.d.ts
|
|
9
9
|
type FolioEditorDeps = {
|
|
@@ -1,8 +1,58 @@
|
|
|
1
1
|
import { document_d_exports } from "../types/document.js";
|
|
2
2
|
import { EditorState } from "prosemirror-state";
|
|
3
3
|
//#region src/controller/fontReadiness.d.ts
|
|
4
|
+
/** The parts of a `FontFace` layout readiness reads. */
|
|
5
|
+
type LayoutFontSetFace = Pick<FontFace, "family" | "status">;
|
|
6
|
+
type LayoutFontSetListener = (event: {
|
|
7
|
+
fontfaces: readonly LayoutFontSetFace[];
|
|
8
|
+
}) => void;
|
|
9
|
+
/**
|
|
10
|
+
* The parts of a `FontFaceSet` layout readiness uses; `document.fonts` in a
|
|
11
|
+
* browser, a scripted stand-in in tests.
|
|
12
|
+
*/
|
|
13
|
+
type LayoutFontSet = Iterable<LayoutFontSetFace> & {
|
|
14
|
+
load: (font: string, text?: string) => Promise<unknown>;
|
|
15
|
+
readonly ready: Promise<unknown>;
|
|
16
|
+
addEventListener: (type: "loadingdone", listener: LayoutFontSetListener) => void;
|
|
17
|
+
removeEventListener: (type: "loadingdone", listener: LayoutFontSetListener) => void;
|
|
18
|
+
};
|
|
4
19
|
declare function getDocumentFontSet(): FontFaceSet | null;
|
|
5
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Names the faces available to measurement: which faces of the families
|
|
22
|
+
* measured stacks name have loaded. Equal signatures mean every measured glyph
|
|
23
|
+
* resolves to the same face, so a measurement taken under one is valid under
|
|
24
|
+
* the other; a host UI face loading leaves it unchanged.
|
|
25
|
+
*
|
|
26
|
+
* Counted over loaded faces only (a face never unloads, and a failed one adds
|
|
27
|
+
* no glyphs) with a per-face identity sum, so a removal replaced by an addition
|
|
28
|
+
* still changes it: a new face's id exceeds every earlier one. The family set
|
|
29
|
+
* only grows, and a family joins it when first measured, so read it after
|
|
30
|
+
* measuring to name what a layout measured in. Without a font set (a server or
|
|
31
|
+
* headless host) there is nothing to load and the signature is constant.
|
|
32
|
+
*/
|
|
33
|
+
declare function readFontSetSignature(fontSet?: LayoutFontSet | null): string;
|
|
34
|
+
type WatchLayoutFontLoadsOptions = {
|
|
35
|
+
/**
|
|
36
|
+
* The font-set signature the committed layout was measured in, or `null`
|
|
37
|
+
* before one is committed (the first layout measures whatever has loaded).
|
|
38
|
+
*/
|
|
39
|
+
measuredFontSet: () => string | null;
|
|
40
|
+
relayout: () => void;
|
|
41
|
+
fontSet?: LayoutFontSet | null;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Re-run layout whenever a face that can change a measured width finishes
|
|
45
|
+
* loading after the committed layout measured without it.
|
|
46
|
+
*
|
|
47
|
+
* Tied to what loaded, never to a time window: fontsource splits each face
|
|
48
|
+
* into `unicode-range` subsets the browser fetches when painted text first
|
|
49
|
+
* needs them, so a subset can land at any moment after the first layout. A
|
|
50
|
+
* load the committed layout already saw (its event can arrive after the layout
|
|
51
|
+
* ran) leaves the signature unchanged and relays nothing, as does a face of a
|
|
52
|
+
* family no measured stack names (a host UI font). Returns the unsubscribe
|
|
53
|
+
* function.
|
|
54
|
+
*/
|
|
55
|
+
declare function watchLayoutFontLoads({ measuredFontSet, relayout, fontSet }: WatchLayoutFontLoadsOptions): () => void;
|
|
6
56
|
declare const LAYOUT_FONT_DESCRIPTORS: readonly [{
|
|
7
57
|
readonly style: "normal";
|
|
8
58
|
readonly weight: 400;
|
|
@@ -21,8 +71,25 @@ type LayoutFontFace = {
|
|
|
21
71
|
style: (typeof LAYOUT_FONT_DESCRIPTORS)[number]["style"];
|
|
22
72
|
weight: (typeof LAYOUT_FONT_DESCRIPTORS)[number]["weight"];
|
|
23
73
|
};
|
|
24
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Resolve once every face the first layout will measure has loaded (`true`),
|
|
76
|
+
* or after a timeout (`false`), so the first layout does not measure fallbacks.
|
|
77
|
+
*
|
|
78
|
+
* Each face is loaded for the document's own characters. A bundled face is a
|
|
79
|
+
* set of `unicode-range` subsets, and `FontFaceSet.load` fetches only the
|
|
80
|
+
* subsets covering the text it is given; without text it takes a single space
|
|
81
|
+
* and loads only the Latin subset, so Czech, Polish, Greek and Cyrillic were
|
|
82
|
+
* measured in a fallback.
|
|
83
|
+
*/
|
|
84
|
+
declare function waitForInitialLayoutFonts(documentModel: document_d_exports.Document | null, pmDoc: EditorState["doc"], fontSet?: LayoutFontSet | null): Promise<boolean>;
|
|
85
|
+
/**
|
|
86
|
+
* Every distinct character the layout will measure, as one string: the body
|
|
87
|
+
* text (tracked deletions included, since All Markup paints them), list
|
|
88
|
+
* markers, headers, footers and notes. Always carries a space, which every
|
|
89
|
+
* line measures.
|
|
90
|
+
*/
|
|
91
|
+
declare function collectLayoutText(documentModel: document_d_exports.Document | null, pmDoc: EditorState["doc"]): string;
|
|
25
92
|
declare function collectInitialLayoutFontFamilies(documentModel: document_d_exports.Document | null, pmDoc: EditorState["doc"]): Set<string>;
|
|
26
93
|
declare function collectInitialLayoutFontFaces(documentModel: document_d_exports.Document | null, pmDoc: EditorState["doc"]): LayoutFontFace[];
|
|
27
94
|
//#endregion
|
|
28
|
-
export { LayoutFontFace, collectInitialLayoutFontFaces, collectInitialLayoutFontFamilies,
|
|
95
|
+
export { LayoutFontFace, LayoutFontSet, LayoutFontSetFace, WatchLayoutFontLoadsOptions, collectInitialLayoutFontFaces, collectInitialLayoutFontFamilies, collectLayoutText, getDocumentFontSet, readFontSetSignature, waitForInitialLayoutFonts, watchLayoutFontLoads };
|