docxmlater 1.16.0 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +491 -259
  2. package/dist/core/Document.d.ts +22 -2
  3. package/dist/core/Document.d.ts.map +1 -1
  4. package/dist/core/Document.js +199 -7
  5. package/dist/core/Document.js.map +1 -1
  6. package/dist/core/DocumentParser.d.ts.map +1 -1
  7. package/dist/core/DocumentParser.js +41 -42
  8. package/dist/core/DocumentParser.js.map +1 -1
  9. package/dist/core/DocumentValidator.d.ts.map +1 -1
  10. package/dist/core/DocumentValidator.js +4 -3
  11. package/dist/core/DocumentValidator.js.map +1 -1
  12. package/dist/elements/Hyperlink.d.ts +1 -0
  13. package/dist/elements/Hyperlink.d.ts.map +1 -1
  14. package/dist/elements/Hyperlink.js +57 -36
  15. package/dist/elements/Hyperlink.js.map +1 -1
  16. package/dist/elements/ImageManager.d.ts.map +1 -1
  17. package/dist/elements/ImageManager.js +2 -1
  18. package/dist/elements/ImageManager.js.map +1 -1
  19. package/dist/elements/Paragraph.d.ts +3 -0
  20. package/dist/elements/Paragraph.d.ts.map +1 -1
  21. package/dist/elements/Paragraph.js +11 -2
  22. package/dist/elements/Paragraph.js.map +1 -1
  23. package/dist/elements/Run.d.ts.map +1 -1
  24. package/dist/elements/Run.js +6 -4
  25. package/dist/elements/Run.js.map +1 -1
  26. package/dist/elements/StructuredDocumentTag.d.ts +2 -0
  27. package/dist/elements/StructuredDocumentTag.d.ts.map +1 -1
  28. package/dist/elements/StructuredDocumentTag.js +5 -1
  29. package/dist/elements/StructuredDocumentTag.js.map +1 -1
  30. package/dist/elements/Table.d.ts.map +1 -1
  31. package/dist/elements/Table.js +3 -2
  32. package/dist/elements/Table.js.map +1 -1
  33. package/dist/formatting/AbstractNumbering.d.ts.map +1 -1
  34. package/dist/formatting/AbstractNumbering.js +2 -1
  35. package/dist/formatting/AbstractNumbering.js.map +1 -1
  36. package/dist/formatting/NumberingManager.d.ts.map +1 -1
  37. package/dist/formatting/NumberingManager.js +6 -5
  38. package/dist/formatting/NumberingManager.js.map +1 -1
  39. package/dist/formatting/Style.d.ts.map +1 -1
  40. package/dist/formatting/Style.js +2 -1
  41. package/dist/formatting/Style.js.map +1 -1
  42. package/dist/types/styleConfig.d.ts +1 -0
  43. package/dist/types/styleConfig.d.ts.map +1 -1
  44. package/dist/utils/deepClone.d.ts +3 -0
  45. package/dist/utils/deepClone.d.ts.map +1 -0
  46. package/dist/utils/deepClone.js +50 -0
  47. package/dist/utils/deepClone.js.map +1 -0
  48. package/dist/utils/validation.d.ts.map +1 -1
  49. package/dist/utils/validation.js +3 -2
  50. package/dist/utils/validation.js.map +1 -1
  51. package/dist/zip/ZipHandler.d.ts.map +1 -1
  52. package/dist/zip/ZipHandler.js +3 -2
  53. package/dist/zip/ZipHandler.js.map +1 -1
  54. package/package.json +6 -4
@@ -54,6 +54,7 @@ const Style_1 = require("../formatting/Style");
54
54
  const AbstractNumbering_1 = require("../formatting/AbstractNumbering");
55
55
  const NumberingInstance_1 = require("../formatting/NumberingInstance");
56
56
  const diagnostics_1 = require("../utils/diagnostics");
57
+ const logger_1 = require("../utils/logger");
57
58
  class DocumentParser {
58
59
  parseErrors = [];
59
60
  strictParsing;
@@ -236,7 +237,7 @@ class DocumentParser {
236
237
  element: "document-validation",
237
238
  error: warning,
238
239
  });
