@harbour-enterprises/superdoc 0.20.0-next.14 → 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 (107) hide show
  1. package/dist/chunks/{PdfViewer-_NPRPRHl.es.js → PdfViewer-D3gJ5ozH.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer-D-erp24R.cjs → PdfViewer-DuEWa8ox.cjs} +1 -1
  3. package/dist/chunks/{index-duHcNiwD.cjs → index-D2h9q27o.cjs} +31 -8
  4. package/dist/chunks/{index-dMbV_syB.es.js → index-DiSIyVKk.es.js} +31 -8
  5. package/dist/chunks/{super-editor.es-BKurmwFy.es.js → super-editor.es-4Ig7dBJr.es.js} +2846 -851
  6. package/dist/chunks/{super-editor.es-ly_a915J.cjs → super-editor.es-lzaBZOn2.cjs} +2846 -851
  7. package/dist/core/SuperDoc.d.ts.map +1 -1
  8. package/dist/stores/comments-store.d.ts.map +1 -1
  9. package/dist/super-editor/ai-writer.es.js +2 -2
  10. package/dist/super-editor/chunks/{converter-Brf9NxwA.js → converter-BJVy6JMW.js} +1971 -636
  11. package/dist/super-editor/chunks/{docx-zipper-Dld3TtPb.js → docx-zipper-DWDJGX0b.js} +1 -1
  12. package/dist/super-editor/chunks/{editor-N0dhAC41.js → editor-BUCOmU2Y.js} +1026 -410
  13. package/dist/super-editor/chunks/{toolbar-CXinz1gO.js → toolbar-CiBIcgiI.js} +2 -2
  14. package/dist/super-editor/converter.es.js +1 -1
  15. package/dist/super-editor/docx-zipper.es.js +2 -2
  16. package/dist/super-editor/editor.es.js +3 -3
  17. package/dist/super-editor/file-zipper.es.js +1 -1
  18. package/dist/super-editor/src/components/toolbar/format-negation.d.ts +5 -0
  19. package/dist/super-editor/src/core/commands/index.d.ts +1 -0
  20. package/dist/super-editor/src/core/commands/toggleMarkCascade.d.ts +42 -0
  21. package/dist/super-editor/src/core/commands/types/index.d.ts +29 -1
  22. package/dist/super-editor/src/core/super-converter/SuperConverter.d.ts +5 -0
  23. package/dist/super-editor/src/core/super-converter/exporter.d.ts +8 -0
  24. package/dist/super-editor/src/core/super-converter/helpers.d.ts +2 -0
  25. package/dist/super-editor/src/core/super-converter/v2/importer/markImporter.d.ts +12 -0
  26. package/dist/super-editor/src/core/super-converter/v2/importer/runNodeImporter.d.ts +6 -6
  27. package/dist/super-editor/src/core/super-converter/v3/handlers/constants/east-asian-regex.d.ts +1 -0
  28. package/dist/super-editor/src/core/super-converter/v3/handlers/constants/index.d.ts +1 -0
  29. package/dist/super-editor/src/core/super-converter/v3/handlers/index.d.ts +2 -12
  30. package/dist/super-editor/src/core/super-converter/v3/handlers/w/b/attributes/index.d.ts +3 -0
  31. package/dist/super-editor/src/core/super-converter/v3/handlers/w/b/attributes/w-val.d.ts +4 -0
  32. package/dist/super-editor/src/core/super-converter/v3/handlers/w/b/b-translator.d.ts +7 -0
  33. package/dist/super-editor/src/core/super-converter/v3/handlers/w/b/index.d.ts +1 -0
  34. package/dist/super-editor/src/core/super-converter/v3/handlers/w/color/attributes/index.d.ts +2 -0
  35. package/dist/super-editor/src/core/super-converter/v3/handlers/w/color/attributes/w-theme-color.d.ts +4 -0
  36. package/dist/super-editor/src/core/super-converter/v3/handlers/w/color/attributes/w-theme-shade.d.ts +4 -0
  37. package/dist/super-editor/src/core/super-converter/v3/handlers/w/color/attributes/w-theme-tint.d.ts +4 -0
  38. package/dist/super-editor/src/core/super-converter/v3/handlers/w/color/attributes/w-val.d.ts +4 -0
  39. package/dist/super-editor/src/core/super-converter/v3/handlers/w/color/color-translator.d.ts +7 -0
  40. package/dist/super-editor/src/core/super-converter/v3/handlers/w/highlight/attributes/index.d.ts +2 -0
  41. package/dist/super-editor/src/core/super-converter/v3/handlers/w/highlight/attributes/w-val.d.ts +4 -0
  42. package/dist/super-editor/src/core/super-converter/v3/handlers/w/highlight/highlight-translator.d.ts +4 -0
  43. package/dist/super-editor/src/core/super-converter/v3/handlers/w/i/attributes/index.d.ts +2 -0
  44. package/dist/super-editor/src/core/super-converter/v3/handlers/w/i/attributes/w-val.d.ts +4 -0
  45. package/dist/super-editor/src/core/super-converter/v3/handlers/w/i/i-translator.d.ts +7 -0
  46. package/dist/super-editor/src/core/super-converter/v3/handlers/w/r/attributes/index.d.ts +2 -0
  47. package/dist/super-editor/src/core/super-converter/v3/handlers/w/r/attributes/w-rsid-del.d.ts +4 -0
  48. package/dist/super-editor/src/core/super-converter/v3/handlers/w/r/attributes/w-rsid-r-pr.d.ts +4 -0
  49. package/dist/super-editor/src/core/super-converter/v3/handlers/w/r/attributes/w-rsid-r.d.ts +4 -0
  50. package/dist/super-editor/src/core/super-converter/v3/handlers/w/r/helpers/helpers.d.ts +40 -0
  51. package/dist/super-editor/src/core/super-converter/v3/handlers/w/r/helpers/index.d.ts +3 -0
  52. package/dist/super-editor/src/core/super-converter/v3/handlers/w/r/helpers/split-run-properties.d.ts +9 -0
  53. package/dist/super-editor/src/core/super-converter/v3/handlers/w/r/helpers/track-change-helpers.d.ts +5 -0
  54. package/dist/super-editor/src/core/super-converter/v3/handlers/w/r/index.d.ts +1 -0
  55. package/dist/super-editor/src/core/super-converter/v3/handlers/w/r/r-translator.d.ts +4 -0
  56. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rFonts/attributes/index.d.ts +2 -0
  57. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rFonts/attributes/w-ascii.d.ts +4 -0
  58. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rFonts/attributes/w-cs.d.ts +4 -0
  59. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rFonts/attributes/w-east-asia.d.ts +4 -0
  60. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rFonts/attributes/w-hansi.d.ts +4 -0
  61. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rFonts/attributes/w-val.d.ts +4 -0
  62. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rFonts/index.d.ts +1 -0
  63. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rFonts/rFonts-translator.d.ts +5 -0
  64. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rStyle/attributes/index.d.ts +2 -0
  65. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rStyle/attributes/w-val.d.ts +4 -0
  66. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rStyle/index.d.ts +1 -0
  67. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rStyle/rstyle-translator.d.ts +7 -0
  68. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rpr/index.d.ts +1 -0
  69. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rpr/rpr-translator.d.ts +5 -0
  70. package/dist/super-editor/src/core/super-converter/v3/handlers/w/rpr/run-property-translators.d.ts +11 -0
  71. package/dist/super-editor/src/core/super-converter/v3/handlers/w/strike/attributes/index.d.ts +2 -0
  72. package/dist/super-editor/src/core/super-converter/v3/handlers/w/strike/attributes/w-val.d.ts +4 -0
  73. package/dist/super-editor/src/core/super-converter/v3/handlers/w/strike/strike-translator.d.ts +7 -0
  74. package/dist/super-editor/src/core/super-converter/v3/handlers/w/sz/attributes/index.d.ts +2 -0
  75. package/dist/super-editor/src/core/super-converter/v3/handlers/w/sz/attributes/w-val.d.ts +4 -0
  76. package/dist/super-editor/src/core/super-converter/v3/handlers/w/sz/sz-translator.d.ts +4 -0
  77. package/dist/super-editor/src/core/super-converter/v3/handlers/w/szcs/attributes/index.d.ts +2 -0
  78. package/dist/super-editor/src/core/super-converter/v3/handlers/w/szcs/attributes/w-val.d.ts +4 -0
  79. package/dist/super-editor/src/core/super-converter/v3/handlers/w/szcs/szcs-translator.d.ts +4 -0
  80. package/dist/super-editor/src/core/super-converter/v3/handlers/w/u/attributes/index.d.ts +2 -0
  81. package/dist/super-editor/src/core/super-converter/v3/handlers/w/u/attributes/w-color.d.ts +4 -0
  82. package/dist/super-editor/src/core/super-converter/v3/handlers/w/u/attributes/w-theme-color.d.ts +4 -0
  83. package/dist/super-editor/src/core/super-converter/v3/handlers/w/u/attributes/w-theme-shade.d.ts +4 -0
  84. package/dist/super-editor/src/core/super-converter/v3/handlers/w/u/attributes/w-theme-tint.d.ts +4 -0
  85. package/dist/super-editor/src/core/super-converter/v3/handlers/w/u/attributes/w-val.d.ts +4 -0
  86. package/dist/super-editor/src/core/super-converter/v3/handlers/w/u/u-translator.d.ts +7 -0
  87. package/dist/super-editor/src/extensions/index.d.ts +2 -2
  88. package/dist/super-editor/src/extensions/linked-styles/index.d.ts +1 -0
  89. package/dist/super-editor/src/extensions/linked-styles/underline-css.d.ts +17 -0
  90. package/dist/super-editor/src/extensions/list-item/helpers/listItemTypography.d.ts +62 -0
  91. package/dist/super-editor/src/extensions/run/commands/index.d.ts +1 -0
  92. package/dist/super-editor/src/extensions/run/commands/split-run.d.ts +1 -0
  93. package/dist/super-editor/src/extensions/run/index.d.ts +1 -0
  94. package/dist/super-editor/src/extensions/run/run.d.ts +6 -0
  95. package/dist/super-editor/src/extensions/shared/cascade-toggle.d.ts +8 -0
  96. package/dist/super-editor/src/extensions/tab/helpers/tabDecorations.d.ts +12 -0
  97. package/dist/super-editor/src/extensions/tab/tab.d.ts +4 -0
  98. package/dist/super-editor/src/tests/helpers/getParagraphText.d.ts +2 -0
  99. package/dist/super-editor/super-editor.es.js +90 -21
  100. package/dist/super-editor/toolbar.es.js +2 -2
  101. package/dist/super-editor.cjs +1 -1
  102. package/dist/super-editor.es.js +1 -1
  103. package/dist/superdoc.cjs +2 -2
  104. package/dist/superdoc.es.js +2 -2
  105. package/dist/superdoc.umd.js +2877 -859
  106. package/dist/superdoc.umd.js.map +1 -1
  107. package/package.json +1 -1
@@ -14886,25 +14886,47 @@ const getContentTypesFromXml = (contentTypesXml) => {
14886
14886
  const defaults = xmlDoc.querySelectorAll("Default");
14887
14887
  return Array.from(defaults).map((item) => item.getAttribute("Extension"));
14888
14888
  };
14889
+ const DOCX_HIGHLIGHT_KEYWORD_MAP = /* @__PURE__ */ new Map([
14890
+ ["yellow", "FFFF00"],
14891
+ ["green", "00FF00"],
14892
+ ["blue", "0000FF"],
14893
+ ["cyan", "00FFFF"],
14894
+ ["magenta", "FF00FF"],
14895
+ ["red", "FF0000"],
14896
+ ["darkYellow", "808000"],
14897
+ ["darkGreen", "008000"],
14898
+ ["darkBlue", "000080"],
14899
+ ["darkCyan", "008080"],
14900
+ ["darkMagenta", "800080"],
14901
+ ["darkGray", "808080"],
14902
+ ["darkRed", "800000"],
14903
+ ["lightGray", "C0C0C0"],
14904
+ ["black", "000000"],
14905
+ ["white", "FFFFFF"]
14906
+ ]);
14907
+ const normalizeHexColor = (hex) => {
14908
+ if (!hex) return null;
14909
+ let value = hex.replace("#", "").trim();
14910
+ if (!value) return null;
14911
+ value = value.toUpperCase();
14912
+ if (value.length === 3)
14913
+ value = value.split("").map((c) => c + c).join("");
14914
+ if (value.length === 8) value = value.slice(0, 6);
14915
+ return value;
14916
+ };
14889
14917
  const getHexColorFromDocxSystem = (docxColor) => {
14890
- const colorMap = /* @__PURE__ */ new Map([
14891
- ["yellow", "#ffff00"],
14892
- ["green", "#00ff00"],
14893
- ["blue", "#0000FFFF"],
14894
- ["cyan", "#00ffff"],
14895
- ["magenta", "#ff00ff"],
14896
- ["red", "#ff0000"],
14897
- ["darkYellow", "#808000FF"],
14898
- ["darkGreen", "#008000FF"],
14899
- ["darkBlue", "#000080"],
14900
- ["darkCyan", "#008080FF"],
14901
- ["darkMagenta", "#800080FF"],
14902
- ["darkGray", "#808080FF"],
14903
- ["darkRed", "#800000FF"],
14904
- ["lightGray", "#C0C0C0FF"],
14905
- ["black", "#000"]
14906
- ]);
14907
- return colorMap.get(docxColor) || null;
14918
+ const hex = DOCX_HIGHLIGHT_KEYWORD_MAP.get(docxColor);
14919
+ return hex ? `#${hex}` : null;
14920
+ };
14921
+ const getDocxHighlightKeywordFromHex = (hexColor) => {
14922
+ if (!hexColor) return null;
14923
+ if (DOCX_HIGHLIGHT_KEYWORD_MAP.has(hexColor)) return hexColor;
14924
+ const normalized = normalizeHexColor(hexColor);
14925
+ if (!normalized) return null;
14926
+ for (const [keyword, hex] of DOCX_HIGHLIGHT_KEYWORD_MAP.entries()) {
14927
+ if (hex === normalized) return keyword;
14928
+ }
14929
+ return null;
14908
14930
  };
