@stll/folio-core 0.43.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 (183) 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/docx/appVersionNormalization.d.ts +0 -18
  9. package/dist/docx/blockContentParser.js +8 -0
  10. package/dist/docx/blockRangeMarkers.d.ts +36 -0
  11. package/dist/docx/blockRangeMarkers.js +59 -0
  12. package/dist/docx/bookmarkParser.d.ts +2 -20
  13. package/dist/docx/bookmarkParser.js +6 -30
  14. package/dist/docx/borderParser.d.ts +13 -0
  15. package/dist/docx/borderParser.js +71 -0
  16. package/dist/docx/builtInStyles.d.ts +165 -0
  17. package/dist/docx/builtInStyles.js +239 -0
  18. package/dist/docx/commentIdNormalization.d.ts +3 -1
  19. package/dist/docx/commentIdNormalization.js +18 -1
  20. package/dist/docx/commentParser.d.ts +2 -1
  21. package/dist/docx/commentParser.js +34 -7
  22. package/dist/docx/commentReferenceNormalization.d.ts +4 -1
  23. package/dist/docx/commentReferenceNormalization.js +23 -14
  24. package/dist/docx/danglingRelationshipReferences.d.ts +15 -0
  25. package/dist/docx/danglingRelationshipReferences.js +30 -0
  26. package/dist/docx/defaultParagraphStyle.d.ts +18 -1
  27. package/dist/docx/defaultParagraphStyle.js +23 -1
  28. package/dist/docx/documentParser.d.ts +2 -1
  29. package/dist/docx/documentParser.js +2 -2
  30. package/dist/docx/drawingUtils.d.ts +8 -1
  31. package/dist/docx/drawingUtils.js +12 -3
  32. package/dist/docx/fieldParser.js +3 -5
  33. package/dist/docx/footnoteParser.d.ts +3 -2
  34. package/dist/docx/footnoteParser.js +19 -4
  35. package/dist/docx/groupDrawingParser.js +1 -1
  36. package/dist/docx/headerFooterRefParser.d.ts +4 -3
  37. package/dist/docx/headerFooterRefParser.js +42 -12
  38. package/dist/docx/headerFooterReferenceNormalization.d.ts +4 -1
  39. package/dist/docx/headerFooterReferenceNormalization.js +5 -1
  40. package/dist/docx/hyperlinkParser.js +11 -15
  41. package/dist/docx/imageParser.d.ts +1 -1
  42. package/dist/docx/imageParser.js +22 -18
  43. package/dist/docx/imageRawXml.js +5 -5
  44. package/dist/docx/markupRangeMarker.d.ts +15 -0
  45. package/dist/docx/markupRangeMarker.js +44 -0
  46. package/dist/docx/noteReferenceStyles.d.ts +29 -0
  47. package/dist/docx/noteReferenceStyles.js +70 -0
  48. package/dist/docx/numberingReferenceNormalization.d.ts +4 -1
  49. package/dist/docx/numberingReferenceNormalization.js +20 -1
  50. package/dist/docx/paraIdRangeNormalization.d.ts +0 -19
  51. package/dist/docx/paragraphParser.js +66 -99
  52. package/dist/docx/paragraphPropertySource.js +1 -0
  53. package/dist/docx/paragraphTraversal.d.ts +37 -1
  54. package/dist/docx/paragraphTraversal.js +84 -1
  55. package/dist/docx/parseContext.d.ts +37 -0
  56. package/dist/docx/parseContext.js +67 -0
  57. package/dist/docx/parseWarningMessage.d.ts +6 -0
  58. package/dist/docx/parseWarningMessage.js +44 -0
  59. package/dist/docx/parser.js +81 -27
  60. package/dist/docx/relsParser.d.ts +28 -11
  61. package/dist/docx/relsParser.js +26 -13
  62. package/dist/docx/revisionIdNormalization.js +81 -7
  63. package/dist/docx/rezip.js +63 -22
  64. package/dist/docx/runConsolidator.js +1 -2
  65. package/dist/docx/runParser.d.ts +8 -1
  66. package/dist/docx/runParser.js +30 -48
  67. package/dist/docx/sectionParser.d.ts +2 -1
  68. package/dist/docx/sectionParser.js +21 -65
  69. package/dist/docx/serializer/borderSerializer.d.ts +1 -2
  70. package/dist/docx/serializer/commentSerializer.js +22 -9
  71. package/dist/docx/serializer/documentSerializer.d.ts +1 -5
  72. package/dist/docx/serializer/documentSerializer.js +6 -16
  73. package/dist/docx/serializer/headerFooterSerializer.js +5 -0
  74. package/dist/docx/serializer/markupRangeAttributes.d.ts +8 -0
  75. package/dist/docx/serializer/markupRangeAttributes.js +24 -0
  76. package/dist/docx/serializer/noteSerializer.js +5 -0
  77. package/dist/docx/serializer/paragraphSerializer.d.ts +1 -5
  78. package/dist/docx/serializer/paragraphSerializer.js +29 -35
  79. package/dist/docx/serializer/runSerializer.js +13 -7
  80. package/dist/docx/serializer/tableSerializer.js +28 -13
  81. package/dist/docx/serializer/textFormattingSerializer.d.ts +2 -3
  82. package/dist/docx/server/build.js +8 -1
  83. package/dist/docx/server/createBilingualDocument.js +10 -18
  84. package/dist/docx/server/extractDocxText.js +3 -4
  85. package/dist/docx/shadingParser.d.ts +6 -0
  86. package/dist/docx/shadingParser.js +32 -0
  87. package/dist/docx/shapeParser.js +3 -3
  88. package/dist/docx/styleParser.js +13 -87
  89. package/dist/docx/styleReferenceResolution.d.ts +36 -0
  90. package/dist/docx/styleReferenceResolution.js +51 -0
  91. package/dist/docx/tableLook.d.ts +57 -0
  92. package/dist/docx/tableLook.js +63 -0
  93. package/dist/docx/tableParser.d.ts +7 -9
  94. package/dist/docx/tableParser.js +64 -110
  95. package/dist/docx/textBoxParser.js +4 -4
  96. package/dist/docx/trackedMoveRangeNormalization.d.ts +3 -1
  97. package/dist/docx/trackedMoveRangeNormalization.js +11 -21
  98. package/dist/docx/transitionalSpelling.d.ts +13 -2
  99. package/dist/docx/transitionalSpelling.js +23 -1
  100. package/dist/docx/verbatimCapture.js +4 -11
  101. package/dist/docx/vmlImageParser.js +2 -2
  102. package/dist/docx/watermarkParser.js +2 -2
  103. package/dist/docx/xmlParser.d.ts +22 -32
  104. package/dist/docx/xmlParser.js +36 -21
  105. package/dist/internal/pageBreakRunSourceDescendantIndex.js +2 -1
  106. package/dist/internal/paragraphFormattingSerialization.d.ts +2 -3
  107. package/dist/internal/paragraphFormattingSerialization.js +26 -6
  108. package/dist/layout-bridge/convert/footnoteLayout.js +2 -7
  109. package/dist/layout-engine/index.d.ts +2 -2
  110. package/dist/layout-engine/index.js +2 -2
  111. package/dist/layout-engine/measure/measureBlocks.js +1 -6
  112. package/dist/layout-engine/types.d.ts +8 -2
  113. package/dist/layout-engine/types.js +35 -2
  114. package/dist/markdown/index.js +1 -1
  115. package/dist/markdown/internals.d.ts +6 -1
  116. package/dist/markdown/internals.js +14 -1
  117. package/dist/markdown/renderBlock.js +35 -21
  118. package/dist/markdown/renderParagraph.js +14 -5
  119. package/dist/markdown/renderRuns.js +4 -3
  120. package/dist/markdown/renderTable.js +4 -3
  121. package/dist/markdown/trailers.js +41 -7
  122. package/dist/markdown/types.d.ts +3 -7
  123. package/dist/prosemirror/attrs/index.js +2 -5
  124. package/dist/prosemirror/bookmarkBoundaryAttrs.d.ts +11 -1
  125. package/dist/prosemirror/bookmarkBoundaryAttrs.js +18 -3
  126. package/dist/prosemirror/commands/index.d.ts +3 -3
  127. package/dist/prosemirror/commands/index.js +2 -2
  128. package/dist/prosemirror/commands/paragraph.d.ts +3 -3
  129. package/dist/prosemirror/commands/paragraph.js +2 -2
  130. package/dist/prosemirror/commentIdAllocator.js +2 -7
  131. package/dist/prosemirror/conversion/fromProseDoc.js +129 -40
  132. package/dist/prosemirror/conversion/toProseDoc.d.ts +1 -14
  133. package/dist/prosemirror/conversion/toProseDoc.js +375 -316
  134. package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +14 -1
  135. package/dist/prosemirror/extensions/core/ParagraphExtension.js +11 -6
  136. package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +3 -3
  137. package/dist/prosemirror/extensions/features/PasteCleanupExtension.d.ts +4 -1
  138. package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +6 -2
  139. package/dist/prosemirror/extensions/features/pastedHeadingStyles.d.ts +7 -0
  140. package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +74 -0
  141. package/dist/prosemirror/extensions/marks/markUtils.d.ts +11 -3
  142. package/dist/prosemirror/extensions/marks/markUtils.js +98 -19
  143. package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +7 -3
  144. package/dist/prosemirror/extensions/nodes/ImageExtension.js +2 -1
  145. package/dist/prosemirror/extensions/nodes/ShapeExtension.js +1 -0
  146. package/dist/prosemirror/extensions/nodes/TableExtension.js +15 -1
  147. package/dist/prosemirror/extensions/types.d.ts +2 -2
  148. package/dist/prosemirror/index.d.ts +3 -3
  149. package/dist/prosemirror/index.js +3 -3
  150. package/dist/prosemirror/insertOperations.d.ts +9 -2
  151. package/dist/prosemirror/insertOperations.js +9 -4
  152. package/dist/prosemirror/paragraphFormattingProvenance.d.ts +159 -0
  153. package/dist/prosemirror/paragraphFormattingProvenance.js +106 -0
  154. package/dist/prosemirror/plugins/documentStyles.d.ts +9 -1
  155. package/dist/prosemirror/plugins/documentStyles.js +11 -1
  156. package/dist/prosemirror/plugins/index.d.ts +2 -2
  157. package/dist/prosemirror/plugins/index.js +2 -2
  158. package/dist/prosemirror/plugins/revisionIds.d.ts +11 -2
  159. package/dist/prosemirror/plugins/revisionIds.js +21 -6
  160. package/dist/prosemirror/runFormattingReconciliation.js +3 -2
  161. package/dist/prosemirror/runStyleFormatting.d.ts +1 -1
  162. package/dist/prosemirror/schema/nodes.d.ts +31 -0
  163. package/dist/prosemirror/styles/resolvedStyleAttrs.js +2 -0
  164. package/dist/prosemirror/styles/styleResolver.d.ts +9 -0
  165. package/dist/prosemirror/styles/styleResolver.js +12 -0
  166. package/dist/style-engine/styleEngine.d.ts +3 -0
  167. package/dist/style-engine/styleEngine.js +3 -0
  168. package/dist/style-sets/extract.js +1 -23
  169. package/dist/style-sets/stellaStyle.js +46 -39
  170. package/dist/style-sets/styleSetNormalization.d.ts +19 -0
  171. package/dist/style-sets/styleSetNormalization.js +99 -0
  172. package/dist/types/content.d.ts +2 -2
  173. package/dist/utils/createDocument.js +145 -20
  174. package/dist/utils/headingCollector.d.ts +8 -5
  175. package/dist/utils/headingCollector.js +23 -25
  176. package/dist/utils/tableOfContentsStyle.js +9 -2
  177. package/package.json +2 -2
  178. package/dist/docx/textWhitespace.d.ts +0 -4
  179. package/dist/docx/textWhitespace.js +0 -4
  180. package/dist/layout-bridge/engine/tableWidthUtils.d.ts +0 -6
  181. package/dist/layout-bridge/engine/tableWidthUtils.js +0 -25
  182. package/dist/markdown/headings.d.ts +0 -13
  183. package/dist/markdown/headings.js +0 -20
