superdoc 1.0.0-beta.13 → 1.0.0-beta.15

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 (40) hide show
  1. package/dist/chunks/{PdfViewer-D0cPi5hG.es.js → PdfViewer-CjlHzt9e.es.js} +2 -2
  2. package/dist/chunks/{PdfViewer-D_E86Mtr.cjs → PdfViewer-DltPlBWC.cjs} +2 -2
  3. package/dist/chunks/{eventemitter3-ByBH0NYV.es.js → eventemitter3-CcXAdeql.es.js} +1 -1
  4. package/dist/chunks/{eventemitter3-CFCpOk3d.cjs → eventemitter3-DQmQUge-.cjs} +1 -1
  5. package/dist/chunks/{index-CL4VptDO.cjs → index-BZnlco_f.cjs} +6 -6
  6. package/dist/chunks/{index-BMAfbNel-DBZCkkMj.cjs → index-Bds7gW4r-JPDW6c39.cjs} +1 -1
  7. package/dist/chunks/{index-BMAfbNel-CvPc3jnD.es.js → index-Bds7gW4r-Pk_xAuWe.es.js} +1 -1
  8. package/dist/chunks/{index-BHmLKAul.es.js → index-qg0AxQJC.es.js} +6 -6
  9. package/dist/chunks/{jszip-BwsONqK5.es.js → jszip-5vvIqAEE.es.js} +1 -1
  10. package/dist/chunks/{jszip-B99MTu59.cjs → jszip-BdEez1WM.cjs} +1 -1
  11. package/dist/chunks/{super-editor.es-5gtBhP8I.es.js → super-editor.es-CQTkj_nb.es.js} +5926 -940
  12. package/dist/chunks/{super-editor.es-riuOlaxm.cjs → super-editor.es-CuAhqbzW.cjs} +5925 -939
  13. package/dist/chunks/{vue-CztqUvm1.es.js → vue-Dysv_7z5.es.js} +101 -12
  14. package/dist/chunks/{vue-ARQSyfaw.cjs → vue-jWLMl8Ts.cjs} +89 -0
  15. package/dist/chunks/xml-js-ClO_jHnq.es.js +2 -0
  16. package/dist/chunks/xml-js-Dz51sEbr.cjs +3 -0
  17. package/dist/packages/superdoc/src/core/SuperDoc.d.ts.map +1 -1
  18. package/dist/style.css +56 -17
  19. package/dist/super-editor/ai-writer.es.js +2 -2
  20. package/dist/super-editor/chunks/{converter-D9KiDgXx.js → converter-qMoZOGGn.js} +918 -342
  21. package/dist/super-editor/chunks/{docx-zipper-DQmUj-ef.js → docx-zipper-QKiyORxV.js} +1 -1
  22. package/dist/super-editor/chunks/{editor-ByPqJ2k8.js → editor-D8ZdjC2V.js} +4471 -502
  23. package/dist/super-editor/chunks/{index-BMAfbNel.js → index-Bds7gW4r.js} +1 -1
  24. package/dist/super-editor/chunks/{toolbar-Da2cOhJ-.js → toolbar-Spi7vpev.js} +36 -22
  25. package/dist/super-editor/converter.es.js +1 -1
  26. package/dist/super-editor/docx-zipper.es.js +2 -2
  27. package/dist/super-editor/editor.es.js +3 -3
  28. package/dist/super-editor/file-zipper.es.js +1 -1
  29. package/dist/super-editor/style.css +56 -17
  30. package/dist/super-editor/super-editor.es.js +560 -160
  31. package/dist/super-editor/toolbar.es.js +2 -2
  32. package/dist/super-editor.cjs +4 -4
  33. package/dist/super-editor.es.js +2 -2
  34. package/dist/superdoc.cjs +2 -2
  35. package/dist/superdoc.es.js +2 -2
  36. package/dist/superdoc.umd.js +5990 -928
  37. package/dist/superdoc.umd.js.map +1 -1
  38. package/package.json +1 -1
  39. package/dist/chunks/xml-js-BZPSMmVo.es.js +0 -2
  40. package/dist/chunks/xml-js-DQa4Ye5C.cjs +0 -3
@@ -18972,7 +18972,6 @@ const encode$B = (params, encodedAttrs = {}) => {
18972
18972
  }
18973
18973
  }
18974
18974
  });
18975
- console.log("subs:", subs);
18976
18975
  return subs;
18977
18976
  };
