@harbour-enterprises/superdoc 0.18.0-next.5 → 0.18.0-next.6

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 (32) hide show
  1. package/dist/chunks/{PdfViewer-DDwiCSwf.cjs → PdfViewer-D923RAYf.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-Md3OYLQ6.es.js → PdfViewer-oLMiGubp.es.js} +1 -1
  3. package/dist/chunks/{index-B8Gqq2Ls.cjs → index-BSBoH60z.cjs} +3 -3
  4. package/dist/chunks/{index-nnK3k8Eg.es.js → index-DfESC4_z.es.js} +3 -3
  5. package/dist/chunks/{super-editor.es-C2jrGo_q.es.js → super-editor.es--ZHZr2PU.es.js} +620 -495
  6. package/dist/chunks/{super-editor.es-DPPXteBi.cjs → super-editor.es-CWyHUECy.cjs} +620 -495
  7. package/dist/super-editor/ai-writer.es.js +2 -2
  8. package/dist/super-editor/chunks/{converter-YnaMMkRN.js → converter-5vEzqeeM.js} +1201 -1076
  9. package/dist/super-editor/chunks/{docx-zipper-Bq9-qqP_.js → docx-zipper-CWFbV6tN.js} +1 -1
  10. package/dist/super-editor/chunks/{editor-CAEseNKq.js → editor-CRz0_fqK.js} +3 -3
  11. package/dist/super-editor/chunks/{toolbar-BxxxSTHJ.js → toolbar-DCZwgkzr.js} +2 -2
  12. package/dist/super-editor/converter.es.js +1 -1
  13. package/dist/super-editor/docx-zipper.es.js +2 -2
  14. package/dist/super-editor/editor.es.js +3 -3
  15. package/dist/super-editor/file-zipper.es.js +1 -1
  16. package/dist/super-editor/src/core/super-converter/exporter.d.ts +2 -2
  17. package/dist/super-editor/src/core/super-converter/v2/importer/docxImporter.d.ts +2 -1
  18. package/dist/super-editor/src/core/super-converter/v2/importer/tableImporter.d.ts +17 -6
  19. package/dist/super-editor/src/core/super-converter/v2/importer/types/index.d.ts +4 -6
  20. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tc/helpers/legacy-handle-table-cell-node.d.ts +9 -0
  21. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tc/helpers/translate-table-cell.d.ts +17 -0
  22. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tc/index.d.ts +1 -0
  23. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tc/tc-translator.d.ts +6 -0
  24. package/dist/super-editor/super-editor.es.js +6 -6
  25. package/dist/super-editor/toolbar.es.js +2 -2
  26. package/dist/super-editor.cjs +1 -1
  27. package/dist/super-editor.es.js +1 -1
  28. package/dist/superdoc.cjs +2 -2
  29. package/dist/superdoc.es.js +2 -2
  30. package/dist/superdoc.umd.js +621 -496
  31. package/dist/superdoc.umd.js.map +1 -1
  32. package/package.json +1 -1
@@ -19658,7 +19658,11 @@ function handleListNodes(params, node2) {
19658
19658
  }
19659
19659
  const styleIdIndex = pPr?.elements?.findIndex((el) => el.name === "w:pStyle");
19660
19660
  if (styleIdIndex >= 0) pPr?.elements?.splice(styleIdIndex, 1);
19661
- const fallBack = nodeListHandler2.handler({ ...params, nodes: [node2] })?.filter((n) => n);
19661
+ const fallBack = nodeListHandler2.handler({
19662
+ ...params,
19663
+ nodes: [node2],
19664
+ path: [...params.path || [], node2]
19665
+ })?.filter((n) => n);
19662
19666
  return fallBack[0];
19663
19667
  }
19664
19668
  if (!lists[currentListNumId]) lists[currentListNumId] = { levels: {} };
