@docx4j/core-ts 0.5.0 → 0.6.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 (155) hide show
  1. package/NOTICE +4 -0
  2. package/README.md +32 -4
  3. package/dist/html/convert.mjs +2 -1
  4. package/dist/html/elements.mjs +2 -1
  5. package/dist/model/color/ColorMath.d.mts +29 -0
  6. package/dist/model/color/ColorMath.mjs +146 -0
  7. package/dist/model/color/ColorTables.d.mts +6 -0
  8. package/dist/model/color/ColorTables.mjs +83 -0
  9. package/dist/model/color/DrawingMLColors.d.mts +52 -0
  10. package/dist/model/color/DrawingMLColors.mjs +374 -0
  11. package/dist/model/color/ResolvedColor.d.mts +36 -0
  12. package/dist/model/color/ResolvedColor.mjs +65 -0
  13. package/dist/model/color/SpreadsheetColors.d.mts +36 -0
  14. package/dist/model/color/SpreadsheetColors.mjs +84 -0
  15. package/dist/model/color/StyleFill.d.mts +28 -0
  16. package/dist/model/color/StyleFill.mjs +21 -0
  17. package/dist/model/color/ThemeColors.d.mts +86 -0
  18. package/dist/model/color/ThemeColors.mjs +304 -0
  19. package/dist/model/color/WordColors.d.mts +71 -0
  20. package/dist/model/color/WordColors.mjs +121 -0
  21. package/dist/model/color/index.d.mts +6 -0
  22. package/dist/model/color/index.mjs +30 -0
  23. package/dist/model/content/Body.d.mts +145 -23
  24. package/dist/model/content/Body.mjs +509 -141
  25. package/dist/model/content/Comment.d.mts +21 -3
  26. package/dist/model/content/Comment.mjs +195 -19
  27. package/dist/model/content/ContentControl.d.mts +197 -18
  28. package/dist/model/content/ContentControl.mjs +664 -95
  29. package/dist/model/content/Font.d.mts +67 -17
  30. package/dist/model/content/Font.mjs +114 -35
  31. package/dist/model/content/InlinePicture.d.mts +11 -0
  32. package/dist/model/content/InlinePicture.mjs +21 -1
  33. package/dist/model/content/List.mjs +3 -0
  34. package/dist/model/content/Paragraph.d.mts +189 -13
  35. package/dist/model/content/Paragraph.mjs +870 -74
  36. package/dist/model/content/Range.d.mts +227 -12
  37. package/dist/model/content/Range.mjs +785 -59
  38. package/dist/model/content/ResolvedView.d.mts +104 -0
  39. package/dist/model/content/ResolvedView.mjs +596 -0
  40. package/dist/model/content/Table.d.mts +29 -3
  41. package/dist/model/content/Table.mjs +109 -33
  42. package/dist/model/content/TrackedChange.d.mts +172 -13
  43. package/dist/model/content/TrackedChange.mjs +728 -167
  44. package/dist/model/content/comments.d.mts +20 -6
  45. package/dist/model/content/comments.mjs +67 -57
  46. package/dist/model/content/generalException.d.mts +18 -0
  47. package/dist/model/content/generalException.mjs +24 -0
  48. package/dist/model/content/index.d.mts +8 -3
  49. package/dist/model/content/index.mjs +7 -2
  50. package/dist/model/content/mathText.d.mts +21 -0
  51. package/dist/model/content/mathText.mjs +267 -0
  52. package/dist/model/content/officeText.d.mts +27 -0
  53. package/dist/model/content/officeText.mjs +74 -0
  54. package/dist/model/content/outline.d.mts +5 -0
  55. package/dist/model/content/outline.mjs +13 -0
  56. package/dist/model/content/placeholders.d.mts +110 -0
  57. package/dist/model/content/placeholders.mjs +253 -0
  58. package/dist/model/content/search.d.mts +72 -0
  59. package/dist/model/content/search.mjs +204 -2
  60. package/dist/model/content/spanEdits.d.mts +159 -0
  61. package/dist/model/content/spanEdits.mjs +728 -0
  62. package/dist/model/content/story.d.mts +44 -0
  63. package/dist/model/content/story.mjs +92 -0
  64. package/dist/model/content/tableColumns.d.mts +1 -1
  65. package/dist/model/content/tableColumns.mjs +108 -80
  66. package/dist/model/content/tableRevisions.d.mts +11 -3
  67. package/dist/model/content/tableRevisions.mjs +72 -42
  68. package/dist/model/content/tableRules.d.mts +30 -0
  69. package/dist/model/content/tableRules.mjs +100 -0
  70. package/dist/model/content/textBoxes.d.mts +18 -0
  71. package/dist/model/content/textBoxes.mjs +105 -0
  72. package/dist/model/content/trackedChangeFilter.d.mts +39 -0
  73. package/dist/model/content/trackedChangeFilter.mjs +81 -0
  74. package/dist/model/content/tracking.d.mts +28 -0
  75. package/dist/model/content/tracking.mjs +149 -10
  76. package/dist/model/content/tree.d.mts +171 -22
  77. package/dist/model/content/tree.mjs +329 -53
  78. package/dist/model/customxml/CustomXmlPartCollection.d.mts +8 -0
  79. package/dist/model/customxml/CustomXmlPartCollection.mjs +34 -11
  80. package/dist/model/customxml/XmlMapping.d.mts +1 -1
  81. package/dist/model/customxml/XmlMapping.mjs +11 -0
  82. package/dist/model/customxml/bindings.d.mts +21 -2
  83. package/dist/model/customxml/bindings.mjs +76 -32
  84. package/dist/model/customxml/kinds.d.mts +8 -3
  85. package/dist/model/customxml/kinds.mjs +26 -5
  86. package/dist/model/customxml/picturePlaceholder.d.mts +17 -0
  87. package/dist/model/customxml/picturePlaceholder.mjs +32 -0
  88. package/dist/model/customxml/pictures.d.mts +4 -3
  89. package/dist/model/customxml/pictures.mjs +18 -6
  90. package/dist/model/customxml/xhtml.mjs +8 -2
  91. package/dist/model/index.d.mts +2 -0
  92. package/dist/model/index.mjs +4 -0
  93. package/dist/model/listnumbering/Emulator.d.mts +37 -5
  94. package/dist/model/listnumbering/Emulator.mjs +63 -9
  95. package/dist/model/properties/PropertyResolver.d.mts +60 -1
  96. package/dist/model/properties/PropertyResolver.mjs +115 -2
  97. package/dist/model/properties/catalogue.d.mts +19 -5
  98. package/dist/model/properties/catalogue.mjs +41 -15
  99. package/dist/model/properties/log.d.mts +1 -1
  100. package/dist/model/properties/log.mjs +5 -5
  101. package/dist/model/properties/table.mjs +4 -2
  102. package/dist/model/text/Extractor.d.mts +289 -0
  103. package/dist/model/text/Extractor.mjs +2162 -0
  104. package/dist/model/text/LinkTargets.d.mts +45 -0
  105. package/dist/model/text/LinkTargets.mjs +170 -0
  106. package/dist/model/text/MarkdownExporter.d.mts +140 -0
  107. package/dist/model/text/MarkdownExporter.mjs +255 -0
  108. package/dist/model/text/PlainText.d.mts +29 -0
  109. package/dist/model/text/PlainText.mjs +539 -0
  110. package/dist/model/text/TextContext.d.mts +161 -0
  111. package/dist/model/text/TextContext.mjs +425 -0
  112. package/dist/model/text/TextOptions.d.mts +150 -0
  113. package/dist/model/text/TextOptions.mjs +278 -0
  114. package/dist/model/text/TextResult.d.mts +504 -0
  115. package/dist/model/text/TextResult.mjs +526 -0
  116. package/dist/model/text/Texts.d.mts +99 -0
  117. package/dist/model/text/Texts.mjs +187 -0
  118. package/dist/model/text/WmlToMarkdown.d.mts +120 -0
  119. package/dist/model/text/WmlToMarkdown.mjs +911 -0
  120. package/dist/model/text/commonmark.d.mts +121 -0
  121. package/dist/model/text/commonmark.mjs +655 -0
  122. package/dist/model/text/index.d.mts +7 -0
  123. package/dist/model/text/index.mjs +8 -0
  124. package/dist/model/text/normalize.d.mts +8 -0
  125. package/dist/model/text/normalize.mjs +13 -0
  126. package/dist/model/text/outline.d.mts +4 -0
  127. package/dist/model/text/outline.mjs +71 -0
  128. package/dist/office-js/fragment.d.mts +7 -5
  129. package/dist/office-js/fragment.mjs +63 -14
  130. package/dist/office-js/proxy.d.mts +8 -0
  131. package/dist/office-js/proxy.mjs +29 -0
  132. package/dist/office-js/run.mjs +2 -0
  133. package/dist/office-js/supported.generated.mjs +16 -0
  134. package/dist/office-js/toApiScript.mjs +21 -5
  135. package/dist/opc/Save.d.mts +17 -0
  136. package/dist/opc/Save.mjs +12 -2
  137. package/dist/opc/index.d.mts +3 -3
  138. package/dist/opc/index.mjs +1 -1
  139. package/dist/opc/mce/preprocessor.d.mts +28 -3
  140. package/dist/opc/mce/preprocessor.mjs +4 -4
  141. package/dist/opc/mce/understood.d.mts +30 -6
  142. package/dist/opc/mce/understood.mjs +37 -7
  143. package/dist/packages/OpcPackage.d.mts +13 -0
  144. package/dist/packages/OpcPackage.mjs +1 -0
  145. package/dist/packages/WordprocessingMLPackage.d.mts +45 -8
  146. package/dist/packages/WordprocessingMLPackage.mjs +155 -20
  147. package/dist/parts/DefaultXmlPart.mjs +2 -2
  148. package/dist/parts/Part.d.mts +10 -2
  149. package/dist/parts/XmlPart.d.mts +12 -30
  150. package/dist/parts/XmlPart.mjs +44 -93
  151. package/dist/parts/wml/comments.mjs +30 -0
  152. package/dist/parts/wml/index.mjs +12 -0
  153. package/dist/xml/dom.d.mts +7 -0
  154. package/dist/xml/dom.mjs +18 -0
  155. package/package.json +2 -2
