@harbour-enterprises/superdoc 1.17.0-next.2 → 1.17.0-next.4

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.
@@ -27601,85 +27601,6 @@ const config$16 = {
27601
27601
  attributes: validXmlAttributes$3
27602
27602
  };
27603
27603
  const translator$7 = NodeTranslator.from(config$16);
27604
- var getColspan = (cell) => {
27605
- const rawColspan = cell?.attrs?.colspan;
27606
- const numericColspan = typeof rawColspan === "string" ? parseInt(rawColspan, 10) : rawColspan;
27607
- return Number.isFinite(numericColspan) && numericColspan > 0 ? numericColspan : 1;
27608
- };
27609
- var resolveGridBefore = (row) => {
27610
- const rawGridBefore = row?.attrs?.tableRowProperties?.gridBefore ?? row?.attrs?.gridBefore;
27611
- const numericGridBefore = typeof rawGridBefore === "string" ? parseInt(rawGridBefore, 10) : rawGridBefore;
27612
- if (!Number.isFinite(numericGridBefore) || numericGridBefore <= 0) return 0;
27613
- const cells = Array.isArray(row.content) ? row.content : [];
27614
- let leadingGridBefore = 0;
27615
- while (leadingGridBefore < cells.length && cells[leadingGridBefore]?.attrs?.__placeholder === "gridBefore") leadingGridBefore += 1;
27616
- return leadingGridBefore > 0 ? 0 : numericGridBefore;
27617
- };
27618
- var advanceColumnsForCell = (columnIndex, cell) => columnIndex + getColspan(cell);
27619
- var getCellStartColumn = (row, targetCell) => {
27620
- const cells = Array.isArray(row.content) ? row.content : [];
27621
- let columnIndex = resolveGridBefore(row);
27622
- for (const cell of cells) {
27623
- if (cell === targetCell) return columnIndex;
27624
- columnIndex = advanceColumnsForCell(columnIndex, cell);
27625
- }
27626
- return columnIndex;
27627
- };
27628
- var findCellCoveringColumn = (row, targetColumn) => {
27629
- const cells = Array.isArray(row.content) ? row.content : [];
27630
- let columnIndex = resolveGridBefore(row);
27631
- for (const cell of cells) {
27632
- const colspan = getColspan(cell);
27633
- if (targetColumn >= columnIndex && targetColumn < columnIndex + colspan) return cell;
27634
- columnIndex = advanceColumnsForCell(columnIndex, cell);
27635
- }
27636
- return null;
27637
- };
27638
- var findInsertionIndexForColumn = (row, targetColumn) => {
27639
- const cells = Array.isArray(row.content) ? row.content : [];
27640
- let columnIndex = resolveGridBefore(row);
27641
- for (let index = 0; index < cells.length; index++) {
27642
- if (columnIndex >= targetColumn) return index;
27643
- columnIndex = advanceColumnsForCell(columnIndex, cells[index]);
27644
- }
27645
- return cells.length;
27646
- };
27647
- function preProcessVerticalMergeCells(table, { editorSchema }) {
27648
- if (!table || !Array.isArray(table.content)) return table;
27649
- const rows = table.content;
27650
- for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
27651
- const row = rows[rowIndex];
27652
- if (!row) continue;
27653
- if (!Array.isArray(row.content)) row.content = [];
27654
- for (let cellIndex = 0; cellIndex < row.content.length; cellIndex++) {
27655
- const cell = row.content[cellIndex];
27656
- if (!cell) continue;
27657
- const attrs = cell.attrs || {};
27658
- const rawRowspan = typeof attrs.rowspan === "string" ? parseInt(attrs.rowspan, 10) : attrs.rowspan;
27659
- if (!Number.isFinite(rawRowspan) || rawRowspan <= 1) continue;
27660
- const maxRowspan = Math.min(rawRowspan, rows.length - rowIndex);
27661
- const startColumn = getCellStartColumn(row, cell);
27662
- for (let offset = 1; offset < maxRowspan; offset++) {
27663
- const rowToChange = rows[rowIndex + offset];
27664
- if (!rowToChange) continue;
27665
- if (!Array.isArray(rowToChange.content)) rowToChange.content = [];
27666
- if (findCellCoveringColumn(rowToChange, startColumn)?.attrs?.continueMerge) continue;
27667
- const mergedCell = {
27668
- type: cell.type,
27669
- content: [editorSchema.nodes.paragraph.createAndFill().toJSON()],
27670
- attrs: {
27671
- ...cell.attrs,
27672
- rowspan: null,
27673
- continueMerge: true
27674
- }
27675
- };
27676
- const insertionIndex = findInsertionIndexForColumn(rowToChange, startColumn);
27677
- rowToChange.content.splice(insertionIndex, 0, mergedCell);
27678
- }
27679
- }
27680
- }
27681
- return table;
27682
- }
27683
27604
  const translator$39 = NodeTranslator.from({
27684
27605
  xmlName: "w:bidiVisual",
27685
27606
  sdNodeOrKeyName: "rightToLeft",
@@ -27793,7 +27714,94 @@ var propertyTranslators$3 = [
27793
27714
  translator$145
27794
27715
  ];
27795
27716
  const translator$154 = NodeTranslator.from(createNestedPropertiesTranslator("w:tblPr", "tableProperties", propertyTranslators$3));
27796
- const translator$60 = NodeTranslator.from(createSingleAttrPropertyHandler("w:gridCol", "col", "w:w", parseInteger, integerToString));
27717
+ var propertyTranslators$2 = [
27718
+ translator$117,
27719
+ translator$120,
27720
+ translator$154,
27721
+ translator$162,
27722
+ translator$180
27723
+ ];
27724
+ var attributeHandlers$1 = [createAttributeHandler("w:type")];
27725
+ const translator$191 = NodeTranslator.from(createNestedPropertiesTranslator("w:tblStylePr", "tableStyleProperties", propertyTranslators$2, {}, attributeHandlers$1));
27726
+ var getColspan = (cell) => {
27727
+ const rawColspan = cell?.attrs?.colspan;
27728
+ const numericColspan = typeof rawColspan === "string" ? parseInt(rawColspan, 10) : rawColspan;
27729
+ return Number.isFinite(numericColspan) && numericColspan > 0 ? numericColspan : 1;
27730
+ };
27731
+ var resolveGridBefore = (row) => {
27732
+ const rawGridBefore = row?.attrs?.tableRowProperties?.gridBefore ?? row?.attrs?.gridBefore;
27733
+ const numericGridBefore = typeof rawGridBefore === "string" ? parseInt(rawGridBefore, 10) : rawGridBefore;
27734
+ if (!Number.isFinite(numericGridBefore) || numericGridBefore <= 0) return 0;
27735
+ const cells = Array.isArray(row.content) ? row.content : [];
27736
+ let leadingGridBefore = 0;
27737
+ while (leadingGridBefore < cells.length && cells[leadingGridBefore]?.attrs?.__placeholder === "gridBefore") leadingGridBefore += 1;
27738
+ return leadingGridBefore > 0 ? 0 : numericGridBefore;
27739
+ };
27740
+ var advanceColumnsForCell = (columnIndex, cell) => columnIndex + getColspan(cell);
27741
+ var getCellStartColumn = (row, targetCell) => {
27742
+ const cells = Array.isArray(row.content) ? row.content : [];
27743
+ let columnIndex = resolveGridBefore(row);
27744
+ for (const cell of cells) {
27745
+ if (cell === targetCell) return columnIndex;
27746
+ columnIndex = advanceColumnsForCell(columnIndex, cell);
27747
+ }
27748
+ return columnIndex;
27749
+ };
27750
+ var findCellCoveringColumn = (row, targetColumn) => {
27751
+ const cells = Array.isArray(row.content) ? row.content : [];
27752
+ let columnIndex = resolveGridBefore(row);
27753
+ for (const cell of cells) {
27754
+ const colspan = getColspan(cell);
27755
+ if (targetColumn >= columnIndex && targetColumn < columnIndex + colspan) return cell;
27756
+ columnIndex = advanceColumnsForCell(columnIndex, cell);
27757
+ }
27758
+ return null;
27759
+ };
27760
+ var findInsertionIndexForColumn = (row, targetColumn) => {
27761
+ const cells = Array.isArray(row.content) ? row.content : [];
27762
+ let columnIndex = resolveGridBefore(row);
27763
+ for (let index = 0; index < cells.length; index++) {
27764
+ if (columnIndex >= targetColumn) return index;
27765
+ columnIndex = advanceColumnsForCell(columnIndex, cells[index]);
27766
+ }
27767
+ return cells.length;
27768
+ };
27769
+ function preProcessVerticalMergeCells(table, { editorSchema }) {
27770
+ if (!table || !Array.isArray(table.content)) return table;
27771
+ const rows = table.content;
27772
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
27773
+ const row = rows[rowIndex];
27774
+ if (!row) continue;
27775
+ if (!Array.isArray(row.content)) row.content = [];
27776
+ for (let cellIndex = 0; cellIndex < row.content.length; cellIndex++) {
27777
+ const cell = row.content[cellIndex];
27778
+ if (!cell) continue;
27779
+ const attrs = cell.attrs || {};
27780
+ const rawRowspan = typeof attrs.rowspan === "string" ? parseInt(attrs.rowspan, 10) : attrs.rowspan;
27781
+ if (!Number.isFinite(rawRowspan) || rawRowspan <= 1) continue;
27782
+ const maxRowspan = Math.min(rawRowspan, rows.length - rowIndex);
27783
+ const startColumn = getCellStartColumn(row, cell);
27784
+ for (let offset = 1; offset < maxRowspan; offset++) {
27785
+ const rowToChange = rows[rowIndex + offset];
27786
+ if (!rowToChange) continue;
27787
+ if (!Array.isArray(rowToChange.content)) rowToChange.content = [];
27788
+ if (findCellCoveringColumn(rowToChange, startColumn)?.attrs?.continueMerge) continue;
27789
+ const mergedCell = {
27790
+ type: cell.type,
27791
+ content: [editorSchema.nodes.paragraph.createAndFill().toJSON()],
27792
+ attrs: {
27793
+ ...cell.attrs,
27794
+ rowspan: null,
27795
+ continueMerge: true
27796
+ }
27797
+ };
27798
+ const insertionIndex = findInsertionIndexForColumn(rowToChange, startColumn);
27799
+ rowToChange.content.splice(insertionIndex, 0, mergedCell);
27800
+ }
27801
+ }
27802
+ }
27803
+ return table;
27804
+ }
27797
27805
  const normalizeTwipWidth = (value) => {
27798
27806
  if (value == null) return null;
27799
27807
  const numericValue = typeof value === "string" ? parseInt(value, 10) : value;
@@ -27829,6 +27837,56 @@ const resolveFallbackColumnWidthTwips = (params, totalColumns, cellMinWidthTwips
27829
27837
  if (!Number.isFinite(fallbackWidthTwips) || Number.isNaN(fallbackWidthTwips) || fallbackWidthTwips <= 0) return Math.max(pixelsToTwips(safeDefaultPx), cellMinWidthTwips);
27830
27838
  return Math.max(fallbackWidthTwips, cellMinWidthTwips);
27831
27839
  };
27840
+ const DEFAULT_CONTENT_WIDTH_TWIPS = 12240 - 2 * 1440;
27841
+ const MIN_COLUMN_WIDTH_TWIPS = pixelsToTwips(10);
27842
+ const pctToPercent = (value) => {
27843
+ if (value == null) return null;
27844
+ return value / 50;
27845
+ };
27846
+ const resolveContentWidthTwips = () => DEFAULT_CONTENT_WIDTH_TWIPS;
27847
+ const resolveMeasurementWidthPx = (measurement) => {
27848
+ if (!measurement || typeof measurement.value !== "number" || measurement.value <= 0) return null;
27849
+ const { value, type } = measurement;
27850
+ if (!type || type === "auto") return null;
27851
+ if (type === "dxa") return twipsToPixels(value);
27852
+ if (type === "pct") {
27853
+ const percent = pctToPercent(value);
27854
+ if (percent == null || percent <= 0) return null;
27855
+ return twipsToPixels(resolveContentWidthTwips() * percent / 100);
27856
+ }
27857
+ return null;
27858
+ };
27859
+ const countColumnsInRow = (row) => {
27860
+ if (!row?.elements?.length) return 0;
27861
+ return row.elements.reduce((count, element) => {
27862
+ if (element.name !== "w:tc") return count;
27863
+ const gridSpan = (element.elements?.find((el) => el.name === "w:tcPr"))?.elements?.find((el) => el.name === "w:gridSpan");
27864
+ const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
27865
+ return count + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
27866
+ }, 0);
27867
+ };
27868
+ var clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS);
27869
+ var createFallbackGrid = (columnCount, columnWidthTwips) => Array.from({ length: columnCount }, () => ({ col: clampColumnWidthTwips(columnWidthTwips) }));
27870
+ const buildFallbackGridForTable = ({ params, rows, tableWidth, tableWidthMeasurement }) => {
27871
+ const columnCount = countColumnsInRow(rows.find((row) => row.elements?.some((el) => el.name === "w:tc")));
27872
+ if (!columnCount) return null;
27873
+ const schemaDefaultPx = getSchemaDefaultColumnWidthPx(params);
27874
+ const minimumColumnWidthPx = Number.isFinite(schemaDefaultPx) && schemaDefaultPx > 0 ? schemaDefaultPx : 100;
27875
+ let totalWidthPx;
27876
+ if (tableWidthMeasurement) {
27877
+ const resolved = resolveMeasurementWidthPx(tableWidthMeasurement);
27878
+ if (resolved != null) totalWidthPx = resolved;
27879
+ }
27880
+ if (totalWidthPx == null && tableWidth?.width && tableWidth.width > 0) totalWidthPx = tableWidth.width;
27881
+ if (totalWidthPx == null) totalWidthPx = twipsToPixels(DEFAULT_CONTENT_WIDTH_TWIPS);
27882
+ const columnWidthTwips = clampColumnWidthTwips(pixelsToTwips(Math.max(totalWidthPx / columnCount, minimumColumnWidthPx)));
27883
+ const fallbackColumnWidthPx = twipsToPixels(columnWidthTwips);
27884
+ return {
27885
+ grid: createFallbackGrid(columnCount, columnWidthTwips),
27886
+ columnWidths: Array(columnCount).fill(fallbackColumnWidthPx)
27887
+ };
27888
+ };
27889
+ const translator$60 = NodeTranslator.from(createSingleAttrPropertyHandler("w:gridCol", "col", "w:w", parseInteger, integerToString));
27832
27890
  var XML_NODE_NAME$16 = "w:tblGrid";
27833
27891
  var SD_ATTR_KEY$1 = "grid";
27834
27892
  var cellMinWidth = pixelsToTwips(10);
@@ -27907,64 +27965,6 @@ var config$15 = {
27907
27965
  decode: decode$33
27908
27966
  };
27909
27967
  const translator$148 = NodeTranslator.from(config$15);
27910
- var propertyTranslators$2 = [
27911
- translator$117,
27912
- translator$120,
27913
- translator$154,
27914
- translator$162,
27915
- translator$180
27916
- ];
27917
- var attributeHandlers$1 = [createAttributeHandler("w:type")];
27918
- const translator$191 = NodeTranslator.from(createNestedPropertiesTranslator("w:tblStylePr", "tableStyleProperties", propertyTranslators$2, {}, attributeHandlers$1));
27919
- const DEFAULT_CONTENT_WIDTH_TWIPS = 12240 - 2 * 1440;
27920
- const MIN_COLUMN_WIDTH_TWIPS = pixelsToTwips(10);
27921
- const pctToPercent = (value) => {
27922
- if (value == null) return null;
27923
- return value / 50;
27924
- };
27925
- const resolveContentWidthTwips = () => DEFAULT_CONTENT_WIDTH_TWIPS;
27926
- const resolveMeasurementWidthPx = (measurement) => {
27927
- if (!measurement || typeof measurement.value !== "number" || measurement.value <= 0) return null;
27928
- const { value, type } = measurement;
27929
- if (!type || type === "auto") return null;
27930
- if (type === "dxa") return twipsToPixels(value);
27931
- if (type === "pct") {
27932
- const percent = pctToPercent(value);
27933
- if (percent == null || percent <= 0) return null;
27934
- return twipsToPixels(resolveContentWidthTwips() * percent / 100);
27935
- }
27936
- return null;
27937
- };
27938
- const countColumnsInRow = (row) => {
27939
- if (!row?.elements?.length) return 0;
27940
- return row.elements.reduce((count, element) => {
27941
- if (element.name !== "w:tc") return count;
27942
- const gridSpan = (element.elements?.find((el) => el.name === "w:tcPr"))?.elements?.find((el) => el.name === "w:gridSpan");
27943
- const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
27944
- return count + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
27945
- }, 0);
27946
- };
27947
- var clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS);
27948
- var createFallbackGrid = (columnCount, columnWidthTwips) => Array.from({ length: columnCount }, () => ({ col: clampColumnWidthTwips(columnWidthTwips) }));
27949
- const buildFallbackGridForTable = ({ params, rows, tableWidth, tableWidthMeasurement }) => {
27950
- const columnCount = countColumnsInRow(rows.find((row) => row.elements?.some((el) => el.name === "w:tc")));
27951
- if (!columnCount) return null;
27952
- const schemaDefaultPx = getSchemaDefaultColumnWidthPx(params);
27953
- const minimumColumnWidthPx = Number.isFinite(schemaDefaultPx) && schemaDefaultPx > 0 ? schemaDefaultPx : 100;
27954
- let totalWidthPx;
27955
- if (tableWidthMeasurement) {
27956
- const resolved = resolveMeasurementWidthPx(tableWidthMeasurement);
27957
- if (resolved != null) totalWidthPx = resolved;
27958
- }
27959
- if (totalWidthPx == null && tableWidth?.width && tableWidth.width > 0) totalWidthPx = tableWidth.width;
27960
- if (totalWidthPx == null) totalWidthPx = minimumColumnWidthPx * columnCount;
27961
- const columnWidthTwips = clampColumnWidthTwips(pixelsToTwips(Math.max(totalWidthPx / columnCount, minimumColumnWidthPx)));
27962
- const fallbackColumnWidthPx = twipsToPixels(columnWidthTwips);
27963
- return {
27964
- grid: createFallbackGrid(columnCount, columnWidthTwips),
27965
- columnWidths: Array(columnCount).fill(fallbackColumnWidthPx)
27966
- };
27967
- };
27968
27968
  var XML_NODE_NAME$15 = "w:tbl";
