@stll/folio-core 0.47.7 → 0.49.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.
Files changed (213) hide show
  1. package/dist/ai-edits/apply.js +565 -121
  2. package/dist/ai-edits/minimal-replacement.d.ts +64 -0
  3. package/dist/ai-edits/minimal-replacement.js +282 -0
  4. package/dist/controller/fontReadiness.js +3 -3
  5. package/dist/controller/hyphenationReadiness.d.ts +19 -0
  6. package/dist/controller/hyphenationReadiness.js +47 -0
  7. package/dist/controller/layoutPipeline.d.ts +3 -0
  8. package/dist/controller/layoutPipeline.js +70 -18
  9. package/dist/display-list/build/buildDisplayList.js +39 -12
  10. package/dist/display-list/build/pageFurniture.d.ts +7 -1
  11. package/dist/display-list/build/pageFurniture.js +21 -8
  12. package/dist/display-list/build/paragraphPrimitives.js +68 -11
  13. package/dist/display-list/build/tablePrimitives.js +10 -6
  14. package/dist/display-list/build/textBoxPrimitives.js +1 -1
  15. package/dist/display-list/build/unsupported.d.ts +2 -2
  16. package/dist/display-list/build/unsupported.js +0 -0
  17. package/dist/display-list/dom/renderDisplayListToDom.js +0 -1
  18. package/dist/docx/attributeRemainder.js +10 -2
  19. package/dist/docx/blockContentParser.d.ts +2 -0
  20. package/dist/docx/blockContentParser.js +79 -64
  21. package/dist/docx/bulletMarkers.d.ts +18 -2
  22. package/dist/docx/bulletMarkers.js +27 -2
  23. package/dist/docx/commentParser.d.ts +2 -1
  24. package/dist/docx/commentParser.js +57 -45
  25. package/dist/docx/containerChildren.d.ts +21 -8
  26. package/dist/docx/containerChildren.js +39 -9
  27. package/dist/docx/documentParser.d.ts +5 -1
  28. package/dist/docx/documentParser.js +8 -5
  29. package/dist/docx/documentSectionFacts.d.ts +22 -0
  30. package/dist/docx/documentSectionFacts.js +43 -0
  31. package/dist/docx/drawingGroupChildren.d.ts +60 -0
  32. package/dist/docx/drawingGroupChildren.js +176 -0
  33. package/dist/docx/drawingUtils.js +3 -0
  34. package/dist/docx/fieldParser.d.ts +8 -1
  35. package/dist/docx/fieldParser.js +47 -3
  36. package/dist/docx/fontTableParser.js +34 -27
  37. package/dist/docx/footnoteParser.d.ts +3 -2
  38. package/dist/docx/footnoteParser.js +15 -12
  39. package/dist/docx/groupDrawingParser.d.ts +9 -2
  40. package/dist/docx/groupDrawingParser.js +125 -37
  41. package/dist/docx/headerFooterParser.d.ts +7 -2
  42. package/dist/docx/headerFooterParser.js +15 -5
  43. package/dist/docx/hyperlinkParser.d.ts +48 -36
  44. package/dist/docx/hyperlinkParser.js +97 -82
  45. package/dist/docx/numberingParser.js +108 -84
  46. package/dist/docx/packageParts.d.ts +45 -1
  47. package/dist/docx/packageParts.js +93 -2
  48. package/dist/docx/paraIdAttribute.d.ts +3 -2
  49. package/dist/docx/paragraphParser.d.ts +5 -1
  50. package/dist/docx/paragraphParser.js +468 -365
  51. package/dist/docx/paragraphProperties.js +123 -109
  52. package/dist/docx/paragraphPropertySource.d.ts +6 -1
  53. package/dist/docx/paragraphPropertySource.js +9 -1
  54. package/dist/docx/paragraphTextBoxEnrichment.d.ts +2 -1
  55. package/dist/docx/paragraphTextBoxEnrichment.js +143 -10
  56. package/dist/docx/parser.d.ts +7 -1
  57. package/dist/docx/parser.js +33 -16
  58. package/dist/docx/previewBudget.d.ts +55 -33
  59. package/dist/docx/previewBudget.js +59 -65
  60. package/dist/docx/rezip.js +41 -58
  61. package/dist/docx/runParser.d.ts +4 -1
  62. package/dist/docx/runParser.js +182 -184
  63. package/dist/docx/sdtProperties.js +87 -84
  64. package/dist/docx/sectionParser.js +169 -160
  65. package/dist/docx/selectiveSaveFlags.d.ts +10 -3
  66. package/dist/docx/selectiveSaveFlags.js +1 -1
  67. package/dist/docx/selectiveXmlPatch.d.ts +56 -34
  68. package/dist/docx/selectiveXmlPatch.js +222 -115
  69. package/dist/docx/serializer/groupTextBoxWriteBack.d.ts +12 -0
  70. package/dist/docx/serializer/groupTextBoxWriteBack.js +101 -0
  71. package/dist/docx/serializer/paragraphSerializer.js +47 -42
  72. package/dist/docx/serializer/runSerializer.d.ts +5 -1
  73. package/dist/docx/serializer/runSerializer.js +4 -3
  74. package/dist/docx/serializer/settingsSerializer.js +19 -1
  75. package/dist/docx/settingsParser.js +8 -0
  76. package/dist/docx/shapeAlternateContent.d.ts +25 -0
  77. package/dist/docx/shapeAlternateContent.js +52 -0
  78. package/dist/docx/streamingXmlParser.d.ts +6 -2
  79. package/dist/docx/streamingXmlParser.js +12 -7
  80. package/dist/docx/styleParser.js +34 -8
  81. package/dist/docx/tableParser.d.ts +21 -12
  82. package/dist/docx/tableParser.js +518 -441
  83. package/dist/docx/textBoxParser.d.ts +18 -5
  84. package/dist/docx/textBoxParser.js +12 -6
  85. package/dist/docx/verbatimCapture.d.ts +10 -8
  86. package/dist/docx/verbatimCapture.js +45 -2
  87. package/dist/docx/vmlImageParser.d.ts +15 -13
  88. package/dist/docx/vmlImageParser.js +75 -60
  89. package/dist/docx/vmlPreview.d.ts +3 -3
  90. package/dist/docx/vmlPreview.js +3 -4
  91. package/dist/docx/xmlNamespaceContext.d.ts +9 -0
  92. package/dist/docx/xmlNamespaceContext.js +54 -0
  93. package/dist/docx/xmlParser.d.ts +6 -3
  94. package/dist/docx/xmlParser.js +11 -41
  95. package/dist/docx/xmlResourceLimits.d.ts +2 -1
  96. package/dist/docx/xmlResourceLimits.js +4 -1
  97. package/dist/fonts/headlessMeasure.js +0 -0
  98. package/dist/headless-layout.d.ts +11 -2
  99. package/dist/headless-layout.js +153 -107
  100. package/dist/internal/headlessRevisionResolution.js +50 -13
  101. package/dist/internal/paragraphFormattingSerialization.js +3 -3
  102. package/dist/layout-bridge/convert/endnoteLayout.d.ts +65 -0
  103. package/dist/layout-bridge/convert/endnoteLayout.js +227 -0
  104. package/dist/layout-bridge/convert/footnoteLayout.d.ts +19 -3
  105. package/dist/layout-bridge/convert/footnoteLayout.js +40 -31
  106. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -7
  107. package/dist/layout-bridge/convert/headerFooterLayout.js +5 -20
  108. package/dist/layout-bridge/convert/paragraphMarkFormatting.d.ts +10 -0
  109. package/dist/layout-bridge/convert/paragraphMarkFormatting.js +59 -0
  110. package/dist/layout-bridge/convert/toFlowBlocks.d.ts +29 -1
  111. package/dist/layout-bridge/convert/toFlowBlocks.js +284 -39
  112. package/dist/layout-bridge/engine/hitTest.js +5 -3
  113. package/dist/layout-bridge/engine/selectionRects.js +5 -3
  114. package/dist/layout-engine/anchorLayoutInCellCompatibility.d.ts +10 -0
  115. package/dist/layout-engine/anchorLayoutInCellCompatibility.js +22 -0
  116. package/dist/layout-engine/index.d.ts +2 -2
  117. package/dist/layout-engine/index.js +102 -14
  118. package/dist/layout-engine/justificationCompatibility.d.ts +1 -1
  119. package/dist/layout-engine/justificationCompatibility.js +9 -5
  120. package/dist/layout-engine/keep-together.d.ts +15 -6
  121. package/dist/layout-engine/keep-together.js +43 -16
  122. package/dist/layout-engine/layoutInstrumentation.d.ts +8 -2
  123. package/dist/layout-engine/layoutInstrumentation.js +8 -1
  124. package/dist/layout-engine/measure/advanceComposition.js +50 -7
  125. package/dist/layout-engine/measure/hyphenationDictionaries.d.ts +74 -0
  126. package/dist/layout-engine/measure/hyphenationDictionaries.js +138 -0
  127. package/dist/layout-engine/measure/hyphenationPreload.d.ts +11 -0
  128. package/dist/layout-engine/measure/hyphenationPreload.js +24 -0
  129. package/dist/layout-engine/measure/lineBreakProvider.d.ts +12 -2
  130. package/dist/layout-engine/measure/lineBreakProvider.js +30 -30
  131. package/dist/layout-engine/measure/lineBreaks.d.ts +6 -1
  132. package/dist/layout-engine/measure/lineBreaks.js +10 -3
  133. package/dist/layout-engine/measure/listMarkerWidth.d.ts +9 -6
  134. package/dist/layout-engine/measure/listMarkerWidth.js +20 -22
  135. package/dist/layout-engine/measure/measureBlocks.js +46 -10
  136. package/dist/layout-engine/measure/measureContainer.js +51 -8
  137. package/dist/layout-engine/measure/measureHelpers.d.ts +15 -3
  138. package/dist/layout-engine/measure/measureHelpers.js +34 -8
  139. package/dist/layout-engine/measure/measureParagraph.js +143 -101
  140. package/dist/layout-engine/measure/measureTypes.d.ts +5 -0
  141. package/dist/layout-engine/measure/smallCapsCasing.d.ts +56 -0
  142. package/dist/layout-engine/measure/smallCapsCasing.js +88 -0
  143. package/dist/layout-engine/measure/tabCalculator.d.ts +2 -0
  144. package/dist/layout-engine/measure/tabCalculator.js +2 -1
  145. package/dist/layout-engine/measure/tableCellFloating.d.ts +2 -0
  146. package/dist/layout-engine/measure/tableCellFloating.js +51 -19
  147. package/dist/layout-engine/measure/tableCellGrid.d.ts +28 -3
  148. package/dist/layout-engine/measure/tableCellGrid.js +45 -5
  149. package/dist/layout-engine/measure/tableFragmentBorderGeometry.js +2 -1
  150. package/dist/layout-engine/noteAreaFlow.d.ts +19 -0
  151. package/dist/layout-engine/noteAreaFlow.js +83 -0
  152. package/dist/layout-engine/paginator.d.ts +12 -1
  153. package/dist/layout-engine/paginator.js +18 -2
  154. package/dist/layout-engine/paragraphSpacing.d.ts +4 -2
  155. package/dist/layout-engine/paragraphSpacing.js +2 -1
  156. package/dist/layout-engine/tableRowBreak.d.ts +8 -1
  157. package/dist/layout-engine/tableRowBreak.js +25 -2
  158. package/dist/layout-engine/types.d.ts +108 -3
  159. package/dist/layout-engine/types.js +96 -1
  160. package/dist/layout-painter/index.d.ts +3 -0
  161. package/dist/layout-painter/renderPage.js +32 -83
  162. package/dist/layout-painter/renderParagraph.d.ts +6 -1
  163. package/dist/layout-painter/renderParagraph.js +75 -26
  164. package/dist/layout-painter/renderTable.js +26 -13
  165. package/dist/layout-painter/renderTextBox.d.ts +12 -2
  166. package/dist/layout-painter/renderTextBox.js +26 -2
  167. package/dist/prosemirror/alternateContentAttrs.d.ts +9 -0
  168. package/dist/prosemirror/alternateContentAttrs.js +35 -0
  169. package/dist/prosemirror/attrs/index.d.ts +9 -9
  170. package/dist/prosemirror/attrs/index.js +133 -11
  171. package/dist/prosemirror/commands/comments.js +51 -41
  172. package/dist/prosemirror/contentControlRevisions.d.ts +43 -0
  173. package/dist/prosemirror/contentControlRevisions.js +84 -0
  174. package/dist/prosemirror/conversion/fromProseDoc.js +54 -23
  175. package/dist/prosemirror/conversion/markInterner.d.ts +21 -0
  176. package/dist/prosemirror/conversion/markInterner.js +90 -0
  177. package/dist/prosemirror/conversion/toProseDoc.js +117 -58
  178. package/dist/prosemirror/extensions/core/DocExtension.js +2 -1
  179. package/dist/prosemirror/extensions/core/ParagraphExtension.js +1 -0
  180. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +7 -7
  181. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +7 -7
  182. package/dist/prosemirror/extensions/marks/markUtils.d.ts +6 -2
  183. package/dist/prosemirror/extensions/marks/markUtils.js +39 -51
  184. package/dist/prosemirror/extensions/nodes/FieldExtension.js +6 -3
  185. package/dist/prosemirror/extensions/nodes/SdtExtension.js +9 -2
  186. package/dist/prosemirror/extensions/nodes/ShapeExtension.js +1 -0
  187. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +5 -1
  188. package/dist/prosemirror/listMarker.d.ts +1 -0
  189. package/dist/prosemirror/listMarker.js +4 -2
  190. package/dist/prosemirror/listRenderingAttrs.d.ts +1 -0
  191. package/dist/prosemirror/listRenderingAttrs.js +3 -0
  192. package/dist/prosemirror/paragraphDirection.d.ts +29 -2
  193. package/dist/prosemirror/paragraphDirection.js +21 -2
  194. package/dist/prosemirror/plugins/suggestionMode.js +37 -8
  195. package/dist/prosemirror/rejoinRunCarriers.d.ts +27 -0
  196. package/dist/prosemirror/rejoinRunCarriers.js +66 -0
  197. package/dist/prosemirror/runIdentityAcrossRevisions.d.ts +10 -0
  198. package/dist/prosemirror/runIdentityAcrossRevisions.js +90 -0
  199. package/dist/prosemirror/schema/nodes.d.ts +50 -6
  200. package/dist/prosemirror/textBoxHostParagraph.d.ts +13 -0
  201. package/dist/prosemirror/textBoxHostParagraph.js +21 -0
  202. package/dist/prosemirror/validation.js +91 -80
  203. package/dist/types/content.d.ts +2 -2
  204. package/dist/utils/createDocument.js +10 -1
  205. package/dist/utils/scriptSegments.d.ts +33 -4
  206. package/dist/utils/scriptSegments.js +39 -6
  207. package/dist/utils/textFormattingMerge.d.ts +17 -3
  208. package/dist/utils/textFormattingMerge.js +18 -12
  209. package/dist/utils/trailingText.d.ts +22 -0
  210. package/dist/utils/trailingText.js +32 -0
  211. package/package.json +2 -2
  212. package/dist/layout-engine/justifiedLineFit.d.ts +0 -7
  213. package/dist/layout-engine/justifiedLineFit.js +0 -6
