docxmlater 2.4.0 → 3.0.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/dist/core/Document.d.ts +7 -1
- package/dist/core/Document.d.ts.map +1 -1
- package/dist/core/Document.js +57 -19
- package/dist/core/Document.js.map +1 -1
- package/dist/elements/Hyperlink.d.ts.map +1 -1
- package/dist/elements/Hyperlink.js +3 -1
- package/dist/elements/Hyperlink.js.map +1 -1
- package/dist/formatting/AbstractNumbering.d.ts.map +1 -1
- package/dist/formatting/AbstractNumbering.js +1 -1
- package/dist/formatting/AbstractNumbering.js.map +1 -1
- package/dist/formatting/Style.d.ts +11 -11
- package/dist/formatting/Style.d.ts.map +1 -1
- package/dist/formatting/Style.js +277 -175
- package/dist/formatting/Style.js.map +1 -1
- package/package.json +1 -1
package/dist/formatting/Style.js
CHANGED
|
@@ -55,7 +55,7 @@ class Style {
|
|
|
55
55
|
}
|
|
56
56
|
setUiPriority(priority) {
|
|
57
57
|
if (priority < 0 || priority > 99) {
|
|
58
|
-
throw new Error(
|
|
58
|
+
throw new Error("UI priority must be between 0 and 99");
|
|
59
59
|
}
|
|
60
60
|
this.properties.uiPriority = priority;
|
|
61
61
|
return this;
|
|
@@ -114,7 +114,7 @@ class Style {
|
|
|
114
114
|
this.properties.tableStyle = {};
|
|
115
115
|
}
|
|
116
116
|
if (size < 0) {
|
|
117
|
-
throw new Error(
|
|
117
|
+
throw new Error("Row band size must be non-negative");
|
|
118
118
|
}
|
|
119
119
|
this.properties.tableStyle.rowBandSize = size;
|
|
120
120
|
return this;
|
|
@@ -124,7 +124,7 @@ class Style {
|
|
|
124
124
|
this.properties.tableStyle = {};
|
|
125
125
|
}
|
|
126
126
|
if (size < 0) {
|
|
127
|
-
throw new Error(
|
|
127
|
+
throw new Error("Column band size must be non-negative");
|
|
128
128
|
}
|
|
129
129
|
this.properties.tableStyle.colBandSize = size;
|
|
130
130
|
return this;
|
|
@@ -141,10 +141,17 @@ class Style {
|
|
|
141
141
|
}
|
|
142
142
|
isValid() {
|
|
143
143
|
try {
|
|
144
|
-
if (!this.properties.styleId ||
|
|
144
|
+
if (!this.properties.styleId ||
|
|
145
|
+
!this.properties.name ||
|
|
146
|
+
!this.properties.type) {
|
|
145
147
|
return false;
|
|
146
148
|
}
|
|
147
|
-
const validTypes = [
|
|
149
|
+
const validTypes = [
|
|
150
|
+
"paragraph",
|
|
151
|
+
"character",
|
|
152
|
+
"table",
|
|
153
|
+
"numbering",
|
|
154
|
+
];
|
|
148
155
|
if (!validTypes.includes(this.properties.type)) {
|
|
149
156
|
return false;
|
|
150
157
|
}
|
|
@@ -154,7 +161,14 @@ class Style {
|
|
|
154
161
|
if (this.properties.paragraphFormatting) {
|
|
155
162
|
const pf = this.properties.paragraphFormatting;
|
|
156
163
|
if (pf.alignment) {
|
|
157
|
-
const validAlignments = [
|
|
164
|
+
const validAlignments = [
|
|
165
|
+
"left",
|
|
166
|
+
"center",
|
|
167
|
+
"right",
|
|
168
|
+
"justify",
|
|
169
|
+
"both",
|
|
170
|
+
"distribute",
|
|
171
|
+
];
|
|
158
172
|
if (!validAlignments.includes(pf.alignment)) {
|
|
159
173
|
return false;
|
|
160
174
|
}
|
|
@@ -167,7 +181,8 @@ class Style {
|
|
|
167
181
|
return false;
|
|
168
182
|
if (spacing.line !== undefined && spacing.line < 0)
|
|
169
183
|
return false;
|
|
170
|
-
if (spacing.lineRule &&
|
|
184
|
+
if (spacing.lineRule &&
|
|
185
|
+
!["auto", "exact", "atLeast"].includes(spacing.lineRule)) {
|
|
171
186
|
return false;
|
|
172
187
|
}
|
|
173
188
|
}
|
|
@@ -189,9 +204,23 @@ class Style {
|
|
|
189
204
|
}
|
|
190
205
|
if (rf.highlight) {
|
|
191
206
|
const validHighlights = [
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
207
|
+
"black",
|
|
208
|
+
"blue",
|
|
209
|
+
"cyan",
|
|
210
|
+
"darkBlue",
|
|
211
|
+
"darkCyan",
|
|
212
|
+
"darkGray",
|
|
213
|
+
"darkGreen",
|
|
214
|
+
"darkMagenta",
|
|
215
|
+
"darkRed",
|
|
216
|
+
"darkYellow",
|
|
217
|
+
"green",
|
|
218
|
+
"lightGray",
|
|
219
|
+
"magenta",
|
|
220
|
+
"none",
|
|
221
|
+
"red",
|
|
222
|
+
"white",
|
|
223
|
+
"yellow",
|
|
195
224
|
];
|
|
196
225
|
if (!validHighlights.includes(rf.highlight)) {
|
|
197
226
|
return false;
|
|
@@ -214,54 +243,56 @@ class Style {
|
|
|
214
243
|
}
|
|
215
244
|
toXML() {
|
|
216
245
|
const styleAttrs = {
|
|
217
|
-
|
|
218
|
-
|
|
246
|
+
"w:type": this.properties.type,
|
|
247
|
+
"w:styleId": this.properties.styleId,
|
|
219
248
|
};
|
|
220
249
|
if (this.properties.isDefault) {
|
|
221
|
-
styleAttrs[
|
|
250
|
+
styleAttrs["w:default"] = "1";
|
|
222
251
|
}
|
|
223
252
|
if (this.properties.customStyle) {
|
|
224
|
-
styleAttrs[
|
|
253
|
+
styleAttrs["w:customStyle"] = "1";
|
|
225
254
|
}
|
|
226
255
|
const styleChildren = [];
|
|
227
|
-
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
256
|
+
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf("name", { "w:val": this.properties.name }));
|
|
228
257
|
if (this.properties.basedOn) {
|
|
229
|
-
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
258
|
+
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf("basedOn", { "w:val": this.properties.basedOn }));
|
|
230
259
|
}
|
|
231
260
|
if (this.properties.next) {
|
|
232
|
-
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
261
|
+
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf("next", { "w:val": this.properties.next }));
|
|
233
262
|
}
|
|
234
263
|
if (this.properties.link) {
|
|
235
|
-
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
264
|
+
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf("link", { "w:val": this.properties.link }));
|
|
236
265
|
}
|
|
237
266
|
if (this.properties.autoRedefine) {
|
|
238
|
-
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
267
|
+
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf("autoRedefine"));
|
|
239
268
|
}
|
|
240
269
|
if (this.properties.qFormat !== undefined) {
|
|
241
270
|
if (this.properties.qFormat) {
|
|
242
|
-
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
271
|
+
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf("qFormat"));
|
|
243
272
|
}
|
|
244
273
|
}
|
|
245
274
|
else if (!this.properties.customStyle) {
|
|
246
|
-
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
275
|
+
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf("qFormat"));
|
|
247
276
|
}
|
|
248
277
|
if (this.properties.semiHidden) {
|
|
249
|
-
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
278
|
+
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf("semiHidden"));
|
|
250
279
|
}
|
|
251
280
|
if (this.properties.unhideWhenUsed) {
|
|
252
|
-
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
281
|
+
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf("unhideWhenUsed"));
|
|
253
282
|
}
|
|
254
283
|
if (this.properties.uiPriority !== undefined) {
|
|
255
|
-
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
284
|
+
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf("uiPriority", {
|
|
285
|
+
"w:val": String(this.properties.uiPriority),
|
|
286
|
+
}));
|
|
256
287
|
}
|
|
257
288
|
if (this.properties.locked) {
|
|
258
|
-
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
289
|
+
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf("locked"));
|
|
259
290
|
}
|
|
260
291
|
if (this.properties.personal) {
|
|
261
|
-
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
292
|
+
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf("personal"));
|
|
262
293
|
}
|
|
263
294
|
if (this.properties.aliases) {
|
|
264
|
-
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
295
|
+
styleChildren.push(XMLBuilder_1.XMLBuilder.wSelf("aliases", { "w:val": this.properties.aliases }));
|
|
265
296
|
}
|
|
266
297
|
if (this.properties.paragraphFormatting) {
|
|
267
298
|
const pPr = this.generateParagraphProperties(this.properties.paragraphFormatting);
|
|
@@ -295,7 +326,8 @@ class Style {
|
|
|
295
326
|
}
|
|
296
327
|
}
|
|
297
328
|
if (this.properties.tableStyle.conditionalFormatting) {
|
|
298
|
-
for (const conditional of this.properties.tableStyle
|
|
329
|
+
for (const conditional of this.properties.tableStyle
|
|
330
|
+
.conditionalFormatting) {
|
|
299
331
|
const tblStylePr = this.generateConditionalFormatting(conditional);
|
|
300
332
|
if (tblStylePr.children && tblStylePr.children.length > 0) {
|
|
301
333
|
styleChildren.push(tblStylePr);
|
|
@@ -303,123 +335,129 @@ class Style {
|
|
|
303
335
|
}
|
|
304
336
|
}
|
|
305
337
|
}
|
|
306
|
-
return XMLBuilder_1.XMLBuilder.w(
|
|
338
|
+
return XMLBuilder_1.XMLBuilder.w("style", styleAttrs, styleChildren);
|
|
307
339
|
}
|
|
308
340
|
generateParagraphProperties(formatting) {
|
|
309
341
|
const pPrChildren = [];
|
|
310
342
|
if (formatting.alignment) {
|
|
311
|
-
const alignmentValue = formatting.alignment ===
|
|
312
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
343
|
+
const alignmentValue = formatting.alignment === "justify" ? "both" : formatting.alignment;
|
|
344
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("jc", { "w:val": alignmentValue }));
|
|
313
345
|
}
|
|
314
346
|
if (formatting.indentation) {
|
|
315
347
|
const ind = formatting.indentation;
|
|
316
348
|
const attributes = {};
|
|
317
349
|
if (ind.left !== undefined)
|
|
318
|
-
attributes[
|
|
350
|
+
attributes["w:left"] = ind.left;
|
|
319
351
|
if (ind.right !== undefined)
|
|
320
|
-
attributes[
|
|
352
|
+
attributes["w:right"] = ind.right;
|
|
321
353
|
if (ind.firstLine !== undefined)
|
|
322
|
-
attributes[
|
|
354
|
+
attributes["w:firstLine"] = ind.firstLine;
|
|
323
355
|
if (ind.hanging !== undefined)
|
|
324
|
-
attributes[
|
|
356
|
+
attributes["w:hanging"] = ind.hanging;
|
|
325
357
|
if (Object.keys(attributes).length > 0) {
|
|
326
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
358
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("ind", attributes));
|
|
327
359
|
}
|
|
328
360
|
}
|
|
329
361
|
if (formatting.spacing) {
|
|
330
362
|
const spc = formatting.spacing;
|
|
331
363
|
const attributes = {};
|
|
332
364
|
if (spc.before !== undefined)
|
|
333
|
-
attributes[
|
|
365
|
+
attributes["w:before"] = spc.before;
|
|
334
366
|
if (spc.after !== undefined)
|
|
335
|
-
attributes[
|
|
367
|
+
attributes["w:after"] = spc.after;
|
|
336
368
|
if (spc.line !== undefined)
|
|
337
|
-
attributes[
|
|
369
|
+
attributes["w:line"] = spc.line;
|
|
338
370
|
if (spc.lineRule)
|
|
339
|
-
attributes[
|
|
371
|
+
attributes["w:lineRule"] = spc.lineRule;
|
|
340
372
|
if (Object.keys(attributes).length > 0) {
|
|
341
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
373
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("spacing", attributes));
|
|
342
374
|
}
|
|
343
375
|
}
|
|
344
376
|
if (formatting.keepNext) {
|
|
345
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
377
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("keepNext"));
|
|
346
378
|
}
|
|
347
379
|
if (formatting.keepLines) {
|
|
348
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
380
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("keepLines"));
|
|
349
381
|
}
|
|
350
382
|
if (formatting.pageBreakBefore) {
|
|
351
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
383
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("pageBreakBefore"));
|
|
352
384
|
}
|
|
353
|
-
return XMLBuilder_1.XMLBuilder.w(
|
|
385
|
+
return XMLBuilder_1.XMLBuilder.w("pPr", undefined, pPrChildren);
|
|
354
386
|
}
|
|
355
387
|
generateRunProperties(formatting) {
|
|
356
388
|
const rPrChildren = [];
|
|
357
389
|
if (formatting.bold) {
|
|
358
|
-
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
390
|
+
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("b"));
|
|
359
391
|
}
|
|
360
392
|
if (formatting.italic) {
|
|
361
|
-
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
393
|
+
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("i"));
|
|
362
394
|
}
|
|
363
395
|
if (formatting.underline) {
|
|
364
|
-
const underlineValue = typeof formatting.underline ===
|
|
396
|
+
const underlineValue = typeof formatting.underline === "string"
|
|
365
397
|
? formatting.underline
|
|
366
|
-
:
|
|
367
|
-
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
398
|
+
: "single";
|
|
399
|
+
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("u", { "w:val": underlineValue }));
|
|
368
400
|
}
|
|
369
401
|
if (formatting.strike) {
|
|
370
|
-
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
402
|
+
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("strike"));
|
|
371
403
|
}
|
|
372
404
|
if (formatting.dstrike) {
|
|
373
|
-
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
405
|
+
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("dstrike"));
|
|
374
406
|
}
|
|
375
407
|
if (formatting.subscript) {
|
|
376
|
-
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
408
|
+
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("vertAlign", { "w:val": "subscript" }));
|
|
377
409
|
}
|
|
378
410
|
if (formatting.superscript) {
|
|
379
|
-
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
411
|
+
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("vertAlign", { "w:val": "superscript" }));
|
|
380
412
|
}
|
|
381
413
|
if (formatting.font) {
|
|
382
|
-
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
414
|
+
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("rFonts", {
|
|
415
|
+
"w:ascii": formatting.font,
|
|
416
|
+
"w:hAnsi": formatting.font,
|
|
417
|
+
"w:cs": formatting.font,
|
|
386
418
|
}));
|
|
387
419
|
}
|
|
388
420
|
if (formatting.size !== undefined) {
|
|
389
421
|
const halfPoints = formatting.size * 2;
|
|
390
|
-
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
391
|
-
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
422
|
+
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("sz", { "w:val": halfPoints }));
|
|
423
|
+
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("szCs", { "w:val": halfPoints }));
|
|
392
424
|
}
|
|
393
425
|
if (formatting.color) {
|
|
394
|
-
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
426
|
+
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("color", { "w:val": formatting.color }));
|
|
395
427
|
}
|
|
396
428
|
if (formatting.highlight) {
|
|
397
|
-
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
429
|
+
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("highlight", { "w:val": formatting.highlight }));
|
|
398
430
|
}
|
|
399
431
|
if (formatting.smallCaps) {
|
|
400
|
-
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
432
|
+
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("smallCaps"));
|
|
401
433
|
}
|
|
402
434
|
if (formatting.allCaps) {
|
|
403
|
-
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
435
|
+
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("caps"));
|
|
404
436
|
}
|
|
405
|
-
return XMLBuilder_1.XMLBuilder.w(
|
|
437
|
+
return XMLBuilder_1.XMLBuilder.w("rPr", undefined, rPrChildren);
|
|
406
438
|
}
|
|
407
439
|
generateTableProperties(formatting, tableStyle) {
|
|
408
440
|
const tblPrChildren = [];
|
|
409
|
-
tblPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
441
|
+
tblPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("tblW", { "w:w": "0", "w:type": "auto" }));
|
|
410
442
|
if (formatting.indent !== undefined) {
|
|
411
|
-
tblPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
443
|
+
tblPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("tblInd", {
|
|
444
|
+
"w:w": formatting.indent,
|
|
445
|
+
"w:type": "dxa",
|
|
446
|
+
}));
|
|
412
447
|
}
|
|
413
448
|
if (formatting.alignment) {
|
|
414
|
-
tblPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
449
|
+
tblPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("jc", { "w:val": formatting.alignment }));
|
|
415
450
|
}
|
|
416
451
|
if (formatting.cellSpacing !== undefined) {
|
|
417
|
-
tblPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
452
|
+
tblPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("tblCellSpacing", {
|
|
453
|
+
"w:w": formatting.cellSpacing,
|
|
454
|
+
"w:type": "dxa",
|
|
455
|
+
}));
|
|
418
456
|
}
|
|
419
457
|
if (formatting.borders) {
|
|
420
458
|
const borderElements = this.generateBorderElements(formatting.borders, false);
|
|
421
459
|
if (borderElements.length > 0) {
|
|
422
|
-
tblPrChildren.push(XMLBuilder_1.XMLBuilder.w(
|
|
460
|
+
tblPrChildren.push(XMLBuilder_1.XMLBuilder.w("tblBorders", undefined, borderElements));
|
|
423
461
|
}
|
|
424
462
|
}
|
|
425
463
|
if (formatting.shading) {
|
|
@@ -428,35 +466,51 @@ class Style {
|
|
|
428
466
|
if (formatting.cellMargins) {
|
|
429
467
|
const marginElements = [];
|
|
430
468
|
if (formatting.cellMargins.top !== undefined) {
|
|
431
|
-
marginElements.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
469
|
+
marginElements.push(XMLBuilder_1.XMLBuilder.wSelf("top", {
|
|
470
|
+
"w:w": formatting.cellMargins.top,
|
|
471
|
+
"w:type": "dxa",
|
|
472
|
+
}));
|
|
432
473
|
}
|
|
433
474
|
if (formatting.cellMargins.left !== undefined) {
|
|
434
|
-
marginElements.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
475
|
+
marginElements.push(XMLBuilder_1.XMLBuilder.wSelf("left", {
|
|
476
|
+
"w:w": formatting.cellMargins.left,
|
|
477
|
+
"w:type": "dxa",
|
|
478
|
+
}));
|
|
435
479
|
}
|
|
436
480
|
if (formatting.cellMargins.bottom !== undefined) {
|
|
437
|
-
marginElements.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
481
|
+
marginElements.push(XMLBuilder_1.XMLBuilder.wSelf("bottom", {
|
|
482
|
+
"w:w": formatting.cellMargins.bottom,
|
|
483
|
+
"w:type": "dxa",
|
|
484
|
+
}));
|
|
438
485
|
}
|
|
439
486
|
if (formatting.cellMargins.right !== undefined) {
|
|
440
|
-
marginElements.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
487
|
+
marginElements.push(XMLBuilder_1.XMLBuilder.wSelf("right", {
|
|
488
|
+
"w:w": formatting.cellMargins.right,
|
|
489
|
+
"w:type": "dxa",
|
|
490
|
+
}));
|
|
441
491
|
}
|
|
442
492
|
if (marginElements.length > 0) {
|
|
443
|
-
tblPrChildren.push(XMLBuilder_1.XMLBuilder.w(
|
|
493
|
+
tblPrChildren.push(XMLBuilder_1.XMLBuilder.w("tblCellMar", undefined, marginElements));
|
|
444
494
|
}
|
|
445
495
|
}
|
|
446
496
|
if (tableStyle.rowBandSize !== undefined) {
|
|
447
|
-
tblPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
497
|
+
tblPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("tblStyleRowBandSize", {
|
|
498
|
+
"w:val": tableStyle.rowBandSize,
|
|
499
|
+
}));
|
|
448
500
|
}
|
|
449
501
|
if (tableStyle.colBandSize !== undefined) {
|
|
450
|
-
tblPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
502
|
+
tblPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("tblStyleColBandSize", {
|
|
503
|
+
"w:val": tableStyle.colBandSize,
|
|
504
|
+
}));
|
|
451
505
|
}
|
|
452
|
-
return XMLBuilder_1.XMLBuilder.w(
|
|
506
|
+
return XMLBuilder_1.XMLBuilder.w("tblPr", undefined, tblPrChildren);
|
|
453
507
|
}
|
|
454
508
|
generateTableCellProperties(formatting) {
|
|
455
509
|
const tcPrChildren = [];
|
|
456
510
|
if (formatting.borders) {
|
|
457
511
|
const borderElements = this.generateBorderElements(formatting.borders, true);
|
|
458
512
|
if (borderElements.length > 0) {
|
|
459
|
-
tcPrChildren.push(XMLBuilder_1.XMLBuilder.w(
|
|
513
|
+
tcPrChildren.push(XMLBuilder_1.XMLBuilder.w("tcBorders", undefined, borderElements));
|
|
460
514
|
}
|
|
461
515
|
}
|
|
462
516
|
if (formatting.shading) {
|
|
@@ -465,39 +519,54 @@ class Style {
|
|
|
465
519
|
if (formatting.margins) {
|
|
466
520
|
const marginElements = [];
|
|
467
521
|
if (formatting.margins.top !== undefined) {
|
|
468
|
-
marginElements.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
522
|
+
marginElements.push(XMLBuilder_1.XMLBuilder.wSelf("top", {
|
|
523
|
+
"w:w": formatting.margins.top,
|
|
524
|
+
"w:type": "dxa",
|
|
525
|
+
}));
|
|
469
526
|
}
|
|
470
527
|
if (formatting.margins.left !== undefined) {
|
|
471
|
-
marginElements.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
528
|
+
marginElements.push(XMLBuilder_1.XMLBuilder.wSelf("left", {
|
|
529
|
+
"w:w": formatting.margins.left,
|
|
530
|
+
"w:type": "dxa",
|
|
531
|
+
}));
|
|
472
532
|
}
|
|
473
533
|
if (formatting.margins.bottom !== undefined) {
|
|
474
|
-
marginElements.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
534
|
+
marginElements.push(XMLBuilder_1.XMLBuilder.wSelf("bottom", {
|
|
535
|
+
"w:w": formatting.margins.bottom,
|
|
536
|
+
"w:type": "dxa",
|
|
537
|
+
}));
|
|
475
538
|
}
|
|
476
539
|
if (formatting.margins.right !== undefined) {
|
|
477
|
-
marginElements.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
540
|
+
marginElements.push(XMLBuilder_1.XMLBuilder.wSelf("right", {
|
|
541
|
+
"w:w": formatting.margins.right,
|
|
542
|
+
"w:type": "dxa",
|
|
543
|
+
}));
|
|
478
544
|
}
|
|
479
545
|
if (marginElements.length > 0) {
|
|
480
|
-
tcPrChildren.push(XMLBuilder_1.XMLBuilder.w(
|
|
546
|
+
tcPrChildren.push(XMLBuilder_1.XMLBuilder.w("tcMar", undefined, marginElements));
|
|
481
547
|
}
|
|
482
548
|
}
|
|
483
549
|
if (formatting.verticalAlignment) {
|
|
484
|
-
tcPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
550
|
+
tcPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("vAlign", { "w:val": formatting.verticalAlignment }));
|
|
485
551
|
}
|
|
486
|
-
return XMLBuilder_1.XMLBuilder.w(
|
|
552
|
+
return XMLBuilder_1.XMLBuilder.w("tcPr", undefined, tcPrChildren);
|
|
487
553
|
}
|
|
488
554
|
generateTableRowProperties(formatting) {
|
|
489
555
|
const trPrChildren = [];
|
|
490
556
|
if (formatting.height !== undefined) {
|
|
491
|
-
const heightRule = formatting.heightRule ||
|
|
492
|
-
trPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
557
|
+
const heightRule = formatting.heightRule || "auto";
|
|
558
|
+
trPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("trHeight", {
|
|
559
|
+
"w:val": formatting.height,
|
|
560
|
+
"w:hRule": heightRule,
|
|
561
|
+
}));
|
|
493
562
|
}
|
|
494
563
|
if (formatting.cantSplit) {
|
|
495
|
-
trPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
564
|
+
trPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("cantSplit"));
|
|
496
565
|
}
|
|
497
566
|
if (formatting.isHeader) {
|
|
498
|
-
trPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
567
|
+
trPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("tblHeader"));
|
|
499
568
|
}
|
|
500
|
-
return XMLBuilder_1.XMLBuilder.w(
|
|
569
|
+
return XMLBuilder_1.XMLBuilder.w("trPr", undefined, trPrChildren);
|
|
501
570
|
}
|
|
502
571
|
generateConditionalFormatting(conditional) {
|
|
503
572
|
const tblStylePrChildren = [];
|
|
@@ -531,23 +600,30 @@ class Style {
|
|
|
531
600
|
tblStylePrChildren.push(trPr);
|
|
532
601
|
}
|
|
533
602
|
}
|
|
534
|
-
return XMLBuilder_1.XMLBuilder.w(
|
|
603
|
+
return XMLBuilder_1.XMLBuilder.w("tblStylePr", { "w:type": conditional.type }, tblStylePrChildren);
|
|
535
604
|
}
|
|
536
605
|
generateBorderElements(borders, includeDiagonals) {
|
|
537
606
|
const borderElements = [];
|
|
538
|
-
const borderProps = [
|
|
607
|
+
const borderProps = [
|
|
608
|
+
"top",
|
|
609
|
+
"bottom",
|
|
610
|
+
"left",
|
|
611
|
+
"right",
|
|
612
|
+
"insideH",
|
|
613
|
+
"insideV",
|
|
614
|
+
];
|
|
539
615
|
for (const prop of borderProps) {
|
|
540
616
|
const border = borders[prop];
|
|
541
617
|
if (border) {
|
|
542
618
|
const attrs = {};
|
|
543
619
|
if (border.style)
|
|
544
|
-
attrs[
|
|
620
|
+
attrs["w:val"] = border.style;
|
|
545
621
|
if (border.size !== undefined)
|
|
546
|
-
attrs[
|
|
622
|
+
attrs["w:sz"] = border.size;
|
|
547
623
|
if (border.space !== undefined)
|
|
548
|
-
attrs[
|
|
624
|
+
attrs["w:space"] = border.space;
|
|
549
625
|
if (border.color)
|
|
550
|
-
attrs[
|
|
626
|
+
attrs["w:color"] = border.color;
|
|
551
627
|
if (Object.keys(attrs).length > 0) {
|
|
552
628
|
borderElements.push(XMLBuilder_1.XMLBuilder.wSelf(prop, attrs));
|
|
553
629
|
}
|
|
@@ -558,29 +634,29 @@ class Style {
|
|
|
558
634
|
if (cellBorders.tl2br) {
|
|
559
635
|
const attrs = {};
|
|
560
636
|
if (cellBorders.tl2br.style)
|
|
561
|
-
attrs[
|
|
637
|
+
attrs["w:val"] = cellBorders.tl2br.style;
|
|
562
638
|
if (cellBorders.tl2br.size !== undefined)
|
|
563
|
-
attrs[
|
|
639
|
+
attrs["w:sz"] = cellBorders.tl2br.size;
|
|
564
640
|
if (cellBorders.tl2br.space !== undefined)
|
|
565
|
-
attrs[
|
|
641
|
+
attrs["w:space"] = cellBorders.tl2br.space;
|
|
566
642
|
if (cellBorders.tl2br.color)
|
|
567
|
-
attrs[
|
|
643
|
+
attrs["w:color"] = cellBorders.tl2br.color;
|
|
568
644
|
if (Object.keys(attrs).length > 0) {
|
|
569
|
-
borderElements.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
645
|
+
borderElements.push(XMLBuilder_1.XMLBuilder.wSelf("tl2br", attrs));
|
|
570
646
|
}
|
|
571
647
|
}
|
|
572
648
|
if (cellBorders.tr2bl) {
|
|
573
649
|
const attrs = {};
|
|
574
650
|
if (cellBorders.tr2bl.style)
|
|
575
|
-
attrs[
|
|
651
|
+
attrs["w:val"] = cellBorders.tr2bl.style;
|
|
576
652
|
if (cellBorders.tr2bl.size !== undefined)
|
|
577
|
-
attrs[
|
|
653
|
+
attrs["w:sz"] = cellBorders.tr2bl.size;
|
|
578
654
|
if (cellBorders.tr2bl.space !== undefined)
|
|
579
|
-
attrs[
|
|
655
|
+
attrs["w:space"] = cellBorders.tr2bl.space;
|
|
580
656
|
if (cellBorders.tr2bl.color)
|
|
581
|
-
attrs[
|
|
657
|
+
attrs["w:color"] = cellBorders.tr2bl.color;
|
|
582
658
|
if (Object.keys(attrs).length > 0) {
|
|
583
|
-
borderElements.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
659
|
+
borderElements.push(XMLBuilder_1.XMLBuilder.wSelf("tr2bl", attrs));
|
|
584
660
|
}
|
|
585
661
|
}
|
|
586
662
|
}
|
|
@@ -589,129 +665,151 @@ class Style {
|
|
|
589
665
|
generateShadingElement(shading) {
|
|
590
666
|
const attrs = {};
|
|
591
667
|
if (shading.val)
|
|
592
|
-
attrs[
|
|
668
|
+
attrs["w:val"] = shading.val;
|
|
593
669
|
if (shading.color)
|
|
594
|
-
attrs[
|
|
670
|
+
attrs["w:color"] = shading.color;
|
|
595
671
|
if (shading.fill)
|
|
596
|
-
attrs[
|
|
597
|
-
return XMLBuilder_1.XMLBuilder.wSelf(
|
|
672
|
+
attrs["w:fill"] = shading.fill;
|
|
673
|
+
return XMLBuilder_1.XMLBuilder.wSelf("shd", attrs);
|
|
598
674
|
}
|
|
599
675
|
static create(properties) {
|
|
600
676
|
return new Style(properties);
|
|
601
677
|
}
|
|
602
678
|
static createNormalStyle() {
|
|
603
679
|
return new Style({
|
|
604
|
-
styleId:
|
|
605
|
-
name:
|
|
606
|
-
type:
|
|
680
|
+
styleId: "Normal",
|
|
681
|
+
name: "Normal",
|
|
682
|
+
type: "paragraph",
|
|
607
683
|
isDefault: true,
|
|
608
|
-
next:
|
|
684
|
+
next: "Normal",
|
|
609
685
|
paragraphFormatting: {
|
|
686
|
+
alignment: "left",
|
|
610
687
|
spacing: {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
688
|
+
before: 60,
|
|
689
|
+
after: 60,
|
|
690
|
+
line: 240,
|
|
691
|
+
lineRule: "auto",
|
|
614
692
|
},
|
|
615
693
|
},
|
|
616
694
|
runFormatting: {
|
|
617
|
-
font:
|
|
618
|
-
size:
|
|
695
|
+
font: "Verdana",
|
|
696
|
+
size: 12,
|
|
697
|
+
color: "000000",
|
|
619
698
|
},
|
|
620
699
|
});
|
|
621
700
|
}
|
|
622
701
|
static createHeadingStyle(level) {
|
|
623
702
|
if (level < 1 || level > 9) {
|
|
624
|
-
throw new Error(
|
|
703
|
+
throw new Error("Heading level must be between 1 and 9");
|
|
625
704
|
}
|
|
626
|
-
const sizes = [
|
|
627
|
-
const
|
|
705
|
+
const sizes = [18, 14, 12, 12, 12, 12, 12, 12, 12];
|
|
706
|
+
const spacingBefore = level === 1 ? 0 : level === 2 ? 120 : level === 3 ? 60 : 120;
|
|
707
|
+
const spacingAfter = level === 1 ? 240 : level === 2 ? 120 : level === 3 ? 60 : 120;
|
|
628
708
|
return new Style({
|
|
629
709
|
styleId: `Heading${level}`,
|
|
630
710
|
name: `Heading ${level}`,
|
|
631
|
-
type:
|
|
632
|
-
basedOn:
|
|
633
|
-
next:
|
|
711
|
+
type: "paragraph",
|
|
712
|
+
basedOn: "Normal",
|
|
713
|
+
next: "Normal",
|
|
634
714
|
paragraphFormatting: {
|
|
715
|
+
alignment: "left",
|
|
635
716
|
spacing: {
|
|
636
|
-
before:
|
|
637
|
-
after:
|
|
717
|
+
before: spacingBefore,
|
|
718
|
+
after: spacingAfter,
|
|
719
|
+
line: 240,
|
|
720
|
+
lineRule: "auto",
|
|
638
721
|
},
|
|
639
722
|
keepNext: true,
|
|
640
723
|
keepLines: true,
|
|
641
724
|
},
|
|
642
725
|
runFormatting: {
|
|
643
|
-
font:
|
|
726
|
+
font: "Verdana",
|
|
644
727
|
size: sizes[level - 1],
|
|
645
|
-
bold:
|
|
646
|
-
color:
|
|
728
|
+
bold: true,
|
|
729
|
+
color: "000000",
|
|
647
730
|
},
|
|
648
731
|
});
|
|
649
732
|
}
|
|
650
733
|
static createTitleStyle() {
|
|
651
734
|
return new Style({
|
|
652
|
-
styleId:
|
|
653
|
-
name:
|
|
654
|
-
type:
|
|
655
|
-
basedOn:
|
|
656
|
-
next:
|
|
735
|
+
styleId: "Title",
|
|
736
|
+
name: "Title",
|
|
737
|
+
type: "paragraph",
|
|
738
|
+
basedOn: "Normal",
|
|
739
|
+
next: "Normal",
|
|
657
740
|
paragraphFormatting: {
|
|
658
741
|
spacing: {
|
|
659
742
|
after: 120,
|
|
660
743
|
},
|
|
661
744
|
},
|
|
662
745
|
runFormatting: {
|
|
663
|
-
font:
|
|
746
|
+
font: "Verdana",
|
|
664
747
|
size: 28,
|
|
665
|
-
color:
|
|
748
|
+
color: "000000",
|
|
666
749
|
},
|
|
667
750
|
});
|
|
668
751
|
}
|
|
669
752
|
static createSubtitleStyle() {
|
|
670
753
|
return new Style({
|
|
671
|
-
styleId:
|
|
672
|
-
name:
|
|
673
|
-
type:
|
|
674
|
-
basedOn:
|
|
675
|
-
next:
|
|
754
|
+
styleId: "Subtitle",
|
|
755
|
+
name: "Subtitle",
|
|
756
|
+
type: "paragraph",
|
|
757
|
+
basedOn: "Normal",
|
|
758
|
+
next: "Normal",
|
|
676
759
|
paragraphFormatting: {
|
|
677
760
|
spacing: {
|
|
678
761
|
after: 120,
|
|
679
762
|
},
|
|
680
763
|
},
|
|
681
764
|
runFormatting: {
|
|
682
|
-
font:
|
|
765
|
+
font: "Verdana",
|
|
683
766
|
size: 14,
|
|
684
|
-
color:
|
|
767
|
+
color: "000000",
|
|
685
768
|
italic: true,
|
|
686
769
|
},
|
|
687
770
|
});
|
|
688
771
|
}
|
|
689
772
|
static createListParagraphStyle() {
|
|
690
773
|
return new Style({
|
|
691
|
-
styleId:
|
|
692
|
-
name:
|
|
693
|
-
type:
|
|
694
|
-
basedOn:
|
|
695
|
-
next:
|
|
774
|
+
styleId: "ListParagraph",
|
|
775
|
+
name: "List Paragraph",
|
|
776
|
+
type: "paragraph",
|
|
777
|
+
basedOn: "Normal",
|
|
778
|
+
next: "ListParagraph",
|
|
696
779
|
paragraphFormatting: {
|
|
780
|
+
alignment: "left",
|
|
697
781
|
indentation: {
|
|
698
782
|
left: 720,
|
|
783
|
+
hanging: 360,
|
|
784
|
+
},
|
|
785
|
+
spacing: {
|
|
786
|
+
before: 0,
|
|
787
|
+
after: 60,
|
|
788
|
+
line: 240,
|
|
789
|
+
lineRule: "auto",
|
|
699
790
|
},
|
|
791
|
+
contextualSpacing: true,
|
|
792
|
+
},
|
|
793
|
+
runFormatting: {
|
|
794
|
+
font: "Verdana",
|
|
795
|
+
size: 12,
|
|
796
|
+
bold: true,
|
|
797
|
+
color: "000000",
|
|
700
798
|
},
|
|
701
799
|
});
|
|
702
800
|
}
|
|
703
801
|
static createTOCHeadingStyle() {
|
|
704
802
|
return new Style({
|
|
705
|
-
styleId:
|
|
706
|
-
name:
|
|
707
|
-
type:
|
|
708
|
-
basedOn:
|
|
709
|
-
next:
|
|
803
|
+
styleId: "TOCHeading",
|
|
804
|
+
name: "TOC Heading",
|
|
805
|
+
type: "paragraph",
|
|
806
|
+
basedOn: "Heading1",
|
|
807
|
+
next: "Normal",
|
|
710
808
|
runFormatting: {
|
|
711
809
|
bold: true,
|
|
712
|
-
font:
|
|
810
|
+
font: "Verdana",
|
|
713
811
|
size: 14,
|
|
714
|
-
color:
|
|
812
|
+
color: "000000",
|
|
715
813
|
},
|
|
716
814
|
paragraphFormatting: {
|
|
717
815
|
spacing: {
|
|
@@ -723,10 +821,10 @@ class Style {
|
|
|
723
821
|
}
|
|
724
822
|
static createTableNormalStyle() {
|
|
725
823
|
return new Style({
|
|
726
|
-
styleId:
|
|
727
|
-
name:
|
|
728
|
-
type:
|
|
729
|
-
basedOn:
|
|
824
|
+
styleId: "TableNormal",
|
|
825
|
+
name: "Table Normal",
|
|
826
|
+
type: "table",
|
|
827
|
+
basedOn: "Normal",
|
|
730
828
|
tableStyle: {
|
|
731
829
|
table: {
|
|
732
830
|
cellMargins: {
|
|
@@ -743,19 +841,19 @@ class Style {
|
|
|
743
841
|
}
|
|
744
842
|
static createTableGridStyle() {
|
|
745
843
|
return new Style({
|
|
746
|
-
styleId:
|
|
747
|
-
name:
|
|
748
|
-
type:
|
|
749
|
-
basedOn:
|
|
844
|
+
styleId: "TableGrid",
|
|
845
|
+
name: "Table Grid",
|
|
846
|
+
type: "table",
|
|
847
|
+
basedOn: "TableNormal",
|
|
750
848
|
tableStyle: {
|
|
751
849
|
table: {
|
|
752
850
|
borders: {
|
|
753
|
-
top: { style:
|
|
754
|
-
bottom: { style:
|
|
755
|
-
left: { style:
|
|
756
|
-
right: { style:
|
|
757
|
-
insideH: { style:
|
|
758
|
-
insideV: { style:
|
|
851
|
+
top: { style: "single", size: 4, color: "000000" },
|
|
852
|
+
bottom: { style: "single", size: 4, color: "000000" },
|
|
853
|
+
left: { style: "single", size: 4, color: "000000" },
|
|
854
|
+
right: { style: "single", size: 4, color: "000000" },
|
|
855
|
+
insideH: { style: "single", size: 4, color: "000000" },
|
|
856
|
+
insideV: { style: "single", size: 4, color: "000000" },
|
|
759
857
|
},
|
|
760
858
|
cellMargins: {
|
|
761
859
|
top: 0,
|
|
@@ -780,16 +878,20 @@ class Style {
|
|
|
780
878
|
this.properties.paragraphFormatting = {};
|
|
781
879
|
}
|
|
782
880
|
if (otherProps.paragraphFormatting.alignment) {
|
|
783
|
-
this.properties.paragraphFormatting.alignment =
|
|
881
|
+
this.properties.paragraphFormatting.alignment =
|
|
882
|
+
otherProps.paragraphFormatting.alignment;
|
|
784
883
|
}
|
|
785
884
|
if (otherProps.paragraphFormatting.keepNext !== undefined) {
|
|
786
|
-
this.properties.paragraphFormatting.keepNext =
|
|
885
|
+
this.properties.paragraphFormatting.keepNext =
|
|
886
|
+
otherProps.paragraphFormatting.keepNext;
|
|
787
887
|
}
|
|
788
888
|
if (otherProps.paragraphFormatting.keepLines !== undefined) {
|
|
789
|
-
this.properties.paragraphFormatting.keepLines =
|
|
889
|
+
this.properties.paragraphFormatting.keepLines =
|
|
890
|
+
otherProps.paragraphFormatting.keepLines;
|
|
790
891
|
}
|
|
791
892
|
if (otherProps.paragraphFormatting.pageBreakBefore !== undefined) {
|
|
792
|
-
this.properties.paragraphFormatting.pageBreakBefore =
|
|
893
|
+
this.properties.paragraphFormatting.pageBreakBefore =
|
|
894
|
+
otherProps.paragraphFormatting.pageBreakBefore;
|
|
793
895
|
}
|
|
794
896
|
if (otherProps.paragraphFormatting.indentation) {
|
|
795
897
|
if (!this.properties.paragraphFormatting.indentation) {
|