@docx4j/core-ts 0.5.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.
- package/NOTICE +4 -0
- package/README.md +92 -4
- package/dist/html/convert.mjs +2 -1
- package/dist/html/elements.mjs +2 -1
- package/dist/model/color/ColorMath.d.mts +29 -0
- package/dist/model/color/ColorMath.mjs +146 -0
- package/dist/model/color/ColorTables.d.mts +6 -0
- package/dist/model/color/ColorTables.mjs +83 -0
- package/dist/model/color/DrawingMLColors.d.mts +52 -0
- package/dist/model/color/DrawingMLColors.mjs +374 -0
- package/dist/model/color/ResolvedColor.d.mts +36 -0
- package/dist/model/color/ResolvedColor.mjs +65 -0
- package/dist/model/color/SpreadsheetColors.d.mts +36 -0
- package/dist/model/color/SpreadsheetColors.mjs +84 -0
- package/dist/model/color/StyleFill.d.mts +28 -0
- package/dist/model/color/StyleFill.mjs +21 -0
- package/dist/model/color/ThemeColors.d.mts +86 -0
- package/dist/model/color/ThemeColors.mjs +304 -0
- package/dist/model/color/WordColors.d.mts +71 -0
- package/dist/model/color/WordColors.mjs +121 -0
- package/dist/model/color/index.d.mts +6 -0
- package/dist/model/color/index.mjs +30 -0
- package/dist/model/content/Body.d.mts +145 -23
- package/dist/model/content/Body.mjs +507 -150
- package/dist/model/content/Comment.d.mts +23 -5
- package/dist/model/content/Comment.mjs +207 -26
- package/dist/model/content/ContentControl.d.mts +198 -19
- package/dist/model/content/ContentControl.mjs +672 -99
- package/dist/model/content/Font.d.mts +70 -17
- package/dist/model/content/Font.mjs +119 -36
- package/dist/model/content/InlinePicture.d.mts +11 -0
- package/dist/model/content/InlinePicture.mjs +21 -1
- package/dist/model/content/List.d.mts +6 -3
- package/dist/model/content/List.mjs +18 -8
- package/dist/model/content/Paragraph.d.mts +200 -14
- package/dist/model/content/Paragraph.mjs +898 -82
- package/dist/model/content/Range.d.mts +227 -12
- package/dist/model/content/Range.mjs +785 -59
- package/dist/model/content/ResolvedView.d.mts +104 -0
- package/dist/model/content/ResolvedView.mjs +596 -0
- package/dist/model/content/Table.d.mts +29 -3
- package/dist/model/content/Table.mjs +135 -49
- package/dist/model/content/TrackedChange.d.mts +174 -15
- package/dist/model/content/TrackedChange.mjs +734 -170
- package/dist/model/content/comments.d.mts +20 -6
- package/dist/model/content/comments.mjs +67 -57
- package/dist/model/content/generalException.d.mts +18 -0
- package/dist/model/content/generalException.mjs +24 -0
- package/dist/model/content/index.d.mts +10 -3
- package/dist/model/content/index.mjs +10 -2
- package/dist/model/content/mathText.d.mts +21 -0
- package/dist/model/content/mathText.mjs +267 -0
- package/dist/model/content/officeText.d.mts +27 -0
- package/dist/model/content/officeText.mjs +74 -0
- package/dist/model/content/ooxml.mjs +12 -1
- package/dist/model/content/outline.d.mts +5 -0
- package/dist/model/content/outline.mjs +13 -0
- package/dist/model/content/paraIds.d.mts +5 -0
- package/dist/model/content/paraIds.mjs +54 -0
- package/dist/model/content/placeholders.d.mts +110 -0
- package/dist/model/content/placeholders.mjs +253 -0
- package/dist/model/content/search.d.mts +74 -0
- package/dist/model/content/search.mjs +255 -9
- package/dist/model/content/spanEdits.d.mts +159 -0
- package/dist/model/content/spanEdits.mjs +728 -0
- package/dist/model/content/story.d.mts +47 -0
- package/dist/model/content/story.mjs +95 -0
- package/dist/model/content/tableColumns.d.mts +1 -1
- package/dist/model/content/tableColumns.mjs +108 -80
- package/dist/model/content/tableRevisions.d.mts +11 -3
- package/dist/model/content/tableRevisions.mjs +72 -42
- package/dist/model/content/tableRules.d.mts +30 -0
- package/dist/model/content/tableRules.mjs +102 -0
- package/dist/model/content/textBoxes.d.mts +18 -0
- package/dist/model/content/textBoxes.mjs +105 -0
- package/dist/model/content/trackedChangeFilter.d.mts +39 -0
- package/dist/model/content/trackedChangeFilter.mjs +81 -0
- package/dist/model/content/tracking.d.mts +63 -6
- package/dist/model/content/tracking.mjs +242 -22
- package/dist/model/content/tree.d.mts +172 -24
- package/dist/model/content/tree.mjs +328 -54
- package/dist/model/content/wordRange.d.mts +48 -0
- package/dist/model/content/wordRange.mjs +97 -0
- package/dist/model/customxml/CustomXmlPartCollection.d.mts +30 -1
- package/dist/model/customxml/CustomXmlPartCollection.mjs +81 -12
- package/dist/model/customxml/XmlMapping.d.mts +32 -8
- package/dist/model/customxml/XmlMapping.mjs +64 -10
- package/dist/model/customxml/bindings.d.mts +33 -4
- package/dist/model/customxml/bindings.mjs +171 -45
- package/dist/model/customxml/index.d.mts +1 -0
- package/dist/model/customxml/index.mjs +1 -0
- package/dist/model/customxml/kinds.d.mts +8 -3
- package/dist/model/customxml/kinds.mjs +26 -5
- package/dist/model/customxml/opendope.d.mts +4 -1
- package/dist/model/customxml/opendope.mjs +9 -6
- package/dist/model/customxml/picturePlaceholder.d.mts +17 -0
- package/dist/model/customxml/picturePlaceholder.mjs +32 -0
- package/dist/model/customxml/pictures.d.mts +4 -3
- package/dist/model/customxml/pictures.mjs +22 -8
- package/dist/model/customxml/storeItems.d.mts +57 -0
- package/dist/model/customxml/storeItems.mjs +122 -0
- package/dist/model/customxml/xhtml.mjs +23 -22
- package/dist/model/dateZone.d.mts +25 -0
- package/dist/model/dateZone.mjs +57 -0
- package/dist/model/index.d.mts +3 -0
- package/dist/model/index.mjs +5 -0
- package/dist/model/listnumbering/Emulator.d.mts +37 -5
- package/dist/model/listnumbering/Emulator.mjs +63 -9
- package/dist/model/properties/PropertyResolver.d.mts +74 -2
- package/dist/model/properties/PropertyResolver.mjs +133 -5
- package/dist/model/properties/catalogue.d.mts +19 -5
- package/dist/model/properties/catalogue.mjs +41 -15
- package/dist/model/properties/index.d.mts +1 -1
- package/dist/model/properties/log.d.mts +1 -1
- package/dist/model/properties/log.mjs +5 -5
- package/dist/model/properties/styleUtil.d.mts +3 -1
- package/dist/model/properties/styleUtil.mjs +20 -24
- package/dist/model/properties/table.mjs +4 -2
- package/dist/model/text/CaseMapping.d.mts +38 -0
- package/dist/model/text/CaseMapping.mjs +86 -0
- package/dist/model/text/Extractor.d.mts +349 -0
- package/dist/model/text/Extractor.mjs +2406 -0
- package/dist/model/text/LinkTargets.d.mts +45 -0
- package/dist/model/text/LinkTargets.mjs +170 -0
- package/dist/model/text/MarkdownExporter.d.mts +140 -0
- package/dist/model/text/MarkdownExporter.mjs +255 -0
- package/dist/model/text/PlainText.d.mts +29 -0
- package/dist/model/text/PlainText.mjs +542 -0
- package/dist/model/text/TextContext.d.mts +256 -0
- package/dist/model/text/TextContext.mjs +600 -0
- package/dist/model/text/TextOptions.d.mts +233 -0
- package/dist/model/text/TextOptions.mjs +419 -0
- package/dist/model/text/TextResult.d.mts +621 -0
- package/dist/model/text/TextResult.mjs +629 -0
- package/dist/model/text/Texts.d.mts +99 -0
- package/dist/model/text/Texts.mjs +187 -0
- package/dist/model/text/WmlToMarkdown.d.mts +120 -0
- package/dist/model/text/WmlToMarkdown.mjs +936 -0
- package/dist/model/text/caseMapping.generated.d.mts +7 -0
- package/dist/model/text/caseMapping.generated.mjs +214 -0
- package/dist/model/text/commonmark.d.mts +121 -0
- package/dist/model/text/commonmark.mjs +655 -0
- package/dist/model/text/index.d.mts +8 -0
- package/dist/model/text/index.mjs +9 -0
- package/dist/model/text/normalize.d.mts +8 -0
- package/dist/model/text/normalize.mjs +13 -0
- package/dist/model/text/outline.d.mts +4 -0
- package/dist/model/text/outline.mjs +71 -0
- package/dist/model/wordIntegers.d.mts +29 -0
- package/dist/model/wordIntegers.mjs +78 -0
- package/dist/office-js/document.mjs +15 -1
- package/dist/office-js/fragment.d.mts +7 -5
- package/dist/office-js/fragment.mjs +63 -14
- package/dist/office-js/proxy.d.mts +8 -0
- package/dist/office-js/proxy.mjs +29 -0
- package/dist/office-js/run.mjs +2 -0
- package/dist/office-js/supported.generated.mjs +16 -0
- package/dist/office-js/toApiScript.mjs +29 -12
- package/dist/opc/DirectoryPartStore.d.mts +6 -2
- package/dist/opc/DirectoryPartStore.mjs +11 -4
- package/dist/opc/FlatOpcPartStore.d.mts +4 -2
- package/dist/opc/FlatOpcPartStore.mjs +11 -8
- package/dist/opc/Load.d.mts +32 -0
- package/dist/opc/Load.mjs +115 -5
- package/dist/opc/PartStore.d.mts +34 -1
- package/dist/opc/PartStore.mjs +71 -8
- package/dist/opc/Save.d.mts +32 -0
- package/dist/opc/Save.mjs +110 -4
- package/dist/opc/ZipPartStore.d.mts +4 -2
- package/dist/opc/ZipPartStore.mjs +12 -7
- package/dist/opc/exceptions.d.mts +140 -0
- package/dist/opc/exceptions.mjs +108 -0
- package/dist/opc/index.d.mts +8 -5
- package/dist/opc/index.mjs +5 -3
- package/dist/opc/mce/preprocessor.d.mts +141 -5
- package/dist/opc/mce/preprocessor.mjs +119 -18
- package/dist/opc/mce/understood.d.mts +3 -11
- package/dist/opc/mce/understood.mjs +27 -23
- package/dist/opc/repair/breaks.d.mts +23 -0
- package/dist/opc/repair/breaks.mjs +288 -0
- package/dist/opc/repair/hosts.d.mts +12 -0
- package/dist/opc/repair/hosts.mjs +33 -0
- package/dist/opc/repair/mainRoot.d.mts +19 -0
- package/dist/opc/repair/mainRoot.mjs +168 -0
- package/dist/opc/repair/unknownElements.d.mts +8 -0
- package/dist/opc/repair/unknownElements.mjs +180 -0
- package/dist/opc/repair/wmlNames.generated.d.mts +2 -0
- package/dist/opc/repair/wmlNames.generated.mjs +80 -0
- package/dist/opc/skipped.d.mts +50 -0
- package/dist/opc/skipped.mjs +140 -0
- package/dist/packages/OpcPackage.d.mts +110 -4
- package/dist/packages/OpcPackage.mjs +123 -7
- package/dist/packages/WordprocessingMLPackage.d.mts +45 -8
- package/dist/packages/WordprocessingMLPackage.mjs +158 -21
- package/dist/packages/index.d.mts +1 -1
- package/dist/parts/DefaultXmlPart.mjs +2 -2
- package/dist/parts/Part.d.mts +14 -2
- package/dist/parts/RelationshipsPart.d.mts +15 -0
- package/dist/parts/RelationshipsPart.mjs +66 -1
- package/dist/parts/XmlPart.d.mts +63 -32
- package/dist/parts/XmlPart.mjs +240 -96
- package/dist/parts/wml/comments.mjs +30 -0
- package/dist/parts/wml/index.d.mts +12 -1
- package/dist/parts/wml/index.mjs +37 -1
- package/dist/xml/dom.d.mts +7 -0
- package/dist/xml/dom.mjs +18 -0
- package/package.json +2 -2
|
@@ -0,0 +1,233 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* The stories `include` adds (REQ-501, REQ-502): `headers`, `footers` and `glossary`. Comments are `comments` (REQ-504, WD 0.91).
|
|
12
|
+
* `comments` here is deprecated, a spelling of `comments: true` kept because 0.6.0 released it (CR-012 section 29).
|
|
13
|
+
*/
|
|
14
|
+
export type TextInclude = 'headers' | 'footers' | 'comments' | 'glossary';
|
|
15
|
+
/** `fields` (REQ-506). */
|
|
16
|
+
export type TextFields = 'cached' | 'update';
|
|
17
|
+
/** `bindings` (REQ-509). */
|
|
18
|
+
export type TextBindings = 'bound' | 'surface';
|
|
19
|
+
/** `symbols` (REQ-601). */
|
|
20
|
+
export type TextSymbols = 'asis' | 'unicode';
|
|
21
|
+
/** `math` (REQ-604). */
|
|
22
|
+
export type TextMath = 'latex' | 'unicodemath';
|
|
23
|
+
/** `tables` (REQ-605). */
|
|
24
|
+
export type TextTables = 'auto' | 'tsv' | 'grid';
|
|
25
|
+
/** `markup_detail` (REQ-702). */
|
|
26
|
+
export type TextMarkupDetail = 'type' | 'author' | 'author_date';
|
|
27
|
+
/** `layout` (REQ-709). */
|
|
28
|
+
export type TextLayout = 'none' | 'indent';
|
|
29
|
+
/**
|
|
30
|
+
* `drop_caps` (REQ-521): a drop cap's frame paragraph (`w:framePr/@w:dropCap`) joined to the paragraph after it, as the
|
|
31
|
+
* page reads (`join`), or the two paragraphs as the package holds them (`asis`, Word's text). CR-012 section 24.3.
|
|
32
|
+
*/
|
|
33
|
+
export type TextDropCaps = 'join' | 'asis';
|
|
34
|
+
/**
|
|
35
|
+
* `small_caps` (REQ-607): a small-caps run written as its stored characters (`asis`), or in capitals as a caps run is
|
|
36
|
+
* (`upper`, Word's text). CR-012 section 24.
|
|
37
|
+
*/
|
|
38
|
+
export type TextSmallCaps = 'asis' | 'upper';
|
|
39
|
+
/**
|
|
40
|
+
* `repair` (REQ-207, WD 0.102): how a package Word reads only through a repair, or won't open, is loaded: every refusal kept
|
|
41
|
+
* (`refuse`), Word's repair followed where the WD states one (`word`), or that and this package's own (`all`). The load's
|
|
42
|
+
* option (`LoadOptions.repair`, CR-031): a reading of a package already loaded doesn't decide again, and the load's setting
|
|
43
|
+
* holds. `duplicate_entries`, which REQ-206 says an implementation MAY offer, isn't offered here: `word` reads its `first`
|
|
44
|
+
* (CR-031 D1).
|
|
45
|
+
*/
|
|
46
|
+
export type TextRepair = 'refuse' | 'word' | 'all';
|
|
47
|
+
/**
|
|
48
|
+
* `profile` (REQ-1002, WD 0.41): a preset of option values applied before the caller's own, so that an option the caller
|
|
49
|
+
* sets by name, before or after the profile, overrides it. `word-text` is Word's Save As plain text as the options reach
|
|
50
|
+
* it (`WORD_TEXT_PROFILE`). CR-012 section 23.1.
|
|
51
|
+
*/
|
|
52
|
+
export type TextProfile = 'word-text';
|
|
53
|
+
/** A boolean option's value: a boolean, or `"true"` / `"false"` as a tool passes it. */
|
|
54
|
+
type Bool = boolean | 'true' | 'false';
|
|
55
|
+
/**
|
|
56
|
+
* The options by the specification's names (WD section 10), every one optional, each absent one at its
|
|
57
|
+
* default. `include` takes a list of story names or a string of them separated by commas or spaces,
|
|
58
|
+
* and naming `comments` in it is a deprecated spelling of `comments: true`, refused beside `comments: false`;
|
|
59
|
+
* a boolean takes `"true"` or `"false"` as well; any other value is its name, in any case.
|
|
60
|
+
* `imageDescriber` is the host's (REQ-514), not one of the specification's options.
|
|
61
|
+
*/
|
|
62
|
+
export interface TextOptionsInit {
|
|
63
|
+
view?: TextModelView | 'current';
|
|
64
|
+
include?: readonly TextInclude[] | string;
|
|
65
|
+
text_boxes?: Bool;
|
|
66
|
+
notes?: Bool;
|
|
67
|
+
note_references?: Bool;
|
|
68
|
+
comments?: Bool;
|
|
69
|
+
hidden?: Bool;
|
|
70
|
+
field_codes?: Bool;
|
|
71
|
+
fields?: TextFields;
|
|
72
|
+
toc?: Bool;
|
|
73
|
+
drop_caps?: TextDropCaps;
|
|
74
|
+
placeholders?: Bool;
|
|
75
|
+
bindings?: TextBindings;
|
|
76
|
+
list_labels?: Bool;
|
|
77
|
+
charts?: Bool;
|
|
78
|
+
smartart?: Bool;
|
|
79
|
+
embedded?: Bool;
|
|
80
|
+
altchunks?: Bool;
|
|
81
|
+
alt_text?: Bool;
|
|
82
|
+
metadata?: Bool;
|
|
83
|
+
symbols?: TextSymbols;
|
|
84
|
+
small_caps?: TextSmallCaps;
|
|
85
|
+
/** A BCP 47 tag (REQ-607, WD 0.80): the language of last resort for a cased run's capitals. */
|
|
86
|
+
default_language?: string;
|
|
87
|
+
math?: TextMath;
|
|
88
|
+
tables?: TextTables;
|
|
89
|
+
markup_detail?: TextMarkupDetail;
|
|
90
|
+
page_markers?: Bool;
|
|
91
|
+
layout?: TextLayout;
|
|
92
|
+
warnings?: Bool;
|
|
93
|
+
repair?: TextRepair;
|
|
94
|
+
/** A preset applied before the other options, whichever came first (REQ-1002); `word-text` or `word_text`, in any case. */
|
|
95
|
+
profile?: TextProfile | string | null;
|
|
96
|
+
/** The describer images take their text from (REQ-514); `AltTextDescriber` by default. */
|
|
97
|
+
imageDescriber?: ImageDescriber;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* An option refused (REQ-1001): an unknown name, a value the specification does not define, or a
|
|
101
|
+
* value this package does not implement yet. `statement` names the requirement, `option` the option.
|
|
102
|
+
*/
|
|
103
|
+
export declare class TextOptionError extends Docx4JException {
|
|
104
|
+
readonly option: string;
|
|
105
|
+
readonly statement: string;
|
|
106
|
+
readonly reason: 'unknown' | 'invalid' | 'not_implemented';
|
|
107
|
+
constructor(message: string, option: string, statement: string, reason: 'unknown' | 'invalid' | 'not_implemented');
|
|
108
|
+
}
|
|
109
|
+
/** The option names of WD section 10, in its order. docx4j `TextOptions.NAMES`. */
|
|
110
|
+
export declare const TEXT_OPTION_NAMES: readonly string[];
|
|
111
|
+
/**
|
|
112
|
+
* `profile: word-text`'s values by WD name, in WD order (REQ-1002; docx4j `TextOptions.WORD_TEXT_VALUES`): the accepted
|
|
113
|
+
* view, hidden text in, headers and footers in, comments in through `comments` alone (WD 0.91), text boxes out, notes and their references in, list labels
|
|
114
|
+
* (WD 0.75), fields cached, no field codes, the table of contents in, a drop cap apart from its word, placeholders in,
|
|
115
|
+
* bound values, chunks expanded, symbols as they are, small caps in capitals, tables as tab-separated rows, no page
|
|
116
|
+
* markers, no indentation, no alt text, no metadata, no charts, SmartArt or embedded packages. `default_language` keeps
|
|
117
|
+
* its default, since the saving installation's language is not in the file (WD 0.80). What it does not reproduce: the
|
|
118
|
+
* notes' and comments' forms, CR LF and CR cells, folded hyphens, the one space Word writes after every list label where
|
|
119
|
+
* the level's suffix is written here (WD 0.79), Word's linear math (`math: unicodemath` is refused here, as in docx4j, so
|
|
120
|
+
* the preset leaves math as LaTeX; CR-012 section 23.1), and three accidents of Word's own: the partial update a DATE,
|
|
121
|
+
* TIME or SAVEDATE field triggers on open, the SYMBOL omission, and the stale PAGE number.
|
|
122
|
+
*/
|
|
123
|
+
export declare const WORD_TEXT_PROFILE: Readonly<Record<string, unknown>>;
|
|
124
|
+
/**
|
|
125
|
+
* What a text includes and how it is written: the specification's section 10 options (REQ-1001), as
|
|
126
|
+
* docx4j's `TextOptions` has them. Mutable; `Texts.of` reads it once.
|
|
127
|
+
*
|
|
128
|
+
* Every option name and value of WD section 10 is accepted by `set`. Some values are not implemented,
|
|
129
|
+
* and `Texts.of` refuses them with a `TextOptionError` naming the statement rather than ignoring them
|
|
130
|
+
* (REQ-1001): `math: unicodemath` and `symbols: unicode`, as docx4j refuses them (no converter, no glyph
|
|
131
|
+
* tables), and, until CR-012 phase 5, `fields: update` (REQ-506) and `embedded: true` (REQ-512). The
|
|
132
|
+
* defaults `charts`, `smartart` and `altchunks` are accepted, and until phase 5 a chart or SmartArt
|
|
133
|
+
* contributes nothing and an `altChunk` is not expanded, raising `altchunk.not_expanded` (CR-012
|
|
134
|
+
* section 5).
|
|
135
|
+
*/
|
|
136
|
+
export declare class TextOptions {
|
|
137
|
+
view: TextModelView;
|
|
138
|
+
private readonly includeSet;
|
|
139
|
+
textBoxes: boolean;
|
|
140
|
+
notes: boolean;
|
|
141
|
+
noteReferences: boolean;
|
|
142
|
+
private commentsOption;
|
|
143
|
+
hidden: boolean;
|
|
144
|
+
fieldCodes: boolean;
|
|
145
|
+
fields: TextFields;
|
|
146
|
+
/**
|
|
147
|
+
* Whether a table of contents is read: false by default (WD REQ-520; docx4j CR-046 D12). A table of
|
|
148
|
+
* contents is the result of a TOC field; under `toc: false` nothing of the field is read, its code
|
|
149
|
+
* included under `field_codes`, and a paragraph with nothing else in it is no paragraph.
|
|
150
|
+
*/
|
|
151
|
+
toc: boolean;
|
|
152
|
+
/** `drop_caps` (REQ-521): `join`, the default, or `asis`. */
|
|
153
|
+
dropCaps: TextDropCaps;
|
|
154
|
+
placeholders: boolean;
|
|
155
|
+
bindings: TextBindings;
|
|
156
|
+
listLabels: boolean;
|
|
157
|
+
charts: boolean;
|
|
158
|
+
smartart: boolean;
|
|
159
|
+
embedded: boolean;
|
|
160
|
+
altchunks: boolean;
|
|
161
|
+
altText: boolean;
|
|
162
|
+
metadata: boolean;
|
|
163
|
+
symbols: TextSymbols;
|
|
164
|
+
/** `small_caps` (REQ-607): `asis`, the default, or `upper`. */
|
|
165
|
+
smallCaps: TextSmallCaps;
|
|
166
|
+
/**
|
|
167
|
+
* `default_language` (REQ-607, WD 0.80): the language a cased run's capitals are mapped by where the run, its styles and
|
|
168
|
+
* the document defaults name none. It stands in for Word's editing language, which a library cannot know;
|
|
169
|
+
* `w:themeFontLang` plays no part. A BCP 47 tag, kept as given; `CaseMapping.DEFAULT_LANGUAGE` (`en-US`) by default.
|
|
170
|
+
* CR-012 section 24.8.
|
|
171
|
+
*/
|
|
172
|
+
defaultLanguage: string;
|
|
173
|
+
math: TextMath;
|
|
174
|
+
tables: TextTables;
|
|
175
|
+
markupDetail: TextMarkupDetail;
|
|
176
|
+
/**
|
|
177
|
+
* `page_markers` (REQ-708): `[page n]` at each `w:lastRenderedPageBreak`. The markers are where Word's
|
|
178
|
+
* pages began when it last laid the document out: they are current only when the package was last
|
|
179
|
+
* paginated (saved by Word) after its last edit, and an extractor cannot tell whether it was.
|
|
180
|
+
*/
|
|
181
|
+
pageMarkers: boolean;
|
|
182
|
+
layout: TextLayout;
|
|
183
|
+
warnings: boolean;
|
|
184
|
+
/**
|
|
185
|
+
* `repair` (REQ-207): the load's option, accepted here by the WD's name (REQ-1001) and passed by a caller that loads, as the
|
|
186
|
+
* suite's adapter does, to `LoadOptions.repair`; a reading of a loaded package doesn't use it.
|
|
187
|
+
*/
|
|
188
|
+
repair: TextRepair;
|
|
189
|
+
/** The describer images take their text from (REQ-514). */
|
|
190
|
+
imageDescriber: ImageDescriber;
|
|
191
|
+
/** The profile applied (REQ-1002), or undefined. */
|
|
192
|
+
private profileName;
|
|
193
|
+
/** The options the caller set by name: a profile does not override them, whichever came first. */
|
|
194
|
+
private readonly explicit;
|
|
195
|
+
/** Options from the specification's names and values (REQ-1001); those not named keep their defaults. */
|
|
196
|
+
static of(init?: TextOptionsInit | TextOptions): TextOptions;
|
|
197
|
+
/**
|
|
198
|
+
* Sets one option by its specification name and value; throws `TextOptionError` for one it does not define. An option set
|
|
199
|
+
* by name is the caller's: a profile, applied before or after, leaves it (REQ-1002). A member assigned directly is not
|
|
200
|
+
* recorded so, and a profile applied after the assignment overrides it.
|
|
201
|
+
*/
|
|
202
|
+
set(name: string, value: unknown): this;
|
|
203
|
+
/**
|
|
204
|
+
* Applies a profile (REQ-1002): its values for every option the caller has not set by name; an option the caller sets
|
|
205
|
+
* afterwards overrides it too. Undefined clears the name, leaving the values. See `WORD_TEXT_PROFILE`.
|
|
206
|
+
*/
|
|
207
|
+
profile(p: TextProfile | undefined): this;
|
|
208
|
+
/** The profile applied, or undefined. */
|
|
209
|
+
get profileApplied(): TextProfile | undefined;
|
|
210
|
+
/** Sets one option without recording it as the caller's (a profile's value). */
|
|
211
|
+
private apply;
|
|
212
|
+
private setInclude;
|
|
213
|
+
/** `comments` never stays in `include`: it is the deprecated spelling of `comments: true`, and the caller's option as that is. */
|
|
214
|
+
private addStories;
|
|
215
|
+
/** Adds stories to `include` (docx4j's builder `include(Include...)`). */
|
|
216
|
+
include(...stories: TextInclude[]): this;
|
|
217
|
+
/** The stories in scope: those `include` names, and `comments` where `comments` is true. */
|
|
218
|
+
get includes(): ReadonlySet<TextInclude>;
|
|
219
|
+
/** `comments: true`, the one setting (REQ-504, WD 0.91). */
|
|
220
|
+
get comments(): boolean;
|
|
221
|
+
set comments(value: boolean);
|
|
222
|
+
/** A copy, for a reading one level down or a first reading. */
|
|
223
|
+
copy(): TextOptions;
|
|
224
|
+
/** The options as the specification names them, with their values, in section 10's order. */
|
|
225
|
+
toMap(): Record<string, unknown>;
|
|
226
|
+
toJSON(): Record<string, unknown>;
|
|
227
|
+
/**
|
|
228
|
+
* Throws for a value this package does not honour (REQ-1001: documented, and refused rather than
|
|
229
|
+
* ignored): the two docx4j refuses, and the two whose statements wait on CR-012 phase 5.
|
|
230
|
+
*/
|
|
231
|
+
checkImplemented(): void;
|
|
232
|
+
}
|
|
233
|
+
export {};
|
|
@@ -0,0 +1,419 @@
|
|
|
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
|
+
import { CaseMapping } from './CaseMapping.mjs';
|
|
8
|
+
import { log } from '../properties/log.mjs';
|
|
9
|
+
/**
|
|
10
|
+
* An option refused (REQ-1001): an unknown name, a value the specification does not define, or a
|
|
11
|
+
* value this package does not implement yet. `statement` names the requirement, `option` the option.
|
|
12
|
+
*/
|
|
13
|
+
export class TextOptionError extends Docx4JException {
|
|
14
|
+
constructor(message, option, statement, reason) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.option = option;
|
|
17
|
+
this.statement = statement;
|
|
18
|
+
this.reason = reason;
|
|
19
|
+
this.name = 'TextOptionError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** The option names of WD section 10, in its order. docx4j `TextOptions.NAMES`. */
|
|
23
|
+
export const TEXT_OPTION_NAMES = Object.freeze([
|
|
24
|
+
'view', 'include', 'text_boxes', 'notes', 'note_references', 'comments', 'hidden', 'field_codes',
|
|
25
|
+
'fields', 'toc', 'drop_caps', 'placeholders', 'bindings', 'list_labels', 'charts', 'smartart', 'embedded', 'altchunks',
|
|
26
|
+
'alt_text', 'metadata', 'symbols', 'small_caps', 'default_language', 'math', 'tables', 'markup_detail', 'page_markers', 'layout',
|
|
27
|
+
'warnings', 'repair', 'profile',
|
|
28
|
+
]);
|
|
29
|
+
/**
|
|
30
|
+
* `profile: word-text`'s values by WD name, in WD order (REQ-1002; docx4j `TextOptions.WORD_TEXT_VALUES`): the accepted
|
|
31
|
+
* view, hidden text in, headers and footers in, comments in through `comments` alone (WD 0.91), text boxes out, notes and their references in, list labels
|
|
32
|
+
* (WD 0.75), fields cached, no field codes, the table of contents in, a drop cap apart from its word, placeholders in,
|
|
33
|
+
* bound values, chunks expanded, symbols as they are, small caps in capitals, tables as tab-separated rows, no page
|
|
34
|
+
* markers, no indentation, no alt text, no metadata, no charts, SmartArt or embedded packages. `default_language` keeps
|
|
35
|
+
* its default, since the saving installation's language is not in the file (WD 0.80). What it does not reproduce: the
|
|
36
|
+
* notes' and comments' forms, CR LF and CR cells, folded hyphens, the one space Word writes after every list label where
|
|
37
|
+
* the level's suffix is written here (WD 0.79), Word's linear math (`math: unicodemath` is refused here, as in docx4j, so
|
|
38
|
+
* the preset leaves math as LaTeX; CR-012 section 23.1), and three accidents of Word's own: the partial update a DATE,
|
|
39
|
+
* TIME or SAVEDATE field triggers on open, the SYMBOL omission, and the stale PAGE number.
|
|
40
|
+
*/
|
|
41
|
+
export const WORD_TEXT_PROFILE = Object.freeze({
|
|
42
|
+
view: 'accepted', include: 'headers,footers', text_boxes: false, notes: true, note_references: true,
|
|
43
|
+
comments: true, hidden: true, field_codes: false, fields: 'cached', toc: true, drop_caps: 'asis', placeholders: true,
|
|
44
|
+
bindings: 'bound', list_labels: true, charts: false, smartart: false, embedded: false, altchunks: true,
|
|
45
|
+
alt_text: false, metadata: false, symbols: 'asis', small_caps: 'upper', math: 'latex', tables: 'tsv',
|
|
46
|
+
page_markers: false, layout: 'none',
|
|
47
|
+
});
|
|
48
|
+
const INCLUDES = ['headers', 'footers', 'comments', 'glossary'];
|
|
49
|
+
/** `include`'s stories: a list of names, or a string of them separated by commas or spaces. */
|
|
50
|
+
function includeItems(value) {
|
|
51
|
+
const items = Array.isArray(value) ? value
|
|
52
|
+
: value === undefined || value === null ? [] : String(value).split(/[,\s]+/).filter((s) => s !== '');
|
|
53
|
+
return items.map((item) => choice('include', item, INCLUDES, 'REQ-501'));
|
|
54
|
+
}
|
|
55
|
+
/** Whether the deprecated spelling's notice has been written: once a process, since a caller's code is what has to change. */
|
|
56
|
+
let includeCommentsNoticed = false;
|
|
57
|
+
/**
|
|
58
|
+
* What a text includes and how it is written: the specification's section 10 options (REQ-1001), as
|
|
59
|
+
* docx4j's `TextOptions` has them. Mutable; `Texts.of` reads it once.
|
|
60
|
+
*
|
|
61
|
+
* Every option name and value of WD section 10 is accepted by `set`. Some values are not implemented,
|
|
62
|
+
* and `Texts.of` refuses them with a `TextOptionError` naming the statement rather than ignoring them
|
|
63
|
+
* (REQ-1001): `math: unicodemath` and `symbols: unicode`, as docx4j refuses them (no converter, no glyph
|
|
64
|
+
* tables), and, until CR-012 phase 5, `fields: update` (REQ-506) and `embedded: true` (REQ-512). The
|
|
65
|
+
* defaults `charts`, `smartart` and `altchunks` are accepted, and until phase 5 a chart or SmartArt
|
|
66
|
+
* contributes nothing and an `altChunk` is not expanded, raising `altchunk.not_expanded` (CR-012
|
|
67
|
+
* section 5).
|
|
68
|
+
*/
|
|
69
|
+
export class TextOptions {
|
|
70
|
+
constructor() {
|
|
71
|
+
this.view = 'accepted';
|
|
72
|
+
this.includeSet = new Set();
|
|
73
|
+
this.textBoxes = true;
|
|
74
|
+
this.notes = true;
|
|
75
|
+
this.noteReferences = true;
|
|
76
|
+
this.commentsOption = false;
|
|
77
|
+
this.hidden = false;
|
|
78
|
+
this.fieldCodes = false;
|
|
79
|
+
this.fields = 'cached';
|
|
80
|
+
/**
|
|
81
|
+
* Whether a table of contents is read: false by default (WD REQ-520; docx4j CR-046 D12). A table of
|
|
82
|
+
* contents is the result of a TOC field; under `toc: false` nothing of the field is read, its code
|
|
83
|
+
* included under `field_codes`, and a paragraph with nothing else in it is no paragraph.
|
|
84
|
+
*/
|
|
85
|
+
this.toc = false;
|
|
86
|
+
/** `drop_caps` (REQ-521): `join`, the default, or `asis`. */
|
|
87
|
+
this.dropCaps = 'join';
|
|
88
|
+
this.placeholders = true;
|
|
89
|
+
this.bindings = 'bound';
|
|
90
|
+
this.listLabels = false;
|
|
91
|
+
this.charts = true;
|
|
92
|
+
this.smartart = true;
|
|
93
|
+
this.embedded = false;
|
|
94
|
+
this.altchunks = true;
|
|
95
|
+
this.altText = false;
|
|
96
|
+
this.metadata = false;
|
|
97
|
+
this.symbols = 'asis';
|
|
98
|
+
/** `small_caps` (REQ-607): `asis`, the default, or `upper`. */
|
|
99
|
+
this.smallCaps = 'asis';
|
|
100
|
+
/**
|
|
101
|
+
* `default_language` (REQ-607, WD 0.80): the language a cased run's capitals are mapped by where the run, its styles and
|
|
102
|
+
* the document defaults name none. It stands in for Word's editing language, which a library cannot know;
|
|
103
|
+
* `w:themeFontLang` plays no part. A BCP 47 tag, kept as given; `CaseMapping.DEFAULT_LANGUAGE` (`en-US`) by default.
|
|
104
|
+
* CR-012 section 24.8.
|
|
105
|
+
*/
|
|
106
|
+
this.defaultLanguage = CaseMapping.DEFAULT_LANGUAGE;
|
|
107
|
+
this.math = 'latex';
|
|
108
|
+
this.tables = 'auto';
|
|
109
|
+
this.markupDetail = 'type';
|
|
110
|
+
/**
|
|
111
|
+
* `page_markers` (REQ-708): `[page n]` at each `w:lastRenderedPageBreak`. The markers are where Word's
|
|
112
|
+
* pages began when it last laid the document out: they are current only when the package was last
|
|
113
|
+
* paginated (saved by Word) after its last edit, and an extractor cannot tell whether it was.
|
|
114
|
+
*/
|
|
115
|
+
this.pageMarkers = false;
|
|
116
|
+
this.layout = 'none';
|
|
117
|
+
this.warnings = true;
|
|
118
|
+
/**
|
|
119
|
+
* `repair` (REQ-207): the load's option, accepted here by the WD's name (REQ-1001) and passed by a caller that loads, as the
|
|
120
|
+
* suite's adapter does, to `LoadOptions.repair`; a reading of a loaded package doesn't use it.
|
|
121
|
+
*/
|
|
122
|
+
this.repair = 'refuse';
|
|
123
|
+
/** The describer images take their text from (REQ-514). */
|
|
124
|
+
this.imageDescriber = AltTextDescriber.INSTANCE;
|
|
125
|
+
/** The options the caller set by name: a profile does not override them, whichever came first. */
|
|
126
|
+
this.explicit = new Set();
|
|
127
|
+
}
|
|
128
|
+
/** Options from the specification's names and values (REQ-1001); those not named keep their defaults. */
|
|
129
|
+
static of(init) {
|
|
130
|
+
var _a;
|
|
131
|
+
if (init instanceof TextOptions)
|
|
132
|
+
return init;
|
|
133
|
+
const o = new TextOptions();
|
|
134
|
+
if (init === undefined || init === null)
|
|
135
|
+
return o;
|
|
136
|
+
if (init.comments !== undefined && init.include !== undefined && !bool('comments', init.comments, 'REQ-504')
|
|
137
|
+
&& includeItems(init.include).includes('comments')) {
|
|
138
|
+
throw new TextOptionError(`comments: false and an include naming comments say opposite things; drop comments from include, `
|
|
139
|
+
+ `which is a deprecated spelling of comments: true (WD REQ-504)`, 'comments', 'REQ-504', 'invalid');
|
|
140
|
+
}
|
|
141
|
+
for (const [name, value] of Object.entries(init)) {
|
|
142
|
+
if (value === undefined)
|
|
143
|
+
continue;
|
|
144
|
+
if (name === 'imageDescriber')
|
|
145
|
+
o.imageDescriber = (_a = value) !== null && _a !== void 0 ? _a : AltTextDescriber.INSTANCE;
|
|
146
|
+
else
|
|
147
|
+
o.set(name, value);
|
|
148
|
+
}
|
|
149
|
+
return o;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Sets one option by its specification name and value; throws `TextOptionError` for one it does not define. An option set
|
|
153
|
+
* by name is the caller's: a profile, applied before or after, leaves it (REQ-1002). A member assigned directly is not
|
|
154
|
+
* recorded so, and a profile applied after the assignment overrides it.
|
|
155
|
+
*/
|
|
156
|
+
set(name, value) {
|
|
157
|
+
const n = (name !== null && name !== void 0 ? name : '').trim();
|
|
158
|
+
if (n === 'profile')
|
|
159
|
+
return this.profile(value === undefined || value === null ? undefined : profileOf(value));
|
|
160
|
+
this.apply(n, name, value);
|
|
161
|
+
this.explicit.add(n);
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Applies a profile (REQ-1002): its values for every option the caller has not set by name; an option the caller sets
|
|
166
|
+
* afterwards overrides it too. Undefined clears the name, leaving the values. See `WORD_TEXT_PROFILE`.
|
|
167
|
+
*/
|
|
168
|
+
profile(p) {
|
|
169
|
+
this.profileName = p;
|
|
170
|
+
if (p === undefined)
|
|
171
|
+
return this;
|
|
172
|
+
for (const [n, value] of Object.entries(WORD_TEXT_PROFILE))
|
|
173
|
+
if (!this.explicit.has(n))
|
|
174
|
+
this.apply(n, n, value);
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
/** The profile applied, or undefined. */
|
|
178
|
+
get profileApplied() {
|
|
179
|
+
return this.profileName;
|
|
180
|
+
}
|
|
181
|
+
/** Sets one option without recording it as the caller's (a profile's value). */
|
|
182
|
+
apply(n, name, value) {
|
|
183
|
+
switch (n) {
|
|
184
|
+
case 'view':
|
|
185
|
+
this.view = viewOf(value);
|
|
186
|
+
break;
|
|
187
|
+
case 'include':
|
|
188
|
+
this.setInclude(value);
|
|
189
|
+
break;
|
|
190
|
+
case 'text_boxes':
|
|
191
|
+
this.textBoxes = bool(n, value, 'REQ-518');
|
|
192
|
+
break;
|
|
193
|
+
case 'notes':
|
|
194
|
+
this.notes = bool(n, value, 'REQ-503');
|
|
195
|
+
break;
|
|
196
|
+
case 'note_references':
|
|
197
|
+
this.noteReferences = bool(n, value, 'REQ-503');
|
|
198
|
+
break;
|
|
199
|
+
case 'comments':
|
|
200
|
+
this.commentsOption = bool(n, value, 'REQ-504');
|
|
201
|
+
break;
|
|
202
|
+
case 'hidden':
|
|
203
|
+
this.hidden = bool(n, value, 'REQ-507');
|
|
204
|
+
break;
|
|
205
|
+
case 'field_codes':
|
|
206
|
+
this.fieldCodes = bool(n, value, 'REQ-505');
|
|
207
|
+
break;
|
|
208
|
+
case 'fields':
|
|
209
|
+
this.fields = choice(n, value, ['cached', 'update'], 'REQ-506');
|
|
210
|
+
break;
|
|
211
|
+
case 'toc':
|
|
212
|
+
this.toc = bool(n, value, 'REQ-520');
|
|
213
|
+
break;
|
|
214
|
+
case 'drop_caps':
|
|
215
|
+
this.dropCaps = choice(n, value, ['join', 'asis'], 'REQ-521');
|
|
216
|
+
break;
|
|
217
|
+
case 'placeholders':
|
|
218
|
+
this.placeholders = bool(n, value, 'REQ-508');
|
|
219
|
+
break;
|
|
220
|
+
case 'bindings':
|
|
221
|
+
this.bindings = choice(n, value, ['bound', 'surface'], 'REQ-509');
|
|
222
|
+
break;
|
|
223
|
+
case 'list_labels':
|
|
224
|
+
this.listLabels = bool(n, value, 'REQ-510');
|
|
225
|
+
break;
|
|
226
|
+
case 'charts':
|
|
227
|
+
this.charts = bool(n, value, 'REQ-511');
|
|
228
|
+
break;
|
|
229
|
+
case 'smartart':
|
|
230
|
+
this.smartart = bool(n, value, 'REQ-511');
|
|
231
|
+
break;
|
|
232
|
+
case 'embedded':
|
|
233
|
+
this.embedded = bool(n, value, 'REQ-512');
|
|
234
|
+
break;
|
|
235
|
+
case 'altchunks':
|
|
236
|
+
this.altchunks = bool(n, value, 'REQ-513');
|
|
237
|
+
break;
|
|
238
|
+
case 'alt_text':
|
|
239
|
+
this.altText = bool(n, value, 'REQ-514');
|
|
240
|
+
break;
|
|
241
|
+
case 'metadata':
|
|
242
|
+
this.metadata = bool(n, value, 'REQ-515');
|
|
243
|
+
break;
|
|
244
|
+
case 'symbols':
|
|
245
|
+
this.symbols = choice(n, value, ['asis', 'unicode'], 'REQ-601');
|
|
246
|
+
break;
|
|
247
|
+
case 'small_caps':
|
|
248
|
+
this.smallCaps = choice(n, value, ['asis', 'upper'], 'REQ-607');
|
|
249
|
+
break;
|
|
250
|
+
case 'default_language':
|
|
251
|
+
this.defaultLanguage = languageTag(n, value, 'REQ-607');
|
|
252
|
+
break;
|
|
253
|
+
case 'math':
|
|
254
|
+
this.math = choice(n, value, ['latex', 'unicodemath'], 'REQ-604');
|
|
255
|
+
break;
|
|
256
|
+
case 'tables':
|
|
257
|
+
this.tables = choice(n, value, ['auto', 'tsv', 'grid'], 'REQ-605');
|
|
258
|
+
break;
|
|
259
|
+
case 'markup_detail':
|
|
260
|
+
this.markupDetail = choice(n, value, ['type', 'author', 'author_date'], 'REQ-702');
|
|
261
|
+
break;
|
|
262
|
+
case 'page_markers':
|
|
263
|
+
this.pageMarkers = bool(n, value, 'REQ-708');
|
|
264
|
+
break;
|
|
265
|
+
case 'layout':
|
|
266
|
+
this.layout = choice(n, value, ['none', 'indent'], 'REQ-709');
|
|
267
|
+
break;
|
|
268
|
+
case 'warnings':
|
|
269
|
+
this.warnings = bool(n, value, 'REQ-801');
|
|
270
|
+
break;
|
|
271
|
+
case 'repair':
|
|
272
|
+
this.repair = choice(n, value, ['refuse', 'word', 'all'], 'REQ-207');
|
|
273
|
+
break;
|
|
274
|
+
case 'duplicate_entries':
|
|
275
|
+
// REQ-206's MAY, not offered (CR-031 D1): one switch, whose word reads the first copy
|
|
276
|
+
throw new TextOptionError("duplicate_entries isn't offered here: load with repair: 'word', which reads the first entry of each name "
|
|
277
|
+
+ '(WD REQ-206, REQ-207)', 'duplicate_entries', 'REQ-206', 'not_implemented');
|
|
278
|
+
default:
|
|
279
|
+
throw new TextOptionError(`Unknown text option '${String(name)}'; the options are ${TEXT_OPTION_NAMES.join(', ')} (WD REQ-1001)`, String(name), 'REQ-1001', 'unknown');
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
setInclude(value) {
|
|
283
|
+
this.includeSet.clear();
|
|
284
|
+
this.addStories(includeItems(value));
|
|
285
|
+
}
|
|
286
|
+
/** `comments` never stays in `include`: it is the deprecated spelling of `comments: true`, and the caller's option as that is. */
|
|
287
|
+
addStories(stories) {
|
|
288
|
+
for (const s of stories) {
|
|
289
|
+
if (s !== 'comments') {
|
|
290
|
+
this.includeSet.add(s);
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
this.commentsOption = true;
|
|
294
|
+
this.explicit.add('comments');
|
|
295
|
+
if (!includeCommentsNoticed)
|
|
296
|
+
log.warn('The text option include: comments is deprecated: use comments: true (WD 0.91, CR-012 section 29)');
|
|
297
|
+
includeCommentsNoticed = true;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/** Adds stories to `include` (docx4j's builder `include(Include...)`). */
|
|
301
|
+
include(...stories) {
|
|
302
|
+
this.addStories(stories.map((s) => choice('include', s, INCLUDES, 'REQ-501')));
|
|
303
|
+
this.explicit.add('include');
|
|
304
|
+
return this;
|
|
305
|
+
}
|
|
306
|
+
/** The stories in scope: those `include` names, and `comments` where `comments` is true. */
|
|
307
|
+
get includes() {
|
|
308
|
+
const out = new Set(this.includeSet);
|
|
309
|
+
if (this.commentsOption)
|
|
310
|
+
out.add('comments');
|
|
311
|
+
return out;
|
|
312
|
+
}
|
|
313
|
+
/** `comments: true`, the one setting (REQ-504, WD 0.91). */
|
|
314
|
+
get comments() {
|
|
315
|
+
return this.commentsOption;
|
|
316
|
+
}
|
|
317
|
+
set comments(value) {
|
|
318
|
+
this.commentsOption = value;
|
|
319
|
+
}
|
|
320
|
+
/** A copy, for a reading one level down or a first reading. */
|
|
321
|
+
copy() {
|
|
322
|
+
const o = new TextOptions();
|
|
323
|
+
Object.assign(o, this);
|
|
324
|
+
o.includeSet = new Set(this.includeSet);
|
|
325
|
+
o.explicit = new Set(this.explicit);
|
|
326
|
+
return o;
|
|
327
|
+
}
|
|
328
|
+
/** The options as the specification names them, with their values, in section 10's order. */
|
|
329
|
+
toMap() {
|
|
330
|
+
var _a;
|
|
331
|
+
return {
|
|
332
|
+
view: this.view, include: [...this.includeSet], text_boxes: this.textBoxes, notes: this.notes,
|
|
333
|
+
note_references: this.noteReferences, comments: this.commentsOption, hidden: this.hidden,
|
|
334
|
+
field_codes: this.fieldCodes, fields: this.fields, toc: this.toc, drop_caps: this.dropCaps, placeholders: this.placeholders,
|
|
335
|
+
bindings: this.bindings, list_labels: this.listLabels, charts: this.charts, smartart: this.smartart,
|
|
336
|
+
embedded: this.embedded, altchunks: this.altchunks, alt_text: this.altText, metadata: this.metadata,
|
|
337
|
+
symbols: this.symbols, small_caps: this.smallCaps, default_language: this.defaultLanguage, math: this.math, tables: this.tables, markup_detail: this.markupDetail,
|
|
338
|
+
page_markers: this.pageMarkers, layout: this.layout, warnings: this.warnings, repair: this.repair,
|
|
339
|
+
profile: (_a = this.profileName) !== null && _a !== void 0 ? _a : null,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
toJSON() {
|
|
343
|
+
return this.toMap();
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Throws for a value this package does not honour (REQ-1001: documented, and refused rather than
|
|
347
|
+
* ignored): the two docx4j refuses, and the two whose statements wait on CR-012 phase 5.
|
|
348
|
+
*/
|
|
349
|
+
checkImplemented() {
|
|
350
|
+
if (this.math === 'unicodemath') {
|
|
351
|
+
throw new TextOptionError('Not implemented (WD REQ-1001): math: unicodemath (no OMML to UnicodeMath converter)', 'math', 'REQ-604', 'not_implemented');
|
|
352
|
+
}
|
|
353
|
+
if (this.symbols === 'unicode') {
|
|
354
|
+
throw new TextOptionError('Not implemented (WD REQ-1001): symbols: unicode (no glyph tables for Symbol and Wingdings)', 'symbols', 'REQ-601', 'not_implemented');
|
|
355
|
+
}
|
|
356
|
+
if (this.fields === 'update') {
|
|
357
|
+
throw new TextOptionError('Not implemented yet (WD REQ-1001): fields: update (REQ-506, CR-012 phase 5a)', 'fields', 'REQ-506', 'not_implemented');
|
|
358
|
+
}
|
|
359
|
+
if (this.embedded) {
|
|
360
|
+
throw new TextOptionError('Not implemented yet (WD REQ-1001): embedded: true (REQ-512, CR-012 phase 5d)', 'embedded', 'REQ-512', 'not_implemented');
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/** A profile's name as the WD writes it (`word-text`), case-insensitively, a hyphen or an underscore. */
|
|
365
|
+
function profileOf(value) {
|
|
366
|
+
const s = String(value).trim();
|
|
367
|
+
if (s.toLowerCase().replace(/_/g, '-') === 'word-text')
|
|
368
|
+
return 'word-text';
|
|
369
|
+
throw new TextOptionError(`profile: '${s}' is not one of word-text (WD REQ-1002)`, 'profile', 'REQ-1002', 'invalid');
|
|
370
|
+
}
|
|
371
|
+
function viewOf(value) {
|
|
372
|
+
const n = String(value !== null && value !== void 0 ? value : '').trim().toLowerCase();
|
|
373
|
+
if (n === 'current')
|
|
374
|
+
return 'accepted';
|
|
375
|
+
if (n === 'accepted' || n === 'original' || n === 'markup')
|
|
376
|
+
return n;
|
|
377
|
+
throw new TextOptionError(`view: '${String(value)}' is not accepted, original, markup or current (WD REQ-401)`, 'view', 'REQ-401', 'invalid');
|
|
378
|
+
}
|
|
379
|
+
function bool(name, value, statement) {
|
|
380
|
+
if (typeof value === 'boolean')
|
|
381
|
+
return value;
|
|
382
|
+
const s = String(value !== null && value !== void 0 ? value : '').trim().toLowerCase();
|
|
383
|
+
if (s === 'true')
|
|
384
|
+
return true;
|
|
385
|
+
if (s === 'false')
|
|
386
|
+
return false;
|
|
387
|
+
throw new TextOptionError(`${name}: '${String(value)}' is not true or false (WD REQ-1001)`, name, statement, 'invalid');
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* RFC 5646's `Language-Tag` (section 2.1): a `langtag`, a private-use tag or a grandfathered one, case-insensitively. A
|
|
391
|
+
* tag this grammar accepts is well formed (section 2.2.9); whether its subtags are registered is not asked.
|
|
392
|
+
*/
|
|
393
|
+
const LANGUAGE_TAG = new RegExp('^(?:'
|
|
394
|
+
+ '(?:[a-z]{2,3}(?:-[a-z]{3}){0,3}|[a-z]{4}|[a-z]{5,8})' // language, with up to three extlang
|
|
395
|
+
+ '(?:-[a-z]{4})?' // script
|
|
396
|
+
+ '(?:-(?:[a-z]{2}|[0-9]{3}))?' // region
|
|
397
|
+
+ '(?:-(?:[a-z0-9]{5,8}|[0-9][a-z0-9]{3}))*' // variants
|
|
398
|
+
+ '(?:-[a-wyz0-9](?:-[a-z0-9]{2,8})+)*' // extensions
|
|
399
|
+
+ '(?:-x(?:-[a-z0-9]{1,8})+)?' // private use
|
|
400
|
+
+ '|x(?:-[a-z0-9]{1,8})+'
|
|
401
|
+
+ '|en-GB-oed|i-(?:ami|bnn|default|enochian|hak|klingon|lux|mingo|navajo|pwn|tao|tay|tsu)|sgn-(?:BE-FR|BE-NL|CH-DE)'
|
|
402
|
+
+ ')$', 'i');
|
|
403
|
+
/**
|
|
404
|
+
* A BCP 47 tag as given, trimmed; one RFC 5646's grammar refuses is refused, so that a mistyped tag cannot select the
|
|
405
|
+
* default unnoticed (CR-012 section 24.8, D2).
|
|
406
|
+
*/
|
|
407
|
+
function languageTag(name, value, statement) {
|
|
408
|
+
const s = typeof value === 'string' ? value.trim() : '';
|
|
409
|
+
if (LANGUAGE_TAG.test(s))
|
|
410
|
+
return s;
|
|
411
|
+
throw new TextOptionError(`${name}: '${String(value)}' is not a well-formed BCP 47 language tag, such as en-US or tr-TR (WD ${statement})`, name, statement, 'invalid');
|
|
412
|
+
}
|
|
413
|
+
function choice(name, value, values, statement) {
|
|
414
|
+
const s = String(value !== null && value !== void 0 ? value : '').trim().toLowerCase();
|
|
415
|
+
const found = values.find((v) => v === s);
|
|
416
|
+
if (found !== undefined)
|
|
417
|
+
return found;
|
|
418
|
+
throw new TextOptionError(`${name}: '${String(value)}' is not one of ${values.join(', ')} (WD REQ-1001)`, name, statement, 'invalid');
|
|
419
|
+
}
|