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.
Files changed (35) hide show
  1. package/README.md +85 -54
  2. package/dist/core/Document.d.ts +4 -7
  3. package/dist/core/Document.d.ts.map +1 -1
  4. package/dist/core/Document.js +21 -111
  5. package/dist/core/Document.js.map +1 -1
  6. package/dist/core/DocumentParser.d.ts.map +1 -1
  7. package/dist/core/DocumentParser.js +28 -2
  8. package/dist/core/DocumentParser.js.map +1 -1
  9. package/dist/elements/Paragraph.d.ts +31 -27
  10. package/dist/elements/Paragraph.d.ts.map +1 -1
  11. package/dist/elements/Paragraph.js +183 -127
  12. package/dist/elements/Paragraph.js.map +1 -1
  13. package/dist/elements/Run.d.ts +14 -14
  14. package/dist/elements/Run.d.ts.map +1 -1
  15. package/dist/elements/Run.js +137 -133
  16. package/dist/elements/Run.js.map +1 -1
  17. package/dist/elements/StructuredDocumentTag.d.ts +10 -7
  18. package/dist/elements/StructuredDocumentTag.d.ts.map +1 -1
  19. package/dist/elements/StructuredDocumentTag.js +87 -70
  20. package/dist/elements/StructuredDocumentTag.js.map +1 -1
  21. package/dist/elements/Table.d.ts +13 -13
  22. package/dist/elements/Table.d.ts.map +1 -1
  23. package/dist/elements/Table.js +61 -51
  24. package/dist/elements/Table.js.map +1 -1
  25. package/dist/elements/TableCell.d.ts +9 -6
  26. package/dist/elements/TableCell.d.ts.map +1 -1
  27. package/dist/elements/TableCell.js +70 -32
  28. package/dist/elements/TableCell.js.map +1 -1
  29. package/dist/formatting/StylesManager.d.ts +21 -1
  30. package/dist/formatting/StylesManager.d.ts.map +1 -1
  31. package/dist/formatting/StylesManager.js +187 -74
  32. package/dist/formatting/StylesManager.js.map +1 -1
  33. package/dist/types/styleConfig.d.ts +4 -3
  34. package/dist/types/styleConfig.d.ts.map +1 -1
  35. 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 === 'string') {
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('Setting left indentation on a numbered paragraph has no effect. ' +
217
- 'Numbering controls indentation. Use different numbering levels to change indent.');
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('Setting first line indentation on a numbered paragraph has no effect. ' +
235
- 'Numbering controls indentation using hanging indent.');
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 = 'auto') {
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('Numbering ID must be non-negative');
323
+ throw new Error("Numbering ID must be non-negative");
297
324
  }
298
325
  if (level < 0 || level > 8) {
299
- throw new Error('Level must be between 0 and 8');
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 ? { ...this.formatting.numbering } : undefined;
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('Outline level must be between 0 and 9');
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)('serialization', -1, runData, this.formatting.bidi);
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('pStyle', { 'w:val': this.formatting.style }));
445
+ pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("pStyle", { "w:val": this.formatting.style }));
417
446
  }
418
- if (this.formatting.paragraphMarkRunProperties || this.formatting.paragraphMarkDeletion) {
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 !== 'string') {
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('del', {
433
- 'w:id': del.id.toString(),
434
- 'w:author': del.author,
435
- 'w:date': del.date.toISOString(),
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('rPr', undefined, rPrChildren));
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('keepNext'));
473
+ pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("keepNext"));
444
474
  }
445
475
  if (this.formatting.keepLines) {
446
- pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf('keepLines'));
476
+ pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("keepLines"));
447
477
  }
448
478
  if (this.formatting.pageBreakBefore) {
449
- pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf('pageBreakBefore'));
479
+ pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("pageBreakBefore"));
450
480
  }
