@stll/folio-core 0.42.0 → 0.44.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 (206) hide show
  1. package/dist/ai-edits/headless.js +6 -5
  2. package/dist/ai-edits/index.d.ts +2 -2
  3. package/dist/ai-edits/index.js +2 -2
  4. package/dist/ai-edits/snapshot.js +13 -9
  5. package/dist/compare/content-alignment.js +16 -1
  6. package/dist/compare/inline-atoms.js +1 -1
  7. package/dist/compare/style-resources.js +6 -0
  8. package/dist/compat/eigenpal.d.ts +2 -2
  9. package/dist/controller/layoutPipeline.d.ts +2 -1
  10. package/dist/controller/layoutPipeline.js +5 -2
  11. package/dist/controller/layoutSession.d.ts +2 -1
  12. package/dist/controller/layoutSession.js +1 -0
  13. package/dist/docx/appVersionNormalization.d.ts +0 -18
  14. package/dist/docx/blockContentParser.js +10 -1
  15. package/dist/docx/blockRangeMarkers.d.ts +36 -0
  16. package/dist/docx/blockRangeMarkers.js +59 -0
  17. package/dist/docx/bookmarkParser.d.ts +2 -20
  18. package/dist/docx/bookmarkParser.js +6 -30
  19. package/dist/docx/borderParser.d.ts +13 -0
  20. package/dist/docx/borderParser.js +71 -0
  21. package/dist/docx/builtInStyles.d.ts +165 -0
  22. package/dist/docx/builtInStyles.js +239 -0
  23. package/dist/docx/commentIdNormalization.d.ts +10 -0
  24. package/dist/docx/commentIdNormalization.js +33 -0
  25. package/dist/docx/commentParser.d.ts +2 -1
  26. package/dist/docx/commentParser.js +34 -7
  27. package/dist/docx/commentReferenceNormalization.d.ts +4 -1
  28. package/dist/docx/commentReferenceNormalization.js +23 -14
  29. package/dist/docx/danglingRelationshipReferences.d.ts +15 -0
  30. package/dist/docx/danglingRelationshipReferences.js +30 -0
  31. package/dist/docx/defaultParagraphStyle.d.ts +39 -0
  32. package/dist/docx/defaultParagraphStyle.js +54 -0
  33. package/dist/docx/documentParser.d.ts +2 -1
  34. package/dist/docx/documentParser.js +2 -2
  35. package/dist/docx/drawingUtils.d.ts +8 -1
  36. package/dist/docx/drawingUtils.js +12 -3
  37. package/dist/docx/fieldParser.js +3 -5
  38. package/dist/docx/footnoteParser.d.ts +3 -2
  39. package/dist/docx/footnoteParser.js +19 -2
  40. package/dist/docx/groupDrawingParser.js +1 -1
  41. package/dist/docx/headerFooterRefParser.d.ts +15 -3
  42. package/dist/docx/headerFooterRefParser.js +51 -14
  43. package/dist/docx/headerFooterReferenceNormalization.d.ts +4 -1
  44. package/dist/docx/headerFooterReferenceNormalization.js +5 -1
  45. package/dist/docx/hyperlinkParser.js +11 -15
  46. package/dist/docx/imageParser.d.ts +1 -1
  47. package/dist/docx/imageParser.js +22 -18
  48. package/dist/docx/imageRawXml.js +5 -5
  49. package/dist/docx/markupRangeMarker.d.ts +15 -0
  50. package/dist/docx/markupRangeMarker.js +44 -0
  51. package/dist/docx/noteReferenceStyles.d.ts +29 -0
  52. package/dist/docx/noteReferenceStyles.js +70 -0
  53. package/dist/docx/numberingParser.js +2 -1
  54. package/dist/docx/numberingReference.d.ts +21 -0
  55. package/dist/docx/numberingReference.js +21 -0
  56. package/dist/docx/numberingReferenceNormalization.d.ts +14 -2
  57. package/dist/docx/numberingReferenceNormalization.js +51 -9
  58. package/dist/docx/paraIdRangeNormalization.d.ts +0 -19
  59. package/dist/docx/paragraphParser.js +69 -101
  60. package/dist/docx/paragraphPropertySource.js +1 -0
  61. package/dist/docx/paragraphTraversal.d.ts +37 -1
  62. package/dist/docx/paragraphTraversal.js +84 -1
  63. package/dist/docx/parseContext.d.ts +37 -0
  64. package/dist/docx/parseContext.js +67 -0
  65. package/dist/docx/parseWarningMessage.d.ts +6 -0
  66. package/dist/docx/parseWarningMessage.js +44 -0
  67. package/dist/docx/parser.js +86 -24
  68. package/dist/docx/relsParser.d.ts +28 -11
  69. package/dist/docx/relsParser.js +26 -13
  70. package/dist/docx/revisionIdNormalization.js +81 -7
  71. package/dist/docx/rezip.js +85 -27
  72. package/dist/docx/runConsolidator.js +1 -2
  73. package/dist/docx/runParser.d.ts +8 -1
  74. package/dist/docx/runParser.js +30 -48
  75. package/dist/docx/sectionParser.d.ts +2 -1
  76. package/dist/docx/sectionParser.js +21 -65
  77. package/dist/docx/serializer/borderSerializer.d.ts +1 -2
  78. package/dist/docx/serializer/commentSerializer.js +22 -9
  79. package/dist/docx/serializer/documentSerializer.d.ts +1 -5
  80. package/dist/docx/serializer/documentSerializer.js +6 -16
  81. package/dist/docx/serializer/headerFooterSerializer.js +5 -0
  82. package/dist/docx/serializer/markupRangeAttributes.d.ts +8 -0
  83. package/dist/docx/serializer/markupRangeAttributes.js +24 -0
  84. package/dist/docx/serializer/noteSerializer.js +5 -0
  85. package/dist/docx/serializer/paragraphSerializer.d.ts +1 -5
  86. package/dist/docx/serializer/paragraphSerializer.js +29 -35
  87. package/dist/docx/serializer/runSerializer.js +13 -7
  88. package/dist/docx/serializer/tableSerializer.js +28 -13
  89. package/dist/docx/serializer/textFormattingSerializer.d.ts +2 -3
  90. package/dist/docx/server/build.js +8 -1
  91. package/dist/docx/server/createBilingualDocument.js +15 -22
  92. package/dist/docx/server/extractDocxText.js +3 -4
  93. package/dist/docx/shadingParser.d.ts +6 -0
  94. package/dist/docx/shadingParser.js +32 -0
  95. package/dist/docx/shapeParser.js +3 -3
  96. package/dist/docx/styleParser.js +15 -89
  97. package/dist/docx/styleReferenceResolution.d.ts +36 -0
  98. package/dist/docx/styleReferenceResolution.js +51 -0
  99. package/dist/docx/tableLook.d.ts +57 -0
  100. package/dist/docx/tableLook.js +63 -0
  101. package/dist/docx/tableParser.d.ts +7 -9
  102. package/dist/docx/tableParser.js +64 -110
  103. package/dist/docx/textBoxParser.js +4 -4
  104. package/dist/docx/trackedMoveRangeNormalization.d.ts +3 -1
  105. package/dist/docx/trackedMoveRangeNormalization.js +11 -21
  106. package/dist/docx/transitionalSpelling.d.ts +13 -2
  107. package/dist/docx/transitionalSpelling.js +23 -1
  108. package/dist/docx/verbatimCapture.js +4 -11
  109. package/dist/docx/vmlImageParser.js +2 -2
  110. package/dist/docx/watermarkParser.js +2 -2
  111. package/dist/docx/xmlParser.d.ts +22 -32
  112. package/dist/docx/xmlParser.js +36 -21
  113. package/dist/index.d.ts +2 -2
  114. package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +2 -0
  115. package/dist/internal/pageBreakRunSourceDescendantIndex.js +9 -6
  116. package/dist/internal/paragraphFormattingSerialization.d.ts +2 -3
  117. package/dist/internal/paragraphFormattingSerialization.js +26 -6
  118. package/dist/layout-bridge/convert/footnoteLayout.js +2 -7
  119. package/dist/layout-bridge/convert/templatePreviewFlow.d.ts +19 -11
  120. package/dist/layout-bridge/convert/templatePreviewFlow.js +103 -38
  121. package/dist/layout-bridge/convert/toFlowBlocks.js +12 -3
  122. package/dist/layout-engine/index.d.ts +2 -2
  123. package/dist/layout-engine/index.js +2 -2
  124. package/dist/layout-engine/measure/measureBlocks.js +1 -6
  125. package/dist/layout-engine/types.d.ts +8 -2
  126. package/dist/layout-engine/types.js +35 -2
  127. package/dist/markdown/index.js +1 -1
  128. package/dist/markdown/internals.d.ts +6 -1
  129. package/dist/markdown/internals.js +14 -1
  130. package/dist/markdown/renderBlock.js +35 -21
  131. package/dist/markdown/renderParagraph.js +14 -5
  132. package/dist/markdown/renderRuns.js +4 -3
  133. package/dist/markdown/renderTable.js +4 -3
  134. package/dist/markdown/trailers.js +41 -7
  135. package/dist/markdown/types.d.ts +3 -7
  136. package/dist/prosemirror/attrs/index.js +2 -5
  137. package/dist/prosemirror/bookmarkBoundaryAttrs.d.ts +11 -1
  138. package/dist/prosemirror/bookmarkBoundaryAttrs.js +18 -3
  139. package/dist/prosemirror/commands/index.d.ts +3 -3
  140. package/dist/prosemirror/commands/index.js +2 -2
  141. package/dist/prosemirror/commands/pageBreak.js +12 -1
  142. package/dist/prosemirror/commands/paragraph.d.ts +3 -3
  143. package/dist/prosemirror/commands/paragraph.js +2 -2
  144. package/dist/prosemirror/commentIdAllocator.js +2 -7
  145. package/dist/prosemirror/conversion/fromProseDoc.js +131 -41
  146. package/dist/prosemirror/conversion/toProseDoc.d.ts +1 -14
  147. package/dist/prosemirror/conversion/toProseDoc.js +402 -328
  148. package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +14 -1
  149. package/dist/prosemirror/extensions/core/ParagraphExtension.js +11 -6
  150. package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +3 -3
  151. package/dist/prosemirror/extensions/features/ListExtension.js +42 -4
  152. package/dist/prosemirror/extensions/features/PasteCleanupExtension.d.ts +4 -1
  153. package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +6 -2
  154. package/dist/prosemirror/extensions/features/pastedHeadingStyles.d.ts +7 -0
  155. package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +74 -0
  156. package/dist/prosemirror/extensions/marks/markUtils.d.ts +11 -3
  157. package/dist/prosemirror/extensions/marks/markUtils.js +98 -19
  158. package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +7 -3
  159. package/dist/prosemirror/extensions/nodes/ImageExtension.js +2 -1
  160. package/dist/prosemirror/extensions/nodes/ShapeExtension.js +1 -0
  161. package/dist/prosemirror/extensions/nodes/TableExtension.js +15 -1
  162. package/dist/prosemirror/extensions/types.d.ts +2 -2
  163. package/dist/prosemirror/index.d.ts +3 -3
  164. package/dist/prosemirror/index.js +3 -3
  165. package/dist/prosemirror/insertOperations.d.ts +9 -2
  166. package/dist/prosemirror/insertOperations.js +9 -4
  167. package/dist/prosemirror/listMarker.js +2 -1
  168. package/dist/prosemirror/numberedRefFields.js +2 -1
  169. package/dist/prosemirror/pageBreakRunProjection.d.ts +11 -3
  170. package/dist/prosemirror/pageBreakRunProjection.js +16 -8
  171. package/dist/prosemirror/paragraphFormattingProvenance.d.ts +159 -0
  172. package/dist/prosemirror/paragraphFormattingProvenance.js +106 -0
  173. package/dist/prosemirror/plugins/documentStyles.d.ts +9 -1
  174. package/dist/prosemirror/plugins/documentStyles.js +11 -1
  175. package/dist/prosemirror/plugins/index.d.ts +2 -2
  176. package/dist/prosemirror/plugins/index.js +2 -2
  177. package/dist/prosemirror/plugins/revisionIds.d.ts +11 -2
  178. package/dist/prosemirror/plugins/revisionIds.js +21 -6
  179. package/dist/prosemirror/plugins/templatePreviewValues.d.ts +42 -1
  180. package/dist/prosemirror/plugins/templatePreviewValues.js +217 -14
  181. package/dist/prosemirror/runFormattingReconciliation.js +3 -2
  182. package/dist/prosemirror/runStyleFormatting.d.ts +1 -1
  183. package/dist/prosemirror/schema/nodes.d.ts +31 -0
  184. package/dist/prosemirror/styles/resolvedStyleAttrs.js +4 -1
  185. package/dist/prosemirror/styles/styleResolver.d.ts +9 -0
  186. package/dist/prosemirror/styles/styleResolver.js +15 -6
  187. package/dist/prosemirror/utils/visualLineNavigation.d.ts +22 -2
  188. package/dist/prosemirror/utils/visualLineNavigation.js +80 -63
  189. package/dist/style-engine/styleEngine.d.ts +4 -1
  190. package/dist/style-engine/styleEngine.js +3 -0
  191. package/dist/style-sets/extract.js +35 -11
  192. package/dist/style-sets/stellaStyle.js +46 -39
  193. package/dist/style-sets/styleSetNormalization.d.ts +19 -0
  194. package/dist/style-sets/styleSetNormalization.js +99 -0
  195. package/dist/types/content.d.ts +2 -2
  196. package/dist/utils/createDocument.js +145 -20
  197. package/dist/utils/headingCollector.d.ts +8 -5
  198. package/dist/utils/headingCollector.js +23 -25
  199. package/dist/utils/tableOfContentsStyle.js +9 -2
  200. package/package.json +3 -2
  201. package/dist/docx/textWhitespace.d.ts +0 -4
  202. package/dist/docx/textWhitespace.js +0 -4
  203. package/dist/layout-bridge/engine/tableWidthUtils.d.ts +0 -6
  204. package/dist/layout-bridge/engine/tableWidthUtils.js +0 -25
  205. package/dist/markdown/headings.d.ts +0 -13
  206. package/dist/markdown/headings.js +0 -20