@@ -0,0 +1,159 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ import { ParagraphAttrs } from "./schema/nodes.js";
3
+ //#region src/prosemirror/paragraphFormattingProvenance.d.ts
4
+ /**
5
+ * How each `w:pPr` field reaches the saved model from paragraph attrs.
6
+ *
7
+ * - `style-resolved-attr`: the named attr holds the effective value, so the
8
+ * write-back filters it against `ParagraphAttrs._resolvedFormatting`.
9
+ * - `direct-provenance`: the field has its own provenance channel and reader
10
+ * (`alignmentFromStyle`, `spacingFromDocDefaults`, `numPrFromStyle`, …).
11
+ * - `derived`: not authored; recomputed from another field on load and save.
12
+ * - `original-only`: no editor attr writes it back; it survives through
13
+ * `ParagraphAttrs._originalFormatting`.
14
+ */
15
+ type ParagraphFieldWriteBack = {
16
+ kind: "style-resolved-attr";
17
+ attr: keyof ParagraphAttrs;
18
+ } | {
19
+ kind: "direct-provenance";
20
+ } | {
21
+ kind: "derived";
22
+ } | {
23
+ kind: "original-only";
24
+ };
25
+ /**
26
+ * Total over `ParagraphFormatting`, so a new `w:pPr` field cannot land without
27
+ * a decision about how a save tells its authored value from its inherited one.
28
+ */
29
+ declare const PARAGRAPH_FORMATTING_WRITE_BACK: {
30
+ readonly alignment: {
31
+ readonly kind: "direct-provenance";
32
+ };
33
+ readonly bidi: {
34
+ readonly kind: "style-resolved-attr";
35
+ readonly attr: "direction";
36
+ };
37
+ readonly kinsoku: {
38
+ readonly kind: "style-resolved-attr";
39
+ readonly attr: "kinsoku";
40
+ };
41
+ readonly overflowPunctuation: {
42
+ readonly kind: "style-resolved-attr";
43
+ readonly attr: "overflowPunctuation";
44
+ };
45
+ readonly spaceBefore: {
46
+ readonly kind: "direct-provenance";
47
+ };
48
+ readonly spaceAfter: {
49
+ readonly kind: "direct-provenance";
50
+ };
51
+ readonly lineSpacing: {
52
+ readonly kind: "direct-provenance";
53
+ };
54
+ readonly lineSpacingRule: {
55
+ readonly kind: "direct-provenance";
56
+ };
57
+ readonly snapToGrid: {
58
+ readonly kind: "style-resolved-attr";
59
+ readonly attr: "snapToGrid";
60
+ };
61
+ readonly beforeAutospacing: {
62
+ readonly kind: "direct-provenance";
63
+ };
64
+ readonly afterAutospacing: {
65
+ readonly kind: "direct-provenance";
66
+ };
67
+ readonly spacingExplicit: {
68
+ readonly kind: "derived";
69
+ };
70
+ readonly indentLeft: {
71
+ readonly kind: "style-resolved-attr";
72
+ readonly attr: "indentLeft";
73
+ };
74
+ readonly indentRight: {
75
+ readonly kind: "style-resolved-attr";
76
+ readonly attr: "indentRight";
77
+ };
78
+ readonly indentFirstLine: {
79
+ readonly kind: "style-resolved-attr";
80
+ readonly attr: "indentFirstLine";
81
+ };
82
+ readonly hangingIndent: {
83
+ readonly kind: "direct-provenance";
84
+ };
85
+ readonly borders: {
86
+ readonly kind: "style-resolved-attr";
87
+ readonly attr: "borders";
88
+ };
89
+ readonly shading: {
90
+ readonly kind: "style-resolved-attr";
91
+ readonly attr: "shading";
92
+ };
93
+ readonly tabs: {
94
+ readonly kind: "style-resolved-attr";
95
+ readonly attr: "tabs";
96
+ };
97
+ readonly keepNext: {
98
+ readonly kind: "original-only";
99
+ };
100
+ readonly keepLines: {
101
+ readonly kind: "original-only";
102
+ };
103
+ readonly widowControl: {
104
+ readonly kind: "style-resolved-attr";
105
+ readonly attr: "widowControl";
106
+ };
107
+ readonly pageBreakBefore: {
108
+ readonly kind: "style-resolved-attr";
109
+ readonly attr: "pageBreakBefore";
110
+ };
111
+ readonly contextualSpacing: {
112
+ readonly kind: "style-resolved-attr";
113
+ readonly attr: "contextualSpacing";
114
+ };
115
+ readonly numPr: {
116
+ readonly kind: "direct-provenance";
117
+ };
118
+ readonly numPrFromStyle: {
119
+ readonly kind: "derived";
120
+ };
121
+ readonly numberingChangeXml: {
122
+ readonly kind: "original-only";
123
+ };
124
+ readonly outlineLevel: {
125
+ readonly kind: "style-resolved-attr";
126
+ readonly attr: "outlineLevel";
127
+ };
128
+ readonly styleId: {
129
+ readonly kind: "direct-provenance";
130
+ };
131
+ readonly frame: {
132
+ readonly kind: "original-only";
133
+ };
134
+ readonly suppressLineNumbers: {
135
+ readonly kind: "original-only";
136
+ };
137
+ readonly suppressAutoHyphens: {
138
+ readonly kind: "style-resolved-attr";
139
+ readonly attr: "suppressAutoHyphens";
140
+ };
141
+ readonly runProperties: {
142
+ readonly kind: "original-only";
143
+ };
144
+ readonly runInWithNext: {
145
+ readonly kind: "original-only";
146
+ };
147
+ };
148
+ type StyleResolvedParagraphField = { [Field in keyof typeof PARAGRAPH_FORMATTING_WRITE_BACK]: (typeof PARAGRAPH_FORMATTING_WRITE_BACK)[Field] extends {
149
+ kind: "style-resolved-attr";
150
+ } ? Field : never; }[keyof typeof PARAGRAPH_FORMATTING_WRITE_BACK];
151
+ declare const STYLE_RESOLVED_PARAGRAPH_FIELDS: StyleResolvedParagraphField[];
152
+ /**
153
+ * The part of a resolved style cascade a save needs to keep out of direct
154
+ * `w:pPr`. Narrowed to the governed fields so an ordinary paragraph, whose
155
+ * cascade supplies only spacing, stores nothing at all.
156
+ */
157
+ declare const styleResolvedParagraphFormatting: (resolved: document_d_exports.ParagraphFormatting | undefined) => document_d_exports.ParagraphFormatting | undefined;
158
+ //#endregion
159
+ export { PARAGRAPH_FORMATTING_WRITE_BACK, ParagraphFieldWriteBack, STYLE_RESOLVED_PARAGRAPH_FIELDS, StyleResolvedParagraphField, styleResolvedParagraphFormatting };
@@ -0,0 +1,106 @@
1
+ //#region src/prosemirror/paragraphFormattingProvenance.ts
2
+ /**
3
+ * Total over `ParagraphFormatting`, so a new `w:pPr` field cannot land without
4
+ * a decision about how a save tells its authored value from its inherited one.
5
+ */
6
+ const PARAGRAPH_FORMATTING_WRITE_BACK = {
7
+ alignment: { kind: "direct-provenance" },
8
+ bidi: {
9
+ kind: "style-resolved-attr",
10
+ attr: "direction"
11
+ },
12
+ kinsoku: {
13
+ kind: "style-resolved-attr",
14
+ attr: "kinsoku"
15
+ },
16
+ overflowPunctuation: {
17
+ kind: "style-resolved-attr",
18
+ attr: "overflowPunctuation"
19
+ },
20
+ spaceBefore: { kind: "direct-provenance" },
21
+ spaceAfter: { kind: "direct-provenance" },
22
+ lineSpacing: { kind: "direct-provenance" },
23
+ lineSpacingRule: { kind: "direct-provenance" },
24
+ snapToGrid: {
25
+ kind: "style-resolved-attr",
26
+ attr: "snapToGrid"
27
+ },
28
+ beforeAutospacing: { kind: "direct-provenance" },
29
+ afterAutospacing: { kind: "direct-provenance" },
30
+ spacingExplicit: { kind: "derived" },
31
+ indentLeft: {
32
+ kind: "style-resolved-attr",
33
+ attr: "indentLeft"
34
+ },
35
+ indentRight: {
36
+ kind: "style-resolved-attr",
37
+ attr: "indentRight"
38
+ },
39
+ indentFirstLine: {
40
+ kind: "style-resolved-attr",
41
+ attr: "indentFirstLine"
42
+ },
43
+ hangingIndent: { kind: "direct-provenance" },
44
+ borders: {
45
+ kind: "style-resolved-attr",
46
+ attr: "borders"
47
+ },
48
+ shading: {
49
+ kind: "style-resolved-attr",
50
+ attr: "shading"
51
+ },
52
+ tabs: {
53
+ kind: "style-resolved-attr",
54
+ attr: "tabs"
55
+ },
56
+ keepNext: { kind: "original-only" },
57
+ keepLines: { kind: "original-only" },
58
+ widowControl: {
59
+ kind: "style-resolved-attr",
60
+ attr: "widowControl"
61
+ },
62
+ pageBreakBefore: {
63
+ kind: "style-resolved-attr",
64
+ attr: "pageBreakBefore"
65
+ },
66
+ contextualSpacing: {
67
+ kind: "style-resolved-attr",
68
+ attr: "contextualSpacing"
69
+ },
70
+ numPr: { kind: "direct-provenance" },
71
+ numPrFromStyle: { kind: "derived" },
72
+ numberingChangeXml: { kind: "original-only" },
73
+ outlineLevel: {
74
+ kind: "style-resolved-attr",
75
+ attr: "outlineLevel"
76
+ },
77
+ styleId: { kind: "direct-provenance" },
78
+ frame: { kind: "original-only" },
79
+ suppressLineNumbers: { kind: "original-only" },
80
+ suppressAutoHyphens: {
81
+ kind: "style-resolved-attr",
82
+ attr: "suppressAutoHyphens"
83
+ },
84
+ runProperties: { kind: "original-only" },
85
+ runInWithNext: { kind: "original-only" }
86
+ };
87
+ const STYLE_RESOLVED_PARAGRAPH_FIELDS = Object.keys(PARAGRAPH_FORMATTING_WRITE_BACK).filter((field) => PARAGRAPH_FORMATTING_WRITE_BACK[field].kind === "style-resolved-attr");
88
+ /**
89
+ * The part of a resolved style cascade a save needs to keep out of direct
90
+ * `w:pPr`. Narrowed to the governed fields so an ordinary paragraph, whose
91
+ * cascade supplies only spacing, stores nothing at all.
92
+ */
93
+ const styleResolvedParagraphFormatting = (resolved) => {
94
+ if (!resolved) return;
95
+ const governed = {};
96
+ let found = false;
97
+ for (const field of STYLE_RESOLVED_PARAGRAPH_FIELDS) {
98
+ const value = resolved[field];
99
+ if (value === void 0) continue;
100
+ Reflect.set(governed, field, value);
101
+ found = true;
102
+ }
103
+ return found ? governed : void 0;
104
+ };
105
+ //#endregion
106
+ export { PARAGRAPH_FORMATTING_WRITE_BACK, STYLE_RESOLVED_PARAGRAPH_FIELDS, styleResolvedParagraphFormatting };
@@ -1,4 +1,5 @@
1
1
  import { document_d_exports } from "../../types/document.js";