27969
27969
  var SD_NODE_NAME$14 = "table";
27970
27970
  var INDENT_TWIPS_TOLERANCE = 5;
@@ -28062,7 +28062,7 @@ var encode$30 = (params, encodedAttrs) => {
28062
28062
  const rowTcWTwipsTotal = hasExplicitGrid && hasIndent ? getFirstRowCellWidthSumTwips(rows) : null;
28063
28063
  const indentDiff = rowTcWTwipsTotal != null && gridTwipsTotal != null ? rowTcWTwipsTotal - gridTwipsTotal : null;
28064
28064
  const preferTableGridWidths = hasExplicitGrid && hasIndent && gridTwipsTotal != null && rowTcWTwipsTotal != null && Math.sign(indentDiff) === Math.sign(tableIndentTwips) && Math.abs(indentDiff - tableIndentTwips) <= INDENT_TWIPS_TOLERANCE;
28065
- if (!columnWidths.length) {
28065
+ if (!(columnWidths.length > 0 && columnWidths.some((w$1) => w$1 > 0))) {
28066
28066
  const fallback = buildFallbackGridForTable({
28067
28067
  params,
28068
28068
  rows,
@@ -28073,6 +28073,11 @@ var encode$30 = (params, encodedAttrs) => {
28073
28073
  encodedAttrs.grid = fallback.grid;
28074
28074
  columnWidths = fallback.columnWidths;
28075
28075
  }
28076
+ const tw = encodedAttrs.tableWidth;
28077
+ if (!(tw && tw.type !== "auto" && (tw.width > 0 || tw.value > 0))) encodedAttrs.tableWidth = {
28078
+ value: 5e3,
28079
+ type: "pct"
28080
+ };
28076
28081
  }
28077
28082
  const content = [];
28078
28083
  const totalColumns = columnWidths.length;
@@ -33819,7 +33824,7 @@ var SuperConverter = class SuperConverter {
33819
33824
  static getStoredSuperdocVersion(docx) {
33820
33825
  return SuperConverter.getStoredCustomProperty(docx, "SuperdocVersion");
33821
33826
  }
33822
- static setStoredSuperdocVersion(docx = this.convertedXml, version = "1.17.0-next.2") {
33827
+ static setStoredSuperdocVersion(docx = this.convertedXml, version = "1.17.0-next.4") {
33823
33828
  return SuperConverter.setStoredCustomProperty(docx, "SuperdocVersion", version, false);
33824
33829
  }
33825
33830
  static generateWordTimestamp() {
@@ -27608,85 +27608,6 @@ const config$16 = {
27608
27608
  attributes: validXmlAttributes$3
27609
27609
  };
27610
27610
  const translator$7 = NodeTranslator.from(config$16);
27611
- var getColspan = (cell) => {
27612
- const rawColspan = cell?.attrs?.colspan;
27613
- const numericColspan = typeof rawColspan === "string" ? parseInt(rawColspan, 10) : rawColspan;
27614
- return Number.isFinite(numericColspan) && numericColspan > 0 ? numericColspan : 1;
27615
- };
27616
- var resolveGridBefore = (row) => {
27617
- const rawGridBefore = row?.attrs?.tableRowProperties?.gridBefore ?? row?.attrs?.gridBefore;
27618
- const numericGridBefore = typeof rawGridBefore === "string" ? parseInt(rawGridBefore, 10) : rawGridBefore;
27619
- if (!Number.isFinite(numericGridBefore) || numericGridBefore <= 0) return 0;
27620
- const cells = Array.isArray(row.content) ? row.content : [];
27621
- let leadingGridBefore = 0;
27622
- while (leadingGridBefore < cells.length && cells[leadingGridBefore]?.attrs?.__placeholder === "gridBefore") leadingGridBefore += 1;
27623
- return leadingGridBefore > 0 ? 0 : numericGridBefore;
27624
- };
27625
- var advanceColumnsForCell = (columnIndex, cell) => columnIndex + getColspan(cell);
27626
- var getCellStartColumn = (row, targetCell) => {
27627
- const cells = Array.isArray(row.content) ? row.content : [];
27628
- let columnIndex = resolveGridBefore(row);
27629
- for (const cell of cells) {
27630
- if (cell === targetCell) return columnIndex;
27631
- columnIndex = advanceColumnsForCell(columnIndex, cell);
27632
- }
27633
- return columnIndex;
27634
- };
27635
- var findCellCoveringColumn = (row, targetColumn) => {
27636
- const cells = Array.isArray(row.content) ? row.content : [];
27637
- let columnIndex = resolveGridBefore(row);
27638
- for (const cell of cells) {
27639
- const colspan = getColspan(cell);
27640
- if (targetColumn >= columnIndex && targetColumn < columnIndex + colspan) return cell;
27641
- columnIndex = advanceColumnsForCell(columnIndex, cell);
27642
- }
27643
- return null;
27644
- };
27645
- var findInsertionIndexForColumn = (row, targetColumn) => {
27646
- const cells = Array.isArray(row.content) ? row.content : [];
27647
- let columnIndex = resolveGridBefore(row);
27648
- for (let index = 0; index < cells.length; index++) {
27649
- if (columnIndex >= targetColumn) return index;
27650
- columnIndex = advanceColumnsForCell(columnIndex, cells[index]);
27651
- }
27652
- return cells.length;
27653
- };
27654
- function preProcessVerticalMergeCells(table, { editorSchema }) {
27655
- if (!table || !Array.isArray(table.content)) return table;
27656
- const rows = table.content;
27657
- for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
27658
- const row = rows[rowIndex];
27659
- if (!row) continue;
27660
- if (!Array.isArray(row.content)) row.content = [];
27661
- for (let cellIndex = 0; cellIndex < row.content.length; cellIndex++) {
27662
- const cell = row.content[cellIndex];
27663
- if (!cell) continue;
27664
- const attrs = cell.attrs || {};
27665
- const rawRowspan = typeof attrs.rowspan === "string" ? parseInt(attrs.rowspan, 10) : attrs.rowspan;
27666
- if (!Number.isFinite(rawRowspan) || rawRowspan <= 1) continue;
27667
- const maxRowspan = Math.min(rawRowspan, rows.length - rowIndex);
27668
- const startColumn = getCellStartColumn(row, cell);
27669
- for (let offset = 1; offset < maxRowspan; offset++) {
27670
- const rowToChange = rows[rowIndex + offset];
27671
- if (!rowToChange) continue;
27672
- if (!Array.isArray(rowToChange.content)) rowToChange.content = [];
27673
- if (findCellCoveringColumn(rowToChange, startColumn)?.attrs?.continueMerge) continue;
27674
- const mergedCell = {
27675
- type: cell.type,
27676
- content: [editorSchema.nodes.paragraph.createAndFill().toJSON()],
27677
- attrs: {
27678
- ...cell.attrs,
27679
- rowspan: null,
27680
- continueMerge: true
27681
- }
27682
- };
27683
- const insertionIndex = findInsertionIndexForColumn(rowToChange, startColumn);
27684
- rowToChange.content.splice(insertionIndex, 0, mergedCell);
27685
- }
27686
- }
27687
- }
27688
- return table;
27689
- }
27690
27611
  const translator$39 = NodeTranslator.from({
27691
27612
  xmlName: "w:bidiVisual",
27692
27613
  sdNodeOrKeyName: "rightToLeft",
@@ -27800,7 +27721,94 @@ var propertyTranslators$3 = [
27800
27721
  translator$145
27801
27722
  ];
27802
27723
  const translator$154 = NodeTranslator.from(createNestedPropertiesTranslator("w:tblPr", "tableProperties", propertyTranslators$3));
27803
- const translator$60 = NodeTranslator.from(createSingleAttrPropertyHandler("w:gridCol", "col", "w:w", parseInteger, integerToString));
27724
+ var propertyTranslators$2 = [
27725
+ translator$117,
27726
+ translator$120,
27727
+ translator$154,
27728
+ translator$162,
27729
+ translator$180
27730
+ ];
27731
+ var attributeHandlers$1 = [createAttributeHandler("w:type")];
27732
+ const translator$191 = NodeTranslator.from(createNestedPropertiesTranslator("w:tblStylePr", "tableStyleProperties", propertyTranslators$2, {}, attributeHandlers$1));
27733
+ var getColspan = (cell) => {
27734
+ const rawColspan = cell?.attrs?.colspan;
27735
+ const numericColspan = typeof rawColspan === "string" ? parseInt(rawColspan, 10) : rawColspan;
27736
+ return Number.isFinite(numericColspan) && numericColspan > 0 ? numericColspan : 1;
27737
+ };
27738
+ var resolveGridBefore = (row) => {
27739
+ const rawGridBefore = row?.attrs?.tableRowProperties?.gridBefore ?? row?.attrs?.gridBefore;
27740
+ const numericGridBefore = typeof rawGridBefore === "string" ? parseInt(rawGridBefore, 10) : rawGridBefore;
27741
+ if (!Number.isFinite(numericGridBefore) || numericGridBefore <= 0) return 0;
27742
+ const cells = Array.isArray(row.content) ? row.content : [];
27743
+ let leadingGridBefore = 0;
27744
+ while (leadingGridBefore < cells.length && cells[leadingGridBefore]?.attrs?.__placeholder === "gridBefore") leadingGridBefore += 1;
27745
+ return leadingGridBefore > 0 ? 0 : numericGridBefore;
27746
+ };
27747
+ var advanceColumnsForCell = (columnIndex, cell) => columnIndex + getColspan(cell);
27748
+ var getCellStartColumn = (row, targetCell) => {
27749
+ const cells = Array.isArray(row.content) ? row.content : [];
27750
+ let columnIndex = resolveGridBefore(row);
27751
+ for (const cell of cells) {
27752
+ if (cell === targetCell) return columnIndex;
27753
+ columnIndex = advanceColumnsForCell(columnIndex, cell);
27754
+ }
27755
+ return columnIndex;
27756
+ };
27757
+ var findCellCoveringColumn = (row, targetColumn) => {
27758
+ const cells = Array.isArray(row.content) ? row.content : [];
27759
+ let columnIndex = resolveGridBefore(row);
27760
+ for (const cell of cells) {
27761
+ const colspan = getColspan(cell);
27762
+ if (targetColumn >= columnIndex && targetColumn < columnIndex + colspan) return cell;
27763
+ columnIndex = advanceColumnsForCell(columnIndex, cell);
27764
+ }
27765
+ return null;
27766
+ };
27767
+ var findInsertionIndexForColumn = (row, targetColumn) => {
27768
+ const cells = Array.isArray(row.content) ? row.content : [];
27769
+ let columnIndex = resolveGridBefore(row);
27770
+ for (let index = 0; index < cells.length; index++) {
27771
+ if (columnIndex >= targetColumn) return index;
27772
+ columnIndex = advanceColumnsForCell(columnIndex, cells[index]);
27773
+ }
27774
+ return cells.length;
27775
+ };
27776
+ function preProcessVerticalMergeCells(table, { editorSchema }) {
27777
+ if (!table || !Array.isArray(table.content)) return table;
27778
+ const rows = table.content;
27779
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
27780
+ const row = rows[rowIndex];
27781
+ if (!row) continue;
27782
+ if (!Array.isArray(row.content)) row.content = [];
27783
+ for (let cellIndex = 0; cellIndex < row.content.length; cellIndex++) {
27784
+ const cell = row.content[cellIndex];
27785
+ if (!cell) continue;
27786
+ const attrs = cell.attrs || {};
27787
+ const rawRowspan = typeof attrs.rowspan === "string" ? parseInt(attrs.rowspan, 10) : attrs.rowspan;
27788
+ if (!Number.isFinite(rawRowspan) || rawRowspan <= 1) continue;
27789
+ const maxRowspan = Math.min(rawRowspan, rows.length - rowIndex);
27790
+ const startColumn = getCellStartColumn(row, cell);
27791
+ for (let offset = 1; offset < maxRowspan; offset++) {
27792
+ const rowToChange = rows[rowIndex + offset];
27793
+ if (!rowToChange) continue;
27794
+ if (!Array.isArray(rowToChange.content)) rowToChange.content = [];
27795
+ if (findCellCoveringColumn(rowToChange, startColumn)?.attrs?.continueMerge) continue;
27796
+ const mergedCell = {
27797
+ type: cell.type,
27798
+ content: [editorSchema.nodes.paragraph.createAndFill().toJSON()],
27799
+ attrs: {
27800
+ ...cell.attrs,
27801
+ rowspan: null,
27802
+ continueMerge: true
27803
+ }
27804
+ };
27805
+ const insertionIndex = findInsertionIndexForColumn(rowToChange, startColumn);
27806
+ rowToChange.content.splice(insertionIndex, 0, mergedCell);
27807
+ }
27808
+ }
27809
+ }
27810
+ return table;
27811
+ }
27804
27812
  const DEFAULT_COLUMN_WIDTH_PX = 100;
27805
27813
  const normalizeTwipWidth = (value) => {
27806
27814
  if (value == null) return null;
@@ -27837,6 +27845,58 @@ const resolveFallbackColumnWidthTwips = (params, totalColumns, cellMinWidthTwips
27837
27845
  if (!Number.isFinite(fallbackWidthTwips) || Number.isNaN(fallbackWidthTwips) || fallbackWidthTwips <= 0) return Math.max(require_constants.pixelsToTwips(safeDefaultPx), cellMinWidthTwips);
27838
27846
  return Math.max(fallbackWidthTwips, cellMinWidthTwips);
27839
27847
  };
27848
+ const DEFAULT_PAGE_WIDTH_TWIPS = 12240;
27849
+ const DEFAULT_PAGE_MARGIN_TWIPS = 1440;
27850
+ const DEFAULT_CONTENT_WIDTH_TWIPS = DEFAULT_PAGE_WIDTH_TWIPS - 2 * DEFAULT_PAGE_MARGIN_TWIPS;
27851
+ const MIN_COLUMN_WIDTH_TWIPS = require_constants.pixelsToTwips(10);
27852
+ const pctToPercent = (value) => {
27853
+ if (value == null) return null;
27854
+ return value / 50;
27855
+ };
27856
+ const resolveContentWidthTwips = () => DEFAULT_CONTENT_WIDTH_TWIPS;
27857
+ const resolveMeasurementWidthPx = (measurement) => {
27858
+ if (!measurement || typeof measurement.value !== "number" || measurement.value <= 0) return null;
27859
+ const { value, type } = measurement;
27860
+ if (!type || type === "auto") return null;
27861
+ if (type === "dxa") return require_constants.twipsToPixels(value);
27862
+ if (type === "pct") {
27863
+ const percent = pctToPercent(value);
27864
+ if (percent == null || percent <= 0) return null;
27865
+ return require_constants.twipsToPixels(resolveContentWidthTwips() * percent / 100);
27866
+ }
27867
+ return null;
27868
+ };
27869
+ const countColumnsInRow = (row) => {
27870
+ if (!row?.elements?.length) return 0;
27871
+ return row.elements.reduce((count, element) => {
27872
+ if (element.name !== "w:tc") return count;
27873
+ const gridSpan = (element.elements?.find((el) => el.name === "w:tcPr"))?.elements?.find((el) => el.name === "w:gridSpan");
27874
+ const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
27875
+ return count + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
27876
+ }, 0);
27877
+ };
27878
+ var clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS);
27879
+ var createFallbackGrid = (columnCount, columnWidthTwips) => Array.from({ length: columnCount }, () => ({ col: clampColumnWidthTwips(columnWidthTwips) }));
27880
+ const buildFallbackGridForTable = ({ params, rows, tableWidth, tableWidthMeasurement }) => {
27881
+ const columnCount = countColumnsInRow(rows.find((row) => row.elements?.some((el) => el.name === "w:tc")));
27882
+ if (!columnCount) return null;
27883
+ const schemaDefaultPx = getSchemaDefaultColumnWidthPx(params);
27884
+ const minimumColumnWidthPx = Number.isFinite(schemaDefaultPx) && schemaDefaultPx > 0 ? schemaDefaultPx : 100;
27885
+ let totalWidthPx;
27886
+ if (tableWidthMeasurement) {
27887
+ const resolved = resolveMeasurementWidthPx(tableWidthMeasurement);
27888
+ if (resolved != null) totalWidthPx = resolved;
27889
+ }
27890
+ if (totalWidthPx == null && tableWidth?.width && tableWidth.width > 0) totalWidthPx = tableWidth.width;
27891
+ if (totalWidthPx == null) totalWidthPx = require_constants.twipsToPixels(DEFAULT_CONTENT_WIDTH_TWIPS);
27892
+ const columnWidthTwips = clampColumnWidthTwips(require_constants.pixelsToTwips(Math.max(totalWidthPx / columnCount, minimumColumnWidthPx)));
27893
+ const fallbackColumnWidthPx = require_constants.twipsToPixels(columnWidthTwips);
27894
+ return {
27895
+ grid: createFallbackGrid(columnCount, columnWidthTwips),
27896
+ columnWidths: Array(columnCount).fill(fallbackColumnWidthPx)
27897
+ };
27898
+ };
27899
+ const translator$60 = NodeTranslator.from(createSingleAttrPropertyHandler("w:gridCol", "col", "w:w", parseInteger, integerToString));
27840
27900
  var XML_NODE_NAME$16 = "w:tblGrid";
27841
27901
  var SD_ATTR_KEY$1 = "grid";
27842
27902
  var cellMinWidth = require_constants.pixelsToTwips(10);
@@ -27915,66 +27975,6 @@ var config$15 = {
27915
27975
  decode: decode$33
27916
27976
  };
27917
27977
  const translator$148 = NodeTranslator.from(config$15);
27918
- var propertyTranslators$2 = [
27919
- translator$117,
27920
- translator$120,
27921
- translator$154,
27922
- translator$162,
27923
- translator$180
27924
- ];
27925
- var attributeHandlers$1 = [createAttributeHandler("w:type")];
27926
- const translator$191 = NodeTranslator.from(createNestedPropertiesTranslator("w:tblStylePr", "tableStyleProperties", propertyTranslators$2, {}, attributeHandlers$1));
27927
- const DEFAULT_PAGE_WIDTH_TWIPS = 12240;
27928
- const DEFAULT_PAGE_MARGIN_TWIPS = 1440;
27929
- const DEFAULT_CONTENT_WIDTH_TWIPS = DEFAULT_PAGE_WIDTH_TWIPS - 2 * DEFAULT_PAGE_MARGIN_TWIPS;
27930
- const MIN_COLUMN_WIDTH_TWIPS = require_constants.pixelsToTwips(10);
27931
- const pctToPercent = (value) => {
27932
- if (value == null) return null;
27933
- return value / 50;
27934
- };
27935
- const resolveContentWidthTwips = () => DEFAULT_CONTENT_WIDTH_TWIPS;
27936
- const resolveMeasurementWidthPx = (measurement) => {
27937
- if (!measurement || typeof measurement.value !== "number" || measurement.value <= 0) return null;
27938
- const { value, type } = measurement;
27939
- if (!type || type === "auto") return null;
27940
- if (type === "dxa") return require_constants.twipsToPixels(value);
27941
- if (type === "pct") {
27942
- const percent = pctToPercent(value);
27943
- if (percent == null || percent <= 0) return null;
27944
- return require_constants.twipsToPixels(resolveContentWidthTwips() * percent / 100);
27945
- }
27946
- return null;
27947
- };
27948
- const countColumnsInRow = (row) => {
27949
- if (!row?.elements?.length) return 0;
27950
- return row.elements.reduce((count, element) => {
27951
- if (element.name !== "w:tc") return count;
27952
- const gridSpan = (element.elements?.find((el) => el.name === "w:tcPr"))?.elements?.find((el) => el.name === "w:gridSpan");
27953
- const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
27954
- return count + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
27955
- }, 0);
27956
- };
27957
- var clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS);
27958
- var createFallbackGrid = (columnCount, columnWidthTwips) => Array.from({ length: columnCount }, () => ({ col: clampColumnWidthTwips(columnWidthTwips) }));
27959
- const buildFallbackGridForTable = ({ params, rows, tableWidth, tableWidthMeasurement }) => {
27960
- const columnCount = countColumnsInRow(rows.find((row) => row.elements?.some((el) => el.name === "w:tc")));
27961
- if (!columnCount) return null;
27962
- const schemaDefaultPx = getSchemaDefaultColumnWidthPx(params);
27963
- const minimumColumnWidthPx = Number.isFinite(schemaDefaultPx) && schemaDefaultPx > 0 ? schemaDefaultPx : 100;
27964
- let totalWidthPx;
27965
- if (tableWidthMeasurement) {
27966
- const resolved = resolveMeasurementWidthPx(tableWidthMeasurement);
27967
- if (resolved != null) totalWidthPx = resolved;
27968
- }
27969
- if (totalWidthPx == null && tableWidth?.width && tableWidth.width > 0) totalWidthPx = tableWidth.width;
27970
- if (totalWidthPx == null) totalWidthPx = minimumColumnWidthPx * columnCount;
27971
- const columnWidthTwips = clampColumnWidthTwips(require_constants.pixelsToTwips(Math.max(totalWidthPx / columnCount, minimumColumnWidthPx)));
27972
- const fallbackColumnWidthPx = require_constants.twipsToPixels(columnWidthTwips);
27973
- return {
27974
- grid: createFallbackGrid(columnCount, columnWidthTwips),
27975
- columnWidths: Array(columnCount).fill(fallbackColumnWidthPx)
27976
- };
27977
- };
27978
27978
  var XML_NODE_NAME$15 = "w:tbl";
27979
27979
  var SD_NODE_NAME$14 = "table";
27980
27980
  var INDENT_TWIPS_TOLERANCE = 5;
@@ -28072,7 +28072,7 @@ var encode$30 = (params, encodedAttrs) => {
28072
28072
  const rowTcWTwipsTotal = hasExplicitGrid && hasIndent ? getFirstRowCellWidthSumTwips(rows) : null;
28073
28073
  const indentDiff = rowTcWTwipsTotal != null && gridTwipsTotal != null ? rowTcWTwipsTotal - gridTwipsTotal : null;
28074
28074
  const preferTableGridWidths = hasExplicitGrid && hasIndent && gridTwipsTotal != null && rowTcWTwipsTotal != null && Math.sign(indentDiff) === Math.sign(tableIndentTwips) && Math.abs(indentDiff - tableIndentTwips) <= INDENT_TWIPS_TOLERANCE;
28075
- if (!columnWidths.length) {
28075
+ if (!(columnWidths.length > 0 && columnWidths.some((w$1) => w$1 > 0))) {
28076
28076
  const fallback = buildFallbackGridForTable({
28077
28077
  params,
28078
28078
  rows,
@@ -28083,6 +28083,11 @@ var encode$30 = (params, encodedAttrs) => {
28083
28083
  encodedAttrs.grid = fallback.grid;
28084
28084
  columnWidths = fallback.columnWidths;
28085
28085
  }
28086
+ const tw = encodedAttrs.tableWidth;
28087
+ if (!(tw && tw.type !== "auto" && (tw.width > 0 || tw.value > 0))) encodedAttrs.tableWidth = {
28088
+ value: 5e3,
28089
+ type: "pct"
28090
+ };
28086
28091
  }
28087
28092
  const content = [];
28088
28093
  const totalColumns = columnWidths.length;
@@ -33833,7 +33838,7 @@ var SuperConverter = class SuperConverter {
33833
33838
  static getStoredSuperdocVersion(docx) {
33834
33839
  return SuperConverter.getStoredCustomProperty(docx, "SuperdocVersion");
33835
33840
  }
33836
- static setStoredSuperdocVersion(docx = this.convertedXml, version = "1.17.0-next.2") {
33841
+ static setStoredSuperdocVersion(docx = this.convertedXml, version = "1.17.0-next.4") {
33837
33842
  return SuperConverter.setStoredCustomProperty(docx, "SuperdocVersion", version, false);
33838
33843
  }
33839
33844
  static generateWordTimestamp() {