@@ -1,4 +1,4 @@
1
- import { seedRevisionIdsAbove } from "./plugins/revisionIds.js";
1
+ import { maxAnnotationIdInDoc, seedRevisionIdsAbove } from "./plugins/revisionIds.js";
2
2
  import { MAX_REVISION_ID } from "@stll/docx-core/model";
3
3
  //#region src/prosemirror/commentIdAllocator.ts
4
4
  /** Sentinel ID for a comment that hasn't been persisted yet (anchored to selection). */
@@ -32,12 +32,7 @@ function createCommentIdAllocator() {
32
32
  function seedCommentAllocator(allocator, comments, view) {
33
33
  let max = 0;
34
34
  for (const comment of comments ?? []) if (Number.isInteger(comment.id) && comment.id > max && comment.id <= MAX_REVISION_ID) max = comment.id;
35
- if (view) view.state.doc.descendants((node) => {
36
- for (const mark of node.marks) {
37
- const revisionId = mark.attrs["revisionId"];
38
- if (typeof revisionId === "number" && Number.isInteger(revisionId) && revisionId > max && revisionId <= MAX_REVISION_ID) max = revisionId;
39
- }
40
- });
35
+ if (view) max = Math.max(max, maxAnnotationIdInDoc(view.state.doc));
41
36
  allocator.seedAbove(max);
42
37
  seedRevisionIdsAbove(max);
43
38
  }
@@ -1,4 +1,5 @@
1
1
  import { EDITED_PREVIEW_FINGERPRINT, imageRawXmlFingerprint } from "../../docx/imageRawXml.js";
2
+ import { isNumberingReference } from "../../docx/numberingReference.js";
2
3
  import { PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR, ParagraphPropertySourceValidationError, copyDocumentParagraphPropertySourceContract, copyDocumentParagraphPropertySources, copyParagraphPropertyCapture, copyParagraphPropertySource, decodeTableCellParagraphSourcePayload, getDocumentParagraphPropertySourceContract, getParagraphPropertySource, getParagraphPropertySourceCandidate, getParagraphPropertySourceToken, getParagraphPropertySourceTransferId, getProseDocumentParagraphPropertySourceContract, getProseParagraphPropertySourceToken, isParagraphPropertySourceToken, linkParagraphPropertySourceCandidate, paragraphPropertySourceBelongsToDocument, paragraphPropertySourceTokenMatchesContract, recreateProseNodeWithParagraphPropertySource, restoreTableCellsWithParagraphPropertySources, visitDocumentStoryParagraphs, visitTableCellParagraphPropertySourceBindings } from "../../docx/paragraphPropertySource.js";
3
4
  import { visitDocxParagraphs } from "../../docx/paragraphTraversal.js";
4
5
  import { ShapeOutlineStyleSchema, narrowEnum } from "../../docx/parserEnums.js";
@@ -12,9 +13,10 @@ import { mergeTextFormatting } from "../../utils/textFormattingMerge.js";
12
13
  import { pixelsToEmu } from "../../utils/units.js";
13
14
  import { expectBlockSdtAttrs, expectCharacterSpacingMarkAttrs, expectCharacterStyleMarkAttrs, expectCommentMarkAttrs, expectEmphasisMarkAttrs, expectFieldAttrs, expectFontFamilyMarkAttrs, expectFontSizeMarkAttrs, expectFootnoteRefMarkAttrs, expectHardBreakAttrs, expectHighlightMarkAttrs, expectHyperlinkMarkAttrs, expectImageAttrs, expectLanguageMarkAttrs, expectMathAttrs, expectPageBreakRunAttrs, expectPageBreakRunOwnerMarkAttrs, expectParagraphAttrs, expectRunFormattingOverrideMarkAttrs, expectRunPropertyChangeMarkAttrs, expectRunShadingMarkAttrs, expectSdtAttrs, expectShapeAttrs, expectStrikeMarkAttrs, expectSymbolAttrs, expectTabAttrs, expectTableAttrs, expectTableCellAttrs, expectTableRowAttrs, expectTextBoxAttrs, expectTextColorMarkAttrs, expectTextEffectMarkAttrs, expectTrackedChangeMarkAttrs, expectUnderlineMarkAttrs } from "../attrs/index.js";
14
15
  import { autospacingMatchesBase, hasAutospacingBaseSide } from "../autospacingBase.js";
15
- import { expectBookmarkBoundaryAttrs } from "../bookmarkBoundaryAttrs.js";
16
+ import { bookmarkBoundaryDisplacement, expectBookmarkBoundaryAttrs } from "../bookmarkBoundaryAttrs.js";
16
17
  import { paragraphRejectAttrPatch, paragraphRejectOriginalFormatting, removeParagraphPropertyChanges } from "../commands/propertyChangeScope.js";
17
18
  import { applyRunFormattingOverrideAttrs, buildRunFormattingOverrideAttrs } from "../extensions/marks/RunFormattingOverrideExtension.js";
19
+ import { textFormattingToMarks } from "../extensions/marks/markUtils.js";
18
20
  import { listRenderingFromAttrs as listRenderingFromAttrs$1 } from "../listRenderingAttrs.js";
19
21
  import { resolveNumberedRefFields } from "../numberedRefFields.js";
20
22
  import { directParagraphAlignment } from "../paragraphAlignment.js";
@@ -23,12 +25,12 @@ import { directParagraphSpacing } from "../paragraphSpacing.js";
23
25
  import { RUN_FORMATTING_MARK_NAMES } from "../runFormattingMarkNames.js";
24
26
  import { authoredRunFormattingFromAttrs, hasAuthoredRunFormattingProvenance } from "../runFormattingProvenance.js";
25
27
  import { paragraphFormattingForRun, paragraphRunStyleContext, resolveEffectiveRunStyleFormatting, suppressParagraphMarkFormatting } from "../runStyleFormatting.js";
28
+ import { schema } from "../schema/index.js";
26
29
  import { parseShapeGeometryAdjustments } from "../shapeGeometryAdjustments.js";
27
30
  import { expectTextBoxAnchorAttrs } from "../textBoxAnchorAttrs.js";
28
31
  import { assertValidProseMirrorDocument } from "../validation.js";
29
32
  import { runShadingAttrsToShading, shadingToRunShadingAttrs } from "./runShadingMark.js";
30
33
  import { decodeSdtListItems, sdtPropertiesFromAttrs, sdtPropertiesMatchAttrs } from "./sdtAttrs.js";
31
- import { textFormattingToMarks } from "./toProseDoc.js";
32
34
  import { panic } from "better-result";
33
35
  import { Fragment } from "prosemirror-model";
34
36
  import { DRAWING_RAW_XML_MODES } from "@stll/docx-core/model";
@@ -270,7 +272,7 @@ function stripSuggestedInlineMarks(marks, { baseParagraphFormatting, inheritedFo
270
272
  styleResolver
271
273
  }) : paragraphFormatting, previousFormatting);