@@ -19686,7 +19690,11 @@ function handleListNodes(params, node2) {
19686
19690
  const nodePpr = node2.attrs?.paragraphProperties?.elements?.find((el) => el.name === "w:pPr");
19687
19691
  const numPrIndex = node2.attrs?.paragraphProperties?.elements?.findIndex((el) => el.name === "w:numPr");
19688
19692
  nodePpr?.elements?.splice(numPrIndex, 1);
19689
- const listContents = nodeListHandler2.handler({ ...params, nodes: [node2] });
19693
+ const listContents = nodeListHandler2.handler({
19694
+ ...params,
19695
+ nodes: [node2],
19696
+ path: [...params.path || [], node2]
19697
+ });
19690
19698
  const innerParagraph = listContents.find((el) => el.type === "paragraph");
19691
19699
  const firstElement = innerParagraph.content[0];
19692
19700
  firstElement?.marks?.find((mark) => mark.type === "textStyle");
@@ -25540,13 +25548,13 @@ const wClearDecoder = (attrs) => {
25540
25548
  const { clear } = attrs;
25541
25549
  return clear;
25542
25550
  };
25543
- const XML_NODE_NAME$1 = "w:br";
25544
- const SD_NODE_NAME$1 = "lineBreak";
25545
- const validXmlAttributes$1 = [
25551
+ const XML_NODE_NAME$2 = "w:br";
25552
+ const SD_NODE_NAME$2 = "lineBreak";
25553
+ const validXmlAttributes$2 = [
25546
25554
  { xmlName: "w:type", sdName: "lineBreakType", encode: lineBreakTypeEncoder, decode: lineBreakTypeDecoder },
25547
25555
  { xmlName: "w:clear", sdName: "clear", encode: wClearEncoder, decode: wClearDecoder }
25548
25556
  ];
25549
- const encode$1 = (_2, encodedAttrs) => {
25557
+ const encode$2 = (_2, encodedAttrs) => {
25550
25558
  const isPageBreak = encodedAttrs?.lineBreakType === "page";
25551
25559
  const translated = {
25552
25560
  type: isPageBreak ? "hardBreak" : "lineBreak"
@@ -25556,7 +25564,7 @@ const encode$1 = (_2, encodedAttrs) => {
25556
25564
  }
25557
25565
  return translated;
25558
25566
  };
25559
- const decode$1 = (params, decodedAttrs) => {
25567
+ const decode$2 = (params, decodedAttrs) => {
25560
25568
  const { node: node2 } = params;
25561
25569
  if (!node2) return;
25562
25570
  const wBreak = { name: "w:br" };
@@ -25573,15 +25581,15 @@ const decode$1 = (params, decodedAttrs) => {
25573
25581
  };
25574
25582
  return translated;
25575
25583
  };
25576
- const config$1 = {
25577
- xmlName: XML_NODE_NAME$1,
25578
- sdNodeOrKeyName: SD_NODE_NAME$1,
25584
+ const config$2 = {
25585
+ xmlName: XML_NODE_NAME$2,
25586
+ sdNodeOrKeyName: SD_NODE_NAME$2,
25579
25587
  type: NodeTranslator.translatorTypes.NODE,
25580
- encode: encode$1,
25581
- decode: decode$1,
25582
- attributes: validXmlAttributes$1
25588
+ encode: encode$2,
25589
+ decode: decode$2,
25590
+ attributes: validXmlAttributes$2
25583
25591
  };
25584
- const translator$1 = NodeTranslator.from(config$1);
25592
+ const translator$2 = NodeTranslator.from(config$2);
25585
25593
  const tabSizeEncoder = (attributes) => {
25586
25594
  return attributes["w:val"];
25587
25595
  };
@@ -25603,19 +25611,19 @@ const tabPositionDecoder = (attrs) => {
25603
25611
  const { pos } = attrs;
25604
25612
  return pos;
25605
25613
  };
25606
- const XML_NODE_NAME = "w:tab";
25607
- const SD_NODE_NAME = "tab";
25608
- const validXmlAttributes = [
25614
+ const XML_NODE_NAME$1 = "w:tab";
25615
+ const SD_NODE_NAME$1 = "tab";
25616
+ const validXmlAttributes$1 = [
25609
25617
  { xmlName: "w:val", sdName: "tabSize", encode: tabSizeEncoder, decode: tabSizeDecoder },
25610
25618
  { xmlName: "w:pos", sdName: "pos", encode: tabPositionEncoder, decode: tabPositionDecoder },
25611
25619
  { xmlName: "w:leader", sdName: "leader", encode: tabLeaderEncoder, decode: tabLeaderDecoder }
25612
25620
  ];
25613
- const encode = (_2, encodedAttrs = {}) => {
25621
+ const encode$1 = (_2, encodedAttrs = {}) => {
25614
25622
  const translated = { type: "tab" };
25615
25623
  if (encodedAttrs) translated.attrs = { ...encodedAttrs };
25616
25624
  return translated;
25617
25625
  };
25618
- const decode = (params, decodedAttrs = {}) => {
25626
+ const decode$1 = (params, decodedAttrs = {}) => {
25619
25627
  const { node: node2 } = params || {};
25620
25628
  if (!node2) return;
25621
25629
  const wTab = { name: "w:tab" };
@@ -25631,144 +25639,676 @@ const decode = (params, decodedAttrs = {}) => {
25631
25639
  }
25632
25640
  return translated;
25633
25641
  };
25634
- const config = {
25635
- xmlName: XML_NODE_NAME,
25636
- sdNodeOrKeyName: SD_NODE_NAME,
25642
+ const config$1 = {
25643
+ xmlName: XML_NODE_NAME$1,
25644
+ sdNodeOrKeyName: SD_NODE_NAME$1,
25637
25645
  type: NodeTranslator.translatorTypes.NODE,
25638
- encode,
25639
- decode,
25640
- attributes: validXmlAttributes
25646
+ encode: encode$1,
25647
+ decode: decode$1,
25648
+ attributes: validXmlAttributes$1
25641
25649
  };
25642
- const translator = NodeTranslator.from(config);
25643
- function exportSchemaToJson(params) {
25644
- const { type: type2 } = params.node || {};
25645
- const router = {
25646
- doc: translateDocumentNode,
25647
- body: translateBodyNode,
25648
- heading: translateHeadingNode,
25649
- paragraph: translateParagraphNode,
25650
- text: translateTextNode,
25651
- bulletList: translateList,
25652
- orderedList: translateList,
25653
- lineBreak: translator$1,
25654
- table: translateTable,
25655
- tableRow: translateTableRow,
25656
- tableCell: translateTableCell,
25657
- bookmarkStart: translateBookmarkStart,
25658
- fieldAnnotation: translateFieldAnnotation,
25659
- tab: translator,
25660
- image: translateImageNode,
25661
- hardBreak: translator$1,
25662
- commentRangeStart: () => translateCommentNode(params, "Start"),
25663
- commentRangeEnd: () => translateCommentNode(params, "End"),
25664
- commentReference: () => null,
25665
- shapeContainer: translateShapeContainer,
25666
- shapeTextbox: translateShapeTextbox,
25667
- contentBlock: translateContentBlock,
25668
- structuredContent: translateStructuredContent,
25669
- structuredContentBlock: translateStructuredContent,
25670
- documentSection: translateDocumentSection,
25671
- "page-number": translatePageNumberNode,
25672
- "total-page-number": translateTotalPageNumberNode
25673
- };
25674
- let handler2 = router[type2];
25675
- if (handler2 && "decode" in handler2 && typeof handler2.decode === "function") {
25676
- return handler2.decode(params);
25650
+ const translator$1 = NodeTranslator.from(config$1);
25651
+ const handleAllTableNodes = (params) => {
25652
+ const { nodes } = params;
25653
+ if (nodes.length === 0) {
25654
+ return { nodes: [], consumed: 0 };
25677
25655
  }
25678
- if (!handler2) {
25679
- console.error("No translation function found for node type:", type2);
25680
- return null;
25656
+ const node2 = nodes[0];
25657
+ switch (node2.name) {
25658
+ case "w:tbl":
25659
+ return { nodes: [handleTableNode(node2, params)], consumed: 1 };
25681
25660
  }
25682
- return handler2(params);
25683
- }
25684
- function translateBodyNode(params) {
25685
- let sectPr = params.bodyNode?.elements.find((n) => n.name === "w:sectPr") || {};
25686
- if (params.converter) {
25687
- const hasHeader = sectPr?.elements?.some((n) => n.name === "w:headerReference");
25688
- const hasDefaultHeader = params.converter.headerIds?.default;
25689
- if (!hasHeader && hasDefaultHeader && !params.editor.options.isHeaderOrFooter) {
25690
- const defaultHeader = generateDefaultHeaderFooter("header", params.converter.headerIds?.default);
25691
- sectPr.elements.push(defaultHeader);
25692
- }
25693
- const hasFooter = sectPr?.elements?.some((n) => n.name === "w:footerReference");
25694
- const hasDefaultFooter = params.converter.footerIds?.default;
25695
- if (!hasFooter && hasDefaultFooter && !params.editor.options.isHeaderOrFooter) {
25696
- const defaultFooter = generateDefaultHeaderFooter("footer", params.converter.footerIds?.default);
25697
- sectPr.elements.push(defaultFooter);
25698
- }
25699
- const newMargins = params.converter.pageStyles.pageMargins;
25700
- const sectPrMargins = sectPr.elements.find((n) => n.name === "w:pgMar");
25701
- const { attributes } = sectPrMargins;
25702
- Object.entries(newMargins).forEach(([key, value]) => {
25703
- const convertedValue = inchesToTwips(value);
25704
- attributes[`w:${key}`] = convertedValue;
25705
- });
25706
- sectPrMargins.attributes = attributes;
25661
+ return { nodes: [], consumed: 0 };
25662
+ };
25663
+ const tableNodeHandlerEntity = {
25664
+ handlerName: "tableNodeHandler",
25665
+ handler: handleAllTableNodes
25666
+ };
25667
+ function handleTableNode(node2, params) {
25668
+ const { docx, nodeListHandler: nodeListHandler2 } = params;
25669
+ const tblPr = node2.elements.find((el) => el.name === "w:tblPr");
25670
+ const tableBordersElement = tblPr.elements.find((el) => el.name === "w:tblBorders");
25671
+ const tableBorders = tableBordersElement?.elements || [];
25672
+ const { borders, rowBorders } = processTableBorders(tableBorders);
25673
+ const tblStyleTag = tblPr.elements.find((el) => el.name === "w:tblStyle");
25674
+ const tableStyleId = tblStyleTag?.attributes["w:val"];
25675
+ const attrs = { tableStyleId };
25676
+ const tableIndent = tblPr?.elements.find((el) => el.name === "w:tblInd");
25677
+ if (tableIndent) {
25678
+ const { "w:w": width, "w:type": type2 } = tableIndent.attributes;
25679
+ attrs["tableIndent"] = { width: twipsToPixels(width), type: type2 };
25707
25680
  }
25708
- const elements = translateChildNodes(params);
25709
- if (params.isHeaderFooter) {
25710
- return {
25711
- name: "w:body",
25712
- elements: [...elements]
25681
+ const tableLayout = tblPr?.elements.find((el) => el.name === "w:tblLayout");
25682
+ if (tableLayout) {
25683
+ const { "w:type": type2 } = tableLayout.attributes;
25684
+ attrs["tableLayout"] = type2;
25685
+ }
25686
+ const referencedStyles = getReferencedTableStyles(tblStyleTag, docx);
25687
+ const tblW = tblPr.elements.find((el) => el.name === "w:tblW");
25688
+ if (tblW) {
25689
+ attrs["tableWidth"] = {
25690
+ width: twipsToPixels(tblW.attributes["w:w"]),
25691
+ type: tblW.attributes["w:type"]
25692
+ };
25693
+ }
25694
+ const tblCellSpacing = tblPr.elements.find((el) => el.name === "w:tblCellSpacing");
25695
+ if (tblCellSpacing) {
25696
+ attrs["tableCellSpacing"] = {
25697
+ w: tblCellSpacing.attributes["w:w"],
25698
+ type: tblCellSpacing.attributes["w:type"]
25713
25699
  };
25700
+ attrs["borderCollapse"] = "separate";
25701
+ }
25702
+ const tblJustification = tblPr.elements.find((el) => el.name === "w:jc");
25703
+ if (tblJustification?.attributes) {
25704
+ attrs["justification"] = tblJustification.attributes["w:val"];
25714
25705
  }
25706
+ const rows = node2.elements.filter((el) => el.name === "w:tr");
25707
+ const refStylesBorders = referencedStyles?.borders || {};
25708
+ const refStylesRowBorders = referencedStyles?.rowBorders || {};
25709
+ const borderData = Object.keys(borders)?.length ? Object.assign(refStylesBorders, borders) : refStylesBorders;
25710
+ const borderRowData = Object.keys(rowBorders)?.length ? Object.assign(refStylesRowBorders, rowBorders) : refStylesRowBorders;
25711
+ attrs["borders"] = borderData;
25712
+ const content = [];
25713
+ rows.forEach((row) => {
25714
+ const result = handleTableRowNode(row, node2, borderRowData, tblStyleTag, params);
25715
+ if (result.content?.length) content.push(result);
25716
+ });
25715
25717
  return {
25716
- name: "w:body",
25717
- elements: [...elements, sectPr]
25718
+ type: "table",
25719
+ content,
25720
+ attrs
25718
25721
  };
25719
25722
  }
25720
- const generateDefaultHeaderFooter = (type2, id) => {
25721
- return {
25722
- type: "element",
25723
- name: `w:${type2}Reference`,
25724
- attributes: {
25725
- "w:type": "default",
25726
- "r:id": id
25727
- }
25728
- };
25729
- };
25730
- function translateHeadingNode(params) {
25731
- const { node: node2 } = params;
25732
- const { level = 1, ...otherAttrs } = node2.attrs;
25733
- const paragraphNode = {
25734
- type: "paragraph",
25735
- content: node2.content,
25736
- attrs: {
25737
- ...otherAttrs,
25738
- styleId: `Heading${level}`
25739
- // Maps to Heading1, Heading2, etc. in Word
25723
+ function handleTableCellNode$1({
25724
+ params,
25725
+ node: node2,
25726
+ table,
25727
+ row,
25728
+ rowBorders,
25729
+ styleTag,
25730
+ columnIndex,
25731
+ columnWidth = null
25732
+ }) {
25733
+ const translatorParams = {
25734
+ ...params,
25735
+ extraParams: {
25736
+ node: node2,
25737
+ table,
25738
+ row,
25739
+ rowBorders,
25740
+ styleTag,
25741
+ columnIndex,
25742
+ columnWidth
25740
25743
  }
25741
25744
  };
25742
- return translateParagraphNode({ ...params, node: paragraphNode });
25745
+ const schemaNode = translator.encode(translatorParams);
25746
+ return schemaNode;
25743
25747
  }
25744
- function translateParagraphNode(params) {
25745
- const elements = translateChildNodes(params);
25746
- const htmlAnnotationChild = elements.find((element) => element.name === "htmlAnnotation");
25747
- if (htmlAnnotationChild) {
25748
- return htmlAnnotationChild.elements;
25748
+ function getReferencedTableStyles(tblStyleTag, docx) {
25749
+ if (!tblStyleTag) return null;
25750
+ const stylesToReturn = {};
25751
+ const { attributes = {} } = tblStyleTag;
25752
+ const tableStyleReference = attributes["w:val"];
25753
+ if (!tableStyleReference) return null;
25754
+ const styles = docx["word/styles.xml"];
25755
+ const { elements } = styles.elements[0];
25756
+ const styleElements = elements.filter((el) => el.name === "w:style");
25757
+ const styleTag = styleElements.find((el) => el.attributes["w:styleId"] === tableStyleReference);
25758
+ if (!styleTag) return null;
25759
+ stylesToReturn.name = styleTag.elements.find((el) => el.name === "w:name");
25760
+ const basedOn = styleTag.elements.find((el) => el.name === "w:basedOn");
25761
+ let baseTblPr;
25762
+ if (basedOn?.attributes) {
25763
+ const baseStyles = styleElements.find((el) => el.attributes["w:styleId"] === basedOn.attributes["w:val"]);
25764
+ baseTblPr = baseStyles ? baseStyles.elements.find((el) => el.name === "w:tblPr") : {};
25749
25765
  }
25750
- const pPr = generateParagraphProperties(params.node);
25751
- if (pPr) elements.unshift(pPr);
25752
- let attributes = {};
25753
- if (params.node.attrs?.rsidRDefault) {
25754
- attributes["w:rsidRDefault"] = params.node.attrs.rsidRDefault;
25766
+ const pPr = styleTag.elements.find((el) => el.name === "w:pPr");
25767
+ if (pPr) {
25768
+ const justification = pPr.elements.find((el) => el.name === "w:jc");
25769
+ if (justification?.attributes) stylesToReturn.justification = justification.attributes["w:val"];
25755
25770
  }
25756
- const result = {
25757
- name: "w:p",
25758
- elements,
25759
- attributes
25760
- };
25761
- return result;
25762
- }
25763
- function normalizeLineHeight(value) {
25764
- if (typeof value === "string" && value.trim().endsWith("%")) {
25765
- const parsed2 = parseFloat(value);
25766
- return Number.isFinite(parsed2) ? parsed2 / 100 : null;
25771
+ const rPr = styleTag?.elements.find((el) => el.name === "w:rPr");
25772
+ if (rPr) {
25773
+ const fonts = rPr.elements.find((el) => el.name === "w:rFonts");
25774
+ if (fonts) {
25775
+ const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
25776
+ stylesToReturn.fonts = { ascii, hAnsi, cs };
25777
+ }
25778
+ const fontSize = rPr.elements.find((el) => el.name === "w:sz");
25779
+ if (fontSize?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize.attributes["w:val"]) + "pt";
25767
25780
  }
25768
- const parsed = parseFloat(value);
25769
- return Number.isFinite(parsed) ? parsed : null;
25781
+ const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
25782
+ if (tblPr && tblPr.elements) {
25783
+ if (baseTblPr && baseTblPr.elements) {
25784
+ tblPr.elements.push(...baseTblPr.elements);
25785
+ }
25786
+ const tableBorders = tblPr?.elements?.find((el) => el.name === "w:tblBorders");
25787
+ const { elements: borderElements = [] } = tableBorders || {};
25788
+ const { borders, rowBorders } = processTableBorders(borderElements);
25789
+ if (borders) stylesToReturn.borders = borders;
25790
+ if (rowBorders) stylesToReturn.rowBorders = rowBorders;
25791
+ const tableCellMargin = tblPr?.elements.find((el) => el.name === "w:tblCellMar");
25792
+ if (tableCellMargin) {
25793
+ const marginLeft = tableCellMargin.elements.find((el) => el.name === "w:left");
25794
+ const marginRight = tableCellMargin.elements.find((el) => el.name === "w:right");
25795
+ const marginTop = tableCellMargin.elements.find((el) => el.name === "w:top");
25796
+ const marginBottom = tableCellMargin.elements.find((el) => el.name === "w:bottom");
25797
+ stylesToReturn.cellMargins = {
25798
+ marginLeft: marginLeft?.attributes["w:w"],
25799
+ marginRight: marginRight?.attributes["w:w"],
25800
+ marginTop: marginTop?.attributes["w:w"],
25801
+ marginBottom: marginBottom?.attributes["w:w"]
25802
+ };
25803
+ }
25804
+ }
25805
+ return stylesToReturn;
25770
25806
  }
25771
- function generateParagraphProperties(node2) {
25807
+ function processTableBorders(borderElements) {
25808
+ const borders = {};
25809
+ const rowBorders = {};
25810
+ borderElements.forEach((borderElement) => {
25811
+ const { name } = borderElement;
25812
+ const borderName = name.split("w:")[1];
25813
+ const { attributes } = borderElement;
25814
+ const attrs = {};
25815
+ const color = attributes["w:color"];
25816
+ const size = attributes["w:sz"];
25817
+ if (color && color !== "auto") attrs["color"] = color.startsWith("#") ? color : `#${color}`;
25818
+ if (size && size !== "auto") attrs["size"] = eigthPointsToPixels(size);
25819
+ const rowBorderNames = ["insideH", "insideV"];
25820
+ if (rowBorderNames.includes(borderName)) rowBorders[borderName] = attrs;
25821
+ borders[borderName] = attrs;
25822
+ });
25823
+ return {
25824
+ borders,
25825
+ rowBorders
25826
+ };
25827
+ }
25828
+ function handleTableRowNode(node2, table, rowBorders, styleTag, params) {
25829
+ const attrs = {};
25830
+ const tPr = node2.elements.find((el) => el.name === "w:trPr");
25831
+ const rowHeightTag = tPr?.elements?.find((el) => el.name === "w:trHeight");
25832
+ const rowHeight = rowHeightTag?.attributes["w:val"];
25833
+ const cantSplitTag = tPr?.elements?.find((el) => el.name === "w:cantSplit");
25834
+ if (cantSplitTag) {
25835
+ attrs["cantSplit"] = true;
25836
+ }
25837
+ const borders = {};
25838
+ if (rowBorders?.insideH) borders["bottom"] = rowBorders.insideH;
25839
+ if (rowBorders?.insideV) borders["right"] = rowBorders.insideV;
25840
+ attrs["borders"] = borders;
25841
+ if (rowHeight) {
25842
+ attrs["rowHeight"] = twipsToPixels(rowHeight);
25843
+ }
25844
+ const gridColumnWidths = getGridColumnWidths(table);
25845
+ const cellNodes = node2.elements.filter((el) => el.name === "w:tc");
25846
+ let currentColumnIndex = 0;
25847
+ const content = cellNodes?.map((n) => {
25848
+ let colWidth = gridColumnWidths?.[currentColumnIndex] || null;
25849
+ const result = handleTableCellNode$1({
25850
+ params,
25851
+ node: n,
25852
+ table,
25853
+ row: node2,
25854
+ rowBorders: borders,
25855
+ styleTag,
25856
+ columnIndex: currentColumnIndex,
25857
+ columnWidth: colWidth
25858
+ });
25859
+ const tcPr = n.elements?.find((el) => el.name === "w:tcPr");
25860
+ const colspanTag = tcPr?.elements?.find((el) => el.name === "w:gridSpan");
25861
+ const colspan = parseInt(colspanTag?.attributes["w:val"] || 1, 10);
25862
+ currentColumnIndex += colspan;
25863
+ return result;
25864
+ }) || [];
25865
+ const newNode = {
25866
+ type: "tableRow",
25867
+ content,
25868
+ attrs
25869
+ };
25870
+ return newNode;
25871
+ }
25872
+ const getGridColumnWidths = (tableNode) => {
25873
+ const tblGrid = tableNode.elements.find((el) => el.name === "w:tblGrid");
25874
+ if (!tblGrid) return [];
25875
+ const columnWidths = tblGrid?.elements?.flatMap((el) => {
25876
+ if (el.name !== "w:gridCol") return [];
25877
+ return twipsToPixels(el.attributes["w:w"]);
25878
+ }) || [];
25879
+ return columnWidths;
25880
+ };
25881
+ function handleTableCellNode({
25882
+ params,
25883
+ node: node2,
25884
+ table,
25885
+ row,
25886
+ rowBorders,
25887
+ styleTag,
25888
+ columnIndex,
25889
+ columnWidth = null
25890
+ }) {
25891
+ const { docx, nodeListHandler: nodeListHandler2 } = params;
25892
+ const tcPr = node2.elements.find((el) => el.name === "w:tcPr");
25893
+ const borders = tcPr?.elements?.find((el) => el.name === "w:tcBorders");
25894
+ const inlineBorders = processInlineCellBorders(borders, rowBorders);
25895
+ const gridColumnWidths = getGridColumnWidths(table);
25896
+ const tcWidth = tcPr?.elements?.find((el) => el.name === "w:tcW");
25897
+ let width = tcWidth ? twipsToPixels(tcWidth.attributes["w:w"]) : null;
25898
+ const widthType = tcWidth?.attributes["w:type"];
25899
+ if (!width && columnWidth) width = columnWidth;
25900
+ const vMerge = getTableCellMergeTag(node2);
25901
+ const { attributes: vMergeAttrs } = vMerge || {};
25902
+ const backgroundColor = tcPr?.elements?.find((el) => el.name === "w:shd");
25903
+ const background = {
25904
+ color: backgroundColor?.attributes["w:fill"]
25905
+ };
25906
+ const colspanTag = tcPr?.elements?.find((el) => el.name === "w:gridSpan");
25907
+ const colspan = colspanTag?.attributes["w:val"];
25908
+ const marginTag = tcPr?.elements?.find((el) => el.name === "w:tcMar");
25909
+ const verticalAlignTag = tcPr?.elements?.find((el) => el.name === "w:vAlign");
25910
+ const verticalAlign = verticalAlignTag?.attributes["w:val"] || "top";
25911
+ const attributes = {};
25912
+ const referencedStyles = getReferencedTableStyles(styleTag, docx) || {};
25913
+ attributes.cellMargins = getTableCellMargins(marginTag, referencedStyles);
25914
+ const { fontSize, fonts = {} } = referencedStyles;
25915
+ const fontFamily = fonts["ascii"];
25916
+ if (width) {
25917
+ attributes["colwidth"] = [width];
25918
+ attributes["widthUnit"] = "px";
25919
+ const defaultColWidths = gridColumnWidths;
25920
+ const hasDefaultColWidths = gridColumnWidths && gridColumnWidths.length > 0;
25921
+ const colspanNum = parseInt(colspan || 1, 10);
25922
+ if (colspanNum && colspanNum > 1 && hasDefaultColWidths) {
25923
+ let colwidth = [];
25924
+ for (let i = 0; i < colspanNum; i++) {
25925
+ let colwidthValue = defaultColWidths[columnIndex + i];
25926
+ let defaultColwidth = 100;
25927
+ if (typeof colwidthValue !== "undefined") {
25928
+ colwidth.push(colwidthValue);
25929
+ } else {
25930
+ colwidth.push(defaultColwidth);
25931
+ }
25932
+ }
25933
+ if (colwidth.length) {
25934
+ attributes["colwidth"] = [...colwidth];
25935
+ }
25936
+ }
25937
+ }
25938
+ if (widthType) attributes["widthType"] = widthType;
25939
+ if (colspan) attributes["colspan"] = parseInt(colspan, 10);
25940
+ if (background) attributes["background"] = background;
25941
+ attributes["verticalAlign"] = verticalAlign;
25942
+ if (fontSize) attributes["fontSize"] = fontSize;
25943
+ if (fontFamily) attributes["fontFamily"] = fontFamily["ascii"];
25944
+ if (rowBorders) attributes["borders"] = { ...rowBorders };
25945
+ if (inlineBorders) attributes["borders"] = Object.assign(attributes["borders"] || {}, inlineBorders);
25946
+ if (vMergeAttrs && vMergeAttrs["w:val"] === "restart") {
25947
+ const rows = table.elements.filter((el) => el.name === "w:tr");
25948
+ const currentRowIndex = rows.findIndex((r) => r === row);
25949
+ const remainingRows = rows.slice(currentRowIndex + 1);
25950
+ const cellsInRow = row.elements.filter((el) => el.name === "w:tc");
25951
+ let cellIndex = cellsInRow.findIndex((el) => el === node2);
25952
+ let rowspan = 1;
25953
+ for (let remainingRow of remainingRows) {
25954
+ const firstCell = remainingRow.elements.findIndex((el) => el.name === "w:tc");
25955
+ const cellAtIndex = remainingRow.elements[firstCell + cellIndex];
25956
+ if (!cellAtIndex) break;
25957
+ const vMerge2 = getTableCellMergeTag(cellAtIndex);
25958
+ const { attributes: currentCellMergeAttrs } = vMerge2 || {};
25959
+ if (!vMerge2 && !currentCellMergeAttrs || currentCellMergeAttrs && currentCellMergeAttrs["w:val"] === "restart") {
25960
+ break;
25961
+ }
25962
+ rowspan++;
25963
+ remainingRow.elements.splice(firstCell + cellIndex, 1);
25964
+ }
25965
+ attributes["rowspan"] = rowspan;
25966
+ }
25967
+ return {
25968
+ type: "tableCell",
25969
+ content: nodeListHandler2.handler({
25970
+ ...params,
25971
+ nodes: node2.elements,
25972
+ path: [...params.path || [], node2]
25973
+ }),
25974
+ attrs: attributes
25975
+ };
25976
+ }
25977
+ const processInlineCellBorders = (borders, rowBorders) => {
25978
+ if (!borders) return null;
25979
+ const processedBorders = {};
25980
+ const inlineBorderBottom = processBorder(borders, "bottom", rowBorders);
25981
+ if (inlineBorderBottom) processedBorders["bottom"] = inlineBorderBottom;
25982
+ const inlineBorderTop = processBorder(borders, "top", rowBorders);
25983
+ if (inlineBorderTop) processedBorders["top"] = inlineBorderTop;
25984
+ const inlineBorderLeft = processBorder(borders, "left", rowBorders);
25985
+ if (inlineBorderLeft) processedBorders["left"] = inlineBorderLeft;
25986
+ const inlineBorderRight = processBorder(borders, "right", rowBorders);
25987
+ if (inlineBorderRight) processedBorders["right"] = inlineBorderRight;
25988
+ return processedBorders;
25989
+ };
25990
+ const processBorder = (borders, direction, rowBorders = {}) => {
25991
+ const borderAttrs = borders?.elements?.find((el) => el.name === `w:${direction}`)?.attributes;
25992
+ if (borderAttrs && borderAttrs["w:val"] !== "nil") {
25993
+ const border = {};
25994
+ const color = borderAttrs["w:color"];
25995
+ if (color) border["color"] = color === "auto" ? "#000000" : `#${color}`;
25996
+ const size = borderAttrs["w:sz"];
25997
+ if (size) border["size"] = eigthPointsToPixels(size);
25998
+ return border;
25999
+ }
26000
+ if (borderAttrs && borderAttrs["w:val"] === "nil") {
26001
+ const border = Object.assign({}, rowBorders[direction] || {});
26002
+ if (!Object.keys(border)) return null;
26003
+ border["val"] = "none";
26004
+ return border;
26005
+ }
26006
+ return null;
26007
+ };
26008
+ const getTableCellMergeTag = (node2) => {
26009
+ const tcPr = node2.elements.find((el) => el.name === "w:tcPr");
26010
+ const vMerge = tcPr?.elements?.find((el) => el.name === "w:vMerge");
26011
+ return vMerge;
26012
+ };
26013
+ const getTableCellMargins = (marginTag, referencedStyles) => {
26014
+ const inlineMarginLeftTag = marginTag?.elements?.find((el) => el.name === "w:left");
26015
+ const inlineMarginRightTag = marginTag?.elements?.find((el) => el.name === "w:right");
26016
+ const inlineMarginTopTag = marginTag?.elements?.find((el) => el.name === "w:top");
26017
+ const inlineMarginBottomTag = marginTag?.elements?.find((el) => el.name === "w:bottom");
26018
+ const inlineMarginLeftValue = inlineMarginLeftTag?.attributes["w:w"];
26019
+ const inlineMarginRightValue = inlineMarginRightTag?.attributes["w:w"];
26020
+ const inlineMarginTopValue = inlineMarginTopTag?.attributes["w:w"];
26021
+ const inlineMarginBottomValue = inlineMarginBottomTag?.attributes["w:w"];
26022
+ const { cellMargins = {} } = referencedStyles;
26023
+ const {
26024
+ marginLeft: marginLeftStyle,
26025
+ marginRight: marginRightStyle,
26026
+ marginTop: marginTopStyle,
26027
+ marginBottom: marginBottomStyle
26028
+ } = cellMargins;
26029
+ const margins = {
26030
+ left: twipsToPixels(inlineMarginLeftValue ?? marginLeftStyle),
26031
+ right: twipsToPixels(inlineMarginRightValue ?? marginRightStyle),
26032
+ top: twipsToPixels(inlineMarginTopValue ?? marginTopStyle),
26033
+ bottom: twipsToPixels(inlineMarginBottomValue ?? marginBottomStyle)
26034
+ };
26035
+ return margins;
26036
+ };
26037
+ function translateTableCell(params) {
26038
+ const elements = translateChildNodes({
26039
+ ...params,
26040
+ tableCell: params.node
26041
+ });
26042
+ const cellProps = generateTableCellProperties(params.node);
26043
+ elements.unshift(cellProps);
26044
+ return {
26045
+ name: "w:tc",
26046
+ elements
26047
+ };
26048
+ }
26049
+ function generateTableCellProperties(node2) {
26050
+ const elements = [];
26051
+ const { attrs } = node2;
26052
+ const { colwidth = [], cellWidthType = "dxa", background = {}, colspan, rowspan, widthUnit } = attrs;
26053
+ const colwidthSum = colwidth.reduce((acc, curr) => acc + curr, 0);
26054
+ const cellWidthElement = {
26055
+ name: "w:tcW",
26056
+ attributes: {
26057
+ "w:w": widthUnit === "px" ? pixelsToTwips(colwidthSum) : inchesToTwips(colwidthSum),
26058
+ "w:type": cellWidthType
26059
+ }
26060
+ };
26061
+ elements.push(cellWidthElement);
26062
+ if (colspan) {
26063
+ const gridSpanElement = {
26064
+ name: "w:gridSpan",
26065
+ attributes: { "w:val": `${colspan}` }
26066
+ };
26067
+ elements.push(gridSpanElement);
26068
+ }
26069
+ const { color } = background || {};
26070
+ if (color) {
26071
+ const cellBgElement = {
26072
+ name: "w:shd",
26073
+ attributes: { "w:fill": color }
26074
+ };
26075
+ elements.push(cellBgElement);
26076
+ }
26077
+ const { cellMargins } = attrs;
26078
+ if (cellMargins) {
26079
+ const cellMarginsElement = {
26080
+ name: "w:tcMar",
26081
+ elements: generateCellMargins(cellMargins)
26082
+ };
26083
+ elements.push(cellMarginsElement);
26084
+ }
26085
+ const { verticalAlign } = attrs;
26086
+ if (verticalAlign) {
26087
+ const vertAlignElement = {
26088
+ name: "w:vAlign",
26089
+ attributes: { "w:val": verticalAlign }
26090
+ };
26091
+ elements.push(vertAlignElement);
26092
+ }
26093
+ if (rowspan && rowspan > 1) {
26094
+ const vMergeElement = {
26095
+ name: "w:vMerge",
26096
+ type: "element",
26097
+ attributes: { "w:val": "restart" }
26098
+ };
26099
+ elements.push(vMergeElement);
26100
+ } else if (attrs.continueMerge) {
26101
+ const vMergeElement = {
26102
+ name: "w:vMerge",
26103
+ type: "element"
26104
+ };
26105
+ elements.push(vMergeElement);
26106
+ }
26107
+ const { borders = {} } = attrs;
26108
+ if (!!borders && Object.keys(borders).length) {
26109
+ const cellBordersElement = {
26110
+ name: "w:tcBorders",
26111
+ elements: Object.entries(borders).map(([key, value]) => {
26112
+ if (!value.size || value.val === "none") {
26113
+ return {
26114
+ name: `w:${key}`,
26115
+ attributes: {
26116
+ "w:val": "nil"
26117
+ }
26118
+ };
26119
+ }
26120
+ return {
26121
+ name: `w:${key}`,
26122
+ attributes: {
26123
+ "w:val": "single",
26124
+ "w:color": value.color ? value.color.substring(1) : "auto",
26125
+ "w:sz": pixelsToEightPoints(value.size),
26126
+ "w:space": value.space || 0
26127
+ }
26128
+ };
26129
+ })
26130
+ };
26131
+ elements.push(cellBordersElement);
26132
+ }
26133
+ return {
26134
+ name: "w:tcPr",
26135
+ elements
26136
+ };
26137
+ }
26138
+ function generateCellMargins(cellMargins) {
26139
+ const elements = [];
26140
+ const { top, right, bottom, left } = cellMargins;
26141
+ if (top != null) elements.push({ name: "w:top", attributes: { "w:w": pixelsToTwips(top) } });
26142
+ if (right != null) elements.push({ name: "w:right", attributes: { "w:w": pixelsToTwips(right) } });
26143
+ if (bottom != null) elements.push({ name: "w:bottom", attributes: { "w:w": pixelsToTwips(bottom) } });
26144
+ if (left != null) elements.push({ name: "w:left", attributes: { "w:w": pixelsToTwips(left) } });
26145
+ return elements;
26146
+ }
26147
+ const XML_NODE_NAME = "w:tc";
26148
+ const SD_NODE_NAME = "tableCell";
26149
+ const validXmlAttributes = [];
26150
+ function encode(params, encodedAttrs) {
26151
+ const { node: node2, table, row, rowBorders, styleTag, columnIndex, columnWidth } = params.extraParams;
26152
+ const schemaNode = handleTableCellNode({
26153
+ params,
26154
+ node: node2,
26155
+ table,
26156
+ row,
26157
+ rowBorders,
26158
+ styleTag,
26159
+ columnIndex,
26160
+ columnWidth
26161
+ });
26162
+ if (encodedAttrs && Object.keys(encodedAttrs).length) {
26163
+ schemaNode.attrs = { ...schemaNode.attrs, ...encodedAttrs };
26164
+ }
26165
+ return schemaNode;
26166
+ }
26167
+ function decode(params, decodedAttrs) {
26168
+ const translated = translateTableCell(params);
26169
+ if (decodedAttrs && Object.keys(decodedAttrs).length) {
26170
+ translated.attributes = { ...translated.attributes || {}, ...decodedAttrs };
26171
+ }
26172
+ return translated;
26173
+ }
26174
+ const config = {
26175
+ xmlName: XML_NODE_NAME,
26176
+ sdNodeOrKeyName: SD_NODE_NAME,
26177
+ type: NodeTranslator.translatorTypes.NODE,
26178
+ encode,
26179
+ decode,
26180
+ attributes: validXmlAttributes
26181
+ };
26182
+ const translator = NodeTranslator.from(config);
26183
+ function exportSchemaToJson(params) {
26184
+ const { type: type2 } = params.node || {};
26185
+ const router = {
26186
+ doc: translateDocumentNode,
26187
+ body: translateBodyNode,
26188
+ heading: translateHeadingNode,
26189
+ paragraph: translateParagraphNode,
26190
+ text: translateTextNode,
26191
+ bulletList: translateList,
26192
+ orderedList: translateList,
26193
+ lineBreak: translator$2,
26194
+ table: translateTable,
26195
+ tableRow: translateTableRow,
26196
+ tableCell: translator,
26197
+ bookmarkStart: translateBookmarkStart,
26198
+ fieldAnnotation: translateFieldAnnotation,
26199
+ tab: translator$1,
26200
+ image: translateImageNode,
26201
+ hardBreak: translator$2,
26202
+ commentRangeStart: () => translateCommentNode(params, "Start"),
26203
+ commentRangeEnd: () => translateCommentNode(params, "End"),
26204
+ commentReference: () => null,
26205
+ shapeContainer: translateShapeContainer,
26206
+ shapeTextbox: translateShapeTextbox,
26207
+ contentBlock: translateContentBlock,
26208
+ structuredContent: translateStructuredContent,
26209
+ structuredContentBlock: translateStructuredContent,
26210
+ documentSection: translateDocumentSection,
26211
+ "page-number": translatePageNumberNode,
26212
+ "total-page-number": translateTotalPageNumberNode
26213
+ };
26214
+ let handler2 = router[type2];
26215
+ if (handler2 && "decode" in handler2 && typeof handler2.decode === "function") {
26216
+ return handler2.decode(params);
26217
+ }
26218
+ if (!handler2) {
26219
+ console.error("No translation function found for node type:", type2);
26220
+ return null;
26221
+ }
26222
+ return handler2(params);
26223
+ }
26224
+ function translateBodyNode(params) {
26225
+ let sectPr = params.bodyNode?.elements.find((n) => n.name === "w:sectPr") || {};
26226
+ if (params.converter) {
26227
+ const hasHeader = sectPr?.elements?.some((n) => n.name === "w:headerReference");
26228
+ const hasDefaultHeader = params.converter.headerIds?.default;
26229
+ if (!hasHeader && hasDefaultHeader && !params.editor.options.isHeaderOrFooter) {
26230
+ const defaultHeader = generateDefaultHeaderFooter("header", params.converter.headerIds?.default);
26231
+ sectPr.elements.push(defaultHeader);
26232
+ }
26233
+ const hasFooter = sectPr?.elements?.some((n) => n.name === "w:footerReference");
26234
+ const hasDefaultFooter = params.converter.footerIds?.default;
26235
+ if (!hasFooter && hasDefaultFooter && !params.editor.options.isHeaderOrFooter) {
26236
+ const defaultFooter = generateDefaultHeaderFooter("footer", params.converter.footerIds?.default);
26237
+ sectPr.elements.push(defaultFooter);
26238
+ }
26239
+ const newMargins = params.converter.pageStyles.pageMargins;
26240
+ const sectPrMargins = sectPr.elements.find((n) => n.name === "w:pgMar");
26241
+ const { attributes } = sectPrMargins;
26242
+ Object.entries(newMargins).forEach(([key, value]) => {
26243
+ const convertedValue = inchesToTwips(value);
26244
+ attributes[`w:${key}`] = convertedValue;
26245
+ });
26246
+ sectPrMargins.attributes = attributes;
26247
+ }
26248
+ const elements = translateChildNodes(params);
26249
+ if (params.isHeaderFooter) {
26250
+ return {
26251
+ name: "w:body",
26252
+ elements: [...elements]
26253
+ };
26254
+ }
26255
+ return {
26256
+ name: "w:body",
26257
+ elements: [...elements, sectPr]
26258
+ };
26259
+ }
26260
+ const generateDefaultHeaderFooter = (type2, id) => {
26261
+ return {
26262
+ type: "element",
26263
+ name: `w:${type2}Reference`,
26264
+ attributes: {
26265
+ "w:type": "default",
26266
+ "r:id": id
26267
+ }
26268
+ };
26269
+ };
26270
+ function translateHeadingNode(params) {
26271
+ const { node: node2 } = params;
26272
+ const { level = 1, ...otherAttrs } = node2.attrs;
26273
+ const paragraphNode = {
26274
+ type: "paragraph",
26275
+ content: node2.content,
26276
+ attrs: {
26277
+ ...otherAttrs,
26278
+ styleId: `Heading${level}`
26279
+ // Maps to Heading1, Heading2, etc. in Word
26280
+ }
26281
+ };
26282
+ return translateParagraphNode({ ...params, node: paragraphNode });
26283
+ }
26284
+ function translateParagraphNode(params) {
26285
+ const elements = translateChildNodes(params);
26286
+ const htmlAnnotationChild = elements.find((element) => element.name === "htmlAnnotation");
26287
+ if (htmlAnnotationChild) {
26288
+ return htmlAnnotationChild.elements;
26289
+ }
26290
+ const pPr = generateParagraphProperties(params.node);
26291
+ if (pPr) elements.unshift(pPr);
26292
+ let attributes = {};
26293
+ if (params.node.attrs?.rsidRDefault) {
26294
+ attributes["w:rsidRDefault"] = params.node.attrs.rsidRDefault;
26295
+ }
26296
+ const result = {
26297
+ name: "w:p",
26298
+ elements,
26299
+ attributes
26300
+ };
26301
+ return result;
26302
+ }
26303
+ function normalizeLineHeight(value) {
26304
+ if (typeof value === "string" && value.trim().endsWith("%")) {
26305
+ const parsed2 = parseFloat(value);
26306
+ return Number.isFinite(parsed2) ? parsed2 / 100 : null;
26307
+ }
26308
+ const parsed = parseFloat(value);
26309
+ return Number.isFinite(parsed) ? parsed : null;
26310
+ }
26311
+ function generateParagraphProperties(node2) {
25772
26312
  const { attrs = {} } = node2;
25773
26313
  const pPrElements = [];
25774
26314
  const { styleId } = attrs;
@@ -26472,133 +27012,23 @@ function generateTableRowProperties(node2) {
26472
27012
  const { attrs } = node2;
26473
27013
  const elements = [];
26474
27014
  const { rowHeight, rowHeightType } = attrs;
26475
- if (rowHeight) {
26476
- const attributes = { "w:val": pixelsToTwips(rowHeight) };
26477
- if (rowHeightType) attributes["w:hRule"] = rowHeightType;
26478
- const rowHeightElement = {
26479
- name: "w:trHeight",
26480
- attributes
26481
- };
26482
- elements.push(rowHeightElement);
26483
- }
26484
- if (attrs?.cantSplit) {
26485
- elements.push({ name: "w:cantSplit" });
26486
- }
26487
- return {
26488
- name: "w:trPr",
26489
- elements
26490
- };
26491
- }
26492
- function translateTableCell(params) {
26493
- const elements = translateChildNodes({
26494
- ...params,
26495
- tableCell: params.node
26496
- });
26497
- const cellProps = generateTableCellProperties(params.node);
26498
- elements.unshift(cellProps);
26499
- return {
26500
- name: "w:tc",
26501
- elements
26502
- };
26503
- }
26504
- function generateTableCellProperties(node2) {
26505
- const elements = [];
26506
- const { attrs } = node2;
26507
- const { colwidth = [], cellWidthType = "dxa", background = {}, colspan, rowspan, widthUnit } = attrs;
26508
- const colwidthSum = colwidth.reduce((acc, curr) => acc + curr, 0);
26509
- const cellWidthElement = {
26510
- name: "w:tcW",
26511
- attributes: {
26512
- "w:w": widthUnit === "px" ? pixelsToTwips(colwidthSum) : inchesToTwips(colwidthSum),
26513
- "w:type": cellWidthType
26514
- }
26515
- };
26516
- elements.push(cellWidthElement);
26517
- if (colspan) {
26518
- const gridSpanElement = {
26519
- name: "w:gridSpan",
26520
- attributes: { "w:val": `${colspan}` }
26521
- };
26522
- elements.push(gridSpanElement);
26523
- }
26524
- const { color } = background || {};
26525
- if (color) {
26526
- const cellBgElement = {
26527
- name: "w:shd",
26528
- attributes: { "w:fill": color }
26529
- };
26530
- elements.push(cellBgElement);
26531
- }
26532
- const { cellMargins } = attrs;
26533
- if (cellMargins) {
26534
- const cellMarginsElement = {
26535
- name: "w:tcMar",
26536
- elements: generateCellMargins(cellMargins)
26537
- };
26538
- elements.push(cellMarginsElement);
26539
- }
26540
- const { verticalAlign } = attrs;
26541
- if (verticalAlign) {
26542
- const vertAlignElement = {
26543
- name: "w:vAlign",
26544
- attributes: { "w:val": verticalAlign }
26545
- };
26546
- elements.push(vertAlignElement);
26547
- }
26548
- if (rowspan && rowspan > 1) {
26549
- const vMergeElement = {
26550
- name: "w:vMerge",
26551
- type: "element",
26552
- attributes: { "w:val": "restart" }
26553
- };
26554
- elements.push(vMergeElement);
26555
- } else if (attrs.continueMerge) {
26556
- const vMergeElement = {
26557
- name: "w:vMerge",
26558
- type: "element"
26559
- };
26560
- elements.push(vMergeElement);
26561
- }
26562
- const { borders = {} } = attrs;
26563
- if (!!borders && Object.keys(borders).length) {
26564
- const cellBordersElement = {
26565
- name: "w:tcBorders",
26566
- elements: Object.entries(borders).map(([key, value]) => {
26567
- if (!value.size || value.val === "none") {
26568
- return {
26569
- name: `w:${key}`,
26570
- attributes: {
26571
- "w:val": "nil"
26572
- }
26573
- };
26574
- }
26575
- return {
26576
- name: `w:${key}`,
26577
- attributes: {
26578
- "w:val": "single",
26579
- "w:color": value.color ? value.color.substring(1) : "auto",
26580
- "w:sz": pixelsToEightPoints(value.size),
26581
- "w:space": value.space || 0
26582
- }
26583
- };
26584
- })
27015
+ if (rowHeight) {
27016
+ const attributes = { "w:val": pixelsToTwips(rowHeight) };
27017
+ if (rowHeightType) attributes["w:hRule"] = rowHeightType;
27018
+ const rowHeightElement = {
27019
+ name: "w:trHeight",
27020
+ attributes
26585
27021
  };
26586
- elements.push(cellBordersElement);
27022
+ elements.push(rowHeightElement);
27023
+ }
27024
+ if (attrs?.cantSplit) {
27025
+ elements.push({ name: "w:cantSplit" });
26587
27026
  }
26588
27027
  return {
26589
- name: "w:tcPr",
27028
+ name: "w:trPr",
26590
27029
  elements
26591
27030
  };
26592
27031
  }
26593
- function generateCellMargins(cellMargins) {
26594
- const elements = [];
26595
- const { top, right, bottom, left } = cellMargins;
26596
- if (top != null) elements.push({ name: "w:top", attributes: { "w:w": pixelsToTwips(top) } });
26597
- if (right != null) elements.push({ name: "w:right", attributes: { "w:w": pixelsToTwips(right) } });
26598
- if (bottom != null) elements.push({ name: "w:bottom", attributes: { "w:w": pixelsToTwips(bottom) } });
26599
- if (left != null) elements.push({ name: "w:left", attributes: { "w:w": pixelsToTwips(left) } });
26600
- return elements;
26601
- }
26602
27032
  function translateBookmarkStart(params) {
26603
27033
  const bookmarkStartNode = {
26604
27034
  name: "w:bookmarkStart",
@@ -27043,848 +27473,509 @@ function prepareHtmlAnnotation(params) {
27043
27473
  doc: DOMParser$1.fromSchema(editorSchema).parse(paragraphHtmlContainer)
27044
27474
  });
27045
27475
  if (allMarks.length) {
27046
- state2 = applyMarksToHtmlAnnotation(state2, allMarks);
27047
- }
27048
- const htmlAnnotationNode = state2.doc.toJSON();
27049
- const listTypes = ["bulletList", "orderedList"];
27050
- const { editor } = params;
27051
- const seenLists = /* @__PURE__ */ new Map();
27052
- state2.doc.descendants((node2) => {
27053
- if (listTypes.includes(node2.type.name)) {
27054
- const listItem = node2.firstChild;
27055
- const { attrs: attrs2 } = listItem;
27056
- const { level, numId } = attrs2;
27057
- if (!seenLists.has(numId)) {
27058
- const newNumId = ListHelpers.changeNumIdSameAbstract(numId, level, node2.type.name, editor);
27059
- listItem.attrs.numId = newNumId;
27060
- seenLists.set(numId, newNumId);
27061
- } else {
27062
- const newNumId = seenLists.get(numId);
27063
- listItem.attrs.numId = newNumId;
27064
- }
27065
- }
27066
- });
27067
- const elements = translateChildNodes({
27068
- ...params,
27069
- node: htmlAnnotationNode
27070
- });
27071
- return {
27072
- name: "htmlAnnotation",
27073
- elements
27074
- };
27075
- }
27076
- function prepareImageAnnotation(params, imageSize) {
27077
- return translateImageNode(params, imageSize);
27078
- }
27079
- function prepareUrlAnnotation(params) {
27080
- const {
27081
- node: { attrs = {}, marks = [] }
27082
- } = params;
27083
- const newId = addNewLinkRelationship(params, attrs.linkUrl);
27084
- const linkTextNode = getTextNodeForExport(attrs.linkUrl, marks, params);
27085
- const contentNode = processLinkContentNode(linkTextNode);
27086
- return {
27087
- name: "w:hyperlink",
27088
- type: "element",
27089
- attributes: {
27090
- "r:id": newId,
27091
- "w:history": 1
27092
- },
27093
- elements: [contentNode]
27094
- };
27095
- }
27096
- function getTranslationByAnnotationType(annotationType, annotationFieldType) {
27097
- if (annotationType === "text" && annotationFieldType === "FILEUPLOADER") {
27098
- return null;
27099
- }
27100
- const imageEmuSize = {
27101
- w: 4286250,
27102
- h: 4286250
27103
- };
27104
- const signatureEmuSize = {
27105
- w: 99e4,
27106
- h: 495e3
27107
- };
27108
- const dictionary = {
27109
- text: prepareTextAnnotation,
27110
- image: (params) => prepareImageAnnotation(params, imageEmuSize),
27111
- signature: (params) => prepareImageAnnotation(params, signatureEmuSize),
27112
- checkbox: prepareCheckboxAnnotation,
27113
- html: prepareHtmlAnnotation,
27114
- link: prepareUrlAnnotation
27115
- };
27116
- return dictionary[annotationType];
27117
- }
27118
- const translateFieldAttrsToMarks = (attrs = {}) => {
27119
- const { fontFamily, fontSize, bold, underline, italic, textColor, textHighlight } = attrs;
27120
- const marks = [];
27121
- if (fontFamily) marks.push({ type: "fontFamily", attrs: { fontFamily } });
27122
- if (fontSize) marks.push({ type: "fontSize", attrs: { fontSize } });
27123
- if (bold) marks.push({ type: "bold", attrs: {} });
27124
- if (underline) marks.push({ type: "underline", attrs: {} });
27125
- if (italic) marks.push({ type: "italic", attrs: {} });
27126
- if (textColor) marks.push({ type: "color", attrs: { color: textColor } });
27127
- if (textHighlight) marks.push({ type: "highlight", attrs: { color: textHighlight } });
27128
- return marks;
27129
- };
27130
- function translateFieldAnnotation(params) {
27131
- const { node: node2, isFinalDoc, fieldsHighlightColor } = params;
27132
- const { attrs = {} } = node2;
27133
- const annotationHandler = getTranslationByAnnotationType(attrs.type, attrs.fieldType);
27134
- if (!annotationHandler) return {};
27135
- let processedNode;
27136
- let sdtContentElements;
27137
- if ((attrs.type === "image" || attrs.type === "signature") && !attrs.hash) {
27138
- attrs.hash = generateDocxRandomId(4);
27139
- }
27140
- if (isFinalDoc) {
27141
- return annotationHandler(params);
27142
- } else {
27143
- processedNode = annotationHandler(params);
27144
- sdtContentElements = [processedNode];
27145
- if (attrs.type === "html") {
27146
- sdtContentElements = [...processedNode.elements];
27147
- }
27148
- }
27149
- sdtContentElements = [...sdtContentElements];
27150
- const fieldBackgroundTag = getFieldHighlightJson(fieldsHighlightColor);
27151
- if (fieldBackgroundTag) {
27152
- sdtContentElements.unshift(fieldBackgroundTag);
27153
- }
27154
- const annotationAttrs = {
27155
- displayLabel: attrs.displayLabel,
27156
- defaultDisplayLabel: attrs.defaultDisplayLabel,
27157
- fieldId: attrs.fieldId,
27158
- fieldType: attrs.fieldType,
27159
- fieldTypeShort: attrs.type,
27160
- fieldColor: attrs.fieldColor,
27161
- fieldMultipleImage: attrs.multipleImage,
27162
- fieldFontFamily: attrs.fontFamily,
27163
- fieldFontSize: attrs.fontSize,
27164
- fieldTextColor: attrs.textColor,
27165
- fieldTextHighlight: attrs.textHighlight,
27166
- hash: attrs.hash
27167
- };
27168
- const annotationAttrsJson = JSON.stringify(annotationAttrs);
27169
- const result = {
27170
- name: "w:sdt",
27171
- elements: [
27172
- {
27173
- name: "w:sdtPr",
27174
- elements: [
27175
- { name: "w:tag", attributes: { "w:val": annotationAttrsJson } },
27176
- { name: "w:alias", attributes: { "w:val": attrs.displayLabel } }
27177
- ]
27178
- },
27179
- {
27180
- name: "w:sdtContent",
27181
- elements: sdtContentElements
27182
- }
27183
- ]
27184
- };
27185
- return result;
27186
- }
27187
- function translateShapeContainer(params) {
27188
- const { node: node2 } = params;
27189
- const elements = translateChildNodes(params);
27190
- const shape = {
27191
- name: "v:shape",
27192
- attributes: {
27193
- ...node2.attrs.attributes,
27194
- fillcolor: node2.attrs.fillcolor
27195
- },
27196
- elements: [
27197
- ...elements,
27198
- ...node2.attrs.wrapAttributes ? [
27199
- {
27200
- name: "w10:wrap",
27201
- attributes: { ...node2.attrs.wrapAttributes }
27202
- }
27203
- ] : []
27204
- ]
27205
- };
27206
- const pict = {
27207
- name: "w:pict",
27208
- attributes: {
27209
- "w14:anchorId": Math.floor(Math.random() * 4294967295).toString()
27210
- },
27211
- elements: [shape]
27212
- };
27213
- const par = {
27214
- name: "w:p",
27215
- elements: [wrapTextInRun(pict)]
27216
- };
27217
- return par;
27218
- }
27219
- function translateShapeTextbox(params) {
27220
- const { node: node2 } = params;
27221
- const elements = translateChildNodes(params);
27222
- const textboxContent = {
27223
- name: "w:txbxContent",
27224
- elements
27225
- };
27226
- const textbox = {
27227
- name: "v:textbox",
27228
- attributes: {
27229
- ...node2.attrs.attributes
27230
- },
27231
- elements: [textboxContent]
27232
- };
27233
- return textbox;
27234
- }
27235
- function translateContentBlock(params) {
27236
- const { node: node2 } = params;
27237
- const { drawingContent, vmlAttributes, horizontalRule } = node2.attrs;
27238
- if (vmlAttributes || horizontalRule) {
27239
- return translateVRectContentBlock(params);
27240
- }
27241
- const drawing = {
27242
- name: "w:drawing",
27243
- elements: [...drawingContent ? [...drawingContent.elements || []] : []]
27244
- };
27245
- const choice = {
27246
- name: "mc:Choice",
27247
- attributes: { Requires: "wps" },
27248
- elements: [drawing]
27249
- };
27250
- const alternateContent = {
27251
- name: "mc:AlternateContent",
27252
- elements: [choice]
27253
- };
27254
- return wrapTextInRun(alternateContent);
27255
- }
27256
- function translateVRectContentBlock(params) {
27257
- const { node: node2 } = params;
27258
- const { vmlAttributes, background, attributes, style } = node2.attrs;
27259
- const rectAttrs = {
27260
- id: attributes?.id || `_x0000_i${Math.floor(Math.random() * 1e4)}`
27261
- };
27262
- if (style) {
27263
- rectAttrs.style = style;
27264
- }
27265
- if (background) {
27266
- rectAttrs.fillcolor = background;
27267
- }
27268
- if (vmlAttributes) {
27269
- if (vmlAttributes.hralign) rectAttrs["o:hralign"] = vmlAttributes.hralign;
27270
- if (vmlAttributes.hrstd) rectAttrs["o:hrstd"] = vmlAttributes.hrstd;
27271
- if (vmlAttributes.hr) rectAttrs["o:hr"] = vmlAttributes.hr;
27272
- if (vmlAttributes.stroked) rectAttrs.stroked = vmlAttributes.stroked;
27273
- }
27274
- if (attributes) {
27275
- Object.entries(attributes).forEach(([key, value]) => {
27276
- if (!rectAttrs[key] && value !== void 0) {
27277
- rectAttrs[key] = value;
27278
- }
27279
- });
27476
+ state2 = applyMarksToHtmlAnnotation(state2, allMarks);
27280
27477
  }
27281
- const rect = {
27282
- name: "v:rect",
27283
- attributes: rectAttrs
27478
+ const htmlAnnotationNode = state2.doc.toJSON();
27479
+ const listTypes = ["bulletList", "orderedList"];
27480
+ const { editor } = params;
27481
+ const seenLists = /* @__PURE__ */ new Map();
27482
+ state2.doc.descendants((node2) => {
27483
+ if (listTypes.includes(node2.type.name)) {
27484
+ const listItem = node2.firstChild;
27485
+ const { attrs: attrs2 } = listItem;
27486
+ const { level, numId } = attrs2;
27487
+ if (!seenLists.has(numId)) {
27488
+ const newNumId = ListHelpers.changeNumIdSameAbstract(numId, level, node2.type.name, editor);
27489
+ listItem.attrs.numId = newNumId;
27490
+ seenLists.set(numId, newNumId);
27491
+ } else {
27492
+ const newNumId = seenLists.get(numId);
27493
+ listItem.attrs.numId = newNumId;
27494
+ }
27495
+ }
27496
+ });
27497
+ const elements = translateChildNodes({
27498
+ ...params,
27499
+ node: htmlAnnotationNode
27500
+ });
27501
+ return {
27502
+ name: "htmlAnnotation",
27503
+ elements
27284
27504
  };
27285
- const pict = {
27286
- name: "w:pict",
27505
+ }
27506
+ function prepareImageAnnotation(params, imageSize) {
27507
+ return translateImageNode(params, imageSize);
27508
+ }
27509
+ function prepareUrlAnnotation(params) {
27510
+ const {
27511
+ node: { attrs = {}, marks = [] }
27512
+ } = params;
27513
+ const newId = addNewLinkRelationship(params, attrs.linkUrl);
27514
+ const linkTextNode = getTextNodeForExport(attrs.linkUrl, marks, params);
27515
+ const contentNode = processLinkContentNode(linkTextNode);
27516
+ return {
27517
+ name: "w:hyperlink",
27518
+ type: "element",
27287
27519
  attributes: {
27288
- "w14:anchorId": Math.floor(Math.random() * 4294967295).toString()
27520
+ "r:id": newId,
27521
+ "w:history": 1
27289
27522
  },
27290
- elements: [rect]
27523
+ elements: [contentNode]
27291
27524
  };
27292
- return wrapTextInRun(pict);
27293
27525
  }
27294
- class DocxExporter {
27295
- constructor(converter) {
27296
- __privateAdd(this, _DocxExporter_instances);
27297
- this.converter = converter;
27298
- }
27299
- schemaToXml(data, debug = false) {
27300
- const result = __privateMethod(this, _DocxExporter_instances, generate_xml_as_list_fn).call(this, data, debug);
27301
- return result.join("");
27526
+ function getTranslationByAnnotationType(annotationType, annotationFieldType) {
27527
+ if (annotationType === "text" && annotationFieldType === "FILEUPLOADER") {
27528
+ return null;
27302
27529
  }
27530
+ const imageEmuSize = {
27531
+ w: 4286250,
27532
+ h: 4286250
27533
+ };
27534
+ const signatureEmuSize = {
27535
+ w: 99e4,
27536
+ h: 495e3
27537
+ };
27538
+ const dictionary = {
27539
+ text: prepareTextAnnotation,
27540
+ image: (params) => prepareImageAnnotation(params, imageEmuSize),
27541
+ signature: (params) => prepareImageAnnotation(params, signatureEmuSize),
27542
+ checkbox: prepareCheckboxAnnotation,
27543
+ html: prepareHtmlAnnotation,
27544
+ link: prepareUrlAnnotation
27545
+ };
27546
+ return dictionary[annotationType];
27303
27547
  }
27304
- _DocxExporter_instances = new WeakSet();
27305
- generate_xml_as_list_fn = function(data, debug = false) {
27306
- const json = JSON.parse(JSON.stringify(data));
27307
- const declaration = this.converter.declaration.attributes;
27308
- const xmlTag = `<?xml${Object.entries(declaration).map(([key, value]) => ` ${key}="${value}"`).join("")}?>`;
27309
- const result = __privateMethod(this, _DocxExporter_instances, generateXml_fn).call(this, json, debug);
27310
- const final = [xmlTag, ...result];
27311
- return final;
27312
- };
27313
- replaceSpecialCharacters_fn = function(text) {
27314
- if (!text) return;
27315
- return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
27548
+ const translateFieldAttrsToMarks = (attrs = {}) => {
27549
+ const { fontFamily, fontSize, bold, underline, italic, textColor, textHighlight } = attrs;
27550
+ const marks = [];
27551
+ if (fontFamily) marks.push({ type: "fontFamily", attrs: { fontFamily } });
27552
+ if (fontSize) marks.push({ type: "fontSize", attrs: { fontSize } });
27553
+ if (bold) marks.push({ type: "bold", attrs: {} });
27554
+ if (underline) marks.push({ type: "underline", attrs: {} });
27555
+ if (italic) marks.push({ type: "italic", attrs: {} });
27556
+ if (textColor) marks.push({ type: "color", attrs: { color: textColor } });
27557
+ if (textHighlight) marks.push({ type: "highlight", attrs: { color: textHighlight } });
27558
+ return marks;
27316
27559
  };
27317
- generateXml_fn = function(node2) {
27318
- if (!node2) return null;
27319
- let { name } = node2;
27320
- const { elements, attributes } = node2;
27321
- let tag = `<${name}`;
27322
- for (let attr in attributes) {
27323
- const parsedAttrName = typeof attributes[attr] === "string" ? __privateMethod(this, _DocxExporter_instances, replaceSpecialCharacters_fn).call(this, attributes[attr]) : attributes[attr];
27324
- tag += ` ${attr}="${parsedAttrName}"`;
27325
- }
27326
- const selfClosing = name && (!elements || !elements.length);
27327
- if (selfClosing) tag += " />";
27328
- else tag += ">";
27329
- let tags = [tag];
27330
- if (!name && node2.type === "text") {
27331
- return node2.text;
27560
+ function translateFieldAnnotation(params) {
27561
+ const { node: node2, isFinalDoc, fieldsHighlightColor } = params;
27562
+ const { attrs = {} } = node2;
27563
+ const annotationHandler = getTranslationByAnnotationType(attrs.type, attrs.fieldType);
27564
+ if (!annotationHandler) return {};
27565
+ let processedNode;
27566
+ let sdtContentElements;
27567
+ if ((attrs.type === "image" || attrs.type === "signature") && !attrs.hash) {
27568
+ attrs.hash = generateDocxRandomId(4);
27332
27569
  }
27333
- if (elements) {
27334
- if (name === "w:instrText") {
27335
- tags.push(elements[0].text);
27336
- } else if (name === "w:t" || name === "w:delText" || name === "wp:posOffset") {
27337
- try {
27338
- let text = String(elements[0].text);
27339
- text = __privateMethod(this, _DocxExporter_instances, replaceSpecialCharacters_fn).call(this, text);
27340
- tags.push(text);
27341
- } catch (error) {
27342
- console.error("Text element does not contain valid string:", error);
27343
- }
27344
- } else {
27345
- if (elements) {
27346
- for (let child of elements) {
27347
- const newElements = __privateMethod(this, _DocxExporter_instances, generateXml_fn).call(this, child);
27348
- if (!newElements) continue;
27349
- if (typeof newElements === "string") {
27350
- tags.push(newElements);
27351
- continue;
27352
- }
27353
- const removeUndefined = newElements.filter((el) => {
27354
- return el !== "<undefined>" && el !== "</undefined>";
27355
- });
27356
- tags.push(...removeUndefined);
27357
- }
27358
- }
27570
+ if (isFinalDoc) {
27571
+ return annotationHandler(params);
27572
+ } else {
27573
+ processedNode = annotationHandler(params);
27574
+ sdtContentElements = [processedNode];
27575
+ if (attrs.type === "html") {
27576
+ sdtContentElements = [...processedNode.elements];
27359
27577
  }
27360
27578
  }
27361
- if (!selfClosing) tags.push(`</${name}>`);
27362
- return tags;
27363
- };
27364
- function resizeKeepAspectRatio(width, height, maxWidth) {
27365
- if (width > maxWidth) {
27366
- let scale = maxWidth / width;
27367
- let newHeight = Math.round(height * scale);
27368
- return { width: maxWidth, height: newHeight };
27369
- }
27370
- return { width, height };
27371
- }
27372
- function applyMarksToHtmlAnnotation(state2, marks) {
27373
- const { tr, doc: doc2, schema } = state2;
27374
- const allowedMarks = ["fontFamily", "fontSize", "highlight"];
27375
- if (!marks.some((m2) => allowedMarks.includes(m2.type))) {
27376
- return state2;
27579
+ sdtContentElements = [...sdtContentElements];
27580
+ const fieldBackgroundTag = getFieldHighlightJson(fieldsHighlightColor);
27581
+ if (fieldBackgroundTag) {
27582
+ sdtContentElements.unshift(fieldBackgroundTag);
27377
27583
  }
27378
- const fontFamily = marks.find((m2) => m2.type === "fontFamily");
27379
- const fontSize = marks.find((m2) => m2.type === "fontSize");
27380
- const highlight = marks.find((m2) => m2.type === "highlight");
27381
- const textStyleType = schema.marks.textStyle;
27382
- const highlightType = schema.marks.highlight;
27383
- doc2.descendants((node2, pos) => {
27384
- if (!node2.isText) return;
27385
- const foundTextStyle = node2.marks.find((m2) => m2.type.name === "textStyle");
27386
- const foundHighlight = node2.marks.find((m2) => m2.type.name === "highlight");
27387
- if (!foundTextStyle) {
27388
- tr.addMark(
27389
- pos,
27390
- pos + node2.nodeSize,
27391
- textStyleType.create({
27392
- ...fontFamily?.attrs,
27393
- ...fontSize?.attrs
27394
- })
27395
- );
27396
- } else if (!foundTextStyle?.attrs.fontFamily && fontFamily) {
27397
- tr.addMark(
27398
- pos,
27399
- pos + node2.nodeSize,
27400
- textStyleType.create({
27401
- ...foundTextStyle?.attrs,
27402
- ...fontFamily.attrs
27403
- })
27404
- );
27405
- } else if (!foundTextStyle?.attrs.fontSize && fontSize) {
27406
- tr.addMark(
27407
- pos,
27408
- pos + node2.nodeSize,
27409
- textStyleType.create({
27410
- ...foundTextStyle?.attrs,
27411
- ...fontSize.attrs
27412
- })
27413
- );
27414
- }
27415
- if (!foundHighlight) {
27416
- tr.addMark(
27417
- pos,
27418
- pos + node2.nodeSize,
27419
- highlightType.create({
27420
- ...highlight?.attrs
27421
- })
27422
- );
27423
- }
27424
- });
27425
- return state2.apply(tr);
27426
- }
27427
- function translateStructuredContent(params) {
27428
- const { node: node2 } = params;
27429
- const { attrs = {} } = node2;
27430
- const childContent = translateChildNodes({ ...params, nodes: node2.content });
27431
- const nodeElements = [
27432
- {
27433
- name: "w:sdtContent",
27434
- elements: childContent
27435
- }
27436
- ];
27437
- nodeElements.unshift(attrs.sdtPr);
27438
- return {
27584
+ const annotationAttrs = {
27585
+ displayLabel: attrs.displayLabel,
27586
+ defaultDisplayLabel: attrs.defaultDisplayLabel,
27587
+ fieldId: attrs.fieldId,
27588
+ fieldType: attrs.fieldType,
27589
+ fieldTypeShort: attrs.type,
27590
+ fieldColor: attrs.fieldColor,
27591
+ fieldMultipleImage: attrs.multipleImage,
27592
+ fieldFontFamily: attrs.fontFamily,
27593
+ fieldFontSize: attrs.fontSize,
27594
+ fieldTextColor: attrs.textColor,
27595
+ fieldTextHighlight: attrs.textHighlight,
27596
+ hash: attrs.hash
27597
+ };
27598
+ const annotationAttrsJson = JSON.stringify(annotationAttrs);
27599
+ const result = {
27439
27600
  name: "w:sdt",
27440
- elements: nodeElements
27601
+ elements: [
27602
+ {
27603
+ name: "w:sdtPr",
27604
+ elements: [
27605
+ { name: "w:tag", attributes: { "w:val": annotationAttrsJson } },
27606
+ { name: "w:alias", attributes: { "w:val": attrs.displayLabel } }
27607
+ ]
27608
+ },
27609
+ {
27610
+ name: "w:sdtContent",
27611
+ elements: sdtContentElements
27612
+ }
27613
+ ]
27441
27614
  };
27615
+ return result;
27442
27616
  }
27443
- const translatePageNumberNode = (params) => {
27444
- const outputMarks = processOutputMarks(params.node.attrs?.marksAsAttrs || []);
27445
- return getAutoPageJson("PAGE", outputMarks);
27446
- };
27447
- const translateTotalPageNumberNode = (params) => {
27448
- const outputMarks = processOutputMarks(params.node.attrs?.marksAsAttrs || []);
27449
- return getAutoPageJson("NUMPAGES", outputMarks);
27450
- };
27451
- const getAutoPageJson = (type2, outputMarks = []) => {
27452
- return [
27453
- {
27454
- name: "w:r",
27455
- elements: [
27456
- {
27457
- name: "w:rPr",
27458
- elements: outputMarks
27459
- },
27460
- {
27461
- name: "w:fldChar",
27462
- attributes: {
27463
- "w:fldCharType": "begin"
27464
- }
27465
- }
27466
- ]
27617
+ function translateShapeContainer(params) {
27618
+ const { node: node2 } = params;
27619
+ const elements = translateChildNodes(params);
27620
+ const shape = {
27621
+ name: "v:shape",
27622
+ attributes: {
27623
+ ...node2.attrs.attributes,
27624
+ fillcolor: node2.attrs.fillcolor
27467
27625
  },
27468
- {
27469
- name: "w:r",
27470
- elements: [
27471
- {
27472
- name: "w:rPr",
27473
- elements: outputMarks
27474
- },
27626
+ elements: [
27627
+ ...elements,
27628
+ ...node2.attrs.wrapAttributes ? [
27475
27629
  {
27476
- name: "w:instrText",
27477
- elements: [
27478
- {
27479
- type: "text",
27480
- text: ` ${type2}`
27481
- }
27482
- ]
27630
+ name: "w10:wrap",
27631
+ attributes: { ...node2.attrs.wrapAttributes }
27483
27632
  }
27484
- ]
27633
+ ] : []
27634
+ ]
27635
+ };
27636
+ const pict = {
27637
+ name: "w:pict",
27638
+ attributes: {
27639
+ "w14:anchorId": Math.floor(Math.random() * 4294967295).toString()
27485
27640
  },
27486
- {
27487
- name: "w:r",
27488
- elements: [
27489
- {
27490
- name: "w:rPr",
27491
- elements: outputMarks
27492
- },
27493
- {
27494
- name: "w:fldChar",
27495
- attributes: {
27496
- "w:fldCharType": "separate"
27497
- }
27498
- }
27499
- ]
27641
+ elements: [shape]
27642
+ };
27643
+ const par = {
27644
+ name: "w:p",
27645
+ elements: [wrapTextInRun(pict)]
27646
+ };
27647
+ return par;
27648
+ }
27649
+ function translateShapeTextbox(params) {
27650
+ const { node: node2 } = params;
27651
+ const elements = translateChildNodes(params);
27652
+ const textboxContent = {
27653
+ name: "w:txbxContent",
27654
+ elements
27655
+ };
27656
+ const textbox = {
27657
+ name: "v:textbox",
27658
+ attributes: {
27659
+ ...node2.attrs.attributes
27500
27660
  },
27501
- {
27502
- name: "w:r",
27503
- elements: [
27504
- {
27505
- name: "w:rPr",
27506
- elements: outputMarks
27507
- },
27508
- {
27509
- name: "w:fldChar",
27510
- attributes: {
27511
- "w:fldCharType": "end"
27512
- }
27513
- }
27514
- ]
27515
- }
27516
- ];
27517
- };
27518
- const getFieldHighlightJson = (fieldsHighlightColor) => {
27519
- if (!fieldsHighlightColor) return null;
27520
- let parsedColor = fieldsHighlightColor.trim();
27521
- const hexRegex = /^#?([A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/;
27522
- if (!hexRegex.test(parsedColor)) {
27523
- console.warn(`Invalid HEX color provided to fieldsHighlightColor export param: ${fieldsHighlightColor}`);
27524
- return null;
27525
- }
27526
- if (parsedColor.startsWith("#")) {
27527
- parsedColor = parsedColor.slice(1);
27528
- }
27529
- return {
27530
- name: "w:rPr",
27531
- elements: [
27532
- {
27533
- name: "w:shd",
27534
- attributes: {
27535
- "w:fill": `#${parsedColor}`,
27536
- "w:color": "auto",
27537
- "w:val": "clear"
27538
- }
27539
- }
27540
- ]
27661
+ elements: [textboxContent]
27541
27662
  };
27542
- };
27543
- const defaultInitialXml = `<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:oel="http://schemas.microsoft.com/office/2019/extlst" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16cex="http://schemas.microsoft.com/office/word/2018/wordml/cex" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16="http://schemas.microsoft.com/office/word/2018/wordml" xmlns:w16sdtdh="http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se w16cid w16 w16cex w16sdtdh wp14"><w:body></w:body></w:document>`;
27544
- const parseXmlToJson = (xml) => {
27545
- return JSON.parse(xmljs.xml2json(xml, null, 2));
27546
- };
27547
- const getInitialJSON = (parsedDocx, fallbackXml = defaultInitialXml) => {
27548
- return parsedDocx["word/document.xml"] || parseXmlToJson(fallbackXml);
27549
- };
27550
- const handleAllTableNodes = (params) => {
27551
- const { nodes } = params;
27552
- if (nodes.length === 0) {
27553
- return { nodes: [], consumed: 0 };
27554
- }
27555
- const node2 = nodes[0];
27556
- switch (node2.name) {
27557
- case "w:tbl":
27558
- return { nodes: [handleTableNode(node2, params)], consumed: 1 };
27559
- }
27560
- return { nodes: [], consumed: 0 };
27561
- };
27562
- const tableNodeHandlerEntity = {
27563
- handlerName: "tableNodeHandler",
27564
- handler: handleAllTableNodes
27565
- };
27566
- function handleTableNode(node2, params) {
27567
- const { docx, nodeListHandler: nodeListHandler2 } = params;
27568
- const tblPr = node2.elements.find((el) => el.name === "w:tblPr");
27569
- const tableBordersElement = tblPr.elements.find((el) => el.name === "w:tblBorders");
27570
- const tableBorders = tableBordersElement?.elements || [];
27571
- const { borders, rowBorders } = processTableBorders(tableBorders);
27572
- const tblStyleTag = tblPr.elements.find((el) => el.name === "w:tblStyle");
27573
- const tableStyleId = tblStyleTag?.attributes["w:val"];
27574
- const attrs = { tableStyleId };
27575
- const tableIndent = tblPr?.elements.find((el) => el.name === "w:tblInd");
27576
- if (tableIndent) {
27577
- const { "w:w": width, "w:type": type2 } = tableIndent.attributes;
27578
- attrs["tableIndent"] = { width: twipsToPixels(width), type: type2 };
27579
- }
27580
- const tableLayout = tblPr?.elements.find((el) => el.name === "w:tblLayout");
27581
- if (tableLayout) {
27582
- const { "w:type": type2 } = tableLayout.attributes;
27583
- attrs["tableLayout"] = type2;
27584
- }
27585
- const referencedStyles = getReferencedTableStyles(tblStyleTag, docx);
27586
- const tblW = tblPr.elements.find((el) => el.name === "w:tblW");
27587
- if (tblW) {
27588
- attrs["tableWidth"] = {
27589
- width: twipsToPixels(tblW.attributes["w:w"]),
27590
- type: tblW.attributes["w:type"]
27591
- };
27592
- }
27593
- const tblCellSpacing = tblPr.elements.find((el) => el.name === "w:tblCellSpacing");
27594
- if (tblCellSpacing) {
27595
- attrs["tableCellSpacing"] = {
27596
- w: tblCellSpacing.attributes["w:w"],
27597
- type: tblCellSpacing.attributes["w:type"]
27598
- };
27599
- attrs["borderCollapse"] = "separate";
27600
- }
27601
- const tblJustification = tblPr.elements.find((el) => el.name === "w:jc");
27602
- if (tblJustification?.attributes) {
27603
- attrs["justification"] = tblJustification.attributes["w:val"];
27663
+ return textbox;
27664
+ }
27665
+ function translateContentBlock(params) {
27666
+ const { node: node2 } = params;
27667
+ const { drawingContent, vmlAttributes, horizontalRule } = node2.attrs;
27668
+ if (vmlAttributes || horizontalRule) {
27669
+ return translateVRectContentBlock(params);
27604
27670
  }
27605
- const rows = node2.elements.filter((el) => el.name === "w:tr");
27606
- const refStylesBorders = referencedStyles?.borders || {};
27607
- const refStylesRowBorders = referencedStyles?.rowBorders || {};
27608
- const borderData = Object.keys(borders)?.length ? Object.assign(refStylesBorders, borders) : refStylesBorders;
27609
- const borderRowData = Object.keys(rowBorders)?.length ? Object.assign(refStylesRowBorders, rowBorders) : refStylesRowBorders;
27610
- attrs["borders"] = borderData;
27611
- const content = [];
27612
- rows.forEach((row) => {
27613
- const result = handleTableRowNode(row, node2, borderRowData, tblStyleTag, params);
27614
- if (result.content?.length) content.push(result);
27615
- });
27616
- return {
27617
- type: "table",
27618
- content,
27619
- attrs
27671
+ const drawing = {
27672
+ name: "w:drawing",
27673
+ elements: [...drawingContent ? [...drawingContent.elements || []] : []]
27620
27674
  };
27621
- }
27622
- function handleTableCellNode(node2, row, table, rowBorders, columnWidth = null, styleTag, params, columnIndex) {
27623
- const { docx, nodeListHandler: nodeListHandler2 } = params;
27624
- const tcPr = node2.elements.find((el) => el.name === "w:tcPr");
27625
- const borders = tcPr?.elements?.find((el) => el.name === "w:tcBorders");
27626
- const inlineBorders = processInlineCellBorders(borders, rowBorders);
27627
- const gridColumnWidths = getGridColumnWidths(table);
27628
- const tcWidth = tcPr?.elements?.find((el) => el.name === "w:tcW");
27629
- let width = tcWidth ? twipsToPixels(tcWidth.attributes["w:w"]) : null;
27630
- const widthType = tcWidth?.attributes["w:type"];
27631
- if (!width && columnWidth) width = columnWidth;
27632
- const vMerge = getTableCellMergeTag(node2);
27633
- const { attributes: vMergeAttrs } = vMerge || {};
27634
- const backgroundColor = tcPr?.elements?.find((el) => el.name === "w:shd");
27635
- const background = {
27636
- color: backgroundColor?.attributes["w:fill"]
27675
+ const choice = {
27676
+ name: "mc:Choice",
27677
+ attributes: { Requires: "wps" },
27678
+ elements: [drawing]
27679
+ };
27680
+ const alternateContent = {
27681
+ name: "mc:AlternateContent",
27682
+ elements: [choice]
27637
27683
  };
27638
- const colspanTag = tcPr?.elements?.find((el) => el.name === "w:gridSpan");
27639
- const colspan = colspanTag?.attributes["w:val"];
27640
- const marginTag = tcPr?.elements?.find((el) => el.name === "w:tcMar");
27641
- const verticalAlignTag = tcPr?.elements?.find((el) => el.name === "w:vAlign");
27642
- const verticalAlign = verticalAlignTag?.attributes["w:val"] || "top";
27643
- const attributes = {};
27644
- const referencedStyles = getReferencedTableStyles(styleTag, docx) || {};
27645
- attributes.cellMargins = getTableCellMargins(marginTag, referencedStyles);
27646
- const { fontSize, fonts = {} } = referencedStyles;
27647
- const fontFamily = fonts["ascii"];
27648
- if (width) {
27649
- attributes["colwidth"] = [width];
27650
- attributes["widthUnit"] = "px";
27651
- const defaultColWidths = gridColumnWidths;
27652
- const hasDefaultColWidths = gridColumnWidths && gridColumnWidths.length > 0;
27653
- const colspanNum = parseInt(colspan || 1, 10);
27654
- if (colspanNum && colspanNum > 1 && hasDefaultColWidths) {
27655
- let colwidth = [];
27656
- for (let i = 0; i < colspanNum; i++) {
27657
- let colwidthValue = defaultColWidths[columnIndex + i];
27658
- let defaultColwidth = 100;
27659
- if (typeof colwidthValue !== "undefined") {
27660
- colwidth.push(colwidthValue);
27661
- } else {
27662
- colwidth.push(defaultColwidth);
27663
- }
27664
- }
27665
- if (colwidth.length) {
27666
- attributes["colwidth"] = [...colwidth];
27667
- }
27668
- }
27684
+ return wrapTextInRun(alternateContent);
27685
+ }
27686
+ function translateVRectContentBlock(params) {
27687
+ const { node: node2 } = params;
27688
+ const { vmlAttributes, background, attributes, style } = node2.attrs;
27689
+ const rectAttrs = {
27690
+ id: attributes?.id || `_x0000_i${Math.floor(Math.random() * 1e4)}`
27691
+ };
27692
+ if (style) {
27693
+ rectAttrs.style = style;
27669
27694
  }
27670
- if (widthType) attributes["widthType"] = widthType;
27671
- if (colspan) attributes["colspan"] = parseInt(colspan, 10);
27672
- if (background) attributes["background"] = background;
27673
- attributes["verticalAlign"] = verticalAlign;
27674
- if (fontSize) attributes["fontSize"] = fontSize;
27675
- if (fontFamily) attributes["fontFamily"] = fontFamily["ascii"];
27676
- if (rowBorders) attributes["borders"] = { ...rowBorders };
27677
- if (inlineBorders) attributes["borders"] = Object.assign(attributes["borders"] || {}, inlineBorders);
27678
- if (vMergeAttrs && vMergeAttrs["w:val"] === "restart") {
27679
- const rows = table.elements.filter((el) => el.name === "w:tr");
27680
- const currentRowIndex = rows.findIndex((r) => r === row);
27681
- const remainingRows = rows.slice(currentRowIndex + 1);
27682
- const cellsInRow = row.elements.filter((el) => el.name === "w:tc");
27683
- let cellIndex = cellsInRow.findIndex((el) => el === node2);
27684
- let rowspan = 1;
27685
- for (let remainingRow of remainingRows) {
27686
- const firstCell = remainingRow.elements.findIndex((el) => el.name === "w:tc");
27687
- const cellAtIndex = remainingRow.elements[firstCell + cellIndex];
27688
- if (!cellAtIndex) break;
27689
- const vMerge2 = getTableCellMergeTag(cellAtIndex);
27690
- const { attributes: currentCellMergeAttrs } = vMerge2 || {};
27691
- if (!vMerge2 && !currentCellMergeAttrs || currentCellMergeAttrs && currentCellMergeAttrs["w:val"] === "restart") {
27692
- break;
27695
+ if (background) {
27696
+ rectAttrs.fillcolor = background;
27697
+ }
27698
+ if (vmlAttributes) {
27699
+ if (vmlAttributes.hralign) rectAttrs["o:hralign"] = vmlAttributes.hralign;
27700
+ if (vmlAttributes.hrstd) rectAttrs["o:hrstd"] = vmlAttributes.hrstd;
27701
+ if (vmlAttributes.hr) rectAttrs["o:hr"] = vmlAttributes.hr;
27702
+ if (vmlAttributes.stroked) rectAttrs.stroked = vmlAttributes.stroked;
27703
+ }
27704
+ if (attributes) {
27705
+ Object.entries(attributes).forEach(([key, value]) => {
27706
+ if (!rectAttrs[key] && value !== void 0) {
27707
+ rectAttrs[key] = value;
27693
27708
  }
27694
- rowspan++;
27695
- remainingRow.elements.splice(firstCell + cellIndex, 1);
27696
- }
27697
- attributes["rowspan"] = rowspan;
27709
+ });
27698
27710
  }
27699
- return {
27700
- type: "tableCell",
27701
- content: nodeListHandler2.handler({ ...params, nodes: node2.elements }),
27702
- attrs: attributes
27711
+ const rect = {
27712
+ name: "v:rect",
27713
+ attributes: rectAttrs
27714
+ };
27715
+ const pict = {
27716
+ name: "w:pict",
27717
+ attributes: {
27718
+ "w14:anchorId": Math.floor(Math.random() * 4294967295).toString()
27719
+ },
27720
+ elements: [rect]
27703
27721
  };
27722
+ return wrapTextInRun(pict);
27704
27723
  }
27705
- const getTableCellMergeTag = (node2) => {
27706
- const tcPr = node2.elements.find((el) => el.name === "w:tcPr");
27707
- const vMerge = tcPr?.elements?.find((el) => el.name === "w:vMerge");
27708
- return vMerge;
27709
- };
27710
- const processBorder = (borders, direction, rowBorders = {}) => {
27711
- const borderAttrs = borders?.elements?.find((el) => el.name === `w:${direction}`)?.attributes;
27712
- if (borderAttrs && borderAttrs["w:val"] !== "nil") {
27713
- const border = {};
27714
- const color = borderAttrs["w:color"];
27715
- if (color) border["color"] = color === "auto" ? "#000000" : `#${color}`;
27716
- const size = borderAttrs["w:sz"];
27717
- if (size) border["size"] = eigthPointsToPixels(size);
27718
- return border;
27724
+ class DocxExporter {
27725
+ constructor(converter) {
27726
+ __privateAdd(this, _DocxExporter_instances);
27727
+ this.converter = converter;
27719
27728
  }
27720
- if (borderAttrs && borderAttrs["w:val"] === "nil") {
27721
- const border = Object.assign({}, rowBorders[direction] || {});
27722
- if (!Object.keys(border)) return null;
27723
- border["val"] = "none";
27724
- return border;
27729
+ schemaToXml(data, debug = false) {
27730
+ const result = __privateMethod(this, _DocxExporter_instances, generate_xml_as_list_fn).call(this, data, debug);
27731
+ return result.join("");
27725
27732
  }
27726
- return null;
27733
+ }
27734
+ _DocxExporter_instances = new WeakSet();
27735
+ generate_xml_as_list_fn = function(data, debug = false) {
27736
+ const json = JSON.parse(JSON.stringify(data));
27737
+ const declaration = this.converter.declaration.attributes;
27738
+ const xmlTag = `<?xml${Object.entries(declaration).map(([key, value]) => ` ${key}="${value}"`).join("")}?>`;
27739
+ const result = __privateMethod(this, _DocxExporter_instances, generateXml_fn).call(this, json, debug);
27740
+ const final = [xmlTag, ...result];
27741
+ return final;
27727
27742
  };
27728
- const processInlineCellBorders = (borders, rowBorders) => {
27729
- if (!borders) return null;
27730
- const processedBorders = {};
27731
- const inlineBorderBottom = processBorder(borders, "bottom", rowBorders);
27732
- if (inlineBorderBottom) processedBorders["bottom"] = inlineBorderBottom;
27733
- const inlineBorderTop = processBorder(borders, "top", rowBorders);
27734
- if (inlineBorderTop) processedBorders["top"] = inlineBorderTop;
27735
- const inlineBorderLeft = processBorder(borders, "left", rowBorders);
27736
- if (inlineBorderLeft) processedBorders["left"] = inlineBorderLeft;
27737
- const inlineBorderRight = processBorder(borders, "right", rowBorders);
27738
- if (inlineBorderRight) processedBorders["right"] = inlineBorderRight;
27739
- return processedBorders;
27743
+ replaceSpecialCharacters_fn = function(text) {
27744
+ if (!text) return;
27745
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
27740
27746
  };
27741
- function getReferencedTableStyles(tblStyleTag, docx) {
27742
- if (!tblStyleTag) return null;
27743
- const stylesToReturn = {};
27744
- const { attributes = {} } = tblStyleTag;
27745
- const tableStyleReference = attributes["w:val"];
27746
- if (!tableStyleReference) return null;
27747
- const styles = docx["word/styles.xml"];
27748
- const { elements } = styles.elements[0];
27749
- const styleElements = elements.filter((el) => el.name === "w:style");
27750
- const styleTag = styleElements.find((el) => el.attributes["w:styleId"] === tableStyleReference);
27751
- if (!styleTag) return null;
27752
- stylesToReturn.name = styleTag.elements.find((el) => el.name === "w:name");
27753
- const basedOn = styleTag.elements.find((el) => el.name === "w:basedOn");
27754
- let baseTblPr;
27755
- if (basedOn?.attributes) {
27756
- const baseStyles = styleElements.find((el) => el.attributes["w:styleId"] === basedOn.attributes["w:val"]);
27757
- baseTblPr = baseStyles ? baseStyles.elements.find((el) => el.name === "w:tblPr") : {};
27747
+ generateXml_fn = function(node2) {
27748
+ if (!node2) return null;
27749
+ let { name } = node2;
27750
+ const { elements, attributes } = node2;
27751
+ let tag = `<${name}`;
27752
+ for (let attr in attributes) {
27753
+ const parsedAttrName = typeof attributes[attr] === "string" ? __privateMethod(this, _DocxExporter_instances, replaceSpecialCharacters_fn).call(this, attributes[attr]) : attributes[attr];
27754
+ tag += ` ${attr}="${parsedAttrName}"`;
27758
27755
  }
27759
- const pPr = styleTag.elements.find((el) => el.name === "w:pPr");
27760
- if (pPr) {
27761
- const justification = pPr.elements.find((el) => el.name === "w:jc");
27762
- if (justification?.attributes) stylesToReturn.justification = justification.attributes["w:val"];
27756
+ const selfClosing = name && (!elements || !elements.length);
27757
+ if (selfClosing) tag += " />";
27758
+ else tag += ">";
27759
+ let tags = [tag];
27760
+ if (!name && node2.type === "text") {
27761
+ return node2.text;
27763
27762
  }
27764
- const rPr = styleTag?.elements.find((el) => el.name === "w:rPr");
27765
- if (rPr) {
27766
- const fonts = rPr.elements.find((el) => el.name === "w:rFonts");
27767
- if (fonts) {
27768
- const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
27769
- stylesToReturn.fonts = { ascii, hAnsi, cs };
27763
+ if (elements) {
27764
+ if (name === "w:instrText") {
27765
+ tags.push(elements[0].text);
27766
+ } else if (name === "w:t" || name === "w:delText" || name === "wp:posOffset") {
27767
+ try {
27768
+ let text = String(elements[0].text);
27769
+ text = __privateMethod(this, _DocxExporter_instances, replaceSpecialCharacters_fn).call(this, text);
27770
+ tags.push(text);
27771
+ } catch (error) {
27772
+ console.error("Text element does not contain valid string:", error);
27773
+ }
27774
+ } else {
27775
+ if (elements) {
27776
+ for (let child of elements) {
27777
+ const newElements = __privateMethod(this, _DocxExporter_instances, generateXml_fn).call(this, child);
27778
+ if (!newElements) continue;
27779
+ if (typeof newElements === "string") {
27780
+ tags.push(newElements);
27781
+ continue;
27782
+ }
27783
+ const removeUndefined = newElements.filter((el) => {
27784
+ return el !== "<undefined>" && el !== "</undefined>";
27785
+ });
27786
+ tags.push(...removeUndefined);
27787
+ }
27788
+ }
27770
27789
  }
27771
- const fontSize = rPr.elements.find((el) => el.name === "w:sz");
27772
- if (fontSize?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize.attributes["w:val"]) + "pt";
27773
27790
  }
27774
- const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
27775
- if (tblPr && tblPr.elements) {
27776
- if (baseTblPr && baseTblPr.elements) {
27777
- tblPr.elements.push(...baseTblPr.elements);
27791
+ if (!selfClosing) tags.push(`</${name}>`);
27792
+ return tags;
27793
+ };
27794
+ function resizeKeepAspectRatio(width, height, maxWidth) {
27795
+ if (width > maxWidth) {
27796
+ let scale = maxWidth / width;
27797
+ let newHeight = Math.round(height * scale);
27798
+ return { width: maxWidth, height: newHeight };
27799
+ }
27800
+ return { width, height };
27801
+ }
27802
+ function applyMarksToHtmlAnnotation(state2, marks) {
27803
+ const { tr, doc: doc2, schema } = state2;
27804
+ const allowedMarks = ["fontFamily", "fontSize", "highlight"];
27805
+ if (!marks.some((m2) => allowedMarks.includes(m2.type))) {
27806
+ return state2;
27807
+ }
27808
+ const fontFamily = marks.find((m2) => m2.type === "fontFamily");
27809
+ const fontSize = marks.find((m2) => m2.type === "fontSize");
27810
+ const highlight = marks.find((m2) => m2.type === "highlight");
27811
+ const textStyleType = schema.marks.textStyle;
27812
+ const highlightType = schema.marks.highlight;
27813
+ doc2.descendants((node2, pos) => {
27814
+ if (!node2.isText) return;
27815
+ const foundTextStyle = node2.marks.find((m2) => m2.type.name === "textStyle");
27816
+ const foundHighlight = node2.marks.find((m2) => m2.type.name === "highlight");
27817
+ if (!foundTextStyle) {
27818
+ tr.addMark(
27819
+ pos,
27820
+ pos + node2.nodeSize,
27821
+ textStyleType.create({
27822
+ ...fontFamily?.attrs,
27823
+ ...fontSize?.attrs
27824
+ })
27825
+ );
27826
+ } else if (!foundTextStyle?.attrs.fontFamily && fontFamily) {
27827
+ tr.addMark(
27828
+ pos,
27829
+ pos + node2.nodeSize,
27830
+ textStyleType.create({
27831
+ ...foundTextStyle?.attrs,
27832
+ ...fontFamily.attrs
27833
+ })
27834
+ );
27835
+ } else if (!foundTextStyle?.attrs.fontSize && fontSize) {
27836
+ tr.addMark(
27837
+ pos,
27838
+ pos + node2.nodeSize,
27839
+ textStyleType.create({
27840
+ ...foundTextStyle?.attrs,
27841
+ ...fontSize.attrs
27842
+ })
27843
+ );
27778
27844
  }
27779
- const tableBorders = tblPr?.elements?.find((el) => el.name === "w:tblBorders");
27780
- const { elements: borderElements = [] } = tableBorders || {};
27781
- const { borders, rowBorders } = processTableBorders(borderElements);
27782
- if (borders) stylesToReturn.borders = borders;
27783
- if (rowBorders) stylesToReturn.rowBorders = rowBorders;
27784
- const tableCellMargin = tblPr?.elements.find((el) => el.name === "w:tblCellMar");
27785
- if (tableCellMargin) {
27786
- const marginLeft = tableCellMargin.elements.find((el) => el.name === "w:left");
27787
- const marginRight = tableCellMargin.elements.find((el) => el.name === "w:right");
27788
- const marginTop = tableCellMargin.elements.find((el) => el.name === "w:top");
27789
- const marginBottom = tableCellMargin.elements.find((el) => el.name === "w:bottom");
27790
- stylesToReturn.cellMargins = {
27791
- marginLeft: marginLeft?.attributes["w:w"],
27792
- marginRight: marginRight?.attributes["w:w"],
27793
- marginTop: marginTop?.attributes["w:w"],
27794
- marginBottom: marginBottom?.attributes["w:w"]
27795
- };
27845
+ if (!foundHighlight) {
27846
+ tr.addMark(
27847
+ pos,
27848
+ pos + node2.nodeSize,
27849
+ highlightType.create({
27850
+ ...highlight?.attrs
27851
+ })
27852
+ );
27796
27853
  }
27797
- }
27798
- return stylesToReturn;
27799
- }
27800
- function processTableBorders(borderElements) {
27801
- const borders = {};
27802
- const rowBorders = {};
27803
- borderElements.forEach((borderElement) => {
27804
- const { name } = borderElement;
27805
- const borderName = name.split("w:")[1];
27806
- const { attributes } = borderElement;
27807
- const attrs = {};
27808
- const color = attributes["w:color"];
27809
- const size = attributes["w:sz"];
27810
- if (color && color !== "auto") attrs["color"] = color.startsWith("#") ? color : `#${color}`;
27811
- if (size && size !== "auto") attrs["size"] = eigthPointsToPixels(size);
27812
- const rowBorderNames = ["insideH", "insideV"];
27813
- if (rowBorderNames.includes(borderName)) rowBorders[borderName] = attrs;
27814
- borders[borderName] = attrs;
27815
27854
  });
27855
+ return state2.apply(tr);
27856
+ }
27857
+ function translateStructuredContent(params) {
27858
+ const { node: node2 } = params;
27859
+ const { attrs = {} } = node2;
27860
+ const childContent = translateChildNodes({ ...params, nodes: node2.content });
27861
+ const nodeElements = [
27862
+ {
27863
+ name: "w:sdtContent",
27864
+ elements: childContent
27865
+ }
27866
+ ];
27867
+ nodeElements.unshift(attrs.sdtPr);
27816
27868
  return {
27817
- borders,
27818
- rowBorders
27869
+ name: "w:sdt",
27870
+ elements: nodeElements
27819
27871
  };
27820
27872
  }
27821
- function handleTableRowNode(node2, table, rowBorders, styleTag, params) {
27822
- const attrs = {};
27823
- const tPr = node2.elements.find((el) => el.name === "w:trPr");
27824
- const rowHeightTag = tPr?.elements?.find((el) => el.name === "w:trHeight");
27825
- const rowHeight = rowHeightTag?.attributes["w:val"];
27826
- const cantSplitTag = tPr?.elements?.find((el) => el.name === "w:cantSplit");
27827
- if (cantSplitTag) {
27828
- attrs["cantSplit"] = true;
27873
+ const translatePageNumberNode = (params) => {
27874
+ const outputMarks = processOutputMarks(params.node.attrs?.marksAsAttrs || []);
27875
+ return getAutoPageJson("PAGE", outputMarks);
27876
+ };
27877
+ const translateTotalPageNumberNode = (params) => {
27878
+ const outputMarks = processOutputMarks(params.node.attrs?.marksAsAttrs || []);
27879
+ return getAutoPageJson("NUMPAGES", outputMarks);
27880
+ };
27881
+ const getAutoPageJson = (type2, outputMarks = []) => {
27882
+ return [
27883
+ {
27884
+ name: "w:r",
27885
+ elements: [
27886
+ {
27887
+ name: "w:rPr",
27888
+ elements: outputMarks
27889
+ },
27890
+ {
27891
+ name: "w:fldChar",
27892
+ attributes: {
27893
+ "w:fldCharType": "begin"
27894
+ }
27895
+ }
27896
+ ]
27897
+ },
27898
+ {
27899
+ name: "w:r",
27900
+ elements: [
27901
+ {
27902
+ name: "w:rPr",
27903
+ elements: outputMarks
27904
+ },
27905
+ {
27906
+ name: "w:instrText",
27907
+ elements: [
27908
+ {
27909
+ type: "text",
27910
+ text: ` ${type2}`
27911
+ }
27912
+ ]
27913
+ }
27914
+ ]
27915
+ },
27916
+ {
27917
+ name: "w:r",
27918
+ elements: [
27919
+ {
27920
+ name: "w:rPr",
27921
+ elements: outputMarks
27922
+ },
27923
+ {
27924
+ name: "w:fldChar",
27925
+ attributes: {
27926
+ "w:fldCharType": "separate"
27927
+ }
27928
+ }
27929
+ ]
27930
+ },
27931
+ {
27932
+ name: "w:r",
27933
+ elements: [
27934
+ {
27935
+ name: "w:rPr",
27936
+ elements: outputMarks
27937
+ },
27938
+ {
27939
+ name: "w:fldChar",
27940
+ attributes: {
27941
+ "w:fldCharType": "end"
27942
+ }
27943
+ }
27944
+ ]
27945
+ }
27946
+ ];
27947
+ };
27948
+ const getFieldHighlightJson = (fieldsHighlightColor) => {
27949
+ if (!fieldsHighlightColor) return null;
27950
+ let parsedColor = fieldsHighlightColor.trim();
27951
+ const hexRegex = /^#?([A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/;
27952
+ if (!hexRegex.test(parsedColor)) {
27953
+ console.warn(`Invalid HEX color provided to fieldsHighlightColor export param: ${fieldsHighlightColor}`);
27954
+ return null;
27829
27955
  }
27830
- const borders = {};
27831
- if (rowBorders?.insideH) borders["bottom"] = rowBorders.insideH;
27832
- if (rowBorders?.insideV) borders["right"] = rowBorders.insideV;
27833
- attrs["borders"] = borders;
27834
- if (rowHeight) {
27835
- attrs["rowHeight"] = twipsToPixels(rowHeight);
27956
+ if (parsedColor.startsWith("#")) {
27957
+ parsedColor = parsedColor.slice(1);
27836
27958
  }
27837
- const gridColumnWidths = getGridColumnWidths(table);
27838
- const cellNodes = node2.elements.filter((el) => el.name === "w:tc");
27839
- let currentColumnIndex = 0;
27840
- const content = cellNodes?.map((n) => {
27841
- let colWidth = gridColumnWidths?.[currentColumnIndex] || null;
27842
- const result = handleTableCellNode(n, node2, table, borders, colWidth, styleTag, params, currentColumnIndex);
27843
- const tcPr = n.elements?.find((el) => el.name === "w:tcPr");
27844
- const colspanTag = tcPr?.elements?.find((el) => el.name === "w:gridSpan");
27845
- const colspan = parseInt(colspanTag?.attributes["w:val"] || 1, 10);
27846
- currentColumnIndex += colspan;
27847
- return result;
27848
- }) || [];
27849
- const newNode = {
27850
- type: "tableRow",
27851
- content,
27852
- attrs
27853
- };
27854
- return newNode;
27855
- }
27856
- const getTableCellMargins = (marginTag, referencedStyles) => {
27857
- const inlineMarginLeftTag = marginTag?.elements?.find((el) => el.name === "w:left");
27858
- const inlineMarginRightTag = marginTag?.elements?.find((el) => el.name === "w:right");
27859
- const inlineMarginTopTag = marginTag?.elements?.find((el) => el.name === "w:top");
27860
- const inlineMarginBottomTag = marginTag?.elements?.find((el) => el.name === "w:bottom");
27861
- const inlineMarginLeftValue = inlineMarginLeftTag?.attributes["w:w"];
27862
- const inlineMarginRightValue = inlineMarginRightTag?.attributes["w:w"];
27863
- const inlineMarginTopValue = inlineMarginTopTag?.attributes["w:w"];
27864
- const inlineMarginBottomValue = inlineMarginBottomTag?.attributes["w:w"];
27865
- const { cellMargins = {} } = referencedStyles;
27866
- const {
27867
- marginLeft: marginLeftStyle,
27868
- marginRight: marginRightStyle,
27869
- marginTop: marginTopStyle,
27870
- marginBottom: marginBottomStyle
27871
- } = cellMargins;
27872
- const margins = {
27873
- left: twipsToPixels(inlineMarginLeftValue ?? marginLeftStyle),
27874
- right: twipsToPixels(inlineMarginRightValue ?? marginRightStyle),
27875
- top: twipsToPixels(inlineMarginTopValue ?? marginTopStyle),
27876
- bottom: twipsToPixels(inlineMarginBottomValue ?? marginBottomStyle)
27959
+ return {
27960
+ name: "w:rPr",
27961
+ elements: [
27962
+ {
27963
+ name: "w:shd",
27964
+ attributes: {
27965
+ "w:fill": `#${parsedColor}`,
27966
+ "w:color": "auto",
27967
+ "w:val": "clear"
27968
+ }
27969
+ }
27970
+ ]
27877
27971
  };
27878
- return margins;
27879
27972
  };
27880
- const getGridColumnWidths = (tableNode) => {
27881
- const tblGrid = tableNode.elements.find((el) => el.name === "w:tblGrid");
27882
- if (!tblGrid) return [];
27883
- const columnWidths = tblGrid?.elements?.flatMap((el) => {
27884
- if (el.name !== "w:gridCol") return [];
27885
- return twipsToPixels(el.attributes["w:w"]);
27886
- }) || [];
27887
- return columnWidths;
27973
+ const defaultInitialXml = `<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:oel="http://schemas.microsoft.com/office/2019/extlst" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16cex="http://schemas.microsoft.com/office/word/2018/wordml/cex" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16="http://schemas.microsoft.com/office/word/2018/wordml" xmlns:w16sdtdh="http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se w16cid w16 w16cex w16sdtdh wp14"><w:body></w:body></w:document>`;
27974
+ const parseXmlToJson = (xml) => {
27975
+ return JSON.parse(xmljs.xml2json(xml, null, 2));
27976
+ };
27977
+ const getInitialJSON = (parsedDocx, fallbackXml = defaultInitialXml) => {
27978
+ return parsedDocx["word/document.xml"] || parseXmlToJson(fallbackXml);
27888
27979
  };
27889
27980
  const handleDrawingNode = (params) => {
27890
27981
  const { nodes, filename } = params;
@@ -28027,7 +28118,8 @@ const handleShapeDrawing = (params, node2, graphicData) => {
28027
28118
  const translatedElement = nodeListHandler2.handler({
28028
28119
  ...params,
28029
28120
  node: textBoxContent.elements[0],
28030
- nodes: textBoxContent.elements
28121
+ nodes: textBoxContent.elements,
28122
+ path: [...params.path || [], textBoxContent]
28031
28123
  });
28032
28124
  return translatedElement[0];
28033
28125
  };
@@ -28290,7 +28382,12 @@ const handleTrackChangeNode = (params) => {
28290
28382
  }
28291
28383
  const { name } = node2;
28292
28384
  const { attributes, elements } = parseProperties(node2);
28293
- const subs = nodeListHandler2.handler({ ...params, insideTrackChange: true, nodes: elements });
28385
+ const subs = nodeListHandler2.handler({
28386
+ ...params,
28387
+ insideTrackChange: true,
28388
+ nodes: elements,
28389
+ path: [...params.path || [], node2]
28390
+ });
28294
28391
  const changeType = name === "w:del" ? TrackDeleteMarkName : TrackInsertMarkName;
28295
28392
  const mappedAttributes = {
28296
28393
  id: attributes["w:id"],
@@ -28349,7 +28446,11 @@ const handleHyperlinkNode = (params) => {
28349
28446
  }
28350
28447
  }
28351
28448
  }
28352
- const updatedNode = nodeListHandler2.handler({ ...params, nodes: runNodes });
28449
+ const updatedNode = nodeListHandler2.handler({
28450
+ ...params,
28451
+ nodes: runNodes,
28452
+ path: [...params.path || [], node2]
28453
+ });
28353
28454
  return { nodes: updatedNode, consumed: 1 };
28354
28455
  };
28355
28456
  const hyperlinkNodeHandlerEntity = {
@@ -28362,7 +28463,7 @@ const handleRunNode = (params) => {
28362
28463
  return { nodes: [], consumed: 0 };
28363
28464
  }
28364
28465
  const node2 = nodes[0];
28365
- const childParams = { ...params, nodes: node2.elements };
28466
+ const childParams = { ...params, nodes: node2.elements, path: [...params.path || [], node2] };
28366
28467
  let processedRun = nodeListHandler2.handler(childParams)?.filter((n) => n) || [];
28367
28468
  const hasRunProperties = node2.elements?.some((el) => el.name === "w:rPr");
28368
28469
  const defaultNodeStyles = getMarksFromStyles(docx, parentStyleId);
@@ -29199,7 +29300,11 @@ const handleSdtNode = (params) => {
29199
29300
  const sdtContent = node2.elements.find((el) => el.name === "w:sdtContent");
29200
29301
  const par = sdtContent?.elements?.find((el) => el.name === "w:p");
29201
29302
  const { marks } = parseAnnotationMarks(sdtContent);
29202
- const translatedContent = nodeListHandler2.handler({ ...params, nodes: sdtContent?.elements });
29303
+ const translatedContent = nodeListHandler2.handler({
29304
+ ...params,
29305
+ nodes: sdtContent?.elements,
29306
+ path: [...params.path || [], node2]
29307
+ });
29203
29308
  let structuredContentType = "structuredContent";
29204
29309
  if (par) {
29205
29310
  structuredContentType = "structuredContentBlock";
@@ -29227,7 +29332,11 @@ const handleDocumentSectionNode = (params, tagValue) => {
29227
29332
  const title = titleTag?.attributes?.["w:val"] || tagValue.title || null;
29228
29333
  const { description } = tagValue;
29229
29334
  const sdtContent = node2.elements.find((el) => el.name === "w:sdtContent");
29230
- const translatedContent = nodeListHandler2.handler({ ...params, nodes: sdtContent?.elements });
29335
+ const translatedContent = nodeListHandler2.handler({
29336
+ ...params,
29337
+ nodes: sdtContent?.elements,
29338
+ path: [...params.path || [], node2]
29339
+ });
29231
29340
  const result = {
29232
29341
  type: "documentSection",
29233
29342
  content: translatedContent,
@@ -29291,7 +29400,12 @@ const handleStandardNode = (params) => {
29291
29400
  el.marks.push(...marks);
29292
29401
  return el;
29293
29402
  });
29294
- const childParams = { ...params, nodes: updatedElements, parentStyleId };
29403
+ const childParams = {
29404
+ ...params,
29405
+ nodes: updatedElements,
29406
+ parentStyleId,
29407
+ path: [...params.path || [], node2]
29408
+ };
29295
29409
  const childContent = nodeListHandler2.handler(childParams);
29296
29410
  content.push(...childContent);
29297
29411
  }
@@ -29317,7 +29431,7 @@ const handler = (params) => {
29317
29431
  if (nodes.length === 0 || nodes[0].name !== "w:br") {
29318
29432
  return { nodes: [], consumed: 0 };
29319
29433
  }
29320
- const result = translator$1.encode(params);
29434
+ const result = translator$2.encode(params);
29321
29435
  if (!result) return { nodes: [], consumed: 0 };
29322
29436
  return {
29323
29437
  nodes: [result],
@@ -29357,7 +29471,11 @@ const handleBookmarkNode = (params) => {
29357
29471
  attrs[key] = value;
29358
29472
  }
29359
29473
  });
29360
- const translatedText = nodeListHandler3.handler({ ...params, nodes: textNodes });
29474
+ const translatedText = nodeListHandler3.handler({
29475
+ ...params,
29476
+ nodes: textNodes,
29477
+ path: [...params.path || [], node2]
29478
+ });
29361
29479
  translatedText.forEach((n) => {
29362
29480
  n.marks.push({
29363
29481
  type: customMark.name,
@@ -29405,7 +29523,8 @@ const handleAlternateChoice = (params) => {
29405
29523
  const contents = wpsNode.elements;
29406
29524
  const result = nodeListHandler2.handler({
29407
29525
  ...params,
29408
- nodes: contents
29526
+ nodes: contents,
29527
+ path: [...params.path || [], wpsNode]
29409
29528
  });
29410
29529
  return { nodes: result, consumed: 1 };
29411
29530
  };
@@ -29699,7 +29818,8 @@ function importCommentData({ docx, editor, converter }) {
29699
29818
  nodeListHandler: nodeListHandler2,
29700
29819
  docx,
29701
29820
  editor,
29702
- converter
29821
+ converter,
29822
+ path: [el]
29703
29823
  });
29704
29824
  const { attrs } = parsedComment[0];
29705
29825
  const paraId = attrs["w14:paraId"];
@@ -29755,7 +29875,7 @@ const handleTabNode = (params) => {
29755
29875
  if (!nodes.length || nodes[0].name !== "w:tab") {
29756
29876
  return { nodes: [], consumed: 0 };
29757
29877
  }
29758
- const node2 = translator.encode(params);
29878
+ const node2 = translator$1.encode(params);
29759
29879
  return { nodes: [node2], consumed: 1 };
29760
29880
  };
29761
29881
  const tabNodeEntityHandler = {
@@ -29800,7 +29920,8 @@ const createDocumentJson = (docx, converter, editor) => {
29800
29920
  docx,
29801
29921
  converter,
29802
29922
  editor,
29803
- lists
29923
+ lists,
29924
+ path: []
29804
29925
  });
29805
29926
  const result = {
29806
29927
  type: "doc",
@@ -29880,7 +30001,8 @@ const createNodeListHandler = (nodeHandlers) => {
29880
30001
  editor,
29881
30002
  filename,
29882
30003
  parentStyleId,
29883
- lists
30004
+ lists,
30005
+ path = []
29884
30006
  }) => {
29885
30007
  if (!elements || !elements.length) return [];
29886
30008
  const filteredElements = pruneIgnoredNodes(elements);
@@ -29905,7 +30027,8 @@ const createNodeListHandler = (nodeHandlers) => {
29905
30027
  editor,
29906
30028
  filename,
29907
30029
  parentStyleId,
29908
- lists
30030
+ lists,
30031
+ path
29909
30032
  });
29910
30033
  },
29911
30034
  { nodes: [], consumed: 0 }
@@ -30082,7 +30205,8 @@ const importHeadersFooters = (docx, converter, mainEditor) => {
30082
30205
  docx,
30083
30206
  converter,
30084
30207
  editor,
30085
- filename: currentFileName
30208
+ filename: currentFileName,
30209
+ path: []
30086
30210
  });
30087
30211
  if (!converter.headerIds.ids) converter.headerIds.ids = [];
30088
30212
  converter.headerIds.ids.push(rId);
@@ -30104,7 +30228,8 @@ const importHeadersFooters = (docx, converter, mainEditor) => {
30104
30228
  docx,
30105
30229
  converter,
30106
30230
  editor,
30107
- filename: currentFileName
30231
+ filename: currentFileName,
30232
+ path: []
30108
30233
  });
30109
30234
  if (!converter.footerIds.ids) converter.footerIds.ids = [];
30110
30235
  converter.footerIds.ids.push(rId);
@@ -30359,7 +30484,7 @@ const _SuperConverter = class _SuperConverter {
30359
30484
  return;
30360
30485
  }
30361
30486
  }
30362
- static updateDocumentVersion(docx = this.convertedXml, version = "0.17.0") {
30487
+ static updateDocumentVersion(docx = this.convertedXml, version = "0.17.1") {
30363
30488
  const customLocation = "docProps/custom.xml";
30364
30489
  if (!docx[customLocation]) {
30365
30490
  docx[customLocation] = generateCustomXml();
@@ -30844,7 +30969,7 @@ function storeSuperdocVersion(docx) {
30844
30969
  function generateCustomXml() {
30845
30970
  return DEFAULT_CUSTOM_XML;
30846
30971
  }
30847
- function generateSuperdocVersion(pid = 2, version = "0.17.0") {
30972
+ function generateSuperdocVersion(pid = 2, version = "0.17.1") {
30848
30973
  return {
30849
30974
  type: "element",
30850
30975
  name: "property",
@@ -30911,8 +31036,8 @@ export {
30911
31036
  readFromClipboard as aB,
30912
31037
  handleClipboardPaste as aC,
30913
31038
  getFileObject as aD,
30914
- translator as aE,
30915
- translator$1 as aF,
31039
+ translator$1 as aE,
31040
+ translator$2 as aF,
30916
31041
  _sfc_main as aG,
30917
31042
  isActive as aa,
30918
31043
  unflattenListsInHtml as ab,