@harbour-enterprises/superdoc 0.20.0-next.9 → 0.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/dist/chunks/{PdfViewer-BqGjx7hC.cjs → PdfViewer-BLwxuMWh.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-BZlsmhsJ.es.js → PdfViewer-t_JS3Mbo.es.js} +1 -1
  3. package/dist/chunks/{index-DPzgGSfg.cjs → index-CBTSdULo.cjs} +2 -2
  4. package/dist/chunks/{index-4GToG3C3.es.js → index-Vp2WxlNm.es.js} +2 -2
  5. package/dist/chunks/{super-editor.es-BkxUKZfn.cjs → super-editor.es-Cten5oWF.cjs} +2494 -3327
  6. package/dist/chunks/{super-editor.es-DqX3Ipsk.es.js → super-editor.es-DGV2_J23.es.js} +2494 -3327
  7. package/dist/core/SuperDoc.d.ts.map +1 -1
  8. package/dist/style.css +0 -38
  9. package/dist/super-editor/ai-writer.es.js +2 -2
  10. package/dist/super-editor/chunks/{converter-C6YOTAXG.js → converter-Dq0PLazx.js} +1092 -1625
  11. package/dist/super-editor/chunks/{docx-zipper-CSiwWpmr.js → docx-zipper-jT0gaoep.js} +2 -2
  12. package/dist/super-editor/chunks/{editor-chVid4VD.js → editor-BEtv1kuN.js} +1046 -1335
  13. package/dist/super-editor/chunks/{toolbar-ancqgN0p.js → toolbar-CJfSHfLU.js} +2 -2
  14. package/dist/super-editor/converter.es.js +1 -1
  15. package/dist/super-editor/docx-zipper.es.js +2 -2
  16. package/dist/super-editor/editor.es.js +3 -3
  17. package/dist/super-editor/file-zipper.es.js +1 -1
  18. package/dist/super-editor/src/core/helpers/index.d.ts +0 -1
  19. package/dist/super-editor/src/core/super-converter/exporter.d.ts +1 -7
  20. package/dist/super-editor/src/core/super-converter/helpers.d.ts +0 -2
  21. package/dist/super-editor/src/core/super-converter/v2/importer/imageImporter.d.ts +1 -1
  22. package/dist/super-editor/src/core/super-converter/v2/importer/tableImporter.d.ts +22 -0
  23. package/dist/super-editor/src/core/super-converter/v3/handlers/index.d.ts +0 -2
  24. package/dist/super-editor/src/core/super-converter/v3/handlers/utils.d.ts +3 -10
  25. package/dist/super-editor/src/core/super-converter/v3/handlers/w/p/helpers/w-p-helpers.d.ts +1 -1
  26. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tc/helpers/legacy-handle-table-cell-node.d.ts +1 -1
  27. package/dist/super-editor/src/core/super-converter/v3/node-translator/node-translator.d.ts +1 -11
  28. package/dist/super-editor/src/extensions/block-node/block-node.d.ts +5 -30
  29. package/dist/super-editor/src/extensions/bold/bold.d.ts +0 -20
  30. package/dist/super-editor/src/extensions/bullet-list/bullet-list.d.ts +0 -12
  31. package/dist/super-editor/src/extensions/color/color.d.ts +0 -26
  32. package/dist/super-editor/src/extensions/content-block/content-block.d.ts +0 -30
  33. package/dist/super-editor/src/extensions/custom-selection/custom-selection.d.ts +0 -16
  34. package/dist/super-editor/src/extensions/document/document.d.ts +0 -26
  35. package/dist/super-editor/src/extensions/dropcursor/dropcursor.d.ts +0 -26
  36. package/dist/super-editor/src/extensions/font-family/font-family.d.ts +0 -29
  37. package/dist/super-editor/src/extensions/font-size/font-size.d.ts +0 -21
  38. package/dist/super-editor/src/extensions/format-commands/format-commands.d.ts +0 -9
  39. package/dist/super-editor/src/extensions/gapcursor/gapcursor.d.ts +0 -9
  40. package/dist/super-editor/src/extensions/heading/heading.d.ts +6 -12
  41. package/dist/super-editor/src/extensions/highlight/highlight.d.ts +0 -20
  42. package/dist/super-editor/src/extensions/history/history.d.ts +15 -7
  43. package/dist/super-editor/src/extensions/image/image.d.ts +0 -78
  44. package/dist/super-editor/src/extensions/image/imageHelpers/imagePlaceholderPlugin.d.ts +5 -0
  45. package/dist/super-editor/src/extensions/image/imageHelpers/index.d.ts +1 -3
  46. package/dist/super-editor/src/extensions/image/imageHelpers/processUploadedImage.d.ts +2 -2
  47. package/dist/super-editor/src/extensions/image/imageHelpers/startImageUpload.d.ts +23 -18
  48. package/dist/super-editor/src/extensions/italic/italic.d.ts +0 -10
  49. package/dist/super-editor/src/extensions/line-break/line-break.d.ts +0 -43
  50. package/dist/super-editor/src/extensions/line-height/line-height.d.ts +0 -22
  51. package/dist/super-editor/src/extensions/link/link.d.ts +25 -53
  52. package/dist/super-editor/src/extensions/linked-styles/linked-styles.d.ts +0 -9
  53. package/dist/super-editor/src/extensions/list-item/list-item.d.ts +0 -48
  54. package/dist/super-editor/src/extensions/mention/mention.d.ts +0 -26
  55. package/dist/super-editor/src/extensions/noderesizer/noderesizer.d.ts +0 -14
  56. package/dist/super-editor/src/extensions/ordered-list/ordered-list.d.ts +0 -35
  57. package/dist/super-editor/src/extensions/page-number/page-number.d.ts +0 -52
  58. package/dist/super-editor/src/extensions/paragraph/paragraph.d.ts +0 -49
  59. package/dist/super-editor/src/extensions/placeholder/placeholder.d.ts +0 -15
  60. package/dist/super-editor/src/extensions/popover-plugin/popover-plugin.d.ts +0 -9
  61. package/dist/super-editor/src/extensions/run-item/run-item.d.ts +0 -24
  62. package/dist/super-editor/src/extensions/search/search.d.ts +2 -11
  63. package/dist/super-editor/src/extensions/shape-container/shape-container.d.ts +0 -29
  64. package/dist/super-editor/src/extensions/shape-textbox/shape-textbox.d.ts +0 -26
  65. package/dist/super-editor/src/extensions/slash-menu/slash-menu.d.ts +0 -9
  66. package/dist/super-editor/src/extensions/strike/strike.d.ts +0 -10
  67. package/dist/super-editor/src/extensions/structured-content/document-section.d.ts +27 -46
  68. package/dist/super-editor/src/extensions/structured-content/structured-content-block.d.ts +1 -29
  69. package/dist/super-editor/src/extensions/structured-content/structured-content.d.ts +1 -29
  70. package/dist/super-editor/src/extensions/tab/tab.d.ts +0 -25
  71. package/dist/super-editor/src/extensions/table/table.d.ts +55 -376
  72. package/dist/super-editor/src/extensions/table-cell/table-cell.d.ts +0 -41
  73. package/dist/super-editor/src/extensions/table-header/table-header.d.ts +0 -22
  74. package/dist/super-editor/src/extensions/table-row/table-row.d.ts +0 -28
  75. package/dist/super-editor/src/extensions/text/text.d.ts +0 -14
  76. package/dist/super-editor/src/extensions/text-align/text-align.d.ts +0 -22
  77. package/dist/super-editor/src/extensions/text-indent/text-indent.d.ts +10 -19
  78. package/dist/super-editor/src/extensions/text-style/text-style.d.ts +0 -20
  79. package/dist/super-editor/src/extensions/text-transform/text-transform.d.ts +0 -20
  80. package/dist/super-editor/src/extensions/underline/underline.d.ts +0 -25
  81. package/dist/super-editor/style.css +0 -38
  82. package/dist/super-editor/super-editor.es.js +55 -65
  83. package/dist/super-editor/toolbar.es.js +2 -2
  84. package/dist/super-editor.cjs +1 -1
  85. package/dist/super-editor.es.js +1 -1
  86. package/dist/superdoc.cjs +2 -2
  87. package/dist/superdoc.es.js +2 -2
  88. package/dist/superdoc.umd.js +3122 -3955
  89. package/dist/superdoc.umd.js.map +1 -1
  90. package/package.json +1 -1
  91. package/dist/super-editor/src/core/helpers/updateDOMAttributes.d.ts +0 -1
  92. package/dist/super-editor/src/core/super-converter/export-helpers/pre-process-vertical-merge-cells.d.ts +0 -6
  93. package/dist/super-editor/src/core/super-converter/helpers/mediaHelpers.d.ts +0 -2
  94. package/dist/super-editor/src/core/super-converter/v3/handlers/w/bidiVisual/bidiVisual-translator.d.ts +0 -6
  95. package/dist/super-editor/src/core/super-converter/v3/handlers/w/bidiVisual/index.d.ts +0 -1
  96. package/dist/super-editor/src/core/super-converter/v3/handlers/w/bottom/bottom-translator.d.ts +0 -6
  97. package/dist/super-editor/src/core/super-converter/v3/handlers/w/bottom/index.d.ts +0 -2
  98. package/dist/super-editor/src/core/super-converter/v3/handlers/w/bottom/marginBottom-translator.d.ts +0 -6
  99. package/dist/super-editor/src/core/super-converter/v3/handlers/w/drawing/drawing-translator.d.ts +0 -6
  100. package/dist/super-editor/src/core/super-converter/v3/handlers/w/drawing/index.d.ts +0 -1
  101. package/dist/super-editor/src/core/super-converter/v3/handlers/w/end/end-translator.d.ts +0 -6
  102. package/dist/super-editor/src/core/super-converter/v3/handlers/w/end/index.d.ts +0 -2
  103. package/dist/super-editor/src/core/super-converter/v3/handlers/w/end/marginEnd-translator.d.ts +0 -6
  104. package/dist/super-editor/src/core/super-converter/v3/handlers/w/gridCol/gridCol-translator.d.ts +0 -6
  105. package/dist/super-editor/src/core/super-converter/v3/handlers/w/gridCol/index.d.ts +0 -1
  106. package/dist/super-editor/src/core/super-converter/v3/handlers/w/insideH/index.d.ts +0 -1
  107. package/dist/super-editor/src/core/super-converter/v3/handlers/w/insideH/insideH-translator.d.ts +0 -6
  108. package/dist/super-editor/src/core/super-converter/v3/handlers/w/insideV/index.d.ts +0 -1
  109. package/dist/super-editor/src/core/super-converter/v3/handlers/w/insideV/insideV-translator.d.ts +0 -6
  110. package/dist/super-editor/src/core/super-converter/v3/handlers/w/left/index.d.ts +0 -2
  111. package/dist/super-editor/src/core/super-converter/v3/handlers/w/left/left-translator.d.ts +0 -6
  112. package/dist/super-editor/src/core/super-converter/v3/handlers/w/left/marginLeft-translator.d.ts +0 -6
  113. package/dist/super-editor/src/core/super-converter/v3/handlers/w/right/index.d.ts +0 -2
  114. package/dist/super-editor/src/core/super-converter/v3/handlers/w/right/marginRight-translator.d.ts +0 -6
  115. package/dist/super-editor/src/core/super-converter/v3/handlers/w/right/right-translator.d.ts +0 -6
  116. package/dist/super-editor/src/core/super-converter/v3/handlers/w/shd/index.d.ts +0 -1
  117. package/dist/super-editor/src/core/super-converter/v3/handlers/w/shd/shd-translator.d.ts +0 -6
  118. package/dist/super-editor/src/core/super-converter/v3/handlers/w/start/index.d.ts +0 -2
  119. package/dist/super-editor/src/core/super-converter/v3/handlers/w/start/marginStart-translator.d.ts +0 -6
  120. package/dist/super-editor/src/core/super-converter/v3/handlers/w/start/start-translator.d.ts +0 -6
  121. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tbl/index.d.ts +0 -1
  122. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tbl/tbl-translator.d.ts +0 -28
  123. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblBorders/index.d.ts +0 -1
  124. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblBorders/tblBorders-translator.d.ts +0 -6
  125. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblCaption/index.d.ts +0 -1
  126. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblCaption/tblCaption-translator.d.ts +0 -6
  127. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblCellMar/index.d.ts +0 -1
  128. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblCellMar/tblCellMar-translator.d.ts +0 -2
  129. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblDescription/index.d.ts +0 -1
  130. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblDescription/tblDescription-translator.d.ts +0 -6
  131. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblGrid/index.d.ts +0 -1
  132. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblGrid/tblGrid-helpers.d.ts +0 -5
  133. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblGrid/tblGrid-translator.d.ts +0 -5
  134. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblInd/index.d.ts +0 -1
  135. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblInd/tblInd-translator.d.ts +0 -6
  136. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblLayout/index.d.ts +0 -1
  137. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblLayout/tblLayout-translator.d.ts +0 -6
  138. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblLook/index.d.ts +0 -1
  139. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblLook/tblLook-translator.d.ts +0 -6
  140. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblOverlap/index.d.ts +0 -1
  141. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblOverlap/tblOverlap-translator.d.ts +0 -6
  142. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblPr/index.d.ts +0 -1
  143. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblPr/tblPr-translator.d.ts +0 -5
  144. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblStyle/index.d.ts +0 -1
  145. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblStyle/tblStyle-translator.d.ts +0 -6
  146. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblStyleColBandSize/index.d.ts +0 -1
  147. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblStyleColBandSize/tblStyleColBandSize-translator.d.ts +0 -6
  148. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblStyleRowBandSize/index.d.ts +0 -1
  149. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblStyleRowBandSize/tblStyleRowBandSize-translator.d.ts +0 -6
  150. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblW/index.d.ts +0 -1
  151. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblW/tblW-translator.d.ts +0 -6
  152. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblpPr/index.d.ts +0 -1
  153. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblpPr/tblpPr-translator.d.ts +0 -6
  154. package/dist/super-editor/src/core/super-converter/v3/handlers/w/top/index.d.ts +0 -2
  155. package/dist/super-editor/src/core/super-converter/v3/handlers/w/top/marginTop-translator.d.ts +0 -6
  156. package/dist/super-editor/src/core/super-converter/v3/handlers/w/top/top-translator.d.ts +0 -6
  157. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/anchor/anchor-translator.d.ts +0 -6
  158. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/anchor/helpers/handle-anchor-node.d.ts +0 -6
  159. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/anchor/helpers/translate-anchor-node.d.ts +0 -6
  160. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/anchor/index.d.ts +0 -1
  161. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/helpers/decode-image-node-helpers.d.ts +0 -18
  162. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/helpers/encode-image-node-helpers.d.ts +0 -6
  163. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/inline/helpers/handle-inline-node.d.ts +0 -6
  164. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/inline/helpers/translate-inline-node.d.ts +0 -6
  165. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/inline/index.d.ts +0 -1
  166. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/inline/inline-translator.d.ts +0 -6
  167. package/dist/super-editor/src/extensions/image/imageHelpers/fileNameUtils.d.ts +0 -3
  168. package/dist/super-editor/src/extensions/image/imageHelpers/handleBase64.d.ts +0 -1
  169. package/dist/super-editor/src/extensions/image/imageHelpers/handleUrl.d.ts +0 -2
  170. package/dist/super-editor/src/extensions/image/imageHelpers/imageRegistrationPlugin.d.ts +0 -11
  171. package/dist/super-editor/src/extensions/image/imageHelpers/rotation.d.ts +0 -4
  172. package/dist/super-editor/src/extensions/structured-content/StructuredContentBlockView.d.ts +0 -9
  173. package/dist/super-editor/src/extensions/structured-content/StructuredContentInlineView.d.ts +0 -9
  174. package/dist/super-editor/src/extensions/structured-content/StructuredContentViewBase.d.ts +0 -24
  175. package/dist/super-editor/src/tests/helpers/editor-test-utils.d.ts +0 -14