239
- console.warn(`\nDocXML Load Warning:\n${warning.message}\n`);
240
+ logger_1.defaultLogger.warn(`\nDocXML Load Warning:\n${warning.message}\n`);
240
241
  }
241
242
  else if (emptyPercentage > 50 && emptyRuns > 5) {
242
243
  const warning = new Error(`Document has ${emptyRuns} out of ${totalRuns} runs (${emptyPercentage.toFixed(1)}%) with no text. ` +
@@ -245,7 +246,7 @@ class DocumentParser {
245
246
  element: "document-validation",
246
247
  error: warning,
247
248
  });
248
- console.warn(`\nDocXML Load Warning:\n${warning.message}\n`);
249
+ logger_1.defaultLogger.warn(`\nDocXML Load Warning:\n${warning.message}\n`);
249
250
  }
250
251
  }
251
252
  }
@@ -838,7 +839,7 @@ class DocumentParser {
838
839
  }
839
840
  let displayText = text || url || '[Link]';
840
841
  if (!text && anchor) {
841
- console.warn(`[DocumentParser] Hyperlink to anchor "${anchor}" has no display text. ` +
842
+ logger_1.defaultLogger.warn(`[DocumentParser] Hyperlink to anchor "${anchor}" has no display text. ` +
842
843
  `Using placeholder "[Link]" to prevent bookmark ID from appearing as visible text. ` +
843
844
  `This may indicate a corrupted TOC or malformed hyperlink in the source document.`);
844
845
  }
@@ -856,7 +857,7 @@ class DocumentParser {
856
857
  return hyperlink;
857
858
  }
858
859
  catch (error) {
859
- console.warn('[DocumentParser] Failed to parse hyperlink:', error);
860
+ logger_1.defaultLogger.warn('[DocumentParser] Failed to parse hyperlink:', error instanceof Error ? { message: error.message, stack: error.stack } : { error: String(error) });
860
861
  return null;
861
862
  }
862
863
  }
