@harbour-enterprises/superdoc 0.20.0-next.5 → 0.20.0-next.7

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 (92) hide show
  1. package/dist/chunks/{PdfViewer-DcPZsBsK.es.js → PdfViewer-BYyZViQt.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer-Blwty0A0.cjs → PdfViewer-DXtnxGoU.cjs} +1 -1
  3. package/dist/chunks/{index-BB5vhzVT.cjs → index-CMBPzhIR.cjs} +2 -2
  4. package/dist/chunks/{index-BZzn2Rcn.es.js → index-CqLcgYHG.es.js} +2 -2
  5. package/dist/chunks/{super-editor.es-BgBNGRxg.cjs → super-editor.es-5O71lyiI.cjs} +815 -471
  6. package/dist/chunks/{super-editor.es-BTcVSa_f.es.js → super-editor.es-BTalhwn-.es.js} +815 -471
  7. package/dist/core/SuperDoc.d.ts.map +1 -1
  8. package/dist/super-editor/ai-writer.es.js +2 -2
  9. package/dist/super-editor/chunks/{converter-BPTfSIJf.js → converter-kutpjDQU.js} +687 -470
  10. package/dist/super-editor/chunks/{docx-zipper-ikgI-2vM.js → docx-zipper-BjcI24VU.js} +1 -1
  11. package/dist/super-editor/chunks/{editor-hh7sL4Wv.js → editor-CQMKOaY4.js} +134 -9
  12. package/dist/super-editor/chunks/{toolbar-B-apzt27.js → toolbar-Cp6gL4i5.js} +2 -2
  13. package/dist/super-editor/converter.es.js +1 -1
  14. package/dist/super-editor/docx-zipper.es.js +2 -2
  15. package/dist/super-editor/editor.es.js +3 -3
  16. package/dist/super-editor/file-zipper.es.js +1 -1
  17. package/dist/super-editor/src/core/super-converter/v2/importer/tableImporter.d.ts +0 -22
  18. package/dist/super-editor/src/core/super-converter/v3/handlers/utils.d.ts +10 -3
  19. package/dist/super-editor/src/core/super-converter/v3/handlers/w/bidiVisual/bidiVisual-translator.d.ts +6 -0
  20. package/dist/super-editor/src/core/super-converter/v3/handlers/w/bidiVisual/index.d.ts +1 -0
  21. package/dist/super-editor/src/core/super-converter/v3/handlers/w/bottom/bottom-translator.d.ts +6 -0
  22. package/dist/super-editor/src/core/super-converter/v3/handlers/w/bottom/index.d.ts +2 -0
  23. package/dist/super-editor/src/core/super-converter/v3/handlers/w/bottom/marginBottom-translator.d.ts +6 -0
  24. package/dist/super-editor/src/core/super-converter/v3/handlers/w/end/end-translator.d.ts +6 -0
  25. package/dist/super-editor/src/core/super-converter/v3/handlers/w/end/index.d.ts +2 -0
  26. package/dist/super-editor/src/core/super-converter/v3/handlers/w/end/marginEnd-translator.d.ts +6 -0
  27. package/dist/super-editor/src/core/super-converter/v3/handlers/w/gridCol/gridCol-translator.d.ts +6 -0
  28. package/dist/super-editor/src/core/super-converter/v3/handlers/w/gridCol/index.d.ts +1 -0
  29. package/dist/super-editor/src/core/super-converter/v3/handlers/w/insideH/index.d.ts +1 -0
  30. package/dist/super-editor/src/core/super-converter/v3/handlers/w/insideH/insideH-translator.d.ts +6 -0
  31. package/dist/super-editor/src/core/super-converter/v3/handlers/w/insideV/index.d.ts +1 -0
  32. package/dist/super-editor/src/core/super-converter/v3/handlers/w/insideV/insideV-translator.d.ts +6 -0
  33. package/dist/super-editor/src/core/super-converter/v3/handlers/w/left/index.d.ts +2 -0
  34. package/dist/super-editor/src/core/super-converter/v3/handlers/w/left/left-translator.d.ts +6 -0
  35. package/dist/super-editor/src/core/super-converter/v3/handlers/w/left/marginLeft-translator.d.ts +6 -0
  36. package/dist/super-editor/src/core/super-converter/v3/handlers/w/right/index.d.ts +2 -0
  37. package/dist/super-editor/src/core/super-converter/v3/handlers/w/right/marginRight-translator.d.ts +6 -0
  38. package/dist/super-editor/src/core/super-converter/v3/handlers/w/right/right-translator.d.ts +6 -0
  39. package/dist/super-editor/src/core/super-converter/v3/handlers/w/shd/index.d.ts +1 -0
  40. package/dist/super-editor/src/core/super-converter/v3/handlers/w/shd/shd-translator.d.ts +6 -0
  41. package/dist/super-editor/src/core/super-converter/v3/handlers/w/start/index.d.ts +2 -0
  42. package/dist/super-editor/src/core/super-converter/v3/handlers/w/start/marginStart-translator.d.ts +6 -0
  43. package/dist/super-editor/src/core/super-converter/v3/handlers/w/start/start-translator.d.ts +6 -0
  44. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tbl/index.d.ts +1 -0
  45. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tbl/tbl-translator.d.ts +28 -0
  46. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblBorders/index.d.ts +1 -0
  47. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblBorders/tblBorders-translator.d.ts +6 -0
  48. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblCaption/index.d.ts +1 -0
  49. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblCaption/tblCaption-translator.d.ts +6 -0
  50. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblCellMar/index.d.ts +1 -0
  51. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblCellMar/tblCellMar-translator.d.ts +2 -0
  52. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblDescription/index.d.ts +1 -0
  53. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblDescription/tblDescription-translator.d.ts +6 -0
  54. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblGrid/index.d.ts +1 -0
  55. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblGrid/tblGrid-translator.d.ts +5 -0
  56. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblInd/index.d.ts +1 -0
  57. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblInd/tblInd-translator.d.ts +6 -0
  58. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblLayout/index.d.ts +1 -0
  59. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblLayout/tblLayout-translator.d.ts +6 -0
  60. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblLook/index.d.ts +1 -0
  61. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblLook/tblLook-translator.d.ts +6 -0
  62. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblOverlap/index.d.ts +1 -0
  63. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblOverlap/tblOverlap-translator.d.ts +6 -0
  64. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblPr/index.d.ts +1 -0
  65. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblPr/tblPr-translator.d.ts +5 -0
  66. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblStyle/index.d.ts +1 -0
  67. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblStyle/tblStyle-translator.d.ts +6 -0
  68. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblStyleColBandSize/index.d.ts +1 -0
  69. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblStyleColBandSize/tblStyleColBandSize-translator.d.ts +6 -0
  70. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblStyleRowBandSize/index.d.ts +1 -0
  71. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblStyleRowBandSize/tblStyleRowBandSize-translator.d.ts +6 -0
  72. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblW/index.d.ts +1 -0
  73. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblW/tblW-translator.d.ts +6 -0
  74. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblpPr/index.d.ts +1 -0
  75. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblpPr/tblpPr-translator.d.ts +6 -0
  76. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tc/helpers/legacy-handle-table-cell-node.d.ts +1 -1
  77. package/dist/super-editor/src/core/super-converter/v3/handlers/w/top/index.d.ts +2 -0
  78. package/dist/super-editor/src/core/super-converter/v3/handlers/w/top/marginTop-translator.d.ts +6 -0
  79. package/dist/super-editor/src/core/super-converter/v3/handlers/w/top/top-translator.d.ts +6 -0
  80. package/dist/super-editor/src/core/super-converter/v3/node-translator/node-translator.d.ts +3 -1
  81. package/dist/super-editor/src/extensions/image/imageHelpers/fileNameUtils.d.ts +3 -0
  82. package/dist/super-editor/src/extensions/image/imageHelpers/index.d.ts +1 -0
  83. package/dist/super-editor/src/extensions/table/table.d.ts +330 -0
  84. package/dist/super-editor/super-editor.es.js +8 -8
  85. package/dist/super-editor/toolbar.es.js +2 -2
  86. package/dist/super-editor.cjs +1 -1
  87. package/dist/super-editor.es.js +1 -1
  88. package/dist/superdoc.cjs +2 -2
  89. package/dist/superdoc.es.js +2 -2
  90. package/dist/superdoc.umd.js +815 -471
  91. package/dist/superdoc.umd.js.map +1 -1
  92. package/package.json +1 -1
@@ -24136,41 +24136,6 @@
24136
24136
  documentXml: updatedXml
24137
24137
  };
24138
24138
  };
24139
- const getColStyleDeclaration = (minWidth, width) => {
24140
- if (width) {
24141
- return ["width", `${Math.max(width, minWidth)}px`];
24142
- }
24143
- return ["min-width", `${minWidth}px`];
24144
- };
24145
- const createColGroup = (node, cellMinWidth, overrideCol, overrideValue) => {
24146
- let totalWidth = 0;
24147
- let fixedWidth = true;
24148
- const cols = [];
24149
- const colsValues = [];
24150
- const row = node.firstChild;
24151
- if (!row) return {};
24152
- for (let i2 = 0, col = 0; i2 < row.childCount; i2++) {
24153
- const { colspan, colwidth } = row.child(i2).attrs;
24154
- for (let j2 = 0; j2 < colspan; j2++, col++) {
24155
- const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j2];
24156
- totalWidth += hasWidth || cellMinWidth;
24157
- if (!hasWidth) fixedWidth = false;
24158
- const [prop, value] = getColStyleDeclaration(cellMinWidth, hasWidth);
24159
- cols.push(["col", { style: `${prop}: ${value}` }]);
24160
- colsValues.push(parseInt(value, 10));
24161
- }
24162
- }
24163
- const tableWidth = fixedWidth ? `${totalWidth}px` : "";
24164
- const tableMinWidth = fixedWidth ? "" : `${totalWidth}px`;
24165
- const colgroup = ["colgroup", {}, ...cols];
24166
- const colgroupValues = [...colsValues];
24167
- return {
24168
- colgroup,
24169
- tableWidth,
24170
- tableMinWidth,
24171
- colgroupValues
24172
- };
24173
- };
24174
24139
  const lower16 = 65535;
24175
24140
  const factor16 = Math.pow(2, 16);
24176
24141
  function makeRecover(index2, offset2) {
@@ -31940,46 +31905,6 @@ Please report this to https://github.com/markedjs/marked.`, e) {
31940
31905
  }
31941
31906
  ]
31942
31907
  };
