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

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 +1812 -257
  2. package/package.json +8 -8
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-DAF1K-X-.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) {
@@ -208961,6 +209025,7 @@ function createStructuredContentSelectPlugin(editor) {
208961
209025
  return false;
208962
209026
  const { state } = view;
208963
209027
  const { selection } = state;
209028
+ const isEditableSlotText = (text5) => text5.replace(/\u200B/g, "").length === 0;
208964
209029
  const resolveBoundaryExit = ($pos) => {
208965
209030
  for (let depth = $pos.depth;depth > 0; depth -= 1) {
208966
209031
  const node3 = $pos.node(depth);
@@ -208972,9 +209037,13 @@ function createStructuredContentSelectPlugin(editor) {
208972
209037
  const beforePos = nodePos;
208973
209038
  const afterPos = nodePos + node3.nodeSize;
208974
209039
  if (selection.empty) {
208975
- if (event.key === "ArrowRight" && selection.from >= contentTo - 1)
209040
+ const trailingSlice = state.doc.textBetween(selection.from, contentTo, "", INLINE_LEAF_TEXT);
209041
+ const leadingSlice = state.doc.textBetween(contentFrom, selection.from, "", INLINE_LEAF_TEXT);
209042
+ const onlyTrailingEditableSlots = trailingSlice.length > 0 && isEditableSlotText(trailingSlice);
209043
+ const onlyLeadingEditableSlots = leadingSlice.length > 0 && isEditableSlotText(leadingSlice);
209044
+ if (event.key === "ArrowRight" && (selection.from >= contentTo - 1 || onlyTrailingEditableSlots))
208976
209045
  return afterPos;
208977
- if (event.key === "ArrowLeft" && selection.from <= contentFrom + 1)
209046
+ if (event.key === "ArrowLeft" && (selection.from <= contentFrom + 1 || onlyLeadingEditableSlots))
208978
209047
  return beforePos;
208979
209048
  return null;
208980
209049
  }
@@ -234562,29 +234631,12 @@ function toTableFailure(code7, message, details) {
234562
234631
  }
234563
234632
  };
234564
234633
  }
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
234634
  function syncExtractedTableAttrs(tp) {
234583
234635
  const extracted = {};
234584
234636
  extracted.tableStyleId = tp.tableStyleId ?? null;
234585
234637
  extracted.justification = tp.justification ?? null;
234586
234638
  extracted.tableLayout = tp.tableLayout ?? null;
234587
- extracted.borders = convertTableBordersToPixelUnits(tp.borders) ?? tp.borders ?? null;
234639
+ extracted.borders = convertTableBordersToPixelUnits(tp.borders) ?? {};
234588
234640
  const indent2 = tp.tableIndent;
234589
234641
  if (indent2?.value != null)
234590
234642
  extracted.tableIndent = {
@@ -234596,7 +234648,7 @@ function syncExtractedTableAttrs(tp) {
234596
234648
  const spacing = tp.tableCellSpacing;
234597
234649
  if (spacing?.value != null) {
234598
234650
  extracted.tableCellSpacing = {
234599
- w: String(spacing.value),
234651
+ value: twipsToPixels(spacing.value),
234600
234652
  type: spacing.type ?? "dxa"
234601
234653
  };
234602
234654
  extracted.borderCollapse = "separate";
@@ -234604,23 +234656,23 @@ function syncExtractedTableAttrs(tp) {
234604
234656
  extracted.tableCellSpacing = null;
234605
234657
  extracted.borderCollapse = null;
234606
234658
  }
234607
- const tw = tp.tableWidth;
234608
- if (tw)
234609
- if (tw.type === "pct" && typeof tw.value === "number")
234659
+ const width = tp.tableWidth;
234660
+ if (width)
234661
+ if (width.type === "pct" && typeof width.value === "number")
234610
234662
  extracted.tableWidth = {
234611
- value: tw.value,
234663
+ value: width.value,
234612
234664
  type: "pct"
234613
234665
  };
234614
- else if (tw.type === "auto")
234666
+ else if (width.type === "auto")
234615
234667
  extracted.tableWidth = {
234616
234668
  width: 0,
234617
234669
  type: "auto"
234618
234670
  };
234619
- else if (tw.value != null) {
234620
- const widthPx = twipsToPixels(tw.value);
234671
+ else if (width.value != null) {
234672
+ const widthPx = twipsToPixels(width.value);
234621
234673
  extracted.tableWidth = widthPx != null ? {
234622
234674
  width: widthPx,
234623
- type: tw.type
234675
+ type: width.type
234624
234676
  } : null;
234625
234677
  } else
234626
234678
  extracted.tableWidth = null;
@@ -234635,6 +234687,95 @@ function convertTableBordersToPixelUnits(value) {
234635
234687
  mapBorderSizes(clone, eighthPointsToPixels);
234636
234688
  return Object.keys(clone).length > 0 ? clone : undefined;
234637
234689
  }
234690
+ function buildWidthAuthoringTableAttrs(currentAttrs, attrOverrides = {}, tablePropertyOverrides = {}) {
234691
+ const currentTableProps = currentAttrs.tableProperties ?? {};
234692
+ const nextTableWidth = resolveWidthAuthoringTableWidth(currentAttrs, attrOverrides, tablePropertyOverrides);
234693
+ const updatedTableProps = {
234694
+ ...currentTableProps,
234695
+ ...tablePropertyOverrides,
234696
+ tableLayout: "fixed"
234697
+ };
234698
+ if (nextTableWidth)
234699
+ updatedTableProps.tableWidth = nextTableWidth;
234700
+ else
234701
+ delete updatedTableProps.tableWidth;
234702
+ return {
234703
+ ...currentAttrs,
234704
+ tableProperties: updatedTableProps,
234705
+ ...attrOverrides,
234706
+ ...syncExtractedTableAttrs(updatedTableProps),
234707
+ userEdited: true
234708
+ };
234709
+ }
234710
+ function resolveWidthAuthoringTableWidth(currentAttrs, attrOverrides, tablePropertyOverrides) {
234711
+ const explicitOverride = normalizeTableWidthMeasurement(tablePropertyOverrides.tableWidth);
234712
+ if (explicitOverride)
234713
+ return explicitOverride;
234714
+ const gridWidth = sumGridColumnTwips(attrOverrides.grid ?? currentAttrs.grid);
234715
+ if (gridWidth != null)
234716
+ return {
234717
+ value: gridWidth,
234718
+ type: "dxa"
234719
+ };
234720
+ return null;
234721
+ }
234722
+ function sumGridColumnTwips(grid) {
234723
+ const columns = normalizeGridColumns$1(grid);
234724
+ if (!columns || columns.length === 0)
234725
+ return null;
234726
+ const total = columns.reduce((sum, column) => sum + column.col, 0);
234727
+ return total > 0 ? total : null;
234728
+ }
234729
+ function normalizeGridColumns$1(grid) {
234730
+ if (Array.isArray(grid)) {
234731
+ const columns = grid.map((width) => normalizeGridWidth$1(width)).filter((width) => width != null);
234732
+ return columns.length > 0 ? columns : null;
234733
+ }
234734
+ if (grid && typeof grid === "object") {
234735
+ const rawColWidths = grid.colWidths;
234736
+ if (Array.isArray(rawColWidths)) {
234737
+ const columns = rawColWidths.map((width) => normalizeGridWidth$1(width)).filter((width) => width != null);
234738
+ return columns.length > 0 ? columns : null;
234739
+ }
234740
+ }
234741
+ return null;
234742
+ }
234743
+ function normalizeGridWidth$1(width) {
234744
+ if (typeof width === "number" && Number.isFinite(width) && width > 0)
234745
+ return { col: Math.round(width) };
234746
+ const value = width?.col;
234747
+ if (typeof value === "number" && Number.isFinite(value) && value > 0)
234748
+ return { col: Math.round(value) };
234749
+ return null;
234750
+ }
234751
+ function normalizeTableWidthMeasurement(width) {
234752
+ if (!width || typeof width !== "object")
234753
+ return null;
234754
+ const value = width.value;
234755
+ if (width.type !== "dxa" || typeof value !== "number" || !Number.isFinite(value) || value <= 0)
234756
+ return null;
234757
+ return {
234758
+ value: Math.round(value),
234759
+ type: "dxa"
234760
+ };
234761
+ }
234762
+ function createSeparatorParagraph(schema) {
234763
+ const paragraphType = schema.nodes.paragraph;
234764
+ if (!paragraphType)
234765
+ return null;
234766
+ const separatorAttrs = {
234767
+ sdBlockId: v4_default(),
234768
+ paraId: generateDocxHexId()
234769
+ };
234770
+ return paragraphType.createAndFill(separatorAttrs) ?? paragraphType.createAndFill();
234771
+ }
234772
+ function buildTableSuccess(tableAddress, trackedChangeRefs) {
234773
+ return {
234774
+ success: true,
234775
+ table: tableAddress,
234776
+ trackedChangeRefs
234777
+ };
234778
+ }
234638
234779
  function normalizeGridWidth(width) {
234639
234780
  if (typeof width === "number" && Number.isFinite(width))
234640
234781
  return { col: Math.round(width) };
@@ -234697,6 +234838,30 @@ function removeGridColumnWidth(grid, deleteIndex) {
234697
234838
  columns: colWidths
234698
234839
  });
234699
234840
  }
234841
+ function buildFirstRowCellWidthProps(attrs, cellStartCol, colspan, colwidth, gridColumns) {
234842
+ const currentCellProps = attrs.tableCellProperties && typeof attrs.tableCellProperties === "object" ? attrs.tableCellProperties : {};
234843
+ const spanTwips = resolveSpanWidthTwips(cellStartCol, colspan, colwidth, gridColumns);
234844
+ if (spanTwips == null)
234845
+ return Object.keys(currentCellProps).length > 0 ? currentCellProps : undefined;
234846
+ return {
234847
+ ...currentCellProps,
234848
+ cellWidth: {
234849
+ value: spanTwips,
234850
+ type: "dxa"
234851
+ }
234852
+ };
234853
+ }
234854
+ function resolveSpanWidthTwips(cellStartCol, colspan, colwidth, gridColumns) {
234855
+ const boundedSpan = Math.max(1, colspan);
234856
+ if (Array.isArray(gridColumns) && cellStartCol >= 0 && cellStartCol + boundedSpan <= gridColumns.length) {
234857
+ const gridSpanTwips = gridColumns.slice(cellStartCol, cellStartCol + boundedSpan).reduce((sum, column) => sum + normalizeGridWidth(column).col, 0);
234858
+ if (gridSpanTwips > 0)
234859
+ return gridSpanTwips;
234860
+ }
234861
+ const spanWidthPx = colwidth.slice(0, boundedSpan).reduce((sum, width) => sum + (Number.isFinite(width) ? width : 0), 0);
234862
+ if (spanWidthPx > 0)
234863
+ return Math.round(spanWidthPx * PIXELS_TO_TWIPS);
234864
+ }
234700
234865
  function normalizeCellAttrsForSingleCell(attrs) {
234701
234866
  const currentColwidth = Array.isArray(attrs.colwidth) ? attrs.colwidth : null;
234702
234867
  const tableCellProperties = { ...attrs.tableCellProperties ?? {} };
@@ -235574,8 +235739,13 @@ function tablesSetColumnWidthAdapter(editor, input2, options) {
235574
235739
  const tablePos = table2.candidate.pos;
235575
235740
  const tableStart = tablePos + 1;
235576
235741
  const tableNode = table2.candidate.node;
235742
+ const tableAttrs = tableNode.attrs;
235577
235743
  const map$12 = TableMap.get(tableNode);
235578
235744
  const widthPx = Math.round(input2.widthPt * (96 / 72));
235745
+ const normalizedGrid = normalizeGridColumns(tableAttrs.grid);
235746
+ const nextGridColumns = normalizedGrid?.columns.slice();
235747
+ if (nextGridColumns && columnIndex < nextGridColumns.length)
235748
+ nextGridColumns[columnIndex] = { col: Math.round(input2.widthPt * POINTS_TO_TWIPS) };
235579
235749
  const processed = /* @__PURE__ */ new Set;
235580
235750
  for (let row2 = 0;row2 < map$12.height; row2++) {
235581
235751
  const index2 = row2 * map$12.width + columnIndex;
@@ -235589,29 +235759,31 @@ function tablesSetColumnWidthAdapter(editor, input2, options) {
235589
235759
  const attrs = cell2.attrs;
235590
235760
  const colspan = attrs.colspan || 1;
235591
235761
  const colwidth = attrs.colwidth?.slice() ?? [];
235592
- const withinCol = columnIndex - map$12.colCount(pos);
235762
+ const cellStartCol = map$12.colCount(pos);
235763
+ const withinCol = columnIndex - cellStartCol;
235593
235764
  while (colwidth.length < colspan)
235594
235765
  colwidth.push(0);
235595
235766
  colwidth[withinCol] = widthPx;
235596
- tr.setNodeMarkup(tableStart + pos, null, {
235767
+ const nextAttrs = {
235597
235768
  ...attrs,
235598
235769
  colwidth
235599
- });
235770
+ };
235771
+ if (row2 === 0) {
235772
+ const nextCellProps = buildFirstRowCellWidthProps(attrs, cellStartCol, colspan, colwidth, nextGridColumns);
235773
+ if (nextCellProps)
235774
+ nextAttrs.tableCellProperties = nextCellProps;
235775
+ else
235776
+ delete nextAttrs.tableCellProperties;
235777
+ }
235778
+ tr.setNodeMarkup(tableStart + pos, null, nextAttrs);
235600
235779
  }
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
235780
+ const tableAttrUpdates = {};
235781
+ if (normalizedGrid && nextGridColumns)
235782
+ tableAttrUpdates.grid = serializeGridColumns(tableAttrs.grid, {
235783
+ ...normalizedGrid,
235784
+ columns: nextGridColumns
235613
235785
  });
235614
- }
235786
+ tr.setNodeMarkup(tablePos, null, buildWidthAuthoringTableAttrs(tableAttrs, tableAttrUpdates));
235615
235787
  applyDirectMutationMeta(tr);
235616
235788
  editor.dispatch(tr);
235617
235789
  clearIndexCache(editor);
@@ -235635,7 +235807,10 @@ function tablesDistributeColumnsAdapter(editor, input2, options) {
235635
235807
  const tablePos = candidate.pos;
235636
235808
  const tableStart = tablePos + 1;
235637
235809
  const tableNode = candidate.node;
235810
+ const tableAttrs = tableNode.attrs;
235638
235811
  const map$12 = TableMap.get(tableNode);
235812
+ const normalizedGrid = normalizeGridColumns(tableAttrs.grid);
235813
+ const nextGridColumns = normalizedGrid?.columns.slice();
235639
235814
  const rangeStart = input2.columnRange?.start ?? 0;
235640
235815
  const rangeEnd = input2.columnRange?.end ?? map$12.width - 1;
235641
235816
  const rangeWidth = rangeEnd - rangeStart + 1;
@@ -235651,6 +235826,12 @@ function tablesDistributeColumnsAdapter(editor, input2, options) {
235651
235826
  totalWidth += colwidth?.[withinCol] ?? 100;
235652
235827
  }
235653
235828
  const evenWidth = Math.round(totalWidth / rangeWidth);
235829
+ if (nextGridColumns) {
235830
+ const evenWidthTwips = Math.max(1, Math.round(evenWidth * PIXELS_TO_TWIPS));
235831
+ const maxColumn = Math.min(rangeEnd, nextGridColumns.length - 1);
235832
+ for (let col = Math.max(rangeStart, 0);col <= maxColumn; col++)
235833
+ nextGridColumns[col] = { col: evenWidthTwips };
235834
+ }
235654
235835
  const processed = /* @__PURE__ */ new Set;
235655
235836
  for (let row2 = 0;row2 < map$12.height; row2++)
235656
235837
  for (let col = rangeStart;col <= rangeEnd; col++) {
@@ -235673,29 +235854,26 @@ function tablesDistributeColumnsAdapter(editor, input2, options) {
235673
235854
  if (absCol >= rangeStart && absCol <= rangeEnd)
235674
235855
  newColwidth[c] = evenWidth;
235675
235856
  }
235676
- tr.setNodeMarkup(tableStart + pos, null, {
235857
+ const nextAttrs = {
235677
235858
  ...attrs,
235678
235859
  colwidth: newColwidth
235679
- });
235860
+ };
235861
+ if (row2 === 0) {
235862
+ const nextCellProps = buildFirstRowCellWidthProps(attrs, cellStartCol, colspan, newColwidth, nextGridColumns);
235863
+ if (nextCellProps)
235864
+ nextAttrs.tableCellProperties = nextCellProps;
235865
+ else
235866
+ delete nextAttrs.tableCellProperties;
235867
+ }
235868
+ tr.setNodeMarkup(tableStart + pos, null, nextAttrs);
235680
235869
  }
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 };
235870
+ const tableAttrUpdates = {};
235871
+ if (normalizedGrid && nextGridColumns)
235693
235872
  tableAttrUpdates.grid = serializeGridColumns(tableAttrs.grid, {
235694
235873
  ...normalizedGrid,
235695
- columns: newColumns
235874
+ columns: nextGridColumns
235696
235875
  });
235697
- }
235698
- tr.setNodeMarkup(tablePos, null, tableAttrUpdates);
235876
+ tr.setNodeMarkup(tablePos, null, buildWidthAuthoringTableAttrs(tableAttrs, tableAttrUpdates));
235699
235877
  applyDirectMutationMeta(tr);
235700
235878
  editor.dispatch(tr);
235701
235879
  clearIndexCache(editor);
@@ -236279,6 +236457,10 @@ function tablesSetCellPropertiesAdapter(editor, input2, options) {
236279
236457
  }
236280
236458
  };
236281
236459
  tr.setNodeMarkup(cellPos, null, newAttrs);
236460
+ if (input2.preferredWidthPt !== undefined) {
236461
+ const tableAttrs = table2.candidate.node.attrs;
236462
+ tr.setNodeMarkup(table2.candidate.pos, null, buildWidthAuthoringTableAttrs(tableAttrs));
236463
+ }
236282
236464
  applyDirectMutationMeta(tr);
236283
236465
  editor.dispatch(tr);
236284
236466
  clearIndexCache(editor);
@@ -250810,7 +250992,7 @@ function normalizeFieldAnnotationMetadata(attrs) {
250810
250992
  borderColor: normalizeColorValue2(attrs.borderColor),
250811
250993
  highlighted: toBoolean$2(attrs.highlighted, true),
250812
250994
  fontFamily: toNullableString(attrs.fontFamily),
250813
- fontSize: normalizeFontSize$1(attrs.fontSize),
250995
+ fontSize: normalizeFontSize$2(attrs.fontSize),
250814
250996
  textColor: normalizeColorValue2(attrs.textColor) ?? null,
250815
250997
  textHighlight: normalizeColorValue2(attrs.textHighlight) ?? null,
250816
250998
  linkUrl: toNullableString(attrs.linkUrl),
@@ -250904,7 +251086,7 @@ function normalizeColorValue2(value) {
250904
251086
  return;
250905
251087
  return trimmed;
250906
251088
  }
250907
- function normalizeFontSize$1(value) {
251089
+ function normalizeFontSize$2(value) {
250908
251090
  if (value == null)
250909
251091
  return null;
250910
251092
  if (typeof value === "number")
@@ -252506,11 +252688,15 @@ function tableNodeToBlock(node3, { nextBlockId, positions, storyKey, trackedChan
252506
252688
  tableAttrs.tableWidth = hydratedTableStyle.tableWidth;
252507
252689
  if (node3.attrs?.tableIndent && typeof node3.attrs.tableIndent === "object")
252508
252690
  tableAttrs.tableIndent = { ...node3.attrs.tableIndent };
252691
+ else if (hydratedTableStyle?.tableIndent)
252692
+ tableAttrs.tableIndent = { ...hydratedTableStyle.tableIndent };
252509
252693
  if (defaultCellPadding && typeof defaultCellPadding === "object")
252510
252694
  tableAttrs.defaultCellPadding = { ...defaultCellPadding };
252511
252695
  const tableLayout = node3.attrs?.tableLayout;
252512
252696
  if (tableLayout)
252513
252697
  tableAttrs.tableLayout = tableLayout;
252698
+ else if (hydratedTableStyle?.tableLayout)
252699
+ tableAttrs.tableLayout = hydratedTableStyle.tableLayout;
252514
252700
  const tableProperties = node3.attrs?.tableProperties;
252515
252701
  if (tableProperties && typeof tableProperties === "object")
252516
252702
  tableAttrs.tableProperties = tableProperties;
@@ -257429,7 +257615,7 @@ function measureCharacterX(block, line, charOffset, availableWidthOverride, alig
257429
257615
  }
257430
257616
  const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text ?? "";
257431
257617
  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);
257618
+ 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
257619
  if (currentCharOffset + runLength >= charOffset) {
257434
257620
  const offsetInRun = charOffset - currentCharOffset;
257435
257621
  ctx$1.font = getRunFontString(run2);
@@ -257478,7 +257664,7 @@ function measureCharacterXSegmentBased(block, line, charOffset, ctx$1) {
257478
257664
  return segmentBaseX + (offsetInSegment > 0 ? segment.width ?? 0 : 0);
257479
257665
  if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math")
257480
257666
  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);
257667
+ const textUpToTarget = applyTextTransform$3(run2.text ?? "", "textTransform" in run2 ? run2.textTransform : undefined).slice(segment.fromChar, segment.toChar).slice(0, offsetInSegment);
257482
257668
  ctx$1.font = getRunFontString(run2);
257483
257669
  const measured = ctx$1.measureText(textUpToTarget);
257484
257670
  const spacingWidth = computeLetterSpacingWidth(run2, offsetInSegment, segmentChars);
@@ -257571,7 +257757,7 @@ function findCharacterAtX(block, line, x, pmStart, availableWidthOverride, align
257571
257757
  }
257572
257758
  const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text ?? "";
257573
257759
  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);
257760
+ 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
257761
  if (runLength === 0)
257576
257762
  continue;
257577
257763
  ctx$1.font = getRunFontString(run2);
@@ -258214,7 +258400,7 @@ function measureRunSliceWidth(run2, fromChar, toChar) {
258214
258400
  const context = getCtx();
258215
258401
  const fullText = runText(run2);
258216
258402
  const transform = isTextRun$3(run2) ? run2.textTransform : undefined;
258217
- const text5 = applyTextTransform$1(fullText.slice(fromChar, toChar), transform, fullText, fromChar);
258403
+ const text5 = applyTextTransform$2(fullText.slice(fromChar, toChar), transform, fullText, fromChar);
258218
258404
  if (!context) {
258219
258405
  const size$1 = (isTextRun$3(run2) ? run2 : null)?.fontSize ?? 16;
258220
258406
  return Math.max(1, text5.length * (size$1 * 0.6));
@@ -261481,7 +261667,7 @@ function areNumberListsEqual(left$1, right$1) {
261481
261667
  return false;
261482
261668
  return true;
261483
261669
  }
261484
- function isWordCharacter(char) {
261670
+ function isWordCharacter$1(char) {
261485
261671
  if (!char)
261486
261672
  return false;
261487
261673
  return WORD_CHARACTER_REGEX.test(char);
@@ -261564,17 +261750,17 @@ function computeWordSelectionRangeAt(state, pos) {
261564
261750
  const parentStart = textblockPos.start();
261565
261751
  const parentEnd = textblockPos.end();
261566
261752
  const sampleEnd = Math.min(pos + 1, parentEnd);
261567
- if (!isWordCharacter(state.doc.textBetween(pos, sampleEnd, "\x00", "\x00")))
261753
+ if (!isWordCharacter$1(state.doc.textBetween(pos, sampleEnd, "\x00", "\x00")))
261568
261754
  return null;
261569
261755
  let startPos = pos;
261570
261756
  while (startPos > parentStart) {
261571
- if (!isWordCharacter(state.doc.textBetween(startPos - 1, startPos, "\x00", "\x00")))
261757
+ if (!isWordCharacter$1(state.doc.textBetween(startPos - 1, startPos, "\x00", "\x00")))
261572
261758
  break;
261573
261759
  startPos -= 1;
261574
261760
  }
261575
261761
  let endPos = pos;
261576
261762
  while (endPos < parentEnd) {
261577
- if (!isWordCharacter(state.doc.textBetween(endPos, endPos + 1, "\x00", "\x00")))
261763
+ if (!isWordCharacter$1(state.doc.textBetween(endPos, endPos + 1, "\x00", "\x00")))
261578
261764
  break;
261579
261765
  endPos += 1;
261580
261766
  }
@@ -264845,6 +265031,1369 @@ function getFontMetrics(ctx$1, fontInfo, mode, fonts) {
264845
265031
  fontMetricsCache.set(key2, result);
264846
265032
  return result;
264847
265033
  }
265034
+ function computeFixedTableColumnWidths(input2) {
265035
+ const gridColumnCount = Math.max(0, sanitizeColumnCount(input2.gridColumnCount), Array.isArray(input2.preferredColumnWidths) ? input2.preferredColumnWidths.length : 0);
265036
+ const preferredTableWidth = sanitizeOptionalWidth$1(input2.preferredTableWidth);
265037
+ const defaultAddedColumnWidth = resolveDefaultAddedColumnWidth(input2.preferredColumnWidths, preferredTableWidth);
265038
+ const columnWidths = buildInitialGrid(input2.preferredColumnWidths, gridColumnCount, defaultAddedColumnWidth);
265039
+ if (input2.preserveAuthoredGrid === true)
265040
+ return {
265041
+ columnWidths,
265042
+ totalWidth: sumWidths$2(columnWidths),
265043
+ gridColumnCount: columnWidths.length,
265044
+ preferredTableWidth
265045
+ };
265046
+ if (input2.rows.length === 0) {
265047
+ if (preferredTableWidth != null)
265048
+ shrinkToPreferredTableWidth(columnWidths, preferredTableWidth);
265049
+ return {
265050
+ columnWidths,
265051
+ totalWidth: sumWidths$2(columnWidths),
265052
+ gridColumnCount: columnWidths.length,
265053
+ preferredTableWidth
265054
+ };
265055
+ }
265056
+ applyFirstRowRequests(columnWidths, input2.rows[0], defaultAddedColumnWidth);
265057
+ if (preferredTableWidth != null)
265058
+ shrinkToPreferredTableWidth(columnWidths, preferredTableWidth);
265059
+ for (const row2 of input2.rows.slice(1)) {
265060
+ applySubsequentRowRequests(columnWidths, row2, defaultAddedColumnWidth);
265061
+ if (preferredTableWidth != null)
265062
+ shrinkToPreferredTableWidth(columnWidths, preferredTableWidth);
265063
+ }
265064
+ return {
265065
+ columnWidths,
265066
+ totalWidth: sumWidths$2(columnWidths),
265067
+ gridColumnCount: columnWidths.length,
265068
+ preferredTableWidth
265069
+ };
265070
+ }
265071
+ function buildInitialGrid(preferredColumnWidths, gridColumnCount, defaultAddedColumnWidth) {
265072
+ const next2 = preferredColumnWidths.slice(0, gridColumnCount).map((width) => sanitizeNonNegativeWidth(width) ?? 0);
265073
+ while (next2.length < gridColumnCount)
265074
+ next2.push(defaultAddedColumnWidth);
265075
+ return next2;
265076
+ }
265077
+ function applyFirstRowRequests(columnWidths, row2, defaultAddedColumnWidth) {
265078
+ ensureGridWidth(columnWidths, row2.logicalColumnCount, defaultAddedColumnWidth);
265079
+ for (const skippedColumn of row2.skippedColumns)
265080
+ setSkippedColumnWidth(columnWidths, skippedColumn, defaultAddedColumnWidth);
265081
+ for (const cell2 of row2.cells)
265082
+ setCellSpanWidth(columnWidths, cell2, defaultAddedColumnWidth);
265083
+ }
265084
+ function applySubsequentRowRequests(columnWidths, row2, defaultAddedColumnWidth) {
265085
+ ensureGridWidth(columnWidths, row2.logicalColumnCount, defaultAddedColumnWidth);
265086
+ for (const skippedColumn of row2.skippedColumns)
265087
+ growSkippedColumnWidth(columnWidths, skippedColumn, defaultAddedColumnWidth);
265088
+ for (const cell2 of row2.cells)
265089
+ growCellSpanWidth(columnWidths, cell2, defaultAddedColumnWidth);
265090
+ }
265091
+ function setSkippedColumnWidth(columnWidths, skippedColumn, defaultAddedColumnWidth) {
265092
+ const preferredWidth = sanitizeOptionalWidth$1(skippedColumn.preferredWidth);
265093
+ if (preferredWidth == null)
265094
+ return;
265095
+ ensureGridWidth(columnWidths, skippedColumn.columnIndex + 1, defaultAddedColumnWidth);
265096
+ columnWidths[skippedColumn.columnIndex] = preferredWidth;
265097
+ }
265098
+ function growSkippedColumnWidth(columnWidths, skippedColumn, defaultAddedColumnWidth) {
265099
+ const preferredWidth = sanitizeOptionalWidth$1(skippedColumn.preferredWidth);
265100
+ if (preferredWidth == null)
265101
+ return;
265102
+ ensureGridWidth(columnWidths, skippedColumn.columnIndex + 1, defaultAddedColumnWidth);
265103
+ columnWidths[skippedColumn.columnIndex] = Math.max(columnWidths[skippedColumn.columnIndex] ?? 0, preferredWidth);
265104
+ }
265105
+ function setCellSpanWidth(columnWidths, cell2, defaultAddedColumnWidth) {
265106
+ const span = Math.max(1, sanitizeColumnCount(cell2.span));
265107
+ const preferredWidth = sanitizeOptionalWidth$1(cell2.preferredWidth);
265108
+ const endColumn = cell2.startColumn + span;
265109
+ ensureGridWidth(columnWidths, endColumn, defaultAddedColumnWidth);
265110
+ if (preferredWidth == null)
265111
+ return;
265112
+ const currentSpanWidth = sumSpan$1(columnWidths, cell2.startColumn, span);
265113
+ const lastColumnIndex = endColumn - 1;
265114
+ columnWidths[lastColumnIndex] = Math.max(0, (columnWidths[lastColumnIndex] ?? 0) + (preferredWidth - currentSpanWidth));
265115
+ }
265116
+ function growCellSpanWidth(columnWidths, cell2, defaultAddedColumnWidth) {
265117
+ const span = Math.max(1, sanitizeColumnCount(cell2.span));
265118
+ const preferredWidth = sanitizeOptionalWidth$1(cell2.preferredWidth);
265119
+ const endColumn = cell2.startColumn + span;
265120
+ ensureGridWidth(columnWidths, endColumn, defaultAddedColumnWidth);
265121
+ if (preferredWidth == null)
265122
+ return;
265123
+ const deficit = preferredWidth - sumSpan$1(columnWidths, cell2.startColumn, span);
265124
+ if (deficit <= 0)
265125
+ return;
265126
+ const lastColumnIndex = endColumn - 1;
265127
+ columnWidths[lastColumnIndex] = Math.max(0, (columnWidths[lastColumnIndex] ?? 0) + deficit);
265128
+ }
265129
+ function shrinkToPreferredTableWidth(columnWidths, preferredTableWidth) {
265130
+ const totalWidth = sumWidths$2(columnWidths);
265131
+ if (preferredTableWidth <= 0 || totalWidth <= preferredTableWidth || totalWidth <= 0)
265132
+ return;
265133
+ const scale = preferredTableWidth / totalWidth;
265134
+ let consumed = 0;
265135
+ for (let index2 = 0;index2 < columnWidths.length; index2++) {
265136
+ if (index2 === columnWidths.length - 1) {
265137
+ columnWidths[index2] = Math.max(0, preferredTableWidth - consumed);
265138
+ continue;
265139
+ }
265140
+ const scaled = Math.max(0, (columnWidths[index2] ?? 0) * scale);
265141
+ columnWidths[index2] = scaled;
265142
+ consumed += scaled;
265143
+ }
265144
+ }
265145
+ function ensureGridWidth(columnWidths, requiredColumnCount, defaultAddedColumnWidth) {
265146
+ while (columnWidths.length < requiredColumnCount)
265147
+ columnWidths.push(defaultAddedColumnWidth);
265148
+ }
265149
+ function resolveDefaultAddedColumnWidth(preferredColumnWidths, preferredTableWidth) {
265150
+ for (let index2 = preferredColumnWidths.length - 1;index2 >= 0; index2--) {
265151
+ const width = sanitizeNonNegativeWidth(preferredColumnWidths[index2]);
265152
+ if (width != null && width > 0)
265153
+ return width;
265154
+ }
265155
+ const positiveAuthoredWidths = preferredColumnWidths.map((width) => sanitizeNonNegativeWidth(width)).filter((width) => width != null && width > 0);
265156
+ if (positiveAuthoredWidths.length > 0)
265157
+ return sumWidths$2(positiveAuthoredWidths) / positiveAuthoredWidths.length;
265158
+ if (preferredTableWidth != null && preferredTableWidth > 0)
265159
+ return preferredTableWidth;
265160
+ return 1;
265161
+ }
265162
+ function sumSpan$1(columnWidths, startColumn, span) {
265163
+ let total = 0;
265164
+ for (let offset$1 = 0;offset$1 < span; offset$1++)
265165
+ total += columnWidths[startColumn + offset$1] ?? 0;
265166
+ return total;
265167
+ }
265168
+ function sumWidths$2(columnWidths) {
265169
+ return columnWidths.reduce((sum, width) => sum + Math.max(0, width), 0);
265170
+ }
265171
+ function sanitizeColumnCount(value) {
265172
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0)
265173
+ return 0;
265174
+ return Math.floor(value);
265175
+ }
265176
+ function sanitizeOptionalWidth$1(value) {
265177
+ const width = sanitizeNonNegativeWidth(value);
265178
+ return width == null ? undefined : width;
265179
+ }
265180
+ function sanitizeNonNegativeWidth(value) {
265181
+ if (typeof value !== "number" || !Number.isFinite(value))
265182
+ return;
265183
+ return Math.max(0, value);
265184
+ }
265185
+ function computeAutoFitColumnWidths(input2) {
265186
+ const { workingInput, fixedLayout, rowMetrics, minColumnWidth } = resolveAutoFitContext(input2);
265187
+ if (workingInput.layoutMode === "fixed")
265188
+ return finalizeResult("fixed", fixedLayout.columnWidths, minColumnWidth);
265189
+ const gridColumnCount = fixedLayout.gridColumnCount;
265190
+ if (gridColumnCount === 0)
265191
+ return buildFallbackResult(workingInput.layoutMode, minColumnWidth);
265192
+ const normalizedRows = buildNormalizedRows(workingInput, rowMetrics);
265193
+ const currentWidths = fixedLayout.columnWidths.slice(0, gridColumnCount);
265194
+ const minBounds = new Array(gridColumnCount).fill(0);
265195
+ const maxBounds = new Array(gridColumnCount).fill(0);
265196
+ const preferredOverrides = new Array(gridColumnCount).fill(undefined);
265197
+ const multiSpanCells = [];
265198
+ accumulateBounds({
265199
+ rows: normalizedRows,
265200
+ minBounds,
265201
+ maxBounds,
265202
+ preferredOverrides,
265203
+ multiSpanCells
265204
+ });
265205
+ applyMultiSpanMinimums(minBounds, multiSpanCells);
265206
+ applySingleSpanPreferredOverrides(maxBounds, minBounds, preferredOverrides);
265207
+ applyMultiSpanMaximums(maxBounds, minBounds, multiSpanCells, currentWidths);
265208
+ const triggerCells = collectTriggerCells(currentWidths, multiSpanCells, normalizedRows);
265209
+ const postTriggerGrowableColumns = triggerCells.length > 0 ? collectNonProtectedColumns(triggerCells, gridColumnCount) : undefined;
265210
+ let resolvedWidths = currentWidths.slice();
265211
+ const preferredTableWidth = sanitizeOptionalWidth(workingInput.preferredTableWidth);
265212
+ let targetTableWidth = preferredTableWidth ?? fixedLayout.totalWidth;
265213
+ const maxResolvedTableWidth = preferredTableWidth != null || hasCompleteAuthoredGrid(workingInput) ? Math.max(workingInput.maxTableWidth, targetTableWidth) : workingInput.maxTableWidth;
265214
+ const shouldPreservePreferredGrid = workingInput.preserveAutoGrid === true || workingInput.preserveExplicitAutoGrid === true;
265215
+ if (triggerCells.length > 0) {
265216
+ resolvedWidths = raiseToMinimums(resolvedWidths, minBounds);
265217
+ resolvedWidths = expandTriggersWithinCurrentTable(resolvedWidths, triggerCells, minBounds, maxBounds);
265218
+ resolvedWidths = expandTriggersByGrowingTable(resolvedWidths, triggerCells, maxBounds, maxResolvedTableWidth);
265219
+ targetTableWidth = Math.max(targetTableWidth, sumWidths$1(resolvedWidths));
265220
+ targetTableWidth = Math.min(targetTableWidth, maxResolvedTableWidth);
265221
+ } else {
265222
+ targetTableWidth = Math.min(targetTableWidth, maxResolvedTableWidth);
265223
+ if (!shouldPreservePreferredGrid) {
265224
+ resolvedWidths = redistributeTowardMaximumsWithinCurrentTable(resolvedWidths, minBounds, maxBounds);
265225
+ resolvedWidths = redistributeTowardContentWeightedShape(resolvedWidths, minBounds, maxBounds);
265226
+ }
265227
+ }
265228
+ resolvedWidths = shrinkToTargetWidth(resolvedWidths, targetTableWidth, minBounds);
265229
+ resolvedWidths = growToTargetWidth(resolvedWidths, targetTableWidth, maxBounds, postTriggerGrowableColumns);
265230
+ if (sumWidths$1(resolvedWidths) < targetTableWidth)
265231
+ resolvedWidths = distributeRemainingSlack(resolvedWidths, targetTableWidth, postTriggerGrowableColumns);
265232
+ if (triggerCells.length > 0)
265233
+ resolvedWidths = clampTriggeredSpansToTargets(resolvedWidths, triggerCells, minBounds, maxBounds, currentWidths);
265234
+ if (sumWidths$1(resolvedWidths) > maxResolvedTableWidth)
265235
+ resolvedWidths = shrinkToTargetWidth(resolvedWidths, maxResolvedTableWidth, minBounds);
265236
+ return finalizeResult(workingInput.layoutMode, resolvedWidths, minColumnWidth);
265237
+ }
265238
+ function hasCompleteAuthoredGrid(workingInput) {
265239
+ const authoredColumnCount = workingInput.preferredColumnWidths.length;
265240
+ if (authoredColumnCount === 0)
265241
+ return false;
265242
+ return workingInput.rows.some((row2) => row2.logicalColumnCount >= authoredColumnCount);
265243
+ }
265244
+ function resolveAutoFitContext(input2) {
265245
+ const minColumnWidth = sanitizeWidth(input2.minColumnWidth, DEFAULT_MIN_COLUMN_WIDTH);
265246
+ if (isExplicitInput(input2))
265247
+ return {
265248
+ workingInput: input2.workingInput,
265249
+ fixedLayout: input2.fixedLayout,
265250
+ rowMetrics: input2.contentMetrics.rowMetrics,
265251
+ minColumnWidth
265252
+ };
265253
+ const layoutMode = resolveLayoutMode$1(input2.tableLayout);
265254
+ const normalizedRows = normalizeLegacyRows(input2.rows ?? []);
265255
+ const gridColumnCount = determineGridColumnCount$1(input2.preferredColumnWidths ?? [], normalizedRows);
265256
+ const workingInput = {
265257
+ layoutMode,
265258
+ maxTableWidth: Math.max(minColumnWidth, sanitizeWidth(input2.maxTableWidth, minColumnWidth)),
265259
+ preferredTableWidth: sanitizeOptionalWidth(input2.preferredTableWidth),
265260
+ preferredColumnWidths: (input2.preferredColumnWidths ?? []).map((width) => Math.max(0, width)),
265261
+ gridColumnCount,
265262
+ rows: normalizedRows.map((row2) => ({
265263
+ skippedBefore: row2.skippedColumns.filter((column) => column.columnIndex < firstCellStart(row2)),
265264
+ skippedAfter: row2.skippedColumns.filter((column) => column.columnIndex >= lastCellEnd(row2)),
265265
+ skippedColumns: row2.skippedColumns,
265266
+ cells: row2.cells.map((cell2) => ({
265267
+ cellId: undefined,
265268
+ startColumn: cell2.startColumn,
265269
+ span: cell2.span,
265270
+ preferredWidth: cell2.preferredWidth
265271
+ })),
265272
+ logicalColumnCount: row2.logicalColumnCount
265273
+ }))
265274
+ };
265275
+ return {
265276
+ workingInput,
265277
+ fixedLayout: computeFixedTableColumnWidths(workingInput),
265278
+ rowMetrics: normalizedRows.map((row2, rowIndex) => ({
265279
+ rowIndex,
265280
+ cells: row2.cells.map((cell2) => ({
265281
+ cellIndex: cell2.cellIndex,
265282
+ span: cell2.span,
265283
+ preferredWidth: cell2.preferredWidth,
265284
+ minContentWidth: cell2.minContentWidth,
265285
+ maxContentWidth: cell2.maxContentWidth
265286
+ }))
265287
+ })),
265288
+ minColumnWidth
265289
+ };
265290
+ }
265291
+ function isExplicitInput(input2) {
265292
+ return "workingInput" in input2 && "fixedLayout" in input2 && "contentMetrics" in input2;
265293
+ }
265294
+ function resolveLayoutMode$1(tableLayout) {
265295
+ return tableLayout === "fixed" ? "fixed" : "autofit";
265296
+ }
265297
+ function normalizeLegacyRows(rows) {
265298
+ return rows.map((row2, rowIndex) => {
265299
+ let columnIndex = 0;
265300
+ const skippedColumns = [];
265301
+ const cells = [];
265302
+ for (const skipped of row2.skippedBefore ?? []) {
265303
+ skippedColumns.push(normalizeSkippedColumn(skipped, columnIndex));
265304
+ columnIndex += 1;
265305
+ }
265306
+ for (let cellIndex = 0;cellIndex < (row2.cells ?? []).length; cellIndex++) {
265307
+ const cell2 = row2.cells?.[cellIndex];
265308
+ if (!cell2)
265309
+ continue;
265310
+ const span = Math.max(1, Math.floor(cell2.span ?? 1));
265311
+ cells.push({
265312
+ rowIndex,
265313
+ cellIndex,
265314
+ startColumn: columnIndex,
265315
+ span,
265316
+ preferredWidth: sanitizeOptionalWidth(cell2.preferredWidth),
265317
+ minContentWidth: Math.max(0, cell2.minContentWidth ?? 0),
265318
+ maxContentWidth: Math.max(0, cell2.maxContentWidth ?? cell2.minContentWidth ?? 0)
265319
+ });
265320
+ columnIndex += span;
265321
+ }
265322
+ for (const skipped of row2.skippedAfter ?? []) {
265323
+ skippedColumns.push(normalizeSkippedColumn(skipped, columnIndex));
265324
+ columnIndex += 1;
265325
+ }
265326
+ return {
265327
+ cells,
265328
+ skippedColumns,
265329
+ logicalColumnCount: columnIndex
265330
+ };
265331
+ });
265332
+ }
265333
+ function normalizeSkippedColumn(skipped, columnIndex) {
265334
+ return {
265335
+ columnIndex,
265336
+ preferredWidth: sanitizeOptionalWidth(skipped.preferredWidth),
265337
+ minContentWidth: Math.max(0, skipped.minContentWidth ?? 0),
265338
+ maxContentWidth: Math.max(0, skipped.maxContentWidth ?? skipped.minContentWidth ?? 0)
265339
+ };
265340
+ }
265341
+ function buildNormalizedRows(workingInput, rowMetrics) {
265342
+ return workingInput.rows.map((workingRow, rowIndex) => {
265343
+ const metricsRow = rowMetrics[rowIndex];
265344
+ return {
265345
+ cells: (workingRow.cells ?? []).map((cell2, cellIndex) => {
265346
+ const metrics = metricsRow?.cells[cellIndex];
265347
+ const placedCell = cell2;
265348
+ return {
265349
+ rowIndex,
265350
+ cellIndex: metrics?.cellIndex ?? cellIndex,
265351
+ startColumn: placedCell.startColumn,
265352
+ span: Math.max(1, placedCell.span ?? metrics?.span ?? 1),
265353
+ preferredWidth: sanitizeOptionalWidth(metrics?.preferredWidth ?? placedCell.preferredWidth),
265354
+ minContentWidth: Math.max(0, metrics?.minContentWidth ?? 0),
265355
+ maxContentWidth: Math.max(0, metrics?.maxContentWidth ?? metrics?.minContentWidth ?? 0)
265356
+ };
265357
+ }),
265358
+ skippedColumns: (workingRow.skippedColumns ?? []).map((skipped) => ({
265359
+ columnIndex: skipped.columnIndex,
265360
+ preferredWidth: sanitizeOptionalWidth(skipped.preferredWidth),
265361
+ minContentWidth: Math.max(0, skipped.minContentWidth ?? 0),
265362
+ maxContentWidth: Math.max(0, skipped.maxContentWidth ?? skipped.minContentWidth ?? 0)
265363
+ })),
265364
+ logicalColumnCount: workingRow.logicalColumnCount
265365
+ };
265366
+ });
265367
+ }
265368
+ function accumulateBounds(args$1) {
265369
+ const { rows, minBounds, maxBounds, preferredOverrides, multiSpanCells } = args$1;
265370
+ for (const row2 of rows) {
265371
+ for (const skipped of row2.skippedColumns) {
265372
+ minBounds[skipped.columnIndex] = Math.max(minBounds[skipped.columnIndex], skipped.minContentWidth);
265373
+ maxBounds[skipped.columnIndex] = Math.max(maxBounds[skipped.columnIndex], skipped.maxContentWidth);
265374
+ if (preferredOverrides[skipped.columnIndex] == null && skipped.preferredWidth != null)
265375
+ preferredOverrides[skipped.columnIndex] = skipped.preferredWidth;
265376
+ }
265377
+ for (const cell2 of row2.cells)
265378
+ if (cell2.span === 1) {
265379
+ minBounds[cell2.startColumn] = Math.max(minBounds[cell2.startColumn], cell2.minContentWidth);
265380
+ maxBounds[cell2.startColumn] = Math.max(maxBounds[cell2.startColumn], cell2.maxContentWidth);
265381
+ if (preferredOverrides[cell2.startColumn] == null && cell2.preferredWidth != null)
265382
+ preferredOverrides[cell2.startColumn] = cell2.preferredWidth;
265383
+ } else
265384
+ multiSpanCells.push(cell2);
265385
+ }
265386
+ }
265387
+ function applyMultiSpanMinimums(minBounds, cells) {
265388
+ for (const cell2 of cells)
265389
+ growSpanTotal(minBounds, cell2.startColumn, cell2.span, cell2.minContentWidth);
265390
+ }
265391
+ function applySingleSpanPreferredOverrides(maxBounds, minBounds, preferredOverrides) {
265392
+ for (let index2 = 0;index2 < maxBounds.length; index2++) {
265393
+ const currentMax = Math.max(maxBounds[index2], minBounds[index2]);
265394
+ maxBounds[index2] = preferredOverrides[index2] ?? currentMax;
265395
+ maxBounds[index2] = Math.max(maxBounds[index2], minBounds[index2]);
265396
+ }
265397
+ }
265398
+ function applyMultiSpanMaximums(maxBounds, minBounds, cells, fixedWidths) {
265399
+ for (const cell2 of cells) {
265400
+ 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));
265401
+ setSpanTotal(maxBounds, minBounds, fixedWidths, cell2.startColumn, cell2.span, targetTotal);
265402
+ }
265403
+ }
265404
+ function collectTriggerCells(currentWidths, multiSpanCells, rows) {
265405
+ const triggers = [];
265406
+ for (const row2 of rows)
265407
+ for (const cell2 of row2.cells)
265408
+ if (sumSpan(currentWidths, cell2.startColumn, cell2.span) < cell2.minContentWidth)
265409
+ triggers.push(cell2);
265410
+ for (const cell2 of multiSpanCells)
265411
+ if (sumSpan(currentWidths, cell2.startColumn, cell2.span) < cell2.minContentWidth)
265412
+ triggers.push(cell2);
265413
+ return coalesceEquivalentTriggerCells(dedupeCells(triggers));
265414
+ }
265415
+ function setSpanTotal(widths, minBounds, fixedWidths, startColumn, span, targetTotal) {
265416
+ const currentTotal = sumSpan(widths, startColumn, span);
265417
+ const minTotal = sumSpan(minBounds, startColumn, span);
265418
+ const boundedTarget = Math.max(targetTotal, minTotal);
265419
+ if (currentTotal < boundedTarget) {
265420
+ growSpanTotal(widths, startColumn, span, boundedTarget, fixedWidths);
265421
+ return;
265422
+ }
265423
+ if (currentTotal === boundedTarget)
265424
+ return;
265425
+ const reducibleRanges = collectSpanRanges(widths, minBounds, startColumn, span);
265426
+ const totalReducible = reducibleRanges.reduce((sum, range) => sum + range.amount, 0);
265427
+ if (totalReducible <= 0)
265428
+ return;
265429
+ const reduction = currentTotal - boundedTarget;
265430
+ let applied = 0;
265431
+ for (let rangeIndex = 0;rangeIndex < reducibleRanges.length; rangeIndex++) {
265432
+ const range = reducibleRanges[rangeIndex];
265433
+ const portion = rangeIndex === reducibleRanges.length - 1 ? reduction - applied : reduction * (range.amount / totalReducible);
265434
+ widths[range.index] = Math.max(minBounds[range.index], widths[range.index] - portion);
265435
+ applied += portion;
265436
+ }
265437
+ }
265438
+ function growSpanTotal(widths, startColumn, span, targetTotal, fixedWidths) {
265439
+ const deficit = targetTotal - sumSpan(widths, startColumn, span);
265440
+ if (deficit <= 0)
265441
+ return;
265442
+ const weights = Array.from({ length: span }, (_$1, offset$1) => {
265443
+ const index2 = startColumn + offset$1;
265444
+ return Math.max(fixedWidths?.[index2] ?? 0, widths[index2] ?? 0, 1);
265445
+ });
265446
+ const totalWeight = weights.reduce((sum, weight) => sum + weight, 0);
265447
+ let applied = 0;
265448
+ for (let offset$1 = 0;offset$1 < span; offset$1++) {
265449
+ const index2 = startColumn + offset$1;
265450
+ const increment2 = offset$1 === span - 1 ? deficit - applied : deficit * (weights[offset$1] / totalWeight);
265451
+ widths[index2] = Math.max(0, (widths[index2] ?? 0) + increment2);
265452
+ applied += increment2;
265453
+ }
265454
+ }
265455
+ function shrinkToTargetWidth(widths, targetWidth, minBounds) {
265456
+ const currentTotal = sumWidths$1(widths);
265457
+ if (currentTotal <= targetWidth)
265458
+ return widths;
265459
+ const minTotal = sumWidths$1(minBounds);
265460
+ if (targetWidth <= 0)
265461
+ return widths;
265462
+ if (targetWidth < minTotal)
265463
+ return scaleToTargetWidth(widths, targetWidth);
265464
+ const capacities = widths.map((width, index2) => Math.max(0, width - minBounds[index2]));
265465
+ const totalCapacity = capacities.reduce((sum, capacity) => sum + capacity, 0);
265466
+ if (totalCapacity <= 0)
265467
+ return widths;
265468
+ const excess = currentTotal - targetWidth;
265469
+ return widths.map((width, index2) => {
265470
+ const shrink = excess * (capacities[index2] / totalCapacity);
265471
+ return Math.max(minBounds[index2], width - shrink);
265472
+ });
265473
+ }
265474
+ function growToTargetWidth(widths, targetWidth, maxBounds, growableColumns) {
265475
+ const currentTotal = sumWidths$1(widths);
265476
+ if (currentTotal >= targetWidth)
265477
+ return widths;
265478
+ const ranges = widths.map((width, index2) => growableColumns == null || growableColumns.has(index2) ? Math.max(0, maxBounds[index2] - width) : 0);
265479
+ const totalRange = ranges.reduce((sum, range) => sum + range, 0);
265480
+ if (totalRange <= 0)
265481
+ return widths;
265482
+ const slack = targetWidth - currentTotal;
265483
+ return widths.map((width, index2) => width + slack * (ranges[index2] / totalRange));
265484
+ }
265485
+ function distributeRemainingSlack(widths, targetWidth, growableColumns) {
265486
+ const currentTotal = sumWidths$1(widths);
265487
+ if (currentTotal >= targetWidth)
265488
+ return widths;
265489
+ const basis = widths.reduce((sum, width, index2) => {
265490
+ if (growableColumns != null && !growableColumns.has(index2))
265491
+ return sum;
265492
+ return sum + Math.max(width, 1);
265493
+ }, 0);
265494
+ const slack = targetWidth - currentTotal;
265495
+ if (basis <= 0) {
265496
+ if (growableColumns == null)
265497
+ return widths;
265498
+ const growableIndexes = widths.map((_$1, index2) => index2).filter((index2) => growableColumns.has(index2));
265499
+ if (growableIndexes.length === 0)
265500
+ return widths;
265501
+ const share = slack / growableIndexes.length;
265502
+ return widths.map((width, index2) => growableColumns.has(index2) ? width + share : width);
265503
+ }
265504
+ return widths.map((width, index2) => {
265505
+ if (growableColumns != null && !growableColumns.has(index2))
265506
+ return width;
265507
+ return width + slack * (Math.max(width, 1) / basis);
265508
+ });
265509
+ }
265510
+ function raiseToMinimums(widths, minBounds) {
265511
+ const next2 = widths.slice();
265512
+ const deficits = next2.map((width, index2) => Math.max(0, minBounds[index2] - width));
265513
+ const totalDeficit = deficits.reduce((sum, deficit) => sum + deficit, 0);
265514
+ if (totalDeficit <= 0)
265515
+ return next2;
265516
+ const capacities = next2.map((width, index2) => Math.max(0, width - minBounds[index2]));
265517
+ const totalCapacity = capacities.reduce((sum, capacity) => sum + capacity, 0);
265518
+ const borrowAmount = Math.min(totalDeficit, totalCapacity);
265519
+ if (borrowAmount > 0 && totalCapacity > 0) {
265520
+ let borrowed = 0;
265521
+ for (let index2 = 0;index2 < next2.length; index2++) {
265522
+ const reduction = index2 === next2.length - 1 ? borrowAmount - borrowed : borrowAmount * (capacities[index2] / totalCapacity);
265523
+ next2[index2] = Math.max(minBounds[index2], next2[index2] - reduction);
265524
+ borrowed += reduction;
265525
+ }
265526
+ }
265527
+ for (let index2 = 0;index2 < next2.length; index2++)
265528
+ next2[index2] = Math.max(next2[index2], Math.min(minBounds[index2], widths[index2] + deficits[index2]));
265529
+ return next2;
265530
+ }
265531
+ function redistributeTowardMaximumsWithinCurrentTable(widths, minBounds, maxBounds) {
265532
+ const next2 = widths.slice();
265533
+ for (let iteration = 0;iteration < 8; iteration++) {
265534
+ const receiverHeadrooms = next2.map((width, index2) => Math.max(0, maxBounds[index2] - width));
265535
+ const totalReceiverHeadroom = receiverHeadrooms.reduce((sum, headroom) => sum + headroom, 0);
265536
+ if (totalReceiverHeadroom <= 0.001)
265537
+ break;
265538
+ const donorCapacities = next2.map((width, index2) => receiverHeadrooms[index2] > 0.001 ? 0 : Math.max(0, width - minBounds[index2]));
265539
+ let totalDonorCapacity = donorCapacities.reduce((sum, capacity) => sum + capacity, 0);
265540
+ if (totalDonorCapacity <= 0.001) {
265541
+ for (let index2 = 0;index2 < next2.length; index2++)
265542
+ donorCapacities[index2] = Math.max(0, next2[index2] - minBounds[index2]);
265543
+ totalDonorCapacity = donorCapacities.reduce((sum, capacity) => sum + capacity, 0);
265544
+ }
265545
+ if (totalDonorCapacity <= 0.001)
265546
+ break;
265547
+ const redistribution = Math.min(totalReceiverHeadroom, totalDonorCapacity);
265548
+ shrinkColumnsByCapacity(next2, donorCapacities, minBounds, redistribution);
265549
+ growColumnsByHeadroom(next2, receiverHeadrooms, redistribution);
265550
+ }
265551
+ return next2;
265552
+ }
265553
+ function redistributeTowardContentWeightedShape(widths, minBounds, maxBounds) {
265554
+ const distributableWidth = sumWidths$1(widths) - sumWidths$1(minBounds);
265555
+ if (distributableWidth <= 0.001 || widths.length === 0)
265556
+ return widths;
265557
+ const demandWeights = widths.map((width, index2) => {
265558
+ const demand = Math.max(maxBounds[index2], width, minBounds[index2], 1);
265559
+ return demand * demand;
265560
+ });
265561
+ const totalDemandWeight = demandWeights.reduce((sum, weight) => sum + weight, 0);
265562
+ if (totalDemandWeight <= 0.001)
265563
+ return widths;
265564
+ return widths.map((_$1, index2) => minBounds[index2] + distributableWidth * (demandWeights[index2] / totalDemandWeight));
265565
+ }
265566
+ function expandTriggersWithinCurrentTable(widths, triggerCells, minBounds, maxBounds) {
265567
+ const next2 = widths.slice();
265568
+ const protectedColumns = collectProtectedColumns(triggerCells);
265569
+ for (let iteration = 0;iteration < 8; iteration++) {
265570
+ const totalHeadroom = collectTriggerHeadrooms(next2, triggerCells, maxBounds).reduce((sum, headroom) => sum + headroom, 0);
265571
+ if (totalHeadroom <= 0.001)
265572
+ break;
265573
+ const donorCapacities = next2.map((width, index2) => protectedColumns.has(index2) ? 0 : Math.max(0, width - minBounds[index2]));
265574
+ const totalDonorCapacity = donorCapacities.reduce((sum, capacity) => sum + capacity, 0);
265575
+ if (totalDonorCapacity <= 0.001)
265576
+ break;
265577
+ const borrowedWidth = Math.min(totalHeadroom, totalDonorCapacity);
265578
+ shrinkColumnsByCapacity(next2, donorCapacities, minBounds, borrowedWidth);
265579
+ applyTriggerGrowth(next2, triggerCells, maxBounds, borrowedWidth);
265580
+ }
265581
+ return next2;
265582
+ }
265583
+ function expandTriggersByGrowingTable(widths, triggerCells, maxBounds, maxTableWidth) {
265584
+ const next2 = widths.slice();
265585
+ for (let iteration = 0;iteration < 8; iteration++) {
265586
+ const totalHeadroom = collectTriggerHeadrooms(next2, triggerCells, maxBounds).reduce((sum, headroom) => sum + headroom, 0);
265587
+ if (totalHeadroom <= 0.001)
265588
+ break;
265589
+ const remainingTableGrowth = Math.max(0, maxTableWidth - sumWidths$1(next2));
265590
+ if (remainingTableGrowth <= 0.001)
265591
+ break;
265592
+ applyTriggerGrowth(next2, triggerCells, maxBounds, Math.min(totalHeadroom, remainingTableGrowth));
265593
+ }
265594
+ return next2;
265595
+ }
265596
+ function collectTriggerHeadrooms(widths, triggerCells, maxBounds) {
265597
+ return triggerCells.map((cell2) => {
265598
+ const currentTotal = sumSpan(widths, cell2.startColumn, cell2.span);
265599
+ const targetTotal = resolveTriggerTargetTotal(cell2, maxBounds);
265600
+ return Math.max(0, targetTotal - currentTotal);
265601
+ });
265602
+ }
265603
+ function resolveTriggerTargetTotal(cell2, maxBounds) {
265604
+ if (cell2.span === 1)
265605
+ return maxBounds[cell2.startColumn] ?? cell2.maxContentWidth;
265606
+ return cell2.preferredWidth != null ? Math.max(cell2.preferredWidth, cell2.minContentWidth) : Math.max(cell2.maxContentWidth, cell2.minContentWidth);
265607
+ }
265608
+ function collectProtectedColumns(cells) {
265609
+ const protectedColumns = /* @__PURE__ */ new Set;
265610
+ for (const cell2 of cells)
265611
+ for (let offset$1 = 0;offset$1 < cell2.span; offset$1++)
265612
+ protectedColumns.add(cell2.startColumn + offset$1);
265613
+ return protectedColumns;
265614
+ }
265615
+ function collectNonProtectedColumns(cells, columnCount) {
265616
+ const protectedColumns = collectProtectedColumns(cells);
265617
+ const growableColumns = /* @__PURE__ */ new Set;
265618
+ for (let index2 = 0;index2 < columnCount; index2++)
265619
+ if (!protectedColumns.has(index2))
265620
+ growableColumns.add(index2);
265621
+ return growableColumns;
265622
+ }
265623
+ function shrinkColumnsByCapacity(widths, capacities, minBounds, shrinkAmount) {
265624
+ const totalCapacity = capacities.reduce((sum, capacity) => sum + capacity, 0);
265625
+ if (totalCapacity <= 0 || shrinkAmount <= 0)
265626
+ return;
265627
+ let applied = 0;
265628
+ for (let index2 = 0;index2 < widths.length; index2++) {
265629
+ const reduction = index2 === widths.length - 1 ? shrinkAmount - applied : shrinkAmount * (capacities[index2] / totalCapacity);
265630
+ widths[index2] = Math.max(minBounds[index2], widths[index2] - reduction);
265631
+ applied += reduction;
265632
+ }
265633
+ }
265634
+ function growColumnsByHeadroom(widths, headrooms, growthAmount) {
265635
+ const totalHeadroom = headrooms.reduce((sum, headroom) => sum + headroom, 0);
265636
+ if (totalHeadroom <= 0 || growthAmount <= 0)
265637
+ return;
265638
+ let applied = 0;
265639
+ const activeIndexes = headrooms.map((headroom, index2) => ({
265640
+ headroom,
265641
+ index: index2
265642
+ })).filter((entry) => entry.headroom > 0.001);
265643
+ for (let activeIndex = 0;activeIndex < activeIndexes.length; activeIndex++) {
265644
+ const { index: index2, headroom } = activeIndexes[activeIndex];
265645
+ const growth = activeIndex === activeIndexes.length - 1 ? growthAmount - applied : growthAmount * (headroom / totalHeadroom);
265646
+ widths[index2] += Math.min(headroom, growth);
265647
+ applied += Math.min(headroom, growth);
265648
+ }
265649
+ }
265650
+ function applyTriggerGrowth(widths, triggerCells, maxBounds, growthAmount) {
265651
+ let remainingGrowth = growthAmount;
265652
+ for (let iteration = 0;iteration < 16 && remainingGrowth > 0.001; iteration++) {
265653
+ const headrooms = collectTriggerHeadrooms(widths, triggerCells, maxBounds);
265654
+ const totalHeadroom = headrooms.reduce((sum, headroom) => sum + headroom, 0);
265655
+ if (totalHeadroom <= 0.001)
265656
+ break;
265657
+ const stepGrowth = Math.min(remainingGrowth, totalHeadroom);
265658
+ const activeIndexes = headrooms.map((headroom, index2) => ({
265659
+ headroom,
265660
+ index: index2
265661
+ })).filter((entry) => entry.headroom > 0.001);
265662
+ let appliedThisRound = 0;
265663
+ for (let activeIndex = 0;activeIndex < activeIndexes.length; activeIndex++) {
265664
+ const { index: index2, headroom } = activeIndexes[activeIndex];
265665
+ const cell2 = triggerCells[index2];
265666
+ const proportionalGrowth = activeIndex === activeIndexes.length - 1 ? stepGrowth - appliedThisRound : stepGrowth * (headroom / totalHeadroom);
265667
+ const boundedGrowth = Math.min(headroom, proportionalGrowth);
265668
+ if (boundedGrowth <= 0)
265669
+ continue;
265670
+ growSpanTotal(widths, cell2.startColumn, cell2.span, sumSpan(widths, cell2.startColumn, cell2.span) + boundedGrowth);
265671
+ appliedThisRound += boundedGrowth;
265672
+ }
265673
+ if (appliedThisRound <= 0.001)
265674
+ break;
265675
+ remainingGrowth -= appliedThisRound;
265676
+ }
265677
+ }
265678
+ function clampTriggeredSpansToTargets(widths, triggerCells, minBounds, maxBounds, fixedWidths) {
265679
+ const next2 = widths.slice();
265680
+ for (let iteration = 0;iteration < 8; iteration++) {
265681
+ let changed = false;
265682
+ for (const cell2 of triggerCells) {
265683
+ const currentTotal = sumSpan(next2, cell2.startColumn, cell2.span);
265684
+ const targetTotal = resolveTriggerTargetTotal(cell2, maxBounds);
265685
+ if (currentTotal > targetTotal + 0.001) {
265686
+ setSpanTotal(next2, minBounds, fixedWidths, cell2.startColumn, cell2.span, targetTotal);
265687
+ changed = true;
265688
+ }
265689
+ }
265690
+ if (!changed)
265691
+ break;
265692
+ }
265693
+ return next2;
265694
+ }
265695
+ function collectSpanRanges(widths, minBounds, startColumn, span) {
265696
+ const ranges = [];
265697
+ for (let offset$1 = 0;offset$1 < span; offset$1++) {
265698
+ const index2 = startColumn + offset$1;
265699
+ const amount = Math.max(0, widths[index2] - minBounds[index2]);
265700
+ if (amount > 0)
265701
+ ranges.push({
265702
+ index: index2,
265703
+ amount
265704
+ });
265705
+ }
265706
+ return ranges;
265707
+ }
265708
+ function dedupeCells(cells) {
265709
+ const seen = /* @__PURE__ */ new Set;
265710
+ return cells.filter((cell2) => {
265711
+ const key2 = `${cell2.rowIndex}:${cell2.startColumn}:${cell2.span}:${cell2.cellIndex}`;
265712
+ if (seen.has(key2))
265713
+ return false;
265714
+ seen.add(key2);
265715
+ return true;
265716
+ });
265717
+ }
265718
+ function coalesceEquivalentTriggerCells(cells) {
265719
+ const strongestBySpan = /* @__PURE__ */ new Map;
265720
+ for (const cell2 of cells) {
265721
+ const key2 = `${cell2.startColumn}:${cell2.span}`;
265722
+ const current = strongestBySpan.get(key2);
265723
+ if (!current || resolveTriggerStrength(cell2) > resolveTriggerStrength(current))
265724
+ strongestBySpan.set(key2, cell2);
265725
+ }
265726
+ return [...strongestBySpan.values()];
265727
+ }
265728
+ function resolveTriggerStrength(cell2) {
265729
+ return cell2.preferredWidth != null ? Math.max(cell2.preferredWidth, cell2.minContentWidth) : Math.max(cell2.maxContentWidth, cell2.minContentWidth);
265730
+ }
265731
+ function determineGridColumnCount$1(preferredColumnWidths, rows) {
265732
+ return Math.max(preferredColumnWidths.length, ...rows.map((row2) => row2.logicalColumnCount), 0);
265733
+ }
265734
+ function firstCellStart(row2) {
265735
+ return row2.cells[0]?.startColumn ?? row2.logicalColumnCount;
265736
+ }
265737
+ function lastCellEnd(row2) {
265738
+ const lastCell = row2.cells[row2.cells.length - 1];
265739
+ return lastCell ? lastCell.startColumn + lastCell.span : 0;
265740
+ }
265741
+ function sumSpan(widths, startColumn, span) {
265742
+ let total = 0;
265743
+ for (let offset$1 = 0;offset$1 < span; offset$1++)
265744
+ total += widths[startColumn + offset$1] ?? 0;
265745
+ return total;
265746
+ }
265747
+ function sumWidths$1(widths) {
265748
+ return widths.reduce((sum, width) => sum + Math.max(0, width), 0);
265749
+ }
265750
+ function scaleToTargetWidth(widths, targetWidth) {
265751
+ const currentTotal = sumWidths$1(widths);
265752
+ if (currentTotal <= 0 || targetWidth <= 0)
265753
+ return widths;
265754
+ const scale = targetWidth / currentTotal;
265755
+ return widths.map((width) => Math.max(0, width * scale));
265756
+ }
265757
+ function sanitizeWidth(value, fallback) {
265758
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : fallback;
265759
+ }
265760
+ function sanitizeOptionalWidth(value) {
265761
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined;
265762
+ }
265763
+ function buildFallbackResult(layoutMode, minColumnWidth) {
265764
+ return {
265765
+ layoutMode,
265766
+ columnWidths: [minColumnWidth],
265767
+ totalWidth: minColumnWidth,
265768
+ gridColumnCount: 1
265769
+ };
265770
+ }
265771
+ function finalizeResult(layoutMode, widths, minColumnWidth) {
265772
+ if (widths.length === 0)
265773
+ return buildFallbackResult(layoutMode, minColumnWidth);
265774
+ return {
265775
+ layoutMode,
265776
+ columnWidths: widths,
265777
+ totalWidth: sumWidths$1(widths),
265778
+ gridColumnCount: widths.length
265779
+ };
265780
+ }
265781
+ function buildAutoFitWorkingGridInput(block, constraints) {
265782
+ const maxTableWidth = sanitizePositiveNumber(constraints.maxWidth);
265783
+ const layoutMode = resolveLayoutMode(block.attrs?.tableLayout);
265784
+ const preferredTableWidth = resolvePreferredTableWidth(block.attrs?.tableWidth, maxTableWidth);
265785
+ const rawPreferredColumnWidths = normalizePreferredColumnWidths(block.columnWidths);
265786
+ const logicalColumnLimit = resolveTrailingPlaceholderColumnLimit(rawPreferredColumnWidths);
265787
+ let activeRowSpans = [];
265788
+ const rows = block.rows.map((row2) => {
265789
+ const normalized = normalizeRow(row2, preferredTableWidth ?? maxTableWidth, activeRowSpans, logicalColumnLimit);
265790
+ activeRowSpans = normalized.nextActiveRowSpans;
265791
+ return normalized.row;
265792
+ });
265793
+ const preferredColumnWidths = trimTrailingUnoccupiedPlaceholderColumns(rawPreferredColumnWidths, determineGridColumnCount(0, rows));
265794
+ const gridColumnCount = determineGridColumnCount(preferredColumnWidths.length, rows);
265795
+ const preserveAuthoredGrid = shouldPreserveAuthoredGrid({
265796
+ layoutMode,
265797
+ preferredColumnWidths,
265798
+ preferredTableWidth,
265799
+ gridColumnCount
265800
+ });
265801
+ const preserveAutoGrid = shouldPreserveAutoGrid({
265802
+ layoutMode,
265803
+ preferredColumnWidths,
265804
+ preferredTableWidth,
265805
+ gridColumnCount
265806
+ });
265807
+ const preserveExplicitAutoGrid = shouldPreserveExplicitAutoGrid({
265808
+ layoutMode,
265809
+ preferredColumnWidths,
265810
+ preferredTableWidth,
265811
+ gridColumnCount,
265812
+ rows
265813
+ });
265814
+ return {
265815
+ layoutMode,
265816
+ maxTableWidth,
265817
+ ...preserveAuthoredGrid ? { preserveAuthoredGrid } : {},
265818
+ ...preserveAutoGrid ? { preserveAutoGrid } : {},
265819
+ ...preserveExplicitAutoGrid ? { preserveExplicitAutoGrid } : {},
265820
+ preferredTableWidth,
265821
+ preferredColumnWidths,
265822
+ gridColumnCount,
265823
+ rows
265824
+ };
265825
+ }
265826
+ function resolveLayoutMode(tableLayout) {
265827
+ return tableLayout === "fixed" ? "fixed" : "autofit";
265828
+ }
265829
+ function shouldPreserveAuthoredGrid(args$1) {
265830
+ const { layoutMode, preferredColumnWidths, preferredTableWidth, gridColumnCount } = args$1;
265831
+ if (layoutMode !== "fixed")
265832
+ return false;
265833
+ if (preferredTableWidth == null || preferredTableWidth <= 0)
265834
+ return false;
265835
+ if (preferredColumnWidths.length === 0 || preferredColumnWidths.length !== gridColumnCount)
265836
+ return false;
265837
+ const totalPreferredColumnWidth = sumWidths(preferredColumnWidths);
265838
+ return approximatelyEqual(totalPreferredColumnWidth, preferredTableWidth) || isSlightlyUnderPreferredTableWidth(totalPreferredColumnWidth, preferredTableWidth);
265839
+ }
265840
+ function shouldPreserveAutoGrid(args$1) {
265841
+ const { layoutMode, preferredColumnWidths, preferredTableWidth, gridColumnCount } = args$1;
265842
+ if (layoutMode !== "autofit")
265843
+ return false;
265844
+ if (preferredTableWidth != null)
265845
+ return false;
265846
+ if (preferredColumnWidths.length === 0 || preferredColumnWidths.length !== gridColumnCount)
265847
+ return false;
265848
+ if (!hasNonUniformGrid(preferredColumnWidths))
265849
+ return false;
265850
+ return true;
265851
+ }
265852
+ function shouldPreserveExplicitAutoGrid(args$1) {
265853
+ const { layoutMode, preferredColumnWidths, preferredTableWidth, gridColumnCount, rows } = args$1;
265854
+ if (layoutMode !== "autofit")
265855
+ return false;
265856
+ if (preferredTableWidth == null || preferredTableWidth <= 0)
265857
+ return false;
265858
+ if (preferredColumnWidths.length === 0 || preferredColumnWidths.length !== gridColumnCount)
265859
+ return false;
265860
+ if (!hasNonUniformGrid(preferredColumnWidths) && !hasConcreteCellWidthRequest(rows))
265861
+ return false;
265862
+ return approximatelyEqual(sumWidths(preferredColumnWidths), preferredTableWidth);
265863
+ }
265864
+ function hasNonUniformGrid(widths) {
265865
+ if (widths.length <= 1)
265866
+ return true;
265867
+ const firstWidth = widths[0];
265868
+ return widths.some((width) => !approximatelyEqual(width, firstWidth));
265869
+ }
265870
+ function hasConcreteCellWidthRequest(rows) {
265871
+ return rows.some((row2) => row2.cells.some((cell2) => cell2.preferredWidth != null));
265872
+ }
265873
+ function trimTrailingUnoccupiedPlaceholderColumns(widths, occupiedGridColumnCount) {
265874
+ const occupiedCount = Math.max(0, Math.floor(occupiedGridColumnCount));
265875
+ if (occupiedCount <= 0 || widths.length <= occupiedCount)
265876
+ return widths;
265877
+ if (!widths.slice(occupiedCount).every((width) => width <= PLACEHOLDER_COLUMN_MAX_WIDTH))
265878
+ return widths;
265879
+ return widths.slice(0, occupiedCount);
265880
+ }
265881
+ function resolveTrailingPlaceholderColumnLimit(widths) {
265882
+ let trailingPlaceholderCount = 0;
265883
+ for (let index2 = widths.length - 1;index2 >= 0; index2--) {
265884
+ if (widths[index2] > PLACEHOLDER_COLUMN_MAX_WIDTH)
265885
+ break;
265886
+ trailingPlaceholderCount += 1;
265887
+ }
265888
+ if (trailingPlaceholderCount === 0 || trailingPlaceholderCount === widths.length)
265889
+ return;
265890
+ return widths.length - trailingPlaceholderCount;
265891
+ }
265892
+ function normalizePreferredColumnWidths(columnWidths) {
265893
+ if (!Array.isArray(columnWidths))
265894
+ return [];
265895
+ return columnWidths.map((width) => sanitizeNonNegativeNumber(width)).filter((width) => width !== undefined).map((width) => width);
265896
+ }
265897
+ function normalizeRow(row2, percentageBasis, activeRowSpans, logicalColumnLimit) {
265898
+ const rowProps = row2.attrs?.tableRowProperties ?? {};
265899
+ const skippedBeforeCount = sanitizeCount(rowProps.gridBefore);
265900
+ const skippedAfterCount = normalizeSkippedAfterCount(rowProps.gridAfter, rowProps.wAfter, percentageBasis);
265901
+ const cells = Array.isArray(row2.cells) ? row2.cells : [];
265902
+ let columnIndex = advancePastOccupiedColumns(activeRowSpans, 0);
265903
+ const skippedBeforePlacement = buildSkippedColumns(skippedBeforeCount, rowProps.wBefore, percentageBasis, columnIndex, activeRowSpans);
265904
+ columnIndex = skippedBeforePlacement.nextColumnIndex;
265905
+ const normalizedCells = cells.map((cell2) => {
265906
+ columnIndex = advancePastOccupiedColumns(activeRowSpans, columnIndex);
265907
+ const normalizedCell = normalizeCell(cell2, percentageBasis, columnIndex, logicalColumnLimit);
265908
+ columnIndex += normalizedCell.span ?? 1;
265909
+ return normalizedCell;
265910
+ });
265911
+ const skippedAfterPlacement = buildSkippedColumns(skippedAfterCount, rowProps.wAfter, percentageBasis, columnIndex, activeRowSpans);
265912
+ columnIndex = skippedAfterPlacement.nextColumnIndex;
265913
+ const logicalColumnCount = Math.max(columnIndex, resolveOccupiedLogicalColumnCount(activeRowSpans));
265914
+ const nextActiveRowSpans = advanceRowSpans(activeRowSpans);
265915
+ normalizedCells.forEach((cell2, index2) => {
265916
+ const rowSpan = sanitizeCount(cells[index2]?.rowSpan) || 1;
265917
+ if (rowSpan > 1)
265918
+ markRowSpanOccupancy(nextActiveRowSpans, cell2.startColumn, cell2.span ?? 1, rowSpan - 1);
265919
+ });
265920
+ return {
265921
+ row: {
265922
+ skippedBefore: skippedBeforePlacement.columns,
265923
+ cells: normalizedCells,
265924
+ skippedAfter: skippedAfterPlacement.columns,
265925
+ skippedColumns: [...skippedBeforePlacement.columns, ...skippedAfterPlacement.columns],
265926
+ logicalColumnCount
265927
+ },
265928
+ nextActiveRowSpans
265929
+ };
265930
+ }
265931
+ function buildSkippedColumns(count2, preferredWidthMeasurement, percentageBasis, startColumnIndex, activeRowSpans) {
265932
+ if (count2 <= 0)
265933
+ return {
265934
+ columns: [],
265935
+ nextColumnIndex: startColumnIndex
265936
+ };
265937
+ const totalPreferredWidth = resolveMeasurementToPx(preferredWidthMeasurement, percentageBasis);
265938
+ const perColumnPreferredWidth = totalPreferredWidth != null && count2 > 0 ? Math.max(0, totalPreferredWidth / count2) : undefined;
265939
+ const columns = [];
265940
+ let columnIndex = startColumnIndex;
265941
+ for (let index2 = 0;index2 < count2; index2++) {
265942
+ columnIndex = advancePastOccupiedColumns(activeRowSpans, columnIndex);
265943
+ columns.push({
265944
+ columnIndex,
265945
+ preferredWidth: perColumnPreferredWidth,
265946
+ minContentWidth: 0,
265947
+ maxContentWidth: 0
265948
+ });
265949
+ columnIndex += 1;
265950
+ }
265951
+ return {
265952
+ columns,
265953
+ nextColumnIndex: columnIndex
265954
+ };
265955
+ }
265956
+ function normalizeSkippedAfterCount(countValue, preferredWidthMeasurement, percentageBasis) {
265957
+ const count2 = sanitizeCount(countValue);
265958
+ if (count2 <= 0)
265959
+ return 0;
265960
+ const totalPreferredWidth = resolveMeasurementToPx(preferredWidthMeasurement, percentageBasis);
265961
+ if (totalPreferredWidth != null && totalPreferredWidth <= PLACEHOLDER_COLUMN_MAX_WIDTH * count2)
265962
+ return 0;
265963
+ return count2;
265964
+ }
265965
+ function normalizeCell(cell2, percentageBasis, startColumn, logicalColumnLimit) {
265966
+ const cellProps = cell2.attrs?.tableCellProperties ?? {};
265967
+ const rawSpan = sanitizeCount(cell2.colSpan) || 1;
265968
+ const span = logicalColumnLimit != null && startColumn < logicalColumnLimit && startColumn + rawSpan > logicalColumnLimit ? Math.max(1, logicalColumnLimit - startColumn) : rawSpan;
265969
+ return {
265970
+ cellId: cell2.id,
265971
+ startColumn,
265972
+ span,
265973
+ preferredWidth: resolveMeasurementToPx(cellProps.cellWidth, percentageBasis)
265974
+ };
265975
+ }
265976
+ function advancePastOccupiedColumns(activeRowSpans, columnIndex) {
265977
+ let nextColumnIndex = columnIndex;
265978
+ while ((activeRowSpans[nextColumnIndex] ?? 0) > 0)
265979
+ nextColumnIndex += 1;
265980
+ return nextColumnIndex;
265981
+ }
265982
+ function resolveOccupiedLogicalColumnCount(activeRowSpans) {
265983
+ for (let index2 = activeRowSpans.length - 1;index2 >= 0; index2--)
265984
+ if ((activeRowSpans[index2] ?? 0) > 0)
265985
+ return index2 + 1;
265986
+ return 0;
265987
+ }
265988
+ function advanceRowSpans(activeRowSpans) {
265989
+ return activeRowSpans.map((remainingRows) => Math.max(0, remainingRows - 1));
265990
+ }
265991
+ function markRowSpanOccupancy(activeRowSpans, startColumn, span, remainingRows) {
265992
+ const boundedSpan = Math.max(1, sanitizeCount(span));
265993
+ for (let offset$1 = 0;offset$1 < boundedSpan; offset$1++) {
265994
+ const columnIndex = startColumn + offset$1;
265995
+ activeRowSpans[columnIndex] = Math.max(activeRowSpans[columnIndex] ?? 0, remainingRows);
265996
+ }
265997
+ }
265998
+ function determineGridColumnCount(preferredColumnCount, rows) {
265999
+ return Math.max(preferredColumnCount, ...rows.map((row2) => {
266000
+ if ("logicalColumnCount" in row2 && typeof row2.logicalColumnCount === "number")
266001
+ return row2.logicalColumnCount;
266002
+ const skippedBefore = row2.skippedBefore?.length ?? 0;
266003
+ const skippedAfter = row2.skippedAfter?.length ?? 0;
266004
+ const cellSpanTotal = (row2.cells ?? []).reduce((sum, cell2) => sum + Math.max(1, cell2.span ?? 1), 0);
266005
+ return skippedBefore + skippedAfter + cellSpanTotal;
266006
+ }), 0);
266007
+ }
266008
+ function resolvePreferredTableWidth(tableWidth, maxWidth) {
266009
+ const resolvedWidth = resolveTableWidthAttr(tableWidth);
266010
+ if (!resolvedWidth)
266011
+ return;
266012
+ if (resolvedWidth.type === "pct")
266013
+ return Math.round(maxWidth * (resolvedWidth.width / OOXML_PCT_DIVISOR));
266014
+ return resolvedWidth.width;
266015
+ }
266016
+ function resolveMeasurementToPx(measurement, percentageBasis) {
266017
+ if (!measurement || typeof measurement !== "object" || !Number.isFinite(measurement.value))
266018
+ return;
266019
+ const value = measurement.value;
266020
+ switch ((measurement.type ?? "dxa").toLowerCase()) {
266021
+ case "dxa":
266022
+ return value / TWIPS_PER_PX$1;
266023
+ case "pct":
266024
+ return Math.round(percentageBasis * (value / OOXML_PCT_DIVISOR));
266025
+ case "px":
266026
+ case "pixel":
266027
+ return value;
266028
+ case "auto":
266029
+ case "nil":
266030
+ return;
266031
+ default:
266032
+ return value;
266033
+ }
266034
+ }
266035
+ function sanitizeCount(value) {
266036
+ if (typeof value !== "number" || !Number.isFinite(value))
266037
+ return 0;
266038
+ return Math.max(0, Math.floor(value));
266039
+ }
266040
+ function sanitizePositiveNumber(value) {
266041
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0)
266042
+ return 1;
266043
+ return value;
266044
+ }
266045
+ function sanitizeNonNegativeNumber(value) {
266046
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
266047
+ return;
266048
+ return value;
266049
+ }
266050
+ function sumWidths(widths) {
266051
+ return widths.reduce((sum, width) => sum + Math.max(0, width), 0);
266052
+ }
266053
+ function approximatelyEqual(left$1, right$1) {
266054
+ return Math.abs(left$1 - right$1) <= 0.01;
266055
+ }
266056
+ function isSlightlyUnderPreferredTableWidth(totalColumnWidth, preferredTableWidth) {
266057
+ if (totalColumnWidth <= 0 || totalColumnWidth >= preferredTableWidth)
266058
+ return false;
266059
+ return preferredTableWidth - totalColumnWidth <= preferredTableWidth * 0.05;
266060
+ }
266061
+ function buildTableCellContentMetricsCacheKey(cell2, options) {
266062
+ return stableSerialize({
266063
+ maxWidth: Math.max(1, Math.round(options.maxWidth)),
266064
+ layoutEpoch: options.layoutEpoch ?? null,
266065
+ attrs: cell2.attrs ?? null,
266066
+ paragraph: cell2.paragraph ?? null,
266067
+ blocks: cell2.blocks ?? null
266068
+ });
266069
+ }
266070
+ function buildAutoFitTableResultCacheKey(table2, options) {
266071
+ return stableSerialize({
266072
+ id: table2.id,
266073
+ attrs: table2.attrs ?? null,
266074
+ columnWidths: table2.columnWidths ?? null,
266075
+ rowCount: table2.rows.length,
266076
+ maxWidth: Math.max(1, Math.round(options.maxWidth)),
266077
+ layoutEpoch: options.layoutEpoch ?? null,
266078
+ cellMetricKeys: options.cellMetricKeys,
266079
+ workingGrid: {
266080
+ layoutMode: options.workingInput.layoutMode,
266081
+ gridColumnCount: options.workingInput.gridColumnCount,
266082
+ preserveAuthoredGrid: options.workingInput.preserveAuthoredGrid === true,
266083
+ preserveAutoGrid: options.workingInput.preserveAutoGrid === true,
266084
+ preserveExplicitAutoGrid: options.workingInput.preserveExplicitAutoGrid === true,
266085
+ preferredTableWidth: options.workingInput.preferredTableWidth ?? null,
266086
+ preferredColumnWidths: options.workingInput.preferredColumnWidths,
266087
+ rows: options.workingInput.rows.map((row2) => ({
266088
+ logicalColumnCount: row2.logicalColumnCount,
266089
+ skippedColumns: (row2.skippedColumns ?? []).map((column) => ({
266090
+ columnIndex: column.columnIndex,
266091
+ preferredWidth: column.preferredWidth ?? null
266092
+ })),
266093
+ cells: row2.cells.map((cell2) => ({
266094
+ startColumn: cell2.startColumn,
266095
+ span: cell2.span ?? 1,
266096
+ preferredWidth: cell2.preferredWidth ?? null
266097
+ }))
266098
+ }))
266099
+ },
266100
+ fixedLayout: {
266101
+ columnWidths: options.fixedLayout.columnWidths,
266102
+ totalWidth: options.fixedLayout.totalWidth,
266103
+ gridColumnCount: options.fixedLayout.gridColumnCount,
266104
+ preferredTableWidth: options.fixedLayout.preferredTableWidth ?? null
266105
+ }
266106
+ });
266107
+ }
266108
+ function getCachedAutoFitTableResult(cacheKey) {
266109
+ return autoFitTableResultCache.get(cacheKey);
266110
+ }
266111
+ function setCachedAutoFitTableResult(cacheKey, result) {
266112
+ autoFitTableResultCache.set(cacheKey, result);
266113
+ }
266114
+ async function measureTableCellContentMetrics(cell2, options) {
266115
+ const cacheKey = buildTableCellContentMetricsCacheKey(cell2, options);
266116
+ const cached = tableCellMetricsCache.get(cacheKey);
266117
+ if (cached)
266118
+ return cached;
266119
+ const horizontalInsets = getHorizontalCellInsets(cell2);
266120
+ const contentBlocks = cell2.blocks ?? (cell2.paragraph ? [cell2.paragraph] : []);
266121
+ if (contentBlocks.length === 0) {
266122
+ const emptyMetrics = {
266123
+ minWidthPx: horizontalInsets,
266124
+ maxWidthPx: horizontalInsets
266125
+ };
266126
+ tableCellMetricsCache.set(cacheKey, emptyMetrics);
266127
+ return emptyMetrics;
266128
+ }
266129
+ let minContentWidthPx = 0;
266130
+ let maxContentWidthPx = 0;
266131
+ for (const block of contentBlocks) {
266132
+ const metrics = await measureIntrinsicBlockWidthMetrics(block, options);
266133
+ minContentWidthPx = Math.max(minContentWidthPx, metrics.minWidthPx);
266134
+ maxContentWidthPx = Math.max(maxContentWidthPx, metrics.maxWidthPx);
266135
+ }
266136
+ const result = {
266137
+ minWidthPx: minContentWidthPx + horizontalInsets,
266138
+ maxWidthPx: maxContentWidthPx + horizontalInsets
266139
+ };
266140
+ tableCellMetricsCache.set(cacheKey, result);
266141
+ return result;
266142
+ }
266143
+ async function measureTableAutoFitContentMetrics(table2, workingInput, fixedLayout, measureBlock$1) {
266144
+ const tableMeasurementBasis = Math.max(1, fixedLayout.totalWidth);
266145
+ const cellMetricKeys = [];
266146
+ const rowMetrics = await Promise.all(table2.rows.map(async (row2, rowIndex) => {
266147
+ const normalizedRow = workingInput.rows[rowIndex] ?? {};
266148
+ return {
266149
+ rowIndex,
266150
+ cells: await Promise.all(row2.cells.map(async (cell2, cellIndex) => {
266151
+ const normalizedCell = normalizedRow.cells?.[cellIndex];
266152
+ const span = normalizedCell?.span ?? cell2.colSpan ?? 1;
266153
+ const measurementMaxWidth = resolveAutoFitCellMeasurementMaxWidth(cell2, normalizedCell, span, fixedLayout, tableMeasurementBasis, workingInput.gridColumnCount);
266154
+ cellMetricKeys.push(buildTableCellContentMetricsCacheKey(cell2, { maxWidth: measurementMaxWidth }));
266155
+ const metrics = await measureTableCellContentMetrics(cell2, {
266156
+ maxWidth: measurementMaxWidth,
266157
+ measureBlock: measureBlock$1
266158
+ });
266159
+ return {
266160
+ cellIndex,
266161
+ span,
266162
+ preferredWidth: normalizedCell?.preferredWidth,
266163
+ minContentWidth: metrics.minWidthPx,
266164
+ maxContentWidth: metrics.maxWidthPx
266165
+ };
266166
+ }))
266167
+ };
266168
+ }));
266169
+ return {
266170
+ rowMetrics,
266171
+ rows: rowMetrics.map((rowMetrics$1, rowIndex) => {
266172
+ const normalizedRow = workingInput.rows[rowIndex] ?? {};
266173
+ return {
266174
+ skippedBefore: normalizedRow.skippedBefore ?? [],
266175
+ cells: rowMetrics$1.cells.map((cellMetrics) => ({
266176
+ span: cellMetrics.span,
266177
+ preferredWidth: cellMetrics.preferredWidth,
266178
+ minContentWidth: cellMetrics.minContentWidth,
266179
+ maxContentWidth: cellMetrics.maxContentWidth
266180
+ })),
266181
+ skippedAfter: normalizedRow.skippedAfter ?? []
266182
+ };
266183
+ }),
266184
+ cellMetricKeys
266185
+ };
266186
+ }
266187
+ async function measureIntrinsicBlockWidthMetrics(block, options) {
266188
+ if (block.kind === "paragraph")
266189
+ return measureParagraphIntrinsicWidthMetrics(block, options.measureBlock);
266190
+ if (block.kind === "table")
266191
+ return measureNestedTableIntrinsicWidthMetrics(block, options);
266192
+ const intrinsicWidth = getIntrinsicAtomicBlockWidth(block);
266193
+ return {
266194
+ minWidthPx: intrinsicWidth,
266195
+ maxWidthPx: intrinsicWidth
266196
+ };
266197
+ }
266198
+ async function measureParagraphIntrinsicWidthMetrics(paragraph2, measureBlock$1) {
266199
+ const maxLineWidth = (await measureBlock$1(paragraph2, {
266200
+ maxWidth: NO_WRAP_MAX_WIDTH,
266201
+ maxHeight: Infinity
266202
+ })).lines.reduce((widest, line) => Math.max(widest, line.width), 0);
266203
+ return {
266204
+ minWidthPx: measureParagraphMinTokenWidth(paragraph2),
266205
+ maxWidthPx: maxLineWidth
266206
+ };
266207
+ }
266208
+ async function measureNestedTableIntrinsicWidthMetrics(table2, options) {
266209
+ const nestedMeasure = await options.measureBlock(table2, {
266210
+ maxWidth: Math.max(1, options.maxWidth),
266211
+ maxHeight: Infinity
266212
+ });
266213
+ if (nestedMeasure.kind !== "table")
266214
+ return {
266215
+ minWidthPx: 0,
266216
+ maxWidthPx: 0
266217
+ };
266218
+ return {
266219
+ minWidthPx: nestedMeasure.totalWidth,
266220
+ maxWidthPx: nestedMeasure.totalWidth
266221
+ };
266222
+ }
266223
+ function measureParagraphMinTokenWidth(paragraph2) {
266224
+ let widestToken = 0;
266225
+ let currentTokenWidth = 0;
266226
+ const flushToken = () => {
266227
+ widestToken = Math.max(widestToken, currentTokenWidth);
266228
+ currentTokenWidth = 0;
266229
+ };
266230
+ for (const run2 of paragraph2.runs) {
266231
+ if (isExplicitLineBreakRun(run2)) {
266232
+ flushToken();
266233
+ continue;
266234
+ }
266235
+ if (isTextLikeRun(run2)) {
266236
+ accumulateTextRunMinTokenWidth(run2, (width) => {
266237
+ currentTokenWidth += width;
266238
+ }, flushToken);
266239
+ continue;
266240
+ }
266241
+ flushToken();
266242
+ if (run2.kind === "image") {
266243
+ widestToken = Math.max(widestToken, run2.width ?? 0);
266244
+ continue;
266245
+ }
266246
+ if (run2.kind === "fieldAnnotation") {
266247
+ widestToken = Math.max(widestToken, measureFieldAnnotationWidth(run2));
266248
+ continue;
266249
+ }
266250
+ if (run2.kind === "math")
266251
+ widestToken = Math.max(widestToken, run2.width ?? 0);
266252
+ }
266253
+ flushToken();
266254
+ return widestToken;
266255
+ }
266256
+ function accumulateTextRunMinTokenWidth(run2, appendTokenPiece, flushToken) {
266257
+ const font = buildFontString$1(run2);
266258
+ let cursor = 0;
266259
+ for (const boundary of run2.text.matchAll(TOKEN_BOUNDARY_PATTERN)) {
266260
+ const boundaryStart = boundary.index ?? cursor;
266261
+ if (boundaryStart > cursor)
266262
+ appendTokenPiece(measureTextRunTokenSlice(run2, cursor, boundaryStart, font));
266263
+ flushToken();
266264
+ cursor = boundaryStart + boundary[0].length;
266265
+ }
266266
+ if (cursor < run2.text.length)
266267
+ appendTokenPiece(measureTextRunTokenSlice(run2, cursor, run2.text.length, font));
266268
+ }
266269
+ function measureTextRunTokenSlice(run2, start$1, end$1, font) {
266270
+ return getMeasuredTextWidth(applyTextTransform$1(run2.text.slice(start$1, end$1), run2, start$1), font, getLetterSpacing(run2), getCanvasContext$1());
266271
+ }
266272
+ function getIntrinsicAtomicBlockWidth(block) {
266273
+ if (block.kind === "image")
266274
+ return block.width ?? 0;
266275
+ if (block.drawingKind === "image")
266276
+ return block.width ?? 0;
266277
+ if (block.drawingKind === "shapeGroup")
266278
+ return block.size?.width ?? block.geometry.width;
266279
+ return block.geometry.width;
266280
+ }
266281
+ function resolveAutoFitCellMeasurementMaxWidth(cell2, normalizedCell, span, fixedLayout, tableWidthBasis, gridColumnCount) {
266282
+ const outerWidth = resolveFixedPassCellOuterWidth(normalizedCell, span, fixedLayout) ?? normalizedCell?.preferredWidth ?? Math.max(1, tableWidthBasis * (Math.max(1, span) / Math.max(1, gridColumnCount || span || 1)));
266283
+ const padding = cell2.attrs?.padding ?? DEFAULT_CELL_PADDING$1;
266284
+ const leftPadding = padding.left ?? DEFAULT_CELL_PADDING$1.left;
266285
+ const rightPadding = padding.right ?? DEFAULT_CELL_PADDING$1.right;
266286
+ const leftBorder = getCellBorderWidthPx(cell2.attrs?.borders?.left);
266287
+ const rightBorder = getCellBorderWidthPx(cell2.attrs?.borders?.right);
266288
+ return Math.max(1, outerWidth - leftPadding - rightPadding - leftBorder - rightBorder);
266289
+ }
266290
+ function resolveFixedPassCellOuterWidth(normalizedCell, fallbackSpan, fixedLayout) {
266291
+ if (normalizedCell?.startColumn == null)
266292
+ return;
266293
+ const span = Math.max(1, normalizedCell.span ?? fallbackSpan);
266294
+ let width = 0;
266295
+ for (let offset$1 = 0;offset$1 < span; offset$1++)
266296
+ width += fixedLayout.columnWidths[normalizedCell.startColumn + offset$1] ?? 0;
266297
+ return width > 0 ? width : undefined;
266298
+ }
266299
+ function getHorizontalCellInsets(cell2) {
266300
+ const padding = cell2.attrs?.padding ?? DEFAULT_CELL_PADDING$1;
266301
+ const leftPadding = padding.left ?? DEFAULT_CELL_PADDING$1.left;
266302
+ const rightPadding = padding.right ?? DEFAULT_CELL_PADDING$1.right;
266303
+ const leftBorder = getCellBorderWidthPx(cell2.attrs?.borders?.left);
266304
+ const rightBorder = getCellBorderWidthPx(cell2.attrs?.borders?.right);
266305
+ return leftPadding + rightPadding + leftBorder + rightBorder;
266306
+ }
266307
+ function getCellBorderWidthPx(border) {
266308
+ if (!border || border.style === "none")
266309
+ return 0;
266310
+ const width = typeof border.width === "number" ? border.width : 0;
266311
+ if (border.style === "thick")
266312
+ return Math.max(width * 2, 3);
266313
+ return Math.max(0, width);
266314
+ }
266315
+ function getCanvasContext$1() {
266316
+ if (!canvasContext$1) {
266317
+ canvasContext$1 = document.createElement("canvas").getContext("2d");
266318
+ if (!canvasContext$1)
266319
+ throw new Error("Failed to create canvas context for AutoFit cell measurement.");
266320
+ }
266321
+ return canvasContext$1;
266322
+ }
266323
+ function buildFontString$1(run2) {
266324
+ const parts = [];
266325
+ if (run2.italic)
266326
+ parts.push("italic");
266327
+ if (run2.bold)
266328
+ parts.push("bold");
266329
+ parts.push(`${normalizeFontSize$1(run2.fontSize)}px`);
266330
+ parts.push(toCssFontFamily(normalizeFontFamily$1(run2.fontFamily)) ?? normalizeFontFamily$1(run2.fontFamily));
266331
+ return parts.join(" ");
266332
+ }
266333
+ function applyTextTransform$1(text5, run2, startOffset = 0) {
266334
+ const transform = run2.textTransform;
266335
+ if (!text5 || !transform || transform === "none")
266336
+ return text5;
266337
+ if (transform === "uppercase")
266338
+ return text5.toUpperCase();
266339
+ if (transform === "lowercase")
266340
+ return text5.toLowerCase();
266341
+ if (transform === "capitalize")
266342
+ return capitalizeText$1(text5, run2.text ?? text5, startOffset);
266343
+ return text5;
266344
+ }
266345
+ function capitalizeText$1(text5, fullText, startOffset) {
266346
+ let result = "";
266347
+ for (let index2 = 0;index2 < text5.length; index2++) {
266348
+ const absoluteIndex = startOffset + index2;
266349
+ const currentChar = text5[index2];
266350
+ const previousChar = absoluteIndex > 0 ? fullText[absoluteIndex - 1] : "";
266351
+ result += isWordCharacter(currentChar) && !isWordCharacter(previousChar) ? currentChar.toUpperCase() : currentChar;
266352
+ }
266353
+ return result;
266354
+ }
266355
+ function measureFieldAnnotationWidth(run2) {
266356
+ 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;
266357
+ const font = buildFontString$1({
266358
+ fontFamily: normalizeFontFamily$1(run2.fontFamily ?? "Arial"),
266359
+ fontSize,
266360
+ bold: run2.bold,
266361
+ italic: run2.italic
266362
+ });
266363
+ return getMeasuredTextWidth(applyTextTransform$1(run2.displayLabel || "", { text: run2.displayLabel || "" }), font, 0, getCanvasContext$1()) + (run2.highlighted === false ? 0 : FIELD_ANNOTATION_PILL_PADDING$1);
266364
+ }
266365
+ function isExplicitLineBreakRun(run2) {
266366
+ return run2.kind === "lineBreak" || run2.kind === "break" && run2.breakType === "line";
266367
+ }
266368
+ function isTextLikeRun(run2) {
266369
+ return "text" in run2 && typeof run2.text === "string";
266370
+ }
266371
+ function getLetterSpacing(run2) {
266372
+ return "letterSpacing" in run2 && typeof run2.letterSpacing === "number" ? run2.letterSpacing : 0;
266373
+ }
266374
+ function normalizeFontSize$1(value) {
266375
+ if (typeof value === "number" && Number.isFinite(value) && value > 0)
266376
+ return value;
266377
+ if (typeof value === "string") {
266378
+ const parsed = parseFloat(value);
266379
+ if (Number.isFinite(parsed) && parsed > 0)
266380
+ return parsed;
266381
+ }
266382
+ return 12;
266383
+ }
266384
+ function normalizeFontFamily$1(value) {
266385
+ return typeof value === "string" && value.trim().length > 0 ? value : "Arial";
266386
+ }
266387
+ function stableSerialize(value) {
266388
+ if (value === null || typeof value !== "object")
266389
+ return JSON.stringify(value);
266390
+ if (Array.isArray(value))
266391
+ return `[${value.map((item) => stableSerialize(item)).join(",")}]`;
266392
+ return `{${Object.entries(value).sort(([left$1], [right$1]) => left$1.localeCompare(right$1)).map(([key2, entry]) => `${JSON.stringify(key2)}:${stableSerialize(entry)}`).join(",")}}`;
266393
+ }
266394
+ function isWordCharacter(value) {
266395
+ return /[A-Za-z0-9]/.test(value);
266396
+ }
264848
266397
  function getTableBorderWidthPx(value) {
264849
266398
  if (value == null)
264850
266399
  return 0;
@@ -266335,141 +267884,9 @@ async function measureParagraphBlock(block, maxWidth) {
266335
267884
  ...dropCapMeasure ? { dropCap: dropCapMeasure } : {}
266336
267885
  };
266337
267886
  }
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
267887
  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
- }
267888
+ const workingInput = buildAutoFitWorkingGridInput(block, { maxWidth: typeof constraints === "number" ? constraints : constraints.maxWidth });
267889
+ const columnWidths = await resolveRuntimeTableColumnWidths(block, workingInput);
266473
267890
  const gridColumnCount = columnWidths.length;
266474
267891
  const calculateCellWidth = (startCol, colspan) => {
266475
267892
  let width = 0;
@@ -266483,11 +267900,19 @@ async function measureTableBlock(block, constraints) {
266483
267900
  const spanConstraints = [];
266484
267901
  for (let rowIndex = 0;rowIndex < block.rows.length; rowIndex++) {
266485
267902
  const row2 = block.rows[rowIndex];
267903
+ const normalizedRow = workingInput.rows[rowIndex];
266486
267904
  const cellMeasures = [];
266487
267905
  let gridColIndex = 0;
266488
- for (const cell2 of row2.cells) {
267906
+ for (let cellIndex = 0;cellIndex < row2.cells.length; cellIndex++) {
267907
+ const cell2 = row2.cells[cellIndex];
266489
267908
  const colspan = cell2.colSpan ?? 1;
266490
267909
  const rowspan = cell2.rowSpan ?? 1;
267910
+ const preferredStartColumn = normalizedRow?.cells?.[cellIndex]?.startColumn ?? gridColIndex;
267911
+ while (gridColIndex < gridColumnCount && gridColIndex < preferredStartColumn) {
267912
+ if (rowspanTracker[gridColIndex] > 0)
267913
+ rowspanTracker[gridColIndex]--;
267914
+ gridColIndex++;
267915
+ }
266491
267916
  while (gridColIndex < gridColumnCount && rowspanTracker[gridColIndex] > 0) {
266492
267917
  rowspanTracker[gridColIndex]--;
266493
267918
  gridColIndex++;
@@ -266590,18 +268015,48 @@ async function measureTableBlock(block, constraints) {
266590
268015
  const borderWidthH = tableBorderWidths.left + tableBorderWidths.right;
266591
268016
  const borderWidthV = tableBorderWidths.top + tableBorderWidths.bottom;
266592
268017
  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
268018
  return {
266596
268019
  kind: "table",
266597
268020
  rows,
266598
268021
  columnWidths,
266599
- totalWidth,
266600
- totalHeight,
268022
+ totalWidth: contentWidth + horizontalGaps + (includeOuterBordersInTotal ? borderWidthH : 0),
268023
+ totalHeight: contentHeight + verticalGaps + (includeOuterBordersInTotal ? borderWidthV : 0),
266601
268024
  cellSpacingPx: cellSpacingPx > 0 ? cellSpacingPx : undefined,
266602
268025
  tableBorderWidths: borderWidthH > 0 || borderWidthV > 0 ? tableBorderWidths : undefined
266603
268026
  };
266604
268027
  }
268028
+ async function resolveRuntimeTableColumnWidths(block, workingInput) {
268029
+ const fixedLayout = computeFixedTableColumnWidths(workingInput);
268030
+ if (workingInput.layoutMode === "fixed")
268031
+ return fixedLayout.columnWidths;
268032
+ const { contentMetrics, cellMetricKeys } = await buildMeasuredAutoFitContentMetrics(block, workingInput, fixedLayout);
268033
+ const cacheKey = buildAutoFitTableResultCacheKey(block, {
268034
+ maxWidth: workingInput.maxTableWidth,
268035
+ cellMetricKeys,
268036
+ workingInput,
268037
+ fixedLayout
268038
+ });
268039
+ const cached = getCachedAutoFitTableResult(cacheKey);
268040
+ if (cached)
268041
+ return cached.columnWidths;
268042
+ const result = computeAutoFitColumnWidths({
268043
+ workingInput,
268044
+ fixedLayout,
268045
+ contentMetrics: { rowMetrics: contentMetrics.rowMetrics }
268046
+ });
268047
+ setCachedAutoFitTableResult(cacheKey, {
268048
+ columnWidths: result.columnWidths,
268049
+ totalWidth: result.totalWidth
268050
+ });
268051
+ return result.columnWidths;
268052
+ }
268053
+ async function buildMeasuredAutoFitContentMetrics(block, workingInput, fixedLayout) {
268054
+ const contentMetrics = await measureTableAutoFitContentMetrics(block, workingInput, fixedLayout, measureBlock);
268055
+ return {
268056
+ contentMetrics,
268057
+ cellMetricKeys: contentMetrics.cellMetricKeys
268058
+ };
268059
+ }
266605
268060
  async function measureImageBlock(block, constraints) {
266606
268061
  const intrinsic = getIntrinsicImageSize(block, constraints.maxWidth);
266607
268062
  const isBlockBehindDoc = block.anchor?.behindDoc;
@@ -267454,7 +268909,7 @@ var Node$13 = class Node$14 {
267454
268909
  "iPhone",
267455
268910
  "iPod"
267456
268911
  ].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) => {
268912
+ }, 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
268913
  if (!run2 || typeof run2 !== "object")
267459
268914
  return false;
267460
268915
  return typeof run2.src === "string";
@@ -269721,7 +271176,7 @@ var Node$13 = class Node$14 {
269721
271176
  const transaction = view.state.tr.setSelection(selection);
269722
271177
  view.dispatch(transaction);
269723
271178
  }
269724
- }, StructuredContentInlineView, STRUCTURED_CONTENT_LOCK_KEY, structuredContentClass = "sd-structured-content", structuredContentInnerClass = "sd-structured-content__content", StructuredContent, StructuredContentBlockView, structuredContentBlockClass = "sd-structured-content-block", structuredContentBlockInnerClass = "sd-structured-content-block__content", StructuredContentBlock, structuredContentHelpers_exports, STRUCTURED_CONTENT_NAMES, findFirstTextNode$1 = (node3) => {
271179
+ }, StructuredContentInlineView, STRUCTURED_CONTENT_LOCK_KEY, INLINE_LEAF_TEXT = "", structuredContentClass = "sd-structured-content", structuredContentInnerClass = "sd-structured-content__content", StructuredContent, StructuredContentBlockView, structuredContentBlockClass = "sd-structured-content-block", structuredContentBlockInnerClass = "sd-structured-content-block__content", StructuredContentBlock, structuredContentHelpers_exports, STRUCTURED_CONTENT_NAMES, findFirstTextNode$1 = (node3) => {
269725
271180
  let firstTextNode = null;
269726
271181
  node3.descendants((child) => {
269727
271182
  if (child.isText) {
@@ -283105,6 +284560,8 @@ var Node$13 = class Node$14 {
283105
284560
  border: 1px solid transparent;
283106
284561
  position: relative;
283107
284562
  display: inline;
284563
+ font-size: initial;
284564
+ line-height: normal;
283108
284565
  z-index: 10;
283109
284566
  }
283110
284567
 
@@ -287025,9 +288482,17 @@ menclose::after {
287025
288482
  inlineBorders = normalizeTableBorders(tableProps.borders);
287026
288483
  if (typeof tableProps.justification === "string")
287027
288484
  hydration.justification = tableProps.justification;
288485
+ const tableIndent = normalizeTableIndent(tableProps.tableIndent);
288486
+ if (tableIndent)
288487
+ hydration.tableIndent = tableIndent;
288488
+ if (typeof tableProps.tableLayout === "string")
288489
+ hydration.tableLayout = tableProps.tableLayout;
287028
288490
  const tableWidth = normalizeTableWidth(tableProps.tableWidth);
287029
288491
  if (tableWidth)
287030
288492
  hydration.tableWidth = tableWidth;
288493
+ const tableCellSpacing = normalizeTableSpacing(tableProps.tableCellSpacing);
288494
+ if (tableCellSpacing)
288495
+ hydration.tableCellSpacing = tableCellSpacing;
287031
288496
  }
287032
288497
  const styleId = effectiveStyleId === null ? undefined : effectiveStyleId ?? (typeof tableNode.attrs?.tableStyleId === "string" ? tableNode.attrs.tableStyleId : undefined);
287033
288498
  if (styleId && context?.translatedLinkedStyles) {
@@ -287054,8 +288519,18 @@ menclose::after {
287054
288519
  hydration.cellPadding = inlinePadding;
287055
288520
  if (!hydration.justification && resolved.justification)
287056
288521
  hydration.justification = resolved.justification;
287057
- if (resolved.tableCellSpacing)
287058
- hydration.tableCellSpacing = resolved.tableCellSpacing;
288522
+ if (!hydration.tableIndent && resolved.tableIndent) {
288523
+ const tableIndent = normalizeTableIndent(resolved.tableIndent);
288524
+ if (tableIndent)
288525
+ hydration.tableIndent = tableIndent;
288526
+ }
288527
+ if (!hydration.tableLayout && resolved.tableLayout)
288528
+ hydration.tableLayout = resolved.tableLayout;
288529
+ if (!hydration.tableCellSpacing && resolved.tableCellSpacing) {
288530
+ const tableCellSpacing = normalizeTableSpacing(resolved.tableCellSpacing);
288531
+ if (tableCellSpacing)
288532
+ hydration.tableCellSpacing = tableCellSpacing;
288533
+ }
287059
288534
  if (!hydration.tableWidth && resolved.tableWidth) {
287060
288535
  const tableWidth = normalizeTableWidth(resolved.tableWidth);
287061
288536
  if (tableWidth)
@@ -287153,7 +288628,41 @@ menclose::after {
287153
288628
  width: raw,
287154
288629
  type: measurement.type
287155
288630
  };
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) => {
288631
+ }, normalizeTableIndent = (value) => {
288632
+ if (!value || typeof value !== "object")
288633
+ return;
288634
+ const measurement = value;
288635
+ const raw = typeof measurement.width === "number" ? measurement.width : measurement.value;
288636
+ if (typeof raw !== "number")
288637
+ return;
288638
+ if (!measurement.type || measurement.type === "px" || measurement.type === "pixel")
288639
+ return {
288640
+ width: raw,
288641
+ type: measurement.type ?? "px"
288642
+ };
288643
+ if (measurement.type === "dxa")
288644
+ return {
288645
+ width: twipsToPx$2(raw),
288646
+ type: "dxa"
288647
+ };
288648
+ return {
288649
+ width: raw,
288650
+ type: measurement.type
288651
+ };
288652
+ }, normalizeTableSpacing = (value) => {
288653
+ if (!value || typeof value !== "object")
288654
+ return;
288655
+ const measurement = value;
288656
+ if (typeof measurement.value !== "number")
288657
+ return;
288658
+ return {
288659
+ value: measurement.value,
288660
+ type: measurement.type ?? "px"
288661
+ };
288662
+ }, 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) => {
288663
+ const placeholder = node3.attrs?.__placeholder;
288664
+ return placeholder === "gridBefore" || placeholder === "gridAfter";
288665
+ }, convertResolvedCellBorder = (value) => {
287157
288666
  if (!value || typeof value !== "object")
287158
288667
  return;
287159
288668
  const border = value;
@@ -287421,6 +288930,8 @@ menclose::after {
287421
288930
  const cells = [];
287422
288931
  const rowCnfStyle = rowNode.attrs?.tableRowProperties?.cnfStyle;
287423
288932
  rowNode.content.forEach((cellNode, cellIndex) => {
288933
+ if (isTableCellNode(cellNode) && isTableSkipPlaceholderCell(cellNode))
288934
+ return;
287424
288935
  const parsedCell = parseTableCell({
287425
288936
  cellNode,
287426
288937
  rowIndex,
@@ -287771,7 +289282,7 @@ menclose::after {
287771
289282
  return true;
287772
289283
  }
287773
289284
  return false;
287774
- }, capitalizeText$2 = (text5) => {
289285
+ }, capitalizeText$3 = (text5) => {
287775
289286
  if (!text5)
287776
289287
  return text5;
287777
289288
  let result = "";
@@ -287781,7 +289292,7 @@ menclose::after {
287781
289292
  result += isWordChar$3(ch) && !isWordChar$3(prevChar) ? ch.toUpperCase() : ch;
287782
289293
  }
287783
289294
  return result;
287784
- }, applyTextTransform$2 = (text5, transform) => {
289295
+ }, applyTextTransform$3 = (text5, transform) => {
287785
289296
  if (!text5 || !transform || transform === "none")
287786
289297
  return text5;
287787
289298
  if (transform === "uppercase")
@@ -287789,7 +289300,7 @@ menclose::after {
287789
289300
  if (transform === "lowercase")
287790
289301
  return text5.toLowerCase();
287791
289302
  if (transform === "capitalize")
287792
- return capitalizeText$2(text5);
289303
+ return capitalizeText$3(text5);
287793
289304
  return text5;
287794
289305
  }, countSpaces = (text5) => {
287795
289306
  let spaces = 0;
@@ -288577,7 +290088,7 @@ menclose::after {
288577
290088
  return false;
288578
290089
  const code7 = char.charCodeAt(0);
288579
290090
  return code7 >= 48 && code7 <= 57 || code7 >= 65 && code7 <= 90 || code7 >= 97 && code7 <= 122 || char === "'";
288580
- }, capitalizeText$1 = (text5, fullText, startOffset) => {
290091
+ }, capitalizeText$2 = (text5, fullText, startOffset) => {
288581
290092
  if (!text5)
288582
290093
  return text5;
288583
290094
  const hasFullText = typeof startOffset === "number" && fullText != null;
@@ -288588,7 +290099,7 @@ menclose::after {
288588
290099
  result += isWordChar$1(ch) && !isWordChar$1(prevChar) ? ch.toUpperCase() : ch;
288589
290100
  }
288590
290101
  return result;
288591
- }, applyTextTransform$1 = (text5, transform, fullText, startOffset) => {
290102
+ }, applyTextTransform$2 = (text5, transform, fullText, startOffset) => {
288592
290103
  if (!text5 || !transform || transform === "none")
288593
290104
  return text5;
288594
290105
  if (transform === "uppercase")
@@ -288596,9 +290107,9 @@ menclose::after {
288596
290107
  if (transform === "lowercase")
288597
290108
  return text5.toLowerCase();
288598
290109
  if (transform === "capitalize")
288599
- return capitalizeText$1(text5, fullText, startOffset);
290110
+ return capitalizeText$2(text5, fullText, startOffset);
288600
290111
  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) => {
290112
+ }, 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
290113
  const width = run2.width;
288603
290114
  return typeof width === "number" ? width : 0;
288604
290115
  }, isLineBreakRun$1 = (run2) => run2.kind === "lineBreak" || run2.kind === "break" && run2.breakType === "line", markerFontString = (run2) => {
@@ -290206,13 +291717,13 @@ menclose::after {
290206
291717
  if (startA == null)
290207
291718
  return false;
290208
291719
  return (endA ?? startA + 1) > startB && startA < endB;
290209
- }, DEFAULT_CELL_PADDING$1, getCellPaddingFromRow = (cellIdx, row2) => {
291720
+ }, DEFAULT_CELL_PADDING$2, getCellPaddingFromRow = (cellIdx, row2) => {
290210
291721
  const padding = row2?.cells?.[cellIdx]?.attrs?.padding ?? {};
290211
291722
  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
291723
+ top: padding.top ?? DEFAULT_CELL_PADDING$2.top,
291724
+ bottom: padding.bottom ?? DEFAULT_CELL_PADDING$2.bottom,
291725
+ left: padding.left ?? DEFAULT_CELL_PADDING$2.left,
291726
+ right: padding.right ?? DEFAULT_CELL_PADDING$2.right
290216
291727
  };
290217
291728
  }, getCellBlocks = (cell2) => {
290218
291729
  if (!cell2)
@@ -294692,7 +296203,41 @@ menclose::after {
294692
296203
  }
294693
296204
  }, EMUS_PER_INCH = 914400, maxSize = 5000, cache, makeKey = (text5, font, letterSpacing) => {
294694
296205
  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) => {
296206
+ }, 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 {
296207
+ constructor(maxSize$1) {
296208
+ this.cache = /* @__PURE__ */ new Map;
296209
+ this.maxSize = maxSize$1;
296210
+ }
296211
+ get(key2) {
296212
+ const hit = this.cache.get(key2);
296213
+ if (!hit)
296214
+ return;
296215
+ this.cache.delete(key2);
296216
+ this.cache.set(key2, hit);
296217
+ return hit.value;
296218
+ }
296219
+ set(key2, value) {
296220
+ this.cache.set(key2, { value });
296221
+ this.evictIfNeeded();
296222
+ }
296223
+ clear() {
296224
+ this.cache.clear();
296225
+ }
296226
+ resize(nextSize) {
296227
+ if (!Number.isFinite(nextSize) || nextSize <= 0)
296228
+ return;
296229
+ this.maxSize = nextSize;
296230
+ this.evictIfNeeded();
296231
+ }
296232
+ evictIfNeeded() {
296233
+ while (this.cache.size > this.maxSize) {
296234
+ const oldestKey = this.cache.keys().next().value;
296235
+ if (oldestKey === undefined)
296236
+ break;
296237
+ this.cache.delete(oldestKey);
296238
+ }
296239
+ }
296240
+ }, 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
296241
  if (isValidFontSize(value))
294697
296242
  return value;
294698
296243
  if (typeof value === "string") {
@@ -296523,12 +298068,12 @@ menclose::after {
296523
298068
  return;
296524
298069
  console.log(...args$1);
296525
298070
  }, 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(() => {
298071
+ var init_src_DAF1K_X_es = __esm(() => {
296527
298072
  init_rolldown_runtime_Bg48TavK_es();
296528
- init_SuperConverter_BTy5lByv_es();
298073
+ init_SuperConverter_Dchjy0My_es();
296529
298074
  init_jszip_C49i9kUs_es();
296530
298075
  init_uuid_qzgm05fK_es();
296531
- init_create_headless_toolbar_k6nNYL53_es();
298076
+ init_create_headless_toolbar_CEcVKzGV_es();
296532
298077
  init_constants_DrU4EASo_es();
296533
298078
  init_dist_B8HfvhaK_es();
296534
298079
  init_unified_Dsuw2be5_es();
@@ -323231,7 +324776,7 @@ function print() { __p += __j.call(arguments, '') }
323231
324776
  "even",
323232
324777
  "odd"
323233
324778
  ];
323234
- TWIPS_PER_PX$1 = 1440 / 96;
324779
+ TWIPS_PER_PX$2 = 1440 / 96;
323235
324780
  init_dist4();
323236
324781
  measureCache = new MeasureCache;
323237
324782
  headerMeasureCache = new HeaderFooterLayoutCache;
@@ -323260,7 +324805,7 @@ function print() { __p += __j.call(arguments, '') }
323260
324805
  workerRoundTrip: 10,
323261
324806
  layoutStaleness: 100
323262
324807
  });
323263
- DEFAULT_CELL_PADDING$1 = {
324808
+ DEFAULT_CELL_PADDING$2 = {
323264
324809
  top: 0,
323265
324810
  bottom: 0,
323266
324811
  left: 4,
@@ -327867,6 +329412,16 @@ function print() { __p += __j.call(arguments, '') }
327867
329412
  EMUS_PER_INCH / 96;
327868
329413
  cache = /* @__PURE__ */ new Map;
327869
329414
  fontMetricsCache = /* @__PURE__ */ new Map;
329415
+ DEFAULT_CELL_PADDING$1 = {
329416
+ top: 0,
329417
+ right: 4,
329418
+ bottom: 0,
329419
+ left: 4
329420
+ };
329421
+ NO_WRAP_MAX_WIDTH = Number.MAX_SAFE_INTEGER;
329422
+ TOKEN_BOUNDARY_PATTERN = /[ \t\f\v\-\u00ad\u2010\u2012\u2013\u2014\u200b\u2028\u2029]+|\r\n|\r|\n|\u2028|\u2029/gu;
329423
+ tableCellMetricsCache = new LruCache(TABLE_CELL_METRICS_CACHE_SIZE);
329424
+ autoFitTableResultCache = new LruCache(TABLE_AUTOFIT_RESULT_CACHE_SIZE);
327870
329425
  ({ computeTabStops } = engines_exports);
327871
329426
  measurementConfig = {
327872
329427
  mode: "browser",
@@ -333739,11 +335294,11 @@ function print() { __p += __j.call(arguments, '') }
333739
335294
  ];
333740
335295
  });
333741
335296
 
333742
- // ../../packages/superdoc/dist/chunks/create-super-doc-ui-BUfd0WN3.es.js
335297
+ // ../../packages/superdoc/dist/chunks/create-super-doc-ui-HW4PZyuU.es.js
333743
335298
  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();
335299
+ var init_create_super_doc_ui_HW4PZyuU_es = __esm(() => {
335300
+ init_SuperConverter_Dchjy0My_es();
335301
+ init_create_headless_toolbar_CEcVKzGV_es();
333747
335302
  ALL_TOOLBAR_COMMAND_IDS = Object.keys(createToolbarRegistry());
333748
335303
  EMPTY_ACTIVE_IDS = Object.freeze([]);
333749
335304
  });
@@ -333761,16 +335316,16 @@ var init_zipper_BxRAi0_5_es = __esm(() => {
333761
335316
 
333762
335317
  // ../../packages/superdoc/dist/super-editor.es.js
333763
335318
  var init_super_editor_es = __esm(() => {
333764
- init_src_BzRjWTpH_es();
333765
- init_SuperConverter_BTy5lByv_es();
335319
+ init_src_DAF1K_X_es();
335320
+ init_SuperConverter_Dchjy0My_es();
333766
335321
  init_jszip_C49i9kUs_es();
333767
335322
  init_xml_js_CqGKpaft_es();
333768
- init_create_headless_toolbar_k6nNYL53_es();
335323
+ init_create_headless_toolbar_CEcVKzGV_es();
333769
335324
  init_constants_DrU4EASo_es();
333770
335325
  init_dist_B8HfvhaK_es();
333771
335326
  init_unified_Dsuw2be5_es();
333772
335327
  init_DocxZipper_CUX64E5K_es();
333773
- init_create_super_doc_ui_BUfd0WN3_es();
335328
+ init_create_super_doc_ui_HW4PZyuU_es();
333774
335329
  init_ui_CGB3qmy3_es();
333775
335330
  init_eventemitter3_BJrNoN9D_es();
333776
335331
  init_errors_C_DoKMoN_es();