2
+ import { BuiltInStyleIndex } from "../../docx/builtInStyles.js";
2
3
  import { StyleResolver } from "../styles/styleResolver.js";
3
4
  import { EditorState, Plugin, PluginKey } from "prosemirror-state";
4
5
  //#region src/prosemirror/plugins/documentStyles.d.ts
@@ -13,7 +14,14 @@ declare const documentStylesKey: PluginKey<StyleResolver | null>;
13
14
  declare function createDocumentStylesPlugin(styles: document_d_exports.StyleDefinitions | StyleResolver | null | undefined): Plugin;
14
15
  /** Read the document's StyleResolver, or null when the plugin isn't installed. */
15
16
  declare function getDocumentStyleResolver(state: EditorState): StyleResolver | null;
17
+ /**
18
+ * Read the document's built-in style index, for the callers that classify
19
+ * paragraphs (heading collection, markdown export, the AI snapshot). Without
20
+ * the plugin every lookup misses, which degrades classification to the
21
+ * paragraph's own outline level rather than to English style ids.
22
+ */
23
+ declare function getDocumentBuiltInStyles(state: EditorState): BuiltInStyleIndex;
16
24
  /** Reconfigure so ProseMirror replaces the keyed plugin's resolver state. */
17
25
  declare const withDocumentStyles: (state: EditorState, styles: document_d_exports.StyleDefinitions | StyleResolver | null | undefined) => EditorState;