14909
14931
  function isValidHexColor(color) {
14910
14932
  if (!color || typeof color !== "string") return false;
@@ -24301,37 +24323,37 @@ const _NodeTranslator = class _NodeTranslator {
24301
24323
  /** @type {typeof TranslatorTypes} */
24302
24324
  __publicField(_NodeTranslator, "translatorTypes", TranslatorTypes);
24303
24325
  let NodeTranslator = _NodeTranslator;
24304
- const encode$A = (attributes) => {
24326
+ const encode$17 = (attributes) => {
24305
24327
  return attributes["w:type"];
24306
24328
  };
24307
- const decode$A = (attrs) => {
24329
+ const decode$_ = (attrs) => {
24308
24330
  const { lineBreakType } = attrs;
24309
24331
  return lineBreakType;
24310
24332
  };
24311
- const attrConfig$i = Object.freeze({
24333
+ const attrConfig$F = Object.freeze({
24312
24334
  xmlName: "w:type",
24313
24335
  sdName: "lineBreakType",
24314
- encode: encode$A,
24315
- decode: decode$A
24336
+ encode: encode$17,
24337
+ decode: decode$_
24316
24338
  });
24317
- const encode$z = (attributes) => {
24339
+ const encode$16 = (attributes) => {
24318
24340
  const xmlAttrValue = attributes["w:clear"];
24319
24341
  return xmlAttrValue;
24320
24342
  };
24321
- const decode$z = (attrs) => {
24343
+ const decode$Z = (attrs) => {
24322
24344
  const { clear } = attrs;
24323
24345
  return clear;
24324
24346
  };
24325
- const attrConfig$h = Object.freeze({
24347
+ const attrConfig$E = Object.freeze({
24326
24348
  xmlName: "w:clear",
24327
24349
  sdName: "clear",
24328
- encode: encode$z,
24329
- decode: decode$z
24350
+ encode: encode$16,
24351
+ decode: decode$Z
24330
24352
  });
24331
- const validXmlAttributes$b = [attrConfig$i, attrConfig$h];
24332
- const XML_NODE_NAME$h = "w:br";
24353
+ const validXmlAttributes$l = [attrConfig$F, attrConfig$E];
24354
+ const XML_NODE_NAME$t = "w:br";
24333
24355
  const SD_NODE_NAME$c = "lineBreak";
24334
- const encode$y = (_2, encodedAttrs) => {
24356
+ const encode$15 = (_2, encodedAttrs) => {
24335
24357
  const isPageBreak = encodedAttrs?.lineBreakType === "page";
24336
24358
  const translated = {
24337
24359
  type: isPageBreak ? "hardBreak" : "lineBreak"
@@ -24341,7 +24363,7 @@ const encode$y = (_2, encodedAttrs) => {
24341
24363
  }
24342
24364
  return translated;
24343
24365
  };
24344
- const decode$y = (params, decodedAttrs) => {
24366
+ const decode$Y = (params, decodedAttrs) => {
24345
24367
  const { node } = params;
24346
24368
  if (!node) return;
24347
24369
  const wBreak = { name: "w:br" };
@@ -24358,63 +24380,125 @@ const decode$y = (params, decodedAttrs) => {
24358
24380
  };
24359
24381
  return translated;
24360
24382
  };
24361
- const config$f = {
24362
- xmlName: XML_NODE_NAME$h,
24383
+ const config$r = {
24384
+ xmlName: XML_NODE_NAME$t,
24363
24385
  sdNodeOrKeyName: SD_NODE_NAME$c,
24364
24386
  type: NodeTranslator.translatorTypes.NODE,
24365
- encode: encode$y,
24366
- decode: decode$y,
24367
- attributes: validXmlAttributes$b
24387
+ encode: encode$15,
24388
+ decode: decode$Y,
24389
+ attributes: validXmlAttributes$l
24390
+ };
24391
+ const translator$15 = NodeTranslator.from(config$r);
24392
+ const encode$14 = (attributes) => attributes?.["w:val"];
24393
+ const decode$X = (attrs) => attrs?.highlight;
24394
+ const attrConfig$D = Object.freeze({
24395
+ xmlName: "w:val",
24396
+ sdName: "highlight",
24397
+ encode: encode$14,
24398
+ decode: decode$X
24399
+ });
24400
+ const validXmlAttributes$k = [attrConfig$D];
24401
+ const XML_NODE_NAME$s = "w:highlight";
24402
+ const SD_ATTR_KEY$f = "highlight";
24403
+ const DISABLED_TOKENS = /* @__PURE__ */ new Set(["transparent", "none", "inherit"]);
24404
+ const encode$13 = (params, encodedAttrs = {}) => {
24405
+ const { nodes } = params;
24406
+ const node = nodes?.[0];
24407
+ const value = encodedAttrs.highlight ?? node?.attributes?.["w:val"];
24408
+ return {
24409
+ type: "attr",
24410
+ xmlName: XML_NODE_NAME$s,
24411
+ sdNodeOrKeyName: SD_ATTR_KEY$f,
24412
+ attributes: { "w:val": value ?? null }
24413
+ };
24414
+ };
24415
+ const decode$W = (params) => {
24416
+ const attrs = params?.node?.attrs || {};
24417
+ const highlightValue = attrs.highlight ?? attrs.color ?? null;
24418
+ if (!highlightValue) return void 0;
24419
+ const normalizedValue = String(highlightValue).trim().toLowerCase();
24420
+ if (!normalizedValue) return void 0;
24421
+ if (DISABLED_TOKENS.has(normalizedValue)) {
24422
+ return {
24423
+ name: XML_NODE_NAME$s,
24424
+ attributes: { "w:val": "none" }
24425
+ };
24426
+ }
24427
+ const keyword = getDocxHighlightKeywordFromHex(highlightValue);
24428
+ if (keyword) {
24429
+ return {
24430
+ name: XML_NODE_NAME$s,
24431
+ attributes: { "w:val": keyword }
24432
+ };
24433
+ }
24434
+ const fill = normalizeHexColor(highlightValue);
24435
+ if (!fill) return void 0;
24436
+ return {
24437
+ name: "w:shd",
24438
+ attributes: {
24439
+ "w:color": "auto",
24440
+ "w:val": "clear",
24441
+ "w:fill": fill
24442
+ }
24443
+ };
24368
24444
  };
24369
- const translator$V = NodeTranslator.from(config$f);
24370
- const encode$x = (attributes) => {
24445
+ const config$q = {
24446
+ xmlName: XML_NODE_NAME$s,
24447
+ sdNodeOrKeyName: SD_ATTR_KEY$f,
24448
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
24449
+ encode: encode$13,
24450
+ decode: decode$W,
24451
+ attributes: validXmlAttributes$k
24452
+ };
24453
+ const translator$14 = NodeTranslator.from(config$q);
24454
+ const encode$12 = (attributes) => {
24371
24455
  return attributes["w:val"];
24372
24456
  };
24373
- const decode$x = (attrs) => {
24457
+ const decode$V = (attrs) => {
24374
24458
  const { tabSize } = attrs || {};
24375
24459
  return tabSize;
24376
24460
  };
24377
- const attrConfig$g = Object.freeze({
24461
+ const attrConfig$C = Object.freeze({
24378
24462
  xmlName: "w:val",
24379
24463
  sdName: "tabSize",
24380
- encode: encode$x,
24381
- decode: decode$x
24464
+ encode: encode$12,
24465
+ decode: decode$V
24382
24466
  });
24383
- const encode$w = (attributes) => {
24467
+ const encode$11 = (attributes) => {
24384
24468
  return attributes["w:leader"];
24385
24469
  };
24386
- const decode$w = (attrs) => {
24470
+ const decode$U = (attrs) => {
24387
24471
  const { leader } = attrs || {};
24388
24472
  return leader;
24389
24473
  };
24390
- const attrConfig$f = Object.freeze({
24474
+ const attrConfig$B = Object.freeze({
24391
24475
  xmlName: "w:leader",
24392
24476
  sdName: "leader",
24393
- encode: encode$w,
24394
- decode: decode$w
24477
+ encode: encode$11,
24478
+ decode: decode$U
24395
24479
  });
24396
- const encode$v = (attributes) => {
24480
+ const encode$10 = (attributes) => {
24397
24481
  return attributes["w:pos"];
24398
24482
  };
24399
- const decode$v = (attrs) => {
24483
+ const decode$T = (attrs) => {
24400
24484
  const { pos } = attrs || {};
24401
24485
  return pos;
24402
24486
  };
24403
- const attrConfig$e = Object.freeze({
24487
+ const attrConfig$A = Object.freeze({
24404
24488
  xmlName: "w:pos",
24405
24489
  sdName: "pos",
24406
- encode: encode$v,
24407
- decode: decode$v
24490
+ encode: encode$10,
24491
+ decode: decode$T
24408
24492
  });
24409
- const validXmlAttributes$a = [attrConfig$g, attrConfig$e, attrConfig$f];
24410
- const XML_NODE_NAME$g = "w:tab";
24493
+ const validXmlAttributes$j = [attrConfig$C, attrConfig$A, attrConfig$B];
24494
+ const XML_NODE_NAME$r = "w:tab";
24411
24495
  const SD_NODE_NAME$b = "tab";
24412
- const encode$u = (_2, encodedAttrs = {}) => {
24496
+ const encode$$ = (_2, encodedAttrs = {}) => {
24413
24497
  const translated = { type: "tab" };
24414
24498
  if (encodedAttrs) translated.attrs = { ...encodedAttrs };
24415
24499
  return translated;
24416
24500
  };
24417
- const decode$u = (params, decodedAttrs = {}) => {
24501
+ const decode$S = (params, decodedAttrs = {}) => {
24418
24502
  const { node } = params || {};
24419
24503
  if (!node) return;
24420
24504
  const wTab = { name: "w:tab" };
@@ -24430,15 +24514,15 @@ const decode$u = (params, decodedAttrs = {}) => {
24430
24514
  }
24431
24515
  return translated;
24432
24516
  };
24433
- const config$e = {
24434
- xmlName: XML_NODE_NAME$g,
24517
+ const config$p = {
24518
+ xmlName: XML_NODE_NAME$r,
24435
24519
  sdNodeOrKeyName: SD_NODE_NAME$b,
24436
24520
  type: NodeTranslator.translatorTypes.NODE,
24437
- encode: encode$u,
24438
- decode: decode$u,
24439
- attributes: validXmlAttributes$a
24521
+ encode: encode$$,
24522
+ decode: decode$S,
24523
+ attributes: validXmlAttributes$j
24440
24524
  };
24441
- const translator$U = NodeTranslator.from(config$e);
24525
+ const translator$13 = NodeTranslator.from(config$p);
24442
24526
  const mergeTextNodes = (nodes) => {
24443
24527
  if (!nodes || !Array.isArray(nodes)) {
24444
24528
  return nodes;
@@ -24613,17 +24697,21 @@ function getMarkValue(markType, attributes, docx) {
24613
24697
  function getFontFamilyValue(attributes, docx) {
24614
24698
  const ascii = attributes["w:ascii"];
24615
24699
  const themeAscii = attributes["w:asciiTheme"];
24616
- if (!docx || !themeAscii) return ascii;
24617
- const theme = docx["word/theme/theme1.xml"];
24618
- if (!theme) return ascii;
24619
- const { elements: topElements } = theme;
24620
- const { elements } = topElements[0];
24621
- const themeElements = elements.find((el) => el.name === "a:themeElements");
24622
- const fontScheme = themeElements.elements.find((el) => el.name === "a:fontScheme");
24623
- const majorFont = fontScheme.elements.find((el) => el.name === "a:majorFont");
24624
- const latin = majorFont.elements.find((el) => el.name === "a:latin");
24625
- const typeface = latin.attributes["typeface"];
24626
- return typeface;
24700
+ let resolved = ascii;
24701
+ if (docx && themeAscii) {
24702
+ const theme = docx["word/theme/theme1.xml"];
24703
+ if (theme?.elements?.length) {
24704
+ const { elements: topElements } = theme;
24705
+ const { elements } = topElements[0] || {};
24706
+ const themeElements = elements?.find((el) => el.name === "a:themeElements");
24707
+ const fontScheme = themeElements?.elements?.find((el) => el.name === "a:fontScheme");
24708
+ const majorFont = fontScheme?.elements?.find((el) => el.name === "a:majorFont");
24709
+ const latin = majorFont?.elements?.find((el) => el.name === "a:latin");
24710
+ resolved = latin?.attributes?.typeface || resolved;
24711
+ }
24712
+ }
24713
+ if (!resolved) return null;
24714
+ return SuperConverter.toCssFontFamily(resolved, docx);
24627
24715
  }
24628
24716
  function getIndentValue(attributes) {
24629
24717
  let value = attributes["w:left"];
@@ -24644,7 +24732,11 @@ function getHighLightValue(attributes) {
24644
24732
  return getHexColorFromDocxSystem(attributes?.["w:val"]) || null;
24645
24733
  }
24646
24734
  function getStrikeValue(attributes) {
24647
- return attributes?.["w:val"] === "1" ? attributes["w:val"] : null;
24735
+ const raw = attributes?.["w:val"];
24736
+ if (raw === void 0 || raw === null) return "1";
24737
+ const value = String(raw).trim().toLowerCase();
24738
+ if (value === "1" || value === "true" || value === "on") return "1";
24739
+ return null;
24648
24740
  }
24649
24741
  const parseParagraphBorders = (pBdr) => {
24650
24742
  if (!pBdr || !pBdr.elements) return {};
@@ -24674,27 +24766,39 @@ const getParagraphIndent = (node, docx, styleId = "") => {
24674
24766
  right: 0,
24675
24767
  firstLine: 0,
24676
24768
  hanging: 0,
24677
- textIndent: 0
24769
+ textIndent: 0,
24770
+ explicitLeft: false,
24771
+ explicitRight: false,
24772
+ explicitFirstLine: false,
24773
+ explicitHanging: false
24678
24774
  };
24679
24775
  const { indent: pDefaultIndent = {} } = getDefaultParagraphStyle(docx, styleId);
24680
24776
  const pPr = node.elements?.find((el) => el.name === "w:pPr");
24681
24777
  const inLineIndentTag = pPr?.elements?.find((el) => el.name === "w:ind");
24682
24778
  const inLineIndent = inLineIndentTag?.attributes || {};
24683
- const leftIndent = inLineIndent?.["w:left"] || pDefaultIndent?.["w:left"];
24684
- const rightIndent = inLineIndent?.["w:right"] || pDefaultIndent?.["w:right"];
24685
- const firstLine = inLineIndent?.["w:firstLine"] || pDefaultIndent?.["w:firstLine"];
24686
- const hanging = inLineIndent?.["w:hanging"] || pDefaultIndent?.["w:hanging"];
24779
+ const inlineLeft = inLineIndent?.["w:left"];
24780
+ const inlineRight = inLineIndent?.["w:right"];
24781
+ const inlineFirstLine = inLineIndent?.["w:firstLine"];
24782
+ const inlineHanging = inLineIndent?.["w:hanging"];
24783
+ const leftIndent = inlineLeft ?? pDefaultIndent?.["w:left"];
24784
+ const rightIndent = inlineRight ?? pDefaultIndent?.["w:right"];
24785
+ const firstLine = inlineFirstLine ?? pDefaultIndent?.["w:firstLine"];
24786
+ const hanging = inlineHanging ?? pDefaultIndent?.["w:hanging"];
24687
24787
  if (leftIndent) {
24688
24788
  indent.left = twipsToPixels(leftIndent);
24789
+ indent.explicitLeft = inlineLeft !== void 0;
24689
24790
  }
24690
24791
  if (rightIndent) {
24691
24792
  indent.right = twipsToPixels(rightIndent);
24793
+ indent.explicitRight = inlineRight !== void 0;
24692
24794
  }
24693
24795
  if (firstLine) {
24694
24796
  indent.firstLine = twipsToPixels(firstLine);
24797
+ indent.explicitFirstLine = inlineFirstLine !== void 0;
24695
24798
  }
24696
24799
  if (hanging) {
24697
24800
  indent.hanging = twipsToPixels(hanging);
24801
+ indent.explicitHanging = inlineHanging !== void 0;
24698
24802
  }
24699
24803
  const textIndentValue = leftIndent - parseInt(hanging || 0) || 0;
24700
24804
  if (textIndentValue) {
@@ -25033,102 +25137,102 @@ const handleParagraphNode$1 = (params) => {
25033
25137
  }
25034
25138
  return schemaNode;
25035
25139
  };
25036
- const encode$t = (attributes) => {
25140
+ const encode$_ = (attributes) => {
25037
25141
  return attributes["w:rsidDel"];
25038
25142
  };
25039
- const decode$t = (attrs) => {
25143
+ const decode$R = (attrs) => {
25040
25144
  return attrs.rsidDel;
25041
25145
  };
25042
- const attrConfig$d = Object.freeze({
25146
+ const attrConfig$z = Object.freeze({
25043
25147
  xmlName: "w:rsidDel",
25044
25148
  sdName: "rsidDel",
25045
- encode: encode$t,
25046
- decode: decode$t
25149
+ encode: encode$_,
25150
+ decode: decode$R
25047
25151
  });
25048
- const encode$s = (attributes) => {
25152
+ const encode$Z = (attributes) => {
25049
25153
  return attributes["w:rsidP"];
25050
25154
  };
25051
- const decode$s = (attrs) => {
25155
+ const decode$Q = (attrs) => {
25052
25156
  return attrs.rsidP;
25053
25157
  };
25054
- const attrConfig$c = Object.freeze({
25158
+ const attrConfig$y = Object.freeze({
25055
25159
  xmlName: "w:rsidP",
25056
25160
  sdName: "rsidP",
25057
- encode: encode$s,
25058
- decode: decode$s
25161
+ encode: encode$Z,
25162
+ decode: decode$Q
25059
25163
  });
25060
- const encode$r = (attributes) => {
25164
+ const encode$Y = (attributes) => {
25061
25165
  return attributes["w:rsidR"];
25062
25166
  };
25063
- const decode$r = (attrs) => {
25167
+ const decode$P = (attrs) => {
25064
25168
  return attrs.rsidR;
25065
25169
  };
25066
- const attrConfig$b = Object.freeze({
25170
+ const attrConfig$x = Object.freeze({
25067
25171
  xmlName: "w:rsidR",
25068
25172
  sdName: "rsidR",
25069
- encode: encode$r,
25070
- decode: decode$r
25173
+ encode: encode$Y,
25174
+ decode: decode$P
25071
25175
  });
25072
- const encode$q = (attributes) => {
25176
+ const encode$X = (attributes) => {
25073
25177
  return attributes["w:rsidRPr"];
25074
25178
  };
25075
- const decode$q = (attrs) => {
25179
+ const decode$O = (attrs) => {
25076
25180
  return attrs.rsidRPr;
25077
25181
  };
25078
- const attrConfig$a = Object.freeze({
25182
+ const attrConfig$w = Object.freeze({
25079
25183
  xmlName: "w:rsidRPr",
25080
25184
  sdName: "rsidRPr",
25081
- encode: encode$q,
25082
- decode: decode$q
25185
+ encode: encode$X,
25186
+ decode: decode$O
25083
25187
  });
25084
- const encode$p = (attributes) => {
25188
+ const encode$W = (attributes) => {
25085
25189
  return attributes["w:rsidRDefault"];
25086
25190
  };
25087
- const decode$p = (attrs) => {
25191
+ const decode$N = (attrs) => {
25088
25192
  return attrs.rsidRDefault;
25089
25193
  };
25090
- const attrConfig$9 = Object.freeze({
25194
+ const attrConfig$v = Object.freeze({
25091
25195
  xmlName: "w:rsidRDefault",
25092
25196
  sdName: "rsidRDefault",
25093
- encode: encode$p,
25094
- decode: decode$p
25197
+ encode: encode$W,
25198
+ decode: decode$N
25095
25199
  });
25096
- const encode$o = (attributes) => {
25200
+ const encode$V = (attributes) => {
25097
25201
  return attributes["w14:paraId"];
25098
25202
  };
25099
- const decode$o = (attrs) => {
25203
+ const decode$M = (attrs) => {
25100
25204
  return attrs.paraId;
25101
25205
  };
25102
- const attrConfig$8 = Object.freeze({
25206
+ const attrConfig$u = Object.freeze({
25103
25207
  xmlName: "w14:paraId",
25104
25208
  sdName: "paraId",
25105
- encode: encode$o,
25106
- decode: decode$o
25209
+ encode: encode$V,
25210
+ decode: decode$M
25107
25211
  });
25108
- const encode$n = (attributes) => {
25212
+ const encode$U = (attributes) => {
25109
25213
  return attributes["w14:textId"];
25110
25214
  };
25111
- const decode$n = (attrs) => {
25215
+ const decode$L = (attrs) => {
25112
25216
  return attrs.textId;
25113
25217
  };
25114
- const attrConfig$7 = Object.freeze({
25218
+ const attrConfig$t = Object.freeze({
25115
25219
  xmlName: "w14:textId",
25116
25220
  sdName: "textId",
25117
- encode: encode$n,
25118
- decode: decode$n
25221
+ encode: encode$U,
25222
+ decode: decode$L
25119
25223
  });
25120
- const validXmlAttributes$9 = [
25121
- attrConfig$8,
25122
- attrConfig$7,
25123
- attrConfig$b,
25124
- attrConfig$9,
25125
- attrConfig$c,
25126
- attrConfig$a,
25127
- attrConfig$d
25224
+ const validXmlAttributes$i = [
25225
+ attrConfig$u,
25226
+ attrConfig$t,
25227
+ attrConfig$x,
25228
+ attrConfig$v,
25229
+ attrConfig$y,
25230
+ attrConfig$w,
25231
+ attrConfig$z
25128
25232
  ];
25129
- const XML_NODE_NAME$f = "w:p";
25233
+ const XML_NODE_NAME$q = "w:p";
25130
25234
  const SD_NODE_NAME$a = "paragraph";
25131
- const encode$m = (params, encodedAttrs = {}) => {
25235
+ const encode$T = (params, encodedAttrs = {}) => {
25132
25236
  const node = handleParagraphNode$1(params);
25133
25237
  if (!node) return void 0;
25134
25238
  if (encodedAttrs && Object.keys(encodedAttrs).length) {
@@ -25136,7 +25240,7 @@ const encode$m = (params, encodedAttrs = {}) => {
25136
25240
  }
25137
25241
  return node;
25138
25242
  };
25139
- const decode$m = (params, decodedAttrs = {}) => {
25243
+ const decode$K = (params, decodedAttrs = {}) => {
25140
25244
  const translated = translateParagraphNode(params);
25141
25245
  if (!translated) return void 0;
25142
25246
  if (decodedAttrs && Object.keys(decodedAttrs).length) {
@@ -25144,167 +25248,1322 @@ const decode$m = (params, decodedAttrs = {}) => {
25144
25248
  }
25145
25249
  return translated;
25146
25250
  };
25147
- const config$d = {
25148
- xmlName: XML_NODE_NAME$f,
25251
+ const config$o = {
25252
+ xmlName: XML_NODE_NAME$q,
25149
25253
  sdNodeOrKeyName: SD_NODE_NAME$a,
25150
25254
  type: NodeTranslator.translatorTypes.NODE,
25151
- encode: encode$m,
25152
- decode: decode$m,
25153
- attributes: validXmlAttributes$9
25255
+ encode: encode$T,
25256
+ decode: decode$K,
25257
+ attributes: validXmlAttributes$i
25258
+ };
25259
+ const translator$12 = NodeTranslator.from(config$o);
25260
+ const encode$S = (attributes) => {
25261
+ const raw = attributes?.["w:val"];
25262
+ if (raw === void 0 || raw === null) return void 0;
25263
+ if (typeof raw === "boolean") return raw;
25264
+ if (typeof raw === "number") return raw !== 0;
25265
+ const val = String(raw).trim().toLowerCase();
25266
+ if (val === "0" || val === "false" || val === "off") return false;
25267
+ if (val === "1" || val === "true" || val === "on") return true;
25268
+ return void 0;
25154
25269
  };
25155
- const translator$T = NodeTranslator.from(config$d);
25156
- const generateV2HandlerEntity = (handlerName, translator2) => ({
25157
- handlerName,
25158
- handler: (params) => {
25159
- const { nodes } = params;
25160
- if (nodes.length === 0 || nodes[0].name !== translator2.xmlName) {
25161
- return { nodes: [], consumed: 0 };
25162
- }
25163
- const result = translator2.encode(params);
25164
- if (!result) return { nodes: [], consumed: 0 };
25165
- return {
25166
- nodes: Array.isArray(result) ? result : [result],
25167
- consumed: 1
25168
- };
25169
- }
25270
+ const decode$J = (runProps) => {
25271
+ if (runProps?.bold === false) return "0";
25272
+ return void 0;
25273
+ };
25274
+ const attrConfig$s = Object.freeze({
25275
+ xmlName: "w:val",
25276
+ sdName: "bold",
25277
+ encode: encode$S,
25278
+ decode: decode$J
25170
25279
  });
25171
- function createSingleAttrPropertyHandler(xmlName, sdName = null, attrName = "w:val", transformEncode = null, transformDecode = null) {
25172
- if (!sdName) sdName = xmlName.split(":")[1];
25173
- if (!transformEncode) transformEncode = (v2) => v2;
25174
- if (!transformDecode) transformDecode = (v2) => v2;
25280
+ const validXmlAttributes$h = [attrConfig$s];
25281
+ const XML_NODE_NAME$p = "w:b";
25282
+ const SD_ATTR_KEY$e = "bold";
25283
+ const encode$R = (params, encodedAttrs = {}) => {
25284
+ const { nodes } = params;
25285
+ const node = nodes[0];
25286
+ if (!node) return void 0;
25287
+ const val = encodedAttrs?.[SD_ATTR_KEY$e];
25288
+ let attributes;
25289
+ if (val === false) attributes = { "w:val": "0" };
25290
+ else if (val === true)
25291
+ attributes = {};
25292
+ else attributes = node.attributes || {};
25175
25293
  return {
25176
- xmlName,
25177
- sdNodeOrKeyName: sdName,
25178
- encode: ({ nodes }) => {
25179
- return transformEncode(nodes[0].attributes[attrName]) ?? void 0;
25180
- },
25181
- decode: ({ node }) => {
25182
- const value = node.attrs?.[sdName] != null ? transformDecode(node.attrs[sdName]) : void 0;
25183
- return value != null ? { name: xmlName, attributes: { [attrName]: value } } : void 0;
25184
- }
25294
+ type: "attr",
25295
+ xmlName: XML_NODE_NAME$p,
25296
+ sdNodeOrKeyName: SD_ATTR_KEY$e,
25297
+ attributes
25185
25298
  };
25186
- }
25187
- function createMeasurementPropertyHandler(xmlName, sdName = null) {
25188
- if (!sdName) sdName = xmlName.split(":")[1];
25299
+ };
25300
+ const config$n = {
25301
+ xmlName: XML_NODE_NAME$p,
25302
+ sdNodeOrKeyName: SD_ATTR_KEY$e,
25303
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
25304
+ encode: encode$R,
25305
+ attributes: validXmlAttributes$h
25306
+ };
25307
+ const translator$11 = NodeTranslator.from(config$n);
25308
+ const XML_NODE_NAME$o = "w:i";
25309
+ const SD_ATTR_KEY$d = "italic";
25310
+ const encode$Q = (params) => {
25311
+ const { nodes } = params;
25312
+ const node = nodes?.[0];
25313
+ if (!node) return void 0;
25189
25314
  return {
25190
- xmlName,
25191
- sdNodeOrKeyName: sdName,
25192
- attributes: [
25193
- createAttributeHandler("w:w", "value", parseInteger, integerToString),
25194
- createAttributeHandler("w:type")
25195
- ],
25196
- encode: (_2, encodedAttrs) => {
25197
- return encodedAttrs["value"] != null ? encodedAttrs : void 0;
25198
- },
25199
- decode: function({ node }) {
25200
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs[sdName] || {} } });
25201
- return decodedAttrs["w:w"] != null ? { attributes: decodedAttrs } : void 0;
25315
+ type: "attr",
25316
+ xmlName: XML_NODE_NAME$o,
25317
+ sdNodeOrKeyName: SD_ATTR_KEY$d,
25318
+ attributes: {
25319
+ "w:val": node.attributes?.["w:val"] ?? null
25202
25320
  }
25203
25321
  };
25204
- }
25205
- function createBorderPropertyHandler(xmlName, sdName = null) {
25206
- if (!sdName) sdName = xmlName.split(":")[1];
25322
+ };
25323
+ const config$m = {
25324
+ xmlName: XML_NODE_NAME$o,
25325
+ sdNodeOrKeyName: SD_ATTR_KEY$d,
25326
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
25327
+ encode: encode$Q
25328
+ };
25329
+ const translator$10 = NodeTranslator.from(config$m);
25330
+ const encode$P = (attributes) => attributes?.["w:val"];
25331
+ const decode$I = (attrs) => attrs?.underline;
25332
+ const attrConfig$r = Object.freeze({
25333
+ xmlName: "w:val",
25334
+ sdName: "underline",
25335
+ encode: encode$P,
25336
+ decode: decode$I
25337
+ });
25338
+ const encode$O = (attributes) => attributes?.["w:color"];
25339
+ const decode$H = (attrs) => attrs?.color;
25340
+ const attrConfig$q = Object.freeze({
25341
+ xmlName: "w:color",
25342
+ sdName: "color",
25343
+ encode: encode$O,
25344
+ decode: decode$H
25345
+ });
25346
+ const encode$N = (attributes) => attributes?.["w:themeColor"];
25347
+ const decode$G = (attrs) => attrs?.themeColor;
25348
+ const attrConfig$p = Object.freeze({
25349
+ xmlName: "w:themeColor",
25350
+ sdName: "themeColor",
25351
+ encode: encode$N,
25352
+ decode: decode$G
25353
+ });
25354
+ const encode$M = (attributes) => attributes?.["w:themeTint"];
25355
+ const decode$F = (attrs) => attrs?.themeTint;
25356
+ const attrConfig$o = Object.freeze({
25357
+ xmlName: "w:themeTint",
25358
+ sdName: "themeTint",
25359
+ encode: encode$M,
25360
+ decode: decode$F
25361
+ });
25362
+ const encode$L = (attributes) => attributes?.["w:themeShade"];
25363
+ const decode$E = (attrs) => attrs?.themeShade;
25364
+ const attrConfig$n = Object.freeze({
25365
+ xmlName: "w:themeShade",
25366
+ sdName: "themeShade",
25367
+ encode: encode$L,
25368
+ decode: decode$E
25369
+ });
25370
+ const validXmlAttributes$g = [attrConfig$r, attrConfig$q, attrConfig$p, attrConfig$o, attrConfig$n];
25371
+ const XML_NODE_NAME$n = "w:u";
25372
+ const SD_ATTR_KEY$c = "underline";
25373
+ const encode$K = (params, encodedAttrs = {}) => {
25374
+ const { nodes } = params;
25375
+ const node = nodes?.[0];
25376
+ const sourceAttrs = node?.attributes || {};
25377
+ const underlineType = encodedAttrs.underline ?? sourceAttrs["w:val"];
25378
+ const color = encodedAttrs.color ?? sourceAttrs["w:color"];
25379
+ const themeColor = encodedAttrs.themeColor ?? sourceAttrs["w:themeColor"];
25380
+ const themeTint = encodedAttrs.themeTint ?? sourceAttrs["w:themeTint"];
25381
+ const themeShade = encodedAttrs.themeShade ?? sourceAttrs["w:themeShade"];
25382
+ const attributes = { "w:val": underlineType ?? null };
25383
+ if (color !== void 0 && color !== null) attributes["w:color"] = color;
25384
+ if (themeColor !== void 0 && themeColor !== null) attributes["w:themeColor"] = themeColor;
25385
+ if (themeTint !== void 0 && themeTint !== null) attributes["w:themeTint"] = themeTint;
25386
+ if (themeShade !== void 0 && themeShade !== null) attributes["w:themeShade"] = themeShade;
25207
25387
  return {
25208
- xmlName,
25209
- sdNodeOrKeyName: sdName,
25210
- attributes: [
25211
- createAttributeHandler("w:val"),
25212
- createAttributeHandler("w:color"),
25213
- createAttributeHandler("w:themeColor"),
25214
- createAttributeHandler("w:themeTint"),
25215
- createAttributeHandler("w:themeShade"),
25216
- createAttributeHandler("w:sz", "size", parseInteger, integerToString),
25217
- createAttributeHandler("w:space", null, parseInteger, integerToString),
25218
- createAttributeHandler("w:shadow", null, parseBoolean, booleanToString),
25219
- createAttributeHandler("w:frame", null, parseBoolean, booleanToString)
25220
- ],
25221
- encode: (params, encodedAttrs) => {
25222
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
25223
- },
25224
- decode: function({ node }, context) {
25225
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs[sdName] || {} } });
25226
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
25227
- }
25388
+ type: "attr",
25389
+ xmlName: XML_NODE_NAME$n,
25390
+ sdNodeOrKeyName: SD_ATTR_KEY$c,
25391
+ attributes
25228
25392
  };
25229
- }
25230
- const createAttributeHandler = (xmlName, sdName = null, transformEncode = null, transformDecode = null) => {
25231
- if (!transformEncode) transformEncode = (v2) => v2;
25232
- if (!transformDecode) transformDecode = (v2) => v2;
25233
- if (!sdName) sdName = xmlName.split(":")[1];
25393
+ };
25394
+ const decode$D = (params) => {
25395
+ const attrs = params?.node?.attrs || {};
25396
+ const underlineType = attrs.underlineType ?? attrs.underline ?? null;
25397
+ const color = attrs.underlineColor ?? attrs.color ?? null;
25398
+ const themeColor = attrs.underlineThemeColor ?? attrs.themeColor ?? null;
25399
+ const themeTint = attrs.underlineThemeTint ?? attrs.themeTint ?? null;
25400
+ const themeShade = attrs.underlineThemeShade ?? attrs.themeShade ?? null;
25401
+ if (!underlineType && !color && !themeColor && !themeTint && !themeShade) return void 0;
25402
+ const attributes = {};
25403
+ if (underlineType) attributes["w:val"] = underlineType;
25404
+ if (color) {
25405
+ const normalized = normalizeHexColor(color);
25406
+ if (normalized) attributes["w:color"] = normalized;
25407
+ }
25408
+ if (themeColor) attributes["w:themeColor"] = themeColor;
25409
+ if (themeTint) attributes["w:themeTint"] = themeTint;
25410
+ if (themeShade) attributes["w:themeShade"] = themeShade;
25234
25411
  return {
25235
- xmlName,
25236
- sdName,
25237
- encode: (attributes) => transformEncode(attributes[xmlName]),
25238
- decode: (attributes) => transformDecode(attributes[sdName])
25412
+ name: XML_NODE_NAME$n,
25413
+ attributes
25239
25414
  };
25240
25415
  };
25241
- function encodeProperties(node, translatorsByXmlName, asArray = false) {
25242
- if (!node?.elements || node.elements.length === 0) {
25243
- return asArray ? [] : {};
25244
- }
25245
- const attributes = asArray ? [] : {};
25246
- node.elements.forEach((el) => {
25247
- const translator2 = translatorsByXmlName[el.name];
25248
- if (translator2) {
25249
- const encodedAttr = translator2.encode({ nodes: [el] });
25250
- if (encodedAttr != null) {
25251
- if (asArray) {
25252
- attributes.push({ [translator2.sdNodeOrKeyName]: encodedAttr });
25253
- } else {
25254
- attributes[translator2.sdNodeOrKeyName] = encodedAttr;
25255
- }
25256
- }
25257
- }
25258
- });
25259
- return attributes;
25260
- }
25261
- function decodeProperties(translatorsBySdName, properties) {
25262
- if (!properties || typeof properties !== "object") {
25263
- return [];
25264
- }
25265
- const elements = [];
25266
- Object.keys(properties).forEach((key) => {
25267
- const translator2 = translatorsBySdName[key];
25268
- if (translator2) {
25269
- const result = translator2.decode({ node: { attrs: { [key]: properties[key] } } });
25270
- if (result != null) {
25271
- result.name = translator2.xmlName;
25272
- elements.push(result);
25273
- }
25274
- }
25275
- });
25276
- return elements;
25277
- }
25278
- const parseBoolean = (value) => value != null ? ["1", "true"].includes(value) : void 0;
25279
- const booleanToString = (value) => value != null ? value ? "1" : "0" : void 0;
25280
- const parseInteger = (value) => {
25281
- if (value == null) return void 0;
25282
- const intValue = parseInt(value, 10);
25283
- return isNaN(intValue) ? void 0 : intValue;
25416
+ const config$l = {
25417
+ xmlName: XML_NODE_NAME$n,
25418
+ sdNodeOrKeyName: SD_ATTR_KEY$c,
25419
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
25420
+ encode: encode$K,
25421
+ decode: decode$D,
25422
+ attributes: validXmlAttributes$g
25423
+ };
25424
+ const translator$$ = NodeTranslator.from(config$l);
25425
+ const encode$J = (attributes) => {
25426
+ const raw = attributes?.["w:val"];
25427
+ if (raw === void 0 || raw === null) return void 0;
25428
+ if (typeof raw === "boolean") return raw;
25429
+ if (typeof raw === "number") return raw !== 0;
25430
+ const val = String(raw).trim().toLowerCase();
25431
+ if (val === "0" || val === "false" || val === "off") return false;
25432
+ if (val === "1" || val === "true" || val === "on") return true;
25433
+ return void 0;
25284
25434
  };
25285
- const integerToString = (value) => {
25286
- const intValue = parseInteger(value);
25287
- return intValue != void 0 ? String(intValue) : void 0;
25435
+ const decode$C = (attrs) => {
25436
+ if (attrs?.strike === false) return "0";
25437
+ return void 0;
25288
25438
  };
25289
- function preProcessVerticalMergeCells(table, { editorSchema }) {
25290
- if (!table || !Array.isArray(table.content)) {
25291
- return table;
25292
- }
25293
- const rows = table.content;
25294
- for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
25295
- const row = rows[rowIndex];
25296
- if (!row) continue;
25297
- if (!Array.isArray(row.content)) {
25298
- row.content = [];
25299
- }
25300
- for (let cellIndex = 0; cellIndex < row.content.length; cellIndex++) {
25301
- const cell = row.content[cellIndex];
25302
- if (!cell) continue;
25303
- const attrs = cell.attrs || {};
25304
- if (!attrs.rowspan || attrs.rowspan <= 1) continue;
25305
- const maxRowspan = Math.min(attrs.rowspan, rows.length - rowIndex);
25306
- for (let offset = 1; offset < maxRowspan; offset++) {
25307
- const rowToChange = rows[rowIndex + offset];
25439
+ const attrConfig$m = Object.freeze({
25440
+ xmlName: "w:val",
25441
+ sdName: "strike",
25442
+ encode: encode$J,
25443
+ decode: decode$C
25444
+ });
25445
+ const validXmlAttributes$f = [attrConfig$m];
25446
+ const XML_NODE_NAME$m = "w:strike";
25447
+ const SD_ATTR_KEY$b = "strike";
25448
+ const encode$I = (params, encodedAttrs = {}) => {
25449
+ const { nodes } = params;
25450
+ const node = nodes?.[0];
25451
+ if (!node) return void 0;
25452
+ const val = encodedAttrs?.[SD_ATTR_KEY$b];
25453
+ let attributes;
25454
+ if (val === false) attributes = { "w:val": "0" };
25455
+ else if (val === true) attributes = {};
25456
+ else attributes = { ...node.attributes || {} };
25457
+ if (attributes["w:val"] === void 0 && val !== true) attributes["w:val"] = null;
25458
+ else if (val === true && attributes["w:val"] === void 0) delete attributes["w:val"];
25459
+ return {
25460
+ type: "attr",
25461
+ xmlName: XML_NODE_NAME$m,
25462
+ sdNodeOrKeyName: SD_ATTR_KEY$b,
25463
+ attributes
25464
+ };
25465
+ };
25466
+ const config$k = {
25467
+ xmlName: XML_NODE_NAME$m,
25468
+ sdNodeOrKeyName: SD_ATTR_KEY$b,
25469
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
25470
+ encode: encode$I,
25471
+ attributes: validXmlAttributes$f
25472
+ };
25473
+ const translator$_ = NodeTranslator.from(config$k);
25474
+ const encode$H = (attributes) => attributes?.["w:val"];
25475
+ const decode$B = (attrs) => attrs?.color;
25476
+ const attrConfig$l = Object.freeze({
25477
+ xmlName: "w:val",
25478
+ sdName: "color",
25479
+ encode: encode$H,
25480
+ decode: decode$B
25481
+ });
25482
+ const encode$G = (attributes) => attributes?.["w:themeColor"];
25483
+ const decode$A = (attrs) => attrs?.themeColor;
25484
+ const attrConfig$k = Object.freeze({
25485
+ xmlName: "w:themeColor",
25486
+ sdName: "themeColor",
25487
+ encode: encode$G,
25488
+ decode: decode$A
25489
+ });
25490
+ const encode$F = (attributes) => attributes?.["w:themeTint"];
25491
+ const decode$z = (attrs) => attrs?.themeTint;
25492
+ const attrConfig$j = Object.freeze({
25493
+ xmlName: "w:themeTint",
25494
+ sdName: "themeTint",
25495
+ encode: encode$F,
25496
+ decode: decode$z
25497
+ });
25498
+ const encode$E = (attributes) => attributes?.["w:themeShade"];
25499
+ const decode$y = (attrs) => attrs?.themeShade;
25500
+ const attrConfig$i = Object.freeze({
25501
+ xmlName: "w:themeShade",
25502
+ sdName: "themeShade",
25503
+ encode: encode$E,
25504
+ decode: decode$y
25505
+ });
25506
+ const validXmlAttributes$e = [attrConfig$l, attrConfig$k, attrConfig$j, attrConfig$i];
25507
+ const XML_NODE_NAME$l = "w:color";
25508
+ const SD_ATTR_KEY$a = "color";
25509
+ const encode$D = (params, encodedAttrs = {}) => {
25510
+ const { nodes } = params;
25511
+ const node = nodes?.[0];
25512
+ const sourceAttrs = node?.attributes || {};
25513
+ const value = encodedAttrs.color ?? sourceAttrs["w:val"];
25514
+ const themeColor = encodedAttrs.themeColor ?? sourceAttrs["w:themeColor"];
25515
+ const themeTint = encodedAttrs.themeTint ?? sourceAttrs["w:themeTint"];
25516
+ const themeShade = encodedAttrs.themeShade ?? sourceAttrs["w:themeShade"];
25517
+ const attributes = {};
25518
+ attributes["w:val"] = value ?? null;
25519
+ if (themeColor !== void 0 && themeColor !== null) attributes["w:themeColor"] = themeColor;
25520
+ if (themeTint !== void 0 && themeTint !== null) attributes["w:themeTint"] = themeTint;
25521
+ if (themeShade !== void 0 && themeShade !== null) attributes["w:themeShade"] = themeShade;
25522
+ return {
25523
+ type: "attr",
25524
+ xmlName: XML_NODE_NAME$l,
25525
+ sdNodeOrKeyName: SD_ATTR_KEY$a,
25526
+ attributes
25527
+ };
25528
+ };
25529
+ const config$j = {
25530
+ xmlName: XML_NODE_NAME$l,
25531
+ sdNodeOrKeyName: SD_ATTR_KEY$a,
25532
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
25533
+ encode: encode$D,
25534
+ attributes: validXmlAttributes$e
25535
+ };
25536
+ const translator$Z = NodeTranslator.from(config$j);
25537
+ const encode$C = (attributes) => attributes?.["w:eastAsia"];
25538
+ const decode$x = (attrs) => attrs?.eastAsia;
25539
+ const attrConfig$h = Object.freeze({
25540
+ xmlName: "w:eastAsia",
25541
+ sdName: "eastAsia",
25542
+ encode: encode$C,
25543
+ decode: decode$x
25544
+ });
25545
+ const encode$B = (attributes) => attributes?.["w:ascii"];
25546
+ const decode$w = (attrs) => attrs?.ascii;
25547
+ const attrConfig$g = Object.freeze({
25548
+ xmlName: "w:ascii",
25549
+ sdName: "ascii",
25550
+ encode: encode$B,
25551
+ decode: decode$w
25552
+ });
25553
+ const encode$A = (attributes) => attributes?.["w:hAnsi"];
25554
+ const decode$v = (attrs) => attrs?.hAnsi;
25555
+ const attrConfig$f = Object.freeze({
25556
+ xmlName: "w:hAnsi",
25557
+ sdName: "hAnsi",
25558
+ encode: encode$A,
25559
+ decode: decode$v
25560
+ });
25561
+ const encode$z = (attributes) => attributes?.["w:cs"];
25562
+ const decode$u = (attrs) => attrs?.cs;
25563
+ const attrConfig$e = Object.freeze({
25564
+ xmlName: "w:cs",
25565
+ sdName: "cs",
25566
+ encode: encode$z,
25567
+ decode: decode$u
25568
+ });
25569
+ const encode$y = (attributes) => attributes?.["w:val"];
25570
+ const decode$t = (attrs) => attrs?.value;
25571
+ const attrConfig$d = Object.freeze({
25572
+ xmlName: "w:val",
25573
+ sdName: "value",
25574
+ encode: encode$y,
25575
+ decode: decode$t
25576
+ });
25577
+ const validXmlAttributes$d = [attrConfig$h, attrConfig$g, attrConfig$f, attrConfig$e, attrConfig$d];
25578
+ const XML_NODE_NAME$k = "w:rFonts";
25579
+ const SD_ATTR_KEY$9 = "fontFamily";
25580
+ const encode$x = (params, encodedAttrs = {}) => {
25581
+ const { nodes } = params;
25582
+ const node = nodes?.[0];
25583
+ const sourceAttrs = node?.attributes || {};
25584
+ const attributes = {};
25585
+ const setAttr = (xmlName, sdName) => {
25586
+ if (encodedAttrs[sdName] !== void 0 && encodedAttrs[sdName] !== null) {
25587
+ attributes[xmlName] = encodedAttrs[sdName];
25588
+ } else if (sourceAttrs[xmlName] !== void 0) {
25589
+ attributes[xmlName] = sourceAttrs[xmlName];
25590
+ }
25591
+ };
25592
+ setAttr("w:eastAsia", "eastAsia");
25593
+ setAttr("w:ascii", "ascii");
25594
+ setAttr("w:hAnsi", "hAnsi");
25595
+ setAttr("w:cs", "cs");
25596
+ setAttr("w:val", "value");
25597
+ Object.keys(sourceAttrs).forEach((key) => {
25598
+ if (attributes[key] === void 0) attributes[key] = sourceAttrs[key];
25599
+ });
25600
+ if (attributes["w:val"] === void 0 && attributes["w:eastAsia"]) {
25601
+ attributes["w:val"] = attributes["w:eastAsia"];
25602
+ }
25603
+ if (attributes["w:val"] === void 0) delete attributes["w:val"];
25604
+ return {
25605
+ type: "attr",
25606
+ xmlName: XML_NODE_NAME$k,
25607
+ sdNodeOrKeyName: SD_ATTR_KEY$9,
25608
+ attributes
25609
+ };
25610
+ };
25611
+ const config$i = {
25612
+ xmlName: XML_NODE_NAME$k,
25613
+ sdNodeOrKeyName: SD_ATTR_KEY$9,
25614
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
25615
+ encode: encode$x,
25616
+ attributes: validXmlAttributes$d
25617
+ };
25618
+ const translator$Y = NodeTranslator.from(config$i);
25619
+ const encode$w = (attributes) => attributes?.["w:val"];
25620
+ const decode$s = (attrs) => attrs?.styleId;
25621
+ const attrConfig$c = Object.freeze({
25622
+ xmlName: "w:val",
25623
+ sdName: "styleId",
25624
+ encode: encode$w,
25625
+ decode: decode$s
25626
+ });
25627
+ const validXmlAttributes$c = [attrConfig$c];
25628
+ const XML_NODE_NAME$j = "w:rStyle";
25629
+ const SD_ATTR_KEY$8 = "styleId";
25630
+ const encode$v = (params, encodedAttrs = {}) => {
25631
+ const { nodes } = params;
25632
+ const node = nodes?.[0];
25633
+ const value = encodedAttrs.styleId ?? node?.attributes?.["w:val"];
25634
+ return {
25635
+ type: "attr",
25636
+ xmlName: XML_NODE_NAME$j,
25637
+ sdNodeOrKeyName: SD_ATTR_KEY$8,
25638
+ attributes: { "w:val": value ?? null }
25639
+ };
25640
+ };
25641
+ const config$h = {
25642
+ xmlName: XML_NODE_NAME$j,
25643
+ sdNodeOrKeyName: SD_ATTR_KEY$8,
25644
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
25645
+ encode: encode$v,
25646
+ attributes: validXmlAttributes$c
25647
+ };
25648
+ const translator$X = NodeTranslator.from(config$h);
25649
+ const encode$u = (attributes) => attributes?.["w:val"];
25650
+ const decode$r = (attrs) => attrs?.fontSize;
25651
+ const attrConfig$b = Object.freeze({
25652
+ xmlName: "w:val",
25653
+ sdName: "fontSize",
25654
+ encode: encode$u,
25655
+ decode: decode$r
25656
+ });
25657
+ const validXmlAttributes$b = [attrConfig$b];
25658
+ const XML_NODE_NAME$i = "w:sz";
25659
+ const SD_ATTR_KEY$7 = "fontSize";
25660
+ const encode$t = (params, encodedAttrs = {}) => {
25661
+ const { nodes } = params;
25662
+ const node = nodes?.[0];
25663
+ const value = encodedAttrs.fontSize ?? node?.attributes?.["w:val"];
25664
+ return {
25665
+ type: "attr",
25666
+ xmlName: XML_NODE_NAME$i,
25667
+ sdNodeOrKeyName: SD_ATTR_KEY$7,
25668
+ attributes: { "w:val": value ?? null }
25669
+ };
25670
+ };
25671
+ const config$g = {
25672
+ xmlName: XML_NODE_NAME$i,
25673
+ sdNodeOrKeyName: SD_ATTR_KEY$7,
25674
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
25675
+ encode: encode$t,
25676
+ attributes: validXmlAttributes$b
25677
+ };
25678
+ const translator$W = NodeTranslator.from(config$g);
25679
+ const encode$s = (attributes) => attributes?.["w:val"];
25680
+ const decode$q = (attrs) => attrs?.fontSizeCs;
25681
+ const attrConfig$a = Object.freeze({
25682
+ xmlName: "w:val",
25683
+ sdName: "fontSizeCs",
25684
+ encode: encode$s,
25685
+ decode: decode$q
25686
+ });
25687
+ const validXmlAttributes$a = [attrConfig$a];
25688
+ const XML_NODE_NAME$h = "w:szCs";
25689
+ const SD_ATTR_KEY$6 = "fontSizeCs";
25690
+ const encode$r = (params, encodedAttrs = {}) => {
25691
+ const { nodes } = params;
25692
+ const node = nodes?.[0];
25693
+ const value = encodedAttrs.fontSizeCs ?? node?.attributes?.["w:val"];
25694
+ return {
25695
+ type: "attr",
25696
+ xmlName: XML_NODE_NAME$h,
25697
+ sdNodeOrKeyName: SD_ATTR_KEY$6,
25698
+ attributes: { "w:val": value ?? null }
25699
+ };
25700
+ };
25701
+ const config$f = {
25702
+ xmlName: XML_NODE_NAME$h,
25703
+ sdNodeOrKeyName: SD_ATTR_KEY$6,
25704
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
25705
+ encode: encode$r,
25706
+ attributes: validXmlAttributes$a
25707
+ };
25708
+ const translator$V = NodeTranslator.from(config$f);
25709
+ const runPropertyTranslators = Object.freeze({
25710
+ "w:b": translator$11,
25711
+ "w:i": translator$10,
25712
+ "w:u": translator$$,
25713
+ "w:strike": translator$_,
25714
+ "w:color": translator$Z,
25715
+ "w:highlight": translator$14,
25716
+ "w:rFonts": translator$Y,
25717
+ "w:rStyle": translator$X,
25718
+ "w:sz": translator$W,
25719
+ "w:szCs": translator$V
25720
+ });
25721
+ const rawRunPropertyXmlNames = Object.freeze(["w:lang", "w:shd"]);
25722
+ const RAW_CHILD_NAME_SET = new Set(rawRunPropertyXmlNames);
25723
+ const KNOWN_CHILD_XML_NAMES = /* @__PURE__ */ new Set([...Object.keys(runPropertyTranslators), ...RAW_CHILD_NAME_SET]);
25724
+ const toRunPropertyEntry = (candidate) => {
25725
+ if (!candidate || candidate.type !== "attr") return null;
25726
+ const xmlName = candidate.xmlName || candidate.name;
25727
+ if (!xmlName) return null;
25728
+ return {
25729
+ xmlName,
25730
+ attributes: { ...candidate.attributes || {} }
25731
+ };
25732
+ };
25733
+ const XML_NODE_NAME$g = "w:rPr";
25734
+ const SD_ATTR_KEY$5 = "runProperties";
25735
+ const encode$q = (params) => {
25736
+ const { nodes } = params;
25737
+ const node = nodes?.[0] || {};
25738
+ const contents = Array.isArray(node.elements) ? node.elements : [];
25739
+ const runPropsArray = contents.reduce(
25740
+ (acc, child) => {
25741
+ if (!child || typeof child !== "object") return acc;
25742
+ const xmlName = child.name;
25743
+ if (!KNOWN_CHILD_XML_NAMES.has(xmlName)) return acc;
25744
+ const translator2 = runPropertyTranslators[xmlName];
25745
+ let entry = null;
25746
+ if (translator2) {
25747
+ const encoded = translator2.encode({ ...params, nodes: [child] }) || null;
25748
+ entry = toRunPropertyEntry(encoded);
25749
+ } else if (RAW_CHILD_NAME_SET.has(xmlName)) {
25750
+ entry = toRunPropertyEntry({
25751
+ type: "attr",
25752
+ xmlName,
25753
+ attributes: { ...child.attributes || {} }
25754
+ });
25755
+ }
25756
+ if (entry) acc.push(entry);
25757
+ return acc;
25758
+ },
25759
+ /** @type {{ xmlName: string, attributes: Record<string, any> }[]} */
25760
+ []
25761
+ );
25762
+ return {
25763
+ type: "attr",
25764
+ xmlName: "w:rPr",
25765
+ sdNodeOrKeyName: "runProperties",
25766
+ attributes: runPropsArray
25767
+ };
25768
+ };
25769
+ const config$e = {
25770
+ xmlName: XML_NODE_NAME$g,
25771
+ sdNodeOrKeyName: SD_ATTR_KEY$5,
25772
+ type: NodeTranslator.translatorTypes.ATTRIBUTE,
25773
+ encode: encode$q
25774
+ };
25775
+ const translator$U = NodeTranslator.from(config$e);
25776
+ 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;
25777
+ const containsEastAsianCharacters = (text) => EAST_ASIAN_CHARACTER_REGEX.test(text);
25778
+ const collectRunProperties = (params, rPrNode, translator2 = translator$U) => {
25779
+ if (!rPrNode) return { entries: [], hadRPr: false, styleChangeMarks: [] };
25780
+ const result = translator2.encode({ ...params, nodes: [rPrNode] }) || {};
25781
+ let entries = [];
25782
+ if (Array.isArray(result.attributes) && result.attributes.length) {
25783
+ entries = result.attributes.map((attr) => ({
25784
+ xmlName: attr?.xmlName,
25785
+ attributes: { ...attr?.attributes || {} }
25786
+ }));
25787
+ } else if (Array.isArray(rPrNode.elements) && rPrNode.elements.length) {
25788
+ entries = rPrNode.elements.filter((el) => el && typeof el === "object").map((el) => ({
25789
+ xmlName: el.name,
25790
+ attributes: { ...el.attributes || {} }
25791
+ }));
25792
+ }
25793
+ const legacyMarks = parseMarks(rPrNode, [], params?.docx) || [];
25794
+ const styleChangeMarks = handleStyleChangeMarks(rPrNode, legacyMarks) || [];
25795
+ return { entries, hadRPr: true, styleChangeMarks };
25796
+ };
25797
+ const buildRunAttrs = (encodedAttrs = {}, hadRPr, runProps) => {
25798
+ const base = { ...encodedAttrs || {} };
25799
+ if (hadRPr) {
25800
+ base.runProperties = runProps.length ? runProps : null;
25801
+ }
25802
+ return base;
25803
+ };
25804
+ const ensureInlineMarks = (marks, inlineMarks = []) => {
25805
+ inlineMarks.forEach(({ type: type2, attrs }) => {
25806
+ if (!type2) return;
25807
+ if (marks.some((mark) => mark?.type === type2)) return;
25808
+ marks.push(attrs ? { type: type2, attrs: { ...attrs } } : { type: type2 });
25809
+ });
25810
+ };
25811
+ const ensureTextStyleMark = (marks, textStyleAttrs) => {
25812
+ if (!textStyleAttrs) return;
25813
+ const existingTextStyle = marks.find((mark) => mark?.type === "textStyle");
25814
+ if (existingTextStyle) {
25815
+ existingTextStyle.attrs = { ...existingTextStyle.attrs || {}, ...textStyleAttrs };
25816
+ return;
25817
+ }
25818
+ marks.push({ type: "textStyle", attrs: { ...textStyleAttrs } });
25819
+ };
25820
+ const normalizeTextStyleAttrsForNode = (textStyleAttrs, node) => {
25821
+ if (!textStyleAttrs || typeof textStyleAttrs !== "object") return null;
25822
+ const normalized = { ...textStyleAttrs };
25823
+ const eastAsiaFont = normalized.eastAsiaFontFamily;
25824
+ if (eastAsiaFont) {
25825
+ delete normalized.eastAsiaFontFamily;
25826
+ const text = typeof node?.text === "string" ? node.text : null;
25827
+ const shouldUseEastAsia = typeof text === "string" && containsEastAsianCharacters(text);
25828
+ if (shouldUseEastAsia) {
25829
+ normalized.fontFamily = eastAsiaFont;
25830
+ }
25831
+ }
25832
+ return Object.keys(normalized).length ? normalized : null;
25833
+ };
25834
+ const applyRunMarks = (node, inlineMarks, textStyleAttrs) => {
25835
+ if (!node || typeof node !== "object") return node;
25836
+ const baseMarks = Array.isArray(node.marks) ? node.marks : [];
25837
+ const marks = baseMarks.map((mark) => cloneMark$1(mark));
25838
+ ensureInlineMarks(marks, inlineMarks);
25839
+ if (node.type === "text") {
25840
+ const normalizedTextStyle = normalizeTextStyleAttrsForNode(textStyleAttrs, node);
25841
+ ensureTextStyleMark(marks, normalizedTextStyle);
25842
+ }
25843
+ return { ...node, marks };
25844
+ };
25845
+ const deriveStyleMarks = ({ docx, paragraphStyleId, runStyleId }) => {
25846
+ const paragraphStyleMarks = collectStyleMarks(paragraphStyleId, docx);
25847
+ const runStyleMarks = collectStyleMarks(runStyleId, docx);
25848
+ const inlineMarks = mergeInlineMarkSets(paragraphStyleMarks.inlineMarks, runStyleMarks.inlineMarks);
25849
+ const textStyleAttrs = mergeTextStyleAttrs(paragraphStyleMarks.textStyleAttrs, runStyleMarks.textStyleAttrs);
25850
+ return { inlineMarks, textStyleAttrs };
25851
+ };
25852
+ const collectStyleMarks = (styleId, docx, seen = /* @__PURE__ */ new Set()) => {
25853
+ if (!styleId || !docx || seen.has(styleId)) return { inlineMarks: [], textStyleAttrs: null };
25854
+ seen.add(styleId);
25855
+ const chain = collectStyleChain(styleId, docx, seen);
25856
+ if (!chain.length) return { inlineMarks: [], textStyleAttrs: null };
25857
+ const inlineMap = /* @__PURE__ */ new Map();
25858
+ let textStyleAttrs = {};
25859
+ chain.forEach((styleTag) => {
25860
+ const marks = extractMarksFromStyle(styleTag, docx);
25861
+ marks.inlineMarks.forEach((mark) => {
25862
+ inlineMap.set(mark.type, mark.attrs ? { type: mark.type, attrs: { ...mark.attrs } } : { type: mark.type });
25863
+ });
25864
+ if (marks.textStyleAttrs) textStyleAttrs = { ...textStyleAttrs, ...marks.textStyleAttrs };
25865
+ });
25866
+ return {
25867
+ inlineMarks: Array.from(inlineMap.values()),
25868
+ textStyleAttrs: Object.keys(textStyleAttrs).length ? textStyleAttrs : null
25869
+ };
25870
+ };
25871
+ const collectStyleChain = (styleId, docx, seen) => {
25872
+ if (!styleId || !docx) return [];
25873
+ const styleTag = findStyleTag(docx, styleId);
25874
+ if (!styleTag || !styleTag.elements) return [];
25875
+ const basedOn = styleTag.elements?.find((el) => el.name === "w:basedOn")?.attributes?.["w:val"];
25876
+ let chain = [];
25877
+ if (basedOn && !seen.has(basedOn)) {
25878
+ seen.add(basedOn);
25879
+ chain = collectStyleChain(basedOn, docx, seen);
25880
+ }
25881
+ chain.push(styleTag);
25882
+ return chain;
25883
+ };
25884
+ const findStyleTag = (docx, styleId) => {
25885
+ const stylesFile = docx?.["word/styles.xml"];
25886
+ if (!stylesFile?.elements?.length) return null;
25887
+ const candidates = [];
25888
+ stylesFile.elements.forEach((el) => {
25889
+ if (!el) return;
25890
+ if (el.name === "w:styles" && Array.isArray(el.elements)) {
25891
+ el.elements.forEach((child) => {
25892
+ if (child?.name === "w:style") candidates.push(child);
25893
+ });
25894
+ return;
25895
+ }
25896
+ if (el.name === "w:style") {
25897
+ candidates.push(el);
25898
+ return;
25899
+ }
25900
+ if (Array.isArray(el.elements)) {
25901
+ el.elements.forEach((child) => {
25902
+ if (child?.name === "w:style") candidates.push(child);
25903
+ });
25904
+ }
25905
+ });
25906
+ return candidates.find((tag) => tag?.attributes?.["w:styleId"] === styleId) || null;
25907
+ };
25908
+ const extractMarksFromStyle = (styleTag, docx) => {
25909
+ const rPr = styleTag?.elements?.find((el) => el.name === "w:rPr");
25910
+ if (!rPr) return { inlineMarks: [], textStyleAttrs: null };
25911
+ const marks = parseMarks(rPr, [], docx) || [];
25912
+ const inlineMarks = [];
25913
+ let textStyleAttrs = {};
25914
+ marks.forEach((mark) => {
25915
+ if (!mark) return;
25916
+ if (mark.type === "textStyle") {
25917
+ const attrs = mark.attrs || {};
25918
+ if (Object.keys(attrs).length) textStyleAttrs = { ...textStyleAttrs, ...attrs };
25919
+ return;
25920
+ }
25921
+ if (mark.type) inlineMarks.push(mark.attrs ? { type: mark.type, attrs: { ...mark.attrs } } : { type: mark.type });
25922
+ });
25923
+ return {
25924
+ inlineMarks,
25925
+ textStyleAttrs: Object.keys(textStyleAttrs).length ? textStyleAttrs : null
25926
+ };
25927
+ };
25928
+ const mergeInlineMarkSets = (...markSets) => {
25929
+ const map = /* @__PURE__ */ new Map();
25930
+ markSets.filter(Boolean).forEach((marks) => {
25931
+ marks.forEach((mark) => {
25932
+ if (!mark || !mark.type) return;
25933
+ map.set(mark.type, mark.attrs ? { type: mark.type, attrs: { ...mark.attrs } } : { type: mark.type });
25934
+ });
25935
+ });
25936
+ return Array.from(map.values());
25937
+ };
25938
+ const mergeTextStyleAttrs = (...attrsList) => {
25939
+ const merged = attrsList.filter((attrs) => attrs && Object.keys(attrs).length).reduce((acc, attrs) => ({ ...acc, ...attrs }), {});
25940
+ return Object.keys(merged).length ? merged : null;
25941
+ };
25942
+ const cloneRunAttrs = (attrs) => {
25943
+ const clone = { ...attrs };
25944
+ if (Array.isArray(attrs?.runProperties)) {
25945
+ clone.runProperties = attrs.runProperties.map((entry) => ({
25946
+ xmlName: entry?.xmlName,
25947
+ attributes: { ...entry?.attributes || {} }
25948
+ }));
25949
+ }
25950
+ return clone;
25951
+ };
25952
+ const cloneMark$1 = (mark) => {
25953
+ if (!mark || typeof mark !== "object") return mark;
25954
+ const cloned = { ...mark };
25955
+ if (mark.attrs && typeof mark.attrs === "object") {
25956
+ cloned.attrs = { ...mark.attrs };
25957
+ if (Array.isArray(mark.attrs.runProperties)) {
25958
+ cloned.attrs.runProperties = mark.attrs.runProperties.map((entry) => ({
25959
+ xmlName: entry?.xmlName,
25960
+ attributes: { ...entry?.attributes || {} }
25961
+ }));
25962
+ }
25963
+ }
25964
+ return cloned;
25965
+ };
25966
+ const normalizeBool = (value) => {
25967
+ if (value === void 0 || value === null) return true;
25968
+ if (typeof value === "boolean") return value;
25969
+ if (typeof value === "number") return value !== 0;
25970
+ const normalized = String(value).trim().toLowerCase();
25971
+ if (normalized === "0" || normalized === "false" || normalized === "off") return false;
25972
+ if (normalized === "1" || normalized === "true" || normalized === "on") return true;
25973
+ return true;
25974
+ };
25975
+ const createRunPropertiesElement = (entries = []) => {
25976
+ if (!Array.isArray(entries) || !entries.length) return null;
25977
+ const elements = entries.map((entry) => {
25978
+ if (!entry || !entry.xmlName) return null;
25979
+ return {
25980
+ name: entry.xmlName,
25981
+ attributes: { ...entry.attributes || {} }
25982
+ };
25983
+ }).filter(Boolean);
25984
+ if (!elements.length) return null;
25985
+ return {
25986
+ name: "w:rPr",
25987
+ elements
25988
+ };
25989
+ };
25990
+ const cloneXmlNode = (nodeLike) => {
25991
+ if (!nodeLike || typeof nodeLike !== "object") return nodeLike;
25992
+ return {
25993
+ name: nodeLike.name,
25994
+ type: nodeLike.type,
25995
+ attributes: nodeLike.attributes ? { ...nodeLike.attributes } : void 0,
25996
+ elements: Array.isArray(nodeLike.elements) ? nodeLike.elements.map((el) => cloneXmlNode(el)) : void 0,
25997
+ text: nodeLike.text
25998
+ };
25999
+ };
26000
+ const applyRunPropertiesTemplate = (runNode, runPropertiesTemplate) => {
26001
+ if (!runNode || !runPropertiesTemplate) return;
26002
+ if (!Array.isArray(runNode.elements)) runNode.elements = [];
26003
+ let runProps = runNode.elements.find((el) => el?.name === "w:rPr");
26004
+ if (!runProps) {
26005
+ runProps = { name: "w:rPr", elements: [] };
26006
+ runNode.elements.unshift(runProps);
26007
+ }
26008
+ if (!Array.isArray(runProps.elements)) runProps.elements = [];
26009
+ if (runPropertiesTemplate.attributes) {
26010
+ runProps.attributes = {
26011
+ ...runProps.attributes || {},
26012
+ ...runPropertiesTemplate.attributes
26013
+ };
26014
+ }
26015
+ const isValidRunPropName = (name) => typeof name === "string" && name.includes(":");
26016
+ runProps.elements = runProps.elements.filter((entry) => isValidRunPropName(entry?.name));
26017
+ const existingNames = new Set(runProps.elements.map((el) => el?.name));
26018
+ (runPropertiesTemplate.elements || []).forEach((entry) => {
26019
+ if (!isValidRunPropName(entry?.name) || existingNames.has(entry.name)) return;
26020
+ runProps.elements.push(cloneXmlNode(entry));
26021
+ existingNames.add(entry.name);
26022
+ });
26023
+ };
26024
+ const splitRunProperties = (entries = [], docx = null) => {
26025
+ const remainingProps = [];
26026
+ const inlineMarks = [];
26027
+ const textStyleAttrs = {};
26028
+ let hasTextStyle = false;
26029
+ let highlightColor = null;
26030
+ let runStyleId = null;
26031
+ entries.forEach((entry) => {
26032
+ if (!entry || !entry.xmlName) return;
26033
+ const attributes = entry.attributes || {};
26034
+ switch (entry.xmlName) {
26035
+ case "w:b": {
26036
+ const val = normalizeBool(attributes["w:val"]);
26037
+ inlineMarks.push(val ? { type: "bold" } : { type: "bold", attrs: { value: "0" } });
26038
+ break;
26039
+ }
26040
+ case "w:i": {
26041
+ const val = normalizeBool(attributes["w:val"]);
26042
+ inlineMarks.push(val ? { type: "italic" } : { type: "italic", attrs: { value: "0" } });
26043
+ break;
26044
+ }
26045
+ case "w:u": {
26046
+ const rawVal = attributes["w:val"];
26047
+ const underlineType = rawVal == null || rawVal === "" ? "single" : String(rawVal);
26048
+ const attrs = {};
26049
+ if (underlineType.toLowerCase() === "none" || underlineType === "0") {
26050
+ attrs.underlineType = "none";
26051
+ } else {
26052
+ attrs.underlineType = underlineType;
26053
+ const colorRaw = attributes["w:color"];
26054
+ if (typeof colorRaw === "string" && colorRaw.toLowerCase() !== "auto") {
26055
+ const normalizedColor = normalizeHexColor(colorRaw);
26056
+ if (normalizedColor) attrs.underlineColor = `#${normalizedColor}`;
26057
+ }
26058
+ }
26059
+ if (attributes["w:themeColor"]) attrs.underlineThemeColor = attributes["w:themeColor"];
26060
+ if (attributes["w:themeTint"]) attrs.underlineThemeTint = attributes["w:themeTint"];
26061
+ if (attributes["w:themeShade"]) attrs.underlineThemeShade = attributes["w:themeShade"];
26062
+ inlineMarks.push({ type: "underline", attrs });
26063
+ break;
26064
+ }
26065
+ case "w:color": {
26066
+ const raw = attributes["w:val"];
26067
+ if (typeof raw === "string" && raw) {
26068
+ hasTextStyle = true;
26069
+ textStyleAttrs.color = `#${raw.replace("#", "").toUpperCase()}`;
26070
+ }
26071
+ break;
26072
+ }
26073
+ case "w:rFonts": {
26074
+ const asciiFamily = attributes["w:ascii"] || attributes["w:hAnsi"] || (attributes["w:eastAsia"] ? void 0 : attributes["w:val"]);
26075
+ const eastAsiaFamily = attributes["w:eastAsia"];
26076
+ if (asciiFamily) {
26077
+ hasTextStyle = true;
26078
+ textStyleAttrs.fontFamily = SuperConverter.toCssFontFamily(asciiFamily, docx);
26079
+ }
26080
+ if (eastAsiaFamily) {
26081
+ hasTextStyle = true;
26082
+ const eastAsiaCss = SuperConverter.toCssFontFamily(eastAsiaFamily, docx);
26083
+ if (!asciiFamily || eastAsiaCss !== textStyleAttrs.fontFamily) {
26084
+ textStyleAttrs.eastAsiaFontFamily = eastAsiaCss;
26085
+ }
26086
+ }
26087
+ break;
26088
+ }
26089
+ case "w:sz":
26090
+ case "w:szCs": {
26091
+ const rawSize = Number(attributes["w:val"]);
26092
+ if (Number.isFinite(rawSize) && rawSize > 0) {
26093
+ hasTextStyle = true;
26094
+ textStyleAttrs.fontSize = `${rawSize / 2}pt`;
26095
+ }
26096
+ break;
26097
+ }
26098
+ case "w:strike": {
26099
+ const val = normalizeBool(attributes["w:val"]);
26100
+ inlineMarks.push(val ? { type: "strike" } : { type: "strike", attrs: { value: "0" } });
26101
+ break;
26102
+ }
26103
+ case "w:highlight": {
26104
+ const color = attributes["w:val"];
26105
+ if (typeof color === "string" && color) {
26106
+ highlightColor = color.toLowerCase() === "none" ? "transparent" : color;
26107
+ }
26108
+ break;
26109
+ }
26110
+ case "w:shd": {
26111
+ const fill = attributes["w:fill"];
26112
+ const shdVal = attributes["w:val"];
26113
+ if (fill && String(fill).toLowerCase() !== "auto") {
26114
+ highlightColor = `#${String(fill).replace("#", "")}`;
26115
+ } else if (typeof shdVal === "string") {
26116
+ const normalized = shdVal.toLowerCase();
26117
+ if (normalized === "clear" || normalized === "nil" || normalized === "none") {
26118
+ highlightColor = "transparent";
26119
+ }
26120
+ }
26121
+ break;
26122
+ }
26123
+ case "w:rStyle": {
26124
+ if (typeof attributes["w:val"] === "string") runStyleId = attributes["w:val"];
26125
+ remainingProps.push({ xmlName: entry.xmlName, attributes: { ...attributes } });
26126
+ break;
26127
+ }
26128
+ default: {
26129
+ remainingProps.push({ xmlName: entry.xmlName, attributes: { ...attributes } });
26130
+ }
26131
+ }
26132
+ });
26133
+ if (highlightColor) inlineMarks.push({ type: "highlight", attrs: { color: highlightColor } });
26134
+ return {
26135
+ remainingProps,
26136
+ inlineMarks,
26137
+ textStyleAttrs: hasTextStyle ? textStyleAttrs : null,
26138
+ runStyleId
26139
+ };
26140
+ };
26141
+ const cloneMark = (mark) => {
26142
+ if (!mark) return mark;
26143
+ return {
26144
+ ...mark,
26145
+ attrs: mark.attrs ? { ...mark.attrs } : void 0
26146
+ };
26147
+ };
26148
+ const cloneNode = (node) => {
26149
+ if (!node || typeof node !== "object") return node;
26150
+ const cloned = { ...node };
26151
+ if (node.marks) cloned.marks = node.marks.map((mark) => cloneMark(mark));
26152
+ if (node.content) cloned.content = node.content.map((child) => cloneNode(child));
26153
+ if (node.elements) cloned.elements = node.elements.map((el) => cloneNode(el));
26154
+ if (node.attributes) cloned.attributes = { ...node.attributes };
26155
+ return cloned;
26156
+ };
26157
+ const cloneRuns = (runs = []) => runs.map((run2) => cloneNode(run2));
26158
+ const prepareRunTrackingContext = (node = {}) => {
26159
+ const marks = Array.isArray(node.marks) ? node.marks : [];
26160
+ const trackingMarks = marks.filter(
26161
+ (mark) => mark?.type === TrackInsertMarkName || mark?.type === TrackDeleteMarkName
26162
+ );
26163
+ if (!trackingMarks.length) {
26164
+ return { runNode: node, trackingMarksByType: /* @__PURE__ */ new Map() };
26165
+ }
26166
+ const trackingMarksByType = /* @__PURE__ */ new Map();
26167
+ trackingMarks.forEach((mark) => {
26168
+ if (mark?.type) trackingMarksByType.set(mark.type, cloneMark(mark));
26169
+ });
26170
+ const preservedMarks = marks.filter((mark) => mark?.type !== TrackInsertMarkName && mark?.type !== TrackDeleteMarkName).map((mark) => cloneMark(mark));
26171
+ const clonedContent = Array.isArray(node.content) ? node.content.map((child) => {
26172
+ const childClone = cloneNode(child);
26173
+ const childMarks = Array.isArray(childClone.marks) ? childClone.marks.slice() : [];
26174
+ trackingMarks.forEach((mark) => {
26175
+ childMarks.push(cloneMark(mark));
26176
+ });
26177
+ childClone.marks = childMarks;
26178
+ return childClone;
26179
+ }) : [];
26180
+ return {
26181
+ runNode: {
26182
+ ...cloneNode(node),
26183
+ marks: preservedMarks,
26184
+ content: clonedContent
26185
+ },
26186
+ trackingMarksByType
26187
+ };
26188
+ };
26189
+ const mapTrackingAttrs = (mark, attrMap) => {
26190
+ const source = mark?.attrs || {};
26191
+ const mapped = {};
26192
+ attrMap.forEach((targetKey, sourceKey) => {
26193
+ if (source[sourceKey] != null) mapped[targetKey] = source[sourceKey];
26194
+ });
26195
+ return mapped;
26196
+ };
26197
+ const renameTextElementsForDeletion = (node) => {
26198
+ if (!node || typeof node !== "object") return;
26199
+ if (node.name === "w:t") node.name = "w:delText";
26200
+ if (Array.isArray(node.elements)) node.elements.forEach(renameTextElementsForDeletion);
26201
+ };
26202
+ const ensureTrackedWrapper = (runs, trackingMarksByType = /* @__PURE__ */ new Map()) => {
26203
+ if (!Array.isArray(runs) || !runs.length) return runs;
26204
+ const firstRun = runs[0];
26205
+ if (firstRun?.name === "w:ins" || firstRun?.name === "w:del") {
26206
+ return runs;
26207
+ }
26208
+ if (!trackingMarksByType.size) return runs;
26209
+ if (trackingMarksByType.has(TrackInsertMarkName)) {
26210
+ const mark = trackingMarksByType.get(TrackInsertMarkName);
26211
+ const clonedRuns = cloneRuns(runs);
26212
+ const wrapper = {
26213
+ name: "w:ins",
26214
+ attributes: mapTrackingAttrs(
26215
+ mark,
26216
+ /* @__PURE__ */ new Map([
26217
+ ["id", "w:id"],
26218
+ ["author", "w:author"],
26219
+ ["authorEmail", "w:authorEmail"],
26220
+ ["date", "w:date"]
26221
+ ])
26222
+ ),
26223
+ elements: clonedRuns
26224
+ };
26225
+ return [wrapper];
26226
+ }
26227
+ if (trackingMarksByType.has(TrackDeleteMarkName)) {
26228
+ const mark = trackingMarksByType.get(TrackDeleteMarkName);
26229
+ const clonedRuns = cloneRuns(runs);
26230
+ clonedRuns.forEach(renameTextElementsForDeletion);
26231
+ const wrapper = {
26232
+ name: "w:del",
26233
+ attributes: mapTrackingAttrs(mark, /* @__PURE__ */ new Map([["id", "w:id"]])),
26234
+ elements: clonedRuns
26235
+ };
26236
+ return [wrapper];
26237
+ }
26238
+ return runs;
26239
+ };
26240
+ const encode$p = (attributes) => {
26241
+ return attributes["w:rsidR"];
26242
+ };
26243
+ const decode$p = (attrs) => {
26244
+ return attrs.rsidR;
26245
+ };
26246
+ const attrConfig$9 = Object.freeze({
26247
+ xmlName: "w:rsidR",
26248
+ sdName: "rsidR",
26249
+ encode: encode$p,
26250
+ decode: decode$p
26251
+ });
26252
+ const encode$o = (attributes) => {
26253
+ return attributes["w:rsidRPr"];
26254
+ };
26255
+ const decode$o = (attrs) => {
26256
+ return attrs.rsidRPr;
26257
+ };
26258
+ const attrConfig$8 = Object.freeze({
26259
+ xmlName: "w:rsidRPr",
26260
+ sdName: "rsidRPr",
26261
+ encode: encode$o,
26262
+ decode: decode$o
26263
+ });
26264
+ const encode$n = (attributes) => {
26265
+ return attributes["w:rsidDel"];
26266
+ };
26267
+ const decode$n = (attrs) => {
26268
+ return attrs.rsidDel;
26269
+ };
26270
+ const attrConfig$7 = Object.freeze({
26271
+ xmlName: "w:rsidDel",
26272
+ sdName: "rsidDel",
26273
+ encode: encode$n,
26274
+ decode: decode$n
26275
+ });
26276
+ const validXmlAttributes$9 = [attrConfig$9, attrConfig$8, attrConfig$7];
26277
+ const XML_NODE_NAME$f = "w:r";
26278
+ const SD_KEY_NAME = "run";
26279
+ const encode$m = (params, encodedAttrs = {}) => {
26280
+ const { nodes = [], nodeListHandler } = params || {};
26281
+ const runNode = nodes[0];
26282
+ if (!runNode) return void 0;
26283
+ const elements = Array.isArray(runNode.elements) ? runNode.elements : [];
26284
+ const rPrNode = elements.find((child) => child?.name === "w:rPr");
26285
+ const contentElements = rPrNode ? elements.filter((el) => el !== rPrNode) : elements;
26286
+ const { entries: runPropEntries, hadRPr, styleChangeMarks } = collectRunProperties(params, rPrNode);
26287
+ const { remainingProps, inlineMarks, textStyleAttrs, runStyleId } = splitRunProperties(runPropEntries, params?.docx);
26288
+ const styleMarks = deriveStyleMarks({
26289
+ docx: params?.docx,
26290
+ paragraphStyleId: params?.parentStyleId,
26291
+ runStyleId
26292
+ });
26293
+ const mergedInlineMarks = mergeInlineMarkSets(styleMarks.inlineMarks, inlineMarks);
26294
+ let mergedTextStyleAttrs = mergeTextStyleAttrs(styleMarks.textStyleAttrs, textStyleAttrs);
26295
+ if (runStyleId) {
26296
+ mergedTextStyleAttrs = mergedTextStyleAttrs ? { ...mergedTextStyleAttrs, styleId: runStyleId } : { styleId: runStyleId };
26297
+ }
26298
+ const runAttrs = buildRunAttrs(encodedAttrs, hadRPr, remainingProps);
26299
+ let runLevelMarks = Array.isArray(runNode.marks) ? runNode.marks.map((mark) => cloneMark$1(mark)) : [];
26300
+ if (styleChangeMarks?.length) {
26301
+ runLevelMarks = [...runLevelMarks, ...styleChangeMarks.map((mark) => cloneMark$1(mark))];
26302
+ }
26303
+ const childParams = { ...params, nodes: contentElements };
26304
+ const content = nodeListHandler?.handler(childParams) || [];
26305
+ const contentWithRunMarks = content.map((child) => {
26306
+ if (!child || typeof child !== "object") return child;
26307
+ const baseMarks = Array.isArray(child.marks) ? child.marks.map((mark) => cloneMark$1(mark)) : [];
26308
+ if (!runLevelMarks.length) return child;
26309
+ return { ...child, marks: [...baseMarks, ...runLevelMarks.map((mark) => cloneMark$1(mark))] };
26310
+ });
26311
+ const marked = contentWithRunMarks.map((child) => applyRunMarks(child, mergedInlineMarks, mergedTextStyleAttrs));
26312
+ const filtered = marked.filter(Boolean);
26313
+ const runNodeResult = {
26314
+ type: SD_KEY_NAME,
26315
+ content: filtered
26316
+ };
26317
+ const attrs = cloneRunAttrs(runAttrs);
26318
+ if (attrs && Object.keys(attrs).length) {
26319
+ if (attrs.runProperties == null) delete attrs.runProperties;
26320
+ if (Object.keys(attrs).length) runNodeResult.attrs = attrs;
26321
+ }
26322
+ if (runLevelMarks.length) {
26323
+ runNodeResult.marks = runLevelMarks.map((mark) => cloneMark$1(mark));
26324
+ }
26325
+ return runNodeResult;
26326
+ };
26327
+ const decode$m = (params, decodedAttrs = {}) => {
26328
+ const { node } = params || {};
26329
+ if (!node) return void 0;
26330
+ const { runNode: runNodeForExport, trackingMarksByType } = prepareRunTrackingContext(node);
26331
+ const runAttrs = runNodeForExport.attrs || {};
26332
+ const runProperties = Array.isArray(runAttrs.runProperties) ? runAttrs.runProperties : [];
26333
+ const exportParams = { ...params, node: runNodeForExport };
26334
+ if (!exportParams.editor) {
26335
+ exportParams.editor = { extensionService: { extensions: [] } };
26336
+ }
26337
+ const childElements = translateChildNodes(exportParams) || [];
26338
+ let runPropertiesElement = createRunPropertiesElement(runProperties);
26339
+ const markElements = processOutputMarks(Array.isArray(runNodeForExport.marks) ? runNodeForExport.marks : []);
26340
+ if (markElements.length) {
26341
+ if (!runPropertiesElement) {
26342
+ runPropertiesElement = generateRunProps(markElements);
26343
+ } else {
26344
+ if (!Array.isArray(runPropertiesElement.elements)) runPropertiesElement.elements = [];
26345
+ const existingNames = new Set(
26346
+ runPropertiesElement.elements.map((el) => el?.name).filter((name) => typeof name === "string")
26347
+ );
26348
+ markElements.forEach((element) => {
26349
+ if (!element || !element.name || existingNames.has(element.name)) return;
26350
+ runPropertiesElement.elements.push({ ...element, attributes: { ...element.attributes || {} } });
26351
+ existingNames.add(element.name);
26352
+ });
26353
+ }
26354
+ }
26355
+ const runPropsTemplate = runPropertiesElement ? cloneXmlNode(runPropertiesElement) : null;
26356
+ const applyBaseRunProps = (runNode) => applyRunPropertiesTemplate(runNode, runPropsTemplate);
26357
+ const runs = [];
26358
+ childElements.forEach((child) => {
26359
+ if (!child) return;
26360
+ if (child.name === "w:r") {
26361
+ const clonedRun = cloneXmlNode(child);
26362
+ applyBaseRunProps(clonedRun);
26363
+ runs.push(clonedRun);
26364
+ return;
26365
+ }
26366
+ if (child.name === "w:hyperlink") {
26367
+ const hyperlinkClone = cloneXmlNode(child);
26368
+ if (Array.isArray(hyperlinkClone.elements)) {
26369
+ hyperlinkClone.elements.forEach((run2) => applyBaseRunProps(run2));
26370
+ }
26371
+ runs.push(hyperlinkClone);
26372
+ return;
26373
+ }
26374
+ if (child.name === "w:ins" || child.name === "w:del") {
26375
+ const trackedClone = cloneXmlNode(child);
26376
+ if (Array.isArray(trackedClone.elements)) {
26377
+ trackedClone.elements.forEach((element) => {
26378
+ if (element?.name === "w:r") applyBaseRunProps(element);
26379
+ });
26380
+ }
26381
+ runs.push(trackedClone);
26382
+ return;
26383
+ }
26384
+ const runWrapper = { name: XML_NODE_NAME$f, elements: [] };
26385
+ applyBaseRunProps(runWrapper);
26386
+ if (!Array.isArray(runWrapper.elements)) runWrapper.elements = [];
26387
+ runWrapper.elements.push(cloneXmlNode(child));
26388
+ runs.push(runWrapper);
26389
+ });
26390
+ const trackedRuns = ensureTrackedWrapper(runs, trackingMarksByType);
26391
+ if (!trackedRuns.length) {
26392
+ const emptyRun = { name: XML_NODE_NAME$f, elements: [] };
26393
+ applyBaseRunProps(emptyRun);
26394
+ trackedRuns.push(emptyRun);
26395
+ }
26396
+ if (decodedAttrs && Object.keys(decodedAttrs).length) {
26397
+ trackedRuns.forEach((run2) => {
26398
+ run2.attributes = { ...run2.attributes || {}, ...decodedAttrs };
26399
+ });
26400
+ }
26401
+ if (trackedRuns.length === 1) {
26402
+ return trackedRuns[0];
26403
+ }
26404
+ return trackedRuns;
26405
+ };
26406
+ const config$d = {
26407
+ xmlName: XML_NODE_NAME$f,
26408
+ sdNodeOrKeyName: SD_KEY_NAME,
26409
+ type: NodeTranslator.translatorTypes.NODE,
26410
+ encode: encode$m,
26411
+ decode: decode$m,
26412
+ attributes: validXmlAttributes$9
26413
+ };
26414
+ const translator$T = NodeTranslator.from(config$d);
26415
+ const generateV2HandlerEntity = (handlerName, translator2) => ({
26416
+ handlerName,
26417
+ handler: (params) => {
26418
+ const { nodes } = params;
26419
+ if (nodes.length === 0 || nodes[0].name !== translator2.xmlName) {
26420
+ return { nodes: [], consumed: 0 };
26421
+ }
26422
+ const result = translator2.encode(params);
26423
+ if (!result) return { nodes: [], consumed: 0 };
26424
+ return {
26425
+ nodes: Array.isArray(result) ? result : [result],
26426
+ consumed: 1
26427
+ };
26428
+ }
26429
+ });
26430
+ function createSingleAttrPropertyHandler(xmlName, sdName = null, attrName = "w:val", transformEncode = null, transformDecode = null) {
26431
+ if (!sdName) sdName = xmlName.split(":")[1];
26432
+ if (!transformEncode) transformEncode = (v2) => v2;
26433
+ if (!transformDecode) transformDecode = (v2) => v2;
26434
+ return {
26435
+ xmlName,
26436
+ sdNodeOrKeyName: sdName,
26437
+ encode: ({ nodes }) => {
26438
+ return transformEncode(nodes[0].attributes[attrName]) ?? void 0;
26439
+ },
26440
+ decode: ({ node }) => {
26441
+ const value = node.attrs?.[sdName] != null ? transformDecode(node.attrs[sdName]) : void 0;
26442
+ return value != null ? { name: xmlName, attributes: { [attrName]: value } } : void 0;
26443
+ }
26444
+ };
26445
+ }
26446
+ function createMeasurementPropertyHandler(xmlName, sdName = null) {
26447
+ if (!sdName) sdName = xmlName.split(":")[1];
26448
+ return {
26449
+ xmlName,
26450
+ sdNodeOrKeyName: sdName,
26451
+ attributes: [
26452
+ createAttributeHandler("w:w", "value", parseInteger, integerToString),
26453
+ createAttributeHandler("w:type")
26454
+ ],
26455
+ encode: (_2, encodedAttrs) => {
26456
+ return encodedAttrs["value"] != null ? encodedAttrs : void 0;
26457
+ },
26458
+ decode: function({ node }) {
26459
+ const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs[sdName] || {} } });
26460
+ return decodedAttrs["w:w"] != null ? { attributes: decodedAttrs } : void 0;
26461
+ }
26462
+ };
26463
+ }
26464
+ function createBorderPropertyHandler(xmlName, sdName = null) {
26465
+ if (!sdName) sdName = xmlName.split(":")[1];
26466
+ return {
26467
+ xmlName,
26468
+ sdNodeOrKeyName: sdName,
26469
+ attributes: [
26470
+ createAttributeHandler("w:val"),
26471
+ createAttributeHandler("w:color"),
26472
+ createAttributeHandler("w:themeColor"),
26473
+ createAttributeHandler("w:themeTint"),
26474
+ createAttributeHandler("w:themeShade"),
26475
+ createAttributeHandler("w:sz", "size", parseInteger, integerToString),
26476
+ createAttributeHandler("w:space", null, parseInteger, integerToString),
26477
+ createAttributeHandler("w:shadow", null, parseBoolean, booleanToString),
26478
+ createAttributeHandler("w:frame", null, parseBoolean, booleanToString)
26479
+ ],
26480
+ encode: (params, encodedAttrs) => {
26481
+ return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
26482
+ },
26483
+ decode: function({ node }, context) {
26484
+ const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs[sdName] || {} } });
26485
+ return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
26486
+ }
26487
+ };
26488
+ }
26489
+ const createAttributeHandler = (xmlName, sdName = null, transformEncode = null, transformDecode = null) => {
26490
+ if (!transformEncode) transformEncode = (v2) => v2;
26491
+ if (!transformDecode) transformDecode = (v2) => v2;
26492
+ if (!sdName) sdName = xmlName.split(":")[1];
26493
+ return {
26494
+ xmlName,
26495
+ sdName,
26496
+ encode: (attributes) => transformEncode(attributes[xmlName]),
26497
+ decode: (attributes) => transformDecode(attributes[sdName])
26498
+ };
26499
+ };
26500
+ function encodeProperties(node, translatorsByXmlName, asArray = false) {
26501
+ if (!node?.elements || node.elements.length === 0) {
26502
+ return asArray ? [] : {};
26503
+ }
26504
+ const attributes = asArray ? [] : {};
26505
+ node.elements.forEach((el) => {
26506
+ const translator2 = translatorsByXmlName[el.name];
26507
+ if (translator2) {
26508
+ const encodedAttr = translator2.encode({ nodes: [el] });
26509
+ if (encodedAttr != null) {
26510
+ if (asArray) {
26511
+ attributes.push({ [translator2.sdNodeOrKeyName]: encodedAttr });
26512
+ } else {
26513
+ attributes[translator2.sdNodeOrKeyName] = encodedAttr;
26514
+ }
26515
+ }
26516
+ }
26517
+ });
26518
+ return attributes;
26519
+ }
26520
+ function decodeProperties(translatorsBySdName, properties) {
26521
+ if (!properties || typeof properties !== "object") {
26522
+ return [];
26523
+ }
26524
+ const elements = [];
26525
+ Object.keys(properties).forEach((key) => {
26526
+ const translator2 = translatorsBySdName[key];
26527
+ if (translator2) {
26528
+ const result = translator2.decode({ node: { attrs: { [key]: properties[key] } } });
26529
+ if (result != null) {
26530
+ result.name = translator2.xmlName;
26531
+ elements.push(result);
26532
+ }
26533
+ }
26534
+ });
26535
+ return elements;
26536
+ }
26537
+ const parseBoolean = (value) => value != null ? ["1", "true"].includes(value) : void 0;
26538
+ const booleanToString = (value) => value != null ? value ? "1" : "0" : void 0;
26539
+ const parseInteger = (value) => {
26540
+ if (value == null) return void 0;
26541
+ const intValue = parseInt(value, 10);
26542
+ return isNaN(intValue) ? void 0 : intValue;
26543
+ };
26544
+ const integerToString = (value) => {
26545
+ const intValue = parseInteger(value);
26546
+ return intValue != void 0 ? String(intValue) : void 0;
26547
+ };
26548
+ function preProcessVerticalMergeCells(table, { editorSchema }) {
26549
+ if (!table || !Array.isArray(table.content)) {
26550
+ return table;
26551
+ }
26552
+ const rows = table.content;
26553
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
26554
+ const row = rows[rowIndex];
26555
+ if (!row) continue;
26556
+ if (!Array.isArray(row.content)) {
26557
+ row.content = [];
26558
+ }
26559
+ for (let cellIndex = 0; cellIndex < row.content.length; cellIndex++) {
26560
+ const cell = row.content[cellIndex];
26561
+ if (!cell) continue;
26562
+ const attrs = cell.attrs || {};
26563
+ if (!attrs.rowspan || attrs.rowspan <= 1) continue;
26564
+ const maxRowspan = Math.min(attrs.rowspan, rows.length - rowIndex);
26565
+ for (let offset = 1; offset < maxRowspan; offset++) {
26566
+ const rowToChange = rows[rowIndex + offset];
25308
26567
  if (!rowToChange) continue;
25309
26568
  if (!Array.isArray(rowToChange.content)) {
25310
26569
  rowToChange.content = [];
@@ -26524,17 +27783,52 @@ const encode$d = (params, encodedAttrs) => {
26524
27783
  const { nodes, docx, nodeListHandler } = params;
26525
27784
  const node = nodes[0];
26526
27785
  let href = _resolveHref(docx, encodedAttrs);
26527
- const linkMark = { type: "link", attrs: { ...encodedAttrs, href } };
27786
+ const linkMark = { attrs: { ...encodedAttrs, href } };
26528
27787
  const runNodes = node.elements.filter((el) => el.name === "w:r");
26529
27788
  runNodes.forEach((runNode) => {
26530
- runNode.marks = [...runNode.marks || [], linkMark];
27789
+ const existingRunMarks = Array.isArray(runNode.marks) ? runNode.marks : [];
27790
+ const runMarksWithoutLink = existingRunMarks.filter((mark) => mark?.type !== "link");
27791
+ runNode.marks = runMarksWithoutLink;
26531
27792
  });
26532
27793
  const updatedNode = nodeListHandler.handler({
26533
27794
  ...params,
26534
27795
  nodes: runNodes,
26535
27796
  path: [...params.path || [], node]
26536
27797
  });
26537
- return updatedNode;
27798
+ const cloneMark2 = (mark) => {
27799
+ if (!mark || typeof mark !== "object") return mark;
27800
+ if (!mark.attrs) return { ...mark };
27801
+ return { ...mark, attrs: { ...mark.attrs } };
27802
+ };
27803
+ const ensureLinkMark = (child) => {
27804
+ if (!child || typeof child !== "object") return child;
27805
+ if (Array.isArray(child.content)) {
27806
+ const updatedContent = child.content.map((item) => ensureLinkMark(item));
27807
+ if (updatedContent !== child.content) {
27808
+ child = { ...child, content: updatedContent };
27809
+ }
27810
+ }
27811
+ if (child.type === "run") {
27812
+ const existingMarks2 = Array.isArray(child.marks) ? child.marks : [];
27813
+ const filteredMarks = existingMarks2.filter((mark) => mark?.type !== "link").map((mark) => cloneMark2(mark));
27814
+ if (filteredMarks.length !== existingMarks2.length) {
27815
+ if (filteredMarks.length) child = { ...child, marks: filteredMarks };
27816
+ else {
27817
+ const { marks, ...rest } = child;
27818
+ child = rest;
27819
+ }
27820
+ }
27821
+ return child;
27822
+ }
27823
+ if (child.type !== "text") return child;
27824
+ const existingMarks = Array.isArray(child.marks) ? child.marks.map((mark) => cloneMark2(mark)) : [];
27825
+ const hasLink = existingMarks.some((mark) => mark?.type === "link");
27826
+ if (hasLink) return child;
27827
+ const linkClone = { type: "link", attrs: { ...linkMark.attrs } };
27828
+ return { ...child, marks: [...existingMarks, linkClone] };
27829
+ };
27830
+ if (!Array.isArray(updatedNode)) return updatedNode;
27831
+ return updatedNode.map((child) => ensureLinkMark(child));
26538
27832
  };
26539
27833
  const _resolveHref = (docx, encodedAttrs) => {
26540
27834
  const rels = docx["word/_rels/document.xml.rels"];
@@ -27416,225 +28710,79 @@ function decode$c(params) {
27416
28710
  return translateAnchorNode(params);
27417
28711
  }
27418
28712
  const config$5 = {
27419
- xmlName: XML_NODE_NAME$5,
27420
- sdNodeOrKeyName: SD_NODE_NAME$5,
27421
- type: NodeTranslator.translatorTypes.NODE,
27422
- encode: encode$c,
27423
- decode: decode$c,
27424
- attributes: validXmlAttributes$5
27425
- };
27426
- const translator$5 = NodeTranslator.from(config$5);
27427
- function handleInlineNode(params) {
27428
- const { node } = params.extraParams;
27429
- if (node.name !== "wp:inline") {
27430
- return null;
27431
- }
27432
- return handleImageNode(node, params, false);
27433
- }
27434
- function translateInlineNode(params) {
27435
- const nodeElements = translateImageNode(params);
27436
- return {
27437
- name: "wp:inline",
27438
- attributes: nodeElements.attributes,
27439
- elements: nodeElements.elements
27440
- };
27441
- }
27442
- const XML_NODE_NAME$4 = "wp:inline";
27443
- const SD_NODE_NAME$4 = ["image"];
27444
- const validXmlAttributes$4 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
27445
- function encode$b(params) {
27446
- const { node } = params.extraParams;
27447
- if (!node || !node.type) {
27448
- return null;
27449
- }
27450
- return handleInlineNode(params);
27451
- }
27452
- function decode$b(params) {
27453
- const { node } = params;
27454
- if (!node || !node.type) {
27455
- return null;
27456
- }
27457
- return translateInlineNode(params);
27458
- }
27459
- const config$4 = {
27460
- xmlName: XML_NODE_NAME$4,
27461
- sdNodeOrKeyName: SD_NODE_NAME$4,
27462
- type: NodeTranslator.translatorTypes.NODE,
27463
- encode: encode$b,
27464
- decode: decode$b,
27465
- attributes: validXmlAttributes$4
27466
- };
27467
- const translator$4 = NodeTranslator.from(config$4);
27468
- const encode$a = (attributes) => {
27469
- return attributes["w:id"];
27470
- };
27471
- const decode$a = (attrs) => {
27472
- return attrs.id;
27473
- };
27474
- const attrConfig$6 = Object.freeze({
27475
- xmlName: "w:id",
27476
- sdName: "id",
27477
- encode: encode$a,
27478
- decode: decode$a
27479
- });
27480
- const encode$9 = (attributes) => {
27481
- return attributes["w:name"];
27482
- };
27483
- const decode$9 = (attrs) => {
27484
- return attrs.name;
27485
- };
27486
- const attrConfig$5 = Object.freeze({
27487
- xmlName: "w:name",
27488
- sdName: "name",
27489
- encode: encode$9,
27490
- decode: decode$9
27491
- });
27492
- const encode$8 = (attributes) => {
27493
- return attributes["w:colFirst"];
27494
- };
27495
- const decode$8 = (attrs) => {
27496
- return attrs.colFirst;
27497
- };
27498
- const attrConfig$4 = Object.freeze({
27499
- xmlName: "w:colFirst",
27500
- sdName: "colFirst",
27501
- encode: encode$8,
27502
- decode: decode$8
27503
- });
27504
- const encode$7 = (attributes) => {
27505
- return attributes["w:colLast"];
27506
- };
27507
- const decode$7 = (attrs) => {
27508
- return attrs.colLast;
27509
- };
27510
- const attrConfig$3 = Object.freeze({
27511
- xmlName: "w:colLast",
27512
- sdName: "colLast",
27513
- encode: encode$7,
27514
- decode: decode$7
27515
- });
27516
- const encode$6 = (attributes) => {
27517
- return attributes["w:displacedByCustomXml"];
27518
- };
27519
- const decode$6 = (attrs) => {
27520
- return attrs.displacedByCustomXml;
27521
- };
27522
- const attrConfig$2 = Object.freeze({
27523
- xmlName: "w:displacedByCustomXml",
27524
- sdName: "displacedByCustomXml",
27525
- encode: encode$6,
27526
- decode: decode$6
27527
- });
27528
- const validXmlAttributes$3 = [attrConfig$6, attrConfig$5, attrConfig$4, attrConfig$3, attrConfig$2];
27529
- const XML_NODE_NAME$3 = "w:bookmarkStart";
27530
- const SD_NODE_NAME$3 = "bookmarkStart";
27531
- const encode$5 = (params, encodedAttrs = {}) => {
27532
- return {
27533
- type: "bookmarkStart",
27534
- attrs: encodedAttrs
27535
- };
27536
- };
27537
- const decode$5 = (params, decodedAttrs = {}) => {
27538
- const result = {
27539
- name: "w:bookmarkStart",
27540
- elements: []
27541
- };
27542
- if (decodedAttrs && Object.keys(decodedAttrs).length) {
27543
- result.attributes = decodedAttrs;
27544
- }
27545
- return result;
27546
- };
27547
- const config$3 = {
27548
- xmlName: XML_NODE_NAME$3,
27549
- sdNodeOrKeyName: SD_NODE_NAME$3,
27550
- type: NodeTranslator.translatorTypes.NODE,
27551
- encode: encode$5,
27552
- decode: decode$5,
27553
- attributes: validXmlAttributes$3
27554
- };
27555
- const translator$3 = NodeTranslator.from(config$3);
27556
- const encode$4 = (attributes) => {
27557
- return attributes["w:id"];
27558
- };
27559
- const decode$4 = (attrs) => {
27560
- return attrs.id;
27561
- };
27562
- const attrConfig$1 = Object.freeze({
27563
- xmlName: "w:id",
27564
- sdName: "id",
27565
- encode: encode$4,
27566
- decode: decode$4
27567
- });
27568
- const encode$3 = (attributes) => {
27569
- return attributes["w:displacedByCustomXml"];
27570
- };
27571
- const decode$3 = (attrs) => {
27572
- return attrs.displacedByCustomXml;
27573
- };
27574
- const attrConfig = Object.freeze({
27575
- xmlName: "w:displacedByCustomXml",
27576
- sdName: "displacedByCustomXml",
27577
- encode: encode$3,
27578
- decode: decode$3
27579
- });
27580
- const validXmlAttributes$2 = [attrConfig$1, attrConfig];
27581
- const XML_NODE_NAME$2 = "w:bookmarkEnd";
27582
- const SD_NODE_NAME$2 = "bookmarkEnd";
27583
- const encode$2 = (params, encodedAttrs = {}) => {
27584
- return {
27585
- type: "bookmarkEnd",
27586
- attrs: encodedAttrs
27587
- };
28713
+ xmlName: XML_NODE_NAME$5,
28714
+ sdNodeOrKeyName: SD_NODE_NAME$5,
28715
+ type: NodeTranslator.translatorTypes.NODE,
28716
+ encode: encode$c,
28717
+ decode: decode$c,
28718
+ attributes: validXmlAttributes$5
27588
28719
  };
27589
- const decode$2 = (params, decodedAttrs = {}) => {
27590
- const result = {
27591
- name: "w:bookmarkEnd",
27592
- elements: []
28720
+ const translator$5 = NodeTranslator.from(config$5);
28721
+ function handleInlineNode(params) {
28722
+ const { node } = params.extraParams;
28723
+ if (node.name !== "wp:inline") {
28724
+ return null;
28725
+ }
28726
+ return handleImageNode(node, params, false);
28727
+ }
28728
+ function translateInlineNode(params) {
28729
+ const nodeElements = translateImageNode(params);
28730
+ return {
28731
+ name: "wp:inline",
28732
+ attributes: nodeElements.attributes,
28733
+ elements: nodeElements.elements
27593
28734
  };
27594
- if (decodedAttrs && Object.keys(decodedAttrs).length) {
27595
- result.attributes = decodedAttrs;
28735
+ }
28736
+ const XML_NODE_NAME$4 = "wp:inline";
28737
+ const SD_NODE_NAME$4 = ["image"];
28738
+ const validXmlAttributes$4 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
28739
+ function encode$b(params) {
28740
+ const { node } = params.extraParams;
28741
+ if (!node || !node.type) {
28742
+ return null;
27596
28743
  }
27597
- return result;
27598
- };
27599
- const config$2 = {
27600
- xmlName: XML_NODE_NAME$2,
27601
- sdNodeOrKeyName: SD_NODE_NAME$2,
28744
+ return handleInlineNode(params);
28745
+ }
28746
+ function decode$b(params) {
28747
+ const { node } = params;
28748
+ if (!node || !node.type) {
28749
+ return null;
28750
+ }
28751
+ return translateInlineNode(params);
28752
+ }
28753
+ const config$4 = {
28754
+ xmlName: XML_NODE_NAME$4,
28755
+ sdNodeOrKeyName: SD_NODE_NAME$4,
27602
28756
  type: NodeTranslator.translatorTypes.NODE,
27603
- encode: encode$2,
27604
- decode: decode$2,
27605
- attributes: validXmlAttributes$2
28757
+ encode: encode$b,
28758
+ decode: decode$b,
28759
+ attributes: validXmlAttributes$4
27606
28760
  };
27607
- const translator$2 = NodeTranslator.from(config$2);
27608
- const registeredHandlers = Object.freeze({
27609
- "w:br": translator$V,
27610
- "w:tab": translator$U,
27611
- "w:p": translator$T,
27612
- "wp:anchor": translator$5,
27613
- "wp:inline": translator$4,
27614
- "w:bookmarkStart": translator$3,
27615
- "w:bookmarkEnd": translator$2
27616
- });
27617
- const XML_NODE_NAME$1 = "w:drawing";
27618
- const SD_NODE_NAME$1 = [];
27619
- const validXmlAttributes$1 = [];
27620
- function encode$1(params) {
28761
+ const translator$4 = NodeTranslator.from(config$4);
28762
+ const XML_NODE_NAME$3 = "w:drawing";
28763
+ const SD_NODE_NAME$3 = [];
28764
+ const validXmlAttributes$3 = [];
28765
+ function encode$a(params) {
27621
28766
  const nodes = params.nodes;
27622
28767
  const node = nodes[0];
27623
- const validChildTranslators = ["wp:anchor", "wp:inline"];
28768
+ const translatorByChildName = {
28769
+ "wp:anchor": translator$5,
28770
+ "wp:inline": translator$4
28771
+ };
27624
28772
  return node.elements.reduce((acc, child) => {
27625
28773
  if (acc) return acc;
27626
- if (!validChildTranslators.includes(child.name)) return acc;
27627
- const translator2 = registeredHandlers[child.name];
28774
+ const translator2 = translatorByChildName[child.name];
28775
+ if (!translator2) return acc;
27628
28776
  return translator2.encode({ ...params, extraParams: { node: child } }) || acc;
27629
28777
  }, null);
27630
28778
  }
27631
- function decode$1(params) {
28779
+ function decode$a(params) {
27632
28780
  const { node } = params;
27633
28781
  if (!node || !node.type) {
27634
28782
  return null;
27635
28783
  }
27636
- const handlerName = node.attrs.isAnchor ? "wp:anchor" : "wp:inline";
27637
- const resultNode = registeredHandlers[handlerName].decode(params);
28784
+ const childTranslator = node.attrs.isAnchor ? translator$5 : translator$4;
28785
+ const resultNode = childTranslator.decode(params);
27638
28786
  return wrapTextInRun(
27639
28787
  {
27640
28788
  name: "w:drawing",
@@ -27643,15 +28791,15 @@ function decode$1(params) {
27643
28791
  []
27644
28792
  );
27645
28793
  }
27646
- const config$1 = {
27647
- xmlName: XML_NODE_NAME$1,
27648
- sdNodeOrKeyName: SD_NODE_NAME$1,
28794
+ const config$3 = {
28795
+ xmlName: XML_NODE_NAME$3,
28796
+ sdNodeOrKeyName: SD_NODE_NAME$3,
27649
28797
  type: NodeTranslator.translatorTypes.NODE,
27650
- encode: encode$1,
27651
- decode: decode$1,
27652
- attributes: validXmlAttributes$1
28798
+ encode: encode$a,
28799
+ decode: decode$a,
28800
+ attributes: validXmlAttributes$3
27653
28801
  };
27654
- const translator$1 = NodeTranslator.from(config$1);
28802
+ const translator$3 = NodeTranslator.from(config$3);
27655
28803
  class CommandService {
27656
28804
  /**
27657
28805
  * @param {import('./commands/types/index.js').CommandServiceOptions} props
@@ -28989,7 +30137,7 @@ function prepareTextAnnotation(params) {
28989
30137
  return getTextNodeForExport(attrs.displayLabel, [...marks, ...marksFromAttrs], params);
28990
30138
  }
28991
30139
  function prepareImageAnnotation(params, imageSize) {
28992
- return translator$1.decode({
30140
+ return translator$3.decode({
28993
30141
  ...params,
28994
30142
  imageSize
28995
30143
  });
@@ -29226,10 +30374,10 @@ function translateStructuredContent(params) {
29226
30374
  };
29227
30375
  return result;
29228
30376
  }
29229
- const XML_NODE_NAME = "w:sdt";
29230
- const SD_NODE_NAME = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
29231
- const validXmlAttributes = [];
29232
- function encode(params) {
30377
+ const XML_NODE_NAME$2 = "w:sdt";
30378
+ const SD_NODE_NAME$2 = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
30379
+ const validXmlAttributes$2 = [];
30380
+ function encode$9(params) {
29233
30381
  const nodes = params.nodes;
29234
30382
  const node = nodes[0];
29235
30383
  const { type: sdtType, handler: handler2 } = sdtNodeTypeStrategy(node);
@@ -29239,7 +30387,7 @@ function encode(params) {
29239
30387
  const result = handler2(params);
29240
30388
  return result;
29241
30389
  }
29242
- function decode(params) {
30390
+ function decode$9(params) {
29243
30391
  const { node } = params;
29244
30392
  if (!node || !node.type) {
29245
30393
  return null;
@@ -29255,6 +30403,146 @@ function decode(params) {
29255
30403
  const result = decoder();
29256
30404
  return result;
29257
30405
  }
30406
+ const config$2 = {
30407
+ xmlName: XML_NODE_NAME$2,
30408
+ sdNodeOrKeyName: SD_NODE_NAME$2,
30409
+ type: NodeTranslator.translatorTypes.NODE,
30410
+ encode: encode$9,
30411
+ decode: decode$9,
30412
+ attributes: validXmlAttributes$2
30413
+ };
30414
+ const translator$2 = NodeTranslator.from(config$2);
30415
+ const encode$8 = (attributes) => {
30416
+ return attributes["w:id"];
30417
+ };
30418
+ const decode$8 = (attrs) => {
30419
+ return attrs.id;
30420
+ };
30421
+ const attrConfig$6 = Object.freeze({
30422
+ xmlName: "w:id",
30423
+ sdName: "id",
30424
+ encode: encode$8,
30425
+ decode: decode$8
30426
+ });
30427
+ const encode$7 = (attributes) => {
30428
+ return attributes["w:name"];
30429
+ };
30430
+ const decode$7 = (attrs) => {
30431
+ return attrs.name;
30432
+ };
30433
+ const attrConfig$5 = Object.freeze({
30434
+ xmlName: "w:name",
30435
+ sdName: "name",
30436
+ encode: encode$7,
30437
+ decode: decode$7
30438
+ });
30439
+ const encode$6 = (attributes) => {
30440
+ return attributes["w:colFirst"];
30441
+ };
30442
+ const decode$6 = (attrs) => {
30443
+ return attrs.colFirst;
30444
+ };
30445
+ const attrConfig$4 = Object.freeze({
30446
+ xmlName: "w:colFirst",
30447
+ sdName: "colFirst",
30448
+ encode: encode$6,
30449
+ decode: decode$6
30450
+ });
30451
+ const encode$5 = (attributes) => {
30452
+ return attributes["w:colLast"];
30453
+ };
30454
+ const decode$5 = (attrs) => {
30455
+ return attrs.colLast;
30456
+ };
30457
+ const attrConfig$3 = Object.freeze({
30458
+ xmlName: "w:colLast",
30459
+ sdName: "colLast",
30460
+ encode: encode$5,
30461
+ decode: decode$5
30462
+ });
30463
+ const encode$4 = (attributes) => {
30464
+ return attributes["w:displacedByCustomXml"];
30465
+ };
30466
+ const decode$4 = (attrs) => {
30467
+ return attrs.displacedByCustomXml;
30468
+ };
30469
+ const attrConfig$2 = Object.freeze({
30470
+ xmlName: "w:displacedByCustomXml",
30471
+ sdName: "displacedByCustomXml",
30472
+ encode: encode$4,
30473
+ decode: decode$4
30474
+ });
30475
+ const validXmlAttributes$1 = [attrConfig$6, attrConfig$5, attrConfig$4, attrConfig$3, attrConfig$2];
30476
+ const XML_NODE_NAME$1 = "w:bookmarkStart";
30477
+ const SD_NODE_NAME$1 = "bookmarkStart";
30478
+ const encode$3 = (params, encodedAttrs = {}) => {
30479
+ return {
30480
+ type: "bookmarkStart",
30481
+ attrs: encodedAttrs
30482
+ };
30483
+ };
30484
+ const decode$3 = (params, decodedAttrs = {}) => {
30485
+ const result = {
30486
+ name: "w:bookmarkStart",
30487
+ elements: []
30488
+ };
30489
+ if (decodedAttrs && Object.keys(decodedAttrs).length) {
30490
+ result.attributes = decodedAttrs;
30491
+ }
30492
+ return result;
30493
+ };
30494
+ const config$1 = {
30495
+ xmlName: XML_NODE_NAME$1,
30496
+ sdNodeOrKeyName: SD_NODE_NAME$1,
30497
+ type: NodeTranslator.translatorTypes.NODE,
30498
+ encode: encode$3,
30499
+ decode: decode$3,
30500
+ attributes: validXmlAttributes$1
30501
+ };
30502
+ const translator$1 = NodeTranslator.from(config$1);
30503
+ const encode$2 = (attributes) => {
30504
+ return attributes["w:id"];
30505
+ };
30506
+ const decode$2 = (attrs) => {
30507
+ return attrs.id;
30508
+ };
30509
+ const attrConfig$1 = Object.freeze({
30510
+ xmlName: "w:id",
30511
+ sdName: "id",
30512
+ encode: encode$2,
30513
+ decode: decode$2
30514
+ });
30515
+ const encode$1 = (attributes) => {
30516
+ return attributes["w:displacedByCustomXml"];
30517
+ };
30518
+ const decode$1 = (attrs) => {
30519
+ return attrs.displacedByCustomXml;
30520
+ };
30521
+ const attrConfig = Object.freeze({
30522
+ xmlName: "w:displacedByCustomXml",
30523
+ sdName: "displacedByCustomXml",
30524
+ encode: encode$1,
30525
+ decode: decode$1
30526
+ });
30527
+ const validXmlAttributes = [attrConfig$1, attrConfig];
30528
+ const XML_NODE_NAME = "w:bookmarkEnd";
30529
+ const SD_NODE_NAME = "bookmarkEnd";
30530
+ const encode = (params, encodedAttrs = {}) => {
30531
+ return {
30532
+ type: "bookmarkEnd",
30533
+ attrs: encodedAttrs
30534
+ };
30535
+ };
30536
+ const decode = (params, decodedAttrs = {}) => {
30537
+ const result = {
30538
+ name: "w:bookmarkEnd",
30539
+ elements: []
30540
+ };
30541
+ if (decodedAttrs && Object.keys(decodedAttrs).length) {
30542
+ result.attributes = decodedAttrs;
30543
+ }
30544
+ return result;
30545
+ };
29258
30546
  const config = {
29259
30547
  xmlName: XML_NODE_NAME,
29260
30548
  sdNodeOrKeyName: SD_NODE_NAME,
@@ -29264,35 +30552,44 @@ const config = {
29264
30552
  attributes: validXmlAttributes
29265
30553
  };
29266
30554
  const translator = NodeTranslator.from(config);
30555
+ const isLineBreakOnlyRun = (node) => {
30556
+ if (!node) return false;
30557
+ if (node.type === "lineBreak" || node.type === "hardBreak") return true;
30558
+ if (node.type !== "run") return false;
30559
+ const runContent = Array.isArray(node.content) ? node.content : [];
30560
+ if (!runContent.length) return false;
30561
+ return runContent.every((child) => child?.type === "lineBreak" || child?.type === "hardBreak");
30562
+ };
29267
30563
  function exportSchemaToJson(params) {
29268
30564
  const { type: type2 } = params.node || {};
29269
30565
  const router = {
29270
30566
  doc: translateDocumentNode,
29271
30567
  body: translateBodyNode,
29272
30568
  heading: translateHeadingNode,
29273
- paragraph: translator$T,
30569
+ paragraph: translator$12,
30570
+ run: translator$T,
29274
30571
  text: translateTextNode,
29275
30572
  bulletList: translateList,
29276
30573
  orderedList: translateList,
29277
- lineBreak: translator$V,
30574
+ lineBreak: translator$15,
29278
30575
  table: translator$8,
29279
30576
  tableRow: translator$F,
29280
30577
  tableCell: translator$7,
29281
- bookmarkStart: translator$3,
29282
- bookmarkEnd: translator$2,
29283
- fieldAnnotation: translator,
29284
- tab: translator$U,
29285
- image: translator$1,
29286
- hardBreak: translator$V,
30578
+ bookmarkStart: translator$1,
30579
+ bookmarkEnd: translator,
30580
+ fieldAnnotation: translator$2,
30581
+ tab: translator$13,
30582
+ image: translator$3,
30583
+ hardBreak: translator$15,
29287
30584
  commentRangeStart: () => translateCommentNode(params, "Start"),
29288
30585
  commentRangeEnd: () => translateCommentNode(params, "End"),
29289
30586
  commentReference: () => null,
29290
30587
  shapeContainer: translateShapeContainer,
29291
30588
  shapeTextbox: translateShapeTextbox,
29292
30589
  contentBlock: translateContentBlock,
29293
- structuredContent: translator,
29294
- structuredContentBlock: translator,
29295
- documentSection: translator,
30590
+ structuredContent: translator$2,
30591
+ structuredContentBlock: translator$2,
30592
+ documentSection: translator$2,
29296
30593
  "page-number": translatePageNumberNode,
29297
30594
  "total-page-number": translateTotalPageNumberNode
29298
30595
  };
@@ -29431,21 +30728,32 @@ function generateParagraphProperties(node) {
29431
30728
  };
29432
30729
  pPrElements.push(spacingElement);
29433
30730
  }
29434
- if (indent && Object.values(indent).some((v2) => v2 !== 0)) {
29435
- const { left, right, firstLine, hanging } = indent;
30731
+ const hasIndent = !!indent;
30732
+ if (hasIndent) {
30733
+ const { left, right, firstLine, hanging, explicitLeft, explicitRight, explicitFirstLine, explicitHanging } = indent;
29436
30734
  const attributes = {};
29437
- if (left || left === 0) attributes["w:left"] = pixelsToTwips(left);
29438
- if (right || right === 0) attributes["w:right"] = pixelsToTwips(right);
29439
- if (firstLine || firstLine === 0) attributes["w:firstLine"] = pixelsToTwips(firstLine);
29440
- if (hanging || hanging === 0) attributes["w:hanging"] = pixelsToTwips(hanging);
29441
- if (textIndent && !attributes["w:left"]) {
30735
+ if (left !== void 0 && (left !== 0 || explicitLeft || textIndent)) {
30736
+ attributes["w:left"] = pixelsToTwips(left);
30737
+ }
30738
+ if (right !== void 0 && (right !== 0 || explicitRight)) {
30739
+ attributes["w:right"] = pixelsToTwips(right);
30740
+ }
30741
+ if (firstLine !== void 0 && (firstLine !== 0 || explicitFirstLine)) {
30742
+ attributes["w:firstLine"] = pixelsToTwips(firstLine);
30743
+ }
30744
+ if (hanging !== void 0 && (hanging !== 0 || explicitHanging)) {
30745
+ attributes["w:hanging"] = pixelsToTwips(hanging);
30746
+ }
30747
+ if (textIndent && attributes["w:left"] === void 0) {
29442
30748
  attributes["w:left"] = getTextIndentExportValue(textIndent);
29443
30749
  }
29444
- const indentElement = {
29445
- name: "w:ind",
29446
- attributes
29447
- };
29448
- pPrElements.push(indentElement);
30750
+ if (Object.keys(attributes).length) {
30751
+ const indentElement = {
30752
+ name: "w:ind",
30753
+ attributes
30754
+ };
30755
+ pPrElements.push(indentElement);
30756
+ }
29449
30757
  } else if (textIndent && textIndent !== "0in") {
29450
30758
  const indentElement = {
29451
30759
  name: "w:ind",
@@ -29495,12 +30803,17 @@ function generateParagraphProperties(node) {
29495
30803
  if (sectPr) {
29496
30804
  pPrElements.push(sectPr);
29497
30805
  }
30806
+ const mapTabVal = (value) => {
30807
+ if (!value || value === "start") return "left";
30808
+ if (value === "end") return "right";
30809
+ return value;
30810
+ };
29498
30811
  const { tabStops } = attrs;
29499
30812
  if (tabStops && tabStops.length > 0) {
29500
30813
  const tabElements = tabStops.map((tab) => {
29501
30814
  const posValue = tab.originalPos !== void 0 ? tab.originalPos : pixelsToTwips(tab.pos).toString();
29502
30815
  const tabAttributes = {
29503
- "w:val": tab.val || "start",
30816
+ "w:val": mapTabVal(tab.val),
29504
30817
  "w:pos": posValue
29505
30818
  };
29506
30819
  if (tab.leader) {
@@ -29855,6 +31168,11 @@ const convertMultipleListItemsIntoSingleNode = (listItem) => {
29855
31168
  collapsedParagraph.content.push(item);
29856
31169
  }
29857
31170
  });
31171
+ collapsedParagraph.content = collapsedParagraph.content.filter((node, index, nodes) => {
31172
+ if (!isLineBreakOnlyRun(node)) return true;
31173
+ const prevNode = nodes[index - 1];
31174
+ return !(prevNode && isLineBreakOnlyRun(prevNode));
31175
+ });
29858
31176
  return collapsedParagraph;
29859
31177
  };
29860
31178
  const restoreIndent = (indent) => {
@@ -29908,13 +31226,27 @@ function translateMark(mark) {
29908
31226
  markElement.type = "element";
29909
31227
  break;
29910
31228
  case "italic":
29911
- delete markElement.attributes;
29912
- markElement.type = "element";
29913
- break;
29914
- case "underline":
31229
+ if (attrs?.value && attrs.value !== "1" && attrs.value !== true) {
31230
+ markElement.attributes["w:val"] = attrs.value;
31231
+ } else {
31232
+ delete markElement.attributes;
31233
+ }
29915
31234
  markElement.type = "element";
29916
- markElement.attributes["w:val"] = attrs.underlineType;
29917
31235
  break;
31236
+ case "underline": {
31237
+ const translated = translator$$.decode({
31238
+ node: {
31239
+ attrs: {
31240
+ underlineType: attrs.underlineType ?? attrs.underline ?? null,
31241
+ underlineColor: attrs.underlineColor ?? attrs.color ?? null,
31242
+ underlineThemeColor: attrs.underlineThemeColor ?? attrs.themeColor ?? null,
31243
+ underlineThemeTint: attrs.underlineThemeTint ?? attrs.themeTint ?? null,
31244
+ underlineThemeShade: attrs.underlineThemeShade ?? attrs.themeShade ?? null
31245
+ }
31246
+ }
31247
+ });
31248
+ return translated || {};
31249
+ }
29918
31250
  // Text style cases
29919
31251
  case "fontSize":
29920
31252
  value = attrs.fontSize;
@@ -29932,13 +31264,21 @@ function translateMark(mark) {
29932
31264
  markElement.name = "w:rStyle";
29933
31265
  markElement.attributes["w:val"] = attrs.styleId;
29934
31266
  break;
29935
- case "color":
29936
- let processedColor = attrs.color.replace(/^#/, "").replace(/;$/, "");
31267
+ case "color": {
31268
+ const rawColor = attrs.color;
31269
+ if (!rawColor) break;
31270
+ const normalized = String(rawColor).trim().toLowerCase();
31271
+ if (normalized === "inherit") {
31272
+ markElement.attributes["w:val"] = "auto";
31273
+ break;
31274
+ }
31275
+ let processedColor = String(rawColor).replace(/^#/, "").replace(/;$/, "");
29937
31276
  if (processedColor.startsWith("rgb")) {
29938
31277
  processedColor = rgbToHex(processedColor);
29939
31278
  }
29940
31279
  markElement.attributes["w:val"] = processedColor;
29941
31280
  break;
31281
+ }
29942
31282
  case "textAlign":
29943
31283
  markElement.attributes["w:val"] = attrs.textAlign;
29944
31284
  break;
@@ -29956,12 +31296,11 @@ function translateMark(mark) {
29956
31296
  case "lineHeight":
29957
31297
  markElement.attributes["w:line"] = linesToTwips(attrs.lineHeight);
29958
31298
  break;
29959
- case "highlight":
29960
- markElement.attributes["w:fill"] = attrs.color?.substring(1);
29961
- markElement.attributes["w:color"] = "auto";
29962
- markElement.attributes["w:val"] = "clear";
29963
- markElement.name = "w:shd";
29964
- break;
31299
+ case "highlight": {
31300
+ const highlightValue = attrs.color ?? attrs.highlight ?? null;
31301
+ const translated = translator$14.decode({ node: { attrs: { highlight: highlightValue } } });
31302
+ return translated || {};
31303
+ }
29965
31304
  }
29966
31305
  return markElement;
29967
31306
  }
@@ -30092,8 +31431,8 @@ generate_xml_as_list_fn = function(data, debug = false) {
30092
31431
  return final;
30093
31432
  };
30094
31433
  replaceSpecialCharacters_fn = function(text) {
30095
- if (!text) return;
30096
- return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
31434
+ if (text === void 0 || text === null) return text;
31435
+ return String(text).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
30097
31436
  };
30098
31437
  generateXml_fn = function(node) {
30099
31438
  if (!node) return null;
@@ -30109,7 +31448,7 @@ generateXml_fn = function(node) {
30109
31448
  else tag += ">";
30110
31449
  let tags = [tag];
30111
31450
  if (!name && node.type === "text") {
30112
- return node.text;
31451
+ return __privateMethod(this, _DocxExporter_instances, replaceSpecialCharacters_fn).call(this, node.text ?? "");
30113
31452
  }
30114
31453
  if (elements) {
30115
31454
  if (name === "w:instrText") {
@@ -30235,7 +31574,7 @@ const handleDrawingNode = (params) => {
30235
31574
  if (mainNode.name === "w:drawing") node = mainNode;
30236
31575
  else node = mainNode.elements.find((el) => el.name === "w:drawing");
30237
31576
  if (!node) return { nodes: [], consumed: 0 };
30238
- const schemaNode = translator$1.encode(params);
31577
+ const schemaNode = translator$3.encode(params);
30239
31578
  const newNodes = schemaNode ? [schemaNode] : [];
30240
31579
  return { nodes: newNodes, consumed: 1 };
30241
31580
  };
@@ -30338,81 +31677,7 @@ const trackChangeNodeHandlerEntity = {
30338
31677
  handler: handleTrackChangeNode
30339
31678
  };
30340
31679
  const hyperlinkNodeHandlerEntity = generateV2HandlerEntity("hyperlinkNodeHandler", translator$6);
30341
- const handleRunNode = (params) => {
30342
- const { nodes, nodeListHandler, parentStyleId, docx } = params;
30343
- if (nodes.length === 0 || nodes[0].name !== "w:r") {
30344
- return { nodes: [], consumed: 0 };
30345
- }
30346
- const node = nodes[0];
30347
- const childParams = { ...params, nodes: node.elements, path: [...params.path || [], node] };
30348
- let processedRun = nodeListHandler.handler(childParams)?.filter((n) => n) || [];
30349
- const hasRunProperties = node.elements?.some((el) => el.name === "w:rPr");
30350
- const defaultNodeStyles = getMarksFromStyles(docx, parentStyleId);
30351
- if (hasRunProperties) {
30352
- const { marks = [] } = parseProperties(node);
30353
- let runStyleAttributes = [];
30354
- const runStyleElement = node.elements?.find((el) => el.name === "w:rPr")?.elements?.find((el) => el.name === "w:rStyle");
30355
- let runStyleId;
30356
- if (runStyleElement && runStyleElement.attributes?.["w:val"] && docx) {
30357
- runStyleId = runStyleElement.attributes["w:val"];
30358
- const runStyleDefinition = getMarksFromStyles(docx, runStyleId);
30359
- if (runStyleDefinition.marks && runStyleDefinition.marks.length > 0) {
30360
- runStyleAttributes = runStyleDefinition.marks;
30361
- }
30362
- }
30363
- let paragraphStyleAttributes = [];
30364
- if (defaultNodeStyles.marks) {
30365
- paragraphStyleAttributes = defaultNodeStyles.marks.filter((mark) => {
30366
- if (["bold"].includes(mark.type) && marks.find((m2) => m2.type === "bold")?.attrs?.value === "0") {
30367
- return false;
30368
- }
30369
- return true;
30370
- });
30371
- }
30372
- const combinedMarks = [...paragraphStyleAttributes];
30373
- runStyleAttributes.forEach((runStyle) => {
30374
- const exists = combinedMarks.some(
30375
- (mark) => mark.type === runStyle.type && JSON.stringify(mark.attrs || {}) === JSON.stringify(runStyle.attrs || {})
30376
- );
30377
- if (!exists) {
30378
- combinedMarks.push(runStyle);
30379
- }
30380
- });
30381
- marks.forEach((mark) => {
30382
- const exists = combinedMarks.some(
30383
- (existing) => existing.type === mark.type && JSON.stringify(existing.attrs || {}) === JSON.stringify(mark.attrs || {})
30384
- );
30385
- if (!exists) {
30386
- combinedMarks.push(mark);
30387
- }
30388
- });
30389
- if (runStyleId) combinedMarks.push({ type: "textStyle", attrs: { styleId: runStyleId } });
30390
- if (node.marks) combinedMarks.push(...node.marks);
30391
- const newMarks = createImportMarks(combinedMarks);
30392
- processedRun = processedRun.map((n) => {
30393
- const existingMarks = n.marks || [];
30394
- return {
30395
- ...n,
30396
- marks: [...newMarks, ...existingMarks]
30397
- };
30398
- });
30399
- }
30400
- return { nodes: processedRun, consumed: 1 };
30401
- };
30402
- const getMarksFromStyles = (docx, styleId) => {
30403
- const styles = docx?.["word/styles.xml"];
30404
- if (!styles) {
30405
- return {};
30406
- }
30407
- const styleTags = styles.elements[0].elements.filter((style2) => style2.name === "w:style");
30408
- const style = styleTags.find((tag) => tag.attributes["w:styleId"] === styleId) || {};
30409
- if (!style) return {};
30410
- return parseProperties(style);
30411
- };
30412
- const runNodeHandlerEntity = {
30413
- handlerName: "runNodeHandler",
30414
- handler: handleRunNode
30415
- };
31680
+ const runNodeHandlerEntity = generateV2HandlerEntity("runNodeHandler", translator$T);
30416
31681
  const handleTextNode = (params) => {
30417
31682
  const { nodes, insideTrackChange } = params;
30418
31683
  if (nodes.length === 0 || !(nodes[0].name === "w:t" || insideTrackChange && nodes[0].name === "w:delText")) {
@@ -30424,6 +31689,10 @@ const handleTextNode = (params) => {
30424
31689
  let text;
30425
31690
  if (elements.length === 1) {
30426
31691
  text = elements[0].text;
31692
+ const xmlSpace = node.attributes?.["xml:space"] ?? elements[0]?.attributes?.["xml:space"];
31693
+ if (xmlSpace !== "preserve" && typeof text === "string") {
31694
+ text = text.replace(/^\s+/, "").replace(/\s+$/, "");
31695
+ }
30427
31696
  text = text.replace(/\[\[sdspace\]\]/g, "");
30428
31697
  } else if (!elements.length && "attributes" in node && node.attributes["xml:space"] === "preserve") {
30429
31698
  text = " ";
@@ -30449,7 +31718,7 @@ const handleParagraphNode = (params) => {
30449
31718
  if (nodes.length === 0 || nodes[0].name !== "w:p") {
30450
31719
  return { nodes: [], consumed: 0 };
30451
31720
  }
30452
- const schemaNode = translator$T.encode(params);
31721
+ const schemaNode = translator$12.encode(params);
30453
31722
  const newNodes = schemaNode ? [schemaNode] : [];
30454
31723
  return { nodes: newNodes, consumed: 1 };
30455
31724
  };
@@ -30462,7 +31731,7 @@ const handleSdtNode = (params) => {
30462
31731
  if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
30463
31732
  return { nodes: [], consumed: 0 };
30464
31733
  }
30465
- const result = translator.encode(params);
31734
+ const result = translator$2.encode(params);
30466
31735
  if (!result) {
30467
31736
  return { nodes: [], consumed: 0 };
30468
31737
  }
@@ -30552,7 +31821,7 @@ const handler = (params) => {
30552
31821
  if (nodes.length === 0 || nodes[0].name !== "w:br") {
30553
31822
  return { nodes: [], consumed: 0 };
30554
31823
  }
30555
- const result = translator$V.encode(params);
31824
+ const result = translator$15.encode(params);
30556
31825
  if (!result) return { nodes: [], consumed: 0 };
30557
31826
  return {
30558
31827
  nodes: [result],
@@ -30624,7 +31893,7 @@ const handleBookmarkStartNode = (params) => {
30624
31893
  if (isCustomMarkBookmark(nodes[0], params.editor)) {
30625
31894
  return handleBookmarkNode(params);
30626
31895
  }
30627
- const node = translator$3.encode(params);
31896
+ const node = translator$1.encode(params);
30628
31897
  if (!node) return { nodes: [], consumed: 0 };
30629
31898
  return { nodes: [node], consumed: 1 };
30630
31899
  };
@@ -30656,7 +31925,7 @@ const handleBookmarkEndNode = (params) => {
30656
31925
  if (!nodes.length || nodes[0].name !== "w:bookmarkEnd") {
30657
31926
  return { nodes: [], consumed: 0 };
30658
31927
  }
30659
- const node = translator$2.encode(params);
31928
+ const node = translator.encode(params);
30660
31929
  if (!node) return { nodes: [], consumed: 0 };
30661
31930
  return { nodes: [node], consumed: 1 };
30662
31931
  };
@@ -31295,7 +32564,7 @@ const handleTabNode = (params) => {
31295
32564
  if (!nodes.length || nodes[0].name !== "w:tab") {
31296
32565
  return { nodes: [], consumed: 0 };
31297
32566
  }
31298
- const node = translator$U.encode(params);
32567
+ const node = translator$13.encode(params);
31299
32568
  return { nodes: [node], consumed: 1 };
31300
32569
  };
31301
32570
  const tabNodeEntityHandler = {
@@ -31744,6 +33013,16 @@ const isAlternatingHeadersOddEven = (docx) => {
31744
33013
  };
31745
33014
  const HYPERLINK_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
31746
33015
  const HEADER_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header";
33016
+ const FONT_FAMILY_FALLBACKS = Object.freeze({
33017
+ swiss: "Arial, sans-serif",
33018
+ roman: "Times New Roman, serif",
33019
+ modern: "Courier New, monospace",
33020
+ script: "cursive",
33021
+ decorative: "fantasy",
33022
+ system: "system-ui",
33023
+ auto: "sans-serif"
33024
+ });
33025
+ const DEFAULT_GENERIC_FALLBACK = "sans-serif";
31747
33026
  const _SuperConverter = class _SuperConverter {
31748
33027
  constructor(params = null) {
31749
33028
  __privateAdd(this, _SuperConverter_instances);
@@ -31779,6 +33058,31 @@ const _SuperConverter = class _SuperConverter {
31779
33058
  this.documentId = params?.documentId || null;
31780
33059
  if (this.docx.length || this.xml) this.parseFromXml();
31781
33060
  }
33061
+ static getFontTableEntry(docx, fontName) {
33062
+ if (!docx || !fontName) return null;
33063
+ const fontTable = docx["word/fontTable.xml"];
33064
+ if (!fontTable?.elements?.length) return null;
33065
+ const fontsNode = fontTable.elements.find((el) => el.name === "w:fonts");
33066
+ if (!fontsNode?.elements?.length) return null;
33067
+ return fontsNode.elements.find((el) => el?.attributes?.["w:name"] === fontName) || null;
33068
+ }
33069
+ static getFallbackFromFontTable(docx, fontName) {
33070
+ const fontEntry = _SuperConverter.getFontTableEntry(docx, fontName);
33071
+ const family = fontEntry?.elements?.find((child) => child.name === "w:family")?.attributes?.["w:val"];
33072
+ if (!family) return null;
33073
+ const mapped = FONT_FAMILY_FALLBACKS[family.toLowerCase()];
33074
+ return mapped || DEFAULT_GENERIC_FALLBACK;
33075
+ }
33076
+ static toCssFontFamily(fontName, docx) {
33077
+ if (!fontName) return fontName;
33078
+ if (fontName.includes(",")) return fontName;
33079
+ const fallback = _SuperConverter.getFallbackFromFontTable(docx, fontName) || DEFAULT_GENERIC_FALLBACK;
33080
+ const normalizedFallbackParts = fallback.split(",").map((part) => part.trim().toLowerCase()).filter(Boolean);
33081
+ if (normalizedFallbackParts.includes(fontName.trim().toLowerCase())) {
33082
+ return fallback;
33083
+ }
33084
+ return `${fontName}, ${fallback}`;
33085
+ }
31782
33086
  /**
31783
33087
  * Get the DocxHelpers object that contains utility functions for working with docx files.
31784
33088
  * @returns {import('./docx-helpers/docx-helpers.js').DocxHelpers} The DocxHelpers object.
@@ -31875,13 +33179,19 @@ const _SuperConverter = class _SuperConverter {
31875
33179
  if (rPrDefaults) {
31876
33180
  const rPr = rPrDefaults.elements?.find((el) => el.name === "w:rPr");
31877
33181
  const fonts = rPr?.elements?.find((el) => el.name === "w:rFonts");
31878
- typeface = fonts?.attributes["w:ascii"];
31879
- const fontSize = typeface ?? rPr?.elements?.find((el) => el.name === "w:sz")?.attributes["w:val"];
31880
- fontSizeNormal = !fontSizeNormal && fontSize ? Number(fontSize) / 2 : null;
33182
+ if (fonts?.attributes?.["w:ascii"]) {
33183
+ typeface = fonts.attributes["w:ascii"];
33184
+ }
33185
+ const fontSizeRaw = rPr?.elements?.find((el) => el.name === "w:sz")?.attributes?.["w:val"];
33186
+ if (!fontSizeNormal && fontSizeRaw) {
33187
+ fontSizeNormal = Number(fontSizeRaw) / 2;
33188
+ }
31881
33189
  }
31882
- const fontSizePt = fontSizeNormal || Number(rElements.find((el) => el.name === "w:sz")?.attributes["w:val"]) / 2 || 10;
33190
+ const fallbackSz = Number(rElements.find((el) => el.name === "w:sz")?.attributes?.["w:val"]);
33191
+ const fontSizePt = fontSizeNormal ?? (Number.isFinite(fallbackSz) ? fallbackSz / 2 : void 0) ?? 10;
31883
33192
  const kern = rElements.find((el) => el.name === "w:kern")?.attributes["w:val"];
31884
- return { fontSizePt, kern, typeface, panose };
33193
+ const fontFamilyCss = _SuperConverter.toCssFontFamily(typeface, this.convertedXml);
33194
+ return { fontSizePt, kern, typeface, panose, fontFamilyCss };
31885
33195
  }
31886
33196
  }
31887
33197
  getDocumentFonts() {
@@ -32367,6 +33677,7 @@ export {
32367
33677
  objectIncludes as Z,
32368
33678
  AddMarkStep as _,
32369
33679
  Plugin as a,
33680
+ translator$R as a$,
32370
33681
  twipsToLines as a0,
32371
33682
  pixelsToTwips as a1,
32372
33683
  helpers as a2,
@@ -32377,12 +33688,33 @@ export {
32377
33688
  createDocFromMarkdown as a7,
32378
33689
  createDocFromHTML as a8,
32379
33690
  EditorState as a9,
32380
- getActiveFormatting as aA,
32381
- readFromClipboard as aB,
32382
- handleClipboardPaste as aC,
32383
- getFileObject as aD,
32384
- _sfc_main as aE,
32385
- registeredHandlers as aF,
33691
+ readFromClipboard as aA,
33692
+ handleClipboardPaste as aB,
33693
+ getFileObject as aC,
33694
+ runPropertyTranslators as aD,
33695
+ translator as aE,
33696
+ translator$1 as aF,
33697
+ translator$4 as aG,
33698
+ translator$5 as aH,
33699
+ translator$H as aI,
33700
+ translator$I as aJ,
33701
+ translator$G as aK,
33702
+ translator$J as aL,
33703
+ translator$F as aM,
33704
+ translator$7 as aN,
33705
+ translator$K as aO,
33706
+ translator$L as aP,
33707
+ translator$13 as aQ,
33708
+ translator$2 as aR,
33709
+ translator$U as aS,
33710
+ translator$T as aT,
33711
+ translator$12 as aU,
33712
+ translator$M as aV,
33713
+ translator$6 as aW,
33714
+ translator$N as aX,
33715
+ translator$O as aY,
33716
+ translator$P as aZ,
33717
+ translator$Q as a_,
32386
33718
  hasSomeParentWithClass as aa,
32387
33719
  isActive as ab,
32388
33720
  unflattenListsInHtml as ac,
@@ -32396,20 +33728,23 @@ export {
32396
33728
  docxNumberigHelpers as ak,
32397
33729
  parseIndentElement as al,
32398
33730
  combineIndents as am,
32399
- StepMap as an,
32400
- SelectionRange as ao,
32401
- Transform as ap,
32402
- isInTable as aq,
32403
- generateDocxRandomId as ar,
32404
- insertNewRelationship as as,
32405
- updateDOMAttributes as at,
32406
- htmlHandler as au,
32407
- commonjsGlobal as av,
32408
- getDefaultExportFromCjs$1 as aw,
32409
- getContentTypesFromXml as ax,
32410
- xmljs as ay,
32411
- vClickOutside as az,
33731
+ SelectionRange as an,
33732
+ Transform as ao,
33733
+ isInTable as ap,
33734
+ generateDocxRandomId as aq,
33735
+ insertNewRelationship as ar,
33736
+ updateDOMAttributes as as,
33737
+ htmlHandler as at,
33738
+ commonjsGlobal as au,
33739
+ getDefaultExportFromCjs$1 as av,
33740
+ getContentTypesFromXml as aw,
33741
+ xmljs as ax,
33742
+ vClickOutside as ay,
33743
+ getActiveFormatting as az,
32412
33744
  Slice as b,
33745
+ translator$S as b0,
33746
+ translator$15 as b1,
33747
+ _sfc_main as b2,
32413
33748
  DOMParser$1 as c,
32414
33749
  Mark as d,
32415
33750
  dropPoint as e,