@@ -869,16 +870,15 @@ class DocumentParser {
869
870
  const hyperlinkIndices = new Map();
870
871
  for (let i = 0; i < content.length; i++) {
871
872
  const item = content[i];
872
- if (item.constructor.name === 'Hyperlink') {
873
- const hyperlink = item;
874
- const url = hyperlink.getUrl() || '';
875
- const anchor = hyperlink.getAnchor() || '';
873
+ if (item instanceof Hyperlink_1.Hyperlink) {
874
+ const url = item.getUrl() || '';
875
+ const anchor = item.getAnchor() || '';
876
876
  const key = `${url}|${anchor}`;
877
877
  if (!hyperlinkGroups.has(key)) {
878
878
  hyperlinkGroups.set(key, []);
879
879
  }
880
- hyperlinkGroups.get(key).push(hyperlink);
881
- hyperlinkIndices.set(hyperlink, i);
880
+ hyperlinkGroups.get(key).push(item);
881
+ hyperlinkIndices.set(item, i);
882
882
  }
883
883
  else {
884
884
  nonHyperlinkItems.push({ item, index: i });
@@ -901,21 +901,20 @@ class DocumentParser {
901
901
  continue;
902
902
  }
903
903
  const item = content[i];
904
- if (item.constructor.name === 'Hyperlink') {
905
- const hyperlink = item;
906
- const url = hyperlink.getUrl() || '';
907
- const anchor = hyperlink.getAnchor() || '';
904
+ if (item instanceof Hyperlink_1.Hyperlink) {
905
+ const url = item.getUrl() || '';
906
+ const anchor = item.getAnchor() || '';
908
907
  const key = `${url}|${anchor}`;
909
908
  const group = hyperlinkGroups.get(key);
910
- if (group.length > 1 && group[0] === hyperlink) {
909
+ if (group.length > 1 && group[0] === item) {
911
910
  const mergedText = group.map(h => h.getText()).join('');
912
- const mergedHyperlink = new hyperlink.constructor({
913
- url: hyperlink.getUrl(),
914
- anchor: hyperlink.getAnchor(),
911
+ const mergedHyperlink = new Hyperlink_1.Hyperlink({
912
+ url: item.getUrl(),
913
+ anchor: item.getAnchor(),
915
914
  text: mergedText,
916
- formatting: resetFormatting ? this.getStandardHyperlinkFormatting() : hyperlink.getFormatting(),
917
- tooltip: hyperlink.getTooltip(),
918
- relationshipId: hyperlink.getRelationshipId(),
915
+ formatting: resetFormatting ? this.getStandardHyperlinkFormatting() : item.getFormatting(),
916
+ tooltip: item.getTooltip(),
917
+ relationshipId: item.getRelationshipId(),
919
918
  });
920
919
  for (const h of group) {
921
920
  processedIndices.add(hyperlinkIndices.get(h));
@@ -924,18 +923,18 @@ class DocumentParser {
924
923
  }
925
924
  else if (group.length === 1) {
926
925
  if (resetFormatting) {
927
- const resetHyperlink = new hyperlink.constructor({
928
- url: hyperlink.getUrl(),
929
- anchor: hyperlink.getAnchor(),
930
- text: hyperlink.getText(),
926
+ const resetHyperlink = new Hyperlink_1.Hyperlink({
927
+ url: item.getUrl(),
928
+ anchor: item.getAnchor(),
929
+ text: item.getText(),
931
930
  formatting: this.getStandardHyperlinkFormatting(),
932
- tooltip: hyperlink.getTooltip(),
933
- relationshipId: hyperlink.getRelationshipId(),
931
+ tooltip: item.getTooltip(),
932
+ relationshipId: item.getRelationshipId(),
934
933
  });
935
934
  mergedContent.push(resetHyperlink);
936
935
  }
937
936
  else {
938
- mergedContent.push(hyperlink);
937
+ mergedContent.push(item);
939
938
  }
940
939
  processedIndices.add(i);
941
940
  }
@@ -948,13 +947,13 @@ class DocumentParser {
948
947
  if (needsMerge || resetFormatting) {
949
948
  paragraph.clearContent();
950
949
  for (const item of mergedContent) {
951
- if (item.constructor.name === 'Hyperlink') {
950
+ if (item instanceof Hyperlink_1.Hyperlink) {
952
951
  paragraph.addHyperlink(item);
953
952
  }
954
- else if (item.constructor.name === 'Run') {
953
+ else if (item instanceof Run_1.Run) {
955
954
  paragraph.addRun(item);
956
955
  }
957
- else if (item.constructor.name === 'Field') {
956
+ else if (item instanceof Field_1.Field) {
958
957
  paragraph.addField(item);
959
958
  }
960
959
  }
@@ -989,7 +988,7 @@ class DocumentParser {
989
988
  return field;
990
989
  }
991
990
  catch (error) {
992
- console.warn('[DocumentParser] Failed to parse field:', error);
991
+ logger_1.defaultLogger.warn('[DocumentParser] Failed to parse field:', error instanceof Error ? { message: error.message, stack: error.stack } : { error: String(error) });
993
992
  return null;
994
993
  }
995
994
  }
@@ -1231,18 +1230,18 @@ class DocumentParser {
1231
1230
  }
1232
1231
  const relationship = relationshipManager.getRelationship(relationshipId);
1233
1232
  if (!relationship) {
1234
- console.warn(`[DocumentParser] Image relationship not found: ${relationshipId}`);
1233
+ logger_1.defaultLogger.warn(`[DocumentParser] Image relationship not found: ${relationshipId}`);
1235
1234
  return null;
1236
1235
  }
1237
1236
  const imageTarget = relationship.getTarget();
1238
1237
  if (!imageTarget) {
1239
- console.warn(`[DocumentParser] Image relationship has no target: ${relationshipId}`);
1238
+ logger_1.defaultLogger.warn(`[DocumentParser] Image relationship has no target: ${relationshipId}`);
1240
1239
  return null;
1241
1240
  }
1242
1241
  const imagePath = `word/${imageTarget}`;
1243
1242
  const imageData = zipHandler.getFileAsBuffer(imagePath);
1244
1243
  if (!imageData) {
1245
- console.warn(`[DocumentParser] Image file not found: ${imagePath}`);
1244
+ logger_1.defaultLogger.warn(`[DocumentParser] Image file not found: ${imagePath}`);
1246
1245
  return null;
1247
1246
  }
1248
1247
  const extension = imagePath.split('.').pop()?.toLowerCase() || 'png';
@@ -1265,7 +1264,7 @@ class DocumentParser {
1265
1264
  return new ImageRun_1.ImageRun(image);
1266
1265
  }
1267
1266
  catch (error) {
1268
- console.warn('[DocumentParser] Failed to parse drawing:', error);
1267
+ logger_1.defaultLogger.warn('[DocumentParser] Failed to parse drawing:', error instanceof Error ? { message: error.message, stack: error.stack } : { error: String(error) });
1269
1268
  return null;
1270
1269
  }
1271
1270
  }
@@ -1391,7 +1390,7 @@ class DocumentParser {
1391
1390
  return table;
1392
1391
  }
1393
1392
  catch (error) {
1394
- console.warn('[DocumentParser] Failed to parse table:', error);
1393
+ logger_1.defaultLogger.warn('[DocumentParser] Failed to parse table:', error instanceof Error ? { message: error.message, stack: error.stack } : { error: String(error) });
1395
1394
  return null;
1396
1395
  }
1397
1396
  }
@@ -1490,7 +1489,7 @@ class DocumentParser {
1490
1489
  return row;
1491
1490
  }
1492
1491
  catch (error) {
1493
- console.warn('[DocumentParser] Failed to parse table row:', error);
1492
+ logger_1.defaultLogger.warn('[DocumentParser] Failed to parse table row:', error instanceof Error ? { message: error.message, stack: error.stack } : { error: String(error) });
1494
1493
  return null;
1495
1494
  }
1496
1495
  }
@@ -1717,7 +1716,7 @@ class DocumentParser {
1717
1716
  return cell;
1718
1717
  }
1719
1718
  catch (error) {
1720
- console.warn('[DocumentParser] Failed to parse table cell:', error);
1719
+ logger_1.defaultLogger.warn('[DocumentParser] Failed to parse table cell:', error instanceof Error ? { message: error.message, stack: error.stack } : { error: String(error) });
1721
1720
  return null;
1722
1721
  }
1723
1722
  }
@@ -1871,7 +1870,7 @@ class DocumentParser {
1871
1870
  return new StructuredDocumentTag_1.StructuredDocumentTag(properties, content);
1872
1871
  }
1873
1872
  catch (error) {
1874
- console.warn('[DocumentParser] Failed to parse SDT:', error);
1873
+ logger_1.defaultLogger.warn('[DocumentParser] Failed to parse SDT:', error instanceof Error ? { message: error.message, stack: error.stack } : { error: String(error) });
1875
1874
  return null;
1876
1875
  }
1877
1876
  }
@@ -1910,7 +1909,7 @@ class DocumentParser {
1910
1909
  break;
1911
1910
  }
1912
1911
  if (!fieldInstruction) {
1913
- console.warn('[DocumentParser] No TOC field instruction found in SDT content');
1912
+ logger_1.defaultLogger.warn('[DocumentParser] No TOC field instruction found in SDT content');
1914
1913
  return null;
1915
1914
  }
1916
1915
  const tocOptions = {
@@ -1953,7 +1952,7 @@ class DocumentParser {
1953
1952
  return new TableOfContents_1.TableOfContents(tocOptions);
1954
1953
  }
1955
1954
  catch (error) {
1956
- console.warn('[DocumentParser] Failed to parse TOC from SDT content:', error);
1955
+ logger_1.defaultLogger.warn('[DocumentParser] Failed to parse TOC from SDT content:', error instanceof Error ? { message: error.message, stack: error.stack } : { error: String(error) });
1957
1956
  return null;
1958
1957
  }
1959
1958
  }