docxmlater 2.2.4 → 2.4.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.
@@ -773,7 +773,7 @@ class Document {
773
773
  }
774
774
  applyStandardTableFormatting(colorOrOptions, multiCellColor) {
775
775
  let options;
776
- if (typeof colorOrOptions === 'string') {
776
+ if (typeof colorOrOptions === "string") {
777
777
  if (multiCellColor) {
778
778
  options = {
779
779
  singleCellShading: colorOrOptions,
@@ -788,13 +788,13 @@ class Document {
788
788
  options = colorOrOptions;
789
789
  }
790
790
  const singleCellShading = options?.singleCellShading?.toUpperCase();
791
- const headerRowShading = (options?.headerRowShading || 'E9E9E9').toUpperCase();
791
+ const headerRowShading = (options?.headerRowShading || "E9E9E9").toUpperCase();
792
792
  const headerRowFormatting = {
793
793
  bold: options?.headerRowFormatting?.bold !== false,
794
- alignment: options?.headerRowFormatting?.alignment || 'center',
795
- font: options?.headerRowFormatting?.font || 'Verdana',
794
+ alignment: options?.headerRowFormatting?.alignment || "center",
795
+ font: options?.headerRowFormatting?.font || "Verdana",
796
796
  size: options?.headerRowFormatting?.size || 12,
797
- color: options?.headerRowFormatting?.color || '000000',
797
+ color: options?.headerRowFormatting?.color || "000000",
798
798
  spacingBefore: options?.headerRowFormatting?.spacingBefore ?? 60,
799
799
  spacingAfter: options?.headerRowFormatting?.spacingAfter ?? 60,
800
800
  };
@@ -814,12 +814,12 @@ class Document {
814
814
  const rowCount = table.getRowCount();
815
815
  const columnCount = table.getColumnCount();
816
816
  table.setAllBorders({
817
- style: 'single',
817
+ style: "single",
818
818
  size: 4,
819
- color: '000000',
819
+ color: "000000",
820
820
  });
821
- table.setLayout('auto');
822
- table.setWidthType('pct');
821
+ table.setLayout("auto");
822
+ table.setWidthType("pct");
823
823
  table.setWidth(5000);
824
824
  const is1x1Table = rowCount === 1 && columnCount === 1;
825
825
  if (is1x1Table) {
@@ -840,7 +840,8 @@ class Document {
840
840
  cell.setMargins(cellMargins);
841
841
  for (const para of cell.getParagraphs()) {
842
842
  const numPr = para.getFormatting().numbering;
843
- if (numPr && (numPr.level !== undefined || numPr.numId !== undefined)) {
843
+ if (numPr &&
844
+ (numPr.level !== undefined || numPr.numId !== undefined)) {
844
845
  continue;
845
846
  }
846
847
  para.setAlignment(headerRowFormatting.alignment);
@@ -864,22 +865,23 @@ class Document {
864
865
  cell.setMargins(cellMargins);
865
866
  const currentShading = cell.getFormatting().shading;
866
867
  const currentColor = currentShading?.fill?.toUpperCase();
867
- const isValidHexColor = /^[0-9A-F]{6}$/i.test(currentColor || '');
868
- if (currentColor && currentColor !== 'FFFFFF' && isValidHexColor) {
868
+ const isValidHexColor = /^[0-9A-F]{6}$/i.test(currentColor || "");
869
+ if (currentColor && currentColor !== "FFFFFF" && isValidHexColor) {
869
870
  cell.setShading({ fill: headerRowShading });
870
871
  cellsRecolored++;
871
872
  for (const para of cell.getParagraphs()) {
872
873
  const numPr = para.getFormatting().numbering;
873
- if (numPr && (numPr.level !== undefined || numPr.numId !== undefined)) {
874
+ if (numPr &&
875
+ (numPr.level !== undefined || numPr.numId !== undefined)) {
874
876
  continue;
875
877
  }
876
- para.setAlignment('center');
878
+ para.setAlignment("center");
877
879
  para.setSpaceBefore(60);
878
880
  para.setSpaceAfter(60);
879
881
  for (const run of para.getRuns()) {
880
882
  run.setBold(true);
881
- run.setFont('Verdana', 12);
882
- run.setColor('000000');
883
+ run.setFont("Verdana", 12);
884
+ run.setColor("000000");
883
885
  }
884
886
  }
885
887
  }
@@ -1085,15 +1087,15 @@ class Document {
1085
1087
  if (!abstractNum)
1086
1088
  continue;
1087
1089
  const level0 = abstractNum.getLevel(0);
1088
- if (!level0 || level0.getFormat() !== 'bullet')
1090
+ if (!level0 || level0.getFormat() !== "bullet")
1089
1091
  continue;
1090
1092
  for (let levelIndex = 0; levelIndex < 9; levelIndex++) {
1091
1093
  const numLevel = abstractNum.getLevel(levelIndex);
1092
1094
  if (!numLevel)
1093
1095
  continue;
1094
- const bullet = levelIndex % 2 === 0 ? '' : '';
1096
+ const bullet = levelIndex % 2 === 0 ? "" : "";
1095
1097
  numLevel.setText(bullet);
1096
- numLevel.setFont('Arial');
1098
+ numLevel.setFont("Arial");
1097
1099
  numLevel.setFontSize(24);
1098
1100
  numLevel.setLeftIndent(720 * (levelIndex + 1));
1099
1101
  numLevel.setHangingIndent(360);
@@ -1112,17 +1114,17 @@ class Document {
1112
1114
  if (!abstractNum)
1113
1115
  continue;
1114
1116
  const level0 = abstractNum.getLevel(0);
1115
- if (!level0 || level0.getFormat() === 'bullet')
1117
+ if (!level0 || level0.getFormat() === "bullet")
1116
1118
  continue;
1117
1119
  for (let levelIndex = 0; levelIndex < 9; levelIndex++) {
1118
1120
  const numLevel = abstractNum.getLevel(levelIndex);
1119
1121
  if (!numLevel)
1120
1122
  continue;
1121
- numLevel.setFont('Verdana');
1123
+ numLevel.setFont("Verdana");
1122
1124
  numLevel.setFontSize(24);
1123
1125
  numLevel.setLeftIndent(720 * (levelIndex + 1));
1124
1126
  numLevel.setHangingIndent(360);
1125
- numLevel.setAlignment('left');
1127
+ numLevel.setAlignment("left");
1126
1128
  }
1127
1129
  this.applyFormattingToListParagraphs(instance.getNumId());
1128
1130
  count++;
@@ -1136,7 +1138,7 @@ class Document {
1136
1138
  if (numbering?.numId === numId) {
1137
1139
  const runs = para.getRuns();
1138
1140
  for (const run of runs) {
1139
- run.setFont('Verdana', 12);
1141
+ run.setFont("Verdana", 12);
1140
1142
  }
1141
1143
  para.setSpaceBefore(0);
1142
1144
  para.setSpaceAfter(60);
@@ -1164,30 +1166,32 @@ class Document {
1164
1166
  wrapParagraphInTable(para, options) {
1165
1167
  const paraIndex = this.bodyElements.indexOf(para);
1166
1168
  if (paraIndex === -1) {
1167
- throw new Error('Paragraph not found in document body elements');
1169
+ throw new Error("Paragraph not found in document body elements");
1168
1170
  }
1169
1171
  const table = new Table_1.Table(1, 1);
1170
1172
  const cell = table.getCell(0, 0);
1171
1173
  if (!cell) {
1172
- throw new Error('Failed to get cell from newly created table');
1174
+ throw new Error("Failed to get cell from newly created table");
1173
1175
  }
1174
1176
  this.bodyElements.splice(paraIndex, 1);
1175
1177
  cell.addParagraph(para);
1176
1178
  if (options.shading) {
1177
1179
  cell.setShading({ fill: options.shading });
1178
1180
  }
1179
- if (options.marginTop !== undefined || options.marginBottom !== undefined ||
1180
- options.marginLeft !== undefined || options.marginRight !== undefined) {
1181
+ if (options.marginTop !== undefined ||
1182
+ options.marginBottom !== undefined ||
1183
+ options.marginLeft !== undefined ||
1184
+ options.marginRight !== undefined) {
1181
1185
  cell.setMargins({
1182
1186
  top: options.marginTop ?? 100,
1183
1187
  bottom: options.marginBottom ?? 100,
1184
1188
  left: options.marginLeft ?? 100,
1185
- right: options.marginRight ?? 100
1189
+ right: options.marginRight ?? 100,
1186
1190
  });
1187
1191
  }
1188
1192
  if (options.tableWidthPercent !== undefined) {
1189
1193
  table.setWidth(options.tableWidthPercent);
1190
- table.setWidthType('pct');
1194
+ table.setWidthType("pct");
1191
1195
  }
1192
1196
  this.bodyElements.splice(paraIndex, 0, table);
1193
1197
  return table;
@@ -1195,60 +1199,60 @@ class Document {
1195
1199
  applyCustomStylesToDocument() {
1196
1200
  const counts = { heading1: 0, heading2: 0, normal: 0 };
1197
1201
  const header1Style = Style_1.Style.create({
1198
- styleId: 'CustomHeader1',
1199
- name: 'Custom Header 1',
1200
- type: 'paragraph',
1201
- basedOn: 'Normal',
1202
+ styleId: "CustomHeader1",
1203
+ name: "Custom Header 1",
1204
+ type: "paragraph",
1205
+ basedOn: "Normal",
1202
1206
  runFormatting: {
1203
- font: 'Verdana',
1207
+ font: "Verdana",
1204
1208
  size: 18,
1205
1209
  bold: true,
1206
- color: '000000'
1210
+ color: "000000",
1207
1211
  },
1208
1212
  paragraphFormatting: {
1209
- alignment: 'left',
1213
+ alignment: "left",
1210
1214
  spacing: {
1211
1215
  before: 0,
1212
- after: 240
1213
- }
1214
- }
1216
+ after: 240,
1217
+ },
1218
+ },
1215
1219
  });
1216
1220
  const header2Style = Style_1.Style.create({
1217
- styleId: 'CustomHeader2',
1218
- name: 'Custom Header 2',
1219
- type: 'paragraph',
1220
- basedOn: 'Normal',
1221
+ styleId: "CustomHeader2",
1222
+ name: "Custom Header 2",
1223
+ type: "paragraph",
1224
+ basedOn: "Normal",
1221
1225
  runFormatting: {
1222
- font: 'Verdana',
1226
+ font: "Verdana",
1223
1227
  size: 14,
1224
1228
  bold: true,
1225
- color: '000000'
1229
+ color: "000000",
1226
1230
  },
1227
1231
  paragraphFormatting: {
1228
- alignment: 'left',
1232
+ alignment: "left",
1229
1233
  spacing: {
1230
1234
  before: 120,
1231
- after: 120
1232
- }
1233
- }
1235
+ after: 120,
1236
+ },
1237
+ },
1234
1238
  });
1235
1239
  const normalStyle = Style_1.Style.create({
1236
- styleId: 'CustomNormal',
1237
- name: 'Custom Normal',
1238
- type: 'paragraph',
1239
- basedOn: 'Normal',
1240
+ styleId: "CustomNormal",
1241
+ name: "Custom Normal",
1242
+ type: "paragraph",
1243
+ basedOn: "Normal",
1240
1244
  runFormatting: {
1241
- font: 'Verdana',
1245
+ font: "Verdana",
1242
1246
  size: 12,
1243
- color: '000000'
1247
+ color: "000000",
1244
1248
  },
1245
1249
  paragraphFormatting: {
1246
- alignment: 'left',
1250
+ alignment: "left",
1247
1251
  spacing: {
1248
1252
  before: 60,
1249
- after: 60
1250
- }
1251
- }
1253
+ after: 60,
1254
+ },
1255
+ },
1252
1256
  });
1253
1257
  this.addStyle(header1Style);
1254
1258
  this.addStyle(header2Style);
@@ -1256,17 +1260,17 @@ class Document {
1256
1260
  const allParagraphs = this.getAllParagraphs();
1257
1261
  for (const para of allParagraphs) {
1258
1262
  const currentStyle = para.getStyle();
1259
- if (currentStyle === 'Heading1' || currentStyle === 'Heading 1') {
1260
- para.setStyle('CustomHeader1');
1263
+ if (currentStyle === "Heading1" || currentStyle === "Heading 1") {
1264
+ para.setStyle("CustomHeader1");
1261
1265
  counts.heading1++;
1262
1266
  }
1263
- else if (currentStyle === 'Heading2' || currentStyle === 'Heading 2') {
1264
- para.setStyle('CustomHeader2');
1267
+ else if (currentStyle === "Heading2" || currentStyle === "Heading 2") {
1268
+ para.setStyle("CustomHeader2");
1265
1269
  const { inTable, cell } = this.isParagraphInTable(para);
1266
1270
  if (inTable && cell) {
1267
- cell.setShading({ fill: 'BFBFBF' });
1271
+ cell.setShading({ fill: "BFBFBF" });
1268
1272
  cell.setMargins({ top: 0, bottom: 0, left: 101, right: 101 });
1269
- const table = this.getAllTables().find(t => {
1273
+ const table = this.getAllTables().find((t) => {
1270
1274
  for (const row of t.getRows()) {
1271
1275
  for (const c of row.getCells()) {
1272
1276
  if (c === cell)
@@ -1277,23 +1281,23 @@ class Document {
1277
1281
  });
1278
1282
  if (table) {
1279
1283
  table.setWidth(5000);
1280
- table.setWidthType('pct');
1284
+ table.setWidthType("pct");
1281
1285
  }
1282
1286
  }
1283
1287
  else {
1284
1288
  this.wrapParagraphInTable(para, {
1285
- shading: 'BFBFBF',
1289
+ shading: "BFBFBF",
1286
1290
  marginTop: 0,
1287
1291
  marginBottom: 0,
1288
1292
  marginLeft: 101,
1289
1293
  marginRight: 101,
1290
- tableWidthPercent: 5000
1294
+ tableWidthPercent: 5000,
1291
1295
  });
1292
1296
  }
1293
1297
  counts.heading2++;
1294
1298
  }
1295
- else if (currentStyle === 'Normal' || currentStyle === undefined) {
1296
- para.setStyle('CustomNormal');
1299
+ else if (currentStyle === "Normal" || currentStyle === undefined) {
1300
+ para.setStyle("CustomNormal");
1297
1301
  counts.normal++;
1298
1302
  }
1299
1303
  }
@@ -1301,29 +1305,29 @@ class Document {
1301
1305
  }
1302
1306
  static DEFAULT_HEADING1_CONFIG = {
1303
1307
  run: {
1304
- font: 'Verdana',
1308
+ font: "Verdana",
1305
1309
  size: 18,
1306
1310
  bold: true,
1307
- color: '000000',
1311
+ color: "000000",
1308
1312
  },
1309
1313
  paragraph: {
1310
- alignment: 'left',
1311
- spacing: { before: 0, after: 240, line: 240, lineRule: 'auto' },
1314
+ alignment: "left",
1315
+ spacing: { before: 0, after: 240, line: 240, lineRule: "auto" },
1312
1316
  },
1313
1317
  };
1314
1318
  static DEFAULT_HEADING2_CONFIG = {
1315
1319
  run: {
1316
- font: 'Verdana',
1320
+ font: "Verdana",
1317
1321
  size: 14,
1318
1322
  bold: true,
1319
- color: '000000',
1323
+ color: "000000",
1320
1324
  },
1321
1325
  paragraph: {
1322
- alignment: 'left',
1323
- spacing: { before: 120, after: 120, line: 240, lineRule: 'auto' },
1326
+ alignment: "left",
1327
+ spacing: { before: 120, after: 120, line: 240, lineRule: "auto" },
1324
1328
  },
1325
1329
  tableOptions: {
1326
- shading: 'BFBFBF',
1330
+ shading: "BFBFBF",
1327
1331
  marginTop: 0,
1328
1332
  marginBottom: 0,
1329
1333
  marginLeft: 115,
@@ -1333,99 +1337,114 @@ class Document {
1333
1337
  };
1334
1338
  static DEFAULT_HEADING3_CONFIG = {
1335
1339
  run: {
1336
- font: 'Verdana',
1340
+ font: "Verdana",
1337
1341
  size: 12,
1338
1342
  bold: true,
1339
- color: '000000',
1343
+ color: "000000",
1340
1344
  },
1341
1345
  paragraph: {
1342
- alignment: 'left',
1343
- spacing: { before: 60, after: 60, line: 240, lineRule: 'auto' },
1346
+ alignment: "left",
1347
+ spacing: { before: 60, after: 60, line: 240, lineRule: "auto" },
1344
1348
  },
1345
1349
  };
1346
1350
  static DEFAULT_NORMAL_CONFIG = {
1347
1351
  run: {
1348
- font: 'Verdana',
1352
+ font: "Verdana",
1349
1353
  size: 12,
1350
- color: '000000',
1354
+ color: "000000",
1351
1355
  },
1352
1356
  paragraph: {
1353
- alignment: 'left',
1354
- spacing: { before: 60, after: 60, line: 240, lineRule: 'auto' },
1357
+ alignment: "left",
1358
+ spacing: { before: 60, after: 60, line: 240, lineRule: "auto" },
1355
1359
  },
1356
1360
  };
1357
1361
  static DEFAULT_LIST_PARAGRAPH_CONFIG = {
1358
1362
  run: {
1359
- font: 'Verdana',
1363
+ font: "Verdana",
1360
1364
  size: 12,
1361
- color: '000000',
1365
+ color: "000000",
1362
1366
  },
1363
1367
  paragraph: {
1364
- alignment: 'left',
1365
- spacing: { before: 0, after: 60, line: 240, lineRule: 'auto' },
1368
+ alignment: "left",
1369
+ spacing: { before: 0, after: 60, line: 240, lineRule: "auto" },
1366
1370
  indentation: { left: 360, hanging: 360 },
1367
1371
  contextualSpacing: true,
1368
1372
  },
1369
1373
  };
1370
1374
  applyCustomFormattingToExistingStyles(options) {
1371
- const results = { heading1: false, heading2: false, heading3: false, normal: false, listParagraph: false };
1372
- const heading1 = this.stylesManager.getStyle('Heading1');
1373
- const heading2 = this.stylesManager.getStyle('Heading2');
1374
- const heading3 = this.stylesManager.getStyle('Heading3');
1375
- const normal = this.stylesManager.getStyle('Normal');
1376
- const listParagraph = this.stylesManager.getStyle('ListParagraph');
1375
+ const results = {
1376
+ heading1: false,
1377
+ heading2: false,
1378
+ heading3: false,
1379
+ normal: false,
1380
+ listParagraph: false,
1381
+ };
1382
+ const heading1 = this.stylesManager.getStyle("Heading1");
1383
+ const heading2 = this.stylesManager.getStyle("Heading2");
1384
+ const heading3 = this.stylesManager.getStyle("Heading3");
1385
+ const normal = this.stylesManager.getStyle("Normal");
1386
+ const listParagraph = this.stylesManager.getStyle("ListParagraph");
1377
1387
  const h1Config = {
1378
1388
  run: {
1379
- ...(heading1?.getRunFormatting() || Document.DEFAULT_HEADING1_CONFIG.run),
1380
- ...options?.heading1?.run
1389
+ ...(heading1?.getRunFormatting() ||
1390
+ Document.DEFAULT_HEADING1_CONFIG.run),
1391
+ ...options?.heading1?.run,
1381
1392
  },
1382
1393
  paragraph: {
1383
- ...(heading1?.getParagraphFormatting() || Document.DEFAULT_HEADING1_CONFIG.paragraph),
1384
- ...options?.heading1?.paragraph
1394
+ ...(heading1?.getParagraphFormatting() ||
1395
+ Document.DEFAULT_HEADING1_CONFIG.paragraph),
1396
+ ...options?.heading1?.paragraph,
1385
1397
  },
1386
1398
  };
1387
1399
  const h2Config = {
1388
1400
  run: {
1389
- ...(heading2?.getRunFormatting() || Document.DEFAULT_HEADING2_CONFIG.run),
1390
- ...options?.heading2?.run
1401
+ ...(heading2?.getRunFormatting() ||
1402
+ Document.DEFAULT_HEADING2_CONFIG.run),
1403
+ ...options?.heading2?.run,
1391
1404
  },
1392
1405
  paragraph: {
1393
- ...(heading2?.getParagraphFormatting() || Document.DEFAULT_HEADING2_CONFIG.paragraph),
1394
- ...options?.heading2?.paragraph
1406
+ ...(heading2?.getParagraphFormatting() ||
1407
+ Document.DEFAULT_HEADING2_CONFIG.paragraph),
1408
+ ...options?.heading2?.paragraph,
1395
1409
  },
1396
1410
  tableOptions: {
1397
1411
  ...Document.DEFAULT_HEADING2_CONFIG.tableOptions,
1398
- ...options?.heading2?.tableOptions
1412
+ ...options?.heading2?.tableOptions,
1399
1413
  },
1400
1414
  };
1401
1415
  const h3Config = {
1402
1416
  run: {
1403
- ...(heading3?.getRunFormatting() || Document.DEFAULT_HEADING3_CONFIG.run),
1404
- ...options?.heading3?.run
1417
+ ...(heading3?.getRunFormatting() ||
1418
+ Document.DEFAULT_HEADING3_CONFIG.run),
1419
+ ...options?.heading3?.run,
1405
1420
  },
1406
1421
  paragraph: {
1407
- ...(heading3?.getParagraphFormatting() || Document.DEFAULT_HEADING3_CONFIG.paragraph),
1408
- ...options?.heading3?.paragraph
1422
+ ...(heading3?.getParagraphFormatting() ||
1423
+ Document.DEFAULT_HEADING3_CONFIG.paragraph),
1424
+ ...options?.heading3?.paragraph,
1409
1425
  },
1410
1426
  };
1411
1427
  const normalConfig = {
1412
1428
  run: {
1413
1429
  ...(normal?.getRunFormatting() || Document.DEFAULT_NORMAL_CONFIG.run),
1414
- ...options?.normal?.run
1430
+ ...options?.normal?.run,
1415
1431
  },
1416
1432
  paragraph: {
1417
- ...(normal?.getParagraphFormatting() || Document.DEFAULT_NORMAL_CONFIG.paragraph),
1418
- ...options?.normal?.paragraph
1433
+ ...(normal?.getParagraphFormatting() ||
1434
+ Document.DEFAULT_NORMAL_CONFIG.paragraph),
1435
+ ...options?.normal?.paragraph,
1419
1436
  },
1420
1437
  };
1421
1438
  const listParaConfig = {
1422
1439
  run: {
1423
- ...(listParagraph?.getRunFormatting() || Document.DEFAULT_LIST_PARAGRAPH_CONFIG.run),
1424
- ...options?.listParagraph?.run
1440
+ ...(listParagraph?.getRunFormatting() ||
1441
+ Document.DEFAULT_LIST_PARAGRAPH_CONFIG.run),
1442
+ ...options?.listParagraph?.run,
1425
1443
  },
1426
1444
  paragraph: {
1427
- ...(listParagraph?.getParagraphFormatting() || Document.DEFAULT_LIST_PARAGRAPH_CONFIG.paragraph),
1428
- ...options?.listParagraph?.paragraph
1445
+ ...(listParagraph?.getParagraphFormatting() ||
1446
+ Document.DEFAULT_LIST_PARAGRAPH_CONFIG.paragraph),
1447
+ ...options?.listParagraph?.paragraph,
1429
1448
  },
1430
1449
  };
1431
1450
  const preserveBlankLines = options?.preserveBlankLinesAfterHeader2Tables ?? true;
@@ -1496,7 +1515,7 @@ class Document {
1496
1515
  continue;
1497
1516
  }
1498
1517
  const styleId = para.getStyle();
1499
- if (styleId === 'Heading1' && heading1) {
1518
+ if (styleId === "Heading1" && heading1) {
1500
1519
  para.clearDirectFormattingConflicts(heading1);
1501
1520
  for (const run of para.getRuns()) {
1502
1521
  if (!h1Preserve.bold) {
@@ -1506,25 +1525,33 @@ class Document {
1506
1525
  run.setItalic(h1Config.run?.italic ?? false);
1507
1526
  }
1508
1527
  if (!h1Preserve.underline) {
1509
- run.setUnderline(h1Config.run?.underline ? 'single' : false);
1528
+ run.setUnderline(h1Config.run?.underline ? "single" : false);
1510
1529
  }
1511
1530
  }
1512
1531
  if (para.formatting.paragraphMarkRunProperties) {
1513
1532
  const markProps = para.formatting.paragraphMarkRunProperties;
1514
- if (!h1Preserve.bold && h1Config.run?.bold === false && markProps.bold) {
1533
+ if (!h1Preserve.bold &&
1534
+ h1Config.run?.bold === false &&
1535
+ markProps.bold) {
1515
1536
  delete markProps.bold;
1516
1537
  }
1517
- if (!h1Preserve.italic && h1Config.run?.italic === false && markProps.italic) {
1538
+ if (!h1Preserve.italic &&
1539
+ h1Config.run?.italic === false &&
1540
+ markProps.italic) {
1518
1541
  delete markProps.italic;
1519
1542
  }
1520
- if (!h1Preserve.underline && h1Config.run?.underline === false && markProps.underline) {
1543
+ if (!h1Preserve.underline &&
1544
+ h1Config.run?.underline === false &&
1545
+ markProps.underline) {
1521
1546
  delete markProps.underline;
1522
1547
  }
1523
1548
  }
1524
1549
  processedParagraphs.add(para);
1525
1550
  }
1526
- else if (styleId === 'Heading2' && heading2) {
1527
- const hasContent = para.getRuns().some(run => run.getText().trim().length > 0);
1551
+ else if (styleId === "Heading2" && heading2) {
1552
+ const hasContent = para
1553
+ .getRuns()
1554
+ .some((run) => run.getText().trim().length > 0);
1528
1555
  if (!hasContent) {
1529
1556
  processedParagraphs.add(para);
1530
1557
  continue;
@@ -1538,18 +1565,24 @@ class Document {
1538
1565
  run.setItalic(h2Config.run?.italic ?? false);
1539
1566
  }
1540
1567
  if (!h2Preserve.underline) {
1541
- run.setUnderline(h2Config.run?.underline ? 'single' : false);
1568
+ run.setUnderline(h2Config.run?.underline ? "single" : false);
1542
1569
  }
1543
1570
  }
1544
1571
  if (para.formatting.paragraphMarkRunProperties) {
1545
1572
  const markProps = para.formatting.paragraphMarkRunProperties;
1546
- if (!h2Preserve.bold && h2Config.run?.bold === false && markProps.bold) {
1573
+ if (!h2Preserve.bold &&
1574
+ h2Config.run?.bold === false &&
1575
+ markProps.bold) {
1547
1576
  delete markProps.bold;
1548
1577
  }
1549
- if (!h2Preserve.italic && h2Config.run?.italic === false && markProps.italic) {
1578
+ if (!h2Preserve.italic &&
1579
+ h2Config.run?.italic === false &&
1580
+ markProps.italic) {
1550
1581
  delete markProps.italic;
1551
1582
  }
1552
- if (!h2Preserve.underline && h2Config.run?.underline === false && markProps.underline) {
1583
+ if (!h2Preserve.underline &&
1584
+ h2Config.run?.underline === false &&
1585
+ markProps.underline) {
1553
1586
  delete markProps.underline;
1554
1587
  }
1555
1588
  }
@@ -1558,8 +1591,10 @@ class Document {
1558
1591
  if (h2Config.tableOptions?.shading) {
1559
1592
  cell.setShading({ fill: h2Config.tableOptions.shading });
1560
1593
  }
1561
- if (h2Config.tableOptions?.marginTop !== undefined || h2Config.tableOptions?.marginBottom !== undefined ||
1562
- h2Config.tableOptions?.marginLeft !== undefined || h2Config.tableOptions?.marginRight !== undefined) {
1594
+ if (h2Config.tableOptions?.marginTop !== undefined ||
1595
+ h2Config.tableOptions?.marginBottom !== undefined ||
1596
+ h2Config.tableOptions?.marginLeft !== undefined ||
1597
+ h2Config.tableOptions?.marginRight !== undefined) {
1563
1598
  cell.setMargins({
1564
1599
  top: h2Config.tableOptions.marginTop ?? 0,
1565
1600
  bottom: h2Config.tableOptions.marginBottom ?? 0,
@@ -1568,7 +1603,7 @@ class Document {
1568
1603
  });
1569
1604
  }
1570
1605
  if (h2Config.tableOptions?.tableWidthPercent) {
1571
- const table = this.getAllTables().find(t => {
1606
+ const table = this.getAllTables().find((t) => {
1572
1607
  for (const row of t.getRows()) {
1573
1608
  for (const c of row.getCells()) {
1574
1609
  if (c === cell)
@@ -1579,13 +1614,13 @@ class Document {
1579
1614
  });
1580
1615
  if (table) {
1581
1616
  table.setWidth(h2Config.tableOptions.tableWidthPercent);
1582
- table.setWidthType('pct');
1617
+ table.setWidthType("pct");
1583
1618
  }
1584
1619
  }
1585
1620
  }
1586
1621
  else {
1587
1622
  const table = this.wrapParagraphInTable(para, {
1588
- shading: h2Config.tableOptions?.shading ?? 'BFBFBF',
1623
+ shading: h2Config.tableOptions?.shading ?? "BFBFBF",
1589
1624
  marginTop: h2Config.tableOptions?.marginTop ?? 0,
1590
1625
  marginBottom: h2Config.tableOptions?.marginBottom ?? 0,
1591
1626
  marginLeft: h2Config.tableOptions?.marginLeft ?? 115,
@@ -1602,12 +1637,12 @@ class Document {
1602
1637
  if (!content || content.length === 0)
1603
1638
  return true;
1604
1639
  for (const item of content) {
1605
- if (item.constructor.name === 'Hyperlink') {
1640
+ if (item.constructor.name === "Hyperlink") {
1606
1641
  return false;
1607
1642
  }
1608
1643
  if (item.getText) {
1609
1644
  const text = item.getText().trim();
1610
- if (text !== '')
1645
+ if (text !== "")
1611
1646
  return false;
1612
1647
  }
1613
1648
  }
@@ -1625,7 +1660,7 @@ class Document {
1625
1660
  }
1626
1661
  processedParagraphs.add(para);
1627
1662
  }
1628
- else if (styleId === 'Heading3' && heading3) {
1663
+ else if (styleId === "Heading3" && heading3) {
1629
1664
  para.clearDirectFormattingConflicts(heading3);
1630
1665
  for (const run of para.getRuns()) {
1631
1666
  if (!h3Preserve.bold) {
@@ -1635,31 +1670,37 @@ class Document {
1635
1670
  run.setItalic(h3Config.run?.italic ?? false);
1636
1671
  }
1637
1672
  if (!h3Preserve.underline) {
1638
- run.setUnderline(h3Config.run?.underline ? 'single' : false);
1673
+ run.setUnderline(h3Config.run?.underline ? "single" : false);
1639
1674
  }
1640
1675
  }
1641
1676
  if (para.formatting.paragraphMarkRunProperties) {
1642
1677
  const markProps = para.formatting.paragraphMarkRunProperties;
1643
- if (!h3Preserve.bold && h3Config.run?.bold === false && markProps.bold) {
1678
+ if (!h3Preserve.bold &&
1679
+ h3Config.run?.bold === false &&
1680
+ markProps.bold) {
1644
1681
  delete markProps.bold;
1645
1682
  }
1646
- if (!h3Preserve.italic && h3Config.run?.italic === false && markProps.italic) {
1683
+ if (!h3Preserve.italic &&
1684
+ h3Config.run?.italic === false &&
1685
+ markProps.italic) {
1647
1686
  delete markProps.italic;
1648
1687
  }
1649
- if (!h3Preserve.underline && h3Config.run?.underline === false && markProps.underline) {
1688
+ if (!h3Preserve.underline &&
1689
+ h3Config.run?.underline === false &&
1690
+ markProps.underline) {
1650
1691
  delete markProps.underline;
1651
1692
  }
1652
1693
  }
1653
1694
  processedParagraphs.add(para);
1654
1695
  }
1655
- else if (styleId === 'ListParagraph' && listParagraph) {
1656
- const preservedFormatting = para.getRuns().map(run => {
1696
+ else if (styleId === "ListParagraph" && listParagraph) {
1697
+ const preservedFormatting = para.getRuns().map((run) => {
1657
1698
  const fmt = run.getFormatting();
1658
1699
  return {
1659
1700
  run: run,
1660
1701
  bold: listParaPreserve.bold ? fmt.bold : undefined,
1661
1702
  italic: listParaPreserve.italic ? fmt.italic : undefined,
1662
- underline: listParaPreserve.underline ? fmt.underline : undefined
1703
+ underline: listParaPreserve.underline ? fmt.underline : undefined,
1663
1704
  };
1664
1705
  });
1665
1706
  para.clearDirectFormattingConflicts(listParagraph);
@@ -1682,31 +1723,37 @@ class Document {
1682
1723
  run.setItalic(listParaConfig.run?.italic ?? false);
1683
1724
  }
1684
1725
  if (!listParaPreserve.underline) {
1685
- run.setUnderline(listParaConfig.run?.underline ? 'single' : false);
1726
+ run.setUnderline(listParaConfig.run?.underline ? "single" : false);
1686
1727
  }
1687
1728
  }
1688
1729
  if (para.formatting.paragraphMarkRunProperties) {
1689
1730
  const markProps = para.formatting.paragraphMarkRunProperties;
1690
- if (!listParaPreserve.bold && listParaConfig.run?.bold === false && markProps.bold) {
1731
+ if (!listParaPreserve.bold &&
1732
+ listParaConfig.run?.bold === false &&
1733
+ markProps.bold) {
1691
1734
  delete markProps.bold;
1692
1735
  }
1693
- if (!listParaPreserve.italic && listParaConfig.run?.italic === false && markProps.italic) {
1736
+ if (!listParaPreserve.italic &&
1737
+ listParaConfig.run?.italic === false &&
1738
+ markProps.italic) {
1694
1739
  delete markProps.italic;
1695
1740
  }
1696
- if (!listParaPreserve.underline && listParaConfig.run?.underline === false && markProps.underline) {
1741
+ if (!listParaPreserve.underline &&
1742
+ listParaConfig.run?.underline === false &&
1743
+ markProps.underline) {
1697
1744
  delete markProps.underline;
1698
1745
  }
1699
1746
  }
1700
1747
  processedParagraphs.add(para);
1701
1748
  }
1702
- else if ((styleId === 'Normal' || styleId === undefined) && normal) {
1703
- const preservedFormatting = para.getRuns().map(run => {
1749
+ else if ((styleId === "Normal" || styleId === undefined) && normal) {
1750
+ const preservedFormatting = para.getRuns().map((run) => {
1704
1751
  const fmt = run.getFormatting();
1705
1752
  return {
1706
1753
  run: run,
1707
1754
  bold: normalPreserve.bold ? fmt.bold : undefined,
1708
1755
  italic: normalPreserve.italic ? fmt.italic : undefined,
1709
- underline: normalPreserve.underline ? fmt.underline : undefined
1756
+ underline: normalPreserve.underline ? fmt.underline : undefined,
1710
1757
  };
1711
1758
  });
1712
1759
  para.clearDirectFormattingConflicts(normal);
@@ -1729,18 +1776,24 @@ class Document {
1729
1776
  run.setItalic(normalConfig.run?.italic ?? false);
1730
1777
  }
1731
1778
  if (!normalPreserve.underline) {
1732
- run.setUnderline(normalConfig.run?.underline ? 'single' : false);
1779
+ run.setUnderline(normalConfig.run?.underline ? "single" : false);
1733
1780
  }
1734
1781
  }
1735
1782
  if (para.formatting.paragraphMarkRunProperties) {
1736
1783
  const markProps = para.formatting.paragraphMarkRunProperties;
1737
- if (!normalPreserve.bold && normalConfig.run?.bold === false && markProps.bold) {
1784
+ if (!normalPreserve.bold &&
1785
+ normalConfig.run?.bold === false &&
1786
+ markProps.bold) {
1738
1787
  delete markProps.bold;
1739
1788
  }
1740
- if (!normalPreserve.italic && normalConfig.run?.italic === false && markProps.italic) {
1789
+ if (!normalPreserve.italic &&
1790
+ normalConfig.run?.italic === false &&
1791
+ markProps.italic) {
1741
1792
  delete markProps.italic;
1742
1793
  }
1743
- if (!normalPreserve.underline && normalConfig.run?.underline === false && markProps.underline) {
1794
+ if (!normalPreserve.underline &&
1795
+ normalConfig.run?.underline === false &&
1796
+ markProps.underline) {
1744
1797
  delete markProps.underline;
1745
1798
  }
1746
1799
  }
@@ -1754,32 +1807,32 @@ class Document {
1754
1807
  for (const style of styles) {
1755
1808
  const styleId = style.getStyleId();
1756
1809
  switch (styleId) {
1757
- case 'Heading1':
1810
+ case "Heading1":
1758
1811
  options.heading1 = {
1759
1812
  run: style.getRunFormatting(),
1760
1813
  paragraph: style.getParagraphFormatting(),
1761
1814
  };
1762
1815
  break;
1763
- case 'Heading2':
1816
+ case "Heading2":
1764
1817
  options.heading2 = {
1765
1818
  run: style.getRunFormatting(),
1766
1819
  paragraph: style.getParagraphFormatting(),
1767
1820
  tableOptions: style.getHeading2TableOptions(),
1768
1821
  };
1769
1822
  break;
1770
- case 'Heading3':
1823
+ case "Heading3":
1771
1824
  options.heading3 = {
1772
1825
  run: style.getRunFormatting(),
1773
1826
  paragraph: style.getParagraphFormatting(),
1774
1827
  };
1775
1828
  break;
1776
- case 'Normal':
1829
+ case "Normal":
1777
1830
  options.normal = {
1778
1831
  run: style.getRunFormatting(),
1779
1832
  paragraph: style.getParagraphFormatting(),
1780
1833
  };
1781
1834
  break;
1782
- case 'ListParagraph':
1835
+ case "ListParagraph":
1783
1836
  options.listParagraph = {
1784
1837
  run: style.getRunFormatting(),
1785
1838
  paragraph: style.getParagraphFormatting(),
@@ -1842,7 +1895,7 @@ class Document {
1842
1895
  return {
1843
1896
  removed,
1844
1897
  preserved,
1845
- total: toRemove.length
1898
+ total: toRemove.length,
1846
1899
  };
1847
1900
  }
1848
1901
  processConsecutiveBlanks(blanks, keepOne, toRemove) {
@@ -1875,8 +1928,10 @@ class Document {
1875
1928
  let hasHeader2 = false;
1876
1929
  for (const para of cellParas) {
1877
1930
  const style = para.getStyle();
1878
- if (style === 'Heading2' || style === 'Heading 2' ||
1879
- style === 'CustomHeader2' || style === 'Header2') {
1931
+ if (style === "Heading2" ||
1932
+ style === "Heading 2" ||
1933
+ style === "CustomHeader2" ||
1934
+ style === "Header2") {
1880
1935
  hasHeader2 = true;
1881
1936
  break;
1882
1937
  }
@@ -1897,6 +1952,7 @@ class Document {
1897
1952
  ensureBlankLinesAfter1x1Tables(options) {
1898
1953
  const spacingAfter = options?.spacingAfter ?? 120;
1899
1954
  const markAsPreserved = options?.markAsPreserved ?? true;
1955
+ const style = options?.style ?? "Normal";
1900
1956
  const filter = options?.filter;
1901
1957
  let tablesProcessed = 0;
1902
1958
  let blankLinesAdded = 0;
@@ -1928,6 +1984,68 @@ class Document {
1928
1984
  }
1929
1985
  else {
1930
1986
  const blankPara = Paragraph_1.Paragraph.create();
1987
+ blankPara.setStyle(style);
1988
+ blankPara.setSpaceAfter(spacingAfter);
1989
+ if (markAsPreserved) {
1990
+ blankPara.setPreserved(true);
1991
+ }
1992
+ this.bodyElements.splice(tableIndex + 1, 0, blankPara);
1993
+ blankLinesAdded++;
1994
+ }
1995
+ }
1996
+ else {
1997
+ const blankPara = Paragraph_1.Paragraph.create();
1998
+ blankPara.setStyle(style);
1999
+ blankPara.setSpaceAfter(spacingAfter);
2000
+ if (markAsPreserved) {
2001
+ blankPara.setPreserved(true);
2002
+ }
2003
+ this.bodyElements.splice(tableIndex + 1, 0, blankPara);
2004
+ blankLinesAdded++;
2005
+ }
2006
+ }
2007
+ return {
2008
+ tablesProcessed,
2009
+ blankLinesAdded,
2010
+ existingLinesMarked,
2011
+ };
2012
+ }
2013
+ ensureBlankLinesAfterOtherTables(options) {
2014
+ const spacingAfter = options?.spacingAfter ?? 120;
2015
+ const markAsPreserved = options?.markAsPreserved ?? true;
2016
+ const style = options?.style ?? "Normal";
2017
+ const filter = options?.filter;
2018
+ let tablesProcessed = 0;
2019
+ let blankLinesAdded = 0;
2020
+ let existingLinesMarked = 0;
2021
+ const tables = this.getAllTables();
2022
+ for (let i = 0; i < tables.length; i++) {
2023
+ const table = tables[i];
2024
+ if (!table)
2025
+ continue;
2026
+ const rowCount = table.getRowCount();
2027
+ const colCount = table.getColumnCount();
2028
+ if (rowCount === 1 && colCount === 1) {
2029
+ continue;
2030
+ }
2031
+ if (filter && !filter(table, i)) {
2032
+ continue;
2033
+ }
2034
+ tablesProcessed++;
2035
+ const tableIndex = this.bodyElements.indexOf(table);
2036
+ if (tableIndex === -1)
2037
+ continue;
2038
+ const nextElement = this.bodyElements[tableIndex + 1];
2039
+ if (nextElement instanceof Paragraph_1.Paragraph) {
2040
+ if (this.isParagraphBlank(nextElement)) {
2041
+ if (markAsPreserved && !nextElement.isPreserved()) {
2042
+ nextElement.setPreserved(true);
2043
+ existingLinesMarked++;
2044
+ }
2045
+ }
2046
+ else {
2047
+ const blankPara = Paragraph_1.Paragraph.create();
2048
+ blankPara.setStyle(style);
1931
2049
  blankPara.setSpaceAfter(spacingAfter);
1932
2050
  if (markAsPreserved) {
1933
2051
  blankPara.setPreserved(true);
@@ -1938,6 +2056,7 @@ class Document {
1938
2056
  }
1939
2057
  else {
1940
2058
  const blankPara = Paragraph_1.Paragraph.create();
2059
+ blankPara.setStyle(style);
1941
2060
  blankPara.setSpaceAfter(spacingAfter);
1942
2061
  if (markAsPreserved) {
1943
2062
  blankPara.setPreserved(true);
@@ -1952,6 +2071,73 @@ class Document {
1952
2071
  existingLinesMarked,
1953
2072
  };
1954
2073
  }
2074
+ standardizeBulletSymbols(options) {
2075
+ const { bold = true, fontSize = 24, color = "000000", font = "Arial", } = options || {};
2076
+ let listsUpdated = 0;
2077
+ let levelsModified = 0;
2078
+ const instances = this.numberingManager.getAllInstances();
2079
+ for (const instance of instances) {
2080
+ const abstractNumId = instance.getAbstractNumId();
2081
+ const abstractNum = this.numberingManager.getAbstractNumbering(abstractNumId);
2082
+ if (!abstractNum)
2083
+ continue;
2084
+ const level0 = abstractNum.getLevel(0);
2085
+ if (!level0 || level0.getFormat() !== "bullet")
2086
+ continue;
2087
+ for (let levelIndex = 0; levelIndex < 9; levelIndex++) {
2088
+ const numLevel = abstractNum.getLevel(levelIndex);
2089
+ if (!numLevel)
2090
+ continue;
2091
+ numLevel.setFont(font);
2092
+ numLevel.setFontSize(fontSize);
2093
+ numLevel.setBold(bold);
2094
+ numLevel.setColor(color);
2095
+ levelsModified++;
2096
+ }
2097
+ listsUpdated++;
2098
+ }
2099
+ return { listsUpdated, levelsModified };
2100
+ }
2101
+ standardizeNumberedListPrefixes(options) {
2102
+ const { bold = true, fontSize = 24, color = "000000", font = "Verdana", } = options || {};
2103
+ let listsUpdated = 0;
2104
+ let levelsModified = 0;
2105
+ const instances = this.numberingManager.getAllInstances();
2106
+ for (const instance of instances) {
2107
+ const abstractNumId = instance.getAbstractNumId();
2108
+ const abstractNum = this.numberingManager.getAbstractNumbering(abstractNumId);
2109
+ if (!abstractNum)
2110
+ continue;
2111
+ const level0 = abstractNum.getLevel(0);
2112
+ if (!level0 || level0.getFormat() === "bullet")
2113
+ continue;
2114
+ for (let levelIndex = 0; levelIndex < 9; levelIndex++) {
2115
+ const numLevel = abstractNum.getLevel(levelIndex);
2116
+ if (!numLevel)
2117
+ continue;
2118
+ numLevel.setFont(font);
2119
+ numLevel.setFontSize(fontSize);
2120
+ numLevel.setBold(bold);
2121
+ numLevel.setColor(color);
2122
+ levelsModified++;
2123
+ }
2124
+ listsUpdated++;
2125
+ }
2126
+ return { listsUpdated, levelsModified };
2127
+ }
2128
+ standardizeAllHyperlinks(options) {
2129
+ const { font = "Verdana", size = 12, color = "0000FF", underline = true, } = options || {};
2130
+ const hyperlinks = this.getHyperlinks();
2131
+ for (const { hyperlink } of hyperlinks) {
2132
+ hyperlink.setFormatting({
2133
+ font: font,
2134
+ size: size,
2135
+ color: color,
2136
+ underline: underline ? "single" : false,
2137
+ });
2138
+ }
2139
+ return hyperlinks.length;
2140
+ }
1955
2141
  cleanFormatting(styleNames) {
1956
2142
  let cleaned = 0;
1957
2143
  for (const para of this.bodyElements) {
@@ -1970,24 +2156,26 @@ class Document {
1970
2156
  return cleaned;
1971
2157
  }
1972
2158
  applyH1(options) {
1973
- return this.applyStyleToMatching('Heading1', options, (style) => /^(heading\s*1|header\s*1|h1)$/i.test(style));
2159
+ return this.applyStyleToMatching("Heading1", options, (style) => /^(heading\s*1|header\s*1|h1)$/i.test(style));
1974
2160
  }
1975
2161
  applyH2(options) {
1976
- return this.applyStyleToMatching('Heading2', options, (style) => /^(heading\s*2|header\s*2|h2)$/i.test(style));
2162
+ return this.applyStyleToMatching("Heading2", options, (style) => /^(heading\s*2|header\s*2|h2)$/i.test(style));
1977
2163
  }
1978
2164
  applyH3(options) {
1979
- return this.applyStyleToMatching('Heading3', options, (style) => /^(heading\s*3|header\s*3|h3)$/i.test(style));
2165
+ return this.applyStyleToMatching("Heading3", options, (style) => /^(heading\s*3|header\s*3|h3)$/i.test(style));
1980
2166
  }
1981
2167
  applyNormal(options) {
1982
- const targets = options?.paragraphs || this.getAllParagraphs().filter(p => {
1983
- const style = p.getStyle();
1984
- return !style || !/^(heading|header|h\d|list|toc|tod|caution|table)/i.test(style);
1985
- });
2168
+ const targets = options?.paragraphs ||
2169
+ this.getAllParagraphs().filter((p) => {
2170
+ const style = p.getStyle();
2171
+ return (!style ||
2172
+ !/^(heading|header|h\d|list|toc|tod|caution|table)/i.test(style));
2173
+ });
1986
2174
  let count = 0;
1987
2175
  for (const para of targets) {
1988
2176
  if (para.isPreserved())
1989
2177
  continue;
1990
- para.setStyle('Normal');
2178
+ para.setStyle("Normal");
1991
2179
  if (options?.keepProperties && options.keepProperties.length > 0) {
1992
2180
  this.clearFormattingExcept(para, options.keepProperties);
1993
2181
  }
@@ -2002,19 +2190,19 @@ class Document {
2002
2190
  return count;
2003
2191
  }
2004
2192
  applyNumList(options) {
2005
- return this.applyStyleToMatching('ListParagraph', options, (style) => /^(list\s*number|numbered\s*list|list\s*paragraph)$/i.test(style));
2193
+ return this.applyStyleToMatching("ListParagraph", options, (style) => /^(list\s*number|numbered\s*list|list\s*paragraph)$/i.test(style));
2006
2194
  }
2007
2195
  applyBulletList(options) {
2008
- return this.applyStyleToMatching('ListParagraph', options, (style) => /^(list\s*bullet|bullet\s*list|list\s*paragraph)$/i.test(style));
2196
+ return this.applyStyleToMatching("ListParagraph", options, (style) => /^(list\s*bullet|bullet\s*list|list\s*paragraph)$/i.test(style));
2009
2197
  }
2010
2198
  applyTOC(options) {
2011
- return this.applyStyleToMatching('TOC', options, (style) => /^(toc|table\s*of\s*contents|toc\s*heading)$/i.test(style));
2199
+ return this.applyStyleToMatching("TOC", options, (style) => /^(toc|table\s*of\s*contents|toc\s*heading)$/i.test(style));
2012
2200
  }
2013
2201
  applyTOD(options) {
2014
- return this.applyStyleToMatching('TopOfDocument', options, (style) => /^(tod|top\s*of\s*document|document\s*top)$/i.test(style));
2202
+ return this.applyStyleToMatching("TopOfDocument", options, (style) => /^(tod|top\s*of\s*document|document\s*top)$/i.test(style));
2015
2203
  }
2016
2204
  applyCaution(options) {
2017
- return this.applyStyleToMatching('Caution', options, (style) => /^(caution|warning|important|alert)$/i.test(style));
2205
+ return this.applyStyleToMatching("Caution", options, (style) => /^(caution|warning|important|alert)$/i.test(style));
2018
2206
  }
2019
2207
  applyCellHeader(options) {
2020
2208
  let count = 0;
@@ -2027,7 +2215,7 @@ class Document {
2027
2215
  for (const para of cell.getParagraphs()) {
2028
2216
  if (para.isPreserved())
2029
2217
  continue;
2030
- para.setStyle('TableHeader');
2218
+ para.setStyle("TableHeader");
2031
2219
  if (options?.keepProperties && options.keepProperties.length > 0) {
2032
2220
  this.clearFormattingExcept(para, options.keepProperties);
2033
2221
  }
@@ -2062,13 +2250,13 @@ class Document {
2062
2250
  if (options.color)
2063
2251
  run.setColor(options.color);
2064
2252
  if (options.emphasis) {
2065
- options.emphasis.forEach(emp => {
2066
- if (emp === 'bold')
2253
+ options.emphasis.forEach((emp) => {
2254
+ if (emp === "bold")
2067
2255
  run.setBold(true);
2068
- if (emp === 'italic')
2256
+ if (emp === "italic")
2069
2257
  run.setItalic(true);
2070
- if (emp === 'underline')
2071
- run.setUnderline('single');
2258
+ if (emp === "underline")
2259
+ run.setUnderline("single");
2072
2260
  });
2073
2261
  }
2074
2262
  }
@@ -2153,10 +2341,11 @@ class Document {
2153
2341
  }
2154
2342
  }
2155
2343
  applyStyleToMatching(targetStyle, options, matcher) {
2156
- const targets = options?.paragraphs || this.getAllParagraphs().filter(p => {
2157
- const style = p.getStyle();
2158
- return style && matcher(style);
2159
- });
2344
+ const targets = options?.paragraphs ||
2345
+ this.getAllParagraphs().filter((p) => {
2346
+ const style = p.getStyle();
2347
+ return style && matcher(style);
2348
+ });
2160
2349
  let count = 0;
2161
2350
  for (const para of targets) {
2162
2351
  if (para.isPreserved())
@@ -2181,26 +2370,27 @@ class Document {
2181
2370
  return true;
2182
2371
  }
2183
2372
  for (const item of content) {
2184
- if (item.constructor.name === 'Hyperlink') {
2373
+ if (item.constructor.name === "Hyperlink") {
2185
2374
  return false;
2186
2375
  }
2187
- if (item.constructor.name === 'Shape') {
2376
+ if (item.constructor.name === "Shape") {
2188
2377
  return false;
2189
2378
  }
2190
- if (item.constructor.name === 'TextBox') {
2379
+ if (item.constructor.name === "TextBox") {
2191
2380
  return false;
2192
2381
  }
2193
- if (item.constructor.name === 'Field') {
2382
+ if (item.constructor.name === "Field") {
2194
2383
  return false;
2195
2384
  }
2196
2385
  if (item.getText) {
2197
2386
  const text = item.getText().trim();
2198
- if (text !== '') {
2387
+ if (text !== "") {
2199
2388
  return false;
2200
2389
  }
2201
2390
  }
2202
2391
  }
2203
- if (para.getBookmarksStart().length > 0 || para.getBookmarksEnd().length > 0) {
2392
+ if (para.getBookmarksStart().length > 0 ||
2393
+ para.getBookmarksEnd().length > 0) {
2204
2394
  return false;
2205
2395
  }
2206
2396
  return true;
@@ -2222,7 +2412,10 @@ class Document {
2222
2412
  const content = match[1];
2223
2413
  if (!content)
2224
2414
  continue;
2225
- const parts = content.split(',').map(p => p.trim()).filter(p => p);
2415
+ const parts = content
2416
+ .split(",")
2417
+ .map((p) => p.trim())
2418
+ .filter((p) => p);
2226
2419
  if (parts.length < 2)
2227
2420
  continue;
2228
2421
  const styleName = parts[0];
@@ -2253,20 +2446,20 @@ class Document {
2253
2446
  const levelSet = new Set(levels);
2254
2447
  try {
2255
2448
  const parsed = XMLParser_1.XMLParser.parseToObject(docXml, { trimValues: false });
2256
- const document = parsed['w:document'];
2449
+ const document = parsed["w:document"];
2257
2450
  if (!document) {
2258
2451
  return headings;
2259
2452
  }
2260
- const body = document['w:body'];
2453
+ const body = document["w:body"];
2261
2454
  if (!body) {
2262
2455
  return headings;
2263
2456
  }
2264
2457
  const extractHeading = (para) => {
2265
- const pPr = para['w:pPr'];
2266
- if (!pPr || !pPr['w:pStyle']) {
2458
+ const pPr = para["w:pPr"];
2459
+ if (!pPr || !pPr["w:pStyle"]) {
2267
2460
  return;
2268
2461
  }
2269
- const styleVal = pPr['w:pStyle']['@_w:val'];
2462
+ const styleVal = pPr["w:pStyle"]["@_w:val"];
2270
2463
  if (!styleVal) {
2271
2464
  return;
2272
2465
  }
@@ -2278,30 +2471,32 @@ class Document {
2278
2471
  if (!levelSet.has(headingLevel)) {
2279
2472
  return;
2280
2473
  }
2281
- let bookmark = '';
2282
- const bookmarkStart = para['w:bookmarkStart'];
2474
+ let bookmark = "";
2475
+ const bookmarkStart = para["w:bookmarkStart"];
2283
2476
  if (bookmarkStart) {
2284
- const bookmarkArray = Array.isArray(bookmarkStart) ? bookmarkStart : [bookmarkStart];
2477
+ const bookmarkArray = Array.isArray(bookmarkStart)
2478
+ ? bookmarkStart
2479
+ : [bookmarkStart];
2285
2480
  for (const bm of bookmarkArray) {
2286
- const bmName = bm['@_w:name'];
2287
- if (bmName && bmName.toLowerCase().includes('_heading')) {
2481
+ const bmName = bm["@_w:name"];
2482
+ if (bmName && bmName.toLowerCase().includes("_heading")) {
2288
2483
  bookmark = bmName;
2289
2484
  break;
2290
2485
  }
2291
2486
  }
2292
2487
  }
2293
- let text = '';
2294
- const runs = para['w:r'];
2488
+ let text = "";
2489
+ const runs = para["w:r"];
2295
2490
  if (runs) {
2296
2491
  const runArray = Array.isArray(runs) ? runs : [runs];
2297
2492
  for (const run of runArray) {
2298
- const textElement = run['w:t'];
2493
+ const textElement = run["w:t"];
2299
2494
  if (textElement) {
2300
- if (typeof textElement === 'string') {
2495
+ if (typeof textElement === "string") {
2301
2496
  text += textElement;
2302
2497
  }
2303
- else if (textElement['#text']) {
2304
- text += textElement['#text'];
2498
+ else if (textElement["#text"]) {
2499
+ text += textElement["#text"];
2305
2500
  }
2306
2501
  }
2307
2502
  }
@@ -2316,34 +2511,36 @@ class Document {
2316
2511
  headings.push({
2317
2512
  level: headingLevel,
2318
2513
  text: text,
2319
- bookmark: bookmark
2514
+ bookmark: bookmark,
2320
2515
  });
2321
2516
  };
2322
- const paragraphs = body['w:p'];
2517
+ const paragraphs = body["w:p"];
2323
2518
  if (paragraphs) {
2324
2519
  const paraArray = Array.isArray(paragraphs) ? paragraphs : [paragraphs];
2325
2520
  for (const para of paraArray) {
2326
2521
  extractHeading(para);
2327
2522
  }
2328
2523
  }
2329
- const tables = body['w:tbl'];
2524
+ const tables = body["w:tbl"];
2330
2525
  if (tables) {
2331
2526
  const tableArray = Array.isArray(tables) ? tables : [tables];
2332
2527
  for (const table of tableArray) {
2333
- const rows = table['w:tr'];
2528
+ const rows = table["w:tr"];
2334
2529
  if (!rows)
2335
2530
  continue;
2336
2531
  const rowArray = Array.isArray(rows) ? rows : [rows];
2337
2532
  for (const row of rowArray) {
2338
- const cells = row['w:tc'];
2533
+ const cells = row["w:tc"];
2339
2534
  if (!cells)
2340
2535
  continue;
2341
2536
  const cellArray = Array.isArray(cells) ? cells : [cells];
2342
2537
  for (const cell of cellArray) {
2343
- const cellParas = cell['w:p'];
2538
+ const cellParas = cell["w:p"];
2344
2539
  if (!cellParas)
2345
2540
  continue;
2346
- const cellParaArray = Array.isArray(cellParas) ? cellParas : [cellParas];
2541
+ const cellParaArray = Array.isArray(cellParas)
2542
+ ? cellParas
2543
+ : [cellParas];
2347
2544
  for (const para of cellParaArray) {
2348
2545
  extractHeading(para);
2349
2546
  }
@@ -2353,7 +2550,9 @@ class Document {
2353
2550
  }
2354
2551
  }
2355
2552
  catch (error) {
2356
- logger_1.defaultLogger.error('Error parsing document.xml for headings:', error instanceof Error ? { message: error.message, stack: error.stack } : { error: String(error) });
2553
+ logger_1.defaultLogger.error("Error parsing document.xml for headings:", error instanceof Error
2554
+ ? { message: error.message, stack: error.stack }
2555
+ : { error: String(error) });
2357
2556
  }
2358
2557
  return headings;
2359
2558
  }
@@ -2375,7 +2574,7 @@ class Document {
2375
2574
  headings.push({
2376
2575
  level: headingLevel,
2377
2576
  text: text,
2378
- bookmark: bookmark.getName()
2577
+ bookmark: bookmark.getName(),
2379
2578
  });
2380
2579
  }
2381
2580
  }
@@ -2387,93 +2586,95 @@ class Document {
2387
2586
  }
2388
2587
  generateTOCXML(headings, originalInstrText) {
2389
2588
  const sdtId = Math.floor(Math.random() * 2000000000) - 1000000000;
2390
- let tocXml = '<w:sdt>';
2391
- tocXml += '<w:sdtPr>';
2589
+ let tocXml = "<w:sdt>";
2590
+ tocXml += "<w:sdtPr>";
2392
2591
  tocXml += `<w:id w:val="${sdtId}"/>`;
2393
- tocXml += '<w:docPartObj>';
2592
+ tocXml += "<w:docPartObj>";
2394
2593
  tocXml += '<w:docPartGallery w:val="Table of Contents"/>';
2395
2594
  tocXml += '<w:docPartUnique w:val="1"/>';
2396
- tocXml += '</w:docPartObj>';
2397
- tocXml += '</w:sdtPr>';
2398
- tocXml += '<w:sdtContent>';
2399
- const minLevel = headings.length > 0
2400
- ? Math.min(...headings.map(h => h.level))
2401
- : 1;
2402
- tocXml += '<w:p>';
2403
- tocXml += '<w:pPr>';
2404
- tocXml += '<w:spacing w:after="0" w:before="0" w:line="240" w:lineRule="auto"/>';
2595
+ tocXml += "</w:docPartObj>";
2596
+ tocXml += "</w:sdtPr>";
2597
+ tocXml += "<w:sdtContent>";
2598
+ const minLevel = headings.length > 0 ? Math.min(...headings.map((h) => h.level)) : 1;
2599
+ tocXml += "<w:p>";
2600
+ tocXml += "<w:pPr>";
2601
+ tocXml +=
2602
+ '<w:spacing w:after="0" w:before="0" w:line="240" w:lineRule="auto"/>';
2405
2603
  if (headings.length > 0 && headings[0]) {
2406
2604
  const firstIndent = (headings[0].level - minLevel) * 360;
2407
2605
  if (firstIndent > 0) {
2408
2606
  tocXml += `<w:ind w:left="${firstIndent}"/>`;
2409
2607
  }
2410
2608
  }
2411
- tocXml += '</w:pPr>';
2609
+ tocXml += "</w:pPr>";
2412
2610
  tocXml += '<w:r><w:fldChar w:fldCharType="begin"/></w:r>';
2413
- tocXml += '<w:r>';
2611
+ tocXml += "<w:r>";
2414
2612
  tocXml += `<w:instrText xml:space="preserve">${this.escapeXml(originalInstrText)}</w:instrText>`;
2415
- tocXml += '</w:r>';
2613
+ tocXml += "</w:r>";
2416
2614
  tocXml += '<w:r><w:fldChar w:fldCharType="separate"/></w:r>';
2417
2615
  if (headings.length > 0 && headings[0]) {
2418
2616
  tocXml += this.buildTOCEntryXML(headings[0]);
2419
2617
  }
2420
- tocXml += '</w:p>';
2618
+ tocXml += "</w:p>";
2421
2619
  for (let i = 1; i < headings.length; i++) {
2422
2620
  const heading = headings[i];
2423
2621
  if (!heading)
2424
2622
  continue;
2425
- tocXml += '<w:p>';
2426
- tocXml += '<w:pPr>';
2427
- tocXml += '<w:spacing w:after="0" w:before="0" w:line="240" w:lineRule="auto"/>';
2623
+ tocXml += "<w:p>";
2624
+ tocXml += "<w:pPr>";
2625
+ tocXml +=
2626
+ '<w:spacing w:after="0" w:before="0" w:line="240" w:lineRule="auto"/>';
2428
2627
  const indent = (heading.level - minLevel) * 360;
2429
2628
  if (indent > 0) {
2430
2629
  tocXml += `<w:ind w:left="${indent}"/>`;
2431
2630
  }
2432
- tocXml += '</w:pPr>';
2631
+ tocXml += "</w:pPr>";
2433
2632
  tocXml += this.buildTOCEntryXML(heading);
2434
- tocXml += '</w:p>';
2633
+ tocXml += "</w:p>";
2435
2634
  }
2436
- tocXml += '<w:p>';
2437
- tocXml += '<w:pPr>';
2438
- tocXml += '<w:spacing w:after="0" w:before="0" w:line="240" w:lineRule="auto"/>';
2439
- tocXml += '</w:pPr>';
2635
+ tocXml += "<w:p>";
2636
+ tocXml += "<w:pPr>";
2637
+ tocXml +=
2638
+ '<w:spacing w:after="0" w:before="0" w:line="240" w:lineRule="auto"/>';
2639
+ tocXml += "</w:pPr>";
2440
2640
  tocXml += '<w:r><w:fldChar w:fldCharType="end"/></w:r>';
2441
- tocXml += '</w:p>';
2442
- tocXml += '</w:sdtContent>';
2443
- tocXml += '</w:sdt>';
2641
+ tocXml += "</w:p>";
2642
+ tocXml += "</w:sdtContent>";
2643
+ tocXml += "</w:sdt>";
2444
2644
  return tocXml;
2445
2645
  }
2446
2646
  buildTOCEntryXML(heading) {
2447
2647
  const escapedText = this.escapeXml(heading.text);
2448
- let xml = '';
2648
+ let xml = "";
2449
2649
  xml += `<w:hyperlink w:anchor="${this.escapeXml(heading.bookmark)}">`;
2450
- xml += '<w:r>';
2451
- xml += '<w:rPr>';
2452
- xml += '<w:rFonts w:ascii="Verdana" w:hAnsi="Verdana" w:cs="Verdana" w:eastAsia="Verdana"/>';
2650
+ xml += "<w:r>";
2651
+ xml += "<w:rPr>";
2652
+ xml +=
2653
+ '<w:rFonts w:ascii="Verdana" w:hAnsi="Verdana" w:cs="Verdana" w:eastAsia="Verdana"/>';
2453
2654
  xml += '<w:color w:val="0000FF"/>';
2454
2655
  xml += '<w:sz w:val="24"/>';
2455
2656
  xml += '<w:szCs w:val="24"/>';
2456
2657
  xml += '<w:u w:val="single"/>';
2457
- xml += '</w:rPr>';
2658
+ xml += "</w:rPr>";
2458
2659
  xml += `<w:t xml:space="preserve">${escapedText}</w:t>`;
2459
- xml += '</w:r>';
2460
- xml += '</w:hyperlink>';
2660
+ xml += "</w:r>";
2661
+ xml += "</w:hyperlink>";
2461
2662
  return xml;
2462
2663
  }
2463
2664
  escapeXml(text) {
2464
2665
  return text
2465
- .replace(/&/g, '&amp;')
2466
- .replace(/</g, '&lt;')
2467
- .replace(/>/g, '&gt;')
2468
- .replace(/"/g, '&quot;')
2469
- .replace(/'/g, '&apos;');
2666
+ .replace(/&/g, "&amp;")
2667
+ .replace(/</g, "&lt;")
2668
+ .replace(/>/g, "&gt;")
2669
+ .replace(/"/g, "&quot;")
2670
+ .replace(/'/g, "&apos;");
2470
2671
  }
2471
2672
  async replaceTableOfContents(filePath) {
2472
2673
  const handler = new ZipHandler_1.ZipHandler();
2473
2674
  await handler.load(filePath);
2474
- const docXml = handler.getFileAsString('word/document.xml');
2675
+ const docXml = handler.getFileAsString("word/document.xml");
2475
2676
  if (!docXml) {
2476
- throw new Error('word/document.xml not found in document');
2677
+ throw new Error("word/document.xml not found in document");
2477
2678
  }
2478
2679
  const tocRegex = /<w:sdt>[\s\S]*?<w:docPartGallery w:val="Table of Contents"[\s\S]*?<\/w:sdt>/g;
2479
2680
  const tocMatches = Array.from(docXml.matchAll(tocRegex));
@@ -2491,9 +2692,9 @@ class Document {
2491
2692
  }
2492
2693
  let fieldInstruction = instrMatch[1];
2493
2694
  fieldInstruction = fieldInstruction
2494
- .replace(/&amp;/g, '&')
2495
- .replace(/&lt;/g, '<')
2496
- .replace(/&gt;/g, '>')
2695
+ .replace(/&amp;/g, "&")
2696
+ .replace(/&lt;/g, "<")
2697
+ .replace(/&gt;/g, ">")
2497
2698
  .replace(/&quot;/g, '"')
2498
2699
  .replace(/&apos;/g, "'");
2499
2700
  const levels = this.parseTOCFieldInstruction(fieldInstruction);
@@ -2511,7 +2712,7 @@ class Document {
2511
2712
  }
2512
2713
  }
2513
2714
  if (replacedCount > 0) {
2514
- handler.updateFile('word/document.xml', modifiedXml);
2715
+ handler.updateFile("word/document.xml", modifiedXml);
2515
2716
  await handler.save(filePath);
2516
2717
  }
2517
2718
  return replacedCount;
@@ -2743,7 +2944,7 @@ class Document {
2743
2944
  bookmark = new Bookmark_1.Bookmark({
2744
2945
  id: 0,
2745
2946
  name: BOOKMARK_NAME,
2746
- skipNormalization: true
2947
+ skipNormalization: true,
2747
2948
  });
2748
2949
  this.bookmarkManager.register(bookmark);
2749
2950
  const paragraphs = this.getParagraphs();
@@ -2761,7 +2962,7 @@ class Document {
2761
2962
  anchor: BOOKMARK_NAME,
2762
2963
  hyperlink: (text, formatting) => {
2763
2964
  return Hyperlink_1.Hyperlink.createInternal(BOOKMARK_NAME, text, formatting);
2764
- }
2965
+ },
2765
2966
  };
2766
2967
  }
2767
2968
  getRevisionManager() {
@@ -2814,13 +3015,15 @@ class Document {
2814
3015
  this.trackFormatting = options.trackFormatting;
2815
3016
  }
2816
3017
  if (options.showInsertionsAndDeletions !== undefined) {
2817
- this.revisionViewSettings.showInsertionsAndDeletions = options.showInsertionsAndDeletions;
3018
+ this.revisionViewSettings.showInsertionsAndDeletions =
3019
+ options.showInsertionsAndDeletions;
2818
3020
  }
2819
3021
  if (options.showFormatting !== undefined) {
2820
3022
  this.revisionViewSettings.showFormatting = options.showFormatting;
2821
3023
  }
2822
3024
  if (options.showInkAnnotations !== undefined) {
2823
- this.revisionViewSettings.showInkAnnotations = options.showInkAnnotations;
3025
+ this.revisionViewSettings.showInkAnnotations =
3026
+ options.showInkAnnotations;
2824
3027
  }
2825
3028
  }
2826
3029
  return this;
@@ -2840,7 +3043,7 @@ class Document {
2840
3043
  }
2841
3044
  setRsidRoot(rsidRoot) {
2842
3045
  if (!/^[0-9A-Fa-f]{8}$/.test(rsidRoot)) {
2843
- throw new Error('RSID must be an 8-character hexadecimal value');
3046
+ throw new Error("RSID must be an 8-character hexadecimal value");
2844
3047
  }
2845
3048
  this.rsidRoot = rsidRoot.toUpperCase();
2846
3049
  this.rsids.add(this.rsidRoot);
@@ -2848,13 +3051,16 @@ class Document {
2848
3051
  }
2849
3052
  addRsid(rsid) {
2850
3053
  if (!/^[0-9A-Fa-f]{8}$/.test(rsid)) {
2851
- throw new Error('RSID must be an 8-character hexadecimal value');
3054
+ throw new Error("RSID must be an 8-character hexadecimal value");
2852
3055
  }
2853
3056
  this.rsids.add(rsid.toUpperCase());
2854
3057
  return this;
2855
3058
  }
2856
3059
  generateRsid() {
2857
- const rsid = Math.floor(Math.random() * 0xFFFFFFFF).toString(16).toUpperCase().padStart(8, '0');
3060
+ const rsid = Math.floor(Math.random() * 0xffffffff)
3061
+ .toString(16)
3062
+ .toUpperCase()
3063
+ .padStart(8, "0");
2858
3064
  this.rsids.add(rsid);
2859
3065
  return rsid;
2860
3066
  }
@@ -2875,9 +3081,11 @@ class Document {
2875
3081
  cryptSpinCount: protection.cryptSpinCount,
2876
3082
  };
2877
3083
  if (protection.password) {
2878
- const crypto = require('crypto');
2879
- const salt = crypto.randomBytes(16).toString('base64');
2880
- const hash = crypto.pbkdf2Sync(protection.password, salt, protection.cryptSpinCount || 100000, 32, 'sha512').toString('base64');
3084
+ const crypto = require("crypto");
3085
+ const salt = crypto.randomBytes(16).toString("base64");
3086
+ const hash = crypto
3087
+ .pbkdf2Sync(protection.password, salt, protection.cryptSpinCount || 100000, 32, "sha512")
3088
+ .toString("base64");
2881
3089
  this.documentProtection.hash = hash;
2882
3090
  this.documentProtection.salt = salt;
2883
3091
  }
@@ -2914,7 +3122,9 @@ class Document {
2914
3122
  return this.revisionManager.register(revision);
2915
3123
  }
2916
3124
  trackMove(author, content, date) {
2917
- const moveId = `move${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
3125
+ const moveId = `move${Date.now()}_${Math.random()
3126
+ .toString(36)
3127
+ .substr(2, 9)}`;
2918
3128
  const moveName = `move${Date.now()}`;
2919
3129
  const rangeIdStart = this.revisionManager.getStats().nextId;
2920
3130
  const moveFromRangeStart = RangeMarker_1.RangeMarker.createMoveFromStart(rangeIdStart, moveName, author, date);
@@ -3065,7 +3275,7 @@ class Document {
3065
3275
  }
3066
3276
  let content = file.content;
3067
3277
  if (!file.isBinary && Buffer.isBuffer(file.content)) {
3068
- content = file.content.toString('utf-8');
3278
+ content = file.content.toString("utf-8");
3069
3279
  }
3070
3280
  return {
3071
3281
  name: partName,
@@ -3423,20 +3633,20 @@ class Document {
3423
3633
  return replacementCount;
3424
3634
  }
3425
3635
  findAndReplaceAll(pattern, replacement, options) {
3426
- const { caseSensitive = false, wholeWord = false, trackChanges = false, author = 'Unknown', } = options || {};
3636
+ const { caseSensitive = false, wholeWord = false, trackChanges = false, author = "Unknown", } = options || {};
3427
3637
  let count = 0;
3428
3638
  const revisions = [];
3429
3639
  let regex;
3430
- if (typeof pattern === 'string') {
3431
- const escaped = pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
3640
+ if (typeof pattern === "string") {
3641
+ const escaped = pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3432
3642
  const boundaryPattern = wholeWord ? `\\b${escaped}\\b` : escaped;
3433
- const flags = caseSensitive ? 'g' : 'gi';
3643
+ const flags = caseSensitive ? "g" : "gi";
3434
3644
  regex = new RegExp(boundaryPattern, flags);
3435
3645
  }
3436
3646
  else {
3437
- const flags = pattern.flags.includes('g')
3647
+ const flags = pattern.flags.includes("g")
3438
3648
  ? pattern.flags
3439
- : pattern.flags + 'g';
3649
+ : pattern.flags + "g";
3440
3650
  regex = new RegExp(pattern.source, flags);
3441
3651
  }
3442
3652
  const runs = this.getAllRuns();
@@ -3568,14 +3778,14 @@ class Document {
3568
3778
  }
3569
3779
  validateParagraph(paragraph) {
3570
3780
  if (!(paragraph instanceof Paragraph_1.Paragraph)) {
3571
- throw new Error('insertParagraphAt: parameter must be a Paragraph instance');
3781
+ throw new Error("insertParagraphAt: parameter must be a Paragraph instance");
3572
3782
  }
3573
3783
  const paraId = paragraph.getFormatting().paraId;
3574
3784
  if (paraId) {
3575
3785
  const existingIds = this.bodyElements
3576
3786
  .filter((el) => el instanceof Paragraph_1.Paragraph)
3577
- .map(p => p.getFormatting().paraId)
3578
- .filter(id => id === paraId);
3787
+ .map((p) => p.getFormatting().paraId)
3788
+ .filter((id) => id === paraId);
3579
3789
  if (existingIds.length > 0) {
3580
3790
  throw new Error(`Duplicate paragraph ID detected: ${paraId}. Each paragraph must have a unique ID.`);
3581
3791
  }
@@ -3591,15 +3801,15 @@ class Document {
3591
3801
  }
3592
3802
  validateTable(table) {
3593
3803
  if (!(table instanceof Table_1.Table)) {
3594
- throw new Error('insertTableAt: parameter must be a Table instance');
3804
+ throw new Error("insertTableAt: parameter must be a Table instance");
3595
3805
  }
3596
3806
  const rows = table.getRows();
3597
3807
  if (rows.length === 0) {
3598
- throw new Error('insertTableAt: table must have at least one row');
3808
+ throw new Error("insertTableAt: table must have at least one row");
3599
3809
  }
3600
3810
  const firstRow = rows[0];
3601
3811
  if (firstRow && firstRow.getCells().length === 0) {
3602
- throw new Error('insertTableAt: table rows must have at least one cell');
3812
+ throw new Error("insertTableAt: table rows must have at least one cell");
3603
3813
  }
3604
3814
  const tableStyle = table.getFormatting().style;
3605
3815
  if (tableStyle && !this.stylesManager.hasStyle(tableStyle)) {
@@ -3608,12 +3818,21 @@ class Document {
3608
3818
  }
3609
3819
  validateToc(toc) {
3610
3820
  if (!(toc instanceof TableOfContentsElement_1.TableOfContentsElement)) {
3611
- throw new Error('insertTocAt: parameter must be a TableOfContentsElement instance');
3612
- }
3613
- const hasHeadings = ['Heading1', 'Heading2', 'Heading3', 'Heading4', 'Heading5', 'Heading6', 'Heading7', 'Heading8', 'Heading9']
3614
- .some(style => this.stylesManager.hasStyle(style));
3821
+ throw new Error("insertTocAt: parameter must be a TableOfContentsElement instance");
3822
+ }
3823
+ const hasHeadings = [
3824
+ "Heading1",
3825
+ "Heading2",
3826
+ "Heading3",
3827
+ "Heading4",
3828
+ "Heading5",
3829
+ "Heading6",
3830
+ "Heading7",
3831
+ "Heading8",
3832
+ "Heading9",
3833
+ ].some((style) => this.stylesManager.hasStyle(style));
3615
3834
  if (!hasHeadings) {
3616
- logger_1.defaultLogger.warn('No heading styles found in document. Table of Contents may not display entries correctly.');
3835
+ logger_1.defaultLogger.warn("No heading styles found in document. Table of Contents may not display entries correctly.");
3617
3836
  }
3618
3837
  }
3619
3838
  normalizeIndex(index) {
@@ -3835,7 +4054,7 @@ class Document {
3835
4054
  const toRemove = [];
3836
4055
  this.bodyElements.forEach((element, index) => {
3837
4056
  if (element instanceof Paragraph_1.Paragraph) {
3838
- const isEmpty = element.getText().trim() === '';
4057
+ const isEmpty = element.getText().trim() === "";
3839
4058
  if (isEmpty && lastWasEmpty) {
3840
4059
  toRemove.push(index);
3841
4060
  }
@@ -3862,7 +4081,7 @@ class Document {
3862
4081
  }
3863
4082
  }
3864
4083
  if (standardLineSpacing !== undefined) {
3865
- para.setLineSpacing(standardLineSpacing, 'auto');
4084
+ para.setLineSpacing(standardLineSpacing, "auto");
3866
4085
  normalized++;
3867
4086
  }
3868
4087
  if (removeTrailingSpaces) {
@@ -3896,7 +4115,7 @@ class Document {
3896
4115
  }
3897
4116
  }
3898
4117
  if (standardLineSpacing !== undefined) {
3899
- para.setLineSpacing(standardLineSpacing, 'auto');
4118
+ para.setLineSpacing(standardLineSpacing, "auto");
3900
4119
  normalized++;
3901
4120
  }
3902
4121
  if (removeTrailingSpaces) {