@@ -1,6 +1,6 @@
1
1
  import { readAttributeBag } from "./attributeRemainder.js";
2
2
  import { parseBorderSpec } from "./borderParser.js";
3
- import { CAPTURE, dispatchChildren, ownedElsewhere, sequencePositions } from "./containerChildren.js";
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 taken = /* @__PURE__ */ new Set();
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
- pStyle: once("pStyle", (child) => {
111
- const val = getAttribute(child, "w", "val");
112
- if (!val) return false;
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 };
@@ -1,9 +1,12 @@
1
1
  import { pixelsToEmu } from "../utils/units.js";
2
+ import { groupTextContentFingerprint, groupXmlFingerprint } from "./drawingGroupChildren.js";
3
+ import { groupPreviewTextBoxes } from "./groupDrawingParser.js";
2
4
  import { parseParagraph } from "./paragraphParser.js";
3
5
  import { consolidateParagraphContent } from "./runConsolidator.js";
4
- import { getTextBoxContentElement, parseTextBox, parseTextBoxContent, scanRunForTextBoxDrawings } from "./textBoxParser.js";
6
+ import { captureShapeAlternateContent } from "./shapeAlternateContent.js";
7
+ import { getTextBoxContentElement, parseTextBox, parseTextBoxContent, parseTextBoxFromShape, scanRunForTextBoxDrawings } from "./textBoxParser.js";
5
8
  import { isVmlPictParsedByRunParser } from "./vmlImageParser.js";
6
- import { findDeep, getAttribute, getChildElements, getLocalName } from "./xmlParser.js";
9
+ import { findChildByLocalName, findDeep, getAttribute, getChildElements, getLocalName } from "./xmlParser.js";
7
10
  //#region src/docx/paragraphTextBoxEnrichment.ts
8
11
  const VML_HORIZONTAL_RELATIVES = /* @__PURE__ */ new Set([
9
12
  "character",
@@ -121,7 +124,7 @@ const vmlWrapType = (positioned, zIndex) => {
121
124
  if (Number.isFinite(zIndex) && zIndex < 0) return "behind";
122
125
  return "inFront";
123
126
  };
124
- const enrichParagraphTextBoxes = (paragraph, paraXml, styles, theme, numbering, rels, media, parseTable, context) => {
127
+ const enrichParagraphTextBoxes = (paragraph, paraXml, styles, theme, numbering, rels, media, parseTable, previews, context) => {
125
128
  enrichTextBoxRuns({
126
129
  content: paragraph.content,
127
130
  xmlChildren: getChildElements(paraXml),
@@ -131,16 +134,129 @@ const enrichParagraphTextBoxes = (paragraph, paraXml, styles, theme, numbering,
131
134
  rels,
132
135
  media,
133
136
  parseTable,
137
+ previews,
134
138
  context
135
139
  });
140
+ liftGroupTextBoxes(paragraph.content, {
141
+ styles,
142
+ theme,
143
+ numbering,
144
+ rels,
145
+ media,
146
+ parseTable,
147
+ previews
148
+ });
136
149
  paragraph.content = consolidateParagraphContent(paragraph.content);
137
150
  };
151
+ /** Previews whose text boxes were already lifted, so a second pass adds none. */
152
+ const liftedGroupPreviews = /* @__PURE__ */ new WeakSet();
153
+ /**
154
+ * Lift the text boxes out of every group preview in the paragraph, each into
155
+ * a text box shape right after the group's drawing in the same run.
156
+ *
157
+ * The group keeps drawing its other children; a lifted text box is laid out
158
+ * and painted like any anchored text box, placed at the group's offset plus
159
+ * the child's frame, and it records where in the group it came from so the
160
+ * writer can put its text back there.
161
+ */
162
+ const liftGroupTextBoxes = (content, parsers) => {
163
+ for (const item of content) switch (item.type) {
164
+ case "run":
165
+ liftGroupTextBoxesInRun(item, parsers);
166
+ break;
167
+ case "hyperlink":
168
+ liftGroupTextBoxes(item.children, parsers);
169
+ break;
170
+ case "inlineSdt":
171
+ case "insertion":
172
+ case "deletion":
173
+ case "moveFrom":
174
+ case "moveTo":
175
+ liftGroupTextBoxes(item.content, parsers);
176
+ break;
177
+ default: break;
178
+ }
179
+ };
180
+ const liftGroupTextBoxesInRun = (run, parsers) => {
181
+ if (!run.content.some((item) => item.type === "drawing")) return;
182
+ const lifted = [];
183
+ for (const item of run.content) {
184
+ lifted.push(item);
185
+ if (item.type !== "drawing" || item.rawXml === void 0) continue;
186
+ const frames = groupPreviewTextBoxes(item.image);
187
+ if (!frames || liftedGroupPreviews.has(item.image)) continue;
188
+ liftedGroupPreviews.add(item.image);
189
+ const group = groupXmlFingerprint(item.rawXml);
190
+ for (const frame of frames) {
191
+ const shape = groupTextBoxShape(item.image, frame, group, parsers);
192
+ if (shape) lifted.push({
193
+ type: "shape",
194
+ shape
195
+ });
196
+ }
197
+ }
198
+ run.content = lifted;
199
+ };
200
+ const groupTextBoxShape = (groupImage, frame, group, { styles, theme, numbering, rels, media, parseTable, previews }) => {
201
+ const position = groupImage.position;
202
+ const horizontalOffset = position?.horizontal.posOffset;
203
+ const verticalOffset = position?.vertical.posOffset;
204
+ if (!position || horizontalOffset === void 0 || verticalOffset === void 0) return;
205
+ const size = {
206
+ width: Math.round(frame.width),
207
+ height: Math.round(frame.height)
208
+ };
209
+ const textBox = parseTextBoxFromShape(frame.wsp, size);
210
+ const content = parseTextBoxContent(findChildByLocalName(findChildByLocalName(frame.wsp, "txbx"), "txbxContent"), parseParagraph, parseTable, styles, theme, numbering, rels, media, previews);
211
+ const transform = frame.rotation !== 0 || frame.flipH || frame.flipV ? {
212
+ ...frame.rotation !== 0 ? { rotation: frame.rotation } : {},
213
+ ...frame.flipH ? { flipH: true } : {},
214
+ ...frame.flipV ? { flipV: true } : {}
215
+ } : void 0;
216
+ const shape = {
217
+ type: "shape",
218
+ shapeType: "textBox",
219
+ size,
220
+ ...textBox?.name !== void 0 ? { name: textBox.name } : {},
221
+ ...textBox?.alt !== void 0 ? { alt: textBox.alt } : {},
222
+ ...textBox?.title !== void 0 ? { title: textBox.title } : {},
223
+ position: {
224
+ horizontal: {
225
+ relativeTo: position.horizontal.relativeTo,
226
+ posOffset: Math.round(horizontalOffset + frame.x)
227
+ },
228
+ vertical: {
229
+ relativeTo: position.vertical.relativeTo,
230
+ posOffset: Math.round(verticalOffset + frame.y)
231
+ }
232
+ },
233
+ wrap: { type: groupImage.wrap.type === "behind" ? "behind" : "inFront" },
234
+ ...groupImage.anchor !== void 0 ? { anchor: { ...groupImage.anchor } } : {},
235
+ ...textBox?.fill !== void 0 ? { fill: textBox.fill } : {},
236
+ ...textBox?.outline !== void 0 ? { outline: textBox.outline } : {},
237
+ ...transform !== void 0 ? { transform } : {},
238
+ textBody: {
239
+ content,
240
+ ...textBox?.autoFit !== void 0 ? { autoFit: textBox.autoFit } : {},
241
+ ...textBox?.textWrap !== void 0 ? { textWrap: textBox.textWrap } : {},
242
+ ...textBox?.verticalAlign !== void 0 ? { anchor: textBox.verticalAlign } : {},
243
+ ...textBox?.margins !== void 0 ? { margins: textBox.margins } : {}
244
+ },
245
+ groupChild: {
246
+ path: frame.path,
247
+ group,
248
+ content: groupTextContentFingerprint(content)
249
+ }
250
+ };
251
+ if (textBox?.id) shape.id = textBox.id;
252
+ return shape;
253
+ };
138
254
  const trackedChangeTypeFromXml = (localName) => {
139
255
  if (localName === "ins") return "insertion";
140
256
  if (localName === "del") return "deletion";
141
257
  if (localName === "moveFrom" || localName === "moveTo") return localName;
142
258
  };
143
- const enrichTextBoxRuns = ({ content, xmlChildren, styles, theme, numbering, rels, media, parseTable, context }) => {
259
+ const enrichTextBoxRuns = ({ content, xmlChildren, styles, theme, numbering, rels, media, parseTable, previews, context }) => {
144
260
  let parsedIndex = 0;
145
261
  let lastConsumedRun;
146
262
  for (const xmlChild of xmlChildren) {
@@ -157,6 +273,7 @@ const enrichTextBoxRuns = ({ content, xmlChildren, styles, theme, numbering, rel
157
273
  rels,
158
274
  media,
159
275
  parseTable,
276
+ previews,
160
277
  context
161
278
  });
162
279
  if (localName === "sdt" && parsedContent?.type === "inlineSdt") {
@@ -179,6 +296,7 @@ const enrichTextBoxRuns = ({ content, xmlChildren, styles, theme, numbering, rel
179
296
  rels,
180
297
  media,
181
298
  parseTable,
299
+ previews,
182
300
  context
183
301
  });
184
302
  parsedIndex = lastSegmentIndex + 1;
@@ -196,13 +314,13 @@ const enrichTextBoxRuns = ({ content, xmlChildren, styles, theme, numbering, rel
196
314
  const targetRun = parsedRun ?? (hasNonTextBoxContent ? lastConsumedRun : void 0);
197
315
  const targetRunMatchesXml = targetRun !== void 0 && (hasNonTextBoxContent || parsedRun?.content.length === 0);
198
316
  const fillsEmptyCarrier = targetRunMatchesXml && !hasNonTextBoxContent && parsedRun !== void 0;
199
- for (const runEl of textBoxDrawings) {
317
+ for (const { drawing: runEl, alternateContent: source } of textBoxDrawings) {
200
318
  const textBox = parseTextBox(runEl, context);
201
319
  if (!textBox) continue;
202
320
  const wsp = findDeep(runEl, "wps", "wsp");
203
321
  if (wsp) {
204
322
  const txbxContentEl = getTextBoxContentElement(wsp);
205
- if (txbxContentEl) textBox.content = parseTextBoxContent(txbxContentEl, parseParagraph, parseTable, styles, theme, numbering, rels, media);
323
+ if (txbxContentEl) textBox.content = parseTextBoxContent(txbxContentEl, parseParagraph, parseTable, styles, theme, numbering, rels, media, previews);
206
324
  }
207
325
  const shape = {
208
326
  type: "shape",
@@ -226,9 +344,16 @@ const enrichTextBoxRuns = ({ content, xmlChildren, styles, theme, numbering, rel
226
344
  }
227
345
  };
228
346
  if (textBox.id) shape.id = textBox.id;
347
+ const alternateContent = source && captureShapeAlternateContent({
348
+ shape,
349
+ alternateContent: source.element,
350
+ branch: source.branch,
351
+ drawing: runEl
352
+ });
229
353
  const shapeContent = {
230
354
  type: "shape",
231
- shape
355
+ shape,
356
+ ...alternateContent ? { alternateContent } : {}
232
357
  };
233
358
  if (targetRunMatchesXml) targetRun.content.push(shapeContent);
234
359
  else {
@@ -242,7 +367,15 @@ const enrichTextBoxRuns = ({ content, xmlChildren, styles, theme, numbering, rel
242
367
  }
243
368
  }
244
369
  for (const pictEl of vmlTextBoxes) {
245
- const shape = parseVmlTextBoxShape(pictEl, styles, theme, numbering, rels, media, parseTable);
370
+ const shape = parseVmlTextBoxShape(pictEl, {
371
+ styles,
372
+ theme,
373
+ numbering,
374
+ rels,
375
+ media,
376
+ parseTable,
377
+ previews
378
+ });
246
379
  if (!shape) continue;
247
380
  const shapeContent = {
248
381
  type: "shape",
@@ -265,7 +398,7 @@ const enrichTextBoxRuns = ({ content, xmlChildren, styles, theme, numbering, rel
265
398
  }
266
399
  }
267
400
  };
268
- const parseVmlTextBoxShape = (pictEl, styles, theme, numbering, rels, media, parseTable) => {
401
+ const parseVmlTextBoxShape = (pictEl, { styles, theme, numbering, rels, media, parseTable, previews }) => {
269
402
  const shapeEl = findDeep(pictEl, "v", "shape");
270
403
  const textBoxEl = shapeEl ? findDeep(shapeEl, "v", "textbox") : null;
271
404
  const contentEl = textBoxEl ? findDeep(textBoxEl, "w", "txbxContent") : null;
@@ -292,7 +425,7 @@ const parseVmlTextBoxShape = (pictEl, styles, theme, numbering, rels, media, par
292
425
  ...fill === void 0 ? {} : { fill },
293
426
  wrap: { type: vmlWrapType(positioned, zIndex) },
294
427
  textBody: {
295
- content: parseTextBoxContent(contentEl, parseParagraph, parseTable, styles, theme, numbering, rels, media),
428
+ content: parseTextBoxContent(contentEl, parseParagraph, parseTable, styles, theme, numbering, rels, media, previews),
296
429
  ...margins === void 0 ? {} : { margins },
297
430
  ...anchor === void 0 ? {} : { anchor }
298
431
  }
@@ -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 };