18978
18977
  function decode$D(params) {
@@ -20131,6 +20130,51 @@ function getStrikeValue(attributes) {
20131
20130
  if (value === "0" || value === "false" || value === "off") return "0";
20132
20131
  return "1";
20133
20132
  }
20133
+ function parseProperties(node) {
20134
+ const marks = [];
20135
+ const unknownMarks = [];
20136
+ const { attributes = {}, elements = [] } = node;
20137
+ const { nodes, paragraphProperties = {}, runProperties = {} } = splitElementsAndProperties(elements);
20138
+ const hasRun = elements.find((element) => element.name === "w:r");
20139
+ if (hasRun) paragraphProperties.elements = paragraphProperties?.elements?.filter((el) => el.name !== "w:rPr");
20140
+ if (runProperties && runProperties?.elements?.length) {
20141
+ marks.push(...parseMarks(runProperties, unknownMarks));
20142
+ }
20143
+ if (paragraphProperties && paragraphProperties.elements?.length) {
20144
+ const disallowedParagraphProperties = ["w:u"];
20145
+ const filteredParagraphProperties = {
20146
+ ...paragraphProperties,
20147
+ elements: paragraphProperties.elements?.filter((el) => !disallowedParagraphProperties.includes(el.name))
20148
+ };
20149
+ marks.push(...parseMarks(filteredParagraphProperties, unknownMarks));
20150
+ }
20151
+ marks.push(...handleStyleChangeMarks(runProperties, marks));
20152
+ if (paragraphProperties && paragraphProperties.elements?.length) {
20153
+ attributes["paragraphProperties"] = paragraphProperties;
20154
+ }
20155
+ if (marks && node.name === "w:p") {
20156
+ marks.forEach((mark) => {
20157
+ const attrValue = Object.keys(mark.attrs ?? {})[0];
20158
+ if (attrValue) {
20159
+ const value = mark.attrs[attrValue];
20160
+ attributes[attrValue] = value;
20161
+ }
20162
+ });
20163
+ }
20164
+ return { elements: nodes, attributes, marks, unknownMarks };
20165
+ }
20166
+ function splitElementsAndProperties(elements) {
20167
+ const pPr = elements.find((el) => el.name === "w:pPr");
20168
+ const rPr = elements.find((el) => el.name === "w:rPr");
20169
+ const sectPr = elements.find((el) => el.name === "w:sectPr");
20170
+ const els = elements.filter((el) => el.name !== "w:pPr" && el.name !== "w:rPr" && el.name !== "w:sectPr");
20171
+ return {
20172
+ nodes: els,
20173
+ paragraphProperties: pPr,
20174
+ runProperties: rPr,
20175
+ sectionProperties: sectPr
20176
+ };
20177
+ }
20134
20178
  function getTableStyleId(path) {
20135
20179
  const tbl = path.find((ancestor) => ancestor.name === "w:tbl");
20136
20180
  if (!tbl) {
@@ -20155,13 +20199,6 @@ const handleParagraphNode$1 = (params) => {
20155
20199
  if (pPr) {
20156
20200
  inlineParagraphProperties = translator$12.encode({ ...params, nodes: [pPr] }) || {};
20157
20201
  }
20158
- const handleStandardNode2 = nodeListHandler.handlerEntities.find(
20159
- (e) => e.handlerName === "standardNodeHandler"
20160
- )?.handler;
20161
- if (!handleStandardNode2) {
20162
- console.error("Standard node handler not found");
20163
- return null;
20164
- }
20165
20202
  const insideTable = (params.path || []).some((ancestor) => ancestor.name === "w:tc");
20166
20203
  const tableStyleId = getTableStyleId(params.path || []);
20167
20204
  const resolvedParagraphProperties = resolveParagraphProperties(
@@ -20170,15 +20207,29 @@ const handleParagraphNode$1 = (params) => {
20170
20207
  insideTable,
20171
20208
  tableStyleId
20172
20209
  );
20173
- const updatedParams = {
20174
- ...params,
20175
- nodes: [node],
20176
- extraParams: { ...params.extraParams, paragraphProperties: resolvedParagraphProperties }
20177
- };
20178
- const result = handleStandardNode2(updatedParams);
20179
- if (result.nodes.length === 1) {
20180
- schemaNode = result.nodes[0];
20210
+ const { elements = [], attributes = {}, marks = [] } = parseProperties(node, params.docx);
20211
+ const childContent = [];
20212
+ if (elements.length) {
20213
+ const updatedElements = elements.map((el) => {
20214
+ if (!el.marks) el.marks = [];
20215
+ el.marks.push(...marks);
20216
+ return el;
20217
+ });
20218
+ const childParams = {
20219
+ ...params,
20220
+ nodes: updatedElements,
20221
+ extraParams: { ...params.extraParams, paragraphProperties: resolvedParagraphProperties },
20222
+ path: [...params.path || [], node]
20223
+ };
20224
+ const translatedChildren = nodeListHandler.handler(childParams);
20225
+ childContent.push(...translatedChildren);
20181
20226
  }
20227
+ schemaNode = {
20228
+ type: "paragraph",
20229
+ content: childContent,
20230
+ attrs: { ...attributes },
20231
+ marks: []
20232
+ };
20182
20233
  schemaNode.type = "paragraph";
20183
20234
  schemaNode.attrs.paragraphProperties = inlineParagraphProperties;
20184
20235
  schemaNode.attrs.rsidRDefault = node.attributes?.["w:rsidRDefault"];
@@ -21649,7 +21700,7 @@ function handleAnnotationNode(params) {
21649
21700
  attrs.displayLabel = placeholderLabel;
21650
21701
  }
21651
21702
  const { attrs: marksAsAttrs, marks } = parseAnnotationMarks(sdtContent);
21652
- const allAttrs = { ...attrs, ...marksAsAttrs };
21703
+ const allAttrs = { ...attrs, ...marksAsAttrs, ...sdtPr && { sdtPr } };
21653
21704
  if (!allAttrs.hash) allAttrs.hash = generateDocxRandomId(4);
21654
21705
  if (!attrs.fieldId || !attrs.type) {
21655
21706
  return null;
@@ -21809,16 +21860,13 @@ function handleDocPartObj(params) {
21809
21860
  const sdtPr = node.elements.find((el) => el.name === "w:sdtPr");
21810
21861
  const docPartObj = sdtPr?.elements.find((el) => el.name === "w:docPartObj");
21811
21862
  const docPartGallery = docPartObj?.elements.find((el) => el.name === "w:docPartGallery");
21812
- const docPartGalleryType = docPartGallery?.attributes["w:val"];
21813
- if (!docPartGalleryType || !validGalleryTypeMap[docPartGalleryType]) {
21814
- return null;
21815
- }
21863
+ const docPartGalleryType = docPartGallery?.attributes?.["w:val"] ?? null;
21816
21864
  const content = node?.elements.find((el) => el.name === "w:sdtContent");
21817
- const handler2 = validGalleryTypeMap[docPartGalleryType];
21865
+ const handler2 = validGalleryTypeMap[docPartGalleryType] || genericDocPartHandler;
21818
21866
  const result = handler2({
21819
21867
  ...params,
21820
21868
  nodes: [content],
21821
- extraParams: { ...params.extraParams || {}, sdtPr }
21869
+ extraParams: { ...params.extraParams || {}, sdtPr, docPartGalleryType }
21822
21870
  });
21823
21871
  return result;
21824
21872
  }
@@ -21829,15 +21877,46 @@ const tableOfContentsHandler = (params) => {
21829
21877
  nodes: node.elements,
21830
21878
  path: [...params.path || [], node]
21831
21879
  });
21880
+ const normalizedContent = normalizeDocPartContent(translatedContent);
21832
21881
  const sdtPr = params.extraParams.sdtPr;
21833
21882
  const id = sdtPr.elements?.find((el) => el.name === "w:id")?.attributes["w:val"] || "";
21883
+ const docPartObj = sdtPr?.elements.find((el) => el.name === "w:docPartObj");
21884
+ const docPartUnique = docPartObj?.elements.some((el) => el.name === "w:docPartUnique") ?? false;
21834
21885
  const result = {
21835
21886
  type: "documentPartObject",
21836
- content: translatedContent,
21887
+ content: normalizedContent,
21837
21888
  attrs: {
21838
21889
  id,
21839
21890
  docPartGallery: "Table of Contents",
21840
- docPartUnique: true
21891
+ docPartUnique,
21892
+ sdtPr
21893
+ // Passthrough for round-trip preservation
21894
+ }
21895
+ };
21896
+ return result;
21897
+ };
21898
+ const genericDocPartHandler = (params) => {
21899
+ const node = params.nodes[0];
21900
+ const translatedContent = params.nodeListHandler.handler({
21901
+ ...params,
21902
+ nodes: node.elements,
21903
+ path: [...params.path || [], node]
21904
+ });
21905
+ const sdtPr = params.extraParams.sdtPr;
21906
+ const docPartGalleryType = params.extraParams.docPartGalleryType;
21907
+ const id = sdtPr?.elements?.find((el) => el.name === "w:id")?.attributes["w:val"] || "";
21908
+ const docPartObj = sdtPr?.elements.find((el) => el.name === "w:docPartObj");
21909
+ const docPartGallery = docPartGalleryType ?? docPartObj?.elements?.find((el) => el.name === "w:docPartGallery")?.attributes?.["w:val"] ?? null;
21910
+ const docPartUnique = docPartObj?.elements.some((el) => el.name === "w:docPartUnique") ?? false;
21911
+ const result = {
21912
+ type: "documentPartObject",
21913
+ content: translatedContent,
21914
+ attrs: {
21915
+ id,
21916
+ docPartGallery,
21917
+ docPartUnique,
21918
+ sdtPr
21919
+ // Passthrough for round-trip preservation of all sdtPr elements
21841
21920
  }
21842
21921
  };
21843
21922
  return result;
@@ -21845,6 +21924,22 @@ const tableOfContentsHandler = (params) => {
21845
21924
  const validGalleryTypeMap = {
21846
21925
  "Table of Contents": tableOfContentsHandler
21847
21926
  };
21927
+ const inlineNodeTypes = /* @__PURE__ */ new Set(["bookmarkStart", "bookmarkEnd"]);
21928
+ const wrapInlineNode = (node) => ({
21929
+ type: "paragraph",
21930
+ content: [node]
21931
+ });
21932
+ const normalizeDocPartContent = (nodes = []) => {
21933
+ const normalized = [];
21934
+ nodes.forEach((node) => {
21935
+ if (inlineNodeTypes.has(node?.type)) {
21936
+ normalized.push(wrapInlineNode(node));
21937
+ } else {
21938
+ normalized.push(node);
21939
+ }
21940
+ });
21941
+ return normalized;
21942
+ };
21848
21943
  function handleDocumentSectionNode(params) {
21849
21944
  const { nodes, nodeListHandler } = params;
21850
21945
  if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
@@ -21859,6 +21954,9 @@ function handleDocumentSectionNode(params) {
21859
21954
  const titleTag = sdtPr?.elements.find((el) => el.name === "w:alias");
21860
21955
  const title = titleTag?.attributes?.["w:val"] || tagValue.title || null;
21861
21956
  const { description } = tagValue;
21957
+ const lockTag = sdtPr?.elements.find((el) => el.name === "w:lock");
21958
+ const lockValue = lockTag?.attributes?.["w:val"];
21959
+ const isLocked = lockValue === "sdtContentLocked";
21862
21960
  const sdtContent = node.elements.find((el) => el.name === "w:sdtContent");
21863
21961
  const translatedContent = nodeListHandler.handler({
21864
21962
  ...params,
@@ -21871,7 +21969,10 @@ function handleDocumentSectionNode(params) {
21871
21969
  attrs: {
21872
21970
  id,
21873
21971
  title,
21874
- description
21972
+ description,
21973
+ isLocked,
21974
+ ...sdtPr && { sdtPr }
21975
+ // Passthrough for round-trip preservation of unknown elements only if it exists
21875
21976
  }
21876
21977
  };
21877
21978
  return result;
@@ -24664,7 +24765,10 @@ function getThemeColor(name) {
24664
24765
  text1: "#000000",
24665
24766
  text2: "#1f497d",
24666
24767
  background1: "#ffffff",
24667
- background2: "#eeece1"
24768
+ background2: "#eeece1",
24769
+ // Office XML shortcuts
24770
+ bg1: "#ffffff",
24771
+ bg2: "#eeece1"
24668
24772
  };
24669
24773
  return colors[name] ?? "#000000";
24670
24774
  }
@@ -24701,7 +24805,10 @@ function applyColorModifier(hexColor, modifier, value) {
24701
24805
  function extractStrokeWidth(spPr) {
24702
24806
  const ln = spPr?.elements?.find((el) => el.name === "a:ln");
24703
24807
  const w2 = ln?.attributes?.["w"];
24704
- return w2 ? emuToPixels(w2) : 1;
24808
+ if (!w2) return 1;
24809
+ const emu = typeof w2 === "string" ? parseFloat(w2) : w2;
24810
+ const STROKE_DPI = 72;
24811
+ return emu * STROKE_DPI / 914400;
24705
24812
  }
24706
24813
  function extractStrokeColor(spPr, style) {
24707
24814
  const ln = spPr?.elements?.find((el) => el.name === "a:ln");
@@ -24762,6 +24869,7 @@ function extractFillColor(spPr, style) {
24762
24869
  if (schemeClr2) {
24763
24870
  const themeName2 = schemeClr2.attributes?.["val"];
24764
24871
  let color2 = getThemeColor(themeName2);
24872
+ let alpha = null;
24765
24873
  const modifiers2 = schemeClr2.elements || [];
24766
24874
  modifiers2.forEach((mod) => {
24767
24875
  if (mod.name === "a:shade") {
@@ -24772,18 +24880,32 @@ function extractFillColor(spPr, style) {
24772
24880
  color2 = applyColorModifier(color2, "lumMod", mod.attributes["val"]);
24773
24881
  } else if (mod.name === "a:lumOff") {
24774
24882
  color2 = applyColorModifier(color2, "lumOff", mod.attributes["val"]);
24883
+ } else if (mod.name === "a:alpha") {
24884
+ alpha = parseInt(mod.attributes["val"]) / 1e5;
24775
24885
  }
24776
24886
  });
24887
+ if (alpha !== null && alpha < 1) {
24888
+ return { type: "solidWithAlpha", color: color2, alpha };
24889
+ }
24777
24890
  return color2;
24778
24891
  }
24779
24892
  const srgbClr = solidFill.elements?.find((el) => el.name === "a:srgbClr");
24780
24893
  if (srgbClr) {
24781
- return "#" + srgbClr.attributes?.["val"];
24894
+ let alpha = null;
24895
+ const alphaEl = srgbClr.elements?.find((el) => el.name === "a:alpha");
24896
+ if (alphaEl) {
24897
+ alpha = parseInt(alphaEl.attributes?.["val"] || "100000", 10) / 1e5;
24898
+ }
24899
+ const color2 = "#" + srgbClr.attributes?.["val"];
24900
+ if (alpha !== null && alpha < 1) {
24901
+ return { type: "solidWithAlpha", color: color2, alpha };
24902
+ }
24903
+ return color2;
24782
24904
  }
24783
24905
  }
24784
24906
  const gradFill = spPr?.elements?.find((el) => el.name === "a:gradFill");
24785
24907
  if (gradFill) {
24786
- return "#cccccc";
24908
+ return extractGradientFill(gradFill);
24787
24909
  }
24788
24910
  const blipFill = spPr?.elements?.find((el) => el.name === "a:blipFill");
24789
24911
  if (blipFill) {
@@ -24792,6 +24914,8 @@ function extractFillColor(spPr, style) {
24792
24914
  if (!style) return "#5b9bd5";
24793
24915
  const fillRef = style.elements?.find((el) => el.name === "a:fillRef");
24794
24916
  if (!fillRef) return "#5b9bd5";
24917
+ const fillRefIdx = fillRef.attributes?.["idx"];
24918
+ if (fillRefIdx === "0") return null;
24795
24919
  const schemeClr = fillRef.elements?.find((el) => el.name === "a:schemeClr");
24796
24920
  if (!schemeClr) return "#5b9bd5";
24797
24921
  const themeName = schemeClr.attributes?.["val"];
@@ -24808,9 +24932,49 @@ function extractFillColor(spPr, style) {
24808
24932
  });
24809
24933
  return color;
24810
24934
  }
24935
+ function extractGradientFill(gradFill) {
24936
+ const gradient = {
24937
+ type: "gradient",
24938
+ stops: [],
24939
+ angle: 0
24940
+ };
24941
+ const gsLst = gradFill.elements?.find((el) => el.name === "a:gsLst");
24942
+ if (gsLst) {
24943
+ const stops = gsLst.elements?.filter((el) => el.name === "a:gs") || [];
24944
+ gradient.stops = stops.map((stop) => {
24945
+ const pos = parseInt(stop.attributes?.["pos"] || "0", 10) / 1e5;
24946
+ const srgbClr = stop.elements?.find((el) => el.name === "a:srgbClr");
24947
+ let color = "#000000";
24948
+ let alpha = 1;
24949
+ if (srgbClr) {
24950
+ color = "#" + srgbClr.attributes?.["val"];
24951
+ const alphaEl = srgbClr.elements?.find((el) => el.name === "a:alpha");
24952
+ if (alphaEl) {
24953
+ alpha = parseInt(alphaEl.attributes?.["val"] || "100000", 10) / 1e5;
24954
+ }
24955
+ }
24956
+ return { position: pos, color, alpha };
24957
+ });
24958
+ }
24959
+ const lin = gradFill.elements?.find((el) => el.name === "a:lin");
24960
+ if (lin) {
24961
+ const ang = parseInt(lin.attributes?.["ang"] || "0", 10) / 6e4;
24962
+ gradient.angle = ang;
24963
+ }
24964
+ const path = gradFill.elements?.find((el) => el.name === "a:path");
24965
+ if (path) {
24966
+ gradient.gradientType = "radial";
24967
+ gradient.path = path.attributes?.["path"] || "circle";
24968
+ } else {
24969
+ gradient.gradientType = "linear";
24970
+ }
24971
+ return gradient;
24972
+ }
24811
24973
  const DRAWING_XML_TAG = "w:drawing";
24812
24974
  const SHAPE_URI = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
24813
24975
  const GROUP_URI = "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup";
24976
+ const DEFAULT_SHAPE_WIDTH = 100;
24977
+ const DEFAULT_SHAPE_HEIGHT = 100;
24814
24978
  function handleImageNode(node, params, isAnchor) {
24815
24979
  const { docx, filename } = params;
24816
24980
  const { attributes } = node;
@@ -24854,7 +25018,8 @@ function handleImageNode(node, params, isAnchor) {
24854
25018
  horizontal: positionHValue,
24855
25019
  top: positionVValue
24856
25020
  };
24857
- const simplePos = node.elements.find((el) => el.name === "wp:simplePos");
25021
+ const useSimplePos = attributes["simplePos"] === "1" || attributes["simplePos"] === 1;
25022
+ const simplePos = useSimplePos ? node.elements.find((el) => el.name === "wp:simplePos") : null;
24858
25023
  const wrapNode = isAnchor ? node.elements.find(
24859
25024
  (el) => ["wp:wrapNone", "wp:wrapSquare", "wp:wrapThrough", "wp:wrapTight", "wp:wrapTopAndBottom"].includes(el.name)
24860
25025
  ) : null;
@@ -24934,7 +25099,7 @@ function handleImageNode(node, params, isAnchor) {
24934
25099
  horizontal: positionHValue,
24935
25100
  top: positionVValue
24936
25101
  };
24937
- return handleShapeDrawing(params, node, graphicData, size, padding, shapeMarginOffset);
25102
+ return handleShapeDrawing(params, node, graphicData, size, padding, shapeMarginOffset, anchorData, wrap2, isAnchor);
24938
25103
  }
24939
25104
  if (uri2 === GROUP_URI) {
24940
25105
  const shapeMarginOffset = {
@@ -24942,13 +25107,16 @@ function handleImageNode(node, params, isAnchor) {
24942
25107
  horizontal: positionHValue,
24943
25108
  top: positionVValue
24944
25109
  };
24945
- return handleShapeGroup(params, node, graphicData, size, padding, shapeMarginOffset);
25110
+ return handleShapeGroup(params, node, graphicData, size, padding, shapeMarginOffset, anchorData, wrap2);
24946
25111
  }
24947
25112
  const picture = graphicData?.elements.find((el) => el.name === "pic:pic");
24948
25113
  if (!picture || !picture.elements) return null;
24949
25114
  const blipFill = picture.elements.find((el) => el.name === "pic:blipFill");
24950
25115
  const blip = blipFill?.elements.find((el) => el.name === "a:blip");
24951
25116
  if (!blip) return null;
25117
+ const stretch = blipFill?.elements.find((el) => el.name === "a:stretch");
25118
+ const fillRect = stretch?.elements.find((el) => el.name === "a:fillRect");
25119
+ const shouldStretch = Boolean(stretch && fillRect);
24952
25120
  const spPr = picture.elements.find((el) => el.name === "pic:spPr");
24953
25121
  if (spPr) {
24954
25122
  const xfrm = spPr.elements.find((el) => el.name === "a:xfrm");
@@ -25002,6 +25170,7 @@ function handleImageNode(node, params, isAnchor) {
25002
25170
  wrapText: wrap2.attrs.wrapText
25003
25171
  } : {},
25004
25172
  wrapTopAndBottom: wrap2.type === "TopAndBottom",
25173
+ shouldStretch,
25005
25174
  originalPadding: {
25006
25175
  distT: attributes["distT"],
25007
25176
  distB: attributes["distB"],
@@ -25013,26 +25182,25 @@ function handleImageNode(node, params, isAnchor) {
25013
25182
  }
25014
25183
  };
25015
25184
  }
25016
- const handleShapeDrawing = (params, node, graphicData, size, padding, marginOffset) => {
25185
+ const handleShapeDrawing = (params, node, graphicData, size, padding, marginOffset, anchorData, wrap2, isAnchor) => {
25017
25186
  const wsp = graphicData.elements.find((el) => el.name === "wps:wsp");
25018
25187
  const textBox = wsp.elements.find((el) => el.name === "wps:txbx");
25019
25188
  const textBoxContent = textBox?.elements?.find((el) => el.name === "w:txbxContent");
25020
25189
  const spPr = wsp.elements.find((el) => el.name === "wps:spPr");
25021
25190
  const prstGeom = spPr?.elements.find((el) => el.name === "a:prstGeom");
25022
25191
  const shapeType = prstGeom?.attributes["prst"];
25023
- if (shapeType === "rect" && !textBoxContent) {
25024
- return getRectangleShape(params, spPr);
25192
+ const hasGradientFill = spPr?.elements?.find((el) => el.name === "a:gradFill");
25193
+ if (shapeType === "rect" && !textBoxContent && !hasGradientFill) {
25194
+ return getRectangleShape(params, spPr, node, marginOffset, anchorData, wrap2, isAnchor);
25025
25195
  }
25026
- if (shapeType && !textBoxContent) {
25027
- const result = getVectorShape({ params, graphicData });
25196
+ if (shapeType) {
25197
+ const result = getVectorShape({ params, node, graphicData, size, marginOffset, anchorData, wrap: wrap2, isAnchor });
25028
25198
  if (result) return result;
25029
25199
  }
25030
- if (!textBoxContent) {
25031
- return buildShapePlaceholder(node, size, padding, marginOffset, "drawing");
25032
- }
25033
- return buildShapePlaceholder(node, size, padding, marginOffset, "textbox");
25200
+ const fallbackType = textBoxContent ? "textbox" : "drawing";
25201
+ return buildShapePlaceholder(node, size, padding, marginOffset, fallbackType);
25034
25202
  };
25035
- const handleShapeGroup = (params, node, graphicData, size, padding, marginOffset) => {
25203
+ const handleShapeGroup = (params, node, graphicData, size, padding, marginOffset, anchorData, wrap2) => {
25036
25204
  const wgp = graphicData.elements.find((el) => el.name === "wpg:wgp");
25037
25205
  if (!wgp) {
25038
25206
  return buildShapePlaceholder(node, size, padding, marginOffset, "group");
@@ -25065,6 +25233,7 @@ const handleShapeGroup = (params, node, graphicData, size, padding, marginOffset
25065
25233
  }
25066
25234
  }
25067
25235
  const childShapes = wgp.elements.filter((el) => el.name === "wps:wsp");
25236
+ const childPictures = wgp.elements.filter((el) => el.name === "pic:pic");
25068
25237
  const shapes = childShapes.map((wsp) => {
25069
25238
  const spPr = wsp.elements?.find((el) => el.name === "wps:spPr");
25070
25239
  if (!spPr) return null;
@@ -25103,6 +25272,14 @@ const handleShapeGroup = (params, node, graphicData, size, padding, marginOffset
25103
25272
  const cNvPr = wsp.elements?.find((el) => el.name === "wps:cNvPr");
25104
25273
  const shapeId = cNvPr?.attributes?.["id"];
25105
25274
  const shapeName = cNvPr?.attributes?.["name"];
25275
+ const textBox = wsp.elements?.find((el) => el.name === "wps:txbx");
25276
+ const textBoxContent = textBox?.elements?.find((el) => el.name === "w:txbxContent");
25277
+ const bodyPr = wsp.elements?.find((el) => el.name === "wps:bodyPr");
25278
+ let textContent = null;
25279
+ if (textBoxContent) {
25280
+ textContent = extractTextFromTextBox(textBoxContent, bodyPr);
25281
+ }
25282
+ const textAlign = textContent?.horizontalAlign || "left";
25106
25283
  return {
25107
25284
  shapeType: "vectorShape",
25108
25285
  attrs: {
@@ -25118,10 +25295,75 @@ const handleShapeGroup = (params, node, graphicData, size, padding, marginOffset
25118
25295
  strokeColor,
25119
25296
  strokeWidth,
25120
25297
  shapeId,
25121
- shapeName
25298
+ shapeName,
25299
+ textContent,
25300
+ textAlign,
25301
+ textVerticalAlign: textContent?.verticalAlign,
25302
+ textInsets: textContent?.insets
25303
+ }
25304
+ };
25305
+ }).filter(Boolean);
25306
+ const pictures = childPictures.map((pic) => {
25307
+ const spPr = pic.elements?.find((el) => el.name === "pic:spPr");
25308
+ if (!spPr) return null;
25309
+ const xfrm2 = spPr.elements?.find((el) => el.name === "a:xfrm");
25310
+ const off = xfrm2?.elements?.find((el) => el.name === "a:off");
25311
+ const ext = xfrm2?.elements?.find((el) => el.name === "a:ext");
25312
+ const rawX = off?.attributes?.["x"] ? parseFloat(off.attributes["x"]) : 0;
25313
+ const rawY = off?.attributes?.["y"] ? parseFloat(off.attributes["y"]) : 0;
25314
+ const rawWidth = ext?.attributes?.["cx"] ? parseFloat(ext.attributes["cx"]) : 914400;
25315
+ const rawHeight = ext?.attributes?.["cy"] ? parseFloat(ext.attributes["cy"]) : 914400;
25316
+ let x2, y2, width, height;
25317
+ if (groupTransform.childWidth && groupTransform.childHeight) {
25318
+ const scaleX = groupTransform.width / groupTransform.childWidth;
25319
+ const scaleY = groupTransform.height / groupTransform.childHeight;
25320
+ const childOriginX = groupTransform.childOriginXEmu || 0;
25321
+ const childOriginY = groupTransform.childOriginYEmu || 0;
25322
+ x2 = groupTransform.x + emuToPixels((rawX - childOriginX) * scaleX);
25323
+ y2 = groupTransform.y + emuToPixels((rawY - childOriginY) * scaleY);
25324
+ width = emuToPixels(rawWidth * scaleX);
25325
+ height = emuToPixels(rawHeight * scaleY);
25326
+ } else {
25327
+ x2 = emuToPixels(rawX);
25328
+ y2 = emuToPixels(rawY);
25329
+ width = emuToPixels(rawWidth);
25330
+ height = emuToPixels(rawHeight);
25331
+ }
25332
+ const blipFill = pic.elements?.find((el) => el.name === "pic:blipFill");
25333
+ const blip = blipFill?.elements?.find((el) => el.name === "a:blip");
25334
+ if (!blip) return null;
25335
+ const rEmbed = blip.attributes?.["r:embed"];
25336
+ if (!rEmbed) return null;
25337
+ const currentFile = params.filename || "document.xml";
25338
+ let rels = params.docx[`word/_rels/${currentFile}.rels`];
25339
+ if (!rels) rels = params.docx[`word/_rels/document.xml.rels`];
25340
+ const relationships = rels?.elements.find((el) => el.name === "Relationships");
25341
+ const { elements } = relationships || [];
25342
+ const rel = elements?.find((el) => el.attributes["Id"] === rEmbed);
25343
+ if (!rel) return null;
25344
+ const targetPath = rel.attributes?.["Target"];
25345
+ let path = `word/${targetPath}`;
25346
+ if (targetPath.startsWith("/word") || targetPath.startsWith("/media")) {
25347
+ path = targetPath.substring(1);
25348
+ }
25349
+ const nvPicPr = pic.elements?.find((el) => el.name === "pic:nvPicPr");
25350
+ const cNvPr = nvPicPr?.elements?.find((el) => el.name === "pic:cNvPr");
25351
+ const picId = cNvPr?.attributes?.["id"];
25352
+ const picName = cNvPr?.attributes?.["name"];
25353
+ return {
25354
+ shapeType: "image",
25355
+ attrs: {
25356
+ x: x2,
25357
+ y: y2,
25358
+ width,
25359
+ height,
25360
+ src: path,
25361
+ imageId: picId,
25362
+ imageName: picName
25122
25363
  }
25123
25364
  };
25124
25365
  }).filter(Boolean);
25366
+ const allShapes = [...pictures, ...shapes];
25125
25367
  const schemaAttrs = {};
25126
25368
  const drawingNode = params.nodes?.[0];
25127
25369
  if (drawingNode?.name === DRAWING_XML_TAG) {
@@ -25132,38 +25374,137 @@ const handleShapeGroup = (params, node, graphicData, size, padding, marginOffset
25132
25374
  attrs: {
25133
25375
  ...schemaAttrs,
25134
25376
  groupTransform,
25135
- shapes,
25377
+ shapes: allShapes,
25136
25378
  size,
25137
25379
  padding,
25138
- marginOffset
25380
+ marginOffset,
25381
+ anchorData,
25382
+ wrap: wrap2,
25383
+ originalAttributes: node?.attributes
25139
25384
  }
25140
25385
  };
25141
25386
  return result;
25142
25387
  };
25143
- const getRectangleShape = (params, node) => {
25388
+ function extractTextFromTextBox(textBoxContent, bodyPr) {
25389
+ if (!textBoxContent || !textBoxContent.elements) return null;
25390
+ const paragraphs = textBoxContent.elements.filter((el) => el.name === "w:p");
25391
+ const textParts = [];
25392
+ let horizontalAlign = null;
25393
+ paragraphs.forEach((paragraph, paragraphIndex) => {
25394
+ if (!horizontalAlign) {
25395
+ const pPr = paragraph.elements?.find((el) => el.name === "w:pPr");
25396
+ const jc = pPr?.elements?.find((el) => el.name === "w:jc");
25397
+ if (jc) {
25398
+ const jcVal = jc.attributes?.["val"] || jc.attributes?.["w:val"];
25399
+ if (jcVal === "left" || jcVal === "start") horizontalAlign = "left";
25400
+ else if (jcVal === "right" || jcVal === "end") horizontalAlign = "right";
25401
+ else if (jcVal === "center") horizontalAlign = "center";
25402
+ }
25403
+ }
25404
+ const runs = paragraph.elements?.filter((el) => el.name === "w:r") || [];
25405
+ let paragraphHasText = false;
25406
+ runs.forEach((run2) => {
25407
+ const textEl = run2.elements?.find((el) => el.name === "w:t");
25408
+ if (textEl && textEl.elements) {
25409
+ const text = textEl.elements.find((el) => el.type === "text");
25410
+ if (text) {
25411
+ paragraphHasText = true;
25412
+ const cleanedText = typeof text.text === "string" ? text.text.replace(/\[\[sdspace\]\]/g, " ") : text.text;
25413
+ const rPr = run2.elements?.find((el) => el.name === "w:rPr");
25414
+ const formatting = {};
25415
+ if (rPr) {
25416
+ const bold = rPr.elements?.find((el) => el.name === "w:b");
25417
+ const italic = rPr.elements?.find((el) => el.name === "w:i");
25418
+ const color = rPr.elements?.find((el) => el.name === "w:color");
25419
+ const sz = rPr.elements?.find((el) => el.name === "w:sz");
25420
+ if (bold) formatting.bold = true;
25421
+ if (italic) formatting.italic = true;
25422
+ if (color) formatting.color = color.attributes?.["val"] || color.attributes?.["w:val"];
25423
+ if (sz) {
25424
+ const szVal = sz.attributes?.["val"] || sz.attributes?.["w:val"];
25425
+ formatting.fontSize = parseInt(szVal, 10) / 2;
25426
+ }
25427
+ }
25428
+ textParts.push({
25429
+ text: cleanedText,
25430
+ formatting
25431
+ });
25432
+ }
25433
+ }
25434
+ });
25435
+ if (paragraphIndex < paragraphs.length - 1) {
25436
+ textParts.push({
25437
+ text: "\n",
25438
+ formatting: {},
25439
+ isLineBreak: true,
25440
+ isEmptyParagraph: !paragraphHasText
25441
+ // Mark empty paragraphs for extra spacing
25442
+ });
25443
+ }
25444
+ });
25445
+ if (textParts.length === 0) return null;
25446
+ const bodyPrAttrs = bodyPr?.attributes || {};
25447
+ let verticalAlign = "center";
25448
+ const anchorAttr = bodyPrAttrs["anchor"];
25449
+ if (anchorAttr === "t") verticalAlign = "top";
25450
+ else if (anchorAttr === "ctr") verticalAlign = "center";
25451
+ else if (anchorAttr === "b") verticalAlign = "bottom";
25452
+ const EMU_TO_PX = 96 / 914400;
25453
+ const DEFAULT_HORIZONTAL_INSET_EMU = 91440;
25454
+ const DEFAULT_VERTICAL_INSET_EMU = 45720;
25455
+ const lIns = bodyPrAttrs["lIns"] != null ? parseFloat(bodyPrAttrs["lIns"]) : DEFAULT_HORIZONTAL_INSET_EMU;
25456
+ const tIns = bodyPrAttrs["tIns"] != null ? parseFloat(bodyPrAttrs["tIns"]) : DEFAULT_VERTICAL_INSET_EMU;
25457
+ const rIns = bodyPrAttrs["rIns"] != null ? parseFloat(bodyPrAttrs["rIns"]) : DEFAULT_HORIZONTAL_INSET_EMU;
25458
+ const bIns = bodyPrAttrs["bIns"] != null ? parseFloat(bodyPrAttrs["bIns"]) : DEFAULT_VERTICAL_INSET_EMU;
25459
+ const insets = {
25460
+ top: tIns * EMU_TO_PX,
25461
+ right: rIns * EMU_TO_PX,
25462
+ bottom: bIns * EMU_TO_PX,
25463
+ left: lIns * EMU_TO_PX
25464
+ };
25465
+ const wrap2 = bodyPrAttrs["wrap"] || "square";
25466
+ return {
25467
+ parts: textParts,
25468
+ horizontalAlign: horizontalAlign || "left",
25469
+ // Default to left if not specified
25470
+ verticalAlign,
25471
+ insets,
25472
+ wrap: wrap2
25473
+ };
25474
+ }
25475
+ const getRectangleShape = (params, spPr, node, marginOffset, anchorData, wrap2, isAnchor) => {
25144
25476
  const schemaAttrs = {};
25145
- const [drawingNode] = params.nodes;
25477
+ const drawingNode = params.nodes?.[0];
25146
25478
  if (drawingNode?.name === DRAWING_XML_TAG) {
25147
25479
  schemaAttrs.drawingContent = drawingNode;
25148
25480
  }
25149
- const xfrm = node.elements.find((el) => el.name === "a:xfrm");
25150
- const start = xfrm.elements.find((el) => el.name === "a:off");
25151
- const size = xfrm.elements.find((el) => el.name === "a:ext");
25152
- const solidFill = node.elements.find((el) => el.name === "a:solidFill");
25153
- const rectangleSize = {
25154
- top: emuToPixels(start.attributes["y"]),
25155
- left: emuToPixels(start.attributes["x"]),
25156
- width: emuToPixels(size.attributes["cx"]),
25157
- height: emuToPixels(size.attributes["cy"])
25158
- };
25159
- schemaAttrs.size = rectangleSize;
25481
+ const xfrm = spPr?.elements?.find((el) => el.name === "a:xfrm");
25482
+ const start = xfrm?.elements?.find((el) => el.name === "a:off");
25483
+ const size = xfrm?.elements?.find((el) => el.name === "a:ext");
25484
+ const solidFill = spPr?.elements?.find((el) => el.name === "a:solidFill");
25485
+ if (start && size) {
25486
+ const rectangleSize = {
25487
+ top: emuToPixels(start.attributes?.["y"] || 0),
25488
+ left: emuToPixels(start.attributes?.["x"] || 0),
25489
+ width: emuToPixels(size.attributes?.["cx"] || 0),
25490
+ height: emuToPixels(size.attributes?.["cy"] || 0)
25491
+ };
25492
+ schemaAttrs.size = rectangleSize;
25493
+ }
25160
25494
  const background = solidFill?.elements[0]?.attributes["val"];
25161
25495
  if (background) {
25162
25496
  schemaAttrs.background = "#" + background;
25163
25497
  }
25164
25498
  return {
25165
25499
  type: "contentBlock",
25166
- attrs: schemaAttrs
25500
+ attrs: {
25501
+ ...schemaAttrs,
25502
+ marginOffset,
25503
+ anchorData,
25504
+ wrap: wrap2,
25505
+ isAnchor,
25506
+ originalAttributes: node?.attributes
25507
+ }
25167
25508
  };
25168
25509
  };
25169
25510
  const buildShapePlaceholder = (node, size, padding, marginOffset, shapeType) => {
@@ -25212,7 +25553,7 @@ const buildShapePlaceholder = (node, size, padding, marginOffset, shapeType) =>
25212
25553
  attrs
25213
25554
  };
25214
25555
  };
25215
- function getVectorShape({ params, graphicData }) {
25556
+ function getVectorShape({ params, node, graphicData, size, marginOffset, anchorData, wrap: wrap2, isAnchor }) {
25216
25557
  const schemaAttrs = {};
25217
25558
  const drawingNode = params.nodes?.[0];
25218
25559
  if (drawingNode?.name === "w:drawing") {
@@ -25232,10 +25573,9 @@ function getVectorShape({ params, graphicData }) {
25232
25573
  console.warn("Shape kind not found");
25233
25574
  }
25234
25575
  schemaAttrs.kind = shapeKind;
25576
+ const width = size?.width ?? DEFAULT_SHAPE_WIDTH;
25577
+ const height = size?.height ?? DEFAULT_SHAPE_HEIGHT;
25235
25578
  const xfrm = spPr.elements?.find((el) => el.name === "a:xfrm");
25236
- const extent = xfrm?.elements?.find((el) => el.name === "a:ext");
25237
- const width = extent?.attributes?.["cx"] ? emuToPixels(extent.attributes["cx"]) : 100;
25238
- const height = extent?.attributes?.["cy"] ? emuToPixels(extent.attributes["cy"]) : 100;
25239
25579
  const rotation = xfrm?.attributes?.["rot"] ? rotToDegrees(xfrm.attributes["rot"]) : 0;
25240
25580
  const flipH = xfrm?.attributes?.["flipH"] === "1";
25241
25581
  const flipV = xfrm?.attributes?.["flipV"] === "1";
@@ -25243,6 +25583,15 @@ function getVectorShape({ params, graphicData }) {
25243
25583
  const fillColor = extractFillColor(spPr, style);
25244
25584
  const strokeColor = extractStrokeColor(spPr, style);
25245
25585
  const strokeWidth = extractStrokeWidth(spPr);
25586
+ const textBox = wsp.elements?.find((el) => el.name === "wps:txbx");
25587
+ const textBoxContent = textBox?.elements?.find((el) => el.name === "w:txbxContent");
25588
+ const bodyPr = wsp.elements?.find((el) => el.name === "wps:bodyPr");
25589
+ let textContent = null;
25590
+ let textAlign = "left";
25591
+ if (textBoxContent) {
25592
+ textContent = extractTextFromTextBox(textBoxContent, bodyPr);
25593
+ textAlign = textContent?.horizontalAlign || "left";
25594
+ }
25246
25595
  return {
25247
25596
  type: "vectorShape",
25248
25597
  attrs: {
@@ -25254,7 +25603,16 @@ function getVectorShape({ params, graphicData }) {
25254
25603
  flipV,
25255
25604
  fillColor,
25256
25605
  strokeColor,
25257
- strokeWidth
25606
+ strokeWidth,
25607
+ marginOffset,
25608
+ anchorData,
25609
+ wrap: wrap2,
25610
+ isAnchor,
25611
+ textContent,
25612
+ textAlign,
25613
+ textVerticalAlign: textContent?.verticalAlign,
25614
+ textInsets: textContent?.insets,
25615
+ originalAttributes: node?.attributes
25258
25616
  }
25259
25617
  };
25260
25618
  }
@@ -31148,16 +31506,24 @@ function translateFieldAnnotation(params) {
31148
31506
  hash: attrs.hash
31149
31507
  };
31150
31508
  const annotationAttrsJson = JSON.stringify(annotationAttrs);
31509
+ const sdtPrElements = [
31510
+ { name: "w:alias", attributes: { "w:val": attrs.displayLabel } },
31511
+ { name: "w:tag", attributes: { "w:val": annotationAttrsJson } },
31512
+ { name: "w:id", attributes: { "w:val": id } }
31513
+ ];
31514
+ if (attrs.sdtPr?.elements && Array.isArray(attrs.sdtPr.elements)) {
31515
+ const elementsToExclude = ["w:alias", "w:tag", "w:id"];
31516
+ const passthroughElements = attrs.sdtPr.elements.filter(
31517
+ (el) => el && el.name && !elementsToExclude.includes(el.name)
31518
+ );
31519
+ sdtPrElements.push(...passthroughElements);
31520
+ }
31151
31521
  const result = {
31152
31522
  name: "w:sdt",
31153
31523
  elements: [
31154
31524
  {
31155
31525
  name: "w:sdtPr",
31156
- elements: [
31157
- { name: "w:alias", attributes: { "w:val": attrs.displayLabel } },
31158
- { name: "w:tag", attributes: { "w:val": annotationAttrsJson } },
31159
- { name: "w:id", attributes: { "w:val": id } }
31160
- ]
31526
+ elements: sdtPrElements
31161
31527
  },
31162
31528
  {
31163
31529
  name: "w:sdtContent",
@@ -31389,7 +31755,7 @@ function translateDocumentSection(params) {
31389
31755
  type: "documentSection",
31390
31756
  description: attrs.description
31391
31757
  });
31392
- const sdtPr = generateSdtPrTagForDocumentSection(attrs.id, attrs.title, exportedTag);
31758
+ const sdtPr = generateSdtPrTagForDocumentSection(attrs.id, attrs.title, exportedTag, attrs.sdtPr);
31393
31759
  const { isLocked } = attrs;
31394
31760
  if (isLocked) {
31395
31761
  sdtPr.elements.push({
@@ -31406,73 +31772,115 @@ function translateDocumentSection(params) {
31406
31772
  };
31407
31773
  return result;
31408
31774
  }
31409
- const generateSdtPrTagForDocumentSection = (id, title, tag) => {
31775
+ const generateSdtPrTagForDocumentSection = (id, title, tag, sdtPr) => {
31776
+ const coreElements = [
31777
+ {
31778
+ name: "w:id",
31779
+ attributes: {
31780
+ "w:val": id
31781
+ }
31782
+ },
31783
+ {
31784
+ name: "w:alias",
31785
+ attributes: {
31786
+ "w:val": title
31787
+ }
31788
+ },
31789
+ {
31790
+ name: "w:tag",
31791
+ attributes: {
31792
+ "w:val": tag
31793
+ }
31794
+ }
31795
+ ];
31796
+ if (sdtPr?.elements && Array.isArray(sdtPr.elements)) {
31797
+ const elementsToExclude = ["w:id", "w:alias", "w:tag", "w:lock"];
31798
+ const passthroughElements = sdtPr.elements.filter((el) => el && el.name && !elementsToExclude.includes(el.name));
31799
+ coreElements.push(...passthroughElements);
31800
+ }
31410
31801
  return {
31411
31802
  name: "w:sdtPr",
31412
- elements: [
31413
- {
31414
- name: "w:id",
31415
- attributes: {
31416
- "w:val": id
31417
- }
31418
- },
31419
- {
31420
- name: "w:alias",
31421
- attributes: {
31422
- "w:val": title
31423
- }
31424
- },
31425
- {
31426
- name: "w:tag",
31427
- attributes: {
31428
- "w:val": tag
31429
- }
31430
- }
31431
- ]
31803
+ elements: coreElements
31432
31804
  };
31433
31805
  };
31434
31806
  function translateDocumentPartObj(params) {
31435
31807
  const { node } = params;
31436
31808
  const { attrs = {} } = node;
31437
31809
  const childContent = translateChildNodes({ ...params, nodes: node.content });
31810
+ const sdtPr = generateSdtPrForDocPartObj(attrs);
31438
31811
  const nodeElements = [
31812
+ sdtPr,
31439
31813
  {
31814
+ name: "w:sdtContent",
31815
+ elements: childContent
31816
+ }
31817
+ ];
31818
+ const result = {
31819
+ name: "w:sdt",
31820
+ elements: nodeElements
31821
+ };
31822
+ return result;
31823
+ }
31824
+ function generateSdtPrForDocPartObj(attrs) {
31825
+ const existingDocPartObj = attrs.sdtPr?.elements?.find((el) => el.name === "w:docPartObj");
31826
+ const existingDocPartGallery = existingDocPartObj?.elements?.find((el) => el.name === "w:docPartGallery")?.attributes?.["w:val"];
31827
+ const docPartGallery = attrs.docPartGallery ?? existingDocPartGallery ?? null;
31828
+ const id = attrs.id ?? attrs.sdtPr?.elements?.find((el) => el.name === "w:id")?.attributes?.["w:val"] ?? "";
31829
+ const docPartUnique = attrs.docPartUnique ?? existingDocPartObj?.elements?.some((el) => el.name === "w:docPartUnique") ?? false;
31830
+ if (docPartGallery === null) {
31831
+ if (attrs.sdtPr) {
31832
+ return attrs.sdtPr;
31833
+ }
31834
+ return {
31440
31835
  name: "w:sdtPr",
31441
31836
  elements: [
31442
31837
  {
31443
31838
  name: "w:id",
31444
31839
  attributes: {
31445
- "w:val": attrs.id
31840
+ "w:val": id
31446
31841
  }
31447
31842
  },
31448
31843
  {
31449
31844
  name: "w:docPartObj",
31450
- elements: [
31451
- {
31452
- name: "w:docPartGallery",
31453
- attributes: {
31454
- "w:val": attrs.docPartGallery
31455
- }
31456
- },
31457
- ...attrs.docPartUnique ? [
31458
- {
31459
- name: "w:docPartUnique"
31460
- }
31461
- ] : []
31462
- ]
31845
+ elements: []
31463
31846
  }
31464
31847
  ]
31848
+ };
31849
+ }
31850
+ const docPartObjElements = [
31851
+ {
31852
+ name: "w:docPartGallery",
31853
+ attributes: {
31854
+ "w:val": docPartGallery
31855
+ }
31856
+ }
31857
+ ];
31858
+ if (docPartUnique) {
31859
+ docPartObjElements.push({ name: "w:docPartUnique" });
31860
+ }
31861
+ const sdtPrElements = [
31862
+ {
31863
+ name: "w:id",
31864
+ attributes: {
31865
+ "w:val": id
31866
+ }
31465
31867
  },
31466
31868
  {
31467
- name: "w:sdtContent",
31468
- elements: childContent
31869
+ name: "w:docPartObj",
31870
+ elements: docPartObjElements
31469
31871
  }
31470
31872
  ];
31471
- const result = {
31472
- name: "w:sdt",
31473
- elements: nodeElements
31873
+ if (attrs.sdtPr?.elements && Array.isArray(attrs.sdtPr.elements)) {
31874
+ const elementsToExclude = ["w:id", "w:docPartObj"];
31875
+ const passthroughElements = attrs.sdtPr.elements.filter(
31876
+ (el) => el && el.name && !elementsToExclude.includes(el.name)
31877
+ );
31878
+ sdtPrElements.push(...passthroughElements);
31879
+ }
31880
+ return {
31881
+ name: "w:sdtPr",
31882
+ elements: sdtPrElements
31474
31883
  };
31475
- return result;
31476
31884
  }
31477
31885
  const RUN_LEVEL_WRAPPERS = /* @__PURE__ */ new Set(["w:hyperlink", "w:ins", "w:del"]);
31478
31886
  function convertSdtContentToRuns(elements) {
@@ -32379,15 +32787,26 @@ const getCommentSchema = (type2, commentIndex) => {
32379
32787
  }
32380
32788
  };
32381
32789
  };
32382
- const getConfig = (type2) => ({
32383
- xmlName: `${XML_NODE_NAME$7}${type2}`,
32384
- sdNodeOrKeyName: `${SD_NODE_NAME$6}${type2}`,
32385
- type: NodeTranslator.translatorTypes.NODE,
32386
- encode: () => {
32387
- },
32388
- decode: decode$7,
32389
- attributes: [attrConfig]
32390
- });
32790
+ const getConfig = (type2) => {
32791
+ const sdName = `${SD_NODE_NAME$6}${type2}`;
32792
+ const isStart = type2 === "Start";
32793
+ return {
32794
+ xmlName: `${XML_NODE_NAME$7}${type2}`,
32795
+ sdNodeOrKeyName: sdName,
32796
+ type: NodeTranslator.translatorTypes.NODE,
32797
+ encode: ({ nodes }) => {
32798
+ const node = nodes?.[0];
32799
+ if (!node) return void 0;
32800
+ const attrs = node.attributes ? { ...node.attributes } : {};
32801
+ return {
32802
+ type: isStart ? "commentRangeStart" : "commentRangeEnd",
32803
+ attrs
32804
+ };
32805
+ },
32806
+ decode: decode$7,
32807
+ attributes: [attrConfig]
32808
+ };
32809
+ };
32391
32810
  const commentRangeStartTranslator = NodeTranslator.from(getConfig("Start"));
32392
32811
  const commentRangeEndTranslator = NodeTranslator.from(getConfig("End"));
32393
32812
  const XML_NODE_NAME$6 = "sd:pageReference";
@@ -33111,127 +33530,224 @@ const sdtNodeHandlerEntity = {
33111
33530
  handlerName: "sdtNodeHandler",
33112
33531
  handler: handleSdtNode
33113
33532
  };
33114
- function parseProperties(node) {
33115
- const marks = [];
33116
- const unknownMarks = [];
33117
- const { attributes = {}, elements = [] } = node;
33118
- const { nodes, paragraphProperties = {}, runProperties = {} } = splitElementsAndProperties(elements);
33119
- const hasRun = elements.find((element) => element.name === "w:r");
33120
- if (hasRun) paragraphProperties.elements = paragraphProperties?.elements?.filter((el) => el.name !== "w:rPr");
33121
- if (runProperties && runProperties?.elements?.length) {
33122
- marks.push(...parseMarks(runProperties, unknownMarks));
33123
- }
33124
- if (paragraphProperties && paragraphProperties.elements?.length) {
33125
- const disallowedParagraphProperties = ["w:u"];
33126
- const filteredParagraphProperties = {
33127
- ...paragraphProperties,
33128
- elements: paragraphProperties.elements?.filter((el) => !disallowedParagraphProperties.includes(el.name))
33129
- };
33130
- marks.push(...parseMarks(filteredParagraphProperties, unknownMarks));
33131
- }
33132
- marks.push(...handleStyleChangeMarks(runProperties, marks));
33133
- if (paragraphProperties && paragraphProperties.elements?.length) {
33134
- attributes["paragraphProperties"] = paragraphProperties;
33533
+ const translatorList = Array.from(
33534
+ /* @__PURE__ */ new Set([
33535
+ translator$1M,
33536
+ translator$6,
33537
+ translator$5,
33538
+ translator$4,
33539
+ translator$3,
33540
+ translator$1L,
33541
+ translator$1K,
33542
+ translator$1J,
33543
+ translator$20,
33544
+ translator$1r,
33545
+ translator$1$,
33546
+ translator$q,
33547
+ translator$7,
33548
+ translator$8,
33549
+ translator$1p,
33550
+ translator$23,
33551
+ translator$F,
33552
+ translator$1R,
33553
+ translator$1H,
33554
+ translator$1W,
33555
+ translator$1G,
33556
+ translator$2,
33557
+ translator$1F,
33558
+ translator$s,
33559
+ translator$1X,
33560
+ translator$X,
33561
+ translator$1E,
33562
+ translator$E,
33563
+ translator$D,
33564
+ translator$b,
33565
+ translator$Z,
33566
+ translator$J,
33567
+ translator$I,
33568
+ translator$C,
33569
+ translator$K,
33570
+ translator$22,
33571
+ translator$10,
33572
+ translator$1_,
33573
+ translator$1x,
33574
+ translator$1D,
33575
+ translator$1w,
33576
+ translator$V,
33577
+ translator$U,
33578
+ translator$1C,
33579
+ translator$1B,
33580
+ translator$1A,
33581
+ translator$1z,
33582
+ translator$1P,
33583
+ translator$1n,
33584
+ translator$1y,
33585
+ translator$O,
33586
+ translator$1v,
33587
+ translator$1u,
33588
+ translator$1t,
33589
+ translator$1s,
33590
+ translator$11,
33591
+ translator$1f,
33592
+ translator$1h,
33593
+ translator$12,
33594
+ translator$1g,
33595
+ translator$$,
33596
+ translator$1V,
33597
+ translator$1N,
33598
+ translator$1U,
33599
+ translator$1l,
33600
+ translator$r,
33601
+ translator$1Q,
33602
+ translator$1e,
33603
+ translator$1d,
33604
+ translator$1c,
33605
+ translator$1b,
33606
+ translator$1a,
33607
+ translator$T,
33608
+ translator$1Y,
33609
+ translator$1T,
33610
+ translator$1S,
33611
+ translator$1,
33612
+ translator$21,
33613
+ translator$19,
33614
+ translator$9,
33615
+ translator$e,
33616
+ translator$p,
33617
+ translator$d,
33618
+ translator$B,
33619
+ translator$o,
33620
+ translator$a,
33621
+ translator$A,
33622
+ translator$n,
33623
+ translator$m,
33624
+ translator$l,
33625
+ translator$k,
33626
+ translator$c,
33627
+ translator$j,
33628
+ translator$i,
33629
+ translator$h,
33630
+ translator$g,
33631
+ translator$f,
33632
+ translator$G,
33633
+ translator$P,
33634
+ translator$M,
33635
+ translator$N,
33636
+ translator$H,
33637
+ translator$_,
33638
+ translator$17,
33639
+ translator$R,
33640
+ translator$v,
33641
+ translator$Q,
33642
+ translator$z,
33643
+ translator$w,
33644
+ translator$18,
33645
+ translator$16,
33646
+ translator$15,
33647
+ translator$1j,
33648
+ translator$1Z,
33649
+ translator$L,
33650
+ translator$Y,
33651
+ translator$y,
33652
+ translator$x,
33653
+ translator$14,
33654
+ translator$13,
33655
+ translator$u,
33656
+ translator$t,
33657
+ commentRangeStartTranslator,
33658
+ commentRangeEndTranslator
33659
+ ])
33660
+ );
33661
+ const additionalHandlers = Object.freeze(
33662
+ translatorList.reduce((acc, translator2) => {
33663
+ const key = translator2?.xmlName;
33664
+ if (!key) return acc;
33665
+ acc[key] = translator2;
33666
+ return acc;
33667
+ }, {})
33668
+ );
33669
+ const baseHandlers = {
33670
+ ...additionalHandlers
33671
+ };
33672
+ const registeredHandlers = Object.freeze(baseHandlers);
33673
+ const INLINE_PARENT_NAMES = /* @__PURE__ */ new Set([
33674
+ "w:r",
33675
+ "w:hyperlink",
33676
+ "w:smartTag",
33677
+ "w:fldSimple",
33678
+ "w:proofErr",
33679
+ "w:del",
33680
+ "w:ins"
33681
+ ]);
33682
+ const INLINE_NODE_NAMES = /* @__PURE__ */ new Set([
33683
+ "m:oMathPara",
33684
+ "m:oMath",
33685
+ "m:t",
33686
+ "m:r",
33687
+ "m:ctrlPr",
33688
+ "m:sSupPr",
33689
+ "m:e",
33690
+ "m:sup",
33691
+ "m:sSup"
33692
+ ]);
33693
+ const BLOCK_BOUNDARY_NAMES = /* @__PURE__ */ new Set(["w:p", "w:body", "w:tbl", "w:tc", "w:tr"]);
33694
+ const isInlineContext = (path = [], currentNodeName) => {
33695
+ if (currentNodeName && INLINE_NODE_NAMES.has(currentNodeName)) {
33696
+ return true;
33135
33697
  }
33136
- if (marks && node.name === "w:p") {
33137
- marks.forEach((mark) => {
33138
- const attrValue = Object.keys(mark.attrs ?? {})[0];
33139
- if (attrValue) {
33140
- const value = mark.attrs[attrValue];
33141
- attributes[attrValue] = value;
33142
- }
33143
- });
33698
+ if (!Array.isArray(path) || path.length === 0) return false;
33699
+ for (let i = path.length - 1; i >= 0; i--) {
33700
+ const ancestorName = path[i]?.name;
33701
+ if (!ancestorName) continue;
33702
+ if (INLINE_NODE_NAMES.has(ancestorName) || INLINE_PARENT_NAMES.has(ancestorName)) {
33703
+ return true;
33704
+ }
33705
+ if (BLOCK_BOUNDARY_NAMES.has(ancestorName)) {
33706
+ return false;
33707
+ }
33144
33708
  }
33145
- return { elements: nodes, attributes, marks, unknownMarks };
33146
- }
33147
- function splitElementsAndProperties(elements) {
33148
- const pPr = elements.find((el) => el.name === "w:pPr");
33149
- const rPr = elements.find((el) => el.name === "w:rPr");
33150
- const sectPr = elements.find((el) => el.name === "w:sectPr");
33151
- const els = elements.filter((el) => el.name !== "w:pPr" && el.name !== "w:rPr" && el.name !== "w:sectPr");
33152
- return {
33153
- nodes: els,
33154
- paragraphProperties: pPr,
33155
- runProperties: rPr,
33156
- sectionProperties: sectPr
33157
- };
33158
- }
33159
- function getElementName(element) {
33160
- return SuperConverter.allowedElements[element.name || element.type];
33161
- }
33162
- const isPropertiesElement = (element) => {
33163
- return !!SuperConverter.propertyTypes[element.name || element.type];
33709
+ return false;
33164
33710
  };
33165
- const handleStandardNode = (params) => {
33166
- const { nodes, docx, nodeListHandler } = params;
33167
- if (!nodes || nodes.length === 0) {
33168
- return { nodes: [], consumed: 0 };
33169
- }
33711
+ const handlePassthroughNode = (params) => {
33712
+ const { nodes = [] } = params;
33170
33713
  const node = nodes[0];
33171
- const { name } = node;
33172
- const { attributes, elements, marks = [] } = parseProperties(node);
33173
- if (name === "w:sdt") {
33714
+ if (!node) return { nodes: [], consumed: 0 };
33715
+ if (registeredHandlers[node.name]) {
33174
33716
  return { nodes: [], consumed: 0 };
33175
33717
  }
33176
- if (isPropertiesElement(node)) {
33177
- return {
33178
- nodes: [
33179
- {
33180
- type: getElementName(node),
33181
- attrs: { ...attributes },
33182
- marks: []
33183
- }
33184
- ],
33185
- consumed: 0
33186
- };
33187
- }
33188
- if (!getElementName(node)) {
33189
- return {
33190
- nodes: [
33191
- {
33192
- type: name,
33193
- content: elements,
33194
- attrs: { ...attributes },
33195
- marks
33196
- }
33197
- ],
33198
- consumed: 0,
33199
- unhandled: true
33200
- };
33201
- }
33202
- const content = [];
33203
- const parentStyleId = getParentStyleId(node);
33204
- if (elements && elements.length) {
33205
- const updatedElements = elements.map((el) => {
33206
- if (!el.marks) el.marks = [];
33207
- el.marks.push(...marks);
33208
- return el;
33209
- });
33718
+ const originalXml = carbonCopy(node) || {};
33719
+ const originalElementsSource = originalXml.elements;
33720
+ const originalElements = originalElementsSource ? carbonCopy(originalElementsSource) : [];
33721
+ const childElements = Array.isArray(node.elements) ? node.elements : [];
33722
+ let childContent = [];
33723
+ if (childElements.length && params.nodeListHandler?.handler) {
33210
33724
  const childParams = {
33211
33725
  ...params,
33212
- nodes: updatedElements,
33213
- parentStyleId,
33726
+ nodes: childElements,
33214
33727
  path: [...params.path || [], node]
33215
33728
  };
33216
- const childContent = nodeListHandler.handler(childParams);
33217
- content.push(...childContent);
33729
+ childContent = params.nodeListHandler.handler(childParams) || [];
33218
33730
  }
33219
- const resultNode = {
33220
- type: getElementName(node),
33221
- content,
33222
- attrs: { ...attributes },
33223
- marks: []
33731
+ if (originalElements?.length) {
33732
+ originalXml.elements = originalElements;
33733
+ }
33734
+ const passthroughNode = {
33735
+ type: isInlineContext(params.path, node.name) ? "passthroughInline" : "passthroughBlock",
33736
+ attrs: {
33737
+ originalName: node.name,
33738
+ originalXml
33739
+ },
33740
+ marks: [],
33741
+ content: childContent
33742
+ };
33743
+ return {
33744
+ nodes: [passthroughNode],
33745
+ consumed: 1
33224
33746
  };
33225
- return { nodes: [resultNode], consumed: 1 };
33226
- };
33227
- const getParentStyleId = (node) => {
33228
- const pPr = node.elements?.find((el) => el.name === "w:pPr");
33229
- const styleTag = pPr?.elements?.find((el) => el.name === "w:pStyle");
33230
- return styleTag ? styleTag.attributes["w:val"] : null;
33231
33747
  };
33232
- const standardNodeHandlerEntity = {
33233
- handlerName: "standardNodeHandler",
33234
- handler: handleStandardNode
33748
+ const passthroughNodeHandlerEntity = {
33749
+ handlerName: "passthroughNodeHandler",
33750
+ handler: handlePassthroughNode
33235
33751
  };
33236
33752
  const handler = (params) => {
33237
33753
  const { nodes } = params;
@@ -33255,13 +33771,6 @@ const handleBookmarkNode = (params) => {
33255
33771
  return { nodes: [], consumed: 0 };
33256
33772
  }
33257
33773
  const node = nodes[0];
33258
- const handleStandardNode2 = nodeListHandler.handlerEntities.find(
33259
- (e) => e.handlerName === "standardNodeHandler"
33260
- )?.handler;
33261
- if (!handleStandardNode2) {
33262
- console.error("Standard node handler not found");
33263
- return { nodes: [], consumed: 0 };
33264
- }
33265
33774
  const customMarks = editor?.extensionService?.extensions?.filter((e) => e.isExternal === true) || [];
33266
33775
  const bookmarkName = node.attributes["w:name"]?.split(";")[0];
33267
33776
  const customMark = customMarks.find((mark) => mark.name === bookmarkName);
@@ -33270,7 +33779,6 @@ const handleBookmarkNode = (params) => {
33270
33779
  (n) => n.name === "w:bookmarkEnd" && n.attributes["w:id"] === node.attributes["w:id"]
33271
33780
  );
33272
33781
  const textNodes = nodes.slice(1, bookmarkEndIndex);
33273
- const nodeListHandler2 = params.nodeListHandler;
33274
33782
  const attrs = {};
33275
33783
  node.attributes["w:name"].split(";").forEach((name) => {
33276
33784
  const [key, value] = name.split("=");
@@ -33278,7 +33786,7 @@ const handleBookmarkNode = (params) => {
33278
33786
  attrs[key] = value;
33279
33787
  }
33280
33788
  });
33281
- const translatedText = nodeListHandler2.handler({
33789
+ const translatedText = nodeListHandler.handler({
33282
33790
  ...params,
33283
33791
  nodes: textNodes,
33284
33792
  path: [...params.path || [], node]
@@ -33294,13 +33802,11 @@ const handleBookmarkNode = (params) => {
33294
33802
  consumed: translatedText.length + 2
33295
33803
  };
33296
33804
  }
33297
- const updatedParams = { ...params, nodes: [node] };
33298
- const result = handleStandardNode2(updatedParams);
33299
- if (result.nodes.length === 1) {
33300
- result.nodes[0].attrs.name = node.attributes["w:name"];
33301
- result.nodes[0].attrs.id = node.attributes["w:id"];
33805
+ const encoded = translator$8.encode({ ...params, nodes: [node] });
33806
+ if (!encoded) {
33807
+ return { nodes: [], consumed: 0 };
33302
33808
  }
33303
- return result;
33809
+ return { nodes: [encoded], consumed: 1 };
33304
33810
  };
33305
33811
  const handleBookmarkStartNode = (params) => {
33306
33812
  const { nodes } = params;
@@ -34222,18 +34728,22 @@ const getInstructionPreProcessor = (instruction) => {
34222
34728
  const preProcessNodesForFldChar = (nodes = [], docx) => {
34223
34729
  const processedNodes = [];
34224
34730
  let collectedNodesStack = [];
34731
+ let rawCollectedNodesStack = [];
34225
34732
  let currentFieldStack = [];
34226
34733
  let unpairedEnd = null;
34227
34734
  let collecting = false;
34228
34735
  const finalizeField = () => {
34229
34736
  if (collecting) {
34230
34737
  const collectedNodes = collectedNodesStack.pop().filter((n) => n !== null);
34738
+ const rawCollectedNodes = rawCollectedNodesStack.pop().filter((n) => n !== null);
34231
34739
  const currentField = currentFieldStack.pop();
34232
- const combined = _processCombinedNodesForFldChar(collectedNodes, currentField.instrText.trim(), docx);
34740
+ const combinedResult = _processCombinedNodesForFldChar(collectedNodes, currentField.instrText.trim(), docx);
34741
+ const outputNodes = combinedResult.handled ? combinedResult.nodes : rawCollectedNodes;
34233
34742
  if (collectedNodesStack.length === 0) {
34234
- processedNodes.push(...combined);
34743
+ processedNodes.push(...outputNodes);
34235
34744
  } else {
34236
- collectedNodesStack[collectedNodesStack.length - 1].push(...combined);
34745
+ collectedNodesStack[collectedNodesStack.length - 1].push(...outputNodes);
34746
+ rawCollectedNodesStack[rawCollectedNodesStack.length - 1].push(...outputNodes);
34237
34747
  }
34238
34748
  } else {
34239
34749
  unpairedEnd = true;
@@ -34245,18 +34755,26 @@ const preProcessNodesForFldChar = (nodes = [], docx) => {
34245
34755
  const instrTextEl = node.elements?.find((el) => el.name === "w:instrText");
34246
34756
  collecting = collectedNodesStack.length > 0;
34247
34757
  if (fldType === "begin") {
34248
- collectedNodesStack.push([null]);
34758
+ collectedNodesStack.push([]);
34759
+ rawCollectedNodesStack.push([node]);
34249
34760
  currentFieldStack.push({ instrText: "" });
34250
34761
  continue;
34251
34762
  }
34252
34763
  if (instrTextEl && collecting && currentFieldStack.length > 0) {
34764
+ rawCollectedNodesStack[rawCollectedNodesStack.length - 1].push(node);
34253
34765
  currentFieldStack[currentFieldStack.length - 1].instrText += (instrTextEl.elements?.[0]?.text || "") + " ";
34254
34766
  continue;
34255
34767
  }
34256
34768
  if (fldType === "end") {
34769
+ if (collecting) {
34770
+ rawCollectedNodesStack[rawCollectedNodesStack.length - 1].push(node);
34771
+ }
34257
34772
  finalizeField();
34258
34773
  continue;
34259
34774
  } else if (fldType === "separate") {
34775
+ if (collecting) {
34776
+ rawCollectedNodesStack[rawCollectedNodesStack.length - 1].push(node);
34777
+ }
34260
34778
  continue;
34261
34779
  }
34262
34780
  if (Array.isArray(node.elements)) {
@@ -34266,17 +34784,21 @@ const preProcessNodesForFldChar = (nodes = [], docx) => {
34266
34784
  childResult.unpairedBegin.forEach((pendingField) => {
34267
34785
  currentFieldStack.push(pendingField.fieldInfo);
34268
34786
  collectedNodesStack.push([node]);
34787
+ rawCollectedNodesStack.push([node]);
34269
34788
  });
34270
34789
  } else if (childResult.unpairedEnd) {
34271
34790
  collectedNodesStack[collectedNodesStack.length - 1].push(node);
34791
+ rawCollectedNodesStack[rawCollectedNodesStack.length - 1].push(node);
34272
34792
  finalizeField();
34273
34793
  } else if (collecting) {
34274
34794
  collectedNodesStack[collectedNodesStack.length - 1].push(node);
34795
+ rawCollectedNodesStack[rawCollectedNodesStack.length - 1].push(node);
34275
34796
  } else {
34276
34797
  processedNodes.push(node);
34277
34798
  }
34278
34799
  } else if (collecting) {
34279
34800
  collectedNodesStack[collectedNodesStack.length - 1].push(node);
34801
+ rawCollectedNodesStack[rawCollectedNodesStack.length - 1].push(node);
34280
34802
  } else {
34281
34803
  processedNodes.push(node);
34282
34804
  }
@@ -34298,11 +34820,91 @@ const _processCombinedNodesForFldChar = (nodesToCombine = [], instrText, docx) =
34298
34820
  const instructionType = instrText.trim().split(" ")[0];
34299
34821
  const instructionPreProcessor = getInstructionPreProcessor(instructionType);
34300
34822
  if (instructionPreProcessor) {
34301
- return instructionPreProcessor(nodesToCombine, instrText, docx);
34302
- } else {
34303
- return nodesToCombine;
34823
+ return { nodes: instructionPreProcessor(nodesToCombine, instrText, docx), handled: true };
34304
34824
  }
34825
+ return { nodes: nodesToCombine, handled: false };
34305
34826
  };
34827
+ const preProcessPageFieldsOnly = (nodes = []) => {
34828
+ const processedNodes = [];
34829
+ let i = 0;
34830
+ while (i < nodes.length) {
34831
+ const node = nodes[i];
34832
+ const fldCharEl = node.elements?.find((el) => el.name === "w:fldChar");
34833
+ const fldType = fldCharEl?.attributes?.["w:fldCharType"];
34834
+ if (fldType === "begin") {
34835
+ const fieldInfo = scanFieldSequence(nodes, i);
34836
+ if (fieldInfo && (fieldInfo.fieldType === "PAGE" || fieldInfo.fieldType === "NUMPAGES")) {
34837
+ const preprocessor = fieldInfo.fieldType === "PAGE" ? preProcessPageInstruction : preProcessNumPagesInstruction;
34838
+ const contentNodes = fieldInfo.contentNodes;
34839
+ const processedField = preprocessor(contentNodes, fieldInfo.instrText);
34840
+ processedNodes.push(...processedField);
34841
+ i = fieldInfo.endIndex + 1;
34842
+ continue;
34843
+ } else {
34844
+ if (fieldInfo) {
34845
+ for (let j2 = i; j2 <= fieldInfo.endIndex; j2++) {
34846
+ const passNode = nodes[j2];
34847
+ if (Array.isArray(passNode.elements)) {
34848
+ const childResult = preProcessPageFieldsOnly(passNode.elements);
34849
+ passNode.elements = childResult.processedNodes;
34850
+ }
34851
+ processedNodes.push(passNode);
34852
+ }
34853
+ i = fieldInfo.endIndex + 1;
34854
+ continue;
34855
+ }
34856
+ }
34857
+ }
34858
+ if (Array.isArray(node.elements)) {
34859
+ const childResult = preProcessPageFieldsOnly(node.elements);
34860
+ node.elements = childResult.processedNodes;
34861
+ }
34862
+ processedNodes.push(node);
34863
+ i++;
34864
+ }
34865
+ return { processedNodes };
34866
+ };
34867
+ function scanFieldSequence(nodes, beginIndex) {
34868
+ let instrText = "";
34869
+ let separateIndex = -1;
34870
+ let endIndex = -1;
34871
+ const contentNodes = [];
34872
+ for (let i = beginIndex + 1; i < nodes.length; i++) {
34873
+ const node = nodes[i];
34874
+ const fldCharEl = node.elements?.find((el) => el.name === "w:fldChar");
34875
+ const fldType = fldCharEl?.attributes?.["w:fldCharType"];
34876
+ const instrTextEl = node.elements?.find((el) => el.name === "w:instrText");
34877
+ if (instrTextEl) {
34878
+ instrText += (instrTextEl.elements?.[0]?.text || "") + " ";
34879
+ }
34880
+ if (fldType === "separate") {
34881
+ separateIndex = i;
34882
+ } else if (fldType === "end") {
34883
+ endIndex = i;
34884
+ break;
34885
+ } else if (separateIndex !== -1 && fldType !== "begin") {
34886
+ contentNodes.push(node);
34887
+ }
34888
+ }
34889
+ if (endIndex === -1) {
34890
+ return null;
34891
+ }
34892
+ const fieldType = instrText.trim().split(" ")[0];
34893
+ return {
34894
+ fieldType,
34895
+ instrText: instrText.trim(),
34896
+ contentNodes,
34897
+ endIndex
34898
+ };
34899
+ }
34900
+ const commentRangeStartHandlerEntity = generateV2HandlerEntity(
34901
+ "commentRangeStartHandler",
34902
+ commentRangeStartTranslator
34903
+ );
34904
+ const commentRangeEndHandlerEntity = generateV2HandlerEntity(
34905
+ "commentRangeEndHandler",
34906
+ commentRangeEndTranslator
34907
+ );
34306
34908
  const createDocumentJson = (docx, converter, editor) => {
34307
34909
  const json = carbonCopy(getInitialJSON(docx));
34308
34910
  if (!json) return null;
@@ -34364,6 +34966,7 @@ const createDocumentJson = (docx, converter, editor) => {
34364
34966
  path: []
34365
34967
  });
34366
34968
  parsedContent = filterOutRootInlineNodes(parsedContent);
34969
+ collapseWhitespaceNextToInlinePassthrough(parsedContent);
34367
34970
  const result = {
34368
34971
  type: "doc",
34369
34972
  content: parsedContent,
@@ -34404,6 +35007,8 @@ const defaultNodeListHandler = () => {
34404
35007
  bookmarkStartNodeHandlerEntity,
34405
35008
  bookmarkEndNodeHandlerEntity,
34406
35009
  hyperlinkNodeHandlerEntity,
35010
+ commentRangeStartHandlerEntity,
35011
+ commentRangeEndHandlerEntity,
34407
35012
  drawingNodeHandlerEntity,
34408
35013
  trackChangeNodeHandlerEntity,
34409
35014
  tableNodeHandlerEntity,
@@ -34412,7 +35017,7 @@ const defaultNodeListHandler = () => {
34412
35017
  autoPageHandlerEntity,
34413
35018
  autoTotalPageCountEntity,
34414
35019
  pageReferenceEntity,
34415
- standardNodeHandlerEntity
35020
+ passthroughNodeHandlerEntity
34416
35021
  ];
34417
35022
  const handler2 = createNodeListHandler(entities);
34418
35023
  return {
@@ -34699,6 +35304,8 @@ const importHeadersFooters = (docx, converter, mainEditor) => {
34699
35304
  editor.options.annotations = true;
34700
35305
  headers.forEach((header) => {
34701
35306
  const { rId, referenceFile, currentFileName } = getHeaderFooterSectionData(header, docx);
35307
+ const headerNodes = carbonCopy(referenceFile.elements[0].elements ?? []);
35308
+ const { processedNodes: headerProcessedNodes } = preProcessPageFieldsOnly(headerNodes);
34702
35309
  const sectPrHeader = allSectPrElements.find(
34703
35310
  (el) => el.name === "w:headerReference" && el.attributes["r:id"] === rId
34704
35311
  );
@@ -34706,7 +35313,7 @@ const importHeadersFooters = (docx, converter, mainEditor) => {
34706
35313
  if (converter.headerIds[sectionType]) sectionType = null;
34707
35314
  const nodeListHandler = defaultNodeListHandler();
34708
35315
  let schema = nodeListHandler.handler({
34709
- nodes: referenceFile.elements[0].elements,
35316
+ nodes: headerProcessedNodes,
34710
35317
  nodeListHandler,
34711
35318
  docx,
34712
35319
  converter,
@@ -34727,13 +35334,15 @@ const importHeadersFooters = (docx, converter, mainEditor) => {
34727
35334
  if (titlePg) converter.headerIds.titlePg = true;
34728
35335
  footers.forEach((footer) => {
34729
35336
  const { rId, referenceFile, currentFileName } = getHeaderFooterSectionData(footer, docx);
35337
+ const footerNodes = carbonCopy(referenceFile.elements[0].elements ?? []);
35338
+ const { processedNodes: footerProcessedNodes } = preProcessPageFieldsOnly(footerNodes);
34730
35339
  const sectPrFooter = allSectPrElements.find(
34731
35340
  (el) => el.name === "w:footerReference" && el.attributes["r:id"] === rId
34732
35341
  );
34733
35342
  const sectionType = sectPrFooter?.attributes["w:type"];
34734
35343
  const nodeListHandler = defaultNodeListHandler();
34735
35344
  let schema = nodeListHandler.handler({
34736
- nodes: referenceFile.elements[0].elements,
35345
+ nodes: footerProcessedNodes,
34737
35346
  nodeListHandler,
34738
35347
  docx,
34739
35348
  converter,
@@ -34796,6 +35405,51 @@ function filterOutRootInlineNodes(content = []) {
34796
35405
  ]);
34797
35406
  return content.filter((node) => node && typeof node.type === "string" && !INLINE_TYPES.has(node.type));
34798
35407
  }
35408
+ function collapseWhitespaceNextToInlinePassthrough(content = []) {
35409
+ if (!Array.isArray(content) || content.length === 0) return;
35410
+ const sequence = collectInlineSequence(content);
35411
+ sequence.forEach((entry, index2) => {
35412
+ if (entry.kind !== "passthrough") return;
35413
+ const prev = findNeighborText(sequence, index2, -1);
35414
+ const next = findNeighborText(sequence, index2, 1);
35415
+ if (!prev || !next) return;
35416
+ if (!prev.node.text.endsWith(" ") || !next.node.text.startsWith(" ")) return;
35417
+ prev.node.text = prev.node.text.replace(/ +$/, " ");
35418
+ next.node.text = next.node.text.replace(/^ +/, "");
35419
+ if (next.node.text.length === 0) {
35420
+ next.parent.splice(next.index, 1);
35421
+ }
35422
+ });
35423
+ }
35424
+ function collectInlineSequence(nodes, result = [], insidePassthrough = false) {
35425
+ if (!Array.isArray(nodes) || nodes.length === 0) return result;
35426
+ nodes.forEach((node, index2) => {
35427
+ if (!node) return;
35428
+ const isPassthrough = node.type === "passthroughInline";
35429
+ if (isPassthrough && !insidePassthrough) {
35430
+ result.push({ kind: "passthrough", parent: nodes, index: index2 });
35431
+ }
35432
+ if (node.type === "text" && typeof node.text === "string" && !insidePassthrough) {
35433
+ result.push({ kind: "text", node, parent: nodes, index: index2 });
35434
+ }
35435
+ if (Array.isArray(node.content) && node.content.length) {
35436
+ const nextInside = insidePassthrough || isPassthrough;
35437
+ collectInlineSequence(node.content, result, nextInside);
35438
+ }
35439
+ });
35440
+ return result;
35441
+ }
35442
+ function findNeighborText(sequence, startIndex, direction) {
35443
+ let cursor = startIndex + direction;
35444
+ while (cursor >= 0 && cursor < sequence.length) {
35445
+ const entry = sequence[cursor];
35446
+ if (entry.kind === "text") {
35447
+ return entry;
35448
+ }
35449
+ cursor += direction;
35450
+ }
35451
+ return null;
35452
+ }
34799
35453
  function getThemeColorPalette(docx) {
34800
35454
  const themePart = docx?.["word/theme/theme1.xml"];
34801
35455
  if (!themePart || !Array.isArray(themePart.elements)) return void 0;
@@ -35158,7 +35812,9 @@ function exportSchemaToJson(params) {
35158
35812
  "page-number": translator$4,
35159
35813
  "total-page-number": translator$3,
35160
35814
  pageReference: translator$6,
35161
- tableOfContents: translator$5
35815
+ tableOfContents: translator$5,
35816
+ passthroughBlock: translatePassthroughNode,
35817
+ passthroughInline: translatePassthroughNode
35162
35818
  };
35163
35819
  let handler2 = router[type2];
35164
35820
  if (handler2 && "decode" in handler2 && typeof handler2.decode === "function") {
@@ -35170,6 +35826,11 @@ function exportSchemaToJson(params) {
35170
35826
  }
35171
35827
  return handler2(params);
35172
35828
  }
35829
+ function translatePassthroughNode(params) {
35830
+ const original = params?.node?.attrs?.originalXml;
35831
+ if (!original) return null;
35832
+ return carbonCopy(original);
35833
+ }
35173
35834
  function translateBodyNode(params) {
35174
35835
  let sectPr = params.bodyNode?.elements?.find((n) => n.name === "w:sectPr");
35175
35836
  if (!sectPr) {
@@ -35869,7 +36530,7 @@ const _SuperConverter = class _SuperConverter {
35869
36530
  static getStoredSuperdocVersion(docx) {
35870
36531
  return _SuperConverter.getStoredCustomProperty(docx, "SuperdocVersion");
35871
36532
  }
35872
- static setStoredSuperdocVersion(docx = this.convertedXml, version = "1.0.0-beta.13") {
36533
+ static setStoredSuperdocVersion(docx = this.convertedXml, version = "1.0.0-beta.15") {
35873
36534
  return _SuperConverter.setStoredCustomProperty(docx, "SuperdocVersion", version, false);
35874
36535
  }
35875
36536
  /**
@@ -36483,7 +37144,6 @@ export {
36483
37144
  inputRulesPlugin as Z,
36484
37145
  TrackDeleteMarkName as _,
36485
37146
  Plugin as a,
36486
- translator$L as a$,
36487
37147
  v4 as a0,
36488
37148
  TrackFormatMarkName as a1,
36489
37149
  comments_module_events as a2,
@@ -36509,18 +37169,7 @@ export {
36509
37169
  vClickOutside as aM,
36510
37170
  getActiveFormatting as aN,
36511
37171
  getFileObject as aO,
36512
- translator$H as aP,
36513
- translator$N as aQ,
36514
- translator$P as aR,
36515
- translator$I as aS,
36516
- translator$J as aT,
36517
- translator$Q as aU,
36518
- translator$R as aV,
36519
- translator$17 as aW,
36520
- translator$K as aX,
36521
- translator$_ as aY,
36522
- translator$M as aZ,
36523
- translator$O as a_,
37172
+ registeredHandlers as aP,
36524
37173
  posToDOMRect as aa,
36525
37174
  CommandService as ab,
36526
37175
  SuperConverter as ac,
@@ -36548,80 +37197,7 @@ export {
36548
37197
  convertSizeToCSS as ay,
36549
37198
  SelectionRange as az,
36550
37199
  Slice as b,
36551
- translator$23 as b$,
36552
- translator$Z as b0,
36553
- translator$Y as b1,
36554
- commentRangeEndTranslator as b2,
36555
- commentRangeStartTranslator as b3,
36556
- translator$t as b4,
36557
- translator$u as b5,
36558
- translator$x as b6,
36559
- translator$y as b7,
36560
- translator$1Z as b8,
36561
- translator$w as b9,
36562
- translator$T as bA,
36563
- translator$1Q as bB,
36564
- translator$r as bC,
36565
- translator$1l as bD,
36566
- translator$1U as bE,
36567
- translator$1N as bF,
36568
- translator$1V as bG,
36569
- translator$$ as bH,
36570
- translator$11 as bI,
36571
- translator$1n as bJ,
36572
- translator$1C as bK,
36573
- translator$U as bL,
36574
- translator$V as bM,
36575
- translator$1_ as bN,
36576
- translator$10 as bO,
36577
- translator$22 as bP,
36578
- translator$C as bQ,
36579
- translator$b as bR,
36580
- translator$D as bS,
36581
- translator$E as bT,
36582
- translator$X as bU,
36583
- translator$s as bV,
36584
- translator$1F as bW,
36585
- translator$1W as bX,
36586
- translator$1H as bY,
36587
- translator$1R as bZ,
36588
- translator$F as b_,
36589
- translator$z as ba,
36590
- translator$v as bb,
36591
- translator$1j as bc,
36592
- translator$G as bd,
36593
- translator$f as be,
36594
- translator$g as bf,
36595
- translator$h as bg,
36596
- translator$i as bh,
36597
- translator$j as bi,
36598
- translator$c as bj,
36599
- translator$k as bk,
36600
- translator$l as bl,
36601
- translator$m as bm,
36602
- translator$n as bn,
36603
- translator$A as bo,
36604
- translator$a as bp,
36605
- translator$o as bq,
36606
- translator$B as br,
36607
- translator$d as bs,
36608
- translator$p as bt,
36609
- translator$e as bu,
36610
- translator$9 as bv,
36611
- translator$21 as bw,
36612
- translator$1S as bx,
36613
- translator$1T as by,
36614
- translator$1Y as bz,
36615
37200
  DOMParser$1 as c,
36616
- translator$1p as c0,
36617
- translator$8 as c1,
36618
- translator$7 as c2,
36619
- translator$q as c3,
36620
- translator$1$ as c4,
36621
- translator$20 as c5,
36622
- translator$5 as c6,
36623
- translator$6 as c7,
36624
- translator$1M as c8,
36625
37201
  Mark as d,
36626
37202
  dropPoint as e,
36627
37203
  callOrGet as f,