@harbour-enterprises/superdoc 0.20.0-next.13 → 0.20.0-next.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/README.md +4 -4
  2. package/dist/chunks/{PdfViewer-Beoed5G0.es.js → PdfViewer-D3gJ5ozH.es.js} +1 -1
  3. package/dist/chunks/{PdfViewer-Dh2tr2ag.cjs → PdfViewer-DuEWa8ox.cjs} +1 -1
  4. package/dist/chunks/{index-BFe2eMYK.cjs → index-D2h9q27o.cjs} +32 -9
  5. package/dist/chunks/{index-OC4NDn1G.es.js → index-DiSIyVKk.es.js} +32 -9
  6. package/dist/chunks/{super-editor.es-cgub83Px.es.js → super-editor.es-4Ig7dBJr.es.js} +2901 -902
  7. package/dist/chunks/{super-editor.es-4ltXjey_.cjs → super-editor.es-lzaBZOn2.cjs} +2901 -902
  8. package/dist/core/SuperDoc.d.ts.map +1 -1
  9. package/dist/stores/comments-store.d.ts.map +1 -1
  10. package/dist/super-editor/ai-writer.es.js +2 -2
  11. package/dist/super-editor/chunks/{converter-CTJIyTAA.js → converter-BJVy6JMW.js} +1996 -657
  12. package/dist/super-editor/chunks/{docx-zipper-BwicJKh2.js → docx-zipper-DWDJGX0b.js} +1 -1
  13. package/dist/super-editor/chunks/{editor-B97u3IuY.js → editor-BUCOmU2Y.js} +1027 -411
  14. package/dist/super-editor/chunks/{toolbar-BcdsHEOP.js → toolbar-CiBIcgiI.js} +2 -2
  15. package/dist/super-editor/converter.es.js +1 -1
  16. package/dist/super-editor/docx-zipper.es.js +2 -2
  17. package/dist/super-editor/editor.es.js +3 -3
  18. package/dist/super-editor/file-zipper.es.js +1 -1
  19. package/dist/super-editor/src/components/toolbar/format-negation.d.ts +5 -0
  20. package/dist/super-editor/src/core/commands/index.d.ts +1 -0
  21. package/dist/super-editor/src/core/commands/toggleMarkCascade.d.ts +42 -0
  22. package/dist/super-editor/src/core/commands/types/index.d.ts +29 -1
  23. package/dist/super-editor/src/core/super-converter/SuperConverter.d.ts +5 -0
  24. package/dist/super-editor/src/core/super-converter/exporter.d.ts +8 -0
  25. package/dist/super-editor/src/core/super-converter/helpers.d.ts +2 -0
  26. package/dist/super-editor/src/core/super-converter/v2/importer/markImporter.d.ts +12 -0
  27. package/dist/super-editor/src/core/super-converter/v2/importer/runNodeImporter.d.ts +6 -6
  28. package/dist/super-editor/src/core/super-converter/v3/handlers/constants/east-asian-regex.d.ts +1 -0
  29. package/dist/super-editor/src/core/super-converter/v3/handlers/constants/index.d.ts +1 -0
  30. package/dist/super-editor/src/core/super-converter/v3/handlers/index.d.ts +2 -12
  31. package/dist/super-editor/src/core/super-converter/v3/handlers/w/b/attributes/index.d.ts +3 -0
  32. package/dist/super-editor/src/core/super-converter/v3/handlers/w/b/attributes/w-val.d.ts +4 -0
  33. package/dist/super-editor/src/core/super-converter/v3/handlers/w/b/b-translator.d.ts +7 -0
  34. package/dist/super-editor/src/core/super-converter/v3/handlers/w/b/index.d.ts +1 -0
  35. package/dist/super-editor/src/core/super-converter/v3/handlers/w/color/attributes/index.d.ts +2 -0
  36. package/dist/super-editor/src/core/super-converter/v3/handlers/w/color/attributes/w-theme-color.d.ts +4 -0
  37. package/dist/super-editor/src/core/super-converter/v3/handlers/w/color/attributes/w-theme-shade.d.ts +4 -0
  38. package/dist/super-editor/src/core/super-converter/v3/handlers/w/color/attributes/w-theme-tint.d.ts +4 -0
  39. package/dist/super-editor/src/core/super-converter/v3/handlers/w/color/attributes/w-val.d.ts +4 -0
  40. package/dist/super-editor/src/core/super-converter/v3/handlers/w/color/color-translator.d.ts +7 -0
  41. package/dist/super-editor/src/core/super-converter/v3/handlers/w/highlight/attributes/index.d.ts +2 -0
  42. package/dist/super-editor/src/core/super-converter/v3/handlers/w/highlight/attributes/w-val.d.ts +4 -0
  43. package/dist/super-editor/src/core/super-converter/v3/handlers/w/highlight/highlight-translator.d.ts +4 -0
  44. package/dist/super-editor/src/core/super-converter/v3/handlers/w/i/attributes/index.d.ts +2 -0
  45. package/dist/super-editor/src/core/super-converter/v3/handlers/w/i/attributes/w-val.d.ts +4 -0
  46. package/dist/super-editor/src/core/super-converter/v3/handlers/w/i/i-translator.d.ts +7 -0
  47. package/dist/super-editor/src/core/super-converter/v3/handlers/w/r/attributes/index.d.ts +2 -0
  48. package/dist/super-editor/src/core/super-converter/v3/handlers/w/r/attributes/w-rsid-del.d.ts +4 -0
  49. package/dist/super-editor/src/core/super-converter/v3/handlers/w/r/attributes/w-rsid-r-pr.d.ts +4 -0
  50. package/dist/super-editor/src/core/super-converter/v3/handlers/w/r/attributes/w-rsid-r.d.ts +4 -0
  51. package/dist/super-editor/src/core/super-converter/v3/handlers/w/r/helpers/helpers.d.ts +40 -0
  52. package/dist/super-editor/src/core/super-converter/v3/handlers/w/r/helpers/index.d.ts +3 -0
  53. package/dist/super-editor/src/core/super-converter/v3/handlers/w/r/helpers/split-run-properties.d.ts +9 -0
  54. package/dist/super-editor/src/core/super-converter/v3/handlers/w/r/helpers/track-change-helpers.d.ts +5 -0
  55. package/dist/super-editor/src/core/super-converter/v3/handlers/w/r/index.d.ts +1 -0
  56. package/dist/super-editor/src/core/super-converter/v3/handlers/w/r/r-translator.d.ts +4 -0
  57. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rFonts/attributes/index.d.ts +2 -0
  58. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rFonts/attributes/w-ascii.d.ts +4 -0
  59. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rFonts/attributes/w-cs.d.ts +4 -0
  60. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rFonts/attributes/w-east-asia.d.ts +4 -0
  61. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rFonts/attributes/w-hansi.d.ts +4 -0
  62. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rFonts/attributes/w-val.d.ts +4 -0
  63. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rFonts/index.d.ts +1 -0
  64. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rFonts/rFonts-translator.d.ts +5 -0
  65. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rStyle/attributes/index.d.ts +2 -0
  66. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rStyle/attributes/w-val.d.ts +4 -0
  67. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rStyle/index.d.ts +1 -0
  68. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rStyle/rstyle-translator.d.ts +7 -0
  69. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rpr/index.d.ts +1 -0
  70. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rpr/rpr-translator.d.ts +5 -0
  71. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rpr/run-property-translators.d.ts +11 -0
  72. package/dist/super-editor/src/core/super-converter/v3/handlers/w/strike/attributes/index.d.ts +2 -0
  73. package/dist/super-editor/src/core/super-converter/v3/handlers/w/strike/attributes/w-val.d.ts +4 -0
  74. package/dist/super-editor/src/core/super-converter/v3/handlers/w/strike/strike-translator.d.ts +7 -0
  75. package/dist/super-editor/src/core/super-converter/v3/handlers/w/sz/attributes/index.d.ts +2 -0
  76. package/dist/super-editor/src/core/super-converter/v3/handlers/w/sz/attributes/w-val.d.ts +4 -0
  77. package/dist/super-editor/src/core/super-converter/v3/handlers/w/sz/sz-translator.d.ts +4 -0
  78. package/dist/super-editor/src/core/super-converter/v3/handlers/w/szcs/attributes/index.d.ts +2 -0
  79. package/dist/super-editor/src/core/super-converter/v3/handlers/w/szcs/attributes/w-val.d.ts +4 -0
  80. package/dist/super-editor/src/core/super-converter/v3/handlers/w/szcs/szcs-translator.d.ts +4 -0
  81. package/dist/super-editor/src/core/super-converter/v3/handlers/w/u/attributes/index.d.ts +2 -0
  82. package/dist/super-editor/src/core/super-converter/v3/handlers/w/u/attributes/w-color.d.ts +4 -0
  83. package/dist/super-editor/src/core/super-converter/v3/handlers/w/u/attributes/w-theme-color.d.ts +4 -0
  84. package/dist/super-editor/src/core/super-converter/v3/handlers/w/u/attributes/w-theme-shade.d.ts +4 -0
  85. package/dist/super-editor/src/core/super-converter/v3/handlers/w/u/attributes/w-theme-tint.d.ts +4 -0
  86. package/dist/super-editor/src/core/super-converter/v3/handlers/w/u/attributes/w-val.d.ts +4 -0
  87. package/dist/super-editor/src/core/super-converter/v3/handlers/w/u/u-translator.d.ts +7 -0
  88. package/dist/super-editor/src/extensions/index.d.ts +2 -2
  89. package/dist/super-editor/src/extensions/linked-styles/index.d.ts +1 -0
  90. package/dist/super-editor/src/extensions/linked-styles/underline-css.d.ts +17 -0
  91. package/dist/super-editor/src/extensions/list-item/helpers/listItemTypography.d.ts +62 -0
  92. package/dist/super-editor/src/extensions/run/commands/index.d.ts +1 -0
  93. package/dist/super-editor/src/extensions/run/commands/split-run.d.ts +1 -0
  94. package/dist/super-editor/src/extensions/run/index.d.ts +1 -0
  95. package/dist/super-editor/src/extensions/run/run.d.ts +6 -0
  96. package/dist/super-editor/src/extensions/shared/cascade-toggle.d.ts +8 -0
  97. package/dist/super-editor/src/extensions/tab/helpers/tabDecorations.d.ts +12 -0
  98. package/dist/super-editor/src/extensions/tab/tab.d.ts +4 -0
  99. package/dist/super-editor/src/tests/helpers/getParagraphText.d.ts +2 -0
  100. package/dist/super-editor/super-editor.es.js +90 -21
  101. package/dist/super-editor/toolbar.es.js +2 -2
  102. package/dist/super-editor.cjs +1 -1
  103. package/dist/super-editor.es.js +1 -1
  104. package/dist/superdoc.cjs +2 -2
  105. package/dist/superdoc.es.js +2 -2
  106. package/dist/superdoc.umd.js +2933 -911
  107. package/dist/superdoc.umd.js.map +1 -1
  108. package/package.json +7 -4
@@ -14888,25 +14888,47 @@ const getContentTypesFromXml = (contentTypesXml) => {
14888
14888
  const defaults = xmlDoc.querySelectorAll("Default");
14889
14889
  return Array.from(defaults).map((item) => item.getAttribute("Extension"));
14890
14890
  };
14891
+ const DOCX_HIGHLIGHT_KEYWORD_MAP = /* @__PURE__ */ new Map([
14892
+ ["yellow", "FFFF00"],
14893
+ ["green", "00FF00"],
14894
+ ["blue", "0000FF"],
14895
+ ["cyan", "00FFFF"],
14896
+ ["magenta", "FF00FF"],
14897
+ ["red", "FF0000"],
14898
+ ["darkYellow", "808000"],
14899
+ ["darkGreen", "008000"],
14900
+ ["darkBlue", "000080"],
14901
+ ["darkCyan", "008080"],
14902
+ ["darkMagenta", "800080"],
14903
+ ["darkGray", "808080"],
14904
+ ["darkRed", "800000"],
14905
+ ["lightGray", "C0C0C0"],
14906
+ ["black", "000000"],
14907
+ ["white", "FFFFFF"]
14908
+ ]);
14909
+ const normalizeHexColor = (hex2) => {
14910
+ if (!hex2) return null;
14911
+ let value = hex2.replace("#", "").trim();
14912
+ if (!value) return null;
14913
+ value = value.toUpperCase();
14914
+ if (value.length === 3)
14915
+ value = value.split("").map((c2) => c2 + c2).join("");
14916
+ if (value.length === 8) value = value.slice(0, 6);
14917
+ return value;
14918
+ };
14891
14919
  const getHexColorFromDocxSystem = (docxColor) => {
14892
- const colorMap = /* @__PURE__ */ new Map([
14893
- ["yellow", "#ffff00"],
14894
- ["green", "#00ff00"],
14895
- ["blue", "#0000FFFF"],
14896
- ["cyan", "#00ffff"],
14897
- ["magenta", "#ff00ff"],
14898
- ["red", "#ff0000"],
14899
- ["darkYellow", "#808000FF"],
14900
- ["darkGreen", "#008000FF"],
14901
- ["darkBlue", "#000080"],
14902
- ["darkCyan", "#008080FF"],
14903
- ["darkMagenta", "#800080FF"],
14904
- ["darkGray", "#808080FF"],
14905
- ["darkRed", "#800000FF"],
14906
- ["lightGray", "#C0C0C0FF"],
14907
- ["black", "#000"]
14908
- ]);
14909
- return colorMap.get(docxColor) || null;
14920
+ const hex2 = DOCX_HIGHLIGHT_KEYWORD_MAP.get(docxColor);
14921
+ return hex2 ? `#${hex2}` : null;
14922
+ };
14923
+ const getDocxHighlightKeywordFromHex = (hexColor) => {
14924
+ if (!hexColor) return null;
14925
+ if (DOCX_HIGHLIGHT_KEYWORD_MAP.has(hexColor)) return hexColor;
14926
+ const normalized = normalizeHexColor(hexColor);
14927
+ if (!normalized) return null;
14928
+ for (const [keyword, hex2] of DOCX_HIGHLIGHT_KEYWORD_MAP.entries()) {
14929
+ if (hex2 === normalized) return keyword;
14930
+ }
14931
+ return null;
14910
14932
  };
