@harbour-enterprises/superdoc 0.27.3-next.1 → 0.28.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/chunks/{PdfViewer-Bnj3c-92.es.js → PdfViewer-9z5hlRyt.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer-BkJGiP2u.cjs → PdfViewer-Jb55JUCS.cjs} +1 -1
  3. package/dist/chunks/{index-CuLDIhMe.cjs → index-D0UvyM8m.cjs} +10 -4
  4. package/dist/chunks/{index-lF5qA9nw.es.js → index-DqP-8_tO.es.js} +10 -4
  5. package/dist/chunks/{super-editor.es-6ikSS3Qu.es.js → super-editor.es-BBJIKdhr.es.js} +1690 -1674
  6. package/dist/chunks/{super-editor.es-RvLsj0rg.cjs → super-editor.es-Ca5D3ZTW.cjs} +1690 -1674
  7. package/dist/chunks/uuid-CjlX8hrF.es.js +35 -0
  8. package/dist/chunks/uuid-R7L08bOx.cjs +34 -0
  9. package/dist/components/CommentsLayer/use-comment.d.ts.map +1 -1
  10. package/dist/core/types/index.d.ts.map +1 -1
  11. package/dist/stores/comments-store.d.ts.map +1 -1
  12. package/dist/super-editor/ai-writer.es.js +2 -2
  13. package/dist/super-editor/chunks/{converter-GcMLdei-.js → converter-AR-76siZ.js} +1344 -1416
  14. package/dist/super-editor/chunks/{docx-zipper-Y0x9TJvc.js → docx-zipper-DVb-VGgt.js} +1 -1
  15. package/dist/super-editor/chunks/{editor-B97ToSSc.js → editor-mK_uimq6.js} +93 -5
  16. package/dist/super-editor/chunks/{toolbar-Cm21JZgi.js → toolbar-ByoNwr7x.js} +2 -2
  17. package/dist/super-editor/converter.es.js +1 -1
  18. package/dist/super-editor/docx-zipper.es.js +2 -2
  19. package/dist/super-editor/editor.es.js +3 -3
  20. package/dist/super-editor/file-zipper.es.js +1 -1
  21. package/dist/super-editor/super-editor/src/components/toolbar/use-toolbar-item.d.ts +1 -1
  22. package/dist/super-editor/super-editor/src/core/commands/getSelectionMarks.d.ts +1 -0
  23. package/dist/super-editor/super-editor/src/core/commands/index.d.ts +2 -0
  24. package/dist/super-editor/super-editor/src/core/commands/setTextSelection.d.ts +4 -0
  25. package/dist/super-editor/super-editor/src/core/super-converter/v2/importer/tableImporter.d.ts +0 -16
  26. package/dist/super-editor/super-editor/src/core/super-converter/v3/handlers/w/tc/helpers/legacy-handle-table-cell-node.d.ts +1 -1
  27. package/dist/super-editor/super-editor/src/extensions/comment/comments-plugin.d.ts +2 -1
  28. package/dist/super-editor/super-editor/src/tests/helpers/helpers.d.ts +1 -1
  29. package/dist/super-editor/super-editor.es.js +6 -6
  30. package/dist/super-editor/toolbar.es.js +2 -2
  31. package/dist/super-editor.cjs +1 -1
  32. package/dist/super-editor.es.js +1 -1
  33. package/dist/superdoc.cjs +2 -2
  34. package/dist/superdoc.es.js +2 -2
  35. package/dist/superdoc.umd.js +1722 -1702
  36. package/dist/superdoc.umd.js.map +1 -1
  37. package/package.json +5 -8
  38. package/dist/chunks/uuid-CQzaMNgL.cjs +0 -36
  39. package/dist/chunks/uuid-DIIKH5Zc.es.js +0 -37
  40. package/dist/images/altText_add.svg +0 -3
  41. package/dist/images/altText_done.svg +0 -3
  42. package/dist/images/annotation-check.svg +0 -11
  43. package/dist/images/annotation-comment.svg +0 -16
  44. package/dist/images/annotation-help.svg +0 -26
  45. package/dist/images/annotation-insert.svg +0 -10
  46. package/dist/images/annotation-key.svg +0 -11
  47. package/dist/images/annotation-newparagraph.svg +0 -11
  48. package/dist/images/annotation-noicon.svg +0 -7
  49. package/dist/images/annotation-note.svg +0 -42
  50. package/dist/images/annotation-paperclip.svg +0 -6
  51. package/dist/images/annotation-paragraph.svg +0 -16
  52. package/dist/images/annotation-pushpin.svg +0 -7
  53. package/dist/images/cursor-editorFreeHighlight.svg +0 -6
  54. package/dist/images/cursor-editorFreeText.svg +0 -3
  55. package/dist/images/cursor-editorInk.svg +0 -4
  56. package/dist/images/cursor-editorTextHighlight.svg +0 -8
  57. package/dist/images/editor-toolbar-delete.svg +0 -5
  58. package/dist/images/loading-icon.gif +0 -0
  59. package/dist/images/toolbarButton-editorHighlight.svg +0 -6
  60. package/dist/images/toolbarButton-menuArrow.svg +0 -3
@@ -11330,39 +11330,37 @@ function requireLib() {
11330
11330
  }
11331
11331
  var libExports = requireLib();
11332
11332
  const xmljs = /* @__PURE__ */ getDefaultExportFromCjs$2(libExports);
11333
- var getRandomValues;
11334
- var rnds8 = new Uint8Array(16);
11333
+ let getRandomValues;
11334
+ const rnds8 = new Uint8Array(16);
11335
11335
  function rng() {
11336
11336
  if (!getRandomValues) {
11337
- getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== "undefined" && typeof msCrypto.getRandomValues === "function" && msCrypto.getRandomValues.bind(msCrypto);
11337
+ getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
11338
11338
  if (!getRandomValues) {
11339
11339
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
11340
11340
  }
11341
11341
  }
11342
11342
  return getRandomValues(rnds8);
11343
11343
  }
