@harbour-enterprises/superdoc 0.27.3-next.2 → 0.27.3

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 (26) hide show
  1. package/dist/chunks/{PdfViewer-B4iIjHV0.cjs → PdfViewer-CCrMOIpU.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-BjZ5mGJm.es.js → PdfViewer-DXMcf_Mb.es.js} +1 -1
  3. package/dist/chunks/{index-D6aLyyxJ.cjs → index-CIFHwmHR.cjs} +2 -2
  4. package/dist/chunks/{index-DkzQzDKS.es.js → index-GJg72zc5.es.js} +2 -2
  5. package/dist/chunks/{super-editor.es-DAZHU_K5.es.js → super-editor.es-BYmNnbzd.es.js} +1755 -1676
  6. package/dist/chunks/{super-editor.es-BbpZtQLg.cjs → super-editor.es-BlDrv5SU.cjs} +1755 -1676
  7. package/dist/super-editor/ai-writer.es.js +2 -2
  8. package/dist/super-editor/chunks/{converter-qTrGAY0a.js → converter-GcMLdei-.js} +4352 -4273
  9. package/dist/super-editor/chunks/{docx-zipper-BRttLmZq.js → docx-zipper-Y0x9TJvc.js} +1 -1
  10. package/dist/super-editor/chunks/{editor-DqOCeU9J.js → editor-Bm6n8ccl.js} +3 -3
  11. package/dist/super-editor/chunks/{toolbar-cZin2t1V.js → toolbar-0L9P26Ib.js} +2 -2
  12. package/dist/super-editor/converter.es.js +1 -1
  13. package/dist/super-editor/docx-zipper.es.js +2 -2
  14. package/dist/super-editor/editor.es.js +3 -3
  15. package/dist/super-editor/file-zipper.es.js +1 -1
  16. package/dist/super-editor/super-editor/src/core/super-converter/v2/importer/tableImporter.d.ts +16 -0
  17. package/dist/super-editor/super-editor/src/core/super-converter/v3/handlers/w/tc/helpers/legacy-handle-table-cell-node.d.ts +1 -1
  18. package/dist/super-editor/super-editor.es.js +6 -6
  19. package/dist/super-editor/toolbar.es.js +2 -2
  20. package/dist/super-editor.cjs +1 -1
  21. package/dist/super-editor.es.js +1 -1
  22. package/dist/superdoc.cjs +2 -2
  23. package/dist/superdoc.es.js +2 -2
  24. package/dist/superdoc.umd.js +1755 -1676
  25. package/dist/superdoc.umd.js.map +1 -1
  26. package/package.json +1 -1
@@ -26990,7 +26990,53 @@ const config$h = {
26990
26990
  attributes: validXmlAttributes$c
26991
26991
  };
26992
26992
  const translator$1b = NodeTranslator.from(config$h);
26993
+ function preProcessVerticalMergeCells(table, { editorSchema }) {
26994
+ if (!table || !Array.isArray(table.content)) {
26995
+ return table;
26996
+ }
26997
+ const rows = table.content;
26998
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
26999
+ const row = rows[rowIndex];
27000
+ if (!row) continue;
27001
+ if (!Array.isArray(row.content)) {
27002
+ row.content = [];
27003
+ }
27004
+ for (let cellIndex = 0; cellIndex < row.content.length; cellIndex++) {
27005
+ const cell = row.content[cellIndex];
27006
+ if (!cell) continue;
27007
+ const attrs = cell.attrs || {};
27008
+ if (!attrs.rowspan || attrs.rowspan <= 1) continue;
27009
+ const maxRowspan = Math.min(attrs.rowspan, rows.length - rowIndex);
27010
+ for (let offset2 = 1; offset2 < maxRowspan; offset2++) {
27011
+ const rowToChange = rows[rowIndex + offset2];
27012
+ if (!rowToChange) continue;
27013
+ if (!Array.isArray(rowToChange.content)) {
27014
+ rowToChange.content = [];
27015
+ }
27016
+ const existingCell = rowToChange.content[cellIndex];
27017
+ if (existingCell?.attrs?.continueMerge) continue;
27018
+ const mergedCell = {
27019
+ type: cell.type,
27020
+ content: [editorSchema.nodes.paragraph.createAndFill().toJSON()],
27021
+ attrs: {
27022
+ ...cell.attrs,
27023
+ rowspan: null,
27024
+ continueMerge: true
27025
+ }
27026
+ };
27027
+ rowToChange.content.splice(cellIndex, 0, mergedCell);
27028
+ }
27029
+ }
27030
+ }
27031
+ return table;
27032
+ }
26993
27033
  const translator$1a = NodeTranslator.from({
27034
+ xmlName: "w:cantSplit",
27035
+ sdNodeOrKeyName: "cantSplit",
27036
+ encode: ({ nodes }) => ["1", "true"].includes(nodes[0].attributes?.["w:val"] ?? "1"),
27037
+ decode: ({ node }) => node.attrs?.cantSplit ? { attributes: {} } : void 0
27038
+ });
27039
+ const translator$19 = NodeTranslator.from({
26994
27040
  xmlName: "w:cnfStyle",
26995
27041
  sdNodeOrKeyName: "cnfStyle",
26996
27042
  attributes: [
@@ -27016,431 +27062,1334 @@ const translator$1a = NodeTranslator.from({
27016
27062
  return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
27017
27063
  }
27018
27064
  });
27019
- const translator$19 = NodeTranslator.from({
27020
- xmlName: "w:shd",
27021
- sdNodeOrKeyName: "shading",
27022
- attributes: [
27023
- "w:color",
27024
- "w:fill",
27025
- "w:themeColor",
27026
- "w:themeFill",
27027
- "w:themeFillShade",
27028
- "w:themeFillTint",
27029
- "w:themeShade",
27030
- "w:themeTint",
27031
- "w:val"
27032
- ].map((attr) => createAttributeHandler(attr)),
27033
- encode: (params2, encodedAttrs) => {
27034
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
27035
- },
27036
- decode: function({ node }, context) {
27037
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.shading || {} } });
27038
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
27039
- }
27040
- });
27041
- const translator$18 = NodeTranslator.from(createMeasurementPropertyHandler("w:tcW", "cellWidth"));
27065
+ const translator$18 = NodeTranslator.from(createSingleAttrPropertyHandler("w:divId"));
27042
27066
  const translator$17 = NodeTranslator.from(
27043
27067
  createSingleAttrPropertyHandler(
27044
- "w:gridSpan",
27068
+ "w:gridAfter",
27045
27069
  null,
27046
27070
  "w:val",
27047
27071
  (v2) => parseInteger(v2) ?? void 0,
27048
27072
  (v2) => integerToString(v2)
27049
27073
  )
27050
27074
  );
27051
- const translator$16 = NodeTranslator.from(createSingleAttrPropertyHandler("w:vMerge"));
27052
- const translator$15 = NodeTranslator.from(createBorderPropertyHandler("w:bottom"));
27053
- const translator$14 = NodeTranslator.from(createMeasurementPropertyHandler("w:bottom", "marginBottom"));
27054
- const translator$13 = NodeTranslator.from(createBorderPropertyHandler("w:end"));
27055
- const translator$12 = NodeTranslator.from(createMeasurementPropertyHandler("w:end", "marginEnd"));
27056
- const translator$11 = NodeTranslator.from(createBorderPropertyHandler("w:insideH"));
27057
- const translator$10 = NodeTranslator.from(createBorderPropertyHandler("w:insideV"));
27058
- const translator$$ = NodeTranslator.from(createBorderPropertyHandler("w:left"));
27059
- const translator$_ = NodeTranslator.from(createMeasurementPropertyHandler("w:left", "marginLeft"));
27060
- const translator$Z = NodeTranslator.from(createBorderPropertyHandler("w:right"));
27061
- const translator$Y = NodeTranslator.from(createMeasurementPropertyHandler("w:right", "marginRight"));
27062
- const translator$X = NodeTranslator.from(createBorderPropertyHandler("w:start"));
27063
- const translator$W = NodeTranslator.from(createMeasurementPropertyHandler("w:start", "marginStart"));
27064
- const translator$V = NodeTranslator.from(createBorderPropertyHandler("w:top"));
27065
- const translator$U = NodeTranslator.from(createMeasurementPropertyHandler("w:top", "marginTop"));
27066
- const translator$T = NodeTranslator.from(createBorderPropertyHandler("w:tl2br"));
27067
- const translator$S = NodeTranslator.from(createBorderPropertyHandler("w:tr2bl"));
27068
- const propertyTranslators$6 = [
27069
- translator$V,
27070
- translator$X,
27071
- translator$$,
27072
- translator$15,
27073
- translator$13,
27074
- translator$Z,
27075
- translator$11,
27076
- translator$10,
27077
- translator$T,
27078
- translator$S
27079
- ];
27080
- const translator$R = NodeTranslator.from(
27081
- createNestedPropertiesTranslator("w:tcBorders", "borders", propertyTranslators$6)
27082
- );
27083
- const translator$Q = NodeTranslator.from(
27075
+ const translator$16 = NodeTranslator.from(
27084
27076
  createSingleAttrPropertyHandler(
27085
- "w:noWrap",
27077
+ "w:gridBefore",
27086
27078
  null,
27087
27079
  "w:val",
27088
- (v2) => parseBoolean(v2 ?? "true"),
27089
- (v2) => booleanToString(v2)
27080
+ (v2) => parseInteger(v2) ?? void 0,
27081
+ (v2) => integerToString(v2)
27090
27082
  )
27091
27083
  );
27092
- const propertyTranslators$5 = [
27084
+ const translator$15 = NodeTranslator.from({
27085
+ xmlName: "w:hidden",
27086
+ sdNodeOrKeyName: "hidden",
27087
+ encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
27088
+ decode: ({ node }) => node.attrs.hidden ? { attributes: {} } : void 0
27089
+ });
27090
+ const translator$14 = NodeTranslator.from(createSingleAttrPropertyHandler("w:jc", "justification"));
27091
+ const translator$13 = NodeTranslator.from(createMeasurementPropertyHandler("w:tblCellSpacing", "tableCellSpacing"));
27092
+ const translator$12 = NodeTranslator.from({
27093
+ xmlName: "w:tblHeader",
27094
+ sdNodeOrKeyName: "repeatHeader",
27095
+ encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
27096
+ decode: ({ node }) => node.attrs.repeatHeader ? { attributes: {} } : void 0
27097
+ });
27098
+ const translator$11 = NodeTranslator.from({
27099
+ xmlName: "w:trHeight",
27100
+ sdNodeOrKeyName: "rowHeight",
27101
+ encode: ({ nodes }) => {
27102
+ const heightAttrs = {};
27103
+ const val = nodes[0].attributes["w:val"];
27104
+ if (val) {
27105
+ heightAttrs["value"] = parseInt(val, 10);
27106
+ }
27107
+ const rule = nodes[0].attributes["w:hRule"];
27108
+ if (rule) {
27109
+ heightAttrs["rule"] = rule;
27110
+ }
27111
+ return Object.keys(heightAttrs).length > 0 ? heightAttrs : void 0;
27112
+ },
27113
+ decode: ({ node }) => {
27114
+ if (!node.attrs?.rowHeight) return;
27115
+ const heightAttrs = {};
27116
+ if (typeof node.attrs.rowHeight.value === "number" && !isNaN(node.attrs.rowHeight.value)) {
27117
+ heightAttrs["w:val"] = String(node.attrs.rowHeight.value);
27118
+ }
27119
+ if (node.attrs.rowHeight.rule) {
27120
+ heightAttrs["w:hRule"] = node.attrs.rowHeight.rule;
27121
+ }
27122
+ return Object.keys(heightAttrs).length > 0 ? { attributes: heightAttrs } : void 0;
27123
+ }
27124
+ });
27125
+ const translator$10 = NodeTranslator.from(createMeasurementPropertyHandler("w:wAfter"));
27126
+ const translator$$ = NodeTranslator.from(createMeasurementPropertyHandler("w:wBefore"));
27127
+ const propertyTranslators$6 = [
27128
+ translator$1a,
27129
+ translator$19,
27130
+ translator$18,
27131
+ translator$17,
27132
+ translator$16,
27133
+ translator$15,
27093
27134
  translator$14,
27135
+ translator$13,
27094
27136
  translator$12,
27095
- translator$_,
27096
- translator$Y,
27097
- translator$W,
27098
- translator$U
27137
+ translator$11,
27138
+ translator$10,
27139
+ translator$$
27099
27140
  ];
27100
- const translator$P = NodeTranslator.from(
27101
- createNestedPropertiesTranslator("w:tcMar", "cellMargins", propertyTranslators$5)
27102
- );
27103
- const translator$O = NodeTranslator.from(createSingleAttrPropertyHandler("w:textDirection"));
27104
- const translator$N = NodeTranslator.from(
27105
- createSingleAttrPropertyHandler(
27106
- "w:tcFitText",
27107
- null,
27108
- "w:val",
27109
- (v2) => parseBoolean(v2 ?? "true"),
27110
- (v2) => booleanToString(v2)
27111
- )
27112
- );
27113
- const translator$M = NodeTranslator.from(createSingleAttrPropertyHandler("w:vAlign"));
27114
- const translator$L = NodeTranslator.from(
27115
- createSingleAttrPropertyHandler(
27116
- "w:hideMark",
27117
- null,
27118
- "w:val",
27119
- (v2) => parseBoolean(v2 ?? "true"),
27120
- (v2) => booleanToString(v2)
27121
- )
27141
+ const translator$_ = NodeTranslator.from(
27142
+ createNestedPropertiesTranslator("w:trPr", "tableRowProperties", propertyTranslators$6, {
27143
+ cantSplit: false,
27144
+ hidden: false,
27145
+ repeatHeader: false
27146
+ })
27122
27147
  );
27123
- const translator$K = NodeTranslator.from(createSingleAttrPropertyHandler("w:header"));
27124
- const XML_NODE_NAME$h = "w:headers";
27125
- const SD_ATTR_KEY$3 = "headers";
27126
- const encode$n = (params2) => {
27127
- const { nodes } = params2;
27128
- const node = nodes[0];
27129
- const attributes = encodeProperties(node, { [translator$K.xmlName]: translator$K }, true);
27148
+ const createPlaceholderCell = (gridWidth, reason) => {
27149
+ const safeWidth = Number.isFinite(gridWidth) ? gridWidth : 0;
27150
+ const noBorder = { val: "none", size: 0 };
27130
27151
  return {
27131
- xmlName: XML_NODE_NAME$h,
27132
- sdNodeOrKeyName: SD_ATTR_KEY$3,
27133
- attributes
27152
+ type: "tableCell",
27153
+ attrs: {
27154
+ colspan: 1,
27155
+ rowspan: 1,
27156
+ colwidth: [safeWidth],
27157
+ __placeholder: reason,
27158
+ borders: {
27159
+ top: { ...noBorder },
27160
+ right: { ...noBorder },
27161
+ bottom: { ...noBorder },
27162
+ left: { ...noBorder }
27163
+ }
27164
+ },
27165
+ content: [{ type: "paragraph", content: [] }]
27134
27166
  };
27135
27167
  };
27136
- const decode$p = (params2) => {
27137
- const { headers = [] } = params2.node.attrs || {};
27168
+ const advancePastRowSpans = (pendingRowSpans, startIndex, totalColumns) => {
27169
+ let index2 = startIndex;
27170
+ while (index2 < totalColumns && pendingRowSpans[index2] > 0) {
27171
+ pendingRowSpans[index2] -= 1;
27172
+ index2 += 1;
27173
+ }
27174
+ return index2;
27175
+ };
27176
+ const fillPlaceholderColumns = ({
27177
+ content,
27178
+ pendingRowSpans,
27179
+ currentIndex,
27180
+ targetIndex,
27181
+ totalColumns,
27182
+ gridColumnWidths,
27183
+ reason
27184
+ }) => {
27185
+ let index2 = currentIndex;
27186
+ while (index2 < targetIndex && index2 < totalColumns) {
27187
+ if (pendingRowSpans[index2] > 0) {
27188
+ pendingRowSpans[index2] -= 1;
27189
+ index2 += 1;
27190
+ continue;
27191
+ }
27192
+ const width = Array.isArray(gridColumnWidths) ? gridColumnWidths[index2] ?? 0 : 0;
27193
+ content.push(createPlaceholderCell(width, reason));
27194
+ index2 += 1;
27195
+ }
27196
+ return index2;
27197
+ };
27198
+ const isPlaceholderCell = (cell) => {
27199
+ if (!cell) return false;
27200
+ if (cell.attrs?.__placeholder) return true;
27201
+ const widths = cell.attrs?.colwidth;
27202
+ if (Array.isArray(widths) && widths.length > 0) {
27203
+ const hasMeaningfulWidth = widths.some(
27204
+ (value) => typeof value === "number" && Number.isFinite(value) && Math.abs(value) > 1
27205
+ );
27206
+ if (!hasMeaningfulWidth) return true;
27207
+ }
27208
+ return false;
27209
+ };
27210
+ const XML_NODE_NAME$h = "w:tr";
27211
+ const SD_NODE_NAME$d = "tableRow";
27212
+ const validXmlAttributes$b = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
27213
+ (xmlName) => createAttributeHandler(xmlName)
27214
+ );
27215
+ const encode$n = (params2, encodedAttrs) => {
27216
+ const { row } = params2.extraParams;
27217
+ let tableRowProperties = {};
27218
+ const tPr = row.elements.find((el) => el.name === "w:trPr");
27219
+ if (tPr) {
27220
+ tableRowProperties = translator$_.encode({
27221
+ ...params2,
27222
+ nodes: [tPr]
27223
+ });
27224
+ }
27225
+ const gridBeforeRaw = tableRowProperties?.["gridBefore"];
27226
+ const safeGridBefore = typeof gridBeforeRaw === "number" && Number.isFinite(gridBeforeRaw) && gridBeforeRaw > 0 ? gridBeforeRaw : 0;
27227
+ encodedAttrs["tableRowProperties"] = Object.freeze(tableRowProperties);
27228
+ encodedAttrs["rowHeight"] = twipsToPixels(tableRowProperties["rowHeight"]?.value);
27229
+ encodedAttrs["cantSplit"] = tableRowProperties["cantSplit"];
27230
+ const { columnWidths: gridColumnWidths, activeRowSpans = [] } = params2.extraParams;
27231
+ const totalColumns = Array.isArray(gridColumnWidths) ? gridColumnWidths.length : 0;
27232
+ const pendingRowSpans = Array.isArray(activeRowSpans) ? activeRowSpans.slice() : [];
27233
+ while (pendingRowSpans.length < totalColumns) pendingRowSpans.push(0);
27234
+ const cellNodes = row.elements.filter((el) => el.name === "w:tc");
27235
+ const content = [];
27236
+ let currentColumnIndex = 0;
27237
+ const fillUntil = (target, reason) => {
27238
+ currentColumnIndex = fillPlaceholderColumns({
27239
+ content,
27240
+ pendingRowSpans,
27241
+ currentIndex: currentColumnIndex,
27242
+ targetIndex: target,
27243
+ totalColumns,
27244
+ gridColumnWidths,
27245
+ reason
27246
+ });
27247
+ };
27248
+ const skipOccupiedColumns = () => {
27249
+ currentColumnIndex = advancePastRowSpans(pendingRowSpans, currentColumnIndex, totalColumns);
27250
+ };
27251
+ fillUntil(safeGridBefore, "gridBefore");
27252
+ skipOccupiedColumns();
27253
+ cellNodes?.forEach((node) => {
27254
+ skipOccupiedColumns();
27255
+ const startColumn = currentColumnIndex;
27256
+ const columnWidth = gridColumnWidths?.[startColumn] || null;
27257
+ const result = translator$c.encode({
27258
+ ...params2,
27259
+ extraParams: {
27260
+ ...params2.extraParams,
27261
+ node,
27262
+ columnIndex: startColumn,
27263
+ columnWidth
27264
+ }
27265
+ });
27266
+ if (result) {
27267
+ content.push(result);
27268
+ const colspan = Math.max(1, result.attrs?.colspan || 1);
27269
+ const rowspan = Math.max(1, result.attrs?.rowspan || 1);
27270
+ if (rowspan > 1) {
27271
+ for (let offset2 = 0; offset2 < colspan; offset2 += 1) {
27272
+ const target = startColumn + offset2;
27273
+ if (target < pendingRowSpans.length) {
27274
+ pendingRowSpans[target] = Math.max(pendingRowSpans[target], rowspan - 1);
27275
+ }
27276
+ }
27277
+ }
27278
+ currentColumnIndex = startColumn + colspan;
27279
+ }
27280
+ });
27281
+ skipOccupiedColumns();
27282
+ fillUntil(totalColumns, "gridAfter");
27138
27283
  const newNode = {
27139
- name: XML_NODE_NAME$h,
27140
- attributes: {},
27141
- elements: headers.map(
27142
- (header) => translator$K.decode({
27143
- node: { type: "header", attrs: header }
27144
- })
27145
- )
27284
+ type: "tableRow",
27285
+ content,
27286
+ attrs: encodedAttrs
27146
27287
  };
27147
27288
  return newNode;
27148
27289
  };
27290
+ const decode$p = (params2, decodedAttrs) => {
27291
+ const { node } = params2;
27292
+ const cells = node.content || [];
27293
+ let leadingPlaceholders = 0;
27294
+ while (leadingPlaceholders < cells.length && isPlaceholderCell(cells[leadingPlaceholders])) {
27295
+ leadingPlaceholders += 1;
27296
+ }
27297
+ let trailingPlaceholders = 0;
27298
+ while (trailingPlaceholders < cells.length - leadingPlaceholders && isPlaceholderCell(cells[cells.length - 1 - trailingPlaceholders])) {
27299
+ trailingPlaceholders += 1;
27300
+ }
27301
+ const trimmedSlice = cells.slice(leadingPlaceholders, cells.length - trailingPlaceholders);
27302
+ const sanitizedCells = trimmedSlice.map((cell) => {
27303
+ if (cell?.attrs && "__placeholder" in cell.attrs) {
27304
+ const { __placeholder, ...rest } = cell.attrs;
27305
+ return { ...cell, attrs: rest };
27306
+ }
27307
+ return cell;
27308
+ });
27309
+ const trimmedContent = sanitizedCells.filter((_2, index2) => !isPlaceholderCell(trimmedSlice[index2]));
27310
+ const translateParams = {
27311
+ ...params2,
27312
+ node: { ...node, content: trimmedContent }
27313
+ };
27314
+ const elements = translateChildNodes(translateParams);
27315
+ if (node.attrs?.tableRowProperties) {
27316
+ const tableRowProperties = { ...node.attrs.tableRowProperties };
27317
+ if (leadingPlaceholders > 0) {
27318
+ tableRowProperties.gridBefore = leadingPlaceholders;
27319
+ }
27320
+ if (trailingPlaceholders > 0) {
27321
+ tableRowProperties.gridAfter = trailingPlaceholders;
27322
+ }
27323
+ if (node.attrs.rowHeight != null) {
27324
+ const rowHeightPixels = twipsToPixels(node.attrs.tableRowProperties["rowHeight"]?.value);
27325
+ if (rowHeightPixels !== node.attrs.rowHeight) {
27326
+ tableRowProperties["rowHeight"] = { value: String(pixelsToTwips(node.attrs["rowHeight"])) };
27327
+ }
27328
+ }
27329
+ tableRowProperties["cantSplit"] = node.attrs["cantSplit"];
27330
+ const trPr = translator$_.decode({
27331
+ ...params2,
27332
+ node: { ...node, attrs: { ...node.attrs, tableRowProperties } }
27333
+ });
27334
+ if (trPr) elements.unshift(trPr);
27335
+ }
27336
+ return {
27337
+ name: "w:tr",
27338
+ attributes: decodedAttrs || {},
27339
+ elements
27340
+ };
27341
+ };
27149
27342
  const config$g = {
27150
27343
  xmlName: XML_NODE_NAME$h,
27151
- sdNodeOrKeyName: SD_ATTR_KEY$3,
27344
+ sdNodeOrKeyName: SD_NODE_NAME$d,
27345
+ type: NodeTranslator.translatorTypes.NODE,
27152
27346
  encode: encode$n,
27153
- decode: decode$p
27347
+ decode: decode$p,
27348
+ attributes: validXmlAttributes$b
27154
27349
  };
27155
- const translator$J = NodeTranslator.from(config$g);
27350
+ const translator$Z = NodeTranslator.from(config$g);
27351
+ const translator$Y = NodeTranslator.from({
27352
+ xmlName: "w:bidiVisual",
27353
+ sdNodeOrKeyName: "rightToLeft",
27354
+ encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
27355
+ decode: ({ node }) => node.attrs.rightToLeft ? { attributes: {} } : void 0
27356
+ });
27357
+ const translator$X = NodeTranslator.from({
27358
+ xmlName: "w:shd",
27359
+ sdNodeOrKeyName: "shading",
27360
+ attributes: [
27361
+ "w:color",
27362
+ "w:fill",
27363
+ "w:themeColor",
27364
+ "w:themeFill",
27365
+ "w:themeFillShade",
27366
+ "w:themeFillTint",
27367
+ "w:themeShade",
27368
+ "w:themeTint",
27369
+ "w:val"
27370
+ ].map((attr) => createAttributeHandler(attr)),
27371
+ encode: (params2, encodedAttrs) => {
27372
+ return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
27373
+ },
27374
+ decode: function({ node }, context) {
27375
+ const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.shading || {} } });
27376
+ return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
27377
+ }
27378
+ });
27379
+ const translator$W = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblCaption", "caption"));
27380
+ const translator$V = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblDescription", "description"));
27381
+ const translator$U = NodeTranslator.from(createMeasurementPropertyHandler("w:tblInd", "tableIndent"));
27382
+ const translator$T = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblLayout", "tableLayout", "w:type"));
27383
+ const translator$S = NodeTranslator.from({
27384
+ xmlName: "w:tblLook",
27385
+ sdNodeOrKeyName: "tblLook",
27386
+ attributes: ["w:firstColumn", "w:firstRow", "w:lastColumn", "w:lastRow", "w:noHBand", "w:noVBand"].map((attr) => createAttributeHandler(attr, null, parseBoolean, booleanToString)).concat([createAttributeHandler("w:val")]),
27387
+ encode: (params2, encodedAttrs) => {
27388
+ return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
27389
+ },
27390
+ decode: function({ node }, context) {
27391
+ const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.tblLook || {} } });
27392
+ return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
27393
+ }
27394
+ });
27395
+ const translator$R = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblOverlap", "overlap"));
27396
+ const translator$Q = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblStyle", "tableStyleId"));
27397
+ const translator$P = NodeTranslator.from(
27398
+ createSingleAttrPropertyHandler("w:tblStyleColBandSize", "tableStyleColBandSize")
27399
+ );
27400
+ const translator$O = NodeTranslator.from(
27401
+ createSingleAttrPropertyHandler("w:tblStyleRowBandSize", "tableStyleRowBandSize")
27402
+ );
27403
+ const translator$N = NodeTranslator.from(createMeasurementPropertyHandler("w:tblW", "tableWidth"));
27404
+ const translator$M = NodeTranslator.from({
27405
+ xmlName: "w:tblpPr",
27406
+ sdNodeOrKeyName: "floatingTableProperties",
27407
+ attributes: ["w:leftFromText", "w:rightFromText", "w:topFromText", "w:bottomFromText", "w:tblpX", "w:tblpY"].map((attr) => createAttributeHandler(attr, null, parseInteger, integerToString)).concat(["w:horzAnchor", "w:vertAnchor", "w:tblpXSpec", "w:tblpYSpec"].map((attr) => createAttributeHandler(attr))),
27408
+ encode: (params2, encodedAttrs) => {
27409
+ return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
27410
+ },
27411
+ decode: function({ node }, context) {
27412
+ const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.floatingTableProperties || {} } });
27413
+ return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
27414
+ }
27415
+ });
27416
+ const translator$L = NodeTranslator.from(createBorderPropertyHandler("w:bottom"));
27417
+ const translator$K = NodeTranslator.from(createMeasurementPropertyHandler("w:bottom", "marginBottom"));
27418
+ const translator$J = NodeTranslator.from(createBorderPropertyHandler("w:end"));
27419
+ const translator$I = NodeTranslator.from(createMeasurementPropertyHandler("w:end", "marginEnd"));
27420
+ const translator$H = NodeTranslator.from(createBorderPropertyHandler("w:insideH"));
27421
+ const translator$G = NodeTranslator.from(createBorderPropertyHandler("w:insideV"));
27422
+ const translator$F = NodeTranslator.from(createBorderPropertyHandler("w:left"));
27423
+ const translator$E = NodeTranslator.from(createMeasurementPropertyHandler("w:left", "marginLeft"));
27424
+ const translator$D = NodeTranslator.from(createBorderPropertyHandler("w:right"));
27425
+ const translator$C = NodeTranslator.from(createMeasurementPropertyHandler("w:right", "marginRight"));
27426
+ const translator$B = NodeTranslator.from(createBorderPropertyHandler("w:start"));
27427
+ const translator$A = NodeTranslator.from(createMeasurementPropertyHandler("w:start", "marginStart"));
27428
+ const translator$z = NodeTranslator.from(createBorderPropertyHandler("w:top"));
27429
+ const translator$y = NodeTranslator.from(createMeasurementPropertyHandler("w:top", "marginTop"));
27430
+ const propertyTranslators$5 = [
27431
+ translator$L,
27432
+ translator$J,
27433
+ translator$H,
27434
+ translator$G,
27435
+ translator$F,
27436
+ translator$D,
27437
+ translator$B,
27438
+ translator$z
27439
+ ];
27440
+ const translator$x = NodeTranslator.from(
27441
+ createNestedPropertiesTranslator("w:tblBorders", "borders", propertyTranslators$5)
27442
+ );
27156
27443
  const propertyTranslators$4 = [
27157
- translator$1a,
27158
- translator$18,
27159
- translator$17,
27160
- translator$16,
27444
+ translator$K,
27445
+ translator$I,
27446
+ translator$E,
27447
+ translator$C,
27448
+ translator$A,
27449
+ translator$y
27450
+ ];
27451
+ const translator$w = NodeTranslator.from(
27452
+ createNestedPropertiesTranslator("w:tblCellMar", "cellMargins", propertyTranslators$4)
27453
+ );
27454
+ const propertyTranslators$3 = [
27455
+ translator$Y,
27456
+ translator$14,
27457
+ translator$X,
27458
+ translator$W,
27459
+ translator$13,
27460
+ translator$V,
27461
+ translator$U,
27462
+ translator$T,
27463
+ translator$S,
27161
27464
  translator$R,
27162
- translator$19,
27163
27465
  translator$Q,
27164
27466
  translator$P,
27165
27467
  translator$O,
27166
27468
  translator$N,
27167
27469
  translator$M,
27168
- translator$L,
27169
- translator$J
27470
+ translator$x,
27471
+ translator$w
27170
27472
  ];
