@docx4j/core-ts 0.6.0 → 0.7.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 (119) hide show
  1. package/README.md +60 -0
  2. package/dist/model/content/Body.mjs +6 -17
  3. package/dist/model/content/Comment.d.mts +2 -2
  4. package/dist/model/content/Comment.mjs +12 -7
  5. package/dist/model/content/ContentControl.d.mts +1 -1
  6. package/dist/model/content/ContentControl.mjs +8 -4
  7. package/dist/model/content/Font.d.mts +4 -1
  8. package/dist/model/content/Font.mjs +6 -2
  9. package/dist/model/content/List.d.mts +6 -3
  10. package/dist/model/content/List.mjs +15 -8
  11. package/dist/model/content/Paragraph.d.mts +12 -2
  12. package/dist/model/content/Paragraph.mjs +31 -11
  13. package/dist/model/content/Table.mjs +26 -16
  14. package/dist/model/content/TrackedChange.d.mts +2 -2
  15. package/dist/model/content/TrackedChange.mjs +6 -3
  16. package/dist/model/content/index.d.mts +3 -1
  17. package/dist/model/content/index.mjs +4 -1
  18. package/dist/model/content/ooxml.mjs +12 -1
  19. package/dist/model/content/paraIds.d.mts +5 -0
  20. package/dist/model/content/paraIds.mjs +54 -0
  21. package/dist/model/content/search.d.mts +2 -0
  22. package/dist/model/content/search.mjs +51 -7
  23. package/dist/model/content/story.d.mts +5 -2
  24. package/dist/model/content/story.mjs +6 -3
  25. package/dist/model/content/tableRules.mjs +2 -0
  26. package/dist/model/content/tracking.d.mts +35 -6
  27. package/dist/model/content/tracking.mjs +93 -12
  28. package/dist/model/content/tree.d.mts +7 -8
  29. package/dist/model/content/tree.mjs +7 -9
  30. package/dist/model/content/wordRange.d.mts +48 -0
  31. package/dist/model/content/wordRange.mjs +97 -0
  32. package/dist/model/customxml/CustomXmlPartCollection.d.mts +22 -1
  33. package/dist/model/customxml/CustomXmlPartCollection.mjs +48 -2
  34. package/dist/model/customxml/XmlMapping.d.mts +31 -7
  35. package/dist/model/customxml/XmlMapping.mjs +53 -10
  36. package/dist/model/customxml/bindings.d.mts +12 -2
  37. package/dist/model/customxml/bindings.mjs +98 -16
  38. package/dist/model/customxml/index.d.mts +1 -0
  39. package/dist/model/customxml/index.mjs +1 -0
  40. package/dist/model/customxml/opendope.d.mts +4 -1
  41. package/dist/model/customxml/opendope.mjs +9 -6
  42. package/dist/model/customxml/pictures.mjs +5 -3
  43. package/dist/model/customxml/storeItems.d.mts +57 -0
  44. package/dist/model/customxml/storeItems.mjs +122 -0
  45. package/dist/model/customxml/xhtml.mjs +15 -20
  46. package/dist/model/dateZone.d.mts +25 -0
  47. package/dist/model/dateZone.mjs +57 -0
  48. package/dist/model/index.d.mts +1 -0
  49. package/dist/model/index.mjs +1 -0
  50. package/dist/model/properties/PropertyResolver.d.mts +14 -1
  51. package/dist/model/properties/PropertyResolver.mjs +18 -3
  52. package/dist/model/properties/index.d.mts +1 -1
  53. package/dist/model/properties/log.mjs +2 -2
  54. package/dist/model/properties/styleUtil.d.mts +3 -1
  55. package/dist/model/properties/styleUtil.mjs +20 -24
  56. package/dist/model/text/CaseMapping.d.mts +38 -0
  57. package/dist/model/text/CaseMapping.mjs +86 -0
  58. package/dist/model/text/Extractor.d.mts +66 -6
  59. package/dist/model/text/Extractor.mjs +300 -56
  60. package/dist/model/text/PlainText.mjs +7 -4
  61. package/dist/model/text/TextContext.d.mts +103 -8
  62. package/dist/model/text/TextContext.mjs +228 -53
  63. package/dist/model/text/TextOptions.d.mts +88 -5
  64. package/dist/model/text/TextOptions.mjs +158 -17
  65. package/dist/model/text/TextResult.d.mts +126 -9
  66. package/dist/model/text/TextResult.mjs +115 -12
  67. package/dist/model/text/WmlToMarkdown.mjs +32 -7
  68. package/dist/model/text/caseMapping.generated.d.mts +7 -0
  69. package/dist/model/text/caseMapping.generated.mjs +214 -0
  70. package/dist/model/text/index.d.mts +3 -2
  71. package/dist/model/text/index.mjs +1 -0
  72. package/dist/model/wordIntegers.d.mts +29 -0
  73. package/dist/model/wordIntegers.mjs +78 -0
  74. package/dist/office-js/document.mjs +15 -1
  75. package/dist/office-js/toApiScript.mjs +8 -7
  76. package/dist/opc/DirectoryPartStore.d.mts +6 -2
  77. package/dist/opc/DirectoryPartStore.mjs +11 -4
  78. package/dist/opc/FlatOpcPartStore.d.mts +4 -2
  79. package/dist/opc/FlatOpcPartStore.mjs +11 -8
  80. package/dist/opc/Load.d.mts +32 -0
  81. package/dist/opc/Load.mjs +115 -5
  82. package/dist/opc/PartStore.d.mts +34 -1
  83. package/dist/opc/PartStore.mjs +71 -8
  84. package/dist/opc/Save.d.mts +17 -2
  85. package/dist/opc/Save.mjs +100 -4
  86. package/dist/opc/ZipPartStore.d.mts +4 -2
  87. package/dist/opc/ZipPartStore.mjs +12 -7
  88. package/dist/opc/exceptions.d.mts +140 -0
  89. package/dist/opc/exceptions.mjs +108 -0
  90. package/dist/opc/index.d.mts +7 -4
  91. package/dist/opc/index.mjs +5 -3
  92. package/dist/opc/mce/preprocessor.d.mts +121 -10
  93. package/dist/opc/mce/preprocessor.mjs +122 -21
  94. package/dist/opc/mce/understood.d.mts +3 -35
  95. package/dist/opc/mce/understood.mjs +27 -53
  96. package/dist/opc/repair/breaks.d.mts +23 -0
  97. package/dist/opc/repair/breaks.mjs +288 -0
  98. package/dist/opc/repair/hosts.d.mts +12 -0
  99. package/dist/opc/repair/hosts.mjs +33 -0
  100. package/dist/opc/repair/mainRoot.d.mts +19 -0
  101. package/dist/opc/repair/mainRoot.mjs +168 -0
  102. package/dist/opc/repair/unknownElements.d.mts +8 -0
  103. package/dist/opc/repair/unknownElements.mjs +180 -0
  104. package/dist/opc/repair/wmlNames.generated.d.mts +2 -0
  105. package/dist/opc/repair/wmlNames.generated.mjs +80 -0
  106. package/dist/opc/skipped.d.mts +50 -0
  107. package/dist/opc/skipped.mjs +140 -0
  108. package/dist/packages/OpcPackage.d.mts +98 -5
  109. package/dist/packages/OpcPackage.mjs +122 -7
  110. package/dist/packages/WordprocessingMLPackage.mjs +3 -1
  111. package/dist/packages/index.d.mts +1 -1
  112. package/dist/parts/Part.d.mts +5 -1
  113. package/dist/parts/RelationshipsPart.d.mts +15 -0
  114. package/dist/parts/RelationshipsPart.mjs +66 -1
  115. package/dist/parts/XmlPart.d.mts +54 -5
  116. package/dist/parts/XmlPart.mjs +203 -10
  117. package/dist/parts/wml/index.d.mts +12 -1
  118. package/dist/parts/wml/index.mjs +25 -1
  119. package/package.json +2 -2