14911
14933
  function isValidHexColor(color) {
14912
14934
  if (!color || typeof color !== "string") return false;
@@ -21401,7 +21423,7 @@ function L() {
21401
21423
  return { async: false, breaks: false, extensions: null, gfm: true, hooks: null, pedantic: false, renderer: null, silent: false, tokenizer: null, walkTokens: null };
21402
21424
  }
21403
21425
  var O = L();
21404
- function H(l3) {
21426
+ function G(l3) {
21405
21427
  O = l3;
21406
21428
  }
21407
21429
  var E = { exec: () => null };
@@ -21413,7 +21435,7 @@ function h(l3, e = "") {
21413
21435
  return n;
21414
21436
  }
21415
21437
  var m = { codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm, outputLinkReplace: /\\([\[\]])/g, indentCodeCompensation: /^(\s+)(?:```)/, beginningSpace: /^\s+/, endingHash: /#$/, startingSpaceChar: /^ /, endingSpaceChar: / $/, nonSpaceChar: /[^ ]/, newLineCharGlobal: /\n/g, tabCharGlobal: /\t/g, multipleSpaceGlobal: /\s+/g, blankLine: /^[ \t]*$/, doubleBlankLine: /\n[ \t]*\n[ \t]*$/, blockquoteStart: /^ {0,3}>/, blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g, blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm, listReplaceTabs: /^\t+/, listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g, listIsTask: /^\[[ xX]\] /, listReplaceTask: /^\[[ xX]\] +/, anyLine: /\n.*\n/, hrefBrackets: /^<(.*)>$/, tableDelimiter: /[:|]/, tableAlignChars: /^\||\| *$/g, tableRowBlankLine: /\n[ \t]*$/, tableAlignRight: /^ *-+: *$/, tableAlignCenter: /^ *:-+: *$/, tableAlignLeft: /^ *:-+ *$/, startATag: /^<a /i, endATag: /^<\/a>/i, startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i, endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i, startAngleBracket: /^</, endAngleBracket: />$/, pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/, unicodeAlphaNumeric: /[\p{L}\p{N}]/u, escapeTest: /[&<>"']/, escapeReplace: /[&<>"']/g, escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/, escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g, unescapeTest: /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, caret: /(^|[^\[])\^/g, percentDecode: /%25/g, findPipe: /\|/g, splitPipe: / \|/, slashPipe: /\\\|/g, carriageReturn: /\r\n|\r/g, spaceLine: /^ +$/gm, notSpaceStart: /^\S*/, endingNewline: /\n$/, listItemRegex: (l3) => new RegExp(`^( {0,3}${l3})((?:[ ][^\\n]*)?(?:\\n|$))`), nextBulletRegex: (l3) => new RegExp(`^ {0,${Math.min(3, l3 - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`), hrRegex: (l3) => new RegExp(`^ {0,${Math.min(3, l3 - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`), fencesBeginRegex: (l3) => new RegExp(`^ {0,${Math.min(3, l3 - 1)}}(?:\`\`\`|~~~)`), headingBeginRegex: (l3) => new RegExp(`^ {0,${Math.min(3, l3 - 1)}}#`), htmlBeginRegex: (l3) => new RegExp(`^ {0,${Math.min(3, l3 - 1)}}<(?:[a-z].*>|!--)`, "i") }, xe = /^(?:[ \t]*(?:\n|$))+/, be = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/, Re = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/, C = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/, Oe = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/, j = /(?:[*+-]|\d{1,9}[.)])/, se = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/, ie$2 = 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$1 = { blockquote: $e, code: be, def: ye, fences: Re, heading: Oe, hr: C, html: Se, lheading: ie$2, 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$1, 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$1, 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} *[^
21416
- ]`).replace("lheading", ie$2).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$1, gfm: _e, pedantic: Le }, M = { normal: X, gfm: N, breaks: We, pedantic: Ke };
21438
+ ]`).replace("lheading", ie$2).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$1, gfm: _e, pedantic: Le }, M = { normal: X, gfm: N, breaks: We, pedantic: Ke };
21417
21439
  var Xe = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }, ke = (l3) => Xe[l3];
21418
21440
  function w(l3, e) {
21419
21441
  if (e) {
@@ -21571,15 +21593,15 @@ ${c2}` : c2;
21571
21593
  if (!(t = s.exec(e)) || this.rules.block.hr.test(e)) break;
21572
21594
  p = t[0], e = e.substring(p.length);
21573
21595
  let f = t[2].split(`
21574
- `, 1)[0].replace(this.rules.other.listReplaceTabs, (Z) => " ".repeat(3 * Z.length)), k = e.split(`
21596
+ `, 1)[0].replace(this.rules.other.listReplaceTabs, (H) => " ".repeat(3 * H.length)), k = e.split(`
21575
21597
  `, 1)[0], x = !f.trim(), g = 0;
21576
21598
  if (this.options.pedantic ? (g = 2, c2 = f.trimStart()) : x ? g = t[1].length + 1 : (g = t[2].search(this.rules.other.nonSpaceChar), g = g > 4 ? 1 : g, c2 = f.slice(g), g += t[1].length), x && this.rules.other.blankLine.test(k) && (p += k + `
21577
21599
  `, e = e.substring(k.length + 1), u = true), !u) {
21578
- 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);
21600
+ 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);
21579
21601
  for (; e; ) {
21580
- let G = e.split(`
21602
+ let Z = e.split(`
21581
21603
  `, 1)[0], A;
21582
- 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;
21604
+ 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;
21583
21605
  if (A.search(this.rules.other.nonSpaceChar) >= g || !k.trim()) c2 += `
21584
21606
  ` + A.slice(g);
21585
21607
  else {
@@ -21587,8 +21609,8 @@ ${c2}` : c2;
21587
21609
  c2 += `
21588
21610
  ` + k;
21589
21611
  }
21590
- !x && !k.trim() && (x = true), p += G + `
21591
- `, e = e.substring(G.length + 1), f = A.slice(g);
21612
+ !x && !k.trim() && (x = true), p += Z + `
21613
+ `, e = e.substring(Z.length + 1), f = A.slice(g);
21592
21614
  }
21593
21615
  }
21594
21616
  i.loose || (o ? i.loose = true : this.rules.other.doubleBlankLine.test(p) && (o = true));
@@ -21895,6 +21917,7 @@ var b = class l {
21895
21917
  }
21896
21918
  for (; (r2 = this.tokenizer.rules.inline.anyPunctuation.exec(n)) != null; ) n = n.slice(0, r2.index) + "++" + n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
21897
21919
  for (; (r2 = this.tokenizer.rules.inline.blockSkip.exec(n)) != null; ) n = n.slice(0, r2.index) + "[" + "a".repeat(r2[0].length - 2) + "]" + n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
21920
+ n = this.options.hooks?.emStrongMask?.call({ lexer: this }, n) ?? n;
21898
21921
  let i = false, s = "";
21899
21922
  for (; e; ) {
21900
21923
  i || (s = ""), i = false;
@@ -22089,7 +22112,7 @@ ${e}</tr>
22089
22112
  return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : "escaped" in e && e.escaped ? e.text : w(e.text);
22090
22113
  }
22091
22114
  };
22092
- var S = class {
22115
+ var $ = class {
22093
22116
  strong({ text: e }) {
22094
22117
  return e;
22095
22118
  }
@@ -22123,7 +22146,7 @@ var R = class l2 {
22123
22146
  __publicField$2(this, "options");
22124
22147
  __publicField$2(this, "renderer");
22125
22148
  __publicField$2(this, "textRenderer");
22126
- 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();
22149
+ 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 $();
22127
22150
  }
22128
22151
  static parse(e, t) {
22129
22152
  return new l2(t).parse(e);
@@ -22263,7 +22286,7 @@ var R = class l2 {
22263
22286
  return n;
22264
22287
  }
22265
22288
  };
22266
- var $ = (_a = class {
22289
+ var S = (_a = class {
22267
22290
  constructor(e) {
22268
22291
  __publicField$2(this, "options");
22269
22292
  __publicField$2(this, "block");
@@ -22278,13 +22301,16 @@ var $ = (_a = class {
22278
22301
  processAllTokens(e) {
22279
22302
  return e;
22280
22303
  }
22304
+ emStrongMask(e) {
22305
+ return e;
22306
+ }
22281
22307
  provideLexer() {
22282
22308
  return this.block ? b.lex : b.lexInline;
22283
22309
  }
22284
22310
  provideParser() {
22285
22311
  return this.block ? R.parse : R.parseInline;
22286
22312
  }
22287
- }, __publicField$2(_a, "passThroughHooks", /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens"])), _a);
22313
+ }, __publicField$2(_a, "passThroughHooks", /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens", "emStrongMask"])), __publicField$2(_a, "passThroughHooksRespectAsync", /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens"])), _a);
22288
22314
  var B = class {
22289
22315
  constructor(...e) {
22290
22316
  __publicField$2(this, "defaults", L());
@@ -22293,10 +22319,10 @@ var B = class {
22293
22319
  __publicField$2(this, "parseInline", this.parseMarkdown(false));
22294
22320
  __publicField$2(this, "Parser", R);
22295
22321
  __publicField$2(this, "Renderer", P);
22296
- __publicField$2(this, "TextRenderer", S);
22322
+ __publicField$2(this, "TextRenderer", $);
22297
22323
  __publicField$2(this, "Lexer", b);
22298
22324
  __publicField$2(this, "Tokenizer", y);
22299
- __publicField$2(this, "Hooks", $);
22325
+ __publicField$2(this, "Hooks", S);
22300
22326
  this.use(...e);
22301
22327
  }
22302
22328
  walkTokens(e, t) {
@@ -22369,13 +22395,13 @@ var B = class {
22369
22395
  r2.tokenizer = i;
22370
22396
  }
22371
22397
  if (n.hooks) {
22372
- let i = this.defaults.hooks || new $();
22398
+ let i = this.defaults.hooks || new S();
22373
22399
  for (let s in n.hooks) {
22374
22400
  if (!(s in i)) throw new Error(`hook '${s}' does not exist`);
22375
22401
  if (["options", "block"].includes(s)) continue;
22376
22402
  let o = s, a = n.hooks[o], u = i[o];
22377
- $.passThroughHooks.has(s) ? i[o] = (p) => {
22378
- if (this.defaults.async) return Promise.resolve(a.call(i, p)).then((f) => u.call(i, f));
22403
+ S.passThroughHooks.has(s) ? i[o] = (p) => {
22404
+ if (this.defaults.async && S.passThroughHooksRespectAsync.has(s)) return Promise.resolve(a.call(i, p)).then((f) => u.call(i, f));
22379
22405
  let c2 = a.call(i, p);
22380
22406
  return u.call(i, c2);
22381
22407
  } : i[o] = (...p) => {
@@ -22441,12 +22467,12 @@ function d(l3, e) {
22441
22467
  return _.parse(l3, e);
22442
22468
  }
22443
22469
  d.options = d.setOptions = function(l3) {
22444
- return _.setOptions(l3), d.defaults = _.defaults, H(d.defaults), d;
22470
+ return _.setOptions(l3), d.defaults = _.defaults, G(d.defaults), d;
22445
22471
  };
22446
22472
  d.getDefaults = L;
22447
22473
  d.defaults = O;
22448
22474
  d.use = function(...l3) {
22449
- return _.use(...l3), d.defaults = _.defaults, H(d.defaults), d;
22475
+ return _.use(...l3), d.defaults = _.defaults, G(d.defaults), d;
22450
22476
  };
22451
22477
  d.walkTokens = function(l3, e) {
22452
22478
  return _.walkTokens(l3, e);
@@ -22455,11 +22481,11 @@ d.parseInline = _.parseInline;
22455
22481
  d.Parser = R;
22456
22482
  d.parser = R.parse;
22457
22483
  d.Renderer = P;
22458
- d.TextRenderer = S;
22484
+ d.TextRenderer = $;
22459
22485
  d.Lexer = b;
22460
22486
  d.lexer = b.lex;
22461
22487
  d.Tokenizer = y;
22462
- d.Hooks = $;
22488
+ d.Hooks = S;
22463
22489
  d.parse = d;
22464
22490
  d.options;
22465
22491
  d.setOptions;
@@ -24290,37 +24316,37 @@ const _NodeTranslator = class _NodeTranslator2 {
24290
24316
  };
24291
24317
  __publicField$2(_NodeTranslator, "translatorTypes", TranslatorTypes);
24292
24318
  let NodeTranslator = _NodeTranslator;
24293
- const encode$A = (attributes) => {
24319
+ const encode$17 = (attributes) => {
24294
24320
  return attributes["w:type"];
24295
24321
  };
24296
- const decode$A = (attrs) => {
24322
+ const decode$_ = (attrs) => {
24297
24323
  const { lineBreakType } = attrs;
24298
24324
  return lineBreakType;
24299
24325
  };
24300
- const attrConfig$i = Object.freeze({
24326
+ const attrConfig$F = Object.freeze({
24301
24327
  xmlName: "w:type",
24302
24328
  sdName: "lineBreakType",
24303
- encode: encode$A,
24304
- decode: decode$A
24329
+ encode: encode$17,
24330
+ decode: decode$_
24305
24331
  });
24306
- const encode$z = (attributes) => {
24332
+ const encode$16 = (attributes) => {
24307
24333
  const xmlAttrValue = attributes["w:clear"];
24308
24334
  return xmlAttrValue;
24309
24335
  };
24310
- const decode$z = (attrs) => {
24336
+ const decode$Z = (attrs) => {
24311
24337
  const { clear } = attrs;
24312
24338
  return clear;
24313
24339
  };
24314
- const attrConfig$h = Object.freeze({
24340
+ const attrConfig$E = Object.freeze({
24315
24341
  xmlName: "w:clear",
24316
24342
  sdName: "clear",
24317
- encode: encode$z,
24318
- decode: decode$z
24343
+ encode: encode$16,
24344
+ decode: decode$Z
24319
24345
  });
24320
- const validXmlAttributes$b = [attrConfig$i, attrConfig$h];
24321
- const XML_NODE_NAME$h = "w:br";
24346
+ const validXmlAttributes$l = [attrConfig$F, attrConfig$E];
24347
+ const XML_NODE_NAME$t = "w:br";
24322
24348
  const SD_NODE_NAME$c = "lineBreak";
24323
- const encode$y = (_2, encodedAttrs) => {
24349
+ const encode$15 = (_2, encodedAttrs) => {
24324
24350
  const isPageBreak = encodedAttrs?.lineBreakType === "page";
24325
24351
  const translated = {
24326
24352
  type: isPageBreak ? "hardBreak" : "lineBreak"
@@ -24330,7 +24356,7 @@ const encode$y = (_2, encodedAttrs) => {
24330
24356
  }
24331
24357
  return translated;
24332
24358
  };
24333
- const decode$y = (params2, decodedAttrs) => {
24359
+ const decode$Y = (params2, decodedAttrs) => {
24334
24360
  const { node } = params2;
24335
24361
  if (!node) return;
24336
24362
  const wBreak = { name: "w:br" };
@@ -24347,63 +24373,125 @@ const decode$y = (params2, decodedAttrs) => {
24347
24373
  };
24348
24374
  return translated;
24349
24375
  };
24350
- const config$f = {
24351
- xmlName: XML_NODE_NAME$h,
24376
+ const config$r = {
24377
+ xmlName: XML_NODE_NAME$t,
24352
24378
  sdNodeOrKeyName: SD_NODE_NAME$c,
24353
24379
  type: NodeTranslator.translatorTypes.NODE,
24354
- encode: encode$y,
24355
- decode: decode$y,
24356
- attributes: validXmlAttributes$b
24380
+ encode: encode$15,
24381
+ decode: decode$Y,
24382
+ attributes: validXmlAttributes$l
24383
+ };
24384
+ const translator$15 = NodeTranslator.from(config$r);
24385
+ const encode$14 = (attributes) => attributes?.["w:val"];
24386
+ const decode$X = (attrs) => attrs?.highlight;
24387
+ const attrConfig$D = Object.freeze({
24388
+ xmlName: "w:val",
24389
+ sdName: "highlight",
24390
+ encode: encode$14,
24391
+ decode: decode$X
24392
+ });
24393
+ const validXmlAttributes$k = [attrConfig$D];
24394
+ const XML_NODE_NAME$s = "w:highlight";
24395
+ const SD_ATTR_KEY$f = "highlight";
24396
+ const DISABLED_TOKENS = /* @__PURE__ */ new Set(["transparent", "none", "inherit"]);
24397
+ const encode$13 = (params2, encodedAttrs = {}) => {
24398
+ const { nodes } = params2;
24399
+ const node = nodes?.[0];
24400
+ const value = encodedAttrs.highlight ?? node?.attributes?.["w:val"];
24401
+ return {
24402
+ type: "attr",
24403
+ xmlName: XML_NODE_NAME$s,
24404
+ sdNodeOrKeyName: SD_ATTR_KEY$f,
24405
+ attributes: { "w:val": value ?? null }
24406
+ };
24407
+ };
24408
+ const decode$W = (params2) => {
24409
+ const attrs = params2?.node?.attrs || {};
24410
+ const highlightValue = attrs.highlight ?? attrs.color ?? null;
24411
+ if (!highlightValue) return void 0;
24412
+ const normalizedValue = String(highlightValue).trim().toLowerCase();
24413
+ if (!normalizedValue) return void 0;
24414
+ if (DISABLED_TOKENS.has(normalizedValue)) {
24415
+ return {
24416
+ name: XML_NODE_NAME$s,
24417
+ attributes: { "w:val": "none" }
24418
+ };
24419
+ }
24420
+ const keyword = getDocxHighlightKeywordFromHex(highlightValue);
24421
+ if (keyword) {
24422
+ return {
24423
+ name: XML_NODE_NAME$s,
24424
+ attributes: { "w:val": keyword }
24425
+ };
24426
+ }
24427
+ const fill = normalizeHexColor(highlightValue);
24428
+ if (!fill) return void 0;
24429
+ return {
24430
+ name: "w:shd",
24431
+ attributes: {
24432
+ "w:color": "auto",
24433
+ "w:val": "clear",
24434
+ "w:fill": fill
24435
+ }
24436
+ };
24357
24437
  };
24358
- const translator$V = NodeTranslator.from(config$f);
24359
- const encode$x = (attributes) => {
24438
+ const config$q = {
24439
+ xmlName: XML_NODE_NAME$s,
24440
+ sdNodeOrKeyName: SD_ATTR_KEY$f,
24441
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
24442
+ encode: encode$13,
24443
+ decode: decode$W,
24444
+ attributes: validXmlAttributes$k
24445
+ };
24446
+ const translator$14 = NodeTranslator.from(config$q);
24447
+ const encode$12 = (attributes) => {
24360
24448
  return attributes["w:val"];
24361
24449
  };
24362
- const decode$x = (attrs) => {
24450
+ const decode$V = (attrs) => {
24363
24451
  const { tabSize } = attrs || {};
24364
24452
  return tabSize;
24365
24453
  };
24366
- const attrConfig$g = Object.freeze({
24454
+ const attrConfig$C = Object.freeze({
24367
24455
  xmlName: "w:val",
24368
24456
  sdName: "tabSize",
24369
- encode: encode$x,
24370
- decode: decode$x
24457
+ encode: encode$12,
24458
+ decode: decode$V
24371
24459
  });
24372
- const encode$w = (attributes) => {
24460
+ const encode$11 = (attributes) => {
24373
24461
  return attributes["w:leader"];
24374
24462
  };
24375
- const decode$w = (attrs) => {
24463
+ const decode$U = (attrs) => {
24376
24464
  const { leader } = attrs || {};
24377
24465
  return leader;
24378
24466
  };
24379
- const attrConfig$f = Object.freeze({
24467
+ const attrConfig$B = Object.freeze({
24380
24468
  xmlName: "w:leader",
24381
24469
  sdName: "leader",
24382
- encode: encode$w,
24383
- decode: decode$w
24470
+ encode: encode$11,
24471
+ decode: decode$U
24384
24472
  });
24385
- const encode$v = (attributes) => {
24473
+ const encode$10 = (attributes) => {
24386
24474
  return attributes["w:pos"];
24387
24475
  };
24388
- const decode$v = (attrs) => {
24476
+ const decode$T = (attrs) => {
24389
24477
  const { pos } = attrs || {};
24390
24478
  return pos;
24391
24479
  };
24392
- const attrConfig$e = Object.freeze({
24480
+ const attrConfig$A = Object.freeze({
24393
24481
  xmlName: "w:pos",
24394
24482
  sdName: "pos",
24395
- encode: encode$v,
24396
- decode: decode$v
24483
+ encode: encode$10,
24484
+ decode: decode$T
24397
24485
  });
24398
- const validXmlAttributes$a = [attrConfig$g, attrConfig$e, attrConfig$f];
24399
- const XML_NODE_NAME$g = "w:tab";
24486
+ const validXmlAttributes$j = [attrConfig$C, attrConfig$A, attrConfig$B];
24487
+ const XML_NODE_NAME$r = "w:tab";
24400
24488
  const SD_NODE_NAME$b = "tab";
24401
- const encode$u = (_2, encodedAttrs = {}) => {
24489
+ const encode$$ = (_2, encodedAttrs = {}) => {
24402
24490
  const translated = { type: "tab" };
24403
24491
  if (encodedAttrs) translated.attrs = { ...encodedAttrs };
24404
24492
  return translated;
24405
24493
  };
24406
- const decode$u = (params2, decodedAttrs = {}) => {
24494
+ const decode$S = (params2, decodedAttrs = {}) => {
24407
24495
  const { node } = params2 || {};
24408
24496
  if (!node) return;
24409
24497
  const wTab = { name: "w:tab" };
@@ -24419,15 +24507,15 @@ const decode$u = (params2, decodedAttrs = {}) => {
24419
24507
  }
24420
24508
  return translated;
24421
24509
  };
24422
- const config$e = {
24423
- xmlName: XML_NODE_NAME$g,
24510
+ const config$p = {
24511
+ xmlName: XML_NODE_NAME$r,
24424
24512
  sdNodeOrKeyName: SD_NODE_NAME$b,
24425
24513
  type: NodeTranslator.translatorTypes.NODE,
24426
- encode: encode$u,
24427
- decode: decode$u,
24428
- attributes: validXmlAttributes$a
24514
+ encode: encode$$,
24515
+ decode: decode$S,
24516
+ attributes: validXmlAttributes$j
24429
24517
  };
24430
- const translator$U = NodeTranslator.from(config$e);
24518
+ const translator$13 = NodeTranslator.from(config$p);
24431
24519
  const mergeTextNodes = (nodes) => {
24432
24520
  if (!nodes || !Array.isArray(nodes)) {
24433
24521
  return nodes;
@@ -24602,17 +24690,21 @@ function getMarkValue(markType, attributes, docx) {
24602
24690
  function getFontFamilyValue(attributes, docx) {
24603
24691
  const ascii = attributes["w:ascii"];
24604
24692
  const themeAscii = attributes["w:asciiTheme"];
24605
- if (!docx || !themeAscii) return ascii;
24606
- const theme = docx["word/theme/theme1.xml"];
24607
- if (!theme) return ascii;
24608
- const { elements: topElements } = theme;
24609
- const { elements } = topElements[0];
24610
- const themeElements = elements.find((el) => el.name === "a:themeElements");
24611
- const fontScheme = themeElements.elements.find((el) => el.name === "a:fontScheme");
24612
- const majorFont = fontScheme.elements.find((el) => el.name === "a:majorFont");
24613
- const latin = majorFont.elements.find((el) => el.name === "a:latin");
24614
- const typeface = latin.attributes["typeface"];
24615
- return typeface;
24693
+ let resolved = ascii;
24694
+ if (docx && themeAscii) {
24695
+ const theme = docx["word/theme/theme1.xml"];
24696
+ if (theme?.elements?.length) {
24697
+ const { elements: topElements } = theme;
24698
+ const { elements } = topElements[0] || {};
24699
+ const themeElements = elements?.find((el) => el.name === "a:themeElements");
24700
+ const fontScheme = themeElements?.elements?.find((el) => el.name === "a:fontScheme");
24701
+ const majorFont = fontScheme?.elements?.find((el) => el.name === "a:majorFont");
24702
+ const latin = majorFont?.elements?.find((el) => el.name === "a:latin");
24703
+ resolved = latin?.attributes?.typeface || resolved;
24704
+ }
24705
+ }
24706
+ if (!resolved) return null;
24707
+ return SuperConverter.toCssFontFamily(resolved, docx);
24616
24708
  }
24617
24709
  function getIndentValue(attributes) {
24618
24710
  let value = attributes["w:left"];
@@ -24633,7 +24725,11 @@ function getHighLightValue(attributes) {
24633
24725
  return getHexColorFromDocxSystem(attributes?.["w:val"]) || null;
24634
24726
  }
24635
24727
  function getStrikeValue(attributes) {
24636
- return attributes?.["w:val"] === "1" ? attributes["w:val"] : null;
24728
+ const raw = attributes?.["w:val"];
24729
+ if (raw === void 0 || raw === null) return "1";
24730
+ const value = String(raw).trim().toLowerCase();
24731
+ if (value === "1" || value === "true" || value === "on") return "1";
24732
+ return null;
24637
24733
  }
24638
24734
  const parseParagraphBorders = (pBdr) => {
24639
24735
  if (!pBdr || !pBdr.elements) return {};
@@ -24663,27 +24759,39 @@ const getParagraphIndent = (node, docx, styleId = "") => {
24663
24759
  right: 0,
24664
24760
  firstLine: 0,
24665
24761
  hanging: 0,
24666
- textIndent: 0
24762
+ textIndent: 0,
24763
+ explicitLeft: false,
24764
+ explicitRight: false,
24765
+ explicitFirstLine: false,
24766
+ explicitHanging: false
24667
24767
  };
24668
24768
  const { indent: pDefaultIndent = {} } = getDefaultParagraphStyle(docx, styleId);
24669
24769
  const pPr = node.elements?.find((el) => el.name === "w:pPr");
24670
24770
  const inLineIndentTag = pPr?.elements?.find((el) => el.name === "w:ind");
24671
24771
  const inLineIndent = inLineIndentTag?.attributes || {};
24672
- const leftIndent = inLineIndent?.["w:left"] || pDefaultIndent?.["w:left"];
24673
- const rightIndent = inLineIndent?.["w:right"] || pDefaultIndent?.["w:right"];
24674
- const firstLine = inLineIndent?.["w:firstLine"] || pDefaultIndent?.["w:firstLine"];
24675
- const hanging = inLineIndent?.["w:hanging"] || pDefaultIndent?.["w:hanging"];
24772
+ const inlineLeft = inLineIndent?.["w:left"];
24773
+ const inlineRight = inLineIndent?.["w:right"];
24774
+ const inlineFirstLine = inLineIndent?.["w:firstLine"];
24775
+ const inlineHanging = inLineIndent?.["w:hanging"];
24776
+ const leftIndent = inlineLeft ?? pDefaultIndent?.["w:left"];
24777
+ const rightIndent = inlineRight ?? pDefaultIndent?.["w:right"];
24778
+ const firstLine = inlineFirstLine ?? pDefaultIndent?.["w:firstLine"];
24779
+ const hanging = inlineHanging ?? pDefaultIndent?.["w:hanging"];
24676
24780
  if (leftIndent) {
24677
24781
  indent.left = twipsToPixels(leftIndent);
24782
+ indent.explicitLeft = inlineLeft !== void 0;
24678
24783
  }
24679
24784
  if (rightIndent) {
24680
24785
  indent.right = twipsToPixels(rightIndent);
24786
+ indent.explicitRight = inlineRight !== void 0;
24681
24787
  }
24682
24788
  if (firstLine) {
24683
24789
  indent.firstLine = twipsToPixels(firstLine);
24790
+ indent.explicitFirstLine = inlineFirstLine !== void 0;
24684
24791
  }
24685
24792
  if (hanging) {
24686
24793
  indent.hanging = twipsToPixels(hanging);
24794
+ indent.explicitHanging = inlineHanging !== void 0;
24687
24795
  }
24688
24796
  const textIndentValue = leftIndent - parseInt(hanging || 0) || 0;
24689
24797
  if (textIndentValue) {
@@ -25022,102 +25130,102 @@ const handleParagraphNode$1 = (params2) => {
25022
25130
  }
25023
25131
  return schemaNode;
25024
25132
  };
25025
- const encode$t = (attributes) => {
25133
+ const encode$_ = (attributes) => {
25026
25134
  return attributes["w:rsidDel"];
25027
25135
  };
25028
- const decode$t = (attrs) => {
25136
+ const decode$R = (attrs) => {
25029
25137
  return attrs.rsidDel;
25030
25138
  };
25031
- const attrConfig$d = Object.freeze({
25139
+ const attrConfig$z = Object.freeze({
25032
25140
  xmlName: "w:rsidDel",
25033
25141
  sdName: "rsidDel",
25034
- encode: encode$t,
25035
- decode: decode$t
25142
+ encode: encode$_,
25143
+ decode: decode$R
25036
25144
  });
25037
- const encode$s = (attributes) => {
25145
+ const encode$Z = (attributes) => {
25038
25146
  return attributes["w:rsidP"];
25039
25147
  };
25040
- const decode$s = (attrs) => {
25148
+ const decode$Q = (attrs) => {
25041
25149
  return attrs.rsidP;
25042
25150
  };
25043
- const attrConfig$c = Object.freeze({
25151
+ const attrConfig$y = Object.freeze({
25044
25152
  xmlName: "w:rsidP",
25045
25153
  sdName: "rsidP",
25046
- encode: encode$s,
25047
- decode: decode$s
25154
+ encode: encode$Z,
25155
+ decode: decode$Q
25048
25156
  });
25049
- const encode$r = (attributes) => {
25157
+ const encode$Y = (attributes) => {
25050
25158
  return attributes["w:rsidR"];
25051
25159
  };
25052
- const decode$r = (attrs) => {
25160
+ const decode$P = (attrs) => {
25053
25161
  return attrs.rsidR;
25054
25162
  };
25055
- const attrConfig$b = Object.freeze({
25163
+ const attrConfig$x = Object.freeze({
25056
25164
  xmlName: "w:rsidR",
25057
25165
  sdName: "rsidR",
25058
- encode: encode$r,
25059
- decode: decode$r
25166
+ encode: encode$Y,
25167
+ decode: decode$P
25060
25168
  });
25061
- const encode$q = (attributes) => {
25169
+ const encode$X = (attributes) => {
25062
25170
  return attributes["w:rsidRPr"];
25063
25171
  };
25064
- const decode$q = (attrs) => {
25172
+ const decode$O = (attrs) => {
25065
25173
  return attrs.rsidRPr;
25066
25174
  };
25067
- const attrConfig$a = Object.freeze({
25175
+ const attrConfig$w = Object.freeze({
25068
25176
  xmlName: "w:rsidRPr",
25069
25177
  sdName: "rsidRPr",
25070
- encode: encode$q,
25071
- decode: decode$q
25178
+ encode: encode$X,
25179
+ decode: decode$O
25072
25180
  });
25073
- const encode$p = (attributes) => {
25181
+ const encode$W = (attributes) => {
25074
25182
  return attributes["w:rsidRDefault"];
25075
25183
  };
25076
- const decode$p = (attrs) => {
25184
+ const decode$N = (attrs) => {
25077
25185
  return attrs.rsidRDefault;
25078
25186
  };
25079
- const attrConfig$9 = Object.freeze({
25187
+ const attrConfig$v = Object.freeze({
25080
25188
  xmlName: "w:rsidRDefault",
25081
25189
  sdName: "rsidRDefault",
25082
- encode: encode$p,
25083
- decode: decode$p
25190
+ encode: encode$W,
25191
+ decode: decode$N
25084
25192
  });
25085
- const encode$o = (attributes) => {
25193
+ const encode$V = (attributes) => {
25086
25194
  return attributes["w14:paraId"];
25087
25195
  };
25088
- const decode$o = (attrs) => {
25196
+ const decode$M = (attrs) => {
25089
25197
  return attrs.paraId;
25090
25198
  };
25091
- const attrConfig$8 = Object.freeze({
25199
+ const attrConfig$u = Object.freeze({
25092
25200
  xmlName: "w14:paraId",
25093
25201
  sdName: "paraId",
25094
- encode: encode$o,
25095
- decode: decode$o
25202
+ encode: encode$V,
25203
+ decode: decode$M
25096
25204
  });
25097
- const encode$n = (attributes) => {
25205
+ const encode$U = (attributes) => {
25098
25206
  return attributes["w14:textId"];
25099
25207
  };
25100
- const decode$n = (attrs) => {
25208
+ const decode$L = (attrs) => {
25101
25209
  return attrs.textId;
25102
25210
  };
25103
- const attrConfig$7 = Object.freeze({
25211
+ const attrConfig$t = Object.freeze({
25104
25212
  xmlName: "w14:textId",
25105
25213
  sdName: "textId",
25106
- encode: encode$n,
25107
- decode: decode$n
25214
+ encode: encode$U,
25215
+ decode: decode$L
25108
25216
  });
25109
- const validXmlAttributes$9 = [
25110
- attrConfig$8,
25111
- attrConfig$7,
25112
- attrConfig$b,
25113
- attrConfig$9,
25114
- attrConfig$c,
25115
- attrConfig$a,
25116
- attrConfig$d
25217
+ const validXmlAttributes$i = [
25218
+ attrConfig$u,
25219
+ attrConfig$t,
25220
+ attrConfig$x,
25221
+ attrConfig$v,
25222
+ attrConfig$y,
25223
+ attrConfig$w,
25224
+ attrConfig$z
25117
25225
  ];
25118
- const XML_NODE_NAME$f = "w:p";
25226
+ const XML_NODE_NAME$q = "w:p";
25119
25227
  const SD_NODE_NAME$a = "paragraph";
25120
- const encode$m = (params2, encodedAttrs = {}) => {
25228
+ const encode$T = (params2, encodedAttrs = {}) => {
25121
25229
  const node = handleParagraphNode$1(params2);
25122
25230
  if (!node) return void 0;
25123
25231
  if (encodedAttrs && Object.keys(encodedAttrs).length) {
@@ -25125,7 +25233,7 @@ const encode$m = (params2, encodedAttrs = {}) => {
25125
25233
  }
25126
25234
  return node;
25127
25235
  };
25128
- const decode$m = (params2, decodedAttrs = {}) => {
25236
+ const decode$K = (params2, decodedAttrs = {}) => {
25129
25237
  const translated = translateParagraphNode(params2);
25130
25238
  if (!translated) return void 0;
25131
25239
  if (decodedAttrs && Object.keys(decodedAttrs).length) {
@@ -25133,9 +25241,1164 @@ const decode$m = (params2, decodedAttrs = {}) => {
25133
25241
  }
25134
25242
  return translated;
25135
25243
  };
25244
+ const config$o = {
25245
+ xmlName: XML_NODE_NAME$q,
25246
+ sdNodeOrKeyName: SD_NODE_NAME$a,
25247
+ type: NodeTranslator.translatorTypes.NODE,
25248
+ encode: encode$T,
25249
+ decode: decode$K,
25250
+ attributes: validXmlAttributes$i
25251
+ };
25252
+ const translator$12 = NodeTranslator.from(config$o);
25253
+ const encode$S = (attributes) => {
25254
+ const raw = attributes?.["w:val"];
25255
+ if (raw === void 0 || raw === null) return void 0;
25256
+ if (typeof raw === "boolean") return raw;
25257
+ if (typeof raw === "number") return raw !== 0;
25258
+ const val = String(raw).trim().toLowerCase();
25259
+ if (val === "0" || val === "false" || val === "off") return false;
25260
+ if (val === "1" || val === "true" || val === "on") return true;
25261
+ return void 0;
25262
+ };
25263
+ const decode$J = (runProps) => {
25264
+ if (runProps?.bold === false) return "0";
25265
+ return void 0;
25266
+ };
25267
+ const attrConfig$s = Object.freeze({
25268
+ xmlName: "w:val",
25269
+ sdName: "bold",
25270
+ encode: encode$S,
25271
+ decode: decode$J
25272
+ });
25273
+ const validXmlAttributes$h = [attrConfig$s];
25274
+ const XML_NODE_NAME$p = "w:b";
25275
+ const SD_ATTR_KEY$e = "bold";
25276
+ const encode$R = (params2, encodedAttrs = {}) => {
25277
+ const { nodes } = params2;
25278
+ const node = nodes[0];
25279
+ if (!node) return void 0;
25280
+ const val = encodedAttrs?.[SD_ATTR_KEY$e];
25281
+ let attributes;
25282
+ if (val === false) attributes = { "w:val": "0" };
25283
+ else if (val === true)
25284
+ attributes = {};
25285
+ else attributes = node.attributes || {};
25286
+ return {
25287
+ type: "attr",
25288
+ xmlName: XML_NODE_NAME$p,
25289
+ sdNodeOrKeyName: SD_ATTR_KEY$e,
25290
+ attributes
25291
+ };
25292
+ };
25293
+ const config$n = {
25294
+ xmlName: XML_NODE_NAME$p,
25295
+ sdNodeOrKeyName: SD_ATTR_KEY$e,
25296
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
25297
+ encode: encode$R,
25298
+ attributes: validXmlAttributes$h
25299
+ };
25300
+ const translator$11 = NodeTranslator.from(config$n);
25301
+ const XML_NODE_NAME$o = "w:i";
25302
+ const SD_ATTR_KEY$d = "italic";
25303
+ const encode$Q = (params2) => {
25304
+ const { nodes } = params2;
25305
+ const node = nodes?.[0];
25306
+ if (!node) return void 0;
25307
+ return {
25308
+ type: "attr",
25309
+ xmlName: XML_NODE_NAME$o,
25310
+ sdNodeOrKeyName: SD_ATTR_KEY$d,
25311
+ attributes: {
25312
+ "w:val": node.attributes?.["w:val"] ?? null
25313
+ }
25314
+ };
25315
+ };
25316
+ const config$m = {
25317
+ xmlName: XML_NODE_NAME$o,
25318
+ sdNodeOrKeyName: SD_ATTR_KEY$d,
25319
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
25320
+ encode: encode$Q
25321
+ };
25322
+ const translator$10 = NodeTranslator.from(config$m);
25323
+ const encode$P = (attributes) => attributes?.["w:val"];
25324
+ const decode$I = (attrs) => attrs?.underline;
25325
+ const attrConfig$r = Object.freeze({
25326
+ xmlName: "w:val",
25327
+ sdName: "underline",
25328
+ encode: encode$P,
25329
+ decode: decode$I
25330
+ });
25331
+ const encode$O = (attributes) => attributes?.["w:color"];
25332
+ const decode$H = (attrs) => attrs?.color;
25333
+ const attrConfig$q = Object.freeze({
25334
+ xmlName: "w:color",
25335
+ sdName: "color",
25336
+ encode: encode$O,
25337
+ decode: decode$H
25338
+ });
25339
+ const encode$N = (attributes) => attributes?.["w:themeColor"];
25340
+ const decode$G = (attrs) => attrs?.themeColor;
25341
+ const attrConfig$p = Object.freeze({
25342
+ xmlName: "w:themeColor",
25343
+ sdName: "themeColor",
25344
+ encode: encode$N,
25345
+ decode: decode$G
25346
+ });
25347
+ const encode$M = (attributes) => attributes?.["w:themeTint"];
25348
+ const decode$F = (attrs) => attrs?.themeTint;
25349
+ const attrConfig$o = Object.freeze({
25350
+ xmlName: "w:themeTint",
25351
+ sdName: "themeTint",
25352
+ encode: encode$M,
25353
+ decode: decode$F
25354
+ });
25355
+ const encode$L = (attributes) => attributes?.["w:themeShade"];
25356
+ const decode$E = (attrs) => attrs?.themeShade;
25357
+ const attrConfig$n = Object.freeze({
25358
+ xmlName: "w:themeShade",
25359
+ sdName: "themeShade",
25360
+ encode: encode$L,
25361
+ decode: decode$E
25362
+ });
25363
+ const validXmlAttributes$g = [attrConfig$r, attrConfig$q, attrConfig$p, attrConfig$o, attrConfig$n];
25364
+ const XML_NODE_NAME$n = "w:u";
25365
+ const SD_ATTR_KEY$c = "underline";
25366
+ const encode$K = (params2, encodedAttrs = {}) => {
25367
+ const { nodes } = params2;
25368
+ const node = nodes?.[0];
25369
+ const sourceAttrs = node?.attributes || {};
25370
+ const underlineType = encodedAttrs.underline ?? sourceAttrs["w:val"];
25371
+ const color = encodedAttrs.color ?? sourceAttrs["w:color"];
25372
+ const themeColor = encodedAttrs.themeColor ?? sourceAttrs["w:themeColor"];
25373
+ const themeTint = encodedAttrs.themeTint ?? sourceAttrs["w:themeTint"];
25374
+ const themeShade = encodedAttrs.themeShade ?? sourceAttrs["w:themeShade"];
25375
+ const attributes = { "w:val": underlineType ?? null };
25376
+ if (color !== void 0 && color !== null) attributes["w:color"] = color;
25377
+ if (themeColor !== void 0 && themeColor !== null) attributes["w:themeColor"] = themeColor;
25378
+ if (themeTint !== void 0 && themeTint !== null) attributes["w:themeTint"] = themeTint;
25379
+ if (themeShade !== void 0 && themeShade !== null) attributes["w:themeShade"] = themeShade;
25380
+ return {
25381
+ type: "attr",
25382
+ xmlName: XML_NODE_NAME$n,
25383
+ sdNodeOrKeyName: SD_ATTR_KEY$c,
25384
+ attributes
25385
+ };
25386
+ };
25387
+ const decode$D = (params2) => {
25388
+ const attrs = params2?.node?.attrs || {};
25389
+ const underlineType = attrs.underlineType ?? attrs.underline ?? null;
25390
+ const color = attrs.underlineColor ?? attrs.color ?? null;
25391
+ const themeColor = attrs.underlineThemeColor ?? attrs.themeColor ?? null;
25392
+ const themeTint = attrs.underlineThemeTint ?? attrs.themeTint ?? null;
25393
+ const themeShade = attrs.underlineThemeShade ?? attrs.themeShade ?? null;
25394
+ if (!underlineType && !color && !themeColor && !themeTint && !themeShade) return void 0;
25395
+ const attributes = {};
25396
+ if (underlineType) attributes["w:val"] = underlineType;
25397
+ if (color) {
25398
+ const normalized = normalizeHexColor(color);
25399
+ if (normalized) attributes["w:color"] = normalized;
25400
+ }
25401
+ if (themeColor) attributes["w:themeColor"] = themeColor;
25402
+ if (themeTint) attributes["w:themeTint"] = themeTint;
25403
+ if (themeShade) attributes["w:themeShade"] = themeShade;
25404
+ return {
25405
+ name: XML_NODE_NAME$n,
25406
+ attributes
25407
+ };
25408
+ };
25409
+ const config$l = {
25410
+ xmlName: XML_NODE_NAME$n,
25411
+ sdNodeOrKeyName: SD_ATTR_KEY$c,
25412
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
25413
+ encode: encode$K,
25414
+ decode: decode$D,
25415
+ attributes: validXmlAttributes$g
25416
+ };
25417
+ const translator$$ = NodeTranslator.from(config$l);
25418
+ const encode$J = (attributes) => {
25419
+ const raw = attributes?.["w:val"];
25420
+ if (raw === void 0 || raw === null) return void 0;
25421
+ if (typeof raw === "boolean") return raw;
25422
+ if (typeof raw === "number") return raw !== 0;
25423
+ const val = String(raw).trim().toLowerCase();
25424
+ if (val === "0" || val === "false" || val === "off") return false;
25425
+ if (val === "1" || val === "true" || val === "on") return true;
25426
+ return void 0;
25427
+ };
25428
+ const decode$C = (attrs) => {
25429
+ if (attrs?.strike === false) return "0";
25430
+ return void 0;
25431
+ };
25432
+ const attrConfig$m = Object.freeze({
25433
+ xmlName: "w:val",
25434
+ sdName: "strike",
25435
+ encode: encode$J,
25436
+ decode: decode$C
25437
+ });
25438
+ const validXmlAttributes$f = [attrConfig$m];
25439
+ const XML_NODE_NAME$m = "w:strike";
25440
+ const SD_ATTR_KEY$b = "strike";
25441
+ const encode$I = (params2, encodedAttrs = {}) => {
25442
+ const { nodes } = params2;
25443
+ const node = nodes?.[0];
25444
+ if (!node) return void 0;
25445
+ const val = encodedAttrs?.[SD_ATTR_KEY$b];
25446
+ let attributes;
25447
+ if (val === false) attributes = { "w:val": "0" };
25448
+ else if (val === true) attributes = {};
25449
+ else attributes = { ...node.attributes || {} };
25450
+ if (attributes["w:val"] === void 0 && val !== true) attributes["w:val"] = null;
25451
+ else if (val === true && attributes["w:val"] === void 0) delete attributes["w:val"];
25452
+ return {
25453
+ type: "attr",
25454
+ xmlName: XML_NODE_NAME$m,
25455
+ sdNodeOrKeyName: SD_ATTR_KEY$b,
25456
+ attributes
25457
+ };
25458
+ };
25459
+ const config$k = {
25460
+ xmlName: XML_NODE_NAME$m,
25461
+ sdNodeOrKeyName: SD_ATTR_KEY$b,
25462
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
25463
+ encode: encode$I,
25464
+ attributes: validXmlAttributes$f
25465
+ };
25466
+ const translator$_ = NodeTranslator.from(config$k);
25467
+ const encode$H = (attributes) => attributes?.["w:val"];
25468
+ const decode$B = (attrs) => attrs?.color;
25469
+ const attrConfig$l = Object.freeze({
25470
+ xmlName: "w:val",
25471
+ sdName: "color",
25472
+ encode: encode$H,
25473
+ decode: decode$B
25474
+ });
25475
+ const encode$G = (attributes) => attributes?.["w:themeColor"];
25476
+ const decode$A = (attrs) => attrs?.themeColor;
25477
+ const attrConfig$k = Object.freeze({
25478
+ xmlName: "w:themeColor",
25479
+ sdName: "themeColor",
25480
+ encode: encode$G,
25481
+ decode: decode$A
25482
+ });
25483
+ const encode$F = (attributes) => attributes?.["w:themeTint"];
25484
+ const decode$z = (attrs) => attrs?.themeTint;
25485
+ const attrConfig$j = Object.freeze({
25486
+ xmlName: "w:themeTint",
25487
+ sdName: "themeTint",
25488
+ encode: encode$F,
25489
+ decode: decode$z
25490
+ });
25491
+ const encode$E = (attributes) => attributes?.["w:themeShade"];
25492
+ const decode$y = (attrs) => attrs?.themeShade;
25493
+ const attrConfig$i = Object.freeze({
25494
+ xmlName: "w:themeShade",
25495
+ sdName: "themeShade",
25496
+ encode: encode$E,
25497
+ decode: decode$y
25498
+ });
25499
+ const validXmlAttributes$e = [attrConfig$l, attrConfig$k, attrConfig$j, attrConfig$i];
25500
+ const XML_NODE_NAME$l = "w:color";
25501
+ const SD_ATTR_KEY$a = "color";
25502
+ const encode$D = (params2, encodedAttrs = {}) => {
25503
+ const { nodes } = params2;
25504
+ const node = nodes?.[0];
25505
+ const sourceAttrs = node?.attributes || {};
25506
+ const value = encodedAttrs.color ?? sourceAttrs["w:val"];
25507
+ const themeColor = encodedAttrs.themeColor ?? sourceAttrs["w:themeColor"];
25508
+ const themeTint = encodedAttrs.themeTint ?? sourceAttrs["w:themeTint"];
25509
+ const themeShade = encodedAttrs.themeShade ?? sourceAttrs["w:themeShade"];
25510
+ const attributes = {};
25511
+ attributes["w:val"] = value ?? null;
25512
+ if (themeColor !== void 0 && themeColor !== null) attributes["w:themeColor"] = themeColor;
25513
+ if (themeTint !== void 0 && themeTint !== null) attributes["w:themeTint"] = themeTint;
25514
+ if (themeShade !== void 0 && themeShade !== null) attributes["w:themeShade"] = themeShade;
25515
+ return {
25516
+ type: "attr",
25517
+ xmlName: XML_NODE_NAME$l,
25518
+ sdNodeOrKeyName: SD_ATTR_KEY$a,
25519
+ attributes
25520
+ };
25521
+ };
25522
+ const config$j = {
25523
+ xmlName: XML_NODE_NAME$l,
25524
+ sdNodeOrKeyName: SD_ATTR_KEY$a,
25525
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
25526
+ encode: encode$D,
25527
+ attributes: validXmlAttributes$e
25528
+ };
25529
+ const translator$Z = NodeTranslator.from(config$j);
25530
+ const encode$C = (attributes) => attributes?.["w:eastAsia"];
25531
+ const decode$x = (attrs) => attrs?.eastAsia;
25532
+ const attrConfig$h = Object.freeze({
25533
+ xmlName: "w:eastAsia",
25534
+ sdName: "eastAsia",
25535
+ encode: encode$C,
25536
+ decode: decode$x
25537
+ });
25538
+ const encode$B = (attributes) => attributes?.["w:ascii"];
25539
+ const decode$w = (attrs) => attrs?.ascii;
25540
+ const attrConfig$g = Object.freeze({
25541
+ xmlName: "w:ascii",
25542
+ sdName: "ascii",
25543
+ encode: encode$B,
25544
+ decode: decode$w
25545
+ });
25546
+ const encode$A = (attributes) => attributes?.["w:hAnsi"];
25547
+ const decode$v = (attrs) => attrs?.hAnsi;
25548
+ const attrConfig$f = Object.freeze({
25549
+ xmlName: "w:hAnsi",
25550
+ sdName: "hAnsi",
25551
+ encode: encode$A,
25552
+ decode: decode$v
25553
+ });
25554
+ const encode$z = (attributes) => attributes?.["w:cs"];
25555
+ const decode$u = (attrs) => attrs?.cs;
25556
+ const attrConfig$e = Object.freeze({
25557
+ xmlName: "w:cs",
25558
+ sdName: "cs",
25559
+ encode: encode$z,
25560
+ decode: decode$u
25561
+ });
25562
+ const encode$y = (attributes) => attributes?.["w:val"];
25563
+ const decode$t = (attrs) => attrs?.value;
25564
+ const attrConfig$d = Object.freeze({
25565
+ xmlName: "w:val",
25566
+ sdName: "value",
25567
+ encode: encode$y,
25568
+ decode: decode$t
25569
+ });
25570
+ const validXmlAttributes$d = [attrConfig$h, attrConfig$g, attrConfig$f, attrConfig$e, attrConfig$d];
25571
+ const XML_NODE_NAME$k = "w:rFonts";
25572
+ const SD_ATTR_KEY$9 = "fontFamily";
25573
+ const encode$x = (params2, encodedAttrs = {}) => {
25574
+ const { nodes } = params2;
25575
+ const node = nodes?.[0];
25576
+ const sourceAttrs = node?.attributes || {};
25577
+ const attributes = {};
25578
+ const setAttr = (xmlName, sdName) => {
25579
+ if (encodedAttrs[sdName] !== void 0 && encodedAttrs[sdName] !== null) {
25580
+ attributes[xmlName] = encodedAttrs[sdName];
25581
+ } else if (sourceAttrs[xmlName] !== void 0) {
25582
+ attributes[xmlName] = sourceAttrs[xmlName];
25583
+ }
25584
+ };
25585
+ setAttr("w:eastAsia", "eastAsia");
25586
+ setAttr("w:ascii", "ascii");
25587
+ setAttr("w:hAnsi", "hAnsi");
25588
+ setAttr("w:cs", "cs");
25589
+ setAttr("w:val", "value");
25590
+ Object.keys(sourceAttrs).forEach((key2) => {
25591
+ if (attributes[key2] === void 0) attributes[key2] = sourceAttrs[key2];
25592
+ });
25593
+ if (attributes["w:val"] === void 0 && attributes["w:eastAsia"]) {
25594
+ attributes["w:val"] = attributes["w:eastAsia"];
25595
+ }
25596
+ if (attributes["w:val"] === void 0) delete attributes["w:val"];
25597
+ return {
25598
+ type: "attr",
25599
+ xmlName: XML_NODE_NAME$k,
25600
+ sdNodeOrKeyName: SD_ATTR_KEY$9,
25601
+ attributes
25602
+ };
25603
+ };
25604
+ const config$i = {
25605
+ xmlName: XML_NODE_NAME$k,
25606
+ sdNodeOrKeyName: SD_ATTR_KEY$9,
25607
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
25608
+ encode: encode$x,
25609
+ attributes: validXmlAttributes$d
25610
+ };
25611
+ const translator$Y = NodeTranslator.from(config$i);
25612
+ const encode$w = (attributes) => attributes?.["w:val"];
25613
+ const decode$s = (attrs) => attrs?.styleId;
25614
+ const attrConfig$c = Object.freeze({
25615
+ xmlName: "w:val",
25616
+ sdName: "styleId",
25617
+ encode: encode$w,
25618
+ decode: decode$s
25619
+ });
25620
+ const validXmlAttributes$c = [attrConfig$c];
25621
+ const XML_NODE_NAME$j = "w:rStyle";
25622
+ const SD_ATTR_KEY$8 = "styleId";
25623
+ const encode$v = (params2, encodedAttrs = {}) => {
25624
+ const { nodes } = params2;
25625
+ const node = nodes?.[0];
25626
+ const value = encodedAttrs.styleId ?? node?.attributes?.["w:val"];
25627
+ return {
25628
+ type: "attr",
25629
+ xmlName: XML_NODE_NAME$j,
25630
+ sdNodeOrKeyName: SD_ATTR_KEY$8,
25631
+ attributes: { "w:val": value ?? null }
25632
+ };
25633
+ };
25634
+ const config$h = {
25635
+ xmlName: XML_NODE_NAME$j,
25636
+ sdNodeOrKeyName: SD_ATTR_KEY$8,
25637
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
25638
+ encode: encode$v,
25639
+ attributes: validXmlAttributes$c
25640
+ };
25641
+ const translator$X = NodeTranslator.from(config$h);
25642
+ const encode$u = (attributes) => attributes?.["w:val"];
25643
+ const decode$r = (attrs) => attrs?.fontSize;
25644
+ const attrConfig$b = Object.freeze({
25645
+ xmlName: "w:val",
25646
+ sdName: "fontSize",
25647
+ encode: encode$u,
25648
+ decode: decode$r
25649
+ });
25650
+ const validXmlAttributes$b = [attrConfig$b];
25651
+ const XML_NODE_NAME$i = "w:sz";
25652
+ const SD_ATTR_KEY$7 = "fontSize";
25653
+ const encode$t = (params2, encodedAttrs = {}) => {
25654
+ const { nodes } = params2;
25655
+ const node = nodes?.[0];
25656
+ const value = encodedAttrs.fontSize ?? node?.attributes?.["w:val"];
25657
+ return {
25658
+ type: "attr",
25659
+ xmlName: XML_NODE_NAME$i,
25660
+ sdNodeOrKeyName: SD_ATTR_KEY$7,
25661
+ attributes: { "w:val": value ?? null }
25662
+ };
25663
+ };
25664
+ const config$g = {
25665
+ xmlName: XML_NODE_NAME$i,
25666
+ sdNodeOrKeyName: SD_ATTR_KEY$7,
25667
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
25668
+ encode: encode$t,
25669
+ attributes: validXmlAttributes$b
25670
+ };
25671
+ const translator$W = NodeTranslator.from(config$g);
25672
+ const encode$s = (attributes) => attributes?.["w:val"];
25673
+ const decode$q = (attrs) => attrs?.fontSizeCs;
25674
+ const attrConfig$a = Object.freeze({
25675
+ xmlName: "w:val",
25676
+ sdName: "fontSizeCs",
25677
+ encode: encode$s,
25678
+ decode: decode$q
25679
+ });
25680
+ const validXmlAttributes$a = [attrConfig$a];
25681
+ const XML_NODE_NAME$h = "w:szCs";
25682
+ const SD_ATTR_KEY$6 = "fontSizeCs";
25683
+ const encode$r = (params2, encodedAttrs = {}) => {
25684
+ const { nodes } = params2;
25685
+ const node = nodes?.[0];
25686
+ const value = encodedAttrs.fontSizeCs ?? node?.attributes?.["w:val"];
25687
+ return {
25688
+ type: "attr",
25689
+ xmlName: XML_NODE_NAME$h,
25690
+ sdNodeOrKeyName: SD_ATTR_KEY$6,
25691
+ attributes: { "w:val": value ?? null }
25692
+ };
25693
+ };
25694
+ const config$f = {
25695
+ xmlName: XML_NODE_NAME$h,
25696
+ sdNodeOrKeyName: SD_ATTR_KEY$6,
25697
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
25698
+ encode: encode$r,
25699
+ attributes: validXmlAttributes$a
25700
+ };
25701
+ const translator$V = NodeTranslator.from(config$f);
25702
+ const runPropertyTranslators = Object.freeze({
25703
+ "w:b": translator$11,
25704
+ "w:i": translator$10,
25705
+ "w:u": translator$$,
25706
+ "w:strike": translator$_,
25707
+ "w:color": translator$Z,
25708
+ "w:highlight": translator$14,
25709
+ "w:rFonts": translator$Y,
25710
+ "w:rStyle": translator$X,
25711
+ "w:sz": translator$W,
25712
+ "w:szCs": translator$V
25713
+ });
25714
+ const rawRunPropertyXmlNames = Object.freeze(["w:lang", "w:shd"]);
25715
+ const RAW_CHILD_NAME_SET = new Set(rawRunPropertyXmlNames);
25716
+ const KNOWN_CHILD_XML_NAMES = /* @__PURE__ */ new Set([...Object.keys(runPropertyTranslators), ...RAW_CHILD_NAME_SET]);
25717
+ const toRunPropertyEntry = (candidate) => {
25718
+ if (!candidate || candidate.type !== "attr") return null;
25719
+ const xmlName = candidate.xmlName || candidate.name;
25720
+ if (!xmlName) return null;
25721
+ return {
25722
+ xmlName,
25723
+ attributes: { ...candidate.attributes || {} }
25724
+ };
25725
+ };
25726
+ const XML_NODE_NAME$g = "w:rPr";
25727
+ const SD_ATTR_KEY$5 = "runProperties";
25728
+ const encode$q = (params2) => {
25729
+ const { nodes } = params2;
25730
+ const node = nodes?.[0] || {};
25731
+ const contents = Array.isArray(node.elements) ? node.elements : [];
25732
+ const runPropsArray = contents.reduce(
25733
+ (acc, child) => {
25734
+ if (!child || typeof child !== "object") return acc;
25735
+ const xmlName = child.name;
25736
+ if (!KNOWN_CHILD_XML_NAMES.has(xmlName)) return acc;
25737
+ const translator2 = runPropertyTranslators[xmlName];
25738
+ let entry = null;
25739
+ if (translator2) {
25740
+ const encoded = translator2.encode({ ...params2, nodes: [child] }) || null;
25741
+ entry = toRunPropertyEntry(encoded);
25742
+ } else if (RAW_CHILD_NAME_SET.has(xmlName)) {
25743
+ entry = toRunPropertyEntry({
25744
+ type: "attr",
25745
+ xmlName,
25746
+ attributes: { ...child.attributes || {} }
25747
+ });
25748
+ }
25749
+ if (entry) acc.push(entry);
25750
+ return acc;
25751
+ },
25752
+ /** @type {{ xmlName: string, attributes: Record<string, any> }[]} */
25753
+ []
25754
+ );
25755
+ return {
25756
+ type: "attr",
25757
+ xmlName: "w:rPr",
25758
+ sdNodeOrKeyName: "runProperties",
25759
+ attributes: runPropsArray
25760
+ };
25761
+ };
25762
+ const config$e = {
25763
+ xmlName: XML_NODE_NAME$g,
25764
+ sdNodeOrKeyName: SD_ATTR_KEY$5,
25765
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
25766
+ encode: encode$q
25767
+ };
25768
+ const translator$U = NodeTranslator.from(config$e);
25769
+ const EAST_ASIAN_CHARACTER_REGEX = /[\u1100-\u11FF\u2E80-\u2EFF\u2F00-\u2FDF\u3040-\u30FF\u3100-\u312F\u3130-\u318F\u31A0-\u31BF\u3400-\u4DBF\u4E00-\u9FFF\uA960-\uA97F\uAC00-\uD7AF\uF900-\uFAFF\uFF00-\uFFEF]/u;
25770
+ const containsEastAsianCharacters = (text) => EAST_ASIAN_CHARACTER_REGEX.test(text);
25771
+ const collectRunProperties = (params2, rPrNode, translator2 = translator$U) => {
25772
+ if (!rPrNode) return { entries: [], hadRPr: false, styleChangeMarks: [] };
25773
+ const result = translator2.encode({ ...params2, nodes: [rPrNode] }) || {};
25774
+ let entries = [];
25775
+ if (Array.isArray(result.attributes) && result.attributes.length) {
25776
+ entries = result.attributes.map((attr) => ({
25777
+ xmlName: attr?.xmlName,
25778
+ attributes: { ...attr?.attributes || {} }
25779
+ }));
25780
+ } else if (Array.isArray(rPrNode.elements) && rPrNode.elements.length) {
25781
+ entries = rPrNode.elements.filter((el) => el && typeof el === "object").map((el) => ({
25782
+ xmlName: el.name,
25783
+ attributes: { ...el.attributes || {} }
25784
+ }));
25785
+ }
25786
+ const legacyMarks = parseMarks(rPrNode, [], params2?.docx) || [];
25787
+ const styleChangeMarks = handleStyleChangeMarks(rPrNode, legacyMarks) || [];
25788
+ return { entries, hadRPr: true, styleChangeMarks };
25789
+ };
25790
+ const buildRunAttrs = (encodedAttrs = {}, hadRPr, runProps) => {
25791
+ const base2 = { ...encodedAttrs || {} };
25792
+ if (hadRPr) {
25793
+ base2.runProperties = runProps.length ? runProps : null;
25794
+ }
25795
+ return base2;
25796
+ };
25797
+ const ensureInlineMarks = (marks, inlineMarks = []) => {
25798
+ inlineMarks.forEach(({ type: type2, attrs }) => {
25799
+ if (!type2) return;
25800
+ if (marks.some((mark) => mark?.type === type2)) return;
25801
+ marks.push(attrs ? { type: type2, attrs: { ...attrs } } : { type: type2 });
25802
+ });
25803
+ };
25804
+ const ensureTextStyleMark = (marks, textStyleAttrs) => {
25805
+ if (!textStyleAttrs) return;
25806
+ const existingTextStyle = marks.find((mark) => mark?.type === "textStyle");
25807
+ if (existingTextStyle) {
25808
+ existingTextStyle.attrs = { ...existingTextStyle.attrs || {}, ...textStyleAttrs };
25809
+ return;
25810
+ }
25811
+ marks.push({ type: "textStyle", attrs: { ...textStyleAttrs } });
25812
+ };
25813
+ const normalizeTextStyleAttrsForNode = (textStyleAttrs, node) => {
25814
+ if (!textStyleAttrs || typeof textStyleAttrs !== "object") return null;
25815
+ const normalized = { ...textStyleAttrs };
25816
+ const eastAsiaFont = normalized.eastAsiaFontFamily;
25817
+ if (eastAsiaFont) {
25818
+ delete normalized.eastAsiaFontFamily;
25819
+ const text = typeof node?.text === "string" ? node.text : null;
25820
+ const shouldUseEastAsia = typeof text === "string" && containsEastAsianCharacters(text);
25821
+ if (shouldUseEastAsia) {
25822
+ normalized.fontFamily = eastAsiaFont;
25823
+ }
25824
+ }
25825
+ return Object.keys(normalized).length ? normalized : null;
25826
+ };
25827
+ const applyRunMarks = (node, inlineMarks, textStyleAttrs) => {
25828
+ if (!node || typeof node !== "object") return node;
25829
+ const baseMarks = Array.isArray(node.marks) ? node.marks : [];
25830
+ const marks = baseMarks.map((mark) => cloneMark$1(mark));
25831
+ ensureInlineMarks(marks, inlineMarks);
25832
+ if (node.type === "text") {
25833
+ const normalizedTextStyle = normalizeTextStyleAttrsForNode(textStyleAttrs, node);
25834
+ ensureTextStyleMark(marks, normalizedTextStyle);
25835
+ }
25836
+ return { ...node, marks };
25837
+ };
25838
+ const deriveStyleMarks = ({ docx, paragraphStyleId, runStyleId }) => {
25839
+ const paragraphStyleMarks = collectStyleMarks(paragraphStyleId, docx);
25840
+ const runStyleMarks = collectStyleMarks(runStyleId, docx);
25841
+ const inlineMarks = mergeInlineMarkSets(paragraphStyleMarks.inlineMarks, runStyleMarks.inlineMarks);
25842
+ const textStyleAttrs = mergeTextStyleAttrs(paragraphStyleMarks.textStyleAttrs, runStyleMarks.textStyleAttrs);
25843
+ return { inlineMarks, textStyleAttrs };
25844
+ };
25845
+ const collectStyleMarks = (styleId, docx, seen = /* @__PURE__ */ new Set()) => {
25846
+ if (!styleId || !docx || seen.has(styleId)) return { inlineMarks: [], textStyleAttrs: null };
25847
+ seen.add(styleId);
25848
+ const chain = collectStyleChain(styleId, docx, seen);
25849
+ if (!chain.length) return { inlineMarks: [], textStyleAttrs: null };
25850
+ const inlineMap = /* @__PURE__ */ new Map();
25851
+ let textStyleAttrs = {};
25852
+ chain.forEach((styleTag) => {
25853
+ const marks = extractMarksFromStyle(styleTag, docx);
25854
+ marks.inlineMarks.forEach((mark) => {
25855
+ inlineMap.set(mark.type, mark.attrs ? { type: mark.type, attrs: { ...mark.attrs } } : { type: mark.type });
25856
+ });
25857
+ if (marks.textStyleAttrs) textStyleAttrs = { ...textStyleAttrs, ...marks.textStyleAttrs };
25858
+ });
25859
+ return {
25860
+ inlineMarks: Array.from(inlineMap.values()),
25861
+ textStyleAttrs: Object.keys(textStyleAttrs).length ? textStyleAttrs : null
25862
+ };
25863
+ };
25864
+ const collectStyleChain = (styleId, docx, seen) => {
25865
+ if (!styleId || !docx) return [];
25866
+ const styleTag = findStyleTag(docx, styleId);
25867
+ if (!styleTag || !styleTag.elements) return [];
25868
+ const basedOn = styleTag.elements?.find((el) => el.name === "w:basedOn")?.attributes?.["w:val"];
25869
+ let chain = [];
25870
+ if (basedOn && !seen.has(basedOn)) {
25871
+ seen.add(basedOn);
25872
+ chain = collectStyleChain(basedOn, docx, seen);
25873
+ }
25874
+ chain.push(styleTag);
25875
+ return chain;
25876
+ };
25877
+ const findStyleTag = (docx, styleId) => {
25878
+ const stylesFile = docx?.["word/styles.xml"];
25879
+ if (!stylesFile?.elements?.length) return null;
25880
+ const candidates = [];
25881
+ stylesFile.elements.forEach((el) => {
25882
+ if (!el) return;
25883
+ if (el.name === "w:styles" && Array.isArray(el.elements)) {
25884
+ el.elements.forEach((child) => {
25885
+ if (child?.name === "w:style") candidates.push(child);
25886
+ });
25887
+ return;
25888
+ }
25889
+ if (el.name === "w:style") {
25890
+ candidates.push(el);
25891
+ return;
25892
+ }
25893
+ if (Array.isArray(el.elements)) {
25894
+ el.elements.forEach((child) => {
25895
+ if (child?.name === "w:style") candidates.push(child);
25896
+ });
25897
+ }
25898
+ });
25899
+ return candidates.find((tag) => tag?.attributes?.["w:styleId"] === styleId) || null;
25900
+ };
25901
+ const extractMarksFromStyle = (styleTag, docx) => {
25902
+ const rPr = styleTag?.elements?.find((el) => el.name === "w:rPr");
25903
+ if (!rPr) return { inlineMarks: [], textStyleAttrs: null };
25904
+ const marks = parseMarks(rPr, [], docx) || [];
25905
+ const inlineMarks = [];
25906
+ let textStyleAttrs = {};
25907
+ marks.forEach((mark) => {
25908
+ if (!mark) return;
25909
+ if (mark.type === "textStyle") {
25910
+ const attrs = mark.attrs || {};
25911
+ if (Object.keys(attrs).length) textStyleAttrs = { ...textStyleAttrs, ...attrs };
25912
+ return;
25913
+ }
25914
+ if (mark.type) inlineMarks.push(mark.attrs ? { type: mark.type, attrs: { ...mark.attrs } } : { type: mark.type });
25915
+ });
25916
+ return {
25917
+ inlineMarks,
25918
+ textStyleAttrs: Object.keys(textStyleAttrs).length ? textStyleAttrs : null
25919
+ };
25920
+ };
25921
+ const mergeInlineMarkSets = (...markSets) => {
25922
+ const map3 = /* @__PURE__ */ new Map();
25923
+ markSets.filter(Boolean).forEach((marks) => {
25924
+ marks.forEach((mark) => {
25925
+ if (!mark || !mark.type) return;
25926
+ map3.set(mark.type, mark.attrs ? { type: mark.type, attrs: { ...mark.attrs } } : { type: mark.type });
25927
+ });
25928
+ });
25929
+ return Array.from(map3.values());
25930
+ };
25931
+ const mergeTextStyleAttrs = (...attrsList) => {
25932
+ const merged = attrsList.filter((attrs) => attrs && Object.keys(attrs).length).reduce((acc, attrs) => ({ ...acc, ...attrs }), {});
25933
+ return Object.keys(merged).length ? merged : null;
25934
+ };
25935
+ const cloneRunAttrs = (attrs) => {
25936
+ const clone = { ...attrs };
25937
+ if (Array.isArray(attrs?.runProperties)) {
25938
+ clone.runProperties = attrs.runProperties.map((entry) => ({
25939
+ xmlName: entry?.xmlName,
25940
+ attributes: { ...entry?.attributes || {} }
25941
+ }));
25942
+ }
25943
+ return clone;
25944
+ };
25945
+ const cloneMark$1 = (mark) => {
25946
+ if (!mark || typeof mark !== "object") return mark;
25947
+ const cloned = { ...mark };
25948
+ if (mark.attrs && typeof mark.attrs === "object") {
25949
+ cloned.attrs = { ...mark.attrs };
25950
+ if (Array.isArray(mark.attrs.runProperties)) {
25951
+ cloned.attrs.runProperties = mark.attrs.runProperties.map((entry) => ({
25952
+ xmlName: entry?.xmlName,
25953
+ attributes: { ...entry?.attributes || {} }
25954
+ }));
25955
+ }
25956
+ }
25957
+ return cloned;
25958
+ };
25959
+ const normalizeBool = (value) => {
25960
+ if (value === void 0 || value === null) return true;
25961
+ if (typeof value === "boolean") return value;
25962
+ if (typeof value === "number") return value !== 0;
25963
+ const normalized = String(value).trim().toLowerCase();
25964
+ if (normalized === "0" || normalized === "false" || normalized === "off") return false;
25965
+ if (normalized === "1" || normalized === "true" || normalized === "on") return true;
25966
+ return true;
25967
+ };
25968
+ const createRunPropertiesElement = (entries = []) => {
25969
+ if (!Array.isArray(entries) || !entries.length) return null;
25970
+ const elements = entries.map((entry) => {
25971
+ if (!entry || !entry.xmlName) return null;
25972
+ return {
25973
+ name: entry.xmlName,
25974
+ attributes: { ...entry.attributes || {} }
25975
+ };
25976
+ }).filter(Boolean);
25977
+ if (!elements.length) return null;
25978
+ return {
25979
+ name: "w:rPr",
25980
+ elements
25981
+ };
25982
+ };
25983
+ const cloneXmlNode = (nodeLike) => {
25984
+ if (!nodeLike || typeof nodeLike !== "object") return nodeLike;
25985
+ return {
25986
+ name: nodeLike.name,
25987
+ type: nodeLike.type,
25988
+ attributes: nodeLike.attributes ? { ...nodeLike.attributes } : void 0,
25989
+ elements: Array.isArray(nodeLike.elements) ? nodeLike.elements.map((el) => cloneXmlNode(el)) : void 0,
25990
+ text: nodeLike.text
25991
+ };
25992
+ };
25993
+ const applyRunPropertiesTemplate = (runNode, runPropertiesTemplate) => {
25994
+ if (!runNode || !runPropertiesTemplate) return;
25995
+ if (!Array.isArray(runNode.elements)) runNode.elements = [];
25996
+ let runProps = runNode.elements.find((el) => el?.name === "w:rPr");
25997
+ if (!runProps) {
25998
+ runProps = { name: "w:rPr", elements: [] };
25999
+ runNode.elements.unshift(runProps);
26000
+ }
26001
+ if (!Array.isArray(runProps.elements)) runProps.elements = [];
26002
+ if (runPropertiesTemplate.attributes) {
26003
+ runProps.attributes = {
26004
+ ...runProps.attributes || {},
26005
+ ...runPropertiesTemplate.attributes
26006
+ };
26007
+ }
26008
+ const isValidRunPropName = (name) => typeof name === "string" && name.includes(":");
26009
+ runProps.elements = runProps.elements.filter((entry) => isValidRunPropName(entry?.name));
26010
+ const existingNames = new Set(runProps.elements.map((el) => el?.name));
26011
+ (runPropertiesTemplate.elements || []).forEach((entry) => {
26012
+ if (!isValidRunPropName(entry?.name) || existingNames.has(entry.name)) return;
26013
+ runProps.elements.push(cloneXmlNode(entry));
26014
+ existingNames.add(entry.name);
26015
+ });
26016
+ };
26017
+ const splitRunProperties = (entries = [], docx = null) => {
26018
+ const remainingProps = [];
26019
+ const inlineMarks = [];
26020
+ const textStyleAttrs = {};
26021
+ let hasTextStyle = false;
26022
+ let highlightColor = null;
26023
+ let runStyleId = null;
26024
+ entries.forEach((entry) => {
26025
+ if (!entry || !entry.xmlName) return;
26026
+ const attributes = entry.attributes || {};
26027
+ switch (entry.xmlName) {
26028
+ case "w:b": {
26029
+ const val = normalizeBool(attributes["w:val"]);
26030
+ inlineMarks.push(val ? { type: "bold" } : { type: "bold", attrs: { value: "0" } });
26031
+ break;
26032
+ }
26033
+ case "w:i": {
26034
+ const val = normalizeBool(attributes["w:val"]);
26035
+ inlineMarks.push(val ? { type: "italic" } : { type: "italic", attrs: { value: "0" } });
26036
+ break;
26037
+ }
26038
+ case "w:u": {
26039
+ const rawVal = attributes["w:val"];
26040
+ const underlineType = rawVal == null || rawVal === "" ? "single" : String(rawVal);
26041
+ const attrs = {};
26042
+ if (underlineType.toLowerCase() === "none" || underlineType === "0") {
26043
+ attrs.underlineType = "none";
26044
+ } else {
26045
+ attrs.underlineType = underlineType;
26046
+ const colorRaw = attributes["w:color"];
26047
+ if (typeof colorRaw === "string" && colorRaw.toLowerCase() !== "auto") {
26048
+ const normalizedColor = normalizeHexColor(colorRaw);
26049
+ if (normalizedColor) attrs.underlineColor = `#${normalizedColor}`;
26050
+ }
26051
+ }
26052
+ if (attributes["w:themeColor"]) attrs.underlineThemeColor = attributes["w:themeColor"];
26053
+ if (attributes["w:themeTint"]) attrs.underlineThemeTint = attributes["w:themeTint"];
26054
+ if (attributes["w:themeShade"]) attrs.underlineThemeShade = attributes["w:themeShade"];
26055
+ inlineMarks.push({ type: "underline", attrs });
26056
+ break;
26057
+ }
26058
+ case "w:color": {
26059
+ const raw = attributes["w:val"];
26060
+ if (typeof raw === "string" && raw) {
26061
+ hasTextStyle = true;
26062
+ textStyleAttrs.color = `#${raw.replace("#", "").toUpperCase()}`;
26063
+ }
26064
+ break;
26065
+ }
26066
+ case "w:rFonts": {
26067
+ const asciiFamily = attributes["w:ascii"] || attributes["w:hAnsi"] || (attributes["w:eastAsia"] ? void 0 : attributes["w:val"]);
26068
+ const eastAsiaFamily = attributes["w:eastAsia"];
26069
+ if (asciiFamily) {
26070
+ hasTextStyle = true;
26071
+ textStyleAttrs.fontFamily = SuperConverter.toCssFontFamily(asciiFamily, docx);
26072
+ }
26073
+ if (eastAsiaFamily) {
26074
+ hasTextStyle = true;
26075
+ const eastAsiaCss = SuperConverter.toCssFontFamily(eastAsiaFamily, docx);
26076
+ if (!asciiFamily || eastAsiaCss !== textStyleAttrs.fontFamily) {
26077
+ textStyleAttrs.eastAsiaFontFamily = eastAsiaCss;
26078
+ }
26079
+ }
26080
+ break;
26081
+ }
26082
+ case "w:sz":
26083
+ case "w:szCs": {
26084
+ const rawSize = Number(attributes["w:val"]);
26085
+ if (Number.isFinite(rawSize) && rawSize > 0) {
26086
+ hasTextStyle = true;
26087
+ textStyleAttrs.fontSize = `${rawSize / 2}pt`;
26088
+ }
26089
+ break;
26090
+ }
26091
+ case "w:strike": {
26092
+ const val = normalizeBool(attributes["w:val"]);
26093
+ inlineMarks.push(val ? { type: "strike" } : { type: "strike", attrs: { value: "0" } });
26094
+ break;
26095
+ }
26096
+ case "w:highlight": {
26097
+ const color = attributes["w:val"];
26098
+ if (typeof color === "string" && color) {
26099
+ highlightColor = color.toLowerCase() === "none" ? "transparent" : color;
26100
+ }
26101
+ break;
26102
+ }
26103
+ case "w:shd": {
26104
+ const fill = attributes["w:fill"];
26105
+ const shdVal = attributes["w:val"];
26106
+ if (fill && String(fill).toLowerCase() !== "auto") {
26107
+ highlightColor = `#${String(fill).replace("#", "")}`;
26108
+ } else if (typeof shdVal === "string") {
26109
+ const normalized = shdVal.toLowerCase();
26110
+ if (normalized === "clear" || normalized === "nil" || normalized === "none") {
26111
+ highlightColor = "transparent";
26112
+ }
26113
+ }
26114
+ break;
26115
+ }
26116
+ case "w:rStyle": {
26117
+ if (typeof attributes["w:val"] === "string") runStyleId = attributes["w:val"];
26118
+ remainingProps.push({ xmlName: entry.xmlName, attributes: { ...attributes } });
26119
+ break;
26120
+ }
26121
+ default: {
26122
+ remainingProps.push({ xmlName: entry.xmlName, attributes: { ...attributes } });
26123
+ }
26124
+ }
26125
+ });
26126
+ if (highlightColor) inlineMarks.push({ type: "highlight", attrs: { color: highlightColor } });
26127
+ return {
26128
+ remainingProps,
26129
+ inlineMarks,
26130
+ textStyleAttrs: hasTextStyle ? textStyleAttrs : null,
26131
+ runStyleId
26132
+ };
26133
+ };
26134
+ const cloneMark = (mark) => {
26135
+ if (!mark) return mark;
26136
+ return {
26137
+ ...mark,
26138
+ attrs: mark.attrs ? { ...mark.attrs } : void 0
26139
+ };
26140
+ };
26141
+ const cloneNode = (node) => {
26142
+ if (!node || typeof node !== "object") return node;
26143
+ const cloned = { ...node };
26144
+ if (node.marks) cloned.marks = node.marks.map((mark) => cloneMark(mark));
26145
+ if (node.content) cloned.content = node.content.map((child) => cloneNode(child));
26146
+ if (node.elements) cloned.elements = node.elements.map((el) => cloneNode(el));
26147
+ if (node.attributes) cloned.attributes = { ...node.attributes };
26148
+ return cloned;
26149
+ };
26150
+ const cloneRuns = (runs = []) => runs.map((run2) => cloneNode(run2));
26151
+ const prepareRunTrackingContext = (node = {}) => {
26152
+ const marks = Array.isArray(node.marks) ? node.marks : [];
26153
+ const trackingMarks = marks.filter(
26154
+ (mark) => mark?.type === TrackInsertMarkName || mark?.type === TrackDeleteMarkName
26155
+ );
26156
+ if (!trackingMarks.length) {
26157
+ return { runNode: node, trackingMarksByType: /* @__PURE__ */ new Map() };
26158
+ }
26159
+ const trackingMarksByType = /* @__PURE__ */ new Map();
26160
+ trackingMarks.forEach((mark) => {
26161
+ if (mark?.type) trackingMarksByType.set(mark.type, cloneMark(mark));
26162
+ });
26163
+ const preservedMarks = marks.filter((mark) => mark?.type !== TrackInsertMarkName && mark?.type !== TrackDeleteMarkName).map((mark) => cloneMark(mark));
26164
+ const clonedContent = Array.isArray(node.content) ? node.content.map((child) => {
26165
+ const childClone = cloneNode(child);
26166
+ const childMarks = Array.isArray(childClone.marks) ? childClone.marks.slice() : [];
26167
+ trackingMarks.forEach((mark) => {
26168
+ childMarks.push(cloneMark(mark));
26169
+ });
26170
+ childClone.marks = childMarks;
26171
+ return childClone;
26172
+ }) : [];
26173
+ return {
26174
+ runNode: {
26175
+ ...cloneNode(node),
26176
+ marks: preservedMarks,
26177
+ content: clonedContent
26178
+ },
26179
+ trackingMarksByType
26180
+ };
26181
+ };
26182
+ const mapTrackingAttrs = (mark, attrMap) => {
26183
+ const source = mark?.attrs || {};
26184
+ const mapped = {};
26185
+ attrMap.forEach((targetKey, sourceKey) => {
26186
+ if (source[sourceKey] != null) mapped[targetKey] = source[sourceKey];
26187
+ });
26188
+ return mapped;
26189
+ };
26190
+ const renameTextElementsForDeletion = (node) => {
26191
+ if (!node || typeof node !== "object") return;
26192
+ if (node.name === "w:t") node.name = "w:delText";
26193
+ if (Array.isArray(node.elements)) node.elements.forEach(renameTextElementsForDeletion);
26194
+ };
26195
+ const ensureTrackedWrapper = (runs, trackingMarksByType = /* @__PURE__ */ new Map()) => {
26196
+ if (!Array.isArray(runs) || !runs.length) return runs;
26197
+ const firstRun = runs[0];
26198
+ if (firstRun?.name === "w:ins" || firstRun?.name === "w:del") {
26199
+ return runs;
26200
+ }
26201
+ if (!trackingMarksByType.size) return runs;
26202
+ if (trackingMarksByType.has(TrackInsertMarkName)) {
26203
+ const mark = trackingMarksByType.get(TrackInsertMarkName);
26204
+ const clonedRuns = cloneRuns(runs);
26205
+ const wrapper = {
26206
+ name: "w:ins",
26207
+ attributes: mapTrackingAttrs(
26208
+ mark,
26209
+ /* @__PURE__ */ new Map([
26210
+ ["id", "w:id"],
26211
+ ["author", "w:author"],
26212
+ ["authorEmail", "w:authorEmail"],
26213
+ ["date", "w:date"]
26214
+ ])
26215
+ ),
26216
+ elements: clonedRuns
26217
+ };
26218
+ return [wrapper];
26219
+ }
26220
+ if (trackingMarksByType.has(TrackDeleteMarkName)) {
26221
+ const mark = trackingMarksByType.get(TrackDeleteMarkName);
26222
+ const clonedRuns = cloneRuns(runs);
26223
+ clonedRuns.forEach(renameTextElementsForDeletion);
26224
+ const wrapper = {
26225
+ name: "w:del",
26226
+ attributes: mapTrackingAttrs(mark, /* @__PURE__ */ new Map([["id", "w:id"]])),
26227
+ elements: clonedRuns
26228
+ };
26229
+ return [wrapper];
26230
+ }
26231
+ return runs;
26232
+ };
26233
+ const encode$p = (attributes) => {
26234
+ return attributes["w:rsidR"];
26235
+ };
26236
+ const decode$p = (attrs) => {
26237
+ return attrs.rsidR;
26238
+ };
26239
+ const attrConfig$9 = Object.freeze({
26240
+ xmlName: "w:rsidR",
26241
+ sdName: "rsidR",
26242
+ encode: encode$p,
26243
+ decode: decode$p
26244
+ });
26245
+ const encode$o = (attributes) => {
26246
+ return attributes["w:rsidRPr"];
26247
+ };
26248
+ const decode$o = (attrs) => {
26249
+ return attrs.rsidRPr;
26250
+ };
26251
+ const attrConfig$8 = Object.freeze({
26252
+ xmlName: "w:rsidRPr",
26253
+ sdName: "rsidRPr",
26254
+ encode: encode$o,
26255
+ decode: decode$o
26256
+ });
26257
+ const encode$n = (attributes) => {
26258
+ return attributes["w:rsidDel"];
26259
+ };
26260
+ const decode$n = (attrs) => {
26261
+ return attrs.rsidDel;
26262
+ };
26263
+ const attrConfig$7 = Object.freeze({
26264
+ xmlName: "w:rsidDel",
26265
+ sdName: "rsidDel",
26266
+ encode: encode$n,
26267
+ decode: decode$n
26268
+ });
26269
+ const validXmlAttributes$9 = [attrConfig$9, attrConfig$8, attrConfig$7];
26270
+ const XML_NODE_NAME$f = "w:r";
26271
+ const SD_KEY_NAME = "run";
26272
+ const encode$m = (params2, encodedAttrs = {}) => {
26273
+ const { nodes = [], nodeListHandler } = params2 || {};
26274
+ const runNode = nodes[0];
26275
+ if (!runNode) return void 0;
26276
+ const elements = Array.isArray(runNode.elements) ? runNode.elements : [];
26277
+ const rPrNode = elements.find((child) => child?.name === "w:rPr");
26278
+ const contentElements = rPrNode ? elements.filter((el) => el !== rPrNode) : elements;
26279
+ const { entries: runPropEntries, hadRPr, styleChangeMarks } = collectRunProperties(params2, rPrNode);
26280
+ const { remainingProps, inlineMarks, textStyleAttrs, runStyleId } = splitRunProperties(runPropEntries, params2?.docx);
26281
+ const styleMarks = deriveStyleMarks({
26282
+ docx: params2?.docx,
26283
+ paragraphStyleId: params2?.parentStyleId,
26284
+ runStyleId
26285
+ });
26286
+ const mergedInlineMarks = mergeInlineMarkSets(styleMarks.inlineMarks, inlineMarks);
26287
+ let mergedTextStyleAttrs = mergeTextStyleAttrs(styleMarks.textStyleAttrs, textStyleAttrs);
26288
+ if (runStyleId) {
26289
+ mergedTextStyleAttrs = mergedTextStyleAttrs ? { ...mergedTextStyleAttrs, styleId: runStyleId } : { styleId: runStyleId };
26290
+ }
26291
+ const runAttrs = buildRunAttrs(encodedAttrs, hadRPr, remainingProps);
26292
+ let runLevelMarks = Array.isArray(runNode.marks) ? runNode.marks.map((mark) => cloneMark$1(mark)) : [];
26293
+ if (styleChangeMarks?.length) {
26294
+ runLevelMarks = [...runLevelMarks, ...styleChangeMarks.map((mark) => cloneMark$1(mark))];
26295
+ }
26296
+ const childParams = { ...params2, nodes: contentElements };
26297
+ const content = nodeListHandler?.handler(childParams) || [];
26298
+ const contentWithRunMarks = content.map((child) => {
26299
+ if (!child || typeof child !== "object") return child;
26300
+ const baseMarks = Array.isArray(child.marks) ? child.marks.map((mark) => cloneMark$1(mark)) : [];
26301
+ if (!runLevelMarks.length) return child;
26302
+ return { ...child, marks: [...baseMarks, ...runLevelMarks.map((mark) => cloneMark$1(mark))] };
26303
+ });
26304
+ const marked = contentWithRunMarks.map((child) => applyRunMarks(child, mergedInlineMarks, mergedTextStyleAttrs));
26305
+ const filtered = marked.filter(Boolean);
26306
+ const runNodeResult = {
26307
+ type: SD_KEY_NAME,
26308
+ content: filtered
26309
+ };
26310
+ const attrs = cloneRunAttrs(runAttrs);
26311
+ if (attrs && Object.keys(attrs).length) {
26312
+ if (attrs.runProperties == null) delete attrs.runProperties;
26313
+ if (Object.keys(attrs).length) runNodeResult.attrs = attrs;
26314
+ }
26315
+ if (runLevelMarks.length) {
26316
+ runNodeResult.marks = runLevelMarks.map((mark) => cloneMark$1(mark));
26317
+ }
26318
+ return runNodeResult;
26319
+ };
26320
+ const decode$m = (params2, decodedAttrs = {}) => {
26321
+ const { node } = params2 || {};
26322
+ if (!node) return void 0;
26323
+ const { runNode: runNodeForExport, trackingMarksByType } = prepareRunTrackingContext(node);
26324
+ const runAttrs = runNodeForExport.attrs || {};
26325
+ const runProperties = Array.isArray(runAttrs.runProperties) ? runAttrs.runProperties : [];
26326
+ const exportParams = { ...params2, node: runNodeForExport };
26327
+ if (!exportParams.editor) {
26328
+ exportParams.editor = { extensionService: { extensions: [] } };
26329
+ }
26330
+ const childElements = translateChildNodes(exportParams) || [];
26331
+ let runPropertiesElement = createRunPropertiesElement(runProperties);
26332
+ const markElements = processOutputMarks(Array.isArray(runNodeForExport.marks) ? runNodeForExport.marks : []);
26333
+ if (markElements.length) {
26334
+ if (!runPropertiesElement) {
26335
+ runPropertiesElement = generateRunProps(markElements);
26336
+ } else {
26337
+ if (!Array.isArray(runPropertiesElement.elements)) runPropertiesElement.elements = [];
26338
+ const existingNames = new Set(
26339
+ runPropertiesElement.elements.map((el) => el?.name).filter((name) => typeof name === "string")
26340
+ );
26341
+ markElements.forEach((element) => {
26342
+ if (!element || !element.name || existingNames.has(element.name)) return;
26343
+ runPropertiesElement.elements.push({ ...element, attributes: { ...element.attributes || {} } });
26344
+ existingNames.add(element.name);
26345
+ });
26346
+ }
26347
+ }
26348
+ const runPropsTemplate = runPropertiesElement ? cloneXmlNode(runPropertiesElement) : null;
26349
+ const applyBaseRunProps = (runNode) => applyRunPropertiesTemplate(runNode, runPropsTemplate);
26350
+ const runs = [];
26351
+ childElements.forEach((child) => {
26352
+ if (!child) return;
26353
+ if (child.name === "w:r") {
26354
+ const clonedRun = cloneXmlNode(child);
26355
+ applyBaseRunProps(clonedRun);
26356
+ runs.push(clonedRun);
26357
+ return;
26358
+ }
26359
+ if (child.name === "w:hyperlink") {
26360
+ const hyperlinkClone = cloneXmlNode(child);
26361
+ if (Array.isArray(hyperlinkClone.elements)) {
26362
+ hyperlinkClone.elements.forEach((run2) => applyBaseRunProps(run2));
26363
+ }
26364
+ runs.push(hyperlinkClone);
26365
+ return;
26366
+ }
26367
+ if (child.name === "w:ins" || child.name === "w:del") {
26368
+ const trackedClone = cloneXmlNode(child);
26369
+ if (Array.isArray(trackedClone.elements)) {
26370
+ trackedClone.elements.forEach((element) => {
26371
+ if (element?.name === "w:r") applyBaseRunProps(element);
26372
+ });
26373
+ }
26374
+ runs.push(trackedClone);
26375
+ return;
26376
+ }
26377
+ const runWrapper = { name: XML_NODE_NAME$f, elements: [] };
26378
+ applyBaseRunProps(runWrapper);
26379
+ if (!Array.isArray(runWrapper.elements)) runWrapper.elements = [];
26380
+ runWrapper.elements.push(cloneXmlNode(child));
26381
+ runs.push(runWrapper);
26382
+ });
26383
+ const trackedRuns = ensureTrackedWrapper(runs, trackingMarksByType);
26384
+ if (!trackedRuns.length) {
26385
+ const emptyRun = { name: XML_NODE_NAME$f, elements: [] };
26386
+ applyBaseRunProps(emptyRun);
26387
+ trackedRuns.push(emptyRun);
26388
+ }
26389
+ if (decodedAttrs && Object.keys(decodedAttrs).length) {
26390
+ trackedRuns.forEach((run2) => {
26391
+ run2.attributes = { ...run2.attributes || {}, ...decodedAttrs };
26392
+ });
26393
+ }
26394
+ if (trackedRuns.length === 1) {
26395
+ return trackedRuns[0];
26396
+ }
26397
+ return trackedRuns;
26398
+ };
25136
26399
  const config$d = {
25137
26400
  xmlName: XML_NODE_NAME$f,
25138
- sdNodeOrKeyName: SD_NODE_NAME$a,
26401
+ sdNodeOrKeyName: SD_KEY_NAME,
25139
26402
  type: NodeTranslator.translatorTypes.NODE,
25140
26403
  encode: encode$m,
25141
26404
  decode: decode$m,
@@ -26513,17 +27776,52 @@ const encode$d = (params2, encodedAttrs) => {
26513
27776
  const { nodes, docx, nodeListHandler } = params2;
26514
27777
  const node = nodes[0];
26515
27778
  let href = _resolveHref(docx, encodedAttrs);
26516
- const linkMark = { type: "link", attrs: { ...encodedAttrs, href } };
27779
+ const linkMark = { attrs: { ...encodedAttrs, href } };
26517
27780
  const runNodes = node.elements.filter((el) => el.name === "w:r");
26518
27781
  runNodes.forEach((runNode) => {
26519
- runNode.marks = [...runNode.marks || [], linkMark];
27782
+ const existingRunMarks = Array.isArray(runNode.marks) ? runNode.marks : [];
27783
+ const runMarksWithoutLink = existingRunMarks.filter((mark) => mark?.type !== "link");
27784
+ runNode.marks = runMarksWithoutLink;
26520
27785
  });
26521
27786
  const updatedNode = nodeListHandler.handler({
26522
27787
  ...params2,
26523
27788
  nodes: runNodes,
26524
27789
  path: [...params2.path || [], node]
26525
27790
  });
26526
- return updatedNode;
27791
+ const cloneMark2 = (mark) => {
27792
+ if (!mark || typeof mark !== "object") return mark;
27793
+ if (!mark.attrs) return { ...mark };
27794
+ return { ...mark, attrs: { ...mark.attrs } };
27795
+ };
27796
+ const ensureLinkMark = (child) => {
27797
+ if (!child || typeof child !== "object") return child;
27798
+ if (Array.isArray(child.content)) {
27799
+ const updatedContent = child.content.map((item) => ensureLinkMark(item));
27800
+ if (updatedContent !== child.content) {
27801
+ child = { ...child, content: updatedContent };
27802
+ }
27803
+ }
27804
+ if (child.type === "run") {
27805
+ const existingMarks2 = Array.isArray(child.marks) ? child.marks : [];
27806
+ const filteredMarks = existingMarks2.filter((mark) => mark?.type !== "link").map((mark) => cloneMark2(mark));
27807
+ if (filteredMarks.length !== existingMarks2.length) {
27808
+ if (filteredMarks.length) child = { ...child, marks: filteredMarks };
27809
+ else {
27810
+ const { marks, ...rest } = child;
27811
+ child = rest;
27812
+ }
27813
+ }
27814
+ return child;
27815
+ }
27816
+ if (child.type !== "text") return child;
27817
+ const existingMarks = Array.isArray(child.marks) ? child.marks.map((mark) => cloneMark2(mark)) : [];
27818
+ const hasLink = existingMarks.some((mark) => mark?.type === "link");
27819
+ if (hasLink) return child;
27820
+ const linkClone = { type: "link", attrs: { ...linkMark.attrs } };
27821
+ return { ...child, marks: [...existingMarks, linkClone] };
27822
+ };
27823
+ if (!Array.isArray(updatedNode)) return updatedNode;
27824
+ return updatedNode.map((child) => ensureLinkMark(child));
26527
27825
  };
26528
27826
  const _resolveHref = (docx, encodedAttrs) => {
26529
27827
  const rels = docx["word/_rels/document.xml.rels"];
@@ -27454,176 +28752,30 @@ const config$4 = {
27454
28752
  attributes: validXmlAttributes$4
27455
28753
  };
27456
28754
  const translator$4 = NodeTranslator.from(config$4);
27457
- const encode$a = (attributes) => {
27458
- return attributes["w:id"];
27459
- };
27460
- const decode$a = (attrs) => {
27461
- return attrs.id;
27462
- };
27463
- const attrConfig$6 = Object.freeze({
27464
- xmlName: "w:id",
27465
- sdName: "id",
27466
- encode: encode$a,
27467
- decode: decode$a
27468
- });
27469
- const encode$9 = (attributes) => {
27470
- return attributes["w:name"];
27471
- };
27472
- const decode$9 = (attrs) => {
27473
- return attrs.name;
27474
- };
27475
- const attrConfig$5 = Object.freeze({
27476
- xmlName: "w:name",
27477
- sdName: "name",
27478
- encode: encode$9,
27479
- decode: decode$9
27480
- });
27481
- const encode$8 = (attributes) => {
27482
- return attributes["w:colFirst"];
27483
- };
27484
- const decode$8 = (attrs) => {
27485
- return attrs.colFirst;
27486
- };
27487
- const attrConfig$4 = Object.freeze({
27488
- xmlName: "w:colFirst",
27489
- sdName: "colFirst",
27490
- encode: encode$8,
27491
- decode: decode$8
27492
- });
27493
- const encode$7 = (attributes) => {
27494
- return attributes["w:colLast"];
27495
- };
27496
- const decode$7 = (attrs) => {
27497
- return attrs.colLast;
27498
- };
27499
- const attrConfig$3 = Object.freeze({
27500
- xmlName: "w:colLast",
27501
- sdName: "colLast",
27502
- encode: encode$7,
27503
- decode: decode$7
27504
- });
27505
- const encode$6 = (attributes) => {
27506
- return attributes["w:displacedByCustomXml"];
27507
- };
27508
- const decode$6 = (attrs) => {
27509
- return attrs.displacedByCustomXml;
27510
- };
27511
- const attrConfig$2 = Object.freeze({
27512
- xmlName: "w:displacedByCustomXml",
27513
- sdName: "displacedByCustomXml",
27514
- encode: encode$6,
27515
- decode: decode$6
27516
- });
27517
- const validXmlAttributes$3 = [attrConfig$6, attrConfig$5, attrConfig$4, attrConfig$3, attrConfig$2];
27518
- const XML_NODE_NAME$3 = "w:bookmarkStart";
27519
- const SD_NODE_NAME$3 = "bookmarkStart";
27520
- const encode$5 = (params2, encodedAttrs = {}) => {
27521
- return {
27522
- type: "bookmarkStart",
27523
- attrs: encodedAttrs
27524
- };
27525
- };
27526
- const decode$5 = (params2, decodedAttrs = {}) => {
27527
- const result = {
27528
- name: "w:bookmarkStart",
27529
- elements: []
27530
- };
27531
- if (decodedAttrs && Object.keys(decodedAttrs).length) {
27532
- result.attributes = decodedAttrs;
27533
- }
27534
- return result;
27535
- };
27536
- const config$3 = {
27537
- xmlName: XML_NODE_NAME$3,
27538
- sdNodeOrKeyName: SD_NODE_NAME$3,
27539
- type: NodeTranslator.translatorTypes.NODE,
27540
- encode: encode$5,
27541
- decode: decode$5,
27542
- attributes: validXmlAttributes$3
27543
- };
27544
- const translator$3 = NodeTranslator.from(config$3);
27545
- const encode$4 = (attributes) => {
27546
- return attributes["w:id"];
27547
- };
27548
- const decode$4 = (attrs) => {
27549
- return attrs.id;
27550
- };
27551
- const attrConfig$1 = Object.freeze({
27552
- xmlName: "w:id",
27553
- sdName: "id",
27554
- encode: encode$4,
27555
- decode: decode$4
27556
- });
27557
- const encode$3 = (attributes) => {
27558
- return attributes["w:displacedByCustomXml"];
27559
- };
27560
- const decode$3 = (attrs) => {
27561
- return attrs.displacedByCustomXml;
27562
- };
27563
- const attrConfig = Object.freeze({
27564
- xmlName: "w:displacedByCustomXml",
27565
- sdName: "displacedByCustomXml",
27566
- encode: encode$3,
27567
- decode: decode$3
27568
- });
27569
- const validXmlAttributes$2 = [attrConfig$1, attrConfig];
27570
- const XML_NODE_NAME$2 = "w:bookmarkEnd";
27571
- const SD_NODE_NAME$2 = "bookmarkEnd";
27572
- const encode$2 = (params2, encodedAttrs = {}) => {
27573
- return {
27574
- type: "bookmarkEnd",
27575
- attrs: encodedAttrs
27576
- };
27577
- };
27578
- const decode$2 = (params2, decodedAttrs = {}) => {
27579
- const result = {
27580
- name: "w:bookmarkEnd",
27581
- elements: []
27582
- };
27583
- if (decodedAttrs && Object.keys(decodedAttrs).length) {
27584
- result.attributes = decodedAttrs;
27585
- }
27586
- return result;
27587
- };
27588
- const config$2 = {
27589
- xmlName: XML_NODE_NAME$2,
27590
- sdNodeOrKeyName: SD_NODE_NAME$2,
27591
- type: NodeTranslator.translatorTypes.NODE,
27592
- encode: encode$2,
27593
- decode: decode$2,
27594
- attributes: validXmlAttributes$2
27595
- };
27596
- const translator$2 = NodeTranslator.from(config$2);
27597
- const registeredHandlers = Object.freeze({
27598
- "w:br": translator$V,
27599
- "w:tab": translator$U,
27600
- "w:p": translator$T,
27601
- "wp:anchor": translator$5,
27602
- "wp:inline": translator$4,
27603
- "w:bookmarkStart": translator$3,
27604
- "w:bookmarkEnd": translator$2
27605
- });
27606
- const XML_NODE_NAME$1 = "w:drawing";
27607
- const SD_NODE_NAME$1 = [];
27608
- const validXmlAttributes$1 = [];
27609
- function encode$1(params2) {
28755
+ const XML_NODE_NAME$3 = "w:drawing";
28756
+ const SD_NODE_NAME$3 = [];
28757
+ const validXmlAttributes$3 = [];
28758
+ function encode$a(params2) {
27610
28759
  const nodes = params2.nodes;
27611
28760
  const node = nodes[0];
27612
- const validChildTranslators = ["wp:anchor", "wp:inline"];
28761
+ const translatorByChildName = {
28762
+ "wp:anchor": translator$5,
28763
+ "wp:inline": translator$4
28764
+ };
27613
28765
  return node.elements.reduce((acc, child) => {
27614
28766
  if (acc) return acc;
27615
- if (!validChildTranslators.includes(child.name)) return acc;
27616
- const translator2 = registeredHandlers[child.name];
28767
+ const translator2 = translatorByChildName[child.name];
28768
+ if (!translator2) return acc;
27617
28769
  return translator2.encode({ ...params2, extraParams: { node: child } }) || acc;
27618
28770
  }, null);
27619
28771
  }
27620
- function decode$1(params2) {
28772
+ function decode$a(params2) {
27621
28773
  const { node } = params2;
27622
28774
  if (!node || !node.type) {
27623
28775
  return null;
27624
28776
  }
27625
- const handlerName = node.attrs.isAnchor ? "wp:anchor" : "wp:inline";
27626
- const resultNode = registeredHandlers[handlerName].decode(params2);
28777
+ const childTranslator = node.attrs.isAnchor ? translator$5 : translator$4;
28778
+ const resultNode = childTranslator.decode(params2);
27627
28779
  return wrapTextInRun(
27628
28780
  {
27629
28781
  name: "w:drawing",
@@ -27632,15 +28784,15 @@ function decode$1(params2) {
27632
28784
  []
27633
28785
  );
27634
28786
  }
27635
- const config$1 = {
27636
- xmlName: XML_NODE_NAME$1,
27637
- sdNodeOrKeyName: SD_NODE_NAME$1,
28787
+ const config$3 = {
28788
+ xmlName: XML_NODE_NAME$3,
28789
+ sdNodeOrKeyName: SD_NODE_NAME$3,
27638
28790
  type: NodeTranslator.translatorTypes.NODE,
27639
- encode: encode$1,
27640
- decode: decode$1,
27641
- attributes: validXmlAttributes$1
28791
+ encode: encode$a,
28792
+ decode: decode$a,
28793
+ attributes: validXmlAttributes$3
27642
28794
  };
27643
- const translator$1 = NodeTranslator.from(config$1);
28795
+ const translator$3 = NodeTranslator.from(config$3);
27644
28796
  class CommandService {
27645
28797
  /**
27646
28798
  * @param {import('./commands/types/index.js').CommandServiceOptions} props
@@ -28978,7 +30130,7 @@ function prepareTextAnnotation(params2) {
28978
30130
  return getTextNodeForExport(attrs.displayLabel, [...marks, ...marksFromAttrs], params2);
28979
30131
  }
28980
30132
  function prepareImageAnnotation(params2, imageSize) {
28981
- return translator$1.decode({
30133
+ return translator$3.decode({
28982
30134
  ...params2,
28983
30135
  imageSize
28984
30136
  });
@@ -29215,10 +30367,10 @@ function translateStructuredContent(params2) {
29215
30367
  };
29216
30368
  return result;
29217
30369
  }
29218
- const XML_NODE_NAME = "w:sdt";
29219
- const SD_NODE_NAME = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
29220
- const validXmlAttributes = [];
29221
- function encode$B(params2) {
30370
+ const XML_NODE_NAME$2 = "w:sdt";
30371
+ const SD_NODE_NAME$2 = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
30372
+ const validXmlAttributes$2 = [];
30373
+ function encode$9(params2) {
29222
30374
  const nodes = params2.nodes;
29223
30375
  const node = nodes[0];
29224
30376
  const { type: sdtType, handler: handler2 } = sdtNodeTypeStrategy(node);
@@ -29228,7 +30380,7 @@ function encode$B(params2) {
29228
30380
  const result = handler2(params2);
29229
30381
  return result;
29230
30382
  }
29231
- function decode(params2) {
30383
+ function decode$9(params2) {
29232
30384
  const { node } = params2;
29233
30385
  if (!node || !node.type) {
29234
30386
  return null;
@@ -29244,44 +30396,193 @@ function decode(params2) {
29244
30396
  const result = decoder();
29245
30397
  return result;
29246
30398
  }
30399
+ const config$2 = {
30400
+ xmlName: XML_NODE_NAME$2,
30401
+ sdNodeOrKeyName: SD_NODE_NAME$2,
30402
+ type: NodeTranslator.translatorTypes.NODE,
30403
+ encode: encode$9,
30404
+ decode: decode$9,
30405
+ attributes: validXmlAttributes$2
30406
+ };
30407
+ const translator$2 = NodeTranslator.from(config$2);
30408
+ const encode$8 = (attributes) => {
30409
+ return attributes["w:id"];
30410
+ };
30411
+ const decode$8 = (attrs) => {
30412
+ return attrs.id;
30413
+ };
30414
+ const attrConfig$6 = Object.freeze({
30415
+ xmlName: "w:id",
30416
+ sdName: "id",
30417
+ encode: encode$8,
30418
+ decode: decode$8
30419
+ });
30420
+ const encode$7 = (attributes) => {
30421
+ return attributes["w:name"];
30422
+ };
30423
+ const decode$7 = (attrs) => {
30424
+ return attrs.name;
30425
+ };
30426
+ const attrConfig$5 = Object.freeze({
30427
+ xmlName: "w:name",
30428
+ sdName: "name",
30429
+ encode: encode$7,
30430
+ decode: decode$7
30431
+ });
30432
+ const encode$6 = (attributes) => {
30433
+ return attributes["w:colFirst"];
30434
+ };
30435
+ const decode$6 = (attrs) => {
30436
+ return attrs.colFirst;
30437
+ };
30438
+ const attrConfig$4 = Object.freeze({
30439
+ xmlName: "w:colFirst",
30440
+ sdName: "colFirst",
30441
+ encode: encode$6,
30442
+ decode: decode$6
30443
+ });
30444
+ const encode$5 = (attributes) => {
30445
+ return attributes["w:colLast"];
30446
+ };
30447
+ const decode$5 = (attrs) => {
30448
+ return attrs.colLast;
30449
+ };
30450
+ const attrConfig$3 = Object.freeze({
30451
+ xmlName: "w:colLast",
30452
+ sdName: "colLast",
30453
+ encode: encode$5,
30454
+ decode: decode$5
30455
+ });
30456
+ const encode$4 = (attributes) => {
30457
+ return attributes["w:displacedByCustomXml"];
30458
+ };
30459
+ const decode$4 = (attrs) => {
30460
+ return attrs.displacedByCustomXml;
30461
+ };
30462
+ const attrConfig$2 = Object.freeze({
30463
+ xmlName: "w:displacedByCustomXml",
30464
+ sdName: "displacedByCustomXml",
30465
+ encode: encode$4,
30466
+ decode: decode$4
30467
+ });
30468
+ const validXmlAttributes$1 = [attrConfig$6, attrConfig$5, attrConfig$4, attrConfig$3, attrConfig$2];
30469
+ const XML_NODE_NAME$1 = "w:bookmarkStart";
30470
+ const SD_NODE_NAME$1 = "bookmarkStart";
30471
+ const encode$3 = (params2, encodedAttrs = {}) => {
30472
+ return {
30473
+ type: "bookmarkStart",
30474
+ attrs: encodedAttrs
30475
+ };
30476
+ };
30477
+ const decode$3 = (params2, decodedAttrs = {}) => {
30478
+ const result = {
30479
+ name: "w:bookmarkStart",
30480
+ elements: []
30481
+ };
30482
+ if (decodedAttrs && Object.keys(decodedAttrs).length) {
30483
+ result.attributes = decodedAttrs;
30484
+ }
30485
+ return result;
30486
+ };
30487
+ const config$1 = {
30488
+ xmlName: XML_NODE_NAME$1,
30489
+ sdNodeOrKeyName: SD_NODE_NAME$1,
30490
+ type: NodeTranslator.translatorTypes.NODE,
30491
+ encode: encode$3,
30492
+ decode: decode$3,
30493
+ attributes: validXmlAttributes$1
30494
+ };
30495
+ const translator$1 = NodeTranslator.from(config$1);
30496
+ const encode$2 = (attributes) => {
30497
+ return attributes["w:id"];
30498
+ };
30499
+ const decode$2 = (attrs) => {
30500
+ return attrs.id;
30501
+ };
30502
+ const attrConfig$1 = Object.freeze({
30503
+ xmlName: "w:id",
30504
+ sdName: "id",
30505
+ encode: encode$2,
30506
+ decode: decode$2
30507
+ });
30508
+ const encode$1 = (attributes) => {
30509
+ return attributes["w:displacedByCustomXml"];
30510
+ };
30511
+ const decode$1 = (attrs) => {
30512
+ return attrs.displacedByCustomXml;
30513
+ };
30514
+ const attrConfig = Object.freeze({
30515
+ xmlName: "w:displacedByCustomXml",
30516
+ sdName: "displacedByCustomXml",
30517
+ encode: encode$1,
30518
+ decode: decode$1
30519
+ });
30520
+ const validXmlAttributes = [attrConfig$1, attrConfig];
30521
+ const XML_NODE_NAME = "w:bookmarkEnd";
30522
+ const SD_NODE_NAME = "bookmarkEnd";
30523
+ const encode$18 = (params2, encodedAttrs = {}) => {
30524
+ return {
30525
+ type: "bookmarkEnd",
30526
+ attrs: encodedAttrs
30527
+ };
30528
+ };
30529
+ const decode = (params2, decodedAttrs = {}) => {
30530
+ const result = {
30531
+ name: "w:bookmarkEnd",
30532
+ elements: []
30533
+ };
30534
+ if (decodedAttrs && Object.keys(decodedAttrs).length) {
30535
+ result.attributes = decodedAttrs;
30536
+ }
30537
+ return result;
30538
+ };
29247
30539
  const config = {
29248
30540
  xmlName: XML_NODE_NAME,
29249
30541
  sdNodeOrKeyName: SD_NODE_NAME,
29250
30542
  type: NodeTranslator.translatorTypes.NODE,
29251
- encode: encode$B,
30543
+ encode: encode$18,
29252
30544
  decode,
29253
30545
  attributes: validXmlAttributes
29254
30546
  };
29255
30547
  const translator = NodeTranslator.from(config);
30548
+ const isLineBreakOnlyRun = (node) => {
30549
+ if (!node) return false;
30550
+ if (node.type === "lineBreak" || node.type === "hardBreak") return true;
30551
+ if (node.type !== "run") return false;
30552
+ const runContent = Array.isArray(node.content) ? node.content : [];
30553
+ if (!runContent.length) return false;
30554
+ return runContent.every((child) => child?.type === "lineBreak" || child?.type === "hardBreak");
30555
+ };
29256
30556
  function exportSchemaToJson(params2) {
29257
30557
  const { type: type2 } = params2.node || {};
29258
30558
  const router = {
29259
30559
  doc: translateDocumentNode,
29260
30560
  body: translateBodyNode,
29261
30561
  heading: translateHeadingNode,
29262
- paragraph: translator$T,
30562
+ paragraph: translator$12,
30563
+ run: translator$T,
29263
30564
  text: translateTextNode,
29264
30565
  bulletList: translateList,
29265
30566
  orderedList: translateList,
29266
- lineBreak: translator$V,
30567
+ lineBreak: translator$15,
29267
30568
  table: translator$8,
29268
30569
  tableRow: translator$F,
29269
30570
  tableCell: translator$7,
29270
- bookmarkStart: translator$3,
29271
- bookmarkEnd: translator$2,
29272
- fieldAnnotation: translator,
29273
- tab: translator$U,
29274
- image: translator$1,
29275
- hardBreak: translator$V,
30571
+ bookmarkStart: translator$1,
30572
+ bookmarkEnd: translator,
30573
+ fieldAnnotation: translator$2,
30574
+ tab: translator$13,
30575
+ image: translator$3,
30576
+ hardBreak: translator$15,
29276
30577
  commentRangeStart: () => translateCommentNode(params2, "Start"),
29277
30578
  commentRangeEnd: () => translateCommentNode(params2, "End"),
29278
30579
  commentReference: () => null,
29279
30580
  shapeContainer: translateShapeContainer,
29280
30581
  shapeTextbox: translateShapeTextbox,
29281
30582
  contentBlock: translateContentBlock,
29282
- structuredContent: translator,
29283
- structuredContentBlock: translator,
29284
- documentSection: translator,
30583
+ structuredContent: translator$2,
30584
+ structuredContentBlock: translator$2,
30585
+ documentSection: translator$2,
29285
30586
  "page-number": translatePageNumberNode,
29286
30587
  "total-page-number": translateTotalPageNumberNode
29287
30588
  };
@@ -29420,21 +30721,32 @@ function generateParagraphProperties(node) {
29420
30721
  };
29421
30722
  pPrElements.push(spacingElement);
29422
30723
  }
29423
- if (indent && Object.values(indent).some((v2) => v2 !== 0)) {
29424
- const { left: left2, right: right2, firstLine, hanging } = indent;
30724
+ const hasIndent = !!indent;
30725
+ if (hasIndent) {
30726
+ const { left: left2, right: right2, firstLine, hanging, explicitLeft, explicitRight, explicitFirstLine, explicitHanging } = indent;
29425
30727
  const attributes = {};
29426
- if (left2 || left2 === 0) attributes["w:left"] = pixelsToTwips(left2);
29427
- if (right2 || right2 === 0) attributes["w:right"] = pixelsToTwips(right2);
29428
- if (firstLine || firstLine === 0) attributes["w:firstLine"] = pixelsToTwips(firstLine);
29429
- if (hanging || hanging === 0) attributes["w:hanging"] = pixelsToTwips(hanging);
29430
- if (textIndent && !attributes["w:left"]) {
30728
+ if (left2 !== void 0 && (left2 !== 0 || explicitLeft || textIndent)) {
30729
+ attributes["w:left"] = pixelsToTwips(left2);
30730
+ }
30731
+ if (right2 !== void 0 && (right2 !== 0 || explicitRight)) {
30732
+ attributes["w:right"] = pixelsToTwips(right2);
30733
+ }
30734
+ if (firstLine !== void 0 && (firstLine !== 0 || explicitFirstLine)) {
30735
+ attributes["w:firstLine"] = pixelsToTwips(firstLine);
30736
+ }
30737
+ if (hanging !== void 0 && (hanging !== 0 || explicitHanging)) {
30738
+ attributes["w:hanging"] = pixelsToTwips(hanging);
30739
+ }
30740
+ if (textIndent && attributes["w:left"] === void 0) {
29431
30741
  attributes["w:left"] = getTextIndentExportValue(textIndent);
29432
30742
  }
29433
- const indentElement = {
29434
- name: "w:ind",
29435
- attributes
29436
- };
29437
- pPrElements.push(indentElement);
30743
+ if (Object.keys(attributes).length) {
30744
+ const indentElement = {
30745
+ name: "w:ind",
30746
+ attributes
30747
+ };
30748
+ pPrElements.push(indentElement);
30749
+ }
29438
30750
  } else if (textIndent && textIndent !== "0in") {
29439
30751
  const indentElement = {
29440
30752
  name: "w:ind",
@@ -29484,12 +30796,17 @@ function generateParagraphProperties(node) {
29484
30796
  if (sectPr) {
29485
30797
  pPrElements.push(sectPr);
29486
30798
  }
30799
+ const mapTabVal = (value) => {
30800
+ if (!value || value === "start") return "left";
30801
+ if (value === "end") return "right";
30802
+ return value;
30803
+ };
29487
30804
  const { tabStops } = attrs;
29488
30805
  if (tabStops && tabStops.length > 0) {
29489
30806
  const tabElements = tabStops.map((tab) => {
29490
30807
  const posValue = tab.originalPos !== void 0 ? tab.originalPos : pixelsToTwips(tab.pos).toString();
29491
30808
  const tabAttributes = {
29492
- "w:val": tab.val || "start",
30809
+ "w:val": mapTabVal(tab.val),
29493
30810
  "w:pos": posValue
29494
30811
  };
29495
30812
  if (tab.leader) {
@@ -29844,6 +31161,11 @@ const convertMultipleListItemsIntoSingleNode = (listItem) => {
29844
31161
  collapsedParagraph.content.push(item);
29845
31162
  }
29846
31163
  });
31164
+ collapsedParagraph.content = collapsedParagraph.content.filter((node, index2, nodes) => {
31165
+ if (!isLineBreakOnlyRun(node)) return true;
31166
+ const prevNode = nodes[index2 - 1];
31167
+ return !(prevNode && isLineBreakOnlyRun(prevNode));
31168
+ });
29847
31169
  return collapsedParagraph;
29848
31170
  };
29849
31171
  const restoreIndent = (indent) => {
@@ -29897,13 +31219,27 @@ function translateMark(mark) {
29897
31219
  markElement.type = "element";
29898
31220
  break;
29899
31221
  case "italic":
29900
- delete markElement.attributes;
29901
- markElement.type = "element";
29902
- break;
29903
- case "underline":
31222
+ if (attrs?.value && attrs.value !== "1" && attrs.value !== true) {
31223
+ markElement.attributes["w:val"] = attrs.value;
31224
+ } else {
31225
+ delete markElement.attributes;
31226
+ }
29904
31227
  markElement.type = "element";
29905
- markElement.attributes["w:val"] = attrs.underlineType;
29906
31228
  break;
31229
+ case "underline": {
31230
+ const translated = translator$$.decode({
31231
+ node: {
31232
+ attrs: {
31233
+ underlineType: attrs.underlineType ?? attrs.underline ?? null,
31234
+ underlineColor: attrs.underlineColor ?? attrs.color ?? null,
31235
+ underlineThemeColor: attrs.underlineThemeColor ?? attrs.themeColor ?? null,
31236
+ underlineThemeTint: attrs.underlineThemeTint ?? attrs.themeTint ?? null,
31237
+ underlineThemeShade: attrs.underlineThemeShade ?? attrs.themeShade ?? null
31238
+ }
31239
+ }
31240
+ });
31241
+ return translated || {};
31242
+ }
29907
31243
  // Text style cases
29908
31244
  case "fontSize":
29909
31245
  value = attrs.fontSize;
@@ -29921,13 +31257,21 @@ function translateMark(mark) {
29921
31257
  markElement.name = "w:rStyle";
29922
31258
  markElement.attributes["w:val"] = attrs.styleId;
29923
31259
  break;
29924
- case "color":
29925
- let processedColor = attrs.color.replace(/^#/, "").replace(/;$/, "");
31260
+ case "color": {
31261
+ const rawColor = attrs.color;
31262
+ if (!rawColor) break;
31263
+ const normalized = String(rawColor).trim().toLowerCase();
31264
+ if (normalized === "inherit") {
31265
+ markElement.attributes["w:val"] = "auto";
31266
+ break;
31267
+ }
31268
+ let processedColor = String(rawColor).replace(/^#/, "").replace(/;$/, "");
29926
31269
  if (processedColor.startsWith("rgb")) {
29927
31270
  processedColor = rgbToHex(processedColor);
29928
31271
  }
29929
31272
  markElement.attributes["w:val"] = processedColor;
29930
31273
  break;
31274
+ }
29931
31275
  case "textAlign":
29932
31276
  markElement.attributes["w:val"] = attrs.textAlign;
29933
31277
  break;
@@ -29945,12 +31289,11 @@ function translateMark(mark) {
29945
31289
  case "lineHeight":
29946
31290
  markElement.attributes["w:line"] = linesToTwips(attrs.lineHeight);
29947
31291
  break;
29948
- case "highlight":
29949
- markElement.attributes["w:fill"] = attrs.color?.substring(1);
29950
- markElement.attributes["w:color"] = "auto";
29951
- markElement.attributes["w:val"] = "clear";
29952
- markElement.name = "w:shd";
29953
- break;
31292
+ case "highlight": {
31293
+ const highlightValue = attrs.color ?? attrs.highlight ?? null;
31294
+ const translated = translator$14.decode({ node: { attrs: { highlight: highlightValue } } });
31295
+ return translated || {};
31296
+ }
29954
31297
  }
29955
31298
  return markElement;
29956
31299
  }
@@ -30081,8 +31424,8 @@ generate_xml_as_list_fn = function(data, debug = false) {
30081
31424
  return final;
30082
31425
  };
30083
31426
  replaceSpecialCharacters_fn = function(text) {
30084
- if (!text) return;
30085
- return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
31427
+ if (text === void 0 || text === null) return text;
31428
+ return String(text).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
30086
31429
  };
30087
31430
  generateXml_fn = function(node) {
30088
31431
  if (!node) return null;
@@ -30098,7 +31441,7 @@ generateXml_fn = function(node) {
30098
31441
  else tag += ">";
30099
31442
  let tags = [tag];
30100
31443
  if (!name && node.type === "text") {
30101
- return node.text;
31444
+ return __privateMethod$2(this, _DocxExporter_instances, replaceSpecialCharacters_fn).call(this, node.text ?? "");
30102
31445
  }
30103
31446
  if (elements) {
30104
31447
  if (name === "w:instrText") {
@@ -30224,7 +31567,7 @@ const handleDrawingNode = (params2) => {
30224
31567
  if (mainNode.name === "w:drawing") node = mainNode;
30225
31568
  else node = mainNode.elements.find((el) => el.name === "w:drawing");
30226
31569
  if (!node) return { nodes: [], consumed: 0 };
30227
- const schemaNode = translator$1.encode(params2);
31570
+ const schemaNode = translator$3.encode(params2);
30228
31571
  const newNodes = schemaNode ? [schemaNode] : [];
30229
31572
  return { nodes: newNodes, consumed: 1 };
30230
31573
  };
@@ -30327,81 +31670,7 @@ const trackChangeNodeHandlerEntity = {
30327
31670
  handler: handleTrackChangeNode
30328
31671
  };
30329
31672
  const hyperlinkNodeHandlerEntity = generateV2HandlerEntity("hyperlinkNodeHandler", translator$6);
30330
- const handleRunNode = (params2) => {
30331
- const { nodes, nodeListHandler, parentStyleId, docx } = params2;
30332
- if (nodes.length === 0 || nodes[0].name !== "w:r") {
30333
- return { nodes: [], consumed: 0 };
30334
- }
30335
- const node = nodes[0];
30336
- const childParams = { ...params2, nodes: node.elements, path: [...params2.path || [], node] };
30337
- let processedRun = nodeListHandler.handler(childParams)?.filter((n) => n) || [];
30338
- const hasRunProperties = node.elements?.some((el) => el.name === "w:rPr");
30339
- const defaultNodeStyles = getMarksFromStyles(docx, parentStyleId);
30340
- if (hasRunProperties) {
30341
- const { marks = [] } = parseProperties(node);
30342
- let runStyleAttributes = [];
30343
- const runStyleElement = node.elements?.find((el) => el.name === "w:rPr")?.elements?.find((el) => el.name === "w:rStyle");
30344
- let runStyleId;
30345
- if (runStyleElement && runStyleElement.attributes?.["w:val"] && docx) {
30346
- runStyleId = runStyleElement.attributes["w:val"];
30347
- const runStyleDefinition = getMarksFromStyles(docx, runStyleId);
30348
- if (runStyleDefinition.marks && runStyleDefinition.marks.length > 0) {
30349
- runStyleAttributes = runStyleDefinition.marks;
30350
- }
30351
- }
30352
- let paragraphStyleAttributes = [];
30353
- if (defaultNodeStyles.marks) {
30354
- paragraphStyleAttributes = defaultNodeStyles.marks.filter((mark) => {
30355
- if (["bold"].includes(mark.type) && marks.find((m2) => m2.type === "bold")?.attrs?.value === "0") {
30356
- return false;
30357
- }
30358
- return true;
30359
- });
30360
- }
30361
- const combinedMarks = [...paragraphStyleAttributes];
30362
- runStyleAttributes.forEach((runStyle) => {
30363
- const exists2 = combinedMarks.some(
30364
- (mark) => mark.type === runStyle.type && JSON.stringify(mark.attrs || {}) === JSON.stringify(runStyle.attrs || {})
30365
- );
30366
- if (!exists2) {
30367
- combinedMarks.push(runStyle);
30368
- }
30369
- });
30370
- marks.forEach((mark) => {
30371
- const exists2 = combinedMarks.some(
30372
- (existing) => existing.type === mark.type && JSON.stringify(existing.attrs || {}) === JSON.stringify(mark.attrs || {})
30373
- );
30374
- if (!exists2) {
30375
- combinedMarks.push(mark);
30376
- }
30377
- });
30378
- if (runStyleId) combinedMarks.push({ type: "textStyle", attrs: { styleId: runStyleId } });
30379
- if (node.marks) combinedMarks.push(...node.marks);
30380
- const newMarks = createImportMarks(combinedMarks);
30381
- processedRun = processedRun.map((n) => {
30382
- const existingMarks = n.marks || [];
30383
- return {
30384
- ...n,
30385
- marks: [...newMarks, ...existingMarks]
30386
- };
30387
- });
30388
- }
30389
- return { nodes: processedRun, consumed: 1 };
30390
- };
30391
- const getMarksFromStyles = (docx, styleId) => {
30392
- const styles = docx?.["word/styles.xml"];
30393
- if (!styles) {
30394
- return {};
30395
- }
30396
- const styleTags = styles.elements[0].elements.filter((style22) => style22.name === "w:style");
30397
- const style2 = styleTags.find((tag) => tag.attributes["w:styleId"] === styleId) || {};
30398
- if (!style2) return {};
30399
- return parseProperties(style2);
30400
- };
30401
- const runNodeHandlerEntity = {
30402
- handlerName: "runNodeHandler",
30403
- handler: handleRunNode
30404
- };
31673
+ const runNodeHandlerEntity = generateV2HandlerEntity("runNodeHandler", translator$T);
30405
31674
  const handleTextNode = (params2) => {
30406
31675
  const { nodes, insideTrackChange } = params2;
30407
31676
  if (nodes.length === 0 || !(nodes[0].name === "w:t" || insideTrackChange && nodes[0].name === "w:delText")) {
@@ -30413,6 +31682,10 @@ const handleTextNode = (params2) => {
30413
31682
  let text;
30414
31683
  if (elements.length === 1) {
30415
31684
  text = elements[0].text;
31685
+ const xmlSpace = node.attributes?.["xml:space"] ?? elements[0]?.attributes?.["xml:space"];
31686
+ if (xmlSpace !== "preserve" && typeof text === "string") {
31687
+ text = text.replace(/^\s+/, "").replace(/\s+$/, "");
31688
+ }
30416
31689
  text = text.replace(/\[\[sdspace\]\]/g, "");
30417
31690
  } else if (!elements.length && "attributes" in node && node.attributes["xml:space"] === "preserve") {
30418
31691
  text = " ";
@@ -30438,7 +31711,7 @@ const handleParagraphNode = (params2) => {
30438
31711
  if (nodes.length === 0 || nodes[0].name !== "w:p") {
30439
31712
  return { nodes: [], consumed: 0 };
30440
31713
  }
30441
- const schemaNode = translator$T.encode(params2);
31714
+ const schemaNode = translator$12.encode(params2);
30442
31715
  const newNodes = schemaNode ? [schemaNode] : [];
30443
31716
  return { nodes: newNodes, consumed: 1 };
30444
31717
  };
@@ -30451,7 +31724,7 @@ const handleSdtNode = (params2) => {
30451
31724
  if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
30452
31725
  return { nodes: [], consumed: 0 };
30453
31726
  }
30454
- const result = translator.encode(params2);
31727
+ const result = translator$2.encode(params2);
30455
31728
  if (!result) {
30456
31729
  return { nodes: [], consumed: 0 };
30457
31730
  }
@@ -30541,7 +31814,7 @@ const handler = (params2) => {
30541
31814
  if (nodes.length === 0 || nodes[0].name !== "w:br") {
30542
31815
  return { nodes: [], consumed: 0 };
30543
31816
  }
30544
- const result = translator$V.encode(params2);
31817
+ const result = translator$15.encode(params2);
30545
31818
  if (!result) return { nodes: [], consumed: 0 };
30546
31819
  return {
30547
31820
  nodes: [result],
@@ -30613,7 +31886,7 @@ const handleBookmarkStartNode = (params2) => {
30613
31886
  if (isCustomMarkBookmark(nodes[0], params2.editor)) {
30614
31887
  return handleBookmarkNode(params2);
30615
31888
  }
30616
- const node = translator$3.encode(params2);
31889
+ const node = translator$1.encode(params2);
30617
31890
  if (!node) return { nodes: [], consumed: 0 };
30618
31891
  return { nodes: [node], consumed: 1 };
30619
31892
  };
@@ -30645,7 +31918,7 @@ const handleBookmarkEndNode = (params2) => {
30645
31918
  if (!nodes.length || nodes[0].name !== "w:bookmarkEnd") {
30646
31919
  return { nodes: [], consumed: 0 };
30647
31920
  }
30648
- const node = translator$2.encode(params2);
31921
+ const node = translator.encode(params2);
30649
31922
  if (!node) return { nodes: [], consumed: 0 };
30650
31923
  return { nodes: [node], consumed: 1 };
30651
31924
  };
@@ -31284,7 +32557,7 @@ const handleTabNode = (params2) => {
31284
32557
  if (!nodes.length || nodes[0].name !== "w:tab") {
31285
32558
  return { nodes: [], consumed: 0 };
31286
32559
  }
31287
- const node = translator$U.encode(params2);
32560
+ const node = translator$13.encode(params2);
31288
32561
  return { nodes: [node], consumed: 1 };
31289
32562
  };
31290
32563
  const tabNodeEntityHandler = {
@@ -31733,6 +33006,16 @@ const isAlternatingHeadersOddEven = (docx) => {
31733
33006
  };
31734
33007
  const HYPERLINK_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
31735
33008
  const HEADER_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header";
33009
+ const FONT_FAMILY_FALLBACKS = Object.freeze({
33010
+ swiss: "Arial, sans-serif",
33011
+ roman: "Times New Roman, serif",
33012
+ modern: "Courier New, monospace",
33013
+ script: "cursive",
33014
+ decorative: "fantasy",
33015
+ system: "system-ui",
33016
+ auto: "sans-serif"
33017
+ });
33018
+ const DEFAULT_GENERIC_FALLBACK = "sans-serif";
31736
33019
  const _SuperConverter = class _SuperConverter2 {
31737
33020
  constructor(params2 = null) {
31738
33021
  __privateAdd$2(this, _SuperConverter_instances);
@@ -31768,6 +33051,31 @@ const _SuperConverter = class _SuperConverter2 {
31768
33051
  this.documentId = params2?.documentId || null;
31769
33052
  if (this.docx.length || this.xml) this.parseFromXml();
31770
33053
  }
33054
+ static getFontTableEntry(docx, fontName) {
33055
+ if (!docx || !fontName) return null;
33056
+ const fontTable = docx["word/fontTable.xml"];
33057
+ if (!fontTable?.elements?.length) return null;
33058
+ const fontsNode = fontTable.elements.find((el) => el.name === "w:fonts");
33059
+ if (!fontsNode?.elements?.length) return null;
33060
+ return fontsNode.elements.find((el) => el?.attributes?.["w:name"] === fontName) || null;
33061
+ }
33062
+ static getFallbackFromFontTable(docx, fontName) {
33063
+ const fontEntry = _SuperConverter2.getFontTableEntry(docx, fontName);
33064
+ const family = fontEntry?.elements?.find((child) => child.name === "w:family")?.attributes?.["w:val"];
33065
+ if (!family) return null;
33066
+ const mapped = FONT_FAMILY_FALLBACKS[family.toLowerCase()];
33067
+ return mapped || DEFAULT_GENERIC_FALLBACK;
33068
+ }
33069
+ static toCssFontFamily(fontName, docx) {
33070
+ if (!fontName) return fontName;
33071
+ if (fontName.includes(",")) return fontName;
33072
+ const fallback = _SuperConverter2.getFallbackFromFontTable(docx, fontName) || DEFAULT_GENERIC_FALLBACK;
33073
+ const normalizedFallbackParts = fallback.split(",").map((part) => part.trim().toLowerCase()).filter(Boolean);
33074
+ if (normalizedFallbackParts.includes(fontName.trim().toLowerCase())) {
33075
+ return fallback;
33076
+ }
33077
+ return `${fontName}, ${fallback}`;
33078
+ }
31771
33079
  /**
31772
33080
  * Get the DocxHelpers object that contains utility functions for working with docx files.
31773
33081
  * @returns {import('./docx-helpers/docx-helpers.js').DocxHelpers} The DocxHelpers object.
@@ -31813,7 +33121,7 @@ const _SuperConverter = class _SuperConverter2 {
31813
33121
  return;
31814
33122
  }
31815
33123
  }
31816
- static updateDocumentVersion(docx = this.convertedXml, version2 = "0.20.0") {
33124
+ static updateDocumentVersion(docx = this.convertedXml, version2 = "0.20.0-next.13") {
31817
33125
  const customLocation = "docProps/custom.xml";
31818
33126
  if (!docx[customLocation]) {
31819
33127
  docx[customLocation] = generateCustomXml();
@@ -31864,13 +33172,19 @@ const _SuperConverter = class _SuperConverter2 {
31864
33172
  if (rPrDefaults) {
31865
33173
  const rPr = rPrDefaults.elements?.find((el) => el.name === "w:rPr");
31866
33174
  const fonts = rPr?.elements?.find((el) => el.name === "w:rFonts");
31867
- typeface = fonts?.attributes["w:ascii"];
31868
- const fontSize2 = typeface ?? rPr?.elements?.find((el) => el.name === "w:sz")?.attributes["w:val"];
31869
- fontSizeNormal = !fontSizeNormal && fontSize2 ? Number(fontSize2) / 2 : null;
33175
+ if (fonts?.attributes?.["w:ascii"]) {
33176
+ typeface = fonts.attributes["w:ascii"];
33177
+ }
33178
+ const fontSizeRaw = rPr?.elements?.find((el) => el.name === "w:sz")?.attributes?.["w:val"];
33179
+ if (!fontSizeNormal && fontSizeRaw) {
33180
+ fontSizeNormal = Number(fontSizeRaw) / 2;
33181
+ }
31870
33182
  }
31871
- const fontSizePt = fontSizeNormal || Number(rElements.find((el) => el.name === "w:sz")?.attributes["w:val"]) / 2 || 10;
33183
+ const fallbackSz = Number(rElements.find((el) => el.name === "w:sz")?.attributes?.["w:val"]);
33184
+ const fontSizePt = fontSizeNormal ?? (Number.isFinite(fallbackSz) ? fallbackSz / 2 : void 0) ?? 10;
31872
33185
  const kern = rElements.find((el) => el.name === "w:kern")?.attributes["w:val"];
31873
- return { fontSizePt, kern, typeface, panose };
33186
+ const fontFamilyCss = _SuperConverter2.toCssFontFamily(typeface, this.convertedXml);
33187
+ return { fontSizePt, kern, typeface, panose, fontFamilyCss };
31874
33188
  }
31875
33189
  }
31876
33190
  getDocumentFonts() {
@@ -32300,7 +33614,7 @@ function storeSuperdocVersion(docx) {
32300
33614
  function generateCustomXml() {
32301
33615
  return DEFAULT_CUSTOM_XML;
32302
33616
  }
32303
- function generateSuperdocVersion(pid = 2, version2 = "0.20.0") {
33617
+ function generateSuperdocVersion(pid = 2, version2 = "0.20.0-next.13") {
32304
33618
  return {
32305
33619
  type: "element",
32306
33620
  name: "property",
@@ -33771,15 +35085,15 @@ function requireJszip_min() {
33771
35085
  function M2(e2, t2, r22, n2, i2) {
33772
35086
  this.good_length = e2, this.max_lazy = t2, this.nice_length = r22, this.max_chain = n2, this.func = i2;
33773
35087
  }
33774
- function H2() {
35088
+ function H() {
33775
35089
  this.strm = null, this.status = 0, this.pending_buf = null, this.pending_buf_size = 0, this.pending_out = 0, this.pending = 0, this.wrap = 0, this.gzhead = null, this.gzindex = 0, this.method = v2, this.last_flush = -1, this.w_size = 0, this.w_bits = 0, this.w_mask = 0, this.window = null, this.window_size = 0, this.prev = null, this.head = null, this.ins_h = 0, this.hash_size = 0, this.hash_bits = 0, this.hash_mask = 0, this.hash_shift = 0, this.block_start = 0, this.match_length = 0, this.prev_match = 0, this.match_available = 0, this.strstart = 0, this.match_start = 0, this.lookahead = 0, this.prev_length = 0, this.max_chain_length = 0, this.max_lazy_match = 0, this.level = 0, this.strategy = 0, this.good_match = 0, this.nice_match = 0, this.dyn_ltree = new c2.Buf16(2 * w2), this.dyn_dtree = new c2.Buf16(2 * (2 * a + 1)), this.bl_tree = new c2.Buf16(2 * (2 * o + 1)), D2(this.dyn_ltree), D2(this.dyn_dtree), D2(this.bl_tree), this.l_desc = null, this.d_desc = null, this.bl_desc = null, this.bl_count = new c2.Buf16(k + 1), this.heap = new c2.Buf16(2 * s + 1), D2(this.heap), this.heap_len = 0, this.heap_max = 0, this.depth = new c2.Buf16(2 * s + 1), D2(this.depth), this.l_buf = 0, this.lit_bufsize = 0, this.last_lit = 0, this.d_buf = 0, this.opt_len = 0, this.static_len = 0, this.matches = 0, this.insert = 0, this.bi_buf = 0, this.bi_valid = 0;
33776
35090
  }
33777
- function G(e2) {
35091
+ function G2(e2) {
33778
35092
  var t2;
33779
35093
  return e2 && e2.state ? (e2.total_in = e2.total_out = 0, e2.data_type = i, (t2 = e2.state).pending = 0, t2.pending_out = 0, t2.wrap < 0 && (t2.wrap = -t2.wrap), t2.status = t2.wrap ? C2 : E2, e2.adler = 2 === t2.wrap ? 0 : 1, t2.last_flush = l3, u._tr_init(t2), m2) : R2(e2, _2);
33780
35094
  }
33781
35095
  function K2(e2) {
33782
- var t2 = G(e2);
35096
+ var t2 = G2(e2);
33783
35097
  return t2 === m2 && (function(e3) {
33784
35098
  e3.window_size = 2 * e3.w_size, D2(e3.head), e3.max_lazy_match = h2[e3.level].max_lazy, e3.good_match = h2[e3.level].good_length, e3.nice_match = h2[e3.level].nice_length, e3.max_chain_length = h2[e3.level].max_chain, e3.strstart = 0, e3.block_start = 0, e3.lookahead = 0, e3.insert = 0, e3.match_length = e3.prev_length = x - 1, e3.match_available = 0, e3.ins_h = 0;
33785
35099
  })(e2.state), t2;
@@ -33789,7 +35103,7 @@ function requireJszip_min() {
33789
35103
  var a2 = 1;
33790
35104
  if (t2 === g && (t2 = 6), n2 < 0 ? (a2 = 0, n2 = -n2) : 15 < n2 && (a2 = 2, n2 -= 16), i2 < 1 || y2 < i2 || r22 !== v2 || n2 < 8 || 15 < n2 || t2 < 0 || 9 < t2 || s2 < 0 || b2 < s2) return R2(e2, _2);
33791
35105
  8 === n2 && (n2 = 9);
33792
- var o2 = new H2();
35106
+ var o2 = new H();
33793
35107
  return (e2.state = o2).strm = e2, o2.wrap = a2, o2.gzhead = null, o2.w_bits = n2, o2.w_size = 1 << o2.w_bits, o2.w_mask = o2.w_size - 1, o2.hash_bits = i2 + 7, o2.hash_size = 1 << o2.hash_bits, o2.hash_mask = o2.hash_size - 1, o2.hash_shift = ~~((o2.hash_bits + x - 1) / x), o2.window = new c2.Buf8(2 * o2.w_size), o2.head = new c2.Buf16(o2.hash_size), o2.prev = new c2.Buf16(o2.w_size), o2.lit_bufsize = 1 << i2 + 6, o2.pending_buf_size = 4 * o2.lit_bufsize, o2.pending_buf = new c2.Buf8(o2.pending_buf_size), o2.d_buf = 1 * o2.lit_bufsize, o2.l_buf = 3 * o2.lit_bufsize, o2.level = t2, o2.strategy = s2, o2.method = r22, K2(e2);
33794
35108
  }
33795
35109
  h2 = [new M2(0, 0, 0, 0, function(e2, t2) {
@@ -33807,7 +35121,7 @@ function requireJszip_min() {
33807
35121
  return e2.insert = 0, t2 === f ? (N2(e2, true), 0 === e2.strm.avail_out ? O2 : B2) : (e2.strstart > e2.block_start && (N2(e2, false), e2.strm.avail_out), A);
33808
35122
  }), new M2(4, 4, 8, 4, Z), new M2(4, 5, 16, 8, Z), new M2(4, 6, 32, 32, Z), new M2(4, 4, 16, 16, W2), new M2(8, 16, 32, 32, W2), new M2(8, 16, 128, 128, W2), new M2(8, 32, 128, 256, W2), new M2(32, 128, 258, 1024, W2), new M2(32, 258, 258, 4096, W2)], r2.deflateInit = function(e2, t2) {
33809
35123
  return Y2(e2, t2, v2, 15, 8, 0);
33810
- }, r2.deflateInit2 = Y2, r2.deflateReset = K2, r2.deflateResetKeep = G, r2.deflateSetHeader = function(e2, t2) {
35124
+ }, r2.deflateInit2 = Y2, r2.deflateReset = K2, r2.deflateResetKeep = G2, r2.deflateSetHeader = function(e2, t2) {
33811
35125
  return e2 && e2.state ? 2 !== e2.state.wrap ? _2 : (e2.state.gzhead = t2, m2) : _2;
33812
35126
  }, r2.deflate = function(e2, t2) {
33813
35127
  var r22, n2, i2, s2;
@@ -34463,12 +35777,12 @@ function requireJszip_min() {
34463
35777
  function M2(e2) {
34464
35778
  8 < e2.bi_valid ? U2(e2, e2.bi_buf) : 0 < e2.bi_valid && (e2.pending_buf[e2.pending++] = e2.bi_buf), e2.bi_buf = 0, e2.bi_valid = 0;
34465
35779
  }
34466
- function H2(e2, t2, r22, n2) {
35780
+ function H(e2, t2, r22, n2) {
34467
35781
  var i2 = 2 * t2, s2 = 2 * r22;
34468
35782
  return e2[i2] < e2[s2] || e2[i2] === e2[s2] && n2[t2] <= n2[r22];
34469
35783
  }
34470
- function G(e2, t2, r22) {
34471
- for (var n2 = e2.heap[r22], i2 = r22 << 1; i2 <= e2.heap_len && (i2 < e2.heap_len && H2(t2, e2.heap[i2 + 1], e2.heap[i2], e2.depth) && i2++, !H2(t2, n2, e2.heap[i2], e2.depth)); ) e2.heap[r22] = e2.heap[i2], r22 = i2, i2 <<= 1;
35784
+ function G2(e2, t2, r22) {
35785
+ for (var n2 = e2.heap[r22], i2 = r22 << 1; i2 <= e2.heap_len && (i2 < e2.heap_len && H(t2, e2.heap[i2 + 1], e2.heap[i2], e2.depth) && i2++, !H(t2, n2, e2.heap[i2], e2.depth)); ) e2.heap[r22] = e2.heap[i2], r22 = i2, i2 <<= 1;
34472
35786
  e2.heap[r22] = n2;
34473
35787
  }
34474
35788
  function K2(e2, t2, r22) {
@@ -34480,8 +35794,8 @@ function requireJszip_min() {
34480
35794
  var r22, n2, i2, s2 = t2.dyn_tree, a2 = t2.stat_desc.static_tree, o2 = t2.stat_desc.has_stree, h22 = t2.stat_desc.elems, u2 = -1;
34481
35795
  for (e2.heap_len = 0, e2.heap_max = _2, r22 = 0; r22 < h22; r22++) 0 !== s2[2 * r22] ? (e2.heap[++e2.heap_len] = u2 = r22, e2.depth[r22] = 0) : s2[2 * r22 + 1] = 0;
34482
35796
  for (; e2.heap_len < 2; ) s2[2 * (i2 = e2.heap[++e2.heap_len] = u2 < 2 ? ++u2 : 0)] = 1, e2.depth[i2] = 0, e2.opt_len--, o2 && (e2.static_len -= a2[2 * i2 + 1]);
34483
- for (t2.max_code = u2, r22 = e2.heap_len >> 1; 1 <= r22; r22--) G(e2, s2, r22);
34484
- for (i2 = h22; r22 = e2.heap[1], e2.heap[1] = e2.heap[e2.heap_len--], G(e2, s2, 1), n2 = e2.heap[1], e2.heap[--e2.heap_max] = r22, e2.heap[--e2.heap_max] = n2, s2[2 * i2] = s2[2 * r22] + s2[2 * n2], e2.depth[i2] = (e2.depth[r22] >= e2.depth[n2] ? e2.depth[r22] : e2.depth[n2]) + 1, s2[2 * r22 + 1] = s2[2 * n2 + 1] = i2, e2.heap[1] = i2++, G(e2, s2, 1), 2 <= e2.heap_len; ) ;
35797
+ for (t2.max_code = u2, r22 = e2.heap_len >> 1; 1 <= r22; r22--) G2(e2, s2, r22);
35798
+ for (i2 = h22; r22 = e2.heap[1], e2.heap[1] = e2.heap[e2.heap_len--], G2(e2, s2, 1), n2 = e2.heap[1], e2.heap[--e2.heap_max] = r22, e2.heap[--e2.heap_max] = n2, s2[2 * i2] = s2[2 * r22] + s2[2 * n2], e2.depth[i2] = (e2.depth[r22] >= e2.depth[n2] ? e2.depth[r22] : e2.depth[n2]) + 1, s2[2 * r22 + 1] = s2[2 * n2 + 1] = i2, e2.heap[1] = i2++, G2(e2, s2, 1), 2 <= e2.heap_len; ) ;
34485
35799
  e2.heap[--e2.heap_max] = e2.heap[1], (function(e3, t3) {
34486
35800
  var r3, n3, i3, s3, a3, o3, h3 = t3.dyn_tree, u3 = t3.max_code, l22 = t3.stat_desc.static_tree, f2 = t3.stat_desc.has_stree, c22 = t3.stat_desc.extra_bits, d22 = t3.stat_desc.extra_base, p2 = t3.stat_desc.max_length, m22 = 0;
34487
35801
  for (s3 = 0; s3 <= g; s3++) e3.bl_count[s3] = 0;
@@ -41043,19 +42357,19 @@ class Hasher {
41043
42357
  this._W = new Uint32Array(buf, 64, 64);
41044
42358
  }
41045
42359
  _updateHash() {
41046
- const H2 = this._H;
42360
+ const H = this._H;
41047
42361
  const W2 = this._W;
41048
42362
  for (let t = 16; t < 64; t++) {
41049
42363
  W2[t] = sigma1to256(W2[t - 2]) + W2[t - 7] + sigma0to256(W2[t - 15]) + W2[t - 16];
41050
42364
  }
41051
- let a = H2[0];
41052
- let b2 = H2[1];
41053
- let c2 = H2[2];
41054
- let d2 = H2[3];
41055
- let e = H2[4];
41056
- let f = H2[5];
41057
- let g = H2[6];
41058
- let h2 = H2[7];
42365
+ let a = H[0];
42366
+ let b2 = H[1];
42367
+ let c2 = H[2];
42368
+ let d2 = H[3];
42369
+ let e = H[4];
42370
+ let f = H[5];
42371
+ let g = H[6];
42372
+ let h2 = H[7];
41059
42373
  for (let tt = 0, T1, T2; tt < 64; tt++) {
41060
42374
  T1 = h2 + sum1to256(e) + (e & f ^ ~e & g) + K[tt] + W2[tt] >>> 0;
41061
42375
  T2 = sum0to256(a) + (a & b2 ^ a & c2 ^ b2 & c2) >>> 0;
@@ -41068,14 +42382,14 @@ class Hasher {
41068
42382
  b2 = a;
41069
42383
  a = T1 + T2 >>> 0;
41070
42384
  }
41071
- H2[0] += a;
41072
- H2[1] += b2;
41073
- H2[2] += c2;
41074
- H2[3] += d2;
41075
- H2[4] += e;
41076
- H2[5] += f;
41077
- H2[6] += g;
41078
- H2[7] += h2;
42385
+ H[0] += a;
42386
+ H[1] += b2;
42387
+ H[2] += c2;
42388
+ H[3] += d2;
42389
+ H[4] += e;
42390
+ H[5] += f;
42391
+ H[6] += g;
42392
+ H[7] += h2;
41079
42393
  }
41080
42394
  /**
41081
42395
  * Returns a 32-byte hash.
@@ -43707,6 +45021,96 @@ const toggleMark = (typeOrName, attrs = {}, options = {}) => ({ state: state2, c
43707
45021
  if (isActive2) return commands2.unsetMark(type2, { extendEmptyMarkRange });
43708
45022
  return commands2.setMark(type2, attrs);
43709
45023
  };
45024
+ const toggleMarkCascade = (markName, options = {}) => ({ state: state2, chain, editor }) => {
45025
+ const {
45026
+ negationAttrs = { value: "0" },
45027
+ isNegation = (attrs) => attrs?.value === "0",
45028
+ styleDetector = defaultStyleDetector,
45029
+ extendEmptyMarkRange = true
45030
+ } = options;
45031
+ const selectionMarks = getMarksFromSelection(state2) || [];
45032
+ const inlineMarks = selectionMarks.filter((m2) => m2.type?.name === markName);
45033
+ const hasNegation = inlineMarks.some((m2) => isNegation(m2.attrs || {}));
45034
+ const hasInline = inlineMarks.some((m2) => !isNegation(m2.attrs || {}));
45035
+ const styleOn = styleDetector({ state: state2, selectionMarks, markName, editor });
45036
+ const cmdChain = chain();
45037
+ if (hasNegation) return cmdChain.unsetMark(markName, { extendEmptyMarkRange }).run();
45038
+ if (hasInline && styleOn) {
45039
+ return cmdChain.unsetMark(markName, { extendEmptyMarkRange }).setMark(markName, negationAttrs, { extendEmptyMarkRange }).run();
45040
+ }
45041
+ if (hasInline) return cmdChain.unsetMark(markName, { extendEmptyMarkRange }).run();
45042
+ if (styleOn) return cmdChain.setMark(markName, negationAttrs, { extendEmptyMarkRange }).run();
45043
+ return cmdChain.setMark(markName, {}, { extendEmptyMarkRange }).run();
45044
+ };
45045
+ function defaultStyleDetector({ state: state2, selectionMarks, markName, editor }) {
45046
+ try {
45047
+ const styleId = getEffectiveStyleId(state2, selectionMarks);
45048
+ if (!styleId || !editor?.converter?.linkedStyles) return false;
45049
+ const styles = editor.converter.linkedStyles;
45050
+ const seen = /* @__PURE__ */ new Set();
45051
+ let current = styleId;
45052
+ const key2 = mapMarkToStyleKey(markName);
45053
+ while (current && !seen.has(current)) {
45054
+ seen.add(current);
45055
+ const style2 = styles.find((s) => s.id === current);
45056
+ const def = style2?.definition?.styles || {};
45057
+ if (key2 in def) {
45058
+ const raw = def[key2];
45059
+ if (raw === void 0) return true;
45060
+ const val = raw?.value ?? raw;
45061
+ return isStyleTokenEnabled(val);
45062
+ }
45063
+ current = style2?.definition?.attrs?.basedOn || null;
45064
+ }
45065
+ return false;
45066
+ } catch {
45067
+ return false;
45068
+ }
45069
+ }
45070
+ function getEffectiveStyleId(state2, selectionMarks) {
45071
+ const sidFromMarks = getStyleIdFromMarks(selectionMarks);
45072
+ if (sidFromMarks) return sidFromMarks;
45073
+ const $from = state2.selection.$from;
45074
+ const before = $from.nodeBefore;
45075
+ const after = $from.nodeAfter;
45076
+ if (before && before.marks) {
45077
+ const sid = getStyleIdFromMarks(before.marks);
45078
+ if (sid) return sid;
45079
+ }
45080
+ if (after && after.marks) {
45081
+ const sid = getStyleIdFromMarks(after.marks);
45082
+ if (sid) return sid;
45083
+ }
45084
+ const ts = selectionMarks.find((m2) => m2.type?.name === "textStyle" && m2.attrs?.styleId);
45085
+ if (ts) return ts.attrs.styleId;
45086
+ const pos = state2.selection.$from.pos;
45087
+ const $pos = state2.doc.resolve(pos);
45088
+ for (let d2 = $pos.depth; d2 >= 0; d2--) {
45089
+ const n = $pos.node(d2);
45090
+ if (n?.type?.name === "paragraph") return n.attrs?.styleId || null;
45091
+ }
45092
+ return null;
45093
+ }
45094
+ function getStyleIdFromMarks(marks) {
45095
+ if (!Array.isArray(marks)) return null;
45096
+ const textStyleMark = marks.find((m2) => m2.type?.name === "textStyle" && m2.attrs?.styleId);
45097
+ if (textStyleMark) return textStyleMark.attrs.styleId;
45098
+ return null;
45099
+ }
45100
+ function mapMarkToStyleKey(markName) {
45101
+ if (markName === "textStyle" || markName === "color") return "color";
45102
+ return markName;
45103
+ }
45104
+ function isStyleTokenEnabled(val) {
45105
+ if (val === false || val === 0) return false;
45106
+ if (typeof val === "string") {
45107
+ const normalized = val.trim().toLowerCase();
45108
+ if (!normalized) return false;
45109
+ if (["0", "false", "none", "inherit", "transparent"].includes(normalized)) return false;
45110
+ return true;
45111
+ }
45112
+ return !!val;
45113
+ }
43710
45114
  const clearNodes = () => ({ state: state2, tr, dispatch }) => {
43711
45115
  const { selection } = tr;
43712
45116
  const { ranges } = selection;
@@ -45052,11 +46456,14 @@ const commands$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
45052
46456
  command,
45053
46457
  createParagraphNear,
45054
46458
  decreaseListIndent,
46459
+ defaultStyleDetector,
45055
46460
  deleteListItem,
45056
46461
  deleteSelection,
45057
46462
  exitCode,
45058
46463
  first,
46464
+ getEffectiveStyleId,
45059
46465
  getParaCtx,
46466
+ getStyleIdFromMarks,
45060
46467
  handleBackspaceNextToList,
45061
46468
  handleDeleteNextToList,
45062
46469
  increaseListIndent,
@@ -45065,12 +46472,14 @@ const commands$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
45065
46472
  insertTabChar,
45066
46473
  insertTabCharacter,
45067
46474
  insertTabNode,
46475
+ isStyleTokenEnabled,
45068
46476
  joinBackward,
45069
46477
  joinDown,
45070
46478
  joinForward,
45071
46479
  joinUp,
45072
46480
  liftEmptyBlock,
45073
46481
  liftListItem,
46482
+ mapMarkToStyleKey,
45074
46483
  nearestListAt,
45075
46484
  newlineInCode,
45076
46485
  rebuildListNodeWithNewNum,
@@ -45090,6 +46499,7 @@ const commands$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
45090
46499
  splitListItem,
45091
46500
  toggleList,
45092
46501
  toggleMark,
46502
+ toggleMarkCascade,
45093
46503
  toggleNode,
45094
46504
  undoInputRule,
45095
46505
  unsetAllMarks,
@@ -45105,6 +46515,7 @@ const Commands = Extension.create({
45105
46515
  });
45106
46516
  const handleEnter = (editor) => {
45107
46517
  return editor.commands.first(({ commands: commands2 }) => [
46518
+ () => commands2.splitRun(),
45108
46519
  () => commands2.newlineInCode(),
45109
46520
  () => commands2.createParagraphNear(),
45110
46521
  () => commands2.liftEmptyBlock(),
@@ -45138,6 +46549,7 @@ const Keymap = Extension.create({
45138
46549
  addShortcuts() {
45139
46550
  const baseKeymap = {
45140
46551
  Enter: () => handleEnter(this.editor),
46552
+ "Shift-Enter": () => this.editor.commands.insertLineBreak(),
45141
46553
  "Mod-Enter": () => this.editor.commands.exitCode(),
45142
46554
  Backspace: () => handleBackspace(this.editor),
45143
46555
  "Mod-Backspace": () => handleBackspace(this.editor),
@@ -46215,7 +47627,18 @@ const updateYdocDocxData = async (editor, ydoc) => {
46215
47627
  ydoc = ydoc || editor.options.ydoc;
46216
47628
  if (!ydoc) return;
46217
47629
  const metaMap = ydoc.getMap("meta");
46218
- const docx = [...metaMap.get("docx")];
47630
+ const docxValue = metaMap.get("docx");
47631
+ let docx = [];
47632
+ if (Array.isArray(docxValue)) {
47633
+ docx = [...docxValue];
47634
+ } else if (docxValue && typeof docxValue.toArray === "function") {
47635
+ docx = docxValue.toArray();
47636
+ } else if (docxValue && typeof docxValue[Symbol.iterator] === "function") {
47637
+ docx = Array.from(docxValue);
47638
+ }
47639
+ if (!docx.length && Array.isArray(editor.options.content)) {
47640
+ docx = [...editor.options.content];
47641
+ }
46219
47642
  const newXml = await editor.exportDocx({ getUpdatedDocs: true });
46220
47643
  Object.keys(newXml).forEach((key2) => {
46221
47644
  const fileIndex = docx.findIndex((item) => item.name === key2);
@@ -46293,7 +47716,7 @@ const createHeaderFooterEditor = ({
46293
47716
  currentPageNumber
46294
47717
  }) => {
46295
47718
  const parentStyles = editor.converter.getDocumentDefaultStyles();
46296
- const { fontSizePt, typeface } = parentStyles;
47719
+ const { fontSizePt, typeface, fontFamilyCss } = parentStyles;
46297
47720
  const fontSizeInPixles = fontSizePt * 1.3333;
46298
47721
  const lineHeight2 = fontSizeInPixles * 1.2;
46299
47722
  Object.assign(editorContainer.style, {
@@ -46306,7 +47729,7 @@ const createHeaderFooterEditor = ({
46306
47729
  left: "0",
46307
47730
  width: "auto",
46308
47731
  maxWidth: "none",
46309
- fontFamily: typeface,
47732
+ fontFamily: fontFamilyCss || typeface,
46310
47733
  fontSize: `${fontSizeInPixles}px`,
46311
47734
  lineHeight: `${lineHeight2}px`
46312
47735
  });
@@ -47136,7 +48559,6 @@ const trackedTransaction = ({ tr, state: state2, user }) => {
47136
48559
  originalStep,
47137
48560
  originalStepIndex
47138
48561
  });
47139
- console.debug("[track-changes]: replaceStep");
47140
48562
  } else if (step instanceof AddMarkStep) {
47141
48563
  addMarkStep({
47142
48564
  state: state2,
@@ -47146,7 +48568,6 @@ const trackedTransaction = ({ tr, state: state2, user }) => {
47146
48568
  user,
47147
48569
  date
47148
48570
  });
47149
- console.debug("[track-changes]: addMarkStep");
47150
48571
  } else if (step instanceof RemoveMarkStep) {
47151
48572
  removeMarkStep({
47152
48573
  state: state2,
@@ -47156,10 +48577,8 @@ const trackedTransaction = ({ tr, state: state2, user }) => {
47156
48577
  user,
47157
48578
  date
47158
48579
  });
47159
- console.debug("[track-changes]: removeMarkStep");
47160
48580
  } else {
47161
48581
  newTr.step(step);
47162
- console.log("[track-changes]: otherStep");
47163
48582
  }
47164
48583
  });
47165
48584
  if (tr.getMeta("inputType")) {
@@ -49229,9 +50648,10 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
49229
50648
  element.style.isolation = "isolate";
49230
50649
  proseMirror.style.outline = "none";
49231
50650
  proseMirror.style.border = "none";
49232
- const { typeface, fontSizePt } = this.converter.getDocumentDefaultStyles() ?? {};
49233
- if (typeface) {
49234
- element.style.fontFamily = typeface;
50651
+ const { typeface, fontSizePt, fontFamilyCss } = this.converter.getDocumentDefaultStyles() ?? {};
50652
+ const resolvedFontFamily = fontFamilyCss || typeface;
50653
+ if (resolvedFontFamily) {
50654
+ element.style.fontFamily = resolvedFontFamily;
49235
50655
  }
49236
50656
  if (fontSizePt) {
49237
50657
  element.style.fontSize = `${fontSizePt}pt`;
@@ -49519,12 +50939,15 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
49519
50939
  }
49520
50940
  destroyHeaderFooterEditors() {
49521
50941
  try {
49522
- const editors = [...this.converter.headerEditors, ...this.converter.footerEditors];
50942
+ const headerEditors = this.converter?.headerEditors ?? [];
50943
+ const footerEditors = this.converter?.footerEditors ?? [];
50944
+ if (!headerEditors.length && !footerEditors.length) return;
50945
+ const editors = [...headerEditors, ...footerEditors].filter(Boolean);
49523
50946
  for (let editorData of editors) {
49524
- editorData.editor.destroy();
50947
+ editorData?.editor?.destroy?.();
49525
50948
  }
49526
- this.converter.headerEditors.length = 0;
49527
- this.converter.footerEditors.length = 0;
50949
+ if (headerEditors.length) headerEditors.length = 0;
50950
+ if (footerEditors.length) footerEditors.length = 0;
49528
50951
  } catch (error) {
49529
50952
  this.emit("exception", { error, editor: this });
49530
50953
  console.error(error);
@@ -49547,7 +50970,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
49547
50970
  * @returns {Object | void} Migration results
49548
50971
  */
49549
50972
  processCollaborationMigrations() {
49550
- console.debug("[checkVersionMigrations] Current editor version", "0.20.0");
50973
+ console.debug("[checkVersionMigrations] Current editor version", "0.20.0-next.13");
49551
50974
  if (!this.options.ydoc) return;
49552
50975
  const metaMap = this.options.ydoc.getMap("meta");
49553
50976
  let docVersion = metaMap.get("version");
@@ -50598,6 +52021,7 @@ const FormatCommands = Extension.create({
50598
52021
  },
50599
52022
  addCommands() {
50600
52023
  return {
52024
+ toggleMarkCascade,
50601
52025
  /**
50602
52026
  * Clear all formatting (nodes and marks)
50603
52027
  * @category Command
@@ -51577,27 +53001,69 @@ const Text = Node$1.create({
51577
53001
  return {};
51578
53002
  }
51579
53003
  });
51580
- const RunItem = Node$1.create({
53004
+ const splitRun = () => (props) => {
53005
+ const { state: state2, view, tr } = props;
53006
+ const { $from, empty: empty2 } = state2.selection;
53007
+ if (!empty2) return false;
53008
+ if ($from.parent.type.name !== "run") return false;
53009
+ const handled = splitBlock(state2, (transaction) => {
53010
+ view.dispatch(transaction);
53011
+ });
53012
+ if (handled) {
53013
+ tr.setMeta("preventDispatch", true);
53014
+ }
53015
+ return handled;
53016
+ };
53017
+ const Run = OxmlNode.create({
51581
53018
  name: "run",
53019
+ oXmlName: "w:r",
51582
53020
  group: "inline",
51583
- content: "text*",
51584
53021
  inline: true,
53022
+ content: "inline*",
53023
+ selectable: false,
53024
+ childToAttributes: ["runProperties"],
51585
53025
  addOptions() {
51586
- return {};
51587
- },
51588
- parseDOM() {
51589
- return [{ tag: "run" }];
51590
- },
51591
- renderDOM() {
51592
- return ["run", 0];
53026
+ return {
53027
+ htmlAttributes: {
53028
+ "data-run": "1"
53029
+ }
53030
+ };
51593
53031
  },
51594
53032
  addAttributes() {
51595
53033
  return {
51596
- attributes: {
53034
+ runProperties: {
53035
+ default: null,
51597
53036
  rendered: false,
51598
- "aria-label": "Run node"
53037
+ keepOnSplit: true
53038
+ },
53039
+ rsidR: {
53040
+ default: null,
53041
+ rendered: false,
53042
+ keepOnSplit: true
53043
+ },
53044
+ rsidRPr: {
53045
+ default: null,
53046
+ rendered: false,
53047
+ keepOnSplit: true
53048
+ },
53049
+ rsidDel: {
53050
+ default: null,
53051
+ rendered: false,
53052
+ keepOnSplit: true
51599
53053
  }
51600
53054
  };
53055
+ },
53056
+ addCommands() {
53057
+ return {
53058
+ splitRun
53059
+ };
53060
+ },
53061
+ parseDOM() {
53062
+ return [{ tag: "span[data-run]" }];
53063
+ },
53064
+ renderDOM({ htmlAttributes }) {
53065
+ const base2 = Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes);
53066
+ return ["span", base2, 0];
51601
53067
  }
51602
53068
  });
51603
53069
  const inputRegex$1 = /^\s*([-+*])\s$/;
@@ -51872,6 +53338,115 @@ const OrderedList = Node$1.create({
51872
53338
  ];
51873
53339
  }
51874
53340
  });
53341
+ const generateOrderedListIndex = ({ listLevel, lvlText, listNumberingType, customFormat }) => {
53342
+ const handler2 = listIndexMap[listNumberingType];
53343
+ return handler2 ? handler2(listLevel, lvlText, customFormat) : null;
53344
+ };
53345
+ const handleDecimal = (path, lvlText) => generateNumbering(path, lvlText, String);
53346
+ const handleRoman = (path, lvlText) => generateNumbering(path, lvlText, intToRoman);
53347
+ const handleLowerRoman = (path, lvlText) => handleRoman(path, lvlText).toLowerCase();
53348
+ const handleLowerAlpha = (path, lvlText) => handleAlpha(path, lvlText).toLowerCase();
53349
+ const handleAlpha = (path, lvlText) => generateNumbering(path, lvlText, (p) => intToAlpha(p));
53350
+ const handleOrdinal = (path, lvlText) => generateNumbering(path, lvlText, ordinalFormatter);
53351
+ const handleCustom = (path, lvlText, customFormat) => generateFromCustom(path, lvlText, customFormat);
53352
+ const handleJapaneseCounting = (path, lvlText) => generateNumbering(path, lvlText, intToJapaneseCounting);
53353
+ const listIndexMap = {
53354
+ decimal: handleDecimal,
53355
+ lowerRoman: handleLowerRoman,
53356
+ upperRoman: handleRoman,
53357
+ lowerLetter: handleLowerAlpha,
53358
+ upperLetter: handleAlpha,
53359
+ ordinal: handleOrdinal,
53360
+ custom: handleCustom,
53361
+ japaneseCounting: handleJapaneseCounting
53362
+ };
53363
+ const createNumbering = (values, lvlText) => {
53364
+ return values.reduce((acc, value, index2) => {
53365
+ return value > 9 ? acc.replace(/^0/, "").replace(`%${index2 + 1}`, value) : acc.replace(`%${index2 + 1}`, value);
53366
+ }, lvlText);
53367
+ };
53368
+ const generateNumbering = (path, lvlText, formatter) => {
53369
+ const formattedValues = path.map(formatter);
53370
+ return createNumbering(formattedValues, lvlText);
53371
+ };
53372
+ const ordinalFormatter = (level) => {
53373
+ const suffixes = ["th", "st", "nd", "rd"];
53374
+ const value = level % 100;
53375
+ const suffix2 = suffixes[(value - 20) % 10] || suffixes[value] || suffixes[0];
53376
+ const p = level + suffix2;
53377
+ return p;
53378
+ };
53379
+ const generateFromCustom = (path, lvlText, customFormat) => {
53380
+ if (customFormat !== "001, 002, 003, ...") return generateNumbering(path, lvlText, String);
53381
+ const match = customFormat.match(/(\d+)/);
53382
+ if (!match) throw new Error("Invalid format string: no numeric pattern found");
53383
+ const sample = match[1];
53384
+ const digitCount = sample.length;
53385
+ const index2 = path.pop();
53386
+ return String(index2).padStart(digitCount, "0");
53387
+ };
53388
+ const intToRoman = (num) => {
53389
+ const romanNumeralMap = [
53390
+ { value: 1e3, numeral: "M" },
53391
+ { value: 900, numeral: "CM" },
53392
+ { value: 500, numeral: "D" },
53393
+ { value: 400, numeral: "CD" },
53394
+ { value: 100, numeral: "C" },
53395
+ { value: 90, numeral: "XC" },
53396
+ { value: 50, numeral: "L" },
53397
+ { value: 40, numeral: "XL" },
53398
+ { value: 10, numeral: "X" },
53399
+ { value: 9, numeral: "IX" },
53400
+ { value: 5, numeral: "V" },
53401
+ { value: 4, numeral: "IV" },
53402
+ { value: 1, numeral: "I" }
53403
+ ];
53404
+ let result = "";
53405
+ for (const { value, numeral } of romanNumeralMap) {
53406
+ while (num >= value) {
53407
+ result += numeral;
53408
+ num -= value;
53409
+ }
53410
+ }
53411
+ return result;
53412
+ };
53413
+ const intToAlpha = (num) => {
53414
+ let result = "";
53415
+ const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
53416
+ while (num > 0) {
53417
+ let index2 = (num - 1) % 26;
53418
+ result = alphabet[index2] + result;
53419
+ num = Math.floor((num - 1) / 26);
53420
+ }
53421
+ return result;
53422
+ };
53423
+ const intToJapaneseCounting = (num) => {
53424
+ const digits = ["", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
53425
+ const units = ["", "十", "百", "千"];
53426
+ if (num === 0) return "零";
53427
+ if (num < 10) return digits[num];
53428
+ let result = "";
53429
+ let tempNum = num;
53430
+ let unitIndex = 0;
53431
+ while (tempNum > 0) {
53432
+ const digit = tempNum % 10;
53433
+ if (digit !== 0) {
53434
+ const digitStr = digit === 1 && unitIndex > 0 ? "" : digits[digit];
53435
+ result = digitStr + (unitIndex > 0 ? units[unitIndex] : "") + result;
53436
+ } else if (result && tempNum > 0) {
53437
+ if (!result.startsWith("零") && tempNum % 100 !== 0) {
53438
+ result = "零" + result;
53439
+ }
53440
+ }
53441
+ tempNum = Math.floor(tempNum / 10);
53442
+ unitIndex++;
53443
+ if (unitIndex > 3) break;
53444
+ }
53445
+ if (num >= 10 && num < 20) {
53446
+ result = result.replace(/^一十/, "十");
53447
+ }
53448
+ return result;
53449
+ };
51875
53450
  const CustomSelectionPluginKey = new PluginKey("CustomSelection");
51876
53451
  const handleClickOutside = (event, editor) => {
51877
53452
  const editorElem = editor?.options?.element;
@@ -52152,6 +53727,7 @@ const getMarksStyle = (attrs) => {
52152
53727
  case "textStyle":
52153
53728
  const { fontFamily: fontFamily2, fontSize: fontSize2 } = attr.attrs;
52154
53729
  styles += `${fontFamily2 ? `font-family: ${fontFamily2};` : ""} ${fontSize2 ? `font-size: ${fontSize2};` : ""}`;
53730
+ break;
52155
53731
  }
52156
53732
  }
52157
53733
  return styles.trim();
@@ -52170,12 +53746,22 @@ const generateLinkedStyleString = (linkedStyle, basedOnStyle, node, parent, incl
52170
53746
  const linkedDefinitionStyles = { ...linkedStyle.definition.styles };
52171
53747
  const basedOnDefinitionStyles = { ...basedOnStyle?.definition?.styles };
52172
53748
  const resultStyles = { ...linkedDefinitionStyles };
52173
- if (!linkedDefinitionStyles["font-size"] && basedOnDefinitionStyles["font-size"]) {
52174
- resultStyles["font-size"] = basedOnDefinitionStyles["font-size"];
52175
- }
52176
- if (!linkedDefinitionStyles["text-transform"] && basedOnDefinitionStyles["text-transform"]) {
52177
- resultStyles["text-transform"] = basedOnDefinitionStyles["text-transform"];
52178
- }
53749
+ const inheritKeys = [
53750
+ "font-size",
53751
+ "font-family",
53752
+ "text-transform",
53753
+ "bold",
53754
+ "italic",
53755
+ "underline",
53756
+ "strike",
53757
+ "color",
53758
+ "highlight"
53759
+ ];
53760
+ inheritKeys.forEach((k) => {
53761
+ if (!linkedDefinitionStyles[k] && basedOnDefinitionStyles[k]) {
53762
+ resultStyles[k] = basedOnDefinitionStyles[k];
53763
+ }
53764
+ });
52179
53765
  Object.entries(resultStyles).forEach(([k, value]) => {
52180
53766
  const key2 = kebabCase$1(k);
52181
53767
  const flattenedMarks = [];
@@ -52190,6 +53776,10 @@ const generateLinkedStyleString = (linkedStyle, basedOnStyle, node, parent, incl
52190
53776
  }
52191
53777
  flattenedMarks.push({ key: n.type.name, value: n.attrs[key2] });
52192
53778
  });
53779
+ const underlineNone = node?.marks?.some((m2) => m2.type?.name === "underline" && m2.attrs?.underlineType === "none");
53780
+ if (underlineNone) {
53781
+ markValue["text-decoration"] = "none";
53782
+ }
52193
53783
  const mark = flattenedMarks.find((n) => n.key === key2);
52194
53784
  const hasParentIndent = Object.keys(parent?.attrs?.indent || {});
52195
53785
  const hasParentSpacing = Object.keys(parent?.attrs?.spacing || {});
@@ -52206,10 +53796,28 @@ const generateLinkedStyleString = (linkedStyle, basedOnStyle, node, parent, incl
52206
53796
  if (rightIndent) markValue["margin-right"] = rightIndent + "px";
52207
53797
  if (firstLine) markValue["text-indent"] = firstLine + "px";
52208
53798
  } else if (key2 === "bold" && node) {
52209
- const val = value?.value;
52210
- if (!listTypes.includes(node.type.name) && val !== "0") {
53799
+ const boldValue = typeof value === "object" && value !== null ? value.value : value;
53800
+ const hasInlineBoldOff = node.marks?.some((m2) => m2.type?.name === "bold" && m2.attrs?.value === "0");
53801
+ const hasInlineBoldOn = node.marks?.some((m2) => m2.type?.name === "bold" && m2.attrs?.value !== "0");
53802
+ if (!listTypes.includes(node.type.name) && !hasInlineBoldOff && !hasInlineBoldOn && boldValue !== "0" && boldValue !== false) {
52211
53803
  markValue["font-weight"] = "bold";
52212
53804
  }
53805
+ } else if (key2 === "italic" && node) {
53806
+ const italicValue = typeof value === "object" && value !== null ? value.value : value;
53807
+ const hasInlineItalicOff = node.marks?.some((m2) => m2.type?.name === "italic" && m2.attrs?.value === "0");
53808
+ const hasInlineItalicOn = node.marks?.some((m2) => m2.type?.name === "italic" && m2.attrs?.value !== "0");
53809
+ if (!listTypes.includes(node.type.name) && !hasInlineItalicOff && !hasInlineItalicOn && italicValue !== "0" && italicValue !== false) {
53810
+ markValue["font-style"] = "italic";
53811
+ }
53812
+ } else if (key2 === "strike" && node) {
53813
+ const strikeValue = typeof value === "object" && value !== null ? value.value : value;
53814
+ const hasInlineStrikeOff = node.marks?.some((m2) => m2.type?.name === "strike" && m2.attrs?.value === "0");
53815
+ const hasInlineStrikeOn = node.marks?.some(
53816
+ (m2) => m2.type?.name === "strike" && (m2.attrs?.value === void 0 || m2.attrs?.value !== "0")
53817
+ );
53818
+ if (!listTypes.includes(node.type.name) && !hasInlineStrikeOff && !hasInlineStrikeOn && strikeValue !== "0" && strikeValue !== false) {
53819
+ markValue["text-decoration"] = "line-through";
53820
+ }
52213
53821
  } else if (key2 === "text-transform" && node) {
52214
53822
  if (!listTypes.includes(node.type.name)) {
52215
53823
  markValue[key2] = value;
@@ -52218,10 +53826,44 @@ const generateLinkedStyleString = (linkedStyle, basedOnStyle, node, parent, incl
52218
53826
  if (!listTypes.includes(node.type.name)) {
52219
53827
  markValue[key2] = value;
52220
53828
  }
53829
+ } else if (key2 === "font-family" && node) {
53830
+ if (!listTypes.includes(node.type.name)) {
53831
+ markValue[key2] = value;
53832
+ }
52221
53833
  } else if (key2 === "color" && node) {
52222
53834
  if (!listTypes.includes(node.type.name)) {
52223
53835
  markValue[key2] = value;
52224
53836
  }
53837
+ } else if (key2 === "highlight" && node) {
53838
+ const hasInlineHighlight = node.marks?.some((m2) => m2.type?.name === "highlight");
53839
+ if (!listTypes.includes(node.type.name) && !hasInlineHighlight) {
53840
+ const color = typeof value === "string" ? value : value?.color;
53841
+ if (color) markValue["background-color"] = color;
53842
+ }
53843
+ } else if (key2 === "underline" && node) {
53844
+ const styleValRaw = value?.value ?? value ?? "";
53845
+ const styleVal = styleValRaw.toString().toLowerCase();
53846
+ const hasInlineUnderlineOff = node.marks?.some(
53847
+ (m2) => m2.type?.name === "underline" && m2.attrs?.underlineType === "none"
53848
+ );
53849
+ const hasInlineUnderlineOn = node.marks?.some(
53850
+ (m2) => m2.type?.name === "underline" && m2.attrs?.underlineType && m2.attrs.underlineType !== "none"
53851
+ );
53852
+ if (!listTypes.includes(node.type.name) && !hasInlineUnderlineOff && !hasInlineUnderlineOn) {
53853
+ if (styleVal && styleVal !== "none" && styleVal !== "0") {
53854
+ const colorVal = value && typeof value === "object" ? value.color || value.underlineColor || null : null;
53855
+ const css = getUnderlineCssString({ type: styleVal, color: colorVal });
53856
+ css.split(";").forEach((decl) => {
53857
+ const d2 = decl.trim();
53858
+ if (!d2) return;
53859
+ const idx = d2.indexOf(":");
53860
+ if (idx === -1) return;
53861
+ const k2 = d2.slice(0, idx).trim();
53862
+ const v2 = d2.slice(idx + 1).trim();
53863
+ markValue[k2] = v2;
53864
+ });
53865
+ }
53866
+ }
52225
53867
  } else if (typeof value === "string") {
52226
53868
  markValue[key2] = value;
52227
53869
  }
@@ -52354,23 +53996,51 @@ const createLinkedStylesPlugin = (editor) => {
52354
53996
  };
52355
53997
  const generateDecorations = (state2, styles) => {
52356
53998
  const decorations = [];
52357
- let lastStyleId = null;
52358
53999
  const doc2 = state2?.doc;
54000
+ const getParagraphStyleId = (pos) => {
54001
+ const $pos = state2.doc.resolve(pos);
54002
+ for (let d2 = $pos.depth; d2 >= 0; d2--) {
54003
+ const n = $pos.node(d2);
54004
+ if (n?.type?.name === "paragraph") return n.attrs?.styleId || null;
54005
+ }
54006
+ return null;
54007
+ };
52359
54008
  doc2.descendants((node, pos) => {
52360
54009
  const { name } = node.type;
52361
- if (node?.attrs?.styleId) lastStyleId = node.attrs.styleId;
52362
- if (name === "paragraph" && !node.attrs?.styleId) lastStyleId = null;
52363
- if (name !== "text" && name !== "listItem" && name !== "orderedList") return;
54010
+ if (name !== "text") return;
54011
+ const paragraphStyleId = getParagraphStyleId(pos);
54012
+ let runStyleId = null;
54013
+ let inlineTextStyleId = null;
52364
54014
  for (const mark of node.marks) {
52365
- if (mark.type.name === "textStyle" && mark.attrs.styleId) {
52366
- lastStyleId = mark.attrs.styleId;
52367
- }
52368
- }
52369
- const { linkedStyle, basedOnStyle } = getLinkedStyle(lastStyleId, styles);
52370
- if (!linkedStyle) return;
54015
+ if (mark.type.name === "run") {
54016
+ const rp = mark.attrs?.runProperties;
54017
+ if (rp && typeof rp === "object" && !Array.isArray(rp) && rp.styleId) runStyleId = rp.styleId;
54018
+ else if (Array.isArray(rp)) {
54019
+ const ent = rp.find((e) => e?.xmlName === "w:rStyle");
54020
+ const sid = ent?.attributes?.["w:val"];
54021
+ if (sid) runStyleId = sid;
54022
+ }
54023
+ } else if (mark.type.name === "textStyle" && mark.attrs?.styleId) {
54024
+ inlineTextStyleId = mark.attrs.styleId;
54025
+ }
54026
+ }
54027
+ const buildStyleMap = (sid) => {
54028
+ if (!sid) return {};
54029
+ const { linkedStyle, basedOnStyle: basedOnStyle2 } = getLinkedStyle(sid, styles);
54030
+ if (!linkedStyle) return {};
54031
+ const base2 = { ...basedOnStyle2?.definition?.styles || {} };
54032
+ return { ...base2, ...linkedStyle.definition?.styles || {} };
54033
+ };
54034
+ const pMap = buildStyleMap(paragraphStyleId);
54035
+ const tMap = buildStyleMap(inlineTextStyleId);
54036
+ const rMap = buildStyleMap(runStyleId);
54037
+ const finalStyles = { ...pMap, ...tMap, ...rMap };
54038
+ if (Object.keys(finalStyles).length === 0) return;
54039
+ const mergedLinkedStyle = { definition: { styles: finalStyles, attrs: {} } };
54040
+ const basedOnStyle = null;
52371
54041
  const $pos = state2.doc.resolve(pos);
52372
54042
  const parent = $pos.parent;
52373
- const styleString = generateLinkedStyleString(linkedStyle, basedOnStyle, node, parent);
54043
+ const styleString = generateLinkedStyleString(mergedLinkedStyle, basedOnStyle, node, parent);
52374
54044
  if (!styleString) return;
52375
54045
  const decoration = Decoration.inline(pos, pos + node.nodeSize, { style: styleString });
52376
54046
  decorations.push(decoration);
@@ -52499,115 +54169,298 @@ const LinkedStyles = Extension.create({
52499
54169
  };
52500
54170
  }
52501
54171
  });
52502
- const generateOrderedListIndex = ({ listLevel, lvlText, listNumberingType, customFormat }) => {
52503
- const handler2 = listIndexMap[listNumberingType];
52504
- return handler2 ? handler2(listLevel, lvlText, customFormat) : null;
52505
- };
52506
- const handleDecimal = (path, lvlText) => generateNumbering(path, lvlText, String);
52507
- const handleRoman = (path, lvlText) => generateNumbering(path, lvlText, intToRoman);
52508
- const handleLowerRoman = (path, lvlText) => handleRoman(path, lvlText).toLowerCase();
52509
- const handleLowerAlpha = (path, lvlText) => handleAlpha(path, lvlText).toLowerCase();
52510
- const handleAlpha = (path, lvlText) => generateNumbering(path, lvlText, (p) => intToAlpha(p));
52511
- const handleOrdinal = (path, lvlText) => generateNumbering(path, lvlText, ordinalFormatter);
52512
- const handleCustom = (path, lvlText, customFormat) => generateFromCustom(path, lvlText, customFormat);
52513
- const handleJapaneseCounting = (path, lvlText) => generateNumbering(path, lvlText, intToJapaneseCounting);
52514
- const listIndexMap = {
52515
- decimal: handleDecimal,
52516
- lowerRoman: handleLowerRoman,
52517
- upperRoman: handleRoman,
52518
- lowerLetter: handleLowerAlpha,
52519
- upperLetter: handleAlpha,
52520
- ordinal: handleOrdinal,
52521
- custom: handleCustom,
52522
- japaneseCounting: handleJapaneseCounting
52523
- };
52524
- const createNumbering = (values, lvlText) => {
52525
- return values.reduce((acc, value, index2) => {
52526
- return value > 9 ? acc.replace(/^0/, "").replace(`%${index2 + 1}`, value) : acc.replace(`%${index2 + 1}`, value);
52527
- }, lvlText);
52528
- };
52529
- const generateNumbering = (path, lvlText, formatter) => {
52530
- const formattedValues = path.map(formatter);
52531
- return createNumbering(formattedValues, lvlText);
52532
- };
52533
- const ordinalFormatter = (level) => {
52534
- const suffixes = ["th", "st", "nd", "rd"];
52535
- const value = level % 100;
52536
- const suffix2 = suffixes[(value - 20) % 10] || suffixes[value] || suffixes[0];
52537
- const p = level + suffix2;
52538
- return p;
52539
- };
52540
- const generateFromCustom = (path, lvlText, customFormat) => {
52541
- if (customFormat !== "001, 002, 003, ...") return generateNumbering(path, lvlText, String);
52542
- const match = customFormat.match(/(\d+)/);
52543
- if (!match) throw new Error("Invalid format string: no numeric pattern found");
52544
- const sample = match[1];
52545
- const digitCount = sample.length;
52546
- const index2 = path.pop();
52547
- return String(index2).padStart(digitCount, "0");
52548
- };
52549
- const intToRoman = (num) => {
52550
- const romanNumeralMap = [
52551
- { value: 1e3, numeral: "M" },
52552
- { value: 900, numeral: "CM" },
52553
- { value: 500, numeral: "D" },
52554
- { value: 400, numeral: "CD" },
52555
- { value: 100, numeral: "C" },
52556
- { value: 90, numeral: "XC" },
52557
- { value: 50, numeral: "L" },
52558
- { value: 40, numeral: "XL" },
52559
- { value: 10, numeral: "X" },
52560
- { value: 9, numeral: "IX" },
52561
- { value: 5, numeral: "V" },
52562
- { value: 4, numeral: "IV" },
52563
- { value: 1, numeral: "I" }
52564
- ];
52565
- let result = "";
52566
- for (const { value, numeral } of romanNumeralMap) {
52567
- while (num >= value) {
52568
- result += numeral;
52569
- num -= value;
54172
+ function getUnderlineCssString({ type: type2 = "single", color = null, thickness = null, approximate = true } = {}) {
54173
+ const parts = [];
54174
+ const add = (k, v2) => {
54175
+ if (!v2) return;
54176
+ parts.push(`${k}: ${v2}`);
54177
+ };
54178
+ const lower = String(type2 || "single").toLowerCase();
54179
+ if (lower === "none" || lower === "0") {
54180
+ add("text-decoration", "none");
54181
+ return parts.join("; ");
54182
+ }
54183
+ add("text-decoration-line", "underline");
54184
+ const HEAVY = thickness || "0.2em";
54185
+ const THICK = thickness || "0.15em";
54186
+ switch (lower) {
54187
+ case "single":
54188
+ break;
54189
+ case "double":
54190
+ add("text-decoration-style", "double");
54191
+ break;
54192
+ case "thick":
54193
+ add("text-decoration-thickness", THICK);
54194
+ break;
54195
+ case "dotted":
54196
+ add("text-decoration-style", "dotted");
54197
+ break;
54198
+ case "dash":
54199
+ case "dashed":
54200
+ add("text-decoration-style", "dashed");
54201
+ break;
54202
+ case "dotdash":
54203
+ case "dotdotdash":
54204
+ case "dashlong":
54205
+ case "dashlongheavy":
54206
+ if (approximate) {
54207
+ add("text-decoration-style", "dashed");
54208
+ if (lower.includes("heavy")) add("text-decoration-thickness", HEAVY);
54209
+ }
54210
+ break;
54211
+ case "dottedheavy":
54212
+ add("text-decoration-style", "dotted");
54213
+ add("text-decoration-thickness", HEAVY);
54214
+ break;
54215
+ case "dashedheavy":
54216
+ add("text-decoration-style", "dashed");
54217
+ add("text-decoration-thickness", HEAVY);
54218
+ break;
54219
+ case "wavy":
54220
+ add("text-decoration-style", "wavy");
54221
+ break;
54222
+ case "wavyheavy":
54223
+ add("text-decoration-style", "wavy");
54224
+ add("text-decoration-thickness", HEAVY);
54225
+ break;
54226
+ case "wavydouble":
54227
+ if (approximate) {
54228
+ add("text-decoration-style", "wavy");
54229
+ add("text-decoration-thickness", HEAVY);
54230
+ }
54231
+ break;
54232
+ }
54233
+ if (color) add("text-decoration-color", color);
54234
+ return parts.join("; ");
54235
+ }
54236
+ function collectTextStyleMarks(listItem, markType) {
54237
+ const textStyleMarks = [];
54238
+ const seenMarks = /* @__PURE__ */ new Set();
54239
+ const attrs = {};
54240
+ if (!markType) {
54241
+ return {
54242
+ marks: textStyleMarks,
54243
+ attrs
54244
+ };
54245
+ }
54246
+ const collectMarks = (node) => {
54247
+ if (!node) return;
54248
+ const candidateMarks = Array.isArray(node.marks) ? node.marks : [];
54249
+ if (candidateMarks.length && typeof markType.isInSet === "function" && markType.isInSet(candidateMarks)) {
54250
+ candidateMarks.forEach((mark) => {
54251
+ if (mark.type === markType && !seenMarks.has(mark)) {
54252
+ seenMarks.add(mark);
54253
+ textStyleMarks.push(mark);
54254
+ }
54255
+ });
54256
+ }
54257
+ if (!node.isText && node.childCount) {
54258
+ node.forEach((child) => collectMarks(child));
54259
+ }
54260
+ };
54261
+ listItem.forEach((childNode) => {
54262
+ if (childNode.type?.name !== "paragraph") return;
54263
+ if (childNode.attrs?.lineHeight !== void 0) {
54264
+ attrs.lineHeight = childNode.attrs.lineHeight;
52570
54265
  }
54266
+ collectMarks(childNode);
54267
+ });
54268
+ return {
54269
+ marks: textStyleMarks,
54270
+ attrs
54271
+ };
54272
+ }
54273
+ function parseSizeFromRunProperties(listRunProperties) {
54274
+ const val = listRunProperties?.["w:val"] || listRunProperties?.["w:sz"];
54275
+ if (val == null) return null;
54276
+ const numeric = Number(val);
54277
+ if (Number.isNaN(numeric) || numeric <= 0) return null;
54278
+ const sizeInPoints = numeric / 2;
54279
+ return `${sizeInPoints}pt`;
54280
+ }
54281
+ function parseFontFamilyFromRunProperties(listRunProperties) {
54282
+ const ascii = listRunProperties?.["w:ascii"];
54283
+ const hAnsi = listRunProperties?.["w:hAnsi"];
54284
+ const eastAsia = listRunProperties?.["w:eastAsia"];
54285
+ return ascii || hAnsi || eastAsia || null;
54286
+ }
54287
+ function readNodeViewStyles(view) {
54288
+ const fallback = { fontSize: null, fontFamily: null, lineHeight: null };
54289
+ if (!view?.dom) return fallback;
54290
+ const inline = {
54291
+ fontSize: view.dom.style?.fontSize || null,
54292
+ fontFamily: view.dom.style?.fontFamily || null,
54293
+ lineHeight: view.dom.style?.lineHeight || null
54294
+ };
54295
+ if (inline.fontSize && inline.fontFamily && inline.lineHeight) return inline;
54296
+ const globalWindow = typeof window !== "undefined" ? window : void 0;
54297
+ if (globalWindow?.getComputedStyle) {
54298
+ const computed2 = globalWindow.getComputedStyle(view.dom);
54299
+ return {
54300
+ fontSize: inline.fontSize || computed2.fontSize,
54301
+ fontFamily: inline.fontFamily || computed2.fontFamily,
54302
+ lineHeight: inline.lineHeight || computed2.lineHeight
54303
+ };
52571
54304
  }
52572
- return result;
52573
- };
52574
- const intToAlpha = (num) => {
52575
- let result = "";
52576
- const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
52577
- while (num > 0) {
52578
- let index2 = (num - 1) % 26;
52579
- result = alphabet[index2] + result;
52580
- num = Math.floor((num - 1) / 26);
54305
+ return inline;
54306
+ }
54307
+ function getAdjacentListItemNodeView({ nodeView, pos, direction, activeNodeViews }) {
54308
+ if (!activeNodeViews) return null;
54309
+ let candidate = null;
54310
+ activeNodeViews.forEach((view) => {
54311
+ if (view === nodeView) return;
54312
+ let viewPos;
54313
+ try {
54314
+ viewPos = view.getPos();
54315
+ } catch {
54316
+ return;
54317
+ }
54318
+ if (typeof viewPos !== "number") return;
54319
+ if (viewPos < pos) {
54320
+ if (!candidate || viewPos > candidate.pos) candidate = { view, pos: viewPos };
54321
+ }
54322
+ });
54323
+ return candidate?.view ?? null;
54324
+ }
54325
+ function findSiblingListItem({ editor, pos, direction }) {
54326
+ if (typeof pos !== "number" || !editor?.view) return null;
54327
+ const { state: state2 } = editor.view;
54328
+ const $pos = state2.doc.resolve(pos);
54329
+ const parentDepth = $pos.depth - 1;
54330
+ if (parentDepth < 0) return null;
54331
+ const parent = $pos.node(parentDepth);
54332
+ if (!parent) return null;
54333
+ const indexInsideParent = $pos.index(parentDepth);
54334
+ const siblingIndex = indexInsideParent + direction;
54335
+ if (siblingIndex < 0 || siblingIndex >= parent.childCount) return null;
54336
+ const sibling = parent.child(siblingIndex);
54337
+ return sibling?.type?.name === "listItem" ? sibling : null;
54338
+ }
54339
+ function deriveFontStylesFromNode({ node, textStyleType, defaultFont, defaultSize, listRunProperties }) {
54340
+ const { marks: allMarks, attrs } = collectTextStyleMarks(node, textStyleType);
54341
+ const styleMarks = textStyleType ? allMarks.filter((m2) => m2.type === textStyleType) : [];
54342
+ const sizeMark = styleMarks.find((m2) => m2.attrs?.fontSize);
54343
+ const familyMark = styleMarks.find((m2) => m2.attrs?.fontFamily);
54344
+ let fontSize2 = defaultSize;
54345
+ if (sizeMark) {
54346
+ const [value, unit = "pt"] = parseSizeUnit(sizeMark.attrs.fontSize);
54347
+ if (!Number.isNaN(value)) {
54348
+ fontSize2 = `${value}${unit}`;
54349
+ }
52581
54350
  }
52582
- return result;
52583
- };
52584
- const intToJapaneseCounting = (num) => {
52585
- const digits = ["", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
52586
- const units = ["", "十", "百", "千"];
52587
- if (num === 0) return "零";
52588
- if (num < 10) return digits[num];
52589
- let result = "";
52590
- let tempNum = num;
52591
- let unitIndex = 0;
52592
- while (tempNum > 0) {
52593
- const digit = tempNum % 10;
52594
- if (digit !== 0) {
52595
- const digitStr = digit === 1 && unitIndex > 0 ? "" : digits[digit];
52596
- result = digitStr + (unitIndex > 0 ? units[unitIndex] : "") + result;
52597
- } else if (result && tempNum > 0) {
52598
- if (!result.startsWith("零") && tempNum % 100 !== 0) {
52599
- result = "零" + result;
52600
- }
54351
+ let hasSize = Boolean(sizeMark);
54352
+ if (!hasSize && listRunProperties) {
54353
+ const sizeFromList = parseSizeFromRunProperties(listRunProperties);
54354
+ if (sizeFromList) {
54355
+ fontSize2 = sizeFromList;
54356
+ hasSize = true;
52601
54357
  }
52602
- tempNum = Math.floor(tempNum / 10);
52603
- unitIndex++;
52604
- if (unitIndex > 3) break;
52605
54358
  }
52606
- if (num >= 10 && num < 20) {
52607
- result = result.replace(/^一十/, "十");
54359
+ let fontFamily2 = familyMark?.attrs?.fontFamily ?? defaultFont;
54360
+ let hasFamily = Boolean(familyMark);
54361
+ if (!hasFamily && listRunProperties) {
54362
+ const fontFromList = parseFontFamilyFromRunProperties(listRunProperties);
54363
+ if (fontFromList) {
54364
+ fontFamily2 = fontFromList;
54365
+ hasFamily = true;
54366
+ }
52608
54367
  }
52609
- return result;
52610
- };
54368
+ let lineHeight2 = attrs.lineHeight;
54369
+ const firstChild = node.firstChild;
54370
+ const hasOnlyOnePar = node.childCount === 1 && firstChild?.type?.name === "paragraph";
54371
+ if (hasOnlyOnePar) {
54372
+ const par = firstChild;
54373
+ const parFirstChild = par?.firstChild;
54374
+ if (par?.childCount === 1 && parFirstChild?.type?.name === "fieldAnnotation") {
54375
+ const aFontSize = parFirstChild.attrs?.fontSize;
54376
+ const aFontFamily = parFirstChild.attrs?.fontFamily;
54377
+ if (!sizeMark && aFontSize) fontSize2 = aFontSize;
54378
+ if (!familyMark && aFontFamily) fontFamily2 = aFontFamily;
54379
+ }
54380
+ }
54381
+ return {
54382
+ fontSize: fontSize2,
54383
+ fontFamily: fontFamily2,
54384
+ lineHeight: lineHeight2,
54385
+ hasSize,
54386
+ hasFamily
54387
+ };
54388
+ }
54389
+ function getStylesFromLinkedStyles({ node, pos, editor }) {
54390
+ const { state: state2 } = editor.view;
54391
+ const linkedStyles = LinkedStylesPluginKey.getState(state2)?.decorations;
54392
+ const decorationsInPlace = linkedStyles?.find(pos, pos + node.nodeSize);
54393
+ const predicates = [
54394
+ (style22) => style22.includes("font-size") && style22.includes("font-family"),
54395
+ (style22) => style22.includes("font-size"),
54396
+ (style22) => style22.includes("font-family")
54397
+ ];
54398
+ let styleDeco;
54399
+ for (const predicateFn of predicates) {
54400
+ styleDeco = decorationsInPlace?.find((dec) => {
54401
+ const style22 = dec.type?.attrs?.style || "";
54402
+ return style22 && predicateFn(style22);
54403
+ });
54404
+ if (styleDeco) break;
54405
+ }
54406
+ const style2 = styleDeco?.type?.attrs?.style;
54407
+ const stylesArray = style2?.split(";") || [];
54408
+ const fontSizeFromStyles = stylesArray.find((s) => s.includes("font-size"))?.split(":")[1]?.trim();
54409
+ const fontFamilyFromStyles = stylesArray.find((s) => s.includes("font-family"))?.split(":")[1]?.trim();
54410
+ return {
54411
+ font: fontFamilyFromStyles,
54412
+ size: fontSizeFromStyles
54413
+ };
54414
+ }
54415
+ function resolveListItemTypography({ node, pos, editor, nodeView, activeNodeViews }) {
54416
+ const defaults = getStylesFromLinkedStyles({ node, pos, editor });
54417
+ const textStyleType = getMarkType("textStyle", editor.schema);
54418
+ const currentStyles = deriveFontStylesFromNode({
54419
+ node,
54420
+ textStyleType,
54421
+ defaultFont: defaults.font,
54422
+ defaultSize: defaults.size,
54423
+ listRunProperties: node.attrs?.listRunProperties
54424
+ });
54425
+ if ((!currentStyles.hasSize || !currentStyles.hasFamily || !currentStyles.lineHeight) && editor?.view) {
54426
+ const previousListItem = findSiblingListItem({ editor, pos, direction: -1 });
54427
+ if (previousListItem) {
54428
+ const previousStyles = deriveFontStylesFromNode({
54429
+ node: previousListItem,
54430
+ textStyleType,
54431
+ defaultFont: defaults.font,
54432
+ defaultSize: defaults.size,
54433
+ listRunProperties: previousListItem.attrs?.listRunProperties
54434
+ });
54435
+ if (!currentStyles.hasSize && previousStyles.fontSize) currentStyles.fontSize = previousStyles.fontSize;
54436
+ if (!currentStyles.hasFamily && previousStyles.fontFamily) currentStyles.fontFamily = previousStyles.fontFamily;
54437
+ if (!currentStyles.lineHeight && previousStyles.lineHeight) currentStyles.lineHeight = previousStyles.lineHeight;
54438
+ }
54439
+ }
54440
+ if ((!currentStyles.fontSize || !currentStyles.fontFamily || !currentStyles.lineHeight) && nodeView) {
54441
+ const previousView = getAdjacentListItemNodeView({
54442
+ nodeView,
54443
+ pos,
54444
+ direction: -1,
54445
+ activeNodeViews
54446
+ });
54447
+ if (previousView) {
54448
+ const {
54449
+ fontSize: prevSize,
54450
+ fontFamily: prevFamily,
54451
+ lineHeight: prevLineHeight
54452
+ } = readNodeViewStyles(previousView);
54453
+ if (!currentStyles.fontSize && prevSize) currentStyles.fontSize = prevSize;
54454
+ if (!currentStyles.fontFamily && prevFamily) currentStyles.fontFamily = prevFamily;
54455
+ if (!currentStyles.lineHeight && prevLineHeight) currentStyles.lineHeight = prevLineHeight;
54456
+ }
54457
+ }
54458
+ return {
54459
+ fontSize: currentStyles.fontSize,
54460
+ fontFamily: currentStyles.fontFamily,
54461
+ lineHeight: currentStyles.lineHeight
54462
+ };
54463
+ }
52611
54464
  const MARKER_PADDING = 6;
52612
54465
  const MARKER_OFFSET_RIGHT = 4;
52613
54466
  const MIN_MARKER_WIDTH = 20;
@@ -52625,8 +54478,8 @@ class ListItemNodeView {
52625
54478
  this.decorations = decorations;
52626
54479
  this.view = editor.view;
52627
54480
  this.getPos = getPos;
52628
- activeListItemNodeViews.add(this);
52629
54481
  __privateMethod$1(this, _ListItemNodeView_instances, init_fn2).call(this);
54482
+ activeListItemNodeViews.add(this);
52630
54483
  }
52631
54484
  refreshIndentStyling() {
52632
54485
  const { attrs } = this.node;
@@ -52669,10 +54522,12 @@ class ListItemNodeView {
52669
54522
  update(node, decorations) {
52670
54523
  this.node = node;
52671
54524
  this.decorations = decorations;
52672
- const { fontSize: fontSize2, fontFamily: fontFamily2, lineHeight: lineHeight2 } = getTextStyleMarksFromLinkedStyles({
54525
+ const { fontSize: fontSize2, fontFamily: fontFamily2, lineHeight: lineHeight2 } = resolveListItemTypography({
52673
54526
  node,
52674
54527
  pos: this.getPos(),
52675
- editor: this.editor
54528
+ editor: this.editor,
54529
+ nodeView: this,
54530
+ activeNodeViews: activeListItemNodeViews
52676
54531
  });
52677
54532
  this.dom.style.fontSize = fontSize2;
52678
54533
  this.dom.style.fontFamily = fontFamily2 || "inherit";
@@ -52701,10 +54556,12 @@ init_fn2 = function() {
52701
54556
  }
52702
54557
  }
52703
54558
  const pos = this.getPos();
52704
- const { fontSize: fontSize2, fontFamily: fontFamily2, lineHeight: lineHeight2 } = getTextStyleMarksFromLinkedStyles({
54559
+ const { fontSize: fontSize2, fontFamily: fontFamily2, lineHeight: lineHeight2 } = resolveListItemTypography({
52705
54560
  node: this.node,
52706
54561
  pos,
52707
- editor: this.editor
54562
+ editor: this.editor,
54563
+ nodeView: this,
54564
+ activeNodeViews: activeListItemNodeViews
52708
54565
  });
52709
54566
  this.dom = document.createElement("li");
52710
54567
  this.dom.className = "sd-editor-list-item-node-view";
@@ -52737,79 +54594,6 @@ function refreshAllListItemNodeViews() {
52737
54594
  }
52738
54595
  });
52739
54596
  }
52740
- function getListItemTextStyleMarks(listItem, markType) {
52741
- let textStyleMarks = [];
52742
- let attrs = {};
52743
- listItem.forEach((childNode) => {
52744
- if (childNode.type.name !== "paragraph") return;
52745
- attrs.lineHeight = childNode.attrs.lineHeight;
52746
- childNode.forEach((textNode) => {
52747
- let isTextNode = textNode.type.name === "text";
52748
- let hasTextStyleMarks = markType.isInSet(textNode.marks);
52749
- if (isTextNode && hasTextStyleMarks) {
52750
- let marks = textNode.marks.filter((mark) => mark.type === markType);
52751
- textStyleMarks.push(...marks);
52752
- }
52753
- });
52754
- });
52755
- return {
52756
- marks: textStyleMarks,
52757
- attrs
52758
- };
52759
- }
52760
- function getTextStyleMarksFromLinkedStyles({ node, pos, editor }) {
52761
- const { font: defaultFont, size: defaultSize } = getStylesFromLinkedStyles({ node, pos, editor });
52762
- const textStyleType = getMarkType("textStyle", editor.schema);
52763
- const { marks: allMarks, attrs: allAttrs } = getListItemTextStyleMarks(node, textStyleType);
52764
- const styleMarks = allMarks.filter((m2) => m2.type === textStyleType);
52765
- const sizeMark = styleMarks.find((m2) => m2.attrs.fontSize);
52766
- const familyMark = styleMarks.find((m2) => m2.attrs.fontFamily);
52767
- const lineHeight2 = allAttrs.lineHeight;
52768
- let fontSize2 = sizeMark ? (() => {
52769
- const [value, unit = "pt"] = parseSizeUnit(sizeMark.attrs.fontSize);
52770
- return Number.isNaN(value) ? defaultSize : `${value}${unit}`;
52771
- })() : defaultSize;
52772
- let fontFamily2 = familyMark?.attrs.fontFamily ?? defaultFont;
52773
- const firstChild = node.firstChild;
52774
- const hasOnlyOnePar = node.childCount === 1 && firstChild?.type.name === "paragraph";
52775
- if (hasOnlyOnePar) {
52776
- const par = firstChild;
52777
- const parFirstChild = par?.firstChild;
52778
- if (par?.childCount === 1 && parFirstChild?.type.name === "fieldAnnotation") {
52779
- const aFontSize = parFirstChild.attrs.fontSize;
52780
- const aFontFamily = parFirstChild.attrs.fontFamily;
52781
- if (!sizeMark && aFontSize) fontSize2 = aFontSize;
52782
- if (!familyMark && aFontFamily) fontFamily2 = aFontFamily;
52783
- }
52784
- }
52785
- return { fontSize: fontSize2, fontFamily: fontFamily2, lineHeight: lineHeight2 };
52786
- }
52787
- const getStylesFromLinkedStyles = ({ node, pos, editor }) => {
52788
- const { state: state2 } = editor.view;
52789
- const linkedStyles = LinkedStylesPluginKey.getState(state2)?.decorations;
52790
- const decorationsInPlace = linkedStyles?.find(pos, pos + node.nodeSize);
52791
- const predicates = [
52792
- (style22) => style22.includes("font-size") && style22.includes("font-family"),
52793
- (style22) => style22.includes("font-size"),
52794
- (style22) => style22.includes("font-family")
52795
- ];
52796
- let styleDeco;
52797
- for (const predicateFn of predicates) {
52798
- styleDeco = decorationsInPlace?.find((dec) => {
52799
- const style22 = dec.type.attrs?.style || "";
52800
- return style22 && predicateFn(style22);
52801
- });
52802
- if (styleDeco) break;
52803
- }
52804
- const style2 = styleDeco?.type.attrs?.style;
52805
- const stylesArray = style2?.split(";") || [];
52806
- const fontSizeFromStyles = stylesArray.find((s) => s.includes("font-size"))?.split(":")[1].trim();
52807
- const fontFamilyFromStyles = stylesArray.find((s) => s.includes("font-family"))?.split(":")[1].trim();
52808
- return {
52809
- font: fontFamilyFromStyles,
52810
- size: fontSizeFromStyles
52811
- };
52812
- };
52813
54597
  const getVisibleIndent = (stylePpr, numDefPpr, inlineIndent) => {
52814
54598
  const styleIndentTag = stylePpr?.elements?.find((el) => el.name === "w:ind") || {};
52815
54599
  const styleIndent = parseIndentElement(styleIndentTag);
@@ -53543,6 +55327,211 @@ const CommentsMark = Mark2.create({
53543
55327
  return [CommentMarkName, Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes)];
53544
55328
  }
53545
55329
  });
55330
+ const defaultTabDistance = 48;
55331
+ const defaultLineLength = 816;
55332
+ const getTabDecorations = (doc2, view, from2 = 0, to = null) => {
55333
+ const decorations = [];
55334
+ const paragraphCache = /* @__PURE__ */ new Map();
55335
+ const end2 = to ?? doc2.content.size;
55336
+ doc2.nodesBetween(from2, end2, (node, pos) => {
55337
+ if (node.type.name !== "tab") return;
55338
+ let extraStyles = "";
55339
+ const $pos = doc2.resolve(pos);
55340
+ const paragraphContext = getParagraphContext($pos, paragraphCache);
55341
+ if (!paragraphContext) return;
55342
+ try {
55343
+ const { tabStops, flattened, startPos } = paragraphContext;
55344
+ const entryIndex = flattened.findIndex((entry) => entry.pos === pos);
55345
+ if (entryIndex === -1) return;
55346
+ const indentWidth = getIndentWidth(view, startPos, paragraphContext.indent);
55347
+ const accumulatedTabWidth = paragraphContext.accumulatedTabWidth || 0;
55348
+ const currentWidth = indentWidth + measureRangeWidth(view, startPos + 1, pos) + accumulatedTabWidth;
55349
+ let tabWidth;
55350
+ if (tabStops.length) {
55351
+ const tabStop = tabStops.find((stop) => stop.pos > currentWidth && stop.val !== "clear");
55352
+ if (tabStop) {
55353
+ tabWidth = tabStop.pos - currentWidth;
55354
+ if (tabStop.val === "center" || tabStop.val === "end" || tabStop.val === "right") {
55355
+ const nextTabIndex = findNextTabIndex(flattened, entryIndex + 1);
55356
+ const segmentStartPos = pos + node.nodeSize;
55357
+ const segmentEndPos = nextTabIndex === -1 ? startPos + paragraphContext.paragraph.nodeSize - 1 : flattened[nextTabIndex].pos;
55358
+ const segmentWidth = measureRangeWidth(view, segmentStartPos, segmentEndPos);
55359
+ tabWidth -= tabStop.val === "center" ? segmentWidth / 2 : segmentWidth;
55360
+ } else if (tabStop.val === "decimal" || tabStop.val === "num") {
55361
+ const breakChar = tabStop.decimalChar || ".";
55362
+ const decimalPos = findDecimalBreakPos(flattened, entryIndex + 1, breakChar);
55363
+ const integralWidth = decimalPos ? measureRangeWidth(view, pos + node.nodeSize, decimalPos) : measureRangeWidth(view, pos + node.nodeSize, startPos + paragraphContext.paragraph.nodeSize - 1);
55364
+ tabWidth -= integralWidth;
55365
+ }
55366
+ if (tabStop.leader) {
55367
+ const leaderStyles = {
55368
+ dot: "border-bottom: 1px dotted black;",
55369
+ heavy: "border-bottom: 2px solid black;",
55370
+ hyphen: "border-bottom: 1px solid black;",
55371
+ middleDot: "border-bottom: 1px dotted black; margin-bottom: 2px;",
55372
+ underscore: "border-bottom: 1px solid black;"
55373
+ };
55374
+ extraStyles += leaderStyles[tabStop.leader] || "";
55375
+ }
55376
+ }
55377
+ }
55378
+ if (!tabWidth || tabWidth < 1) {
55379
+ tabWidth = defaultTabDistance - currentWidth % defaultLineLength % defaultTabDistance;
55380
+ if (tabWidth === 0) tabWidth = defaultTabDistance;
55381
+ }
55382
+ const tabHeight = calcTabHeight($pos);
55383
+ decorations.push(
55384
+ Decoration.node(pos, pos + node.nodeSize, {
55385
+ style: `width: ${tabWidth}px; height: ${tabHeight};${extraStyles}`
55386
+ })
55387
+ );
55388
+ paragraphContext.accumulatedTabWidth = accumulatedTabWidth + tabWidth;
55389
+ } catch (error) {
55390
+ console.error("tab decoration error", error);
55391
+ }
55392
+ });
55393
+ return decorations;
55394
+ };
55395
+ function getParagraphContext($pos, cache2) {
55396
+ for (let depth = $pos.depth; depth >= 0; depth--) {
55397
+ const node = $pos.node(depth);
55398
+ if (node?.type?.name === "paragraph") {
55399
+ const startPos = $pos.start(depth);
55400
+ if (!cache2.has(startPos)) {
55401
+ cache2.set(startPos, {
55402
+ paragraph: node,
55403
+ paragraphDepth: depth,
55404
+ startPos,
55405
+ indent: node.attrs?.indent || {},
55406
+ tabStops: Array.isArray(node.attrs?.tabStops) ? node.attrs.tabStops : [],
55407
+ flattened: flattenParagraph(node, startPos),
55408
+ accumulatedTabWidth: 0
55409
+ });
55410
+ }
55411
+ return cache2.get(startPos);
55412
+ }
55413
+ }
55414
+ return null;
55415
+ }
55416
+ function flattenParagraph(paragraph, paragraphStartPos) {
55417
+ const entries = [];
55418
+ const walk = (node, basePos) => {
55419
+ if (!node) return;
55420
+ if (node.type?.name === "run") {
55421
+ node.forEach((child, offset2) => {
55422
+ const childPos = basePos + offset2 + 1;
55423
+ walk(child, childPos);
55424
+ });
55425
+ return;
55426
+ }
55427
+ entries.push({ node, pos: basePos - 1 });
55428
+ };
55429
+ paragraph.forEach((child, offset2) => {
55430
+ const childPos = paragraphStartPos + offset2 + 1;
55431
+ walk(child, childPos);
55432
+ });
55433
+ return entries;
55434
+ }
55435
+ function findNextTabIndex(flattened, fromIndex) {
55436
+ for (let i = fromIndex; i < flattened.length; i++) {
55437
+ if (flattened[i]?.node?.type?.name === "tab") {
55438
+ return i;
55439
+ }
55440
+ }
55441
+ return -1;
55442
+ }
55443
+ function findDecimalBreakPos(flattened, startIndex, breakChar) {
55444
+ for (let i = startIndex; i < flattened.length; i++) {
55445
+ const entry = flattened[i];
55446
+ if (!entry) break;
55447
+ if (entry.node.type?.name === "tab") break;
55448
+ if (entry.node.type?.name === "text") {
55449
+ const index2 = entry.node.text?.indexOf(breakChar);
55450
+ if (index2 !== void 0 && index2 !== -1) {
55451
+ return entry.pos + index2 + 1;
55452
+ }
55453
+ }
55454
+ }
55455
+ return null;
55456
+ }
55457
+ function measureRangeWidth(view, from2, to) {
55458
+ if (!Number.isFinite(from2) || !Number.isFinite(to) || to <= from2) return 0;
55459
+ try {
55460
+ const range2 = document.createRange();
55461
+ const fromRef = view.domAtPos(from2);
55462
+ const toRef2 = view.domAtPos(to);
55463
+ range2.setStart(fromRef.node, fromRef.offset);
55464
+ range2.setEnd(toRef2.node, toRef2.offset);
55465
+ const rect = range2.getBoundingClientRect();
55466
+ range2.detach?.();
55467
+ return rect.width || 0;
55468
+ } catch {
55469
+ const startLeft = getLeftCoord(view, from2);
55470
+ const endLeft = getLeftCoord(view, to);
55471
+ if (startLeft == null || endLeft == null) return 0;
55472
+ return Math.max(0, endLeft - startLeft);
55473
+ }
55474
+ }
55475
+ function getIndentWidth(view, paragraphStartPos, indentAttrs = {}) {
55476
+ const marginLeft = getLeftCoord(view, paragraphStartPos);
55477
+ const lineLeft = getLeftCoord(view, paragraphStartPos + 1);
55478
+ if (marginLeft != null && lineLeft != null) {
55479
+ const diff = lineLeft - marginLeft;
55480
+ if (!Number.isNaN(diff) && Math.abs(diff) > 0.5) {
55481
+ return diff;
55482
+ }
55483
+ }
55484
+ return calculateIndentFallback(indentAttrs);
55485
+ }
55486
+ function calculateIndentFallback(indentAttrs = {}) {
55487
+ if (!indentAttrs) return 0;
55488
+ const left2 = Number(indentAttrs.left) || 0;
55489
+ const firstLine = Number(indentAttrs.firstLine) || 0;
55490
+ const hanging = Number(indentAttrs.hanging) || 0;
55491
+ let textIndent = 0;
55492
+ if (firstLine && hanging) {
55493
+ textIndent = firstLine - hanging;
55494
+ } else if (firstLine) {
55495
+ textIndent = firstLine;
55496
+ } else if (hanging) {
55497
+ textIndent = -hanging;
55498
+ } else if (typeof indentAttrs.textIndent === "string") {
55499
+ const match = indentAttrs.textIndent.match(/(-?\d*\.?\d+)in$/);
55500
+ if (match) {
55501
+ textIndent = Number(match[1]) * 96;
55502
+ }
55503
+ }
55504
+ if (textIndent) return left2 + textIndent;
55505
+ if (left2) return left2;
55506
+ return 0;
55507
+ }
55508
+ function getLeftCoord(view, pos) {
55509
+ if (!Number.isFinite(pos)) return null;
55510
+ try {
55511
+ return view.coordsAtPos(pos).left;
55512
+ } catch {
55513
+ try {
55514
+ const ref2 = view.domAtPos(pos);
55515
+ const range2 = document.createRange();
55516
+ range2.setStart(ref2.node, ref2.offset);
55517
+ range2.setEnd(ref2.node, ref2.offset);
55518
+ const rect = range2.getBoundingClientRect();
55519
+ range2.detach?.();
55520
+ return rect.left;
55521
+ } catch {
55522
+ return null;
55523
+ }
55524
+ }
55525
+ }
55526
+ function calcTabHeight(pos) {
55527
+ const ptToPxRatio = 1.333;
55528
+ const defaultFontSize = 16;
55529
+ const defaultLineHeight = 1.1;
55530
+ const blockParent2 = pos.node(1);
55531
+ const parentTextStyleMark = blockParent2.firstChild.marks.find((mark) => mark.type.name === "textStyle");
55532
+ const fontSize2 = parseInt(parentTextStyleMark?.attrs.fontSize) * ptToPxRatio || defaultFontSize;
55533
+ return `${fontSize2 * defaultLineHeight}px`;
55534
+ }
53546
55535
  const TabNode = Node$1.create({
53547
55536
  name: "tab",
53548
55537
  group: "inline",
@@ -53580,8 +55569,7 @@ const TabNode = Node$1.create({
53580
55569
  };
53581
55570
  },
53582
55571
  addPmPlugins() {
53583
- const { view, schema } = this.editor;
53584
- const domSerializer = DOMSerializer.fromSchema(schema);
55572
+ const { view } = this.editor;
53585
55573
  const tabPlugin = new Plugin({
53586
55574
  name: "tabPlugin",
53587
55575
  key: new PluginKey("tabPlugin"),
@@ -53591,10 +55579,7 @@ const TabNode = Node$1.create({
53591
55579
  },
53592
55580
  apply(tr, { decorations }, _oldState, newState) {
53593
55581
  if (!decorations) {
53594
- decorations = DecorationSet.create(
53595
- newState.doc,
53596
- getTabDecorations(newState.doc, StepMap.empty, view, domSerializer)
53597
- );
55582
+ decorations = DecorationSet.create(newState.doc, getTabDecorations(newState.doc, view));
53598
55583
  }
53599
55584
  if (!tr.docChanged) {
53600
55585
  return { decorations };
@@ -53634,8 +55619,7 @@ const TabNode = Node$1.create({
53634
55619
  rangesToRecalculate.forEach(([start2, end2]) => {
53635
55620
  const oldDecorations = decorations.find(start2, end2);
53636
55621
  decorations = decorations.remove(oldDecorations);
53637
- const invertMapping = tr.mapping.invert();
53638
- const newDecorations = getTabDecorations(newState.doc, invertMapping, view, domSerializer, start2, end2);
55622
+ const newDecorations = getTabDecorations(newState.doc, view, start2, end2);
53639
55623
  decorations = decorations.add(newState.doc, newDecorations);
53640
55624
  });
53641
55625
  return { decorations };
@@ -53650,156 +55634,6 @@ const TabNode = Node$1.create({
53650
55634
  return [tabPlugin];
53651
55635
  }
53652
55636
  });
53653
- const defaultTabDistance = 48;
53654
- const defaultLineLength = 816;
53655
- const getTabDecorations = (doc2, invertMapping, view, domSerializer, from2 = 0, to = null) => {
53656
- if (!to) {
53657
- to = doc2.content.size;
53658
- }
53659
- const nodeWidthCache = {};
53660
- let decorations = [];
53661
- doc2.nodesBetween(from2, to, (node, pos, parent) => {
53662
- if (node.type.name === "tab") {
53663
- let extraStyles = "";
53664
- const $pos = doc2.resolve(pos);
53665
- const tabIndex = $pos.index($pos.depth);
53666
- const fistlineIndent = parent.attrs?.indent?.firstLine || 0;
53667
- const currentWidth = calcChildNodesWidth(
53668
- parent,
53669
- pos - $pos.parentOffset,
53670
- 0,
53671
- tabIndex,
53672
- domSerializer,
53673
- view,
53674
- invertMapping,
53675
- nodeWidthCache
53676
- ) + fistlineIndent;
53677
- let tabWidth;
53678
- if ($pos.depth === 1 && parent.attrs.tabStops && parent.attrs.tabStops.length > 0) {
53679
- const tabStop = parent.attrs.tabStops.find((tabStop2) => tabStop2.pos > currentWidth && tabStop2.val !== "clear");
53680
- if (tabStop) {
53681
- tabWidth = tabStop.pos - currentWidth;
53682
- if (["end", "center"].includes(tabStop.val)) {
53683
- let nextTabIndex = tabIndex + 1;
53684
- while (nextTabIndex < parent.childCount && parent.child(nextTabIndex).type.name !== "tab") {
53685
- nextTabIndex++;
53686
- }
53687
- const tabSectionWidth = calcChildNodesWidth(
53688
- parent,
53689
- pos - $pos.parentOffset,
53690
- tabIndex,
53691
- nextTabIndex,
53692
- domSerializer,
53693
- view,
53694
- invertMapping,
53695
- nodeWidthCache
53696
- );
53697
- tabWidth -= tabStop.val === "end" ? tabSectionWidth : tabSectionWidth / 2;
53698
- } else if (["decimal", "num"].includes(tabStop.val)) {
53699
- const breakChar = ".";
53700
- let nodeIndex = tabIndex + 1;
53701
- let integralWidth = 0;
53702
- let nodePos = pos - $pos.parentOffset;
53703
- while (nodeIndex < parent.childCount) {
53704
- const node2 = parent.child(nodeIndex);
53705
- if (node2.type.name === "tab") {
53706
- break;
53707
- }
53708
- const oldPos = invertMapping.map(nodePos);
53709
- if (node2.type.name === "text" && node2.text.includes(breakChar)) {
53710
- const modifiedNode = node2.cut(0, node2.text.indexOf(breakChar));
53711
- integralWidth += calcNodeWidth(domSerializer, modifiedNode, view, oldPos);
53712
- break;
53713
- }
53714
- integralWidth += calcNodeWidth(domSerializer, node2, view, oldPos);
53715
- nodeWidthCache[nodePos] = integralWidth;
53716
- nodePos += node2.nodeSize;
53717
- nodeIndex += 1;
53718
- }
53719
- tabWidth -= integralWidth;
53720
- }
53721
- if (tabStop.leader) {
53722
- if (tabStop.leader === "dot") {
53723
- extraStyles += `border-bottom: 1px dotted black;`;
53724
- } else if (tabStop.leader === "heavy") {
53725
- extraStyles += `border-bottom: 2px solid black;`;
53726
- } else if (tabStop.leader === "hyphen") {
53727
- extraStyles += `border-bottom: 1px solid black;`;
53728
- } else if (tabStop.leader === "middleDot") {
53729
- extraStyles += `border-bottom: 1px dotted black; margin-bottom: 2px;`;
53730
- } else if (tabStop.leader === "underscore") {
53731
- extraStyles += `border-bottom: 1px solid black;`;
53732
- }
53733
- }
53734
- }
53735
- }
53736
- if (!tabWidth || tabWidth < 1) {
53737
- tabWidth = defaultTabDistance - currentWidth % defaultLineLength % defaultTabDistance;
53738
- if (tabWidth === 0) {
53739
- tabWidth = defaultTabDistance;
53740
- }
53741
- }
53742
- nodeWidthCache[pos] = tabWidth;
53743
- const tabHeight = calcTabHeight($pos);
53744
- decorations.push(
53745
- Decoration.node(pos, pos + node.nodeSize, {
53746
- style: `width: ${tabWidth}px; height: ${tabHeight};${extraStyles}`
53747
- })
53748
- );
53749
- }
53750
- });
53751
- return decorations;
53752
- };
53753
- function calcNodeWidth(domSerializer, node, view, oldPos) {
53754
- const oldDomNode = view.nodeDOM(oldPos);
53755
- const styleReference = oldDomNode ? oldDomNode.nodeName === "#text" ? oldDomNode.parentNode : oldDomNode : view.dom;
53756
- const temp = document.createElement("div");
53757
- const style2 = window.getComputedStyle(styleReference);
53758
- temp.style.cssText = `
53759
- position: absolute;
53760
- top: -9999px;
53761
- left: -9999px;
53762
- white-space: nowrap;
53763
- font-family: ${style2.fontFamily};
53764
- font-size: ${style2.fontSize};
53765
- font-weight: ${style2.fontWeight};
53766
- font-style: ${style2.fontStyle};
53767
- letter-spacing: ${style2.letterSpacing};
53768
- word-spacing: ${style2.wordSpacing};
53769
- text-transform: ${style2.textTransform};
53770
- display: inline-block;
53771
- `;
53772
- const domNode = domSerializer.serializeNode(node);
53773
- temp.appendChild(domNode);
53774
- document.body.appendChild(temp);
53775
- const width = temp.offsetWidth;
53776
- document.body.removeChild(temp);
53777
- return width;
53778
- }
53779
- function calcChildNodesWidth(parent, parentPos, startIndex, endIndex, domSerializer, view, invertMapping, nodeWidthCache) {
53780
- let pos = parentPos;
53781
- let width = 0;
53782
- for (let i = 0; i < endIndex; i++) {
53783
- const node = parent.child(i);
53784
- if (i >= startIndex) {
53785
- if (!nodeWidthCache[pos]) {
53786
- nodeWidthCache[pos] = calcNodeWidth(domSerializer, node, view, invertMapping.map(pos));
53787
- }
53788
- width += nodeWidthCache[pos];
53789
- }
53790
- pos += node.nodeSize;
53791
- }
53792
- return width;
53793
- }
53794
- function calcTabHeight(pos) {
53795
- const ptToPxRatio = 1.333;
53796
- const defaultFontSize = 16;
53797
- const defaultLineHeight = 1.1;
53798
- const blockParent2 = pos.node(1);
53799
- const parentTextStyleMark = blockParent2.firstChild.marks.find((mark) => mark.type.name === "textStyle");
53800
- const fontSize2 = parseInt(parentTextStyleMark?.attrs.fontSize) * ptToPxRatio || defaultFontSize;
53801
- return `${fontSize2 * defaultLineHeight}px`;
53802
- }
53803
55637
  const LineBreak = Node$1.create({
53804
55638
  name: "lineBreak",
53805
55639
  group: "inline",
@@ -59466,10 +61300,10 @@ const Image = Node$1.create({
59466
61300
  },
59467
61301
  padding: {
59468
61302
  default: {},
59469
- renderDOM: ({ size: size2 = {}, padding, marginOffset, transformData }) => {
61303
+ renderDOM: ({ size: size2 = {}, padding, marginOffset, transformData = {} }) => {
59470
61304
  let { left: left2 = 0, top: top2 = 0, bottom: bottom2 = 0, right: right2 = 0 } = padding ?? {};
59471
- const { rotation } = transformData ?? {};
59472
- const { height, width } = size2 ?? {};
61305
+ const { rotation } = transformData;
61306
+ const { height, width } = size2;
59473
61307
  if (rotation && height && width) {
59474
61308
  const { horizontal, vertical } = getRotationMargins(width, height, rotation);
59475
61309
  left2 += horizontal;
@@ -61260,6 +63094,30 @@ const TextStyle = Mark2.create({
61260
63094
  };
61261
63095
  }
61262
63096
  });
63097
+ function createCascadeToggleCommands({
63098
+ markName,
63099
+ setCommand,
63100
+ unsetCommand,
63101
+ toggleCommand,
63102
+ negationAttrs,
63103
+ isNegation,
63104
+ extendEmptyMarkRange
63105
+ } = {}) {
63106
+ if (!markName) throw new Error("createCascadeToggleCommands requires a markName");
63107
+ const capitalized = markName.charAt(0).toUpperCase() + markName.slice(1);
63108
+ const setName = setCommand ?? `set${capitalized}`;
63109
+ const unsetName = unsetCommand ?? `unset${capitalized}`;
63110
+ const toggleName = toggleCommand ?? `toggle${capitalized}`;
63111
+ const cascadeOptions = {};
63112
+ if (negationAttrs) cascadeOptions.negationAttrs = negationAttrs;
63113
+ if (typeof isNegation === "function") cascadeOptions.isNegation = isNegation;
63114
+ if (extendEmptyMarkRange !== void 0) cascadeOptions.extendEmptyMarkRange = extendEmptyMarkRange;
63115
+ return {
63116
+ [setName]: () => ({ commands: commands2 }) => commands2.setMark(markName),
63117
+ [unsetName]: () => ({ commands: commands2 }) => commands2.unsetMark(markName),
63118
+ [toggleName]: () => ({ commands: commands2 }) => commands2.toggleMarkCascade(markName, cascadeOptions)
63119
+ };
63120
+ }
61263
63121
  const Bold = Mark2.create({
61264
63122
  name: "bold",
61265
63123
  addOptions() {
@@ -61290,9 +63148,18 @@ const Bold = Mark2.create({
61290
63148
  ];
61291
63149
  },
61292
63150
  renderDOM({ htmlAttributes }) {
61293
- return ["strong", Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes), 0];
63151
+ const merged = Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes);
63152
+ const { value, ...rest } = merged || {};
63153
+ if (value === "0") {
63154
+ return ["span", rest, 0];
63155
+ }
63156
+ return ["strong", rest, 0];
61294
63157
  },
61295
63158
  addCommands() {
63159
+ const { setBold, unsetBold, toggleBold } = createCascadeToggleCommands({
63160
+ markName: this.name,
63161
+ negationAttrs: { value: "0" }
63162
+ });
61296
63163
  return {
61297
63164
  /**
61298
63165
  * Apply bold formatting
@@ -61301,21 +63168,21 @@ const Bold = Mark2.create({
61301
63168
  * editor.commands.setBold()
61302
63169
  * @note '0' renders as normal weight
61303
63170
  */
61304
- setBold: () => ({ commands: commands2 }) => commands2.setMark(this.name),
63171
+ setBold,
61305
63172
  /**
61306
63173
  * Remove bold formatting
61307
63174
  * @category Command
61308
63175
  * @example
61309
63176
  * editor.commands.unsetBold()
61310
63177
  */
61311
- unsetBold: () => ({ commands: commands2 }) => commands2.unsetMark(this.name),
63178
+ unsetBold,
61312
63179
  /**
61313
63180
  * Toggle bold formatting
61314
63181
  * @category Command
61315
63182
  * @example
61316
63183
  * editor.commands.toggleBold()
61317
63184
  */
61318
- toggleBold: () => ({ commands: commands2 }) => commands2.toggleMark(this.name)
63185
+ toggleBold
61319
63186
  };
61320
63187
  },
61321
63188
  addShortcuts() {
@@ -61332,6 +63199,22 @@ const Italic = Mark2.create({
61332
63199
  htmlAttributes: {}
61333
63200
  };
61334
63201
  },
63202
+ addAttributes() {
63203
+ return {
63204
+ /**
63205
+ * @category Attribute
63206
+ * @param {string} [value] - Italic toggle value ('0' renders as normal)
63207
+ */
63208
+ value: {
63209
+ default: null,
63210
+ renderDOM: (attrs) => {
63211
+ if (!attrs.value) return {};
63212
+ if (attrs.value === "0") return { style: "font-style: normal" };
63213
+ return {};
63214
+ }
63215
+ }
63216
+ };
63217
+ },
61335
63218
  parseDOM() {
61336
63219
  return [
61337
63220
  { tag: "i" },
@@ -61341,9 +63224,18 @@ const Italic = Mark2.create({
61341
63224
  ];
61342
63225
  },
61343
63226
  renderDOM({ htmlAttributes }) {
61344
- return ["em", Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes), 0];
63227
+ const merged = Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes);
63228
+ const { value, ...rest } = merged || {};
63229
+ if (value === "0") {
63230
+ return ["span", rest, 0];
63231
+ }
63232
+ return ["em", rest, 0];
61345
63233
  },
61346
63234
  addCommands() {
63235
+ const { setItalic, unsetItalic, toggleItalic } = createCascadeToggleCommands({
63236
+ markName: this.name,
63237
+ negationAttrs: { value: "0" }
63238
+ });
61347
63239
  return {
61348
63240
  /**
61349
63241
  * Apply italic formatting
@@ -61351,21 +63243,21 @@ const Italic = Mark2.create({
61351
63243
  * @example
61352
63244
  * editor.commands.setItalic()
61353
63245
  */
61354
- setItalic: () => ({ commands: commands2 }) => commands2.setMark(this.name),
63246
+ setItalic,
61355
63247
  /**
61356
63248
  * Remove italic formatting
61357
63249
  * @category Command
61358
63250
  * @example
61359
63251
  * editor.commands.unsetItalic()
61360
63252
  */
61361
- unsetItalic: () => ({ commands: commands2 }) => commands2.unsetMark(this.name),
63253
+ unsetItalic,
61362
63254
  /**
61363
63255
  * Toggle italic formatting
61364
63256
  * @category Command
61365
63257
  * @example
61366
63258
  * editor.commands.toggleItalic()
61367
63259
  */
61368
- toggleItalic: () => ({ commands: commands2 }) => commands2.toggleMark(this.name)
63260
+ toggleItalic
61369
63261
  };
61370
63262
  },
61371
63263
  addShortcuts() {
@@ -61390,7 +63282,16 @@ const Underline = Mark2.create({
61390
63282
  ];
61391
63283
  },
61392
63284
  renderDOM({ htmlAttributes }) {
61393
- return ["u", Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes), 0];
63285
+ const merged = Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes);
63286
+ const type2 = merged?.underlineType;
63287
+ const color = merged?.underlineColor;
63288
+ const css = getUnderlineCssString({ type: type2, color });
63289
+ const { style: style2, ...rest } = merged || {};
63290
+ const styleString = [style2, css].filter(Boolean).join("; ");
63291
+ if (type2 === "none") {
63292
+ return ["span", { ...rest, ...styleString ? { style: styleString } : {} }, 0];
63293
+ }
63294
+ return ["u", { ...rest, ...styleString ? { style: styleString } : {} }, 0];
61394
63295
  },
61395
63296
  addAttributes() {
61396
63297
  return {
@@ -61400,10 +63301,18 @@ const Underline = Mark2.create({
61400
63301
  */
61401
63302
  underlineType: {
61402
63303
  default: "single"
63304
+ },
63305
+ underlineColor: {
63306
+ default: null
61403
63307
  }
61404
63308
  };
61405
63309
  },
61406
63310
  addCommands() {
63311
+ const { setUnderline, unsetUnderline, toggleUnderline } = createCascadeToggleCommands({
63312
+ markName: this.name,
63313
+ negationAttrs: { underlineType: "none" },
63314
+ isNegation: (attrs) => attrs?.underlineType === "none"
63315
+ });
61407
63316
  return {
61408
63317
  /**
61409
63318
  * Apply underline formatting
@@ -61412,7 +63321,7 @@ const Underline = Mark2.create({
61412
63321
  * @example
61413
63322
  * setUnderline()
61414
63323
  */
61415
- setUnderline: () => ({ commands: commands2 }) => commands2.setMark(this.name),
63324
+ setUnderline,
61416
63325
  /**
61417
63326
  * Remove underline formatting
61418
63327
  * @category Command
@@ -61420,7 +63329,7 @@ const Underline = Mark2.create({
61420
63329
  * @example
61421
63330
  * unsetUnderline()
61422
63331
  */
61423
- unsetUnderline: () => ({ commands: commands2 }) => commands2.unsetMark(this.name),
63332
+ unsetUnderline,
61424
63333
  /**
61425
63334
  * Toggle underline formatting
61426
63335
  * @category Command
@@ -61428,7 +63337,7 @@ const Underline = Mark2.create({
61428
63337
  * @example
61429
63338
  * toggleUnderline()
61430
63339
  */
61431
- toggleUnderline: () => ({ commands: commands2 }) => commands2.toggleMark(this.name)
63340
+ toggleUnderline
61432
63341
  };
61433
63342
  },
61434
63343
  addShortcuts() {
@@ -61516,9 +63425,18 @@ const Strike = Mark2.create({
61516
63425
  ];
61517
63426
  },
61518
63427
  renderDOM({ htmlAttributes }) {
61519
- return ["s", Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes), 0];
63428
+ const merged = Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes);
63429
+ const { value, ...rest } = merged || {};
63430
+ if (value === "0") {
63431
+ return ["span", rest, 0];
63432
+ }
63433
+ return ["s", rest, 0];
61520
63434
  },
61521
63435
  addCommands() {
63436
+ const { setStrike, unsetStrike, toggleStrike } = createCascadeToggleCommands({
63437
+ markName: this.name,
63438
+ negationAttrs: { value: "0" }
63439
+ });
61522
63440
  return {
61523
63441
  /**
61524
63442
  * Apply strikethrough formatting
@@ -61526,26 +63444,38 @@ const Strike = Mark2.create({
61526
63444
  * @example
61527
63445
  * editor.commands.setStrike()
61528
63446
  */
61529
- setStrike: () => ({ commands: commands2 }) => {
61530
- return commands2.setMark(this.name);
61531
- },
63447
+ setStrike,
61532
63448
  /**
61533
63449
  * Remove strikethrough formatting
61534
63450
  * @category Command
61535
63451
  * @example
61536
63452
  * editor.commands.unsetStrike()
61537
63453
  */
61538
- unsetStrike: () => ({ commands: commands2 }) => {
61539
- return commands2.unsetMark(this.name);
61540
- },
63454
+ unsetStrike,
61541
63455
  /**
61542
63456
  * Toggle strikethrough formatting
61543
63457
  * @category Command
61544
63458
  * @example
61545
63459
  * editor.commands.toggleStrike()
61546
63460
  */
61547
- toggleStrike: () => ({ commands: commands2 }) => {
61548
- return commands2.toggleMark(this.name);
63461
+ toggleStrike
63462
+ };
63463
+ },
63464
+ addAttributes() {
63465
+ return {
63466
+ /**
63467
+ * @category Attribute
63468
+ * @param {string} [value] - Strike toggle value ('0' renders as normal)
63469
+ */
63470
+ value: {
63471
+ default: null,
63472
+ renderDOM: (attrs) => {
63473
+ if (!attrs.value) return {};
63474
+ if (attrs.value === "0") {
63475
+ return { style: "text-decoration: none" };
63476
+ }
63477
+ return {};
63478
+ }
61549
63479
  }
61550
63480
  };
61551
63481
  },
@@ -67686,7 +69616,7 @@ const getStarterExtensions = () => {
67686
69616
  Paragraph,
67687
69617
  LineBreak,
67688
69618
  HardBreak,
67689
- RunItem,
69619
+ Run,
67690
69620
  SlashMenu,
67691
69621
  Strike,
67692
69622
  TabNode,
@@ -80914,6 +82844,38 @@ const toolbarTexts = {
80914
82844
  documentViewingModeDescription: "View clean version of document only",
80915
82845
  linkedStyles: "Linked styles"
80916
82846
  };
82847
+ const isOffValue = (value) => {
82848
+ if (value == null) return false;
82849
+ const normalized = String(value).toLowerCase();
82850
+ return normalized === "0" || normalized === "false" || normalized === "off";
82851
+ };
82852
+ const negationChecks = {
82853
+ bold: (attrs = {}) => isOffValue(attrs.value),
82854
+ italic: (attrs = {}) => isOffValue(attrs.value),
82855
+ strike: (attrs = {}) => isOffValue(attrs.value),
82856
+ underline: (attrs = {}) => {
82857
+ const type2 = attrs.underlineType ?? attrs.value;
82858
+ if (type2 == null) return false;
82859
+ const normalized = String(type2).toLowerCase();
82860
+ return normalized === "none" || isOffValue(normalized);
82861
+ },
82862
+ color: (attrs = {}) => {
82863
+ const value = attrs.color;
82864
+ if (value == null) return true;
82865
+ return String(value).toLowerCase() === "inherit";
82866
+ },
82867
+ highlight: (attrs = {}) => {
82868
+ const value = attrs.color;
82869
+ if (value == null) return true;
82870
+ const normalized = String(value).toLowerCase();
82871
+ return normalized === "transparent" || normalized === "none";
82872
+ }
82873
+ };
82874
+ const isNegatedMark = (name, attrs = {}) => {
82875
+ const checker = negationChecks[name];
82876
+ if (typeof checker !== "function") return false;
82877
+ return Boolean(checker(attrs));
82878
+ };
80917
82879
  class SuperToolbar extends EventEmitter2 {
80918
82880
  /**
80919
82881
  * Creates a new SuperToolbar instance
@@ -81007,10 +82969,14 @@ class SuperToolbar extends EventEmitter2 {
81007
82969
  * @param {string} params.argument - The color to set
81008
82970
  * @returns {void}
81009
82971
  */
81010
- setColor: ({ item, argument }) => {
81011
- __privateMethod(this, _SuperToolbar_instances, runCommandWithArgumentOnly_fn).call(this, { item, argument }, () => {
81012
- this.activeEditor?.commands.setFieldAnnotationsTextColor(argument, true);
81013
- });
82972
+ setColor: ({ argument }) => {
82973
+ if (!argument || !this.activeEditor) return;
82974
+ const isNone = argument === "none";
82975
+ const value = isNone ? "inherit" : argument;
82976
+ if (this.activeEditor?.commands?.setColor) this.activeEditor.commands.setColor(value);
82977
+ const argValue = isNone ? null : argument;
82978
+ this.activeEditor?.commands.setFieldAnnotationsTextColor(argValue, true);
82979
+ this.updateToolbarState();
81014
82980
  },
81015
82981
  /**
81016
82982
  * Sets the highlight color for text
@@ -81019,12 +82985,14 @@ class SuperToolbar extends EventEmitter2 {
81019
82985
  * @param {string} params.argument - The highlight color to set
81020
82986
  * @returns {void}
81021
82987
  */
81022
- setHighlight: ({ item, argument }) => {
81023
- __privateMethod(this, _SuperToolbar_instances, runCommandWithArgumentOnly_fn).call(this, { item, argument, noArgumentCallback: true }, () => {
81024
- let arg = argument !== "none" ? argument : null;
81025
- this.activeEditor?.commands.setFieldAnnotationsTextHighlight(arg, true);
81026
- this.activeEditor?.commands.setCellBackground(arg);
81027
- });
82988
+ setHighlight: ({ argument }) => {
82989
+ if (!argument || !this.activeEditor) return;
82990
+ const inlineColor = argument !== "none" ? argument : "transparent";
82991
+ if (this.activeEditor?.commands?.setHighlight) this.activeEditor.commands.setHighlight(inlineColor);
82992
+ const argValue = argument !== "none" ? argument : null;
82993
+ this.activeEditor?.commands.setFieldAnnotationsTextHighlight(argValue, true);
82994
+ this.activeEditor?.commands.setCellBackground(argValue);
82995
+ this.updateToolbarState();
81028
82996
  },
81029
82997
  /**
81030
82998
  * Toggles the ruler visibility
@@ -81341,14 +83309,16 @@ class SuperToolbar extends EventEmitter2 {
81341
83309
  return item.activate();
81342
83310
  }
81343
83311
  }
81344
- const activeMark = marks.find((mark) => mark.name === item.name.value);
83312
+ const rawActiveMark = marks.find((mark) => mark.name === item.name.value);
83313
+ const markNegated = rawActiveMark ? isNegatedMark(rawActiveMark.name, rawActiveMark.attrs) : false;
83314
+ const activeMark = markNegated ? null : rawActiveMark;
81345
83315
  if (activeMark) {
81346
83316
  item.activate(activeMark.attrs);
81347
83317
  } else {
81348
83318
  item.deactivate();
81349
83319
  }
81350
83320
  const styleIdMark = marks.find((mark) => mark.name === "styleId");
81351
- if (!activeMark && styleIdMark?.attrs.styleId) {
83321
+ if (!activeMark && !markNegated && styleIdMark?.attrs.styleId) {
81352
83322
  const markToStyleMap = {
81353
83323
  fontSize: "font-size",
81354
83324
  fontFamily: "font-family",
@@ -81406,7 +83376,6 @@ class SuperToolbar extends EventEmitter2 {
81406
83376
  if (!command2) {
81407
83377
  return;
81408
83378
  }
81409
- this.log("(emmitCommand) Command:", command2, "\n item:", item, "\n argument:", argument, "\n option:", option);
81410
83379
  if (command2 in __privateGet(this, _interceptedCommands)) {
81411
83380
  return __privateGet(this, _interceptedCommands)[command2]({ item, argument });
81412
83381
  }
@@ -82969,6 +84938,36 @@ const _sfc_main = {
82969
84938
  }
82970
84939
  };
82971
84940
  const SuperInput = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-4d5cff52"]]);
84941
+ const baseHandlers = {
84942
+ ...runPropertyTranslators,
84943
+ "w:br": translator$15,
84944
+ "w:cantSplit": translator$S,
84945
+ "w:cnfStyle": translator$R,
84946
+ "w:divId": translator$Q,
84947
+ "w:gridAfter": translator$P,
84948
+ "w:gridBefore": translator$O,
84949
+ "w:hidden": translator$N,
84950
+ "w:hyperlink": translator$6,
84951
+ "w:jc": translator$M,
84952
+ "w:p": translator$12,
84953
+ "w:r": translator$T,
84954
+ "w:rPr": translator$U,
84955
+ "w:sdt": translator$2,
84956
+ "w:tab": translator$13,
84957
+ "w:tblCellSpacing": translator$L,
84958
+ "w:tblHeader": translator$K,
84959
+ "w:tc": translator$7,
84960
+ "w:tr": translator$F,
84961
+ "w:trHeight": translator$J,
84962
+ "w:trPr": translator$G,
84963
+ "w:wAfter": translator$I,
84964
+ "w:wBefore": translator$H,
84965
+ "wp:anchor": translator$5,
84966
+ "wp:inline": translator$4,
84967
+ "w:bookmarkStart": translator$1,
84968
+ "w:bookmarkEnd": translator
84969
+ };
84970
+ const registeredHandlers = Object.freeze(baseHandlers);
82972
84971
  const Extensions = {
82973
84972
  Node: Node$1,
82974
84973
  Attribute: Attribute2,