@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
@@ -18,9 +18,9 @@ var lookup = [];
18
18
  var revLookup = [];
19
19
  var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
20
20
  var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
21
- for (var i$1 = 0, len = code.length; i$1 < len; ++i$1) {
22
- lookup[i$1] = code[i$1];
23
- revLookup[code.charCodeAt(i$1)] = i$1;
21
+ for (var i = 0, len = code.length; i < len; ++i) {
22
+ lookup[i] = code[i];
23
+ revLookup[code.charCodeAt(i)] = i;
24
24
  }
25
25
  revLookup["-".charCodeAt(0)] = 62;
26
26
  revLookup["_".charCodeAt(0)] = 63;
@@ -11328,39 +11328,37 @@ function requireLib() {
11328
11328
  }
11329
11329
  var libExports = requireLib();
11330
11330
  const xmljs = /* @__PURE__ */ getDefaultExportFromCjs$2(libExports);
11331
- var getRandomValues;
11332
- var rnds8 = new Uint8Array(16);
11331
+ let getRandomValues;
11332
+ const rnds8 = new Uint8Array(16);
11333
11333
  function rng() {
11334
11334
  if (!getRandomValues) {
11335
- getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== "undefined" && typeof msCrypto.getRandomValues === "function" && msCrypto.getRandomValues.bind(msCrypto);
11335
+ getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
11336
11336
  if (!getRandomValues) {
11337
11337
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
11338
11338
  }
11339
11339
  }
11340
11340
  return getRandomValues(rnds8);
11341
11341
  }
11342
- 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;
11343
- function validate(uuid) {
11344
- return typeof uuid === "string" && REGEX.test(uuid);
11342
+ const byteToHex = [];
11343
+ for (let i = 0; i < 256; ++i) {
11344
+ byteToHex.push((i + 256).toString(16).slice(1));
11345
11345
  }
11346
- var byteToHex = [];
11347
- for (var i = 0; i < 256; ++i) {
11348
- byteToHex.push((i + 256).toString(16).substr(1));
11349
- }
11350
- function stringify(arr) {
11351
- var offset = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
11352
- var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
11353
- if (!validate(uuid)) {
11354
- throw TypeError("Stringified UUID is invalid");
11355
- }
11356
- return uuid;
11346
+ function unsafeStringify(arr, offset = 0) {
11347
+ return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
11357
11348
  }
11349
+ const randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
11350
+ const native = {
11351
+ randomUUID
11352
+ };
11358
11353
  function v4(options, buf, offset) {
11354
+ if (native.randomUUID && true && !options) {
11355
+ return native.randomUUID();
11356
+ }
11359
11357
  options = options || {};
11360
- var rnds = options.random || (options.rng || rng)();
11358
+ const rnds = options.random || (options.rng || rng)();
11361
11359
  rnds[6] = rnds[6] & 15 | 64;
11362
11360
  rnds[8] = rnds[8] & 63 | 128;
11363
- return stringify(rnds);
11361
+ return unsafeStringify(rnds);
11364
11362
  }
11365
11363
  function getDefaultExportFromCjs(x) {
11366
11364
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
@@ -14413,6 +14411,7 @@ class ParseContext {
14413
14411
  addTextNode(dom, marks) {
14414
14412
  let value = dom.nodeValue;
14415
14413
  let top = this.top, preserveWS = top.options & OPT_PRESERVE_WS_FULL ? "full" : this.localPreserveWS || (top.options & OPT_PRESERVE_WS) > 0;
14414
+ let { schema } = this.parser;
14416
14415
  if (preserveWS === "full" || top.inlineContext(dom) || /[^ \t\r\n\u000c]/.test(value)) {
14417
14416
  if (!preserveWS) {
14418
14417
  value = value.replace(/[ \t\r\n\u000c]+/g, " ");
@@ -14422,13 +14421,22 @@ class ParseContext {
14422
14421
  if (!nodeBefore || domNodeBefore && domNodeBefore.nodeName == "BR" || nodeBefore.isText && /[ \t\r\n\u000c]$/.test(nodeBefore.text))
14423
14422
  value = value.slice(1);
14424
14423
  }
14425
- } else if (preserveWS !== "full") {
14426
- value = value.replace(/\r?\n|\r/g, " ");
14427
- } else {
14424
+ } else if (preserveWS === "full") {
14428
14425
  value = value.replace(/\r\n?/g, "\n");
14426
+ } else if (schema.linebreakReplacement && /[\r\n]/.test(value) && this.top.findWrapping(schema.linebreakReplacement.create())) {
14427
+ let lines = value.split(/\r?\n|\r/);
14428
+ for (let i = 0; i < lines.length; i++) {
14429
+ if (i)
14430
+ this.insertNode(schema.linebreakReplacement.create(), marks, true);
14431
+ if (lines[i])
14432
+ this.insertNode(schema.text(lines[i]), marks, !/\S/.test(lines[i]));
14433
+ }
14434
+ value = "";
14435
+ } else {
14436
+ value = value.replace(/\r?\n|\r/g, " ");
14429
14437
  }
14430
14438
  if (value)
14431
- this.insertNode(this.parser.schema.text(value), marks, !/\S/.test(value));
14439
+ this.insertNode(schema.text(value), marks, !/\S/.test(value));
14432
14440
  this.findInText(dom);
14433
14441
  } else {
14434
14442
  this.findInside(dom);
@@ -18988,7 +18996,6 @@ class Transaction extends Transform {
18988
18996
  } else {
18989
18997
  if (to == null)
18990
18998
  to = from;
18991
- to = to == null ? from : to;
18992
18999
  if (!text)
18993
19000
  return this.deleteRange(from, to);
18994
19001
  let marks = this.storedMarks;
@@ -18997,7 +19004,7 @@ class Transaction extends Transform {
18997
19004
  marks = to == from ? $from.marks() : $from.marksAcross(this.doc.resolve(to));
18998
19005
  }
18999
19006
  this.replaceRangeWith(from, to, schema.text(text, marks));
19000
- if (!this.selection.empty)
19007
+ if (!this.selection.empty && this.selection.to == from + text.length)
19001
19008
  this.setSelection(Selection.near(this.selection.$to));
19002
19009
  return this;
19003
19010
  }
@@ -19189,7 +19196,7 @@ class EditorState {
19189
19196
  return newInstance;
19190
19197
  }
19191
19198
  /**
19192
- Start a [transaction](https://prosemirror.net/docs/ref/#state.Transaction) from this state.
19199
+ Accessor that constructs and returns a new [transaction](https://prosemirror.net/docs/ref/#state.Transaction) from this state.
19193
19200
  */
19194
19201
  get tr() {
19195
19202
  return new Transaction(this);
@@ -26997,53 +27004,7 @@ const config$h = {
26997
27004
  attributes: validXmlAttributes$c
26998
27005
  };
26999
27006
  const translator$1b = NodeTranslator.from(config$h);
27000
- function preProcessVerticalMergeCells(table, { editorSchema }) {
27001
- if (!table || !Array.isArray(table.content)) {
27002
- return table;
27003
- }
27004
- const rows = table.content;
27005
- for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
27006
- const row = rows[rowIndex];
27007
- if (!row) continue;
27008
- if (!Array.isArray(row.content)) {
27009
- row.content = [];
27010
- }
27011
- for (let cellIndex = 0; cellIndex < row.content.length; cellIndex++) {
27012
- const cell = row.content[cellIndex];
27013
- if (!cell) continue;
27014
- const attrs = cell.attrs || {};
27015
- if (!attrs.rowspan || attrs.rowspan <= 1) continue;
27016
- const maxRowspan = Math.min(attrs.rowspan, rows.length - rowIndex);
27017
- for (let offset = 1; offset < maxRowspan; offset++) {
27018
- const rowToChange = rows[rowIndex + offset];
27019
- if (!rowToChange) continue;
27020
- if (!Array.isArray(rowToChange.content)) {
27021
- rowToChange.content = [];
27022
- }
27023
- const existingCell = rowToChange.content[cellIndex];
27024
- if (existingCell?.attrs?.continueMerge) continue;
27025
- const mergedCell = {
27026
- type: cell.type,
27027
- content: [editorSchema.nodes.paragraph.createAndFill().toJSON()],
27028
- attrs: {
27029
- ...cell.attrs,
27030
- rowspan: null,
27031
- continueMerge: true
27032
- }
27033
- };
27034
- rowToChange.content.splice(cellIndex, 0, mergedCell);
27035
- }
27036
- }
27037
- }
27038
- return table;
27039
- }
27040
27007
  const translator$1a = NodeTranslator.from({
27041
- xmlName: "w:cantSplit",
27042
- sdNodeOrKeyName: "cantSplit",
27043
- encode: ({ nodes }) => ["1", "true"].includes(nodes[0].attributes?.["w:val"] ?? "1"),
27044
- decode: ({ node }) => node.attrs?.cantSplit ? { attributes: {} } : void 0
27045
- });
27046
- const translator$19 = NodeTranslator.from({
27047
27008
  xmlName: "w:cnfStyle",
27048
27009
  sdNodeOrKeyName: "cnfStyle",
27049
27010
  attributes: [
@@ -27069,299 +27030,7 @@ const translator$19 = NodeTranslator.from({
27069
27030
  return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
27070
27031
  }
27071
27032
  });
27072
- const translator$18 = NodeTranslator.from(createSingleAttrPropertyHandler("w:divId"));
27073
- const translator$17 = NodeTranslator.from(
27074
- createSingleAttrPropertyHandler(
27075
- "w:gridAfter",
27076
- null,
27077
- "w:val",
27078
- (v2) => parseInteger(v2) ?? void 0,
27079
- (v2) => integerToString(v2)
27080
- )
27081
- );
27082
- const translator$16 = NodeTranslator.from(
27083
- createSingleAttrPropertyHandler(
27084
- "w:gridBefore",
27085
- null,
27086
- "w:val",
27087
- (v2) => parseInteger(v2) ?? void 0,
27088
- (v2) => integerToString(v2)
27089
- )
27090
- );
27091
- const translator$15 = NodeTranslator.from({
27092
- xmlName: "w:hidden",
27093
- sdNodeOrKeyName: "hidden",
27094
- encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
27095
- decode: ({ node }) => node.attrs.hidden ? { attributes: {} } : void 0
27096
- });
27097
- const translator$14 = NodeTranslator.from(createSingleAttrPropertyHandler("w:jc", "justification"));
27098
- const translator$13 = NodeTranslator.from(createMeasurementPropertyHandler("w:tblCellSpacing", "tableCellSpacing"));
27099
- const translator$12 = NodeTranslator.from({
27100
- xmlName: "w:tblHeader",
27101
- sdNodeOrKeyName: "repeatHeader",
27102
- encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
27103
- decode: ({ node }) => node.attrs.repeatHeader ? { attributes: {} } : void 0
27104
- });
27105
- const translator$11 = NodeTranslator.from({
27106
- xmlName: "w:trHeight",
27107
- sdNodeOrKeyName: "rowHeight",
27108
- encode: ({ nodes }) => {
27109
- const heightAttrs = {};
27110
- const val = nodes[0].attributes["w:val"];
27111
- if (val) {
27112
- heightAttrs["value"] = parseInt(val, 10);
27113
- }
27114
- const rule = nodes[0].attributes["w:hRule"];
27115
- if (rule) {
27116
- heightAttrs["rule"] = rule;
27117
- }
27118
- return Object.keys(heightAttrs).length > 0 ? heightAttrs : void 0;
27119
- },
27120
- decode: ({ node }) => {
27121
- if (!node.attrs?.rowHeight) return;
27122
- const heightAttrs = {};
27123
- if (typeof node.attrs.rowHeight.value === "number" && !isNaN(node.attrs.rowHeight.value)) {
27124
- heightAttrs["w:val"] = String(node.attrs.rowHeight.value);
27125
- }
27126
- if (node.attrs.rowHeight.rule) {
27127
- heightAttrs["w:hRule"] = node.attrs.rowHeight.rule;
27128
- }
27129
- return Object.keys(heightAttrs).length > 0 ? { attributes: heightAttrs } : void 0;
27130
- }
27131
- });
27132
- const translator$10 = NodeTranslator.from(createMeasurementPropertyHandler("w:wAfter"));
27133
- const translator$$ = NodeTranslator.from(createMeasurementPropertyHandler("w:wBefore"));
27134
- const propertyTranslators$6 = [
27135
- translator$1a,
27136
- translator$19,
27137
- translator$18,
27138
- translator$17,
27139
- translator$16,
27140
- translator$15,
27141
- translator$14,
27142
- translator$13,
27143
- translator$12,
27144
- translator$11,
27145
- translator$10,
27146
- translator$$
27147
- ];
27148
- const translator$_ = NodeTranslator.from(
27149
- createNestedPropertiesTranslator("w:trPr", "tableRowProperties", propertyTranslators$6, {
27150
- cantSplit: false,
27151
- hidden: false,
27152
- repeatHeader: false
27153
- })
27154
- );
27155
- const createPlaceholderCell = (gridWidth, reason) => {
27156
- const safeWidth = Number.isFinite(gridWidth) ? gridWidth : 0;
27157
- const noBorder = { val: "none", size: 0 };
27158
- return {
27159
- type: "tableCell",
27160
- attrs: {
27161
- colspan: 1,
27162
- rowspan: 1,
27163
- colwidth: [safeWidth],
27164
- __placeholder: reason,
27165
- borders: {
27166
- top: { ...noBorder },
27167
- right: { ...noBorder },
27168
- bottom: { ...noBorder },
27169
- left: { ...noBorder }
27170
- }
27171
- },
27172
- content: [{ type: "paragraph", content: [] }]
27173
- };
27174
- };
27175
- const advancePastRowSpans = (pendingRowSpans, startIndex, totalColumns) => {
27176
- let index2 = startIndex;
27177
- while (index2 < totalColumns && pendingRowSpans[index2] > 0) {
27178
- pendingRowSpans[index2] -= 1;
27179
- index2 += 1;
27180
- }
27181
- return index2;
27182
- };
27183
- const fillPlaceholderColumns = ({
27184
- content,
27185
- pendingRowSpans,
27186
- currentIndex,
27187
- targetIndex,
27188
- totalColumns,
27189
- gridColumnWidths,
27190
- reason
27191
- }) => {
27192
- let index2 = currentIndex;
27193
- while (index2 < targetIndex && index2 < totalColumns) {
27194
- if (pendingRowSpans[index2] > 0) {
27195
- pendingRowSpans[index2] -= 1;
27196
- index2 += 1;
27197
- continue;
27198
- }
27199
- const width = Array.isArray(gridColumnWidths) ? gridColumnWidths[index2] ?? 0 : 0;
27200
- content.push(createPlaceholderCell(width, reason));
27201
- index2 += 1;
27202
- }
27203
- return index2;
27204
- };
27205
- const isPlaceholderCell = (cell) => {
27206
- if (!cell) return false;
27207
- if (cell.attrs?.__placeholder) return true;
27208
- const widths = cell.attrs?.colwidth;
27209
- if (Array.isArray(widths) && widths.length > 0) {
27210
- const hasMeaningfulWidth = widths.some(
27211
- (value) => typeof value === "number" && Number.isFinite(value) && Math.abs(value) > 1
27212
- );
27213
- if (!hasMeaningfulWidth) return true;
27214
- }
27215
- return false;
27216
- };
27217
- const XML_NODE_NAME$h = "w:tr";
27218
- const SD_NODE_NAME$d = "tableRow";
27219
- const validXmlAttributes$b = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
27220
- (xmlName) => createAttributeHandler(xmlName)
27221
- );
27222
- const encode$n = (params, encodedAttrs) => {
27223
- const { row } = params.extraParams;
27224
- let tableRowProperties = {};
27225
- const tPr = row.elements.find((el) => el.name === "w:trPr");
27226
- if (tPr) {
27227
- tableRowProperties = translator$_.encode({
27228
- ...params,
27229
- nodes: [tPr]
27230
- });
27231
- }
27232
- const gridBeforeRaw = tableRowProperties?.["gridBefore"];
27233
- const safeGridBefore = typeof gridBeforeRaw === "number" && Number.isFinite(gridBeforeRaw) && gridBeforeRaw > 0 ? gridBeforeRaw : 0;
27234
- encodedAttrs["tableRowProperties"] = Object.freeze(tableRowProperties);
27235
- encodedAttrs["rowHeight"] = twipsToPixels(tableRowProperties["rowHeight"]?.value);
27236
- encodedAttrs["cantSplit"] = tableRowProperties["cantSplit"];
27237
- const { columnWidths: gridColumnWidths, activeRowSpans = [] } = params.extraParams;
27238
- const totalColumns = Array.isArray(gridColumnWidths) ? gridColumnWidths.length : 0;
27239
- const pendingRowSpans = Array.isArray(activeRowSpans) ? activeRowSpans.slice() : [];
27240
- while (pendingRowSpans.length < totalColumns) pendingRowSpans.push(0);
27241
- const cellNodes = row.elements.filter((el) => el.name === "w:tc");
27242
- const content = [];
27243
- let currentColumnIndex = 0;
27244
- const fillUntil = (target, reason) => {
27245
- currentColumnIndex = fillPlaceholderColumns({
27246
- content,
27247
- pendingRowSpans,
27248
- currentIndex: currentColumnIndex,
27249
- targetIndex: target,
27250
- totalColumns,
27251
- gridColumnWidths,
27252
- reason
27253
- });
27254
- };
27255
- const skipOccupiedColumns = () => {
27256
- currentColumnIndex = advancePastRowSpans(pendingRowSpans, currentColumnIndex, totalColumns);
27257
- };
27258
- fillUntil(safeGridBefore, "gridBefore");
27259
- skipOccupiedColumns();
27260
- cellNodes?.forEach((node) => {
27261
- skipOccupiedColumns();
27262
- const startColumn = currentColumnIndex;
27263
- const columnWidth = gridColumnWidths?.[startColumn] || null;
27264
- const result = translator$c.encode({
27265
- ...params,
27266
- extraParams: {
27267
- ...params.extraParams,
27268
- node,
27269
- columnIndex: startColumn,
27270
- columnWidth
27271
- }
27272
- });
27273
- if (result) {
27274
- content.push(result);
27275
- const colspan = Math.max(1, result.attrs?.colspan || 1);
27276
- const rowspan = Math.max(1, result.attrs?.rowspan || 1);
27277
- if (rowspan > 1) {
27278
- for (let offset = 0; offset < colspan; offset += 1) {
27279
- const target = startColumn + offset;
27280
- if (target < pendingRowSpans.length) {
27281
- pendingRowSpans[target] = Math.max(pendingRowSpans[target], rowspan - 1);
27282
- }
27283
- }
27284
- }
27285
- currentColumnIndex = startColumn + colspan;
27286
- }
27287
- });
27288
- skipOccupiedColumns();
27289
- fillUntil(totalColumns, "gridAfter");
27290
- const newNode = {
27291
- type: "tableRow",
27292
- content,
27293
- attrs: encodedAttrs
27294
- };
27295
- return newNode;
27296
- };
27297
- const decode$p = (params, decodedAttrs) => {
27298
- const { node } = params;
27299
- const cells = node.content || [];
27300
- let leadingPlaceholders = 0;
27301
- while (leadingPlaceholders < cells.length && isPlaceholderCell(cells[leadingPlaceholders])) {
27302
- leadingPlaceholders += 1;
27303
- }
27304
- let trailingPlaceholders = 0;
27305
- while (trailingPlaceholders < cells.length - leadingPlaceholders && isPlaceholderCell(cells[cells.length - 1 - trailingPlaceholders])) {
27306
- trailingPlaceholders += 1;
27307
- }
27308
- const trimmedSlice = cells.slice(leadingPlaceholders, cells.length - trailingPlaceholders);
27309
- const sanitizedCells = trimmedSlice.map((cell) => {
27310
- if (cell?.attrs && "__placeholder" in cell.attrs) {
27311
- const { __placeholder, ...rest } = cell.attrs;
27312
- return { ...cell, attrs: rest };
27313
- }
27314
- return cell;
27315
- });
27316
- const trimmedContent = sanitizedCells.filter((_2, index2) => !isPlaceholderCell(trimmedSlice[index2]));
27317
- const translateParams = {
27318
- ...params,
27319
- node: { ...node, content: trimmedContent }
27320
- };
27321
- const elements = translateChildNodes(translateParams);
27322
- if (node.attrs?.tableRowProperties) {
27323
- const tableRowProperties = { ...node.attrs.tableRowProperties };
27324
- if (leadingPlaceholders > 0) {
27325
- tableRowProperties.gridBefore = leadingPlaceholders;
27326
- }
27327
- if (trailingPlaceholders > 0) {
27328
- tableRowProperties.gridAfter = trailingPlaceholders;
27329
- }
27330
- if (node.attrs.rowHeight != null) {
27331
- const rowHeightPixels = twipsToPixels(node.attrs.tableRowProperties["rowHeight"]?.value);
27332
- if (rowHeightPixels !== node.attrs.rowHeight) {
27333
- tableRowProperties["rowHeight"] = { value: String(pixelsToTwips(node.attrs["rowHeight"])) };
27334
- }
27335
- }
27336
- tableRowProperties["cantSplit"] = node.attrs["cantSplit"];
27337
- const trPr = translator$_.decode({
27338
- ...params,
27339
- node: { ...node, attrs: { ...node.attrs, tableRowProperties } }
27340
- });
27341
- if (trPr) elements.unshift(trPr);
27342
- }
27343
- return {
27344
- name: "w:tr",
27345
- attributes: decodedAttrs || {},
27346
- elements
27347
- };
27348
- };
27349
- const config$g = {
27350
- xmlName: XML_NODE_NAME$h,
27351
- sdNodeOrKeyName: SD_NODE_NAME$d,
27352
- type: NodeTranslator.translatorTypes.NODE,
27353
- encode: encode$n,
27354
- decode: decode$p,
27355
- attributes: validXmlAttributes$b
27356
- };
27357
- const translator$Z = NodeTranslator.from(config$g);
27358
- const translator$Y = NodeTranslator.from({
27359
- xmlName: "w:bidiVisual",
27360
- sdNodeOrKeyName: "rightToLeft",
27361
- encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
27362
- decode: ({ node }) => node.attrs.rightToLeft ? { attributes: {} } : void 0
27363
- });
27364
- const translator$X = NodeTranslator.from({
27033
+ const translator$19 = NodeTranslator.from({
27365
27034
  xmlName: "w:shd",
27366
27035
  sdNodeOrKeyName: "shading",
27367
27036
  attributes: [
@@ -27383,895 +27052,284 @@ const translator$X = NodeTranslator.from({
27383
27052
  return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
27384
27053
  }
27385
27054
  });
27386
- const translator$W = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblCaption", "caption"));
27387
- const translator$V = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblDescription", "description"));
27388
- const translator$U = NodeTranslator.from(createMeasurementPropertyHandler("w:tblInd", "tableIndent"));
27389
- const translator$T = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblLayout", "tableLayout", "w:type"));
27390
- const translator$S = NodeTranslator.from({
27391
- xmlName: "w:tblLook",
27392
- sdNodeOrKeyName: "tblLook",
27393
- attributes: ["w:firstColumn", "w:firstRow", "w:lastColumn", "w:lastRow", "w:noHBand", "w:noVBand"].map((attr) => createAttributeHandler(attr, null, parseBoolean, booleanToString)).concat([createAttributeHandler("w:val")]),
27394
- encode: (params, encodedAttrs) => {
27395
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
27396
- },
27397
- decode: function({ node }, context) {
27398
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.tblLook || {} } });
27399
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
27400
- }
27401
- });
27402
- const translator$R = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblOverlap", "overlap"));
27403
- const translator$Q = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblStyle", "tableStyleId"));
27404
- const translator$P = NodeTranslator.from(
27405
- createSingleAttrPropertyHandler("w:tblStyleColBandSize", "tableStyleColBandSize")
27406
- );
27407
- const translator$O = NodeTranslator.from(
27408
- createSingleAttrPropertyHandler("w:tblStyleRowBandSize", "tableStyleRowBandSize")
27055
+ const translator$18 = NodeTranslator.from(createMeasurementPropertyHandler("w:tcW", "cellWidth"));
27056
+ const translator$17 = NodeTranslator.from(
27057
+ createSingleAttrPropertyHandler(
27058
+ "w:gridSpan",
27059
+ null,
27060
+ "w:val",
27061
+ (v2) => parseInteger(v2) ?? void 0,
27062
+ (v2) => integerToString(v2)
27063
+ )
27409
27064
  );
27410
- const translator$N = NodeTranslator.from(createMeasurementPropertyHandler("w:tblW", "tableWidth"));
27411
- const translator$M = NodeTranslator.from({
27412
- xmlName: "w:tblpPr",
27413
- sdNodeOrKeyName: "floatingTableProperties",
27414
- 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))),
27415
- encode: (params, encodedAttrs) => {
27416
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
27417
- },
27418
- decode: function({ node }, context) {
27419
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.floatingTableProperties || {} } });
27420
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
27421
- }
27422
- });
27423
- const translator$L = NodeTranslator.from(createBorderPropertyHandler("w:bottom"));
27424
- const translator$K = NodeTranslator.from(createMeasurementPropertyHandler("w:bottom", "marginBottom"));
27425
- const translator$J = NodeTranslator.from(createBorderPropertyHandler("w:end"));
27426
- const translator$I = NodeTranslator.from(createMeasurementPropertyHandler("w:end", "marginEnd"));
27427
- const translator$H = NodeTranslator.from(createBorderPropertyHandler("w:insideH"));
27428
- const translator$G = NodeTranslator.from(createBorderPropertyHandler("w:insideV"));
27429
- const translator$F = NodeTranslator.from(createBorderPropertyHandler("w:left"));
27430
- const translator$E = NodeTranslator.from(createMeasurementPropertyHandler("w:left", "marginLeft"));
27431
- const translator$D = NodeTranslator.from(createBorderPropertyHandler("w:right"));
27432
- const translator$C = NodeTranslator.from(createMeasurementPropertyHandler("w:right", "marginRight"));
27433
- const translator$B = NodeTranslator.from(createBorderPropertyHandler("w:start"));
27434
- const translator$A = NodeTranslator.from(createMeasurementPropertyHandler("w:start", "marginStart"));
27435
- const translator$z = NodeTranslator.from(createBorderPropertyHandler("w:top"));
27436
- const translator$y = NodeTranslator.from(createMeasurementPropertyHandler("w:top", "marginTop"));
27437
- const propertyTranslators$5 = [
27438
- translator$L,
27439
- translator$J,
27440
- translator$H,
27441
- translator$G,
27442
- translator$F,
27443
- translator$D,
27444
- translator$B,
27445
- translator$z
27065
+ const translator$16 = NodeTranslator.from(createSingleAttrPropertyHandler("w:vMerge"));
27066
+ const translator$15 = NodeTranslator.from(createBorderPropertyHandler("w:bottom"));
27067
+ const translator$14 = NodeTranslator.from(createMeasurementPropertyHandler("w:bottom", "marginBottom"));
27068
+ const translator$13 = NodeTranslator.from(createBorderPropertyHandler("w:end"));
27069
+ const translator$12 = NodeTranslator.from(createMeasurementPropertyHandler("w:end", "marginEnd"));
27070
+ const translator$11 = NodeTranslator.from(createBorderPropertyHandler("w:insideH"));
27071
+ const translator$10 = NodeTranslator.from(createBorderPropertyHandler("w:insideV"));
27072
+ const translator$$ = NodeTranslator.from(createBorderPropertyHandler("w:left"));
27073
+ const translator$_ = NodeTranslator.from(createMeasurementPropertyHandler("w:left", "marginLeft"));
27074
+ const translator$Z = NodeTranslator.from(createBorderPropertyHandler("w:right"));
27075
+ const translator$Y = NodeTranslator.from(createMeasurementPropertyHandler("w:right", "marginRight"));
27076
+ const translator$X = NodeTranslator.from(createBorderPropertyHandler("w:start"));
27077
+ const translator$W = NodeTranslator.from(createMeasurementPropertyHandler("w:start", "marginStart"));
27078
+ const translator$V = NodeTranslator.from(createBorderPropertyHandler("w:top"));
27079
+ const translator$U = NodeTranslator.from(createMeasurementPropertyHandler("w:top", "marginTop"));
27080
+ const translator$T = NodeTranslator.from(createBorderPropertyHandler("w:tl2br"));
27081
+ const translator$S = NodeTranslator.from(createBorderPropertyHandler("w:tr2bl"));
27082
+ const propertyTranslators$6 = [
27083
+ translator$V,
27084
+ translator$X,
27085
+ translator$$,
27086
+ translator$15,
27087
+ translator$13,
27088
+ translator$Z,
27089
+ translator$11,
27090
+ translator$10,
27091
+ translator$T,
27092
+ translator$S
27446
27093
  ];
27447
- const translator$x = NodeTranslator.from(
27448
- createNestedPropertiesTranslator("w:tblBorders", "borders", propertyTranslators$5)
27094
+ const translator$R = NodeTranslator.from(
27095
+ createNestedPropertiesTranslator("w:tcBorders", "borders", propertyTranslators$6)
27449
27096
  );
27450
- const propertyTranslators$4 = [
27451
- translator$K,
27452
- translator$I,
27453
- translator$E,
27454
- translator$C,
27455
- translator$A,
27456
- translator$y
27457
- ];
27458
- const translator$w = NodeTranslator.from(
27459
- createNestedPropertiesTranslator("w:tblCellMar", "cellMargins", propertyTranslators$4)
27097
+ const translator$Q = NodeTranslator.from(
27098
+ createSingleAttrPropertyHandler(
27099
+ "w:noWrap",
27100
+ null,
27101
+ "w:val",
27102
+ (v2) => parseBoolean(v2 ?? "true"),
27103
+ (v2) => booleanToString(v2)
27104
+ )
27460
27105
  );
27461
- const propertyTranslators$3 = [
27462
- translator$Y,
27106
+ const propertyTranslators$5 = [
27463
27107
  translator$14,
27464
- translator$X,
27108
+ translator$12,
27109
+ translator$_,
27110
+ translator$Y,
27465
27111
  translator$W,
27466
- translator$13,
27467
- translator$V,
27468
- translator$U,
27469
- translator$T,
27470
- translator$S,
27471
- translator$R,
27472
- translator$Q,
27473
- translator$P,
27474
- translator$O,
27475
- translator$N,
27476
- translator$M,
27477
- translator$x,
27478
- translator$w
27112
+ translator$U
27479
27113
  ];
27480
- const translator$v = NodeTranslator.from(
27481
- createNestedPropertiesTranslator("w:tblPr", "tableProperties", propertyTranslators$3)
27114
+ const translator$P = NodeTranslator.from(
27115
+ createNestedPropertiesTranslator("w:tcMar", "cellMargins", propertyTranslators$5)
27482
27116
  );
27483
- const translator$u = NodeTranslator.from(
27484
- createSingleAttrPropertyHandler("w:gridCol", "col", "w:w", parseInteger, integerToString)
27117
+ const translator$O = NodeTranslator.from(createSingleAttrPropertyHandler("w:textDirection"));
27118
+ const translator$N = NodeTranslator.from(
27119
+ createSingleAttrPropertyHandler(
27120
+ "w:tcFitText",
27121
+ null,
27122
+ "w:val",
27123
+ (v2) => parseBoolean(v2 ?? "true"),
27124
+ (v2) => booleanToString(v2)
27125
+ )
27485
27126
  );
27486
- const DEFAULT_COLUMN_WIDTH_PX = 100;
27487
- const normalizeTwipWidth = (value) => {
27488
- if (value == null) return null;
27489
- const numericValue = typeof value === "string" ? parseInt(value, 10) : value;
27490
- if (!Number.isFinite(numericValue) || Number.isNaN(numericValue) || numericValue <= 0) {
27491
- return null;
27492
- }
27493
- return numericValue;
27494
- };
27495
- const getSchemaDefaultColumnWidthPx = (params) => {
27496
- const defaultValue = params?.editor?.schema?.nodes?.tableCell?.spec?.attrs?.colwidth?.default;
27497
- if (Array.isArray(defaultValue)) {
27498
- const numericWidth = defaultValue.find((width) => typeof width === "number" && Number.isFinite(width) && width > 0);
27499
- if (numericWidth != null) return numericWidth;
27500
- } else if (typeof defaultValue === "number" && Number.isFinite(defaultValue) && defaultValue > 0) {
27501
- return defaultValue;
27502
- }
27503
- return DEFAULT_COLUMN_WIDTH_PX;
27504
- };
27505
- const getTableWidthPx = (params) => {
27506
- const explicitWidth = params?.node?.attrs?.tableWidth?.width;
27507
- if (typeof explicitWidth === "number" && explicitWidth > 0) return explicitWidth;
27508
- const tableWidth = params?.node?.attrs?.tableProperties?.tableWidth;
27509
- if (tableWidth?.value != null && typeof tableWidth.value === "number" && tableWidth.value > 0) {
27510
- const { value, type: type2 } = tableWidth;
27511
- if (!type2 || type2 === "auto" || type2 === "dxa") {
27512
- return twipsToPixels(value);
27513
- }
27514
- }
27515
- return null;
27516
- };
27517
- const resolveFallbackColumnWidthTwips = (params, totalColumns, cellMinWidthTwips) => {
27518
- const columnCount = Math.max(totalColumns, 1);
27519
- const defaultColumnWidthPx = getSchemaDefaultColumnWidthPx(params);
27520
- const tableWidthPx = getTableWidthPx(params);
27521
- const safeDefaultPx = Number.isFinite(defaultColumnWidthPx) && defaultColumnWidthPx > 0 ? defaultColumnWidthPx : DEFAULT_COLUMN_WIDTH_PX;
27522
- let fallbackWidthPx = safeDefaultPx;
27523
- if (typeof tableWidthPx === "number" && tableWidthPx > 0) {
27524
- fallbackWidthPx = tableWidthPx / columnCount;
27525
- }
27526
- const fallbackWidthTwips = pixelsToTwips(fallbackWidthPx);
27527
- if (!Number.isFinite(fallbackWidthTwips) || Number.isNaN(fallbackWidthTwips) || fallbackWidthTwips <= 0) {
27528
- const safeDefault = Math.max(pixelsToTwips(safeDefaultPx), cellMinWidthTwips);
27529
- return safeDefault;
27530
- }
27531
- return Math.max(fallbackWidthTwips, cellMinWidthTwips);
27532
- };
27533
- const XML_NODE_NAME$g = "w:tblGrid";
27534
- const SD_ATTR_KEY$3 = "grid";
27535
- const cellMinWidth = pixelsToTwips(10);
27536
- const encode$m = (params) => {
27127
+ const translator$M = NodeTranslator.from(createSingleAttrPropertyHandler("w:vAlign"));
27128
+ const translator$L = NodeTranslator.from(
27129
+ createSingleAttrPropertyHandler(
27130
+ "w:hideMark",
27131
+ null,
27132
+ "w:val",
27133
+ (v2) => parseBoolean(v2 ?? "true"),
27134
+ (v2) => booleanToString(v2)
27135
+ )
27136
+ );
27137
+ const translator$K = NodeTranslator.from(createSingleAttrPropertyHandler("w:header"));
27138
+ const XML_NODE_NAME$h = "w:headers";
27139
+ const SD_ATTR_KEY$3 = "headers";
27140
+ const encode$n = (params) => {
27537
27141
  const { nodes } = params;
27538
27142
  const node = nodes[0];
27539
- const attributes = encodeProperties(node, { [translator$u.xmlName]: translator$u }, true);
27143
+ const attributes = encodeProperties(node, { [translator$K.xmlName]: translator$K }, true);
27540
27144
  return {
27541
- xmlName: XML_NODE_NAME$g,
27145
+ xmlName: XML_NODE_NAME$h,
27542
27146
  sdNodeOrKeyName: SD_ATTR_KEY$3,
27543
27147
  attributes
27544
27148
  };
27545
27149
  };
27546
- const decode$o = (params) => {
27547
- const { grid: rawGrid } = params.node.attrs || {};
27548
- const grid = Array.isArray(rawGrid) ? rawGrid : [];
27549
- const { firstRow = {} } = params.extraParams || {};
27550
- const cellNodes = firstRow.content?.filter((n) => n.type === "tableCell") ?? [];
27551
- const columnCountFromCells = cellNodes.reduce((count, cell) => {
27552
- const spanCount = Math.max(1, cell?.attrs?.colspan ?? 1);
27553
- return count + spanCount;
27554
- }, 0);
27555
- const totalColumns = Math.max(columnCountFromCells, grid.length);
27556
- const fallbackColumnWidthTwips = resolveFallbackColumnWidthTwips(params, totalColumns, cellMinWidth);
27557
- const elements = [];
27558
- let columnIndex = 0;
27559
- const pushColumn = (widthTwips, { enforceMinimum = false } = {}) => {
27560
- let numericWidth = typeof widthTwips === "string" ? parseInt(widthTwips, 10) : widthTwips;
27561
- let shouldEnforceMinimum = enforceMinimum;
27562
- if (numericWidth == null || Number.isNaN(numericWidth) || numericWidth <= 0) {
27563
- numericWidth = fallbackColumnWidthTwips;
27564
- shouldEnforceMinimum = true;
27565
- }
27566
- const roundedWidth = Math.round(numericWidth);
27567
- const minimumWidth = shouldEnforceMinimum ? cellMinWidth : 1;
27568
- const safeWidth = Math.max(roundedWidth, minimumWidth);
27569
- const decoded = translator$u.decode({
27570
- node: { type: (
27571
- /** @type {string} */
27572
- translator$u.sdNodeOrKeyName
27573
- ), attrs: { col: safeWidth } }
27574
- });
27575
- if (decoded) elements.push(decoded);
27576
- };
27577
- cellNodes.forEach((cell) => {
27578
- const { colspan = 1, colwidth } = cell?.attrs || {};
27579
- const spanCount = Math.max(1, colspan);
27580
- for (let span = 0; span < spanCount; span++) {
27581
- const rawWidth = Array.isArray(colwidth) ? colwidth[span] : void 0;
27582
- const cellWidthPixels = typeof rawWidth === "number" && Number.isFinite(rawWidth) ? rawWidth : Number(rawWidth);
27583
- const hasCellWidth = Number.isFinite(cellWidthPixels) && cellWidthPixels > 0;
27584
- const colGridAttrs = grid?.[columnIndex] || {};
27585
- const gridWidthTwips = normalizeTwipWidth(colGridAttrs.col);
27586
- const gridWidthPixels = gridWidthTwips != null ? twipsToPixels(gridWidthTwips) : null;
27587
- let cellWidthTwips;
27588
- let enforceMinimum = false;
27589
- if (hasCellWidth) {
27590
- const tolerance = 0.5;
27591
- if (gridWidthTwips != null && gridWidthPixels != null && Math.abs(gridWidthPixels - cellWidthPixels) <= tolerance) {
27592
- cellWidthTwips = gridWidthTwips;
27593
- } else {
27594
- cellWidthTwips = pixelsToTwips(cellWidthPixels);
27595
- }
27596
- } else if (gridWidthTwips != null) {
27597
- cellWidthTwips = gridWidthTwips;
27598
- } else {
27599
- cellWidthTwips = fallbackColumnWidthTwips;
27600
- enforceMinimum = true;
27601
- }
27602
- pushColumn(cellWidthTwips, { enforceMinimum });
27603
- columnIndex++;
27604
- }
27605
- });
27606
- while (columnIndex < grid.length) {
27607
- const gridWidthTwips = normalizeTwipWidth(grid[columnIndex]?.col);
27608
- pushColumn(gridWidthTwips);
27609
- columnIndex++;
27610
- }
27150
+ const decode$p = (params) => {
27151
+ const { headers = [] } = params.node.attrs || {};
27611
27152
  const newNode = {
27612
- name: XML_NODE_NAME$g,
27153
+ name: XML_NODE_NAME$h,
27613
27154
  attributes: {},
27614
- elements
27155
+ elements: headers.map(
27156
+ (header) => translator$K.decode({
27157
+ node: { type: "header", attrs: header }
27158
+ })
27159
+ )
27615
27160
  };
27616
27161
  return newNode;
27617
27162
  };
27618
- const config$f = {
27619
- xmlName: XML_NODE_NAME$g,
27163
+ const config$g = {
27164
+ xmlName: XML_NODE_NAME$h,
27620
27165
  sdNodeOrKeyName: SD_ATTR_KEY$3,
27621
- encode: encode$m,
27622
- decode: decode$o
27623
- };
27624
- const translator$t = NodeTranslator.from(config$f);
27625
- const DEFAULT_PAGE_WIDTH_TWIPS = 12240;
27626
- const DEFAULT_PAGE_MARGIN_TWIPS = 1440;
27627
- const DEFAULT_CONTENT_WIDTH_TWIPS = DEFAULT_PAGE_WIDTH_TWIPS - 2 * DEFAULT_PAGE_MARGIN_TWIPS;
27628
- const MIN_COLUMN_WIDTH_TWIPS = pixelsToTwips(10);
27629
- const pctToPercent = (value) => {
27630
- if (value == null) return null;
27631
- return value / 50;
27166
+ encode: encode$n,
27167
+ decode: decode$p
27632
27168
  };
27633
- const resolveContentWidthTwips = () => DEFAULT_CONTENT_WIDTH_TWIPS;
27634
- const resolveMeasurementWidthPx = (measurement) => {
27635
- if (!measurement || typeof measurement.value !== "number" || measurement.value <= 0) return null;
27636
- const { value, type: type2 } = measurement;
27637
- if (!type2 || type2 === "auto") return null;
27638
- if (type2 === "dxa") return twipsToPixels(value);
27639
- if (type2 === "pct") {
27640
- const percent = pctToPercent(value);
27641
- if (percent == null || percent <= 0) return null;
27642
- const widthTwips = resolveContentWidthTwips() * percent / 100;
27643
- return twipsToPixels(widthTwips);
27169
+ const translator$J = NodeTranslator.from(config$g);
27170
+ const propertyTranslators$4 = [
27171
+ translator$1a,
27172
+ translator$18,
27173
+ translator$17,
27174
+ translator$16,
27175
+ translator$R,
27176
+ translator$19,
27177
+ translator$Q,
27178
+ translator$P,
27179
+ translator$O,
27180
+ translator$N,
27181
+ translator$M,
27182
+ translator$L,
27183
+ translator$J
27184
+ ];
27185
+ const translator$I = NodeTranslator.from(
27186
+ createNestedPropertiesTranslator("w:tcPr", "tableCellProperties", propertyTranslators$4)
27187
+ );
27188
+ function handleTableCellNode({
27189
+ params,
27190
+ node,
27191
+ table,
27192
+ row,
27193
+ rowBorders,
27194
+ columnIndex,
27195
+ columnWidth = null,
27196
+ allColumnWidths = [],
27197
+ _referencedStyles
27198
+ }) {
27199
+ const { nodeListHandler } = params;
27200
+ const attributes = {};
27201
+ const referencedStyles = _referencedStyles ?? { fontSize: null, fonts: {}, cellMargins: {} };
27202
+ const tcPr = node.elements.find((el) => el.name === "w:tcPr");
27203
+ const tableCellProperties = tcPr ? translator$I.encode({ ...params, nodes: [tcPr] }) ?? {} : {};
27204
+ attributes["tableCellProperties"] = tableCellProperties;
27205
+ if (rowBorders?.insideH) {
27206
+ rowBorders["bottom"] = rowBorders.insideH;
27207
+ delete rowBorders.insideH;
27644
27208
  }
27645
- return null;
27646
- };
27647
- const countColumnsInRow = (row) => {
27648
- if (!row?.elements?.length) return 0;
27649
- return row.elements.reduce((count, element) => {
27650
- if (element.name !== "w:tc") return count;
27651
- const tcPr = element.elements?.find((el) => el.name === "w:tcPr");
27652
- const gridSpan = tcPr?.elements?.find((el) => el.name === "w:gridSpan");
27653
- const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
27654
- return count + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
27655
- }, 0);
27656
- };
27657
- const clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS);
27658
- const createFallbackGrid = (columnCount, columnWidthTwips) => Array.from({ length: columnCount }, () => ({ col: clampColumnWidthTwips(columnWidthTwips) }));
27659
- const buildFallbackGridForTable = ({ params, rows, tableWidth, tableWidthMeasurement }) => {
27660
- const firstRow = rows.find((row) => row.elements?.some((el) => el.name === "w:tc"));
27661
- const columnCount = countColumnsInRow(firstRow);
27662
- if (!columnCount) return null;
27663
- const schemaDefaultPx = getSchemaDefaultColumnWidthPx(
27664
- /** @type {any} */
27665
- params
27666
- );
27667
- const minimumColumnWidthPx = Number.isFinite(schemaDefaultPx) && schemaDefaultPx > 0 ? schemaDefaultPx : DEFAULT_COLUMN_WIDTH_PX;
27668
- let totalWidthPx;
27669
- if (tableWidthMeasurement) {
27670
- const resolved = resolveMeasurementWidthPx(tableWidthMeasurement);
27671
- if (resolved != null) totalWidthPx = resolved;
27209
+ if (rowBorders?.insideV) {
27210
+ rowBorders["right"] = rowBorders.insideV;
27211
+ delete rowBorders?.insideV;
27672
27212
  }
27673
- if (totalWidthPx == null && tableWidth?.width && tableWidth.width > 0) {
27674
- totalWidthPx = tableWidth.width;
27213
+ if (rowBorders) attributes["borders"] = { ...rowBorders };
27214
+ const inlineBorders = processInlineCellBorders(tableCellProperties.borders, rowBorders);
27215
+ if (inlineBorders) attributes["borders"] = Object.assign(attributes["borders"] || {}, inlineBorders);
27216
+ const colspan = tableCellProperties.gridSpan;
27217
+ if (colspan && !isNaN(parseInt(colspan, 10))) attributes["colspan"] = parseInt(colspan, 10);
27218
+ let width = tableCellProperties.cellWidth?.value ? twipsToPixels(tableCellProperties.cellWidth?.value) : null;
27219
+ const widthType = tableCellProperties.cellWidth?.type;
27220
+ if (widthType) attributes["widthType"] = widthType;
27221
+ if (!width && columnWidth) width = columnWidth;
27222
+ if (width) {
27223
+ attributes["colwidth"] = [width];
27224
+ attributes["widthUnit"] = "px";
27225
+ const defaultColWidths = allColumnWidths;
27226
+ const hasDefaultColWidths = allColumnWidths && allColumnWidths.length > 0;
27227
+ const colspanNum = parseInt(colspan || 1, 10);
27228
+ if (colspanNum && colspanNum > 1 && hasDefaultColWidths) {
27229
+ let colwidth = [];
27230
+ for (let i = 0; i < colspanNum; i++) {
27231
+ let colwidthValue = defaultColWidths[columnIndex + i];
27232
+ let defaultColwidth = 100;
27233
+ if (typeof colwidthValue !== "undefined") {
27234
+ colwidth.push(colwidthValue);
27235
+ } else {
27236
+ colwidth.push(defaultColwidth);
27237
+ }
27238
+ }
27239
+ if (colwidth.length) {
27240
+ attributes["colwidth"] = [...colwidth];
27241
+ }
27242
+ }
27675
27243
  }
27676
- if (totalWidthPx == null) {
27677
- totalWidthPx = minimumColumnWidthPx * columnCount;
27244
+ const background = {
27245
+ color: tableCellProperties.shading?.fill
27246
+ };
27247
+ if (background.color) attributes["background"] = background;
27248
+ const verticalAlign = tableCellProperties.vAlign;
27249
+ if (verticalAlign) attributes["verticalAlign"] = verticalAlign;
27250
+ attributes.cellMargins = getTableCellMargins(tableCellProperties.cellMargins, referencedStyles);
27251
+ const { fontSize, fonts = {} } = referencedStyles;
27252
+ const fontFamily = fonts["ascii"];
27253
+ if (fontSize) attributes["fontSize"] = fontSize;
27254
+ if (fontFamily) attributes["fontFamily"] = fontFamily;
27255
+ if (tableCellProperties.vMerge === "restart") {
27256
+ const rows = table.elements.filter((el) => el.name === "w:tr");
27257
+ const currentRowIndex = rows.findIndex((r) => r === row);
27258
+ const remainingRows = rows.slice(currentRowIndex + 1);
27259
+ const cellsInRow = row.elements.filter((el) => el.name === "w:tc");
27260
+ let cellIndex = cellsInRow.findIndex((el) => el === node);
27261
+ let rowspan = 1;
27262
+ for (let remainingRow of remainingRows) {
27263
+ const firstCell = remainingRow.elements.findIndex((el) => el.name === "w:tc");
27264
+ const cellAtIndex = remainingRow.elements[firstCell + cellIndex];
27265
+ if (!cellAtIndex) break;
27266
+ const vMerge = getTableCellVMerge(cellAtIndex);
27267
+ if (!vMerge || vMerge === "restart") {
27268
+ break;
27269
+ }
27270
+ rowspan++;
27271
+ remainingRow.elements.splice(firstCell + cellIndex, 1);
27272
+ }
27273
+ attributes["rowspan"] = rowspan;
27678
27274
  }
27679
- const rawColumnWidthPx = Math.max(totalWidthPx / columnCount, minimumColumnWidthPx);
27680
- const columnWidthTwips = clampColumnWidthTwips(pixelsToTwips(rawColumnWidthPx));
27681
- const fallbackColumnWidthPx = twipsToPixels(columnWidthTwips);
27682
27275
  return {
27683
- grid: createFallbackGrid(columnCount, columnWidthTwips),
27684
- columnWidths: Array(columnCount).fill(fallbackColumnWidthPx)
27276
+ type: "tableCell",
27277
+ content: normalizeTableCellContent(
27278
+ nodeListHandler.handler({
27279
+ ...params,
27280
+ nodes: node.elements,
27281
+ path: [...params.path || [], node]
27282
+ }),
27283
+ params.editor
27284
+ ),
27285
+ attrs: attributes
27685
27286
  };
27686
- };
27687
- const XML_NODE_NAME$f = "w:tbl";
27688
- const SD_NODE_NAME$c = "table";
27689
- const encode$l = (params, encodedAttrs) => {
27690
- const { nodes } = params;
27691
- const node = nodes[0];
27692
- const tblPr = node.elements.find((el) => el.name === "w:tblPr");
27693
- if (tblPr) {
27694
- const encodedProperties = translator$v.encode({ ...params, nodes: [tblPr] });
27695
- encodedAttrs["tableProperties"] = encodedProperties || {};
27696
- }
27697
- const tblGrid = node.elements.find((el) => el.name === "w:tblGrid");
27698
- if (tblGrid) {
27699
- encodedAttrs["grid"] = translator$t.encode({ ...params, nodes: [tblGrid] }).attributes;
27700
- }
27701
- [
27702
- "tableStyleId",
27703
- "justification",
27704
- "tableLayout",
27705
- ["tableIndent", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
27706
- ["tableCellSpacing", ({ value, type: type2 }) => ({ w: String(value), type: type2 })]
27707
- ].forEach((prop) => {
27708
- let key;
27709
- let transform;
27710
- if (Array.isArray(prop)) {
27711
- [key, transform] = prop;
27712
- } else {
27713
- key = prop;
27714
- transform = (v2) => v2;
27287
+ }
27288
+ function normalizeTableCellContent(content, editor) {
27289
+ if (!Array.isArray(content) || content.length === 0) return content;
27290
+ const normalized = [];
27291
+ const pendingForNextBlock = [];
27292
+ const schema = editor?.schema;
27293
+ const cloneBlock = (node) => {
27294
+ if (!node) return node;
27295
+ const cloned = { ...node };
27296
+ if (Array.isArray(node.content)) {
27297
+ cloned.content = [...node.content];
27715
27298
  }
27716
- if (encodedAttrs.tableProperties && encodedAttrs.tableProperties[key]) {
27717
- encodedAttrs[key] = transform(encodedAttrs.tableProperties[key]);
27299
+ return cloned;
27300
+ };
27301
+ const ensureArray = (node) => {
27302
+ if (!Array.isArray(node.content)) {
27303
+ node.content = [];
27718
27304
  }
27719
- });
27720
- if (encodedAttrs.tableCellSpacing) {
27721
- encodedAttrs["borderCollapse"] = "separate";
27722
- }
27723
- if (encodedAttrs.tableProperties?.tableWidth) {
27724
- const tableWidthMeasurement = encodedAttrs.tableProperties.tableWidth;
27725
- const widthPx = twipsToPixels(tableWidthMeasurement.value);
27726
- if (widthPx != null) {
27727
- encodedAttrs.tableWidth = {
27728
- width: widthPx,
27729
- type: tableWidthMeasurement.type
27730
- };
27731
- } else if (tableWidthMeasurement.type === "auto") {
27732
- encodedAttrs.tableWidth = {
27733
- width: 0,
27734
- type: tableWidthMeasurement.type
27735
- };
27305
+ return node.content;
27306
+ };
27307
+ const isInlineNode = (node) => {
27308
+ if (!node || typeof node.type !== "string") return false;
27309
+ if (node.type === "text") return true;
27310
+ if (node.type === "bookmarkStart" || node.type === "bookmarkEnd") return true;
27311
+ const nodeType = schema?.nodes?.[node.type];
27312
+ if (nodeType) {
27313
+ if (typeof nodeType.isInline === "boolean") return nodeType.isInline;
27314
+ if (nodeType.spec?.group && typeof nodeType.spec.group === "string") {
27315
+ return nodeType.spec.group.split(" ").includes("inline");
27316
+ }
27736
27317
  }
27737
- }
27738
- const { borders, rowBorders } = _processTableBorders(encodedAttrs.tableProperties?.borders || {});
27739
- const referencedStyles = _getReferencedTableStyles(encodedAttrs.tableStyleId, params);
27740
- if (referencedStyles?.cellMargins && !encodedAttrs.tableProperties?.cellMargins) {
27741
- encodedAttrs.tableProperties = {
27742
- ...encodedAttrs.tableProperties || {},
27743
- cellMargins: referencedStyles.cellMargins
27744
- };
27745
- }
27746
- const rows = node.elements.filter((el) => el.name === "w:tr");
27747
- const borderData = Object.assign({}, referencedStyles?.borders || {}, borders || {});
27748
- const borderRowData = Object.assign({}, referencedStyles?.rowBorders || {}, rowBorders || {});
27749
- encodedAttrs["borders"] = borderData;
27750
- const tblStyleTag = tblPr?.elements?.find((el) => el.name === "w:tblStyle");
27751
- let columnWidths = Array.isArray(encodedAttrs["grid"]) ? encodedAttrs["grid"].map((item) => twipsToPixels(item.col)) : [];
27752
- if (!columnWidths.length) {
27753
- const fallback = buildFallbackGridForTable({
27754
- params,
27755
- rows,
27756
- tableWidth: encodedAttrs.tableWidth,
27757
- tableWidthMeasurement: encodedAttrs.tableProperties?.tableWidth
27758
- });
27759
- if (fallback) {
27760
- encodedAttrs.grid = fallback.grid;
27761
- columnWidths = fallback.columnWidths;
27318
+ return false;
27319
+ };
27320
+ for (const node of content) {
27321
+ if (!node || typeof node.type !== "string") {
27322
+ normalized.push(node);
27323
+ continue;
27762
27324
  }
27763
- }
27764
- const content = [];
27765
- const totalColumns = columnWidths.length;
27766
- const activeRowSpans = totalColumns > 0 ? new Array(totalColumns).fill(0) : [];
27767
- rows.forEach((row, rowIndex) => {
27768
- const result = translator$Z.encode({
27769
- ...params,
27770
- nodes: [row],
27771
- extraParams: {
27772
- row,
27773
- table: node,
27774
- rowBorders: borderRowData,
27775
- styleTag: tblStyleTag,
27776
- columnWidths,
27777
- activeRowSpans: activeRowSpans.slice(),
27778
- rowIndex
27779
- }
27780
- });
27781
- if (result) {
27782
- content.push(result);
27783
- if (totalColumns > 0) {
27784
- const activeRowSpansForCurrentRow = activeRowSpans.slice();
27785
- for (let col = 0; col < totalColumns; col++) {
27786
- if (activeRowSpans[col] > 0) {
27787
- activeRowSpans[col] -= 1;
27788
- }
27789
- }
27790
- let columnIndex = 0;
27791
- const advanceColumnIndex = () => {
27792
- while (columnIndex < totalColumns && activeRowSpansForCurrentRow[columnIndex] > 0) {
27793
- columnIndex += 1;
27794
- }
27795
- };
27796
- advanceColumnIndex();
27797
- result.content?.forEach((cell) => {
27798
- advanceColumnIndex();
27799
- const colspan = Math.max(1, cell.attrs?.colspan || 1);
27800
- const rowspan = Math.max(1, cell.attrs?.rowspan || 1);
27801
- if (rowspan > 1) {
27802
- for (let offset = 0; offset < colspan && columnIndex + offset < totalColumns; offset++) {
27803
- const targetIndex = columnIndex + offset;
27804
- const remainingRows = rowspan - 1;
27805
- if (remainingRows > 0 && remainingRows > activeRowSpans[targetIndex]) {
27806
- activeRowSpans[targetIndex] = remainingRows;
27807
- }
27808
- }
27809
- }
27810
- columnIndex += colspan;
27811
- advanceColumnIndex();
27812
- });
27813
- }
27814
- }
27815
- });
27816
- return {
27817
- type: "table",
27818
- content,
27819
- attrs: encodedAttrs
27820
- };
27821
- };
27822
- const decode$n = (params, decodedAttrs) => {
27823
- params.node = preProcessVerticalMergeCells(params.node, params);
27824
- const { node } = params;
27825
- const elements = translateChildNodes(params);
27826
- const firstRow = node.content?.find((n) => n.type === "tableRow");
27827
- const properties = node.attrs.grid;
27828
- const element = translator$t.decode({
27829
- ...params,
27830
- node: { ...node, attrs: { ...node.attrs, grid: properties } },
27831
- extraParams: {
27832
- firstRow
27833
- }
27834
- });
27835
- if (element) elements.unshift(element);
27836
- if (node.attrs?.tableProperties) {
27837
- const properties2 = { ...node.attrs.tableProperties };
27838
- const element2 = translator$v.decode({
27839
- ...params,
27840
- node: { ...node, attrs: { ...node.attrs, tableProperties: properties2 } }
27841
- });
27842
- if (element2) elements.unshift(element2);
27843
- }
27844
- return {
27845
- name: "w:tbl",
27846
- attributes: decodedAttrs || {},
27847
- elements
27848
- };
27849
- };
27850
- function _processTableBorders(rawBorders) {
27851
- const borders = {};
27852
- const rowBorders = {};
27853
- Object.entries(rawBorders).forEach(([name, attributes]) => {
27854
- const attrs = {};
27855
- const color = attributes.color;
27856
- const size = attributes.size;
27857
- if (color && color !== "auto") attrs["color"] = color.startsWith("#") ? color : `#${color}`;
27858
- if (size && size !== "auto") attrs["size"] = eighthPointsToPixels(size);
27859
- const rowBorderNames = ["insideH", "insideV"];
27860
- if (rowBorderNames.includes(name)) rowBorders[name] = attrs;
27861
- borders[name] = attrs;
27862
- });
27863
- return {
27864
- borders,
27865
- rowBorders
27866
- };
27867
- }
27868
- function _getReferencedTableStyles(tableStyleReference, params) {
27869
- if (!tableStyleReference) return null;
27870
- const stylesToReturn = {};
27871
- const { docx } = params;
27872
- const styles = docx["word/styles.xml"];
27873
- const { elements } = styles.elements[0];
27874
- const styleElements = elements.filter((el) => el.name === "w:style");
27875
- const styleTag = styleElements.find((el) => el.attributes["w:styleId"] === tableStyleReference);
27876
- if (!styleTag) return null;
27877
- stylesToReturn.name = styleTag.elements.find((el) => el.name === "w:name");
27878
- const basedOn = styleTag.elements.find((el) => el.name === "w:basedOn");
27879
- let baseTblPr;
27880
- if (basedOn?.attributes) {
27881
- const baseStyles = styleElements.find((el) => el.attributes["w:styleId"] === basedOn.attributes["w:val"]);
27882
- baseTblPr = baseStyles ? baseStyles.elements.find((el) => el.name === "w:tblPr") : {};
27883
- }
27884
- const pPr = styleTag.elements.find((el) => el.name === "w:pPr");
27885
- if (pPr) {
27886
- const justification = pPr.elements.find((el) => el.name === "w:jc");
27887
- if (justification?.attributes) stylesToReturn.justification = justification.attributes["w:val"];
27888
- }
27889
- const rPr = styleTag?.elements.find((el) => el.name === "w:rPr");
27890
- if (rPr) {
27891
- const fonts = rPr.elements.find((el) => el.name === "w:rFonts");
27892
- if (fonts) {
27893
- const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
27894
- stylesToReturn.fonts = { ascii, hAnsi, cs };
27895
- }
27896
- const fontSize = rPr.elements.find((el) => el.name === "w:sz");
27897
- if (fontSize?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize.attributes["w:val"]) + "pt";
27898
- }
27899
- const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
27900
- if (tblPr && tblPr.elements) {
27901
- if (baseTblPr && baseTblPr.elements) {
27902
- tblPr.elements.push(...baseTblPr.elements);
27903
- }
27904
- const tableProperties = translator$v.encode({ ...params, nodes: [tblPr] });
27905
- const { borders, rowBorders } = _processTableBorders(tableProperties.borders || {});
27906
- if (borders) stylesToReturn.borders = borders;
27907
- if (rowBorders) stylesToReturn.rowBorders = rowBorders;
27908
- const cellMargins = {};
27909
- Object.entries(tableProperties.cellMargins || {}).forEach(([key, attrs]) => {
27910
- if (attrs?.value != null) {
27911
- cellMargins[key] = {
27912
- value: attrs.value,
27913
- type: attrs.type || "dxa"
27914
- };
27915
- }
27916
- });
27917
- if (Object.keys(cellMargins).length) stylesToReturn.cellMargins = cellMargins;
27918
- }
27919
- return stylesToReturn;
27920
- }
27921
- const config$e = {
27922
- xmlName: XML_NODE_NAME$f,
27923
- sdNodeOrKeyName: SD_NODE_NAME$c,
27924
- type: NodeTranslator.translatorTypes.NODE,
27925
- encode: encode$l,
27926
- decode: decode$n,
27927
- attributes: []
27928
- };
27929
- const translator$s = NodeTranslator.from(config$e);
27930
- const tableNodeHandlerEntity = generateV2HandlerEntity("tableNodeHandler", translator$s);
27931
- function getReferencedTableStyles(tblStyleTag, docx) {
27932
- if (!tblStyleTag) return null;
27933
- const stylesToReturn = {};
27934
- const { attributes = {} } = tblStyleTag;
27935
- const tableStyleReference = attributes["w:val"];
27936
- if (!tableStyleReference) return null;
27937
- const styles = docx["word/styles.xml"];
27938
- const { elements } = styles.elements[0];
27939
- const styleElements = elements.filter((el) => el.name === "w:style");
27940
- const styleTag = styleElements.find((el) => el.attributes["w:styleId"] === tableStyleReference);
27941
- if (!styleTag) return null;
27942
- stylesToReturn.name = styleTag.elements.find((el) => el.name === "w:name");
27943
- const basedOn = styleTag.elements.find((el) => el.name === "w:basedOn");
27944
- let baseTblPr;
27945
- if (basedOn?.attributes) {
27946
- const baseStyles = styleElements.find((el) => el.attributes["w:styleId"] === basedOn.attributes["w:val"]);
27947
- baseTblPr = baseStyles ? baseStyles.elements.find((el) => el.name === "w:tblPr") : {};
27948
- }
27949
- const pPr = styleTag.elements.find((el) => el.name === "w:pPr");
27950
- if (pPr) {
27951
- const justification = pPr.elements.find((el) => el.name === "w:jc");
27952
- if (justification?.attributes) stylesToReturn.justification = justification.attributes["w:val"];
27953
- }
27954
- const rPr = styleTag?.elements.find((el) => el.name === "w:rPr");
27955
- if (rPr) {
27956
- const fonts = rPr.elements.find((el) => el.name === "w:rFonts");
27957
- if (fonts) {
27958
- const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
27959
- stylesToReturn.fonts = { ascii, hAnsi, cs };
27960
- }
27961
- const fontSize = rPr.elements.find((el) => el.name === "w:sz");
27962
- if (fontSize?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize.attributes["w:val"]) + "pt";
27963
- }
27964
- const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
27965
- if (tblPr && tblPr.elements) {
27966
- if (baseTblPr && baseTblPr.elements) {
27967
- tblPr.elements.push(...baseTblPr.elements);
27968
- }
27969
- const tableBorders = tblPr?.elements?.find((el) => el.name === "w:tblBorders");
27970
- const { elements: borderElements = [] } = tableBorders || {};
27971
- const { borders, rowBorders } = processTableBorders(borderElements);
27972
- if (borders) stylesToReturn.borders = borders;
27973
- if (rowBorders) stylesToReturn.rowBorders = rowBorders;
27974
- const tableCellMargin = tblPr?.elements.find((el) => el.name === "w:tblCellMar");
27975
- if (tableCellMargin) {
27976
- const marginLeft = tableCellMargin.elements.find((el) => el.name === "w:left");
27977
- const marginRight = tableCellMargin.elements.find((el) => el.name === "w:right");
27978
- const marginTop = tableCellMargin.elements.find((el) => el.name === "w:top");
27979
- const marginBottom = tableCellMargin.elements.find((el) => el.name === "w:bottom");
27980
- stylesToReturn.cellMargins = {
27981
- marginLeft: marginLeft?.attributes["w:w"],
27982
- marginRight: marginRight?.attributes["w:w"],
27983
- marginTop: marginTop?.attributes["w:w"],
27984
- marginBottom: marginBottom?.attributes["w:w"]
27985
- };
27986
- }
27987
- }
27988
- return stylesToReturn;
27989
- }
27990
- function processTableBorders(borderElements) {
27991
- const borders = {};
27992
- const rowBorders = {};
27993
- borderElements.forEach((borderElement) => {
27994
- const { name } = borderElement;
27995
- const borderName = name.split("w:")[1];
27996
- const { attributes } = borderElement;
27997
- const attrs = {};
27998
- const color = attributes["w:color"];
27999
- const size = attributes["w:sz"];
28000
- if (color && color !== "auto") attrs["color"] = color.startsWith("#") ? color : `#${color}`;
28001
- if (size && size !== "auto") attrs["size"] = eighthPointsToPixels(size);
28002
- const rowBorderNames = ["insideH", "insideV"];
28003
- if (rowBorderNames.includes(borderName)) rowBorders[borderName] = attrs;
28004
- borders[borderName] = attrs;
28005
- });
28006
- return {
28007
- borders,
28008
- rowBorders
28009
- };
28010
- }
28011
- const translator$r = NodeTranslator.from(createMeasurementPropertyHandler("w:tcW", "cellWidth"));
28012
- const translator$q = NodeTranslator.from(
28013
- createSingleAttrPropertyHandler(
28014
- "w:gridSpan",
28015
- null,
28016
- "w:val",
28017
- (v2) => parseInteger(v2) ?? void 0,
28018
- (v2) => integerToString(v2)
28019
- )
28020
- );
28021
- const translator$p = NodeTranslator.from(createSingleAttrPropertyHandler("w:vMerge"));
28022
- const translator$o = NodeTranslator.from(createBorderPropertyHandler("w:tl2br"));
28023
- const translator$n = NodeTranslator.from(createBorderPropertyHandler("w:tr2bl"));
28024
- const propertyTranslators$2 = [
28025
- translator$z,
28026
- translator$B,
28027
- translator$F,
28028
- translator$L,
28029
- translator$J,
28030
- translator$D,
28031
- translator$H,
28032
- translator$G,
28033
- translator$o,
28034
- translator$n
28035
- ];
28036
- const translator$m = NodeTranslator.from(
28037
- createNestedPropertiesTranslator("w:tcBorders", "borders", propertyTranslators$2)
28038
- );
28039
- const translator$l = NodeTranslator.from(
28040
- createSingleAttrPropertyHandler(
28041
- "w:noWrap",
28042
- null,
28043
- "w:val",
28044
- (v2) => parseBoolean(v2 ?? "true"),
28045
- (v2) => booleanToString(v2)
28046
- )
28047
- );
28048
- const propertyTranslators$1 = [
28049
- translator$K,
28050
- translator$I,
28051
- translator$E,
28052
- translator$C,
28053
- translator$A,
28054
- translator$y
28055
- ];
28056
- const translator$k = NodeTranslator.from(
28057
- createNestedPropertiesTranslator("w:tcMar", "cellMargins", propertyTranslators$1)
28058
- );
28059
- const translator$j = NodeTranslator.from(createSingleAttrPropertyHandler("w:textDirection"));
28060
- const translator$i = NodeTranslator.from(
28061
- createSingleAttrPropertyHandler(
28062
- "w:tcFitText",
28063
- null,
28064
- "w:val",
28065
- (v2) => parseBoolean(v2 ?? "true"),
28066
- (v2) => booleanToString(v2)
28067
- )
28068
- );
28069
- const translator$h = NodeTranslator.from(createSingleAttrPropertyHandler("w:vAlign"));
28070
- const translator$g = NodeTranslator.from(
28071
- createSingleAttrPropertyHandler(
28072
- "w:hideMark",
28073
- null,
28074
- "w:val",
28075
- (v2) => parseBoolean(v2 ?? "true"),
28076
- (v2) => booleanToString(v2)
28077
- )
28078
- );
28079
- const translator$f = NodeTranslator.from(createSingleAttrPropertyHandler("w:header"));
28080
- const XML_NODE_NAME$e = "w:headers";
28081
- const SD_ATTR_KEY$2 = "headers";
28082
- const encode$k = (params) => {
28083
- const { nodes } = params;
28084
- const node = nodes[0];
28085
- const attributes = encodeProperties(node, { [translator$f.xmlName]: translator$f }, true);
28086
- return {
28087
- xmlName: XML_NODE_NAME$e,
28088
- sdNodeOrKeyName: SD_ATTR_KEY$2,
28089
- attributes
28090
- };
28091
- };
28092
- const decode$m = (params) => {
28093
- const { headers = [] } = params.node.attrs || {};
28094
- const newNode = {
28095
- name: XML_NODE_NAME$e,
28096
- attributes: {},
28097
- elements: headers.map(
28098
- (header) => translator$f.decode({
28099
- node: { type: "header", attrs: header }
28100
- })
28101
- )
28102
- };
28103
- return newNode;
28104
- };
28105
- const config$d = {
28106
- xmlName: XML_NODE_NAME$e,
28107
- sdNodeOrKeyName: SD_ATTR_KEY$2,
28108
- encode: encode$k,
28109
- decode: decode$m
28110
- };
28111
- const translator$e = NodeTranslator.from(config$d);
28112
- const propertyTranslators = [
28113
- translator$19,
28114
- translator$r,
28115
- translator$q,
28116
- translator$p,
28117
- translator$m,
28118
- translator$X,
28119
- translator$l,
28120
- translator$k,
28121
- translator$j,
28122
- translator$i,
28123
- translator$h,
28124
- translator$g,
28125
- translator$e
28126
- ];
28127
- const translator$d = NodeTranslator.from(
28128
- createNestedPropertiesTranslator("w:tcPr", "tableCellProperties", propertyTranslators)
28129
- );
28130
- function handleTableCellNode({
28131
- params,
28132
- node,
28133
- table,
28134
- row,
28135
- rowBorders,
28136
- styleTag,
28137
- columnIndex,
28138
- columnWidth = null,
28139
- allColumnWidths = []
28140
- }) {
28141
- const { docx, nodeListHandler } = params;
28142
- const attributes = {};
28143
- const tcPr = node.elements.find((el) => el.name === "w:tcPr");
28144
- const tableCellProperties = tcPr ? translator$d.encode({ ...params, nodes: [tcPr] }) ?? {} : {};
28145
- attributes["tableCellProperties"] = tableCellProperties;
28146
- if (rowBorders?.insideH) {
28147
- rowBorders["bottom"] = rowBorders.insideH;
28148
- delete rowBorders.insideH;
28149
- }
28150
- if (rowBorders?.insideV) {
28151
- rowBorders["right"] = rowBorders.insideV;
28152
- delete rowBorders?.insideV;
28153
- }
28154
- if (rowBorders) attributes["borders"] = { ...rowBorders };
28155
- const inlineBorders = processInlineCellBorders(tableCellProperties.borders, rowBorders);
28156
- if (inlineBorders) attributes["borders"] = Object.assign(attributes["borders"] || {}, inlineBorders);
28157
- const colspan = tableCellProperties.gridSpan;
28158
- if (colspan && !isNaN(parseInt(colspan, 10))) attributes["colspan"] = parseInt(colspan, 10);
28159
- let width = tableCellProperties.cellWidth?.value ? twipsToPixels(tableCellProperties.cellWidth?.value) : null;
28160
- const widthType = tableCellProperties.cellWidth?.type;
28161
- if (widthType) attributes["widthType"] = widthType;
28162
- if (!width && columnWidth) width = columnWidth;
28163
- if (width) {
28164
- attributes["colwidth"] = [width];
28165
- attributes["widthUnit"] = "px";
28166
- const defaultColWidths = allColumnWidths;
28167
- const hasDefaultColWidths = allColumnWidths && allColumnWidths.length > 0;
28168
- const colspanNum = parseInt(colspan || 1, 10);
28169
- if (colspanNum && colspanNum > 1 && hasDefaultColWidths) {
28170
- let colwidth = [];
28171
- for (let i = 0; i < colspanNum; i++) {
28172
- let colwidthValue = defaultColWidths[columnIndex + i];
28173
- let defaultColwidth = 100;
28174
- if (typeof colwidthValue !== "undefined") {
28175
- colwidth.push(colwidthValue);
28176
- } else {
28177
- colwidth.push(defaultColwidth);
28178
- }
28179
- }
28180
- if (colwidth.length) {
28181
- attributes["colwidth"] = [...colwidth];
28182
- }
28183
- }
28184
- }
28185
- const background = {
28186
- color: tableCellProperties.shading?.fill
28187
- };
28188
- if (background.color) attributes["background"] = background;
28189
- const verticalAlign = tableCellProperties.vAlign;
28190
- if (verticalAlign) attributes["verticalAlign"] = verticalAlign;
28191
- const referencedStyles = getReferencedTableStyles(styleTag, docx) || { fontSize: null, fonts: {}, cellMargins: {} };
28192
- attributes.cellMargins = getTableCellMargins(tableCellProperties.cellMargins, referencedStyles);
28193
- const { fontSize, fonts = {} } = referencedStyles;
28194
- const fontFamily = fonts["ascii"];
28195
- if (fontSize) attributes["fontSize"] = fontSize;
28196
- if (fontFamily) attributes["fontFamily"] = fontFamily;
28197
- if (tableCellProperties.vMerge === "restart") {
28198
- const rows = table.elements.filter((el) => el.name === "w:tr");
28199
- const currentRowIndex = rows.findIndex((r) => r === row);
28200
- const remainingRows = rows.slice(currentRowIndex + 1);
28201
- const cellsInRow = row.elements.filter((el) => el.name === "w:tc");
28202
- let cellIndex = cellsInRow.findIndex((el) => el === node);
28203
- let rowspan = 1;
28204
- for (let remainingRow of remainingRows) {
28205
- const firstCell = remainingRow.elements.findIndex((el) => el.name === "w:tc");
28206
- const cellAtIndex = remainingRow.elements[firstCell + cellIndex];
28207
- if (!cellAtIndex) break;
28208
- const vMerge = getTableCellVMerge(cellAtIndex);
28209
- if (!vMerge || vMerge === "restart") {
28210
- break;
28211
- }
28212
- rowspan++;
28213
- remainingRow.elements.splice(firstCell + cellIndex, 1);
28214
- }
28215
- attributes["rowspan"] = rowspan;
28216
- }
28217
- return {
28218
- type: "tableCell",
28219
- content: normalizeTableCellContent(
28220
- nodeListHandler.handler({
28221
- ...params,
28222
- nodes: node.elements,
28223
- path: [...params.path || [], node]
28224
- }),
28225
- params.editor
28226
- ),
28227
- attrs: attributes
28228
- };
28229
- }
28230
- function normalizeTableCellContent(content, editor) {
28231
- if (!Array.isArray(content) || content.length === 0) return content;
28232
- const normalized = [];
28233
- const pendingForNextBlock = [];
28234
- const schema = editor?.schema;
28235
- const cloneBlock = (node) => {
28236
- if (!node) return node;
28237
- const cloned = { ...node };
28238
- if (Array.isArray(node.content)) {
28239
- cloned.content = [...node.content];
28240
- }
28241
- return cloned;
28242
- };
28243
- const ensureArray = (node) => {
28244
- if (!Array.isArray(node.content)) {
28245
- node.content = [];
28246
- }
28247
- return node.content;
28248
- };
28249
- const isInlineNode = (node) => {
28250
- if (!node || typeof node.type !== "string") return false;
28251
- if (node.type === "text") return true;
28252
- if (node.type === "bookmarkStart" || node.type === "bookmarkEnd") return true;
28253
- const nodeType = schema?.nodes?.[node.type];
28254
- if (nodeType) {
28255
- if (typeof nodeType.isInline === "boolean") return nodeType.isInline;
28256
- if (nodeType.spec?.group && typeof nodeType.spec.group === "string") {
28257
- return nodeType.spec.group.split(" ").includes("inline");
28258
- }
28259
- }
28260
- return false;
28261
- };
28262
- for (const node of content) {
28263
- if (!node || typeof node.type !== "string") {
28264
- normalized.push(node);
28265
- continue;
28266
- }
28267
- if (!isInlineNode(node)) {
28268
- const blockNode = cloneBlock(node);
28269
- if (pendingForNextBlock.length) {
28270
- const blockContent = ensureArray(blockNode);
28271
- const leadingInline = pendingForNextBlock.splice(0);
28272
- blockNode.content = [...leadingInline, ...blockContent];
28273
- } else if (Array.isArray(blockNode.content)) {
28274
- blockNode.content = [...blockNode.content];
27325
+ if (!isInlineNode(node)) {
27326
+ const blockNode = cloneBlock(node);
27327
+ if (pendingForNextBlock.length) {
27328
+ const blockContent = ensureArray(blockNode);
27329
+ const leadingInline = pendingForNextBlock.splice(0);
27330
+ blockNode.content = [...leadingInline, ...blockContent];
27331
+ } else if (Array.isArray(blockNode.content)) {
27332
+ blockNode.content = [...blockNode.content];
28275
27333
  }
28276
27334
  normalized.push(blockNode);
28277
27335
  continue;
@@ -28454,22 +27512,22 @@ function generateTableCellProperties(node) {
28454
27512
  } else if (tableCellProperties?.borders) {
28455
27513
  delete tableCellProperties.borders;
28456
27514
  }
28457
- const result = translator$d.decode({ node: { ...node, attrs: { ...node.attrs, tableCellProperties } } });
27515
+ const result = translator$I.decode({ node: { ...node, attrs: { ...node.attrs, tableCellProperties } } });
28458
27516
  return result;
28459
27517
  }
28460
- const XML_NODE_NAME$d = "w:tc";
28461
- const SD_NODE_NAME$b = "tableCell";
28462
- const validXmlAttributes$a = [];
28463
- function encode$j(params, encodedAttrs) {
27518
+ const XML_NODE_NAME$g = "w:tc";
27519
+ const SD_NODE_NAME$d = "tableCell";
27520
+ const validXmlAttributes$b = [];
27521
+ function encode$m(params, encodedAttrs) {
28464
27522
  const {
28465
27523
  node,
28466
27524
  table,
28467
27525
  row,
28468
27526
  rowBorders,
28469
- styleTag,
28470
27527
  columnIndex,
28471
27528
  columnWidth,
28472
- columnWidths: allColumnWidths
27529
+ columnWidths: allColumnWidths,
27530
+ _referencedStyles
28473
27531
  } = params.extraParams;
28474
27532
  const schemaNode = handleTableCellNode({
28475
27533
  params,
@@ -28477,96 +27535,388 @@ function encode$j(params, encodedAttrs) {
28477
27535
  table,
28478
27536
  row,
28479
27537
  rowBorders,
28480
- styleTag,
28481
27538
  columnIndex,
28482
27539
  columnWidth,
28483
- allColumnWidths
27540
+ allColumnWidths,
27541
+ _referencedStyles
28484
27542
  });
28485
27543
  if (encodedAttrs && Object.keys(encodedAttrs).length) {
28486
27544
  schemaNode.attrs = { ...schemaNode.attrs, ...encodedAttrs };
28487
27545
  }
28488
27546
  return schemaNode;
28489
27547
  }
28490
- function decode$l(params, decodedAttrs) {
27548
+ function decode$o(params, decodedAttrs) {
28491
27549
  const translated = translateTableCell(params);
28492
27550
  if (decodedAttrs && Object.keys(decodedAttrs).length) {
28493
27551
  translated.attributes = { ...translated.attributes || {}, ...decodedAttrs };
28494
27552
  }
28495
27553
  return translated;
28496
27554
  }
28497
- const config$c = {
28498
- xmlName: XML_NODE_NAME$d,
28499
- sdNodeOrKeyName: SD_NODE_NAME$b,
27555
+ const config$f = {
27556
+ xmlName: XML_NODE_NAME$g,
27557
+ sdNodeOrKeyName: SD_NODE_NAME$d,
28500
27558
  type: NodeTranslator.translatorTypes.NODE,
28501
- encode: encode$j,
28502
- decode: decode$l,
28503
- attributes: validXmlAttributes$a
27559
+ encode: encode$m,
27560
+ decode: decode$o,
27561
+ attributes: validXmlAttributes$b
28504
27562
  };
28505
- const translator$c = NodeTranslator.from(config$c);
28506
- function parseTagValueJSON(json) {
28507
- if (typeof json !== "string") {
28508
- return {};
28509
- }
28510
- const trimmed = json.trim();
28511
- if (!trimmed) {
28512
- return {};
28513
- }
28514
- try {
28515
- return JSON.parse(trimmed);
28516
- } catch {
28517
- return {};
28518
- }
28519
- }
28520
- function handleAnnotationNode(params) {
28521
- const { nodes } = params;
28522
- if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
28523
- return null;
28524
- }
28525
- const node = nodes[0];
28526
- const sdtPr = node.elements.find((el) => el.name === "w:sdtPr");
28527
- const sdtContent = node.elements.find((el) => el.name === "w:sdtContent");
28528
- const sdtId = sdtPr?.elements?.find((el) => el.name === "w:id");
28529
- const alias = sdtPr?.elements.find((el) => el.name === "w:alias");
28530
- const tag = sdtPr?.elements.find((el) => el.name === "w:tag");
28531
- const tagValue = tag?.attributes["w:val"];
28532
- const shouldProcessAsJson = tagValue?.startsWith("{") && tagValue?.endsWith("}");
28533
- let attrs = {};
28534
- const aliasLabel = getSafeString(alias?.attributes?.["w:val"]);
28535
- if (shouldProcessAsJson) {
28536
- const parsedAttrs = parseTagValueJSON(tagValue);
28537
- attrs = {
28538
- type: parsedAttrs.fieldTypeShort,
28539
- fieldId: parsedAttrs.fieldId,
28540
- displayLabel: parsedAttrs.displayLabel,
28541
- defaultDisplayLabel: parsedAttrs.defaultDisplayLabel,
28542
- fieldType: parsedAttrs.fieldType,
28543
- fieldColor: parsedAttrs.fieldColor,
28544
- multipleImage: parsedAttrs.fieldMultipleImage,
28545
- fontFamily: parsedAttrs.fieldFontFamily,
28546
- fontSize: parsedAttrs.fieldFontSize,
28547
- textColor: parsedAttrs.fieldTextColor,
28548
- textHighlight: parsedAttrs.fieldTextHighlight,
28549
- hash: parsedAttrs.hash
28550
- };
28551
- } else {
28552
- attrs = getAttrsFromElements({ sdtPr, tag, alias, sdtId });
28553
- }
28554
- const initialDisplayLabel = getSafeString(attrs.displayLabel);
28555
- const extractedContent = getTextFromSdtContent(sdtContent);
28556
- if (!attrs.defaultDisplayLabel) {
28557
- if (initialDisplayLabel) {
28558
- attrs.defaultDisplayLabel = initialDisplayLabel;
28559
- } else if (aliasLabel) {
28560
- attrs.defaultDisplayLabel = aliasLabel;
27563
+ const translator$H = NodeTranslator.from(config$f);
27564
+ const translator$G = NodeTranslator.from({
27565
+ xmlName: "w:cantSplit",
27566
+ sdNodeOrKeyName: "cantSplit",
27567
+ encode: ({ nodes }) => ["1", "true"].includes(nodes[0].attributes?.["w:val"] ?? "1"),
27568
+ decode: ({ node }) => node.attrs?.cantSplit ? { attributes: {} } : void 0
27569
+ });
27570
+ const translator$F = NodeTranslator.from(createSingleAttrPropertyHandler("w:divId"));
27571
+ const translator$E = NodeTranslator.from(
27572
+ createSingleAttrPropertyHandler(
27573
+ "w:gridAfter",
27574
+ null,
27575
+ "w:val",
27576
+ (v2) => parseInteger(v2) ?? void 0,
27577
+ (v2) => integerToString(v2)
27578
+ )
27579
+ );
27580
+ const translator$D = NodeTranslator.from(
27581
+ createSingleAttrPropertyHandler(
27582
+ "w:gridBefore",
27583
+ null,
27584
+ "w:val",
27585
+ (v2) => parseInteger(v2) ?? void 0,
27586
+ (v2) => integerToString(v2)
27587
+ )
27588
+ );
27589
+ const translator$C = NodeTranslator.from({
27590
+ xmlName: "w:hidden",
27591
+ sdNodeOrKeyName: "hidden",
27592
+ encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
27593
+ decode: ({ node }) => node.attrs.hidden ? { attributes: {} } : void 0
27594
+ });
27595
+ const translator$B = NodeTranslator.from(createSingleAttrPropertyHandler("w:jc", "justification"));
27596
+ const translator$A = NodeTranslator.from(createMeasurementPropertyHandler("w:tblCellSpacing", "tableCellSpacing"));
27597
+ const translator$z = NodeTranslator.from({
27598
+ xmlName: "w:tblHeader",
27599
+ sdNodeOrKeyName: "repeatHeader",
27600
+ encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
27601
+ decode: ({ node }) => node.attrs.repeatHeader ? { attributes: {} } : void 0
27602
+ });
27603
+ const translator$y = NodeTranslator.from({
27604
+ xmlName: "w:trHeight",
27605
+ sdNodeOrKeyName: "rowHeight",
27606
+ encode: ({ nodes }) => {
27607
+ const heightAttrs = {};
27608
+ const val = nodes[0].attributes["w:val"];
27609
+ if (val) {
27610
+ heightAttrs["value"] = parseInt(val, 10);
28561
27611
  }
28562
- }
28563
- const placeholderLabel = getPlaceholderLabel(attrs, aliasLabel);
28564
- const placeholderText = ensurePlaceholderFormat(placeholderLabel);
28565
- const isAnnotationsEnabled = Boolean(params.editor?.options?.annotations);
28566
- const contentIsDistinct = shouldUseSdtContent(extractedContent, placeholderText);
28567
- const shouldUseContent = !isAnnotationsEnabled && contentIsDistinct && (hasMoustache(extractedContent) || !placeholderText);
28568
- if (contentIsDistinct) {
28569
- attrs.displayLabel = extractedContent;
27612
+ const rule = nodes[0].attributes["w:hRule"];
27613
+ if (rule) {
27614
+ heightAttrs["rule"] = rule;
27615
+ }
27616
+ return Object.keys(heightAttrs).length > 0 ? heightAttrs : void 0;
27617
+ },
27618
+ decode: ({ node }) => {
27619
+ if (!node.attrs?.rowHeight) return;
27620
+ const heightAttrs = {};
27621
+ if (typeof node.attrs.rowHeight.value === "number" && !isNaN(node.attrs.rowHeight.value)) {
27622
+ heightAttrs["w:val"] = String(node.attrs.rowHeight.value);
27623
+ }
27624
+ if (node.attrs.rowHeight.rule) {
27625
+ heightAttrs["w:hRule"] = node.attrs.rowHeight.rule;
27626
+ }
27627
+ return Object.keys(heightAttrs).length > 0 ? { attributes: heightAttrs } : void 0;
27628
+ }
27629
+ });
27630
+ const translator$x = NodeTranslator.from(createMeasurementPropertyHandler("w:wAfter"));
27631
+ const translator$w = NodeTranslator.from(createMeasurementPropertyHandler("w:wBefore"));
27632
+ const propertyTranslators$3 = [
27633
+ translator$G,
27634
+ translator$1a,
27635
+ translator$F,
27636
+ translator$E,
27637
+ translator$D,
27638
+ translator$C,
27639
+ translator$B,
27640
+ translator$A,
27641
+ translator$z,
27642
+ translator$y,
27643
+ translator$x,
27644
+ translator$w
27645
+ ];
27646
+ const translator$v = NodeTranslator.from(
27647
+ createNestedPropertiesTranslator("w:trPr", "tableRowProperties", propertyTranslators$3, {
27648
+ cantSplit: false,
27649
+ hidden: false,
27650
+ repeatHeader: false
27651
+ })
27652
+ );
27653
+ const createPlaceholderCell = (gridWidth, reason) => {
27654
+ const safeWidth = Number.isFinite(gridWidth) ? gridWidth : 0;
27655
+ const noBorder = { val: "none", size: 0 };
27656
+ return {
27657
+ type: "tableCell",
27658
+ attrs: {
27659
+ colspan: 1,
27660
+ rowspan: 1,
27661
+ colwidth: [safeWidth],
27662
+ __placeholder: reason,
27663
+ borders: {
27664
+ top: { ...noBorder },
27665
+ right: { ...noBorder },
27666
+ bottom: { ...noBorder },
27667
+ left: { ...noBorder }
27668
+ }
27669
+ },
27670
+ content: [{ type: "paragraph", content: [] }]
27671
+ };
27672
+ };
27673
+ const advancePastRowSpans = (pendingRowSpans, startIndex, totalColumns) => {
27674
+ let index2 = startIndex;
27675
+ while (index2 < totalColumns && pendingRowSpans[index2] > 0) {
27676
+ pendingRowSpans[index2] -= 1;
27677
+ index2 += 1;
27678
+ }
27679
+ return index2;
27680
+ };
27681
+ const fillPlaceholderColumns = ({
27682
+ content,
27683
+ pendingRowSpans,
27684
+ currentIndex,
27685
+ targetIndex,
27686
+ totalColumns,
27687
+ gridColumnWidths,
27688
+ reason
27689
+ }) => {
27690
+ let index2 = currentIndex;
27691
+ while (index2 < targetIndex && index2 < totalColumns) {
27692
+ if (pendingRowSpans[index2] > 0) {
27693
+ pendingRowSpans[index2] -= 1;
27694
+ index2 += 1;
27695
+ continue;
27696
+ }
27697
+ const width = Array.isArray(gridColumnWidths) ? gridColumnWidths[index2] ?? 0 : 0;
27698
+ content.push(createPlaceholderCell(width, reason));
27699
+ index2 += 1;
27700
+ }
27701
+ return index2;
27702
+ };
27703
+ const isPlaceholderCell = (cell) => {
27704
+ if (!cell) return false;
27705
+ if (cell.attrs?.__placeholder) return true;
27706
+ const widths = cell.attrs?.colwidth;
27707
+ if (Array.isArray(widths) && widths.length > 0) {
27708
+ const hasMeaningfulWidth = widths.some(
27709
+ (value) => typeof value === "number" && Number.isFinite(value) && Math.abs(value) > 1
27710
+ );
27711
+ if (!hasMeaningfulWidth) return true;
27712
+ }
27713
+ return false;
27714
+ };
27715
+ const XML_NODE_NAME$f = "w:tr";
27716
+ const SD_NODE_NAME$c = "tableRow";
27717
+ const validXmlAttributes$a = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
27718
+ (xmlName) => createAttributeHandler(xmlName)
27719
+ );
27720
+ const encode$l = (params, encodedAttrs) => {
27721
+ const { row } = params.extraParams;
27722
+ let tableRowProperties = {};
27723
+ const tPr = row.elements.find((el) => el.name === "w:trPr");
27724
+ if (tPr) {
27725
+ tableRowProperties = translator$v.encode({
27726
+ ...params,
27727
+ nodes: [tPr]
27728
+ });
27729
+ }
27730
+ const gridBeforeRaw = tableRowProperties?.["gridBefore"];
27731
+ const safeGridBefore = typeof gridBeforeRaw === "number" && Number.isFinite(gridBeforeRaw) && gridBeforeRaw > 0 ? gridBeforeRaw : 0;
27732
+ encodedAttrs["tableRowProperties"] = Object.freeze(tableRowProperties);
27733
+ encodedAttrs["rowHeight"] = twipsToPixels(tableRowProperties["rowHeight"]?.value);
27734
+ encodedAttrs["cantSplit"] = tableRowProperties["cantSplit"];
27735
+ const { columnWidths: gridColumnWidths, activeRowSpans = [] } = params.extraParams;
27736
+ const totalColumns = Array.isArray(gridColumnWidths) ? gridColumnWidths.length : 0;
27737
+ const pendingRowSpans = Array.isArray(activeRowSpans) ? activeRowSpans.slice() : [];
27738
+ while (pendingRowSpans.length < totalColumns) pendingRowSpans.push(0);
27739
+ const cellNodes = row.elements.filter((el) => el.name === "w:tc");
27740
+ const content = [];
27741
+ let currentColumnIndex = 0;
27742
+ const fillUntil = (target, reason) => {
27743
+ currentColumnIndex = fillPlaceholderColumns({
27744
+ content,
27745
+ pendingRowSpans,
27746
+ currentIndex: currentColumnIndex,
27747
+ targetIndex: target,
27748
+ totalColumns,
27749
+ gridColumnWidths,
27750
+ reason
27751
+ });
27752
+ };
27753
+ const skipOccupiedColumns = () => {
27754
+ currentColumnIndex = advancePastRowSpans(pendingRowSpans, currentColumnIndex, totalColumns);
27755
+ };
27756
+ fillUntil(safeGridBefore, "gridBefore");
27757
+ skipOccupiedColumns();
27758
+ cellNodes?.forEach((node) => {
27759
+ skipOccupiedColumns();
27760
+ const startColumn = currentColumnIndex;
27761
+ const columnWidth = gridColumnWidths?.[startColumn] || null;
27762
+ const result = translator$H.encode({
27763
+ ...params,
27764
+ extraParams: {
27765
+ ...params.extraParams,
27766
+ node,
27767
+ columnIndex: startColumn,
27768
+ columnWidth
27769
+ }
27770
+ });
27771
+ if (result) {
27772
+ content.push(result);
27773
+ const colspan = Math.max(1, result.attrs?.colspan || 1);
27774
+ const rowspan = Math.max(1, result.attrs?.rowspan || 1);
27775
+ if (rowspan > 1) {
27776
+ for (let offset = 0; offset < colspan; offset += 1) {
27777
+ const target = startColumn + offset;
27778
+ if (target < pendingRowSpans.length) {
27779
+ pendingRowSpans[target] = Math.max(pendingRowSpans[target], rowspan - 1);
27780
+ }
27781
+ }
27782
+ }
27783
+ currentColumnIndex = startColumn + colspan;
27784
+ }
27785
+ });
27786
+ skipOccupiedColumns();
27787
+ fillUntil(totalColumns, "gridAfter");
27788
+ const newNode = {
27789
+ type: "tableRow",
27790
+ content,
27791
+ attrs: encodedAttrs
27792
+ };
27793
+ return newNode;
27794
+ };
27795
+ const decode$n = (params, decodedAttrs) => {
27796
+ const { node } = params;
27797
+ const cells = node.content || [];
27798
+ let leadingPlaceholders = 0;
27799
+ while (leadingPlaceholders < cells.length && isPlaceholderCell(cells[leadingPlaceholders])) {
27800
+ leadingPlaceholders += 1;
27801
+ }
27802
+ let trailingPlaceholders = 0;
27803
+ while (trailingPlaceholders < cells.length - leadingPlaceholders && isPlaceholderCell(cells[cells.length - 1 - trailingPlaceholders])) {
27804
+ trailingPlaceholders += 1;
27805
+ }
27806
+ const trimmedSlice = cells.slice(leadingPlaceholders, cells.length - trailingPlaceholders);
27807
+ const sanitizedCells = trimmedSlice.map((cell) => {
27808
+ if (cell?.attrs && "__placeholder" in cell.attrs) {
27809
+ const { __placeholder, ...rest } = cell.attrs;
27810
+ return { ...cell, attrs: rest };
27811
+ }
27812
+ return cell;
27813
+ });
27814
+ const trimmedContent = sanitizedCells.filter((_2, index2) => !isPlaceholderCell(trimmedSlice[index2]));
27815
+ const translateParams = {
27816
+ ...params,
27817
+ node: { ...node, content: trimmedContent }
27818
+ };
27819
+ const elements = translateChildNodes(translateParams);
27820
+ if (node.attrs?.tableRowProperties) {
27821
+ const tableRowProperties = { ...node.attrs.tableRowProperties };
27822
+ if (leadingPlaceholders > 0) {
27823
+ tableRowProperties.gridBefore = leadingPlaceholders;
27824
+ }
27825
+ if (trailingPlaceholders > 0) {
27826
+ tableRowProperties.gridAfter = trailingPlaceholders;
27827
+ }
27828
+ if (node.attrs.rowHeight != null) {
27829
+ const rowHeightPixels = twipsToPixels(node.attrs.tableRowProperties["rowHeight"]?.value);
27830
+ if (rowHeightPixels !== node.attrs.rowHeight) {
27831
+ tableRowProperties["rowHeight"] = { value: String(pixelsToTwips(node.attrs["rowHeight"])) };
27832
+ }
27833
+ }
27834
+ tableRowProperties["cantSplit"] = node.attrs["cantSplit"];
27835
+ const trPr = translator$v.decode({
27836
+ ...params,
27837
+ node: { ...node, attrs: { ...node.attrs, tableRowProperties } }
27838
+ });
27839
+ if (trPr) elements.unshift(trPr);
27840
+ }
27841
+ return {
27842
+ name: "w:tr",
27843
+ attributes: decodedAttrs || {},
27844
+ elements
27845
+ };
27846
+ };
27847
+ const config$e = {
27848
+ xmlName: XML_NODE_NAME$f,
27849
+ sdNodeOrKeyName: SD_NODE_NAME$c,
27850
+ type: NodeTranslator.translatorTypes.NODE,
27851
+ encode: encode$l,
27852
+ decode: decode$n,
27853
+ attributes: validXmlAttributes$a
27854
+ };
27855
+ const translator$u = NodeTranslator.from(config$e);
27856
+ function parseTagValueJSON(json) {
27857
+ if (typeof json !== "string") {
27858
+ return {};
27859
+ }
27860
+ const trimmed = json.trim();
27861
+ if (!trimmed) {
27862
+ return {};
27863
+ }
27864
+ try {
27865
+ return JSON.parse(trimmed);
27866
+ } catch {
27867
+ return {};
27868
+ }
27869
+ }
27870
+ function handleAnnotationNode(params) {
27871
+ const { nodes } = params;
27872
+ if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
27873
+ return null;
27874
+ }
27875
+ const node = nodes[0];
27876
+ const sdtPr = node.elements.find((el) => el.name === "w:sdtPr");
27877
+ const sdtContent = node.elements.find((el) => el.name === "w:sdtContent");
27878
+ const sdtId = sdtPr?.elements?.find((el) => el.name === "w:id");
27879
+ const alias = sdtPr?.elements.find((el) => el.name === "w:alias");
27880
+ const tag = sdtPr?.elements.find((el) => el.name === "w:tag");
27881
+ const tagValue = tag?.attributes["w:val"];
27882
+ const shouldProcessAsJson = tagValue?.startsWith("{") && tagValue?.endsWith("}");
27883
+ let attrs = {};
27884
+ const aliasLabel = getSafeString(alias?.attributes?.["w:val"]);
27885
+ if (shouldProcessAsJson) {
27886
+ const parsedAttrs = parseTagValueJSON(tagValue);
27887
+ attrs = {
27888
+ type: parsedAttrs.fieldTypeShort,
27889
+ fieldId: parsedAttrs.fieldId,
27890
+ displayLabel: parsedAttrs.displayLabel,
27891
+ defaultDisplayLabel: parsedAttrs.defaultDisplayLabel,
27892
+ fieldType: parsedAttrs.fieldType,
27893
+ fieldColor: parsedAttrs.fieldColor,
27894
+ multipleImage: parsedAttrs.fieldMultipleImage,
27895
+ fontFamily: parsedAttrs.fieldFontFamily,
27896
+ fontSize: parsedAttrs.fieldFontSize,
27897
+ textColor: parsedAttrs.fieldTextColor,
27898
+ textHighlight: parsedAttrs.fieldTextHighlight,
27899
+ hash: parsedAttrs.hash
27900
+ };
27901
+ } else {
27902
+ attrs = getAttrsFromElements({ sdtPr, tag, alias, sdtId });
27903
+ }
27904
+ const initialDisplayLabel = getSafeString(attrs.displayLabel);
27905
+ const extractedContent = getTextFromSdtContent(sdtContent);
27906
+ if (!attrs.defaultDisplayLabel) {
27907
+ if (initialDisplayLabel) {
27908
+ attrs.defaultDisplayLabel = initialDisplayLabel;
27909
+ } else if (aliasLabel) {
27910
+ attrs.defaultDisplayLabel = aliasLabel;
27911
+ }
27912
+ }
27913
+ const placeholderLabel = getPlaceholderLabel(attrs, aliasLabel);
27914
+ const placeholderText = ensurePlaceholderFormat(placeholderLabel);
27915
+ const isAnnotationsEnabled = Boolean(params.editor?.options?.annotations);
27916
+ const contentIsDistinct = shouldUseSdtContent(extractedContent, placeholderText);
27917
+ const shouldUseContent = !isAnnotationsEnabled && contentIsDistinct && (hasMoustache(extractedContent) || !placeholderText);
27918
+ if (contentIsDistinct) {
27919
+ attrs.displayLabel = extractedContent;
28570
27920
  } else if (!attrs.displayLabel && placeholderLabel) {
28571
27921
  attrs.displayLabel = placeholderLabel;
28572
27922
  }
@@ -29825,32 +29175,32 @@ function translateAnchorNode(params) {
29825
29175
  elements: [...anchorElements, ...elementsWithWrap]
29826
29176
  };
29827
29177
  }
29828
- const XML_NODE_NAME$c = "wp:anchor";
29829
- const SD_NODE_NAME$a = ["image"];
29178
+ const XML_NODE_NAME$e = "wp:anchor";
29179
+ const SD_NODE_NAME$b = ["image"];
29830
29180
  const validXmlAttributes$9 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
29831
- function encode$i(params) {
29181
+ function encode$k(params) {
29832
29182
  const { node } = params.extraParams;
29833
29183
  if (!node || !node.type) {
29834
29184
  return null;
29835
29185
  }
29836
29186
  return handleAnchorNode(params);
29837
29187
  }
29838
- function decode$k(params) {
29188
+ function decode$m(params) {
29839
29189
  const { node } = params;
29840
29190
  if (!node || !node.type) {
29841
29191
  return null;
29842
29192
  }
29843
29193
  return translateAnchorNode(params);
29844
29194
  }
29845
- const config$b = {
29846
- xmlName: XML_NODE_NAME$c,
29847
- sdNodeOrKeyName: SD_NODE_NAME$a,
29195
+ const config$d = {
29196
+ xmlName: XML_NODE_NAME$e,
29197
+ sdNodeOrKeyName: SD_NODE_NAME$b,
29848
29198
  type: NodeTranslator.translatorTypes.NODE,
29849
- encode: encode$i,
29850
- decode: decode$k,
29199
+ encode: encode$k,
29200
+ decode: decode$m,
29851
29201
  attributes: validXmlAttributes$9
29852
29202
  };
29853
- const translator$b = NodeTranslator.from(config$b);
29203
+ const translator$t = NodeTranslator.from(config$d);
29854
29204
  function handleInlineNode(params) {
29855
29205
  const { node } = params.extraParams;
29856
29206
  if (node.name !== "wp:inline") {
@@ -29866,41 +29216,41 @@ function translateInlineNode(params) {
29866
29216
  elements: nodeElements.elements
29867
29217
  };
29868
29218
  }
29869
- const XML_NODE_NAME$b = "wp:inline";
29870
- const SD_NODE_NAME$9 = ["image"];
29219
+ const XML_NODE_NAME$d = "wp:inline";
29220
+ const SD_NODE_NAME$a = ["image"];
29871
29221
  const validXmlAttributes$8 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
29872
- function encode$h(params) {
29222
+ function encode$j(params) {
29873
29223
  const { node } = params.extraParams;
29874
29224
  if (!node || !node.type) {
29875
29225
  return null;
29876
29226
  }
29877
29227
  return handleInlineNode(params);
29878
29228
  }
29879
- function decode$j(params) {
29229
+ function decode$l(params) {
29880
29230
  const { node } = params;
29881
29231
  if (!node || !node.type) {
29882
29232
  return null;
29883
29233
  }
29884
29234
  return translateInlineNode(params);
29885
29235
  }
29886
- const config$a = {
29887
- xmlName: XML_NODE_NAME$b,
29888
- sdNodeOrKeyName: SD_NODE_NAME$9,
29236
+ const config$c = {
29237
+ xmlName: XML_NODE_NAME$d,
29238
+ sdNodeOrKeyName: SD_NODE_NAME$a,
29889
29239
  type: NodeTranslator.translatorTypes.NODE,
29890
- encode: encode$h,
29891
- decode: decode$j,
29240
+ encode: encode$j,
29241
+ decode: decode$l,
29892
29242
  attributes: validXmlAttributes$8
29893
29243
  };
29894
- const translator$a = NodeTranslator.from(config$a);
29895
- const XML_NODE_NAME$a = "w:drawing";
29896
- const SD_NODE_NAME$8 = [];
29244
+ const translator$s = NodeTranslator.from(config$c);
29245
+ const XML_NODE_NAME$c = "w:drawing";
29246
+ const SD_NODE_NAME$9 = [];
29897
29247
  const validXmlAttributes$7 = [];
29898
- function encode$g(params) {
29248
+ function encode$i(params) {
29899
29249
  const nodes = params.nodes;
29900
29250
  const node = nodes[0];
29901
29251
  const translatorByChildName = {
29902
- "wp:anchor": translator$b,
29903
- "wp:inline": translator$a
29252
+ "wp:anchor": translator$t,
29253
+ "wp:inline": translator$s
29904
29254
  };
29905
29255
  return node.elements.reduce((acc, child) => {
29906
29256
  if (acc) return acc;
@@ -29909,12 +29259,12 @@ function encode$g(params) {
29909
29259
  return translator2.encode({ ...params, extraParams: { node: child } }) || acc;
29910
29260
  }, null);
29911
29261
  }
29912
- function decode$i(params) {
29262
+ function decode$k(params) {
29913
29263
  const { node } = params;
29914
29264
  if (!node || !node.type) {
29915
29265
  return null;
29916
29266
  }
29917
- const childTranslator = node.attrs.isAnchor ? translator$b : translator$a;
29267
+ const childTranslator = node.attrs.isAnchor ? translator$t : translator$s;
29918
29268
  const resultNode = childTranslator.decode(params);
29919
29269
  return wrapTextInRun(
29920
29270
  {
@@ -29924,15 +29274,15 @@ function decode$i(params) {
29924
29274
  []
29925
29275
  );
29926
29276
  }
29927
- const config$9 = {
29928
- xmlName: XML_NODE_NAME$a,
29929
- sdNodeOrKeyName: SD_NODE_NAME$8,
29277
+ const config$b = {
29278
+ xmlName: XML_NODE_NAME$c,
29279
+ sdNodeOrKeyName: SD_NODE_NAME$9,
29930
29280
  type: NodeTranslator.translatorTypes.NODE,
29931
- encode: encode$g,
29932
- decode: decode$i,
29281
+ encode: encode$i,
29282
+ decode: decode$k,
29933
29283
  attributes: validXmlAttributes$7
29934
29284
  };
29935
- const translator$9 = NodeTranslator.from(config$9);
29285
+ const translator$r = NodeTranslator.from(config$b);
29936
29286
  class CommandService {
29937
29287
  /**
29938
29288
  * @param {import('./commands/types/index.js').CommandServiceOptions} props
@@ -31280,7 +30630,7 @@ function prepareTextAnnotation(params) {
31280
30630
  return getTextNodeForExport(attrs.displayLabel, [...marks, ...marksFromAttrs], params);
31281
30631
  }
31282
30632
  function prepareImageAnnotation(params, imageSize) {
31283
- return translator$9.decode({
30633
+ return translator$r.decode({
31284
30634
  ...params,
31285
30635
  imageSize
31286
30636
  });
@@ -31595,10 +30945,10 @@ function generateSdtPrTagForStructuredContent({ node }) {
31595
30945
  };
31596
30946
  return result;
31597
30947
  }
31598
- const XML_NODE_NAME$9 = "w:sdt";
31599
- const SD_NODE_NAME$7 = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
30948
+ const XML_NODE_NAME$b = "w:sdt";
30949
+ const SD_NODE_NAME$8 = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
31600
30950
  const validXmlAttributes$6 = [];
31601
- function encode$f(params) {
30951
+ function encode$h(params) {
31602
30952
  const nodes = params.nodes;
31603
30953
  const node = nodes[0];
31604
30954
  const { type: sdtType, handler: handler2 } = sdtNodeTypeStrategy(node);
@@ -31608,7 +30958,7 @@ function encode$f(params) {
31608
30958
  const result = handler2(params);
31609
30959
  return result;
31610
30960
  }
31611
- function decode$h(params) {
30961
+ function decode$j(params) {
31612
30962
  const { node } = params;
31613
30963
  if (!node || !node.type) {
31614
30964
  return null;
@@ -31626,13 +30976,590 @@ function decode$h(params) {
31626
30976
  const result = decoder();
31627
30977
  return result;
31628
30978
  }
30979
+ const config$a = {
30980
+ xmlName: XML_NODE_NAME$b,
30981
+ sdNodeOrKeyName: SD_NODE_NAME$8,
30982
+ type: NodeTranslator.translatorTypes.NODE,
30983
+ encode: encode$h,
30984
+ decode: decode$j,
30985
+ attributes: validXmlAttributes$6
30986
+ };
30987
+ const translator$q = NodeTranslator.from(config$a);
30988
+ function preProcessVerticalMergeCells(table, { editorSchema }) {
30989
+ if (!table || !Array.isArray(table.content)) {
30990
+ return table;
30991
+ }
30992
+ const rows = table.content;
30993
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
30994
+ const row = rows[rowIndex];
30995
+ if (!row) continue;
30996
+ if (!Array.isArray(row.content)) {
30997
+ row.content = [];
30998
+ }
30999
+ for (let cellIndex = 0; cellIndex < row.content.length; cellIndex++) {
31000
+ const cell = row.content[cellIndex];
31001
+ if (!cell) continue;
31002
+ const attrs = cell.attrs || {};
31003
+ if (!attrs.rowspan || attrs.rowspan <= 1) continue;
31004
+ const maxRowspan = Math.min(attrs.rowspan, rows.length - rowIndex);
31005
+ for (let offset = 1; offset < maxRowspan; offset++) {
31006
+ const rowToChange = rows[rowIndex + offset];
31007
+ if (!rowToChange) continue;
31008
+ if (!Array.isArray(rowToChange.content)) {
31009
+ rowToChange.content = [];
31010
+ }
31011
+ const existingCell = rowToChange.content[cellIndex];
31012
+ if (existingCell?.attrs?.continueMerge) continue;
31013
+ const mergedCell = {
31014
+ type: cell.type,
31015
+ content: [editorSchema.nodes.paragraph.createAndFill().toJSON()],
31016
+ attrs: {
31017
+ ...cell.attrs,
31018
+ rowspan: null,
31019
+ continueMerge: true
31020
+ }
31021
+ };
31022
+ rowToChange.content.splice(cellIndex, 0, mergedCell);
31023
+ }
31024
+ }
31025
+ }
31026
+ return table;
31027
+ }
31028
+ const translator$p = NodeTranslator.from({
31029
+ xmlName: "w:bidiVisual",
31030
+ sdNodeOrKeyName: "rightToLeft",
31031
+ encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
31032
+ decode: ({ node }) => node.attrs.rightToLeft ? { attributes: {} } : void 0
31033
+ });
31034
+ const translator$o = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblCaption", "caption"));
31035
+ const translator$n = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblDescription", "description"));
31036
+ const translator$m = NodeTranslator.from(createMeasurementPropertyHandler("w:tblInd", "tableIndent"));
31037
+ const translator$l = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblLayout", "tableLayout", "w:type"));
31038
+ const translator$k = NodeTranslator.from({
31039
+ xmlName: "w:tblLook",
31040
+ sdNodeOrKeyName: "tblLook",
31041
+ attributes: ["w:firstColumn", "w:firstRow", "w:lastColumn", "w:lastRow", "w:noHBand", "w:noVBand"].map((attr) => createAttributeHandler(attr, null, parseBoolean, booleanToString)).concat([createAttributeHandler("w:val")]),
31042
+ encode: (params, encodedAttrs) => {
31043
+ return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
31044
+ },
31045
+ decode: function({ node }, context) {
31046
+ const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.tblLook || {} } });
31047
+ return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
31048
+ }
31049
+ });
31050
+ const translator$j = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblOverlap", "overlap"));
31051
+ const translator$i = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblStyle", "tableStyleId"));
31052
+ const translator$h = NodeTranslator.from(
31053
+ createSingleAttrPropertyHandler("w:tblStyleColBandSize", "tableStyleColBandSize")
31054
+ );
31055
+ const translator$g = NodeTranslator.from(
31056
+ createSingleAttrPropertyHandler("w:tblStyleRowBandSize", "tableStyleRowBandSize")
31057
+ );
31058
+ const translator$f = NodeTranslator.from(createMeasurementPropertyHandler("w:tblW", "tableWidth"));
31059
+ const translator$e = NodeTranslator.from({
31060
+ xmlName: "w:tblpPr",
31061
+ sdNodeOrKeyName: "floatingTableProperties",
31062
+ 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))),
31063
+ encode: (params, encodedAttrs) => {
31064
+ return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
31065
+ },
31066
+ decode: function({ node }, context) {
31067
+ const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.floatingTableProperties || {} } });
31068
+ return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
31069
+ }
31070
+ });
31071
+ const propertyTranslators$2 = [
31072
+ translator$15,
31073
+ translator$13,
31074
+ translator$11,
31075
+ translator$10,
31076
+ translator$$,
31077
+ translator$Z,
31078
+ translator$X,
31079
+ translator$V
31080
+ ];
31081
+ const translator$d = NodeTranslator.from(
31082
+ createNestedPropertiesTranslator("w:tblBorders", "borders", propertyTranslators$2)
31083
+ );
31084
+ const propertyTranslators$1 = [
31085
+ translator$14,
31086
+ translator$12,
31087
+ translator$_,
31088
+ translator$Y,
31089
+ translator$W,
31090
+ translator$U
31091
+ ];
31092
+ const translator$c = NodeTranslator.from(
31093
+ createNestedPropertiesTranslator("w:tblCellMar", "cellMargins", propertyTranslators$1)
31094
+ );
31095
+ const propertyTranslators = [
31096
+ translator$p,
31097
+ translator$B,
31098
+ translator$19,
31099
+ translator$o,
31100
+ translator$A,
31101
+ translator$n,
31102
+ translator$m,
31103
+ translator$l,
31104
+ translator$k,
31105
+ translator$j,
31106
+ translator$i,
31107
+ translator$h,
31108
+ translator$g,
31109
+ translator$f,
31110
+ translator$e,
31111
+ translator$d,
31112
+ translator$c
31113
+ ];
31114
+ const translator$b = NodeTranslator.from(
31115
+ createNestedPropertiesTranslator("w:tblPr", "tableProperties", propertyTranslators)
31116
+ );
31117
+ const translator$a = NodeTranslator.from(
31118
+ createSingleAttrPropertyHandler("w:gridCol", "col", "w:w", parseInteger, integerToString)
31119
+ );
31120
+ const DEFAULT_COLUMN_WIDTH_PX = 100;
31121
+ const normalizeTwipWidth = (value) => {
31122
+ if (value == null) return null;
31123
+ const numericValue = typeof value === "string" ? parseInt(value, 10) : value;
31124
+ if (!Number.isFinite(numericValue) || Number.isNaN(numericValue) || numericValue <= 0) {
31125
+ return null;
31126
+ }
31127
+ return numericValue;
31128
+ };
31129
+ const getSchemaDefaultColumnWidthPx = (params) => {
31130
+ const defaultValue = params?.editor?.schema?.nodes?.tableCell?.spec?.attrs?.colwidth?.default;
31131
+ if (Array.isArray(defaultValue)) {
31132
+ const numericWidth = defaultValue.find((width) => typeof width === "number" && Number.isFinite(width) && width > 0);
31133
+ if (numericWidth != null) return numericWidth;
31134
+ } else if (typeof defaultValue === "number" && Number.isFinite(defaultValue) && defaultValue > 0) {
31135
+ return defaultValue;
31136
+ }
31137
+ return DEFAULT_COLUMN_WIDTH_PX;
31138
+ };
31139
+ const getTableWidthPx = (params) => {
31140
+ const explicitWidth = params?.node?.attrs?.tableWidth?.width;
31141
+ if (typeof explicitWidth === "number" && explicitWidth > 0) return explicitWidth;
31142
+ const tableWidth = params?.node?.attrs?.tableProperties?.tableWidth;
31143
+ if (tableWidth?.value != null && typeof tableWidth.value === "number" && tableWidth.value > 0) {
31144
+ const { value, type: type2 } = tableWidth;
31145
+ if (!type2 || type2 === "auto" || type2 === "dxa") {
31146
+ return twipsToPixels(value);
31147
+ }
31148
+ }
31149
+ return null;
31150
+ };
31151
+ const resolveFallbackColumnWidthTwips = (params, totalColumns, cellMinWidthTwips) => {
31152
+ const columnCount = Math.max(totalColumns, 1);
31153
+ const defaultColumnWidthPx = getSchemaDefaultColumnWidthPx(params);
31154
+ const tableWidthPx = getTableWidthPx(params);
31155
+ const safeDefaultPx = Number.isFinite(defaultColumnWidthPx) && defaultColumnWidthPx > 0 ? defaultColumnWidthPx : DEFAULT_COLUMN_WIDTH_PX;
31156
+ let fallbackWidthPx = safeDefaultPx;
31157
+ if (typeof tableWidthPx === "number" && tableWidthPx > 0) {
31158
+ fallbackWidthPx = tableWidthPx / columnCount;
31159
+ }
31160
+ const fallbackWidthTwips = pixelsToTwips(fallbackWidthPx);
31161
+ if (!Number.isFinite(fallbackWidthTwips) || Number.isNaN(fallbackWidthTwips) || fallbackWidthTwips <= 0) {
31162
+ const safeDefault = Math.max(pixelsToTwips(safeDefaultPx), cellMinWidthTwips);
31163
+ return safeDefault;
31164
+ }
31165
+ return Math.max(fallbackWidthTwips, cellMinWidthTwips);
31166
+ };
31167
+ const XML_NODE_NAME$a = "w:tblGrid";
31168
+ const SD_ATTR_KEY$2 = "grid";
31169
+ const cellMinWidth = pixelsToTwips(10);
31170
+ const encode$g = (params) => {
31171
+ const { nodes } = params;
31172
+ const node = nodes[0];
31173
+ const attributes = encodeProperties(node, { [translator$a.xmlName]: translator$a }, true);
31174
+ return {
31175
+ xmlName: XML_NODE_NAME$a,
31176
+ sdNodeOrKeyName: SD_ATTR_KEY$2,
31177
+ attributes
31178
+ };
31179
+ };
31180
+ const decode$i = (params) => {
31181
+ const { grid: rawGrid } = params.node.attrs || {};
31182
+ const grid = Array.isArray(rawGrid) ? rawGrid : [];
31183
+ const { firstRow = {} } = params.extraParams || {};
31184
+ const cellNodes = firstRow.content?.filter((n) => n.type === "tableCell") ?? [];
31185
+ const columnCountFromCells = cellNodes.reduce((count, cell) => {
31186
+ const spanCount = Math.max(1, cell?.attrs?.colspan ?? 1);
31187
+ return count + spanCount;
31188
+ }, 0);
31189
+ const totalColumns = Math.max(columnCountFromCells, grid.length);
31190
+ const fallbackColumnWidthTwips = resolveFallbackColumnWidthTwips(params, totalColumns, cellMinWidth);
31191
+ const elements = [];
31192
+ let columnIndex = 0;
31193
+ const pushColumn = (widthTwips, { enforceMinimum = false } = {}) => {
31194
+ let numericWidth = typeof widthTwips === "string" ? parseInt(widthTwips, 10) : widthTwips;
31195
+ let shouldEnforceMinimum = enforceMinimum;
31196
+ if (numericWidth == null || Number.isNaN(numericWidth) || numericWidth <= 0) {
31197
+ numericWidth = fallbackColumnWidthTwips;
31198
+ shouldEnforceMinimum = true;
31199
+ }
31200
+ const roundedWidth = Math.round(numericWidth);
31201
+ const minimumWidth = shouldEnforceMinimum ? cellMinWidth : 1;
31202
+ const safeWidth = Math.max(roundedWidth, minimumWidth);
31203
+ const decoded = translator$a.decode({
31204
+ node: { type: (
31205
+ /** @type {string} */
31206
+ translator$a.sdNodeOrKeyName
31207
+ ), attrs: { col: safeWidth } }
31208
+ });
31209
+ if (decoded) elements.push(decoded);
31210
+ };
31211
+ cellNodes.forEach((cell) => {
31212
+ const { colspan = 1, colwidth } = cell?.attrs || {};
31213
+ const spanCount = Math.max(1, colspan);
31214
+ for (let span = 0; span < spanCount; span++) {
31215
+ const rawWidth = Array.isArray(colwidth) ? colwidth[span] : void 0;
31216
+ const cellWidthPixels = typeof rawWidth === "number" && Number.isFinite(rawWidth) ? rawWidth : Number(rawWidth);
31217
+ const hasCellWidth = Number.isFinite(cellWidthPixels) && cellWidthPixels > 0;
31218
+ const colGridAttrs = grid?.[columnIndex] || {};
31219
+ const gridWidthTwips = normalizeTwipWidth(colGridAttrs.col);
31220
+ const gridWidthPixels = gridWidthTwips != null ? twipsToPixels(gridWidthTwips) : null;
31221
+ let cellWidthTwips;
31222
+ let enforceMinimum = false;
31223
+ if (hasCellWidth) {
31224
+ const tolerance = 0.5;
31225
+ if (gridWidthTwips != null && gridWidthPixels != null && Math.abs(gridWidthPixels - cellWidthPixels) <= tolerance) {
31226
+ cellWidthTwips = gridWidthTwips;
31227
+ } else {
31228
+ cellWidthTwips = pixelsToTwips(cellWidthPixels);
31229
+ }
31230
+ } else if (gridWidthTwips != null) {
31231
+ cellWidthTwips = gridWidthTwips;
31232
+ } else {
31233
+ cellWidthTwips = fallbackColumnWidthTwips;
31234
+ enforceMinimum = true;
31235
+ }
31236
+ pushColumn(cellWidthTwips, { enforceMinimum });
31237
+ columnIndex++;
31238
+ }
31239
+ });
31240
+ while (columnIndex < grid.length) {
31241
+ const gridWidthTwips = normalizeTwipWidth(grid[columnIndex]?.col);
31242
+ pushColumn(gridWidthTwips);
31243
+ columnIndex++;
31244
+ }
31245
+ const newNode = {
31246
+ name: XML_NODE_NAME$a,
31247
+ attributes: {},
31248
+ elements
31249
+ };
31250
+ return newNode;
31251
+ };
31252
+ const config$9 = {
31253
+ xmlName: XML_NODE_NAME$a,
31254
+ sdNodeOrKeyName: SD_ATTR_KEY$2,
31255
+ encode: encode$g,
31256
+ decode: decode$i
31257
+ };
31258
+ const translator$9 = NodeTranslator.from(config$9);
31259
+ const DEFAULT_PAGE_WIDTH_TWIPS = 12240;
31260
+ const DEFAULT_PAGE_MARGIN_TWIPS = 1440;
31261
+ const DEFAULT_CONTENT_WIDTH_TWIPS = DEFAULT_PAGE_WIDTH_TWIPS - 2 * DEFAULT_PAGE_MARGIN_TWIPS;
31262
+ const MIN_COLUMN_WIDTH_TWIPS = pixelsToTwips(10);
31263
+ const pctToPercent = (value) => {
31264
+ if (value == null) return null;
31265
+ return value / 50;
31266
+ };
31267
+ const resolveContentWidthTwips = () => DEFAULT_CONTENT_WIDTH_TWIPS;
31268
+ const resolveMeasurementWidthPx = (measurement) => {
31269
+ if (!measurement || typeof measurement.value !== "number" || measurement.value <= 0) return null;
31270
+ const { value, type: type2 } = measurement;
31271
+ if (!type2 || type2 === "auto") return null;
31272
+ if (type2 === "dxa") return twipsToPixels(value);
31273
+ if (type2 === "pct") {
31274
+ const percent = pctToPercent(value);
31275
+ if (percent == null || percent <= 0) return null;
31276
+ const widthTwips = resolveContentWidthTwips() * percent / 100;
31277
+ return twipsToPixels(widthTwips);
31278
+ }
31279
+ return null;
31280
+ };
31281
+ const countColumnsInRow = (row) => {
31282
+ if (!row?.elements?.length) return 0;
31283
+ return row.elements.reduce((count, element) => {
31284
+ if (element.name !== "w:tc") return count;
31285
+ const tcPr = element.elements?.find((el) => el.name === "w:tcPr");
31286
+ const gridSpan = tcPr?.elements?.find((el) => el.name === "w:gridSpan");
31287
+ const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
31288
+ return count + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
31289
+ }, 0);
31290
+ };
31291
+ const clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS);
31292
+ const createFallbackGrid = (columnCount, columnWidthTwips) => Array.from({ length: columnCount }, () => ({ col: clampColumnWidthTwips(columnWidthTwips) }));
31293
+ const buildFallbackGridForTable = ({ params, rows, tableWidth, tableWidthMeasurement }) => {
31294
+ const firstRow = rows.find((row) => row.elements?.some((el) => el.name === "w:tc"));
31295
+ const columnCount = countColumnsInRow(firstRow);
31296
+ if (!columnCount) return null;
31297
+ const schemaDefaultPx = getSchemaDefaultColumnWidthPx(
31298
+ /** @type {any} */
31299
+ params
31300
+ );
31301
+ const minimumColumnWidthPx = Number.isFinite(schemaDefaultPx) && schemaDefaultPx > 0 ? schemaDefaultPx : DEFAULT_COLUMN_WIDTH_PX;
31302
+ let totalWidthPx;
31303
+ if (tableWidthMeasurement) {
31304
+ const resolved = resolveMeasurementWidthPx(tableWidthMeasurement);
31305
+ if (resolved != null) totalWidthPx = resolved;
31306
+ }
31307
+ if (totalWidthPx == null && tableWidth?.width && tableWidth.width > 0) {
31308
+ totalWidthPx = tableWidth.width;
31309
+ }
31310
+ if (totalWidthPx == null) {
31311
+ totalWidthPx = minimumColumnWidthPx * columnCount;
31312
+ }
31313
+ const rawColumnWidthPx = Math.max(totalWidthPx / columnCount, minimumColumnWidthPx);
31314
+ const columnWidthTwips = clampColumnWidthTwips(pixelsToTwips(rawColumnWidthPx));
31315
+ const fallbackColumnWidthPx = twipsToPixels(columnWidthTwips);
31316
+ return {
31317
+ grid: createFallbackGrid(columnCount, columnWidthTwips),
31318
+ columnWidths: Array(columnCount).fill(fallbackColumnWidthPx)
31319
+ };
31320
+ };
31321
+ const XML_NODE_NAME$9 = "w:tbl";
31322
+ const SD_NODE_NAME$7 = "table";
31323
+ const encode$f = (params, encodedAttrs) => {
31324
+ const { nodes } = params;
31325
+ const node = nodes[0];
31326
+ const tblPr = node.elements.find((el) => el.name === "w:tblPr");
31327
+ if (tblPr) {
31328
+ const encodedProperties = translator$b.encode({ ...params, nodes: [tblPr] });
31329
+ encodedAttrs["tableProperties"] = encodedProperties || {};
31330
+ }
31331
+ const tblGrid = node.elements.find((el) => el.name === "w:tblGrid");
31332
+ if (tblGrid) {
31333
+ encodedAttrs["grid"] = translator$9.encode({ ...params, nodes: [tblGrid] }).attributes;
31334
+ }
31335
+ [
31336
+ "tableStyleId",
31337
+ "justification",
31338
+ "tableLayout",
31339
+ ["tableIndent", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
31340
+ ["tableCellSpacing", ({ value, type: type2 }) => ({ w: String(value), type: type2 })]
31341
+ ].forEach((prop) => {
31342
+ let key;
31343
+ let transform;
31344
+ if (Array.isArray(prop)) {
31345
+ [key, transform] = prop;
31346
+ } else {
31347
+ key = prop;
31348
+ transform = (v2) => v2;
31349
+ }
31350
+ if (encodedAttrs.tableProperties && encodedAttrs.tableProperties[key]) {
31351
+ encodedAttrs[key] = transform(encodedAttrs.tableProperties[key]);
31352
+ }
31353
+ });
31354
+ if (encodedAttrs.tableCellSpacing) {
31355
+ encodedAttrs["borderCollapse"] = "separate";
31356
+ }
31357
+ if (encodedAttrs.tableProperties?.tableWidth) {
31358
+ const tableWidthMeasurement = encodedAttrs.tableProperties.tableWidth;
31359
+ const widthPx = twipsToPixels(tableWidthMeasurement.value);
31360
+ if (widthPx != null) {
31361
+ encodedAttrs.tableWidth = {
31362
+ width: widthPx,
31363
+ type: tableWidthMeasurement.type
31364
+ };
31365
+ } else if (tableWidthMeasurement.type === "auto") {
31366
+ encodedAttrs.tableWidth = {
31367
+ width: 0,
31368
+ type: tableWidthMeasurement.type
31369
+ };
31370
+ }
31371
+ }
31372
+ const { borders, rowBorders } = _processTableBorders(encodedAttrs.tableProperties?.borders || {});
31373
+ const referencedStyles = _getReferencedTableStyles(encodedAttrs.tableStyleId, params);
31374
+ if (referencedStyles?.cellMargins && !encodedAttrs.tableProperties?.cellMargins) {
31375
+ encodedAttrs.tableProperties = {
31376
+ ...encodedAttrs.tableProperties || {},
31377
+ cellMargins: referencedStyles.cellMargins
31378
+ };
31379
+ }
31380
+ const rows = node.elements.filter((el) => el.name === "w:tr");
31381
+ const borderData = Object.assign({}, referencedStyles?.borders || {}, borders || {});
31382
+ const borderRowData = Object.assign({}, referencedStyles?.rowBorders || {}, rowBorders || {});
31383
+ encodedAttrs["borders"] = borderData;
31384
+ let columnWidths = Array.isArray(encodedAttrs["grid"]) ? encodedAttrs["grid"].map((item) => twipsToPixels(item.col)) : [];
31385
+ if (!columnWidths.length) {
31386
+ const fallback = buildFallbackGridForTable({
31387
+ params,
31388
+ rows,
31389
+ tableWidth: encodedAttrs.tableWidth,
31390
+ tableWidthMeasurement: encodedAttrs.tableProperties?.tableWidth
31391
+ });
31392
+ if (fallback) {
31393
+ encodedAttrs.grid = fallback.grid;
31394
+ columnWidths = fallback.columnWidths;
31395
+ }
31396
+ }
31397
+ const content = [];
31398
+ const totalColumns = columnWidths.length;
31399
+ const activeRowSpans = totalColumns > 0 ? new Array(totalColumns).fill(0) : [];
31400
+ rows.forEach((row, rowIndex) => {
31401
+ const result = translator$u.encode({
31402
+ ...params,
31403
+ nodes: [row],
31404
+ extraParams: {
31405
+ row,
31406
+ table: node,
31407
+ rowBorders: borderRowData,
31408
+ columnWidths,
31409
+ activeRowSpans: activeRowSpans.slice(),
31410
+ rowIndex,
31411
+ _referencedStyles: referencedStyles
31412
+ }
31413
+ });
31414
+ if (result) {
31415
+ content.push(result);
31416
+ if (totalColumns > 0) {
31417
+ const activeRowSpansForCurrentRow = activeRowSpans.slice();
31418
+ for (let col = 0; col < totalColumns; col++) {
31419
+ if (activeRowSpans[col] > 0) {
31420
+ activeRowSpans[col] -= 1;
31421
+ }
31422
+ }
31423
+ let columnIndex = 0;
31424
+ const advanceColumnIndex = () => {
31425
+ while (columnIndex < totalColumns && activeRowSpansForCurrentRow[columnIndex] > 0) {
31426
+ columnIndex += 1;
31427
+ }
31428
+ };
31429
+ advanceColumnIndex();
31430
+ result.content?.forEach((cell) => {
31431
+ advanceColumnIndex();
31432
+ const colspan = Math.max(1, cell.attrs?.colspan || 1);
31433
+ const rowspan = Math.max(1, cell.attrs?.rowspan || 1);
31434
+ if (rowspan > 1) {
31435
+ for (let offset = 0; offset < colspan && columnIndex + offset < totalColumns; offset++) {
31436
+ const targetIndex = columnIndex + offset;
31437
+ const remainingRows = rowspan - 1;
31438
+ if (remainingRows > 0 && remainingRows > activeRowSpans[targetIndex]) {
31439
+ activeRowSpans[targetIndex] = remainingRows;
31440
+ }
31441
+ }
31442
+ }
31443
+ columnIndex += colspan;
31444
+ advanceColumnIndex();
31445
+ });
31446
+ }
31447
+ }
31448
+ });
31449
+ return {
31450
+ type: "table",
31451
+ content,
31452
+ attrs: encodedAttrs
31453
+ };
31454
+ };
31455
+ const decode$h = (params, decodedAttrs) => {
31456
+ params.node = preProcessVerticalMergeCells(params.node, params);
31457
+ const { node } = params;
31458
+ const elements = translateChildNodes(params);
31459
+ const firstRow = node.content?.find((n) => n.type === "tableRow");
31460
+ const properties = node.attrs.grid;
31461
+ const element = translator$9.decode({
31462
+ ...params,
31463
+ node: { ...node, attrs: { ...node.attrs, grid: properties } },
31464
+ extraParams: {
31465
+ firstRow
31466
+ }
31467
+ });
31468
+ if (element) elements.unshift(element);
31469
+ if (node.attrs?.tableProperties) {
31470
+ const properties2 = { ...node.attrs.tableProperties };
31471
+ const element2 = translator$b.decode({
31472
+ ...params,
31473
+ node: { ...node, attrs: { ...node.attrs, tableProperties: properties2 } }
31474
+ });
31475
+ if (element2) elements.unshift(element2);
31476
+ }
31477
+ return {
31478
+ name: "w:tbl",
31479
+ attributes: decodedAttrs || {},
31480
+ elements
31481
+ };
31482
+ };
31483
+ function _processTableBorders(rawBorders) {
31484
+ const borders = {};
31485
+ const rowBorders = {};
31486
+ Object.entries(rawBorders).forEach(([name, attributes]) => {
31487
+ const attrs = {};
31488
+ const color = attributes.color;
31489
+ const size = attributes.size;
31490
+ if (color && color !== "auto") attrs["color"] = color.startsWith("#") ? color : `#${color}`;
31491
+ if (size && size !== "auto") attrs["size"] = eighthPointsToPixels(size);
31492
+ const rowBorderNames = ["insideH", "insideV"];
31493
+ if (rowBorderNames.includes(name)) rowBorders[name] = attrs;
31494
+ borders[name] = attrs;
31495
+ });
31496
+ return {
31497
+ borders,
31498
+ rowBorders
31499
+ };
31500
+ }
31501
+ function _getReferencedTableStyles(tableStyleReference, params) {
31502
+ if (!tableStyleReference) return null;
31503
+ const stylesToReturn = {};
31504
+ const { docx } = params;
31505
+ const styles = docx["word/styles.xml"];
31506
+ const { elements } = styles.elements[0];
31507
+ const styleElements = elements.filter((el) => el.name === "w:style");
31508
+ const styleTag = styleElements.find((el) => el.attributes["w:styleId"] === tableStyleReference);
31509
+ if (!styleTag) return null;
31510
+ stylesToReturn.name = styleTag.elements.find((el) => el.name === "w:name");
31511
+ const basedOn = styleTag.elements.find((el) => el.name === "w:basedOn");
31512
+ let baseTblPr;
31513
+ if (basedOn?.attributes) {
31514
+ const baseStyles = styleElements.find((el) => el.attributes["w:styleId"] === basedOn.attributes["w:val"]);
31515
+ baseTblPr = baseStyles ? baseStyles.elements.find((el) => el.name === "w:tblPr") : {};
31516
+ }
31517
+ const pPr = styleTag.elements.find((el) => el.name === "w:pPr");
31518
+ if (pPr) {
31519
+ const justification = pPr.elements.find((el) => el.name === "w:jc");
31520
+ if (justification?.attributes) stylesToReturn.justification = justification.attributes["w:val"];
31521
+ }
31522
+ const rPr = styleTag?.elements.find((el) => el.name === "w:rPr");
31523
+ if (rPr) {
31524
+ const fonts = rPr.elements.find((el) => el.name === "w:rFonts");
31525
+ if (fonts) {
31526
+ const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
31527
+ stylesToReturn.fonts = { ascii, hAnsi, cs };
31528
+ }
31529
+ const fontSize = rPr.elements.find((el) => el.name === "w:sz");
31530
+ if (fontSize?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize.attributes["w:val"]) + "pt";
31531
+ }
31532
+ const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
31533
+ if (tblPr && tblPr.elements) {
31534
+ if (baseTblPr && baseTblPr.elements) {
31535
+ tblPr.elements.push(...baseTblPr.elements);
31536
+ }
31537
+ const tableProperties = translator$b.encode({ ...params, nodes: [tblPr] });
31538
+ if (tableProperties) {
31539
+ const { borders, rowBorders } = _processTableBorders(tableProperties.borders || {});
31540
+ if (borders) stylesToReturn.borders = borders;
31541
+ if (rowBorders) stylesToReturn.rowBorders = rowBorders;
31542
+ const cellMargins = {};
31543
+ Object.entries(tableProperties.cellMargins || {}).forEach(([key, attrs]) => {
31544
+ if (attrs?.value != null) {
31545
+ cellMargins[key] = {
31546
+ value: attrs.value,
31547
+ type: attrs.type || "dxa"
31548
+ };
31549
+ }
31550
+ });
31551
+ if (Object.keys(cellMargins).length) stylesToReturn.cellMargins = cellMargins;
31552
+ }
31553
+ }
31554
+ return stylesToReturn;
31555
+ }
31629
31556
  const config$8 = {
31630
31557
  xmlName: XML_NODE_NAME$9,
31631
31558
  sdNodeOrKeyName: SD_NODE_NAME$7,
31632
31559
  type: NodeTranslator.translatorTypes.NODE,
31633
31560
  encode: encode$f,
31634
31561
  decode: decode$h,
31635
- attributes: validXmlAttributes$6
31562
+ attributes: []
31636
31563
  };
31637
31564
  const translator$8 = NodeTranslator.from(config$8);
31638
31565
  const encode$e = (attributes) => {
@@ -32147,7 +32074,7 @@ const handleDrawingNode = (params) => {
32147
32074
  if (mainNode.name === "w:drawing") node = mainNode;
32148
32075
  else node = mainNode.elements.find((el) => el.name === "w:drawing");
32149
32076
  if (!node) return { nodes: [], consumed: 0 };
32150
- const schemaNode = translator$9.encode(params);
32077
+ const schemaNode = translator$r.encode(params);
32151
32078
  const newNodes = schemaNode ? [schemaNode] : [];
32152
32079
  return { nodes: newNodes, consumed: 1 };
32153
32080
  };
@@ -32456,7 +32383,7 @@ const handleSdtNode = (params) => {
32456
32383
  if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
32457
32384
  return { nodes: [], consumed: 0 };
32458
32385
  }
32459
- const result = translator$8.encode(params);
32386
+ const result = translator$q.encode(params);
32460
32387
  if (!result) {
32461
32388
  return { nodes: [], consumed: 0 };
32462
32389
  }
@@ -33250,6 +33177,7 @@ const tabNodeEntityHandler = {
33250
33177
  handlerName: "w:tabTranslator",
33251
33178
  handler: handleTabNode
33252
33179
  };
33180
+ const tableNodeHandlerEntity = generateV2HandlerEntity("tableNodeHandler", translator$8);
33253
33181
  const tableOfContentsHandlerEntity = generateV2HandlerEntity("tableOfContentsHandler", translator$4);
33254
33182
  function preProcessPageInstruction(nodesToCombine) {
33255
33183
  const pageNumNode = {
@@ -34259,14 +34187,14 @@ function exportSchemaToJson(params) {
34259
34187
  bulletList: translateList,
34260
34188
  orderedList: translateList,
34261
34189
  lineBreak: translator$1r,
34262
- table: translator$s,
34263
- tableRow: translator$Z,
34264
- tableCell: translator$c,
34190
+ table: translator$8,
34191
+ tableRow: translator$u,
34192
+ tableCell: translator$H,
34265
34193
  bookmarkStart: translator$7,
34266
34194
  bookmarkEnd: translator$6,
34267
- fieldAnnotation: translator$8,
34195
+ fieldAnnotation: translator$q,
34268
34196
  tab: translator$1p,
34269
- image: translator$9,
34197
+ image: translator$r,
34270
34198
  hardBreak: translator$1r,
34271
34199
  commentRangeStart: commentRangeStartTranslator,
34272
34200
  commentRangeEnd: commentRangeEndTranslator,
@@ -34275,10 +34203,10 @@ function exportSchemaToJson(params) {
34275
34203
  shapeTextbox: translator,
34276
34204
  contentBlock: translator,
34277
34205
  vectorShape: translateVectorShape,
34278
- structuredContent: translator$8,
34279
- structuredContentBlock: translator$8,
34280
- documentPartObject: translator$8,
34281
- documentSection: translator$8,
34206
+ structuredContent: translator$q,
34207
+ structuredContentBlock: translator$q,
34208
+ documentPartObject: translator$q,
34209
+ documentSection: translator$q,
34282
34210
  "page-number": translatePageNumberNode,
34283
34211
  "total-page-number": translateTotalPageNumberNode,
34284
34212
  pageReference: translator$5,
@@ -36015,7 +35943,7 @@ exportProcessNewRelationships_fn = function(rels = []) {
36015
35943
  });
36016
35944
  relationships.elements = [...relationships.elements, ...newRels];
36017
35945
  };
36018
- exportProcessMediaFiles_fn = async function(media = {}, editor) {
35946
+ exportProcessMediaFiles_fn = async function(media = {}) {
36019
35947
  const processedData = {
36020
35948
  ...this.convertedXml.media || {}
36021
35949
  };
@@ -36114,7 +36042,7 @@ export {
36114
36042
  objectIncludes as Z,
36115
36043
  AddMarkStep as _,
36116
36044
  Plugin as a,
36117
- translator$b as a$,
36045
+ translator$t as a$,
36118
36046
  twipsToLines as a0,
36119
36047
  pixelsToTwips as a1,
36120
36048
  helpers as a2,
@@ -36134,24 +36062,24 @@ export {
36134
36062
  handleClipboardPaste as aG,
36135
36063
  getFileObject as aH,
36136
36064
  runPropertyTranslators as aI,
36137
- translator$d as aJ,
36138
- translator$k as aK,
36139
- translator$m as aL,
36140
- translator$e as aM,
36141
- translator$f as aN,
36142
- translator$n as aO,
36143
- translator$o as aP,
36144
- translator$j as aQ,
36145
- translator$g as aR,
36146
- translator$r as aS,
36147
- translator$i as aT,
36148
- translator$l as aU,
36149
- translator$h as aV,
36150
- translator$q as aW,
36151
- translator$p as aX,
36065
+ translator$I as aJ,
36066
+ translator$P as aK,
36067
+ translator$R as aL,
36068
+ translator$J as aM,
36069
+ translator$K as aN,
36070
+ translator$S as aO,
36071
+ translator$T as aP,
36072
+ translator$O as aQ,
36073
+ translator$L as aR,
36074
+ translator$18 as aS,
36075
+ translator$N as aT,
36076
+ translator$Q as aU,
36077
+ translator$M as aV,
36078
+ translator$17 as aW,
36079
+ translator$16 as aX,
36152
36080
  commentRangeEndTranslator as aY,
36153
36081
  commentRangeStartTranslator as aZ,
36154
- translator$a as a_,
36082
+ translator$s as a_,
36155
36083
  hasSomeParentWithClass as aa,
36156
36084
  isActive as ab,
36157
36085
  unflattenListsInHtml as ac,
@@ -36180,67 +36108,67 @@ export {
36180
36108
  commonjsGlobal as az,
36181
36109
  Slice as b,
36182
36110
  translator$5 as b$,
36183
- translator$$ as b0,
36184
- translator$10 as b1,
36111
+ translator$w as b0,
36112
+ translator$x as b1,
36185
36113
  translator$1l as b2,
36186
- translator$_ as b3,
36187
- translator$11 as b4,
36188
- translator$Z as b5,
36189
- translator$z as b6,
36190
- translator$c as b7,
36191
- translator$M as b8,
36192
- translator$N as b9,
36114
+ translator$v as b3,
36115
+ translator$y as b4,
36116
+ translator$u as b5,
36117
+ translator$V as b6,
36118
+ translator$H as b7,
36119
+ translator$e as b8,
36120
+ translator$f as b9,
36193
36121
  translator$1i as bA,
36194
36122
  translator$1b as bB,
36195
36123
  translator$1o as bC,
36196
- translator$F as bD,
36197
- translator$14 as bE,
36198
- translator$G as bF,
36199
- translator$H as bG,
36124
+ translator$$ as bD,
36125
+ translator$B as bE,
36126
+ translator$10 as bF,
36127
+ translator$11 as bG,
36200
36128
  translator$1m as bH,
36201
36129
  translator$1c as bI,
36202
36130
  translator$1q as bJ,
36203
- translator$15 as bK,
36204
- translator$u as bL,
36205
- translator$16 as bM,
36206
- translator$17 as bN,
36207
- translator$J as bO,
36208
- translator$9 as bP,
36209
- translator$18 as bQ,
36131
+ translator$C as bK,
36132
+ translator$a as bL,
36133
+ translator$D as bM,
36134
+ translator$E as bN,
36135
+ translator$13 as bO,
36136
+ translator$r as bP,
36137
+ translator$F as bQ,
36210
36138
  translator$1j as bR,
36211
- translator$19 as bS,
36212
- translator$1a as bT,
36139
+ translator$1a as bS,
36140
+ translator$G as bT,
36213
36141
  translator$1r as bU,
36214
- translator$L as bV,
36142
+ translator$15 as bV,
36215
36143
  translator$7 as bW,
36216
36144
  translator$6 as bX,
36217
- translator$Y as bY,
36145
+ translator$p as bY,
36218
36146
  translator$1n as bZ,
36219
36147
  translator$4 as b_,
36220
- translator$O as ba,
36221
- translator$P as bb,
36222
- translator$Q as bc,
36223
- translator$v as bd,
36224
- translator$R as be,
36225
- translator$S as bf,
36226
- translator$T as bg,
36227
- translator$U as bh,
36228
- translator$12 as bi,
36229
- translator$t as bj,
36230
- translator$V as bk,
36231
- translator$13 as bl,
36232
- translator$w as bm,
36233
- translator$W as bn,
36234
- translator$x as bo,
36235
- translator$s as bp,
36148
+ translator$g as ba,
36149
+ translator$h as bb,
36150
+ translator$i as bc,
36151
+ translator$b as bd,
36152
+ translator$j as be,
36153
+ translator$k as bf,
36154
+ translator$l as bg,
36155
+ translator$m as bh,
36156
+ translator$z as bi,
36157
+ translator$9 as bj,
36158
+ translator$n as bk,
36159
+ translator$A as bl,
36160
+ translator$c as bm,
36161
+ translator$o as bn,
36162
+ translator$d as bo,
36163
+ translator$8 as bp,
36236
36164
  translator$1p as bq,
36237
36165
  translator$1f as br,
36238
36166
  translator$1g as bs,
36239
36167
  translator$1k as bt,
36240
- translator$B as bu,
36241
- translator$X as bv,
36242
- translator$8 as bw,
36243
- translator$D as bx,
36168
+ translator$X as bu,
36169
+ translator$19 as bv,
36170
+ translator$q as bw,
36171
+ translator$Z as bx,
36244
36172
  translator$1h as by,
36245
36173
  translator$1d as bz,
36246
36174
  DOMParser$1 as c,