@stll/folio-core 0.67.0 → 0.68.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai-edits/apply.d.ts +9 -1
- package/dist/ai-edits/apply.js +94 -8
- package/dist/ai-edits/headless.d.ts +36 -21
- package/dist/ai-edits/headless.js +104 -34
- package/dist/ai-edits/index.d.ts +2 -2
- package/dist/ai-edits/note-references.d.ts +6 -0
- package/dist/ai-edits/note-references.js +7 -1
- package/dist/ai-edits/read.d.ts +19 -0
- package/dist/ai-edits/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 +29 -12
- package/dist/controller/canonicalComposition.js +1 -1
- 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 +28 -1
- package/dist/controller/canonicalListRendering.d.ts +2 -1
- package/dist/controller/canonicalListRendering.js +1 -1
- package/dist/controller/canonicalLockGuard.d.ts +8 -0
- package/dist/controller/canonicalLockGuard.js +88 -0
- package/dist/controller/canonicalPublicOperations.d.ts +12 -4
- package/dist/controller/canonicalPublicOperations.js +274 -20
- package/dist/controller/canonicalSession.d.ts +87 -7
- package/dist/controller/canonicalSession.js +327 -73
- package/dist/controller/canonicalStoryEditor.d.ts +3 -2
- package/dist/controller/canonicalStoryEditor.js +4 -3
- package/dist/controller/canonicalStructure.d.ts +2 -1
- package/dist/controller/canonicalStructure.js +129 -7
- package/dist/controller/contentControlWidgetController.d.ts +5 -0
- package/dist/controller/contentControlWidgetController.js +13 -1
- package/dist/controller/folioEditor.js +1 -0
- package/dist/controller/headerFooterEditorManager.d.ts +2 -2
- package/dist/controller/headerFooterEditorManager.js +5 -5
- package/dist/controller/hiddenEditorApi.d.ts +6 -0
- package/dist/controller/hiddenEditorApi.js +1 -0
- package/dist/controller/hiddenEditorManager.d.ts +4 -3
- package/dist/controller/hiddenEditorManager.js +91 -37
- package/dist/controller/layoutPipeline.js +48 -15
- package/dist/controller/noteEditorManager.d.ts +2 -2
- package/dist/controller/noteEditorManager.js +5 -5
- package/dist/display-list/build/pageFurniture.js +41 -19
- package/dist/display-list/build/tablePrimitives.js +23 -4
- package/dist/display-list/dom/renderDisplayListToDom.js +4 -4
- package/dist/document-operations.d.ts +8 -0
- package/dist/document-operations.js +4 -3
- package/dist/docx/blockContentParser.d.ts +7 -3
- package/dist/docx/blockContentParser.js +2 -3
- package/dist/docx/blockPlainText.js +2 -0
- package/dist/docx/bookmarkRangeJoin.d.ts +6 -0
- package/dist/docx/bookmarkRangeJoin.js +43 -0
- package/dist/docx/canonicalSave.js +5 -1
- package/dist/docx/canonicalSessionInput.d.ts +5 -1
- package/dist/docx/canonicalSessionInput.js +7 -2
- package/dist/docx/commentAnchorIndex.d.ts +21 -5
- package/dist/docx/commentAnchorIndex.js +39 -11
- package/dist/docx/commentRangeIntegrity.js +30 -24
- package/dist/docx/commentRangeJoin.d.ts +4 -0
- package/dist/docx/commentRangeJoin.js +26 -12
- package/dist/docx/commentReferenceCompletion.js +5 -4
- package/dist/docx/commentReferenceNormalization.js +40 -18
- package/dist/docx/compatibility.js +9 -2
- package/dist/docx/containerChildren.js +22 -1
- package/dist/docx/encryption/compoundFile.js +9 -1
- package/dist/docx/encryption/encryptionInfo.js +16 -2
- package/dist/docx/ensureParaIds.js +46 -7
- package/dist/docx/ensureUniqueControlIds.d.ts +25 -0
- package/dist/docx/ensureUniqueControlIds.js +110 -0
- package/dist/docx/headerFooterVerbatim.d.ts +7 -0
- package/dist/docx/headerFooterVerbatim.js +13 -2
- package/dist/docx/hostCommentThreads.d.ts +17 -0
- package/dist/docx/hostCommentThreads.js +49 -0
- package/dist/docx/hyperlinkParser.js +9 -2
- package/dist/docx/inlineWrapperContent.d.ts +8 -1
- package/dist/docx/inlineWrapperContent.js +9 -2
- package/dist/docx/listMarkerComputation.d.ts +35 -1
- package/dist/docx/listMarkerComputation.js +39 -1
- package/dist/docx/listModelNormalization.d.ts +44 -1
- package/dist/docx/listModelNormalization.js +227 -96
- package/dist/docx/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/paragraphParser.js +159 -48
- package/dist/docx/paragraphPropertySource.d.ts +7 -0
- package/dist/docx/paragraphPropertySource.js +22 -1
- package/dist/docx/paragraphTextBoxEnrichment.js +2 -1
- package/dist/docx/paragraphTraversal.js +2 -0
- package/dist/docx/parseWarningMessage.js +2 -1
- package/dist/docx/parser.js +6 -0
- package/dist/docx/renderedPageBreakNormalization.js +1 -1
- package/dist/docx/reviewProvenanceDiagnostics.d.ts +7 -0
- package/dist/docx/reviewProvenanceDiagnostics.js +39 -0
- package/dist/docx/reviewResolutionProvenance.d.ts +29 -3
- package/dist/docx/reviewResolutionProvenance.js +110 -25
- package/dist/docx/rezip.d.ts +6 -0
- package/dist/docx/rezip.js +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 +3 -1
- package/dist/docx/serializer/headerFooterSerializer.js +3 -1
- package/dist/docx/serializer/markupRangeAttributes.d.ts +6 -1
- package/dist/docx/serializer/markupRangeAttributes.js +6 -1
- package/dist/docx/serializer/noteSerializer.d.ts +17 -4
- package/dist/docx/serializer/noteSerializer.js +23 -16
- package/dist/docx/serializer/paragraphSerializer.js +56 -12
- package/dist/docx/serializer/runSerializer.d.ts +1 -3
- package/dist/docx/serializer/runSerializer.js +2 -2
- package/dist/docx/serializer/tableSerializer.d.ts +4 -0
- package/dist/docx/serializer/tableSerializer.js +4 -2
- package/dist/docx/server/applyDocxXmlPatchProposal.js +8 -4
- package/dist/docx/server/createBilingualDocument.js +27 -5
- package/dist/docx/server/migrateYjsAttrSchema.js +4 -0
- package/dist/docx/sessionListPruning.d.ts +2 -0
- package/dist/docx/sessionListPruning.js +50 -0
- package/dist/docx/splitRevisionPieces.d.ts +10 -0
- package/dist/docx/splitRevisionPieces.js +14 -0
- package/dist/docx/storyBlockReplay.js +4 -0
- package/dist/docx/structuralXmlPatch.js +19 -7
- package/dist/docx/tableParser.d.ts +6 -2
- package/dist/docx/tableParser.js +2 -3
- package/dist/docx/textBoxContentParser.d.ts +11 -0
- package/dist/docx/textBoxContentParser.js +51 -0
- package/dist/docx/textBoxParser.d.ts +0 -5
- package/dist/docx/textBoxParser.js +1 -23
- package/dist/docx/verticalMergeProjection.js +1 -1
- package/dist/fonts/fontsourceFaces.d.ts +2 -8
- package/dist/fonts/fontsourceFaces.js +1 -7
- package/dist/i18n/messages/ar.gen.js +2 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +34 -0
- package/dist/i18n/messages/catalogs.gen.js +34 -0
- package/dist/i18n/messages/cs.gen.js +2 -0
- package/dist/i18n/messages/de.gen.js +2 -0
- package/dist/i18n/messages/en.gen.js +2 -0
- package/dist/i18n/messages/es.gen.js +2 -0
- package/dist/i18n/messages/et.gen.js +2 -0
- package/dist/i18n/messages/fr.gen.js +2 -0
- package/dist/i18n/messages/he.gen.js +2 -0
- package/dist/i18n/messages/hi.gen.js +2 -0
- package/dist/i18n/messages/hu.gen.js +2 -0
- package/dist/i18n/messages/lt.gen.js +2 -0
- package/dist/i18n/messages/lv.gen.js +2 -0
- package/dist/i18n/messages/messages.gen.d.ts +2 -0
- package/dist/i18n/messages/pl.gen.js +2 -0
- package/dist/i18n/messages/pt-BR.gen.js +2 -0
- package/dist/i18n/messages/sk.gen.js +2 -0
- package/dist/i18n/messages/tr.gen.js +2 -0
- package/dist/i18n/messages/zh-CN.gen.js +2 -0
- package/dist/internal/acceptedBlockProjection.js +2 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +5 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
- package/dist/internal/revisionResolutionInline.js +1 -2
- package/dist/layout-bridge/convert/tableConversion.js +19 -8
- 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-engine/footnoteContinuation.d.ts +36 -0
- package/dist/layout-engine/footnoteContinuation.js +210 -0
- package/dist/layout-engine/index.d.ts +2 -2
- package/dist/layout-engine/index.js +7 -2
- package/dist/layout-engine/measure/cache.js +10 -5
- package/dist/layout-engine/measure/measureParagraph.js +1 -1
- package/dist/layout-engine/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 +36 -1
- package/dist/layout-painter/renderPage.d.ts +4 -4
- package/dist/layout-painter/renderPage.js +46 -17
- package/dist/layout-painter/renderTable.js +7 -4
- package/dist/managers/AutoSaveManager.d.ts +5 -1
- package/dist/managers/FindReplaceManager.js +3 -10
- package/dist/markdown/escape.d.ts +20 -1
- package/dist/markdown/escape.js +43 -1
- package/dist/markdown/renderBlock.js +4 -1
- package/dist/markdown/renderParagraph.js +13 -27
- package/dist/markdown/renderTable.js +6 -2
- package/dist/markdown/trailers.js +1 -0
- package/dist/pdf/images.d.ts +17 -1
- package/dist/pdf/images.js +22 -4
- package/dist/pdf/writePdf.js +4 -2
- package/dist/prosemirror/attrs/index.js +1 -0
- package/dist/prosemirror/canonicalCommands.d.ts +39 -1
- package/dist/prosemirror/canonicalTableCommands.d.ts +28 -0
- package/dist/prosemirror/canonicalTableCommands.js +362 -0
- package/dist/prosemirror/commands/comments.d.ts +25 -0
- package/dist/prosemirror/commands/comments.js +102 -11
- 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/commentReferenceIntegrity.js +3 -4
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
- package/dist/prosemirror/conversion/fromProseDoc.js +76 -31
- package/dist/prosemirror/conversion/index.d.ts +1 -1
- package/dist/prosemirror/conversion/toProseDoc.d.ts +128 -1
- package/dist/prosemirror/conversion/toProseDoc.js +319 -51
- 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 +1 -1
- package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
- package/dist/prosemirror/extensions/marks/CommentExtension.js +6 -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/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 +2 -2
- package/dist/prosemirror/listLabels.js +3 -2
- package/dist/prosemirror/listNumbering.d.ts +6 -0
- package/dist/prosemirror/listNumbering.js +12 -9
- package/dist/prosemirror/lockedControls.d.ts +13 -0
- package/dist/prosemirror/lockedControls.js +106 -0
- package/dist/prosemirror/markupViewProjection.js +1 -1
- package/dist/prosemirror/noteReferenceReview.js +2 -2
- package/dist/prosemirror/plugins/documentNumbering.js +4 -1
- package/dist/prosemirror/plugins/suggestionMode.js +20 -9
- 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/runPropertyChangeResolution.js +1 -2
- package/dist/prosemirror/runStyleFormatting.d.ts +14 -4
- package/dist/prosemirror/runStyleFormatting.js +16 -13
- package/dist/prosemirror/schema/marks.d.ts +6 -0
- package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
- package/dist/prosemirror/validation.js +1 -0
- package/dist/redline.js +23 -9
- package/dist/server.d.ts +2 -2
- package/dist/style-sets/extract.js +2 -2
- package/dist/types/canonicalCapabilities.d.ts +29 -8
- package/dist/types/canonicalCapabilities.js +13 -9
- package/dist/utils/cssString.d.ts +7 -0
- package/dist/utils/cssString.js +9 -0
- package/dist/utils/fontResolver.js +4 -1
- package/dist/utils/replaceText.d.ts +11 -0
- package/dist/utils/replaceText.js +39 -7
- package/dist/version-comparison.d.ts +9 -1
- package/dist/version-comparison.js +11 -5
- package/package.json +2 -2
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { decodeText } from "../utils/textEncoding.js";
|
|
2
2
|
import "./archiveInflation.js";
|
|
3
|
+
import { resolvePackageRelationshipTarget } from "./packageParts.js";
|
|
4
|
+
import { RELATIONSHIP_TYPES, parseRelationships } from "./relsParser.js";
|
|
3
5
|
import { elementToXml, getLocalName, parseXmlDocument } from "./xmlParser.js";
|
|
4
6
|
import { Result, TaggedError } from "better-result";
|
|
5
7
|
import { ZipArchive, ZipError } from "@stll/docx-core/zip";
|
|
@@ -81,13 +83,31 @@ const loadPrivacyArchive = async (buffer) => {
|
|
|
81
83
|
cause
|
|
82
84
|
});
|
|
83
85
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
return read.value;
|
|
87
|
+
};
|
|
88
|
+
const PACKAGE_RELATIONSHIPS_PATH = "_rels/.rels";
|
|
89
|
+
/**
|
|
90
|
+
* Every part that holds core properties: the one the package relationship
|
|
91
|
+
* selects, which is the one a package reader follows, and the conventional
|
|
92
|
+
* `docProps/core.xml`. Each is size-checked before it is read.
|
|
93
|
+
*/
|
|
94
|
+
const findCorePropertiesEntries = async (zip) => {
|
|
95
|
+
const paths = /* @__PURE__ */ new Set([CORE_PROPERTIES_PATH_LOWER]);
|
|
96
|
+
const packageRelationships = findZipEntryCaseInsensitive(zip, PACKAGE_RELATIONSHIPS_PATH);
|
|
97
|
+
if (packageRelationships) {
|
|
98
|
+
const relationships = parseRelationships(await readBoundedPart(packageRelationships));
|
|
99
|
+
for (const { type, target, targetMode } of relationships.values()) {
|
|
100
|
+
if (type !== RELATIONSHIP_TYPES.coreProperties || targetMode === "External") continue;
|
|
101
|
+
const path = resolvePackageRelationshipTarget(target, PACKAGE_RELATIONSHIPS_PATH);
|
|
102
|
+
if (path !== void 0) paths.add(path);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const entries = /* @__PURE__ */ new Map();
|
|
106
|
+
for (const path of paths) {
|
|
107
|
+
const entry = findZipEntryCaseInsensitive(zip, path);
|
|
108
|
+
if (entry) entries.set(entry.path, entry);
|
|
109
|
+
}
|
|
110
|
+
return [...entries.values()];
|
|
91
111
|
};
|
|
92
112
|
const rewriteCorePropertiesPrivacy = (xml, transforms) => {
|
|
93
113
|
const root = parseXmlDocument(xml);
|
|
@@ -112,10 +132,14 @@ const rewriteCorePropertiesPrivacy = (xml, transforms) => {
|
|
|
112
132
|
};
|
|
113
133
|
};
|
|
114
134
|
/**
|
|
115
|
-
* Read
|
|
116
|
-
*
|
|
135
|
+
* Read a core-properties or package-relationships part: its declared size is
|
|
136
|
+
* checked first, and inflation stops at that size.
|
|
117
137
|
*/
|
|
118
|
-
const
|
|
138
|
+
const readBoundedPart = async (entry) => {
|
|
139
|
+
if (entry.size > MAX_CORE_PROPERTIES_BYTES) throw new FolioDocumentPrivacyArchiveError({
|
|
140
|
+
message: "Document privacy core properties exceeded the part-size limit",
|
|
141
|
+
reason: "core-properties-too-large"
|
|
142
|
+
});
|
|
119
143
|
const read = await Result.tryPromise({
|
|
120
144
|
try: async () => await entry.bytes(),
|
|
121
145
|
catch: (cause) => cause
|
|
@@ -137,28 +161,25 @@ const readCoreProperties = async (entry) => {
|
|
|
137
161
|
const rewriteDocxMetadataPrivacy = async (buffer, { transforms }) => {
|
|
138
162
|
const appliedTransforms = resolveFolioDocumentPrivacyTransforms(transforms);
|
|
139
163
|
const zip = await loadPrivacyArchive(buffer);
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const rewritten = rewriteCorePropertiesPrivacy(await readCoreProperties(coreProperties), appliedTransforms);
|
|
149
|
-
if (rewritten.removedMetadataProperties.length === 0) return {
|
|
164
|
+
const removedPropertySet = /* @__PURE__ */ new Set();
|
|
165
|
+
for (const coreProperties of await findCorePropertiesEntries(zip)) {
|
|
166
|
+
const rewritten = rewriteCorePropertiesPrivacy(await readBoundedPart(coreProperties), appliedTransforms);
|
|
167
|
+
if (rewritten.removedMetadataProperties.length === 0) continue;
|
|
168
|
+
for (const property of rewritten.removedMetadataProperties) removedPropertySet.add(property);
|
|
169
|
+
zip.set(coreProperties.path, rewritten.xml);
|
|
170
|
+
}
|
|
171
|
+
if (removedPropertySet.size === 0) return {
|
|
150
172
|
buffer,
|
|
151
173
|
privacyReport: {
|
|
152
174
|
appliedTransforms,
|
|
153
175
|
removedMetadataProperties: []
|
|
154
176
|
}
|
|
155
177
|
};
|
|
156
|
-
zip.set(coreProperties.path, rewritten.xml);
|
|
157
178
|
return {
|
|
158
179
|
buffer: (await zip.generate()).buffer,
|
|
159
180
|
privacyReport: {
|
|
160
181
|
appliedTransforms,
|
|
161
|
-
removedMetadataProperties:
|
|
182
|
+
removedMetadataProperties: FOLIO_DOCUMENT_METADATA_PROPERTIES.filter((property) => removedPropertySet.has(property))
|
|
162
183
|
}
|
|
163
184
|
};
|
|
164
185
|
};
|
|
@@ -60,6 +60,8 @@ const normalizeCellBlock = (block, styles) => {
|
|
|
60
60
|
case "preservedBlock":
|
|
61
61
|
case "bookmarkStart":
|
|
62
62
|
case "bookmarkEnd":
|
|
63
|
+
case "commentRangeStart":
|
|
64
|
+
case "commentRangeEnd":
|
|
63
65
|
case "moveFromRangeStart":
|
|
64
66
|
case "moveFromRangeEnd":
|
|
65
67
|
case "moveToRangeStart":
|
|
@@ -70,7 +72,7 @@ const normalizeCellBlock = (block, styles) => {
|
|
|
70
72
|
const normalizeBlocks = (blocks, styles) => blocks.map((block) => {
|
|
71
73
|
if (block.type === "paragraph") return normalizeParagraph(block, styles);
|
|
72
74
|
if (block.type === "table") return normalizeTable(block, styles);
|
|
73
|
-
if (block.type === "preservedBlock" || block.type === "bookmarkStart" || block.type === "bookmarkEnd" || block.type === "moveFromRangeStart" || block.type === "moveFromRangeEnd" || block.type === "moveToRangeStart" || block.type === "moveToRangeEnd") return block;
|
|
75
|
+
if (block.type === "preservedBlock" || block.type === "bookmarkStart" || block.type === "bookmarkEnd" || block.type === "commentRangeStart" || block.type === "commentRangeEnd" || block.type === "moveFromRangeStart" || block.type === "moveFromRangeEnd" || block.type === "moveToRangeStart" || block.type === "moveToRangeEnd") return block;
|
|
74
76
|
return {
|
|
75
77
|
...block,
|
|
76
78
|
content: normalizeBlocks(block.content, styles)
|
|
@@ -21,12 +21,13 @@ import { assignParagraphPropertySource } from "./paragraphPropertySource.js";
|
|
|
21
21
|
import { preserveInlineChild, preserveRunChild, preservedInlineCapture } from "./preservedRunContent.js";
|
|
22
22
|
import { standalonePreviewLedger } from "./previewBudget.js";
|
|
23
23
|
import { FOLIO_REVIEW_HISTORY_NAMESPACE } from "./reviewHistoryNamespace.js";
|
|
24
|
-
import {
|
|
24
|
+
import { parseParagraphMarkResolutionJoin, parseResolutionJoins, parseSplitResolutionPiece } from "./reviewResolutionProvenance.js";
|
|
25
25
|
import { consolidateParagraphContent } from "./runConsolidator.js";
|
|
26
26
|
import { parseRun } from "./runParser.js";
|
|
27
27
|
import { runHoldsPayload } from "./runPayload.js";
|
|
28
28
|
import { captureSdtSiblingMarkers, parseSdtProperties } from "./sdtProperties.js";
|
|
29
29
|
import { parseSectionProperties } from "./sectionParser.js";
|
|
30
|
+
import { splitPieces, tagSplitPiece } from "./splitRevisionPieces.js";
|
|
30
31
|
import { hasAttributeAnySpelling } from "./strictNames.js";
|
|
31
32
|
import { scanRunForTextBoxDrawings } from "./textBoxParser.js";
|
|
32
33
|
import { parsePropertyChangeInfo, parseTrackedChangeInfo } from "./trackedChangeInfo.js";
|
|
@@ -232,7 +233,13 @@ function parseParagraphMarkChange(pPr) {
|
|
|
232
233
|
};
|
|
233
234
|
}
|
|
234
235
|
}
|
|
235
|
-
function pushTrackedChangeWrapper(
|
|
236
|
+
function pushTrackedChangeWrapper(params) {
|
|
237
|
+
const before = params.contents.length;
|
|
238
|
+
pushTrackedChangeWrapperRecord(params);
|
|
239
|
+
const pushed = params.contents.at(-1);
|
|
240
|
+
if (params.split !== void 0 && params.contents.length > before && pushed !== void 0) splitPieces.set(pushed, params.split);
|
|
241
|
+
}
|
|
242
|
+
function pushTrackedChangeWrapperRecord({ contents, type, info, resolutionJoins, content, preserveEmpty = false }) {
|
|
236
243
|
if (content.length === 0 && !preserveEmpty) return;
|
|
237
244
|
const provenance = resolutionJoins === void 0 ? {} : { resolutionJoins };
|
|
238
245
|
if (type === "insertion") {
|
|
@@ -269,46 +276,20 @@ function pushTrackedChangeWrapper({ contents, type, info, resolutionJoins, conte
|
|
|
269
276
|
...provenance
|
|
270
277
|
});
|
|
271
278
|
}
|
|
272
|
-
function pushTrackedChangeSegments({ contents, type, info, resolutionJoins, parsedContent }) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
});
|
|
278
|
-
if (!parsedContent.some(isTrackedChangeWrapperChild)) {
|
|
279
|
-
pushTrackedChangeWrapper({
|
|
280
|
-
contents,
|
|
281
|
-
type,
|
|
282
|
-
info,
|
|
283
|
-
resolutionJoins,
|
|
284
|
-
content: [],
|
|
285
|
-
preserveEmpty: true
|
|
286
|
-
});
|
|
287
|
-
contents.push(...parsedContent);
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
const segment = [];
|
|
291
|
-
for (const content of parsedContent) {
|
|
292
|
-
if (isTrackedChangeWrapperChild(content)) {
|
|
293
|
-
segment.push(content);
|
|
294
|
-
continue;
|
|
295
|
-
}
|
|
296
|
-
pushTrackedChangeWrapper({
|
|
297
|
-
contents,
|
|
298
|
-
type,
|
|
299
|
-
info,
|
|
300
|
-
resolutionJoins,
|
|
301
|
-
content: segment
|
|
302
|
-
});
|
|
303
|
-
segment.length = 0;
|
|
304
|
-
contents.push(content);
|
|
279
|
+
function pushTrackedChangeSegments({ contents, type, info, resolutionJoins, parsedContent, split }) {
|
|
280
|
+
const content = [];
|
|
281
|
+
for (const item of parsedContent) {
|
|
282
|
+
if (!isTrackedChangeWrapperChild(item)) panic(`A ${item.type} is not a tracked change child; the invariant that every paragraph content kind is one broke.`);
|
|
283
|
+
content.push(item);
|
|
305
284
|
}
|
|
306
285
|
pushTrackedChangeWrapper({
|
|
307
286
|
contents,
|
|
308
287
|
type,
|
|
309
288
|
info,
|
|
310
289
|
resolutionJoins,
|
|
311
|
-
content
|
|
290
|
+
content,
|
|
291
|
+
preserveEmpty: true,
|
|
292
|
+
...split === void 0 ? {} : { split }
|
|
312
293
|
});
|
|
313
294
|
}
|
|
314
295
|
function pushInlineSdtSegments({ contents, properties, parsedContent }) {
|
|
@@ -404,12 +385,16 @@ const linkedRevisionContent = (wrapped, linkOver) => {
|
|
|
404
385
|
case "insertion":
|
|
405
386
|
case "deletion":
|
|
406
387
|
case "moveFrom":
|
|
407
|
-
case "moveTo":
|
|
408
|
-
|
|
388
|
+
case "moveTo": {
|
|
389
|
+
const relinked = {
|
|
409
390
|
...item,
|
|
410
391
|
content: linkedRevisionContent(item.content, linkOver)
|
|
411
|
-
}
|
|
392
|
+
};
|
|
393
|
+
const split = splitPieces.get(item);
|
|
394
|
+
if (split !== void 0) splitPieces.set(relinked, split);
|
|
395
|
+
content.push(relinked);
|
|
412
396
|
break;
|
|
397
|
+
}
|
|
413
398
|
case "inlineSdt": return panic("An SDT under a hyperlink must retain its opaque source span");
|
|
414
399
|
default: if (isTrackedChangeWrapperChild(item)) content.push(item);
|
|
415
400
|
}
|
|
@@ -420,11 +405,15 @@ const linkedRevisionContent = (wrapped, linkOver) => {
|
|
|
420
405
|
const hoistRevision = (wrapper) => (child, { styles, theme, rels, media, previews, inScopeXmlns, items, linkOver }) => {
|
|
421
406
|
const wrapped = parseParagraphContents(child, styles, theme, null, rels, media, previews, TRACKED_CHANGE_PARSE_CONTEXT[wrapper], inScopeXmlns, "hyperlink");
|
|
422
407
|
const content = linkedRevisionContent(wrapped, linkOver);
|
|
408
|
+
const split = parseSplitResolutionPiece(child);
|
|
409
|
+
const resolutionJoins = parseResolutionJoins(child);
|
|
423
410
|
items.push({
|
|
424
411
|
type: "hoistedRevision",
|
|
425
412
|
wrapper,
|
|
426
413
|
info: parseTrackedChangeInfo(child),
|
|
427
|
-
content
|
|
414
|
+
content,
|
|
415
|
+
...split === void 0 ? {} : { split },
|
|
416
|
+
...resolutionJoins === void 0 ? {} : { resolutionJoins }
|
|
428
417
|
});
|
|
429
418
|
};
|
|
430
419
|
const HYPERLINK_REVISION_HOISTING_HANDLERS = {
|
|
@@ -435,6 +424,30 @@ const HYPERLINK_REVISION_HOISTING_HANDLERS = {
|
|
|
435
424
|
moveTo: hoistRevision("moveTo")
|
|
436
425
|
};
|
|
437
426
|
/**
|
|
427
|
+
* A link holding a complex field, read with the paragraph's field scan so a
|
|
428
|
+
* field whose `begin` and `end` are both inside the link is one child.
|
|
429
|
+
*
|
|
430
|
+
* A table of contents entry is one link over the heading text,
|
|
431
|
+
* a tab and the `PAGEREF` page number. The link reads its runs one at a time,
|
|
432
|
+
* which would leave the page number's field characters as loose runs. A field
|
|
433
|
+
* the link does not close stays as the loose runs it was read as, and so does
|
|
434
|
+
* the whole link when the scan returns anything a link cannot hold.
|
|
435
|
+
*/
|
|
436
|
+
const linkWithFields = (node, children, rels, styles, theme, media, rootXmlns, previews) => {
|
|
437
|
+
if (!children.some((child) => getLocalName(child.name) === "r" && findWordprocessingChild(child, "fldChar") !== void 0)) return void 0;
|
|
438
|
+
const contents = parseParagraphContents(node, styles, theme, null, rels, media, previews, "default", rootXmlns, "hyperlink");
|
|
439
|
+
const linked = [];
|
|
440
|
+
for (const item of contents) if (isHyperlinkContent(item)) linked.push(item);
|
|
441
|
+
if (linked.length !== contents.length || !linked.some(({ type }) => type === "complexField")) {
|
|
442
|
+
previews.release(contents);
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
return {
|
|
446
|
+
...parseHyperlinkShell(node, rels),
|
|
447
|
+
children: linked
|
|
448
|
+
};
|
|
449
|
+
};
|
|
450
|
+
/**
|
|
438
451
|
* A `w:hyperlink` as paragraph content, with any revision wrapper it holds
|
|
439
452
|
* hoisted around it.
|
|
440
453
|
*
|
|
@@ -444,7 +457,12 @@ const HYPERLINK_REVISION_HOISTING_HANDLERS = {
|
|
|
444
457
|
* inverse of what the serializer writes, so a package survives the round trip.
|
|
445
458
|
*/
|
|
446
459
|
function parseHyperlinkParagraphContents(node, rels, styles, theme, media, rootXmlns, previews) {
|
|
447
|
-
|
|
460
|
+
const children = getChildElements(node);
|
|
461
|
+
if (!children.some((child) => HYPERLINK_REVISION_WRAPPERS.has(getLocalName(child.name)))) {
|
|
462
|
+
const linkedFields = linkWithFields(node, children, rels, styles, theme, media, rootXmlns, previews);
|
|
463
|
+
if (linkedFields !== void 0) return [linkedFields];
|
|
464
|
+
return [parseHyperlink(node, rels, styles, theme, media, rootXmlns, previews)];
|
|
465
|
+
}
|
|
448
466
|
const inScopeXmlns = mergeXmlnsDeclarations(rootXmlns, node);
|
|
449
467
|
const shell = parseHyperlinkShell(node, rels);
|
|
450
468
|
const linkOver = (linkChildren) => ({
|
|
@@ -490,7 +508,9 @@ function parseHyperlinkParagraphContents(node, rels, styles, theme, media, rootX
|
|
|
490
508
|
type: item.wrapper,
|
|
491
509
|
info: item.info,
|
|
492
510
|
content: item.content,
|
|
493
|
-
preserveEmpty: true
|
|
511
|
+
preserveEmpty: true,
|
|
512
|
+
split: item.split,
|
|
513
|
+
resolutionJoins: item.resolutionJoins
|
|
494
514
|
});
|
|
495
515
|
}
|
|
496
516
|
flushPlain();
|
|
@@ -901,7 +921,9 @@ const assembledFieldBeginsOf = (container) => {
|
|
|
901
921
|
* adds.
|
|
902
922
|
*/
|
|
903
923
|
const paragraphInlineWrapper = (element) => (child, { styles, theme, rels, media, previews, trackedContext, inScopeXmlns, inlineScope, contents }) => {
|
|
904
|
-
|
|
924
|
+
const wrapper = inlineWrapperOf(element, child, parseParagraphContents(child, styles, theme, null, rels, media, previews, trackedContext, mergeXmlnsDeclarations(inScopeXmlns, child), inlineScope));
|
|
925
|
+
tagSplitPiece(child, wrapper);
|
|
926
|
+
contents.push(wrapper);
|
|
905
927
|
};
|
|
906
928
|
const PARAGRAPH_CONTENT_UNDECLARED = { AlternateContent: (child, { contents, styles, theme, rels, media, previews, trackedContext, inScopeXmlns, inlineScope }) => {
|
|
907
929
|
const selectedBranch = selectAlternateContentBranch(child);
|
|
@@ -914,13 +936,15 @@ const PARAGRAPH_CONTENT_UNDECLARED_NAMESPACES = { [OMML_NAMESPACE]: (child, { co
|
|
|
914
936
|
/** All revision wrappers retain typed review ownership while parsing their children. */
|
|
915
937
|
const trackedParagraphRevision = (type) => (child, { contents, styles, theme, rels, media, previews, inScopeXmlns, inlineScope }) => {
|
|
916
938
|
const resolutionJoins = parseResolutionJoins(child);
|
|
939
|
+
const split = parseSplitResolutionPiece(child);
|
|
917
940
|
const parsedContent = parseParagraphContents(child, styles, theme, null, rels, media, previews, TRACKED_CHANGE_PARSE_CONTEXT[type], inScopeXmlns, inlineScope);
|
|
918
941
|
pushTrackedChangeSegments({
|
|
919
942
|
contents,
|
|
920
943
|
type,
|
|
921
944
|
info: parseTrackedChangeInfo(child),
|
|
922
945
|
resolutionJoins,
|
|
923
|
-
parsedContent
|
|
946
|
+
parsedContent,
|
|
947
|
+
split
|
|
924
948
|
});
|
|
925
949
|
};
|
|
926
950
|
const PARAGRAPH_CONTENT_HANDLERS = {
|
|
@@ -976,7 +1000,7 @@ const PARAGRAPH_CONTENT_HANDLERS = {
|
|
|
976
1000
|
scan.complexFieldOpenRuns.push(withOrphanFieldCharsPreserved(run, runElement));
|
|
977
1001
|
if (commentReferenceId !== null || trackedContext === "deletion") scan.complexFieldSourceRuns = null;
|
|
978
1002
|
else scan.complexFieldSourceRuns?.push(runElement);
|
|
979
|
-
if (instrText) scan.complexFieldInstr += instrText;
|
|
1003
|
+
if (instrText && !(isNestedField && scan.afterSeparator)) scan.complexFieldInstr += instrText;
|
|
980
1004
|
if ((!scan.complexFieldFormatting || Object.keys(scan.complexFieldFormatting).length === 0) && run.formatting && Object.keys(run.formatting).length > 0) scan.complexFieldFormatting = run.formatting;
|
|
981
1005
|
let inFieldCodeRegion = !hasFieldBegin && !scan.afterSeparator;
|
|
982
1006
|
const fieldCodeContent = [];
|
|
@@ -996,8 +1020,12 @@ const PARAGRAPH_CONTENT_HANDLERS = {
|
|
|
996
1020
|
content: fieldCodeContent
|
|
997
1021
|
});
|
|
998
1022
|
if (hasFieldSeparate && !isNestedField) scan.afterSeparator = true;
|
|
999
|
-
|
|
1000
|
-
|
|
1023
|
+
const ownStructure = !isNestedField && (hasFieldSeparate || hasFieldEnd);
|
|
1024
|
+
if (scan.afterSeparator && !ownStructure) {
|
|
1025
|
+
let resultRun = run;
|
|
1026
|
+
if (isHiddenByOpenFieldCode(scan)) resultRun = hiddenRunCaptureOf(runElement, run.formatting);
|
|
1027
|
+
else if (isNestedField) resultRun = withOrphanFieldCharsPreserved(run, runElement);
|
|
1028
|
+
scan.complexFieldResultRuns.push(resultRun);
|
|
1001
1029
|
}
|
|
1002
1030
|
if (hasFieldEnd && !isNestedField) {
|
|
1003
1031
|
let resultRuns = scan.complexFieldResultRuns;
|
|
@@ -1211,8 +1239,90 @@ function parseParagraphContents(paraElement, styles, theme, _numbering, rels, me
|
|
|
1211
1239
|
}
|
|
1212
1240
|
});
|
|
1213
1241
|
if (scan.inComplexField) contents.push(...scan.complexFieldOpenRuns);
|
|
1214
|
-
return withPreservedChildren(contents, preserved, preservedInlineCapture);
|
|
1242
|
+
return joinSplitRevisionPieces(withPreservedChildren(contents, preserved, preservedInlineCapture));
|
|
1215
1243
|
}
|
|
1244
|
+
/**
|
|
1245
|
+
* Put back together each change the serializer wrote as several elements
|
|
1246
|
+
* around a hyperlink: its pieces, read as neighbouring wrappers of one kind
|
|
1247
|
+
* and author, become the one change again, under the first piece's id and
|
|
1248
|
+
* with the joins it carried. Pieces that do not line up stay as they were
|
|
1249
|
+
* read, without the joins, which no one piece could own.
|
|
1250
|
+
*/
|
|
1251
|
+
const joinSplitRevisionPieces = (source) => {
|
|
1252
|
+
const contents = source.map(sinkLiftedLink);
|
|
1253
|
+
if (!contents.some((item) => splitPieces.has(item))) return source;
|
|
1254
|
+
const out = [];
|
|
1255
|
+
for (let index = 0; index < contents.length; index += 1) {
|
|
1256
|
+
const first = contents[index];
|
|
1257
|
+
if (first === void 0) continue;
|
|
1258
|
+
const split = splitPieces.get(first);
|
|
1259
|
+
if (split?.piece !== 0 || !isSplittable(first)) {
|
|
1260
|
+
out.push(first);
|
|
1261
|
+
continue;
|
|
1262
|
+
}
|
|
1263
|
+
const pieces = contents.slice(index, index + split.pieces);
|
|
1264
|
+
if (!(pieces.length === split.pieces && pieces.every((piece, ordinal) => {
|
|
1265
|
+
const own = splitPieces.get(piece);
|
|
1266
|
+
return own?.piece === ordinal && own.pieces === split.pieces && isSplittable(piece) && samePieceOwner(first, piece);
|
|
1267
|
+
}))) {
|
|
1268
|
+
out.push(first);
|
|
1269
|
+
continue;
|
|
1270
|
+
}
|
|
1271
|
+
const joined = [];
|
|
1272
|
+
for (const piece of pieces) if (isSplittable(piece)) joined.push(...piece.content);
|
|
1273
|
+
if (first.type === "inlineWrapper") {
|
|
1274
|
+
out.push({
|
|
1275
|
+
...first,
|
|
1276
|
+
content: joinSplitRevisionPieces(joined)
|
|
1277
|
+
});
|
|
1278
|
+
index += split.pieces - 1;
|
|
1279
|
+
continue;
|
|
1280
|
+
}
|
|
1281
|
+
const content = joinSplitRevisionPieces(joined).filter(isTrackedChangeWrapperChild);
|
|
1282
|
+
const { resolutionJoins: _pieceJoins, ...rest } = first;
|
|
1283
|
+
out.push({
|
|
1284
|
+
...rest,
|
|
1285
|
+
content,
|
|
1286
|
+
...split.joins === void 0 ? {} : { resolutionJoins: split.joins }
|
|
1287
|
+
});
|
|
1288
|
+
index += split.pieces - 1;
|
|
1289
|
+
}
|
|
1290
|
+
return out;
|
|
1291
|
+
};
|
|
1292
|
+
/**
|
|
1293
|
+
* A lifted link the parser read around the pieces it holds, put back below
|
|
1294
|
+
* them: the serializer writes the link outermost and every split piece inside
|
|
1295
|
+
* it, so the piece a wrapper or change was split into sits under the link
|
|
1296
|
+
* the change originally held.
|
|
1297
|
+
*/
|
|
1298
|
+
const sinkLiftedLink = (item) => {
|
|
1299
|
+
if (item.type !== "hyperlink") return item;
|
|
1300
|
+
const [only, ...rest] = item.children;
|
|
1301
|
+
if (only === void 0 || rest.length > 0 || !splitPieces.has(only)) return item;
|
|
1302
|
+
if (!isSplittable(only)) return item;
|
|
1303
|
+
const sunk = {
|
|
1304
|
+
...only,
|
|
1305
|
+
content: [sinkLiftedLink({
|
|
1306
|
+
...item,
|
|
1307
|
+
children: [...only.content]
|
|
1308
|
+
})]
|
|
1309
|
+
};
|
|
1310
|
+
splitPieces.set(sunk, splitPieces.get(only));
|
|
1311
|
+
return sunk;
|
|
1312
|
+
};
|
|
1313
|
+
/** What the serializer splits around a lifted link: changes and transparent wrappers. */
|
|
1314
|
+
const isSplittable = (item) => isTrackedRunChange(item) || item.type === "inlineWrapper";
|
|
1315
|
+
/** Whether two pieces came from one element: the same record, its content aside. */
|
|
1316
|
+
const samePieceOwner = (first, piece) => {
|
|
1317
|
+
if (first.type !== piece.type) return false;
|
|
1318
|
+
if (first.type === "inlineWrapper" || piece.type === "inlineWrapper") {
|
|
1319
|
+
const { content: _first, ...firstOwner } = first;
|
|
1320
|
+
const { content: _piece, ...pieceOwner } = piece;
|
|
1321
|
+
return JSON.stringify(firstOwner) === JSON.stringify(pieceOwner);
|
|
1322
|
+
}
|
|
1323
|
+
return first.info.author === piece.info.author && first.info.date === piece.info.date;
|
|
1324
|
+
};
|
|
1325
|
+
const isTrackedRunChange = (item) => item.type === "insertion" || item.type === "deletion" || item.type === "moveFrom" || item.type === "moveTo";
|
|
1216
1326
|
function getCommentReferenceId(runElement) {
|
|
1217
1327
|
const commentReference = findChild(runElement, "w", "commentReference");
|
|
1218
1328
|
if (!commentReference) return null;
|
|
@@ -1426,6 +1536,7 @@ const getHyperlinkText = (hyperlink) => hyperlink.children.map((child) => {
|
|
|
1426
1536
|
case "moveToRangeEnd": return "";
|
|
1427
1537
|
case "preservedInline": return child.text;
|
|
1428
1538
|
case "inlineWrapper": return child.content.map(getParagraphContentText).join("");
|
|
1539
|
+
case "complexField": return getParagraphContentText(child);
|
|
1429
1540
|
default: return panic(`Unsupported hyperlink child in plain-text extraction: ${JSON.stringify(child)}`);
|
|
1430
1541
|
}
|
|
1431
1542
|
}).join("");
|
|
@@ -71,6 +71,13 @@ export declare const paragraphPropertySourceBelongsToDocument: (paragraph: docum
|
|
|
71
71
|
export declare const getProseDocumentParagraphPropertySourceContract: (document: Node) => string | null;
|
|
72
72
|
export declare const getProseParagraphPropertySourceToken: (paragraph: Node) => unknown;
|
|
73
73
|
export declare const copyDocumentParagraphPropertySourceContract: (target: document_d_exports.Document, source: document_d_exports.Document) => void;
|
|
74
|
+
/**
|
|
75
|
+
* Every fact this module keeps for a paragraph outside its fields, by
|
|
76
|
+
* identity. A conversion of the paragraph may read any of them, so a
|
|
77
|
+
* converted paragraph is reused only while they are the ones it was
|
|
78
|
+
* converted with.
|
|
79
|
+
*/
|
|
80
|
+
export declare const paragraphPropertySourceState: (paragraph: document_d_exports.Paragraph) => readonly unknown[];
|
|
74
81
|
export declare const getParagraphPropertySourceToken: (paragraph: document_d_exports.Paragraph) => string | undefined;
|
|
75
82
|
type ParagraphSourceIdentity = {
|
|
76
83
|
type: "durable";
|
|
@@ -307,6 +307,23 @@ const copyDocumentParagraphPropertySourceContract = (target, source) => {
|
|
|
307
307
|
const binding = getDocumentParagraphPropertySourceBinding(source);
|
|
308
308
|
if (binding) setDocumentParagraphPropertySourceBinding(target, binding);
|
|
309
309
|
};
|
|
310
|
+
/**
|
|
311
|
+
* Every fact this module keeps for a paragraph outside its fields, by
|
|
312
|
+
* identity. A conversion of the paragraph may read any of them, so a
|
|
313
|
+
* converted paragraph is reused only while they are the ones it was
|
|
314
|
+
* converted with.
|
|
315
|
+
*/
|
|
316
|
+
const paragraphPropertySourceState = (paragraph) => [
|
|
317
|
+
paragraphPropertySourceTokens.get(paragraph),
|
|
318
|
+
paragraphPropertySourceCandidates.get(paragraph),
|
|
319
|
+
paragraphPropertySourceTransferIds.get(paragraph),
|
|
320
|
+
paragraphSourceRecordKinds.get(paragraph),
|
|
321
|
+
captureForParagraph(paragraph),
|
|
322
|
+
indentationProjectionFor(paragraph),
|
|
323
|
+
assignedIndentationProjections.has(paragraph),
|
|
324
|
+
decodedTableCellParagraphSourcePayloads.get(paragraph),
|
|
325
|
+
...paragraph.formatting === void 0 ? [] : [paragraphPropertyCaptures.get(paragraph.formatting), indentationProjections.get(paragraph.formatting)]
|
|
326
|
+
];
|
|
310
327
|
const getParagraphPropertySourceToken = (paragraph) => paragraphPropertySourceTokens.get(paragraph);
|
|
311
328
|
/** Byte captures can follow derivations; only explicit copies carry durable tokens. */
|
|
312
329
|
const inspectParagraphSourceIdentity = (paragraph, document) => {
|
|
@@ -441,6 +458,8 @@ const tableCellBlockTraversalByType = {
|
|
|
441
458
|
blockCustomXml: "blockSdt",
|
|
442
459
|
bookmarkEnd: "leaf",
|
|
443
460
|
bookmarkStart: "leaf",
|
|
461
|
+
commentRangeEnd: "leaf",
|
|
462
|
+
commentRangeStart: "leaf",
|
|
444
463
|
moveFromRangeEnd: "leaf",
|
|
445
464
|
moveFromRangeStart: "leaf",
|
|
446
465
|
moveToRangeEnd: "leaf",
|
|
@@ -658,6 +677,8 @@ const TABLE_CELL_LEAF_BLOCK_FIELDS = {
|
|
|
658
677
|
name: "string"
|
|
659
678
|
},
|
|
660
679
|
bookmarkEnd: { id: "number" },
|
|
680
|
+
commentRangeStart: { id: "number" },
|
|
681
|
+
commentRangeEnd: { id: "number" },
|
|
661
682
|
moveFromRangeStart: {
|
|
662
683
|
id: "number",
|
|
663
684
|
name: "string",
|
|
@@ -931,4 +952,4 @@ const linkParagraphPropertySourceCandidate = (target, source) => {
|
|
|
931
952
|
};
|
|
932
953
|
const getParagraphPropertySourceCandidate = (paragraph) => paragraphPropertySourceCandidates.get(paragraph);
|
|
933
954
|
const getParagraphPropertySourceTransferId = (paragraph) => paragraphPropertySourceTransferIds.get(paragraph);
|
|
934
|
-
export { PARAGRAPH_PROPERTY_SOURCE_VALIDATION_CODES, PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR, PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR, ParagraphPropertySourceValidationError, TABLE_CELL_PARAGRAPH_SOURCE_BINDING_ATTR, TABLE_CELL_PARAGRAPH_SOURCE_PAYLOAD_ERROR_CLASSIFICATIONS, assignDocumentParagraphPropertySourceContract, assignParagraphIndentationProjection, assignParagraphPropertySource, cloneDocumentWithParagraphPropertySources, cloneParagraphWithPropertySource, cloneParagraphWithoutPropertySource, cloneTableCellsWithParagraphPropertyCaptures, copyDocumentParagraphPropertySourceContract, copyDocumentParagraphPropertySources, copyParagraphIndentationProjection, copyParagraphPropertyCapture, copyParagraphPropertySource, createProseParagraphWithPropertySource, decodeTableCellParagraphSourcePayload, getDocumentParagraphPropertySourceContract, getExplicitParagraphPropertySourceTransfers, getParagraphPropertySource, getParagraphPropertySourceCandidate, getParagraphPropertySourceToken, getParagraphPropertySourceTransferId, getProseDocumentParagraphPropertySourceContract, getProseParagraphPropertySourceToken, inspectParagraphSourceIdentity, isParagraphPropertySourceToken, joinProseParagraphsWithRightPropertySource, linkParagraphPropertySourceCandidate, linkProseParagraphPropertySource, markParagraphPropertySourceTransfers, paragraphFormattingWithAuthoredIndentation, paragraphPropertySourceBelongsToDocument, paragraphPropertySourceMatchesAuthoredIndentation, paragraphPropertySourceMatchesEmission, paragraphPropertySourceTokenMatchesContract, proseParagraphAttrsWithoutPropertySource, recreateProseNodeWithDetachedParagraphPropertySource, recreateProseNodeWithParagraphPropertySource, restoreParagraphIndentationProjection, restoreTableCellsWithParagraphPropertySources, sameParagraphIndentationProjection, setProseParagraphMarkupWithPropertySource, transferProseParagraphPropertySource, transportTableCellsWithParagraphPropertySources, visitDocumentStoryParagraphs, visitTableCellParagraphPropertySourceBindings };
|
|
955
|
+
export { PARAGRAPH_PROPERTY_SOURCE_VALIDATION_CODES, PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR, PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR, ParagraphPropertySourceValidationError, TABLE_CELL_PARAGRAPH_SOURCE_BINDING_ATTR, TABLE_CELL_PARAGRAPH_SOURCE_PAYLOAD_ERROR_CLASSIFICATIONS, assignDocumentParagraphPropertySourceContract, assignParagraphIndentationProjection, assignParagraphPropertySource, cloneDocumentWithParagraphPropertySources, cloneParagraphWithPropertySource, cloneParagraphWithoutPropertySource, cloneTableCellsWithParagraphPropertyCaptures, copyDocumentParagraphPropertySourceContract, copyDocumentParagraphPropertySources, copyParagraphIndentationProjection, copyParagraphPropertyCapture, copyParagraphPropertySource, createProseParagraphWithPropertySource, decodeTableCellParagraphSourcePayload, getDocumentParagraphPropertySourceContract, getExplicitParagraphPropertySourceTransfers, getParagraphPropertySource, getParagraphPropertySourceCandidate, getParagraphPropertySourceToken, getParagraphPropertySourceTransferId, getProseDocumentParagraphPropertySourceContract, getProseParagraphPropertySourceToken, inspectParagraphSourceIdentity, isParagraphPropertySourceToken, joinProseParagraphsWithRightPropertySource, linkParagraphPropertySourceCandidate, linkProseParagraphPropertySource, markParagraphPropertySourceTransfers, paragraphFormattingWithAuthoredIndentation, paragraphPropertySourceBelongsToDocument, paragraphPropertySourceMatchesAuthoredIndentation, paragraphPropertySourceMatchesEmission, paragraphPropertySourceState, paragraphPropertySourceTokenMatchesContract, proseParagraphAttrsWithoutPropertySource, recreateProseNodeWithDetachedParagraphPropertySource, recreateProseNodeWithParagraphPropertySource, restoreParagraphIndentationProjection, restoreTableCellsWithParagraphPropertySources, sameParagraphIndentationProjection, setProseParagraphMarkupWithPropertySource, transferProseParagraphPropertySource, transportTableCellsWithParagraphPropertySources, visitDocumentStoryParagraphs, visitTableCellParagraphPropertySourceBindings };
|
|
@@ -4,7 +4,8 @@ import { groupPreviewTextBoxes } from "./groupDrawingParser.js";
|
|
|
4
4
|
import { parseParagraph } from "./paragraphParser.js";
|
|
5
5
|
import { consolidateParagraphContent } from "./runConsolidator.js";
|
|
6
6
|
import { captureShapeAlternateContent } from "./shapeAlternateContent.js";
|
|
7
|
-
import {
|
|
7
|
+
import { parseTextBoxContent } from "./textBoxContentParser.js";
|
|
8
|
+
import { getTextBoxContentElement, parseTextBox, parseTextBoxFromShape, scanRunForTextBoxDrawings } from "./textBoxParser.js";
|
|
8
9
|
import { isVmlPictParsedByRunParser } from "./vmlImageParser.js";
|
|
9
10
|
import { WORDPROCESSINGML_NAMESPACE_URIS, findChildByLocalName, findChildByNamespaceUri, findDeep, findWordprocessingChild, getAttribute, getChildElements, getLocalName } from "./xmlParser.js";
|
|
10
11
|
// src/docx/paragraphTextBoxEnrichment.ts
|
|
@@ -104,6 +104,8 @@ const visitBlockChildren = ({ block, visitRecord, visitBlocks }) => {
|
|
|
104
104
|
case "preservedBlock":
|
|
105
105
|
case "bookmarkStart":
|
|
106
106
|
case "bookmarkEnd":
|
|
107
|
+
case "commentRangeStart":
|
|
108
|
+
case "commentRangeEnd":
|
|
107
109
|
case "moveFromRangeStart":
|
|
108
110
|
case "moveFromRangeEnd":
|
|
109
111
|
case "moveToRangeStart":
|
|
@@ -44,7 +44,8 @@ const PARSE_WARNING_MESSAGES = {
|
|
|
44
44
|
[PARSE_WARNING_CODES.pageBreakProjectionApproximated]: (warning) => `${warning.detail ?? "An explicit page break is laid out approximately"}${where(warning)}.`,
|
|
45
45
|
[PARSE_WARNING_CODES.altChunkUnsupported]: (warning) => `Preserved ${plural(warning.count, "w:altChunk")}; Folio cannot import its external content. Readers show a diagnostic marker.`,
|
|
46
46
|
[PARSE_WARNING_CODES.revisionCarrierOpaque]: (warning) => `Preserved ${plural(warning.count, "block-level tracked-change wrapper")}; Folio cannot interpret its block content, so that content is unavailable to readers or edits.`,
|
|
47
|
-
[PARSE_WARNING_CODES.nestedRowOpaque]: (warning) => `Preserved ${plural(warning.count, "nested table row")} as opaque markup; readers show a diagnostic marker for its content
|
|
47
|
+
[PARSE_WARNING_CODES.nestedRowOpaque]: (warning) => `Preserved ${plural(warning.count, "nested table row")} as opaque markup; readers show a diagnostic marker for its content.`,
|
|
48
|
+
[PARSE_WARNING_CODES.reviewProvenanceDropped]: (warning) => `Dropped ${plural(warning.count, "review provenance value")} Folio cannot read (${warning.detail ?? "invalid"})${where(warning)}; the revisions they annotate are kept.`
|
|
48
49
|
};
|
|
49
50
|
const formatParseWarning = (warning) => PARSE_WARNING_MESSAGES[warning.code](warning);
|
|
50
51
|
const formatParseWarnings = (warnings) => warnings.map(formatParseWarning);
|
package/dist/docx/parser.js
CHANGED
|
@@ -33,6 +33,7 @@ import { createPackagePreviewBudget } from "./previewBudget.js";
|
|
|
33
33
|
import { detectRasterMimeType } from "./rasterMime.js";
|
|
34
34
|
import { RELATIONSHIP_TYPES, parseRelationships, resolveRelativePath } from "./relsParser.js";
|
|
35
35
|
import { normalizeRenderedPageBreakHints } from "./renderedPageBreakNormalization.js";
|
|
36
|
+
import { diagnoseReviewProvenance } from "./reviewProvenanceDiagnostics.js";
|
|
36
37
|
import { parseSettings } from "./settingsParser.js";
|
|
37
38
|
import { parseStylesPackage } from "./styleParser.js";
|
|
38
39
|
import { applyThemeFontLang, parseTheme } from "./themeParser.js";
|
|
@@ -91,6 +92,8 @@ const countAltChunks = (blocks) => {
|
|
|
91
92
|
case "paragraph":
|
|
92
93
|
case "bookmarkStart":
|
|
93
94
|
case "bookmarkEnd":
|
|
95
|
+
case "commentRangeStart":
|
|
96
|
+
case "commentRangeEnd":
|
|
94
97
|
case "moveFromRangeStart":
|
|
95
98
|
case "moveFromRangeEnd":
|
|
96
99
|
case "moveToRangeStart":
|
|
@@ -169,6 +172,8 @@ const countOpaqueRevisionCarriers = (blocks) => {
|
|
|
169
172
|
case "paragraph":
|
|
170
173
|
case "bookmarkStart":
|
|
171
174
|
case "bookmarkEnd":
|
|
175
|
+
case "commentRangeStart":
|
|
176
|
+
case "commentRangeEnd":
|
|
172
177
|
case "moveFromRangeStart":
|
|
173
178
|
case "moveFromRangeEnd":
|
|
174
179
|
case "moveToRangeStart":
|
|
@@ -207,6 +212,7 @@ async function parseDocxWithPreviewBudget(input, options, previewBudget) {
|
|
|
207
212
|
extractAllXml: false
|
|
208
213
|
}));
|
|
209
214
|
diagnoseImportedIdCollisions(raw.allXml, parseContext);
|
|
215
|
+
diagnoseReviewProvenance(raw.allXml, parseContext);
|
|
210
216
|
await replaceRawDocxXmlParts(raw, normalizeBookmarkIdsInXmlParts(raw.allXml));
|
|
211
217
|
const repairedDocumentTree = await normalizeRawDocxNumericIds(raw);
|
|
212
218
|
const paragraphPropertySourceDigest = sha256Hex(raw.originalBuffer);
|
|
@@ -30,7 +30,7 @@ const scanRun = (run, scan) => {
|
|
|
30
30
|
};
|
|
31
31
|
const scanHyperlink = (hyperlink, scan) => {
|
|
32
32
|
for (const child of hyperlink.children) {
|
|
33
|
-
if (child.type !== "run" && child.type !== "inlineWrapper") continue;
|
|
33
|
+
if (child.type !== "run" && child.type !== "inlineWrapper" && child.type !== "complexField") continue;
|
|
34
34
|
const result = child.type === "run" ? scanRun(child, scan) : scanParagraphContent(child, scan);
|
|
35
35
|
if (result !== void 0) return result;
|
|
36
36
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ParseContext } from "./parseContext.js";
|
|
2
|
+
/**
|
|
3
|
+
* Report each review provenance value the reader drops: a version, a field or
|
|
4
|
+
* a value folio cannot read. Reading drops them and keeps the revisions; this
|
|
5
|
+
* is how the host learns that it did.
|
|
6
|
+
*/
|
|
7
|
+
export declare const diagnoseReviewProvenance: (parts: ReadonlyMap<string, string>, context: ParseContext) => void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { sliceText } from "../utils/sliceText.js";
|
|
2
|
+
import "./reviewHistoryNamespace.js";
|
|
3
|
+
import { reviewProvenanceIssue } from "./reviewResolutionProvenance.js";
|
|
4
|
+
import { getLocalName, resolveAttributeNamespaceUri } from "./xmlParser.js";
|
|
5
|
+
import { PARSE_WARNING_CODES } from "@stll/docx-core/model";
|
|
6
|
+
import { scanStreamingXmlElements } from "@stll/docx-core/xml";
|
|
7
|
+
// src/docx/reviewProvenanceDiagnostics.ts
|
|
8
|
+
/** The longest value a warning quotes; the rest is elided. */
|
|
9
|
+
const QUOTED_VALUE_LIMIT = 200;
|
|
10
|
+
/**
|
|
11
|
+
* Report each review provenance value the reader drops: a version, a field or
|
|
12
|
+
* a value folio cannot read. Reading drops them and keeps the revisions; this
|
|
13
|
+
* is how the host learns that it did.
|
|
14
|
+
*/
|
|
15
|
+
const diagnoseReviewProvenance = (parts, context) => {
|
|
16
|
+
for (const [part, xml] of parts) {
|
|
17
|
+
if (!xml.includes("urn:stella:folio:review-history:1")) continue;
|
|
18
|
+
const scoped = context.scoped({ part });
|
|
19
|
+
scanStreamingXmlElements(xml, ({ element }) => {
|
|
20
|
+
for (const [name, value] of Object.entries(element.attributes ?? {})) {
|
|
21
|
+
if (!name.includes(":") || name.startsWith("xmlns:") || resolveAttributeNamespaceUri(element, name) !== "urn:stella:folio:review-history:1") continue;
|
|
22
|
+
const encoded = String(value);
|
|
23
|
+
const issue = reviewProvenanceIssue(getLocalName(name), encoded);
|
|
24
|
+
if (issue === void 0) continue;
|
|
25
|
+
scoped.warn({
|
|
26
|
+
code: PARSE_WARNING_CODES.reviewProvenanceDropped,
|
|
27
|
+
...element.name === void 0 ? {} : { element: element.name },
|
|
28
|
+
value: encoded.length > QUOTED_VALUE_LIMIT ? `${sliceText({
|
|
29
|
+
text: encoded,
|
|
30
|
+
units: "codeUnits",
|
|
31
|
+
end: QUOTED_VALUE_LIMIT
|
|
32
|
+
})}...` : encoded,
|
|
33
|
+
detail: issue === "unsupportedVersion" ? `${getLocalName(name)}: unsupported version` : `${getLocalName(name)}: invalid value`
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
export { diagnoseReviewProvenance };
|