451
481
  if (this.formatting.widowControl !== undefined) {
452
- pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf('widowControl', { 'w:val': this.formatting.widowControl ? '1' : '0' }));
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('numPr', undefined, [
456
- XMLBuilder_1.XMLBuilder.wSelf('ilvl', { 'w:val': this.formatting.numbering.level.toString() }),
457
- XMLBuilder_1.XMLBuilder.wSelf('numId', { 'w:val': this.formatting.numbering.numId.toString() })
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('suppressLineNumbers'));
498
+ pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("suppressLineNumbers"));
463
499
  }
464
500
  if (this.formatting.suppressAutoHyphens) {
465
- pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf('suppressAutoHyphens'));
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['w:before'] = spc.before;
507
+ attributes["w:before"] = spc.before;
472
508
  if (spc.after !== undefined)
473
- attributes['w:after'] = spc.after;
509
+ attributes["w:after"] = spc.after;
474
510
  if (spc.line !== undefined)
475
- attributes['w:line'] = spc.line;
511
+ attributes["w:line"] = spc.line;
476
512
  if (spc.lineRule)
477
- attributes['w:lineRule'] = spc.lineRule;
513
+ attributes["w:lineRule"] = spc.lineRule;
478
514
  if (Object.keys(attributes).length > 0) {
479
- pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf('spacing', attributes));
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('contextualSpacing', { 'w:val': '1' }));
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['w:left'] = ind.left;
525
+ attributes["w:left"] = ind.left;
490
526
  if (ind.right !== undefined)
491
- attributes['w:right'] = ind.right;
527
+ attributes["w:right"] = ind.right;
492
528
  if (ind.firstLine !== undefined)
493
- attributes['w:firstLine'] = ind.firstLine;
529
+ attributes["w:firstLine"] = ind.firstLine;
494
530
  if (ind.hanging !== undefined)
495
- attributes['w:hanging'] = ind.hanging;
531
+ attributes["w:hanging"] = ind.hanging;
496
532
  if (Object.keys(attributes).length > 0) {
497
- pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf('ind', attributes));
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('mirrorIndents'));
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['w:val'] = border.style;
547
+ attributes["w:val"] = border.style;
512
548
  if (border.size !== undefined)
513
- attributes['w:sz'] = border.size;
549
+ attributes["w:sz"] = border.size;
514
550
  if (border.color)
515
- attributes['w:color'] = border.color;
551
+ attributes["w:color"] = border.color;
516
552
  if (border.space !== undefined)
517
- attributes['w:space'] = border.space;
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('top', borders.top);
559
+ const topBorder = createBorder("top", borders.top);
524
560
  if (topBorder)
525
561
  borderChildren.push(topBorder);
526
- const leftBorder = createBorder('left', borders.left);
562
+ const leftBorder = createBorder("left", borders.left);
527
563
  if (leftBorder)
528
564
  borderChildren.push(leftBorder);
529
- const bottomBorder = createBorder('bottom', borders.bottom);
565
+ const bottomBorder = createBorder("bottom", borders.bottom);
530
566
  if (bottomBorder)
531
567
  borderChildren.push(bottomBorder);
532
- const rightBorder = createBorder('right', borders.right);
568
+ const rightBorder = createBorder("right", borders.right);
533
569
  if (rightBorder)
534
570
  borderChildren.push(rightBorder);
535
- const betweenBorder = createBorder('between', borders.between);
571
+ const betweenBorder = createBorder("between", borders.between);
536
572
  if (betweenBorder)
537
573
  borderChildren.push(betweenBorder);
538
- const barBorder = createBorder('bar', borders.bar);
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('pBdr', undefined, borderChildren));
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['w:fill'] = shd.fill;
585
+ attributes["w:fill"] = shd.fill;
550
586
  if (shd.color)
551
- attributes['w:color'] = shd.color;
587
+ attributes["w:color"] = shd.color;
552
588
  if (shd.val)
553
- attributes['w:val'] = shd.val;
589
+ attributes["w:val"] = shd.val;
554
590
  if (Object.keys(attributes).length > 0) {
555
- pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf('shd', attributes));
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['w:pos'] = tab.position;
598
+ attributes["w:pos"] = tab.position;
563
599
  if (tab.val)
