docxmlater 3.2.0 → 4.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/README.md +85 -54
- package/dist/core/Document.d.ts +4 -7
- package/dist/core/Document.d.ts.map +1 -1
- package/dist/core/Document.js +21 -111
- package/dist/core/Document.js.map +1 -1
- package/dist/core/DocumentParser.d.ts.map +1 -1
- package/dist/core/DocumentParser.js +28 -2
- package/dist/core/DocumentParser.js.map +1 -1
- package/dist/elements/Paragraph.d.ts +31 -27
- package/dist/elements/Paragraph.d.ts.map +1 -1
- package/dist/elements/Paragraph.js +183 -127
- package/dist/elements/Paragraph.js.map +1 -1
- package/dist/elements/Run.d.ts +14 -14
- package/dist/elements/Run.d.ts.map +1 -1
- package/dist/elements/Run.js +137 -133
- package/dist/elements/Run.js.map +1 -1
- package/dist/elements/StructuredDocumentTag.d.ts +10 -7
- package/dist/elements/StructuredDocumentTag.d.ts.map +1 -1
- package/dist/elements/StructuredDocumentTag.js +87 -70
- package/dist/elements/StructuredDocumentTag.js.map +1 -1
- package/dist/elements/Table.d.ts +13 -13
- package/dist/elements/Table.d.ts.map +1 -1
- package/dist/elements/Table.js +61 -51
- package/dist/elements/Table.js.map +1 -1
- package/dist/elements/TableCell.d.ts +9 -6
- package/dist/elements/TableCell.d.ts.map +1 -1
- package/dist/elements/TableCell.js +70 -32
- package/dist/elements/TableCell.js.map +1 -1
- package/dist/formatting/StylesManager.d.ts +21 -1
- package/dist/formatting/StylesManager.d.ts.map +1 -1
- package/dist/formatting/StylesManager.js +187 -74
- package/dist/formatting/StylesManager.js.map +1 -1
- package/dist/types/styleConfig.d.ts +4 -3
- package/dist/types/styleConfig.d.ts.map +1 -1
- package/package.json +3 -2
|
@@ -24,7 +24,7 @@ class Paragraph {
|
|
|
24
24
|
this.formatting = formatting;
|
|
25
25
|
}
|
|
26
26
|
static create(textOrFormatting, formatting) {
|
|
27
|
-
if (typeof textOrFormatting ===
|
|
27
|
+
if (typeof textOrFormatting === "string") {
|
|
28
28
|
const paragraph = new Paragraph(formatting);
|
|
29
29
|
paragraph.addText(textOrFormatting);
|
|
30
30
|
return paragraph;
|
|
@@ -158,8 +158,35 @@ class Paragraph {
|
|
|
158
158
|
getText() {
|
|
159
159
|
return this.content
|
|
160
160
|
.filter((item) => item instanceof Run_1.Run || item instanceof Hyperlink_1.Hyperlink)
|
|
161
|
-
.map(item => item.getText())
|
|
162
|
-
.join(
|
|
161
|
+
.map((item) => item.getText())
|
|
162
|
+
.join("");
|
|
163
|
+
}
|
|
164
|
+
getFields() {
|
|
165
|
+
return this.content.filter((item) => item instanceof Field_1.Field || item instanceof Field_1.ComplexField);
|
|
166
|
+
}
|
|
167
|
+
findFieldsByInstruction(pattern) {
|
|
168
|
+
const regex = typeof pattern === "string" ? new RegExp(pattern, "i") : pattern;
|
|
169
|
+
return this.getFields().filter((field) => {
|
|
170
|
+
const instruction = field.getInstruction();
|
|
171
|
+
return regex.test(instruction);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
removeAllFields() {
|
|
175
|
+
const originalLength = this.content.length;
|
|
176
|
+
this.content = this.content.filter((item) => !(item instanceof Field_1.Field || item instanceof Field_1.ComplexField));
|
|
177
|
+
return originalLength - this.content.length;
|
|
178
|
+
}
|
|
179
|
+
replaceField(oldField, replacement) {
|
|
180
|
+
const index = this.content.indexOf(oldField);
|
|
181
|
+
if (index === -1)
|
|
182
|
+
return false;
|
|
183
|
+
if (typeof replacement === "string") {
|
|
184
|
+
this.content[index] = new Run_1.Run(replacement);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
this.content[index] = replacement;
|
|
188
|
+
}
|
|
189
|
+
return true;
|
|
163
190
|
}
|
|
164
191
|
getFormatting() {
|
|
165
192
|
return { ...this.formatting };
|
|
@@ -213,8 +240,8 @@ class Paragraph {
|
|
|
213
240
|
}
|
|
214
241
|
setLeftIndent(twips) {
|
|
215
242
|
if (this.formatting.numbering) {
|
|
216
|
-
logger_1.defaultLogger.warn(
|
|
217
|
-
|
|
243
|
+
logger_1.defaultLogger.warn("Setting left indentation on a numbered paragraph has no effect. " +
|
|
244
|
+
"Numbering controls indentation. Use different numbering levels to change indent.");
|
|
218
245
|
}
|
|
219
246
|
if (!this.formatting.indentation) {
|
|
220
247
|
this.formatting.indentation = {};
|
|
@@ -231,8 +258,8 @@ class Paragraph {
|
|
|
231
258
|
}
|
|
232
259
|
setFirstLineIndent(twips) {
|
|
233
260
|
if (this.formatting.numbering) {
|
|
234
|
-
logger_1.defaultLogger.warn(
|
|
235
|
-
|
|
261
|
+
logger_1.defaultLogger.warn("Setting first line indentation on a numbered paragraph has no effect. " +
|
|
262
|
+
"Numbering controls indentation using hanging indent.");
|
|
236
263
|
}
|
|
237
264
|
if (!this.formatting.indentation) {
|
|
238
265
|
this.formatting.indentation = {};
|
|
@@ -254,7 +281,7 @@ class Paragraph {
|
|
|
254
281
|
this.formatting.spacing.after = twips;
|
|
255
282
|
return this;
|
|
256
283
|
}
|
|
257
|
-
setLineSpacing(twips, rule =
|
|
284
|
+
setLineSpacing(twips, rule = "auto") {
|
|
258
285
|
if (!this.formatting.spacing) {
|
|
259
286
|
this.formatting.spacing = {};
|
|
260
287
|
}
|
|
@@ -293,10 +320,10 @@ class Paragraph {
|
|
|
293
320
|
}
|
|
294
321
|
setNumbering(numId, level = 0) {
|
|
295
322
|
if (numId < 0) {
|
|
296
|
-
throw new Error(
|
|
323
|
+
throw new Error("Numbering ID must be non-negative");
|
|
297
324
|
}
|
|
298
325
|
if (level < 0 || level > 8) {
|
|
299
|
-
throw new Error(
|
|
326
|
+
throw new Error("Level must be between 0 and 8");
|
|
300
327
|
}
|
|
301
328
|
this.formatting.numbering = { numId, level };
|
|
302
329
|
if (this.formatting.indentation) {
|
|
@@ -314,7 +341,9 @@ class Paragraph {
|
|
|
314
341
|
return this;
|
|
315
342
|
}
|
|
316
343
|
getNumbering() {
|
|
317
|
-
return this.formatting.numbering
|
|
344
|
+
return this.formatting.numbering
|
|
345
|
+
? { ...this.formatting.numbering }
|
|
346
|
+
: undefined;
|
|
318
347
|
}
|
|
319
348
|
setWidowControl(enable = true) {
|
|
320
349
|
this.formatting.widowControl = enable;
|
|
@@ -322,7 +351,7 @@ class Paragraph {
|
|
|
322
351
|
}
|
|
323
352
|
setOutlineLevel(level) {
|
|
324
353
|
if (level < 0 || level > 9) {
|
|
325
|
-
throw new Error(
|
|
354
|
+
throw new Error("Outline level must be between 0 and 9");
|
|
326
355
|
}
|
|
327
356
|
this.formatting.outlineLevel = level;
|
|
328
357
|
return this;
|
|
@@ -403,25 +432,26 @@ class Paragraph {
|
|
|
403
432
|
return !!this.formatting.paragraphMarkDeletion;
|
|
404
433
|
}
|
|
405
434
|
toXML() {
|
|
406
|
-
const runData = this.getRuns().map(run => ({
|
|
435
|
+
const runData = this.getRuns().map((run) => ({
|
|
407
436
|
text: run.getText(),
|
|
408
437
|
rtl: run.getFormatting().rtl,
|
|
409
438
|
}));
|
|
410
|
-
(0, diagnostics_1.logParagraphContent)(
|
|
439
|
+
(0, diagnostics_1.logParagraphContent)("serialization", -1, runData, this.formatting.bidi);
|
|
411
440
|
if (this.formatting.bidi) {
|
|
412
441
|
(0, diagnostics_1.logTextDirection)(`Serializing paragraph with BiDi enabled`);
|
|
413
442
|
}
|
|
414
443
|
const pPrChildren = [];
|
|
415
444
|
if (this.formatting.style) {
|
|
416
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
445
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("pStyle", { "w:val": this.formatting.style }));
|
|
417
446
|
}
|
|
418
|
-
if (this.formatting.paragraphMarkRunProperties ||
|
|
447
|
+
if (this.formatting.paragraphMarkRunProperties ||
|
|
448
|
+
this.formatting.paragraphMarkDeletion) {
|
|
419
449
|
const rPrChildren = [];
|
|
420
450
|
if (this.formatting.paragraphMarkRunProperties) {
|
|
421
451
|
const rPr = Run_1.Run.generateRunPropertiesXML(this.formatting.paragraphMarkRunProperties);
|
|
422
452
|
if (rPr && rPr.children) {
|
|
423
453
|
for (const child of rPr.children) {
|
|
424
|
-
if (typeof child !==
|
|
454
|
+
if (typeof child !== "string") {
|
|
425
455
|
rPrChildren.push(child);
|
|
426
456
|
}
|
|
427
457
|
}
|
|
@@ -429,76 +459,82 @@ class Paragraph {
|
|
|
429
459
|
}
|
|
430
460
|
if (this.formatting.paragraphMarkDeletion) {
|
|
431
461
|
const del = this.formatting.paragraphMarkDeletion;
|
|
432
|
-
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
462
|
+
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("del", {
|
|
463
|
+
"w:id": del.id.toString(),
|
|
464
|
+
"w:author": del.author,
|
|
465
|
+
"w:date": del.date.toISOString(),
|
|
436
466
|
}));
|
|
437
467
|
}
|
|
438
468
|
if (rPrChildren.length > 0) {
|
|
439
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.w(
|
|
469
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.w("rPr", undefined, rPrChildren));
|
|
440
470
|
}
|
|
441
471
|
}
|
|
442
472
|
if (this.formatting.keepNext) {
|
|
443
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
473
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("keepNext"));
|
|
444
474
|
}
|
|
445
475
|
if (this.formatting.keepLines) {
|
|
446
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
476
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("keepLines"));
|
|
447
477
|
}
|
|
448
478
|
if (this.formatting.pageBreakBefore) {
|
|
449
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
479
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("pageBreakBefore"));
|
|
450
480
|
}
|
|
451
481
|
if (this.formatting.widowControl !== undefined) {
|
|
452
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
482
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("widowControl", {
|
|
483
|
+
"w:val": this.formatting.widowControl ? "1" : "0",
|
|
484
|
+
}));
|
|
453
485
|
}
|
|
454
486
|
if (this.formatting.numbering) {
|
|
455
|
-
const numPr = XMLBuilder_1.XMLBuilder.w(
|
|
456
|
-
XMLBuilder_1.XMLBuilder.wSelf(
|
|
457
|
-
|
|
487
|
+
const numPr = XMLBuilder_1.XMLBuilder.w("numPr", undefined, [
|
|
488
|
+
XMLBuilder_1.XMLBuilder.wSelf("ilvl", {
|
|
489
|
+
"w:val": this.formatting.numbering.level.toString(),
|
|
490
|
+
}),
|
|
491
|
+
XMLBuilder_1.XMLBuilder.wSelf("numId", {
|
|
492
|
+
"w:val": this.formatting.numbering.numId.toString(),
|
|
493
|
+
}),
|
|
458
494
|
]);
|
|
459
495
|
pPrChildren.push(numPr);
|
|
460
496
|
}
|
|
461
497
|
if (this.formatting.suppressLineNumbers) {
|
|
462
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
498
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("suppressLineNumbers"));
|
|
463
499
|
}
|
|
464
500
|
if (this.formatting.suppressAutoHyphens) {
|
|
465
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
501
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("suppressAutoHyphens"));
|
|
466
502
|
}
|
|
467
503
|
if (this.formatting.spacing) {
|
|
468
504
|
const spc = this.formatting.spacing;
|
|
469
505
|
const attributes = {};
|
|
470
506
|
if (spc.before !== undefined)
|
|
471
|
-
attributes[
|
|
507
|
+
attributes["w:before"] = spc.before;
|
|
472
508
|
if (spc.after !== undefined)
|
|
473
|
-
attributes[
|
|
509
|
+
attributes["w:after"] = spc.after;
|
|
474
510
|
if (spc.line !== undefined)
|
|
475
|
-
attributes[
|
|
511
|
+
attributes["w:line"] = spc.line;
|
|
476
512
|
if (spc.lineRule)
|
|
477
|
-
attributes[
|
|
513
|
+
attributes["w:lineRule"] = spc.lineRule;
|
|
478
514
|
if (Object.keys(attributes).length > 0) {
|
|
479
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
515
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("spacing", attributes));
|
|
480
516
|
}
|
|
481
517
|
}
|
|
482
518
|
if (this.formatting.contextualSpacing) {
|
|
483
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
519
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("contextualSpacing", { "w:val": "1" }));
|
|
484
520
|
}
|
|
485
521
|
if (this.formatting.indentation) {
|
|
486
522
|
const ind = this.formatting.indentation;
|
|
487
523
|
const attributes = {};
|
|
488
524
|
if (ind.left !== undefined)
|
|
489
|
-
attributes[
|
|
525
|
+
attributes["w:left"] = ind.left;
|
|
490
526
|
if (ind.right !== undefined)
|
|
491
|
-
attributes[
|
|
527
|
+
attributes["w:right"] = ind.right;
|
|
492
528
|
if (ind.firstLine !== undefined)
|
|
493
|
-
attributes[
|
|
529
|
+
attributes["w:firstLine"] = ind.firstLine;
|
|
494
530
|
if (ind.hanging !== undefined)
|
|
495
|
-
attributes[
|
|
531
|
+
attributes["w:hanging"] = ind.hanging;
|
|
496
532
|
if (Object.keys(attributes).length > 0) {
|
|
497
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
533
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("ind", attributes));
|
|
498
534
|
}
|
|
499
535
|
}
|
|
500
536
|
if (this.formatting.mirrorIndents) {
|
|
501
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
537
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("mirrorIndents"));
|
|
502
538
|
}
|
|
503
539
|
if (this.formatting.borders) {
|
|
504
540
|
const borderChildren = [];
|
|
@@ -508,210 +544,222 @@ class Paragraph {
|
|
|
508
544
|
return null;
|
|
509
545
|
const attributes = {};
|
|
510
546
|
if (border.style)
|
|
511
|
-
attributes[
|
|
547
|
+
attributes["w:val"] = border.style;
|
|
512
548
|
if (border.size !== undefined)
|
|
513
|
-
attributes[
|
|
549
|
+
attributes["w:sz"] = border.size;
|
|
514
550
|
if (border.color)
|
|
515
|
-
attributes[
|
|
551
|
+
attributes["w:color"] = border.color;
|
|
516
552
|
if (border.space !== undefined)
|
|
517
|
-
attributes[
|
|
553
|
+
attributes["w:space"] = border.space;
|
|
518
554
|
if (Object.keys(attributes).length > 0) {
|
|
519
555
|
return XMLBuilder_1.XMLBuilder.wSelf(borderType, attributes);
|
|
520
556
|
}
|
|
521
557
|
return null;
|
|
522
558
|
};
|
|
523
|
-
const topBorder = createBorder(
|
|
559
|
+
const topBorder = createBorder("top", borders.top);
|
|
524
560
|
if (topBorder)
|
|
525
561
|
borderChildren.push(topBorder);
|
|
526
|
-
const leftBorder = createBorder(
|
|
562
|
+
const leftBorder = createBorder("left", borders.left);
|
|
527
563
|
if (leftBorder)
|
|
528
564
|
borderChildren.push(leftBorder);
|
|
529
|
-
const bottomBorder = createBorder(
|
|
565
|
+
const bottomBorder = createBorder("bottom", borders.bottom);
|
|
530
566
|
if (bottomBorder)
|
|
531
567
|
borderChildren.push(bottomBorder);
|
|
532
|
-
const rightBorder = createBorder(
|
|
568
|
+
const rightBorder = createBorder("right", borders.right);
|
|
533
569
|
if (rightBorder)
|
|
534
570
|
borderChildren.push(rightBorder);
|
|
535
|
-
const betweenBorder = createBorder(
|
|
571
|
+
const betweenBorder = createBorder("between", borders.between);
|
|
536
572
|
if (betweenBorder)
|
|
537
573
|
borderChildren.push(betweenBorder);
|
|
538
|
-
const barBorder = createBorder(
|
|
574
|
+
const barBorder = createBorder("bar", borders.bar);
|
|
539
575
|
if (barBorder)
|
|
540
576
|
borderChildren.push(barBorder);
|
|
541
577
|
if (borderChildren.length > 0) {
|
|
542
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.w(
|
|
578
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.w("pBdr", undefined, borderChildren));
|
|
543
579
|
}
|
|
544
580
|
}
|
|
545
581
|
if (this.formatting.shading) {
|
|
546
582
|
const shd = this.formatting.shading;
|
|
547
583
|
const attributes = {};
|
|
548
584
|
if (shd.fill)
|
|
549
|
-
attributes[
|
|
585
|
+
attributes["w:fill"] = shd.fill;
|
|
550
586
|
if (shd.color)
|
|
551
|
-
attributes[
|
|
587
|
+
attributes["w:color"] = shd.color;
|
|
552
588
|
if (shd.val)
|
|
553
|
-
attributes[
|
|
589
|
+
attributes["w:val"] = shd.val;
|
|
554
590
|
if (Object.keys(attributes).length > 0) {
|
|
555
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
591
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("shd", attributes));
|
|
556
592
|
}
|
|
557
593
|
}
|
|
558
594
|
if (this.formatting.tabs && this.formatting.tabs.length > 0) {
|
|
559
595
|
const tabChildren = [];
|
|
560
596
|
for (const tab of this.formatting.tabs) {
|
|
561
597
|
const attributes = {};
|
|
562
|
-
attributes[
|
|
598
|
+
attributes["w:pos"] = tab.position;
|
|
563
599
|
if (tab.val)
|
|
564
|
-
attributes[
|
|
600
|
+
attributes["w:val"] = tab.val;
|
|
565
601
|
if (tab.leader)
|
|
566
|
-
attributes[
|
|
567
|
-
tabChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
602
|
+
attributes["w:leader"] = tab.leader;
|
|
603
|
+
tabChildren.push(XMLBuilder_1.XMLBuilder.wSelf("tab", attributes));
|
|
568
604
|
}
|
|
569
605
|
if (tabChildren.length > 0) {
|
|
570
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.w(
|
|
606
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.w("tabs", undefined, tabChildren));
|
|
571
607
|
}
|
|
572
608
|
}
|
|
573
609
|
if (this.formatting.framePr) {
|
|
574
610
|
const attrs = {};
|
|
575
611
|
const f = this.formatting.framePr;
|
|
576
612
|
if (f.w !== undefined)
|
|
577
|
-
attrs[
|
|
613
|
+
attrs["w:w"] = f.w.toString();
|
|
578
614
|
if (f.h !== undefined)
|
|
579
|
-
attrs[
|
|
615
|
+
attrs["w:h"] = f.h.toString();
|
|
580
616
|
if (f.hRule)
|
|
581
|
-
attrs[
|
|
617
|
+
attrs["w:hRule"] = f.hRule;
|
|
582
618
|
if (f.x !== undefined)
|
|
583
|
-
attrs[
|
|
619
|
+
attrs["w:x"] = f.x.toString();
|
|
584
620
|
if (f.y !== undefined)
|
|
585
|
-
attrs[
|
|
621
|
+
attrs["w:y"] = f.y.toString();
|
|
586
622
|
if (f.xAlign)
|
|
587
|
-
attrs[
|
|
623
|
+
attrs["w:xAlign"] = f.xAlign;
|
|
588
624
|
if (f.yAlign)
|
|
589
|
-
attrs[
|
|
625
|
+
attrs["w:yAlign"] = f.yAlign;
|
|
590
626
|
if (f.hAnchor)
|
|
591
|
-
attrs[
|
|
627
|
+
attrs["w:hAnchor"] = f.hAnchor;
|
|
592
628
|
if (f.vAnchor)
|
|
593
|
-
attrs[
|
|
629
|
+
attrs["w:vAnchor"] = f.vAnchor;
|
|
594
630
|
if (f.hSpace !== undefined)
|
|
595
|
-
attrs[
|
|
631
|
+
attrs["w:hSpace"] = f.hSpace.toString();
|
|
596
632
|
if (f.vSpace !== undefined)
|
|
597
|
-
attrs[
|
|
633
|
+
attrs["w:vSpace"] = f.vSpace.toString();
|
|
598
634
|
if (f.wrap)
|
|
599
|
-
attrs[
|
|
635
|
+
attrs["w:wrap"] = f.wrap;
|
|
600
636
|
if (f.dropCap)
|
|
601
|
-
attrs[
|
|
637
|
+
attrs["w:dropCap"] = f.dropCap;
|
|
602
638
|
if (f.lines !== undefined)
|
|
603
|
-
attrs[
|
|
639
|
+
attrs["w:lines"] = f.lines.toString();
|
|
604
640
|
if (f.anchorLock !== undefined)
|
|
605
|
-
attrs[
|
|
641
|
+
attrs["w:anchorLock"] = f.anchorLock ? "1" : "0";
|
|
606
642
|
if (Object.keys(attrs).length > 0) {
|
|
607
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
643
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("framePr", attrs));
|
|
608
644
|
}
|
|
609
645
|
}
|
|
610
646
|
if (this.formatting.suppressOverlap) {
|
|
611
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
647
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("suppressOverlap"));
|
|
612
648
|
}
|
|
613
649
|
if (this.formatting.bidi !== undefined) {
|
|
614
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
650
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("bidi", { "w:val": this.formatting.bidi ? "1" : "0" }));
|
|
615
651
|
}
|
|
616
652
|
if (this.formatting.adjustRightInd !== undefined) {
|
|
617
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
653
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("adjustRightInd", {
|
|
654
|
+
"w:val": this.formatting.adjustRightInd ? "1" : "0",
|
|
655
|
+
}));
|
|
618
656
|
}
|
|
619
657
|
if (this.formatting.textboxTightWrap) {
|
|
620
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
658
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("textboxTightWrap", {
|
|
659
|
+
"w:val": this.formatting.textboxTightWrap,
|
|
660
|
+
}));
|
|
621
661
|
}
|
|
622
662
|
if (this.formatting.alignment) {
|
|
623
|
-
const alignmentValue = this.formatting.alignment ===
|
|
624
|
-
|
|
663
|
+
const alignmentValue = this.formatting.alignment === "justify"
|
|
664
|
+
? "both"
|
|
665
|
+
: this.formatting.alignment;
|
|
666
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("jc", { "w:val": alignmentValue }));
|
|
625
667
|
}
|
|
626
668
|
if (this.formatting.textAlignment) {
|
|
627
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
669
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("textAlignment", {
|
|
670
|
+
"w:val": this.formatting.textAlignment,
|
|
671
|
+
}));
|
|
628
672
|
}
|
|
629
673
|
if (this.formatting.textDirection) {
|
|
630
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
674
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("textDirection", {
|
|
675
|
+
"w:val": this.formatting.textDirection,
|
|
676
|
+
}));
|
|
631
677
|
}
|
|
632
678
|
if (this.formatting.outlineLevel !== undefined) {
|
|
633
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
679
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("outlineLvl", {
|
|
680
|
+
"w:val": this.formatting.outlineLevel.toString(),
|
|
681
|
+
}));
|
|
634
682
|
}
|
|
635
683
|
if (this.formatting.divId !== undefined) {
|
|
636
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
684
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("divId", { "w:val": this.formatting.divId.toString() }));
|
|
637
685
|
}
|
|
638
686
|
if (this.formatting.cnfStyle) {
|
|
639
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
687
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("cnfStyle", { "w:val": this.formatting.cnfStyle }));
|
|
640
688
|
}
|
|
641
689
|
if (this.formatting.pPrChange) {
|
|
642
690
|
const change = this.formatting.pPrChange;
|
|
643
691
|
const attrs = {};
|
|
644
692
|
if (change.author)
|
|
645
|
-
attrs[
|
|
693
|
+
attrs["w:author"] = change.author;
|
|
646
694
|
if (change.date)
|
|
647
|
-
attrs[
|
|
695
|
+
attrs["w:date"] = change.date;
|
|
648
696
|
if (change.id)
|
|
649
|
-
attrs[
|
|
697
|
+
attrs["w:id"] = change.id;
|
|
650
698
|
const prevPPrChildren = [];
|
|
651
699
|
if (change.previousProperties) {
|
|
652
700
|
const prev = change.previousProperties;
|
|
653
701
|
if (prev.style) {
|
|
654
|
-
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
702
|
+
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("pStyle", { "w:val": prev.style }));
|
|
655
703
|
}
|
|
656
704
|
if (prev.keepNext !== undefined) {
|
|
657
|
-
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
705
|
+
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("keepNext", prev.keepNext ? { "w:val": "1" } : { "w:val": "0" }));
|
|
658
706
|
}
|
|
659
707
|
if (prev.keepLines !== undefined) {
|
|
660
|
-
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
708
|
+
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("keepLines", prev.keepLines ? { "w:val": "1" } : { "w:val": "0" }));
|
|
661
709
|
}
|
|
662
710
|
if (prev.pageBreakBefore !== undefined) {
|
|
663
|
-
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
711
|
+
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("pageBreakBefore", prev.pageBreakBefore ? { "w:val": "1" } : { "w:val": "0" }));
|
|
664
712
|
}
|
|
665
713
|
if (prev.alignment) {
|
|
666
|
-
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
714
|
+
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("jc", { "w:val": prev.alignment }));
|
|
667
715
|
}
|
|
668
716
|
if (prev.indentation) {
|
|
669
717
|
const indAttrs = {};
|
|
670
718
|
if (prev.indentation.left !== undefined)
|
|
671
|
-
indAttrs[
|
|
719
|
+
indAttrs["w:left"] = prev.indentation.left.toString();
|
|
672
720
|
if (prev.indentation.right !== undefined)
|
|
673
|
-
indAttrs[
|
|
721
|
+
indAttrs["w:right"] = prev.indentation.right.toString();
|
|
674
722
|
if (prev.indentation.firstLine !== undefined)
|
|
675
|
-
indAttrs[
|
|
723
|
+
indAttrs["w:firstLine"] = prev.indentation.firstLine.toString();
|
|
676
724
|
if (prev.indentation.hanging !== undefined)
|
|
677
|
-
indAttrs[
|
|
678
|
-
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
725
|
+
indAttrs["w:hanging"] = prev.indentation.hanging.toString();
|
|
726
|
+
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("ind", indAttrs));
|
|
679
727
|
}
|
|
680
728
|
if (prev.spacing) {
|
|
681
729
|
const spacingAttrs = {};
|
|
682
730
|
if (prev.spacing.before !== undefined)
|
|
683
|
-
spacingAttrs[
|
|
731
|
+
spacingAttrs["w:before"] = prev.spacing.before.toString();
|
|
684
732
|
if (prev.spacing.after !== undefined)
|
|
685
|
-
spacingAttrs[
|
|
733
|
+
spacingAttrs["w:after"] = prev.spacing.after.toString();
|
|
686
734
|
if (prev.spacing.line !== undefined)
|
|
687
|
-
spacingAttrs[
|
|
735
|
+
spacingAttrs["w:line"] = prev.spacing.line.toString();
|
|
688
736
|
if (prev.spacing.lineRule)
|
|
689
|
-
spacingAttrs[
|
|
737
|
+
spacingAttrs["w:lineRule"] = prev.spacing.lineRule;
|
|
690
738
|
if (Object.keys(spacingAttrs).length > 0) {
|
|
691
|
-
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
739
|
+
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("spacing", spacingAttrs));
|
|
692
740
|
}
|
|
693
741
|
}
|
|
694
742
|
}
|
|
695
743
|
const pPrChangeChildren = [];
|
|
696
744
|
if (prevPPrChildren.length > 0) {
|
|
697
745
|
pPrChangeChildren.push({
|
|
698
|
-
name:
|
|
746
|
+
name: "w:pPr",
|
|
699
747
|
attributes: {},
|
|
700
748
|
children: prevPPrChildren,
|
|
701
749
|
});
|
|
702
750
|
}
|
|
703
751
|
pPrChildren.push({
|
|
704
|
-
name:
|
|
752
|
+
name: "w:pPrChange",
|
|
705
753
|
attributes: attrs,
|
|
706
754
|
children: pPrChangeChildren,
|
|
707
755
|
});
|
|
708
756
|
}
|
|
709
757
|
if (this.formatting.sectPr) {
|
|
710
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
758
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("sectPr", this.formatting.sectPr));
|
|
711
759
|
}
|
|
712
760
|
const paragraphChildren = [];
|
|
713
761
|
if (pPrChildren.length > 0) {
|
|
714
|
-
paragraphChildren.push(XMLBuilder_1.XMLBuilder.w(
|
|
762
|
+
paragraphChildren.push(XMLBuilder_1.XMLBuilder.w("pPr", undefined, pPrChildren));
|
|
715
763
|
}
|
|
716
764
|
for (const bookmark of this.bookmarksStart) {
|
|
717
765
|
paragraphChildren.push(bookmark.toStartXML());
|
|
@@ -722,7 +770,7 @@ class Paragraph {
|
|
|
722
770
|
for (let i = 0; i < this.content.length; i++) {
|
|
723
771
|
const item = this.content[i];
|
|
724
772
|
if (item instanceof Field_1.Field) {
|
|
725
|
-
paragraphChildren.push(XMLBuilder_1.XMLBuilder.w(
|
|
773
|
+
paragraphChildren.push(XMLBuilder_1.XMLBuilder.w("r", undefined, [item.toXML()]));
|
|
726
774
|
}
|
|
727
775
|
else if (item instanceof Field_1.ComplexField) {
|
|
728
776
|
const fieldXml = item.toXML();
|
|
@@ -730,7 +778,7 @@ class Paragraph {
|
|
|
730
778
|
paragraphChildren.push(...fieldXml);
|
|
731
779
|
}
|
|
732
780
|
else {
|
|
733
|
-
paragraphChildren.push(XMLBuilder_1.XMLBuilder.w(
|
|
781
|
+
paragraphChildren.push(XMLBuilder_1.XMLBuilder.w("r", undefined, [fieldXml]));
|
|
734
782
|
}
|
|
735
783
|
}
|
|
736
784
|
else if (item instanceof Hyperlink_1.Hyperlink) {
|
|
@@ -743,17 +791,17 @@ class Paragraph {
|
|
|
743
791
|
paragraphChildren.push(item.toXML());
|
|
744
792
|
}
|
|
745
793
|
else if (item instanceof Shape_1.Shape) {
|
|
746
|
-
paragraphChildren.push(XMLBuilder_1.XMLBuilder.w(
|
|
794
|
+
paragraphChildren.push(XMLBuilder_1.XMLBuilder.w("r", undefined, [item.toXML()]));
|
|
747
795
|
}
|
|
748
796
|
else if (item instanceof TextBox_1.TextBox) {
|
|
749
|
-
paragraphChildren.push(XMLBuilder_1.XMLBuilder.w(
|
|
797
|
+
paragraphChildren.push(XMLBuilder_1.XMLBuilder.w("r", undefined, [item.toXML()]));
|
|
750
798
|
}
|
|
751
799
|
else if (item) {
|
|
752
800
|
paragraphChildren.push(item.toXML());
|
|
753
801
|
}
|
|
754
802
|
}
|
|
755
803
|
if (this.content.length === 0) {
|
|
756
|
-
paragraphChildren.push(new Run_1.Run(
|
|
804
|
+
paragraphChildren.push(new Run_1.Run("").toXML());
|
|
757
805
|
}
|
|
758
806
|
for (const comment of this.commentsEnd) {
|
|
759
807
|
paragraphChildren.push(comment.toRangeEndXML());
|
|
@@ -766,15 +814,17 @@ class Paragraph {
|
|
|
766
814
|
}
|
|
767
815
|
const paragraphAttributes = {};
|
|
768
816
|
if (this.formatting.paraId) {
|
|
769
|
-
paragraphAttributes[
|
|
817
|
+
paragraphAttributes["w14:paraId"] = this.formatting.paraId;
|
|
770
818
|
}
|
|
771
|
-
return XMLBuilder_1.XMLBuilder.w(
|
|
819
|
+
return XMLBuilder_1.XMLBuilder.w("p", Object.keys(paragraphAttributes).length > 0
|
|
820
|
+
? paragraphAttributes
|
|
821
|
+
: undefined, paragraphChildren);
|
|
772
822
|
}
|
|
773
823
|
getWordCount() {
|
|
774
824
|
const text = this.getText().trim();
|
|
775
825
|
if (!text)
|
|
776
826
|
return 0;
|
|
777
|
-
const words = text.split(/\s+/).filter(word => word.length > 0);
|
|
827
|
+
const words = text.split(/\s+/).filter((word) => word.length > 0);
|
|
778
828
|
return words.length;
|
|
779
829
|
}
|
|
780
830
|
getLength(includeSpaces = true) {
|
|
@@ -783,7 +833,7 @@ class Paragraph {
|
|
|
783
833
|
return text.length;
|
|
784
834
|
}
|
|
785
835
|
else {
|
|
786
|
-
return text.replace(/\s/g,
|
|
836
|
+
return text.replace(/\s/g, "").length;
|
|
787
837
|
}
|
|
788
838
|
}
|
|
789
839
|
clone() {
|
|
@@ -862,9 +912,11 @@ class Paragraph {
|
|
|
862
912
|
for (let i = 0; i < this.content.length; i++) {
|
|
863
913
|
const item = this.content[i];
|
|
864
914
|
if (item instanceof Run_1.Run) {
|
|
865
|
-
const runText = caseSensitive
|
|
915
|
+
const runText = caseSensitive
|
|
916
|
+
? item.getText()
|
|
917
|
+
: item.getText().toLowerCase();
|
|
866
918
|
if (wholeWord) {
|
|
867
|
-
const wordPattern = new RegExp(`\\b${searchText.replace(/[.*+?^${}()|[\]\\]/g,
|
|
919
|
+
const wordPattern = new RegExp(`\\b${searchText.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`);
|
|
868
920
|
if (wordPattern.test(runText)) {
|
|
869
921
|
indices.push(i);
|
|
870
922
|
}
|
|
@@ -887,7 +939,7 @@ class Paragraph {
|
|
|
887
939
|
const originalText = item.getText();
|
|
888
940
|
let newText = originalText;
|
|
889
941
|
if (wholeWord) {
|
|
890
|
-
const wordPattern = new RegExp(`\\b${find.replace(/[.*+?^${}()|[\]\\]/g,
|
|
942
|
+
const wordPattern = new RegExp(`\\b${find.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`, caseSensitive ? "g" : "gi");
|
|
891
943
|
const matches = originalText.match(wordPattern);
|
|
892
944
|
if (matches) {
|
|
893
945
|
replacementCount += matches.length;
|
|
@@ -895,7 +947,7 @@ class Paragraph {
|
|
|
895
947
|
}
|
|
896
948
|
}
|
|
897
949
|
else {
|
|
898
|
-
const searchPattern = new RegExp(find.replace(/[.*+?^${}()|[\]\\]/g,
|
|
950
|
+
const searchPattern = new RegExp(find.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), caseSensitive ? "g" : "gi");
|
|
899
951
|
const matches = originalText.match(searchPattern);
|
|
900
952
|
if (matches) {
|
|
901
953
|
replacementCount += matches.length;
|
|
@@ -967,13 +1019,17 @@ class Paragraph {
|
|
|
967
1019
|
const conflictingParaProps = [];
|
|
968
1020
|
for (const key in this.formatting) {
|
|
969
1021
|
const propKey = key;
|
|
970
|
-
if (propKey ===
|
|
1022
|
+
if (propKey === "style") {
|
|
971
1023
|
continue;
|
|
972
1024
|
}
|
|
973
1025
|
if (styleParagraphFormatting[propKey] === undefined) {
|
|
974
1026
|
continue;
|
|
975
1027
|
}
|
|
976
|
-
if (propKey ===
|
|
1028
|
+
if (propKey === "indentation" ||
|
|
1029
|
+
propKey === "spacing" ||
|
|
1030
|
+
propKey === "borders" ||
|
|
1031
|
+
propKey === "shading" ||
|
|
1032
|
+
propKey === "numbering") {
|
|
977
1033
|
const paraValue = this.formatting[propKey];
|
|
978
1034
|
const styleValue = styleParagraphFormatting[propKey];
|
|
979
1035
|
if (JSON.stringify(paraValue) !== JSON.stringify(styleValue)) {
|