@harbour-enterprises/superdoc 0.20.0-next.8 → 0.20.0

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 (126) hide show
  1. package/dist/chunks/{PdfViewer-Ch0v9vA6.cjs → PdfViewer--8KwZWwP.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-BoDHZ2nW.es.js → PdfViewer-SpPk10jl.es.js} +1 -1
  3. package/dist/chunks/{index-BWPWqVxp.es.js → index-BjLjS5O9.es.js} +3 -3
  4. package/dist/chunks/{index-DFOT300M.cjs → index-yRUOdLmp.cjs} +3 -3
  5. package/dist/chunks/{super-editor.es-BQ6kZTNg.cjs → super-editor.es-CuNhawtn.cjs} +1937 -3044
  6. package/dist/chunks/{super-editor.es-sBfWb5tn.es.js → super-editor.es-D24_Ox1u.es.js} +1937 -3044
  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-C91Sr_5w.js → converter-Cg4SgA5y.js} +1132 -1616
  11. package/dist/super-editor/chunks/{docx-zipper-Cl7LYpt6.js → docx-zipper-CDX2fnxb.js} +2 -2
  12. package/dist/super-editor/chunks/{editor-a7cQT9Dw.js → editor-MKuu81v8.js} +638 -1250
  13. package/dist/super-editor/chunks/{toolbar-DiNFtCKr.js → toolbar-CpQ7L2K-.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/v2/importer/imageImporter.d.ts +1 -0
  21. package/dist/super-editor/src/core/super-converter/v2/importer/tableImporter.d.ts +22 -0
  22. package/dist/super-editor/src/core/super-converter/v3/handlers/index.d.ts +0 -2
  23. package/dist/super-editor/src/core/super-converter/v3/handlers/utils.d.ts +3 -10
  24. package/dist/super-editor/src/core/super-converter/v3/handlers/w/p/helpers/w-p-helpers.d.ts +1 -1
  25. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tc/helpers/legacy-handle-table-cell-node.d.ts +1 -1
  26. package/dist/super-editor/src/core/super-converter/v3/node-translator/node-translator.d.ts +1 -11
  27. package/dist/super-editor/src/extensions/image/imageHelpers/imagePlaceholderPlugin.d.ts +5 -0
  28. package/dist/super-editor/src/extensions/image/imageHelpers/index.d.ts +1 -2
  29. package/dist/super-editor/src/extensions/image/imageHelpers/processUploadedImage.d.ts +2 -2
  30. package/dist/super-editor/src/extensions/image/imageHelpers/startImageUpload.d.ts +23 -18
  31. package/dist/super-editor/src/extensions/structured-content/structured-content-block.d.ts +1 -3
  32. package/dist/super-editor/src/extensions/structured-content/structured-content.d.ts +1 -3
  33. package/dist/super-editor/src/extensions/table/table.d.ts +0 -330
  34. package/dist/super-editor/style.css +0 -38
  35. package/dist/super-editor/super-editor.es.js +55 -65
  36. package/dist/super-editor/toolbar.es.js +2 -2
  37. package/dist/super-editor.cjs +1 -1
  38. package/dist/super-editor.es.js +1 -1
  39. package/dist/superdoc.cjs +2 -2
  40. package/dist/superdoc.es.js +2 -2
  41. package/dist/superdoc.umd.js +2566 -3673
  42. package/dist/superdoc.umd.js.map +1 -1
  43. package/package.json +1 -1
  44. package/dist/super-editor/src/core/helpers/updateDOMAttributes.d.ts +0 -1
  45. package/dist/super-editor/src/core/super-converter/export-helpers/pre-process-vertical-merge-cells.d.ts +0 -6
  46. package/dist/super-editor/src/core/super-converter/helpers/mediaHelpers.d.ts +0 -2
  47. package/dist/super-editor/src/core/super-converter/v3/handlers/w/bidiVisual/bidiVisual-translator.d.ts +0 -6
  48. package/dist/super-editor/src/core/super-converter/v3/handlers/w/bidiVisual/index.d.ts +0 -1
  49. package/dist/super-editor/src/core/super-converter/v3/handlers/w/bottom/bottom-translator.d.ts +0 -6
  50. package/dist/super-editor/src/core/super-converter/v3/handlers/w/bottom/index.d.ts +0 -2
  51. package/dist/super-editor/src/core/super-converter/v3/handlers/w/bottom/marginBottom-translator.d.ts +0 -6
  52. package/dist/super-editor/src/core/super-converter/v3/handlers/w/drawing/drawing-translator.d.ts +0 -6
  53. package/dist/super-editor/src/core/super-converter/v3/handlers/w/drawing/index.d.ts +0 -1
  54. package/dist/super-editor/src/core/super-converter/v3/handlers/w/end/end-translator.d.ts +0 -6
  55. package/dist/super-editor/src/core/super-converter/v3/handlers/w/end/index.d.ts +0 -2
  56. package/dist/super-editor/src/core/super-converter/v3/handlers/w/end/marginEnd-translator.d.ts +0 -6
  57. package/dist/super-editor/src/core/super-converter/v3/handlers/w/gridCol/gridCol-translator.d.ts +0 -6
  58. package/dist/super-editor/src/core/super-converter/v3/handlers/w/gridCol/index.d.ts +0 -1
  59. package/dist/super-editor/src/core/super-converter/v3/handlers/w/insideH/index.d.ts +0 -1
  60. package/dist/super-editor/src/core/super-converter/v3/handlers/w/insideH/insideH-translator.d.ts +0 -6
  61. package/dist/super-editor/src/core/super-converter/v3/handlers/w/insideV/index.d.ts +0 -1
  62. package/dist/super-editor/src/core/super-converter/v3/handlers/w/insideV/insideV-translator.d.ts +0 -6
  63. package/dist/super-editor/src/core/super-converter/v3/handlers/w/left/index.d.ts +0 -2
  64. package/dist/super-editor/src/core/super-converter/v3/handlers/w/left/left-translator.d.ts +0 -6
  65. package/dist/super-editor/src/core/super-converter/v3/handlers/w/left/marginLeft-translator.d.ts +0 -6
  66. package/dist/super-editor/src/core/super-converter/v3/handlers/w/right/index.d.ts +0 -2
  67. package/dist/super-editor/src/core/super-converter/v3/handlers/w/right/marginRight-translator.d.ts +0 -6
  68. package/dist/super-editor/src/core/super-converter/v3/handlers/w/right/right-translator.d.ts +0 -6
  69. package/dist/super-editor/src/core/super-converter/v3/handlers/w/shd/index.d.ts +0 -1
  70. package/dist/super-editor/src/core/super-converter/v3/handlers/w/shd/shd-translator.d.ts +0 -6
  71. package/dist/super-editor/src/core/super-converter/v3/handlers/w/start/index.d.ts +0 -2
  72. package/dist/super-editor/src/core/super-converter/v3/handlers/w/start/marginStart-translator.d.ts +0 -6
  73. package/dist/super-editor/src/core/super-converter/v3/handlers/w/start/start-translator.d.ts +0 -6
  74. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tbl/index.d.ts +0 -1
  75. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tbl/tbl-translator.d.ts +0 -28
  76. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblBorders/index.d.ts +0 -1
  77. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblBorders/tblBorders-translator.d.ts +0 -6
  78. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblCaption/index.d.ts +0 -1
  79. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblCaption/tblCaption-translator.d.ts +0 -6
  80. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblCellMar/index.d.ts +0 -1
  81. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblCellMar/tblCellMar-translator.d.ts +0 -2
  82. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblDescription/index.d.ts +0 -1
  83. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblDescription/tblDescription-translator.d.ts +0 -6
  84. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblGrid/index.d.ts +0 -1
  85. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblGrid/tblGrid-helpers.d.ts +0 -5
  86. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblGrid/tblGrid-translator.d.ts +0 -5
  87. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblInd/index.d.ts +0 -1
  88. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblInd/tblInd-translator.d.ts +0 -6
  89. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblLayout/index.d.ts +0 -1
  90. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblLayout/tblLayout-translator.d.ts +0 -6
  91. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblLook/index.d.ts +0 -1
  92. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblLook/tblLook-translator.d.ts +0 -6
  93. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblOverlap/index.d.ts +0 -1
  94. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblOverlap/tblOverlap-translator.d.ts +0 -6
  95. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblPr/index.d.ts +0 -1
  96. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblPr/tblPr-translator.d.ts +0 -5
  97. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblStyle/index.d.ts +0 -1
  98. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblStyle/tblStyle-translator.d.ts +0 -6
  99. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblStyleColBandSize/index.d.ts +0 -1
  100. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblStyleColBandSize/tblStyleColBandSize-translator.d.ts +0 -6
  101. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblStyleRowBandSize/index.d.ts +0 -1
  102. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblStyleRowBandSize/tblStyleRowBandSize-translator.d.ts +0 -6
  103. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblW/index.d.ts +0 -1
  104. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblW/tblW-translator.d.ts +0 -6
  105. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblpPr/index.d.ts +0 -1
  106. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblpPr/tblpPr-translator.d.ts +0 -6
  107. package/dist/super-editor/src/core/super-converter/v3/handlers/w/top/index.d.ts +0 -2
  108. package/dist/super-editor/src/core/super-converter/v3/handlers/w/top/marginTop-translator.d.ts +0 -6
  109. package/dist/super-editor/src/core/super-converter/v3/handlers/w/top/top-translator.d.ts +0 -6
  110. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/anchor/anchor-translator.d.ts +0 -6
  111. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/anchor/helpers/handle-anchor-node.d.ts +0 -6
  112. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/anchor/helpers/translate-anchor-node.d.ts +0 -6
  113. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/anchor/index.d.ts +0 -1
  114. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/helpers/decode-image-node-helpers.d.ts +0 -18
  115. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/helpers/encode-image-node-helpers.d.ts +0 -6
  116. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/inline/helpers/handle-inline-node.d.ts +0 -6
  117. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/inline/helpers/translate-inline-node.d.ts +0 -6
  118. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/inline/index.d.ts +0 -1
  119. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/inline/inline-translator.d.ts +0 -6
  120. package/dist/super-editor/src/extensions/image/imageHelpers/fileNameUtils.d.ts +0 -3
  121. package/dist/super-editor/src/extensions/image/imageHelpers/handleBase64.d.ts +0 -1
  122. package/dist/super-editor/src/extensions/image/imageHelpers/handleUrl.d.ts +0 -2
  123. package/dist/super-editor/src/extensions/image/imageHelpers/imageRegistrationPlugin.d.ts +0 -11
  124. package/dist/super-editor/src/extensions/structured-content/StructuredContentBlockView.d.ts +0 -9
  125. package/dist/super-editor/src/extensions/structured-content/StructuredContentInlineView.d.ts +0 -9
  126. package/dist/super-editor/src/extensions/structured-content/StructuredContentViewBase.d.ts +0 -24
@@ -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;
@@ -16395,6 +16392,41 @@ const prepareCommentsXmlFilesForExport = ({ convertedXml, defs, commentsWithPara
16395
16392
  documentXml: updatedXml
16396
16393
  };
16397
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
+ };
16398
16430
  const lower16 = 65535;
16399
16431
  const factor16 = Math.pow(2, 16);
16400
16432
  function makeRecover(index, offset) {
@@ -21339,7 +21371,7 @@ const isInTable = (state2) => {
21339
21371
  };
21340
21372
  function stripHtmlStyles(html) {
21341
21373
  if (!html) return "";
21342
- const parser = new window.DOMParser();
21374
+ const parser = new DOMParser();
21343
21375
  const doc2 = parser.parseFromString(html, "text/html");
21344
21376
  const SUPPORTED_ATTRS = [
21345
21377
  "href",
@@ -21358,11 +21390,9 @@ function stripHtmlStyles(html) {
21358
21390
  "styleid"
21359
21391
  ];
21360
21392
  const cleanNode = (node) => {
21361
- if (node.nodeType !== window.Node.ELEMENT_NODE) return;
21393
+ if (node.nodeType !== Node.ELEMENT_NODE) return;
21362
21394
  [...node.attributes].forEach((attr) => {
21363
- const name = attr.name.toLowerCase();
21364
- const shouldKeep = SUPPORTED_ATTRS.includes(name) || name.startsWith("data-");
21365
- if (!shouldKeep) {
21395
+ if (!SUPPORTED_ATTRS.includes(attr.name.toLowerCase())) {
21366
21396
  node.removeAttribute(attr.name);
21367
21397
  }
21368
21398
  });
@@ -21391,7 +21421,7 @@ function L() {
21391
21421
  return { async: false, breaks: false, extensions: null, gfm: true, hooks: null, pedantic: false, renderer: null, silent: false, tokenizer: null, walkTokens: null };
21392
21422
  }
21393
21423
  var O = L();
21394
- function G(l3) {
21424
+ function H(l3) {
21395
21425
  O = l3;
21396
21426
  }
21397
21427
  var E = { exec: () => null };
@@ -21403,7 +21433,7 @@ function h(l3, e = "") {
21403
21433
  return n;
21404
21434
  }
21405
21435
  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} *[^
21406
- ]`).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 };
21436
+ ]`).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 };
21407
21437
  var Xe = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }, ke = (l3) => Xe[l3];
21408
21438
  function w(l3, e) {
21409
21439
  if (e) {
@@ -21561,15 +21591,15 @@ ${c}` : c;
21561
21591
  if (!(t = s.exec(e)) || this.rules.block.hr.test(e)) break;
21562
21592
  p = t[0], e = e.substring(p.length);
21563
21593
  let f = t[2].split(`
21564
- `, 1)[0].replace(this.rules.other.listReplaceTabs, (H) => " ".repeat(3 * H.length)), k = e.split(`
21594
+ `, 1)[0].replace(this.rules.other.listReplaceTabs, (Z) => " ".repeat(3 * Z.length)), k = e.split(`
21565
21595
  `, 1)[0], x = !f.trim(), g = 0;
21566
21596
  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 + `
21567
21597
  `, e = e.substring(k.length + 1), u = true), !u) {
21568
- 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);
21598
+ 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);
21569
21599
  for (; e; ) {
21570
- let Z = e.split(`
21600
+ let G = e.split(`
21571
21601
  `, 1)[0], A;
21572
- 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;
21602
+ 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;
21573
21603
  if (A.search(this.rules.other.nonSpaceChar) >= g || !k.trim()) c += `
21574
21604
  ` + A.slice(g);
21575
21605
  else {
@@ -21577,8 +21607,8 @@ ${c}` : c;
21577
21607
  c += `
21578
21608
  ` + k;
21579
21609
  }
21580
- !x && !k.trim() && (x = true), p += Z + `
21581
- `, e = e.substring(Z.length + 1), f = A.slice(g);
21610
+ !x && !k.trim() && (x = true), p += G + `
21611
+ `, e = e.substring(G.length + 1), f = A.slice(g);
21582
21612
  }
21583
21613
  }
21584
21614
  i.loose || (o ? i.loose = true : this.rules.other.doubleBlankLine.test(p) && (o = true));
@@ -21885,7 +21915,6 @@ var b = class l {
21885
21915
  }
21886
21916
  for (; (r = this.tokenizer.rules.inline.anyPunctuation.exec(n)) != null; ) n = n.slice(0, r.index) + "++" + n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
21887
21917
  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);
21888
- n = this.options.hooks?.emStrongMask?.call({ lexer: this }, n) ?? n;
21889
21918
  let i = false, s = "";
21890
21919
  for (; e; ) {
21891
21920
  i || (s = ""), i = false;
@@ -22080,7 +22109,7 @@ ${e}</tr>
22080
22109
  return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : "escaped" in e && e.escaped ? e.text : w(e.text);
22081
22110
  }
22082
22111
  };
22083
- var $ = class {
22112
+ var S = class {
22084
22113
  strong({ text: e }) {
22085
22114
  return e;
22086
22115
  }
@@ -22114,7 +22143,7 @@ var R = class l2 {
22114
22143
  __publicField(this, "options");
22115
22144
  __publicField(this, "renderer");
22116
22145
  __publicField(this, "textRenderer");
22117
- 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 $();
22146
+ 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();
22118
22147
  }
22119
22148
  static parse(e, t) {
22120
22149
  return new l2(t).parse(e);
@@ -22254,7 +22283,7 @@ var R = class l2 {
22254
22283
  return n;
22255
22284
  }
22256
22285
  };
22257
- var S = (_a = class {
22286
+ var $ = (_a = class {
22258
22287
  constructor(e) {
22259
22288
  __publicField(this, "options");
22260
22289
  __publicField(this, "block");
@@ -22269,16 +22298,13 @@ var S = (_a = class {
22269
22298
  processAllTokens(e) {
22270
22299
  return e;
22271
22300
  }
22272
- emStrongMask(e) {
22273
- return e;
22274
- }
22275
22301
  provideLexer() {
22276
22302
  return this.block ? b.lex : b.lexInline;
22277
22303
  }
22278
22304
  provideParser() {
22279
22305
  return this.block ? R.parse : R.parseInline;
22280
22306
  }
22281
- }, __publicField(_a, "passThroughHooks", /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens", "emStrongMask"])), __publicField(_a, "passThroughHooksRespectAsync", /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens"])), _a);
22307
+ }, __publicField(_a, "passThroughHooks", /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens"])), _a);
22282
22308
  var B = class {
22283
22309
  constructor(...e) {
22284
22310
  __publicField(this, "defaults", L());
@@ -22287,10 +22313,10 @@ var B = class {
22287
22313
  __publicField(this, "parseInline", this.parseMarkdown(false));
22288
22314
  __publicField(this, "Parser", R);
22289
22315
  __publicField(this, "Renderer", P);
22290
- __publicField(this, "TextRenderer", $);
22316
+ __publicField(this, "TextRenderer", S);
22291
22317
  __publicField(this, "Lexer", b);
22292
22318
  __publicField(this, "Tokenizer", y);
22293
- __publicField(this, "Hooks", S);
22319
+ __publicField(this, "Hooks", $);
22294
22320
  this.use(...e);
22295
22321
  }
22296
22322
  walkTokens(e, t) {
@@ -22363,13 +22389,13 @@ var B = class {
22363
22389
  r.tokenizer = i;
22364
22390
  }
22365
22391
  if (n.hooks) {
22366
- let i = this.defaults.hooks || new S();
22392
+ let i = this.defaults.hooks || new $();
22367
22393
  for (let s in n.hooks) {
22368
22394
  if (!(s in i)) throw new Error(`hook '${s}' does not exist`);
22369
22395
  if (["options", "block"].includes(s)) continue;
22370
22396
  let o = s, a = n.hooks[o], u = i[o];
22371
- S.passThroughHooks.has(s) ? i[o] = (p) => {
22372
- if (this.defaults.async && S.passThroughHooksRespectAsync.has(s)) return Promise.resolve(a.call(i, p)).then((f) => u.call(i, f));
22397
+ $.passThroughHooks.has(s) ? i[o] = (p) => {
22398
+ if (this.defaults.async) return Promise.resolve(a.call(i, p)).then((f) => u.call(i, f));
22373
22399
  let c = a.call(i, p);
22374
22400
  return u.call(i, c);
22375
22401
  } : i[o] = (...p) => {
@@ -22435,12 +22461,12 @@ function d(l3, e) {
22435
22461
  return _.parse(l3, e);
22436
22462
  }
22437
22463
  d.options = d.setOptions = function(l3) {
22438
- return _.setOptions(l3), d.defaults = _.defaults, G(d.defaults), d;
22464
+ return _.setOptions(l3), d.defaults = _.defaults, H(d.defaults), d;
22439
22465
  };
22440
22466
  d.getDefaults = L;
22441
22467
  d.defaults = O;
22442
22468
  d.use = function(...l3) {
22443
- return _.use(...l3), d.defaults = _.defaults, G(d.defaults), d;
22469
+ return _.use(...l3), d.defaults = _.defaults, H(d.defaults), d;
22444
22470
  };
22445
22471
  d.walkTokens = function(l3, e) {
22446
22472
  return _.walkTokens(l3, e);
@@ -22449,11 +22475,11 @@ d.parseInline = _.parseInline;
22449
22475
  d.Parser = R;
22450
22476
  d.parser = R.parse;
22451
22477
  d.Renderer = P;
22452
- d.TextRenderer = $;
22478
+ d.TextRenderer = S;
22453
22479
  d.Lexer = b;
22454
22480
  d.lexer = b.lex;
22455
22481
  d.Tokenizer = y;
22456
- d.Hooks = S;
22482
+ d.Hooks = $;
22457
22483
  d.parse = d;
22458
22484
  d.options;
22459
22485
  d.setOptions;
@@ -22501,23 +22527,6 @@ function processContent({ content, type: type2, schema }) {
22501
22527
  }
22502
22528
  return doc2;
22503
22529
  }
22504
- const defaultBooleans = ["required", "readonly", "disabled", "checked", "multiple", "autofocus"];
22505
- function updateDOMAttributes(dom, attrs = {}, options = {}) {
22506
- const customBooleans = options.customBooleans || [];
22507
- const booleans = [...defaultBooleans, ...customBooleans];
22508
- Object.entries(attrs).forEach(([key, value]) => {
22509
- if (booleans.includes(key)) {
22510
- if (!value) dom.removeAttribute(key);
22511
- else dom.setAttribute(key, "");
22512
- return;
22513
- }
22514
- if (value != null) {
22515
- dom.setAttribute(key, value);
22516
- } else {
22517
- dom.removeAttribute(key);
22518
- }
22519
- });
22520
- }
22521
22530
  const helpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
22522
22531
  __proto__: null,
22523
22532
  chainableEditorState,
@@ -22550,8 +22559,7 @@ const helpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
22550
22559
  isNodeActive,
22551
22560
  isTextSelection,
22552
22561
  posToDOMRect,
22553
- processContent,
22554
- updateDOMAttributes
22562
+ processContent
22555
22563
  }, Symbol.toStringTag, { value: "Module" }));
22556
22564
  const generateNewListDefinition = ({ numId, listType, level, start, text, fmt, editor }) => {
22557
22565
  if (typeof listType === "string") listType = editor.schema.nodes[listType];
@@ -22763,18 +22771,13 @@ const createSchemaOrderedListNode = ({ level, numId, listType, editor, listLevel
22763
22771
  numId = Number(numId);
22764
22772
  const { lvlText, numFmt } = ListHelpers.getListDefinitionDetails({ numId, level, listType, editor });
22765
22773
  const listNodeJSON = createListItemNodeJSON({ level, lvlText, numFmt, numId, listLevel, contentNode });
22766
- const nodeTypeName = typeof listType === "string" ? listType : listType?.name;
22767
- const type2 = nodeTypeName || "orderedList";
22768
- const attrs = {
22769
- "list-style-type": numFmt,
22770
- listId: numId
22771
- };
22772
- if (type2 === "orderedList") {
22773
- attrs.order = level;
22774
- }
22775
22774
  const node = {
22776
- type: type2,
22777
- attrs,
22775
+ type: "orderedList",
22776
+ attrs: {
22777
+ "list-style-type": numFmt,
22778
+ listId: numId,
22779
+ order: level
22780
+ },
22778
22781
  content: [listNodeJSON]
22779
22782
  };
22780
22783
  return editor.schema.nodeFromJSON(node);
@@ -24293,37 +24296,37 @@ const _NodeTranslator = class _NodeTranslator {
24293
24296
  /** @type {typeof TranslatorTypes} */
24294
24297
  __publicField(_NodeTranslator, "translatorTypes", TranslatorTypes);
24295
24298
  let NodeTranslator = _NodeTranslator;
24296
- const encode$r = (attributes) => {
24299
+ const encode$j = (attributes) => {
24297
24300
  return attributes["w:type"];
24298
24301
  };
24299
- const decode$r = (attrs) => {
24302
+ const decode$j = (attrs) => {
24300
24303
  const { lineBreakType } = attrs;
24301
24304
  return lineBreakType;
24302
24305
  };
24303
24306
  const attrConfig$b = Object.freeze({
24304
24307
  xmlName: "w:type",
24305
24308
  sdName: "lineBreakType",
24306
- encode: encode$r,
24307
- decode: decode$r
24309
+ encode: encode$j,
24310
+ decode: decode$j
24308
24311
  });
24309
- const encode$q = (attributes) => {
24312
+ const encode$i = (attributes) => {
24310
24313
  const xmlAttrValue = attributes["w:clear"];
24311
24314
  return xmlAttrValue;
24312
24315
  };
24313
- const decode$q = (attrs) => {
24316
+ const decode$i = (attrs) => {
24314
24317
  const { clear } = attrs;
24315
24318
  return clear;
24316
24319
  };
24317
24320
  const attrConfig$a = Object.freeze({
24318
24321
  xmlName: "w:clear",
24319
24322
  sdName: "clear",
24320
- encode: encode$q,
24321
- decode: decode$q
24323
+ encode: encode$i,
24324
+ decode: decode$i
24322
24325
  });
24323
- const validXmlAttributes$9 = [attrConfig$b, attrConfig$a];
24324
- const XML_NODE_NAME$f = "w:br";
24325
- const SD_NODE_NAME$a = "lineBreak";
24326
- const encode$p = (_2, encodedAttrs) => {
24326
+ const validXmlAttributes$6 = [attrConfig$b, attrConfig$a];
24327
+ const XML_NODE_NAME$7 = "w:br";
24328
+ const SD_NODE_NAME$6 = "lineBreak";
24329
+ const encode$h = (_2, encodedAttrs) => {
24327
24330
  const isPageBreak = encodedAttrs?.lineBreakType === "page";
24328
24331
  const translated = {
24329
24332
  type: isPageBreak ? "hardBreak" : "lineBreak"
@@ -24333,7 +24336,7 @@ const encode$p = (_2, encodedAttrs) => {
24333
24336
  }
24334
24337
  return translated;
24335
24338
  };
24336
- const decode$p = (params, decodedAttrs) => {
24339
+ const decode$h = (params, decodedAttrs) => {
24337
24340
  const { node } = params;
24338
24341
  if (!node) return;
24339
24342
  const wBreak = { name: "w:br" };
@@ -24350,63 +24353,63 @@ const decode$p = (params, decodedAttrs) => {
24350
24353
  };
24351
24354
  return translated;
24352
24355
  };
24353
- const config$d = {
24354
- xmlName: XML_NODE_NAME$f,
24355
- sdNodeOrKeyName: SD_NODE_NAME$a,
24356
+ const config$7 = {
24357
+ xmlName: XML_NODE_NAME$7,
24358
+ sdNodeOrKeyName: SD_NODE_NAME$6,
24356
24359
  type: NodeTranslator.translatorTypes.NODE,
24357
- encode: encode$p,
24358
- decode: decode$p,
24359
- attributes: validXmlAttributes$9
24360
+ encode: encode$h,
24361
+ decode: decode$h,
24362
+ attributes: validXmlAttributes$6
24360
24363
  };
24361
- const translator$T = NodeTranslator.from(config$d);
24362
- const encode$o = (attributes) => {
24364
+ const translator$j = NodeTranslator.from(config$7);
24365
+ const encode$g = (attributes) => {
24363
24366
  return attributes["w:val"];
24364
24367
  };
24365
- const decode$o = (attrs) => {
24368
+ const decode$g = (attrs) => {
24366
24369
  const { tabSize } = attrs || {};
24367
24370
  return tabSize;
24368
24371
  };
24369
24372
  const attrConfig$9 = Object.freeze({
24370
24373
  xmlName: "w:val",
24371
24374
  sdName: "tabSize",
24372
- encode: encode$o,
24373
- decode: decode$o
24375
+ encode: encode$g,
24376
+ decode: decode$g
24374
24377
  });
24375
- const encode$n = (attributes) => {
24378
+ const encode$f = (attributes) => {
24376
24379
  return attributes["w:leader"];
24377
24380
  };
24378
- const decode$n = (attrs) => {
24381
+ const decode$f = (attrs) => {
24379
24382
  const { leader } = attrs || {};
24380
24383
  return leader;
24381
24384
  };
24382
24385
  const attrConfig$8 = Object.freeze({
24383
24386
  xmlName: "w:leader",
24384
24387
  sdName: "leader",
24385
- encode: encode$n,
24386
- decode: decode$n
24388
+ encode: encode$f,
24389
+ decode: decode$f
24387
24390
  });
24388
- const encode$m = (attributes) => {
24391
+ const encode$e = (attributes) => {
24389
24392
  return attributes["w:pos"];
24390
24393
  };
24391
- const decode$m = (attrs) => {
24394
+ const decode$e = (attrs) => {
24392
24395
  const { pos } = attrs || {};
24393
24396
  return pos;
24394
24397
  };
24395
24398
  const attrConfig$7 = Object.freeze({
24396
24399
  xmlName: "w:pos",
24397
24400
  sdName: "pos",
24398
- encode: encode$m,
24399
- decode: decode$m
24401
+ encode: encode$e,
24402
+ decode: decode$e
24400
24403
  });
24401
- const validXmlAttributes$8 = [attrConfig$9, attrConfig$7, attrConfig$8];
24402
- const XML_NODE_NAME$e = "w:tab";
24403
- const SD_NODE_NAME$9 = "tab";
24404
- const encode$l = (_2, encodedAttrs = {}) => {
24404
+ const validXmlAttributes$5 = [attrConfig$9, attrConfig$7, attrConfig$8];
24405
+ const XML_NODE_NAME$6 = "w:tab";
24406
+ const SD_NODE_NAME$5 = "tab";
24407
+ const encode$d = (_2, encodedAttrs = {}) => {
24405
24408
  const translated = { type: "tab" };
24406
24409
  if (encodedAttrs) translated.attrs = { ...encodedAttrs };
24407
24410
  return translated;
24408
24411
  };
24409
- const decode$l = (params, decodedAttrs = {}) => {
24412
+ const decode$d = (params, decodedAttrs = {}) => {
24410
24413
  const { node } = params || {};
24411
24414
  if (!node) return;
24412
24415
  const wTab = { name: "w:tab" };
@@ -24422,15 +24425,15 @@ const decode$l = (params, decodedAttrs = {}) => {
24422
24425
  }
24423
24426
  return translated;
24424
24427
  };
24425
- const config$c = {
24426
- xmlName: XML_NODE_NAME$e,
24427
- sdNodeOrKeyName: SD_NODE_NAME$9,
24428
+ const config$6 = {
24429
+ xmlName: XML_NODE_NAME$6,
24430
+ sdNodeOrKeyName: SD_NODE_NAME$5,
24428
24431
  type: NodeTranslator.translatorTypes.NODE,
24429
- encode: encode$l,
24430
- decode: decode$l,
24431
- attributes: validXmlAttributes$8
24432
+ encode: encode$d,
24433
+ decode: decode$d,
24434
+ attributes: validXmlAttributes$5
24432
24435
  };
24433
- const translator$S = NodeTranslator.from(config$c);
24436
+ const translator$i = NodeTranslator.from(config$6);
24434
24437
  const mergeTextNodes = (nodes) => {
24435
24438
  if (!nodes || !Array.isArray(nodes)) {
24436
24439
  return nodes;
@@ -24694,15 +24697,13 @@ const getParagraphIndent = (node, docx, styleId = "") => {
24694
24697
  }
24695
24698
  return indent;
24696
24699
  };
24697
- const getParagraphSpacing = (node, docx, styleId = "", marks = [], options = {}) => {
24698
- const { insideTable = false } = options;
24700
+ const getParagraphSpacing = (node, docx, styleId = "", marks = []) => {
24699
24701
  const spacing = {};
24700
- const { spacing: pDefaultSpacing = {}, spacingSource } = getDefaultParagraphStyle(docx, styleId);
24702
+ const { spacing: pDefaultSpacing = {} } = getDefaultParagraphStyle(docx, styleId);
24701
24703
  let lineSpaceAfter, lineSpaceBefore, line, lineRuleStyle;
24702
24704
  const pPr = node.elements?.find((el) => el.name === "w:pPr");
24703
24705
  const inLineSpacingTag = pPr?.elements?.find((el) => el.name === "w:spacing");
24704
24706
  const inLineSpacing = inLineSpacingTag?.attributes || {};
24705
- const hasInlineSpacing = !!Object.keys(inLineSpacing).length;
24706
24707
  const textStyleMark = marks.find((el) => el.type === "textStyle");
24707
24708
  const fontSize = textStyleMark?.attrs?.fontSize;
24708
24709
  const lineSpacing = inLineSpacing?.["w:line"] || line || pDefaultSpacing?.["w:line"];
@@ -24724,12 +24725,6 @@ const getParagraphSpacing = (node, docx, styleId = "", marks = [], options = {})
24724
24725
  if (afterAutospacing === "1" && fontSize) {
24725
24726
  spacing.lineSpaceAfter += Math.round(parseInt(fontSize) * 0.5 * 96 / 72);
24726
24727
  }
24727
- if (insideTable && !hasInlineSpacing && spacingSource === "docDefault") {
24728
- const hasExplicitSpacing = Object.keys(inLineSpacing).length > 0;
24729
- if (!hasExplicitSpacing) {
24730
- return void 0;
24731
- }
24732
- }
24733
24728
  return spacing;
24734
24729
  };
24735
24730
  const getDefaultParagraphStyle = (docx, styleId = "") => {
@@ -24770,20 +24765,9 @@ const getDefaultParagraphStyle = (docx, styleId = "") => {
24770
24765
  const { attributes: pPrByIdIndentAttr } = pPrStyleIdIndentTag;
24771
24766
  const spacingRest = isNormalAsDefault ? pPrNormalSpacingAttr || pPrDefaultSpacingAttr : pPrDefaultSpacingAttr || pPrNormalSpacingAttr;
24772
24767
  const indentRest = isNormalAsDefault ? pPrNormalIndentAttr || pPrDefaultIndentAttr : pPrDefaultIndentAttr || pPrNormalIndentAttr;
24773
- let spacingToUse = pPrByIdSpacingAttr || spacingRest;
24774
- let spacingSource = "docDefault";
24775
- if (pPrByIdSpacingAttr) {
24776
- spacingSource = "style";
24777
- } else if (spacingRest === pPrNormalSpacingAttr && pPrNormalSpacingAttr) {
24778
- spacingSource = isNormalAsDefault ? "docDefault" : "normal";
24779
- } else if (spacingRest === pPrDefaultSpacingAttr && pPrDefaultSpacingAttr) {
24780
- spacingSource = "docDefault";
24781
- }
24782
- let indentToUse = pPrByIdIndentAttr || indentRest;
24783
24768
  return {
24784
- spacing: spacingToUse,
24785
- spacingSource,
24786
- indent: indentToUse,
24769
+ spacing: pPrByIdSpacingAttr || spacingRest,
24770
+ indent: pPrByIdIndentAttr || indentRest,
24787
24771
  justify: pPrByIdJcAttr
24788
24772
  };
24789
24773
  };
@@ -24958,13 +24942,7 @@ const handleParagraphNode$1 = (params) => {
24958
24942
  }
24959
24943
  if (docx) {
24960
24944
  const defaultStyleId = node.attributes?.["w:rsidRDefault"];
24961
- const insideTable = (params.path || []).some((ancestor) => ancestor.name === "w:tc");
24962
- const spacing = getParagraphSpacing(node, docx, styleId, schemaNode.attrs.marksAttrs, {
24963
- insideTable
24964
- });
24965
- if (spacing) {
24966
- schemaNode.attrs["spacing"] = spacing;
24967
- }
24945
+ schemaNode.attrs["spacing"] = getParagraphSpacing(node, docx, styleId, schemaNode.attrs.marksAttrs);
24968
24946
  schemaNode.attrs["rsidRDefault"] = defaultStyleId;
24969
24947
  }
24970
24948
  if (docx) {
@@ -25025,91 +25003,91 @@ const handleParagraphNode$1 = (params) => {
25025
25003
  }
25026
25004
  return schemaNode;
25027
25005
  };
25028
- const encode$k = (attributes) => {
25006
+ const encode$c = (attributes) => {
25029
25007
  return attributes["w:rsidDel"];
25030
25008
  };
25031
- const decode$k = (attrs) => {
25009
+ const decode$c = (attrs) => {
25032
25010
  return attrs.rsidDel;
25033
25011
  };
25034
25012
  const attrConfig$6 = Object.freeze({
25035
25013
  xmlName: "w:rsidDel",
25036
25014
  sdName: "rsidDel",
25037
- encode: encode$k,
25038
- decode: decode$k
25015
+ encode: encode$c,
25016
+ decode: decode$c
25039
25017
  });
25040
- const encode$j = (attributes) => {
25018
+ const encode$b = (attributes) => {
25041
25019
  return attributes["w:rsidP"];
25042
25020
  };
25043
- const decode$j = (attrs) => {
25021
+ const decode$b = (attrs) => {
25044
25022
  return attrs.rsidP;
25045
25023
  };
25046
25024
  const attrConfig$5 = Object.freeze({
25047
25025
  xmlName: "w:rsidP",
25048
25026
  sdName: "rsidP",
25049
- encode: encode$j,
25050
- decode: decode$j
25027
+ encode: encode$b,
25028
+ decode: decode$b
25051
25029
  });
25052
- const encode$i = (attributes) => {
25030
+ const encode$a = (attributes) => {
25053
25031
  return attributes["w:rsidR"];
25054
25032
  };
25055
- const decode$i = (attrs) => {
25033
+ const decode$a = (attrs) => {
25056
25034
  return attrs.rsidR;
25057
25035
  };
25058
25036
  const attrConfig$4 = Object.freeze({
25059
25037
  xmlName: "w:rsidR",
25060
25038
  sdName: "rsidR",
25061
- encode: encode$i,
25062
- decode: decode$i
25039
+ encode: encode$a,
25040
+ decode: decode$a
25063
25041
  });
25064
- const encode$h = (attributes) => {
25042
+ const encode$9 = (attributes) => {
25065
25043
  return attributes["w:rsidRPr"];
25066
25044
  };
25067
- const decode$h = (attrs) => {
25045
+ const decode$9 = (attrs) => {
25068
25046
  return attrs.rsidRPr;
25069
25047
  };
25070
25048
  const attrConfig$3 = Object.freeze({
25071
25049
  xmlName: "w:rsidRPr",
25072
25050
  sdName: "rsidRPr",
25073
- encode: encode$h,
25074
- decode: decode$h
25051
+ encode: encode$9,
25052
+ decode: decode$9
25075
25053
  });
25076
- const encode$g = (attributes) => {
25054
+ const encode$8 = (attributes) => {
25077
25055
  return attributes["w:rsidRDefault"];
25078
25056
  };
25079
- const decode$g = (attrs) => {
25057
+ const decode$8 = (attrs) => {
25080
25058
  return attrs.rsidRDefault;
25081
25059
  };
25082
25060
  const attrConfig$2 = Object.freeze({
25083
25061
  xmlName: "w:rsidRDefault",
25084
25062
  sdName: "rsidRDefault",
25085
- encode: encode$g,
25086
- decode: decode$g
25063
+ encode: encode$8,
25064
+ decode: decode$8
25087
25065
  });
25088
- const encode$f = (attributes) => {
25066
+ const encode$7 = (attributes) => {
25089
25067
  return attributes["w14:paraId"];
25090
25068
  };
25091
- const decode$f = (attrs) => {
25069
+ const decode$7 = (attrs) => {
25092
25070
  return attrs.paraId;
25093
25071
  };
25094
25072
  const attrConfig$1 = Object.freeze({
25095
25073
  xmlName: "w14:paraId",
25096
25074
  sdName: "paraId",
25097
- encode: encode$f,
25098
- decode: decode$f
25075
+ encode: encode$7,
25076
+ decode: decode$7
25099
25077
  });
25100
- const encode$e = (attributes) => {
25078
+ const encode$6 = (attributes) => {
25101
25079
  return attributes["w14:textId"];
25102
25080
  };
25103
- const decode$e = (attrs) => {
25081
+ const decode$6 = (attrs) => {
25104
25082
  return attrs.textId;
25105
25083
  };
25106
25084
  const attrConfig = Object.freeze({
25107
25085
  xmlName: "w14:textId",
25108
25086
  sdName: "textId",
25109
- encode: encode$e,
25110
- decode: decode$e
25087
+ encode: encode$6,
25088
+ decode: decode$6
25111
25089
  });
25112
- const validXmlAttributes$7 = [
25090
+ const validXmlAttributes$4 = [
25113
25091
  attrConfig$1,
25114
25092
  attrConfig,
25115
25093
  attrConfig$4,
@@ -25118,9 +25096,9 @@ const validXmlAttributes$7 = [
25118
25096
  attrConfig$3,
25119
25097
  attrConfig$6
25120
25098
  ];
25121
- const XML_NODE_NAME$d = "w:p";
25122
- const SD_NODE_NAME$8 = "paragraph";
25123
- const encode$d = (params, encodedAttrs = {}) => {
25099
+ const XML_NODE_NAME$5 = "w:p";
25100
+ const SD_NODE_NAME$4 = "paragraph";
25101
+ const encode$5 = (params, encodedAttrs = {}) => {
25124
25102
  const node = handleParagraphNode$1(params);
25125
25103
  if (!node) return void 0;
25126
25104
  if (encodedAttrs && Object.keys(encodedAttrs).length) {
@@ -25128,7 +25106,7 @@ const encode$d = (params, encodedAttrs = {}) => {
25128
25106
  }
25129
25107
  return node;
25130
25108
  };
25131
- const decode$d = (params, decodedAttrs = {}) => {
25109
+ const decode$5 = (params, decodedAttrs = {}) => {
25132
25110
  const translated = translateParagraphNode(params);
25133
25111
  if (!translated) return void 0;
25134
25112
  if (decodedAttrs && Object.keys(decodedAttrs).length) {
@@ -25136,15 +25114,15 @@ const decode$d = (params, decodedAttrs = {}) => {
25136
25114
  }
25137
25115
  return translated;
25138
25116
  };
25139
- const config$b = {
25140
- xmlName: XML_NODE_NAME$d,
25141
- sdNodeOrKeyName: SD_NODE_NAME$8,
25117
+ const config$5 = {
25118
+ xmlName: XML_NODE_NAME$5,
25119
+ sdNodeOrKeyName: SD_NODE_NAME$4,
25142
25120
  type: NodeTranslator.translatorTypes.NODE,
25143
- encode: encode$d,
25144
- decode: decode$d,
25145
- attributes: validXmlAttributes$7
25121
+ encode: encode$5,
25122
+ decode: decode$5,
25123
+ attributes: validXmlAttributes$4
25146
25124
  };
25147
- const translator$R = NodeTranslator.from(config$b);
25125
+ const translator$h = NodeTranslator.from(config$5);
25148
25126
  const generateV2HandlerEntity = (handlerName, translator2) => ({
25149
25127
  handlerName,
25150
25128
  handler: (params) => {
@@ -25172,7 +25150,7 @@ function createSingleAttrPropertyHandler(xmlName, sdName = null, attrName = "w:v
25172
25150
  },
25173
25151
  decode: ({ node }) => {
25174
25152
  const value = node.attrs?.[sdName] != null ? transformDecode(node.attrs[sdName]) : void 0;
25175
- return value != null ? { name: xmlName, attributes: { [attrName]: value } } : void 0;
25153
+ return value != null ? { [attrName]: value } : void 0;
25176
25154
  }
25177
25155
  };
25178
25156
  }
@@ -25190,32 +25168,7 @@ function createMeasurementPropertyHandler(xmlName, sdName = null) {
25190
25168
  },
25191
25169
  decode: function({ node }) {
25192
25170
  const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs[sdName] || {} } });
25193
- return decodedAttrs["w:w"] != null ? { attributes: decodedAttrs } : void 0;
25194
- }
25195
- };
25196
- }
25197
- function createBorderPropertyHandler(xmlName, sdName = null) {
25198
- if (!sdName) sdName = xmlName.split(":")[1];
25199
- return {
25200
- xmlName,
25201
- sdNodeOrKeyName: sdName,
25202
- attributes: [
25203
- createAttributeHandler("w:val"),
25204
- createAttributeHandler("w:color"),
25205
- createAttributeHandler("w:themeColor"),
25206
- createAttributeHandler("w:themeTint"),
25207
- createAttributeHandler("w:themeShade"),
25208
- createAttributeHandler("w:sz", "size", parseInteger, integerToString),
25209
- createAttributeHandler("w:space", null, parseInteger, integerToString),
25210
- createAttributeHandler("w:shadow", null, parseBoolean, booleanToString),
25211
- createAttributeHandler("w:frame", null, parseBoolean, booleanToString)
25212
- ],
25213
- encode: (params, encodedAttrs) => {
25214
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
25215
- },
25216
- decode: function({ node }, context) {
25217
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs[sdName] || {} } });
25218
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
25171
+ return decodedAttrs["w:w"] != null ? decodedAttrs : void 0;
25219
25172
  }
25220
25173
  };
25221
25174
  }
@@ -25258,17 +25211,15 @@ function decodeProperties(translatorsBySdName, properties) {
25258
25211
  Object.keys(properties).forEach((key) => {
25259
25212
  const translator2 = translatorsBySdName[key];
25260
25213
  if (translator2) {
25261
- const result = translator2.decode({ node: { attrs: { [key]: properties[key] } } });
25262
- if (result != null) {
25263
- result.name = translator2.xmlName;
25264
- elements.push(result);
25214
+ const attributes = translator2.decode({ node: { attrs: { [key]: properties[key] } } });
25215
+ if (attributes != null) {
25216
+ elements.push({ name: translator2.xmlName, attributes });
25265
25217
  }
25266
25218
  }
25267
25219
  });
25268
25220
  return elements;
25269
25221
  }
25270
- const parseBoolean = (value) => value != null ? ["1", "true"].includes(value) : void 0;
25271
- const booleanToString = (value) => value != null ? value ? "1" : "0" : void 0;
25222
+ const parseBoolean = (value) => ["1", "true"].includes(value);
25272
25223
  const parseInteger = (value) => {
25273
25224
  if (value == null) return void 0;
25274
25225
  const intValue = parseInt(value, 10);
@@ -25278,53 +25229,13 @@ const integerToString = (value) => {
25278
25229
  const intValue = parseInteger(value);
25279
25230
  return intValue != void 0 ? String(intValue) : void 0;
25280
25231
  };
25281
- function preProcessVerticalMergeCells(table, { editorSchema }) {
25282
- if (!table || !Array.isArray(table.content)) {
25283
- return table;
25284
- }
25285
- const rows = table.content;
25286
- for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
25287
- const row = rows[rowIndex];
25288
- if (!row) continue;
25289
- if (!Array.isArray(row.content)) {
25290
- row.content = [];
25291
- }
25292
- for (let cellIndex = 0; cellIndex < row.content.length; cellIndex++) {
25293
- const cell = row.content[cellIndex];
25294
- if (!cell) continue;
25295
- const attrs = cell.attrs || {};
25296
- if (!attrs.rowspan || attrs.rowspan <= 1) continue;
25297
- const maxRowspan = Math.min(attrs.rowspan, rows.length - rowIndex);
25298
- for (let offset = 1; offset < maxRowspan; offset++) {
25299
- const rowToChange = rows[rowIndex + offset];
25300
- if (!rowToChange) continue;
25301
- if (!Array.isArray(rowToChange.content)) {
25302
- rowToChange.content = [];
25303
- }
25304
- const existingCell = rowToChange.content[cellIndex];
25305
- if (existingCell?.attrs?.continueMerge) continue;
25306
- const mergedCell = {
25307
- type: cell.type,
25308
- content: [editorSchema.nodes.paragraph.createAndFill().toJSON()],
25309
- attrs: {
25310
- ...cell.attrs,
25311
- rowspan: null,
25312
- continueMerge: true
25313
- }
25314
- };
25315
- rowToChange.content.splice(cellIndex, 0, mergedCell);
25316
- }
25317
- }
25318
- }
25319
- return table;
25320
- }
25321
- const translator$Q = NodeTranslator.from({
25232
+ const translator$g = NodeTranslator.from({
25322
25233
  xmlName: "w:cantSplit",
25323
25234
  sdNodeOrKeyName: "cantSplit",
25324
25235
  encode: ({ nodes }) => ["1", "true"].includes(nodes[0].attributes?.["w:val"] ?? "1"),
25325
- decode: ({ node }) => node.attrs?.cantSplit ? { attributes: {} } : void 0
25236
+ decode: ({ node }) => node.attrs?.cantSplit ? {} : void 0
25326
25237
  });
25327
- const translator$P = NodeTranslator.from({
25238
+ const translator$f = NodeTranslator.from({
25328
25239
  xmlName: "w:cnfStyle",
25329
25240
  sdNodeOrKeyName: "cnfStyle",
25330
25241
  attributes: [
@@ -25339,19 +25250,26 @@ const translator$P = NodeTranslator.from({
25339
25250
  "w:lastRowFirstColumn",
25340
25251
  "w:lastRowLastColumn",
25341
25252
  "w:oddHBand",
25342
- "w:oddVBand"
25343
- ].map((attr) => createAttributeHandler(attr, null, parseBoolean, booleanToString)).concat([createAttributeHandler("w:val")]),
25253
+ "w:oddVBand",
25254
+ "w:val"
25255
+ ].map((attr) => createAttributeHandler(attr)),
25344
25256
  encode: (_2, encodedAttrs) => {
25257
+ Object.keys(encodedAttrs).forEach((key) => {
25258
+ encodedAttrs[key] = ["1", "true"].includes(encodedAttrs[key]);
25259
+ });
25345
25260
  return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
25346
25261
  },
25347
- decode: function({ node }) {
25262
+ decode: ({ node }) => {
25348
25263
  if (!node.attrs?.cnfStyle) return;
25349
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.cnfStyle || {} } });
25350
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
25264
+ const cnfStyleAttrs = {};
25265
+ Object.entries(node.attrs.cnfStyle).forEach(([key, value]) => {
25266
+ cnfStyleAttrs[`w:${key}`] = value ? "1" : "0";
25267
+ });
25268
+ return Object.keys(cnfStyleAttrs).length > 0 ? cnfStyleAttrs : void 0;
25351
25269
  }
25352
25270
  });
25353
- const translator$O = NodeTranslator.from(createSingleAttrPropertyHandler("w:divId"));
25354
- const translator$N = NodeTranslator.from(
25271
+ const translator$e = NodeTranslator.from(createSingleAttrPropertyHandler("w:divId"));
25272
+ const translator$d = NodeTranslator.from(
25355
25273
  createSingleAttrPropertyHandler(
25356
25274
  "w:gridAfter",
25357
25275
  null,
@@ -25360,7 +25278,7 @@ const translator$N = NodeTranslator.from(
25360
25278
  (v2) => integerToString(v2)
25361
25279
  )
25362
25280
  );
25363
- const translator$M = NodeTranslator.from(
25281
+ const translator$c = NodeTranslator.from(
25364
25282
  createSingleAttrPropertyHandler(
25365
25283
  "w:gridBefore",
25366
25284
  null,
@@ -25369,21 +25287,21 @@ const translator$M = NodeTranslator.from(
25369
25287
  (v2) => integerToString(v2)
25370
25288
  )
25371
25289
  );
25372
- const translator$L = NodeTranslator.from({
25290
+ const translator$b = NodeTranslator.from({
25373
25291
  xmlName: "w:hidden",
25374
25292
  sdNodeOrKeyName: "hidden",
25375
25293
  encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
25376
- decode: ({ node }) => node.attrs.hidden ? { attributes: {} } : void 0
25294
+ decode: ({ node }) => node.attrs.hidden ? {} : void 0
25377
25295
  });
25378
- const translator$K = NodeTranslator.from(createSingleAttrPropertyHandler("w:jc", "justification"));
25379
- const translator$J = NodeTranslator.from(createMeasurementPropertyHandler("w:tblCellSpacing", "tableCellSpacing"));
25380
- const translator$I = NodeTranslator.from({
25296
+ const translator$a = NodeTranslator.from(createSingleAttrPropertyHandler("w:jc"));
25297
+ const translator$9 = NodeTranslator.from(createMeasurementPropertyHandler("w:tblCellSpacing", "cellSpacing"));
25298
+ const translator$8 = NodeTranslator.from({
25381
25299
  xmlName: "w:tblHeader",
25382
25300
  sdNodeOrKeyName: "repeatHeader",
25383
25301
  encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
25384
- decode: ({ node }) => node.attrs.repeatHeader ? { attributes: {} } : void 0
25302
+ decode: ({ node }) => node.attrs.repeatHeader ? {} : void 0
25385
25303
  });
25386
- const translator$H = NodeTranslator.from({
25304
+ const translator$7 = NodeTranslator.from({
25387
25305
  xmlName: "w:trHeight",
25388
25306
  sdNodeOrKeyName: "rowHeight",
25389
25307
  encode: ({ nodes }) => {
@@ -25407,14 +25325,14 @@ const translator$H = NodeTranslator.from({
25407
25325
  if (node.attrs.rowHeight.rule) {
25408
25326
  heightAttrs["w:hRule"] = node.attrs.rowHeight.rule;
25409
25327
  }
25410
- return Object.keys(heightAttrs).length > 0 ? { attributes: heightAttrs } : void 0;
25328
+ return Object.keys(heightAttrs).length > 0 ? heightAttrs : void 0;
25411
25329
  }
25412
25330
  });
25413
- const translator$G = NodeTranslator.from(createMeasurementPropertyHandler("w:wAfter"));
25414
- const translator$F = NodeTranslator.from(createMeasurementPropertyHandler("w:wBefore"));
25415
- const XML_NODE_NAME$c = "w:trPr";
25416
- const SD_ATTR_KEY$4 = "tableRowProperties";
25417
- const encode$c = (params) => {
25331
+ const translator$6 = NodeTranslator.from(createMeasurementPropertyHandler("w:wAfter"));
25332
+ const translator$5 = NodeTranslator.from(createMeasurementPropertyHandler("w:wBefore"));
25333
+ const XML_NODE_NAME$4 = "w:trPr";
25334
+ const SD_ATTR_KEY = "tableRowProperties";
25335
+ const encode$4 = (params) => {
25418
25336
  const { nodes } = params;
25419
25337
  const node = nodes[0];
25420
25338
  let attributes = {
@@ -25424,18 +25342,18 @@ const encode$c = (params) => {
25424
25342
  };
25425
25343
  attributes = {
25426
25344
  ...attributes,
25427
- ...encodeProperties(node, propertyTranslatorsByXmlName$2)
25345
+ ...encodeProperties(node, propertyTranslatorsByXmlName)
25428
25346
  };
25429
25347
  return {
25430
25348
  type: NodeTranslator.translatorTypes.ATTRIBUTE,
25431
- xmlName: XML_NODE_NAME$c,
25432
- sdNodeOrKeyName: SD_ATTR_KEY$4,
25349
+ xmlName: XML_NODE_NAME$4,
25350
+ sdNodeOrKeyName: SD_ATTR_KEY,
25433
25351
  attributes
25434
25352
  };
25435
25353
  };
25436
- const decode$c = (params) => {
25354
+ const decode$4 = (params) => {
25437
25355
  const { tableRowProperties = {} } = params.node.attrs || {};
25438
- const elements = decodeProperties(propertyTranslatorsBySdName$2, tableRowProperties);
25356
+ const elements = decodeProperties(propertyTranslatorsBySdName, tableRowProperties);
25439
25357
  const newNode = {
25440
25358
  name: "w:trPr",
25441
25359
  type: "element",
@@ -25444,47 +25362,47 @@ const decode$c = (params) => {
25444
25362
  };
25445
25363
  return newNode;
25446
25364
  };
25447
- const propertyTranslators$3 = [
25448
- translator$Q,
25449
- translator$P,
25450
- translator$O,
25451
- translator$N,
25452
- translator$M,
25453
- translator$L,
25454
- translator$K,
25455
- translator$J,
25456
- translator$I,
25457
- translator$H,
25458
- translator$G,
25459
- translator$F
25365
+ const propertyTranslators = [
25366
+ translator$g,
25367
+ translator$f,
25368
+ translator$e,
25369
+ translator$d,
25370
+ translator$c,
25371
+ translator$b,
25372
+ translator$a,
25373
+ translator$9,
25374
+ translator$8,
25375
+ translator$7,
25376
+ translator$6,
25377
+ translator$5
25460
25378
  ];
25461
- const propertyTranslatorsByXmlName$2 = {};
25462
- propertyTranslators$3.forEach((translator2) => {
25463
- propertyTranslatorsByXmlName$2[translator2.xmlName] = translator2;
25379
+ const propertyTranslatorsByXmlName = {};
25380
+ propertyTranslators.forEach((translator2) => {
25381
+ propertyTranslatorsByXmlName[translator2.xmlName] = translator2;
25464
25382
  });
25465
- const propertyTranslatorsBySdName$2 = {};
25466
- propertyTranslators$3.forEach((translator2) => {
25467
- propertyTranslatorsBySdName$2[translator2.sdNodeOrKeyName] = translator2;
25383
+ const propertyTranslatorsBySdName = {};
25384
+ propertyTranslators.forEach((translator2) => {
25385
+ propertyTranslatorsBySdName[translator2.sdNodeOrKeyName] = translator2;
25468
25386
  });
25469
- const config$a = {
25470
- xmlName: XML_NODE_NAME$c,
25471
- sdNodeOrKeyName: SD_ATTR_KEY$4,
25387
+ const config$4 = {
25388
+ xmlName: XML_NODE_NAME$4,
25389
+ sdNodeOrKeyName: SD_ATTR_KEY,
25472
25390
  type: NodeTranslator.translatorTypes.ATTRIBUTE,
25473
- encode: encode$c,
25474
- decode: decode$c
25391
+ encode: encode$4,
25392
+ decode: decode$4
25475
25393
  };
25476
- const translator$E = NodeTranslator.from(config$a);
25477
- const XML_NODE_NAME$b = "w:tr";
25478
- const SD_NODE_NAME$7 = "tableRow";
25479
- const validXmlAttributes$6 = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
25394
+ const translator$4 = NodeTranslator.from(config$4);
25395
+ const XML_NODE_NAME$3 = "w:tr";
25396
+ const SD_NODE_NAME$3 = "tableRow";
25397
+ const validXmlAttributes$3 = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
25480
25398
  (xmlName) => createAttributeHandler(xmlName)
25481
25399
  );
25482
- const encode$b = (params, encodedAttrs) => {
25483
- const { row } = params.extraParams;
25400
+ const encode$3 = (params, encodedAttrs) => {
25401
+ const { row, table } = params.extraParams;
25484
25402
  let tableRowProperties = {};
25485
25403
  const tPr = row.elements.find((el) => el.name === "w:trPr");
25486
25404
  if (tPr) {
25487
- ({ attributes: tableRowProperties } = translator$E.encode({
25405
+ ({ attributes: tableRowProperties } = translator$4.encode({
25488
25406
  ...params,
25489
25407
  nodes: [tPr]
25490
25408
  }));
@@ -25492,12 +25410,12 @@ const encode$b = (params, encodedAttrs) => {
25492
25410
  encodedAttrs["tableRowProperties"] = Object.freeze(tableRowProperties);
25493
25411
  encodedAttrs["rowHeight"] = twipsToPixels(tableRowProperties["rowHeight"]?.value);
25494
25412
  encodedAttrs["cantSplit"] = tableRowProperties["cantSplit"];
25495
- const { columnWidths: gridColumnWidths } = params.extraParams;
25413
+ const gridColumnWidths = _getGridColumnWidths(table);
25496
25414
  const cellNodes = row.elements.filter((el) => el.name === "w:tc");
25497
25415
  let currentColumnIndex = 0;
25498
25416
  const content = cellNodes?.map((n) => {
25499
25417
  let columnWidth = gridColumnWidths?.[currentColumnIndex] || null;
25500
- const result = translator$5.encode({
25418
+ const result = translator$2.encode({
25501
25419
  ...params,
25502
25420
  extraParams: {
25503
25421
  ...params.extraParams,
@@ -25519,7 +25437,16 @@ const encode$b = (params, encodedAttrs) => {
25519
25437
  };
25520
25438
  return newNode;
25521
25439
  };
25522
- const decode$b = (params, decodedAttrs) => {
25440
+ const _getGridColumnWidths = (tableNode) => {
25441
+ const tblGrid = tableNode.elements.find((el) => el.name === "w:tblGrid");
25442
+ if (!tblGrid) return [];
25443
+ const columnWidths = tblGrid?.elements?.flatMap((el) => {
25444
+ if (el.name !== "w:gridCol") return [];
25445
+ return twipsToPixels(el.attributes["w:w"]);
25446
+ }) || [];
25447
+ return columnWidths;
25448
+ };
25449
+ const decode$3 = (params, decodedAttrs) => {
25523
25450
  const { node } = params;
25524
25451
  const elements = translateChildNodes(params);
25525
25452
  if (node.attrs?.tableRowProperties) {
@@ -25531,7 +25458,7 @@ const decode$b = (params, decodedAttrs) => {
25531
25458
  }
25532
25459
  }
25533
25460
  tableRowProperties["cantSplit"] = node.attrs["cantSplit"];
25534
- const trPr = translator$E.decode({
25461
+ const trPr = translator$4.decode({
25535
25462
  ...params,
25536
25463
  node: { ...node, attrs: { ...node.attrs, tableRowProperties } }
25537
25464
  });
@@ -25543,547 +25470,96 @@ const decode$b = (params, decodedAttrs) => {
25543
25470
  elements
25544
25471
  };
25545
25472
  };
25546
- const config$9 = {
25547
- xmlName: XML_NODE_NAME$b,
25548
- sdNodeOrKeyName: SD_NODE_NAME$7,
25473
+ const config$3 = {
25474
+ xmlName: XML_NODE_NAME$3,
25475
+ sdNodeOrKeyName: SD_NODE_NAME$3,
25549
25476
  type: NodeTranslator.translatorTypes.NODE,
25550
- encode: encode$b,
25551
- decode: decode$b,
25552
- attributes: validXmlAttributes$6
25553
- };
25554
- const translator$D = NodeTranslator.from(config$9);
25555
- const translator$C = NodeTranslator.from({
25556
- xmlName: "w:bidiVisual",
25557
- sdNodeOrKeyName: "rightToLeft",
25558
- encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
25559
- decode: ({ node }) => node.attrs.rightToLeft ? { attributes: {} } : void 0
25560
- });
25561
- const translator$B = NodeTranslator.from({
25562
- xmlName: "w:shd",
25563
- sdNodeOrKeyName: "shading",
25564
- attributes: [
25565
- "w:color",
25566
- "w:fill",
25567
- "w:themeColor",
25568
- "w:themeFill",
25569
- "w:themeFillShade",
25570
- "w:themeFillTint",
25571
- "w:themeShade",
25572
- "w:themeTint",
25573
- "w:val"
25574
- ].map((attr) => createAttributeHandler(attr)),
25575
- encode: (params, encodedAttrs) => {
25576
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
25577
- },
25578
- decode: function({ node }, context) {
25579
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.shading || {} } });
25580
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
25581
- }
25582
- });
25583
- const translator$A = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblCaption", "caption"));
25584
- const translator$z = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblDescription", "description"));
25585
- const translator$y = NodeTranslator.from(createMeasurementPropertyHandler("w:tblInd", "tableIndent"));
25586
- const translator$x = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblLayout", "tableLayout", "w:type"));
25587
- const translator$w = NodeTranslator.from({
25588
- xmlName: "w:tblLook",
25589
- sdNodeOrKeyName: "tblLook",
25590
- attributes: ["w:firstColumn", "w:firstRow", "w:lastColumn", "w:lastRow", "w:noHBand", "w:noVBand"].map((attr) => createAttributeHandler(attr, null, parseBoolean, booleanToString)).concat([createAttributeHandler("w:val")]),
25591
- encode: (params, encodedAttrs) => {
25592
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
25593
- },
25594
- decode: function({ node }, context) {
25595
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.tblLook || {} } });
25596
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
25597
- }
25598
- });
25599
- const translator$v = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblOverlap", "overlap"));
25600
- const translator$u = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblStyle", "tableStyleId"));
25601
- const translator$t = NodeTranslator.from(
25602
- createSingleAttrPropertyHandler("w:tblStyleColBandSize", "tableStyleColBandSize")
25603
- );
25604
- const translator$s = NodeTranslator.from(
25605
- createSingleAttrPropertyHandler("w:tblStyleRowBandSize", "tableStyleRowBandSize")
25606
- );
25607
- const translator$r = NodeTranslator.from(createMeasurementPropertyHandler("w:tblW", "tableWidth"));
25608
- const translator$q = NodeTranslator.from({
25609
- xmlName: "w:tblpPr",
25610
- sdNodeOrKeyName: "floatingTableProperties",
25611
- 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))),
25612
- encode: (params, encodedAttrs) => {
25613
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
25614
- },
25615
- decode: function({ node }, context) {
25616
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.floatingTableProperties || {} } });
25617
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
25618
- }
25619
- });
25620
- const translator$p = NodeTranslator.from(createBorderPropertyHandler("w:bottom"));
25621
- const translator$o = NodeTranslator.from(createMeasurementPropertyHandler("w:bottom", "marginBottom"));
25622
- const translator$n = NodeTranslator.from(createBorderPropertyHandler("w:end"));
25623
- const translator$m = NodeTranslator.from(createMeasurementPropertyHandler("w:end", "marginEnd"));
25624
- const translator$l = NodeTranslator.from(createBorderPropertyHandler("w:insideH"));
25625
- const translator$k = NodeTranslator.from(createBorderPropertyHandler("w:insideV"));
25626
- const translator$j = NodeTranslator.from(createBorderPropertyHandler("w:left"));
25627
- const translator$i = NodeTranslator.from(createMeasurementPropertyHandler("w:left", "marginLeft"));
25628
- const translator$h = NodeTranslator.from(createBorderPropertyHandler("w:right"));
25629
- const translator$g = NodeTranslator.from(createMeasurementPropertyHandler("w:right", "marginRight"));
25630
- const translator$f = NodeTranslator.from(createBorderPropertyHandler("w:start"));
25631
- const translator$e = NodeTranslator.from(createMeasurementPropertyHandler("w:start", "marginStart"));
25632
- const translator$d = NodeTranslator.from(createBorderPropertyHandler("w:top"));
25633
- const translator$c = NodeTranslator.from(createMeasurementPropertyHandler("w:top", "marginTop"));
25634
- const XML_NODE_NAME$a = "w:tblBorders";
25635
- const SD_ATTR_KEY$3 = "borders";
25636
- const encode$a = (params) => {
25637
- const { nodes } = params;
25638
- const node = nodes[0];
25639
- const attributes = encodeProperties(node, tblBordersTranslatorsByXmlName);
25640
- return Object.keys(attributes).length > 0 ? attributes : void 0;
25641
- };
25642
- const decode$a = (params) => {
25643
- const { borders = {} } = params.node.attrs || {};
25644
- const elements = decodeProperties(tblBordersTranslatorsBySdName, borders);
25645
- const newNode = {
25646
- name: "w:tblBorders",
25647
- type: "element",
25648
- attributes: {},
25649
- elements
25650
- };
25651
- return newNode;
25477
+ encode: encode$3,
25478
+ decode: decode$3,
25479
+ attributes: validXmlAttributes$3
25652
25480
  };
25653
- const propertyTranslators$2 = [
25654
- translator$p,
25655
- translator$n,
25656
- translator$l,
25657
- translator$k,
25658
- translator$j,
25659
- translator$h,
25660
- translator$f,
25661
- translator$d
25662
- ];
25663
- const tblBordersTranslatorsByXmlName = {};
25664
- const tblBordersTranslatorsBySdName = {};
25665
- propertyTranslators$2.forEach((translator2) => {
25666
- tblBordersTranslatorsByXmlName[translator2.xmlName] = translator2;
25667
- tblBordersTranslatorsBySdName[translator2.sdNodeOrKeyName] = translator2;
25668
- });
25669
- const translator$b = NodeTranslator.from({
25670
- xmlName: XML_NODE_NAME$a,
25671
- sdNodeOrKeyName: SD_ATTR_KEY$3,
25672
- type: NodeTranslator.translatorTypes.NODE,
25673
- attributes: [],
25674
- encode: encode$a,
25675
- decode: decode$a
25676
- });
25677
- const XML_NODE_NAME$9 = "w:tblCellMar";
25678
- const SD_ATTR_KEY$2 = "cellMargins";
25679
- const encode$9 = (params) => {
25481
+ const translator$3 = NodeTranslator.from(config$3);
25482
+ const handleAllTableNodes = (params) => {
25680
25483
  const { nodes } = params;
25484
+ if (nodes.length === 0) {
25485
+ return { nodes: [], consumed: 0 };
25486
+ }
25681
25487
  const node = nodes[0];
25682
- const attributes = encodeProperties(node, propertyTranslatorsByXmlName$1);
25683
- return Object.keys(attributes).length > 0 ? attributes : void 0;
25488
+ switch (node.name) {
25489
+ case "w:tbl":
25490
+ return { nodes: [handleTableNode(node, params)], consumed: 1 };
25491
+ }
25492
+ return { nodes: [], consumed: 0 };
25684
25493
  };
25685
- const decode$9 = (params) => {
25686
- const { cellMargins = {} } = params.node.attrs || {};
25687
- const elements = decodeProperties(propertyTranslatorsBySdName$1, cellMargins);
25688
- const newNode = {
25689
- name: XML_NODE_NAME$9,
25690
- type: "element",
25691
- attributes: {},
25692
- elements
25693
- };
25694
- return newNode;
25494
+ const tableNodeHandlerEntity = {
25495
+ handlerName: "tableNodeHandler",
25496
+ handler: handleAllTableNodes
25695
25497
  };
25696
- const propertyTranslators$1 = [
25697
- translator$o,
25698
- translator$m,
25699
- translator$i,
25700
- translator$g,
25701
- translator$e,
25702
- translator$c
25703
- ];
25704
- const propertyTranslatorsByXmlName$1 = {};
25705
- const propertyTranslatorsBySdName$1 = {};
25706
- propertyTranslators$1.forEach((translator2) => {
25707
- propertyTranslatorsByXmlName$1[translator2.xmlName] = translator2;
25708
- propertyTranslatorsBySdName$1[translator2.sdNodeOrKeyName] = translator2;
25709
- });
25710
- const translator$a = NodeTranslator.from({
25711
- xmlName: XML_NODE_NAME$9,
25712
- sdNodeOrKeyName: SD_ATTR_KEY$2,
25713
- type: NodeTranslator.translatorTypes.NODE,
25714
- attributes: [],
25715
- encode: encode$9,
25716
- decode: decode$9
25717
- });
25718
- const XML_NODE_NAME$8 = "w:tblPr";
25719
- const SD_ATTR_KEY$1 = "tableProperties";
25720
- const encode$8 = (params) => {
25721
- const { nodes } = params;
25722
- const node = nodes[0];
25723
- const attributes = encodeProperties(node, propertyTranslatorsByXmlName);
25498
+ function handleTableNode(node, params) {
25499
+ const { docx, nodeListHandler } = params;
25500
+ const tblPr = node.elements.find((el) => el.name === "w:tblPr");
25501
+ const tableBordersElement = tblPr.elements.find((el) => el.name === "w:tblBorders");
25502
+ const tableBorders = tableBordersElement?.elements || [];
25503
+ const { borders, rowBorders } = processTableBorders(tableBorders);
25504
+ const tblStyleTag = tblPr.elements.find((el) => el.name === "w:tblStyle");
25505
+ const tableStyleId = tblStyleTag?.attributes["w:val"];
25506
+ const attrs = { tableStyleId };
25507
+ const tableIndent = tblPr?.elements.find((el) => el.name === "w:tblInd");
25508
+ if (tableIndent) {
25509
+ const { "w:w": width, "w:type": type2 } = tableIndent.attributes;
25510
+ attrs["tableIndent"] = { width: twipsToPixels(width), type: type2 };
25511
+ }
25512
+ const tableLayout = tblPr?.elements.find((el) => el.name === "w:tblLayout");
25513
+ if (tableLayout) {
25514
+ const { "w:type": type2 } = tableLayout.attributes;
25515
+ attrs["tableLayout"] = type2;
25516
+ }
25517
+ const referencedStyles = getReferencedTableStyles(tblStyleTag, docx);
25518
+ const tblW = tblPr.elements.find((el) => el.name === "w:tblW");
25519
+ if (tblW) {
25520
+ attrs["tableWidth"] = {
25521
+ width: twipsToPixels(tblW.attributes["w:w"]),
25522
+ type: tblW.attributes["w:type"]
25523
+ };
25524
+ }
25525
+ const tblCellSpacing = tblPr.elements.find((el) => el.name === "w:tblCellSpacing");
25526
+ if (tblCellSpacing) {
25527
+ attrs["tableCellSpacing"] = {
25528
+ w: tblCellSpacing.attributes["w:w"],
25529
+ type: tblCellSpacing.attributes["w:type"]
25530
+ };
25531
+ attrs["borderCollapse"] = "separate";
25532
+ }
25533
+ const tblJustification = tblPr.elements.find((el) => el.name === "w:jc");
25534
+ if (tblJustification?.attributes) {
25535
+ attrs["justification"] = tblJustification.attributes["w:val"];
25536
+ }
25537
+ const rows = node.elements.filter((el) => el.name === "w:tr");
25538
+ const refStylesBorders = referencedStyles?.borders || {};
25539
+ const refStylesRowBorders = referencedStyles?.rowBorders || {};
25540
+ const borderData = Object.keys(borders)?.length ? Object.assign(refStylesBorders, borders) : refStylesBorders;
25541
+ const borderRowData = Object.keys(rowBorders)?.length ? Object.assign(refStylesRowBorders, rowBorders) : refStylesRowBorders;
25542
+ attrs["borders"] = borderData;
25543
+ const content = [];
25544
+ rows.forEach((row) => {
25545
+ const result = translator$3.encode({
25546
+ ...params,
25547
+ nodes: [row],
25548
+ extraParams: {
25549
+ row,
25550
+ table: node,
25551
+ rowBorders: borderRowData,
25552
+ styleTag: tblStyleTag
25553
+ }
25554
+ });
25555
+ if (result.content?.length) content.push(result);
25556
+ });
25724
25557
  return {
25725
- xmlName: XML_NODE_NAME$8,
25726
- sdNodeOrKeyName: SD_ATTR_KEY$1,
25727
- attributes
25558
+ type: "table",
25559
+ content,
25560
+ attrs
25728
25561
  };
25729
- };
25730
- const decode$8 = (params) => {
25731
- const { tableProperties = {} } = params.node.attrs || {};
25732
- const elements = decodeProperties(propertyTranslatorsBySdName, tableProperties);
25733
- const newNode = {
25734
- name: "w:tblPr",
25735
- type: "element",
25736
- attributes: {},
25737
- elements
25738
- };
25739
- return newNode;
25740
- };
25741
- const propertyTranslators = [
25742
- translator$C,
25743
- translator$K,
25744
- translator$B,
25745
- translator$A,
25746
- translator$J,
25747
- translator$z,
25748
- translator$y,
25749
- translator$x,
25750
- translator$w,
25751
- translator$v,
25752
- translator$u,
25753
- translator$t,
25754
- translator$s,
25755
- translator$r,
25756
- translator$q,
25757
- translator$b,
25758
- translator$a
25759
- ];
25760
- const propertyTranslatorsByXmlName = {};
25761
- const propertyTranslatorsBySdName = {};
25762
- propertyTranslators.forEach((translator2) => {
25763
- propertyTranslatorsByXmlName[translator2.xmlName] = translator2;
25764
- propertyTranslatorsBySdName[translator2.sdNodeOrKeyName] = translator2;
25765
- });
25766
- const config$8 = {
25767
- xmlName: XML_NODE_NAME$8,
25768
- sdNodeOrKeyName: SD_ATTR_KEY$1,
25769
- encode: encode$8,
25770
- decode: decode$8
25771
- };
25772
- const translator$9 = NodeTranslator.from(config$8);
25773
- const translator$8 = NodeTranslator.from(
25774
- createSingleAttrPropertyHandler("w:gridCol", "col", "w:w", parseInteger, integerToString)
25775
- );
25776
- const DEFAULT_COLUMN_WIDTH_PX = 100;
25777
- const normalizeTwipWidth = (value) => {
25778
- if (value == null) return null;
25779
- const numericValue = typeof value === "string" ? parseInt(value, 10) : value;
25780
- if (!Number.isFinite(numericValue) || Number.isNaN(numericValue) || numericValue <= 0) {
25781
- return null;
25782
- }
25783
- return numericValue;
25784
- };
25785
- const getSchemaDefaultColumnWidthPx = (params) => {
25786
- const defaultValue = params?.editor?.schema?.nodes?.tableCell?.spec?.attrs?.colwidth?.default;
25787
- if (Array.isArray(defaultValue)) {
25788
- const numericWidth = defaultValue.find((width) => typeof width === "number" && Number.isFinite(width) && width > 0);
25789
- if (numericWidth != null) return numericWidth;
25790
- } else if (typeof defaultValue === "number" && Number.isFinite(defaultValue) && defaultValue > 0) {
25791
- return defaultValue;
25792
- }
25793
- return DEFAULT_COLUMN_WIDTH_PX;
25794
- };
25795
- const getTableWidthPx = (params) => {
25796
- const explicitWidth = params?.node?.attrs?.tableWidth?.width;
25797
- if (typeof explicitWidth === "number" && explicitWidth > 0) return explicitWidth;
25798
- const tableWidth = params?.node?.attrs?.tableProperties?.tableWidth;
25799
- if (tableWidth?.value != null && typeof tableWidth.value === "number" && tableWidth.value > 0) {
25800
- const { value, type: type2 } = tableWidth;
25801
- if (!type2 || type2 === "auto" || type2 === "dxa") {
25802
- return twipsToPixels(value);
25803
- }
25804
- }
25805
- return null;
25806
- };
25807
- const resolveFallbackColumnWidthTwips = (params, totalColumns, cellMinWidthTwips) => {
25808
- const columnCount = Math.max(totalColumns, 1);
25809
- const defaultColumnWidthPx = getSchemaDefaultColumnWidthPx(params);
25810
- const tableWidthPx = getTableWidthPx(params);
25811
- const safeDefaultPx = Number.isFinite(defaultColumnWidthPx) && defaultColumnWidthPx > 0 ? defaultColumnWidthPx : DEFAULT_COLUMN_WIDTH_PX;
25812
- let fallbackWidthPx = safeDefaultPx;
25813
- if (typeof tableWidthPx === "number" && tableWidthPx > 0) {
25814
- fallbackWidthPx = tableWidthPx / columnCount;
25815
- }
25816
- const fallbackWidthTwips = pixelsToTwips(fallbackWidthPx);
25817
- if (!Number.isFinite(fallbackWidthTwips) || Number.isNaN(fallbackWidthTwips) || fallbackWidthTwips <= 0) {
25818
- const safeDefault = Math.max(pixelsToTwips(safeDefaultPx), cellMinWidthTwips);
25819
- return safeDefault;
25820
- }
25821
- return Math.max(fallbackWidthTwips, cellMinWidthTwips);
25822
- };
25823
- const XML_NODE_NAME$7 = "w:tblGrid";
25824
- const SD_ATTR_KEY = "grid";
25825
- const cellMinWidth = pixelsToTwips(10);
25826
- const encode$7 = (params) => {
25827
- const { nodes } = params;
25828
- const node = nodes[0];
25829
- const attributes = encodeProperties(node, { [translator$8.xmlName]: translator$8 }, true);
25830
- return {
25831
- xmlName: XML_NODE_NAME$7,
25832
- sdNodeOrKeyName: SD_ATTR_KEY,
25833
- attributes
25834
- };
25835
- };
25836
- const decode$7 = (params) => {
25837
- const { grid: rawGrid } = params.node.attrs || {};
25838
- const grid = Array.isArray(rawGrid) ? rawGrid : [];
25839
- const { firstRow = {} } = params.extraParams || {};
25840
- const cellNodes = firstRow.content?.filter((n) => n.type === "tableCell") ?? [];
25841
- const columnCountFromCells = cellNodes.reduce((count, cell) => {
25842
- const spanCount = Math.max(1, cell?.attrs?.colspan ?? 1);
25843
- return count + spanCount;
25844
- }, 0);
25845
- const totalColumns = Math.max(columnCountFromCells, grid.length);
25846
- const fallbackColumnWidthTwips = resolveFallbackColumnWidthTwips(params, totalColumns, cellMinWidth);
25847
- const elements = [];
25848
- let columnIndex = 0;
25849
- const pushColumn = (widthTwips) => {
25850
- let numericWidth = typeof widthTwips === "string" ? parseInt(widthTwips, 10) : widthTwips;
25851
- if (numericWidth == null || Number.isNaN(numericWidth) || numericWidth <= 0) {
25852
- numericWidth = fallbackColumnWidthTwips;
25853
- }
25854
- numericWidth = Math.max(numericWidth, cellMinWidth);
25855
- const decoded = translator$8.decode({
25856
- node: { type: (
25857
- /** @type {string} */
25858
- translator$8.sdNodeOrKeyName
25859
- ), attrs: { col: numericWidth } }
25860
- });
25861
- if (decoded) elements.push(decoded);
25862
- };
25863
- cellNodes.forEach((cell) => {
25864
- const { colspan = 1, colwidth } = cell?.attrs || {};
25865
- const spanCount = Math.max(1, colspan);
25866
- for (let span = 0; span < spanCount; span++) {
25867
- const cellWidthPixels = Array.isArray(colwidth) ? colwidth[span] : void 0;
25868
- const colGridAttrs = grid?.[columnIndex] || {};
25869
- const gridWidthTwips = normalizeTwipWidth(colGridAttrs.col);
25870
- const gridWidthPixels = gridWidthTwips != null ? twipsToPixels(gridWidthTwips) : null;
25871
- let cellWidthTwips;
25872
- if (cellWidthPixels != null) {
25873
- if (gridWidthTwips != null && gridWidthPixels === cellWidthPixels) {
25874
- cellWidthTwips = gridWidthTwips;
25875
- } else {
25876
- cellWidthTwips = pixelsToTwips(cellWidthPixels);
25877
- }
25878
- } else if (gridWidthTwips != null) {
25879
- cellWidthTwips = gridWidthTwips;
25880
- } else {
25881
- cellWidthTwips = fallbackColumnWidthTwips;
25882
- }
25883
- pushColumn(cellWidthTwips);
25884
- columnIndex++;
25885
- }
25886
- });
25887
- while (columnIndex < grid.length) {
25888
- const gridWidthTwips = normalizeTwipWidth(grid[columnIndex]?.col);
25889
- pushColumn(gridWidthTwips);
25890
- columnIndex++;
25891
- }
25892
- const newNode = {
25893
- name: XML_NODE_NAME$7,
25894
- attributes: {},
25895
- elements
25896
- };
25897
- return newNode;
25898
- };
25899
- const config$7 = {
25900
- xmlName: XML_NODE_NAME$7,
25901
- sdNodeOrKeyName: SD_ATTR_KEY,
25902
- encode: encode$7,
25903
- decode: decode$7
25904
- };
25905
- const translator$7 = NodeTranslator.from(config$7);
25906
- const XML_NODE_NAME$6 = "w:tbl";
25907
- const SD_NODE_NAME$6 = "table";
25908
- const encode$6 = (params, encodedAttrs) => {
25909
- const { nodes } = params;
25910
- const node = nodes[0];
25911
- const tblPr = node.elements.find((el) => el.name === "w:tblPr");
25912
- if (tblPr) {
25913
- const encodedProperties = translator$9.encode({ ...params, nodes: [tblPr] });
25914
- encodedAttrs["tableProperties"] = encodedProperties?.attributes || {};
25915
- }
25916
- const tblGrid = node.elements.find((el) => el.name === "w:tblGrid");
25917
- if (tblGrid) {
25918
- encodedAttrs["grid"] = translator$7.encode({ ...params, nodes: [tblGrid] }).attributes;
25919
- }
25920
- [
25921
- "tableStyleId",
25922
- "justification",
25923
- "tableLayout",
25924
- ["tableIndent", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
25925
- ["tableWidth", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
25926
- ["tableCellSpacing", ({ value, type: type2 }) => ({ w: String(value), type: type2 })]
25927
- ].forEach((prop) => {
25928
- let key;
25929
- let transform;
25930
- if (Array.isArray(prop)) {
25931
- [key, transform] = prop;
25932
- } else {
25933
- key = prop;
25934
- transform = (v2) => v2;
25935
- }
25936
- if (encodedAttrs.tableProperties && encodedAttrs.tableProperties[key]) {
25937
- encodedAttrs[key] = transform(encodedAttrs.tableProperties[key]);
25938
- }
25939
- });
25940
- if (encodedAttrs.tableCellSpacing) {
25941
- encodedAttrs["borderCollapse"] = "separate";
25942
- }
25943
- const { borders, rowBorders } = _processTableBorders(encodedAttrs.tableProperties?.borders || {});
25944
- const referencedStyles = _getReferencedTableStyles(encodedAttrs.tableStyleId, params);
25945
- if (referencedStyles?.cellMargins && !encodedAttrs.tableProperties?.cellMargins) {
25946
- encodedAttrs.tableProperties = {
25947
- ...encodedAttrs.tableProperties || {},
25948
- cellMargins: referencedStyles.cellMargins
25949
- };
25950
- }
25951
- const rows = node.elements.filter((el) => el.name === "w:tr");
25952
- const borderData = Object.assign({}, referencedStyles?.borders || {}, borders || {});
25953
- const borderRowData = Object.assign({}, referencedStyles?.rowBorders || {}, rowBorders || {});
25954
- encodedAttrs["borders"] = borderData;
25955
- const tblStyleTag = tblPr?.elements?.find((el) => el.name === "w:tblStyle");
25956
- const columnWidths = (encodedAttrs["grid"] ?? []).map((item) => twipsToPixels(item.col));
25957
- const content = [];
25958
- rows.forEach((row) => {
25959
- const result = translator$D.encode({
25960
- ...params,
25961
- nodes: [row],
25962
- extraParams: {
25963
- row,
25964
- table: node,
25965
- rowBorders: borderRowData,
25966
- styleTag: tblStyleTag,
25967
- columnWidths
25968
- }
25969
- });
25970
- if (result.content?.length) content.push(result);
25971
- });
25972
- return {
25973
- type: "table",
25974
- content,
25975
- attrs: encodedAttrs
25976
- };
25977
- };
25978
- const decode$6 = (params, decodedAttrs) => {
25979
- params.node = preProcessVerticalMergeCells(params.node, params);
25980
- const { node } = params;
25981
- const elements = translateChildNodes(params);
25982
- const firstRow = node.content?.find((n) => n.type === "tableRow");
25983
- const properties = node.attrs.grid;
25984
- const element = translator$7.decode({
25985
- ...params,
25986
- node: { ...node, attrs: { ...node.attrs, grid: properties } },
25987
- extraParams: {
25988
- firstRow
25989
- }
25990
- });
25991
- if (element) elements.unshift(element);
25992
- if (node.attrs?.tableProperties) {
25993
- const properties2 = { ...node.attrs.tableProperties };
25994
- const element2 = translator$9.decode({
25995
- ...params,
25996
- node: { ...node, attrs: { ...node.attrs, tableProperties: properties2 } }
25997
- });
25998
- if (element2) elements.unshift(element2);
25999
- }
26000
- return {
26001
- name: "w:tbl",
26002
- attributes: decodedAttrs || {},
26003
- elements
26004
- };
26005
- };
26006
- function _processTableBorders(rawBorders) {
26007
- const borders = {};
26008
- const rowBorders = {};
26009
- Object.entries(rawBorders).forEach(([name, attributes]) => {
26010
- const attrs = {};
26011
- const color = attributes.color;
26012
- const size = attributes.size;
26013
- if (color && color !== "auto") attrs["color"] = color.startsWith("#") ? color : `#${color}`;
26014
- if (size && size !== "auto") attrs["size"] = eigthPointsToPixels(size);
26015
- const rowBorderNames = ["insideH", "insideV"];
26016
- if (rowBorderNames.includes(name)) rowBorders[name] = attrs;
26017
- borders[name] = attrs;
26018
- });
26019
- return {
26020
- borders,
26021
- rowBorders
26022
- };
26023
- }
26024
- function _getReferencedTableStyles(tableStyleReference, params) {
26025
- if (!tableStyleReference) return null;
26026
- const stylesToReturn = {};
26027
- const { docx } = params;
26028
- const styles = docx["word/styles.xml"];
26029
- const { elements } = styles.elements[0];
26030
- const styleElements = elements.filter((el) => el.name === "w:style");
26031
- const styleTag = styleElements.find((el) => el.attributes["w:styleId"] === tableStyleReference);
26032
- if (!styleTag) return null;
26033
- stylesToReturn.name = styleTag.elements.find((el) => el.name === "w:name");
26034
- const basedOn = styleTag.elements.find((el) => el.name === "w:basedOn");
26035
- let baseTblPr;
26036
- if (basedOn?.attributes) {
26037
- const baseStyles = styleElements.find((el) => el.attributes["w:styleId"] === basedOn.attributes["w:val"]);
26038
- baseTblPr = baseStyles ? baseStyles.elements.find((el) => el.name === "w:tblPr") : {};
26039
- }
26040
- const pPr = styleTag.elements.find((el) => el.name === "w:pPr");
26041
- if (pPr) {
26042
- const justification = pPr.elements.find((el) => el.name === "w:jc");
26043
- if (justification?.attributes) stylesToReturn.justification = justification.attributes["w:val"];
26044
- }
26045
- const rPr = styleTag?.elements.find((el) => el.name === "w:rPr");
26046
- if (rPr) {
26047
- const fonts = rPr.elements.find((el) => el.name === "w:rFonts");
26048
- if (fonts) {
26049
- const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
26050
- stylesToReturn.fonts = { ascii, hAnsi, cs };
26051
- }
26052
- const fontSize = rPr.elements.find((el) => el.name === "w:sz");
26053
- if (fontSize?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize.attributes["w:val"]) + "pt";
26054
- }
26055
- const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
26056
- if (tblPr && tblPr.elements) {
26057
- if (baseTblPr && baseTblPr.elements) {
26058
- tblPr.elements.push(...baseTblPr.elements);
26059
- }
26060
- const tableProperties = translator$9.encode({ ...params, nodes: [tblPr] }).attributes;
26061
- const { borders, rowBorders } = _processTableBorders(tableProperties.borders || {});
26062
- if (borders) stylesToReturn.borders = borders;
26063
- if (rowBorders) stylesToReturn.rowBorders = rowBorders;
26064
- const cellMargins = {};
26065
- Object.entries(tableProperties.cellMargins || {}).forEach(([key, attrs]) => {
26066
- if (attrs?.value != null) {
26067
- cellMargins[key] = {
26068
- value: attrs.value,
26069
- type: attrs.type || "dxa"
26070
- };
26071
- }
26072
- });
26073
- if (Object.keys(cellMargins).length) stylesToReturn.cellMargins = cellMargins;
26074
- }
26075
- return stylesToReturn;
26076
25562
  }
26077
- const config$6 = {
26078
- xmlName: XML_NODE_NAME$6,
26079
- sdNodeOrKeyName: SD_NODE_NAME$6,
26080
- type: NodeTranslator.translatorTypes.NODE,
26081
- encode: encode$6,
26082
- decode: decode$6,
26083
- attributes: []
26084
- };
26085
- const translator$6 = NodeTranslator.from(config$6);
26086
- const tableNodeHandlerEntity = generateV2HandlerEntity("tableNodeHandler", translator$6);
26087
25563
  function getReferencedTableStyles(tblStyleTag, docx) {
26088
25564
  if (!tblStyleTag) return null;
26089
25565
  const stylesToReturn = {};
@@ -26164,6 +25640,15 @@ function processTableBorders(borderElements) {
26164
25640
  rowBorders
26165
25641
  };
26166
25642
  }
25643
+ const getGridColumnWidths = (tableNode) => {
25644
+ const tblGrid = tableNode.elements.find((el) => el.name === "w:tblGrid");
25645
+ if (!tblGrid) return [];
25646
+ const columnWidths = tblGrid?.elements?.flatMap((el) => {
25647
+ if (el.name !== "w:gridCol") return [];
25648
+ return twipsToPixels(el.attributes["w:w"]);
25649
+ }) || [];
25650
+ return columnWidths;
25651
+ };
26167
25652
  function handleTableCellNode({
26168
25653
  params,
26169
25654
  node,
@@ -26172,8 +25657,7 @@ function handleTableCellNode({
26172
25657
  rowBorders,
26173
25658
  styleTag,
26174
25659
  columnIndex,
26175
- columnWidth = null,
26176
- allColumnWidths = []
25660
+ columnWidth = null
26177
25661
  }) {
26178
25662
  const { docx, nodeListHandler } = params;
26179
25663
  const tcPr = node.elements.find((el) => el.name === "w:tcPr");
@@ -26187,7 +25671,7 @@ function handleTableCellNode({
26187
25671
  delete rowBorders?.insideV;
26188
25672
  }
26189
25673
  const inlineBorders = processInlineCellBorders(borders, rowBorders);
26190
- const gridColumnWidths = allColumnWidths;
25674
+ const gridColumnWidths = getGridColumnWidths(table);
26191
25675
  const tcWidth = tcPr?.elements?.find((el) => el.name === "w:tcW");
26192
25676
  let width = tcWidth ? twipsToPixels(tcWidth.attributes["w:w"]) : null;
26193
25677
  const widthType = tcWidth?.attributes["w:type"];
@@ -26321,17 +25805,11 @@ const getTableCellMargins = (marginTag, referencedStyles) => {
26321
25805
  marginTop: marginTopStyle,
26322
25806
  marginBottom: marginBottomStyle
26323
25807
  } = cellMargins;
26324
- const resolveMargin = (inlineValue, styleValue) => {
26325
- if (inlineValue != null) return inlineValue;
26326
- if (styleValue == null) return void 0;
26327
- if (typeof styleValue === "object") return styleValue.value;
26328
- return styleValue;
26329
- };
26330
25808
  const margins = {
26331
- left: twipsToPixels(resolveMargin(inlineMarginLeftValue, marginLeftStyle)),
26332
- right: twipsToPixels(resolveMargin(inlineMarginRightValue, marginRightStyle)),
26333
- top: twipsToPixels(resolveMargin(inlineMarginTopValue, marginTopStyle)),
26334
- bottom: twipsToPixels(resolveMargin(inlineMarginBottomValue, marginBottomStyle))
25809
+ left: twipsToPixels(inlineMarginLeftValue ?? marginLeftStyle),
25810
+ right: twipsToPixels(inlineMarginRightValue ?? marginRightStyle),
25811
+ top: twipsToPixels(inlineMarginTopValue ?? marginTopStyle),
25812
+ bottom: twipsToPixels(inlineMarginBottomValue ?? marginBottomStyle)
26335
25813
  };
26336
25814
  return margins;
26337
25815
  };
@@ -26445,20 +25923,11 @@ function generateCellMargins(cellMargins) {
26445
25923
  if (left != null) elements.push({ name: "w:left", attributes: { "w:w": pixelsToTwips(left) } });
26446
25924
  return elements;
26447
25925
  }
26448
- const XML_NODE_NAME$5 = "w:tc";
26449
- const SD_NODE_NAME$5 = "tableCell";
26450
- const validXmlAttributes$5 = [];
26451
- function encode$5(params, encodedAttrs) {
26452
- const {
26453
- node,
26454
- table,
26455
- row,
26456
- rowBorders,
26457
- styleTag,
26458
- columnIndex,
26459
- columnWidth,
26460
- columnWidths: allColumnWidths
26461
- } = params.extraParams;
25926
+ const XML_NODE_NAME$2 = "w:tc";
25927
+ const SD_NODE_NAME$2 = "tableCell";
25928
+ const validXmlAttributes$2 = [];
25929
+ function encode$2(params, encodedAttrs) {
25930
+ const { node, table, row, rowBorders, styleTag, columnIndex, columnWidth } = params.extraParams;
26462
25931
  const schemaNode = handleTableCellNode({
26463
25932
  params,
26464
25933
  node,
@@ -26467,39 +25936,38 @@ function encode$5(params, encodedAttrs) {
26467
25936
  rowBorders,
26468
25937
  styleTag,
26469
25938
  columnIndex,
26470
- columnWidth,
26471
- allColumnWidths
25939
+ columnWidth
26472
25940
  });
26473
25941
  if (encodedAttrs && Object.keys(encodedAttrs).length) {
26474
25942
  schemaNode.attrs = { ...schemaNode.attrs, ...encodedAttrs };
26475
25943
  }
26476
25944
  return schemaNode;
26477
25945
  }
26478
- function decode$5(params, decodedAttrs) {
25946
+ function decode$2(params, decodedAttrs) {
26479
25947
  const translated = translateTableCell(params);
26480
25948
  if (decodedAttrs && Object.keys(decodedAttrs).length) {
26481
25949
  translated.attributes = { ...translated.attributes || {}, ...decodedAttrs };
26482
25950
  }
26483
25951
  return translated;
26484
25952
  }
26485
- const config$5 = {
26486
- xmlName: XML_NODE_NAME$5,
26487
- sdNodeOrKeyName: SD_NODE_NAME$5,
25953
+ const config$2 = {
25954
+ xmlName: XML_NODE_NAME$2,
25955
+ sdNodeOrKeyName: SD_NODE_NAME$2,
26488
25956
  type: NodeTranslator.translatorTypes.NODE,
26489
- encode: encode$5,
26490
- decode: decode$5,
26491
- attributes: validXmlAttributes$5
25957
+ encode: encode$2,
25958
+ decode: decode$2,
25959
+ attributes: validXmlAttributes$2
26492
25960
  };
26493
- const translator$5 = NodeTranslator.from(config$5);
26494
- const XML_NODE_NAME$4 = "w:hyperlink";
26495
- const SD_NODE_NAME$4 = "link";
25961
+ const translator$2 = NodeTranslator.from(config$2);
25962
+ const XML_NODE_NAME$1 = "w:hyperlink";
25963
+ const SD_NODE_NAME$1 = "link";
26496
25964
  const _createAttributeHandler = (xmlName, sdName) => ({
26497
25965
  xmlName,
26498
25966
  sdName,
26499
25967
  encode: (attributes) => attributes[xmlName],
26500
25968
  decode: (attributes) => attributes[sdName]
26501
25969
  });
26502
- const validXmlAttributes$4 = [
25970
+ const validXmlAttributes$1 = [
26503
25971
  _createAttributeHandler("w:anchor", "anchor"),
26504
25972
  _createAttributeHandler("w:docLocation", "docLocation"),
26505
25973
  {
@@ -26512,7 +25980,7 @@ const validXmlAttributes$4 = [
26512
25980
  _createAttributeHandler("r:id", "rId"),
26513
25981
  _createAttributeHandler("w:tgtFrame", "target")
26514
25982
  ];
26515
- const encode$4 = (params, encodedAttrs) => {
25983
+ const encode$1 = (params, encodedAttrs) => {
26516
25984
  const { nodes, docx, nodeListHandler } = params;
26517
25985
  const node = nodes[0];
26518
25986
  let href = _resolveHref(docx, encodedAttrs);
@@ -26543,7 +26011,7 @@ const _resolveHref = (docx, encodedAttrs) => {
26543
26011
  }
26544
26012
  return href;
26545
26013
  };
26546
- function decode$4(params) {
26014
+ function decode$1(params) {
26547
26015
  const { node } = params;
26548
26016
  const linkMark = node.marks.find((m2) => m2.type === "link");
26549
26017
  const linkAttrs = this.decodeAttributes({ ...params, node: linkMark });
@@ -26587,15 +26055,15 @@ function _addNewLinkRelationship(params, link, rId) {
26587
26055
  });
26588
26056
  return rId;
26589
26057
  }
26590
- const config$4 = {
26591
- xmlName: XML_NODE_NAME$4,
26592
- sdNodeOrKeyName: SD_NODE_NAME$4,
26058
+ const config$1 = {
26059
+ xmlName: XML_NODE_NAME$1,
26060
+ sdNodeOrKeyName: SD_NODE_NAME$1,
26593
26061
  type: NodeTranslator.translatorTypes.NODE,
26594
- encode: encode$4,
26595
- decode: decode$4,
26596
- attributes: validXmlAttributes$4
26062
+ encode: encode$1,
26063
+ decode: decode$1,
26064
+ attributes: validXmlAttributes$1
26597
26065
  };
26598
- const translator$4 = NodeTranslator.from(config$4);
26066
+ const translator$1 = NodeTranslator.from(config$1);
26599
26067
  function parseTagValueJSON(json) {
26600
26068
  if (typeof json !== "string") {
26601
26069
  return {};
@@ -26606,7 +26074,7 @@ function parseTagValueJSON(json) {
26606
26074
  }
26607
26075
  try {
26608
26076
  return JSON.parse(trimmed);
26609
- } catch {
26077
+ } catch (err) {
26610
26078
  return {};
26611
26079
  }
26612
26080
  }
@@ -26837,640 +26305,23 @@ function sdtNodeTypeStrategy(node) {
26837
26305
  }
26838
26306
  return { type: "unknown", handler: null };
26839
26307
  }
26840
- function handleImageNode(node, params, isAnchor) {
26841
- const { docx, filename } = params;
26842
- const { attributes } = node;
26843
- const padding = {
26844
- top: emuToPixels(attributes["distT"]),
26845
- bottom: emuToPixels(attributes["distB"]),
26846
- left: emuToPixels(attributes["distL"]),
26847
- right: emuToPixels(attributes["distR"])
26848
- };
26849
- const extent = node.elements.find((el) => el.name === "wp:extent");
26850
- const size = {
26851
- width: emuToPixels(extent.attributes?.cx),
26852
- height: emuToPixels(extent.attributes?.cy)
26853
- };
26854
- const graphic = node.elements.find((el) => el.name === "a:graphic");
26855
- const graphicData = graphic.elements.find((el) => el.name === "a:graphicData");
26856
- const { uri: uri2 } = graphicData?.attributes || {};
26857
- const shapeURI = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
26858
- if (!!uri2 && uri2 === shapeURI) {
26859
- return handleShapeDrawing(params, node, graphicData);
26308
+ class CommandService {
26309
+ /**
26310
+ * @param {import('./commands/types/index.js').CommandServiceOptions} props
26311
+ */
26312
+ constructor(props) {
26313
+ __publicField(this, "editor");
26314
+ __publicField(this, "rawCommands");
26315
+ this.editor = props.editor;
26316
+ this.rawCommands = this.editor.extensionService.commands;
26860
26317
  }
26861
- const picture = graphicData.elements.find((el) => el.name === "pic:pic");
26862
- if (!picture || !picture.elements) return null;
26863
- const blipFill = picture.elements.find((el) => el.name === "pic:blipFill");
26864
- const blip = blipFill.elements.find((el) => el.name === "a:blip");
26865
- const positionHTag = node.elements.find((el) => el.name === "wp:positionH");
26866
- const positionH = positionHTag?.elements.find((el) => el.name === "wp:posOffset");
26867
- const positionHValue = emuToPixels(positionH?.elements[0]?.text);
26868
- const hRelativeFrom = positionHTag?.attributes.relativeFrom;
26869
- const alignH = positionHTag?.elements.find((el) => el.name === "wp:align")?.elements[0]?.text;
26870
- const positionVTag = node.elements.find((el) => el.name === "wp:positionV");
26871
- const positionV = positionVTag?.elements?.find((el) => el.name === "wp:posOffset");
26872
- const positionVValue = emuToPixels(positionV?.elements[0]?.text);
26873
- const vRelativeFrom = positionVTag?.attributes.relativeFrom;
26874
- const alignV = positionVTag?.elements?.find((el) => el.name === "wp:align")?.elements[0]?.text;
26875
- const simplePos = node.elements.find((el) => el.name === "wp:simplePos");
26876
- const wrapSquare = node.elements.find((el) => el.name === "wp:wrapSquare");
26877
- const wrapTopAndBottom = node.elements.find((el) => el.name === "wp:wrapTopAndBottom");
26878
- const docPr = node.elements.find((el) => el.name === "wp:docPr");
26879
- let anchorData = null;
26880
- if (hRelativeFrom || alignH || vRelativeFrom || alignV) {
26881
- anchorData = {
26882
- hRelativeFrom,
26883
- vRelativeFrom,
26884
- alignH,
26885
- alignV
26886
- };
26887
- }
26888
- const marginOffset = {
26889
- left: positionHValue,
26890
- top: positionVValue
26891
- };
26892
- const { attributes: blipAttributes = {} } = blip;
26893
- const rEmbed = blipAttributes["r:embed"];
26894
- if (!rEmbed) return null;
26895
- const currentFile = filename || "document.xml";
26896
- let rels = docx[`word/_rels/${currentFile}.rels`];
26897
- if (!rels) rels = docx[`word/_rels/document.xml.rels`];
26898
- const relationships = rels.elements.find((el) => el.name === "Relationships");
26899
- const { elements } = relationships || [];
26900
- const rel = elements?.find((el) => el.attributes["Id"] === rEmbed);
26901
- if (!rel) return null;
26902
- const { attributes: relAttributes } = rel;
26903
- const targetPath = relAttributes["Target"];
26904
- let path = `word/${targetPath}`;
26905
- if (targetPath.startsWith("/word") || targetPath.startsWith("/media")) path = targetPath.substring(1);
26906
- const extension = targetPath.substring(targetPath.lastIndexOf(".") + 1);
26907
- return {
26908
- type: "image",
26909
- attrs: {
26910
- src: path,
26911
- alt: ["emf", "wmf"].includes(extension) ? "Unable to render EMF/WMF image" : docPr?.attributes.name || "Image",
26912
- extension,
26913
- id: docPr?.attributes.id || "",
26914
- title: docPr?.attributes.descr || "Image",
26915
- inline: true,
26916
- padding,
26917
- marginOffset,
26918
- size,
26919
- anchorData,
26920
- isAnchor,
26921
- ...simplePos && {
26922
- simplePos: {
26923
- x: simplePos.attributes.x,
26924
- y: simplePos.attributes.y
26925
- }
26926
- },
26927
- ...wrapSquare && {
26928
- wrapText: wrapSquare.attributes.wrapText
26929
- },
26930
- wrapTopAndBottom: !!wrapTopAndBottom,
26931
- originalPadding: {
26932
- distT: attributes["distT"],
26933
- distB: attributes["distB"],
26934
- distL: attributes["distL"],
26935
- distR: attributes["distR"]
26936
- },
26937
- originalAttributes: node.attributes,
26938
- rId: relAttributes["Id"]
26939
- }
26940
- };
26941
- }
26942
- const handleShapeDrawing = (params, node, graphicData) => {
26943
- const wsp = graphicData.elements.find((el) => el.name === "wps:wsp");
26944
- const textBox = wsp.elements.find((el) => el.name === "wps:txbx");
26945
- const textBoxContent = textBox?.elements?.find((el) => el.name === "w:txbxContent");
26946
- node.elements.find((el) => el.name === "wp:docPr");
26947
- const spPr = wsp.elements.find((el) => el.name === "wps:spPr");
26948
- const prstGeom = spPr?.elements.find((el) => el.name === "a:prstGeom");
26949
- if (!!prstGeom && prstGeom.attributes["prst"] === "rect" && !textBoxContent) {
26950
- return getRectangleShape(params, spPr);
26951
- }
26952
- if (!textBoxContent) {
26953
- return null;
26954
- }
26955
- const { nodeListHandler } = params;
26956
- const translatedElement = nodeListHandler.handler({
26957
- ...params,
26958
- node: textBoxContent.elements[0],
26959
- nodes: textBoxContent.elements,
26960
- path: [...params.path || [], textBoxContent]
26961
- });
26962
- return translatedElement[0];
26963
- };
26964
- const getRectangleShape = (params, node) => {
26965
- const schemaAttrs = {};
26966
- const [drawingNode] = params.nodes;
26967
- if (drawingNode?.name === "w:drawing") {
26968
- schemaAttrs.drawingContent = drawingNode;
26969
- }
26970
- const xfrm = node.elements.find((el) => el.name === "a:xfrm");
26971
- const start = xfrm.elements.find((el) => el.name === "a:off");
26972
- const size = xfrm.elements.find((el) => el.name === "a:ext");
26973
- const solidFill = node.elements.find((el) => el.name === "a:solidFill");
26974
- node.elements.find((el) => el.name === "a:ln");
26975
- const rectangleSize = {
26976
- top: emuToPixels(start.attributes["y"]),
26977
- left: emuToPixels(start.attributes["x"]),
26978
- width: emuToPixels(size.attributes["cx"]),
26979
- height: emuToPixels(size.attributes["cy"])
26980
- };
26981
- schemaAttrs.size = rectangleSize;
26982
- const background = solidFill?.elements[0]?.attributes["val"];
26983
- if (background) {
26984
- schemaAttrs.background = "#" + background;
26985
- }
26986
- return {
26987
- type: "contentBlock",
26988
- attrs: schemaAttrs
26989
- };
26990
- };
26991
- function handleAnchorNode(params) {
26992
- const { node } = params.extraParams;
26993
- if (node.name !== "wp:anchor") {
26994
- return null;
26995
- }
26996
- return handleImageNode(node, params, true);
26997
- }
26998
- const sanitizeDocxMediaName = (value, fallback = "image") => {
26999
- if (!value) return fallback;
27000
- const sanitized = value.replace(/[^a-zA-Z0-9_-]/g, "_");
27001
- return sanitized || fallback;
27002
- };
27003
- const getFallbackImageNameFromDataUri = (src = "", fallback = "image") => {
27004
- if (!src || typeof src !== "string") return fallback;
27005
- const [prefix] = src.split(";");
27006
- const [, maybeType] = prefix.split("/");
27007
- const extension = maybeType?.toLowerCase();
27008
- return extension ? `${fallback}.${extension}` : fallback;
27009
- };
27010
- const translateImageNode = (params) => {
27011
- const {
27012
- node: { attrs = {} },
27013
- tableCell,
27014
- imageSize
27015
- } = params;
27016
- let imageId = attrs.rId;
27017
- const src = attrs.src || attrs.imageSrc;
27018
- const { originalWidth, originalHeight } = getPngDimensions(src);
27019
- let imageName;
27020
- if (params.node.type === "image") {
27021
- if (src?.startsWith("data:")) {
27022
- imageName = getFallbackImageNameFromDataUri(src);
27023
- } else {
27024
- imageName = src?.split("/").pop();
27025
- }
27026
- } else {
27027
- imageName = attrs.fieldId;
27028
- }
27029
- imageName = sanitizeDocxMediaName(imageName);
27030
- let size = attrs.size ? {
27031
- w: pixelsToEmu(attrs.size.width),
27032
- h: pixelsToEmu(attrs.size.height)
27033
- } : imageSize;
27034
- if (originalWidth && originalHeight) {
27035
- const boxWidthPx = emuToPixels(size.w);
27036
- const boxHeightPx = emuToPixels(size.h);
27037
- const { scaledWidth, scaledHeight } = getScaledSize(originalWidth, originalHeight, boxWidthPx, boxHeightPx);
27038
- size = {
27039
- w: pixelsToEmu(scaledWidth),
27040
- h: pixelsToEmu(scaledHeight)
27041
- };
27042
- }
27043
- if (tableCell) {
27044
- const colwidthSum = tableCell.attrs.colwidth.reduce((acc, curr) => acc + curr, 0);
27045
- const leftMargin = tableCell.attrs.cellMargins?.left || 8;
27046
- const rightMargin = tableCell.attrs.cellMargins?.right || 8;
27047
- const maxWidthEmu = pixelsToEmu(colwidthSum - (leftMargin + rightMargin));
27048
- const { width: w2, height: h2 } = resizeKeepAspectRatio(size.w, size.h, maxWidthEmu);
27049
- if (w2 && h2) size = { w: w2, h: h2 };
27050
- }
27051
- if (params.node.type === "image" && !imageId) {
27052
- const path = src?.split("word/")[1];
27053
- imageId = addNewImageRelationship(params, path);
27054
- } else if (params.node.type === "fieldAnnotation" && !imageId) {
27055
- const type2 = src?.split(";")[0].split("/")[1];
27056
- if (!type2) {
27057
- return prepareTextAnnotation(params);
27058
- }
27059
- const sanitizedHash = sanitizeDocxMediaName(attrs.hash, generateDocxRandomId(4));
27060
- const fileName = `${imageName}_${sanitizedHash}.${type2}`;
27061
- const relationshipTarget = `media/${fileName}`;
27062
- const packagePath = `word/${relationshipTarget}`;
27063
- imageId = addNewImageRelationship(params, relationshipTarget);
27064
- params.media[packagePath] = src;
27065
- }
27066
- const inlineAttrs = attrs.originalPadding || {
27067
- distT: 0,
27068
- distB: 0,
27069
- distL: 0,
27070
- distR: 0
27071
- };
27072
- const drawingXmlns = "http://schemas.openxmlformats.org/drawingml/2006/main";
27073
- const pictureXmlns = "http://schemas.openxmlformats.org/drawingml/2006/picture";
27074
- return {
27075
- attributes: inlineAttrs,
27076
- elements: [
27077
- {
27078
- name: "wp:extent",
27079
- attributes: {
27080
- cx: size.w,
27081
- cy: size.h
27082
- }
27083
- },
27084
- {
27085
- name: "wp:effectExtent",
27086
- attributes: {
27087
- l: 0,
27088
- t: 0,
27089
- r: 0,
27090
- b: 0
27091
- }
27092
- },
27093
- {
27094
- name: "wp:docPr",
27095
- attributes: {
27096
- id: attrs.id || 0,
27097
- name: attrs.alt || `Picture ${imageName}`
27098
- }
27099
- },
27100
- {
27101
- name: "wp:cNvGraphicFramePr",
27102
- elements: [
27103
- {
27104
- name: "a:graphicFrameLocks",
27105
- attributes: {
27106
- "xmlns:a": drawingXmlns,
27107
- noChangeAspect: 1
27108
- }
27109
- }
27110
- ]
27111
- },
27112
- {
27113
- name: "a:graphic",
27114
- attributes: { "xmlns:a": drawingXmlns },
27115
- elements: [
27116
- {
27117
- name: "a:graphicData",
27118
- attributes: { uri: pictureXmlns },
27119
- elements: [
27120
- {
27121
- name: "pic:pic",
27122
- attributes: { "xmlns:pic": pictureXmlns },
27123
- elements: [
27124
- {
27125
- name: "pic:nvPicPr",
27126
- elements: [
27127
- {
27128
- name: "pic:cNvPr",
27129
- attributes: {
27130
- id: attrs.id || 0,
27131
- name: attrs.title || `Picture ${imageName}`
27132
- }
27133
- },
27134
- {
27135
- name: "pic:cNvPicPr",
27136
- elements: [
27137
- {
27138
- name: "a:picLocks",
27139
- attributes: {
27140
- noChangeAspect: 1,
27141
- noChangeArrowheads: 1
27142
- }
27143
- }
27144
- ]
27145
- }
27146
- ]
27147
- },
27148
- {
27149
- name: "pic:blipFill",
27150
- elements: [
27151
- {
27152
- name: "a:blip",
27153
- attributes: {
27154
- "r:embed": imageId
27155
- }
27156
- },
27157
- {
27158
- name: "a:stretch",
27159
- elements: [{ name: "a:fillRect" }]
27160
- }
27161
- ]
27162
- },
27163
- {
27164
- name: "pic:spPr",
27165
- attributes: {
27166
- bwMode: "auto"
27167
- },
27168
- elements: [
27169
- {
27170
- name: "a:xfrm",
27171
- elements: [
27172
- {
27173
- name: "a:ext",
27174
- attributes: {
27175
- cx: size.w,
27176
- cy: size.h
27177
- }
27178
- },
27179
- {
27180
- name: "a:off",
27181
- attributes: {
27182
- x: 0,
27183
- y: 0
27184
- }
27185
- }
27186
- ]
27187
- },
27188
- {
27189
- name: "a:prstGeom",
27190
- attributes: { prst: "rect" },
27191
- elements: [{ name: "a:avLst" }]
27192
- },
27193
- {
27194
- name: "a:noFill"
27195
- }
27196
- ]
27197
- }
27198
- ]
27199
- }
27200
- ]
27201
- }
27202
- ]
27203
- }
27204
- ]
27205
- };
27206
- };
27207
- function getPngDimensions(base64) {
27208
- if (!base64) return {};
27209
- const type2 = base64.split(";")[0].split("/")[1];
27210
- if (!base64 || type2 !== "png") {
27211
- return {
27212
- originalWidth: void 0,
27213
- originalHeight: void 0
27214
- };
27215
- }
27216
- let header = base64.split(",")[1].slice(0, 50);
27217
- let uint8 = Uint8Array.from(atob(header), (c) => c.charCodeAt(0));
27218
- let dataView = new DataView(uint8.buffer, 0, 28);
27219
- return {
27220
- originalWidth: dataView.getInt32(16),
27221
- originalHeight: dataView.getInt32(20)
27222
- };
27223
- }
27224
- function getScaledSize(originalWidth, originalHeight, maxWidth, maxHeight) {
27225
- let scaledWidth = originalWidth;
27226
- let scaledHeight = originalHeight;
27227
- let ratio = Math.min(maxWidth / originalWidth, maxHeight / originalHeight);
27228
- scaledWidth = Math.round(scaledWidth * ratio);
27229
- scaledHeight = Math.round(scaledHeight * ratio);
27230
- return { scaledWidth, scaledHeight };
27231
- }
27232
- function resizeKeepAspectRatio(width, height, maxWidth) {
27233
- if (width > maxWidth) {
27234
- let scale = maxWidth / width;
27235
- let newHeight = Math.round(height * scale);
27236
- return { width: maxWidth, height: newHeight };
27237
- }
27238
- return { width, height };
27239
- }
27240
- function addNewImageRelationship(params, imagePath) {
27241
- const newId = "rId" + generateDocxRandomId();
27242
- const newRel = {
27243
- type: "element",
27244
- name: "Relationship",
27245
- attributes: {
27246
- Id: newId,
27247
- Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
27248
- Target: imagePath
27249
- }
27250
- };
27251
- params.relationships.push(newRel);
27252
- return newId;
27253
- }
27254
- function translateAnchorNode(params) {
27255
- const { attrs } = params.node;
27256
- const anchorElements = [];
27257
- const wrapElements = [];
27258
- if (attrs.simplePos) {
27259
- anchorElements.push({
27260
- name: "wp:simplePos",
27261
- attributes: {
27262
- x: 0,
27263
- y: 0
27264
- }
27265
- });
27266
- }
27267
- if (attrs.anchorData) {
27268
- const hElements = [];
27269
- if (attrs.marginOffset.left !== void 0) {
27270
- hElements.push({
27271
- name: "wp:posOffset",
27272
- elements: [{ type: "text", text: pixelsToEmu(attrs.marginOffset.left).toString() }]
27273
- });
27274
- }
27275
- if (attrs.anchorData.alignH) {
27276
- hElements.push({
27277
- name: "wp:align",
27278
- elements: [{ type: "text", text: attrs.anchorData.alignH }]
27279
- });
27280
- }
27281
- anchorElements.push({
27282
- name: "wp:positionH",
27283
- attributes: { relativeFrom: attrs.anchorData.hRelativeFrom },
27284
- ...hElements.length && { elements: hElements }
27285
- });
27286
- const vElements = [];
27287
- if (attrs.marginOffset.top !== void 0) {
27288
- vElements.push({
27289
- name: "wp:posOffset",
27290
- elements: [{ type: "text", text: pixelsToEmu(attrs.marginOffset.top).toString() }]
27291
- });
27292
- }
27293
- if (attrs.anchorData.alignV) {
27294
- vElements.push({
27295
- name: "wp:align",
27296
- elements: [{ type: "text", text: attrs.anchorData.alignV }]
27297
- });
27298
- }
27299
- anchorElements.push({
27300
- name: "wp:positionV",
27301
- attributes: { relativeFrom: attrs.anchorData.vRelativeFrom },
27302
- ...vElements.length && { elements: vElements }
27303
- });
27304
- }
27305
- if (attrs.wrapText) {
27306
- wrapElements.push({
27307
- name: "wp:wrapSquare",
27308
- attributes: {
27309
- wrapText: attrs.wrapText
27310
- }
27311
- });
27312
- }
27313
- if (attrs.wrapTopAndBottom) {
27314
- wrapElements.push({
27315
- name: "wp:wrapTopAndBottom"
27316
- });
27317
- }
27318
- if (!wrapElements.length) {
27319
- wrapElements.push({
27320
- name: "wp:wrapNone"
27321
- });
27322
- }
27323
- const nodeElements = translateImageNode(params);
27324
- const inlineAttrs = {
27325
- ...nodeElements.attributes,
27326
- simplePos: attrs.originalAttributes?.simplePos,
27327
- relativeHeight: 1,
27328
- behindDoc: attrs.originalAttributes?.behindDoc,
27329
- locked: attrs.originalAttributes?.locked,
27330
- layoutInCell: attrs.originalAttributes?.layoutInCell,
27331
- allowOverlap: attrs.originalAttributes?.allowOverlap
27332
- };
27333
- const effectIndex = nodeElements.elements.findIndex((el) => el.name === "wp:effectExtent");
27334
- const elementsWithWrap = [
27335
- ...nodeElements.elements.slice(0, effectIndex + 1),
27336
- ...wrapElements,
27337
- ...nodeElements.elements.slice(effectIndex + 1)
27338
- ];
27339
- return {
27340
- name: "wp:anchor",
27341
- attributes: inlineAttrs,
27342
- elements: [...anchorElements, ...elementsWithWrap]
27343
- };
27344
- }
27345
- const XML_NODE_NAME$3 = "wp:anchor";
27346
- const SD_NODE_NAME$3 = ["image"];
27347
- const validXmlAttributes$3 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
27348
- function encode$3(params) {
27349
- const { node } = params.extraParams;
27350
- if (!node || !node.type) {
27351
- return null;
27352
- }
27353
- return handleAnchorNode(params);
27354
- }
27355
- function decode$3(params) {
27356
- const { node } = params;
27357
- if (!node || !node.type) {
27358
- return null;
27359
- }
27360
- return translateAnchorNode(params);
27361
- }
27362
- const config$3 = {
27363
- xmlName: XML_NODE_NAME$3,
27364
- sdNodeOrKeyName: SD_NODE_NAME$3,
27365
- type: NodeTranslator.translatorTypes.NODE,
27366
- encode: encode$3,
27367
- decode: decode$3,
27368
- attributes: validXmlAttributes$3
27369
- };
27370
- const translator$3 = NodeTranslator.from(config$3);
27371
- function handleInlineNode(params) {
27372
- const { node } = params.extraParams;
27373
- if (node.name !== "wp:inline") {
27374
- return null;
27375
- }
27376
- return handleImageNode(node, params, false);
27377
- }
27378
- function translateInlineNode(params) {
27379
- const nodeElements = translateImageNode(params);
27380
- return {
27381
- name: "wp:inline",
27382
- attributes: nodeElements.attributes,
27383
- elements: nodeElements.elements
27384
- };
27385
- }
27386
- const XML_NODE_NAME$2 = "wp:inline";
27387
- const SD_NODE_NAME$2 = ["image"];
27388
- const validXmlAttributes$2 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
27389
- function encode$2(params) {
27390
- const { node } = params.extraParams;
27391
- if (!node || !node.type) {
27392
- return null;
27393
- }
27394
- return handleInlineNode(params);
27395
- }
27396
- function decode$2(params) {
27397
- const { node } = params;
27398
- if (!node || !node.type) {
27399
- return null;
27400
- }
27401
- return translateInlineNode(params);
27402
- }
27403
- const config$2 = {
27404
- xmlName: XML_NODE_NAME$2,
27405
- sdNodeOrKeyName: SD_NODE_NAME$2,
27406
- type: NodeTranslator.translatorTypes.NODE,
27407
- encode: encode$2,
27408
- decode: decode$2,
27409
- attributes: validXmlAttributes$2
27410
- };
27411
- const translator$2 = NodeTranslator.from(config$2);
27412
- const registeredHandlers = Object.freeze({
27413
- "w:br": translator$T,
27414
- "w:tab": translator$S,
27415
- "w:p": translator$R,
27416
- "wp:anchor": translator$3,
27417
- "wp:inline": translator$2
27418
- });
27419
- const XML_NODE_NAME$1 = "w:drawing";
27420
- const SD_NODE_NAME$1 = [];
27421
- const validXmlAttributes$1 = [];
27422
- function encode$1(params) {
27423
- const nodes = params.nodes;
27424
- const node = nodes[0];
27425
- const validChildTranslators = ["wp:anchor", "wp:inline"];
27426
- return node.elements.reduce((acc, child) => {
27427
- if (acc) return acc;
27428
- if (!validChildTranslators.includes(child.name)) return acc;
27429
- const translator2 = registeredHandlers[child.name];
27430
- return translator2.encode({ ...params, extraParams: { node: child } }) || acc;
27431
- }, null);
27432
- }
27433
- function decode$1(params) {
27434
- const { node } = params;
27435
- if (!node || !node.type) {
27436
- return null;
27437
- }
27438
- const handlerName = node.attrs.isAnchor ? "wp:anchor" : "wp:inline";
27439
- const resultNode = registeredHandlers[handlerName].decode(params);
27440
- return wrapTextInRun(
27441
- {
27442
- name: "w:drawing",
27443
- elements: [resultNode]
27444
- },
27445
- []
27446
- );
27447
- }
27448
- const config$1 = {
27449
- xmlName: XML_NODE_NAME$1,
27450
- sdNodeOrKeyName: SD_NODE_NAME$1,
27451
- type: NodeTranslator.translatorTypes.NODE,
27452
- encode: encode$1,
27453
- decode: decode$1,
27454
- attributes: validXmlAttributes$1
27455
- };
27456
- const translator$1 = NodeTranslator.from(config$1);
27457
- class CommandService {
27458
- /**
27459
- * @param {import('./commands/types/index.js').CommandServiceOptions} props
27460
- */
27461
- constructor(props) {
27462
- __publicField(this, "editor");
27463
- __publicField(this, "rawCommands");
27464
- this.editor = props.editor;
27465
- this.rawCommands = this.editor.extensionService.commands;
27466
- }
27467
- /**
27468
- * Static method for creating a service.
27469
- * @param {import('./commands/types/index.js').CommandServiceOptions} params for the constructor.
27470
- * @returns {CommandService} New instance of CommandService
27471
- */
27472
- static create(params) {
27473
- return new CommandService(params);
26318
+ /**
26319
+ * Static method for creating a service.
26320
+ * @param {import('./commands/types/index.js').CommandServiceOptions} params for the constructor.
26321
+ * @returns {CommandService} New instance of CommandService
26322
+ */
26323
+ static create(params) {
26324
+ return new CommandService(params);
27474
26325
  }
27475
26326
  /**
27476
26327
  * Get editor state.
@@ -28791,10 +27642,7 @@ function prepareTextAnnotation(params) {
28791
27642
  return getTextNodeForExport(attrs.displayLabel, [...marks, ...marksFromAttrs], params);
28792
27643
  }
28793
27644
  function prepareImageAnnotation(params, imageSize) {
28794
- return translator$1.decode({
28795
- ...params,
28796
- imageSize
28797
- });
27645
+ return translateImageNode(params, imageSize);
28798
27646
  }
28799
27647
  function prepareCheckboxAnnotation(params) {
28800
27648
  const {
@@ -29031,7 +27879,7 @@ function translateStructuredContent(params) {
29031
27879
  const XML_NODE_NAME = "w:sdt";
29032
27880
  const SD_NODE_NAME = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
29033
27881
  const validXmlAttributes = [];
29034
- function encode(params) {
27882
+ function encode(params, encodedAttrs) {
29035
27883
  const nodes = params.nodes;
29036
27884
  const node = nodes[0];
29037
27885
  const { type: sdtType, handler: handler2 } = sdtNodeTypeStrategy(node);
@@ -29041,7 +27889,7 @@ function encode(params) {
29041
27889
  const result = handler2(params);
29042
27890
  return result;
29043
27891
  }
29044
- function decode(params) {
27892
+ function decode(params, decodedAttrs) {
29045
27893
  const { node } = params;
29046
27894
  if (!node || !node.type) {
29047
27895
  return null;
@@ -29072,19 +27920,19 @@ function exportSchemaToJson(params) {
29072
27920
  doc: translateDocumentNode,
29073
27921
  body: translateBodyNode,
29074
27922
  heading: translateHeadingNode,
29075
- paragraph: translator$R,
27923
+ paragraph: translator$h,
29076
27924
  text: translateTextNode,
29077
27925
  bulletList: translateList,
29078
27926
  orderedList: translateList,
29079
- lineBreak: translator$T,
29080
- table: translator$6,
29081
- tableRow: translator$D,
29082
- tableCell: translator$5,
27927
+ lineBreak: translator$j,
27928
+ table: translateTable,
27929
+ tableRow: translator$3,
27930
+ tableCell: translator$2,
29083
27931
  bookmarkStart: translateBookmarkStart,
29084
27932
  fieldAnnotation: translator,
29085
- tab: translator$S,
29086
- image: translator$1,
29087
- hardBreak: translator$T,
27933
+ tab: translator$i,
27934
+ image: translateImageNode,
27935
+ hardBreak: translator$j,
29088
27936
  commentRangeStart: () => translateCommentNode(params, "Start"),
29089
27937
  commentRangeEnd: () => translateCommentNode(params, "End"),
29090
27938
  commentReference: () => null,
@@ -29416,7 +28264,7 @@ function translateTextNode(params) {
29416
28264
  const isTrackedNode = node.marks?.some((m2) => trackedMarks.includes(m2.type));
29417
28265
  if (isTrackedNode) return translateTrackedNode(params);
29418
28266
  const isLinkNode = node.marks?.some((m2) => m2.type === "link");
29419
- if (isLinkNode) return translator$4.decode(params);
28267
+ if (isLinkNode) return translator$1.decode(params);
29420
28268
  const { text, marks = [] } = node;
29421
28269
  return getTextNodeForExport(text, marks, params);
29422
28270
  }
@@ -29549,6 +28397,20 @@ function addNewLinkRelationship(params, link) {
29549
28397
  });
29550
28398
  return newId;
29551
28399
  }
28400
+ function addNewImageRelationship(params, imagePath) {
28401
+ const newId = "rId" + generateDocxRandomId();
28402
+ const newRel = {
28403
+ type: "element",
28404
+ name: "Relationship",
28405
+ attributes: {
28406
+ Id: newId,
28407
+ Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
28408
+ Target: imagePath
28409
+ }
28410
+ };
28411
+ params.relationships.push(newRel);
28412
+ return newId;
28413
+ }
29552
28414
  function translateList(params) {
29553
28415
  const { node, editor } = params;
29554
28416
  const listItem = node.content[0];
@@ -29691,6 +28553,165 @@ const generateNumPrTag = (numId, level) => {
29691
28553
  ]
29692
28554
  };
29693
28555
  };
28556
+ function translateTable(params) {
28557
+ params.node = preProcessVerticalMergeCells(params.node, params);
28558
+ const elements = translateChildNodes(params);
28559
+ const tableProperties = generateTableProperties(params.node);
28560
+ const gridProperties = generateTableGrid(params.node, params);
28561
+ elements.unshift(tableProperties);
28562
+ elements.unshift(gridProperties);
28563
+ return {
28564
+ name: "w:tbl",
28565
+ elements
28566
+ };
28567
+ }
28568
+ function preProcessVerticalMergeCells(table, { editorSchema }) {
28569
+ const { content } = table;
28570
+ for (let rowIndex = 0; rowIndex < content.length; rowIndex++) {
28571
+ const row = content[rowIndex];
28572
+ if (!row.content) continue;
28573
+ for (let cellIndex = 0; cellIndex < row.content?.length; cellIndex++) {
28574
+ const cell = row.content[cellIndex];
28575
+ if (!cell) continue;
28576
+ const { attrs } = cell;
28577
+ if (attrs.rowspan > 1) {
28578
+ const rowsToChange = content.slice(rowIndex + 1, rowIndex + attrs.rowspan);
28579
+ const mergedCell = {
28580
+ type: cell.type,
28581
+ content: [
28582
+ // cells must end with a paragraph
28583
+ editorSchema.nodes.paragraph.createAndFill().toJSON()
28584
+ ],
28585
+ attrs: {
28586
+ ...cell.attrs,
28587
+ // reset colspan and rowspan
28588
+ colspan: null,
28589
+ rowspan: null,
28590
+ // to add vMerge
28591
+ continueMerge: true
28592
+ }
28593
+ };
28594
+ rowsToChange.forEach((rowToChange) => {
28595
+ rowToChange.content.splice(cellIndex, 0, mergedCell);
28596
+ });
28597
+ }
28598
+ }
28599
+ }
28600
+ return table;
28601
+ }
28602
+ function generateTableProperties(node) {
28603
+ const elements = [];
28604
+ const { attrs } = node;
28605
+ const { tableWidth, tableStyleId, borders, tableIndent, tableLayout, tableCellSpacing, justification } = attrs;
28606
+ if (tableStyleId) {
28607
+ const tableStyleElement = {
28608
+ name: "w:tblStyle",
28609
+ attributes: { "w:val": tableStyleId }
28610
+ };
28611
+ elements.push(tableStyleElement);
28612
+ }
28613
+ if (borders) {
28614
+ const borderElement = generateTableBorders(node);
28615
+ elements.push(borderElement);
28616
+ }
28617
+ if (tableIndent) {
28618
+ const { width, type: type2 } = tableIndent;
28619
+ const tableIndentElement = {
28620
+ name: "w:tblInd",
28621
+ attributes: { "w:w": pixelsToTwips(width), "w:type": type2 }
28622
+ };
28623
+ elements.push(tableIndentElement);
28624
+ }
28625
+ if (tableLayout) {
28626
+ const tableLayoutElement = {
28627
+ name: "w:tblLayout",
28628
+ attributes: { "w:type": tableLayout }
28629
+ };
28630
+ elements.push(tableLayoutElement);
28631
+ }
28632
+ if (tableWidth && tableWidth.width) {
28633
+ const tableWidthElement = {
28634
+ name: "w:tblW",
28635
+ attributes: { "w:w": pixelsToTwips(tableWidth.width), "w:type": tableWidth.type }
28636
+ };
28637
+ elements.push(tableWidthElement);
28638
+ }
28639
+ if (tableCellSpacing) {
28640
+ elements.push({
28641
+ name: "w:tblCellSpacing",
28642
+ attributes: {
28643
+ "w:w": tableCellSpacing.w,
28644
+ "w:type": tableCellSpacing.type
28645
+ }
28646
+ });
28647
+ }
28648
+ if (justification) {
28649
+ const justificationElement = {
28650
+ name: "w:jc",
28651
+ attributes: { "w:val": justification }
28652
+ };
28653
+ elements.push(justificationElement);
28654
+ }
28655
+ return {
28656
+ name: "w:tblPr",
28657
+ elements
28658
+ };
28659
+ }
28660
+ function generateTableBorders(node) {
28661
+ const { borders } = node.attrs;
28662
+ const elements = [];
28663
+ if (!borders) return;
28664
+ const borderTypes = ["top", "bottom", "left", "right", "insideH", "insideV"];
28665
+ borderTypes.forEach((type2) => {
28666
+ const border = borders[type2];
28667
+ if (!border) return;
28668
+ let attributes = {};
28669
+ if (!Object.keys(border).length || !border.size) {
28670
+ attributes = {
28671
+ "w:val": "nil"
28672
+ };
28673
+ } else {
28674
+ attributes = {
28675
+ "w:val": "single",
28676
+ "w:sz": pixelsToEightPoints(border.size),
28677
+ "w:space": border.space || 0,
28678
+ "w:color": border?.color?.substring(1) || "000000"
28679
+ };
28680
+ }
28681
+ const borderElement = {
28682
+ name: `w:${type2}`,
28683
+ attributes
28684
+ };
28685
+ elements.push(borderElement);
28686
+ });
28687
+ return {
28688
+ name: "w:tblBorders",
28689
+ elements
28690
+ };
28691
+ }
28692
+ function generateTableGrid(node, params) {
28693
+ const { editorSchema } = params;
28694
+ let colgroup = [];
28695
+ try {
28696
+ const pmNode = editorSchema.nodeFromJSON(node);
28697
+ const cellMinWidth = 10;
28698
+ const { colgroupValues } = createColGroup(pmNode, cellMinWidth);
28699
+ colgroup = colgroupValues;
28700
+ } catch {
28701
+ colgroup = [];
28702
+ }
28703
+ const elements = [];
28704
+ colgroup?.forEach((width) => {
28705
+ elements.push({
28706
+ name: "w:gridCol",
28707
+ attributes: { "w:w": pixelsToTwips(width) }
28708
+ });
28709
+ });
28710
+ return {
28711
+ name: "w:tblGrid",
28712
+ elements
28713
+ };
28714
+ }
29694
28715
  function translateBookmarkStart(params) {
29695
28716
  const bookmarkStartNode = {
29696
28717
  name: "w:bookmarkStart",
@@ -29743,44 +28764,370 @@ function translateMark(mark) {
29743
28764
  const parsedValue = value.split(", ");
29744
28765
  markElement.attributes[attr] = parsedValue[0] ? parsedValue[0] : value;
29745
28766
  });
29746
- break;
29747
- // Add ability to get run styleIds from textStyle marks and inject to run properties in word
29748
- case "styleId":
29749
- markElement.name = "w:rStyle";
29750
- markElement.attributes["w:val"] = attrs.styleId;
29751
- break;
29752
- case "color":
29753
- let processedColor = attrs.color.replace(/^#/, "").replace(/;$/, "");
29754
- if (processedColor.startsWith("rgb")) {
29755
- processedColor = rgbToHex(processedColor);
29756
- }
29757
- markElement.attributes["w:val"] = processedColor;
29758
- break;
29759
- case "textAlign":
29760
- markElement.attributes["w:val"] = attrs.textAlign;
29761
- break;
29762
- case "textIndent":
29763
- markElement.attributes["w:firstline"] = inchesToTwips(attrs.textIndent);
29764
- break;
29765
- case "textTransform":
29766
- if (attrs?.textTransform === "none") {
29767
- markElement.attributes["w:val"] = "0";
29768
- } else {
29769
- delete markElement.attributes;
29770
- }
29771
- markElement.type = "element";
29772
- break;
29773
- case "lineHeight":
29774
- markElement.attributes["w:line"] = linesToTwips(attrs.lineHeight);
29775
- break;
29776
- case "highlight":
29777
- markElement.attributes["w:fill"] = attrs.color?.substring(1);
29778
- markElement.attributes["w:color"] = "auto";
29779
- markElement.attributes["w:val"] = "clear";
29780
- markElement.name = "w:shd";
29781
- break;
28767
+ break;
28768
+ // Add ability to get run styleIds from textStyle marks and inject to run properties in word
28769
+ case "styleId":
28770
+ markElement.name = "w:rStyle";
28771
+ markElement.attributes["w:val"] = attrs.styleId;
28772
+ break;
28773
+ case "color":
28774
+ let processedColor = attrs.color.replace(/^#/, "").replace(/;$/, "");
28775
+ if (processedColor.startsWith("rgb")) {
28776
+ processedColor = rgbToHex(processedColor);
28777
+ }
28778
+ markElement.attributes["w:val"] = processedColor;
28779
+ break;
28780
+ case "textAlign":
28781
+ markElement.attributes["w:val"] = attrs.textAlign;
28782
+ break;
28783
+ case "textIndent":
28784
+ markElement.attributes["w:firstline"] = inchesToTwips(attrs.textIndent);
28785
+ break;
28786
+ case "textTransform":
28787
+ if (attrs?.textTransform === "none") {
28788
+ markElement.attributes["w:val"] = "0";
28789
+ } else {
28790
+ delete markElement.attributes;
28791
+ }
28792
+ markElement.type = "element";
28793
+ break;
28794
+ case "lineHeight":
28795
+ markElement.attributes["w:line"] = linesToTwips(attrs.lineHeight);
28796
+ break;
28797
+ case "highlight":
28798
+ markElement.attributes["w:fill"] = attrs.color?.substring(1);
28799
+ markElement.attributes["w:color"] = "auto";
28800
+ markElement.attributes["w:val"] = "clear";
28801
+ markElement.name = "w:shd";
28802
+ break;
28803
+ }
28804
+ return markElement;
28805
+ }
28806
+ function getPngDimensions(base64) {
28807
+ if (!base64) return {};
28808
+ const type2 = base64.split(";")[0].split("/")[1];
28809
+ if (!base64 || type2 !== "png") {
28810
+ return {
28811
+ originalWidth: void 0,
28812
+ originalHeight: void 0
28813
+ };
28814
+ }
28815
+ let header = base64.split(",")[1].slice(0, 50);
28816
+ let uint8 = Uint8Array.from(atob(header), (c) => c.charCodeAt(0));
28817
+ let dataView = new DataView(uint8.buffer, 0, 28);
28818
+ return {
28819
+ originalWidth: dataView.getInt32(16),
28820
+ originalHeight: dataView.getInt32(20)
28821
+ };
28822
+ }
28823
+ function getScaledSize(originalWidth, originalHeight, maxWidth, maxHeight) {
28824
+ let scaledWidth = originalWidth;
28825
+ let scaledHeight = originalHeight;
28826
+ let ratio = Math.min(maxWidth / originalWidth, maxHeight / originalHeight);
28827
+ scaledWidth = Math.round(scaledWidth * ratio);
28828
+ scaledHeight = Math.round(scaledHeight * ratio);
28829
+ return { scaledWidth, scaledHeight };
28830
+ }
28831
+ function translateImageNode(params, imageSize) {
28832
+ const {
28833
+ node: { attrs = {} },
28834
+ tableCell
28835
+ } = params;
28836
+ let imageId = attrs.rId;
28837
+ const src = attrs.src || attrs.imageSrc;
28838
+ const { originalWidth, originalHeight } = getPngDimensions(src);
28839
+ const imageName = params.node.type === "image" ? src.split("/").pop() : attrs.fieldId?.replace("-", "_");
28840
+ let size = attrs.size ? {
28841
+ w: pixelsToEmu(attrs.size.width),
28842
+ h: pixelsToEmu(attrs.size.height)
28843
+ } : imageSize;
28844
+ if (originalWidth && originalHeight) {
28845
+ const boxWidthPx = emuToPixels(size.w);
28846
+ const boxHeightPx = emuToPixels(size.h);
28847
+ const { scaledWidth, scaledHeight } = getScaledSize(originalWidth, originalHeight, boxWidthPx, boxHeightPx);
28848
+ size = {
28849
+ w: pixelsToEmu(scaledWidth),
28850
+ h: pixelsToEmu(scaledHeight)
28851
+ };
28852
+ }
28853
+ if (tableCell) {
28854
+ const colwidthSum = tableCell.attrs.colwidth.reduce((acc, curr) => acc + curr, 0);
28855
+ const leftMargin = tableCell.attrs.cellMargins?.left || 8;
28856
+ const rightMargin = tableCell.attrs.cellMargins?.right || 8;
28857
+ const maxWidthEmu = pixelsToEmu(colwidthSum - (leftMargin + rightMargin));
28858
+ const { width: w2, height: h2 } = resizeKeepAspectRatio(size.w, size.h, maxWidthEmu);
28859
+ if (w2 && h2) size = { w: w2, h: h2 };
28860
+ }
28861
+ if (params.node.type === "image" && !imageId) {
28862
+ const path = src?.split("word/")[1];
28863
+ imageId = addNewImageRelationship(params, path);
28864
+ } else if (params.node.type === "fieldAnnotation" && !imageId) {
28865
+ const type2 = src?.split(";")[0].split("/")[1];
28866
+ if (!type2) {
28867
+ return prepareTextAnnotation(params);
28868
+ }
28869
+ const imageUrl = `media/${imageName}_${attrs.hash}.${type2}`;
28870
+ imageId = addNewImageRelationship(params, imageUrl);
28871
+ params.media[`${imageName}_${attrs.hash}.${type2}`] = src;
28872
+ }
28873
+ let inlineAttrs = attrs.originalPadding || {
28874
+ distT: 0,
28875
+ distB: 0,
28876
+ distL: 0,
28877
+ distR: 0
28878
+ };
28879
+ const anchorElements = [];
28880
+ let wrapProp = [];
28881
+ if (attrs.isAnchor) {
28882
+ inlineAttrs = {
28883
+ ...inlineAttrs,
28884
+ simplePos: attrs.originalAttributes?.simplePos,
28885
+ relativeHeight: 1,
28886
+ behindDoc: attrs.originalAttributes?.behindDoc,
28887
+ locked: attrs.originalAttributes?.locked,
28888
+ layoutInCell: attrs.originalAttributes?.layoutInCell,
28889
+ allowOverlap: attrs.originalAttributes?.allowOverlap
28890
+ };
28891
+ if (attrs.simplePos) {
28892
+ anchorElements.push({
28893
+ name: "wp:simplePos",
28894
+ attributes: {
28895
+ x: 0,
28896
+ y: 0
28897
+ }
28898
+ });
28899
+ }
28900
+ if (attrs.anchorData) {
28901
+ anchorElements.push({
28902
+ name: "wp:positionH",
28903
+ attributes: {
28904
+ relativeFrom: attrs.anchorData.hRelativeFrom
28905
+ },
28906
+ ...attrs.marginOffset.left !== void 0 && {
28907
+ elements: [
28908
+ {
28909
+ name: "wp:posOffset",
28910
+ elements: [
28911
+ {
28912
+ type: "text",
28913
+ text: pixelsToEmu(attrs.marginOffset.left).toString()
28914
+ }
28915
+ ]
28916
+ }
28917
+ ]
28918
+ },
28919
+ ...attrs.anchorData.alignH && {
28920
+ elements: [
28921
+ {
28922
+ name: "wp:align",
28923
+ elements: [
28924
+ {
28925
+ type: "text",
28926
+ text: attrs.anchorData.alignH
28927
+ }
28928
+ ]
28929
+ }
28930
+ ]
28931
+ }
28932
+ });
28933
+ anchorElements.push({
28934
+ name: "wp:positionV",
28935
+ attributes: {
28936
+ relativeFrom: attrs.anchorData.vRelativeFrom
28937
+ },
28938
+ ...attrs.marginOffset.top !== void 0 && {
28939
+ elements: [
28940
+ {
28941
+ name: "wp:posOffset",
28942
+ elements: [
28943
+ {
28944
+ type: "text",
28945
+ text: pixelsToEmu(attrs.marginOffset.top).toString()
28946
+ }
28947
+ ]
28948
+ }
28949
+ ]
28950
+ },
28951
+ ...attrs.anchorData.alignV && {
28952
+ elements: [
28953
+ {
28954
+ name: "wp:align",
28955
+ elements: [
28956
+ {
28957
+ type: "text",
28958
+ text: attrs.anchorData.alignV
28959
+ }
28960
+ ]
28961
+ }
28962
+ ]
28963
+ }
28964
+ });
28965
+ }
28966
+ if (attrs.wrapText) {
28967
+ wrapProp.push({
28968
+ name: "wp:wrapSquare",
28969
+ attributes: {
28970
+ wrapText: attrs.wrapText
28971
+ }
28972
+ });
28973
+ }
28974
+ if (attrs.wrapTopAndBottom) {
28975
+ wrapProp.push({
28976
+ name: "wp:wrapTopAndBottom"
28977
+ });
28978
+ }
28979
+ if (attrs.isAnchor && !wrapProp.length) {
28980
+ wrapProp.push({
28981
+ name: "wp:wrapNone"
28982
+ });
28983
+ }
29782
28984
  }
29783
- return markElement;
28985
+ const drawingXmlns = "http://schemas.openxmlformats.org/drawingml/2006/main";
28986
+ const pictureXmlns = "http://schemas.openxmlformats.org/drawingml/2006/picture";
28987
+ const textNode = wrapTextInRun(
28988
+ {
28989
+ name: "w:drawing",
28990
+ elements: [
28991
+ {
28992
+ name: attrs.isAnchor ? "wp:anchor" : "wp:inline",
28993
+ attributes: inlineAttrs,
28994
+ elements: [
28995
+ ...anchorElements,
28996
+ {
28997
+ name: "wp:extent",
28998
+ attributes: {
28999
+ cx: size.w,
29000
+ cy: size.h
29001
+ }
29002
+ },
29003
+ {
29004
+ name: "wp:effectExtent",
29005
+ attributes: {
29006
+ l: 0,
29007
+ t: 0,
29008
+ r: 0,
29009
+ b: 0
29010
+ }
29011
+ },
29012
+ ...wrapProp,
29013
+ {
29014
+ name: "wp:docPr",
29015
+ attributes: {
29016
+ id: attrs.id || 0,
29017
+ name: attrs.alt || `Picture ${imageName}`
29018
+ }
29019
+ },
29020
+ {
29021
+ name: "wp:cNvGraphicFramePr",
29022
+ elements: [
29023
+ {
29024
+ name: "a:graphicFrameLocks",
29025
+ attributes: {
29026
+ "xmlns:a": drawingXmlns,
29027
+ noChangeAspect: 1
29028
+ }
29029
+ }
29030
+ ]
29031
+ },
29032
+ {
29033
+ name: "a:graphic",
29034
+ attributes: { "xmlns:a": drawingXmlns },
29035
+ elements: [
29036
+ {
29037
+ name: "a:graphicData",
29038
+ attributes: { uri: pictureXmlns },
29039
+ elements: [
29040
+ {
29041
+ name: "pic:pic",
29042
+ attributes: { "xmlns:pic": pictureXmlns },
29043
+ elements: [
29044
+ {
29045
+ name: "pic:nvPicPr",
29046
+ elements: [
29047
+ {
29048
+ name: "pic:cNvPr",
29049
+ attributes: {
29050
+ id: attrs.id || 0,
29051
+ name: attrs.title || `Picture ${imageName}`
29052
+ }
29053
+ },
29054
+ {
29055
+ name: "pic:cNvPicPr",
29056
+ elements: [
29057
+ {
29058
+ name: "a:picLocks",
29059
+ attributes: {
29060
+ noChangeAspect: 1,
29061
+ noChangeArrowheads: 1
29062
+ }
29063
+ }
29064
+ ]
29065
+ }
29066
+ ]
29067
+ },
29068
+ {
29069
+ name: "pic:blipFill",
29070
+ elements: [
29071
+ {
29072
+ name: "a:blip",
29073
+ attributes: {
29074
+ "r:embed": imageId
29075
+ }
29076
+ },
29077
+ {
29078
+ name: "a:stretch",
29079
+ elements: [{ name: "a:fillRect" }]
29080
+ }
29081
+ ]
29082
+ },
29083
+ {
29084
+ name: "pic:spPr",
29085
+ attributes: {
29086
+ bwMode: "auto"
29087
+ },
29088
+ elements: [
29089
+ {
29090
+ name: "a:xfrm",
29091
+ elements: [
29092
+ {
29093
+ name: "a:ext",
29094
+ attributes: {
29095
+ cx: size.w,
29096
+ cy: size.h
29097
+ }
29098
+ },
29099
+ {
29100
+ name: "a:off",
29101
+ attributes: {
29102
+ x: 0,
29103
+ y: 0
29104
+ }
29105
+ }
29106
+ ]
29107
+ },
29108
+ {
29109
+ name: "a:prstGeom",
29110
+ attributes: { prst: "rect" },
29111
+ elements: [{ name: "a:avLst" }]
29112
+ },
29113
+ {
29114
+ name: "a:noFill"
29115
+ }
29116
+ ]
29117
+ }
29118
+ ]
29119
+ }
29120
+ ]
29121
+ }
29122
+ ]
29123
+ }
29124
+ ]
29125
+ }
29126
+ ]
29127
+ },
29128
+ []
29129
+ );
29130
+ return textNode;
29784
29131
  }
29785
29132
  function translateShapeContainer(params) {
29786
29133
  const { node } = params;
@@ -29959,6 +29306,14 @@ generateXml_fn = function(node) {
29959
29306
  if (!selfClosing) tags.push(`</${name}>`);
29960
29307
  return tags;
29961
29308
  };
29309
+ function resizeKeepAspectRatio(width, height, maxWidth) {
29310
+ if (width > maxWidth) {
29311
+ let scale = maxWidth / width;
29312
+ let newHeight = Math.round(height * scale);
29313
+ return { width: maxWidth, height: newHeight };
29314
+ }
29315
+ return { width, height };
29316
+ }
29962
29317
  const translatePageNumberNode = (params) => {
29963
29318
  const outputMarks = processOutputMarks(params.node.attrs?.marksAsAttrs || []);
29964
29319
  return getAutoPageJson("PAGE", outputMarks);
@@ -30042,7 +29397,7 @@ const getInitialJSON = (parsedDocx, fallbackXml = defaultInitialXml) => {
30042
29397
  return parsedDocx["word/document.xml"] || parseXmlToJson(fallbackXml);
30043
29398
  };
30044
29399
  const handleDrawingNode = (params) => {
30045
- const { nodes } = params;
29400
+ const { nodes, filename } = params;
30046
29401
  const validNodes = ["w:drawing", "w:p"];
30047
29402
  if (nodes.length === 0 || !validNodes.includes(nodes[0].name)) {
30048
29403
  return { nodes: [], consumed: 0 };
@@ -30052,9 +29407,167 @@ const handleDrawingNode = (params) => {
30052
29407
  if (mainNode.name === "w:drawing") node = mainNode;
30053
29408
  else node = mainNode.elements.find((el) => el.name === "w:drawing");
30054
29409
  if (!node) return { nodes: [], consumed: 0 };
30055
- const schemaNode = translator$1.encode(params);
30056
- const newNodes = schemaNode ? [schemaNode] : [];
30057
- return { nodes: newNodes, consumed: 1 };
29410
+ let result;
29411
+ const { elements } = node;
29412
+ const currentFileName = filename || null;
29413
+ const isAnchor = elements.find((el) => el.name === "wp:anchor");
29414
+ if (isAnchor) {
29415
+ result = handleImageImport(elements[0], currentFileName, params);
29416
+ if (result && result.attrs) result.attrs.isAnchor = isAnchor;
29417
+ }
29418
+ const inlineImage = elements.find((el) => el.name === "wp:inline");
29419
+ if (inlineImage) result = handleImageImport(inlineImage, currentFileName, params);
29420
+ return { nodes: result ? [result] : [], consumed: 1 };
29421
+ };
29422
+ function handleImageImport(node, currentFileName, params) {
29423
+ const { docx } = params;
29424
+ const { attributes } = node;
29425
+ const padding = {
29426
+ top: emuToPixels(attributes["distT"]),
29427
+ bottom: emuToPixels(attributes["distB"]),
29428
+ left: emuToPixels(attributes["distL"]),
29429
+ right: emuToPixels(attributes["distR"])
29430
+ };
29431
+ const extent = node.elements.find((el) => el.name === "wp:extent");
29432
+ const size = {
29433
+ width: emuToPixels(extent.attributes?.cx),
29434
+ height: emuToPixels(extent.attributes?.cy)
29435
+ };
29436
+ const graphic = node.elements.find((el) => el.name === "a:graphic");
29437
+ const graphicData = graphic.elements.find((el) => el.name === "a:graphicData");
29438
+ const { uri: uri2 } = graphicData?.attributes || {};
29439
+ const shapeURI = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
29440
+ if (!!uri2 && uri2 === shapeURI) {
29441
+ return handleShapeDrawing(params, node, graphicData);
29442
+ }
29443
+ const picture = graphicData.elements.find((el) => el.name === "pic:pic");
29444
+ if (!picture || !picture.elements) return null;
29445
+ const blipFill = picture.elements.find((el) => el.name === "pic:blipFill");
29446
+ const blip = blipFill.elements.find((el) => el.name === "a:blip");
29447
+ const positionHTag = node.elements.find((el) => el.name === "wp:positionH");
29448
+ const positionH = positionHTag?.elements.find((el) => el.name === "wp:posOffset");
29449
+ const positionHValue = emuToPixels(positionH?.elements[0]?.text);
29450
+ const hRelativeFrom = positionHTag?.attributes.relativeFrom;
29451
+ const alignH = positionHTag?.elements.find((el) => el.name === "wp:align")?.elements[0]?.text;
29452
+ const positionVTag = node.elements.find((el) => el.name === "wp:positionV");
29453
+ const positionV = positionVTag?.elements?.find((el) => el.name === "wp:posOffset");
29454
+ const positionVValue = emuToPixels(positionV?.elements[0]?.text);
29455
+ const vRelativeFrom = positionVTag?.attributes.relativeFrom;
29456
+ const alignV = positionVTag?.elements?.find((el) => el.name === "wp:align")?.elements[0]?.text;
29457
+ const simplePos = node.elements.find((el) => el.name === "wp:simplePos");
29458
+ const wrapSquare = node.elements.find((el) => el.name === "wp:wrapSquare");
29459
+ const wrapTopAndBottom = node.elements.find((el) => el.name === "wp:wrapTopAndBottom");
29460
+ const docPr = node.elements.find((el) => el.name === "wp:docPr");
29461
+ let anchorData = null;
29462
+ if (hRelativeFrom || alignH || vRelativeFrom || alignV) {
29463
+ anchorData = {
29464
+ hRelativeFrom,
29465
+ vRelativeFrom,
29466
+ alignH,
29467
+ alignV
29468
+ };
29469
+ }
29470
+ const marginOffset = {
29471
+ left: positionHValue,
29472
+ top: positionVValue
29473
+ };
29474
+ const { attributes: blipAttributes = {} } = blip;
29475
+ const rEmbed = blipAttributes["r:embed"];
29476
+ if (!rEmbed) return null;
29477
+ const currentFile = currentFileName || "document.xml";
29478
+ let rels = docx[`word/_rels/${currentFile}.rels`];
29479
+ if (!rels) rels = docx[`word/_rels/document.xml.rels`];
29480
+ const relationships = rels.elements.find((el) => el.name === "Relationships");
29481
+ const { elements } = relationships;
29482
+ const rel = elements.find((el) => el.attributes["Id"] === rEmbed);
29483
+ if (!rel) return null;
29484
+ const { attributes: relAttributes } = rel;
29485
+ const targetPath = relAttributes["Target"];
29486
+ let path = `word/${targetPath}`;
29487
+ if (targetPath.startsWith("/word") || targetPath.startsWith("/media")) path = targetPath.substring(1);
29488
+ const extension = targetPath.substring(targetPath.lastIndexOf(".") + 1);
29489
+ return {
29490
+ type: "image",
29491
+ attrs: {
29492
+ src: path,
29493
+ alt: ["emf", "wmf"].includes(extension) ? "Unable to render EMF/WMF image" : docPr?.attributes.name || "Image",
29494
+ extension,
29495
+ id: docPr?.attributes.id || "",
29496
+ title: docPr?.attributes.descr || "Image",
29497
+ inline: true,
29498
+ padding,
29499
+ marginOffset,
29500
+ size,
29501
+ anchorData,
29502
+ ...simplePos && {
29503
+ simplePos: {
29504
+ x: simplePos.attributes.x,
29505
+ y: simplePos.attributes.y
29506
+ }
29507
+ },
29508
+ ...wrapSquare && {
29509
+ wrapText: wrapSquare.attributes.wrapText
29510
+ },
29511
+ wrapTopAndBottom: !!wrapTopAndBottom,
29512
+ originalPadding: {
29513
+ distT: attributes["distT"],
29514
+ distB: attributes["distB"],
29515
+ distL: attributes["distL"],
29516
+ distR: attributes["distR"]
29517
+ },
29518
+ originalAttributes: node.attributes,
29519
+ rId: relAttributes["Id"]
29520
+ }
29521
+ };
29522
+ }
29523
+ const handleShapeDrawing = (params, node, graphicData) => {
29524
+ const wsp = graphicData.elements.find((el) => el.name === "wps:wsp");
29525
+ const textBox = wsp.elements.find((el) => el.name === "wps:txbx");
29526
+ const textBoxContent = textBox?.elements?.find((el) => el.name === "w:txbxContent");
29527
+ node.elements.find((el) => el.name === "wp:docPr");
29528
+ const spPr = wsp.elements.find((el) => el.name === "wps:spPr");
29529
+ const prstGeom = spPr?.elements.find((el) => el.name === "a:prstGeom");
29530
+ if (!!prstGeom && prstGeom.attributes["prst"] === "rect" && !textBoxContent) {
29531
+ return getRectangleShape(params, spPr);
29532
+ }
29533
+ if (!textBoxContent) {
29534
+ return null;
29535
+ }
29536
+ const { nodeListHandler } = params;
29537
+ const translatedElement = nodeListHandler.handler({
29538
+ ...params,
29539
+ node: textBoxContent.elements[0],
29540
+ nodes: textBoxContent.elements,
29541
+ path: [...params.path || [], textBoxContent]
29542
+ });
29543
+ return translatedElement[0];
29544
+ };
29545
+ const getRectangleShape = (params, node) => {
29546
+ const schemaAttrs = {};
29547
+ const [drawingNode] = params.nodes;
29548
+ if (drawingNode?.name === "w:drawing") {
29549
+ schemaAttrs.drawingContent = drawingNode;
29550
+ }
29551
+ const xfrm = node.elements.find((el) => el.name === "a:xfrm");
29552
+ const start = xfrm.elements.find((el) => el.name === "a:off");
29553
+ const size = xfrm.elements.find((el) => el.name === "a:ext");
29554
+ const solidFill = node.elements.find((el) => el.name === "a:solidFill");
29555
+ node.elements.find((el) => el.name === "a:ln");
29556
+ const rectangleSize = {
29557
+ top: emuToPixels(start.attributes["y"]),
29558
+ left: emuToPixels(start.attributes["x"]),
29559
+ width: emuToPixels(size.attributes["cx"]),
29560
+ height: emuToPixels(size.attributes["cy"])
29561
+ };
29562
+ schemaAttrs.size = rectangleSize;
29563
+ const background = solidFill?.elements[0]?.attributes["val"];
29564
+ if (background) {
29565
+ schemaAttrs.background = "#" + background;
29566
+ }
29567
+ return {
29568
+ type: "contentBlock",
29569
+ attrs: schemaAttrs
29570
+ };
30058
29571
  };
30059
29572
  const drawingNodeHandlerEntity = {
30060
29573
  handlerName: "drawingNodeHandler",
@@ -30154,7 +29667,7 @@ const trackChangeNodeHandlerEntity = {
30154
29667
  handlerName: "trackChangeNodeHandler",
30155
29668
  handler: handleTrackChangeNode
30156
29669
  };
30157
- const hyperlinkNodeHandlerEntity = generateV2HandlerEntity("hyperlinkNodeHandler", translator$4);
29670
+ const hyperlinkNodeHandlerEntity = generateV2HandlerEntity("hyperlinkNodeHandler", translator$1);
30158
29671
  const handleRunNode = (params) => {
30159
29672
  const { nodes, nodeListHandler, parentStyleId, docx } = params;
30160
29673
  if (nodes.length === 0 || nodes[0].name !== "w:r") {
@@ -30266,7 +29779,7 @@ const handleParagraphNode = (params) => {
30266
29779
  if (nodes.length === 0 || nodes[0].name !== "w:p") {
30267
29780
  return { nodes: [], consumed: 0 };
30268
29781
  }
30269
- const schemaNode = translator$R.encode(params);
29782
+ const schemaNode = translator$h.encode(params);
30270
29783
  const newNodes = schemaNode ? [schemaNode] : [];
30271
29784
  return { nodes: newNodes, consumed: 1 };
30272
29785
  };
@@ -30369,7 +29882,7 @@ const handler = (params) => {
30369
29882
  if (nodes.length === 0 || nodes[0].name !== "w:br") {
30370
29883
  return { nodes: [], consumed: 0 };
30371
29884
  }
30372
- const result = translator$T.encode(params);
29885
+ const result = translator$j.encode(params);
30373
29886
  if (!result) return { nodes: [], consumed: 0 };
30374
29887
  return {
30375
29888
  nodes: [result],
@@ -31065,7 +30578,7 @@ const handleTabNode = (params) => {
31065
30578
  if (!nodes.length || nodes[0].name !== "w:tab") {
31066
30579
  return { nodes: [], consumed: 0 };
31067
30580
  }
31068
- const node = translator$S.encode(params);
30581
+ const node = translator$i.encode(params);
31069
30582
  return { nodes: [node], consumed: 1 };
31070
30583
  };
31071
30584
  const tabNodeEntityHandler = {
@@ -31592,7 +31105,7 @@ const _SuperConverter = class _SuperConverter {
31592
31105
  return;
31593
31106
  }
31594
31107
  }
31595
- static updateDocumentVersion(docx = this.convertedXml, version = "0.20.0") {
31108
+ static updateDocumentVersion(docx = this.convertedXml, version = "0.19.0") {
31596
31109
  const customLocation = "docProps/custom.xml";
31597
31110
  if (!docx[customLocation]) {
31598
31111
  docx[customLocation] = generateCustomXml();
@@ -32082,7 +31595,7 @@ function storeSuperdocVersion(docx) {
32082
31595
  function generateCustomXml() {
32083
31596
  return DEFAULT_CUSTOM_XML;
32084
31597
  }
32085
- function generateSuperdocVersion(pid = 2, version = "0.20.0") {
31598
+ function generateSuperdocVersion(pid = 2, version = "0.19.0") {
32086
31599
  return {
32087
31600
  type: "element",
32088
31601
  name: "property",
@@ -32145,12 +31658,15 @@ export {
32145
31658
  createDocFromMarkdown as a7,
32146
31659
  createDocFromHTML as a8,
32147
31660
  EditorState as a9,
32148
- getActiveFormatting as aA,
32149
- readFromClipboard as aB,
32150
- handleClipboardPaste as aC,
32151
- getFileObject as aD,
32152
- _sfc_main as aE,
32153
- registeredHandlers as aF,
31661
+ vClickOutside as aA,
31662
+ getActiveFormatting as aB,
31663
+ readFromClipboard as aC,
31664
+ handleClipboardPaste as aD,
31665
+ getFileObject as aE,
31666
+ translator$h as aF,
31667
+ translator$i as aG,
31668
+ translator$j as aH,
31669
+ _sfc_main as aI,
32154
31670
  hasSomeParentWithClass as aa,
32155
31671
  isActive as ab,
32156
31672
  unflattenListsInHtml as ac,
@@ -32165,18 +31681,18 @@ export {
32165
31681
  parseIndentElement as al,
32166
31682
  combineIndents as am,
32167
31683
  StepMap as an,
32168
- SelectionRange as ao,
32169
- Transform as ap,
32170
- isInTable as aq,
32171
- generateDocxRandomId as ar,
32172
- insertNewRelationship as as,
32173
- updateDOMAttributes as at,
32174
- htmlHandler as au,
32175
- commonjsGlobal as av,
32176
- getDefaultExportFromCjs$1 as aw,
32177
- getContentTypesFromXml as ax,
32178
- xmljs as ay,
32179
- vClickOutside as az,
31684
+ getColStyleDeclaration as ao,
31685
+ SelectionRange as ap,
31686
+ Transform as aq,
31687
+ isInTable as ar,
31688
+ createColGroup as as,
31689
+ generateDocxRandomId as at,
31690
+ insertNewRelationship as au,
31691
+ htmlHandler as av,
31692
+ commonjsGlobal as aw,
31693
+ getDefaultExportFromCjs$1 as ax,
31694
+ getContentTypesFromXml as ay,
31695
+ xmljs as az,
32180
31696
  Slice as b,
32181
31697
  DOMParser$1 as c,
32182
31698
  Mark as d,