31943
- function preProcessVerticalMergeCells(table, { editorSchema }) {
31944
- if (!table || !Array.isArray(table.content)) {
31945
- return table;
31946
- }
31947
- const rows = table.content;
31948
- for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
31949
- const row = rows[rowIndex];
31950
- if (!row) continue;
31951
- if (!Array.isArray(row.content)) {
31952
- row.content = [];
31953
- }
31954
- for (let cellIndex = 0; cellIndex < row.content.length; cellIndex++) {
31955
- const cell = row.content[cellIndex];
31956
- if (!cell) continue;
31957
- const attrs = cell.attrs || {};
31958
- if (!attrs.rowspan || attrs.rowspan <= 1) continue;
31959
- const maxRowspan = Math.min(attrs.rowspan, rows.length - rowIndex);
31960
- for (let offset2 = 1; offset2 < maxRowspan; offset2++) {
31961
- const rowToChange = rows[rowIndex + offset2];
31962
- if (!rowToChange) continue;
31963
- if (!Array.isArray(rowToChange.content)) {
31964
- rowToChange.content = [];
31965
- }
31966
- const existingCell = rowToChange.content[cellIndex];
31967
- if (existingCell?.attrs?.continueMerge) continue;
31968
- const mergedCell = {
31969
- type: cell.type,
31970
- content: [editorSchema.nodes.paragraph.createAndFill().toJSON()],
31971
- attrs: {
31972
- ...cell.attrs,
31973
- rowspan: null,
31974
- continueMerge: true
31975
- }
31976
- };
31977
- rowToChange.content.splice(cellIndex, 0, mergedCell);
31978
- }
31979
- }
31980
- }
31981
- return table;
31982
- }
31983
31908
  const TranslatorTypes = Object.freeze({
31984
31909
  NODE: "node",
31985
31910
  ATTRIBUTE: "attribute"
@@ -32100,37 +32025,37 @@ Please report this to https://github.com/markedjs/marked.`, e) {
32100
32025
  };
32101
32026
  __publicField$2(_NodeTranslator, "translatorTypes", TranslatorTypes);
32102
32027
  let NodeTranslator = _NodeTranslator;
32103
- const encode$m = (attributes) => {
32028
+ const encode$r = (attributes) => {
32104
32029
  return attributes["w:type"];
32105
32030
  };
32106
- const decode$m = (attrs) => {
32031
+ const decode$r = (attrs) => {
32107
32032
  const { lineBreakType } = attrs;
32108
32033
  return lineBreakType;
32109
32034
  };
32110
32035
  const attrConfig$b = Object.freeze({
32111
32036
  xmlName: "w:type",
32112
32037
  sdName: "lineBreakType",
32113
- encode: encode$m,
32114
- decode: decode$m
32038
+ encode: encode$r,
32039
+ decode: decode$r
32115
32040
  });
32116
- const encode$l = (attributes) => {
32041
+ const encode$q = (attributes) => {
32117
32042
  const xmlAttrValue = attributes["w:clear"];
32118
32043
  return xmlAttrValue;
32119
32044
  };
32120
- const decode$l = (attrs) => {
32045
+ const decode$q = (attrs) => {
32121
32046
  const { clear } = attrs;
32122
32047
  return clear;
32123
32048
  };
32124
32049
  const attrConfig$a = Object.freeze({
32125
32050
  xmlName: "w:clear",
32126
32051
  sdName: "clear",
32127
- encode: encode$l,
32128
- decode: decode$l
32052
+ encode: encode$q,
32053
+ decode: decode$q
32129
32054
  });
32130
32055
  const validXmlAttributes$9 = [attrConfig$b, attrConfig$a];
32131
- const XML_NODE_NAME$a = "w:br";
32132
- const SD_NODE_NAME$9 = "lineBreak";
32133
- const encode$k = (_2, encodedAttrs) => {
32056
+ const XML_NODE_NAME$f = "w:br";
32057
+ const SD_NODE_NAME$a = "lineBreak";
32058
+ const encode$p = (_2, encodedAttrs) => {
32134
32059
  const isPageBreak = encodedAttrs?.lineBreakType === "page";
32135
32060
  const translated = {
32136
32061
  type: isPageBreak ? "hardBreak" : "lineBreak"
@@ -32140,7 +32065,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
32140
32065
  }
32141
32066
  return translated;
32142
32067
  };
32143
- const decode$k = (params2, decodedAttrs) => {
32068
+ const decode$p = (params2, decodedAttrs) => {
32144
32069
  const { node } = params2;
32145
32070
  if (!node) return;
32146
32071
  const wBreak = { name: "w:br" };
@@ -32157,63 +32082,63 @@ Please report this to https://github.com/markedjs/marked.`, e) {
32157
32082
  };
32158
32083
  return translated;
32159
32084
  };
32160
- const config$a = {
32161
- xmlName: XML_NODE_NAME$a,
32162
- sdNodeOrKeyName: SD_NODE_NAME$9,
32085
+ const config$d = {
32086
+ xmlName: XML_NODE_NAME$f,
32087
+ sdNodeOrKeyName: SD_NODE_NAME$a,
32163
32088
  type: NodeTranslator.translatorTypes.NODE,
32164
- encode: encode$k,
32165
- decode: decode$k,
32089
+ encode: encode$p,
32090
+ decode: decode$p,
32166
32091
  attributes: validXmlAttributes$9
32167
32092
  };
32168
- const translator$m = NodeTranslator.from(config$a);
32169
- const encode$j = (attributes) => {
32093
+ const translator$T = NodeTranslator.from(config$d);
32094
+ const encode$o = (attributes) => {
32170
32095
  return attributes["w:val"];
32171
32096
  };
32172
- const decode$j = (attrs) => {
32097
+ const decode$o = (attrs) => {
32173
32098
  const { tabSize } = attrs || {};
32174
32099
  return tabSize;
32175
32100
  };
32176
32101
  const attrConfig$9 = Object.freeze({
32177
32102
  xmlName: "w:val",
32178
32103
  sdName: "tabSize",
32179
- encode: encode$j,
32180
- decode: decode$j
32104
+ encode: encode$o,
32105
+ decode: decode$o
32181
32106
  });
32182
- const encode$i = (attributes) => {
32107
+ const encode$n = (attributes) => {
32183
32108
  return attributes["w:leader"];
32184
32109
  };
32185
- const decode$i = (attrs) => {
32110
+ const decode$n = (attrs) => {
32186
32111
  const { leader } = attrs || {};
32187
32112
  return leader;
32188
32113
  };
32189
32114
  const attrConfig$8 = Object.freeze({
32190
32115
  xmlName: "w:leader",
32191
32116
  sdName: "leader",
32192
- encode: encode$i,
32193
- decode: decode$i
32117
+ encode: encode$n,
32118
+ decode: decode$n
32194
32119
  });
32195
- const encode$h = (attributes) => {
32120
+ const encode$m = (attributes) => {
32196
32121
  return attributes["w:pos"];
32197
32122
  };
32198
- const decode$h = (attrs) => {
32123
+ const decode$m = (attrs) => {
32199
32124
  const { pos } = attrs || {};
32200
32125
  return pos;
32201
32126
  };
32202
32127
  const attrConfig$7 = Object.freeze({
32203
32128
  xmlName: "w:pos",
32204
32129
  sdName: "pos",
32205
- encode: encode$h,
32206
- decode: decode$h
32130
+ encode: encode$m,
32131
+ decode: decode$m
32207
32132
  });
32208
32133
  const validXmlAttributes$8 = [attrConfig$9, attrConfig$7, attrConfig$8];
32209
- const XML_NODE_NAME$9 = "w:tab";
32210
- const SD_NODE_NAME$8 = "tab";
32211
- const encode$g = (_2, encodedAttrs = {}) => {
32134
+ const XML_NODE_NAME$e = "w:tab";
32135
+ const SD_NODE_NAME$9 = "tab";
32136
+ const encode$l = (_2, encodedAttrs = {}) => {
32212
32137
  const translated = { type: "tab" };
32213
32138
  if (encodedAttrs) translated.attrs = { ...encodedAttrs };
32214
32139
  return translated;
32215
32140
  };
32216
- const decode$g = (params2, decodedAttrs = {}) => {
32141
+ const decode$l = (params2, decodedAttrs = {}) => {
32217
32142
  const { node } = params2 || {};
32218
32143
  if (!node) return;
32219
32144
  const wTab = { name: "w:tab" };
@@ -32229,15 +32154,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
32229
32154
  }
32230
32155
  return translated;
32231
32156
  };
32232
- const config$9 = {
32233
- xmlName: XML_NODE_NAME$9,
32234
- sdNodeOrKeyName: SD_NODE_NAME$8,
32157
+ const config$c = {
32158
+ xmlName: XML_NODE_NAME$e,
32159
+ sdNodeOrKeyName: SD_NODE_NAME$9,
32235
32160
  type: NodeTranslator.translatorTypes.NODE,
32236
- encode: encode$g,
32237
- decode: decode$g,
32161
+ encode: encode$l,
32162
+ decode: decode$l,
32238
32163
  attributes: validXmlAttributes$8
32239
32164
  };
32240
- const translator$l = NodeTranslator.from(config$9);
32165
+ const translator$S = NodeTranslator.from(config$c);
32241
32166
  const mergeTextNodes = (nodes) => {
32242
32167
  if (!nodes || !Array.isArray(nodes)) {
32243
32168
  return nodes;
@@ -32807,89 +32732,89 @@ Please report this to https://github.com/markedjs/marked.`, e) {
32807
32732
  }
32808
32733
  return schemaNode;
32809
32734
  };
32810
- const encode$f = (attributes) => {
32735
+ const encode$k = (attributes) => {
32811
32736
  return attributes["w:rsidDel"];
32812
32737
  };
32813
- const decode$f = (attrs) => {
32738
+ const decode$k = (attrs) => {
32814
32739
  return attrs.rsidDel;
32815
32740
  };
32816
32741
  const attrConfig$6 = Object.freeze({
32817
32742
  xmlName: "w:rsidDel",
32818
32743
  sdName: "rsidDel",
32819
- encode: encode$f,
32820
- decode: decode$f
32744
+ encode: encode$k,
32745
+ decode: decode$k
32821
32746
  });
32822
- const encode$e = (attributes) => {
32747
+ const encode$j = (attributes) => {
32823
32748
  return attributes["w:rsidP"];
32824
32749
  };
32825
- const decode$e = (attrs) => {
32750
+ const decode$j = (attrs) => {
32826
32751
  return attrs.rsidP;
32827
32752
  };
32828
32753
  const attrConfig$5 = Object.freeze({
32829
32754
  xmlName: "w:rsidP",
32830
32755
  sdName: "rsidP",
32831
- encode: encode$e,
32832
- decode: decode$e
32756
+ encode: encode$j,
32757
+ decode: decode$j
32833
32758
  });
32834
- const encode$d = (attributes) => {
32759
+ const encode$i = (attributes) => {
32835
32760
  return attributes["w:rsidR"];
32836
32761
  };
32837
- const decode$d = (attrs) => {
32762
+ const decode$i = (attrs) => {
32838
32763
  return attrs.rsidR;
32839
32764
  };
32840
32765
  const attrConfig$4 = Object.freeze({
32841
32766
  xmlName: "w:rsidR",
32842
32767
  sdName: "rsidR",
32843
- encode: encode$d,
32844
- decode: decode$d
32768
+ encode: encode$i,
32769
+ decode: decode$i
32845
32770
  });
32846
- const encode$c = (attributes) => {
32771
+ const encode$h = (attributes) => {
32847
32772
  return attributes["w:rsidRPr"];
32848
32773
  };
32849
- const decode$c = (attrs) => {
32774
+ const decode$h = (attrs) => {
32850
32775
  return attrs.rsidRPr;
32851
32776
  };
32852
32777
  const attrConfig$3 = Object.freeze({
32853
32778
  xmlName: "w:rsidRPr",
32854
32779
  sdName: "rsidRPr",
32855
- encode: encode$c,
32856
- decode: decode$c
32780
+ encode: encode$h,
32781
+ decode: decode$h
32857
32782
  });
32858
- const encode$b = (attributes) => {
32783
+ const encode$g = (attributes) => {
32859
32784
  return attributes["w:rsidRDefault"];
32860
32785
  };
32861
- const decode$b = (attrs) => {
32786
+ const decode$g = (attrs) => {
32862
32787
  return attrs.rsidRDefault;
32863
32788
  };
32864
32789
  const attrConfig$2 = Object.freeze({
32865
32790
  xmlName: "w:rsidRDefault",
32866
32791
  sdName: "rsidRDefault",
32867
- encode: encode$b,
32868
- decode: decode$b
32792
+ encode: encode$g,
32793
+ decode: decode$g
32869
32794
  });
32870
- const encode$a = (attributes) => {
32795
+ const encode$f = (attributes) => {
32871
32796
  return attributes["w14:paraId"];
32872
32797
  };
32873
- const decode$a = (attrs) => {
32798
+ const decode$f = (attrs) => {
32874
32799
  return attrs.paraId;
32875
32800
  };
32876
32801
  const attrConfig$1 = Object.freeze({
32877
32802
  xmlName: "w14:paraId",
32878
32803
  sdName: "paraId",
32879
- encode: encode$a,
32880
- decode: decode$a
32804
+ encode: encode$f,
32805
+ decode: decode$f
32881
32806
  });
32882
- const encode$9 = (attributes) => {
32807
+ const encode$e = (attributes) => {
32883
32808
  return attributes["w14:textId"];
32884
32809
  };
32885
- const decode$9 = (attrs) => {
32810
+ const decode$e = (attrs) => {
32886
32811
  return attrs.textId;
32887
32812
  };
32888
32813
  const attrConfig = Object.freeze({
32889
32814
  xmlName: "w14:textId",
32890
32815
  sdName: "textId",
32891
- encode: encode$9,
32892
- decode: decode$9
32816
+ encode: encode$e,
32817
+ decode: decode$e
32893
32818
  });
32894
32819
  const validXmlAttributes$7 = [
32895
32820
  attrConfig$1,
@@ -32900,9 +32825,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
32900
32825
  attrConfig$3,
32901
32826
  attrConfig$6
32902
32827
  ];
32903
- const XML_NODE_NAME$8 = "w:p";
32904
- const SD_NODE_NAME$7 = "paragraph";
32905
- const encode$8 = (params2, encodedAttrs = {}) => {
32828
+ const XML_NODE_NAME$d = "w:p";
32829
+ const SD_NODE_NAME$8 = "paragraph";
32830
+ const encode$d = (params2, encodedAttrs = {}) => {
32906
32831
  const node = handleParagraphNode$1(params2);
32907
32832
  if (!node) return void 0;
32908
32833
  if (encodedAttrs && Object.keys(encodedAttrs).length) {
@@ -32910,7 +32835,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
32910
32835
  }
32911
32836
  return node;
32912
32837
  };
32913
- const decode$8 = (params2, decodedAttrs = {}) => {
32838
+ const decode$d = (params2, decodedAttrs = {}) => {
32914
32839
  const translated = translateParagraphNode(params2);
32915
32840
  if (!translated) return void 0;
32916
32841
  if (decodedAttrs && Object.keys(decodedAttrs).length) {
@@ -32918,15 +32843,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
32918
32843
  }
32919
32844
  return translated;
32920
32845
  };
32921
- const config$8 = {
32922
- xmlName: XML_NODE_NAME$8,
32923
- sdNodeOrKeyName: SD_NODE_NAME$7,
32846
+ const config$b = {
32847
+ xmlName: XML_NODE_NAME$d,
32848
+ sdNodeOrKeyName: SD_NODE_NAME$8,
32924
32849
  type: NodeTranslator.translatorTypes.NODE,
32925
- encode: encode$8,
32926
- decode: decode$8,
32850
+ encode: encode$d,
32851
+ decode: decode$d,
32927
32852
  attributes: validXmlAttributes$7
32928
32853
  };
32929
- const translator$k = NodeTranslator.from(config$8);
32854
+ const translator$R = NodeTranslator.from(config$b);
32930
32855
  const generateV2HandlerEntity = (handlerName, translator2) => ({
32931
32856
  handlerName,
32932
32857
  handler: (params2) => {
@@ -32954,7 +32879,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
32954
32879
  },
32955
32880
  decode: ({ node }) => {
32956
32881
  const value = node.attrs?.[sdName] != null ? transformDecode(node.attrs[sdName]) : void 0;
32957
- return value != null ? { [attrName]: value } : void 0;
32882
+ return value != null ? { name: xmlName, attributes: { [attrName]: value } } : void 0;
32958
32883
  }
32959
32884
  };
32960
32885
  }
@@ -32972,7 +32897,32 @@ Please report this to https://github.com/markedjs/marked.`, e) {
32972
32897
  },
32973
32898
  decode: function({ node }) {
32974
32899
  const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs[sdName] || {} } });
32975
- return decodedAttrs["w:w"] != null ? decodedAttrs : void 0;
32900
+ return decodedAttrs["w:w"] != null ? { attributes: decodedAttrs } : void 0;
32901
+ }
32902
+ };
32903
+ }
32904
+ function createBorderPropertyHandler(xmlName, sdName = null) {
32905
+ if (!sdName) sdName = xmlName.split(":")[1];
32906
+ return {
32907
+ xmlName,
32908
+ sdNodeOrKeyName: sdName,
32909
+ attributes: [
32910
+ createAttributeHandler("w:val"),
32911
+ createAttributeHandler("w:color"),
32912
+ createAttributeHandler("w:themeColor"),
32913
+ createAttributeHandler("w:themeTint"),
32914
+ createAttributeHandler("w:themeShade"),
32915
+ createAttributeHandler("w:sz", "size", parseInteger, integerToString),
32916
+ createAttributeHandler("w:space", null, parseInteger, integerToString),
32917
+ createAttributeHandler("w:shadow", null, parseBoolean, booleanToString),
32918
+ createAttributeHandler("w:frame", null, parseBoolean, booleanToString)
32919
+ ],
32920
+ encode: (_2, encodedAttrs) => {
32921
+ return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
32922
+ },
32923
+ decode: function({ node }, _2) {
32924
+ const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs[sdName] || {} } });
32925
+ return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
32976
32926
  }
32977
32927
  };
32978
32928
  }
@@ -33015,15 +32965,17 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33015
32965
  Object.keys(properties).forEach((key2) => {
33016
32966
  const translator2 = translatorsBySdName[key2];
33017
32967
  if (translator2) {
33018
- const attributes = translator2.decode({ node: { attrs: { [key2]: properties[key2] } } });
33019
- if (attributes != null) {
33020
- elements.push({ name: translator2.xmlName, attributes });
32968
+ const result = translator2.decode({ node: { attrs: { [key2]: properties[key2] } } });
32969
+ if (result != null) {
32970
+ result.name = translator2.xmlName;
32971
+ elements.push(result);
33021
32972
  }
33022
32973
  }
33023
32974
  });
33024
32975
  return elements;
33025
32976
  }
33026
- const parseBoolean = (value) => ["1", "true"].includes(value);
32977
+ const parseBoolean = (value) => value != null ? ["1", "true"].includes(value) : void 0;
32978
+ const booleanToString = (value) => value != null ? value ? "1" : "0" : void 0;
33027
32979
  const parseInteger = (value) => {
33028
32980
  if (value == null) return void 0;
33029
32981
  const intValue = parseInt(value, 10);
@@ -33033,13 +32985,53 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33033
32985
  const intValue = parseInteger(value);
33034
32986
  return intValue != void 0 ? String(intValue) : void 0;
33035
32987
  };
33036
- const translator$j = NodeTranslator.from({
32988
+ function preProcessVerticalMergeCells(table, { editorSchema }) {
32989
+ if (!table || !Array.isArray(table.content)) {
32990
+ return table;
32991
+ }
32992
+ const rows = table.content;
32993
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
32994
+ const row = rows[rowIndex];
32995
+ if (!row) continue;
32996
+ if (!Array.isArray(row.content)) {
32997
+ row.content = [];
32998
+ }
32999
+ for (let cellIndex = 0; cellIndex < row.content.length; cellIndex++) {
33000
+ const cell = row.content[cellIndex];
33001
+ if (!cell) continue;
33002
+ const attrs = cell.attrs || {};
33003
+ if (!attrs.rowspan || attrs.rowspan <= 1) continue;
33004
+ const maxRowspan = Math.min(attrs.rowspan, rows.length - rowIndex);
33005
+ for (let offset2 = 1; offset2 < maxRowspan; offset2++) {
33006
+ const rowToChange = rows[rowIndex + offset2];
33007
+ if (!rowToChange) continue;
33008
+ if (!Array.isArray(rowToChange.content)) {
33009
+ rowToChange.content = [];
33010
+ }
33011
+ const existingCell = rowToChange.content[cellIndex];
33012
+ if (existingCell?.attrs?.continueMerge) continue;
33013
+ const mergedCell = {
33014
+ type: cell.type,
33015
+ content: [editorSchema.nodes.paragraph.createAndFill().toJSON()],
33016
+ attrs: {
33017
+ ...cell.attrs,
33018
+ rowspan: null,
33019
+ continueMerge: true
33020
+ }
33021
+ };
33022
+ rowToChange.content.splice(cellIndex, 0, mergedCell);
33023
+ }
33024
+ }
33025
+ }
33026
+ return table;
33027
+ }
33028
+ const translator$Q = NodeTranslator.from({
33037
33029
  xmlName: "w:cantSplit",
33038
33030
  sdNodeOrKeyName: "cantSplit",
33039
33031
  encode: ({ nodes }) => ["1", "true"].includes(nodes[0].attributes?.["w:val"] ?? "1"),
33040
- decode: ({ node }) => node.attrs?.cantSplit ? {} : void 0
33032
+ decode: ({ node }) => node.attrs?.cantSplit ? { attributes: {} } : void 0
33041
33033
  });
33042
- const translator$i = NodeTranslator.from({
33034
+ const translator$P = NodeTranslator.from({
33043
33035
  xmlName: "w:cnfStyle",
33044
33036
  sdNodeOrKeyName: "cnfStyle",
33045
33037
  attributes: [
@@ -33054,26 +33046,19 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33054
33046
  "w:lastRowFirstColumn",
33055
33047
  "w:lastRowLastColumn",
33056
33048
  "w:oddHBand",
33057
- "w:oddVBand",
33058
- "w:val"
33059
- ].map((attr) => createAttributeHandler(attr)),
33049
+ "w:oddVBand"
33050
+ ].map((attr) => createAttributeHandler(attr, null, parseBoolean, booleanToString)).concat([createAttributeHandler("w:val")]),
33060
33051
  encode: (_2, encodedAttrs) => {
33061
- Object.keys(encodedAttrs).forEach((key2) => {
33062
- encodedAttrs[key2] = ["1", "true"].includes(encodedAttrs[key2]);
33063
- });
33064
33052
  return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
33065
33053
  },
33066
- decode: ({ node }) => {
33054
+ decode: function({ node }) {
33067
33055
  if (!node.attrs?.cnfStyle) return;
33068
- const cnfStyleAttrs = {};
33069
- Object.entries(node.attrs.cnfStyle).forEach(([key2, value]) => {
33070
- cnfStyleAttrs[`w:${key2}`] = value ? "1" : "0";
33071
- });
33072
- return Object.keys(cnfStyleAttrs).length > 0 ? cnfStyleAttrs : void 0;
33056
+ const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.cnfStyle || {} } });
33057
+ return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
33073
33058
  }
33074
33059
  });
33075
- const translator$h = NodeTranslator.from(createSingleAttrPropertyHandler("w:divId"));
33076
- const translator$g = NodeTranslator.from(
33060
+ const translator$O = NodeTranslator.from(createSingleAttrPropertyHandler("w:divId"));
33061
+ const translator$N = NodeTranslator.from(
33077
33062
  createSingleAttrPropertyHandler(
33078
33063
  "w:gridAfter",
33079
33064
  null,
@@ -33082,7 +33067,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33082
33067
  (v2) => integerToString(v2)
33083
33068
  )
33084
33069
  );
33085
- const translator$f = NodeTranslator.from(
33070
+ const translator$M = NodeTranslator.from(
33086
33071
  createSingleAttrPropertyHandler(
33087
33072
  "w:gridBefore",
33088
33073
  null,
@@ -33091,21 +33076,21 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33091
33076
  (v2) => integerToString(v2)
33092
33077
  )
33093
33078
  );
33094
- const translator$e = NodeTranslator.from({
33079
+ const translator$L = NodeTranslator.from({
33095
33080
  xmlName: "w:hidden",
33096
33081
  sdNodeOrKeyName: "hidden",
33097
33082
  encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
33098
- decode: ({ node }) => node.attrs.hidden ? {} : void 0
33083
+ decode: ({ node }) => node.attrs.hidden ? { attributes: {} } : void 0
33099
33084
  });
33100
- const translator$d = NodeTranslator.from(createSingleAttrPropertyHandler("w:jc"));
33101
- const translator$c = NodeTranslator.from(createMeasurementPropertyHandler("w:tblCellSpacing", "cellSpacing"));
33102
- const translator$b = NodeTranslator.from({
33085
+ const translator$K = NodeTranslator.from(createSingleAttrPropertyHandler("w:jc", "justification"));
33086
+ const translator$J = NodeTranslator.from(createMeasurementPropertyHandler("w:tblCellSpacing", "tableCellSpacing"));
33087
+ const translator$I = NodeTranslator.from({
33103
33088
  xmlName: "w:tblHeader",
33104
33089
  sdNodeOrKeyName: "repeatHeader",
33105
33090
  encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
33106
- decode: ({ node }) => node.attrs.repeatHeader ? {} : void 0
33091
+ decode: ({ node }) => node.attrs.repeatHeader ? { attributes: {} } : void 0
33107
33092
  });
33108
- const translator$a = NodeTranslator.from({
33093
+ const translator$H = NodeTranslator.from({
33109
33094
  xmlName: "w:trHeight",
33110
33095
  sdNodeOrKeyName: "rowHeight",
33111
33096
  encode: ({ nodes }) => {
@@ -33129,14 +33114,14 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33129
33114
  if (node.attrs.rowHeight.rule) {
33130
33115
  heightAttrs["w:hRule"] = node.attrs.rowHeight.rule;
33131
33116
  }
33132
- return Object.keys(heightAttrs).length > 0 ? heightAttrs : void 0;
33117
+ return Object.keys(heightAttrs).length > 0 ? { attributes: heightAttrs } : void 0;
33133
33118
  }
33134
33119
  });
33135
- const translator$9 = NodeTranslator.from(createMeasurementPropertyHandler("w:wAfter"));
33136
- const translator$8 = NodeTranslator.from(createMeasurementPropertyHandler("w:wBefore"));
33137
- const XML_NODE_NAME$7 = "w:trPr";
33138
- const SD_ATTR_KEY = "tableRowProperties";
33139
- const encode$7 = (params2) => {
33120
+ const translator$G = NodeTranslator.from(createMeasurementPropertyHandler("w:wAfter"));
33121
+ const translator$F = NodeTranslator.from(createMeasurementPropertyHandler("w:wBefore"));
33122
+ const XML_NODE_NAME$c = "w:trPr";
33123
+ const SD_ATTR_KEY$4 = "tableRowProperties";
33124
+ const encode$c = (params2) => {
33140
33125
  const { nodes } = params2;
33141
33126
  const node = nodes[0];
33142
33127
  let attributes = {
@@ -33146,18 +33131,18 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33146
33131
  };
33147
33132
  attributes = {
33148
33133
  ...attributes,
33149
- ...encodeProperties(node, propertyTranslatorsByXmlName)
33134
+ ...encodeProperties(node, propertyTranslatorsByXmlName$2)
33150
33135
  };
33151
33136
  return {
33152
33137
  type: NodeTranslator.translatorTypes.ATTRIBUTE,
33153
- xmlName: XML_NODE_NAME$7,
33154
- sdNodeOrKeyName: SD_ATTR_KEY,
33138
+ xmlName: XML_NODE_NAME$c,
33139
+ sdNodeOrKeyName: SD_ATTR_KEY$4,
33155
33140
  attributes
33156
33141
  };
33157
33142
  };
33158
- const decode$7 = (params2) => {
33143
+ const decode$c = (params2) => {
33159
33144
  const { tableRowProperties = {} } = params2.node.attrs || {};
33160
- const elements = decodeProperties(propertyTranslatorsBySdName, tableRowProperties);
33145
+ const elements = decodeProperties(propertyTranslatorsBySdName$2, tableRowProperties);
33161
33146
  const newNode = {
33162
33147
  name: "w:trPr",
33163
33148
  type: "element",
@@ -33166,47 +33151,47 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33166
33151
  };
33167
33152
  return newNode;
33168
33153
  };
33169
- const propertyTranslators = [
33170
- translator$j,
33171
- translator$i,
33172
- translator$h,
33173
- translator$g,
33174
- translator$f,
33175
- translator$e,
33176
- translator$d,
33177
- translator$c,
33178
- translator$b,
33179
- translator$a,
33180
- translator$9,
33181
- translator$8
33154
+ const propertyTranslators$3 = [
33155
+ translator$Q,
33156
+ translator$P,
33157
+ translator$O,
33158
+ translator$N,
33159
+ translator$M,
33160
+ translator$L,
33161
+ translator$K,
33162
+ translator$J,
33163
+ translator$I,
33164
+ translator$H,
33165
+ translator$G,
33166
+ translator$F
33182
33167
  ];
33183
- const propertyTranslatorsByXmlName = {};
33184
- propertyTranslators.forEach((translator2) => {
33185
- propertyTranslatorsByXmlName[translator2.xmlName] = translator2;
33168
+ const propertyTranslatorsByXmlName$2 = {};
33169
+ propertyTranslators$3.forEach((translator2) => {
33170
+ propertyTranslatorsByXmlName$2[translator2.xmlName] = translator2;
33186
33171
  });
33187
- const propertyTranslatorsBySdName = {};
33188
- propertyTranslators.forEach((translator2) => {
33189
- propertyTranslatorsBySdName[translator2.sdNodeOrKeyName] = translator2;
33172
+ const propertyTranslatorsBySdName$2 = {};
33173
+ propertyTranslators$3.forEach((translator2) => {
33174
+ propertyTranslatorsBySdName$2[translator2.sdNodeOrKeyName] = translator2;
33190
33175
  });
33191
- const config$7 = {
33192
- xmlName: XML_NODE_NAME$7,
33193
- sdNodeOrKeyName: SD_ATTR_KEY,
33176
+ const config$a = {
33177
+ xmlName: XML_NODE_NAME$c,
33178
+ sdNodeOrKeyName: SD_ATTR_KEY$4,
33194
33179
  type: NodeTranslator.translatorTypes.ATTRIBUTE,
33195
- encode: encode$7,
33196
- decode: decode$7
33180
+ encode: encode$c,
33181
+ decode: decode$c
33197
33182
  };
33198
- const translator$7 = NodeTranslator.from(config$7);
33199
- const XML_NODE_NAME$6 = "w:tr";
33200
- const SD_NODE_NAME$6 = "tableRow";
33183
+ const translator$E = NodeTranslator.from(config$a);
33184
+ const XML_NODE_NAME$b = "w:tr";
33185
+ const SD_NODE_NAME$7 = "tableRow";
33201
33186
  const validXmlAttributes$6 = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
33202
33187
  (xmlName) => createAttributeHandler(xmlName)
33203
33188
  );
33204
- const encode$6 = (params2, encodedAttrs) => {
33205
- const { row, table } = params2.extraParams;
33189
+ const encode$b = (params2, encodedAttrs) => {
33190
+ const { row } = params2.extraParams;
33206
33191
  let tableRowProperties = {};
33207
33192
  const tPr = row.elements.find((el) => el.name === "w:trPr");
33208
33193
  if (tPr) {
33209
- ({ attributes: tableRowProperties } = translator$7.encode({
33194
+ ({ attributes: tableRowProperties } = translator$E.encode({
33210
33195
  ...params2,
33211
33196
  nodes: [tPr]
33212
33197
  }));
@@ -33214,7 +33199,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33214
33199
  encodedAttrs["tableRowProperties"] = Object.freeze(tableRowProperties);
33215
33200
  encodedAttrs["rowHeight"] = twipsToPixels(tableRowProperties["rowHeight"]?.value);
33216
33201
  encodedAttrs["cantSplit"] = tableRowProperties["cantSplit"];
33217
- const gridColumnWidths = _getGridColumnWidths(table);
33202
+ const { columnWidths: gridColumnWidths } = params2.extraParams;
33218
33203
  const cellNodes = row.elements.filter((el) => el.name === "w:tc");
33219
33204
  let currentColumnIndex = 0;
33220
33205
  const content = cellNodes?.map((n) => {
@@ -33241,16 +33226,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33241
33226
  };
33242
33227
  return newNode;
33243
33228
  };
33244
- const _getGridColumnWidths = (tableNode) => {
33245
- const tblGrid = tableNode.elements.find((el) => el.name === "w:tblGrid");
33246
- if (!tblGrid) return [];
33247
- const columnWidths = tblGrid?.elements?.flatMap((el) => {
33248
- if (el.name !== "w:gridCol") return [];
33249
- return twipsToPixels(el.attributes["w:w"]);
33250
- }) || [];
33251
- return columnWidths;
33252
- };
33253
- const decode$6 = (params2, decodedAttrs) => {
33229
+ const decode$b = (params2, decodedAttrs) => {
33254
33230
  const { node } = params2;
33255
33231
  const elements = translateChildNodes(params2);
33256
33232
  if (node.attrs?.tableRowProperties) {
@@ -33262,7 +33238,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33262
33238
  }
33263
33239
  }
33264
33240
  tableRowProperties["cantSplit"] = node.attrs["cantSplit"];
33265
- const trPr = translator$7.decode({
33241
+ const trPr = translator$E.decode({
33266
33242
  ...params2,
33267
33243
  node: { ...node, attrs: { ...node.attrs, tableRowProperties } }
33268
33244
  });
@@ -33274,86 +33250,348 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33274
33250
  elements
33275
33251
  };
33276
33252
  };
33277
- const config$6 = {
33278
- xmlName: XML_NODE_NAME$6,
33279
- sdNodeOrKeyName: SD_NODE_NAME$6,
33253
+ const config$9 = {
33254
+ xmlName: XML_NODE_NAME$b,
33255
+ sdNodeOrKeyName: SD_NODE_NAME$7,
33280
33256
  type: NodeTranslator.translatorTypes.NODE,
33281
- encode: encode$6,
33282
- decode: decode$6,
33257
+ encode: encode$b,
33258
+ decode: decode$b,
33283
33259
  attributes: validXmlAttributes$6
33284
33260
  };
33285
- const translator$6 = NodeTranslator.from(config$6);
33286
- const handleAllTableNodes = (params2) => {
33287
- const { nodes } = params2;
33288
- if (nodes.length === 0) {
33289
- return { nodes: [], consumed: 0 };
33261
+ const translator$D = NodeTranslator.from(config$9);
33262
+ const translator$C = NodeTranslator.from({
33263
+ xmlName: "w:bidiVisual",
33264
+ sdNodeOrKeyName: "rightToLeft",
33265
+ encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
33266
+ decode: ({ node }) => node.attrs.rightToLeft ? { attributes: {} } : void 0
33267
+ });
33268
+ const translator$B = NodeTranslator.from({
33269
+ xmlName: "w:shd",
33270
+ sdNodeOrKeyName: "shading",
33271
+ attributes: [
33272
+ "w:color",
33273
+ "w:fill",
33274
+ "w:themeColor",
33275
+ "w:themeFill",
33276
+ "w:themeFillShade",
33277
+ "w:themeFillTint",
33278
+ "w:themeShade",
33279
+ "w:themeTint",
33280
+ "w:val"
33281
+ ].map((attr) => createAttributeHandler(attr)),
33282
+ encode: (_2, encodedAttrs) => {
33283
+ return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
33284
+ },
33285
+ decode: function({ node }, _2) {
33286
+ const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.shading || {} } });
33287
+ return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
33288
+ }
33289
+ });
33290
+ const translator$A = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblCaption", "caption"));
33291
+ const translator$z = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblDescription", "description"));
33292
+ const translator$y = NodeTranslator.from(createMeasurementPropertyHandler("w:tblInd", "tableIndent"));
33293
+ const translator$x = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblLayout", "tableLayout", "w:type"));
33294
+ const translator$w = NodeTranslator.from({
33295
+ xmlName: "w:tblLook",
33296
+ sdNodeOrKeyName: "tblLook",
33297
+ attributes: ["w:firstColumn", "w:firstRow", "w:lastColumn", "w:lastRow", "w:noHBand", "w:noVBand"].map((attr) => createAttributeHandler(attr, null, parseBoolean, booleanToString)).concat([createAttributeHandler("w:val")]),
33298
+ encode: (_2, encodedAttrs) => {
33299
+ return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
33300
+ },
33301
+ decode: function({ node }, _2) {
33302
+ const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.tblLook || {} } });
33303
+ return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
33304
+ }
33305
+ });
33306
+ const translator$v = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblOverlap", "overlap"));
33307
+ const translator$u = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblStyle", "tableStyleId"));
33308
+ const translator$t = NodeTranslator.from(
33309
+ createSingleAttrPropertyHandler("w:tblStyleColBandSize", "tableStyleColBandSize")
33310
+ );
33311
+ const translator$s = NodeTranslator.from(
33312
+ createSingleAttrPropertyHandler("w:tblStyleRowBandSize", "tableStyleRowBandSize")
33313
+ );
33314
+ const translator$r = NodeTranslator.from(createMeasurementPropertyHandler("w:tblW", "tableWidth"));
33315
+ const translator$q = NodeTranslator.from({
33316
+ xmlName: "w:tblpPr",
33317
+ sdNodeOrKeyName: "floatingTableProperties",
33318
+ 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))),
33319
+ encode: (_2, encodedAttrs) => {
33320
+ return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
33321
+ },
33322
+ decode: function({ node }, _2) {
33323
+ const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.floatingTableProperties || {} } });
33324
+ return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
33290
33325
  }
33326
+ });
33327
+ const translator$p = NodeTranslator.from(createBorderPropertyHandler("w:bottom"));
33328
+ const translator$o = NodeTranslator.from(createMeasurementPropertyHandler("w:bottom", "marginBottom"));
33329
+ const translator$n = NodeTranslator.from(createBorderPropertyHandler("w:end"));
33330
+ const translator$m = NodeTranslator.from(createMeasurementPropertyHandler("w:end", "marginEnd"));
33331
+ const translator$l = NodeTranslator.from(createBorderPropertyHandler("w:insideH"));
33332
+ const translator$k = NodeTranslator.from(createBorderPropertyHandler("w:insideV"));
33333
+ const translator$j = NodeTranslator.from(createBorderPropertyHandler("w:left"));
33334
+ const translator$i = NodeTranslator.from(createMeasurementPropertyHandler("w:left", "marginLeft"));
33335
+ const translator$h = NodeTranslator.from(createBorderPropertyHandler("w:right"));
33336
+ const translator$g = NodeTranslator.from(createMeasurementPropertyHandler("w:right", "marginRight"));
33337
+ const translator$f = NodeTranslator.from(createBorderPropertyHandler("w:start"));
33338
+ const translator$e = NodeTranslator.from(createMeasurementPropertyHandler("w:start", "marginStart"));
33339
+ const translator$d = NodeTranslator.from(createBorderPropertyHandler("w:top"));
33340
+ const translator$c = NodeTranslator.from(createMeasurementPropertyHandler("w:top", "marginTop"));
33341
+ const XML_NODE_NAME$a = "w:tblBorders";
33342
+ const SD_ATTR_KEY$3 = "borders";
33343
+ const encode$a = (params2, _2) => {
33344
+ const { nodes } = params2;
33345
+ const node = nodes[0];
33346
+ const attributes = encodeProperties(node, tblBordersTranslatorsByXmlName);
33347
+ return Object.keys(attributes).length > 0 ? attributes : void 0;
33348
+ };
33349
+ const decode$a = (params2, _2) => {
33350
+ const { borders = {} } = params2.node.attrs || {};
33351
+ const elements = decodeProperties(tblBordersTranslatorsBySdName, borders);
33352
+ const newNode = {
33353
+ name: "w:tblBorders",
33354
+ type: "element",
33355
+ attributes: {},
33356
+ elements
33357
+ };
33358
+ return newNode;
33359
+ };
33360
+ const propertyTranslators$2 = [
33361
+ translator$p,
33362
+ translator$n,
33363
+ translator$l,
33364
+ translator$k,
33365
+ translator$j,
33366
+ translator$h,
33367
+ translator$f,
33368
+ translator$d
33369
+ ];
33370
+ const tblBordersTranslatorsByXmlName = {};
33371
+ const tblBordersTranslatorsBySdName = {};
33372
+ propertyTranslators$2.forEach((translator2) => {
33373
+ tblBordersTranslatorsByXmlName[translator2.xmlName] = translator2;
33374
+ tblBordersTranslatorsBySdName[translator2.sdNodeOrKeyName] = translator2;
33375
+ });
33376
+ const translator$b = NodeTranslator.from({
33377
+ xmlName: XML_NODE_NAME$a,
33378
+ sdNodeOrKeyName: SD_ATTR_KEY$3,
33379
+ type: NodeTranslator.translatorTypes.NODE,
33380
+ attributes: [],
33381
+ encode: encode$a,
33382
+ decode: decode$a
33383
+ });
33384
+ const XML_NODE_NAME$9 = "w:tblCellMar";
33385
+ const SD_ATTR_KEY$2 = "cellMargins";
33386
+ const encode$9 = (params2, _2) => {
33387
+ const { nodes } = params2;
33388
+ const node = nodes[0];
33389
+ const attributes = encodeProperties(node, propertyTranslatorsByXmlName$1);
33390
+ return Object.keys(attributes).length > 0 ? attributes : void 0;
33391
+ };
33392
+ const decode$9 = (params2, _2) => {
33393
+ const { cellMargins = {} } = params2.node.attrs || {};
33394
+ const elements = decodeProperties(propertyTranslatorsBySdName$1, cellMargins);
33395
+ const newNode = {
33396
+ name: XML_NODE_NAME$9,
33397
+ type: "element",
33398
+ attributes: {},
33399
+ elements
33400
+ };
33401
+ return newNode;
33402
+ };
33403
+ const propertyTranslators$1 = [
33404
+ translator$o,
33405
+ translator$m,
33406
+ translator$i,
33407
+ translator$g,
33408
+ translator$e,
33409
+ translator$c
33410
+ ];
33411
+ const propertyTranslatorsByXmlName$1 = {};
33412
+ const propertyTranslatorsBySdName$1 = {};
33413
+ propertyTranslators$1.forEach((translator2) => {
33414
+ propertyTranslatorsByXmlName$1[translator2.xmlName] = translator2;
33415
+ propertyTranslatorsBySdName$1[translator2.sdNodeOrKeyName] = translator2;
33416
+ });
33417
+ const translator$a = NodeTranslator.from({
33418
+ xmlName: XML_NODE_NAME$9,
33419
+ sdNodeOrKeyName: SD_ATTR_KEY$2,
33420
+ type: NodeTranslator.translatorTypes.NODE,
33421
+ attributes: [],
33422
+ encode: encode$9,
33423
+ decode: decode$9
33424
+ });
33425
+ const XML_NODE_NAME$8 = "w:tblPr";
33426
+ const SD_ATTR_KEY$1 = "tableProperties";
33427
+ const encode$8 = (params2) => {
33428
+ const { nodes } = params2;
33429
+ const node = nodes[0];
33430
+ const attributes = encodeProperties(node, propertyTranslatorsByXmlName);
33431
+ return {
33432
+ xmlName: XML_NODE_NAME$8,
33433
+ sdNodeOrKeyName: SD_ATTR_KEY$1,
33434
+ attributes
33435
+ };
33436
+ };
33437
+ const decode$8 = (params2) => {
33438
+ const { tableProperties = {} } = params2.node.attrs || {};
33439
+ const elements = decodeProperties(propertyTranslatorsBySdName, tableProperties);
33440
+ const newNode = {
33441
+ name: "w:tblPr",
33442
+ type: "element",
33443
+ attributes: {},
33444
+ elements
33445
+ };
33446
+ return newNode;
33447
+ };
33448
+ const propertyTranslators = [
33449
+ translator$C,
33450
+ translator$K,
33451
+ translator$B,
33452
+ translator$A,
33453
+ translator$J,
33454
+ translator$z,
33455
+ translator$y,
33456
+ translator$x,
33457
+ translator$w,
33458
+ translator$v,
33459
+ translator$u,
33460
+ translator$t,
33461
+ translator$s,
33462
+ translator$r,
33463
+ translator$q,
33464
+ translator$b,
33465
+ translator$a
33466
+ ];
33467
+ const propertyTranslatorsByXmlName = {};
33468
+ const propertyTranslatorsBySdName = {};
33469
+ propertyTranslators.forEach((translator2) => {
33470
+ propertyTranslatorsByXmlName[translator2.xmlName] = translator2;
33471
+ propertyTranslatorsBySdName[translator2.sdNodeOrKeyName] = translator2;
33472
+ });
33473
+ const config$8 = {
33474
+ xmlName: XML_NODE_NAME$8,
33475
+ sdNodeOrKeyName: SD_ATTR_KEY$1,
33476
+ encode: encode$8,
33477
+ decode: decode$8
33478
+ };
33479
+ const translator$9 = NodeTranslator.from(config$8);
33480
+ const translator$8 = NodeTranslator.from(
33481
+ createSingleAttrPropertyHandler("w:gridCol", "col", "w:w", parseInteger, integerToString)
33482
+ );
33483
+ const XML_NODE_NAME$7 = "w:tblGrid";
33484
+ const SD_ATTR_KEY = "grid";
33485
+ const cellMinWidth = pixelsToTwips(10);
33486
+ const encode$7 = (params2) => {
33487
+ const { nodes } = params2;
33291
33488
  const node = nodes[0];
33292
- switch (node.name) {
33293
- case "w:tbl":
33294
- return { nodes: [handleTableNode(node, params2)], consumed: 1 };
33489
+ const attributes = encodeProperties(node, { [translator$8.xmlName]: translator$8 }, true);
33490
+ return {
33491
+ xmlName: XML_NODE_NAME$7,
33492
+ sdNodeOrKeyName: SD_ATTR_KEY,
33493
+ attributes
33494
+ };
33495
+ };
33496
+ const decode$7 = (params2) => {
33497
+ const { grid = [] } = params2.node.attrs || {};
33498
+ const { firstRow = {} } = params2.extraParams || {};
33499
+ const cellNodes = firstRow.content?.filter((n) => n.type === "tableCell") ?? [];
33500
+ const numberOfColumns = cellNodes.length || grid.length;
33501
+ const elements = [];
33502
+ for (let cellIdx = 0; cellIdx < numberOfColumns; cellIdx++) {
33503
+ const cell = cellNodes[cellIdx];
33504
+ const { colspan = 1, colwidth } = cell?.attrs || {};
33505
+ for (let mergedCellIdx = 0; mergedCellIdx < colspan; mergedCellIdx++) {
33506
+ const cellWidthPixels = colwidth && colwidth[mergedCellIdx];
33507
+ const colGridAttrs = grid?.[mergedCellIdx] || {};
33508
+ const gridWidthTwips = colGridAttrs.col;
33509
+ const gridWidthPixels = twipsToPixels(gridWidthTwips);
33510
+ let cellWidthTwips;
33511
+ if (gridWidthPixels === cellWidthPixels) {
33512
+ cellWidthTwips = gridWidthTwips;
33513
+ } else if (cellWidthPixels) {
33514
+ cellWidthTwips = pixelsToTwips(cellWidthPixels);
33515
+ }
33516
+ const widthTwips = Math.max(cellWidthTwips, cellMinWidth);
33517
+ elements.push(
33518
+ translator$8.decode({
33519
+ node: { type: (
33520
+ /** @type {string} */
33521
+ translator$8.sdNodeOrKeyName
33522
+ ), attrs: { col: widthTwips } }
33523
+ })
33524
+ );
33525
+ }
33295
33526
  }
33296
- return { nodes: [], consumed: 0 };
33527
+ const newNode = {
33528
+ name: XML_NODE_NAME$7,
33529
+ attributes: {},
33530
+ elements
33531
+ };
33532
+ return newNode;
33297
33533
  };
33298
- const tableNodeHandlerEntity = {
33299
- handlerName: "tableNodeHandler",
33300
- handler: handleAllTableNodes
33534
+ const config$7 = {
33535
+ xmlName: XML_NODE_NAME$7,
33536
+ sdNodeOrKeyName: SD_ATTR_KEY,
33537
+ encode: encode$7,
33538
+ decode: decode$7
33301
33539
  };
33302
- function handleTableNode(node, params2) {
33303
- const { docx, nodeListHandler } = params2;
33540
+ const translator$7 = NodeTranslator.from(config$7);
33541
+ const XML_NODE_NAME$6 = "w:tbl";
33542
+ const SD_NODE_NAME$6 = "table";
33543
+ const encode$6 = (params2, encodedAttrs) => {
33544
+ const { nodes } = params2;
33545
+ const node = nodes[0];
33304
33546
  const tblPr = node.elements.find((el) => el.name === "w:tblPr");
33305
- const tableBordersElement = tblPr.elements.find((el) => el.name === "w:tblBorders");
33306
- const tableBorders = tableBordersElement?.elements || [];
33307
- const { borders, rowBorders } = processTableBorders(tableBorders);
33308
- const tblStyleTag = tblPr.elements.find((el) => el.name === "w:tblStyle");
33309
- const tableStyleId = tblStyleTag?.attributes["w:val"];
33310
- const attrs = { tableStyleId };
33311
- const tableIndent = tblPr?.elements.find((el) => el.name === "w:tblInd");
33312
- if (tableIndent) {
33313
- const { "w:w": width, "w:type": type2 } = tableIndent.attributes;
33314
- attrs["tableIndent"] = { width: twipsToPixels(width), type: type2 };
33315
- }
33316
- const tableLayout = tblPr?.elements.find((el) => el.name === "w:tblLayout");
33317
- if (tableLayout) {
33318
- const { "w:type": type2 } = tableLayout.attributes;
33319
- attrs["tableLayout"] = type2;
33320
- }
33321
- const referencedStyles = getReferencedTableStyles(tblStyleTag, docx);
33322
- const tblW = tblPr.elements.find((el) => el.name === "w:tblW");
33323
- if (tblW) {
33324
- attrs["tableWidth"] = {
33325
- width: twipsToPixels(tblW.attributes["w:w"]),
33326
- type: tblW.attributes["w:type"]
33327
- };
33328
- }
33329
- const tblCellSpacing = tblPr.elements.find((el) => el.name === "w:tblCellSpacing");
33330
- if (tblCellSpacing) {
33331
- attrs["tableCellSpacing"] = {
33332
- w: tblCellSpacing.attributes["w:w"],
33333
- type: tblCellSpacing.attributes["w:type"]
33334
- };
33335
- attrs["borderCollapse"] = "separate";
33336
- }
33337
- const tblJustification = tblPr.elements.find((el) => el.name === "w:jc");
33338
- if (tblJustification?.attributes) {
33339
- attrs["justification"] = tblJustification.attributes["w:val"];
33547
+ if (tblPr) {
33548
+ encodedAttrs["tableProperties"] = translator$9.encode({ ...params2, nodes: [tblPr] }).attributes;
33549
+ }
33550
+ const tblGrid = node.elements.find((el) => el.name === "w:tblGrid");
33551
+ if (tblGrid) {
33552
+ encodedAttrs["grid"] = translator$7.encode({ ...params2, nodes: [tblGrid] }).attributes;
33553
+ }
33554
+ [
33555
+ "tableStyleId",
33556
+ "justification",
33557
+ "tableLayout",
33558
+ ["tableIndent", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
33559
+ ["tableWidth", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
33560
+ ["tableCellSpacing", ({ value, type: type2 }) => ({ w: String(value), type: type2 })]
33561
+ ].forEach((prop) => {
33562
+ let key2;
33563
+ let transform;
33564
+ if (Array.isArray(prop)) {
33565
+ [key2, transform] = prop;
33566
+ } else {
33567
+ key2 = prop;
33568
+ transform = (v2) => v2;
33569
+ }
33570
+ if (encodedAttrs.tableProperties?.[key2]) {
33571
+ encodedAttrs[key2] = transform(encodedAttrs.tableProperties[key2]);
33572
+ }
33573
+ });
33574
+ if (encodedAttrs.tableCellSpacing) {
33575
+ encodedAttrs["borderCollapse"] = "separate";
33340
33576
  }
33577
+ const { borders, rowBorders } = _processTableBorders(encodedAttrs.tableProperties?.borders || {});
33578
+ const referencedStyles = _getReferencedTableStyles(encodedAttrs.tableStyleId, params2);
33341
33579
  const rows = node.elements.filter((el) => el.name === "w:tr");
33342
- const refStylesBorders = referencedStyles?.borders || {};
33343
- const refStylesRowBorders = referencedStyles?.rowBorders || {};
33344
- const borderData = Object.keys(borders)?.length ? Object.assign(refStylesBorders, borders) : refStylesBorders;
33345
- const borderRowData = Object.keys(rowBorders)?.length ? Object.assign(refStylesRowBorders, rowBorders) : refStylesRowBorders;
33346
- attrs["borders"] = borderData;
33580
+ const borderData = Object.assign({}, referencedStyles?.borders || {}, borders || {});
33581
+ const borderRowData = Object.assign({}, referencedStyles?.rowBorders || {}, rowBorders || {});
33582
+ encodedAttrs["borders"] = borderData;
33583
+ const tblStyleTag = tblPr.elements.find((el) => el.name === "w:tblStyle");
33584
+ const columnWidths = (encodedAttrs["grid"] ?? []).map((item) => twipsToPixels(item.col));
33347
33585
  const content = [];
33348
33586
  rows.forEach((row) => {
33349
- const result = translator$6.encode({
33587
+ const result = translator$D.encode({
33350
33588
  ...params2,
33351
33589
  nodes: [row],
33352
33590
  extraParams: {
33353
33591
  row,
33354
- table: node,
33355
33592
  rowBorders: borderRowData,
33356
- styleTag: tblStyleTag
33593
+ styleTag: tblStyleTag,
33594
+ columnWidths
33357
33595
  }
33358
33596
  });
33359
33597
  if (result.content?.length) content.push(result);
@@ -33361,9 +33599,113 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33361
33599
  return {
33362
33600
  type: "table",
33363
33601
  content,
33364
- attrs
33602
+ attrs: encodedAttrs
33603
+ };
33604
+ };
33605
+ const decode$6 = (params2, decodedAttrs) => {
33606
+ params2.node = preProcessVerticalMergeCells(params2.node, params2);
33607
+ const { node } = params2;
33608
+ const elements = translateChildNodes(params2);
33609
+ const firstRow = node.content?.find((n) => n.type === "tableRow");
33610
+ const properties = node.attrs.grid;
33611
+ const element = translator$7.decode({
33612
+ ...params2,
33613
+ node: { ...node, attrs: { ...node.attrs, grid: properties } },
33614
+ extraParams: {
33615
+ firstRow
33616
+ }
33617
+ });
33618
+ if (element) elements.unshift(element);
33619
+ if (node.attrs?.tableProperties) {
33620
+ const properties2 = { ...node.attrs.tableProperties };
33621
+ const element2 = translator$9.decode({
33622
+ ...params2,
33623
+ node: { ...node, attrs: { ...node.attrs, tableProperties: properties2 } }
33624
+ });
33625
+ if (element2) elements.unshift(element2);
33626
+ }
33627
+ return {
33628
+ name: "w:tbl",
33629
+ attributes: decodedAttrs || {},
33630
+ elements
33631
+ };
33632
+ };
33633
+ function _processTableBorders(rawBorders) {
33634
+ const borders = {};
33635
+ const rowBorders = {};
33636
+ Object.entries(rawBorders).forEach(([name, attributes]) => {
33637
+ const attrs = {};
33638
+ const color = attributes.color;
33639
+ const size2 = attributes.size;
33640
+ if (color && color !== "auto") attrs["color"] = color.startsWith("#") ? color : `#${color}`;
33641
+ if (size2 && size2 !== "auto") attrs["size"] = eigthPointsToPixels(size2);
33642
+ const rowBorderNames = ["insideH", "insideV"];
33643
+ if (rowBorderNames.includes(name)) rowBorders[name] = attrs;
33644
+ borders[name] = attrs;
33645
+ });
33646
+ return {
33647
+ borders,
33648
+ rowBorders
33365
33649
  };
33366
33650
  }
33651
+ function _getReferencedTableStyles(tableStyleReference, params2) {
33652
+ if (!tableStyleReference) return null;
33653
+ const stylesToReturn = {};
33654
+ const { docx } = params2;
33655
+ const styles = docx["word/styles.xml"];
33656
+ const { elements } = styles.elements[0];
33657
+ const styleElements = elements.filter((el) => el.name === "w:style");
33658
+ const styleTag = styleElements.find((el) => el.attributes["w:styleId"] === tableStyleReference);
33659
+ if (!styleTag) return null;
33660
+ stylesToReturn.name = styleTag.elements.find((el) => el.name === "w:name");
33661
+ const basedOn = styleTag.elements.find((el) => el.name === "w:basedOn");
33662
+ let baseTblPr;
33663
+ if (basedOn?.attributes) {
33664
+ const baseStyles = styleElements.find((el) => el.attributes["w:styleId"] === basedOn.attributes["w:val"]);
33665
+ baseTblPr = baseStyles ? baseStyles.elements.find((el) => el.name === "w:tblPr") : {};
33666
+ }
33667
+ const pPr = styleTag.elements.find((el) => el.name === "w:pPr");
33668
+ if (pPr) {
33669
+ const justification = pPr.elements.find((el) => el.name === "w:jc");
33670
+ if (justification?.attributes) stylesToReturn.justification = justification.attributes["w:val"];
33671
+ }
33672
+ const rPr = styleTag?.elements.find((el) => el.name === "w:rPr");
33673
+ if (rPr) {
33674
+ const fonts = rPr.elements.find((el) => el.name === "w:rFonts");
33675
+ if (fonts) {
33676
+ const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
33677
+ stylesToReturn.fonts = { ascii, hAnsi, cs };
33678
+ }
33679
+ const fontSize2 = rPr.elements.find((el) => el.name === "w:sz");
33680
+ if (fontSize2?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize2.attributes["w:val"]) + "pt";
33681
+ }
33682
+ const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
33683
+ if (tblPr && tblPr.elements) {
33684
+ if (baseTblPr && baseTblPr.elements) {
33685
+ tblPr.elements.push(...baseTblPr.elements);
33686
+ }
33687
+ const tableProperties = translator$9.encode({ ...params2, nodes: [tblPr] }).attributes;
33688
+ const { borders, rowBorders } = _processTableBorders(tableProperties.borders || {});
33689
+ if (borders) stylesToReturn.borders = borders;
33690
+ if (rowBorders) stylesToReturn.rowBorders = rowBorders;
33691
+ const cellMargins = {};
33692
+ Object.entries(tableProperties.cellMargins || {}).forEach(([key2, attrs]) => {
33693
+ if (attrs?.value) cellMargins[key2] = String(attrs.value);
33694
+ });
33695
+ if (Object.keys(cellMargins).length) stylesToReturn.cellMargins = cellMargins;
33696
+ }
33697
+ return stylesToReturn;
33698
+ }
33699
+ const config$6 = {
33700
+ xmlName: XML_NODE_NAME$6,
33701
+ sdNodeOrKeyName: SD_NODE_NAME$6,
33702
+ type: NodeTranslator.translatorTypes.NODE,
33703
+ encode: encode$6,
33704
+ decode: decode$6,
33705
+ attributes: []
33706
+ };
33707
+ const translator$6 = NodeTranslator.from(config$6);
33708
+ const tableNodeHandlerEntity = generateV2HandlerEntity("tableNodeHandler", translator$6);
33367
33709
  function getReferencedTableStyles(tblStyleTag, docx) {
33368
33710
  if (!tblStyleTag) return null;
33369
33711
  const stylesToReturn = {};
@@ -33444,15 +33786,6 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33444
33786
  rowBorders
33445
33787
  };
33446
33788
  }
33447
- const getGridColumnWidths = (tableNode) => {
33448
- const tblGrid = tableNode.elements.find((el) => el.name === "w:tblGrid");
33449
- if (!tblGrid) return [];
33450
- const columnWidths = tblGrid?.elements?.flatMap((el) => {
33451
- if (el.name !== "w:gridCol") return [];
33452
- return twipsToPixels(el.attributes["w:w"]);
33453
- }) || [];
33454
- return columnWidths;
33455
- };
33456
33789
  function handleTableCellNode({
33457
33790
  params: params2,
33458
33791
  node,
@@ -33461,7 +33794,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33461
33794
  rowBorders,
33462
33795
  styleTag,
33463
33796
  columnIndex,
33464
- columnWidth = null
33797
+ columnWidth = null,
33798
+ allColumnWidths = []
33465
33799
  }) {
33466
33800
  const { docx, nodeListHandler } = params2;
33467
33801
  const tcPr = node.elements.find((el) => el.name === "w:tcPr");
@@ -33475,7 +33809,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33475
33809
  delete rowBorders?.insideV;
33476
33810
  }
33477
33811
  const inlineBorders = processInlineCellBorders(borders, rowBorders);
33478
- const gridColumnWidths = getGridColumnWidths(table);
33812
+ const gridColumnWidths = allColumnWidths;
33479
33813
  const tcWidth = tcPr?.elements?.find((el) => el.name === "w:tcW");
33480
33814
  let width = tcWidth ? twipsToPixels(tcWidth.attributes["w:w"]) : null;
33481
33815
  const widthType = tcWidth?.attributes["w:type"];
@@ -33731,7 +34065,16 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33731
34065
  const SD_NODE_NAME$5 = "tableCell";
33732
34066
  const validXmlAttributes$5 = [];
33733
34067
  function encode$5(params2, encodedAttrs) {
33734
- const { node, table, row, rowBorders, styleTag, columnIndex, columnWidth } = params2.extraParams;
34068
+ const {
34069
+ node,
34070
+ table,
34071
+ row,
34072
+ rowBorders,
34073
+ styleTag,
34074
+ columnIndex,
34075
+ columnWidth,
34076
+ columnWidths: allColumnWidths
34077
+ } = params2.extraParams;
33735
34078
  const schemaNode = handleTableCellNode({
33736
34079
  params: params2,
33737
34080
  node,
@@ -33740,7 +34083,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33740
34083
  rowBorders,
33741
34084
  styleTag,
33742
34085
  columnIndex,
33743
- columnWidth
34086
+ columnWidth,
34087
+ allColumnWidths
33744
34088
  });
33745
34089
  if (encodedAttrs && Object.keys(encodedAttrs).length) {
33746
34090
  schemaNode.attrs = { ...schemaNode.attrs, ...encodedAttrs };
@@ -34682,9 +35026,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
34682
35026
  };
34683
35027
  const translator$2 = NodeTranslator.from(config$2);
34684
35028
  const registeredHandlers = Object.freeze({
34685
- "w:br": translator$m,
34686
- "w:tab": translator$l,
34687
- "w:p": translator$k,
35029
+ "w:br": translator$T,
35030
+ "w:tab": translator$S,
35031
+ "w:p": translator$R,
34688
35032
  "wp:anchor": translator$3,
34689
35033
  "wp:inline": translator$2
34690
35034
  });
@@ -36303,7 +36647,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
36303
36647
  const XML_NODE_NAME = "w:sdt";
36304
36648
  const SD_NODE_NAME = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
36305
36649
  const validXmlAttributes = [];
36306
- function encode$n(params2, encodedAttrs) {
36650
+ function encode$s(params2, encodedAttrs) {
36307
36651
  const nodes = params2.nodes;
36308
36652
  const node = nodes[0];
36309
36653
  const { type: sdtType, handler: handler2 } = sdtNodeTypeStrategy(node);
@@ -36333,7 +36677,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
36333
36677
  xmlName: XML_NODE_NAME,
36334
36678
  sdNodeOrKeyName: SD_NODE_NAME,
36335
36679
  type: NodeTranslator.translatorTypes.NODE,
36336
- encode: encode$n,
36680
+ encode: encode$s,
36337
36681
  decode,
36338
36682
  attributes: validXmlAttributes
36339
36683
  };
@@ -36344,19 +36688,19 @@ Please report this to https://github.com/markedjs/marked.`, e) {
36344
36688
  doc: translateDocumentNode,
36345
36689
  body: translateBodyNode,
36346
36690
  heading: translateHeadingNode,
36347
- paragraph: translator$k,
36691
+ paragraph: translator$R,
36348
36692
  text: translateTextNode,
36349
36693
  bulletList: translateList,
36350
36694
  orderedList: translateList,
36351
- lineBreak: translator$m,
36352
- table: translateTable,
36353
- tableRow: translator$6,
36695
+ lineBreak: translator$T,
36696
+ table: translator$6,
36697
+ tableRow: translator$D,
36354
36698
  tableCell: translator$5,
36355
36699
  bookmarkStart: translateBookmarkStart,
36356
36700
  fieldAnnotation: translator,
36357
- tab: translator$l,
36701
+ tab: translator$S,
36358
36702
  image: translator$1,
36359
- hardBreak: translator$m,
36703
+ hardBreak: translator$T,
36360
36704
  commentRangeStart: () => translateCommentNode(params2, "Start"),
36361
36705
  commentRangeEnd: () => translateCommentNode(params2, "End"),
36362
36706
  commentReference: () => null,
@@ -36963,131 +37307,6 @@ Please report this to https://github.com/markedjs/marked.`, e) {
36963
37307
  ]
36964
37308
  };
36965
37309
  };
36966
- function translateTable(params2) {
36967
- params2.node = preProcessVerticalMergeCells(params2.node, params2);
36968
- const elements = translateChildNodes(params2);
36969
- const tableProperties = generateTableProperties(params2.node);
36970
- const gridProperties = generateTableGrid(params2.node, params2);
36971
- elements.unshift(tableProperties);
36972
- elements.unshift(gridProperties);
36973
- return {
36974
- name: "w:tbl",
36975
- elements
36976
- };
36977
- }
36978
- function generateTableProperties(node) {
36979
- const elements = [];
36980
- const { attrs } = node;
36981
- const { tableWidth, tableStyleId, borders, tableIndent, tableLayout, tableCellSpacing, justification } = attrs;
36982
- if (tableStyleId) {
36983
- const tableStyleElement = {
36984
- name: "w:tblStyle",
36985
- attributes: { "w:val": tableStyleId }
36986
- };
36987
- elements.push(tableStyleElement);
36988
- }
36989
- if (borders) {
36990
- const borderElement = generateTableBorders(node);
36991
- elements.push(borderElement);
36992
- }
36993
- if (tableIndent) {
36994
- const { width, type: type2 } = tableIndent;
36995
- const tableIndentElement = {
36996
- name: "w:tblInd",
36997
- attributes: { "w:w": pixelsToTwips(width), "w:type": type2 }
36998
- };
36999
- elements.push(tableIndentElement);
37000
- }
37001
- if (tableLayout) {
37002
- const tableLayoutElement = {
37003
- name: "w:tblLayout",
37004
- attributes: { "w:type": tableLayout }
37005
- };
37006
- elements.push(tableLayoutElement);
37007
- }
37008
- if (tableWidth && tableWidth.width) {
37009
- const tableWidthElement = {
37010
- name: "w:tblW",
37011
- attributes: { "w:w": pixelsToTwips(tableWidth.width), "w:type": tableWidth.type }
37012
- };
37013
- elements.push(tableWidthElement);
37014
- }
37015
- if (tableCellSpacing) {
37016
- elements.push({
37017
- name: "w:tblCellSpacing",
37018
- attributes: {
37019
- "w:w": tableCellSpacing.w,
37020
- "w:type": tableCellSpacing.type
37021
- }
37022
- });
37023
- }
37024
- if (justification) {
37025
- const justificationElement = {
37026
- name: "w:jc",
37027
- attributes: { "w:val": justification }
37028
- };
37029
- elements.push(justificationElement);
37030
- }
37031
- return {
37032
- name: "w:tblPr",
37033
- elements
37034
- };
37035
- }
37036
- function generateTableBorders(node) {
37037
- const { borders } = node.attrs;
37038
- const elements = [];
37039
- if (!borders) return;
37040
- const borderTypes = ["top", "bottom", "left", "right", "insideH", "insideV"];
37041
- borderTypes.forEach((type2) => {
37042
- const border = borders[type2];
37043
- if (!border) return;
37044
- let attributes = {};
37045
- if (!Object.keys(border).length || !border.size) {
37046
- attributes = {
37047
- "w:val": "nil"
37048
- };
37049
- } else {
37050
- attributes = {
37051
- "w:val": "single",
37052
- "w:sz": pixelsToEightPoints(border.size),
37053
- "w:space": border.space || 0,
37054
- "w:color": border?.color?.substring(1) || "000000"
37055
- };
37056
- }
37057
- const borderElement = {
37058
- name: `w:${type2}`,
37059
- attributes
37060
- };
37061
- elements.push(borderElement);
37062
- });
37063
- return {
37064
- name: "w:tblBorders",
37065
- elements
37066
- };
37067
- }
37068
- function generateTableGrid(node, params2) {
37069
- const { editorSchema } = params2;
37070
- let colgroup = [];
37071
- try {
37072
- const pmNode = editorSchema.nodeFromJSON(node);
37073
- const cellMinWidth = 10;
37074
- const { colgroupValues } = createColGroup(pmNode, cellMinWidth);
37075
- colgroup = colgroupValues;
37076
- } catch {
37077
- colgroup = [];
37078
- }
37079
- const elements = [];
37080
- colgroup?.forEach((width) => {
37081
- elements.push({
37082
- name: "w:gridCol",
37083
- attributes: { "w:w": pixelsToTwips(width) }
37084
- });
37085
- });
37086
- return {
37087
- name: "w:tblGrid",
37088
- elements
37089
- };
37090
- }
37091
37310
  function translateBookmarkStart(params2) {
37092
37311
  const bookmarkStartNode = {
37093
37312
  name: "w:bookmarkStart",
@@ -37663,7 +37882,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
37663
37882
  if (nodes.length === 0 || nodes[0].name !== "w:p") {
37664
37883
  return { nodes: [], consumed: 0 };
37665
37884
  }
37666
- const schemaNode = translator$k.encode(params2);
37885
+ const schemaNode = translator$R.encode(params2);
37667
37886
  const newNodes = schemaNode ? [schemaNode] : [];
37668
37887
  return { nodes: newNodes, consumed: 1 };
37669
37888
  };
@@ -37766,7 +37985,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
37766
37985
  if (nodes.length === 0 || nodes[0].name !== "w:br") {
37767
37986
  return { nodes: [], consumed: 0 };
37768
37987
  }
37769
- const result = translator$m.encode(params2);
37988
+ const result = translator$T.encode(params2);
37770
37989
  if (!result) return { nodes: [], consumed: 0 };
37771
37990
  return {
37772
37991
  nodes: [result],
@@ -38435,7 +38654,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
38435
38654
  if (!nodes.length || nodes[0].name !== "w:tab") {
38436
38655
  return { nodes: [], consumed: 0 };
38437
38656
  }
38438
- const node = translator$l.encode(params2);
38657
+ const node = translator$S.encode(params2);
38439
38658
  return { nodes: [node], consumed: 1 };
38440
38659
  };
38441
38660
  const tabNodeEntityHandler = {
@@ -61185,9 +61404,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61185
61404
  };
61186
61405
  }
61187
61406
  });
61407
+ const getColStyleDeclaration = (minWidth, width) => {
61408
+ if (width) {
61409
+ return ["width", `${Math.max(width, minWidth)}px`];
61410
+ }
61411
+ return ["min-width", `${minWidth}px`];
61412
+ };
61188
61413
  const createTableView = ({ editor }) => {
61189
61414
  return class TableView {
61190
- constructor(node, cellMinWidth) {
61415
+ constructor(node, cellMinWidth2) {
61191
61416
  __publicField$1(this, "editor");
61192
61417
  __publicField$1(this, "node");
61193
61418
  __publicField$1(this, "dom");
@@ -61197,13 +61422,13 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61197
61422
  __publicField$1(this, "cellMinWidth");
61198
61423
  this.editor = editor;
61199
61424
  this.node = node;
61200
- this.cellMinWidth = cellMinWidth;
61425
+ this.cellMinWidth = cellMinWidth2;
61201
61426
  this.dom = document.createElement("div");
61202
61427
  this.dom.className = "tableWrapper";
61203
61428
  this.table = this.dom.appendChild(document.createElement("table"));
61204
61429
  this.colgroup = this.table.appendChild(document.createElement("colgroup"));
61205
61430
  updateTable(this.editor, this.node, this.table);
61206
- updateColumns(node, this.colgroup, this.table, cellMinWidth);
61431
+ updateColumns(node, this.colgroup, this.table, cellMinWidth2);
61207
61432
  this.contentDOM = this.table.appendChild(document.createElement("tbody"));
61208
61433
  setTimeout(() => {
61209
61434
  updateTableWrapper(this.dom, this.table);
@@ -61228,7 +61453,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61228
61453
  }
61229
61454
  };
61230
61455
  };
61231
- function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) {
61456
+ function updateColumns(node, colgroup, table, cellMinWidth2, overrideCol, overrideValue) {
61232
61457
  let totalWidth = 0;
61233
61458
  let fixedWidth = true;
61234
61459
  let nextDOM = colgroup.firstChild;
@@ -61239,16 +61464,16 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61239
61464
  for (let j2 = 0; j2 < colspan; j2++, col++) {
61240
61465
  const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j2];
61241
61466
  const cssWidth = hasWidth ? `${hasWidth}px` : "";
61242
- totalWidth += hasWidth || cellMinWidth;
61467
+ totalWidth += hasWidth || cellMinWidth2;
61243
61468
  if (!hasWidth) fixedWidth = false;
61244
61469
  if (!nextDOM) {
61245
61470
  const col2 = document.createElement("col");
61246
- const [propKey, propVal] = getColStyleDeclaration(cellMinWidth, hasWidth);
61471
+ const [propKey, propVal] = getColStyleDeclaration(cellMinWidth2, hasWidth);
61247
61472
  col2.style.setProperty(propKey, propVal);
61248
61473
  colgroup.appendChild(col2);
61249
61474
  } else {
61250
61475
  if (nextDOM.style.width !== cssWidth) {
61251
- const [propKey, propVal] = getColStyleDeclaration(cellMinWidth, hasWidth);
61476
+ const [propKey, propVal] = getColStyleDeclaration(cellMinWidth2, hasWidth);
61252
61477
  nextDOM.style.setProperty(propKey, propVal);
61253
61478
  }
61254
61479
  nextDOM = nextDOM.nextSibling;
@@ -61345,6 +61570,35 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61345
61570
  const tableBorders = createTableBorders();
61346
61571
  return types2.table.createChecked({ borders: tableBorders }, rows);
61347
61572
  };
61573
+ const createColGroup = (node, cellMinWidth2, overrideCol, overrideValue) => {
61574
+ let totalWidth = 0;
61575
+ let fixedWidth = true;
61576
+ const cols = [];
61577
+ const colsValues = [];
61578
+ const row = node.firstChild;
61579
+ if (!row) return {};
61580
+ for (let i2 = 0, col = 0; i2 < row.childCount; i2++) {
61581
+ const { colspan, colwidth } = row.child(i2).attrs;
61582
+ for (let j2 = 0; j2 < colspan; j2++, col++) {
61583
+ const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j2];
61584
+ totalWidth += hasWidth || cellMinWidth2;
61585
+ if (!hasWidth) fixedWidth = false;
61586
+ const [prop, value] = getColStyleDeclaration(cellMinWidth2, hasWidth);
61587
+ cols.push(["col", { style: `${prop}: ${value}` }]);
61588
+ colsValues.push(parseInt(value, 10));
61589
+ }
61590
+ }
61591
+ const tableWidth = fixedWidth ? `${totalWidth}px` : "";
61592
+ const tableMinWidth = fixedWidth ? "" : `${totalWidth}px`;
61593
+ const colgroup = ["colgroup", {}, ...cols];
61594
+ const colgroupValues = [...colsValues];
61595
+ return {
61596
+ colgroup,
61597
+ tableWidth,
61598
+ tableMinWidth,
61599
+ colgroupValues
61600
+ };
61601
+ };
61348
61602
  var readFromCache;
61349
61603
  var addToCache;
61350
61604
  if (typeof WeakMap != "undefined") {
@@ -63162,7 +63416,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
63162
63416
  );
63163
63417
  function columnResizing({
63164
63418
  handleWidth = 5,
63165
- cellMinWidth = 25,
63419
+ cellMinWidth: cellMinWidth2 = 25,
63166
63420
  defaultCellMinWidth = 100,
63167
63421
  View = TableView,
63168
63422
  lastColumnResizable = true
@@ -63198,7 +63452,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
63198
63452
  handleMouseLeave(view);
63199
63453
  },
63200
63454
  mousedown: (view, event) => {
63201
- handleMouseDown2(view, event, cellMinWidth, defaultCellMinWidth);
63455
+ handleMouseDown2(view, event, cellMinWidth2, defaultCellMinWidth);
63202
63456
  }
63203
63457
  },
63204
63458
  decorations: (state2) => {
@@ -63269,7 +63523,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
63269
63523
  if (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging)
63270
63524
  updateHandle(view, -1);
63271
63525
  }
63272
- function handleMouseDown2(view, event, cellMinWidth, defaultCellMinWidth) {
63526
+ function handleMouseDown2(view, event, cellMinWidth2, defaultCellMinWidth) {
63273
63527
  var _a2;
63274
63528
  if (!view.editable) return false;
63275
63529
  const win = (_a2 = view.dom.ownerDocument.defaultView) != null ? _a2 : window;
@@ -63291,7 +63545,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
63291
63545
  updateColumnWidth(
63292
63546
  view,
63293
63547
  pluginState2.activeHandle,
63294
- draggedWidth(pluginState2.dragging, event2, cellMinWidth)
63548
+ draggedWidth(pluginState2.dragging, event2, cellMinWidth2)
63295
63549
  );
63296
63550
  view.dispatch(
63297
63551
  view.state.tr.setMeta(columnResizingPluginKey, { setDragging: null })
@@ -63303,7 +63557,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
63303
63557
  const pluginState2 = columnResizingPluginKey.getState(view.state);
63304
63558
  if (!pluginState2) return;
63305
63559
  if (pluginState2.dragging) {
63306
- const dragged = draggedWidth(pluginState2.dragging, event2, cellMinWidth);
63560
+ const dragged = draggedWidth(pluginState2.dragging, event2, cellMinWidth2);
63307
63561
  displayColumnWidth(
63308
63562
  view,
63309
63563
  pluginState2.activeHandle,
@@ -63658,6 +63912,24 @@ Please report this to https://github.com/markedjs/marked.`, e) {
63658
63912
  tableCellSpacing: {
63659
63913
  default: null,
63660
63914
  rendered: false
63915
+ },
63916
+ /**
63917
+ * @category Attribute
63918
+ * @param {TableProperties} [tableProperties] - Properties for the table.
63919
+ * @see {@link https://ecma-international.org/publications-and-standards/standards/ecma-376/} "Fundamentals And Markup Language Reference", page 371-483
63920
+ */
63921
+ tableProperties: {
63922
+ default: null,
63923
+ rendered: false
63924
+ },
63925
+ /**
63926
+ * @category Attribute
63927
+ * @param {TableGrid} [grid] - Grid definition for the table
63928
+ * @see {@link https://ecma-international.org/publications-and-standards/standards/ecma-376/} "Fundamentals And Markup Language Reference", page 432
63929
+ */
63930
+ grid: {
63931
+ default: null,
63932
+ rendered: false
63661
63933
  }
63662
63934
  };
63663
63935
  },
@@ -66262,6 +66534,57 @@ Please report this to https://github.com/markedjs/marked.`, e) {
66262
66534
  }
66263
66535
  resample_high_quality(canvas, width, height);
66264
66536
  }
66537
+ const FALLBACK_NAME = "image";
66538
+ const stripDiacritics = (value) => value.normalize("NFKD").replace(/[\u0300-\u036f]/g, "");
66539
+ const sanitizeSegment = (segment, { allowDots = false } = {}) => {
66540
+ if (!segment) return "";
66541
+ const normalized = stripDiacritics(segment).replace(/[\s\u2000-\u206f]+/g, "_").replace(/[\\/]+/g, "_");
66542
+ const allowedPattern = allowDots ? /[^0-9A-Za-z._-]+/g : /[^0-9A-Za-z_-]+/g;
66543
+ let sanitized = normalized.replace(allowedPattern, "_");
66544
+ sanitized = sanitized.replace(/_+/g, "_");
66545
+ sanitized = sanitized.replace(/^[_.-]+/, "");
66546
+ sanitized = sanitized.replace(/[_-]+$/, "");
66547
+ return sanitized;
66548
+ };
66549
+ const splitFileName = (name) => {
66550
+ const trimmed = name?.trim?.() ?? "";
66551
+ const lastDot = trimmed.lastIndexOf(".");
66552
+ if (lastDot <= 0 || lastDot === trimmed.length - 1) {
66553
+ return { base: trimmed, ext: "" };
66554
+ }
66555
+ return {
66556
+ base: trimmed.slice(0, lastDot),
66557
+ ext: trimmed.slice(lastDot + 1)
66558
+ };
66559
+ };
66560
+ const sanitizeImageFileName = (inputName) => {
66561
+ const { base: base2, ext } = splitFileName(inputName || "");
66562
+ const sanitizedBase = sanitizeSegment(base2, { allowDots: true }) || FALLBACK_NAME;
66563
+ const sanitizedExt = sanitizeSegment(ext, { allowDots: false }).toLowerCase();
66564
+ if (!sanitizedExt) return sanitizedBase;
66565
+ return `${sanitizedBase}.${sanitizedExt}`;
66566
+ };
66567
+ const ensureUniqueFileName = (preferredName, existingNames = /* @__PURE__ */ new Set()) => {
66568
+ const sanitized = sanitizeImageFileName(preferredName);
66569
+ if (!existingNames || typeof existingNames.has !== "function") {
66570
+ return sanitized;
66571
+ }
66572
+ const existingSet = /* @__PURE__ */ new Set();
66573
+ existingNames.forEach((name) => existingSet.add(sanitizeImageFileName(name)));
66574
+ if (!existingSet.has(sanitized)) {
66575
+ return sanitized;
66576
+ }
66577
+ const { base: base2, ext } = splitFileName(sanitized);
66578
+ let counter = 1;
66579
+ let candidate = sanitized;
66580
+ const suffix2 = () => `${base2}-${counter}${ext ? `.${ext}` : ""}`;
66581
+ while (existingSet.has(candidate)) {
66582
+ candidate = suffix2();
66583
+ counter += 1;
66584
+ }
66585
+ return candidate;
66586
+ };
66587
+ const buildMediaPath = (fileName) => `word/media/${fileName}`;
66265
66588
  const fileTooLarge = (file) => {
66266
66589
  let fileSizeMb = Number((file.size / (1024 * 1024)).toFixed(4));
66267
66590
  if (fileSizeMb > 5) {
@@ -66295,16 +66618,37 @@ Please report this to https://github.com/markedjs/marked.`, e) {
66295
66618
  tr = addImagePlaceholder(view.state, tr, id, selection.from);
66296
66619
  view.dispatch(tr);
66297
66620
  }
66621
+ const generateUniqueDocPrId = (editor) => {
66622
+ const existingIds = /* @__PURE__ */ new Set();
66623
+ editor?.state?.doc?.descendants((node) => {
66624
+ if (node.type.name === "image" && node.attrs.id !== void 0 && node.attrs.id !== null) {
66625
+ existingIds.add(String(node.attrs.id));
66626
+ }
66627
+ });
66628
+ let candidate;
66629
+ do {
66630
+ const hex2 = generateDocxRandomId();
66631
+ candidate = String(parseInt(hex2, 16));
66632
+ } while (!candidate || existingIds.has(candidate));
66633
+ return candidate;
66634
+ };
66298
66635
  async function uploadAndInsertImage({ editor, view, file, size: size2, id }) {
66299
66636
  const imageUploadHandler = typeof editor.options.handleImageUpload === "function" ? editor.options.handleImageUpload : handleImageUpload;
66637
+ const placeholderId = id;
66300
66638
  try {
66301
- let url = await imageUploadHandler(file);
66302
- let fileName = file.name.replace(" ", "_");
66303
- let placeholderPos = findPlaceholder(view.state, id);
66639
+ const existingFileNames = new Set(Object.keys(editor.storage.image.media ?? {}).map((key2) => key2.split("/").pop()));
66640
+ const uniqueFileName = ensureUniqueFileName(file.name, existingFileNames);
66641
+ const normalizedFile = uniqueFileName === file.name ? file : new File([file], uniqueFileName, {
66642
+ type: file.type,
66643
+ lastModified: file.lastModified ?? Date.now()
66644
+ });
66645
+ let url = await imageUploadHandler(normalizedFile);
66646
+ let placeholderPos = findPlaceholder(view.state, placeholderId);
66304
66647
  if (placeholderPos == null) {
66305
66648
  return;
66306
66649
  }
66307
- let mediaPath = `word/media/${fileName}`;
66650
+ const mediaPath = buildMediaPath(uniqueFileName);
66651
+ const docPrId = generateUniqueDocPrId(editor);
66308
66652
  let rId = null;
66309
66653
  if (editor.options.mode === "docx") {
66310
66654
  const [, path] = mediaPath.split("word/");
@@ -66314,7 +66658,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
66314
66658
  let imageNode = view.state.schema.nodes.image.create({
66315
66659
  src: mediaPath,
66316
66660
  size: size2,
66317
- id,
66661
+ id: docPrId,
66318
66662
  rId
66319
66663
  });
66320
66664
  editor.storage.image.media = Object.assign(editor.storage.image.media, { [mediaPath]: url });
@@ -66323,10 +66667,10 @@ Please report this to https://github.com/markedjs/marked.`, e) {
66323
66667
  }
66324
66668
  let tr = view.state.tr;
66325
66669
  tr.replaceWith(placeholderPos, placeholderPos, imageNode);
66326
- tr = removeImagePlaceholder(view.state, tr, id);
66670
+ tr = removeImagePlaceholder(view.state, tr, placeholderId);
66327
66671
  view.dispatch(tr);
66328
66672
  } catch {
66329
- const tr = removeImagePlaceholder(view.state, view.state.tr, id);
66673
+ const tr = removeImagePlaceholder(view.state, view.state.tr, placeholderId);
66330
66674
  view.dispatch(tr);
66331
66675
  }
66332
66676
  }