564
- attributes['w:val'] = tab.val;
600
+ attributes["w:val"] = tab.val;
565
601
  if (tab.leader)
566
- attributes['w:leader'] = tab.leader;
567
- tabChildren.push(XMLBuilder_1.XMLBuilder.wSelf('tab', attributes));
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('tabs', undefined, tabChildren));
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['w:w'] = f.w.toString();
613
+ attrs["w:w"] = f.w.toString();
578
614
  if (f.h !== undefined)
579
- attrs['w:h'] = f.h.toString();
615
+ attrs["w:h"] = f.h.toString();
580
616
  if (f.hRule)
581
- attrs['w:hRule'] = f.hRule;
617
+ attrs["w:hRule"] = f.hRule;
582
618
  if (f.x !== undefined)
583
- attrs['w:x'] = f.x.toString();
619
+ attrs["w:x"] = f.x.toString();
584
620
  if (f.y !== undefined)
585
- attrs['w:y'] = f.y.toString();
621
+ attrs["w:y"] = f.y.toString();
586
622
  if (f.xAlign)
587
- attrs['w:xAlign'] = f.xAlign;
623
+ attrs["w:xAlign"] = f.xAlign;
588
624
  if (f.yAlign)
589
- attrs['w:yAlign'] = f.yAlign;
625
+ attrs["w:yAlign"] = f.yAlign;
590
626
  if (f.hAnchor)
591
- attrs['w:hAnchor'] = f.hAnchor;
627
+ attrs["w:hAnchor"] = f.hAnchor;
592
628
  if (f.vAnchor)
593
- attrs['w:vAnchor'] = f.vAnchor;
629
+ attrs["w:vAnchor"] = f.vAnchor;
594
630
  if (f.hSpace !== undefined)
595
- attrs['w:hSpace'] = f.hSpace.toString();
631
+ attrs["w:hSpace"] = f.hSpace.toString();
596
632
  if (f.vSpace !== undefined)
597
- attrs['w:vSpace'] = f.vSpace.toString();
633
+ attrs["w:vSpace"] = f.vSpace.toString();
598
634
  if (f.wrap)
599
- attrs['w:wrap'] = f.wrap;
635
+ attrs["w:wrap"] = f.wrap;
600
636
  if (f.dropCap)
601
- attrs['w:dropCap'] = f.dropCap;
637
+ attrs["w:dropCap"] = f.dropCap;
602
638
  if (f.lines !== undefined)
603
- attrs['w:lines'] = f.lines.toString();
639
+ attrs["w:lines"] = f.lines.toString();
604
640
  if (f.anchorLock !== undefined)
605
- attrs['w:anchorLock'] = f.anchorLock ? '1' : '0';
641
+ attrs["w:anchorLock"] = f.anchorLock ? "1" : "0";
606
642
  if (Object.keys(attrs).length > 0) {
607
- pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf('framePr', attrs));
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('suppressOverlap'));
647
+ pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("suppressOverlap"));
612
648
  }
613
649
  if (this.formatting.bidi !== undefined) {
614
- pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf('bidi', { 'w:val': this.formatting.bidi ? '1' : '0' }));
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('adjustRightInd', { 'w:val': this.formatting.adjustRightInd ? '1' : '0' }));
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('textboxTightWrap', { 'w:val': this.formatting.textboxTightWrap }));
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 === 'justify' ? 'both' : this.formatting.alignment;
624
- pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf('jc', { 'w:val': alignmentValue }));
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('textAlignment', { 'w:val': this.formatting.textAlignment }));
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('textDirection', { 'w:val': this.formatting.textDirection }));
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('outlineLvl', { 'w:val': this.formatting.outlineLevel.toString() }));
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('divId', { 'w:val': this.formatting.divId.toString() }));
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('cnfStyle', { 'w:val': this.formatting.cnfStyle }));
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['w:author'] = change.author;
693
+ attrs["w:author"] = change.author;
646
694
  if (change.date)
