@stll/folio-core 0.54.2 → 0.56.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.js +185 -33
- package/dist/ai-edits/headless.js +3 -2
- package/dist/ai-edits/types.d.ts +7 -1
- package/dist/compare/compare.js +1 -0
- package/dist/compare/content-types.d.ts +3 -15
- package/dist/compare/reproducible-package.d.ts +0 -17
- package/dist/compare/reproducible-package.js +12 -18
- package/dist/controller/canonicalClipboard.d.ts +23 -0
- package/dist/controller/canonicalClipboard.js +476 -0
- package/dist/controller/canonicalClipboardResources.d.ts +21 -0
- package/dist/controller/canonicalClipboardResources.js +382 -0
- package/dist/controller/canonicalComposition.d.ts +53 -0
- package/dist/controller/canonicalComposition.js +296 -0
- package/dist/controller/canonicalInlineProjection.d.ts +113 -0
- package/dist/controller/canonicalInlineProjection.js +393 -0
- package/dist/controller/canonicalInput.d.ts +54 -0
- package/dist/controller/canonicalInput.js +377 -0
- package/dist/controller/canonicalInputTimer.d.ts +7 -0
- package/dist/controller/canonicalInputTimer.js +11 -0
- package/dist/controller/canonicalOperations.d.ts +22 -0
- package/dist/controller/canonicalOperations.js +85 -0
- package/dist/controller/canonicalPublicOperations.d.ts +48 -0
- package/dist/controller/canonicalPublicOperations.js +556 -0
- package/dist/controller/canonicalReview.d.ts +12 -0
- package/dist/controller/canonicalReview.js +19 -0
- package/dist/controller/canonicalSession.d.ts +167 -0
- package/dist/controller/canonicalSession.js +1186 -0
- package/dist/controller/canonicalStoryEditor.d.ts +36 -0
- package/dist/controller/canonicalStoryEditor.js +87 -0
- package/dist/controller/canonicalStructure.d.ts +16 -0
- package/dist/controller/canonicalStructure.js +322 -0
- package/dist/controller/canonicalTocSelection.d.ts +11 -0
- package/dist/controller/canonicalTocSelection.js +43 -0
- package/dist/controller/folioEditor.d.ts +3 -10
- package/dist/controller/folioEditor.js +14 -4
- package/dist/controller/headerFooterEditorManager.d.ts +5 -0
- package/dist/controller/headerFooterEditorManager.js +72 -3
- package/dist/controller/hiddenEditorApi.d.ts +45 -0
- package/dist/controller/hiddenEditorApi.js +29 -8
- package/dist/controller/hiddenEditorManager.d.ts +13 -2
- package/dist/controller/hiddenEditorManager.js +639 -31
- package/dist/controller/layoutPipeline.d.ts +1 -1
- package/dist/controller/layoutPipeline.js +2 -0
- package/dist/controller/noteEditorManager.d.ts +5 -0
- package/dist/controller/noteEditorManager.js +114 -15
- package/dist/document-operations.d.ts +8 -1
- package/dist/document-operations.js +6 -4
- package/dist/docx/attributeRemainder.js +1 -0
- package/dist/docx/blockPlainText.d.ts +1 -1
- package/dist/docx/blockPlainText.js +11 -3
- package/dist/docx/canonicalResourceSave.d.ts +16 -0
- package/dist/docx/canonicalResourceSave.js +27 -0
- package/dist/docx/canonicalSave.d.ts +29 -0
- package/dist/docx/canonicalSave.js +101 -0
- package/dist/docx/canonicalSessionInput.d.ts +11 -0
- package/dist/docx/canonicalSessionInput.js +27 -0
- package/dist/docx/canonicalStoryRepack.d.ts +10 -0
- package/dist/docx/canonicalStoryRepack.js +74 -0
- package/dist/docx/contentTypeRegistry.d.ts +8 -0
- package/dist/docx/contentTypeRegistry.js +64 -0
- package/dist/docx/documentParser.d.ts +1 -13
- package/dist/docx/documentParser.js +1 -47
- package/dist/docx/ensureParaIds.d.ts +7 -1
- package/dist/docx/ensureParaIds.js +173 -215
- package/dist/docx/foldedListNumberFields.d.ts +85 -0
- package/dist/docx/foldedListNumberFields.js +267 -0
- package/dist/docx/footnoteParser.d.ts +1 -11
- package/dist/docx/footnoteParser.js +1 -16
- package/dist/docx/headerFooterParser.d.ts +1 -9
- package/dist/docx/headerFooterParser.js +1 -12
- package/dist/docx/headerFooterVerbatim.d.ts +39 -1
- package/dist/docx/headerFooterVerbatim.js +173 -2
- package/dist/docx/imageParser.d.ts +13 -1
- package/dist/docx/imageParser.js +20 -11
- package/dist/docx/metadataPrivacy.js +6 -1
- package/dist/docx/noteIds.d.ts +5 -0
- package/dist/docx/noteIds.js +6 -2
- package/dist/docx/noteReferenceMark.d.ts +3 -1
- package/dist/docx/noteReferenceMark.js +15 -14
- package/dist/docx/numberingParser.d.ts +3 -1
- package/dist/docx/numberingParser.js +17 -3
- package/dist/docx/packageParts.d.ts +3 -1
- package/dist/docx/packageParts.js +74 -19
- package/dist/docx/paragraphMarkPropertyPresence.d.ts +9 -0
- package/dist/docx/paragraphMarkPropertyPresence.js +21 -0
- package/dist/docx/paragraphParser.js +101 -53
- package/dist/docx/paragraphPropertySource.d.ts +15 -1
- package/dist/docx/paragraphPropertySource.js +77 -22
- package/dist/docx/parser.js +3 -1
- package/dist/docx/removeHeaderFooterParts.js +17 -6
- package/dist/docx/reviewHistoryNamespace.d.ts +4 -0
- package/dist/docx/reviewHistoryNamespace.js +4 -0
- package/dist/docx/reviewResolutionProvenance.d.ts +25 -0
- package/dist/docx/reviewResolutionProvenance.js +153 -0
- package/dist/docx/rezip.d.ts +54 -6
- package/dist/docx/rezip.js +835 -257
- package/dist/docx/runConsolidator.d.ts +2 -58
- package/dist/docx/runConsolidator.js +3 -175
- package/dist/docx/runParser.d.ts +2 -1
- package/dist/docx/runParser.js +156 -116
- package/dist/docx/saveDiagnostics.d.ts +22 -0
- package/dist/docx/saveDiagnostics.js +0 -0
- package/dist/docx/selectiveSave.d.ts +3 -1
- package/dist/docx/selectiveSave.js +36 -4
- package/dist/docx/selectiveXmlPatch.d.ts +16 -8
- package/dist/docx/selectiveXmlPatch.js +81 -7
- package/dist/docx/serializer/documentSerializer.d.ts +9 -2
- package/dist/docx/serializer/documentSerializer.js +29 -10
- package/dist/docx/serializer/headerFooterSerializer.d.ts +5 -1
- package/dist/docx/serializer/headerFooterSerializer.js +19 -11
- package/dist/docx/serializer/noteSerializer.d.ts +2 -2
- package/dist/docx/serializer/noteSerializer.js +24 -8
- package/dist/docx/serializer/paragraphSerializer.js +41 -4
- package/dist/docx/serializer/partNamespaces.js +2 -1
- package/dist/docx/serializer/runSerializer.js +3 -1
- package/dist/docx/server/applyDocxXmlPatchProposal.js +14 -9
- package/dist/docx/settingsHeaderFooterUpdate.d.ts +5 -0
- package/dist/docx/settingsHeaderFooterUpdate.js +90 -0
- package/dist/docx/settingsParser.d.ts +1 -2
- package/dist/docx/settingsParser.js +5 -6
- package/dist/docx/storyBlockReplay.d.ts +31 -0
- package/dist/docx/storyBlockReplay.js +471 -0
- package/dist/docx/storyPlainText.d.ts +20 -0
- package/dist/docx/storyPlainText.js +23 -0
- package/dist/docx/streamingXmlParser.d.ts +22 -1
- package/dist/docx/streamingXmlParser.js +49 -3
- package/dist/docx/structuralXmlPatch.js +18 -23
- package/dist/docx/styleParser.d.ts +5 -1
- package/dist/docx/styleParser.js +1 -1
- package/dist/docx/tableParser.d.ts +1 -8
- package/dist/docx/tableParser.js +1 -28
- package/dist/docx/textBoxParser.d.ts +1 -5
- package/dist/docx/textBoxParser.js +1 -20
- package/dist/docx/unzip.js +6 -1
- package/dist/docx/verbatimCapture.d.ts +3 -1
- package/dist/docx/verbatimCapture.js +49 -6
- package/dist/i18n/messages/ar.gen.d.ts +5 -0
- package/dist/i18n/messages/ar.gen.js +656 -0
- package/dist/i18n/messages/cs.gen.d.ts +5 -0
- package/dist/i18n/messages/cs.gen.js +656 -0
- package/dist/i18n/messages/de.gen.d.ts +5 -0
- package/dist/i18n/messages/de.gen.js +656 -0
- package/dist/i18n/messages/en.gen.d.ts +5 -0
- package/dist/i18n/messages/en.gen.js +656 -0
- package/dist/i18n/messages/es.gen.d.ts +5 -0
- package/dist/i18n/messages/es.gen.js +656 -0
- package/dist/i18n/messages/et.gen.d.ts +5 -0
- package/dist/i18n/messages/et.gen.js +656 -0
- package/dist/i18n/messages/fr.gen.d.ts +5 -0
- package/dist/i18n/messages/fr.gen.js +656 -0
- package/dist/i18n/messages/he.gen.d.ts +5 -0
- package/dist/i18n/messages/he.gen.js +656 -0
- package/dist/i18n/messages/hi.gen.d.ts +5 -0
- package/dist/i18n/messages/hi.gen.js +656 -0
- package/dist/i18n/messages/hu.gen.d.ts +5 -0
- package/dist/i18n/messages/hu.gen.js +656 -0
- package/dist/i18n/messages/locales.d.ts +5 -0
- package/dist/i18n/messages/locales.js +22 -0
- package/dist/i18n/messages/lt.gen.d.ts +5 -0
- package/dist/i18n/messages/lt.gen.js +656 -0
- package/dist/i18n/messages/lv.gen.d.ts +5 -0
- package/dist/i18n/messages/lv.gen.js +656 -0
- package/dist/i18n/messages/pl.gen.d.ts +5 -0
- package/dist/i18n/messages/pl.gen.js +656 -0
- package/dist/i18n/messages/pt-BR.gen.d.ts +5 -0
- package/dist/i18n/messages/pt-BR.gen.js +656 -0
- package/dist/i18n/messages/sk.gen.d.ts +5 -0
- package/dist/i18n/messages/sk.gen.js +656 -0
- package/dist/i18n/messages/tr.gen.d.ts +5 -0
- package/dist/i18n/messages/tr.gen.js +656 -0
- package/dist/i18n/messages/zh-CN.gen.d.ts +5 -0
- package/dist/i18n/messages/zh-CN.gen.js +656 -0
- package/dist/i18n/messages.d.ts +2 -3
- package/dist/i18n/messages.js +1 -19
- package/dist/internal/acceptedBlockProjection.d.ts +12 -0
- package/dist/internal/acceptedBlockProjection.js +45 -0
- package/dist/internal/noteMarkerAttrs.d.ts +8 -0
- package/dist/internal/noteMarkerAttrs.js +16 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +1 -0
- package/dist/internal/prosemirrorAttrBoundary.d.ts +21 -0
- package/dist/internal/prosemirrorAttrBoundary.js +50 -0
- package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
- package/dist/layout-bridge/convert/footnoteLayout.js +3 -3
- package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
- package/dist/layout-bridge/convert/headerFooterLayout.js +1 -0
- package/dist/layout-bridge/convert/noteReferences.d.ts +1 -3
- package/dist/layout-bridge/convert/noteReferences.js +1 -6
- package/dist/layout-bridge/convert/paragraphRuns.js +2 -4
- package/dist/layout-bridge/convert/toFlowBlocks.d.ts +2 -2
- package/dist/layout-bridge/convert/toFlowBlocks.js +2 -2
- package/dist/managers/DocumentLoaderManager.d.ts +1 -0
- package/dist/managers/DocumentLoaderManager.js +9 -1
- package/dist/markdown/escape.d.ts +3 -1
- package/dist/markdown/escape.js +9 -2
- package/dist/markdown/renderBlock.js +20 -121
- package/dist/markdown/renderParagraph.js +13 -15
- package/dist/markdown/renderRuns.d.ts +7 -1
- package/dist/markdown/renderRuns.js +35 -15
- package/dist/markdown/renderTable.js +2 -0
- package/dist/markdown/types.d.ts +3 -9
- package/dist/prosemirror/attrs/index.d.ts +2 -12
- package/dist/prosemirror/attrs/index.js +22 -48
- package/dist/prosemirror/bookmarkBoundaryAttrs.d.ts +2 -1
- package/dist/prosemirror/canonicalCommands.d.ts +121 -0
- package/dist/prosemirror/canonicalCommands.js +35 -0
- package/dist/prosemirror/canonicalSelectionRange.d.ts +9 -0
- package/dist/prosemirror/canonicalSelectionRange.js +15 -0
- package/dist/prosemirror/clipboardIntent.d.ts +7 -0
- package/dist/prosemirror/clipboardIntent.js +9 -0
- package/dist/prosemirror/commands/pageBreak.js +15 -1
- package/dist/prosemirror/commands/pastePlainText.js +2 -1
- package/dist/prosemirror/commentReferenceAttrs.d.ts +2 -1
- package/dist/prosemirror/conversion/fromProseDoc.js +91 -19
- package/dist/prosemirror/conversion/hyphenTextCarriers.d.ts +8 -0
- package/dist/prosemirror/conversion/hyphenTextCarriers.js +8 -0
- package/dist/prosemirror/conversion/listRenderingDefinition.d.ts +6 -0
- package/dist/prosemirror/conversion/listRenderingDefinition.js +97 -0
- package/dist/prosemirror/conversion/toProseDoc.d.ts +11 -4
- package/dist/prosemirror/conversion/toProseDoc.js +55 -14
- package/dist/prosemirror/executeEditorCommand.d.ts +11 -0
- package/dist/prosemirror/executeEditorCommand.js +26 -0
- package/dist/prosemirror/extensions/StarterKit.js +2 -0
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +88 -48
- package/dist/prosemirror/extensions/features/ListExtension.js +18 -5
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +5 -2
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +13 -1
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +56 -28
- package/dist/prosemirror/extensions/marks/TextColorExtension.js +3 -2
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +2 -0
- package/dist/prosemirror/extensions/marks/markUtils.js +72 -8
- package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.js +36 -0
- package/dist/prosemirror/extensions/nodes/PreservedXmlExtension.js +4 -2
- package/dist/prosemirror/insertOperations.js +2 -1
- package/dist/prosemirror/listMarker.d.ts +1 -0
- package/dist/prosemirror/listMarker.js +16 -7
- package/dist/prosemirror/listNumbering.js +26 -5
- package/dist/prosemirror/listRenderingAttrs.d.ts +1 -0
- package/dist/prosemirror/listRenderingAttrs.js +3 -0
- package/dist/prosemirror/markupViewNotes.js +3 -2
- package/dist/prosemirror/moveRangeBoundaryAttrs.d.ts +2 -1
- package/dist/prosemirror/noteReferenceReview.js +5 -3
- package/dist/prosemirror/paragraphPropertyCarry.d.ts +7 -1
- package/dist/prosemirror/paragraphPropertyCarry.js +8 -3
- package/dist/prosemirror/plugins/suggestionMode.js +57 -7
- package/dist/prosemirror/rangeAnchorAttrs.d.ts +2 -1
- package/dist/prosemirror/runFormattingFromMarks.d.ts +4 -1
- package/dist/prosemirror/runFormattingFromMarks.js +15 -1
- package/dist/prosemirror/runFormattingInlineCarriers.d.ts +2 -1
- package/dist/prosemirror/runFormattingInlineCarriers.js +4 -1
- package/dist/prosemirror/schema/marks.d.ts +2 -0
- package/dist/prosemirror/schema/nodes.d.ts +10 -2
- package/dist/prosemirror/textBoxAnchorAttrs.d.ts +2 -1
- package/dist/prosemirror/textInput.js +5 -1
- package/dist/prosemirror/trackedRevisionPath.js +2 -1
- package/dist/prosemirror/trackedRunInlineAtoms.d.ts +1 -0
- package/dist/prosemirror/trackedRunInlineAtoms.js +1 -0
- package/dist/prosemirror/validation.js +4 -0
- package/dist/types/canonicalCapabilities.d.ts +215 -0
- package/dist/types/canonicalCapabilities.js +212 -0
- package/dist/types/canonicalSave.d.ts +11 -0
- package/dist/types/canonicalSave.js +0 -0
- package/dist/types/content.d.ts +2 -2
- package/dist/types/docxSerialization.d.ts +14 -0
- package/dist/types/docxSerialization.js +7 -0
- package/dist/utils/createDocument.js +2 -2
- package/package.json +16 -4
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { withTrackedSectionEndpointRemoval } from "../internal/sectionEndpointResolution.js";
|
|
2
|
+
import { withSectionReferenceResolution } from "../internal/sectionReferenceResolution.js";
|
|
3
|
+
import { readDocumentSectionFacts } from "./documentSectionFacts.js";
|
|
4
|
+
import { parseDocx } from "./parser.js";
|
|
5
|
+
import { assertSectionCarriersMatchModel } from "./rezip.js";
|
|
6
|
+
import { serializeDocument } from "./serializer/documentSerializer.js";
|
|
7
|
+
import JSZip from "jszip";
|
|
8
|
+
//#region src/docx/canonicalStoryRepack.ts
|
|
9
|
+
/** Canonical snapshots own explicit section references; the PM projection does not. */
|
|
10
|
+
const referenceKey = ({ element, type, rId }) => `${element}:${type}:${rId}`;
|
|
11
|
+
const xmlFingerprint = async (xml) => {
|
|
12
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(xml));
|
|
13
|
+
let fingerprint = "";
|
|
14
|
+
for (const byte of new Uint8Array(digest)) fingerprint += byte.toString(16).padStart(2, "0");
|
|
15
|
+
return fingerprint;
|
|
16
|
+
};
|
|
17
|
+
/** Authorize exact canonical section removals and references missing from the committed snapshot. */
|
|
18
|
+
const repackWithCanonicalStoryRemovals = async ({ document, repack }) => {
|
|
19
|
+
const originalBuffer = document.originalBuffer;
|
|
20
|
+
if (!originalBuffer) return repack();
|
|
21
|
+
const xml = await (await JSZip.loadAsync(originalBuffer)).file("word/document.xml")?.async("text");
|
|
22
|
+
if (!xml) return repack();
|
|
23
|
+
const before = readDocumentSectionFacts(xml);
|
|
24
|
+
const serializedXml = serializeDocument(document);
|
|
25
|
+
const after = readDocumentSectionFacts(serializedXml);
|
|
26
|
+
const remaining = /* @__PURE__ */ new Map();
|
|
27
|
+
for (const reference of after.headerFooterReferences) {
|
|
28
|
+
const key = referenceKey(reference);
|
|
29
|
+
remaining.set(key, (remaining.get(key) ?? 0) + 1);
|
|
30
|
+
}
|
|
31
|
+
const removedReferences = [];
|
|
32
|
+
for (const reference of before.headerFooterReferences) {
|
|
33
|
+
const key = referenceKey(reference);
|
|
34
|
+
const count = remaining.get(key) ?? 0;
|
|
35
|
+
if (count > 0) {
|
|
36
|
+
remaining.set(key, count - 1);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
removedReferences.push({
|
|
40
|
+
part: reference.element === "headerReference" ? "header" : "footer",
|
|
41
|
+
type: reference.type,
|
|
42
|
+
relationshipId: reference.rId
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return withSectionReferenceResolution({
|
|
46
|
+
document,
|
|
47
|
+
removedReferences,
|
|
48
|
+
repack: async () => {
|
|
49
|
+
if (after.sectionCount >= before.sectionCount) return repack();
|
|
50
|
+
const baseline = await parseDocx(originalBuffer, { preloadFonts: false });
|
|
51
|
+
const baselineXml = serializeDocument(baseline);
|
|
52
|
+
const baselineFacts = readDocumentSectionFacts(baselineXml);
|
|
53
|
+
if (baselineFacts.sectionCount !== before.sectionCount) return repack();
|
|
54
|
+
assertSectionCarriersMatchModel({
|
|
55
|
+
doc: baseline,
|
|
56
|
+
serializedSectionCount: baselineFacts.sectionCount
|
|
57
|
+
});
|
|
58
|
+
return withTrackedSectionEndpointRemoval({
|
|
59
|
+
document,
|
|
60
|
+
resolution: {
|
|
61
|
+
type: "tracked-section-endpoint-removal",
|
|
62
|
+
sourceParagraphEndpointCount: before.sectionCount,
|
|
63
|
+
expectedParagraphEndpointCount: after.sectionCount,
|
|
64
|
+
sourceEndpointFingerprint: await xmlFingerprint(baselineXml),
|
|
65
|
+
expectedEndpointFingerprint: await xmlFingerprint(serializedXml),
|
|
66
|
+
removedReferences
|
|
67
|
+
},
|
|
68
|
+
repack
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
//#endregion
|
|
74
|
+
export { repackWithCanonicalStoryRemovals };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/docx/contentTypeRegistry.d.ts
|
|
2
|
+
type ContentTypePart = {
|
|
3
|
+
partName: string;
|
|
4
|
+
contentType: string;
|
|
5
|
+
};
|
|
6
|
+
declare const registerContentTypeParts: (xml: string, parts: readonly ContentTypePart[]) => string;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { registerContentTypeParts };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { resolvePackageRelationshipTarget } from "./packageParts.js";
|
|
2
|
+
import { spliceXml } from "./selectiveXmlPatch.js";
|
|
3
|
+
import { getAttribute, getLocalName, getNamespacePrefix, getNamespaceUri, parseXmlDocument } from "./xmlParser.js";
|
|
4
|
+
import { panic } from "better-result";
|
|
5
|
+
import { escapeXmlAttribute } from "@stll/docx-core";
|
|
6
|
+
import { OOXML_NS } from "@stll/docx-utils";
|
|
7
|
+
//#region src/docx/contentTypeRegistry.ts
|
|
8
|
+
/** Register a package part without rewriting authored content-type entries. */
|
|
9
|
+
const registerContentTypeParts = (xml, parts) => {
|
|
10
|
+
const root = parseXmlDocument(xml);
|
|
11
|
+
if (root?.name === void 0 || getLocalName(root.name) !== "Types" || getNamespaceUri(root) !== OOXML_NS.ct) return panic("The package content-type registry must have a valid Types root.");
|
|
12
|
+
const overrides = /* @__PURE__ */ new Map();
|
|
13
|
+
const defaults = /* @__PURE__ */ new Map();
|
|
14
|
+
for (const element of root.elements ?? []) {
|
|
15
|
+
if (getNamespaceUri(element) !== OOXML_NS.ct) continue;
|
|
16
|
+
const type = getAttribute(element, null, "ContentType");
|
|
17
|
+
if (type === null) continue;
|
|
18
|
+
if (getLocalName(element.name) === "Override") {
|
|
19
|
+
const name = getAttribute(element, null, "PartName");
|
|
20
|
+
const path = name === null ? void 0 : resolvePackageRelationshipTarget(name, "_rels/.rels");
|
|
21
|
+
if (path !== void 0) overrides.set(path, type);
|
|
22
|
+
}
|
|
23
|
+
if (getLocalName(element.name) === "Default") {
|
|
24
|
+
const extension = getAttribute(element, null, "Extension");
|
|
25
|
+
if (extension !== null) defaults.set(extension.toLowerCase(), type);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const prefix = getNamespacePrefix(root.name);
|
|
29
|
+
const name = prefix ? `${prefix}:Override` : "Override";
|
|
30
|
+
const additions = [];
|
|
31
|
+
for (const part of parts) {
|
|
32
|
+
const path = resolvePackageRelationshipTarget(part.partName, "_rels/.rels");
|
|
33
|
+
if (path === void 0) return panic("A registered part must have a safe package URI.");
|
|
34
|
+
const type = overrides.get(path);
|
|
35
|
+
if (type !== void 0) {
|
|
36
|
+
if (type !== part.contentType) return panic("A part's registered content type cannot change.");
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const extension = path.slice(path.lastIndexOf(".") + 1);
|
|
40
|
+
if (defaults.get(extension) === part.contentType) continue;
|
|
41
|
+
additions.push(`<${name} PartName="${escapeXmlAttribute(part.partName)}" ContentType="${escapeXmlAttribute(part.contentType)}"/>`);
|
|
42
|
+
overrides.set(path, part.contentType);
|
|
43
|
+
}
|
|
44
|
+
if (additions.length === 0) return xml;
|
|
45
|
+
for (const token of xml.matchAll(/<!--[\s\S]*?-->|<\?[\s\S]*?\?>|<!\[CDATA\[[\s\S]*?\]\]>|<(?:"[^"]*"|'[^']*'|[^'">])*>/gu)) {
|
|
46
|
+
const markup = token[0];
|
|
47
|
+
if (markup.startsWith("</") && markup.slice(2, -1).trim() === root.name) return spliceXml(xml, [{
|
|
48
|
+
start: token.index,
|
|
49
|
+
end: token.index,
|
|
50
|
+
newXml: additions.join("")
|
|
51
|
+
}]) ?? panic("A registry insertion must preserve XML ranges.");
|
|
52
|
+
if (markup.startsWith(`<${root.name}`) && /[\s/>]/u.test(markup.charAt(root.name.length + 1)) && markup.endsWith("/>")) {
|
|
53
|
+
const end = token.index + markup.length - 2;
|
|
54
|
+
return spliceXml(xml, [{
|
|
55
|
+
start: end,
|
|
56
|
+
end: end + 2,
|
|
57
|
+
newXml: ">" + additions.join("") + `</${root.name}>`
|
|
58
|
+
}]) ?? panic("A registry insertion must preserve XML ranges.");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return panic("A content-type registry needs a closing root boundary.");
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
export { registerContentTypeParts };
|
|
@@ -54,22 +54,10 @@ declare function getAllParagraphs(body: document_d_exports.DocumentBody): docume
|
|
|
54
54
|
* Get all tables from document body
|
|
55
55
|
*/
|
|
56
56
|
declare function getAllTables(body: document_d_exports.DocumentBody): document_d_exports.Table[];
|
|
57
|
-
/**
|
|
58
|
-
* Get plain text from entire document body
|
|
59
|
-
*/
|
|
60
|
-
declare function getDocumentText(body: document_d_exports.DocumentBody): string;
|
|
61
57
|
/**
|
|
62
58
|
* Count total paragraphs in document
|
|
63
59
|
*/
|
|
64
60
|
declare function getParagraphCount(body: document_d_exports.DocumentBody): number;
|
|
65
|
-
/**
|
|
66
|
-
* Count total words in document (approximate)
|
|
67
|
-
*/
|
|
68
|
-
declare function getWordCount(body: document_d_exports.DocumentBody): number;
|
|
69
|
-
/**
|
|
70
|
-
* Count total characters in document
|
|
71
|
-
*/
|
|
72
|
-
declare function getCharacterCount(body: document_d_exports.DocumentBody): number;
|
|
73
61
|
/**
|
|
74
62
|
* Get section count
|
|
75
63
|
*/
|
|
@@ -79,4 +67,4 @@ declare function getSectionCount(body: document_d_exports.DocumentBody): number;
|
|
|
79
67
|
*/
|
|
80
68
|
declare function hasTemplateVariables(body: document_d_exports.DocumentBody): boolean;
|
|
81
69
|
//#endregion
|
|
82
|
-
export { extractAllTemplateVariables, extractTemplateVariables, getAllParagraphs, getAllTables,
|
|
70
|
+
export { extractAllTemplateVariables, extractTemplateVariables, getAllParagraphs, getAllTables, getParagraphCount, getSectionCount, hasTemplateVariables, parseDocumentBody, parseDocumentBodyTree };
|
|
@@ -239,58 +239,12 @@ function getNestedTables(table) {
|
|
|
239
239
|
return tables;
|
|
240
240
|
}
|
|
241
241
|
/**
|
|
242
|
-
* Get plain text from entire document body
|
|
243
|
-
*/
|
|
244
|
-
function getDocumentText(body) {
|
|
245
|
-
const lines = [];
|
|
246
|
-
for (const block of body.content) if (block.type === "paragraph") lines.push(getParagraphText(block));
|
|
247
|
-
else if (block.type === "table") lines.push(getTableText(block));
|
|
248
|
-
else if (block.type === "blockSdt" || block.type === "blockCustomXml") lines.push(getTextFromBlocks(block.content));
|
|
249
|
-
return lines.join("\n");
|
|
250
|
-
}
|
|
251
|
-
const getTextFromBlocks = (blocks) => blocks.flatMap((block) => {
|
|
252
|
-
if (block.type === "paragraph") return [getParagraphText(block)];
|
|
253
|
-
if (block.type === "table") return [getTableText(block)];
|
|
254
|
-
return block.type === "blockSdt" || block.type === "blockCustomXml" ? [getTextFromBlocks(block.content)] : [];
|
|
255
|
-
}).join("\n");
|
|
256
|
-
/**
|
|
257
|
-
* Get plain text from a table
|
|
258
|
-
*/
|
|
259
|
-
function getTableText(table) {
|
|
260
|
-
const lines = [];
|
|
261
|
-
for (const row of table.rows) {
|
|
262
|
-
const rowTexts = [];
|
|
263
|
-
for (const cell of row.cells) {
|
|
264
|
-
const cellTexts = [];
|
|
265
|
-
for (const content of cell.content) if (content.type === "paragraph") cellTexts.push(getParagraphText(content));
|
|
266
|
-
else if (content.type === "table") cellTexts.push(getTableText(content));
|
|
267
|
-
else if (content.type === "blockSdt" || content.type === "blockCustomXml") cellTexts.push(getTextFromBlocks(content.content));
|
|
268
|
-
rowTexts.push(cellTexts.join("\n"));
|
|
269
|
-
}
|
|
270
|
-
lines.push(rowTexts.join(" "));
|
|
271
|
-
}
|
|
272
|
-
return lines.join("\n");
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
242
|
* Count total paragraphs in document
|
|
276
243
|
*/
|
|
277
244
|
function getParagraphCount(body) {
|
|
278
245
|
return getAllParagraphs(body).length;
|
|
279
246
|
}
|
|
280
247
|
/**
|
|
281
|
-
* Count total words in document (approximate)
|
|
282
|
-
*/
|
|
283
|
-
function getWordCount(body) {
|
|
284
|
-
const words = getDocumentText(body).trim().split(/\s+/u);
|
|
285
|
-
return words.length > 0 && words[0] !== "" ? words.length : 0;
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Count total characters in document
|
|
289
|
-
*/
|
|
290
|
-
function getCharacterCount(body) {
|
|
291
|
-
return getDocumentText(body).length;
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
248
|
* Get section count
|
|
295
249
|
*/
|
|
296
250
|
function getSectionCount(body) {
|
|
@@ -303,4 +257,4 @@ function hasTemplateVariables(body) {
|
|
|
303
257
|
return extractAllTemplateVariables(body.content).length > 0;
|
|
304
258
|
}
|
|
305
259
|
//#endregion
|
|
306
|
-
export { extractAllTemplateVariables, extractTemplateVariables, getAllParagraphs, getAllTables,
|
|
260
|
+
export { extractAllTemplateVariables, extractTemplateVariables, getAllParagraphs, getAllTables, getParagraphCount, getSectionCount, hasTemplateVariables, parseDocumentBody, parseDocumentBodyTree };
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
//#region src/docx/ensureParaIds.d.ts
|
|
2
|
+
declare const ENSURE_PARA_IDS_REASONS: {
|
|
3
|
+
readonly NORMALIZATION_FAILED: "normalization-failed";
|
|
4
|
+
readonly NAMESPACE_INVALID: "namespace-invalid";
|
|
5
|
+
readonly SIGNED_PACKAGE: "signed-package";
|
|
6
|
+
};
|
|
2
7
|
declare const EnsureParaIdsError_base: import("better-result").TaggedErrorClass<"EnsureParaIdsError">;
|
|
3
8
|
/** A malformed or unsupported package prevented paragraph-ID normalization. */
|
|
4
9
|
declare class EnsureParaIdsError extends EnsureParaIdsError_base<{
|
|
5
10
|
message: string;
|
|
11
|
+
reason: (typeof ENSURE_PARA_IDS_REASONS)[keyof typeof ENSURE_PARA_IDS_REASONS];
|
|
6
12
|
cause?: unknown;
|
|
7
13
|
}> {}
|
|
8
14
|
/** Counts and normalized bytes returned by {@link ensureParaIds}. */
|
|
@@ -35,4 +41,4 @@ type EnsureParaIdsOptions = {
|
|
|
35
41
|
*/
|
|
36
42
|
declare const ensureParaIds: (docx: Uint8Array | ArrayBuffer, options?: EnsureParaIdsOptions) => Promise<EnsureParaIdsResult>;
|
|
37
43
|
//#endregion
|
|
38
|
-
export { EnsureParaIdsError, EnsureParaIdsOptions, EnsureParaIdsResult, ensureParaIds };
|
|
44
|
+
export { ENSURE_PARA_IDS_REASONS, EnsureParaIdsError, EnsureParaIdsOptions, EnsureParaIdsResult, ensureParaIds };
|