@stll/folio-core 0.59.0 → 0.61.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 -1
- package/dist/ai-edits/apply.js +139 -32
- package/dist/ai-edits/headless.d.ts +3 -0
- package/dist/ai-edits/headless.js +57 -63
- package/dist/ai-edits/note-story-inventory.d.ts +7 -0
- package/dist/ai-edits/note-story-inventory.js +11 -0
- package/dist/ai-edits/read.js +16 -9
- package/dist/ai-edits/revisionStretches.js +52 -1
- package/dist/ai-edits/table-row-column-mutations.js +6 -1
- package/dist/compare/reproducible-package.js +2 -1
- package/dist/compare/verification.js +1 -0
- package/dist/compat/eigenpal.d.ts +4 -2
- package/dist/compat/eigenpal.js +2 -2
- package/dist/controller/canonicalClipboard.js +2 -1
- package/dist/controller/canonicalListRendering.d.ts +4 -6
- package/dist/controller/canonicalListRendering.js +3 -157
- package/dist/controller/canonicalSession.js +3 -2
- package/dist/controller/canonicalStructure.js +10 -7
- package/dist/controller/fontReadiness.js +1 -1
- package/dist/controller/headerFooterEditorManager.d.ts +1 -0
- package/dist/controller/headerFooterEditorManager.js +11 -0
- package/dist/controller/hiddenEditorManager.d.ts +1 -1
- package/dist/controller/hiddenEditorManager.js +3 -1
- package/dist/controller/layoutPipeline.d.ts +3 -1
- package/dist/controller/layoutPipeline.js +19 -4
- package/dist/controller/layoutSession.d.ts +4 -1
- package/dist/display-list/build/fontTable.js +7 -5
- package/dist/display-list/build/furniture.d.ts +1 -0
- package/dist/display-list/build/furniture.js +1 -0
- package/dist/display-list/build/imagePrimitives.js +3 -6
- package/dist/display-list/build/watermarkPrimitives.d.ts +2 -1
- package/dist/display-list/build/watermarkPrimitives.js +9 -3
- package/dist/display-list/editor/pageRenderer.js +1 -0
- package/dist/docx/bookmarkIdNormalization.d.ts +10 -0
- package/dist/docx/bookmarkIdNormalization.js +100 -0
- package/dist/docx/bookmarkParser.js +4 -2
- package/dist/docx/canonicalStoryRepack.js +3 -2
- package/dist/docx/commentTextParagraph.d.ts +6 -0
- package/dist/docx/commentTextParagraph.js +15 -0
- package/dist/docx/conformance.js +6 -1
- package/dist/docx/diagramPreview.js +2 -1
- package/dist/docx/documentParser.d.ts +13 -1
- package/dist/docx/documentParser.js +1 -1
- package/dist/docx/encryption/compoundFile.d.ts +0 -8
- package/dist/docx/encryption/compoundFile.js +2 -1
- package/dist/docx/encryption/cryptoBytes.d.ts +2 -2
- package/dist/docx/encryption/cryptoBytes.js +3 -18
- package/dist/docx/encryption/encryptionInfo.d.ts +0 -5
- package/dist/docx/encryption/encryptionInfo.js +2 -1
- package/dist/docx/ensureParaIds.js +2 -1
- package/dist/docx/groupDrawingParser.js +6 -1
- package/dist/docx/importedIdCollisions.d.ts +136 -0
- package/dist/docx/importedIdCollisions.js +215 -0
- package/dist/docx/listModelNormalization.d.ts +10 -0
- package/dist/docx/listModelNormalization.js +166 -0
- package/dist/docx/metadataPrivacy.js +3 -2
- package/dist/docx/metafileRaster.js +2 -1
- package/dist/docx/numberingParser.js +2 -2
- package/dist/docx/packageParts.js +6 -5
- package/dist/docx/paragraphParser.js +6 -4
- package/dist/docx/paragraphPropertySource.js +1 -2
- package/dist/docx/parseContext.d.ts +2 -1
- package/dist/docx/parseContext.js +1 -0
- package/dist/docx/parseWarningMessage.js +1 -0
- package/dist/docx/parser.js +10 -5
- package/dist/docx/preservedRunContent.js +11 -2
- package/dist/docx/relsParser.js +1 -1
- package/dist/docx/removeHeaderFooterParts.js +8 -7
- package/dist/docx/replyToComment.js +3 -13
- package/dist/docx/rezip.js +90 -90
- package/dist/docx/runParser.js +12 -6
- package/dist/docx/runPropertyPresence.d.ts +11 -0
- package/dist/docx/runPropertyPresence.js +14 -0
- package/dist/docx/selectedXmlIdentityScan.d.ts +10 -0
- package/dist/docx/selectedXmlIdentityScan.js +36 -0
- package/dist/docx/selectiveSave.js +19 -17
- package/dist/docx/selectiveXmlPatch.js +44 -52
- package/dist/docx/serializer/commentSerializer.d.ts +3 -1
- package/dist/docx/serializer/commentSerializer.js +11 -2
- package/dist/docx/serializer/runSerializer.js +5 -4
- package/dist/docx/serializer/tableSerializer.js +2 -1
- package/dist/docx/serializer/trackedChangeAttributes.d.ts +1 -3
- package/dist/docx/serializer/trackedChangeAttributes.js +1 -11
- package/dist/docx/server/applyDocxXmlPatchProposal.js +2 -2
- package/dist/docx/server/boundedArchive.js +2 -1
- package/dist/docx/server/evaluateDocxXmlPatchProposal.js +2 -1
- package/dist/docx/server/inspectDocxPackage.js +5 -1
- package/dist/docx/server/validateDocxConformance.js +2 -1
- package/dist/docx/tableParser.js +7 -4
- package/dist/docx/tableRowPropertyPresence.d.ts +9 -0
- package/dist/docx/tableRowPropertyPresence.js +15 -0
- package/dist/docx/unzip.js +2 -1
- package/dist/docx/xmlEncoding.js +6 -5
- package/dist/fonts/embeddedFontFingerprint.d.ts +5 -0
- package/dist/fonts/embeddedFontFingerprint.js +18 -0
- package/dist/fonts/embeddedFonts.d.ts +1 -1
- package/dist/fonts/embeddedFonts.js +1 -1
- package/dist/fonts/fontsourceFaces.js +2 -1
- package/dist/fonts/headlessMeasure.js +0 -0
- package/dist/fonts/sfnt/parse.js +6 -9
- package/dist/fonts/sfnt/subset.js +2 -1
- package/dist/fonts/sfnt/tables.js +2 -3
- package/dist/fonts/sfnt/woff.js +2 -1
- package/dist/headless-layout.js +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +2 -2
- package/dist/internal/revisionResolutionInline.d.ts +2 -1
- package/dist/internal/revisionResolutionInline.js +22 -1
- package/dist/internal/wholeStoryRevisionResolution.js +24 -7
- package/dist/layout-bridge/convert/flowConversionShared.d.ts +4 -0
- package/dist/layout-bridge/convert/footnoteLayout.d.ts +5 -1
- package/dist/layout-bridge/convert/footnoteLayout.js +16 -3
- package/dist/layout-bridge/convert/headerFooterLayout.d.ts +6 -0
- package/dist/layout-bridge/convert/headerFooterLayout.js +13 -14
- package/dist/layout-bridge/convert/paragraphConversion.js +8 -1
- package/dist/layout-bridge/convert/paragraphRuns.js +2 -1
- package/dist/layout-bridge/convert/toFlowBlocks.js +25 -1
- package/dist/layout-engine/measure/cache.js +39 -7
- package/dist/layout-engine/measure/crossRunWords.js +12 -2
- package/dist/layout-engine/measure/lineTypography.js +1 -0
- package/dist/layout-engine/measure/listMarkerWidth.d.ts +1 -0
- package/dist/layout-engine/measure/listMarkerWidth.js +1 -0
- package/dist/layout-engine/measure/measureContainer.js +3 -4
- package/dist/layout-engine/measure/measureHelpers.d.ts +6 -9
- package/dist/layout-engine/measure/measureHelpers.js +21 -18
- package/dist/layout-engine/measure/measureParagraph.js +2 -0
- package/dist/layout-engine/measure/measureTypes.d.ts +2 -0
- package/dist/layout-engine/types.d.ts +4 -1
- package/dist/layout-painter/renderPage.d.ts +1 -0
- package/dist/layout-painter/renderPage.js +11 -3
- package/dist/layout-painter/renderParagraph.js +13 -3
- package/dist/layout-painter/renderWatermark.d.ts +1 -0
- package/dist/layout-painter/renderWatermark.js +7 -3
- package/dist/managers/AutoSaveManager.js +2 -1
- package/dist/managers/EditorModeManager.d.ts +10 -1
- package/dist/managers/EditorModeManager.js +15 -1
- package/dist/managers/TableSelectionManager.d.ts +1 -1
- package/dist/managers/autoSaveCodec.js +2 -6
- package/dist/managers/editorShortcuts.d.ts +2 -1
- package/dist/managers/editorShortcuts.js +2 -1
- package/dist/managers/reviewDisplayMode.d.ts +8 -0
- package/dist/managers/reviewDisplayMode.js +15 -0
- package/dist/paged-layout/pageText.d.ts +11 -2
- package/dist/paged-layout/pageText.js +8 -3
- package/dist/pdf/fonts.js +5 -14
- package/dist/pdf/images.js +3 -2
- package/dist/pdf/objects.d.ts +0 -11
- package/dist/pdf/objects.js +7 -9
- package/dist/pdf/writePdf.js +2 -1
- package/dist/prosemirror/canonicalSelectionRange.d.ts +4 -1
- package/dist/prosemirror/canonicalSelectionRange.js +9 -3
- package/dist/prosemirror/commands/comments.js +51 -13
- package/dist/prosemirror/containerFinalParagraph.d.ts +8 -8
- package/dist/prosemirror/containerFinalParagraph.js +8 -8
- package/dist/prosemirror/conversion/fromProseDoc.js +9 -4
- package/dist/prosemirror/conversion/toProseDoc.js +4 -4
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +8 -2
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +39 -3
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.d.ts +8 -2
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +4 -3
- package/dist/prosemirror/extensions/features/ImageDragExtension.js +4 -3
- package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.js +4 -3
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +9 -3
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +6 -5
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +8 -2
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +11 -3
- package/dist/prosemirror/extensions/marks/RunIdentityExtension.js +4 -3
- package/dist/prosemirror/extensions/marks/markUtils.js +1 -1
- package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +16 -2
- package/dist/prosemirror/findReplaceSelection.d.ts +11 -1
- package/dist/prosemirror/findReplaceSelection.js +15 -1
- package/dist/prosemirror/markupViewProjection.d.ts +10 -1
- package/dist/prosemirror/markupViewProjection.js +21 -3
- package/dist/prosemirror/pluginKeyOwner.d.ts +13 -0
- package/dist/prosemirror/pluginKeyOwner.js +35 -0
- package/dist/prosemirror/plugins/aiCitationDecorations.d.ts +11 -4
- package/dist/prosemirror/plugins/aiCitationDecorations.js +16 -3
- package/dist/prosemirror/plugins/aiSuggestionDecorations.d.ts +11 -4
- package/dist/prosemirror/plugins/aiSuggestionDecorations.js +18 -3
- package/dist/prosemirror/plugins/anonymizationDecorations.d.ts +11 -11
- package/dist/prosemirror/plugins/anonymizationDecorations.js +23 -13
- package/dist/prosemirror/plugins/autocompleteSuggestion.d.ts +8 -2
- package/dist/prosemirror/plugins/autocompleteSuggestion.js +27 -5
- package/dist/prosemirror/plugins/contentControlWidgets.d.ts +8 -2
- package/dist/prosemirror/plugins/contentControlWidgets.js +4 -3
- package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +6 -5
- package/dist/prosemirror/plugins/createDocScanPlugin.js +1 -1
- package/dist/prosemirror/plugins/documentNumbering.js +5 -3
- package/dist/prosemirror/plugins/documentStyleState.d.ts +8 -2
- package/dist/prosemirror/plugins/documentStyleState.js +2 -2
- package/dist/prosemirror/plugins/documentStyles.js +1 -1
- package/dist/prosemirror/plugins/selectionTracker.d.ts +8 -2
- package/dist/prosemirror/plugins/selectionTracker.js +4 -3
- package/dist/prosemirror/plugins/suggestionMode.d.ts +8 -2
- package/dist/prosemirror/plugins/suggestionMode.js +4 -3
- package/dist/prosemirror/plugins/templateDirectives.d.ts +8 -2
- package/dist/prosemirror/plugins/templateDirectives.js +19 -4
- package/dist/prosemirror/plugins/templatePreviewValues.d.ts +8 -2
- package/dist/prosemirror/plugins/templatePreviewValues.js +27 -5
- package/dist/prosemirror/plugins/templateSlashMenu.d.ts +8 -2
- package/dist/prosemirror/plugins/templateSlashMenu.js +23 -5
- package/dist/prosemirror/plugins/transactionInvariants.js +29 -4
- package/dist/prosemirror/replacedAnnotations.d.ts +15 -1
- package/dist/prosemirror/replacedAnnotations.js +71 -12
- package/dist/prosemirror/runFormattingReconciliation.d.ts +3 -1
- package/dist/prosemirror/runFormattingReconciliation.js +10 -2
- package/dist/prosemirror/runIdentityAcrossRevisions.d.ts +5 -7
- package/dist/prosemirror/runIdentityAcrossRevisions.js +66 -38
- package/dist/prosemirror/runPropertyChangeResolution.js +13 -1
- package/dist/utils/base64.d.ts +1 -31
- package/dist/utils/base64.js +19 -33
- package/dist/utils/clipboard.js +5 -4
- package/dist/utils/colorResolver.js +11 -2
- package/dist/utils/findReplace.d.ts +5 -0
- package/dist/utils/fontLoader.d.ts +2 -2
- package/dist/utils/fontLoader.js +2 -7
- package/dist/utils/fontResolver.d.ts +7 -3
- package/dist/utils/fontResolver.js +6 -8
- package/dist/utils/replaceText.js +21 -4
- package/dist/utils/sliceText.d.ts +2 -0
- package/dist/utils/sliceText.js +2 -0
- package/dist/utils/textEncoding.d.ts +2 -0
- package/dist/utils/textEncoding.js +2 -0
- package/dist/utils/tiffConverter.d.ts +0 -9
- package/dist/utils/tiffConverter.js +2 -4
- package/package.json +73 -31
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { ParseContext } from "./parseContext.js";
|
|
2
|
+
//#region src/docx/importedIdCollisions.d.ts
|
|
3
|
+
/** Definition sites only: paired markers and references never claim an identity. */
|
|
4
|
+
declare const IMPORTED_ID_COLLISION_REGISTRY: {
|
|
5
|
+
readonly bookmark: {
|
|
6
|
+
readonly kind: "bookmark";
|
|
7
|
+
readonly scope: "part";
|
|
8
|
+
readonly sites: readonly [{
|
|
9
|
+
readonly namespace: "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
10
|
+
readonly elements: Set<string>;
|
|
11
|
+
}];
|
|
12
|
+
readonly attribute: "id";
|
|
13
|
+
readonly attributeNamespace: "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
14
|
+
readonly encoding: "decimal";
|
|
15
|
+
};
|
|
16
|
+
readonly comment: {
|
|
17
|
+
readonly kind: "comment";
|
|
18
|
+
readonly scope: "part";
|
|
19
|
+
readonly sites: readonly [{
|
|
20
|
+
readonly namespace: "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
21
|
+
readonly elements: Set<string>;
|
|
22
|
+
}];
|
|
23
|
+
readonly attribute: "id";
|
|
24
|
+
readonly attributeNamespace: "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
25
|
+
readonly encoding: "decimal";
|
|
26
|
+
};
|
|
27
|
+
readonly footnote: {
|
|
28
|
+
readonly kind: "footnote";
|
|
29
|
+
readonly scope: "part";
|
|
30
|
+
readonly sites: readonly [{
|
|
31
|
+
readonly namespace: "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
32
|
+
readonly elements: Set<string>;
|
|
33
|
+
}];
|
|
34
|
+
readonly attribute: "id";
|
|
35
|
+
readonly attributeNamespace: "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
36
|
+
readonly encoding: "decimal";
|
|
37
|
+
};
|
|
38
|
+
readonly endnote: {
|
|
39
|
+
readonly kind: "endnote";
|
|
40
|
+
readonly scope: "part";
|
|
41
|
+
readonly sites: readonly [{
|
|
42
|
+
readonly namespace: "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
43
|
+
readonly elements: Set<string>;
|
|
44
|
+
}];
|
|
45
|
+
readonly attribute: "id";
|
|
46
|
+
readonly attributeNamespace: "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
47
|
+
readonly encoding: "decimal";
|
|
48
|
+
};
|
|
49
|
+
readonly revision: {
|
|
50
|
+
readonly kind: "revision";
|
|
51
|
+
readonly scope: "package";
|
|
52
|
+
readonly sites: readonly [{
|
|
53
|
+
readonly namespace: "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
54
|
+
readonly elements: Set<string>;
|
|
55
|
+
}];
|
|
56
|
+
readonly attribute: "id";
|
|
57
|
+
readonly attributeNamespace: "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
58
|
+
readonly encoding: "decimal";
|
|
59
|
+
};
|
|
60
|
+
readonly paraId: {
|
|
61
|
+
readonly kind: "paraId";
|
|
62
|
+
readonly scope: "part";
|
|
63
|
+
readonly sites: readonly [{
|
|
64
|
+
readonly namespace: "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
65
|
+
readonly elements: Set<string>;
|
|
66
|
+
}, {
|
|
67
|
+
readonly namespace: "http://schemas.microsoft.com/office/word/2012/wordml";
|
|
68
|
+
readonly elements: Set<string>;
|
|
69
|
+
}, {
|
|
70
|
+
readonly namespace: string;
|
|
71
|
+
readonly elements: Set<string>;
|
|
72
|
+
}];
|
|
73
|
+
readonly attribute: "paraId";
|
|
74
|
+
readonly attributeNamespace: "http://schemas.microsoft.com/office/word/2010/wordml";
|
|
75
|
+
readonly encoding: "hex";
|
|
76
|
+
};
|
|
77
|
+
readonly textId: {
|
|
78
|
+
readonly kind: "textId";
|
|
79
|
+
readonly scope: "part";
|
|
80
|
+
readonly sites: readonly [{
|
|
81
|
+
readonly namespace: "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
82
|
+
readonly elements: Set<string>;
|
|
83
|
+
}];
|
|
84
|
+
readonly attribute: "textId";
|
|
85
|
+
readonly attributeNamespace: "http://schemas.microsoft.com/office/word/2010/wordml";
|
|
86
|
+
readonly encoding: "hex";
|
|
87
|
+
};
|
|
88
|
+
readonly numId: {
|
|
89
|
+
readonly kind: "numId";
|
|
90
|
+
readonly scope: "part";
|
|
91
|
+
readonly sites: readonly [{
|
|
92
|
+
readonly namespace: "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
93
|
+
readonly elements: Set<string>;
|
|
94
|
+
}];
|
|
95
|
+
readonly attribute: "numId";
|
|
96
|
+
readonly attributeNamespace: "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
97
|
+
readonly encoding: "decimal";
|
|
98
|
+
};
|
|
99
|
+
readonly abstractNumId: {
|
|
100
|
+
readonly kind: "abstractNumId";
|
|
101
|
+
readonly scope: "part";
|
|
102
|
+
readonly sites: readonly [{
|
|
103
|
+
readonly namespace: "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
104
|
+
readonly elements: Set<string>;
|
|
105
|
+
}];
|
|
106
|
+
readonly attribute: "abstractNumId";
|
|
107
|
+
readonly attributeNamespace: "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
108
|
+
readonly encoding: "decimal";
|
|
109
|
+
};
|
|
110
|
+
readonly drawing: {
|
|
111
|
+
readonly kind: "drawing";
|
|
112
|
+
readonly scope: "package";
|
|
113
|
+
readonly sites: readonly [{
|
|
114
|
+
readonly namespace: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing";
|
|
115
|
+
readonly elements: Set<string>;
|
|
116
|
+
}];
|
|
117
|
+
readonly attribute: "id";
|
|
118
|
+
readonly attributeNamespace: null;
|
|
119
|
+
readonly encoding: "decimal";
|
|
120
|
+
};
|
|
121
|
+
readonly relationship: {
|
|
122
|
+
readonly kind: "relationship";
|
|
123
|
+
readonly scope: "part";
|
|
124
|
+
readonly sites: readonly [{
|
|
125
|
+
readonly namespace: "http://schemas.openxmlformats.org/package/2006/relationships";
|
|
126
|
+
readonly elements: Set<string>;
|
|
127
|
+
}];
|
|
128
|
+
readonly attribute: "Id";
|
|
129
|
+
readonly attributeNamespace: null;
|
|
130
|
+
readonly encoding: "string";
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
/** Reports repeated source definitions without changing the package or choosing a winner. */
|
|
134
|
+
declare const diagnoseImportedIdCollisions: (parts: ReadonlyMap<string, string>, context: ParseContext) => void;
|
|
135
|
+
//#endregion
|
|
136
|
+
export { IMPORTED_ID_COLLISION_REGISTRY, diagnoseImportedIdCollisions };
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { paraIdAttribute, textIdAttribute } from "./paraIdAttribute.js";
|
|
2
|
+
import { REVISION_ELEMENT_NAMES } from "./revisionIdNormalization.js";
|
|
3
|
+
import { scanSelectedStreamingXmlElements } from "./selectedXmlIdentityScan.js";
|
|
4
|
+
import { OOXML_NAMESPACES } from "./serializer/partNamespaces.js";
|
|
5
|
+
import { toTransitionalNamespaceUri } from "./transitionalSpelling.js";
|
|
6
|
+
import { resolveNamespaceUri } from "./xmlNamespaceContext.js";
|
|
7
|
+
import { NAMESPACES, getLocalName, getNamespaceUri } from "./xmlParser.js";
|
|
8
|
+
import { panic } from "better-result";
|
|
9
|
+
import { IMPORTED_ID_COLLISION_KINDS, PARSE_WARNING_CODES } from "@stll/docx-core/model";
|
|
10
|
+
//#region src/docx/importedIdCollisions.ts
|
|
11
|
+
const WORD_2010_NAMESPACE = "http://schemas.microsoft.com/office/word/2010/wordml";
|
|
12
|
+
const PACKAGE_RELATIONSHIP_NAMESPACE = "http://schemas.openxmlformats.org/package/2006/relationships";
|
|
13
|
+
const paragraphIdentityForKind = (kind, element) => {
|
|
14
|
+
switch (kind) {
|
|
15
|
+
case IMPORTED_ID_COLLISION_KINDS.paraId: return paraIdAttribute(element);
|
|
16
|
+
case IMPORTED_ID_COLLISION_KINDS.textId: return textIdAttribute(element);
|
|
17
|
+
default: return;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
/** Definition sites only: paired markers and references never claim an identity. */
|
|
21
|
+
const IMPORTED_ID_COLLISION_REGISTRY = {
|
|
22
|
+
bookmark: {
|
|
23
|
+
kind: IMPORTED_ID_COLLISION_KINDS.bookmark,
|
|
24
|
+
scope: "part",
|
|
25
|
+
sites: [{
|
|
26
|
+
namespace: NAMESPACES.w,
|
|
27
|
+
elements: /* @__PURE__ */ new Set(["bookmarkStart"])
|
|
28
|
+
}],
|
|
29
|
+
attribute: "id",
|
|
30
|
+
attributeNamespace: NAMESPACES.w,
|
|
31
|
+
encoding: "decimal"
|
|
32
|
+
},
|
|
33
|
+
comment: {
|
|
34
|
+
kind: IMPORTED_ID_COLLISION_KINDS.comment,
|
|
35
|
+
scope: "part",
|
|
36
|
+
sites: [{
|
|
37
|
+
namespace: NAMESPACES.w,
|
|
38
|
+
elements: /* @__PURE__ */ new Set(["comment"])
|
|
39
|
+
}],
|
|
40
|
+
attribute: "id",
|
|
41
|
+
attributeNamespace: NAMESPACES.w,
|
|
42
|
+
encoding: "decimal"
|
|
43
|
+
},
|
|
44
|
+
footnote: {
|
|
45
|
+
kind: IMPORTED_ID_COLLISION_KINDS.footnote,
|
|
46
|
+
scope: "part",
|
|
47
|
+
sites: [{
|
|
48
|
+
namespace: NAMESPACES.w,
|
|
49
|
+
elements: /* @__PURE__ */ new Set(["footnote"])
|
|
50
|
+
}],
|
|
51
|
+
attribute: "id",
|
|
52
|
+
attributeNamespace: NAMESPACES.w,
|
|
53
|
+
encoding: "decimal"
|
|
54
|
+
},
|
|
55
|
+
endnote: {
|
|
56
|
+
kind: IMPORTED_ID_COLLISION_KINDS.endnote,
|
|
57
|
+
scope: "part",
|
|
58
|
+
sites: [{
|
|
59
|
+
namespace: NAMESPACES.w,
|
|
60
|
+
elements: /* @__PURE__ */ new Set(["endnote"])
|
|
61
|
+
}],
|
|
62
|
+
attribute: "id",
|
|
63
|
+
attributeNamespace: NAMESPACES.w,
|
|
64
|
+
encoding: "decimal"
|
|
65
|
+
},
|
|
66
|
+
revision: {
|
|
67
|
+
kind: IMPORTED_ID_COLLISION_KINDS.revision,
|
|
68
|
+
scope: "package",
|
|
69
|
+
sites: [{
|
|
70
|
+
namespace: NAMESPACES.w,
|
|
71
|
+
elements: REVISION_ELEMENT_NAMES
|
|
72
|
+
}],
|
|
73
|
+
attribute: "id",
|
|
74
|
+
attributeNamespace: NAMESPACES.w,
|
|
75
|
+
encoding: "decimal"
|
|
76
|
+
},
|
|
77
|
+
paraId: {
|
|
78
|
+
kind: IMPORTED_ID_COLLISION_KINDS.paraId,
|
|
79
|
+
scope: "part",
|
|
80
|
+
sites: [
|
|
81
|
+
{
|
|
82
|
+
namespace: NAMESPACES.w,
|
|
83
|
+
elements: /* @__PURE__ */ new Set(["p"])
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
namespace: NAMESPACES.w15,
|
|
87
|
+
elements: /* @__PURE__ */ new Set(["commentEx"])
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
namespace: OOXML_NAMESPACES.w16cex.uri,
|
|
91
|
+
elements: /* @__PURE__ */ new Set(["comment"])
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
attribute: "paraId",
|
|
95
|
+
attributeNamespace: WORD_2010_NAMESPACE,
|
|
96
|
+
encoding: "hex"
|
|
97
|
+
},
|
|
98
|
+
textId: {
|
|
99
|
+
kind: IMPORTED_ID_COLLISION_KINDS.textId,
|
|
100
|
+
scope: "part",
|
|
101
|
+
sites: [{
|
|
102
|
+
namespace: NAMESPACES.w,
|
|
103
|
+
elements: /* @__PURE__ */ new Set(["p"])
|
|
104
|
+
}],
|
|
105
|
+
attribute: "textId",
|
|
106
|
+
attributeNamespace: WORD_2010_NAMESPACE,
|
|
107
|
+
encoding: "hex"
|
|
108
|
+
},
|
|
109
|
+
numId: {
|
|
110
|
+
kind: IMPORTED_ID_COLLISION_KINDS.numId,
|
|
111
|
+
scope: "part",
|
|
112
|
+
sites: [{
|
|
113
|
+
namespace: NAMESPACES.w,
|
|
114
|
+
elements: /* @__PURE__ */ new Set(["num"])
|
|
115
|
+
}],
|
|
116
|
+
attribute: "numId",
|
|
117
|
+
attributeNamespace: NAMESPACES.w,
|
|
118
|
+
encoding: "decimal"
|
|
119
|
+
},
|
|
120
|
+
abstractNumId: {
|
|
121
|
+
kind: IMPORTED_ID_COLLISION_KINDS.abstractNumId,
|
|
122
|
+
scope: "part",
|
|
123
|
+
sites: [{
|
|
124
|
+
namespace: NAMESPACES.w,
|
|
125
|
+
elements: /* @__PURE__ */ new Set(["abstractNum"])
|
|
126
|
+
}],
|
|
127
|
+
attribute: "abstractNumId",
|
|
128
|
+
attributeNamespace: NAMESPACES.w,
|
|
129
|
+
encoding: "decimal"
|
|
130
|
+
},
|
|
131
|
+
drawing: {
|
|
132
|
+
kind: IMPORTED_ID_COLLISION_KINDS.drawing,
|
|
133
|
+
scope: "package",
|
|
134
|
+
sites: [{
|
|
135
|
+
namespace: NAMESPACES.wp,
|
|
136
|
+
elements: /* @__PURE__ */ new Set(["docPr"])
|
|
137
|
+
}],
|
|
138
|
+
attribute: "id",
|
|
139
|
+
attributeNamespace: null,
|
|
140
|
+
encoding: "decimal"
|
|
141
|
+
},
|
|
142
|
+
relationship: {
|
|
143
|
+
kind: IMPORTED_ID_COLLISION_KINDS.relationship,
|
|
144
|
+
scope: "part",
|
|
145
|
+
sites: [{
|
|
146
|
+
namespace: PACKAGE_RELATIONSHIP_NAMESPACE,
|
|
147
|
+
elements: /* @__PURE__ */ new Set(["Relationship"])
|
|
148
|
+
}],
|
|
149
|
+
attribute: "Id",
|
|
150
|
+
attributeNamespace: null,
|
|
151
|
+
encoding: "string"
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const normalizedIdentity = (value, encoding) => {
|
|
155
|
+
if (encoding === "string") return value;
|
|
156
|
+
if (encoding === "hex") return /^[0-9a-f]{8}$/iu.test(value) ? value.toUpperCase() : void 0;
|
|
157
|
+
const spelling = value.trim();
|
|
158
|
+
if (!/^[+-]?\d+$/u.test(spelling)) return void 0;
|
|
159
|
+
const digits = spelling.replace(/^[+-]?0*/u, "");
|
|
160
|
+
return digits === "" ? "0" : `${spelling.startsWith("-") ? "-" : ""}${digits}`;
|
|
161
|
+
};
|
|
162
|
+
/** Reports repeated source definitions without changing the package or choosing a winner. */
|
|
163
|
+
const diagnoseImportedIdCollisions = (parts, context) => {
|
|
164
|
+
const rules = Object.values(IMPORTED_ID_COLLISION_REGISTRY);
|
|
165
|
+
const packageSeen = /* @__PURE__ */ new Map();
|
|
166
|
+
for (const [part, xml] of parts) {
|
|
167
|
+
const partSeen = /* @__PURE__ */ new Map();
|
|
168
|
+
const scoped = context.scoped({ part });
|
|
169
|
+
scanSelectedStreamingXmlElements(xml, ({ element, attributeValueSpans }) => {
|
|
170
|
+
if (element.name === void 0) return;
|
|
171
|
+
const namespace = toTransitionalNamespaceUri(getNamespaceUri(element) ?? "");
|
|
172
|
+
const localName = getLocalName(element.name);
|
|
173
|
+
for (const rule of rules) {
|
|
174
|
+
const kind = rule.kind;
|
|
175
|
+
if (!rule.sites.some((site) => namespace === site.namespace && site.elements.has(localName))) continue;
|
|
176
|
+
const paragraphIdentity = paragraphIdentityForKind(kind, element);
|
|
177
|
+
const seen = rule.scope === "package" ? packageSeen : partSeen;
|
|
178
|
+
for (const [name, rawValue] of Object.entries(element.attributes ?? {})) {
|
|
179
|
+
if (getLocalName(name) !== rule.attribute || rawValue === void 0) continue;
|
|
180
|
+
const colon = name.indexOf(":");
|
|
181
|
+
const attributeNamespace = colon < 0 ? null : toTransitionalNamespaceUri(resolveNamespaceUri(element.namespaceScope, name.slice(0, colon)) ?? "");
|
|
182
|
+
if (rule.encoding === "hex") {
|
|
183
|
+
if (String(rawValue) !== paragraphIdentity) continue;
|
|
184
|
+
} else if (attributeNamespace !== rule.attributeNamespace) continue;
|
|
185
|
+
const value = String(rawValue);
|
|
186
|
+
const identity = normalizedIdentity(value, rule.encoding);
|
|
187
|
+
if (identity === void 0) continue;
|
|
188
|
+
const key = `${kind}:${identity}`;
|
|
189
|
+
const span = attributeValueSpans.get(name);
|
|
190
|
+
if (span === void 0) panic("Missing imported identity source span");
|
|
191
|
+
const offset = span.start;
|
|
192
|
+
const first = seen.get(key);
|
|
193
|
+
if (first === void 0) {
|
|
194
|
+
seen.set(key, {
|
|
195
|
+
part,
|
|
196
|
+
offset
|
|
197
|
+
});
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
scoped.warn({
|
|
201
|
+
code: PARSE_WARNING_CODES.duplicateImportedId,
|
|
202
|
+
identityKind: kind,
|
|
203
|
+
element: element.name,
|
|
204
|
+
at: `offset ${offset}`,
|
|
205
|
+
value,
|
|
206
|
+
detail: `${kind} identity repeats the definition at offset ${first.offset} in ${first.part}.`
|
|
207
|
+
});
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
//#endregion
|
|
215
|
+
export { IMPORTED_ID_COLLISION_REGISTRY, diagnoseImportedIdCollisions };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { document_d_exports } from "../types/document.js";
|
|
2
|
+
import { DocumentOp } from "@stll/docx-core/ops";
|
|
3
|
+
//#region src/docx/listModelNormalization.d.ts
|
|
4
|
+
type CanonicalListNormalization = {
|
|
5
|
+
document: document_d_exports.Document;
|
|
6
|
+
inverse: DocumentOp[];
|
|
7
|
+
};
|
|
8
|
+
declare const normalizeListModelRendering: (document: document_d_exports.Document) => CanonicalListNormalization;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { normalizeListModelRendering };
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { effectiveParagraphNumberingReference, paragraphNumberingSourcesFromBoundary } from "../prosemirror/numberingAttr.js";
|
|
2
|
+
import { paragraphIndentationFromFormatting } from "../prosemirror/paragraphIndentation.js";
|
|
3
|
+
import { listIndentationProvenancePatch } from "../prosemirror/styles/resolvedStyleAttrs.js";
|
|
4
|
+
import { createStyleResolver } from "../prosemirror/styles/styleResolver.js";
|
|
5
|
+
import { canonicalJson } from "../utils/canonicalJson.js";
|
|
6
|
+
import { foldListNumberFields, planParagraphListNumberFold, unfoldedListNumberContent } from "./foldedListNumberFields.js";
|
|
7
|
+
import { computeListMarker } from "./listMarkerComputation.js";
|
|
8
|
+
import { listRenderingDefinitionsMatch } from "./listRendering.js";
|
|
9
|
+
import { computeListRendering, getCachedNumberingMap } from "./numberingParser.js";
|
|
10
|
+
import { assignParagraphIndentationProjection, cloneParagraphWithPropertySource, paragraphFormattingWithAuthoredIndentation, sameParagraphIndentationProjection } from "./paragraphPropertySource.js";
|
|
11
|
+
import { panic } from "better-result";
|
|
12
|
+
import { DOCUMENT_OP_TYPES, EMPTY_PROPERTY_SETS, OP_STORIES, registerParagraphPropertySnapshot, withBodyContent } from "@stll/docx-core/ops";
|
|
13
|
+
//#region src/docx/listModelNormalization.ts
|
|
14
|
+
/** Canonical edits retain authored fields; list rendering follows the current numbering. */
|
|
15
|
+
const normalizeListModelRendering = (document) => {
|
|
16
|
+
const inverse = [];
|
|
17
|
+
const styles = createStyleResolver(document.package.styles);
|
|
18
|
+
const numbering = document.package.numbering === void 0 ? null : getCachedNumberingMap(document.package.numbering);
|
|
19
|
+
const normalizeBody = (body, story) => {
|
|
20
|
+
const counters = {
|
|
21
|
+
numbering,
|
|
22
|
+
listCounters: /* @__PURE__ */ new Map(),
|
|
23
|
+
abstractCounters: /* @__PURE__ */ new Map(),
|
|
24
|
+
restartedNumIds: /* @__PURE__ */ new Set(),
|
|
25
|
+
previousList: {
|
|
26
|
+
abstractNumId: null,
|
|
27
|
+
fromStyle: false,
|
|
28
|
+
numId: null
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const content = body.content.map((paragraph) => {
|
|
32
|
+
if (paragraph.type !== "paragraph") return paragraph;
|
|
33
|
+
registerParagraphPropertySnapshot({
|
|
34
|
+
paragraph,
|
|
35
|
+
snapshot: paragraphFormattingWithAuthoredIndentation(paragraph)
|
|
36
|
+
});
|
|
37
|
+
const formatting = paragraph.formatting;
|
|
38
|
+
const next = cloneParagraphWithPropertySource(paragraph, {});
|
|
39
|
+
const styleNumbering = formatting?.styleId ? styles.resolveParagraphStyle(formatting.styleId).paragraphFormatting?.numPr : void 0;
|
|
40
|
+
if (styleNumbering !== void 0 && (formatting?.numPr === void 0 || formatting.numPr.kind === "levelOnly")) next.formatting = {
|
|
41
|
+
...formatting,
|
|
42
|
+
numPrFromStyle: styleNumbering
|
|
43
|
+
};
|
|
44
|
+
if (formatting?.numPrFromStyle !== void 0 && (formatting.styleId !== void 0 && styleNumbering === void 0 || formatting.numPr?.kind === "reference" || formatting.numPr?.kind === "none")) {
|
|
45
|
+
next.formatting = { ...formatting };
|
|
46
|
+
delete next.formatting.numPrFromStyle;
|
|
47
|
+
}
|
|
48
|
+
if (canonicalJson(next.formatting?.numPrFromStyle) !== canonicalJson(formatting?.numPrFromStyle)) inverse.unshift({
|
|
49
|
+
type: DOCUMENT_OP_TYPES.SET_PARAGRAPH_PROPS,
|
|
50
|
+
story,
|
|
51
|
+
blockId: paragraph.paraId ?? panic("List normalization requires paragraph identities."),
|
|
52
|
+
patch: { numPrFromStyle: formatting?.numPrFromStyle ?? null },
|
|
53
|
+
whenEmpty: formatting === void 0 ? EMPTY_PROPERTY_SETS.OMIT : EMPTY_PROPERTY_SETS.KEEP
|
|
54
|
+
});
|
|
55
|
+
const numPr = effectiveParagraphNumberingReference(paragraphNumberingSourcesFromBoundary({
|
|
56
|
+
numPr: next.formatting?.numPr,
|
|
57
|
+
numPrFromStyle: next.formatting?.numPrFromStyle
|
|
58
|
+
}));
|
|
59
|
+
if (paragraph.listRendering === void 0 && formatting?.numPrFromStyle === void 0 && next.formatting?.numPrFromStyle === void 0 && (numPr?.kind !== "reference" || numbering === null)) {
|
|
60
|
+
computeListMarker(paragraph, counters);
|
|
61
|
+
return paragraph;
|
|
62
|
+
}
|
|
63
|
+
const definition = numPr?.kind === "reference" && numbering !== null ? computeListRendering(numPr, numbering) : null;
|
|
64
|
+
const cached = paragraph.listRendering;
|
|
65
|
+
const rendering = definition !== null && cached !== void 0 && listRenderingDefinitionsMatch(cached, definition) ? { ...cached } : definition;
|
|
66
|
+
const authoredFormatting = paragraphFormattingWithAuthoredIndentation(next);
|
|
67
|
+
assignParagraphIndentationProjection({
|
|
68
|
+
paragraph: next,
|
|
69
|
+
authored: authoredFormatting,
|
|
70
|
+
inherited: paragraphIndentationFromFormatting(listIndentationProvenancePatch({
|
|
71
|
+
direct: paragraphIndentationFromFormatting(authoredFormatting),
|
|
72
|
+
styleFormatting: styles.resolveParagraphStyle(next.formatting?.styleId).paragraphFormatting,
|
|
73
|
+
numberingSource: next.formatting?.numPr?.kind === "reference" || next.formatting?.numPrFromStyle === void 0 ? "paragraph" : "style",
|
|
74
|
+
numPr: numPr?.kind === "reference" ? {
|
|
75
|
+
numId: numPr.numId,
|
|
76
|
+
ilvl: numPr.ilvl ?? 0
|
|
77
|
+
} : void 0,
|
|
78
|
+
numbering
|
|
79
|
+
})._resolvedFormatting) ?? {}
|
|
80
|
+
});
|
|
81
|
+
if (canonicalJson(paragraphIndentationFromFormatting(next.formatting)) !== canonicalJson(paragraphIndentationFromFormatting(formatting))) inverse.unshift({
|
|
82
|
+
type: DOCUMENT_OP_TYPES.SET_PARAGRAPH_PROPS,
|
|
83
|
+
story,
|
|
84
|
+
blockId: paragraph.paraId ?? panic("Canonical numbering normalization requires paragraph identities."),
|
|
85
|
+
patch: {
|
|
86
|
+
indentLeft: formatting?.indentLeft ?? null,
|
|
87
|
+
indentRight: formatting?.indentRight ?? null,
|
|
88
|
+
indentFirstLine: formatting?.indentFirstLine ?? null,
|
|
89
|
+
hangingIndent: formatting?.hangingIndent ?? null
|
|
90
|
+
},
|
|
91
|
+
whenEmpty: formatting === void 0 ? EMPTY_PROPERTY_SETS.OMIT : EMPTY_PROPERTY_SETS.KEEP
|
|
92
|
+
});
|
|
93
|
+
if (rendering === null) delete next.listRendering;
|
|
94
|
+
else {
|
|
95
|
+
const fields = foldListNumberFields(paragraph.content.map(unfoldedListNumberContent), () => void 0).fieldCount;
|
|
96
|
+
if (fields === 0) delete rendering.implicitChildLevelAdvances;
|
|
97
|
+
else rendering.implicitChildLevelAdvances = fields;
|
|
98
|
+
const template = rendering.markerTemplate ?? rendering.marker;
|
|
99
|
+
const fold = planParagraphListNumberFold(paragraph.content, !rendering.isBullet && template !== "" && !template.includes(" "));
|
|
100
|
+
if (fold.suffix === void 0) delete rendering.foldedMarkerSuffix;
|
|
101
|
+
else rendering.foldedMarkerSuffix = fold.suffix;
|
|
102
|
+
const child = numbering?.getLevel(rendering.numId, rendering.level + 1)?.pPr;
|
|
103
|
+
if (fold.suffix !== void 0 && child?.hangingIndent === true && child.indentFirstLine !== void 0 && child.indentFirstLine < 0) rendering.markerSecondSlotOffsetTwips = -child.indentFirstLine;
|
|
104
|
+
else delete rendering.markerSecondSlotOffsetTwips;
|
|
105
|
+
rendering.marker = rendering.foldedMarkerSuffix !== void 0 && !template.includes(" ") ? `${template}\t${rendering.foldedMarkerSuffix}` : template;
|
|
106
|
+
next.listRendering = rendering;
|
|
107
|
+
}
|
|
108
|
+
computeListMarker(next, counters);
|
|
109
|
+
registerParagraphPropertySnapshot({
|
|
110
|
+
paragraph: next,
|
|
111
|
+
snapshot: authoredFormatting
|
|
112
|
+
});
|
|
113
|
+
if (sameParagraphIndentationProjection({
|
|
114
|
+
left: next,
|
|
115
|
+
right: paragraph
|
|
116
|
+
}) && canonicalJson(next.formatting) === canonicalJson(formatting) && canonicalJson(next.listRendering) === canonicalJson(cached)) return paragraph;
|
|
117
|
+
return next;
|
|
118
|
+
});
|
|
119
|
+
return content.every((paragraph, index) => paragraph === body.content[index]) ? body : {
|
|
120
|
+
...body,
|
|
121
|
+
...withBodyContent(body, content)
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
const pkg = document.package;
|
|
125
|
+
const body = normalizeBody(pkg.document, OP_STORIES.MAIN);
|
|
126
|
+
const normalizeParts = (parts, kind) => {
|
|
127
|
+
if (parts === void 0) return parts;
|
|
128
|
+
const normalized = new Map([...parts].map(([id, part]) => [id, normalizeBody(part, {
|
|
129
|
+
kind,
|
|
130
|
+
rId: id
|
|
131
|
+
})]));
|
|
132
|
+
return [...normalized].every(([id, part]) => part === parts.get(id)) ? parts : normalized;
|
|
133
|
+
};
|
|
134
|
+
const normalizeNotes = (notes, kind) => {
|
|
135
|
+
if (notes === void 0) return notes;
|
|
136
|
+
const normalized = notes.map((note) => normalizeBody(note, {
|
|
137
|
+
kind,
|
|
138
|
+
id: note.id
|
|
139
|
+
}));
|
|
140
|
+
return normalized.every((note, index) => note === notes[index]) ? notes : normalized;
|
|
141
|
+
};
|
|
142
|
+
const headers = normalizeParts(pkg.headers, "header");
|
|
143
|
+
const footers = normalizeParts(pkg.footers, "footer");
|
|
144
|
+
const footnotes = normalizeNotes(pkg.footnotes, "footnote");
|
|
145
|
+
const endnotes = normalizeNotes(pkg.endnotes, "endnote");
|
|
146
|
+
if (body === pkg.document && headers === pkg.headers && footers === pkg.footers && footnotes === pkg.footnotes && endnotes === pkg.endnotes) return {
|
|
147
|
+
document,
|
|
148
|
+
inverse
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
inverse,
|
|
152
|
+
document: {
|
|
153
|
+
...document,
|
|
154
|
+
package: {
|
|
155
|
+
...pkg,
|
|
156
|
+
document: body,
|
|
157
|
+
...headers === void 0 ? {} : { headers },
|
|
158
|
+
...footers === void 0 ? {} : { footers },
|
|
159
|
+
...footnotes === void 0 ? {} : { footnotes },
|
|
160
|
+
...endnotes === void 0 ? {} : { endnotes }
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
//#endregion
|
|
166
|
+
export { normalizeListModelRendering };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { decodeText, encodeUtf8 } from "../utils/textEncoding.js";
|
|
1
2
|
import { countCentralDirectoryRecords, createInflationBudget, inflateEntryWithinLimits } from "./archiveInflation.js";
|
|
2
3
|
import { elementToXml, getLocalName, parseXmlDocument } from "./xmlParser.js";
|
|
3
4
|
import { TaggedError } from "better-result";
|
|
@@ -131,7 +132,7 @@ const readCoreProperties = async (entry) => {
|
|
|
131
132
|
message: "Document privacy core properties exceeded the part-size limit",
|
|
132
133
|
reason: "core-properties-too-large"
|
|
133
134
|
});
|
|
134
|
-
return
|
|
135
|
+
return decodeText(result.bytes, { ignoreBOM: true });
|
|
135
136
|
};
|
|
136
137
|
/** Rewrite selected package metadata fields without changing other package parts. */
|
|
137
138
|
const rewriteDocxMetadataPrivacy = async (buffer, { transforms }) => {
|
|
@@ -156,7 +157,7 @@ const rewriteDocxMetadataPrivacy = async (buffer, { transforms }) => {
|
|
|
156
157
|
writeZipPart({
|
|
157
158
|
zip,
|
|
158
159
|
path: coreProperties.name,
|
|
159
|
-
data: rewritten.xml
|
|
160
|
+
data: encodeUtf8(rewritten.xml)
|
|
160
161
|
});
|
|
161
162
|
return {
|
|
162
163
|
buffer: await zip.generateAsync({
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { decodeText } from "../utils/textEncoding.js";
|
|
1
2
|
//#region src/docx/metafileRaster.ts
|
|
2
3
|
function indexOfBytes(haystack, needle, from = 0) {
|
|
3
4
|
outer: for (let i = from; i + needle.length <= haystack.length; i++) {
|
|
@@ -25,7 +26,7 @@ function extractPng(bytes) {
|
|
|
25
26
|
const b2 = bytes[off + 2];
|
|
26
27
|
const b3 = bytes[off + 3];
|
|
27
28
|
const len = b0 << 24 | b1 << 16 | b2 << 8 | b3;
|
|
28
|
-
const type =
|
|
29
|
+
const type = decodeText(bytes.subarray(off + 4, off + 8), { encoding: "binary" });
|
|
29
30
|
const next = off + 12 + (len >>> 0);
|
|
30
31
|
if (type === "IEND") return bytes.slice(start, off + 12);
|
|
31
32
|
if (next <= off || next > bytes.length) break;
|
|
@@ -398,9 +398,9 @@ function getCachedNumberingMap(definitions) {
|
|
|
398
398
|
*/
|
|
399
399
|
function createNumberingMap(definitions) {
|
|
400
400
|
const abstractMap = /* @__PURE__ */ new Map();
|
|
401
|
-
for (const abs of definitions.abstractNums) abstractMap.set(abs.abstractNumId, abs);
|
|
401
|
+
for (const abs of definitions.abstractNums) if (!abstractMap.has(abs.abstractNumId)) abstractMap.set(abs.abstractNumId, abs);
|
|
402
402
|
const numMap = /* @__PURE__ */ new Map();
|
|
403
|
-
for (const num of definitions.nums) numMap.set(num.numId, num);
|
|
403
|
+
for (const num of definitions.nums) if (!numMap.has(num.numId)) numMap.set(num.numId, num);
|
|
404
404
|
return {
|
|
405
405
|
definitions,
|
|
406
406
|
getLevel(numId, ilvl) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { decodeText, encodeUtf8 } from "../utils/textEncoding.js";
|
|
1
2
|
import { Result } from "better-result";
|
|
2
3
|
import { writeZipPart } from "@stll/docx-core/zip";
|
|
3
4
|
//#region src/docx/packageParts.ts
|
|
@@ -124,7 +125,7 @@ const readRelationshipParts = async (zip) => {
|
|
|
124
125
|
if (file.dir || !normalizePartPath(path).endsWith(".rels")) continue;
|
|
125
126
|
parts.push({
|
|
126
127
|
path,
|
|
127
|
-
xml: await file.async("
|
|
128
|
+
xml: await file.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }))
|
|
128
129
|
});
|
|
129
130
|
}
|
|
130
131
|
return parts;
|
|
@@ -133,7 +134,7 @@ const writePart = ({ zip, path, xml, compressionLevel }) => {
|
|
|
133
134
|
writeZipPart({
|
|
134
135
|
zip,
|
|
135
136
|
path,
|
|
136
|
-
data: xml,
|
|
137
|
+
data: encodeUtf8(xml),
|
|
137
138
|
options: {
|
|
138
139
|
compression: "DEFLATE",
|
|
139
140
|
compressionOptions: { level: compressionLevel }
|
|
@@ -186,7 +187,7 @@ const reconcilePackageReferences = async (zip, compressionLevel) => {
|
|
|
186
187
|
if (!file) continue;
|
|
187
188
|
const idPattern = [...ids].map((id) => escapeRegExp(id)).join("|");
|
|
188
189
|
const referencePattern = new RegExp(`\\s+r:[A-Za-z]+\\s*=\\s*(?<quote>["'])(?<id>${idPattern})\\k<quote>`, "gu");
|
|
189
|
-
const xml = await file.async("
|
|
190
|
+
const xml = await file.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
190
191
|
const removedIds = /* @__PURE__ */ new Set();
|
|
191
192
|
const scrubbed = xml.replaceAll(referencePattern, (...args) => {
|
|
192
193
|
const groups = args.at(-1);
|
|
@@ -206,7 +207,7 @@ const reconcilePackageReferences = async (zip, compressionLevel) => {
|
|
|
206
207
|
const contentTypes = zip.file(CONTENT_TYPES_PATTERN)[0];
|
|
207
208
|
if (!contentTypes) return repair;
|
|
208
209
|
let droppedOverride = false;
|
|
209
|
-
const prunedContentTypes = (await contentTypes.async("
|
|
210
|
+
const prunedContentTypes = (await contentTypes.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }))).replaceAll(CONTENT_TYPE_ELEMENT, (element) => {
|
|
210
211
|
const partName = PART_NAME_ATTRIBUTE.exec(element)?.groups?.["value"];
|
|
211
212
|
if (partName === void 0 || isPresent(present, partName)) return element;
|
|
212
213
|
repair.danglingOverrides.push(normalizePartPath(decodePartName(partName) ?? partName));
|
|
@@ -256,7 +257,7 @@ const checkPackageIntegrity = async (zip) => {
|
|
|
256
257
|
}
|
|
257
258
|
for (const [path, file] of Object.entries(zip.files)) {
|
|
258
259
|
if (file.dir || !normalizePartPath(path).endsWith(".xml")) continue;
|
|
259
|
-
const xml = await file.async("
|
|
260
|
+
const xml = await file.async("uint8array").then((bytes) => decodeText(bytes, { ignoreBOM: true }));
|
|
260
261
|
const ids = idsByOwningPart.get(path);
|
|
261
262
|
for (const match of xml.matchAll(REFERENCE_ATTRIBUTE)) {
|
|
262
263
|
const id = match.groups?.["id"];
|
|
@@ -52,16 +52,18 @@ function extractMathText(el) {
|
|
|
52
52
|
* Capture the authored paragraph properties separately from structural and
|
|
53
53
|
* revision children, which have their own model fields and lifecycles.
|
|
54
54
|
*/
|
|
55
|
-
const captureParagraphPropertySource = (pPr) => captureVerbatimXml(cloneElement(pPr, { elements: (pPr.elements ?? []).flatMap((child) => {
|
|
55
|
+
const captureParagraphPropertySource = (pPr, paragraph) => captureVerbatimXml(cloneElement(pPr, { elements: (pPr.elements ?? []).flatMap((child) => {
|
|
56
56
|
if (child.type !== "element") return [child];
|
|
57
57
|
const localName = getLocalName(child.name);
|
|
58
58
|
if (WORDPROCESSINGML_NAMESPACE_URIS.has(child.namespaceUri ?? "") && (localName === "sectPr" || localName === "pPrChange")) return [];
|
|
59
59
|
if (localName !== "rPr" || !WORDPROCESSINGML_NAMESPACE_URIS.has(child.namespaceUri ?? "")) return [child];
|
|
60
|
-
|
|
60
|
+
const elements = (child.elements ?? []).filter((runProperty) => {
|
|
61
61
|
if (runProperty.type !== "element") return true;
|
|
62
62
|
const runPropertyName = getLocalName(runProperty.name);
|
|
63
63
|
return !WORDPROCESSINGML_NAMESPACE_URIS.has(runProperty.namespaceUri ?? "") || !PARAGRAPH_MARK_CHANGE_KINDS.some((kind) => kind === runPropertyName);
|
|
64
|
-
})
|
|
64
|
+
});
|
|
65
|
+
if (paragraph.formatting?.runProperties === void 0 && elements.every((element) => element.type === "text" && (element.text === void 0 || typeof element.text === "string" && element.text.trim() === ""))) return [];
|
|
66
|
+
return [cloneElement(child, { elements })];
|
|
65
67
|
}) }));
|
|
66
68
|
const RENDERED_BREAK_INLINE_WRAPPERS = /* @__PURE__ */ new Set([
|
|
67
69
|
"hyperlink",
|
|
@@ -1328,7 +1330,7 @@ function parseParagraph(node, styles, theme, numbering, rels = null, media = nul
|
|
|
1328
1330
|
}
|
|
1329
1331
|
}
|
|
1330
1332
|
}
|
|
1331
|
-
if (pPr) assignParagraphPropertySource(paragraph, captureParagraphPropertySource(pPr));
|
|
1333
|
+
if (pPr) assignParagraphPropertySource(paragraph, captureParagraphPropertySource(pPr, paragraph));
|
|
1332
1334
|
return paragraph;
|
|
1333
1335
|
}
|
|
1334
1336
|
/**
|