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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +2022 -342
  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-CCV76OsP.es.js
207189
+ // ../../packages/superdoc/dist/chunks/src-Dinif16O.es.js
207126
207190
  function deleteProps(obj, propOrProps) {
207127
207191
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
207128
207192
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -207334,6 +207398,18 @@ function calculateTabWidth(params$1) {
207334
207398
  tabStopPosUsed: nextStop.pos
207335
207399
  };
207336
207400
  }
207401
+ function resolveTableWidthAttr(value) {
207402
+ if (!value || typeof value !== "object")
207403
+ return null;
207404
+ const measurement = value;
207405
+ const width = measurement.width ?? measurement.value;
207406
+ if (typeof width !== "number" || !Number.isFinite(width) || width <= 0)
207407
+ return null;
207408
+ return {
207409
+ width,
207410
+ type: measurement.type
207411
+ };
207412
+ }
207337
207413
  function resolveColumnWidths(columns, availableWidth) {
207338
207414
  const width = availableWidth / columns.length;
207339
207415
  return columns.map(() => width);
@@ -207365,7 +207441,7 @@ function getCellSpacingPx(cellSpacing) {
207365
207441
  const v = cellSpacing.value;
207366
207442
  if (typeof v !== "number" || !Number.isFinite(v))
207367
207443
  return 0;
207368
- 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;
207369
207445
  return Math.max(0, asPx);
207370
207446
  }
207371
207447
  function coerceRelativeHeight(raw) {
@@ -221842,7 +221918,8 @@ function executeTextSelector(editor, index2, query2, diagnostics) {
221842
221918
  const rawResult = requireEditorCommand(editor.commands?.search, "find (search)")(pattern, {
221843
221919
  highlight: false,
221844
221920
  caseSensitive: selector.caseSensitive ?? false,
221845
- maxMatches: Infinity
221921
+ maxMatches: Infinity,
221922
+ searchModel: "visible"
221846
221923
  });
221847
221924
  if (!Array.isArray(rawResult))
221848
221925
  throw new DocumentApiAdapterError("CAPABILITY_UNAVAILABLE", "Editor search command returned an unexpected result format.");
@@ -228977,6 +229054,28 @@ function toNotFoundError(input2) {
228977
229054
  function isSameTarget(left$1, right$1) {
228978
229055
  return left$1.blockId === right$1.blockId && left$1.range.start === right$1.range.start && left$1.range.end === right$1.range.end;
228979
229056
  }
229057
+ function isTextAddressShape(target) {
229058
+ if (!target || typeof target !== "object")
229059
+ return false;
229060
+ const t = target;
229061
+ if (t.kind !== "text")
229062
+ return false;
229063
+ if (typeof t.blockId !== "string")
229064
+ return false;
229065
+ return isTextRangeShape(t.range);
229066
+ }
229067
+ function isTextRangeShape(range) {
229068
+ if (!range || typeof range !== "object")
229069
+ return false;
229070
+ const r$1 = range;
229071
+ return Number.isInteger(r$1.start) && Number.isInteger(r$1.end) && r$1.start <= r$1.end;
229072
+ }
229073
+ function isTextSegmentShape(segment) {
229074
+ if (!segment || typeof segment !== "object")
229075
+ return false;
229076
+ const seg = segment;
229077
+ return typeof seg.blockId === "string" && isTextRangeShape(seg.range);
229078
+ }
228980
229079
  function isTextTargetShape(target) {
228981
229080
  if (!target || typeof target !== "object")
228982
229081
  return false;
@@ -228985,17 +229084,19 @@ function isTextTargetShape(target) {
228985
229084
  return false;
228986
229085
  if (!Array.isArray(t.segments) || t.segments.length === 0)
228987
229086
  return false;
228988
- if (typeof t.blockId === "string" || t.range !== undefined && t.range !== null)
229087
+ if (!t.segments.every(isTextSegmentShape))
228989
229088
  return false;
228990
229089
  return true;
228991
229090
  }
228992
229091
  function targetToSegments(target) {
229092
+ if (isTextAddressShape(target))
229093
+ return [{
229094
+ blockId: target.blockId,
229095
+ range: target.range
229096
+ }];
228993
229097
  if (isTextTargetShape(target))
228994
229098
  return [...target.segments];
228995
- return [{
228996
- blockId: target.blockId,
228997
- range: target.range
228998
- }];
229099
+ return null;
228999
229100
  }
229000
229101
  function listCommentAnchorsSafe(editor) {
229001
229102
  try {
@@ -229213,6 +229314,15 @@ function addCommentHandler(editor, input2, options) {
229213
229314
  }
229214
229315
  };
229215
229316
  const segments = targetToSegments(target);
229317
+ if (!segments)
229318
+ return {
229319
+ success: false,
229320
+ failure: {
229321
+ code: "INVALID_TARGET",
229322
+ message: "Comment target must be a TextAddress or TextTarget.",
229323
+ details: { target }
229324
+ }
229325
+ };
229216
229326
  for (const seg of segments)
229217
229327
  if (seg.range.start === seg.range.end)
229218
229328
  return {
@@ -234132,8 +234242,9 @@ function resolveCurrentSelectionInfo(editor, input2) {
234132
234242
  activeCommentIds: [],
234133
234243
  activeChangeIds: []
234134
234244
  };
234135
- const { from: from$1, to, empty: empty$1 } = state.selection;
234136
- const segments = collectTextSegments(state.doc, from$1, to);
234245
+ const sel = state.selection;
234246
+ const { from: from$1, to, empty: empty$1 } = sel;
234247
+ const segments = shouldProjectTextTarget(sel) ? collectTextSegments(state.doc, from$1, to) : null;
234137
234248
  const target = segments && segments.length > 0 ? buildTextTarget(segments) : null;
234138
234249
  const activeMarks = collectActiveMarks(state, from$1, to);
234139
234250
  const { commentIds: activeCommentIds, changeIds: activeChangeRawIds } = collectActiveEntityIds(state, from$1, to);
@@ -234154,6 +234265,15 @@ function buildTextTarget(segments) {
234154
234265
  segments
234155
234266
  };
234156
234267
  }
234268
+ function shouldProjectTextTarget(selection) {
234269
+ if (!selection || typeof selection !== "object")
234270
+ return false;
234271
+ if (selection instanceof NodeSelection)
234272
+ return false;
234273
+ if ("$anchorCell" in selection)
234274
+ return false;
234275
+ return true;
234276
+ }
234157
234277
  function collectTextSegments(doc$12, from$1, to) {
234158
234278
  const segments = [];
234159
234279
  let abort = false;
@@ -234506,29 +234626,12 @@ function toTableFailure(code7, message, details) {
234506
234626
  }
234507
234627
  };
234508
234628
  }
234509
- function createSeparatorParagraph(schema) {
234510
- const paragraphType = schema.nodes.paragraph;
234511
- if (!paragraphType)
234512
- return null;
234513
- const separatorAttrs = {
234514
- sdBlockId: v4_default(),
234515
- paraId: generateDocxHexId()
234516
- };
234517
- return paragraphType.createAndFill(separatorAttrs) ?? paragraphType.createAndFill();
234518
- }
234519
- function buildTableSuccess(tableAddress, trackedChangeRefs) {
234520
- return {
234521
- success: true,
234522
- table: tableAddress,
234523
- trackedChangeRefs
234524
- };
234525
- }
234526
234629
  function syncExtractedTableAttrs(tp) {
234527
234630
  const extracted = {};
234528
234631
  extracted.tableStyleId = tp.tableStyleId ?? null;
234529
234632
  extracted.justification = tp.justification ?? null;
234530
234633
  extracted.tableLayout = tp.tableLayout ?? null;
234531
- extracted.borders = convertTableBordersToPixelUnits(tp.borders) ?? tp.borders ?? null;
234634
+ extracted.borders = convertTableBordersToPixelUnits(tp.borders) ?? {};
234532
234635
  const indent2 = tp.tableIndent;
234533
234636
  if (indent2?.value != null)
234534
234637
  extracted.tableIndent = {
@@ -234540,7 +234643,7 @@ function syncExtractedTableAttrs(tp) {
234540
234643
  const spacing = tp.tableCellSpacing;
234541
234644
  if (spacing?.value != null) {
234542
234645
  extracted.tableCellSpacing = {
234543
- w: String(spacing.value),
234646
+ value: twipsToPixels(spacing.value),
234544
234647
  type: spacing.type ?? "dxa"
234545
234648
  };
234546
234649
  extracted.borderCollapse = "separate";
@@ -234548,23 +234651,23 @@ function syncExtractedTableAttrs(tp) {
234548
234651
  extracted.tableCellSpacing = null;
234549
234652
  extracted.borderCollapse = null;
234550
234653
  }
234551
- const tw = tp.tableWidth;
234552
- if (tw)
234553
- if (tw.type === "pct" && typeof tw.value === "number")
234654
+ const width = tp.tableWidth;
234655
+ if (width)
234656
+ if (width.type === "pct" && typeof width.value === "number")
234554
234657
  extracted.tableWidth = {
234555
- value: tw.value,
234658
+ value: width.value,
234556
234659
  type: "pct"
234557
234660
  };
234558
- else if (tw.type === "auto")
234661
+ else if (width.type === "auto")
234559
234662
  extracted.tableWidth = {
234560
234663
  width: 0,
234561
234664
  type: "auto"
234562
234665
  };
234563
- else if (tw.value != null) {
234564
- const widthPx = twipsToPixels(tw.value);
234666
+ else if (width.value != null) {
234667
+ const widthPx = twipsToPixels(width.value);
234565
234668
  extracted.tableWidth = widthPx != null ? {
234566
234669
  width: widthPx,
234567
- type: tw.type
234670
+ type: width.type
234568
234671
  } : null;
234569
234672
  } else
234570
234673
  extracted.tableWidth = null;
@@ -234579,6 +234682,95 @@ function convertTableBordersToPixelUnits(value) {
234579
234682
  mapBorderSizes(clone, eighthPointsToPixels);
234580
234683
  return Object.keys(clone).length > 0 ? clone : undefined;
234581
234684
  }
234685
+ function buildWidthAuthoringTableAttrs(currentAttrs, attrOverrides = {}, tablePropertyOverrides = {}) {
234686
+ const currentTableProps = currentAttrs.tableProperties ?? {};
234687
+ const nextTableWidth = resolveWidthAuthoringTableWidth(currentAttrs, attrOverrides, tablePropertyOverrides);
234688
+ const updatedTableProps = {
234689
+ ...currentTableProps,
234690
+ ...tablePropertyOverrides,
234691
+ tableLayout: "fixed"
234692
+ };
234693
+ if (nextTableWidth)
234694
+ updatedTableProps.tableWidth = nextTableWidth;
234695
+ else
234696
+ delete updatedTableProps.tableWidth;
234697
+ return {
234698
+ ...currentAttrs,
234699
+ tableProperties: updatedTableProps,
234700
+ ...attrOverrides,
234701
+ ...syncExtractedTableAttrs(updatedTableProps),
234702
+ userEdited: true
234703
+ };
234704
+ }
234705
+ function resolveWidthAuthoringTableWidth(currentAttrs, attrOverrides, tablePropertyOverrides) {
234706
+ const explicitOverride = normalizeTableWidthMeasurement(tablePropertyOverrides.tableWidth);
234707
+ if (explicitOverride)
234708
+ return explicitOverride;
234709
+ const gridWidth = sumGridColumnTwips(attrOverrides.grid ?? currentAttrs.grid);
234710
+ if (gridWidth != null)
234711
+ return {
234712
+ value: gridWidth,
234713
+ type: "dxa"
234714
+ };
234715
+ return null;
234716
+ }
234717
+ function sumGridColumnTwips(grid) {
234718
+ const columns = normalizeGridColumns$1(grid);
234719
+ if (!columns || columns.length === 0)
234720
+ return null;
234721
+ const total = columns.reduce((sum, column) => sum + column.col, 0);
234722
+ return total > 0 ? total : null;
234723
+ }
234724
+ function normalizeGridColumns$1(grid) {
234725
+ if (Array.isArray(grid)) {
234726
+ const columns = grid.map((width) => normalizeGridWidth$1(width)).filter((width) => width != null);
234727
+ return columns.length > 0 ? columns : null;
234728
+ }
234729
+ if (grid && typeof grid === "object") {
234730
+ const rawColWidths = grid.colWidths;
234731
+ if (Array.isArray(rawColWidths)) {
234732
+ const columns = rawColWidths.map((width) => normalizeGridWidth$1(width)).filter((width) => width != null);
234733
+ return columns.length > 0 ? columns : null;
234734
+ }
234735
+ }
234736
+ return null;
234737
+ }
234738
+ function normalizeGridWidth$1(width) {
234739
+ if (typeof width === "number" && Number.isFinite(width) && width > 0)
234740
+ return { col: Math.round(width) };
234741
+ const value = width?.col;
234742
+ if (typeof value === "number" && Number.isFinite(value) && value > 0)
234743
+ return { col: Math.round(value) };
234744
+ return null;
234745
+ }
234746
+ function normalizeTableWidthMeasurement(width) {
234747
+ if (!width || typeof width !== "object")
234748
+ return null;
234749
+ const value = width.value;
234750
+ if (width.type !== "dxa" || typeof value !== "number" || !Number.isFinite(value) || value <= 0)
234751
+ return null;
234752
+ return {
234753
+ value: Math.round(value),
234754
+ type: "dxa"
234755
+ };
234756
+ }
234757
+ function createSeparatorParagraph(schema) {
234758
+ const paragraphType = schema.nodes.paragraph;
234759
+ if (!paragraphType)
234760
+ return null;
234761
+ const separatorAttrs = {
234762
+ sdBlockId: v4_default(),
234763
+ paraId: generateDocxHexId()
234764
+ };
234765
+ return paragraphType.createAndFill(separatorAttrs) ?? paragraphType.createAndFill();
234766
+ }
234767
+ function buildTableSuccess(tableAddress, trackedChangeRefs) {
234768
+ return {
234769
+ success: true,
234770
+ table: tableAddress,
234771
+ trackedChangeRefs
234772
+ };
234773
+ }
234582
234774
  function normalizeGridWidth(width) {
234583
234775
  if (typeof width === "number" && Number.isFinite(width))
234584
234776
  return { col: Math.round(width) };
@@ -234641,6 +234833,30 @@ function removeGridColumnWidth(grid, deleteIndex) {
234641
234833
  columns: colWidths
234642
234834
  });
234643
234835
  }
234836
+ function buildFirstRowCellWidthProps(attrs, cellStartCol, colspan, colwidth, gridColumns) {
234837
+ const currentCellProps = attrs.tableCellProperties && typeof attrs.tableCellProperties === "object" ? attrs.tableCellProperties : {};
234838
+ const spanTwips = resolveSpanWidthTwips(cellStartCol, colspan, colwidth, gridColumns);
234839
+ if (spanTwips == null)
234840
+ return Object.keys(currentCellProps).length > 0 ? currentCellProps : undefined;
234841
+ return {
234842
+ ...currentCellProps,
234843
+ cellWidth: {
234844
+ value: spanTwips,
234845
+ type: "dxa"
234846
+ }
234847
+ };
234848
+ }
234849
+ function resolveSpanWidthTwips(cellStartCol, colspan, colwidth, gridColumns) {
234850
+ const boundedSpan = Math.max(1, colspan);
234851
+ if (Array.isArray(gridColumns) && cellStartCol >= 0 && cellStartCol + boundedSpan <= gridColumns.length) {
234852
+ const gridSpanTwips = gridColumns.slice(cellStartCol, cellStartCol + boundedSpan).reduce((sum, column) => sum + normalizeGridWidth(column).col, 0);
234853
+ if (gridSpanTwips > 0)
234854
+ return gridSpanTwips;
234855
+ }
234856
+ const spanWidthPx = colwidth.slice(0, boundedSpan).reduce((sum, width) => sum + (Number.isFinite(width) ? width : 0), 0);
234857
+ if (spanWidthPx > 0)
234858
+ return Math.round(spanWidthPx * PIXELS_TO_TWIPS);
234859
+ }
234644
234860
  function normalizeCellAttrsForSingleCell(attrs) {
234645
234861
  const currentColwidth = Array.isArray(attrs.colwidth) ? attrs.colwidth : null;
234646
234862
  const tableCellProperties = { ...attrs.tableCellProperties ?? {} };
@@ -235518,8 +235734,13 @@ function tablesSetColumnWidthAdapter(editor, input2, options) {
235518
235734
  const tablePos = table2.candidate.pos;
235519
235735
  const tableStart = tablePos + 1;
235520
235736
  const tableNode = table2.candidate.node;
235737
+ const tableAttrs = tableNode.attrs;
235521
235738
  const map$12 = TableMap.get(tableNode);
235522
235739
  const widthPx = Math.round(input2.widthPt * (96 / 72));
235740
+ const normalizedGrid = normalizeGridColumns(tableAttrs.grid);
235741
+ const nextGridColumns = normalizedGrid?.columns.slice();
235742
+ if (nextGridColumns && columnIndex < nextGridColumns.length)
235743
+ nextGridColumns[columnIndex] = { col: Math.round(input2.widthPt * POINTS_TO_TWIPS) };
235523
235744
  const processed = /* @__PURE__ */ new Set;
235524
235745
  for (let row2 = 0;row2 < map$12.height; row2++) {
235525
235746
  const index2 = row2 * map$12.width + columnIndex;
@@ -235533,29 +235754,31 @@ function tablesSetColumnWidthAdapter(editor, input2, options) {
235533
235754
  const attrs = cell2.attrs;
235534
235755
  const colspan = attrs.colspan || 1;
235535
235756
  const colwidth = attrs.colwidth?.slice() ?? [];
235536
- const withinCol = columnIndex - map$12.colCount(pos);
235757
+ const cellStartCol = map$12.colCount(pos);
235758
+ const withinCol = columnIndex - cellStartCol;
235537
235759
  while (colwidth.length < colspan)
235538
235760
  colwidth.push(0);
235539
235761
  colwidth[withinCol] = widthPx;
235540
- tr.setNodeMarkup(tableStart + pos, null, {
235762
+ const nextAttrs = {
235541
235763
  ...attrs,
235542
235764
  colwidth
235543
- });
235765
+ };
235766
+ if (row2 === 0) {
235767
+ const nextCellProps = buildFirstRowCellWidthProps(attrs, cellStartCol, colspan, colwidth, nextGridColumns);
235768
+ if (nextCellProps)
235769
+ nextAttrs.tableCellProperties = nextCellProps;
235770
+ else
235771
+ delete nextAttrs.tableCellProperties;
235772
+ }
235773
+ tr.setNodeMarkup(tableStart + pos, null, nextAttrs);
235544
235774
  }
235545
- const tableAttrs = tableNode.attrs;
235546
- const normalizedGrid = normalizeGridColumns(tableAttrs.grid);
235547
- if (normalizedGrid && columnIndex < normalizedGrid.columns.length) {
235548
- const newColumns = normalizedGrid.columns.slice();
235549
- newColumns[columnIndex] = { col: Math.round(input2.widthPt * POINTS_TO_TWIPS) };
235550
- tr.setNodeMarkup(tablePos, null, {
235551
- ...tableAttrs,
235552
- grid: serializeGridColumns(tableAttrs.grid, {
235553
- ...normalizedGrid,
235554
- columns: newColumns
235555
- }),
235556
- userEdited: true
235775
+ const tableAttrUpdates = {};
235776
+ if (normalizedGrid && nextGridColumns)
235777
+ tableAttrUpdates.grid = serializeGridColumns(tableAttrs.grid, {
235778
+ ...normalizedGrid,
235779
+ columns: nextGridColumns
235557
235780
  });
235558
- }
235781
+ tr.setNodeMarkup(tablePos, null, buildWidthAuthoringTableAttrs(tableAttrs, tableAttrUpdates));
235559
235782
  applyDirectMutationMeta(tr);
235560
235783
  editor.dispatch(tr);
235561
235784
  clearIndexCache(editor);
@@ -235579,7 +235802,10 @@ function tablesDistributeColumnsAdapter(editor, input2, options) {
235579
235802
  const tablePos = candidate.pos;
235580
235803
  const tableStart = tablePos + 1;
235581
235804
  const tableNode = candidate.node;
235805
+ const tableAttrs = tableNode.attrs;
235582
235806
  const map$12 = TableMap.get(tableNode);
235807
+ const normalizedGrid = normalizeGridColumns(tableAttrs.grid);
235808
+ const nextGridColumns = normalizedGrid?.columns.slice();
235583
235809
  const rangeStart = input2.columnRange?.start ?? 0;
235584
235810
  const rangeEnd = input2.columnRange?.end ?? map$12.width - 1;
235585
235811
  const rangeWidth = rangeEnd - rangeStart + 1;
@@ -235595,6 +235821,12 @@ function tablesDistributeColumnsAdapter(editor, input2, options) {
235595
235821
  totalWidth += colwidth?.[withinCol] ?? 100;
235596
235822
  }
235597
235823
  const evenWidth = Math.round(totalWidth / rangeWidth);
235824
+ if (nextGridColumns) {
235825
+ const evenWidthTwips = Math.max(1, Math.round(evenWidth * PIXELS_TO_TWIPS));
235826
+ const maxColumn = Math.min(rangeEnd, nextGridColumns.length - 1);
235827
+ for (let col = Math.max(rangeStart, 0);col <= maxColumn; col++)
235828
+ nextGridColumns[col] = { col: evenWidthTwips };
235829
+ }
235598
235830
  const processed = /* @__PURE__ */ new Set;
235599
235831
  for (let row2 = 0;row2 < map$12.height; row2++)
235600
235832
  for (let col = rangeStart;col <= rangeEnd; col++) {
@@ -235617,29 +235849,26 @@ function tablesDistributeColumnsAdapter(editor, input2, options) {
235617
235849
  if (absCol >= rangeStart && absCol <= rangeEnd)
235618
235850
  newColwidth[c] = evenWidth;
235619
235851
  }
235620
- tr.setNodeMarkup(tableStart + pos, null, {
235852
+ const nextAttrs = {
235621
235853
  ...attrs,
235622
235854
  colwidth: newColwidth
235623
- });
235855
+ };
235856
+ if (row2 === 0) {
235857
+ const nextCellProps = buildFirstRowCellWidthProps(attrs, cellStartCol, colspan, newColwidth, nextGridColumns);
235858
+ if (nextCellProps)
235859
+ nextAttrs.tableCellProperties = nextCellProps;
235860
+ else
235861
+ delete nextAttrs.tableCellProperties;
235862
+ }
235863
+ tr.setNodeMarkup(tableStart + pos, null, nextAttrs);
235624
235864
  }
235625
- const tableAttrs = tableNode.attrs;
235626
- const normalizedGrid = normalizeGridColumns(tableAttrs.grid);
235627
- const tableAttrUpdates = {
235628
- ...tableAttrs,
235629
- userEdited: true
235630
- };
235631
- if (normalizedGrid) {
235632
- const newColumns = normalizedGrid.columns.slice();
235633
- const evenWidthTwips = Math.max(1, Math.round(evenWidth * PIXELS_TO_TWIPS));
235634
- const maxColumn = Math.min(rangeEnd, newColumns.length - 1);
235635
- for (let col = Math.max(rangeStart, 0);col <= maxColumn; col++)
235636
- newColumns[col] = { col: evenWidthTwips };
235865
+ const tableAttrUpdates = {};
235866
+ if (normalizedGrid && nextGridColumns)
235637
235867
  tableAttrUpdates.grid = serializeGridColumns(tableAttrs.grid, {
235638
235868
  ...normalizedGrid,
235639
- columns: newColumns
235869
+ columns: nextGridColumns
235640
235870
  });
235641
- }
235642
- tr.setNodeMarkup(tablePos, null, tableAttrUpdates);
235871
+ tr.setNodeMarkup(tablePos, null, buildWidthAuthoringTableAttrs(tableAttrs, tableAttrUpdates));
235643
235872
  applyDirectMutationMeta(tr);
235644
235873
  editor.dispatch(tr);
235645
235874
  clearIndexCache(editor);
@@ -236223,6 +236452,10 @@ function tablesSetCellPropertiesAdapter(editor, input2, options) {
236223
236452
  }
236224
236453
  };
236225
236454
  tr.setNodeMarkup(cellPos, null, newAttrs);
236455
+ if (input2.preferredWidthPt !== undefined) {
236456
+ const tableAttrs = table2.candidate.node.attrs;
236457
+ tr.setNodeMarkup(table2.candidate.pos, null, buildWidthAuthoringTableAttrs(tableAttrs));
236458
+ }
236226
236459
  applyDirectMutationMeta(tr);
236227
236460
  editor.dispatch(tr);
236228
236461
  clearIndexCache(editor);
@@ -250754,7 +250987,7 @@ function normalizeFieldAnnotationMetadata(attrs) {
250754
250987
  borderColor: normalizeColorValue2(attrs.borderColor),
250755
250988
  highlighted: toBoolean$2(attrs.highlighted, true),
250756
250989
  fontFamily: toNullableString(attrs.fontFamily),
250757
- fontSize: normalizeFontSize$1(attrs.fontSize),
250990
+ fontSize: normalizeFontSize$2(attrs.fontSize),
250758
250991
  textColor: normalizeColorValue2(attrs.textColor) ?? null,
250759
250992
  textHighlight: normalizeColorValue2(attrs.textHighlight) ?? null,
250760
250993
  linkUrl: toNullableString(attrs.linkUrl),
@@ -250848,7 +251081,7 @@ function normalizeColorValue2(value) {
250848
251081
  return;
250849
251082
  return trimmed;
250850
251083
  }
250851
- function normalizeFontSize$1(value) {
251084
+ function normalizeFontSize$2(value) {
250852
251085
  if (value == null)
250853
251086
  return null;
250854
251087
  if (typeof value === "number")
@@ -252450,11 +252683,15 @@ function tableNodeToBlock(node3, { nextBlockId, positions, storyKey, trackedChan
252450
252683
  tableAttrs.tableWidth = hydratedTableStyle.tableWidth;
252451
252684
  if (node3.attrs?.tableIndent && typeof node3.attrs.tableIndent === "object")
252452
252685
  tableAttrs.tableIndent = { ...node3.attrs.tableIndent };
252686
+ else if (hydratedTableStyle?.tableIndent)
252687
+ tableAttrs.tableIndent = { ...hydratedTableStyle.tableIndent };
252453
252688
  if (defaultCellPadding && typeof defaultCellPadding === "object")
252454
252689
  tableAttrs.defaultCellPadding = { ...defaultCellPadding };
252455
252690
  const tableLayout = node3.attrs?.tableLayout;
252456
252691
  if (tableLayout)
252457
252692
  tableAttrs.tableLayout = tableLayout;
252693
+ else if (hydratedTableStyle?.tableLayout)
252694
+ tableAttrs.tableLayout = hydratedTableStyle.tableLayout;
252458
252695
  const tableProperties = node3.attrs?.tableProperties;
252459
252696
  if (tableProperties && typeof tableProperties === "object")
252460
252697
  tableAttrs.tableProperties = tableProperties;
@@ -254417,23 +254654,37 @@ function applyTableIndent(x, width, indent2, columnWidth) {
254417
254654
  x: shiftedX,
254418
254655
  width: Math.max(0, width - indent2)
254419
254656
  };
254657
+ if (width > columnWidth)
254658
+ return {
254659
+ x: shiftedX,
254660
+ width
254661
+ };
254420
254662
  const maxWidthWithinColumn = Math.max(0, columnWidth - indent2);
254421
254663
  return {
254422
254664
  x: shiftedX,
254423
254665
  width: Math.min(width, maxWidthWithinColumn)
254424
254666
  };
254425
254667
  }
254668
+ function resolveRenderedTableWidth(columnWidth, measuredWidth, attrs) {
254669
+ const safeMeasuredWidth = Number.isFinite(measuredWidth) && measuredWidth > 0 ? measuredWidth : Math.max(0, columnWidth);
254670
+ const configuredWidth = resolveTableWidthAttr(attrs?.tableWidth);
254671
+ if (!configuredWidth)
254672
+ return safeMeasuredWidth;
254673
+ if (configuredWidth.type === "pct")
254674
+ return Math.max(0, Math.round(columnWidth * (configuredWidth.width / OOXML_PCT_DIVISOR)));
254675
+ return safeMeasuredWidth;
254676
+ }
254426
254677
  function resolveTableFrame(baseX, columnWidth, tableWidth, attrs) {
254427
- const width = Math.min(columnWidth, tableWidth);
254678
+ const width = resolveRenderedTableWidth(columnWidth, tableWidth, attrs);
254428
254679
  const justification = typeof attrs?.justification === "string" ? attrs.justification : undefined;
254429
254680
  if (justification === "center")
254430
254681
  return {
254431
- x: baseX + Math.max(0, (columnWidth - width) / 2),
254682
+ x: baseX + (columnWidth - width) / 2,
254432
254683
  width
254433
254684
  };
254434
254685
  if (justification === "right" || justification === "end")
254435
254686
  return {
254436
- x: baseX + Math.max(0, columnWidth - width),
254687
+ x: baseX + (columnWidth - width),
254437
254688
  width
254438
254689
  };
254439
254690
  return applyTableIndent(baseX, width, getTableIndentWidth(attrs), columnWidth);
@@ -254863,13 +255114,14 @@ function layoutMonolithicTable(context) {
254863
255114
  state = context.ensurePage();
254864
255115
  const height = Math.min(context.measure.totalHeight, state.contentBottom - state.cursorY);
254865
255116
  const baseX = context.columnX(state.columnIndex);
254866
- const baseWidth = Math.min(context.columnWidth, context.measure.totalWidth || context.columnWidth);
255117
+ const baseWidth = Math.max(0, context.measure.totalWidth || context.columnWidth);
254867
255118
  const { x, width } = resolveTableFrame(baseX, context.columnWidth, baseWidth, context.block.attrs);
254868
255119
  const columnWidths = rescaleColumnWidths(context.measure.columnWidths, context.measure.totalWidth, width);
254869
255120
  const metadata = generateFragmentMetadata(context.measure, context.block, 0, context.block.rows.length, 0, columnWidths);
254870
255121
  const fragment2 = {
254871
255122
  kind: "table",
254872
255123
  blockId: context.block.id,
255124
+ columnIndex: state.columnIndex,
254873
255125
  fromRow: 0,
254874
255126
  toRow: context.block.rows.length,
254875
255127
  x,
@@ -254941,12 +255193,13 @@ function layoutTableBlock({ block, measure, columnWidth, ensurePage, advanceColu
254941
255193
  let pendingPartialRow = null;
254942
255194
  if (block.rows.length === 0 && measure.totalHeight > 0) {
254943
255195
  const height = Math.min(measure.totalHeight, state.contentBottom - state.cursorY);
254944
- const { x, width } = resolveTableFrame(columnX(state.columnIndex), columnWidth, Math.min(columnWidth, measure.totalWidth || columnWidth), block.attrs);
255196
+ const { x, width } = resolveTableFrame(columnX(state.columnIndex), columnWidth, Math.max(0, measure.totalWidth || columnWidth), block.attrs);
254945
255197
  const columnWidths = rescaleColumnWidths(measure.columnWidths, measure.totalWidth, width);
254946
255198
  const metadata = generateFragmentMetadata(measure, block, 0, 0, 0, columnWidths);
254947
255199
  const fragment2 = {
254948
255200
  kind: "table",
254949
255201
  blockId: block.id,
255202
+ columnIndex: state.columnIndex,
254950
255203
  fromRow: 0,
254951
255204
  toRow: 0,
254952
255205
  x,
@@ -255011,11 +255264,12 @@ function layoutTableBlock({ block, measure, columnWidth, ensurePage, advanceColu
255011
255264
  });
255012
255265
  const fragmentHeight$1 = computeFragmentHeight$1(measure, rowIndex, rowIndex + 1, repeatHeaderCount, borderCollapse, continuationPartialRow);
255013
255266
  if (fragmentHeight$1 > 0 && madeProgress) {
255014
- const { x: x$1, width: width$1 } = resolveTableFrame(columnX(state.columnIndex), columnWidth, Math.min(columnWidth, measure.totalWidth || columnWidth), block.attrs);
255267
+ const { x: x$1, width: width$1 } = resolveTableFrame(columnX(state.columnIndex), columnWidth, Math.max(0, measure.totalWidth || columnWidth), block.attrs);
255015
255268
  const scaledWidths$1 = rescaleColumnWidths(measure.columnWidths, measure.totalWidth, width$1);
255016
255269
  const fragment$1 = {
255017
255270
  kind: "table",
255018
255271
  blockId: block.id,
255272
+ columnIndex: state.columnIndex,
255019
255273
  fromRow: rowIndex,
255020
255274
  toRow: rowIndex + 1,
255021
255275
  x: x$1,
@@ -255067,11 +255321,12 @@ function layoutTableBlock({ block, measure, columnWidth, ensurePage, advanceColu
255067
255321
  }
255068
255322
  const forcedEndRow = bodyStartRow + 1;
255069
255323
  const fragmentHeight$1 = computeFragmentHeight$1(measure, bodyStartRow, forcedEndRow, repeatHeaderCount, borderCollapse, forcedPartialRow);
255070
- const { x: x$1, width: width$1 } = resolveTableFrame(columnX(state.columnIndex), columnWidth, Math.min(columnWidth, measure.totalWidth || columnWidth), block.attrs);
255324
+ const { x: x$1, width: width$1 } = resolveTableFrame(columnX(state.columnIndex), columnWidth, Math.max(0, measure.totalWidth || columnWidth), block.attrs);
255071
255325
  const scaledWidths$1 = rescaleColumnWidths(measure.columnWidths, measure.totalWidth, width$1);
255072
255326
  const fragment$1 = {
255073
255327
  kind: "table",
255074
255328
  blockId: block.id,
255329
+ columnIndex: state.columnIndex,
255075
255330
  fromRow: bodyStartRow,
255076
255331
  toRow: forcedEndRow,
255077
255332
  x: x$1,
@@ -255096,11 +255351,12 @@ function layoutTableBlock({ block, measure, columnWidth, ensurePage, advanceColu
255096
255351
  continue;
255097
255352
  }
255098
255353
  const fragmentHeight = computeFragmentHeight$1(measure, bodyStartRow, endRow, repeatHeaderCount, borderCollapse, partialRow);
255099
- const { x, width } = resolveTableFrame(columnX(state.columnIndex), columnWidth, Math.min(columnWidth, measure.totalWidth || columnWidth), block.attrs);
255354
+ const { x, width } = resolveTableFrame(columnX(state.columnIndex), columnWidth, Math.max(0, measure.totalWidth || columnWidth), block.attrs);
255100
255355
  const scaledWidths = rescaleColumnWidths(measure.columnWidths, measure.totalWidth, width);
255101
255356
  const fragment2 = {
255102
255357
  kind: "table",
255103
255358
  blockId: block.id,
255359
+ columnIndex: state.columnIndex,
255104
255360
  fromRow: bodyStartRow,
255105
255361
  toRow: endRow,
255106
255362
  x,
@@ -257354,7 +257610,7 @@ function measureCharacterX(block, line, charOffset, availableWidthOverride, alig
257354
257610
  }
257355
257611
  const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text ?? "";
257356
257612
  const runLength = text5.length;
257357
- const displayText = applyTextTransform$2(text5, isTabRun$1(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? undefined : run2.textTransform);
257613
+ const displayText = applyTextTransform$3(text5, isTabRun$1(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? undefined : run2.textTransform);
257358
257614
  if (currentCharOffset + runLength >= charOffset) {
257359
257615
  const offsetInRun = charOffset - currentCharOffset;
257360
257616
  ctx$1.font = getRunFontString(run2);
@@ -257403,7 +257659,7 @@ function measureCharacterXSegmentBased(block, line, charOffset, ctx$1) {
257403
257659
  return segmentBaseX + (offsetInSegment > 0 ? segment.width ?? 0 : 0);
257404
257660
  if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math")
257405
257661
  return segmentBaseX + (offsetInSegment >= segmentChars ? segment.width ?? 0 : 0);
257406
- const textUpToTarget = applyTextTransform$2(run2.text ?? "", "textTransform" in run2 ? run2.textTransform : undefined).slice(segment.fromChar, segment.toChar).slice(0, offsetInSegment);
257662
+ const textUpToTarget = applyTextTransform$3(run2.text ?? "", "textTransform" in run2 ? run2.textTransform : undefined).slice(segment.fromChar, segment.toChar).slice(0, offsetInSegment);
257407
257663
  ctx$1.font = getRunFontString(run2);
257408
257664
  const measured = ctx$1.measureText(textUpToTarget);
257409
257665
  const spacingWidth = computeLetterSpacingWidth(run2, offsetInSegment, segmentChars);
@@ -257496,7 +257752,7 @@ function findCharacterAtX(block, line, x, pmStart, availableWidthOverride, align
257496
257752
  }
257497
257753
  const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text ?? "";
257498
257754
  const runLength = text5.length;
257499
- const displayText = applyTextTransform$2(text5, isTabRun$1(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? undefined : run2.textTransform);
257755
+ const displayText = applyTextTransform$3(text5, isTabRun$1(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? undefined : run2.textTransform);
257500
257756
  if (runLength === 0)
257501
257757
  continue;
257502
257758
  ctx$1.font = getRunFontString(run2);
@@ -258139,7 +258395,7 @@ function measureRunSliceWidth(run2, fromChar, toChar) {
258139
258395
  const context = getCtx();
258140
258396
  const fullText = runText(run2);
258141
258397
  const transform = isTextRun$3(run2) ? run2.textTransform : undefined;
258142
- const text5 = applyTextTransform$1(fullText.slice(fromChar, toChar), transform, fullText, fromChar);
258398
+ const text5 = applyTextTransform$2(fullText.slice(fromChar, toChar), transform, fullText, fromChar);
258143
258399
  if (!context) {
258144
258400
  const size$1 = (isTextRun$3(run2) ? run2 : null)?.fontSize ?? 16;
258145
258401
  return Math.max(1, text5.length * (size$1 * 0.6));
@@ -259196,32 +259452,12 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
259196
259452
  return;
259197
259453
  if (!block || block.kind !== "table")
259198
259454
  return;
259199
- const tableWidthRaw = Math.max(0, measure.totalWidth ?? 0);
259200
- let tableWidth = Math.min(contentWidth, tableWidthRaw);
259201
- let tableX = columnX;
259202
- const justification = typeof block.attrs?.justification === "string" ? block.attrs.justification : undefined;
259203
- if (justification === "center")
259204
- tableX = columnX + Math.max(0, (contentWidth - tableWidth) / 2);
259205
- else if (justification === "right" || justification === "end")
259206
- tableX = columnX + Math.max(0, contentWidth - tableWidth);
259207
- else {
259208
- const indentValue = block.attrs?.tableIndent?.width;
259209
- const indent2 = typeof indentValue === "number" && Number.isFinite(indentValue) ? indentValue : 0;
259210
- tableX += indent2;
259211
- tableWidth = Math.max(0, tableWidth - indent2);
259212
- }
259213
- let fragmentColumnWidths;
259214
- if (tableWidthRaw > tableWidth && measure.columnWidths && measure.columnWidths.length > 0 && tableWidthRaw > 0) {
259215
- const scale = tableWidth / tableWidthRaw;
259216
- fragmentColumnWidths = measure.columnWidths.map((w) => Math.max(1, Math.round(w * scale)));
259217
- const scaledSum = fragmentColumnWidths.reduce((a2, b$1) => a2 + b$1, 0);
259218
- const target = Math.round(tableWidth);
259219
- if (scaledSum !== target && fragmentColumnWidths.length > 0)
259220
- fragmentColumnWidths[fragmentColumnWidths.length - 1] = Math.max(1, fragmentColumnWidths[fragmentColumnWidths.length - 1] + (target - scaledSum));
259221
- }
259455
+ const { x: tableX, width: tableWidth } = resolveTableFrame(columnX, contentWidth, Math.max(0, measure.totalWidth ?? contentWidth), block.attrs);
259456
+ const fragmentColumnWidths = rescaleColumnWidths(measure.columnWidths, measure.totalWidth, tableWidth);
259222
259457
  page.fragments.push({
259223
259458
  kind: "table",
259224
259459
  blockId: range.blockId,
259460
+ columnIndex,
259225
259461
  fromRow: 0,
259226
259462
  toRow: block.rows.length,
259227
259463
  x: tableX,
@@ -259964,7 +260200,7 @@ function clickToPositionGeometry(layout, blocks2, measures, containerPoint, opti
259964
260200
  layoutEpoch,
259965
260201
  blockId: tableHit.fragment.blockId,
259966
260202
  pageIndex,
259967
- column: determineColumn(layout, tableHit.fragment.x),
260203
+ column: determineTableColumn(layout, tableHit.fragment),
259968
260204
  lineIndex
259969
260205
  };
259970
260206
  }
@@ -259975,7 +260211,7 @@ function clickToPositionGeometry(layout, blocks2, measures, containerPoint, opti
259975
260211
  layoutEpoch,
259976
260212
  blockId: tableHit.fragment.blockId,
259977
260213
  pageIndex,
259978
- column: determineColumn(layout, tableHit.fragment.x),
260214
+ column: determineTableColumn(layout, tableHit.fragment),
259979
260215
  lineIndex: 0
259980
260216
  };
259981
260217
  }
@@ -261426,7 +261662,7 @@ function areNumberListsEqual(left$1, right$1) {
261426
261662
  return false;
261427
261663
  return true;
261428
261664
  }
261429
- function isWordCharacter(char) {
261665
+ function isWordCharacter$1(char) {
261430
261666
  if (!char)
261431
261667
  return false;
261432
261668
  return WORD_CHARACTER_REGEX.test(char);
@@ -261509,17 +261745,17 @@ function computeWordSelectionRangeAt(state, pos) {
261509
261745
  const parentStart = textblockPos.start();
261510
261746
  const parentEnd = textblockPos.end();
261511
261747
  const sampleEnd = Math.min(pos + 1, parentEnd);
261512
- if (!isWordCharacter(state.doc.textBetween(pos, sampleEnd, "\x00", "\x00")))
261748
+ if (!isWordCharacter$1(state.doc.textBetween(pos, sampleEnd, "\x00", "\x00")))
261513
261749
  return null;
261514
261750
  let startPos = pos;
261515
261751
  while (startPos > parentStart) {
261516
- if (!isWordCharacter(state.doc.textBetween(startPos - 1, startPos, "\x00", "\x00")))
261752
+ if (!isWordCharacter$1(state.doc.textBetween(startPos - 1, startPos, "\x00", "\x00")))
261517
261753
  break;
261518
261754
  startPos -= 1;
261519
261755
  }
261520
261756
  let endPos = pos;
261521
261757
  while (endPos < parentEnd) {
261522
- if (!isWordCharacter(state.doc.textBetween(endPos, endPos + 1, "\x00", "\x00")))
261758
+ if (!isWordCharacter$1(state.doc.textBetween(endPos, endPos + 1, "\x00", "\x00")))
261523
261759
  break;
261524
261760
  endPos += 1;
261525
261761
  }
@@ -264790,6 +265026,1369 @@ function getFontMetrics(ctx$1, fontInfo, mode, fonts) {
264790
265026
  fontMetricsCache.set(key2, result);
264791
265027
  return result;
264792
265028
  }
265029
+ function computeFixedTableColumnWidths(input2) {
265030
+ const gridColumnCount = Math.max(0, sanitizeColumnCount(input2.gridColumnCount), Array.isArray(input2.preferredColumnWidths) ? input2.preferredColumnWidths.length : 0);
265031
+ const preferredTableWidth = sanitizeOptionalWidth$1(input2.preferredTableWidth);
265032
+ const defaultAddedColumnWidth = resolveDefaultAddedColumnWidth(input2.preferredColumnWidths, preferredTableWidth);
265033
+ const columnWidths = buildInitialGrid(input2.preferredColumnWidths, gridColumnCount, defaultAddedColumnWidth);
265034
+ if (input2.preserveAuthoredGrid === true)
265035
+ return {
265036
+ columnWidths,
265037
+ totalWidth: sumWidths$2(columnWidths),
265038
+ gridColumnCount: columnWidths.length,
265039
+ preferredTableWidth
265040
+ };
265041
+ if (input2.rows.length === 0) {
265042
+ if (preferredTableWidth != null)
265043
+ shrinkToPreferredTableWidth(columnWidths, preferredTableWidth);
265044
+ return {
265045
+ columnWidths,
265046
+ totalWidth: sumWidths$2(columnWidths),
265047
+ gridColumnCount: columnWidths.length,
265048
+ preferredTableWidth
265049
+ };
265050
+ }
265051
+ applyFirstRowRequests(columnWidths, input2.rows[0], defaultAddedColumnWidth);
265052
+ if (preferredTableWidth != null)
265053
+ shrinkToPreferredTableWidth(columnWidths, preferredTableWidth);
265054
+ for (const row2 of input2.rows.slice(1)) {
265055
+ applySubsequentRowRequests(columnWidths, row2, defaultAddedColumnWidth);
265056
+ if (preferredTableWidth != null)
265057
+ shrinkToPreferredTableWidth(columnWidths, preferredTableWidth);
265058
+ }
265059
+ return {
265060
+ columnWidths,
265061
+ totalWidth: sumWidths$2(columnWidths),
265062
+ gridColumnCount: columnWidths.length,
265063
+ preferredTableWidth
265064
+ };
265065
+ }
265066
+ function buildInitialGrid(preferredColumnWidths, gridColumnCount, defaultAddedColumnWidth) {
265067
+ const next2 = preferredColumnWidths.slice(0, gridColumnCount).map((width) => sanitizeNonNegativeWidth(width) ?? 0);
265068
+ while (next2.length < gridColumnCount)
265069
+ next2.push(defaultAddedColumnWidth);
265070
+ return next2;
265071
+ }
265072
+ function applyFirstRowRequests(columnWidths, row2, defaultAddedColumnWidth) {
265073
+ ensureGridWidth(columnWidths, row2.logicalColumnCount, defaultAddedColumnWidth);
265074
+ for (const skippedColumn of row2.skippedColumns)
265075
+ setSkippedColumnWidth(columnWidths, skippedColumn, defaultAddedColumnWidth);
265076
+ for (const cell2 of row2.cells)
265077
+ setCellSpanWidth(columnWidths, cell2, defaultAddedColumnWidth);
265078
+ }
265079
+ function applySubsequentRowRequests(columnWidths, row2, defaultAddedColumnWidth) {
265080
+ ensureGridWidth(columnWidths, row2.logicalColumnCount, defaultAddedColumnWidth);
265081
+ for (const skippedColumn of row2.skippedColumns)
265082
+ growSkippedColumnWidth(columnWidths, skippedColumn, defaultAddedColumnWidth);
265083
+ for (const cell2 of row2.cells)
265084
+ growCellSpanWidth(columnWidths, cell2, defaultAddedColumnWidth);
265085
+ }
265086
+ function setSkippedColumnWidth(columnWidths, skippedColumn, defaultAddedColumnWidth) {
265087
+ const preferredWidth = sanitizeOptionalWidth$1(skippedColumn.preferredWidth);
265088
+ if (preferredWidth == null)
265089
+ return;
265090
+ ensureGridWidth(columnWidths, skippedColumn.columnIndex + 1, defaultAddedColumnWidth);
265091
+ columnWidths[skippedColumn.columnIndex] = preferredWidth;
265092
+ }
265093
+ function growSkippedColumnWidth(columnWidths, skippedColumn, defaultAddedColumnWidth) {
265094
+ const preferredWidth = sanitizeOptionalWidth$1(skippedColumn.preferredWidth);
265095
+ if (preferredWidth == null)
265096
+ return;
265097
+ ensureGridWidth(columnWidths, skippedColumn.columnIndex + 1, defaultAddedColumnWidth);
265098
+ columnWidths[skippedColumn.columnIndex] = Math.max(columnWidths[skippedColumn.columnIndex] ?? 0, preferredWidth);
265099
+ }
265100
+ function setCellSpanWidth(columnWidths, cell2, defaultAddedColumnWidth) {
265101
+ const span = Math.max(1, sanitizeColumnCount(cell2.span));
265102
+ const preferredWidth = sanitizeOptionalWidth$1(cell2.preferredWidth);
265103
+ const endColumn = cell2.startColumn + span;
265104
+ ensureGridWidth(columnWidths, endColumn, defaultAddedColumnWidth);
265105
+ if (preferredWidth == null)
265106
+ return;
265107
+ const currentSpanWidth = sumSpan$1(columnWidths, cell2.startColumn, span);
265108
+ const lastColumnIndex = endColumn - 1;
265109
+ columnWidths[lastColumnIndex] = Math.max(0, (columnWidths[lastColumnIndex] ?? 0) + (preferredWidth - currentSpanWidth));
265110
+ }
265111
+ function growCellSpanWidth(columnWidths, cell2, defaultAddedColumnWidth) {
265112
+ const span = Math.max(1, sanitizeColumnCount(cell2.span));
265113
+ const preferredWidth = sanitizeOptionalWidth$1(cell2.preferredWidth);
265114
+ const endColumn = cell2.startColumn + span;
265115
+ ensureGridWidth(columnWidths, endColumn, defaultAddedColumnWidth);
265116
+ if (preferredWidth == null)
265117
+ return;
265118
+ const deficit = preferredWidth - sumSpan$1(columnWidths, cell2.startColumn, span);
265119
+ if (deficit <= 0)
265120
+ return;
265121
+ const lastColumnIndex = endColumn - 1;
265122
+ columnWidths[lastColumnIndex] = Math.max(0, (columnWidths[lastColumnIndex] ?? 0) + deficit);
265123
+ }
265124
+ function shrinkToPreferredTableWidth(columnWidths, preferredTableWidth) {
265125
+ const totalWidth = sumWidths$2(columnWidths);
265126
+ if (preferredTableWidth <= 0 || totalWidth <= preferredTableWidth || totalWidth <= 0)
265127
+ return;
265128
+ const scale = preferredTableWidth / totalWidth;
265129
+ let consumed = 0;
265130
+ for (let index2 = 0;index2 < columnWidths.length; index2++) {
265131
+ if (index2 === columnWidths.length - 1) {
265132
+ columnWidths[index2] = Math.max(0, preferredTableWidth - consumed);
265133
+ continue;
265134
+ }
265135
+ const scaled = Math.max(0, (columnWidths[index2] ?? 0) * scale);
265136
+ columnWidths[index2] = scaled;
265137
+ consumed += scaled;
265138
+ }
265139
+ }
265140
+ function ensureGridWidth(columnWidths, requiredColumnCount, defaultAddedColumnWidth) {
265141
+ while (columnWidths.length < requiredColumnCount)
265142
+ columnWidths.push(defaultAddedColumnWidth);
265143
+ }
265144
+ function resolveDefaultAddedColumnWidth(preferredColumnWidths, preferredTableWidth) {
265145
+ for (let index2 = preferredColumnWidths.length - 1;index2 >= 0; index2--) {
265146
+ const width = sanitizeNonNegativeWidth(preferredColumnWidths[index2]);
265147
+ if (width != null && width > 0)
265148
+ return width;
265149
+ }
265150
+ const positiveAuthoredWidths = preferredColumnWidths.map((width) => sanitizeNonNegativeWidth(width)).filter((width) => width != null && width > 0);
265151
+ if (positiveAuthoredWidths.length > 0)
265152
+ return sumWidths$2(positiveAuthoredWidths) / positiveAuthoredWidths.length;
265153
+ if (preferredTableWidth != null && preferredTableWidth > 0)
265154
+ return preferredTableWidth;
265155
+ return 1;
265156
+ }
265157
+ function sumSpan$1(columnWidths, startColumn, span) {
265158
+ let total = 0;
265159
+ for (let offset$1 = 0;offset$1 < span; offset$1++)
265160
+ total += columnWidths[startColumn + offset$1] ?? 0;
265161
+ return total;
265162
+ }
265163
+ function sumWidths$2(columnWidths) {
265164
+ return columnWidths.reduce((sum, width) => sum + Math.max(0, width), 0);
265165
+ }
265166
+ function sanitizeColumnCount(value) {
265167
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0)
265168
+ return 0;
265169
+ return Math.floor(value);
265170
+ }
265171
+ function sanitizeOptionalWidth$1(value) {
265172
+ const width = sanitizeNonNegativeWidth(value);
265173
+ return width == null ? undefined : width;
265174
+ }
265175
+ function sanitizeNonNegativeWidth(value) {
265176
+ if (typeof value !== "number" || !Number.isFinite(value))
265177
+ return;
265178
+ return Math.max(0, value);
265179
+ }
265180
+ function computeAutoFitColumnWidths(input2) {
265181
+ const { workingInput, fixedLayout, rowMetrics, minColumnWidth } = resolveAutoFitContext(input2);
265182
+ if (workingInput.layoutMode === "fixed")
265183
+ return finalizeResult("fixed", fixedLayout.columnWidths, minColumnWidth);
265184
+ const gridColumnCount = fixedLayout.gridColumnCount;
265185
+ if (gridColumnCount === 0)
265186
+ return buildFallbackResult(workingInput.layoutMode, minColumnWidth);
265187
+ const normalizedRows = buildNormalizedRows(workingInput, rowMetrics);
265188
+ const currentWidths = fixedLayout.columnWidths.slice(0, gridColumnCount);
265189
+ const minBounds = new Array(gridColumnCount).fill(0);
265190
+ const maxBounds = new Array(gridColumnCount).fill(0);
265191
+ const preferredOverrides = new Array(gridColumnCount).fill(undefined);
265192
+ const multiSpanCells = [];
265193
+ accumulateBounds({
265194
+ rows: normalizedRows,
265195
+ minBounds,
265196
+ maxBounds,
265197
+ preferredOverrides,
265198
+ multiSpanCells
265199
+ });
265200
+ applyMultiSpanMinimums(minBounds, multiSpanCells);
265201
+ applySingleSpanPreferredOverrides(maxBounds, minBounds, preferredOverrides);
265202
+ applyMultiSpanMaximums(maxBounds, minBounds, multiSpanCells, currentWidths);
265203
+ const triggerCells = collectTriggerCells(currentWidths, multiSpanCells, normalizedRows);
265204
+ const postTriggerGrowableColumns = triggerCells.length > 0 ? collectNonProtectedColumns(triggerCells, gridColumnCount) : undefined;
265205
+ let resolvedWidths = currentWidths.slice();
265206
+ const preferredTableWidth = sanitizeOptionalWidth(workingInput.preferredTableWidth);
265207
+ let targetTableWidth = preferredTableWidth ?? fixedLayout.totalWidth;
265208
+ const maxResolvedTableWidth = preferredTableWidth != null || hasCompleteAuthoredGrid(workingInput) ? Math.max(workingInput.maxTableWidth, targetTableWidth) : workingInput.maxTableWidth;
265209
+ const shouldPreservePreferredGrid = workingInput.preserveAutoGrid === true || workingInput.preserveExplicitAutoGrid === true;
265210
+ if (triggerCells.length > 0) {
265211
+ resolvedWidths = raiseToMinimums(resolvedWidths, minBounds);
265212
+ resolvedWidths = expandTriggersWithinCurrentTable(resolvedWidths, triggerCells, minBounds, maxBounds);
265213
+ resolvedWidths = expandTriggersByGrowingTable(resolvedWidths, triggerCells, maxBounds, maxResolvedTableWidth);
265214
+ targetTableWidth = Math.max(targetTableWidth, sumWidths$1(resolvedWidths));
265215
+ targetTableWidth = Math.min(targetTableWidth, maxResolvedTableWidth);
265216
+ } else {
265217
+ targetTableWidth = Math.min(targetTableWidth, maxResolvedTableWidth);
265218
+ if (!shouldPreservePreferredGrid) {
265219
+ resolvedWidths = redistributeTowardMaximumsWithinCurrentTable(resolvedWidths, minBounds, maxBounds);
265220
+ resolvedWidths = redistributeTowardContentWeightedShape(resolvedWidths, minBounds, maxBounds);
265221
+ }
265222
+ }
265223
+ resolvedWidths = shrinkToTargetWidth(resolvedWidths, targetTableWidth, minBounds);
265224
+ resolvedWidths = growToTargetWidth(resolvedWidths, targetTableWidth, maxBounds, postTriggerGrowableColumns);
265225
+ if (sumWidths$1(resolvedWidths) < targetTableWidth)
265226
+ resolvedWidths = distributeRemainingSlack(resolvedWidths, targetTableWidth, postTriggerGrowableColumns);
265227
+ if (triggerCells.length > 0)
265228
+ resolvedWidths = clampTriggeredSpansToTargets(resolvedWidths, triggerCells, minBounds, maxBounds, currentWidths);
265229
+ if (sumWidths$1(resolvedWidths) > maxResolvedTableWidth)
265230
+ resolvedWidths = shrinkToTargetWidth(resolvedWidths, maxResolvedTableWidth, minBounds);
265231
+ return finalizeResult(workingInput.layoutMode, resolvedWidths, minColumnWidth);
265232
+ }
265233
+ function hasCompleteAuthoredGrid(workingInput) {
265234
+ const authoredColumnCount = workingInput.preferredColumnWidths.length;
265235
+ if (authoredColumnCount === 0)
265236
+ return false;
265237
+ return workingInput.rows.some((row2) => row2.logicalColumnCount >= authoredColumnCount);
265238
+ }
265239
+ function resolveAutoFitContext(input2) {
265240
+ const minColumnWidth = sanitizeWidth(input2.minColumnWidth, DEFAULT_MIN_COLUMN_WIDTH);
265241
+ if (isExplicitInput(input2))
265242
+ return {
265243
+ workingInput: input2.workingInput,
265244
+ fixedLayout: input2.fixedLayout,
265245
+ rowMetrics: input2.contentMetrics.rowMetrics,
265246
+ minColumnWidth
265247
+ };
265248
+ const layoutMode = resolveLayoutMode$1(input2.tableLayout);
265249
+ const normalizedRows = normalizeLegacyRows(input2.rows ?? []);
265250
+ const gridColumnCount = determineGridColumnCount$1(input2.preferredColumnWidths ?? [], normalizedRows);
265251
+ const workingInput = {
265252
+ layoutMode,
265253
+ maxTableWidth: Math.max(minColumnWidth, sanitizeWidth(input2.maxTableWidth, minColumnWidth)),
265254
+ preferredTableWidth: sanitizeOptionalWidth(input2.preferredTableWidth),
265255
+ preferredColumnWidths: (input2.preferredColumnWidths ?? []).map((width) => Math.max(0, width)),
265256
+ gridColumnCount,
265257
+ rows: normalizedRows.map((row2) => ({
265258
+ skippedBefore: row2.skippedColumns.filter((column) => column.columnIndex < firstCellStart(row2)),
265259
+ skippedAfter: row2.skippedColumns.filter((column) => column.columnIndex >= lastCellEnd(row2)),
265260
+ skippedColumns: row2.skippedColumns,
265261
+ cells: row2.cells.map((cell2) => ({
265262
+ cellId: undefined,
265263
+ startColumn: cell2.startColumn,
265264
+ span: cell2.span,
265265
+ preferredWidth: cell2.preferredWidth
265266
+ })),
265267
+ logicalColumnCount: row2.logicalColumnCount
265268
+ }))
265269
+ };
265270
+ return {
265271
+ workingInput,
265272
+ fixedLayout: computeFixedTableColumnWidths(workingInput),
265273
+ rowMetrics: normalizedRows.map((row2, rowIndex) => ({
265274
+ rowIndex,
265275
+ cells: row2.cells.map((cell2) => ({
265276
+ cellIndex: cell2.cellIndex,
265277
+ span: cell2.span,
265278
+ preferredWidth: cell2.preferredWidth,
265279
+ minContentWidth: cell2.minContentWidth,
265280
+ maxContentWidth: cell2.maxContentWidth
265281
+ }))
265282
+ })),
265283
+ minColumnWidth
265284
+ };
265285
+ }
265286
+ function isExplicitInput(input2) {
265287
+ return "workingInput" in input2 && "fixedLayout" in input2 && "contentMetrics" in input2;
265288
+ }
265289
+ function resolveLayoutMode$1(tableLayout) {
265290
+ return tableLayout === "fixed" ? "fixed" : "autofit";
265291
+ }
265292
+ function normalizeLegacyRows(rows) {
265293
+ return rows.map((row2, rowIndex) => {
265294
+ let columnIndex = 0;
265295
+ const skippedColumns = [];
265296
+ const cells = [];
265297
+ for (const skipped of row2.skippedBefore ?? []) {
265298
+ skippedColumns.push(normalizeSkippedColumn(skipped, columnIndex));
265299
+ columnIndex += 1;
265300
+ }
265301
+ for (let cellIndex = 0;cellIndex < (row2.cells ?? []).length; cellIndex++) {
265302
+ const cell2 = row2.cells?.[cellIndex];
265303
+ if (!cell2)
265304
+ continue;
265305
+ const span = Math.max(1, Math.floor(cell2.span ?? 1));
265306
+ cells.push({
265307
+ rowIndex,
265308
+ cellIndex,
265309
+ startColumn: columnIndex,
265310
+ span,
265311
+ preferredWidth: sanitizeOptionalWidth(cell2.preferredWidth),
265312
+ minContentWidth: Math.max(0, cell2.minContentWidth ?? 0),
265313
+ maxContentWidth: Math.max(0, cell2.maxContentWidth ?? cell2.minContentWidth ?? 0)
265314
+ });
265315
+ columnIndex += span;
265316
+ }
265317
+ for (const skipped of row2.skippedAfter ?? []) {
265318
+ skippedColumns.push(normalizeSkippedColumn(skipped, columnIndex));
265319
+ columnIndex += 1;
265320
+ }
265321
+ return {
265322
+ cells,
265323
+ skippedColumns,
265324
+ logicalColumnCount: columnIndex
265325
+ };
265326
+ });
265327
+ }
265328
+ function normalizeSkippedColumn(skipped, columnIndex) {
265329
+ return {
265330
+ columnIndex,
265331
+ preferredWidth: sanitizeOptionalWidth(skipped.preferredWidth),
265332
+ minContentWidth: Math.max(0, skipped.minContentWidth ?? 0),
265333
+ maxContentWidth: Math.max(0, skipped.maxContentWidth ?? skipped.minContentWidth ?? 0)
265334
+ };
265335
+ }
265336
+ function buildNormalizedRows(workingInput, rowMetrics) {
265337
+ return workingInput.rows.map((workingRow, rowIndex) => {
265338
+ const metricsRow = rowMetrics[rowIndex];
265339
+ return {
265340
+ cells: (workingRow.cells ?? []).map((cell2, cellIndex) => {
265341
+ const metrics = metricsRow?.cells[cellIndex];
265342
+ const placedCell = cell2;
265343
+ return {
265344
+ rowIndex,
265345
+ cellIndex: metrics?.cellIndex ?? cellIndex,
265346
+ startColumn: placedCell.startColumn,
265347
+ span: Math.max(1, placedCell.span ?? metrics?.span ?? 1),
265348
+ preferredWidth: sanitizeOptionalWidth(metrics?.preferredWidth ?? placedCell.preferredWidth),
265349
+ minContentWidth: Math.max(0, metrics?.minContentWidth ?? 0),
265350
+ maxContentWidth: Math.max(0, metrics?.maxContentWidth ?? metrics?.minContentWidth ?? 0)
265351
+ };
265352
+ }),
265353
+ skippedColumns: (workingRow.skippedColumns ?? []).map((skipped) => ({
265354
+ columnIndex: skipped.columnIndex,
265355
+ preferredWidth: sanitizeOptionalWidth(skipped.preferredWidth),
265356
+ minContentWidth: Math.max(0, skipped.minContentWidth ?? 0),
265357
+ maxContentWidth: Math.max(0, skipped.maxContentWidth ?? skipped.minContentWidth ?? 0)
265358
+ })),
265359
+ logicalColumnCount: workingRow.logicalColumnCount
265360
+ };
265361
+ });
265362
+ }
265363
+ function accumulateBounds(args$1) {
265364
+ const { rows, minBounds, maxBounds, preferredOverrides, multiSpanCells } = args$1;
265365
+ for (const row2 of rows) {
265366
+ for (const skipped of row2.skippedColumns) {
265367
+ minBounds[skipped.columnIndex] = Math.max(minBounds[skipped.columnIndex], skipped.minContentWidth);
265368
+ maxBounds[skipped.columnIndex] = Math.max(maxBounds[skipped.columnIndex], skipped.maxContentWidth);
265369
+ if (preferredOverrides[skipped.columnIndex] == null && skipped.preferredWidth != null)
265370
+ preferredOverrides[skipped.columnIndex] = skipped.preferredWidth;
265371
+ }
265372
+ for (const cell2 of row2.cells)
265373
+ if (cell2.span === 1) {
265374
+ minBounds[cell2.startColumn] = Math.max(minBounds[cell2.startColumn], cell2.minContentWidth);
265375
+ maxBounds[cell2.startColumn] = Math.max(maxBounds[cell2.startColumn], cell2.maxContentWidth);
265376
+ if (preferredOverrides[cell2.startColumn] == null && cell2.preferredWidth != null)
265377
+ preferredOverrides[cell2.startColumn] = cell2.preferredWidth;
265378
+ } else
265379
+ multiSpanCells.push(cell2);
265380
+ }
265381
+ }
265382
+ function applyMultiSpanMinimums(minBounds, cells) {
265383
+ for (const cell2 of cells)
265384
+ growSpanTotal(minBounds, cell2.startColumn, cell2.span, cell2.minContentWidth);
265385
+ }
265386
+ function applySingleSpanPreferredOverrides(maxBounds, minBounds, preferredOverrides) {
265387
+ for (let index2 = 0;index2 < maxBounds.length; index2++) {
265388
+ const currentMax = Math.max(maxBounds[index2], minBounds[index2]);
265389
+ maxBounds[index2] = preferredOverrides[index2] ?? currentMax;
265390
+ maxBounds[index2] = Math.max(maxBounds[index2], minBounds[index2]);
265391
+ }
265392
+ }
265393
+ function applyMultiSpanMaximums(maxBounds, minBounds, cells, fixedWidths) {
265394
+ for (const cell2 of cells) {
265395
+ const targetTotal = cell2.preferredWidth != null ? Math.max(cell2.preferredWidth, sumSpan(minBounds, cell2.startColumn, cell2.span)) : Math.max(cell2.maxContentWidth, sumSpan(minBounds, cell2.startColumn, cell2.span));
265396
+ setSpanTotal(maxBounds, minBounds, fixedWidths, cell2.startColumn, cell2.span, targetTotal);
265397
+ }
265398
+ }
265399
+ function collectTriggerCells(currentWidths, multiSpanCells, rows) {
265400
+ const triggers = [];
265401
+ for (const row2 of rows)
265402
+ for (const cell2 of row2.cells)
265403
+ if (sumSpan(currentWidths, cell2.startColumn, cell2.span) < cell2.minContentWidth)
265404
+ triggers.push(cell2);
265405
+ for (const cell2 of multiSpanCells)
265406
+ if (sumSpan(currentWidths, cell2.startColumn, cell2.span) < cell2.minContentWidth)
265407
+ triggers.push(cell2);
265408
+ return coalesceEquivalentTriggerCells(dedupeCells(triggers));
265409
+ }
265410
+ function setSpanTotal(widths, minBounds, fixedWidths, startColumn, span, targetTotal) {
265411
+ const currentTotal = sumSpan(widths, startColumn, span);
265412
+ const minTotal = sumSpan(minBounds, startColumn, span);
265413
+ const boundedTarget = Math.max(targetTotal, minTotal);
265414
+ if (currentTotal < boundedTarget) {
265415
+ growSpanTotal(widths, startColumn, span, boundedTarget, fixedWidths);
265416
+ return;
265417
+ }
265418
+ if (currentTotal === boundedTarget)
265419
+ return;
265420
+ const reducibleRanges = collectSpanRanges(widths, minBounds, startColumn, span);
265421
+ const totalReducible = reducibleRanges.reduce((sum, range) => sum + range.amount, 0);
265422
+ if (totalReducible <= 0)
265423
+ return;
265424
+ const reduction = currentTotal - boundedTarget;
265425
+ let applied = 0;
265426
+ for (let rangeIndex = 0;rangeIndex < reducibleRanges.length; rangeIndex++) {
265427
+ const range = reducibleRanges[rangeIndex];
265428
+ const portion = rangeIndex === reducibleRanges.length - 1 ? reduction - applied : reduction * (range.amount / totalReducible);
265429
+ widths[range.index] = Math.max(minBounds[range.index], widths[range.index] - portion);
265430
+ applied += portion;
265431
+ }
265432
+ }
265433
+ function growSpanTotal(widths, startColumn, span, targetTotal, fixedWidths) {
265434
+ const deficit = targetTotal - sumSpan(widths, startColumn, span);
265435
+ if (deficit <= 0)
265436
+ return;
265437
+ const weights = Array.from({ length: span }, (_$1, offset$1) => {
265438
+ const index2 = startColumn + offset$1;
265439
+ return Math.max(fixedWidths?.[index2] ?? 0, widths[index2] ?? 0, 1);
265440
+ });
265441
+ const totalWeight = weights.reduce((sum, weight) => sum + weight, 0);
265442
+ let applied = 0;
265443
+ for (let offset$1 = 0;offset$1 < span; offset$1++) {
265444
+ const index2 = startColumn + offset$1;
265445
+ const increment2 = offset$1 === span - 1 ? deficit - applied : deficit * (weights[offset$1] / totalWeight);
265446
+ widths[index2] = Math.max(0, (widths[index2] ?? 0) + increment2);
265447
+ applied += increment2;
265448
+ }
265449
+ }
265450
+ function shrinkToTargetWidth(widths, targetWidth, minBounds) {
265451
+ const currentTotal = sumWidths$1(widths);
265452
+ if (currentTotal <= targetWidth)
265453
+ return widths;
265454
+ const minTotal = sumWidths$1(minBounds);
265455
+ if (targetWidth <= 0)
265456
+ return widths;
265457
+ if (targetWidth < minTotal)
265458
+ return scaleToTargetWidth(widths, targetWidth);
265459
+ const capacities = widths.map((width, index2) => Math.max(0, width - minBounds[index2]));
265460
+ const totalCapacity = capacities.reduce((sum, capacity) => sum + capacity, 0);
265461
+ if (totalCapacity <= 0)
265462
+ return widths;
265463
+ const excess = currentTotal - targetWidth;
265464
+ return widths.map((width, index2) => {
265465
+ const shrink = excess * (capacities[index2] / totalCapacity);
265466
+ return Math.max(minBounds[index2], width - shrink);
265467
+ });
265468
+ }
265469
+ function growToTargetWidth(widths, targetWidth, maxBounds, growableColumns) {
265470
+ const currentTotal = sumWidths$1(widths);
265471
+ if (currentTotal >= targetWidth)
265472
+ return widths;
265473
+ const ranges = widths.map((width, index2) => growableColumns == null || growableColumns.has(index2) ? Math.max(0, maxBounds[index2] - width) : 0);
265474
+ const totalRange = ranges.reduce((sum, range) => sum + range, 0);
265475
+ if (totalRange <= 0)
265476
+ return widths;
265477
+ const slack = targetWidth - currentTotal;
265478
+ return widths.map((width, index2) => width + slack * (ranges[index2] / totalRange));
265479
+ }
265480
+ function distributeRemainingSlack(widths, targetWidth, growableColumns) {
265481
+ const currentTotal = sumWidths$1(widths);
265482
+ if (currentTotal >= targetWidth)
265483
+ return widths;
265484
+ const basis = widths.reduce((sum, width, index2) => {
265485
+ if (growableColumns != null && !growableColumns.has(index2))
265486
+ return sum;
265487
+ return sum + Math.max(width, 1);
265488
+ }, 0);
265489
+ const slack = targetWidth - currentTotal;
265490
+ if (basis <= 0) {
265491
+ if (growableColumns == null)
265492
+ return widths;
265493
+ const growableIndexes = widths.map((_$1, index2) => index2).filter((index2) => growableColumns.has(index2));
265494
+ if (growableIndexes.length === 0)
265495
+ return widths;
265496
+ const share = slack / growableIndexes.length;
265497
+ return widths.map((width, index2) => growableColumns.has(index2) ? width + share : width);
265498
+ }
265499
+ return widths.map((width, index2) => {
265500
+ if (growableColumns != null && !growableColumns.has(index2))
265501
+ return width;
265502
+ return width + slack * (Math.max(width, 1) / basis);
265503
+ });
265504
+ }
265505
+ function raiseToMinimums(widths, minBounds) {
265506
+ const next2 = widths.slice();
265507
+ const deficits = next2.map((width, index2) => Math.max(0, minBounds[index2] - width));
265508
+ const totalDeficit = deficits.reduce((sum, deficit) => sum + deficit, 0);
265509
+ if (totalDeficit <= 0)
265510
+ return next2;
265511
+ const capacities = next2.map((width, index2) => Math.max(0, width - minBounds[index2]));
265512
+ const totalCapacity = capacities.reduce((sum, capacity) => sum + capacity, 0);
265513
+ const borrowAmount = Math.min(totalDeficit, totalCapacity);
265514
+ if (borrowAmount > 0 && totalCapacity > 0) {
265515
+ let borrowed = 0;
265516
+ for (let index2 = 0;index2 < next2.length; index2++) {
265517
+ const reduction = index2 === next2.length - 1 ? borrowAmount - borrowed : borrowAmount * (capacities[index2] / totalCapacity);
265518
+ next2[index2] = Math.max(minBounds[index2], next2[index2] - reduction);
265519
+ borrowed += reduction;
265520
+ }
265521
+ }
265522
+ for (let index2 = 0;index2 < next2.length; index2++)
265523
+ next2[index2] = Math.max(next2[index2], Math.min(minBounds[index2], widths[index2] + deficits[index2]));
265524
+ return next2;
265525
+ }
265526
+ function redistributeTowardMaximumsWithinCurrentTable(widths, minBounds, maxBounds) {
265527
+ const next2 = widths.slice();
265528
+ for (let iteration = 0;iteration < 8; iteration++) {
265529
+ const receiverHeadrooms = next2.map((width, index2) => Math.max(0, maxBounds[index2] - width));
265530
+ const totalReceiverHeadroom = receiverHeadrooms.reduce((sum, headroom) => sum + headroom, 0);
265531
+ if (totalReceiverHeadroom <= 0.001)
265532
+ break;
265533
+ const donorCapacities = next2.map((width, index2) => receiverHeadrooms[index2] > 0.001 ? 0 : Math.max(0, width - minBounds[index2]));
265534
+ let totalDonorCapacity = donorCapacities.reduce((sum, capacity) => sum + capacity, 0);
265535
+ if (totalDonorCapacity <= 0.001) {
265536
+ for (let index2 = 0;index2 < next2.length; index2++)
265537
+ donorCapacities[index2] = Math.max(0, next2[index2] - minBounds[index2]);
265538
+ totalDonorCapacity = donorCapacities.reduce((sum, capacity) => sum + capacity, 0);
265539
+ }
265540
+ if (totalDonorCapacity <= 0.001)
265541
+ break;
265542
+ const redistribution = Math.min(totalReceiverHeadroom, totalDonorCapacity);
265543
+ shrinkColumnsByCapacity(next2, donorCapacities, minBounds, redistribution);
265544
+ growColumnsByHeadroom(next2, receiverHeadrooms, redistribution);
265545
+ }
265546
+ return next2;
265547
+ }
265548
+ function redistributeTowardContentWeightedShape(widths, minBounds, maxBounds) {
265549
+ const distributableWidth = sumWidths$1(widths) - sumWidths$1(minBounds);
265550
+ if (distributableWidth <= 0.001 || widths.length === 0)
265551
+ return widths;
265552
+ const demandWeights = widths.map((width, index2) => {
265553
+ const demand = Math.max(maxBounds[index2], width, minBounds[index2], 1);
265554
+ return demand * demand;
265555
+ });
265556
+ const totalDemandWeight = demandWeights.reduce((sum, weight) => sum + weight, 0);
265557
+ if (totalDemandWeight <= 0.001)
265558
+ return widths;
265559
+ return widths.map((_$1, index2) => minBounds[index2] + distributableWidth * (demandWeights[index2] / totalDemandWeight));
265560
+ }
265561
+ function expandTriggersWithinCurrentTable(widths, triggerCells, minBounds, maxBounds) {
265562
+ const next2 = widths.slice();
265563
+ const protectedColumns = collectProtectedColumns(triggerCells);
265564
+ for (let iteration = 0;iteration < 8; iteration++) {
265565
+ const totalHeadroom = collectTriggerHeadrooms(next2, triggerCells, maxBounds).reduce((sum, headroom) => sum + headroom, 0);
265566
+ if (totalHeadroom <= 0.001)
265567
+ break;
265568
+ const donorCapacities = next2.map((width, index2) => protectedColumns.has(index2) ? 0 : Math.max(0, width - minBounds[index2]));
265569
+ const totalDonorCapacity = donorCapacities.reduce((sum, capacity) => sum + capacity, 0);
265570
+ if (totalDonorCapacity <= 0.001)
265571
+ break;
265572
+ const borrowedWidth = Math.min(totalHeadroom, totalDonorCapacity);
265573
+ shrinkColumnsByCapacity(next2, donorCapacities, minBounds, borrowedWidth);
265574
+ applyTriggerGrowth(next2, triggerCells, maxBounds, borrowedWidth);
265575
+ }
265576
+ return next2;
265577
+ }
265578
+ function expandTriggersByGrowingTable(widths, triggerCells, maxBounds, maxTableWidth) {
265579
+ const next2 = widths.slice();
265580
+ for (let iteration = 0;iteration < 8; iteration++) {
265581
+ const totalHeadroom = collectTriggerHeadrooms(next2, triggerCells, maxBounds).reduce((sum, headroom) => sum + headroom, 0);
265582
+ if (totalHeadroom <= 0.001)
265583
+ break;
265584
+ const remainingTableGrowth = Math.max(0, maxTableWidth - sumWidths$1(next2));
265585
+ if (remainingTableGrowth <= 0.001)
265586
+ break;
265587
+ applyTriggerGrowth(next2, triggerCells, maxBounds, Math.min(totalHeadroom, remainingTableGrowth));
265588
+ }
265589
+ return next2;
265590
+ }
265591
+ function collectTriggerHeadrooms(widths, triggerCells, maxBounds) {
265592
+ return triggerCells.map((cell2) => {
265593
+ const currentTotal = sumSpan(widths, cell2.startColumn, cell2.span);
265594
+ const targetTotal = resolveTriggerTargetTotal(cell2, maxBounds);
265595
+ return Math.max(0, targetTotal - currentTotal);
265596
+ });
265597
+ }
265598
+ function resolveTriggerTargetTotal(cell2, maxBounds) {
265599
+ if (cell2.span === 1)
265600
+ return maxBounds[cell2.startColumn] ?? cell2.maxContentWidth;
265601
+ return cell2.preferredWidth != null ? Math.max(cell2.preferredWidth, cell2.minContentWidth) : Math.max(cell2.maxContentWidth, cell2.minContentWidth);
265602
+ }
265603
+ function collectProtectedColumns(cells) {
265604
+ const protectedColumns = /* @__PURE__ */ new Set;
265605
+ for (const cell2 of cells)
265606
+ for (let offset$1 = 0;offset$1 < cell2.span; offset$1++)
265607
+ protectedColumns.add(cell2.startColumn + offset$1);
265608
+ return protectedColumns;
265609
+ }
265610
+ function collectNonProtectedColumns(cells, columnCount) {
265611
+ const protectedColumns = collectProtectedColumns(cells);
265612
+ const growableColumns = /* @__PURE__ */ new Set;
265613
+ for (let index2 = 0;index2 < columnCount; index2++)
265614
+ if (!protectedColumns.has(index2))
265615
+ growableColumns.add(index2);
265616
+ return growableColumns;
265617
+ }
265618
+ function shrinkColumnsByCapacity(widths, capacities, minBounds, shrinkAmount) {
265619
+ const totalCapacity = capacities.reduce((sum, capacity) => sum + capacity, 0);
265620
+ if (totalCapacity <= 0 || shrinkAmount <= 0)
265621
+ return;
265622
+ let applied = 0;
265623
+ for (let index2 = 0;index2 < widths.length; index2++) {
265624
+ const reduction = index2 === widths.length - 1 ? shrinkAmount - applied : shrinkAmount * (capacities[index2] / totalCapacity);
265625
+ widths[index2] = Math.max(minBounds[index2], widths[index2] - reduction);
265626
+ applied += reduction;
265627
+ }
265628
+ }
265629
+ function growColumnsByHeadroom(widths, headrooms, growthAmount) {
265630
+ const totalHeadroom = headrooms.reduce((sum, headroom) => sum + headroom, 0);
265631
+ if (totalHeadroom <= 0 || growthAmount <= 0)
265632
+ return;
265633
+ let applied = 0;
265634
+ const activeIndexes = headrooms.map((headroom, index2) => ({
265635
+ headroom,
265636
+ index: index2
265637
+ })).filter((entry) => entry.headroom > 0.001);
265638
+ for (let activeIndex = 0;activeIndex < activeIndexes.length; activeIndex++) {
265639
+ const { index: index2, headroom } = activeIndexes[activeIndex];
265640
+ const growth = activeIndex === activeIndexes.length - 1 ? growthAmount - applied : growthAmount * (headroom / totalHeadroom);
265641
+ widths[index2] += Math.min(headroom, growth);
265642
+ applied += Math.min(headroom, growth);
265643
+ }
265644
+ }
265645
+ function applyTriggerGrowth(widths, triggerCells, maxBounds, growthAmount) {
265646
+ let remainingGrowth = growthAmount;
265647
+ for (let iteration = 0;iteration < 16 && remainingGrowth > 0.001; iteration++) {
265648
+ const headrooms = collectTriggerHeadrooms(widths, triggerCells, maxBounds);
265649
+ const totalHeadroom = headrooms.reduce((sum, headroom) => sum + headroom, 0);
265650
+ if (totalHeadroom <= 0.001)
265651
+ break;
265652
+ const stepGrowth = Math.min(remainingGrowth, totalHeadroom);
265653
+ const activeIndexes = headrooms.map((headroom, index2) => ({
265654
+ headroom,
265655
+ index: index2
265656
+ })).filter((entry) => entry.headroom > 0.001);
265657
+ let appliedThisRound = 0;
265658
+ for (let activeIndex = 0;activeIndex < activeIndexes.length; activeIndex++) {
265659
+ const { index: index2, headroom } = activeIndexes[activeIndex];
265660
+ const cell2 = triggerCells[index2];
265661
+ const proportionalGrowth = activeIndex === activeIndexes.length - 1 ? stepGrowth - appliedThisRound : stepGrowth * (headroom / totalHeadroom);
265662
+ const boundedGrowth = Math.min(headroom, proportionalGrowth);
265663
+ if (boundedGrowth <= 0)
265664
+ continue;
265665
+ growSpanTotal(widths, cell2.startColumn, cell2.span, sumSpan(widths, cell2.startColumn, cell2.span) + boundedGrowth);
265666
+ appliedThisRound += boundedGrowth;
265667
+ }
265668
+ if (appliedThisRound <= 0.001)
265669
+ break;
265670
+ remainingGrowth -= appliedThisRound;
265671
+ }
265672
+ }
265673
+ function clampTriggeredSpansToTargets(widths, triggerCells, minBounds, maxBounds, fixedWidths) {
265674
+ const next2 = widths.slice();
265675
+ for (let iteration = 0;iteration < 8; iteration++) {
265676
+ let changed = false;
265677
+ for (const cell2 of triggerCells) {
265678
+ const currentTotal = sumSpan(next2, cell2.startColumn, cell2.span);
265679
+ const targetTotal = resolveTriggerTargetTotal(cell2, maxBounds);
265680
+ if (currentTotal > targetTotal + 0.001) {
265681
+ setSpanTotal(next2, minBounds, fixedWidths, cell2.startColumn, cell2.span, targetTotal);
265682
+ changed = true;
265683
+ }
265684
+ }
265685
+ if (!changed)
265686
+ break;
265687
+ }
265688
+ return next2;
265689
+ }
265690
+ function collectSpanRanges(widths, minBounds, startColumn, span) {
265691
+ const ranges = [];
265692
+ for (let offset$1 = 0;offset$1 < span; offset$1++) {
265693
+ const index2 = startColumn + offset$1;
265694
+ const amount = Math.max(0, widths[index2] - minBounds[index2]);
265695
+ if (amount > 0)
265696
+ ranges.push({
265697
+ index: index2,
265698
+ amount
265699
+ });
265700
+ }
265701
+ return ranges;
265702
+ }
265703
+ function dedupeCells(cells) {
265704
+ const seen = /* @__PURE__ */ new Set;
265705
+ return cells.filter((cell2) => {
265706
+ const key2 = `${cell2.rowIndex}:${cell2.startColumn}:${cell2.span}:${cell2.cellIndex}`;
265707
+ if (seen.has(key2))
265708
+ return false;
265709
+ seen.add(key2);
265710
+ return true;
265711
+ });
265712
+ }
265713
+ function coalesceEquivalentTriggerCells(cells) {
265714
+ const strongestBySpan = /* @__PURE__ */ new Map;
265715
+ for (const cell2 of cells) {
265716
+ const key2 = `${cell2.startColumn}:${cell2.span}`;
265717
+ const current = strongestBySpan.get(key2);
265718
+ if (!current || resolveTriggerStrength(cell2) > resolveTriggerStrength(current))
265719
+ strongestBySpan.set(key2, cell2);
265720
+ }
265721
+ return [...strongestBySpan.values()];
265722
+ }
265723
+ function resolveTriggerStrength(cell2) {
265724
+ return cell2.preferredWidth != null ? Math.max(cell2.preferredWidth, cell2.minContentWidth) : Math.max(cell2.maxContentWidth, cell2.minContentWidth);
265725
+ }
265726
+ function determineGridColumnCount$1(preferredColumnWidths, rows) {
265727
+ return Math.max(preferredColumnWidths.length, ...rows.map((row2) => row2.logicalColumnCount), 0);
265728
+ }
265729
+ function firstCellStart(row2) {
265730
+ return row2.cells[0]?.startColumn ?? row2.logicalColumnCount;
265731
+ }
265732
+ function lastCellEnd(row2) {
265733
+ const lastCell = row2.cells[row2.cells.length - 1];
265734
+ return lastCell ? lastCell.startColumn + lastCell.span : 0;
265735
+ }
265736
+ function sumSpan(widths, startColumn, span) {
265737
+ let total = 0;
265738
+ for (let offset$1 = 0;offset$1 < span; offset$1++)
265739
+ total += widths[startColumn + offset$1] ?? 0;
265740
+ return total;
265741
+ }
265742
+ function sumWidths$1(widths) {
265743
+ return widths.reduce((sum, width) => sum + Math.max(0, width), 0);
265744
+ }
265745
+ function scaleToTargetWidth(widths, targetWidth) {
265746
+ const currentTotal = sumWidths$1(widths);
265747
+ if (currentTotal <= 0 || targetWidth <= 0)
265748
+ return widths;
265749
+ const scale = targetWidth / currentTotal;
265750
+ return widths.map((width) => Math.max(0, width * scale));
265751
+ }
265752
+ function sanitizeWidth(value, fallback) {
265753
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : fallback;
265754
+ }
265755
+ function sanitizeOptionalWidth(value) {
265756
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined;
265757
+ }
265758
+ function buildFallbackResult(layoutMode, minColumnWidth) {
265759
+ return {
265760
+ layoutMode,
265761
+ columnWidths: [minColumnWidth],
265762
+ totalWidth: minColumnWidth,
265763
+ gridColumnCount: 1
265764
+ };
265765
+ }
265766
+ function finalizeResult(layoutMode, widths, minColumnWidth) {
265767
+ if (widths.length === 0)
265768
+ return buildFallbackResult(layoutMode, minColumnWidth);
265769
+ return {
265770
+ layoutMode,
265771
+ columnWidths: widths,
265772
+ totalWidth: sumWidths$1(widths),
265773
+ gridColumnCount: widths.length
265774
+ };
265775
+ }
265776
+ function buildAutoFitWorkingGridInput(block, constraints) {
265777
+ const maxTableWidth = sanitizePositiveNumber(constraints.maxWidth);
265778
+ const layoutMode = resolveLayoutMode(block.attrs?.tableLayout);
265779
+ const preferredTableWidth = resolvePreferredTableWidth(block.attrs?.tableWidth, maxTableWidth);
265780
+ const rawPreferredColumnWidths = normalizePreferredColumnWidths(block.columnWidths);
265781
+ const logicalColumnLimit = resolveTrailingPlaceholderColumnLimit(rawPreferredColumnWidths);
265782
+ let activeRowSpans = [];
265783
+ const rows = block.rows.map((row2) => {
265784
+ const normalized = normalizeRow(row2, preferredTableWidth ?? maxTableWidth, activeRowSpans, logicalColumnLimit);
265785
+ activeRowSpans = normalized.nextActiveRowSpans;
265786
+ return normalized.row;
265787
+ });
265788
+ const preferredColumnWidths = trimTrailingUnoccupiedPlaceholderColumns(rawPreferredColumnWidths, determineGridColumnCount(0, rows));
265789
+ const gridColumnCount = determineGridColumnCount(preferredColumnWidths.length, rows);
265790
+ const preserveAuthoredGrid = shouldPreserveAuthoredGrid({
265791
+ layoutMode,
265792
+ preferredColumnWidths,
265793
+ preferredTableWidth,
265794
+ gridColumnCount
265795
+ });
265796
+ const preserveAutoGrid = shouldPreserveAutoGrid({
265797
+ layoutMode,
265798
+ preferredColumnWidths,
265799
+ preferredTableWidth,
265800
+ gridColumnCount
265801
+ });
265802
+ const preserveExplicitAutoGrid = shouldPreserveExplicitAutoGrid({
265803
+ layoutMode,
265804
+ preferredColumnWidths,
265805
+ preferredTableWidth,
265806
+ gridColumnCount,
265807
+ rows
265808
+ });
265809
+ return {
265810
+ layoutMode,
265811
+ maxTableWidth,
265812
+ ...preserveAuthoredGrid ? { preserveAuthoredGrid } : {},
265813
+ ...preserveAutoGrid ? { preserveAutoGrid } : {},
265814
+ ...preserveExplicitAutoGrid ? { preserveExplicitAutoGrid } : {},
265815
+ preferredTableWidth,
265816
+ preferredColumnWidths,
265817
+ gridColumnCount,
265818
+ rows
265819
+ };
265820
+ }
265821
+ function resolveLayoutMode(tableLayout) {
265822
+ return tableLayout === "fixed" ? "fixed" : "autofit";
265823
+ }
265824
+ function shouldPreserveAuthoredGrid(args$1) {
265825
+ const { layoutMode, preferredColumnWidths, preferredTableWidth, gridColumnCount } = args$1;
265826
+ if (layoutMode !== "fixed")
265827
+ return false;
265828
+ if (preferredTableWidth == null || preferredTableWidth <= 0)
265829
+ return false;
265830
+ if (preferredColumnWidths.length === 0 || preferredColumnWidths.length !== gridColumnCount)
265831
+ return false;
265832
+ const totalPreferredColumnWidth = sumWidths(preferredColumnWidths);
265833
+ return approximatelyEqual(totalPreferredColumnWidth, preferredTableWidth) || isSlightlyUnderPreferredTableWidth(totalPreferredColumnWidth, preferredTableWidth);
265834
+ }
265835
+ function shouldPreserveAutoGrid(args$1) {
265836
+ const { layoutMode, preferredColumnWidths, preferredTableWidth, gridColumnCount } = args$1;
265837
+ if (layoutMode !== "autofit")
265838
+ return false;
265839
+ if (preferredTableWidth != null)
265840
+ return false;
265841
+ if (preferredColumnWidths.length === 0 || preferredColumnWidths.length !== gridColumnCount)
265842
+ return false;
265843
+ if (!hasNonUniformGrid(preferredColumnWidths))
265844
+ return false;
265845
+ return true;
265846
+ }
265847
+ function shouldPreserveExplicitAutoGrid(args$1) {
265848
+ const { layoutMode, preferredColumnWidths, preferredTableWidth, gridColumnCount, rows } = args$1;
265849
+ if (layoutMode !== "autofit")
265850
+ return false;
265851
+ if (preferredTableWidth == null || preferredTableWidth <= 0)
265852
+ return false;
265853
+ if (preferredColumnWidths.length === 0 || preferredColumnWidths.length !== gridColumnCount)
265854
+ return false;
265855
+ if (!hasNonUniformGrid(preferredColumnWidths) && !hasConcreteCellWidthRequest(rows))
265856
+ return false;
265857
+ return approximatelyEqual(sumWidths(preferredColumnWidths), preferredTableWidth);
265858
+ }
265859
+ function hasNonUniformGrid(widths) {
265860
+ if (widths.length <= 1)
265861
+ return true;
265862
+ const firstWidth = widths[0];
265863
+ return widths.some((width) => !approximatelyEqual(width, firstWidth));
265864
+ }
265865
+ function hasConcreteCellWidthRequest(rows) {
265866
+ return rows.some((row2) => row2.cells.some((cell2) => cell2.preferredWidth != null));
265867
+ }
265868
+ function trimTrailingUnoccupiedPlaceholderColumns(widths, occupiedGridColumnCount) {
265869
+ const occupiedCount = Math.max(0, Math.floor(occupiedGridColumnCount));
265870
+ if (occupiedCount <= 0 || widths.length <= occupiedCount)
265871
+ return widths;
265872
+ if (!widths.slice(occupiedCount).every((width) => width <= PLACEHOLDER_COLUMN_MAX_WIDTH))
265873
+ return widths;
265874
+ return widths.slice(0, occupiedCount);
265875
+ }
265876
+ function resolveTrailingPlaceholderColumnLimit(widths) {
265877
+ let trailingPlaceholderCount = 0;
265878
+ for (let index2 = widths.length - 1;index2 >= 0; index2--) {
265879
+ if (widths[index2] > PLACEHOLDER_COLUMN_MAX_WIDTH)
265880
+ break;
265881
+ trailingPlaceholderCount += 1;
265882
+ }
265883
+ if (trailingPlaceholderCount === 0 || trailingPlaceholderCount === widths.length)
265884
+ return;
265885
+ return widths.length - trailingPlaceholderCount;
265886
+ }
265887
+ function normalizePreferredColumnWidths(columnWidths) {
265888
+ if (!Array.isArray(columnWidths))
265889
+ return [];
265890
+ return columnWidths.map((width) => sanitizeNonNegativeNumber(width)).filter((width) => width !== undefined).map((width) => width);
265891
+ }
265892
+ function normalizeRow(row2, percentageBasis, activeRowSpans, logicalColumnLimit) {
265893
+ const rowProps = row2.attrs?.tableRowProperties ?? {};
265894
+ const skippedBeforeCount = sanitizeCount(rowProps.gridBefore);
265895
+ const skippedAfterCount = normalizeSkippedAfterCount(rowProps.gridAfter, rowProps.wAfter, percentageBasis);
265896
+ const cells = Array.isArray(row2.cells) ? row2.cells : [];
265897
+ let columnIndex = advancePastOccupiedColumns(activeRowSpans, 0);
265898
+ const skippedBeforePlacement = buildSkippedColumns(skippedBeforeCount, rowProps.wBefore, percentageBasis, columnIndex, activeRowSpans);
265899
+ columnIndex = skippedBeforePlacement.nextColumnIndex;
265900
+ const normalizedCells = cells.map((cell2) => {
265901
+ columnIndex = advancePastOccupiedColumns(activeRowSpans, columnIndex);
265902
+ const normalizedCell = normalizeCell(cell2, percentageBasis, columnIndex, logicalColumnLimit);
265903
+ columnIndex += normalizedCell.span ?? 1;
265904
+ return normalizedCell;
265905
+ });
265906
+ const skippedAfterPlacement = buildSkippedColumns(skippedAfterCount, rowProps.wAfter, percentageBasis, columnIndex, activeRowSpans);
265907
+ columnIndex = skippedAfterPlacement.nextColumnIndex;
265908
+ const logicalColumnCount = Math.max(columnIndex, resolveOccupiedLogicalColumnCount(activeRowSpans));
265909
+ const nextActiveRowSpans = advanceRowSpans(activeRowSpans);
265910
+ normalizedCells.forEach((cell2, index2) => {
265911
+ const rowSpan = sanitizeCount(cells[index2]?.rowSpan) || 1;
265912
+ if (rowSpan > 1)
265913
+ markRowSpanOccupancy(nextActiveRowSpans, cell2.startColumn, cell2.span ?? 1, rowSpan - 1);
265914
+ });
265915
+ return {
265916
+ row: {
265917
+ skippedBefore: skippedBeforePlacement.columns,
265918
+ cells: normalizedCells,
265919
+ skippedAfter: skippedAfterPlacement.columns,
265920
+ skippedColumns: [...skippedBeforePlacement.columns, ...skippedAfterPlacement.columns],
265921
+ logicalColumnCount
265922
+ },
265923
+ nextActiveRowSpans
265924
+ };
265925
+ }
265926
+ function buildSkippedColumns(count2, preferredWidthMeasurement, percentageBasis, startColumnIndex, activeRowSpans) {
265927
+ if (count2 <= 0)
265928
+ return {
265929
+ columns: [],
265930
+ nextColumnIndex: startColumnIndex
265931
+ };
265932
+ const totalPreferredWidth = resolveMeasurementToPx(preferredWidthMeasurement, percentageBasis);
265933
+ const perColumnPreferredWidth = totalPreferredWidth != null && count2 > 0 ? Math.max(0, totalPreferredWidth / count2) : undefined;
265934
+ const columns = [];
265935
+ let columnIndex = startColumnIndex;
265936
+ for (let index2 = 0;index2 < count2; index2++) {
265937
+ columnIndex = advancePastOccupiedColumns(activeRowSpans, columnIndex);
265938
+ columns.push({
265939
+ columnIndex,
265940
+ preferredWidth: perColumnPreferredWidth,
265941
+ minContentWidth: 0,
265942
+ maxContentWidth: 0
265943
+ });
265944
+ columnIndex += 1;
265945
+ }
265946
+ return {
265947
+ columns,
265948
+ nextColumnIndex: columnIndex
265949
+ };
265950
+ }
265951
+ function normalizeSkippedAfterCount(countValue, preferredWidthMeasurement, percentageBasis) {
265952
+ const count2 = sanitizeCount(countValue);
265953
+ if (count2 <= 0)
265954
+ return 0;
265955
+ const totalPreferredWidth = resolveMeasurementToPx(preferredWidthMeasurement, percentageBasis);
265956
+ if (totalPreferredWidth != null && totalPreferredWidth <= PLACEHOLDER_COLUMN_MAX_WIDTH * count2)
265957
+ return 0;
265958
+ return count2;
265959
+ }
265960
+ function normalizeCell(cell2, percentageBasis, startColumn, logicalColumnLimit) {
265961
+ const cellProps = cell2.attrs?.tableCellProperties ?? {};
265962
+ const rawSpan = sanitizeCount(cell2.colSpan) || 1;
265963
+ const span = logicalColumnLimit != null && startColumn < logicalColumnLimit && startColumn + rawSpan > logicalColumnLimit ? Math.max(1, logicalColumnLimit - startColumn) : rawSpan;
265964
+ return {
265965
+ cellId: cell2.id,
265966
+ startColumn,
265967
+ span,
265968
+ preferredWidth: resolveMeasurementToPx(cellProps.cellWidth, percentageBasis)
265969
+ };
265970
+ }
265971
+ function advancePastOccupiedColumns(activeRowSpans, columnIndex) {
265972
+ let nextColumnIndex = columnIndex;
265973
+ while ((activeRowSpans[nextColumnIndex] ?? 0) > 0)
265974
+ nextColumnIndex += 1;
265975
+ return nextColumnIndex;
265976
+ }
265977
+ function resolveOccupiedLogicalColumnCount(activeRowSpans) {
265978
+ for (let index2 = activeRowSpans.length - 1;index2 >= 0; index2--)
265979
+ if ((activeRowSpans[index2] ?? 0) > 0)
265980
+ return index2 + 1;
265981
+ return 0;
265982
+ }
265983
+ function advanceRowSpans(activeRowSpans) {
265984
+ return activeRowSpans.map((remainingRows) => Math.max(0, remainingRows - 1));
265985
+ }
265986
+ function markRowSpanOccupancy(activeRowSpans, startColumn, span, remainingRows) {
265987
+ const boundedSpan = Math.max(1, sanitizeCount(span));
265988
+ for (let offset$1 = 0;offset$1 < boundedSpan; offset$1++) {
265989
+ const columnIndex = startColumn + offset$1;
265990
+ activeRowSpans[columnIndex] = Math.max(activeRowSpans[columnIndex] ?? 0, remainingRows);
265991
+ }
265992
+ }
265993
+ function determineGridColumnCount(preferredColumnCount, rows) {
265994
+ return Math.max(preferredColumnCount, ...rows.map((row2) => {
265995
+ if ("logicalColumnCount" in row2 && typeof row2.logicalColumnCount === "number")
265996
+ return row2.logicalColumnCount;
265997
+ const skippedBefore = row2.skippedBefore?.length ?? 0;
265998
+ const skippedAfter = row2.skippedAfter?.length ?? 0;
265999
+ const cellSpanTotal = (row2.cells ?? []).reduce((sum, cell2) => sum + Math.max(1, cell2.span ?? 1), 0);
266000
+ return skippedBefore + skippedAfter + cellSpanTotal;
266001
+ }), 0);
266002
+ }
266003
+ function resolvePreferredTableWidth(tableWidth, maxWidth) {
266004
+ const resolvedWidth = resolveTableWidthAttr(tableWidth);
266005
+ if (!resolvedWidth)
266006
+ return;
266007
+ if (resolvedWidth.type === "pct")
266008
+ return Math.round(maxWidth * (resolvedWidth.width / OOXML_PCT_DIVISOR));
266009
+ return resolvedWidth.width;
266010
+ }
266011
+ function resolveMeasurementToPx(measurement, percentageBasis) {
266012
+ if (!measurement || typeof measurement !== "object" || !Number.isFinite(measurement.value))
266013
+ return;
266014
+ const value = measurement.value;
266015
+ switch ((measurement.type ?? "dxa").toLowerCase()) {
266016
+ case "dxa":
266017
+ return value / TWIPS_PER_PX$1;
266018
+ case "pct":
266019
+ return Math.round(percentageBasis * (value / OOXML_PCT_DIVISOR));
266020
+ case "px":
266021
+ case "pixel":
266022
+ return value;
266023
+ case "auto":
266024
+ case "nil":
266025
+ return;
266026
+ default:
266027
+ return value;
266028
+ }
266029
+ }
266030
+ function sanitizeCount(value) {
266031
+ if (typeof value !== "number" || !Number.isFinite(value))
266032
+ return 0;
266033
+ return Math.max(0, Math.floor(value));
266034
+ }
266035
+ function sanitizePositiveNumber(value) {
266036
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0)
266037
+ return 1;
266038
+ return value;
266039
+ }
266040
+ function sanitizeNonNegativeNumber(value) {
266041
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
266042
+ return;
266043
+ return value;
266044
+ }
266045
+ function sumWidths(widths) {
266046
+ return widths.reduce((sum, width) => sum + Math.max(0, width), 0);
266047
+ }
266048
+ function approximatelyEqual(left$1, right$1) {
266049
+ return Math.abs(left$1 - right$1) <= 0.01;
266050
+ }
266051
+ function isSlightlyUnderPreferredTableWidth(totalColumnWidth, preferredTableWidth) {
266052
+ if (totalColumnWidth <= 0 || totalColumnWidth >= preferredTableWidth)
266053
+ return false;
266054
+ return preferredTableWidth - totalColumnWidth <= preferredTableWidth * 0.05;
266055
+ }
266056
+ function buildTableCellContentMetricsCacheKey(cell2, options) {
266057
+ return stableSerialize({
266058
+ maxWidth: Math.max(1, Math.round(options.maxWidth)),
266059
+ layoutEpoch: options.layoutEpoch ?? null,
266060
+ attrs: cell2.attrs ?? null,
266061
+ paragraph: cell2.paragraph ?? null,
266062
+ blocks: cell2.blocks ?? null
266063
+ });
266064
+ }
266065
+ function buildAutoFitTableResultCacheKey(table2, options) {
266066
+ return stableSerialize({
266067
+ id: table2.id,
266068
+ attrs: table2.attrs ?? null,
266069
+ columnWidths: table2.columnWidths ?? null,
266070
+ rowCount: table2.rows.length,
266071
+ maxWidth: Math.max(1, Math.round(options.maxWidth)),
266072
+ layoutEpoch: options.layoutEpoch ?? null,
266073
+ cellMetricKeys: options.cellMetricKeys,
266074
+ workingGrid: {
266075
+ layoutMode: options.workingInput.layoutMode,
266076
+ gridColumnCount: options.workingInput.gridColumnCount,
266077
+ preserveAuthoredGrid: options.workingInput.preserveAuthoredGrid === true,
266078
+ preserveAutoGrid: options.workingInput.preserveAutoGrid === true,
266079
+ preserveExplicitAutoGrid: options.workingInput.preserveExplicitAutoGrid === true,
266080
+ preferredTableWidth: options.workingInput.preferredTableWidth ?? null,
266081
+ preferredColumnWidths: options.workingInput.preferredColumnWidths,
266082
+ rows: options.workingInput.rows.map((row2) => ({
266083
+ logicalColumnCount: row2.logicalColumnCount,
266084
+ skippedColumns: (row2.skippedColumns ?? []).map((column) => ({
266085
+ columnIndex: column.columnIndex,
266086
+ preferredWidth: column.preferredWidth ?? null
266087
+ })),
266088
+ cells: row2.cells.map((cell2) => ({
266089
+ startColumn: cell2.startColumn,
266090
+ span: cell2.span ?? 1,
266091
+ preferredWidth: cell2.preferredWidth ?? null
266092
+ }))
266093
+ }))
266094
+ },
266095
+ fixedLayout: {
266096
+ columnWidths: options.fixedLayout.columnWidths,
266097
+ totalWidth: options.fixedLayout.totalWidth,
266098
+ gridColumnCount: options.fixedLayout.gridColumnCount,
266099
+ preferredTableWidth: options.fixedLayout.preferredTableWidth ?? null
266100
+ }
266101
+ });
266102
+ }
266103
+ function getCachedAutoFitTableResult(cacheKey) {
266104
+ return autoFitTableResultCache.get(cacheKey);
266105
+ }
266106
+ function setCachedAutoFitTableResult(cacheKey, result) {
266107
+ autoFitTableResultCache.set(cacheKey, result);
266108
+ }
266109
+ async function measureTableCellContentMetrics(cell2, options) {
266110
+ const cacheKey = buildTableCellContentMetricsCacheKey(cell2, options);
266111
+ const cached = tableCellMetricsCache.get(cacheKey);
266112
+ if (cached)
266113
+ return cached;
266114
+ const horizontalInsets = getHorizontalCellInsets(cell2);
266115
+ const contentBlocks = cell2.blocks ?? (cell2.paragraph ? [cell2.paragraph] : []);
266116
+ if (contentBlocks.length === 0) {
266117
+ const emptyMetrics = {
266118
+ minWidthPx: horizontalInsets,
266119
+ maxWidthPx: horizontalInsets
266120
+ };
266121
+ tableCellMetricsCache.set(cacheKey, emptyMetrics);
266122
+ return emptyMetrics;
266123
+ }
266124
+ let minContentWidthPx = 0;
266125
+ let maxContentWidthPx = 0;
266126
+ for (const block of contentBlocks) {
266127
+ const metrics = await measureIntrinsicBlockWidthMetrics(block, options);
266128
+ minContentWidthPx = Math.max(minContentWidthPx, metrics.minWidthPx);
266129
+ maxContentWidthPx = Math.max(maxContentWidthPx, metrics.maxWidthPx);
266130
+ }
266131
+ const result = {
266132
+ minWidthPx: minContentWidthPx + horizontalInsets,
266133
+ maxWidthPx: maxContentWidthPx + horizontalInsets
266134
+ };
266135
+ tableCellMetricsCache.set(cacheKey, result);
266136
+ return result;
266137
+ }
266138
+ async function measureTableAutoFitContentMetrics(table2, workingInput, fixedLayout, measureBlock$1) {
266139
+ const tableMeasurementBasis = Math.max(1, fixedLayout.totalWidth);
266140
+ const cellMetricKeys = [];
266141
+ const rowMetrics = await Promise.all(table2.rows.map(async (row2, rowIndex) => {
266142
+ const normalizedRow = workingInput.rows[rowIndex] ?? {};
266143
+ return {
266144
+ rowIndex,
266145
+ cells: await Promise.all(row2.cells.map(async (cell2, cellIndex) => {
266146
+ const normalizedCell = normalizedRow.cells?.[cellIndex];
266147
+ const span = normalizedCell?.span ?? cell2.colSpan ?? 1;
266148
+ const measurementMaxWidth = resolveAutoFitCellMeasurementMaxWidth(cell2, normalizedCell, span, fixedLayout, tableMeasurementBasis, workingInput.gridColumnCount);
266149
+ cellMetricKeys.push(buildTableCellContentMetricsCacheKey(cell2, { maxWidth: measurementMaxWidth }));
266150
+ const metrics = await measureTableCellContentMetrics(cell2, {
266151
+ maxWidth: measurementMaxWidth,
266152
+ measureBlock: measureBlock$1
266153
+ });
266154
+ return {
266155
+ cellIndex,
266156
+ span,
266157
+ preferredWidth: normalizedCell?.preferredWidth,
266158
+ minContentWidth: metrics.minWidthPx,
266159
+ maxContentWidth: metrics.maxWidthPx
266160
+ };
266161
+ }))
266162
+ };
266163
+ }));
266164
+ return {
266165
+ rowMetrics,
266166
+ rows: rowMetrics.map((rowMetrics$1, rowIndex) => {
266167
+ const normalizedRow = workingInput.rows[rowIndex] ?? {};
266168
+ return {
266169
+ skippedBefore: normalizedRow.skippedBefore ?? [],
266170
+ cells: rowMetrics$1.cells.map((cellMetrics) => ({
266171
+ span: cellMetrics.span,
266172
+ preferredWidth: cellMetrics.preferredWidth,
266173
+ minContentWidth: cellMetrics.minContentWidth,
266174
+ maxContentWidth: cellMetrics.maxContentWidth
266175
+ })),
266176
+ skippedAfter: normalizedRow.skippedAfter ?? []
266177
+ };
266178
+ }),
266179
+ cellMetricKeys
266180
+ };
266181
+ }
266182
+ async function measureIntrinsicBlockWidthMetrics(block, options) {
266183
+ if (block.kind === "paragraph")
266184
+ return measureParagraphIntrinsicWidthMetrics(block, options.measureBlock);
266185
+ if (block.kind === "table")
266186
+ return measureNestedTableIntrinsicWidthMetrics(block, options);
266187
+ const intrinsicWidth = getIntrinsicAtomicBlockWidth(block);
266188
+ return {
266189
+ minWidthPx: intrinsicWidth,
266190
+ maxWidthPx: intrinsicWidth
266191
+ };
266192
+ }
266193
+ async function measureParagraphIntrinsicWidthMetrics(paragraph2, measureBlock$1) {
266194
+ const maxLineWidth = (await measureBlock$1(paragraph2, {
266195
+ maxWidth: NO_WRAP_MAX_WIDTH,
266196
+ maxHeight: Infinity
266197
+ })).lines.reduce((widest, line) => Math.max(widest, line.width), 0);
266198
+ return {
266199
+ minWidthPx: measureParagraphMinTokenWidth(paragraph2),
266200
+ maxWidthPx: maxLineWidth
266201
+ };
266202
+ }
266203
+ async function measureNestedTableIntrinsicWidthMetrics(table2, options) {
266204
+ const nestedMeasure = await options.measureBlock(table2, {
266205
+ maxWidth: Math.max(1, options.maxWidth),
266206
+ maxHeight: Infinity
266207
+ });
266208
+ if (nestedMeasure.kind !== "table")
266209
+ return {
266210
+ minWidthPx: 0,
266211
+ maxWidthPx: 0
266212
+ };
266213
+ return {
266214
+ minWidthPx: nestedMeasure.totalWidth,
266215
+ maxWidthPx: nestedMeasure.totalWidth
266216
+ };
266217
+ }
266218
+ function measureParagraphMinTokenWidth(paragraph2) {
266219
+ let widestToken = 0;
266220
+ let currentTokenWidth = 0;
266221
+ const flushToken = () => {
266222
+ widestToken = Math.max(widestToken, currentTokenWidth);
266223
+ currentTokenWidth = 0;
266224
+ };
266225
+ for (const run2 of paragraph2.runs) {
266226
+ if (isExplicitLineBreakRun(run2)) {
266227
+ flushToken();
266228
+ continue;
266229
+ }
266230
+ if (isTextLikeRun(run2)) {
266231
+ accumulateTextRunMinTokenWidth(run2, (width) => {
266232
+ currentTokenWidth += width;
266233
+ }, flushToken);
266234
+ continue;
266235
+ }
266236
+ flushToken();
266237
+ if (run2.kind === "image") {
266238
+ widestToken = Math.max(widestToken, run2.width ?? 0);
266239
+ continue;
266240
+ }
266241
+ if (run2.kind === "fieldAnnotation") {
266242
+ widestToken = Math.max(widestToken, measureFieldAnnotationWidth(run2));
266243
+ continue;
266244
+ }
266245
+ if (run2.kind === "math")
266246
+ widestToken = Math.max(widestToken, run2.width ?? 0);
266247
+ }
266248
+ flushToken();
266249
+ return widestToken;
266250
+ }
266251
+ function accumulateTextRunMinTokenWidth(run2, appendTokenPiece, flushToken) {
266252
+ const font = buildFontString$1(run2);
266253
+ let cursor = 0;
266254
+ for (const boundary of run2.text.matchAll(TOKEN_BOUNDARY_PATTERN)) {
266255
+ const boundaryStart = boundary.index ?? cursor;
266256
+ if (boundaryStart > cursor)
266257
+ appendTokenPiece(measureTextRunTokenSlice(run2, cursor, boundaryStart, font));
266258
+ flushToken();
266259
+ cursor = boundaryStart + boundary[0].length;
266260
+ }
266261
+ if (cursor < run2.text.length)
266262
+ appendTokenPiece(measureTextRunTokenSlice(run2, cursor, run2.text.length, font));
266263
+ }
266264
+ function measureTextRunTokenSlice(run2, start$1, end$1, font) {
266265
+ return getMeasuredTextWidth(applyTextTransform$1(run2.text.slice(start$1, end$1), run2, start$1), font, getLetterSpacing(run2), getCanvasContext$1());
266266
+ }
266267
+ function getIntrinsicAtomicBlockWidth(block) {
266268
+ if (block.kind === "image")
266269
+ return block.width ?? 0;
266270
+ if (block.drawingKind === "image")
266271
+ return block.width ?? 0;
266272
+ if (block.drawingKind === "shapeGroup")
266273
+ return block.size?.width ?? block.geometry.width;
266274
+ return block.geometry.width;
266275
+ }
266276
+ function resolveAutoFitCellMeasurementMaxWidth(cell2, normalizedCell, span, fixedLayout, tableWidthBasis, gridColumnCount) {
266277
+ const outerWidth = resolveFixedPassCellOuterWidth(normalizedCell, span, fixedLayout) ?? normalizedCell?.preferredWidth ?? Math.max(1, tableWidthBasis * (Math.max(1, span) / Math.max(1, gridColumnCount || span || 1)));
266278
+ const padding = cell2.attrs?.padding ?? DEFAULT_CELL_PADDING$1;
266279
+ const leftPadding = padding.left ?? DEFAULT_CELL_PADDING$1.left;
266280
+ const rightPadding = padding.right ?? DEFAULT_CELL_PADDING$1.right;
266281
+ const leftBorder = getCellBorderWidthPx(cell2.attrs?.borders?.left);
266282
+ const rightBorder = getCellBorderWidthPx(cell2.attrs?.borders?.right);
266283
+ return Math.max(1, outerWidth - leftPadding - rightPadding - leftBorder - rightBorder);
266284
+ }
266285
+ function resolveFixedPassCellOuterWidth(normalizedCell, fallbackSpan, fixedLayout) {
266286
+ if (normalizedCell?.startColumn == null)
266287
+ return;
266288
+ const span = Math.max(1, normalizedCell.span ?? fallbackSpan);
266289
+ let width = 0;
266290
+ for (let offset$1 = 0;offset$1 < span; offset$1++)
266291
+ width += fixedLayout.columnWidths[normalizedCell.startColumn + offset$1] ?? 0;
266292
+ return width > 0 ? width : undefined;
266293
+ }
266294
+ function getHorizontalCellInsets(cell2) {
266295
+ const padding = cell2.attrs?.padding ?? DEFAULT_CELL_PADDING$1;
266296
+ const leftPadding = padding.left ?? DEFAULT_CELL_PADDING$1.left;
266297
+ const rightPadding = padding.right ?? DEFAULT_CELL_PADDING$1.right;
266298
+ const leftBorder = getCellBorderWidthPx(cell2.attrs?.borders?.left);
266299
+ const rightBorder = getCellBorderWidthPx(cell2.attrs?.borders?.right);
266300
+ return leftPadding + rightPadding + leftBorder + rightBorder;
266301
+ }
266302
+ function getCellBorderWidthPx(border) {
266303
+ if (!border || border.style === "none")
266304
+ return 0;
266305
+ const width = typeof border.width === "number" ? border.width : 0;
266306
+ if (border.style === "thick")
266307
+ return Math.max(width * 2, 3);
266308
+ return Math.max(0, width);
266309
+ }
266310
+ function getCanvasContext$1() {
266311
+ if (!canvasContext$1) {
266312
+ canvasContext$1 = document.createElement("canvas").getContext("2d");
266313
+ if (!canvasContext$1)
266314
+ throw new Error("Failed to create canvas context for AutoFit cell measurement.");
266315
+ }
266316
+ return canvasContext$1;
266317
+ }
266318
+ function buildFontString$1(run2) {
266319
+ const parts = [];
266320
+ if (run2.italic)
266321
+ parts.push("italic");
266322
+ if (run2.bold)
266323
+ parts.push("bold");
266324
+ parts.push(`${normalizeFontSize$1(run2.fontSize)}px`);
266325
+ parts.push(toCssFontFamily(normalizeFontFamily$1(run2.fontFamily)) ?? normalizeFontFamily$1(run2.fontFamily));
266326
+ return parts.join(" ");
266327
+ }
266328
+ function applyTextTransform$1(text5, run2, startOffset = 0) {
266329
+ const transform = run2.textTransform;
266330
+ if (!text5 || !transform || transform === "none")
266331
+ return text5;
266332
+ if (transform === "uppercase")
266333
+ return text5.toUpperCase();
266334
+ if (transform === "lowercase")
266335
+ return text5.toLowerCase();
266336
+ if (transform === "capitalize")
266337
+ return capitalizeText$1(text5, run2.text ?? text5, startOffset);
266338
+ return text5;
266339
+ }
266340
+ function capitalizeText$1(text5, fullText, startOffset) {
266341
+ let result = "";
266342
+ for (let index2 = 0;index2 < text5.length; index2++) {
266343
+ const absoluteIndex = startOffset + index2;
266344
+ const currentChar = text5[index2];
266345
+ const previousChar = absoluteIndex > 0 ? fullText[absoluteIndex - 1] : "";
266346
+ result += isWordCharacter(currentChar) && !isWordCharacter(previousChar) ? currentChar.toUpperCase() : currentChar;
266347
+ }
266348
+ return result;
266349
+ }
266350
+ function measureFieldAnnotationWidth(run2) {
266351
+ const fontSize = typeof run2.fontSize === "number" ? run2.fontSize : typeof run2.fontSize === "string" ? parseFloat(run2.fontSize) || DEFAULT_FIELD_ANNOTATION_FONT_SIZE$1 : DEFAULT_FIELD_ANNOTATION_FONT_SIZE$1;
266352
+ const font = buildFontString$1({
266353
+ fontFamily: normalizeFontFamily$1(run2.fontFamily ?? "Arial"),
266354
+ fontSize,
266355
+ bold: run2.bold,
266356
+ italic: run2.italic
266357
+ });
266358
+ return getMeasuredTextWidth(applyTextTransform$1(run2.displayLabel || "", { text: run2.displayLabel || "" }), font, 0, getCanvasContext$1()) + (run2.highlighted === false ? 0 : FIELD_ANNOTATION_PILL_PADDING$1);
266359
+ }
266360
+ function isExplicitLineBreakRun(run2) {
266361
+ return run2.kind === "lineBreak" || run2.kind === "break" && run2.breakType === "line";
266362
+ }
266363
+ function isTextLikeRun(run2) {
266364
+ return "text" in run2 && typeof run2.text === "string";
266365
+ }
266366
+ function getLetterSpacing(run2) {
266367
+ return "letterSpacing" in run2 && typeof run2.letterSpacing === "number" ? run2.letterSpacing : 0;
266368
+ }
266369
+ function normalizeFontSize$1(value) {
266370
+ if (typeof value === "number" && Number.isFinite(value) && value > 0)
266371
+ return value;
266372
+ if (typeof value === "string") {
266373
+ const parsed = parseFloat(value);
266374
+ if (Number.isFinite(parsed) && parsed > 0)
266375
+ return parsed;
266376
+ }
266377
+ return 12;
266378
+ }
266379
+ function normalizeFontFamily$1(value) {
266380
+ return typeof value === "string" && value.trim().length > 0 ? value : "Arial";
266381
+ }
266382
+ function stableSerialize(value) {
266383
+ if (value === null || typeof value !== "object")
266384
+ return JSON.stringify(value);
266385
+ if (Array.isArray(value))
266386
+ return `[${value.map((item) => stableSerialize(item)).join(",")}]`;
266387
+ return `{${Object.entries(value).sort(([left$1], [right$1]) => left$1.localeCompare(right$1)).map(([key2, entry]) => `${JSON.stringify(key2)}:${stableSerialize(entry)}`).join(",")}}`;
266388
+ }
266389
+ function isWordCharacter(value) {
266390
+ return /[A-Za-z0-9]/.test(value);
266391
+ }
264793
266392
  function getTableBorderWidthPx(value) {
264794
266393
  if (value == null)
264795
266394
  return 0;
@@ -266280,161 +267879,9 @@ async function measureParagraphBlock(block, maxWidth) {
266280
267879
  ...dropCapMeasure ? { dropCap: dropCapMeasure } : {}
266281
267880
  };
266282
267881
  }
266283
- function validateTableWidthValue(attr) {
266284
- const value = attr.width ?? attr.value;
266285
- if (typeof value === "number" && Number.isFinite(value) && value > 0)
266286
- return value;
266287
- }
266288
- function resolveTableWidth(attrs, maxWidth) {
266289
- const tableWidthAttr = attrs?.tableWidth;
266290
- if (!tableWidthAttr || typeof tableWidthAttr !== "object")
266291
- return;
266292
- const typedAttr = tableWidthAttr;
266293
- const validValue = validateTableWidthValue(typedAttr);
266294
- if (validValue === undefined)
266295
- return;
266296
- if (typedAttr.type === "pct")
266297
- return Math.round(maxWidth * (validValue / OOXML_PCT_DIVISOR));
266298
- else if (typedAttr.type === "px" || typedAttr.type === "pixel" || typedAttr.type === "dxa")
266299
- return validValue;
266300
- }
266301
267882
  async function measureTableBlock(block, constraints) {
266302
- const maxWidth = typeof constraints === "number" ? constraints : constraints.maxWidth;
266303
- const resolvedTableWidth = resolveTableWidth(block.attrs, maxWidth);
266304
- let columnWidths;
266305
- const maxCellCount = Math.max(1, Math.max(...block.rows.map((r$1) => r$1.cells.reduce((sum, cell2) => sum + (cell2.colSpan ?? 1), 0))));
266306
- const effectiveTargetWidth = resolvedTableWidth != null ? Math.min(resolvedTableWidth, maxWidth) : maxWidth;
266307
- if (block.columnWidths && block.columnWidths.length > 0) {
266308
- columnWidths = [...block.columnWidths];
266309
- const hasExplicitWidth = resolvedTableWidth != null;
266310
- const hasFixedLayout = block.attrs?.tableLayout === "fixed";
266311
- if (hasExplicitWidth || hasFixedLayout) {
266312
- const totalWidth$1 = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
266313
- const tableWidthType = block.attrs?.tableWidth?.type;
266314
- if ((totalWidth$1 > effectiveTargetWidth || totalWidth$1 < effectiveTargetWidth && effectiveTargetWidth > 0 && (tableWidthType === "pct" || hasExplicitWidth && !hasFixedLayout)) && effectiveTargetWidth > 0 && totalWidth$1 > 0) {
266315
- const scale = effectiveTargetWidth / totalWidth$1;
266316
- columnWidths = columnWidths.map((w) => Math.max(1, Math.round(w * scale)));
266317
- const scaledSum = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
266318
- if (scaledSum !== effectiveTargetWidth && columnWidths.length > 0) {
266319
- const diff = effectiveTargetWidth - scaledSum;
266320
- columnWidths[columnWidths.length - 1] = Math.max(1, columnWidths[columnWidths.length - 1] + diff);
266321
- }
266322
- }
266323
- } else {
266324
- if (columnWidths.length < maxCellCount) {
266325
- const usedWidth = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
266326
- const remainingWidth = Math.max(0, effectiveTargetWidth - usedWidth);
266327
- const missingColumns = maxCellCount - columnWidths.length;
266328
- const paddingWidth = Math.max(1, Math.floor(remainingWidth / missingColumns));
266329
- columnWidths.push(...Array.from({ length: missingColumns }, () => paddingWidth));
266330
- } else if (columnWidths.length > maxCellCount)
266331
- columnWidths = columnWidths.slice(0, maxCellCount);
266332
- const totalWidth$1 = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
266333
- if (totalWidth$1 > effectiveTargetWidth && effectiveTargetWidth > 0) {
266334
- const scale = effectiveTargetWidth / totalWidth$1;
266335
- columnWidths = columnWidths.map((w) => Math.max(1, Math.round(w * scale)));
266336
- const scaledSum = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
266337
- if (scaledSum !== effectiveTargetWidth && columnWidths.length > 0) {
266338
- const diff = effectiveTargetWidth - scaledSum;
266339
- columnWidths[columnWidths.length - 1] = Math.max(1, columnWidths[columnWidths.length - 1] + diff);
266340
- }
266341
- }
266342
- }
266343
- } else {
266344
- const columnWidth = Math.max(1, Math.floor(effectiveTargetWidth / maxCellCount));
266345
- columnWidths = Array.from({ length: maxCellCount }, () => columnWidth);
266346
- }
266347
- const isFixedLayout = block.attrs?.tableLayout === "fixed";
266348
- const gridLooksLikePlaceholder = columnWidths.reduce((a2, b$1) => a2 + b$1, 0) < maxWidth * 0.1;
266349
- if (!isFixedLayout && gridLooksLikePlaceholder) {
266350
- const gridColCount = columnWidths.length;
266351
- const maxContentWidths = new Array(gridColCount).fill(0);
266352
- const autoFitRowspanTracker = new Array(gridColCount).fill(0);
266353
- for (const row2 of block.rows) {
266354
- let colIndex = 0;
266355
- for (const cell2 of row2.cells) {
266356
- const colspan = cell2.colSpan ?? 1;
266357
- const rowspan = cell2.rowSpan ?? 1;
266358
- while (colIndex < gridColCount && autoFitRowspanTracker[colIndex] > 0) {
266359
- autoFitRowspanTracker[colIndex]--;
266360
- colIndex++;
266361
- }
266362
- if (colIndex >= gridColCount)
266363
- break;
266364
- if (colspan === 1) {
266365
- const cellPadding = cell2.attrs?.padding ?? DEFAULT_CELL_PADDING;
266366
- const paddingH = (cellPadding.left ?? 4) + (cellPadding.right ?? 4);
266367
- const cellBlocks = cell2.blocks ?? (cell2.paragraph ? [cell2.paragraph] : []);
266368
- let cellMaxWidth = 0;
266369
- for (const cellBlock of cellBlocks) {
266370
- const maxMeasure = await measureBlock(cellBlock, {
266371
- maxWidth: 99999,
266372
- maxHeight: Infinity
266373
- });
266374
- let blockMaxWidth = 0;
266375
- if (maxMeasure.kind === "paragraph") {
266376
- for (const line of maxMeasure.lines)
266377
- if (line.width > blockMaxWidth)
266378
- blockMaxWidth = line.width;
266379
- } else if (maxMeasure.kind === "image" || maxMeasure.kind === "drawing")
266380
- blockMaxWidth = maxMeasure.width;
266381
- else if (maxMeasure.kind === "table")
266382
- blockMaxWidth = maxMeasure.totalWidth;
266383
- else if (maxMeasure.kind === "list") {
266384
- for (const item of maxMeasure.items)
266385
- if (item.paragraph) {
266386
- const gutterWidth = (item.indentLeft ?? 0) + (item.markerWidth ?? 0);
266387
- for (const line of item.paragraph.lines) {
266388
- const lineTotal = gutterWidth + line.width;
266389
- if (lineTotal > blockMaxWidth)
266390
- blockMaxWidth = lineTotal;
266391
- }
266392
- }
266393
- }
266394
- if (blockMaxWidth > cellMaxWidth)
266395
- cellMaxWidth = blockMaxWidth;
266396
- }
266397
- const totalWidth$1 = cellMaxWidth + paddingH;
266398
- if (totalWidth$1 > maxContentWidths[colIndex])
266399
- maxContentWidths[colIndex] = totalWidth$1;
266400
- }
266401
- if (rowspan > 1)
266402
- for (let c = 0;c < colspan && colIndex + c < gridColCount; c++)
266403
- autoFitRowspanTracker[colIndex + c] = rowspan - 1;
266404
- colIndex += colspan;
266405
- }
266406
- for (let col = colIndex;col < gridColCount; col++)
266407
- if (autoFitRowspanTracker[col] > 0)
266408
- autoFitRowspanTracker[col]--;
266409
- }
266410
- const contentTotal = maxContentWidths.reduce((a2, b$1) => a2 + b$1, 0);
266411
- if (contentTotal > 0)
266412
- if (contentTotal <= maxWidth) {
266413
- for (let i4 = 0;i4 < gridColCount; i4++)
266414
- if (maxContentWidths[i4] > columnWidths[i4])
266415
- columnWidths[i4] = maxContentWidths[i4];
266416
- const expandedTotal = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
266417
- if (expandedTotal > maxWidth && gridColCount > 0) {
266418
- const scale = maxWidth / expandedTotal;
266419
- for (let i4 = 0;i4 < gridColCount; i4++)
266420
- columnWidths[i4] = Math.max(1, Math.round(columnWidths[i4] * scale));
266421
- const scaledSum = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
266422
- if (scaledSum !== maxWidth) {
266423
- const diff = maxWidth - scaledSum;
266424
- columnWidths[gridColCount - 1] = Math.max(1, columnWidths[gridColCount - 1] + diff);
266425
- }
266426
- }
266427
- } else {
266428
- const scale = maxWidth / contentTotal;
266429
- for (let i4 = 0;i4 < gridColCount; i4++)
266430
- columnWidths[i4] = Math.max(1, Math.round(maxContentWidths[i4] * scale));
266431
- const scaledSum = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
266432
- if (scaledSum !== maxWidth && gridColCount > 0) {
266433
- const diff = maxWidth - scaledSum;
266434
- columnWidths[gridColCount - 1] = Math.max(1, columnWidths[gridColCount - 1] + diff);
266435
- }
266436
- }
266437
- }
267883
+ const workingInput = buildAutoFitWorkingGridInput(block, { maxWidth: typeof constraints === "number" ? constraints : constraints.maxWidth });
267884
+ const columnWidths = await resolveRuntimeTableColumnWidths(block, workingInput);
266438
267885
  const gridColumnCount = columnWidths.length;
266439
267886
  const calculateCellWidth = (startCol, colspan) => {
266440
267887
  let width = 0;
@@ -266448,11 +267895,19 @@ async function measureTableBlock(block, constraints) {
266448
267895
  const spanConstraints = [];
266449
267896
  for (let rowIndex = 0;rowIndex < block.rows.length; rowIndex++) {
266450
267897
  const row2 = block.rows[rowIndex];
267898
+ const normalizedRow = workingInput.rows[rowIndex];
266451
267899
  const cellMeasures = [];
266452
267900
  let gridColIndex = 0;
266453
- for (const cell2 of row2.cells) {
267901
+ for (let cellIndex = 0;cellIndex < row2.cells.length; cellIndex++) {
267902
+ const cell2 = row2.cells[cellIndex];
266454
267903
  const colspan = cell2.colSpan ?? 1;
266455
267904
  const rowspan = cell2.rowSpan ?? 1;
267905
+ const preferredStartColumn = normalizedRow?.cells?.[cellIndex]?.startColumn ?? gridColIndex;
267906
+ while (gridColIndex < gridColumnCount && gridColIndex < preferredStartColumn) {
267907
+ if (rowspanTracker[gridColIndex] > 0)
267908
+ rowspanTracker[gridColIndex]--;
267909
+ gridColIndex++;
267910
+ }
266456
267911
  while (gridColIndex < gridColumnCount && rowspanTracker[gridColIndex] > 0) {
266457
267912
  rowspanTracker[gridColIndex]--;
266458
267913
  gridColIndex++;
@@ -266555,18 +268010,48 @@ async function measureTableBlock(block, constraints) {
266555
268010
  const borderWidthH = tableBorderWidths.left + tableBorderWidths.right;
266556
268011
  const borderWidthV = tableBorderWidths.top + tableBorderWidths.bottom;
266557
268012
  const includeOuterBordersInTotal = (block.attrs?.borderCollapse ?? (block.attrs?.cellSpacing != null ? "separate" : "collapse")) === "separate";
266558
- const totalWidth = contentWidth + horizontalGaps + (includeOuterBordersInTotal ? borderWidthH : 0);
266559
- const totalHeight = contentHeight + verticalGaps + (includeOuterBordersInTotal ? borderWidthV : 0);
266560
268013
  return {
266561
268014
  kind: "table",
266562
268015
  rows,
266563
268016
  columnWidths,
266564
- totalWidth,
266565
- totalHeight,
268017
+ totalWidth: contentWidth + horizontalGaps + (includeOuterBordersInTotal ? borderWidthH : 0),
268018
+ totalHeight: contentHeight + verticalGaps + (includeOuterBordersInTotal ? borderWidthV : 0),
266566
268019
  cellSpacingPx: cellSpacingPx > 0 ? cellSpacingPx : undefined,
266567
268020
  tableBorderWidths: borderWidthH > 0 || borderWidthV > 0 ? tableBorderWidths : undefined
266568
268021
  };
266569
268022
  }
268023
+ async function resolveRuntimeTableColumnWidths(block, workingInput) {
268024
+ const fixedLayout = computeFixedTableColumnWidths(workingInput);
268025
+ if (workingInput.layoutMode === "fixed")
268026
+ return fixedLayout.columnWidths;
268027
+ const { contentMetrics, cellMetricKeys } = await buildMeasuredAutoFitContentMetrics(block, workingInput, fixedLayout);
268028
+ const cacheKey = buildAutoFitTableResultCacheKey(block, {
268029
+ maxWidth: workingInput.maxTableWidth,
268030
+ cellMetricKeys,
268031
+ workingInput,
268032
+ fixedLayout
268033
+ });
268034
+ const cached = getCachedAutoFitTableResult(cacheKey);
268035
+ if (cached)
268036
+ return cached.columnWidths;
268037
+ const result = computeAutoFitColumnWidths({
268038
+ workingInput,
268039
+ fixedLayout,
268040
+ contentMetrics: { rowMetrics: contentMetrics.rowMetrics }
268041
+ });
268042
+ setCachedAutoFitTableResult(cacheKey, {
268043
+ columnWidths: result.columnWidths,
268044
+ totalWidth: result.totalWidth
268045
+ });
268046
+ return result.columnWidths;
268047
+ }
268048
+ async function buildMeasuredAutoFitContentMetrics(block, workingInput, fixedLayout) {
268049
+ const contentMetrics = await measureTableAutoFitContentMetrics(block, workingInput, fixedLayout, measureBlock);
268050
+ return {
268051
+ contentMetrics,
268052
+ cellMetricKeys: contentMetrics.cellMetricKeys
268053
+ };
268054
+ }
266570
268055
  async function measureImageBlock(block, constraints) {
266571
268056
  const intrinsic = getIntrinsicImageSize(block, constraints.maxWidth);
266572
268057
  const isBlockBehindDoc = block.anchor?.behindDoc;
@@ -267419,7 +268904,7 @@ var Node$13 = class Node$14 {
267419
268904
  "iPhone",
267420
268905
  "iPod"
267421
268906
  ].includes(navigator.platform);
267422
- }, OOXML_PCT_DIVISOR = 5000, TWIPS_PER_PX$2 = 15, isPlainObject$7 = (value) => value !== null && typeof value === "object" && !Array.isArray(value), OOXML_Z_INDEX_BASE = 251658240, SPACE_CHARS, isAtomicRunKind = (kind) => kind === "image" || kind === "lineBreak" || kind === "break" || kind === "tab" || kind === "fieldAnnotation", isImageLikeRun = (run2) => {
268907
+ }, OOXML_PCT_DIVISOR = 5000, TWIPS_PER_PX$3 = 15, isPlainObject$7 = (value) => value !== null && typeof value === "object" && !Array.isArray(value), OOXML_Z_INDEX_BASE = 251658240, SPACE_CHARS, isAtomicRunKind = (kind) => kind === "image" || kind === "lineBreak" || kind === "break" || kind === "tab" || kind === "fieldAnnotation", isImageLikeRun = (run2) => {
267423
268908
  if (!run2 || typeof run2 !== "object")
267424
268909
  return false;
267425
268910
  return typeof run2.src === "string";
@@ -277246,7 +278731,7 @@ var Node$13 = class Node$14 {
277246
278731
  this.deco = deco;
277247
278732
  }
277248
278733
  }, searchKey, BLOCK_SEPARATOR = `
277249
- `, ATOM_PLACEHOLDER = "", SearchIndex, customSearchHighlightsKey, isRegExp2 = (value) => Object.prototype.toString.call(value) === "[object RegExp]", SEARCH_POSITION_TRACKER_TYPE = "search-match", mapIndexMatchesToDocMatches = ({ searchIndex, indexMatches, doc: doc$12, positionTracker }) => {
278734
+ `, ATOM_PLACEHOLDER = "", DELETION_BARRIER = "\x00", DEFAULT_SEARCH_MODEL$1 = "raw", hasTrackDeleteMark$1 = (node3) => node3?.marks?.some((mark2) => mark2?.type?.name === "trackDelete") ?? false, SearchIndex, customSearchHighlightsKey, isRegExp2 = (value) => Object.prototype.toString.call(value) === "[object RegExp]", SEARCH_POSITION_TRACKER_TYPE = "search-match", DEFAULT_SEARCH_MODEL = "raw", normalizeSearchModel = (value) => value === "visible" ? "visible" : DEFAULT_SEARCH_MODEL, mapIndexMatchesToDocMatches = ({ searchIndex, indexMatches, doc: doc$12, positionTracker }) => {
277250
278735
  const matches2 = [];
277251
278736
  for (const indexMatch of indexMatches) {
277252
278737
  const ranges = searchIndex.offsetRangeToDocRanges(indexMatch.start, indexMatch.end);
@@ -278583,7 +280068,7 @@ var Node$13 = class Node$14 {
278583
280068
  });
278584
280069
  const renderSearchDropdown = () => {
278585
280070
  const handleSubmit = ({ value }) => {
278586
- superToolbar.activeEditor.commands.search(value);
280071
+ superToolbar.activeEditor.commands.search(value, { searchModel: "visible" });
278587
280072
  };
278588
280073
  return exports_vue.h("div", {}, [exports_vue.h(SearchInput_default, {
278589
280074
  onSubmit: handleSubmit,
@@ -286990,9 +288475,17 @@ menclose::after {
286990
288475
  inlineBorders = normalizeTableBorders(tableProps.borders);
286991
288476
  if (typeof tableProps.justification === "string")
286992
288477
  hydration.justification = tableProps.justification;
288478
+ const tableIndent = normalizeTableIndent(tableProps.tableIndent);
288479
+ if (tableIndent)
288480
+ hydration.tableIndent = tableIndent;
288481
+ if (typeof tableProps.tableLayout === "string")
288482
+ hydration.tableLayout = tableProps.tableLayout;
286993
288483
  const tableWidth = normalizeTableWidth(tableProps.tableWidth);
286994
288484
  if (tableWidth)
286995
288485
  hydration.tableWidth = tableWidth;
288486
+ const tableCellSpacing = normalizeTableSpacing(tableProps.tableCellSpacing);
288487
+ if (tableCellSpacing)
288488
+ hydration.tableCellSpacing = tableCellSpacing;
286996
288489
  }
286997
288490
  const styleId = effectiveStyleId === null ? undefined : effectiveStyleId ?? (typeof tableNode.attrs?.tableStyleId === "string" ? tableNode.attrs.tableStyleId : undefined);
286998
288491
  if (styleId && context?.translatedLinkedStyles) {
@@ -287019,8 +288512,18 @@ menclose::after {
287019
288512
  hydration.cellPadding = inlinePadding;
287020
288513
  if (!hydration.justification && resolved.justification)
287021
288514
  hydration.justification = resolved.justification;
287022
- if (resolved.tableCellSpacing)
287023
- hydration.tableCellSpacing = resolved.tableCellSpacing;
288515
+ if (!hydration.tableIndent && resolved.tableIndent) {
288516
+ const tableIndent = normalizeTableIndent(resolved.tableIndent);
288517
+ if (tableIndent)
288518
+ hydration.tableIndent = tableIndent;
288519
+ }
288520
+ if (!hydration.tableLayout && resolved.tableLayout)
288521
+ hydration.tableLayout = resolved.tableLayout;
288522
+ if (!hydration.tableCellSpacing && resolved.tableCellSpacing) {
288523
+ const tableCellSpacing = normalizeTableSpacing(resolved.tableCellSpacing);
288524
+ if (tableCellSpacing)
288525
+ hydration.tableCellSpacing = tableCellSpacing;
288526
+ }
287024
288527
  if (!hydration.tableWidth && resolved.tableWidth) {
287025
288528
  const tableWidth = normalizeTableWidth(resolved.tableWidth);
287026
288529
  if (tableWidth)
@@ -287118,7 +288621,41 @@ menclose::after {
287118
288621
  width: raw,
287119
288622
  type: measurement.type
287120
288623
  };
287121
- }, isTableRowNode = (node3) => node3.type === "tableRow" || node3.type === "table_row", isTableCellNode = (node3) => node3.type === "tableCell" || node3.type === "table_cell" || node3.type === "tableHeader" || node3.type === "table_header", convertResolvedCellBorder = (value) => {
288624
+ }, normalizeTableIndent = (value) => {
288625
+ if (!value || typeof value !== "object")
288626
+ return;
288627
+ const measurement = value;
288628
+ const raw = typeof measurement.width === "number" ? measurement.width : measurement.value;
288629
+ if (typeof raw !== "number")
288630
+ return;
288631
+ if (!measurement.type || measurement.type === "px" || measurement.type === "pixel")
288632
+ return {
288633
+ width: raw,
288634
+ type: measurement.type ?? "px"
288635
+ };
288636
+ if (measurement.type === "dxa")
288637
+ return {
288638
+ width: twipsToPx$2(raw),
288639
+ type: "dxa"
288640
+ };
288641
+ return {
288642
+ width: raw,
288643
+ type: measurement.type
288644
+ };
288645
+ }, normalizeTableSpacing = (value) => {
288646
+ if (!value || typeof value !== "object")
288647
+ return;
288648
+ const measurement = value;
288649
+ if (typeof measurement.value !== "number")
288650
+ return;
288651
+ return {
288652
+ value: measurement.value,
288653
+ type: measurement.type ?? "px"
288654
+ };
288655
+ }, isTableRowNode = (node3) => node3.type === "tableRow" || node3.type === "table_row", isTableCellNode = (node3) => node3.type === "tableCell" || node3.type === "table_cell" || node3.type === "tableHeader" || node3.type === "table_header", isTableSkipPlaceholderCell = (node3) => {
288656
+ const placeholder = node3.attrs?.__placeholder;
288657
+ return placeholder === "gridBefore" || placeholder === "gridAfter";
288658
+ }, convertResolvedCellBorder = (value) => {
287122
288659
  if (!value || typeof value !== "object")
287123
288660
  return;
287124
288661
  const border = value;
@@ -287386,6 +288923,8 @@ menclose::after {
287386
288923
  const cells = [];
287387
288924
  const rowCnfStyle = rowNode.attrs?.tableRowProperties?.cnfStyle;
287388
288925
  rowNode.content.forEach((cellNode, cellIndex) => {
288926
+ if (isTableCellNode(cellNode) && isTableSkipPlaceholderCell(cellNode))
288927
+ return;
287389
288928
  const parsedCell = parseTableCell({
287390
288929
  cellNode,
287391
288930
  rowIndex,
@@ -287736,7 +289275,7 @@ menclose::after {
287736
289275
  return true;
287737
289276
  }
287738
289277
  return false;
287739
- }, capitalizeText$2 = (text5) => {
289278
+ }, capitalizeText$3 = (text5) => {
287740
289279
  if (!text5)
287741
289280
  return text5;
287742
289281
  let result = "";
@@ -287746,7 +289285,7 @@ menclose::after {
287746
289285
  result += isWordChar$3(ch) && !isWordChar$3(prevChar) ? ch.toUpperCase() : ch;
287747
289286
  }
287748
289287
  return result;
287749
- }, applyTextTransform$2 = (text5, transform) => {
289288
+ }, applyTextTransform$3 = (text5, transform) => {
287750
289289
  if (!text5 || !transform || transform === "none")
287751
289290
  return text5;
287752
289291
  if (transform === "uppercase")
@@ -287754,7 +289293,7 @@ menclose::after {
287754
289293
  if (transform === "lowercase")
287755
289294
  return text5.toLowerCase();
287756
289295
  if (transform === "capitalize")
287757
- return capitalizeText$2(text5);
289296
+ return capitalizeText$3(text5);
287758
289297
  return text5;
287759
289298
  }, countSpaces = (text5) => {
287760
289299
  let spaces = 0;
@@ -288542,7 +290081,7 @@ menclose::after {
288542
290081
  return false;
288543
290082
  const code7 = char.charCodeAt(0);
288544
290083
  return code7 >= 48 && code7 <= 57 || code7 >= 65 && code7 <= 90 || code7 >= 97 && code7 <= 122 || char === "'";
288545
- }, capitalizeText$1 = (text5, fullText, startOffset) => {
290084
+ }, capitalizeText$2 = (text5, fullText, startOffset) => {
288546
290085
  if (!text5)
288547
290086
  return text5;
288548
290087
  const hasFullText = typeof startOffset === "number" && fullText != null;
@@ -288553,7 +290092,7 @@ menclose::after {
288553
290092
  result += isWordChar$1(ch) && !isWordChar$1(prevChar) ? ch.toUpperCase() : ch;
288554
290093
  }
288555
290094
  return result;
288556
- }, applyTextTransform$1 = (text5, transform, fullText, startOffset) => {
290095
+ }, applyTextTransform$2 = (text5, transform, fullText, startOffset) => {
288557
290096
  if (!text5 || !transform || transform === "none")
288558
290097
  return text5;
288559
290098
  if (transform === "uppercase")
@@ -288561,9 +290100,9 @@ menclose::after {
288561
290100
  if (transform === "lowercase")
288562
290101
  return text5.toLowerCase();
288563
290102
  if (transform === "capitalize")
288564
- return capitalizeText$1(text5, fullText, startOffset);
290103
+ return capitalizeText$2(text5, fullText, startOffset);
288565
290104
  return text5;
288566
- }, DEFAULT_TAB_INTERVAL_TWIPS$1 = 720, TWIPS_PER_PX$1, TAB_EPSILON$1 = 0.1, WIDTH_FUDGE_PX = 0.5, twipsToPx$1 = (twips) => twips / TWIPS_PER_PX$1, pxToTwips$1 = (px) => Math.round(px * TWIPS_PER_PX$1), sanitizeIndent$1 = (value) => typeof value === "number" && Number.isFinite(value) ? Math.max(0, value) : 0, sanitizeDecimalSeparator$1 = (value) => value === "," ? "," : ".", getRunWidth = (run2) => {
290105
+ }, DEFAULT_TAB_INTERVAL_TWIPS$1 = 720, TWIPS_PER_PX$2, TAB_EPSILON$1 = 0.1, WIDTH_FUDGE_PX = 0.5, twipsToPx$1 = (twips) => twips / TWIPS_PER_PX$2, pxToTwips$1 = (px) => Math.round(px * TWIPS_PER_PX$2), sanitizeIndent$1 = (value) => typeof value === "number" && Number.isFinite(value) ? Math.max(0, value) : 0, sanitizeDecimalSeparator$1 = (value) => value === "," ? "," : ".", getRunWidth = (run2) => {
288567
290106
  const width = run2.width;
288568
290107
  return typeof width === "number" ? width : 0;
288569
290108
  }, isLineBreakRun$1 = (run2) => run2.kind === "lineBreak" || run2.kind === "break" && run2.breakType === "line", markerFontString = (run2) => {
@@ -289342,7 +290881,9 @@ menclose::after {
289342
290881
  let columnIndex = 0;
289343
290882
  if (columns && columns.count > 1 && page) {
289344
290883
  const fragment2 = findFragmentForPos(page, ref$1.pos);
289345
- if (fragment2 && typeof fragment2.x === "number") {
290884
+ if (fragment2?.kind === "table" && typeof fragment2.columnIndex === "number")
290885
+ columnIndex = Math.max(0, Math.min(columns.count - 1, fragment2.columnIndex));
290886
+ else if (fragment2 && typeof fragment2.x === "number") {
289346
290887
  const widths = Array.isArray(columns.widths) && columns.widths.length > 0 ? columns.widths : undefined;
289347
290888
  if (widths) {
289348
290889
  let cursorX = columns.left;
@@ -289944,6 +291485,12 @@ menclose::after {
289944
291485
  const relative = fragmentX;
289945
291486
  const raw = Math.floor(relative / Math.max(span, 1));
289946
291487
  return Math.max(0, Math.min(columns.count - 1, raw));
291488
+ }, determineTableColumn = (layout, fragment2) => {
291489
+ if (typeof fragment2.columnIndex === "number") {
291490
+ const count2 = layout.columns?.count ?? 1;
291491
+ return Math.max(0, Math.min(Math.max(0, count2 - 1), fragment2.columnIndex));
291492
+ }
291493
+ return determineColumn(layout, fragment2.x);
289947
291494
  }, findLineIndexAtY = (lines, offsetY, fromLine, toLine) => {
289948
291495
  if (!lines || lines.length === 0)
289949
291496
  return null;
@@ -290163,13 +291710,13 @@ menclose::after {
290163
291710
  if (startA == null)
290164
291711
  return false;
290165
291712
  return (endA ?? startA + 1) > startB && startA < endB;
290166
- }, DEFAULT_CELL_PADDING$1, getCellPaddingFromRow = (cellIdx, row2) => {
291713
+ }, DEFAULT_CELL_PADDING$2, getCellPaddingFromRow = (cellIdx, row2) => {
290167
291714
  const padding = row2?.cells?.[cellIdx]?.attrs?.padding ?? {};
290168
291715
  return {
290169
- top: padding.top ?? DEFAULT_CELL_PADDING$1.top,
290170
- bottom: padding.bottom ?? DEFAULT_CELL_PADDING$1.bottom,
290171
- left: padding.left ?? DEFAULT_CELL_PADDING$1.left,
290172
- right: padding.right ?? DEFAULT_CELL_PADDING$1.right
291716
+ top: padding.top ?? DEFAULT_CELL_PADDING$2.top,
291717
+ bottom: padding.bottom ?? DEFAULT_CELL_PADDING$2.bottom,
291718
+ left: padding.left ?? DEFAULT_CELL_PADDING$2.left,
291719
+ right: padding.right ?? DEFAULT_CELL_PADDING$2.right
290173
291720
  };
290174
291721
  }, getCellBlocks = (cell2) => {
290175
291722
  if (!cell2)
@@ -294649,7 +296196,41 @@ menclose::after {
294649
296196
  }
294650
296197
  }, EMUS_PER_INCH = 914400, maxSize = 5000, cache, makeKey = (text5, font, letterSpacing) => {
294651
296198
  return `${text5}|${font}|${letterSpacing || 0}`;
294652
- }, fontMetricsCache, MAX_CACHE_SIZE = 1000, METRICS_TEST_STRING = "MHgypbdlÁÉÍ", computeTabStops, measurementConfig, canvasContext = null, DEFAULT_TAB_INTERVAL_TWIPS = 720, TWIPS_PER_PX, twipsToPx = (twips) => twips / TWIPS_PER_PX, pxToTwips = (px) => Math.round(px * TWIPS_PER_PX), DEFAULT_TAB_INTERVAL_PX, TAB_EPSILON = 0.1, DEFAULT_CELL_PADDING, DEFAULT_DECIMAL_SEPARATOR = ".", ALLOWED_TAB_VALS, FIELD_ANNOTATION_PILL_PADDING = 8, FIELD_ANNOTATION_LINE_HEIGHT_MULTIPLIER = 1.2, FIELD_ANNOTATION_VERTICAL_PADDING = 6, DEFAULT_FIELD_ANNOTATION_FONT_SIZE = 16, DEFAULT_PARAGRAPH_FONT_SIZE = 12, DEFAULT_PARAGRAPH_FONT_FAMILY = "Arial", isValidFontSize = (value) => typeof value === "number" && Number.isFinite(value) && value > 0, normalizeFontSize = (value, fallback = DEFAULT_PARAGRAPH_FONT_SIZE) => {
296199
+ }, fontMetricsCache, MAX_CACHE_SIZE = 1000, METRICS_TEST_STRING = "MHgypbdlÁÉÍ", DEFAULT_MIN_COLUMN_WIDTH = 8, TWIPS_PER_PX$1 = 15, PLACEHOLDER_COLUMN_MAX_WIDTH = 1, DEFAULT_CELL_PADDING$1, DEFAULT_FIELD_ANNOTATION_FONT_SIZE$1 = 16, FIELD_ANNOTATION_PILL_PADDING$1 = 8, TABLE_CELL_METRICS_CACHE_SIZE = 2000, TABLE_AUTOFIT_RESULT_CACHE_SIZE = 500, NO_WRAP_MAX_WIDTH, TOKEN_BOUNDARY_PATTERN, LruCache = class {
296200
+ constructor(maxSize$1) {
296201
+ this.cache = /* @__PURE__ */ new Map;
296202
+ this.maxSize = maxSize$1;
296203
+ }
296204
+ get(key2) {
296205
+ const hit = this.cache.get(key2);
296206
+ if (!hit)
296207
+ return;
296208
+ this.cache.delete(key2);
296209
+ this.cache.set(key2, hit);
296210
+ return hit.value;
296211
+ }
296212
+ set(key2, value) {
296213
+ this.cache.set(key2, { value });
296214
+ this.evictIfNeeded();
296215
+ }
296216
+ clear() {
296217
+ this.cache.clear();
296218
+ }
296219
+ resize(nextSize) {
296220
+ if (!Number.isFinite(nextSize) || nextSize <= 0)
296221
+ return;
296222
+ this.maxSize = nextSize;
296223
+ this.evictIfNeeded();
296224
+ }
296225
+ evictIfNeeded() {
296226
+ while (this.cache.size > this.maxSize) {
296227
+ const oldestKey = this.cache.keys().next().value;
296228
+ if (oldestKey === undefined)
296229
+ break;
296230
+ this.cache.delete(oldestKey);
296231
+ }
296232
+ }
296233
+ }, tableCellMetricsCache, autoFitTableResultCache, canvasContext$1 = null, computeTabStops, measurementConfig, canvasContext = null, DEFAULT_TAB_INTERVAL_TWIPS = 720, TWIPS_PER_PX, twipsToPx = (twips) => twips / TWIPS_PER_PX, pxToTwips = (px) => Math.round(px * TWIPS_PER_PX), DEFAULT_TAB_INTERVAL_PX, TAB_EPSILON = 0.1, DEFAULT_CELL_PADDING, DEFAULT_DECIMAL_SEPARATOR = ".", ALLOWED_TAB_VALS, FIELD_ANNOTATION_PILL_PADDING = 8, FIELD_ANNOTATION_LINE_HEIGHT_MULTIPLIER = 1.2, FIELD_ANNOTATION_VERTICAL_PADDING = 6, DEFAULT_FIELD_ANNOTATION_FONT_SIZE = 16, DEFAULT_PARAGRAPH_FONT_SIZE = 12, DEFAULT_PARAGRAPH_FONT_FAMILY = "Arial", isValidFontSize = (value) => typeof value === "number" && Number.isFinite(value) && value > 0, normalizeFontSize = (value, fallback = DEFAULT_PARAGRAPH_FONT_SIZE) => {
294653
296234
  if (isValidFontSize(value))
294654
296235
  return value;
294655
296236
  if (typeof value === "string") {
@@ -296480,12 +298061,12 @@ menclose::after {
296480
298061
  return;
296481
298062
  console.log(...args$1);
296482
298063
  }, HEADER_FOOTER_INIT_BUDGET_MS = 200, MAX_ZOOM_WARNING_THRESHOLD = 10, MAX_SELECTION_RECTS_PER_USER = 100, SEMANTIC_RESIZE_DEBOUNCE_MS = 120, MIN_SEMANTIC_CONTENT_WIDTH_PX = 1, GLOBAL_PERFORMANCE, PresentationEditor, ICONS, TEXTS, tableActionsOptions;
296483
- var init_src_CCV76OsP_es = __esm(() => {
298064
+ var init_src_Dinif16O_es = __esm(() => {
296484
298065
  init_rolldown_runtime_Bg48TavK_es();
296485
- init_SuperConverter_BTy5lByv_es();
298066
+ init_SuperConverter_Dchjy0My_es();
296486
298067
  init_jszip_C49i9kUs_es();
296487
298068
  init_uuid_qzgm05fK_es();
296488
- init_create_headless_toolbar_k6nNYL53_es();
298069
+ init_create_headless_toolbar_CEcVKzGV_es();
296489
298070
  init_constants_DrU4EASo_es();
296490
298071
  init_dist_B8HfvhaK_es();
296491
298072
  init_unified_Dsuw2be5_es();
@@ -296511,6 +298092,7 @@ var init_src_CCV76OsP_es = __esm(() => {
296511
298092
  measureRowHeights: () => measureRowHeights,
296512
298093
  resolveColumnWidths: () => resolveColumnWidths,
296513
298094
  resolveSpacingIndent: () => resolveSpacingIndent,
298095
+ resolveTableWidthAttr: () => resolveTableWidthAttr,
296514
298096
  scaleWrapPolygon: () => scaleWrapPolygon
296515
298097
  }, 1);
296516
298098
  floor4 = Math.floor;
@@ -313863,19 +315445,69 @@ function print() { __p += __j.call(arguments, '') }
313863
315445
  valid = false;
313864
315446
  docSize = 0;
313865
315447
  doc = null;
313866
- build(doc$12) {
313867
- this.text = doc$12.textBetween(0, doc$12.content.size, BLOCK_SEPARATOR, ATOM_PLACEHOLDER);
315448
+ searchModel = DEFAULT_SEARCH_MODEL$1;
315449
+ build(doc$12, options = {}) {
315450
+ const searchModel = options?.searchModel === "visible" ? "visible" : DEFAULT_SEARCH_MODEL$1;
315451
+ if (searchModel === "visible")
315452
+ this.#buildVisible(doc$12);
315453
+ else
315454
+ this.text = doc$12.textBetween(0, doc$12.content.size, BLOCK_SEPARATOR, ATOM_PLACEHOLDER);
313868
315455
  this.segments = [];
313869
315456
  this.docSize = doc$12.content.size;
313870
315457
  this.doc = doc$12;
315458
+ this.searchModel = searchModel;
313871
315459
  let offset$1 = 0;
315460
+ const visibleContext = searchModel === "visible" ? { deletionBarrierActive: false } : null;
313872
315461
  this.#walkNodeContent(doc$12, 0, offset$1, (segment) => {
313873
315462
  this.segments.push(segment);
313874
315463
  offset$1 = segment.offsetEnd;
313875
- });
315464
+ }, searchModel, visibleContext);
313876
315465
  this.valid = true;
313877
315466
  }
313878
- #walkNodeContent(node3, contentStart, offset$1, addSegment) {
315467
+ #buildVisible(doc$12) {
315468
+ const parts = [];
315469
+ let emittedDeletionBarrier = false;
315470
+ const appendDeletionBarrier = () => {
315471
+ if (emittedDeletionBarrier)
315472
+ return;
315473
+ parts.push(DELETION_BARRIER);
315474
+ emittedDeletionBarrier = true;
315475
+ };
315476
+ const walkNodeContent2 = (node3) => {
315477
+ let isFirstChild = true;
315478
+ node3.forEach((child) => {
315479
+ if (child.isBlock && !isFirstChild) {
315480
+ parts.push(BLOCK_SEPARATOR);
315481
+ emittedDeletionBarrier = false;
315482
+ }
315483
+ walkNode2(child);
315484
+ isFirstChild = false;
315485
+ });
315486
+ };
315487
+ const walkNode2 = (node3) => {
315488
+ if (node3.isText) {
315489
+ const text5 = node3.text || "";
315490
+ if (!text5.length)
315491
+ return;
315492
+ if (hasTrackDeleteMark$1(node3)) {
315493
+ appendDeletionBarrier();
315494
+ return;
315495
+ }
315496
+ parts.push(text5);
315497
+ emittedDeletionBarrier = false;
315498
+ return;
315499
+ }
315500
+ if (node3.isLeaf) {
315501
+ parts.push(ATOM_PLACEHOLDER);
315502
+ emittedDeletionBarrier = false;
315503
+ return;
315504
+ }
315505
+ walkNodeContent2(node3);
315506
+ };
315507
+ walkNodeContent2(doc$12);
315508
+ this.text = parts.join("");
315509
+ }
315510
+ #walkNodeContent(node3, contentStart, offset$1, addSegment, searchModel = DEFAULT_SEARCH_MODEL$1, context = null) {
313879
315511
  let currentOffset = offset$1;
313880
315512
  let isFirstChild = true;
313881
315513
  node3.forEach((child, childContentOffset) => {
@@ -313889,16 +315521,34 @@ function print() { __p += __j.call(arguments, '') }
313889
315521
  kind: "blockSep"
313890
315522
  });
313891
315523
  currentOffset += 1;
315524
+ if (context && searchModel === "visible")
315525
+ context.deletionBarrierActive = false;
313892
315526
  }
313893
- currentOffset = this.#walkNode(child, childDocPos, currentOffset, addSegment);
315527
+ currentOffset = this.#walkNode(child, childDocPos, currentOffset, addSegment, searchModel, context);
313894
315528
  isFirstChild = false;
313895
315529
  });
313896
315530
  return currentOffset;
313897
315531
  }
313898
- #walkNode(node3, docPos, offset$1, addSegment) {
315532
+ #walkNode(node3, docPos, offset$1, addSegment, searchModel = DEFAULT_SEARCH_MODEL$1, context = null) {
313899
315533
  if (node3.isText) {
315534
+ if (searchModel === "visible" && hasTrackDeleteMark$1(node3)) {
315535
+ if (context?.deletionBarrierActive)
315536
+ return offset$1;
315537
+ addSegment({
315538
+ offsetStart: offset$1,
315539
+ offsetEnd: offset$1 + 1,
315540
+ docFrom: docPos,
315541
+ docTo: docPos,
315542
+ kind: "atom"
315543
+ });
315544
+ if (context)
315545
+ context.deletionBarrierActive = true;
315546
+ return offset$1 + 1;
315547
+ }
313900
315548
  const text5 = node3.text || "";
313901
315549
  if (text5.length > 0) {
315550
+ if (context && searchModel === "visible")
315551
+ context.deletionBarrierActive = false;
313902
315552
  addSegment({
313903
315553
  offsetStart: offset$1,
313904
315554
  offsetEnd: offset$1 + text5.length,
@@ -313911,6 +315561,8 @@ function print() { __p += __j.call(arguments, '') }
313911
315561
  return offset$1;
313912
315562
  }
313913
315563
  if (node3.isLeaf) {
315564
+ if (context && searchModel === "visible")
315565
+ context.deletionBarrierActive = false;
313914
315566
  if (node3.type.name === "hard_break") {
313915
315567
  addSegment({
313916
315568
  offsetStart: offset$1,
@@ -313930,17 +315582,18 @@ function print() { __p += __j.call(arguments, '') }
313930
315582
  });
313931
315583
  return offset$1 + 1;
313932
315584
  }
313933
- return this.#walkNodeContent(node3, docPos + 1, offset$1, addSegment);
315585
+ return this.#walkNodeContent(node3, docPos + 1, offset$1, addSegment, searchModel, context);
313934
315586
  }
313935
315587
  invalidate() {
313936
315588
  this.valid = false;
313937
315589
  }
313938
- isStale(doc$12) {
313939
- return !this.valid || this.doc !== doc$12;
315590
+ isStale(doc$12, options = {}) {
315591
+ const searchModel = options?.searchModel === "visible" ? "visible" : DEFAULT_SEARCH_MODEL$1;
315592
+ return !this.valid || this.doc !== doc$12 || this.searchModel !== searchModel;
313940
315593
  }
313941
- ensureValid(doc$12) {
313942
- if (this.isStale(doc$12))
313943
- this.build(doc$12);
315594
+ ensureValid(doc$12, options = {}) {
315595
+ if (this.isStale(doc$12, options))
315596
+ this.build(doc$12, options);
313944
315597
  }
313945
315598
  offsetRangeToDocRanges(start$1, end$1) {
313946
315599
  const ranges = [];
@@ -314090,7 +315743,8 @@ function print() { __p += __j.call(arguments, '') }
314090
315743
  activeMatchIndex: -1,
314091
315744
  query: "",
314092
315745
  caseSensitive: false,
314093
- ignoreDiacritics: false
315746
+ ignoreDiacritics: false,
315747
+ searchModel: DEFAULT_SEARCH_MODEL
314094
315748
  };
314095
315749
  },
314096
315750
  addPmPlugins() {
@@ -314104,8 +315758,11 @@ function print() { __p += __j.call(arguments, '') }
314104
315758
  if (storage?.searchIndex)
314105
315759
  storage.searchIndex.invalidate();
314106
315760
  if (storage?.query) {
314107
- storage.searchIndex.ensureValid(newState.doc);
314108
- const indexMatches = (storage.ignoreDiacritics ? (q$1, opts) => storage.searchIndex.searchIgnoringDiacritics(q$1, opts) : (q$1, opts) => storage.searchIndex.search(q$1, opts))(storage.query, { caseSensitive: storage.caseSensitive });
315761
+ storage.searchIndex.ensureValid(newState.doc, { searchModel: storage.searchModel ?? DEFAULT_SEARCH_MODEL });
315762
+ const indexMatches = (storage.ignoreDiacritics ? (q$1, opts) => storage.searchIndex.searchIgnoringDiacritics(q$1, opts) : (q$1, opts) => storage.searchIndex.search(q$1, opts))(storage.query, {
315763
+ caseSensitive: storage.caseSensitive,
315764
+ searchModel: storage.searchModel ?? DEFAULT_SEARCH_MODEL
315765
+ });
314109
315766
  const refreshed = mapIndexMatchesToDocMatches({
314110
315767
  searchIndex: storage.searchIndex,
314111
315768
  indexMatches,
@@ -314203,11 +315860,12 @@ function print() { __p += __j.call(arguments, '') }
314203
315860
  } catch {}
314204
315861
  return true;
314205
315862
  },
314206
- search: (patternInput, options = {}) => ({ state, dispatch, editor }) => {
315863
+ search: (patternInput, options = {}) => ({ state, editor }) => {
314207
315864
  if (options != null && (typeof options !== "object" || Array.isArray(options)))
314208
315865
  throw new TypeError("Search options must be an object");
314209
315866
  const highlight = typeof options?.highlight === "boolean" ? options.highlight : true;
314210
315867
  const maxMatches = typeof options?.maxMatches === "number" ? options.maxMatches : 1000;
315868
+ const searchModel = normalizeSearchModel(options?.searchModel);
314211
315869
  let caseSensitive = false;
314212
315870
  let searchPattern = patternInput;
314213
315871
  if (isRegExp2(patternInput)) {
@@ -314224,12 +315882,14 @@ function print() { __p += __j.call(arguments, '') }
314224
315882
  const positionTracker = getPositionTracker(editor);
314225
315883
  positionTracker?.untrackByType?.(SEARCH_POSITION_TRACKER_TYPE);
314226
315884
  const searchIndex = this.storage.searchIndex;
314227
- searchIndex.ensureValid(state.doc);
315885
+ searchIndex.ensureValid(state.doc, { searchModel });
315886
+ this.storage.searchModel = searchModel;
314228
315887
  const resultMatches = mapIndexMatchesToDocMatches({
314229
315888
  searchIndex,
314230
315889
  indexMatches: searchIndex.search(searchPattern, {
314231
315890
  caseSensitive,
314232
- maxMatches
315891
+ maxMatches,
315892
+ searchModel
314233
315893
  }),
314234
315894
  doc: state.doc,
314235
315895
  positionTracker
@@ -314274,9 +315934,11 @@ function print() { __p += __j.call(arguments, '') }
314274
315934
  const caseSensitive = options.caseSensitive ?? false;
314275
315935
  const ignoreDiacritics = options.ignoreDiacritics ?? false;
314276
315936
  const highlight = options.highlight ?? true;
315937
+ const searchModel = normalizeSearchModel(options.searchModel);
314277
315938
  this.storage.query = query2;
314278
315939
  this.storage.caseSensitive = caseSensitive;
314279
315940
  this.storage.ignoreDiacritics = ignoreDiacritics;
315941
+ this.storage.searchModel = searchModel;
314280
315942
  const positionTracker = getPositionTracker(editor);
314281
315943
  positionTracker?.untrackByType?.(SEARCH_POSITION_TRACKER_TYPE);
314282
315944
  if (!query2) {
@@ -314289,10 +315951,16 @@ function print() { __p += __j.call(arguments, '') }
314289
315951
  };
314290
315952
  }
314291
315953
  const searchIndex = this.storage.searchIndex;
314292
- searchIndex.ensureValid(state.doc);
315954
+ searchIndex.ensureValid(state.doc, { searchModel });
314293
315955
  const resultMatches = mapIndexMatchesToDocMatches({
314294
315956
  searchIndex,
314295
- indexMatches: ignoreDiacritics ? searchIndex.searchIgnoringDiacritics(query2, { caseSensitive }) : searchIndex.search(query2, { caseSensitive }),
315957
+ indexMatches: ignoreDiacritics ? searchIndex.searchIgnoringDiacritics(query2, {
315958
+ caseSensitive,
315959
+ searchModel
315960
+ }) : searchIndex.search(query2, {
315961
+ caseSensitive,
315962
+ searchModel
315963
+ }),
314296
315964
  doc: state.doc,
314297
315965
  positionTracker
314298
315966
  });
@@ -314312,9 +315980,10 @@ function print() { __p += __j.call(arguments, '') }
314312
315980
  this.storage.query = "";
314313
315981
  this.storage.caseSensitive = false;
314314
315982
  this.storage.ignoreDiacritics = false;
315983
+ this.storage.searchModel = DEFAULT_SEARCH_MODEL;
314315
315984
  return true;
314316
315985
  },
314317
- nextSearchMatch: () => ({ state, editor }) => {
315986
+ nextSearchMatch: () => ({ editor }) => {
314318
315987
  const matches2 = this.storage.searchResults;
314319
315988
  if (!matches2 || matches2.length === 0)
314320
315989
  return {
@@ -314330,7 +315999,7 @@ function print() { __p += __j.call(arguments, '') }
314330
315999
  match: match$1
314331
316000
  };
314332
316001
  },
314333
- previousSearchMatch: () => ({ state, editor }) => {
316002
+ previousSearchMatch: () => ({ editor }) => {
314334
316003
  const matches2 = this.storage.searchResults;
314335
316004
  if (!matches2 || matches2.length === 0)
314336
316005
  return {
@@ -314346,7 +316015,7 @@ function print() { __p += __j.call(arguments, '') }
314346
316015
  match: match$1
314347
316016
  };
314348
316017
  },
314349
- replaceSearchMatch: (replacement) => ({ state, dispatch, editor, commands: commands$1 }) => {
316018
+ replaceSearchMatch: (replacement) => ({ state, dispatch, commands: commands$1 }) => {
314350
316019
  const matches2 = this.storage.searchResults;
314351
316020
  const activeIdx = this.storage.activeMatchIndex;
314352
316021
  if (!matches2 || activeIdx < 0 || activeIdx >= matches2.length)
@@ -314368,7 +316037,8 @@ function print() { __p += __j.call(arguments, '') }
314368
316037
  const result = commands$1.setSearchSession(this.storage.query, {
314369
316038
  caseSensitive: this.storage.caseSensitive,
314370
316039
  ignoreDiacritics: this.storage.ignoreDiacritics,
314371
- highlight: this.storage.highlightEnabled
316040
+ highlight: this.storage.highlightEnabled,
316041
+ searchModel: this.storage.searchModel
314372
316042
  });
314373
316043
  if (result.matches.length > 0) {
314374
316044
  const newIdx = Math.min(activeIdx, result.matches.length - 1);
@@ -323099,7 +324769,7 @@ function print() { __p += __j.call(arguments, '') }
323099
324769
  "even",
323100
324770
  "odd"
323101
324771
  ];
323102
- TWIPS_PER_PX$1 = 1440 / 96;
324772
+ TWIPS_PER_PX$2 = 1440 / 96;
323103
324773
  init_dist4();
323104
324774
  measureCache = new MeasureCache;
323105
324775
  headerMeasureCache = new HeaderFooterLayoutCache;
@@ -323128,7 +324798,7 @@ function print() { __p += __j.call(arguments, '') }
323128
324798
  workerRoundTrip: 10,
323129
324799
  layoutStaleness: 100
323130
324800
  });
323131
- DEFAULT_CELL_PADDING$1 = {
324801
+ DEFAULT_CELL_PADDING$2 = {
323132
324802
  top: 0,
323133
324803
  bottom: 0,
323134
324804
  left: 4,
@@ -327735,6 +329405,16 @@ function print() { __p += __j.call(arguments, '') }
327735
329405
  EMUS_PER_INCH / 96;
327736
329406
  cache = /* @__PURE__ */ new Map;
327737
329407
  fontMetricsCache = /* @__PURE__ */ new Map;
329408
+ DEFAULT_CELL_PADDING$1 = {
329409
+ top: 0,
329410
+ right: 4,
329411
+ bottom: 0,
329412
+ left: 4
329413
+ };
329414
+ NO_WRAP_MAX_WIDTH = Number.MAX_SAFE_INTEGER;
329415
+ TOKEN_BOUNDARY_PATTERN = /[ \t\f\v\-\u00ad\u2010\u2012\u2013\u2014\u200b\u2028\u2029]+|\r\n|\r|\n|\u2028|\u2029/gu;
329416
+ tableCellMetricsCache = new LruCache(TABLE_CELL_METRICS_CACHE_SIZE);
329417
+ autoFitTableResultCache = new LruCache(TABLE_AUTOFIT_RESULT_CACHE_SIZE);
327738
329418
  ({ computeTabStops } = engines_exports);
327739
329419
  measurementConfig = {
327740
329420
  mode: "browser",
@@ -333607,11 +335287,11 @@ function print() { __p += __j.call(arguments, '') }
333607
335287
  ];
333608
335288
  });
333609
335289
 
333610
- // ../../packages/superdoc/dist/chunks/create-super-doc-ui-BUfd0WN3.es.js
335290
+ // ../../packages/superdoc/dist/chunks/create-super-doc-ui-HW4PZyuU.es.js
333611
335291
  var ALL_TOOLBAR_COMMAND_IDS, EMPTY_ACTIVE_IDS;
333612
- var init_create_super_doc_ui_BUfd0WN3_es = __esm(() => {
333613
- init_SuperConverter_BTy5lByv_es();
333614
- init_create_headless_toolbar_k6nNYL53_es();
335292
+ var init_create_super_doc_ui_HW4PZyuU_es = __esm(() => {
335293
+ init_SuperConverter_Dchjy0My_es();
335294
+ init_create_headless_toolbar_CEcVKzGV_es();
333615
335295
  ALL_TOOLBAR_COMMAND_IDS = Object.keys(createToolbarRegistry());
333616
335296
  EMPTY_ACTIVE_IDS = Object.freeze([]);
333617
335297
  });
@@ -333629,16 +335309,16 @@ var init_zipper_BxRAi0_5_es = __esm(() => {
333629
335309
 
333630
335310
  // ../../packages/superdoc/dist/super-editor.es.js
333631
335311
  var init_super_editor_es = __esm(() => {
333632
- init_src_CCV76OsP_es();
333633
- init_SuperConverter_BTy5lByv_es();
335312
+ init_src_Dinif16O_es();
335313
+ init_SuperConverter_Dchjy0My_es();
333634
335314
  init_jszip_C49i9kUs_es();
333635
335315
  init_xml_js_CqGKpaft_es();
333636
- init_create_headless_toolbar_k6nNYL53_es();
335316
+ init_create_headless_toolbar_CEcVKzGV_es();
333637
335317
  init_constants_DrU4EASo_es();
333638
335318
  init_dist_B8HfvhaK_es();
333639
335319
  init_unified_Dsuw2be5_es();
333640
335320
  init_DocxZipper_CUX64E5K_es();
333641
- init_create_super_doc_ui_BUfd0WN3_es();
335321
+ init_create_super_doc_ui_HW4PZyuU_es();
333642
335322
  init_ui_CGB3qmy3_es();
333643
335323
  init_eventemitter3_BJrNoN9D_es();
333644
335324
  init_errors_C_DoKMoN_es();