@superdoc-dev/cli 0.8.0-next.35 → 0.8.0-next.36

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 (2) hide show
  1. package/dist/index.js +1802 -254
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -65806,7 +65806,7 @@ var init_remark_gfm_BhnWr3yf_es = __esm(() => {
65806
65806
  emptyOptions2 = {};
65807
65807
  });
65808
65808
 
65809
- // ../../packages/superdoc/dist/chunks/SuperConverter-BTy5lByv.es.js
65809
+ // ../../packages/superdoc/dist/chunks/SuperConverter-Dchjy0My.es.js
65810
65810
  function getExtensionConfigField(extension$1, field, context = { name: "" }) {
65811
65811
  const fieldValue = extension$1.config[field];
65812
65812
  if (typeof fieldValue === "function")
@@ -114303,18 +114303,78 @@ var isRegExp = (value) => {
114303
114303
  return twipsToPixels(resolveContentWidthTwips() * percent / 100);
114304
114304
  }
114305
114305
  return null;
114306
+ }, getRawRowGridMetadata = (row) => {
114307
+ const trPr = row?.elements?.find((element) => element.name === "w:trPr");
114308
+ const getChild = (name) => trPr?.elements?.find((element) => element.name === name);
114309
+ const parseCount = (name) => {
114310
+ const rawValue = getChild(name)?.attributes?.["w:val"];
114311
+ const value = typeof rawValue === "number" ? rawValue : Number.parseInt(rawValue || "0", 10);
114312
+ return Number.isFinite(value) && value > 0 ? value : 0;
114313
+ };
114314
+ const parseMeasurement = (name) => {
114315
+ const node3 = getChild(name);
114316
+ if (!node3?.attributes)
114317
+ return null;
114318
+ const rawValue = node3.attributes["w:w"];
114319
+ const value = typeof rawValue === "number" ? rawValue : Number.parseInt(rawValue || "", 10);
114320
+ if (!Number.isFinite(value) || value <= 0)
114321
+ return null;
114322
+ return {
114323
+ value,
114324
+ type: node3.attributes["w:type"] || "dxa"
114325
+ };
114326
+ };
114327
+ return {
114328
+ gridBefore: parseCount("w:gridBefore"),
114329
+ gridAfter: parseCount("w:gridAfter"),
114330
+ wBefore: parseMeasurement("w:wBefore"),
114331
+ wAfter: parseMeasurement("w:wAfter")
114332
+ };
114306
114333
  }, countColumnsInRow = (row) => {
114307
114334
  if (!row?.elements?.length)
114308
114335
  return 0;
114309
- return row.elements.reduce((count2, element) => {
114336
+ const { gridBefore, gridAfter } = getRawRowGridMetadata(row);
114337
+ return gridBefore + row.elements.reduce((count2, element) => {
114310
114338
  if (element.name !== "w:tc")
114311
114339
  return count2;
114312
114340
  const gridSpan = element.elements?.find((el) => el.name === "w:tcPr")?.elements?.find((el) => el.name === "w:gridSpan");
114313
114341
  const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
114314
114342
  return count2 + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
114315
- }, 0);
114316
- }, clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS), createFallbackGrid = (columnCount, columnWidthTwips) => Array.from({ length: columnCount }, () => ({ col: clampColumnWidthTwips(columnWidthTwips) })), buildFallbackGridForTable = ({ params: params3, rows, tableWidth, tableWidthMeasurement }) => {
114317
- const columnCount = countColumnsInRow(rows.find((row) => row.elements?.some((el) => el.name === "w:tc")));
114343
+ }, 0) + gridAfter;
114344
+ }, clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS), resolveSkippedColumnSeedWidthsTwips = (measurement, span) => {
114345
+ if (!measurement || !Number.isFinite(span) || span <= 0)
114346
+ return [];
114347
+ const resolvedPx = resolveMeasurementWidthPx(measurement);
114348
+ if (resolvedPx == null || resolvedPx <= 0)
114349
+ return [];
114350
+ const totalTwips = clampColumnWidthTwips(pixelsToTwips(resolvedPx));
114351
+ const baseWidth = Math.floor(totalTwips / span);
114352
+ const remainder = totalTwips - baseWidth * span;
114353
+ return Array.from({ length: span }, (_, index2) => clampColumnWidthTwips(baseWidth + (index2 < remainder ? 1 : 0)));
114354
+ }, buildFallbackColumnWidthTwips = ({ columnCount, totalWidthTwips, rows }) => {
114355
+ const seededWidths = new Array(columnCount).fill(null);
114356
+ for (const row of rows) {
114357
+ const { gridBefore, gridAfter, wBefore, wAfter } = getRawRowGridMetadata(row);
114358
+ if (gridBefore > 0)
114359
+ resolveSkippedColumnSeedWidthsTwips(wBefore, gridBefore).forEach((widthTwips, index2) => {
114360
+ if (index2 < columnCount)
114361
+ seededWidths[index2] = Math.max(seededWidths[index2] ?? 0, widthTwips);
114362
+ });
114363
+ if (gridAfter > 0)
114364
+ resolveSkippedColumnSeedWidthsTwips(wAfter, gridAfter).forEach((widthTwips, index2) => {
114365
+ const targetIndex = columnCount - gridAfter + index2;
114366
+ if (targetIndex >= 0 && targetIndex < columnCount)
114367
+ seededWidths[targetIndex] = Math.max(seededWidths[targetIndex] ?? 0, widthTwips);
114368
+ });
114369
+ }
114370
+ const seededTotalTwips = seededWidths.reduce((sum, widthTwips) => sum + (widthTwips ?? 0), 0);
114371
+ const remainingColumns = seededWidths.filter((widthTwips) => widthTwips == null).length;
114372
+ const minimumRemainingTwips = remainingColumns * MIN_COLUMN_WIDTH_TWIPS;
114373
+ const effectiveTotalTwips = Math.max(totalWidthTwips, seededTotalTwips + minimumRemainingTwips);
114374
+ const defaultRemainingTwips = remainingColumns > 0 ? clampColumnWidthTwips((effectiveTotalTwips - seededTotalTwips) / remainingColumns) : 0;
114375
+ return seededWidths.map((widthTwips) => clampColumnWidthTwips(widthTwips ?? defaultRemainingTwips));
114376
+ }, buildFallbackGridForTable = ({ params: params3, rows, tableWidth, tableWidthMeasurement }) => {
114377
+ const columnCount = rows.reduce((max4, row) => Math.max(max4, countColumnsInRow(row)), 0);
114318
114378
  if (!columnCount)
114319
114379
  return null;
114320
114380
  const schemaDefaultPx = getSchemaDefaultColumnWidthPx(params3);
@@ -114329,11 +114389,15 @@ var isRegExp = (value) => {
114329
114389
  totalWidthPx = tableWidth.width;
114330
114390
  if (totalWidthPx == null)
114331
114391
  totalWidthPx = twipsToPixels(DEFAULT_CONTENT_WIDTH_TWIPS);
114332
- const columnWidthTwips = clampColumnWidthTwips(pixelsToTwips(Math.max(totalWidthPx / columnCount, minimumColumnWidthPx)));
114333
- const fallbackColumnWidthPx = twipsToPixels(columnWidthTwips);
114392
+ const minimumColumnWidthTwips = clampColumnWidthTwips(pixelsToTwips(minimumColumnWidthPx));
114393
+ const fallbackColumnWidthTwips = buildFallbackColumnWidthTwips({
114394
+ columnCount,
114395
+ totalWidthTwips: Math.max(clampColumnWidthTwips(pixelsToTwips(totalWidthPx)), minimumColumnWidthTwips * columnCount),
114396
+ rows
114397
+ });
114334
114398
  return {
114335
- grid: createFallbackGrid(columnCount, columnWidthTwips),
114336
- columnWidths: Array(columnCount).fill(fallbackColumnWidthPx)
114399
+ grid: fallbackColumnWidthTwips.map((columnWidthTwips) => ({ col: clampColumnWidthTwips(columnWidthTwips) })),
114400
+ columnWidths: fallbackColumnWidthTwips.map((columnWidthTwips) => twipsToPixels(columnWidthTwips))
114337
114401
  };
114338
114402
  }, translator$69, XML_NODE_NAME$26 = "w:tblGrid", SD_ATTR_KEY$2 = "grid", cellMinWidth, encode$43 = (params3) => {
114339
114403
  const { nodes } = params3;
@@ -118203,7 +118267,7 @@ var isRegExp = (value) => {
118203
118267
  state.kern = kernNode.attributes["w:val"];
118204
118268
  }
118205
118269
  }, SuperConverter;
118206
- var init_SuperConverter_BTy5lByv_es = __esm(() => {
118270
+ var init_SuperConverter_Dchjy0My_es = __esm(() => {
118207
118271
  init_rolldown_runtime_Bg48TavK_es();
118208
118272
  init_jszip_C49i9kUs_es();
118209
118273
  init_xml_js_CqGKpaft_es();
@@ -155798,7 +155862,7 @@ var init_SuperConverter_BTy5lByv_es = __esm(() => {
155798
155862
  };
155799
155863
  });
155800
155864
 
155801
- // ../../packages/superdoc/dist/chunks/create-headless-toolbar-k6nNYL53.es.js
155865
+ // ../../packages/superdoc/dist/chunks/create-headless-toolbar-CEcVKzGV.es.js
155802
155866
  function parseSizeUnit(val = "0") {
155803
155867
  const length3 = val.toString() || "0";
155804
155868
  const value = Number.parseFloat(length3);
@@ -158434,8 +158498,8 @@ var CSS_DIMENSION_REGEX, DOM_SIZE_UNITS, Extension = class Extension2 {
158434
158498
  }
158435
158499
  };
158436
158500
  };
158437
- var init_create_headless_toolbar_k6nNYL53_es = __esm(() => {
158438
- init_SuperConverter_BTy5lByv_es();
158501
+ var init_create_headless_toolbar_CEcVKzGV_es = __esm(() => {
158502
+ init_SuperConverter_Dchjy0My_es();
158439
158503
  init_constants_DrU4EASo_es();
158440
158504
  init_dist_B8HfvhaK_es();
158441
158505
  CSS_DIMENSION_REGEX = /[\d-.]+(\w+)$/;
@@ -207122,7 +207186,7 @@ var init_remark_gfm_eZN6yzWQ_es = __esm(() => {
207122
207186
  init_remark_gfm_BhnWr3yf_es();
207123
207187
  });
207124
207188
 
207125
- // ../../packages/superdoc/dist/chunks/src-BzRjWTpH.es.js
207189
+ // ../../packages/superdoc/dist/chunks/src-Dinif16O.es.js
207126
207190
  function deleteProps(obj, propOrProps) {
207127
207191
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
207128
207192
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -207377,7 +207441,7 @@ function getCellSpacingPx(cellSpacing) {
207377
207441
  const v = cellSpacing.value;
207378
207442
  if (typeof v !== "number" || !Number.isFinite(v))
207379
207443
  return 0;
207380
- const asPx = (cellSpacing.type ?? "").toLowerCase() === "dxa" && v >= 20 ? v / TWIPS_PER_PX$2 : v;
207444
+ const asPx = (cellSpacing.type ?? "").toLowerCase() === "dxa" && v >= 20 ? v / TWIPS_PER_PX$3 : v;
207381
207445
  return Math.max(0, asPx);
207382
207446
  }
207383
207447
  function coerceRelativeHeight(raw) {
@@ -234562,29 +234626,12 @@ function toTableFailure(code7, message, details) {
234562
234626
  }
234563
234627
  };
234564
234628
  }
234565
- function createSeparatorParagraph(schema) {
234566
- const paragraphType = schema.nodes.paragraph;
234567
- if (!paragraphType)
234568
- return null;
234569
- const separatorAttrs = {
234570
- sdBlockId: v4_default(),
234571
- paraId: generateDocxHexId()
234572
- };
234573
- return paragraphType.createAndFill(separatorAttrs) ?? paragraphType.createAndFill();
234574
- }
234575
- function buildTableSuccess(tableAddress, trackedChangeRefs) {
234576
- return {
234577
- success: true,
234578
- table: tableAddress,
234579
- trackedChangeRefs
234580
- };
234581
- }
234582
234629
  function syncExtractedTableAttrs(tp) {
234583
234630
  const extracted = {};
234584
234631
  extracted.tableStyleId = tp.tableStyleId ?? null;
234585
234632
  extracted.justification = tp.justification ?? null;
234586
234633
  extracted.tableLayout = tp.tableLayout ?? null;
234587
- extracted.borders = convertTableBordersToPixelUnits(tp.borders) ?? tp.borders ?? null;
234634
+ extracted.borders = convertTableBordersToPixelUnits(tp.borders) ?? {};
234588
234635
  const indent2 = tp.tableIndent;
234589
234636
  if (indent2?.value != null)
234590
234637
  extracted.tableIndent = {
@@ -234596,7 +234643,7 @@ function syncExtractedTableAttrs(tp) {
234596
234643
  const spacing = tp.tableCellSpacing;
234597
234644
  if (spacing?.value != null) {
234598
234645
  extracted.tableCellSpacing = {
234599
- w: String(spacing.value),
234646
+ value: twipsToPixels(spacing.value),
234600
234647
  type: spacing.type ?? "dxa"
234601
234648
  };
234602
234649
  extracted.borderCollapse = "separate";
@@ -234604,23 +234651,23 @@ function syncExtractedTableAttrs(tp) {
234604
234651
  extracted.tableCellSpacing = null;
234605
234652
  extracted.borderCollapse = null;
234606
234653
  }
234607
- const tw = tp.tableWidth;
234608
- if (tw)
234609
- if (tw.type === "pct" && typeof tw.value === "number")
234654
+ const width = tp.tableWidth;
234655
+ if (width)
234656
+ if (width.type === "pct" && typeof width.value === "number")
234610
234657
  extracted.tableWidth = {
234611
- value: tw.value,
234658
+ value: width.value,
234612
234659
  type: "pct"
234613
234660
  };
234614
- else if (tw.type === "auto")
234661
+ else if (width.type === "auto")
234615
234662
  extracted.tableWidth = {
234616
234663
  width: 0,
234617
234664
  type: "auto"
234618
234665
  };
234619
- else if (tw.value != null) {
234620
- const widthPx = twipsToPixels(tw.value);
234666
+ else if (width.value != null) {
234667
+ const widthPx = twipsToPixels(width.value);
234621
234668
  extracted.tableWidth = widthPx != null ? {
234622
234669
  width: widthPx,
234623
- type: tw.type
234670
+ type: width.type
234624
234671
  } : null;
234625
234672
  } else
234626
234673
  extracted.tableWidth = null;
@@ -234635,6 +234682,95 @@ function convertTableBordersToPixelUnits(value) {
234635
234682
  mapBorderSizes(clone, eighthPointsToPixels);
234636
234683
  return Object.keys(clone).length > 0 ? clone : undefined;
234637
234684
  }
234685
+ function buildWidthAuthoringTableAttrs(currentAttrs, attrOverrides = {}, tablePropertyOverrides = {}) {
234686
+ const currentTableProps = currentAttrs.tableProperties ?? {};
234687
+ const nextTableWidth = resolveWidthAuthoringTableWidth(currentAttrs, attrOverrides, tablePropertyOverrides);
234688
+ const updatedTableProps = {
234689
+ ...currentTableProps,
234690
+ ...tablePropertyOverrides,
234691
+ tableLayout: "fixed"
234692
+ };
234693
+ if (nextTableWidth)
234694
+ updatedTableProps.tableWidth = nextTableWidth;
234695
+ else
234696
+ delete updatedTableProps.tableWidth;
234697
+ return {
234698
+ ...currentAttrs,
234699
+ tableProperties: updatedTableProps,
234700
+ ...attrOverrides,
234701
+ ...syncExtractedTableAttrs(updatedTableProps),
234702
+ userEdited: true
234703
+ };
234704
+ }
234705
+ function resolveWidthAuthoringTableWidth(currentAttrs, attrOverrides, tablePropertyOverrides) {
234706
+ const explicitOverride = normalizeTableWidthMeasurement(tablePropertyOverrides.tableWidth);
234707
+ if (explicitOverride)
234708
+ return explicitOverride;
234709
+ const gridWidth = sumGridColumnTwips(attrOverrides.grid ?? currentAttrs.grid);
234710
+ if (gridWidth != null)
234711
+ return {
234712
+ value: gridWidth,
234713
+ type: "dxa"
234714
+ };
234715
+ return null;
234716
+ }
234717
+ function sumGridColumnTwips(grid) {
234718
+ const columns = normalizeGridColumns$1(grid);
234719
+ if (!columns || columns.length === 0)
234720
+ return null;
234721
+ const total = columns.reduce((sum, column) => sum + column.col, 0);
234722
+ return total > 0 ? total : null;
234723
+ }
234724
+ function normalizeGridColumns$1(grid) {
234725
+ if (Array.isArray(grid)) {
234726
+ const columns = grid.map((width) => normalizeGridWidth$1(width)).filter((width) => width != null);
234727
+ return columns.length > 0 ? columns : null;
234728
+ }
234729
+ if (grid && typeof grid === "object") {
234730
+ const rawColWidths = grid.colWidths;
234731
+ if (Array.isArray(rawColWidths)) {
234732
+ const columns = rawColWidths.map((width) => normalizeGridWidth$1(width)).filter((width) => width != null);
234733
+ return columns.length > 0 ? columns : null;
234734
+ }
234735
+ }
234736
+ return null;
234737
+ }
234738
+ function normalizeGridWidth$1(width) {
234739
+ if (typeof width === "number" && Number.isFinite(width) && width > 0)
234740
+ return { col: Math.round(width) };
234741
+ const value = width?.col;
234742
+ if (typeof value === "number" && Number.isFinite(value) && value > 0)
234743
+ return { col: Math.round(value) };
234744
+ return null;
234745
+ }
234746
+ function normalizeTableWidthMeasurement(width) {
234747
+ if (!width || typeof width !== "object")
234748
+ return null;
234749
+ const value = width.value;
234750
+ if (width.type !== "dxa" || typeof value !== "number" || !Number.isFinite(value) || value <= 0)
234751
+ return null;
234752
+ return {
234753
+ value: Math.round(value),
234754
+ type: "dxa"
234755
+ };
234756
+ }
234757
+ function createSeparatorParagraph(schema) {
234758
+ const paragraphType = schema.nodes.paragraph;
234759
+ if (!paragraphType)
234760
+ return null;
234761
+ const separatorAttrs = {
234762
+ sdBlockId: v4_default(),
234763
+ paraId: generateDocxHexId()
234764
+ };
234765
+ return paragraphType.createAndFill(separatorAttrs) ?? paragraphType.createAndFill();
234766
+ }
234767
+ function buildTableSuccess(tableAddress, trackedChangeRefs) {
234768
+ return {
234769
+ success: true,
234770
+ table: tableAddress,
234771
+ trackedChangeRefs
234772
+ };
234773
+ }
234638
234774
  function normalizeGridWidth(width) {
234639
234775
  if (typeof width === "number" && Number.isFinite(width))
234640
234776
  return { col: Math.round(width) };
@@ -234697,6 +234833,30 @@ function removeGridColumnWidth(grid, deleteIndex) {
234697
234833
  columns: colWidths
234698
234834
  });
234699
234835
  }
234836
+ function buildFirstRowCellWidthProps(attrs, cellStartCol, colspan, colwidth, gridColumns) {
234837
+ const currentCellProps = attrs.tableCellProperties && typeof attrs.tableCellProperties === "object" ? attrs.tableCellProperties : {};
234838
+ const spanTwips = resolveSpanWidthTwips(cellStartCol, colspan, colwidth, gridColumns);
234839
+ if (spanTwips == null)
234840
+ return Object.keys(currentCellProps).length > 0 ? currentCellProps : undefined;
234841
+ return {
234842
+ ...currentCellProps,
234843
+ cellWidth: {
234844
+ value: spanTwips,
234845
+ type: "dxa"
234846
+ }
234847
+ };
234848
+ }
234849
+ function resolveSpanWidthTwips(cellStartCol, colspan, colwidth, gridColumns) {
234850
+ const boundedSpan = Math.max(1, colspan);
234851
+ if (Array.isArray(gridColumns) && cellStartCol >= 0 && cellStartCol + boundedSpan <= gridColumns.length) {
234852
+ const gridSpanTwips = gridColumns.slice(cellStartCol, cellStartCol + boundedSpan).reduce((sum, column) => sum + normalizeGridWidth(column).col, 0);
234853
+ if (gridSpanTwips > 0)
234854
+ return gridSpanTwips;
234855
+ }
234856
+ const spanWidthPx = colwidth.slice(0, boundedSpan).reduce((sum, width) => sum + (Number.isFinite(width) ? width : 0), 0);
234857
+ if (spanWidthPx > 0)
234858
+ return Math.round(spanWidthPx * PIXELS_TO_TWIPS);
234859
+ }
234700
234860
  function normalizeCellAttrsForSingleCell(attrs) {
234701
234861
  const currentColwidth = Array.isArray(attrs.colwidth) ? attrs.colwidth : null;
234702
234862
  const tableCellProperties = { ...attrs.tableCellProperties ?? {} };
@@ -235574,8 +235734,13 @@ function tablesSetColumnWidthAdapter(editor, input2, options) {
235574
235734
  const tablePos = table2.candidate.pos;
235575
235735
  const tableStart = tablePos + 1;
235576
235736
  const tableNode = table2.candidate.node;
235737
+ const tableAttrs = tableNode.attrs;
235577
235738
  const map$12 = TableMap.get(tableNode);
235578
235739
  const widthPx = Math.round(input2.widthPt * (96 / 72));
235740
+ const normalizedGrid = normalizeGridColumns(tableAttrs.grid);
235741
+ const nextGridColumns = normalizedGrid?.columns.slice();
235742
+ if (nextGridColumns && columnIndex < nextGridColumns.length)
235743
+ nextGridColumns[columnIndex] = { col: Math.round(input2.widthPt * POINTS_TO_TWIPS) };
235579
235744
  const processed = /* @__PURE__ */ new Set;
235580
235745
  for (let row2 = 0;row2 < map$12.height; row2++) {
235581
235746
  const index2 = row2 * map$12.width + columnIndex;
@@ -235589,29 +235754,31 @@ function tablesSetColumnWidthAdapter(editor, input2, options) {
235589
235754
  const attrs = cell2.attrs;
235590
235755
  const colspan = attrs.colspan || 1;
235591
235756
  const colwidth = attrs.colwidth?.slice() ?? [];
235592
- const withinCol = columnIndex - map$12.colCount(pos);
235757
+ const cellStartCol = map$12.colCount(pos);
235758
+ const withinCol = columnIndex - cellStartCol;
235593
235759
  while (colwidth.length < colspan)
235594
235760
  colwidth.push(0);
235595
235761
  colwidth[withinCol] = widthPx;
235596
- tr.setNodeMarkup(tableStart + pos, null, {
235762
+ const nextAttrs = {
235597
235763
  ...attrs,
235598
235764
  colwidth
235599
- });
235765
+ };
235766
+ if (row2 === 0) {
235767
+ const nextCellProps = buildFirstRowCellWidthProps(attrs, cellStartCol, colspan, colwidth, nextGridColumns);
235768
+ if (nextCellProps)
235769
+ nextAttrs.tableCellProperties = nextCellProps;
235770
+ else
235771
+ delete nextAttrs.tableCellProperties;
235772
+ }
235773
+ tr.setNodeMarkup(tableStart + pos, null, nextAttrs);
235600
235774
  }
235601
- const tableAttrs = tableNode.attrs;
235602
- const normalizedGrid = normalizeGridColumns(tableAttrs.grid);
235603
- if (normalizedGrid && columnIndex < normalizedGrid.columns.length) {
235604
- const newColumns = normalizedGrid.columns.slice();
235605
- newColumns[columnIndex] = { col: Math.round(input2.widthPt * POINTS_TO_TWIPS) };
235606
- tr.setNodeMarkup(tablePos, null, {
235607
- ...tableAttrs,
235608
- grid: serializeGridColumns(tableAttrs.grid, {
235609
- ...normalizedGrid,
235610
- columns: newColumns
235611
- }),
235612
- userEdited: true
235775
+ const tableAttrUpdates = {};
235776
+ if (normalizedGrid && nextGridColumns)
235777
+ tableAttrUpdates.grid = serializeGridColumns(tableAttrs.grid, {
235778
+ ...normalizedGrid,
235779
+ columns: nextGridColumns
235613
235780
  });
235614
- }
235781
+ tr.setNodeMarkup(tablePos, null, buildWidthAuthoringTableAttrs(tableAttrs, tableAttrUpdates));
235615
235782
  applyDirectMutationMeta(tr);
235616
235783
  editor.dispatch(tr);
235617
235784
  clearIndexCache(editor);
@@ -235635,7 +235802,10 @@ function tablesDistributeColumnsAdapter(editor, input2, options) {
235635
235802
  const tablePos = candidate.pos;
235636
235803
  const tableStart = tablePos + 1;
235637
235804
  const tableNode = candidate.node;
235805
+ const tableAttrs = tableNode.attrs;
235638
235806
  const map$12 = TableMap.get(tableNode);
235807
+ const normalizedGrid = normalizeGridColumns(tableAttrs.grid);
235808
+ const nextGridColumns = normalizedGrid?.columns.slice();
235639
235809
  const rangeStart = input2.columnRange?.start ?? 0;
235640
235810
  const rangeEnd = input2.columnRange?.end ?? map$12.width - 1;
235641
235811
  const rangeWidth = rangeEnd - rangeStart + 1;
@@ -235651,6 +235821,12 @@ function tablesDistributeColumnsAdapter(editor, input2, options) {
235651
235821
  totalWidth += colwidth?.[withinCol] ?? 100;
235652
235822
  }
235653
235823
  const evenWidth = Math.round(totalWidth / rangeWidth);
235824
+ if (nextGridColumns) {
235825
+ const evenWidthTwips = Math.max(1, Math.round(evenWidth * PIXELS_TO_TWIPS));
235826
+ const maxColumn = Math.min(rangeEnd, nextGridColumns.length - 1);
235827
+ for (let col = Math.max(rangeStart, 0);col <= maxColumn; col++)
235828
+ nextGridColumns[col] = { col: evenWidthTwips };
235829
+ }
235654
235830
  const processed = /* @__PURE__ */ new Set;
235655
235831
  for (let row2 = 0;row2 < map$12.height; row2++)
235656
235832
  for (let col = rangeStart;col <= rangeEnd; col++) {
@@ -235673,29 +235849,26 @@ function tablesDistributeColumnsAdapter(editor, input2, options) {
235673
235849
  if (absCol >= rangeStart && absCol <= rangeEnd)
235674
235850
  newColwidth[c] = evenWidth;
235675
235851
  }
235676
- tr.setNodeMarkup(tableStart + pos, null, {
235852
+ const nextAttrs = {
235677
235853
  ...attrs,
235678
235854
  colwidth: newColwidth
235679
- });
235855
+ };
235856
+ if (row2 === 0) {
235857
+ const nextCellProps = buildFirstRowCellWidthProps(attrs, cellStartCol, colspan, newColwidth, nextGridColumns);
235858
+ if (nextCellProps)
235859
+ nextAttrs.tableCellProperties = nextCellProps;
235860
+ else
235861
+ delete nextAttrs.tableCellProperties;
235862
+ }
235863
+ tr.setNodeMarkup(tableStart + pos, null, nextAttrs);
235680
235864
  }
235681
- const tableAttrs = tableNode.attrs;
235682
- const normalizedGrid = normalizeGridColumns(tableAttrs.grid);
235683
- const tableAttrUpdates = {
235684
- ...tableAttrs,
235685
- userEdited: true
235686
- };
235687
- if (normalizedGrid) {
235688
- const newColumns = normalizedGrid.columns.slice();
235689
- const evenWidthTwips = Math.max(1, Math.round(evenWidth * PIXELS_TO_TWIPS));
235690
- const maxColumn = Math.min(rangeEnd, newColumns.length - 1);
235691
- for (let col = Math.max(rangeStart, 0);col <= maxColumn; col++)
235692
- newColumns[col] = { col: evenWidthTwips };
235865
+ const tableAttrUpdates = {};
235866
+ if (normalizedGrid && nextGridColumns)
235693
235867
  tableAttrUpdates.grid = serializeGridColumns(tableAttrs.grid, {
235694
235868
  ...normalizedGrid,
235695
- columns: newColumns
235869
+ columns: nextGridColumns
235696
235870
  });
235697
- }
235698
- tr.setNodeMarkup(tablePos, null, tableAttrUpdates);
235871
+ tr.setNodeMarkup(tablePos, null, buildWidthAuthoringTableAttrs(tableAttrs, tableAttrUpdates));
235699
235872
  applyDirectMutationMeta(tr);
235700
235873
  editor.dispatch(tr);
235701
235874
  clearIndexCache(editor);
@@ -236279,6 +236452,10 @@ function tablesSetCellPropertiesAdapter(editor, input2, options) {
236279
236452
  }
236280
236453
  };
236281
236454
  tr.setNodeMarkup(cellPos, null, newAttrs);
236455
+ if (input2.preferredWidthPt !== undefined) {
236456
+ const tableAttrs = table2.candidate.node.attrs;
236457
+ tr.setNodeMarkup(table2.candidate.pos, null, buildWidthAuthoringTableAttrs(tableAttrs));
236458
+ }
236282
236459
  applyDirectMutationMeta(tr);
236283
236460
  editor.dispatch(tr);
236284
236461
  clearIndexCache(editor);
@@ -250810,7 +250987,7 @@ function normalizeFieldAnnotationMetadata(attrs) {
250810
250987
  borderColor: normalizeColorValue2(attrs.borderColor),
250811
250988
  highlighted: toBoolean$2(attrs.highlighted, true),
250812
250989
  fontFamily: toNullableString(attrs.fontFamily),
250813
- fontSize: normalizeFontSize$1(attrs.fontSize),
250990
+ fontSize: normalizeFontSize$2(attrs.fontSize),
250814
250991
  textColor: normalizeColorValue2(attrs.textColor) ?? null,
250815
250992
  textHighlight: normalizeColorValue2(attrs.textHighlight) ?? null,
250816
250993
  linkUrl: toNullableString(attrs.linkUrl),
@@ -250904,7 +251081,7 @@ function normalizeColorValue2(value) {
250904
251081
  return;
250905
251082
  return trimmed;
250906
251083
  }
250907
- function normalizeFontSize$1(value) {
251084
+ function normalizeFontSize$2(value) {
250908
251085
  if (value == null)
250909
251086
  return null;
250910
251087
  if (typeof value === "number")
@@ -252506,11 +252683,15 @@ function tableNodeToBlock(node3, { nextBlockId, positions, storyKey, trackedChan
252506
252683
  tableAttrs.tableWidth = hydratedTableStyle.tableWidth;
252507
252684
  if (node3.attrs?.tableIndent && typeof node3.attrs.tableIndent === "object")
252508
252685
  tableAttrs.tableIndent = { ...node3.attrs.tableIndent };
252686
+ else if (hydratedTableStyle?.tableIndent)
252687
+ tableAttrs.tableIndent = { ...hydratedTableStyle.tableIndent };
252509
252688
  if (defaultCellPadding && typeof defaultCellPadding === "object")
252510
252689
  tableAttrs.defaultCellPadding = { ...defaultCellPadding };
252511
252690
  const tableLayout = node3.attrs?.tableLayout;
252512
252691
  if (tableLayout)
252513
252692
  tableAttrs.tableLayout = tableLayout;
252693
+ else if (hydratedTableStyle?.tableLayout)
252694
+ tableAttrs.tableLayout = hydratedTableStyle.tableLayout;
252514
252695
  const tableProperties = node3.attrs?.tableProperties;
252515
252696
  if (tableProperties && typeof tableProperties === "object")
252516
252697
  tableAttrs.tableProperties = tableProperties;
@@ -257429,7 +257610,7 @@ function measureCharacterX(block, line, charOffset, availableWidthOverride, alig
257429
257610
  }
257430
257611
  const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text ?? "";
257431
257612
  const runLength = text5.length;
257432
- const displayText = applyTextTransform$2(text5, isTabRun$1(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? undefined : run2.textTransform);
257613
+ const displayText = applyTextTransform$3(text5, isTabRun$1(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? undefined : run2.textTransform);
257433
257614
  if (currentCharOffset + runLength >= charOffset) {
257434
257615
  const offsetInRun = charOffset - currentCharOffset;
257435
257616
  ctx$1.font = getRunFontString(run2);
@@ -257478,7 +257659,7 @@ function measureCharacterXSegmentBased(block, line, charOffset, ctx$1) {
257478
257659
  return segmentBaseX + (offsetInSegment > 0 ? segment.width ?? 0 : 0);
257479
257660
  if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math")
257480
257661
  return segmentBaseX + (offsetInSegment >= segmentChars ? segment.width ?? 0 : 0);
257481
- const textUpToTarget = applyTextTransform$2(run2.text ?? "", "textTransform" in run2 ? run2.textTransform : undefined).slice(segment.fromChar, segment.toChar).slice(0, offsetInSegment);
257662
+ const textUpToTarget = applyTextTransform$3(run2.text ?? "", "textTransform" in run2 ? run2.textTransform : undefined).slice(segment.fromChar, segment.toChar).slice(0, offsetInSegment);
257482
257663
  ctx$1.font = getRunFontString(run2);
257483
257664
  const measured = ctx$1.measureText(textUpToTarget);
257484
257665
  const spacingWidth = computeLetterSpacingWidth(run2, offsetInSegment, segmentChars);
@@ -257571,7 +257752,7 @@ function findCharacterAtX(block, line, x, pmStart, availableWidthOverride, align
257571
257752
  }
257572
257753
  const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text ?? "";
257573
257754
  const runLength = text5.length;
257574
- const displayText = applyTextTransform$2(text5, isTabRun$1(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? undefined : run2.textTransform);
257755
+ const displayText = applyTextTransform$3(text5, isTabRun$1(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? undefined : run2.textTransform);
257575
257756
  if (runLength === 0)
257576
257757
  continue;
257577
257758
  ctx$1.font = getRunFontString(run2);
@@ -258214,7 +258395,7 @@ function measureRunSliceWidth(run2, fromChar, toChar) {
258214
258395
  const context = getCtx();
258215
258396
  const fullText = runText(run2);
258216
258397
  const transform = isTextRun$3(run2) ? run2.textTransform : undefined;
258217
- const text5 = applyTextTransform$1(fullText.slice(fromChar, toChar), transform, fullText, fromChar);
258398
+ const text5 = applyTextTransform$2(fullText.slice(fromChar, toChar), transform, fullText, fromChar);
258218
258399
  if (!context) {
258219
258400
  const size$1 = (isTextRun$3(run2) ? run2 : null)?.fontSize ?? 16;
258220
258401
  return Math.max(1, text5.length * (size$1 * 0.6));
@@ -261481,7 +261662,7 @@ function areNumberListsEqual(left$1, right$1) {
261481
261662
  return false;
261482
261663
  return true;
261483
261664
  }
261484
- function isWordCharacter(char) {
261665
+ function isWordCharacter$1(char) {
261485
261666
  if (!char)
261486
261667
  return false;
261487
261668
  return WORD_CHARACTER_REGEX.test(char);
@@ -261564,17 +261745,17 @@ function computeWordSelectionRangeAt(state, pos) {
261564
261745
  const parentStart = textblockPos.start();
261565
261746
  const parentEnd = textblockPos.end();
261566
261747
  const sampleEnd = Math.min(pos + 1, parentEnd);
261567
- if (!isWordCharacter(state.doc.textBetween(pos, sampleEnd, "\x00", "\x00")))
261748
+ if (!isWordCharacter$1(state.doc.textBetween(pos, sampleEnd, "\x00", "\x00")))
261568
261749
  return null;
261569
261750
  let startPos = pos;
261570
261751
  while (startPos > parentStart) {
261571
- if (!isWordCharacter(state.doc.textBetween(startPos - 1, startPos, "\x00", "\x00")))
261752
+ if (!isWordCharacter$1(state.doc.textBetween(startPos - 1, startPos, "\x00", "\x00")))
261572
261753
  break;
261573
261754
  startPos -= 1;
261574
261755
  }
261575
261756
  let endPos = pos;
261576
261757
  while (endPos < parentEnd) {
261577
- if (!isWordCharacter(state.doc.textBetween(endPos, endPos + 1, "\x00", "\x00")))
261758
+ if (!isWordCharacter$1(state.doc.textBetween(endPos, endPos + 1, "\x00", "\x00")))
261578
261759
  break;
261579
261760
  endPos += 1;
261580
261761
  }
@@ -264845,6 +265026,1369 @@ function getFontMetrics(ctx$1, fontInfo, mode, fonts) {
264845
265026
  fontMetricsCache.set(key2, result);
264846
265027
  return result;
264847
265028
  }
265029
+ function computeFixedTableColumnWidths(input2) {
265030
+ const gridColumnCount = Math.max(0, sanitizeColumnCount(input2.gridColumnCount), Array.isArray(input2.preferredColumnWidths) ? input2.preferredColumnWidths.length : 0);
265031
+ const preferredTableWidth = sanitizeOptionalWidth$1(input2.preferredTableWidth);
265032
+ const defaultAddedColumnWidth = resolveDefaultAddedColumnWidth(input2.preferredColumnWidths, preferredTableWidth);
265033
+ const columnWidths = buildInitialGrid(input2.preferredColumnWidths, gridColumnCount, defaultAddedColumnWidth);
265034
+ if (input2.preserveAuthoredGrid === true)
265035
+ return {
265036
+ columnWidths,
265037
+ totalWidth: sumWidths$2(columnWidths),
265038
+ gridColumnCount: columnWidths.length,
265039
+ preferredTableWidth
265040
+ };
265041
+ if (input2.rows.length === 0) {
265042
+ if (preferredTableWidth != null)
265043
+ shrinkToPreferredTableWidth(columnWidths, preferredTableWidth);
265044
+ return {
265045
+ columnWidths,
265046
+ totalWidth: sumWidths$2(columnWidths),
265047
+ gridColumnCount: columnWidths.length,
265048
+ preferredTableWidth
265049
+ };
265050
+ }
265051
+ applyFirstRowRequests(columnWidths, input2.rows[0], defaultAddedColumnWidth);
265052
+ if (preferredTableWidth != null)
265053
+ shrinkToPreferredTableWidth(columnWidths, preferredTableWidth);
265054
+ for (const row2 of input2.rows.slice(1)) {
265055
+ applySubsequentRowRequests(columnWidths, row2, defaultAddedColumnWidth);
265056
+ if (preferredTableWidth != null)
265057
+ shrinkToPreferredTableWidth(columnWidths, preferredTableWidth);
265058
+ }
265059
+ return {
265060
+ columnWidths,
265061
+ totalWidth: sumWidths$2(columnWidths),
265062
+ gridColumnCount: columnWidths.length,
265063
+ preferredTableWidth
265064
+ };
265065
+ }
265066
+ function buildInitialGrid(preferredColumnWidths, gridColumnCount, defaultAddedColumnWidth) {
265067
+ const next2 = preferredColumnWidths.slice(0, gridColumnCount).map((width) => sanitizeNonNegativeWidth(width) ?? 0);
265068
+ while (next2.length < gridColumnCount)
265069
+ next2.push(defaultAddedColumnWidth);
265070
+ return next2;
265071
+ }
265072
+ function applyFirstRowRequests(columnWidths, row2, defaultAddedColumnWidth) {
265073
+ ensureGridWidth(columnWidths, row2.logicalColumnCount, defaultAddedColumnWidth);
265074
+ for (const skippedColumn of row2.skippedColumns)
265075
+ setSkippedColumnWidth(columnWidths, skippedColumn, defaultAddedColumnWidth);
265076
+ for (const cell2 of row2.cells)
265077
+ setCellSpanWidth(columnWidths, cell2, defaultAddedColumnWidth);
265078
+ }
265079
+ function applySubsequentRowRequests(columnWidths, row2, defaultAddedColumnWidth) {
265080
+ ensureGridWidth(columnWidths, row2.logicalColumnCount, defaultAddedColumnWidth);
265081
+ for (const skippedColumn of row2.skippedColumns)
265082
+ growSkippedColumnWidth(columnWidths, skippedColumn, defaultAddedColumnWidth);
265083
+ for (const cell2 of row2.cells)
265084
+ growCellSpanWidth(columnWidths, cell2, defaultAddedColumnWidth);
265085
+ }
265086
+ function setSkippedColumnWidth(columnWidths, skippedColumn, defaultAddedColumnWidth) {
265087
+ const preferredWidth = sanitizeOptionalWidth$1(skippedColumn.preferredWidth);
265088
+ if (preferredWidth == null)
265089
+ return;
265090
+ ensureGridWidth(columnWidths, skippedColumn.columnIndex + 1, defaultAddedColumnWidth);
265091
+ columnWidths[skippedColumn.columnIndex] = preferredWidth;
265092
+ }
265093
+ function growSkippedColumnWidth(columnWidths, skippedColumn, defaultAddedColumnWidth) {
265094
+ const preferredWidth = sanitizeOptionalWidth$1(skippedColumn.preferredWidth);
265095
+ if (preferredWidth == null)
265096
+ return;
265097
+ ensureGridWidth(columnWidths, skippedColumn.columnIndex + 1, defaultAddedColumnWidth);
265098
+ columnWidths[skippedColumn.columnIndex] = Math.max(columnWidths[skippedColumn.columnIndex] ?? 0, preferredWidth);
265099
+ }
265100
+ function setCellSpanWidth(columnWidths, cell2, defaultAddedColumnWidth) {
265101
+ const span = Math.max(1, sanitizeColumnCount(cell2.span));
265102
+ const preferredWidth = sanitizeOptionalWidth$1(cell2.preferredWidth);
265103
+ const endColumn = cell2.startColumn + span;
265104
+ ensureGridWidth(columnWidths, endColumn, defaultAddedColumnWidth);
265105
+ if (preferredWidth == null)
265106
+ return;
265107
+ const currentSpanWidth = sumSpan$1(columnWidths, cell2.startColumn, span);
265108
+ const lastColumnIndex = endColumn - 1;
265109
+ columnWidths[lastColumnIndex] = Math.max(0, (columnWidths[lastColumnIndex] ?? 0) + (preferredWidth - currentSpanWidth));
265110
+ }
265111
+ function growCellSpanWidth(columnWidths, cell2, defaultAddedColumnWidth) {
265112
+ const span = Math.max(1, sanitizeColumnCount(cell2.span));
265113
+ const preferredWidth = sanitizeOptionalWidth$1(cell2.preferredWidth);
265114
+ const endColumn = cell2.startColumn + span;
265115
+ ensureGridWidth(columnWidths, endColumn, defaultAddedColumnWidth);
265116
+ if (preferredWidth == null)
265117
+ return;
265118
+ const deficit = preferredWidth - sumSpan$1(columnWidths, cell2.startColumn, span);
265119
+ if (deficit <= 0)
265120
+ return;
265121
+ const lastColumnIndex = endColumn - 1;
265122
+ columnWidths[lastColumnIndex] = Math.max(0, (columnWidths[lastColumnIndex] ?? 0) + deficit);
265123
+ }
265124
+ function shrinkToPreferredTableWidth(columnWidths, preferredTableWidth) {
265125
+ const totalWidth = sumWidths$2(columnWidths);
265126
+ if (preferredTableWidth <= 0 || totalWidth <= preferredTableWidth || totalWidth <= 0)
265127
+ return;
265128
+ const scale = preferredTableWidth / totalWidth;
265129
+ let consumed = 0;
265130
+ for (let index2 = 0;index2 < columnWidths.length; index2++) {
265131
+ if (index2 === columnWidths.length - 1) {
265132
+ columnWidths[index2] = Math.max(0, preferredTableWidth - consumed);
265133
+ continue;
265134
+ }
265135
+ const scaled = Math.max(0, (columnWidths[index2] ?? 0) * scale);
265136
+ columnWidths[index2] = scaled;
265137
+ consumed += scaled;
265138
+ }
265139
+ }
265140
+ function ensureGridWidth(columnWidths, requiredColumnCount, defaultAddedColumnWidth) {
265141
+ while (columnWidths.length < requiredColumnCount)
265142
+ columnWidths.push(defaultAddedColumnWidth);
265143
+ }
265144
+ function resolveDefaultAddedColumnWidth(preferredColumnWidths, preferredTableWidth) {
265145
+ for (let index2 = preferredColumnWidths.length - 1;index2 >= 0; index2--) {
265146
+ const width = sanitizeNonNegativeWidth(preferredColumnWidths[index2]);
265147
+ if (width != null && width > 0)
265148
+ return width;
265149
+ }
265150
+ const positiveAuthoredWidths = preferredColumnWidths.map((width) => sanitizeNonNegativeWidth(width)).filter((width) => width != null && width > 0);
265151
+ if (positiveAuthoredWidths.length > 0)
265152
+ return sumWidths$2(positiveAuthoredWidths) / positiveAuthoredWidths.length;
265153
+ if (preferredTableWidth != null && preferredTableWidth > 0)
265154
+ return preferredTableWidth;
265155
+ return 1;
265156
+ }
265157
+ function sumSpan$1(columnWidths, startColumn, span) {
265158
+ let total = 0;
265159
+ for (let offset$1 = 0;offset$1 < span; offset$1++)
265160
+ total += columnWidths[startColumn + offset$1] ?? 0;
265161
+ return total;
265162
+ }
265163
+ function sumWidths$2(columnWidths) {
265164
+ return columnWidths.reduce((sum, width) => sum + Math.max(0, width), 0);
265165
+ }
265166
+ function sanitizeColumnCount(value) {
265167
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0)
265168
+ return 0;
265169
+ return Math.floor(value);
265170
+ }
265171
+ function sanitizeOptionalWidth$1(value) {
265172
+ const width = sanitizeNonNegativeWidth(value);
265173
+ return width == null ? undefined : width;
265174
+ }
265175
+ function sanitizeNonNegativeWidth(value) {
265176
+ if (typeof value !== "number" || !Number.isFinite(value))
265177
+ return;
265178
+ return Math.max(0, value);
265179
+ }
265180
+ function computeAutoFitColumnWidths(input2) {
265181
+ const { workingInput, fixedLayout, rowMetrics, minColumnWidth } = resolveAutoFitContext(input2);
265182
+ if (workingInput.layoutMode === "fixed")
265183
+ return finalizeResult("fixed", fixedLayout.columnWidths, minColumnWidth);
265184
+ const gridColumnCount = fixedLayout.gridColumnCount;
265185
+ if (gridColumnCount === 0)
265186
+ return buildFallbackResult(workingInput.layoutMode, minColumnWidth);
265187
+ const normalizedRows = buildNormalizedRows(workingInput, rowMetrics);
265188
+ const currentWidths = fixedLayout.columnWidths.slice(0, gridColumnCount);
265189
+ const minBounds = new Array(gridColumnCount).fill(0);
265190
+ const maxBounds = new Array(gridColumnCount).fill(0);
265191
+ const preferredOverrides = new Array(gridColumnCount).fill(undefined);
265192
+ const multiSpanCells = [];
265193
+ accumulateBounds({
265194
+ rows: normalizedRows,
265195
+ minBounds,
265196
+ maxBounds,
265197
+ preferredOverrides,
265198
+ multiSpanCells
265199
+ });
265200
+ applyMultiSpanMinimums(minBounds, multiSpanCells);
265201
+ applySingleSpanPreferredOverrides(maxBounds, minBounds, preferredOverrides);
265202
+ applyMultiSpanMaximums(maxBounds, minBounds, multiSpanCells, currentWidths);
265203
+ const triggerCells = collectTriggerCells(currentWidths, multiSpanCells, normalizedRows);
265204
+ const postTriggerGrowableColumns = triggerCells.length > 0 ? collectNonProtectedColumns(triggerCells, gridColumnCount) : undefined;
265205
+ let resolvedWidths = currentWidths.slice();
265206
+ const preferredTableWidth = sanitizeOptionalWidth(workingInput.preferredTableWidth);
265207
+ let targetTableWidth = preferredTableWidth ?? fixedLayout.totalWidth;
265208
+ const maxResolvedTableWidth = preferredTableWidth != null || hasCompleteAuthoredGrid(workingInput) ? Math.max(workingInput.maxTableWidth, targetTableWidth) : workingInput.maxTableWidth;
265209
+ const shouldPreservePreferredGrid = workingInput.preserveAutoGrid === true || workingInput.preserveExplicitAutoGrid === true;
265210
+ if (triggerCells.length > 0) {
265211
+ resolvedWidths = raiseToMinimums(resolvedWidths, minBounds);
265212
+ resolvedWidths = expandTriggersWithinCurrentTable(resolvedWidths, triggerCells, minBounds, maxBounds);
265213
+ resolvedWidths = expandTriggersByGrowingTable(resolvedWidths, triggerCells, maxBounds, maxResolvedTableWidth);
265214
+ targetTableWidth = Math.max(targetTableWidth, sumWidths$1(resolvedWidths));
265215
+ targetTableWidth = Math.min(targetTableWidth, maxResolvedTableWidth);
265216
+ } else {
265217
+ targetTableWidth = Math.min(targetTableWidth, maxResolvedTableWidth);
265218
+ if (!shouldPreservePreferredGrid) {
265219
+ resolvedWidths = redistributeTowardMaximumsWithinCurrentTable(resolvedWidths, minBounds, maxBounds);
265220
+ resolvedWidths = redistributeTowardContentWeightedShape(resolvedWidths, minBounds, maxBounds);
265221
+ }
265222
+ }
265223
+ resolvedWidths = shrinkToTargetWidth(resolvedWidths, targetTableWidth, minBounds);
265224
+ resolvedWidths = growToTargetWidth(resolvedWidths, targetTableWidth, maxBounds, postTriggerGrowableColumns);
265225
+ if (sumWidths$1(resolvedWidths) < targetTableWidth)
265226
+ resolvedWidths = distributeRemainingSlack(resolvedWidths, targetTableWidth, postTriggerGrowableColumns);
265227
+ if (triggerCells.length > 0)
265228
+ resolvedWidths = clampTriggeredSpansToTargets(resolvedWidths, triggerCells, minBounds, maxBounds, currentWidths);
265229
+ if (sumWidths$1(resolvedWidths) > maxResolvedTableWidth)
265230
+ resolvedWidths = shrinkToTargetWidth(resolvedWidths, maxResolvedTableWidth, minBounds);
265231
+ return finalizeResult(workingInput.layoutMode, resolvedWidths, minColumnWidth);
265232
+ }
265233
+ function hasCompleteAuthoredGrid(workingInput) {
265234
+ const authoredColumnCount = workingInput.preferredColumnWidths.length;
265235
+ if (authoredColumnCount === 0)
265236
+ return false;
265237
+ return workingInput.rows.some((row2) => row2.logicalColumnCount >= authoredColumnCount);
265238
+ }
265239
+ function resolveAutoFitContext(input2) {
265240
+ const minColumnWidth = sanitizeWidth(input2.minColumnWidth, DEFAULT_MIN_COLUMN_WIDTH);
265241
+ if (isExplicitInput(input2))
265242
+ return {
265243
+ workingInput: input2.workingInput,
265244
+ fixedLayout: input2.fixedLayout,
265245
+ rowMetrics: input2.contentMetrics.rowMetrics,
265246
+ minColumnWidth
265247
+ };
265248
+ const layoutMode = resolveLayoutMode$1(input2.tableLayout);
265249
+ const normalizedRows = normalizeLegacyRows(input2.rows ?? []);
265250
+ const gridColumnCount = determineGridColumnCount$1(input2.preferredColumnWidths ?? [], normalizedRows);
265251
+ const workingInput = {
265252
+ layoutMode,
265253
+ maxTableWidth: Math.max(minColumnWidth, sanitizeWidth(input2.maxTableWidth, minColumnWidth)),
265254
+ preferredTableWidth: sanitizeOptionalWidth(input2.preferredTableWidth),
265255
+ preferredColumnWidths: (input2.preferredColumnWidths ?? []).map((width) => Math.max(0, width)),
265256
+ gridColumnCount,
265257
+ rows: normalizedRows.map((row2) => ({
265258
+ skippedBefore: row2.skippedColumns.filter((column) => column.columnIndex < firstCellStart(row2)),
265259
+ skippedAfter: row2.skippedColumns.filter((column) => column.columnIndex >= lastCellEnd(row2)),
265260
+ skippedColumns: row2.skippedColumns,
265261
+ cells: row2.cells.map((cell2) => ({
265262
+ cellId: undefined,
265263
+ startColumn: cell2.startColumn,
265264
+ span: cell2.span,
265265
+ preferredWidth: cell2.preferredWidth
265266
+ })),
265267
+ logicalColumnCount: row2.logicalColumnCount
265268
+ }))
265269
+ };
265270
+ return {
265271
+ workingInput,
265272
+ fixedLayout: computeFixedTableColumnWidths(workingInput),
265273
+ rowMetrics: normalizedRows.map((row2, rowIndex) => ({
265274
+ rowIndex,
265275
+ cells: row2.cells.map((cell2) => ({
265276
+ cellIndex: cell2.cellIndex,
265277
+ span: cell2.span,
265278
+ preferredWidth: cell2.preferredWidth,
265279
+ minContentWidth: cell2.minContentWidth,
265280
+ maxContentWidth: cell2.maxContentWidth
265281
+ }))
265282
+ })),
265283
+ minColumnWidth
265284
+ };
265285
+ }
265286
+ function isExplicitInput(input2) {
265287
+ return "workingInput" in input2 && "fixedLayout" in input2 && "contentMetrics" in input2;
265288
+ }
265289
+ function resolveLayoutMode$1(tableLayout) {
265290
+ return tableLayout === "fixed" ? "fixed" : "autofit";
265291
+ }
265292
+ function normalizeLegacyRows(rows) {
265293
+ return rows.map((row2, rowIndex) => {
265294
+ let columnIndex = 0;
265295
+ const skippedColumns = [];
265296
+ const cells = [];
265297
+ for (const skipped of row2.skippedBefore ?? []) {
265298
+ skippedColumns.push(normalizeSkippedColumn(skipped, columnIndex));
265299
+ columnIndex += 1;
265300
+ }
265301
+ for (let cellIndex = 0;cellIndex < (row2.cells ?? []).length; cellIndex++) {
265302
+ const cell2 = row2.cells?.[cellIndex];
265303
+ if (!cell2)
265304
+ continue;
265305
+ const span = Math.max(1, Math.floor(cell2.span ?? 1));
265306
+ cells.push({
265307
+ rowIndex,
265308
+ cellIndex,
265309
+ startColumn: columnIndex,
265310
+ span,
265311
+ preferredWidth: sanitizeOptionalWidth(cell2.preferredWidth),
265312
+ minContentWidth: Math.max(0, cell2.minContentWidth ?? 0),
265313
+ maxContentWidth: Math.max(0, cell2.maxContentWidth ?? cell2.minContentWidth ?? 0)
265314
+ });
265315
+ columnIndex += span;
265316
+ }
265317
+ for (const skipped of row2.skippedAfter ?? []) {
265318
+ skippedColumns.push(normalizeSkippedColumn(skipped, columnIndex));
265319
+ columnIndex += 1;
265320
+ }
265321
+ return {
265322
+ cells,
265323
+ skippedColumns,
265324
+ logicalColumnCount: columnIndex
265325
+ };
265326
+ });
265327
+ }
265328
+ function normalizeSkippedColumn(skipped, columnIndex) {
265329
+ return {
265330
+ columnIndex,
265331
+ preferredWidth: sanitizeOptionalWidth(skipped.preferredWidth),
265332
+ minContentWidth: Math.max(0, skipped.minContentWidth ?? 0),
265333
+ maxContentWidth: Math.max(0, skipped.maxContentWidth ?? skipped.minContentWidth ?? 0)
265334
+ };
265335
+ }
265336
+ function buildNormalizedRows(workingInput, rowMetrics) {
265337
+ return workingInput.rows.map((workingRow, rowIndex) => {
265338
+ const metricsRow = rowMetrics[rowIndex];
265339
+ return {
265340
+ cells: (workingRow.cells ?? []).map((cell2, cellIndex) => {
265341
+ const metrics = metricsRow?.cells[cellIndex];
265342
+ const placedCell = cell2;
265343
+ return {
265344
+ rowIndex,
265345
+ cellIndex: metrics?.cellIndex ?? cellIndex,
265346
+ startColumn: placedCell.startColumn,
265347
+ span: Math.max(1, placedCell.span ?? metrics?.span ?? 1),
265348
+ preferredWidth: sanitizeOptionalWidth(metrics?.preferredWidth ?? placedCell.preferredWidth),
265349
+ minContentWidth: Math.max(0, metrics?.minContentWidth ?? 0),
265350
+ maxContentWidth: Math.max(0, metrics?.maxContentWidth ?? metrics?.minContentWidth ?? 0)
265351
+ };
265352
+ }),
265353
+ skippedColumns: (workingRow.skippedColumns ?? []).map((skipped) => ({
265354
+ columnIndex: skipped.columnIndex,
265355
+ preferredWidth: sanitizeOptionalWidth(skipped.preferredWidth),
265356
+ minContentWidth: Math.max(0, skipped.minContentWidth ?? 0),
265357
+ maxContentWidth: Math.max(0, skipped.maxContentWidth ?? skipped.minContentWidth ?? 0)
265358
+ })),
265359
+ logicalColumnCount: workingRow.logicalColumnCount
265360
+ };
265361
+ });
265362
+ }
265363
+ function accumulateBounds(args$1) {
265364
+ const { rows, minBounds, maxBounds, preferredOverrides, multiSpanCells } = args$1;
265365
+ for (const row2 of rows) {
265366
+ for (const skipped of row2.skippedColumns) {
265367
+ minBounds[skipped.columnIndex] = Math.max(minBounds[skipped.columnIndex], skipped.minContentWidth);
265368
+ maxBounds[skipped.columnIndex] = Math.max(maxBounds[skipped.columnIndex], skipped.maxContentWidth);
265369
+ if (preferredOverrides[skipped.columnIndex] == null && skipped.preferredWidth != null)
265370
+ preferredOverrides[skipped.columnIndex] = skipped.preferredWidth;
265371
+ }
265372
+ for (const cell2 of row2.cells)
265373
+ if (cell2.span === 1) {
265374
+ minBounds[cell2.startColumn] = Math.max(minBounds[cell2.startColumn], cell2.minContentWidth);
265375
+ maxBounds[cell2.startColumn] = Math.max(maxBounds[cell2.startColumn], cell2.maxContentWidth);
265376
+ if (preferredOverrides[cell2.startColumn] == null && cell2.preferredWidth != null)
265377
+ preferredOverrides[cell2.startColumn] = cell2.preferredWidth;
265378
+ } else
265379
+ multiSpanCells.push(cell2);
265380
+ }
265381
+ }
265382
+ function applyMultiSpanMinimums(minBounds, cells) {
265383
+ for (const cell2 of cells)
265384
+ growSpanTotal(minBounds, cell2.startColumn, cell2.span, cell2.minContentWidth);
265385
+ }
265386
+ function applySingleSpanPreferredOverrides(maxBounds, minBounds, preferredOverrides) {
265387
+ for (let index2 = 0;index2 < maxBounds.length; index2++) {
265388
+ const currentMax = Math.max(maxBounds[index2], minBounds[index2]);
265389
+ maxBounds[index2] = preferredOverrides[index2] ?? currentMax;
265390
+ maxBounds[index2] = Math.max(maxBounds[index2], minBounds[index2]);
265391
+ }
265392
+ }
265393
+ function applyMultiSpanMaximums(maxBounds, minBounds, cells, fixedWidths) {
265394
+ for (const cell2 of cells) {
265395
+ const targetTotal = cell2.preferredWidth != null ? Math.max(cell2.preferredWidth, sumSpan(minBounds, cell2.startColumn, cell2.span)) : Math.max(cell2.maxContentWidth, sumSpan(minBounds, cell2.startColumn, cell2.span));
265396
+ setSpanTotal(maxBounds, minBounds, fixedWidths, cell2.startColumn, cell2.span, targetTotal);
265397
+ }
265398
+ }
265399
+ function collectTriggerCells(currentWidths, multiSpanCells, rows) {
265400
+ const triggers = [];
265401
+ for (const row2 of rows)
265402
+ for (const cell2 of row2.cells)
265403
+ if (sumSpan(currentWidths, cell2.startColumn, cell2.span) < cell2.minContentWidth)
265404
+ triggers.push(cell2);
265405
+ for (const cell2 of multiSpanCells)
265406
+ if (sumSpan(currentWidths, cell2.startColumn, cell2.span) < cell2.minContentWidth)
265407
+ triggers.push(cell2);
265408
+ return coalesceEquivalentTriggerCells(dedupeCells(triggers));
265409
+ }
265410
+ function setSpanTotal(widths, minBounds, fixedWidths, startColumn, span, targetTotal) {
265411
+ const currentTotal = sumSpan(widths, startColumn, span);
265412
+ const minTotal = sumSpan(minBounds, startColumn, span);
265413
+ const boundedTarget = Math.max(targetTotal, minTotal);
265414
+ if (currentTotal < boundedTarget) {
265415
+ growSpanTotal(widths, startColumn, span, boundedTarget, fixedWidths);
265416
+ return;
265417
+ }
265418
+ if (currentTotal === boundedTarget)
265419
+ return;
265420
+ const reducibleRanges = collectSpanRanges(widths, minBounds, startColumn, span);
265421
+ const totalReducible = reducibleRanges.reduce((sum, range) => sum + range.amount, 0);
265422
+ if (totalReducible <= 0)
265423
+ return;
265424
+ const reduction = currentTotal - boundedTarget;
265425
+ let applied = 0;
265426
+ for (let rangeIndex = 0;rangeIndex < reducibleRanges.length; rangeIndex++) {
265427
+ const range = reducibleRanges[rangeIndex];
265428
+ const portion = rangeIndex === reducibleRanges.length - 1 ? reduction - applied : reduction * (range.amount / totalReducible);
265429
+ widths[range.index] = Math.max(minBounds[range.index], widths[range.index] - portion);
265430
+ applied += portion;
265431
+ }
265432
+ }
265433
+ function growSpanTotal(widths, startColumn, span, targetTotal, fixedWidths) {
265434
+ const deficit = targetTotal - sumSpan(widths, startColumn, span);
265435
+ if (deficit <= 0)
265436
+ return;
265437
+ const weights = Array.from({ length: span }, (_$1, offset$1) => {
265438
+ const index2 = startColumn + offset$1;
265439
+ return Math.max(fixedWidths?.[index2] ?? 0, widths[index2] ?? 0, 1);
265440
+ });
265441
+ const totalWeight = weights.reduce((sum, weight) => sum + weight, 0);
265442
+ let applied = 0;
265443
+ for (let offset$1 = 0;offset$1 < span; offset$1++) {
265444
+ const index2 = startColumn + offset$1;
265445
+ const increment2 = offset$1 === span - 1 ? deficit - applied : deficit * (weights[offset$1] / totalWeight);
265446
+ widths[index2] = Math.max(0, (widths[index2] ?? 0) + increment2);
265447
+ applied += increment2;
265448
+ }
265449
+ }
265450
+ function shrinkToTargetWidth(widths, targetWidth, minBounds) {
265451
+ const currentTotal = sumWidths$1(widths);
265452
+ if (currentTotal <= targetWidth)
265453
+ return widths;
265454
+ const minTotal = sumWidths$1(minBounds);
265455
+ if (targetWidth <= 0)
265456
+ return widths;
265457
+ if (targetWidth < minTotal)
265458
+ return scaleToTargetWidth(widths, targetWidth);
265459
+ const capacities = widths.map((width, index2) => Math.max(0, width - minBounds[index2]));
265460
+ const totalCapacity = capacities.reduce((sum, capacity) => sum + capacity, 0);
265461
+ if (totalCapacity <= 0)
265462
+ return widths;
265463
+ const excess = currentTotal - targetWidth;
265464
+ return widths.map((width, index2) => {
265465
+ const shrink = excess * (capacities[index2] / totalCapacity);
265466
+ return Math.max(minBounds[index2], width - shrink);
265467
+ });
265468
+ }
265469
+ function growToTargetWidth(widths, targetWidth, maxBounds, growableColumns) {
265470
+ const currentTotal = sumWidths$1(widths);
265471
+ if (currentTotal >= targetWidth)
265472
+ return widths;
265473
+ const ranges = widths.map((width, index2) => growableColumns == null || growableColumns.has(index2) ? Math.max(0, maxBounds[index2] - width) : 0);
265474
+ const totalRange = ranges.reduce((sum, range) => sum + range, 0);
265475
+ if (totalRange <= 0)
265476
+ return widths;
265477
+ const slack = targetWidth - currentTotal;
265478
+ return widths.map((width, index2) => width + slack * (ranges[index2] / totalRange));
265479
+ }
265480
+ function distributeRemainingSlack(widths, targetWidth, growableColumns) {
265481
+ const currentTotal = sumWidths$1(widths);
265482
+ if (currentTotal >= targetWidth)
265483
+ return widths;
265484
+ const basis = widths.reduce((sum, width, index2) => {
265485
+ if (growableColumns != null && !growableColumns.has(index2))
265486
+ return sum;
265487
+ return sum + Math.max(width, 1);
265488
+ }, 0);
265489
+ const slack = targetWidth - currentTotal;
265490
+ if (basis <= 0) {
265491
+ if (growableColumns == null)
265492
+ return widths;
265493
+ const growableIndexes = widths.map((_$1, index2) => index2).filter((index2) => growableColumns.has(index2));
265494
+ if (growableIndexes.length === 0)
265495
+ return widths;
265496
+ const share = slack / growableIndexes.length;
265497
+ return widths.map((width, index2) => growableColumns.has(index2) ? width + share : width);
265498
+ }
265499
+ return widths.map((width, index2) => {
265500
+ if (growableColumns != null && !growableColumns.has(index2))
265501
+ return width;
265502
+ return width + slack * (Math.max(width, 1) / basis);
265503
+ });
265504
+ }
265505
+ function raiseToMinimums(widths, minBounds) {
265506
+ const next2 = widths.slice();
265507
+ const deficits = next2.map((width, index2) => Math.max(0, minBounds[index2] - width));
265508
+ const totalDeficit = deficits.reduce((sum, deficit) => sum + deficit, 0);
265509
+ if (totalDeficit <= 0)
265510
+ return next2;
265511
+ const capacities = next2.map((width, index2) => Math.max(0, width - minBounds[index2]));
265512
+ const totalCapacity = capacities.reduce((sum, capacity) => sum + capacity, 0);
265513
+ const borrowAmount = Math.min(totalDeficit, totalCapacity);
265514
+ if (borrowAmount > 0 && totalCapacity > 0) {
265515
+ let borrowed = 0;
265516
+ for (let index2 = 0;index2 < next2.length; index2++) {
265517
+ const reduction = index2 === next2.length - 1 ? borrowAmount - borrowed : borrowAmount * (capacities[index2] / totalCapacity);
265518
+ next2[index2] = Math.max(minBounds[index2], next2[index2] - reduction);
265519
+ borrowed += reduction;
265520
+ }
265521
+ }
265522
+ for (let index2 = 0;index2 < next2.length; index2++)
265523
+ next2[index2] = Math.max(next2[index2], Math.min(minBounds[index2], widths[index2] + deficits[index2]));
265524
+ return next2;
265525
+ }
265526
+ function redistributeTowardMaximumsWithinCurrentTable(widths, minBounds, maxBounds) {
265527
+ const next2 = widths.slice();
265528
+ for (let iteration = 0;iteration < 8; iteration++) {
265529
+ const receiverHeadrooms = next2.map((width, index2) => Math.max(0, maxBounds[index2] - width));
265530
+ const totalReceiverHeadroom = receiverHeadrooms.reduce((sum, headroom) => sum + headroom, 0);
265531
+ if (totalReceiverHeadroom <= 0.001)
265532
+ break;
265533
+ const donorCapacities = next2.map((width, index2) => receiverHeadrooms[index2] > 0.001 ? 0 : Math.max(0, width - minBounds[index2]));
265534
+ let totalDonorCapacity = donorCapacities.reduce((sum, capacity) => sum + capacity, 0);
265535
+ if (totalDonorCapacity <= 0.001) {
265536
+ for (let index2 = 0;index2 < next2.length; index2++)
265537
+ donorCapacities[index2] = Math.max(0, next2[index2] - minBounds[index2]);
265538
+ totalDonorCapacity = donorCapacities.reduce((sum, capacity) => sum + capacity, 0);
265539
+ }
265540
+ if (totalDonorCapacity <= 0.001)
265541
+ break;
265542
+ const redistribution = Math.min(totalReceiverHeadroom, totalDonorCapacity);
265543
+ shrinkColumnsByCapacity(next2, donorCapacities, minBounds, redistribution);
265544
+ growColumnsByHeadroom(next2, receiverHeadrooms, redistribution);
265545
+ }
265546
+ return next2;
265547
+ }
265548
+ function redistributeTowardContentWeightedShape(widths, minBounds, maxBounds) {
265549
+ const distributableWidth = sumWidths$1(widths) - sumWidths$1(minBounds);
265550
+ if (distributableWidth <= 0.001 || widths.length === 0)
265551
+ return widths;
265552
+ const demandWeights = widths.map((width, index2) => {
265553
+ const demand = Math.max(maxBounds[index2], width, minBounds[index2], 1);
265554
+ return demand * demand;
265555
+ });
265556
+ const totalDemandWeight = demandWeights.reduce((sum, weight) => sum + weight, 0);
265557
+ if (totalDemandWeight <= 0.001)
265558
+ return widths;
265559
+ return widths.map((_$1, index2) => minBounds[index2] + distributableWidth * (demandWeights[index2] / totalDemandWeight));
265560
+ }
265561
+ function expandTriggersWithinCurrentTable(widths, triggerCells, minBounds, maxBounds) {
265562
+ const next2 = widths.slice();
265563
+ const protectedColumns = collectProtectedColumns(triggerCells);
265564
+ for (let iteration = 0;iteration < 8; iteration++) {
265565
+ const totalHeadroom = collectTriggerHeadrooms(next2, triggerCells, maxBounds).reduce((sum, headroom) => sum + headroom, 0);
265566
+ if (totalHeadroom <= 0.001)
265567
+ break;
265568
+ const donorCapacities = next2.map((width, index2) => protectedColumns.has(index2) ? 0 : Math.max(0, width - minBounds[index2]));
265569
+ const totalDonorCapacity = donorCapacities.reduce((sum, capacity) => sum + capacity, 0);
265570
+ if (totalDonorCapacity <= 0.001)
265571
+ break;
265572
+ const borrowedWidth = Math.min(totalHeadroom, totalDonorCapacity);
265573
+ shrinkColumnsByCapacity(next2, donorCapacities, minBounds, borrowedWidth);
265574
+ applyTriggerGrowth(next2, triggerCells, maxBounds, borrowedWidth);
265575
+ }
265576
+ return next2;
265577
+ }
265578
+ function expandTriggersByGrowingTable(widths, triggerCells, maxBounds, maxTableWidth) {
265579
+ const next2 = widths.slice();
265580
+ for (let iteration = 0;iteration < 8; iteration++) {
265581
+ const totalHeadroom = collectTriggerHeadrooms(next2, triggerCells, maxBounds).reduce((sum, headroom) => sum + headroom, 0);
265582
+ if (totalHeadroom <= 0.001)
265583
+ break;
265584
+ const remainingTableGrowth = Math.max(0, maxTableWidth - sumWidths$1(next2));
265585
+ if (remainingTableGrowth <= 0.001)
265586
+ break;
265587
+ applyTriggerGrowth(next2, triggerCells, maxBounds, Math.min(totalHeadroom, remainingTableGrowth));
265588
+ }
265589
+ return next2;
265590
+ }
265591
+ function collectTriggerHeadrooms(widths, triggerCells, maxBounds) {
265592
+ return triggerCells.map((cell2) => {
265593
+ const currentTotal = sumSpan(widths, cell2.startColumn, cell2.span);
265594
+ const targetTotal = resolveTriggerTargetTotal(cell2, maxBounds);
265595
+ return Math.max(0, targetTotal - currentTotal);
265596
+ });
265597
+ }
265598
+ function resolveTriggerTargetTotal(cell2, maxBounds) {
265599
+ if (cell2.span === 1)
265600
+ return maxBounds[cell2.startColumn] ?? cell2.maxContentWidth;
265601
+ return cell2.preferredWidth != null ? Math.max(cell2.preferredWidth, cell2.minContentWidth) : Math.max(cell2.maxContentWidth, cell2.minContentWidth);
265602
+ }
265603
+ function collectProtectedColumns(cells) {
265604
+ const protectedColumns = /* @__PURE__ */ new Set;
265605
+ for (const cell2 of cells)
265606
+ for (let offset$1 = 0;offset$1 < cell2.span; offset$1++)
265607
+ protectedColumns.add(cell2.startColumn + offset$1);
265608
+ return protectedColumns;
265609
+ }
265610
+ function collectNonProtectedColumns(cells, columnCount) {
265611
+ const protectedColumns = collectProtectedColumns(cells);
265612
+ const growableColumns = /* @__PURE__ */ new Set;
265613
+ for (let index2 = 0;index2 < columnCount; index2++)
265614
+ if (!protectedColumns.has(index2))
265615
+ growableColumns.add(index2);
265616
+ return growableColumns;
265617
+ }
265618
+ function shrinkColumnsByCapacity(widths, capacities, minBounds, shrinkAmount) {
265619
+ const totalCapacity = capacities.reduce((sum, capacity) => sum + capacity, 0);
265620
+ if (totalCapacity <= 0 || shrinkAmount <= 0)
265621
+ return;
265622
+ let applied = 0;
265623
+ for (let index2 = 0;index2 < widths.length; index2++) {
265624
+ const reduction = index2 === widths.length - 1 ? shrinkAmount - applied : shrinkAmount * (capacities[index2] / totalCapacity);
265625
+ widths[index2] = Math.max(minBounds[index2], widths[index2] - reduction);
265626
+ applied += reduction;
265627
+ }
265628
+ }
265629
+ function growColumnsByHeadroom(widths, headrooms, growthAmount) {
265630
+ const totalHeadroom = headrooms.reduce((sum, headroom) => sum + headroom, 0);
265631
+ if (totalHeadroom <= 0 || growthAmount <= 0)
265632
+ return;
265633
+ let applied = 0;
265634
+ const activeIndexes = headrooms.map((headroom, index2) => ({
265635
+ headroom,
265636
+ index: index2
265637
+ })).filter((entry) => entry.headroom > 0.001);
265638
+ for (let activeIndex = 0;activeIndex < activeIndexes.length; activeIndex++) {
265639
+ const { index: index2, headroom } = activeIndexes[activeIndex];
265640
+ const growth = activeIndex === activeIndexes.length - 1 ? growthAmount - applied : growthAmount * (headroom / totalHeadroom);
265641
+ widths[index2] += Math.min(headroom, growth);
265642
+ applied += Math.min(headroom, growth);
265643
+ }
265644
+ }
265645
+ function applyTriggerGrowth(widths, triggerCells, maxBounds, growthAmount) {
265646
+ let remainingGrowth = growthAmount;
265647
+ for (let iteration = 0;iteration < 16 && remainingGrowth > 0.001; iteration++) {
265648
+ const headrooms = collectTriggerHeadrooms(widths, triggerCells, maxBounds);
265649
+ const totalHeadroom = headrooms.reduce((sum, headroom) => sum + headroom, 0);
265650
+ if (totalHeadroom <= 0.001)
265651
+ break;
265652
+ const stepGrowth = Math.min(remainingGrowth, totalHeadroom);
265653
+ const activeIndexes = headrooms.map((headroom, index2) => ({
265654
+ headroom,
265655
+ index: index2
265656
+ })).filter((entry) => entry.headroom > 0.001);
265657
+ let appliedThisRound = 0;
265658
+ for (let activeIndex = 0;activeIndex < activeIndexes.length; activeIndex++) {
265659
+ const { index: index2, headroom } = activeIndexes[activeIndex];
265660
+ const cell2 = triggerCells[index2];
265661
+ const proportionalGrowth = activeIndex === activeIndexes.length - 1 ? stepGrowth - appliedThisRound : stepGrowth * (headroom / totalHeadroom);
265662
+ const boundedGrowth = Math.min(headroom, proportionalGrowth);
265663
+ if (boundedGrowth <= 0)
265664
+ continue;
265665
+ growSpanTotal(widths, cell2.startColumn, cell2.span, sumSpan(widths, cell2.startColumn, cell2.span) + boundedGrowth);
265666
+ appliedThisRound += boundedGrowth;
265667
+ }
265668
+ if (appliedThisRound <= 0.001)
265669
+ break;
265670
+ remainingGrowth -= appliedThisRound;
265671
+ }
265672
+ }
265673
+ function clampTriggeredSpansToTargets(widths, triggerCells, minBounds, maxBounds, fixedWidths) {
265674
+ const next2 = widths.slice();
265675
+ for (let iteration = 0;iteration < 8; iteration++) {
265676
+ let changed = false;
265677
+ for (const cell2 of triggerCells) {
265678
+ const currentTotal = sumSpan(next2, cell2.startColumn, cell2.span);
265679
+ const targetTotal = resolveTriggerTargetTotal(cell2, maxBounds);
265680
+ if (currentTotal > targetTotal + 0.001) {
265681
+ setSpanTotal(next2, minBounds, fixedWidths, cell2.startColumn, cell2.span, targetTotal);
265682
+ changed = true;
265683
+ }
265684
+ }
265685
+ if (!changed)
265686
+ break;
265687
+ }
265688
+ return next2;
265689
+ }
265690
+ function collectSpanRanges(widths, minBounds, startColumn, span) {
265691
+ const ranges = [];
265692
+ for (let offset$1 = 0;offset$1 < span; offset$1++) {
265693
+ const index2 = startColumn + offset$1;
265694
+ const amount = Math.max(0, widths[index2] - minBounds[index2]);
265695
+ if (amount > 0)
265696
+ ranges.push({
265697
+ index: index2,
265698
+ amount
265699
+ });
265700
+ }
265701
+ return ranges;
265702
+ }
265703
+ function dedupeCells(cells) {
265704
+ const seen = /* @__PURE__ */ new Set;
265705
+ return cells.filter((cell2) => {
265706
+ const key2 = `${cell2.rowIndex}:${cell2.startColumn}:${cell2.span}:${cell2.cellIndex}`;
265707
+ if (seen.has(key2))
265708
+ return false;
265709
+ seen.add(key2);
265710
+ return true;
265711
+ });
265712
+ }
265713
+ function coalesceEquivalentTriggerCells(cells) {
265714
+ const strongestBySpan = /* @__PURE__ */ new Map;
265715
+ for (const cell2 of cells) {
265716
+ const key2 = `${cell2.startColumn}:${cell2.span}`;
265717
+ const current = strongestBySpan.get(key2);
265718
+ if (!current || resolveTriggerStrength(cell2) > resolveTriggerStrength(current))
265719
+ strongestBySpan.set(key2, cell2);
265720
+ }
265721
+ return [...strongestBySpan.values()];
265722
+ }
265723
+ function resolveTriggerStrength(cell2) {
265724
+ return cell2.preferredWidth != null ? Math.max(cell2.preferredWidth, cell2.minContentWidth) : Math.max(cell2.maxContentWidth, cell2.minContentWidth);
265725
+ }
265726
+ function determineGridColumnCount$1(preferredColumnWidths, rows) {
265727
+ return Math.max(preferredColumnWidths.length, ...rows.map((row2) => row2.logicalColumnCount), 0);
265728
+ }
265729
+ function firstCellStart(row2) {
265730
+ return row2.cells[0]?.startColumn ?? row2.logicalColumnCount;
265731
+ }
265732
+ function lastCellEnd(row2) {
265733
+ const lastCell = row2.cells[row2.cells.length - 1];
265734
+ return lastCell ? lastCell.startColumn + lastCell.span : 0;
265735
+ }
265736
+ function sumSpan(widths, startColumn, span) {
265737
+ let total = 0;
265738
+ for (let offset$1 = 0;offset$1 < span; offset$1++)
265739
+ total += widths[startColumn + offset$1] ?? 0;
265740
+ return total;
265741
+ }
265742
+ function sumWidths$1(widths) {
265743
+ return widths.reduce((sum, width) => sum + Math.max(0, width), 0);
265744
+ }
265745
+ function scaleToTargetWidth(widths, targetWidth) {
265746
+ const currentTotal = sumWidths$1(widths);
265747
+ if (currentTotal <= 0 || targetWidth <= 0)
265748
+ return widths;
265749
+ const scale = targetWidth / currentTotal;
265750
+ return widths.map((width) => Math.max(0, width * scale));
265751
+ }
265752
+ function sanitizeWidth(value, fallback) {
265753
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : fallback;
265754
+ }
265755
+ function sanitizeOptionalWidth(value) {
265756
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined;
265757
+ }
265758
+ function buildFallbackResult(layoutMode, minColumnWidth) {
265759
+ return {
265760
+ layoutMode,
265761
+ columnWidths: [minColumnWidth],
265762
+ totalWidth: minColumnWidth,
265763
+ gridColumnCount: 1
265764
+ };
265765
+ }
265766
+ function finalizeResult(layoutMode, widths, minColumnWidth) {
265767
+ if (widths.length === 0)
265768
+ return buildFallbackResult(layoutMode, minColumnWidth);
265769
+ return {
265770
+ layoutMode,
265771
+ columnWidths: widths,
265772
+ totalWidth: sumWidths$1(widths),
265773
+ gridColumnCount: widths.length
265774
+ };
265775
+ }
265776
+ function buildAutoFitWorkingGridInput(block, constraints) {
265777
+ const maxTableWidth = sanitizePositiveNumber(constraints.maxWidth);
265778
+ const layoutMode = resolveLayoutMode(block.attrs?.tableLayout);
265779
+ const preferredTableWidth = resolvePreferredTableWidth(block.attrs?.tableWidth, maxTableWidth);
265780
+ const rawPreferredColumnWidths = normalizePreferredColumnWidths(block.columnWidths);
265781
+ const logicalColumnLimit = resolveTrailingPlaceholderColumnLimit(rawPreferredColumnWidths);
265782
+ let activeRowSpans = [];
265783
+ const rows = block.rows.map((row2) => {
265784
+ const normalized = normalizeRow(row2, preferredTableWidth ?? maxTableWidth, activeRowSpans, logicalColumnLimit);
265785
+ activeRowSpans = normalized.nextActiveRowSpans;
265786
+ return normalized.row;
265787
+ });
265788
+ const preferredColumnWidths = trimTrailingUnoccupiedPlaceholderColumns(rawPreferredColumnWidths, determineGridColumnCount(0, rows));
265789
+ const gridColumnCount = determineGridColumnCount(preferredColumnWidths.length, rows);
265790
+ const preserveAuthoredGrid = shouldPreserveAuthoredGrid({
265791
+ layoutMode,
265792
+ preferredColumnWidths,
265793
+ preferredTableWidth,
265794
+ gridColumnCount
265795
+ });
265796
+ const preserveAutoGrid = shouldPreserveAutoGrid({
265797
+ layoutMode,
265798
+ preferredColumnWidths,
265799
+ preferredTableWidth,
265800
+ gridColumnCount
265801
+ });
265802
+ const preserveExplicitAutoGrid = shouldPreserveExplicitAutoGrid({
265803
+ layoutMode,
265804
+ preferredColumnWidths,
265805
+ preferredTableWidth,
265806
+ gridColumnCount,
265807
+ rows
265808
+ });
265809
+ return {
265810
+ layoutMode,
265811
+ maxTableWidth,
265812
+ ...preserveAuthoredGrid ? { preserveAuthoredGrid } : {},
265813
+ ...preserveAutoGrid ? { preserveAutoGrid } : {},
265814
+ ...preserveExplicitAutoGrid ? { preserveExplicitAutoGrid } : {},
265815
+ preferredTableWidth,
265816
+ preferredColumnWidths,
265817
+ gridColumnCount,
265818
+ rows
265819
+ };
265820
+ }
265821
+ function resolveLayoutMode(tableLayout) {
265822
+ return tableLayout === "fixed" ? "fixed" : "autofit";
265823
+ }
265824
+ function shouldPreserveAuthoredGrid(args$1) {
265825
+ const { layoutMode, preferredColumnWidths, preferredTableWidth, gridColumnCount } = args$1;
265826
+ if (layoutMode !== "fixed")
265827
+ return false;
265828
+ if (preferredTableWidth == null || preferredTableWidth <= 0)
265829
+ return false;
265830
+ if (preferredColumnWidths.length === 0 || preferredColumnWidths.length !== gridColumnCount)
265831
+ return false;
265832
+ const totalPreferredColumnWidth = sumWidths(preferredColumnWidths);
265833
+ return approximatelyEqual(totalPreferredColumnWidth, preferredTableWidth) || isSlightlyUnderPreferredTableWidth(totalPreferredColumnWidth, preferredTableWidth);
265834
+ }
265835
+ function shouldPreserveAutoGrid(args$1) {
265836
+ const { layoutMode, preferredColumnWidths, preferredTableWidth, gridColumnCount } = args$1;
265837
+ if (layoutMode !== "autofit")
265838
+ return false;
265839
+ if (preferredTableWidth != null)
265840
+ return false;
265841
+ if (preferredColumnWidths.length === 0 || preferredColumnWidths.length !== gridColumnCount)
265842
+ return false;
265843
+ if (!hasNonUniformGrid(preferredColumnWidths))
265844
+ return false;
265845
+ return true;
265846
+ }
265847
+ function shouldPreserveExplicitAutoGrid(args$1) {
265848
+ const { layoutMode, preferredColumnWidths, preferredTableWidth, gridColumnCount, rows } = args$1;
265849
+ if (layoutMode !== "autofit")
265850
+ return false;
265851
+ if (preferredTableWidth == null || preferredTableWidth <= 0)
265852
+ return false;
265853
+ if (preferredColumnWidths.length === 0 || preferredColumnWidths.length !== gridColumnCount)
265854
+ return false;
265855
+ if (!hasNonUniformGrid(preferredColumnWidths) && !hasConcreteCellWidthRequest(rows))
265856
+ return false;
265857
+ return approximatelyEqual(sumWidths(preferredColumnWidths), preferredTableWidth);
265858
+ }
265859
+ function hasNonUniformGrid(widths) {
265860
+ if (widths.length <= 1)
265861
+ return true;
265862
+ const firstWidth = widths[0];
265863
+ return widths.some((width) => !approximatelyEqual(width, firstWidth));
265864
+ }
265865
+ function hasConcreteCellWidthRequest(rows) {
265866
+ return rows.some((row2) => row2.cells.some((cell2) => cell2.preferredWidth != null));
265867
+ }
265868
+ function trimTrailingUnoccupiedPlaceholderColumns(widths, occupiedGridColumnCount) {
265869
+ const occupiedCount = Math.max(0, Math.floor(occupiedGridColumnCount));
265870
+ if (occupiedCount <= 0 || widths.length <= occupiedCount)
265871
+ return widths;
265872
+ if (!widths.slice(occupiedCount).every((width) => width <= PLACEHOLDER_COLUMN_MAX_WIDTH))
265873
+ return widths;
265874
+ return widths.slice(0, occupiedCount);
265875
+ }
265876
+ function resolveTrailingPlaceholderColumnLimit(widths) {
265877
+ let trailingPlaceholderCount = 0;
265878
+ for (let index2 = widths.length - 1;index2 >= 0; index2--) {
265879
+ if (widths[index2] > PLACEHOLDER_COLUMN_MAX_WIDTH)
265880
+ break;
265881
+ trailingPlaceholderCount += 1;
265882
+ }
265883
+ if (trailingPlaceholderCount === 0 || trailingPlaceholderCount === widths.length)
265884
+ return;
265885
+ return widths.length - trailingPlaceholderCount;
265886
+ }
265887
+ function normalizePreferredColumnWidths(columnWidths) {
265888
+ if (!Array.isArray(columnWidths))
265889
+ return [];
265890
+ return columnWidths.map((width) => sanitizeNonNegativeNumber(width)).filter((width) => width !== undefined).map((width) => width);
265891
+ }
265892
+ function normalizeRow(row2, percentageBasis, activeRowSpans, logicalColumnLimit) {
265893
+ const rowProps = row2.attrs?.tableRowProperties ?? {};
265894
+ const skippedBeforeCount = sanitizeCount(rowProps.gridBefore);
265895
+ const skippedAfterCount = normalizeSkippedAfterCount(rowProps.gridAfter, rowProps.wAfter, percentageBasis);
265896
+ const cells = Array.isArray(row2.cells) ? row2.cells : [];
265897
+ let columnIndex = advancePastOccupiedColumns(activeRowSpans, 0);
265898
+ const skippedBeforePlacement = buildSkippedColumns(skippedBeforeCount, rowProps.wBefore, percentageBasis, columnIndex, activeRowSpans);
265899
+ columnIndex = skippedBeforePlacement.nextColumnIndex;
265900
+ const normalizedCells = cells.map((cell2) => {
265901
+ columnIndex = advancePastOccupiedColumns(activeRowSpans, columnIndex);
265902
+ const normalizedCell = normalizeCell(cell2, percentageBasis, columnIndex, logicalColumnLimit);
265903
+ columnIndex += normalizedCell.span ?? 1;
265904
+ return normalizedCell;
265905
+ });
265906
+ const skippedAfterPlacement = buildSkippedColumns(skippedAfterCount, rowProps.wAfter, percentageBasis, columnIndex, activeRowSpans);
265907
+ columnIndex = skippedAfterPlacement.nextColumnIndex;
265908
+ const logicalColumnCount = Math.max(columnIndex, resolveOccupiedLogicalColumnCount(activeRowSpans));
265909
+ const nextActiveRowSpans = advanceRowSpans(activeRowSpans);
265910
+ normalizedCells.forEach((cell2, index2) => {
265911
+ const rowSpan = sanitizeCount(cells[index2]?.rowSpan) || 1;
265912
+ if (rowSpan > 1)
265913
+ markRowSpanOccupancy(nextActiveRowSpans, cell2.startColumn, cell2.span ?? 1, rowSpan - 1);
265914
+ });
265915
+ return {
265916
+ row: {
265917
+ skippedBefore: skippedBeforePlacement.columns,
265918
+ cells: normalizedCells,
265919
+ skippedAfter: skippedAfterPlacement.columns,
265920
+ skippedColumns: [...skippedBeforePlacement.columns, ...skippedAfterPlacement.columns],
265921
+ logicalColumnCount
265922
+ },
265923
+ nextActiveRowSpans
265924
+ };
265925
+ }
265926
+ function buildSkippedColumns(count2, preferredWidthMeasurement, percentageBasis, startColumnIndex, activeRowSpans) {
265927
+ if (count2 <= 0)
265928
+ return {
265929
+ columns: [],
265930
+ nextColumnIndex: startColumnIndex
265931
+ };
265932
+ const totalPreferredWidth = resolveMeasurementToPx(preferredWidthMeasurement, percentageBasis);
265933
+ const perColumnPreferredWidth = totalPreferredWidth != null && count2 > 0 ? Math.max(0, totalPreferredWidth / count2) : undefined;
265934
+ const columns = [];
265935
+ let columnIndex = startColumnIndex;
265936
+ for (let index2 = 0;index2 < count2; index2++) {
265937
+ columnIndex = advancePastOccupiedColumns(activeRowSpans, columnIndex);
265938
+ columns.push({
265939
+ columnIndex,
265940
+ preferredWidth: perColumnPreferredWidth,
265941
+ minContentWidth: 0,
265942
+ maxContentWidth: 0
265943
+ });
265944
+ columnIndex += 1;
265945
+ }
265946
+ return {
265947
+ columns,
265948
+ nextColumnIndex: columnIndex
265949
+ };
265950
+ }
265951
+ function normalizeSkippedAfterCount(countValue, preferredWidthMeasurement, percentageBasis) {
265952
+ const count2 = sanitizeCount(countValue);
265953
+ if (count2 <= 0)
265954
+ return 0;
265955
+ const totalPreferredWidth = resolveMeasurementToPx(preferredWidthMeasurement, percentageBasis);
265956
+ if (totalPreferredWidth != null && totalPreferredWidth <= PLACEHOLDER_COLUMN_MAX_WIDTH * count2)
265957
+ return 0;
265958
+ return count2;
265959
+ }
265960
+ function normalizeCell(cell2, percentageBasis, startColumn, logicalColumnLimit) {
265961
+ const cellProps = cell2.attrs?.tableCellProperties ?? {};
265962
+ const rawSpan = sanitizeCount(cell2.colSpan) || 1;
265963
+ const span = logicalColumnLimit != null && startColumn < logicalColumnLimit && startColumn + rawSpan > logicalColumnLimit ? Math.max(1, logicalColumnLimit - startColumn) : rawSpan;
265964
+ return {
265965
+ cellId: cell2.id,
265966
+ startColumn,
265967
+ span,
265968
+ preferredWidth: resolveMeasurementToPx(cellProps.cellWidth, percentageBasis)
265969
+ };
265970
+ }
265971
+ function advancePastOccupiedColumns(activeRowSpans, columnIndex) {
265972
+ let nextColumnIndex = columnIndex;
265973
+ while ((activeRowSpans[nextColumnIndex] ?? 0) > 0)
265974
+ nextColumnIndex += 1;
265975
+ return nextColumnIndex;
265976
+ }
265977
+ function resolveOccupiedLogicalColumnCount(activeRowSpans) {
265978
+ for (let index2 = activeRowSpans.length - 1;index2 >= 0; index2--)
265979
+ if ((activeRowSpans[index2] ?? 0) > 0)
265980
+ return index2 + 1;
265981
+ return 0;
265982
+ }
265983
+ function advanceRowSpans(activeRowSpans) {
265984
+ return activeRowSpans.map((remainingRows) => Math.max(0, remainingRows - 1));
265985
+ }
265986
+ function markRowSpanOccupancy(activeRowSpans, startColumn, span, remainingRows) {
265987
+ const boundedSpan = Math.max(1, sanitizeCount(span));
265988
+ for (let offset$1 = 0;offset$1 < boundedSpan; offset$1++) {
265989
+ const columnIndex = startColumn + offset$1;
265990
+ activeRowSpans[columnIndex] = Math.max(activeRowSpans[columnIndex] ?? 0, remainingRows);
265991
+ }
265992
+ }
265993
+ function determineGridColumnCount(preferredColumnCount, rows) {
265994
+ return Math.max(preferredColumnCount, ...rows.map((row2) => {
265995
+ if ("logicalColumnCount" in row2 && typeof row2.logicalColumnCount === "number")
265996
+ return row2.logicalColumnCount;
265997
+ const skippedBefore = row2.skippedBefore?.length ?? 0;
265998
+ const skippedAfter = row2.skippedAfter?.length ?? 0;
265999
+ const cellSpanTotal = (row2.cells ?? []).reduce((sum, cell2) => sum + Math.max(1, cell2.span ?? 1), 0);
266000
+ return skippedBefore + skippedAfter + cellSpanTotal;
266001
+ }), 0);
266002
+ }
266003
+ function resolvePreferredTableWidth(tableWidth, maxWidth) {
266004
+ const resolvedWidth = resolveTableWidthAttr(tableWidth);
266005
+ if (!resolvedWidth)
266006
+ return;
266007
+ if (resolvedWidth.type === "pct")
266008
+ return Math.round(maxWidth * (resolvedWidth.width / OOXML_PCT_DIVISOR));
266009
+ return resolvedWidth.width;
266010
+ }
266011
+ function resolveMeasurementToPx(measurement, percentageBasis) {
266012
+ if (!measurement || typeof measurement !== "object" || !Number.isFinite(measurement.value))
266013
+ return;
266014
+ const value = measurement.value;
266015
+ switch ((measurement.type ?? "dxa").toLowerCase()) {
266016
+ case "dxa":
266017
+ return value / TWIPS_PER_PX$1;
266018
+ case "pct":
266019
+ return Math.round(percentageBasis * (value / OOXML_PCT_DIVISOR));
266020
+ case "px":
266021
+ case "pixel":
266022
+ return value;
266023
+ case "auto":
266024
+ case "nil":
266025
+ return;
266026
+ default:
266027
+ return value;
266028
+ }
266029
+ }
266030
+ function sanitizeCount(value) {
266031
+ if (typeof value !== "number" || !Number.isFinite(value))
266032
+ return 0;
266033
+ return Math.max(0, Math.floor(value));
266034
+ }
266035
+ function sanitizePositiveNumber(value) {
266036
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0)
266037
+ return 1;
266038
+ return value;
266039
+ }
266040
+ function sanitizeNonNegativeNumber(value) {
266041
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
266042
+ return;
266043
+ return value;
266044
+ }
266045
+ function sumWidths(widths) {
266046
+ return widths.reduce((sum, width) => sum + Math.max(0, width), 0);
266047
+ }
266048
+ function approximatelyEqual(left$1, right$1) {
266049
+ return Math.abs(left$1 - right$1) <= 0.01;
266050
+ }
266051
+ function isSlightlyUnderPreferredTableWidth(totalColumnWidth, preferredTableWidth) {
266052
+ if (totalColumnWidth <= 0 || totalColumnWidth >= preferredTableWidth)
266053
+ return false;
266054
+ return preferredTableWidth - totalColumnWidth <= preferredTableWidth * 0.05;
266055
+ }
266056
+ function buildTableCellContentMetricsCacheKey(cell2, options) {
266057
+ return stableSerialize({
266058
+ maxWidth: Math.max(1, Math.round(options.maxWidth)),
266059
+ layoutEpoch: options.layoutEpoch ?? null,
266060
+ attrs: cell2.attrs ?? null,
266061
+ paragraph: cell2.paragraph ?? null,
266062
+ blocks: cell2.blocks ?? null
266063
+ });
266064
+ }
266065
+ function buildAutoFitTableResultCacheKey(table2, options) {
266066
+ return stableSerialize({
266067
+ id: table2.id,
266068
+ attrs: table2.attrs ?? null,
266069
+ columnWidths: table2.columnWidths ?? null,
266070
+ rowCount: table2.rows.length,
266071
+ maxWidth: Math.max(1, Math.round(options.maxWidth)),
266072
+ layoutEpoch: options.layoutEpoch ?? null,
266073
+ cellMetricKeys: options.cellMetricKeys,
266074
+ workingGrid: {
266075
+ layoutMode: options.workingInput.layoutMode,
266076
+ gridColumnCount: options.workingInput.gridColumnCount,
266077
+ preserveAuthoredGrid: options.workingInput.preserveAuthoredGrid === true,
266078
+ preserveAutoGrid: options.workingInput.preserveAutoGrid === true,
266079
+ preserveExplicitAutoGrid: options.workingInput.preserveExplicitAutoGrid === true,
266080
+ preferredTableWidth: options.workingInput.preferredTableWidth ?? null,
266081
+ preferredColumnWidths: options.workingInput.preferredColumnWidths,
266082
+ rows: options.workingInput.rows.map((row2) => ({
266083
+ logicalColumnCount: row2.logicalColumnCount,
266084
+ skippedColumns: (row2.skippedColumns ?? []).map((column) => ({
266085
+ columnIndex: column.columnIndex,
266086
+ preferredWidth: column.preferredWidth ?? null
266087
+ })),
266088
+ cells: row2.cells.map((cell2) => ({
266089
+ startColumn: cell2.startColumn,
266090
+ span: cell2.span ?? 1,
266091
+ preferredWidth: cell2.preferredWidth ?? null
266092
+ }))
266093
+ }))
266094
+ },
266095
+ fixedLayout: {
266096
+ columnWidths: options.fixedLayout.columnWidths,
266097
+ totalWidth: options.fixedLayout.totalWidth,
266098
+ gridColumnCount: options.fixedLayout.gridColumnCount,
266099
+ preferredTableWidth: options.fixedLayout.preferredTableWidth ?? null
266100
+ }
266101
+ });
266102
+ }
266103
+ function getCachedAutoFitTableResult(cacheKey) {
266104
+ return autoFitTableResultCache.get(cacheKey);
266105
+ }
266106
+ function setCachedAutoFitTableResult(cacheKey, result) {
266107
+ autoFitTableResultCache.set(cacheKey, result);
266108
+ }
266109
+ async function measureTableCellContentMetrics(cell2, options) {
266110
+ const cacheKey = buildTableCellContentMetricsCacheKey(cell2, options);
266111
+ const cached = tableCellMetricsCache.get(cacheKey);
266112
+ if (cached)
266113
+ return cached;
266114
+ const horizontalInsets = getHorizontalCellInsets(cell2);
266115
+ const contentBlocks = cell2.blocks ?? (cell2.paragraph ? [cell2.paragraph] : []);
266116
+ if (contentBlocks.length === 0) {
266117
+ const emptyMetrics = {
266118
+ minWidthPx: horizontalInsets,
266119
+ maxWidthPx: horizontalInsets
266120
+ };
266121
+ tableCellMetricsCache.set(cacheKey, emptyMetrics);
266122
+ return emptyMetrics;
266123
+ }
266124
+ let minContentWidthPx = 0;
266125
+ let maxContentWidthPx = 0;
266126
+ for (const block of contentBlocks) {
266127
+ const metrics = await measureIntrinsicBlockWidthMetrics(block, options);
266128
+ minContentWidthPx = Math.max(minContentWidthPx, metrics.minWidthPx);
266129
+ maxContentWidthPx = Math.max(maxContentWidthPx, metrics.maxWidthPx);
266130
+ }
266131
+ const result = {
266132
+ minWidthPx: minContentWidthPx + horizontalInsets,
266133
+ maxWidthPx: maxContentWidthPx + horizontalInsets
266134
+ };
266135
+ tableCellMetricsCache.set(cacheKey, result);
266136
+ return result;
266137
+ }
266138
+ async function measureTableAutoFitContentMetrics(table2, workingInput, fixedLayout, measureBlock$1) {
266139
+ const tableMeasurementBasis = Math.max(1, fixedLayout.totalWidth);
266140
+ const cellMetricKeys = [];
266141
+ const rowMetrics = await Promise.all(table2.rows.map(async (row2, rowIndex) => {
266142
+ const normalizedRow = workingInput.rows[rowIndex] ?? {};
266143
+ return {
266144
+ rowIndex,
266145
+ cells: await Promise.all(row2.cells.map(async (cell2, cellIndex) => {
266146
+ const normalizedCell = normalizedRow.cells?.[cellIndex];
266147
+ const span = normalizedCell?.span ?? cell2.colSpan ?? 1;
266148
+ const measurementMaxWidth = resolveAutoFitCellMeasurementMaxWidth(cell2, normalizedCell, span, fixedLayout, tableMeasurementBasis, workingInput.gridColumnCount);
266149
+ cellMetricKeys.push(buildTableCellContentMetricsCacheKey(cell2, { maxWidth: measurementMaxWidth }));
266150
+ const metrics = await measureTableCellContentMetrics(cell2, {
266151
+ maxWidth: measurementMaxWidth,
266152
+ measureBlock: measureBlock$1
266153
+ });
266154
+ return {
266155
+ cellIndex,
266156
+ span,
266157
+ preferredWidth: normalizedCell?.preferredWidth,
266158
+ minContentWidth: metrics.minWidthPx,
266159
+ maxContentWidth: metrics.maxWidthPx
266160
+ };
266161
+ }))
266162
+ };
266163
+ }));
266164
+ return {
266165
+ rowMetrics,
266166
+ rows: rowMetrics.map((rowMetrics$1, rowIndex) => {
266167
+ const normalizedRow = workingInput.rows[rowIndex] ?? {};
266168
+ return {
266169
+ skippedBefore: normalizedRow.skippedBefore ?? [],
266170
+ cells: rowMetrics$1.cells.map((cellMetrics) => ({
266171
+ span: cellMetrics.span,
266172
+ preferredWidth: cellMetrics.preferredWidth,
266173
+ minContentWidth: cellMetrics.minContentWidth,
266174
+ maxContentWidth: cellMetrics.maxContentWidth
266175
+ })),
266176
+ skippedAfter: normalizedRow.skippedAfter ?? []
266177
+ };
266178
+ }),
266179
+ cellMetricKeys
266180
+ };
266181
+ }
266182
+ async function measureIntrinsicBlockWidthMetrics(block, options) {
266183
+ if (block.kind === "paragraph")
266184
+ return measureParagraphIntrinsicWidthMetrics(block, options.measureBlock);
266185
+ if (block.kind === "table")
266186
+ return measureNestedTableIntrinsicWidthMetrics(block, options);
266187
+ const intrinsicWidth = getIntrinsicAtomicBlockWidth(block);
266188
+ return {
266189
+ minWidthPx: intrinsicWidth,
266190
+ maxWidthPx: intrinsicWidth
266191
+ };
266192
+ }
266193
+ async function measureParagraphIntrinsicWidthMetrics(paragraph2, measureBlock$1) {
266194
+ const maxLineWidth = (await measureBlock$1(paragraph2, {
266195
+ maxWidth: NO_WRAP_MAX_WIDTH,
266196
+ maxHeight: Infinity
266197
+ })).lines.reduce((widest, line) => Math.max(widest, line.width), 0);
266198
+ return {
266199
+ minWidthPx: measureParagraphMinTokenWidth(paragraph2),
266200
+ maxWidthPx: maxLineWidth
266201
+ };
266202
+ }
266203
+ async function measureNestedTableIntrinsicWidthMetrics(table2, options) {
266204
+ const nestedMeasure = await options.measureBlock(table2, {
266205
+ maxWidth: Math.max(1, options.maxWidth),
266206
+ maxHeight: Infinity
266207
+ });
266208
+ if (nestedMeasure.kind !== "table")
266209
+ return {
266210
+ minWidthPx: 0,
266211
+ maxWidthPx: 0
266212
+ };
266213
+ return {
266214
+ minWidthPx: nestedMeasure.totalWidth,
266215
+ maxWidthPx: nestedMeasure.totalWidth
266216
+ };
266217
+ }
266218
+ function measureParagraphMinTokenWidth(paragraph2) {
266219
+ let widestToken = 0;
266220
+ let currentTokenWidth = 0;
266221
+ const flushToken = () => {
266222
+ widestToken = Math.max(widestToken, currentTokenWidth);
266223
+ currentTokenWidth = 0;
266224
+ };
266225
+ for (const run2 of paragraph2.runs) {
266226
+ if (isExplicitLineBreakRun(run2)) {
266227
+ flushToken();
266228
+ continue;
266229
+ }
266230
+ if (isTextLikeRun(run2)) {
266231
+ accumulateTextRunMinTokenWidth(run2, (width) => {
266232
+ currentTokenWidth += width;
266233
+ }, flushToken);
266234
+ continue;
266235
+ }
266236
+ flushToken();
266237
+ if (run2.kind === "image") {
266238
+ widestToken = Math.max(widestToken, run2.width ?? 0);
266239
+ continue;
266240
+ }
266241
+ if (run2.kind === "fieldAnnotation") {
266242
+ widestToken = Math.max(widestToken, measureFieldAnnotationWidth(run2));
266243
+ continue;
266244
+ }
266245
+ if (run2.kind === "math")
266246
+ widestToken = Math.max(widestToken, run2.width ?? 0);
266247
+ }
266248
+ flushToken();
266249
+ return widestToken;
266250
+ }
266251
+ function accumulateTextRunMinTokenWidth(run2, appendTokenPiece, flushToken) {
266252
+ const font = buildFontString$1(run2);
266253
+ let cursor = 0;
266254
+ for (const boundary of run2.text.matchAll(TOKEN_BOUNDARY_PATTERN)) {
266255
+ const boundaryStart = boundary.index ?? cursor;
266256
+ if (boundaryStart > cursor)
266257
+ appendTokenPiece(measureTextRunTokenSlice(run2, cursor, boundaryStart, font));
266258
+ flushToken();
266259
+ cursor = boundaryStart + boundary[0].length;
266260
+ }
266261
+ if (cursor < run2.text.length)
266262
+ appendTokenPiece(measureTextRunTokenSlice(run2, cursor, run2.text.length, font));
266263
+ }
266264
+ function measureTextRunTokenSlice(run2, start$1, end$1, font) {
266265
+ return getMeasuredTextWidth(applyTextTransform$1(run2.text.slice(start$1, end$1), run2, start$1), font, getLetterSpacing(run2), getCanvasContext$1());
266266
+ }
266267
+ function getIntrinsicAtomicBlockWidth(block) {
266268
+ if (block.kind === "image")
266269
+ return block.width ?? 0;
266270
+ if (block.drawingKind === "image")
266271
+ return block.width ?? 0;
266272
+ if (block.drawingKind === "shapeGroup")
266273
+ return block.size?.width ?? block.geometry.width;
266274
+ return block.geometry.width;
266275
+ }
266276
+ function resolveAutoFitCellMeasurementMaxWidth(cell2, normalizedCell, span, fixedLayout, tableWidthBasis, gridColumnCount) {
266277
+ const outerWidth = resolveFixedPassCellOuterWidth(normalizedCell, span, fixedLayout) ?? normalizedCell?.preferredWidth ?? Math.max(1, tableWidthBasis * (Math.max(1, span) / Math.max(1, gridColumnCount || span || 1)));
266278
+ const padding = cell2.attrs?.padding ?? DEFAULT_CELL_PADDING$1;
266279
+ const leftPadding = padding.left ?? DEFAULT_CELL_PADDING$1.left;
266280
+ const rightPadding = padding.right ?? DEFAULT_CELL_PADDING$1.right;
266281
+ const leftBorder = getCellBorderWidthPx(cell2.attrs?.borders?.left);
266282
+ const rightBorder = getCellBorderWidthPx(cell2.attrs?.borders?.right);
266283
+ return Math.max(1, outerWidth - leftPadding - rightPadding - leftBorder - rightBorder);
266284
+ }
266285
+ function resolveFixedPassCellOuterWidth(normalizedCell, fallbackSpan, fixedLayout) {
266286
+ if (normalizedCell?.startColumn == null)
266287
+ return;
266288
+ const span = Math.max(1, normalizedCell.span ?? fallbackSpan);
266289
+ let width = 0;
266290
+ for (let offset$1 = 0;offset$1 < span; offset$1++)
266291
+ width += fixedLayout.columnWidths[normalizedCell.startColumn + offset$1] ?? 0;
266292
+ return width > 0 ? width : undefined;
266293
+ }
266294
+ function getHorizontalCellInsets(cell2) {
266295
+ const padding = cell2.attrs?.padding ?? DEFAULT_CELL_PADDING$1;
266296
+ const leftPadding = padding.left ?? DEFAULT_CELL_PADDING$1.left;
266297
+ const rightPadding = padding.right ?? DEFAULT_CELL_PADDING$1.right;
266298
+ const leftBorder = getCellBorderWidthPx(cell2.attrs?.borders?.left);
266299
+ const rightBorder = getCellBorderWidthPx(cell2.attrs?.borders?.right);
266300
+ return leftPadding + rightPadding + leftBorder + rightBorder;
266301
+ }
266302
+ function getCellBorderWidthPx(border) {
266303
+ if (!border || border.style === "none")
266304
+ return 0;
266305
+ const width = typeof border.width === "number" ? border.width : 0;
266306
+ if (border.style === "thick")
266307
+ return Math.max(width * 2, 3);
266308
+ return Math.max(0, width);
266309
+ }
266310
+ function getCanvasContext$1() {
266311
+ if (!canvasContext$1) {
266312
+ canvasContext$1 = document.createElement("canvas").getContext("2d");
266313
+ if (!canvasContext$1)
266314
+ throw new Error("Failed to create canvas context for AutoFit cell measurement.");
266315
+ }
266316
+ return canvasContext$1;
266317
+ }
266318
+ function buildFontString$1(run2) {
266319
+ const parts = [];
266320
+ if (run2.italic)
266321
+ parts.push("italic");
266322
+ if (run2.bold)
266323
+ parts.push("bold");
266324
+ parts.push(`${normalizeFontSize$1(run2.fontSize)}px`);
266325
+ parts.push(toCssFontFamily(normalizeFontFamily$1(run2.fontFamily)) ?? normalizeFontFamily$1(run2.fontFamily));
266326
+ return parts.join(" ");
266327
+ }
266328
+ function applyTextTransform$1(text5, run2, startOffset = 0) {
266329
+ const transform = run2.textTransform;
266330
+ if (!text5 || !transform || transform === "none")
266331
+ return text5;
266332
+ if (transform === "uppercase")
266333
+ return text5.toUpperCase();
266334
+ if (transform === "lowercase")
266335
+ return text5.toLowerCase();
266336
+ if (transform === "capitalize")
266337
+ return capitalizeText$1(text5, run2.text ?? text5, startOffset);
266338
+ return text5;
266339
+ }
266340
+ function capitalizeText$1(text5, fullText, startOffset) {
266341
+ let result = "";
266342
+ for (let index2 = 0;index2 < text5.length; index2++) {
266343
+ const absoluteIndex = startOffset + index2;
266344
+ const currentChar = text5[index2];
266345
+ const previousChar = absoluteIndex > 0 ? fullText[absoluteIndex - 1] : "";
266346
+ result += isWordCharacter(currentChar) && !isWordCharacter(previousChar) ? currentChar.toUpperCase() : currentChar;
266347
+ }
266348
+ return result;
266349
+ }
266350
+ function measureFieldAnnotationWidth(run2) {
266351
+ const fontSize = typeof run2.fontSize === "number" ? run2.fontSize : typeof run2.fontSize === "string" ? parseFloat(run2.fontSize) || DEFAULT_FIELD_ANNOTATION_FONT_SIZE$1 : DEFAULT_FIELD_ANNOTATION_FONT_SIZE$1;
266352
+ const font = buildFontString$1({
266353
+ fontFamily: normalizeFontFamily$1(run2.fontFamily ?? "Arial"),
266354
+ fontSize,
266355
+ bold: run2.bold,
266356
+ italic: run2.italic
266357
+ });
266358
+ return getMeasuredTextWidth(applyTextTransform$1(run2.displayLabel || "", { text: run2.displayLabel || "" }), font, 0, getCanvasContext$1()) + (run2.highlighted === false ? 0 : FIELD_ANNOTATION_PILL_PADDING$1);
266359
+ }
266360
+ function isExplicitLineBreakRun(run2) {
266361
+ return run2.kind === "lineBreak" || run2.kind === "break" && run2.breakType === "line";
266362
+ }
266363
+ function isTextLikeRun(run2) {
266364
+ return "text" in run2 && typeof run2.text === "string";
266365
+ }
266366
+ function getLetterSpacing(run2) {
266367
+ return "letterSpacing" in run2 && typeof run2.letterSpacing === "number" ? run2.letterSpacing : 0;
266368
+ }
266369
+ function normalizeFontSize$1(value) {
266370
+ if (typeof value === "number" && Number.isFinite(value) && value > 0)
266371
+ return value;
266372
+ if (typeof value === "string") {
266373
+ const parsed = parseFloat(value);
266374
+ if (Number.isFinite(parsed) && parsed > 0)
266375
+ return parsed;
266376
+ }
266377
+ return 12;
266378
+ }
266379
+ function normalizeFontFamily$1(value) {
266380
+ return typeof value === "string" && value.trim().length > 0 ? value : "Arial";
266381
+ }
266382
+ function stableSerialize(value) {
266383
+ if (value === null || typeof value !== "object")
266384
+ return JSON.stringify(value);
266385
+ if (Array.isArray(value))
266386
+ return `[${value.map((item) => stableSerialize(item)).join(",")}]`;
266387
+ return `{${Object.entries(value).sort(([left$1], [right$1]) => left$1.localeCompare(right$1)).map(([key2, entry]) => `${JSON.stringify(key2)}:${stableSerialize(entry)}`).join(",")}}`;
266388
+ }
266389
+ function isWordCharacter(value) {
266390
+ return /[A-Za-z0-9]/.test(value);
266391
+ }
264848
266392
  function getTableBorderWidthPx(value) {
264849
266393
  if (value == null)
264850
266394
  return 0;
@@ -266335,141 +267879,9 @@ async function measureParagraphBlock(block, maxWidth) {
266335
267879
  ...dropCapMeasure ? { dropCap: dropCapMeasure } : {}
266336
267880
  };
266337
267881
  }
266338
- function resolveTableWidth(attrs, maxWidth) {
266339
- const tableWidthAttr = resolveTableWidthAttr(attrs?.tableWidth);
266340
- if (!tableWidthAttr)
266341
- return;
266342
- if (tableWidthAttr.type === "pct")
266343
- return Math.round(maxWidth * (tableWidthAttr.width / OOXML_PCT_DIVISOR));
266344
- else if (tableWidthAttr.type === "px" || tableWidthAttr.type === "pixel" || tableWidthAttr.type === "dxa")
266345
- return tableWidthAttr.width;
266346
- }
266347
267882
  async function measureTableBlock(block, constraints) {
266348
- const maxWidth = typeof constraints === "number" ? constraints : constraints.maxWidth;
266349
- const resolvedTableWidth = resolveTableWidth(block.attrs, maxWidth);
266350
- let columnWidths;
266351
- const maxCellCount = Math.max(1, Math.max(...block.rows.map((r$1) => r$1.cells.reduce((sum, cell2) => sum + (cell2.colSpan ?? 1), 0))));
266352
- const effectiveTargetWidth = resolvedTableWidth != null ? resolvedTableWidth : maxWidth;
266353
- if (block.columnWidths && block.columnWidths.length > 0) {
266354
- columnWidths = [...block.columnWidths];
266355
- const hasExplicitWidth = resolvedTableWidth != null;
266356
- const hasFixedLayout = block.attrs?.tableLayout === "fixed";
266357
- if (hasExplicitWidth || hasFixedLayout) {
266358
- const totalWidth$1 = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
266359
- const tableWidthType = block.attrs?.tableWidth?.type;
266360
- const targetWidth = hasExplicitWidth ? effectiveTargetWidth : totalWidth$1;
266361
- if ((totalWidth$1 > targetWidth || totalWidth$1 < targetWidth && targetWidth > 0 && (tableWidthType === "pct" || hasExplicitWidth && !hasFixedLayout)) && targetWidth > 0 && totalWidth$1 > 0) {
266362
- const scale = targetWidth / totalWidth$1;
266363
- columnWidths = columnWidths.map((w) => Math.max(1, Math.round(w * scale)));
266364
- const scaledSum = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
266365
- if (scaledSum !== targetWidth && columnWidths.length > 0) {
266366
- const diff = targetWidth - scaledSum;
266367
- columnWidths[columnWidths.length - 1] = Math.max(1, columnWidths[columnWidths.length - 1] + diff);
266368
- }
266369
- }
266370
- } else if (columnWidths.length < maxCellCount) {
266371
- const usedWidth = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
266372
- const remainingWidth = Math.max(0, effectiveTargetWidth - usedWidth);
266373
- const missingColumns = maxCellCount - columnWidths.length;
266374
- const paddingWidth = Math.max(1, Math.floor(remainingWidth / missingColumns));
266375
- columnWidths.push(...Array.from({ length: missingColumns }, () => paddingWidth));
266376
- } else if (columnWidths.length > maxCellCount)
266377
- columnWidths = columnWidths.slice(0, maxCellCount);
266378
- } else {
266379
- const columnWidth = Math.max(1, Math.floor(effectiveTargetWidth / maxCellCount));
266380
- columnWidths = Array.from({ length: maxCellCount }, () => columnWidth);
266381
- }
266382
- const isFixedLayout = block.attrs?.tableLayout === "fixed";
266383
- const gridLooksLikePlaceholder = columnWidths.reduce((a2, b$1) => a2 + b$1, 0) < maxWidth * 0.1;
266384
- if (!isFixedLayout && gridLooksLikePlaceholder) {
266385
- const gridColCount = columnWidths.length;
266386
- const maxContentWidths = new Array(gridColCount).fill(0);
266387
- const autoFitRowspanTracker = new Array(gridColCount).fill(0);
266388
- for (const row2 of block.rows) {
266389
- let colIndex = 0;
266390
- for (const cell2 of row2.cells) {
266391
- const colspan = cell2.colSpan ?? 1;
266392
- const rowspan = cell2.rowSpan ?? 1;
266393
- while (colIndex < gridColCount && autoFitRowspanTracker[colIndex] > 0) {
266394
- autoFitRowspanTracker[colIndex]--;
266395
- colIndex++;
266396
- }
266397
- if (colIndex >= gridColCount)
266398
- break;
266399
- if (colspan === 1) {
266400
- const cellPadding = cell2.attrs?.padding ?? DEFAULT_CELL_PADDING;
266401
- const paddingH = (cellPadding.left ?? 4) + (cellPadding.right ?? 4);
266402
- const cellBlocks = cell2.blocks ?? (cell2.paragraph ? [cell2.paragraph] : []);
266403
- let cellMaxWidth = 0;
266404
- for (const cellBlock of cellBlocks) {
266405
- const maxMeasure = await measureBlock(cellBlock, {
266406
- maxWidth: 99999,
266407
- maxHeight: Infinity
266408
- });
266409
- let blockMaxWidth = 0;
266410
- if (maxMeasure.kind === "paragraph") {
266411
- for (const line of maxMeasure.lines)
266412
- if (line.width > blockMaxWidth)
266413
- blockMaxWidth = line.width;
266414
- } else if (maxMeasure.kind === "image" || maxMeasure.kind === "drawing")
266415
- blockMaxWidth = maxMeasure.width;
266416
- else if (maxMeasure.kind === "table")
266417
- blockMaxWidth = maxMeasure.totalWidth;
266418
- else if (maxMeasure.kind === "list") {
266419
- for (const item of maxMeasure.items)
266420
- if (item.paragraph) {
266421
- const gutterWidth = (item.indentLeft ?? 0) + (item.markerWidth ?? 0);
266422
- for (const line of item.paragraph.lines) {
266423
- const lineTotal = gutterWidth + line.width;
266424
- if (lineTotal > blockMaxWidth)
266425
- blockMaxWidth = lineTotal;
266426
- }
266427
- }
266428
- }
266429
- if (blockMaxWidth > cellMaxWidth)
266430
- cellMaxWidth = blockMaxWidth;
266431
- }
266432
- const totalWidth$1 = cellMaxWidth + paddingH;
266433
- if (totalWidth$1 > maxContentWidths[colIndex])
266434
- maxContentWidths[colIndex] = totalWidth$1;
266435
- }
266436
- if (rowspan > 1)
266437
- for (let c = 0;c < colspan && colIndex + c < gridColCount; c++)
266438
- autoFitRowspanTracker[colIndex + c] = rowspan - 1;
266439
- colIndex += colspan;
266440
- }
266441
- for (let col = colIndex;col < gridColCount; col++)
266442
- if (autoFitRowspanTracker[col] > 0)
266443
- autoFitRowspanTracker[col]--;
266444
- }
266445
- const contentTotal = maxContentWidths.reduce((a2, b$1) => a2 + b$1, 0);
266446
- if (contentTotal > 0)
266447
- if (contentTotal <= maxWidth) {
266448
- for (let i4 = 0;i4 < gridColCount; i4++)
266449
- if (maxContentWidths[i4] > columnWidths[i4])
266450
- columnWidths[i4] = maxContentWidths[i4];
266451
- const expandedTotal = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
266452
- if (expandedTotal > maxWidth && gridColCount > 0) {
266453
- const scale = maxWidth / expandedTotal;
266454
- for (let i4 = 0;i4 < gridColCount; i4++)
266455
- columnWidths[i4] = Math.max(1, Math.round(columnWidths[i4] * scale));
266456
- const scaledSum = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
266457
- if (scaledSum !== maxWidth) {
266458
- const diff = maxWidth - scaledSum;
266459
- columnWidths[gridColCount - 1] = Math.max(1, columnWidths[gridColCount - 1] + diff);
266460
- }
266461
- }
266462
- } else {
266463
- const scale = maxWidth / contentTotal;
266464
- for (let i4 = 0;i4 < gridColCount; i4++)
266465
- columnWidths[i4] = Math.max(1, Math.round(maxContentWidths[i4] * scale));
266466
- const scaledSum = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
266467
- if (scaledSum !== maxWidth && gridColCount > 0) {
266468
- const diff = maxWidth - scaledSum;
266469
- columnWidths[gridColCount - 1] = Math.max(1, columnWidths[gridColCount - 1] + diff);
266470
- }
266471
- }
266472
- }
267883
+ const workingInput = buildAutoFitWorkingGridInput(block, { maxWidth: typeof constraints === "number" ? constraints : constraints.maxWidth });
267884
+ const columnWidths = await resolveRuntimeTableColumnWidths(block, workingInput);
266473
267885
  const gridColumnCount = columnWidths.length;
266474
267886
  const calculateCellWidth = (startCol, colspan) => {
266475
267887
  let width = 0;
@@ -266483,11 +267895,19 @@ async function measureTableBlock(block, constraints) {
266483
267895
  const spanConstraints = [];
266484
267896
  for (let rowIndex = 0;rowIndex < block.rows.length; rowIndex++) {
266485
267897
  const row2 = block.rows[rowIndex];
267898
+ const normalizedRow = workingInput.rows[rowIndex];
266486
267899
  const cellMeasures = [];
266487
267900
  let gridColIndex = 0;
266488
- for (const cell2 of row2.cells) {
267901
+ for (let cellIndex = 0;cellIndex < row2.cells.length; cellIndex++) {
267902
+ const cell2 = row2.cells[cellIndex];
266489
267903
  const colspan = cell2.colSpan ?? 1;
266490
267904
  const rowspan = cell2.rowSpan ?? 1;
267905
+ const preferredStartColumn = normalizedRow?.cells?.[cellIndex]?.startColumn ?? gridColIndex;
267906
+ while (gridColIndex < gridColumnCount && gridColIndex < preferredStartColumn) {
267907
+ if (rowspanTracker[gridColIndex] > 0)
267908
+ rowspanTracker[gridColIndex]--;
267909
+ gridColIndex++;
267910
+ }
266491
267911
  while (gridColIndex < gridColumnCount && rowspanTracker[gridColIndex] > 0) {
266492
267912
  rowspanTracker[gridColIndex]--;
266493
267913
  gridColIndex++;
@@ -266590,18 +268010,48 @@ async function measureTableBlock(block, constraints) {
266590
268010
  const borderWidthH = tableBorderWidths.left + tableBorderWidths.right;
266591
268011
  const borderWidthV = tableBorderWidths.top + tableBorderWidths.bottom;
266592
268012
  const includeOuterBordersInTotal = (block.attrs?.borderCollapse ?? (block.attrs?.cellSpacing != null ? "separate" : "collapse")) === "separate";
266593
- const totalWidth = contentWidth + horizontalGaps + (includeOuterBordersInTotal ? borderWidthH : 0);
266594
- const totalHeight = contentHeight + verticalGaps + (includeOuterBordersInTotal ? borderWidthV : 0);
266595
268013
  return {
266596
268014
  kind: "table",
266597
268015
  rows,
266598
268016
  columnWidths,
266599
- totalWidth,
266600
- totalHeight,
268017
+ totalWidth: contentWidth + horizontalGaps + (includeOuterBordersInTotal ? borderWidthH : 0),
268018
+ totalHeight: contentHeight + verticalGaps + (includeOuterBordersInTotal ? borderWidthV : 0),
266601
268019
  cellSpacingPx: cellSpacingPx > 0 ? cellSpacingPx : undefined,
266602
268020
  tableBorderWidths: borderWidthH > 0 || borderWidthV > 0 ? tableBorderWidths : undefined
266603
268021
  };
266604
268022
  }
268023
+ async function resolveRuntimeTableColumnWidths(block, workingInput) {
268024
+ const fixedLayout = computeFixedTableColumnWidths(workingInput);
268025
+ if (workingInput.layoutMode === "fixed")
268026
+ return fixedLayout.columnWidths;
268027
+ const { contentMetrics, cellMetricKeys } = await buildMeasuredAutoFitContentMetrics(block, workingInput, fixedLayout);
268028
+ const cacheKey = buildAutoFitTableResultCacheKey(block, {
268029
+ maxWidth: workingInput.maxTableWidth,
268030
+ cellMetricKeys,
268031
+ workingInput,
268032
+ fixedLayout
268033
+ });
268034
+ const cached = getCachedAutoFitTableResult(cacheKey);
268035
+ if (cached)
268036
+ return cached.columnWidths;
268037
+ const result = computeAutoFitColumnWidths({
268038
+ workingInput,
268039
+ fixedLayout,
268040
+ contentMetrics: { rowMetrics: contentMetrics.rowMetrics }
268041
+ });
268042
+ setCachedAutoFitTableResult(cacheKey, {
268043
+ columnWidths: result.columnWidths,
268044
+ totalWidth: result.totalWidth
268045
+ });
268046
+ return result.columnWidths;
268047
+ }
268048
+ async function buildMeasuredAutoFitContentMetrics(block, workingInput, fixedLayout) {
268049
+ const contentMetrics = await measureTableAutoFitContentMetrics(block, workingInput, fixedLayout, measureBlock);
268050
+ return {
268051
+ contentMetrics,
268052
+ cellMetricKeys: contentMetrics.cellMetricKeys
268053
+ };
268054
+ }
266605
268055
  async function measureImageBlock(block, constraints) {
266606
268056
  const intrinsic = getIntrinsicImageSize(block, constraints.maxWidth);
266607
268057
  const isBlockBehindDoc = block.anchor?.behindDoc;
@@ -267454,7 +268904,7 @@ var Node$13 = class Node$14 {
267454
268904
  "iPhone",
267455
268905
  "iPod"
267456
268906
  ].includes(navigator.platform);
267457
- }, OOXML_PCT_DIVISOR = 5000, TWIPS_PER_PX$2 = 15, isPlainObject$7 = (value) => value !== null && typeof value === "object" && !Array.isArray(value), OOXML_Z_INDEX_BASE = 251658240, SPACE_CHARS, isAtomicRunKind = (kind) => kind === "image" || kind === "lineBreak" || kind === "break" || kind === "tab" || kind === "fieldAnnotation", isImageLikeRun = (run2) => {
268907
+ }, OOXML_PCT_DIVISOR = 5000, TWIPS_PER_PX$3 = 15, isPlainObject$7 = (value) => value !== null && typeof value === "object" && !Array.isArray(value), OOXML_Z_INDEX_BASE = 251658240, SPACE_CHARS, isAtomicRunKind = (kind) => kind === "image" || kind === "lineBreak" || kind === "break" || kind === "tab" || kind === "fieldAnnotation", isImageLikeRun = (run2) => {
267458
268908
  if (!run2 || typeof run2 !== "object")
267459
268909
  return false;
267460
268910
  return typeof run2.src === "string";
@@ -287025,9 +288475,17 @@ menclose::after {
287025
288475
  inlineBorders = normalizeTableBorders(tableProps.borders);
287026
288476
  if (typeof tableProps.justification === "string")
287027
288477
  hydration.justification = tableProps.justification;
288478
+ const tableIndent = normalizeTableIndent(tableProps.tableIndent);
288479
+ if (tableIndent)
288480
+ hydration.tableIndent = tableIndent;
288481
+ if (typeof tableProps.tableLayout === "string")
288482
+ hydration.tableLayout = tableProps.tableLayout;
287028
288483
  const tableWidth = normalizeTableWidth(tableProps.tableWidth);
287029
288484
  if (tableWidth)
287030
288485
  hydration.tableWidth = tableWidth;
288486
+ const tableCellSpacing = normalizeTableSpacing(tableProps.tableCellSpacing);
288487
+ if (tableCellSpacing)
288488
+ hydration.tableCellSpacing = tableCellSpacing;
287031
288489
  }
287032
288490
  const styleId = effectiveStyleId === null ? undefined : effectiveStyleId ?? (typeof tableNode.attrs?.tableStyleId === "string" ? tableNode.attrs.tableStyleId : undefined);
287033
288491
  if (styleId && context?.translatedLinkedStyles) {
@@ -287054,8 +288512,18 @@ menclose::after {
287054
288512
  hydration.cellPadding = inlinePadding;
287055
288513
  if (!hydration.justification && resolved.justification)
287056
288514
  hydration.justification = resolved.justification;
287057
- if (resolved.tableCellSpacing)
287058
- hydration.tableCellSpacing = resolved.tableCellSpacing;
288515
+ if (!hydration.tableIndent && resolved.tableIndent) {
288516
+ const tableIndent = normalizeTableIndent(resolved.tableIndent);
288517
+ if (tableIndent)
288518
+ hydration.tableIndent = tableIndent;
288519
+ }
288520
+ if (!hydration.tableLayout && resolved.tableLayout)
288521
+ hydration.tableLayout = resolved.tableLayout;
288522
+ if (!hydration.tableCellSpacing && resolved.tableCellSpacing) {
288523
+ const tableCellSpacing = normalizeTableSpacing(resolved.tableCellSpacing);
288524
+ if (tableCellSpacing)
288525
+ hydration.tableCellSpacing = tableCellSpacing;
288526
+ }
287059
288527
  if (!hydration.tableWidth && resolved.tableWidth) {
287060
288528
  const tableWidth = normalizeTableWidth(resolved.tableWidth);
287061
288529
  if (tableWidth)
@@ -287153,7 +288621,41 @@ menclose::after {
287153
288621
  width: raw,
287154
288622
  type: measurement.type
287155
288623
  };
287156
- }, isTableRowNode = (node3) => node3.type === "tableRow" || node3.type === "table_row", isTableCellNode = (node3) => node3.type === "tableCell" || node3.type === "table_cell" || node3.type === "tableHeader" || node3.type === "table_header", convertResolvedCellBorder = (value) => {
288624
+ }, normalizeTableIndent = (value) => {
288625
+ if (!value || typeof value !== "object")
288626
+ return;
288627
+ const measurement = value;
288628
+ const raw = typeof measurement.width === "number" ? measurement.width : measurement.value;
288629
+ if (typeof raw !== "number")
288630
+ return;
288631
+ if (!measurement.type || measurement.type === "px" || measurement.type === "pixel")
288632
+ return {
288633
+ width: raw,
288634
+ type: measurement.type ?? "px"
288635
+ };
288636
+ if (measurement.type === "dxa")
288637
+ return {
288638
+ width: twipsToPx$2(raw),
288639
+ type: "dxa"
288640
+ };
288641
+ return {
288642
+ width: raw,
288643
+ type: measurement.type
288644
+ };
288645
+ }, normalizeTableSpacing = (value) => {
288646
+ if (!value || typeof value !== "object")
288647
+ return;
288648
+ const measurement = value;
288649
+ if (typeof measurement.value !== "number")
288650
+ return;
288651
+ return {
288652
+ value: measurement.value,
288653
+ type: measurement.type ?? "px"
288654
+ };
288655
+ }, isTableRowNode = (node3) => node3.type === "tableRow" || node3.type === "table_row", isTableCellNode = (node3) => node3.type === "tableCell" || node3.type === "table_cell" || node3.type === "tableHeader" || node3.type === "table_header", isTableSkipPlaceholderCell = (node3) => {
288656
+ const placeholder = node3.attrs?.__placeholder;
288657
+ return placeholder === "gridBefore" || placeholder === "gridAfter";
288658
+ }, convertResolvedCellBorder = (value) => {
287157
288659
  if (!value || typeof value !== "object")
287158
288660
  return;
287159
288661
  const border = value;
@@ -287421,6 +288923,8 @@ menclose::after {
287421
288923
  const cells = [];
287422
288924
  const rowCnfStyle = rowNode.attrs?.tableRowProperties?.cnfStyle;
287423
288925
  rowNode.content.forEach((cellNode, cellIndex) => {
288926
+ if (isTableCellNode(cellNode) && isTableSkipPlaceholderCell(cellNode))
288927
+ return;
287424
288928
  const parsedCell = parseTableCell({
287425
288929
  cellNode,
287426
288930
  rowIndex,
@@ -287771,7 +289275,7 @@ menclose::after {
287771
289275
  return true;
287772
289276
  }
287773
289277
  return false;
287774
- }, capitalizeText$2 = (text5) => {
289278
+ }, capitalizeText$3 = (text5) => {
287775
289279
  if (!text5)
287776
289280
  return text5;
287777
289281
  let result = "";
@@ -287781,7 +289285,7 @@ menclose::after {
287781
289285
  result += isWordChar$3(ch) && !isWordChar$3(prevChar) ? ch.toUpperCase() : ch;
287782
289286
  }
287783
289287
  return result;
287784
- }, applyTextTransform$2 = (text5, transform) => {
289288
+ }, applyTextTransform$3 = (text5, transform) => {
287785
289289
  if (!text5 || !transform || transform === "none")
287786
289290
  return text5;
287787
289291
  if (transform === "uppercase")
@@ -287789,7 +289293,7 @@ menclose::after {
287789
289293
  if (transform === "lowercase")
287790
289294
  return text5.toLowerCase();
287791
289295
  if (transform === "capitalize")
287792
- return capitalizeText$2(text5);
289296
+ return capitalizeText$3(text5);
287793
289297
  return text5;
287794
289298
  }, countSpaces = (text5) => {
287795
289299
  let spaces = 0;
@@ -288577,7 +290081,7 @@ menclose::after {
288577
290081
  return false;
288578
290082
  const code7 = char.charCodeAt(0);
288579
290083
  return code7 >= 48 && code7 <= 57 || code7 >= 65 && code7 <= 90 || code7 >= 97 && code7 <= 122 || char === "'";
288580
- }, capitalizeText$1 = (text5, fullText, startOffset) => {
290084
+ }, capitalizeText$2 = (text5, fullText, startOffset) => {
288581
290085
  if (!text5)
288582
290086
  return text5;
288583
290087
  const hasFullText = typeof startOffset === "number" && fullText != null;
@@ -288588,7 +290092,7 @@ menclose::after {
288588
290092
  result += isWordChar$1(ch) && !isWordChar$1(prevChar) ? ch.toUpperCase() : ch;
288589
290093
  }
288590
290094
  return result;
288591
- }, applyTextTransform$1 = (text5, transform, fullText, startOffset) => {
290095
+ }, applyTextTransform$2 = (text5, transform, fullText, startOffset) => {
288592
290096
  if (!text5 || !transform || transform === "none")
288593
290097
  return text5;
288594
290098
  if (transform === "uppercase")
@@ -288596,9 +290100,9 @@ menclose::after {
288596
290100
  if (transform === "lowercase")
288597
290101
  return text5.toLowerCase();
288598
290102
  if (transform === "capitalize")
288599
- return capitalizeText$1(text5, fullText, startOffset);
290103
+ return capitalizeText$2(text5, fullText, startOffset);
288600
290104
  return text5;
288601
- }, DEFAULT_TAB_INTERVAL_TWIPS$1 = 720, TWIPS_PER_PX$1, TAB_EPSILON$1 = 0.1, WIDTH_FUDGE_PX = 0.5, twipsToPx$1 = (twips) => twips / TWIPS_PER_PX$1, pxToTwips$1 = (px) => Math.round(px * TWIPS_PER_PX$1), sanitizeIndent$1 = (value) => typeof value === "number" && Number.isFinite(value) ? Math.max(0, value) : 0, sanitizeDecimalSeparator$1 = (value) => value === "," ? "," : ".", getRunWidth = (run2) => {
290105
+ }, DEFAULT_TAB_INTERVAL_TWIPS$1 = 720, TWIPS_PER_PX$2, TAB_EPSILON$1 = 0.1, WIDTH_FUDGE_PX = 0.5, twipsToPx$1 = (twips) => twips / TWIPS_PER_PX$2, pxToTwips$1 = (px) => Math.round(px * TWIPS_PER_PX$2), sanitizeIndent$1 = (value) => typeof value === "number" && Number.isFinite(value) ? Math.max(0, value) : 0, sanitizeDecimalSeparator$1 = (value) => value === "," ? "," : ".", getRunWidth = (run2) => {
288602
290106
  const width = run2.width;
288603
290107
  return typeof width === "number" ? width : 0;
288604
290108
  }, isLineBreakRun$1 = (run2) => run2.kind === "lineBreak" || run2.kind === "break" && run2.breakType === "line", markerFontString = (run2) => {
@@ -290206,13 +291710,13 @@ menclose::after {
290206
291710
  if (startA == null)
290207
291711
  return false;
290208
291712
  return (endA ?? startA + 1) > startB && startA < endB;
290209
- }, DEFAULT_CELL_PADDING$1, getCellPaddingFromRow = (cellIdx, row2) => {
291713
+ }, DEFAULT_CELL_PADDING$2, getCellPaddingFromRow = (cellIdx, row2) => {
290210
291714
  const padding = row2?.cells?.[cellIdx]?.attrs?.padding ?? {};
290211
291715
  return {
290212
- top: padding.top ?? DEFAULT_CELL_PADDING$1.top,
290213
- bottom: padding.bottom ?? DEFAULT_CELL_PADDING$1.bottom,
290214
- left: padding.left ?? DEFAULT_CELL_PADDING$1.left,
290215
- right: padding.right ?? DEFAULT_CELL_PADDING$1.right
291716
+ top: padding.top ?? DEFAULT_CELL_PADDING$2.top,
291717
+ bottom: padding.bottom ?? DEFAULT_CELL_PADDING$2.bottom,
291718
+ left: padding.left ?? DEFAULT_CELL_PADDING$2.left,
291719
+ right: padding.right ?? DEFAULT_CELL_PADDING$2.right
290216
291720
  };
290217
291721
  }, getCellBlocks = (cell2) => {
290218
291722
  if (!cell2)
@@ -294692,7 +296196,41 @@ menclose::after {
294692
296196
  }
294693
296197
  }, EMUS_PER_INCH = 914400, maxSize = 5000, cache, makeKey = (text5, font, letterSpacing) => {
294694
296198
  return `${text5}|${font}|${letterSpacing || 0}`;
294695
- }, fontMetricsCache, MAX_CACHE_SIZE = 1000, METRICS_TEST_STRING = "MHgypbdlÁÉÍ", computeTabStops, measurementConfig, canvasContext = null, DEFAULT_TAB_INTERVAL_TWIPS = 720, TWIPS_PER_PX, twipsToPx = (twips) => twips / TWIPS_PER_PX, pxToTwips = (px) => Math.round(px * TWIPS_PER_PX), DEFAULT_TAB_INTERVAL_PX, TAB_EPSILON = 0.1, DEFAULT_CELL_PADDING, DEFAULT_DECIMAL_SEPARATOR = ".", ALLOWED_TAB_VALS, FIELD_ANNOTATION_PILL_PADDING = 8, FIELD_ANNOTATION_LINE_HEIGHT_MULTIPLIER = 1.2, FIELD_ANNOTATION_VERTICAL_PADDING = 6, DEFAULT_FIELD_ANNOTATION_FONT_SIZE = 16, DEFAULT_PARAGRAPH_FONT_SIZE = 12, DEFAULT_PARAGRAPH_FONT_FAMILY = "Arial", isValidFontSize = (value) => typeof value === "number" && Number.isFinite(value) && value > 0, normalizeFontSize = (value, fallback = DEFAULT_PARAGRAPH_FONT_SIZE) => {
296199
+ }, fontMetricsCache, MAX_CACHE_SIZE = 1000, METRICS_TEST_STRING = "MHgypbdlÁÉÍ", DEFAULT_MIN_COLUMN_WIDTH = 8, TWIPS_PER_PX$1 = 15, PLACEHOLDER_COLUMN_MAX_WIDTH = 1, DEFAULT_CELL_PADDING$1, DEFAULT_FIELD_ANNOTATION_FONT_SIZE$1 = 16, FIELD_ANNOTATION_PILL_PADDING$1 = 8, TABLE_CELL_METRICS_CACHE_SIZE = 2000, TABLE_AUTOFIT_RESULT_CACHE_SIZE = 500, NO_WRAP_MAX_WIDTH, TOKEN_BOUNDARY_PATTERN, LruCache = class {
296200
+ constructor(maxSize$1) {
296201
+ this.cache = /* @__PURE__ */ new Map;
296202
+ this.maxSize = maxSize$1;
296203
+ }
296204
+ get(key2) {
296205
+ const hit = this.cache.get(key2);
296206
+ if (!hit)
296207
+ return;
296208
+ this.cache.delete(key2);
296209
+ this.cache.set(key2, hit);
296210
+ return hit.value;
296211
+ }
296212
+ set(key2, value) {
296213
+ this.cache.set(key2, { value });
296214
+ this.evictIfNeeded();
296215
+ }
296216
+ clear() {
296217
+ this.cache.clear();
296218
+ }
296219
+ resize(nextSize) {
296220
+ if (!Number.isFinite(nextSize) || nextSize <= 0)
296221
+ return;
296222
+ this.maxSize = nextSize;
296223
+ this.evictIfNeeded();
296224
+ }
296225
+ evictIfNeeded() {
296226
+ while (this.cache.size > this.maxSize) {
296227
+ const oldestKey = this.cache.keys().next().value;
296228
+ if (oldestKey === undefined)
296229
+ break;
296230
+ this.cache.delete(oldestKey);
296231
+ }
296232
+ }
296233
+ }, tableCellMetricsCache, autoFitTableResultCache, canvasContext$1 = null, computeTabStops, measurementConfig, canvasContext = null, DEFAULT_TAB_INTERVAL_TWIPS = 720, TWIPS_PER_PX, twipsToPx = (twips) => twips / TWIPS_PER_PX, pxToTwips = (px) => Math.round(px * TWIPS_PER_PX), DEFAULT_TAB_INTERVAL_PX, TAB_EPSILON = 0.1, DEFAULT_CELL_PADDING, DEFAULT_DECIMAL_SEPARATOR = ".", ALLOWED_TAB_VALS, FIELD_ANNOTATION_PILL_PADDING = 8, FIELD_ANNOTATION_LINE_HEIGHT_MULTIPLIER = 1.2, FIELD_ANNOTATION_VERTICAL_PADDING = 6, DEFAULT_FIELD_ANNOTATION_FONT_SIZE = 16, DEFAULT_PARAGRAPH_FONT_SIZE = 12, DEFAULT_PARAGRAPH_FONT_FAMILY = "Arial", isValidFontSize = (value) => typeof value === "number" && Number.isFinite(value) && value > 0, normalizeFontSize = (value, fallback = DEFAULT_PARAGRAPH_FONT_SIZE) => {
294696
296234
  if (isValidFontSize(value))
294697
296235
  return value;
294698
296236
  if (typeof value === "string") {
@@ -296523,12 +298061,12 @@ menclose::after {
296523
298061
  return;
296524
298062
  console.log(...args$1);
296525
298063
  }, HEADER_FOOTER_INIT_BUDGET_MS = 200, MAX_ZOOM_WARNING_THRESHOLD = 10, MAX_SELECTION_RECTS_PER_USER = 100, SEMANTIC_RESIZE_DEBOUNCE_MS = 120, MIN_SEMANTIC_CONTENT_WIDTH_PX = 1, GLOBAL_PERFORMANCE, PresentationEditor, ICONS, TEXTS, tableActionsOptions;
296526
- var init_src_BzRjWTpH_es = __esm(() => {
298064
+ var init_src_Dinif16O_es = __esm(() => {
296527
298065
  init_rolldown_runtime_Bg48TavK_es();
296528
- init_SuperConverter_BTy5lByv_es();
298066
+ init_SuperConverter_Dchjy0My_es();
296529
298067
  init_jszip_C49i9kUs_es();
296530
298068
  init_uuid_qzgm05fK_es();
296531
- init_create_headless_toolbar_k6nNYL53_es();
298069
+ init_create_headless_toolbar_CEcVKzGV_es();
296532
298070
  init_constants_DrU4EASo_es();
296533
298071
  init_dist_B8HfvhaK_es();
296534
298072
  init_unified_Dsuw2be5_es();
@@ -323231,7 +324769,7 @@ function print() { __p += __j.call(arguments, '') }
323231
324769
  "even",
323232
324770
  "odd"
323233
324771
  ];
323234
- TWIPS_PER_PX$1 = 1440 / 96;
324772
+ TWIPS_PER_PX$2 = 1440 / 96;
323235
324773
  init_dist4();
323236
324774
  measureCache = new MeasureCache;
323237
324775
  headerMeasureCache = new HeaderFooterLayoutCache;
@@ -323260,7 +324798,7 @@ function print() { __p += __j.call(arguments, '') }
323260
324798
  workerRoundTrip: 10,
323261
324799
  layoutStaleness: 100
323262
324800
  });
323263
- DEFAULT_CELL_PADDING$1 = {
324801
+ DEFAULT_CELL_PADDING$2 = {
323264
324802
  top: 0,
323265
324803
  bottom: 0,
323266
324804
  left: 4,
@@ -327867,6 +329405,16 @@ function print() { __p += __j.call(arguments, '') }
327867
329405
  EMUS_PER_INCH / 96;
327868
329406
  cache = /* @__PURE__ */ new Map;
327869
329407
  fontMetricsCache = /* @__PURE__ */ new Map;
329408
+ DEFAULT_CELL_PADDING$1 = {
329409
+ top: 0,
329410
+ right: 4,
329411
+ bottom: 0,
329412
+ left: 4
329413
+ };
329414
+ NO_WRAP_MAX_WIDTH = Number.MAX_SAFE_INTEGER;
329415
+ TOKEN_BOUNDARY_PATTERN = /[ \t\f\v\-\u00ad\u2010\u2012\u2013\u2014\u200b\u2028\u2029]+|\r\n|\r|\n|\u2028|\u2029/gu;
329416
+ tableCellMetricsCache = new LruCache(TABLE_CELL_METRICS_CACHE_SIZE);
329417
+ autoFitTableResultCache = new LruCache(TABLE_AUTOFIT_RESULT_CACHE_SIZE);
327870
329418
  ({ computeTabStops } = engines_exports);
327871
329419
  measurementConfig = {
327872
329420
  mode: "browser",
@@ -333739,11 +335287,11 @@ function print() { __p += __j.call(arguments, '') }
333739
335287
  ];
333740
335288
  });
333741
335289
 
333742
- // ../../packages/superdoc/dist/chunks/create-super-doc-ui-BUfd0WN3.es.js
335290
+ // ../../packages/superdoc/dist/chunks/create-super-doc-ui-HW4PZyuU.es.js
333743
335291
  var ALL_TOOLBAR_COMMAND_IDS, EMPTY_ACTIVE_IDS;
333744
- var init_create_super_doc_ui_BUfd0WN3_es = __esm(() => {
333745
- init_SuperConverter_BTy5lByv_es();
333746
- init_create_headless_toolbar_k6nNYL53_es();
335292
+ var init_create_super_doc_ui_HW4PZyuU_es = __esm(() => {
335293
+ init_SuperConverter_Dchjy0My_es();
335294
+ init_create_headless_toolbar_CEcVKzGV_es();
333747
335295
  ALL_TOOLBAR_COMMAND_IDS = Object.keys(createToolbarRegistry());
333748
335296
  EMPTY_ACTIVE_IDS = Object.freeze([]);
333749
335297
  });
@@ -333761,16 +335309,16 @@ var init_zipper_BxRAi0_5_es = __esm(() => {
333761
335309
 
333762
335310
  // ../../packages/superdoc/dist/super-editor.es.js
333763
335311
  var init_super_editor_es = __esm(() => {
333764
- init_src_BzRjWTpH_es();
333765
- init_SuperConverter_BTy5lByv_es();
335312
+ init_src_Dinif16O_es();
335313
+ init_SuperConverter_Dchjy0My_es();
333766
335314
  init_jszip_C49i9kUs_es();
333767
335315
  init_xml_js_CqGKpaft_es();
333768
- init_create_headless_toolbar_k6nNYL53_es();
335316
+ init_create_headless_toolbar_CEcVKzGV_es();
333769
335317
  init_constants_DrU4EASo_es();
333770
335318
  init_dist_B8HfvhaK_es();
333771
335319
  init_unified_Dsuw2be5_es();
333772
335320
  init_DocxZipper_CUX64E5K_es();
333773
- init_create_super_doc_ui_BUfd0WN3_es();
335321
+ init_create_super_doc_ui_HW4PZyuU_es();
333774
335322
  init_ui_CGB3qmy3_es();
333775
335323
  init_eventemitter3_BJrNoN9D_es();
333776
335324
  init_errors_C_DoKMoN_es();