18
26
  //#endregion
19
- export { createDocumentStylesPlugin, documentStylesKey, getDocumentStyleResolver, withDocumentStyles };
27
+ export { createDocumentStylesPlugin, documentStylesKey, getDocumentBuiltInStyles, getDocumentStyleResolver, withDocumentStyles };
@@ -1,3 +1,4 @@
1
+ import { EMPTY_BUILT_IN_STYLE_INDEX } from "../../docx/builtInStyles.js";
1
2
  import { StyleResolver, createStyleResolver } from "../styles/styleResolver.js";
2
3
  import { Plugin, PluginKey } from "prosemirror-state";
3
4
  //#region src/prosemirror/plugins/documentStyles.ts
@@ -42,6 +43,15 @@ function createDocumentStylesPlugin(styles) {
42
43
  function getDocumentStyleResolver(state) {
43
44
  return documentStylesKey.getState(state) ?? null;
44
45
  }
46
+ /**
47
+ * Read the document's built-in style index, for the callers that classify
48
+ * paragraphs (heading collection, markdown export, the AI snapshot). Without
49
+ * the plugin every lookup misses, which degrades classification to the
50
+ * paragraph's own outline level rather than to English style ids.
51
+ */
52
+ function getDocumentBuiltInStyles(state) {
53
+ return getDocumentStyleResolver(state)?.builtInStyles ?? EMPTY_BUILT_IN_STYLE_INDEX;
54
+ }
45
55
  /** Reconfigure so ProseMirror replaces the keyed plugin's resolver state. */
46
56
  const withDocumentStyles = (state, styles) => {
47
57
  const previous = documentStylesKey.get(state);
@@ -49,4 +59,4 @@ const withDocumentStyles = (state, styles) => {
49
59
  return state.reconfigure({ plugins: retained }).reconfigure({ plugins: [...retained, createDocumentStylesPlugin(styles)] });
50
60
  };
51
61
  //#endregion
52
- export { createDocumentStylesPlugin, documentStylesKey, getDocumentStyleResolver, withDocumentStyles };
62
+ export { createDocumentStylesPlugin, documentStylesKey, getDocumentBuiltInStyles, getDocumentStyleResolver, withDocumentStyles };
@@ -1,3 +1,3 @@
1
1
  import { SelectionChangeCallback, SelectionContext, createSelectionTrackerPlugin, extractSelectionContext, getSelectionContext, selectionTrackerKey } from "./selectionTracker.js";
2
- import { createDocumentStylesPlugin, documentStylesKey, getDocumentStyleResolver } from "./documentStyles.js";
3
- export { type SelectionChangeCallback, type SelectionContext, createDocumentStylesPlugin, createSelectionTrackerPlugin, documentStylesKey, extractSelectionContext, getDocumentStyleResolver, getSelectionContext, selectionTrackerKey };
2
+ import { createDocumentStylesPlugin, documentStylesKey, getDocumentBuiltInStyles, getDocumentStyleResolver } from "./documentStyles.js";
3
+ export { type SelectionChangeCallback, type SelectionContext, createDocumentStylesPlugin, createSelectionTrackerPlugin, documentStylesKey, extractSelectionContext, getDocumentBuiltInStyles, getDocumentStyleResolver, getSelectionContext, selectionTrackerKey };
@@ -1,3 +1,3 @@
1
- import { createDocumentStylesPlugin, documentStylesKey, getDocumentStyleResolver } from "./documentStyles.js";
1
+ import { createDocumentStylesPlugin, documentStylesKey, getDocumentBuiltInStyles, getDocumentStyleResolver } from "./documentStyles.js";
2
2
  import { createSelectionTrackerPlugin, extractSelectionContext, getSelectionContext, selectionTrackerKey } from "./selectionTracker.js";
3
- export { createDocumentStylesPlugin, createSelectionTrackerPlugin, documentStylesKey, extractSelectionContext, getDocumentStyleResolver, getSelectionContext, selectionTrackerKey };
3
+ export { createDocumentStylesPlugin, createSelectionTrackerPlugin, documentStylesKey, extractSelectionContext, getDocumentBuiltInStyles, getDocumentStyleResolver, getSelectionContext, selectionTrackerKey };
@@ -14,9 +14,18 @@ declare function mintRevisionId(): number;
14
14
  */
15
15
  declare function seedRevisionIdsAbove(maxId: number): void;
16
16
  /**
17
- * Raise the counter above every revision id already present in `doc`.
17
+ * The highest id in `doc` from any part of the annotation space.
18
+ *
19
+ * A revision, a comment and a bookmark draw their `w:id` from one space, so a
20
+ * counter seeded above its own kind alone still mints over another kind's id.
21
+ * Both allocators seed from this, and the save-time normalization avoids the
22
+ * same space, so the three agree on what is taken.
23
+ */
24
+ declare function maxAnnotationIdInDoc(doc: Node): number;
25
+ /**
26
+ * Raise the counter above every annotation id already present in `doc`.
18
27
  * Called from the suggestion-mode plugin's `state.init`.
19
28
  */
20
29
  declare function seedRevisionIdsFromDoc(doc: Node): void;
21
30
  //#endregion
22
- export { mintRevisionId, seedRevisionIdsAbove, seedRevisionIdsFromDoc };
31
+ export { maxAnnotationIdInDoc, mintRevisionId, seedRevisionIdsAbove, seedRevisionIdsFromDoc };
@@ -31,16 +31,24 @@ function seedRevisionIdsAbove(maxId) {
31
31
  /** Node attrs that carry a revision id directly (`revisionId` field). */
32
32
  const DIRECT_REVISION_ATTR_KEYS = ["trIns", "trDel"];
33
33
  /**
34
- * Raise the counter above every revision id already present in `doc`.
35
- * Called from the suggestion-mode plugin's `state.init`.
34
+ * The highest id in `doc` from any part of the annotation space.
35
+ *
36
+ * A revision, a comment and a bookmark draw their `w:id` from one space, so a
37
+ * counter seeded above its own kind alone still mints over another kind's id.
38
+ * Both allocators seed from this, and the save-time normalization avoids the
39
+ * same space, so the three agree on what is taken.
36
40
  */
37
- function seedRevisionIdsFromDoc(doc) {
41
+ function maxAnnotationIdInDoc(doc) {
38
42
  let max = 0;
39
43
  const consider = (id) => {
40
44
  if (typeof id === "number" && Number.isInteger(id) && id > max && id <= MAX_REVISION_ID) max = id;
41
45
  };
42
46
  doc.descendants((node) => {
43
- for (const mark of node.marks) consider(mark.attrs["revisionId"]);
47
+ for (const mark of node.marks) {
48
+ consider(mark.attrs["revisionId"]);
49
+ consider(mark.attrs["commentId"]);
50
+ }
51
+ if (node.type.name === "bookmarkBoundary") consider(node.attrs["id"]);
44
52
  const attrs = node.attrs;
45
53
  const pPrMark = attrs["pPrMark"];
46
54
  if (pPrMark?.info) consider(pPrMark.info.id);
@@ -51,7 +59,14 @@ function seedRevisionIdsFromDoc(doc) {
51
59
  const cellMarker = attrs["cellMarker"];
52
60
  if (cellMarker?.info) consider(cellMarker.info.revisionId);
53
61
  });
54
- seedRevisionIdsAbove(max);
62
+ return max;
63
+ }
64
+ /**
65
+ * Raise the counter above every annotation id already present in `doc`.
66
+ * Called from the suggestion-mode plugin's `state.init`.
67
+ */
68
+ function seedRevisionIdsFromDoc(doc) {
69
+ seedRevisionIdsAbove(maxAnnotationIdInDoc(doc));
55
70
  }
56
71
  //#endregion
57
- export { mintRevisionId, seedRevisionIdsAbove, seedRevisionIdsFromDoc };
72
+ export { maxAnnotationIdInDoc, mintRevisionId, seedRevisionIdsAbove, seedRevisionIdsFromDoc };
@@ -1,9 +1,10 @@
1
1
  import { mergeTextFormatting } from "../utils/textFormattingMerge.js";
2
2
  import { expectCharacterStyleMarkAttrs } from "./attrs/index.js";
3
3
  import { marksToTextFormatting } from "./conversion/fromProseDoc.js";
4
- import { textFormattingToMarks } from "./conversion/toProseDoc.js";
4
+ import { textFormattingToMarks } from "./extensions/marks/markUtils.js";
5
5
  import { RUN_FORMATTING_MARK_NAMES } from "./runFormattingMarkNames.js";
6
6
  import { getParagraphMarkSuppressionOverrides, hasDirectRunFormatting, paragraphFormattingForRun, resolveEffectiveRunStyleFormatting } from "./runStyleFormatting.js";
7
+ import { schema } from "./schema/index.js";
7
8
  import { Mark } from "prosemirror-model";
8
9
  //#region src/prosemirror/runFormattingReconciliation.ts
9
10
  /** Read authored run properties without confusing inherited visuals for direct formatting. */
@@ -36,7 +37,7 @@ const reconcileRunFormattingMarks = ({ authoredFormatting, context, node, styleR
36
37
  marks: styleResolutionMarks,
37
38
  paragraphFormatting,
38
39
  ...styleResolver !== void 0 ? { styleResolver } : {}
39
- }), authoredFormatting), {
40
+ }), authoredFormatting), schema, {
40
41
  overrideFormatting: mergeTextFormatting(getParagraphMarkSuppressionOverrides({
41
42
  directFormatting: authoredFormatting,
42
43
  paragraphMarkFormatting: context.paragraphMarkFormatting,
@@ -26,7 +26,7 @@ type ParagraphRunStyleContext = {
26
26
  paragraphMarkFormatting: document_d_exports.TextFormatting | undefined;
27
27
  paragraphMarkPrecedesStyle: boolean;
28
28
  };
29
- type RunStyleResolver = Pick<StyleEngine, "getDefaultCharacterStyle" | "getDefaultParagraphStyle" | "getDocDefaults" | "getRunStyleOwnProperties" | "getStyle" | "resolveParagraphStyle">;
29
+ type RunStyleResolver = Pick<StyleEngine, "builtInStyles" | "getDefaultCharacterStyle" | "getDefaultParagraphStyle" | "getDocDefaults" | "getRunStyleOwnProperties" | "getStyle" | "resolveParagraphStyle">;
30
30
  type ResolveParagraphBodyRunFormattingOptions = {
31
31
  styleId: string | undefined;
32
32
  styleResolver?: RunStyleResolver | null | undefined;
@@ -27,9 +27,11 @@ type BookmarkBoundaryAttrs = {
27
27
  name: string;
28
28
  colFirst?: number;
29
29
  colLast?: number;
30
+ displacedByCustomXml?: document_d_exports.DisplacedByCustomXml;
30
31
  } | {
31
32
  type: "end";
32
33
  id: number;
34
+ displacedByCustomXml?: document_d_exports.DisplacedByCustomXml;
33
35
  };
34
36
  /**
35
37
  * Paragraph node attributes - maps to ParagraphFormatting
@@ -189,6 +191,19 @@ type ParagraphAttrs = {
189
191
  /** Original inline paragraph formatting from DOCX (pre-style-resolution).
190
192
  * Used by fromProseDoc for lossless round-trip serialization. */
191
193
  _originalFormatting?: document_d_exports.ParagraphFormatting;
194
+ /**
195
+ * The `w:pPr` the style cascade resolves to for this paragraph: document
196
+ * defaults, the enclosing table style, then the `w:pStyle` chain. PM-only;
197
+ * never serialized.
198
+ *
199
+ * The formatting attrs above hold the EFFECTIVE value, because that is what
200
+ * the editor renders with. A save must write only what the paragraph states
201
+ * itself, so it needs this companion to tell an inherited value from an
202
+ * authored one — writing an inherited value back as direct `w:pPr` outranks
203
+ * the style it came from, and a later edit to that style stops reaching the
204
+ * paragraph. `TableCellAttrs._resolvedBorders` is the same device.
205
+ */
206
+ _resolvedFormatting?: document_d_exports.ParagraphFormatting;
192
207
  /** Import-effective spacing baseline for HTML auto-spacing detection.
193
208
  * PM-only; never serialized back into DOCX formatting. */
194
209
  _autospacingBase?: {
@@ -334,6 +349,14 @@ type ImageAttrs = {
334
349
  _docxRawImageFingerprint?: string;
335
350
  /** Embedded-object previews use their authored box as the exact line height. */
336
351
  _docxObjectPreview?: boolean;
352
+ /**
353
+ * The `w:rPr` of the run this atom came from. Inline atoms do not carry the
354
+ * run's formatting marks (see `withRunBoundaryMarks`), so without this the
355
+ * run properties of an embedded object, picture or shape are lost on save
356
+ * (`content[].content[].formatting: object became absent` in the corpus
357
+ * census).
358
+ */
359
+ _docxRunFormatting?: document_d_exports.TextFormatting;
337
360
  };
338
361
  /**
339
362
  * Field node attributes
@@ -507,6 +530,14 @@ type ShapeAttrs = {
507
530
  glowColor?: string;
508
531
  /** Glow radius in pixels */
509
532
  glowRadius?: number;
533
+ /**
534
+ * The `w:rPr` of the run this atom came from. Inline atoms do not carry the
535
+ * run's formatting marks (see `withRunBoundaryMarks`), so without this the
536
+ * run properties of an embedded object, picture or shape are lost on save
537
+ * (`content[].content[].formatting: object became absent` in the corpus
538
+ * census).
539
+ */
540
+ _docxRunFormatting?: document_d_exports.TextFormatting;
510
541
  };
511
542
  /**
512
543
  * Text box node attributes
@@ -4,6 +4,7 @@ import { tableOfContentsStyleLevel } from "../../utils/tableOfContentsStyle.js";
4
4
  import { setAutospacingBaseValue } from "../autospacingBase.js";
5
5
  import { CLEARED_LIST_RENDERING_ATTRS } from "../listMarker.js";
6
6
  import { listRenderingAttrPatch } from "../listRenderingAttrs.js";
7
+ import { styleResolvedParagraphFormatting } from "../paragraphFormattingProvenance.js";
7
8
  //#region src/prosemirror/styles/resolvedStyleAttrs.ts
8
9
  /**
9
10
  * Shared helper for projecting a resolved paragraph style onto ProseMirror
@@ -45,6 +46,7 @@ function paragraphAttrsFromResolvedStyle(resolved, identity) {
45
46
  outlineLevel: ppr?.outlineLevel ?? null,
46
47
  borders: ppr?.borders ?? null,
47
48
  defaultTextFormatting: hasRunFormatting ? runFormatting : null,
49
+ _resolvedFormatting: styleResolvedParagraphFormatting(ppr),
48
50
  _autospacingBase: autospacingBaseFromResolvedParagraphFormatting(ppr),
49
51
  _tableOfContentsLevel: tableOfContentsStyleLevel(identity) ?? null
50
52
  };
@@ -1,4 +1,5 @@
1
1
  import { document_d_exports } from "../../types/document.js";
2
+ import { BuiltInStyleIndex } from "../../docx/builtInStyles.js";
2
3
  //#region src/prosemirror/styles/styleResolver.d.ts
3
4
  /**
4
5
  * Resolved style properties ready for rendering
@@ -27,6 +28,7 @@ type TableCellParagraphSpacingOverlay = Pick<document_d_exports.ParagraphFormatt
27
28
  */
28
29
  declare class StyleResolver {
29
30
  private readonly stylesById;
31
+ private builtInStyleIndex;
30
32
  private readonly docDefaults;
31
33
  private readonly defaultParagraphStyle;
32
34
  private readonly defaultCharacterStyle;
@@ -36,6 +38,13 @@ declare class StyleResolver {
36
38
  * Get a style by ID
37
39
  */
38
40
  getStyle(styleId: string): document_d_exports.Style | undefined;
41
+ /**
42
+ * This document's styles indexed by the built-in they are, so a consumer can
43
+ * ask whether a paragraph is a heading without matching an English style id.
44
+ * Built on first use and kept: the resolver outlives a single query, and the
45
+ * outline sidebar rebuilds its heading list on every transaction.
46
+ */
47
+ get builtInStyles(): BuiltInStyleIndex;
39
48
  /**
40
49
  * Get all available paragraph styles (for toolbar dropdown)
41
50
  */
@@ -1,3 +1,4 @@
1
+ import { createBuiltInStyleIndex } from "../../docx/builtInStyles.js";
1
2
  import { BUILT_IN_DEFAULT_PARAGRAPH_FORMATTING, resolveDefaultParagraphStyle } from "../../docx/defaultParagraphStyle.js";
2
3
  import { mergeParagraphFormatting } from "../../utils/paragraphFormattingMerge.js";
3
4
  import { cascadeStyleTextFormatting } from "./styleToggleCascade.js";
@@ -27,6 +28,7 @@ const BUILTIN_NORMAL_STYLE = {
27
28
  */
28
29
  var StyleResolver = class {
29
30
  stylesById;
31
+ builtInStyleIndex;
30
32
  docDefaults;
31
33
  defaultParagraphStyle;
32
34
  defaultCharacterStyle;
@@ -48,6 +50,16 @@ var StyleResolver = class {
48
50
  return this.stylesById.get(styleId);
49
51
  }
50
52
  /**
53
+ * This document's styles indexed by the built-in they are, so a consumer can
54
+ * ask whether a paragraph is a heading without matching an English style id.
55
+ * Built on first use and kept: the resolver outlives a single query, and the
56
+ * outline sidebar rebuilds its heading list on every transaction.
57
+ */
58
+ get builtInStyles() {
59
+ this.builtInStyleIndex ??= createBuiltInStyleIndex(this.stylesById.values(), this.docDefaults);
60
+ return this.builtInStyleIndex;
61
+ }
62
+ /**
51
63
  * Get all available paragraph styles (for toolbar dropdown)
52
64
  */
53
65
  getParagraphStyles() {
@@ -1,4 +1,5 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
+ import { BuiltInStyleIndex } from "../docx/builtInStyles.js";
2
3
  import { ResolvedParagraphStyle, TableCellParagraphSpacingOverlay } from "../prosemirror/styles/styleResolver.js";
3
4
  //#region src/style-engine/styleEngine.d.ts
4
5
  /** Engine construction options. */
@@ -44,6 +45,8 @@ type StyleEngine = {
44
45
  getParagraphStyles: () => document_d_exports.Style[];
45
46
  /** All visible table styles, sorted for the table-style gallery. */
46
47
  getTableStyles: () => document_d_exports.Style[];
48
+ /** The document's styles indexed by the built-in they are — see {@link StyleResolver.builtInStyles}. */
49
+ builtInStyles: BuiltInStyleIndex;
47
50
  /**
48
51
  * Resolve the full paragraph cascade for a given styleId.
49
52
  * Returned object is cached and must not be mutated.
@@ -62,6 +62,9 @@ function createStyleEngine(styleDefinitions, options) {
62
62
  getDefaultTableStyle: () => resolver.getDefaultTableStyle(),
63
63
  getParagraphStyles: () => resolver.getParagraphStyles(),
64
64
  getTableStyles: () => resolver.getTableStyles(),
65
+ get builtInStyles() {
66
+ return resolver.builtInStyles;
67
+ },
65
68
  resolveParagraphStyle: (styleId) => memoize(paragraphCache, cacheKey(styleId), () => resolver.resolveParagraphStyle(styleId)),
66
69
  resolveParagraphStyleInTable: (styleId, tableParagraphOverlay) => tableParagraphOverlay === void 0 ? memoize(paragraphCache, cacheKey(styleId), () => resolver.resolveParagraphStyleInTable(styleId, void 0)) : memoizeInTable(styleId, tableParagraphOverlay),
67
70
  resolveRunStyle: (styleId) => memoize(runCache, cacheKey(styleId), () => resolver.resolveRunStyle(styleId)),
@@ -1,4 +1,4 @@
1
- import { BUILT_IN_DEFAULT_PARAGRAPH_FORMATTING, BUILT_IN_DEFAULT_PARAGRAPH_STYLE_ID, BUILT_IN_DEFAULT_PARAGRAPH_STYLE_NAME, resolveDefaultParagraphStyle } from "../docx/defaultParagraphStyle.js";
1
+ import { mintDefaultParagraphStyle, resolveDefaultParagraphStyle } from "../docx/defaultParagraphStyle.js";
2
2
  import { getCachedNumberingMap } from "../docx/numberingParser.js";
3
3
  import { isNumberingReference } from "../docx/numberingReference.js";
4
4
  import { normalizeStyleNumberingReferences } from "../docx/numberingReferenceNormalization.js";
@@ -83,28 +83,6 @@ const ensureInitialParagraphStyle = ({ styles, requested, hasDocDefaults }) => {
83
83
  styles.push(minted);
84
84
  return minted.styleId;
85
85
  };
86
- /**
87
- * The default paragraph style a set needs when its source declared none.
88
- *
89
- * The id only has to be free, because the set is what defines it. The
90
- * formatting has to be the built-in template's whenever the source had no
91
- * `w:docDefaults`, because that is what the source itself rendered as: a
92
- * consumer applies its built-in Normal only where no default paragraph style
93
- * exists, and this minted style is one. Where the source did declare
94
- * `w:docDefaults`, the set carries them and they remain authoritative, so the
95
- * minted style states nothing.
96
- */
97
- const mintDefaultParagraphStyle = ({ takenStyleIds, hasDocDefaults }) => {
98
- let styleId = BUILT_IN_DEFAULT_PARAGRAPH_STYLE_ID;
99
- for (let suffix = 1; takenStyleIds.has(styleId); suffix += 1) styleId = `${BUILT_IN_DEFAULT_PARAGRAPH_STYLE_ID}${suffix}`;
100
- return {
101
- styleId,
102
- type: "paragraph",
103
- name: BUILT_IN_DEFAULT_PARAGRAPH_STYLE_NAME,
104
- default: true,
105
- ...hasDocDefaults ? {} : { pPr: { ...BUILT_IN_DEFAULT_PARAGRAPH_FORMATTING } }
106
- };
107
- };
108
86
  const collectStyleDependencyClosure = (stylesById, requestedStyleIds) => {
109
87
  const selected = /* @__PURE__ */ new Set();
110
88
  const pending = [...requestedStyleIds];