@@ -0,0 +1,150 @@
1
+ import { Docx4JException } from '../../opc/exceptions.mjs';
2
+ import type { ImageDescriber } from './TextResult.mjs';
3
+ /**
4
+ * The three revision views (WD section 4, REQ-401): the document as Word's Accept All leaves it, as
5
+ * Reject All leaves it, and every run as the package holds it, insertions and deletions marked.
6
+ * `current` is accepted as a synonym of `accepted` (WD section 4.1's note). docx4j's `TextView`, by
7
+ * another name: the content API's `TextView` (CR-002 phase F) is `getText`'s two views.
8
+ */
9
+ export type TextModelView = 'accepted' | 'original' | 'markup';
10
+ /** The stories `include` adds (REQ-501, REQ-502). */
11
+ export type TextInclude = 'headers' | 'footers' | 'comments' | 'glossary';
12
+ /** `fields` (REQ-506). */
13
+ export type TextFields = 'cached' | 'update';
14
+ /** `bindings` (REQ-509). */
15
+ export type TextBindings = 'bound' | 'surface';
16
+ /** `symbols` (REQ-601). */
17
+ export type TextSymbols = 'asis' | 'unicode';
18
+ /** `math` (REQ-604). */
19
+ export type TextMath = 'latex' | 'unicodemath';
20
+ /** `tables` (REQ-605). */
21
+ export type TextTables = 'auto' | 'tsv' | 'grid';
22
+ /** `markup_detail` (REQ-702). */
23
+ export type TextMarkupDetail = 'type' | 'author' | 'author_date';
24
+ /** `layout` (REQ-709). */
25
+ export type TextLayout = 'none' | 'indent';
26
+ /** A boolean option's value: a boolean, or `"true"` / `"false"` as a tool passes it. */
27
+ type Bool = boolean | 'true' | 'false';
28
+ /**
29
+ * The options by the specification's names (WD section 10), every one optional, each absent one at its
30
+ * default. `include` takes a list of story names or a string of them separated by commas or spaces;
31
+ * a boolean takes `"true"` or `"false"` as well; any other value is its name, in any case.
32
+ * `imageDescriber` is the host's (REQ-514), not one of the specification's options.
33
+ */
34
+ export interface TextOptionsInit {
35
+ view?: TextModelView | 'current';
36
+ include?: readonly TextInclude[] | string;
37
+ text_boxes?: Bool;
38
+ notes?: Bool;
39
+ note_references?: Bool;
40
+ comments?: Bool;
41
+ hidden?: Bool;
42
+ field_codes?: Bool;
43
+ fields?: TextFields;
44
+ toc?: Bool;
45
+ placeholders?: Bool;
46
+ bindings?: TextBindings;
47
+ list_labels?: Bool;
48
+ charts?: Bool;
49
+ smartart?: Bool;
50
+ embedded?: Bool;
51
+ altchunks?: Bool;
52
+ alt_text?: Bool;
53
+ metadata?: Bool;
54
+ symbols?: TextSymbols;
55
+ math?: TextMath;
56
+ tables?: TextTables;
57
+ markup_detail?: TextMarkupDetail;
58
+ page_markers?: Bool;
59
+ layout?: TextLayout;
60
+ warnings?: Bool;
61
+ /** The describer images take their text from (REQ-514); `AltTextDescriber` by default. */
62
+ imageDescriber?: ImageDescriber;
63
+ }
64
+ /**
65
+ * An option refused (REQ-1001): an unknown name, a value the specification does not define, or a
66
+ * value this package does not implement yet. `statement` names the requirement, `option` the option.
67
+ */
68
+ export declare class TextOptionError extends Docx4JException {
69
+ readonly option: string;
70
+ readonly statement: string;
71
+ readonly reason: 'unknown' | 'invalid' | 'not_implemented';
72
+ constructor(message: string, option: string, statement: string, reason: 'unknown' | 'invalid' | 'not_implemented');
73
+ }
74
+ /** The option names of WD section 10, in its order. docx4j `TextOptions.NAMES`. */
75
+ export declare const TEXT_OPTION_NAMES: readonly string[];
76
+ /**
77
+ * What a text includes and how it is written: the specification's section 10 options (REQ-1001), as
78
+ * docx4j's `TextOptions` has them. Mutable; `Texts.of` reads it once.
79
+ *
80
+ * Every option name and value of WD section 10 is accepted by `set`. Some values are not implemented,
81
+ * and `Texts.of` refuses them with a `TextOptionError` naming the statement rather than ignoring them
82
+ * (REQ-1001): `math: unicodemath` and `symbols: unicode`, as docx4j refuses them (no converter, no glyph
83
+ * tables), and, until CR-012 phase 5, `fields: update` (REQ-506) and `embedded: true` (REQ-512). The
84
+ * defaults `charts`, `smartart` and `altchunks` are accepted, and until phase 5 a chart or SmartArt
85
+ * contributes nothing and an `altChunk` is not expanded, raising `altchunk.not_expanded` (CR-012
86
+ * section 5).
87
+ */
88
+ export declare class TextOptions {
89
+ view: TextModelView;
90
+ private readonly includeSet;
91
+ textBoxes: boolean;
92
+ notes: boolean;
93
+ noteReferences: boolean;
94
+ private commentsOption;
95
+ hidden: boolean;
96
+ fieldCodes: boolean;
97
+ fields: TextFields;
98
+ /**
99
+ * Whether a table of contents is read: false by default (WD REQ-520; docx4j CR-046 D12). A table of
100
+ * contents is the result of a TOC field; under `toc: false` nothing of the field is read, its code
101
+ * included under `field_codes`, and a paragraph with nothing else in it is no paragraph.
102
+ */
103
+ toc: boolean;
104
+ placeholders: boolean;
105
+ bindings: TextBindings;
106
+ listLabels: boolean;
107
+ charts: boolean;
108
+ smartart: boolean;
109
+ embedded: boolean;
110
+ altchunks: boolean;
111
+ altText: boolean;
112
+ metadata: boolean;
113
+ symbols: TextSymbols;
114
+ math: TextMath;
115
+ tables: TextTables;
116
+ markupDetail: TextMarkupDetail;
117
+ /**
118
+ * `page_markers` (REQ-708): `[page n]` at each `w:lastRenderedPageBreak`. The markers are where Word's
119
+ * pages began when it last laid the document out: they are current only when the package was last
120
+ * paginated (saved by Word) after its last edit, and an extractor cannot tell whether it was.
121
+ */
122
+ pageMarkers: boolean;
123
+ layout: TextLayout;
124
+ warnings: boolean;
125
+ /** The describer images take their text from (REQ-514). */
126
+ imageDescriber: ImageDescriber;
127
+ /** Options from the specification's names and values (REQ-1001); those not named keep their defaults. */
128
+ static of(init?: TextOptionsInit | TextOptions): TextOptions;
129
+ /** Sets one option by its specification name and value; throws `TextOptionError` for one it does not define. */
130
+ set(name: string, value: unknown): this;
131
+ private setInclude;
132
+ /** Adds stories to `include` (docx4j's builder `include(Include...)`). */
133
+ include(...stories: TextInclude[]): this;
134
+ /** The stories `include` names; `comments: true` adds `comments`. */
135
+ get includes(): ReadonlySet<TextInclude>;
136
+ /** `comments: true` or `include: comments`. */
137
+ get comments(): boolean;
138
+ set comments(value: boolean);
139
+ /** A copy, for a reading one level down or a first reading. */
140
+ copy(): TextOptions;
141
+ /** The options as the specification names them, with their values, in section 10's order. */
142
+ toMap(): Record<string, unknown>;
143
+ toJSON(): Record<string, unknown>;
144
+ /**
145
+ * Throws for a value this package does not honour (REQ-1001: documented, and refused rather than
146
+ * ignored): the two docx4j refuses, and the two whose statements wait on CR-012 phase 5.
147
+ */
148
+ checkImplemented(): void;
149
+ }
150
+ export {};
@@ -0,0 +1,278 @@
1
+ // CR-012 phase 2: what a text includes and how it is written, docx4j's org.docx4j.model.text.TextOptions.
2
+ // The option names are the specification's section 10 names verbatim (`note_references`, `field_codes`),
3
+ // not camelCase (CR-012 D1), so that the suite's scenarios, the editor's tools and the MCP tools pass
4
+ // options through unchanged; docx4j's `of(Map)` and `set(name, value)` take the same.
5
+ import { Docx4JException } from '../../opc/exceptions.mjs';
6
+ import { AltTextDescriber } from './TextResult.mjs';
7
+ /**
8
+ * An option refused (REQ-1001): an unknown name, a value the specification does not define, or a
9
+ * value this package does not implement yet. `statement` names the requirement, `option` the option.
10
+ */
11
+ export class TextOptionError extends Docx4JException {
12
+ constructor(message, option, statement, reason) {
13
+ super(message);
14
+ this.option = option;
15
+ this.statement = statement;
16
+ this.reason = reason;
17
+ this.name = 'TextOptionError';
18
+ }
19
+ }
20
+ /** The option names of WD section 10, in its order. docx4j `TextOptions.NAMES`. */
21
+ export const TEXT_OPTION_NAMES = Object.freeze([
22
+ 'view', 'include', 'text_boxes', 'notes', 'note_references', 'comments', 'hidden', 'field_codes',
23
+ 'fields', 'toc', 'placeholders', 'bindings', 'list_labels', 'charts', 'smartart', 'embedded', 'altchunks',
24
+ 'alt_text', 'metadata', 'symbols', 'math', 'tables', 'markup_detail', 'page_markers', 'layout',
25
+ 'warnings',
26
+ ]);
27
+ const INCLUDES = ['headers', 'footers', 'comments', 'glossary'];
28
+ /**
29
+ * What a text includes and how it is written: the specification's section 10 options (REQ-1001), as
30
+ * docx4j's `TextOptions` has them. Mutable; `Texts.of` reads it once.
31
+ *
32
+ * Every option name and value of WD section 10 is accepted by `set`. Some values are not implemented,
33
+ * and `Texts.of` refuses them with a `TextOptionError` naming the statement rather than ignoring them
34
+ * (REQ-1001): `math: unicodemath` and `symbols: unicode`, as docx4j refuses them (no converter, no glyph
35
+ * tables), and, until CR-012 phase 5, `fields: update` (REQ-506) and `embedded: true` (REQ-512). The
36
+ * defaults `charts`, `smartart` and `altchunks` are accepted, and until phase 5 a chart or SmartArt
37
+ * contributes nothing and an `altChunk` is not expanded, raising `altchunk.not_expanded` (CR-012
38
+ * section 5).
39
+ */
40
+ export class TextOptions {
41
+ constructor() {
42
+ this.view = 'accepted';
43
+ this.includeSet = new Set();
44
+ this.textBoxes = true;
45
+ this.notes = true;
46
+ this.noteReferences = true;
47
+ this.commentsOption = false;
48
+ this.hidden = false;
49
+ this.fieldCodes = false;
50
+ this.fields = 'cached';
51
+ /**
52
+ * Whether a table of contents is read: false by default (WD REQ-520; docx4j CR-046 D12). A table of
53
+ * contents is the result of a TOC field; under `toc: false` nothing of the field is read, its code
54
+ * included under `field_codes`, and a paragraph with nothing else in it is no paragraph.
55
+ */
56
+ this.toc = false;
57
+ this.placeholders = true;
58
+ this.bindings = 'bound';
59
+ this.listLabels = false;
60
+ this.charts = true;
61
+ this.smartart = true;
62
+ this.embedded = false;
63
+ this.altchunks = true;
64
+ this.altText = false;
65
+ this.metadata = false;
66
+ this.symbols = 'asis';
67
+ this.math = 'latex';
68
+ this.tables = 'auto';
69
+ this.markupDetail = 'type';
70
+ /**
71
+ * `page_markers` (REQ-708): `[page n]` at each `w:lastRenderedPageBreak`. The markers are where Word's
72
+ * pages began when it last laid the document out: they are current only when the package was last
73
+ * paginated (saved by Word) after its last edit, and an extractor cannot tell whether it was.
74
+ */
75
+ this.pageMarkers = false;
76
+ this.layout = 'none';
77
+ this.warnings = true;
78
+ /** The describer images take their text from (REQ-514). */
79
+ this.imageDescriber = AltTextDescriber.INSTANCE;
80
+ }
81
+ /** Options from the specification's names and values (REQ-1001); those not named keep their defaults. */
82
+ static of(init) {
83
+ var _a;
84
+ if (init instanceof TextOptions)
85
+ return init;
86
+ const o = new TextOptions();
87
+ if (init === undefined || init === null)
88
+ return o;
89
+ for (const [name, value] of Object.entries(init)) {
90
+ if (value === undefined)
91
+ continue;
92
+ if (name === 'imageDescriber')
93
+ o.imageDescriber = (_a = value) !== null && _a !== void 0 ? _a : AltTextDescriber.INSTANCE;
94
+ else
95
+ o.set(name, value);
96
+ }
97
+ return o;
98
+ }
99
+ /** Sets one option by its specification name and value; throws `TextOptionError` for one it does not define. */
100
+ set(name, value) {
101
+ const n = (name !== null && name !== void 0 ? name : '').trim();
102
+ switch (n) {
103
+ case 'view':
104
+ this.view = viewOf(value);
105
+ break;
106
+ case 'include':
107
+ this.setInclude(value);
108
+ break;
109
+ case 'text_boxes':
110
+ this.textBoxes = bool(n, value, 'REQ-518');
111
+ break;
112
+ case 'notes':
113
+ this.notes = bool(n, value, 'REQ-503');
114
+ break;
115
+ case 'note_references':
116
+ this.noteReferences = bool(n, value, 'REQ-503');
117
+ break;
118
+ case 'comments':
119
+ this.commentsOption = bool(n, value, 'REQ-504');
120
+ break;
121
+ case 'hidden':
122
+ this.hidden = bool(n, value, 'REQ-507');
123
+ break;
124
+ case 'field_codes':
125
+ this.fieldCodes = bool(n, value, 'REQ-505');
126
+ break;
127
+ case 'fields':
128
+ this.fields = choice(n, value, ['cached', 'update'], 'REQ-506');
129
+ break;
130
+ case 'toc':
131
+ this.toc = bool(n, value, 'REQ-520');
132
+ break;
133
+ case 'placeholders':
134
+ this.placeholders = bool(n, value, 'REQ-508');
135
+ break;
136
+ case 'bindings':
137
+ this.bindings = choice(n, value, ['bound', 'surface'], 'REQ-509');
138
+ break;
139
+ case 'list_labels':
140
+ this.listLabels = bool(n, value, 'REQ-510');
141
+ break;
142
+ case 'charts':
143
+ this.charts = bool(n, value, 'REQ-511');
144
+ break;
145
+ case 'smartart':
146
+ this.smartart = bool(n, value, 'REQ-511');
147
+ break;
148
+ case 'embedded':
149
+ this.embedded = bool(n, value, 'REQ-512');
150
+ break;
151
+ case 'altchunks':
152
+ this.altchunks = bool(n, value, 'REQ-513');
153
+ break;
154
+ case 'alt_text':
155
+ this.altText = bool(n, value, 'REQ-514');
156
+ break;
157
+ case 'metadata':
158
+ this.metadata = bool(n, value, 'REQ-515');
159
+ break;
160
+ case 'symbols':
161
+ this.symbols = choice(n, value, ['asis', 'unicode'], 'REQ-601');
162
+ break;
163
+ case 'math':
164
+ this.math = choice(n, value, ['latex', 'unicodemath'], 'REQ-604');
165
+ break;
166
+ case 'tables':
167
+ this.tables = choice(n, value, ['auto', 'tsv', 'grid'], 'REQ-605');
168
+ break;
169
+ case 'markup_detail':
170
+ this.markupDetail = choice(n, value, ['type', 'author', 'author_date'], 'REQ-702');
171
+ break;
172
+ case 'page_markers':
173
+ this.pageMarkers = bool(n, value, 'REQ-708');
174
+ break;
175
+ case 'layout':
176
+ this.layout = choice(n, value, ['none', 'indent'], 'REQ-709');
177
+ break;
178
+ case 'warnings':
179
+ this.warnings = bool(n, value, 'REQ-801');
180
+ break;
181
+ default:
182
+ throw new TextOptionError(`Unknown text option '${String(name)}'; the options are ${TEXT_OPTION_NAMES.join(', ')} (WD REQ-1001)`, String(name), 'REQ-1001', 'unknown');
183
+ }
184
+ return this;
185
+ }
186
+ setInclude(value) {
187
+ this.includeSet.clear();
188
+ const items = Array.isArray(value) ? value
189
+ : value === undefined || value === null ? [] : String(value).split(/[,\s]+/).filter((s) => s !== '');
190
+ for (const item of items)
191
+ this.includeSet.add(choice('include', item, INCLUDES, 'REQ-501'));
192
+ }
193
+ /** Adds stories to `include` (docx4j's builder `include(Include...)`). */
194
+ include(...stories) {
195
+ for (const s of stories)
196
+ this.includeSet.add(choice('include', s, INCLUDES, 'REQ-501'));
197
+ return this;
198
+ }
199
+ /** The stories `include` names; `comments: true` adds `comments`. */
200
+ get includes() {
201
+ const out = new Set(this.includeSet);
202
+ if (this.commentsOption)
203
+ out.add('comments');
204
+ return out;
205
+ }
206
+ /** `comments: true` or `include: comments`. */
207
+ get comments() {
208
+ return this.commentsOption || this.includeSet.has('comments');
209
+ }
210
+ set comments(value) {
211
+ this.commentsOption = value;
212
+ }
213
+ /** A copy, for a reading one level down or a first reading. */
214
+ copy() {
215
+ const o = new TextOptions();
216
+ Object.assign(o, this);
217
+ o.includeSet = new Set(this.includeSet);
218
+ return o;
219
+ }
220
+ /** The options as the specification names them, with their values, in section 10's order. */
221
+ toMap() {
222
+ return {
223
+ view: this.view, include: [...this.includeSet], text_boxes: this.textBoxes, notes: this.notes,
224
+ note_references: this.noteReferences, comments: this.commentsOption, hidden: this.hidden,
225
+ field_codes: this.fieldCodes, fields: this.fields, toc: this.toc, placeholders: this.placeholders,
226
+ bindings: this.bindings, list_labels: this.listLabels, charts: this.charts, smartart: this.smartart,
227
+ embedded: this.embedded, altchunks: this.altchunks, alt_text: this.altText, metadata: this.metadata,
228
+ symbols: this.symbols, math: this.math, tables: this.tables, markup_detail: this.markupDetail,
229
+ page_markers: this.pageMarkers, layout: this.layout, warnings: this.warnings,
230
+ };
231
+ }
232
+ toJSON() {
233
+ return this.toMap();
234
+ }
235
+ /**
236
+ * Throws for a value this package does not honour (REQ-1001: documented, and refused rather than
237
+ * ignored): the two docx4j refuses, and the two whose statements wait on CR-012 phase 5.
238
+ */
239
+ checkImplemented() {
240
+ if (this.math === 'unicodemath') {
241
+ throw new TextOptionError('Not implemented (WD REQ-1001): math: unicodemath (no OMML to UnicodeMath converter)', 'math', 'REQ-604', 'not_implemented');
242
+ }
243
+ if (this.symbols === 'unicode') {
244
+ throw new TextOptionError('Not implemented (WD REQ-1001): symbols: unicode (no glyph tables for Symbol and Wingdings)', 'symbols', 'REQ-601', 'not_implemented');
245
+ }
246
+ if (this.fields === 'update') {
247
+ throw new TextOptionError('Not implemented yet (WD REQ-1001): fields: update (REQ-506, CR-012 phase 5a)', 'fields', 'REQ-506', 'not_implemented');
248
+ }
249
+ if (this.embedded) {
250
+ throw new TextOptionError('Not implemented yet (WD REQ-1001): embedded: true (REQ-512, CR-012 phase 5d)', 'embedded', 'REQ-512', 'not_implemented');
251
+ }
252
+ }
253
+ }
254
+ function viewOf(value) {
255
+ const n = String(value !== null && value !== void 0 ? value : '').trim().toLowerCase();
256
+ if (n === 'current')
257
+ return 'accepted';
258
+ if (n === 'accepted' || n === 'original' || n === 'markup')
259
+ return n;
260
+ throw new TextOptionError(`view: '${String(value)}' is not accepted, original, markup or current (WD REQ-401)`, 'view', 'REQ-401', 'invalid');
261
+ }
262
+ function bool(name, value, statement) {
263
+ if (typeof value === 'boolean')
264
+ return value;
265
+ const s = String(value !== null && value !== void 0 ? value : '').trim().toLowerCase();
266
+ if (s === 'true')
267
+ return true;
268
+ if (s === 'false')
269
+ return false;
270
+ throw new TextOptionError(`${name}: '${String(value)}' is not true or false (WD REQ-1001)`, name, statement, 'invalid');
271
+ }
272
+ function choice(name, value, values, statement) {
273
+ const s = String(value !== null && value !== void 0 ? value : '').trim().toLowerCase();
274
+ const found = values.find((v) => v === s);
275
+ if (found !== undefined)
276
+ return found;
277
+ throw new TextOptionError(`${name}: '${String(value)}' is not one of ${values.join(', ')} (WD REQ-1001)`, name, statement, 'invalid');
278
+ }