@office-open/docx 0.10.14 → 0.11.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/README.md +21 -17
- package/dist/index.d.mts +3774 -33
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +16469 -530
- package/dist/index.mjs.map +1 -1
- package/package.json +17 -34
- package/dist/chart.d.mts +0 -1
- package/dist/chart.mjs +0 -2
- package/dist/comments-Cn9Q0iT6.mjs +0 -8509
- package/dist/comments-Cn9Q0iT6.mjs.map +0 -1
- package/dist/context-B5k1UabT.mjs +0 -4530
- package/dist/context-B5k1UabT.mjs.map +0 -1
- package/dist/core-properties-C4tdD3KL.d.mts +0 -4004
- package/dist/core-properties-C4tdD3KL.d.mts.map +0 -1
- package/dist/document-attributes-C6PDT-ap.mjs +0 -60
- package/dist/document-attributes-C6PDT-ap.mjs.map +0 -1
- package/dist/drawingml.d.mts +0 -1
- package/dist/drawingml.mjs +0 -2
- package/dist/generate-BxIo24VV.mjs +0 -535
- package/dist/generate-BxIo24VV.mjs.map +0 -1
- package/dist/generate.d.mts +0 -10
- package/dist/generate.d.mts.map +0 -1
- package/dist/generate.mjs +0 -2
- package/dist/parse-ep7JKATJ.mjs +0 -2115
- package/dist/parse-ep7JKATJ.mjs.map +0 -1
- package/dist/parse.d.mts +0 -2
- package/dist/parse.mjs +0 -2
- package/dist/patch/index.d.mts +0 -47
- package/dist/patch/index.d.mts.map +0 -1
- package/dist/patch/index.mjs +0 -416
- package/dist/patch/index.mjs.map +0 -1
- package/dist/smartart.d.mts +0 -1
- package/dist/smartart.mjs +0 -2
|
@@ -1,4530 +0,0 @@
|
|
|
1
|
-
import { $ as parseRunProperties, C as FontWrapper, Q as stringifyRunProperties, Z as stringifyParagraphProperties, c as stringifyTableProperties, d as stringifyParagraphInline, et as stringifyElement, h as parseParagraph, i as parseTableRowPropertiesEl, it as WidthType, l as stringifyTableRowProperties, n as parseTableCellPropertiesEl, r as parseTablePropertiesEl, s as stringifyTableCellProperties, st as BorderStyle, xt as Media } from "./comments-Cn9Q0iT6.mjs";
|
|
2
|
-
import { DOCX_PARTS, Relationships, appPropertiesDesc, buildContentTypeOverrides, convertInchesToTwip, customPropertiesDesc, decimalNumber, derivePasswordHash, uniqueNumericIdCreator } from "@office-open/core";
|
|
3
|
-
import { attr, attrBool, attrMeasure, attrNum, escapeXml, findChild, js2xml, stringify, textOf, xml2js } from "@office-open/xml";
|
|
4
|
-
import { ChartCollection } from "@office-open/core/chart";
|
|
5
|
-
import { SmartArtCollection } from "@office-open/core/smartart";
|
|
6
|
-
//#region src/parts/paragraph/formatting/alignment.ts
|
|
7
|
-
/**
|
|
8
|
-
* Paragraph and table alignment module for WordprocessingML documents.
|
|
9
|
-
*
|
|
10
|
-
* This module provides justification (alignment) options for paragraphs and tables.
|
|
11
|
-
*
|
|
12
|
-
* Reference: http://officeopenxml.com/WPalignment.php
|
|
13
|
-
*
|
|
14
|
-
* @see http://officeopenxml.com/WPtableAlignment.php
|
|
15
|
-
* @see http://www.datypic.com/sc/ooxml/t-w_ST_Jc.html
|
|
16
|
-
*
|
|
17
|
-
* @module
|
|
18
|
-
*/
|
|
19
|
-
/**
|
|
20
|
-
* Paragraph justification (alignment) types.
|
|
21
|
-
*
|
|
22
|
-
* Specifies the horizontal alignment of text within a paragraph.
|
|
23
|
-
*
|
|
24
|
-
* Reference: http://officeopenxml.com/WPalignment.php
|
|
25
|
-
*
|
|
26
|
-
* ## XSD Schema
|
|
27
|
-
* ```xml
|
|
28
|
-
* <xsd:simpleType name="ST_Jc">
|
|
29
|
-
* <xsd:restriction base="xsd:string">
|
|
30
|
-
* <xsd:enumeration value="start"/>
|
|
31
|
-
* <xsd:enumeration value="center"/>
|
|
32
|
-
* <xsd:enumeration value="end"/>
|
|
33
|
-
* <xsd:enumeration value="both"/>
|
|
34
|
-
* <xsd:enumeration value="mediumKashida"/>
|
|
35
|
-
* <xsd:enumeration value="distribute"/>
|
|
36
|
-
* <xsd:enumeration value="numTab"/>
|
|
37
|
-
* <xsd:enumeration value="highKashida"/>
|
|
38
|
-
* <xsd:enumeration value="lowKashida"/>
|
|
39
|
-
* <xsd:enumeration value="thaiDistribute"/>
|
|
40
|
-
* <xsd:enumeration value="left"/>
|
|
41
|
-
* <xsd:enumeration value="right"/>
|
|
42
|
-
* </xsd:restriction>
|
|
43
|
-
* </xsd:simpleType>
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
|
-
* @publicApi
|
|
47
|
-
*/
|
|
48
|
-
const AlignmentType = {
|
|
49
|
-
/** Align Start */
|
|
50
|
-
START: "start",
|
|
51
|
-
/** Align Center */
|
|
52
|
-
CENTER: "center",
|
|
53
|
-
/** End */
|
|
54
|
-
END: "end",
|
|
55
|
-
/** Justified */
|
|
56
|
-
BOTH: "both",
|
|
57
|
-
/** Medium Kashida Length */
|
|
58
|
-
MEDIUM_KASHIDA: "mediumKashida",
|
|
59
|
-
/** Distribute All Characters Equally */
|
|
60
|
-
DISTRIBUTE: "distribute",
|
|
61
|
-
/** Align to List Tab */
|
|
62
|
-
NUM_TAB: "numTab",
|
|
63
|
-
/** Widest Kashida Length */
|
|
64
|
-
HIGH_KASHIDA: "highKashida",
|
|
65
|
-
/** Low Kashida Length */
|
|
66
|
-
LOW_KASHIDA: "lowKashida",
|
|
67
|
-
/** Thai Language Justification */
|
|
68
|
-
THAI_DISTRIBUTE: "thaiDistribute",
|
|
69
|
-
/** Align Left */
|
|
70
|
-
LEFT: "left",
|
|
71
|
-
/** Align Right */
|
|
72
|
-
RIGHT: "right",
|
|
73
|
-
/** Justified */
|
|
74
|
-
JUSTIFIED: "both"
|
|
75
|
-
};
|
|
76
|
-
//#endregion
|
|
77
|
-
//#region src/parts/numbering/level.ts
|
|
78
|
-
/**
|
|
79
|
-
* Number format types for list levels.
|
|
80
|
-
*
|
|
81
|
-
* Defines the various numbering formats available for list levels, including
|
|
82
|
-
* decimal, roman numerals, letters, and various international formats.
|
|
83
|
-
*
|
|
84
|
-
* Reference: http://officeopenxml.com/WPnumbering-numFmt.php
|
|
85
|
-
*
|
|
86
|
-
* @publicApi
|
|
87
|
-
*/
|
|
88
|
-
const LevelFormat = {
|
|
89
|
-
/** Decimal numbering (1, 2, 3...). */
|
|
90
|
-
DECIMAL: "decimal",
|
|
91
|
-
/** Uppercase roman numerals (I, II, III...). */
|
|
92
|
-
UPPER_ROMAN: "upperRoman",
|
|
93
|
-
/** Lowercase roman numerals (i, ii, iii...). */
|
|
94
|
-
LOWER_ROMAN: "lowerRoman",
|
|
95
|
-
/** Uppercase letters (A, B, C...). */
|
|
96
|
-
UPPER_LETTER: "upperLetter",
|
|
97
|
-
/** Lowercase letters (a, b, c...). */
|
|
98
|
-
LOWER_LETTER: "lowerLetter",
|
|
99
|
-
/** Ordinal numbers (1st, 2nd, 3rd...). */
|
|
100
|
-
ORDINAL: "ordinal",
|
|
101
|
-
/** Cardinal text (one, two, three...). */
|
|
102
|
-
CARDINAL_TEXT: "cardinalText",
|
|
103
|
-
/** Ordinal text (first, second, third...). */
|
|
104
|
-
ORDINAL_TEXT: "ordinalText",
|
|
105
|
-
/** Hexadecimal numbering. */
|
|
106
|
-
HEX: "hex",
|
|
107
|
-
/** Chicago Manual of Style numbering. */
|
|
108
|
-
CHICAGO: "chicago",
|
|
109
|
-
/** Ideograph digital numbering. */
|
|
110
|
-
IDEOGRAPH__DIGITAL: "ideographDigital",
|
|
111
|
-
/** Japanese counting system. */
|
|
112
|
-
JAPANESE_COUNTING: "japaneseCounting",
|
|
113
|
-
/** Japanese aiueo ordering. */
|
|
114
|
-
AIUEO: "aiueo",
|
|
115
|
-
/** Japanese iroha ordering. */
|
|
116
|
-
IROHA: "iroha",
|
|
117
|
-
/** Full-width decimal numbering. */
|
|
118
|
-
DECIMAL_FULL_WIDTH: "decimalFullWidth",
|
|
119
|
-
/** Half-width decimal numbering. */
|
|
120
|
-
DECIMAL_HALF_WIDTH: "decimalHalfWidth",
|
|
121
|
-
/** Japanese legal numbering. */
|
|
122
|
-
JAPANESE_LEGAL: "japaneseLegal",
|
|
123
|
-
/** Japanese digital ten thousand numbering. */
|
|
124
|
-
JAPANESE_DIGITAL_TEN_THOUSAND: "japaneseDigitalTenThousand",
|
|
125
|
-
/** Decimal numbers enclosed in circles. */
|
|
126
|
-
DECIMAL_ENCLOSED_CIRCLE: "decimalEnclosedCircle",
|
|
127
|
-
/** Full-width decimal numbering variant 2. */
|
|
128
|
-
DECIMAL_FULL_WIDTH2: "decimalFullWidth2",
|
|
129
|
-
/** Full-width aiueo ordering. */
|
|
130
|
-
AIUEO_FULL_WIDTH: "aiueoFullWidth",
|
|
131
|
-
/** Full-width iroha ordering. */
|
|
132
|
-
IROHA_FULL_WIDTH: "irohaFullWidth",
|
|
133
|
-
/** Decimal with leading zeros. */
|
|
134
|
-
DECIMAL_ZERO: "decimalZero",
|
|
135
|
-
/** Bullet points. */
|
|
136
|
-
BULLET: "bullet",
|
|
137
|
-
/** Korean ganada ordering. */
|
|
138
|
-
GANADA: "ganada",
|
|
139
|
-
/** Korean chosung ordering. */
|
|
140
|
-
CHOSUNG: "chosung",
|
|
141
|
-
/** Decimal enclosed with fullstop. */
|
|
142
|
-
DECIMAL_ENCLOSED_FULLSTOP: "decimalEnclosedFullstop",
|
|
143
|
-
/** Decimal enclosed in parentheses. */
|
|
144
|
-
DECIMAL_ENCLOSED_PARENTHESES: "decimalEnclosedParen",
|
|
145
|
-
/** Decimal enclosed in circles (Chinese). */
|
|
146
|
-
DECIMAL_ENCLOSED_CIRCLE_CHINESE: "decimalEnclosedCircleChinese",
|
|
147
|
-
/** Ideograph enclosed in circles. */
|
|
148
|
-
IDEOGRAPH_ENCLOSED_CIRCLE: "ideographEnclosedCircle",
|
|
149
|
-
/** Traditional ideograph numbering. */
|
|
150
|
-
IDEOGRAPH_TRADITIONAL: "ideographTraditional",
|
|
151
|
-
/** Ideograph zodiac numbering. */
|
|
152
|
-
IDEOGRAPH_ZODIAC: "ideographZodiac",
|
|
153
|
-
/** Traditional ideograph zodiac numbering. */
|
|
154
|
-
IDEOGRAPH_ZODIAC_TRADITIONAL: "ideographZodiacTraditional",
|
|
155
|
-
/** Taiwanese counting system. */
|
|
156
|
-
TAIWANESE_COUNTING: "taiwaneseCounting",
|
|
157
|
-
/** Traditional ideograph legal numbering. */
|
|
158
|
-
IDEOGRAPH_LEGAL_TRADITIONAL: "ideographLegalTraditional",
|
|
159
|
-
/** Taiwanese counting thousand system. */
|
|
160
|
-
TAIWANESE_COUNTING_THOUSAND: "taiwaneseCountingThousand",
|
|
161
|
-
/** Taiwanese digital numbering. */
|
|
162
|
-
TAIWANESE_DIGITAL: "taiwaneseDigital",
|
|
163
|
-
/** Chinese counting system. */
|
|
164
|
-
CHINESE_COUNTING: "chineseCounting",
|
|
165
|
-
/** Simplified Chinese legal numbering. */
|
|
166
|
-
CHINESE_LEGAL_SIMPLIFIED: "chineseLegalSimplified",
|
|
167
|
-
/** Chinese counting thousand system. */
|
|
168
|
-
CHINESE_COUNTING_THOUSAND: "chineseCountingThousand",
|
|
169
|
-
/** Korean digital numbering. */
|
|
170
|
-
KOREAN_DIGITAL: "koreanDigital",
|
|
171
|
-
/** Korean counting system. */
|
|
172
|
-
KOREAN_COUNTING: "koreanCounting",
|
|
173
|
-
/** Korean legal numbering. */
|
|
174
|
-
KOREAN_LEGAL: "koreanLegal",
|
|
175
|
-
/** Korean digital numbering variant 2. */
|
|
176
|
-
KOREAN_DIGITAL2: "koreanDigital2",
|
|
177
|
-
/** Vietnamese counting system. */
|
|
178
|
-
VIETNAMESE_COUNTING: "vietnameseCounting",
|
|
179
|
-
/** Russian lowercase numbering. */
|
|
180
|
-
RUSSIAN_LOWER: "russianLower",
|
|
181
|
-
/** Russian uppercase numbering. */
|
|
182
|
-
RUSSIAN_UPPER: "russianUpper",
|
|
183
|
-
/** No numbering. */
|
|
184
|
-
NONE: "none",
|
|
185
|
-
/** Number enclosed in dashes. */
|
|
186
|
-
NUMBER_IN_DASH: "numberInDash",
|
|
187
|
-
/** Hebrew numbering variant 1. */
|
|
188
|
-
HEBREW1: "hebrew1",
|
|
189
|
-
/** Hebrew numbering variant 2. */
|
|
190
|
-
HEBREW2: "hebrew2",
|
|
191
|
-
/** Arabic alpha numbering. */
|
|
192
|
-
ARABIC_ALPHA: "arabicAlpha",
|
|
193
|
-
/** Arabic abjad numbering. */
|
|
194
|
-
ARABIC_ABJAD: "arabicAbjad",
|
|
195
|
-
/** Hindi vowels. */
|
|
196
|
-
HINDI_VOWELS: "hindiVowels",
|
|
197
|
-
/** Hindi consonants. */
|
|
198
|
-
HINDI_CONSONANTS: "hindiConsonants",
|
|
199
|
-
/** Hindi numbers. */
|
|
200
|
-
HINDI_NUMBERS: "hindiNumbers",
|
|
201
|
-
/** Hindi counting system. */
|
|
202
|
-
HINDI_COUNTING: "hindiCounting",
|
|
203
|
-
/** Thai letters. */
|
|
204
|
-
THAI_LETTERS: "thaiLetters",
|
|
205
|
-
/** Thai numbers. */
|
|
206
|
-
THAI_NUMBERS: "thaiNumbers",
|
|
207
|
-
/** Thai counting system. */
|
|
208
|
-
THAI_COUNTING: "thaiCounting",
|
|
209
|
-
/** Thai Baht text. */
|
|
210
|
-
BAHT_TEXT: "bahtText",
|
|
211
|
-
/** Dollar text. */
|
|
212
|
-
DOLLAR_TEXT: "dollarText",
|
|
213
|
-
/** Custom numbering format. */
|
|
214
|
-
CUSTOM: "custom"
|
|
215
|
-
};
|
|
216
|
-
/**
|
|
217
|
-
* Suffix types for list levels.
|
|
218
|
-
*
|
|
219
|
-
* Defines what follows the numbering text (tab, space, or nothing).
|
|
220
|
-
*
|
|
221
|
-
* @publicApi
|
|
222
|
-
*/
|
|
223
|
-
const LevelSuffix = {
|
|
224
|
-
/** No separator after the numbering. */
|
|
225
|
-
NOTHING: "nothing",
|
|
226
|
-
/** Space character after the numbering. */
|
|
227
|
-
SPACE: "space",
|
|
228
|
-
/** Tab character after the numbering. */
|
|
229
|
-
TAB: "tab"
|
|
230
|
-
};
|
|
231
|
-
//#endregion
|
|
232
|
-
//#region src/parts/numbering/numbering.ts
|
|
233
|
-
/**
|
|
234
|
-
* Numbering module for WordprocessingML documents.
|
|
235
|
-
*
|
|
236
|
-
* Numbering provides support for numbered and bulleted lists.
|
|
237
|
-
* Pure string serialization — no XmlComponent inheritance.
|
|
238
|
-
*
|
|
239
|
-
* Reference: http://officeopenxml.com/WPnumbering.php
|
|
240
|
-
*
|
|
241
|
-
* @module
|
|
242
|
-
*/
|
|
243
|
-
/** Namespace attributes for w:numbering (pre-computed constant). */
|
|
244
|
-
const NUMBERING_ATTRS = "xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" mc:Ignorable=\"w14 w15 wp14\"";
|
|
245
|
-
/** Default bullet levels (9 levels: 0-8). */
|
|
246
|
-
const DEFAULT_BULLET_LEVELS = [
|
|
247
|
-
{
|
|
248
|
-
alignment: AlignmentType.LEFT,
|
|
249
|
-
format: LevelFormat.BULLET,
|
|
250
|
-
level: 0,
|
|
251
|
-
style: { paragraph: { indent: {
|
|
252
|
-
hanging: convertInchesToTwip(.25),
|
|
253
|
-
left: convertInchesToTwip(.5)
|
|
254
|
-
} } },
|
|
255
|
-
text: "●"
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
alignment: AlignmentType.LEFT,
|
|
259
|
-
format: LevelFormat.BULLET,
|
|
260
|
-
level: 1,
|
|
261
|
-
style: { paragraph: { indent: {
|
|
262
|
-
hanging: convertInchesToTwip(.25),
|
|
263
|
-
left: convertInchesToTwip(1)
|
|
264
|
-
} } },
|
|
265
|
-
text: "○"
|
|
266
|
-
},
|
|
267
|
-
{
|
|
268
|
-
alignment: AlignmentType.LEFT,
|
|
269
|
-
format: LevelFormat.BULLET,
|
|
270
|
-
level: 2,
|
|
271
|
-
style: { paragraph: { indent: {
|
|
272
|
-
hanging: convertInchesToTwip(.25),
|
|
273
|
-
left: 2160
|
|
274
|
-
} } },
|
|
275
|
-
text: "■"
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
alignment: AlignmentType.LEFT,
|
|
279
|
-
format: LevelFormat.BULLET,
|
|
280
|
-
level: 3,
|
|
281
|
-
style: { paragraph: { indent: {
|
|
282
|
-
hanging: convertInchesToTwip(.25),
|
|
283
|
-
left: 2880
|
|
284
|
-
} } },
|
|
285
|
-
text: "●"
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
alignment: AlignmentType.LEFT,
|
|
289
|
-
format: LevelFormat.BULLET,
|
|
290
|
-
level: 4,
|
|
291
|
-
style: { paragraph: { indent: {
|
|
292
|
-
hanging: convertInchesToTwip(.25),
|
|
293
|
-
left: 3600
|
|
294
|
-
} } },
|
|
295
|
-
text: "○"
|
|
296
|
-
},
|
|
297
|
-
{
|
|
298
|
-
alignment: AlignmentType.LEFT,
|
|
299
|
-
format: LevelFormat.BULLET,
|
|
300
|
-
level: 5,
|
|
301
|
-
style: { paragraph: { indent: {
|
|
302
|
-
hanging: convertInchesToTwip(.25),
|
|
303
|
-
left: 4320
|
|
304
|
-
} } },
|
|
305
|
-
text: "■"
|
|
306
|
-
},
|
|
307
|
-
{
|
|
308
|
-
alignment: AlignmentType.LEFT,
|
|
309
|
-
format: LevelFormat.BULLET,
|
|
310
|
-
level: 6,
|
|
311
|
-
style: { paragraph: { indent: {
|
|
312
|
-
hanging: convertInchesToTwip(.25),
|
|
313
|
-
left: 5040
|
|
314
|
-
} } },
|
|
315
|
-
text: "●"
|
|
316
|
-
},
|
|
317
|
-
{
|
|
318
|
-
alignment: AlignmentType.LEFT,
|
|
319
|
-
format: LevelFormat.BULLET,
|
|
320
|
-
level: 7,
|
|
321
|
-
style: { paragraph: { indent: {
|
|
322
|
-
hanging: convertInchesToTwip(.25),
|
|
323
|
-
left: 5760
|
|
324
|
-
} } },
|
|
325
|
-
text: "●"
|
|
326
|
-
},
|
|
327
|
-
{
|
|
328
|
-
alignment: AlignmentType.LEFT,
|
|
329
|
-
format: LevelFormat.BULLET,
|
|
330
|
-
level: 8,
|
|
331
|
-
style: { paragraph: { indent: {
|
|
332
|
-
hanging: convertInchesToTwip(.25),
|
|
333
|
-
left: 6480
|
|
334
|
-
} } },
|
|
335
|
-
text: "●"
|
|
336
|
-
}
|
|
337
|
-
];
|
|
338
|
-
/**
|
|
339
|
-
* Numbering definitions for a WordprocessingML document.
|
|
340
|
-
*
|
|
341
|
-
* Pure data accumulator — no XmlComponent inheritance.
|
|
342
|
-
* Serializes via `serialize()` producing a complete XML part.
|
|
343
|
-
*/
|
|
344
|
-
var Numbering = class {
|
|
345
|
-
abstractNumberingData = /* @__PURE__ */ new Map();
|
|
346
|
-
concreteNumberingData = /* @__PURE__ */ new Map();
|
|
347
|
-
referenceConfigMap = /* @__PURE__ */ new Map();
|
|
348
|
-
abstractNumUniqueNumericId = uniqueNumericIdCreator();
|
|
349
|
-
concreteNumUniqueNumericId = uniqueNumericIdCreator(1);
|
|
350
|
-
_numIdMacAtCleanup;
|
|
351
|
-
_numPicBullets;
|
|
352
|
-
constructor(options) {
|
|
353
|
-
this._numIdMacAtCleanup = options.numIdMacAtCleanup;
|
|
354
|
-
this._numPicBullets = options.numPicBullets;
|
|
355
|
-
if (options.config.length === 0) {
|
|
356
|
-
const defaultAbstractId = this.abstractNumUniqueNumericId();
|
|
357
|
-
this.abstractNumberingData.set("default-bullet-numbering", {
|
|
358
|
-
id: defaultAbstractId,
|
|
359
|
-
levels: DEFAULT_BULLET_LEVELS
|
|
360
|
-
});
|
|
361
|
-
this.concreteNumberingData.set("default-bullet-numbering", {
|
|
362
|
-
abstractNumId: defaultAbstractId,
|
|
363
|
-
instance: 0,
|
|
364
|
-
numId: 1,
|
|
365
|
-
overrideLevels: [{
|
|
366
|
-
num: 0,
|
|
367
|
-
start: 1
|
|
368
|
-
}],
|
|
369
|
-
reference: "default-bullet-numbering"
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
for (const con of options.config) {
|
|
373
|
-
this.abstractNumberingData.set(con.reference, {
|
|
374
|
-
id: this.abstractNumUniqueNumericId(),
|
|
375
|
-
levels: con.levels,
|
|
376
|
-
extraOptions: con.extraOptions
|
|
377
|
-
});
|
|
378
|
-
this.referenceConfigMap.set(con.reference, con.levels);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
/** Serialize to word/numbering.xml content (with XML declaration). */
|
|
382
|
-
serialize() {
|
|
383
|
-
const parts = [];
|
|
384
|
-
parts.push(`<w:numbering ${NUMBERING_ATTRS}>`);
|
|
385
|
-
if (this._numPicBullets) for (const bullet of this._numPicBullets) if (bullet.pict) parts.push(`<w:numPicBullet w:numPicBulletId="${bullet.numPicBulletId}">${bullet.pict}</w:numPicBullet>`);
|
|
386
|
-
else parts.push(`<w:numPicBullet w:numPicBulletId="${bullet.numPicBulletId}"/>`);
|
|
387
|
-
for (const an of this.abstractNumberingData.values()) parts.push(stringifyAbstractNumbering(an.id, an.levels, an.extraOptions));
|
|
388
|
-
for (const cn of this.concreteNumberingData.values()) parts.push(stringifyConcreteNumbering(cn));
|
|
389
|
-
if (this._numIdMacAtCleanup !== void 0) parts.push(`<w:numIdMacAtCleanup w:val="${decimalNumber(this._numIdMacAtCleanup)}"/>`);
|
|
390
|
-
parts.push("</w:numbering>");
|
|
391
|
-
return "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + parts.join("");
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* Creates a concrete numbering instance from an abstract numbering definition.
|
|
395
|
-
*/
|
|
396
|
-
createConcreteNumberingInstance(reference, instance) {
|
|
397
|
-
const abstractNumbering = this.abstractNumberingData.get(reference);
|
|
398
|
-
if (!abstractNumbering) return;
|
|
399
|
-
const fullReference = `${reference}-${instance}`;
|
|
400
|
-
if (this.concreteNumberingData.has(fullReference)) return;
|
|
401
|
-
const firstLevelStartNumber = this.referenceConfigMap.get(reference)?.[0]?.start;
|
|
402
|
-
const overrideLevels = typeof firstLevelStartNumber === "number" && Number.isInteger(firstLevelStartNumber) && firstLevelStartNumber !== 1 ? [{
|
|
403
|
-
num: 0,
|
|
404
|
-
start: firstLevelStartNumber
|
|
405
|
-
}] : void 0;
|
|
406
|
-
this.concreteNumberingData.set(fullReference, {
|
|
407
|
-
abstractNumId: abstractNumbering.id,
|
|
408
|
-
instance,
|
|
409
|
-
numId: this.concreteNumUniqueNumericId(),
|
|
410
|
-
overrideLevels,
|
|
411
|
-
reference
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
/** Gets all concrete numbering instances. */
|
|
415
|
-
get concreteNumbering() {
|
|
416
|
-
return [...this.concreteNumberingData.values()];
|
|
417
|
-
}
|
|
418
|
-
/** Gets all reference configurations. */
|
|
419
|
-
get referenceConfig() {
|
|
420
|
-
return [...this.referenceConfigMap.values()];
|
|
421
|
-
}
|
|
422
|
-
};
|
|
423
|
-
function stringifyAbstractNumbering(id, levels, extraOptions) {
|
|
424
|
-
const parts = [];
|
|
425
|
-
const restartAttr = extraOptions?.restartNumberingAfterBreak !== void 0 ? ` w15:restartNumberingAfterBreak="${extraOptions.restartNumberingAfterBreak ? 1 : 0}"` : "";
|
|
426
|
-
parts.push(`<w:abstractNum w:abstractNumId="${decimalNumber(id)}"${restartAttr}>`);
|
|
427
|
-
if (extraOptions?.nsid !== void 0) parts.push(`<w:nsid w:val="${extraOptions.nsid}"/>`);
|
|
428
|
-
parts.push(`<w:multiLevelType w:val="${extraOptions?.multiLevelType ?? "hybridMultilevel"}"/>`);
|
|
429
|
-
if (extraOptions?.tmpl !== void 0) parts.push(`<w:tmpl w:val="${extraOptions.tmpl}"/>`);
|
|
430
|
-
if (extraOptions?.name !== void 0) parts.push(`<w:name w:val="${extraOptions.name}"/>`);
|
|
431
|
-
if (extraOptions?.styleLink !== void 0) parts.push(`<w:styleLink w:val="${extraOptions.styleLink}"/>`);
|
|
432
|
-
if (extraOptions?.numStyleLink !== void 0) parts.push(`<w:numStyleLink w:val="${extraOptions.numStyleLink}"/>`);
|
|
433
|
-
for (const level of levels) parts.push(stringifyLevel(level));
|
|
434
|
-
parts.push("</w:abstractNum>");
|
|
435
|
-
return parts.join("");
|
|
436
|
-
}
|
|
437
|
-
function stringifyConcreteNumbering(cn) {
|
|
438
|
-
const parts = [];
|
|
439
|
-
parts.push(`<w:num w:numId="${decimalNumber(cn.numId)}">`);
|
|
440
|
-
parts.push(`<w:abstractNumId w:val="${decimalNumber(cn.abstractNumId)}"/>`);
|
|
441
|
-
if (cn.overrideLevels) for (const level of cn.overrideLevels) if (level.start !== void 0) parts.push(`<w:lvlOverride w:ilvl="${level.num}"><w:startOverride w:val="${level.start}"/></w:lvlOverride>`);
|
|
442
|
-
else parts.push(`<w:lvlOverride w:ilvl="${level.num}"/>`);
|
|
443
|
-
parts.push("</w:num>");
|
|
444
|
-
return parts.join("");
|
|
445
|
-
}
|
|
446
|
-
function stringifyLevel(opts) {
|
|
447
|
-
const children = [];
|
|
448
|
-
children.push(`<w:start w:val="${decimalNumber(opts.start ?? 1)}"/>`);
|
|
449
|
-
if (opts.format) children.push(`<w:numFmt w:val="${opts.format}"/>`);
|
|
450
|
-
if (opts.lvlRestart !== void 0) children.push(`<w:lvlRestart w:val="${decimalNumber(opts.lvlRestart)}"/>`);
|
|
451
|
-
if (opts.paragraphStyle !== void 0) children.push(`<w:pStyle w:val="${opts.paragraphStyle}"/>`);
|
|
452
|
-
if (opts.isLegalNumberingStyle) children.push("<w:isLgl/>");
|
|
453
|
-
if (opts.suffix) children.push(`<w:suff w:val="${opts.suffix}"/>`);
|
|
454
|
-
if (opts.text !== void 0 || opts.textNull) {
|
|
455
|
-
const lvlTextAttrs = [];
|
|
456
|
-
if (opts.text !== void 0) lvlTextAttrs.push(`w:val="${opts.text}"`);
|
|
457
|
-
if (opts.textNull) lvlTextAttrs.push("w:null=\"1\"");
|
|
458
|
-
children.push(`<w:lvlText ${lvlTextAttrs.join(" ")}/>`);
|
|
459
|
-
}
|
|
460
|
-
if (opts.lvlPicBulletId !== void 0) children.push(`<w:lvlPicBulletId w:val="${decimalNumber(opts.lvlPicBulletId)}"/>`);
|
|
461
|
-
if (opts.legacy !== void 0) {
|
|
462
|
-
const legacyAttrs = [`w:legacy="${opts.legacy.enabled ?? true ? 1 : 0}"`];
|
|
463
|
-
if (opts.legacy.space !== void 0) legacyAttrs.push(`w:legacySpace="${opts.legacy.space}"`);
|
|
464
|
-
if (opts.legacy.indent !== void 0) legacyAttrs.push(`w:legacyIndent="${opts.legacy.indent}"`);
|
|
465
|
-
children.push(`<w:legacy ${legacyAttrs.join(" ")}/>`);
|
|
466
|
-
}
|
|
467
|
-
children.push(`<w:lvlJc w:val="${opts.alignment ?? AlignmentType.START}"/>`);
|
|
468
|
-
const pPrXml = stringifyParagraphProperties(opts.style && opts.style.paragraph).xml;
|
|
469
|
-
const rPrXml = stringifyRunProperties(opts.style && opts.style.run);
|
|
470
|
-
if (pPrXml) children.push(pPrXml);
|
|
471
|
-
if (rPrXml) children.push(rPrXml);
|
|
472
|
-
const lvlAttrs = [`w:ilvl="${decimalNumber(Math.min(opts.level, 9))}"`];
|
|
473
|
-
if (opts.w15Tentative !== void 0) lvlAttrs.push(`w15:tentative="${opts.w15Tentative ? 1 : 0}"`);
|
|
474
|
-
if (opts.templateCode !== void 0) lvlAttrs.push(`w:tplc="${opts.templateCode}"`);
|
|
475
|
-
if (opts.tentative !== void 0) lvlAttrs.push(`w:tentative="${opts.tentative ? 1 : 0}"`);
|
|
476
|
-
return `<w:lvl ${lvlAttrs.join(" ")}>${children.join("")}</w:lvl>`;
|
|
477
|
-
}
|
|
478
|
-
/**
|
|
479
|
-
* Parse w:numbering element into NumberingOptions.
|
|
480
|
-
*/
|
|
481
|
-
function parseNumberingDefinitions(el, parseParagraphProperties, ctx) {
|
|
482
|
-
const abstractNums = /* @__PURE__ */ new Map();
|
|
483
|
-
for (const child of el.elements ?? []) {
|
|
484
|
-
if (child.name !== "w:abstractNum") continue;
|
|
485
|
-
const id = attr(child, "w:abstractNumId");
|
|
486
|
-
if (id !== void 0) abstractNums.set(id, child);
|
|
487
|
-
}
|
|
488
|
-
const numToAbstract = /* @__PURE__ */ new Map();
|
|
489
|
-
for (const child of el.elements ?? []) {
|
|
490
|
-
if (child.name !== "w:num") continue;
|
|
491
|
-
const numId = attr(child, "w:numId");
|
|
492
|
-
const abstractRef = findChild(child, "w:abstractNumId");
|
|
493
|
-
const abstractId = abstractRef ? attr(abstractRef, "w:val") : void 0;
|
|
494
|
-
if (numId !== void 0 && abstractId !== void 0) numToAbstract.set(numId, abstractId);
|
|
495
|
-
}
|
|
496
|
-
const configs = [];
|
|
497
|
-
for (const [numId, abstractId] of numToAbstract) {
|
|
498
|
-
const abstractEl = abstractNums.get(abstractId);
|
|
499
|
-
if (!abstractEl) continue;
|
|
500
|
-
const levels = [];
|
|
501
|
-
for (const child of abstractEl.elements ?? []) {
|
|
502
|
-
if (child.name !== "w:lvl") continue;
|
|
503
|
-
const levelOpts = parseLevelEl(child, parseParagraphProperties, ctx);
|
|
504
|
-
if (levelOpts) levels.push(levelOpts);
|
|
505
|
-
}
|
|
506
|
-
if (levels.length > 0) {
|
|
507
|
-
const extraOptions = {};
|
|
508
|
-
const nsidEl = findChild(abstractEl, "w:nsid");
|
|
509
|
-
if (nsidEl) {
|
|
510
|
-
const v = attr(nsidEl, "w:val");
|
|
511
|
-
if (v) extraOptions.nsid = v;
|
|
512
|
-
}
|
|
513
|
-
const multiLevelTypeEl = findChild(abstractEl, "w:multiLevelType");
|
|
514
|
-
if (multiLevelTypeEl) {
|
|
515
|
-
const v = attr(multiLevelTypeEl, "w:val");
|
|
516
|
-
if (v) extraOptions.multiLevelType = v;
|
|
517
|
-
}
|
|
518
|
-
const restartVal = attrBool(abstractEl, "w15:restartNumberingAfterBreak");
|
|
519
|
-
if (restartVal !== void 0) extraOptions.restartNumberingAfterBreak = restartVal;
|
|
520
|
-
const tmplEl = findChild(abstractEl, "w:tmpl");
|
|
521
|
-
if (tmplEl) {
|
|
522
|
-
const v = attr(tmplEl, "w:val");
|
|
523
|
-
if (v) extraOptions.tmpl = v;
|
|
524
|
-
}
|
|
525
|
-
configs.push({
|
|
526
|
-
reference: `list_${numId}`,
|
|
527
|
-
levels,
|
|
528
|
-
extraOptions
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
if (configs.length === 0) return void 0;
|
|
533
|
-
return { config: configs };
|
|
534
|
-
}
|
|
535
|
-
function parseLevelEl(el, parseParagraphProperties, ctx) {
|
|
536
|
-
const opts = {};
|
|
537
|
-
const level = attrNum(el, "w:ilvl");
|
|
538
|
-
if (level !== void 0) opts.level = level;
|
|
539
|
-
const start = findChild(el, "w:start");
|
|
540
|
-
if (start) {
|
|
541
|
-
const val = attrNum(start, "w:val");
|
|
542
|
-
if (val !== void 0) opts.start = val;
|
|
543
|
-
}
|
|
544
|
-
const lvlRestart = findChild(el, "w:lvlRestart");
|
|
545
|
-
if (lvlRestart) {
|
|
546
|
-
const val = attrNum(lvlRestart, "w:val");
|
|
547
|
-
if (val !== void 0) opts.lvlRestart = val;
|
|
548
|
-
}
|
|
549
|
-
const numFmt = findChild(el, "w:numFmt");
|
|
550
|
-
if (numFmt) {
|
|
551
|
-
const val = attr(numFmt, "w:val");
|
|
552
|
-
if (val) opts.format = val;
|
|
553
|
-
}
|
|
554
|
-
const suff = findChild(el, "w:suff");
|
|
555
|
-
if (suff) {
|
|
556
|
-
const val = attr(suff, "w:val");
|
|
557
|
-
if (val) opts.suffix = val;
|
|
558
|
-
}
|
|
559
|
-
const pStyle = findChild(el, "w:pStyle");
|
|
560
|
-
if (pStyle) {
|
|
561
|
-
const val = attr(pStyle, "w:val");
|
|
562
|
-
if (val) opts.paragraphStyle = val;
|
|
563
|
-
}
|
|
564
|
-
if (findChild(el, "w:isLgl")) opts.isLegalNumberingStyle = true;
|
|
565
|
-
const lvlText = findChild(el, "w:lvlText");
|
|
566
|
-
if (lvlText) {
|
|
567
|
-
const val = attr(lvlText, "w:val");
|
|
568
|
-
if (val) opts.text = val;
|
|
569
|
-
const isNull = attrBool(lvlText, "w:null");
|
|
570
|
-
if (isNull) opts.textNull = isNull;
|
|
571
|
-
}
|
|
572
|
-
const lvlPicBulletId = findChild(el, "w:lvlPicBulletId");
|
|
573
|
-
if (lvlPicBulletId) {
|
|
574
|
-
const val = attrNum(lvlPicBulletId, "w:val");
|
|
575
|
-
if (val !== void 0) opts.lvlPicBulletId = val;
|
|
576
|
-
}
|
|
577
|
-
const legacyEl = findChild(el, "w:legacy");
|
|
578
|
-
if (legacyEl) {
|
|
579
|
-
const legacy = {};
|
|
580
|
-
const enabled = attrBool(legacyEl, "w:legacy");
|
|
581
|
-
if (enabled !== void 0) legacy.enabled = enabled;
|
|
582
|
-
const space = attrNum(legacyEl, "w:legacySpace");
|
|
583
|
-
if (space !== void 0) legacy.space = space;
|
|
584
|
-
const indent = attrNum(legacyEl, "w:legacyIndent");
|
|
585
|
-
if (indent !== void 0) legacy.indent = indent;
|
|
586
|
-
opts.legacy = legacy;
|
|
587
|
-
}
|
|
588
|
-
const lvlJc = findChild(el, "w:lvlJc");
|
|
589
|
-
if (lvlJc) {
|
|
590
|
-
const val = attr(lvlJc, "w:val");
|
|
591
|
-
if (val) opts.alignment = val;
|
|
592
|
-
}
|
|
593
|
-
const tplc = attr(el, "w:tplc");
|
|
594
|
-
if (tplc) opts.templateCode = tplc;
|
|
595
|
-
const tentative = attrBool(el, "w:tentative");
|
|
596
|
-
if (tentative !== void 0) opts.tentative = tentative;
|
|
597
|
-
const w15Tentative = attrBool(el, "w15:tentative");
|
|
598
|
-
if (w15Tentative !== void 0) opts.w15Tentative = w15Tentative;
|
|
599
|
-
const style = {};
|
|
600
|
-
const rPr = findChild(el, "w:rPr");
|
|
601
|
-
if (rPr) {
|
|
602
|
-
const runOpts = parseRunProperties(rPr);
|
|
603
|
-
if (Object.keys(runOpts).length > 0) style.run = runOpts;
|
|
604
|
-
}
|
|
605
|
-
const pPr = findChild(el, "w:pPr");
|
|
606
|
-
if (pPr) {
|
|
607
|
-
const paraOpts = parseParagraphProperties(pPr, ctx);
|
|
608
|
-
if (Object.keys(paraOpts).length > 0) style.paragraph = paraOpts;
|
|
609
|
-
}
|
|
610
|
-
if (Object.keys(style).length > 0) opts.style = style;
|
|
611
|
-
return Object.keys(opts).length > 0 ? opts : void 0;
|
|
612
|
-
}
|
|
613
|
-
//#endregion
|
|
614
|
-
//#region src/parts/styles/factory.ts
|
|
615
|
-
/**
|
|
616
|
-
* Build CT_Style style-level children (name…rsid), shared by paragraph/character/table styles.
|
|
617
|
-
* Order follows CT_Style sequence: name, aliases, basedOn, next, link, autoRedefine, hidden,
|
|
618
|
-
* uiPriority, semiHidden, unhideWhenUsed, qFormat, locked, personal, personalCompose,
|
|
619
|
-
* personalReply, rsid.
|
|
620
|
-
*/
|
|
621
|
-
function stringifyStyleLevelChildren(opts) {
|
|
622
|
-
const parts = [`<w:name w:val="${escapeXml(opts.name ?? opts.id ?? "")}"/>`];
|
|
623
|
-
if (opts.aliases) parts.push(`<w:aliases w:val="${escapeXml(opts.aliases)}"/>`);
|
|
624
|
-
if (opts.basedOn) parts.push(`<w:basedOn w:val="${escapeXml(opts.basedOn)}"/>`);
|
|
625
|
-
if (opts.next) parts.push(`<w:next w:val="${escapeXml(opts.next)}"/>`);
|
|
626
|
-
if (opts.link) parts.push(`<w:link w:val="${escapeXml(opts.link)}"/>`);
|
|
627
|
-
if (opts.autoRedefine) parts.push("<w:autoRedefine/>");
|
|
628
|
-
if (opts.hidden) parts.push("<w:hidden/>");
|
|
629
|
-
if (opts.uiPriority !== void 0) parts.push(`<w:uiPriority w:val="${opts.uiPriority}"/>`);
|
|
630
|
-
if (opts.semiHidden) parts.push("<w:semiHidden/>");
|
|
631
|
-
if (opts.unhideWhenUsed) parts.push("<w:unhideWhenUsed/>");
|
|
632
|
-
if (opts.quickFormat) parts.push("<w:qFormat/>");
|
|
633
|
-
if (opts.locked) parts.push("<w:locked/>");
|
|
634
|
-
if (opts.personal) parts.push("<w:personal/>");
|
|
635
|
-
if (opts.personalCompose) parts.push("<w:personalCompose/>");
|
|
636
|
-
if (opts.personalReply) parts.push("<w:personalReply/>");
|
|
637
|
-
if (opts.rsid) parts.push(`<w:rsid w:val="${opts.rsid}"/>`);
|
|
638
|
-
return parts.join("");
|
|
639
|
-
}
|
|
640
|
-
/**
|
|
641
|
-
* Build the `<w:style>` opening tag: type/styleId plus the optional w:default
|
|
642
|
-
* and w:customStyle element attributes (CT_Style). Shared by paragraph/
|
|
643
|
-
* character/table styles.
|
|
644
|
-
*/
|
|
645
|
-
function styleOpenTag(type, opts) {
|
|
646
|
-
let attrs = ` w:type="${type}" w:styleId="${escapeXml(opts.id ?? "")}"`;
|
|
647
|
-
if (opts.default) attrs += " w:default=\"1\"";
|
|
648
|
-
if (opts.customStyle) attrs += " w:customStyle=\"1\"";
|
|
649
|
-
return `<w:style${attrs}>`;
|
|
650
|
-
}
|
|
651
|
-
/** Build `<w:style>` XML for a paragraph style. */
|
|
652
|
-
function stringifyParagraphStyle(opts) {
|
|
653
|
-
const children = [stringifyStyleLevelChildren(opts)];
|
|
654
|
-
const pPr = stringifyParagraphProperties(opts.paragraph).xml;
|
|
655
|
-
if (pPr) children.push(pPr);
|
|
656
|
-
const rPr = stringifyRunProperties(opts.run);
|
|
657
|
-
if (rPr) children.push(rPr);
|
|
658
|
-
return `${styleOpenTag("paragraph", opts)}${children.join("")}</w:style>`;
|
|
659
|
-
}
|
|
660
|
-
/** Build `<w:style>` XML for a character style. */
|
|
661
|
-
function stringifyCharacterStyle(opts) {
|
|
662
|
-
const children = [stringifyStyleLevelChildren(opts)];
|
|
663
|
-
const rPr = stringifyRunProperties(opts.run);
|
|
664
|
-
if (rPr) children.push(rPr);
|
|
665
|
-
return `${styleOpenTag("character", opts)}${children.join("")}</w:style>`;
|
|
666
|
-
}
|
|
667
|
-
/** Build `<w:tblStylePr>` XML for a conditional table style format. */
|
|
668
|
-
function stringifyConditionalTableStyle(opts) {
|
|
669
|
-
const children = [];
|
|
670
|
-
const pPr = stringifyParagraphProperties(opts.paragraph).xml;
|
|
671
|
-
if (pPr) children.push(pPr);
|
|
672
|
-
const rPr = stringifyRunProperties(opts.run);
|
|
673
|
-
if (rPr) children.push(rPr);
|
|
674
|
-
if (opts.table) {
|
|
675
|
-
const tblPr = stringifyTableProperties(opts.table);
|
|
676
|
-
if (tblPr) children.push(tblPr);
|
|
677
|
-
}
|
|
678
|
-
if (opts.row) {
|
|
679
|
-
const trPr = stringifyTableRowProperties(opts.row);
|
|
680
|
-
if (trPr) children.push(trPr);
|
|
681
|
-
}
|
|
682
|
-
if (opts.cell) {
|
|
683
|
-
const tcPr = stringifyTableCellProperties(opts.cell);
|
|
684
|
-
if (tcPr) children.push(tcPr);
|
|
685
|
-
}
|
|
686
|
-
return `<w:tblStylePr w:type="${opts.type}">${children.join("")}</w:tblStylePr>`;
|
|
687
|
-
}
|
|
688
|
-
/** Build `<w:style type="table">` XML for a table style. */
|
|
689
|
-
function stringifyTableStyle(opts) {
|
|
690
|
-
const children = [stringifyStyleLevelChildren(opts)];
|
|
691
|
-
const pPr = stringifyParagraphProperties(opts.paragraph).xml;
|
|
692
|
-
if (pPr) children.push(pPr);
|
|
693
|
-
const rPr = stringifyRunProperties(opts.run);
|
|
694
|
-
if (rPr) children.push(rPr);
|
|
695
|
-
if (opts.table) {
|
|
696
|
-
const tblPr = stringifyTableProperties(opts.table);
|
|
697
|
-
if (tblPr) children.push(tblPr);
|
|
698
|
-
}
|
|
699
|
-
if (opts.row) {
|
|
700
|
-
const trPr = stringifyTableRowProperties(opts.row);
|
|
701
|
-
if (trPr) children.push(trPr);
|
|
702
|
-
}
|
|
703
|
-
if (opts.cell) {
|
|
704
|
-
const tcPr = stringifyTableCellProperties(opts.cell);
|
|
705
|
-
if (tcPr) children.push(tcPr);
|
|
706
|
-
}
|
|
707
|
-
for (const cf of opts.conditionalFormats ?? []) children.push(stringifyConditionalTableStyle(cf));
|
|
708
|
-
return `${styleOpenTag("table", opts)}${children.join("")}</w:style>`;
|
|
709
|
-
}
|
|
710
|
-
/** Build `<w:style type="numbering">` XML for a numbering style. */
|
|
711
|
-
function stringifyNumberingStyle(opts) {
|
|
712
|
-
const children = [stringifyStyleLevelChildren(opts)];
|
|
713
|
-
const pPr = stringifyParagraphProperties(opts.paragraph).xml;
|
|
714
|
-
if (pPr) children.push(pPr);
|
|
715
|
-
const rPr = stringifyRunProperties(opts.run);
|
|
716
|
-
if (rPr) children.push(rPr);
|
|
717
|
-
return `${styleOpenTag("numbering", opts)}${children.join("")}</w:style>`;
|
|
718
|
-
}
|
|
719
|
-
/** Resolve a user override for heading level N (1-9) from default styles options. */
|
|
720
|
-
function headingOverride(options, level) {
|
|
721
|
-
switch (level) {
|
|
722
|
-
case 1: return options.heading1;
|
|
723
|
-
case 2: return options.heading2;
|
|
724
|
-
case 3: return options.heading3;
|
|
725
|
-
case 4: return options.heading4;
|
|
726
|
-
case 5: return options.heading5;
|
|
727
|
-
case 6: return options.heading6;
|
|
728
|
-
case 7: return options.heading7;
|
|
729
|
-
case 8: return options.heading8;
|
|
730
|
-
case 9: return options.heading9;
|
|
731
|
-
default: return;
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
/** Word's default `<w:rPrDefault>` — theme fonts, kern, 11pt, ligatures. Injected
|
|
735
|
-
* for fresh documents (no structured docDefaults provided) to mirror Word's
|
|
736
|
-
* Normal.dotx. On round-trip the structured form is used instead. */
|
|
737
|
-
const WORD_DEFAULT_RPR_DEFAULT = "<w:rPrDefault><w:rPr><w:rFonts w:asciiTheme=\"minorHAnsi\" w:eastAsiaTheme=\"minorEastAsia\" w:hAnsiTheme=\"minorHAnsi\" w:cstheme=\"minorBidi\"/><w:kern w:val=\"2\"/><w:sz w:val=\"22\"/><w:szCs w:val=\"24\"/><w:lang w:val=\"en-US\" w:eastAsia=\"zh-CN\" w:bidi=\"ar-SA\"/><w14:ligatures w14:val=\"standardContextual\"/></w:rPr></w:rPrDefault>";
|
|
738
|
-
/** Word's default `<w:pPrDefault>` — widow/orphan control + 8pt after / 1.16 line.
|
|
739
|
-
* Injected for fresh documents only. */
|
|
740
|
-
const WORD_DEFAULT_PPR_DEFAULT = "<w:pPrDefault><w:pPr><w:widowControl/><w:spacing w:after=\"160\" w:line=\"278\" w:lineRule=\"auto\"/></w:pPr></w:pPrDefault>";
|
|
741
|
-
/**
|
|
742
|
-
* Build `<w:docDefaults>` XML from a structured {@link DocumentDefaultsOptions}.
|
|
743
|
-
*
|
|
744
|
-
* Three states per run/paragraph:
|
|
745
|
-
* - object → structured child element
|
|
746
|
-
* - null → explicit empty tag (`<w:pPrDefault/>`) — the source declared "no
|
|
747
|
-
* defaults here", so Word does NOT inject its own spacing. Distinct
|
|
748
|
-
* from absence (ECMA-376: empty pPrDefault suppresses default
|
|
749
|
-
* spacing; a missing pPrDefault is application-defined).
|
|
750
|
-
* - undefined → field is missing. On fresh generation (`injectDefaults`) we
|
|
751
|
-
* mirror Word's Normal.dotx; on round-trip we omit the element
|
|
752
|
-
* to preserve the source's "this default category is absent".
|
|
753
|
-
*/
|
|
754
|
-
function stringifyDocDefaults(opts, injectDefaults = true) {
|
|
755
|
-
const children = [];
|
|
756
|
-
if (opts.run) {
|
|
757
|
-
const rPr = stringifyRunProperties(opts.run);
|
|
758
|
-
children.push(rPr ? `<w:rPrDefault>${rPr}</w:rPrDefault>` : `<w:rPrDefault/>`);
|
|
759
|
-
} else if (opts.run === null) children.push(`<w:rPrDefault/>`);
|
|
760
|
-
else if (injectDefaults) children.push(WORD_DEFAULT_RPR_DEFAULT);
|
|
761
|
-
if (opts.paragraph) {
|
|
762
|
-
const pPr = stringifyParagraphProperties(opts.paragraph).xml;
|
|
763
|
-
children.push(pPr ? `<w:pPrDefault>${pPr}</w:pPrDefault>` : `<w:pPrDefault/>`);
|
|
764
|
-
} else if (opts.paragraph === null) children.push(`<w:pPrDefault/>`);
|
|
765
|
-
else if (injectDefaults) children.push(WORD_DEFAULT_PPR_DEFAULT);
|
|
766
|
-
return `<w:docDefaults>${children.join("")}</w:docDefaults>`;
|
|
767
|
-
}
|
|
768
|
-
let cachedDefaultStyles = null;
|
|
769
|
-
/**
|
|
770
|
-
* Factory for creating default document styles.
|
|
771
|
-
*
|
|
772
|
-
* Creates styles matching Microsoft Word's default document template.
|
|
773
|
-
* Pure string generation — no XmlComponent inheritance.
|
|
774
|
-
*/
|
|
775
|
-
var DefaultStylesFactory = class {
|
|
776
|
-
newInstance(options = {}) {
|
|
777
|
-
if (Object.keys(options).length === 0) {
|
|
778
|
-
if (!cachedDefaultStyles) cachedDefaultStyles = this.build({});
|
|
779
|
-
return cachedDefaultStyles;
|
|
780
|
-
}
|
|
781
|
-
return this.build(options);
|
|
782
|
-
}
|
|
783
|
-
build(options) {
|
|
784
|
-
const importedStyles = [];
|
|
785
|
-
const paragraphStyles = [];
|
|
786
|
-
const characterStyles = [];
|
|
787
|
-
const tableStyles = [];
|
|
788
|
-
const numberingStyles = [];
|
|
789
|
-
const initialAttributes = {
|
|
790
|
-
"xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
|
|
791
|
-
"xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
|
|
792
|
-
"xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
|
|
793
|
-
"xmlns:w14": "http://schemas.microsoft.com/office/word/2010/wordml",
|
|
794
|
-
"xmlns:w15": "http://schemas.microsoft.com/office/word/2012/wordml",
|
|
795
|
-
"mc:Ignorable": "w14 w15"
|
|
796
|
-
};
|
|
797
|
-
importedStyles.push({ _raw: stringifyDocDefaults(options.document ?? {}) });
|
|
798
|
-
importedStyles.push({ _raw: "<w:latentStyles w:defLockedState=\"0\" w:defUIPriority=\"99\" w:defSemiHidden=\"0\" w:defUnhideWhenUsed=\"0\" w:defQFormat=\"0\" w:count=\"376\"><w:lsdException w:name=\"Normal\" w:uiPriority=\"0\" w:qFormat=\"1\"/><w:lsdException w:name=\"heading 1\" w:uiPriority=\"9\" w:qFormat=\"1\"/><w:lsdException w:name=\"heading 2\" w:semiHidden=\"1\" w:uiPriority=\"9\" w:unhideWhenUsed=\"1\" w:qFormat=\"1\"/><w:lsdException w:name=\"heading 3\" w:semiHidden=\"1\" w:uiPriority=\"9\" w:unhideWhenUsed=\"1\" w:qFormat=\"1\"/><w:lsdException w:name=\"heading 4\" w:semiHidden=\"1\" w:uiPriority=\"9\" w:unhideWhenUsed=\"1\" w:qFormat=\"1\"/><w:lsdException w:name=\"heading 5\" w:semiHidden=\"1\" w:uiPriority=\"9\" w:unhideWhenUsed=\"1\" w:qFormat=\"1\"/><w:lsdException w:name=\"heading 6\" w:semiHidden=\"1\" w:uiPriority=\"9\" w:unhideWhenUsed=\"1\" w:qFormat=\"1\"/><w:lsdException w:name=\"heading 7\" w:semiHidden=\"1\" w:uiPriority=\"9\" w:unhideWhenUsed=\"1\" w:qFormat=\"1\"/><w:lsdException w:name=\"heading 8\" w:semiHidden=\"1\" w:uiPriority=\"9\" w:unhideWhenUsed=\"1\" w:qFormat=\"1\"/><w:lsdException w:name=\"heading 9\" w:semiHidden=\"1\" w:uiPriority=\"9\" w:unhideWhenUsed=\"1\" w:qFormat=\"1\"/><w:lsdException w:name=\"Default Paragraph Font\" w:semiHidden=\"1\" w:uiPriority=\"1\" w:unhideWhenUsed=\"1\"/><w:lsdException w:name=\"Normal Table\" w:semiHidden=\"1\" w:uiPriority=\"99\" w:unhideWhenUsed=\"1\"/><w:lsdException w:name=\"No List\" w:semiHidden=\"1\" w:uiPriority=\"99\" w:unhideWhenUsed=\"1\"/><w:lsdException w:name=\"Subtitle\" w:uiPriority=\"11\" w:qFormat=\"1\"/><w:lsdException w:name=\"Strong\" w:uiPriority=\"22\" w:qFormat=\"1\"/><w:lsdException w:name=\"Emphasis\" w:uiPriority=\"20\" w:qFormat=\"1\"/><w:lsdException w:name=\"Hyperlink\" w:semiHidden=\"1\" w:unhideWhenUsed=\"1\"/><w:lsdException w:name=\"FollowedHyperlink\" w:semiHidden=\"1\" w:unhideWhenUsed=\"1\"/><w:lsdException w:name=\"No Spacing\" w:uiPriority=\"1\" w:qFormat=\"1\"/><w:lsdException w:name=\"Revision\" w:semiHidden=\"1\"/></w:latentStyles>" });
|
|
799
|
-
paragraphStyles.push({
|
|
800
|
-
id: "Normal",
|
|
801
|
-
name: "Normal",
|
|
802
|
-
default: true,
|
|
803
|
-
quickFormat: true
|
|
804
|
-
});
|
|
805
|
-
for (const [headingIdx, h] of [
|
|
806
|
-
{
|
|
807
|
-
id: "Heading1",
|
|
808
|
-
name: "heading 1",
|
|
809
|
-
link: "Heading1Char",
|
|
810
|
-
sz: 48,
|
|
811
|
-
before: 480,
|
|
812
|
-
after: 80,
|
|
813
|
-
outlineLvl: 0
|
|
814
|
-
},
|
|
815
|
-
{
|
|
816
|
-
id: "Heading2",
|
|
817
|
-
name: "heading 2",
|
|
818
|
-
link: "Heading2Char",
|
|
819
|
-
sz: 40,
|
|
820
|
-
before: 160,
|
|
821
|
-
after: 80,
|
|
822
|
-
outlineLvl: 1
|
|
823
|
-
},
|
|
824
|
-
{
|
|
825
|
-
id: "Heading3",
|
|
826
|
-
name: "heading 3",
|
|
827
|
-
link: "Heading3Char",
|
|
828
|
-
sz: 32,
|
|
829
|
-
before: 160,
|
|
830
|
-
after: 80,
|
|
831
|
-
outlineLvl: 2
|
|
832
|
-
},
|
|
833
|
-
{
|
|
834
|
-
id: "Heading4",
|
|
835
|
-
name: "heading 4",
|
|
836
|
-
link: "Heading4Char",
|
|
837
|
-
sz: 28,
|
|
838
|
-
before: 80,
|
|
839
|
-
after: 40,
|
|
840
|
-
outlineLvl: 3
|
|
841
|
-
},
|
|
842
|
-
{
|
|
843
|
-
id: "Heading5",
|
|
844
|
-
name: "heading 5",
|
|
845
|
-
link: "Heading5Char",
|
|
846
|
-
sz: 24,
|
|
847
|
-
before: 80,
|
|
848
|
-
after: 40,
|
|
849
|
-
outlineLvl: 4
|
|
850
|
-
},
|
|
851
|
-
{
|
|
852
|
-
id: "Heading6",
|
|
853
|
-
name: "heading 6",
|
|
854
|
-
link: "Heading6Char",
|
|
855
|
-
sz: void 0,
|
|
856
|
-
before: 40,
|
|
857
|
-
after: 0,
|
|
858
|
-
outlineLvl: 5
|
|
859
|
-
},
|
|
860
|
-
{
|
|
861
|
-
id: "Heading7",
|
|
862
|
-
name: "heading 7",
|
|
863
|
-
link: "Heading7Char",
|
|
864
|
-
sz: void 0,
|
|
865
|
-
before: 40,
|
|
866
|
-
after: 0,
|
|
867
|
-
outlineLvl: 6
|
|
868
|
-
},
|
|
869
|
-
{
|
|
870
|
-
id: "Heading8",
|
|
871
|
-
name: "heading 8",
|
|
872
|
-
link: "Heading8Char",
|
|
873
|
-
sz: void 0,
|
|
874
|
-
before: void 0,
|
|
875
|
-
after: 0,
|
|
876
|
-
outlineLvl: 7
|
|
877
|
-
},
|
|
878
|
-
{
|
|
879
|
-
id: "Heading9",
|
|
880
|
-
name: "heading 9",
|
|
881
|
-
link: "Heading9Char",
|
|
882
|
-
sz: void 0,
|
|
883
|
-
before: void 0,
|
|
884
|
-
after: 0,
|
|
885
|
-
outlineLvl: 8
|
|
886
|
-
}
|
|
887
|
-
].entries()) {
|
|
888
|
-
const outlineLvl = h.outlineLvl;
|
|
889
|
-
const headingOverrideOpts = headingOverride(options, headingIdx + 1);
|
|
890
|
-
if (headingOverrideOpts) {
|
|
891
|
-
paragraphStyles.push({
|
|
892
|
-
id: h.id,
|
|
893
|
-
name: headingOverrideOpts.name ?? h.name,
|
|
894
|
-
basedOn: headingOverrideOpts.basedOn ?? "Normal",
|
|
895
|
-
next: headingOverrideOpts.next ?? "Normal",
|
|
896
|
-
link: headingOverrideOpts.link ?? h.link,
|
|
897
|
-
uiPriority: headingOverrideOpts.uiPriority ?? 9,
|
|
898
|
-
quickFormat: headingOverrideOpts.quickFormat ?? true,
|
|
899
|
-
semiHidden: headingOverrideOpts.semiHidden,
|
|
900
|
-
unhideWhenUsed: headingOverrideOpts.unhideWhenUsed,
|
|
901
|
-
paragraph: {
|
|
902
|
-
outlineLevel: headingIdx,
|
|
903
|
-
...headingOverrideOpts.paragraph
|
|
904
|
-
},
|
|
905
|
-
run: headingOverrideOpts.run
|
|
906
|
-
});
|
|
907
|
-
characterStyles.push({
|
|
908
|
-
id: h.link,
|
|
909
|
-
name: `${h.name} Char`,
|
|
910
|
-
basedOn: "DefaultParagraphFont",
|
|
911
|
-
link: h.id,
|
|
912
|
-
run: headingOverrideOpts.run
|
|
913
|
-
});
|
|
914
|
-
continue;
|
|
915
|
-
}
|
|
916
|
-
const accentRange = outlineLvl < 6;
|
|
917
|
-
const runProps = {
|
|
918
|
-
font: accentRange ? {
|
|
919
|
-
asciiTheme: "majorHAnsi",
|
|
920
|
-
eastAsiaTheme: "majorEastAsia",
|
|
921
|
-
hAnsiTheme: "majorHAnsi",
|
|
922
|
-
cstheme: "majorBidi"
|
|
923
|
-
} : { cstheme: "majorBidi" },
|
|
924
|
-
color: accentRange ? {
|
|
925
|
-
val: "0F4761",
|
|
926
|
-
themeColor: "accent1",
|
|
927
|
-
themeShade: "BF"
|
|
928
|
-
} : {
|
|
929
|
-
val: "595959",
|
|
930
|
-
themeColor: "text1",
|
|
931
|
-
themeTint: "A6"
|
|
932
|
-
}
|
|
933
|
-
};
|
|
934
|
-
if (h.sz) {
|
|
935
|
-
const sizePt = h.sz / 2;
|
|
936
|
-
runProps.size = sizePt;
|
|
937
|
-
runProps.sizeComplexScript = sizePt;
|
|
938
|
-
}
|
|
939
|
-
if (outlineLvl >= 5) {
|
|
940
|
-
runProps.bold = true;
|
|
941
|
-
runProps.boldComplexScript = true;
|
|
942
|
-
}
|
|
943
|
-
paragraphStyles.push({
|
|
944
|
-
id: h.id,
|
|
945
|
-
name: h.name,
|
|
946
|
-
basedOn: "Normal",
|
|
947
|
-
next: "Normal",
|
|
948
|
-
link: h.link,
|
|
949
|
-
uiPriority: 9,
|
|
950
|
-
semiHidden: outlineLvl > 0,
|
|
951
|
-
unhideWhenUsed: outlineLvl > 0,
|
|
952
|
-
quickFormat: true,
|
|
953
|
-
paragraph: {
|
|
954
|
-
keepNext: true,
|
|
955
|
-
keepLines: true,
|
|
956
|
-
spacing: {
|
|
957
|
-
before: h.before,
|
|
958
|
-
after: h.after
|
|
959
|
-
},
|
|
960
|
-
outlineLevel: outlineLvl
|
|
961
|
-
},
|
|
962
|
-
run: runProps
|
|
963
|
-
});
|
|
964
|
-
characterStyles.push({
|
|
965
|
-
id: h.link,
|
|
966
|
-
name: `${h.name} Char`,
|
|
967
|
-
basedOn: "DefaultParagraphFont",
|
|
968
|
-
link: h.id,
|
|
969
|
-
uiPriority: 9,
|
|
970
|
-
semiHidden: outlineLvl > 0,
|
|
971
|
-
run: runProps
|
|
972
|
-
});
|
|
973
|
-
}
|
|
974
|
-
characterStyles.push({
|
|
975
|
-
id: "DefaultParagraphFont",
|
|
976
|
-
name: "Default Paragraph Font",
|
|
977
|
-
default: true,
|
|
978
|
-
uiPriority: 1,
|
|
979
|
-
semiHidden: true,
|
|
980
|
-
unhideWhenUsed: true
|
|
981
|
-
});
|
|
982
|
-
tableStyles.push({
|
|
983
|
-
id: "NormalTable",
|
|
984
|
-
name: "Normal Table",
|
|
985
|
-
default: true,
|
|
986
|
-
uiPriority: 99,
|
|
987
|
-
semiHidden: true,
|
|
988
|
-
unhideWhenUsed: true,
|
|
989
|
-
table: {
|
|
990
|
-
indent: {
|
|
991
|
-
size: 0,
|
|
992
|
-
type: WidthType.DXA
|
|
993
|
-
},
|
|
994
|
-
cellMargin: {
|
|
995
|
-
top: {
|
|
996
|
-
size: 0,
|
|
997
|
-
type: WidthType.DXA
|
|
998
|
-
},
|
|
999
|
-
left: {
|
|
1000
|
-
size: 108,
|
|
1001
|
-
type: WidthType.DXA
|
|
1002
|
-
},
|
|
1003
|
-
bottom: {
|
|
1004
|
-
size: 0,
|
|
1005
|
-
type: WidthType.DXA
|
|
1006
|
-
},
|
|
1007
|
-
right: {
|
|
1008
|
-
size: 108,
|
|
1009
|
-
type: WidthType.DXA
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
});
|
|
1014
|
-
numberingStyles.push({
|
|
1015
|
-
id: "NoList",
|
|
1016
|
-
name: "No List",
|
|
1017
|
-
default: true,
|
|
1018
|
-
uiPriority: 99,
|
|
1019
|
-
semiHidden: true,
|
|
1020
|
-
unhideWhenUsed: true
|
|
1021
|
-
});
|
|
1022
|
-
if (options.title) {
|
|
1023
|
-
paragraphStyles.push({
|
|
1024
|
-
id: "Title",
|
|
1025
|
-
name: options.title.name ?? "Title",
|
|
1026
|
-
basedOn: options.title.basedOn ?? "Normal",
|
|
1027
|
-
next: options.title.next ?? "Normal",
|
|
1028
|
-
link: options.title.link ?? "TitleChar",
|
|
1029
|
-
uiPriority: options.title.uiPriority ?? 10,
|
|
1030
|
-
quickFormat: options.title.quickFormat ?? true,
|
|
1031
|
-
paragraph: options.title.paragraph,
|
|
1032
|
-
run: options.title.run
|
|
1033
|
-
});
|
|
1034
|
-
characterStyles.push({
|
|
1035
|
-
id: "TitleChar",
|
|
1036
|
-
name: "Title Char",
|
|
1037
|
-
basedOn: "DefaultParagraphFont",
|
|
1038
|
-
link: "Title",
|
|
1039
|
-
run: options.title.run
|
|
1040
|
-
});
|
|
1041
|
-
} else {
|
|
1042
|
-
const titleRun = {
|
|
1043
|
-
font: {
|
|
1044
|
-
asciiTheme: "majorHAnsi",
|
|
1045
|
-
eastAsiaTheme: "majorEastAsia",
|
|
1046
|
-
hAnsiTheme: "majorHAnsi",
|
|
1047
|
-
cstheme: "majorBidi"
|
|
1048
|
-
},
|
|
1049
|
-
characterSpacing: -10,
|
|
1050
|
-
kern: 28,
|
|
1051
|
-
size: 28,
|
|
1052
|
-
sizeComplexScript: 28
|
|
1053
|
-
};
|
|
1054
|
-
paragraphStyles.push({
|
|
1055
|
-
id: "Title",
|
|
1056
|
-
name: "Title",
|
|
1057
|
-
basedOn: "Normal",
|
|
1058
|
-
next: "Normal",
|
|
1059
|
-
link: "TitleChar",
|
|
1060
|
-
uiPriority: 10,
|
|
1061
|
-
quickFormat: true,
|
|
1062
|
-
paragraph: {
|
|
1063
|
-
spacing: {
|
|
1064
|
-
after: 80,
|
|
1065
|
-
line: 240,
|
|
1066
|
-
lineRule: "auto"
|
|
1067
|
-
},
|
|
1068
|
-
contextualSpacing: true,
|
|
1069
|
-
alignment: AlignmentType.CENTER
|
|
1070
|
-
},
|
|
1071
|
-
run: titleRun
|
|
1072
|
-
});
|
|
1073
|
-
characterStyles.push({
|
|
1074
|
-
id: "TitleChar",
|
|
1075
|
-
name: "Title Char",
|
|
1076
|
-
basedOn: "DefaultParagraphFont",
|
|
1077
|
-
link: "Title",
|
|
1078
|
-
uiPriority: 10,
|
|
1079
|
-
run: titleRun
|
|
1080
|
-
});
|
|
1081
|
-
}
|
|
1082
|
-
if (options.subtitle) {
|
|
1083
|
-
paragraphStyles.push({
|
|
1084
|
-
id: "Subtitle",
|
|
1085
|
-
name: options.subtitle.name ?? "Subtitle",
|
|
1086
|
-
basedOn: options.subtitle.basedOn ?? "Normal",
|
|
1087
|
-
next: options.subtitle.next ?? "Normal",
|
|
1088
|
-
link: options.subtitle.link ?? "SubtitleChar",
|
|
1089
|
-
uiPriority: options.subtitle.uiPriority ?? 11,
|
|
1090
|
-
quickFormat: options.subtitle.quickFormat ?? true,
|
|
1091
|
-
paragraph: options.subtitle.paragraph,
|
|
1092
|
-
run: options.subtitle.run
|
|
1093
|
-
});
|
|
1094
|
-
characterStyles.push({
|
|
1095
|
-
id: "SubtitleChar",
|
|
1096
|
-
name: "Subtitle Char",
|
|
1097
|
-
basedOn: "DefaultParagraphFont",
|
|
1098
|
-
link: "Subtitle",
|
|
1099
|
-
run: options.subtitle.run
|
|
1100
|
-
});
|
|
1101
|
-
} else {
|
|
1102
|
-
const subtitleRun = {
|
|
1103
|
-
font: {
|
|
1104
|
-
asciiTheme: "majorHAnsi",
|
|
1105
|
-
eastAsiaTheme: "majorEastAsia",
|
|
1106
|
-
hAnsiTheme: "majorHAnsi",
|
|
1107
|
-
cstheme: "majorBidi"
|
|
1108
|
-
},
|
|
1109
|
-
color: {
|
|
1110
|
-
val: "595959",
|
|
1111
|
-
themeColor: "text1",
|
|
1112
|
-
themeTint: "A6"
|
|
1113
|
-
},
|
|
1114
|
-
characterSpacing: 15,
|
|
1115
|
-
size: 14,
|
|
1116
|
-
sizeComplexScript: 14
|
|
1117
|
-
};
|
|
1118
|
-
paragraphStyles.push({
|
|
1119
|
-
id: "Subtitle",
|
|
1120
|
-
name: "Subtitle",
|
|
1121
|
-
basedOn: "Normal",
|
|
1122
|
-
next: "Normal",
|
|
1123
|
-
link: "SubtitleChar",
|
|
1124
|
-
uiPriority: 11,
|
|
1125
|
-
quickFormat: true,
|
|
1126
|
-
paragraph: { alignment: AlignmentType.CENTER },
|
|
1127
|
-
run: subtitleRun
|
|
1128
|
-
});
|
|
1129
|
-
characterStyles.push({
|
|
1130
|
-
id: "SubtitleChar",
|
|
1131
|
-
name: "Subtitle Char",
|
|
1132
|
-
basedOn: "DefaultParagraphFont",
|
|
1133
|
-
link: "Subtitle",
|
|
1134
|
-
uiPriority: 11,
|
|
1135
|
-
run: subtitleRun
|
|
1136
|
-
});
|
|
1137
|
-
}
|
|
1138
|
-
if (options.listParagraph) paragraphStyles.push({
|
|
1139
|
-
id: "ListParagraph",
|
|
1140
|
-
name: options.listParagraph.name ?? "List Paragraph",
|
|
1141
|
-
basedOn: options.listParagraph.basedOn ?? "Normal",
|
|
1142
|
-
uiPriority: options.listParagraph.uiPriority ?? 34,
|
|
1143
|
-
quickFormat: options.listParagraph.quickFormat ?? true,
|
|
1144
|
-
paragraph: options.listParagraph.paragraph,
|
|
1145
|
-
run: options.listParagraph.run
|
|
1146
|
-
});
|
|
1147
|
-
else paragraphStyles.push({
|
|
1148
|
-
id: "ListParagraph",
|
|
1149
|
-
name: "List Paragraph",
|
|
1150
|
-
basedOn: "Normal",
|
|
1151
|
-
uiPriority: 34,
|
|
1152
|
-
quickFormat: true,
|
|
1153
|
-
paragraph: {
|
|
1154
|
-
indent: { left: 720 },
|
|
1155
|
-
contextualSpacing: true
|
|
1156
|
-
}
|
|
1157
|
-
});
|
|
1158
|
-
if (options.strong) paragraphStyles.push({
|
|
1159
|
-
id: "Strong",
|
|
1160
|
-
name: options.strong.name ?? "Strong",
|
|
1161
|
-
basedOn: options.strong.basedOn ?? "Normal",
|
|
1162
|
-
next: options.strong.next ?? "Normal",
|
|
1163
|
-
quickFormat: options.strong.quickFormat ?? true,
|
|
1164
|
-
paragraph: options.strong.paragraph,
|
|
1165
|
-
run: options.strong.run
|
|
1166
|
-
});
|
|
1167
|
-
if (options.emphasis) paragraphStyles.push({
|
|
1168
|
-
id: "Emphasis",
|
|
1169
|
-
name: options.emphasis.name ?? "Emphasis",
|
|
1170
|
-
basedOn: options.emphasis.basedOn ?? "Normal",
|
|
1171
|
-
next: options.emphasis.next ?? "Normal",
|
|
1172
|
-
quickFormat: options.emphasis.quickFormat ?? true,
|
|
1173
|
-
paragraph: options.emphasis.paragraph,
|
|
1174
|
-
run: options.emphasis.run
|
|
1175
|
-
});
|
|
1176
|
-
const quoteRun = {
|
|
1177
|
-
italic: true,
|
|
1178
|
-
italicComplexScript: true,
|
|
1179
|
-
color: {
|
|
1180
|
-
val: "404040",
|
|
1181
|
-
themeColor: "text1",
|
|
1182
|
-
themeTint: "BF"
|
|
1183
|
-
}
|
|
1184
|
-
};
|
|
1185
|
-
if (options.quote) {
|
|
1186
|
-
paragraphStyles.push({
|
|
1187
|
-
id: "Quote",
|
|
1188
|
-
name: options.quote.name ?? "Quote",
|
|
1189
|
-
basedOn: options.quote.basedOn ?? "Normal",
|
|
1190
|
-
next: options.quote.next ?? "Normal",
|
|
1191
|
-
link: options.quote.link ?? "QuoteChar",
|
|
1192
|
-
uiPriority: options.quote.uiPriority ?? 29,
|
|
1193
|
-
quickFormat: options.quote.quickFormat ?? true,
|
|
1194
|
-
paragraph: options.quote.paragraph,
|
|
1195
|
-
run: options.quote.run
|
|
1196
|
-
});
|
|
1197
|
-
characterStyles.push({
|
|
1198
|
-
id: "QuoteChar",
|
|
1199
|
-
name: "Quote Char",
|
|
1200
|
-
basedOn: "DefaultParagraphFont",
|
|
1201
|
-
link: "Quote",
|
|
1202
|
-
run: options.quote.run
|
|
1203
|
-
});
|
|
1204
|
-
} else {
|
|
1205
|
-
paragraphStyles.push({
|
|
1206
|
-
id: "Quote",
|
|
1207
|
-
name: "Quote",
|
|
1208
|
-
basedOn: "Normal",
|
|
1209
|
-
next: "Normal",
|
|
1210
|
-
link: "QuoteChar",
|
|
1211
|
-
uiPriority: 29,
|
|
1212
|
-
quickFormat: true,
|
|
1213
|
-
paragraph: {
|
|
1214
|
-
spacing: { before: 160 },
|
|
1215
|
-
alignment: AlignmentType.CENTER
|
|
1216
|
-
},
|
|
1217
|
-
run: quoteRun
|
|
1218
|
-
});
|
|
1219
|
-
characterStyles.push({
|
|
1220
|
-
id: "QuoteChar",
|
|
1221
|
-
name: "Quote Char",
|
|
1222
|
-
basedOn: "DefaultParagraphFont",
|
|
1223
|
-
link: "Quote",
|
|
1224
|
-
uiPriority: 29,
|
|
1225
|
-
run: quoteRun
|
|
1226
|
-
});
|
|
1227
|
-
}
|
|
1228
|
-
const intenseQuoteRun = {
|
|
1229
|
-
italic: true,
|
|
1230
|
-
italicComplexScript: true,
|
|
1231
|
-
color: {
|
|
1232
|
-
val: "0F4761",
|
|
1233
|
-
themeColor: "accent1",
|
|
1234
|
-
themeShade: "BF"
|
|
1235
|
-
}
|
|
1236
|
-
};
|
|
1237
|
-
const intenseQuoteBorder = {
|
|
1238
|
-
style: BorderStyle.SINGLE,
|
|
1239
|
-
size: 4,
|
|
1240
|
-
space: 10,
|
|
1241
|
-
color: "0F4761",
|
|
1242
|
-
themeColor: "accent1",
|
|
1243
|
-
themeShade: "BF"
|
|
1244
|
-
};
|
|
1245
|
-
paragraphStyles.push({
|
|
1246
|
-
id: "IntenseQuote",
|
|
1247
|
-
name: "Intense Quote",
|
|
1248
|
-
basedOn: "Normal",
|
|
1249
|
-
next: "Normal",
|
|
1250
|
-
link: "IntenseQuoteChar",
|
|
1251
|
-
uiPriority: 30,
|
|
1252
|
-
quickFormat: true,
|
|
1253
|
-
paragraph: {
|
|
1254
|
-
border: {
|
|
1255
|
-
top: intenseQuoteBorder,
|
|
1256
|
-
bottom: intenseQuoteBorder
|
|
1257
|
-
},
|
|
1258
|
-
spacing: {
|
|
1259
|
-
before: 360,
|
|
1260
|
-
after: 360
|
|
1261
|
-
},
|
|
1262
|
-
indent: {
|
|
1263
|
-
left: 864,
|
|
1264
|
-
right: 864
|
|
1265
|
-
},
|
|
1266
|
-
alignment: AlignmentType.CENTER
|
|
1267
|
-
},
|
|
1268
|
-
run: intenseQuoteRun
|
|
1269
|
-
});
|
|
1270
|
-
characterStyles.push({
|
|
1271
|
-
id: "IntenseQuoteChar",
|
|
1272
|
-
name: "Intense Quote Char",
|
|
1273
|
-
basedOn: "DefaultParagraphFont",
|
|
1274
|
-
link: "IntenseQuote",
|
|
1275
|
-
uiPriority: 30,
|
|
1276
|
-
run: intenseQuoteRun
|
|
1277
|
-
});
|
|
1278
|
-
characterStyles.push({
|
|
1279
|
-
id: "Hyperlink",
|
|
1280
|
-
name: "Hyperlink",
|
|
1281
|
-
basedOn: "DefaultParagraphFont",
|
|
1282
|
-
semiHidden: true,
|
|
1283
|
-
unhideWhenUsed: true,
|
|
1284
|
-
run: {
|
|
1285
|
-
color: "0563C1",
|
|
1286
|
-
underline: { type: "single" }
|
|
1287
|
-
},
|
|
1288
|
-
...options.hyperlink
|
|
1289
|
-
});
|
|
1290
|
-
characterStyles.push({
|
|
1291
|
-
id: "FootnoteReference",
|
|
1292
|
-
name: "footnote reference",
|
|
1293
|
-
basedOn: "DefaultParagraphFont",
|
|
1294
|
-
semiHidden: true,
|
|
1295
|
-
unhideWhenUsed: true,
|
|
1296
|
-
run: { superScript: true },
|
|
1297
|
-
...options.footnoteReference
|
|
1298
|
-
});
|
|
1299
|
-
paragraphStyles.push({
|
|
1300
|
-
id: "FootnoteText",
|
|
1301
|
-
name: "footnote text",
|
|
1302
|
-
basedOn: "Normal",
|
|
1303
|
-
link: "FootnoteTextChar",
|
|
1304
|
-
semiHidden: true,
|
|
1305
|
-
uiPriority: 99,
|
|
1306
|
-
unhideWhenUsed: true,
|
|
1307
|
-
paragraph: { spacing: {
|
|
1308
|
-
after: 0,
|
|
1309
|
-
line: 240,
|
|
1310
|
-
lineRule: "auto"
|
|
1311
|
-
} },
|
|
1312
|
-
run: { size: 20 },
|
|
1313
|
-
...options.footnoteText
|
|
1314
|
-
});
|
|
1315
|
-
characterStyles.push({
|
|
1316
|
-
id: "FootnoteTextChar",
|
|
1317
|
-
name: "Footnote Text Char",
|
|
1318
|
-
basedOn: "DefaultParagraphFont",
|
|
1319
|
-
link: "FootnoteText",
|
|
1320
|
-
semiHidden: true,
|
|
1321
|
-
run: { size: 20 },
|
|
1322
|
-
...options.footnoteTextChar
|
|
1323
|
-
});
|
|
1324
|
-
characterStyles.push({
|
|
1325
|
-
id: "EndnoteReference",
|
|
1326
|
-
name: "endnote reference",
|
|
1327
|
-
basedOn: "DefaultParagraphFont",
|
|
1328
|
-
semiHidden: true,
|
|
1329
|
-
unhideWhenUsed: true,
|
|
1330
|
-
run: { superScript: true },
|
|
1331
|
-
...options.endnoteReference
|
|
1332
|
-
});
|
|
1333
|
-
paragraphStyles.push({
|
|
1334
|
-
id: "EndnoteText",
|
|
1335
|
-
name: "endnote text",
|
|
1336
|
-
basedOn: "Normal",
|
|
1337
|
-
link: "EndnoteTextChar",
|
|
1338
|
-
semiHidden: true,
|
|
1339
|
-
uiPriority: 99,
|
|
1340
|
-
unhideWhenUsed: true,
|
|
1341
|
-
paragraph: { spacing: {
|
|
1342
|
-
after: 0,
|
|
1343
|
-
line: 240,
|
|
1344
|
-
lineRule: "auto"
|
|
1345
|
-
} },
|
|
1346
|
-
run: { size: 20 },
|
|
1347
|
-
...options.endnoteText
|
|
1348
|
-
});
|
|
1349
|
-
characterStyles.push({
|
|
1350
|
-
id: "EndnoteTextChar",
|
|
1351
|
-
name: "Endnote Text Char",
|
|
1352
|
-
basedOn: "DefaultParagraphFont",
|
|
1353
|
-
link: "EndnoteText",
|
|
1354
|
-
semiHidden: true,
|
|
1355
|
-
run: { size: 20 },
|
|
1356
|
-
...options.endnoteTextChar
|
|
1357
|
-
});
|
|
1358
|
-
characterStyles.push({
|
|
1359
|
-
id: "IntenseReference",
|
|
1360
|
-
name: "Intense Reference",
|
|
1361
|
-
basedOn: "DefaultParagraphFont",
|
|
1362
|
-
uiPriority: 32,
|
|
1363
|
-
quickFormat: true,
|
|
1364
|
-
run: {
|
|
1365
|
-
bold: true,
|
|
1366
|
-
boldComplexScript: true,
|
|
1367
|
-
smallCaps: true,
|
|
1368
|
-
color: {
|
|
1369
|
-
val: "0F4761",
|
|
1370
|
-
themeColor: "accent1",
|
|
1371
|
-
themeShade: "BF"
|
|
1372
|
-
},
|
|
1373
|
-
characterSpacing: 5
|
|
1374
|
-
}
|
|
1375
|
-
});
|
|
1376
|
-
return {
|
|
1377
|
-
importedStyles,
|
|
1378
|
-
paragraphStyles,
|
|
1379
|
-
characterStyles,
|
|
1380
|
-
tableStyles,
|
|
1381
|
-
numberingStyles,
|
|
1382
|
-
initialAttributes
|
|
1383
|
-
};
|
|
1384
|
-
}
|
|
1385
|
-
};
|
|
1386
|
-
//#endregion
|
|
1387
|
-
//#region src/parts/styles/styles.ts
|
|
1388
|
-
/**
|
|
1389
|
-
* Styles module for WordprocessingML documents.
|
|
1390
|
-
*
|
|
1391
|
-
* Pure collector — no XmlComponent inheritance.
|
|
1392
|
-
* Collects child elements as raw XML strings and serializes.
|
|
1393
|
-
*
|
|
1394
|
-
* Reference: http://officeopenxml.com/WPstyles.php
|
|
1395
|
-
*
|
|
1396
|
-
* @module
|
|
1397
|
-
*/
|
|
1398
|
-
/**
|
|
1399
|
-
* Extract the `w:styleId` from a raw `<w:style>` XML string, if present.
|
|
1400
|
-
*
|
|
1401
|
-
* Returns `undefined` for non-style elements (docDefaults / latentStyles),
|
|
1402
|
-
* whose raw XML carries no `w:styleId` attribute.
|
|
1403
|
-
*/
|
|
1404
|
-
function extractStyleId(raw) {
|
|
1405
|
-
const m = raw.match(/w:styleId="([^"]+)"/);
|
|
1406
|
-
return m ? m[1] : void 0;
|
|
1407
|
-
}
|
|
1408
|
-
/**
|
|
1409
|
-
* Represents the styles definitions in a WordprocessingML document.
|
|
1410
|
-
*
|
|
1411
|
-
* Pure collector — no XmlComponent inheritance.
|
|
1412
|
-
* Collects child elements as raw XML strings and serializes.
|
|
1413
|
-
*/
|
|
1414
|
-
var Styles = class {
|
|
1415
|
-
attributes = {};
|
|
1416
|
-
parts = [];
|
|
1417
|
-
constructor(options) {
|
|
1418
|
-
if (options.initialAttributes) this.attributes = options.initialAttributes;
|
|
1419
|
-
const customStyleIds = /* @__PURE__ */ new Set();
|
|
1420
|
-
for (const s of options.paragraphStyles ?? []) customStyleIds.add(s.id);
|
|
1421
|
-
for (const s of options.characterStyles ?? []) customStyleIds.add(s.id);
|
|
1422
|
-
for (const s of options.tableStyles ?? []) customStyleIds.add(s.id);
|
|
1423
|
-
if (options.importedStyles) for (const style of options.importedStyles) {
|
|
1424
|
-
if (!style._raw) continue;
|
|
1425
|
-
if (customStyleIds.size > 0) {
|
|
1426
|
-
const id = extractStyleId(style._raw);
|
|
1427
|
-
if (id && customStyleIds.has(id)) continue;
|
|
1428
|
-
}
|
|
1429
|
-
this.parts.push(style._raw);
|
|
1430
|
-
}
|
|
1431
|
-
if (options.paragraphStyles) for (const style of options.paragraphStyles) this.parts.push(stringifyParagraphStyle(style));
|
|
1432
|
-
if (options.characterStyles) for (const style of options.characterStyles) this.parts.push(stringifyCharacterStyle(style));
|
|
1433
|
-
if (options.tableStyles) for (const style of options.tableStyles) this.parts.push(stringifyTableStyle(style));
|
|
1434
|
-
if (options.numberingStyles) for (const style of options.numberingStyles) this.parts.push(stringifyNumberingStyle(style));
|
|
1435
|
-
}
|
|
1436
|
-
/**
|
|
1437
|
-
* Serialize to word/styles.xml content (with XML declaration).
|
|
1438
|
-
*/
|
|
1439
|
-
serialize() {
|
|
1440
|
-
const attrParts = [];
|
|
1441
|
-
for (const [k, v] of Object.entries(this.attributes)) if (v !== void 0 && v !== null) attrParts.push(` ${k}="${v}"`);
|
|
1442
|
-
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:styles${attrParts.join("")}>${this.parts.join("")}</w:styles>`;
|
|
1443
|
-
}
|
|
1444
|
-
};
|
|
1445
|
-
/**
|
|
1446
|
-
* Build a cache of style elements keyed by styleId.
|
|
1447
|
-
*/
|
|
1448
|
-
function buildStyleCache(stylesEl) {
|
|
1449
|
-
const cache = /* @__PURE__ */ new Map();
|
|
1450
|
-
if (!stylesEl) return cache;
|
|
1451
|
-
for (const child of stylesEl.elements ?? []) {
|
|
1452
|
-
if (child.name !== "w:style") continue;
|
|
1453
|
-
const styleId = attr(child, "w:styleId");
|
|
1454
|
-
if (styleId) cache.set(styleId, child);
|
|
1455
|
-
}
|
|
1456
|
-
return cache;
|
|
1457
|
-
}
|
|
1458
|
-
/**
|
|
1459
|
-
* Build a cache of abstract numbering elements keyed by abstractNumId.
|
|
1460
|
-
*/
|
|
1461
|
-
function buildNumberingCache(numberingEl) {
|
|
1462
|
-
const cache = /* @__PURE__ */ new Map();
|
|
1463
|
-
if (!numberingEl) return cache;
|
|
1464
|
-
for (const child of numberingEl.elements ?? []) {
|
|
1465
|
-
if (child.name !== "w:abstractNum") continue;
|
|
1466
|
-
const abstractNumId = attr(child, "w:abstractNumId");
|
|
1467
|
-
if (abstractNumId !== void 0) cache.set(abstractNumId, child);
|
|
1468
|
-
}
|
|
1469
|
-
return cache;
|
|
1470
|
-
}
|
|
1471
|
-
/**
|
|
1472
|
-
* Parse w:styles element into StylesOptions.
|
|
1473
|
-
*
|
|
1474
|
-
* Skips built-in styles that DefaultStylesFactory already generates,
|
|
1475
|
-
* keeping only user-defined custom styles for round-trip fidelity.
|
|
1476
|
-
*/
|
|
1477
|
-
function parseStyleDefinitions(el, parseParagraphProperties, ctx) {
|
|
1478
|
-
const opts = {};
|
|
1479
|
-
const paragraphStyles = [];
|
|
1480
|
-
const characterStyles = [];
|
|
1481
|
-
const tableStyles = [];
|
|
1482
|
-
const numberingStyles = [];
|
|
1483
|
-
for (const child of el.elements ?? []) if (child.name === "w:docDefaults") {
|
|
1484
|
-
const defOpts = parseDocDefaults(child, parseParagraphProperties, ctx);
|
|
1485
|
-
if (defOpts) opts.default = defOpts;
|
|
1486
|
-
opts.docDefaultsXml = stringifyElement(child);
|
|
1487
|
-
} else if (child.name === "w:latentStyles") opts.latentStylesXml = stringifyElement(child);
|
|
1488
|
-
else if (child.name === "w:style") {
|
|
1489
|
-
const styleOpts = parseStyleElement(child, parseParagraphProperties, ctx);
|
|
1490
|
-
if (!styleOpts?._type || !styleOpts.id) continue;
|
|
1491
|
-
const type = styleOpts._type;
|
|
1492
|
-
delete styleOpts._type;
|
|
1493
|
-
if (type === "table") tableStyles.push(styleOpts);
|
|
1494
|
-
else if (type === "numbering") numberingStyles.push(styleOpts);
|
|
1495
|
-
else if (type === "paragraph") paragraphStyles.push(styleOpts);
|
|
1496
|
-
else if (type === "character") characterStyles.push(styleOpts);
|
|
1497
|
-
}
|
|
1498
|
-
if (paragraphStyles.length > 0) opts.paragraphStyles = paragraphStyles;
|
|
1499
|
-
if (characterStyles.length > 0) opts.characterStyles = characterStyles;
|
|
1500
|
-
if (tableStyles.length > 0) opts.tableStyles = tableStyles;
|
|
1501
|
-
if (numberingStyles.length > 0) opts.numberingStyles = numberingStyles;
|
|
1502
|
-
opts.roundTripped = true;
|
|
1503
|
-
return Object.keys(opts).length > 0 ? opts : void 0;
|
|
1504
|
-
}
|
|
1505
|
-
function parseDocDefaults(el, parseParagraphProperties, ctx) {
|
|
1506
|
-
const document = {};
|
|
1507
|
-
const rPrDefault = findChild(el, "w:rPrDefault");
|
|
1508
|
-
if (rPrDefault) {
|
|
1509
|
-
const rPr = findChild(rPrDefault, "w:rPr");
|
|
1510
|
-
if (rPr) {
|
|
1511
|
-
const runDefaults = parseRunProperties(rPr);
|
|
1512
|
-
document.run = Object.keys(runDefaults).length > 0 ? runDefaults : null;
|
|
1513
|
-
} else document.run = null;
|
|
1514
|
-
}
|
|
1515
|
-
const pPrDefault = findChild(el, "w:pPrDefault");
|
|
1516
|
-
if (pPrDefault) {
|
|
1517
|
-
const pPr = findChild(pPrDefault, "w:pPr");
|
|
1518
|
-
if (pPr) {
|
|
1519
|
-
const paraDefaults = parseParagraphProperties(pPr, ctx);
|
|
1520
|
-
document.paragraph = Object.keys(paraDefaults).length > 0 ? paraDefaults : null;
|
|
1521
|
-
} else document.paragraph = null;
|
|
1522
|
-
}
|
|
1523
|
-
return Object.keys(document).length > 0 ? { document } : void 0;
|
|
1524
|
-
}
|
|
1525
|
-
function parseStyleElement(el, parseParagraphProperties, ctx) {
|
|
1526
|
-
const opts = {};
|
|
1527
|
-
const type = attr(el, "w:type");
|
|
1528
|
-
if (type) opts._type = type;
|
|
1529
|
-
const id = attr(el, "w:styleId");
|
|
1530
|
-
if (id) opts.id = id;
|
|
1531
|
-
if (attrBool(el, "w:default")) opts.default = true;
|
|
1532
|
-
if (attrBool(el, "w:customStyle")) opts.customStyle = true;
|
|
1533
|
-
const nameEl = findChild(el, "w:name");
|
|
1534
|
-
if (nameEl) {
|
|
1535
|
-
const name = attr(nameEl, "w:val");
|
|
1536
|
-
if (name) opts.name = name;
|
|
1537
|
-
}
|
|
1538
|
-
const basedOn = findChild(el, "w:basedOn");
|
|
1539
|
-
if (basedOn) {
|
|
1540
|
-
const val = attr(basedOn, "w:val");
|
|
1541
|
-
if (val) opts.basedOn = val;
|
|
1542
|
-
}
|
|
1543
|
-
const next = findChild(el, "w:next");
|
|
1544
|
-
if (next) {
|
|
1545
|
-
const val = attr(next, "w:val");
|
|
1546
|
-
if (val) opts.next = val;
|
|
1547
|
-
}
|
|
1548
|
-
const link = findChild(el, "w:link");
|
|
1549
|
-
if (link) {
|
|
1550
|
-
const val = attr(link, "w:val");
|
|
1551
|
-
if (val) opts.link = val;
|
|
1552
|
-
}
|
|
1553
|
-
const uiPriority = findChild(el, "w:uiPriority");
|
|
1554
|
-
if (uiPriority) {
|
|
1555
|
-
const val = attrNum(uiPriority, "w:val");
|
|
1556
|
-
if (val !== void 0) opts.uiPriority = val;
|
|
1557
|
-
}
|
|
1558
|
-
if (findChild(el, "w:qFormat")) opts.quickFormat = true;
|
|
1559
|
-
if (findChild(el, "w:semiHidden")) opts.semiHidden = true;
|
|
1560
|
-
if (findChild(el, "w:unhideWhenUsed")) opts.unhideWhenUsed = true;
|
|
1561
|
-
if (findChild(el, "w:autoRedefine")) opts.autoRedefine = true;
|
|
1562
|
-
if (findChild(el, "w:locked")) opts.locked = true;
|
|
1563
|
-
if (findChild(el, "w:personal")) opts.personal = true;
|
|
1564
|
-
if (findChild(el, "w:personalCompose")) opts.personalCompose = true;
|
|
1565
|
-
if (findChild(el, "w:personalReply")) opts.personalReply = true;
|
|
1566
|
-
if (findChild(el, "w:hidden")) opts.hidden = true;
|
|
1567
|
-
const rsidEl = findChild(el, "w:rsid");
|
|
1568
|
-
if (rsidEl) {
|
|
1569
|
-
const val = attr(rsidEl, "w:val");
|
|
1570
|
-
if (val) opts.rsid = val;
|
|
1571
|
-
}
|
|
1572
|
-
const aliases = findChild(el, "w:aliases");
|
|
1573
|
-
if (aliases) {
|
|
1574
|
-
const val = attr(aliases, "w:val");
|
|
1575
|
-
if (val) opts.aliases = val;
|
|
1576
|
-
}
|
|
1577
|
-
const pPr = findChild(el, "w:pPr");
|
|
1578
|
-
if (pPr) {
|
|
1579
|
-
const paraOpts = parseParagraphProperties(pPr, ctx);
|
|
1580
|
-
if (Object.keys(paraOpts).length > 0) opts.paragraph = paraOpts;
|
|
1581
|
-
}
|
|
1582
|
-
const rPr = findChild(el, "w:rPr");
|
|
1583
|
-
if (rPr) {
|
|
1584
|
-
const runOpts = parseRunProperties(rPr);
|
|
1585
|
-
if (Object.keys(runOpts).length > 0) opts.run = runOpts;
|
|
1586
|
-
}
|
|
1587
|
-
const tblPr = findChild(el, "w:tblPr");
|
|
1588
|
-
if (tblPr) {
|
|
1589
|
-
const tableOpts = parseTablePropertiesEl(tblPr);
|
|
1590
|
-
if (Object.keys(tableOpts).length > 0) opts.table = tableOpts;
|
|
1591
|
-
}
|
|
1592
|
-
const trPr = findChild(el, "w:trPr");
|
|
1593
|
-
if (trPr) {
|
|
1594
|
-
const rowOpts = parseTableRowPropertiesEl(trPr);
|
|
1595
|
-
if (Object.keys(rowOpts).length > 0) opts.row = rowOpts;
|
|
1596
|
-
}
|
|
1597
|
-
const tcPr = findChild(el, "w:tcPr");
|
|
1598
|
-
if (tcPr) {
|
|
1599
|
-
const cellOpts = parseTableCellPropertiesEl(tcPr);
|
|
1600
|
-
if (Object.keys(cellOpts).length > 0) opts.cell = cellOpts;
|
|
1601
|
-
}
|
|
1602
|
-
const conditionalFormats = [];
|
|
1603
|
-
for (const child of el.elements ?? []) {
|
|
1604
|
-
if (child.name !== "w:tblStylePr") continue;
|
|
1605
|
-
const type = attr(child, "w:type");
|
|
1606
|
-
if (!type) continue;
|
|
1607
|
-
const cf = { type };
|
|
1608
|
-
const cfPPr = findChild(child, "w:pPr");
|
|
1609
|
-
if (cfPPr) {
|
|
1610
|
-
const paraOpts = parseParagraphProperties(cfPPr, ctx);
|
|
1611
|
-
if (Object.keys(paraOpts).length > 0) cf.paragraph = paraOpts;
|
|
1612
|
-
}
|
|
1613
|
-
const cfRPr = findChild(child, "w:rPr");
|
|
1614
|
-
if (cfRPr) {
|
|
1615
|
-
const runOpts = parseRunProperties(cfRPr);
|
|
1616
|
-
if (Object.keys(runOpts).length > 0) cf.run = runOpts;
|
|
1617
|
-
}
|
|
1618
|
-
const cfTblPr = findChild(child, "w:tblPr");
|
|
1619
|
-
if (cfTblPr) {
|
|
1620
|
-
const tableOpts = parseTablePropertiesEl(cfTblPr);
|
|
1621
|
-
if (Object.keys(tableOpts).length > 0) cf.table = tableOpts;
|
|
1622
|
-
}
|
|
1623
|
-
const cfTrPr = findChild(child, "w:trPr");
|
|
1624
|
-
if (cfTrPr) {
|
|
1625
|
-
const rowOpts = parseTableRowPropertiesEl(cfTrPr);
|
|
1626
|
-
if (Object.keys(rowOpts).length > 0) cf.row = rowOpts;
|
|
1627
|
-
}
|
|
1628
|
-
const cfTcPr = findChild(child, "w:tcPr");
|
|
1629
|
-
if (cfTcPr) {
|
|
1630
|
-
const cellOpts = parseTableCellPropertiesEl(cfTcPr);
|
|
1631
|
-
if (Object.keys(cellOpts).length > 0) cf.cell = cellOpts;
|
|
1632
|
-
}
|
|
1633
|
-
conditionalFormats.push(cf);
|
|
1634
|
-
}
|
|
1635
|
-
if (conditionalFormats.length > 0) opts.conditionalFormats = conditionalFormats;
|
|
1636
|
-
return opts;
|
|
1637
|
-
}
|
|
1638
|
-
//#endregion
|
|
1639
|
-
//#region src/parts/settings/descriptor.ts
|
|
1640
|
-
/**
|
|
1641
|
-
* Settings descriptor — produces word/settings.xml.
|
|
1642
|
-
*
|
|
1643
|
-
* Stringifies pure JSON SettingsOptions into XML without creating
|
|
1644
|
-
* Settings/Compatibility/DocumentProtection/etc. class instances.
|
|
1645
|
-
* Zero XmlComponent allocation — pure string concatenation.
|
|
1646
|
-
*
|
|
1647
|
-
* @module
|
|
1648
|
-
*/
|
|
1649
|
-
/** Derive the namespace-prefixed val attribute from the element tag. */
|
|
1650
|
-
function valAttr(tag) {
|
|
1651
|
-
return `${tag.split(":")[0]}:val`;
|
|
1652
|
-
}
|
|
1653
|
-
function onOff(tag, val) {
|
|
1654
|
-
return val !== void 0 ? `<${tag} ${valAttr(tag)}="${val ? 1 : 0}"/>` : "";
|
|
1655
|
-
}
|
|
1656
|
-
function numVal(tag, val) {
|
|
1657
|
-
return val !== void 0 ? `<${tag} ${valAttr(tag)}="${val}"/>` : "";
|
|
1658
|
-
}
|
|
1659
|
-
function strVal(tag, val) {
|
|
1660
|
-
return val !== void 0 ? `<${tag} ${valAttr(tag)}="${escapeXml(val)}"/>` : "";
|
|
1661
|
-
}
|
|
1662
|
-
/** Build attribute string from key-value pairs, skipping undefined. */
|
|
1663
|
-
function attrStr(attrs) {
|
|
1664
|
-
const parts = [];
|
|
1665
|
-
for (const [k, v] of Object.entries(attrs)) if (v !== void 0) parts.push(`${k}="${escapeXml(String(v))}"`);
|
|
1666
|
-
return parts.join(" ");
|
|
1667
|
-
}
|
|
1668
|
-
/** Self-closing element with attributes only. */
|
|
1669
|
-
function attrEl(tag, attrs) {
|
|
1670
|
-
const a = attrStr(attrs);
|
|
1671
|
-
return a ? `<${tag} ${a}/>` : `<${tag}/>`;
|
|
1672
|
-
}
|
|
1673
|
-
function compatSetting(name, val, uri) {
|
|
1674
|
-
const u = uri ?? "http://schemas.microsoft.com/office/word";
|
|
1675
|
-
return `<w:compatSetting w:name="${escapeXml(name)}" w:uri="${u}" w:val="${val}"/>`;
|
|
1676
|
-
}
|
|
1677
|
-
/** Read a CT_OnOff child as boolean (presence true unless val is explicitly false). */
|
|
1678
|
-
function readOnOff(el) {
|
|
1679
|
-
if (!el || !el.name) return void 0;
|
|
1680
|
-
const v = attr(el, valAttr(el.name));
|
|
1681
|
-
return v !== "false" && v !== "0" && v !== "off";
|
|
1682
|
-
}
|
|
1683
|
-
/** Read an attribute as a number, or undefined if absent/unparseable. */
|
|
1684
|
-
function readNum(el, name) {
|
|
1685
|
-
if (!el) return void 0;
|
|
1686
|
-
const v = attr(el, name);
|
|
1687
|
-
if (v === void 0 || v === "") return void 0;
|
|
1688
|
-
const n = parseInt(v, 10);
|
|
1689
|
-
return Number.isNaN(n) ? void 0 : n;
|
|
1690
|
-
}
|
|
1691
|
-
/** Read an attribute as a string, or undefined if absent. */
|
|
1692
|
-
function readStr(el, name) {
|
|
1693
|
-
if (!el) return void 0;
|
|
1694
|
-
const v = attr(el, name);
|
|
1695
|
-
return v === void 0 || v === "" ? void 0 : v;
|
|
1696
|
-
}
|
|
1697
|
-
/** Read an attribute constrained to an enum; undefined if absent or not allowed. */
|
|
1698
|
-
function readEnum(el, name, allowed) {
|
|
1699
|
-
const v = readStr(el, name);
|
|
1700
|
-
return v !== void 0 && allowed.includes(v) ? v : void 0;
|
|
1701
|
-
}
|
|
1702
|
-
/** Shared password/crypto attributes (AG_TransitionalPassword) → options keys. */
|
|
1703
|
-
const PASSWORD_ATTR_MAP = [
|
|
1704
|
-
[
|
|
1705
|
-
"hashValue",
|
|
1706
|
-
"w:hashValue",
|
|
1707
|
-
false
|
|
1708
|
-
],
|
|
1709
|
-
[
|
|
1710
|
-
"saltValue",
|
|
1711
|
-
"w:saltValue",
|
|
1712
|
-
false
|
|
1713
|
-
],
|
|
1714
|
-
[
|
|
1715
|
-
"hash",
|
|
1716
|
-
"w:hash",
|
|
1717
|
-
false
|
|
1718
|
-
],
|
|
1719
|
-
[
|
|
1720
|
-
"salt",
|
|
1721
|
-
"w:salt",
|
|
1722
|
-
false
|
|
1723
|
-
],
|
|
1724
|
-
[
|
|
1725
|
-
"spinCount",
|
|
1726
|
-
"w:spinCount",
|
|
1727
|
-
true
|
|
1728
|
-
],
|
|
1729
|
-
[
|
|
1730
|
-
"algorithmName",
|
|
1731
|
-
"w:algorithmName",
|
|
1732
|
-
false
|
|
1733
|
-
],
|
|
1734
|
-
[
|
|
1735
|
-
"cryptoAlgorithmClass",
|
|
1736
|
-
"w:cryptAlgorithmClass",
|
|
1737
|
-
false
|
|
1738
|
-
],
|
|
1739
|
-
[
|
|
1740
|
-
"cryptoAlgorithmSid",
|
|
1741
|
-
"w:cryptAlgorithmSid",
|
|
1742
|
-
true
|
|
1743
|
-
],
|
|
1744
|
-
[
|
|
1745
|
-
"cryptoAlgorithmType",
|
|
1746
|
-
"w:cryptAlgorithmType",
|
|
1747
|
-
false
|
|
1748
|
-
],
|
|
1749
|
-
[
|
|
1750
|
-
"cryptoProvider",
|
|
1751
|
-
"w:cryptProvider",
|
|
1752
|
-
false
|
|
1753
|
-
],
|
|
1754
|
-
[
|
|
1755
|
-
"cryptoProviderType",
|
|
1756
|
-
"w:cryptProviderType",
|
|
1757
|
-
false
|
|
1758
|
-
],
|
|
1759
|
-
[
|
|
1760
|
-
"cryptoProviderTypeExtension",
|
|
1761
|
-
"w:cryptProviderTypeExt",
|
|
1762
|
-
true
|
|
1763
|
-
],
|
|
1764
|
-
[
|
|
1765
|
-
"cryptoProviderTypeExtensionSource",
|
|
1766
|
-
"w:cryptProviderTypeExtSource",
|
|
1767
|
-
false
|
|
1768
|
-
],
|
|
1769
|
-
[
|
|
1770
|
-
"algorithmExtensionId",
|
|
1771
|
-
"w:algIdExt",
|
|
1772
|
-
true
|
|
1773
|
-
],
|
|
1774
|
-
[
|
|
1775
|
-
"algorithmExtensionSource",
|
|
1776
|
-
"w:algIdExtSource",
|
|
1777
|
-
false
|
|
1778
|
-
],
|
|
1779
|
-
[
|
|
1780
|
-
"cryptoSpinCount",
|
|
1781
|
-
"w:cryptSpinCount",
|
|
1782
|
-
true
|
|
1783
|
-
]
|
|
1784
|
-
];
|
|
1785
|
-
/** Read shared password/crypto attributes into an options object. */
|
|
1786
|
-
function readPasswordAttrs(el) {
|
|
1787
|
-
const out = {};
|
|
1788
|
-
for (const [key, xmlAttr, isNum] of PASSWORD_ATTR_MAP) {
|
|
1789
|
-
const v = attr(el, xmlAttr);
|
|
1790
|
-
if (v === void 0 || v === "") continue;
|
|
1791
|
-
out[key] = isNum ? parseInt(v, 10) : v;
|
|
1792
|
-
}
|
|
1793
|
-
return out;
|
|
1794
|
-
}
|
|
1795
|
-
/**
|
|
1796
|
-
* CT_OnOff compat flag elements → CompatibilityOptions keys. The XML tag often
|
|
1797
|
-
* differs from the option key (e.g. wordPerfectJustification → w:wpJustification).
|
|
1798
|
-
* Order mirrors stringifyCompatibility so round-trip preserves element order.
|
|
1799
|
-
*/
|
|
1800
|
-
const COMPAT_FLAG_MAP = [
|
|
1801
|
-
["useSingleBorderforContiguousCells", "w:useSingleBorderforContiguousCells"],
|
|
1802
|
-
["wordPerfectJustification", "w:wpJustification"],
|
|
1803
|
-
["noTabStopForHangingIndent", "w:noTabHangInd"],
|
|
1804
|
-
["noLeading", "w:noLeading"],
|
|
1805
|
-
["spaceForUnderline", "w:spaceForUL"],
|
|
1806
|
-
["noColumnBalance", "w:noColumnBalance"],
|
|
1807
|
-
["balanceSingleByteDoubleByteWidth", "w:balanceSingleByteDoubleByteWidth"],
|
|
1808
|
-
["noExtraLineSpacing", "w:noExtraLineSpacing"],
|
|
1809
|
-
["doNotLeaveBackslashAlone", "w:doNotLeaveBackslashAlone"],
|
|
1810
|
-
["underlineTrailingSpaces", "w:ulTrailSpace"],
|
|
1811
|
-
["doNotExpandShiftReturn", "w:doNotExpandShiftReturn"],
|
|
1812
|
-
["spacingInWholePoints", "w:spacingInWholePoints"],
|
|
1813
|
-
["lineWrapLikeWord6", "w:lineWrapLikeWord6"],
|
|
1814
|
-
["printBodyTextBeforeHeader", "w:printBodyTextBeforeHeader"],
|
|
1815
|
-
["printColorsBlack", "w:printColBlack"],
|
|
1816
|
-
["spaceWidth", "w:wpSpaceWidth"],
|
|
1817
|
-
["showBreaksInFrames", "w:showBreaksInFrames"],
|
|
1818
|
-
["subFontBySize", "w:subFontBySize"],
|
|
1819
|
-
["suppressBottomSpacing", "w:suppressBottomSpacing"],
|
|
1820
|
-
["suppressTopSpacing", "w:suppressTopSpacing"],
|
|
1821
|
-
["suppressSpacingAtTopOfPage", "w:suppressSpacingAtTopOfPage"],
|
|
1822
|
-
["suppressTopSpacingWP", "w:suppressTopSpacingWP"],
|
|
1823
|
-
["suppressSpBfAfterPgBrk", "w:suppressSpBfAfterPgBrk"],
|
|
1824
|
-
["swapBordersFacingPages", "w:swapBordersFacingPages"],
|
|
1825
|
-
["convertMailMergeEsc", "w:convMailMergeEsc"],
|
|
1826
|
-
["truncateFontHeightsLikeWP6", "w:truncateFontHeightsLikeWP6"],
|
|
1827
|
-
["macWordSmallCaps", "w:mwSmallCaps"],
|
|
1828
|
-
["usePrinterMetrics", "w:usePrinterMetrics"],
|
|
1829
|
-
["doNotSuppressParagraphBorders", "w:doNotSuppressParagraphBorders"],
|
|
1830
|
-
["wrapTrailSpaces", "w:wrapTrailSpaces"],
|
|
1831
|
-
["footnoteLayoutLikeWW8", "w:footnoteLayoutLikeWW8"],
|
|
1832
|
-
["shapeLayoutLikeWW8", "w:shapeLayoutLikeWW8"],
|
|
1833
|
-
["alignTablesRowByRow", "w:alignTablesRowByRow"],
|
|
1834
|
-
["forgetLastTabAlignment", "w:forgetLastTabAlignment"],
|
|
1835
|
-
["adjustLineHeightInTable", "w:adjustLineHeightInTable"],
|
|
1836
|
-
["autoSpaceLikeWord95", "w:autoSpaceLikeWord95"],
|
|
1837
|
-
["noSpaceRaiseLower", "w:noSpaceRaiseLower"],
|
|
1838
|
-
["doNotUseHTMLParagraphAutoSpacing", "w:doNotUseHTMLParagraphAutoSpacing"],
|
|
1839
|
-
["layoutRawTableWidth", "w:layoutRawTableWidth"],
|
|
1840
|
-
["layoutTableRowsApart", "w:layoutTableRowsApart"],
|
|
1841
|
-
["useWord97LineBreakRules", "w:useWord97LineBreakRules"],
|
|
1842
|
-
["doNotBreakWrappedTables", "w:doNotBreakWrappedTables"],
|
|
1843
|
-
["doNotSnapToGridInCell", "w:doNotSnapToGridInCell"],
|
|
1844
|
-
["selectFieldWithFirstOrLastCharacter", "w:selectFldWithFirstOrLastChar"],
|
|
1845
|
-
["applyBreakingRules", "w:applyBreakingRules"],
|
|
1846
|
-
["doNotWrapTextWithPunctuation", "w:doNotWrapTextWithPunct"],
|
|
1847
|
-
["doNotUseEastAsianBreakRules", "w:doNotUseEastAsianBreakRules"],
|
|
1848
|
-
["useWord2002TableStyleRules", "w:useWord2002TableStyleRules"],
|
|
1849
|
-
["growAutofit", "w:growAutofit"],
|
|
1850
|
-
["useFELayout", "w:useFELayout"],
|
|
1851
|
-
["useNormalStyleForList", "w:useNormalStyleForList"],
|
|
1852
|
-
["doNotUseIndentAsNumberingTabStop", "w:doNotUseIndentAsNumberingTabStop"],
|
|
1853
|
-
["useAlternateEastAsianLineBreakRules", "w:useAltKinsokuLineBreakRules"],
|
|
1854
|
-
["allowSpaceOfSameStyleInTable", "w:allowSpaceOfSameStyleInTable"],
|
|
1855
|
-
["doNotSuppressIndentation", "w:doNotSuppressIndentation"],
|
|
1856
|
-
["doNotAutofitConstrainedTables", "w:doNotAutofitConstrainedTables"],
|
|
1857
|
-
["autofitToFirstFixedWidthCell", "w:autofitToFirstFixedWidthCell"],
|
|
1858
|
-
["underlineTabInNumberingList", "w:underlineTabInNumList"],
|
|
1859
|
-
["displayHangulFixedWidth", "w:displayHangulFixedWidth"],
|
|
1860
|
-
["splitPgBreakAndParaMark", "w:splitPgBreakAndParaMark"],
|
|
1861
|
-
["doNotVerticallyAlignCellWithSp", "w:doNotVertAlignCellWithSp"],
|
|
1862
|
-
["doNotBreakConstrainedForcedTable", "w:doNotBreakConstrainedForcedTable"],
|
|
1863
|
-
["ignoreVerticalAlignmentInTextboxes", "w:doNotVertAlignInTxbx"],
|
|
1864
|
-
["useAnsiKerningPairs", "w:useAnsiKerningPairs"],
|
|
1865
|
-
["cachedColumnBalance", "w:cachedColBalance"]
|
|
1866
|
-
];
|
|
1867
|
-
/** compatSetting names that map to dedicated sugar fields (not into compatSettings[]). */
|
|
1868
|
-
const COMPAT_SETTING_SUGAR = {
|
|
1869
|
-
compatibilityMode: "version",
|
|
1870
|
-
overrideTableStyleFontSizeAndJustification: "overrideTableStyleFontSizeAndJustification",
|
|
1871
|
-
enableOpenTypeFeatures: "enableOpenTypeFeatures",
|
|
1872
|
-
doNotFlipMirrorIndents: "doNotFlipMirrorIndents"
|
|
1873
|
-
};
|
|
1874
|
-
/** Parse w:footnotePr / w:endnotePr (CT_FtnDocProps / CT_EdnDocProps). */
|
|
1875
|
-
function parseFtnEdnPr(el) {
|
|
1876
|
-
const o = {};
|
|
1877
|
-
const pos = readStr(findChild(el, "w:pos"), "w:val");
|
|
1878
|
-
if (pos) o.pos = pos;
|
|
1879
|
-
const numFmtEl = findChild(el, "w:numFmt");
|
|
1880
|
-
if (numFmtEl) {
|
|
1881
|
-
const v = readStr(numFmtEl, "w:val");
|
|
1882
|
-
if (v) o.numFmt = v;
|
|
1883
|
-
const format = readStr(numFmtEl, "w:format");
|
|
1884
|
-
if (format) o.format = format;
|
|
1885
|
-
}
|
|
1886
|
-
const numStart = readNum(findChild(el, "w:numStart"), "w:val");
|
|
1887
|
-
if (numStart !== void 0) o.numStart = numStart;
|
|
1888
|
-
const numRestart = readStr(findChild(el, "w:numRestart"), "w:val");
|
|
1889
|
-
if (numRestart) o.numRestart = numRestart;
|
|
1890
|
-
return Object.keys(o).length > 0 ? o : void 0;
|
|
1891
|
-
}
|
|
1892
|
-
/** Parse w:compat (CT_Compat): on/off flag elements + w:compatSetting entries. */
|
|
1893
|
-
function parseCompatibility(el) {
|
|
1894
|
-
const o = {};
|
|
1895
|
-
const flagMap = Object.fromEntries(COMPAT_FLAG_MAP.map(([key, tag]) => [tag, key]));
|
|
1896
|
-
const extras = [];
|
|
1897
|
-
for (const child of el.elements ?? []) {
|
|
1898
|
-
if (child.type !== "element" || !child.name) continue;
|
|
1899
|
-
const key = flagMap[child.name];
|
|
1900
|
-
if (key !== void 0) {
|
|
1901
|
-
o[key] = true;
|
|
1902
|
-
continue;
|
|
1903
|
-
}
|
|
1904
|
-
if (child.name === "w:compatSetting") {
|
|
1905
|
-
const name = attr(child, "w:name");
|
|
1906
|
-
const val = attr(child, "w:val");
|
|
1907
|
-
if (name === void 0 || val === void 0) continue;
|
|
1908
|
-
const sugar = COMPAT_SETTING_SUGAR[name];
|
|
1909
|
-
if (sugar === "version") {
|
|
1910
|
-
const n = parseInt(val, 10);
|
|
1911
|
-
if (!Number.isNaN(n)) o.version = n;
|
|
1912
|
-
} else if (sugar !== void 0) o[sugar] = val !== "0" && val !== "false";
|
|
1913
|
-
else extras.push({
|
|
1914
|
-
name,
|
|
1915
|
-
val,
|
|
1916
|
-
uri: attr(child, "w:uri")
|
|
1917
|
-
});
|
|
1918
|
-
}
|
|
1919
|
-
}
|
|
1920
|
-
if (extras.length > 0) o.compatSettings = extras;
|
|
1921
|
-
return Object.keys(o).length > 0 ? o : void 0;
|
|
1922
|
-
}
|
|
1923
|
-
/** Parse m:mathPr (CT_MathPr). */
|
|
1924
|
-
function parseMathPr(el) {
|
|
1925
|
-
const o = {};
|
|
1926
|
-
const mathFont = readStr(findChild(el, "m:mathFont"), "m:val");
|
|
1927
|
-
if (mathFont) o.mathFont = mathFont;
|
|
1928
|
-
const binaryOperatorBreak = readEnum(findChild(el, "m:brkBin"), "m:val", [
|
|
1929
|
-
"before",
|
|
1930
|
-
"after",
|
|
1931
|
-
"repeat"
|
|
1932
|
-
]);
|
|
1933
|
-
if (binaryOperatorBreak) o.binaryOperatorBreak = binaryOperatorBreak;
|
|
1934
|
-
const binaryOperatorBreakSubtraction = readEnum(findChild(el, "m:brkBinSub"), "m:val", [
|
|
1935
|
-
"--",
|
|
1936
|
-
"-+",
|
|
1937
|
-
"+-"
|
|
1938
|
-
]);
|
|
1939
|
-
if (binaryOperatorBreakSubtraction) o.binaryOperatorBreakSubtraction = binaryOperatorBreakSubtraction;
|
|
1940
|
-
const smallFractions = readOnOff(findChild(el, "m:smallFrac"));
|
|
1941
|
-
if (smallFractions !== void 0) o.smallFractions = smallFractions;
|
|
1942
|
-
const displayDefaults = readOnOff(findChild(el, "m:dispDef"));
|
|
1943
|
-
if (displayDefaults !== void 0) o.displayDefaults = displayDefaults;
|
|
1944
|
-
const leftMargin = readNum(findChild(el, "m:lMargin"), "m:val");
|
|
1945
|
-
if (leftMargin !== void 0) o.leftMargin = leftMargin;
|
|
1946
|
-
const rightMargin = readNum(findChild(el, "m:rMargin"), "m:val");
|
|
1947
|
-
if (rightMargin !== void 0) o.rightMargin = rightMargin;
|
|
1948
|
-
const defaultJustification = readEnum(findChild(el, "m:defJc"), "m:val", [
|
|
1949
|
-
"left",
|
|
1950
|
-
"right",
|
|
1951
|
-
"center",
|
|
1952
|
-
"centerGroup"
|
|
1953
|
-
]);
|
|
1954
|
-
if (defaultJustification) o.defaultJustification = defaultJustification;
|
|
1955
|
-
const preSpacing = readNum(findChild(el, "m:preSp"), "m:val");
|
|
1956
|
-
if (preSpacing !== void 0) o.preSpacing = preSpacing;
|
|
1957
|
-
const postSpacing = readNum(findChild(el, "m:postSp"), "m:val");
|
|
1958
|
-
if (postSpacing !== void 0) o.postSpacing = postSpacing;
|
|
1959
|
-
const interSpacing = readNum(findChild(el, "m:interSp"), "m:val");
|
|
1960
|
-
if (interSpacing !== void 0) o.interSpacing = interSpacing;
|
|
1961
|
-
const intraSpacing = readNum(findChild(el, "m:intraSp"), "m:val");
|
|
1962
|
-
if (intraSpacing !== void 0) o.intraSpacing = intraSpacing;
|
|
1963
|
-
const wrapIndent = readNum(findChild(el, "m:wrapIndent"), "m:val");
|
|
1964
|
-
if (wrapIndent !== void 0) o.wrapIndent = wrapIndent;
|
|
1965
|
-
const wrapRight = readOnOff(findChild(el, "m:wrapRight"));
|
|
1966
|
-
if (wrapRight !== void 0) o.wrapRight = wrapRight;
|
|
1967
|
-
const integralLimitLocation = readEnum(findChild(el, "m:intLim"), "m:val", ["subSup", "undOvr"]);
|
|
1968
|
-
if (integralLimitLocation) o.integralLimitLocation = integralLimitLocation;
|
|
1969
|
-
const naryLimitLocation = readEnum(findChild(el, "m:naryLim"), "m:val", ["subSup", "undOvr"]);
|
|
1970
|
-
if (naryLimitLocation) o.naryLimitLocation = naryLimitLocation;
|
|
1971
|
-
return Object.keys(o).length > 0 ? o : void 0;
|
|
1972
|
-
}
|
|
1973
|
-
/** Parse w:captions (CT_Captions). */
|
|
1974
|
-
function parseCaptions(el) {
|
|
1975
|
-
const captions = [];
|
|
1976
|
-
const autoCaptions = [];
|
|
1977
|
-
for (const child of el.elements ?? []) {
|
|
1978
|
-
if (child.type !== "element") continue;
|
|
1979
|
-
if (child.name === "w:caption") {
|
|
1980
|
-
const c = { name: attr(child, "w:name") ?? "" };
|
|
1981
|
-
const pos = attr(child, "w:pos");
|
|
1982
|
-
if (pos) c.pos = pos;
|
|
1983
|
-
const chapNum = attr(child, "w:chapNum");
|
|
1984
|
-
if (chapNum !== void 0) c.chapNum = chapNum === "1";
|
|
1985
|
-
const heading = attr(child, "w:heading");
|
|
1986
|
-
if (heading !== void 0) c.heading = parseInt(heading, 10);
|
|
1987
|
-
const noLabel = attr(child, "w:noLabel");
|
|
1988
|
-
if (noLabel !== void 0) c.noLabel = noLabel === "1";
|
|
1989
|
-
const numFmt = attr(child, "w:numFmt");
|
|
1990
|
-
if (numFmt) c.numFmt = numFmt;
|
|
1991
|
-
const sep = attr(child, "w:sep");
|
|
1992
|
-
if (sep) c.sep = sep;
|
|
1993
|
-
captions.push(c);
|
|
1994
|
-
} else if (child.name === "w:autoCaptions") for (const ac of child.elements ?? []) {
|
|
1995
|
-
if (ac.name !== "w:autoCaption") continue;
|
|
1996
|
-
const name = attr(ac, "w:name");
|
|
1997
|
-
const caption = attr(ac, "w:caption");
|
|
1998
|
-
if (name && caption) autoCaptions.push({
|
|
1999
|
-
name,
|
|
2000
|
-
caption
|
|
2001
|
-
});
|
|
2002
|
-
}
|
|
2003
|
-
}
|
|
2004
|
-
if (captions.length === 0) return void 0;
|
|
2005
|
-
const o = { captions };
|
|
2006
|
-
if (autoCaptions.length > 0) o.autoCaptions = autoCaptions;
|
|
2007
|
-
return o;
|
|
2008
|
-
}
|
|
2009
|
-
/** Parse w:odso (CT_Odso). */
|
|
2010
|
-
function parseOdso(el) {
|
|
2011
|
-
const o = {};
|
|
2012
|
-
const udl = readStr(findChild(el, "w:udl"), "w:val");
|
|
2013
|
-
if (udl) o.udl = udl;
|
|
2014
|
-
const table = readStr(findChild(el, "w:table"), "w:val");
|
|
2015
|
-
if (table) o.table = table;
|
|
2016
|
-
const srcEl = findChild(el, "w:src");
|
|
2017
|
-
if (srcEl) {
|
|
2018
|
-
const rid = attr(srcEl, "r:id");
|
|
2019
|
-
if (rid) o.src = rid;
|
|
2020
|
-
}
|
|
2021
|
-
const colDelim = readNum(findChild(el, "w:colDelim"), "w:val");
|
|
2022
|
-
if (colDelim !== void 0) o.colDelim = colDelim;
|
|
2023
|
-
const type = readStr(findChild(el, "w:type"), "w:val");
|
|
2024
|
-
if (type) o.type = type;
|
|
2025
|
-
const fHdr = readOnOff(findChild(el, "w:fHdr"));
|
|
2026
|
-
if (fHdr !== void 0) o.fHdr = fHdr;
|
|
2027
|
-
const fieldMapData = [];
|
|
2028
|
-
for (const child of el.elements ?? []) {
|
|
2029
|
-
if (child.name !== "w:fieldMapData") continue;
|
|
2030
|
-
const fm = {};
|
|
2031
|
-
const t = readStr(findChild(child, "w:type"), "w:val");
|
|
2032
|
-
if (t) fm.type = t;
|
|
2033
|
-
const n = readStr(findChild(child, "w:name"), "w:val");
|
|
2034
|
-
if (n) fm.name = n;
|
|
2035
|
-
const mn = readStr(findChild(child, "w:mappedName"), "w:val");
|
|
2036
|
-
if (mn) fm.mappedName = mn;
|
|
2037
|
-
const col = readNum(findChild(child, "w:column"), "w:val");
|
|
2038
|
-
if (col !== void 0) fm.column = col;
|
|
2039
|
-
const lid = readStr(findChild(child, "w:lid"), "w:val");
|
|
2040
|
-
if (lid) fm.lid = lid;
|
|
2041
|
-
const dyn = readOnOff(findChild(child, "w:dynamicAddress"));
|
|
2042
|
-
if (dyn !== void 0) fm.dynamicAddress = dyn;
|
|
2043
|
-
if (Object.keys(fm).length > 0) fieldMapData.push(fm);
|
|
2044
|
-
}
|
|
2045
|
-
if (fieldMapData.length > 0) o.fieldMapData = fieldMapData;
|
|
2046
|
-
const recipientData = [];
|
|
2047
|
-
for (const child of el.elements ?? []) {
|
|
2048
|
-
if (child.name !== "w:recipientData") continue;
|
|
2049
|
-
const rid = attr(child, "r:id");
|
|
2050
|
-
if (rid) recipientData.push(rid);
|
|
2051
|
-
}
|
|
2052
|
-
if (recipientData.length > 0) o.recipientData = recipientData;
|
|
2053
|
-
const uniqueTag = readStr(findChild(el, "w:uniqueTag"), "w:val");
|
|
2054
|
-
if (uniqueTag) o.uniqueTag = uniqueTag;
|
|
2055
|
-
return Object.keys(o).length > 0 ? o : void 0;
|
|
2056
|
-
}
|
|
2057
|
-
/** Parse w:mailMerge (CT_MailMerge). */
|
|
2058
|
-
function parseMailMerge(el) {
|
|
2059
|
-
const o = {};
|
|
2060
|
-
const mdt = readStr(findChild(el, "w:mainDocumentType"), "w:val");
|
|
2061
|
-
if (mdt) o.mainDocumentType = mdt;
|
|
2062
|
-
const dataType = readStr(findChild(el, "w:dataType"), "w:val");
|
|
2063
|
-
if (dataType) o.dataType = dataType;
|
|
2064
|
-
const dest = readStr(findChild(el, "w:destination"), "w:val");
|
|
2065
|
-
if (dest) o.destination = dest;
|
|
2066
|
-
const connectString = readStr(findChild(el, "w:connectString"), "w:val");
|
|
2067
|
-
if (connectString) o.connectString = connectString;
|
|
2068
|
-
const query = readStr(findChild(el, "w:query"), "w:val");
|
|
2069
|
-
if (query) o.query = query;
|
|
2070
|
-
const dsEl = findChild(el, "w:dataSource");
|
|
2071
|
-
if (dsEl) {
|
|
2072
|
-
const rid = attr(dsEl, "r:id");
|
|
2073
|
-
if (rid) o.dataSource = rid;
|
|
2074
|
-
}
|
|
2075
|
-
const hsEl = findChild(el, "w:headerSource");
|
|
2076
|
-
if (hsEl) {
|
|
2077
|
-
const rid = attr(hsEl, "r:id");
|
|
2078
|
-
if (rid) o.headerSource = rid;
|
|
2079
|
-
}
|
|
2080
|
-
const linkToQuery = readOnOff(findChild(el, "w:linkToQuery"));
|
|
2081
|
-
if (linkToQuery !== void 0) o.linkToQuery = linkToQuery;
|
|
2082
|
-
const doNotSuppress = readOnOff(findChild(el, "w:doNotSuppressBlankLines"));
|
|
2083
|
-
if (doNotSuppress !== void 0) o.doNotSuppressBlankLines = doNotSuppress;
|
|
2084
|
-
const addressFieldName = readStr(findChild(el, "w:addressFieldName"), "w:val");
|
|
2085
|
-
if (addressFieldName) o.addressFieldName = addressFieldName;
|
|
2086
|
-
const mailSubject = readStr(findChild(el, "w:mailSubject"), "w:val");
|
|
2087
|
-
if (mailSubject) o.mailSubject = mailSubject;
|
|
2088
|
-
const mailAsAttachment = readOnOff(findChild(el, "w:mailAsAttachment"));
|
|
2089
|
-
if (mailAsAttachment !== void 0) o.mailAsAttachment = mailAsAttachment;
|
|
2090
|
-
const viewMergedData = readOnOff(findChild(el, "w:viewMergedData"));
|
|
2091
|
-
if (viewMergedData !== void 0) o.viewMergedData = viewMergedData;
|
|
2092
|
-
const activeRecord = readNum(findChild(el, "w:activeRecord"), "w:val");
|
|
2093
|
-
if (activeRecord !== void 0) o.activeRecord = activeRecord;
|
|
2094
|
-
const checkErrors = readNum(findChild(el, "w:checkErrors"), "w:val");
|
|
2095
|
-
if (checkErrors !== void 0) o.checkErrors = checkErrors;
|
|
2096
|
-
const active = readOnOff(findChild(el, "w:active"));
|
|
2097
|
-
if (active !== void 0) o.active = active;
|
|
2098
|
-
const recipientsEl = findChild(el, "w:recipients");
|
|
2099
|
-
if (recipientsEl) {
|
|
2100
|
-
const rid = attr(recipientsEl, "r:id");
|
|
2101
|
-
if (rid) o.recipients = rid;
|
|
2102
|
-
}
|
|
2103
|
-
const odsoEl = findChild(el, "w:odso");
|
|
2104
|
-
if (odsoEl) {
|
|
2105
|
-
const odso = parseOdso(odsoEl);
|
|
2106
|
-
if (odso) o.odso = odso;
|
|
2107
|
-
}
|
|
2108
|
-
if (Object.keys(o).length === 0) return void 0;
|
|
2109
|
-
return o;
|
|
2110
|
-
}
|
|
2111
|
-
function maybeDerive(password, hashValue) {
|
|
2112
|
-
return password !== void 0 && hashValue === void 0 ? derivePasswordHash(password) : void 0;
|
|
2113
|
-
}
|
|
2114
|
-
/** Valid w:documentProtection/@w:edit values (ST_DocProtect). */
|
|
2115
|
-
const DOC_PROTECT_EDITS = [
|
|
2116
|
-
"none",
|
|
2117
|
-
"readOnly",
|
|
2118
|
-
"comments",
|
|
2119
|
-
"trackedChanges",
|
|
2120
|
-
"forms"
|
|
2121
|
-
];
|
|
2122
|
-
function stringifyDocProtect(opts) {
|
|
2123
|
-
const derived = maybeDerive(opts.password, opts.hashValue);
|
|
2124
|
-
const attrs = { "w:enforcement": "1" };
|
|
2125
|
-
if (opts.edit !== void 0) attrs["w:edit"] = opts.edit;
|
|
2126
|
-
if (opts.formatting !== void 0) attrs["w:formatting"] = opts.formatting ? "1" : "0";
|
|
2127
|
-
if (opts.algorithmName ?? derived?.algorithmName) attrs["w:algorithmName"] = opts.algorithmName ?? derived.algorithmName;
|
|
2128
|
-
if (opts.hashValue ?? derived?.hashValue) attrs["w:hashValue"] = opts.hashValue ?? derived.hashValue;
|
|
2129
|
-
if (opts.saltValue ?? derived?.saltValue) attrs["w:saltValue"] = opts.saltValue ?? derived.saltValue;
|
|
2130
|
-
if (opts.hash !== void 0) attrs["w:hash"] = opts.hash;
|
|
2131
|
-
if (opts.salt !== void 0) attrs["w:salt"] = opts.salt;
|
|
2132
|
-
if (opts.spinCount ?? derived?.spinCount) attrs["w:spinCount"] = opts.spinCount ?? derived.spinCount;
|
|
2133
|
-
if (opts.cryptoAlgorithmClass !== void 0) attrs["w:cryptAlgorithmClass"] = opts.cryptoAlgorithmClass;
|
|
2134
|
-
if (opts.cryptoAlgorithmSid !== void 0) attrs["w:cryptAlgorithmSid"] = opts.cryptoAlgorithmSid;
|
|
2135
|
-
if (opts.cryptoAlgorithmType !== void 0) attrs["w:cryptAlgorithmType"] = opts.cryptoAlgorithmType;
|
|
2136
|
-
if (opts.cryptoProvider !== void 0) attrs["w:cryptProvider"] = opts.cryptoProvider;
|
|
2137
|
-
if (opts.cryptoProviderType !== void 0) attrs["w:cryptProviderType"] = opts.cryptoProviderType;
|
|
2138
|
-
if (opts.cryptoProviderTypeExtension !== void 0) attrs["w:cryptProviderTypeExt"] = opts.cryptoProviderTypeExtension;
|
|
2139
|
-
if (opts.cryptoProviderTypeExtensionSource !== void 0) attrs["w:cryptProviderTypeExtSource"] = opts.cryptoProviderTypeExtensionSource;
|
|
2140
|
-
if (opts.algorithmExtensionId !== void 0) attrs["w:algIdExt"] = opts.algorithmExtensionId;
|
|
2141
|
-
if (opts.algorithmExtensionSource !== void 0) attrs["w:algIdExtSource"] = opts.algorithmExtensionSource;
|
|
2142
|
-
if (opts.cryptoSpinCount !== void 0) attrs["w:cryptSpinCount"] = opts.cryptoSpinCount;
|
|
2143
|
-
return attrEl("w:documentProtection", attrs);
|
|
2144
|
-
}
|
|
2145
|
-
function stringifyWriteProtect(opts) {
|
|
2146
|
-
const derived = maybeDerive(opts.password, opts.hashValue);
|
|
2147
|
-
const attrs = {};
|
|
2148
|
-
if (opts.recommended !== void 0) attrs["w:recommended"] = opts.recommended ? "1" : "0";
|
|
2149
|
-
if (opts.hashValue ?? derived?.hashValue) attrs["w:hashValue"] = opts.hashValue ?? derived.hashValue;
|
|
2150
|
-
if (opts.saltValue ?? derived?.saltValue) attrs["w:saltValue"] = opts.saltValue ?? derived.saltValue;
|
|
2151
|
-
if (opts.hash !== void 0) attrs["w:hash"] = opts.hash;
|
|
2152
|
-
if (opts.salt !== void 0) attrs["w:salt"] = opts.salt;
|
|
2153
|
-
if (opts.spinCount ?? derived?.spinCount) attrs["w:spinCount"] = opts.spinCount ?? derived.spinCount;
|
|
2154
|
-
if (opts.algorithmName ?? derived?.algorithmName) attrs["w:algorithmName"] = opts.algorithmName ?? derived.algorithmName;
|
|
2155
|
-
if (opts.cryptoAlgorithmClass !== void 0) attrs["w:cryptAlgorithmClass"] = opts.cryptoAlgorithmClass;
|
|
2156
|
-
if (opts.cryptoAlgorithmSid !== void 0) attrs["w:cryptAlgorithmSid"] = opts.cryptoAlgorithmSid;
|
|
2157
|
-
if (opts.cryptoAlgorithmType !== void 0) attrs["w:cryptAlgorithmType"] = opts.cryptoAlgorithmType;
|
|
2158
|
-
if (opts.cryptoProvider !== void 0) attrs["w:cryptProvider"] = opts.cryptoProvider;
|
|
2159
|
-
if (opts.cryptoProviderType !== void 0) attrs["w:cryptProviderType"] = opts.cryptoProviderType;
|
|
2160
|
-
if (opts.algorithmExtensionId !== void 0) attrs["w:algIdExt"] = opts.algorithmExtensionId;
|
|
2161
|
-
if (opts.algorithmExtensionSource !== void 0) attrs["w:algIdExtSource"] = opts.algorithmExtensionSource;
|
|
2162
|
-
if (opts.cryptoProviderTypeExtension !== void 0) attrs["w:cryptProviderTypeExt"] = opts.cryptoProviderTypeExtension;
|
|
2163
|
-
if (opts.cryptoProviderTypeExtensionSource !== void 0) attrs["w:cryptProviderTypeExtSource"] = opts.cryptoProviderTypeExtensionSource;
|
|
2164
|
-
if (opts.cryptoSpinCount !== void 0) attrs["w:cryptSpinCount"] = opts.cryptoSpinCount;
|
|
2165
|
-
return attrEl("w:writeProtection", attrs);
|
|
2166
|
-
}
|
|
2167
|
-
function stringifyRevisionView(opts) {
|
|
2168
|
-
const attrs = {};
|
|
2169
|
-
if (opts.markup !== void 0) attrs["w:markup"] = opts.markup ? "true" : "false";
|
|
2170
|
-
if (opts.comments !== void 0) attrs["w:comments"] = opts.comments ? "true" : "false";
|
|
2171
|
-
if (opts.insDel !== void 0) attrs["w:insDel"] = opts.insDel ? "true" : "false";
|
|
2172
|
-
if (opts.formatting !== void 0) attrs["w:formatting"] = opts.formatting ? "true" : "false";
|
|
2173
|
-
if (opts.inkAnnotations !== void 0) attrs["w:inkAnnotations"] = opts.inkAnnotations ? "true" : "false";
|
|
2174
|
-
return attrEl("w:revisionView", attrs);
|
|
2175
|
-
}
|
|
2176
|
-
function stringifyMailMerge(opts) {
|
|
2177
|
-
const p = [];
|
|
2178
|
-
p.push(strVal("w:mainDocumentType", opts.mainDocumentType));
|
|
2179
|
-
p.push(onOff("w:linkToQuery", opts.linkToQuery));
|
|
2180
|
-
p.push(strVal("w:dataType", opts.dataType));
|
|
2181
|
-
p.push(strVal("w:connectString", opts.connectString));
|
|
2182
|
-
p.push(strVal("w:query", opts.query));
|
|
2183
|
-
if (opts.dataSource !== void 0) p.push(attrEl("w:dataSource", { "r:id": opts.dataSource }));
|
|
2184
|
-
if (opts.headerSource !== void 0) p.push(attrEl("w:headerSource", { "r:id": opts.headerSource }));
|
|
2185
|
-
p.push(onOff("w:doNotSuppressBlankLines", opts.doNotSuppressBlankLines));
|
|
2186
|
-
p.push(strVal("w:destination", opts.destination));
|
|
2187
|
-
p.push(strVal("w:addressFieldName", opts.addressFieldName));
|
|
2188
|
-
p.push(strVal("w:mailSubject", opts.mailSubject));
|
|
2189
|
-
p.push(onOff("w:mailAsAttachment", opts.mailAsAttachment));
|
|
2190
|
-
p.push(onOff("w:viewMergedData", opts.viewMergedData));
|
|
2191
|
-
p.push(numVal("w:activeRecord", opts.activeRecord));
|
|
2192
|
-
p.push(numVal("w:checkErrors", opts.checkErrors));
|
|
2193
|
-
if (opts.odso !== void 0) p.push(stringifyOdso(opts.odso));
|
|
2194
|
-
p.push(onOff("w:active", opts.active));
|
|
2195
|
-
if (opts.recipients !== void 0) p.push(attrEl("w:recipients", { "r:id": opts.recipients }));
|
|
2196
|
-
return `<w:mailMerge>${p.join("")}</w:mailMerge>`;
|
|
2197
|
-
}
|
|
2198
|
-
function stringifyOdso(opts) {
|
|
2199
|
-
const p = [];
|
|
2200
|
-
p.push(strVal("w:udl", opts.udl));
|
|
2201
|
-
p.push(strVal("w:table", opts.table));
|
|
2202
|
-
if (opts.src !== void 0) p.push(attrEl("w:src", { "r:id": opts.src }));
|
|
2203
|
-
p.push(numVal("w:colDelim", opts.colDelim));
|
|
2204
|
-
p.push(strVal("w:type", opts.type));
|
|
2205
|
-
p.push(onOff("w:fHdr", opts.fHdr));
|
|
2206
|
-
if (opts.fieldMapData !== void 0) for (const fm of opts.fieldMapData) p.push(stringifyOdsoFieldMap(fm));
|
|
2207
|
-
if (opts.recipientData !== void 0) for (const rd of opts.recipientData) p.push(attrEl("w:recipientData", { "r:id": rd }));
|
|
2208
|
-
p.push(strVal("w:uniqueTag", opts.uniqueTag));
|
|
2209
|
-
return `<w:odso>${p.join("")}</w:odso>`;
|
|
2210
|
-
}
|
|
2211
|
-
function stringifyOdsoFieldMap(opts) {
|
|
2212
|
-
const p = [];
|
|
2213
|
-
p.push(strVal("w:type", opts.type));
|
|
2214
|
-
p.push(strVal("w:name", opts.name));
|
|
2215
|
-
p.push(strVal("w:mappedName", opts.mappedName));
|
|
2216
|
-
p.push(numVal("w:column", opts.column));
|
|
2217
|
-
p.push(strVal("w:lid", opts.lid));
|
|
2218
|
-
p.push(onOff("w:dynamicAddress", opts.dynamicAddress));
|
|
2219
|
-
return `<w:fieldMapData>${p.join("")}</w:fieldMapData>`;
|
|
2220
|
-
}
|
|
2221
|
-
function stringifyFootnotePr(opts) {
|
|
2222
|
-
const p = [];
|
|
2223
|
-
if (opts.pos !== void 0) p.push(attrEl("w:pos", { "w:val": opts.pos }));
|
|
2224
|
-
if (opts.numFmt !== void 0 || opts.format !== void 0) {
|
|
2225
|
-
const a = {};
|
|
2226
|
-
if (opts.numFmt !== void 0) a["w:val"] = opts.numFmt;
|
|
2227
|
-
if (opts.format !== void 0) a["w:format"] = opts.format;
|
|
2228
|
-
p.push(attrEl("w:numFmt", a));
|
|
2229
|
-
}
|
|
2230
|
-
p.push(numVal("w:numStart", opts.numStart));
|
|
2231
|
-
p.push(strVal("w:numRestart", opts.numRestart));
|
|
2232
|
-
return `<w:footnotePr>${p.join("")}</w:footnotePr>`;
|
|
2233
|
-
}
|
|
2234
|
-
function stringifyEndnotePr(opts) {
|
|
2235
|
-
const p = [];
|
|
2236
|
-
if (opts.pos !== void 0) p.push(attrEl("w:pos", { "w:val": opts.pos }));
|
|
2237
|
-
if (opts.numFmt !== void 0 || opts.format !== void 0) {
|
|
2238
|
-
const a = {};
|
|
2239
|
-
if (opts.numFmt !== void 0) a["w:val"] = opts.numFmt;
|
|
2240
|
-
if (opts.format !== void 0) a["w:format"] = opts.format;
|
|
2241
|
-
p.push(attrEl("w:numFmt", a));
|
|
2242
|
-
}
|
|
2243
|
-
p.push(numVal("w:numStart", opts.numStart));
|
|
2244
|
-
p.push(strVal("w:numRestart", opts.numRestart));
|
|
2245
|
-
return `<w:endnotePr>${p.join("")}</w:endnotePr>`;
|
|
2246
|
-
}
|
|
2247
|
-
function stringifyRsids(opts) {
|
|
2248
|
-
const p = [];
|
|
2249
|
-
if (opts.rsidRoot !== void 0) p.push(attrEl("w:rsidRoot", { "w:val": opts.rsidRoot }));
|
|
2250
|
-
if (opts.rsids !== void 0) for (const rsid of opts.rsids) p.push(attrEl("w:rsid", { "w:val": rsid }));
|
|
2251
|
-
return `<w:rsids>${p.join("")}</w:rsids>`;
|
|
2252
|
-
}
|
|
2253
|
-
function stringifyReadModeInkLockDown(opts) {
|
|
2254
|
-
return attrEl("w:readModeInkLockDown", {
|
|
2255
|
-
"w:actualPg": opts.actualPg === false ? "0" : "1",
|
|
2256
|
-
"w:w": opts.w,
|
|
2257
|
-
"w:h": opts.h,
|
|
2258
|
-
"w:fontSz": opts.fontSz
|
|
2259
|
-
});
|
|
2260
|
-
}
|
|
2261
|
-
function stringifyCaptions(opts) {
|
|
2262
|
-
const p = [];
|
|
2263
|
-
for (const cap of opts.captions) {
|
|
2264
|
-
const attrs = { "w:name": cap.name };
|
|
2265
|
-
if (cap.pos !== void 0) attrs["w:pos"] = cap.pos;
|
|
2266
|
-
if (cap.chapNum !== void 0) attrs["w:chapNum"] = cap.chapNum ? "1" : "0";
|
|
2267
|
-
if (cap.heading !== void 0) attrs["w:heading"] = cap.heading;
|
|
2268
|
-
if (cap.noLabel !== void 0) attrs["w:noLabel"] = cap.noLabel ? "1" : "0";
|
|
2269
|
-
if (cap.numFmt !== void 0) attrs["w:numFmt"] = cap.numFmt;
|
|
2270
|
-
if (cap.sep !== void 0) attrs["w:sep"] = cap.sep;
|
|
2271
|
-
p.push(attrEl("w:caption", attrs));
|
|
2272
|
-
}
|
|
2273
|
-
if (opts.autoCaptions?.length) {
|
|
2274
|
-
const acXml = opts.autoCaptions.map((ac) => attrEl("w:autoCaption", {
|
|
2275
|
-
"w:name": ac.name,
|
|
2276
|
-
"w:caption": ac.caption
|
|
2277
|
-
})).join("");
|
|
2278
|
-
p.push(`<w:autoCaptions>${acXml}</w:autoCaptions>`);
|
|
2279
|
-
}
|
|
2280
|
-
return `<w:captions>${p.join("")}</w:captions>`;
|
|
2281
|
-
}
|
|
2282
|
-
function stringifyMathPr(opts) {
|
|
2283
|
-
const p = [];
|
|
2284
|
-
if (opts.mathFont !== void 0) p.push(attrEl("m:mathFont", { "m:val": opts.mathFont }));
|
|
2285
|
-
if (opts.binaryOperatorBreak !== void 0) p.push(attrEl("m:brkBin", { "m:val": opts.binaryOperatorBreak }));
|
|
2286
|
-
if (opts.binaryOperatorBreakSubtraction !== void 0) p.push(attrEl("m:brkBinSub", { "m:val": opts.binaryOperatorBreakSubtraction }));
|
|
2287
|
-
p.push(onOff("m:smallFrac", opts.smallFractions));
|
|
2288
|
-
p.push(onOff("m:dispDef", opts.displayDefaults));
|
|
2289
|
-
p.push(numVal("m:lMargin", opts.leftMargin));
|
|
2290
|
-
p.push(numVal("m:rMargin", opts.rightMargin));
|
|
2291
|
-
if (opts.defaultJustification !== void 0) p.push(attrEl("m:defJc", { "m:val": opts.defaultJustification }));
|
|
2292
|
-
p.push(numVal("m:preSp", opts.preSpacing));
|
|
2293
|
-
p.push(numVal("m:postSp", opts.postSpacing));
|
|
2294
|
-
p.push(numVal("m:interSp", opts.interSpacing));
|
|
2295
|
-
p.push(numVal("m:intraSp", opts.intraSpacing));
|
|
2296
|
-
p.push(numVal("m:wrapIndent", opts.wrapIndent));
|
|
2297
|
-
p.push(onOff("m:wrapRight", opts.wrapRight));
|
|
2298
|
-
if (opts.integralLimitLocation !== void 0) p.push(attrEl("m:intLim", { "m:val": opts.integralLimitLocation }));
|
|
2299
|
-
if (opts.naryLimitLocation !== void 0) p.push(attrEl("m:naryLim", { "m:val": opts.naryLimitLocation }));
|
|
2300
|
-
return `<m:mathPr>${p.join("")}</m:mathPr>`;
|
|
2301
|
-
}
|
|
2302
|
-
function stringifyColorSchemeMapping(opts) {
|
|
2303
|
-
const attrs = {};
|
|
2304
|
-
if (opts.bg1 !== void 0) attrs["w:bg1"] = opts.bg1;
|
|
2305
|
-
if (opts.t1 !== void 0) attrs["w:t1"] = opts.t1;
|
|
2306
|
-
if (opts.bg2 !== void 0) attrs["w:bg2"] = opts.bg2;
|
|
2307
|
-
if (opts.t2 !== void 0) attrs["w:t2"] = opts.t2;
|
|
2308
|
-
if (opts.accent1 !== void 0) attrs["w:accent1"] = opts.accent1;
|
|
2309
|
-
if (opts.accent2 !== void 0) attrs["w:accent2"] = opts.accent2;
|
|
2310
|
-
if (opts.accent3 !== void 0) attrs["w:accent3"] = opts.accent3;
|
|
2311
|
-
if (opts.accent4 !== void 0) attrs["w:accent4"] = opts.accent4;
|
|
2312
|
-
if (opts.accent5 !== void 0) attrs["w:accent5"] = opts.accent5;
|
|
2313
|
-
if (opts.accent6 !== void 0) attrs["w:accent6"] = opts.accent6;
|
|
2314
|
-
if (opts.hyperlink !== void 0) attrs["w:hyperlink"] = opts.hyperlink;
|
|
2315
|
-
if (opts.followedHyperlink !== void 0) attrs["w:followedHyperlink"] = opts.followedHyperlink;
|
|
2316
|
-
return attrEl("w:clrSchemeMapping", attrs);
|
|
2317
|
-
}
|
|
2318
|
-
function stringifyCompatibility(opts) {
|
|
2319
|
-
const p = [];
|
|
2320
|
-
if (opts.useSingleBorderforContiguousCells) p.push(onOff("w:useSingleBorderforContiguousCells", true));
|
|
2321
|
-
if (opts.wordPerfectJustification) p.push(onOff("w:wpJustification", true));
|
|
2322
|
-
if (opts.noTabStopForHangingIndent) p.push(onOff("w:noTabHangInd", true));
|
|
2323
|
-
if (opts.noLeading) p.push(onOff("w:noLeading", true));
|
|
2324
|
-
if (opts.spaceForUnderline) p.push(onOff("w:spaceForUL", true));
|
|
2325
|
-
if (opts.noColumnBalance) p.push(onOff("w:noColumnBalance", true));
|
|
2326
|
-
if (opts.balanceSingleByteDoubleByteWidth) p.push(onOff("w:balanceSingleByteDoubleByteWidth", true));
|
|
2327
|
-
if (opts.noExtraLineSpacing) p.push(onOff("w:noExtraLineSpacing", true));
|
|
2328
|
-
if (opts.doNotLeaveBackslashAlone) p.push(onOff("w:doNotLeaveBackslashAlone", true));
|
|
2329
|
-
if (opts.underlineTrailingSpaces) p.push(onOff("w:ulTrailSpace", true));
|
|
2330
|
-
if (opts.doNotExpandShiftReturn) p.push(onOff("w:doNotExpandShiftReturn", true));
|
|
2331
|
-
if (opts.spacingInWholePoints) p.push(onOff("w:spacingInWholePoints", true));
|
|
2332
|
-
if (opts.lineWrapLikeWord6) p.push(onOff("w:lineWrapLikeWord6", true));
|
|
2333
|
-
if (opts.printBodyTextBeforeHeader) p.push(onOff("w:printBodyTextBeforeHeader", true));
|
|
2334
|
-
if (opts.printColorsBlack) p.push(onOff("w:printColBlack", true));
|
|
2335
|
-
if (opts.spaceWidth) p.push(onOff("w:wpSpaceWidth", true));
|
|
2336
|
-
if (opts.showBreaksInFrames) p.push(onOff("w:showBreaksInFrames", true));
|
|
2337
|
-
if (opts.subFontBySize) p.push(onOff("w:subFontBySize", true));
|
|
2338
|
-
if (opts.suppressBottomSpacing) p.push(onOff("w:suppressBottomSpacing", true));
|
|
2339
|
-
if (opts.suppressTopSpacing) p.push(onOff("w:suppressTopSpacing", true));
|
|
2340
|
-
if (opts.suppressSpacingAtTopOfPage) p.push(onOff("w:suppressSpacingAtTopOfPage", true));
|
|
2341
|
-
if (opts.suppressTopSpacingWP) p.push(onOff("w:suppressTopSpacingWP", true));
|
|
2342
|
-
if (opts.suppressSpBfAfterPgBrk) p.push(onOff("w:suppressSpBfAfterPgBrk", true));
|
|
2343
|
-
if (opts.swapBordersFacingPages) p.push(onOff("w:swapBordersFacingPages", true));
|
|
2344
|
-
if (opts.convertMailMergeEsc) p.push(onOff("w:convMailMergeEsc", true));
|
|
2345
|
-
if (opts.truncateFontHeightsLikeWP6) p.push(onOff("w:truncateFontHeightsLikeWP6", true));
|
|
2346
|
-
if (opts.macWordSmallCaps) p.push(onOff("w:mwSmallCaps", true));
|
|
2347
|
-
if (opts.usePrinterMetrics) p.push(onOff("w:usePrinterMetrics", true));
|
|
2348
|
-
if (opts.doNotSuppressParagraphBorders) p.push(onOff("w:doNotSuppressParagraphBorders", true));
|
|
2349
|
-
if (opts.wrapTrailSpaces) p.push(onOff("w:wrapTrailSpaces", true));
|
|
2350
|
-
if (opts.footnoteLayoutLikeWW8) p.push(onOff("w:footnoteLayoutLikeWW8", true));
|
|
2351
|
-
if (opts.shapeLayoutLikeWW8) p.push(onOff("w:shapeLayoutLikeWW8", true));
|
|
2352
|
-
if (opts.alignTablesRowByRow) p.push(onOff("w:alignTablesRowByRow", true));
|
|
2353
|
-
if (opts.forgetLastTabAlignment) p.push(onOff("w:forgetLastTabAlignment", true));
|
|
2354
|
-
if (opts.adjustLineHeightInTable) p.push(onOff("w:adjustLineHeightInTable", true));
|
|
2355
|
-
if (opts.autoSpaceLikeWord95) p.push(onOff("w:autoSpaceLikeWord95", true));
|
|
2356
|
-
if (opts.noSpaceRaiseLower) p.push(onOff("w:noSpaceRaiseLower", true));
|
|
2357
|
-
if (opts.doNotUseHTMLParagraphAutoSpacing) p.push(onOff("w:doNotUseHTMLParagraphAutoSpacing", true));
|
|
2358
|
-
if (opts.layoutRawTableWidth) p.push(onOff("w:layoutRawTableWidth", true));
|
|
2359
|
-
if (opts.layoutTableRowsApart) p.push(onOff("w:layoutTableRowsApart", true));
|
|
2360
|
-
if (opts.useWord97LineBreakRules) p.push(onOff("w:useWord97LineBreakRules", true));
|
|
2361
|
-
if (opts.doNotBreakWrappedTables) p.push(onOff("w:doNotBreakWrappedTables", true));
|
|
2362
|
-
if (opts.doNotSnapToGridInCell) p.push(onOff("w:doNotSnapToGridInCell", true));
|
|
2363
|
-
if (opts.selectFieldWithFirstOrLastCharacter) p.push(onOff("w:selectFldWithFirstOrLastChar", true));
|
|
2364
|
-
if (opts.applyBreakingRules) p.push(onOff("w:applyBreakingRules", true));
|
|
2365
|
-
if (opts.doNotWrapTextWithPunctuation) p.push(onOff("w:doNotWrapTextWithPunct", true));
|
|
2366
|
-
if (opts.doNotUseEastAsianBreakRules) p.push(onOff("w:doNotUseEastAsianBreakRules", true));
|
|
2367
|
-
if (opts.useWord2002TableStyleRules) p.push(onOff("w:useWord2002TableStyleRules", true));
|
|
2368
|
-
if (opts.growAutofit) p.push(onOff("w:growAutofit", true));
|
|
2369
|
-
if (opts.useFELayout) p.push(onOff("w:useFELayout", true));
|
|
2370
|
-
if (opts.useNormalStyleForList) p.push(onOff("w:useNormalStyleForList", true));
|
|
2371
|
-
if (opts.doNotUseIndentAsNumberingTabStop) p.push(onOff("w:doNotUseIndentAsNumberingTabStop", true));
|
|
2372
|
-
if (opts.useAlternateEastAsianLineBreakRules) p.push(onOff("w:useAltKinsokuLineBreakRules", true));
|
|
2373
|
-
if (opts.allowSpaceOfSameStyleInTable) p.push(onOff("w:allowSpaceOfSameStyleInTable", true));
|
|
2374
|
-
if (opts.doNotSuppressIndentation) p.push(onOff("w:doNotSuppressIndentation", true));
|
|
2375
|
-
if (opts.doNotAutofitConstrainedTables) p.push(onOff("w:doNotAutofitConstrainedTables", true));
|
|
2376
|
-
if (opts.autofitToFirstFixedWidthCell) p.push(onOff("w:autofitToFirstFixedWidthCell", true));
|
|
2377
|
-
if (opts.underlineTabInNumberingList) p.push(onOff("w:underlineTabInNumList", true));
|
|
2378
|
-
if (opts.displayHangulFixedWidth) p.push(onOff("w:displayHangulFixedWidth", true));
|
|
2379
|
-
if (opts.splitPgBreakAndParaMark) p.push(onOff("w:splitPgBreakAndParaMark", true));
|
|
2380
|
-
if (opts.doNotVerticallyAlignCellWithSp) p.push(onOff("w:doNotVertAlignCellWithSp", true));
|
|
2381
|
-
if (opts.doNotBreakConstrainedForcedTable) p.push(onOff("w:doNotBreakConstrainedForcedTable", true));
|
|
2382
|
-
if (opts.ignoreVerticalAlignmentInTextboxes) p.push(onOff("w:doNotVertAlignInTxbx", true));
|
|
2383
|
-
if (opts.useAnsiKerningPairs) p.push(onOff("w:useAnsiKerningPairs", true));
|
|
2384
|
-
if (opts.cachedColumnBalance) p.push(onOff("w:cachedColBalance", true));
|
|
2385
|
-
if (opts.version) p.push(compatSetting("compatibilityMode", opts.version));
|
|
2386
|
-
if (opts.overrideTableStyleFontSizeAndJustification) p.push(compatSetting("overrideTableStyleFontSizeAndJustification", 1));
|
|
2387
|
-
if (opts.enableOpenTypeFeatures) p.push(compatSetting("enableOpenTypeFeatures", 1));
|
|
2388
|
-
if (opts.doNotFlipMirrorIndents) p.push(compatSetting("doNotFlipMirrorIndents", 1));
|
|
2389
|
-
if (opts.compatSettings) {
|
|
2390
|
-
const emitted = /* @__PURE__ */ new Set();
|
|
2391
|
-
if (opts.version) emitted.add("compatibilityMode");
|
|
2392
|
-
if (opts.overrideTableStyleFontSizeAndJustification) emitted.add("overrideTableStyleFontSizeAndJustification");
|
|
2393
|
-
if (opts.enableOpenTypeFeatures) emitted.add("enableOpenTypeFeatures");
|
|
2394
|
-
if (opts.doNotFlipMirrorIndents) emitted.add("doNotFlipMirrorIndents");
|
|
2395
|
-
for (const cs of opts.compatSettings) {
|
|
2396
|
-
if (emitted.has(cs.name)) continue;
|
|
2397
|
-
p.push(compatSetting(cs.name, cs.val, cs.uri));
|
|
2398
|
-
emitted.add(cs.name);
|
|
2399
|
-
}
|
|
2400
|
-
}
|
|
2401
|
-
return p.length ? `<w:compat>${p.join("")}</w:compat>` : "";
|
|
2402
|
-
}
|
|
2403
|
-
const SETTINGS_NS = "xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" mc:Ignorable=\"w14 w15 wp14\"";
|
|
2404
|
-
const settingsDesc = {
|
|
2405
|
-
kind: "custom",
|
|
2406
|
-
stringify(opts, _ctx) {
|
|
2407
|
-
if (opts.rawXml !== void 0) return `<w:settings ${opts.rootAttributes ? attrStr(opts.rootAttributes) : SETTINGS_NS}>${opts.rawXml}</w:settings>`;
|
|
2408
|
-
const p = [];
|
|
2409
|
-
if (opts.writeProtection !== void 0) p.push(stringifyWriteProtect(opts.writeProtection));
|
|
2410
|
-
if (opts.view !== void 0) p.push(attrEl("w:view", { "w:val": opts.view }));
|
|
2411
|
-
if (opts.zoom !== void 0) p.push(attrEl("w:zoom", {
|
|
2412
|
-
"w:percent": opts.zoom.percent ?? 100,
|
|
2413
|
-
"w:val": opts.zoom.val
|
|
2414
|
-
}));
|
|
2415
|
-
p.push(onOff("w:removePersonalInformation", opts.removePersonalInformation));
|
|
2416
|
-
p.push(onOff("w:removeDateAndTime", opts.removeDateAndTime));
|
|
2417
|
-
p.push(onOff("w:doNotDisplayPageBoundaries", opts.doNotDisplayPageBoundaries));
|
|
2418
|
-
p.push(onOff("w:displayBackgroundShape", opts.displayBackgroundShape));
|
|
2419
|
-
p.push(onOff("w:printPostScriptOverText", opts.printPostScriptOverText));
|
|
2420
|
-
p.push(onOff("w:printFractionalCharacterWidth", opts.printFractionalCharacterWidth));
|
|
2421
|
-
p.push(onOff("w:printFormsData", opts.printFormsData));
|
|
2422
|
-
p.push(onOff("w:embedTrueTypeFonts", opts.embedTrueTypeFonts));
|
|
2423
|
-
p.push(onOff("w:embedSystemFonts", opts.embedSystemFonts));
|
|
2424
|
-
p.push(onOff("w:saveSubsetFonts", opts.saveSubsetFonts));
|
|
2425
|
-
p.push(onOff("w:saveFormsData", opts.saveFormsData));
|
|
2426
|
-
p.push(onOff("w:mirrorMargins", opts.mirrorMargins));
|
|
2427
|
-
p.push(onOff("w:alignBordersAndEdges", opts.alignBordersAndEdges));
|
|
2428
|
-
p.push(onOff("w:bordersDoNotSurroundHeader", opts.bordersDoNotSurroundHeader));
|
|
2429
|
-
p.push(onOff("w:bordersDoNotSurroundFooter", opts.bordersDoNotSurroundFooter));
|
|
2430
|
-
p.push(onOff("w:gutterAtTop", opts.gutterAtTop));
|
|
2431
|
-
p.push(onOff("w:hideSpellingErrors", opts.hideSpellingErrors));
|
|
2432
|
-
p.push(onOff("w:hideGrammaticalErrors", opts.hideGrammaticalErrors));
|
|
2433
|
-
if (opts.activeWritingStyle !== void 0) for (const ws of opts.activeWritingStyle) {
|
|
2434
|
-
const attrs = {};
|
|
2435
|
-
if (ws.lang !== void 0) attrs["w:lang"] = ws.lang;
|
|
2436
|
-
if (ws.vendorID !== void 0) attrs["w:vendorID"] = ws.vendorID;
|
|
2437
|
-
if (ws.dllVersion !== void 0) attrs["w:dllVersion"] = ws.dllVersion;
|
|
2438
|
-
if (ws.nlCheck !== void 0) attrs["w:nlCheck"] = ws.nlCheck;
|
|
2439
|
-
if (ws.checkStyle !== void 0) attrs["w:checkStyle"] = ws.checkStyle;
|
|
2440
|
-
if (ws.appCheck !== void 0) attrs["w:appCheck"] = ws.appCheck;
|
|
2441
|
-
if (ws.appName !== void 0) attrs["w:appName"] = ws.appName;
|
|
2442
|
-
p.push(attrEl("w:activeWritingStyle", attrs));
|
|
2443
|
-
}
|
|
2444
|
-
if (opts.proofState !== void 0) {
|
|
2445
|
-
const attrs = {};
|
|
2446
|
-
if (opts.proofState.spelling !== void 0) attrs["w:spelling"] = opts.proofState.spelling;
|
|
2447
|
-
if (opts.proofState.grammar !== void 0) attrs["w:grammar"] = opts.proofState.grammar;
|
|
2448
|
-
p.push(attrEl("w:proofState", attrs));
|
|
2449
|
-
}
|
|
2450
|
-
p.push(onOff("w:formsDesign", opts.formsDesign));
|
|
2451
|
-
if (opts.attachedTemplate !== void 0) p.push(attrEl("w:attachedTemplate", { "r:id": opts.attachedTemplate }));
|
|
2452
|
-
p.push(onOff("w:linkStyles", opts.linkStyles));
|
|
2453
|
-
if (opts.stylePaneFormatFilter !== void 0) {
|
|
2454
|
-
const f = opts.stylePaneFormatFilter;
|
|
2455
|
-
const attrs = {};
|
|
2456
|
-
for (const [prop, xmlKey] of [
|
|
2457
|
-
["allStyles", "w:allStyles"],
|
|
2458
|
-
["customStyles", "w:customStyles"],
|
|
2459
|
-
["stylesInUse", "w:stylesInUse"],
|
|
2460
|
-
["headingStyles", "w:headingStyles"],
|
|
2461
|
-
["numberingStyles", "w:numberingStyles"],
|
|
2462
|
-
["tableStyles", "w:tableStyles"],
|
|
2463
|
-
["directFormattingOnRuns", "w:directFormattingOnRuns"],
|
|
2464
|
-
["directFormattingOnParagraphs", "w:directFormattingOnParagraphs"],
|
|
2465
|
-
["directFormattingOnNumbering", "w:directFormattingOnNumbering"],
|
|
2466
|
-
["directFormattingOnTables", "w:directFormattingOnTables"],
|
|
2467
|
-
["clearFormatting", "w:clearFormatting"],
|
|
2468
|
-
["top3HeadingStyles", "w:top3HeadingStyles"],
|
|
2469
|
-
["visibleStyles", "w:visibleStyles"],
|
|
2470
|
-
["alternateStyleNames", "w:alternateStyleNames"],
|
|
2471
|
-
["latentStyles", "w:latentStyles"]
|
|
2472
|
-
]) if (f[prop] !== void 0) attrs[xmlKey] = f[prop] ? "1" : "0";
|
|
2473
|
-
p.push(attrEl("w:stylePaneFormatFilter", attrs));
|
|
2474
|
-
}
|
|
2475
|
-
p.push(strVal("w:stylePaneSortMethod", opts.stylePaneSortMethod));
|
|
2476
|
-
p.push(strVal("w:documentType", opts.documentType));
|
|
2477
|
-
if (opts.revisionView !== void 0) p.push(stringifyRevisionView(opts.revisionView));
|
|
2478
|
-
p.push(onOff("w:trackRevisions", opts.trackRevisions));
|
|
2479
|
-
p.push(onOff("w:doNotTrackMoves", opts.doNotTrackMoves));
|
|
2480
|
-
p.push(onOff("w:doNotTrackFormatting", opts.doNotTrackFormatting));
|
|
2481
|
-
if (opts.mailMerge !== void 0) p.push(stringifyMailMerge(opts.mailMerge));
|
|
2482
|
-
if (opts.documentProtection !== void 0) p.push(stringifyDocProtect(opts.documentProtection));
|
|
2483
|
-
p.push(onOff("w:autoFormatOverride", opts.autoFormatOverride));
|
|
2484
|
-
p.push(onOff("w:styleLockTheme", opts.styleLockTheme));
|
|
2485
|
-
p.push(onOff("w:styleLockQFSet", opts.styleLockQFSet));
|
|
2486
|
-
if (opts.defaultTabStop !== void 0) p.push(numVal("w:defaultTabStop", opts.defaultTabStop));
|
|
2487
|
-
p.push(onOff("w:autoHyphenation", opts.hyphenation?.autoHyphenation));
|
|
2488
|
-
p.push(numVal("w:consecutiveHyphenLimit", opts.hyphenation?.consecutiveHyphenLimit));
|
|
2489
|
-
p.push(numVal("w:hyphenationZone", opts.hyphenation?.hyphenationZone));
|
|
2490
|
-
p.push(onOff("w:doNotHyphenateCaps", opts.hyphenation?.doNotHyphenateCaps));
|
|
2491
|
-
p.push(onOff("w:showEnvelope", opts.showEnvelope));
|
|
2492
|
-
p.push(numVal("w:summaryLength", opts.summaryLength));
|
|
2493
|
-
p.push(strVal("w:clickAndTypeStyle", opts.clickAndTypeStyle));
|
|
2494
|
-
p.push(strVal("w:defaultTableStyle", opts.defaultTableStyle));
|
|
2495
|
-
p.push(onOff("w:evenAndOddHeaders", opts.evenAndOddHeaders));
|
|
2496
|
-
p.push(onOff("w:bookFoldRevPrinting", opts.bookFoldRevPrinting));
|
|
2497
|
-
p.push(onOff("w:bookFoldPrinting", opts.bookFoldPrinting));
|
|
2498
|
-
p.push(numVal("w:bookFoldPrintingSheets", opts.bookFoldPrintingSheets));
|
|
2499
|
-
p.push(numVal("w:drawingGridHorizontalSpacing", opts.drawingGridHorizontalSpacing));
|
|
2500
|
-
p.push(numVal("w:drawingGridVerticalSpacing", opts.drawingGridVerticalSpacing));
|
|
2501
|
-
p.push(numVal("w:displayHorizontalDrawingGridEvery", opts.displayHorizontalDrawingGridEvery));
|
|
2502
|
-
p.push(numVal("w:displayVerticalDrawingGridEvery", opts.displayVerticalDrawingGridEvery));
|
|
2503
|
-
p.push(onOff("w:doNotUseMarginsForDrawingGridOrigin", opts.doNotUseMarginsForDrawingGridOrigin));
|
|
2504
|
-
p.push(numVal("w:drawingGridHorizontalOrigin", opts.drawingGridHorizontalOrigin));
|
|
2505
|
-
p.push(numVal("w:drawingGridVerticalOrigin", opts.drawingGridVerticalOrigin));
|
|
2506
|
-
p.push(onOff("w:doNotShadeFormData", opts.doNotShadeFormData));
|
|
2507
|
-
p.push(onOff("w:noPunctuationKerning", opts.noPunctuationKerning));
|
|
2508
|
-
if (opts.characterSpacingControl !== void 0) p.push(strVal("w:characterSpacingControl", opts.characterSpacingControl));
|
|
2509
|
-
p.push(onOff("w:printTwoOnOne", opts.printTwoOnOne));
|
|
2510
|
-
p.push(onOff("w:strictFirstAndLastChars", opts.strictFirstAndLastChars));
|
|
2511
|
-
if (opts.noLineBreaksAfter !== void 0) {
|
|
2512
|
-
const attrs = {};
|
|
2513
|
-
if (opts.noLineBreaksAfter.lang !== void 0) attrs["w:lang"] = opts.noLineBreaksAfter.lang;
|
|
2514
|
-
if (opts.noLineBreaksAfter.val !== void 0) attrs["w:val"] = opts.noLineBreaksAfter.val;
|
|
2515
|
-
p.push(attrEl("w:noLineBreaksAfter", attrs));
|
|
2516
|
-
}
|
|
2517
|
-
if (opts.noLineBreaksBefore !== void 0) {
|
|
2518
|
-
const attrs = {};
|
|
2519
|
-
if (opts.noLineBreaksBefore.lang !== void 0) attrs["w:lang"] = opts.noLineBreaksBefore.lang;
|
|
2520
|
-
if (opts.noLineBreaksBefore.val !== void 0) attrs["w:val"] = opts.noLineBreaksBefore.val;
|
|
2521
|
-
p.push(attrEl("w:noLineBreaksBefore", attrs));
|
|
2522
|
-
}
|
|
2523
|
-
p.push(onOff("w:savePreviewPicture", opts.savePreviewPicture));
|
|
2524
|
-
p.push(onOff("w:doNotValidateAgainstSchema", opts.doNotValidateAgainstSchema));
|
|
2525
|
-
p.push(onOff("w:saveInvalidXml", opts.saveInvalidXml));
|
|
2526
|
-
p.push(onOff("w:ignoreMixedContent", opts.ignoreMixedContent));
|
|
2527
|
-
p.push(onOff("w:alwaysShowPlaceholderText", opts.alwaysShowPlaceholderText));
|
|
2528
|
-
p.push(onOff("w:doNotDemarcateInvalidXml", opts.doNotDemarcateInvalidXml));
|
|
2529
|
-
p.push(onOff("w:saveXmlDataOnly", opts.saveXmlDataOnly));
|
|
2530
|
-
p.push(onOff("w:useXSLTWhenSaving", opts.useXSLTWhenSaving));
|
|
2531
|
-
if (opts.saveThroughXslt !== void 0) {
|
|
2532
|
-
const attrs = {};
|
|
2533
|
-
if (opts.saveThroughXslt.id !== void 0) attrs["r:id"] = opts.saveThroughXslt.id;
|
|
2534
|
-
if (opts.saveThroughXslt.val !== void 0) attrs["w:val"] = opts.saveThroughXslt.val;
|
|
2535
|
-
if (opts.saveThroughXslt.solutionID !== void 0) attrs["w:solutionID"] = opts.saveThroughXslt.solutionID;
|
|
2536
|
-
p.push(attrEl("w:saveThroughXslt", attrs));
|
|
2537
|
-
}
|
|
2538
|
-
p.push(onOff("w:showXMLTags", opts.showXMLTags));
|
|
2539
|
-
p.push(onOff("w:alwaysMergeEmptyNamespace", opts.alwaysMergeEmptyNamespace));
|
|
2540
|
-
p.push(onOff("w:updateFields", opts.updateFields));
|
|
2541
|
-
if (opts.hdrShapeDefaults !== void 0) p.push(`<w:hdrShapeDefaults>${opts.hdrShapeDefaults}</w:hdrShapeDefaults>`);
|
|
2542
|
-
if (opts.footnotePr !== void 0) p.push(stringifyFootnotePr(opts.footnotePr));
|
|
2543
|
-
if (opts.endnotePr !== void 0) p.push(stringifyEndnotePr(opts.endnotePr));
|
|
2544
|
-
const compatXml = stringifyCompatibility({
|
|
2545
|
-
...opts.compatibility,
|
|
2546
|
-
version: opts.compatibility?.version ?? opts.compatibilityModeVersion ?? 15
|
|
2547
|
-
});
|
|
2548
|
-
if (compatXml) p.push(compatXml);
|
|
2549
|
-
if (opts.docVars?.length) {
|
|
2550
|
-
const vars = opts.docVars.map((v) => attrEl("w:docVar", {
|
|
2551
|
-
"w:name": v.name,
|
|
2552
|
-
"w:val": v.val
|
|
2553
|
-
})).join("");
|
|
2554
|
-
p.push(`<w:docVars>${vars}</w:docVars>`);
|
|
2555
|
-
}
|
|
2556
|
-
if (opts.rsids !== void 0) p.push(stringifyRsids(opts.rsids));
|
|
2557
|
-
if (opts.mathPr !== void 0) p.push(stringifyMathPr(opts.mathPr));
|
|
2558
|
-
if (opts.attachedSchema !== void 0) for (const schema of opts.attachedSchema) p.push(strVal("w:attachedSchema", schema));
|
|
2559
|
-
if (opts.themeFontLang !== void 0) {
|
|
2560
|
-
const a = {};
|
|
2561
|
-
if (opts.themeFontLang.val !== void 0) a["w:val"] = opts.themeFontLang.val;
|
|
2562
|
-
if (opts.themeFontLang.eastAsia !== void 0) a["w:eastAsia"] = opts.themeFontLang.eastAsia;
|
|
2563
|
-
if (opts.themeFontLang.bidi !== void 0) a["w:bidi"] = opts.themeFontLang.bidi;
|
|
2564
|
-
p.push(attrEl("w:themeFontLang", a));
|
|
2565
|
-
}
|
|
2566
|
-
if (opts.colorSchemeMapping !== void 0) p.push(stringifyColorSchemeMapping(opts.colorSchemeMapping));
|
|
2567
|
-
p.push(onOff("w:doNotIncludeSubdocsInStats", opts.doNotIncludeSubdocsInStats));
|
|
2568
|
-
p.push(onOff("w:doNotAutoCompressPictures", opts.doNotAutoCompressPictures));
|
|
2569
|
-
if (opts.forceUpgrade !== void 0) p.push("<w:forceUpgrade/>");
|
|
2570
|
-
if (opts.captions !== void 0) p.push(stringifyCaptions(opts.captions));
|
|
2571
|
-
if (opts.readModeInkLockDown !== void 0) p.push(stringifyReadModeInkLockDown(opts.readModeInkLockDown));
|
|
2572
|
-
if (opts.smartTagType !== void 0) for (const st of opts.smartTagType) {
|
|
2573
|
-
const attrs = {};
|
|
2574
|
-
if (st.namespace !== void 0) attrs["w:namespace"] = st.namespace;
|
|
2575
|
-
if (st.namespaceuri !== void 0) attrs["w:namespaceuri"] = st.namespaceuri;
|
|
2576
|
-
if (st.name !== void 0) attrs["w:name"] = st.name;
|
|
2577
|
-
if (st.url !== void 0) attrs["w:url"] = st.url;
|
|
2578
|
-
p.push(attrEl("w:smartTagType", attrs));
|
|
2579
|
-
}
|
|
2580
|
-
if (opts.shapeDefaults !== void 0) p.push(`<w:shapeDefaults>${opts.shapeDefaults}</w:shapeDefaults>`);
|
|
2581
|
-
p.push(onOff("w:doNotEmbedSmartTags", opts.doNotEmbedSmartTags));
|
|
2582
|
-
p.push(strVal("w:decimalSymbol", opts.decimalSymbol));
|
|
2583
|
-
p.push(strVal("w:listSeparator", opts.listSeparator));
|
|
2584
|
-
if (opts.w14DocId !== void 0) p.push(strVal("w14:docId", opts.w14DocId));
|
|
2585
|
-
if (opts.w15ChartTrackingRefBased) p.push(`<w15:chartTrackingRefBased/>`);
|
|
2586
|
-
if (opts.w15DocId !== void 0) p.push(strVal("w15:docId", opts.w15DocId));
|
|
2587
|
-
return `<w:settings ${SETTINGS_NS}>${p.join("")}</w:settings>`;
|
|
2588
|
-
},
|
|
2589
|
-
parse(el, _ctx) {
|
|
2590
|
-
const opts = {};
|
|
2591
|
-
const wpEl = findChild(el, "w:writeProtection");
|
|
2592
|
-
if (wpEl) {
|
|
2593
|
-
const wp = readPasswordAttrs(wpEl);
|
|
2594
|
-
const recommended = attr(wpEl, "w:recommended");
|
|
2595
|
-
if (recommended !== void 0) wp.recommended = recommended === "1" || recommended === "true";
|
|
2596
|
-
if (Object.keys(wp).length > 0) opts.writeProtection = wp;
|
|
2597
|
-
}
|
|
2598
|
-
const viewVal = readStr(findChild(el, "w:view"), "w:val");
|
|
2599
|
-
if (viewVal) opts.view = viewVal;
|
|
2600
|
-
const zoomEl = findChild(el, "w:zoom");
|
|
2601
|
-
if (zoomEl) {
|
|
2602
|
-
const zoom = {};
|
|
2603
|
-
const percent = attr(zoomEl, "w:percent");
|
|
2604
|
-
if (percent) zoom.percent = parseInt(percent, 10);
|
|
2605
|
-
const zval = attr(zoomEl, "w:val");
|
|
2606
|
-
if (zval) zoom.val = zval;
|
|
2607
|
-
if (Object.keys(zoom).length > 0) opts.zoom = zoom;
|
|
2608
|
-
}
|
|
2609
|
-
for (const [key, tag] of [
|
|
2610
|
-
["removePersonalInformation", "w:removePersonalInformation"],
|
|
2611
|
-
["removeDateAndTime", "w:removeDateAndTime"],
|
|
2612
|
-
["doNotDisplayPageBoundaries", "w:doNotDisplayPageBoundaries"],
|
|
2613
|
-
["displayBackgroundShape", "w:displayBackgroundShape"],
|
|
2614
|
-
["printPostScriptOverText", "w:printPostScriptOverText"],
|
|
2615
|
-
["printFractionalCharacterWidth", "w:printFractionalCharacterWidth"],
|
|
2616
|
-
["printFormsData", "w:printFormsData"],
|
|
2617
|
-
["embedTrueTypeFonts", "w:embedTrueTypeFonts"],
|
|
2618
|
-
["embedSystemFonts", "w:embedSystemFonts"],
|
|
2619
|
-
["saveSubsetFonts", "w:saveSubsetFonts"],
|
|
2620
|
-
["saveFormsData", "w:saveFormsData"],
|
|
2621
|
-
["mirrorMargins", "w:mirrorMargins"],
|
|
2622
|
-
["alignBordersAndEdges", "w:alignBordersAndEdges"],
|
|
2623
|
-
["bordersDoNotSurroundHeader", "w:bordersDoNotSurroundHeader"],
|
|
2624
|
-
["bordersDoNotSurroundFooter", "w:bordersDoNotSurroundFooter"],
|
|
2625
|
-
["gutterAtTop", "w:gutterAtTop"],
|
|
2626
|
-
["hideSpellingErrors", "w:hideSpellingErrors"],
|
|
2627
|
-
["hideGrammaticalErrors", "w:hideGrammaticalErrors"],
|
|
2628
|
-
["formsDesign", "w:formsDesign"],
|
|
2629
|
-
["linkStyles", "w:linkStyles"],
|
|
2630
|
-
["trackRevisions", "w:trackRevisions"],
|
|
2631
|
-
["doNotTrackMoves", "w:doNotTrackMoves"],
|
|
2632
|
-
["doNotTrackFormatting", "w:doNotTrackFormatting"],
|
|
2633
|
-
["autoFormatOverride", "w:autoFormatOverride"],
|
|
2634
|
-
["styleLockTheme", "w:styleLockTheme"],
|
|
2635
|
-
["styleLockQFSet", "w:styleLockQFSet"],
|
|
2636
|
-
["showEnvelope", "w:showEnvelope"],
|
|
2637
|
-
["evenAndOddHeaders", "w:evenAndOddHeaders"],
|
|
2638
|
-
["bookFoldRevPrinting", "w:bookFoldRevPrinting"],
|
|
2639
|
-
["bookFoldPrinting", "w:bookFoldPrinting"],
|
|
2640
|
-
["doNotUseMarginsForDrawingGridOrigin", "w:doNotUseMarginsForDrawingGridOrigin"],
|
|
2641
|
-
["doNotShadeFormData", "w:doNotShadeFormData"],
|
|
2642
|
-
["noPunctuationKerning", "w:noPunctuationKerning"],
|
|
2643
|
-
["printTwoOnOne", "w:printTwoOnOne"],
|
|
2644
|
-
["strictFirstAndLastChars", "w:strictFirstAndLastChars"],
|
|
2645
|
-
["savePreviewPicture", "w:savePreviewPicture"],
|
|
2646
|
-
["doNotValidateAgainstSchema", "w:doNotValidateAgainstSchema"],
|
|
2647
|
-
["saveInvalidXml", "w:saveInvalidXml"],
|
|
2648
|
-
["ignoreMixedContent", "w:ignoreMixedContent"],
|
|
2649
|
-
["alwaysShowPlaceholderText", "w:alwaysShowPlaceholderText"],
|
|
2650
|
-
["doNotDemarcateInvalidXml", "w:doNotDemarcateInvalidXml"],
|
|
2651
|
-
["saveXmlDataOnly", "w:saveXmlDataOnly"],
|
|
2652
|
-
["useXSLTWhenSaving", "w:useXSLTWhenSaving"],
|
|
2653
|
-
["showXMLTags", "w:showXMLTags"],
|
|
2654
|
-
["alwaysMergeEmptyNamespace", "w:alwaysMergeEmptyNamespace"],
|
|
2655
|
-
["updateFields", "w:updateFields"],
|
|
2656
|
-
["doNotIncludeSubdocsInStats", "w:doNotIncludeSubdocsInStats"],
|
|
2657
|
-
["doNotAutoCompressPictures", "w:doNotAutoCompressPictures"],
|
|
2658
|
-
["doNotEmbedSmartTags", "w:doNotEmbedSmartTags"]
|
|
2659
|
-
]) {
|
|
2660
|
-
const v = readOnOff(findChild(el, tag));
|
|
2661
|
-
if (v !== void 0) opts[key] = v;
|
|
2662
|
-
}
|
|
2663
|
-
const awsList = [];
|
|
2664
|
-
for (const child of el.elements ?? []) {
|
|
2665
|
-
if (child.name !== "w:activeWritingStyle") continue;
|
|
2666
|
-
const entry = {};
|
|
2667
|
-
const lang = attr(child, "w:lang");
|
|
2668
|
-
if (lang) entry.lang = lang;
|
|
2669
|
-
const vendorID = attr(child, "w:vendorID");
|
|
2670
|
-
if (vendorID) entry.vendorID = vendorID;
|
|
2671
|
-
const dllVersion = attr(child, "w:dllVersion");
|
|
2672
|
-
if (dllVersion) entry.dllVersion = dllVersion;
|
|
2673
|
-
const nlCheck = attr(child, "w:nlCheck");
|
|
2674
|
-
if (nlCheck !== void 0) entry.nlCheck = nlCheck !== "0" && nlCheck !== "false";
|
|
2675
|
-
const checkStyle = attr(child, "w:checkStyle");
|
|
2676
|
-
if (checkStyle !== void 0) entry.checkStyle = checkStyle !== "0" && checkStyle !== "false";
|
|
2677
|
-
const appCheck = attr(child, "w:appCheck");
|
|
2678
|
-
if (appCheck) entry.appCheck = appCheck;
|
|
2679
|
-
const appName = attr(child, "w:appName");
|
|
2680
|
-
if (appName) entry.appName = appName;
|
|
2681
|
-
if (Object.keys(entry).length > 0) awsList.push(entry);
|
|
2682
|
-
}
|
|
2683
|
-
if (awsList.length > 0) opts.activeWritingStyle = awsList;
|
|
2684
|
-
const proofEl = findChild(el, "w:proofState");
|
|
2685
|
-
if (proofEl) {
|
|
2686
|
-
const proof = {};
|
|
2687
|
-
const spelling = attr(proofEl, "w:spelling");
|
|
2688
|
-
if (spelling) proof.spelling = spelling;
|
|
2689
|
-
const grammar = attr(proofEl, "w:grammar");
|
|
2690
|
-
if (grammar) proof.grammar = grammar;
|
|
2691
|
-
if (Object.keys(proof).length > 0) opts.proofState = proof;
|
|
2692
|
-
}
|
|
2693
|
-
const attachedTplEl = findChild(el, "w:attachedTemplate");
|
|
2694
|
-
if (attachedTplEl) {
|
|
2695
|
-
const rid = attr(attachedTplEl, "r:id");
|
|
2696
|
-
if (rid) opts.attachedTemplate = rid;
|
|
2697
|
-
}
|
|
2698
|
-
const spffEl = findChild(el, "w:stylePaneFormatFilter");
|
|
2699
|
-
if (spffEl) {
|
|
2700
|
-
const filter = {};
|
|
2701
|
-
for (const [prop, xmlKey] of [
|
|
2702
|
-
["allStyles", "w:allStyles"],
|
|
2703
|
-
["customStyles", "w:customStyles"],
|
|
2704
|
-
["stylesInUse", "w:stylesInUse"],
|
|
2705
|
-
["headingStyles", "w:headingStyles"],
|
|
2706
|
-
["numberingStyles", "w:numberingStyles"],
|
|
2707
|
-
["tableStyles", "w:tableStyles"],
|
|
2708
|
-
["directFormattingOnRuns", "w:directFormattingOnRuns"],
|
|
2709
|
-
["directFormattingOnParagraphs", "w:directFormattingOnParagraphs"],
|
|
2710
|
-
["directFormattingOnNumbering", "w:directFormattingOnNumbering"],
|
|
2711
|
-
["directFormattingOnTables", "w:directFormattingOnTables"],
|
|
2712
|
-
["clearFormatting", "w:clearFormatting"],
|
|
2713
|
-
["top3HeadingStyles", "w:top3HeadingStyles"],
|
|
2714
|
-
["visibleStyles", "w:visibleStyles"],
|
|
2715
|
-
["alternateStyleNames", "w:alternateStyleNames"],
|
|
2716
|
-
["latentStyles", "w:latentStyles"]
|
|
2717
|
-
]) {
|
|
2718
|
-
const v = attr(spffEl, xmlKey);
|
|
2719
|
-
if (v !== void 0) filter[prop] = v !== "0" && v !== "false" && v !== "off";
|
|
2720
|
-
}
|
|
2721
|
-
if (Object.keys(filter).length > 0) opts.stylePaneFormatFilter = filter;
|
|
2722
|
-
}
|
|
2723
|
-
const stylePaneSortMethod = readStr(findChild(el, "w:stylePaneSortMethod"), "w:val");
|
|
2724
|
-
if (stylePaneSortMethod) opts.stylePaneSortMethod = stylePaneSortMethod;
|
|
2725
|
-
const documentType = readStr(findChild(el, "w:documentType"), "w:val");
|
|
2726
|
-
if (documentType) opts.documentType = documentType;
|
|
2727
|
-
const clickAndTypeStyle = readStr(findChild(el, "w:clickAndTypeStyle"), "w:val");
|
|
2728
|
-
if (clickAndTypeStyle) opts.clickAndTypeStyle = clickAndTypeStyle;
|
|
2729
|
-
const defaultTableStyle = readStr(findChild(el, "w:defaultTableStyle"), "w:val");
|
|
2730
|
-
if (defaultTableStyle) opts.defaultTableStyle = defaultTableStyle;
|
|
2731
|
-
const mailMergeEl = findChild(el, "w:mailMerge");
|
|
2732
|
-
if (mailMergeEl) {
|
|
2733
|
-
const mm = parseMailMerge(mailMergeEl);
|
|
2734
|
-
if (mm) opts.mailMerge = mm;
|
|
2735
|
-
}
|
|
2736
|
-
const revViewEl = findChild(el, "w:revisionView");
|
|
2737
|
-
if (revViewEl) {
|
|
2738
|
-
const rv = {};
|
|
2739
|
-
for (const [k, a] of [
|
|
2740
|
-
["markup", "w:markup"],
|
|
2741
|
-
["comments", "w:comments"],
|
|
2742
|
-
["insDel", "w:insDel"],
|
|
2743
|
-
["formatting", "w:formatting"],
|
|
2744
|
-
["inkAnnotations", "w:inkAnnotations"]
|
|
2745
|
-
]) {
|
|
2746
|
-
const v = attr(revViewEl, a);
|
|
2747
|
-
if (v !== void 0) rv[k] = v !== "false" && v !== "0";
|
|
2748
|
-
}
|
|
2749
|
-
if (Object.keys(rv).length > 0) opts.revisionView = rv;
|
|
2750
|
-
}
|
|
2751
|
-
const docProtEl = findChild(el, "w:documentProtection");
|
|
2752
|
-
if (docProtEl) {
|
|
2753
|
-
const prot = {};
|
|
2754
|
-
const edit = attr(docProtEl, "w:edit");
|
|
2755
|
-
if (edit && DOC_PROTECT_EDITS.includes(edit)) prot.edit = edit;
|
|
2756
|
-
if (attr(docProtEl, "w:enforcement") !== void 0) {
|
|
2757
|
-
Object.assign(prot, readPasswordAttrs(docProtEl));
|
|
2758
|
-
const formatting = attr(docProtEl, "w:formatting");
|
|
2759
|
-
if (formatting !== void 0) prot.formatting = formatting === "1" || formatting === "true";
|
|
2760
|
-
}
|
|
2761
|
-
if (Object.keys(prot).length > 0) opts.documentProtection = prot;
|
|
2762
|
-
}
|
|
2763
|
-
const defaultTabStop = readNum(findChild(el, "w:defaultTabStop"), "w:val");
|
|
2764
|
-
if (defaultTabStop !== void 0) opts.defaultTabStop = defaultTabStop;
|
|
2765
|
-
if (findChild(el, "w:autoHyphenation") || findChild(el, "w:doNotHyphenateCaps") || findChild(el, "w:consecutiveHyphenLimit") || findChild(el, "w:hyphenationZone")) {
|
|
2766
|
-
const hyphenation = {};
|
|
2767
|
-
const autoHyph = readOnOff(findChild(el, "w:autoHyphenation"));
|
|
2768
|
-
if (autoHyph !== void 0) hyphenation.autoHyphenation = autoHyph;
|
|
2769
|
-
const noHyphCaps = readOnOff(findChild(el, "w:doNotHyphenateCaps"));
|
|
2770
|
-
if (noHyphCaps !== void 0) hyphenation.doNotHyphenateCaps = noHyphCaps;
|
|
2771
|
-
const consLimit = readNum(findChild(el, "w:consecutiveHyphenLimit"), "w:val");
|
|
2772
|
-
if (consLimit !== void 0) hyphenation.consecutiveHyphenLimit = consLimit;
|
|
2773
|
-
const zone = readNum(findChild(el, "w:hyphenationZone"), "w:val");
|
|
2774
|
-
if (zone !== void 0) hyphenation.hyphenationZone = zone;
|
|
2775
|
-
if (Object.keys(hyphenation).length > 0) opts.hyphenation = hyphenation;
|
|
2776
|
-
}
|
|
2777
|
-
const summaryLength = readNum(findChild(el, "w:summaryLength"), "w:val");
|
|
2778
|
-
if (summaryLength !== void 0) opts.summaryLength = summaryLength;
|
|
2779
|
-
const bookFoldSheets = readNum(findChild(el, "w:bookFoldPrintingSheets"), "w:val");
|
|
2780
|
-
if (bookFoldSheets !== void 0) opts.bookFoldPrintingSheets = bookFoldSheets;
|
|
2781
|
-
for (const [key, tag] of [
|
|
2782
|
-
["drawingGridHorizontalSpacing", "w:drawingGridHorizontalSpacing"],
|
|
2783
|
-
["drawingGridVerticalSpacing", "w:drawingGridVerticalSpacing"],
|
|
2784
|
-
["displayHorizontalDrawingGridEvery", "w:displayHorizontalDrawingGridEvery"],
|
|
2785
|
-
["displayVerticalDrawingGridEvery", "w:displayVerticalDrawingGridEvery"],
|
|
2786
|
-
["drawingGridHorizontalOrigin", "w:drawingGridHorizontalOrigin"],
|
|
2787
|
-
["drawingGridVerticalOrigin", "w:drawingGridVerticalOrigin"]
|
|
2788
|
-
]) {
|
|
2789
|
-
const v = readNum(findChild(el, tag), "w:val");
|
|
2790
|
-
if (v !== void 0) opts[key] = v;
|
|
2791
|
-
}
|
|
2792
|
-
const characterSpacingControl = readStr(findChild(el, "w:characterSpacingControl"), "w:val");
|
|
2793
|
-
if (characterSpacingControl) opts.characterSpacingControl = characterSpacingControl;
|
|
2794
|
-
for (const [key, tag] of [["noLineBreaksAfter", "w:noLineBreaksAfter"], ["noLineBreaksBefore", "w:noLineBreaksBefore"]]) {
|
|
2795
|
-
const lbEl = findChild(el, tag);
|
|
2796
|
-
if (!lbEl) continue;
|
|
2797
|
-
const entry = {};
|
|
2798
|
-
const lang = attr(lbEl, "w:lang");
|
|
2799
|
-
if (lang) entry.lang = lang;
|
|
2800
|
-
const val = attr(lbEl, "w:val");
|
|
2801
|
-
if (val) entry.val = val;
|
|
2802
|
-
if (Object.keys(entry).length > 0) opts[key] = entry;
|
|
2803
|
-
}
|
|
2804
|
-
const stxEl = findChild(el, "w:saveThroughXslt");
|
|
2805
|
-
if (stxEl) {
|
|
2806
|
-
const stx = {};
|
|
2807
|
-
const id = attr(stxEl, "r:id");
|
|
2808
|
-
if (id) stx.id = id;
|
|
2809
|
-
const val = attr(stxEl, "w:val");
|
|
2810
|
-
if (val) stx.val = val;
|
|
2811
|
-
const solutionID = attr(stxEl, "w:solutionID");
|
|
2812
|
-
if (solutionID) stx.solutionID = solutionID;
|
|
2813
|
-
if (Object.keys(stx).length > 0) opts.saveThroughXslt = stx;
|
|
2814
|
-
}
|
|
2815
|
-
const hdrSdEl = findChild(el, "w:hdrShapeDefaults");
|
|
2816
|
-
if (hdrSdEl) opts.hdrShapeDefaults = stringify(hdrSdEl);
|
|
2817
|
-
const sdEl = findChild(el, "w:shapeDefaults");
|
|
2818
|
-
if (sdEl) opts.shapeDefaults = stringify(sdEl);
|
|
2819
|
-
const fnPrEl = findChild(el, "w:footnotePr");
|
|
2820
|
-
if (fnPrEl) {
|
|
2821
|
-
const fn = parseFtnEdnPr(fnPrEl);
|
|
2822
|
-
if (fn) opts.footnotePr = fn;
|
|
2823
|
-
}
|
|
2824
|
-
const enPrEl = findChild(el, "w:endnotePr");
|
|
2825
|
-
if (enPrEl) {
|
|
2826
|
-
const en = parseFtnEdnPr(enPrEl);
|
|
2827
|
-
if (en) opts.endnotePr = en;
|
|
2828
|
-
}
|
|
2829
|
-
const compatEl = findChild(el, "w:compat");
|
|
2830
|
-
if (compatEl) {
|
|
2831
|
-
const compat = parseCompatibility(compatEl);
|
|
2832
|
-
if (compat) opts.compatibility = compat;
|
|
2833
|
-
}
|
|
2834
|
-
const docVarsEl = findChild(el, "w:docVars");
|
|
2835
|
-
if (docVarsEl) {
|
|
2836
|
-
const vars = [];
|
|
2837
|
-
for (const child of docVarsEl.elements ?? []) {
|
|
2838
|
-
if (child.name !== "w:docVar") continue;
|
|
2839
|
-
const name = attr(child, "w:name");
|
|
2840
|
-
const val = attr(child, "w:val");
|
|
2841
|
-
if (name !== void 0 && val !== void 0) vars.push({
|
|
2842
|
-
name,
|
|
2843
|
-
val
|
|
2844
|
-
});
|
|
2845
|
-
}
|
|
2846
|
-
if (vars.length > 0) opts.docVars = vars;
|
|
2847
|
-
}
|
|
2848
|
-
const rsidsEl = findChild(el, "w:rsids");
|
|
2849
|
-
if (rsidsEl) {
|
|
2850
|
-
const rsids = {};
|
|
2851
|
-
const root = readStr(findChild(rsidsEl, "w:rsidRoot"), "w:val");
|
|
2852
|
-
if (root) rsids.rsidRoot = root;
|
|
2853
|
-
const list = [];
|
|
2854
|
-
for (const child of rsidsEl.elements ?? []) {
|
|
2855
|
-
if (child.name !== "w:rsid") continue;
|
|
2856
|
-
const val = attr(child, "w:val");
|
|
2857
|
-
if (val) list.push(val);
|
|
2858
|
-
}
|
|
2859
|
-
if (list.length > 0) rsids.rsids = list;
|
|
2860
|
-
if (Object.keys(rsids).length > 0) opts.rsids = rsids;
|
|
2861
|
-
}
|
|
2862
|
-
const mathPrEl = findChild(el, "m:mathPr");
|
|
2863
|
-
if (mathPrEl) {
|
|
2864
|
-
const mp = parseMathPr(mathPrEl);
|
|
2865
|
-
if (mp) opts.mathPr = mp;
|
|
2866
|
-
}
|
|
2867
|
-
const attachedSchemas = [];
|
|
2868
|
-
for (const child of el.elements ?? []) {
|
|
2869
|
-
if (child.name !== "w:attachedSchema") continue;
|
|
2870
|
-
const val = attr(child, "w:val");
|
|
2871
|
-
if (val) attachedSchemas.push(val);
|
|
2872
|
-
}
|
|
2873
|
-
if (attachedSchemas.length > 0) opts.attachedSchema = attachedSchemas;
|
|
2874
|
-
const tflEl = findChild(el, "w:themeFontLang");
|
|
2875
|
-
if (tflEl) {
|
|
2876
|
-
const tfl = {};
|
|
2877
|
-
const val = attr(tflEl, "w:val");
|
|
2878
|
-
if (val) tfl.val = val;
|
|
2879
|
-
const eastAsia = attr(tflEl, "w:eastAsia");
|
|
2880
|
-
if (eastAsia) tfl.eastAsia = eastAsia;
|
|
2881
|
-
const bidi = attr(tflEl, "w:bidi");
|
|
2882
|
-
if (bidi) tfl.bidi = bidi;
|
|
2883
|
-
if (Object.keys(tfl).length > 0) opts.themeFontLang = tfl;
|
|
2884
|
-
}
|
|
2885
|
-
const csmEl = findChild(el, "w:clrSchemeMapping");
|
|
2886
|
-
if (csmEl) {
|
|
2887
|
-
const csm = {};
|
|
2888
|
-
for (const [key, xmlAttr] of [
|
|
2889
|
-
["bg1", "w:bg1"],
|
|
2890
|
-
["t1", "w:t1"],
|
|
2891
|
-
["bg2", "w:bg2"],
|
|
2892
|
-
["t2", "w:t2"],
|
|
2893
|
-
["accent1", "w:accent1"],
|
|
2894
|
-
["accent2", "w:accent2"],
|
|
2895
|
-
["accent3", "w:accent3"],
|
|
2896
|
-
["accent4", "w:accent4"],
|
|
2897
|
-
["accent5", "w:accent5"],
|
|
2898
|
-
["accent6", "w:accent6"],
|
|
2899
|
-
["hyperlink", "w:hyperlink"],
|
|
2900
|
-
["followedHyperlink", "w:followedHyperlink"]
|
|
2901
|
-
]) {
|
|
2902
|
-
const v = attr(csmEl, xmlAttr);
|
|
2903
|
-
if (v) csm[key] = v;
|
|
2904
|
-
}
|
|
2905
|
-
if (Object.keys(csm).length > 0) opts.colorSchemeMapping = csm;
|
|
2906
|
-
}
|
|
2907
|
-
if (findChild(el, "w:forceUpgrade")) opts.forceUpgrade = true;
|
|
2908
|
-
const captionsEl = findChild(el, "w:captions");
|
|
2909
|
-
if (captionsEl) {
|
|
2910
|
-
const captions = parseCaptions(captionsEl);
|
|
2911
|
-
if (captions) opts.captions = captions;
|
|
2912
|
-
}
|
|
2913
|
-
const rmilEl = findChild(el, "w:readModeInkLockDown");
|
|
2914
|
-
if (rmilEl) opts.readModeInkLockDown = {
|
|
2915
|
-
actualPg: attr(rmilEl, "w:actualPg") !== "0",
|
|
2916
|
-
w: parseInt(attr(rmilEl, "w:w") ?? "0", 10),
|
|
2917
|
-
h: parseInt(attr(rmilEl, "w:h") ?? "0", 10),
|
|
2918
|
-
fontSz: parseInt(attr(rmilEl, "w:fontSz") ?? "0", 10)
|
|
2919
|
-
};
|
|
2920
|
-
const smartTags = [];
|
|
2921
|
-
for (const child of el.elements ?? []) {
|
|
2922
|
-
if (child.name !== "w:smartTagType") continue;
|
|
2923
|
-
const entry = {};
|
|
2924
|
-
const ns = attr(child, "w:namespace");
|
|
2925
|
-
if (ns) entry.namespace = ns;
|
|
2926
|
-
const nsuri = attr(child, "w:namespaceuri");
|
|
2927
|
-
if (nsuri) entry.namespaceuri = nsuri;
|
|
2928
|
-
const name = attr(child, "w:name");
|
|
2929
|
-
if (name) entry.name = name;
|
|
2930
|
-
const url = attr(child, "w:url");
|
|
2931
|
-
if (url) entry.url = url;
|
|
2932
|
-
if (Object.keys(entry).length > 0) smartTags.push(entry);
|
|
2933
|
-
}
|
|
2934
|
-
if (smartTags.length > 0) opts.smartTagType = smartTags;
|
|
2935
|
-
const decimalSymbol = readStr(findChild(el, "w:decimalSymbol"), "w:val");
|
|
2936
|
-
if (decimalSymbol) opts.decimalSymbol = decimalSymbol;
|
|
2937
|
-
const listSeparator = readStr(findChild(el, "w:listSeparator"), "w:val");
|
|
2938
|
-
if (listSeparator) opts.listSeparator = listSeparator;
|
|
2939
|
-
const w14DocId = readStr(findChild(el, "w14:docId"), "w14:val");
|
|
2940
|
-
if (w14DocId) opts.w14DocId = w14DocId;
|
|
2941
|
-
if (findChild(el, "w15:chartTrackingRefBased")) opts.w15ChartTrackingRefBased = true;
|
|
2942
|
-
const w15DocId = readStr(findChild(el, "w15:docId"), "w15:val");
|
|
2943
|
-
if (w15DocId) opts.w15DocId = w15DocId;
|
|
2944
|
-
return opts;
|
|
2945
|
-
}
|
|
2946
|
-
};
|
|
2947
|
-
//#endregion
|
|
2948
|
-
//#region src/parts/footnotes/descriptor.ts
|
|
2949
|
-
const NS$2 = "xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" xmlns:wne=\"http://schemas.openxmlformats.org/office/word/2006/wordml\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\"";
|
|
2950
|
-
/** XML for the footnoteRef run — auto-injected at start of first paragraph. */
|
|
2951
|
-
const FOOTNOTE_REF_RUN = "<w:r><w:rPr><w:rStyle w:val=\"FootnoteReference\"/></w:rPr><w:footnoteRef/></w:r>";
|
|
2952
|
-
/** Default separator footnote (id=-1) for freshly generated documents. */
|
|
2953
|
-
const SEPARATOR_FOOTNOTE = "<w:footnote w:type=\"separator\" w:id=\"-1\"><w:p><w:pPr><w:spacing w:after=\"0\" w:line=\"240\" w:lineRule=\"auto\"/></w:pPr><w:r><w:separator/></w:r></w:p></w:footnote>";
|
|
2954
|
-
/** Default continuation separator footnote (id=0) for freshly generated documents. */
|
|
2955
|
-
const CONTINUATION_SEPARATOR_FOOTNOTE = "<w:footnote w:type=\"continuationSeparator\" w:id=\"0\"><w:p><w:pPr><w:spacing w:after=\"0\" w:line=\"240\" w:lineRule=\"auto\"/></w:pPr><w:r><w:continuationSeparator/></w:r></w:p></w:footnote>";
|
|
2956
|
-
/** Render a system footnote from round-tripped id + content, or the spec default. */
|
|
2957
|
-
function footnoteSystemNote(type, sep, fallback, ctx) {
|
|
2958
|
-
if (!sep) return fallback;
|
|
2959
|
-
const inner = sep.paragraphs.map((p) => stringifyParagraphInline(p, ctx)).join("");
|
|
2960
|
-
return `<w:footnote w:type="${type}" w:id="${sep.id}">${inner}</w:footnote>`;
|
|
2961
|
-
}
|
|
2962
|
-
const footnotesDesc = {
|
|
2963
|
-
kind: "custom",
|
|
2964
|
-
stringify(data, ctx) {
|
|
2965
|
-
const parts = [`<w:footnotes ${NS$2} mc:Ignorable="w14 w15 wp14">`];
|
|
2966
|
-
parts.push(footnoteSystemNote("separator", data.separator, SEPARATOR_FOOTNOTE, ctx));
|
|
2967
|
-
parts.push(footnoteSystemNote("continuationSeparator", data.continuationSeparator, CONTINUATION_SEPARATOR_FOOTNOTE, ctx));
|
|
2968
|
-
for (const [id, paragraphs] of data.notes) {
|
|
2969
|
-
parts.push(`<w:footnote w:id="${id}">`);
|
|
2970
|
-
for (const [i, para] of paragraphs.entries()) {
|
|
2971
|
-
const pXml = stringifyParagraphInline(para, ctx);
|
|
2972
|
-
if (i === 0) {
|
|
2973
|
-
const pPrEnd = pXml.indexOf("</w:pPr>");
|
|
2974
|
-
if (pPrEnd !== -1) {
|
|
2975
|
-
const at = pPrEnd + 8;
|
|
2976
|
-
parts.push(pXml.slice(0, at) + FOOTNOTE_REF_RUN + pXml.slice(at));
|
|
2977
|
-
} else {
|
|
2978
|
-
const openIdx = pXml.indexOf(">");
|
|
2979
|
-
if (openIdx !== -1) parts.push(pXml.slice(0, openIdx + 1) + FOOTNOTE_REF_RUN + pXml.slice(openIdx + 1));
|
|
2980
|
-
else parts.push(pXml);
|
|
2981
|
-
}
|
|
2982
|
-
} else parts.push(pXml);
|
|
2983
|
-
}
|
|
2984
|
-
parts.push("</w:footnote>");
|
|
2985
|
-
}
|
|
2986
|
-
parts.push("</w:footnotes>");
|
|
2987
|
-
return parts.join("");
|
|
2988
|
-
},
|
|
2989
|
-
parse(el, ctx) {
|
|
2990
|
-
const notes = /* @__PURE__ */ new Map();
|
|
2991
|
-
let separator;
|
|
2992
|
-
let continuationSeparator;
|
|
2993
|
-
for (const child of el.elements ?? []) {
|
|
2994
|
-
if (child.name !== "w:footnote") continue;
|
|
2995
|
-
const id = attrNum(child, "w:id");
|
|
2996
|
-
if (id === void 0) continue;
|
|
2997
|
-
const type = attr(child, "w:type");
|
|
2998
|
-
const paragraphs = [];
|
|
2999
|
-
for (const sub of child.elements ?? []) if (sub.name === "w:p") paragraphs.push(parseParagraph(sub, ctx));
|
|
3000
|
-
if (type === "separator") separator = {
|
|
3001
|
-
id,
|
|
3002
|
-
paragraphs
|
|
3003
|
-
};
|
|
3004
|
-
else if (type === "continuationSeparator") continuationSeparator = {
|
|
3005
|
-
id,
|
|
3006
|
-
paragraphs
|
|
3007
|
-
};
|
|
3008
|
-
else notes.set(id, paragraphs);
|
|
3009
|
-
}
|
|
3010
|
-
return {
|
|
3011
|
-
notes,
|
|
3012
|
-
separator,
|
|
3013
|
-
continuationSeparator
|
|
3014
|
-
};
|
|
3015
|
-
}
|
|
3016
|
-
};
|
|
3017
|
-
//#endregion
|
|
3018
|
-
//#region src/parts/endnotes/descriptor.ts
|
|
3019
|
-
const NS$1 = "xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" xmlns:wne=\"http://schemas.openxmlformats.org/office/word/2006/wordml\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\"";
|
|
3020
|
-
/** XML for the endnoteRef run — auto-injected at start of first paragraph. */
|
|
3021
|
-
const ENDNOTE_REF_RUN = "<w:r><w:rPr><w:rStyle w:val=\"EndnoteReference\"/></w:rPr><w:endnoteRef/></w:r>";
|
|
3022
|
-
/** Default separator endnote (id=-1) for freshly generated documents. */
|
|
3023
|
-
const SEPARATOR_ENDNOTE = "<w:endnote w:type=\"separator\" w:id=\"-1\"><w:p><w:pPr><w:spacing w:after=\"0\" w:line=\"240\" w:lineRule=\"auto\"/></w:pPr><w:r><w:separator/></w:r></w:p></w:endnote>";
|
|
3024
|
-
/** Default continuation separator endnote (id=0) for freshly generated documents. */
|
|
3025
|
-
const CONTINUATION_SEPARATOR_ENDNOTE = "<w:endnote w:type=\"continuationSeparator\" w:id=\"0\"><w:p><w:pPr><w:spacing w:after=\"0\" w:line=\"240\" w:lineRule=\"auto\"/></w:pPr><w:r><w:continuationSeparator/></w:r></w:p></w:endnote>";
|
|
3026
|
-
/** Render a system endnote from round-tripped id + content, or the spec default. */
|
|
3027
|
-
function endnoteSystemNote(type, sep, fallback, ctx) {
|
|
3028
|
-
if (!sep) return fallback;
|
|
3029
|
-
const inner = sep.paragraphs.map((p) => stringifyParagraphInline(p, ctx)).join("");
|
|
3030
|
-
return `<w:endnote w:type="${type}" w:id="${sep.id}">${inner}</w:endnote>`;
|
|
3031
|
-
}
|
|
3032
|
-
const endnotesDesc = {
|
|
3033
|
-
kind: "custom",
|
|
3034
|
-
stringify(data, ctx) {
|
|
3035
|
-
const parts = [`<w:endnotes ${NS$1} mc:Ignorable="w14 w15 wp14">`];
|
|
3036
|
-
parts.push(endnoteSystemNote("separator", data.separator, SEPARATOR_ENDNOTE, ctx));
|
|
3037
|
-
parts.push(endnoteSystemNote("continuationSeparator", data.continuationSeparator, CONTINUATION_SEPARATOR_ENDNOTE, ctx));
|
|
3038
|
-
for (const [id, paragraphs] of data.notes) {
|
|
3039
|
-
parts.push(`<w:endnote w:id="${id}">`);
|
|
3040
|
-
for (const [i, para] of paragraphs.entries()) {
|
|
3041
|
-
const pXml = stringifyParagraphInline(para, ctx);
|
|
3042
|
-
if (i === 0) {
|
|
3043
|
-
const openIdx = pXml.indexOf(">");
|
|
3044
|
-
if (openIdx !== -1) parts.push(pXml.slice(0, openIdx + 1) + ENDNOTE_REF_RUN + pXml.slice(openIdx + 1));
|
|
3045
|
-
else parts.push(pXml);
|
|
3046
|
-
} else parts.push(pXml);
|
|
3047
|
-
}
|
|
3048
|
-
parts.push("</w:endnote>");
|
|
3049
|
-
}
|
|
3050
|
-
parts.push("</w:endnotes>");
|
|
3051
|
-
return parts.join("");
|
|
3052
|
-
},
|
|
3053
|
-
parse(el, ctx) {
|
|
3054
|
-
const notes = /* @__PURE__ */ new Map();
|
|
3055
|
-
let separator;
|
|
3056
|
-
let continuationSeparator;
|
|
3057
|
-
for (const child of el.elements ?? []) {
|
|
3058
|
-
if (child.name !== "w:endnote") continue;
|
|
3059
|
-
const id = attrNum(child, "w:id");
|
|
3060
|
-
if (id === void 0) continue;
|
|
3061
|
-
const type = attr(child, "w:type");
|
|
3062
|
-
const paragraphs = [];
|
|
3063
|
-
for (const sub of child.elements ?? []) if (sub.name === "w:p") paragraphs.push(parseParagraph(sub, ctx));
|
|
3064
|
-
if (type === "separator") separator = {
|
|
3065
|
-
id,
|
|
3066
|
-
paragraphs
|
|
3067
|
-
};
|
|
3068
|
-
else if (type === "continuationSeparator") continuationSeparator = {
|
|
3069
|
-
id,
|
|
3070
|
-
paragraphs
|
|
3071
|
-
};
|
|
3072
|
-
else notes.set(id, paragraphs);
|
|
3073
|
-
}
|
|
3074
|
-
return {
|
|
3075
|
-
notes,
|
|
3076
|
-
separator,
|
|
3077
|
-
continuationSeparator
|
|
3078
|
-
};
|
|
3079
|
-
}
|
|
3080
|
-
};
|
|
3081
|
-
//#endregion
|
|
3082
|
-
//#region src/parts/alt-chunk/alt-chunk-collection.ts
|
|
3083
|
-
/**
|
|
3084
|
-
* Manages alternative format chunk parts in a document.
|
|
3085
|
-
*
|
|
3086
|
-
* Stores external content (HTML, RTF, plain text) that will be
|
|
3087
|
-
* serialized into separate parts in the DOCX package.
|
|
3088
|
-
*/
|
|
3089
|
-
var AltChunkCollection = class {
|
|
3090
|
-
map;
|
|
3091
|
-
constructor() {
|
|
3092
|
-
this.map = /* @__PURE__ */ new Map();
|
|
3093
|
-
}
|
|
3094
|
-
addAltChunk(key, data) {
|
|
3095
|
-
this.map.set(key, data);
|
|
3096
|
-
}
|
|
3097
|
-
get array() {
|
|
3098
|
-
return [...this.map.values()];
|
|
3099
|
-
}
|
|
3100
|
-
};
|
|
3101
|
-
//#endregion
|
|
3102
|
-
//#region src/parts/sub-doc/sub-doc-collection.ts
|
|
3103
|
-
/**
|
|
3104
|
-
* Manages sub-document parts in a document.
|
|
3105
|
-
*/
|
|
3106
|
-
var SubDocCollection = class {
|
|
3107
|
-
map;
|
|
3108
|
-
constructor() {
|
|
3109
|
-
this.map = /* @__PURE__ */ new Map();
|
|
3110
|
-
}
|
|
3111
|
-
addSubDoc(key, data) {
|
|
3112
|
-
this.map.set(key, data);
|
|
3113
|
-
}
|
|
3114
|
-
get array() {
|
|
3115
|
-
return [...this.map.values()];
|
|
3116
|
-
}
|
|
3117
|
-
};
|
|
3118
|
-
//#endregion
|
|
3119
|
-
//#region src/parts/fonts/descriptor.ts
|
|
3120
|
-
const NS = "xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" xmlns:w16=\"http://schemas.microsoft.com/office/word/2018/wordml\" xmlns:w16cex=\"http://schemas.microsoft.com/office/word/2018/wordml/cex\" xmlns:w16cid=\"http://schemas.microsoft.com/office/word/2016/wordml/cid\" xmlns:w16sdtdh=\"http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash\" xmlns:w16se=\"http://schemas.microsoft.com/office/word/2015/wordml/symex\"";
|
|
3121
|
-
/** Default font signature for regular embedded fonts. */
|
|
3122
|
-
const DEFAULT_SIG = {
|
|
3123
|
-
usb0: "E0002AFF",
|
|
3124
|
-
usb1: "C000247B",
|
|
3125
|
-
usb2: "00000009",
|
|
3126
|
-
usb3: "00000000",
|
|
3127
|
-
csb0: "000001FF",
|
|
3128
|
-
csb1: "00000000"
|
|
3129
|
-
};
|
|
3130
|
-
function fontXml(font) {
|
|
3131
|
-
const parts = [`<w:font w:name="${escapeXml(font.name)}">`];
|
|
3132
|
-
if (font.altName) parts.push(`<w:altName w:val="${escapeXml(font.altName)}"/>`);
|
|
3133
|
-
if (font.panose1) parts.push(`<w:panose1 w:val="${escapeXml(font.panose1)}"/>`);
|
|
3134
|
-
if (font.characterSet || font.characterSetName) {
|
|
3135
|
-
const valAttr = font.characterSet ? ` w:val="${escapeXml(font.characterSet)}"` : "";
|
|
3136
|
-
const csAttr = font.characterSetName ? ` w:characterSet="${escapeXml(font.characterSetName)}"` : "";
|
|
3137
|
-
parts.push(`<w:charset${valAttr}${csAttr}/>`);
|
|
3138
|
-
}
|
|
3139
|
-
const family = font.family ?? (font.embedRid ? "auto" : void 0);
|
|
3140
|
-
if (family) parts.push(`<w:family w:val="${escapeXml(family)}"/>`);
|
|
3141
|
-
const pitch = font.pitch ?? (font.embedRid ? "variable" : void 0);
|
|
3142
|
-
if (pitch) parts.push(`<w:pitch w:val="${escapeXml(pitch)}"/>`);
|
|
3143
|
-
const sig = font.sig ?? (font.embedRid ? DEFAULT_SIG : void 0);
|
|
3144
|
-
if (sig) parts.push(`<w:sig w:usb0="${sig.usb0}" w:usb1="${sig.usb1}" w:usb2="${sig.usb2}" w:usb3="${sig.usb3}" w:csb0="${sig.csb0}" w:csb1="${sig.csb1}"/>`);
|
|
3145
|
-
if (font.embedRid) {
|
|
3146
|
-
const embedAttrs = [`r:id="${font.embedRid}"`, `w:fontKey="{${font.fontKey}}"`];
|
|
3147
|
-
if (font.subsetted !== void 0) embedAttrs.push(`w:subsetted="${font.subsetted ? 1 : 0}"`);
|
|
3148
|
-
parts.push(`<w:embedRegular ${embedAttrs.join(" ")}/>`);
|
|
3149
|
-
}
|
|
3150
|
-
parts.push("</w:font>");
|
|
3151
|
-
return parts.join("");
|
|
3152
|
-
}
|
|
3153
|
-
const fontTableDesc = {
|
|
3154
|
-
kind: "custom",
|
|
3155
|
-
stringify(opts, _ctx) {
|
|
3156
|
-
const parts = [`<w:fonts ${NS} mc:Ignorable="w14 w15 w16se w16cid w16 w16cex w16sdtdh">`];
|
|
3157
|
-
for (const font of opts.fonts) parts.push(fontXml(font));
|
|
3158
|
-
parts.push("</w:fonts>");
|
|
3159
|
-
return parts.join("");
|
|
3160
|
-
},
|
|
3161
|
-
parse(el, _ctx) {
|
|
3162
|
-
const fonts = [];
|
|
3163
|
-
for (const child of el.elements ?? []) {
|
|
3164
|
-
if (child.name !== "w:font") continue;
|
|
3165
|
-
const font = { fontKey: "" };
|
|
3166
|
-
const name = child.attributes?.["w:name"];
|
|
3167
|
-
if (name) font.name = String(name);
|
|
3168
|
-
const altNameEl = findChild(child, "w:altName");
|
|
3169
|
-
if (altNameEl) {
|
|
3170
|
-
const val = attr(altNameEl, "w:val");
|
|
3171
|
-
if (val) font.altName = val;
|
|
3172
|
-
}
|
|
3173
|
-
const panose1El = findChild(child, "w:panose1");
|
|
3174
|
-
if (panose1El) {
|
|
3175
|
-
const val = attr(panose1El, "w:val");
|
|
3176
|
-
if (val) font.panose1 = val;
|
|
3177
|
-
}
|
|
3178
|
-
const charsetEl = findChild(child, "w:charset");
|
|
3179
|
-
if (charsetEl) {
|
|
3180
|
-
const val = attr(charsetEl, "w:val");
|
|
3181
|
-
if (val) font.characterSet = val;
|
|
3182
|
-
const csName = attr(charsetEl, "w:characterSet");
|
|
3183
|
-
if (csName) font.characterSetName = csName;
|
|
3184
|
-
}
|
|
3185
|
-
const familyEl = findChild(child, "w:family");
|
|
3186
|
-
if (familyEl) {
|
|
3187
|
-
const val = attr(familyEl, "w:val");
|
|
3188
|
-
if (val) font.family = val;
|
|
3189
|
-
}
|
|
3190
|
-
const pitchEl = findChild(child, "w:pitch");
|
|
3191
|
-
if (pitchEl) {
|
|
3192
|
-
const val = attr(pitchEl, "w:val");
|
|
3193
|
-
if (val) font.pitch = val;
|
|
3194
|
-
}
|
|
3195
|
-
const sigEl = findChild(child, "w:sig");
|
|
3196
|
-
if (sigEl) {
|
|
3197
|
-
const sig = {
|
|
3198
|
-
usb0: "",
|
|
3199
|
-
usb1: "",
|
|
3200
|
-
usb2: "",
|
|
3201
|
-
usb3: "",
|
|
3202
|
-
csb0: "",
|
|
3203
|
-
csb1: ""
|
|
3204
|
-
};
|
|
3205
|
-
for (const key of [
|
|
3206
|
-
"usb0",
|
|
3207
|
-
"usb1",
|
|
3208
|
-
"usb2",
|
|
3209
|
-
"usb3",
|
|
3210
|
-
"csb0",
|
|
3211
|
-
"csb1"
|
|
3212
|
-
]) {
|
|
3213
|
-
const val = attr(sigEl, `w:${key}`);
|
|
3214
|
-
if (val) sig[key] = val;
|
|
3215
|
-
}
|
|
3216
|
-
if (Object.values(sig).some(Boolean)) font.sig = sig;
|
|
3217
|
-
}
|
|
3218
|
-
const embedEl = findChild(child, "w:embedRegular");
|
|
3219
|
-
if (embedEl) {
|
|
3220
|
-
const rawKey = attr(embedEl, "w:fontKey");
|
|
3221
|
-
if (rawKey) font.fontKey = rawKey.replace(/^\{\{|\}\}$/g, "").replace(/^\{|\}$/g, "");
|
|
3222
|
-
const rid = attr(embedEl, "r:id");
|
|
3223
|
-
if (rid) font.embedRid = rid;
|
|
3224
|
-
const subsetted = attrBool(embedEl, "w:subsetted");
|
|
3225
|
-
if (subsetted !== void 0) font.subsetted = subsetted;
|
|
3226
|
-
}
|
|
3227
|
-
fonts.push(font);
|
|
3228
|
-
}
|
|
3229
|
-
return { fonts };
|
|
3230
|
-
}
|
|
3231
|
-
};
|
|
3232
|
-
//#endregion
|
|
3233
|
-
//#region src/parts/bibliography.ts
|
|
3234
|
-
const SOURCE_FIELDS = [
|
|
3235
|
-
["SourceType", "type"],
|
|
3236
|
-
["Title", "title"],
|
|
3237
|
-
["Author", "author"],
|
|
3238
|
-
["Year", "year"],
|
|
3239
|
-
["Month", "month"],
|
|
3240
|
-
["Day", "day"],
|
|
3241
|
-
["BookTitle", "bookTitle"],
|
|
3242
|
-
["JournalName", "journal"],
|
|
3243
|
-
["Volume", "volume"],
|
|
3244
|
-
["Issue", "issue"],
|
|
3245
|
-
["Pages", "pages"],
|
|
3246
|
-
["Publisher", "publisher"],
|
|
3247
|
-
["City", "city"],
|
|
3248
|
-
["URL", "url"],
|
|
3249
|
-
["Edition", "edition"],
|
|
3250
|
-
["Institution", "institution"]
|
|
3251
|
-
];
|
|
3252
|
-
const bibliographyDesc = {
|
|
3253
|
-
kind: "custom",
|
|
3254
|
-
stringify(opts, _ctx) {
|
|
3255
|
-
const attrParts = ["xmlns:b=\"http://schemas.openxmlformats.org/officeDocument/2006/bibliography\""];
|
|
3256
|
-
if (opts.styleName !== void 0) attrParts.push(`StyleName="${escapeXml(opts.styleName)}"`);
|
|
3257
|
-
const parts = [`<b:Sources ${attrParts.join(" ")}>`];
|
|
3258
|
-
for (const source of opts.sources) {
|
|
3259
|
-
const sourceParts = [];
|
|
3260
|
-
for (const [tagName, key] of SOURCE_FIELDS) {
|
|
3261
|
-
const value = source[key];
|
|
3262
|
-
if (value !== void 0) sourceParts.push(`<b:${tagName}>${escapeXml(value)}</b:${tagName}>`);
|
|
3263
|
-
}
|
|
3264
|
-
parts.push(`<b:Source>${sourceParts.join("")}</b:Source>`);
|
|
3265
|
-
}
|
|
3266
|
-
parts.push("</b:Sources>");
|
|
3267
|
-
return parts.join("");
|
|
3268
|
-
},
|
|
3269
|
-
parse(el, _ctx) {
|
|
3270
|
-
const opts = {};
|
|
3271
|
-
const styleName = el.attributes?.["StyleName"];
|
|
3272
|
-
if (styleName) opts.styleName = styleName;
|
|
3273
|
-
const sources = [];
|
|
3274
|
-
for (const child of el.elements ?? []) {
|
|
3275
|
-
if (child.name !== "b:Source") continue;
|
|
3276
|
-
const source = {};
|
|
3277
|
-
for (const [, key] of SOURCE_FIELDS) {
|
|
3278
|
-
const xmlChild = findChild(child, `b:${SOURCE_FIELDS.find((f) => f[1] === key)[0]}`);
|
|
3279
|
-
if (xmlChild) {
|
|
3280
|
-
const val = textOf(xmlChild);
|
|
3281
|
-
if (val) source[key] = val;
|
|
3282
|
-
}
|
|
3283
|
-
}
|
|
3284
|
-
sources.push(source);
|
|
3285
|
-
}
|
|
3286
|
-
opts.sources = sources;
|
|
3287
|
-
return opts;
|
|
3288
|
-
}
|
|
3289
|
-
};
|
|
3290
|
-
//#endregion
|
|
3291
|
-
//#region src/parts/glossary-document.ts
|
|
3292
|
-
/** Gallery type for building blocks (ST_DocPartGallery) */
|
|
3293
|
-
const DocPartGallery = {
|
|
3294
|
-
PLACEHOLDER: "placeholder",
|
|
3295
|
-
DEFAULT: "default",
|
|
3296
|
-
DOC_PARTS: "docParts",
|
|
3297
|
-
COVER_PAGE: "coverPg",
|
|
3298
|
-
EQUATIONS: "eq",
|
|
3299
|
-
FOOTERS: "ftrs",
|
|
3300
|
-
HEADERS: "hdrs",
|
|
3301
|
-
PAGE_NUMBERS: "pgNum",
|
|
3302
|
-
TABLES: "tbls",
|
|
3303
|
-
WATERMARKS: "watermarks",
|
|
3304
|
-
AUTO_TEXT: "autoTxt",
|
|
3305
|
-
TEXT_BOX: "txtBox",
|
|
3306
|
-
PAGE_NUMBERS_TOP: "pgNumT",
|
|
3307
|
-
PAGE_NUMBERS_BOTTOM: "pgNumB",
|
|
3308
|
-
PAGE_NUMBERS_MARGIN: "pgNumMargins",
|
|
3309
|
-
TABLE_OF_CONTENTS: "tblOfContents",
|
|
3310
|
-
BIBLIOGRAPHY: "bib",
|
|
3311
|
-
CUSTOM_QUICK_PARTS: "custQuickParts",
|
|
3312
|
-
CUSTOM_COVER_PAGE: "custCoverPg",
|
|
3313
|
-
CUSTOM_EQUATIONS: "custEq",
|
|
3314
|
-
CUSTOM_FOOTERS: "custFtrs",
|
|
3315
|
-
CUSTOM_HEADERS: "custHdrs",
|
|
3316
|
-
CUSTOM_PAGE_NUMBERS: "custPgNum",
|
|
3317
|
-
CUSTOM_TABLES: "custTbls",
|
|
3318
|
-
CUSTOM_WATERMARKS: "custWatermarks",
|
|
3319
|
-
CUSTOM_AUTO_TEXT: "custAutoTxt",
|
|
3320
|
-
CUSTOM_TEXT_BOX: "custTxtBox",
|
|
3321
|
-
CUSTOM_PAGE_NUMBERS_TOP: "custPgNumT",
|
|
3322
|
-
CUSTOM_PAGE_NUMBERS_BOTTOM: "custPgNumB",
|
|
3323
|
-
CUSTOM_PAGE_NUMBERS_MARGIN: "custPgNumMargins",
|
|
3324
|
-
CUSTOM_TABLE_OF_CONTENTS: "custTblOfContents",
|
|
3325
|
-
CUSTOM_BIBLIOGRAPHY: "custBib",
|
|
3326
|
-
CUSTOM1: "custom1",
|
|
3327
|
-
CUSTOM2: "custom2",
|
|
3328
|
-
CUSTOM3: "custom3",
|
|
3329
|
-
CUSTOM4: "custom4",
|
|
3330
|
-
CUSTOM5: "custom5"
|
|
3331
|
-
};
|
|
3332
|
-
/** Building block type (ST_DocPartType) */
|
|
3333
|
-
const DocPartType = {
|
|
3334
|
-
NONE: "none",
|
|
3335
|
-
NORMAL: "normal",
|
|
3336
|
-
AUTO_EXPAND: "autoExp",
|
|
3337
|
-
TOOLBAR: "toolbar",
|
|
3338
|
-
SPELLER: "speller",
|
|
3339
|
-
FORM_FIELD: "formFld",
|
|
3340
|
-
BUILDING_BLOCK_PLACEHOLDER: "bbPlcHdr"
|
|
3341
|
-
};
|
|
3342
|
-
/** Building block behavior (ST_DocPartBehavior) */
|
|
3343
|
-
const DocPartBehavior = {
|
|
3344
|
-
CONTENT: "content",
|
|
3345
|
-
PARAGRAPH: "p",
|
|
3346
|
-
PAGE: "pg"
|
|
3347
|
-
};
|
|
3348
|
-
const GLOSSARY_NS = "xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\"";
|
|
3349
|
-
function docPartPrXml(part) {
|
|
3350
|
-
const prParts = [];
|
|
3351
|
-
prParts.push(`<w:name w:val="${escapeXml(part.name)}"${part.decorated ? " w:decorated=\"1\"" : ""}/>`);
|
|
3352
|
-
if (part.category || part.gallery) {
|
|
3353
|
-
const catParts = [];
|
|
3354
|
-
if (part.category) catParts.push(`<w:name w:val="${escapeXml(part.category)}"/>`);
|
|
3355
|
-
catParts.push(`<w:gallery w:val="${part.gallery}"/>`);
|
|
3356
|
-
prParts.push(`<w:category>${catParts.join("")}</w:category>`);
|
|
3357
|
-
}
|
|
3358
|
-
if (part.types && part.types.length > 0) {
|
|
3359
|
-
const typeXml = part.types.map((t) => `<w:type w:val="${t}"/>`).join("");
|
|
3360
|
-
const allAttr = part.allTypes ? " w:all=\"1\"" : "";
|
|
3361
|
-
prParts.push(`<w:types${allAttr}>${typeXml}</w:types>`);
|
|
3362
|
-
}
|
|
3363
|
-
if (part.behaviors && part.behaviors.length > 0) {
|
|
3364
|
-
const behaviorXml = part.behaviors.map((b) => `<w:behavior w:val="${b}"/>`).join("");
|
|
3365
|
-
prParts.push(`<w:behaviors>${behaviorXml}</w:behaviors>`);
|
|
3366
|
-
}
|
|
3367
|
-
if (part.description) prParts.push(`<w:description w:val="${escapeXml(part.description)}"/>`);
|
|
3368
|
-
if (part.guid) prParts.push(`<w:guid w:val="${escapeXml(part.guid)}"/>`);
|
|
3369
|
-
return `<w:docPartPr>${prParts.join("")}</w:docPartPr>`;
|
|
3370
|
-
}
|
|
3371
|
-
const glossaryDesc = {
|
|
3372
|
-
kind: "custom",
|
|
3373
|
-
stringify(opts, ctx) {
|
|
3374
|
-
return `<w:glossaryDocument ${GLOSSARY_NS}><w:docParts>${opts.parts.map((part) => {
|
|
3375
|
-
const bodyContent = (part.children ?? []).map((child) => ctx.stringifyChild(child, ctx)).join("");
|
|
3376
|
-
return `<w:docPart>${docPartPrXml(part)}<w:docPartBody>${bodyContent}</w:docPartBody></w:docPart>`;
|
|
3377
|
-
}).join("")}</w:docParts></w:glossaryDocument>`;
|
|
3378
|
-
},
|
|
3379
|
-
parse(el, ctx) {
|
|
3380
|
-
const dctx = ctx;
|
|
3381
|
-
const parts = [];
|
|
3382
|
-
const docPartsEl = findChild(el, "w:docParts");
|
|
3383
|
-
if (!docPartsEl) return { parts };
|
|
3384
|
-
for (const docPart of docPartsEl.elements ?? []) {
|
|
3385
|
-
if (docPart.name !== "w:docPart") continue;
|
|
3386
|
-
const part = {};
|
|
3387
|
-
const pr = findChild(docPart, "w:docPartPr");
|
|
3388
|
-
if (pr) {
|
|
3389
|
-
const name = findChild(pr, "w:name");
|
|
3390
|
-
if (name) {
|
|
3391
|
-
part.name = attr(name, "w:val") ?? "";
|
|
3392
|
-
if (attr(name, "w:decorated") === "1") part.decorated = true;
|
|
3393
|
-
}
|
|
3394
|
-
const category = findChild(pr, "w:category");
|
|
3395
|
-
if (category) {
|
|
3396
|
-
const catName = findChild(category, "w:name");
|
|
3397
|
-
if (catName) part.category = attr(catName, "w:val");
|
|
3398
|
-
const gallery = findChild(category, "w:gallery");
|
|
3399
|
-
if (gallery) part.gallery = attr(gallery, "w:val");
|
|
3400
|
-
}
|
|
3401
|
-
const types = findChild(pr, "w:types");
|
|
3402
|
-
if (types) {
|
|
3403
|
-
const typeList = [];
|
|
3404
|
-
for (const t of types.elements ?? []) if (t.name === "w:type") {
|
|
3405
|
-
const val = attr(t, "w:val");
|
|
3406
|
-
if (val) typeList.push(val);
|
|
3407
|
-
}
|
|
3408
|
-
if (typeList.length > 0) part.types = typeList;
|
|
3409
|
-
if (attr(types, "w:all") === "1") part.allTypes = true;
|
|
3410
|
-
}
|
|
3411
|
-
const behaviors = findChild(pr, "w:behaviors");
|
|
3412
|
-
if (behaviors) {
|
|
3413
|
-
const behaviorList = [];
|
|
3414
|
-
for (const b of behaviors.elements ?? []) if (b.name === "w:behavior") {
|
|
3415
|
-
const val = attr(b, "w:val");
|
|
3416
|
-
if (val) behaviorList.push(val);
|
|
3417
|
-
}
|
|
3418
|
-
if (behaviorList.length > 0) part.behaviors = behaviorList;
|
|
3419
|
-
}
|
|
3420
|
-
const desc = findChild(pr, "w:description");
|
|
3421
|
-
if (desc) {
|
|
3422
|
-
const val = attr(desc, "w:val");
|
|
3423
|
-
if (val) part.description = val;
|
|
3424
|
-
}
|
|
3425
|
-
const guid = findChild(pr, "w:guid");
|
|
3426
|
-
if (guid) {
|
|
3427
|
-
const val = attr(guid, "w:val");
|
|
3428
|
-
if (val) part.guid = val;
|
|
3429
|
-
}
|
|
3430
|
-
}
|
|
3431
|
-
const body = findChild(docPart, "w:docPartBody");
|
|
3432
|
-
if (body) {
|
|
3433
|
-
const childList = [];
|
|
3434
|
-
for (const sub of body.elements ?? []) if (sub.name === "w:p") childList.push({ paragraph: parseParagraph(sub, dctx) });
|
|
3435
|
-
if (childList.length > 0) part.children = childList;
|
|
3436
|
-
}
|
|
3437
|
-
parts.push(part);
|
|
3438
|
-
}
|
|
3439
|
-
return { parts };
|
|
3440
|
-
}
|
|
3441
|
-
};
|
|
3442
|
-
//#endregion
|
|
3443
|
-
//#region src/parts/contenttypes.ts
|
|
3444
|
-
/**
|
|
3445
|
-
* Content types descriptor — produces [Content_Types].xml.
|
|
3446
|
-
*
|
|
3447
|
-
* Reference: OPC, Content_Types.xsd
|
|
3448
|
-
*
|
|
3449
|
-
* @module
|
|
3450
|
-
*/
|
|
3451
|
-
function defaultXml(ext, ct) {
|
|
3452
|
-
return `<Default Extension="${ext}" ContentType="${ct}"/>`;
|
|
3453
|
-
}
|
|
3454
|
-
function overrideXml(partName, ct) {
|
|
3455
|
-
return `<Override PartName="${partName}" ContentType="${ct}"/>`;
|
|
3456
|
-
}
|
|
3457
|
-
const contentTypesDesc = {
|
|
3458
|
-
kind: "custom",
|
|
3459
|
-
stringify(opts, _ctx) {
|
|
3460
|
-
const p = ["<Types xmlns=\"http://schemas.openxmlformats.org/package/2006/content-types\">"];
|
|
3461
|
-
const seenDefault = /* @__PURE__ */ new Set();
|
|
3462
|
-
for (const d of opts.defaults) {
|
|
3463
|
-
const key = d.extension.toLowerCase();
|
|
3464
|
-
if (seenDefault.has(key)) continue;
|
|
3465
|
-
seenDefault.add(key);
|
|
3466
|
-
p.push(defaultXml(d.extension, d.contentType));
|
|
3467
|
-
}
|
|
3468
|
-
const seenOverride = /* @__PURE__ */ new Set();
|
|
3469
|
-
for (const o of opts.overrides) {
|
|
3470
|
-
const key = o.partName.toLowerCase();
|
|
3471
|
-
if (seenOverride.has(key)) continue;
|
|
3472
|
-
seenOverride.add(key);
|
|
3473
|
-
p.push(overrideXml(o.partName, o.contentType));
|
|
3474
|
-
}
|
|
3475
|
-
p.push("</Types>");
|
|
3476
|
-
return p.join("");
|
|
3477
|
-
},
|
|
3478
|
-
parse(el, _ctx) {
|
|
3479
|
-
const defaults = [];
|
|
3480
|
-
const overrides = [];
|
|
3481
|
-
for (const child of el.elements ?? []) if (child.name === "Default") {
|
|
3482
|
-
const ext = child.attributes?.["Extension"];
|
|
3483
|
-
const ct = child.attributes?.["ContentType"];
|
|
3484
|
-
if (ext && ct) defaults.push({
|
|
3485
|
-
extension: String(ext),
|
|
3486
|
-
contentType: String(ct)
|
|
3487
|
-
});
|
|
3488
|
-
} else if (child.name === "Override") {
|
|
3489
|
-
const pn = child.attributes?.["PartName"];
|
|
3490
|
-
const ct = child.attributes?.["ContentType"];
|
|
3491
|
-
if (pn && ct) overrides.push({
|
|
3492
|
-
partName: String(pn),
|
|
3493
|
-
contentType: String(ct)
|
|
3494
|
-
});
|
|
3495
|
-
}
|
|
3496
|
-
return {
|
|
3497
|
-
defaults,
|
|
3498
|
-
overrides
|
|
3499
|
-
};
|
|
3500
|
-
}
|
|
3501
|
-
};
|
|
3502
|
-
/** Standard extension → content-type defaults covering every media type emitted. */
|
|
3503
|
-
const STANDARD_DEFAULTS = [
|
|
3504
|
-
{
|
|
3505
|
-
extension: "png",
|
|
3506
|
-
contentType: "image/png"
|
|
3507
|
-
},
|
|
3508
|
-
{
|
|
3509
|
-
extension: "jpeg",
|
|
3510
|
-
contentType: "image/jpeg"
|
|
3511
|
-
},
|
|
3512
|
-
{
|
|
3513
|
-
extension: "jpg",
|
|
3514
|
-
contentType: "image/jpeg"
|
|
3515
|
-
},
|
|
3516
|
-
{
|
|
3517
|
-
extension: "bmp",
|
|
3518
|
-
contentType: "image/bmp"
|
|
3519
|
-
},
|
|
3520
|
-
{
|
|
3521
|
-
extension: "gif",
|
|
3522
|
-
contentType: "image/gif"
|
|
3523
|
-
},
|
|
3524
|
-
{
|
|
3525
|
-
extension: "tif",
|
|
3526
|
-
contentType: "image/tiff"
|
|
3527
|
-
},
|
|
3528
|
-
{
|
|
3529
|
-
extension: "tiff",
|
|
3530
|
-
contentType: "image/tiff"
|
|
3531
|
-
},
|
|
3532
|
-
{
|
|
3533
|
-
extension: "emf",
|
|
3534
|
-
contentType: "image/x-emf"
|
|
3535
|
-
},
|
|
3536
|
-
{
|
|
3537
|
-
extension: "wmf",
|
|
3538
|
-
contentType: "image/x-wmf"
|
|
3539
|
-
},
|
|
3540
|
-
{
|
|
3541
|
-
extension: "ico",
|
|
3542
|
-
contentType: "image/x-icon"
|
|
3543
|
-
},
|
|
3544
|
-
{
|
|
3545
|
-
extension: "svg",
|
|
3546
|
-
contentType: "image/svg+xml"
|
|
3547
|
-
},
|
|
3548
|
-
{
|
|
3549
|
-
extension: "rels",
|
|
3550
|
-
contentType: "application/vnd.openxmlformats-package.relationships+xml"
|
|
3551
|
-
},
|
|
3552
|
-
{
|
|
3553
|
-
extension: "xml",
|
|
3554
|
-
contentType: "application/xml"
|
|
3555
|
-
},
|
|
3556
|
-
{
|
|
3557
|
-
extension: "odttf",
|
|
3558
|
-
contentType: "application/vnd.openxmlformats-officedocument.obfuscatedFont"
|
|
3559
|
-
},
|
|
3560
|
-
{
|
|
3561
|
-
extension: "bin",
|
|
3562
|
-
contentType: "application/vnd.openxmlformats-officedocument.oleObject"
|
|
3563
|
-
}
|
|
3564
|
-
];
|
|
3565
|
-
/**
|
|
3566
|
-
* Ensure every media part in the package has a resolvable content-type Default.
|
|
3567
|
-
*
|
|
3568
|
-
* Round-tripped packages pass through the source's [Content_Types], which may
|
|
3569
|
-
* declare an uppercase extension (e.g. `JPG`) while the media is named `.jpg`.
|
|
3570
|
-
* OPC extension matching is **case-insensitive** (ECMA-376-2 §10.1.2), so `JPG`
|
|
3571
|
-
* and `jpg` are one key — emitting both yields a duplicate default that Word
|
|
3572
|
-
* rejects as unreadable content. Match existing defaults case-insensitively so
|
|
3573
|
-
* we never add a colliding extension; the media then resolves through the
|
|
3574
|
-
* source's already-declared default.
|
|
3575
|
-
*/
|
|
3576
|
-
function withMediaDefaults(input, mediaFileNames) {
|
|
3577
|
-
const have = new Set(input.defaults.map((d) => d.extension.toLowerCase()));
|
|
3578
|
-
const standard = new Map(STANDARD_DEFAULTS.map((d) => [d.extension, d.contentType]));
|
|
3579
|
-
const defaults = [...input.defaults];
|
|
3580
|
-
for (const fileName of mediaFileNames) {
|
|
3581
|
-
const ext = fileName.slice(fileName.lastIndexOf(".") + 1);
|
|
3582
|
-
const key = ext.toLowerCase();
|
|
3583
|
-
if (!ext || have.has(key)) continue;
|
|
3584
|
-
const contentType = standard.get(key);
|
|
3585
|
-
if (contentType) {
|
|
3586
|
-
defaults.push({
|
|
3587
|
-
extension: ext,
|
|
3588
|
-
contentType
|
|
3589
|
-
});
|
|
3590
|
-
have.add(key);
|
|
3591
|
-
}
|
|
3592
|
-
}
|
|
3593
|
-
return {
|
|
3594
|
-
defaults,
|
|
3595
|
-
overrides: input.overrides
|
|
3596
|
-
};
|
|
3597
|
-
}
|
|
3598
|
-
/** Default content types for altChunk part extensions. */
|
|
3599
|
-
const ALTCHUNK_DEFAULTS = {
|
|
3600
|
-
html: "text/html",
|
|
3601
|
-
rtf: "application/rtf",
|
|
3602
|
-
txt: "text/plain"
|
|
3603
|
-
};
|
|
3604
|
-
/**
|
|
3605
|
-
* Realign [Content_Types] Overrides for altChunk parts on a round-tripped
|
|
3606
|
-
* package. The pass-through content types carry Override PartNames from the
|
|
3607
|
-
* source, but the compiler regenerates altChunk part paths (uniqueId), so the
|
|
3608
|
-
* Override and the written part drift apart (O5/O6). This drops the stale
|
|
3609
|
-
* afchunk Overrides and appends ones matching the freshly generated paths,
|
|
3610
|
-
* backfilling the extension Default so the part is resolvable either way.
|
|
3611
|
-
*/
|
|
3612
|
-
function withAltChunkOverrides(input, altChunks) {
|
|
3613
|
-
const defaults = [...input.defaults];
|
|
3614
|
-
const haveExt = new Set(defaults.map((d) => d.extension.toLowerCase()));
|
|
3615
|
-
for (const ac of altChunks) {
|
|
3616
|
-
const ext = (ac.path.split(".").pop() ?? "").toLowerCase();
|
|
3617
|
-
if (ext && !haveExt.has(ext) && ALTCHUNK_DEFAULTS[ext]) {
|
|
3618
|
-
defaults.push({
|
|
3619
|
-
extension: ext,
|
|
3620
|
-
contentType: ALTCHUNK_DEFAULTS[ext]
|
|
3621
|
-
});
|
|
3622
|
-
haveExt.add(ext);
|
|
3623
|
-
}
|
|
3624
|
-
}
|
|
3625
|
-
const overrides = input.overrides.filter((o) => !o.partName.startsWith("/word/afchunks/"));
|
|
3626
|
-
for (const ac of altChunks) {
|
|
3627
|
-
const partName = ac.path.startsWith("/") ? ac.path : `/${ac.path}`;
|
|
3628
|
-
overrides.push({
|
|
3629
|
-
partName,
|
|
3630
|
-
contentType: ac.contentType
|
|
3631
|
-
});
|
|
3632
|
-
}
|
|
3633
|
-
return {
|
|
3634
|
-
defaults,
|
|
3635
|
-
overrides
|
|
3636
|
-
};
|
|
3637
|
-
}
|
|
3638
|
-
const CUSTOM_PROPERTIES_PART_NAME = "/docProps/custom.xml";
|
|
3639
|
-
const CUSTOM_PROPERTIES_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.custom-properties+xml";
|
|
3640
|
-
/**
|
|
3641
|
-
* Ensure the docProps/custom.xml Override exists on a round-tripped package.
|
|
3642
|
-
* The custom-properties part is always written (even when empty), but a source
|
|
3643
|
-
* [Content_Types] may omit its Override — the part then resolves only through
|
|
3644
|
-
* the generic `application/xml` Default, which Word rejects as unreadable
|
|
3645
|
-
* content (OPC O5). Mirror the unconditional part emission by forcing the
|
|
3646
|
-
* Override whenever it is missing.
|
|
3647
|
-
*/
|
|
3648
|
-
function ensureCustomPropertiesOverride(input) {
|
|
3649
|
-
if (input.overrides.some((o) => o.partName.toLowerCase() === CUSTOM_PROPERTIES_PART_NAME)) return input;
|
|
3650
|
-
return {
|
|
3651
|
-
...input,
|
|
3652
|
-
overrides: [...input.overrides, {
|
|
3653
|
-
partName: CUSTOM_PROPERTIES_PART_NAME,
|
|
3654
|
-
contentType: CUSTOM_PROPERTIES_CONTENT_TYPE
|
|
3655
|
-
}]
|
|
3656
|
-
};
|
|
3657
|
-
}
|
|
3658
|
-
/**
|
|
3659
|
-
* Build [Content_Types].xml for a fresh DOCX compile, driven by the part
|
|
3660
|
-
* registry. Static parts (document/styles/…/comments/headers/…) come from
|
|
3661
|
-
* {@link buildContentTypeOverrides} over {@link DOCX_PARTS}; dynamic parts whose
|
|
3662
|
-
* path or count is runtime-determined (altChunks, sub-documents) are appended
|
|
3663
|
-
* here — they are not enumerable in the registry.
|
|
3664
|
-
*
|
|
3665
|
-
* `facts` keys mirror the registry's `flag` / `countFrom` tokens. The Override
|
|
3666
|
-
* set (order-independent) matches the former hand-written builder, so the OPC
|
|
3667
|
-
* consistency validator stays green.
|
|
3668
|
-
*/
|
|
3669
|
-
function buildContentTypesFromRegistry(facts, dynamic = {}) {
|
|
3670
|
-
const overrides = buildContentTypeOverrides(DOCX_PARTS, facts);
|
|
3671
|
-
for (const ac of dynamic.altChunks ?? []) overrides.push({
|
|
3672
|
-
partName: ac.path.startsWith("/") ? ac.path : `/${ac.path}`,
|
|
3673
|
-
contentType: ac.contentType
|
|
3674
|
-
});
|
|
3675
|
-
for (const sd of dynamic.subDocs ?? []) overrides.push({
|
|
3676
|
-
partName: sd.path.startsWith("/") ? sd.path : `/${sd.path}`,
|
|
3677
|
-
contentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"
|
|
3678
|
-
});
|
|
3679
|
-
const defaults = [{
|
|
3680
|
-
extension: "rels",
|
|
3681
|
-
contentType: "application/vnd.openxmlformats-package.relationships+xml"
|
|
3682
|
-
}, {
|
|
3683
|
-
extension: "xml",
|
|
3684
|
-
contentType: "application/xml"
|
|
3685
|
-
}];
|
|
3686
|
-
const haveExt = new Set(["rels", "xml"]);
|
|
3687
|
-
for (const ac of dynamic.altChunks ?? []) {
|
|
3688
|
-
const ext = (ac.path.split(".").pop() ?? "").toLowerCase();
|
|
3689
|
-
if (ext && !haveExt.has(ext) && ALTCHUNK_DEFAULTS[ext]) {
|
|
3690
|
-
defaults.push({
|
|
3691
|
-
extension: ext,
|
|
3692
|
-
contentType: ALTCHUNK_DEFAULTS[ext]
|
|
3693
|
-
});
|
|
3694
|
-
haveExt.add(ext);
|
|
3695
|
-
}
|
|
3696
|
-
}
|
|
3697
|
-
return {
|
|
3698
|
-
defaults,
|
|
3699
|
-
overrides
|
|
3700
|
-
};
|
|
3701
|
-
}
|
|
3702
|
-
//#endregion
|
|
3703
|
-
//#region src/parts/core-properties.ts
|
|
3704
|
-
const corePropertiesDesc = {
|
|
3705
|
-
kind: "custom",
|
|
3706
|
-
stringify(opts, _ctx) {
|
|
3707
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3708
|
-
const p = ["<cp:coreProperties xmlns:cp=\"http://schemas.openxmlformats.org/package/2006/metadata/core-properties\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:dcmitype=\"http://purl.org/dc/dcmitype/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"];
|
|
3709
|
-
p.push(`<dcterms:created xsi:type="dcterms:W3CDTF">${opts.created ?? now}</dcterms:created>`);
|
|
3710
|
-
if (opts.creator) p.push(`<dc:creator>${escapeXml(opts.creator)}</dc:creator>`);
|
|
3711
|
-
if (opts.description) p.push(`<dc:description>${escapeXml(opts.description)}</dc:description>`);
|
|
3712
|
-
if (opts.keywords) p.push(`<cp:keywords>${escapeXml(opts.keywords)}</cp:keywords>`);
|
|
3713
|
-
if (opts.lastModifiedBy) p.push(`<cp:lastModifiedBy>${escapeXml(opts.lastModifiedBy)}</cp:lastModifiedBy>`);
|
|
3714
|
-
if (opts.lastPrinted) p.push(`<cp:lastPrinted>${escapeXml(opts.lastPrinted)}</cp:lastPrinted>`);
|
|
3715
|
-
p.push(`<dcterms:modified xsi:type="dcterms:W3CDTF">${opts.modified ?? now}</dcterms:modified>`);
|
|
3716
|
-
if (opts.revision !== void 0) p.push(`<cp:revision>${opts.revision}</cp:revision>`);
|
|
3717
|
-
if (opts.subject) p.push(`<dc:subject>${escapeXml(opts.subject)}</dc:subject>`);
|
|
3718
|
-
if (opts.title) p.push(`<dc:title>${escapeXml(opts.title)}</dc:title>`);
|
|
3719
|
-
p.push("</cp:coreProperties>");
|
|
3720
|
-
return p.join("");
|
|
3721
|
-
},
|
|
3722
|
-
parse(el, _ctx) {
|
|
3723
|
-
const result = {};
|
|
3724
|
-
for (const child of el.elements ?? []) {
|
|
3725
|
-
if (typeof child.name !== "string") continue;
|
|
3726
|
-
const text = child.elements?.[0]?.text;
|
|
3727
|
-
if (typeof text !== "string") continue;
|
|
3728
|
-
switch (child.name) {
|
|
3729
|
-
case "dc:title":
|
|
3730
|
-
result.title = text;
|
|
3731
|
-
break;
|
|
3732
|
-
case "dc:subject":
|
|
3733
|
-
result.subject = text;
|
|
3734
|
-
break;
|
|
3735
|
-
case "dc:creator":
|
|
3736
|
-
result.creator = text;
|
|
3737
|
-
break;
|
|
3738
|
-
case "cp:keywords":
|
|
3739
|
-
result.keywords = text;
|
|
3740
|
-
break;
|
|
3741
|
-
case "dc:description":
|
|
3742
|
-
result.description = text;
|
|
3743
|
-
break;
|
|
3744
|
-
case "cp:lastModifiedBy":
|
|
3745
|
-
result.lastModifiedBy = text;
|
|
3746
|
-
break;
|
|
3747
|
-
case "cp:revision":
|
|
3748
|
-
result.revision = Number(text);
|
|
3749
|
-
break;
|
|
3750
|
-
case "cp:lastPrinted":
|
|
3751
|
-
result.lastPrinted = text;
|
|
3752
|
-
break;
|
|
3753
|
-
case "dcterms:created":
|
|
3754
|
-
result.created = text;
|
|
3755
|
-
break;
|
|
3756
|
-
case "dcterms:modified":
|
|
3757
|
-
result.modified = text;
|
|
3758
|
-
break;
|
|
3759
|
-
}
|
|
3760
|
-
}
|
|
3761
|
-
return result;
|
|
3762
|
-
}
|
|
3763
|
-
};
|
|
3764
|
-
//#endregion
|
|
3765
|
-
//#region src/parts/web-settings.ts
|
|
3766
|
-
/**
|
|
3767
|
-
* Screen size types for web settings target.
|
|
3768
|
-
*/
|
|
3769
|
-
const TargetScreenSize = {
|
|
3770
|
-
SIZE_544X376: "544x376",
|
|
3771
|
-
SIZE_640X480: "640x480",
|
|
3772
|
-
SIZE_720X512: "720x512",
|
|
3773
|
-
SIZE_800X600: "800x600",
|
|
3774
|
-
SIZE_1024X768: "1024x768",
|
|
3775
|
-
SIZE_1152X882: "1152x882",
|
|
3776
|
-
SIZE_1152X900: "1152x900",
|
|
3777
|
-
SIZE_1280X1024: "1280x1024",
|
|
3778
|
-
SIZE_1600X1200: "1600x1200",
|
|
3779
|
-
SIZE_1800X1440: "1800x1440",
|
|
3780
|
-
SIZE_1920X1200: "1920x1200"
|
|
3781
|
-
};
|
|
3782
|
-
const WS_NS = "xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\"";
|
|
3783
|
-
function wsOnOff(tag, val) {
|
|
3784
|
-
return `<${tag} w:val="${val ? "true" : "false"}"/>`;
|
|
3785
|
-
}
|
|
3786
|
-
function wsStringVal(tag, val) {
|
|
3787
|
-
return `<${tag} w:val="${escapeXml(val)}"/>`;
|
|
3788
|
-
}
|
|
3789
|
-
function wsNumVal(tag, val) {
|
|
3790
|
-
return `<${tag} w:val="${val}"/>`;
|
|
3791
|
-
}
|
|
3792
|
-
function parseFramesetEl(el) {
|
|
3793
|
-
const opts = {};
|
|
3794
|
-
const sz = findChild(el, "w:sz");
|
|
3795
|
-
if (sz) {
|
|
3796
|
-
const val = attr(sz, "w:val");
|
|
3797
|
-
if (val) opts.size = val;
|
|
3798
|
-
}
|
|
3799
|
-
const splitbar = findChild(el, "w:framesetSplitbar");
|
|
3800
|
-
if (splitbar) opts.splitbar = parseSplitbarEl(splitbar);
|
|
3801
|
-
const layout = findChild(el, "w:frameLayout");
|
|
3802
|
-
if (layout) {
|
|
3803
|
-
const val = attr(layout, "w:val");
|
|
3804
|
-
if (val === "rows" || val === "cols") opts.layout = val;
|
|
3805
|
-
}
|
|
3806
|
-
const title = findChild(el, "w:title");
|
|
3807
|
-
if (title) {
|
|
3808
|
-
const val = attr(title, "w:val");
|
|
3809
|
-
if (val) opts.title = val;
|
|
3810
|
-
}
|
|
3811
|
-
const children = [];
|
|
3812
|
-
for (const child of el.elements ?? []) if (child.name === "w:frameset") children.push(parseFramesetEl(child));
|
|
3813
|
-
else if (child.name === "w:frame") children.push(parseFrameEl(child));
|
|
3814
|
-
if (children.length > 0) opts.children = children;
|
|
3815
|
-
return opts;
|
|
3816
|
-
}
|
|
3817
|
-
function parseSplitbarEl(el) {
|
|
3818
|
-
const opts = {};
|
|
3819
|
-
const w = findChild(el, "w:w");
|
|
3820
|
-
if (w) {
|
|
3821
|
-
const val = attrNum(w, "w:w");
|
|
3822
|
-
if (val !== void 0) opts.width = val;
|
|
3823
|
-
}
|
|
3824
|
-
const color = findChild(el, "w:color");
|
|
3825
|
-
if (color) {
|
|
3826
|
-
const val = attr(color, "w:val");
|
|
3827
|
-
if (val) opts.color = val;
|
|
3828
|
-
}
|
|
3829
|
-
if (findChild(el, "w:noBorder")) opts.noBorder = true;
|
|
3830
|
-
if (findChild(el, "w:flatBorders")) opts.flatBorders = true;
|
|
3831
|
-
return opts;
|
|
3832
|
-
}
|
|
3833
|
-
function parseFrameEl(el) {
|
|
3834
|
-
const opts = {};
|
|
3835
|
-
const sz = findChild(el, "w:sz");
|
|
3836
|
-
if (sz) {
|
|
3837
|
-
const val = attr(sz, "w:val");
|
|
3838
|
-
if (val) opts.size = val;
|
|
3839
|
-
}
|
|
3840
|
-
const name = findChild(el, "w:name");
|
|
3841
|
-
if (name) {
|
|
3842
|
-
const val = attr(name, "w:val");
|
|
3843
|
-
if (val) opts.name = val;
|
|
3844
|
-
}
|
|
3845
|
-
const title = findChild(el, "w:title");
|
|
3846
|
-
if (title) {
|
|
3847
|
-
const val = attr(title, "w:val");
|
|
3848
|
-
if (val) opts.title = val;
|
|
3849
|
-
}
|
|
3850
|
-
const source = findChild(el, "w:sourceFileName");
|
|
3851
|
-
if (source) {
|
|
3852
|
-
const val = attr(source, "r:id");
|
|
3853
|
-
if (val) opts.sourceRId = val;
|
|
3854
|
-
}
|
|
3855
|
-
const marW = findChild(el, "w:marW");
|
|
3856
|
-
if (marW) {
|
|
3857
|
-
const val = attrNum(marW, "w:val");
|
|
3858
|
-
if (val !== void 0) opts.marginWidth = val;
|
|
3859
|
-
}
|
|
3860
|
-
const marH = findChild(el, "w:marH");
|
|
3861
|
-
if (marH) {
|
|
3862
|
-
const val = attrNum(marH, "w:val");
|
|
3863
|
-
if (val !== void 0) opts.marginHeight = val;
|
|
3864
|
-
}
|
|
3865
|
-
const scrollbar = findChild(el, "w:scrollbar");
|
|
3866
|
-
if (scrollbar) {
|
|
3867
|
-
const val = attr(scrollbar, "w:val");
|
|
3868
|
-
if (val === "on" || val === "off" || val === "auto") opts.scrollbar = val;
|
|
3869
|
-
}
|
|
3870
|
-
if (findChild(el, "w:noResizeAllowed")) opts.noResizeAllowed = true;
|
|
3871
|
-
if (findChild(el, "w:linkedToFile")) opts.linkedToFile = true;
|
|
3872
|
-
const longDesc = findChild(el, "w:longDesc");
|
|
3873
|
-
if (longDesc) {
|
|
3874
|
-
const val = attr(longDesc, "r:id");
|
|
3875
|
-
if (val) opts.longDescRId = val;
|
|
3876
|
-
}
|
|
3877
|
-
return opts;
|
|
3878
|
-
}
|
|
3879
|
-
function parseDivsEl(el) {
|
|
3880
|
-
const result = [];
|
|
3881
|
-
for (const child of el.elements ?? []) if (child.name === "w:div") result.push(parseDivEl(child));
|
|
3882
|
-
return result;
|
|
3883
|
-
}
|
|
3884
|
-
function parseDivEl(el) {
|
|
3885
|
-
const opts = { id: attrNum(el, "w:id") ?? 0 };
|
|
3886
|
-
const marLeft = findChild(el, "w:marLeft");
|
|
3887
|
-
if (marLeft) {
|
|
3888
|
-
const val = attrMeasure(marLeft, "w:val");
|
|
3889
|
-
if (val !== void 0) opts.marginLeft = val;
|
|
3890
|
-
}
|
|
3891
|
-
const marRight = findChild(el, "w:marRight");
|
|
3892
|
-
if (marRight) {
|
|
3893
|
-
const val = attrMeasure(marRight, "w:val");
|
|
3894
|
-
if (val !== void 0) opts.marginRight = val;
|
|
3895
|
-
}
|
|
3896
|
-
const marTop = findChild(el, "w:marTop");
|
|
3897
|
-
if (marTop) {
|
|
3898
|
-
const val = attrMeasure(marTop, "w:val");
|
|
3899
|
-
if (val !== void 0) opts.marginTop = val;
|
|
3900
|
-
}
|
|
3901
|
-
const marBottom = findChild(el, "w:marBottom");
|
|
3902
|
-
if (marBottom) {
|
|
3903
|
-
const val = attrMeasure(marBottom, "w:val");
|
|
3904
|
-
if (val !== void 0) opts.marginBottom = val;
|
|
3905
|
-
}
|
|
3906
|
-
const blockQuote = findChild(el, "w:blockQuote");
|
|
3907
|
-
if (blockQuote) opts.blockQuote = attr(blockQuote, "w:val") !== "off";
|
|
3908
|
-
const bodyDiv = findChild(el, "w:bodyDiv");
|
|
3909
|
-
if (bodyDiv) opts.bodyDiv = attr(bodyDiv, "w:val") !== "off";
|
|
3910
|
-
const divBdr = findChild(el, "w:divBdr");
|
|
3911
|
-
if (divBdr) opts.border = parseDivBorderEl(divBdr);
|
|
3912
|
-
const divsChild = findChild(el, "w:divsChild");
|
|
3913
|
-
if (divsChild) {
|
|
3914
|
-
const children = parseDivsEl(divsChild);
|
|
3915
|
-
if (children.length > 0) opts.children = children;
|
|
3916
|
-
}
|
|
3917
|
-
return opts;
|
|
3918
|
-
}
|
|
3919
|
-
function parseDivBorderEl(el) {
|
|
3920
|
-
const opts = {};
|
|
3921
|
-
for (const side of [
|
|
3922
|
-
"top",
|
|
3923
|
-
"left",
|
|
3924
|
-
"bottom",
|
|
3925
|
-
"right"
|
|
3926
|
-
]) {
|
|
3927
|
-
const sideEl = findChild(el, `w:${side}`);
|
|
3928
|
-
if (sideEl) {
|
|
3929
|
-
const b = {};
|
|
3930
|
-
const val = attr(sideEl, "w:val");
|
|
3931
|
-
if (val) b.style = val;
|
|
3932
|
-
const color = attr(sideEl, "w:color");
|
|
3933
|
-
if (color) b.color = color;
|
|
3934
|
-
const sz = attrNum(sideEl, "w:sz");
|
|
3935
|
-
if (sz !== void 0) b.size = sz;
|
|
3936
|
-
opts[side] = b;
|
|
3937
|
-
}
|
|
3938
|
-
}
|
|
3939
|
-
return opts;
|
|
3940
|
-
}
|
|
3941
|
-
function wsDivBorderXml(b) {
|
|
3942
|
-
const parts = ["<w:divBdr>"];
|
|
3943
|
-
const sides = [
|
|
3944
|
-
["w:top", b.top],
|
|
3945
|
-
["w:left", b.left],
|
|
3946
|
-
["w:bottom", b.bottom],
|
|
3947
|
-
["w:right", b.right]
|
|
3948
|
-
];
|
|
3949
|
-
for (const [tag, side] of sides) {
|
|
3950
|
-
if (!side) continue;
|
|
3951
|
-
const attrParts = [`w:val="${escapeXml(side.style)}"`];
|
|
3952
|
-
if (side.color) attrParts.push(`w:color="${escapeXml(side.color)}"`);
|
|
3953
|
-
if (side.size !== void 0) attrParts.push(`w:sz="${side.size}"`);
|
|
3954
|
-
parts.push(`<${tag} ${attrParts.join(" ")}/>`);
|
|
3955
|
-
}
|
|
3956
|
-
parts.push("</w:divBdr>");
|
|
3957
|
-
return parts.join("");
|
|
3958
|
-
}
|
|
3959
|
-
function wsDivXml(d) {
|
|
3960
|
-
const parts = [`<w:div w:id="${d.id}">`];
|
|
3961
|
-
if (d.blockQuote !== void 0) parts.push(wsStringVal("w:blockQuote", d.blockQuote ? "on" : "off"));
|
|
3962
|
-
if (d.bodyDiv !== void 0) parts.push(wsStringVal("w:bodyDiv", d.bodyDiv ? "on" : "off"));
|
|
3963
|
-
parts.push(wsNumVal("w:marLeft", d.marginLeft));
|
|
3964
|
-
parts.push(wsNumVal("w:marRight", d.marginRight));
|
|
3965
|
-
parts.push(wsNumVal("w:marTop", d.marginTop));
|
|
3966
|
-
parts.push(wsNumVal("w:marBottom", d.marginBottom));
|
|
3967
|
-
if (d.border) parts.push(wsDivBorderXml(d.border));
|
|
3968
|
-
if (d.children?.length) {
|
|
3969
|
-
parts.push("<w:divsChild>");
|
|
3970
|
-
for (const child of d.children) parts.push(wsDivXml(child));
|
|
3971
|
-
parts.push("</w:divsChild>");
|
|
3972
|
-
}
|
|
3973
|
-
parts.push("</w:div>");
|
|
3974
|
-
return parts.join("");
|
|
3975
|
-
}
|
|
3976
|
-
function framesetXml(fs) {
|
|
3977
|
-
const parts = ["<w:frameset>"];
|
|
3978
|
-
if (fs.size !== void 0) parts.push(wsStringVal("w:sz", fs.size));
|
|
3979
|
-
if (fs.splitbar) {
|
|
3980
|
-
parts.push("<w:framesetSplitbar>");
|
|
3981
|
-
if (fs.splitbar.width !== void 0) parts.push(`<w:w w:w="${fs.splitbar.width}" w:type="dxa"/>`);
|
|
3982
|
-
if (fs.splitbar.color !== void 0) parts.push(wsStringVal("w:color", fs.splitbar.color));
|
|
3983
|
-
if (fs.splitbar.noBorder) parts.push("<w:noBorder/>");
|
|
3984
|
-
if (fs.splitbar.flatBorders) parts.push("<w:flatBorders/>");
|
|
3985
|
-
parts.push("</w:framesetSplitbar>");
|
|
3986
|
-
}
|
|
3987
|
-
if (fs.layout !== void 0) parts.push(`<w:frameLayout w:val="${fs.layout}"/>`);
|
|
3988
|
-
if (fs.title !== void 0) parts.push(wsStringVal("w:title", fs.title));
|
|
3989
|
-
if (fs.children) for (const child of fs.children) if ("children" in child || "layout" in child || "splitbar" in child) parts.push(framesetXml(child));
|
|
3990
|
-
else parts.push(frameXml(child));
|
|
3991
|
-
parts.push("</w:frameset>");
|
|
3992
|
-
return parts.join("");
|
|
3993
|
-
}
|
|
3994
|
-
function frameXml(f) {
|
|
3995
|
-
const parts = ["<w:frame>"];
|
|
3996
|
-
if (f.size !== void 0) parts.push(wsStringVal("w:sz", f.size));
|
|
3997
|
-
if (f.name !== void 0) parts.push(wsStringVal("w:name", f.name));
|
|
3998
|
-
if (f.title !== void 0) parts.push(wsStringVal("w:title", f.title));
|
|
3999
|
-
if (f.sourceRId !== void 0) parts.push(`<w:sourceFileName r:id="${escapeXml(f.sourceRId)}"/>`);
|
|
4000
|
-
if (f.marginWidth !== void 0) parts.push(wsNumVal("w:marW", f.marginWidth));
|
|
4001
|
-
if (f.marginHeight !== void 0) parts.push(wsNumVal("w:marH", f.marginHeight));
|
|
4002
|
-
if (f.scrollbar !== void 0) parts.push(`<w:scrollbar w:val="${f.scrollbar}"/>`);
|
|
4003
|
-
if (f.noResizeAllowed) parts.push("<w:noResizeAllowed/>");
|
|
4004
|
-
if (f.linkedToFile) parts.push("<w:linkedToFile/>");
|
|
4005
|
-
if (f.longDescRId !== void 0) parts.push(`<w:longDesc r:id="${escapeXml(f.longDescRId)}"/>`);
|
|
4006
|
-
parts.push("</w:frame>");
|
|
4007
|
-
return parts.join("");
|
|
4008
|
-
}
|
|
4009
|
-
const webSettingsDesc = {
|
|
4010
|
-
kind: "custom",
|
|
4011
|
-
stringify(opts, _ctx) {
|
|
4012
|
-
const p = [`<w:webSettings ${WS_NS}>`];
|
|
4013
|
-
if (opts.frameset !== void 0) p.push(framesetXml(opts.frameset));
|
|
4014
|
-
if (opts.divs?.length) {
|
|
4015
|
-
p.push("<w:divs>");
|
|
4016
|
-
for (const d of opts.divs) p.push(wsDivXml(d));
|
|
4017
|
-
p.push("</w:divs>");
|
|
4018
|
-
}
|
|
4019
|
-
if (opts.encoding !== void 0) p.push(wsStringVal("w:encoding", opts.encoding));
|
|
4020
|
-
if (opts.optimizeForBrowser !== void 0) {
|
|
4021
|
-
const ob = opts.optimizeForBrowser;
|
|
4022
|
-
if (typeof ob === "boolean") p.push(wsOnOff("w:optimizeForBrowser", ob));
|
|
4023
|
-
else {
|
|
4024
|
-
const valAttr = ob.value === false ? " w:val=\"false\"" : "";
|
|
4025
|
-
const targetAttr = ob.target ? ` w:target="${escapeXml(ob.target)}"` : "";
|
|
4026
|
-
p.push(`<w:optimizeForBrowser${valAttr}${targetAttr}/>`);
|
|
4027
|
-
}
|
|
4028
|
-
}
|
|
4029
|
-
if (opts.relyOnVML !== void 0) p.push(wsOnOff("w:relyOnVML", opts.relyOnVML));
|
|
4030
|
-
if (opts.allowPNG !== void 0) p.push(wsOnOff("w:allowPNG", opts.allowPNG));
|
|
4031
|
-
if (opts.doNotRelyOnCSS !== void 0) p.push(wsOnOff("w:doNotRelyOnCSS", opts.doNotRelyOnCSS));
|
|
4032
|
-
if (opts.doNotSaveAsSingleFile !== void 0) p.push(wsOnOff("w:doNotSaveAsSingleFile", opts.doNotSaveAsSingleFile));
|
|
4033
|
-
if (opts.doNotOrganizeInFolder !== void 0) p.push(wsOnOff("w:doNotOrganizeInFolder", opts.doNotOrganizeInFolder));
|
|
4034
|
-
if (opts.doNotUseLongFileNames !== void 0) p.push(wsOnOff("w:doNotUseLongFileNames", opts.doNotUseLongFileNames));
|
|
4035
|
-
if (opts.pixelsPerInch !== void 0) p.push(wsNumVal("w:pixelsPerInch", opts.pixelsPerInch));
|
|
4036
|
-
if (opts.targetScreenSize !== void 0) p.push(wsStringVal("w:targetScreenSz", opts.targetScreenSize));
|
|
4037
|
-
if (opts.saveSmartTagsAsXml !== void 0) p.push(wsOnOff("w:saveSmartTagsAsXml", opts.saveSmartTagsAsXml));
|
|
4038
|
-
p.push("</w:webSettings>");
|
|
4039
|
-
return p.join("");
|
|
4040
|
-
},
|
|
4041
|
-
parse(el, _ctx) {
|
|
4042
|
-
const opts = {};
|
|
4043
|
-
const frameset = findChild(el, "w:frameset");
|
|
4044
|
-
if (frameset) opts.frameset = parseFramesetEl(frameset);
|
|
4045
|
-
const divs = findChild(el, "w:divs");
|
|
4046
|
-
if (divs) {
|
|
4047
|
-
const parsed = parseDivsEl(divs);
|
|
4048
|
-
if (parsed.length > 0) opts.divs = parsed;
|
|
4049
|
-
}
|
|
4050
|
-
const encoding = findChild(el, "w:encoding");
|
|
4051
|
-
if (encoding) {
|
|
4052
|
-
const val = attr(encoding, "w:val");
|
|
4053
|
-
if (val) opts.encoding = val;
|
|
4054
|
-
}
|
|
4055
|
-
for (const [name, optKey] of [
|
|
4056
|
-
["w:relyOnVML", "relyOnVML"],
|
|
4057
|
-
["w:allowPNG", "allowPNG"],
|
|
4058
|
-
["w:doNotRelyOnCSS", "doNotRelyOnCSS"],
|
|
4059
|
-
["w:doNotSaveAsSingleFile", "doNotSaveAsSingleFile"],
|
|
4060
|
-
["w:doNotOrganizeInFolder", "doNotOrganizeInFolder"],
|
|
4061
|
-
["w:doNotUseLongFileNames", "doNotUseLongFileNames"],
|
|
4062
|
-
["w:saveSmartTagsAsXml", "saveSmartTagsAsXml"]
|
|
4063
|
-
]) {
|
|
4064
|
-
const child = findChild(el, name);
|
|
4065
|
-
if (child) opts[optKey] = attrBool(child, "w:val") ?? true;
|
|
4066
|
-
}
|
|
4067
|
-
const obEl = findChild(el, "w:optimizeForBrowser");
|
|
4068
|
-
if (obEl) {
|
|
4069
|
-
const target = attr(obEl, "w:target");
|
|
4070
|
-
if (target) opts.optimizeForBrowser = {
|
|
4071
|
-
value: attrBool(obEl, "w:val") ?? true,
|
|
4072
|
-
target
|
|
4073
|
-
};
|
|
4074
|
-
else opts.optimizeForBrowser = attrBool(obEl, "w:val") ?? true;
|
|
4075
|
-
}
|
|
4076
|
-
const ppi = findChild(el, "w:pixelsPerInch");
|
|
4077
|
-
if (ppi) {
|
|
4078
|
-
const val = attrNum(ppi, "w:val");
|
|
4079
|
-
if (val !== void 0) opts.pixelsPerInch = val;
|
|
4080
|
-
}
|
|
4081
|
-
const targetScreenSize = findChild(el, "w:targetScreenSz");
|
|
4082
|
-
if (targetScreenSize) {
|
|
4083
|
-
const val = attr(targetScreenSize, "w:val");
|
|
4084
|
-
if (val) opts.targetScreenSize = val;
|
|
4085
|
-
}
|
|
4086
|
-
return opts;
|
|
4087
|
-
}
|
|
4088
|
-
};
|
|
4089
|
-
//#endregion
|
|
4090
|
-
//#region src/parts/styles/external-styles-factory.ts
|
|
4091
|
-
/**
|
|
4092
|
-
* External styles factory module for WordprocessingML documents.
|
|
4093
|
-
*
|
|
4094
|
-
* Parses styles from external XML and returns raw XML strings.
|
|
4095
|
-
* No XmlComponent dependency.
|
|
4096
|
-
*
|
|
4097
|
-
* Reference: http://officeopenxml.com/WPstyles.php
|
|
4098
|
-
*
|
|
4099
|
-
* @module
|
|
4100
|
-
*/
|
|
4101
|
-
/**
|
|
4102
|
-
* Factory for creating styles from external XML sources.
|
|
4103
|
-
*
|
|
4104
|
-
* Parses styles from XML (typically from a styles.xml file)
|
|
4105
|
-
* and returns raw XML strings for each style element.
|
|
4106
|
-
*/
|
|
4107
|
-
var ExternalStylesFactory = class {
|
|
4108
|
-
/**
|
|
4109
|
-
* Creates new Styles based on the given XML data.
|
|
4110
|
-
*
|
|
4111
|
-
* Parses the styles XML and converts each child to a raw XML string.
|
|
4112
|
-
*/
|
|
4113
|
-
newInstance(xmlData) {
|
|
4114
|
-
const xmlObj = xml2js(xmlData, { compact: false });
|
|
4115
|
-
let stylesXmlElement;
|
|
4116
|
-
for (const xmlElm of xmlObj.elements || []) if (xmlElm.name === "w:styles") stylesXmlElement = xmlElm;
|
|
4117
|
-
if (stylesXmlElement === void 0) return {
|
|
4118
|
-
importedStyles: [],
|
|
4119
|
-
initialAttributes: {}
|
|
4120
|
-
};
|
|
4121
|
-
return {
|
|
4122
|
-
importedStyles: (stylesXmlElement.elements || []).map((childElm) => ({ _raw: js2xml({ elements: [childElm] }) })),
|
|
4123
|
-
initialAttributes: stylesXmlElement.attributes ?? {}
|
|
4124
|
-
};
|
|
4125
|
-
}
|
|
4126
|
-
};
|
|
4127
|
-
//#endregion
|
|
4128
|
-
//#region src/shared/embeddings/embeddings.ts
|
|
4129
|
-
/**
|
|
4130
|
-
* Collects OLE embeddings allocated during document generation. Each embedding
|
|
4131
|
-
* is stored under a sequential `oleObjectN.bin` name in word/embeddings/,
|
|
4132
|
-
* mirroring MS Office's numbering so output is deterministic and diffable.
|
|
4133
|
-
*/
|
|
4134
|
-
var EmbeddingCollection = class {
|
|
4135
|
-
map = /* @__PURE__ */ new Map();
|
|
4136
|
-
counter = 0;
|
|
4137
|
-
/** Allocate the next sequential embedding file name (oleObject1.bin, …). */
|
|
4138
|
-
nextEmbeddingName() {
|
|
4139
|
-
return `oleObject${++this.counter}.bin`;
|
|
4140
|
-
}
|
|
4141
|
-
/** Register an embedding under a unique key. */
|
|
4142
|
-
addEmbedding(key, data) {
|
|
4143
|
-
this.map.set(key, data);
|
|
4144
|
-
}
|
|
4145
|
-
/** All registered embeddings in insertion order. */
|
|
4146
|
-
get array() {
|
|
4147
|
-
return [...this.map.values()];
|
|
4148
|
-
}
|
|
4149
|
-
};
|
|
4150
|
-
//#endregion
|
|
4151
|
-
//#region src/context.ts
|
|
4152
|
-
/**
|
|
4153
|
-
* DOCX compilation context.
|
|
4154
|
-
*
|
|
4155
|
-
* DocxWriteContext holds all mutable state needed during document compilation.
|
|
4156
|
-
* generateDocument() creates a DocxWriteContext internally.
|
|
4157
|
-
*
|
|
4158
|
-
* @module
|
|
4159
|
-
*/
|
|
4160
|
-
/** User styles override factory defaults with the same styleId; keep the rest. */
|
|
4161
|
-
function mergeById(factoryStyles, userStyles) {
|
|
4162
|
-
const factory = factoryStyles ?? [];
|
|
4163
|
-
if (!userStyles || userStyles.length === 0) return factory;
|
|
4164
|
-
const userIds = new Set(userStyles.map((s) => s.id));
|
|
4165
|
-
return [...factory.filter((s) => !userIds.has(s.id)), ...userStyles];
|
|
4166
|
-
}
|
|
4167
|
-
/**
|
|
4168
|
-
* Highest comment id in an explicit comments list, or -1 when there are none.
|
|
4169
|
-
* Seeds the comment id allocator so auto-allocated ids never collide with ids
|
|
4170
|
-
* the caller already assigned (e.g. round-tripped from an existing document).
|
|
4171
|
-
*/
|
|
4172
|
-
function maxCommentId(comments) {
|
|
4173
|
-
let max = -1;
|
|
4174
|
-
if (comments) {
|
|
4175
|
-
for (const c of comments) if (c.id > max) max = c.id;
|
|
4176
|
-
}
|
|
4177
|
-
return max;
|
|
4178
|
-
}
|
|
4179
|
-
/** Narrows an object to a `{ id: number }` marker without an `as` cast. */
|
|
4180
|
-
function isNumericIdMarker(value) {
|
|
4181
|
-
return typeof value === "object" && value !== null && "id" in value && typeof value.id === "number";
|
|
4182
|
-
}
|
|
4183
|
-
/**
|
|
4184
|
-
* Highest w:id among explicit bookmark + move-range start markers (`range`) and
|
|
4185
|
-
* explicit movedFrom/movedTo runs (`moveRun`) anywhere in the body tree
|
|
4186
|
-
* (paragraphs, tables, textboxes, SDTs, headers/footers nested in sections).
|
|
4187
|
-
* Seeds the markup id allocators so `{ bookmark }` / `{ moveFrom }` / `{ moveTo }`
|
|
4188
|
-
* sugars never collide with ids the caller already assigned. Comment ids live in
|
|
4189
|
-
* their own namespace (comments.nextId) and are intentionally excluded.
|
|
4190
|
-
*/
|
|
4191
|
-
function collectMaxMarkupIds(value, acc) {
|
|
4192
|
-
if (value === null || value === void 0 || typeof value !== "object") return;
|
|
4193
|
-
if (value instanceof Uint8Array || value instanceof Date) return;
|
|
4194
|
-
if (Array.isArray(value)) {
|
|
4195
|
-
for (const item of value) collectMaxMarkupIds(item, acc);
|
|
4196
|
-
return;
|
|
4197
|
-
}
|
|
4198
|
-
const obj = value;
|
|
4199
|
-
const rangeMarker = obj.bookmarkStart ?? obj.moveFromRangeStart ?? obj.moveToRangeStart;
|
|
4200
|
-
if (isNumericIdMarker(rangeMarker) && rangeMarker.id > acc.range) acc.range = rangeMarker.id;
|
|
4201
|
-
const moveRun = obj.movedFrom ?? obj.movedTo;
|
|
4202
|
-
if (isNumericIdMarker(moveRun) && moveRun.id > acc.moveRun) acc.moveRun = moveRun.id;
|
|
4203
|
-
for (const key of Object.keys(obj)) collectMaxMarkupIds(obj[key], acc);
|
|
4204
|
-
}
|
|
4205
|
-
/**
|
|
4206
|
-
* Whether any `{ comment }` sugar child appears anywhere in the body tree
|
|
4207
|
-
* (paragraphs, tables, textboxes, SDTs, headers/footers nested in sections).
|
|
4208
|
-
* The document→comments relationship must exist whenever comments.xml will be
|
|
4209
|
-
* generated; since sugar entries are registered during stringify — after the
|
|
4210
|
-
* constructor wires relationships — this pre-scan predicts them so the part and
|
|
4211
|
-
* its relationship stay in sync (OPC consistency). Every `{ comment }` always
|
|
4212
|
-
* stringifies, so the prediction matches the entries actually registered.
|
|
4213
|
-
*/
|
|
4214
|
-
function bodyContainsCommentSugar(value) {
|
|
4215
|
-
if (value === null || value === void 0) return false;
|
|
4216
|
-
if (typeof value !== "object") return false;
|
|
4217
|
-
if (value instanceof Uint8Array || value instanceof Date) return false;
|
|
4218
|
-
if (Array.isArray(value)) {
|
|
4219
|
-
for (const item of value) if (bodyContainsCommentSugar(item)) return true;
|
|
4220
|
-
return false;
|
|
4221
|
-
}
|
|
4222
|
-
const obj = value;
|
|
4223
|
-
if (typeof obj.comment === "object" && obj.comment !== null) return true;
|
|
4224
|
-
for (const key of Object.keys(obj)) if (bodyContainsCommentSugar(obj[key])) return true;
|
|
4225
|
-
return false;
|
|
4226
|
-
}
|
|
4227
|
-
var DocxWriteContext = class {
|
|
4228
|
-
_currentRelationshipId = 1;
|
|
4229
|
-
_sectionProperties = [];
|
|
4230
|
-
get sectionProperties() {
|
|
4231
|
-
return this._sectionProperties;
|
|
4232
|
-
}
|
|
4233
|
-
_hasFootnotes;
|
|
4234
|
-
_hasEndnotes;
|
|
4235
|
-
_hasNumbering;
|
|
4236
|
-
get hasFootnotes() {
|
|
4237
|
-
return this._hasFootnotes;
|
|
4238
|
-
}
|
|
4239
|
-
get hasEndnotes() {
|
|
4240
|
-
return this._hasEndnotes;
|
|
4241
|
-
}
|
|
4242
|
-
get hasNumbering() {
|
|
4243
|
-
return this._hasNumbering;
|
|
4244
|
-
}
|
|
4245
|
-
addRelationship(_type, _target, _mode) {
|
|
4246
|
-
return `rId${this._currentRelationshipId++}`;
|
|
4247
|
-
}
|
|
4248
|
-
addMedia(data, type) {
|
|
4249
|
-
return `{${this.media.addMedia(data, type, (fileName) => ({
|
|
4250
|
-
data,
|
|
4251
|
-
fileName,
|
|
4252
|
-
type,
|
|
4253
|
-
transformation: {
|
|
4254
|
-
pixels: {
|
|
4255
|
-
x: 0,
|
|
4256
|
-
y: 0
|
|
4257
|
-
},
|
|
4258
|
-
emus: {
|
|
4259
|
-
x: 0,
|
|
4260
|
-
y: 0
|
|
4261
|
-
}
|
|
4262
|
-
}
|
|
4263
|
-
})).fileName}}`;
|
|
4264
|
-
}
|
|
4265
|
-
_headers = [];
|
|
4266
|
-
_footers = [];
|
|
4267
|
-
constructor(options) {
|
|
4268
|
-
this._options = options;
|
|
4269
|
-
this.numbering = new Numbering(options.numbering ? options.numbering : { config: [] });
|
|
4270
|
-
this.comments = {
|
|
4271
|
-
relationships: new Relationships(),
|
|
4272
|
-
entries: [],
|
|
4273
|
-
nextId: maxCommentId(options.comments?.children) + 1
|
|
4274
|
-
};
|
|
4275
|
-
const markupSeed = {
|
|
4276
|
-
range: -1,
|
|
4277
|
-
moveRun: -1
|
|
4278
|
-
};
|
|
4279
|
-
collectMaxMarkupIds(options.sections, markupSeed);
|
|
4280
|
-
this.markupIds = {
|
|
4281
|
-
rangeNext: markupSeed.range + 1,
|
|
4282
|
-
moveRunNext: markupSeed.moveRun + 1
|
|
4283
|
-
};
|
|
4284
|
-
this.fileRelationships = new Relationships();
|
|
4285
|
-
this.footNotes = {
|
|
4286
|
-
relationships: new Relationships(),
|
|
4287
|
-
notes: /* @__PURE__ */ new Map()
|
|
4288
|
-
};
|
|
4289
|
-
this.endnotes = {
|
|
4290
|
-
relationships: new Relationships(),
|
|
4291
|
-
notes: /* @__PURE__ */ new Map()
|
|
4292
|
-
};
|
|
4293
|
-
this.document = { relationships: new Relationships() };
|
|
4294
|
-
this._settingsOptions = {
|
|
4295
|
-
compatibility: options.compatibility,
|
|
4296
|
-
compatibilityModeVersion: options.compatabilityModeVersion,
|
|
4297
|
-
defaultTabStop: options.defaultTabStop,
|
|
4298
|
-
evenAndOddHeaders: options.evenAndOddHeaderAndFooters || void 0,
|
|
4299
|
-
characterSpacingControl: options.characterSpacingControl,
|
|
4300
|
-
hyphenation: {
|
|
4301
|
-
autoHyphenation: options.hyphenation?.autoHyphenation,
|
|
4302
|
-
consecutiveHyphenLimit: options.hyphenation?.consecutiveHyphenLimit,
|
|
4303
|
-
doNotHyphenateCaps: options.hyphenation?.doNotHyphenateCaps,
|
|
4304
|
-
hyphenationZone: options.hyphenation?.hyphenationZone
|
|
4305
|
-
},
|
|
4306
|
-
trackRevisions: options.features?.trackRevisions,
|
|
4307
|
-
updateFields: options.features?.updateFields,
|
|
4308
|
-
documentProtection: options.features?.documentProtection,
|
|
4309
|
-
view: options.view,
|
|
4310
|
-
zoom: options.zoom,
|
|
4311
|
-
writeProtection: options.writeProtection,
|
|
4312
|
-
displayBackgroundShape: options.displayBackgroundShape ?? (options.background?.image ? true : void 0),
|
|
4313
|
-
embedTrueTypeFonts: options.embedTrueTypeFonts,
|
|
4314
|
-
embedSystemFonts: options.embedSystemFonts,
|
|
4315
|
-
saveSubsetFonts: options.saveSubsetFonts,
|
|
4316
|
-
docVars: options.docVars,
|
|
4317
|
-
colorSchemeMapping: options.colorSchemeMapping,
|
|
4318
|
-
mailMerge: options.mailMerge,
|
|
4319
|
-
...options.settings
|
|
4320
|
-
};
|
|
4321
|
-
this.media = new Media();
|
|
4322
|
-
this.charts = new ChartCollection();
|
|
4323
|
-
this.smartArts = new SmartArtCollection();
|
|
4324
|
-
this.embeddings = new EmbeddingCollection();
|
|
4325
|
-
this.altChunks = new AltChunkCollection();
|
|
4326
|
-
this.subDocs = new SubDocCollection();
|
|
4327
|
-
if (options.externalStyles !== void 0) {
|
|
4328
|
-
const externalStyles = new ExternalStylesFactory().newInstance(options.externalStyles);
|
|
4329
|
-
const defaultStyles = new DefaultStylesFactory().newInstance(options.styles?.default ?? {});
|
|
4330
|
-
const externalIds = /* @__PURE__ */ new Set();
|
|
4331
|
-
for (const s of externalStyles.importedStyles ?? []) {
|
|
4332
|
-
const id = extractStyleId(s._raw);
|
|
4333
|
-
if (id) externalIds.add(id);
|
|
4334
|
-
}
|
|
4335
|
-
const notInExternal = (arr) => (arr ?? []).filter((s) => !externalIds.has(s.id));
|
|
4336
|
-
this.styles = new Styles({
|
|
4337
|
-
importedStyles: externalStyles.importedStyles,
|
|
4338
|
-
initialAttributes: externalStyles.initialAttributes ?? defaultStyles.initialAttributes,
|
|
4339
|
-
paragraphStyles: notInExternal(defaultStyles.paragraphStyles),
|
|
4340
|
-
characterStyles: notInExternal(defaultStyles.characterStyles),
|
|
4341
|
-
tableStyles: notInExternal(defaultStyles.tableStyles),
|
|
4342
|
-
numberingStyles: notInExternal(defaultStyles.numberingStyles)
|
|
4343
|
-
});
|
|
4344
|
-
} else if (options.styles) {
|
|
4345
|
-
const s = options.styles;
|
|
4346
|
-
if (s.roundTripped) {
|
|
4347
|
-
const f = new DefaultStylesFactory().newInstance({});
|
|
4348
|
-
const docDefaults = s.default?.document !== void 0 ? stringifyDocDefaults(s.default.document, false) : s.docDefaultsXml ?? f.importedStyles?.[0]?._raw ?? "";
|
|
4349
|
-
const latentStyles = s.latentStylesXml ?? f.importedStyles?.[1]?._raw ?? "";
|
|
4350
|
-
this.styles = new Styles({
|
|
4351
|
-
importedStyles: [{ _raw: docDefaults }, { _raw: latentStyles }],
|
|
4352
|
-
initialAttributes: s.initialAttributes ?? f.initialAttributes,
|
|
4353
|
-
paragraphStyles: s.paragraphStyles,
|
|
4354
|
-
characterStyles: s.characterStyles,
|
|
4355
|
-
tableStyles: s.tableStyles,
|
|
4356
|
-
numberingStyles: s.numberingStyles
|
|
4357
|
-
});
|
|
4358
|
-
} else {
|
|
4359
|
-
const f = new DefaultStylesFactory().newInstance(s.default);
|
|
4360
|
-
this.styles = new Styles({
|
|
4361
|
-
importedStyles: f.importedStyles,
|
|
4362
|
-
initialAttributes: s.initialAttributes ?? f.initialAttributes,
|
|
4363
|
-
paragraphStyles: mergeById(f.paragraphStyles, s.paragraphStyles),
|
|
4364
|
-
characterStyles: mergeById(f.characterStyles, s.characterStyles),
|
|
4365
|
-
tableStyles: mergeById(f.tableStyles, s.tableStyles),
|
|
4366
|
-
numberingStyles: mergeById(f.numberingStyles, s.numberingStyles)
|
|
4367
|
-
});
|
|
4368
|
-
}
|
|
4369
|
-
} else {
|
|
4370
|
-
const stylesFactory = new DefaultStylesFactory();
|
|
4371
|
-
this.styles = new Styles(stylesFactory.newInstance());
|
|
4372
|
-
}
|
|
4373
|
-
if (options.styles?.paragraphStyles) for (const style of options.styles.paragraphStyles) {
|
|
4374
|
-
const num = style.paragraph?.numbering;
|
|
4375
|
-
if (num) this.numbering.createConcreteNumberingInstance(num.reference, num.instance ?? 0);
|
|
4376
|
-
}
|
|
4377
|
-
const sourceOverrides = options.contentTypes?.overrides ?? [];
|
|
4378
|
-
this._hasFootnotes = !options.contentTypes || sourceOverrides.some((o) => o.partName === "/word/footnotes.xml");
|
|
4379
|
-
this._hasEndnotes = !options.contentTypes || sourceOverrides.some((o) => o.partName === "/word/endnotes.xml");
|
|
4380
|
-
this._hasNumbering = !options.contentTypes || sourceOverrides.some((o) => o.partName === "/word/numbering.xml");
|
|
4381
|
-
this.addDefaultRelationships();
|
|
4382
|
-
for (const section of options.sections) this.addSection(section);
|
|
4383
|
-
if (options.footnotes) {
|
|
4384
|
-
for (const key in options.footnotes) {
|
|
4385
|
-
if (key === "separator" || key === "continuationSeparator") continue;
|
|
4386
|
-
const note = options.footnotes[key];
|
|
4387
|
-
if (!note) continue;
|
|
4388
|
-
this.footNotes.notes.set(parseFloat(key), note.children);
|
|
4389
|
-
}
|
|
4390
|
-
this.footNotes.separator = options.footnotes.separator;
|
|
4391
|
-
this.footNotes.continuationSeparator = options.footnotes.continuationSeparator;
|
|
4392
|
-
}
|
|
4393
|
-
if (options.endnotes) {
|
|
4394
|
-
for (const key in options.endnotes) {
|
|
4395
|
-
if (key === "separator" || key === "continuationSeparator") continue;
|
|
4396
|
-
const note = options.endnotes[key];
|
|
4397
|
-
if (!note) continue;
|
|
4398
|
-
this.endnotes.notes.set(parseFloat(key), note.children);
|
|
4399
|
-
}
|
|
4400
|
-
this.endnotes.separator = options.endnotes.separator;
|
|
4401
|
-
this.endnotes.continuationSeparator = options.endnotes.continuationSeparator;
|
|
4402
|
-
}
|
|
4403
|
-
this.fontTable = new FontWrapper(options.fonts ?? []);
|
|
4404
|
-
this.glossaryOptions = options.glossary;
|
|
4405
|
-
this.webSettings = options.webSettings ?? void 0;
|
|
4406
|
-
if (options.glossary) this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/glossaryDocument", "glossary/document.xml");
|
|
4407
|
-
if (this.webSettings) this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings", "webSettings.xml");
|
|
4408
|
-
}
|
|
4409
|
-
get headers() {
|
|
4410
|
-
return this._headers;
|
|
4411
|
-
}
|
|
4412
|
-
get footers() {
|
|
4413
|
-
return this._footers;
|
|
4414
|
-
}
|
|
4415
|
-
addSection({ headers = {}, footers = {}, properties }) {
|
|
4416
|
-
const sectPrOptions = {
|
|
4417
|
-
...properties,
|
|
4418
|
-
footerWrapperGroup: {
|
|
4419
|
-
default: footers.default ? this.createFooter(footers.default) : void 0,
|
|
4420
|
-
even: footers.even ? this.createFooter(footers.even) : void 0,
|
|
4421
|
-
first: footers.first ? this.createFooter(footers.first) : void 0
|
|
4422
|
-
},
|
|
4423
|
-
headerWrapperGroup: {
|
|
4424
|
-
default: headers.default ? this.createHeader(headers.default) : void 0,
|
|
4425
|
-
even: headers.even ? this.createHeader(headers.even) : void 0,
|
|
4426
|
-
first: headers.first ? this.createHeader(headers.first) : void 0
|
|
4427
|
-
}
|
|
4428
|
-
};
|
|
4429
|
-
this._sectionProperties.push(sectPrOptions);
|
|
4430
|
-
}
|
|
4431
|
-
createHeader(header) {
|
|
4432
|
-
const referenceId = this._currentRelationshipId++;
|
|
4433
|
-
const entry = {
|
|
4434
|
-
children: header,
|
|
4435
|
-
relationships: new Relationships(),
|
|
4436
|
-
referenceId
|
|
4437
|
-
};
|
|
4438
|
-
this.addHeaderToDocument(entry);
|
|
4439
|
-
return entry;
|
|
4440
|
-
}
|
|
4441
|
-
createFooter(footer) {
|
|
4442
|
-
const referenceId = this._currentRelationshipId++;
|
|
4443
|
-
const entry = {
|
|
4444
|
-
children: footer,
|
|
4445
|
-
relationships: new Relationships(),
|
|
4446
|
-
referenceId
|
|
4447
|
-
};
|
|
4448
|
-
this.addFooterToDocument(entry);
|
|
4449
|
-
return entry;
|
|
4450
|
-
}
|
|
4451
|
-
addHeaderToDocument(header) {
|
|
4452
|
-
this._headers.push(header);
|
|
4453
|
-
this.document.relationships.addRelationship(header.referenceId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", `header${this._headers.length}.xml`);
|
|
4454
|
-
}
|
|
4455
|
-
addFooterToDocument(footer) {
|
|
4456
|
-
this._footers.push(footer);
|
|
4457
|
-
this.document.relationships.addRelationship(footer.referenceId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", `footer${this._footers.length}.xml`);
|
|
4458
|
-
}
|
|
4459
|
-
addDefaultRelationships() {
|
|
4460
|
-
this.fileRelationships.addRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", "word/document.xml");
|
|
4461
|
-
this.fileRelationships.addRelationship(2, "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties", "docProps/core.xml");
|
|
4462
|
-
this.fileRelationships.addRelationship(3, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties", "docProps/app.xml");
|
|
4463
|
-
this.fileRelationships.addRelationship(4, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties", "docProps/custom.xml");
|
|
4464
|
-
this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml");
|
|
4465
|
-
if (this._hasNumbering) this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", "numbering.xml");
|
|
4466
|
-
if (this._hasFootnotes) this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes", "footnotes.xml");
|
|
4467
|
-
if (this._hasEndnotes) this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes", "endnotes.xml");
|
|
4468
|
-
this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings", "settings.xml");
|
|
4469
|
-
if (this._options.comments?.children?.length || bodyContainsCommentSugar(this._options.sections)) this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments", "comments.xml");
|
|
4470
|
-
if (this._options.bibliography) this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/bibliography", "bibliography.xml");
|
|
4471
|
-
const themePart = this._options.rawParts?.find((p) => p.path.startsWith("word/theme/"));
|
|
4472
|
-
this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme", themePart ? themePart.path.replace(/^word\//, "") : "theme/theme1.xml");
|
|
4473
|
-
for (const part of this._options.rawParts ?? []) if (part.path.startsWith("customXml/") && part.path.endsWith(".xml") && !part.path.includes("/_rels/") && !part.path.includes("itemProps")) this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml", `../${part.path}`);
|
|
4474
|
-
}
|
|
4475
|
-
};
|
|
4476
|
-
/**
|
|
4477
|
-
* DOCX-specific read context.
|
|
4478
|
-
*
|
|
4479
|
-
* Holds references to the parsed DocxDocument and cached style/numbering data
|
|
4480
|
-
* used throughout the DOCX parsing pipeline. Implements ReadContext for
|
|
4481
|
-
* descriptor pipeline compatibility.
|
|
4482
|
-
*/
|
|
4483
|
-
var DocxReadContext = class {
|
|
4484
|
-
docx;
|
|
4485
|
-
styleCache;
|
|
4486
|
-
numberingCache;
|
|
4487
|
-
/**
|
|
4488
|
-
* Path of the part currently being parsed. Each part carries its own .rels
|
|
4489
|
-
* with independent rId numbering, so drawings inside a part must resolve
|
|
4490
|
-
* image relationships against that part's rels. Defaults to the document body.
|
|
4491
|
-
*/
|
|
4492
|
-
currentPart = "word/document.xml";
|
|
4493
|
-
constructor(docx, styleCache, numberingCache) {
|
|
4494
|
-
this.docx = docx;
|
|
4495
|
-
this.styleCache = styleCache;
|
|
4496
|
-
this.numberingCache = numberingCache;
|
|
4497
|
-
}
|
|
4498
|
-
resolveRelationship(rId) {
|
|
4499
|
-
const partMedia = this.docx.partRefs.partMedia.get(this.currentPart);
|
|
4500
|
-
if (partMedia) {
|
|
4501
|
-
const media = partMedia.get(rId);
|
|
4502
|
-
if (media) return media;
|
|
4503
|
-
}
|
|
4504
|
-
return this.docx.partRefs.headers.get(rId) ?? this.docx.partRefs.footers.get(rId) ?? this.docx.partRefs.media.get(rId) ?? this.docx.partRefs.charts.get(rId) ?? this.docx.partRefs.diagramData.get(rId) ?? this.docx.partRefs.afChunks.get(rId) ?? this.docx.partRefs.subDocs.get(rId) ?? this.docx.partRefs.hyperlinks.get(rId);
|
|
4505
|
-
}
|
|
4506
|
-
/**
|
|
4507
|
-
* Run `fn` with `currentPart` temporarily set to `partPath`, restoring the
|
|
4508
|
-
* previous value afterwards. Use when parsing a sub-document part (header,
|
|
4509
|
-
* footer, footnotes, …) so its drawings resolve images from its own rels.
|
|
4510
|
-
*/
|
|
4511
|
-
withPart(partPath, fn) {
|
|
4512
|
-
const prev = this.currentPart;
|
|
4513
|
-
this.currentPart = partPath;
|
|
4514
|
-
try {
|
|
4515
|
-
return fn();
|
|
4516
|
-
} finally {
|
|
4517
|
-
this.currentPart = prev;
|
|
4518
|
-
}
|
|
4519
|
-
}
|
|
4520
|
-
getPart(path) {
|
|
4521
|
-
return this.docx.doc.get(path);
|
|
4522
|
-
}
|
|
4523
|
-
getRaw(path) {
|
|
4524
|
-
return this.docx.doc.getRaw(path);
|
|
4525
|
-
}
|
|
4526
|
-
};
|
|
4527
|
-
//#endregion
|
|
4528
|
-
export { parseStyleDefinitions as A, LevelFormat as B, endnotesDesc as C, buildNumberingCache as D, Styles as E, stringifyNumberingStyle as F, AlignmentType as H, stringifyParagraphStyle as I, stringifyTableStyle as L, stringifyCharacterStyle as M, stringifyConditionalTableStyle as N, buildStyleCache as O, stringifyDocDefaults as P, Numbering as R, AltChunkCollection as S, settingsDesc as T, LevelSuffix as V, DocPartType as _, framesetXml as a, fontTableDesc as b, customPropertiesDesc as c, contentTypesDesc as d, ensureCustomPropertiesOverride as f, DocPartGallery as g, DocPartBehavior as h, frameXml as i, DefaultStylesFactory as j, extractStyleId as k, corePropertiesDesc as l, withMediaDefaults as m, DocxWriteContext as n, webSettingsDesc as o, withAltChunkOverrides as p, TargetScreenSize as r, appPropertiesDesc as s, DocxReadContext as t, buildContentTypesFromRegistry as u, glossaryDesc as v, footnotesDesc as w, SubDocCollection as x, bibliographyDesc as y, parseNumberingDefinitions as z };
|
|
4529
|
-
|
|
4530
|
-
//# sourceMappingURL=context-B5k1UabT.mjs.map
|