27171
- const translator$I = NodeTranslator.from(
27172
- createNestedPropertiesTranslator("w:tcPr", "tableCellProperties", propertyTranslators$4)
27473
+ const translator$v = NodeTranslator.from(
27474
+ createNestedPropertiesTranslator("w:tblPr", "tableProperties", propertyTranslators$3)
27173
27475
  );
27174
- function handleTableCellNode({
27175
- params: params2,
27176
- node,
27177
- table,
27178
- row,
27179
- rowBorders,
27180
- columnIndex,
27181
- columnWidth = null,
27182
- allColumnWidths = [],
27183
- _referencedStyles
27184
- }) {
27185
- const { nodeListHandler } = params2;
27186
- const attributes = {};
27187
- const referencedStyles = _referencedStyles ?? { fontSize: null, fonts: {}, cellMargins: {} };
27188
- const tcPr = node.elements.find((el) => el.name === "w:tcPr");
27189
- const tableCellProperties = tcPr ? translator$I.encode({ ...params2, nodes: [tcPr] }) ?? {} : {};
27190
- attributes["tableCellProperties"] = tableCellProperties;
27191
- if (rowBorders?.insideH) {
27192
- rowBorders["bottom"] = rowBorders.insideH;
27193
- delete rowBorders.insideH;
27476
+ const translator$u = NodeTranslator.from(
27477
+ createSingleAttrPropertyHandler("w:gridCol", "col", "w:w", parseInteger, integerToString)
27478
+ );
27479
+ const DEFAULT_COLUMN_WIDTH_PX = 100;
27480
+ const normalizeTwipWidth = (value) => {
27481
+ if (value == null) return null;
27482
+ const numericValue = typeof value === "string" ? parseInt(value, 10) : value;
27483
+ if (!Number.isFinite(numericValue) || Number.isNaN(numericValue) || numericValue <= 0) {
27484
+ return null;
27194
27485
  }
27195
- if (rowBorders?.insideV) {
27196
- rowBorders["right"] = rowBorders.insideV;
27197
- delete rowBorders?.insideV;
27486
+ return numericValue;
27487
+ };
27488
+ const getSchemaDefaultColumnWidthPx = (params2) => {
27489
+ const defaultValue = params2?.editor?.schema?.nodes?.tableCell?.spec?.attrs?.colwidth?.default;
27490
+ if (Array.isArray(defaultValue)) {
27491
+ const numericWidth = defaultValue.find((width) => typeof width === "number" && Number.isFinite(width) && width > 0);
27492
+ if (numericWidth != null) return numericWidth;
27493
+ } else if (typeof defaultValue === "number" && Number.isFinite(defaultValue) && defaultValue > 0) {
27494
+ return defaultValue;
27198
27495
  }
27199
- if (rowBorders) attributes["borders"] = { ...rowBorders };
27200
- const inlineBorders = processInlineCellBorders(tableCellProperties.borders, rowBorders);
27201
- if (inlineBorders) attributes["borders"] = Object.assign(attributes["borders"] || {}, inlineBorders);
27202
- const colspan = tableCellProperties.gridSpan;
27203
- if (colspan && !isNaN(parseInt(colspan, 10))) attributes["colspan"] = parseInt(colspan, 10);
27204
- let width = tableCellProperties.cellWidth?.value ? twipsToPixels(tableCellProperties.cellWidth?.value) : null;
27205
- const widthType = tableCellProperties.cellWidth?.type;
27206
- if (widthType) attributes["widthType"] = widthType;
27207
- if (!width && columnWidth) width = columnWidth;
27208
- if (width) {
27209
- attributes["colwidth"] = [width];
27210
- attributes["widthUnit"] = "px";
27211
- const defaultColWidths = allColumnWidths;
27212
- const hasDefaultColWidths = allColumnWidths && allColumnWidths.length > 0;
27213
- const colspanNum = parseInt(colspan || 1, 10);
27214
- if (colspanNum && colspanNum > 1 && hasDefaultColWidths) {
27215
- let colwidth = [];
27216
- for (let i = 0; i < colspanNum; i++) {
27217
- let colwidthValue = defaultColWidths[columnIndex + i];
27218
- let defaultColwidth = 100;
27219
- if (typeof colwidthValue !== "undefined") {
27220
- colwidth.push(colwidthValue);
27221
- } else {
27222
- colwidth.push(defaultColwidth);
27223
- }
27224
- }
27225
- if (colwidth.length) {
27226
- attributes["colwidth"] = [...colwidth];
27227
- }
27496
+ return DEFAULT_COLUMN_WIDTH_PX;
27497
+ };
27498
+ const getTableWidthPx = (params2) => {
27499
+ const explicitWidth = params2?.node?.attrs?.tableWidth?.width;
27500
+ if (typeof explicitWidth === "number" && explicitWidth > 0) return explicitWidth;
27501
+ const tableWidth = params2?.node?.attrs?.tableProperties?.tableWidth;
27502
+ if (tableWidth?.value != null && typeof tableWidth.value === "number" && tableWidth.value > 0) {
27503
+ const { value, type: type2 } = tableWidth;
27504
+ if (!type2 || type2 === "auto" || type2 === "dxa") {
27505
+ return twipsToPixels(value);
27228
27506
  }
27229
27507
  }
27230
- const background = {
27231
- color: tableCellProperties.shading?.fill
27232
- };
27233
- if (background.color) attributes["background"] = background;
27234
- const verticalAlign = tableCellProperties.vAlign;
27235
- if (verticalAlign) attributes["verticalAlign"] = verticalAlign;
27236
- attributes.cellMargins = getTableCellMargins(tableCellProperties.cellMargins, referencedStyles);
27237
- const { fontSize: fontSize2, fonts = {} } = referencedStyles;
27238
- const fontFamily2 = fonts["ascii"];
27239
- if (fontSize2) attributes["fontSize"] = fontSize2;
27240
- if (fontFamily2) attributes["fontFamily"] = fontFamily2;
27241
- if (tableCellProperties.vMerge === "restart") {
27242
- const rows = table.elements.filter((el) => el.name === "w:tr");
27243
- const currentRowIndex = rows.findIndex((r2) => r2 === row);
27244
- const remainingRows = rows.slice(currentRowIndex + 1);
27245
- const cellsInRow = row.elements.filter((el) => el.name === "w:tc");
27246
- let cellIndex = cellsInRow.findIndex((el) => el === node);
27247
- let rowspan = 1;
27248
- for (let remainingRow of remainingRows) {
27249
- const firstCell = remainingRow.elements.findIndex((el) => el.name === "w:tc");
27250
- const cellAtIndex = remainingRow.elements[firstCell + cellIndex];
27251
- if (!cellAtIndex) break;
27252
- const vMerge = getTableCellVMerge(cellAtIndex);
27253
- if (!vMerge || vMerge === "restart") {
27254
- break;
27255
- }
27256
- rowspan++;
27257
- remainingRow.elements.splice(firstCell + cellIndex, 1);
27258
- }
27259
- attributes["rowspan"] = rowspan;
27508
+ return null;
27509
+ };
27510
+ const resolveFallbackColumnWidthTwips = (params2, totalColumns, cellMinWidthTwips) => {
27511
+ const columnCount = Math.max(totalColumns, 1);
27512
+ const defaultColumnWidthPx = getSchemaDefaultColumnWidthPx(params2);
27513
+ const tableWidthPx = getTableWidthPx(params2);
27514
+ const safeDefaultPx = Number.isFinite(defaultColumnWidthPx) && defaultColumnWidthPx > 0 ? defaultColumnWidthPx : DEFAULT_COLUMN_WIDTH_PX;
27515
+ let fallbackWidthPx = safeDefaultPx;
27516
+ if (typeof tableWidthPx === "number" && tableWidthPx > 0) {
27517
+ fallbackWidthPx = tableWidthPx / columnCount;
27518
+ }
27519
+ const fallbackWidthTwips = pixelsToTwips(fallbackWidthPx);
27520
+ if (!Number.isFinite(fallbackWidthTwips) || Number.isNaN(fallbackWidthTwips) || fallbackWidthTwips <= 0) {
27521
+ const safeDefault = Math.max(pixelsToTwips(safeDefaultPx), cellMinWidthTwips);
27522
+ return safeDefault;
27260
27523
  }
27524
+ return Math.max(fallbackWidthTwips, cellMinWidthTwips);
27525
+ };
27526
+ const XML_NODE_NAME$g = "w:tblGrid";
27527
+ const SD_ATTR_KEY$3 = "grid";
27528
+ const cellMinWidth = pixelsToTwips(10);
27529
+ const encode$m = (params2) => {
27530
+ const { nodes } = params2;
27531
+ const node = nodes[0];
27532
+ const attributes = encodeProperties(node, { [translator$u.xmlName]: translator$u }, true);
27261
27533
  return {
27262
- type: "tableCell",
27263
- content: normalizeTableCellContent(
27264
- nodeListHandler.handler({
27265
- ...params2,
27266
- nodes: node.elements,
27267
- path: [...params2.path || [], node]
27268
- }),
27269
- params2.editor
27270
- ),
27271
- attrs: attributes
27272
- };
27273
- }
27274
- function normalizeTableCellContent(content, editor) {
27275
- if (!Array.isArray(content) || content.length === 0) return content;
27276
- const normalized = [];
27277
- const pendingForNextBlock = [];
27278
- const schema = editor?.schema;
27279
- const cloneBlock = (node) => {
27280
- if (!node) return node;
27281
- const cloned = { ...node };
27282
- if (Array.isArray(node.content)) {
27283
- cloned.content = [...node.content];
27284
- }
27285
- return cloned;
27534
+ xmlName: XML_NODE_NAME$g,
27535
+ sdNodeOrKeyName: SD_ATTR_KEY$3,
27536
+ attributes
27286
27537
  };
27287
- const ensureArray = (node) => {
27288
- if (!Array.isArray(node.content)) {
27289
- node.content = [];
27538
+ };
27539
+ const decode$o = (params2) => {
27540
+ const { grid: rawGrid } = params2.node.attrs || {};
27541
+ const grid = Array.isArray(rawGrid) ? rawGrid : [];
27542
+ const { firstRow = {} } = params2.extraParams || {};
27543
+ const cellNodes = firstRow.content?.filter((n) => n.type === "tableCell") ?? [];
27544
+ const columnCountFromCells = cellNodes.reduce((count, cell) => {
27545
+ const spanCount = Math.max(1, cell?.attrs?.colspan ?? 1);
27546
+ return count + spanCount;
27547
+ }, 0);
27548
+ const totalColumns = Math.max(columnCountFromCells, grid.length);
27549
+ const fallbackColumnWidthTwips = resolveFallbackColumnWidthTwips(params2, totalColumns, cellMinWidth);
27550
+ const elements = [];
27551
+ let columnIndex = 0;
27552
+ const pushColumn = (widthTwips, { enforceMinimum = false } = {}) => {
27553
+ let numericWidth = typeof widthTwips === "string" ? parseInt(widthTwips, 10) : widthTwips;
27554
+ let shouldEnforceMinimum = enforceMinimum;
27555
+ if (numericWidth == null || Number.isNaN(numericWidth) || numericWidth <= 0) {
27556
+ numericWidth = fallbackColumnWidthTwips;
27557
+ shouldEnforceMinimum = true;
27290
27558
  }
27291
- return node.content;
27559
+ const roundedWidth = Math.round(numericWidth);
27560
+ const minimumWidth = shouldEnforceMinimum ? cellMinWidth : 1;
27561
+ const safeWidth = Math.max(roundedWidth, minimumWidth);
27562
+ const decoded = translator$u.decode({
27563
+ node: { type: (
27564
+ /** @type {string} */
27565
+ translator$u.sdNodeOrKeyName
27566
+ ), attrs: { col: safeWidth } }
27567
+ });
27568
+ if (decoded) elements.push(decoded);
27292
27569
  };
27293
- const isInlineNode = (node) => {
27294
- if (!node || typeof node.type !== "string") return false;
27295
- if (node.type === "text") return true;
27296
- if (node.type === "bookmarkStart" || node.type === "bookmarkEnd") return true;
27297
- const nodeType = schema?.nodes?.[node.type];
27298
- if (nodeType) {
27299
- if (typeof nodeType.isInline === "boolean") return nodeType.isInline;
27300
- if (nodeType.spec?.group && typeof nodeType.spec.group === "string") {
27301
- return nodeType.spec.group.split(" ").includes("inline");
27570
+ cellNodes.forEach((cell) => {
27571
+ const { colspan = 1, colwidth } = cell?.attrs || {};
27572
+ const spanCount = Math.max(1, colspan);
27573
+ for (let span = 0; span < spanCount; span++) {
27574
+ const rawWidth = Array.isArray(colwidth) ? colwidth[span] : void 0;
27575
+ const cellWidthPixels = typeof rawWidth === "number" && Number.isFinite(rawWidth) ? rawWidth : Number(rawWidth);
27576
+ const hasCellWidth = Number.isFinite(cellWidthPixels) && cellWidthPixels > 0;
27577
+ const colGridAttrs = grid?.[columnIndex] || {};
27578
+ const gridWidthTwips = normalizeTwipWidth(colGridAttrs.col);
27579
+ const gridWidthPixels = gridWidthTwips != null ? twipsToPixels(gridWidthTwips) : null;
27580
+ let cellWidthTwips;
27581
+ let enforceMinimum = false;
27582
+ if (hasCellWidth) {
27583
+ const tolerance = 0.5;
27584
+ if (gridWidthTwips != null && gridWidthPixels != null && Math.abs(gridWidthPixels - cellWidthPixels) <= tolerance) {
27585
+ cellWidthTwips = gridWidthTwips;
27586
+ } else {
27587
+ cellWidthTwips = pixelsToTwips(cellWidthPixels);
27588
+ }
27589
+ } else if (gridWidthTwips != null) {
27590
+ cellWidthTwips = gridWidthTwips;
27591
+ } else {
27592
+ cellWidthTwips = fallbackColumnWidthTwips;
27593
+ enforceMinimum = true;
27302
27594
  }
27595
+ pushColumn(cellWidthTwips, { enforceMinimum });
27596
+ columnIndex++;
27303
27597
  }
27304
- return false;
27598
+ });
27599
+ while (columnIndex < grid.length) {
27600
+ const gridWidthTwips = normalizeTwipWidth(grid[columnIndex]?.col);
27601
+ pushColumn(gridWidthTwips);
27602
+ columnIndex++;
27603
+ }
27604
+ const newNode = {
27605
+ name: XML_NODE_NAME$g,
27606
+ attributes: {},
27607
+ elements
27305
27608
  };
27306
- for (const node of content) {
27307
- if (!node || typeof node.type !== "string") {
27308
- normalized.push(node);
27309
- continue;
27310
- }
27311
- if (!isInlineNode(node)) {
27312
- const blockNode = cloneBlock(node);
27313
- if (pendingForNextBlock.length) {
27314
- const blockContent = ensureArray(blockNode);
27315
- const leadingInline = pendingForNextBlock.splice(0);
27316
- blockNode.content = [...leadingInline, ...blockContent];
27317
- } else if (Array.isArray(blockNode.content)) {
27318
- blockNode.content = [...blockNode.content];
27319
- }
27320
- normalized.push(blockNode);
27321
- continue;
27322
- }
27323
- const targetIsNextBlock = node.type === "bookmarkStart" || normalized.length === 0;
27324
- if (targetIsNextBlock) {
27325
- pendingForNextBlock.push(node);
27609
+ return newNode;
27610
+ };
27611
+ const config$f = {
27612
+ xmlName: XML_NODE_NAME$g,
27613
+ sdNodeOrKeyName: SD_ATTR_KEY$3,
27614
+ encode: encode$m,
27615
+ decode: decode$o
27616
+ };
27617
+ const translator$t = NodeTranslator.from(config$f);
27618
+ const DEFAULT_PAGE_WIDTH_TWIPS = 12240;
27619
+ const DEFAULT_PAGE_MARGIN_TWIPS = 1440;
27620
+ const DEFAULT_CONTENT_WIDTH_TWIPS = DEFAULT_PAGE_WIDTH_TWIPS - 2 * DEFAULT_PAGE_MARGIN_TWIPS;
27621
+ const MIN_COLUMN_WIDTH_TWIPS = pixelsToTwips(10);
27622
+ const pctToPercent = (value) => {
27623
+ if (value == null) return null;
27624
+ return value / 50;
27625
+ };
27626
+ const resolveContentWidthTwips = () => DEFAULT_CONTENT_WIDTH_TWIPS;
27627
+ const resolveMeasurementWidthPx = (measurement) => {
27628
+ if (!measurement || typeof measurement.value !== "number" || measurement.value <= 0) return null;
27629
+ const { value, type: type2 } = measurement;
27630
+ if (!type2 || type2 === "auto") return null;
27631
+ if (type2 === "dxa") return twipsToPixels(value);
27632
+ if (type2 === "pct") {
27633
+ const percent2 = pctToPercent(value);
27634
+ if (percent2 == null || percent2 <= 0) return null;
27635
+ const widthTwips = resolveContentWidthTwips() * percent2 / 100;
27636
+ return twipsToPixels(widthTwips);
27637
+ }
27638
+ return null;
27639
+ };
27640
+ const countColumnsInRow = (row) => {
27641
+ if (!row?.elements?.length) return 0;
27642
+ return row.elements.reduce((count, element) => {
27643
+ if (element.name !== "w:tc") return count;
27644
+ const tcPr = element.elements?.find((el) => el.name === "w:tcPr");
27645
+ const gridSpan = tcPr?.elements?.find((el) => el.name === "w:gridSpan");
27646
+ const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
27647
+ return count + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
27648
+ }, 0);
27649
+ };
27650
+ const clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS);
27651
+ const createFallbackGrid = (columnCount, columnWidthTwips) => Array.from({ length: columnCount }, () => ({ col: clampColumnWidthTwips(columnWidthTwips) }));
27652
+ const buildFallbackGridForTable = ({ params: params2, rows, tableWidth, tableWidthMeasurement }) => {
27653
+ const firstRow = rows.find((row) => row.elements?.some((el) => el.name === "w:tc"));
27654
+ const columnCount = countColumnsInRow(firstRow);
27655
+ if (!columnCount) return null;
27656
+ const schemaDefaultPx = getSchemaDefaultColumnWidthPx(
27657
+ /** @type {any} */
27658
+ params2
27659
+ );
27660
+ const minimumColumnWidthPx = Number.isFinite(schemaDefaultPx) && schemaDefaultPx > 0 ? schemaDefaultPx : DEFAULT_COLUMN_WIDTH_PX;
27661
+ let totalWidthPx;
27662
+ if (tableWidthMeasurement) {
27663
+ const resolved = resolveMeasurementWidthPx(tableWidthMeasurement);
27664
+ if (resolved != null) totalWidthPx = resolved;
27665
+ }
27666
+ if (totalWidthPx == null && tableWidth?.width && tableWidth.width > 0) {
27667
+ totalWidthPx = tableWidth.width;
27668
+ }
27669
+ if (totalWidthPx == null) {
27670
+ totalWidthPx = minimumColumnWidthPx * columnCount;
27671
+ }
27672
+ const rawColumnWidthPx = Math.max(totalWidthPx / columnCount, minimumColumnWidthPx);
27673
+ const columnWidthTwips = clampColumnWidthTwips(pixelsToTwips(rawColumnWidthPx));
27674
+ const fallbackColumnWidthPx = twipsToPixels(columnWidthTwips);
27675
+ return {
27676
+ grid: createFallbackGrid(columnCount, columnWidthTwips),
27677
+ columnWidths: Array(columnCount).fill(fallbackColumnWidthPx)
27678
+ };
27679
+ };
27680
+ const XML_NODE_NAME$f = "w:tbl";
27681
+ const SD_NODE_NAME$c = "table";
27682
+ const encode$l = (params2, encodedAttrs) => {
27683
+ const { nodes } = params2;
27684
+ const node = nodes[0];
27685
+ const tblPr = node.elements.find((el) => el.name === "w:tblPr");
27686
+ if (tblPr) {
27687
+ const encodedProperties = translator$v.encode({ ...params2, nodes: [tblPr] });
27688
+ encodedAttrs["tableProperties"] = encodedProperties || {};
27689
+ }
27690
+ const tblGrid = node.elements.find((el) => el.name === "w:tblGrid");
27691
+ if (tblGrid) {
27692
+ encodedAttrs["grid"] = translator$t.encode({ ...params2, nodes: [tblGrid] }).attributes;
27693
+ }
27694
+ [
27695
+ "tableStyleId",
27696
+ "justification",
27697
+ "tableLayout",
27698
+ ["tableIndent", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
27699
+ ["tableCellSpacing", ({ value, type: type2 }) => ({ w: String(value), type: type2 })]
27700
+ ].forEach((prop) => {
27701
+ let key2;
27702
+ let transform;
27703
+ if (Array.isArray(prop)) {
27704
+ [key2, transform] = prop;
27326
27705
  } else {
27327
- const lastIndex = normalized.length - 1;
27328
- const lastNode = normalized[lastIndex];
27329
- if (!lastNode || typeof lastNode.type !== "string" || isInlineNode(lastNode)) {
27330
- pendingForNextBlock.push(node);
27331
- continue;
27332
- }
27333
- const blockContent = ensureArray(lastNode);
27334
- if (pendingForNextBlock.length) {
27335
- blockContent.push(...pendingForNextBlock.splice(0));
27336
- }
27337
- blockContent.push(node);
27706
+ key2 = prop;
27707
+ transform = (v2) => v2;
27338
27708
  }
27339
- }
27340
- if (pendingForNextBlock.length) {
27341
- if (normalized.length) {
27342
- const lastIndex = normalized.length - 1;
27343
- const lastNode = normalized[lastIndex];
27344
- if (lastNode && typeof lastNode.type === "string" && !isInlineNode(lastNode)) {
27345
- const blockContent = ensureArray(lastNode);
27346
- blockContent.push(...pendingForNextBlock);
27347
- pendingForNextBlock.length = 0;
27348
- }
27709
+ if (encodedAttrs.tableProperties && encodedAttrs.tableProperties[key2]) {
27710
+ encodedAttrs[key2] = transform(encodedAttrs.tableProperties[key2]);
27349
27711
  }
27350
- if (pendingForNextBlock.length) {
27351
- normalized.push({
27352
- type: "paragraph",
27353
- attrs: {},
27354
- content: [...pendingForNextBlock]
27355
- });
27356
- pendingForNextBlock.length = 0;
27712
+ });
27713
+ if (encodedAttrs.tableCellSpacing) {
27714
+ encodedAttrs["borderCollapse"] = "separate";
27715
+ }
27716
+ if (encodedAttrs.tableProperties?.tableWidth) {
27717
+ const tableWidthMeasurement = encodedAttrs.tableProperties.tableWidth;
27718
+ const widthPx = twipsToPixels(tableWidthMeasurement.value);
27719
+ if (widthPx != null) {
27720
+ encodedAttrs.tableWidth = {
27721
+ width: widthPx,
27722
+ type: tableWidthMeasurement.type
27723
+ };
27724
+ } else if (tableWidthMeasurement.type === "auto") {
27725
+ encodedAttrs.tableWidth = {
27726
+ width: 0,
27727
+ type: tableWidthMeasurement.type
27728
+ };
27357
27729
  }
27358
27730
  }
27359
- return normalized;
27360
- }
27361
- const processInlineCellBorders = (borders, rowBorders) => {
27362
- if (!borders) return null;
27363
- return ["bottom", "top", "left", "right"].reduce((acc, direction) => {
27364
- const borderAttrs = borders[direction];
27365
- const rowBorderAttrs = rowBorders[direction];
27366
- if (borderAttrs && borderAttrs["val"] !== "nil") {
27367
- const color = borderAttrs["color"];
27368
- let size2 = borderAttrs["size"];
27369
- if (size2) size2 = eighthPointsToPixels(size2);
27370
- acc[direction] = { color, size: size2, val: borderAttrs["val"] };
27371
- return acc;
27731
+ const { borders, rowBorders } = _processTableBorders(encodedAttrs.tableProperties?.borders || {});
27732
+ const referencedStyles = _getReferencedTableStyles(encodedAttrs.tableStyleId, params2);
27733
+ if (referencedStyles?.cellMargins && !encodedAttrs.tableProperties?.cellMargins) {
27734
+ encodedAttrs.tableProperties = {
27735
+ ...encodedAttrs.tableProperties || {},
27736
+ cellMargins: referencedStyles.cellMargins
27737
+ };
27738
+ }
27739
+ const rows = node.elements.filter((el) => el.name === "w:tr");
27740
+ const borderData = Object.assign({}, referencedStyles?.borders || {}, borders || {});
27741
+ const borderRowData = Object.assign({}, referencedStyles?.rowBorders || {}, rowBorders || {});
27742
+ encodedAttrs["borders"] = borderData;
27743
+ const tblStyleTag = tblPr?.elements?.find((el) => el.name === "w:tblStyle");
27744
+ let columnWidths = Array.isArray(encodedAttrs["grid"]) ? encodedAttrs["grid"].map((item) => twipsToPixels(item.col)) : [];
27745
+ if (!columnWidths.length) {
27746
+ const fallback = buildFallbackGridForTable({
27747
+ params: params2,
27748
+ rows,
27749
+ tableWidth: encodedAttrs.tableWidth,
27750
+ tableWidthMeasurement: encodedAttrs.tableProperties?.tableWidth
27751
+ });
27752
+ if (fallback) {
27753
+ encodedAttrs.grid = fallback.grid;
27754
+ columnWidths = fallback.columnWidths;
27372
27755
  }
27373
- if (borderAttrs && borderAttrs["val"] === "nil") {
27374
- const border = Object.assign({}, rowBorderAttrs || {});
27375
- if (!Object.keys(border).length) {
27376
- return acc;
27377
- } else {
27378
- border["val"] = "none";
27379
- acc[direction] = border;
27380
- return acc;
27756
+ }
27757
+ const content = [];
27758
+ const totalColumns = columnWidths.length;
27759
+ const activeRowSpans = totalColumns > 0 ? new Array(totalColumns).fill(0) : [];
27760
+ rows.forEach((row, rowIndex) => {
27761
+ const result = translator$Z.encode({
27762
+ ...params2,
27763
+ nodes: [row],
27764
+ extraParams: {
27765
+ row,
27766
+ table: node,
27767
+ rowBorders: borderRowData,
27768
+ styleTag: tblStyleTag,
27769
+ columnWidths,
27770
+ activeRowSpans: activeRowSpans.slice(),
27771
+ rowIndex
27772
+ }
27773
+ });
27774
+ if (result) {
27775
+ content.push(result);
27776
+ if (totalColumns > 0) {
27777
+ const activeRowSpansForCurrentRow = activeRowSpans.slice();
27778
+ for (let col = 0; col < totalColumns; col++) {
27779
+ if (activeRowSpans[col] > 0) {
27780
+ activeRowSpans[col] -= 1;
27781
+ }
27782
+ }
27783
+ let columnIndex = 0;
27784
+ const advanceColumnIndex = () => {
27785
+ while (columnIndex < totalColumns && activeRowSpansForCurrentRow[columnIndex] > 0) {
27786
+ columnIndex += 1;
27787
+ }
27788
+ };
27789
+ advanceColumnIndex();
27790
+ result.content?.forEach((cell) => {
27791
+ advanceColumnIndex();
27792
+ const colspan = Math.max(1, cell.attrs?.colspan || 1);
27793
+ const rowspan = Math.max(1, cell.attrs?.rowspan || 1);
27794
+ if (rowspan > 1) {
27795
+ for (let offset2 = 0; offset2 < colspan && columnIndex + offset2 < totalColumns; offset2++) {
27796
+ const targetIndex = columnIndex + offset2;
27797
+ const remainingRows = rowspan - 1;
27798
+ if (remainingRows > 0 && remainingRows > activeRowSpans[targetIndex]) {
27799
+ activeRowSpans[targetIndex] = remainingRows;
27800
+ }
27801
+ }
27802
+ }
27803
+ columnIndex += colspan;
27804
+ advanceColumnIndex();
27805
+ });
27381
27806
  }
27382
27807
  }
27383
- return acc;
27384
- }, {});
27385
- };
27386
- const getTableCellVMerge = (node) => {
27387
- const tcPr = node.elements.find((el) => el.name === "w:tcPr");
27388
- const vMerge = tcPr?.elements?.find((el) => el.name === "w:vMerge");
27389
- if (!vMerge) return null;
27390
- return vMerge.attributes?.["w:val"] || "continue";
27391
- };
27392
- const getTableCellMargins = (inlineMargins, referencedStyles) => {
27393
- const { cellMargins = {} } = referencedStyles;
27394
- return ["left", "right", "top", "bottom"].reduce((acc, direction) => {
27395
- const key2 = `margin${direction.charAt(0).toUpperCase() + direction.slice(1)}`;
27396
- const inlineValue = inlineMargins ? inlineMargins?.[key2]?.value : null;
27397
- const styleValue = cellMargins ? cellMargins[key2] : null;
27398
- if (inlineValue != null) {
27399
- acc[direction] = twipsToPixels(inlineValue);
27400
- } else if (styleValue == null) {
27401
- acc[direction] = void 0;
27402
- } else if (typeof styleValue === "object") {
27403
- acc[direction] = twipsToPixels(styleValue.value);
27404
- } else {
27405
- acc[direction] = twipsToPixels(styleValue);
27406
- }
27407
- return acc;
27408
- }, {});
27808
+ });
27809
+ return {
27810
+ type: "table",
27811
+ content,
27812
+ attrs: encodedAttrs
27813
+ };
27409
27814
  };
27410
- function translateTableCell(params2) {
27411
- const elements = translateChildNodes({
27815
+ const decode$n = (params2, decodedAttrs) => {
27816
+ params2.node = preProcessVerticalMergeCells(params2.node, params2);
27817
+ const { node } = params2;
27818
+ const elements = translateChildNodes(params2);
27819
+ const firstRow = node.content?.find((n) => n.type === "tableRow");
27820
+ const properties = node.attrs.grid;
27821
+ const element = translator$t.decode({
27412
27822
  ...params2,
27413
- tableCell: params2.node
27823
+ node: { ...node, attrs: { ...node.attrs, grid: properties } },
27824
+ extraParams: {
27825
+ firstRow
27826
+ }
27414
27827
  });
27415
- const cellProps = generateTableCellProperties(params2.node);
27416
- elements.unshift(cellProps);
27828
+ if (element) elements.unshift(element);
27829
+ if (node.attrs?.tableProperties) {
27830
+ const properties2 = { ...node.attrs.tableProperties };
27831
+ const element2 = translator$v.decode({
27832
+ ...params2,
27833
+ node: { ...node, attrs: { ...node.attrs, tableProperties: properties2 } }
27834
+ });
27835
+ if (element2) elements.unshift(element2);
27836
+ }
27417
27837
  return {
27418
- name: "w:tc",
27838
+ name: "w:tbl",
27839
+ attributes: decodedAttrs || {},
27419
27840
  elements
27420
27841
  };
27842
+ };
27843
+ function _processTableBorders(rawBorders) {
27844
+ const borders = {};
27845
+ const rowBorders = {};
27846
+ Object.entries(rawBorders).forEach(([name, attributes]) => {
27847
+ const attrs = {};
27848
+ const color = attributes.color;
27849
+ const size2 = attributes.size;
27850
+ if (color && color !== "auto") attrs["color"] = color.startsWith("#") ? color : `#${color}`;
27851
+ if (size2 && size2 !== "auto") attrs["size"] = eighthPointsToPixels(size2);
27852
+ const rowBorderNames = ["insideH", "insideV"];
27853
+ if (rowBorderNames.includes(name)) rowBorders[name] = attrs;
27854
+ borders[name] = attrs;
27855
+ });
27856
+ return {
27857
+ borders,
27858
+ rowBorders
27859
+ };
27421
27860
  }
27422
- function generateTableCellProperties(node) {
27423
- const tableCellProperties = { ...node.attrs?.tableCellProperties || {} };
27424
- const { attrs } = node;
27425
- const { colwidth = [], cellWidthType = "dxa", widthUnit } = attrs;
27426
- const colwidthSum = colwidth.reduce((acc, curr) => acc + curr, 0);
27427
- const propertiesWidthPixels = twipsToPixels(tableCellProperties.cellWidth?.value);
27428
- if (propertiesWidthPixels !== colwidthSum) {
27429
- tableCellProperties["cellWidth"] = {
27430
- value: widthUnit === "px" ? pixelsToTwips(colwidthSum) : inchesToTwips(colwidthSum),
27431
- type: cellWidthType
27432
- };
27861
+ function _getReferencedTableStyles(tableStyleReference, params2) {
27862
+ if (!tableStyleReference) return null;
27863
+ const stylesToReturn = {};
27864
+ const { docx } = params2;
27865
+ const styles = docx["word/styles.xml"];
27866
+ const { elements } = styles.elements[0];
27867
+ const styleElements = elements.filter((el) => el.name === "w:style");
27868
+ const styleTag = styleElements.find((el) => el.attributes["w:styleId"] === tableStyleReference);
27869
+ if (!styleTag) return null;
27870
+ stylesToReturn.name = styleTag.elements.find((el) => el.name === "w:name");
27871
+ const basedOn = styleTag.elements.find((el) => el.name === "w:basedOn");
27872
+ let baseTblPr;
27873
+ if (basedOn?.attributes) {
27874
+ const baseStyles = styleElements.find((el) => el.attributes["w:styleId"] === basedOn.attributes["w:val"]);
27875
+ baseTblPr = baseStyles ? baseStyles.elements.find((el) => el.name === "w:tblPr") : {};
27433
27876
  }
27434
- const { colspan } = attrs;
27435
- if (colspan > 1 && tableCellProperties.gridSpan !== colspan) {
27436
- tableCellProperties["gridSpan"] = colspan;
27437
- } else if (!colspan || tableCellProperties?.gridSpan === 1) {
27438
- delete tableCellProperties.gridSpan;
27877
+ const pPr = styleTag.elements.find((el) => el.name === "w:pPr");
27878
+ if (pPr) {
27879
+ const justification = pPr.elements.find((el) => el.name === "w:jc");
27880
+ if (justification?.attributes) stylesToReturn.justification = justification.attributes["w:val"];
27439
27881
  }
27440
- const { background = {} } = attrs;
27441
- if (background?.color && tableCellProperties.shading?.fill !== background?.color) {
27442
- tableCellProperties["shading"] = { fill: background.color };
27443
- } else if (!background?.color && tableCellProperties?.shading?.fill) {
27882
+ const rPr = styleTag?.elements.find((el) => el.name === "w:rPr");
27883
+ if (rPr) {
27884
+ const fonts = rPr.elements.find((el) => el.name === "w:rFonts");
27885
+ if (fonts) {
27886
+ const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
27887
+ stylesToReturn.fonts = { ascii, hAnsi, cs };
27888
+ }
27889
+ const fontSize2 = rPr.elements.find((el) => el.name === "w:sz");
27890
+ if (fontSize2?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize2.attributes["w:val"]) + "pt";
27891
+ }
27892
+ const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
27893
+ if (tblPr && tblPr.elements) {
27894
+ if (baseTblPr && baseTblPr.elements) {
27895
+ tblPr.elements.push(...baseTblPr.elements);
27896
+ }
27897
+ const tableProperties = translator$v.encode({ ...params2, nodes: [tblPr] });
27898
+ const { borders, rowBorders } = _processTableBorders(tableProperties.borders || {});
27899
+ if (borders) stylesToReturn.borders = borders;
27900
+ if (rowBorders) stylesToReturn.rowBorders = rowBorders;
27901
+ const cellMargins = {};
27902
+ Object.entries(tableProperties.cellMargins || {}).forEach(([key2, attrs]) => {
27903
+ if (attrs?.value != null) {
27904
+ cellMargins[key2] = {
27905
+ value: attrs.value,
27906
+ type: attrs.type || "dxa"
27907
+ };
27908
+ }
27909
+ });
27910
+ if (Object.keys(cellMargins).length) stylesToReturn.cellMargins = cellMargins;
27911
+ }
27912
+ return stylesToReturn;
27913
+ }
27914
+ const config$e = {
27915
+ xmlName: XML_NODE_NAME$f,
27916
+ sdNodeOrKeyName: SD_NODE_NAME$c,
27917
+ type: NodeTranslator.translatorTypes.NODE,
27918
+ encode: encode$l,
27919
+ decode: decode$n,
27920
+ attributes: []
27921
+ };
27922
+ const translator$s = NodeTranslator.from(config$e);
27923
+ const tableNodeHandlerEntity = generateV2HandlerEntity("tableNodeHandler", translator$s);
27924
+ function getReferencedTableStyles(tblStyleTag, docx) {
27925
+ if (!tblStyleTag) return null;
27926
+ const stylesToReturn = {};
27927
+ const { attributes = {} } = tblStyleTag;
27928
+ const tableStyleReference = attributes["w:val"];
27929
+ if (!tableStyleReference) return null;
27930
+ const styles = docx["word/styles.xml"];
27931
+ const { elements } = styles.elements[0];
27932
+ const styleElements = elements.filter((el) => el.name === "w:style");
27933
+ const styleTag = styleElements.find((el) => el.attributes["w:styleId"] === tableStyleReference);
27934
+ if (!styleTag) return null;
27935
+ stylesToReturn.name = styleTag.elements.find((el) => el.name === "w:name");
27936
+ const basedOn = styleTag.elements.find((el) => el.name === "w:basedOn");
27937
+ let baseTblPr;
27938
+ if (basedOn?.attributes) {
27939
+ const baseStyles = styleElements.find((el) => el.attributes["w:styleId"] === basedOn.attributes["w:val"]);
27940
+ baseTblPr = baseStyles ? baseStyles.elements.find((el) => el.name === "w:tblPr") : {};
27941
+ }
27942
+ const pPr = styleTag.elements.find((el) => el.name === "w:pPr");
27943
+ if (pPr) {
27944
+ const justification = pPr.elements.find((el) => el.name === "w:jc");
27945
+ if (justification?.attributes) stylesToReturn.justification = justification.attributes["w:val"];
27946
+ }
27947
+ const rPr = styleTag?.elements.find((el) => el.name === "w:rPr");
27948
+ if (rPr) {
27949
+ const fonts = rPr.elements.find((el) => el.name === "w:rFonts");
27950
+ if (fonts) {
27951
+ const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
27952
+ stylesToReturn.fonts = { ascii, hAnsi, cs };
27953
+ }
27954
+ const fontSize2 = rPr.elements.find((el) => el.name === "w:sz");
27955
+ if (fontSize2?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize2.attributes["w:val"]) + "pt";
27956
+ }
27957
+ const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
27958
+ if (tblPr && tblPr.elements) {
27959
+ if (baseTblPr && baseTblPr.elements) {
27960
+ tblPr.elements.push(...baseTblPr.elements);
27961
+ }
27962
+ const tableBorders = tblPr?.elements?.find((el) => el.name === "w:tblBorders");
27963
+ const { elements: borderElements = [] } = tableBorders || {};
27964
+ const { borders, rowBorders } = processTableBorders(borderElements);
27965
+ if (borders) stylesToReturn.borders = borders;
27966
+ if (rowBorders) stylesToReturn.rowBorders = rowBorders;
27967
+ const tableCellMargin = tblPr?.elements.find((el) => el.name === "w:tblCellMar");
27968
+ if (tableCellMargin) {
27969
+ const marginLeft = tableCellMargin.elements.find((el) => el.name === "w:left");
27970
+ const marginRight = tableCellMargin.elements.find((el) => el.name === "w:right");
27971
+ const marginTop = tableCellMargin.elements.find((el) => el.name === "w:top");
27972
+ const marginBottom = tableCellMargin.elements.find((el) => el.name === "w:bottom");
27973
+ stylesToReturn.cellMargins = {
27974
+ marginLeft: marginLeft?.attributes["w:w"],
27975
+ marginRight: marginRight?.attributes["w:w"],
27976
+ marginTop: marginTop?.attributes["w:w"],
27977
+ marginBottom: marginBottom?.attributes["w:w"]
27978
+ };
27979
+ }
27980
+ }
27981
+ return stylesToReturn;
27982
+ }
27983
+ function processTableBorders(borderElements) {
27984
+ const borders = {};
27985
+ const rowBorders = {};
27986
+ borderElements.forEach((borderElement) => {
27987
+ const { name } = borderElement;
27988
+ const borderName = name.split("w:")[1];
27989
+ const { attributes } = borderElement;
27990
+ const attrs = {};
27991
+ const color = attributes["w:color"];
27992
+ const size2 = attributes["w:sz"];
27993
+ if (color && color !== "auto") attrs["color"] = color.startsWith("#") ? color : `#${color}`;
27994
+ if (size2 && size2 !== "auto") attrs["size"] = eighthPointsToPixels(size2);
27995
+ const rowBorderNames = ["insideH", "insideV"];
27996
+ if (rowBorderNames.includes(borderName)) rowBorders[borderName] = attrs;
27997
+ borders[borderName] = attrs;
27998
+ });
27999
+ return {
28000
+ borders,
28001
+ rowBorders
28002
+ };
28003
+ }
28004
+ const translator$r = NodeTranslator.from(createMeasurementPropertyHandler("w:tcW", "cellWidth"));
28005
+ const translator$q = NodeTranslator.from(
28006
+ createSingleAttrPropertyHandler(
28007
+ "w:gridSpan",
28008
+ null,
28009
+ "w:val",
28010
+ (v2) => parseInteger(v2) ?? void 0,
28011
+ (v2) => integerToString(v2)
28012
+ )
28013
+ );
28014
+ const translator$p = NodeTranslator.from(createSingleAttrPropertyHandler("w:vMerge"));
28015
+ const translator$o = NodeTranslator.from(createBorderPropertyHandler("w:tl2br"));
28016
+ const translator$n = NodeTranslator.from(createBorderPropertyHandler("w:tr2bl"));
28017
+ const propertyTranslators$2 = [
28018
+ translator$z,
28019
+ translator$B,
28020
+ translator$F,
28021
+ translator$L,
28022
+ translator$J,
28023
+ translator$D,
28024
+ translator$H,
28025
+ translator$G,
28026
+ translator$o,
28027
+ translator$n
28028
+ ];
28029
+ const translator$m = NodeTranslator.from(
28030
+ createNestedPropertiesTranslator("w:tcBorders", "borders", propertyTranslators$2)
28031
+ );
28032
+ const translator$l = NodeTranslator.from(
28033
+ createSingleAttrPropertyHandler(
28034
+ "w:noWrap",
28035
+ null,
28036
+ "w:val",
28037
+ (v2) => parseBoolean(v2 ?? "true"),
28038
+ (v2) => booleanToString(v2)
28039
+ )
28040
+ );
28041
+ const propertyTranslators$1 = [
28042
+ translator$K,
28043
+ translator$I,
28044
+ translator$E,
28045
+ translator$C,
28046
+ translator$A,
28047
+ translator$y
28048
+ ];
28049
+ const translator$k = NodeTranslator.from(
28050
+ createNestedPropertiesTranslator("w:tcMar", "cellMargins", propertyTranslators$1)
28051
+ );
28052
+ const translator$j = NodeTranslator.from(createSingleAttrPropertyHandler("w:textDirection"));
28053
+ const translator$i = NodeTranslator.from(
28054
+ createSingleAttrPropertyHandler(
28055
+ "w:tcFitText",
28056
+ null,
28057
+ "w:val",
28058
+ (v2) => parseBoolean(v2 ?? "true"),
28059
+ (v2) => booleanToString(v2)
28060
+ )
28061
+ );
28062
+ const translator$h = NodeTranslator.from(createSingleAttrPropertyHandler("w:vAlign"));
28063
+ const translator$g = NodeTranslator.from(
28064
+ createSingleAttrPropertyHandler(
28065
+ "w:hideMark",
28066
+ null,
28067
+ "w:val",
28068
+ (v2) => parseBoolean(v2 ?? "true"),
28069
+ (v2) => booleanToString(v2)
28070
+ )
28071
+ );
28072
+ const translator$f = NodeTranslator.from(createSingleAttrPropertyHandler("w:header"));
28073
+ const XML_NODE_NAME$e = "w:headers";
28074
+ const SD_ATTR_KEY$2 = "headers";
28075
+ const encode$k = (params2) => {
28076
+ const { nodes } = params2;
28077
+ const node = nodes[0];
28078
+ const attributes = encodeProperties(node, { [translator$f.xmlName]: translator$f }, true);
28079
+ return {
28080
+ xmlName: XML_NODE_NAME$e,
28081
+ sdNodeOrKeyName: SD_ATTR_KEY$2,
28082
+ attributes
28083
+ };
28084
+ };
28085
+ const decode$m = (params2) => {
28086
+ const { headers = [] } = params2.node.attrs || {};
28087
+ const newNode = {
28088
+ name: XML_NODE_NAME$e,
28089
+ attributes: {},
28090
+ elements: headers.map(
28091
+ (header) => translator$f.decode({
28092
+ node: { type: "header", attrs: header }
28093
+ })
28094
+ )
28095
+ };
28096
+ return newNode;
28097
+ };
28098
+ const config$d = {
28099
+ xmlName: XML_NODE_NAME$e,
28100
+ sdNodeOrKeyName: SD_ATTR_KEY$2,
28101
+ encode: encode$k,
28102
+ decode: decode$m
28103
+ };
28104
+ const translator$e = NodeTranslator.from(config$d);
28105
+ const propertyTranslators = [
28106
+ translator$19,
28107
+ translator$r,
28108
+ translator$q,
28109
+ translator$p,
28110
+ translator$m,
28111
+ translator$X,
28112
+ translator$l,
28113
+ translator$k,
28114
+ translator$j,
28115
+ translator$i,
28116
+ translator$h,
28117
+ translator$g,
28118
+ translator$e
28119
+ ];
28120
+ const translator$d = NodeTranslator.from(
28121
+ createNestedPropertiesTranslator("w:tcPr", "tableCellProperties", propertyTranslators)
28122
+ );
28123
+ function handleTableCellNode({
28124
+ params: params2,
28125
+ node,
28126
+ table,
28127
+ row,
28128
+ rowBorders,
28129
+ styleTag,
28130
+ columnIndex,
28131
+ columnWidth = null,
28132
+ allColumnWidths = []
28133
+ }) {
28134
+ const { docx, nodeListHandler } = params2;
28135
+ const attributes = {};
28136
+ const tcPr = node.elements.find((el) => el.name === "w:tcPr");
28137
+ const tableCellProperties = tcPr ? translator$d.encode({ ...params2, nodes: [tcPr] }) ?? {} : {};
28138
+ attributes["tableCellProperties"] = tableCellProperties;
28139
+ if (rowBorders?.insideH) {
28140
+ rowBorders["bottom"] = rowBorders.insideH;
28141
+ delete rowBorders.insideH;
28142
+ }
28143
+ if (rowBorders?.insideV) {
28144
+ rowBorders["right"] = rowBorders.insideV;
28145
+ delete rowBorders?.insideV;
28146
+ }
28147
+ if (rowBorders) attributes["borders"] = { ...rowBorders };
28148
+ const inlineBorders = processInlineCellBorders(tableCellProperties.borders, rowBorders);
28149
+ if (inlineBorders) attributes["borders"] = Object.assign(attributes["borders"] || {}, inlineBorders);
28150
+ const colspan = tableCellProperties.gridSpan;
28151
+ if (colspan && !isNaN(parseInt(colspan, 10))) attributes["colspan"] = parseInt(colspan, 10);
28152
+ let width = tableCellProperties.cellWidth?.value ? twipsToPixels(tableCellProperties.cellWidth?.value) : null;
28153
+ const widthType = tableCellProperties.cellWidth?.type;
28154
+ if (widthType) attributes["widthType"] = widthType;
28155
+ if (!width && columnWidth) width = columnWidth;
28156
+ if (width) {
28157
+ attributes["colwidth"] = [width];
28158
+ attributes["widthUnit"] = "px";
28159
+ const defaultColWidths = allColumnWidths;
28160
+ const hasDefaultColWidths = allColumnWidths && allColumnWidths.length > 0;
28161
+ const colspanNum = parseInt(colspan || 1, 10);
28162
+ if (colspanNum && colspanNum > 1 && hasDefaultColWidths) {
28163
+ let colwidth = [];
28164
+ for (let i = 0; i < colspanNum; i++) {
28165
+ let colwidthValue = defaultColWidths[columnIndex + i];
28166
+ let defaultColwidth = 100;
28167
+ if (typeof colwidthValue !== "undefined") {
28168
+ colwidth.push(colwidthValue);
28169
+ } else {
28170
+ colwidth.push(defaultColwidth);
28171
+ }
28172
+ }
28173
+ if (colwidth.length) {
28174
+ attributes["colwidth"] = [...colwidth];
28175
+ }
28176
+ }
28177
+ }
28178
+ const background = {
28179
+ color: tableCellProperties.shading?.fill
28180
+ };
28181
+ if (background.color) attributes["background"] = background;
28182
+ const verticalAlign = tableCellProperties.vAlign;
28183
+ if (verticalAlign) attributes["verticalAlign"] = verticalAlign;
28184
+ const referencedStyles = getReferencedTableStyles(styleTag, docx) || { fontSize: null, fonts: {}, cellMargins: {} };
28185
+ attributes.cellMargins = getTableCellMargins(tableCellProperties.cellMargins, referencedStyles);
28186
+ const { fontSize: fontSize2, fonts = {} } = referencedStyles;
28187
+ const fontFamily2 = fonts["ascii"];
28188
+ if (fontSize2) attributes["fontSize"] = fontSize2;
28189
+ if (fontFamily2) attributes["fontFamily"] = fontFamily2;
28190
+ if (tableCellProperties.vMerge === "restart") {
28191
+ const rows = table.elements.filter((el) => el.name === "w:tr");
28192
+ const currentRowIndex = rows.findIndex((r2) => r2 === row);
28193
+ const remainingRows = rows.slice(currentRowIndex + 1);
28194
+ const cellsInRow = row.elements.filter((el) => el.name === "w:tc");
28195
+ let cellIndex = cellsInRow.findIndex((el) => el === node);
28196
+ let rowspan = 1;
28197
+ for (let remainingRow of remainingRows) {
28198
+ const firstCell = remainingRow.elements.findIndex((el) => el.name === "w:tc");
28199
+ const cellAtIndex = remainingRow.elements[firstCell + cellIndex];
28200
+ if (!cellAtIndex) break;
28201
+ const vMerge = getTableCellVMerge(cellAtIndex);
28202
+ if (!vMerge || vMerge === "restart") {
28203
+ break;
28204
+ }
28205
+ rowspan++;
28206
+ remainingRow.elements.splice(firstCell + cellIndex, 1);
28207
+ }
28208
+ attributes["rowspan"] = rowspan;
28209
+ }
28210
+ return {
28211
+ type: "tableCell",
28212
+ content: normalizeTableCellContent(
28213
+ nodeListHandler.handler({
28214
+ ...params2,
28215
+ nodes: node.elements,
28216
+ path: [...params2.path || [], node]
28217
+ }),
28218
+ params2.editor
28219
+ ),
28220
+ attrs: attributes
28221
+ };
28222
+ }
28223
+ function normalizeTableCellContent(content, editor) {
28224
+ if (!Array.isArray(content) || content.length === 0) return content;
28225
+ const normalized = [];
28226
+ const pendingForNextBlock = [];
28227
+ const schema = editor?.schema;
28228
+ const cloneBlock = (node) => {
28229
+ if (!node) return node;
28230
+ const cloned = { ...node };
28231
+ if (Array.isArray(node.content)) {
28232
+ cloned.content = [...node.content];
28233
+ }
28234
+ return cloned;
28235
+ };
28236
+ const ensureArray = (node) => {
28237
+ if (!Array.isArray(node.content)) {
28238
+ node.content = [];
28239
+ }
28240
+ return node.content;
28241
+ };
28242
+ const isInlineNode = (node) => {
28243
+ if (!node || typeof node.type !== "string") return false;
28244
+ if (node.type === "text") return true;
28245
+ if (node.type === "bookmarkStart" || node.type === "bookmarkEnd") return true;
28246
+ const nodeType = schema?.nodes?.[node.type];
28247
+ if (nodeType) {
28248
+ if (typeof nodeType.isInline === "boolean") return nodeType.isInline;
28249
+ if (nodeType.spec?.group && typeof nodeType.spec.group === "string") {
28250
+ return nodeType.spec.group.split(" ").includes("inline");
28251
+ }
28252
+ }
28253
+ return false;
28254
+ };
28255
+ for (const node of content) {
28256
+ if (!node || typeof node.type !== "string") {
28257
+ normalized.push(node);
28258
+ continue;
28259
+ }
28260
+ if (!isInlineNode(node)) {
28261
+ const blockNode = cloneBlock(node);
28262
+ if (pendingForNextBlock.length) {
28263
+ const blockContent = ensureArray(blockNode);
28264
+ const leadingInline = pendingForNextBlock.splice(0);
28265
+ blockNode.content = [...leadingInline, ...blockContent];
28266
+ } else if (Array.isArray(blockNode.content)) {
28267
+ blockNode.content = [...blockNode.content];
28268
+ }
28269
+ normalized.push(blockNode);
28270
+ continue;
28271
+ }
28272
+ const targetIsNextBlock = node.type === "bookmarkStart" || normalized.length === 0;
28273
+ if (targetIsNextBlock) {
28274
+ pendingForNextBlock.push(node);
28275
+ } else {
28276
+ const lastIndex = normalized.length - 1;
28277
+ const lastNode = normalized[lastIndex];
28278
+ if (!lastNode || typeof lastNode.type !== "string" || isInlineNode(lastNode)) {
28279
+ pendingForNextBlock.push(node);
28280
+ continue;
28281
+ }
28282
+ const blockContent = ensureArray(lastNode);
28283
+ if (pendingForNextBlock.length) {
28284
+ blockContent.push(...pendingForNextBlock.splice(0));
28285
+ }
28286
+ blockContent.push(node);
28287
+ }
28288
+ }
28289
+ if (pendingForNextBlock.length) {
28290
+ if (normalized.length) {
28291
+ const lastIndex = normalized.length - 1;
28292
+ const lastNode = normalized[lastIndex];
28293
+ if (lastNode && typeof lastNode.type === "string" && !isInlineNode(lastNode)) {
28294
+ const blockContent = ensureArray(lastNode);
28295
+ blockContent.push(...pendingForNextBlock);
28296
+ pendingForNextBlock.length = 0;
28297
+ }
28298
+ }
28299
+ if (pendingForNextBlock.length) {
28300
+ normalized.push({
28301
+ type: "paragraph",
28302
+ attrs: {},
28303
+ content: [...pendingForNextBlock]
28304
+ });
28305
+ pendingForNextBlock.length = 0;
28306
+ }
28307
+ }
28308
+ return normalized;
28309
+ }
28310
+ const processInlineCellBorders = (borders, rowBorders) => {
28311
+ if (!borders) return null;
28312
+ return ["bottom", "top", "left", "right"].reduce((acc, direction) => {
28313
+ const borderAttrs = borders[direction];
28314
+ const rowBorderAttrs = rowBorders[direction];
28315
+ if (borderAttrs && borderAttrs["val"] !== "nil") {
28316
+ const color = borderAttrs["color"];
28317
+ let size2 = borderAttrs["size"];
28318
+ if (size2) size2 = eighthPointsToPixels(size2);
28319
+ acc[direction] = { color, size: size2, val: borderAttrs["val"] };
28320
+ return acc;
28321
+ }
28322
+ if (borderAttrs && borderAttrs["val"] === "nil") {
28323
+ const border = Object.assign({}, rowBorderAttrs || {});
28324
+ if (!Object.keys(border).length) {
28325
+ return acc;
28326
+ } else {
28327
+ border["val"] = "none";
28328
+ acc[direction] = border;
28329
+ return acc;
28330
+ }
28331
+ }
28332
+ return acc;
28333
+ }, {});
28334
+ };
28335
+ const getTableCellVMerge = (node) => {
28336
+ const tcPr = node.elements.find((el) => el.name === "w:tcPr");
28337
+ const vMerge = tcPr?.elements?.find((el) => el.name === "w:vMerge");
28338
+ if (!vMerge) return null;
28339
+ return vMerge.attributes?.["w:val"] || "continue";
28340
+ };
28341
+ const getTableCellMargins = (inlineMargins, referencedStyles) => {
28342
+ const { cellMargins = {} } = referencedStyles;
28343
+ return ["left", "right", "top", "bottom"].reduce((acc, direction) => {
28344
+ const key2 = `margin${direction.charAt(0).toUpperCase() + direction.slice(1)}`;
28345
+ const inlineValue = inlineMargins ? inlineMargins?.[key2]?.value : null;
28346
+ const styleValue = cellMargins ? cellMargins[key2] : null;
28347
+ if (inlineValue != null) {
28348
+ acc[direction] = twipsToPixels(inlineValue);
28349
+ } else if (styleValue == null) {
28350
+ acc[direction] = void 0;
28351
+ } else if (typeof styleValue === "object") {
28352
+ acc[direction] = twipsToPixels(styleValue.value);
28353
+ } else {
28354
+ acc[direction] = twipsToPixels(styleValue);
28355
+ }
28356
+ return acc;
28357
+ }, {});
28358
+ };
28359
+ function translateTableCell(params2) {
28360
+ const elements = translateChildNodes({
28361
+ ...params2,
28362
+ tableCell: params2.node
28363
+ });
28364
+ const cellProps = generateTableCellProperties(params2.node);
28365
+ elements.unshift(cellProps);
28366
+ return {
28367
+ name: "w:tc",
28368
+ elements
28369
+ };
28370
+ }
28371
+ function generateTableCellProperties(node) {
28372
+ const tableCellProperties = { ...node.attrs?.tableCellProperties || {} };
28373
+ const { attrs } = node;
28374
+ const { colwidth = [], cellWidthType = "dxa", widthUnit } = attrs;
28375
+ const colwidthSum = colwidth.reduce((acc, curr) => acc + curr, 0);
28376
+ const propertiesWidthPixels = twipsToPixels(tableCellProperties.cellWidth?.value);
28377
+ if (propertiesWidthPixels !== colwidthSum) {
28378
+ tableCellProperties["cellWidth"] = {
28379
+ value: widthUnit === "px" ? pixelsToTwips(colwidthSum) : inchesToTwips(colwidthSum),
28380
+ type: cellWidthType
28381
+ };
28382
+ }
28383
+ const { colspan } = attrs;
28384
+ if (colspan > 1 && tableCellProperties.gridSpan !== colspan) {
28385
+ tableCellProperties["gridSpan"] = colspan;
28386
+ } else if (!colspan || tableCellProperties?.gridSpan === 1) {
28387
+ delete tableCellProperties.gridSpan;
28388
+ }
28389
+ const { background = {} } = attrs;
28390
+ if (background?.color && tableCellProperties.shading?.fill !== background?.color) {
28391
+ tableCellProperties["shading"] = { fill: background.color };
28392
+ } else if (!background?.color && tableCellProperties?.shading?.fill) {
27444
28393
  delete tableCellProperties.shading;
27445
28394
  }
27446
28395
  const { cellMargins } = attrs;
@@ -27498,22 +28447,22 @@ function generateTableCellProperties(node) {
27498
28447
  } else if (tableCellProperties?.borders) {
27499
28448
  delete tableCellProperties.borders;
27500
28449
  }
27501
- const result = translator$I.decode({ node: { ...node, attrs: { ...node.attrs, tableCellProperties } } });
28450
+ const result = translator$d.decode({ node: { ...node, attrs: { ...node.attrs, tableCellProperties } } });
27502
28451
  return result;
27503
28452
  }
27504
- const XML_NODE_NAME$g = "w:tc";
27505
- const SD_NODE_NAME$d = "tableCell";
27506
- const validXmlAttributes$b = [];
27507
- function encode$m(params2, encodedAttrs) {
28453
+ const XML_NODE_NAME$d = "w:tc";
28454
+ const SD_NODE_NAME$b = "tableCell";
28455
+ const validXmlAttributes$a = [];
28456
+ function encode$j(params2, encodedAttrs) {
27508
28457
  const {
27509
28458
  node,
27510
28459
  table,
27511
28460
  row,
27512
28461
  rowBorders,
28462
+ styleTag,
27513
28463
  columnIndex,
27514
28464
  columnWidth,
27515
- columnWidths: allColumnWidths,
27516
- _referencedStyles
28465
+ columnWidths: allColumnWidths
27517
28466
  } = params2.extraParams;
27518
28467
  const schemaNode = handleTableCellNode({
27519
28468
  params: params2,
@@ -27521,327 +28470,35 @@ function encode$m(params2, encodedAttrs) {
27521
28470
  table,
27522
28471
  row,
27523
28472
  rowBorders,
28473
+ styleTag,
27524
28474
  columnIndex,
27525
28475
  columnWidth,
27526
- allColumnWidths,
27527
- _referencedStyles
28476
+ allColumnWidths
27528
28477
  });
27529
28478
  if (encodedAttrs && Object.keys(encodedAttrs).length) {
27530
28479
  schemaNode.attrs = { ...schemaNode.attrs, ...encodedAttrs };
27531
28480
  }
27532
28481
  return schemaNode;
27533
28482
  }
27534
- function decode$o(params2, decodedAttrs) {
28483
+ function decode$l(params2, decodedAttrs) {
27535
28484
  const translated = translateTableCell(params2);
27536
28485
  if (decodedAttrs && Object.keys(decodedAttrs).length) {
27537
28486
  translated.attributes = { ...translated.attributes || {}, ...decodedAttrs };
27538
28487
  }
27539
28488
  return translated;
27540
28489
  }
27541
- const config$f = {
27542
- xmlName: XML_NODE_NAME$g,
27543
- sdNodeOrKeyName: SD_NODE_NAME$d,
28490
+ const config$c = {
28491
+ xmlName: XML_NODE_NAME$d,
28492
+ sdNodeOrKeyName: SD_NODE_NAME$b,
27544
28493
  type: NodeTranslator.translatorTypes.NODE,
27545
- encode: encode$m,
27546
- decode: decode$o,
27547
- attributes: validXmlAttributes$b
28494
+ encode: encode$j,
28495
+ decode: decode$l,
28496
+ attributes: validXmlAttributes$a
27548
28497
  };
27549
- const translator$H = NodeTranslator.from(config$f);
27550
- const translator$G = NodeTranslator.from({
27551
- xmlName: "w:cantSplit",
27552
- sdNodeOrKeyName: "cantSplit",
27553
- encode: ({ nodes }) => ["1", "true"].includes(nodes[0].attributes?.["w:val"] ?? "1"),
27554
- decode: ({ node }) => node.attrs?.cantSplit ? { attributes: {} } : void 0
27555
- });
27556
- const translator$F = NodeTranslator.from(createSingleAttrPropertyHandler("w:divId"));
27557
- const translator$E = NodeTranslator.from(
27558
- createSingleAttrPropertyHandler(
27559
- "w:gridAfter",
27560
- null,
27561
- "w:val",
27562
- (v2) => parseInteger(v2) ?? void 0,
27563
- (v2) => integerToString(v2)
27564
- )
27565
- );
27566
- const translator$D = NodeTranslator.from(
27567
- createSingleAttrPropertyHandler(
27568
- "w:gridBefore",
27569
- null,
27570
- "w:val",
27571
- (v2) => parseInteger(v2) ?? void 0,
27572
- (v2) => integerToString(v2)
27573
- )
27574
- );
27575
- const translator$C = NodeTranslator.from({
27576
- xmlName: "w:hidden",
27577
- sdNodeOrKeyName: "hidden",
27578
- encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
27579
- decode: ({ node }) => node.attrs.hidden ? { attributes: {} } : void 0
27580
- });
27581
- const translator$B = NodeTranslator.from(createSingleAttrPropertyHandler("w:jc", "justification"));
27582
- const translator$A = NodeTranslator.from(createMeasurementPropertyHandler("w:tblCellSpacing", "tableCellSpacing"));
27583
- const translator$z = NodeTranslator.from({
27584
- xmlName: "w:tblHeader",
27585
- sdNodeOrKeyName: "repeatHeader",
27586
- encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
27587
- decode: ({ node }) => node.attrs.repeatHeader ? { attributes: {} } : void 0
27588
- });
27589
- const translator$y = NodeTranslator.from({
27590
- xmlName: "w:trHeight",
27591
- sdNodeOrKeyName: "rowHeight",
27592
- encode: ({ nodes }) => {
27593
- const heightAttrs = {};
27594
- const val = nodes[0].attributes["w:val"];
27595
- if (val) {
27596
- heightAttrs["value"] = parseInt(val, 10);
27597
- }
27598
- const rule = nodes[0].attributes["w:hRule"];
27599
- if (rule) {
27600
- heightAttrs["rule"] = rule;
27601
- }
27602
- return Object.keys(heightAttrs).length > 0 ? heightAttrs : void 0;
27603
- },
27604
- decode: ({ node }) => {
27605
- if (!node.attrs?.rowHeight) return;
27606
- const heightAttrs = {};
27607
- if (typeof node.attrs.rowHeight.value === "number" && !isNaN(node.attrs.rowHeight.value)) {
27608
- heightAttrs["w:val"] = String(node.attrs.rowHeight.value);
27609
- }
27610
- if (node.attrs.rowHeight.rule) {
27611
- heightAttrs["w:hRule"] = node.attrs.rowHeight.rule;
27612
- }
27613
- return Object.keys(heightAttrs).length > 0 ? { attributes: heightAttrs } : void 0;
27614
- }
27615
- });
27616
- const translator$x = NodeTranslator.from(createMeasurementPropertyHandler("w:wAfter"));
27617
- const translator$w = NodeTranslator.from(createMeasurementPropertyHandler("w:wBefore"));
27618
- const propertyTranslators$3 = [
27619
- translator$G,
27620
- translator$1a,
27621
- translator$F,
27622
- translator$E,
27623
- translator$D,
27624
- translator$C,
27625
- translator$B,
27626
- translator$A,
27627
- translator$z,
27628
- translator$y,
27629
- translator$x,
27630
- translator$w
27631
- ];
27632
- const translator$v = NodeTranslator.from(
27633
- createNestedPropertiesTranslator("w:trPr", "tableRowProperties", propertyTranslators$3, {
27634
- cantSplit: false,
27635
- hidden: false,
27636
- repeatHeader: false
27637
- })
27638
- );
27639
- const createPlaceholderCell = (gridWidth, reason) => {
27640
- const safeWidth = Number.isFinite(gridWidth) ? gridWidth : 0;
27641
- const noBorder = { val: "none", size: 0 };
27642
- return {
27643
- type: "tableCell",
27644
- attrs: {
27645
- colspan: 1,
27646
- rowspan: 1,
27647
- colwidth: [safeWidth],
27648
- __placeholder: reason,
27649
- borders: {
27650
- top: { ...noBorder },
27651
- right: { ...noBorder },
27652
- bottom: { ...noBorder },
27653
- left: { ...noBorder }
27654
- }
27655
- },
27656
- content: [{ type: "paragraph", content: [] }]
27657
- };
27658
- };
27659
- const advancePastRowSpans = (pendingRowSpans, startIndex, totalColumns) => {
27660
- let index2 = startIndex;
27661
- while (index2 < totalColumns && pendingRowSpans[index2] > 0) {
27662
- pendingRowSpans[index2] -= 1;
27663
- index2 += 1;
27664
- }
27665
- return index2;
27666
- };
27667
- const fillPlaceholderColumns = ({
27668
- content,
27669
- pendingRowSpans,
27670
- currentIndex,
27671
- targetIndex,
27672
- totalColumns,
27673
- gridColumnWidths,
27674
- reason
27675
- }) => {
27676
- let index2 = currentIndex;
27677
- while (index2 < targetIndex && index2 < totalColumns) {
27678
- if (pendingRowSpans[index2] > 0) {
27679
- pendingRowSpans[index2] -= 1;
27680
- index2 += 1;
27681
- continue;
27682
- }
27683
- const width = Array.isArray(gridColumnWidths) ? gridColumnWidths[index2] ?? 0 : 0;
27684
- content.push(createPlaceholderCell(width, reason));
27685
- index2 += 1;
27686
- }
27687
- return index2;
27688
- };
27689
- const isPlaceholderCell = (cell) => {
27690
- if (!cell) return false;
27691
- if (cell.attrs?.__placeholder) return true;
27692
- const widths = cell.attrs?.colwidth;
27693
- if (Array.isArray(widths) && widths.length > 0) {
27694
- const hasMeaningfulWidth = widths.some(
27695
- (value) => typeof value === "number" && Number.isFinite(value) && Math.abs(value) > 1
27696
- );
27697
- if (!hasMeaningfulWidth) return true;
27698
- }
27699
- return false;
27700
- };
27701
- const XML_NODE_NAME$f = "w:tr";
27702
- const SD_NODE_NAME$c = "tableRow";
27703
- const validXmlAttributes$a = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
27704
- (xmlName) => createAttributeHandler(xmlName)
27705
- );
27706
- const encode$l = (params2, encodedAttrs) => {
27707
- const { row } = params2.extraParams;
27708
- let tableRowProperties = {};
27709
- const tPr = row.elements.find((el) => el.name === "w:trPr");
27710
- if (tPr) {
27711
- tableRowProperties = translator$v.encode({
27712
- ...params2,
27713
- nodes: [tPr]
27714
- });
27715
- }
27716
- const gridBeforeRaw = tableRowProperties?.["gridBefore"];
27717
- const safeGridBefore = typeof gridBeforeRaw === "number" && Number.isFinite(gridBeforeRaw) && gridBeforeRaw > 0 ? gridBeforeRaw : 0;
27718
- encodedAttrs["tableRowProperties"] = Object.freeze(tableRowProperties);
27719
- encodedAttrs["rowHeight"] = twipsToPixels(tableRowProperties["rowHeight"]?.value);
27720
- encodedAttrs["cantSplit"] = tableRowProperties["cantSplit"];
27721
- const { columnWidths: gridColumnWidths, activeRowSpans = [] } = params2.extraParams;
27722
- const totalColumns = Array.isArray(gridColumnWidths) ? gridColumnWidths.length : 0;
27723
- const pendingRowSpans = Array.isArray(activeRowSpans) ? activeRowSpans.slice() : [];
27724
- while (pendingRowSpans.length < totalColumns) pendingRowSpans.push(0);
27725
- const cellNodes = row.elements.filter((el) => el.name === "w:tc");
27726
- const content = [];
27727
- let currentColumnIndex = 0;
27728
- const fillUntil = (target, reason) => {
27729
- currentColumnIndex = fillPlaceholderColumns({
27730
- content,
27731
- pendingRowSpans,
27732
- currentIndex: currentColumnIndex,
27733
- targetIndex: target,
27734
- totalColumns,
27735
- gridColumnWidths,
27736
- reason
27737
- });
27738
- };
27739
- const skipOccupiedColumns = () => {
27740
- currentColumnIndex = advancePastRowSpans(pendingRowSpans, currentColumnIndex, totalColumns);
27741
- };
27742
- fillUntil(safeGridBefore, "gridBefore");
27743
- skipOccupiedColumns();
27744
- cellNodes?.forEach((node) => {
27745
- skipOccupiedColumns();
27746
- const startColumn = currentColumnIndex;
27747
- const columnWidth = gridColumnWidths?.[startColumn] || null;
27748
- const result = translator$H.encode({
27749
- ...params2,
27750
- extraParams: {
27751
- ...params2.extraParams,
27752
- node,
27753
- columnIndex: startColumn,
27754
- columnWidth
27755
- }
27756
- });
27757
- if (result) {
27758
- content.push(result);
27759
- const colspan = Math.max(1, result.attrs?.colspan || 1);
27760
- const rowspan = Math.max(1, result.attrs?.rowspan || 1);
27761
- if (rowspan > 1) {
27762
- for (let offset2 = 0; offset2 < colspan; offset2 += 1) {
27763
- const target = startColumn + offset2;
27764
- if (target < pendingRowSpans.length) {
27765
- pendingRowSpans[target] = Math.max(pendingRowSpans[target], rowspan - 1);
27766
- }
27767
- }
27768
- }
27769
- currentColumnIndex = startColumn + colspan;
27770
- }
27771
- });
27772
- skipOccupiedColumns();
27773
- fillUntil(totalColumns, "gridAfter");
27774
- const newNode = {
27775
- type: "tableRow",
27776
- content,
27777
- attrs: encodedAttrs
27778
- };
27779
- return newNode;
27780
- };
27781
- const decode$n = (params2, decodedAttrs) => {
27782
- const { node } = params2;
27783
- const cells = node.content || [];
27784
- let leadingPlaceholders = 0;
27785
- while (leadingPlaceholders < cells.length && isPlaceholderCell(cells[leadingPlaceholders])) {
27786
- leadingPlaceholders += 1;
27787
- }
27788
- let trailingPlaceholders = 0;
27789
- while (trailingPlaceholders < cells.length - leadingPlaceholders && isPlaceholderCell(cells[cells.length - 1 - trailingPlaceholders])) {
27790
- trailingPlaceholders += 1;
27791
- }
27792
- const trimmedSlice = cells.slice(leadingPlaceholders, cells.length - trailingPlaceholders);
27793
- const sanitizedCells = trimmedSlice.map((cell) => {
27794
- if (cell?.attrs && "__placeholder" in cell.attrs) {
27795
- const { __placeholder, ...rest } = cell.attrs;
27796
- return { ...cell, attrs: rest };
27797
- }
27798
- return cell;
27799
- });
27800
- const trimmedContent = sanitizedCells.filter((_2, index2) => !isPlaceholderCell(trimmedSlice[index2]));
27801
- const translateParams = {
27802
- ...params2,
27803
- node: { ...node, content: trimmedContent }
27804
- };
27805
- const elements = translateChildNodes(translateParams);
27806
- if (node.attrs?.tableRowProperties) {
27807
- const tableRowProperties = { ...node.attrs.tableRowProperties };
27808
- if (leadingPlaceholders > 0) {
27809
- tableRowProperties.gridBefore = leadingPlaceholders;
27810
- }
27811
- if (trailingPlaceholders > 0) {
27812
- tableRowProperties.gridAfter = trailingPlaceholders;
27813
- }
27814
- if (node.attrs.rowHeight != null) {
27815
- const rowHeightPixels = twipsToPixels(node.attrs.tableRowProperties["rowHeight"]?.value);
27816
- if (rowHeightPixels !== node.attrs.rowHeight) {
27817
- tableRowProperties["rowHeight"] = { value: String(pixelsToTwips(node.attrs["rowHeight"])) };
27818
- }
27819
- }
27820
- tableRowProperties["cantSplit"] = node.attrs["cantSplit"];
27821
- const trPr = translator$v.decode({
27822
- ...params2,
27823
- node: { ...node, attrs: { ...node.attrs, tableRowProperties } }
27824
- });
27825
- if (trPr) elements.unshift(trPr);
27826
- }
27827
- return {
27828
- name: "w:tr",
27829
- attributes: decodedAttrs || {},
27830
- elements
27831
- };
27832
- };
27833
- const config$e = {
27834
- xmlName: XML_NODE_NAME$f,
27835
- sdNodeOrKeyName: SD_NODE_NAME$c,
27836
- type: NodeTranslator.translatorTypes.NODE,
27837
- encode: encode$l,
27838
- decode: decode$n,
27839
- attributes: validXmlAttributes$a
27840
- };
27841
- const translator$u = NodeTranslator.from(config$e);
27842
- function parseTagValueJSON(json) {
27843
- if (typeof json !== "string") {
27844
- return {};
28498
+ const translator$c = NodeTranslator.from(config$c);
28499
+ function parseTagValueJSON(json) {
28500
+ if (typeof json !== "string") {
28501
+ return {};
27845
28502
  }
27846
28503
  const trimmed = json.trim();
27847
28504
  if (!trimmed) {
@@ -29161,32 +29818,32 @@ function translateAnchorNode(params2) {
29161
29818
  elements: [...anchorElements, ...elementsWithWrap]
29162
29819
  };
29163
29820
  }
29164
- const XML_NODE_NAME$e = "wp:anchor";
29165
- const SD_NODE_NAME$b = ["image"];
29821
+ const XML_NODE_NAME$c = "wp:anchor";
29822
+ const SD_NODE_NAME$a = ["image"];
29166
29823
  const validXmlAttributes$9 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
29167
- function encode$k(params2) {
29824
+ function encode$i(params2) {
29168
29825
  const { node } = params2.extraParams;
29169
29826
  if (!node || !node.type) {
29170
29827
  return null;
29171
29828
  }
29172
29829
  return handleAnchorNode(params2);
29173
29830
  }
29174
- function decode$m(params2) {
29831
+ function decode$k(params2) {
29175
29832
  const { node } = params2;
29176
29833
  if (!node || !node.type) {
29177
29834
  return null;
29178
29835
  }
29179
29836
  return translateAnchorNode(params2);
29180
29837
  }
29181
- const config$d = {
29182
- xmlName: XML_NODE_NAME$e,
29183
- sdNodeOrKeyName: SD_NODE_NAME$b,
29838
+ const config$b = {
29839
+ xmlName: XML_NODE_NAME$c,
29840
+ sdNodeOrKeyName: SD_NODE_NAME$a,
29184
29841
  type: NodeTranslator.translatorTypes.NODE,
29185
- encode: encode$k,
29186
- decode: decode$m,
29842
+ encode: encode$i,
29843
+ decode: decode$k,
29187
29844
  attributes: validXmlAttributes$9
29188
29845
  };
29189
- const translator$t = NodeTranslator.from(config$d);
29846
+ const translator$b = NodeTranslator.from(config$b);
29190
29847
  function handleInlineNode(params2) {
29191
29848
  const { node } = params2.extraParams;
29192
29849
  if (node.name !== "wp:inline") {
@@ -29202,41 +29859,41 @@ function translateInlineNode(params2) {
29202
29859
  elements: nodeElements.elements
29203
29860
  };
29204
29861
  }
29205
- const XML_NODE_NAME$d = "wp:inline";
29206
- const SD_NODE_NAME$a = ["image"];
29862
+ const XML_NODE_NAME$b = "wp:inline";
29863
+ const SD_NODE_NAME$9 = ["image"];
29207
29864
  const validXmlAttributes$8 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
29208
- function encode$j(params2) {
29865
+ function encode$h(params2) {
29209
29866
  const { node } = params2.extraParams;
29210
29867
  if (!node || !node.type) {
29211
29868
  return null;
29212
29869
  }
29213
29870
  return handleInlineNode(params2);
29214
29871
  }
29215
- function decode$l(params2) {
29872
+ function decode$j(params2) {
29216
29873
  const { node } = params2;
29217
29874
  if (!node || !node.type) {
29218
29875
  return null;
29219
29876
  }
29220
29877
  return translateInlineNode(params2);
29221
29878
  }
29222
- const config$c = {
29223
- xmlName: XML_NODE_NAME$d,
29224
- sdNodeOrKeyName: SD_NODE_NAME$a,
29879
+ const config$a = {
29880
+ xmlName: XML_NODE_NAME$b,
29881
+ sdNodeOrKeyName: SD_NODE_NAME$9,
29225
29882
  type: NodeTranslator.translatorTypes.NODE,
29226
- encode: encode$j,
29227
- decode: decode$l,
29883
+ encode: encode$h,
29884
+ decode: decode$j,
29228
29885
  attributes: validXmlAttributes$8
29229
29886
  };
29230
- const translator$s = NodeTranslator.from(config$c);
29231
- const XML_NODE_NAME$c = "w:drawing";
29232
- const SD_NODE_NAME$9 = [];
29887
+ const translator$a = NodeTranslator.from(config$a);
29888
+ const XML_NODE_NAME$a = "w:drawing";
29889
+ const SD_NODE_NAME$8 = [];
29233
29890
  const validXmlAttributes$7 = [];
29234
- function encode$i(params2) {
29891
+ function encode$g(params2) {
29235
29892
  const nodes = params2.nodes;
29236
29893
  const node = nodes[0];
29237
29894
  const translatorByChildName = {
29238
- "wp:anchor": translator$t,
29239
- "wp:inline": translator$s
29895
+ "wp:anchor": translator$b,
29896
+ "wp:inline": translator$a
29240
29897
  };
29241
29898
  return node.elements.reduce((acc, child) => {
29242
29899
  if (acc) return acc;
@@ -29245,12 +29902,12 @@ function encode$i(params2) {
29245
29902
  return translator2.encode({ ...params2, extraParams: { node: child } }) || acc;
29246
29903
  }, null);
29247
29904
  }
29248
- function decode$k(params2) {
29905
+ function decode$i(params2) {
29249
29906
  const { node } = params2;
29250
29907
  if (!node || !node.type) {
29251
29908
  return null;
29252
29909
  }
29253
- const childTranslator = node.attrs.isAnchor ? translator$t : translator$s;
29910
+ const childTranslator = node.attrs.isAnchor ? translator$b : translator$a;
29254
29911
  const resultNode = childTranslator.decode(params2);
29255
29912
  return wrapTextInRun(
29256
29913
  {
@@ -29260,15 +29917,15 @@ function decode$k(params2) {
29260
29917
  []
29261
29918
  );
29262
29919
  }
29263
- const config$b = {
29264
- xmlName: XML_NODE_NAME$c,
29265
- sdNodeOrKeyName: SD_NODE_NAME$9,
29920
+ const config$9 = {
29921
+ xmlName: XML_NODE_NAME$a,
29922
+ sdNodeOrKeyName: SD_NODE_NAME$8,
29266
29923
  type: NodeTranslator.translatorTypes.NODE,
29267
- encode: encode$i,
29268
- decode: decode$k,
29924
+ encode: encode$g,
29925
+ decode: decode$i,
29269
29926
  attributes: validXmlAttributes$7
29270
29927
  };
29271
- const translator$r = NodeTranslator.from(config$b);
29928
+ const translator$9 = NodeTranslator.from(config$9);
29272
29929
  class CommandService {
29273
29930
  /**
29274
29931
  * @param {import('./commands/types/index.js').CommandServiceOptions} props
@@ -30616,928 +31273,351 @@ function prepareTextAnnotation(params2) {
30616
31273
  return getTextNodeForExport(attrs.displayLabel, [...marks, ...marksFromAttrs], params2);
30617
31274
  }
30618
31275
  function prepareImageAnnotation(params2, imageSize) {
30619
- return translator$r.decode({
30620
- ...params2,
30621
- imageSize
30622
- });
30623
- }
30624
- function prepareCheckboxAnnotation(params2) {
30625
- const {
30626
- node: { attrs = {}, marks = [] }
30627
- } = params2;
30628
- const content = he.decode(attrs.displayLabel);
30629
- return getTextNodeForExport(content, marks, params2);
30630
- }
30631
- function prepareHtmlAnnotation(params2) {
30632
- const {
30633
- node: { attrs = {}, marks = [] },
30634
- editorSchema
30635
- } = params2;
30636
- let html = attrs.rawHtml || attrs.displayLabel;
30637
- const paragraphHtmlContainer = sanitizeHtml(html);
30638
- const marksFromAttrs = translateFieldAttrsToMarks(attrs);
30639
- const allMarks = [...marks, ...marksFromAttrs];
30640
- let state2 = EditorState.create({
30641
- doc: DOMParser$1.fromSchema(editorSchema).parse(paragraphHtmlContainer)
30642
- });
30643
- if (allMarks.length) {
30644
- state2 = applyMarksToHtmlAnnotation(state2, allMarks);
30645
- }
30646
- const htmlAnnotationNode = state2.doc.toJSON();
30647
- const listTypes = ["bulletList", "orderedList"];
30648
- const { editor } = params2;
30649
- const seenLists = /* @__PURE__ */ new Map();
30650
- state2.doc.descendants((node) => {
30651
- if (listTypes.includes(node.type.name)) {
30652
- const listItem = node.firstChild;
30653
- const { attrs: attrs2 } = listItem;
30654
- const { level, numId } = attrs2;
30655
- if (!seenLists.has(numId)) {
30656
- const newNumId = ListHelpers.changeNumIdSameAbstract(numId, level, node.type.name, editor);
30657
- listItem.attrs.numId = newNumId;
30658
- seenLists.set(numId, newNumId);
30659
- } else {
30660
- const newNumId = seenLists.get(numId);
30661
- listItem.attrs.numId = newNumId;
30662
- }
30663
- }
30664
- });
30665
- const elements = translateChildNodes({
30666
- ...params2,
30667
- node: htmlAnnotationNode
30668
- });
30669
- return {
30670
- name: "htmlAnnotation",
30671
- elements
30672
- };
30673
- }
30674
- function prepareUrlAnnotation(params2) {
30675
- const {
30676
- node: { attrs = {}, marks = [] }
30677
- } = params2;
30678
- if (!attrs.linkUrl) return prepareTextAnnotation(params2);
30679
- const newId = addNewLinkRelationship(params2, attrs.linkUrl);
30680
- const linkTextNode = getTextNodeForExport(attrs.linkUrl, marks, params2);
30681
- const contentNode = processLinkContentNode(linkTextNode);
30682
- return {
30683
- name: "w:hyperlink",
30684
- type: "element",
30685
- attributes: {
30686
- "r:id": newId,
30687
- "w:history": 1
30688
- },
30689
- elements: [contentNode]
30690
- };
30691
- }
30692
- function translateFieldAttrsToMarks(attrs = {}) {
30693
- const { fontFamily: fontFamily2, fontSize: fontSize2, bold, underline, italic, textColor, textHighlight } = attrs;
30694
- const marks = [];
30695
- if (fontFamily2) marks.push({ type: "fontFamily", attrs: { fontFamily: fontFamily2 } });
30696
- if (fontSize2) marks.push({ type: "fontSize", attrs: { fontSize: fontSize2 } });
30697
- if (bold) marks.push({ type: "bold", attrs: {} });
30698
- if (underline) marks.push({ type: "underline", attrs: {} });
30699
- if (italic) marks.push({ type: "italic", attrs: {} });
30700
- if (textColor) marks.push({ type: "color", attrs: { color: textColor } });
30701
- if (textHighlight) marks.push({ type: "highlight", attrs: { color: textHighlight } });
30702
- return marks;
30703
- }
30704
- function applyMarksToHtmlAnnotation(state2, marks) {
30705
- const { tr, doc: doc2, schema } = state2;
30706
- const allowedMarks = ["fontFamily", "fontSize", "highlight"];
30707
- if (!marks.some((m2) => allowedMarks.includes(m2.type))) {
30708
- return state2;
30709
- }
30710
- const fontFamily2 = marks.find((m2) => m2.type === "fontFamily");
30711
- const fontSize2 = marks.find((m2) => m2.type === "fontSize");
30712
- const highlight = marks.find((m2) => m2.type === "highlight");
30713
- const textStyleType = schema.marks.textStyle;
30714
- const highlightType = schema.marks.highlight;
30715
- doc2.descendants((node, pos) => {
30716
- if (!node.isText) return;
30717
- const foundTextStyle = node.marks.find((m2) => m2.type.name === "textStyle");
30718
- const foundHighlight = node.marks.find((m2) => m2.type.name === "highlight");
30719
- if (!foundTextStyle) {
30720
- tr.addMark(
30721
- pos,
30722
- pos + node.nodeSize,
30723
- textStyleType.create({
30724
- ...fontFamily2?.attrs,
30725
- ...fontSize2?.attrs
30726
- })
30727
- );
30728
- } else if (!foundTextStyle?.attrs.fontFamily && fontFamily2) {
30729
- tr.addMark(
30730
- pos,
30731
- pos + node.nodeSize,
30732
- textStyleType.create({
30733
- ...foundTextStyle?.attrs,
30734
- ...fontFamily2.attrs
30735
- })
30736
- );
30737
- } else if (!foundTextStyle?.attrs.fontSize && fontSize2) {
30738
- tr.addMark(
30739
- pos,
30740
- pos + node.nodeSize,
30741
- textStyleType.create({
30742
- ...foundTextStyle?.attrs,
30743
- ...fontSize2.attrs
30744
- })
30745
- );
30746
- }
30747
- if (!foundHighlight) {
30748
- tr.addMark(
30749
- pos,
30750
- pos + node.nodeSize,
30751
- highlightType.create({
30752
- ...highlight?.attrs
30753
- })
30754
- );
30755
- }
30756
- });
30757
- return state2.apply(tr);
30758
- }
30759
- function getFieldHighlightJson(fieldsHighlightColor) {
30760
- if (!fieldsHighlightColor) return null;
30761
- let parsedColor = fieldsHighlightColor.trim();
30762
- const hexRegex2 = /^#?([A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/;
30763
- if (!hexRegex2.test(parsedColor)) {
30764
- console.warn(`Invalid HEX color provided to fieldsHighlightColor export param: ${fieldsHighlightColor}`);
30765
- return null;
30766
- }
30767
- if (parsedColor.startsWith("#")) {
30768
- parsedColor = parsedColor.slice(1);
30769
- }
30770
- return {
30771
- name: "w:rPr",
30772
- elements: [
30773
- {
30774
- name: "w:shd",
30775
- attributes: {
30776
- "w:fill": `#${parsedColor}`,
30777
- "w:color": "auto",
30778
- "w:val": "clear"
30779
- }
30780
- }
30781
- ]
30782
- };
30783
- }
30784
- function translateDocumentSection(params2) {
30785
- const { node } = params2;
30786
- const { attrs = {} } = node;
30787
- const childContent = translateChildNodes({ ...params2, nodes: node.content });
30788
- const nodeElements = [
30789
- {
30790
- name: "w:sdtContent",
30791
- elements: childContent
30792
- }
30793
- ];
30794
- const exportedTag = JSON.stringify({
30795
- type: "documentSection",
30796
- description: attrs.description
30797
- });
30798
- const sdtPr = generateSdtPrTagForDocumentSection(attrs.id, attrs.title, exportedTag);
30799
- const { isLocked } = attrs;
30800
- if (isLocked) {
30801
- sdtPr.elements.push({
30802
- name: "w:lock",
30803
- attributes: {
30804
- "w:val": "sdtContentLocked"
30805
- }
30806
- });
30807
- }
30808
- nodeElements.unshift(sdtPr);
30809
- const result = {
30810
- name: "w:sdt",
30811
- elements: nodeElements
30812
- };
30813
- return result;
30814
- }
30815
- const generateSdtPrTagForDocumentSection = (id, title, tag) => {
30816
- return {
30817
- name: "w:sdtPr",
30818
- elements: [
30819
- {
30820
- name: "w:id",
30821
- attributes: {
30822
- "w:val": id
30823
- }
30824
- },
30825
- {
30826
- name: "w:alias",
30827
- attributes: {
30828
- "w:val": title
30829
- }
30830
- },
30831
- {
30832
- name: "w:tag",
30833
- attributes: {
30834
- "w:val": tag
30835
- }
30836
- }
30837
- ]
30838
- };
30839
- };
30840
- function translateDocumentPartObj(params2) {
30841
- const { node } = params2;
30842
- const { attrs = {} } = node;
30843
- const childContent = translateChildNodes({ ...params2, nodes: node.content });
30844
- const nodeElements = [
30845
- {
30846
- name: "w:sdtPr",
30847
- elements: [
30848
- {
30849
- name: "w:id",
30850
- attributes: {
30851
- "w:val": attrs.id
30852
- }
30853
- },
30854
- {
30855
- name: "w:docPartObj",
30856
- elements: [
30857
- {
30858
- name: "w:docPartGallery",
30859
- attributes: {
30860
- "w:val": attrs.docPartGallery
30861
- }
30862
- },
30863
- ...attrs.docPartUnique ? [
30864
- {
30865
- name: "w:docPartUnique"
30866
- }
30867
- ] : []
30868
- ]
30869
- }
30870
- ]
30871
- },
30872
- {
30873
- name: "w:sdtContent",
30874
- elements: childContent
30875
- }
30876
- ];
30877
- const result = {
30878
- name: "w:sdt",
30879
- elements: nodeElements
30880
- };
30881
- return result;
30882
- }
30883
- function translateStructuredContent(params2) {
30884
- const { node } = params2;
30885
- const childContent = translateChildNodes({ ...params2, nodes: node.content });
30886
- const sdtContent = { name: "w:sdtContent", elements: childContent };
30887
- const sdtPr = generateSdtPrTagForStructuredContent({ node });
30888
- const nodeElements = [sdtPr, sdtContent];
30889
- const result = {
30890
- name: "w:sdt",
30891
- elements: nodeElements
30892
- };
30893
- return result;
30894
- }
30895
- function generateSdtPrTagForStructuredContent({ node }) {
30896
- const { attrs = {} } = node;
30897
- const id = {
30898
- name: "w:id",
30899
- type: "element",
30900
- attributes: { "w:val": attrs.id }
30901
- };
30902
- const alias = {
30903
- name: "w:alias",
30904
- type: "element",
30905
- attributes: { "w:val": attrs.alias }
30906
- };
30907
- const tag = {
30908
- name: "w:tag",
30909
- type: "element",
30910
- attributes: { "w:val": attrs.tag }
30911
- };
30912
- const resultElements = [];
30913
- if (attrs.id) resultElements.push(id);
30914
- if (attrs.alias) resultElements.push(alias);
30915
- if (attrs.tag) resultElements.push(tag);
30916
- if (attrs.sdtPr) {
30917
- const elements = attrs.sdtPr.elements || [];
30918
- const elementsToExclude = ["w:id", "w:alias", "w:tag"];
30919
- const restElements = elements.filter((el) => !elementsToExclude.includes(el.name));
30920
- const result2 = {
30921
- name: "w:sdtPr",
30922
- type: "element",
30923
- elements: [...resultElements, ...restElements]
30924
- };
30925
- return result2;
30926
- }
30927
- const result = {
30928
- name: "w:sdtPr",
30929
- type: "element",
30930
- elements: resultElements
30931
- };
30932
- return result;
30933
- }
30934
- const XML_NODE_NAME$b = "w:sdt";
30935
- const SD_NODE_NAME$8 = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
30936
- const validXmlAttributes$6 = [];
30937
- function encode$h(params2) {
30938
- const nodes = params2.nodes;
30939
- const node = nodes[0];
30940
- const { type: sdtType, handler: handler2 } = sdtNodeTypeStrategy(node);
30941
- if (!handler2 || sdtType === "unknown") {
30942
- return void 0;
30943
- }
30944
- const result = handler2(params2);
30945
- return result;
30946
- }
30947
- function decode$j(params2) {
30948
- const { node } = params2;
30949
- if (!node || !node.type) {
30950
- return null;
30951
- }
30952
- const types2 = {
30953
- fieldAnnotation: () => translateFieldAnnotation(params2),
30954
- structuredContent: () => translateStructuredContent(params2),
30955
- structuredContentBlock: () => translateStructuredContent(params2),
30956
- documentSection: () => translateDocumentSection(params2),
30957
- documentPartObject: () => translateDocumentPartObj(params2),
30958
- // Handled in doc-part-obj translator
30959
- default: () => null
30960
- };
30961
- const decoder = types2[node.type] ?? types2.default;
30962
- const result = decoder();
30963
- return result;
30964
- }
30965
- const config$a = {
30966
- xmlName: XML_NODE_NAME$b,
30967
- sdNodeOrKeyName: SD_NODE_NAME$8,
30968
- type: NodeTranslator.translatorTypes.NODE,
30969
- encode: encode$h,
30970
- decode: decode$j,
30971
- attributes: validXmlAttributes$6
30972
- };
30973
- const translator$q = NodeTranslator.from(config$a);
30974
- function preProcessVerticalMergeCells(table, { editorSchema }) {
30975
- if (!table || !Array.isArray(table.content)) {
30976
- return table;
30977
- }
30978
- const rows = table.content;
30979
- for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
30980
- const row = rows[rowIndex];
30981
- if (!row) continue;
30982
- if (!Array.isArray(row.content)) {
30983
- row.content = [];
30984
- }
30985
- for (let cellIndex = 0; cellIndex < row.content.length; cellIndex++) {
30986
- const cell = row.content[cellIndex];
30987
- if (!cell) continue;
30988
- const attrs = cell.attrs || {};
30989
- if (!attrs.rowspan || attrs.rowspan <= 1) continue;
30990
- const maxRowspan = Math.min(attrs.rowspan, rows.length - rowIndex);
30991
- for (let offset2 = 1; offset2 < maxRowspan; offset2++) {
30992
- const rowToChange = rows[rowIndex + offset2];
30993
- if (!rowToChange) continue;
30994
- if (!Array.isArray(rowToChange.content)) {
30995
- rowToChange.content = [];
30996
- }
30997
- const existingCell = rowToChange.content[cellIndex];
30998
- if (existingCell?.attrs?.continueMerge) continue;
30999
- const mergedCell = {
31000
- type: cell.type,
31001
- content: [editorSchema.nodes.paragraph.createAndFill().toJSON()],
31002
- attrs: {
31003
- ...cell.attrs,
31004
- rowspan: null,
31005
- continueMerge: true
31006
- }
31007
- };
31008
- rowToChange.content.splice(cellIndex, 0, mergedCell);
31009
- }
31010
- }
31011
- }
31012
- return table;
31013
- }
31014
- const translator$p = NodeTranslator.from({
31015
- xmlName: "w:bidiVisual",
31016
- sdNodeOrKeyName: "rightToLeft",
31017
- encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
31018
- decode: ({ node }) => node.attrs.rightToLeft ? { attributes: {} } : void 0
31019
- });
31020
- const translator$o = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblCaption", "caption"));
31021
- const translator$n = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblDescription", "description"));
31022
- const translator$m = NodeTranslator.from(createMeasurementPropertyHandler("w:tblInd", "tableIndent"));
31023
- const translator$l = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblLayout", "tableLayout", "w:type"));
31024
- const translator$k = NodeTranslator.from({
31025
- xmlName: "w:tblLook",
31026
- sdNodeOrKeyName: "tblLook",
31027
- attributes: ["w:firstColumn", "w:firstRow", "w:lastColumn", "w:lastRow", "w:noHBand", "w:noVBand"].map((attr) => createAttributeHandler(attr, null, parseBoolean, booleanToString)).concat([createAttributeHandler("w:val")]),
31028
- encode: (params2, encodedAttrs) => {
31029
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
31030
- },
31031
- decode: function({ node }, context) {
31032
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.tblLook || {} } });
31033
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
31034
- }
31035
- });
31036
- const translator$j = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblOverlap", "overlap"));
31037
- const translator$i = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblStyle", "tableStyleId"));
31038
- const translator$h = NodeTranslator.from(
31039
- createSingleAttrPropertyHandler("w:tblStyleColBandSize", "tableStyleColBandSize")
31040
- );
31041
- const translator$g = NodeTranslator.from(
31042
- createSingleAttrPropertyHandler("w:tblStyleRowBandSize", "tableStyleRowBandSize")
31043
- );
31044
- const translator$f = NodeTranslator.from(createMeasurementPropertyHandler("w:tblW", "tableWidth"));
31045
- const translator$e = NodeTranslator.from({
31046
- xmlName: "w:tblpPr",
31047
- sdNodeOrKeyName: "floatingTableProperties",
31048
- 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))),
31049
- encode: (params2, encodedAttrs) => {
31050
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
31051
- },
31052
- decode: function({ node }, context) {
31053
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.floatingTableProperties || {} } });
31054
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
31055
- }
31056
- });
31057
- const propertyTranslators$2 = [
31058
- translator$15,
31059
- translator$13,
31060
- translator$11,
31061
- translator$10,
31062
- translator$$,
31063
- translator$Z,
31064
- translator$X,
31065
- translator$V
31066
- ];
31067
- const translator$d = NodeTranslator.from(
31068
- createNestedPropertiesTranslator("w:tblBorders", "borders", propertyTranslators$2)
31069
- );
31070
- const propertyTranslators$1 = [
31071
- translator$14,
31072
- translator$12,
31073
- translator$_,
31074
- translator$Y,
31075
- translator$W,
31076
- translator$U
31077
- ];
31078
- const translator$c = NodeTranslator.from(
31079
- createNestedPropertiesTranslator("w:tblCellMar", "cellMargins", propertyTranslators$1)
31080
- );
31081
- const propertyTranslators = [
31082
- translator$p,
31083
- translator$B,
31084
- translator$19,
31085
- translator$o,
31086
- translator$A,
31087
- translator$n,
31088
- translator$m,
31089
- translator$l,
31090
- translator$k,
31091
- translator$j,
31092
- translator$i,
31093
- translator$h,
31094
- translator$g,
31095
- translator$f,
31096
- translator$e,
31097
- translator$d,
31098
- translator$c
31099
- ];
31100
- const translator$b = NodeTranslator.from(
31101
- createNestedPropertiesTranslator("w:tblPr", "tableProperties", propertyTranslators)
31102
- );
31103
- const translator$a = NodeTranslator.from(
31104
- createSingleAttrPropertyHandler("w:gridCol", "col", "w:w", parseInteger, integerToString)
31105
- );
31106
- const DEFAULT_COLUMN_WIDTH_PX = 100;
31107
- const normalizeTwipWidth = (value) => {
31108
- if (value == null) return null;
31109
- const numericValue = typeof value === "string" ? parseInt(value, 10) : value;
31110
- if (!Number.isFinite(numericValue) || Number.isNaN(numericValue) || numericValue <= 0) {
31111
- return null;
31112
- }
31113
- return numericValue;
31114
- };
31115
- const getSchemaDefaultColumnWidthPx = (params2) => {
31116
- const defaultValue = params2?.editor?.schema?.nodes?.tableCell?.spec?.attrs?.colwidth?.default;
31117
- if (Array.isArray(defaultValue)) {
31118
- const numericWidth = defaultValue.find((width) => typeof width === "number" && Number.isFinite(width) && width > 0);
31119
- if (numericWidth != null) return numericWidth;
31120
- } else if (typeof defaultValue === "number" && Number.isFinite(defaultValue) && defaultValue > 0) {
31121
- return defaultValue;
31122
- }
31123
- return DEFAULT_COLUMN_WIDTH_PX;
31124
- };
31125
- const getTableWidthPx = (params2) => {
31126
- const explicitWidth = params2?.node?.attrs?.tableWidth?.width;
31127
- if (typeof explicitWidth === "number" && explicitWidth > 0) return explicitWidth;
31128
- const tableWidth = params2?.node?.attrs?.tableProperties?.tableWidth;
31129
- if (tableWidth?.value != null && typeof tableWidth.value === "number" && tableWidth.value > 0) {
31130
- const { value, type: type2 } = tableWidth;
31131
- if (!type2 || type2 === "auto" || type2 === "dxa") {
31132
- return twipsToPixels(value);
31133
- }
31134
- }
31135
- return null;
31136
- };
31137
- const resolveFallbackColumnWidthTwips = (params2, totalColumns, cellMinWidthTwips) => {
31138
- const columnCount = Math.max(totalColumns, 1);
31139
- const defaultColumnWidthPx = getSchemaDefaultColumnWidthPx(params2);
31140
- const tableWidthPx = getTableWidthPx(params2);
31141
- const safeDefaultPx = Number.isFinite(defaultColumnWidthPx) && defaultColumnWidthPx > 0 ? defaultColumnWidthPx : DEFAULT_COLUMN_WIDTH_PX;
31142
- let fallbackWidthPx = safeDefaultPx;
31143
- if (typeof tableWidthPx === "number" && tableWidthPx > 0) {
31144
- fallbackWidthPx = tableWidthPx / columnCount;
31145
- }
31146
- const fallbackWidthTwips = pixelsToTwips(fallbackWidthPx);
31147
- if (!Number.isFinite(fallbackWidthTwips) || Number.isNaN(fallbackWidthTwips) || fallbackWidthTwips <= 0) {
31148
- const safeDefault = Math.max(pixelsToTwips(safeDefaultPx), cellMinWidthTwips);
31149
- return safeDefault;
31150
- }
31151
- return Math.max(fallbackWidthTwips, cellMinWidthTwips);
31152
- };
31153
- const XML_NODE_NAME$a = "w:tblGrid";
31154
- const SD_ATTR_KEY$2 = "grid";
31155
- const cellMinWidth = pixelsToTwips(10);
31156
- const encode$g = (params2) => {
31157
- const { nodes } = params2;
31158
- const node = nodes[0];
31159
- const attributes = encodeProperties(node, { [translator$a.xmlName]: translator$a }, true);
31160
- return {
31161
- xmlName: XML_NODE_NAME$a,
31162
- sdNodeOrKeyName: SD_ATTR_KEY$2,
31163
- attributes
31164
- };
31165
- };
31166
- const decode$i = (params2) => {
31167
- const { grid: rawGrid } = params2.node.attrs || {};
31168
- const grid = Array.isArray(rawGrid) ? rawGrid : [];
31169
- const { firstRow = {} } = params2.extraParams || {};
31170
- const cellNodes = firstRow.content?.filter((n) => n.type === "tableCell") ?? [];
31171
- const columnCountFromCells = cellNodes.reduce((count, cell) => {
31172
- const spanCount = Math.max(1, cell?.attrs?.colspan ?? 1);
31173
- return count + spanCount;
31174
- }, 0);
31175
- const totalColumns = Math.max(columnCountFromCells, grid.length);
31176
- const fallbackColumnWidthTwips = resolveFallbackColumnWidthTwips(params2, totalColumns, cellMinWidth);
31177
- const elements = [];
31178
- let columnIndex = 0;
31179
- const pushColumn = (widthTwips, { enforceMinimum = false } = {}) => {
31180
- let numericWidth = typeof widthTwips === "string" ? parseInt(widthTwips, 10) : widthTwips;
31181
- let shouldEnforceMinimum = enforceMinimum;
31182
- if (numericWidth == null || Number.isNaN(numericWidth) || numericWidth <= 0) {
31183
- numericWidth = fallbackColumnWidthTwips;
31184
- shouldEnforceMinimum = true;
31185
- }
31186
- const roundedWidth = Math.round(numericWidth);
31187
- const minimumWidth = shouldEnforceMinimum ? cellMinWidth : 1;
31188
- const safeWidth = Math.max(roundedWidth, minimumWidth);
31189
- const decoded = translator$a.decode({
31190
- node: { type: (
31191
- /** @type {string} */
31192
- translator$a.sdNodeOrKeyName
31193
- ), attrs: { col: safeWidth } }
31194
- });
31195
- if (decoded) elements.push(decoded);
31196
- };
31197
- cellNodes.forEach((cell) => {
31198
- const { colspan = 1, colwidth } = cell?.attrs || {};
31199
- const spanCount = Math.max(1, colspan);
31200
- for (let span = 0; span < spanCount; span++) {
31201
- const rawWidth = Array.isArray(colwidth) ? colwidth[span] : void 0;
31202
- const cellWidthPixels = typeof rawWidth === "number" && Number.isFinite(rawWidth) ? rawWidth : Number(rawWidth);
31203
- const hasCellWidth = Number.isFinite(cellWidthPixels) && cellWidthPixels > 0;
31204
- const colGridAttrs = grid?.[columnIndex] || {};
31205
- const gridWidthTwips = normalizeTwipWidth(colGridAttrs.col);
31206
- const gridWidthPixels = gridWidthTwips != null ? twipsToPixels(gridWidthTwips) : null;
31207
- let cellWidthTwips;
31208
- let enforceMinimum = false;
31209
- if (hasCellWidth) {
31210
- const tolerance = 0.5;
31211
- if (gridWidthTwips != null && gridWidthPixels != null && Math.abs(gridWidthPixels - cellWidthPixels) <= tolerance) {
31212
- cellWidthTwips = gridWidthTwips;
31213
- } else {
31214
- cellWidthTwips = pixelsToTwips(cellWidthPixels);
31215
- }
31216
- } else if (gridWidthTwips != null) {
31217
- cellWidthTwips = gridWidthTwips;
31218
- } else {
31219
- cellWidthTwips = fallbackColumnWidthTwips;
31220
- enforceMinimum = true;
31221
- }
31222
- pushColumn(cellWidthTwips, { enforceMinimum });
31223
- columnIndex++;
31224
- }
31225
- });
31226
- while (columnIndex < grid.length) {
31227
- const gridWidthTwips = normalizeTwipWidth(grid[columnIndex]?.col);
31228
- pushColumn(gridWidthTwips);
31229
- columnIndex++;
31230
- }
31231
- const newNode = {
31232
- name: XML_NODE_NAME$a,
31233
- attributes: {},
31234
- elements
31235
- };
31236
- return newNode;
31237
- };
31238
- const config$9 = {
31239
- xmlName: XML_NODE_NAME$a,
31240
- sdNodeOrKeyName: SD_ATTR_KEY$2,
31241
- encode: encode$g,
31242
- decode: decode$i
31243
- };
31244
- const translator$9 = NodeTranslator.from(config$9);
31245
- const DEFAULT_PAGE_WIDTH_TWIPS = 12240;
31246
- const DEFAULT_PAGE_MARGIN_TWIPS = 1440;
31247
- const DEFAULT_CONTENT_WIDTH_TWIPS = DEFAULT_PAGE_WIDTH_TWIPS - 2 * DEFAULT_PAGE_MARGIN_TWIPS;
31248
- const MIN_COLUMN_WIDTH_TWIPS = pixelsToTwips(10);
31249
- const pctToPercent = (value) => {
31250
- if (value == null) return null;
31251
- return value / 50;
31252
- };
31253
- const resolveContentWidthTwips = () => DEFAULT_CONTENT_WIDTH_TWIPS;
31254
- const resolveMeasurementWidthPx = (measurement) => {
31255
- if (!measurement || typeof measurement.value !== "number" || measurement.value <= 0) return null;
31256
- const { value, type: type2 } = measurement;
31257
- if (!type2 || type2 === "auto") return null;
31258
- if (type2 === "dxa") return twipsToPixels(value);
31259
- if (type2 === "pct") {
31260
- const percent2 = pctToPercent(value);
31261
- if (percent2 == null || percent2 <= 0) return null;
31262
- const widthTwips = resolveContentWidthTwips() * percent2 / 100;
31263
- return twipsToPixels(widthTwips);
31264
- }
31265
- return null;
31266
- };
31267
- const countColumnsInRow = (row) => {
31268
- if (!row?.elements?.length) return 0;
31269
- return row.elements.reduce((count, element) => {
31270
- if (element.name !== "w:tc") return count;
31271
- const tcPr = element.elements?.find((el) => el.name === "w:tcPr");
31272
- const gridSpan = tcPr?.elements?.find((el) => el.name === "w:gridSpan");
31273
- const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
31274
- return count + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
31275
- }, 0);
31276
- };
31277
- const clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS);
31278
- const createFallbackGrid = (columnCount, columnWidthTwips) => Array.from({ length: columnCount }, () => ({ col: clampColumnWidthTwips(columnWidthTwips) }));
31279
- const buildFallbackGridForTable = ({ params: params2, rows, tableWidth, tableWidthMeasurement }) => {
31280
- const firstRow = rows.find((row) => row.elements?.some((el) => el.name === "w:tc"));
31281
- const columnCount = countColumnsInRow(firstRow);
31282
- if (!columnCount) return null;
31283
- const schemaDefaultPx = getSchemaDefaultColumnWidthPx(
31284
- /** @type {any} */
31285
- params2
31286
- );
31287
- const minimumColumnWidthPx = Number.isFinite(schemaDefaultPx) && schemaDefaultPx > 0 ? schemaDefaultPx : DEFAULT_COLUMN_WIDTH_PX;
31288
- let totalWidthPx;
31289
- if (tableWidthMeasurement) {
31290
- const resolved = resolveMeasurementWidthPx(tableWidthMeasurement);
31291
- if (resolved != null) totalWidthPx = resolved;
31292
- }
31293
- if (totalWidthPx == null && tableWidth?.width && tableWidth.width > 0) {
31294
- totalWidthPx = tableWidth.width;
31295
- }
31296
- if (totalWidthPx == null) {
31297
- totalWidthPx = minimumColumnWidthPx * columnCount;
31276
+ return translator$9.decode({
31277
+ ...params2,
31278
+ imageSize
31279
+ });
31280
+ }
31281
+ function prepareCheckboxAnnotation(params2) {
31282
+ const {
31283
+ node: { attrs = {}, marks = [] }
31284
+ } = params2;
31285
+ const content = he.decode(attrs.displayLabel);
31286
+ return getTextNodeForExport(content, marks, params2);
31287
+ }
31288
+ function prepareHtmlAnnotation(params2) {
31289
+ const {
31290
+ node: { attrs = {}, marks = [] },
31291
+ editorSchema
31292
+ } = params2;
31293
+ let html = attrs.rawHtml || attrs.displayLabel;
31294
+ const paragraphHtmlContainer = sanitizeHtml(html);
31295
+ const marksFromAttrs = translateFieldAttrsToMarks(attrs);
31296
+ const allMarks = [...marks, ...marksFromAttrs];
31297
+ let state2 = EditorState.create({
31298
+ doc: DOMParser$1.fromSchema(editorSchema).parse(paragraphHtmlContainer)
31299
+ });
31300
+ if (allMarks.length) {
31301
+ state2 = applyMarksToHtmlAnnotation(state2, allMarks);
31298
31302
  }
31299
- const rawColumnWidthPx = Math.max(totalWidthPx / columnCount, minimumColumnWidthPx);
31300
- const columnWidthTwips = clampColumnWidthTwips(pixelsToTwips(rawColumnWidthPx));
31301
- const fallbackColumnWidthPx = twipsToPixels(columnWidthTwips);
31303
+ const htmlAnnotationNode = state2.doc.toJSON();
31304
+ const listTypes = ["bulletList", "orderedList"];
31305
+ const { editor } = params2;
31306
+ const seenLists = /* @__PURE__ */ new Map();
31307
+ state2.doc.descendants((node) => {
31308
+ if (listTypes.includes(node.type.name)) {
31309
+ const listItem = node.firstChild;
31310
+ const { attrs: attrs2 } = listItem;
31311
+ const { level, numId } = attrs2;
31312
+ if (!seenLists.has(numId)) {
31313
+ const newNumId = ListHelpers.changeNumIdSameAbstract(numId, level, node.type.name, editor);
31314
+ listItem.attrs.numId = newNumId;
31315
+ seenLists.set(numId, newNumId);
31316
+ } else {
31317
+ const newNumId = seenLists.get(numId);
31318
+ listItem.attrs.numId = newNumId;
31319
+ }
31320
+ }
31321
+ });
31322
+ const elements = translateChildNodes({
31323
+ ...params2,
31324
+ node: htmlAnnotationNode
31325
+ });
31302
31326
  return {
31303
- grid: createFallbackGrid(columnCount, columnWidthTwips),
31304
- columnWidths: Array(columnCount).fill(fallbackColumnWidthPx)
31327
+ name: "htmlAnnotation",
31328
+ elements
31305
31329
  };
31306
- };
31307
- const XML_NODE_NAME$9 = "w:tbl";
31308
- const SD_NODE_NAME$7 = "table";
31309
- const encode$f = (params2, encodedAttrs) => {
31310
- const { nodes } = params2;
31311
- const node = nodes[0];
31312
- const tblPr = node.elements.find((el) => el.name === "w:tblPr");
31313
- if (tblPr) {
31314
- const encodedProperties = translator$b.encode({ ...params2, nodes: [tblPr] });
31315
- encodedAttrs["tableProperties"] = encodedProperties || {};
31316
- }
31317
- const tblGrid = node.elements.find((el) => el.name === "w:tblGrid");
31318
- if (tblGrid) {
31319
- encodedAttrs["grid"] = translator$9.encode({ ...params2, nodes: [tblGrid] }).attributes;
31330
+ }
31331
+ function prepareUrlAnnotation(params2) {
31332
+ const {
31333
+ node: { attrs = {}, marks = [] }
31334
+ } = params2;
31335
+ if (!attrs.linkUrl) return prepareTextAnnotation(params2);
31336
+ const newId = addNewLinkRelationship(params2, attrs.linkUrl);
31337
+ const linkTextNode = getTextNodeForExport(attrs.linkUrl, marks, params2);
31338
+ const contentNode = processLinkContentNode(linkTextNode);
31339
+ return {
31340
+ name: "w:hyperlink",
31341
+ type: "element",
31342
+ attributes: {
31343
+ "r:id": newId,
31344
+ "w:history": 1
31345
+ },
31346
+ elements: [contentNode]
31347
+ };
31348
+ }
31349
+ function translateFieldAttrsToMarks(attrs = {}) {
31350
+ const { fontFamily: fontFamily2, fontSize: fontSize2, bold, underline, italic, textColor, textHighlight } = attrs;
31351
+ const marks = [];
31352
+ if (fontFamily2) marks.push({ type: "fontFamily", attrs: { fontFamily: fontFamily2 } });
31353
+ if (fontSize2) marks.push({ type: "fontSize", attrs: { fontSize: fontSize2 } });
31354
+ if (bold) marks.push({ type: "bold", attrs: {} });
31355
+ if (underline) marks.push({ type: "underline", attrs: {} });
31356
+ if (italic) marks.push({ type: "italic", attrs: {} });
31357
+ if (textColor) marks.push({ type: "color", attrs: { color: textColor } });
31358
+ if (textHighlight) marks.push({ type: "highlight", attrs: { color: textHighlight } });
31359
+ return marks;
31360
+ }
31361
+ function applyMarksToHtmlAnnotation(state2, marks) {
31362
+ const { tr, doc: doc2, schema } = state2;
31363
+ const allowedMarks = ["fontFamily", "fontSize", "highlight"];
31364
+ if (!marks.some((m2) => allowedMarks.includes(m2.type))) {
31365
+ return state2;
31320
31366
  }
31321
- [
31322
- "tableStyleId",
31323
- "justification",
31324
- "tableLayout",
31325
- ["tableIndent", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
31326
- ["tableCellSpacing", ({ value, type: type2 }) => ({ w: String(value), type: type2 })]
31327
- ].forEach((prop) => {
31328
- let key2;
31329
- let transform;
31330
- if (Array.isArray(prop)) {
31331
- [key2, transform] = prop;
31332
- } else {
31333
- key2 = prop;
31334
- transform = (v2) => v2;
31367
+ const fontFamily2 = marks.find((m2) => m2.type === "fontFamily");
31368
+ const fontSize2 = marks.find((m2) => m2.type === "fontSize");
31369
+ const highlight = marks.find((m2) => m2.type === "highlight");
31370
+ const textStyleType = schema.marks.textStyle;
31371
+ const highlightType = schema.marks.highlight;
31372
+ doc2.descendants((node, pos) => {
31373
+ if (!node.isText) return;
31374
+ const foundTextStyle = node.marks.find((m2) => m2.type.name === "textStyle");
31375
+ const foundHighlight = node.marks.find((m2) => m2.type.name === "highlight");
31376
+ if (!foundTextStyle) {
31377
+ tr.addMark(
31378
+ pos,
31379
+ pos + node.nodeSize,
31380
+ textStyleType.create({
31381
+ ...fontFamily2?.attrs,
31382
+ ...fontSize2?.attrs
31383
+ })
31384
+ );
31385
+ } else if (!foundTextStyle?.attrs.fontFamily && fontFamily2) {
31386
+ tr.addMark(
31387
+ pos,
31388
+ pos + node.nodeSize,
31389
+ textStyleType.create({
31390
+ ...foundTextStyle?.attrs,
31391
+ ...fontFamily2.attrs
31392
+ })
31393
+ );
31394
+ } else if (!foundTextStyle?.attrs.fontSize && fontSize2) {
31395
+ tr.addMark(
31396
+ pos,
31397
+ pos + node.nodeSize,
31398
+ textStyleType.create({
31399
+ ...foundTextStyle?.attrs,
31400
+ ...fontSize2.attrs
31401
+ })
31402
+ );
31335
31403
  }
31336
- if (encodedAttrs.tableProperties && encodedAttrs.tableProperties[key2]) {
31337
- encodedAttrs[key2] = transform(encodedAttrs.tableProperties[key2]);
31404
+ if (!foundHighlight) {
31405
+ tr.addMark(
31406
+ pos,
31407
+ pos + node.nodeSize,
31408
+ highlightType.create({
31409
+ ...highlight?.attrs
31410
+ })
31411
+ );
31338
31412
  }
31339
31413
  });
31340
- if (encodedAttrs.tableCellSpacing) {
31341
- encodedAttrs["borderCollapse"] = "separate";
31342
- }
31343
- if (encodedAttrs.tableProperties?.tableWidth) {
31344
- const tableWidthMeasurement = encodedAttrs.tableProperties.tableWidth;
31345
- const widthPx = twipsToPixels(tableWidthMeasurement.value);
31346
- if (widthPx != null) {
31347
- encodedAttrs.tableWidth = {
31348
- width: widthPx,
31349
- type: tableWidthMeasurement.type
31350
- };
31351
- } else if (tableWidthMeasurement.type === "auto") {
31352
- encodedAttrs.tableWidth = {
31353
- width: 0,
31354
- type: tableWidthMeasurement.type
31355
- };
31356
- }
31357
- }
31358
- const { borders, rowBorders } = _processTableBorders(encodedAttrs.tableProperties?.borders || {});
31359
- const referencedStyles = _getReferencedTableStyles(encodedAttrs.tableStyleId, params2);
31360
- if (referencedStyles?.cellMargins && !encodedAttrs.tableProperties?.cellMargins) {
31361
- encodedAttrs.tableProperties = {
31362
- ...encodedAttrs.tableProperties || {},
31363
- cellMargins: referencedStyles.cellMargins
31364
- };
31414
+ return state2.apply(tr);
31415
+ }
31416
+ function getFieldHighlightJson(fieldsHighlightColor) {
31417
+ if (!fieldsHighlightColor) return null;
31418
+ let parsedColor = fieldsHighlightColor.trim();
31419
+ const hexRegex2 = /^#?([A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/;
31420
+ if (!hexRegex2.test(parsedColor)) {
31421
+ console.warn(`Invalid HEX color provided to fieldsHighlightColor export param: ${fieldsHighlightColor}`);
31422
+ return null;
31365
31423
  }
31366
- const rows = node.elements.filter((el) => el.name === "w:tr");
31367
- const borderData = Object.assign({}, referencedStyles?.borders || {}, borders || {});
31368
- const borderRowData = Object.assign({}, referencedStyles?.rowBorders || {}, rowBorders || {});
31369
- encodedAttrs["borders"] = borderData;
31370
- let columnWidths = Array.isArray(encodedAttrs["grid"]) ? encodedAttrs["grid"].map((item) => twipsToPixels(item.col)) : [];
31371
- if (!columnWidths.length) {
31372
- const fallback = buildFallbackGridForTable({
31373
- params: params2,
31374
- rows,
31375
- tableWidth: encodedAttrs.tableWidth,
31376
- tableWidthMeasurement: encodedAttrs.tableProperties?.tableWidth
31377
- });
31378
- if (fallback) {
31379
- encodedAttrs.grid = fallback.grid;
31380
- columnWidths = fallback.columnWidths;
31381
- }
31424
+ if (parsedColor.startsWith("#")) {
31425
+ parsedColor = parsedColor.slice(1);
31382
31426
  }
31383
- const content = [];
31384
- const totalColumns = columnWidths.length;
31385
- const activeRowSpans = totalColumns > 0 ? new Array(totalColumns).fill(0) : [];
31386
- rows.forEach((row, rowIndex) => {
31387
- const result = translator$u.encode({
31388
- ...params2,
31389
- nodes: [row],
31390
- extraParams: {
31391
- row,
31392
- table: node,
31393
- rowBorders: borderRowData,
31394
- columnWidths,
31395
- activeRowSpans: activeRowSpans.slice(),
31396
- rowIndex,
31397
- _referencedStyles: referencedStyles
31398
- }
31399
- });
31400
- if (result) {
31401
- content.push(result);
31402
- if (totalColumns > 0) {
31403
- const activeRowSpansForCurrentRow = activeRowSpans.slice();
31404
- for (let col = 0; col < totalColumns; col++) {
31405
- if (activeRowSpans[col] > 0) {
31406
- activeRowSpans[col] -= 1;
31407
- }
31427
+ return {
31428
+ name: "w:rPr",
31429
+ elements: [
31430
+ {
31431
+ name: "w:shd",
31432
+ attributes: {
31433
+ "w:fill": `#${parsedColor}`,
31434
+ "w:color": "auto",
31435
+ "w:val": "clear"
31408
31436
  }
31409
- let columnIndex = 0;
31410
- const advanceColumnIndex = () => {
31411
- while (columnIndex < totalColumns && activeRowSpansForCurrentRow[columnIndex] > 0) {
31412
- columnIndex += 1;
31413
- }
31414
- };
31415
- advanceColumnIndex();
31416
- result.content?.forEach((cell) => {
31417
- advanceColumnIndex();
31418
- const colspan = Math.max(1, cell.attrs?.colspan || 1);
31419
- const rowspan = Math.max(1, cell.attrs?.rowspan || 1);
31420
- if (rowspan > 1) {
31421
- for (let offset2 = 0; offset2 < colspan && columnIndex + offset2 < totalColumns; offset2++) {
31422
- const targetIndex = columnIndex + offset2;
31423
- const remainingRows = rowspan - 1;
31424
- if (remainingRows > 0 && remainingRows > activeRowSpans[targetIndex]) {
31425
- activeRowSpans[targetIndex] = remainingRows;
31426
- }
31427
- }
31428
- }
31429
- columnIndex += colspan;
31430
- advanceColumnIndex();
31431
- });
31432
31437
  }
31433
- }
31434
- });
31435
- return {
31436
- type: "table",
31437
- content,
31438
- attrs: encodedAttrs
31438
+ ]
31439
31439
  };
31440
- };
31441
- const decode$h = (params2, decodedAttrs) => {
31442
- params2.node = preProcessVerticalMergeCells(params2.node, params2);
31440
+ }
31441
+ function translateDocumentSection(params2) {
31443
31442
  const { node } = params2;
31444
- const elements = translateChildNodes(params2);
31445
- const firstRow = node.content?.find((n) => n.type === "tableRow");
31446
- const properties = node.attrs.grid;
31447
- const element = translator$9.decode({
31448
- ...params2,
31449
- node: { ...node, attrs: { ...node.attrs, grid: properties } },
31450
- extraParams: {
31451
- firstRow
31443
+ const { attrs = {} } = node;
31444
+ const childContent = translateChildNodes({ ...params2, nodes: node.content });
31445
+ const nodeElements = [
31446
+ {
31447
+ name: "w:sdtContent",
31448
+ elements: childContent
31452
31449
  }
31450
+ ];
31451
+ const exportedTag = JSON.stringify({
31452
+ type: "documentSection",
31453
+ description: attrs.description
31453
31454
  });
31454
- if (element) elements.unshift(element);
31455
- if (node.attrs?.tableProperties) {
31456
- const properties2 = { ...node.attrs.tableProperties };
31457
- const element2 = translator$b.decode({
31458
- ...params2,
31459
- node: { ...node, attrs: { ...node.attrs, tableProperties: properties2 } }
31455
+ const sdtPr = generateSdtPrTagForDocumentSection(attrs.id, attrs.title, exportedTag);
31456
+ const { isLocked } = attrs;
31457
+ if (isLocked) {
31458
+ sdtPr.elements.push({
31459
+ name: "w:lock",
31460
+ attributes: {
31461
+ "w:val": "sdtContentLocked"
31462
+ }
31460
31463
  });
31461
- if (element2) elements.unshift(element2);
31462
31464
  }
31465
+ nodeElements.unshift(sdtPr);
31466
+ const result = {
31467
+ name: "w:sdt",
31468
+ elements: nodeElements
31469
+ };
31470
+ return result;
31471
+ }
31472
+ const generateSdtPrTagForDocumentSection = (id, title, tag) => {
31463
31473
  return {
31464
- name: "w:tbl",
31465
- attributes: decodedAttrs || {},
31466
- elements
31474
+ name: "w:sdtPr",
31475
+ elements: [
31476
+ {
31477
+ name: "w:id",
31478
+ attributes: {
31479
+ "w:val": id
31480
+ }
31481
+ },
31482
+ {
31483
+ name: "w:alias",
31484
+ attributes: {
31485
+ "w:val": title
31486
+ }
31487
+ },
31488
+ {
31489
+ name: "w:tag",
31490
+ attributes: {
31491
+ "w:val": tag
31492
+ }
31493
+ }
31494
+ ]
31467
31495
  };
31468
31496
  };
31469
- function _processTableBorders(rawBorders) {
31470
- const borders = {};
31471
- const rowBorders = {};
31472
- Object.entries(rawBorders).forEach(([name, attributes]) => {
31473
- const attrs = {};
31474
- const color = attributes.color;
31475
- const size2 = attributes.size;
31476
- if (color && color !== "auto") attrs["color"] = color.startsWith("#") ? color : `#${color}`;
31477
- if (size2 && size2 !== "auto") attrs["size"] = eighthPointsToPixels(size2);
31478
- const rowBorderNames = ["insideH", "insideV"];
31479
- if (rowBorderNames.includes(name)) rowBorders[name] = attrs;
31480
- borders[name] = attrs;
31481
- });
31482
- return {
31483
- borders,
31484
- rowBorders
31497
+ function translateDocumentPartObj(params2) {
31498
+ const { node } = params2;
31499
+ const { attrs = {} } = node;
31500
+ const childContent = translateChildNodes({ ...params2, nodes: node.content });
31501
+ const nodeElements = [
31502
+ {
31503
+ name: "w:sdtPr",
31504
+ elements: [
31505
+ {
31506
+ name: "w:id",
31507
+ attributes: {
31508
+ "w:val": attrs.id
31509
+ }
31510
+ },
31511
+ {
31512
+ name: "w:docPartObj",
31513
+ elements: [
31514
+ {
31515
+ name: "w:docPartGallery",
31516
+ attributes: {
31517
+ "w:val": attrs.docPartGallery
31518
+ }
31519
+ },
31520
+ ...attrs.docPartUnique ? [
31521
+ {
31522
+ name: "w:docPartUnique"
31523
+ }
31524
+ ] : []
31525
+ ]
31526
+ }
31527
+ ]
31528
+ },
31529
+ {
31530
+ name: "w:sdtContent",
31531
+ elements: childContent
31532
+ }
31533
+ ];
31534
+ const result = {
31535
+ name: "w:sdt",
31536
+ elements: nodeElements
31485
31537
  };
31538
+ return result;
31486
31539
  }
31487
- function _getReferencedTableStyles(tableStyleReference, params2) {
31488
- if (!tableStyleReference) return null;
31489
- const stylesToReturn = {};
31490
- const { docx } = params2;
31491
- const styles = docx["word/styles.xml"];
31492
- const { elements } = styles.elements[0];
31493
- const styleElements = elements.filter((el) => el.name === "w:style");
31494
- const styleTag = styleElements.find((el) => el.attributes["w:styleId"] === tableStyleReference);
31495
- if (!styleTag) return null;
31496
- stylesToReturn.name = styleTag.elements.find((el) => el.name === "w:name");
31497
- const basedOn = styleTag.elements.find((el) => el.name === "w:basedOn");
31498
- let baseTblPr;
31499
- if (basedOn?.attributes) {
31500
- const baseStyles = styleElements.find((el) => el.attributes["w:styleId"] === basedOn.attributes["w:val"]);
31501
- baseTblPr = baseStyles ? baseStyles.elements.find((el) => el.name === "w:tblPr") : {};
31502
- }
31503
- const pPr = styleTag.elements.find((el) => el.name === "w:pPr");
31504
- if (pPr) {
31505
- const justification = pPr.elements.find((el) => el.name === "w:jc");
31506
- if (justification?.attributes) stylesToReturn.justification = justification.attributes["w:val"];
31540
+ function translateStructuredContent(params2) {
31541
+ const { node } = params2;
31542
+ const childContent = translateChildNodes({ ...params2, nodes: node.content });
31543
+ const sdtContent = { name: "w:sdtContent", elements: childContent };
31544
+ const sdtPr = generateSdtPrTagForStructuredContent({ node });
31545
+ const nodeElements = [sdtPr, sdtContent];
31546
+ const result = {
31547
+ name: "w:sdt",
31548
+ elements: nodeElements
31549
+ };
31550
+ return result;
31551
+ }
31552
+ function generateSdtPrTagForStructuredContent({ node }) {
31553
+ const { attrs = {} } = node;
31554
+ const id = {
31555
+ name: "w:id",
31556
+ type: "element",
31557
+ attributes: { "w:val": attrs.id }
31558
+ };
31559
+ const alias = {
31560
+ name: "w:alias",
31561
+ type: "element",
31562
+ attributes: { "w:val": attrs.alias }
31563
+ };
31564
+ const tag = {
31565
+ name: "w:tag",
31566
+ type: "element",
31567
+ attributes: { "w:val": attrs.tag }
31568
+ };
31569
+ const resultElements = [];
31570
+ if (attrs.id) resultElements.push(id);
31571
+ if (attrs.alias) resultElements.push(alias);
31572
+ if (attrs.tag) resultElements.push(tag);
31573
+ if (attrs.sdtPr) {
31574
+ const elements = attrs.sdtPr.elements || [];
31575
+ const elementsToExclude = ["w:id", "w:alias", "w:tag"];
31576
+ const restElements = elements.filter((el) => !elementsToExclude.includes(el.name));
31577
+ const result2 = {
31578
+ name: "w:sdtPr",
31579
+ type: "element",
31580
+ elements: [...resultElements, ...restElements]
31581
+ };
31582
+ return result2;
31507
31583
  }
31508
- const rPr = styleTag?.elements.find((el) => el.name === "w:rPr");
31509
- if (rPr) {
31510
- const fonts = rPr.elements.find((el) => el.name === "w:rFonts");
31511
- if (fonts) {
31512
- const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
31513
- stylesToReturn.fonts = { ascii, hAnsi, cs };
31514
- }
31515
- const fontSize2 = rPr.elements.find((el) => el.name === "w:sz");
31516
- if (fontSize2?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize2.attributes["w:val"]) + "pt";
31584
+ const result = {
31585
+ name: "w:sdtPr",
31586
+ type: "element",
31587
+ elements: resultElements
31588
+ };
31589
+ return result;
31590
+ }
31591
+ const XML_NODE_NAME$9 = "w:sdt";
31592
+ const SD_NODE_NAME$7 = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
31593
+ const validXmlAttributes$6 = [];
31594
+ function encode$f(params2) {
31595
+ const nodes = params2.nodes;
31596
+ const node = nodes[0];
31597
+ const { type: sdtType, handler: handler2 } = sdtNodeTypeStrategy(node);
31598
+ if (!handler2 || sdtType === "unknown") {
31599
+ return void 0;
31517
31600
  }
31518
- const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
31519
- if (tblPr && tblPr.elements) {
31520
- if (baseTblPr && baseTblPr.elements) {
31521
- tblPr.elements.push(...baseTblPr.elements);
31522
- }
31523
- const tableProperties = translator$b.encode({ ...params2, nodes: [tblPr] });
31524
- if (tableProperties) {
31525
- const { borders, rowBorders } = _processTableBorders(tableProperties.borders || {});
31526
- if (borders) stylesToReturn.borders = borders;
31527
- if (rowBorders) stylesToReturn.rowBorders = rowBorders;
31528
- const cellMargins = {};
31529
- Object.entries(tableProperties.cellMargins || {}).forEach(([key2, attrs]) => {
31530
- if (attrs?.value != null) {
31531
- cellMargins[key2] = {
31532
- value: attrs.value,
31533
- type: attrs.type || "dxa"
31534
- };
31535
- }
31536
- });
31537
- if (Object.keys(cellMargins).length) stylesToReturn.cellMargins = cellMargins;
31538
- }
31601
+ const result = handler2(params2);
31602
+ return result;
31603
+ }
31604
+ function decode$h(params2) {
31605
+ const { node } = params2;
31606
+ if (!node || !node.type) {
31607
+ return null;
31539
31608
  }
31540
- return stylesToReturn;
31609
+ const types2 = {
31610
+ fieldAnnotation: () => translateFieldAnnotation(params2),
31611
+ structuredContent: () => translateStructuredContent(params2),
31612
+ structuredContentBlock: () => translateStructuredContent(params2),
31613
+ documentSection: () => translateDocumentSection(params2),
31614
+ documentPartObject: () => translateDocumentPartObj(params2),
31615
+ // Handled in doc-part-obj translator
31616
+ default: () => null
31617
+ };
31618
+ const decoder = types2[node.type] ?? types2.default;
31619
+ const result = decoder();
31620
+ return result;
31541
31621
  }
31542
31622
  const config$8 = {
31543
31623
  xmlName: XML_NODE_NAME$9,
@@ -31545,7 +31625,7 @@ const config$8 = {
31545
31625
  type: NodeTranslator.translatorTypes.NODE,
31546
31626
  encode: encode$f,
31547
31627
  decode: decode$h,
31548
- attributes: []
31628
+ attributes: validXmlAttributes$6
31549
31629
  };
31550
31630
  const translator$8 = NodeTranslator.from(config$8);
31551
31631
  const encode$e = (attributes) => {
@@ -32060,7 +32140,7 @@ const handleDrawingNode = (params2) => {
32060
32140
  if (mainNode.name === "w:drawing") node = mainNode;
32061
32141
  else node = mainNode.elements.find((el) => el.name === "w:drawing");
32062
32142
  if (!node) return { nodes: [], consumed: 0 };
32063
- const schemaNode = translator$r.encode(params2);
32143
+ const schemaNode = translator$9.encode(params2);
32064
32144
  const newNodes = schemaNode ? [schemaNode] : [];
32065
32145
  return { nodes: newNodes, consumed: 1 };
32066
32146
  };
@@ -32369,7 +32449,7 @@ const handleSdtNode = (params2) => {
32369
32449
  if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
32370
32450
  return { nodes: [], consumed: 0 };
32371
32451
  }
32372
- const result = translator$q.encode(params2);
32452
+ const result = translator$8.encode(params2);
32373
32453
  if (!result) {
32374
32454
  return { nodes: [], consumed: 0 };
32375
32455
  }
@@ -33163,7 +33243,6 @@ const tabNodeEntityHandler = {
33163
33243
  handlerName: "w:tabTranslator",
33164
33244
  handler: handleTabNode
33165
33245
  };
33166
- const tableNodeHandlerEntity = generateV2HandlerEntity("tableNodeHandler", translator$8);
33167
33246
  const tableOfContentsHandlerEntity = generateV2HandlerEntity("tableOfContentsHandler", translator$4);
33168
33247
  function preProcessPageInstruction(nodesToCombine) {
33169
33248
  const pageNumNode = {
@@ -34173,14 +34252,14 @@ function exportSchemaToJson(params2) {
34173
34252
  bulletList: translateList,
34174
34253
  orderedList: translateList,
34175
34254
  lineBreak: translator$1r,
34176
- table: translator$8,
34177
- tableRow: translator$u,
34178
- tableCell: translator$H,
34255
+ table: translator$s,
34256
+ tableRow: translator$Z,
34257
+ tableCell: translator$c,
34179
34258
  bookmarkStart: translator$7,
34180
34259
  bookmarkEnd: translator$6,
34181
- fieldAnnotation: translator$q,
34260
+ fieldAnnotation: translator$8,
34182
34261
  tab: translator$1p,
34183
- image: translator$r,
34262
+ image: translator$9,
34184
34263
  hardBreak: translator$1r,
34185
34264
  commentRangeStart: commentRangeStartTranslator,
34186
34265
  commentRangeEnd: commentRangeEndTranslator,
@@ -34189,10 +34268,10 @@ function exportSchemaToJson(params2) {
34189
34268
  shapeTextbox: translator,
34190
34269
  contentBlock: translator,
34191
34270
  vectorShape: translateVectorShape,
34192
- structuredContent: translator$q,
34193
- structuredContentBlock: translator$q,
34194
- documentPartObject: translator$q,
34195
- documentSection: translator$q,
34271
+ structuredContent: translator$8,
34272
+ structuredContentBlock: translator$8,
34273
+ documentPartObject: translator$8,
34274
+ documentSection: translator$8,
34196
34275
  "page-number": translatePageNumberNode,
34197
34276
  "total-page-number": translateTotalPageNumberNode,
34198
34277
  pageReference: translator$5,
@@ -65513,7 +65592,7 @@ const Image = Node$1.create({
65513
65592
  return {
65514
65593
  allowBase64: true,
65515
65594
  htmlAttributes: {
65516
- style: "display: inline-block; content-visibility: auto; contain-intrinsic-size: auto 600px;",
65595
+ style: "display: inline-block;",
65517
65596
  "aria-label": "Image node"
65518
65597
  }
65519
65598
  };
@@ -91759,86 +91838,86 @@ const additionalHandlers = Object.freeze({
91759
91838
  "sd:pageReference": translator$5,
91760
91839
  "sd:tableOfContents": translator$4,
91761
91840
  "w:b": translator$1n,
91762
- "w:bidiVisual": translator$p,
91841
+ "w:bidiVisual": translator$Y,
91763
91842
  "w:bookmarkEnd": translator$6,
91764
91843
  "w:bookmarkStart": translator$7,
91765
- "w:bottom": translator$15,
91844
+ "w:bottom": translator$L,
91766
91845
  "w:br": translator$1r,
91767
- "w:cantSplit": translator$G,
91768
- "w:cnfStyle": translator$1a,
91846
+ "w:cantSplit": translator$1a,
91847
+ "w:cnfStyle": translator$19,
91769
91848
  "w:color": translator$1j,
91770
- "w:divId": translator$F,
91771
- "w:drawing": translator$r,
91772
- "w:end": translator$13,
91773
- "w:gridAfter": translator$E,
91774
- "w:gridBefore": translator$D,
91775
- "w:gridCol": translator$a,
91776
- "w:hidden": translator$C,
91849
+ "w:divId": translator$18,
91850
+ "w:drawing": translator$9,
91851
+ "w:end": translator$J,
91852
+ "w:gridAfter": translator$17,
91853
+ "w:gridBefore": translator$16,
91854
+ "w:gridCol": translator$u,
91855
+ "w:hidden": translator$15,
91777
91856
  "w:highlight": translator$1q,
91778
91857
  "w:hyperlink": translator$1c,
91779
91858
  "w:i": translator$1m,
91780
- "w:insideH": translator$11,
91781
- "w:insideV": translator$10,
91782
- "w:jc": translator$B,
91783
- "w:left": translator$$,
91859
+ "w:insideH": translator$H,
91860
+ "w:insideV": translator$G,
91861
+ "w:jc": translator$14,
91862
+ "w:left": translator$F,
91784
91863
  "w:p": translator$1o,
91785
91864
  "w:r": translator$1b,
91786
91865
  "w:rFonts": translator$1i,
91787
91866
  "w:rPr": translator$1d,
91788
91867
  "w:rStyle": translator$1h,
91789
- "w:right": translator$Z,
91790
- "w:sdt": translator$q,
91791
- "w:shd": translator$19,
91792
- "w:start": translator$X,
91868
+ "w:right": translator$D,
91869
+ "w:sdt": translator$8,
91870
+ "w:shd": translator$X,
91871
+ "w:start": translator$B,
91793
91872
  "w:strike": translator$1k,
91794
91873
  "w:sz": translator$1g,
91795
91874
  "w:szCs": translator$1f,
91796
91875
  "w:tab": translator$1p,
91797
- "w:tbl": translator$8,
91798
- "w:tblBorders": translator$d,
91799
- "w:tblCaption": translator$o,
91800
- "w:tblCellMar": translator$c,
91801
- "w:tblCellSpacing": translator$A,
91802
- "w:tblDescription": translator$n,
91803
- "w:tblGrid": translator$9,
91804
- "w:tblHeader": translator$z,
91805
- "w:tblInd": translator$m,
91806
- "w:tblLayout": translator$l,
91807
- "w:tblLook": translator$k,
91808
- "w:tblOverlap": translator$j,
91809
- "w:tblPr": translator$b,
91810
- "w:tblStyle": translator$i,
91811
- "w:tblStyleColBandSize": translator$h,
91812
- "w:tblStyleRowBandSize": translator$g,
91813
- "w:tblW": translator$f,
91814
- "w:tblpPr": translator$e,
91815
- "w:tc": translator$H,
91816
- "w:top": translator$V,
91817
- "w:tr": translator$u,
91818
- "w:trHeight": translator$y,
91819
- "w:trPr": translator$v,
91876
+ "w:tbl": translator$s,
91877
+ "w:tblBorders": translator$x,
91878
+ "w:tblCaption": translator$W,
91879
+ "w:tblCellMar": translator$w,
91880
+ "w:tblCellSpacing": translator$13,
91881
+ "w:tblDescription": translator$V,
91882
+ "w:tblGrid": translator$t,
91883
+ "w:tblHeader": translator$12,
91884
+ "w:tblInd": translator$U,
91885
+ "w:tblLayout": translator$T,
91886
+ "w:tblLook": translator$S,
91887
+ "w:tblOverlap": translator$R,
91888
+ "w:tblPr": translator$v,
91889
+ "w:tblStyle": translator$Q,
91890
+ "w:tblStyleColBandSize": translator$P,
91891
+ "w:tblStyleRowBandSize": translator$O,
91892
+ "w:tblW": translator$N,
91893
+ "w:tblpPr": translator$M,
91894
+ "w:tc": translator$c,
91895
+ "w:top": translator$z,
91896
+ "w:tr": translator$Z,
91897
+ "w:trHeight": translator$11,
91898
+ "w:trPr": translator$_,
91820
91899
  "w:u": translator$1l,
91821
- "w:wAfter": translator$x,
91822
- "w:wBefore": translator$w,
91823
- "wp:anchor": translator$t,
91824
- "wp:inline": translator$s,
91900
+ "w:wAfter": translator$10,
91901
+ "w:wBefore": translator$$,
91902
+ "wp:anchor": translator$b,
91903
+ "wp:inline": translator$a,
91825
91904
  "w:commentRangeStart": commentRangeStartTranslator,
91826
91905
  "w:commentRangeEnd": commentRangeEndTranslator,
91827
- "w:vMerge": translator$16,
91828
- "w:gridSpan": translator$17,
91829
- "w:vAlign": translator$M,
91830
- "w:noWrap": translator$Q,
91831
- "w:tcFitText": translator$N,
91832
- "w:tcW": translator$18,
91833
- "w:hideMark": translator$L,
91834
- "w:textDirection": translator$O,
91835
- "w:tl2br": translator$T,
91836
- "w:tr2bl": translator$S,
91837
- "w:header": translator$K,
91838
- "w:headers": translator$J,
91839
- "w:tcBorders": translator$R,
91840
- "w:tcMar": translator$P,
91841
- "w:tcPr": translator$I
91906
+ "w:vMerge": translator$p,
91907
+ "w:gridSpan": translator$q,
91908
+ "w:vAlign": translator$h,
91909
+ "w:noWrap": translator$l,
91910
+ "w:tcFitText": translator$i,
91911
+ "w:tcW": translator$r,
91912
+ "w:hideMark": translator$g,
91913
+ "w:textDirection": translator$j,
91914
+ "w:tl2br": translator$o,
91915
+ "w:tr2bl": translator$n,
91916
+ "w:header": translator$f,
91917
+ "w:headers": translator$e,
91918
+ "w:tcBorders": translator$m,
91919
+ "w:tcMar": translator$k,
91920
+ "w:tcPr": translator$d
91842
91921
  });
91843
91922
  const baseHandlers = {
91844
91923
  ...runPropertyTranslators,