docxmlater 3.1.0 → 3.5.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 +1 -0
- package/dist/core/Document.d.ts.map +1 -1
- package/dist/core/Document.js +38 -40
- package/dist/core/Document.js.map +1 -1
- package/dist/elements/Paragraph.d.ts +27 -27
- package/dist/elements/Paragraph.d.ts.map +1 -1
- package/dist/elements/Paragraph.js +156 -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/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/package.json +1 -1
|
@@ -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,8 @@ 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
163
|
}
|
|
164
164
|
getFormatting() {
|
|
165
165
|
return { ...this.formatting };
|
|
@@ -213,8 +213,8 @@ class Paragraph {
|
|
|
213
213
|
}
|
|
214
214
|
setLeftIndent(twips) {
|
|
215
215
|
if (this.formatting.numbering) {
|
|
216
|
-
logger_1.defaultLogger.warn(
|
|
217
|
-
|
|
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.");
|
|
218
218
|
}
|
|
219
219
|
if (!this.formatting.indentation) {
|
|
220
220
|
this.formatting.indentation = {};
|
|
@@ -231,8 +231,8 @@ class Paragraph {
|
|
|
231
231
|
}
|
|
232
232
|
setFirstLineIndent(twips) {
|
|
233
233
|
if (this.formatting.numbering) {
|
|
234
|
-
logger_1.defaultLogger.warn(
|
|
235
|
-
|
|
234
|
+
logger_1.defaultLogger.warn("Setting first line indentation on a numbered paragraph has no effect. " +
|
|
235
|
+
"Numbering controls indentation using hanging indent.");
|
|
236
236
|
}
|
|
237
237
|
if (!this.formatting.indentation) {
|
|
238
238
|
this.formatting.indentation = {};
|
|
@@ -254,7 +254,7 @@ class Paragraph {
|
|
|
254
254
|
this.formatting.spacing.after = twips;
|
|
255
255
|
return this;
|
|
256
256
|
}
|
|
257
|
-
setLineSpacing(twips, rule =
|
|
257
|
+
setLineSpacing(twips, rule = "auto") {
|
|
258
258
|
if (!this.formatting.spacing) {
|
|
259
259
|
this.formatting.spacing = {};
|
|
260
260
|
}
|
|
@@ -293,10 +293,10 @@ class Paragraph {
|
|
|
293
293
|
}
|
|
294
294
|
setNumbering(numId, level = 0) {
|
|
295
295
|
if (numId < 0) {
|
|
296
|
-
throw new Error(
|
|
296
|
+
throw new Error("Numbering ID must be non-negative");
|
|
297
297
|
}
|
|
298
298
|
if (level < 0 || level > 8) {
|
|
299
|
-
throw new Error(
|
|
299
|
+
throw new Error("Level must be between 0 and 8");
|
|
300
300
|
}
|
|
301
301
|
this.formatting.numbering = { numId, level };
|
|
302
302
|
if (this.formatting.indentation) {
|
|
@@ -314,7 +314,9 @@ class Paragraph {
|
|
|
314
314
|
return this;
|
|
315
315
|
}
|
|
316
316
|
getNumbering() {
|
|
317
|
-
return this.formatting.numbering
|
|
317
|
+
return this.formatting.numbering
|
|
318
|
+
? { ...this.formatting.numbering }
|
|
319
|
+
: undefined;
|
|
318
320
|
}
|
|
319
321
|
setWidowControl(enable = true) {
|
|
320
322
|
this.formatting.widowControl = enable;
|
|
@@ -322,7 +324,7 @@ class Paragraph {
|
|
|
322
324
|
}
|
|
323
325
|
setOutlineLevel(level) {
|
|
324
326
|
if (level < 0 || level > 9) {
|
|
325
|
-
throw new Error(
|
|
327
|
+
throw new Error("Outline level must be between 0 and 9");
|
|
326
328
|
}
|
|
327
329
|
this.formatting.outlineLevel = level;
|
|
328
330
|
return this;
|
|
@@ -403,25 +405,26 @@ class Paragraph {
|
|
|
403
405
|
return !!this.formatting.paragraphMarkDeletion;
|
|
404
406
|
}
|
|
405
407
|
toXML() {
|
|
406
|
-
const runData = this.getRuns().map(run => ({
|
|
408
|
+
const runData = this.getRuns().map((run) => ({
|
|
407
409
|
text: run.getText(),
|
|
408
410
|
rtl: run.getFormatting().rtl,
|
|
409
411
|
}));
|
|
410
|
-
(0, diagnostics_1.logParagraphContent)(
|
|
412
|
+
(0, diagnostics_1.logParagraphContent)("serialization", -1, runData, this.formatting.bidi);
|
|
411
413
|
if (this.formatting.bidi) {
|
|
412
414
|
(0, diagnostics_1.logTextDirection)(`Serializing paragraph with BiDi enabled`);
|
|
413
415
|
}
|
|
414
416
|
const pPrChildren = [];
|
|
415
417
|
if (this.formatting.style) {
|
|
416
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
418
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("pStyle", { "w:val": this.formatting.style }));
|
|
417
419
|
}
|
|
418
|
-
if (this.formatting.paragraphMarkRunProperties ||
|
|
420
|
+
if (this.formatting.paragraphMarkRunProperties ||
|
|
421
|
+
this.formatting.paragraphMarkDeletion) {
|
|
419
422
|
const rPrChildren = [];
|
|
420
423
|
if (this.formatting.paragraphMarkRunProperties) {
|
|
421
424
|
const rPr = Run_1.Run.generateRunPropertiesXML(this.formatting.paragraphMarkRunProperties);
|
|
422
425
|
if (rPr && rPr.children) {
|
|
423
426
|
for (const child of rPr.children) {
|
|
424
|
-
if (typeof child !==
|
|
427
|
+
if (typeof child !== "string") {
|
|
425
428
|
rPrChildren.push(child);
|
|
426
429
|
}
|
|
427
430
|
}
|
|
@@ -429,76 +432,82 @@ class Paragraph {
|
|
|
429
432
|
}
|
|
430
433
|
if (this.formatting.paragraphMarkDeletion) {
|
|
431
434
|
const del = this.formatting.paragraphMarkDeletion;
|
|
432
|
-
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
435
|
+
rPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("del", {
|
|
436
|
+
"w:id": del.id.toString(),
|
|
437
|
+
"w:author": del.author,
|
|
438
|
+
"w:date": del.date.toISOString(),
|
|
436
439
|
}));
|
|
437
440
|
}
|
|
438
441
|
if (rPrChildren.length > 0) {
|
|
439
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.w(
|
|
442
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.w("rPr", undefined, rPrChildren));
|
|
440
443
|
}
|
|
441
444
|
}
|
|
442
445
|
if (this.formatting.keepNext) {
|
|
443
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
446
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("keepNext"));
|
|
444
447
|
}
|
|
445
448
|
if (this.formatting.keepLines) {
|
|
446
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
449
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("keepLines"));
|
|
447
450
|
}
|
|
448
451
|
if (this.formatting.pageBreakBefore) {
|
|
449
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
452
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("pageBreakBefore"));
|
|
450
453
|
}
|
|
451
454
|
if (this.formatting.widowControl !== undefined) {
|
|
452
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
455
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("widowControl", {
|
|
456
|
+
"w:val": this.formatting.widowControl ? "1" : "0",
|
|
457
|
+
}));
|
|
453
458
|
}
|
|
454
459
|
if (this.formatting.numbering) {
|
|
455
|
-
const numPr = XMLBuilder_1.XMLBuilder.w(
|
|
456
|
-
XMLBuilder_1.XMLBuilder.wSelf(
|
|
457
|
-
|
|
460
|
+
const numPr = XMLBuilder_1.XMLBuilder.w("numPr", undefined, [
|
|
461
|
+
XMLBuilder_1.XMLBuilder.wSelf("ilvl", {
|
|
462
|
+
"w:val": this.formatting.numbering.level.toString(),
|
|
463
|
+
}),
|
|
464
|
+
XMLBuilder_1.XMLBuilder.wSelf("numId", {
|
|
465
|
+
"w:val": this.formatting.numbering.numId.toString(),
|
|
466
|
+
}),
|
|
458
467
|
]);
|
|
459
468
|
pPrChildren.push(numPr);
|
|
460
469
|
}
|
|
461
470
|
if (this.formatting.suppressLineNumbers) {
|
|
462
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
471
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("suppressLineNumbers"));
|
|
463
472
|
}
|
|
464
473
|
if (this.formatting.suppressAutoHyphens) {
|
|
465
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
474
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("suppressAutoHyphens"));
|
|
466
475
|
}
|
|
467
476
|
if (this.formatting.spacing) {
|
|
468
477
|
const spc = this.formatting.spacing;
|
|
469
478
|
const attributes = {};
|
|
470
479
|
if (spc.before !== undefined)
|
|
471
|
-
attributes[
|
|
480
|
+
attributes["w:before"] = spc.before;
|
|
472
481
|
if (spc.after !== undefined)
|
|
473
|
-
attributes[
|
|
482
|
+
attributes["w:after"] = spc.after;
|
|
474
483
|
if (spc.line !== undefined)
|
|
475
|
-
attributes[
|
|
484
|
+
attributes["w:line"] = spc.line;
|
|
476
485
|
if (spc.lineRule)
|
|
477
|
-
attributes[
|
|
486
|
+
attributes["w:lineRule"] = spc.lineRule;
|
|
478
487
|
if (Object.keys(attributes).length > 0) {
|
|
479
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
488
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("spacing", attributes));
|
|
480
489
|
}
|
|
481
490
|
}
|
|
482
491
|
if (this.formatting.contextualSpacing) {
|
|
483
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
492
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("contextualSpacing", { "w:val": "1" }));
|
|
484
493
|
}
|
|
485
494
|
if (this.formatting.indentation) {
|
|
486
495
|
const ind = this.formatting.indentation;
|
|
487
496
|
const attributes = {};
|
|
488
497
|
if (ind.left !== undefined)
|
|
489
|
-
attributes[
|
|
498
|
+
attributes["w:left"] = ind.left;
|
|
490
499
|
if (ind.right !== undefined)
|
|
491
|
-
attributes[
|
|
500
|
+
attributes["w:right"] = ind.right;
|
|
492
501
|
if (ind.firstLine !== undefined)
|
|
493
|
-
attributes[
|
|
502
|
+
attributes["w:firstLine"] = ind.firstLine;
|
|
494
503
|
if (ind.hanging !== undefined)
|
|
495
|
-
attributes[
|
|
504
|
+
attributes["w:hanging"] = ind.hanging;
|
|
496
505
|
if (Object.keys(attributes).length > 0) {
|
|
497
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
506
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("ind", attributes));
|
|
498
507
|
}
|
|
499
508
|
}
|
|
500
509
|
if (this.formatting.mirrorIndents) {
|
|
501
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
510
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("mirrorIndents"));
|
|
502
511
|
}
|
|
503
512
|
if (this.formatting.borders) {
|
|
504
513
|
const borderChildren = [];
|
|
@@ -508,210 +517,222 @@ class Paragraph {
|
|
|
508
517
|
return null;
|
|
509
518
|
const attributes = {};
|
|
510
519
|
if (border.style)
|
|
511
|
-
attributes[
|
|
520
|
+
attributes["w:val"] = border.style;
|
|
512
521
|
if (border.size !== undefined)
|
|
513
|
-
attributes[
|
|
522
|
+
attributes["w:sz"] = border.size;
|
|
514
523
|
if (border.color)
|
|
515
|
-
attributes[
|
|
524
|
+
attributes["w:color"] = border.color;
|
|
516
525
|
if (border.space !== undefined)
|
|
517
|
-
attributes[
|
|
526
|
+
attributes["w:space"] = border.space;
|
|
518
527
|
if (Object.keys(attributes).length > 0) {
|
|
519
528
|
return XMLBuilder_1.XMLBuilder.wSelf(borderType, attributes);
|
|
520
529
|
}
|
|
521
530
|
return null;
|
|
522
531
|
};
|
|
523
|
-
const topBorder = createBorder(
|
|
532
|
+
const topBorder = createBorder("top", borders.top);
|
|
524
533
|
if (topBorder)
|
|
525
534
|
borderChildren.push(topBorder);
|
|
526
|
-
const leftBorder = createBorder(
|
|
535
|
+
const leftBorder = createBorder("left", borders.left);
|
|
527
536
|
if (leftBorder)
|
|
528
537
|
borderChildren.push(leftBorder);
|
|
529
|
-
const bottomBorder = createBorder(
|
|
538
|
+
const bottomBorder = createBorder("bottom", borders.bottom);
|
|
530
539
|
if (bottomBorder)
|
|
531
540
|
borderChildren.push(bottomBorder);
|
|
532
|
-
const rightBorder = createBorder(
|
|
541
|
+
const rightBorder = createBorder("right", borders.right);
|
|
533
542
|
if (rightBorder)
|
|
534
543
|
borderChildren.push(rightBorder);
|
|
535
|
-
const betweenBorder = createBorder(
|
|
544
|
+
const betweenBorder = createBorder("between", borders.between);
|
|
536
545
|
if (betweenBorder)
|
|
537
546
|
borderChildren.push(betweenBorder);
|
|
538
|
-
const barBorder = createBorder(
|
|
547
|
+
const barBorder = createBorder("bar", borders.bar);
|
|
539
548
|
if (barBorder)
|
|
540
549
|
borderChildren.push(barBorder);
|
|
541
550
|
if (borderChildren.length > 0) {
|
|
542
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.w(
|
|
551
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.w("pBdr", undefined, borderChildren));
|
|
543
552
|
}
|
|
544
553
|
}
|
|
545
554
|
if (this.formatting.shading) {
|
|
546
555
|
const shd = this.formatting.shading;
|
|
547
556
|
const attributes = {};
|
|
548
557
|
if (shd.fill)
|
|
549
|
-
attributes[
|
|
558
|
+
attributes["w:fill"] = shd.fill;
|
|
550
559
|
if (shd.color)
|
|
551
|
-
attributes[
|
|
560
|
+
attributes["w:color"] = shd.color;
|
|
552
561
|
if (shd.val)
|
|
553
|
-
attributes[
|
|
562
|
+
attributes["w:val"] = shd.val;
|
|
554
563
|
if (Object.keys(attributes).length > 0) {
|
|
555
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
564
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("shd", attributes));
|
|
556
565
|
}
|
|
557
566
|
}
|
|
558
567
|
if (this.formatting.tabs && this.formatting.tabs.length > 0) {
|
|
559
568
|
const tabChildren = [];
|
|
560
569
|
for (const tab of this.formatting.tabs) {
|
|
561
570
|
const attributes = {};
|
|
562
|
-
attributes[
|
|
571
|
+
attributes["w:pos"] = tab.position;
|
|
563
572
|
if (tab.val)
|
|
564
|
-
attributes[
|
|
573
|
+
attributes["w:val"] = tab.val;
|
|
565
574
|
if (tab.leader)
|
|
566
|
-
attributes[
|
|
567
|
-
tabChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
575
|
+
attributes["w:leader"] = tab.leader;
|
|
576
|
+
tabChildren.push(XMLBuilder_1.XMLBuilder.wSelf("tab", attributes));
|
|
568
577
|
}
|
|
569
578
|
if (tabChildren.length > 0) {
|
|
570
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.w(
|
|
579
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.w("tabs", undefined, tabChildren));
|
|
571
580
|
}
|
|
572
581
|
}
|
|
573
582
|
if (this.formatting.framePr) {
|
|
574
583
|
const attrs = {};
|
|
575
584
|
const f = this.formatting.framePr;
|
|
576
585
|
if (f.w !== undefined)
|
|
577
|
-
attrs[
|
|
586
|
+
attrs["w:w"] = f.w.toString();
|
|
578
587
|
if (f.h !== undefined)
|
|
579
|
-
attrs[
|
|
588
|
+
attrs["w:h"] = f.h.toString();
|
|
580
589
|
if (f.hRule)
|
|
581
|
-
attrs[
|
|
590
|
+
attrs["w:hRule"] = f.hRule;
|
|
582
591
|
if (f.x !== undefined)
|
|
583
|
-
attrs[
|
|
592
|
+
attrs["w:x"] = f.x.toString();
|
|
584
593
|
if (f.y !== undefined)
|
|
585
|
-
attrs[
|
|
594
|
+
attrs["w:y"] = f.y.toString();
|
|
586
595
|
if (f.xAlign)
|
|
587
|
-
attrs[
|
|
596
|
+
attrs["w:xAlign"] = f.xAlign;
|
|
588
597
|
if (f.yAlign)
|
|
589
|
-
attrs[
|
|
598
|
+
attrs["w:yAlign"] = f.yAlign;
|
|
590
599
|
if (f.hAnchor)
|
|
591
|
-
attrs[
|
|
600
|
+
attrs["w:hAnchor"] = f.hAnchor;
|
|
592
601
|
if (f.vAnchor)
|
|
593
|
-
attrs[
|
|
602
|
+
attrs["w:vAnchor"] = f.vAnchor;
|
|
594
603
|
if (f.hSpace !== undefined)
|
|
595
|
-
attrs[
|
|
604
|
+
attrs["w:hSpace"] = f.hSpace.toString();
|
|
596
605
|
if (f.vSpace !== undefined)
|
|
597
|
-
attrs[
|
|
606
|
+
attrs["w:vSpace"] = f.vSpace.toString();
|
|
598
607
|
if (f.wrap)
|
|
599
|
-
attrs[
|
|
608
|
+
attrs["w:wrap"] = f.wrap;
|
|
600
609
|
if (f.dropCap)
|
|
601
|
-
attrs[
|
|
610
|
+
attrs["w:dropCap"] = f.dropCap;
|
|
602
611
|
if (f.lines !== undefined)
|
|
603
|
-
attrs[
|
|
612
|
+
attrs["w:lines"] = f.lines.toString();
|
|
604
613
|
if (f.anchorLock !== undefined)
|
|
605
|
-
attrs[
|
|
614
|
+
attrs["w:anchorLock"] = f.anchorLock ? "1" : "0";
|
|
606
615
|
if (Object.keys(attrs).length > 0) {
|
|
607
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
616
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("framePr", attrs));
|
|
608
617
|
}
|
|
609
618
|
}
|
|
610
619
|
if (this.formatting.suppressOverlap) {
|
|
611
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
620
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("suppressOverlap"));
|
|
612
621
|
}
|
|
613
622
|
if (this.formatting.bidi !== undefined) {
|
|
614
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
623
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("bidi", { "w:val": this.formatting.bidi ? "1" : "0" }));
|
|
615
624
|
}
|
|
616
625
|
if (this.formatting.adjustRightInd !== undefined) {
|
|
617
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
626
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("adjustRightInd", {
|
|
627
|
+
"w:val": this.formatting.adjustRightInd ? "1" : "0",
|
|
628
|
+
}));
|
|
618
629
|
}
|
|
619
630
|
if (this.formatting.textboxTightWrap) {
|
|
620
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
631
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("textboxTightWrap", {
|
|
632
|
+
"w:val": this.formatting.textboxTightWrap,
|
|
633
|
+
}));
|
|
621
634
|
}
|
|
622
635
|
if (this.formatting.alignment) {
|
|
623
|
-
const alignmentValue = this.formatting.alignment ===
|
|
624
|
-
|
|
636
|
+
const alignmentValue = this.formatting.alignment === "justify"
|
|
637
|
+
? "both"
|
|
638
|
+
: this.formatting.alignment;
|
|
639
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("jc", { "w:val": alignmentValue }));
|
|
625
640
|
}
|
|
626
641
|
if (this.formatting.textAlignment) {
|
|
627
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
642
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("textAlignment", {
|
|
643
|
+
"w:val": this.formatting.textAlignment,
|
|
644
|
+
}));
|
|
628
645
|
}
|
|
629
646
|
if (this.formatting.textDirection) {
|
|
630
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
647
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("textDirection", {
|
|
648
|
+
"w:val": this.formatting.textDirection,
|
|
649
|
+
}));
|
|
631
650
|
}
|
|
632
651
|
if (this.formatting.outlineLevel !== undefined) {
|
|
633
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
652
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("outlineLvl", {
|
|
653
|
+
"w:val": this.formatting.outlineLevel.toString(),
|
|
654
|
+
}));
|
|
634
655
|
}
|
|
635
656
|
if (this.formatting.divId !== undefined) {
|
|
636
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
657
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("divId", { "w:val": this.formatting.divId.toString() }));
|
|
637
658
|
}
|
|
638
659
|
if (this.formatting.cnfStyle) {
|
|
639
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
660
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("cnfStyle", { "w:val": this.formatting.cnfStyle }));
|
|
640
661
|
}
|
|
641
662
|
if (this.formatting.pPrChange) {
|
|
642
663
|
const change = this.formatting.pPrChange;
|
|
643
664
|
const attrs = {};
|
|
644
665
|
if (change.author)
|
|
645
|
-
attrs[
|
|
666
|
+
attrs["w:author"] = change.author;
|
|
646
667
|
if (change.date)
|
|
647
|
-
attrs[
|
|
668
|
+
attrs["w:date"] = change.date;
|
|
648
669
|
if (change.id)
|
|
649
|
-
attrs[
|
|
670
|
+
attrs["w:id"] = change.id;
|
|
650
671
|
const prevPPrChildren = [];
|
|
651
672
|
if (change.previousProperties) {
|
|
652
673
|
const prev = change.previousProperties;
|
|
653
674
|
if (prev.style) {
|
|
654
|
-
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
675
|
+
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("pStyle", { "w:val": prev.style }));
|
|
655
676
|
}
|
|
656
677
|
if (prev.keepNext !== undefined) {
|
|
657
|
-
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
678
|
+
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("keepNext", prev.keepNext ? { "w:val": "1" } : { "w:val": "0" }));
|
|
658
679
|
}
|
|
659
680
|
if (prev.keepLines !== undefined) {
|
|
660
|
-
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
681
|
+
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("keepLines", prev.keepLines ? { "w:val": "1" } : { "w:val": "0" }));
|
|
661
682
|
}
|
|
662
683
|
if (prev.pageBreakBefore !== undefined) {
|
|
663
|
-
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
684
|
+
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("pageBreakBefore", prev.pageBreakBefore ? { "w:val": "1" } : { "w:val": "0" }));
|
|
664
685
|
}
|
|
665
686
|
if (prev.alignment) {
|
|
666
|
-
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
687
|
+
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("jc", { "w:val": prev.alignment }));
|
|
667
688
|
}
|
|
668
689
|
if (prev.indentation) {
|
|
669
690
|
const indAttrs = {};
|
|
670
691
|
if (prev.indentation.left !== undefined)
|
|
671
|
-
indAttrs[
|
|
692
|
+
indAttrs["w:left"] = prev.indentation.left.toString();
|
|
672
693
|
if (prev.indentation.right !== undefined)
|
|
673
|
-
indAttrs[
|
|
694
|
+
indAttrs["w:right"] = prev.indentation.right.toString();
|
|
674
695
|
if (prev.indentation.firstLine !== undefined)
|
|
675
|
-
indAttrs[
|
|
696
|
+
indAttrs["w:firstLine"] = prev.indentation.firstLine.toString();
|
|
676
697
|
if (prev.indentation.hanging !== undefined)
|
|
677
|
-
indAttrs[
|
|
678
|
-
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
698
|
+
indAttrs["w:hanging"] = prev.indentation.hanging.toString();
|
|
699
|
+
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("ind", indAttrs));
|
|
679
700
|
}
|
|
680
701
|
if (prev.spacing) {
|
|
681
702
|
const spacingAttrs = {};
|
|
682
703
|
if (prev.spacing.before !== undefined)
|
|
683
|
-
spacingAttrs[
|
|
704
|
+
spacingAttrs["w:before"] = prev.spacing.before.toString();
|
|
684
705
|
if (prev.spacing.after !== undefined)
|
|
685
|
-
spacingAttrs[
|
|
706
|
+
spacingAttrs["w:after"] = prev.spacing.after.toString();
|
|
686
707
|
if (prev.spacing.line !== undefined)
|
|
687
|
-
spacingAttrs[
|
|
708
|
+
spacingAttrs["w:line"] = prev.spacing.line.toString();
|
|
688
709
|
if (prev.spacing.lineRule)
|
|
689
|
-
spacingAttrs[
|
|
710
|
+
spacingAttrs["w:lineRule"] = prev.spacing.lineRule;
|
|
690
711
|
if (Object.keys(spacingAttrs).length > 0) {
|
|
691
|
-
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
712
|
+
prevPPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("spacing", spacingAttrs));
|
|
692
713
|
}
|
|
693
714
|
}
|
|
694
715
|
}
|
|
695
716
|
const pPrChangeChildren = [];
|
|
696
717
|
if (prevPPrChildren.length > 0) {
|
|
697
718
|
pPrChangeChildren.push({
|
|
698
|
-
name:
|
|
719
|
+
name: "w:pPr",
|
|
699
720
|
attributes: {},
|
|
700
721
|
children: prevPPrChildren,
|
|
701
722
|
});
|
|
702
723
|
}
|
|
703
724
|
pPrChildren.push({
|
|
704
|
-
name:
|
|
725
|
+
name: "w:pPrChange",
|
|
705
726
|
attributes: attrs,
|
|
706
727
|
children: pPrChangeChildren,
|
|
707
728
|
});
|
|
708
729
|
}
|
|
709
730
|
if (this.formatting.sectPr) {
|
|
710
|
-
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf(
|
|
731
|
+
pPrChildren.push(XMLBuilder_1.XMLBuilder.wSelf("sectPr", this.formatting.sectPr));
|
|
711
732
|
}
|
|
712
733
|
const paragraphChildren = [];
|
|
713
734
|
if (pPrChildren.length > 0) {
|
|
714
|
-
paragraphChildren.push(XMLBuilder_1.XMLBuilder.w(
|
|
735
|
+
paragraphChildren.push(XMLBuilder_1.XMLBuilder.w("pPr", undefined, pPrChildren));
|
|
715
736
|
}
|
|
716
737
|
for (const bookmark of this.bookmarksStart) {
|
|
717
738
|
paragraphChildren.push(bookmark.toStartXML());
|
|
@@ -722,7 +743,7 @@ class Paragraph {
|
|
|
722
743
|
for (let i = 0; i < this.content.length; i++) {
|
|
723
744
|
const item = this.content[i];
|
|
724
745
|
if (item instanceof Field_1.Field) {
|
|
725
|
-
paragraphChildren.push(XMLBuilder_1.XMLBuilder.w(
|
|
746
|
+
paragraphChildren.push(XMLBuilder_1.XMLBuilder.w("r", undefined, [item.toXML()]));
|
|
726
747
|
}
|
|
727
748
|
else if (item instanceof Field_1.ComplexField) {
|
|
728
749
|
const fieldXml = item.toXML();
|
|
@@ -730,7 +751,7 @@ class Paragraph {
|
|
|
730
751
|
paragraphChildren.push(...fieldXml);
|
|
731
752
|
}
|
|
732
753
|
else {
|
|
733
|
-
paragraphChildren.push(XMLBuilder_1.XMLBuilder.w(
|
|
754
|
+
paragraphChildren.push(XMLBuilder_1.XMLBuilder.w("r", undefined, [fieldXml]));
|
|
734
755
|
}
|
|
735
756
|
}
|
|
736
757
|
else if (item instanceof Hyperlink_1.Hyperlink) {
|
|
@@ -743,17 +764,17 @@ class Paragraph {
|
|
|
743
764
|
paragraphChildren.push(item.toXML());
|
|
744
765
|
}
|
|
745
766
|
else if (item instanceof Shape_1.Shape) {
|
|
746
|
-
paragraphChildren.push(XMLBuilder_1.XMLBuilder.w(
|
|
767
|
+
paragraphChildren.push(XMLBuilder_1.XMLBuilder.w("r", undefined, [item.toXML()]));
|
|
747
768
|
}
|
|
748
769
|
else if (item instanceof TextBox_1.TextBox) {
|
|
749
|
-
paragraphChildren.push(XMLBuilder_1.XMLBuilder.w(
|
|
770
|
+
paragraphChildren.push(XMLBuilder_1.XMLBuilder.w("r", undefined, [item.toXML()]));
|
|
750
771
|
}
|
|
751
772
|
else if (item) {
|
|
752
773
|
paragraphChildren.push(item.toXML());
|
|
753
774
|
}
|
|
754
775
|
}
|
|
755
776
|
if (this.content.length === 0) {
|
|
756
|
-
paragraphChildren.push(new Run_1.Run(
|
|
777
|
+
paragraphChildren.push(new Run_1.Run("").toXML());
|
|
757
778
|
}
|
|
758
779
|
for (const comment of this.commentsEnd) {
|
|
759
780
|
paragraphChildren.push(comment.toRangeEndXML());
|
|
@@ -766,15 +787,17 @@ class Paragraph {
|
|
|
766
787
|
}
|
|
767
788
|
const paragraphAttributes = {};
|
|
768
789
|
if (this.formatting.paraId) {
|
|
769
|
-
paragraphAttributes[
|
|
790
|
+
paragraphAttributes["w14:paraId"] = this.formatting.paraId;
|
|
770
791
|
}
|
|
771
|
-
return XMLBuilder_1.XMLBuilder.w(
|
|
792
|
+
return XMLBuilder_1.XMLBuilder.w("p", Object.keys(paragraphAttributes).length > 0
|
|
793
|
+
? paragraphAttributes
|
|
794
|
+
: undefined, paragraphChildren);
|
|
772
795
|
}
|
|
773
796
|
getWordCount() {
|
|
774
797
|
const text = this.getText().trim();
|
|
775
798
|
if (!text)
|
|
776
799
|
return 0;
|
|
777
|
-
const words = text.split(/\s+/).filter(word => word.length > 0);
|
|
800
|
+
const words = text.split(/\s+/).filter((word) => word.length > 0);
|
|
778
801
|
return words.length;
|
|
779
802
|
}
|
|
780
803
|
getLength(includeSpaces = true) {
|
|
@@ -783,7 +806,7 @@ class Paragraph {
|
|
|
783
806
|
return text.length;
|
|
784
807
|
}
|
|
785
808
|
else {
|
|
786
|
-
return text.replace(/\s/g,
|
|
809
|
+
return text.replace(/\s/g, "").length;
|
|
787
810
|
}
|
|
788
811
|
}
|
|
789
812
|
clone() {
|
|
@@ -862,9 +885,11 @@ class Paragraph {
|
|
|
862
885
|
for (let i = 0; i < this.content.length; i++) {
|
|
863
886
|
const item = this.content[i];
|
|
864
887
|
if (item instanceof Run_1.Run) {
|
|
865
|
-
const runText = caseSensitive
|
|
888
|
+
const runText = caseSensitive
|
|
889
|
+
? item.getText()
|
|
890
|
+
: item.getText().toLowerCase();
|
|
866
891
|
if (wholeWord) {
|
|
867
|
-
const wordPattern = new RegExp(`\\b${searchText.replace(/[.*+?^${}()|[\]\\]/g,
|
|
892
|
+
const wordPattern = new RegExp(`\\b${searchText.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`);
|
|
868
893
|
if (wordPattern.test(runText)) {
|
|
869
894
|
indices.push(i);
|
|
870
895
|
}
|
|
@@ -887,7 +912,7 @@ class Paragraph {
|
|
|
887
912
|
const originalText = item.getText();
|
|
888
913
|
let newText = originalText;
|
|
889
914
|
if (wholeWord) {
|
|
890
|
-
const wordPattern = new RegExp(`\\b${find.replace(/[.*+?^${}()|[\]\\]/g,
|
|
915
|
+
const wordPattern = new RegExp(`\\b${find.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`, caseSensitive ? "g" : "gi");
|
|
891
916
|
const matches = originalText.match(wordPattern);
|
|
892
917
|
if (matches) {
|
|
893
918
|
replacementCount += matches.length;
|
|
@@ -895,7 +920,7 @@ class Paragraph {
|
|
|
895
920
|
}
|
|
896
921
|
}
|
|
897
922
|
else {
|
|
898
|
-
const searchPattern = new RegExp(find.replace(/[.*+?^${}()|[\]\\]/g,
|
|
923
|
+
const searchPattern = new RegExp(find.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), caseSensitive ? "g" : "gi");
|
|
899
924
|
const matches = originalText.match(searchPattern);
|
|
900
925
|
if (matches) {
|
|
901
926
|
replacementCount += matches.length;
|
|
@@ -967,13 +992,17 @@ class Paragraph {
|
|
|
967
992
|
const conflictingParaProps = [];
|
|
968
993
|
for (const key in this.formatting) {
|
|
969
994
|
const propKey = key;
|
|
970
|
-
if (propKey ===
|
|
995
|
+
if (propKey === "style") {
|
|
971
996
|
continue;
|
|
972
997
|
}
|
|
973
998
|
if (styleParagraphFormatting[propKey] === undefined) {
|
|
974
999
|
continue;
|
|
975
1000
|
}
|
|
976
|
-
if (propKey ===
|
|
1001
|
+
if (propKey === "indentation" ||
|
|
1002
|
+
propKey === "spacing" ||
|
|
1003
|
+
propKey === "borders" ||
|
|
1004
|
+
propKey === "shading" ||
|
|
1005
|
+
propKey === "numbering") {
|
|
977
1006
|
const paraValue = this.formatting[propKey];
|
|
978
1007
|
const styleValue = styleParagraphFormatting[propKey];
|
|
979
1008
|
if (JSON.stringify(paraValue) !== JSON.stringify(styleValue)) {
|