11344
- const REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
11345
- function validate(uuid) {
11346
- return typeof uuid === "string" && REGEX.test(uuid);
11344
+ const byteToHex = [];
11345
+ for (let i = 0; i < 256; ++i) {
11346
+ byteToHex.push((i + 256).toString(16).slice(1));
11347
11347
  }
11348
- var byteToHex = [];
11349
- for (var i$2 = 0; i$2 < 256; ++i$2) {
11350
- byteToHex.push((i$2 + 256).toString(16).substr(1));
11351
- }
11352
- function stringify(arr) {
11353
- var offset2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
11354
- var uuid = (byteToHex[arr[offset2 + 0]] + byteToHex[arr[offset2 + 1]] + byteToHex[arr[offset2 + 2]] + byteToHex[arr[offset2 + 3]] + "-" + byteToHex[arr[offset2 + 4]] + byteToHex[arr[offset2 + 5]] + "-" + byteToHex[arr[offset2 + 6]] + byteToHex[arr[offset2 + 7]] + "-" + byteToHex[arr[offset2 + 8]] + byteToHex[arr[offset2 + 9]] + "-" + byteToHex[arr[offset2 + 10]] + byteToHex[arr[offset2 + 11]] + byteToHex[arr[offset2 + 12]] + byteToHex[arr[offset2 + 13]] + byteToHex[arr[offset2 + 14]] + byteToHex[arr[offset2 + 15]]).toLowerCase();
11355
- if (!validate(uuid)) {
11356
- throw TypeError("Stringified UUID is invalid");
11357
- }
11358
- return uuid;
11348
+ function unsafeStringify(arr, offset2 = 0) {
11349
+ return byteToHex[arr[offset2 + 0]] + byteToHex[arr[offset2 + 1]] + byteToHex[arr[offset2 + 2]] + byteToHex[arr[offset2 + 3]] + "-" + byteToHex[arr[offset2 + 4]] + byteToHex[arr[offset2 + 5]] + "-" + byteToHex[arr[offset2 + 6]] + byteToHex[arr[offset2 + 7]] + "-" + byteToHex[arr[offset2 + 8]] + byteToHex[arr[offset2 + 9]] + "-" + byteToHex[arr[offset2 + 10]] + byteToHex[arr[offset2 + 11]] + byteToHex[arr[offset2 + 12]] + byteToHex[arr[offset2 + 13]] + byteToHex[arr[offset2 + 14]] + byteToHex[arr[offset2 + 15]];
11359
11350
  }
11351
+ const randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
11352
+ const native = {
11353
+ randomUUID
11354
+ };
11360
11355
  function v4(options, buf, offset2) {
11356
+ if (native.randomUUID && true && !options) {
11357
+ return native.randomUUID();
11358
+ }
11361
11359
  options = options || {};
11362
- var rnds = options.random || (options.rng || rng)();
11360
+ const rnds = options.random || (options.rng || rng)();
11363
11361
  rnds[6] = rnds[6] & 15 | 64;
11364
11362
  rnds[8] = rnds[8] & 63 | 128;
11365
- return stringify(rnds);
11363
+ return unsafeStringify(rnds);
11366
11364
  }
11367
11365
  function getDefaultExportFromCjs(x) {
11368
11366
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
@@ -14415,6 +14413,7 @@ class ParseContext {
14415
14413
  addTextNode(dom, marks) {
14416
14414
  let value = dom.nodeValue;
14417
14415
  let top2 = this.top, preserveWS = top2.options & OPT_PRESERVE_WS_FULL ? "full" : this.localPreserveWS || (top2.options & OPT_PRESERVE_WS) > 0;
14416
+ let { schema } = this.parser;
14418
14417
  if (preserveWS === "full" || top2.inlineContext(dom) || /[^ \t\r\n\u000c]/.test(value)) {
14419
14418
  if (!preserveWS) {
14420
14419
  value = value.replace(/[ \t\r\n\u000c]+/g, " ");
@@ -14424,13 +14423,22 @@ class ParseContext {
14424
14423
  if (!nodeBefore || domNodeBefore && domNodeBefore.nodeName == "BR" || nodeBefore.isText && /[ \t\r\n\u000c]$/.test(nodeBefore.text))
14425
14424
  value = value.slice(1);
14426
14425
  }
14427
- } else if (preserveWS !== "full") {
14428
- value = value.replace(/\r?\n|\r/g, " ");
14429
- } else {
14426
+ } else if (preserveWS === "full") {
14430
14427
  value = value.replace(/\r\n?/g, "\n");
14428
+ } else if (schema.linebreakReplacement && /[\r\n]/.test(value) && this.top.findWrapping(schema.linebreakReplacement.create())) {
14429
+ let lines = value.split(/\r?\n|\r/);
14430
+ for (let i = 0; i < lines.length; i++) {
14431
+ if (i)
14432
+ this.insertNode(schema.linebreakReplacement.create(), marks, true);
14433
+ if (lines[i])
14434
+ this.insertNode(schema.text(lines[i]), marks, !/\S/.test(lines[i]));
14435
+ }
14436
+ value = "";
14437
+ } else {
14438
+ value = value.replace(/\r?\n|\r/g, " ");
14431
14439
  }
14432
14440
  if (value)
14433
- this.insertNode(this.parser.schema.text(value), marks, !/\S/.test(value));
14441
+ this.insertNode(schema.text(value), marks, !/\S/.test(value));
14434
14442
  this.findInText(dom);
14435
14443
  } else {
14436
14444
  this.findInside(dom);
@@ -18990,7 +18998,6 @@ class Transaction extends Transform {
18990
18998
  } else {
18991
18999
  if (to == null)
18992
19000
  to = from2;
18993
- to = to == null ? from2 : to;
18994
19001
  if (!text)
18995
19002
  return this.deleteRange(from2, to);
18996
19003
  let marks = this.storedMarks;
@@ -18999,7 +19006,7 @@ class Transaction extends Transform {
18999
19006
  marks = to == from2 ? $from.marks() : $from.marksAcross(this.doc.resolve(to));
19000
19007
  }
19001
19008
  this.replaceRangeWith(from2, to, schema.text(text, marks));
19002
- if (!this.selection.empty)
19009
+ if (!this.selection.empty && this.selection.to == from2 + text.length)
19003
19010
  this.setSelection(Selection.near(this.selection.$to));
19004
19011
  return this;
19005
19012
  }
@@ -19191,7 +19198,7 @@ class EditorState {
19191
19198
  return newInstance;
19192
19199
  }
19193
19200
  /**
19194
- Start a [transaction](https://prosemirror.net/docs/ref/#state.Transaction) from this state.
19201
+ Accessor that constructs and returns a new [transaction](https://prosemirror.net/docs/ref/#state.Transaction) from this state.
19195
19202
  */
19196
19203
  get tr() {
19197
19204
  return new Transaction(this);
@@ -26990,53 +26997,7 @@ const config$h = {
26990
26997
  attributes: validXmlAttributes$c
26991
26998
  };
26992
26999
  const translator$1b = NodeTranslator.from(config$h);
26993
- function preProcessVerticalMergeCells(table, { editorSchema }) {
26994
- if (!table || !Array.isArray(table.content)) {
26995
- return table;
26996
- }
26997
- const rows = table.content;
26998
- for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
26999
- const row = rows[rowIndex];
27000
- if (!row) continue;
27001
- if (!Array.isArray(row.content)) {
27002
- row.content = [];
27003
- }
27004
- for (let cellIndex = 0; cellIndex < row.content.length; cellIndex++) {
27005
- const cell = row.content[cellIndex];
27006
- if (!cell) continue;
27007
- const attrs = cell.attrs || {};
27008
- if (!attrs.rowspan || attrs.rowspan <= 1) continue;
27009
- const maxRowspan = Math.min(attrs.rowspan, rows.length - rowIndex);
27010
- for (let offset2 = 1; offset2 < maxRowspan; offset2++) {
27011
- const rowToChange = rows[rowIndex + offset2];
27012
- if (!rowToChange) continue;
27013
- if (!Array.isArray(rowToChange.content)) {
27014
- rowToChange.content = [];
27015
- }
27016
- const existingCell = rowToChange.content[cellIndex];
27017
- if (existingCell?.attrs?.continueMerge) continue;
27018
- const mergedCell = {
27019
- type: cell.type,
27020
- content: [editorSchema.nodes.paragraph.createAndFill().toJSON()],
27021
- attrs: {
27022
- ...cell.attrs,
27023
- rowspan: null,
27024
- continueMerge: true
27025
- }
27026
- };
27027
- rowToChange.content.splice(cellIndex, 0, mergedCell);
27028
- }
27029
- }
27030
- }
27031
- return table;
27032
- }
27033
27000
  const translator$1a = NodeTranslator.from({
27034
- xmlName: "w:cantSplit",
27035
- sdNodeOrKeyName: "cantSplit",
27036
- encode: ({ nodes }) => ["1", "true"].includes(nodes[0].attributes?.["w:val"] ?? "1"),
27037
- decode: ({ node }) => node.attrs?.cantSplit ? { attributes: {} } : void 0
27038
- });
27039
- const translator$19 = NodeTranslator.from({
27040
27001
  xmlName: "w:cnfStyle",
27041
27002
  sdNodeOrKeyName: "cnfStyle",
27042
27003
  attributes: [
@@ -27062,299 +27023,7 @@ const translator$19 = NodeTranslator.from({
27062
27023
  return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
27063
27024
  }
27064
27025
  });
27065
- const translator$18 = NodeTranslator.from(createSingleAttrPropertyHandler("w:divId"));
27066
- const translator$17 = NodeTranslator.from(
27067
- createSingleAttrPropertyHandler(
27068
- "w:gridAfter",
27069
- null,
27070
- "w:val",
27071
- (v2) => parseInteger(v2) ?? void 0,
27072
- (v2) => integerToString(v2)
27073
- )
27074
- );
27075
- const translator$16 = NodeTranslator.from(
27076
- createSingleAttrPropertyHandler(
27077
- "w:gridBefore",
27078
- null,
27079
- "w:val",
27080
- (v2) => parseInteger(v2) ?? void 0,
27081
- (v2) => integerToString(v2)
27082
- )
27083
- );
27084
- const translator$15 = NodeTranslator.from({
27085
- xmlName: "w:hidden",
27086
- sdNodeOrKeyName: "hidden",
27087
- encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
27088
- decode: ({ node }) => node.attrs.hidden ? { attributes: {} } : void 0
27089
- });
27090
- const translator$14 = NodeTranslator.from(createSingleAttrPropertyHandler("w:jc", "justification"));
27091
- const translator$13 = NodeTranslator.from(createMeasurementPropertyHandler("w:tblCellSpacing", "tableCellSpacing"));
27092
- const translator$12 = NodeTranslator.from({
27093
- xmlName: "w:tblHeader",
27094
- sdNodeOrKeyName: "repeatHeader",
27095
- encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
27096
- decode: ({ node }) => node.attrs.repeatHeader ? { attributes: {} } : void 0
27097
- });
27098
- const translator$11 = NodeTranslator.from({
27099
- xmlName: "w:trHeight",
27100
- sdNodeOrKeyName: "rowHeight",
27101
- encode: ({ nodes }) => {
27102
- const heightAttrs = {};
27103
- const val = nodes[0].attributes["w:val"];
27104
- if (val) {
27105
- heightAttrs["value"] = parseInt(val, 10);
27106
- }
27107
- const rule = nodes[0].attributes["w:hRule"];
27108
- if (rule) {
27109
- heightAttrs["rule"] = rule;
27110
- }
27111
- return Object.keys(heightAttrs).length > 0 ? heightAttrs : void 0;
27112
- },
27113
- decode: ({ node }) => {
27114
- if (!node.attrs?.rowHeight) return;
27115
- const heightAttrs = {};
27116
- if (typeof node.attrs.rowHeight.value === "number" && !isNaN(node.attrs.rowHeight.value)) {
27117
- heightAttrs["w:val"] = String(node.attrs.rowHeight.value);
27118
- }
27119
- if (node.attrs.rowHeight.rule) {
27120
- heightAttrs["w:hRule"] = node.attrs.rowHeight.rule;
27121
- }
27122
- return Object.keys(heightAttrs).length > 0 ? { attributes: heightAttrs } : void 0;
27123
- }
27124
- });
27125
- const translator$10 = NodeTranslator.from(createMeasurementPropertyHandler("w:wAfter"));
27126
- const translator$$ = NodeTranslator.from(createMeasurementPropertyHandler("w:wBefore"));
27127
- const propertyTranslators$6 = [
27128
- translator$1a,
27129
- translator$19,
27130
- translator$18,
27131
- translator$17,
27132
- translator$16,
27133
- translator$15,
27134
- translator$14,
27135
- translator$13,
27136
- translator$12,
27137
- translator$11,
27138
- translator$10,
27139
- translator$$
27140
- ];
27141
- const translator$_ = NodeTranslator.from(
27142
- createNestedPropertiesTranslator("w:trPr", "tableRowProperties", propertyTranslators$6, {
27143
- cantSplit: false,
27144
- hidden: false,
27145
- repeatHeader: false
27146
- })
27147
- );
27148
- const createPlaceholderCell = (gridWidth, reason) => {
27149
- const safeWidth = Number.isFinite(gridWidth) ? gridWidth : 0;
27150
- const noBorder = { val: "none", size: 0 };
27151
- return {
27152
- type: "tableCell",
27153
- attrs: {
27154
- colspan: 1,
27155
- rowspan: 1,
27156
- colwidth: [safeWidth],
27157
- __placeholder: reason,
27158
- borders: {
27159
- top: { ...noBorder },
27160
- right: { ...noBorder },
27161
- bottom: { ...noBorder },
27162
- left: { ...noBorder }
27163
- }
27164
- },
27165
- content: [{ type: "paragraph", content: [] }]
27166
- };
27167
- };
27168
- const advancePastRowSpans = (pendingRowSpans, startIndex, totalColumns) => {
27169
- let index2 = startIndex;
27170
- while (index2 < totalColumns && pendingRowSpans[index2] > 0) {
27171
- pendingRowSpans[index2] -= 1;
27172
- index2 += 1;
27173
- }
27174
- return index2;
27175
- };
27176
- const fillPlaceholderColumns = ({
27177
- content,
27178
- pendingRowSpans,
27179
- currentIndex,
27180
- targetIndex,
27181
- totalColumns,
27182
- gridColumnWidths,
27183
- reason
27184
- }) => {
27185
- let index2 = currentIndex;
27186
- while (index2 < targetIndex && index2 < totalColumns) {
27187
- if (pendingRowSpans[index2] > 0) {
27188
- pendingRowSpans[index2] -= 1;
27189
- index2 += 1;
27190
- continue;
27191
- }
27192
- const width = Array.isArray(gridColumnWidths) ? gridColumnWidths[index2] ?? 0 : 0;
27193
- content.push(createPlaceholderCell(width, reason));
27194
- index2 += 1;
27195
- }
27196
- return index2;
27197
- };
27198
- const isPlaceholderCell = (cell) => {
27199
- if (!cell) return false;
27200
- if (cell.attrs?.__placeholder) return true;
27201
- const widths = cell.attrs?.colwidth;
27202
- if (Array.isArray(widths) && widths.length > 0) {
27203
- const hasMeaningfulWidth = widths.some(
27204
- (value) => typeof value === "number" && Number.isFinite(value) && Math.abs(value) > 1
27205
- );
27206
- if (!hasMeaningfulWidth) return true;
27207
- }
27208
- return false;
27209
- };
27210
- const XML_NODE_NAME$h = "w:tr";
27211
- const SD_NODE_NAME$d = "tableRow";
27212
- const validXmlAttributes$b = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
27213
- (xmlName) => createAttributeHandler(xmlName)
27214
- );
27215
- const encode$n = (params2, encodedAttrs) => {
27216
- const { row } = params2.extraParams;
27217
- let tableRowProperties = {};
27218
- const tPr = row.elements.find((el) => el.name === "w:trPr");
27219
- if (tPr) {
27220
- tableRowProperties = translator$_.encode({
27221
- ...params2,
27222
- nodes: [tPr]
27223
- });
27224
- }
27225
- const gridBeforeRaw = tableRowProperties?.["gridBefore"];
27226
- const safeGridBefore = typeof gridBeforeRaw === "number" && Number.isFinite(gridBeforeRaw) && gridBeforeRaw > 0 ? gridBeforeRaw : 0;
27227
- encodedAttrs["tableRowProperties"] = Object.freeze(tableRowProperties);
27228
- encodedAttrs["rowHeight"] = twipsToPixels(tableRowProperties["rowHeight"]?.value);
27229
- encodedAttrs["cantSplit"] = tableRowProperties["cantSplit"];
27230
- const { columnWidths: gridColumnWidths, activeRowSpans = [] } = params2.extraParams;
27231
- const totalColumns = Array.isArray(gridColumnWidths) ? gridColumnWidths.length : 0;
27232
- const pendingRowSpans = Array.isArray(activeRowSpans) ? activeRowSpans.slice() : [];
27233
- while (pendingRowSpans.length < totalColumns) pendingRowSpans.push(0);
27234
- const cellNodes = row.elements.filter((el) => el.name === "w:tc");
27235
- const content = [];
27236
- let currentColumnIndex = 0;
27237
- const fillUntil = (target, reason) => {
27238
- currentColumnIndex = fillPlaceholderColumns({
27239
- content,
27240
- pendingRowSpans,
27241
- currentIndex: currentColumnIndex,
27242
- targetIndex: target,
27243
- totalColumns,
27244
- gridColumnWidths,
27245
- reason
27246
- });
27247
- };
27248
- const skipOccupiedColumns = () => {
27249
- currentColumnIndex = advancePastRowSpans(pendingRowSpans, currentColumnIndex, totalColumns);
27250
- };
27251
- fillUntil(safeGridBefore, "gridBefore");
27252
- skipOccupiedColumns();
27253
- cellNodes?.forEach((node) => {
27254
- skipOccupiedColumns();
27255
- const startColumn = currentColumnIndex;
27256
- const columnWidth = gridColumnWidths?.[startColumn] || null;
27257
- const result = translator$c.encode({
27258
- ...params2,
27259
- extraParams: {
27260
- ...params2.extraParams,
27261
- node,
27262
- columnIndex: startColumn,
27263
- columnWidth
27264
- }
27265
- });
27266
- if (result) {
27267
- content.push(result);
27268
- const colspan = Math.max(1, result.attrs?.colspan || 1);
27269
- const rowspan = Math.max(1, result.attrs?.rowspan || 1);
27270
- if (rowspan > 1) {
27271
- for (let offset2 = 0; offset2 < colspan; offset2 += 1) {
27272
- const target = startColumn + offset2;
27273
- if (target < pendingRowSpans.length) {
27274
- pendingRowSpans[target] = Math.max(pendingRowSpans[target], rowspan - 1);
27275
- }
27276
- }
27277
- }
27278
- currentColumnIndex = startColumn + colspan;
27279
- }
27280
- });
27281
- skipOccupiedColumns();
27282
- fillUntil(totalColumns, "gridAfter");
27283
- const newNode = {
27284
- type: "tableRow",
27285
- content,
27286
- attrs: encodedAttrs
27287
- };
27288
- return newNode;
27289
- };
27290
- const decode$p = (params2, decodedAttrs) => {
27291
- const { node } = params2;
27292
- const cells = node.content || [];
27293
- let leadingPlaceholders = 0;
27294
- while (leadingPlaceholders < cells.length && isPlaceholderCell(cells[leadingPlaceholders])) {
27295
- leadingPlaceholders += 1;
27296
- }
27297
- let trailingPlaceholders = 0;
27298
- while (trailingPlaceholders < cells.length - leadingPlaceholders && isPlaceholderCell(cells[cells.length - 1 - trailingPlaceholders])) {
27299
- trailingPlaceholders += 1;
27300
- }
27301
- const trimmedSlice = cells.slice(leadingPlaceholders, cells.length - trailingPlaceholders);
27302
- const sanitizedCells = trimmedSlice.map((cell) => {
27303
- if (cell?.attrs && "__placeholder" in cell.attrs) {
27304
- const { __placeholder, ...rest } = cell.attrs;
27305
- return { ...cell, attrs: rest };
27306
- }
27307
- return cell;
27308
- });
27309
- const trimmedContent = sanitizedCells.filter((_2, index2) => !isPlaceholderCell(trimmedSlice[index2]));
27310
- const translateParams = {
27311
- ...params2,
27312
- node: { ...node, content: trimmedContent }
27313
- };
27314
- const elements = translateChildNodes(translateParams);
27315
- if (node.attrs?.tableRowProperties) {
27316
- const tableRowProperties = { ...node.attrs.tableRowProperties };
27317
- if (leadingPlaceholders > 0) {
27318
- tableRowProperties.gridBefore = leadingPlaceholders;
27319
- }
27320
- if (trailingPlaceholders > 0) {
27321
- tableRowProperties.gridAfter = trailingPlaceholders;
27322
- }
27323
- if (node.attrs.rowHeight != null) {
27324
- const rowHeightPixels = twipsToPixels(node.attrs.tableRowProperties["rowHeight"]?.value);
27325
- if (rowHeightPixels !== node.attrs.rowHeight) {
27326
- tableRowProperties["rowHeight"] = { value: String(pixelsToTwips(node.attrs["rowHeight"])) };
27327
- }
27328
- }
27329
- tableRowProperties["cantSplit"] = node.attrs["cantSplit"];
27330
- const trPr = translator$_.decode({
27331
- ...params2,
27332
- node: { ...node, attrs: { ...node.attrs, tableRowProperties } }
27333
- });
27334
- if (trPr) elements.unshift(trPr);
27335
- }
27336
- return {
27337
- name: "w:tr",
27338
- attributes: decodedAttrs || {},
27339
- elements
27340
- };
27341
- };
27342
- const config$g = {
27343
- xmlName: XML_NODE_NAME$h,
27344
- sdNodeOrKeyName: SD_NODE_NAME$d,
27345
- type: NodeTranslator.translatorTypes.NODE,
27346
- encode: encode$n,
27347
- decode: decode$p,
27348
- attributes: validXmlAttributes$b
27349
- };
27350
- const translator$Z = NodeTranslator.from(config$g);
27351
- const translator$Y = NodeTranslator.from({
27352
- xmlName: "w:bidiVisual",
27353
- sdNodeOrKeyName: "rightToLeft",
27354
- encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
27355
- decode: ({ node }) => node.attrs.rightToLeft ? { attributes: {} } : void 0
27356
- });
27357
- const translator$X = NodeTranslator.from({
27026
+ const translator$19 = NodeTranslator.from({
27358
27027
  xmlName: "w:shd",
27359
27028
  sdNodeOrKeyName: "shading",
27360
27029
  attributes: [
@@ -27376,895 +27045,284 @@ const translator$X = NodeTranslator.from({
27376
27045
  return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
27377
27046
  }
27378
27047
  });
27379
- const translator$W = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblCaption", "caption"));
27380
- const translator$V = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblDescription", "description"));
27381
- const translator$U = NodeTranslator.from(createMeasurementPropertyHandler("w:tblInd", "tableIndent"));
27382
- const translator$T = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblLayout", "tableLayout", "w:type"));
27383
- const translator$S = NodeTranslator.from({
27384
- xmlName: "w:tblLook",
27385
- sdNodeOrKeyName: "tblLook",
27386
- attributes: ["w:firstColumn", "w:firstRow", "w:lastColumn", "w:lastRow", "w:noHBand", "w:noVBand"].map((attr) => createAttributeHandler(attr, null, parseBoolean, booleanToString)).concat([createAttributeHandler("w:val")]),
27387
- encode: (params2, encodedAttrs) => {
27388
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
27389
- },
27390
- decode: function({ node }, context) {
27391
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.tblLook || {} } });
27392
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
27393
- }
27394
- });
27395
- const translator$R = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblOverlap", "overlap"));
27396
- const translator$Q = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblStyle", "tableStyleId"));
27397
- const translator$P = NodeTranslator.from(
27398
- createSingleAttrPropertyHandler("w:tblStyleColBandSize", "tableStyleColBandSize")
27399
- );
27400
- const translator$O = NodeTranslator.from(
27401
- createSingleAttrPropertyHandler("w:tblStyleRowBandSize", "tableStyleRowBandSize")
27048
+ const translator$18 = NodeTranslator.from(createMeasurementPropertyHandler("w:tcW", "cellWidth"));
27049
+ const translator$17 = NodeTranslator.from(
27050
+ createSingleAttrPropertyHandler(
27051
+ "w:gridSpan",
27052
+ null,
27053
+ "w:val",
27054
+ (v2) => parseInteger(v2) ?? void 0,
27055
+ (v2) => integerToString(v2)
27056
+ )
27402
27057
  );
27403
- const translator$N = NodeTranslator.from(createMeasurementPropertyHandler("w:tblW", "tableWidth"));
27404
- const translator$M = NodeTranslator.from({
27405
- xmlName: "w:tblpPr",
27406
- sdNodeOrKeyName: "floatingTableProperties",
27407
- attributes: ["w:leftFromText", "w:rightFromText", "w:topFromText", "w:bottomFromText", "w:tblpX", "w:tblpY"].map((attr) => createAttributeHandler(attr, null, parseInteger, integerToString)).concat(["w:horzAnchor", "w:vertAnchor", "w:tblpXSpec", "w:tblpYSpec"].map((attr) => createAttributeHandler(attr))),
27408
- encode: (params2, encodedAttrs) => {
27409
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
27410
- },
27411
- decode: function({ node }, context) {
27412
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.floatingTableProperties || {} } });
27413
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
27414
- }
27415
- });
27416
- const translator$L = NodeTranslator.from(createBorderPropertyHandler("w:bottom"));
27417
- const translator$K = NodeTranslator.from(createMeasurementPropertyHandler("w:bottom", "marginBottom"));
27418
- const translator$J = NodeTranslator.from(createBorderPropertyHandler("w:end"));
27419
- const translator$I = NodeTranslator.from(createMeasurementPropertyHandler("w:end", "marginEnd"));
27420
- const translator$H = NodeTranslator.from(createBorderPropertyHandler("w:insideH"));
27421
- const translator$G = NodeTranslator.from(createBorderPropertyHandler("w:insideV"));
27422
- const translator$F = NodeTranslator.from(createBorderPropertyHandler("w:left"));
27423
- const translator$E = NodeTranslator.from(createMeasurementPropertyHandler("w:left", "marginLeft"));
27424
- const translator$D = NodeTranslator.from(createBorderPropertyHandler("w:right"));
27425
- const translator$C = NodeTranslator.from(createMeasurementPropertyHandler("w:right", "marginRight"));
27426
- const translator$B = NodeTranslator.from(createBorderPropertyHandler("w:start"));
27427
- const translator$A = NodeTranslator.from(createMeasurementPropertyHandler("w:start", "marginStart"));
27428
- const translator$z = NodeTranslator.from(createBorderPropertyHandler("w:top"));
27429
- const translator$y = NodeTranslator.from(createMeasurementPropertyHandler("w:top", "marginTop"));
27430
- const propertyTranslators$5 = [
27431
- translator$L,
27432
- translator$J,
27433
- translator$H,
27434
- translator$G,
27435
- translator$F,
27436
- translator$D,
27437
- translator$B,
27438
- translator$z
27058
+ const translator$16 = NodeTranslator.from(createSingleAttrPropertyHandler("w:vMerge"));
27059
+ const translator$15 = NodeTranslator.from(createBorderPropertyHandler("w:bottom"));
27060
+ const translator$14 = NodeTranslator.from(createMeasurementPropertyHandler("w:bottom", "marginBottom"));
27061
+ const translator$13 = NodeTranslator.from(createBorderPropertyHandler("w:end"));
27062
+ const translator$12 = NodeTranslator.from(createMeasurementPropertyHandler("w:end", "marginEnd"));
27063
+ const translator$11 = NodeTranslator.from(createBorderPropertyHandler("w:insideH"));
27064
+ const translator$10 = NodeTranslator.from(createBorderPropertyHandler("w:insideV"));
27065
+ const translator$$ = NodeTranslator.from(createBorderPropertyHandler("w:left"));
27066
+ const translator$_ = NodeTranslator.from(createMeasurementPropertyHandler("w:left", "marginLeft"));
27067
+ const translator$Z = NodeTranslator.from(createBorderPropertyHandler("w:right"));
27068
+ const translator$Y = NodeTranslator.from(createMeasurementPropertyHandler("w:right", "marginRight"));
27069
+ const translator$X = NodeTranslator.from(createBorderPropertyHandler("w:start"));
27070
+ const translator$W = NodeTranslator.from(createMeasurementPropertyHandler("w:start", "marginStart"));
27071
+ const translator$V = NodeTranslator.from(createBorderPropertyHandler("w:top"));
27072
+ const translator$U = NodeTranslator.from(createMeasurementPropertyHandler("w:top", "marginTop"));
27073
+ const translator$T = NodeTranslator.from(createBorderPropertyHandler("w:tl2br"));
27074
+ const translator$S = NodeTranslator.from(createBorderPropertyHandler("w:tr2bl"));
27075
+ const propertyTranslators$6 = [
27076
+ translator$V,
27077
+ translator$X,
27078
+ translator$$,
27079
+ translator$15,
27080
+ translator$13,
27081
+ translator$Z,
27082
+ translator$11,
27083
+ translator$10,
27084
+ translator$T,
27085
+ translator$S
27439
27086
  ];
27440
- const translator$x = NodeTranslator.from(
27441
- createNestedPropertiesTranslator("w:tblBorders", "borders", propertyTranslators$5)
27087
+ const translator$R = NodeTranslator.from(
27088
+ createNestedPropertiesTranslator("w:tcBorders", "borders", propertyTranslators$6)
27442
27089
  );
27443
- const propertyTranslators$4 = [
27444
- translator$K,
27445
- translator$I,
27446
- translator$E,
27447
- translator$C,
27448
- translator$A,
27449
- translator$y
27450
- ];
27451
- const translator$w = NodeTranslator.from(
27452
- createNestedPropertiesTranslator("w:tblCellMar", "cellMargins", propertyTranslators$4)
27090
+ const translator$Q = NodeTranslator.from(
27091
+ createSingleAttrPropertyHandler(
27092
+ "w:noWrap",
27093
+ null,
27094
+ "w:val",
27095
+ (v2) => parseBoolean(v2 ?? "true"),
27096
+ (v2) => booleanToString(v2)
27097
+ )
27453
27098
  );
27454
- const propertyTranslators$3 = [
27455
- translator$Y,
27099
+ const propertyTranslators$5 = [
27456
27100
  translator$14,
27457
- translator$X,
27101
+ translator$12,
27102
+ translator$_,
27103
+ translator$Y,
27458
27104
  translator$W,
27459
- translator$13,
27460
- translator$V,
27461
- translator$U,
27462
- translator$T,
27463
- translator$S,
27464
- translator$R,
27465
- translator$Q,
27466
- translator$P,
27467
- translator$O,
27468
- translator$N,
27469
- translator$M,
27470
- translator$x,
27471
- translator$w
27105
+ translator$U
27472
27106
  ];
27473
- const translator$v = NodeTranslator.from(
27474
- createNestedPropertiesTranslator("w:tblPr", "tableProperties", propertyTranslators$3)
27107
+ const translator$P = NodeTranslator.from(
27108
+ createNestedPropertiesTranslator("w:tcMar", "cellMargins", propertyTranslators$5)
27475
27109
  );
27476
- const translator$u = NodeTranslator.from(
27477
- createSingleAttrPropertyHandler("w:gridCol", "col", "w:w", parseInteger, integerToString)
27110
+ const translator$O = NodeTranslator.from(createSingleAttrPropertyHandler("w:textDirection"));
27111
+ const translator$N = NodeTranslator.from(
27112
+ createSingleAttrPropertyHandler(
27113
+ "w:tcFitText",
27114
+ null,
27115
+ "w:val",
27116
+ (v2) => parseBoolean(v2 ?? "true"),
27117
+ (v2) => booleanToString(v2)
27118
+ )
27478
27119
  );
27479
- const DEFAULT_COLUMN_WIDTH_PX = 100;
27480
- const normalizeTwipWidth = (value) => {
27481
- if (value == null) return null;
27482
- const numericValue = typeof value === "string" ? parseInt(value, 10) : value;
27483
- if (!Number.isFinite(numericValue) || Number.isNaN(numericValue) || numericValue <= 0) {
27484
- return null;
27485
- }
27486
- return numericValue;
27487
- };
27488
- const getSchemaDefaultColumnWidthPx = (params2) => {
27489
- const defaultValue = params2?.editor?.schema?.nodes?.tableCell?.spec?.attrs?.colwidth?.default;
27490
- if (Array.isArray(defaultValue)) {
27491
- const numericWidth = defaultValue.find((width) => typeof width === "number" && Number.isFinite(width) && width > 0);
27492
- if (numericWidth != null) return numericWidth;
27493
- } else if (typeof defaultValue === "number" && Number.isFinite(defaultValue) && defaultValue > 0) {
27494
- return defaultValue;
27495
- }
27496
- return DEFAULT_COLUMN_WIDTH_PX;
27497
- };
27498
- const getTableWidthPx = (params2) => {
27499
- const explicitWidth = params2?.node?.attrs?.tableWidth?.width;
27500
- if (typeof explicitWidth === "number" && explicitWidth > 0) return explicitWidth;
27501
- const tableWidth = params2?.node?.attrs?.tableProperties?.tableWidth;
27502
- if (tableWidth?.value != null && typeof tableWidth.value === "number" && tableWidth.value > 0) {
27503
- const { value, type: type2 } = tableWidth;
27504
- if (!type2 || type2 === "auto" || type2 === "dxa") {
27505
- return twipsToPixels(value);
27506
- }
27507
- }
27508
- return null;
27509
- };
27510
- const resolveFallbackColumnWidthTwips = (params2, totalColumns, cellMinWidthTwips) => {
27511
- const columnCount = Math.max(totalColumns, 1);
27512
- const defaultColumnWidthPx = getSchemaDefaultColumnWidthPx(params2);
27513
- const tableWidthPx = getTableWidthPx(params2);
27514
- const safeDefaultPx = Number.isFinite(defaultColumnWidthPx) && defaultColumnWidthPx > 0 ? defaultColumnWidthPx : DEFAULT_COLUMN_WIDTH_PX;
27515
- let fallbackWidthPx = safeDefaultPx;
27516
- if (typeof tableWidthPx === "number" && tableWidthPx > 0) {
27517
- fallbackWidthPx = tableWidthPx / columnCount;
27518
- }
27519
- const fallbackWidthTwips = pixelsToTwips(fallbackWidthPx);
27520
- if (!Number.isFinite(fallbackWidthTwips) || Number.isNaN(fallbackWidthTwips) || fallbackWidthTwips <= 0) {
27521
- const safeDefault = Math.max(pixelsToTwips(safeDefaultPx), cellMinWidthTwips);
27522
- return safeDefault;
27523
- }
27524
- return Math.max(fallbackWidthTwips, cellMinWidthTwips);
27525
- };
27526
- const XML_NODE_NAME$g = "w:tblGrid";
27527
- const SD_ATTR_KEY$3 = "grid";
27528
- const cellMinWidth = pixelsToTwips(10);
27529
- const encode$m = (params2) => {
27120
+ const translator$M = NodeTranslator.from(createSingleAttrPropertyHandler("w:vAlign"));
27121
+ const translator$L = NodeTranslator.from(
27122
+ createSingleAttrPropertyHandler(
27123
+ "w:hideMark",
27124
+ null,
27125
+ "w:val",
27126
+ (v2) => parseBoolean(v2 ?? "true"),
27127
+ (v2) => booleanToString(v2)
27128
+ )
27129
+ );
27130
+ const translator$K = NodeTranslator.from(createSingleAttrPropertyHandler("w:header"));
27131
+ const XML_NODE_NAME$h = "w:headers";
27132
+ const SD_ATTR_KEY$3 = "headers";
27133
+ const encode$n = (params2) => {
27530
27134
  const { nodes } = params2;
27531
27135
  const node = nodes[0];
27532
- const attributes = encodeProperties(node, { [translator$u.xmlName]: translator$u }, true);
27136
+ const attributes = encodeProperties(node, { [translator$K.xmlName]: translator$K }, true);
27533
27137
  return {
27534
- xmlName: XML_NODE_NAME$g,
27138
+ xmlName: XML_NODE_NAME$h,
27535
27139
  sdNodeOrKeyName: SD_ATTR_KEY$3,
27536
27140
  attributes
27537
27141
  };
27538
27142
  };
27539
- const decode$o = (params2) => {
27540
- const { grid: rawGrid } = params2.node.attrs || {};
27541
- const grid = Array.isArray(rawGrid) ? rawGrid : [];
27542
- const { firstRow = {} } = params2.extraParams || {};
27543
- const cellNodes = firstRow.content?.filter((n) => n.type === "tableCell") ?? [];
27544
- const columnCountFromCells = cellNodes.reduce((count, cell) => {
27545
- const spanCount = Math.max(1, cell?.attrs?.colspan ?? 1);
27546
- return count + spanCount;
27547
- }, 0);
27548
- const totalColumns = Math.max(columnCountFromCells, grid.length);
27549
- const fallbackColumnWidthTwips = resolveFallbackColumnWidthTwips(params2, totalColumns, cellMinWidth);
27550
- const elements = [];
27551
- let columnIndex = 0;
27552
- const pushColumn = (widthTwips, { enforceMinimum = false } = {}) => {
27553
- let numericWidth = typeof widthTwips === "string" ? parseInt(widthTwips, 10) : widthTwips;
27554
- let shouldEnforceMinimum = enforceMinimum;
27555
- if (numericWidth == null || Number.isNaN(numericWidth) || numericWidth <= 0) {
27556
- numericWidth = fallbackColumnWidthTwips;
27557
- shouldEnforceMinimum = true;
27558
- }
27559
- const roundedWidth = Math.round(numericWidth);
27560
- const minimumWidth = shouldEnforceMinimum ? cellMinWidth : 1;
27561
- const safeWidth = Math.max(roundedWidth, minimumWidth);
27562
- const decoded = translator$u.decode({
27563
- node: { type: (
27564
- /** @type {string} */
27565
- translator$u.sdNodeOrKeyName
27566
- ), attrs: { col: safeWidth } }
27567
- });
27568
- if (decoded) elements.push(decoded);
27569
- };
27570
- cellNodes.forEach((cell) => {
27571
- const { colspan = 1, colwidth } = cell?.attrs || {};
27572
- const spanCount = Math.max(1, colspan);
27573
- for (let span = 0; span < spanCount; span++) {
27574
- const rawWidth = Array.isArray(colwidth) ? colwidth[span] : void 0;
27575
- const cellWidthPixels = typeof rawWidth === "number" && Number.isFinite(rawWidth) ? rawWidth : Number(rawWidth);
27576
- const hasCellWidth = Number.isFinite(cellWidthPixels) && cellWidthPixels > 0;
27577
- const colGridAttrs = grid?.[columnIndex] || {};
27578
- const gridWidthTwips = normalizeTwipWidth(colGridAttrs.col);
27579
- const gridWidthPixels = gridWidthTwips != null ? twipsToPixels(gridWidthTwips) : null;
27580
- let cellWidthTwips;
27581
- let enforceMinimum = false;
27582
- if (hasCellWidth) {
27583
- const tolerance = 0.5;
27584
- if (gridWidthTwips != null && gridWidthPixels != null && Math.abs(gridWidthPixels - cellWidthPixels) <= tolerance) {
27585
- cellWidthTwips = gridWidthTwips;
27586
- } else {
27587
- cellWidthTwips = pixelsToTwips(cellWidthPixels);
27588
- }
27589
- } else if (gridWidthTwips != null) {
27590
- cellWidthTwips = gridWidthTwips;
27591
- } else {
27592
- cellWidthTwips = fallbackColumnWidthTwips;
27593
- enforceMinimum = true;
27594
- }
27595
- pushColumn(cellWidthTwips, { enforceMinimum });
27596
- columnIndex++;
27597
- }
27598
- });
27599
- while (columnIndex < grid.length) {
27600
- const gridWidthTwips = normalizeTwipWidth(grid[columnIndex]?.col);
27601
- pushColumn(gridWidthTwips);
27602
- columnIndex++;
27603
- }
27143
+ const decode$p = (params2) => {
27144
+ const { headers = [] } = params2.node.attrs || {};
27604
27145
  const newNode = {
27605
- name: XML_NODE_NAME$g,
27146
+ name: XML_NODE_NAME$h,
27606
27147
  attributes: {},
27607
- elements
27148
+ elements: headers.map(
27149
+ (header) => translator$K.decode({
27150
+ node: { type: "header", attrs: header }
27151
+ })
27152
+ )
27608
27153
  };
27609
27154
  return newNode;
27610
27155
  };
27611
- const config$f = {
27612
- xmlName: XML_NODE_NAME$g,
27156
+ const config$g = {
27157
+ xmlName: XML_NODE_NAME$h,
27613
27158
  sdNodeOrKeyName: SD_ATTR_KEY$3,
27614
- encode: encode$m,
27615
- decode: decode$o
27616
- };
27617
- const translator$t = NodeTranslator.from(config$f);
27618
- const DEFAULT_PAGE_WIDTH_TWIPS = 12240;
27619
- const DEFAULT_PAGE_MARGIN_TWIPS = 1440;
27620
- const DEFAULT_CONTENT_WIDTH_TWIPS = DEFAULT_PAGE_WIDTH_TWIPS - 2 * DEFAULT_PAGE_MARGIN_TWIPS;
27621
- const MIN_COLUMN_WIDTH_TWIPS = pixelsToTwips(10);
27622
- const pctToPercent = (value) => {
27623
- if (value == null) return null;
27624
- return value / 50;
27159
+ encode: encode$n,
27160
+ decode: decode$p
27625
27161
  };
27626
- const resolveContentWidthTwips = () => DEFAULT_CONTENT_WIDTH_TWIPS;
27627
- const resolveMeasurementWidthPx = (measurement) => {
27628
- if (!measurement || typeof measurement.value !== "number" || measurement.value <= 0) return null;
27629
- const { value, type: type2 } = measurement;
27630
- if (!type2 || type2 === "auto") return null;
27631
- if (type2 === "dxa") return twipsToPixels(value);
27632
- if (type2 === "pct") {
27633
- const percent2 = pctToPercent(value);
27634
- if (percent2 == null || percent2 <= 0) return null;
27635
- const widthTwips = resolveContentWidthTwips() * percent2 / 100;
27636
- return twipsToPixels(widthTwips);
27162
+ const translator$J = NodeTranslator.from(config$g);
27163
+ const propertyTranslators$4 = [
27164
+ translator$1a,
27165
+ translator$18,
27166
+ translator$17,
27167
+ translator$16,
27168
+ translator$R,
27169
+ translator$19,
27170
+ translator$Q,
27171
+ translator$P,
27172
+ translator$O,
27173
+ translator$N,
27174
+ translator$M,
27175
+ translator$L,
27176
+ translator$J
27177
+ ];
27178
+ const translator$I = NodeTranslator.from(
27179
+ createNestedPropertiesTranslator("w:tcPr", "tableCellProperties", propertyTranslators$4)
27180
+ );
27181
+ function handleTableCellNode({
27182
+ params: params2,
27183
+ node,
27184
+ table,
27185
+ row,
27186
+ rowBorders,
27187
+ columnIndex,
27188
+ columnWidth = null,
27189
+ allColumnWidths = [],
27190
+ _referencedStyles
27191
+ }) {
27192
+ const { nodeListHandler } = params2;
27193
+ const attributes = {};
27194
+ const referencedStyles = _referencedStyles ?? { fontSize: null, fonts: {}, cellMargins: {} };
27195
+ const tcPr = node.elements.find((el) => el.name === "w:tcPr");
27196
+ const tableCellProperties = tcPr ? translator$I.encode({ ...params2, nodes: [tcPr] }) ?? {} : {};
27197
+ attributes["tableCellProperties"] = tableCellProperties;
27198
+ if (rowBorders?.insideH) {
27199
+ rowBorders["bottom"] = rowBorders.insideH;
27200
+ delete rowBorders.insideH;
27637
27201
  }
27638
- return null;
27639
- };
27640
- const countColumnsInRow = (row) => {
27641
- if (!row?.elements?.length) return 0;
27642
- return row.elements.reduce((count, element) => {
27643
- if (element.name !== "w:tc") return count;
27644
- const tcPr = element.elements?.find((el) => el.name === "w:tcPr");
27645
- const gridSpan = tcPr?.elements?.find((el) => el.name === "w:gridSpan");
27646
- const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
27647
- return count + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
27648
- }, 0);
27649
- };
27650
- const clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS);
27651
- const createFallbackGrid = (columnCount, columnWidthTwips) => Array.from({ length: columnCount }, () => ({ col: clampColumnWidthTwips(columnWidthTwips) }));
27652
- const buildFallbackGridForTable = ({ params: params2, rows, tableWidth, tableWidthMeasurement }) => {
27653
- const firstRow = rows.find((row) => row.elements?.some((el) => el.name === "w:tc"));
27654
- const columnCount = countColumnsInRow(firstRow);
27655
- if (!columnCount) return null;
27656
- const schemaDefaultPx = getSchemaDefaultColumnWidthPx(
27657
- /** @type {any} */
27658
- params2
27659
- );
27660
- const minimumColumnWidthPx = Number.isFinite(schemaDefaultPx) && schemaDefaultPx > 0 ? schemaDefaultPx : DEFAULT_COLUMN_WIDTH_PX;
27661
- let totalWidthPx;
27662
- if (tableWidthMeasurement) {
27663
- const resolved = resolveMeasurementWidthPx(tableWidthMeasurement);
27664
- if (resolved != null) totalWidthPx = resolved;
27202
+ if (rowBorders?.insideV) {
27203
+ rowBorders["right"] = rowBorders.insideV;
27204
+ delete rowBorders?.insideV;
27665
27205
  }
27666
- if (totalWidthPx == null && tableWidth?.width && tableWidth.width > 0) {
27667
- totalWidthPx = tableWidth.width;
27206
+ if (rowBorders) attributes["borders"] = { ...rowBorders };
27207
+ const inlineBorders = processInlineCellBorders(tableCellProperties.borders, rowBorders);
27208
+ if (inlineBorders) attributes["borders"] = Object.assign(attributes["borders"] || {}, inlineBorders);
27209
+ const colspan = tableCellProperties.gridSpan;
27210
+ if (colspan && !isNaN(parseInt(colspan, 10))) attributes["colspan"] = parseInt(colspan, 10);
27211
+ let width = tableCellProperties.cellWidth?.value ? twipsToPixels(tableCellProperties.cellWidth?.value) : null;
27212
+ const widthType = tableCellProperties.cellWidth?.type;
27213
+ if (widthType) attributes["widthType"] = widthType;
27214
+ if (!width && columnWidth) width = columnWidth;
27215
+ if (width) {
27216
+ attributes["colwidth"] = [width];
27217
+ attributes["widthUnit"] = "px";
27218
+ const defaultColWidths = allColumnWidths;
27219
+ const hasDefaultColWidths = allColumnWidths && allColumnWidths.length > 0;
27220
+ const colspanNum = parseInt(colspan || 1, 10);
27221
+ if (colspanNum && colspanNum > 1 && hasDefaultColWidths) {
27222
+ let colwidth = [];
27223
+ for (let i = 0; i < colspanNum; i++) {
27224
+ let colwidthValue = defaultColWidths[columnIndex + i];
27225
+ let defaultColwidth = 100;
27226
+ if (typeof colwidthValue !== "undefined") {
27227
+ colwidth.push(colwidthValue);
27228
+ } else {
27229
+ colwidth.push(defaultColwidth);
27230
+ }
27231
+ }
27232
+ if (colwidth.length) {
27233
+ attributes["colwidth"] = [...colwidth];
27234
+ }
27235
+ }
27668
27236
  }
27669
- if (totalWidthPx == null) {
27670
- totalWidthPx = minimumColumnWidthPx * columnCount;
27237
+ const background = {
27238
+ color: tableCellProperties.shading?.fill
27239
+ };
27240
+ if (background.color) attributes["background"] = background;
27241
+ const verticalAlign = tableCellProperties.vAlign;
27242
+ if (verticalAlign) attributes["verticalAlign"] = verticalAlign;
27243
+ attributes.cellMargins = getTableCellMargins(tableCellProperties.cellMargins, referencedStyles);
27244
+ const { fontSize: fontSize2, fonts = {} } = referencedStyles;
27245
+ const fontFamily2 = fonts["ascii"];
27246
+ if (fontSize2) attributes["fontSize"] = fontSize2;
27247
+ if (fontFamily2) attributes["fontFamily"] = fontFamily2;
27248
+ if (tableCellProperties.vMerge === "restart") {
27249
+ const rows = table.elements.filter((el) => el.name === "w:tr");
27250
+ const currentRowIndex = rows.findIndex((r2) => r2 === row);
27251
+ const remainingRows = rows.slice(currentRowIndex + 1);
27252
+ const cellsInRow = row.elements.filter((el) => el.name === "w:tc");
27253
+ let cellIndex = cellsInRow.findIndex((el) => el === node);
27254
+ let rowspan = 1;
27255
+ for (let remainingRow of remainingRows) {
27256
+ const firstCell = remainingRow.elements.findIndex((el) => el.name === "w:tc");
27257
+ const cellAtIndex = remainingRow.elements[firstCell + cellIndex];
27258
+ if (!cellAtIndex) break;
27259
+ const vMerge = getTableCellVMerge(cellAtIndex);
27260
+ if (!vMerge || vMerge === "restart") {
27261
+ break;
27262
+ }
27263
+ rowspan++;
27264
+ remainingRow.elements.splice(firstCell + cellIndex, 1);
27265
+ }
27266
+ attributes["rowspan"] = rowspan;
27671
27267
  }
27672
- const rawColumnWidthPx = Math.max(totalWidthPx / columnCount, minimumColumnWidthPx);
27673
- const columnWidthTwips = clampColumnWidthTwips(pixelsToTwips(rawColumnWidthPx));
27674
- const fallbackColumnWidthPx = twipsToPixels(columnWidthTwips);
27675
27268
  return {
27676
- grid: createFallbackGrid(columnCount, columnWidthTwips),
27677
- columnWidths: Array(columnCount).fill(fallbackColumnWidthPx)
27269
+ type: "tableCell",
27270
+ content: normalizeTableCellContent(
27271
+ nodeListHandler.handler({
27272
+ ...params2,
27273
+ nodes: node.elements,
27274
+ path: [...params2.path || [], node]
27275
+ }),
27276
+ params2.editor
27277
+ ),
27278
+ attrs: attributes
27678
27279
  };
27679
- };
27680
- const XML_NODE_NAME$f = "w:tbl";
27681
- const SD_NODE_NAME$c = "table";
27682
- const encode$l = (params2, encodedAttrs) => {
27683
- const { nodes } = params2;
27684
- const node = nodes[0];
27685
- const tblPr = node.elements.find((el) => el.name === "w:tblPr");
27686
- if (tblPr) {
27687
- const encodedProperties = translator$v.encode({ ...params2, nodes: [tblPr] });
27688
- encodedAttrs["tableProperties"] = encodedProperties || {};
27689
- }
27690
- const tblGrid = node.elements.find((el) => el.name === "w:tblGrid");
27691
- if (tblGrid) {
27692
- encodedAttrs["grid"] = translator$t.encode({ ...params2, nodes: [tblGrid] }).attributes;
27693
- }
27694
- [
27695
- "tableStyleId",
27696
- "justification",
27697
- "tableLayout",
27698
- ["tableIndent", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
27699
- ["tableCellSpacing", ({ value, type: type2 }) => ({ w: String(value), type: type2 })]
27700
- ].forEach((prop) => {
27701
- let key2;
27702
- let transform;
27703
- if (Array.isArray(prop)) {
27704
- [key2, transform] = prop;
27705
- } else {
27706
- key2 = prop;
27707
- transform = (v2) => v2;
27280
+ }
27281
+ function normalizeTableCellContent(content, editor) {
27282
+ if (!Array.isArray(content) || content.length === 0) return content;
27283
+ const normalized = [];
27284
+ const pendingForNextBlock = [];
27285
+ const schema = editor?.schema;
27286
+ const cloneBlock = (node) => {
27287
+ if (!node) return node;
27288
+ const cloned = { ...node };
27289
+ if (Array.isArray(node.content)) {
27290
+ cloned.content = [...node.content];
27708
27291
  }
27709
- if (encodedAttrs.tableProperties && encodedAttrs.tableProperties[key2]) {
27710
- encodedAttrs[key2] = transform(encodedAttrs.tableProperties[key2]);
27292
+ return cloned;
27293
+ };
27294
+ const ensureArray = (node) => {
27295
+ if (!Array.isArray(node.content)) {
27296
+ node.content = [];
27711
27297
  }
27712
- });
27713
- if (encodedAttrs.tableCellSpacing) {
27714
- encodedAttrs["borderCollapse"] = "separate";
27715
- }
27716
- if (encodedAttrs.tableProperties?.tableWidth) {
27717
- const tableWidthMeasurement = encodedAttrs.tableProperties.tableWidth;
27718
- const widthPx = twipsToPixels(tableWidthMeasurement.value);
27719
- if (widthPx != null) {
27720
- encodedAttrs.tableWidth = {
27721
- width: widthPx,
27722
- type: tableWidthMeasurement.type
27723
- };
27724
- } else if (tableWidthMeasurement.type === "auto") {
27725
- encodedAttrs.tableWidth = {
27726
- width: 0,
27727
- type: tableWidthMeasurement.type
27728
- };
27298
+ return node.content;
27299
+ };
27300
+ const isInlineNode = (node) => {
27301
+ if (!node || typeof node.type !== "string") return false;
27302
+ if (node.type === "text") return true;
27303
+ if (node.type === "bookmarkStart" || node.type === "bookmarkEnd") return true;
27304
+ const nodeType = schema?.nodes?.[node.type];
27305
+ if (nodeType) {
27306
+ if (typeof nodeType.isInline === "boolean") return nodeType.isInline;
27307
+ if (nodeType.spec?.group && typeof nodeType.spec.group === "string") {
27308
+ return nodeType.spec.group.split(" ").includes("inline");
27309
+ }
27729
27310
  }
27730
- }
27731
- const { borders, rowBorders } = _processTableBorders(encodedAttrs.tableProperties?.borders || {});
27732
- const referencedStyles = _getReferencedTableStyles(encodedAttrs.tableStyleId, params2);
27733
- if (referencedStyles?.cellMargins && !encodedAttrs.tableProperties?.cellMargins) {
27734
- encodedAttrs.tableProperties = {
27735
- ...encodedAttrs.tableProperties || {},
27736
- cellMargins: referencedStyles.cellMargins
27737
- };
27738
- }
27739
- const rows = node.elements.filter((el) => el.name === "w:tr");
27740
- const borderData = Object.assign({}, referencedStyles?.borders || {}, borders || {});
27741
- const borderRowData = Object.assign({}, referencedStyles?.rowBorders || {}, rowBorders || {});
27742
- encodedAttrs["borders"] = borderData;
27743
- const tblStyleTag = tblPr?.elements?.find((el) => el.name === "w:tblStyle");
27744
- let columnWidths = Array.isArray(encodedAttrs["grid"]) ? encodedAttrs["grid"].map((item) => twipsToPixels(item.col)) : [];
27745
- if (!columnWidths.length) {
27746
- const fallback = buildFallbackGridForTable({
27747
- params: params2,
27748
- rows,
27749
- tableWidth: encodedAttrs.tableWidth,
27750
- tableWidthMeasurement: encodedAttrs.tableProperties?.tableWidth
27751
- });
27752
- if (fallback) {
27753
- encodedAttrs.grid = fallback.grid;
27754
- columnWidths = fallback.columnWidths;
27311
+ return false;
27312
+ };
27313
+ for (const node of content) {
27314
+ if (!node || typeof node.type !== "string") {
27315
+ normalized.push(node);
27316
+ continue;
27755
27317
  }
27756
- }
27757
- const content = [];
27758
- const totalColumns = columnWidths.length;
27759
- const activeRowSpans = totalColumns > 0 ? new Array(totalColumns).fill(0) : [];
27760
- rows.forEach((row, rowIndex) => {
27761
- const result = translator$Z.encode({
27762
- ...params2,
27763
- nodes: [row],
27764
- extraParams: {
27765
- row,
27766
- table: node,
27767
- rowBorders: borderRowData,
27768
- styleTag: tblStyleTag,
27769
- columnWidths,
27770
- activeRowSpans: activeRowSpans.slice(),
27771
- rowIndex
27772
- }
27773
- });
27774
- if (result) {
27775
- content.push(result);
27776
- if (totalColumns > 0) {
27777
- const activeRowSpansForCurrentRow = activeRowSpans.slice();
27778
- for (let col = 0; col < totalColumns; col++) {
27779
- if (activeRowSpans[col] > 0) {
27780
- activeRowSpans[col] -= 1;
27781
- }
27782
- }
27783
- let columnIndex = 0;
27784
- const advanceColumnIndex = () => {
27785
- while (columnIndex < totalColumns && activeRowSpansForCurrentRow[columnIndex] > 0) {
27786
- columnIndex += 1;
27787
- }
27788
- };
27789
- advanceColumnIndex();
27790
- result.content?.forEach((cell) => {
27791
- advanceColumnIndex();
27792
- const colspan = Math.max(1, cell.attrs?.colspan || 1);
27793
- const rowspan = Math.max(1, cell.attrs?.rowspan || 1);
27794
- if (rowspan > 1) {
27795
- for (let offset2 = 0; offset2 < colspan && columnIndex + offset2 < totalColumns; offset2++) {
27796
- const targetIndex = columnIndex + offset2;
27797
- const remainingRows = rowspan - 1;
27798
- if (remainingRows > 0 && remainingRows > activeRowSpans[targetIndex]) {
27799
- activeRowSpans[targetIndex] = remainingRows;
27800
- }
27801
- }
27802
- }
27803
- columnIndex += colspan;
27804
- advanceColumnIndex();
27805
- });
27806
- }
27807
- }
27808
- });
27809
- return {
27810
- type: "table",
27811
- content,
27812
- attrs: encodedAttrs
27813
- };
27814
- };
27815
- const decode$n = (params2, decodedAttrs) => {
27816
- params2.node = preProcessVerticalMergeCells(params2.node, params2);
27817
- const { node } = params2;
27818
- const elements = translateChildNodes(params2);
27819
- const firstRow = node.content?.find((n) => n.type === "tableRow");
27820
- const properties = node.attrs.grid;
27821
- const element = translator$t.decode({
27822
- ...params2,
27823
- node: { ...node, attrs: { ...node.attrs, grid: properties } },
27824
- extraParams: {
27825
- firstRow
27826
- }
27827
- });
27828
- if (element) elements.unshift(element);
27829
- if (node.attrs?.tableProperties) {
27830
- const properties2 = { ...node.attrs.tableProperties };
27831
- const element2 = translator$v.decode({
27832
- ...params2,
27833
- node: { ...node, attrs: { ...node.attrs, tableProperties: properties2 } }
27834
- });
27835
- if (element2) elements.unshift(element2);
27836
- }
27837
- return {
27838
- name: "w:tbl",
27839
- attributes: decodedAttrs || {},
27840
- elements
27841
- };
27842
- };
27843
- function _processTableBorders(rawBorders) {
27844
- const borders = {};
27845
- const rowBorders = {};
27846
- Object.entries(rawBorders).forEach(([name, attributes]) => {
27847
- const attrs = {};
27848
- const color = attributes.color;
27849
- const size2 = attributes.size;
27850
- if (color && color !== "auto") attrs["color"] = color.startsWith("#") ? color : `#${color}`;
27851
- if (size2 && size2 !== "auto") attrs["size"] = eighthPointsToPixels(size2);
27852
- const rowBorderNames = ["insideH", "insideV"];
27853
- if (rowBorderNames.includes(name)) rowBorders[name] = attrs;
27854
- borders[name] = attrs;
27855
- });
27856
- return {
27857
- borders,
27858
- rowBorders
27859
- };
27860
- }
27861
- function _getReferencedTableStyles(tableStyleReference, params2) {
27862
- if (!tableStyleReference) return null;
27863
- const stylesToReturn = {};
27864
- const { docx } = params2;
27865
- const styles = docx["word/styles.xml"];
27866
- const { elements } = styles.elements[0];
27867
- const styleElements = elements.filter((el) => el.name === "w:style");
27868
- const styleTag = styleElements.find((el) => el.attributes["w:styleId"] === tableStyleReference);
27869
- if (!styleTag) return null;
27870
- stylesToReturn.name = styleTag.elements.find((el) => el.name === "w:name");
27871
- const basedOn = styleTag.elements.find((el) => el.name === "w:basedOn");
27872
- let baseTblPr;
27873
- if (basedOn?.attributes) {
27874
- const baseStyles = styleElements.find((el) => el.attributes["w:styleId"] === basedOn.attributes["w:val"]);
27875
- baseTblPr = baseStyles ? baseStyles.elements.find((el) => el.name === "w:tblPr") : {};
27876
- }
27877
- const pPr = styleTag.elements.find((el) => el.name === "w:pPr");
27878
- if (pPr) {
27879
- const justification = pPr.elements.find((el) => el.name === "w:jc");
27880
- if (justification?.attributes) stylesToReturn.justification = justification.attributes["w:val"];
27881
- }
27882
- const rPr = styleTag?.elements.find((el) => el.name === "w:rPr");
27883
- if (rPr) {
27884
- const fonts = rPr.elements.find((el) => el.name === "w:rFonts");
27885
- if (fonts) {
27886
- const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
27887
- stylesToReturn.fonts = { ascii, hAnsi, cs };
27888
- }
27889
- const fontSize2 = rPr.elements.find((el) => el.name === "w:sz");
27890
- if (fontSize2?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize2.attributes["w:val"]) + "pt";
27891
- }
27892
- const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
27893
- if (tblPr && tblPr.elements) {
27894
- if (baseTblPr && baseTblPr.elements) {
27895
- tblPr.elements.push(...baseTblPr.elements);
27896
- }
27897
- const tableProperties = translator$v.encode({ ...params2, nodes: [tblPr] });
27898
- const { borders, rowBorders } = _processTableBorders(tableProperties.borders || {});
27899
- if (borders) stylesToReturn.borders = borders;
27900
- if (rowBorders) stylesToReturn.rowBorders = rowBorders;
27901
- const cellMargins = {};
27902
- Object.entries(tableProperties.cellMargins || {}).forEach(([key2, attrs]) => {
27903
- if (attrs?.value != null) {
27904
- cellMargins[key2] = {
27905
- value: attrs.value,
27906
- type: attrs.type || "dxa"
27907
- };
27908
- }
27909
- });
27910
- if (Object.keys(cellMargins).length) stylesToReturn.cellMargins = cellMargins;
27911
- }
27912
- return stylesToReturn;
27913
- }
27914
- const config$e = {
27915
- xmlName: XML_NODE_NAME$f,
27916
- sdNodeOrKeyName: SD_NODE_NAME$c,
27917
- type: NodeTranslator.translatorTypes.NODE,
27918
- encode: encode$l,
27919
- decode: decode$n,
27920
- attributes: []
27921
- };
27922
- const translator$s = NodeTranslator.from(config$e);
27923
- const tableNodeHandlerEntity = generateV2HandlerEntity("tableNodeHandler", translator$s);
27924
- function getReferencedTableStyles(tblStyleTag, docx) {
27925
- if (!tblStyleTag) return null;
27926
- const stylesToReturn = {};
27927
- const { attributes = {} } = tblStyleTag;
27928
- const tableStyleReference = attributes["w:val"];
27929
- if (!tableStyleReference) return null;
27930
- const styles = docx["word/styles.xml"];
27931
- const { elements } = styles.elements[0];
27932
- const styleElements = elements.filter((el) => el.name === "w:style");
27933
- const styleTag = styleElements.find((el) => el.attributes["w:styleId"] === tableStyleReference);
27934
- if (!styleTag) return null;
27935
- stylesToReturn.name = styleTag.elements.find((el) => el.name === "w:name");
27936
- const basedOn = styleTag.elements.find((el) => el.name === "w:basedOn");
27937
- let baseTblPr;
27938
- if (basedOn?.attributes) {
27939
- const baseStyles = styleElements.find((el) => el.attributes["w:styleId"] === basedOn.attributes["w:val"]);
27940
- baseTblPr = baseStyles ? baseStyles.elements.find((el) => el.name === "w:tblPr") : {};
27941
- }
27942
- const pPr = styleTag.elements.find((el) => el.name === "w:pPr");
27943
- if (pPr) {
27944
- const justification = pPr.elements.find((el) => el.name === "w:jc");
27945
- if (justification?.attributes) stylesToReturn.justification = justification.attributes["w:val"];
27946
- }
27947
- const rPr = styleTag?.elements.find((el) => el.name === "w:rPr");
27948
- if (rPr) {
27949
- const fonts = rPr.elements.find((el) => el.name === "w:rFonts");
27950
- if (fonts) {
27951
- const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
27952
- stylesToReturn.fonts = { ascii, hAnsi, cs };
27953
- }
27954
- const fontSize2 = rPr.elements.find((el) => el.name === "w:sz");
27955
- if (fontSize2?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize2.attributes["w:val"]) + "pt";
27956
- }
27957
- const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
27958
- if (tblPr && tblPr.elements) {
27959
- if (baseTblPr && baseTblPr.elements) {
27960
- tblPr.elements.push(...baseTblPr.elements);
27961
- }
27962
- const tableBorders = tblPr?.elements?.find((el) => el.name === "w:tblBorders");
27963
- const { elements: borderElements = [] } = tableBorders || {};
27964
- const { borders, rowBorders } = processTableBorders(borderElements);
27965
- if (borders) stylesToReturn.borders = borders;
27966
- if (rowBorders) stylesToReturn.rowBorders = rowBorders;
27967
- const tableCellMargin = tblPr?.elements.find((el) => el.name === "w:tblCellMar");
27968
- if (tableCellMargin) {
27969
- const marginLeft = tableCellMargin.elements.find((el) => el.name === "w:left");
27970
- const marginRight = tableCellMargin.elements.find((el) => el.name === "w:right");
27971
- const marginTop = tableCellMargin.elements.find((el) => el.name === "w:top");
27972
- const marginBottom = tableCellMargin.elements.find((el) => el.name === "w:bottom");
27973
- stylesToReturn.cellMargins = {
27974
- marginLeft: marginLeft?.attributes["w:w"],
27975
- marginRight: marginRight?.attributes["w:w"],
27976
- marginTop: marginTop?.attributes["w:w"],
27977
- marginBottom: marginBottom?.attributes["w:w"]
27978
- };
27979
- }
27980
- }
27981
- return stylesToReturn;
27982
- }
27983
- function processTableBorders(borderElements) {
27984
- const borders = {};
27985
- const rowBorders = {};
27986
- borderElements.forEach((borderElement) => {
27987
- const { name } = borderElement;
27988
- const borderName = name.split("w:")[1];
27989
- const { attributes } = borderElement;
27990
- const attrs = {};
27991
- const color = attributes["w:color"];
27992
- const size2 = attributes["w:sz"];
27993
- if (color && color !== "auto") attrs["color"] = color.startsWith("#") ? color : `#${color}`;
27994
- if (size2 && size2 !== "auto") attrs["size"] = eighthPointsToPixels(size2);
27995
- const rowBorderNames = ["insideH", "insideV"];
27996
- if (rowBorderNames.includes(borderName)) rowBorders[borderName] = attrs;
27997
- borders[borderName] = attrs;
27998
- });
27999
- return {
28000
- borders,
28001
- rowBorders
28002
- };
28003
- }
28004
- const translator$r = NodeTranslator.from(createMeasurementPropertyHandler("w:tcW", "cellWidth"));
28005
- const translator$q = NodeTranslator.from(
28006
- createSingleAttrPropertyHandler(
28007
- "w:gridSpan",
28008
- null,
28009
- "w:val",
28010
- (v2) => parseInteger(v2) ?? void 0,
28011
- (v2) => integerToString(v2)
28012
- )
28013
- );
28014
- const translator$p = NodeTranslator.from(createSingleAttrPropertyHandler("w:vMerge"));
28015
- const translator$o = NodeTranslator.from(createBorderPropertyHandler("w:tl2br"));
28016
- const translator$n = NodeTranslator.from(createBorderPropertyHandler("w:tr2bl"));
28017
- const propertyTranslators$2 = [
28018
- translator$z,
28019
- translator$B,
28020
- translator$F,
28021
- translator$L,
28022
- translator$J,
28023
- translator$D,
28024
- translator$H,
28025
- translator$G,
28026
- translator$o,
28027
- translator$n
28028
- ];
28029
- const translator$m = NodeTranslator.from(
28030
- createNestedPropertiesTranslator("w:tcBorders", "borders", propertyTranslators$2)
28031
- );
28032
- const translator$l = NodeTranslator.from(
28033
- createSingleAttrPropertyHandler(
28034
- "w:noWrap",
28035
- null,
28036
- "w:val",
28037
- (v2) => parseBoolean(v2 ?? "true"),
28038
- (v2) => booleanToString(v2)
28039
- )
28040
- );
28041
- const propertyTranslators$1 = [
28042
- translator$K,
28043
- translator$I,
28044
- translator$E,
28045
- translator$C,
28046
- translator$A,
28047
- translator$y
28048
- ];
28049
- const translator$k = NodeTranslator.from(
28050
- createNestedPropertiesTranslator("w:tcMar", "cellMargins", propertyTranslators$1)
28051
- );
28052
- const translator$j = NodeTranslator.from(createSingleAttrPropertyHandler("w:textDirection"));
28053
- const translator$i = NodeTranslator.from(
28054
- createSingleAttrPropertyHandler(
28055
- "w:tcFitText",
28056
- null,
28057
- "w:val",
28058
- (v2) => parseBoolean(v2 ?? "true"),
28059
- (v2) => booleanToString(v2)
28060
- )
28061
- );
28062
- const translator$h = NodeTranslator.from(createSingleAttrPropertyHandler("w:vAlign"));
28063
- const translator$g = NodeTranslator.from(
28064
- createSingleAttrPropertyHandler(
28065
- "w:hideMark",
28066
- null,
28067
- "w:val",
28068
- (v2) => parseBoolean(v2 ?? "true"),
28069
- (v2) => booleanToString(v2)
28070
- )
28071
- );
28072
- const translator$f = NodeTranslator.from(createSingleAttrPropertyHandler("w:header"));
28073
- const XML_NODE_NAME$e = "w:headers";
28074
- const SD_ATTR_KEY$2 = "headers";
28075
- const encode$k = (params2) => {
28076
- const { nodes } = params2;
28077
- const node = nodes[0];
28078
- const attributes = encodeProperties(node, { [translator$f.xmlName]: translator$f }, true);
28079
- return {
28080
- xmlName: XML_NODE_NAME$e,
28081
- sdNodeOrKeyName: SD_ATTR_KEY$2,
28082
- attributes
28083
- };
28084
- };
28085
- const decode$m = (params2) => {
28086
- const { headers = [] } = params2.node.attrs || {};
28087
- const newNode = {
28088
- name: XML_NODE_NAME$e,
28089
- attributes: {},
28090
- elements: headers.map(
28091
- (header) => translator$f.decode({
28092
- node: { type: "header", attrs: header }
28093
- })
28094
- )
28095
- };
28096
- return newNode;
28097
- };
28098
- const config$d = {
28099
- xmlName: XML_NODE_NAME$e,
28100
- sdNodeOrKeyName: SD_ATTR_KEY$2,
28101
- encode: encode$k,
28102
- decode: decode$m
28103
- };
28104
- const translator$e = NodeTranslator.from(config$d);
28105
- const propertyTranslators = [
28106
- translator$19,
28107
- translator$r,
28108
- translator$q,
28109
- translator$p,
28110
- translator$m,
28111
- translator$X,
28112
- translator$l,
28113
- translator$k,
28114
- translator$j,
28115
- translator$i,
28116
- translator$h,
28117
- translator$g,
28118
- translator$e
28119
- ];
28120
- const translator$d = NodeTranslator.from(
28121
- createNestedPropertiesTranslator("w:tcPr", "tableCellProperties", propertyTranslators)
28122
- );
28123
- function handleTableCellNode({
28124
- params: params2,
28125
- node,
28126
- table,
28127
- row,
28128
- rowBorders,
28129
- styleTag,
28130
- columnIndex,
28131
- columnWidth = null,
28132
- allColumnWidths = []
28133
- }) {
28134
- const { docx, nodeListHandler } = params2;
28135
- const attributes = {};
28136
- const tcPr = node.elements.find((el) => el.name === "w:tcPr");
28137
- const tableCellProperties = tcPr ? translator$d.encode({ ...params2, nodes: [tcPr] }) ?? {} : {};
28138
- attributes["tableCellProperties"] = tableCellProperties;
28139
- if (rowBorders?.insideH) {
28140
- rowBorders["bottom"] = rowBorders.insideH;
28141
- delete rowBorders.insideH;
28142
- }
28143
- if (rowBorders?.insideV) {
28144
- rowBorders["right"] = rowBorders.insideV;
28145
- delete rowBorders?.insideV;
28146
- }
28147
- if (rowBorders) attributes["borders"] = { ...rowBorders };
28148
- const inlineBorders = processInlineCellBorders(tableCellProperties.borders, rowBorders);
28149
- if (inlineBorders) attributes["borders"] = Object.assign(attributes["borders"] || {}, inlineBorders);
28150
- const colspan = tableCellProperties.gridSpan;
28151
- if (colspan && !isNaN(parseInt(colspan, 10))) attributes["colspan"] = parseInt(colspan, 10);
28152
- let width = tableCellProperties.cellWidth?.value ? twipsToPixels(tableCellProperties.cellWidth?.value) : null;
28153
- const widthType = tableCellProperties.cellWidth?.type;
28154
- if (widthType) attributes["widthType"] = widthType;
28155
- if (!width && columnWidth) width = columnWidth;
28156
- if (width) {
28157
- attributes["colwidth"] = [width];
28158
- attributes["widthUnit"] = "px";
28159
- const defaultColWidths = allColumnWidths;
28160
- const hasDefaultColWidths = allColumnWidths && allColumnWidths.length > 0;
28161
- const colspanNum = parseInt(colspan || 1, 10);
28162
- if (colspanNum && colspanNum > 1 && hasDefaultColWidths) {
28163
- let colwidth = [];
28164
- for (let i = 0; i < colspanNum; i++) {
28165
- let colwidthValue = defaultColWidths[columnIndex + i];
28166
- let defaultColwidth = 100;
28167
- if (typeof colwidthValue !== "undefined") {
28168
- colwidth.push(colwidthValue);
28169
- } else {
28170
- colwidth.push(defaultColwidth);
28171
- }
28172
- }
28173
- if (colwidth.length) {
28174
- attributes["colwidth"] = [...colwidth];
28175
- }
28176
- }
28177
- }
28178
- const background = {
28179
- color: tableCellProperties.shading?.fill
28180
- };
28181
- if (background.color) attributes["background"] = background;
28182
- const verticalAlign = tableCellProperties.vAlign;
28183
- if (verticalAlign) attributes["verticalAlign"] = verticalAlign;
28184
- const referencedStyles = getReferencedTableStyles(styleTag, docx) || { fontSize: null, fonts: {}, cellMargins: {} };
28185
- attributes.cellMargins = getTableCellMargins(tableCellProperties.cellMargins, referencedStyles);
28186
- const { fontSize: fontSize2, fonts = {} } = referencedStyles;
28187
- const fontFamily2 = fonts["ascii"];
28188
- if (fontSize2) attributes["fontSize"] = fontSize2;
28189
- if (fontFamily2) attributes["fontFamily"] = fontFamily2;
28190
- if (tableCellProperties.vMerge === "restart") {
28191
- const rows = table.elements.filter((el) => el.name === "w:tr");
28192
- const currentRowIndex = rows.findIndex((r2) => r2 === row);
28193
- const remainingRows = rows.slice(currentRowIndex + 1);
28194
- const cellsInRow = row.elements.filter((el) => el.name === "w:tc");
28195
- let cellIndex = cellsInRow.findIndex((el) => el === node);
28196
- let rowspan = 1;
28197
- for (let remainingRow of remainingRows) {
28198
- const firstCell = remainingRow.elements.findIndex((el) => el.name === "w:tc");
28199
- const cellAtIndex = remainingRow.elements[firstCell + cellIndex];
28200
- if (!cellAtIndex) break;
28201
- const vMerge = getTableCellVMerge(cellAtIndex);
28202
- if (!vMerge || vMerge === "restart") {
28203
- break;
28204
- }
28205
- rowspan++;
28206
- remainingRow.elements.splice(firstCell + cellIndex, 1);
28207
- }
28208
- attributes["rowspan"] = rowspan;
28209
- }
28210
- return {
28211
- type: "tableCell",
28212
- content: normalizeTableCellContent(
28213
- nodeListHandler.handler({
28214
- ...params2,
28215
- nodes: node.elements,
28216
- path: [...params2.path || [], node]
28217
- }),
28218
- params2.editor
28219
- ),
28220
- attrs: attributes
28221
- };
28222
- }
28223
- function normalizeTableCellContent(content, editor) {
28224
- if (!Array.isArray(content) || content.length === 0) return content;
28225
- const normalized = [];
28226
- const pendingForNextBlock = [];
28227
- const schema = editor?.schema;
28228
- const cloneBlock = (node) => {
28229
- if (!node) return node;
28230
- const cloned = { ...node };
28231
- if (Array.isArray(node.content)) {
28232
- cloned.content = [...node.content];
28233
- }
28234
- return cloned;
28235
- };
28236
- const ensureArray = (node) => {
28237
- if (!Array.isArray(node.content)) {
28238
- node.content = [];
28239
- }
28240
- return node.content;
28241
- };
28242
- const isInlineNode = (node) => {
28243
- if (!node || typeof node.type !== "string") return false;
28244
- if (node.type === "text") return true;
28245
- if (node.type === "bookmarkStart" || node.type === "bookmarkEnd") return true;
28246
- const nodeType = schema?.nodes?.[node.type];
28247
- if (nodeType) {
28248
- if (typeof nodeType.isInline === "boolean") return nodeType.isInline;
28249
- if (nodeType.spec?.group && typeof nodeType.spec.group === "string") {
28250
- return nodeType.spec.group.split(" ").includes("inline");
28251
- }
28252
- }
28253
- return false;
28254
- };
28255
- for (const node of content) {
28256
- if (!node || typeof node.type !== "string") {
28257
- normalized.push(node);
28258
- continue;
28259
- }
28260
- if (!isInlineNode(node)) {
28261
- const blockNode = cloneBlock(node);
28262
- if (pendingForNextBlock.length) {
28263
- const blockContent = ensureArray(blockNode);
28264
- const leadingInline = pendingForNextBlock.splice(0);
28265
- blockNode.content = [...leadingInline, ...blockContent];
28266
- } else if (Array.isArray(blockNode.content)) {
28267
- blockNode.content = [...blockNode.content];
27318
+ if (!isInlineNode(node)) {
27319
+ const blockNode = cloneBlock(node);
27320
+ if (pendingForNextBlock.length) {
27321
+ const blockContent = ensureArray(blockNode);
27322
+ const leadingInline = pendingForNextBlock.splice(0);
27323
+ blockNode.content = [...leadingInline, ...blockContent];
27324
+ } else if (Array.isArray(blockNode.content)) {
27325
+ blockNode.content = [...blockNode.content];
28268
27326
  }
28269
27327
  normalized.push(blockNode);
28270
27328
  continue;
@@ -28447,22 +27505,22 @@ function generateTableCellProperties(node) {
28447
27505
  } else if (tableCellProperties?.borders) {
28448
27506
  delete tableCellProperties.borders;
28449
27507
  }
28450
- const result = translator$d.decode({ node: { ...node, attrs: { ...node.attrs, tableCellProperties } } });
27508
+ const result = translator$I.decode({ node: { ...node, attrs: { ...node.attrs, tableCellProperties } } });
28451
27509
  return result;
28452
27510
  }
28453
- const XML_NODE_NAME$d = "w:tc";
28454
- const SD_NODE_NAME$b = "tableCell";
28455
- const validXmlAttributes$a = [];
28456
- function encode$j(params2, encodedAttrs) {
27511
+ const XML_NODE_NAME$g = "w:tc";
27512
+ const SD_NODE_NAME$d = "tableCell";
27513
+ const validXmlAttributes$b = [];
27514
+ function encode$m(params2, encodedAttrs) {
28457
27515
  const {
28458
27516
  node,
28459
27517
  table,
28460
27518
  row,
28461
27519
  rowBorders,
28462
- styleTag,
28463
27520
  columnIndex,
28464
27521
  columnWidth,
28465
- columnWidths: allColumnWidths
27522
+ columnWidths: allColumnWidths,
27523
+ _referencedStyles
28466
27524
  } = params2.extraParams;
28467
27525
  const schemaNode = handleTableCellNode({
28468
27526
  params: params2,
@@ -28470,96 +27528,388 @@ function encode$j(params2, encodedAttrs) {
28470
27528
  table,
28471
27529
  row,
28472
27530
  rowBorders,
28473
- styleTag,
28474
27531
  columnIndex,
28475
27532
  columnWidth,
28476
- allColumnWidths
27533
+ allColumnWidths,
27534
+ _referencedStyles
28477
27535
  });
28478
27536
  if (encodedAttrs && Object.keys(encodedAttrs).length) {
28479
27537
  schemaNode.attrs = { ...schemaNode.attrs, ...encodedAttrs };
28480
27538
  }
28481
27539
  return schemaNode;
28482
27540
  }
28483
- function decode$l(params2, decodedAttrs) {
27541
+ function decode$o(params2, decodedAttrs) {
28484
27542
  const translated = translateTableCell(params2);
28485
27543
  if (decodedAttrs && Object.keys(decodedAttrs).length) {
28486
27544
  translated.attributes = { ...translated.attributes || {}, ...decodedAttrs };
28487
27545
  }
28488
27546
  return translated;
28489
27547
  }
28490
- const config$c = {
28491
- xmlName: XML_NODE_NAME$d,
28492
- sdNodeOrKeyName: SD_NODE_NAME$b,
27548
+ const config$f = {
27549
+ xmlName: XML_NODE_NAME$g,
27550
+ sdNodeOrKeyName: SD_NODE_NAME$d,
28493
27551
  type: NodeTranslator.translatorTypes.NODE,
28494
- encode: encode$j,
28495
- decode: decode$l,
28496
- attributes: validXmlAttributes$a
27552
+ encode: encode$m,
27553
+ decode: decode$o,
27554
+ attributes: validXmlAttributes$b
28497
27555
  };
28498
- const translator$c = NodeTranslator.from(config$c);
28499
- function parseTagValueJSON(json) {
28500
- if (typeof json !== "string") {
28501
- return {};
28502
- }
28503
- const trimmed = json.trim();
28504
- if (!trimmed) {
28505
- return {};
28506
- }
28507
- try {
28508
- return JSON.parse(trimmed);
28509
- } catch {
28510
- return {};
28511
- }
28512
- }
28513
- function handleAnnotationNode(params2) {
28514
- const { nodes } = params2;
28515
- if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
28516
- return null;
28517
- }
28518
- const node = nodes[0];
28519
- const sdtPr = node.elements.find((el) => el.name === "w:sdtPr");
28520
- const sdtContent = node.elements.find((el) => el.name === "w:sdtContent");
28521
- const sdtId = sdtPr?.elements?.find((el) => el.name === "w:id");
28522
- const alias = sdtPr?.elements.find((el) => el.name === "w:alias");
28523
- const tag = sdtPr?.elements.find((el) => el.name === "w:tag");
28524
- const tagValue = tag?.attributes["w:val"];
28525
- const shouldProcessAsJson = tagValue?.startsWith("{") && tagValue?.endsWith("}");
28526
- let attrs = {};
28527
- const aliasLabel = getSafeString(alias?.attributes?.["w:val"]);
28528
- if (shouldProcessAsJson) {
28529
- const parsedAttrs = parseTagValueJSON(tagValue);
28530
- attrs = {
28531
- type: parsedAttrs.fieldTypeShort,
28532
- fieldId: parsedAttrs.fieldId,
28533
- displayLabel: parsedAttrs.displayLabel,
28534
- defaultDisplayLabel: parsedAttrs.defaultDisplayLabel,
28535
- fieldType: parsedAttrs.fieldType,
28536
- fieldColor: parsedAttrs.fieldColor,
28537
- multipleImage: parsedAttrs.fieldMultipleImage,
28538
- fontFamily: parsedAttrs.fieldFontFamily,
28539
- fontSize: parsedAttrs.fieldFontSize,
28540
- textColor: parsedAttrs.fieldTextColor,
28541
- textHighlight: parsedAttrs.fieldTextHighlight,
28542
- hash: parsedAttrs.hash
28543
- };
28544
- } else {
28545
- attrs = getAttrsFromElements({ sdtPr, tag, alias, sdtId });
28546
- }
28547
- const initialDisplayLabel = getSafeString(attrs.displayLabel);
28548
- const extractedContent = getTextFromSdtContent(sdtContent);
28549
- if (!attrs.defaultDisplayLabel) {
28550
- if (initialDisplayLabel) {
28551
- attrs.defaultDisplayLabel = initialDisplayLabel;
28552
- } else if (aliasLabel) {
28553
- attrs.defaultDisplayLabel = aliasLabel;
27556
+ const translator$H = NodeTranslator.from(config$f);
27557
+ const translator$G = NodeTranslator.from({
27558
+ xmlName: "w:cantSplit",
27559
+ sdNodeOrKeyName: "cantSplit",
27560
+ encode: ({ nodes }) => ["1", "true"].includes(nodes[0].attributes?.["w:val"] ?? "1"),
27561
+ decode: ({ node }) => node.attrs?.cantSplit ? { attributes: {} } : void 0
27562
+ });
27563
+ const translator$F = NodeTranslator.from(createSingleAttrPropertyHandler("w:divId"));
27564
+ const translator$E = NodeTranslator.from(
27565
+ createSingleAttrPropertyHandler(
27566
+ "w:gridAfter",
27567
+ null,
27568
+ "w:val",
27569
+ (v2) => parseInteger(v2) ?? void 0,
27570
+ (v2) => integerToString(v2)
27571
+ )
27572
+ );
27573
+ const translator$D = NodeTranslator.from(
27574
+ createSingleAttrPropertyHandler(
27575
+ "w:gridBefore",
27576
+ null,
27577
+ "w:val",
27578
+ (v2) => parseInteger(v2) ?? void 0,
27579
+ (v2) => integerToString(v2)
27580
+ )
27581
+ );
27582
+ const translator$C = NodeTranslator.from({
27583
+ xmlName: "w:hidden",
27584
+ sdNodeOrKeyName: "hidden",
27585
+ encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
27586
+ decode: ({ node }) => node.attrs.hidden ? { attributes: {} } : void 0
27587
+ });
27588
+ const translator$B = NodeTranslator.from(createSingleAttrPropertyHandler("w:jc", "justification"));
27589
+ const translator$A = NodeTranslator.from(createMeasurementPropertyHandler("w:tblCellSpacing", "tableCellSpacing"));
27590
+ const translator$z = NodeTranslator.from({
27591
+ xmlName: "w:tblHeader",
27592
+ sdNodeOrKeyName: "repeatHeader",
27593
+ encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
27594
+ decode: ({ node }) => node.attrs.repeatHeader ? { attributes: {} } : void 0
27595
+ });
27596
+ const translator$y = NodeTranslator.from({
27597
+ xmlName: "w:trHeight",
27598
+ sdNodeOrKeyName: "rowHeight",
27599
+ encode: ({ nodes }) => {
27600
+ const heightAttrs = {};
27601
+ const val = nodes[0].attributes["w:val"];
27602
+ if (val) {
27603
+ heightAttrs["value"] = parseInt(val, 10);
28554
27604
  }
28555
- }
28556
- const placeholderLabel = getPlaceholderLabel(attrs, aliasLabel);
28557
- const placeholderText = ensurePlaceholderFormat(placeholderLabel);
28558
- const isAnnotationsEnabled = Boolean(params2.editor?.options?.annotations);
28559
- const contentIsDistinct = shouldUseSdtContent(extractedContent, placeholderText);
28560
- const shouldUseContent = !isAnnotationsEnabled && contentIsDistinct && (hasMoustache(extractedContent) || !placeholderText);
28561
- if (contentIsDistinct) {
28562
- attrs.displayLabel = extractedContent;
27605
+ const rule = nodes[0].attributes["w:hRule"];
27606
+ if (rule) {
27607
+ heightAttrs["rule"] = rule;
27608
+ }
27609
+ return Object.keys(heightAttrs).length > 0 ? heightAttrs : void 0;
27610
+ },
27611
+ decode: ({ node }) => {
27612
+ if (!node.attrs?.rowHeight) return;
27613
+ const heightAttrs = {};
27614
+ if (typeof node.attrs.rowHeight.value === "number" && !isNaN(node.attrs.rowHeight.value)) {
27615
+ heightAttrs["w:val"] = String(node.attrs.rowHeight.value);
27616
+ }
27617
+ if (node.attrs.rowHeight.rule) {
27618
+ heightAttrs["w:hRule"] = node.attrs.rowHeight.rule;
27619
+ }
27620
+ return Object.keys(heightAttrs).length > 0 ? { attributes: heightAttrs } : void 0;
27621
+ }
27622
+ });
27623
+ const translator$x = NodeTranslator.from(createMeasurementPropertyHandler("w:wAfter"));
27624
+ const translator$w = NodeTranslator.from(createMeasurementPropertyHandler("w:wBefore"));
27625
+ const propertyTranslators$3 = [
27626
+ translator$G,
27627
+ translator$1a,
27628
+ translator$F,
27629
+ translator$E,
27630
+ translator$D,
27631
+ translator$C,
27632
+ translator$B,
27633
+ translator$A,
27634
+ translator$z,
27635
+ translator$y,
27636
+ translator$x,
27637
+ translator$w
27638
+ ];
27639
+ const translator$v = NodeTranslator.from(
27640
+ createNestedPropertiesTranslator("w:trPr", "tableRowProperties", propertyTranslators$3, {
27641
+ cantSplit: false,
27642
+ hidden: false,
27643
+ repeatHeader: false
27644
+ })
27645
+ );
27646
+ const createPlaceholderCell = (gridWidth, reason) => {
27647
+ const safeWidth = Number.isFinite(gridWidth) ? gridWidth : 0;
27648
+ const noBorder = { val: "none", size: 0 };
27649
+ return {
27650
+ type: "tableCell",
27651
+ attrs: {
27652
+ colspan: 1,
27653
+ rowspan: 1,
27654
+ colwidth: [safeWidth],
27655
+ __placeholder: reason,
27656
+ borders: {
27657
+ top: { ...noBorder },
27658
+ right: { ...noBorder },
27659
+ bottom: { ...noBorder },
27660
+ left: { ...noBorder }
27661
+ }
27662
+ },
27663
+ content: [{ type: "paragraph", content: [] }]
27664
+ };
27665
+ };
27666
+ const advancePastRowSpans = (pendingRowSpans, startIndex, totalColumns) => {
27667
+ let index2 = startIndex;
27668
+ while (index2 < totalColumns && pendingRowSpans[index2] > 0) {
27669
+ pendingRowSpans[index2] -= 1;
27670
+ index2 += 1;
27671
+ }
27672
+ return index2;
27673
+ };
27674
+ const fillPlaceholderColumns = ({
27675
+ content,
27676
+ pendingRowSpans,
27677
+ currentIndex,
27678
+ targetIndex,
27679
+ totalColumns,
27680
+ gridColumnWidths,
27681
+ reason
27682
+ }) => {
27683
+ let index2 = currentIndex;
27684
+ while (index2 < targetIndex && index2 < totalColumns) {
27685
+ if (pendingRowSpans[index2] > 0) {
27686
+ pendingRowSpans[index2] -= 1;
27687
+ index2 += 1;
27688
+ continue;
27689
+ }
27690
+ const width = Array.isArray(gridColumnWidths) ? gridColumnWidths[index2] ?? 0 : 0;
27691
+ content.push(createPlaceholderCell(width, reason));
27692
+ index2 += 1;
27693
+ }
27694
+ return index2;
27695
+ };
27696
+ const isPlaceholderCell = (cell) => {
27697
+ if (!cell) return false;
27698
+ if (cell.attrs?.__placeholder) return true;
27699
+ const widths = cell.attrs?.colwidth;
27700
+ if (Array.isArray(widths) && widths.length > 0) {
27701
+ const hasMeaningfulWidth = widths.some(
27702
+ (value) => typeof value === "number" && Number.isFinite(value) && Math.abs(value) > 1
27703
+ );
27704
+ if (!hasMeaningfulWidth) return true;
27705
+ }
27706
+ return false;
27707
+ };
27708
+ const XML_NODE_NAME$f = "w:tr";
27709
+ const SD_NODE_NAME$c = "tableRow";
27710
+ const validXmlAttributes$a = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
27711
+ (xmlName) => createAttributeHandler(xmlName)
27712
+ );
27713
+ const encode$l = (params2, encodedAttrs) => {
27714
+ const { row } = params2.extraParams;
27715
+ let tableRowProperties = {};
27716
+ const tPr = row.elements.find((el) => el.name === "w:trPr");
27717
+ if (tPr) {
27718
+ tableRowProperties = translator$v.encode({
27719
+ ...params2,
27720
+ nodes: [tPr]
27721
+ });
27722
+ }
27723
+ const gridBeforeRaw = tableRowProperties?.["gridBefore"];
27724
+ const safeGridBefore = typeof gridBeforeRaw === "number" && Number.isFinite(gridBeforeRaw) && gridBeforeRaw > 0 ? gridBeforeRaw : 0;
27725
+ encodedAttrs["tableRowProperties"] = Object.freeze(tableRowProperties);
27726
+ encodedAttrs["rowHeight"] = twipsToPixels(tableRowProperties["rowHeight"]?.value);
27727
+ encodedAttrs["cantSplit"] = tableRowProperties["cantSplit"];
27728
+ const { columnWidths: gridColumnWidths, activeRowSpans = [] } = params2.extraParams;
27729
+ const totalColumns = Array.isArray(gridColumnWidths) ? gridColumnWidths.length : 0;
27730
+ const pendingRowSpans = Array.isArray(activeRowSpans) ? activeRowSpans.slice() : [];
27731
+ while (pendingRowSpans.length < totalColumns) pendingRowSpans.push(0);
27732
+ const cellNodes = row.elements.filter((el) => el.name === "w:tc");
27733
+ const content = [];
27734
+ let currentColumnIndex = 0;
27735
+ const fillUntil = (target, reason) => {
27736
+ currentColumnIndex = fillPlaceholderColumns({
27737
+ content,
27738
+ pendingRowSpans,
27739
+ currentIndex: currentColumnIndex,
27740
+ targetIndex: target,
27741
+ totalColumns,
27742
+ gridColumnWidths,
27743
+ reason
27744
+ });
27745
+ };
27746
+ const skipOccupiedColumns = () => {
27747
+ currentColumnIndex = advancePastRowSpans(pendingRowSpans, currentColumnIndex, totalColumns);
27748
+ };
27749
+ fillUntil(safeGridBefore, "gridBefore");
27750
+ skipOccupiedColumns();
27751
+ cellNodes?.forEach((node) => {
27752
+ skipOccupiedColumns();
27753
+ const startColumn = currentColumnIndex;
27754
+ const columnWidth = gridColumnWidths?.[startColumn] || null;
27755
+ const result = translator$H.encode({
27756
+ ...params2,
27757
+ extraParams: {
27758
+ ...params2.extraParams,
27759
+ node,
27760
+ columnIndex: startColumn,
27761
+ columnWidth
27762
+ }
27763
+ });
27764
+ if (result) {
27765
+ content.push(result);
27766
+ const colspan = Math.max(1, result.attrs?.colspan || 1);
27767
+ const rowspan = Math.max(1, result.attrs?.rowspan || 1);
27768
+ if (rowspan > 1) {
27769
+ for (let offset2 = 0; offset2 < colspan; offset2 += 1) {
27770
+ const target = startColumn + offset2;
27771
+ if (target < pendingRowSpans.length) {
27772
+ pendingRowSpans[target] = Math.max(pendingRowSpans[target], rowspan - 1);
27773
+ }
27774
+ }
27775
+ }
27776
+ currentColumnIndex = startColumn + colspan;
27777
+ }
27778
+ });
27779
+ skipOccupiedColumns();
27780
+ fillUntil(totalColumns, "gridAfter");
27781
+ const newNode = {
27782
+ type: "tableRow",
27783
+ content,
27784
+ attrs: encodedAttrs
27785
+ };
27786
+ return newNode;
27787
+ };
27788
+ const decode$n = (params2, decodedAttrs) => {
27789
+ const { node } = params2;
27790
+ const cells = node.content || [];
27791
+ let leadingPlaceholders = 0;
27792
+ while (leadingPlaceholders < cells.length && isPlaceholderCell(cells[leadingPlaceholders])) {
27793
+ leadingPlaceholders += 1;
27794
+ }
27795
+ let trailingPlaceholders = 0;
27796
+ while (trailingPlaceholders < cells.length - leadingPlaceholders && isPlaceholderCell(cells[cells.length - 1 - trailingPlaceholders])) {
27797
+ trailingPlaceholders += 1;
27798
+ }
27799
+ const trimmedSlice = cells.slice(leadingPlaceholders, cells.length - trailingPlaceholders);
27800
+ const sanitizedCells = trimmedSlice.map((cell) => {
27801
+ if (cell?.attrs && "__placeholder" in cell.attrs) {
27802
+ const { __placeholder, ...rest } = cell.attrs;
27803
+ return { ...cell, attrs: rest };
27804
+ }
27805
+ return cell;
27806
+ });
27807
+ const trimmedContent = sanitizedCells.filter((_2, index2) => !isPlaceholderCell(trimmedSlice[index2]));
27808
+ const translateParams = {
27809
+ ...params2,
27810
+ node: { ...node, content: trimmedContent }
27811
+ };
27812
+ const elements = translateChildNodes(translateParams);
27813
+ if (node.attrs?.tableRowProperties) {
27814
+ const tableRowProperties = { ...node.attrs.tableRowProperties };
27815
+ if (leadingPlaceholders > 0) {
27816
+ tableRowProperties.gridBefore = leadingPlaceholders;
27817
+ }
27818
+ if (trailingPlaceholders > 0) {
27819
+ tableRowProperties.gridAfter = trailingPlaceholders;
27820
+ }
27821
+ if (node.attrs.rowHeight != null) {
27822
+ const rowHeightPixels = twipsToPixels(node.attrs.tableRowProperties["rowHeight"]?.value);
27823
+ if (rowHeightPixels !== node.attrs.rowHeight) {
27824
+ tableRowProperties["rowHeight"] = { value: String(pixelsToTwips(node.attrs["rowHeight"])) };
27825
+ }
27826
+ }
27827
+ tableRowProperties["cantSplit"] = node.attrs["cantSplit"];
27828
+ const trPr = translator$v.decode({
27829
+ ...params2,
27830
+ node: { ...node, attrs: { ...node.attrs, tableRowProperties } }
27831
+ });
27832
+ if (trPr) elements.unshift(trPr);
27833
+ }
27834
+ return {
27835
+ name: "w:tr",
27836
+ attributes: decodedAttrs || {},
27837
+ elements
27838
+ };
27839
+ };
27840
+ const config$e = {
27841
+ xmlName: XML_NODE_NAME$f,
27842
+ sdNodeOrKeyName: SD_NODE_NAME$c,
27843
+ type: NodeTranslator.translatorTypes.NODE,
27844
+ encode: encode$l,
27845
+ decode: decode$n,
27846
+ attributes: validXmlAttributes$a
27847
+ };
27848
+ const translator$u = NodeTranslator.from(config$e);
27849
+ function parseTagValueJSON(json) {
27850
+ if (typeof json !== "string") {
27851
+ return {};
27852
+ }
27853
+ const trimmed = json.trim();
27854
+ if (!trimmed) {
27855
+ return {};
27856
+ }
27857
+ try {
27858
+ return JSON.parse(trimmed);
27859
+ } catch {
27860
+ return {};
27861
+ }
27862
+ }
27863
+ function handleAnnotationNode(params2) {
27864
+ const { nodes } = params2;
27865
+ if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
27866
+ return null;
27867
+ }
27868
+ const node = nodes[0];
27869
+ const sdtPr = node.elements.find((el) => el.name === "w:sdtPr");
27870
+ const sdtContent = node.elements.find((el) => el.name === "w:sdtContent");
27871
+ const sdtId = sdtPr?.elements?.find((el) => el.name === "w:id");
27872
+ const alias = sdtPr?.elements.find((el) => el.name === "w:alias");
27873
+ const tag = sdtPr?.elements.find((el) => el.name === "w:tag");
27874
+ const tagValue = tag?.attributes["w:val"];
27875
+ const shouldProcessAsJson = tagValue?.startsWith("{") && tagValue?.endsWith("}");
27876
+ let attrs = {};
27877
+ const aliasLabel = getSafeString(alias?.attributes?.["w:val"]);
27878
+ if (shouldProcessAsJson) {
27879
+ const parsedAttrs = parseTagValueJSON(tagValue);
27880
+ attrs = {
27881
+ type: parsedAttrs.fieldTypeShort,
27882
+ fieldId: parsedAttrs.fieldId,
27883
+ displayLabel: parsedAttrs.displayLabel,
27884
+ defaultDisplayLabel: parsedAttrs.defaultDisplayLabel,
27885
+ fieldType: parsedAttrs.fieldType,
27886
+ fieldColor: parsedAttrs.fieldColor,
27887
+ multipleImage: parsedAttrs.fieldMultipleImage,
27888
+ fontFamily: parsedAttrs.fieldFontFamily,
27889
+ fontSize: parsedAttrs.fieldFontSize,
27890
+ textColor: parsedAttrs.fieldTextColor,
27891
+ textHighlight: parsedAttrs.fieldTextHighlight,
27892
+ hash: parsedAttrs.hash
27893
+ };
27894
+ } else {
27895
+ attrs = getAttrsFromElements({ sdtPr, tag, alias, sdtId });
27896
+ }
27897
+ const initialDisplayLabel = getSafeString(attrs.displayLabel);
27898
+ const extractedContent = getTextFromSdtContent(sdtContent);
27899
+ if (!attrs.defaultDisplayLabel) {
27900
+ if (initialDisplayLabel) {
27901
+ attrs.defaultDisplayLabel = initialDisplayLabel;
27902
+ } else if (aliasLabel) {
27903
+ attrs.defaultDisplayLabel = aliasLabel;
27904
+ }
27905
+ }
27906
+ const placeholderLabel = getPlaceholderLabel(attrs, aliasLabel);
27907
+ const placeholderText = ensurePlaceholderFormat(placeholderLabel);
27908
+ const isAnnotationsEnabled = Boolean(params2.editor?.options?.annotations);
27909
+ const contentIsDistinct = shouldUseSdtContent(extractedContent, placeholderText);
27910
+ const shouldUseContent = !isAnnotationsEnabled && contentIsDistinct && (hasMoustache(extractedContent) || !placeholderText);
27911
+ if (contentIsDistinct) {
27912
+ attrs.displayLabel = extractedContent;
28563
27913
  } else if (!attrs.displayLabel && placeholderLabel) {
28564
27914
  attrs.displayLabel = placeholderLabel;
28565
27915
  }
@@ -28901,11 +28251,11 @@ function applyColorModifier(hexColor, modifier, value) {
28901
28251
  } else {
28902
28252
  return hexColor;
28903
28253
  }
28904
- const clamp = (n) => Math.max(0, Math.min(255, Math.round(n)));
28254
+ const clamp2 = (n) => Math.max(0, Math.min(255, Math.round(n)));
28905
28255
  const toHex2 = (n) => n.toString(16).padStart(2, "0");
28906
- newR = clamp(newR);
28907
- newG = clamp(newG);
28908
- newB = clamp(newB);
28256
+ newR = clamp2(newR);
28257
+ newG = clamp2(newG);
28258
+ newB = clamp2(newB);
28909
28259
  const result = `#${toHex2(newR)}${toHex2(newG)}${toHex2(newB)}`;
28910
28260
  return result;
28911
28261
  }
@@ -29818,32 +29168,32 @@ function translateAnchorNode(params2) {
29818
29168
  elements: [...anchorElements, ...elementsWithWrap]
29819
29169
  };
29820
29170
  }
29821
- const XML_NODE_NAME$c = "wp:anchor";
29822
- const SD_NODE_NAME$a = ["image"];
29171
+ const XML_NODE_NAME$e = "wp:anchor";
29172
+ const SD_NODE_NAME$b = ["image"];
29823
29173
  const validXmlAttributes$9 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
29824
- function encode$i(params2) {
29174
+ function encode$k(params2) {
29825
29175
  const { node } = params2.extraParams;
29826
29176
  if (!node || !node.type) {
29827
29177
  return null;
29828
29178
  }
29829
29179
  return handleAnchorNode(params2);
29830
29180
  }
29831
- function decode$k(params2) {
29181
+ function decode$m(params2) {
29832
29182
  const { node } = params2;
29833
29183
  if (!node || !node.type) {
29834
29184
  return null;
29835
29185
  }
29836
29186
  return translateAnchorNode(params2);
29837
29187
  }
29838
- const config$b = {
29839
- xmlName: XML_NODE_NAME$c,
29840
- sdNodeOrKeyName: SD_NODE_NAME$a,
29188
+ const config$d = {
29189
+ xmlName: XML_NODE_NAME$e,
29190
+ sdNodeOrKeyName: SD_NODE_NAME$b,
29841
29191
  type: NodeTranslator.translatorTypes.NODE,
29842
- encode: encode$i,
29843
- decode: decode$k,
29192
+ encode: encode$k,
29193
+ decode: decode$m,
29844
29194
  attributes: validXmlAttributes$9
29845
29195
  };
29846
- const translator$b = NodeTranslator.from(config$b);
29196
+ const translator$t = NodeTranslator.from(config$d);
29847
29197
  function handleInlineNode(params2) {
29848
29198
  const { node } = params2.extraParams;
29849
29199
  if (node.name !== "wp:inline") {
@@ -29859,41 +29209,41 @@ function translateInlineNode(params2) {
29859
29209
  elements: nodeElements.elements
29860
29210
  };
29861
29211
  }
29862
- const XML_NODE_NAME$b = "wp:inline";
29863
- const SD_NODE_NAME$9 = ["image"];
29212
+ const XML_NODE_NAME$d = "wp:inline";
29213
+ const SD_NODE_NAME$a = ["image"];
29864
29214
  const validXmlAttributes$8 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
29865
- function encode$h(params2) {
29215
+ function encode$j(params2) {
29866
29216
  const { node } = params2.extraParams;
29867
29217
  if (!node || !node.type) {
29868
29218
  return null;
29869
29219
  }
29870
29220
  return handleInlineNode(params2);
29871
29221
  }
29872
- function decode$j(params2) {
29222
+ function decode$l(params2) {
29873
29223
  const { node } = params2;
29874
29224
  if (!node || !node.type) {
29875
29225
  return null;
29876
29226
  }
29877
29227
  return translateInlineNode(params2);
29878
29228
  }
29879
- const config$a = {
29880
- xmlName: XML_NODE_NAME$b,
29881
- sdNodeOrKeyName: SD_NODE_NAME$9,
29229
+ const config$c = {
29230
+ xmlName: XML_NODE_NAME$d,
29231
+ sdNodeOrKeyName: SD_NODE_NAME$a,
29882
29232
  type: NodeTranslator.translatorTypes.NODE,
29883
- encode: encode$h,
29884
- decode: decode$j,
29233
+ encode: encode$j,
29234
+ decode: decode$l,
29885
29235
  attributes: validXmlAttributes$8
29886
29236
  };
29887
- const translator$a = NodeTranslator.from(config$a);
29888
- const XML_NODE_NAME$a = "w:drawing";
29889
- const SD_NODE_NAME$8 = [];
29237
+ const translator$s = NodeTranslator.from(config$c);
29238
+ const XML_NODE_NAME$c = "w:drawing";
29239
+ const SD_NODE_NAME$9 = [];
29890
29240
  const validXmlAttributes$7 = [];
29891
- function encode$g(params2) {
29241
+ function encode$i(params2) {
29892
29242
  const nodes = params2.nodes;
29893
29243
  const node = nodes[0];
29894
29244
  const translatorByChildName = {
29895
- "wp:anchor": translator$b,
29896
- "wp:inline": translator$a
29245
+ "wp:anchor": translator$t,
29246
+ "wp:inline": translator$s
29897
29247
  };
29898
29248
  return node.elements.reduce((acc, child) => {
29899
29249
  if (acc) return acc;
@@ -29902,12 +29252,12 @@ function encode$g(params2) {
29902
29252
  return translator2.encode({ ...params2, extraParams: { node: child } }) || acc;
29903
29253
  }, null);
29904
29254
  }
29905
- function decode$i(params2) {
29255
+ function decode$k(params2) {
29906
29256
  const { node } = params2;
29907
29257
  if (!node || !node.type) {
29908
29258
  return null;
29909
29259
  }
29910
- const childTranslator = node.attrs.isAnchor ? translator$b : translator$a;
29260
+ const childTranslator = node.attrs.isAnchor ? translator$t : translator$s;
29911
29261
  const resultNode = childTranslator.decode(params2);
29912
29262
  return wrapTextInRun(
29913
29263
  {
@@ -29917,15 +29267,15 @@ function decode$i(params2) {
29917
29267
  []
29918
29268
  );
29919
29269
  }
29920
- const config$9 = {
29921
- xmlName: XML_NODE_NAME$a,
29922
- sdNodeOrKeyName: SD_NODE_NAME$8,
29270
+ const config$b = {
29271
+ xmlName: XML_NODE_NAME$c,
29272
+ sdNodeOrKeyName: SD_NODE_NAME$9,
29923
29273
  type: NodeTranslator.translatorTypes.NODE,
29924
- encode: encode$g,
29925
- decode: decode$i,
29274
+ encode: encode$i,
29275
+ decode: decode$k,
29926
29276
  attributes: validXmlAttributes$7
29927
29277
  };
29928
- const translator$9 = NodeTranslator.from(config$9);
29278
+ const translator$r = NodeTranslator.from(config$b);
29929
29279
  class CommandService {
29930
29280
  /**
29931
29281
  * @param {import('./commands/types/index.js').CommandServiceOptions} props
@@ -31273,7 +30623,7 @@ function prepareTextAnnotation(params2) {
31273
30623
  return getTextNodeForExport(attrs.displayLabel, [...marks, ...marksFromAttrs], params2);
31274
30624
  }
31275
30625
  function prepareImageAnnotation(params2, imageSize) {
31276
- return translator$9.decode({
30626
+ return translator$r.decode({
31277
30627
  ...params2,
31278
30628
  imageSize
31279
30629
  });
@@ -31337,287 +30687,864 @@ function prepareUrlAnnotation(params2) {
31337
30687
  const linkTextNode = getTextNodeForExport(attrs.linkUrl, marks, params2);
31338
30688
  const contentNode = processLinkContentNode(linkTextNode);
31339
30689
  return {
31340
- name: "w:hyperlink",
31341
- type: "element",
31342
- attributes: {
31343
- "r:id": newId,
31344
- "w:history": 1
31345
- },
31346
- elements: [contentNode]
30690
+ name: "w:hyperlink",
30691
+ type: "element",
30692
+ attributes: {
30693
+ "r:id": newId,
30694
+ "w:history": 1
30695
+ },
30696
+ elements: [contentNode]
30697
+ };
30698
+ }
30699
+ function translateFieldAttrsToMarks(attrs = {}) {
30700
+ const { fontFamily: fontFamily2, fontSize: fontSize2, bold, underline, italic, textColor, textHighlight } = attrs;
30701
+ const marks = [];
30702
+ if (fontFamily2) marks.push({ type: "fontFamily", attrs: { fontFamily: fontFamily2 } });
30703
+ if (fontSize2) marks.push({ type: "fontSize", attrs: { fontSize: fontSize2 } });
30704
+ if (bold) marks.push({ type: "bold", attrs: {} });
30705
+ if (underline) marks.push({ type: "underline", attrs: {} });
30706
+ if (italic) marks.push({ type: "italic", attrs: {} });
30707
+ if (textColor) marks.push({ type: "color", attrs: { color: textColor } });
30708
+ if (textHighlight) marks.push({ type: "highlight", attrs: { color: textHighlight } });
30709
+ return marks;
30710
+ }
30711
+ function applyMarksToHtmlAnnotation(state2, marks) {
30712
+ const { tr, doc: doc2, schema } = state2;
30713
+ const allowedMarks = ["fontFamily", "fontSize", "highlight"];
30714
+ if (!marks.some((m2) => allowedMarks.includes(m2.type))) {
30715
+ return state2;
30716
+ }
30717
+ const fontFamily2 = marks.find((m2) => m2.type === "fontFamily");
30718
+ const fontSize2 = marks.find((m2) => m2.type === "fontSize");
30719
+ const highlight = marks.find((m2) => m2.type === "highlight");
30720
+ const textStyleType = schema.marks.textStyle;
30721
+ const highlightType = schema.marks.highlight;
30722
+ doc2.descendants((node, pos) => {
30723
+ if (!node.isText) return;
30724
+ const foundTextStyle = node.marks.find((m2) => m2.type.name === "textStyle");
30725
+ const foundHighlight = node.marks.find((m2) => m2.type.name === "highlight");
30726
+ if (!foundTextStyle) {
30727
+ tr.addMark(
30728
+ pos,
30729
+ pos + node.nodeSize,
30730
+ textStyleType.create({
30731
+ ...fontFamily2?.attrs,
30732
+ ...fontSize2?.attrs
30733
+ })
30734
+ );
30735
+ } else if (!foundTextStyle?.attrs.fontFamily && fontFamily2) {
30736
+ tr.addMark(
30737
+ pos,
30738
+ pos + node.nodeSize,
30739
+ textStyleType.create({
30740
+ ...foundTextStyle?.attrs,
30741
+ ...fontFamily2.attrs
30742
+ })
30743
+ );
30744
+ } else if (!foundTextStyle?.attrs.fontSize && fontSize2) {
30745
+ tr.addMark(
30746
+ pos,
30747
+ pos + node.nodeSize,
30748
+ textStyleType.create({
30749
+ ...foundTextStyle?.attrs,
30750
+ ...fontSize2.attrs
30751
+ })
30752
+ );
30753
+ }
30754
+ if (!foundHighlight) {
30755
+ tr.addMark(
30756
+ pos,
30757
+ pos + node.nodeSize,
30758
+ highlightType.create({
30759
+ ...highlight?.attrs
30760
+ })
30761
+ );
30762
+ }
30763
+ });
30764
+ return state2.apply(tr);
30765
+ }
30766
+ function getFieldHighlightJson(fieldsHighlightColor) {
30767
+ if (!fieldsHighlightColor) return null;
30768
+ let parsedColor = fieldsHighlightColor.trim();
30769
+ const hexRegex2 = /^#?([A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/;
30770
+ if (!hexRegex2.test(parsedColor)) {
30771
+ console.warn(`Invalid HEX color provided to fieldsHighlightColor export param: ${fieldsHighlightColor}`);
30772
+ return null;
30773
+ }
30774
+ if (parsedColor.startsWith("#")) {
30775
+ parsedColor = parsedColor.slice(1);
30776
+ }
30777
+ return {
30778
+ name: "w:rPr",
30779
+ elements: [
30780
+ {
30781
+ name: "w:shd",
30782
+ attributes: {
30783
+ "w:fill": `#${parsedColor}`,
30784
+ "w:color": "auto",
30785
+ "w:val": "clear"
30786
+ }
30787
+ }
30788
+ ]
30789
+ };
30790
+ }
30791
+ function translateDocumentSection(params2) {
30792
+ const { node } = params2;
30793
+ const { attrs = {} } = node;
30794
+ const childContent = translateChildNodes({ ...params2, nodes: node.content });
30795
+ const nodeElements = [
30796
+ {
30797
+ name: "w:sdtContent",
30798
+ elements: childContent
30799
+ }
30800
+ ];
30801
+ const exportedTag = JSON.stringify({
30802
+ type: "documentSection",
30803
+ description: attrs.description
30804
+ });
30805
+ const sdtPr = generateSdtPrTagForDocumentSection(attrs.id, attrs.title, exportedTag);
30806
+ const { isLocked } = attrs;
30807
+ if (isLocked) {
30808
+ sdtPr.elements.push({
30809
+ name: "w:lock",
30810
+ attributes: {
30811
+ "w:val": "sdtContentLocked"
30812
+ }
30813
+ });
30814
+ }
30815
+ nodeElements.unshift(sdtPr);
30816
+ const result = {
30817
+ name: "w:sdt",
30818
+ elements: nodeElements
30819
+ };
30820
+ return result;
30821
+ }
30822
+ const generateSdtPrTagForDocumentSection = (id, title, tag) => {
30823
+ return {
30824
+ name: "w:sdtPr",
30825
+ elements: [
30826
+ {
30827
+ name: "w:id",
30828
+ attributes: {
30829
+ "w:val": id
30830
+ }
30831
+ },
30832
+ {
30833
+ name: "w:alias",
30834
+ attributes: {
30835
+ "w:val": title
30836
+ }
30837
+ },
30838
+ {
30839
+ name: "w:tag",
30840
+ attributes: {
30841
+ "w:val": tag
30842
+ }
30843
+ }
30844
+ ]
30845
+ };
30846
+ };
30847
+ function translateDocumentPartObj(params2) {
30848
+ const { node } = params2;
30849
+ const { attrs = {} } = node;
30850
+ const childContent = translateChildNodes({ ...params2, nodes: node.content });
30851
+ const nodeElements = [
30852
+ {
30853
+ name: "w:sdtPr",
30854
+ elements: [
30855
+ {
30856
+ name: "w:id",
30857
+ attributes: {
30858
+ "w:val": attrs.id
30859
+ }
30860
+ },
30861
+ {
30862
+ name: "w:docPartObj",
30863
+ elements: [
30864
+ {
30865
+ name: "w:docPartGallery",
30866
+ attributes: {
30867
+ "w:val": attrs.docPartGallery
30868
+ }
30869
+ },
30870
+ ...attrs.docPartUnique ? [
30871
+ {
30872
+ name: "w:docPartUnique"
30873
+ }
30874
+ ] : []
30875
+ ]
30876
+ }
30877
+ ]
30878
+ },
30879
+ {
30880
+ name: "w:sdtContent",
30881
+ elements: childContent
30882
+ }
30883
+ ];
30884
+ const result = {
30885
+ name: "w:sdt",
30886
+ elements: nodeElements
30887
+ };
30888
+ return result;
30889
+ }
30890
+ function translateStructuredContent(params2) {
30891
+ const { node } = params2;
30892
+ const childContent = translateChildNodes({ ...params2, nodes: node.content });
30893
+ const sdtContent = { name: "w:sdtContent", elements: childContent };
30894
+ const sdtPr = generateSdtPrTagForStructuredContent({ node });
30895
+ const nodeElements = [sdtPr, sdtContent];
30896
+ const result = {
30897
+ name: "w:sdt",
30898
+ elements: nodeElements
30899
+ };
30900
+ return result;
30901
+ }
30902
+ function generateSdtPrTagForStructuredContent({ node }) {
30903
+ const { attrs = {} } = node;
30904
+ const id = {
30905
+ name: "w:id",
30906
+ type: "element",
30907
+ attributes: { "w:val": attrs.id }
30908
+ };
30909
+ const alias = {
30910
+ name: "w:alias",
30911
+ type: "element",
30912
+ attributes: { "w:val": attrs.alias }
30913
+ };
30914
+ const tag = {
30915
+ name: "w:tag",
30916
+ type: "element",
30917
+ attributes: { "w:val": attrs.tag }
30918
+ };
30919
+ const resultElements = [];
30920
+ if (attrs.id) resultElements.push(id);
30921
+ if (attrs.alias) resultElements.push(alias);
30922
+ if (attrs.tag) resultElements.push(tag);
30923
+ if (attrs.sdtPr) {
30924
+ const elements = attrs.sdtPr.elements || [];
30925
+ const elementsToExclude = ["w:id", "w:alias", "w:tag"];
30926
+ const restElements = elements.filter((el) => !elementsToExclude.includes(el.name));
30927
+ const result2 = {
30928
+ name: "w:sdtPr",
30929
+ type: "element",
30930
+ elements: [...resultElements, ...restElements]
30931
+ };
30932
+ return result2;
30933
+ }
30934
+ const result = {
30935
+ name: "w:sdtPr",
30936
+ type: "element",
30937
+ elements: resultElements
30938
+ };
30939
+ return result;
30940
+ }
30941
+ const XML_NODE_NAME$b = "w:sdt";
30942
+ const SD_NODE_NAME$8 = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
30943
+ const validXmlAttributes$6 = [];
30944
+ function encode$h(params2) {
30945
+ const nodes = params2.nodes;
30946
+ const node = nodes[0];
30947
+ const { type: sdtType, handler: handler2 } = sdtNodeTypeStrategy(node);
30948
+ if (!handler2 || sdtType === "unknown") {
30949
+ return void 0;
30950
+ }
30951
+ const result = handler2(params2);
30952
+ return result;
30953
+ }
30954
+ function decode$j(params2) {
30955
+ const { node } = params2;
30956
+ if (!node || !node.type) {
30957
+ return null;
30958
+ }
30959
+ const types2 = {
30960
+ fieldAnnotation: () => translateFieldAnnotation(params2),
30961
+ structuredContent: () => translateStructuredContent(params2),
30962
+ structuredContentBlock: () => translateStructuredContent(params2),
30963
+ documentSection: () => translateDocumentSection(params2),
30964
+ documentPartObject: () => translateDocumentPartObj(params2),
30965
+ // Handled in doc-part-obj translator
30966
+ default: () => null
30967
+ };
30968
+ const decoder = types2[node.type] ?? types2.default;
30969
+ const result = decoder();
30970
+ return result;
30971
+ }
30972
+ const config$a = {
30973
+ xmlName: XML_NODE_NAME$b,
30974
+ sdNodeOrKeyName: SD_NODE_NAME$8,
30975
+ type: NodeTranslator.translatorTypes.NODE,
30976
+ encode: encode$h,
30977
+ decode: decode$j,
30978
+ attributes: validXmlAttributes$6
30979
+ };
30980
+ const translator$q = NodeTranslator.from(config$a);
30981
+ function preProcessVerticalMergeCells(table, { editorSchema }) {
30982
+ if (!table || !Array.isArray(table.content)) {
30983
+ return table;
30984
+ }
30985
+ const rows = table.content;
30986
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
30987
+ const row = rows[rowIndex];
30988
+ if (!row) continue;
30989
+ if (!Array.isArray(row.content)) {
30990
+ row.content = [];
30991
+ }
30992
+ for (let cellIndex = 0; cellIndex < row.content.length; cellIndex++) {
30993
+ const cell = row.content[cellIndex];
30994
+ if (!cell) continue;
30995
+ const attrs = cell.attrs || {};
30996
+ if (!attrs.rowspan || attrs.rowspan <= 1) continue;
30997
+ const maxRowspan = Math.min(attrs.rowspan, rows.length - rowIndex);
30998
+ for (let offset2 = 1; offset2 < maxRowspan; offset2++) {
30999
+ const rowToChange = rows[rowIndex + offset2];
31000
+ if (!rowToChange) continue;
31001
+ if (!Array.isArray(rowToChange.content)) {
31002
+ rowToChange.content = [];
31003
+ }
31004
+ const existingCell = rowToChange.content[cellIndex];
31005
+ if (existingCell?.attrs?.continueMerge) continue;
31006
+ const mergedCell = {
31007
+ type: cell.type,
31008
+ content: [editorSchema.nodes.paragraph.createAndFill().toJSON()],
31009
+ attrs: {
31010
+ ...cell.attrs,
31011
+ rowspan: null,
31012
+ continueMerge: true
31013
+ }
31014
+ };
31015
+ rowToChange.content.splice(cellIndex, 0, mergedCell);
31016
+ }
31017
+ }
31018
+ }
31019
+ return table;
31020
+ }
31021
+ const translator$p = NodeTranslator.from({
31022
+ xmlName: "w:bidiVisual",
31023
+ sdNodeOrKeyName: "rightToLeft",
31024
+ encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
31025
+ decode: ({ node }) => node.attrs.rightToLeft ? { attributes: {} } : void 0
31026
+ });
31027
+ const translator$o = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblCaption", "caption"));
31028
+ const translator$n = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblDescription", "description"));
31029
+ const translator$m = NodeTranslator.from(createMeasurementPropertyHandler("w:tblInd", "tableIndent"));
31030
+ const translator$l = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblLayout", "tableLayout", "w:type"));
31031
+ const translator$k = NodeTranslator.from({
31032
+ xmlName: "w:tblLook",
31033
+ sdNodeOrKeyName: "tblLook",
31034
+ attributes: ["w:firstColumn", "w:firstRow", "w:lastColumn", "w:lastRow", "w:noHBand", "w:noVBand"].map((attr) => createAttributeHandler(attr, null, parseBoolean, booleanToString)).concat([createAttributeHandler("w:val")]),
31035
+ encode: (params2, encodedAttrs) => {
31036
+ return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
31037
+ },
31038
+ decode: function({ node }, context) {
31039
+ const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.tblLook || {} } });
31040
+ return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
31041
+ }
31042
+ });
31043
+ const translator$j = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblOverlap", "overlap"));
31044
+ const translator$i = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblStyle", "tableStyleId"));
31045
+ const translator$h = NodeTranslator.from(
31046
+ createSingleAttrPropertyHandler("w:tblStyleColBandSize", "tableStyleColBandSize")
31047
+ );
31048
+ const translator$g = NodeTranslator.from(
31049
+ createSingleAttrPropertyHandler("w:tblStyleRowBandSize", "tableStyleRowBandSize")
31050
+ );
31051
+ const translator$f = NodeTranslator.from(createMeasurementPropertyHandler("w:tblW", "tableWidth"));
31052
+ const translator$e = NodeTranslator.from({
31053
+ xmlName: "w:tblpPr",
31054
+ sdNodeOrKeyName: "floatingTableProperties",
31055
+ attributes: ["w:leftFromText", "w:rightFromText", "w:topFromText", "w:bottomFromText", "w:tblpX", "w:tblpY"].map((attr) => createAttributeHandler(attr, null, parseInteger, integerToString)).concat(["w:horzAnchor", "w:vertAnchor", "w:tblpXSpec", "w:tblpYSpec"].map((attr) => createAttributeHandler(attr))),
31056
+ encode: (params2, encodedAttrs) => {
31057
+ return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
31058
+ },
31059
+ decode: function({ node }, context) {
31060
+ const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.floatingTableProperties || {} } });
31061
+ return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
31062
+ }
31063
+ });
31064
+ const propertyTranslators$2 = [
31065
+ translator$15,
31066
+ translator$13,
31067
+ translator$11,
31068
+ translator$10,
31069
+ translator$$,
31070
+ translator$Z,
31071
+ translator$X,
31072
+ translator$V
31073
+ ];
31074
+ const translator$d = NodeTranslator.from(
31075
+ createNestedPropertiesTranslator("w:tblBorders", "borders", propertyTranslators$2)
31076
+ );
31077
+ const propertyTranslators$1 = [
31078
+ translator$14,
31079
+ translator$12,
31080
+ translator$_,
31081
+ translator$Y,
31082
+ translator$W,
31083
+ translator$U
31084
+ ];
31085
+ const translator$c = NodeTranslator.from(
31086
+ createNestedPropertiesTranslator("w:tblCellMar", "cellMargins", propertyTranslators$1)
31087
+ );
31088
+ const propertyTranslators = [
31089
+ translator$p,
31090
+ translator$B,
31091
+ translator$19,
31092
+ translator$o,
31093
+ translator$A,
31094
+ translator$n,
31095
+ translator$m,
31096
+ translator$l,
31097
+ translator$k,
31098
+ translator$j,
31099
+ translator$i,
31100
+ translator$h,
31101
+ translator$g,
31102
+ translator$f,
31103
+ translator$e,
31104
+ translator$d,
31105
+ translator$c
31106
+ ];
31107
+ const translator$b = NodeTranslator.from(
31108
+ createNestedPropertiesTranslator("w:tblPr", "tableProperties", propertyTranslators)
31109
+ );
31110
+ const translator$a = NodeTranslator.from(
31111
+ createSingleAttrPropertyHandler("w:gridCol", "col", "w:w", parseInteger, integerToString)
31112
+ );
31113
+ const DEFAULT_COLUMN_WIDTH_PX = 100;
31114
+ const normalizeTwipWidth = (value) => {
31115
+ if (value == null) return null;
31116
+ const numericValue = typeof value === "string" ? parseInt(value, 10) : value;
31117
+ if (!Number.isFinite(numericValue) || Number.isNaN(numericValue) || numericValue <= 0) {
31118
+ return null;
31119
+ }
31120
+ return numericValue;
31121
+ };
31122
+ const getSchemaDefaultColumnWidthPx = (params2) => {
31123
+ const defaultValue = params2?.editor?.schema?.nodes?.tableCell?.spec?.attrs?.colwidth?.default;
31124
+ if (Array.isArray(defaultValue)) {
31125
+ const numericWidth = defaultValue.find((width) => typeof width === "number" && Number.isFinite(width) && width > 0);
31126
+ if (numericWidth != null) return numericWidth;
31127
+ } else if (typeof defaultValue === "number" && Number.isFinite(defaultValue) && defaultValue > 0) {
31128
+ return defaultValue;
31129
+ }
31130
+ return DEFAULT_COLUMN_WIDTH_PX;
31131
+ };
31132
+ const getTableWidthPx = (params2) => {
31133
+ const explicitWidth = params2?.node?.attrs?.tableWidth?.width;
31134
+ if (typeof explicitWidth === "number" && explicitWidth > 0) return explicitWidth;
31135
+ const tableWidth = params2?.node?.attrs?.tableProperties?.tableWidth;
31136
+ if (tableWidth?.value != null && typeof tableWidth.value === "number" && tableWidth.value > 0) {
31137
+ const { value, type: type2 } = tableWidth;
31138
+ if (!type2 || type2 === "auto" || type2 === "dxa") {
31139
+ return twipsToPixels(value);
31140
+ }
31141
+ }
31142
+ return null;
31143
+ };
31144
+ const resolveFallbackColumnWidthTwips = (params2, totalColumns, cellMinWidthTwips) => {
31145
+ const columnCount = Math.max(totalColumns, 1);
31146
+ const defaultColumnWidthPx = getSchemaDefaultColumnWidthPx(params2);
31147
+ const tableWidthPx = getTableWidthPx(params2);
31148
+ const safeDefaultPx = Number.isFinite(defaultColumnWidthPx) && defaultColumnWidthPx > 0 ? defaultColumnWidthPx : DEFAULT_COLUMN_WIDTH_PX;
31149
+ let fallbackWidthPx = safeDefaultPx;
31150
+ if (typeof tableWidthPx === "number" && tableWidthPx > 0) {
31151
+ fallbackWidthPx = tableWidthPx / columnCount;
31152
+ }
31153
+ const fallbackWidthTwips = pixelsToTwips(fallbackWidthPx);
31154
+ if (!Number.isFinite(fallbackWidthTwips) || Number.isNaN(fallbackWidthTwips) || fallbackWidthTwips <= 0) {
31155
+ const safeDefault = Math.max(pixelsToTwips(safeDefaultPx), cellMinWidthTwips);
31156
+ return safeDefault;
31157
+ }
31158
+ return Math.max(fallbackWidthTwips, cellMinWidthTwips);
31159
+ };
31160
+ const XML_NODE_NAME$a = "w:tblGrid";
31161
+ const SD_ATTR_KEY$2 = "grid";
31162
+ const cellMinWidth = pixelsToTwips(10);
31163
+ const encode$g = (params2) => {
31164
+ const { nodes } = params2;
31165
+ const node = nodes[0];
31166
+ const attributes = encodeProperties(node, { [translator$a.xmlName]: translator$a }, true);
31167
+ return {
31168
+ xmlName: XML_NODE_NAME$a,
31169
+ sdNodeOrKeyName: SD_ATTR_KEY$2,
31170
+ attributes
31171
+ };
31172
+ };
31173
+ const decode$i = (params2) => {
31174
+ const { grid: rawGrid } = params2.node.attrs || {};
31175
+ const grid = Array.isArray(rawGrid) ? rawGrid : [];
31176
+ const { firstRow = {} } = params2.extraParams || {};
31177
+ const cellNodes = firstRow.content?.filter((n) => n.type === "tableCell") ?? [];
31178
+ const columnCountFromCells = cellNodes.reduce((count, cell) => {
31179
+ const spanCount = Math.max(1, cell?.attrs?.colspan ?? 1);
31180
+ return count + spanCount;
31181
+ }, 0);
31182
+ const totalColumns = Math.max(columnCountFromCells, grid.length);
31183
+ const fallbackColumnWidthTwips = resolveFallbackColumnWidthTwips(params2, totalColumns, cellMinWidth);
31184
+ const elements = [];
31185
+ let columnIndex = 0;
31186
+ const pushColumn = (widthTwips, { enforceMinimum = false } = {}) => {
31187
+ let numericWidth = typeof widthTwips === "string" ? parseInt(widthTwips, 10) : widthTwips;
31188
+ let shouldEnforceMinimum = enforceMinimum;
31189
+ if (numericWidth == null || Number.isNaN(numericWidth) || numericWidth <= 0) {
31190
+ numericWidth = fallbackColumnWidthTwips;
31191
+ shouldEnforceMinimum = true;
31192
+ }
31193
+ const roundedWidth = Math.round(numericWidth);
31194
+ const minimumWidth = shouldEnforceMinimum ? cellMinWidth : 1;
31195
+ const safeWidth = Math.max(roundedWidth, minimumWidth);
31196
+ const decoded = translator$a.decode({
31197
+ node: { type: (
31198
+ /** @type {string} */
31199
+ translator$a.sdNodeOrKeyName
31200
+ ), attrs: { col: safeWidth } }
31201
+ });
31202
+ if (decoded) elements.push(decoded);
31203
+ };
31204
+ cellNodes.forEach((cell) => {
31205
+ const { colspan = 1, colwidth } = cell?.attrs || {};
31206
+ const spanCount = Math.max(1, colspan);
31207
+ for (let span = 0; span < spanCount; span++) {
31208
+ const rawWidth = Array.isArray(colwidth) ? colwidth[span] : void 0;
31209
+ const cellWidthPixels = typeof rawWidth === "number" && Number.isFinite(rawWidth) ? rawWidth : Number(rawWidth);
31210
+ const hasCellWidth = Number.isFinite(cellWidthPixels) && cellWidthPixels > 0;
31211
+ const colGridAttrs = grid?.[columnIndex] || {};
31212
+ const gridWidthTwips = normalizeTwipWidth(colGridAttrs.col);
31213
+ const gridWidthPixels = gridWidthTwips != null ? twipsToPixels(gridWidthTwips) : null;
31214
+ let cellWidthTwips;
31215
+ let enforceMinimum = false;
31216
+ if (hasCellWidth) {
31217
+ const tolerance = 0.5;
31218
+ if (gridWidthTwips != null && gridWidthPixels != null && Math.abs(gridWidthPixels - cellWidthPixels) <= tolerance) {
31219
+ cellWidthTwips = gridWidthTwips;
31220
+ } else {
31221
+ cellWidthTwips = pixelsToTwips(cellWidthPixels);
31222
+ }
31223
+ } else if (gridWidthTwips != null) {
31224
+ cellWidthTwips = gridWidthTwips;
31225
+ } else {
31226
+ cellWidthTwips = fallbackColumnWidthTwips;
31227
+ enforceMinimum = true;
31228
+ }
31229
+ pushColumn(cellWidthTwips, { enforceMinimum });
31230
+ columnIndex++;
31231
+ }
31232
+ });
31233
+ while (columnIndex < grid.length) {
31234
+ const gridWidthTwips = normalizeTwipWidth(grid[columnIndex]?.col);
31235
+ pushColumn(gridWidthTwips);
31236
+ columnIndex++;
31237
+ }
31238
+ const newNode = {
31239
+ name: XML_NODE_NAME$a,
31240
+ attributes: {},
31241
+ elements
31242
+ };
31243
+ return newNode;
31244
+ };
31245
+ const config$9 = {
31246
+ xmlName: XML_NODE_NAME$a,
31247
+ sdNodeOrKeyName: SD_ATTR_KEY$2,
31248
+ encode: encode$g,
31249
+ decode: decode$i
31250
+ };
31251
+ const translator$9 = NodeTranslator.from(config$9);
31252
+ const DEFAULT_PAGE_WIDTH_TWIPS = 12240;
31253
+ const DEFAULT_PAGE_MARGIN_TWIPS = 1440;
31254
+ const DEFAULT_CONTENT_WIDTH_TWIPS = DEFAULT_PAGE_WIDTH_TWIPS - 2 * DEFAULT_PAGE_MARGIN_TWIPS;
31255
+ const MIN_COLUMN_WIDTH_TWIPS = pixelsToTwips(10);
31256
+ const pctToPercent = (value) => {
31257
+ if (value == null) return null;
31258
+ return value / 50;
31259
+ };
31260
+ const resolveContentWidthTwips = () => DEFAULT_CONTENT_WIDTH_TWIPS;
31261
+ const resolveMeasurementWidthPx = (measurement) => {
31262
+ if (!measurement || typeof measurement.value !== "number" || measurement.value <= 0) return null;
31263
+ const { value, type: type2 } = measurement;
31264
+ if (!type2 || type2 === "auto") return null;
31265
+ if (type2 === "dxa") return twipsToPixels(value);
31266
+ if (type2 === "pct") {
31267
+ const percent2 = pctToPercent(value);
31268
+ if (percent2 == null || percent2 <= 0) return null;
31269
+ const widthTwips = resolveContentWidthTwips() * percent2 / 100;
31270
+ return twipsToPixels(widthTwips);
31271
+ }
31272
+ return null;
31273
+ };
31274
+ const countColumnsInRow = (row) => {
31275
+ if (!row?.elements?.length) return 0;
31276
+ return row.elements.reduce((count, element) => {
31277
+ if (element.name !== "w:tc") return count;
31278
+ const tcPr = element.elements?.find((el) => el.name === "w:tcPr");
31279
+ const gridSpan = tcPr?.elements?.find((el) => el.name === "w:gridSpan");
31280
+ const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
31281
+ return count + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
31282
+ }, 0);
31283
+ };
31284
+ const clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS);
31285
+ const createFallbackGrid = (columnCount, columnWidthTwips) => Array.from({ length: columnCount }, () => ({ col: clampColumnWidthTwips(columnWidthTwips) }));
31286
+ const buildFallbackGridForTable = ({ params: params2, rows, tableWidth, tableWidthMeasurement }) => {
31287
+ const firstRow = rows.find((row) => row.elements?.some((el) => el.name === "w:tc"));
31288
+ const columnCount = countColumnsInRow(firstRow);
31289
+ if (!columnCount) return null;
31290
+ const schemaDefaultPx = getSchemaDefaultColumnWidthPx(
31291
+ /** @type {any} */
31292
+ params2
31293
+ );
31294
+ const minimumColumnWidthPx = Number.isFinite(schemaDefaultPx) && schemaDefaultPx > 0 ? schemaDefaultPx : DEFAULT_COLUMN_WIDTH_PX;
31295
+ let totalWidthPx;
31296
+ if (tableWidthMeasurement) {
31297
+ const resolved = resolveMeasurementWidthPx(tableWidthMeasurement);
31298
+ if (resolved != null) totalWidthPx = resolved;
31299
+ }
31300
+ if (totalWidthPx == null && tableWidth?.width && tableWidth.width > 0) {
31301
+ totalWidthPx = tableWidth.width;
31302
+ }
31303
+ if (totalWidthPx == null) {
31304
+ totalWidthPx = minimumColumnWidthPx * columnCount;
31305
+ }
31306
+ const rawColumnWidthPx = Math.max(totalWidthPx / columnCount, minimumColumnWidthPx);
31307
+ const columnWidthTwips = clampColumnWidthTwips(pixelsToTwips(rawColumnWidthPx));
31308
+ const fallbackColumnWidthPx = twipsToPixels(columnWidthTwips);
31309
+ return {
31310
+ grid: createFallbackGrid(columnCount, columnWidthTwips),
31311
+ columnWidths: Array(columnCount).fill(fallbackColumnWidthPx)
31347
31312
  };
31348
- }
31349
- function translateFieldAttrsToMarks(attrs = {}) {
31350
- const { fontFamily: fontFamily2, fontSize: fontSize2, bold, underline, italic, textColor, textHighlight } = attrs;
31351
- const marks = [];
31352
- if (fontFamily2) marks.push({ type: "fontFamily", attrs: { fontFamily: fontFamily2 } });
31353
- if (fontSize2) marks.push({ type: "fontSize", attrs: { fontSize: fontSize2 } });
31354
- if (bold) marks.push({ type: "bold", attrs: {} });
31355
- if (underline) marks.push({ type: "underline", attrs: {} });
31356
- if (italic) marks.push({ type: "italic", attrs: {} });
31357
- if (textColor) marks.push({ type: "color", attrs: { color: textColor } });
31358
- if (textHighlight) marks.push({ type: "highlight", attrs: { color: textHighlight } });
31359
- return marks;
31360
- }
31361
- function applyMarksToHtmlAnnotation(state2, marks) {
31362
- const { tr, doc: doc2, schema } = state2;
31363
- const allowedMarks = ["fontFamily", "fontSize", "highlight"];
31364
- if (!marks.some((m2) => allowedMarks.includes(m2.type))) {
31365
- return state2;
31313
+ };
31314
+ const XML_NODE_NAME$9 = "w:tbl";
31315
+ const SD_NODE_NAME$7 = "table";
31316
+ const encode$f = (params2, encodedAttrs) => {
31317
+ const { nodes } = params2;
31318
+ const node = nodes[0];
31319
+ const tblPr = node.elements.find((el) => el.name === "w:tblPr");
31320
+ if (tblPr) {
31321
+ const encodedProperties = translator$b.encode({ ...params2, nodes: [tblPr] });
31322
+ encodedAttrs["tableProperties"] = encodedProperties || {};
31366
31323
  }
31367
- const fontFamily2 = marks.find((m2) => m2.type === "fontFamily");
31368
- const fontSize2 = marks.find((m2) => m2.type === "fontSize");
31369
- const highlight = marks.find((m2) => m2.type === "highlight");
31370
- const textStyleType = schema.marks.textStyle;
31371
- const highlightType = schema.marks.highlight;
31372
- doc2.descendants((node, pos) => {
31373
- if (!node.isText) return;
31374
- const foundTextStyle = node.marks.find((m2) => m2.type.name === "textStyle");
31375
- const foundHighlight = node.marks.find((m2) => m2.type.name === "highlight");
31376
- if (!foundTextStyle) {
31377
- tr.addMark(
31378
- pos,
31379
- pos + node.nodeSize,
31380
- textStyleType.create({
31381
- ...fontFamily2?.attrs,
31382
- ...fontSize2?.attrs
31383
- })
31384
- );
31385
- } else if (!foundTextStyle?.attrs.fontFamily && fontFamily2) {
31386
- tr.addMark(
31387
- pos,
31388
- pos + node.nodeSize,
31389
- textStyleType.create({
31390
- ...foundTextStyle?.attrs,
31391
- ...fontFamily2.attrs
31392
- })
31393
- );
31394
- } else if (!foundTextStyle?.attrs.fontSize && fontSize2) {
31395
- tr.addMark(
31396
- pos,
31397
- pos + node.nodeSize,
31398
- textStyleType.create({
31399
- ...foundTextStyle?.attrs,
31400
- ...fontSize2.attrs
31401
- })
31402
- );
31324
+ const tblGrid = node.elements.find((el) => el.name === "w:tblGrid");
31325
+ if (tblGrid) {
31326
+ encodedAttrs["grid"] = translator$9.encode({ ...params2, nodes: [tblGrid] }).attributes;
31327
+ }
31328
+ [
31329
+ "tableStyleId",
31330
+ "justification",
31331
+ "tableLayout",
31332
+ ["tableIndent", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
31333
+ ["tableCellSpacing", ({ value, type: type2 }) => ({ w: String(value), type: type2 })]
31334
+ ].forEach((prop) => {
31335
+ let key2;
31336
+ let transform;
31337
+ if (Array.isArray(prop)) {
31338
+ [key2, transform] = prop;
31339
+ } else {
31340
+ key2 = prop;
31341
+ transform = (v2) => v2;
31403
31342
  }
31404
- if (!foundHighlight) {
31405
- tr.addMark(
31406
- pos,
31407
- pos + node.nodeSize,
31408
- highlightType.create({
31409
- ...highlight?.attrs
31410
- })
31411
- );
31343
+ if (encodedAttrs.tableProperties && encodedAttrs.tableProperties[key2]) {
31344
+ encodedAttrs[key2] = transform(encodedAttrs.tableProperties[key2]);
31412
31345
  }
31413
31346
  });
31414
- return state2.apply(tr);
31415
- }
31416
- function getFieldHighlightJson(fieldsHighlightColor) {
31417
- if (!fieldsHighlightColor) return null;
31418
- let parsedColor = fieldsHighlightColor.trim();
31419
- const hexRegex2 = /^#?([A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/;
31420
- if (!hexRegex2.test(parsedColor)) {
31421
- console.warn(`Invalid HEX color provided to fieldsHighlightColor export param: ${fieldsHighlightColor}`);
31422
- return null;
31347
+ if (encodedAttrs.tableCellSpacing) {
31348
+ encodedAttrs["borderCollapse"] = "separate";
31423
31349
  }
31424
- if (parsedColor.startsWith("#")) {
31425
- parsedColor = parsedColor.slice(1);
31350
+ if (encodedAttrs.tableProperties?.tableWidth) {
31351
+ const tableWidthMeasurement = encodedAttrs.tableProperties.tableWidth;
31352
+ const widthPx = twipsToPixels(tableWidthMeasurement.value);
31353
+ if (widthPx != null) {
31354
+ encodedAttrs.tableWidth = {
31355
+ width: widthPx,
31356
+ type: tableWidthMeasurement.type
31357
+ };
31358
+ } else if (tableWidthMeasurement.type === "auto") {
31359
+ encodedAttrs.tableWidth = {
31360
+ width: 0,
31361
+ type: tableWidthMeasurement.type
31362
+ };
31363
+ }
31426
31364
  }
31427
- return {
31428
- name: "w:rPr",
31429
- elements: [
31430
- {
31431
- name: "w:shd",
31432
- attributes: {
31433
- "w:fill": `#${parsedColor}`,
31434
- "w:color": "auto",
31435
- "w:val": "clear"
31365
+ const { borders, rowBorders } = _processTableBorders(encodedAttrs.tableProperties?.borders || {});
31366
+ const referencedStyles = _getReferencedTableStyles(encodedAttrs.tableStyleId, params2);
31367
+ if (referencedStyles?.cellMargins && !encodedAttrs.tableProperties?.cellMargins) {
31368
+ encodedAttrs.tableProperties = {
31369
+ ...encodedAttrs.tableProperties || {},
31370
+ cellMargins: referencedStyles.cellMargins
31371
+ };
31372
+ }
31373
+ const rows = node.elements.filter((el) => el.name === "w:tr");
31374
+ const borderData = Object.assign({}, referencedStyles?.borders || {}, borders || {});
31375
+ const borderRowData = Object.assign({}, referencedStyles?.rowBorders || {}, rowBorders || {});
31376
+ encodedAttrs["borders"] = borderData;
31377
+ let columnWidths = Array.isArray(encodedAttrs["grid"]) ? encodedAttrs["grid"].map((item) => twipsToPixels(item.col)) : [];
31378
+ if (!columnWidths.length) {
31379
+ const fallback = buildFallbackGridForTable({
31380
+ params: params2,
31381
+ rows,
31382
+ tableWidth: encodedAttrs.tableWidth,
31383
+ tableWidthMeasurement: encodedAttrs.tableProperties?.tableWidth
31384
+ });
31385
+ if (fallback) {
31386
+ encodedAttrs.grid = fallback.grid;
31387
+ columnWidths = fallback.columnWidths;
31388
+ }
31389
+ }
31390
+ const content = [];
31391
+ const totalColumns = columnWidths.length;
31392
+ const activeRowSpans = totalColumns > 0 ? new Array(totalColumns).fill(0) : [];
31393
+ rows.forEach((row, rowIndex) => {
31394
+ const result = translator$u.encode({
31395
+ ...params2,
31396
+ nodes: [row],
31397
+ extraParams: {
31398
+ row,
31399
+ table: node,
31400
+ rowBorders: borderRowData,
31401
+ columnWidths,
31402
+ activeRowSpans: activeRowSpans.slice(),
31403
+ rowIndex,
31404
+ _referencedStyles: referencedStyles
31405
+ }
31406
+ });
31407
+ if (result) {
31408
+ content.push(result);
31409
+ if (totalColumns > 0) {
31410
+ const activeRowSpansForCurrentRow = activeRowSpans.slice();
31411
+ for (let col = 0; col < totalColumns; col++) {
31412
+ if (activeRowSpans[col] > 0) {
31413
+ activeRowSpans[col] -= 1;
31414
+ }
31436
31415
  }
31416
+ let columnIndex = 0;
31417
+ const advanceColumnIndex = () => {
31418
+ while (columnIndex < totalColumns && activeRowSpansForCurrentRow[columnIndex] > 0) {
31419
+ columnIndex += 1;
31420
+ }
31421
+ };
31422
+ advanceColumnIndex();
31423
+ result.content?.forEach((cell) => {
31424
+ advanceColumnIndex();
31425
+ const colspan = Math.max(1, cell.attrs?.colspan || 1);
31426
+ const rowspan = Math.max(1, cell.attrs?.rowspan || 1);
31427
+ if (rowspan > 1) {
31428
+ for (let offset2 = 0; offset2 < colspan && columnIndex + offset2 < totalColumns; offset2++) {
31429
+ const targetIndex = columnIndex + offset2;
31430
+ const remainingRows = rowspan - 1;
31431
+ if (remainingRows > 0 && remainingRows > activeRowSpans[targetIndex]) {
31432
+ activeRowSpans[targetIndex] = remainingRows;
31433
+ }
31434
+ }
31435
+ }
31436
+ columnIndex += colspan;
31437
+ advanceColumnIndex();
31438
+ });
31437
31439
  }
31438
- ]
31440
+ }
31441
+ });
31442
+ return {
31443
+ type: "table",
31444
+ content,
31445
+ attrs: encodedAttrs
31439
31446
  };
31440
- }
31441
- function translateDocumentSection(params2) {
31447
+ };
31448
+ const decode$h = (params2, decodedAttrs) => {
31449
+ params2.node = preProcessVerticalMergeCells(params2.node, params2);
31442
31450
  const { node } = params2;
31443
- const { attrs = {} } = node;
31444
- const childContent = translateChildNodes({ ...params2, nodes: node.content });
31445
- const nodeElements = [
31446
- {
31447
- name: "w:sdtContent",
31448
- elements: childContent
31451
+ const elements = translateChildNodes(params2);
31452
+ const firstRow = node.content?.find((n) => n.type === "tableRow");
31453
+ const properties = node.attrs.grid;
31454
+ const element = translator$9.decode({
31455
+ ...params2,
31456
+ node: { ...node, attrs: { ...node.attrs, grid: properties } },
31457
+ extraParams: {
31458
+ firstRow
31449
31459
  }
31450
- ];
31451
- const exportedTag = JSON.stringify({
31452
- type: "documentSection",
31453
- description: attrs.description
31454
31460
  });
31455
- const sdtPr = generateSdtPrTagForDocumentSection(attrs.id, attrs.title, exportedTag);
31456
- const { isLocked } = attrs;
31457
- if (isLocked) {
31458
- sdtPr.elements.push({
31459
- name: "w:lock",
31460
- attributes: {
31461
- "w:val": "sdtContentLocked"
31462
- }
31461
+ if (element) elements.unshift(element);
31462
+ if (node.attrs?.tableProperties) {
31463
+ const properties2 = { ...node.attrs.tableProperties };
31464
+ const element2 = translator$b.decode({
31465
+ ...params2,
31466
+ node: { ...node, attrs: { ...node.attrs, tableProperties: properties2 } }
31463
31467
  });
31468
+ if (element2) elements.unshift(element2);
31464
31469
  }
31465
- nodeElements.unshift(sdtPr);
31466
- const result = {
31467
- name: "w:sdt",
31468
- elements: nodeElements
31469
- };
31470
- return result;
31471
- }
31472
- const generateSdtPrTagForDocumentSection = (id, title, tag) => {
31473
31470
  return {
31474
- name: "w:sdtPr",
31475
- elements: [
31476
- {
31477
- name: "w:id",
31478
- attributes: {
31479
- "w:val": id
31480
- }
31481
- },
31482
- {
31483
- name: "w:alias",
31484
- attributes: {
31485
- "w:val": title
31486
- }
31487
- },
31488
- {
31489
- name: "w:tag",
31490
- attributes: {
31491
- "w:val": tag
31492
- }
31493
- }
31494
- ]
31471
+ name: "w:tbl",
31472
+ attributes: decodedAttrs || {},
31473
+ elements
31495
31474
  };
31496
31475
  };
31497
- function translateDocumentPartObj(params2) {
31498
- const { node } = params2;
31499
- const { attrs = {} } = node;
31500
- const childContent = translateChildNodes({ ...params2, nodes: node.content });
31501
- const nodeElements = [
31502
- {
31503
- name: "w:sdtPr",
31504
- elements: [
31505
- {
31506
- name: "w:id",
31507
- attributes: {
31508
- "w:val": attrs.id
31509
- }
31510
- },
31511
- {
31512
- name: "w:docPartObj",
31513
- elements: [
31514
- {
31515
- name: "w:docPartGallery",
31516
- attributes: {
31517
- "w:val": attrs.docPartGallery
31518
- }
31519
- },
31520
- ...attrs.docPartUnique ? [
31521
- {
31522
- name: "w:docPartUnique"
31523
- }
31524
- ] : []
31525
- ]
31526
- }
31527
- ]
31528
- },
31529
- {
31530
- name: "w:sdtContent",
31531
- elements: childContent
31532
- }
31533
- ];
31534
- const result = {
31535
- name: "w:sdt",
31536
- elements: nodeElements
31537
- };
31538
- return result;
31539
- }
31540
- function translateStructuredContent(params2) {
31541
- const { node } = params2;
31542
- const childContent = translateChildNodes({ ...params2, nodes: node.content });
31543
- const sdtContent = { name: "w:sdtContent", elements: childContent };
31544
- const sdtPr = generateSdtPrTagForStructuredContent({ node });
31545
- const nodeElements = [sdtPr, sdtContent];
31546
- const result = {
31547
- name: "w:sdt",
31548
- elements: nodeElements
31476
+ function _processTableBorders(rawBorders) {
31477
+ const borders = {};
31478
+ const rowBorders = {};
31479
+ Object.entries(rawBorders).forEach(([name, attributes]) => {
31480
+ const attrs = {};
31481
+ const color = attributes.color;
31482
+ const size2 = attributes.size;
31483
+ if (color && color !== "auto") attrs["color"] = color.startsWith("#") ? color : `#${color}`;
31484
+ if (size2 && size2 !== "auto") attrs["size"] = eighthPointsToPixels(size2);
31485
+ const rowBorderNames = ["insideH", "insideV"];
31486
+ if (rowBorderNames.includes(name)) rowBorders[name] = attrs;
31487
+ borders[name] = attrs;
31488
+ });
31489
+ return {
31490
+ borders,
31491
+ rowBorders
31549
31492
  };
31550
- return result;
31551
31493
  }
31552
- function generateSdtPrTagForStructuredContent({ node }) {
31553
- const { attrs = {} } = node;
31554
- const id = {
31555
- name: "w:id",
31556
- type: "element",
31557
- attributes: { "w:val": attrs.id }
31558
- };
31559
- const alias = {
31560
- name: "w:alias",
31561
- type: "element",
31562
- attributes: { "w:val": attrs.alias }
31563
- };
31564
- const tag = {
31565
- name: "w:tag",
31566
- type: "element",
31567
- attributes: { "w:val": attrs.tag }
31568
- };
31569
- const resultElements = [];
31570
- if (attrs.id) resultElements.push(id);
31571
- if (attrs.alias) resultElements.push(alias);
31572
- if (attrs.tag) resultElements.push(tag);
31573
- if (attrs.sdtPr) {
31574
- const elements = attrs.sdtPr.elements || [];
31575
- const elementsToExclude = ["w:id", "w:alias", "w:tag"];
31576
- const restElements = elements.filter((el) => !elementsToExclude.includes(el.name));
31577
- const result2 = {
31578
- name: "w:sdtPr",
31579
- type: "element",
31580
- elements: [...resultElements, ...restElements]
31581
- };
31582
- return result2;
31494
+ function _getReferencedTableStyles(tableStyleReference, params2) {
31495
+ if (!tableStyleReference) return null;
31496
+ const stylesToReturn = {};
31497
+ const { docx } = params2;
31498
+ const styles = docx["word/styles.xml"];
31499
+ const { elements } = styles.elements[0];
31500
+ const styleElements = elements.filter((el) => el.name === "w:style");
31501
+ const styleTag = styleElements.find((el) => el.attributes["w:styleId"] === tableStyleReference);
31502
+ if (!styleTag) return null;
31503
+ stylesToReturn.name = styleTag.elements.find((el) => el.name === "w:name");
31504
+ const basedOn = styleTag.elements.find((el) => el.name === "w:basedOn");
31505
+ let baseTblPr;
31506
+ if (basedOn?.attributes) {
31507
+ const baseStyles = styleElements.find((el) => el.attributes["w:styleId"] === basedOn.attributes["w:val"]);
31508
+ baseTblPr = baseStyles ? baseStyles.elements.find((el) => el.name === "w:tblPr") : {};
31583
31509
  }
31584
- const result = {
31585
- name: "w:sdtPr",
31586
- type: "element",
31587
- elements: resultElements
31588
- };
31589
- return result;
31590
- }
31591
- const XML_NODE_NAME$9 = "w:sdt";
31592
- const SD_NODE_NAME$7 = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
31593
- const validXmlAttributes$6 = [];
31594
- function encode$f(params2) {
31595
- const nodes = params2.nodes;
31596
- const node = nodes[0];
31597
- const { type: sdtType, handler: handler2 } = sdtNodeTypeStrategy(node);
31598
- if (!handler2 || sdtType === "unknown") {
31599
- return void 0;
31510
+ const pPr = styleTag.elements.find((el) => el.name === "w:pPr");
31511
+ if (pPr) {
31512
+ const justification = pPr.elements.find((el) => el.name === "w:jc");
31513
+ if (justification?.attributes) stylesToReturn.justification = justification.attributes["w:val"];
31600
31514
  }
31601
- const result = handler2(params2);
31602
- return result;
31603
- }
31604
- function decode$h(params2) {
31605
- const { node } = params2;
31606
- if (!node || !node.type) {
31607
- return null;
31515
+ const rPr = styleTag?.elements.find((el) => el.name === "w:rPr");
31516
+ if (rPr) {
31517
+ const fonts = rPr.elements.find((el) => el.name === "w:rFonts");
31518
+ if (fonts) {
31519
+ const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
31520
+ stylesToReturn.fonts = { ascii, hAnsi, cs };
31521
+ }
31522
+ const fontSize2 = rPr.elements.find((el) => el.name === "w:sz");
31523
+ if (fontSize2?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize2.attributes["w:val"]) + "pt";
31608
31524
  }
31609
- const types2 = {
31610
- fieldAnnotation: () => translateFieldAnnotation(params2),
31611
- structuredContent: () => translateStructuredContent(params2),
31612
- structuredContentBlock: () => translateStructuredContent(params2),
31613
- documentSection: () => translateDocumentSection(params2),
31614
- documentPartObject: () => translateDocumentPartObj(params2),
31615
- // Handled in doc-part-obj translator
31616
- default: () => null
31617
- };
31618
- const decoder = types2[node.type] ?? types2.default;
31619
- const result = decoder();
31620
- return result;
31525
+ const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
31526
+ if (tblPr && tblPr.elements) {
31527
+ if (baseTblPr && baseTblPr.elements) {
31528
+ tblPr.elements.push(...baseTblPr.elements);
31529
+ }
31530
+ const tableProperties = translator$b.encode({ ...params2, nodes: [tblPr] });
31531
+ if (tableProperties) {
31532
+ const { borders, rowBorders } = _processTableBorders(tableProperties.borders || {});
31533
+ if (borders) stylesToReturn.borders = borders;
31534
+ if (rowBorders) stylesToReturn.rowBorders = rowBorders;
31535
+ const cellMargins = {};
31536
+ Object.entries(tableProperties.cellMargins || {}).forEach(([key2, attrs]) => {
31537
+ if (attrs?.value != null) {
31538
+ cellMargins[key2] = {
31539
+ value: attrs.value,
31540
+ type: attrs.type || "dxa"
31541
+ };
31542
+ }
31543
+ });
31544
+ if (Object.keys(cellMargins).length) stylesToReturn.cellMargins = cellMargins;
31545
+ }
31546
+ }
31547
+ return stylesToReturn;
31621
31548
  }
31622
31549
  const config$8 = {
31623
31550
  xmlName: XML_NODE_NAME$9,
@@ -31625,7 +31552,7 @@ const config$8 = {
31625
31552
  type: NodeTranslator.translatorTypes.NODE,
31626
31553
  encode: encode$f,
31627
31554
  decode: decode$h,
31628
- attributes: validXmlAttributes$6
31555
+ attributes: []
31629
31556
  };
31630
31557
  const translator$8 = NodeTranslator.from(config$8);
31631
31558
  const encode$e = (attributes) => {
@@ -32140,7 +32067,7 @@ const handleDrawingNode = (params2) => {
32140
32067
  if (mainNode.name === "w:drawing") node = mainNode;
32141
32068
  else node = mainNode.elements.find((el) => el.name === "w:drawing");
32142
32069
  if (!node) return { nodes: [], consumed: 0 };
32143
- const schemaNode = translator$9.encode(params2);
32070
+ const schemaNode = translator$r.encode(params2);
32144
32071
  const newNodes = schemaNode ? [schemaNode] : [];
32145
32072
  return { nodes: newNodes, consumed: 1 };
32146
32073
  };
@@ -32449,7 +32376,7 @@ const handleSdtNode = (params2) => {
32449
32376
  if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
32450
32377
  return { nodes: [], consumed: 0 };
32451
32378
  }
32452
- const result = translator$8.encode(params2);
32379
+ const result = translator$q.encode(params2);
32453
32380
  if (!result) {
32454
32381
  return { nodes: [], consumed: 0 };
32455
32382
  }
@@ -33243,6 +33170,7 @@ const tabNodeEntityHandler = {
33243
33170
  handlerName: "w:tabTranslator",
33244
33171
  handler: handleTabNode
33245
33172
  };
33173
+ const tableNodeHandlerEntity = generateV2HandlerEntity("tableNodeHandler", translator$8);
33246
33174
  const tableOfContentsHandlerEntity = generateV2HandlerEntity("tableOfContentsHandler", translator$4);
33247
33175
  function preProcessPageInstruction(nodesToCombine) {
33248
33176
  const pageNumNode = {
@@ -34252,14 +34180,14 @@ function exportSchemaToJson(params2) {
34252
34180
  bulletList: translateList,
34253
34181
  orderedList: translateList,
34254
34182
  lineBreak: translator$1r,
34255
- table: translator$s,
34256
- tableRow: translator$Z,
34257
- tableCell: translator$c,
34183
+ table: translator$8,
34184
+ tableRow: translator$u,
34185
+ tableCell: translator$H,
34258
34186
  bookmarkStart: translator$7,
34259
34187
  bookmarkEnd: translator$6,
34260
- fieldAnnotation: translator$8,
34188
+ fieldAnnotation: translator$q,
34261
34189
  tab: translator$1p,
34262
- image: translator$9,
34190
+ image: translator$r,
34263
34191
  hardBreak: translator$1r,
34264
34192
  commentRangeStart: commentRangeStartTranslator,
34265
34193
  commentRangeEnd: commentRangeEndTranslator,
@@ -34268,10 +34196,10 @@ function exportSchemaToJson(params2) {
34268
34196
  shapeTextbox: translator,
34269
34197
  contentBlock: translator,
34270
34198
  vectorShape: translateVectorShape,
34271
- structuredContent: translator$8,
34272
- structuredContentBlock: translator$8,
34273
- documentPartObject: translator$8,
34274
- documentSection: translator$8,
34199
+ structuredContent: translator$q,
34200
+ structuredContentBlock: translator$q,
34201
+ documentPartObject: translator$q,
34202
+ documentSection: translator$q,
34275
34203
  "page-number": translatePageNumberNode,
34276
34204
  "total-page-number": translateTotalPageNumberNode,
34277
34205
  pageReference: translator$5,
@@ -36005,7 +35933,7 @@ exportProcessNewRelationships_fn = function(rels = []) {
36005
35933
  });
36006
35934
  relationships.elements = [...relationships.elements, ...newRels];
36007
35935
  };
36008
- exportProcessMediaFiles_fn = async function(media = {}, editor) {
35936
+ exportProcessMediaFiles_fn = async function(media = {}) {
36009
35937
  const processedData = {
36010
35938
  ...this.convertedXml.media || {}
36011
35939
  };
@@ -43772,6 +43700,8 @@ function readDOMChange(view, from2, to, typeOver, addedNodes) {
43772
43700
  let deflt = () => mkTr(view.state.tr.insertText(text, chFrom, chTo));
43773
43701
  if (!view.someProp("handleTextInput", (f2) => f2(view, chFrom, chTo, text, deflt)))
43774
43702
  view.dispatch(deflt());
43703
+ } else {
43704
+ view.dispatch(mkTr());
43775
43705
  }
43776
43706
  } else {
43777
43707
  view.dispatch(mkTr());
@@ -48969,6 +48899,49 @@ const restoreSelection = () => ({ editor, state: state2, tr }) => {
48969
48899
  editor.view.dispatch(selectionTr);
48970
48900
  }
48971
48901
  };
48902
+ const clamp = (value, min2, max2) => Math.max(min2, Math.min(value, max2));
48903
+ const setTextSelection = ({ from: from2, to }) => ({ state: state2, dispatch, editor }) => {
48904
+ if (typeof from2 !== "number" && typeof to !== "number") {
48905
+ return false;
48906
+ }
48907
+ const doc2 = state2.doc;
48908
+ const docSize = doc2.content.size;
48909
+ const nextFrom = clamp(typeof from2 === "number" ? from2 : state2.selection.from, 0, docSize);
48910
+ const nextToBase = typeof to === "number" ? to : nextFrom;
48911
+ const nextTo = clamp(nextToBase, 0, docSize);
48912
+ const [head, anchor] = nextFrom <= nextTo ? [nextFrom, nextTo] : [nextTo, nextFrom];
48913
+ const selection = TextSelection$1.create(doc2, head, anchor);
48914
+ if (dispatch) {
48915
+ const transaction = state2.tr.setSelection(selection);
48916
+ dispatch(transaction);
48917
+ }
48918
+ if (editor?.view?.focus) {
48919
+ editor.view.focus();
48920
+ }
48921
+ return true;
48922
+ };
48923
+ const getSelectionMarks = () => ({ state: state2, tr }) => {
48924
+ tr.setMeta("preventDispatch", true);
48925
+ const marks = getMarksFromSelection(state2) ?? [];
48926
+ const uniqueByType = /* @__PURE__ */ new Map();
48927
+ for (const mark of marks) {
48928
+ const typeName = typeof mark?.type === "string" ? mark.type : mark?.type?.name;
48929
+ if (!typeName) continue;
48930
+ const existing = uniqueByType.get(typeName);
48931
+ if (!existing) {
48932
+ uniqueByType.set(typeName, mark);
48933
+ continue;
48934
+ }
48935
+ const existingAttrs = existing?.attrs ?? {};
48936
+ const nextAttrs = mark?.attrs ?? {};
48937
+ const existingHasValues = Object.values(existingAttrs).some((value) => value != null);
48938
+ const nextHasValues = Object.values(nextAttrs).some((value) => value != null);
48939
+ if (!existingHasValues && nextHasValues) {
48940
+ uniqueByType.set(typeName, mark);
48941
+ }
48942
+ }
48943
+ return Array.from(uniqueByType.values());
48944
+ };
48972
48945
  const commands$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
48973
48946
  __proto__: null,
48974
48947
  atVisualParaEnd,
@@ -48984,6 +48957,7 @@ const commands$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
48984
48957
  first,
48985
48958
  getEffectiveStyleId,
48986
48959
  getParaCtx,
48960
+ getSelectionMarks,
48987
48961
  getStyleIdFromMarks,
48988
48962
  handleBackspaceNextToList,
48989
48963
  handleDeleteNextToList,
@@ -49015,6 +48989,7 @@ const commands$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
49015
48989
  setMark,
49016
48990
  setMeta,
49017
48991
  setNode,
48992
+ setTextSelection,
49018
48993
  sinkListItem,
49019
48994
  splitBlock: splitBlock$1,
49020
48995
  splitListItem,
@@ -49679,6 +49654,7 @@ const markInsertion = ({ tr, from: from2, to, user, date }) => {
49679
49654
  id,
49680
49655
  author: user.name,
49681
49656
  authorEmail: user.email,
49657
+ authorImage: user.image,
49682
49658
  date
49683
49659
  });
49684
49660
  tr.addMark(from2, to, insertionMark);
@@ -49715,6 +49691,7 @@ const markDeletion = ({ tr, from: from2, to, user, date, id: providedId }) => {
49715
49691
  id,
49716
49692
  author: user.name,
49717
49693
  authorEmail: user.email,
49694
+ authorImage: user.image,
49718
49695
  date
49719
49696
  });
49720
49697
  const deletionMap = new Mapping();
@@ -50411,6 +50388,9 @@ const normalizeCommentEventPayload = ({ conversation, editorOptions, fallbackCom
50411
50388
  if (!normalized.creatorEmail && user?.email) {
50412
50389
  normalized.creatorEmail = user.email;
50413
50390
  }
50391
+ if (!normalized.creatorImage && user?.image) {
50392
+ normalized.creatorImage = user.image;
50393
+ }
50414
50394
  if (!normalized.createdTime) {
50415
50395
  normalized.createdTime = Date.now();
50416
50396
  }
@@ -50869,7 +50849,7 @@ const createOrUpdateTrackedChangeComment = ({ event, marks, deletionNodes, nodes
50869
50849
  const trackedMark = marks.insertedMark || marks.deletionMark || marks.formatMark;
50870
50850
  const { type: type2, attrs } = trackedMark;
50871
50851
  const { name: trackedChangeType } = type2;
50872
- const { author, authorEmail, date, importedAuthor } = attrs;
50852
+ const { author, authorEmail, authorImage, date, importedAuthor } = attrs;
50873
50853
  const id = attrs.id;
50874
50854
  const node = nodes[0];
50875
50855
  const isDeletionInsertion = !!(marks.insertedMark && marks.deletionMark);
@@ -50900,6 +50880,7 @@ const createOrUpdateTrackedChangeComment = ({ event, marks, deletionNodes, nodes
50900
50880
  deletedText: marks.deletionMark ? deletionText : null,
50901
50881
  author,
50902
50882
  authorEmail,
50883
+ ...authorImage && { authorImage },
50903
50884
  date,
50904
50885
  ...importedAuthor && {
50905
50886
  importedAuthor: {
@@ -51044,6 +51025,7 @@ const addMarkStep = ({ state: state2, step, newTr, doc: doc2, user, date }) => {
51044
51025
  id: wid,
51045
51026
  author: user.name,
51046
51027
  authorEmail: user.email,
51028
+ authorImage: user.image,
51047
51029
  date,
51048
51030
  before,
51049
51031
  after
@@ -51109,6 +51091,7 @@ const removeMarkStep = ({ state: state2, step, newTr, doc: doc2, user, date }) =
51109
51091
  id: v4(),
51110
51092
  author: user.name,
51111
51093
  authorEmail: user.email,
51094
+ authorImage: user.image,
51112
51095
  date,
51113
51096
  before,
51114
51097
  after
@@ -55108,6 +55091,9 @@ class GapBookmark {
55108
55091
  return GapCursor.valid($pos) ? new GapCursor($pos) : Selection.near($pos);
55109
55092
  }
55110
55093
  }
55094
+ function needsGap(type2) {
55095
+ return type2.isAtom || type2.spec.isolating || type2.spec.createGapCursor;
55096
+ }
55111
55097
  function closedBefore($pos) {
55112
55098
  for (let d2 = $pos.depth; d2 >= 0; d2--) {
55113
55099
  let index2 = $pos.index(d2), parent = $pos.node(d2);
@@ -55117,7 +55103,7 @@ function closedBefore($pos) {
55117
55103
  continue;
55118
55104
  }
55119
55105
  for (let before = parent.child(index2 - 1); ; before = before.lastChild) {
55120
- if (before.childCount == 0 && !before.inlineContent || before.isAtom || before.type.spec.isolating)
55106
+ if (before.childCount == 0 && !before.inlineContent || needsGap(before.type))
55121
55107
  return true;
55122
55108
  if (before.inlineContent)
55123
55109
  return false;
@@ -55134,7 +55120,7 @@ function closedAfter($pos) {
55134
55120
  continue;
55135
55121
  }
55136
55122
  for (let after = parent.child(index2); ; after = after.firstChild) {
55137
- if (after.childCount == 0 && !after.inlineContent || after.isAtom || after.type.spec.isolating)
55123
+ if (after.childCount == 0 && !after.inlineContent || needsGap(after.type))
55138
55124
  return true;
55139
55125
  if (after.inlineContent)
55140
55126
  return false;
@@ -70019,6 +70005,16 @@ const TrackInsert = Mark2.create({
70019
70005
  };
70020
70006
  }
70021
70007
  },
70008
+ authorImage: {
70009
+ default: "",
70010
+ parseDOM: (elem) => elem.getAttribute("data-authorimage"),
70011
+ renderDOM: (attrs) => {
70012
+ if (!attrs.authorImage) return {};
70013
+ return {
70014
+ "data-authorimage": attrs.authorImage
70015
+ };
70016
+ }
70017
+ },
70022
70018
  date: {
70023
70019
  default: "",
70024
70020
  parseDOM: (elem) => elem.getAttribute("data-date"),
@@ -70086,6 +70082,16 @@ const TrackDelete = Mark2.create({
70086
70082
  };
70087
70083
  }
70088
70084
  },
70085
+ authorImage: {
70086
+ default: "",
70087
+ parseDOM: (elem) => elem.getAttribute("data-authorimage"),
70088
+ renderDOM: (attrs) => {
70089
+ if (!attrs.authorImage) return {};
70090
+ return {
70091
+ "data-authorimage": attrs.authorImage
70092
+ };
70093
+ }
70094
+ },
70089
70095
  date: {
70090
70096
  default: "",
70091
70097
  parseDOM: (elem) => elem.getAttribute("data-date"),
@@ -70185,6 +70191,16 @@ const TrackFormat = Mark2.create({
70185
70191
  };
70186
70192
  }
70187
70193
  },
70194
+ authorImage: {
70195
+ default: "",
70196
+ parseDOM: (elem) => elem.getAttribute("data-authorimage"),
70197
+ renderDOM: (attrs) => {
70198
+ if (!attrs.authorImage) return {};
70199
+ return {
70200
+ "data-authorimage": attrs.authorImage
70201
+ };
70202
+ }
70203
+ },
70188
70204
  date: {
70189
70205
  default: "",
70190
70206
  parseDOM: (elem) => elem.getAttribute("data-date"),
@@ -91838,86 +91854,86 @@ const additionalHandlers = Object.freeze({
91838
91854
  "sd:pageReference": translator$5,
91839
91855
  "sd:tableOfContents": translator$4,
91840
91856
  "w:b": translator$1n,
91841
- "w:bidiVisual": translator$Y,
91857
+ "w:bidiVisual": translator$p,
91842
91858
  "w:bookmarkEnd": translator$6,
91843
91859
  "w:bookmarkStart": translator$7,
91844
- "w:bottom": translator$L,
91860
+ "w:bottom": translator$15,
91845
91861
  "w:br": translator$1r,
91846
- "w:cantSplit": translator$1a,
91847
- "w:cnfStyle": translator$19,
91862
+ "w:cantSplit": translator$G,
91863
+ "w:cnfStyle": translator$1a,
91848
91864
  "w:color": translator$1j,
91849
- "w:divId": translator$18,
91850
- "w:drawing": translator$9,
91851
- "w:end": translator$J,
91852
- "w:gridAfter": translator$17,
91853
- "w:gridBefore": translator$16,
91854
- "w:gridCol": translator$u,
91855
- "w:hidden": translator$15,
91865
+ "w:divId": translator$F,
91866
+ "w:drawing": translator$r,
91867
+ "w:end": translator$13,
91868
+ "w:gridAfter": translator$E,
91869
+ "w:gridBefore": translator$D,
91870
+ "w:gridCol": translator$a,
91871
+ "w:hidden": translator$C,
91856
91872
  "w:highlight": translator$1q,
91857
91873
  "w:hyperlink": translator$1c,
91858
91874
  "w:i": translator$1m,
91859
- "w:insideH": translator$H,
91860
- "w:insideV": translator$G,
91861
- "w:jc": translator$14,
91862
- "w:left": translator$F,
91875
+ "w:insideH": translator$11,
91876
+ "w:insideV": translator$10,
91877
+ "w:jc": translator$B,
91878
+ "w:left": translator$$,
91863
91879
  "w:p": translator$1o,
91864
91880
  "w:r": translator$1b,
91865
91881
  "w:rFonts": translator$1i,
91866
91882
  "w:rPr": translator$1d,
91867
91883
  "w:rStyle": translator$1h,
91868
- "w:right": translator$D,
91869
- "w:sdt": translator$8,
91870
- "w:shd": translator$X,
91871
- "w:start": translator$B,
91884
+ "w:right": translator$Z,
91885
+ "w:sdt": translator$q,
91886
+ "w:shd": translator$19,
91887
+ "w:start": translator$X,
91872
91888
  "w:strike": translator$1k,
91873
91889
  "w:sz": translator$1g,
91874
91890
  "w:szCs": translator$1f,
91875
91891
  "w:tab": translator$1p,
91876
- "w:tbl": translator$s,
91877
- "w:tblBorders": translator$x,
91878
- "w:tblCaption": translator$W,
91879
- "w:tblCellMar": translator$w,
91880
- "w:tblCellSpacing": translator$13,
91881
- "w:tblDescription": translator$V,
91882
- "w:tblGrid": translator$t,
91883
- "w:tblHeader": translator$12,
91884
- "w:tblInd": translator$U,
91885
- "w:tblLayout": translator$T,
91886
- "w:tblLook": translator$S,
91887
- "w:tblOverlap": translator$R,
91888
- "w:tblPr": translator$v,
91889
- "w:tblStyle": translator$Q,
91890
- "w:tblStyleColBandSize": translator$P,
91891
- "w:tblStyleRowBandSize": translator$O,
91892
- "w:tblW": translator$N,
91893
- "w:tblpPr": translator$M,
91894
- "w:tc": translator$c,
91895
- "w:top": translator$z,
91896
- "w:tr": translator$Z,
91897
- "w:trHeight": translator$11,
91898
- "w:trPr": translator$_,
91892
+ "w:tbl": translator$8,
91893
+ "w:tblBorders": translator$d,
91894
+ "w:tblCaption": translator$o,
91895
+ "w:tblCellMar": translator$c,
91896
+ "w:tblCellSpacing": translator$A,
91897
+ "w:tblDescription": translator$n,
91898
+ "w:tblGrid": translator$9,
91899
+ "w:tblHeader": translator$z,
91900
+ "w:tblInd": translator$m,
91901
+ "w:tblLayout": translator$l,
91902
+ "w:tblLook": translator$k,
91903
+ "w:tblOverlap": translator$j,
91904
+ "w:tblPr": translator$b,
91905
+ "w:tblStyle": translator$i,
91906
+ "w:tblStyleColBandSize": translator$h,
91907
+ "w:tblStyleRowBandSize": translator$g,
91908
+ "w:tblW": translator$f,
91909
+ "w:tblpPr": translator$e,
91910
+ "w:tc": translator$H,
91911
+ "w:top": translator$V,
91912
+ "w:tr": translator$u,
91913
+ "w:trHeight": translator$y,
91914
+ "w:trPr": translator$v,
91899
91915
  "w:u": translator$1l,
91900
- "w:wAfter": translator$10,
91901
- "w:wBefore": translator$$,
91902
- "wp:anchor": translator$b,
91903
- "wp:inline": translator$a,
91916
+ "w:wAfter": translator$x,
91917
+ "w:wBefore": translator$w,
91918
+ "wp:anchor": translator$t,
91919
+ "wp:inline": translator$s,
91904
91920
  "w:commentRangeStart": commentRangeStartTranslator,
91905
91921
  "w:commentRangeEnd": commentRangeEndTranslator,
91906
- "w:vMerge": translator$p,
91907
- "w:gridSpan": translator$q,
91908
- "w:vAlign": translator$h,
91909
- "w:noWrap": translator$l,
91910
- "w:tcFitText": translator$i,
91911
- "w:tcW": translator$r,
91912
- "w:hideMark": translator$g,
91913
- "w:textDirection": translator$j,
91914
- "w:tl2br": translator$o,
91915
- "w:tr2bl": translator$n,
91916
- "w:header": translator$f,
91917
- "w:headers": translator$e,
91918
- "w:tcBorders": translator$m,
91919
- "w:tcMar": translator$k,
91920
- "w:tcPr": translator$d
91922
+ "w:vMerge": translator$16,
91923
+ "w:gridSpan": translator$17,
91924
+ "w:vAlign": translator$M,
91925
+ "w:noWrap": translator$Q,
91926
+ "w:tcFitText": translator$N,
91927
+ "w:tcW": translator$18,
91928
+ "w:hideMark": translator$L,
91929
+ "w:textDirection": translator$O,
91930
+ "w:tl2br": translator$T,
91931
+ "w:tr2bl": translator$S,
91932
+ "w:header": translator$K,
91933
+ "w:headers": translator$J,
91934
+ "w:tcBorders": translator$R,
91935
+ "w:tcMar": translator$P,
91936
+ "w:tcPr": translator$I
91921
91937
  });
91922
91938
  const baseHandlers = {
91923
91939
  ...runPropertyTranslators,