@ansonlai/docx-redline-js 0.2.0 → 0.2.1

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.
@@ -1,4 +1,4 @@
1
- // @ansonlai/docx-redline-js v0.2.0 — https://github.com/AnsonLai/docx-redline-js
1
+ // @ansonlai/docx-redline-js v0.2.1 — https://github.com/AnsonLai/docx-redline-js
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -6,7 +6,11 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __commonJS = (cb, mod) => function __require() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ try {
10
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
+ } catch (e) {
12
+ throw mod = 0, e;
13
+ }
10
14
  };
11
15
  var __copyProps = (to, from, except, desc) => {
12
16
  if (from && typeof from === "object" || typeof from === "function") {
@@ -4425,11 +4429,11 @@ function createFormattedRuns(xmlDoc, text, baseRPr, formatHints, baseOffset, aut
4425
4429
  const applicableHints = formatHints.filter(
4426
4430
  (h) => h.start <= segmentBaseOffset && h.end >= segmentEndOffset
4427
4431
  );
4428
- const combinedFormat = {};
4432
+ const combinedFormat = { ...extractFormatFromRPr(baseRPr) };
4429
4433
  applicableHints.forEach((h) => {
4430
4434
  if (h.format) Object.assign(combinedFormat, h.format);
4431
4435
  });
4432
- const formattedRPr = injectFormattingToRPr(xmlDoc, baseRPr, combinedFormat, author, generateRedlines);
4436
+ const formattedRPr = applicableHints.length > 0 ? injectFormattingToRPr(xmlDoc, baseRPr, combinedFormat, author, generateRedlines) : baseRPr?.cloneNode(true) || null;
4433
4437
  runs.push(createTextRunWithRPrElement(xmlDoc, segment, formattedRPr, false));
4434
4438
  }
4435
4439
  return runs;
@@ -4549,6 +4553,7 @@ function isWordElement3(node, localName) {
4549
4553
  return nodeName === `w:${localName}` || nodeName === localName;
4550
4554
  }
4551
4555
  function buildParagraphInfos(xmlDoc, paragraphs, textSpans) {
4556
+ void xmlDoc;
4552
4557
  const spansByParagraph = /* @__PURE__ */ new Map();
4553
4558
  for (const span of textSpans) {
4554
4559
  if (!span || !span.paragraph) continue;
@@ -4753,6 +4758,7 @@ function normalizePrecomputedFormatContext(precomputedContext) {
4753
4758
  };
4754
4759
  }
4755
4760
  function applyFormatRemovalAsSurgicalReplacement(xmlDoc, textSpans, existingFormatHints, serializer, author, generateRedlines = true) {
4761
+ void textSpans;
4756
4762
  let hasAnyChanges = false;
4757
4763
  const processedRuns = /* @__PURE__ */ new Set();
4758
4764
  log(`[OxmlEngine] Surgical format removal: ${existingFormatHints.length} hints to process (using w:rPrChange)`);
@@ -5208,26 +5214,11 @@ function cloneRunPiece(xmlDoc, sourceNode, text, asDeletedText) {
5208
5214
 
5209
5215
  // engine/surgical-diff-application.js
5210
5216
  function reconcileFormattingForTextSpan(xmlDoc, span, start, end, applicableHints, author, generateRedlines) {
5211
- const desiredFormat = {};
5212
- if (applicableHints.length > 0) {
5213
- applicableHints.forEach((h) => Object.assign(desiredFormat, h.format));
5214
- }
5217
+ if (applicableHints.length === 0) return false;
5215
5218
  const rPr = span.rPr;
5216
- const hasElement = (localName) => {
5217
- if (!rPr) return false;
5218
- for (let node = rPr.firstChild; node; node = node.nextSibling) {
5219
- if (isWordElement(node, localName)) {
5220
- return true;
5221
- }
5222
- }
5223
- return false;
5224
- };
5225
- const existingFormat = {
5226
- bold: hasElement("b"),
5227
- italic: hasElement("i"),
5228
- underline: hasElement("u"),
5229
- strikethrough: hasElement("strike")
5230
- };
5219
+ const existingFormat = extractFormatFromRPr(rPr);
5220
+ const desiredFormat = { ...existingFormat };
5221
+ applicableHints.forEach((h) => Object.assign(desiredFormat, h.format));
5231
5222
  const formatsToCheck = ["bold", "italic", "underline", "strikethrough"];
5232
5223
  const changesNeeded = formatsToCheck.some((f) => !!desiredFormat[f] !== existingFormat[f]);
5233
5224
  if (!changesNeeded) return false;
@@ -5361,6 +5352,7 @@ function insertTextRuns(xmlDoc, parent, referenceNode, text, baseRPr, author, fo
5361
5352
 
5362
5353
  // engine/surgical-mode.js
5363
5354
  function applySurgicalMode(xmlDoc, originalText, modifiedText, serializer, author, formatHints, generateRedlines = true, targetParagraph = null) {
5355
+ void originalText;
5364
5356
  const allParagraphs = targetParagraph ? [targetParagraph] : getDocumentParagraphs(xmlDoc);
5365
5357
  const { fullText, textSpans } = buildSurgicalTextSpans(allParagraphs);
5366
5358
  const diffs = computeWordDiffs(fullText, modifiedText);
@@ -8802,6 +8794,11 @@ function injectCommentsIntoPackage2(packageOxml, commentsXml) {
8802
8794
  }
8803
8795
 
8804
8796
  // engine/formatting-removal.js
8797
+ function removeNode2(node) {
8798
+ if (node?.parentNode) {
8799
+ node.parentNode.removeChild(node);
8800
+ }
8801
+ }
8805
8802
  function removeFormattingFromRPr(rPr, formatTypes = ["all"]) {
8806
8803
  if (!rPr) return null;
8807
8804
  const rPrClone = rPr.cloneNode(true);
@@ -8825,7 +8822,7 @@ function removeFormattingFromRPr(rPr, formatTypes = ["all"]) {
8825
8822
  ];
8826
8823
  toRemove.forEach((tag) => {
8827
8824
  const elements = rPrClone.querySelectorAll(`${tag}, ${tag.replace("w:", "")}`);
8828
- elements.forEach((el) => el.remove());
8825
+ elements.forEach(removeNode2);
8829
8826
  });
8830
8827
  } else {
8831
8828
  const tagMap = {
@@ -8847,7 +8844,7 @@ function removeFormattingFromRPr(rPr, formatTypes = ["all"]) {
8847
8844
  const tag = tagMap[type];
8848
8845
  if (tag) {
8849
8846
  const elements = rPrClone.querySelectorAll(`${tag}, ${tag.replace("w:", "")}`);
8850
- elements.forEach((el) => el.remove());
8847
+ elements.forEach(removeNode2);
8851
8848
  }
8852
8849
  });
8853
8850
  }
@@ -8877,7 +8874,7 @@ function applyFormattingRemovalToOoxml(ooxmlString, targetText, formatTypes) {
8877
8874
  rPr.parentNode.replaceChild(newRPr, rPr);
8878
8875
  }
8879
8876
  } else {
8880
- rPr.remove();
8877
+ removeNode2(rPr);
8881
8878
  }
8882
8879
  }
8883
8880
  }
@@ -8923,7 +8920,7 @@ function injectHighlightIntoRPr(doc, rPr, color = "yellow", options = {}) {
8923
8920
  });
8924
8921
  }
8925
8922
  const existingHighlight = rPrElement.getElementsByTagNameNS(NS_W7, "highlight");
8926
- Array.from(existingHighlight).forEach((el) => el.remove());
8923
+ Array.from(existingHighlight).forEach(removeNode2);
8927
8924
  const highlightEl = createWordElement(doc, "w:highlight");
8928
8925
  highlightEl.setAttributeNS(NS_W7, "w:val", ooxmlColor);
8929
8926
  rPrElement.appendChild(highlightEl);
@@ -8935,7 +8932,7 @@ function injectHighlightIntoRPr(doc, rPr, color = "yellow", options = {}) {
8935
8932
  rPrChange.setAttribute("w:date", metadata.date);
8936
8933
  rPrChange.appendChild(previousRPrState);
8937
8934
  const existingChange = rPrElement.getElementsByTagNameNS(NS_W7, "rPrChange");
8938
- Array.from(existingChange).forEach((el) => el.remove());
8935
+ Array.from(existingChange).forEach(removeNode2);
8939
8936
  rPrElement.appendChild(rPrChange);
8940
8937
  }
8941
8938
  return rPrElement;
@@ -8967,7 +8964,7 @@ function applyHighlightToOoxml(ooxmlString, targetText, color = "yellow", option
8967
8964
  if (prefixText.length > 0) {
8968
8965
  const prefixRun = run.cloneNode(true);
8969
8966
  const tNodes = prefixRun.getElementsByTagNameNS(NS_W7, "t");
8970
- Array.from(tNodes).forEach((t) => t.remove());
8967
+ Array.from(tNodes).forEach(removeNode2);
8971
8968
  const newT = createWordElement(doc, "w:t");
8972
8969
  newT.setAttribute("xml:space", "preserve");
8973
8970
  newT.textContent = prefixText;
@@ -8977,7 +8974,7 @@ function applyHighlightToOoxml(ooxmlString, targetText, color = "yellow", option
8977
8974
  if (matchText.length > 0) {
8978
8975
  const matchRun = run.cloneNode(true);
8979
8976
  const tNodes = matchRun.getElementsByTagNameNS(NS_W7, "t");
8980
- Array.from(tNodes).forEach((t) => t.remove());
8977
+ Array.from(tNodes).forEach(removeNode2);
8981
8978
  const newT = createWordElement(doc, "w:t");
8982
8979
  newT.setAttribute("xml:space", "preserve");
8983
8980
  newT.textContent = matchText;
@@ -8995,7 +8992,7 @@ function applyHighlightToOoxml(ooxmlString, targetText, color = "yellow", option
8995
8992
  if (suffixText.length > 0) {
8996
8993
  const suffixRun = run.cloneNode(true);
8997
8994
  const tNodes = suffixRun.getElementsByTagNameNS(NS_W7, "t");
8998
- Array.from(tNodes).forEach((t) => t.remove());
8995
+ Array.from(tNodes).forEach(removeNode2);
8999
8996
  const newT = createWordElement(doc, "w:t");
9000
8997
  newT.setAttribute("xml:space", "preserve");
9001
8998
  newT.textContent = suffixText;