@@ -31,6 +31,11 @@ export type TextRunKind =
31
31
  | 'PAGE_MARKER';
32
32
  /** `footnote` or `endnote`, as a note reference, mark or block says whose it is. */
33
33
  export type NoteType = 'footnote' | 'endnote';
34
+ /**
35
+ * A run's `w:vertAlign` (WD REQ-710): `SUPERSCRIPT`, `SUBSCRIPT`, or `BASELINE` for neither. docx4j's
36
+ * `TextRun.VerticalAlignment` names as strings (CR-012 section 24, D3).
37
+ */
38
+ export type TextVerticalAlignment = 'BASELINE' | 'SUPERSCRIPT' | 'SUBSCRIPT';
34
39
  /** Where a run's text was read from: its run and its paragraph (CR-012 section 4.4). */
35
40
  export interface TextRunSource {
36
41
  run: wml.R;
@@ -168,10 +173,32 @@ export declare class TextRun {
168
173
  bold: boolean;
169
174
  /** Italic where its paragraph's style is not. */
170
175
  italic: boolean;
171
- /** Struck through where its paragraph's style is not. */
176
+ /** Struck through where its paragraph's style is not: `w:strike`, or `w:dstrike`, struck twice (CR-012 section 24.5). */
172
177
  strike: boolean;
173
178
  /** In a monospaced font where its paragraph's style is not in one. */
174
179
  monospace: boolean;
180
+ /**
181
+ * Shown in capitals (`w:caps`): the run's own property, else its styles', the paragraph style's among them (the case is
182
+ * the text's, not emphasis). `text` stays the stored characters; the plain-text and Markdown writers write them in
183
+ * capitals by `language` (`CaseMapping`; WD REQ-607, CR-012 section 24).
184
+ */
185
+ caps: boolean;
186
+ /**
187
+ * In small capitals (`w:smallCaps`), folded as `caps` is, and not caps: a run under both is a caps run. The writers write
188
+ * its stored characters, unless `small_caps: upper` is set (WD REQ-607).
189
+ */
190
+ smallCaps: boolean;
191
+ /**
192
+ * The text's `w:vertAlign`, the run's own, else its styles' (WD REQ-710); `BASELINE` for a note reference, which is a
193
+ * reference (REQ-503), not a superscript.
194
+ */
195
+ verticalAlignment: TextVerticalAlignment;
196
+ /**
197
+ * For a caps or small-caps run, the language its capitals are mapped by (WD REQ-607, the WD's `lang`): its
198
+ * `w:lang/@w:val`, else its styles' or the document defaults', else the `default_language` option (`en-US` by default;
199
+ * `w:themeFontLang` is no link, WD 0.80); undefined for any other run, so that a `w:lang` alone never splits runs.
200
+ */
201
+ language: string | undefined;
175
202
  /** For text in a link: its target (a `w:hyperlink`'s, or a HYPERLINK field's, REQ-703). */
176
203
  link: string | undefined;
177
204
  /** True for an equation (REQ-604). */
@@ -381,6 +408,8 @@ export declare class TextBlock {
381
408
  * rows a line apart, their cells a tab apart. No list label, note number or comment.
382
409
  */
383
410
  get text(): string;
411
+ /** `text` with each text run's text as the function gives it (`CaseMapping.written`). */
412
+ textWith(runText: (run: TextRun) => string): string;
384
413
  /** The block model's JSON (REQ-706): the fields, the text and the flags; never a tree object. */
385
414
  toJSON(): Record<string, unknown>;
386
415
  toString(): string;
@@ -410,8 +439,10 @@ export declare class TextComment {
410
439
  /**
411
440
  * Where a result is not the whole document (WD section 8, REQ-801): a kind, the address it is at where
412
441
  * there is one, and its selector: for `mce.branches_differ` the name of the branch selected, for
413
- * `altchunk.not_expanded` the chunk's content type, for `content.not_read` and `image.not_described` the
414
- * part's name. Never the document's text (REQ-802). docx4j `TextWarning`.
442
+ * `altchunk.not_expanded`, `content.not_read` and `image.not_described` the part's name (the chunk's since
443
+ * CR-012 section 22.2 (a), WD 0.47; it was the chunk's content type, which the warning still carries), for
444
+ * `paragraph.drop_cap_joined` the name of the part the paragraphs are in. Never the document's text (REQ-802).
445
+ * docx4j `TextWarning`.
415
446
  */
416
447
  export declare class TextWarning {
417
448
  readonly kind: string;
@@ -421,10 +452,38 @@ export declare class TextWarning {
421
452
  readonly branch?: string | undefined;
422
453
  /** For `altchunk.not_expanded`, the chunk's content type as the package declares it. */
423
454
  readonly contentType?: string | undefined;
424
- /** For `content.not_read` and `image.not_described`, the part's name. */
455
+ /**
456
+ * For `content.not_read`, `part.not_read` and `part.absent`, the part's name; for `image.not_described`, the image part's; for `altchunk.not_expanded`,
457
+ * the chunk's (`/word/afchunk.rtf`), so that a host can read it itself; for `paragraph.drop_cap_joined`, the part the
458
+ * paragraphs are in (`/word/document.xml`); for `package.multiple_main_parts` and `package.external_main_part`, the part
459
+ * read; for `package.relationships_namespace`, the relationships part; for `mce.nothing_selected`,
460
+ * the part holding the element.
461
+ */
425
462
  readonly partName?: string | undefined;
463
+ /**
464
+ * What the kind says beyond its selector (REQ-801's `detail`): for `package.duplicate_entry`, the entries of the name; for
465
+ * `package.multiple_main_parts`, the relationships; for `package.external_main_part`, the first URL as written; for
466
+ * `package.relationships_namespace`, the relationships read; for `mce.nothing_selected`, the namespaces required.
467
+ */
468
+ readonly detail?: (number | string) | undefined;
426
469
  /** Both branches of an `mc:AlternateContent` hold text, and the texts differ (REQ-307). */
427
470
  static readonly MCE_BRANCHES_DIFFER = "mce.branches_differ";
471
+ /**
472
+ * An `mc:AlternateContent` with Choices, none understood, and no Fallback, so it reads as absent (REQ-305): at its address,
473
+ * or with none where the walk can't meet it (a resolved load took it out, or it is a part's root). The part's name is the
474
+ * selector, and `detail` the namespaces its Choices require, as one string of URIs, empty if every prefix binds to nothing.
475
+ */
476
+ static readonly MCE_NOTHING_SELECTED = "mce.nothing_selected";
477
+ /**
478
+ * An `mc:Ignorable` listing a prefix no declaration in scope binds, read as though the list didn't hold it (REQ-323, CR-030):
479
+ * once a part the reading took, no address, the part's name the selector and `detail` the prefixes, separated by spaces.
480
+ */
481
+ static readonly MCE_UNDECLARED_PREFIX = "mce.undeclared_prefix";
482
+ /**
483
+ * A main document part whose root Word opens showing nothing of, read as an empty document (REQ-320, CR-028 D11): once, no
484
+ * address, the part's name the selector and `detail` the root's qualified name.
485
+ */
486
+ static readonly PART_UNEXPECTED_ROOT = "part.unexpected_root";
428
487
  /** A field with no cached result (REQ-505). */
429
488
  static readonly FIELD_NO_RESULT = "field.no_result";
430
489
  /** A data-bound control whose surface differs from its bound value (REQ-509). */
@@ -433,8 +492,46 @@ export declare class TextWarning {
433
492
  static readonly ALTCHUNK_NOT_EXPANDED = "altchunk.not_expanded";
434
493
  /** A chart, a SmartArt data part, or an embedded package or a part inside it, that can't be read. */
435
494
  static readonly CONTENT_NOT_READ = "content.not_read";
495
+ /**
496
+ * A part the reading consulted and needed for this document, but does not emit, that cannot be read (REQ-801, WD 0.66):
497
+ * a styles, numbering or settings part, a document-properties part where the metadata is written, or a custom XML store
498
+ * a binding names. The reading proceeds as for a package that lacks it; once per part, no address, the part's name the
499
+ * selector (CR-012 section 28).
500
+ */
501
+ static readonly PART_NOT_READ = "part.not_read";
502
+ /**
503
+ * A part the reading needed that the package does not hold, where the reading supplies what it would have: the numbering
504
+ * part, for a numbered paragraph, counted as Word's default definition (REQ-510, WD 0.76). Once, no address, the name the
505
+ * package would have held the part under (`/word/numbering.xml`) the selector.
506
+ */
507
+ static readonly PART_ABSENT = "part.absent";
508
+ /**
509
+ * A name the package's container holds more than one entry of, read from the first under `repair: 'word'`
510
+ * (REQ-206, CR-024): no address, the entry as its first copy spells it the selector, the number of entries `detail`.
511
+ */
512
+ static readonly PACKAGE_DUPLICATE_ENTRY = "package.duplicate_entry";
513
+ /**
514
+ * A package with more than one officeDocument relationship, the last's target read under `repair: 'word'`
515
+ * (REQ-206's statement, CR-024 section 9): once a package, no address, that part's name the selector, the number of relationships `detail`.
516
+ */
517
+ static readonly PACKAGE_MULTIPLE_MAIN_PARTS = "package.multiple_main_parts";
518
+ /**
519
+ * An `External` officeDocument relationship beside an internal one, dropped under `repair: 'all'`, a repair of this package's
520
+ * own (REQ-206's NOTE, CR-031): once a package, no address, the part read the selector, the first URL as written `detail`.
521
+ */
522
+ static readonly PACKAGE_EXTERNAL_MAIN_PART = "package.external_main_part";
523
+ /**
524
+ * A relationships part in a wrong namespace, read by local name under `repair: 'word'` (REQ-801's NOTE, CR-031 section 2.3):
525
+ * once a part, no address, the relationships part's name the selector, the relationships read `detail`.
526
+ */
527
+ static readonly PACKAGE_RELATIONSHIPS_NAMESPACE = "package.relationships_namespace";
436
528
  /** An image the `ImageDescriber` failed to describe (REQ-514). */
437
529
  static readonly IMAGE_NOT_DESCRIBED = "image.not_described";
530
+ /**
531
+ * A drop cap's frame paragraph joined to the paragraph after it, two `w:p` read as one (REQ-521): at the frame paragraph's
532
+ * address (CR-012 section 24.3).
533
+ */
534
+ static readonly DROP_CAP_JOINED = "paragraph.drop_cap_joined";
438
535
  constructor(kind: string,
439
536
  /** The address of the block it is in (REQ-518's grammar), or undefined. */
440
537
  address?: string | undefined,
@@ -442,9 +539,24 @@ export declare class TextWarning {
442
539
  branch?: string | undefined,
443
540
  /** For `altchunk.not_expanded`, the chunk's content type as the package declares it. */
444
541
  contentType?: string | undefined,
445
- /** For `content.not_read` and `image.not_described`, the part's name. */
446
- partName?: string | undefined);
447
- /** The selector of REQ-801: the branch, the content type or the part's name, whichever the kind has. */
542
+ /**
543
+ * For `content.not_read`, `part.not_read` and `part.absent`, the part's name; for `image.not_described`, the image part's; for `altchunk.not_expanded`,
544
+ * the chunk's (`/word/afchunk.rtf`), so that a host can read it itself; for `paragraph.drop_cap_joined`, the part the
545
+ * paragraphs are in (`/word/document.xml`); for `package.multiple_main_parts` and `package.external_main_part`, the part
546
+ * read; for `package.relationships_namespace`, the relationships part; for `mce.nothing_selected`,
547
+ * the part holding the element.
548
+ */
549
+ partName?: string | undefined,
550
+ /**
551
+ * What the kind says beyond its selector (REQ-801's `detail`): for `package.duplicate_entry`, the entries of the name; for
552
+ * `package.multiple_main_parts`, the relationships; for `package.external_main_part`, the first URL as written; for
553
+ * `package.relationships_namespace`, the relationships read; for `mce.nothing_selected`, the namespaces required.
554
+ */
555
+ detail?: (number | string) | undefined);
556
+ /**
557
+ * The selector of REQ-801: the branch, else the part's name, else the content type (a warning made without a part
558
+ * name). `altchunk.not_expanded`'s is its part name since CR-012 section 22.2 (a) (WD 0.47), its content type before.
559
+ */
448
560
  get selector(): string | undefined;
449
561
  /** The identity a result keeps each warning once by. */
450
562
  get key(): string;
@@ -464,7 +576,7 @@ export declare class TextResult {
464
576
  /** The warnings raised (REQ-801), never with the document's text (REQ-802). */
465
577
  readonly warnings: readonly TextWarning[];
466
578
  /**
467
- * The result's metadata (REQ-801, REQ-515), whatever the options: `fields_update_on_open`, and the
579
+ * The result's metadata (REQ-801, REQ-515), whatever the options: `fields_update_on_open`, `repaired` (REQ-207), and the
468
580
  * document properties under `core`, `app` and `custom`, each a record, present when the package has
469
581
  * that part. Property values are document text, in the text stream only under `metadata: true`.
470
582
  */
@@ -473,6 +585,11 @@ export declare class TextResult {
473
585
  readonly options: TextOptions;
474
586
  /** The metadata's key for the settings' `w:updateFields` (REQ-506, REQ-801): a boolean. */
475
587
  static readonly FIELDS_UPDATE_ON_OPEN = "fields_update_on_open";
588
+ /**
589
+ * The metadata's key for what the load repaired (REQ-207, REQ-801; CR-031): `none`, `word` where only Word's repairs were
590
+ * followed, `own` where a repair of this package's own was made. docx4j `TextResult.REPAIRED`.
591
+ */
592
+ static readonly REPAIRED = "repaired";
476
593
  /** The metadata's key for the core properties (REQ-515): each property's element name to its value. */
477
594
  static readonly CORE = "core";
478
595
  /** The metadata's key for the application properties (REQ-515), the statistics left out. */
@@ -487,7 +604,7 @@ export declare class TextResult {
487
604
  /** The warnings raised (REQ-801), never with the document's text (REQ-802). */
488
605
  warnings: readonly TextWarning[],
489
606
  /**
490
- * The result's metadata (REQ-801, REQ-515), whatever the options: `fields_update_on_open`, and the
607
+ * The result's metadata (REQ-801, REQ-515), whatever the options: `fields_update_on_open`, `repaired` (REQ-207), and the
491
608
  * document properties under `core`, `app` and `custom`, each a record, present when the package has
492
609
  * that part. Property values are document text, in the text stream only under `metadata: true`.
493
610
  */
@@ -130,10 +130,26 @@ export class TextRun {
130
130
  this.bold = false;
131
131
  /** Italic where its paragraph's style is not. */
132
132
  this.italic = false;
133
- /** Struck through where its paragraph's style is not. */
133
+ /** Struck through where its paragraph's style is not: `w:strike`, or `w:dstrike`, struck twice (CR-012 section 24.5). */
134
134
  this.strike = false;
135
135
  /** In a monospaced font where its paragraph's style is not in one. */
136
136
  this.monospace = false;
137
+ /**
138
+ * Shown in capitals (`w:caps`): the run's own property, else its styles', the paragraph style's among them (the case is
139
+ * the text's, not emphasis). `text` stays the stored characters; the plain-text and Markdown writers write them in
140
+ * capitals by `language` (`CaseMapping`; WD REQ-607, CR-012 section 24).
141
+ */
142
+ this.caps = false;
143
+ /**
144
+ * In small capitals (`w:smallCaps`), folded as `caps` is, and not caps: a run under both is a caps run. The writers write
145
+ * its stored characters, unless `small_caps: upper` is set (WD REQ-607).
146
+ */
147
+ this.smallCaps = false;
148
+ /**
149
+ * The text's `w:vertAlign`, the run's own, else its styles' (WD REQ-710); `BASELINE` for a note reference, which is a
150
+ * reference (REQ-503), not a superscript.
151
+ */
152
+ this.verticalAlignment = 'BASELINE';
137
153
  /** True for an equation (REQ-604). */
138
154
  this.math = false;
139
155
  /** True for a display equation (`m:oMathPara`). */
@@ -152,6 +168,8 @@ export class TextRun {
152
168
  /** Whether two runs' text can be one run: the same formatting, link and equation. */
153
169
  sameFormat(o) {
154
170
  return this.bold === o.bold && this.italic === o.italic && this.strike === o.strike && this.monospace === o.monospace
171
+ && this.caps === o.caps && this.smallCaps === o.smallCaps && this.verticalAlignment === o.verticalAlignment
172
+ && this.language === o.language
155
173
  && this.link === o.link && this.math === o.math && this.displayMath === o.displayMath;
156
174
  }
157
175
  copyFormat(from) {
@@ -159,6 +177,10 @@ export class TextRun {
159
177
  this.italic = from.italic;
160
178
  this.strike = from.strike;
161
179
  this.monospace = from.monospace;
180
+ this.caps = from.caps;
181
+ this.smallCaps = from.smallCaps;
182
+ this.verticalAlignment = from.verticalAlignment;
183
+ this.language = from.language;
162
184
  this.link = from.link;
163
185
  this.math = from.math;
164
186
  this.displayMath = from.displayMath;
@@ -351,6 +373,10 @@ export class TextBlock {
351
373
  * rows a line apart, their cells a tab apart. No list label, note number or comment.
352
374
  */
353
375
  get text() {
376
+ return this.textWith((r) => r.text);
377
+ }
378
+ /** `text` with each text run's text as the function gives it (`CaseMapping.written`). */
379
+ textWith(runText) {
354
380
  var _a;
355
381
  if (this.kind === 'CHART') {
356
382
  let out = (_a = this.chartTitle) !== null && _a !== void 0 ? _a : '';
@@ -361,12 +387,12 @@ export class TextBlock {
361
387
  return out;
362
388
  }
363
389
  if (this.kind === 'TABLE') {
364
- return this.rows.map((row) => row.cells.map((cell) => cell.blocks.map((b) => b.text).join(' ')).join('\t')).join('\n');
390
+ return this.rows.map((row) => row.cells.map((cell) => cell.blocks.map((b) => b.textWith(runText)).join(' ')).join('\t')).join('\n');
365
391
  }
366
392
  let out = '';
367
393
  for (const r of this.runs)
368
394
  if (r.kind === 'TEXT' || r.kind === 'FIELD_CODE')
369
- out += r.text;
395
+ out += runText(r);
370
396
  return out;
371
397
  }
372
398
  /** The block model's JSON (REQ-706): the fields, the text and the flags; never a tree object. */
@@ -408,8 +434,10 @@ export class TextComment {
408
434
  /**
409
435
  * Where a result is not the whole document (WD section 8, REQ-801): a kind, the address it is at where
410
436
  * there is one, and its selector: for `mce.branches_differ` the name of the branch selected, for
411
- * `altchunk.not_expanded` the chunk's content type, for `content.not_read` and `image.not_described` the
412
- * part's name. Never the document's text (REQ-802). docx4j `TextWarning`.
437
+ * `altchunk.not_expanded`, `content.not_read` and `image.not_described` the part's name (the chunk's since
438
+ * CR-012 section 22.2 (a), WD 0.47; it was the chunk's content type, which the warning still carries), for
439
+ * `paragraph.drop_cap_joined` the name of the part the paragraphs are in. Never the document's text (REQ-802).
440
+ * docx4j `TextWarning`.
413
441
  */
414
442
  export class TextWarning {
415
443
  constructor(kind,
@@ -419,25 +447,41 @@ export class TextWarning {
419
447
  branch,
420
448
  /** For `altchunk.not_expanded`, the chunk's content type as the package declares it. */
421
449
  contentType,
422
- /** For `content.not_read` and `image.not_described`, the part's name. */
423
- partName) {
450
+ /**
451
+ * For `content.not_read`, `part.not_read` and `part.absent`, the part's name; for `image.not_described`, the image part's; for `altchunk.not_expanded`,
452
+ * the chunk's (`/word/afchunk.rtf`), so that a host can read it itself; for `paragraph.drop_cap_joined`, the part the
453
+ * paragraphs are in (`/word/document.xml`); for `package.multiple_main_parts` and `package.external_main_part`, the part
454
+ * read; for `package.relationships_namespace`, the relationships part; for `mce.nothing_selected`,
455
+ * the part holding the element.
456
+ */
457
+ partName,
458
+ /**
459
+ * What the kind says beyond its selector (REQ-801's `detail`): for `package.duplicate_entry`, the entries of the name; for
460
+ * `package.multiple_main_parts`, the relationships; for `package.external_main_part`, the first URL as written; for
461
+ * `package.relationships_namespace`, the relationships read; for `mce.nothing_selected`, the namespaces required.
462
+ */
463
+ detail) {
424
464
  this.kind = kind;
425
465
  this.address = address;
426
466
  this.branch = branch;
427
467
  this.contentType = contentType;
428
468
  this.partName = partName;
469
+ this.detail = detail;
429
470
  }
430
- /** The selector of REQ-801: the branch, the content type or the part's name, whichever the kind has. */
471
+ /**
472
+ * The selector of REQ-801: the branch, else the part's name, else the content type (a warning made without a part
473
+ * name). `altchunk.not_expanded`'s is its part name since CR-012 section 22.2 (a) (WD 0.47), its content type before.
474
+ */
431
475
  get selector() {
432
476
  var _a, _b;
433
- return (_b = (_a = this.branch) !== null && _a !== void 0 ? _a : this.contentType) !== null && _b !== void 0 ? _b : this.partName;
477
+ return (_b = (_a = this.branch) !== null && _a !== void 0 ? _a : this.partName) !== null && _b !== void 0 ? _b : this.contentType;
434
478
  }
435
479
  /** The identity a result keeps each warning once by. */
436
480
  get key() {
437
- return [this.kind, this.address, this.branch, this.contentType, this.partName].map((v) => v !== null && v !== void 0 ? v : '\u0000').join('\u0001');
481
+ return [this.kind, this.address, this.branch, this.contentType, this.partName, this.detail].map((v) => v !== null && v !== void 0 ? v : '\u0000').join('\u0001');
438
482
  }
439
483
  toJSON() {
440
- return { kind: this.kind, address: this.address, selector: this.selector };
484
+ return { kind: this.kind, address: this.address, selector: this.selector, ...(this.detail === undefined ? {} : { detail: this.detail }) };
441
485
  }
442
486
  toString() {
443
487
  return this.kind + (this.address === undefined ? '' : ` at ${this.address}`) + (this.branch === undefined ? '' : ` (${this.branch})`)
@@ -446,6 +490,22 @@ export class TextWarning {
446
490
  }
447
491
  /** Both branches of an `mc:AlternateContent` hold text, and the texts differ (REQ-307). */
448
492
  TextWarning.MCE_BRANCHES_DIFFER = 'mce.branches_differ';
493
+ /**
494
+ * An `mc:AlternateContent` with Choices, none understood, and no Fallback, so it reads as absent (REQ-305): at its address,
495
+ * or with none where the walk can't meet it (a resolved load took it out, or it is a part's root). The part's name is the
496
+ * selector, and `detail` the namespaces its Choices require, as one string of URIs, empty if every prefix binds to nothing.
497
+ */
498
+ TextWarning.MCE_NOTHING_SELECTED = 'mce.nothing_selected';
499
+ /**
500
+ * An `mc:Ignorable` listing a prefix no declaration in scope binds, read as though the list didn't hold it (REQ-323, CR-030):
501
+ * once a part the reading took, no address, the part's name the selector and `detail` the prefixes, separated by spaces.
502
+ */
503
+ TextWarning.MCE_UNDECLARED_PREFIX = 'mce.undeclared_prefix';
504
+ /**
505
+ * A main document part whose root Word opens showing nothing of, read as an empty document (REQ-320, CR-028 D11): once, no
506
+ * address, the part's name the selector and `detail` the root's qualified name.
507
+ */
508
+ TextWarning.PART_UNEXPECTED_ROOT = 'part.unexpected_root';
449
509
  /** A field with no cached result (REQ-505). */
450
510
  TextWarning.FIELD_NO_RESULT = 'field.no_result';
451
511
  /** A data-bound control whose surface differs from its bound value (REQ-509). */
@@ -454,8 +514,46 @@ TextWarning.SDT_BINDING_DIFFERS = 'sdt.binding_differs';
454
514
  TextWarning.ALTCHUNK_NOT_EXPANDED = 'altchunk.not_expanded';
455
515
  /** A chart, a SmartArt data part, or an embedded package or a part inside it, that can't be read. */
456
516
  TextWarning.CONTENT_NOT_READ = 'content.not_read';
517
+ /**
518
+ * A part the reading consulted and needed for this document, but does not emit, that cannot be read (REQ-801, WD 0.66):
519
+ * a styles, numbering or settings part, a document-properties part where the metadata is written, or a custom XML store
520
+ * a binding names. The reading proceeds as for a package that lacks it; once per part, no address, the part's name the
521
+ * selector (CR-012 section 28).
522
+ */
523
+ TextWarning.PART_NOT_READ = 'part.not_read';
524
+ /**
525
+ * A part the reading needed that the package does not hold, where the reading supplies what it would have: the numbering
526
+ * part, for a numbered paragraph, counted as Word's default definition (REQ-510, WD 0.76). Once, no address, the name the
527
+ * package would have held the part under (`/word/numbering.xml`) the selector.
528
+ */
529
+ TextWarning.PART_ABSENT = 'part.absent';
530
+ /**
531
+ * A name the package's container holds more than one entry of, read from the first under `repair: 'word'`
532
+ * (REQ-206, CR-024): no address, the entry as its first copy spells it the selector, the number of entries `detail`.
533
+ */
534
+ TextWarning.PACKAGE_DUPLICATE_ENTRY = 'package.duplicate_entry';
535
+ /**
536
+ * A package with more than one officeDocument relationship, the last's target read under `repair: 'word'`
537
+ * (REQ-206's statement, CR-024 section 9): once a package, no address, that part's name the selector, the number of relationships `detail`.
538
+ */
539
+ TextWarning.PACKAGE_MULTIPLE_MAIN_PARTS = 'package.multiple_main_parts';
540
+ /**
541
+ * An `External` officeDocument relationship beside an internal one, dropped under `repair: 'all'`, a repair of this package's
542
+ * own (REQ-206's NOTE, CR-031): once a package, no address, the part read the selector, the first URL as written `detail`.
543
+ */
544
+ TextWarning.PACKAGE_EXTERNAL_MAIN_PART = 'package.external_main_part';
545
+ /**
546
+ * A relationships part in a wrong namespace, read by local name under `repair: 'word'` (REQ-801's NOTE, CR-031 section 2.3):
547
+ * once a part, no address, the relationships part's name the selector, the relationships read `detail`.
548
+ */
549
+ TextWarning.PACKAGE_RELATIONSHIPS_NAMESPACE = 'package.relationships_namespace';
457
550
  /** An image the `ImageDescriber` failed to describe (REQ-514). */
458
551
  TextWarning.IMAGE_NOT_DESCRIBED = 'image.not_described';
552
+ /**
553
+ * A drop cap's frame paragraph joined to the paragraph after it, two `w:p` read as one (REQ-521): at the frame paragraph's
554
+ * address (CR-012 section 24.3).
555
+ */
556
+ TextWarning.DROP_CAP_JOINED = 'paragraph.drop_cap_joined';
459
557
  /**
460
558
  * A text in the block model (WD sections 7.4 and 8): the blocks in reading order, the comments, the
461
559
  * warnings and the metadata. Plain text (`PlainText`) and the other serialisations are written from it
@@ -470,7 +568,7 @@ export class TextResult {
470
568
  /** The warnings raised (REQ-801), never with the document's text (REQ-802). */
471
569
  warnings,
472
570
  /**
473
- * The result's metadata (REQ-801, REQ-515), whatever the options: `fields_update_on_open`, and the
571
+ * The result's metadata (REQ-801, REQ-515), whatever the options: `fields_update_on_open`, `repaired` (REQ-207), and the
474
572
  * document properties under `core`, `app` and `custom`, each a record, present when the package has
475
573
  * that part. Property values are document text, in the text stream only under `metadata: true`.
476
574
  */
@@ -518,6 +616,11 @@ export class TextResult {
518
616
  }
519
617
  /** The metadata's key for the settings' `w:updateFields` (REQ-506, REQ-801): a boolean. */
520
618
  TextResult.FIELDS_UPDATE_ON_OPEN = 'fields_update_on_open';
619
+ /**
620
+ * The metadata's key for what the load repaired (REQ-207, REQ-801; CR-031): `none`, `word` where only Word's repairs were
621
+ * followed, `own` where a repair of this package's own was made. docx4j `TextResult.REPAIRED`.
622
+ */
623
+ TextResult.REPAIRED = 'repaired';
521
624
  /** The metadata's key for the core properties (REQ-515): each property's element name to its value. */
522
625
  TextResult.CORE = 'core';
523
626
  /** The metadata's key for the application properties (REQ-515), the statistics left out. */
@@ -1,5 +1,6 @@
1
1
  import { log } from '../properties/log.mjs';
2
2
  import { LinkTargets } from './LinkTargets.mjs';
3
+ import { CaseMapping } from './CaseMapping.mjs';
3
4
  import { MdDocument, MdParagraph, MdHeading, MdBlockQuote, MdBulletList, MdOrderedList, MdListItem, MdFencedCodeBlock, MdThematicBreak, MdHtmlInline, MdText, MdCode, MdEmphasis, MdStrongEmphasis, MdLink, MdImage, MdHardLineBreak, MdTableBlock, MdTableHead, MdTableBody, MdTableRow, MdTableCell, MdStrikethrough, MdFootnoteDefinition, MdFootnoteReference, MdInlineMath, MdDisplayMath, } from './commonmark.mjs';
4
5
  const TWIPS_PER_LEVEL = 720;
5
6
  /** The paragraph styles docx4j's importer writes, which the export reads back (docx4j `ImportStyles`). */
@@ -209,7 +210,9 @@ export class WmlToMarkdown {
209
210
  out += this.open(revision);
210
211
  for (let k = i; k < j; k++) {
211
212
  const r = runs[k];
212
- if (r.kind === 'TEXT' || r.kind === 'FIELD_CODE')
213
+ if (r.kind === 'TEXT')
214
+ out += CaseMapping.written(r, this.textOptions);
215
+ else if (r.kind === 'FIELD_CODE')
213
216
  out += r.text;
214
217
  }
215
218
  if (revision !== undefined)
@@ -605,7 +608,7 @@ export class WmlToMarkdown {
605
608
  }
606
609
  }
607
610
  text(run, sink) {
608
- const value = run.text;
611
+ const value = CaseMapping.written(run, this.textOptions); // w:caps in capitals, by the run's language (REQ-607)
609
612
  if (value === '')
610
613
  return;
611
614
  if (run.math) {
@@ -623,17 +626,23 @@ export class WmlToMarkdown {
623
626
  if (line === '')
624
627
  continue;
625
628
  if (run.monospace) {
629
+ // the tags around the code span, not in it, where they would be its text
630
+ const t = tag(run.verticalAlignment);
631
+ if (t !== undefined)
632
+ sink.node(new MdHtmlInline(`<${t}>`));
626
633
  sink.node(new MdCode(line));
634
+ if (t !== undefined)
635
+ sink.node(new MdHtmlInline(`</${t}>`));
627
636
  }
628
637
  else {
629
- sink.text(line, bold, run.italic, run.strike);
638
+ sink.text(line, bold, run.italic, run.strike, run.verticalAlignment);
630
639
  }
631
640
  }
632
641
  }
633
642
  comment(comment, sink) {
634
643
  sink.node(new MdHtmlInline('{>>'));
635
644
  this.detailText(comment.author, comment.date, sink);
636
- sink.text(comment.text, false, false, false);
645
+ sink.text(CaseMapping.written(comment, this.textOptions), false, false, false);
637
646
  sink.node(new MdHtmlInline('<<}'));
638
647
  }
639
648
  /** Runs under one marker: the same type, and the same author and date where the detail shows them. */
@@ -670,7 +679,7 @@ export class WmlToMarkdown {
670
679
  detail(author, date) {
671
680
  switch (this.textOptions.markupDetail) {
672
681
  case 'author': return `${author !== null && author !== void 0 ? author : ''}: `;
673
- case 'author_date': return `${author !== null && author !== void 0 ? author : ''}, ${date !== null && date !== void 0 ? date : ''}: `;
682
+ case 'author_date': return `${author !== null && author !== void 0 ? author : ''}${date === undefined ? '' : `, ${date}`}: `; // a mark with no date: its author alone (REQ-702)
674
683
  default: return '';
675
684
  }
676
685
  }
@@ -691,6 +700,14 @@ function tagged(node, block) {
691
700
  node.tag = block;
692
701
  return node;
693
702
  }
703
+ /**
704
+ * The inline HTML a raised or lowered run is written in, `sup` or `sub`, never a Unicode superscript or subscript
705
+ * character (WD REQ-710; docx4j CR-069 phase 3, CR-012 section 24.4); undefined on the baseline. The tags are the
706
+ * writer's: document text can't form them, the renderer escaping its `<`.
707
+ */
708
+ function tag(vertical) {
709
+ return vertical === 'SUPERSCRIPT' ? 'sup' : vertical === 'SUBSCRIPT' ? 'sub' : undefined;
710
+ }
694
711
  /** Accumulates same-formatted text, wrapping it on flush. */
695
712
  class InlineSink {
696
713
  constructor(parent) {
@@ -699,13 +716,15 @@ class InlineSink {
699
716
  this.bold = false;
700
717
  this.italic = false;
701
718
  this.strike = false;
719
+ this.vertical = 'BASELINE';
702
720
  }
703
- text(s, b, i, st) {
704
- if ((b !== this.bold || i !== this.italic || st !== this.strike) && this.buf.length > 0)
721
+ text(s, b, i, st, v = 'BASELINE') {
722
+ if ((b !== this.bold || i !== this.italic || st !== this.strike || v !== this.vertical) && this.buf.length > 0)
705
723
  this.flush();
706
724
  this.bold = b;
707
725
  this.italic = i;
708
726
  this.strike = st;
727
+ this.vertical = v;
709
728
  this.buf += s;
710
729
  }
711
730
  node(n) {
@@ -732,7 +751,13 @@ class InlineSink {
732
751
  st.appendChild(n);
733
752
  n = st;
734
753
  }
754
+ // the tags outside the emphasis: 48,210<sup>**3**</sup>, where a ** after the digit, before the tag, would not open
755
+ const t = tag(this.vertical);
756
+ if (t !== undefined)
757
+ this.parent.appendChild(new MdHtmlInline(`<${t}>`));
735
758
  this.parent.appendChild(n);
759
+ if (t !== undefined)
760
+ this.parent.appendChild(new MdHtmlInline(`</${t}>`));
736
761
  this.buf = '';
737
762
  }
738
763
  }
@@ -0,0 +1,7 @@
1
+ /** The Unicode version of the table: a later case pair is unmapped until the table is regenerated (WD 0.52's REQ-607). */
2
+ export declare const CASE_MAPPING_UNICODE_VERSION = "15.0.0";
3
+ /**
4
+ * Runs of code points mapped by one delta: `start, end, delta, stride` each, by `start`; `end` is the run's last code
5
+ * point, and every `stride`th code point from `start` to it maps to itself plus `delta`.
6
+ */
7
+ export declare const UPPERCASE_RUNS: readonly number[];