@stll/folio-core 0.47.7 → 0.48.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/controller/fontReadiness.js +3 -3
- package/dist/controller/hyphenationReadiness.d.ts +19 -0
- package/dist/controller/hyphenationReadiness.js +47 -0
- package/dist/controller/layoutPipeline.d.ts +3 -0
- package/dist/controller/layoutPipeline.js +59 -17
- package/dist/display-list/build/buildDisplayList.js +39 -12
- package/dist/display-list/build/pageFurniture.d.ts +7 -1
- package/dist/display-list/build/pageFurniture.js +21 -8
- package/dist/display-list/build/paragraphPrimitives.js +5 -4
- package/dist/display-list/build/tablePrimitives.js +10 -6
- package/dist/docx/attributeRemainder.js +10 -2
- package/dist/docx/blockContentParser.d.ts +2 -0
- package/dist/docx/blockContentParser.js +77 -62
- package/dist/docx/commentParser.d.ts +2 -1
- package/dist/docx/commentParser.js +57 -45
- package/dist/docx/containerChildren.d.ts +21 -8
- package/dist/docx/containerChildren.js +39 -9
- package/dist/docx/documentParser.d.ts +5 -1
- package/dist/docx/documentParser.js +8 -5
- package/dist/docx/documentSectionFacts.d.ts +22 -0
- package/dist/docx/documentSectionFacts.js +43 -0
- package/dist/docx/fieldParser.d.ts +8 -1
- package/dist/docx/fieldParser.js +47 -3
- package/dist/docx/fontTableParser.js +34 -27
- package/dist/docx/footnoteParser.d.ts +3 -2
- package/dist/docx/footnoteParser.js +15 -12
- package/dist/docx/groupDrawingParser.d.ts +2 -1
- package/dist/docx/groupDrawingParser.js +3 -6
- package/dist/docx/headerFooterParser.d.ts +7 -2
- package/dist/docx/headerFooterParser.js +15 -5
- package/dist/docx/hyperlinkParser.d.ts +48 -36
- package/dist/docx/hyperlinkParser.js +97 -82
- package/dist/docx/numberingParser.js +108 -84
- package/dist/docx/paragraphParser.d.ts +5 -1
- package/dist/docx/paragraphParser.js +381 -362
- package/dist/docx/paragraphProperties.js +123 -109
- package/dist/docx/paragraphPropertySource.d.ts +6 -1
- package/dist/docx/paragraphPropertySource.js +9 -1
- package/dist/docx/paragraphTextBoxEnrichment.d.ts +2 -1
- package/dist/docx/paragraphTextBoxEnrichment.js +17 -6
- package/dist/docx/parser.d.ts +7 -1
- package/dist/docx/parser.js +33 -16
- package/dist/docx/previewBudget.d.ts +55 -33
- package/dist/docx/previewBudget.js +59 -65
- package/dist/docx/rezip.js +41 -58
- package/dist/docx/runParser.d.ts +4 -1
- package/dist/docx/runParser.js +172 -184
- package/dist/docx/sdtProperties.js +87 -84
- package/dist/docx/sectionParser.js +169 -160
- package/dist/docx/serializer/paragraphSerializer.js +42 -38
- package/dist/docx/serializer/settingsSerializer.js +19 -1
- package/dist/docx/settingsParser.js +8 -0
- package/dist/docx/streamingXmlParser.d.ts +6 -2
- package/dist/docx/streamingXmlParser.js +12 -7
- package/dist/docx/styleParser.js +34 -8
- package/dist/docx/tableParser.d.ts +21 -12
- package/dist/docx/tableParser.js +518 -441
- package/dist/docx/textBoxParser.d.ts +8 -3
- package/dist/docx/textBoxParser.js +3 -3
- package/dist/docx/verbatimCapture.d.ts +10 -8
- package/dist/docx/verbatimCapture.js +45 -2
- package/dist/docx/vmlImageParser.d.ts +15 -13
- package/dist/docx/vmlImageParser.js +75 -60
- package/dist/docx/vmlPreview.d.ts +3 -3
- package/dist/docx/vmlPreview.js +3 -4
- package/dist/docx/xmlNamespaceContext.d.ts +9 -0
- package/dist/docx/xmlNamespaceContext.js +54 -0
- package/dist/docx/xmlParser.d.ts +6 -3
- package/dist/docx/xmlParser.js +11 -41
- package/dist/docx/xmlResourceLimits.d.ts +2 -1
- package/dist/docx/xmlResourceLimits.js +4 -1
- package/dist/fonts/headlessMeasure.js +0 -0
- package/dist/headless-layout.d.ts +11 -2
- package/dist/headless-layout.js +153 -107
- package/dist/internal/paragraphFormattingSerialization.js +3 -3
- package/dist/layout-bridge/convert/endnoteLayout.d.ts +65 -0
- package/dist/layout-bridge/convert/endnoteLayout.js +227 -0
- package/dist/layout-bridge/convert/footnoteLayout.d.ts +19 -3
- package/dist/layout-bridge/convert/footnoteLayout.js +40 -31
- package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -7
- package/dist/layout-bridge/convert/headerFooterLayout.js +5 -20
- package/dist/layout-bridge/convert/paragraphMarkFormatting.d.ts +10 -0
- package/dist/layout-bridge/convert/paragraphMarkFormatting.js +59 -0
- package/dist/layout-bridge/convert/toFlowBlocks.d.ts +29 -1
- package/dist/layout-bridge/convert/toFlowBlocks.js +258 -35
- package/dist/layout-bridge/engine/hitTest.js +5 -3
- package/dist/layout-bridge/engine/selectionRects.js +5 -3
- package/dist/layout-engine/anchorLayoutInCellCompatibility.d.ts +10 -0
- package/dist/layout-engine/anchorLayoutInCellCompatibility.js +22 -0
- package/dist/layout-engine/index.d.ts +2 -2
- package/dist/layout-engine/index.js +70 -11
- package/dist/layout-engine/justificationCompatibility.d.ts +1 -1
- package/dist/layout-engine/justificationCompatibility.js +9 -5
- package/dist/layout-engine/keep-together.d.ts +11 -5
- package/dist/layout-engine/keep-together.js +39 -16
- package/dist/layout-engine/layoutInstrumentation.d.ts +8 -2
- package/dist/layout-engine/layoutInstrumentation.js +8 -1
- package/dist/layout-engine/measure/advanceComposition.js +4 -7
- package/dist/layout-engine/measure/hyphenationDictionaries.d.ts +74 -0
- package/dist/layout-engine/measure/hyphenationDictionaries.js +138 -0
- package/dist/layout-engine/measure/hyphenationPreload.d.ts +11 -0
- package/dist/layout-engine/measure/hyphenationPreload.js +24 -0
- package/dist/layout-engine/measure/lineBreakProvider.d.ts +12 -2
- package/dist/layout-engine/measure/lineBreakProvider.js +30 -30
- package/dist/layout-engine/measure/lineBreaks.d.ts +6 -1
- package/dist/layout-engine/measure/lineBreaks.js +10 -3
- package/dist/layout-engine/measure/listMarkerWidth.d.ts +9 -6
- package/dist/layout-engine/measure/listMarkerWidth.js +20 -22
- package/dist/layout-engine/measure/measureBlocks.js +42 -8
- package/dist/layout-engine/measure/measureContainer.js +5 -5
- package/dist/layout-engine/measure/measureHelpers.d.ts +15 -3
- package/dist/layout-engine/measure/measureHelpers.js +21 -5
- package/dist/layout-engine/measure/measureParagraph.js +109 -30
- package/dist/layout-engine/measure/measureTypes.d.ts +5 -0
- package/dist/layout-engine/measure/tabCalculator.d.ts +2 -0
- package/dist/layout-engine/measure/tabCalculator.js +2 -1
- package/dist/layout-engine/measure/tableCellFloating.d.ts +2 -0
- package/dist/layout-engine/measure/tableCellFloating.js +51 -19
- package/dist/layout-engine/measure/tableCellGrid.d.ts +28 -3
- package/dist/layout-engine/measure/tableCellGrid.js +45 -5
- package/dist/layout-engine/measure/tableFragmentBorderGeometry.js +2 -1
- package/dist/layout-engine/noteAreaFlow.d.ts +19 -0
- package/dist/layout-engine/noteAreaFlow.js +83 -0
- package/dist/layout-engine/paginator.d.ts +10 -1
- package/dist/layout-engine/paginator.js +13 -1
- package/dist/layout-engine/tableRowBreak.js +3 -1
- package/dist/layout-engine/types.d.ts +89 -3
- package/dist/layout-engine/types.js +96 -1
- package/dist/layout-painter/index.d.ts +3 -0
- package/dist/layout-painter/renderPage.js +32 -83
- package/dist/layout-painter/renderParagraph.d.ts +6 -1
- package/dist/layout-painter/renderParagraph.js +34 -22
- package/dist/layout-painter/renderTable.js +26 -13
- package/dist/prosemirror/attrs/index.d.ts +9 -9
- package/dist/prosemirror/attrs/index.js +43 -11
- package/dist/prosemirror/conversion/fromProseDoc.js +8 -1
- package/dist/prosemirror/conversion/markInterner.d.ts +21 -0
- package/dist/prosemirror/conversion/markInterner.js +90 -0
- package/dist/prosemirror/conversion/toProseDoc.js +77 -41
- package/dist/prosemirror/extensions/core/DocExtension.js +2 -1
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +1 -0
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +6 -2
- package/dist/prosemirror/extensions/marks/markUtils.js +39 -51
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +2 -1
- package/dist/prosemirror/listMarker.d.ts +1 -0
- package/dist/prosemirror/listMarker.js +2 -0
- package/dist/prosemirror/listRenderingAttrs.d.ts +1 -0
- package/dist/prosemirror/listRenderingAttrs.js +3 -0
- package/dist/prosemirror/schema/nodes.d.ts +13 -1
- package/dist/prosemirror/textBoxHostParagraph.d.ts +13 -0
- package/dist/prosemirror/textBoxHostParagraph.js +21 -0
- package/dist/prosemirror/validation.js +91 -80
- package/dist/utils/createDocument.js +10 -1
- package/dist/utils/scriptSegments.d.ts +33 -4
- package/dist/utils/scriptSegments.js +39 -6
- package/dist/utils/textFormattingMerge.d.ts +17 -3
- package/dist/utils/textFormattingMerge.js +18 -12
- package/dist/utils/trailingText.d.ts +22 -0
- package/dist/utils/trailingText.js +32 -0
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readAttributeBag } from "./attributeRemainder.js";
|
|
2
2
|
import { parseBorderSpec } from "./borderParser.js";
|
|
3
|
-
import { CAPTURE,
|
|
3
|
+
import { CAPTURE, dispatchChildrenWithContext, ownedElsewhere, sequencePositions } from "./containerChildren.js";
|
|
4
4
|
import { readParagraphNumbering } from "./numberingReference.js";
|
|
5
5
|
import { FrameWrapSchema, FrameXAlignSchema, FrameYAlignSchema, LineSpacingRuleSchema, ParagraphAlignmentSchema, TabLeaderSchema, TabStopAlignmentSchema, narrowEnum } from "./parserEnums.js";
|
|
6
6
|
import { FRAME_ATTRIBUTES, INDENTATION_ATTRIBUTES, SPACING_ATTRIBUTES, TAB_STOP_ATTRIBUTES } from "./propertyElementAttributes.js";
|
|
@@ -74,6 +74,123 @@ function parseFrameProperties(framePr) {
|
|
|
74
74
|
return frame;
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
|
+
* The content model declares each property once. A source that states one
|
|
78
|
+
* twice keeps the first as the model's value and the repeat as bytes at the
|
|
79
|
+
* same schema ordinal, rather than letting the second silently win or fall off
|
|
80
|
+
* the end of the walk.
|
|
81
|
+
*/
|
|
82
|
+
const readOnce = (name, read) => (child, { formatting, taken }) => {
|
|
83
|
+
if (taken.has(name) || !read(child, formatting)) return CAPTURE;
|
|
84
|
+
taken.add(name);
|
|
85
|
+
};
|
|
86
|
+
const readToggle = (name, field) => readOnce(name, (child, formatting) => {
|
|
87
|
+
formatting[field] = parseBooleanElement(child);
|
|
88
|
+
return true;
|
|
89
|
+
});
|
|
90
|
+
/**
|
|
91
|
+
* The `w:pPr` decision map. Built once: every reader takes the record it fills
|
|
92
|
+
* from the walk's context rather than closing over it.
|
|
93
|
+
*/
|
|
94
|
+
const PARAGRAPH_PROPERTY_HANDLERS = {
|
|
95
|
+
pStyle: readOnce("pStyle", (child, formatting) => {
|
|
96
|
+
const val = getAttribute(child, "w", "val");
|
|
97
|
+
if (!val) return false;
|
|
98
|
+
formatting.styleId = val;
|
|
99
|
+
return true;
|
|
100
|
+
}),
|
|
101
|
+
keepNext: readToggle("keepNext", "keepNext"),
|
|
102
|
+
keepLines: readToggle("keepLines", "keepLines"),
|
|
103
|
+
pageBreakBefore: readToggle("pageBreakBefore", "pageBreakBefore"),
|
|
104
|
+
framePr: readOnce("framePr", (child, formatting) => {
|
|
105
|
+
const frame = parseFrameProperties(child);
|
|
106
|
+
if (frame === void 0) return false;
|
|
107
|
+
formatting.frame = frame;
|
|
108
|
+
return true;
|
|
109
|
+
}),
|
|
110
|
+
widowControl: readToggle("widowControl", "widowControl"),
|
|
111
|
+
numPr: readOnce("numPr", (child, formatting) => {
|
|
112
|
+
const stated = readParagraphNumbering(child);
|
|
113
|
+
if (stated !== void 0) formatting.numPr = stated;
|
|
114
|
+
const numberingChange = findChild(child, "w", "numberingChange");
|
|
115
|
+
if (numberingChange) formatting.numberingChangeXml = captureVerbatimXml(numberingChange);
|
|
116
|
+
const numberingInsertion = findChild(child, "w", "ins");
|
|
117
|
+
if (numberingInsertion) formatting.numberingInsertionXml = captureVerbatimXml(numberingInsertion);
|
|
118
|
+
const statedLevel = parseNumericAttribute(findChild(child, "w", "ilvl"), "w", "val");
|
|
119
|
+
return stated !== void 0 || numberingChange !== null || numberingInsertion !== null || statedLevel === -1;
|
|
120
|
+
}),
|
|
121
|
+
suppressLineNumbers: readToggle("suppressLineNumbers", "suppressLineNumbers"),
|
|
122
|
+
pBdr: readOnce("pBdr", (child, formatting) => {
|
|
123
|
+
const borders = {};
|
|
124
|
+
for (const side of PARAGRAPH_BORDER_SIDES) {
|
|
125
|
+
const border = parseBorderSpec(findChild(child, "w", side));
|
|
126
|
+
if (border) borders[side] = border;
|
|
127
|
+
}
|
|
128
|
+
if (Object.keys(borders).length === 0) return false;
|
|
129
|
+
formatting.borders = borders;
|
|
130
|
+
return true;
|
|
131
|
+
}),
|
|
132
|
+
shd: readOnce("shd", (child, formatting) => {
|
|
133
|
+
const shading = parseShading(child);
|
|
134
|
+
if (shading === void 0) return false;
|
|
135
|
+
formatting.shading = shading;
|
|
136
|
+
return true;
|
|
137
|
+
}),
|
|
138
|
+
tabs: readOnce("tabs", (child, formatting) => {
|
|
139
|
+
const tabs = parseTabStops(child);
|
|
140
|
+
if (tabs === void 0) return false;
|
|
141
|
+
formatting.tabs = tabs;
|
|
142
|
+
return true;
|
|
143
|
+
}),
|
|
144
|
+
suppressAutoHyphens: readToggle("suppressAutoHyphens", "suppressAutoHyphens"),
|
|
145
|
+
kinsoku: readToggle("kinsoku", "kinsoku"),
|
|
146
|
+
wordWrap: CAPTURE,
|
|
147
|
+
overflowPunct: readToggle("overflowPunct", "overflowPunctuation"),
|
|
148
|
+
topLinePunct: CAPTURE,
|
|
149
|
+
autoSpaceDE: CAPTURE,
|
|
150
|
+
autoSpaceDN: CAPTURE,
|
|
151
|
+
bidi: readToggle("bidi", "bidi"),
|
|
152
|
+
adjustRightInd: CAPTURE,
|
|
153
|
+
snapToGrid: readToggle("snapToGrid", "snapToGrid"),
|
|
154
|
+
spacing: readOnce("spacing", (child, formatting) => readParagraphSpacing(child, formatting)),
|
|
155
|
+
ind: readOnce("ind", (child, formatting) => readParagraphIndentation(child, formatting)),
|
|
156
|
+
contextualSpacing: readToggle("contextualSpacing", "contextualSpacing"),
|
|
157
|
+
mirrorIndents: CAPTURE,
|
|
158
|
+
suppressOverlap: CAPTURE,
|
|
159
|
+
jc: readOnce("jc", (child, formatting) => {
|
|
160
|
+
const val = narrowEnum(getAttribute(child, "w", "val"), ParagraphAlignmentSchema);
|
|
161
|
+
if (!val) return false;
|
|
162
|
+
formatting.alignment = val;
|
|
163
|
+
return true;
|
|
164
|
+
}),
|
|
165
|
+
textDirection: CAPTURE,
|
|
166
|
+
textAlignment: CAPTURE,
|
|
167
|
+
textboxTightWrap: CAPTURE,
|
|
168
|
+
outlineLvl: readOnce("outlineLvl", (child, formatting) => {
|
|
169
|
+
const val = parseNumericAttribute(child, "w", "val");
|
|
170
|
+
const level = val === void 0 ? void 0 : outlineLevelFromStatedValue(val);
|
|
171
|
+
if (level === void 0) return val === -1;
|
|
172
|
+
formatting.outlineLevel = level;
|
|
173
|
+
return true;
|
|
174
|
+
}),
|
|
175
|
+
divId: CAPTURE,
|
|
176
|
+
cnfStyle: CAPTURE,
|
|
177
|
+
rPr: ownedElsewhere({
|
|
178
|
+
container: "paragraph-properties",
|
|
179
|
+
child: "rPr",
|
|
180
|
+
reader: "paragraphProperties#parseParagraphProperties"
|
|
181
|
+
}),
|
|
182
|
+
sectPr: ownedElsewhere({
|
|
183
|
+
container: "paragraph-properties",
|
|
184
|
+
child: "sectPr",
|
|
185
|
+
reader: "sectionParser#parseSectionProperties"
|
|
186
|
+
}),
|
|
187
|
+
pPrChange: ownedElsewhere({
|
|
188
|
+
container: "paragraph-properties",
|
|
189
|
+
child: "pPrChange",
|
|
190
|
+
reader: "paragraphParser#parseParagraphPropertyChanges"
|
|
191
|
+
})
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
77
194
|
* Read `w:pPr` into {@link ParagraphFormatting}, every declared child carrying
|
|
78
195
|
* a decision.
|
|
79
196
|
*
|
|
@@ -93,117 +210,14 @@ function parseFrameProperties(framePr) {
|
|
|
93
210
|
function parseParagraphProperties(pPr, theme) {
|
|
94
211
|
if (!pPr) return;
|
|
95
212
|
const formatting = {};
|
|
96
|
-
const
|
|
97
|
-
const once = (name, read) => (child) => {
|
|
98
|
-
if (taken.has(name) || !read(child)) return CAPTURE;
|
|
99
|
-
taken.add(name);
|
|
100
|
-
};
|
|
101
|
-
const toggle = (name, field) => once(name, (child) => {
|
|
102
|
-
formatting[field] = parseBooleanElement(child);
|
|
103
|
-
return true;
|
|
104
|
-
});
|
|
105
|
-
const preserved = dispatchChildren({
|
|
213
|
+
const preserved = dispatchChildrenWithContext({
|
|
106
214
|
element: pPr,
|
|
107
215
|
container: "paragraph-properties",
|
|
108
216
|
capturePosition: sequencePositions("paragraph-properties", pPr),
|
|
109
|
-
handlers:
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
formatting.styleId = val;
|
|
114
|
-
return true;
|
|
115
|
-
}),
|
|
116
|
-
keepNext: toggle("keepNext", "keepNext"),
|
|
117
|
-
keepLines: toggle("keepLines", "keepLines"),
|
|
118
|
-
pageBreakBefore: toggle("pageBreakBefore", "pageBreakBefore"),
|
|
119
|
-
framePr: once("framePr", (child) => {
|
|
120
|
-
const frame = parseFrameProperties(child);
|
|
121
|
-
if (frame === void 0) return false;
|
|
122
|
-
formatting.frame = frame;
|
|
123
|
-
return true;
|
|
124
|
-
}),
|
|
125
|
-
widowControl: toggle("widowControl", "widowControl"),
|
|
126
|
-
numPr: once("numPr", (child) => {
|
|
127
|
-
const stated = readParagraphNumbering(child);
|
|
128
|
-
if (stated !== void 0) formatting.numPr = stated;
|
|
129
|
-
const numberingChange = findChild(child, "w", "numberingChange");
|
|
130
|
-
if (numberingChange) formatting.numberingChangeXml = captureVerbatimXml(numberingChange);
|
|
131
|
-
const numberingInsertion = findChild(child, "w", "ins");
|
|
132
|
-
if (numberingInsertion) formatting.numberingInsertionXml = captureVerbatimXml(numberingInsertion);
|
|
133
|
-
const statedLevel = parseNumericAttribute(findChild(child, "w", "ilvl"), "w", "val");
|
|
134
|
-
return stated !== void 0 || numberingChange !== null || numberingInsertion !== null || statedLevel === -1;
|
|
135
|
-
}),
|
|
136
|
-
suppressLineNumbers: toggle("suppressLineNumbers", "suppressLineNumbers"),
|
|
137
|
-
pBdr: once("pBdr", (child) => {
|
|
138
|
-
const borders = {};
|
|
139
|
-
for (const side of PARAGRAPH_BORDER_SIDES) {
|
|
140
|
-
const border = parseBorderSpec(findChild(child, "w", side));
|
|
141
|
-
if (border) borders[side] = border;
|
|
142
|
-
}
|
|
143
|
-
if (Object.keys(borders).length === 0) return false;
|
|
144
|
-
formatting.borders = borders;
|
|
145
|
-
return true;
|
|
146
|
-
}),
|
|
147
|
-
shd: once("shd", (child) => {
|
|
148
|
-
const shading = parseShading(child);
|
|
149
|
-
if (shading === void 0) return false;
|
|
150
|
-
formatting.shading = shading;
|
|
151
|
-
return true;
|
|
152
|
-
}),
|
|
153
|
-
tabs: once("tabs", (child) => {
|
|
154
|
-
const tabs = parseTabStops(child);
|
|
155
|
-
if (tabs === void 0) return false;
|
|
156
|
-
formatting.tabs = tabs;
|
|
157
|
-
return true;
|
|
158
|
-
}),
|
|
159
|
-
suppressAutoHyphens: toggle("suppressAutoHyphens", "suppressAutoHyphens"),
|
|
160
|
-
kinsoku: toggle("kinsoku", "kinsoku"),
|
|
161
|
-
wordWrap: CAPTURE,
|
|
162
|
-
overflowPunct: toggle("overflowPunct", "overflowPunctuation"),
|
|
163
|
-
topLinePunct: CAPTURE,
|
|
164
|
-
autoSpaceDE: CAPTURE,
|
|
165
|
-
autoSpaceDN: CAPTURE,
|
|
166
|
-
bidi: toggle("bidi", "bidi"),
|
|
167
|
-
adjustRightInd: CAPTURE,
|
|
168
|
-
snapToGrid: toggle("snapToGrid", "snapToGrid"),
|
|
169
|
-
spacing: once("spacing", (child) => readParagraphSpacing(child, formatting)),
|
|
170
|
-
ind: once("ind", (child) => readParagraphIndentation(child, formatting)),
|
|
171
|
-
contextualSpacing: toggle("contextualSpacing", "contextualSpacing"),
|
|
172
|
-
mirrorIndents: CAPTURE,
|
|
173
|
-
suppressOverlap: CAPTURE,
|
|
174
|
-
jc: once("jc", (child) => {
|
|
175
|
-
const val = narrowEnum(getAttribute(child, "w", "val"), ParagraphAlignmentSchema);
|
|
176
|
-
if (!val) return false;
|
|
177
|
-
formatting.alignment = val;
|
|
178
|
-
return true;
|
|
179
|
-
}),
|
|
180
|
-
textDirection: CAPTURE,
|
|
181
|
-
textAlignment: CAPTURE,
|
|
182
|
-
textboxTightWrap: CAPTURE,
|
|
183
|
-
outlineLvl: once("outlineLvl", (child) => {
|
|
184
|
-
const val = parseNumericAttribute(child, "w", "val");
|
|
185
|
-
const level = val === void 0 ? void 0 : outlineLevelFromStatedValue(val);
|
|
186
|
-
if (level === void 0) return val === -1;
|
|
187
|
-
formatting.outlineLevel = level;
|
|
188
|
-
return true;
|
|
189
|
-
}),
|
|
190
|
-
divId: CAPTURE,
|
|
191
|
-
cnfStyle: CAPTURE,
|
|
192
|
-
rPr: ownedElsewhere({
|
|
193
|
-
container: "paragraph-properties",
|
|
194
|
-
child: "rPr",
|
|
195
|
-
reader: "paragraphProperties#parseParagraphProperties"
|
|
196
|
-
}),
|
|
197
|
-
sectPr: ownedElsewhere({
|
|
198
|
-
container: "paragraph-properties",
|
|
199
|
-
child: "sectPr",
|
|
200
|
-
reader: "sectionParser#parseSectionProperties"
|
|
201
|
-
}),
|
|
202
|
-
pPrChange: ownedElsewhere({
|
|
203
|
-
container: "paragraph-properties",
|
|
204
|
-
child: "pPrChange",
|
|
205
|
-
reader: "paragraphParser#parseParagraphPropertyChanges"
|
|
206
|
-
})
|
|
217
|
+
handlers: PARAGRAPH_PROPERTY_HANDLERS,
|
|
218
|
+
context: {
|
|
219
|
+
formatting,
|
|
220
|
+
taken: /* @__PURE__ */ new Set()
|
|
207
221
|
}
|
|
208
222
|
});
|
|
209
223
|
const rPr = findChild(pPr, "w", "rPr");
|
|
@@ -111,6 +111,11 @@ declare const recreateProseNodeWithParagraphPropertySource: (source: Node, optio
|
|
|
111
111
|
* can only name a paragraph in the package it came from.
|
|
112
112
|
*/
|
|
113
113
|
declare const recreateProseNodeWithDetachedParagraphPropertySource: (source: Node, options?: RecreateProseNodeOptions) => Node;
|
|
114
|
+
/**
|
|
115
|
+
* A paragraph's attributes without its durable source token, for a copy of
|
|
116
|
+
* them that is carried by another node and must not claim the paragraph.
|
|
117
|
+
*/
|
|
118
|
+
declare const proseParagraphAttrsWithoutPropertySource: (attrs: Node["attrs"]) => Node["attrs"];
|
|
114
119
|
type SetProseParagraphMarkupOptions = {
|
|
115
120
|
attrs: Node["attrs"];
|
|
116
121
|
ownership: "preserve" | "transfer-allocated-id";
|
|
@@ -129,4 +134,4 @@ declare const linkParagraphPropertySourceCandidate: (target: document_d_exports.
|
|
|
129
134
|
declare const getParagraphPropertySourceCandidate: (paragraph: document_d_exports.Paragraph) => document_d_exports.Paragraph | undefined;
|
|
130
135
|
declare const getParagraphPropertySourceTransferId: (paragraph: document_d_exports.Paragraph) => string | undefined;
|
|
131
136
|
//#endregion
|
|
132
|
-
export { DecodedTableCellParagraphSourcePayload, PARAGRAPH_PROPERTY_SOURCE_VALIDATION_CODES, PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR, PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR, ParagraphPropertySourceValidationCode, ParagraphPropertySourceValidationError, TABLE_CELL_PARAGRAPH_SOURCE_BINDING_ATTR, TABLE_CELL_PARAGRAPH_SOURCE_PAYLOAD_ERROR_CLASSIFICATIONS, TableCellParagraphPropertySourceBinding, TableCellParagraphSourcePayloadErrorClassification, assignDocumentParagraphPropertySourceContract, assignParagraphPropertySource, cloneDocumentWithParagraphPropertySources, cloneParagraphWithPropertySource, cloneParagraphWithoutPropertySource, cloneTableCellsWithParagraphPropertyCaptures, copyDocumentParagraphPropertySourceContract, copyDocumentParagraphPropertySources, copyParagraphPropertyCapture, copyParagraphPropertySource, createProseParagraphWithPropertySource, decodeTableCellParagraphSourcePayload, getDocumentParagraphPropertySourceContract, getExplicitParagraphPropertySourceTransfers, getParagraphPropertySource, getParagraphPropertySourceCandidate, getParagraphPropertySourceToken, getParagraphPropertySourceTransferId, getProseDocumentParagraphPropertySourceContract, getProseParagraphPropertySourceToken, isParagraphPropertySourceToken, joinProseParagraphsWithRightPropertySource, linkParagraphPropertySourceCandidate, linkProseParagraphPropertySource, paragraphPropertySourceBelongsToDocument, paragraphPropertySourceMatchesEmission, paragraphPropertySourceTokenMatchesContract, recreateProseNodeWithDetachedParagraphPropertySource, recreateProseNodeWithParagraphPropertySource, restoreTableCellsWithParagraphPropertySources, setProseParagraphMarkupWithPropertySource, transferProseParagraphPropertySource, transportTableCellsWithParagraphPropertySources, visitDocumentStoryParagraphs, visitTableCellParagraphPropertySourceBindings };
|
|
137
|
+
export { DecodedTableCellParagraphSourcePayload, PARAGRAPH_PROPERTY_SOURCE_VALIDATION_CODES, PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR, PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR, ParagraphPropertySourceValidationCode, ParagraphPropertySourceValidationError, TABLE_CELL_PARAGRAPH_SOURCE_BINDING_ATTR, TABLE_CELL_PARAGRAPH_SOURCE_PAYLOAD_ERROR_CLASSIFICATIONS, TableCellParagraphPropertySourceBinding, TableCellParagraphSourcePayloadErrorClassification, assignDocumentParagraphPropertySourceContract, assignParagraphPropertySource, cloneDocumentWithParagraphPropertySources, cloneParagraphWithPropertySource, cloneParagraphWithoutPropertySource, cloneTableCellsWithParagraphPropertyCaptures, copyDocumentParagraphPropertySourceContract, copyDocumentParagraphPropertySources, copyParagraphPropertyCapture, copyParagraphPropertySource, createProseParagraphWithPropertySource, decodeTableCellParagraphSourcePayload, getDocumentParagraphPropertySourceContract, getExplicitParagraphPropertySourceTransfers, getParagraphPropertySource, getParagraphPropertySourceCandidate, getParagraphPropertySourceToken, getParagraphPropertySourceTransferId, getProseDocumentParagraphPropertySourceContract, getProseParagraphPropertySourceToken, isParagraphPropertySourceToken, joinProseParagraphsWithRightPropertySource, linkParagraphPropertySourceCandidate, linkProseParagraphPropertySource, paragraphPropertySourceBelongsToDocument, paragraphPropertySourceMatchesEmission, paragraphPropertySourceTokenMatchesContract, proseParagraphAttrsWithoutPropertySource, recreateProseNodeWithDetachedParagraphPropertySource, recreateProseNodeWithParagraphPropertySource, restoreTableCellsWithParagraphPropertySources, setProseParagraphMarkupWithPropertySource, transferProseParagraphPropertySource, transportTableCellsWithParagraphPropertySources, visitDocumentStoryParagraphs, visitTableCellParagraphPropertySourceBindings };
|
|
@@ -662,6 +662,14 @@ const recreateProseNodeWithDetachedParagraphPropertySource = (source, options =
|
|
|
662
662
|
} : attrs
|
|
663
663
|
});
|
|
664
664
|
};
|
|
665
|
+
/**
|
|
666
|
+
* A paragraph's attributes without its durable source token, for a copy of
|
|
667
|
+
* them that is carried by another node and must not claim the paragraph.
|
|
668
|
+
*/
|
|
669
|
+
const proseParagraphAttrsWithoutPropertySource = (attrs) => {
|
|
670
|
+
const { [PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR]: _token, ...rest } = attrs;
|
|
671
|
+
return rest;
|
|
672
|
+
};
|
|
665
673
|
/** Replace paragraph markup without losing its private parser-owner link. */
|
|
666
674
|
const setProseParagraphMarkupWithPropertySource = ({ attrs, ownership, pos, transaction }) => {
|
|
667
675
|
const source = transaction.doc.nodeAt(pos);
|
|
@@ -695,4 +703,4 @@ const linkParagraphPropertySourceCandidate = (target, source) => {
|
|
|
695
703
|
const getParagraphPropertySourceCandidate = (paragraph) => paragraphPropertySourceCandidates.get(paragraph);
|
|
696
704
|
const getParagraphPropertySourceTransferId = (paragraph) => paragraphPropertySourceTransferIds.get(paragraph);
|
|
697
705
|
//#endregion
|
|
698
|
-
export { PARAGRAPH_PROPERTY_SOURCE_VALIDATION_CODES, PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR, PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR, ParagraphPropertySourceValidationError, TABLE_CELL_PARAGRAPH_SOURCE_BINDING_ATTR, TABLE_CELL_PARAGRAPH_SOURCE_PAYLOAD_ERROR_CLASSIFICATIONS, assignDocumentParagraphPropertySourceContract, assignParagraphPropertySource, cloneDocumentWithParagraphPropertySources, cloneParagraphWithPropertySource, cloneParagraphWithoutPropertySource, cloneTableCellsWithParagraphPropertyCaptures, copyDocumentParagraphPropertySourceContract, copyDocumentParagraphPropertySources, copyParagraphPropertyCapture, copyParagraphPropertySource, createProseParagraphWithPropertySource, decodeTableCellParagraphSourcePayload, getDocumentParagraphPropertySourceContract, getExplicitParagraphPropertySourceTransfers, getParagraphPropertySource, getParagraphPropertySourceCandidate, getParagraphPropertySourceToken, getParagraphPropertySourceTransferId, getProseDocumentParagraphPropertySourceContract, getProseParagraphPropertySourceToken, isParagraphPropertySourceToken, joinProseParagraphsWithRightPropertySource, linkParagraphPropertySourceCandidate, linkProseParagraphPropertySource, paragraphPropertySourceBelongsToDocument, paragraphPropertySourceMatchesEmission, paragraphPropertySourceTokenMatchesContract, recreateProseNodeWithDetachedParagraphPropertySource, recreateProseNodeWithParagraphPropertySource, restoreTableCellsWithParagraphPropertySources, setProseParagraphMarkupWithPropertySource, transferProseParagraphPropertySource, transportTableCellsWithParagraphPropertySources, visitDocumentStoryParagraphs, visitTableCellParagraphPropertySourceBindings };
|
|
706
|
+
export { PARAGRAPH_PROPERTY_SOURCE_VALIDATION_CODES, PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR, PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR, ParagraphPropertySourceValidationError, TABLE_CELL_PARAGRAPH_SOURCE_BINDING_ATTR, TABLE_CELL_PARAGRAPH_SOURCE_PAYLOAD_ERROR_CLASSIFICATIONS, assignDocumentParagraphPropertySourceContract, assignParagraphPropertySource, cloneDocumentWithParagraphPropertySources, cloneParagraphWithPropertySource, cloneParagraphWithoutPropertySource, cloneTableCellsWithParagraphPropertyCaptures, copyDocumentParagraphPropertySourceContract, copyDocumentParagraphPropertySources, copyParagraphPropertyCapture, copyParagraphPropertySource, createProseParagraphWithPropertySource, decodeTableCellParagraphSourcePayload, getDocumentParagraphPropertySourceContract, getExplicitParagraphPropertySourceTransfers, getParagraphPropertySource, getParagraphPropertySourceCandidate, getParagraphPropertySourceToken, getParagraphPropertySourceTransferId, getProseDocumentParagraphPropertySourceContract, getProseParagraphPropertySourceToken, isParagraphPropertySourceToken, joinProseParagraphsWithRightPropertySource, linkParagraphPropertySourceCandidate, linkProseParagraphPropertySource, paragraphPropertySourceBelongsToDocument, paragraphPropertySourceMatchesEmission, paragraphPropertySourceTokenMatchesContract, proseParagraphAttrsWithoutPropertySource, recreateProseNodeWithDetachedParagraphPropertySource, recreateProseNodeWithParagraphPropertySource, restoreTableCellsWithParagraphPropertySources, setProseParagraphMarkupWithPropertySource, transferProseParagraphPropertySource, transportTableCellsWithParagraphPropertySources, visitDocumentStoryParagraphs, visitTableCellParagraphPropertySourceBindings };
|
|
@@ -2,9 +2,10 @@ import { document_d_exports } from "../types/document.js";
|
|
|
2
2
|
import { NumberingMap } from "./numberingParser.js";
|
|
3
3
|
import { ParseContext } from "./parseContext.js";
|
|
4
4
|
import { XmlElement } from "./xmlParser.js";
|
|
5
|
+
import { PreviewLedger } from "./previewBudget.js";
|
|
5
6
|
import { StyleMap } from "./styleParser.js";
|
|
6
7
|
import { TableParserFn } from "./textBoxParser.js";
|
|
7
8
|
//#region src/docx/paragraphTextBoxEnrichment.d.ts
|
|
8
|
-
declare const enrichParagraphTextBoxes: (paragraph: document_d_exports.Paragraph, paraXml: XmlElement, styles: StyleMap | null, theme: document_d_exports.Theme | null, numbering: NumberingMap | null, rels: document_d_exports.RelationshipMap | null, media: Map<string, document_d_exports.MediaFile> | null, parseTable: TableParserFn, context?: ParseContext) => void;
|
|
9
|
+
declare const enrichParagraphTextBoxes: (paragraph: document_d_exports.Paragraph, paraXml: XmlElement, styles: StyleMap | null, theme: document_d_exports.Theme | null, numbering: NumberingMap | null, rels: document_d_exports.RelationshipMap | null, media: Map<string, document_d_exports.MediaFile> | null, parseTable: TableParserFn, previews: PreviewLedger, context?: ParseContext) => void;
|
|
9
10
|
//#endregion
|
|
10
11
|
export { enrichParagraphTextBoxes };
|
|
@@ -121,7 +121,7 @@ const vmlWrapType = (positioned, zIndex) => {
|
|
|
121
121
|
if (Number.isFinite(zIndex) && zIndex < 0) return "behind";
|
|
122
122
|
return "inFront";
|
|
123
123
|
};
|
|
124
|
-
const enrichParagraphTextBoxes = (paragraph, paraXml, styles, theme, numbering, rels, media, parseTable, context) => {
|
|
124
|
+
const enrichParagraphTextBoxes = (paragraph, paraXml, styles, theme, numbering, rels, media, parseTable, previews, context) => {
|
|
125
125
|
enrichTextBoxRuns({
|
|
126
126
|
content: paragraph.content,
|
|
127
127
|
xmlChildren: getChildElements(paraXml),
|
|
@@ -131,6 +131,7 @@ const enrichParagraphTextBoxes = (paragraph, paraXml, styles, theme, numbering,
|
|
|
131
131
|
rels,
|
|
132
132
|
media,
|
|
133
133
|
parseTable,
|
|
134
|
+
previews,
|
|
134
135
|
context
|
|
135
136
|
});
|
|
136
137
|
paragraph.content = consolidateParagraphContent(paragraph.content);
|
|
@@ -140,7 +141,7 @@ const trackedChangeTypeFromXml = (localName) => {
|
|
|
140
141
|
if (localName === "del") return "deletion";
|
|
141
142
|
if (localName === "moveFrom" || localName === "moveTo") return localName;
|
|
142
143
|
};
|
|
143
|
-
const enrichTextBoxRuns = ({ content, xmlChildren, styles, theme, numbering, rels, media, parseTable, context }) => {
|
|
144
|
+
const enrichTextBoxRuns = ({ content, xmlChildren, styles, theme, numbering, rels, media, parseTable, previews, context }) => {
|
|
144
145
|
let parsedIndex = 0;
|
|
145
146
|
let lastConsumedRun;
|
|
146
147
|
for (const xmlChild of xmlChildren) {
|
|
@@ -157,6 +158,7 @@ const enrichTextBoxRuns = ({ content, xmlChildren, styles, theme, numbering, rel
|
|
|
157
158
|
rels,
|
|
158
159
|
media,
|
|
159
160
|
parseTable,
|
|
161
|
+
previews,
|
|
160
162
|
context
|
|
161
163
|
});
|
|
162
164
|
if (localName === "sdt" && parsedContent?.type === "inlineSdt") {
|
|
@@ -179,6 +181,7 @@ const enrichTextBoxRuns = ({ content, xmlChildren, styles, theme, numbering, rel
|
|
|
179
181
|
rels,
|
|
180
182
|
media,
|
|
181
183
|
parseTable,
|
|
184
|
+
previews,
|
|
182
185
|
context
|
|
183
186
|
});
|
|
184
187
|
parsedIndex = lastSegmentIndex + 1;
|
|
@@ -202,7 +205,7 @@ const enrichTextBoxRuns = ({ content, xmlChildren, styles, theme, numbering, rel
|
|
|
202
205
|
const wsp = findDeep(runEl, "wps", "wsp");
|
|
203
206
|
if (wsp) {
|
|
204
207
|
const txbxContentEl = getTextBoxContentElement(wsp);
|
|
205
|
-
if (txbxContentEl) textBox.content = parseTextBoxContent(txbxContentEl, parseParagraph, parseTable, styles, theme, numbering, rels, media);
|
|
208
|
+
if (txbxContentEl) textBox.content = parseTextBoxContent(txbxContentEl, parseParagraph, parseTable, styles, theme, numbering, rels, media, previews);
|
|
206
209
|
}
|
|
207
210
|
const shape = {
|
|
208
211
|
type: "shape",
|
|
@@ -242,7 +245,15 @@ const enrichTextBoxRuns = ({ content, xmlChildren, styles, theme, numbering, rel
|
|
|
242
245
|
}
|
|
243
246
|
}
|
|
244
247
|
for (const pictEl of vmlTextBoxes) {
|
|
245
|
-
const shape = parseVmlTextBoxShape(pictEl,
|
|
248
|
+
const shape = parseVmlTextBoxShape(pictEl, {
|
|
249
|
+
styles,
|
|
250
|
+
theme,
|
|
251
|
+
numbering,
|
|
252
|
+
rels,
|
|
253
|
+
media,
|
|
254
|
+
parseTable,
|
|
255
|
+
previews
|
|
256
|
+
});
|
|
246
257
|
if (!shape) continue;
|
|
247
258
|
const shapeContent = {
|
|
248
259
|
type: "shape",
|
|
@@ -265,7 +276,7 @@ const enrichTextBoxRuns = ({ content, xmlChildren, styles, theme, numbering, rel
|
|
|
265
276
|
}
|
|
266
277
|
}
|
|
267
278
|
};
|
|
268
|
-
const parseVmlTextBoxShape = (pictEl, styles, theme, numbering, rels, media, parseTable) => {
|
|
279
|
+
const parseVmlTextBoxShape = (pictEl, { styles, theme, numbering, rels, media, parseTable, previews }) => {
|
|
269
280
|
const shapeEl = findDeep(pictEl, "v", "shape");
|
|
270
281
|
const textBoxEl = shapeEl ? findDeep(shapeEl, "v", "textbox") : null;
|
|
271
282
|
const contentEl = textBoxEl ? findDeep(textBoxEl, "w", "txbxContent") : null;
|
|
@@ -292,7 +303,7 @@ const parseVmlTextBoxShape = (pictEl, styles, theme, numbering, rels, media, par
|
|
|
292
303
|
...fill === void 0 ? {} : { fill },
|
|
293
304
|
wrap: { type: vmlWrapType(positioned, zIndex) },
|
|
294
305
|
textBody: {
|
|
295
|
-
content: parseTextBoxContent(contentEl, parseParagraph, parseTable, styles, theme, numbering, rels, media),
|
|
306
|
+
content: parseTextBoxContent(contentEl, parseParagraph, parseTable, styles, theme, numbering, rels, media, previews),
|
|
296
307
|
...margins === void 0 ? {} : { margins },
|
|
297
308
|
...anchor === void 0 ? {} : { anchor }
|
|
298
309
|
}
|
package/dist/docx/parser.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { document_d_exports } from "../types/document.js";
|
|
2
2
|
import { DocxInput } from "../utils/docxInput.js";
|
|
3
3
|
import { DocxUnzipOptions } from "./unzip.js";
|
|
4
|
+
import { PreviewBudgetOverrides } from "./previewBudget.js";
|
|
4
5
|
//#region src/docx/parser.d.ts
|
|
5
6
|
/**
|
|
6
7
|
* Progress callback for tracking parsing stages
|
|
@@ -45,6 +46,11 @@ type ParseOptions = {
|
|
|
45
46
|
* @throws {Error} if parsing fails
|
|
46
47
|
*/
|
|
47
48
|
declare function parseDocx(input: DocxInput, options?: ParseOptions): Promise<document_d_exports.Document>;
|
|
49
|
+
/**
|
|
50
|
+
* {@link parseDocx}, charging the package's previews against `previewBudget`
|
|
51
|
+
* in place of the default per-kind allowances.
|
|
52
|
+
*/
|
|
53
|
+
declare function parseDocxWithPreviewBudget(input: DocxInput, options: ParseOptions, previewBudget: PreviewBudgetOverrides): Promise<document_d_exports.Document>;
|
|
48
54
|
declare const DocxParseError_base: import("better-result").TaggedErrorClass<"DocxParseError">;
|
|
49
55
|
/** DOCX parsing failure: malformed package, unsupported feature, or
|
|
50
56
|
* upstream parser exception. Wraps the original cause for diagnostics. */
|
|
@@ -80,4 +86,4 @@ declare function getDocxSummary(buffer: ArrayBuffer): Promise<{
|
|
|
80
86
|
variableCount: number;
|
|
81
87
|
}>;
|
|
82
88
|
//#endregion
|
|
83
|
-
export { DocxParseError, MediaResolver, ParseOptions, ProgressCallback, fullParseDocx, getDocxSummary, getDocxVariables, parseDocx, quickParseDocx };
|
|
89
|
+
export { DocxParseError, MediaResolver, ParseOptions, ProgressCallback, fullParseDocx, getDocxSummary, getDocxVariables, parseDocx, parseDocxWithPreviewBudget, quickParseDocx };
|
package/dist/docx/parser.js
CHANGED
|
@@ -23,7 +23,7 @@ import { UNNUMBERED_PARAGRAPH_WARNING, UNNUMBERED_STYLE_WARNING, normalizeNumber
|
|
|
23
23
|
import { assignDocumentParagraphPropertySourceContract } from "./paragraphPropertySource.js";
|
|
24
24
|
import { createParseWarningCollector } from "./parseContext.js";
|
|
25
25
|
import { formatParseWarnings } from "./parseWarningMessage.js";
|
|
26
|
-
import {
|
|
26
|
+
import { createPackagePreviewBudget } from "./previewBudget.js";
|
|
27
27
|
import { RELATIONSHIP_TYPES, parseRelationships, resolveRelativePath } from "./relsParser.js";
|
|
28
28
|
import { normalizeRenderedPageBreakHints } from "./renderedPageBreakNormalization.js";
|
|
29
29
|
import { parseSettings } from "./settingsParser.js";
|
|
@@ -71,10 +71,18 @@ const sha256Hex = async (buffer) => {
|
|
|
71
71
|
* @returns Promise resolving to Document
|
|
72
72
|
* @throws {Error} if parsing fails
|
|
73
73
|
*/
|
|
74
|
-
|
|
74
|
+
function parseDocx(input, options = {}) {
|
|
75
|
+
return parseDocxWithPreviewBudget(input, options, {});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* {@link parseDocx}, charging the package's previews against `previewBudget`
|
|
79
|
+
* in place of the default per-kind allowances.
|
|
80
|
+
*/
|
|
81
|
+
async function parseDocxWithPreviewBudget(input, options, previewBudget) {
|
|
75
82
|
const buffer = input instanceof ArrayBuffer ? input : await toArrayBuffer(input);
|
|
76
83
|
const { onProgress = () => {}, preloadFonts = true, parseHeadersFooters = true, parseNotes = true, detectVariables = true, password, unzipLimits, mediaResolver } = options;
|
|
77
84
|
const { context: parseContext, warnings: collectedWarnings } = createParseWarningCollector();
|
|
85
|
+
const previews = createPackagePreviewBudget();
|
|
78
86
|
try {
|
|
79
87
|
const timeStage = (_name, fn) => fn();
|
|
80
88
|
const timeStageAsync = async (_name, fn) => await fn();
|
|
@@ -121,7 +129,7 @@ async function parseDocx(input, options = {}) {
|
|
|
121
129
|
onProgress("Parsing document body...", 40);
|
|
122
130
|
let documentBody = { content: [] };
|
|
123
131
|
timeStage("documentBody", () => {
|
|
124
|
-
if (raw.documentXml) documentBody = parseDocumentBody(raw.documentXml, styles, theme, numbering, rels, media, parseContext.scoped({ part: "word/document.xml" }));
|
|
132
|
+
if (raw.documentXml) documentBody = parseDocumentBody(raw.documentXml, styles, theme, numbering, rels, media, parseContext.scoped({ part: "word/document.xml" }), previews.ledger);
|
|
125
133
|
else parseContext.warn({ code: PARSE_WARNING_CODES.documentPartMissing });
|
|
126
134
|
});
|
|
127
135
|
onProgress("Parsed document body", 55);
|
|
@@ -129,7 +137,7 @@ async function parseDocx(input, options = {}) {
|
|
|
129
137
|
let footers;
|
|
130
138
|
if (parseHeadersFooters) {
|
|
131
139
|
onProgress("Parsing headers/footers...", 55);
|
|
132
|
-
const hf = timeStage("headersFooters", () => parseHeadersAndFooters(raw, styles, theme, numbering, rels, media));
|
|
140
|
+
const hf = timeStage("headersFooters", () => parseHeadersAndFooters(raw, styles, theme, numbering, rels, media, previews.ledger));
|
|
133
141
|
headers = hf.headers;
|
|
134
142
|
footers = hf.footers;
|
|
135
143
|
onProgress("Parsed headers/footers", 65);
|
|
@@ -138,15 +146,20 @@ async function parseDocx(input, options = {}) {
|
|
|
138
146
|
let endnotes;
|
|
139
147
|
if (parseNotes) {
|
|
140
148
|
onProgress("Parsing footnotes/endnotes...", 65);
|
|
141
|
-
const notes = timeStage("footnotesEndnotes", () => parseNotesContent(raw, styles, theme, numbering, rels, media, parseContext));
|
|
149
|
+
const notes = timeStage("footnotesEndnotes", () => parseNotesContent(raw, styles, theme, numbering, rels, media, parseContext, previews.ledger));
|
|
142
150
|
footnotes = notes.footnotes;
|
|
143
151
|
endnotes = notes.endnotes;
|
|
144
152
|
onProgress("Parsed footnotes/endnotes", 75);
|
|
145
153
|
} else onProgress("Skipping footnotes/endnotes", 75);
|
|
146
154
|
onProgress("Parsing comments...", 75);
|
|
147
155
|
const commentsContext = parseContext.scoped({ part: "word/comments.xml" });
|
|
148
|
-
const comments = timeStage("comments", () => parseComments(raw.commentsXml, styles, theme, rels, media, raw.commentsExtensibleXml, raw.commentsExtendedXml, commentsContext));
|
|
156
|
+
const comments = timeStage("comments", () => parseComments(raw.commentsXml, styles, theme, rels, media, raw.commentsExtensibleXml, raw.commentsExtendedXml, commentsContext, previews.ledger));
|
|
157
|
+
const parsedComments = [...comments];
|
|
149
158
|
const commentIdNormalization = normalizeCommentIds(comments);
|
|
159
|
+
if (commentIdNormalization.droppedDuplicateComments > 0) {
|
|
160
|
+
const kept = new Set(comments);
|
|
161
|
+
previews.ledger.release(parsedComments.filter((comment) => !kept.has(comment)));
|
|
162
|
+
}
|
|
150
163
|
if (commentIdNormalization.droppedDuplicateComments > 0) commentsContext.warn({
|
|
151
164
|
code: DUPLICATE_COMMENT_ID_WARNING,
|
|
152
165
|
count: commentIdNormalization.droppedDuplicateComments
|
|
@@ -281,7 +294,7 @@ async function parseDocx(input, options = {}) {
|
|
|
281
294
|
...requiredFonts.length > 0 ? { requiredFonts } : {}
|
|
282
295
|
};
|
|
283
296
|
assignDocumentParagraphPropertySourceContract(document, await paragraphPropertySourceDigest);
|
|
284
|
-
|
|
297
|
+
previews.enforce(previewBudget);
|
|
285
298
|
const validation = validateFolioDocumentModel(document);
|
|
286
299
|
const parsedCompleteModel = parseHeadersFooters && parseNotes;
|
|
287
300
|
if (!validation.valid && parsedCompleteModel) throw new DocxModelValidationError("Parsed DOCX produced an invalid document model", validation.issues);
|
|
@@ -463,7 +476,7 @@ function getHeaderFooterXml(raw, partPath, indexedParts) {
|
|
|
463
476
|
const filename = partPath.split("/").pop() ?? partPath;
|
|
464
477
|
return getMapCaseInsensitive(raw.allXml, partPath) ?? getMapCaseInsensitive(indexedParts, filename);
|
|
465
478
|
}
|
|
466
|
-
function parseHeadersAndFooters(raw, styles, theme, numbering, rels, media) {
|
|
479
|
+
function parseHeadersAndFooters(raw, styles, theme, numbering, rels, media, previews) {
|
|
467
480
|
const headers = /* @__PURE__ */ new Map();
|
|
468
481
|
const footers = /* @__PURE__ */ new Map();
|
|
469
482
|
for (const [rId, rel] of rels.entries()) if (rel.type === RELATIONSHIP_TYPES.header && rel.target) {
|
|
@@ -473,7 +486,7 @@ function parseHeadersAndFooters(raw, styles, theme, numbering, rels, media) {
|
|
|
473
486
|
const headerRelsPath = getRelationshipsPathForPart(partPath);
|
|
474
487
|
const headerRelsXml = getMapCaseInsensitive(raw.allXml, headerRelsPath);
|
|
475
488
|
const headerRels = headerRelsXml ? parseRelationships(headerRelsXml) : /* @__PURE__ */ new Map();
|
|
476
|
-
const header = parseHeader(headerXml, "default", styles, theme, numbering, headerRels, media);
|
|
489
|
+
const header = parseHeader(headerXml, "default", styles, theme, numbering, headerRels, media, previews);
|
|
477
490
|
const watermark = header.watermark;
|
|
478
491
|
if (watermark?.kind === "picture") {
|
|
479
492
|
const imageRel = headerRels.get(watermark.imageRId);
|
|
@@ -491,7 +504,7 @@ function parseHeadersAndFooters(raw, styles, theme, numbering, rels, media) {
|
|
|
491
504
|
if (footerXml) {
|
|
492
505
|
const footerRelsPath = getRelationshipsPathForPart(partPath);
|
|
493
506
|
const footerRelsXml = getMapCaseInsensitive(raw.allXml, footerRelsPath);
|
|
494
|
-
const footer = parseFooter(footerXml, "default", styles, theme, numbering, footerRelsXml ? parseRelationships(footerRelsXml) : /* @__PURE__ */ new Map(), media);
|
|
507
|
+
const footer = parseFooter(footerXml, "default", styles, theme, numbering, footerRelsXml ? parseRelationships(footerRelsXml) : /* @__PURE__ */ new Map(), media, previews);
|
|
495
508
|
footers.set(rId, footer);
|
|
496
509
|
}
|
|
497
510
|
}
|
|
@@ -503,16 +516,20 @@ function parseHeadersAndFooters(raw, styles, theme, numbering, rels, media) {
|
|
|
503
516
|
/**
|
|
504
517
|
* Parse footnotes and endnotes from raw content
|
|
505
518
|
*/
|
|
506
|
-
function parseNotesContent(raw, styles, theme, numbering, rels, media, context) {
|
|
519
|
+
function parseNotesContent(raw, styles, theme, numbering, rels, media, context, previews) {
|
|
507
520
|
const relsForNotePart = (partPath) => {
|
|
508
521
|
const xml = getMapCaseInsensitive(raw.allXml, getRelationshipsPathForPart(partPath));
|
|
509
522
|
return xml ? parseRelationships(xml) : rels;
|
|
510
523
|
};
|
|
511
|
-
const footnoteMap = parseFootnotes(raw.footnotesXml, styles, theme, numbering, relsForNotePart("word/footnotes.xml"), media, context
|
|
512
|
-
const endnoteMap = parseEndnotes(raw.endnotesXml, styles, theme, numbering, relsForNotePart("word/endnotes.xml"), media, context
|
|
524
|
+
const footnoteMap = parseFootnotes(raw.footnotesXml, styles, theme, numbering, relsForNotePart("word/footnotes.xml"), media, context.scoped({ part: "word/footnotes.xml" }), previews);
|
|
525
|
+
const endnoteMap = parseEndnotes(raw.endnotesXml, styles, theme, numbering, relsForNotePart("word/endnotes.xml"), media, context.scoped({ part: "word/endnotes.xml" }), previews);
|
|
526
|
+
const footnotes = footnoteMap.getNormalFootnotes();
|
|
527
|
+
const endnotes = endnoteMap.getNormalEndnotes();
|
|
528
|
+
previews.release(footnoteMap.footnotes.filter((note) => !footnotes.includes(note)));
|
|
529
|
+
previews.release(endnoteMap.endnotes.filter((note) => !endnotes.includes(note)));
|
|
513
530
|
return {
|
|
514
|
-
footnotes
|
|
515
|
-
endnotes
|
|
531
|
+
footnotes,
|
|
532
|
+
endnotes
|
|
516
533
|
};
|
|
517
534
|
}
|
|
518
535
|
/**
|
|
@@ -590,4 +607,4 @@ async function getDocxSummary(buffer) {
|
|
|
590
607
|
};
|
|
591
608
|
}
|
|
592
609
|
//#endregion
|
|
593
|
-
export { DocxParseError, fullParseDocx, getDocxSummary, getDocxVariables, parseDocx, quickParseDocx };
|
|
610
|
+
export { DocxParseError, fullParseDocx, getDocxSummary, getDocxVariables, parseDocx, parseDocxWithPreviewBudget, quickParseDocx };
|