@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
@@ -1,3 +1,4 @@
1
+ import { BUILT_IN_STYLE_NAME, builtInHeadingStyleName, builtInTableOfContentsStyleName } from "../docx/builtInStyles.js";
1
2
  import "./types.js";
2
3
  //#region src/style-sets/stellaStyle.ts
3
4
  const CLAUSE_NUMBERING_ID = 1;
@@ -43,7 +44,7 @@ const createStellaStyleSet = () => ({
43
44
  {
44
45
  styleId: "Normal",
45
46
  type: "paragraph",
46
- name: "Normal",
47
+ name: BUILT_IN_STYLE_NAME.normal,
47
48
  default: true,
48
49
  qFormat: true,
49
50
  uiPriority: 0,
@@ -64,7 +65,7 @@ const createStellaStyleSet = () => ({
64
65
  {
65
66
  styleId: "DefaultParagraphFont",
66
67
  type: "character",
67
- name: "Default Paragraph Font",
68
+ name: BUILT_IN_STYLE_NAME.defaultParagraphFont,
68
69
  default: true,
69
70
  semiHidden: true,
70
71
  unhideWhenUsed: true
@@ -72,7 +73,7 @@ const createStellaStyleSet = () => ({
72
73
  {
73
74
  styleId: "BodyText",
74
75
  type: "paragraph",
75
- name: "Body Text",
76
+ name: BUILT_IN_STYLE_NAME.bodyText,
76
77
  basedOn: "Normal",
77
78
  qFormat: true,
78
79
  uiPriority: 1
@@ -80,7 +81,7 @@ const createStellaStyleSet = () => ({
80
81
  {
81
82
  styleId: "Title",
82
83
  type: "paragraph",
83
- name: "Title",
84
+ name: BUILT_IN_STYLE_NAME.title,
84
85
  basedOn: "BodyText",
85
86
  next: "BodyText",
86
87
  qFormat: true,
@@ -109,7 +110,7 @@ const createStellaStyleSet = () => ({
109
110
  {
110
111
  styleId: "Subtitle",
111
112
  type: "paragraph",
112
- name: "Subtitle",
113
+ name: BUILT_IN_STYLE_NAME.subtitle,
113
114
  basedOn: "Title",
114
115
  next: "BodyText",
115
116
  qFormat: true,
@@ -131,7 +132,10 @@ const createStellaStyleSet = () => ({
131
132
  next: "Recital",
132
133
  qFormat: true,
133
134
  uiPriority: 5,
134
- pPr: { keepNext: true },
135
+ pPr: {
136
+ keepNext: true,
137
+ outlineLevel: 0
138
+ },
135
139
  rPr: { bold: true }
136
140
  },
137
141
  {
@@ -179,7 +183,7 @@ const createStellaStyleSet = () => ({
179
183
  {
180
184
  styleId: "ListParagraph",
181
185
  type: "paragraph",
182
- name: "List Paragraph",
186
+ name: BUILT_IN_STYLE_NAME.listParagraph,
183
187
  basedOn: "BodyText",
184
188
  qFormat: true,
185
189
  uiPriority: 31,
@@ -208,13 +212,14 @@ const createStellaStyleSet = () => ({
208
212
  pPr: {
209
213
  pageBreakBefore: true,
210
214
  keepNext: true,
211
- spaceAfter: 240
215
+ spaceAfter: 240,
216
+ outlineLevel: 0
212
217
  }
213
218
  },
214
219
  {
215
220
  styleId: "FootnoteText",
216
221
  type: "paragraph",
217
- name: "Footnote Text",
222
+ name: BUILT_IN_STYLE_NAME.footnoteText,
218
223
  basedOn: "Normal",
219
224
  link: "FootnoteTextChar",
220
225
  semiHidden: true,
@@ -229,7 +234,7 @@ const createStellaStyleSet = () => ({
229
234
  {
230
235
  styleId: "FootnoteTextChar",
231
236
  type: "character",
232
- name: "Footnote Text Char",
237
+ name: BUILT_IN_STYLE_NAME.footnoteTextChar,
233
238
  basedOn: "DefaultParagraphFont",
234
239
  link: "FootnoteText",
235
240
  semiHidden: true,
@@ -243,7 +248,7 @@ const createStellaStyleSet = () => ({
243
248
  {
244
249
  styleId: "FootnoteReference",
245
250
  type: "character",
246
- name: "Footnote Reference",
251
+ name: BUILT_IN_STYLE_NAME.footnoteReference,
247
252
  basedOn: "DefaultParagraphFont",
248
253
  semiHidden: true,
249
254
  unhideWhenUsed: true,
@@ -253,7 +258,7 @@ const createStellaStyleSet = () => ({
253
258
  {
254
259
  styleId: "EndnoteText",
255
260
  type: "paragraph",
256
- name: "Endnote Text",
261
+ name: BUILT_IN_STYLE_NAME.endnoteText,
257
262
  basedOn: "Normal",
258
263
  link: "EndnoteTextChar",
259
264
  semiHidden: true,
@@ -268,7 +273,7 @@ const createStellaStyleSet = () => ({
268
273
  {
269
274
  styleId: "EndnoteTextChar",
270
275
  type: "character",
271
- name: "Endnote Text Char",
276
+ name: BUILT_IN_STYLE_NAME.endnoteTextChar,
272
277
  basedOn: "DefaultParagraphFont",
273
278
  link: "EndnoteText",
274
279
  semiHidden: true,
@@ -282,7 +287,7 @@ const createStellaStyleSet = () => ({
282
287
  {
283
288
  styleId: "EndnoteReference",
284
289
  type: "character",
285
- name: "Endnote Reference",
290
+ name: BUILT_IN_STYLE_NAME.endnoteReference,
286
291
  basedOn: "DefaultParagraphFont",
287
292
  semiHidden: true,
288
293
  unhideWhenUsed: true,
@@ -292,7 +297,7 @@ const createStellaStyleSet = () => ({
292
297
  {
293
298
  styleId: "Footer",
294
299
  type: "paragraph",
295
- name: "Footer",
300
+ name: BUILT_IN_STYLE_NAME.footer,
296
301
  basedOn: "Normal",
297
302
  pPr: {
298
303
  alignment: "right",
@@ -307,7 +312,7 @@ const createStellaStyleSet = () => ({
307
312
  {
308
313
  styleId: "Hyperlink",
309
314
  type: "character",
310
- name: "Hyperlink",
315
+ name: BUILT_IN_STYLE_NAME.hyperlink,
311
316
  basedOn: "DefaultParagraphFont",
312
317
  unhideWhenUsed: true,
313
318
  uiPriority: 99,
@@ -319,7 +324,7 @@ const createStellaStyleSet = () => ({
319
324
  {
320
325
  styleId: "TableNormal",
321
326
  type: "table",
322
- name: "Normal Table",
327
+ name: BUILT_IN_STYLE_NAME.normalTable,
323
328
  default: true,
324
329
  semiHidden: true,
325
330
  unhideWhenUsed: true,
@@ -328,7 +333,7 @@ const createStellaStyleSet = () => ({
328
333
  {
329
334
  styleId: "TableGrid",
330
335
  type: "table",
331
- name: "Table Grid",
336
+ name: BUILT_IN_STYLE_NAME.tableGrid,
332
337
  basedOn: "TableNormal",
333
338
  qFormat: true,
334
339
  uiPriority: 59,
@@ -399,37 +404,37 @@ const createHeadingStyles = () => {
399
404
  return [
400
405
  {
401
406
  styleId: "Heading1",
402
- name: "heading 1",
407
+ name: builtInHeadingStyleName(0),
403
408
  fontSize: 28,
404
409
  spaceBefore: 360
405
410
  },
406
411
  {
407
412
  styleId: "Heading2",
408
- name: "heading 2",
413
+ name: builtInHeadingStyleName(1),
409
414
  fontSize: 24,
410
415
  spaceBefore: 240
411
416
  },
412
417
  {
413
418
  styleId: "Heading3",
414
- name: "heading 3",
419
+ name: builtInHeadingStyleName(2),
415
420
  fontSize: 22,
416
421
  spaceBefore: 240
417
422
  },
418
423
  {
419
424
  styleId: "Heading4",
420
- name: "heading 4",
425
+ name: builtInHeadingStyleName(3),
421
426
  fontSize: 20,
422
427
  spaceBefore: 120
423
428
  },
424
429
  {
425
430
  styleId: "Heading5",
426
- name: "heading 5",
431
+ name: builtInHeadingStyleName(4),
427
432
  fontSize: 20,
428
433
  spaceBefore: 120
429
434
  },
430
435
  {
431
436
  styleId: "Heading6",
432
- name: "heading 6",
437
+ name: builtInHeadingStyleName(5),
433
438
  fontSize: 20,
434
439
  spaceBefore: 120
435
440
  }
@@ -457,32 +462,33 @@ const createHeadingStyles = () => {
457
462
  };
458
463
  /** `TOCHeading` plus `TOC1`..`TOC3`, the styles a `TOC \o "1-3"` field fills. */
459
464
  const createTableOfContentsStyles = () => {
460
- return [{
461
- styleId: "TOCHeading",
462
- type: "paragraph",
463
- name: "TOC Heading",
464
- basedOn: "Heading1",
465
- next: "BodyText",
466
- unhideWhenUsed: true,
467
- uiPriority: 39,
468
- pPr: { outlineLevel: 9 }
469
- }, ...[
465
+ const levels = [
470
466
  {
471
467
  styleId: "TOC1",
472
- name: "toc 1",
468
+ name: builtInTableOfContentsStyleName(1),
473
469
  indent: 0
474
470
  },
475
471
  {
476
472
  styleId: "TOC2",
477
- name: "toc 2",
473
+ name: builtInTableOfContentsStyleName(2),
478
474
  indent: 220
479
475
  },
480
476
  {
481
477
  styleId: "TOC3",
482
- name: "toc 3",
478
+ name: builtInTableOfContentsStyleName(3),
483
479
  indent: 440
484
480
  }
485
- ].map(({ styleId, name, indent }) => ({
481
+ ];
482
+ return [{
483
+ styleId: "TOCHeading",
484
+ type: "paragraph",
485
+ name: BUILT_IN_STYLE_NAME.tocHeading,
486
+ basedOn: "Heading1",
487
+ next: "BodyText",
488
+ unhideWhenUsed: true,
489
+ uiPriority: 39,
490
+ pPr: { outlineLevel: 9 }
491
+ }, ...levels.map(({ styleId, name, indent }) => ({
486
492
  styleId,
487
493
  type: "paragraph",
488
494
  name,
@@ -548,7 +554,8 @@ const createClauseStyles = () => {
548
554
  ilvl: level
549
555
  },
550
556
  keepNext: level < 2,
551
- spaceBefore: clauseSpaceBefore(level)
557
+ spaceBefore: clauseSpaceBefore(level),
558
+ outlineLevel: level === 0 ? 0 : 9
552
559
  }
553
560
  };
554
561
  if (bold) return Object.assign(style, { rPr: { bold: true } });
@@ -0,0 +1,19 @@
1
+ import { DocumentStyleSet } from "./types.js";
2
+ import { ParseContext } from "../docx/parseContext.js";
3
+ //#region src/style-sets/styleSetNormalization.d.ts
4
+ /** The codes this normalisation is reported under, owned here, not at the caller. */
5
+ declare const DUPLICATE_STYLE_ID_WARNING: "style-set-duplicate-style-id";
6
+ declare const INITIAL_PARAGRAPH_STYLE_WARNING: "style-set-initial-style-missing";
7
+ declare const UNNUMBERED_STYLE_SET_STYLE_WARNING: "unnumbered-style";
8
+ /** The part a style-set normalisation names: the set itself, not a package. */
9
+ declare const STYLE_SET_PART = "style-set";
10
+ /**
11
+ * A normalised copy of the set, leaving the caller's value untouched.
12
+ *
13
+ * The version is the one thing still refused rather than repaired: a value
14
+ * folio has no reader for is programmer misuse, not a document defect, and
15
+ * guessing at its meaning would be worse than saying so.
16
+ */
17
+ declare const normalizeDocumentStyleSet: (styleSet: DocumentStyleSet, context?: ParseContext) => DocumentStyleSet;
18
+ //#endregion
19
+ export { DUPLICATE_STYLE_ID_WARNING, INITIAL_PARAGRAPH_STYLE_WARNING, STYLE_SET_PART, UNNUMBERED_STYLE_SET_STYLE_WARNING, normalizeDocumentStyleSet };
@@ -0,0 +1,99 @@
1
+ import { mintDefaultParagraphStyle, resolveDefaultParagraphStyle } from "../docx/defaultParagraphStyle.js";
2
+ import { getCachedNumberingMap } from "../docx/numberingParser.js";
3
+ import { normalizeStyleNumberingReferences } from "../docx/numberingReferenceNormalization.js";
4
+ import "./types.js";
5
+ import { panic } from "better-result";
6
+ import { PARSE_WARNING_CODES } from "@stll/docx-core/model";
7
+ //#region src/style-sets/styleSetNormalization.ts
8
+ /**
9
+ * The boundary an external `DocumentStyleSet` crosses to become a document.
10
+ *
11
+ * A style set is portable by design: hosts persist one as JSON, ship it
12
+ * between workspaces, and hand it back months later. That makes it untrusted
13
+ * input on the same footing as a `.docx`, and it can carry the same defects a
14
+ * package can: a style numbering the set never defines, two styles under one
15
+ * id, an initial paragraph style that is not in the set. A set written before
16
+ * folio learned to normalise those still carries them.
17
+ *
18
+ * So it is normalised here, once, on the way in, through the same owners the
19
+ * parser and the extractor use, rather than at a third call site with its own
20
+ * rules. `createEmptyDocument` is the only door, so this is the only place
21
+ * that has to run.
22
+ *
23
+ * `DOCUMENT_STYLE_SET_VERSION` does not move: the shape is unchanged and a v1
24
+ * value is still a v1 value. What changed is that folio repairs one instead of
25
+ * trusting it.
26
+ */
27
+ /** The codes this normalisation is reported under, owned here, not at the caller. */
28
+ const DUPLICATE_STYLE_ID_WARNING = PARSE_WARNING_CODES.styleSetDuplicateStyleId;
29
+ const INITIAL_PARAGRAPH_STYLE_WARNING = PARSE_WARNING_CODES.styleSetInitialStyleMissing;
30
+ const UNNUMBERED_STYLE_SET_STYLE_WARNING = PARSE_WARNING_CODES.unnumberedStyle;
31
+ /** The part a style-set normalisation names: the set itself, not a package. */
32
+ const STYLE_SET_PART = "style-set";
33
+ /**
34
+ * A normalised copy of the set, leaving the caller's value untouched.
35
+ *
36
+ * The version is the one thing still refused rather than repaired: a value
37
+ * folio has no reader for is programmer misuse, not a document defect, and
38
+ * guessing at its meaning would be worse than saying so.
39
+ */
40
+ const normalizeDocumentStyleSet = (styleSet, context) => {
41
+ if (styleSet.version !== 1) return panic(`Unsupported document style set version: ${String(styleSet.version)}`);
42
+ if (styleSet.name.trim().length === 0) return panic("Document style set name cannot be empty");
43
+ const scoped = context?.scoped({ part: STYLE_SET_PART });
44
+ const normalized = structuredClone(styleSet);
45
+ const styles = dropDuplicateStyleIds(normalized.styles.styles, scoped);
46
+ normalized.styles.styles = styles;
47
+ const unnumbered = normalizeStyleNumberingReferences({
48
+ styles,
49
+ numbering: normalized.numbering ? getCachedNumberingMap(normalized.numbering) : void 0
50
+ });
51
+ for (const styleId of unnumbered.unnumberedStyleIds) scoped?.warn({
52
+ code: UNNUMBERED_STYLE_SET_STYLE_WARNING,
53
+ value: styleId,
54
+ at: `style "${styleId}"`
55
+ });
56
+ normalized.initialParagraphStyleId = resolveInitialParagraphStyleId({
57
+ styles,
58
+ requested: styleSet.initialParagraphStyleId,
59
+ hasDocDefaults: normalized.styles.docDefaults !== void 0,
60
+ context: scoped
61
+ });
62
+ return normalized;
63
+ };
64
+ const dropDuplicateStyleIds = (styles, context) => {
65
+ const seen = /* @__PURE__ */ new Set();
66
+ const kept = [];
67
+ for (const style of styles) {
68
+ if (seen.has(style.styleId)) {
69
+ context?.warn({
70
+ code: DUPLICATE_STYLE_ID_WARNING,
71
+ value: style.styleId,
72
+ at: `style "${style.styleId}"`
73
+ });
74
+ continue;
75
+ }
76
+ seen.add(style.styleId);
77
+ kept.push(style);
78
+ }
79
+ return kept;
80
+ };
81
+ const resolveInitialParagraphStyleId = ({ styles, requested, hasDocDefaults, context }) => {
82
+ if (styles.find((style) => style.styleId === requested && style.type === "paragraph")) return requested;
83
+ const replacement = resolveDefaultParagraphStyle(styles) ?? (() => {
84
+ const minted = mintDefaultParagraphStyle({
85
+ takenStyleIds: new Set(styles.map((style) => style.styleId)),
86
+ hasDocDefaults
87
+ });
88
+ styles.push(minted);
89
+ return minted;
90
+ })();
91
+ context?.warn({
92
+ code: INITIAL_PARAGRAPH_STYLE_WARNING,
93
+ value: requested,
94
+ at: `style "${replacement.styleId}"`
95
+ });
96
+ return replacement.styleId;
97
+ };
98
+ //#endregion
99
+ export { DUPLICATE_STYLE_ID_WARNING, INITIAL_PARAGRAPH_STYLE_WARNING, STYLE_SET_PART, UNNUMBERED_STYLE_SET_STYLE_WARNING, normalizeDocumentStyleSet };
@@ -1,2 +1,2 @@
1
- import { BlockContent, BlockSdt, BookmarkEnd, BookmarkStart, BreakContent, Column, Comment, CommentRangeEnd, CommentRangeStart, CommentReference, ComplexField, Deletion, DocumentBody, DrawingContent, DrawingRawXmlMode, Endnote, EndnotePosition, EndnoteProperties, Field, FieldCharContent, FieldType, FooterReference, Footnote, FootnotePosition, FootnoteProperties, HeaderFooter, HeaderFooterType, HeaderReference, Hyperlink, Image, ImageCrop, ImagePadding, ImagePosition, ImageSize, ImageTransform, ImageWrap, InlineSdt, Insertion, InstrTextContent, LineNumberRestart, MathEquation, MoveFrom, MoveFromRangeEnd, MoveFromRangeStart, MoveTo, MoveToRangeEnd, MoveToRangeStart, NoBreakHyphenContent, NoteNumberRestart, NoteReferenceContent, PageOrientation, Paragraph, ParagraphContent, ParagraphPropertyChange, PositionalTab, PropertyChangeInfo, Run, RunContent, RunPropertyChange, SdtProperties, SdtType, Section, SectionProperties, SectionStart, Shape, ShapeContent, ShapeFill, ShapeGeometryAdjustment, ShapeOutline, ShapeTextBody, ShapeType, SimpleField, SoftHyphenContent, SymbolContent, TabContent, Table, TableCell, TableCellPropertyChange, TableRow, TableRowPropertyChange, TableStructuralChangeInfo, TextBox, TextContent, TrackedChangeInfo, TrackedRunChange, TrackedRunContent, VerticalAlign } from "@stll/docx-core/model";
2
- export type { BlockContent, BlockSdt, BookmarkEnd, BookmarkStart, BreakContent, Column, Comment, CommentRangeEnd, CommentRangeStart, CommentReference, ComplexField, Deletion, DocumentBody, DrawingContent, DrawingRawXmlMode, Endnote, EndnotePosition, EndnoteProperties, Field, FieldCharContent, FieldType, FooterReference, Footnote, FootnotePosition, FootnoteProperties, HeaderFooter, HeaderFooterType, HeaderReference, Hyperlink, Image, ImageCrop, ImagePadding, ImagePosition, ImageSize, ImageTransform, ImageWrap, InlineSdt, Insertion, InstrTextContent, LineNumberRestart, MathEquation, MoveFrom, MoveFromRangeEnd, MoveFromRangeStart, MoveTo, MoveToRangeEnd, MoveToRangeStart, NoBreakHyphenContent, NoteNumberRestart, NoteReferenceContent, PageOrientation, Paragraph, ParagraphContent, ParagraphPropertyChange, PositionalTab, PropertyChangeInfo, Run, RunContent, RunPropertyChange, SdtProperties, SdtType, Section, SectionProperties, SectionStart, Shape, ShapeContent, ShapeFill, ShapeGeometryAdjustment, ShapeOutline, ShapeTextBody, ShapeType, SimpleField, SoftHyphenContent, SymbolContent, TabContent, Table, TableCell, TableCellPropertyChange, TableRow, TableRowPropertyChange, TableStructuralChangeInfo, TextBox, TextContent, TrackedChangeInfo, TrackedRunChange, TrackedRunContent, VerticalAlign };
1
+ import { BlockContent, BlockRangeMarkerCapture, BlockSdt, BookmarkEnd, BookmarkStart, BreakContent, Column, Comment, CommentRangeEnd, CommentRangeStart, CommentReference, ComplexField, Deletion, DisplacedByCustomXml, DocumentBody, DrawingContent, DrawingRawXmlMode, Endnote, EndnotePosition, EndnoteProperties, Field, FieldCharContent, FieldType, FooterReference, Footnote, FootnotePosition, FootnoteProperties, HeaderFooter, HeaderFooterType, HeaderReference, Hyperlink, Image, ImageCrop, ImagePadding, ImagePosition, ImageSize, ImageTransform, ImageWrap, InlineSdt, Insertion, InstrTextContent, LineNumberRestart, MathEquation, MoveFrom, MoveFromRangeEnd, MoveFromRangeStart, MoveTo, MoveToRangeEnd, MoveToRangeStart, NoBreakHyphenContent, NoteNumberRestart, NoteReferenceContent, PageOrientation, Paragraph, ParagraphContent, ParagraphPropertyChange, PositionalTab, PropertyChangeInfo, Run, RunContent, RunPropertyChange, SdtProperties, SdtType, Section, SectionProperties, SectionStart, Shape, ShapeContent, ShapeFill, ShapeGeometryAdjustment, ShapeOutline, ShapeTextBody, ShapeType, SimpleField, SoftHyphenContent, SymbolContent, TabContent, Table, TableCell, TableCellPropertyChange, TableRow, TableRowPropertyChange, TableStructuralChangeInfo, TextBox, TextContent, TrackedChangeInfo, TrackedRunChange, TrackedRunContent, VerticalAlign } from "@stll/docx-core/model";
2
+ export type { BlockContent, BlockRangeMarkerCapture, BlockSdt, BookmarkEnd, BookmarkStart, BreakContent, Column, Comment, CommentRangeEnd, CommentRangeStart, CommentReference, ComplexField, Deletion, DisplacedByCustomXml, DocumentBody, DrawingContent, DrawingRawXmlMode, Endnote, EndnotePosition, EndnoteProperties, Field, FieldCharContent, FieldType, FooterReference, Footnote, FootnotePosition, FootnoteProperties, HeaderFooter, HeaderFooterType, HeaderReference, Hyperlink, Image, ImageCrop, ImagePadding, ImagePosition, ImageSize, ImageTransform, ImageWrap, InlineSdt, Insertion, InstrTextContent, LineNumberRestart, MathEquation, MoveFrom, MoveFromRangeEnd, MoveFromRangeStart, MoveTo, MoveToRangeEnd, MoveToRangeStart, NoBreakHyphenContent, NoteNumberRestart, NoteReferenceContent, PageOrientation, Paragraph, ParagraphContent, ParagraphPropertyChange, PositionalTab, PropertyChangeInfo, Run, RunContent, RunPropertyChange, SdtProperties, SdtType, Section, SectionProperties, SectionStart, Shape, ShapeContent, ShapeFill, ShapeGeometryAdjustment, ShapeOutline, ShapeTextBody, ShapeType, SimpleField, SoftHyphenContent, SymbolContent, TabContent, Table, TableCell, TableCellPropertyChange, TableRow, TableRowPropertyChange, TableStructuralChangeInfo, TextBox, TextContent, TrackedChangeInfo, TrackedRunChange, TrackedRunContent, VerticalAlign };
@@ -1,3 +1,8 @@
1
+ import { BUILT_IN_STYLE_NAME, builtInHeadingStyleName } from "../docx/builtInStyles.js";
2
+ import "../docx/defaultParagraphStyle.js";
3
+ import { createParseWarningCollector } from "../docx/parseContext.js";
4
+ import { formatParseWarnings } from "../docx/parseWarningMessage.js";
5
+ import { STYLE_SET_PART, normalizeDocumentStyleSet } from "../style-sets/styleSetNormalization.js";
1
6
  import "../style-sets/types.js";
2
7
  import { panic } from "better-result";
3
8
  import { DOCX_CONFORMANCE_CLASSES } from "@stll/docx-core/model";
@@ -12,13 +17,17 @@ import { DOCX_CONFORMANCE_CLASSES } from "@stll/docx-core/model";
12
17
  *
13
18
  * Font sizes are in half-points (e.g., 22 = 11pt, 40 = 20pt)
14
19
  * Colors are RGB hex without # prefix
20
+ *
21
+ * Each style carries the built-in `w:name` it stands for, which is how every
22
+ * consumer recognises it (`docx/builtInStyles.ts`), and the headings carry
23
+ * `w:outlineLvl` so a Word TOC field and the navigation pane list them.
15
24
  */
16
25
  function getDefaultStyles() {
17
26
  return [
18
27
  {
19
28
  styleId: "Normal",
20
29
  type: "paragraph",
21
- name: "Normal",
30
+ name: BUILT_IN_STYLE_NAME.normal,
22
31
  default: true,
23
32
  qFormat: true,
24
33
  uiPriority: 0,
@@ -34,7 +43,7 @@ function getDefaultStyles() {
34
43
  {
35
44
  styleId: "Title",
36
45
  type: "paragraph",
37
- name: "Title",
46
+ name: BUILT_IN_STYLE_NAME.title,
38
47
  basedOn: "Normal",
39
48
  next: "Normal",
40
49
  qFormat: true,
@@ -52,7 +61,7 @@ function getDefaultStyles() {
52
61
  {
53
62
  styleId: "Subtitle",
54
63
  type: "paragraph",
55
- name: "Subtitle",
64
+ name: BUILT_IN_STYLE_NAME.subtitle,
56
65
  basedOn: "Normal",
57
66
  next: "Normal",
58
67
  qFormat: true,
@@ -70,7 +79,7 @@ function getDefaultStyles() {
70
79
  {
71
80
  styleId: "Heading1",
72
81
  type: "paragraph",
73
- name: "Heading 1",
82
+ name: builtInHeadingStyleName(0),
74
83
  basedOn: "Normal",
75
84
  next: "Normal",
76
85
  qFormat: true,
@@ -86,13 +95,14 @@ function getDefaultStyles() {
86
95
  pPr: {
87
96
  spaceBefore: 400,
88
97
  spaceAfter: 120,
89
- lineSpacing: 240
98
+ lineSpacing: 240,
99
+ outlineLevel: 0
90
100
  }
91
101
  },
92
102
  {
93
103
  styleId: "Heading2",
94
104
  type: "paragraph",
95
- name: "Heading 2",
105
+ name: builtInHeadingStyleName(1),
96
106
  basedOn: "Normal",
97
107
  next: "Normal",
98
108
  qFormat: true,
@@ -108,13 +118,14 @@ function getDefaultStyles() {
108
118
  pPr: {
109
119
  spaceBefore: 360,
110
120
  spaceAfter: 80,
111
- lineSpacing: 240
121
+ lineSpacing: 240,
122
+ outlineLevel: 1
112
123
  }
113
124
  },
114
125
  {
115
126
  styleId: "Heading3",
116
127
  type: "paragraph",
117
- name: "Heading 3",
128
+ name: builtInHeadingStyleName(2),
118
129
  basedOn: "Normal",
119
130
  next: "Normal",
120
131
  qFormat: true,
@@ -130,13 +141,14 @@ function getDefaultStyles() {
130
141
  pPr: {
131
142
  spaceBefore: 320,
132
143
  spaceAfter: 80,
133
- lineSpacing: 240
144
+ lineSpacing: 240,
145
+ outlineLevel: 2
134
146
  }
135
147
  },
136
148
  {
137
149
  styleId: "Heading4",
138
150
  type: "paragraph",
139
- name: "Heading 4",
151
+ name: builtInHeadingStyleName(3),
140
152
  basedOn: "Normal",
141
153
  next: "Normal",
142
154
  qFormat: true,
@@ -152,6 +164,121 @@ function getDefaultStyles() {
152
164
  pPr: {
153
165
  spaceBefore: 280,
154
166
  spaceAfter: 80,
167
+ lineSpacing: 240,
168
+ outlineLevel: 3
169
+ }
170
+ },
171
+ {
172
+ styleId: "Heading5",
173
+ type: "paragraph",
174
+ name: builtInHeadingStyleName(4),
175
+ basedOn: "Normal",
176
+ next: "Normal",
177
+ qFormat: true,
178
+ uiPriority: 9,
179
+ rPr: {
180
+ fontSize: 22,
181
+ bold: true,
182
+ fontFamily: {
183
+ ascii: "Arial",
184
+ hAnsi: "Arial"
185
+ }
186
+ },
187
+ pPr: {
188
+ spaceBefore: 240,
189
+ spaceAfter: 80,
190
+ lineSpacing: 240,
191
+ outlineLevel: 4
192
+ }
193
+ },
194
+ {
195
+ styleId: "Heading6",
196
+ type: "paragraph",
197
+ name: builtInHeadingStyleName(5),
198
+ basedOn: "Normal",
199
+ next: "Normal",
200
+ qFormat: true,
201
+ uiPriority: 9,
202
+ rPr: {
203
+ fontSize: 22,
204
+ bold: true,
205
+ color: { rgb: "595959" },
206
+ fontFamily: {
207
+ ascii: "Arial",
208
+ hAnsi: "Arial"
209
+ }
210
+ },
211
+ pPr: {
212
+ spaceBefore: 240,
213
+ spaceAfter: 80,
214
+ lineSpacing: 240,
215
+ outlineLevel: 5
216
+ }
217
+ },
218
+ {
219
+ styleId: "TableNormal",
220
+ type: "table",
221
+ name: BUILT_IN_STYLE_NAME.normalTable,
222
+ uiPriority: 99,
223
+ semiHidden: true,
224
+ unhideWhenUsed: true
225
+ },
226
+ {
227
+ styleId: "TableGrid",
228
+ type: "table",
229
+ name: BUILT_IN_STYLE_NAME.tableGrid,
230
+ basedOn: "TableNormal",
231
+ uiPriority: 39,
232
+ tblPr: { borders: {
233
+ top: {
234
+ style: "single",
235
+ size: 4,
236
+ space: 0
237
+ },
238
+ bottom: {
239
+ style: "single",
240
+ size: 4,
241
+ space: 0
242
+ },
243
+ left: {
244
+ style: "single",
245
+ size: 4,
246
+ space: 0
247
+ },
248
+ right: {
249
+ style: "single",
250
+ size: 4,
251
+ space: 0
252
+ },
253
+ insideH: {
254
+ style: "single",
255
+ size: 4,
256
+ space: 0
257
+ },
258
+ insideV: {
259
+ style: "single",
260
+ size: 4,
261
+ space: 0
262
+ }
263
+ } }
264
+ },
265
+ {
266
+ styleId: "Quote",
267
+ type: "paragraph",
268
+ name: BUILT_IN_STYLE_NAME.quote,
269
+ basedOn: "Normal",
270
+ next: "Normal",
271
+ qFormat: true,
272
+ uiPriority: 29,
273
+ rPr: {
274
+ italic: true,
275
+ color: { rgb: "404040" }
276
+ },
277
+ pPr: {
278
+ indentLeft: 720,
279
+ indentRight: 720,
280
+ spaceBefore: 160,
281
+ spaceAfter: 160,
155
282
  lineSpacing: 240
156
283
  }
157
284
  }
@@ -203,9 +330,10 @@ function getDefaultSectionProperties() {
203
330
  * ```
204
331
  */
205
332
  function createEmptyDocument(options = {}) {
206
- const styleSet = options.preset?.styleSet ?? options.styleSet;
207
- validateDocumentStyleSet(styleSet);
333
+ const suppliedStyleSet = options.preset?.styleSet ?? options.styleSet;
208
334
  if (options.preset?.version !== void 0 && options.preset.version !== 1) return panic(`Unsupported document preset version: ${options.preset.version}`);
335
+ const { context: styleSetContext, warnings: styleSetWarnings } = createParseWarningCollector(STYLE_SET_PART);
336
+ const styleSet = suppliedStyleSet === void 0 ? void 0 : normalizeDocumentStyleSet(suppliedStyleSet, styleSetContext);
209
337
  const sectionProps = structuredClone(options.preset?.sectionProperties ?? getDefaultSectionProperties());
210
338
  if (options.pageWidth !== void 0) sectionProps.pageWidth = Math.round(options.pageWidth);
211
339
  if (options.pageHeight !== void 0) sectionProps.pageHeight = Math.round(options.pageHeight);
@@ -253,18 +381,15 @@ function createEmptyDocument(options = {}) {
253
381
  if (styleSet?.theme) docxPackage.theme = structuredClone(styleSet.theme);
254
382
  if (styleSet?.fontTable) docxPackage.fontTable = structuredClone(styleSet.fontTable);
255
383
  if (styleSet?.settings) docxPackage.settings = structuredClone(styleSet.settings);
256
- return {
384
+ const parseWarnings = styleSetWarnings();
385
+ const document = {
257
386
  package: docxPackage,
258
387
  templateVariables: [],
259
- warnings: []
388
+ warnings: formatParseWarnings(parseWarnings)
260
389
  };
390
+ if (parseWarnings.length > 0) document.parseWarnings = parseWarnings;
391
+ return document;
261
392
  }
262
- const validateDocumentStyleSet = (styleSet) => {
263
- if (!styleSet) return;
264
- if (styleSet.version !== 1) return panic(`Unsupported document style set version: ${styleSet.version}`);
265
- if (styleSet.name.trim().length === 0) return panic("Document style set name cannot be empty");
266
- if (styleSet.styles.styles.find((style) => style.styleId === styleSet.initialParagraphStyleId)?.type !== "paragraph") return panic(`Initial paragraph style "${styleSet.initialParagraphStyleId}" is missing from style set "${styleSet.name}"`);
267
- };
268
393
  /**
269
394
  * Create a document with a single paragraph containing the given text
270
395
  *
@@ -1,3 +1,4 @@
1
+ import { BuiltInStyleIndex } from "../docx/builtInStyles.js";
1
2
  import { Node } from "prosemirror-model";
2
3
  //#region src/utils/headingCollector.d.ts
3
4
  /**
@@ -14,12 +15,14 @@ type HeadingInfo = {
14
15
  pageNumber?: number | null;
15
16
  };
16
17
  /**
17
- * Collect all headings from a ProseMirror document.
18
+ * Collect all headings from a ProseMirror document, in document order.
18
19
  *
19
- * Detection logic:
20
- * 1. Check `outlineLevel` attr (set by OOXML parsing or style resolution)
21
- * 2. Fallback to `styleId` matching /^[Hh]eading(\d)$/
20
+ * Classification is {@link resolveHeadingLevel}'s: the paragraph's effective
21
+ * outline level, else the style's built-in `w:name`. Pass the open document's
22
+ * index (`styleResolver.builtInStyles`) so a localized style id such as
23
+ * `Nadpis1` or `berschrift1` resolves through its name rather than falling out
24
+ * of the outline.
22
25
  */
23
- declare function collectHeadings(doc: Node): HeadingInfo[];
26
+ declare function collectHeadings(doc: Node, styles: BuiltInStyleIndex): HeadingInfo[];
24
27
  //#endregion
25
28
  export { HeadingInfo, collectHeadings };