@stll/folio-core 0.72.0 → 0.74.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 +12 -6
- package/dist/ai-edits/applyTypes.d.ts +85 -0
- package/dist/ai-edits/applyTypes.js +24 -0
- package/dist/ai-edits/clean-text.d.ts +7 -1
- package/dist/ai-edits/clean-text.js +23 -2
- package/dist/ai-edits/finalSectionReview.d.ts +1 -1
- package/dist/ai-edits/headless.d.ts +29 -147
- package/dist/ai-edits/headless.js +215 -1639
- package/dist/ai-edits/index.d.ts +3 -3
- package/dist/ai-edits/index.js +2 -3
- package/dist/ai-edits/pending-suggestions.d.ts +14 -4
- package/dist/ai-edits/pending-suggestions.js +183 -90
- package/dist/ai-edits/pendingJoin.js +6 -1
- package/dist/ai-edits/retired-comment-receipts.d.ts +1 -1
- package/dist/ai-edits/snapshot.js +9 -4
- package/dist/ai-edits/table-cell-mutations.d.ts +1 -1
- package/dist/ai-edits/table-cell-mutations.js +2 -2
- package/dist/ai-edits/table-geometry.d.ts +1 -1
- package/dist/ai-edits/table-geometry.js +1 -1
- package/dist/ai-edits/table-row-column-mutations.d.ts +1 -1
- package/dist/ai-edits/table-row-column-mutations.js +1 -1
- package/dist/ai-edits/tableNodes.d.ts +38 -0
- package/dist/ai-edits/tableNodes.js +86 -0
- package/dist/ai-edits/tracked-batch-fidelity.d.ts +1 -1
- package/dist/ai-edits/tracked-batch-fidelity.js +1 -1
- package/dist/ai-edits/undefinedReferences.d.ts +7 -0
- package/dist/canonical/batchCommentReferences.js +1 -0
- package/dist/canonical/canonicalInlineGaps.d.ts +56 -0
- package/dist/canonical/canonicalInlineGaps.js +118 -0
- package/dist/canonical/canonicalInlineProjection.d.ts +4 -13
- package/dist/canonical/canonicalInlineProjection.js +5 -27
- package/dist/canonical/canonicalProjectionBlocks.d.ts +4 -4
- package/dist/canonical/canonicalPublicOperations.js +282 -75
- package/dist/canonical/canonicalSelection.js +1 -1
- package/dist/canonical/canonicalSession.d.ts +9 -1
- package/dist/canonical/canonicalSession.js +106 -33
- package/dist/compare/compare.d.ts +1 -1
- package/dist/compare/inline-atoms-model.d.ts +1 -1
- package/dist/compare/inline-atoms.d.ts +2 -2
- package/dist/compare/inline-provenance-model.d.ts +1 -1
- package/dist/compare/inline-provenance.d.ts +2 -2
- package/dist/compat/eigenpal.d.ts +3 -3
- package/dist/compat/eigenpal.js +2 -3
- package/dist/controller/autocompleteSuggestion.js +1 -1
- package/dist/controller/canonicalClipboard.d.ts +13 -3
- package/dist/controller/canonicalClipboard.js +186 -50
- package/dist/controller/canonicalClipboardResources.d.ts +9 -1
- package/dist/controller/canonicalClipboardResources.js +22 -2
- package/dist/controller/canonicalComposition.js +1 -1
- package/dist/controller/canonicalInput.js +1 -1
- package/dist/controller/canonicalPresence.js +1 -1
- package/dist/controller/canonicalReview.d.ts +1 -1
- package/dist/controller/canonicalReview.js +1 -1
- package/dist/controller/canonicalRoomAuthority.js +1 -1
- package/dist/controller/canonicalRoomWire.js +1 -1
- package/dist/controller/canonicalStructure.js +1 -1
- package/dist/controller/canonicalTabRoom.js +1 -1
- package/dist/controller/canonicalWatermark.d.ts +10 -0
- package/dist/controller/canonicalWatermark.js +37 -0
- package/dist/controller/canonicalYjsRoom.js +1 -1
- package/dist/controller/hiddenEditorApi.d.ts +1 -1
- package/dist/controller/hiddenEditorApi.js +2 -17
- package/dist/controller/hiddenEditorManager.d.ts +4 -3
- package/dist/controller/hiddenEditorManager.js +79 -23
- package/dist/document-operations.d.ts +1 -14
- package/dist/document-operations.js +1 -278
- package/dist/docx/canonicalSave.d.ts +1 -1
- package/dist/docx/canonicalSave.js +1 -1
- package/dist/docx/canonicalSessionInput.js +1 -1
- package/dist/docx/containerChildren.js +1 -1
- package/dist/docx/createDocx.d.ts +4 -0
- package/dist/docx/createDocx.js +6 -0
- package/dist/docx/paragraphParser.js +2 -2
- package/dist/docx/paragraphPropertySource.d.ts +1 -1
- package/dist/docx/parser.js +1 -1
- package/dist/docx/reviewResolutionProvenance.d.ts +3 -2
- package/dist/docx/reviewResolutionProvenance.js +31 -8
- package/dist/docx/revisionIdNormalization.js +30 -7
- package/dist/docx/rezip.d.ts +1 -1
- package/dist/docx/rezip.js +1 -1
- package/dist/docx/serializer/tableSerializer.js +4 -36
- package/dist/docx/server/templatePlan/apply.d.ts +15 -0
- package/dist/docx/server/templatePlan/apply.js +658 -0
- package/dist/docx/server/templatePlan/blocks.d.ts +97 -0
- package/dist/docx/server/templatePlan/blocks.js +355 -0
- package/dist/docx/server/templatePlan/builders.d.ts +72 -0
- package/dist/docx/server/templatePlan/builders.js +237 -0
- package/dist/docx/server/templatePlan/emit.d.ts +118 -0
- package/dist/docx/server/templatePlan/emit.js +466 -0
- package/dist/docx/server/templatePlan/emphasis.d.ts +62 -0
- package/dist/docx/server/templatePlan/emphasis.js +173 -0
- package/dist/docx/server/templatePlan/inspect.d.ts +22 -0
- package/dist/docx/server/templatePlan/inspect.js +230 -0
- package/dist/docx/server/templatePlan/labels.d.ts +45 -0
- package/dist/docx/server/templatePlan/labels.js +155 -0
- package/dist/docx/server/templatePlan/package.d.ts +34 -0
- package/dist/docx/server/templatePlan/package.js +99 -0
- package/dist/docx/server/templatePlan/plan.d.ts +145 -0
- package/dist/docx/server/templatePlan/plan.js +875 -0
- package/dist/docx/server/templatePlan/planShape.d.ts +9 -0
- package/dist/docx/server/templatePlan/planShape.js +180 -0
- package/dist/docx/server/templatePlan/resources.d.ts +41 -0
- package/dist/docx/server/templatePlan/resources.js +136 -0
- package/dist/docx/server/templatePlan/story.d.ts +128 -0
- package/dist/docx/server/templatePlan/story.js +440 -0
- package/dist/docx/server/templatePlan/types.d.ts +442 -0
- package/dist/docx/server/templatePlan/types.js +29 -0
- package/dist/docx/server/templatePlan/verify.d.ts +40 -0
- package/dist/docx/server/templatePlan/verify.js +976 -0
- package/dist/docx/server/templatePlan/xml.d.ts +74 -0
- package/dist/docx/server/templatePlan/xml.js +125 -0
- package/dist/docx/settingsHeaderFooterUpdate.d.ts +9 -0
- package/dist/docx/settingsHeaderFooterUpdate.js +45 -10
- package/dist/docx/structuralXmlPatch.js +9 -1
- package/dist/docx/tableGridXml.d.ts +30 -0
- package/dist/docx/tableGridXml.js +54 -0
- package/dist/docx/tableParser.js +7 -0
- package/dist/i18n/loadMessages.d.ts +5 -0
- package/dist/i18n/loadMessages.js +46 -0
- package/dist/i18n/locales.d.ts +3 -0
- package/dist/i18n/locales.js +17 -0
- package/dist/i18n/messages.d.ts +3 -2
- package/dist/i18n/messages.js +4 -16
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -3
- package/dist/internal/clipboardTransformPlugin.d.ts +3 -0
- package/dist/internal/clipboardTransformPlugin.js +13 -0
- package/dist/internal/extensionRuntime.d.ts +7 -0
- package/dist/internal/extensionRuntime.js +28 -0
- package/dist/internal/starterKitExtensions.d.ts +20 -0
- package/dist/internal/starterKitExtensions.js +123 -0
- package/dist/internal/wholeStoryRevisionResolution.js +1 -1
- package/dist/managers/ContextMenuManager.js +2 -1
- package/dist/managers/editorShortcuts.d.ts +1 -1
- package/dist/prosemirror/anchoredTextBoxes.d.ts +1 -1
- package/dist/prosemirror/attrs/index.js +1 -1
- package/dist/prosemirror/canonicalCommands.d.ts +1 -1
- package/dist/prosemirror/canonicalSelectionRange.d.ts +1 -1
- package/dist/prosemirror/canonicalSelectionRange.js +1 -1
- package/dist/prosemirror/canonicalTableCommands.js +3 -3
- package/dist/prosemirror/commands/comments.js +4 -4
- package/dist/prosemirror/commands/contentControls.d.ts +1 -1
- package/dist/prosemirror/commands/contentControls.js +1 -1
- package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
- package/dist/prosemirror/commands/formatting.d.ts +1 -1
- package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
- package/dist/prosemirror/commands/pastePlainText.js +2 -3
- package/dist/prosemirror/commands/replaceRangeText.js +1 -1
- package/dist/prosemirror/commands/sectionBreak.js +1 -1
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -1
- package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +1 -1
- package/dist/prosemirror/commentRecords.d.ts +1 -1
- package/dist/prosemirror/commentRecords.js +2 -2
- package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +0 -5
- package/dist/prosemirror/conversion/fromProseDoc.js +2 -9
- package/dist/prosemirror/conversion/index.d.ts +2 -2
- package/dist/prosemirror/conversion/index.js +2 -2
- package/dist/prosemirror/documentStructureCounts.d.ts +24 -0
- package/dist/prosemirror/documentStructureCounts.js +76 -0
- package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
- package/dist/prosemirror/extensions/ExtensionManager.js +4 -22
- package/dist/prosemirror/extensions/StarterKit.d.ts +4 -27
- package/dist/prosemirror/extensions/StarterKit.js +29 -115
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +1 -1
- package/dist/prosemirror/extensions/core/historyCommands.d.ts +16 -0
- package/dist/prosemirror/extensions/core/historyCommands.js +19 -0
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +1 -1
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +1 -1
- package/dist/prosemirror/extensions/features/ListExtension.js +7 -2
- package/dist/prosemirror/extensions/features/pastedCellSections.d.ts +1 -1
- package/dist/prosemirror/extensions/index.d.ts +2 -1
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +8 -3
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +1 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.js +8 -41
- package/dist/prosemirror/extensions/types.d.ts +1 -1
- package/dist/prosemirror/findReplaceSelection.d.ts +1 -1
- package/dist/prosemirror/hyperlinkRemoval.d.ts +1 -1
- package/dist/prosemirror/hyperlinkRemoval.js +7 -2
- package/dist/prosemirror/index.d.ts +3 -3
- package/dist/prosemirror/index.js +3 -3
- package/dist/prosemirror/insertionGaps.d.ts +1 -1
- package/dist/prosemirror/keptRangeBoundaries.d.ts +1 -1
- package/dist/prosemirror/keptRangeBoundaries.js +1 -1
- package/dist/prosemirror/listNumbering.d.ts +1 -1
- package/dist/prosemirror/listNumbering.js +1 -1
- package/dist/prosemirror/lockedControls.d.ts +1 -1
- package/dist/prosemirror/markupViewProjection.d.ts +1 -1
- package/dist/prosemirror/noteReferenceOccurrences.d.ts +1 -1
- package/dist/prosemirror/noteReferenceOccurrences.js +1 -1
- package/dist/prosemirror/noteReferenceReview.d.ts +2 -56
- package/dist/prosemirror/noteReferenceReview.js +2 -243
- package/dist/prosemirror/{extensions/features/ParaIdAllocatorExtension.d.ts → paraIds.d.ts} +13 -23
- package/dist/prosemirror/paraIds.js +152 -0
- package/dist/prosemirror/paragraphChangeTrackerMeta.d.ts +97 -0
- package/dist/prosemirror/paragraphChangeTrackerMeta.js +87 -0
- package/dist/prosemirror/paragraphMarkJoin.d.ts +1 -1
- package/dist/prosemirror/paragraphPropertyCarry.d.ts +1 -1
- package/dist/prosemirror/pastedCommentCopies.d.ts +1 -1
- package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
- package/dist/prosemirror/plugins/documentNumbering.d.ts +1 -1
- package/dist/prosemirror/plugins/documentNumbering.js +1 -1
- package/dist/prosemirror/plugins/documentStyles.js +1 -1
- package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
- package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -1
- package/dist/prosemirror/rebaseParagraphRuns.d.ts +1 -1
- package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
- package/dist/prosemirror/replacedAnnotations.d.ts +1 -1
- package/dist/prosemirror/replacedAnnotations.js +17 -2
- package/dist/prosemirror/revisionCarriers.d.ts +1 -1
- package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
- package/dist/prosemirror/sectionMarkEdits.d.ts +1 -1
- package/dist/prosemirror/selectionBounds.d.ts +10 -0
- package/dist/prosemirror/selectionBounds.js +22 -0
- package/dist/prosemirror/storyListNumbering.d.ts +1 -1
- package/dist/prosemirror/suggestionCommands.d.ts +47 -0
- package/dist/prosemirror/suggestionCommands.js +31 -0
- package/dist/prosemirror/tableCellPaste.d.ts +1 -1
- package/dist/prosemirror/tableCellPaste.js +1 -1
- package/dist/prosemirror/tableGridMutation.d.ts +1 -1
- package/dist/prosemirror/tableRunIn.js +1 -1
- package/dist/prosemirror/textInput.d.ts +1 -1
- package/dist/prosemirror/textInput.js +1 -1
- package/dist/server.d.ts +7 -2
- package/dist/server.js +6 -1
- package/dist/types/canonicalCapabilities.d.ts +13 -92
- package/dist/types/canonicalCapabilities.js +11 -85
- package/package.json +4 -4
- package/dist/ai-edits/apply.d.ts +0 -202
- package/dist/ai-edits/apply.js +0 -6759
- package/dist/ai-edits/note-story-inventory.d.ts +0 -5
- package/dist/ai-edits/note-story-inventory.js +0 -10
- package/dist/ai-edits/revisionStretches.d.ts +0 -32
- package/dist/ai-edits/revisionStretches.js +0 -147
- package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +0 -18
- package/dist/prosemirror/extensions/core/HistoryExtension.js +0 -122
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +0 -408
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +0 -135
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +0 -566
- package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -92
- package/dist/prosemirror/plugins/suggestionMode.js +0 -1515
- package/dist/prosemirror/tablePositionedBookmarks.d.ts +0 -8
- package/dist/prosemirror/tablePositionedBookmarks.js +0 -80
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
import { parseFieldType } from "../../fieldParser.js";
|
|
2
|
+
import { readParagraphNumbering } from "../../numberingReference.js";
|
|
3
|
+
import { paraIdAttribute } from "../../paraIdAttribute.js";
|
|
4
|
+
import { getLocalName } from "../../xmlParser.js";
|
|
5
|
+
import { MARKUP_COMPATIBILITY_NAMESPACE, MATH_NAMESPACE, elementChildren, relationshipAttr, wAttr, wChild, wChildVal, wName } from "./xml.js";
|
|
6
|
+
// src/docx/server/templatePlan/story.ts
|
|
7
|
+
/** The mark a footnote or endnote reference leaves in a block's text. */
|
|
8
|
+
const NOTE_REFERENCE_MARK = "";
|
|
9
|
+
const createStoryState = () => ({
|
|
10
|
+
fields: [],
|
|
11
|
+
open: [],
|
|
12
|
+
paragraphOrdinal: 0,
|
|
13
|
+
comments: 0,
|
|
14
|
+
trackedChanges: 0,
|
|
15
|
+
formattingRevisions: 0,
|
|
16
|
+
strayFieldEnds: 0
|
|
17
|
+
});
|
|
18
|
+
/** A bookmark start, with how many atoms of its paragraph come before it. */
|
|
19
|
+
/**
|
|
20
|
+
* Close a story at its end: a field still open there never closes, and must
|
|
21
|
+
* not swallow the text of the story read next with the same state.
|
|
22
|
+
*/
|
|
23
|
+
const endStory = (state) => {
|
|
24
|
+
state.strayFieldEnds += state.open.length;
|
|
25
|
+
state.open = [];
|
|
26
|
+
};
|
|
27
|
+
const REVISION_INCLUDED = /* @__PURE__ */ new Set(["ins", "moveTo"]);
|
|
28
|
+
const REVISION_EXCLUDED = /* @__PURE__ */ new Set(["del", "moveFrom"]);
|
|
29
|
+
const TRANSPARENT_WRAPPERS = /* @__PURE__ */ new Set([
|
|
30
|
+
"smartTag",
|
|
31
|
+
"customXml",
|
|
32
|
+
"dir",
|
|
33
|
+
"bdo"
|
|
34
|
+
]);
|
|
35
|
+
const PROPERTY_REVISIONS = /* @__PURE__ */ new Set([
|
|
36
|
+
"rPrChange",
|
|
37
|
+
"pPrChange",
|
|
38
|
+
"sectPrChange",
|
|
39
|
+
"tblPrChange",
|
|
40
|
+
"trPrChange",
|
|
41
|
+
"tcPrChange",
|
|
42
|
+
"numberingChange"
|
|
43
|
+
]);
|
|
44
|
+
const OBJECT_RUN_CHILDREN = /* @__PURE__ */ new Set([
|
|
45
|
+
"drawing",
|
|
46
|
+
"pict",
|
|
47
|
+
"object"
|
|
48
|
+
]);
|
|
49
|
+
/** Run children that carry no content of their own, or are read elsewhere. */
|
|
50
|
+
const IGNORED_RUN_CHILDREN = /* @__PURE__ */ new Set([
|
|
51
|
+
"rPr",
|
|
52
|
+
"lastRenderedPageBreak",
|
|
53
|
+
"footnoteRef",
|
|
54
|
+
"endnoteRef",
|
|
55
|
+
"annotationRef",
|
|
56
|
+
"separator",
|
|
57
|
+
"continuationSeparator",
|
|
58
|
+
"delText",
|
|
59
|
+
"delInstrText"
|
|
60
|
+
]);
|
|
61
|
+
/** Paragraph-level children that mark ranges or carry properties only. */
|
|
62
|
+
const IGNORED_INLINE_CHILDREN = /* @__PURE__ */ new Set([
|
|
63
|
+
"pPr",
|
|
64
|
+
"rPr",
|
|
65
|
+
"sdtPr",
|
|
66
|
+
"sdtEndPr",
|
|
67
|
+
"smartTagPr",
|
|
68
|
+
"customXmlPr",
|
|
69
|
+
"commentRangeStart",
|
|
70
|
+
"commentRangeEnd",
|
|
71
|
+
"proofErr",
|
|
72
|
+
"permStart",
|
|
73
|
+
"permEnd",
|
|
74
|
+
"moveFromRangeStart",
|
|
75
|
+
"moveFromRangeEnd",
|
|
76
|
+
"moveToRangeStart",
|
|
77
|
+
"moveToRangeEnd",
|
|
78
|
+
"customXmlInsRangeStart",
|
|
79
|
+
"customXmlInsRangeEnd",
|
|
80
|
+
"customXmlDelRangeStart",
|
|
81
|
+
"customXmlDelRangeEnd",
|
|
82
|
+
"customXmlMoveFromRangeStart",
|
|
83
|
+
"customXmlMoveFromRangeEnd",
|
|
84
|
+
"customXmlMoveToRangeStart",
|
|
85
|
+
"customXmlMoveToRangeEnd"
|
|
86
|
+
]);
|
|
87
|
+
const CONTENT_REVISIONS = /* @__PURE__ */ new Set([
|
|
88
|
+
"ins",
|
|
89
|
+
"del",
|
|
90
|
+
"moveFrom",
|
|
91
|
+
"moveTo"
|
|
92
|
+
]);
|
|
93
|
+
const REPLACEMENT_CHARACTER = "�";
|
|
94
|
+
const FIRST_SURROGATE = 55296;
|
|
95
|
+
const LAST_SURROGATE = 57343;
|
|
96
|
+
const FIRST_PRINTABLE = 32;
|
|
97
|
+
/** The character a `w:sym` shows; one a string cannot hold whole reads as U+FFFD. */
|
|
98
|
+
const symbolText = (element) => {
|
|
99
|
+
const code = Number.parseInt(wAttr(element, "char") ?? "", 16);
|
|
100
|
+
return Number.isInteger(code) && code >= FIRST_PRINTABLE && code <= 1114111 && (code < FIRST_SURROGATE || code > LAST_SURROGATE) ? String.fromCodePoint(code) : REPLACEMENT_CHARACTER;
|
|
101
|
+
};
|
|
102
|
+
/** Tracked insertions, deletions and moves anywhere under `element`. */
|
|
103
|
+
const countContentRevisions = (element) => {
|
|
104
|
+
let count = 0;
|
|
105
|
+
const stack = [element];
|
|
106
|
+
while (stack.length > 0) {
|
|
107
|
+
const node = stack.pop();
|
|
108
|
+
if (node === void 0) continue;
|
|
109
|
+
if (CONTENT_REVISIONS.has(wName(node) ?? "")) count += 1;
|
|
110
|
+
stack.push(...elementChildren(node));
|
|
111
|
+
}
|
|
112
|
+
return count;
|
|
113
|
+
};
|
|
114
|
+
const textOf = (element) => (element.elements ?? []).map((child) => child.type === "text" ? String(child.text ?? "") : "").join("");
|
|
115
|
+
const BODY_TEXT_OUTLINE_LEVEL = 9;
|
|
116
|
+
/** `w:outlineLvl` as a heading level; the reserved body-text value is none. */
|
|
117
|
+
const headingLevelOf = (value) => {
|
|
118
|
+
const level = value === null ? NaN : Number.parseInt(value, 10);
|
|
119
|
+
return Number.isInteger(level) && level >= 0 && level < BODY_TEXT_OUTLINE_LEVEL ? level : null;
|
|
120
|
+
};
|
|
121
|
+
const fieldKindOf = (instruction) => {
|
|
122
|
+
const known = parseFieldType(instruction);
|
|
123
|
+
if (known !== "UNKNOWN") return known;
|
|
124
|
+
return /^\s*\\?(?<name>[A-Za-z][A-Za-z0-9]*)/u.exec(instruction)?.groups?.["name"]?.toUpperCase() ?? "UNKNOWN";
|
|
125
|
+
};
|
|
126
|
+
const inCode = (state) => state.open.some(({ phase }) => phase === "code");
|
|
127
|
+
const pushAtom = (walk, atom) => {
|
|
128
|
+
const { state, read } = walk;
|
|
129
|
+
if (inCode(state)) return;
|
|
130
|
+
const fields = state.open.map(({ field }) => field.index);
|
|
131
|
+
for (const { field } of state.open) field.result += atom.text;
|
|
132
|
+
read.atoms.push({
|
|
133
|
+
...atom,
|
|
134
|
+
fields
|
|
135
|
+
});
|
|
136
|
+
walk.textLength += atom.text.length;
|
|
137
|
+
};
|
|
138
|
+
const beginField = (walk, instruction) => {
|
|
139
|
+
const { state, read } = walk;
|
|
140
|
+
const field = {
|
|
141
|
+
index: state.fields.length,
|
|
142
|
+
instruction,
|
|
143
|
+
kind: fieldKindOf(instruction),
|
|
144
|
+
result: "",
|
|
145
|
+
resultStart: -1,
|
|
146
|
+
paragraphOrdinal: read.ordinal,
|
|
147
|
+
endParagraphOrdinal: read.ordinal,
|
|
148
|
+
closed: false,
|
|
149
|
+
nestedInCode: inCode(state)
|
|
150
|
+
};
|
|
151
|
+
state.fields.push(field);
|
|
152
|
+
read.fieldIndices.push(field.index);
|
|
153
|
+
return field;
|
|
154
|
+
};
|
|
155
|
+
const readRun = (run, walk, { link }) => {
|
|
156
|
+
const { state, read } = walk;
|
|
157
|
+
const runProperties = wChild(run, "rPr");
|
|
158
|
+
if (wChild(runProperties, "rPrChange") !== null) state.formattingRevisions += 1;
|
|
159
|
+
const atom = (kind, text, element) => {
|
|
160
|
+
pushAtom(walk, {
|
|
161
|
+
kind,
|
|
162
|
+
text,
|
|
163
|
+
runProperties,
|
|
164
|
+
link,
|
|
165
|
+
element
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
const object = (element) => {
|
|
169
|
+
if (inCode(state)) return;
|
|
170
|
+
read.inlineObjects += 1;
|
|
171
|
+
state.trackedChanges += countContentRevisions(element);
|
|
172
|
+
atom("object", "", element);
|
|
173
|
+
};
|
|
174
|
+
for (const child of elementChildren(run)) {
|
|
175
|
+
const name = wName(child);
|
|
176
|
+
if (name === null) {
|
|
177
|
+
if (child.namespaceUri === MARKUP_COMPATIBILITY_NAMESPACE && getLocalName(child.name) === "AlternateContent") object(child);
|
|
178
|
+
else if (!inCode(state)) read.unsupported.push(child.name ?? "");
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
switch (name) {
|
|
182
|
+
case "t":
|
|
183
|
+
atom("text", textOf(child), null);
|
|
184
|
+
break;
|
|
185
|
+
case "tab":
|
|
186
|
+
case "ptab":
|
|
187
|
+
atom("tab", " ", child);
|
|
188
|
+
break;
|
|
189
|
+
case "cr":
|
|
190
|
+
atom("lineBreak", "\n", child);
|
|
191
|
+
break;
|
|
192
|
+
case "br": {
|
|
193
|
+
const type = wAttr(child, "type");
|
|
194
|
+
if (type === "page" || type === "column") atom("pageBreak", "", child);
|
|
195
|
+
else atom("lineBreak", "\n", child);
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
case "noBreakHyphen":
|
|
199
|
+
atom("noBreakHyphen", "‑", child);
|
|
200
|
+
break;
|
|
201
|
+
case "softHyphen":
|
|
202
|
+
atom("softHyphen", "", child);
|
|
203
|
+
break;
|
|
204
|
+
case "sym":
|
|
205
|
+
atom("symbol", symbolText(child), child);
|
|
206
|
+
break;
|
|
207
|
+
case "footnoteReference":
|
|
208
|
+
atom("footnoteReference", "", child);
|
|
209
|
+
break;
|
|
210
|
+
case "endnoteReference":
|
|
211
|
+
atom("endnoteReference", "", child);
|
|
212
|
+
break;
|
|
213
|
+
case "commentReference":
|
|
214
|
+
state.comments += 1;
|
|
215
|
+
break;
|
|
216
|
+
case "fldChar": {
|
|
217
|
+
const type = wAttr(child, "fldCharType");
|
|
218
|
+
if (type === "begin") state.open.push({
|
|
219
|
+
field: beginField(walk, ""),
|
|
220
|
+
phase: "code"
|
|
221
|
+
});
|
|
222
|
+
else if (type === "separate") {
|
|
223
|
+
const top = state.open.at(-1);
|
|
224
|
+
if (top === void 0 || top.phase === "result") state.strayFieldEnds += 1;
|
|
225
|
+
else {
|
|
226
|
+
top.phase = "result";
|
|
227
|
+
top.field.kind = fieldKindOf(top.field.instruction);
|
|
228
|
+
top.field.resultStart = top.field.paragraphOrdinal === read.ordinal ? walk.textLength : 0;
|
|
229
|
+
}
|
|
230
|
+
} else if (type === "end") {
|
|
231
|
+
const top = state.open.pop();
|
|
232
|
+
if (top === void 0) state.strayFieldEnds += 1;
|
|
233
|
+
else {
|
|
234
|
+
top.field.kind = fieldKindOf(top.field.instruction);
|
|
235
|
+
top.field.endParagraphOrdinal = read.ordinal;
|
|
236
|
+
top.field.closed = true;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
case "instrText": {
|
|
242
|
+
const top = state.open.at(-1);
|
|
243
|
+
if (top !== void 0 && top.phase === "code") top.field.instruction += textOf(child);
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
default: if (OBJECT_RUN_CHILDREN.has(name)) object(child);
|
|
247
|
+
else if (!IGNORED_RUN_CHILDREN.has(name) && !inCode(state)) read.unsupported.push(name);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
const readInline = (container, walk, context) => {
|
|
252
|
+
const { state, read } = walk;
|
|
253
|
+
for (const child of elementChildren(container)) {
|
|
254
|
+
const name = wName(child);
|
|
255
|
+
if (name === null) {
|
|
256
|
+
if (child.namespaceUri === MATH_NAMESPACE && !inCode(state) && (getLocalName(child.name) === "oMath" || getLocalName(child.name) === "oMathPara")) {
|
|
257
|
+
read.inlineObjects += 1;
|
|
258
|
+
state.trackedChanges += countContentRevisions(child);
|
|
259
|
+
pushAtom(walk, {
|
|
260
|
+
kind: "object",
|
|
261
|
+
text: "",
|
|
262
|
+
runProperties: null,
|
|
263
|
+
link: context.link,
|
|
264
|
+
element: child
|
|
265
|
+
});
|
|
266
|
+
} else if (!inCode(state)) read.unsupported.push(child.name ?? "");
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
if (name === "r") readRun(child, walk, context);
|
|
270
|
+
else if (name === "hyperlink") {
|
|
271
|
+
const relationshipId = relationshipAttr(child, "id");
|
|
272
|
+
const anchor = wAttr(child, "anchor");
|
|
273
|
+
let link = context.link;
|
|
274
|
+
if (relationshipId !== null) link = {
|
|
275
|
+
kind: "relationship",
|
|
276
|
+
relationshipId,
|
|
277
|
+
anchor
|
|
278
|
+
};
|
|
279
|
+
else if (anchor !== null) link = {
|
|
280
|
+
kind: "anchor",
|
|
281
|
+
anchor
|
|
282
|
+
};
|
|
283
|
+
readInline(child, walk, { link });
|
|
284
|
+
} else if (name === "fldSimple") {
|
|
285
|
+
const field = beginField(walk, wAttr(child, "instr") ?? "");
|
|
286
|
+
field.resultStart = walk.textLength;
|
|
287
|
+
state.open.push({
|
|
288
|
+
field,
|
|
289
|
+
phase: "result"
|
|
290
|
+
});
|
|
291
|
+
readInline(child, walk, context);
|
|
292
|
+
state.open.pop();
|
|
293
|
+
field.closed = true;
|
|
294
|
+
} else if (REVISION_INCLUDED.has(name)) {
|
|
295
|
+
state.trackedChanges += 1;
|
|
296
|
+
readInline(child, walk, context);
|
|
297
|
+
} else if (REVISION_EXCLUDED.has(name)) state.trackedChanges += 1;
|
|
298
|
+
else if (name === "sdt") {
|
|
299
|
+
const content = wChild(child, "sdtContent");
|
|
300
|
+
if (content !== null) readInline(content, walk, context);
|
|
301
|
+
} else if (TRANSPARENT_WRAPPERS.has(name)) readInline(child, walk, context);
|
|
302
|
+
else if (name === "bookmarkStart") read.bookmarks.push({
|
|
303
|
+
name: wAttr(child, "name") ?? "",
|
|
304
|
+
id: wAttr(child, "id") ?? "",
|
|
305
|
+
atomIndex: read.atoms.length
|
|
306
|
+
});
|
|
307
|
+
else if (name === "bookmarkEnd") read.bookmarkEnds.push({
|
|
308
|
+
id: wAttr(child, "id") ?? "",
|
|
309
|
+
atomIndex: read.atoms.length
|
|
310
|
+
});
|
|
311
|
+
else if (!IGNORED_INLINE_CHILDREN.has(name) && !inCode(state)) read.unsupported.push(name);
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
/** Read one `w:p`, advancing the story's field and revision state. */
|
|
315
|
+
const readParagraph = (element, state) => {
|
|
316
|
+
const properties = wChild(element, "pPr");
|
|
317
|
+
const mark = wChild(properties, "rPr");
|
|
318
|
+
const hasTrackedMark = wChild(mark, "ins") !== null || wChild(mark, "del") !== null || wChild(mark, "moveFrom") !== null || wChild(mark, "moveTo") !== null;
|
|
319
|
+
if (hasTrackedMark) state.trackedChanges += 1;
|
|
320
|
+
for (const child of elementChildren(properties)) if (PROPERTY_REVISIONS.has(wName(child) ?? "")) state.formattingRevisions += 1;
|
|
321
|
+
const outline = wChildVal(properties, "outlineLvl");
|
|
322
|
+
const read = {
|
|
323
|
+
element,
|
|
324
|
+
ordinal: state.paragraphOrdinal,
|
|
325
|
+
styleId: wChildVal(properties, "pStyle"),
|
|
326
|
+
numPr: readParagraphNumbering(wChild(properties, "numPr")),
|
|
327
|
+
paraId: paraIdAttribute(element) ?? null,
|
|
328
|
+
outlineLevel: headingLevelOf(outline),
|
|
329
|
+
atoms: [],
|
|
330
|
+
text: "",
|
|
331
|
+
fieldIndices: [],
|
|
332
|
+
openFieldsAtStart: state.open.length,
|
|
333
|
+
bookmarks: [],
|
|
334
|
+
bookmarkEnds: [],
|
|
335
|
+
inlineObjects: 0,
|
|
336
|
+
unsupported: [],
|
|
337
|
+
hasSectionBreak: wChild(properties, "sectPr") !== null,
|
|
338
|
+
hasTrackedMark
|
|
339
|
+
};
|
|
340
|
+
state.paragraphOrdinal += 1;
|
|
341
|
+
const walk = {
|
|
342
|
+
state,
|
|
343
|
+
read,
|
|
344
|
+
textLength: 0
|
|
345
|
+
};
|
|
346
|
+
for (const open of state.open) if (open.phase === "result" && open.field.result !== "") open.field.result += "\n";
|
|
347
|
+
readInline(element, walk, { link: null });
|
|
348
|
+
read.text = read.atoms.map(({ text }) => text).join("");
|
|
349
|
+
return read;
|
|
350
|
+
};
|
|
351
|
+
const BLOCK_WRAPPERS = /* @__PURE__ */ new Set(["customXml"]);
|
|
352
|
+
const ROW_REVISIONS = ["ins", "del"];
|
|
353
|
+
const CELL_REVISIONS = [
|
|
354
|
+
"cellIns",
|
|
355
|
+
"cellDel",
|
|
356
|
+
"cellMerge"
|
|
357
|
+
];
|
|
358
|
+
const hasRevisionChild = (properties, names) => names.some((name) => wChild(properties, name) !== null);
|
|
359
|
+
const IGNORED_BLOCK_CHILDREN = /* @__PURE__ */ new Set([
|
|
360
|
+
"sectPr",
|
|
361
|
+
"bookmarkStart",
|
|
362
|
+
"bookmarkEnd",
|
|
363
|
+
"proofErr",
|
|
364
|
+
"permStart",
|
|
365
|
+
"permEnd",
|
|
366
|
+
"commentRangeStart",
|
|
367
|
+
"commentRangeEnd",
|
|
368
|
+
"moveFromRangeStart",
|
|
369
|
+
"moveFromRangeEnd",
|
|
370
|
+
"moveToRangeStart",
|
|
371
|
+
"moveToRangeEnd",
|
|
372
|
+
"tblPr",
|
|
373
|
+
"tblGrid",
|
|
374
|
+
"tblPrEx",
|
|
375
|
+
"trPr",
|
|
376
|
+
"tcPr",
|
|
377
|
+
"sdtPr",
|
|
378
|
+
"sdtEndPr",
|
|
379
|
+
"customXmlPr"
|
|
380
|
+
]);
|
|
381
|
+
const walkRows = (container, visitor, depth, rowCounter) => {
|
|
382
|
+
for (const child of elementChildren(container)) {
|
|
383
|
+
const name = wName(child);
|
|
384
|
+
if (name === "tr") {
|
|
385
|
+
if (hasRevisionChild(wChild(child, "trPr"), ROW_REVISIONS)) visitor.tracked(child);
|
|
386
|
+
const row = rowCounter.row;
|
|
387
|
+
rowCounter.row += 1;
|
|
388
|
+
let col = 0;
|
|
389
|
+
const walkCells = (rowContainer) => {
|
|
390
|
+
for (const cell of elementChildren(rowContainer)) {
|
|
391
|
+
const cellName = wName(cell);
|
|
392
|
+
if (cellName === "tc") {
|
|
393
|
+
if (hasRevisionChild(wChild(cell, "tcPr"), CELL_REVISIONS)) visitor.tracked(cell);
|
|
394
|
+
visitor.cellStart(row, col);
|
|
395
|
+
col += 1;
|
|
396
|
+
walkBlocks(cell, visitor, depth + 1);
|
|
397
|
+
} else if (cellName === "sdt") {
|
|
398
|
+
const content = wChild(cell, "sdtContent");
|
|
399
|
+
if (content !== null) walkCells(content);
|
|
400
|
+
} else if (cellName !== null && BLOCK_WRAPPERS.has(cellName)) walkCells(cell);
|
|
401
|
+
else if (cellName !== null && CONTENT_REVISIONS.has(cellName)) {
|
|
402
|
+
visitor.tracked(cell);
|
|
403
|
+
if (REVISION_INCLUDED.has(cellName)) walkCells(cell);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
walkCells(child);
|
|
408
|
+
} else if (name === "sdt") {
|
|
409
|
+
const content = wChild(child, "sdtContent");
|
|
410
|
+
if (content !== null) walkRows(content, visitor, depth, rowCounter);
|
|
411
|
+
} else if (name !== null && BLOCK_WRAPPERS.has(name)) walkRows(child, visitor, depth, rowCounter);
|
|
412
|
+
else if (name !== null && CONTENT_REVISIONS.has(name)) {
|
|
413
|
+
visitor.tracked(child);
|
|
414
|
+
if (REVISION_INCLUDED.has(name)) walkRows(child, visitor, depth, rowCounter);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
/**
|
|
419
|
+
* Visit the blocks under a story container (`w:body`, `w:tc`, a note, a
|
|
420
|
+
* header) in document order. Block content controls are read through.
|
|
421
|
+
*/
|
|
422
|
+
const walkBlocks = (container, visitor, depth = 0) => {
|
|
423
|
+
for (const child of elementChildren(container)) {
|
|
424
|
+
const name = wName(child);
|
|
425
|
+
if (name === "p") visitor.paragraph(child, depth);
|
|
426
|
+
else if (name === "tbl") {
|
|
427
|
+
visitor.tableStart(child, depth);
|
|
428
|
+
walkRows(child, visitor, depth, { row: 0 });
|
|
429
|
+
visitor.tableEnd(child);
|
|
430
|
+
} else if (name === "sdt") {
|
|
431
|
+
const content = wChild(child, "sdtContent");
|
|
432
|
+
if (content !== null) walkBlocks(content, visitor, depth);
|
|
433
|
+
} else if (name !== null && BLOCK_WRAPPERS.has(name)) walkBlocks(child, visitor, depth);
|
|
434
|
+
else if (name !== null && CONTENT_REVISIONS.has(name)) {
|
|
435
|
+
visitor.tracked(child);
|
|
436
|
+
if (REVISION_INCLUDED.has(name)) walkBlocks(child, visitor, depth);
|
|
437
|
+
} else if (name === null || !IGNORED_BLOCK_CHILDREN.has(name)) visitor.unread(child);
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
export { NOTE_REFERENCE_MARK, createStoryState, endStory, readParagraph, walkBlocks };
|