@@ -14779,25 +14779,22 @@ async function readFromClipboard(state2) {
14779
14779
  function inchesToTwips(inches) {
14780
14780
  if (inches == null) return;
14781
14781
  if (typeof inches === "string") inches = parseFloat(inches);
14782
- return Math.round(Number(inches) * 1440);
14782
+ return Math.round(inches * 1440);
14783
14783
  }
14784
14784
  function twipsToInches(twips) {
14785
14785
  if (twips == null) return;
14786
- const value = Number(twips);
14787
- if (Number.isNaN(value)) return;
14788
- return value / 1440;
14786
+ if (typeof twips === "string") twips = parseInt(twips, 10);
14787
+ return Math.round(twips / 1440 * 100) / 100;
14789
14788
  }
14790
14789
  function twipsToPixels(twips) {
14791
14790
  if (twips == null) return;
14792
- const inches = twipsToInches(twips);
14793
- if (inches == null) return;
14794
- const pixels = inches * 96;
14795
- return Math.round(pixels * 1e3) / 1e3;
14791
+ twips = twipsToInches(twips);
14792
+ return Math.round(twips * 96);
14796
14793
  }
14797
14794
  function pixelsToTwips(pixels) {
14798
14795
  if (pixels == null) return;
14799
- const inches = Number(pixels) / 96;
14800
- return inchesToTwips(inches);
14796
+ pixels = pixels / 96;
14797
+ return inchesToTwips(pixels);
14801
14798
  }
14802
14799
  function twipsToLines(twips) {
14803
14800
  if (twips == null) return;
@@ -14840,14 +14837,6 @@ function ptToTwips(pt) {
14840
14837
  if (pt == null) return;
14841
14838
  return pt * 20;
14842
14839
  }
14843
- function rotToDegrees(rot) {
14844
- if (rot == null) return;
14845
- return rot / 6e4;
14846
- }
14847
- function degreesToRot(degrees) {
14848
- if (degrees == null) return;
14849
- return degrees * 6e4;
14850
- }
14851
14840
  const getTextIndentExportValue = (indent) => {
14852
14841
  const [value, unit] = parseSizeUnit(indent);
14853
14842
  const functionsMap = {
@@ -16403,6 +16392,41 @@ const prepareCommentsXmlFilesForExport = ({ convertedXml, defs, commentsWithPara
16403
16392
  documentXml: updatedXml
16404
16393
  };
16405
16394
  };
16395
+ const getColStyleDeclaration = (minWidth, width) => {
16396
+ if (width) {
16397
+ return ["width", `${Math.max(width, minWidth)}px`];
16398
+ }
16399
+ return ["min-width", `${minWidth}px`];
16400
+ };
16401
+ const createColGroup = (node, cellMinWidth, overrideCol, overrideValue) => {
16402
+ let totalWidth = 0;
16403
+ let fixedWidth = true;
16404
+ const cols = [];
16405
+ const colsValues = [];
16406
+ const row = node.firstChild;
16407
+ if (!row) return {};
16408
+ for (let i = 0, col = 0; i < row.childCount; i++) {
16409
+ const { colspan, colwidth } = row.child(i).attrs;
16410
+ for (let j2 = 0; j2 < colspan; j2++, col++) {
16411
+ const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j2];
16412
+ totalWidth += hasWidth || cellMinWidth;
16413
+ if (!hasWidth) fixedWidth = false;
16414
+ const [prop, value] = getColStyleDeclaration(cellMinWidth, hasWidth);
16415
+ cols.push(["col", { style: `${prop}: ${value}` }]);
16416
+ colsValues.push(parseInt(value, 10));
16417
+ }
16418
+ }
16419
+ const tableWidth = fixedWidth ? `${totalWidth}px` : "";
16420
+ const tableMinWidth = fixedWidth ? "" : `${totalWidth}px`;
16421
+ const colgroup = ["colgroup", {}, ...cols];
16422
+ const colgroupValues = [...colsValues];
16423
+ return {
16424
+ colgroup,
16425
+ tableWidth,
16426
+ tableMinWidth,
16427
+ colgroupValues
16428
+ };
16429
+ };
16406
16430
  const lower16 = 65535;
16407
16431
  const factor16 = Math.pow(2, 16);
16408
16432
  function makeRecover(index, offset) {
@@ -21347,7 +21371,7 @@ const isInTable = (state2) => {
21347
21371
  };
21348
21372
  function stripHtmlStyles(html) {
21349
21373
  if (!html) return "";
21350
- const parser = new window.DOMParser();
21374
+ const parser = new DOMParser();
21351
21375
  const doc2 = parser.parseFromString(html, "text/html");
21352
21376
  const SUPPORTED_ATTRS = [
21353
21377
  "href",
@@ -21366,7 +21390,7 @@ function stripHtmlStyles(html) {
21366
21390
  "styleid"
21367
21391
  ];
21368
21392
  const cleanNode = (node) => {
21369
- if (node.nodeType !== window.Node.ELEMENT_NODE) return;
21393
+ if (node.nodeType !== Node.ELEMENT_NODE) return;
21370
21394
  [...node.attributes].forEach((attr) => {
21371
21395
  const name = attr.name.toLowerCase();
21372
21396
  const shouldKeep = SUPPORTED_ATTRS.includes(name) || name.startsWith("data-");
@@ -21399,7 +21423,7 @@ function L() {
21399
21423
  return { async: false, breaks: false, extensions: null, gfm: true, hooks: null, pedantic: false, renderer: null, silent: false, tokenizer: null, walkTokens: null };
21400
21424
  }
21401
21425
  var O = L();
21402
- function G(l3) {
21426
+ function H(l3) {
21403
21427
  O = l3;
21404
21428
  }
21405
21429
  var E = { exec: () => null };
@@ -21411,7 +21435,7 @@ function h(l3, e = "") {
21411
21435
  return n;
21412
21436
  }
21413
21437
  var m = { codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm, outputLinkReplace: /\\([\[\]])/g, indentCodeCompensation: /^(\s+)(?:```)/, beginningSpace: /^\s+/, endingHash: /#$/, startingSpaceChar: /^ /, endingSpaceChar: / $/, nonSpaceChar: /[^ ]/, newLineCharGlobal: /\n/g, tabCharGlobal: /\t/g, multipleSpaceGlobal: /\s+/g, blankLine: /^[ \t]*$/, doubleBlankLine: /\n[ \t]*\n[ \t]*$/, blockquoteStart: /^ {0,3}>/, blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g, blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm, listReplaceTabs: /^\t+/, listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g, listIsTask: /^\[[ xX]\] /, listReplaceTask: /^\[[ xX]\] +/, anyLine: /\n.*\n/, hrefBrackets: /^<(.*)>$/, tableDelimiter: /[:|]/, tableAlignChars: /^\||\| *$/g, tableRowBlankLine: /\n[ \t]*$/, tableAlignRight: /^ *-+: *$/, tableAlignCenter: /^ *:-+: *$/, tableAlignLeft: /^ *:-+ *$/, startATag: /^<a /i, endATag: /^<\/a>/i, startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i, endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i, startAngleBracket: /^</, endAngleBracket: />$/, pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/, unicodeAlphaNumeric: /[\p{L}\p{N}]/u, escapeTest: /[&<>"']/, escapeReplace: /[&<>"']/g, escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/, escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g, unescapeTest: /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, caret: /(^|[^\[])\^/g, percentDecode: /%25/g, findPipe: /\|/g, splitPipe: / \|/, slashPipe: /\\\|/g, carriageReturn: /\r\n|\r/g, spaceLine: /^ +$/gm, notSpaceStart: /^\S*/, endingNewline: /\n$/, listItemRegex: (l3) => new RegExp(`^( {0,3}${l3})((?:[ ][^\\n]*)?(?:\\n|$))`), nextBulletRegex: (l3) => new RegExp(`^ {0,${Math.min(3, l3 - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`), hrRegex: (l3) => new RegExp(`^ {0,${Math.min(3, l3 - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`), fencesBeginRegex: (l3) => new RegExp(`^ {0,${Math.min(3, l3 - 1)}}(?:\`\`\`|~~~)`), headingBeginRegex: (l3) => new RegExp(`^ {0,${Math.min(3, l3 - 1)}}#`), htmlBeginRegex: (l3) => new RegExp(`^ {0,${Math.min(3, l3 - 1)}}<(?:[a-z].*>|!--)`, "i") }, xe = /^(?:[ \t]*(?:\n|$))+/, be = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/, Re = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/, C = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/, Oe = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/, j = /(?:[*+-]|\d{1,9}[.)])/, se = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/, ie = h(se).replace(/bull/g, j).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/\|table/g, "").getRegex(), Te = h(se).replace(/bull/g, j).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(), F = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/, we = /^[^\n]+/, Q = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/, ye = h(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", Q).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(), Pe = h(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, j).getRegex(), v = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul", U = /<!--(?:-?>|[\s\S]*?(?:-->|$))/, Se = h("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))", "i").replace("comment", U).replace("tag", v).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(), oe = h(F).replace("hr", C).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", v).getRegex(), $e = h(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", oe).getRegex(), K = { blockquote: $e, code: be, def: ye, fences: Re, heading: Oe, hr: C, html: Se, lheading: ie, list: Pe, newline: xe, paragraph: oe, table: E, text: we }, re = h("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", C).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("blockquote", " {0,3}>").replace("code", "(?: {4}| {0,3} )[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", v).getRegex(), _e = { ...K, lheading: Te, table: re, paragraph: h(F).replace("hr", C).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", re).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", v).getRegex() }, Le = { ...K, html: h(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment", U).replace(/tag/g, "(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(), def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/, heading: /^(#{1,6})(.*)(?:\n+|$)/, fences: E, lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/, paragraph: h(F).replace("hr", C).replace("heading", ` *#{1,6} *[^
21414
- ]`).replace("lheading", ie).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex() }, Me = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, ze = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/, ae = /^( {2,}|\\)\n(?!\s*$)/, Ae = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/, D = /[\p{P}\p{S}]/u, W = /[\s\p{P}\p{S}]/u, le = /[^\s\p{P}\p{S}]/u, Ee = h(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, W).getRegex(), ue = /(?!~)[\p{P}\p{S}]/u, Ce = /(?!~)[\s\p{P}\p{S}]/u, Ie = /(?:[^\s\p{P}\p{S}]|~)/u, Be = /\[[^\[\]]*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)|`[^`]*?`|<(?! )[^<>]*?>/g, pe = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/, qe = h(pe, "u").replace(/punct/g, D).getRegex(), ve = h(pe, "u").replace(/punct/g, ue).getRegex(), ce = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)", De = h(ce, "gu").replace(/notPunctSpace/g, le).replace(/punctSpace/g, W).replace(/punct/g, D).getRegex(), He = h(ce, "gu").replace(/notPunctSpace/g, Ie).replace(/punctSpace/g, Ce).replace(/punct/g, ue).getRegex(), Ze = h("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)", "gu").replace(/notPunctSpace/g, le).replace(/punctSpace/g, W).replace(/punct/g, D).getRegex(), Ge = h(/\\(punct)/, "gu").replace(/punct/g, D).getRegex(), Ne = h(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme", /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email", /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(), je = h(U).replace("(?:-->|$)", "-->").getRegex(), Fe = h("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment", je).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(), q = /(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`[^`]*`|[^\[\]\\`])*?/, Qe = h(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label", q).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(), he$3 = h(/^!?\[(label)\]\[(ref)\]/).replace("label", q).replace("ref", Q).getRegex(), de = h(/^!?\[(ref)\](?:\[\])?/).replace("ref", Q).getRegex(), Ue = h("reflink|nolink(?!\\()", "g").replace("reflink", he$3).replace("nolink", de).getRegex(), X = { _backpedal: E, anyPunctuation: Ge, autolink: Ne, blockSkip: Be, br: ae, code: ze, del: E, emStrongLDelim: qe, emStrongRDelimAst: De, emStrongRDelimUnd: Ze, escape: Me, link: Qe, nolink: de, punctuation: Ee, reflink: he$3, reflinkSearch: Ue, tag: Fe, text: Ae, url: E }, Ke = { ...X, link: h(/^!?\[(label)\]\((.*?)\)/).replace("label", q).getRegex(), reflink: h(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", q).getRegex() }, N = { ...X, emStrongRDelimAst: He, emStrongLDelim: ve, url: h(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/, "i").replace("email", /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(), _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/, del: /^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/, text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/ }, We = { ...N, br: h(ae).replace("{2,}", "*").getRegex(), text: h(N.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex() }, I = { normal: K, gfm: _e, pedantic: Le }, M = { normal: X, gfm: N, breaks: We, pedantic: Ke };
21438
+ ]`).replace("lheading", ie).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex() }, Me = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, ze = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/, ae = /^( {2,}|\\)\n(?!\s*$)/, Ae = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/, D = /[\p{P}\p{S}]/u, W = /[\s\p{P}\p{S}]/u, le = /[^\s\p{P}\p{S}]/u, Ee = h(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, W).getRegex(), ue = /(?!~)[\p{P}\p{S}]/u, Ce = /(?!~)[\s\p{P}\p{S}]/u, Ie = /(?:[^\s\p{P}\p{S}]|~)/u, Be = /\[[^\[\]]*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)|`[^`]*?`|<(?! )[^<>]*?>/g, pe = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/, qe = h(pe, "u").replace(/punct/g, D).getRegex(), ve = h(pe, "u").replace(/punct/g, ue).getRegex(), ce = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)", De = h(ce, "gu").replace(/notPunctSpace/g, le).replace(/punctSpace/g, W).replace(/punct/g, D).getRegex(), Ze = h(ce, "gu").replace(/notPunctSpace/g, Ie).replace(/punctSpace/g, Ce).replace(/punct/g, ue).getRegex(), Ge = h("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)", "gu").replace(/notPunctSpace/g, le).replace(/punctSpace/g, W).replace(/punct/g, D).getRegex(), He = h(/\\(punct)/, "gu").replace(/punct/g, D).getRegex(), Ne = h(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme", /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email", /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(), je = h(U).replace("(?:-->|$)", "-->").getRegex(), Fe = h("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment", je).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(), q = /(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`[^`]*`|[^\[\]\\`])*?/, Qe = h(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label", q).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(), he$3 = h(/^!?\[(label)\]\[(ref)\]/).replace("label", q).replace("ref", Q).getRegex(), de = h(/^!?\[(ref)\](?:\[\])?/).replace("ref", Q).getRegex(), Ue = h("reflink|nolink(?!\\()", "g").replace("reflink", he$3).replace("nolink", de).getRegex(), X = { _backpedal: E, anyPunctuation: He, autolink: Ne, blockSkip: Be, br: ae, code: ze, del: E, emStrongLDelim: qe, emStrongRDelimAst: De, emStrongRDelimUnd: Ge, escape: Me, link: Qe, nolink: de, punctuation: Ee, reflink: he$3, reflinkSearch: Ue, tag: Fe, text: Ae, url: E }, Ke = { ...X, link: h(/^!?\[(label)\]\((.*?)\)/).replace("label", q).getRegex(), reflink: h(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", q).getRegex() }, N = { ...X, emStrongRDelimAst: Ze, emStrongLDelim: ve, url: h(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/, "i").replace("email", /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(), _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/, del: /^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/, text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/ }, We = { ...N, br: h(ae).replace("{2,}", "*").getRegex(), text: h(N.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex() }, I = { normal: K, gfm: _e, pedantic: Le }, M = { normal: X, gfm: N, breaks: We, pedantic: Ke };
21415
21439
  var Xe = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }, ke = (l3) => Xe[l3];
21416
21440
  function w(l3, e) {
21417
21441
  if (e) {
@@ -21569,15 +21593,15 @@ ${c}` : c;
21569
21593
  if (!(t = s.exec(e)) || this.rules.block.hr.test(e)) break;
21570
21594
  p = t[0], e = e.substring(p.length);
21571
21595
  let f = t[2].split(`
21572
- `, 1)[0].replace(this.rules.other.listReplaceTabs, (H) => " ".repeat(3 * H.length)), k = e.split(`
21596
+ `, 1)[0].replace(this.rules.other.listReplaceTabs, (Z) => " ".repeat(3 * Z.length)), k = e.split(`
21573
21597
  `, 1)[0], x = !f.trim(), g = 0;
21574
21598
  if (this.options.pedantic ? (g = 2, c = f.trimStart()) : x ? g = t[1].length + 1 : (g = t[2].search(this.rules.other.nonSpaceChar), g = g > 4 ? 1 : g, c = f.slice(g), g += t[1].length), x && this.rules.other.blankLine.test(k) && (p += k + `
21575
21599
  `, e = e.substring(k.length + 1), u = true), !u) {
21576
- let H = this.rules.other.nextBulletRegex(g), ee = this.rules.other.hrRegex(g), te = this.rules.other.fencesBeginRegex(g), ne = this.rules.other.headingBeginRegex(g), me = this.rules.other.htmlBeginRegex(g);
21600
+ let Z = this.rules.other.nextBulletRegex(g), ee = this.rules.other.hrRegex(g), te = this.rules.other.fencesBeginRegex(g), ne = this.rules.other.headingBeginRegex(g), me = this.rules.other.htmlBeginRegex(g);
21577
21601
  for (; e; ) {
21578
- let Z = e.split(`
21602
+ let G = e.split(`
21579
21603
  `, 1)[0], A;
21580
- if (k = Z, this.options.pedantic ? (k = k.replace(this.rules.other.listReplaceNesting, " "), A = k) : A = k.replace(this.rules.other.tabCharGlobal, " "), te.test(k) || ne.test(k) || me.test(k) || H.test(k) || ee.test(k)) break;
21604
+ if (k = G, this.options.pedantic ? (k = k.replace(this.rules.other.listReplaceNesting, " "), A = k) : A = k.replace(this.rules.other.tabCharGlobal, " "), te.test(k) || ne.test(k) || me.test(k) || Z.test(k) || ee.test(k)) break;
21581
21605
  if (A.search(this.rules.other.nonSpaceChar) >= g || !k.trim()) c += `
21582
21606
  ` + A.slice(g);
21583
21607
  else {
@@ -21585,8 +21609,8 @@ ${c}` : c;
21585
21609
  c += `
21586
21610
  ` + k;
21587
21611
  }
21588
- !x && !k.trim() && (x = true), p += Z + `
21589
- `, e = e.substring(Z.length + 1), f = A.slice(g);
21612
+ !x && !k.trim() && (x = true), p += G + `
21613
+ `, e = e.substring(G.length + 1), f = A.slice(g);
21590
21614
  }
21591
21615
  }
21592
21616
  i.loose || (o ? i.loose = true : this.rules.other.doubleBlankLine.test(p) && (o = true));
@@ -21893,7 +21917,6 @@ var b = class l {
21893
21917
  }
21894
21918
  for (; (r = this.tokenizer.rules.inline.anyPunctuation.exec(n)) != null; ) n = n.slice(0, r.index) + "++" + n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
21895
21919
  for (; (r = this.tokenizer.rules.inline.blockSkip.exec(n)) != null; ) n = n.slice(0, r.index) + "[" + "a".repeat(r[0].length - 2) + "]" + n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
21896
- n = this.options.hooks?.emStrongMask?.call({ lexer: this }, n) ?? n;
21897
21920
  let i = false, s = "";
21898
21921
  for (; e; ) {
21899
21922
  i || (s = ""), i = false;
@@ -22088,7 +22111,7 @@ ${e}</tr>
22088
22111
  return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : "escaped" in e && e.escaped ? e.text : w(e.text);
22089
22112
  }
22090
22113
  };
22091
- var $ = class {
22114
+ var S = class {
22092
22115
  strong({ text: e }) {
22093
22116
  return e;
22094
22117
  }
@@ -22122,7 +22145,7 @@ var R = class l2 {
22122
22145
  __publicField(this, "options");
22123
22146
  __publicField(this, "renderer");
22124
22147
  __publicField(this, "textRenderer");
22125
- this.options = e || O, this.options.renderer = this.options.renderer || new P(), this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new $();
22148
+ this.options = e || O, this.options.renderer = this.options.renderer || new P(), this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new S();
22126
22149
  }
22127
22150
  static parse(e, t) {
22128
22151
  return new l2(t).parse(e);
@@ -22262,7 +22285,7 @@ var R = class l2 {
22262
22285
  return n;
22263
22286
  }
22264
22287
  };
22265
- var S = (_a = class {
22288
+ var $ = (_a = class {
22266
22289
  constructor(e) {
22267
22290
  __publicField(this, "options");
22268
22291
  __publicField(this, "block");
@@ -22277,16 +22300,13 @@ var S = (_a = class {
22277
22300
  processAllTokens(e) {
22278
22301
  return e;
22279
22302
  }
22280
- emStrongMask(e) {
22281
- return e;
22282
- }
22283
22303
  provideLexer() {
22284
22304
  return this.block ? b.lex : b.lexInline;
22285
22305
  }
22286
22306
  provideParser() {
22287
22307
  return this.block ? R.parse : R.parseInline;
22288
22308
  }
22289
- }, __publicField(_a, "passThroughHooks", /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens", "emStrongMask"])), __publicField(_a, "passThroughHooksRespectAsync", /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens"])), _a);
22309
+ }, __publicField(_a, "passThroughHooks", /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens"])), _a);
22290
22310
  var B = class {
22291
22311
  constructor(...e) {
22292
22312
  __publicField(this, "defaults", L());
@@ -22295,10 +22315,10 @@ var B = class {
22295
22315
  __publicField(this, "parseInline", this.parseMarkdown(false));
22296
22316
  __publicField(this, "Parser", R);
22297
22317
  __publicField(this, "Renderer", P);
22298
- __publicField(this, "TextRenderer", $);
22318
+ __publicField(this, "TextRenderer", S);
22299
22319
  __publicField(this, "Lexer", b);
22300
22320
  __publicField(this, "Tokenizer", y);
22301
- __publicField(this, "Hooks", S);
22321
+ __publicField(this, "Hooks", $);
22302
22322
  this.use(...e);
22303
22323
  }
22304
22324
  walkTokens(e, t) {
@@ -22371,13 +22391,13 @@ var B = class {
22371
22391
  r.tokenizer = i;
22372
22392
  }
22373
22393
  if (n.hooks) {
22374
- let i = this.defaults.hooks || new S();
22394
+ let i = this.defaults.hooks || new $();
22375
22395
  for (let s in n.hooks) {
22376
22396
  if (!(s in i)) throw new Error(`hook '${s}' does not exist`);
22377
22397
  if (["options", "block"].includes(s)) continue;
22378
22398
  let o = s, a = n.hooks[o], u = i[o];
22379
- S.passThroughHooks.has(s) ? i[o] = (p) => {
22380
- if (this.defaults.async && S.passThroughHooksRespectAsync.has(s)) return Promise.resolve(a.call(i, p)).then((f) => u.call(i, f));
22399
+ $.passThroughHooks.has(s) ? i[o] = (p) => {
22400
+ if (this.defaults.async) return Promise.resolve(a.call(i, p)).then((f) => u.call(i, f));
22381
22401
  let c = a.call(i, p);
22382
22402
  return u.call(i, c);
22383
22403
  } : i[o] = (...p) => {
@@ -22443,12 +22463,12 @@ function d(l3, e) {
22443
22463
  return _.parse(l3, e);
22444
22464
  }
22445
22465
  d.options = d.setOptions = function(l3) {
22446
- return _.setOptions(l3), d.defaults = _.defaults, G(d.defaults), d;
22466
+ return _.setOptions(l3), d.defaults = _.defaults, H(d.defaults), d;
22447
22467
  };
22448
22468
  d.getDefaults = L;
22449
22469
  d.defaults = O;
22450
22470
  d.use = function(...l3) {
22451
- return _.use(...l3), d.defaults = _.defaults, G(d.defaults), d;
22471
+ return _.use(...l3), d.defaults = _.defaults, H(d.defaults), d;
22452
22472
  };
22453
22473
  d.walkTokens = function(l3, e) {
22454
22474
  return _.walkTokens(l3, e);
@@ -22457,11 +22477,11 @@ d.parseInline = _.parseInline;
22457
22477
  d.Parser = R;
22458
22478
  d.parser = R.parse;
22459
22479
  d.Renderer = P;
22460
- d.TextRenderer = $;
22480
+ d.TextRenderer = S;
22461
22481
  d.Lexer = b;
22462
22482
  d.lexer = b.lex;
22463
22483
  d.Tokenizer = y;
22464
- d.Hooks = S;
22484
+ d.Hooks = $;
22465
22485
  d.parse = d;
22466
22486
  d.options;
22467
22487
  d.setOptions;
@@ -22509,23 +22529,6 @@ function processContent({ content, type: type2, schema }) {
22509
22529
  }
22510
22530
  return doc2;
22511
22531
  }
22512
- const defaultBooleans = ["required", "readonly", "disabled", "checked", "multiple", "autofocus"];
22513
- function updateDOMAttributes(dom, attrs = {}, options = {}) {
22514
- const customBooleans = options.customBooleans || [];
22515
- const booleans = [...defaultBooleans, ...customBooleans];
22516
- Object.entries(attrs).forEach(([key, value]) => {
22517
- if (booleans.includes(key)) {
22518
- if (!value) dom.removeAttribute(key);
22519
- else dom.setAttribute(key, "");
22520
- return;
22521
- }
22522
- if (value != null) {
22523
- dom.setAttribute(key, value);
22524
- } else {
22525
- dom.removeAttribute(key);
22526
- }
22527
- });
22528
- }
22529
22532
  const helpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
22530
22533
  __proto__: null,
22531
22534
  chainableEditorState,
@@ -22558,8 +22561,7 @@ const helpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
22558
22561
  isNodeActive,
22559
22562
  isTextSelection,
22560
22563
  posToDOMRect,
22561
- processContent,
22562
- updateDOMAttributes
22564
+ processContent
22563
22565
  }, Symbol.toStringTag, { value: "Module" }));
22564
22566
  const generateNewListDefinition = ({ numId, listType, level, start, text, fmt, editor }) => {
22565
22567
  if (typeof listType === "string") listType = editor.schema.nodes[listType];
@@ -24301,37 +24303,37 @@ const _NodeTranslator = class _NodeTranslator {
24301
24303
  /** @type {typeof TranslatorTypes} */
24302
24304
  __publicField(_NodeTranslator, "translatorTypes", TranslatorTypes);
24303
24305
  let NodeTranslator = _NodeTranslator;
24304
- const encode$r = (attributes) => {
24306
+ const encode$j = (attributes) => {
24305
24307
  return attributes["w:type"];
24306
24308
  };
24307
- const decode$r = (attrs) => {
24309
+ const decode$j = (attrs) => {
24308
24310
  const { lineBreakType } = attrs;
24309
24311
  return lineBreakType;
24310
24312
  };
24311
24313
  const attrConfig$b = Object.freeze({
24312
24314
  xmlName: "w:type",
24313
24315
  sdName: "lineBreakType",
24314
- encode: encode$r,
24315
- decode: decode$r
24316
+ encode: encode$j,
24317
+ decode: decode$j
24316
24318
  });
24317
- const encode$q = (attributes) => {
24319
+ const encode$i = (attributes) => {
24318
24320
  const xmlAttrValue = attributes["w:clear"];
24319
24321
  return xmlAttrValue;
24320
24322
  };
24321
- const decode$q = (attrs) => {
24323
+ const decode$i = (attrs) => {
24322
24324
  const { clear } = attrs;
24323
24325
  return clear;
24324
24326
  };
24325
24327
  const attrConfig$a = Object.freeze({
24326
24328
  xmlName: "w:clear",
24327
24329
  sdName: "clear",
24328
- encode: encode$q,
24329
- decode: decode$q
24330
+ encode: encode$i,
24331
+ decode: decode$i
24330
24332
  });
24331
- const validXmlAttributes$9 = [attrConfig$b, attrConfig$a];
24332
- const XML_NODE_NAME$f = "w:br";
24333
- const SD_NODE_NAME$a = "lineBreak";
24334
- const encode$p = (_2, encodedAttrs) => {
24333
+ const validXmlAttributes$6 = [attrConfig$b, attrConfig$a];
24334
+ const XML_NODE_NAME$7 = "w:br";
24335
+ const SD_NODE_NAME$6 = "lineBreak";
24336
+ const encode$h = (_2, encodedAttrs) => {
24335
24337
  const isPageBreak = encodedAttrs?.lineBreakType === "page";
24336
24338
  const translated = {
24337
24339
  type: isPageBreak ? "hardBreak" : "lineBreak"
@@ -24341,7 +24343,7 @@ const encode$p = (_2, encodedAttrs) => {
24341
24343
  }
24342
24344
  return translated;
24343
24345
  };
24344
- const decode$p = (params, decodedAttrs) => {
24346
+ const decode$h = (params, decodedAttrs) => {
24345
24347
  const { node } = params;
24346
24348
  if (!node) return;
24347
24349
  const wBreak = { name: "w:br" };
@@ -24358,63 +24360,63 @@ const decode$p = (params, decodedAttrs) => {
24358
24360
  };
24359
24361
  return translated;
24360
24362
  };
24361
- const config$d = {
24362
- xmlName: XML_NODE_NAME$f,
24363
- sdNodeOrKeyName: SD_NODE_NAME$a,
24363
+ const config$7 = {
24364
+ xmlName: XML_NODE_NAME$7,
24365
+ sdNodeOrKeyName: SD_NODE_NAME$6,
24364
24366
  type: NodeTranslator.translatorTypes.NODE,
24365
- encode: encode$p,
24366
- decode: decode$p,
24367
- attributes: validXmlAttributes$9
24367
+ encode: encode$h,
24368
+ decode: decode$h,
24369
+ attributes: validXmlAttributes$6
24368
24370
  };
24369
- const translator$T = NodeTranslator.from(config$d);
24370
- const encode$o = (attributes) => {
24371
+ const translator$j = NodeTranslator.from(config$7);
24372
+ const encode$g = (attributes) => {
24371
24373
  return attributes["w:val"];
24372
24374
  };
24373
- const decode$o = (attrs) => {
24375
+ const decode$g = (attrs) => {
24374
24376
  const { tabSize } = attrs || {};
24375
24377
  return tabSize;
24376
24378
  };
24377
24379
  const attrConfig$9 = Object.freeze({
24378
24380
  xmlName: "w:val",
24379
24381
  sdName: "tabSize",
24380
- encode: encode$o,
24381
- decode: decode$o
24382
+ encode: encode$g,
24383
+ decode: decode$g
24382
24384
  });
24383
- const encode$n = (attributes) => {
24385
+ const encode$f = (attributes) => {
24384
24386
  return attributes["w:leader"];
24385
24387
  };
24386
- const decode$n = (attrs) => {
24388
+ const decode$f = (attrs) => {
24387
24389
  const { leader } = attrs || {};
24388
24390
  return leader;
24389
24391
  };
24390
24392
  const attrConfig$8 = Object.freeze({
24391
24393
  xmlName: "w:leader",
24392
24394
  sdName: "leader",
24393
- encode: encode$n,
24394
- decode: decode$n
24395
+ encode: encode$f,
24396
+ decode: decode$f
24395
24397
  });
24396
- const encode$m = (attributes) => {
24398
+ const encode$e = (attributes) => {
24397
24399
  return attributes["w:pos"];
24398
24400
  };
24399
- const decode$m = (attrs) => {
24401
+ const decode$e = (attrs) => {
24400
24402
  const { pos } = attrs || {};
24401
24403
  return pos;
24402
24404
  };
24403
24405
  const attrConfig$7 = Object.freeze({
24404
24406
  xmlName: "w:pos",
24405
24407
  sdName: "pos",
24406
- encode: encode$m,
24407
- decode: decode$m
24408
+ encode: encode$e,
24409
+ decode: decode$e
24408
24410
  });
24409
- const validXmlAttributes$8 = [attrConfig$9, attrConfig$7, attrConfig$8];
24410
- const XML_NODE_NAME$e = "w:tab";
24411
- const SD_NODE_NAME$9 = "tab";
24412
- const encode$l = (_2, encodedAttrs = {}) => {
24411
+ const validXmlAttributes$5 = [attrConfig$9, attrConfig$7, attrConfig$8];
24412
+ const XML_NODE_NAME$6 = "w:tab";
24413
+ const SD_NODE_NAME$5 = "tab";
24414
+ const encode$d = (_2, encodedAttrs = {}) => {
24413
24415
  const translated = { type: "tab" };
24414
24416
  if (encodedAttrs) translated.attrs = { ...encodedAttrs };
24415
24417
  return translated;
24416
24418
  };
24417
- const decode$l = (params, decodedAttrs = {}) => {
24419
+ const decode$d = (params, decodedAttrs = {}) => {
24418
24420
  const { node } = params || {};
24419
24421
  if (!node) return;
24420
24422
  const wTab = { name: "w:tab" };
@@ -24430,15 +24432,15 @@ const decode$l = (params, decodedAttrs = {}) => {
24430
24432
  }
24431
24433
  return translated;
24432
24434
  };
24433
- const config$c = {
24434
- xmlName: XML_NODE_NAME$e,
24435
- sdNodeOrKeyName: SD_NODE_NAME$9,
24435
+ const config$6 = {
24436
+ xmlName: XML_NODE_NAME$6,
24437
+ sdNodeOrKeyName: SD_NODE_NAME$5,
24436
24438
  type: NodeTranslator.translatorTypes.NODE,
24437
- encode: encode$l,
24438
- decode: decode$l,
24439
- attributes: validXmlAttributes$8
24439
+ encode: encode$d,
24440
+ decode: decode$d,
24441
+ attributes: validXmlAttributes$5
24440
24442
  };
24441
- const translator$S = NodeTranslator.from(config$c);
24443
+ const translator$i = NodeTranslator.from(config$6);
24442
24444
  const mergeTextNodes = (nodes) => {
24443
24445
  if (!nodes || !Array.isArray(nodes)) {
24444
24446
  return nodes;
@@ -24702,15 +24704,13 @@ const getParagraphIndent = (node, docx, styleId = "") => {
24702
24704
  }
24703
24705
  return indent;
24704
24706
  };
24705
- const getParagraphSpacing = (node, docx, styleId = "", marks = [], options = {}) => {
24706
- const { insideTable = false } = options;
24707
+ const getParagraphSpacing = (node, docx, styleId = "", marks = []) => {
24707
24708
  const spacing = {};
24708
- const { spacing: pDefaultSpacing = {}, spacingSource } = getDefaultParagraphStyle(docx, styleId);
24709
+ const { spacing: pDefaultSpacing = {} } = getDefaultParagraphStyle(docx, styleId);
24709
24710
  let lineSpaceAfter, lineSpaceBefore, line, lineRuleStyle;
24710
24711
  const pPr = node.elements?.find((el) => el.name === "w:pPr");
24711
24712
  const inLineSpacingTag = pPr?.elements?.find((el) => el.name === "w:spacing");
24712
24713
  const inLineSpacing = inLineSpacingTag?.attributes || {};
24713
- const hasInlineSpacing = !!Object.keys(inLineSpacing).length;
24714
24714
  const textStyleMark = marks.find((el) => el.type === "textStyle");
24715
24715
  const fontSize = textStyleMark?.attrs?.fontSize;
24716
24716
  const lineSpacing = inLineSpacing?.["w:line"] || line || pDefaultSpacing?.["w:line"];
@@ -24732,12 +24732,6 @@ const getParagraphSpacing = (node, docx, styleId = "", marks = [], options = {})
24732
24732
  if (afterAutospacing === "1" && fontSize) {
24733
24733
  spacing.lineSpaceAfter += Math.round(parseInt(fontSize) * 0.5 * 96 / 72);
24734
24734
  }
24735
- if (insideTable && !hasInlineSpacing && spacingSource === "docDefault") {
24736
- const hasExplicitSpacing = Object.keys(inLineSpacing).length > 0;
24737
- if (!hasExplicitSpacing) {
24738
- return void 0;
24739
- }
24740
- }
24741
24735
  return spacing;
24742
24736
  };
24743
24737
  const getDefaultParagraphStyle = (docx, styleId = "") => {
@@ -24778,20 +24772,9 @@ const getDefaultParagraphStyle = (docx, styleId = "") => {
24778
24772
  const { attributes: pPrByIdIndentAttr } = pPrStyleIdIndentTag;
24779
24773
  const spacingRest = isNormalAsDefault ? pPrNormalSpacingAttr || pPrDefaultSpacingAttr : pPrDefaultSpacingAttr || pPrNormalSpacingAttr;
24780
24774
  const indentRest = isNormalAsDefault ? pPrNormalIndentAttr || pPrDefaultIndentAttr : pPrDefaultIndentAttr || pPrNormalIndentAttr;
24781
- let spacingToUse = pPrByIdSpacingAttr || spacingRest;
24782
- let spacingSource = "docDefault";
24783
- if (pPrByIdSpacingAttr) {
24784
- spacingSource = "style";
24785
- } else if (spacingRest === pPrNormalSpacingAttr && pPrNormalSpacingAttr) {
24786
- spacingSource = isNormalAsDefault ? "docDefault" : "normal";
24787
- } else if (spacingRest === pPrDefaultSpacingAttr && pPrDefaultSpacingAttr) {
24788
- spacingSource = "docDefault";
24789
- }
24790
- let indentToUse = pPrByIdIndentAttr || indentRest;
24791
24775
  return {
24792
- spacing: spacingToUse,
24793
- spacingSource,
24794
- indent: indentToUse,
24776
+ spacing: pPrByIdSpacingAttr || spacingRest,
24777
+ indent: pPrByIdIndentAttr || indentRest,
24795
24778
  justify: pPrByIdJcAttr
24796
24779
  };
24797
24780
  };
@@ -24966,13 +24949,7 @@ const handleParagraphNode$1 = (params) => {
24966
24949
  }
24967
24950
  if (docx) {
24968
24951
  const defaultStyleId = node.attributes?.["w:rsidRDefault"];
24969
- const insideTable = (params.path || []).some((ancestor) => ancestor.name === "w:tc");
24970
- const spacing = getParagraphSpacing(node, docx, styleId, schemaNode.attrs.marksAttrs, {
24971
- insideTable
24972
- });
24973
- if (spacing) {
24974
- schemaNode.attrs["spacing"] = spacing;
24975
- }
24952
+ schemaNode.attrs["spacing"] = getParagraphSpacing(node, docx, styleId, schemaNode.attrs.marksAttrs);
24976
24953
  schemaNode.attrs["rsidRDefault"] = defaultStyleId;
24977
24954
  }
24978
24955
  if (docx) {
@@ -25033,91 +25010,91 @@ const handleParagraphNode$1 = (params) => {
25033
25010
  }
25034
25011
  return schemaNode;
25035
25012
  };
25036
- const encode$k = (attributes) => {
25013
+ const encode$c = (attributes) => {
25037
25014
  return attributes["w:rsidDel"];
25038
25015
  };
25039
- const decode$k = (attrs) => {
25016
+ const decode$c = (attrs) => {
25040
25017
  return attrs.rsidDel;
25041
25018
  };
25042
25019
  const attrConfig$6 = Object.freeze({
25043
25020
  xmlName: "w:rsidDel",
25044
25021
  sdName: "rsidDel",
25045
- encode: encode$k,
25046
- decode: decode$k
25022
+ encode: encode$c,
25023
+ decode: decode$c
25047
25024
  });
25048
- const encode$j = (attributes) => {
25025
+ const encode$b = (attributes) => {
25049
25026
  return attributes["w:rsidP"];
25050
25027
  };
25051
- const decode$j = (attrs) => {
25028
+ const decode$b = (attrs) => {
25052
25029
  return attrs.rsidP;
25053
25030
  };
25054
25031
  const attrConfig$5 = Object.freeze({
25055
25032
  xmlName: "w:rsidP",
25056
25033
  sdName: "rsidP",
25057
- encode: encode$j,
25058
- decode: decode$j
25034
+ encode: encode$b,
25035
+ decode: decode$b
25059
25036
  });
25060
- const encode$i = (attributes) => {
25037
+ const encode$a = (attributes) => {
25061
25038
  return attributes["w:rsidR"];
25062
25039
  };
25063
- const decode$i = (attrs) => {
25040
+ const decode$a = (attrs) => {
25064
25041
  return attrs.rsidR;
25065
25042
  };
25066
25043
  const attrConfig$4 = Object.freeze({
25067
25044
  xmlName: "w:rsidR",
25068
25045
  sdName: "rsidR",
25069
- encode: encode$i,
25070
- decode: decode$i
25046
+ encode: encode$a,
25047
+ decode: decode$a
25071
25048
  });
25072
- const encode$h = (attributes) => {
25049
+ const encode$9 = (attributes) => {
25073
25050
  return attributes["w:rsidRPr"];
25074
25051
  };
25075
- const decode$h = (attrs) => {
25052
+ const decode$9 = (attrs) => {
25076
25053
  return attrs.rsidRPr;
25077
25054
  };
25078
25055
  const attrConfig$3 = Object.freeze({
25079
25056
  xmlName: "w:rsidRPr",
25080
25057
  sdName: "rsidRPr",
25081
- encode: encode$h,
25082
- decode: decode$h
25058
+ encode: encode$9,
25059
+ decode: decode$9
25083
25060
  });
25084
- const encode$g = (attributes) => {
25061
+ const encode$8 = (attributes) => {
25085
25062
  return attributes["w:rsidRDefault"];
25086
25063
  };
25087
- const decode$g = (attrs) => {
25064
+ const decode$8 = (attrs) => {
25088
25065
  return attrs.rsidRDefault;
25089
25066
  };
25090
25067
  const attrConfig$2 = Object.freeze({
25091
25068
  xmlName: "w:rsidRDefault",
25092
25069
  sdName: "rsidRDefault",
25093
- encode: encode$g,
25094
- decode: decode$g
25070
+ encode: encode$8,
25071
+ decode: decode$8
25095
25072
  });
25096
- const encode$f = (attributes) => {
25073
+ const encode$7 = (attributes) => {
25097
25074
  return attributes["w14:paraId"];
25098
25075
  };
25099
- const decode$f = (attrs) => {
25076
+ const decode$7 = (attrs) => {
25100
25077
  return attrs.paraId;
25101
25078
  };
25102
25079
  const attrConfig$1 = Object.freeze({
25103
25080
  xmlName: "w14:paraId",
25104
25081
  sdName: "paraId",
25105
- encode: encode$f,
25106
- decode: decode$f
25082
+ encode: encode$7,
25083
+ decode: decode$7
25107
25084
  });
25108
- const encode$e = (attributes) => {
25085
+ const encode$6 = (attributes) => {
25109
25086
  return attributes["w14:textId"];
25110
25087
  };
25111
- const decode$e = (attrs) => {
25088
+ const decode$6 = (attrs) => {
25112
25089
  return attrs.textId;
25113
25090
  };
25114
25091
  const attrConfig = Object.freeze({
25115
25092
  xmlName: "w14:textId",
25116
25093
  sdName: "textId",
25117
- encode: encode$e,
25118
- decode: decode$e
25094
+ encode: encode$6,
25095
+ decode: decode$6
25119
25096
  });
25120
- const validXmlAttributes$7 = [
25097
+ const validXmlAttributes$4 = [
25121
25098
  attrConfig$1,
25122
25099
  attrConfig,
25123
25100
  attrConfig$4,
@@ -25126,9 +25103,9 @@ const validXmlAttributes$7 = [
25126
25103
  attrConfig$3,
25127
25104
  attrConfig$6
25128
25105
  ];
25129
- const XML_NODE_NAME$d = "w:p";
25130
- const SD_NODE_NAME$8 = "paragraph";
25131
- const encode$d = (params, encodedAttrs = {}) => {
25106
+ const XML_NODE_NAME$5 = "w:p";
25107
+ const SD_NODE_NAME$4 = "paragraph";
25108
+ const encode$5 = (params, encodedAttrs = {}) => {
25132
25109
  const node = handleParagraphNode$1(params);
25133
25110
  if (!node) return void 0;
25134
25111
  if (encodedAttrs && Object.keys(encodedAttrs).length) {
@@ -25136,7 +25113,7 @@ const encode$d = (params, encodedAttrs = {}) => {
25136
25113
  }
25137
25114
  return node;
25138
25115
  };
25139
- const decode$d = (params, decodedAttrs = {}) => {
25116
+ const decode$5 = (params, decodedAttrs = {}) => {
25140
25117
  const translated = translateParagraphNode(params);
25141
25118
  if (!translated) return void 0;
25142
25119
  if (decodedAttrs && Object.keys(decodedAttrs).length) {
@@ -25144,15 +25121,15 @@ const decode$d = (params, decodedAttrs = {}) => {
25144
25121
  }
25145
25122
  return translated;
25146
25123
  };
25147
- const config$b = {
25148
- xmlName: XML_NODE_NAME$d,
25149
- sdNodeOrKeyName: SD_NODE_NAME$8,
25124
+ const config$5 = {
25125
+ xmlName: XML_NODE_NAME$5,
25126
+ sdNodeOrKeyName: SD_NODE_NAME$4,
25150
25127
  type: NodeTranslator.translatorTypes.NODE,
25151
- encode: encode$d,
25152
- decode: decode$d,
25153
- attributes: validXmlAttributes$7
25128
+ encode: encode$5,
25129
+ decode: decode$5,
25130
+ attributes: validXmlAttributes$4
25154
25131
  };
25155
- const translator$R = NodeTranslator.from(config$b);
25132
+ const translator$h = NodeTranslator.from(config$5);
25156
25133
  const generateV2HandlerEntity = (handlerName, translator2) => ({
25157
25134
  handlerName,
25158
25135
  handler: (params) => {
@@ -25180,7 +25157,7 @@ function createSingleAttrPropertyHandler(xmlName, sdName = null, attrName = "w:v
25180
25157
  },
25181
25158
  decode: ({ node }) => {
25182
25159
  const value = node.attrs?.[sdName] != null ? transformDecode(node.attrs[sdName]) : void 0;
25183
- return value != null ? { name: xmlName, attributes: { [attrName]: value } } : void 0;
25160
+ return value != null ? { [attrName]: value } : void 0;
25184
25161
  }
25185
25162
  };
25186
25163
  }
@@ -25198,32 +25175,7 @@ function createMeasurementPropertyHandler(xmlName, sdName = null) {
25198
25175
  },
25199
25176
  decode: function({ node }) {
25200
25177
  const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs[sdName] || {} } });
25201
- return decodedAttrs["w:w"] != null ? { attributes: decodedAttrs } : void 0;
25202
- }
25203
- };
25204
- }
25205
- function createBorderPropertyHandler(xmlName, sdName = null) {
25206
- if (!sdName) sdName = xmlName.split(":")[1];
25207
- return {
25208
- xmlName,
25209
- sdNodeOrKeyName: sdName,
25210
- attributes: [
25211
- createAttributeHandler("w:val"),
25212
- createAttributeHandler("w:color"),
25213
- createAttributeHandler("w:themeColor"),
25214
- createAttributeHandler("w:themeTint"),
25215
- createAttributeHandler("w:themeShade"),
25216
- createAttributeHandler("w:sz", "size", parseInteger, integerToString),
25217
- createAttributeHandler("w:space", null, parseInteger, integerToString),
25218
- createAttributeHandler("w:shadow", null, parseBoolean, booleanToString),
25219
- createAttributeHandler("w:frame", null, parseBoolean, booleanToString)
25220
- ],
25221
- encode: (params, encodedAttrs) => {
25222
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
25223
- },
25224
- decode: function({ node }, context) {
25225
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs[sdName] || {} } });
25226
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
25178
+ return decodedAttrs["w:w"] != null ? decodedAttrs : void 0;
25227
25179
  }
25228
25180
  };
25229
25181
  }
@@ -25266,17 +25218,15 @@ function decodeProperties(translatorsBySdName, properties) {
25266
25218
  Object.keys(properties).forEach((key) => {
25267
25219
  const translator2 = translatorsBySdName[key];
25268
25220
  if (translator2) {
25269
- const result = translator2.decode({ node: { attrs: { [key]: properties[key] } } });
25270
- if (result != null) {
25271
- result.name = translator2.xmlName;
25272
- elements.push(result);
25221
+ const attributes = translator2.decode({ node: { attrs: { [key]: properties[key] } } });
25222
+ if (attributes != null) {
25223
+ elements.push({ name: translator2.xmlName, attributes });
25273
25224
  }
25274
25225
  }
25275
25226
  });
25276
25227
  return elements;
25277
25228
  }
25278
- const parseBoolean = (value) => value != null ? ["1", "true"].includes(value) : void 0;
25279
- const booleanToString = (value) => value != null ? value ? "1" : "0" : void 0;
25229
+ const parseBoolean = (value) => ["1", "true"].includes(value);
25280
25230
  const parseInteger = (value) => {
25281
25231
  if (value == null) return void 0;
25282
25232
  const intValue = parseInt(value, 10);
@@ -25286,53 +25236,13 @@ const integerToString = (value) => {
25286
25236
  const intValue = parseInteger(value);
25287
25237
  return intValue != void 0 ? String(intValue) : void 0;
25288
25238
  };
25289
- function preProcessVerticalMergeCells(table, { editorSchema }) {
25290
- if (!table || !Array.isArray(table.content)) {
25291
- return table;
25292
- }
25293
- const rows = table.content;
25294
- for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
25295
- const row = rows[rowIndex];
25296
- if (!row) continue;
25297
- if (!Array.isArray(row.content)) {
25298
- row.content = [];
25299
- }
25300
- for (let cellIndex = 0; cellIndex < row.content.length; cellIndex++) {
25301
- const cell = row.content[cellIndex];
25302
- if (!cell) continue;
25303
- const attrs = cell.attrs || {};
25304
- if (!attrs.rowspan || attrs.rowspan <= 1) continue;
25305
- const maxRowspan = Math.min(attrs.rowspan, rows.length - rowIndex);
25306
- for (let offset = 1; offset < maxRowspan; offset++) {
25307
- const rowToChange = rows[rowIndex + offset];
25308
- if (!rowToChange) continue;
25309
- if (!Array.isArray(rowToChange.content)) {
25310
- rowToChange.content = [];
25311
- }
25312
- const existingCell = rowToChange.content[cellIndex];
25313
- if (existingCell?.attrs?.continueMerge) continue;
25314
- const mergedCell = {
25315
- type: cell.type,
25316
- content: [editorSchema.nodes.paragraph.createAndFill().toJSON()],
25317
- attrs: {
25318
- ...cell.attrs,
25319
- rowspan: null,
25320
- continueMerge: true
25321
- }
25322
- };
25323
- rowToChange.content.splice(cellIndex, 0, mergedCell);
25324
- }
25325
- }
25326
- }
25327
- return table;
25328
- }
25329
- const translator$Q = NodeTranslator.from({
25239
+ const translator$g = NodeTranslator.from({
25330
25240
  xmlName: "w:cantSplit",
25331
25241
  sdNodeOrKeyName: "cantSplit",
25332
25242
  encode: ({ nodes }) => ["1", "true"].includes(nodes[0].attributes?.["w:val"] ?? "1"),
25333
- decode: ({ node }) => node.attrs?.cantSplit ? { attributes: {} } : void 0
25243
+ decode: ({ node }) => node.attrs?.cantSplit ? {} : void 0
25334
25244
  });
25335
- const translator$P = NodeTranslator.from({
25245
+ const translator$f = NodeTranslator.from({
25336
25246
  xmlName: "w:cnfStyle",
25337
25247
  sdNodeOrKeyName: "cnfStyle",
25338
25248
  attributes: [
@@ -25347,19 +25257,26 @@ const translator$P = NodeTranslator.from({
25347
25257
  "w:lastRowFirstColumn",
25348
25258
  "w:lastRowLastColumn",
25349
25259
  "w:oddHBand",
25350
- "w:oddVBand"
25351
- ].map((attr) => createAttributeHandler(attr, null, parseBoolean, booleanToString)).concat([createAttributeHandler("w:val")]),
25260
+ "w:oddVBand",
25261
+ "w:val"
25262
+ ].map((attr) => createAttributeHandler(attr)),
25352
25263
  encode: (_2, encodedAttrs) => {
25264
+ Object.keys(encodedAttrs).forEach((key) => {
25265
+ encodedAttrs[key] = ["1", "true"].includes(encodedAttrs[key]);
25266
+ });
25353
25267
  return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
25354
25268
  },
25355
- decode: function({ node }) {
25269
+ decode: ({ node }) => {
25356
25270
  if (!node.attrs?.cnfStyle) return;
25357
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.cnfStyle || {} } });
25358
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
25271
+ const cnfStyleAttrs = {};
25272
+ Object.entries(node.attrs.cnfStyle).forEach(([key, value]) => {
25273
+ cnfStyleAttrs[`w:${key}`] = value ? "1" : "0";
25274
+ });
25275
+ return Object.keys(cnfStyleAttrs).length > 0 ? cnfStyleAttrs : void 0;
25359
25276
  }
25360
25277
  });
25361
- const translator$O = NodeTranslator.from(createSingleAttrPropertyHandler("w:divId"));
25362
- const translator$N = NodeTranslator.from(
25278
+ const translator$e = NodeTranslator.from(createSingleAttrPropertyHandler("w:divId"));
25279
+ const translator$d = NodeTranslator.from(
25363
25280
  createSingleAttrPropertyHandler(
25364
25281
  "w:gridAfter",
25365
25282
  null,
@@ -25368,7 +25285,7 @@ const translator$N = NodeTranslator.from(
25368
25285
  (v2) => integerToString(v2)
25369
25286
  )
25370
25287
  );
25371
- const translator$M = NodeTranslator.from(
25288
+ const translator$c = NodeTranslator.from(
25372
25289
  createSingleAttrPropertyHandler(
25373
25290
  "w:gridBefore",
25374
25291
  null,
@@ -25377,21 +25294,21 @@ const translator$M = NodeTranslator.from(
25377
25294
  (v2) => integerToString(v2)
25378
25295
  )
25379
25296
  );
25380
- const translator$L = NodeTranslator.from({
25297
+ const translator$b = NodeTranslator.from({
25381
25298
  xmlName: "w:hidden",
25382
25299
  sdNodeOrKeyName: "hidden",
25383
25300
  encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
25384
- decode: ({ node }) => node.attrs.hidden ? { attributes: {} } : void 0
25301
+ decode: ({ node }) => node.attrs.hidden ? {} : void 0
25385
25302
  });
25386
- const translator$K = NodeTranslator.from(createSingleAttrPropertyHandler("w:jc", "justification"));
25387
- const translator$J = NodeTranslator.from(createMeasurementPropertyHandler("w:tblCellSpacing", "tableCellSpacing"));
25388
- const translator$I = NodeTranslator.from({
25303
+ const translator$a = NodeTranslator.from(createSingleAttrPropertyHandler("w:jc"));
25304
+ const translator$9 = NodeTranslator.from(createMeasurementPropertyHandler("w:tblCellSpacing", "cellSpacing"));
25305
+ const translator$8 = NodeTranslator.from({
25389
25306
  xmlName: "w:tblHeader",
25390
25307
  sdNodeOrKeyName: "repeatHeader",
25391
25308
  encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
25392
- decode: ({ node }) => node.attrs.repeatHeader ? { attributes: {} } : void 0
25309
+ decode: ({ node }) => node.attrs.repeatHeader ? {} : void 0
25393
25310
  });
25394
- const translator$H = NodeTranslator.from({
25311
+ const translator$7 = NodeTranslator.from({
25395
25312
  xmlName: "w:trHeight",
25396
25313
  sdNodeOrKeyName: "rowHeight",
25397
25314
  encode: ({ nodes }) => {
@@ -25415,14 +25332,14 @@ const translator$H = NodeTranslator.from({
25415
25332
  if (node.attrs.rowHeight.rule) {
25416
25333
  heightAttrs["w:hRule"] = node.attrs.rowHeight.rule;
25417
25334
  }
25418
- return Object.keys(heightAttrs).length > 0 ? { attributes: heightAttrs } : void 0;
25335
+ return Object.keys(heightAttrs).length > 0 ? heightAttrs : void 0;
25419
25336
  }
25420
25337
  });
25421
- const translator$G = NodeTranslator.from(createMeasurementPropertyHandler("w:wAfter"));
25422
- const translator$F = NodeTranslator.from(createMeasurementPropertyHandler("w:wBefore"));
25423
- const XML_NODE_NAME$c = "w:trPr";
25424
- const SD_ATTR_KEY$4 = "tableRowProperties";
25425
- const encode$c = (params) => {
25338
+ const translator$6 = NodeTranslator.from(createMeasurementPropertyHandler("w:wAfter"));
25339
+ const translator$5 = NodeTranslator.from(createMeasurementPropertyHandler("w:wBefore"));
25340
+ const XML_NODE_NAME$4 = "w:trPr";
25341
+ const SD_ATTR_KEY = "tableRowProperties";
25342
+ const encode$4 = (params) => {
25426
25343
  const { nodes } = params;
25427
25344
  const node = nodes[0];
25428
25345
  let attributes = {
@@ -25432,18 +25349,18 @@ const encode$c = (params) => {
25432
25349
  };
25433
25350
  attributes = {
25434
25351
  ...attributes,
25435
- ...encodeProperties(node, propertyTranslatorsByXmlName$2)
25352
+ ...encodeProperties(node, propertyTranslatorsByXmlName)
25436
25353
  };
25437
25354
  return {
25438
25355
  type: NodeTranslator.translatorTypes.ATTRIBUTE,
25439
- xmlName: XML_NODE_NAME$c,
25440
- sdNodeOrKeyName: SD_ATTR_KEY$4,
25356
+ xmlName: XML_NODE_NAME$4,
25357
+ sdNodeOrKeyName: SD_ATTR_KEY,
25441
25358
  attributes
25442
25359
  };
25443
25360
  };
25444
- const decode$c = (params) => {
25361
+ const decode$4 = (params) => {
25445
25362
  const { tableRowProperties = {} } = params.node.attrs || {};
25446
- const elements = decodeProperties(propertyTranslatorsBySdName$2, tableRowProperties);
25363
+ const elements = decodeProperties(propertyTranslatorsBySdName, tableRowProperties);
25447
25364
  const newNode = {
25448
25365
  name: "w:trPr",
25449
25366
  type: "element",
@@ -25452,47 +25369,47 @@ const decode$c = (params) => {
25452
25369
  };
25453
25370
  return newNode;
25454
25371
  };
25455
- const propertyTranslators$3 = [
25456
- translator$Q,
25457
- translator$P,
25458
- translator$O,
25459
- translator$N,
25460
- translator$M,
25461
- translator$L,
25462
- translator$K,
25463
- translator$J,
25464
- translator$I,
25465
- translator$H,
25466
- translator$G,
25467
- translator$F
25372
+ const propertyTranslators = [
25373
+ translator$g,
25374
+ translator$f,
25375
+ translator$e,
25376
+ translator$d,
25377
+ translator$c,
25378
+ translator$b,
25379
+ translator$a,
25380
+ translator$9,
25381
+ translator$8,
25382
+ translator$7,
25383
+ translator$6,
25384
+ translator$5
25468
25385
  ];
25469
- const propertyTranslatorsByXmlName$2 = {};
25470
- propertyTranslators$3.forEach((translator2) => {
25471
- propertyTranslatorsByXmlName$2[translator2.xmlName] = translator2;
25386
+ const propertyTranslatorsByXmlName = {};
25387
+ propertyTranslators.forEach((translator2) => {
25388
+ propertyTranslatorsByXmlName[translator2.xmlName] = translator2;
25472
25389
  });
25473
- const propertyTranslatorsBySdName$2 = {};
25474
- propertyTranslators$3.forEach((translator2) => {
25475
- propertyTranslatorsBySdName$2[translator2.sdNodeOrKeyName] = translator2;
25390
+ const propertyTranslatorsBySdName = {};
25391
+ propertyTranslators.forEach((translator2) => {
25392
+ propertyTranslatorsBySdName[translator2.sdNodeOrKeyName] = translator2;
25476
25393
  });
25477
- const config$a = {
25478
- xmlName: XML_NODE_NAME$c,
25479
- sdNodeOrKeyName: SD_ATTR_KEY$4,
25394
+ const config$4 = {
25395
+ xmlName: XML_NODE_NAME$4,
25396
+ sdNodeOrKeyName: SD_ATTR_KEY,
25480
25397
  type: NodeTranslator.translatorTypes.ATTRIBUTE,
25481
- encode: encode$c,
25482
- decode: decode$c
25398
+ encode: encode$4,
25399
+ decode: decode$4
25483
25400
  };
25484
- const translator$E = NodeTranslator.from(config$a);
25485
- const XML_NODE_NAME$b = "w:tr";
25486
- const SD_NODE_NAME$7 = "tableRow";
25487
- const validXmlAttributes$6 = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
25401
+ const translator$4 = NodeTranslator.from(config$4);
25402
+ const XML_NODE_NAME$3 = "w:tr";
25403
+ const SD_NODE_NAME$3 = "tableRow";
25404
+ const validXmlAttributes$3 = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
25488
25405
  (xmlName) => createAttributeHandler(xmlName)
25489
25406
  );
25490
- const encode$b = (params, encodedAttrs) => {
25491
- const { row } = params.extraParams;
25407
+ const encode$3 = (params, encodedAttrs) => {
25408
+ const { row, table } = params.extraParams;
25492
25409
  let tableRowProperties = {};
25493
25410
  const tPr = row.elements.find((el) => el.name === "w:trPr");
25494
25411
  if (tPr) {
25495
- ({ attributes: tableRowProperties } = translator$E.encode({
25412
+ ({ attributes: tableRowProperties } = translator$4.encode({
25496
25413
  ...params,
25497
25414
  nodes: [tPr]
25498
25415
  }));
@@ -25500,12 +25417,12 @@ const encode$b = (params, encodedAttrs) => {
25500
25417
  encodedAttrs["tableRowProperties"] = Object.freeze(tableRowProperties);
25501
25418
  encodedAttrs["rowHeight"] = twipsToPixels(tableRowProperties["rowHeight"]?.value);
25502
25419
  encodedAttrs["cantSplit"] = tableRowProperties["cantSplit"];
25503
- const { columnWidths: gridColumnWidths } = params.extraParams;
25420
+ const gridColumnWidths = _getGridColumnWidths(table);
25504
25421
  const cellNodes = row.elements.filter((el) => el.name === "w:tc");
25505
25422
  let currentColumnIndex = 0;
25506
25423
  const content = cellNodes?.map((n) => {
25507
25424
  let columnWidth = gridColumnWidths?.[currentColumnIndex] || null;
25508
- const result = translator$5.encode({
25425
+ const result = translator$2.encode({
25509
25426
  ...params,
25510
25427
  extraParams: {
25511
25428
  ...params.extraParams,
@@ -25527,7 +25444,16 @@ const encode$b = (params, encodedAttrs) => {
25527
25444
  };
25528
25445
  return newNode;
25529
25446
  };
25530
- const decode$b = (params, decodedAttrs) => {
25447
+ const _getGridColumnWidths = (tableNode) => {
25448
+ const tblGrid = tableNode.elements.find((el) => el.name === "w:tblGrid");
25449
+ if (!tblGrid) return [];
25450
+ const columnWidths = tblGrid?.elements?.flatMap((el) => {
25451
+ if (el.name !== "w:gridCol") return [];
25452
+ return twipsToPixels(el.attributes["w:w"]);
25453
+ }) || [];
25454
+ return columnWidths;
25455
+ };
25456
+ const decode$3 = (params, decodedAttrs) => {
25531
25457
  const { node } = params;
25532
25458
  const elements = translateChildNodes(params);
25533
25459
  if (node.attrs?.tableRowProperties) {
@@ -25539,7 +25465,7 @@ const decode$b = (params, decodedAttrs) => {
25539
25465
  }
25540
25466
  }
25541
25467
  tableRowProperties["cantSplit"] = node.attrs["cantSplit"];
25542
- const trPr = translator$E.decode({
25468
+ const trPr = translator$4.decode({
25543
25469
  ...params,
25544
25470
  node: { ...node, attrs: { ...node.attrs, tableRowProperties } }
25545
25471
  });
@@ -25551,428 +25477,86 @@ const decode$b = (params, decodedAttrs) => {
25551
25477
  elements
25552
25478
  };
25553
25479
  };
25554
- const config$9 = {
25555
- xmlName: XML_NODE_NAME$b,
25556
- sdNodeOrKeyName: SD_NODE_NAME$7,
25557
- type: NodeTranslator.translatorTypes.NODE,
25558
- encode: encode$b,
25559
- decode: decode$b,
25560
- attributes: validXmlAttributes$6
25561
- };
25562
- const translator$D = NodeTranslator.from(config$9);
25563
- const translator$C = NodeTranslator.from({
25564
- xmlName: "w:bidiVisual",
25565
- sdNodeOrKeyName: "rightToLeft",
25566
- encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
25567
- decode: ({ node }) => node.attrs.rightToLeft ? { attributes: {} } : void 0
25568
- });
25569
- const translator$B = NodeTranslator.from({
25570
- xmlName: "w:shd",
25571
- sdNodeOrKeyName: "shading",
25572
- attributes: [
25573
- "w:color",
25574
- "w:fill",
25575
- "w:themeColor",
25576
- "w:themeFill",
25577
- "w:themeFillShade",
25578
- "w:themeFillTint",
25579
- "w:themeShade",
25580
- "w:themeTint",
25581
- "w:val"
25582
- ].map((attr) => createAttributeHandler(attr)),
25583
- encode: (params, encodedAttrs) => {
25584
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
25585
- },
25586
- decode: function({ node }, context) {
25587
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.shading || {} } });
25588
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
25589
- }
25590
- });
25591
- const translator$A = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblCaption", "caption"));
25592
- const translator$z = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblDescription", "description"));
25593
- const translator$y = NodeTranslator.from(createMeasurementPropertyHandler("w:tblInd", "tableIndent"));
25594
- const translator$x = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblLayout", "tableLayout", "w:type"));
25595
- const translator$w = NodeTranslator.from({
25596
- xmlName: "w:tblLook",
25597
- sdNodeOrKeyName: "tblLook",
25598
- attributes: ["w:firstColumn", "w:firstRow", "w:lastColumn", "w:lastRow", "w:noHBand", "w:noVBand"].map((attr) => createAttributeHandler(attr, null, parseBoolean, booleanToString)).concat([createAttributeHandler("w:val")]),
25599
- encode: (params, encodedAttrs) => {
25600
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
25601
- },
25602
- decode: function({ node }, context) {
25603
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.tblLook || {} } });
25604
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
25605
- }
25606
- });
25607
- const translator$v = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblOverlap", "overlap"));
25608
- const translator$u = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblStyle", "tableStyleId"));
25609
- const translator$t = NodeTranslator.from(
25610
- createSingleAttrPropertyHandler("w:tblStyleColBandSize", "tableStyleColBandSize")
25611
- );
25612
- const translator$s = NodeTranslator.from(
25613
- createSingleAttrPropertyHandler("w:tblStyleRowBandSize", "tableStyleRowBandSize")
25614
- );
25615
- const translator$r = NodeTranslator.from(createMeasurementPropertyHandler("w:tblW", "tableWidth"));
25616
- const translator$q = NodeTranslator.from({
25617
- xmlName: "w:tblpPr",
25618
- sdNodeOrKeyName: "floatingTableProperties",
25619
- attributes: ["w:leftFromText", "w:rightFromText", "w:topFromText", "w:bottomFromText", "w:tblpX", "w:tblpY"].map((attr) => createAttributeHandler(attr, null, parseInteger, integerToString)).concat(["w:horzAnchor", "w:vertAnchor", "w:tblpXSpec", "w:tblpYSpec"].map((attr) => createAttributeHandler(attr))),
25620
- encode: (params, encodedAttrs) => {
25621
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
25622
- },
25623
- decode: function({ node }, context) {
25624
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.floatingTableProperties || {} } });
25625
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
25626
- }
25627
- });
25628
- const translator$p = NodeTranslator.from(createBorderPropertyHandler("w:bottom"));
25629
- const translator$o = NodeTranslator.from(createMeasurementPropertyHandler("w:bottom", "marginBottom"));
25630
- const translator$n = NodeTranslator.from(createBorderPropertyHandler("w:end"));
25631
- const translator$m = NodeTranslator.from(createMeasurementPropertyHandler("w:end", "marginEnd"));
25632
- const translator$l = NodeTranslator.from(createBorderPropertyHandler("w:insideH"));
25633
- const translator$k = NodeTranslator.from(createBorderPropertyHandler("w:insideV"));
25634
- const translator$j = NodeTranslator.from(createBorderPropertyHandler("w:left"));
25635
- const translator$i = NodeTranslator.from(createMeasurementPropertyHandler("w:left", "marginLeft"));
25636
- const translator$h = NodeTranslator.from(createBorderPropertyHandler("w:right"));
25637
- const translator$g = NodeTranslator.from(createMeasurementPropertyHandler("w:right", "marginRight"));
25638
- const translator$f = NodeTranslator.from(createBorderPropertyHandler("w:start"));
25639
- const translator$e = NodeTranslator.from(createMeasurementPropertyHandler("w:start", "marginStart"));
25640
- const translator$d = NodeTranslator.from(createBorderPropertyHandler("w:top"));
25641
- const translator$c = NodeTranslator.from(createMeasurementPropertyHandler("w:top", "marginTop"));
25642
- const XML_NODE_NAME$a = "w:tblBorders";
25643
- const SD_ATTR_KEY$3 = "borders";
25644
- const encode$a = (params) => {
25645
- const { nodes } = params;
25646
- const node = nodes[0];
25647
- const attributes = encodeProperties(node, tblBordersTranslatorsByXmlName);
25648
- return Object.keys(attributes).length > 0 ? attributes : void 0;
25649
- };
25650
- const decode$a = (params) => {
25651
- const { borders = {} } = params.node.attrs || {};
25652
- const elements = decodeProperties(tblBordersTranslatorsBySdName, borders);
25653
- const newNode = {
25654
- name: "w:tblBorders",
25655
- type: "element",
25656
- attributes: {},
25657
- elements
25658
- };
25659
- return newNode;
25660
- };
25661
- const propertyTranslators$2 = [
25662
- translator$p,
25663
- translator$n,
25664
- translator$l,
25665
- translator$k,
25666
- translator$j,
25667
- translator$h,
25668
- translator$f,
25669
- translator$d
25670
- ];
25671
- const tblBordersTranslatorsByXmlName = {};
25672
- const tblBordersTranslatorsBySdName = {};
25673
- propertyTranslators$2.forEach((translator2) => {
25674
- tblBordersTranslatorsByXmlName[translator2.xmlName] = translator2;
25675
- tblBordersTranslatorsBySdName[translator2.sdNodeOrKeyName] = translator2;
25676
- });
25677
- const translator$b = NodeTranslator.from({
25678
- xmlName: XML_NODE_NAME$a,
25679
- sdNodeOrKeyName: SD_ATTR_KEY$3,
25480
+ const config$3 = {
25481
+ xmlName: XML_NODE_NAME$3,
25482
+ sdNodeOrKeyName: SD_NODE_NAME$3,
25680
25483
  type: NodeTranslator.translatorTypes.NODE,
25681
- attributes: [],
25682
- encode: encode$a,
25683
- decode: decode$a
25684
- });
25685
- const XML_NODE_NAME$9 = "w:tblCellMar";
25686
- const SD_ATTR_KEY$2 = "cellMargins";
25687
- const encode$9 = (params) => {
25688
- const { nodes } = params;
25689
- const node = nodes[0];
25690
- const attributes = encodeProperties(node, propertyTranslatorsByXmlName$1);
25691
- return Object.keys(attributes).length > 0 ? attributes : void 0;
25692
- };
25693
- const decode$9 = (params) => {
25694
- const { cellMargins = {} } = params.node.attrs || {};
25695
- const elements = decodeProperties(propertyTranslatorsBySdName$1, cellMargins);
25696
- const newNode = {
25697
- name: XML_NODE_NAME$9,
25698
- type: "element",
25699
- attributes: {},
25700
- elements
25701
- };
25702
- return newNode;
25484
+ encode: encode$3,
25485
+ decode: decode$3,
25486
+ attributes: validXmlAttributes$3
25703
25487
  };
25704
- const propertyTranslators$1 = [
25705
- translator$o,
25706
- translator$m,
25707
- translator$i,
25708
- translator$g,
25709
- translator$e,
25710
- translator$c
25711
- ];
25712
- const propertyTranslatorsByXmlName$1 = {};
25713
- const propertyTranslatorsBySdName$1 = {};
25714
- propertyTranslators$1.forEach((translator2) => {
25715
- propertyTranslatorsByXmlName$1[translator2.xmlName] = translator2;
25716
- propertyTranslatorsBySdName$1[translator2.sdNodeOrKeyName] = translator2;
25717
- });
25718
- const translator$a = NodeTranslator.from({
25719
- xmlName: XML_NODE_NAME$9,
25720
- sdNodeOrKeyName: SD_ATTR_KEY$2,
25721
- type: NodeTranslator.translatorTypes.NODE,
25722
- attributes: [],
25723
- encode: encode$9,
25724
- decode: decode$9
25725
- });
25726
- const XML_NODE_NAME$8 = "w:tblPr";
25727
- const SD_ATTR_KEY$1 = "tableProperties";
25728
- const encode$8 = (params) => {
25488
+ const translator$3 = NodeTranslator.from(config$3);
25489
+ const handleAllTableNodes = (params) => {
25729
25490
  const { nodes } = params;
25491
+ if (nodes.length === 0) {
25492
+ return { nodes: [], consumed: 0 };
25493
+ }
25730
25494
  const node = nodes[0];
25731
- const attributes = encodeProperties(node, propertyTranslatorsByXmlName);
25732
- return {
25733
- xmlName: XML_NODE_NAME$8,
25734
- sdNodeOrKeyName: SD_ATTR_KEY$1,
25735
- attributes
25736
- };
25737
- };
25738
- const decode$8 = (params) => {
25739
- const { tableProperties = {} } = params.node.attrs || {};
25740
- const elements = decodeProperties(propertyTranslatorsBySdName, tableProperties);
25741
- const newNode = {
25742
- name: "w:tblPr",
25743
- type: "element",
25744
- attributes: {},
25745
- elements
25746
- };
25747
- return newNode;
25495
+ switch (node.name) {
25496
+ case "w:tbl":
25497
+ return { nodes: [handleTableNode(node, params)], consumed: 1 };
25498
+ }
25499
+ return { nodes: [], consumed: 0 };
25748
25500
  };
25749
- const propertyTranslators = [
25750
- translator$C,
25751
- translator$K,
25752
- translator$B,
25753
- translator$A,
25754
- translator$J,
25755
- translator$z,
25756
- translator$y,
25757
- translator$x,
25758
- translator$w,
25759
- translator$v,
25760
- translator$u,
25761
- translator$t,
25762
- translator$s,
25763
- translator$r,
25764
- translator$q,
25765
- translator$b,
25766
- translator$a
25767
- ];
25768
- const propertyTranslatorsByXmlName = {};
25769
- const propertyTranslatorsBySdName = {};
25770
- propertyTranslators.forEach((translator2) => {
25771
- propertyTranslatorsByXmlName[translator2.xmlName] = translator2;
25772
- propertyTranslatorsBySdName[translator2.sdNodeOrKeyName] = translator2;
25773
- });
25774
- const config$8 = {
25775
- xmlName: XML_NODE_NAME$8,
25776
- sdNodeOrKeyName: SD_ATTR_KEY$1,
25777
- encode: encode$8,
25778
- decode: decode$8
25501
+ const tableNodeHandlerEntity = {
25502
+ handlerName: "tableNodeHandler",
25503
+ handler: handleAllTableNodes
25779
25504
  };
25780
- const translator$9 = NodeTranslator.from(config$8);
25781
- const translator$8 = NodeTranslator.from(
25782
- createSingleAttrPropertyHandler("w:gridCol", "col", "w:w", parseInteger, integerToString)
25783
- );
25784
- const DEFAULT_COLUMN_WIDTH_PX = 100;
25785
- const normalizeTwipWidth = (value) => {
25786
- if (value == null) return null;
25787
- const numericValue = typeof value === "string" ? parseInt(value, 10) : value;
25788
- if (!Number.isFinite(numericValue) || Number.isNaN(numericValue) || numericValue <= 0) {
25789
- return null;
25505
+ function handleTableNode(node, params) {
25506
+ const { docx, nodeListHandler } = params;
25507
+ const tblPr = node.elements.find((el) => el.name === "w:tblPr");
25508
+ const tableBordersElement = tblPr.elements.find((el) => el.name === "w:tblBorders");
25509
+ const tableBorders = tableBordersElement?.elements || [];
25510
+ const { borders, rowBorders } = processTableBorders(tableBorders);
25511
+ const tblStyleTag = tblPr.elements.find((el) => el.name === "w:tblStyle");
25512
+ const tableStyleId = tblStyleTag?.attributes["w:val"];
25513
+ const attrs = { tableStyleId };
25514
+ const tableIndent = tblPr?.elements.find((el) => el.name === "w:tblInd");
25515
+ if (tableIndent) {
25516
+ const { "w:w": width, "w:type": type2 } = tableIndent.attributes;
25517
+ attrs["tableIndent"] = { width: twipsToPixels(width), type: type2 };
25518
+ }
25519
+ const tableLayout = tblPr?.elements.find((el) => el.name === "w:tblLayout");
25520
+ if (tableLayout) {
25521
+ const { "w:type": type2 } = tableLayout.attributes;
25522
+ attrs["tableLayout"] = type2;
25523
+ }
25524
+ const referencedStyles = getReferencedTableStyles(tblStyleTag, docx);
25525
+ const tblW = tblPr.elements.find((el) => el.name === "w:tblW");
25526
+ if (tblW) {
25527
+ attrs["tableWidth"] = {
25528
+ width: twipsToPixels(tblW.attributes["w:w"]),
25529
+ type: tblW.attributes["w:type"]
25530
+ };
25790
25531
  }
25791
- return numericValue;
25792
- };
25793
- const getSchemaDefaultColumnWidthPx = (params) => {
25794
- const defaultValue = params?.editor?.schema?.nodes?.tableCell?.spec?.attrs?.colwidth?.default;
25795
- if (Array.isArray(defaultValue)) {
25796
- const numericWidth = defaultValue.find((width) => typeof width === "number" && Number.isFinite(width) && width > 0);
25797
- if (numericWidth != null) return numericWidth;
25798
- } else if (typeof defaultValue === "number" && Number.isFinite(defaultValue) && defaultValue > 0) {
25799
- return defaultValue;
25532
+ const tblCellSpacing = tblPr.elements.find((el) => el.name === "w:tblCellSpacing");
25533
+ if (tblCellSpacing) {
25534
+ attrs["tableCellSpacing"] = {
25535
+ w: tblCellSpacing.attributes["w:w"],
25536
+ type: tblCellSpacing.attributes["w:type"]
25537
+ };
25538
+ attrs["borderCollapse"] = "separate";
25800
25539
  }
25801
- return DEFAULT_COLUMN_WIDTH_PX;
25802
- };
25803
- const getTableWidthPx = (params) => {
25804
- const explicitWidth = params?.node?.attrs?.tableWidth?.width;
25805
- if (typeof explicitWidth === "number" && explicitWidth > 0) return explicitWidth;
25806
- const tableWidth = params?.node?.attrs?.tableProperties?.tableWidth;
25807
- if (tableWidth?.value != null && typeof tableWidth.value === "number" && tableWidth.value > 0) {
25808
- const { value, type: type2 } = tableWidth;
25809
- if (!type2 || type2 === "auto" || type2 === "dxa") {
25810
- return twipsToPixels(value);
25811
- }
25812
- }
25813
- return null;
25814
- };
25815
- const resolveFallbackColumnWidthTwips = (params, totalColumns, cellMinWidthTwips) => {
25816
- const columnCount = Math.max(totalColumns, 1);
25817
- const defaultColumnWidthPx = getSchemaDefaultColumnWidthPx(params);
25818
- const tableWidthPx = getTableWidthPx(params);
25819
- const safeDefaultPx = Number.isFinite(defaultColumnWidthPx) && defaultColumnWidthPx > 0 ? defaultColumnWidthPx : DEFAULT_COLUMN_WIDTH_PX;
25820
- let fallbackWidthPx = safeDefaultPx;
25821
- if (typeof tableWidthPx === "number" && tableWidthPx > 0) {
25822
- fallbackWidthPx = tableWidthPx / columnCount;
25823
- }
25824
- const fallbackWidthTwips = pixelsToTwips(fallbackWidthPx);
25825
- if (!Number.isFinite(fallbackWidthTwips) || Number.isNaN(fallbackWidthTwips) || fallbackWidthTwips <= 0) {
25826
- const safeDefault = Math.max(pixelsToTwips(safeDefaultPx), cellMinWidthTwips);
25827
- return safeDefault;
25828
- }
25829
- return Math.max(fallbackWidthTwips, cellMinWidthTwips);
25830
- };
25831
- const XML_NODE_NAME$7 = "w:tblGrid";
25832
- const SD_ATTR_KEY = "grid";
25833
- const cellMinWidth = pixelsToTwips(10);
25834
- const encode$7 = (params) => {
25835
- const { nodes } = params;
25836
- const node = nodes[0];
25837
- const attributes = encodeProperties(node, { [translator$8.xmlName]: translator$8 }, true);
25838
- return {
25839
- xmlName: XML_NODE_NAME$7,
25840
- sdNodeOrKeyName: SD_ATTR_KEY,
25841
- attributes
25842
- };
25843
- };
25844
- const decode$7 = (params) => {
25845
- const { grid: rawGrid } = params.node.attrs || {};
25846
- const grid = Array.isArray(rawGrid) ? rawGrid : [];
25847
- const { firstRow = {} } = params.extraParams || {};
25848
- const cellNodes = firstRow.content?.filter((n) => n.type === "tableCell") ?? [];
25849
- const columnCountFromCells = cellNodes.reduce((count, cell) => {
25850
- const spanCount = Math.max(1, cell?.attrs?.colspan ?? 1);
25851
- return count + spanCount;
25852
- }, 0);
25853
- const totalColumns = Math.max(columnCountFromCells, grid.length);
25854
- const fallbackColumnWidthTwips = resolveFallbackColumnWidthTwips(params, totalColumns, cellMinWidth);
25855
- const elements = [];
25856
- let columnIndex = 0;
25857
- const pushColumn = (widthTwips) => {
25858
- let numericWidth = typeof widthTwips === "string" ? parseInt(widthTwips, 10) : widthTwips;
25859
- if (numericWidth == null || Number.isNaN(numericWidth) || numericWidth <= 0) {
25860
- numericWidth = fallbackColumnWidthTwips;
25861
- }
25862
- numericWidth = Math.max(numericWidth, cellMinWidth);
25863
- const decoded = translator$8.decode({
25864
- node: { type: (
25865
- /** @type {string} */
25866
- translator$8.sdNodeOrKeyName
25867
- ), attrs: { col: numericWidth } }
25868
- });
25869
- if (decoded) elements.push(decoded);
25870
- };
25871
- cellNodes.forEach((cell) => {
25872
- const { colspan = 1, colwidth } = cell?.attrs || {};
25873
- const spanCount = Math.max(1, colspan);
25874
- for (let span = 0; span < spanCount; span++) {
25875
- const cellWidthPixels = Array.isArray(colwidth) ? colwidth[span] : void 0;
25876
- const colGridAttrs = grid?.[columnIndex] || {};
25877
- const gridWidthTwips = normalizeTwipWidth(colGridAttrs.col);
25878
- const gridWidthPixels = gridWidthTwips != null ? twipsToPixels(gridWidthTwips) : null;
25879
- let cellWidthTwips;
25880
- if (cellWidthPixels != null) {
25881
- if (gridWidthTwips != null && gridWidthPixels === cellWidthPixels) {
25882
- cellWidthTwips = gridWidthTwips;
25883
- } else {
25884
- cellWidthTwips = pixelsToTwips(cellWidthPixels);
25885
- }
25886
- } else if (gridWidthTwips != null) {
25887
- cellWidthTwips = gridWidthTwips;
25888
- } else {
25889
- cellWidthTwips = fallbackColumnWidthTwips;
25890
- }
25891
- pushColumn(cellWidthTwips);
25892
- columnIndex++;
25893
- }
25894
- });
25895
- while (columnIndex < grid.length) {
25896
- const gridWidthTwips = normalizeTwipWidth(grid[columnIndex]?.col);
25897
- pushColumn(gridWidthTwips);
25898
- columnIndex++;
25899
- }
25900
- const newNode = {
25901
- name: XML_NODE_NAME$7,
25902
- attributes: {},
25903
- elements
25904
- };
25905
- return newNode;
25906
- };
25907
- const config$7 = {
25908
- xmlName: XML_NODE_NAME$7,
25909
- sdNodeOrKeyName: SD_ATTR_KEY,
25910
- encode: encode$7,
25911
- decode: decode$7
25912
- };
25913
- const translator$7 = NodeTranslator.from(config$7);
25914
- const XML_NODE_NAME$6 = "w:tbl";
25915
- const SD_NODE_NAME$6 = "table";
25916
- const encode$6 = (params, encodedAttrs) => {
25917
- const { nodes } = params;
25918
- const node = nodes[0];
25919
- const tblPr = node.elements.find((el) => el.name === "w:tblPr");
25920
- if (tblPr) {
25921
- const encodedProperties = translator$9.encode({ ...params, nodes: [tblPr] });
25922
- encodedAttrs["tableProperties"] = encodedProperties?.attributes || {};
25923
- }
25924
- const tblGrid = node.elements.find((el) => el.name === "w:tblGrid");
25925
- if (tblGrid) {
25926
- encodedAttrs["grid"] = translator$7.encode({ ...params, nodes: [tblGrid] }).attributes;
25927
- }
25928
- [
25929
- "tableStyleId",
25930
- "justification",
25931
- "tableLayout",
25932
- ["tableIndent", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
25933
- ["tableWidth", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
25934
- ["tableCellSpacing", ({ value, type: type2 }) => ({ w: String(value), type: type2 })]
25935
- ].forEach((prop) => {
25936
- let key;
25937
- let transform;
25938
- if (Array.isArray(prop)) {
25939
- [key, transform] = prop;
25940
- } else {
25941
- key = prop;
25942
- transform = (v2) => v2;
25943
- }
25944
- if (encodedAttrs.tableProperties && encodedAttrs.tableProperties[key]) {
25945
- encodedAttrs[key] = transform(encodedAttrs.tableProperties[key]);
25946
- }
25947
- });
25948
- if (encodedAttrs.tableCellSpacing) {
25949
- encodedAttrs["borderCollapse"] = "separate";
25950
- }
25951
- const { borders, rowBorders } = _processTableBorders(encodedAttrs.tableProperties?.borders || {});
25952
- const referencedStyles = _getReferencedTableStyles(encodedAttrs.tableStyleId, params);
25953
- if (referencedStyles?.cellMargins && !encodedAttrs.tableProperties?.cellMargins) {
25954
- encodedAttrs.tableProperties = {
25955
- ...encodedAttrs.tableProperties || {},
25956
- cellMargins: referencedStyles.cellMargins
25957
- };
25540
+ const tblJustification = tblPr.elements.find((el) => el.name === "w:jc");
25541
+ if (tblJustification?.attributes) {
25542
+ attrs["justification"] = tblJustification.attributes["w:val"];
25958
25543
  }
25959
25544
  const rows = node.elements.filter((el) => el.name === "w:tr");
25960
- const borderData = Object.assign({}, referencedStyles?.borders || {}, borders || {});
25961
- const borderRowData = Object.assign({}, referencedStyles?.rowBorders || {}, rowBorders || {});
25962
- encodedAttrs["borders"] = borderData;
25963
- const tblStyleTag = tblPr?.elements?.find((el) => el.name === "w:tblStyle");
25964
- const columnWidths = (encodedAttrs["grid"] ?? []).map((item) => twipsToPixels(item.col));
25545
+ const refStylesBorders = referencedStyles?.borders || {};
25546
+ const refStylesRowBorders = referencedStyles?.rowBorders || {};
25547
+ const borderData = Object.keys(borders)?.length ? Object.assign(refStylesBorders, borders) : refStylesBorders;
25548
+ const borderRowData = Object.keys(rowBorders)?.length ? Object.assign(refStylesRowBorders, rowBorders) : refStylesRowBorders;
25549
+ attrs["borders"] = borderData;
25965
25550
  const content = [];
25966
25551
  rows.forEach((row) => {
25967
- const result = translator$D.encode({
25552
+ const result = translator$3.encode({
25968
25553
  ...params,
25969
25554
  nodes: [row],
25970
25555
  extraParams: {
25971
25556
  row,
25972
25557
  table: node,
25973
25558
  rowBorders: borderRowData,
25974
- styleTag: tblStyleTag,
25975
- columnWidths
25559
+ styleTag: tblStyleTag
25976
25560
  }
25977
25561
  });
25978
25562
  if (result.content?.length) content.push(result);
@@ -25980,118 +25564,9 @@ const encode$6 = (params, encodedAttrs) => {
25980
25564
  return {
25981
25565
  type: "table",
25982
25566
  content,
25983
- attrs: encodedAttrs
25984
- };
25985
- };
25986
- const decode$6 = (params, decodedAttrs) => {
25987
- params.node = preProcessVerticalMergeCells(params.node, params);
25988
- const { node } = params;
25989
- const elements = translateChildNodes(params);
25990
- const firstRow = node.content?.find((n) => n.type === "tableRow");
25991
- const properties = node.attrs.grid;
25992
- const element = translator$7.decode({
25993
- ...params,
25994
- node: { ...node, attrs: { ...node.attrs, grid: properties } },
25995
- extraParams: {
25996
- firstRow
25997
- }
25998
- });
25999
- if (element) elements.unshift(element);
26000
- if (node.attrs?.tableProperties) {
26001
- const properties2 = { ...node.attrs.tableProperties };
26002
- const element2 = translator$9.decode({
26003
- ...params,
26004
- node: { ...node, attrs: { ...node.attrs, tableProperties: properties2 } }
26005
- });
26006
- if (element2) elements.unshift(element2);
26007
- }
26008
- return {
26009
- name: "w:tbl",
26010
- attributes: decodedAttrs || {},
26011
- elements
26012
- };
26013
- };
26014
- function _processTableBorders(rawBorders) {
26015
- const borders = {};
26016
- const rowBorders = {};
26017
- Object.entries(rawBorders).forEach(([name, attributes]) => {
26018
- const attrs = {};
26019
- const color = attributes.color;
26020
- const size = attributes.size;
26021
- if (color && color !== "auto") attrs["color"] = color.startsWith("#") ? color : `#${color}`;
26022
- if (size && size !== "auto") attrs["size"] = eigthPointsToPixels(size);
26023
- const rowBorderNames = ["insideH", "insideV"];
26024
- if (rowBorderNames.includes(name)) rowBorders[name] = attrs;
26025
- borders[name] = attrs;
26026
- });
26027
- return {
26028
- borders,
26029
- rowBorders
25567
+ attrs
26030
25568
  };
26031
25569
  }
26032
- function _getReferencedTableStyles(tableStyleReference, params) {
26033
- if (!tableStyleReference) return null;
26034
- const stylesToReturn = {};
26035
- const { docx } = params;
26036
- const styles = docx["word/styles.xml"];
26037
- const { elements } = styles.elements[0];
26038
- const styleElements = elements.filter((el) => el.name === "w:style");
26039
- const styleTag = styleElements.find((el) => el.attributes["w:styleId"] === tableStyleReference);
26040
- if (!styleTag) return null;
26041
- stylesToReturn.name = styleTag.elements.find((el) => el.name === "w:name");
26042
- const basedOn = styleTag.elements.find((el) => el.name === "w:basedOn");
26043
- let baseTblPr;
26044
- if (basedOn?.attributes) {
26045
- const baseStyles = styleElements.find((el) => el.attributes["w:styleId"] === basedOn.attributes["w:val"]);
26046
- baseTblPr = baseStyles ? baseStyles.elements.find((el) => el.name === "w:tblPr") : {};
26047
- }
26048
- const pPr = styleTag.elements.find((el) => el.name === "w:pPr");
26049
- if (pPr) {
26050
- const justification = pPr.elements.find((el) => el.name === "w:jc");
26051
- if (justification?.attributes) stylesToReturn.justification = justification.attributes["w:val"];
26052
- }
26053
- const rPr = styleTag?.elements.find((el) => el.name === "w:rPr");
26054
- if (rPr) {
26055
- const fonts = rPr.elements.find((el) => el.name === "w:rFonts");
26056
- if (fonts) {
26057
- const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
26058
- stylesToReturn.fonts = { ascii, hAnsi, cs };
26059
- }
26060
- const fontSize = rPr.elements.find((el) => el.name === "w:sz");
26061
- if (fontSize?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize.attributes["w:val"]) + "pt";
26062
- }
26063
- const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
26064
- if (tblPr && tblPr.elements) {
26065
- if (baseTblPr && baseTblPr.elements) {
26066
- tblPr.elements.push(...baseTblPr.elements);
26067
- }
26068
- const tableProperties = translator$9.encode({ ...params, nodes: [tblPr] }).attributes;
26069
- const { borders, rowBorders } = _processTableBorders(tableProperties.borders || {});
26070
- if (borders) stylesToReturn.borders = borders;
26071
- if (rowBorders) stylesToReturn.rowBorders = rowBorders;
26072
- const cellMargins = {};
26073
- Object.entries(tableProperties.cellMargins || {}).forEach(([key, attrs]) => {
26074
- if (attrs?.value != null) {
26075
- cellMargins[key] = {
26076
- value: attrs.value,
26077
- type: attrs.type || "dxa"
26078
- };
26079
- }
26080
- });
26081
- if (Object.keys(cellMargins).length) stylesToReturn.cellMargins = cellMargins;
26082
- }
26083
- return stylesToReturn;
26084
- }
26085
- const config$6 = {
26086
- xmlName: XML_NODE_NAME$6,
26087
- sdNodeOrKeyName: SD_NODE_NAME$6,
26088
- type: NodeTranslator.translatorTypes.NODE,
26089
- encode: encode$6,
26090
- decode: decode$6,
26091
- attributes: []
26092
- };
26093
- const translator$6 = NodeTranslator.from(config$6);
26094
- const tableNodeHandlerEntity = generateV2HandlerEntity("tableNodeHandler", translator$6);
26095
25570
  function getReferencedTableStyles(tblStyleTag, docx) {
26096
25571
  if (!tblStyleTag) return null;
26097
25572
  const stylesToReturn = {};
@@ -26172,6 +25647,15 @@ function processTableBorders(borderElements) {
26172
25647
  rowBorders
26173
25648
  };
26174
25649
  }
25650
+ const getGridColumnWidths = (tableNode) => {
25651
+ const tblGrid = tableNode.elements.find((el) => el.name === "w:tblGrid");
25652
+ if (!tblGrid) return [];
25653
+ const columnWidths = tblGrid?.elements?.flatMap((el) => {
25654
+ if (el.name !== "w:gridCol") return [];
25655
+ return twipsToPixels(el.attributes["w:w"]);
25656
+ }) || [];
25657
+ return columnWidths;
25658
+ };
26175
25659
  function handleTableCellNode({
26176
25660
  params,
26177
25661
  node,
@@ -26180,8 +25664,7 @@ function handleTableCellNode({
26180
25664
  rowBorders,
26181
25665
  styleTag,
26182
25666
  columnIndex,
26183
- columnWidth = null,
26184
- allColumnWidths = []
25667
+ columnWidth = null
26185
25668
  }) {
26186
25669
  const { docx, nodeListHandler } = params;
26187
25670
  const tcPr = node.elements.find((el) => el.name === "w:tcPr");
@@ -26195,7 +25678,7 @@ function handleTableCellNode({
26195
25678
  delete rowBorders?.insideV;
26196
25679
  }
26197
25680
  const inlineBorders = processInlineCellBorders(borders, rowBorders);
26198
- const gridColumnWidths = allColumnWidths;
25681
+ const gridColumnWidths = getGridColumnWidths(table);
26199
25682
  const tcWidth = tcPr?.elements?.find((el) => el.name === "w:tcW");
26200
25683
  let width = tcWidth ? twipsToPixels(tcWidth.attributes["w:w"]) : null;
26201
25684
  const widthType = tcWidth?.attributes["w:type"];
@@ -26329,17 +25812,11 @@ const getTableCellMargins = (marginTag, referencedStyles) => {
26329
25812
  marginTop: marginTopStyle,
26330
25813
  marginBottom: marginBottomStyle
26331
25814
  } = cellMargins;
26332
- const resolveMargin = (inlineValue, styleValue) => {
26333
- if (inlineValue != null) return inlineValue;
26334
- if (styleValue == null) return void 0;
26335
- if (typeof styleValue === "object") return styleValue.value;
26336
- return styleValue;
26337
- };
26338
25815
  const margins = {
26339
- left: twipsToPixels(resolveMargin(inlineMarginLeftValue, marginLeftStyle)),
26340
- right: twipsToPixels(resolveMargin(inlineMarginRightValue, marginRightStyle)),
26341
- top: twipsToPixels(resolveMargin(inlineMarginTopValue, marginTopStyle)),
26342
- bottom: twipsToPixels(resolveMargin(inlineMarginBottomValue, marginBottomStyle))
25816
+ left: twipsToPixels(inlineMarginLeftValue ?? marginLeftStyle),
25817
+ right: twipsToPixels(inlineMarginRightValue ?? marginRightStyle),
25818
+ top: twipsToPixels(inlineMarginTopValue ?? marginTopStyle),
25819
+ bottom: twipsToPixels(inlineMarginBottomValue ?? marginBottomStyle)
26343
25820
  };
26344
25821
  return margins;
26345
25822
  };
@@ -26453,20 +25930,11 @@ function generateCellMargins(cellMargins) {
26453
25930
  if (left != null) elements.push({ name: "w:left", attributes: { "w:w": pixelsToTwips(left) } });
26454
25931
  return elements;
26455
25932
  }
26456
- const XML_NODE_NAME$5 = "w:tc";
26457
- const SD_NODE_NAME$5 = "tableCell";
26458
- const validXmlAttributes$5 = [];
26459
- function encode$5(params, encodedAttrs) {
26460
- const {
26461
- node,
26462
- table,
26463
- row,
26464
- rowBorders,
26465
- styleTag,
26466
- columnIndex,
26467
- columnWidth,
26468
- columnWidths: allColumnWidths
26469
- } = params.extraParams;
25933
+ const XML_NODE_NAME$2 = "w:tc";
25934
+ const SD_NODE_NAME$2 = "tableCell";
25935
+ const validXmlAttributes$2 = [];
25936
+ function encode$2(params, encodedAttrs) {
25937
+ const { node, table, row, rowBorders, styleTag, columnIndex, columnWidth } = params.extraParams;
26470
25938
  const schemaNode = handleTableCellNode({
26471
25939
  params,
26472
25940
  node,
@@ -26475,39 +25943,38 @@ function encode$5(params, encodedAttrs) {
26475
25943
  rowBorders,
26476
25944
  styleTag,
26477
25945
  columnIndex,
26478
- columnWidth,
26479
- allColumnWidths
25946
+ columnWidth
26480
25947
  });
26481
25948
  if (encodedAttrs && Object.keys(encodedAttrs).length) {
26482
25949
  schemaNode.attrs = { ...schemaNode.attrs, ...encodedAttrs };
26483
25950
  }
26484
25951
  return schemaNode;
26485
25952
  }
26486
- function decode$5(params, decodedAttrs) {
25953
+ function decode$2(params, decodedAttrs) {
26487
25954
  const translated = translateTableCell(params);
26488
25955
  if (decodedAttrs && Object.keys(decodedAttrs).length) {
26489
25956
  translated.attributes = { ...translated.attributes || {}, ...decodedAttrs };
26490
25957
  }
26491
25958
  return translated;
26492
25959
  }
26493
- const config$5 = {
26494
- xmlName: XML_NODE_NAME$5,
26495
- sdNodeOrKeyName: SD_NODE_NAME$5,
25960
+ const config$2 = {
25961
+ xmlName: XML_NODE_NAME$2,
25962
+ sdNodeOrKeyName: SD_NODE_NAME$2,
26496
25963
  type: NodeTranslator.translatorTypes.NODE,
26497
- encode: encode$5,
26498
- decode: decode$5,
26499
- attributes: validXmlAttributes$5
25964
+ encode: encode$2,
25965
+ decode: decode$2,
25966
+ attributes: validXmlAttributes$2
26500
25967
  };
26501
- const translator$5 = NodeTranslator.from(config$5);
26502
- const XML_NODE_NAME$4 = "w:hyperlink";
26503
- const SD_NODE_NAME$4 = "link";
25968
+ const translator$2 = NodeTranslator.from(config$2);
25969
+ const XML_NODE_NAME$1 = "w:hyperlink";
25970
+ const SD_NODE_NAME$1 = "link";
26504
25971
  const _createAttributeHandler = (xmlName, sdName) => ({
26505
25972
  xmlName,
26506
25973
  sdName,
26507
25974
  encode: (attributes) => attributes[xmlName],
26508
25975
  decode: (attributes) => attributes[sdName]
26509
25976
  });
26510
- const validXmlAttributes$4 = [
25977
+ const validXmlAttributes$1 = [
26511
25978
  _createAttributeHandler("w:anchor", "anchor"),
26512
25979
  _createAttributeHandler("w:docLocation", "docLocation"),
26513
25980
  {
@@ -26520,7 +25987,7 @@ const validXmlAttributes$4 = [
26520
25987
  _createAttributeHandler("r:id", "rId"),
26521
25988
  _createAttributeHandler("w:tgtFrame", "target")
26522
25989
  ];
26523
- const encode$4 = (params, encodedAttrs) => {
25990
+ const encode$1 = (params, encodedAttrs) => {
26524
25991
  const { nodes, docx, nodeListHandler } = params;
26525
25992
  const node = nodes[0];
26526
25993
  let href = _resolveHref(docx, encodedAttrs);
@@ -26551,7 +26018,7 @@ const _resolveHref = (docx, encodedAttrs) => {
26551
26018
  }
26552
26019
  return href;
26553
26020
  };
26554
- function decode$4(params) {
26021
+ function decode$1(params) {
26555
26022
  const { node } = params;
26556
26023
  const linkMark = node.marks.find((m2) => m2.type === "link");
26557
26024
  const linkAttrs = this.decodeAttributes({ ...params, node: linkMark });
@@ -26595,15 +26062,15 @@ function _addNewLinkRelationship(params, link, rId) {
26595
26062
  });
26596
26063
  return rId;
26597
26064
  }
26598
- const config$4 = {
26599
- xmlName: XML_NODE_NAME$4,
26600
- sdNodeOrKeyName: SD_NODE_NAME$4,
26065
+ const config$1 = {
26066
+ xmlName: XML_NODE_NAME$1,
26067
+ sdNodeOrKeyName: SD_NODE_NAME$1,
26601
26068
  type: NodeTranslator.translatorTypes.NODE,
26602
- encode: encode$4,
26603
- decode: decode$4,
26604
- attributes: validXmlAttributes$4
26069
+ encode: encode$1,
26070
+ decode: decode$1,
26071
+ attributes: validXmlAttributes$1
26605
26072
  };
26606
- const translator$4 = NodeTranslator.from(config$4);
26073
+ const translator$1 = NodeTranslator.from(config$1);
26607
26074
  function parseTagValueJSON(json) {
26608
26075
  if (typeof json !== "string") {
26609
26076
  return {};
@@ -26614,7 +26081,7 @@ function parseTagValueJSON(json) {
26614
26081
  }
26615
26082
  try {
26616
26083
  return JSON.parse(trimmed);
26617
- } catch {
26084
+ } catch (err) {
26618
26085
  return {};
26619
26086
  }
26620
26087
  }
@@ -26843,673 +26310,8 @@ function sdtNodeTypeStrategy(node) {
26843
26310
  if (sdtContent) {
26844
26311
  return { type: "structuredContent", handler: handleStructuredContentNode };
26845
26312
  }
26846
- return { type: "unknown", handler: null };
26847
- }
26848
- function handleImageNode(node, params, isAnchor) {
26849
- const { docx, filename } = params;
26850
- const { attributes } = node;
26851
- const padding = {
26852
- top: emuToPixels(attributes["distT"]),
26853
- bottom: emuToPixels(attributes["distB"]),
26854
- left: emuToPixels(attributes["distL"]),
26855
- right: emuToPixels(attributes["distR"])
26856
- };
26857
- const extent = node.elements.find((el) => el.name === "wp:extent");
26858
- const size = {
26859
- width: emuToPixels(extent.attributes?.cx),
26860
- height: emuToPixels(extent.attributes?.cy)
26861
- };
26862
- const graphic = node.elements.find((el) => el.name === "a:graphic");
26863
- const graphicData = graphic.elements.find((el) => el.name === "a:graphicData");
26864
- const { uri: uri2 } = graphicData?.attributes || {};
26865
- const shapeURI = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
26866
- if (!!uri2 && uri2 === shapeURI) {
26867
- return handleShapeDrawing(params, node, graphicData);
26868
- }
26869
- const picture = graphicData.elements.find((el) => el.name === "pic:pic");
26870
- if (!picture || !picture.elements) return null;
26871
- const blipFill = picture.elements.find((el) => el.name === "pic:blipFill");
26872
- const blip = blipFill.elements.find((el) => el.name === "a:blip");
26873
- const spPr = picture.elements.find((el) => el.name === "pic:spPr");
26874
- let transformData = {};
26875
- if (spPr) {
26876
- const xfrm = spPr.elements.find((el) => el.name === "a:xfrm");
26877
- if (xfrm?.attributes) {
26878
- transformData = {
26879
- rotation: rotToDegrees(xfrm.attributes["rot"]),
26880
- verticalFlip: xfrm.attributes["flipV"] === "1",
26881
- horizontalFlip: xfrm.attributes["flipH"] === "1"
26882
- };
26883
- }
26884
- }
26885
- const effectExtent = node.elements.find((el) => el.name === "wp:effectExtent");
26886
- if (effectExtent) {
26887
- const sanitizeEmuValue = (value) => {
26888
- if (value === null || value === void 0) return 0;
26889
- const numeric = Number(value);
26890
- return Number.isFinite(numeric) ? numeric : 0;
26891
- };
26892
- transformData.sizeExtension = {
26893
- left: emuToPixels(sanitizeEmuValue(effectExtent.attributes["l"])),
26894
- top: emuToPixels(sanitizeEmuValue(effectExtent.attributes["t"])),
26895
- right: emuToPixels(sanitizeEmuValue(effectExtent.attributes["r"])),
26896
- bottom: emuToPixels(sanitizeEmuValue(effectExtent.attributes["b"]))
26897
- };
26898
- }
26899
- const positionHTag = node.elements.find((el) => el.name === "wp:positionH");
26900
- const positionH = positionHTag?.elements.find((el) => el.name === "wp:posOffset");
26901
- const positionHValue = emuToPixels(positionH?.elements[0]?.text);
26902
- const hRelativeFrom = positionHTag?.attributes.relativeFrom;
26903
- const alignH = positionHTag?.elements.find((el) => el.name === "wp:align")?.elements[0]?.text;
26904
- const positionVTag = node.elements.find((el) => el.name === "wp:positionV");
26905
- const positionV = positionVTag?.elements?.find((el) => el.name === "wp:posOffset");
26906
- const positionVValue = emuToPixels(positionV?.elements[0]?.text);
26907
- const vRelativeFrom = positionVTag?.attributes.relativeFrom;
26908
- const alignV = positionVTag?.elements?.find((el) => el.name === "wp:align")?.elements[0]?.text;
26909
- const simplePos = node.elements.find((el) => el.name === "wp:simplePos");
26910
- const wrapSquare = node.elements.find((el) => el.name === "wp:wrapSquare");
26911
- const wrapTopAndBottom = node.elements.find((el) => el.name === "wp:wrapTopAndBottom");
26912
- const docPr = node.elements.find((el) => el.name === "wp:docPr");
26913
- let anchorData = null;
26914
- if (hRelativeFrom || alignH || vRelativeFrom || alignV) {
26915
- anchorData = {
26916
- hRelativeFrom,
26917
- vRelativeFrom,
26918
- alignH,
26919
- alignV
26920
- };
26921
- }
26922
- const marginOffset = {
26923
- left: positionHValue,
26924
- top: positionVValue
26925
- };
26926
- const { attributes: blipAttributes = {} } = blip;
26927
- const rEmbed = blipAttributes["r:embed"];
26928
- if (!rEmbed) return null;
26929
- const currentFile = filename || "document.xml";
26930
- let rels = docx[`word/_rels/${currentFile}.rels`];
26931
- if (!rels) rels = docx[`word/_rels/document.xml.rels`];
26932
- const relationships = rels.elements.find((el) => el.name === "Relationships");
26933
- const { elements } = relationships || [];
26934
- const rel = elements?.find((el) => el.attributes["Id"] === rEmbed);
26935
- if (!rel) return null;
26936
- const { attributes: relAttributes } = rel;
26937
- const targetPath = relAttributes["Target"];
26938
- let path = `word/${targetPath}`;
26939
- if (targetPath.startsWith("/word") || targetPath.startsWith("/media")) path = targetPath.substring(1);
26940
- const extension = targetPath.substring(targetPath.lastIndexOf(".") + 1);
26941
- return {
26942
- type: "image",
26943
- attrs: {
26944
- src: path,
26945
- alt: ["emf", "wmf"].includes(extension) ? "Unable to render EMF/WMF image" : docPr?.attributes.name || "Image",
26946
- extension,
26947
- id: docPr?.attributes.id || "",
26948
- title: docPr?.attributes.descr || "Image",
26949
- inline: true,
26950
- padding,
26951
- marginOffset,
26952
- size,
26953
- anchorData,
26954
- isAnchor,
26955
- transformData,
26956
- ...simplePos && {
26957
- simplePos: {
26958
- x: simplePos.attributes.x,
26959
- y: simplePos.attributes.y
26960
- }
26961
- },
26962
- ...wrapSquare && {
26963
- wrapText: wrapSquare.attributes.wrapText
26964
- },
26965
- wrapTopAndBottom: !!wrapTopAndBottom,
26966
- originalPadding: {
26967
- distT: attributes["distT"],
26968
- distB: attributes["distB"],
26969
- distL: attributes["distL"],
26970
- distR: attributes["distR"]
26971
- },
26972
- originalAttributes: node.attributes,
26973
- rId: relAttributes["Id"]
26974
- }
26975
- };
26976
- }
26977
- const handleShapeDrawing = (params, node, graphicData) => {
26978
- const wsp = graphicData.elements.find((el) => el.name === "wps:wsp");
26979
- const textBox = wsp.elements.find((el) => el.name === "wps:txbx");
26980
- const textBoxContent = textBox?.elements?.find((el) => el.name === "w:txbxContent");
26981
- node.elements.find((el) => el.name === "wp:docPr");
26982
- const spPr = wsp.elements.find((el) => el.name === "wps:spPr");
26983
- const prstGeom = spPr?.elements.find((el) => el.name === "a:prstGeom");
26984
- if (!!prstGeom && prstGeom.attributes["prst"] === "rect" && !textBoxContent) {
26985
- return getRectangleShape(params, spPr);
26986
- }
26987
- if (!textBoxContent) {
26988
- return null;
26989
- }
26990
- const { nodeListHandler } = params;
26991
- const translatedElement = nodeListHandler.handler({
26992
- ...params,
26993
- node: textBoxContent.elements[0],
26994
- nodes: textBoxContent.elements,
26995
- path: [...params.path || [], textBoxContent]
26996
- });
26997
- return translatedElement[0];
26998
- };
26999
- const getRectangleShape = (params, node) => {
27000
- const schemaAttrs = {};
27001
- const [drawingNode] = params.nodes;
27002
- if (drawingNode?.name === "w:drawing") {
27003
- schemaAttrs.drawingContent = drawingNode;
27004
- }
27005
- const xfrm = node.elements.find((el) => el.name === "a:xfrm");
27006
- const start = xfrm.elements.find((el) => el.name === "a:off");
27007
- const size = xfrm.elements.find((el) => el.name === "a:ext");
27008
- const solidFill = node.elements.find((el) => el.name === "a:solidFill");
27009
- node.elements.find((el) => el.name === "a:ln");
27010
- const rectangleSize = {
27011
- top: emuToPixels(start.attributes["y"]),
27012
- left: emuToPixels(start.attributes["x"]),
27013
- width: emuToPixels(size.attributes["cx"]),
27014
- height: emuToPixels(size.attributes["cy"])
27015
- };
27016
- schemaAttrs.size = rectangleSize;
27017
- const background = solidFill?.elements[0]?.attributes["val"];
27018
- if (background) {
27019
- schemaAttrs.background = "#" + background;
27020
- }
27021
- return {
27022
- type: "contentBlock",
27023
- attrs: schemaAttrs
27024
- };
27025
- };
27026
- function handleAnchorNode(params) {
27027
- const { node } = params.extraParams;
27028
- if (node.name !== "wp:anchor") {
27029
- return null;
27030
- }
27031
- return handleImageNode(node, params, true);
27032
- }
27033
- const sanitizeDocxMediaName = (value, fallback = "image") => {
27034
- if (!value) return fallback;
27035
- const sanitized = value.replace(/[^a-zA-Z0-9_-]/g, "_");
27036
- return sanitized || fallback;
27037
- };
27038
- const getFallbackImageNameFromDataUri = (src = "", fallback = "image") => {
27039
- if (!src || typeof src !== "string") return fallback;
27040
- const [prefix] = src.split(";");
27041
- const [, maybeType] = prefix.split("/");
27042
- const extension = maybeType?.toLowerCase();
27043
- return extension ? `${fallback}.${extension}` : fallback;
27044
- };
27045
- const translateImageNode = (params) => {
27046
- const {
27047
- node: { attrs = {} },
27048
- tableCell,
27049
- imageSize
27050
- } = params;
27051
- let imageId = attrs.rId;
27052
- const src = attrs.src || attrs.imageSrc;
27053
- const { originalWidth, originalHeight } = getPngDimensions(src);
27054
- let imageName;
27055
- if (params.node.type === "image") {
27056
- if (src?.startsWith("data:")) {
27057
- imageName = getFallbackImageNameFromDataUri(src);
27058
- } else {
27059
- imageName = src?.split("/").pop();
27060
- }
27061
- } else {
27062
- imageName = attrs.fieldId;
27063
- }
27064
- imageName = sanitizeDocxMediaName(imageName);
27065
- let size = attrs.size ? {
27066
- w: pixelsToEmu(attrs.size.width),
27067
- h: pixelsToEmu(attrs.size.height)
27068
- } : imageSize;
27069
- if (originalWidth && originalHeight) {
27070
- const boxWidthPx = emuToPixels(size.w);
27071
- const boxHeightPx = emuToPixels(size.h);
27072
- const { scaledWidth, scaledHeight } = getScaledSize(originalWidth, originalHeight, boxWidthPx, boxHeightPx);
27073
- size = {
27074
- w: pixelsToEmu(scaledWidth),
27075
- h: pixelsToEmu(scaledHeight)
27076
- };
27077
- }
27078
- if (tableCell) {
27079
- const colwidthSum = tableCell.attrs.colwidth.reduce((acc, curr) => acc + curr, 0);
27080
- const leftMargin = tableCell.attrs.cellMargins?.left || 8;
27081
- const rightMargin = tableCell.attrs.cellMargins?.right || 8;
27082
- const maxWidthEmu = pixelsToEmu(colwidthSum - (leftMargin + rightMargin));
27083
- const { width: w2, height: h2 } = resizeKeepAspectRatio(size.w, size.h, maxWidthEmu);
27084
- if (w2 && h2) size = { w: w2, h: h2 };
27085
- }
27086
- if (params.node.type === "image" && !imageId) {
27087
- const path = src?.split("word/")[1];
27088
- imageId = addNewImageRelationship(params, path);
27089
- } else if (params.node.type === "fieldAnnotation" && !imageId) {
27090
- const type2 = src?.split(";")[0].split("/")[1];
27091
- if (!type2) {
27092
- return prepareTextAnnotation(params);
27093
- }
27094
- const sanitizedHash = sanitizeDocxMediaName(attrs.hash, generateDocxRandomId(4));
27095
- const fileName = `${imageName}_${sanitizedHash}.${type2}`;
27096
- const relationshipTarget = `media/${fileName}`;
27097
- const packagePath = `word/${relationshipTarget}`;
27098
- imageId = addNewImageRelationship(params, relationshipTarget);
27099
- params.media[packagePath] = src;
27100
- }
27101
- const inlineAttrs = attrs.originalPadding || {
27102
- distT: 0,
27103
- distB: 0,
27104
- distL: 0,
27105
- distR: 0
27106
- };
27107
- const xfrmAttrs = {};
27108
- const effectExtentAttrs = {
27109
- l: 0,
27110
- t: 0,
27111
- r: 0,
27112
- b: 0
27113
- };
27114
- const transformData = attrs.transformData;
27115
- if (transformData) {
27116
- if (transformData.rotation) {
27117
- xfrmAttrs.rot = degreesToRot(transformData.rotation);
27118
- }
27119
- if (transformData.verticalFlip) {
27120
- xfrmAttrs.flipV = "1";
27121
- }
27122
- if (transformData.horizontalFlip) {
27123
- xfrmAttrs.flipH = "1";
27124
- }
27125
- if (transformData.sizeExtension) {
27126
- effectExtentAttrs.l = pixelsToEmu(transformData.sizeExtension.left);
27127
- effectExtentAttrs.t = pixelsToEmu(transformData.sizeExtension.top);
27128
- effectExtentAttrs.r = pixelsToEmu(transformData.sizeExtension.right);
27129
- effectExtentAttrs.b = pixelsToEmu(transformData.sizeExtension.bottom);
27130
- }
27131
- }
27132
- const drawingXmlns = "http://schemas.openxmlformats.org/drawingml/2006/main";
27133
- const pictureXmlns = "http://schemas.openxmlformats.org/drawingml/2006/picture";
27134
- return {
27135
- attributes: inlineAttrs,
27136
- elements: [
27137
- {
27138
- name: "wp:extent",
27139
- attributes: {
27140
- cx: size.w,
27141
- cy: size.h
27142
- }
27143
- },
27144
- {
27145
- name: "wp:effectExtent",
27146
- attributes: effectExtentAttrs
27147
- },
27148
- {
27149
- name: "wp:docPr",
27150
- attributes: {
27151
- id: attrs.id || 0,
27152
- name: attrs.alt || `Picture ${imageName}`
27153
- }
27154
- },
27155
- {
27156
- name: "wp:cNvGraphicFramePr",
27157
- elements: [
27158
- {
27159
- name: "a:graphicFrameLocks",
27160
- attributes: {
27161
- "xmlns:a": drawingXmlns,
27162
- noChangeAspect: 1
27163
- }
27164
- }
27165
- ]
27166
- },
27167
- {
27168
- name: "a:graphic",
27169
- attributes: { "xmlns:a": drawingXmlns },
27170
- elements: [
27171
- {
27172
- name: "a:graphicData",
27173
- attributes: { uri: pictureXmlns },
27174
- elements: [
27175
- {
27176
- name: "pic:pic",
27177
- attributes: { "xmlns:pic": pictureXmlns },
27178
- elements: [
27179
- {
27180
- name: "pic:nvPicPr",
27181
- elements: [
27182
- {
27183
- name: "pic:cNvPr",
27184
- attributes: {
27185
- id: attrs.id || 0,
27186
- name: attrs.title || `Picture ${imageName}`
27187
- }
27188
- },
27189
- {
27190
- name: "pic:cNvPicPr",
27191
- elements: [
27192
- {
27193
- name: "a:picLocks",
27194
- attributes: {
27195
- noChangeAspect: 1,
27196
- noChangeArrowheads: 1
27197
- }
27198
- }
27199
- ]
27200
- }
27201
- ]
27202
- },
27203
- {
27204
- name: "pic:blipFill",
27205
- elements: [
27206
- {
27207
- name: "a:blip",
27208
- attributes: {
27209
- "r:embed": imageId
27210
- }
27211
- },
27212
- {
27213
- name: "a:stretch",
27214
- elements: [{ name: "a:fillRect" }]
27215
- }
27216
- ]
27217
- },
27218
- {
27219
- name: "pic:spPr",
27220
- attributes: {
27221
- bwMode: "auto"
27222
- },
27223
- elements: [
27224
- {
27225
- name: "a:xfrm",
27226
- attributes: xfrmAttrs,
27227
- elements: [
27228
- {
27229
- name: "a:ext",
27230
- attributes: {
27231
- cx: size.w,
27232
- cy: size.h
27233
- }
27234
- },
27235
- {
27236
- name: "a:off",
27237
- attributes: {
27238
- x: 0,
27239
- y: 0
27240
- }
27241
- }
27242
- ]
27243
- },
27244
- {
27245
- name: "a:prstGeom",
27246
- attributes: { prst: "rect" },
27247
- elements: [{ name: "a:avLst" }]
27248
- },
27249
- {
27250
- name: "a:noFill"
27251
- }
27252
- ]
27253
- }
27254
- ]
27255
- }
27256
- ]
27257
- }
27258
- ]
27259
- }
27260
- ]
27261
- };
27262
- };
27263
- function getPngDimensions(base64) {
27264
- if (!base64) return {};
27265
- const type2 = base64.split(";")[0].split("/")[1];
27266
- if (!base64 || type2 !== "png") {
27267
- return {
27268
- originalWidth: void 0,
27269
- originalHeight: void 0
27270
- };
27271
- }
27272
- let header = base64.split(",")[1].slice(0, 50);
27273
- let uint8 = Uint8Array.from(atob(header), (c) => c.charCodeAt(0));
27274
- let dataView = new DataView(uint8.buffer, 0, 28);
27275
- return {
27276
- originalWidth: dataView.getInt32(16),
27277
- originalHeight: dataView.getInt32(20)
27278
- };
27279
- }
27280
- function getScaledSize(originalWidth, originalHeight, maxWidth, maxHeight) {
27281
- let scaledWidth = originalWidth;
27282
- let scaledHeight = originalHeight;
27283
- let ratio = Math.min(maxWidth / originalWidth, maxHeight / originalHeight);
27284
- scaledWidth = Math.round(scaledWidth * ratio);
27285
- scaledHeight = Math.round(scaledHeight * ratio);
27286
- return { scaledWidth, scaledHeight };
27287
- }
27288
- function resizeKeepAspectRatio(width, height, maxWidth) {
27289
- if (width > maxWidth) {
27290
- let scale = maxWidth / width;
27291
- let newHeight = Math.round(height * scale);
27292
- return { width: maxWidth, height: newHeight };
27293
- }
27294
- return { width, height };
27295
- }
27296
- function addNewImageRelationship(params, imagePath) {
27297
- const newId = "rId" + generateDocxRandomId();
27298
- const newRel = {
27299
- type: "element",
27300
- name: "Relationship",
27301
- attributes: {
27302
- Id: newId,
27303
- Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
27304
- Target: imagePath
27305
- }
27306
- };
27307
- params.relationships.push(newRel);
27308
- return newId;
27309
- }
27310
- function translateAnchorNode(params) {
27311
- const { attrs } = params.node;
27312
- const anchorElements = [];
27313
- const wrapElements = [];
27314
- if (attrs.simplePos) {
27315
- anchorElements.push({
27316
- name: "wp:simplePos",
27317
- attributes: {
27318
- x: 0,
27319
- y: 0
27320
- }
27321
- });
27322
- }
27323
- if (attrs.anchorData) {
27324
- const hElements = [];
27325
- if (attrs.marginOffset.left !== void 0) {
27326
- hElements.push({
27327
- name: "wp:posOffset",
27328
- elements: [{ type: "text", text: pixelsToEmu(attrs.marginOffset.left).toString() }]
27329
- });
27330
- }
27331
- if (attrs.anchorData.alignH) {
27332
- hElements.push({
27333
- name: "wp:align",
27334
- elements: [{ type: "text", text: attrs.anchorData.alignH }]
27335
- });
27336
- }
27337
- anchorElements.push({
27338
- name: "wp:positionH",
27339
- attributes: { relativeFrom: attrs.anchorData.hRelativeFrom },
27340
- ...hElements.length && { elements: hElements }
27341
- });
27342
- const vElements = [];
27343
- if (attrs.marginOffset.top !== void 0) {
27344
- vElements.push({
27345
- name: "wp:posOffset",
27346
- elements: [{ type: "text", text: pixelsToEmu(attrs.marginOffset.top).toString() }]
27347
- });
27348
- }
27349
- if (attrs.anchorData.alignV) {
27350
- vElements.push({
27351
- name: "wp:align",
27352
- elements: [{ type: "text", text: attrs.anchorData.alignV }]
27353
- });
27354
- }
27355
- anchorElements.push({
27356
- name: "wp:positionV",
27357
- attributes: { relativeFrom: attrs.anchorData.vRelativeFrom },
27358
- ...vElements.length && { elements: vElements }
27359
- });
27360
- }
27361
- if (attrs.wrapText) {
27362
- wrapElements.push({
27363
- name: "wp:wrapSquare",
27364
- attributes: {
27365
- wrapText: attrs.wrapText
27366
- }
27367
- });
27368
- }
27369
- if (attrs.wrapTopAndBottom) {
27370
- wrapElements.push({
27371
- name: "wp:wrapTopAndBottom"
27372
- });
27373
- }
27374
- if (!wrapElements.length) {
27375
- wrapElements.push({
27376
- name: "wp:wrapNone"
27377
- });
27378
- }
27379
- const nodeElements = translateImageNode(params);
27380
- const inlineAttrs = {
27381
- ...nodeElements.attributes,
27382
- simplePos: attrs.originalAttributes?.simplePos,
27383
- relativeHeight: 1,
27384
- behindDoc: attrs.originalAttributes?.behindDoc,
27385
- locked: attrs.originalAttributes?.locked,
27386
- layoutInCell: attrs.originalAttributes?.layoutInCell,
27387
- allowOverlap: attrs.originalAttributes?.allowOverlap
27388
- };
27389
- const effectIndex = nodeElements.elements.findIndex((el) => el.name === "wp:effectExtent");
27390
- const elementsWithWrap = [
27391
- ...nodeElements.elements.slice(0, effectIndex + 1),
27392
- ...wrapElements,
27393
- ...nodeElements.elements.slice(effectIndex + 1)
27394
- ];
27395
- return {
27396
- name: "wp:anchor",
27397
- attributes: inlineAttrs,
27398
- elements: [...anchorElements, ...elementsWithWrap]
27399
- };
27400
- }
27401
- const XML_NODE_NAME$3 = "wp:anchor";
27402
- const SD_NODE_NAME$3 = ["image"];
27403
- const validXmlAttributes$3 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
27404
- function encode$3(params) {
27405
- const { node } = params.extraParams;
27406
- if (!node || !node.type) {
27407
- return null;
27408
- }
27409
- return handleAnchorNode(params);
27410
- }
27411
- function decode$3(params) {
27412
- const { node } = params;
27413
- if (!node || !node.type) {
27414
- return null;
27415
- }
27416
- return translateAnchorNode(params);
27417
- }
27418
- const config$3 = {
27419
- xmlName: XML_NODE_NAME$3,
27420
- sdNodeOrKeyName: SD_NODE_NAME$3,
27421
- type: NodeTranslator.translatorTypes.NODE,
27422
- encode: encode$3,
27423
- decode: decode$3,
27424
- attributes: validXmlAttributes$3
27425
- };
27426
- const translator$3 = NodeTranslator.from(config$3);
27427
- function handleInlineNode(params) {
27428
- const { node } = params.extraParams;
27429
- if (node.name !== "wp:inline") {
27430
- return null;
27431
- }
27432
- return handleImageNode(node, params, false);
27433
- }
27434
- function translateInlineNode(params) {
27435
- const nodeElements = translateImageNode(params);
27436
- return {
27437
- name: "wp:inline",
27438
- attributes: nodeElements.attributes,
27439
- elements: nodeElements.elements
27440
- };
27441
- }
27442
- const XML_NODE_NAME$2 = "wp:inline";
27443
- const SD_NODE_NAME$2 = ["image"];
27444
- const validXmlAttributes$2 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
27445
- function encode$2(params) {
27446
- const { node } = params.extraParams;
27447
- if (!node || !node.type) {
27448
- return null;
27449
- }
27450
- return handleInlineNode(params);
27451
- }
27452
- function decode$2(params) {
27453
- const { node } = params;
27454
- if (!node || !node.type) {
27455
- return null;
27456
- }
27457
- return translateInlineNode(params);
27458
- }
27459
- const config$2 = {
27460
- xmlName: XML_NODE_NAME$2,
27461
- sdNodeOrKeyName: SD_NODE_NAME$2,
27462
- type: NodeTranslator.translatorTypes.NODE,
27463
- encode: encode$2,
27464
- decode: decode$2,
27465
- attributes: validXmlAttributes$2
27466
- };
27467
- const translator$2 = NodeTranslator.from(config$2);
27468
- const registeredHandlers = Object.freeze({
27469
- "w:br": translator$T,
27470
- "w:tab": translator$S,
27471
- "w:p": translator$R,
27472
- "wp:anchor": translator$3,
27473
- "wp:inline": translator$2
27474
- });
27475
- const XML_NODE_NAME$1 = "w:drawing";
27476
- const SD_NODE_NAME$1 = [];
27477
- const validXmlAttributes$1 = [];
27478
- function encode$1(params) {
27479
- const nodes = params.nodes;
27480
- const node = nodes[0];
27481
- const validChildTranslators = ["wp:anchor", "wp:inline"];
27482
- return node.elements.reduce((acc, child) => {
27483
- if (acc) return acc;
27484
- if (!validChildTranslators.includes(child.name)) return acc;
27485
- const translator2 = registeredHandlers[child.name];
27486
- return translator2.encode({ ...params, extraParams: { node: child } }) || acc;
27487
- }, null);
27488
- }
27489
- function decode$1(params) {
27490
- const { node } = params;
27491
- if (!node || !node.type) {
27492
- return null;
27493
- }
27494
- const handlerName = node.attrs.isAnchor ? "wp:anchor" : "wp:inline";
27495
- const resultNode = registeredHandlers[handlerName].decode(params);
27496
- return wrapTextInRun(
27497
- {
27498
- name: "w:drawing",
27499
- elements: [resultNode]
27500
- },
27501
- []
27502
- );
26313
+ return { type: "unknown", handler: null };
27503
26314
  }
27504
- const config$1 = {
27505
- xmlName: XML_NODE_NAME$1,
27506
- sdNodeOrKeyName: SD_NODE_NAME$1,
27507
- type: NodeTranslator.translatorTypes.NODE,
27508
- encode: encode$1,
27509
- decode: decode$1,
27510
- attributes: validXmlAttributes$1
27511
- };
27512
- const translator$1 = NodeTranslator.from(config$1);
27513
26315
  class CommandService {
27514
26316
  /**
27515
26317
  * @param {import('./commands/types/index.js').CommandServiceOptions} props
@@ -28847,10 +27649,7 @@ function prepareTextAnnotation(params) {
28847
27649
  return getTextNodeForExport(attrs.displayLabel, [...marks, ...marksFromAttrs], params);
28848
27650
  }
28849
27651
  function prepareImageAnnotation(params, imageSize) {
28850
- return translator$1.decode({
28851
- ...params,
28852
- imageSize
28853
- });
27652
+ return translateImageNode(params, imageSize);
28854
27653
  }
28855
27654
  function prepareCheckboxAnnotation(params) {
28856
27655
  const {
@@ -29087,7 +27886,7 @@ function translateStructuredContent(params) {
29087
27886
  const XML_NODE_NAME = "w:sdt";
29088
27887
  const SD_NODE_NAME = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
29089
27888
  const validXmlAttributes = [];
29090
- function encode(params) {
27889
+ function encode(params, encodedAttrs) {
29091
27890
  const nodes = params.nodes;
29092
27891
  const node = nodes[0];
29093
27892
  const { type: sdtType, handler: handler2 } = sdtNodeTypeStrategy(node);
@@ -29097,7 +27896,7 @@ function encode(params) {
29097
27896
  const result = handler2(params);
29098
27897
  return result;
29099
27898
  }
29100
- function decode(params) {
27899
+ function decode(params, decodedAttrs) {
29101
27900
  const { node } = params;
29102
27901
  if (!node || !node.type) {
29103
27902
  return null;
@@ -29128,19 +27927,19 @@ function exportSchemaToJson(params) {
29128
27927
  doc: translateDocumentNode,
29129
27928
  body: translateBodyNode,
29130
27929
  heading: translateHeadingNode,
29131
- paragraph: translator$R,
27930
+ paragraph: translator$h,
29132
27931
  text: translateTextNode,
29133
27932
  bulletList: translateList,
29134
27933
  orderedList: translateList,
29135
- lineBreak: translator$T,
29136
- table: translator$6,
29137
- tableRow: translator$D,
29138
- tableCell: translator$5,
27934
+ lineBreak: translator$j,
27935
+ table: translateTable,
27936
+ tableRow: translator$3,
27937
+ tableCell: translator$2,
29139
27938
  bookmarkStart: translateBookmarkStart,
29140
27939
  fieldAnnotation: translator,
29141
- tab: translator$S,
29142
- image: translator$1,
29143
- hardBreak: translator$T,
27940
+ tab: translator$i,
27941
+ image: translateImageNode,
27942
+ hardBreak: translator$j,
29144
27943
  commentRangeStart: () => translateCommentNode(params, "Start"),
29145
27944
  commentRangeEnd: () => translateCommentNode(params, "End"),
29146
27945
  commentReference: () => null,
@@ -29472,7 +28271,7 @@ function translateTextNode(params) {
29472
28271
  const isTrackedNode = node.marks?.some((m2) => trackedMarks.includes(m2.type));
29473
28272
  if (isTrackedNode) return translateTrackedNode(params);
29474
28273
  const isLinkNode = node.marks?.some((m2) => m2.type === "link");
29475
- if (isLinkNode) return translator$4.decode(params);
28274
+ if (isLinkNode) return translator$1.decode(params);
29476
28275
  const { text, marks = [] } = node;
29477
28276
  return getTextNodeForExport(text, marks, params);
29478
28277
  }
@@ -29605,6 +28404,20 @@ function addNewLinkRelationship(params, link) {
29605
28404
  });
29606
28405
  return newId;
29607
28406
  }
28407
+ function addNewImageRelationship(params, imagePath) {
28408
+ const newId = "rId" + generateDocxRandomId();
28409
+ const newRel = {
28410
+ type: "element",
28411
+ name: "Relationship",
28412
+ attributes: {
28413
+ Id: newId,
28414
+ Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
28415
+ Target: imagePath
28416
+ }
28417
+ };
28418
+ params.relationships.push(newRel);
28419
+ return newId;
28420
+ }
29608
28421
  function translateList(params) {
29609
28422
  const { node, editor } = params;
29610
28423
  const listItem = node.content[0];
@@ -29747,6 +28560,165 @@ const generateNumPrTag = (numId, level) => {
29747
28560
  ]
29748
28561
  };
29749
28562
  };
28563
+ function translateTable(params) {
28564
+ params.node = preProcessVerticalMergeCells(params.node, params);
28565
+ const elements = translateChildNodes(params);
28566
+ const tableProperties = generateTableProperties(params.node);
28567
+ const gridProperties = generateTableGrid(params.node, params);
28568
+ elements.unshift(tableProperties);
28569
+ elements.unshift(gridProperties);
28570
+ return {
28571
+ name: "w:tbl",
28572
+ elements
28573
+ };
28574
+ }
28575
+ function preProcessVerticalMergeCells(table, { editorSchema }) {
28576
+ const { content } = table;
28577
+ for (let rowIndex = 0; rowIndex < content.length; rowIndex++) {
28578
+ const row = content[rowIndex];
28579
+ if (!row.content) continue;
28580
+ for (let cellIndex = 0; cellIndex < row.content?.length; cellIndex++) {
28581
+ const cell = row.content[cellIndex];
28582
+ if (!cell) continue;
28583
+ const { attrs } = cell;
28584
+ if (attrs.rowspan > 1) {
28585
+ const rowsToChange = content.slice(rowIndex + 1, rowIndex + attrs.rowspan);
28586
+ const mergedCell = {
28587
+ type: cell.type,
28588
+ content: [
28589
+ // cells must end with a paragraph
28590
+ editorSchema.nodes.paragraph.createAndFill().toJSON()
28591
+ ],
28592
+ attrs: {
28593
+ ...cell.attrs,
28594
+ // reset colspan and rowspan
28595
+ colspan: null,
28596
+ rowspan: null,
28597
+ // to add vMerge
28598
+ continueMerge: true
28599
+ }
28600
+ };
28601
+ rowsToChange.forEach((rowToChange) => {
28602
+ rowToChange.content.splice(cellIndex, 0, mergedCell);
28603
+ });
28604
+ }
28605
+ }
28606
+ }
28607
+ return table;
28608
+ }
28609
+ function generateTableProperties(node) {
28610
+ const elements = [];
28611
+ const { attrs } = node;
28612
+ const { tableWidth, tableStyleId, borders, tableIndent, tableLayout, tableCellSpacing, justification } = attrs;
28613
+ if (tableStyleId) {
28614
+ const tableStyleElement = {
28615
+ name: "w:tblStyle",
28616
+ attributes: { "w:val": tableStyleId }
28617
+ };
28618
+ elements.push(tableStyleElement);
28619
+ }
28620
+ if (borders) {
28621
+ const borderElement = generateTableBorders(node);
28622
+ elements.push(borderElement);
28623
+ }
28624
+ if (tableIndent) {
28625
+ const { width, type: type2 } = tableIndent;
28626
+ const tableIndentElement = {
28627
+ name: "w:tblInd",
28628
+ attributes: { "w:w": pixelsToTwips(width), "w:type": type2 }
28629
+ };
28630
+ elements.push(tableIndentElement);
28631
+ }
28632
+ if (tableLayout) {
28633
+ const tableLayoutElement = {
28634
+ name: "w:tblLayout",
28635
+ attributes: { "w:type": tableLayout }
28636
+ };
28637
+ elements.push(tableLayoutElement);
28638
+ }
28639
+ if (tableWidth && tableWidth.width) {
28640
+ const tableWidthElement = {
28641
+ name: "w:tblW",
28642
+ attributes: { "w:w": pixelsToTwips(tableWidth.width), "w:type": tableWidth.type }
28643
+ };
28644
+ elements.push(tableWidthElement);
28645
+ }
28646
+ if (tableCellSpacing) {
28647
+ elements.push({
28648
+ name: "w:tblCellSpacing",
28649
+ attributes: {
28650
+ "w:w": tableCellSpacing.w,
28651
+ "w:type": tableCellSpacing.type
28652
+ }
28653
+ });
28654
+ }
28655
+ if (justification) {
28656
+ const justificationElement = {
28657
+ name: "w:jc",
28658
+ attributes: { "w:val": justification }
28659
+ };
28660
+ elements.push(justificationElement);
28661
+ }
28662
+ return {
28663
+ name: "w:tblPr",
28664
+ elements
28665
+ };
28666
+ }
28667
+ function generateTableBorders(node) {
28668
+ const { borders } = node.attrs;
28669
+ const elements = [];
28670
+ if (!borders) return;
28671
+ const borderTypes = ["top", "bottom", "left", "right", "insideH", "insideV"];
28672
+ borderTypes.forEach((type2) => {
28673
+ const border = borders[type2];
28674
+ if (!border) return;
28675
+ let attributes = {};
28676
+ if (!Object.keys(border).length || !border.size) {
28677
+ attributes = {
28678
+ "w:val": "nil"
28679
+ };
28680
+ } else {
28681
+ attributes = {
28682
+ "w:val": "single",
28683
+ "w:sz": pixelsToEightPoints(border.size),
28684
+ "w:space": border.space || 0,
28685
+ "w:color": border?.color?.substring(1) || "000000"
28686
+ };
28687
+ }
28688
+ const borderElement = {
28689
+ name: `w:${type2}`,
28690
+ attributes
28691
+ };
28692
+ elements.push(borderElement);
28693
+ });
28694
+ return {
28695
+ name: "w:tblBorders",
28696
+ elements
28697
+ };
28698
+ }
28699
+ function generateTableGrid(node, params) {
28700
+ const { editorSchema } = params;
28701
+ let colgroup = [];
28702
+ try {
28703
+ const pmNode = editorSchema.nodeFromJSON(node);
28704
+ const cellMinWidth = 10;
28705
+ const { colgroupValues } = createColGroup(pmNode, cellMinWidth);
28706
+ colgroup = colgroupValues;
28707
+ } catch {
28708
+ colgroup = [];
28709
+ }
28710
+ const elements = [];
28711
+ colgroup?.forEach((width) => {
28712
+ elements.push({
28713
+ name: "w:gridCol",
28714
+ attributes: { "w:w": pixelsToTwips(width) }
28715
+ });
28716
+ });
28717
+ return {
28718
+ name: "w:tblGrid",
28719
+ elements
28720
+ };
28721
+ }
29750
28722
  function translateBookmarkStart(params) {
29751
28723
  const bookmarkStartNode = {
29752
28724
  name: "w:bookmarkStart",
@@ -29799,44 +28771,370 @@ function translateMark(mark) {
29799
28771
  const parsedValue = value.split(", ");
29800
28772
  markElement.attributes[attr] = parsedValue[0] ? parsedValue[0] : value;
29801
28773
  });
29802
- break;
29803
- // Add ability to get run styleIds from textStyle marks and inject to run properties in word
29804
- case "styleId":
29805
- markElement.name = "w:rStyle";
29806
- markElement.attributes["w:val"] = attrs.styleId;
29807
- break;
29808
- case "color":
29809
- let processedColor = attrs.color.replace(/^#/, "").replace(/;$/, "");
29810
- if (processedColor.startsWith("rgb")) {
29811
- processedColor = rgbToHex(processedColor);
29812
- }
29813
- markElement.attributes["w:val"] = processedColor;
29814
- break;
29815
- case "textAlign":
29816
- markElement.attributes["w:val"] = attrs.textAlign;
29817
- break;
29818
- case "textIndent":
29819
- markElement.attributes["w:firstline"] = inchesToTwips(attrs.textIndent);
29820
- break;
29821
- case "textTransform":
29822
- if (attrs?.textTransform === "none") {
29823
- markElement.attributes["w:val"] = "0";
29824
- } else {
29825
- delete markElement.attributes;
29826
- }
29827
- markElement.type = "element";
29828
- break;
29829
- case "lineHeight":
29830
- markElement.attributes["w:line"] = linesToTwips(attrs.lineHeight);
29831
- break;
29832
- case "highlight":
29833
- markElement.attributes["w:fill"] = attrs.color?.substring(1);
29834
- markElement.attributes["w:color"] = "auto";
29835
- markElement.attributes["w:val"] = "clear";
29836
- markElement.name = "w:shd";
29837
- break;
28774
+ break;
28775
+ // Add ability to get run styleIds from textStyle marks and inject to run properties in word
28776
+ case "styleId":
28777
+ markElement.name = "w:rStyle";
28778
+ markElement.attributes["w:val"] = attrs.styleId;
28779
+ break;
28780
+ case "color":
28781
+ let processedColor = attrs.color.replace(/^#/, "").replace(/;$/, "");
28782
+ if (processedColor.startsWith("rgb")) {
28783
+ processedColor = rgbToHex(processedColor);
28784
+ }
28785
+ markElement.attributes["w:val"] = processedColor;
28786
+ break;
28787
+ case "textAlign":
28788
+ markElement.attributes["w:val"] = attrs.textAlign;
28789
+ break;
28790
+ case "textIndent":
28791
+ markElement.attributes["w:firstline"] = inchesToTwips(attrs.textIndent);
28792
+ break;
28793
+ case "textTransform":
28794
+ if (attrs?.textTransform === "none") {
28795
+ markElement.attributes["w:val"] = "0";
28796
+ } else {
28797
+ delete markElement.attributes;
28798
+ }
28799
+ markElement.type = "element";
28800
+ break;
28801
+ case "lineHeight":
28802
+ markElement.attributes["w:line"] = linesToTwips(attrs.lineHeight);
28803
+ break;
28804
+ case "highlight":
28805
+ markElement.attributes["w:fill"] = attrs.color?.substring(1);
28806
+ markElement.attributes["w:color"] = "auto";
28807
+ markElement.attributes["w:val"] = "clear";
28808
+ markElement.name = "w:shd";
28809
+ break;
28810
+ }
28811
+ return markElement;
28812
+ }
28813
+ function getPngDimensions(base64) {
28814
+ if (!base64) return {};
28815
+ const type2 = base64.split(";")[0].split("/")[1];
28816
+ if (!base64 || type2 !== "png") {
28817
+ return {
28818
+ originalWidth: void 0,
28819
+ originalHeight: void 0
28820
+ };
28821
+ }
28822
+ let header = base64.split(",")[1].slice(0, 50);
28823
+ let uint8 = Uint8Array.from(atob(header), (c) => c.charCodeAt(0));
28824
+ let dataView = new DataView(uint8.buffer, 0, 28);
28825
+ return {
28826
+ originalWidth: dataView.getInt32(16),
28827
+ originalHeight: dataView.getInt32(20)
28828
+ };
28829
+ }
28830
+ function getScaledSize(originalWidth, originalHeight, maxWidth, maxHeight) {
28831
+ let scaledWidth = originalWidth;
28832
+ let scaledHeight = originalHeight;
28833
+ let ratio = Math.min(maxWidth / originalWidth, maxHeight / originalHeight);
28834
+ scaledWidth = Math.round(scaledWidth * ratio);
28835
+ scaledHeight = Math.round(scaledHeight * ratio);
28836
+ return { scaledWidth, scaledHeight };
28837
+ }
28838
+ function translateImageNode(params, imageSize) {
28839
+ const {
28840
+ node: { attrs = {} },
28841
+ tableCell
28842
+ } = params;
28843
+ let imageId = attrs.rId;
28844
+ const src = attrs.src || attrs.imageSrc;
28845
+ const { originalWidth, originalHeight } = getPngDimensions(src);
28846
+ const imageName = params.node.type === "image" ? src.split("/").pop() : attrs.fieldId?.replace("-", "_");
28847
+ let size = attrs.size ? {
28848
+ w: pixelsToEmu(attrs.size.width),
28849
+ h: pixelsToEmu(attrs.size.height)
28850
+ } : imageSize;
28851
+ if (originalWidth && originalHeight) {
28852
+ const boxWidthPx = emuToPixels(size.w);
28853
+ const boxHeightPx = emuToPixels(size.h);
28854
+ const { scaledWidth, scaledHeight } = getScaledSize(originalWidth, originalHeight, boxWidthPx, boxHeightPx);
28855
+ size = {
28856
+ w: pixelsToEmu(scaledWidth),
28857
+ h: pixelsToEmu(scaledHeight)
28858
+ };
28859
+ }
28860
+ if (tableCell) {
28861
+ const colwidthSum = tableCell.attrs.colwidth.reduce((acc, curr) => acc + curr, 0);
28862
+ const leftMargin = tableCell.attrs.cellMargins?.left || 8;
28863
+ const rightMargin = tableCell.attrs.cellMargins?.right || 8;
28864
+ const maxWidthEmu = pixelsToEmu(colwidthSum - (leftMargin + rightMargin));
28865
+ const { width: w2, height: h2 } = resizeKeepAspectRatio(size.w, size.h, maxWidthEmu);
28866
+ if (w2 && h2) size = { w: w2, h: h2 };
28867
+ }
28868
+ if (params.node.type === "image" && !imageId) {
28869
+ const path = src?.split("word/")[1];
28870
+ imageId = addNewImageRelationship(params, path);
28871
+ } else if (params.node.type === "fieldAnnotation" && !imageId) {
28872
+ const type2 = src?.split(";")[0].split("/")[1];
28873
+ if (!type2) {
28874
+ return prepareTextAnnotation(params);
28875
+ }
28876
+ const imageUrl = `media/${imageName}_${attrs.hash}.${type2}`;
28877
+ imageId = addNewImageRelationship(params, imageUrl);
28878
+ params.media[`${imageName}_${attrs.hash}.${type2}`] = src;
28879
+ }
28880
+ let inlineAttrs = attrs.originalPadding || {
28881
+ distT: 0,
28882
+ distB: 0,
28883
+ distL: 0,
28884
+ distR: 0
28885
+ };
28886
+ const anchorElements = [];
28887
+ let wrapProp = [];
28888
+ if (attrs.isAnchor) {
28889
+ inlineAttrs = {
28890
+ ...inlineAttrs,
28891
+ simplePos: attrs.originalAttributes?.simplePos,
28892
+ relativeHeight: 1,
28893
+ behindDoc: attrs.originalAttributes?.behindDoc,
28894
+ locked: attrs.originalAttributes?.locked,
28895
+ layoutInCell: attrs.originalAttributes?.layoutInCell,
28896
+ allowOverlap: attrs.originalAttributes?.allowOverlap
28897
+ };
28898
+ if (attrs.simplePos) {
28899
+ anchorElements.push({
28900
+ name: "wp:simplePos",
28901
+ attributes: {
28902
+ x: 0,
28903
+ y: 0
28904
+ }
28905
+ });
28906
+ }
28907
+ if (attrs.anchorData) {
28908
+ anchorElements.push({
28909
+ name: "wp:positionH",
28910
+ attributes: {
28911
+ relativeFrom: attrs.anchorData.hRelativeFrom
28912
+ },
28913
+ ...attrs.marginOffset.left !== void 0 && {
28914
+ elements: [
28915
+ {
28916
+ name: "wp:posOffset",
28917
+ elements: [
28918
+ {
28919
+ type: "text",
28920
+ text: pixelsToEmu(attrs.marginOffset.left).toString()
28921
+ }
28922
+ ]
28923
+ }
28924
+ ]
28925
+ },
28926
+ ...attrs.anchorData.alignH && {
28927
+ elements: [
28928
+ {
28929
+ name: "wp:align",
28930
+ elements: [
28931
+ {
28932
+ type: "text",
28933
+ text: attrs.anchorData.alignH
28934
+ }
28935
+ ]
28936
+ }
28937
+ ]
28938
+ }
28939
+ });
28940
+ anchorElements.push({
28941
+ name: "wp:positionV",
28942
+ attributes: {
28943
+ relativeFrom: attrs.anchorData.vRelativeFrom
28944
+ },
28945
+ ...attrs.marginOffset.top !== void 0 && {
28946
+ elements: [
28947
+ {
28948
+ name: "wp:posOffset",
28949
+ elements: [
28950
+ {
28951
+ type: "text",
28952
+ text: pixelsToEmu(attrs.marginOffset.top).toString()
28953
+ }
28954
+ ]
28955
+ }
28956
+ ]
28957
+ },
28958
+ ...attrs.anchorData.alignV && {
28959
+ elements: [
28960
+ {
28961
+ name: "wp:align",
28962
+ elements: [
28963
+ {
28964
+ type: "text",
28965
+ text: attrs.anchorData.alignV
28966
+ }
28967
+ ]
28968
+ }
28969
+ ]
28970
+ }
28971
+ });
28972
+ }
28973
+ if (attrs.wrapText) {
28974
+ wrapProp.push({
28975
+ name: "wp:wrapSquare",
28976
+ attributes: {
28977
+ wrapText: attrs.wrapText
28978
+ }
28979
+ });
28980
+ }
28981
+ if (attrs.wrapTopAndBottom) {
28982
+ wrapProp.push({
28983
+ name: "wp:wrapTopAndBottom"
28984
+ });
28985
+ }
28986
+ if (attrs.isAnchor && !wrapProp.length) {
28987
+ wrapProp.push({
28988
+ name: "wp:wrapNone"
28989
+ });
28990
+ }
29838
28991
  }
29839
- return markElement;
28992
+ const drawingXmlns = "http://schemas.openxmlformats.org/drawingml/2006/main";
28993
+ const pictureXmlns = "http://schemas.openxmlformats.org/drawingml/2006/picture";
28994
+ const textNode = wrapTextInRun(
28995
+ {
28996
+ name: "w:drawing",
28997
+ elements: [
28998
+ {
28999
+ name: attrs.isAnchor ? "wp:anchor" : "wp:inline",
29000
+ attributes: inlineAttrs,
29001
+ elements: [
29002
+ ...anchorElements,
29003
+ {
29004
+ name: "wp:extent",
29005
+ attributes: {
29006
+ cx: size.w,
29007
+ cy: size.h
29008
+ }
29009
+ },
29010
+ {
29011
+ name: "wp:effectExtent",
29012
+ attributes: {
29013
+ l: 0,
29014
+ t: 0,
29015
+ r: 0,
29016
+ b: 0
29017
+ }
29018
+ },
29019
+ ...wrapProp,
29020
+ {
29021
+ name: "wp:docPr",
29022
+ attributes: {
29023
+ id: attrs.id || 0,
29024
+ name: attrs.alt || `Picture ${imageName}`
29025
+ }
29026
+ },
29027
+ {
29028
+ name: "wp:cNvGraphicFramePr",
29029
+ elements: [
29030
+ {
29031
+ name: "a:graphicFrameLocks",
29032
+ attributes: {
29033
+ "xmlns:a": drawingXmlns,
29034
+ noChangeAspect: 1
29035
+ }
29036
+ }
29037
+ ]
29038
+ },
29039
+ {
29040
+ name: "a:graphic",
29041
+ attributes: { "xmlns:a": drawingXmlns },
29042
+ elements: [
29043
+ {
29044
+ name: "a:graphicData",
29045
+ attributes: { uri: pictureXmlns },
29046
+ elements: [
29047
+ {
29048
+ name: "pic:pic",
29049
+ attributes: { "xmlns:pic": pictureXmlns },
29050
+ elements: [
29051
+ {
29052
+ name: "pic:nvPicPr",
29053
+ elements: [
29054
+ {
29055
+ name: "pic:cNvPr",
29056
+ attributes: {
29057
+ id: attrs.id || 0,
29058
+ name: attrs.title || `Picture ${imageName}`
29059
+ }
29060
+ },
29061
+ {
29062
+ name: "pic:cNvPicPr",
29063
+ elements: [
29064
+ {
29065
+ name: "a:picLocks",
29066
+ attributes: {
29067
+ noChangeAspect: 1,
29068
+ noChangeArrowheads: 1
29069
+ }
29070
+ }
29071
+ ]
29072
+ }
29073
+ ]
29074
+ },
29075
+ {
29076
+ name: "pic:blipFill",
29077
+ elements: [
29078
+ {
29079
+ name: "a:blip",
29080
+ attributes: {
29081
+ "r:embed": imageId
29082
+ }
29083
+ },
29084
+ {
29085
+ name: "a:stretch",
29086
+ elements: [{ name: "a:fillRect" }]
29087
+ }
29088
+ ]
29089
+ },
29090
+ {
29091
+ name: "pic:spPr",
29092
+ attributes: {
29093
+ bwMode: "auto"
29094
+ },
29095
+ elements: [
29096
+ {
29097
+ name: "a:xfrm",
29098
+ elements: [
29099
+ {
29100
+ name: "a:ext",
29101
+ attributes: {
29102
+ cx: size.w,
29103
+ cy: size.h
29104
+ }
29105
+ },
29106
+ {
29107
+ name: "a:off",
29108
+ attributes: {
29109
+ x: 0,
29110
+ y: 0
29111
+ }
29112
+ }
29113
+ ]
29114
+ },
29115
+ {
29116
+ name: "a:prstGeom",
29117
+ attributes: { prst: "rect" },
29118
+ elements: [{ name: "a:avLst" }]
29119
+ },
29120
+ {
29121
+ name: "a:noFill"
29122
+ }
29123
+ ]
29124
+ }
29125
+ ]
29126
+ }
29127
+ ]
29128
+ }
29129
+ ]
29130
+ }
29131
+ ]
29132
+ }
29133
+ ]
29134
+ },
29135
+ []
29136
+ );
29137
+ return textNode;
29840
29138
  }
29841
29139
  function translateShapeContainer(params) {
29842
29140
  const { node } = params;
@@ -30015,6 +29313,14 @@ generateXml_fn = function(node) {
30015
29313
  if (!selfClosing) tags.push(`</${name}>`);
30016
29314
  return tags;
30017
29315
  };
29316
+ function resizeKeepAspectRatio(width, height, maxWidth) {
29317
+ if (width > maxWidth) {
29318
+ let scale = maxWidth / width;
29319
+ let newHeight = Math.round(height * scale);
29320
+ return { width: maxWidth, height: newHeight };
29321
+ }
29322
+ return { width, height };
29323
+ }
30018
29324
  const translatePageNumberNode = (params) => {
30019
29325
  const outputMarks = processOutputMarks(params.node.attrs?.marksAsAttrs || []);
30020
29326
  return getAutoPageJson("PAGE", outputMarks);
@@ -30098,7 +29404,7 @@ const getInitialJSON = (parsedDocx, fallbackXml = defaultInitialXml) => {
30098
29404
  return parsedDocx["word/document.xml"] || parseXmlToJson(fallbackXml);
30099
29405
  };
30100
29406
  const handleDrawingNode = (params) => {
30101
- const { nodes } = params;
29407
+ const { nodes, filename } = params;
30102
29408
  const validNodes = ["w:drawing", "w:p"];
30103
29409
  if (nodes.length === 0 || !validNodes.includes(nodes[0].name)) {
30104
29410
  return { nodes: [], consumed: 0 };
@@ -30108,9 +29414,167 @@ const handleDrawingNode = (params) => {
30108
29414
  if (mainNode.name === "w:drawing") node = mainNode;
30109
29415
  else node = mainNode.elements.find((el) => el.name === "w:drawing");
30110
29416
  if (!node) return { nodes: [], consumed: 0 };
30111
- const schemaNode = translator$1.encode(params);
30112
- const newNodes = schemaNode ? [schemaNode] : [];
30113
- return { nodes: newNodes, consumed: 1 };
29417
+ let result;
29418
+ const { elements } = node;
29419
+ const currentFileName = filename || null;
29420
+ const isAnchor = elements.find((el) => el.name === "wp:anchor");
29421
+ if (isAnchor) {
29422
+ result = handleImageImport(elements[0], currentFileName, params);
29423
+ if (result && result.attrs) result.attrs.isAnchor = isAnchor;
29424
+ }
29425
+ const inlineImage = elements.find((el) => el.name === "wp:inline");
29426
+ if (inlineImage) result = handleImageImport(inlineImage, currentFileName, params);
29427
+ return { nodes: result ? [result] : [], consumed: 1 };
29428
+ };
29429
+ function handleImageImport(node, currentFileName, params) {
29430
+ const { docx } = params;
29431
+ const { attributes } = node;
29432
+ const padding = {
29433
+ top: emuToPixels(attributes["distT"]),
29434
+ bottom: emuToPixels(attributes["distB"]),
29435
+ left: emuToPixels(attributes["distL"]),
29436
+ right: emuToPixels(attributes["distR"])
29437
+ };
29438
+ const extent = node.elements.find((el) => el.name === "wp:extent");
29439
+ const size = {
29440
+ width: emuToPixels(extent.attributes?.cx),
29441
+ height: emuToPixels(extent.attributes?.cy)
29442
+ };
29443
+ const graphic = node.elements.find((el) => el.name === "a:graphic");
29444
+ const graphicData = graphic.elements.find((el) => el.name === "a:graphicData");
29445
+ const { uri: uri2 } = graphicData?.attributes || {};
29446
+ const shapeURI = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
29447
+ if (!!uri2 && uri2 === shapeURI) {
29448
+ return handleShapeDrawing(params, node, graphicData);
29449
+ }
29450
+ const picture = graphicData.elements.find((el) => el.name === "pic:pic");
29451
+ if (!picture || !picture.elements) return null;
29452
+ const blipFill = picture.elements.find((el) => el.name === "pic:blipFill");
29453
+ const blip = blipFill.elements.find((el) => el.name === "a:blip");
29454
+ const positionHTag = node.elements.find((el) => el.name === "wp:positionH");
29455
+ const positionH = positionHTag?.elements.find((el) => el.name === "wp:posOffset");
29456
+ const positionHValue = emuToPixels(positionH?.elements[0]?.text);
29457
+ const hRelativeFrom = positionHTag?.attributes.relativeFrom;
29458
+ const alignH = positionHTag?.elements.find((el) => el.name === "wp:align")?.elements[0]?.text;
29459
+ const positionVTag = node.elements.find((el) => el.name === "wp:positionV");
29460
+ const positionV = positionVTag?.elements?.find((el) => el.name === "wp:posOffset");
29461
+ const positionVValue = emuToPixels(positionV?.elements[0]?.text);
29462
+ const vRelativeFrom = positionVTag?.attributes.relativeFrom;
29463
+ const alignV = positionVTag?.elements?.find((el) => el.name === "wp:align")?.elements[0]?.text;
29464
+ const simplePos = node.elements.find((el) => el.name === "wp:simplePos");
29465
+ const wrapSquare = node.elements.find((el) => el.name === "wp:wrapSquare");
29466
+ const wrapTopAndBottom = node.elements.find((el) => el.name === "wp:wrapTopAndBottom");
29467
+ const docPr = node.elements.find((el) => el.name === "wp:docPr");
29468
+ let anchorData = null;
29469
+ if (hRelativeFrom || alignH || vRelativeFrom || alignV) {
29470
+ anchorData = {
29471
+ hRelativeFrom,
29472
+ vRelativeFrom,
29473
+ alignH,
29474
+ alignV
29475
+ };
29476
+ }
29477
+ const marginOffset = {
29478
+ left: positionHValue,
29479
+ top: positionVValue
29480
+ };
29481
+ const { attributes: blipAttributes = {} } = blip;
29482
+ const rEmbed = blipAttributes["r:embed"];
29483
+ if (!rEmbed) return null;
29484
+ const currentFile = currentFileName || "document.xml";
29485
+ let rels = docx[`word/_rels/${currentFile}.rels`];
29486
+ if (!rels) rels = docx[`word/_rels/document.xml.rels`];
29487
+ const relationships = rels.elements.find((el) => el.name === "Relationships");
29488
+ const { elements } = relationships;
29489
+ const rel = elements.find((el) => el.attributes["Id"] === rEmbed);
29490
+ if (!rel) return null;
29491
+ const { attributes: relAttributes } = rel;
29492
+ const targetPath = relAttributes["Target"];
29493
+ let path = `word/${targetPath}`;
29494
+ if (targetPath.startsWith("/word") || targetPath.startsWith("/media")) path = targetPath.substring(1);
29495
+ const extension = targetPath.substring(targetPath.lastIndexOf(".") + 1);
29496
+ return {
29497
+ type: "image",
29498
+ attrs: {
29499
+ src: path,
29500
+ alt: ["emf", "wmf"].includes(extension) ? "Unable to render EMF/WMF image" : docPr?.attributes.name || "Image",
29501
+ extension,
29502
+ id: docPr?.attributes.id || "",
29503
+ title: docPr?.attributes.descr || "Image",
29504
+ inline: true,
29505
+ padding,
29506
+ marginOffset,
29507
+ size,
29508
+ anchorData,
29509
+ ...simplePos && {
29510
+ simplePos: {
29511
+ x: simplePos.attributes.x,
29512
+ y: simplePos.attributes.y
29513
+ }
29514
+ },
29515
+ ...wrapSquare && {
29516
+ wrapText: wrapSquare.attributes.wrapText
29517
+ },
29518
+ wrapTopAndBottom: !!wrapTopAndBottom,
29519
+ originalPadding: {
29520
+ distT: attributes["distT"],
29521
+ distB: attributes["distB"],
29522
+ distL: attributes["distL"],
29523
+ distR: attributes["distR"]
29524
+ },
29525
+ originalAttributes: node.attributes,
29526
+ rId: relAttributes["Id"]
29527
+ }
29528
+ };
29529
+ }
29530
+ const handleShapeDrawing = (params, node, graphicData) => {
29531
+ const wsp = graphicData.elements.find((el) => el.name === "wps:wsp");
29532
+ const textBox = wsp.elements.find((el) => el.name === "wps:txbx");
29533
+ const textBoxContent = textBox?.elements?.find((el) => el.name === "w:txbxContent");
29534
+ node.elements.find((el) => el.name === "wp:docPr");
29535
+ const spPr = wsp.elements.find((el) => el.name === "wps:spPr");
29536
+ const prstGeom = spPr?.elements.find((el) => el.name === "a:prstGeom");
29537
+ if (!!prstGeom && prstGeom.attributes["prst"] === "rect" && !textBoxContent) {
29538
+ return getRectangleShape(params, spPr);
29539
+ }
29540
+ if (!textBoxContent) {
29541
+ return null;
29542
+ }
29543
+ const { nodeListHandler } = params;
29544
+ const translatedElement = nodeListHandler.handler({
29545
+ ...params,
29546
+ node: textBoxContent.elements[0],
29547
+ nodes: textBoxContent.elements,
29548
+ path: [...params.path || [], textBoxContent]
29549
+ });
29550
+ return translatedElement[0];
29551
+ };
29552
+ const getRectangleShape = (params, node) => {
29553
+ const schemaAttrs = {};
29554
+ const [drawingNode] = params.nodes;
29555
+ if (drawingNode?.name === "w:drawing") {
29556
+ schemaAttrs.drawingContent = drawingNode;
29557
+ }
29558
+ const xfrm = node.elements.find((el) => el.name === "a:xfrm");
29559
+ const start = xfrm.elements.find((el) => el.name === "a:off");
29560
+ const size = xfrm.elements.find((el) => el.name === "a:ext");
29561
+ const solidFill = node.elements.find((el) => el.name === "a:solidFill");
29562
+ node.elements.find((el) => el.name === "a:ln");
29563
+ const rectangleSize = {
29564
+ top: emuToPixels(start.attributes["y"]),
29565
+ left: emuToPixels(start.attributes["x"]),
29566
+ width: emuToPixels(size.attributes["cx"]),
29567
+ height: emuToPixels(size.attributes["cy"])
29568
+ };
29569
+ schemaAttrs.size = rectangleSize;
29570
+ const background = solidFill?.elements[0]?.attributes["val"];
29571
+ if (background) {
29572
+ schemaAttrs.background = "#" + background;
29573
+ }
29574
+ return {
29575
+ type: "contentBlock",
29576
+ attrs: schemaAttrs
29577
+ };
30114
29578
  };
30115
29579
  const drawingNodeHandlerEntity = {
30116
29580
  handlerName: "drawingNodeHandler",
@@ -30210,7 +29674,7 @@ const trackChangeNodeHandlerEntity = {
30210
29674
  handlerName: "trackChangeNodeHandler",
30211
29675
  handler: handleTrackChangeNode
30212
29676
  };
30213
- const hyperlinkNodeHandlerEntity = generateV2HandlerEntity("hyperlinkNodeHandler", translator$4);
29677
+ const hyperlinkNodeHandlerEntity = generateV2HandlerEntity("hyperlinkNodeHandler", translator$1);
30214
29678
  const handleRunNode = (params) => {
30215
29679
  const { nodes, nodeListHandler, parentStyleId, docx } = params;
30216
29680
  if (nodes.length === 0 || nodes[0].name !== "w:r") {
@@ -30322,7 +29786,7 @@ const handleParagraphNode = (params) => {
30322
29786
  if (nodes.length === 0 || nodes[0].name !== "w:p") {
30323
29787
  return { nodes: [], consumed: 0 };
30324
29788
  }
30325
- const schemaNode = translator$R.encode(params);
29789
+ const schemaNode = translator$h.encode(params);
30326
29790
  const newNodes = schemaNode ? [schemaNode] : [];
30327
29791
  return { nodes: newNodes, consumed: 1 };
30328
29792
  };
@@ -30425,7 +29889,7 @@ const handler = (params) => {
30425
29889
  if (nodes.length === 0 || nodes[0].name !== "w:br") {
30426
29890
  return { nodes: [], consumed: 0 };
30427
29891
  }
30428
- const result = translator$T.encode(params);
29892
+ const result = translator$j.encode(params);
30429
29893
  if (!result) return { nodes: [], consumed: 0 };
30430
29894
  return {
30431
29895
  nodes: [result],
@@ -31121,7 +30585,7 @@ const handleTabNode = (params) => {
31121
30585
  if (!nodes.length || nodes[0].name !== "w:tab") {
31122
30586
  return { nodes: [], consumed: 0 };
31123
30587
  }
31124
- const node = translator$S.encode(params);
30588
+ const node = translator$i.encode(params);
31125
30589
  return { nodes: [node], consumed: 1 };
31126
30590
  };
31127
30591
  const tabNodeEntityHandler = {
@@ -31426,8 +30890,8 @@ function addDefaultStylesIfMissing(styles) {
31426
30890
  }
31427
30891
  const importHeadersFooters = (docx, converter, mainEditor) => {
31428
30892
  const rels = docx["word/_rels/document.xml.rels"];
31429
- const relationships = rels?.elements.find((el) => el.name === "Relationships");
31430
- const { elements } = relationships || { elements: [] };
30893
+ const relationships = rels.elements.find((el) => el.name === "Relationships");
30894
+ const { elements } = relationships;
31431
30895
  const headerType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header";
31432
30896
  const footerType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer";
31433
30897
  const headers = elements.filter((el) => el.attributes["Type"] === headerType);
@@ -32201,12 +31665,15 @@ export {
32201
31665
  createDocFromMarkdown as a7,
32202
31666
  createDocFromHTML as a8,
32203
31667
  EditorState as a9,
32204
- getActiveFormatting as aA,
32205
- readFromClipboard as aB,
32206
- handleClipboardPaste as aC,
32207
- getFileObject as aD,
32208
- _sfc_main as aE,
32209
- registeredHandlers as aF,
31668
+ vClickOutside as aA,
31669
+ getActiveFormatting as aB,
31670
+ readFromClipboard as aC,
31671
+ handleClipboardPaste as aD,
31672
+ getFileObject as aE,
31673
+ translator$h as aF,
31674
+ translator$i as aG,
31675
+ translator$j as aH,
31676
+ _sfc_main as aI,
32210
31677
  hasSomeParentWithClass as aa,
32211
31678
  isActive as ab,
32212
31679
  unflattenListsInHtml as ac,
@@ -32221,18 +31688,18 @@ export {
32221
31688
  parseIndentElement as al,
32222
31689
  combineIndents as am,
32223
31690
  StepMap as an,
32224
- SelectionRange as ao,
32225
- Transform as ap,
32226
- isInTable as aq,
32227
- generateDocxRandomId as ar,
32228
- insertNewRelationship as as,
32229
- updateDOMAttributes as at,
32230
- htmlHandler as au,
32231
- commonjsGlobal as av,
32232
- getDefaultExportFromCjs$1 as aw,
32233
- getContentTypesFromXml as ax,
32234
- xmljs as ay,
32235
- vClickOutside as az,
31691
+ getColStyleDeclaration as ao,
31692
+ SelectionRange as ap,
31693
+ Transform as aq,
31694
+ isInTable as ar,
31695
+ createColGroup as as,
31696
+ generateDocxRandomId as at,
31697
+ insertNewRelationship as au,
31698
+ htmlHandler as av,
31699
+ commonjsGlobal as aw,
31700
+ getDefaultExportFromCjs$1 as ax,
31701
+ getContentTypesFromXml as ay,
31702
+ xmljs as az,
32236
31703
  Slice as b,
32237
31704
  DOMParser$1 as c,
32238
31705
  Mark as d,