272
274
  next = next.filter((mark) => !RUN_FORMATTING_MARK_NAMES.has(mark.type.name));
273
- for (const restored of textFormattingToMarks(effectivePreviousFormatting, {
275
+ for (const restored of textFormattingToMarks(effectivePreviousFormatting, schema, {
274
276
  overrideFormatting: previousFormatting,
275
277
  directFormatting: previousFormatting
276
278
  })) next = restored.addToSet(next);
@@ -644,17 +646,47 @@ function replaceTextBoxAnchorInBlocks(blocks, marker, textBoxRun) {
644
646
  }
645
647
  return false;
646
648
  }
649
+ /**
650
+ * The inline list a text-box anchor run can be spliced out of, or nothing when
651
+ * the item holds no such list.
652
+ *
653
+ * A complex field keeps its runs in `fieldCode`/`fieldResult`, two arrays
654
+ * rather than one, and an anchor has never been placed in either; splicing one
655
+ * would have to pick a side. The marker stays where it is and
656
+ * `removeUnresolvedTextBoxAnchors` leaves it, as before.
657
+ */
658
+ const textBoxAnchorHost = (item) => {
659
+ switch (item.type) {
660
+ case "hyperlink": return item.children;
661
+ case "simpleField": return item.content;
662
+ case "inlineSdt":
663
+ case "insertion":
664
+ case "deletion":
665
+ case "moveFrom":
666
+ case "moveTo":
667
+ case "bidiWrapper": return item.content;
668
+ case "run":
669
+ case "complexField":
670
+ case "bookmarkStart":
671
+ case "bookmarkEnd":
672
+ case "commentRangeStart":
673
+ case "commentRangeEnd":
674
+ case "commentReference":
675
+ case "moveFromRangeStart":
676
+ case "moveFromRangeEnd":
677
+ case "moveToRangeStart":
678
+ case "moveToRangeEnd":
679
+ case "mathEquation": return;
680
+ default: panic(`Unsupported paragraph content: ${JSON.stringify(item)}`);
681
+ }
682
+ };
647
683
  function editTextBoxAnchorInContent(content, marker, replacement) {
648
- for (let index = 0; index < content.length; index += 1) {
649
- const item = content[index];
684
+ for (const [index, item] of content.entries()) {
650
685
  if (item === marker) {
651
686
  content.splice(index, 1, ...replacement ? [replacement] : []);
652
687
  return true;
653
688
  }
654
- let nestedContent;
655
- if (item?.type === "hyperlink") nestedContent = item.children;
656
- else if (item?.type === "simpleField") nestedContent = item.content;
657
- else if (item?.type === "inlineSdt" || item?.type === "insertion" || item?.type === "deletion" || item?.type === "moveFrom" || item?.type === "moveTo") nestedContent = item.content;
689
+ const nestedContent = textBoxAnchorHost(item);
658
690
  if (!nestedContent) continue;
659
691
  const hadContent = nestedContent.length > 0;
660
692
  if (editTextBoxAnchorInContent(nestedContent, marker, replacement)) {
@@ -689,7 +721,7 @@ function removeTextBoxAnchorFromBlocks(blocks, marker) {
689
721
  */
690
722
  function listRenderingFromAttrs(attrs) {
691
723
  const numId = attrs.numPr?.numId;
692
- if (numId === void 0 || numId === 0) return;
724
+ if (!isNumberingReference(numId)) return;
693
725
  if (!(attrs.listMarker != null || attrs.listIsBullet || attrs.listNumFmt != null)) return;
694
726
  return listRenderingFromAttrs$1({
695
727
  attrs,
@@ -799,8 +831,23 @@ const propertyChangeFromAttrs = (change) => {
799
831
  ...currentFormatting !== void 0 && { currentFormatting }
800
832
  };
801
833
  };
834
+ /**
835
+ * What the paragraph states itself for one `w:pPr` field, as opposed to what
836
+ * the style cascade resolved into the same attr.
837
+ *
838
+ * `undefined` means the paragraph states nothing and the field must stay
839
+ * absent: a materialised value is a direct override that outranks the style it
840
+ * was read from, and a later edit to that style no longer reaches the
841
+ * paragraph. A value the source stated directly is always authored, even when
842
+ * it happens to equal the style's.
843
+ */
844
+ const authoredParagraphValue = (field, value, orig, resolved) => {
845
+ if (value === void 0) return;
846
+ if (orig?.[field] !== void 0) return value;
847
+ return sameResolvedValue(value, resolved?.[field]) ? void 0 : value;
848
+ };
802
849
  function assignBooleanToggle(result, attrs, orig, key) {
803
- const value = attrs[key] ?? void 0;
850
+ const value = authoredParagraphValue(key, attrs[key] ?? void 0, orig, attrs._resolvedFormatting);
804
851
  if (value === (orig[key] ?? void 0)) return;
805
852
  if (value === void 0) Reflect.deleteProperty(result, key);
806
853
  else result[key] = value;
@@ -865,14 +912,29 @@ function paragraphAttrsToFormatting(attrs) {
865
912
  assignBooleanToggle(result, attrs, orig, "suppressAutoHyphens");
866
913
  if (attrs.spacingExplicit !== orig.spacingExplicit) if (attrs.spacingExplicit) result.spacingExplicit = attrs.spacingExplicit;
867
914
  else delete result.spacingExplicit;
868
- const bidi = directionToBidi(attrs.direction);
915
+ const bidi = authoredParagraphValue("bidi", directionToBidi(attrs.direction), orig, attrs._resolvedFormatting);
869
916
  if (bidi !== (orig.bidi ?? void 0)) if (bidi === void 0) delete result.bidi;
870
917
  else result.bidi = bidi;
871
918
  return result;
872
919
  }
873
- const outlineLevel = Reflect.get(attrs, "outlineLevel");
874
- const bidi = directionToBidi(attrs.direction);
875
- if (!(directAlignment !== void 0 || shouldSerializeSpaceBefore || shouldSerializeSpaceAfter || beforeAutospacingEdited || afterAutospacingEdited || hasDirectLineSpacing || hasDirectLineSpacingRule || attrs.snapToGrid != null || attrs.indentLeft || attrs.indentRight || attrs.indentFirstLine || attrs.numPr || attrs.styleId || attrs.borders || attrs.shading || attrs.tabs || typeof outlineLevel === "number" || attrs.contextualSpacing || attrs.spacingExplicit || bidi != null || attrs.pageBreakBefore != null || attrs.widowControl != null || attrs.kinsoku != null || attrs.overflowPunctuation != null || attrs.suppressAutoHyphens != null)) return;
920
+ const resolved = attrs._resolvedFormatting;
921
+ const authored = (field, value) => authoredParagraphValue(field, value ?? void 0, void 0, resolved);
922
+ const outlineLevel = authored("outlineLevel", Reflect.get(attrs, "outlineLevel"));
923
+ const bidi = authored("bidi", directionToBidi(attrs.direction));
924
+ const snapToGrid = authored("snapToGrid", attrs.snapToGrid);
925
+ const indentLeft = authored("indentLeft", attrs.indentLeft);
926
+ const indentRight = authored("indentRight", attrs.indentRight);
927
+ const indentFirstLine = authored("indentFirstLine", attrs.indentFirstLine);
928
+ const borders = authored("borders", attrs.borders);
929
+ const shading = authored("shading", attrs.shading);
930
+ const tabs = authored("tabs", attrs.tabs);
931
+ const contextualSpacing = authored("contextualSpacing", attrs.contextualSpacing);
932
+ const pageBreakBefore = authored("pageBreakBefore", attrs.pageBreakBefore);
933
+ const widowControl = authored("widowControl", attrs.widowControl);
934
+ const kinsoku = authored("kinsoku", attrs.kinsoku);
935
+ const overflowPunctuation = authored("overflowPunctuation", attrs.overflowPunctuation);
936
+ const suppressAutoHyphens = authored("suppressAutoHyphens", attrs.suppressAutoHyphens);
937
+ if (!(directAlignment !== void 0 || shouldSerializeSpaceBefore || shouldSerializeSpaceAfter || beforeAutospacingEdited || afterAutospacingEdited || hasDirectLineSpacing || hasDirectLineSpacingRule || snapToGrid != null || indentLeft || indentRight || indentFirstLine || attrs.numPr || attrs.styleId || borders || shading || tabs || typeof outlineLevel === "number" || contextualSpacing || attrs.spacingExplicit || bidi != null || pageBreakBefore != null || widowControl != null || kinsoku != null || overflowPunctuation != null || suppressAutoHyphens != null)) return;
876
938
  const f = {};
877
939
  if (directAlignment !== void 0) f.alignment = directAlignment;
878
940
  if (shouldSerializeSpaceBefore) f.spaceBefore = spaceBefore;
@@ -881,25 +943,25 @@ function paragraphAttrsToFormatting(attrs) {
881
943
  if (afterAutospacingEdited) f.afterAutospacing = false;
882
944
  if (hasDirectLineSpacing && typeof attrs.lineSpacing === "number") f.lineSpacing = attrs.lineSpacing;
883
945
  if (hasDirectLineSpacingRule && attrs.lineSpacingRule) f.lineSpacingRule = attrs.lineSpacingRule;
884
- if (attrs.snapToGrid != null) f.snapToGrid = attrs.snapToGrid;
946
+ if (snapToGrid != null) f.snapToGrid = snapToGrid;
885
947
  if (attrs.spacingExplicit) f.spacingExplicit = attrs.spacingExplicit;
886
- if (attrs.indentLeft) f.indentLeft = attrs.indentLeft;
887
- if (attrs.indentRight) f.indentRight = attrs.indentRight;
888
- if (attrs.indentFirstLine) f.indentFirstLine = attrs.indentFirstLine;
889
- if (attrs.hangingIndent) f.hangingIndent = attrs.hangingIndent;
948
+ if (indentLeft) f.indentLeft = indentLeft;
949
+ if (indentRight) f.indentRight = indentRight;
950
+ if (indentFirstLine) f.indentFirstLine = indentFirstLine;
951
+ if (attrs.hangingIndent && indentFirstLine) f.hangingIndent = attrs.hangingIndent;
890
952
  if (attrs.numPr && !isStyleSourcedParagraphNumbering(attrs.numPr, attrs.numPrFromStyle)) f.numPr = attrs.numPr;
891
953
  if (attrs.styleId) f.styleId = attrs.styleId;
892
- if (attrs.borders) f.borders = attrs.borders;
893
- if (attrs.shading) f.shading = attrs.shading;
894
- if (attrs.tabs) f.tabs = attrs.tabs;
954
+ if (borders) f.borders = borders;
955
+ if (shading) f.shading = shading;
956
+ if (tabs) f.tabs = tabs;
895
957
  if (typeof outlineLevel === "number") f.outlineLevel = outlineLevel;
896
- if (attrs.contextualSpacing) f.contextualSpacing = attrs.contextualSpacing;
958
+ if (contextualSpacing) f.contextualSpacing = contextualSpacing;
897
959
  if (bidi != null) f.bidi = bidi;
898
- if (attrs.pageBreakBefore != null) f.pageBreakBefore = attrs.pageBreakBefore;
899
- if (attrs.widowControl != null) f.widowControl = attrs.widowControl;
900
- if (attrs.kinsoku != null) f.kinsoku = attrs.kinsoku;
901
- if (attrs.overflowPunctuation != null) f.overflowPunctuation = attrs.overflowPunctuation;
902
- if (attrs.suppressAutoHyphens != null) f.suppressAutoHyphens = attrs.suppressAutoHyphens;
960
+ if (pageBreakBefore != null) f.pageBreakBefore = pageBreakBefore;
961
+ if (widowControl != null) f.widowControl = widowControl;
962
+ if (kinsoku != null) f.kinsoku = kinsoku;
963
+ if (overflowPunctuation != null) f.overflowPunctuation = overflowPunctuation;
964
+ if (suppressAutoHyphens != null) f.suppressAutoHyphens = suppressAutoHyphens;
903
965
  return f;
904
966
  }
905
967
  function createTrackedRunWrapper(type, info, child) {
@@ -1142,10 +1204,12 @@ function extractParagraphContent(paragraph, _documentCounts, emptyHyperlinks, te
1142
1204
  id: attrs.id,
1143
1205
  name: attrs.name,
1144
1206
  ...attrs.colFirst !== void 0 ? { colFirst: attrs.colFirst } : {},
1145
- ...attrs.colLast !== void 0 ? { colLast: attrs.colLast } : {}
1207
+ ...attrs.colLast !== void 0 ? { colLast: attrs.colLast } : {},
1208
+ ...bookmarkBoundaryDisplacement(attrs)
1146
1209
  } : {
1147
1210
  type: "bookmarkEnd",
1148
- id: attrs.id
1211
+ id: attrs.id,
1212
+ ...bookmarkBoundaryDisplacement(attrs)
1149
1213
  };
1150
1214
  currentTrackedChange.wrapper.content.push(boundary);
1151
1215
  return;
@@ -1208,11 +1272,13 @@ function extractParagraphContent(paragraph, _documentCounts, emptyHyperlinks, te
1208
1272
  id: attrs.id,
1209
1273
  name: attrs.name,
1210
1274
  ...attrs.colFirst !== void 0 ? { colFirst: attrs.colFirst } : {},
1211
- ...attrs.colLast !== void 0 ? { colLast: attrs.colLast } : {}
1275
+ ...attrs.colLast !== void 0 ? { colLast: attrs.colLast } : {},
1276
+ ...bookmarkBoundaryDisplacement(attrs)
1212
1277
  });
1213
1278
  else content.push({
1214
1279
  type: "bookmarkEnd",
1215
- id: attrs.id
1280
+ id: attrs.id,
1281
+ ...bookmarkBoundaryDisplacement(attrs)
1216
1282
  });
1217
1283
  } else if (node.isText) appendDirectRun(node, createRunFromText({
1218
1284
  ...formattingContext,
@@ -1425,11 +1491,13 @@ function addNodeToHyperlink({ baseParagraphFormatting, hyperlink, inheritedForma
1425
1491
  id: attrs.id,
1426
1492
  name: attrs.name,
1427
1493
  ...attrs.colFirst !== void 0 ? { colFirst: attrs.colFirst } : {},
1428
- ...attrs.colLast !== void 0 ? { colLast: attrs.colLast } : {}
1494
+ ...attrs.colLast !== void 0 ? { colLast: attrs.colLast } : {},
1495
+ ...bookmarkBoundaryDisplacement(attrs)
1429
1496
  });
1430
1497
  else hyperlink.children.push({
1431
1498
  type: "bookmarkEnd",
1432
- id: attrs.id
1499
+ id: attrs.id,
1500
+ ...bookmarkBoundaryDisplacement(attrs)
1433
1501
  });
1434
1502
  return;
1435
1503
  }
@@ -1817,6 +1885,14 @@ function createInlineSdtFromNode(node, textBoxAnchorMarkers, formattingContext)
1817
1885
  /**
1818
1886
  * Create a Run containing an image
1819
1887
  */
1888
+ /**
1889
+ * Restore the `w:rPr` an inline atom carried from its source run.
1890
+ *
1891
+ * Image and shape nodes do not hold the run's formatting marks
1892
+ * (`withRunBoundaryMarks` in toProseDoc keeps them off), so the run rebuilt
1893
+ * around one has no other record of the properties it was authored with.
1894
+ */
1895
+ const carriedRunFormatting = (formatting) => formatting && Object.keys(formatting).length > 0 ? { formatting } : {};
1820
1896
  function createImageRun(node) {
1821
1897
  const attrs = expectImageAttrs(node);
1822
1898
  const wrap = { type: attrs.wrapType || "inline" };
@@ -1887,6 +1963,7 @@ function createImageRun(node) {
1887
1963
  }
1888
1964
  return {
1889
1965
  type: "run",
1966
+ ...carriedRunFormatting(attrs._docxRunFormatting),
1890
1967
  content: [drawingFromImageAttrs(image, attrs)]
1891
1968
  };
1892
1969
  }
@@ -1983,12 +2060,14 @@ function createShapeRun(node) {
1983
2060
  if (attrs.outlineColor) shapeOutline.color = attrs.outlineColorValue ?? { rgb: attrs.outlineColor.replace("#", "") };
1984
2061
  shape.outline = shapeOutline;
1985
2062
  }
2063
+ const shapeContent = {
2064
+ type: "shape",
2065
+ shape
2066
+ };
1986
2067
  return {
1987
2068
  type: "run",
1988
- content: [{
1989
- type: "shape",
1990
- shape
1991
- }]
2069
+ ...carriedRunFormatting(attrs._docxRunFormatting),
2070
+ content: [shapeContent]
1992
2071
  };
1993
2072
  }
1994
2073
  const RUN_FORMATTING_VISUAL_GROUPS = {
@@ -2549,6 +2628,17 @@ function marksToTextFormatting(marks, options) {
2549
2628
  /**
2550
2629
  * Convert a ProseMirror table node to our Table type
2551
2630
  */
2631
+ /**
2632
+ * A table the editor created carries no `w:tblPr`, so the borders its cells
2633
+ * were built with are the only record of what the table looks like. Lift the
2634
+ * first bordered cell's set to the table.
2635
+ *
2636
+ * Only for such a table: a table read from a package states its own
2637
+ * `w:tblBorders` or deliberately states none, and its cells' borders may be
2638
+ * the table style's rather than their own. Inferring there invents a
2639
+ * `w:tblBorders` the source never had, and it outranks the table style on
2640
+ * reload (`formatting.borders: absent became object` in the corpus census).
2641
+ */
2552
2642
  function inferTableBorders(rows) {
2553
2643
  for (const row of rows) for (const cell of row.cells) {
2554
2644
  const borders = cell.formatting?.borders;
@@ -2570,7 +2660,7 @@ function convertPMTable(node, documentCounts, styleResolver = null) {
2570
2660
  const attrs = expectTableAttrs(node);
2571
2661
  const rows = convertPMTableRows(node, documentCounts, styleResolver);
2572
2662
  const formatting = tableAttrsToFormatting(attrs) || void 0;
2573
- if (!formatting?.borders) {
2663
+ if (!formatting?.borders && !attrs._originalFormatting) {
2574
2664
  const inferredBorders = inferTableBorders(rows);
2575
2665
  if (inferredBorders) if (formatting) formatting.borders = inferredBorders;
2576
2666
  else {
@@ -2589,7 +2679,7 @@ function convertPMTable(node, documentCounts, styleResolver = null) {
2589
2679
  rows
2590
2680
  };
2591
2681
  if (attrs.columnWidths) table.columnWidths = attrs.columnWidths;
2592
- if (formatting) table.formatting = formatting;
2682
+ if (formatting && Object.keys(formatting).length > 0) table.formatting = formatting;
2593
2683
  restoreTablePropertyChanges(table, attrs);
2594
2684
  return table;
2595
2685
  }
@@ -1,7 +1,6 @@
1
1
  import { document_d_exports } from "../../types/document.js";
2
2
  import { StyleEngine } from "../../style-engine/styleEngine.js";
3
3
  import "../../style-engine/index.js";
4
- import { schema } from "../schema/index.js";
5
4
  import { Node } from "prosemirror-model";
6
5
  //#region src/prosemirror/conversion/toProseDoc.d.ts
7
6
  type UnsupportedDocxToProseMirrorOwner = "complex-field-instruction" | "field-result" | "page-break-bearing-run" | "paragraph-borders" | "paragraph-frame" | "paragraph-outline" | "paragraph-text-box-anchor" | "table-cell" | "text-box";
@@ -39,18 +38,6 @@ declare function resolveParagraphDefaultTextFormatting(styleId: string | undefin
39
38
  includeParagraphMarkRunProperties?: boolean;
40
39
  }): document_d_exports.TextFormatting | undefined;
41
40
  declare function standaloneTableCellToProseMirror(cell: document_d_exports.TableCell, nodeType: "tableCell" | "tableHeader"): Node;
42
- type AuthoredRunFormattingCarrier = "preserve" | "reconstruct";
43
- /**
44
- * Convert TextFormatting to ProseMirror marks
45
- */
46
- type TextFormattingToMarksOptions = {
47
- overrideFormatting: document_d_exports.TextFormatting | undefined;
48
- /** Direct standard font properties whose authored provenance must survive. */
49
- directFormatting?: document_d_exports.TextFormatting | undefined;
50
- /** Whether direct authorship is reconstructible from structural marks and the style context. */
51
- authoredCarrier?: AuthoredRunFormattingCarrier;
52
- };
53
- declare function textFormattingToMarks(formatting: document_d_exports.TextFormatting | undefined, options?: TextFormattingToMarksOptions): ReturnType<typeof schema.mark>[];
54
41
  /**
55
42
  * Convert HeaderFooter content (array of Paragraph/Table blocks) to a ProseMirror document.
56
43
  * Used for editing headers/footers in their own ProseMirror editor and for
@@ -66,4 +53,4 @@ declare function footnoteToProseDoc(content: document_d_exports.BlockContent[],
66
53
  */
67
54
  declare function createEmptyDoc(): Node;
68
55
  //#endregion
69
- export { ToProseDocOptions, UnsupportedDocxToProseMirrorConversionError, createEmptyDoc, footnoteToProseDoc, headerFooterToProseDoc, resolveParagraphDefaultTextFormatting, standaloneTableCellToProseMirror, textFormattingToMarks, toProseDoc };
56
+ export { ToProseDocOptions, UnsupportedDocxToProseMirrorConversionError, createEmptyDoc, footnoteToProseDoc, headerFooterToProseDoc, resolveParagraphDefaultTextFormatting, standaloneTableCellToProseMirror, toProseDoc };