647
- attrs['w:date'] = change.date;
695
+ attrs["w:date"] = change.date;
648
696
  if (change.id)
649
- attrs['w:id'] = change.id;
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('pStyle', { 'w:val': prev.style }));
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('keepNext', prev.keepNext ? { 'w:val': '1' } : { 'w:val': '0' }));
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('keepLines', prev.keepLines ? { 'w:val': '1' } : { 'w:val': '0' }));
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('pageBreakBefore', prev.pageBreakBefore ? { 'w:val': '1' } : { 'w:val': '0' }));
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('jc', { 'w:val': prev.alignment }));
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['w:left'] = prev.indentation.left.toString();
719
+ indAttrs["w:left"] = prev.indentation.left.toString();
672
720
  if (prev.indentation.right !== undefined)
673
- indAttrs['w:right'] = prev.indentation.right.toString();
721
+ indAttrs["w:right"] = prev.indentation.right.toString();
674
722
  if (prev.indentation.firstLine !== undefined)
675
- indAttrs['w:firstLine'] = prev.indentation.firstLine.toString();
723
+ indAttrs["w:firstLine"] = prev.indentation.firstLine.toString();
676
724
  if (prev.indentation.hanging !== undefined)
677
- indAttrs['w:hanging'] = prev.indentation.hanging.toString();
678
- prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf('ind', indAttrs));
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['w:before'] = prev.spacing.before.toString();
731
+ spacingAttrs["w:before"] = prev.spacing.before.toString();
684
732
  if (prev.spacing.after !== undefined)
685
- spacingAttrs['w:after'] = prev.spacing.after.toString();
733
+ spacingAttrs["w:after"] = prev.spacing.after.toString();
686
734
  if (prev.spacing.line !== undefined)
687
- spacingAttrs['w:line'] = prev.spacing.line.toString();
735
+ spacingAttrs["w:line"] = prev.spacing.line.toString();
688
736
  if (prev.spacing.lineRule)
689
- spacingAttrs['w:lineRule'] = prev.spacing.lineRule;
737
+ spacingAttrs["w:lineRule"] = prev.spacing.lineRule;
690
738
  if (Object.keys(spacingAttrs).length > 0) {
691
- prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf('spacing', spacingAttrs));
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: 'w:pPr',
746
+ name: "w:pPr",
699
747
  attributes: {},
700
748
  children: prevPPrChildren,
701
749
  });
702
750
  }
703
751
  pPrChildren.push({
704
- name: 'w:pPrChange',
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('sectPr', this.formatting.sectPr));
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('pPr', undefined, pPrChildren));
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('r', undefined, [item.toXML()]));
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('r', undefined, [fieldXml]));
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('r', undefined, [item.toXML()]));
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('r', undefined, [item.toXML()]));
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('').toXML());
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['w14:paraId'] = this.formatting.paraId;
817
+ paragraphAttributes["w14:paraId"] = this.formatting.paraId;
770
818
  }
771
- return XMLBuilder_1.XMLBuilder.w('p', Object.keys(paragraphAttributes).length > 0 ? paragraphAttributes : undefined, paragraphChildren);
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, '').length;
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 ? item.getText() : item.getText().toLowerCase();
915
+ const runText = caseSensitive
916
+ ? item.getText()
917
+ : item.getText().toLowerCase();
866
918
  if (wholeWord) {
867
- const wordPattern = new RegExp(`\\b${searchText.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`);
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, '\\$&')}\\b`, caseSensitive ? 'g' : 'gi');
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, '\\$&'), caseSensitive ? 'g' : 'gi');
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 === 'style') {
1022
+ if (propKey === "style") {
971
1023
  continue;
972
1024
  }
973
1025
  if (styleParagraphFormatting[propKey] === undefined) {
974
1026
  continue;
975
1027
  }
976
- if (propKey === 'indentation' || propKey === 'spacing' || propKey === 'borders' || propKey === 'shading' || propKey === 'numbering') {
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)) {