@superdoc-dev/mcp 0.3.0-next.17 → 0.3.0-next.18
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.
- package/dist/index.js +2064 -323
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -51837,7 +51837,7 @@ var init_remark_gfm_BhnWr3yf_es = __esm(() => {
|
|
|
51837
51837
|
emptyOptions2 = {};
|
|
51838
51838
|
});
|
|
51839
51839
|
|
|
51840
|
-
// ../../packages/superdoc/dist/chunks/SuperConverter-
|
|
51840
|
+
// ../../packages/superdoc/dist/chunks/SuperConverter-Dchjy0My.es.js
|
|
51841
51841
|
function getExtensionConfigField(extension$1, field, context = { name: "" }) {
|
|
51842
51842
|
const fieldValue = extension$1.config[field];
|
|
51843
51843
|
if (typeof fieldValue === "function")
|
|
@@ -100334,18 +100334,78 @@ var isRegExp = (value) => {
|
|
|
100334
100334
|
return twipsToPixels(resolveContentWidthTwips() * percent / 100);
|
|
100335
100335
|
}
|
|
100336
100336
|
return null;
|
|
100337
|
+
}, getRawRowGridMetadata = (row) => {
|
|
100338
|
+
const trPr = row?.elements?.find((element) => element.name === "w:trPr");
|
|
100339
|
+
const getChild = (name) => trPr?.elements?.find((element) => element.name === name);
|
|
100340
|
+
const parseCount = (name) => {
|
|
100341
|
+
const rawValue = getChild(name)?.attributes?.["w:val"];
|
|
100342
|
+
const value = typeof rawValue === "number" ? rawValue : Number.parseInt(rawValue || "0", 10);
|
|
100343
|
+
return Number.isFinite(value) && value > 0 ? value : 0;
|
|
100344
|
+
};
|
|
100345
|
+
const parseMeasurement = (name) => {
|
|
100346
|
+
const node2 = getChild(name);
|
|
100347
|
+
if (!node2?.attributes)
|
|
100348
|
+
return null;
|
|
100349
|
+
const rawValue = node2.attributes["w:w"];
|
|
100350
|
+
const value = typeof rawValue === "number" ? rawValue : Number.parseInt(rawValue || "", 10);
|
|
100351
|
+
if (!Number.isFinite(value) || value <= 0)
|
|
100352
|
+
return null;
|
|
100353
|
+
return {
|
|
100354
|
+
value,
|
|
100355
|
+
type: node2.attributes["w:type"] || "dxa"
|
|
100356
|
+
};
|
|
100357
|
+
};
|
|
100358
|
+
return {
|
|
100359
|
+
gridBefore: parseCount("w:gridBefore"),
|
|
100360
|
+
gridAfter: parseCount("w:gridAfter"),
|
|
100361
|
+
wBefore: parseMeasurement("w:wBefore"),
|
|
100362
|
+
wAfter: parseMeasurement("w:wAfter")
|
|
100363
|
+
};
|
|
100337
100364
|
}, countColumnsInRow = (row) => {
|
|
100338
100365
|
if (!row?.elements?.length)
|
|
100339
100366
|
return 0;
|
|
100340
|
-
|
|
100367
|
+
const { gridBefore, gridAfter } = getRawRowGridMetadata(row);
|
|
100368
|
+
return gridBefore + row.elements.reduce((count, element) => {
|
|
100341
100369
|
if (element.name !== "w:tc")
|
|
100342
100370
|
return count;
|
|
100343
100371
|
const gridSpan = element.elements?.find((el) => el.name === "w:tcPr")?.elements?.find((el) => el.name === "w:gridSpan");
|
|
100344
100372
|
const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
|
|
100345
100373
|
return count + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
|
|
100346
|
-
}, 0);
|
|
100347
|
-
}, clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS),
|
|
100348
|
-
|
|
100374
|
+
}, 0) + gridAfter;
|
|
100375
|
+
}, clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS), resolveSkippedColumnSeedWidthsTwips = (measurement, span) => {
|
|
100376
|
+
if (!measurement || !Number.isFinite(span) || span <= 0)
|
|
100377
|
+
return [];
|
|
100378
|
+
const resolvedPx = resolveMeasurementWidthPx(measurement);
|
|
100379
|
+
if (resolvedPx == null || resolvedPx <= 0)
|
|
100380
|
+
return [];
|
|
100381
|
+
const totalTwips = clampColumnWidthTwips(pixelsToTwips(resolvedPx));
|
|
100382
|
+
const baseWidth = Math.floor(totalTwips / span);
|
|
100383
|
+
const remainder = totalTwips - baseWidth * span;
|
|
100384
|
+
return Array.from({ length: span }, (_, index2) => clampColumnWidthTwips(baseWidth + (index2 < remainder ? 1 : 0)));
|
|
100385
|
+
}, buildFallbackColumnWidthTwips = ({ columnCount, totalWidthTwips, rows }) => {
|
|
100386
|
+
const seededWidths = new Array(columnCount).fill(null);
|
|
100387
|
+
for (const row of rows) {
|
|
100388
|
+
const { gridBefore, gridAfter, wBefore, wAfter } = getRawRowGridMetadata(row);
|
|
100389
|
+
if (gridBefore > 0)
|
|
100390
|
+
resolveSkippedColumnSeedWidthsTwips(wBefore, gridBefore).forEach((widthTwips, index2) => {
|
|
100391
|
+
if (index2 < columnCount)
|
|
100392
|
+
seededWidths[index2] = Math.max(seededWidths[index2] ?? 0, widthTwips);
|
|
100393
|
+
});
|
|
100394
|
+
if (gridAfter > 0)
|
|
100395
|
+
resolveSkippedColumnSeedWidthsTwips(wAfter, gridAfter).forEach((widthTwips, index2) => {
|
|
100396
|
+
const targetIndex = columnCount - gridAfter + index2;
|
|
100397
|
+
if (targetIndex >= 0 && targetIndex < columnCount)
|
|
100398
|
+
seededWidths[targetIndex] = Math.max(seededWidths[targetIndex] ?? 0, widthTwips);
|
|
100399
|
+
});
|
|
100400
|
+
}
|
|
100401
|
+
const seededTotalTwips = seededWidths.reduce((sum, widthTwips) => sum + (widthTwips ?? 0), 0);
|
|
100402
|
+
const remainingColumns = seededWidths.filter((widthTwips) => widthTwips == null).length;
|
|
100403
|
+
const minimumRemainingTwips = remainingColumns * MIN_COLUMN_WIDTH_TWIPS;
|
|
100404
|
+
const effectiveTotalTwips = Math.max(totalWidthTwips, seededTotalTwips + minimumRemainingTwips);
|
|
100405
|
+
const defaultRemainingTwips = remainingColumns > 0 ? clampColumnWidthTwips((effectiveTotalTwips - seededTotalTwips) / remainingColumns) : 0;
|
|
100406
|
+
return seededWidths.map((widthTwips) => clampColumnWidthTwips(widthTwips ?? defaultRemainingTwips));
|
|
100407
|
+
}, buildFallbackGridForTable = ({ params, rows, tableWidth, tableWidthMeasurement }) => {
|
|
100408
|
+
const columnCount = rows.reduce((max, row) => Math.max(max, countColumnsInRow(row)), 0);
|
|
100349
100409
|
if (!columnCount)
|
|
100350
100410
|
return null;
|
|
100351
100411
|
const schemaDefaultPx = getSchemaDefaultColumnWidthPx(params);
|
|
@@ -100360,11 +100420,15 @@ var isRegExp = (value) => {
|
|
|
100360
100420
|
totalWidthPx = tableWidth.width;
|
|
100361
100421
|
if (totalWidthPx == null)
|
|
100362
100422
|
totalWidthPx = twipsToPixels(DEFAULT_CONTENT_WIDTH_TWIPS);
|
|
100363
|
-
const
|
|
100364
|
-
const
|
|
100423
|
+
const minimumColumnWidthTwips = clampColumnWidthTwips(pixelsToTwips(minimumColumnWidthPx));
|
|
100424
|
+
const fallbackColumnWidthTwips = buildFallbackColumnWidthTwips({
|
|
100425
|
+
columnCount,
|
|
100426
|
+
totalWidthTwips: Math.max(clampColumnWidthTwips(pixelsToTwips(totalWidthPx)), minimumColumnWidthTwips * columnCount),
|
|
100427
|
+
rows
|
|
100428
|
+
});
|
|
100365
100429
|
return {
|
|
100366
|
-
grid:
|
|
100367
|
-
columnWidths:
|
|
100430
|
+
grid: fallbackColumnWidthTwips.map((columnWidthTwips) => ({ col: clampColumnWidthTwips(columnWidthTwips) })),
|
|
100431
|
+
columnWidths: fallbackColumnWidthTwips.map((columnWidthTwips) => twipsToPixels(columnWidthTwips))
|
|
100368
100432
|
};
|
|
100369
100433
|
}, translator$69, XML_NODE_NAME$26 = "w:tblGrid", SD_ATTR_KEY$2 = "grid", cellMinWidth, encode$43 = (params) => {
|
|
100370
100434
|
const { nodes } = params;
|
|
@@ -104234,7 +104298,7 @@ var isRegExp = (value) => {
|
|
|
104234
104298
|
state.kern = kernNode.attributes["w:val"];
|
|
104235
104299
|
}
|
|
104236
104300
|
}, SuperConverter;
|
|
104237
|
-
var
|
|
104301
|
+
var init_SuperConverter_Dchjy0My_es = __esm(() => {
|
|
104238
104302
|
init_rolldown_runtime_Bg48TavK_es();
|
|
104239
104303
|
init_jszip_C49i9kUs_es();
|
|
104240
104304
|
init_xml_js_CqGKpaft_es();
|
|
@@ -141829,7 +141893,7 @@ var init_SuperConverter_BTy5lByv_es = __esm(() => {
|
|
|
141829
141893
|
};
|
|
141830
141894
|
});
|
|
141831
141895
|
|
|
141832
|
-
// ../../packages/superdoc/dist/chunks/create-headless-toolbar-
|
|
141896
|
+
// ../../packages/superdoc/dist/chunks/create-headless-toolbar-CEcVKzGV.es.js
|
|
141833
141897
|
function parseSizeUnit(val = "0") {
|
|
141834
141898
|
const length = val.toString() || "0";
|
|
141835
141899
|
const value = Number.parseFloat(length);
|
|
@@ -144465,8 +144529,8 @@ var CSS_DIMENSION_REGEX, DOM_SIZE_UNITS, Extension = class Extension2 {
|
|
|
144465
144529
|
}
|
|
144466
144530
|
};
|
|
144467
144531
|
};
|
|
144468
|
-
var
|
|
144469
|
-
|
|
144532
|
+
var init_create_headless_toolbar_CEcVKzGV_es = __esm(() => {
|
|
144533
|
+
init_SuperConverter_Dchjy0My_es();
|
|
144470
144534
|
init_constants_DrU4EASo_es();
|
|
144471
144535
|
init_dist_B8HfvhaK_es();
|
|
144472
144536
|
CSS_DIMENSION_REGEX = /[\d-.]+(\w+)$/;
|
|
@@ -198675,7 +198739,7 @@ var init_remark_gfm_eZN6yzWQ_es = __esm(() => {
|
|
|
198675
198739
|
init_remark_gfm_BhnWr3yf_es();
|
|
198676
198740
|
});
|
|
198677
198741
|
|
|
198678
|
-
// ../../packages/superdoc/dist/chunks/src-
|
|
198742
|
+
// ../../packages/superdoc/dist/chunks/src-Dinif16O.es.js
|
|
198679
198743
|
function deleteProps(obj, propOrProps) {
|
|
198680
198744
|
const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
|
|
198681
198745
|
const removeNested = (target, pathParts, index2 = 0) => {
|
|
@@ -198930,7 +198994,7 @@ function getCellSpacingPx(cellSpacing) {
|
|
|
198930
198994
|
const v = cellSpacing.value;
|
|
198931
198995
|
if (typeof v !== "number" || !Number.isFinite(v))
|
|
198932
198996
|
return 0;
|
|
198933
|
-
const asPx = (cellSpacing.type ?? "").toLowerCase() === "dxa" && v >= 20 ? v / TWIPS_PER_PX$
|
|
198997
|
+
const asPx = (cellSpacing.type ?? "").toLowerCase() === "dxa" && v >= 20 ? v / TWIPS_PER_PX$3 : v;
|
|
198934
198998
|
return Math.max(0, asPx);
|
|
198935
198999
|
}
|
|
198936
199000
|
function coerceRelativeHeight(raw) {
|
|
@@ -226115,29 +226179,12 @@ function toTableFailure(code7, message, details) {
|
|
|
226115
226179
|
}
|
|
226116
226180
|
};
|
|
226117
226181
|
}
|
|
226118
|
-
function createSeparatorParagraph(schema) {
|
|
226119
|
-
const paragraphType = schema.nodes.paragraph;
|
|
226120
|
-
if (!paragraphType)
|
|
226121
|
-
return null;
|
|
226122
|
-
const separatorAttrs = {
|
|
226123
|
-
sdBlockId: v4_default(),
|
|
226124
|
-
paraId: generateDocxHexId()
|
|
226125
|
-
};
|
|
226126
|
-
return paragraphType.createAndFill(separatorAttrs) ?? paragraphType.createAndFill();
|
|
226127
|
-
}
|
|
226128
|
-
function buildTableSuccess(tableAddress, trackedChangeRefs) {
|
|
226129
|
-
return {
|
|
226130
|
-
success: true,
|
|
226131
|
-
table: tableAddress,
|
|
226132
|
-
trackedChangeRefs
|
|
226133
|
-
};
|
|
226134
|
-
}
|
|
226135
226182
|
function syncExtractedTableAttrs(tp) {
|
|
226136
226183
|
const extracted = {};
|
|
226137
226184
|
extracted.tableStyleId = tp.tableStyleId ?? null;
|
|
226138
226185
|
extracted.justification = tp.justification ?? null;
|
|
226139
226186
|
extracted.tableLayout = tp.tableLayout ?? null;
|
|
226140
|
-
extracted.borders = convertTableBordersToPixelUnits(tp.borders) ??
|
|
226187
|
+
extracted.borders = convertTableBordersToPixelUnits(tp.borders) ?? {};
|
|
226141
226188
|
const indent2 = tp.tableIndent;
|
|
226142
226189
|
if (indent2?.value != null)
|
|
226143
226190
|
extracted.tableIndent = {
|
|
@@ -226149,7 +226196,7 @@ function syncExtractedTableAttrs(tp) {
|
|
|
226149
226196
|
const spacing = tp.tableCellSpacing;
|
|
226150
226197
|
if (spacing?.value != null) {
|
|
226151
226198
|
extracted.tableCellSpacing = {
|
|
226152
|
-
|
|
226199
|
+
value: twipsToPixels(spacing.value),
|
|
226153
226200
|
type: spacing.type ?? "dxa"
|
|
226154
226201
|
};
|
|
226155
226202
|
extracted.borderCollapse = "separate";
|
|
@@ -226157,23 +226204,23 @@ function syncExtractedTableAttrs(tp) {
|
|
|
226157
226204
|
extracted.tableCellSpacing = null;
|
|
226158
226205
|
extracted.borderCollapse = null;
|
|
226159
226206
|
}
|
|
226160
|
-
const
|
|
226161
|
-
if (
|
|
226162
|
-
if (
|
|
226207
|
+
const width = tp.tableWidth;
|
|
226208
|
+
if (width)
|
|
226209
|
+
if (width.type === "pct" && typeof width.value === "number")
|
|
226163
226210
|
extracted.tableWidth = {
|
|
226164
|
-
value:
|
|
226211
|
+
value: width.value,
|
|
226165
226212
|
type: "pct"
|
|
226166
226213
|
};
|
|
226167
|
-
else if (
|
|
226214
|
+
else if (width.type === "auto")
|
|
226168
226215
|
extracted.tableWidth = {
|
|
226169
226216
|
width: 0,
|
|
226170
226217
|
type: "auto"
|
|
226171
226218
|
};
|
|
226172
|
-
else if (
|
|
226173
|
-
const widthPx = twipsToPixels(
|
|
226219
|
+
else if (width.value != null) {
|
|
226220
|
+
const widthPx = twipsToPixels(width.value);
|
|
226174
226221
|
extracted.tableWidth = widthPx != null ? {
|
|
226175
226222
|
width: widthPx,
|
|
226176
|
-
type:
|
|
226223
|
+
type: width.type
|
|
226177
226224
|
} : null;
|
|
226178
226225
|
} else
|
|
226179
226226
|
extracted.tableWidth = null;
|
|
@@ -226188,6 +226235,95 @@ function convertTableBordersToPixelUnits(value) {
|
|
|
226188
226235
|
mapBorderSizes(clone2, eighthPointsToPixels);
|
|
226189
226236
|
return Object.keys(clone2).length > 0 ? clone2 : undefined;
|
|
226190
226237
|
}
|
|
226238
|
+
function buildWidthAuthoringTableAttrs(currentAttrs, attrOverrides = {}, tablePropertyOverrides = {}) {
|
|
226239
|
+
const currentTableProps = currentAttrs.tableProperties ?? {};
|
|
226240
|
+
const nextTableWidth = resolveWidthAuthoringTableWidth(currentAttrs, attrOverrides, tablePropertyOverrides);
|
|
226241
|
+
const updatedTableProps = {
|
|
226242
|
+
...currentTableProps,
|
|
226243
|
+
...tablePropertyOverrides,
|
|
226244
|
+
tableLayout: "fixed"
|
|
226245
|
+
};
|
|
226246
|
+
if (nextTableWidth)
|
|
226247
|
+
updatedTableProps.tableWidth = nextTableWidth;
|
|
226248
|
+
else
|
|
226249
|
+
delete updatedTableProps.tableWidth;
|
|
226250
|
+
return {
|
|
226251
|
+
...currentAttrs,
|
|
226252
|
+
tableProperties: updatedTableProps,
|
|
226253
|
+
...attrOverrides,
|
|
226254
|
+
...syncExtractedTableAttrs(updatedTableProps),
|
|
226255
|
+
userEdited: true
|
|
226256
|
+
};
|
|
226257
|
+
}
|
|
226258
|
+
function resolveWidthAuthoringTableWidth(currentAttrs, attrOverrides, tablePropertyOverrides) {
|
|
226259
|
+
const explicitOverride = normalizeTableWidthMeasurement(tablePropertyOverrides.tableWidth);
|
|
226260
|
+
if (explicitOverride)
|
|
226261
|
+
return explicitOverride;
|
|
226262
|
+
const gridWidth = sumGridColumnTwips(attrOverrides.grid ?? currentAttrs.grid);
|
|
226263
|
+
if (gridWidth != null)
|
|
226264
|
+
return {
|
|
226265
|
+
value: gridWidth,
|
|
226266
|
+
type: "dxa"
|
|
226267
|
+
};
|
|
226268
|
+
return null;
|
|
226269
|
+
}
|
|
226270
|
+
function sumGridColumnTwips(grid) {
|
|
226271
|
+
const columns = normalizeGridColumns$1(grid);
|
|
226272
|
+
if (!columns || columns.length === 0)
|
|
226273
|
+
return null;
|
|
226274
|
+
const total = columns.reduce((sum, column) => sum + column.col, 0);
|
|
226275
|
+
return total > 0 ? total : null;
|
|
226276
|
+
}
|
|
226277
|
+
function normalizeGridColumns$1(grid) {
|
|
226278
|
+
if (Array.isArray(grid)) {
|
|
226279
|
+
const columns = grid.map((width) => normalizeGridWidth$1(width)).filter((width) => width != null);
|
|
226280
|
+
return columns.length > 0 ? columns : null;
|
|
226281
|
+
}
|
|
226282
|
+
if (grid && typeof grid === "object") {
|
|
226283
|
+
const rawColWidths = grid.colWidths;
|
|
226284
|
+
if (Array.isArray(rawColWidths)) {
|
|
226285
|
+
const columns = rawColWidths.map((width) => normalizeGridWidth$1(width)).filter((width) => width != null);
|
|
226286
|
+
return columns.length > 0 ? columns : null;
|
|
226287
|
+
}
|
|
226288
|
+
}
|
|
226289
|
+
return null;
|
|
226290
|
+
}
|
|
226291
|
+
function normalizeGridWidth$1(width) {
|
|
226292
|
+
if (typeof width === "number" && Number.isFinite(width) && width > 0)
|
|
226293
|
+
return { col: Math.round(width) };
|
|
226294
|
+
const value = width?.col;
|
|
226295
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0)
|
|
226296
|
+
return { col: Math.round(value) };
|
|
226297
|
+
return null;
|
|
226298
|
+
}
|
|
226299
|
+
function normalizeTableWidthMeasurement(width) {
|
|
226300
|
+
if (!width || typeof width !== "object")
|
|
226301
|
+
return null;
|
|
226302
|
+
const value = width.value;
|
|
226303
|
+
if (width.type !== "dxa" || typeof value !== "number" || !Number.isFinite(value) || value <= 0)
|
|
226304
|
+
return null;
|
|
226305
|
+
return {
|
|
226306
|
+
value: Math.round(value),
|
|
226307
|
+
type: "dxa"
|
|
226308
|
+
};
|
|
226309
|
+
}
|
|
226310
|
+
function createSeparatorParagraph(schema) {
|
|
226311
|
+
const paragraphType = schema.nodes.paragraph;
|
|
226312
|
+
if (!paragraphType)
|
|
226313
|
+
return null;
|
|
226314
|
+
const separatorAttrs = {
|
|
226315
|
+
sdBlockId: v4_default(),
|
|
226316
|
+
paraId: generateDocxHexId()
|
|
226317
|
+
};
|
|
226318
|
+
return paragraphType.createAndFill(separatorAttrs) ?? paragraphType.createAndFill();
|
|
226319
|
+
}
|
|
226320
|
+
function buildTableSuccess(tableAddress, trackedChangeRefs) {
|
|
226321
|
+
return {
|
|
226322
|
+
success: true,
|
|
226323
|
+
table: tableAddress,
|
|
226324
|
+
trackedChangeRefs
|
|
226325
|
+
};
|
|
226326
|
+
}
|
|
226191
226327
|
function normalizeGridWidth(width) {
|
|
226192
226328
|
if (typeof width === "number" && Number.isFinite(width))
|
|
226193
226329
|
return { col: Math.round(width) };
|
|
@@ -226250,6 +226386,30 @@ function removeGridColumnWidth(grid, deleteIndex) {
|
|
|
226250
226386
|
columns: colWidths
|
|
226251
226387
|
});
|
|
226252
226388
|
}
|
|
226389
|
+
function buildFirstRowCellWidthProps(attrs, cellStartCol, colspan, colwidth, gridColumns) {
|
|
226390
|
+
const currentCellProps = attrs.tableCellProperties && typeof attrs.tableCellProperties === "object" ? attrs.tableCellProperties : {};
|
|
226391
|
+
const spanTwips = resolveSpanWidthTwips(cellStartCol, colspan, colwidth, gridColumns);
|
|
226392
|
+
if (spanTwips == null)
|
|
226393
|
+
return Object.keys(currentCellProps).length > 0 ? currentCellProps : undefined;
|
|
226394
|
+
return {
|
|
226395
|
+
...currentCellProps,
|
|
226396
|
+
cellWidth: {
|
|
226397
|
+
value: spanTwips,
|
|
226398
|
+
type: "dxa"
|
|
226399
|
+
}
|
|
226400
|
+
};
|
|
226401
|
+
}
|
|
226402
|
+
function resolveSpanWidthTwips(cellStartCol, colspan, colwidth, gridColumns) {
|
|
226403
|
+
const boundedSpan = Math.max(1, colspan);
|
|
226404
|
+
if (Array.isArray(gridColumns) && cellStartCol >= 0 && cellStartCol + boundedSpan <= gridColumns.length) {
|
|
226405
|
+
const gridSpanTwips = gridColumns.slice(cellStartCol, cellStartCol + boundedSpan).reduce((sum, column) => sum + normalizeGridWidth(column).col, 0);
|
|
226406
|
+
if (gridSpanTwips > 0)
|
|
226407
|
+
return gridSpanTwips;
|
|
226408
|
+
}
|
|
226409
|
+
const spanWidthPx = colwidth.slice(0, boundedSpan).reduce((sum, width) => sum + (Number.isFinite(width) ? width : 0), 0);
|
|
226410
|
+
if (spanWidthPx > 0)
|
|
226411
|
+
return Math.round(spanWidthPx * PIXELS_TO_TWIPS);
|
|
226412
|
+
}
|
|
226253
226413
|
function normalizeCellAttrsForSingleCell(attrs) {
|
|
226254
226414
|
const currentColwidth = Array.isArray(attrs.colwidth) ? attrs.colwidth : null;
|
|
226255
226415
|
const tableCellProperties = { ...attrs.tableCellProperties ?? {} };
|
|
@@ -227127,8 +227287,13 @@ function tablesSetColumnWidthAdapter(editor, input2, options) {
|
|
|
227127
227287
|
const tablePos = table2.candidate.pos;
|
|
227128
227288
|
const tableStart = tablePos + 1;
|
|
227129
227289
|
const tableNode = table2.candidate.node;
|
|
227290
|
+
const tableAttrs = tableNode.attrs;
|
|
227130
227291
|
const map$12 = TableMap.get(tableNode);
|
|
227131
227292
|
const widthPx = Math.round(input2.widthPt * (96 / 72));
|
|
227293
|
+
const normalizedGrid = normalizeGridColumns(tableAttrs.grid);
|
|
227294
|
+
const nextGridColumns = normalizedGrid?.columns.slice();
|
|
227295
|
+
if (nextGridColumns && columnIndex < nextGridColumns.length)
|
|
227296
|
+
nextGridColumns[columnIndex] = { col: Math.round(input2.widthPt * POINTS_TO_TWIPS) };
|
|
227132
227297
|
const processed = /* @__PURE__ */ new Set;
|
|
227133
227298
|
for (let row2 = 0;row2 < map$12.height; row2++) {
|
|
227134
227299
|
const index2 = row2 * map$12.width + columnIndex;
|
|
@@ -227142,29 +227307,31 @@ function tablesSetColumnWidthAdapter(editor, input2, options) {
|
|
|
227142
227307
|
const attrs = cell2.attrs;
|
|
227143
227308
|
const colspan = attrs.colspan || 1;
|
|
227144
227309
|
const colwidth = attrs.colwidth?.slice() ?? [];
|
|
227145
|
-
const
|
|
227310
|
+
const cellStartCol = map$12.colCount(pos);
|
|
227311
|
+
const withinCol = columnIndex - cellStartCol;
|
|
227146
227312
|
while (colwidth.length < colspan)
|
|
227147
227313
|
colwidth.push(0);
|
|
227148
227314
|
colwidth[withinCol] = widthPx;
|
|
227149
|
-
|
|
227315
|
+
const nextAttrs = {
|
|
227150
227316
|
...attrs,
|
|
227151
227317
|
colwidth
|
|
227152
|
-
}
|
|
227318
|
+
};
|
|
227319
|
+
if (row2 === 0) {
|
|
227320
|
+
const nextCellProps = buildFirstRowCellWidthProps(attrs, cellStartCol, colspan, colwidth, nextGridColumns);
|
|
227321
|
+
if (nextCellProps)
|
|
227322
|
+
nextAttrs.tableCellProperties = nextCellProps;
|
|
227323
|
+
else
|
|
227324
|
+
delete nextAttrs.tableCellProperties;
|
|
227325
|
+
}
|
|
227326
|
+
tr.setNodeMarkup(tableStart + pos, null, nextAttrs);
|
|
227153
227327
|
}
|
|
227154
|
-
const
|
|
227155
|
-
|
|
227156
|
-
|
|
227157
|
-
|
|
227158
|
-
|
|
227159
|
-
tr.setNodeMarkup(tablePos, null, {
|
|
227160
|
-
...tableAttrs,
|
|
227161
|
-
grid: serializeGridColumns(tableAttrs.grid, {
|
|
227162
|
-
...normalizedGrid,
|
|
227163
|
-
columns: newColumns
|
|
227164
|
-
}),
|
|
227165
|
-
userEdited: true
|
|
227328
|
+
const tableAttrUpdates = {};
|
|
227329
|
+
if (normalizedGrid && nextGridColumns)
|
|
227330
|
+
tableAttrUpdates.grid = serializeGridColumns(tableAttrs.grid, {
|
|
227331
|
+
...normalizedGrid,
|
|
227332
|
+
columns: nextGridColumns
|
|
227166
227333
|
});
|
|
227167
|
-
|
|
227334
|
+
tr.setNodeMarkup(tablePos, null, buildWidthAuthoringTableAttrs(tableAttrs, tableAttrUpdates));
|
|
227168
227335
|
applyDirectMutationMeta(tr);
|
|
227169
227336
|
editor.dispatch(tr);
|
|
227170
227337
|
clearIndexCache(editor);
|
|
@@ -227188,7 +227355,10 @@ function tablesDistributeColumnsAdapter(editor, input2, options) {
|
|
|
227188
227355
|
const tablePos = candidate.pos;
|
|
227189
227356
|
const tableStart = tablePos + 1;
|
|
227190
227357
|
const tableNode = candidate.node;
|
|
227358
|
+
const tableAttrs = tableNode.attrs;
|
|
227191
227359
|
const map$12 = TableMap.get(tableNode);
|
|
227360
|
+
const normalizedGrid = normalizeGridColumns(tableAttrs.grid);
|
|
227361
|
+
const nextGridColumns = normalizedGrid?.columns.slice();
|
|
227192
227362
|
const rangeStart = input2.columnRange?.start ?? 0;
|
|
227193
227363
|
const rangeEnd = input2.columnRange?.end ?? map$12.width - 1;
|
|
227194
227364
|
const rangeWidth = rangeEnd - rangeStart + 1;
|
|
@@ -227204,6 +227374,12 @@ function tablesDistributeColumnsAdapter(editor, input2, options) {
|
|
|
227204
227374
|
totalWidth += colwidth?.[withinCol] ?? 100;
|
|
227205
227375
|
}
|
|
227206
227376
|
const evenWidth = Math.round(totalWidth / rangeWidth);
|
|
227377
|
+
if (nextGridColumns) {
|
|
227378
|
+
const evenWidthTwips = Math.max(1, Math.round(evenWidth * PIXELS_TO_TWIPS));
|
|
227379
|
+
const maxColumn = Math.min(rangeEnd, nextGridColumns.length - 1);
|
|
227380
|
+
for (let col = Math.max(rangeStart, 0);col <= maxColumn; col++)
|
|
227381
|
+
nextGridColumns[col] = { col: evenWidthTwips };
|
|
227382
|
+
}
|
|
227207
227383
|
const processed = /* @__PURE__ */ new Set;
|
|
227208
227384
|
for (let row2 = 0;row2 < map$12.height; row2++)
|
|
227209
227385
|
for (let col = rangeStart;col <= rangeEnd; col++) {
|
|
@@ -227226,29 +227402,26 @@ function tablesDistributeColumnsAdapter(editor, input2, options) {
|
|
|
227226
227402
|
if (absCol >= rangeStart && absCol <= rangeEnd)
|
|
227227
227403
|
newColwidth[c] = evenWidth;
|
|
227228
227404
|
}
|
|
227229
|
-
|
|
227405
|
+
const nextAttrs = {
|
|
227230
227406
|
...attrs,
|
|
227231
227407
|
colwidth: newColwidth
|
|
227232
|
-
}
|
|
227408
|
+
};
|
|
227409
|
+
if (row2 === 0) {
|
|
227410
|
+
const nextCellProps = buildFirstRowCellWidthProps(attrs, cellStartCol, colspan, newColwidth, nextGridColumns);
|
|
227411
|
+
if (nextCellProps)
|
|
227412
|
+
nextAttrs.tableCellProperties = nextCellProps;
|
|
227413
|
+
else
|
|
227414
|
+
delete nextAttrs.tableCellProperties;
|
|
227415
|
+
}
|
|
227416
|
+
tr.setNodeMarkup(tableStart + pos, null, nextAttrs);
|
|
227233
227417
|
}
|
|
227234
|
-
const
|
|
227235
|
-
|
|
227236
|
-
const tableAttrUpdates = {
|
|
227237
|
-
...tableAttrs,
|
|
227238
|
-
userEdited: true
|
|
227239
|
-
};
|
|
227240
|
-
if (normalizedGrid) {
|
|
227241
|
-
const newColumns = normalizedGrid.columns.slice();
|
|
227242
|
-
const evenWidthTwips = Math.max(1, Math.round(evenWidth * PIXELS_TO_TWIPS));
|
|
227243
|
-
const maxColumn = Math.min(rangeEnd, newColumns.length - 1);
|
|
227244
|
-
for (let col = Math.max(rangeStart, 0);col <= maxColumn; col++)
|
|
227245
|
-
newColumns[col] = { col: evenWidthTwips };
|
|
227418
|
+
const tableAttrUpdates = {};
|
|
227419
|
+
if (normalizedGrid && nextGridColumns)
|
|
227246
227420
|
tableAttrUpdates.grid = serializeGridColumns(tableAttrs.grid, {
|
|
227247
227421
|
...normalizedGrid,
|
|
227248
|
-
columns:
|
|
227422
|
+
columns: nextGridColumns
|
|
227249
227423
|
});
|
|
227250
|
-
|
|
227251
|
-
tr.setNodeMarkup(tablePos, null, tableAttrUpdates);
|
|
227424
|
+
tr.setNodeMarkup(tablePos, null, buildWidthAuthoringTableAttrs(tableAttrs, tableAttrUpdates));
|
|
227252
227425
|
applyDirectMutationMeta(tr);
|
|
227253
227426
|
editor.dispatch(tr);
|
|
227254
227427
|
clearIndexCache(editor);
|
|
@@ -227832,6 +228005,10 @@ function tablesSetCellPropertiesAdapter(editor, input2, options) {
|
|
|
227832
228005
|
}
|
|
227833
228006
|
};
|
|
227834
228007
|
tr.setNodeMarkup(cellPos, null, newAttrs);
|
|
228008
|
+
if (input2.preferredWidthPt !== undefined) {
|
|
228009
|
+
const tableAttrs = table2.candidate.node.attrs;
|
|
228010
|
+
tr.setNodeMarkup(table2.candidate.pos, null, buildWidthAuthoringTableAttrs(tableAttrs));
|
|
228011
|
+
}
|
|
227835
228012
|
applyDirectMutationMeta(tr);
|
|
227836
228013
|
editor.dispatch(tr);
|
|
227837
228014
|
clearIndexCache(editor);
|
|
@@ -242363,7 +242540,7 @@ function normalizeFieldAnnotationMetadata(attrs) {
|
|
|
242363
242540
|
borderColor: normalizeColorValue2(attrs.borderColor),
|
|
242364
242541
|
highlighted: toBoolean$2(attrs.highlighted, true),
|
|
242365
242542
|
fontFamily: toNullableString(attrs.fontFamily),
|
|
242366
|
-
fontSize: normalizeFontSize$
|
|
242543
|
+
fontSize: normalizeFontSize$2(attrs.fontSize),
|
|
242367
242544
|
textColor: normalizeColorValue2(attrs.textColor) ?? null,
|
|
242368
242545
|
textHighlight: normalizeColorValue2(attrs.textHighlight) ?? null,
|
|
242369
242546
|
linkUrl: toNullableString(attrs.linkUrl),
|
|
@@ -242457,7 +242634,7 @@ function normalizeColorValue2(value) {
|
|
|
242457
242634
|
return;
|
|
242458
242635
|
return trimmed;
|
|
242459
242636
|
}
|
|
242460
|
-
function normalizeFontSize$
|
|
242637
|
+
function normalizeFontSize$2(value) {
|
|
242461
242638
|
if (value == null)
|
|
242462
242639
|
return null;
|
|
242463
242640
|
if (typeof value === "number")
|
|
@@ -244059,11 +244236,15 @@ function tableNodeToBlock(node2, { nextBlockId, positions, storyKey, trackedChan
|
|
|
244059
244236
|
tableAttrs.tableWidth = hydratedTableStyle.tableWidth;
|
|
244060
244237
|
if (node2.attrs?.tableIndent && typeof node2.attrs.tableIndent === "object")
|
|
244061
244238
|
tableAttrs.tableIndent = { ...node2.attrs.tableIndent };
|
|
244239
|
+
else if (hydratedTableStyle?.tableIndent)
|
|
244240
|
+
tableAttrs.tableIndent = { ...hydratedTableStyle.tableIndent };
|
|
244062
244241
|
if (defaultCellPadding && typeof defaultCellPadding === "object")
|
|
244063
244242
|
tableAttrs.defaultCellPadding = { ...defaultCellPadding };
|
|
244064
244243
|
const tableLayout = node2.attrs?.tableLayout;
|
|
244065
244244
|
if (tableLayout)
|
|
244066
244245
|
tableAttrs.tableLayout = tableLayout;
|
|
244246
|
+
else if (hydratedTableStyle?.tableLayout)
|
|
244247
|
+
tableAttrs.tableLayout = hydratedTableStyle.tableLayout;
|
|
244067
244248
|
const tableProperties = node2.attrs?.tableProperties;
|
|
244068
244249
|
if (tableProperties && typeof tableProperties === "object")
|
|
244069
244250
|
tableAttrs.tableProperties = tableProperties;
|
|
@@ -248982,7 +249163,7 @@ function measureCharacterX(block, line, charOffset, availableWidthOverride, alig
|
|
|
248982
249163
|
}
|
|
248983
249164
|
const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text ?? "";
|
|
248984
249165
|
const runLength = text5.length;
|
|
248985
|
-
const displayText = applyTextTransform$
|
|
249166
|
+
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);
|
|
248986
249167
|
if (currentCharOffset + runLength >= charOffset) {
|
|
248987
249168
|
const offsetInRun = charOffset - currentCharOffset;
|
|
248988
249169
|
ctx$1.font = getRunFontString(run2);
|
|
@@ -249031,7 +249212,7 @@ function measureCharacterXSegmentBased(block, line, charOffset, ctx$1) {
|
|
|
249031
249212
|
return segmentBaseX + (offsetInSegment > 0 ? segment.width ?? 0 : 0);
|
|
249032
249213
|
if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math")
|
|
249033
249214
|
return segmentBaseX + (offsetInSegment >= segmentChars ? segment.width ?? 0 : 0);
|
|
249034
|
-
const textUpToTarget = applyTextTransform$
|
|
249215
|
+
const textUpToTarget = applyTextTransform$3(run2.text ?? "", "textTransform" in run2 ? run2.textTransform : undefined).slice(segment.fromChar, segment.toChar).slice(0, offsetInSegment);
|
|
249035
249216
|
ctx$1.font = getRunFontString(run2);
|
|
249036
249217
|
const measured = ctx$1.measureText(textUpToTarget);
|
|
249037
249218
|
const spacingWidth = computeLetterSpacingWidth(run2, offsetInSegment, segmentChars);
|
|
@@ -249124,7 +249305,7 @@ function findCharacterAtX(block, line, x, pmStart, availableWidthOverride, align
|
|
|
249124
249305
|
}
|
|
249125
249306
|
const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text ?? "";
|
|
249126
249307
|
const runLength = text5.length;
|
|
249127
|
-
const displayText = applyTextTransform$
|
|
249308
|
+
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);
|
|
249128
249309
|
if (runLength === 0)
|
|
249129
249310
|
continue;
|
|
249130
249311
|
ctx$1.font = getRunFontString(run2);
|
|
@@ -249767,7 +249948,7 @@ function measureRunSliceWidth(run2, fromChar, toChar) {
|
|
|
249767
249948
|
const context = getCtx();
|
|
249768
249949
|
const fullText = runText(run2);
|
|
249769
249950
|
const transform2 = isTextRun$3(run2) ? run2.textTransform : undefined;
|
|
249770
|
-
const text5 = applyTextTransform$
|
|
249951
|
+
const text5 = applyTextTransform$2(fullText.slice(fromChar, toChar), transform2, fullText, fromChar);
|
|
249771
249952
|
if (!context) {
|
|
249772
249953
|
const size$1 = (isTextRun$3(run2) ? run2 : null)?.fontSize ?? 16;
|
|
249773
249954
|
return Math.max(1, text5.length * (size$1 * 0.6));
|
|
@@ -253034,7 +253215,7 @@ function areNumberListsEqual(left$1, right$1) {
|
|
|
253034
253215
|
return false;
|
|
253035
253216
|
return true;
|
|
253036
253217
|
}
|
|
253037
|
-
function isWordCharacter(char) {
|
|
253218
|
+
function isWordCharacter$1(char) {
|
|
253038
253219
|
if (!char)
|
|
253039
253220
|
return false;
|
|
253040
253221
|
return WORD_CHARACTER_REGEX.test(char);
|
|
@@ -253117,17 +253298,17 @@ function computeWordSelectionRangeAt(state, pos) {
|
|
|
253117
253298
|
const parentStart = textblockPos.start();
|
|
253118
253299
|
const parentEnd = textblockPos.end();
|
|
253119
253300
|
const sampleEnd = Math.min(pos + 1, parentEnd);
|
|
253120
|
-
if (!isWordCharacter(state.doc.textBetween(pos, sampleEnd, "\x00", "\x00")))
|
|
253301
|
+
if (!isWordCharacter$1(state.doc.textBetween(pos, sampleEnd, "\x00", "\x00")))
|
|
253121
253302
|
return null;
|
|
253122
253303
|
let startPos = pos;
|
|
253123
253304
|
while (startPos > parentStart) {
|
|
253124
|
-
if (!isWordCharacter(state.doc.textBetween(startPos - 1, startPos, "\x00", "\x00")))
|
|
253305
|
+
if (!isWordCharacter$1(state.doc.textBetween(startPos - 1, startPos, "\x00", "\x00")))
|
|
253125
253306
|
break;
|
|
253126
253307
|
startPos -= 1;
|
|
253127
253308
|
}
|
|
253128
253309
|
let endPos = pos;
|
|
253129
253310
|
while (endPos < parentEnd) {
|
|
253130
|
-
if (!isWordCharacter(state.doc.textBetween(endPos, endPos + 1, "\x00", "\x00")))
|
|
253311
|
+
if (!isWordCharacter$1(state.doc.textBetween(endPos, endPos + 1, "\x00", "\x00")))
|
|
253131
253312
|
break;
|
|
253132
253313
|
endPos += 1;
|
|
253133
253314
|
}
|
|
@@ -256398,6 +256579,1369 @@ function getFontMetrics(ctx$1, fontInfo, mode, fonts) {
|
|
|
256398
256579
|
fontMetricsCache.set(key2, result);
|
|
256399
256580
|
return result;
|
|
256400
256581
|
}
|
|
256582
|
+
function computeFixedTableColumnWidths(input2) {
|
|
256583
|
+
const gridColumnCount = Math.max(0, sanitizeColumnCount(input2.gridColumnCount), Array.isArray(input2.preferredColumnWidths) ? input2.preferredColumnWidths.length : 0);
|
|
256584
|
+
const preferredTableWidth = sanitizeOptionalWidth$1(input2.preferredTableWidth);
|
|
256585
|
+
const defaultAddedColumnWidth = resolveDefaultAddedColumnWidth(input2.preferredColumnWidths, preferredTableWidth);
|
|
256586
|
+
const columnWidths = buildInitialGrid(input2.preferredColumnWidths, gridColumnCount, defaultAddedColumnWidth);
|
|
256587
|
+
if (input2.preserveAuthoredGrid === true)
|
|
256588
|
+
return {
|
|
256589
|
+
columnWidths,
|
|
256590
|
+
totalWidth: sumWidths$2(columnWidths),
|
|
256591
|
+
gridColumnCount: columnWidths.length,
|
|
256592
|
+
preferredTableWidth
|
|
256593
|
+
};
|
|
256594
|
+
if (input2.rows.length === 0) {
|
|
256595
|
+
if (preferredTableWidth != null)
|
|
256596
|
+
shrinkToPreferredTableWidth(columnWidths, preferredTableWidth);
|
|
256597
|
+
return {
|
|
256598
|
+
columnWidths,
|
|
256599
|
+
totalWidth: sumWidths$2(columnWidths),
|
|
256600
|
+
gridColumnCount: columnWidths.length,
|
|
256601
|
+
preferredTableWidth
|
|
256602
|
+
};
|
|
256603
|
+
}
|
|
256604
|
+
applyFirstRowRequests(columnWidths, input2.rows[0], defaultAddedColumnWidth);
|
|
256605
|
+
if (preferredTableWidth != null)
|
|
256606
|
+
shrinkToPreferredTableWidth(columnWidths, preferredTableWidth);
|
|
256607
|
+
for (const row2 of input2.rows.slice(1)) {
|
|
256608
|
+
applySubsequentRowRequests(columnWidths, row2, defaultAddedColumnWidth);
|
|
256609
|
+
if (preferredTableWidth != null)
|
|
256610
|
+
shrinkToPreferredTableWidth(columnWidths, preferredTableWidth);
|
|
256611
|
+
}
|
|
256612
|
+
return {
|
|
256613
|
+
columnWidths,
|
|
256614
|
+
totalWidth: sumWidths$2(columnWidths),
|
|
256615
|
+
gridColumnCount: columnWidths.length,
|
|
256616
|
+
preferredTableWidth
|
|
256617
|
+
};
|
|
256618
|
+
}
|
|
256619
|
+
function buildInitialGrid(preferredColumnWidths, gridColumnCount, defaultAddedColumnWidth) {
|
|
256620
|
+
const next2 = preferredColumnWidths.slice(0, gridColumnCount).map((width) => sanitizeNonNegativeWidth(width) ?? 0);
|
|
256621
|
+
while (next2.length < gridColumnCount)
|
|
256622
|
+
next2.push(defaultAddedColumnWidth);
|
|
256623
|
+
return next2;
|
|
256624
|
+
}
|
|
256625
|
+
function applyFirstRowRequests(columnWidths, row2, defaultAddedColumnWidth) {
|
|
256626
|
+
ensureGridWidth(columnWidths, row2.logicalColumnCount, defaultAddedColumnWidth);
|
|
256627
|
+
for (const skippedColumn of row2.skippedColumns)
|
|
256628
|
+
setSkippedColumnWidth(columnWidths, skippedColumn, defaultAddedColumnWidth);
|
|
256629
|
+
for (const cell2 of row2.cells)
|
|
256630
|
+
setCellSpanWidth(columnWidths, cell2, defaultAddedColumnWidth);
|
|
256631
|
+
}
|
|
256632
|
+
function applySubsequentRowRequests(columnWidths, row2, defaultAddedColumnWidth) {
|
|
256633
|
+
ensureGridWidth(columnWidths, row2.logicalColumnCount, defaultAddedColumnWidth);
|
|
256634
|
+
for (const skippedColumn of row2.skippedColumns)
|
|
256635
|
+
growSkippedColumnWidth(columnWidths, skippedColumn, defaultAddedColumnWidth);
|
|
256636
|
+
for (const cell2 of row2.cells)
|
|
256637
|
+
growCellSpanWidth(columnWidths, cell2, defaultAddedColumnWidth);
|
|
256638
|
+
}
|
|
256639
|
+
function setSkippedColumnWidth(columnWidths, skippedColumn, defaultAddedColumnWidth) {
|
|
256640
|
+
const preferredWidth = sanitizeOptionalWidth$1(skippedColumn.preferredWidth);
|
|
256641
|
+
if (preferredWidth == null)
|
|
256642
|
+
return;
|
|
256643
|
+
ensureGridWidth(columnWidths, skippedColumn.columnIndex + 1, defaultAddedColumnWidth);
|
|
256644
|
+
columnWidths[skippedColumn.columnIndex] = preferredWidth;
|
|
256645
|
+
}
|
|
256646
|
+
function growSkippedColumnWidth(columnWidths, skippedColumn, defaultAddedColumnWidth) {
|
|
256647
|
+
const preferredWidth = sanitizeOptionalWidth$1(skippedColumn.preferredWidth);
|
|
256648
|
+
if (preferredWidth == null)
|
|
256649
|
+
return;
|
|
256650
|
+
ensureGridWidth(columnWidths, skippedColumn.columnIndex + 1, defaultAddedColumnWidth);
|
|
256651
|
+
columnWidths[skippedColumn.columnIndex] = Math.max(columnWidths[skippedColumn.columnIndex] ?? 0, preferredWidth);
|
|
256652
|
+
}
|
|
256653
|
+
function setCellSpanWidth(columnWidths, cell2, defaultAddedColumnWidth) {
|
|
256654
|
+
const span = Math.max(1, sanitizeColumnCount(cell2.span));
|
|
256655
|
+
const preferredWidth = sanitizeOptionalWidth$1(cell2.preferredWidth);
|
|
256656
|
+
const endColumn = cell2.startColumn + span;
|
|
256657
|
+
ensureGridWidth(columnWidths, endColumn, defaultAddedColumnWidth);
|
|
256658
|
+
if (preferredWidth == null)
|
|
256659
|
+
return;
|
|
256660
|
+
const currentSpanWidth = sumSpan$1(columnWidths, cell2.startColumn, span);
|
|
256661
|
+
const lastColumnIndex = endColumn - 1;
|
|
256662
|
+
columnWidths[lastColumnIndex] = Math.max(0, (columnWidths[lastColumnIndex] ?? 0) + (preferredWidth - currentSpanWidth));
|
|
256663
|
+
}
|
|
256664
|
+
function growCellSpanWidth(columnWidths, cell2, defaultAddedColumnWidth) {
|
|
256665
|
+
const span = Math.max(1, sanitizeColumnCount(cell2.span));
|
|
256666
|
+
const preferredWidth = sanitizeOptionalWidth$1(cell2.preferredWidth);
|
|
256667
|
+
const endColumn = cell2.startColumn + span;
|
|
256668
|
+
ensureGridWidth(columnWidths, endColumn, defaultAddedColumnWidth);
|
|
256669
|
+
if (preferredWidth == null)
|
|
256670
|
+
return;
|
|
256671
|
+
const deficit = preferredWidth - sumSpan$1(columnWidths, cell2.startColumn, span);
|
|
256672
|
+
if (deficit <= 0)
|
|
256673
|
+
return;
|
|
256674
|
+
const lastColumnIndex = endColumn - 1;
|
|
256675
|
+
columnWidths[lastColumnIndex] = Math.max(0, (columnWidths[lastColumnIndex] ?? 0) + deficit);
|
|
256676
|
+
}
|
|
256677
|
+
function shrinkToPreferredTableWidth(columnWidths, preferredTableWidth) {
|
|
256678
|
+
const totalWidth = sumWidths$2(columnWidths);
|
|
256679
|
+
if (preferredTableWidth <= 0 || totalWidth <= preferredTableWidth || totalWidth <= 0)
|
|
256680
|
+
return;
|
|
256681
|
+
const scale = preferredTableWidth / totalWidth;
|
|
256682
|
+
let consumed = 0;
|
|
256683
|
+
for (let index2 = 0;index2 < columnWidths.length; index2++) {
|
|
256684
|
+
if (index2 === columnWidths.length - 1) {
|
|
256685
|
+
columnWidths[index2] = Math.max(0, preferredTableWidth - consumed);
|
|
256686
|
+
continue;
|
|
256687
|
+
}
|
|
256688
|
+
const scaled = Math.max(0, (columnWidths[index2] ?? 0) * scale);
|
|
256689
|
+
columnWidths[index2] = scaled;
|
|
256690
|
+
consumed += scaled;
|
|
256691
|
+
}
|
|
256692
|
+
}
|
|
256693
|
+
function ensureGridWidth(columnWidths, requiredColumnCount, defaultAddedColumnWidth) {
|
|
256694
|
+
while (columnWidths.length < requiredColumnCount)
|
|
256695
|
+
columnWidths.push(defaultAddedColumnWidth);
|
|
256696
|
+
}
|
|
256697
|
+
function resolveDefaultAddedColumnWidth(preferredColumnWidths, preferredTableWidth) {
|
|
256698
|
+
for (let index2 = preferredColumnWidths.length - 1;index2 >= 0; index2--) {
|
|
256699
|
+
const width = sanitizeNonNegativeWidth(preferredColumnWidths[index2]);
|
|
256700
|
+
if (width != null && width > 0)
|
|
256701
|
+
return width;
|
|
256702
|
+
}
|
|
256703
|
+
const positiveAuthoredWidths = preferredColumnWidths.map((width) => sanitizeNonNegativeWidth(width)).filter((width) => width != null && width > 0);
|
|
256704
|
+
if (positiveAuthoredWidths.length > 0)
|
|
256705
|
+
return sumWidths$2(positiveAuthoredWidths) / positiveAuthoredWidths.length;
|
|
256706
|
+
if (preferredTableWidth != null && preferredTableWidth > 0)
|
|
256707
|
+
return preferredTableWidth;
|
|
256708
|
+
return 1;
|
|
256709
|
+
}
|
|
256710
|
+
function sumSpan$1(columnWidths, startColumn, span) {
|
|
256711
|
+
let total = 0;
|
|
256712
|
+
for (let offset$1 = 0;offset$1 < span; offset$1++)
|
|
256713
|
+
total += columnWidths[startColumn + offset$1] ?? 0;
|
|
256714
|
+
return total;
|
|
256715
|
+
}
|
|
256716
|
+
function sumWidths$2(columnWidths) {
|
|
256717
|
+
return columnWidths.reduce((sum, width) => sum + Math.max(0, width), 0);
|
|
256718
|
+
}
|
|
256719
|
+
function sanitizeColumnCount(value) {
|
|
256720
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0)
|
|
256721
|
+
return 0;
|
|
256722
|
+
return Math.floor(value);
|
|
256723
|
+
}
|
|
256724
|
+
function sanitizeOptionalWidth$1(value) {
|
|
256725
|
+
const width = sanitizeNonNegativeWidth(value);
|
|
256726
|
+
return width == null ? undefined : width;
|
|
256727
|
+
}
|
|
256728
|
+
function sanitizeNonNegativeWidth(value) {
|
|
256729
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
256730
|
+
return;
|
|
256731
|
+
return Math.max(0, value);
|
|
256732
|
+
}
|
|
256733
|
+
function computeAutoFitColumnWidths(input2) {
|
|
256734
|
+
const { workingInput, fixedLayout, rowMetrics, minColumnWidth } = resolveAutoFitContext(input2);
|
|
256735
|
+
if (workingInput.layoutMode === "fixed")
|
|
256736
|
+
return finalizeResult("fixed", fixedLayout.columnWidths, minColumnWidth);
|
|
256737
|
+
const gridColumnCount = fixedLayout.gridColumnCount;
|
|
256738
|
+
if (gridColumnCount === 0)
|
|
256739
|
+
return buildFallbackResult(workingInput.layoutMode, minColumnWidth);
|
|
256740
|
+
const normalizedRows = buildNormalizedRows(workingInput, rowMetrics);
|
|
256741
|
+
const currentWidths = fixedLayout.columnWidths.slice(0, gridColumnCount);
|
|
256742
|
+
const minBounds = new Array(gridColumnCount).fill(0);
|
|
256743
|
+
const maxBounds = new Array(gridColumnCount).fill(0);
|
|
256744
|
+
const preferredOverrides = new Array(gridColumnCount).fill(undefined);
|
|
256745
|
+
const multiSpanCells = [];
|
|
256746
|
+
accumulateBounds({
|
|
256747
|
+
rows: normalizedRows,
|
|
256748
|
+
minBounds,
|
|
256749
|
+
maxBounds,
|
|
256750
|
+
preferredOverrides,
|
|
256751
|
+
multiSpanCells
|
|
256752
|
+
});
|
|
256753
|
+
applyMultiSpanMinimums(minBounds, multiSpanCells);
|
|
256754
|
+
applySingleSpanPreferredOverrides(maxBounds, minBounds, preferredOverrides);
|
|
256755
|
+
applyMultiSpanMaximums(maxBounds, minBounds, multiSpanCells, currentWidths);
|
|
256756
|
+
const triggerCells = collectTriggerCells(currentWidths, multiSpanCells, normalizedRows);
|
|
256757
|
+
const postTriggerGrowableColumns = triggerCells.length > 0 ? collectNonProtectedColumns(triggerCells, gridColumnCount) : undefined;
|
|
256758
|
+
let resolvedWidths = currentWidths.slice();
|
|
256759
|
+
const preferredTableWidth = sanitizeOptionalWidth(workingInput.preferredTableWidth);
|
|
256760
|
+
let targetTableWidth = preferredTableWidth ?? fixedLayout.totalWidth;
|
|
256761
|
+
const maxResolvedTableWidth = preferredTableWidth != null || hasCompleteAuthoredGrid(workingInput) ? Math.max(workingInput.maxTableWidth, targetTableWidth) : workingInput.maxTableWidth;
|
|
256762
|
+
const shouldPreservePreferredGrid = workingInput.preserveAutoGrid === true || workingInput.preserveExplicitAutoGrid === true;
|
|
256763
|
+
if (triggerCells.length > 0) {
|
|
256764
|
+
resolvedWidths = raiseToMinimums(resolvedWidths, minBounds);
|
|
256765
|
+
resolvedWidths = expandTriggersWithinCurrentTable(resolvedWidths, triggerCells, minBounds, maxBounds);
|
|
256766
|
+
resolvedWidths = expandTriggersByGrowingTable(resolvedWidths, triggerCells, maxBounds, maxResolvedTableWidth);
|
|
256767
|
+
targetTableWidth = Math.max(targetTableWidth, sumWidths$1(resolvedWidths));
|
|
256768
|
+
targetTableWidth = Math.min(targetTableWidth, maxResolvedTableWidth);
|
|
256769
|
+
} else {
|
|
256770
|
+
targetTableWidth = Math.min(targetTableWidth, maxResolvedTableWidth);
|
|
256771
|
+
if (!shouldPreservePreferredGrid) {
|
|
256772
|
+
resolvedWidths = redistributeTowardMaximumsWithinCurrentTable(resolvedWidths, minBounds, maxBounds);
|
|
256773
|
+
resolvedWidths = redistributeTowardContentWeightedShape(resolvedWidths, minBounds, maxBounds);
|
|
256774
|
+
}
|
|
256775
|
+
}
|
|
256776
|
+
resolvedWidths = shrinkToTargetWidth(resolvedWidths, targetTableWidth, minBounds);
|
|
256777
|
+
resolvedWidths = growToTargetWidth(resolvedWidths, targetTableWidth, maxBounds, postTriggerGrowableColumns);
|
|
256778
|
+
if (sumWidths$1(resolvedWidths) < targetTableWidth)
|
|
256779
|
+
resolvedWidths = distributeRemainingSlack(resolvedWidths, targetTableWidth, postTriggerGrowableColumns);
|
|
256780
|
+
if (triggerCells.length > 0)
|
|
256781
|
+
resolvedWidths = clampTriggeredSpansToTargets(resolvedWidths, triggerCells, minBounds, maxBounds, currentWidths);
|
|
256782
|
+
if (sumWidths$1(resolvedWidths) > maxResolvedTableWidth)
|
|
256783
|
+
resolvedWidths = shrinkToTargetWidth(resolvedWidths, maxResolvedTableWidth, minBounds);
|
|
256784
|
+
return finalizeResult(workingInput.layoutMode, resolvedWidths, minColumnWidth);
|
|
256785
|
+
}
|
|
256786
|
+
function hasCompleteAuthoredGrid(workingInput) {
|
|
256787
|
+
const authoredColumnCount = workingInput.preferredColumnWidths.length;
|
|
256788
|
+
if (authoredColumnCount === 0)
|
|
256789
|
+
return false;
|
|
256790
|
+
return workingInput.rows.some((row2) => row2.logicalColumnCount >= authoredColumnCount);
|
|
256791
|
+
}
|
|
256792
|
+
function resolveAutoFitContext(input2) {
|
|
256793
|
+
const minColumnWidth = sanitizeWidth(input2.minColumnWidth, DEFAULT_MIN_COLUMN_WIDTH);
|
|
256794
|
+
if (isExplicitInput(input2))
|
|
256795
|
+
return {
|
|
256796
|
+
workingInput: input2.workingInput,
|
|
256797
|
+
fixedLayout: input2.fixedLayout,
|
|
256798
|
+
rowMetrics: input2.contentMetrics.rowMetrics,
|
|
256799
|
+
minColumnWidth
|
|
256800
|
+
};
|
|
256801
|
+
const layoutMode = resolveLayoutMode$1(input2.tableLayout);
|
|
256802
|
+
const normalizedRows = normalizeLegacyRows(input2.rows ?? []);
|
|
256803
|
+
const gridColumnCount = determineGridColumnCount$1(input2.preferredColumnWidths ?? [], normalizedRows);
|
|
256804
|
+
const workingInput = {
|
|
256805
|
+
layoutMode,
|
|
256806
|
+
maxTableWidth: Math.max(minColumnWidth, sanitizeWidth(input2.maxTableWidth, minColumnWidth)),
|
|
256807
|
+
preferredTableWidth: sanitizeOptionalWidth(input2.preferredTableWidth),
|
|
256808
|
+
preferredColumnWidths: (input2.preferredColumnWidths ?? []).map((width) => Math.max(0, width)),
|
|
256809
|
+
gridColumnCount,
|
|
256810
|
+
rows: normalizedRows.map((row2) => ({
|
|
256811
|
+
skippedBefore: row2.skippedColumns.filter((column) => column.columnIndex < firstCellStart(row2)),
|
|
256812
|
+
skippedAfter: row2.skippedColumns.filter((column) => column.columnIndex >= lastCellEnd(row2)),
|
|
256813
|
+
skippedColumns: row2.skippedColumns,
|
|
256814
|
+
cells: row2.cells.map((cell2) => ({
|
|
256815
|
+
cellId: undefined,
|
|
256816
|
+
startColumn: cell2.startColumn,
|
|
256817
|
+
span: cell2.span,
|
|
256818
|
+
preferredWidth: cell2.preferredWidth
|
|
256819
|
+
})),
|
|
256820
|
+
logicalColumnCount: row2.logicalColumnCount
|
|
256821
|
+
}))
|
|
256822
|
+
};
|
|
256823
|
+
return {
|
|
256824
|
+
workingInput,
|
|
256825
|
+
fixedLayout: computeFixedTableColumnWidths(workingInput),
|
|
256826
|
+
rowMetrics: normalizedRows.map((row2, rowIndex) => ({
|
|
256827
|
+
rowIndex,
|
|
256828
|
+
cells: row2.cells.map((cell2) => ({
|
|
256829
|
+
cellIndex: cell2.cellIndex,
|
|
256830
|
+
span: cell2.span,
|
|
256831
|
+
preferredWidth: cell2.preferredWidth,
|
|
256832
|
+
minContentWidth: cell2.minContentWidth,
|
|
256833
|
+
maxContentWidth: cell2.maxContentWidth
|
|
256834
|
+
}))
|
|
256835
|
+
})),
|
|
256836
|
+
minColumnWidth
|
|
256837
|
+
};
|
|
256838
|
+
}
|
|
256839
|
+
function isExplicitInput(input2) {
|
|
256840
|
+
return "workingInput" in input2 && "fixedLayout" in input2 && "contentMetrics" in input2;
|
|
256841
|
+
}
|
|
256842
|
+
function resolveLayoutMode$1(tableLayout) {
|
|
256843
|
+
return tableLayout === "fixed" ? "fixed" : "autofit";
|
|
256844
|
+
}
|
|
256845
|
+
function normalizeLegacyRows(rows) {
|
|
256846
|
+
return rows.map((row2, rowIndex) => {
|
|
256847
|
+
let columnIndex = 0;
|
|
256848
|
+
const skippedColumns = [];
|
|
256849
|
+
const cells = [];
|
|
256850
|
+
for (const skipped of row2.skippedBefore ?? []) {
|
|
256851
|
+
skippedColumns.push(normalizeSkippedColumn(skipped, columnIndex));
|
|
256852
|
+
columnIndex += 1;
|
|
256853
|
+
}
|
|
256854
|
+
for (let cellIndex = 0;cellIndex < (row2.cells ?? []).length; cellIndex++) {
|
|
256855
|
+
const cell2 = row2.cells?.[cellIndex];
|
|
256856
|
+
if (!cell2)
|
|
256857
|
+
continue;
|
|
256858
|
+
const span = Math.max(1, Math.floor(cell2.span ?? 1));
|
|
256859
|
+
cells.push({
|
|
256860
|
+
rowIndex,
|
|
256861
|
+
cellIndex,
|
|
256862
|
+
startColumn: columnIndex,
|
|
256863
|
+
span,
|
|
256864
|
+
preferredWidth: sanitizeOptionalWidth(cell2.preferredWidth),
|
|
256865
|
+
minContentWidth: Math.max(0, cell2.minContentWidth ?? 0),
|
|
256866
|
+
maxContentWidth: Math.max(0, cell2.maxContentWidth ?? cell2.minContentWidth ?? 0)
|
|
256867
|
+
});
|
|
256868
|
+
columnIndex += span;
|
|
256869
|
+
}
|
|
256870
|
+
for (const skipped of row2.skippedAfter ?? []) {
|
|
256871
|
+
skippedColumns.push(normalizeSkippedColumn(skipped, columnIndex));
|
|
256872
|
+
columnIndex += 1;
|
|
256873
|
+
}
|
|
256874
|
+
return {
|
|
256875
|
+
cells,
|
|
256876
|
+
skippedColumns,
|
|
256877
|
+
logicalColumnCount: columnIndex
|
|
256878
|
+
};
|
|
256879
|
+
});
|
|
256880
|
+
}
|
|
256881
|
+
function normalizeSkippedColumn(skipped, columnIndex) {
|
|
256882
|
+
return {
|
|
256883
|
+
columnIndex,
|
|
256884
|
+
preferredWidth: sanitizeOptionalWidth(skipped.preferredWidth),
|
|
256885
|
+
minContentWidth: Math.max(0, skipped.minContentWidth ?? 0),
|
|
256886
|
+
maxContentWidth: Math.max(0, skipped.maxContentWidth ?? skipped.minContentWidth ?? 0)
|
|
256887
|
+
};
|
|
256888
|
+
}
|
|
256889
|
+
function buildNormalizedRows(workingInput, rowMetrics) {
|
|
256890
|
+
return workingInput.rows.map((workingRow, rowIndex) => {
|
|
256891
|
+
const metricsRow = rowMetrics[rowIndex];
|
|
256892
|
+
return {
|
|
256893
|
+
cells: (workingRow.cells ?? []).map((cell2, cellIndex) => {
|
|
256894
|
+
const metrics = metricsRow?.cells[cellIndex];
|
|
256895
|
+
const placedCell = cell2;
|
|
256896
|
+
return {
|
|
256897
|
+
rowIndex,
|
|
256898
|
+
cellIndex: metrics?.cellIndex ?? cellIndex,
|
|
256899
|
+
startColumn: placedCell.startColumn,
|
|
256900
|
+
span: Math.max(1, placedCell.span ?? metrics?.span ?? 1),
|
|
256901
|
+
preferredWidth: sanitizeOptionalWidth(metrics?.preferredWidth ?? placedCell.preferredWidth),
|
|
256902
|
+
minContentWidth: Math.max(0, metrics?.minContentWidth ?? 0),
|
|
256903
|
+
maxContentWidth: Math.max(0, metrics?.maxContentWidth ?? metrics?.minContentWidth ?? 0)
|
|
256904
|
+
};
|
|
256905
|
+
}),
|
|
256906
|
+
skippedColumns: (workingRow.skippedColumns ?? []).map((skipped) => ({
|
|
256907
|
+
columnIndex: skipped.columnIndex,
|
|
256908
|
+
preferredWidth: sanitizeOptionalWidth(skipped.preferredWidth),
|
|
256909
|
+
minContentWidth: Math.max(0, skipped.minContentWidth ?? 0),
|
|
256910
|
+
maxContentWidth: Math.max(0, skipped.maxContentWidth ?? skipped.minContentWidth ?? 0)
|
|
256911
|
+
})),
|
|
256912
|
+
logicalColumnCount: workingRow.logicalColumnCount
|
|
256913
|
+
};
|
|
256914
|
+
});
|
|
256915
|
+
}
|
|
256916
|
+
function accumulateBounds(args$1) {
|
|
256917
|
+
const { rows, minBounds, maxBounds, preferredOverrides, multiSpanCells } = args$1;
|
|
256918
|
+
for (const row2 of rows) {
|
|
256919
|
+
for (const skipped of row2.skippedColumns) {
|
|
256920
|
+
minBounds[skipped.columnIndex] = Math.max(minBounds[skipped.columnIndex], skipped.minContentWidth);
|
|
256921
|
+
maxBounds[skipped.columnIndex] = Math.max(maxBounds[skipped.columnIndex], skipped.maxContentWidth);
|
|
256922
|
+
if (preferredOverrides[skipped.columnIndex] == null && skipped.preferredWidth != null)
|
|
256923
|
+
preferredOverrides[skipped.columnIndex] = skipped.preferredWidth;
|
|
256924
|
+
}
|
|
256925
|
+
for (const cell2 of row2.cells)
|
|
256926
|
+
if (cell2.span === 1) {
|
|
256927
|
+
minBounds[cell2.startColumn] = Math.max(minBounds[cell2.startColumn], cell2.minContentWidth);
|
|
256928
|
+
maxBounds[cell2.startColumn] = Math.max(maxBounds[cell2.startColumn], cell2.maxContentWidth);
|
|
256929
|
+
if (preferredOverrides[cell2.startColumn] == null && cell2.preferredWidth != null)
|
|
256930
|
+
preferredOverrides[cell2.startColumn] = cell2.preferredWidth;
|
|
256931
|
+
} else
|
|
256932
|
+
multiSpanCells.push(cell2);
|
|
256933
|
+
}
|
|
256934
|
+
}
|
|
256935
|
+
function applyMultiSpanMinimums(minBounds, cells) {
|
|
256936
|
+
for (const cell2 of cells)
|
|
256937
|
+
growSpanTotal(minBounds, cell2.startColumn, cell2.span, cell2.minContentWidth);
|
|
256938
|
+
}
|
|
256939
|
+
function applySingleSpanPreferredOverrides(maxBounds, minBounds, preferredOverrides) {
|
|
256940
|
+
for (let index2 = 0;index2 < maxBounds.length; index2++) {
|
|
256941
|
+
const currentMax = Math.max(maxBounds[index2], minBounds[index2]);
|
|
256942
|
+
maxBounds[index2] = preferredOverrides[index2] ?? currentMax;
|
|
256943
|
+
maxBounds[index2] = Math.max(maxBounds[index2], minBounds[index2]);
|
|
256944
|
+
}
|
|
256945
|
+
}
|
|
256946
|
+
function applyMultiSpanMaximums(maxBounds, minBounds, cells, fixedWidths) {
|
|
256947
|
+
for (const cell2 of cells) {
|
|
256948
|
+
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));
|
|
256949
|
+
setSpanTotal(maxBounds, minBounds, fixedWidths, cell2.startColumn, cell2.span, targetTotal);
|
|
256950
|
+
}
|
|
256951
|
+
}
|
|
256952
|
+
function collectTriggerCells(currentWidths, multiSpanCells, rows) {
|
|
256953
|
+
const triggers = [];
|
|
256954
|
+
for (const row2 of rows)
|
|
256955
|
+
for (const cell2 of row2.cells)
|
|
256956
|
+
if (sumSpan(currentWidths, cell2.startColumn, cell2.span) < cell2.minContentWidth)
|
|
256957
|
+
triggers.push(cell2);
|
|
256958
|
+
for (const cell2 of multiSpanCells)
|
|
256959
|
+
if (sumSpan(currentWidths, cell2.startColumn, cell2.span) < cell2.minContentWidth)
|
|
256960
|
+
triggers.push(cell2);
|
|
256961
|
+
return coalesceEquivalentTriggerCells(dedupeCells(triggers));
|
|
256962
|
+
}
|
|
256963
|
+
function setSpanTotal(widths, minBounds, fixedWidths, startColumn, span, targetTotal) {
|
|
256964
|
+
const currentTotal = sumSpan(widths, startColumn, span);
|
|
256965
|
+
const minTotal = sumSpan(minBounds, startColumn, span);
|
|
256966
|
+
const boundedTarget = Math.max(targetTotal, minTotal);
|
|
256967
|
+
if (currentTotal < boundedTarget) {
|
|
256968
|
+
growSpanTotal(widths, startColumn, span, boundedTarget, fixedWidths);
|
|
256969
|
+
return;
|
|
256970
|
+
}
|
|
256971
|
+
if (currentTotal === boundedTarget)
|
|
256972
|
+
return;
|
|
256973
|
+
const reducibleRanges = collectSpanRanges(widths, minBounds, startColumn, span);
|
|
256974
|
+
const totalReducible = reducibleRanges.reduce((sum, range) => sum + range.amount, 0);
|
|
256975
|
+
if (totalReducible <= 0)
|
|
256976
|
+
return;
|
|
256977
|
+
const reduction = currentTotal - boundedTarget;
|
|
256978
|
+
let applied = 0;
|
|
256979
|
+
for (let rangeIndex = 0;rangeIndex < reducibleRanges.length; rangeIndex++) {
|
|
256980
|
+
const range = reducibleRanges[rangeIndex];
|
|
256981
|
+
const portion = rangeIndex === reducibleRanges.length - 1 ? reduction - applied : reduction * (range.amount / totalReducible);
|
|
256982
|
+
widths[range.index] = Math.max(minBounds[range.index], widths[range.index] - portion);
|
|
256983
|
+
applied += portion;
|
|
256984
|
+
}
|
|
256985
|
+
}
|
|
256986
|
+
function growSpanTotal(widths, startColumn, span, targetTotal, fixedWidths) {
|
|
256987
|
+
const deficit = targetTotal - sumSpan(widths, startColumn, span);
|
|
256988
|
+
if (deficit <= 0)
|
|
256989
|
+
return;
|
|
256990
|
+
const weights = Array.from({ length: span }, (_$1, offset$1) => {
|
|
256991
|
+
const index2 = startColumn + offset$1;
|
|
256992
|
+
return Math.max(fixedWidths?.[index2] ?? 0, widths[index2] ?? 0, 1);
|
|
256993
|
+
});
|
|
256994
|
+
const totalWeight = weights.reduce((sum, weight) => sum + weight, 0);
|
|
256995
|
+
let applied = 0;
|
|
256996
|
+
for (let offset$1 = 0;offset$1 < span; offset$1++) {
|
|
256997
|
+
const index2 = startColumn + offset$1;
|
|
256998
|
+
const increment2 = offset$1 === span - 1 ? deficit - applied : deficit * (weights[offset$1] / totalWeight);
|
|
256999
|
+
widths[index2] = Math.max(0, (widths[index2] ?? 0) + increment2);
|
|
257000
|
+
applied += increment2;
|
|
257001
|
+
}
|
|
257002
|
+
}
|
|
257003
|
+
function shrinkToTargetWidth(widths, targetWidth, minBounds) {
|
|
257004
|
+
const currentTotal = sumWidths$1(widths);
|
|
257005
|
+
if (currentTotal <= targetWidth)
|
|
257006
|
+
return widths;
|
|
257007
|
+
const minTotal = sumWidths$1(minBounds);
|
|
257008
|
+
if (targetWidth <= 0)
|
|
257009
|
+
return widths;
|
|
257010
|
+
if (targetWidth < minTotal)
|
|
257011
|
+
return scaleToTargetWidth(widths, targetWidth);
|
|
257012
|
+
const capacities = widths.map((width, index2) => Math.max(0, width - minBounds[index2]));
|
|
257013
|
+
const totalCapacity = capacities.reduce((sum, capacity) => sum + capacity, 0);
|
|
257014
|
+
if (totalCapacity <= 0)
|
|
257015
|
+
return widths;
|
|
257016
|
+
const excess = currentTotal - targetWidth;
|
|
257017
|
+
return widths.map((width, index2) => {
|
|
257018
|
+
const shrink = excess * (capacities[index2] / totalCapacity);
|
|
257019
|
+
return Math.max(minBounds[index2], width - shrink);
|
|
257020
|
+
});
|
|
257021
|
+
}
|
|
257022
|
+
function growToTargetWidth(widths, targetWidth, maxBounds, growableColumns) {
|
|
257023
|
+
const currentTotal = sumWidths$1(widths);
|
|
257024
|
+
if (currentTotal >= targetWidth)
|
|
257025
|
+
return widths;
|
|
257026
|
+
const ranges = widths.map((width, index2) => growableColumns == null || growableColumns.has(index2) ? Math.max(0, maxBounds[index2] - width) : 0);
|
|
257027
|
+
const totalRange = ranges.reduce((sum, range) => sum + range, 0);
|
|
257028
|
+
if (totalRange <= 0)
|
|
257029
|
+
return widths;
|
|
257030
|
+
const slack = targetWidth - currentTotal;
|
|
257031
|
+
return widths.map((width, index2) => width + slack * (ranges[index2] / totalRange));
|
|
257032
|
+
}
|
|
257033
|
+
function distributeRemainingSlack(widths, targetWidth, growableColumns) {
|
|
257034
|
+
const currentTotal = sumWidths$1(widths);
|
|
257035
|
+
if (currentTotal >= targetWidth)
|
|
257036
|
+
return widths;
|
|
257037
|
+
const basis = widths.reduce((sum, width, index2) => {
|
|
257038
|
+
if (growableColumns != null && !growableColumns.has(index2))
|
|
257039
|
+
return sum;
|
|
257040
|
+
return sum + Math.max(width, 1);
|
|
257041
|
+
}, 0);
|
|
257042
|
+
const slack = targetWidth - currentTotal;
|
|
257043
|
+
if (basis <= 0) {
|
|
257044
|
+
if (growableColumns == null)
|
|
257045
|
+
return widths;
|
|
257046
|
+
const growableIndexes = widths.map((_$1, index2) => index2).filter((index2) => growableColumns.has(index2));
|
|
257047
|
+
if (growableIndexes.length === 0)
|
|
257048
|
+
return widths;
|
|
257049
|
+
const share = slack / growableIndexes.length;
|
|
257050
|
+
return widths.map((width, index2) => growableColumns.has(index2) ? width + share : width);
|
|
257051
|
+
}
|
|
257052
|
+
return widths.map((width, index2) => {
|
|
257053
|
+
if (growableColumns != null && !growableColumns.has(index2))
|
|
257054
|
+
return width;
|
|
257055
|
+
return width + slack * (Math.max(width, 1) / basis);
|
|
257056
|
+
});
|
|
257057
|
+
}
|
|
257058
|
+
function raiseToMinimums(widths, minBounds) {
|
|
257059
|
+
const next2 = widths.slice();
|
|
257060
|
+
const deficits = next2.map((width, index2) => Math.max(0, minBounds[index2] - width));
|
|
257061
|
+
const totalDeficit = deficits.reduce((sum, deficit) => sum + deficit, 0);
|
|
257062
|
+
if (totalDeficit <= 0)
|
|
257063
|
+
return next2;
|
|
257064
|
+
const capacities = next2.map((width, index2) => Math.max(0, width - minBounds[index2]));
|
|
257065
|
+
const totalCapacity = capacities.reduce((sum, capacity) => sum + capacity, 0);
|
|
257066
|
+
const borrowAmount = Math.min(totalDeficit, totalCapacity);
|
|
257067
|
+
if (borrowAmount > 0 && totalCapacity > 0) {
|
|
257068
|
+
let borrowed = 0;
|
|
257069
|
+
for (let index2 = 0;index2 < next2.length; index2++) {
|
|
257070
|
+
const reduction = index2 === next2.length - 1 ? borrowAmount - borrowed : borrowAmount * (capacities[index2] / totalCapacity);
|
|
257071
|
+
next2[index2] = Math.max(minBounds[index2], next2[index2] - reduction);
|
|
257072
|
+
borrowed += reduction;
|
|
257073
|
+
}
|
|
257074
|
+
}
|
|
257075
|
+
for (let index2 = 0;index2 < next2.length; index2++)
|
|
257076
|
+
next2[index2] = Math.max(next2[index2], Math.min(minBounds[index2], widths[index2] + deficits[index2]));
|
|
257077
|
+
return next2;
|
|
257078
|
+
}
|
|
257079
|
+
function redistributeTowardMaximumsWithinCurrentTable(widths, minBounds, maxBounds) {
|
|
257080
|
+
const next2 = widths.slice();
|
|
257081
|
+
for (let iteration = 0;iteration < 8; iteration++) {
|
|
257082
|
+
const receiverHeadrooms = next2.map((width, index2) => Math.max(0, maxBounds[index2] - width));
|
|
257083
|
+
const totalReceiverHeadroom = receiverHeadrooms.reduce((sum, headroom) => sum + headroom, 0);
|
|
257084
|
+
if (totalReceiverHeadroom <= 0.001)
|
|
257085
|
+
break;
|
|
257086
|
+
const donorCapacities = next2.map((width, index2) => receiverHeadrooms[index2] > 0.001 ? 0 : Math.max(0, width - minBounds[index2]));
|
|
257087
|
+
let totalDonorCapacity = donorCapacities.reduce((sum, capacity) => sum + capacity, 0);
|
|
257088
|
+
if (totalDonorCapacity <= 0.001) {
|
|
257089
|
+
for (let index2 = 0;index2 < next2.length; index2++)
|
|
257090
|
+
donorCapacities[index2] = Math.max(0, next2[index2] - minBounds[index2]);
|
|
257091
|
+
totalDonorCapacity = donorCapacities.reduce((sum, capacity) => sum + capacity, 0);
|
|
257092
|
+
}
|
|
257093
|
+
if (totalDonorCapacity <= 0.001)
|
|
257094
|
+
break;
|
|
257095
|
+
const redistribution = Math.min(totalReceiverHeadroom, totalDonorCapacity);
|
|
257096
|
+
shrinkColumnsByCapacity(next2, donorCapacities, minBounds, redistribution);
|
|
257097
|
+
growColumnsByHeadroom(next2, receiverHeadrooms, redistribution);
|
|
257098
|
+
}
|
|
257099
|
+
return next2;
|
|
257100
|
+
}
|
|
257101
|
+
function redistributeTowardContentWeightedShape(widths, minBounds, maxBounds) {
|
|
257102
|
+
const distributableWidth = sumWidths$1(widths) - sumWidths$1(minBounds);
|
|
257103
|
+
if (distributableWidth <= 0.001 || widths.length === 0)
|
|
257104
|
+
return widths;
|
|
257105
|
+
const demandWeights = widths.map((width, index2) => {
|
|
257106
|
+
const demand = Math.max(maxBounds[index2], width, minBounds[index2], 1);
|
|
257107
|
+
return demand * demand;
|
|
257108
|
+
});
|
|
257109
|
+
const totalDemandWeight = demandWeights.reduce((sum, weight) => sum + weight, 0);
|
|
257110
|
+
if (totalDemandWeight <= 0.001)
|
|
257111
|
+
return widths;
|
|
257112
|
+
return widths.map((_$1, index2) => minBounds[index2] + distributableWidth * (demandWeights[index2] / totalDemandWeight));
|
|
257113
|
+
}
|
|
257114
|
+
function expandTriggersWithinCurrentTable(widths, triggerCells, minBounds, maxBounds) {
|
|
257115
|
+
const next2 = widths.slice();
|
|
257116
|
+
const protectedColumns = collectProtectedColumns(triggerCells);
|
|
257117
|
+
for (let iteration = 0;iteration < 8; iteration++) {
|
|
257118
|
+
const totalHeadroom = collectTriggerHeadrooms(next2, triggerCells, maxBounds).reduce((sum, headroom) => sum + headroom, 0);
|
|
257119
|
+
if (totalHeadroom <= 0.001)
|
|
257120
|
+
break;
|
|
257121
|
+
const donorCapacities = next2.map((width, index2) => protectedColumns.has(index2) ? 0 : Math.max(0, width - minBounds[index2]));
|
|
257122
|
+
const totalDonorCapacity = donorCapacities.reduce((sum, capacity) => sum + capacity, 0);
|
|
257123
|
+
if (totalDonorCapacity <= 0.001)
|
|
257124
|
+
break;
|
|
257125
|
+
const borrowedWidth = Math.min(totalHeadroom, totalDonorCapacity);
|
|
257126
|
+
shrinkColumnsByCapacity(next2, donorCapacities, minBounds, borrowedWidth);
|
|
257127
|
+
applyTriggerGrowth(next2, triggerCells, maxBounds, borrowedWidth);
|
|
257128
|
+
}
|
|
257129
|
+
return next2;
|
|
257130
|
+
}
|
|
257131
|
+
function expandTriggersByGrowingTable(widths, triggerCells, maxBounds, maxTableWidth) {
|
|
257132
|
+
const next2 = widths.slice();
|
|
257133
|
+
for (let iteration = 0;iteration < 8; iteration++) {
|
|
257134
|
+
const totalHeadroom = collectTriggerHeadrooms(next2, triggerCells, maxBounds).reduce((sum, headroom) => sum + headroom, 0);
|
|
257135
|
+
if (totalHeadroom <= 0.001)
|
|
257136
|
+
break;
|
|
257137
|
+
const remainingTableGrowth = Math.max(0, maxTableWidth - sumWidths$1(next2));
|
|
257138
|
+
if (remainingTableGrowth <= 0.001)
|
|
257139
|
+
break;
|
|
257140
|
+
applyTriggerGrowth(next2, triggerCells, maxBounds, Math.min(totalHeadroom, remainingTableGrowth));
|
|
257141
|
+
}
|
|
257142
|
+
return next2;
|
|
257143
|
+
}
|
|
257144
|
+
function collectTriggerHeadrooms(widths, triggerCells, maxBounds) {
|
|
257145
|
+
return triggerCells.map((cell2) => {
|
|
257146
|
+
const currentTotal = sumSpan(widths, cell2.startColumn, cell2.span);
|
|
257147
|
+
const targetTotal = resolveTriggerTargetTotal(cell2, maxBounds);
|
|
257148
|
+
return Math.max(0, targetTotal - currentTotal);
|
|
257149
|
+
});
|
|
257150
|
+
}
|
|
257151
|
+
function resolveTriggerTargetTotal(cell2, maxBounds) {
|
|
257152
|
+
if (cell2.span === 1)
|
|
257153
|
+
return maxBounds[cell2.startColumn] ?? cell2.maxContentWidth;
|
|
257154
|
+
return cell2.preferredWidth != null ? Math.max(cell2.preferredWidth, cell2.minContentWidth) : Math.max(cell2.maxContentWidth, cell2.minContentWidth);
|
|
257155
|
+
}
|
|
257156
|
+
function collectProtectedColumns(cells) {
|
|
257157
|
+
const protectedColumns = /* @__PURE__ */ new Set;
|
|
257158
|
+
for (const cell2 of cells)
|
|
257159
|
+
for (let offset$1 = 0;offset$1 < cell2.span; offset$1++)
|
|
257160
|
+
protectedColumns.add(cell2.startColumn + offset$1);
|
|
257161
|
+
return protectedColumns;
|
|
257162
|
+
}
|
|
257163
|
+
function collectNonProtectedColumns(cells, columnCount) {
|
|
257164
|
+
const protectedColumns = collectProtectedColumns(cells);
|
|
257165
|
+
const growableColumns = /* @__PURE__ */ new Set;
|
|
257166
|
+
for (let index2 = 0;index2 < columnCount; index2++)
|
|
257167
|
+
if (!protectedColumns.has(index2))
|
|
257168
|
+
growableColumns.add(index2);
|
|
257169
|
+
return growableColumns;
|
|
257170
|
+
}
|
|
257171
|
+
function shrinkColumnsByCapacity(widths, capacities, minBounds, shrinkAmount) {
|
|
257172
|
+
const totalCapacity = capacities.reduce((sum, capacity) => sum + capacity, 0);
|
|
257173
|
+
if (totalCapacity <= 0 || shrinkAmount <= 0)
|
|
257174
|
+
return;
|
|
257175
|
+
let applied = 0;
|
|
257176
|
+
for (let index2 = 0;index2 < widths.length; index2++) {
|
|
257177
|
+
const reduction = index2 === widths.length - 1 ? shrinkAmount - applied : shrinkAmount * (capacities[index2] / totalCapacity);
|
|
257178
|
+
widths[index2] = Math.max(minBounds[index2], widths[index2] - reduction);
|
|
257179
|
+
applied += reduction;
|
|
257180
|
+
}
|
|
257181
|
+
}
|
|
257182
|
+
function growColumnsByHeadroom(widths, headrooms, growthAmount) {
|
|
257183
|
+
const totalHeadroom = headrooms.reduce((sum, headroom) => sum + headroom, 0);
|
|
257184
|
+
if (totalHeadroom <= 0 || growthAmount <= 0)
|
|
257185
|
+
return;
|
|
257186
|
+
let applied = 0;
|
|
257187
|
+
const activeIndexes = headrooms.map((headroom, index2) => ({
|
|
257188
|
+
headroom,
|
|
257189
|
+
index: index2
|
|
257190
|
+
})).filter((entry) => entry.headroom > 0.001);
|
|
257191
|
+
for (let activeIndex = 0;activeIndex < activeIndexes.length; activeIndex++) {
|
|
257192
|
+
const { index: index2, headroom } = activeIndexes[activeIndex];
|
|
257193
|
+
const growth = activeIndex === activeIndexes.length - 1 ? growthAmount - applied : growthAmount * (headroom / totalHeadroom);
|
|
257194
|
+
widths[index2] += Math.min(headroom, growth);
|
|
257195
|
+
applied += Math.min(headroom, growth);
|
|
257196
|
+
}
|
|
257197
|
+
}
|
|
257198
|
+
function applyTriggerGrowth(widths, triggerCells, maxBounds, growthAmount) {
|
|
257199
|
+
let remainingGrowth = growthAmount;
|
|
257200
|
+
for (let iteration = 0;iteration < 16 && remainingGrowth > 0.001; iteration++) {
|
|
257201
|
+
const headrooms = collectTriggerHeadrooms(widths, triggerCells, maxBounds);
|
|
257202
|
+
const totalHeadroom = headrooms.reduce((sum, headroom) => sum + headroom, 0);
|
|
257203
|
+
if (totalHeadroom <= 0.001)
|
|
257204
|
+
break;
|
|
257205
|
+
const stepGrowth = Math.min(remainingGrowth, totalHeadroom);
|
|
257206
|
+
const activeIndexes = headrooms.map((headroom, index2) => ({
|
|
257207
|
+
headroom,
|
|
257208
|
+
index: index2
|
|
257209
|
+
})).filter((entry) => entry.headroom > 0.001);
|
|
257210
|
+
let appliedThisRound = 0;
|
|
257211
|
+
for (let activeIndex = 0;activeIndex < activeIndexes.length; activeIndex++) {
|
|
257212
|
+
const { index: index2, headroom } = activeIndexes[activeIndex];
|
|
257213
|
+
const cell2 = triggerCells[index2];
|
|
257214
|
+
const proportionalGrowth = activeIndex === activeIndexes.length - 1 ? stepGrowth - appliedThisRound : stepGrowth * (headroom / totalHeadroom);
|
|
257215
|
+
const boundedGrowth = Math.min(headroom, proportionalGrowth);
|
|
257216
|
+
if (boundedGrowth <= 0)
|
|
257217
|
+
continue;
|
|
257218
|
+
growSpanTotal(widths, cell2.startColumn, cell2.span, sumSpan(widths, cell2.startColumn, cell2.span) + boundedGrowth);
|
|
257219
|
+
appliedThisRound += boundedGrowth;
|
|
257220
|
+
}
|
|
257221
|
+
if (appliedThisRound <= 0.001)
|
|
257222
|
+
break;
|
|
257223
|
+
remainingGrowth -= appliedThisRound;
|
|
257224
|
+
}
|
|
257225
|
+
}
|
|
257226
|
+
function clampTriggeredSpansToTargets(widths, triggerCells, minBounds, maxBounds, fixedWidths) {
|
|
257227
|
+
const next2 = widths.slice();
|
|
257228
|
+
for (let iteration = 0;iteration < 8; iteration++) {
|
|
257229
|
+
let changed = false;
|
|
257230
|
+
for (const cell2 of triggerCells) {
|
|
257231
|
+
const currentTotal = sumSpan(next2, cell2.startColumn, cell2.span);
|
|
257232
|
+
const targetTotal = resolveTriggerTargetTotal(cell2, maxBounds);
|
|
257233
|
+
if (currentTotal > targetTotal + 0.001) {
|
|
257234
|
+
setSpanTotal(next2, minBounds, fixedWidths, cell2.startColumn, cell2.span, targetTotal);
|
|
257235
|
+
changed = true;
|
|
257236
|
+
}
|
|
257237
|
+
}
|
|
257238
|
+
if (!changed)
|
|
257239
|
+
break;
|
|
257240
|
+
}
|
|
257241
|
+
return next2;
|
|
257242
|
+
}
|
|
257243
|
+
function collectSpanRanges(widths, minBounds, startColumn, span) {
|
|
257244
|
+
const ranges = [];
|
|
257245
|
+
for (let offset$1 = 0;offset$1 < span; offset$1++) {
|
|
257246
|
+
const index2 = startColumn + offset$1;
|
|
257247
|
+
const amount = Math.max(0, widths[index2] - minBounds[index2]);
|
|
257248
|
+
if (amount > 0)
|
|
257249
|
+
ranges.push({
|
|
257250
|
+
index: index2,
|
|
257251
|
+
amount
|
|
257252
|
+
});
|
|
257253
|
+
}
|
|
257254
|
+
return ranges;
|
|
257255
|
+
}
|
|
257256
|
+
function dedupeCells(cells) {
|
|
257257
|
+
const seen = /* @__PURE__ */ new Set;
|
|
257258
|
+
return cells.filter((cell2) => {
|
|
257259
|
+
const key2 = `${cell2.rowIndex}:${cell2.startColumn}:${cell2.span}:${cell2.cellIndex}`;
|
|
257260
|
+
if (seen.has(key2))
|
|
257261
|
+
return false;
|
|
257262
|
+
seen.add(key2);
|
|
257263
|
+
return true;
|
|
257264
|
+
});
|
|
257265
|
+
}
|
|
257266
|
+
function coalesceEquivalentTriggerCells(cells) {
|
|
257267
|
+
const strongestBySpan = /* @__PURE__ */ new Map;
|
|
257268
|
+
for (const cell2 of cells) {
|
|
257269
|
+
const key2 = `${cell2.startColumn}:${cell2.span}`;
|
|
257270
|
+
const current = strongestBySpan.get(key2);
|
|
257271
|
+
if (!current || resolveTriggerStrength(cell2) > resolveTriggerStrength(current))
|
|
257272
|
+
strongestBySpan.set(key2, cell2);
|
|
257273
|
+
}
|
|
257274
|
+
return [...strongestBySpan.values()];
|
|
257275
|
+
}
|
|
257276
|
+
function resolveTriggerStrength(cell2) {
|
|
257277
|
+
return cell2.preferredWidth != null ? Math.max(cell2.preferredWidth, cell2.minContentWidth) : Math.max(cell2.maxContentWidth, cell2.minContentWidth);
|
|
257278
|
+
}
|
|
257279
|
+
function determineGridColumnCount$1(preferredColumnWidths, rows) {
|
|
257280
|
+
return Math.max(preferredColumnWidths.length, ...rows.map((row2) => row2.logicalColumnCount), 0);
|
|
257281
|
+
}
|
|
257282
|
+
function firstCellStart(row2) {
|
|
257283
|
+
return row2.cells[0]?.startColumn ?? row2.logicalColumnCount;
|
|
257284
|
+
}
|
|
257285
|
+
function lastCellEnd(row2) {
|
|
257286
|
+
const lastCell = row2.cells[row2.cells.length - 1];
|
|
257287
|
+
return lastCell ? lastCell.startColumn + lastCell.span : 0;
|
|
257288
|
+
}
|
|
257289
|
+
function sumSpan(widths, startColumn, span) {
|
|
257290
|
+
let total = 0;
|
|
257291
|
+
for (let offset$1 = 0;offset$1 < span; offset$1++)
|
|
257292
|
+
total += widths[startColumn + offset$1] ?? 0;
|
|
257293
|
+
return total;
|
|
257294
|
+
}
|
|
257295
|
+
function sumWidths$1(widths) {
|
|
257296
|
+
return widths.reduce((sum, width) => sum + Math.max(0, width), 0);
|
|
257297
|
+
}
|
|
257298
|
+
function scaleToTargetWidth(widths, targetWidth) {
|
|
257299
|
+
const currentTotal = sumWidths$1(widths);
|
|
257300
|
+
if (currentTotal <= 0 || targetWidth <= 0)
|
|
257301
|
+
return widths;
|
|
257302
|
+
const scale = targetWidth / currentTotal;
|
|
257303
|
+
return widths.map((width) => Math.max(0, width * scale));
|
|
257304
|
+
}
|
|
257305
|
+
function sanitizeWidth(value, fallback) {
|
|
257306
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : fallback;
|
|
257307
|
+
}
|
|
257308
|
+
function sanitizeOptionalWidth(value) {
|
|
257309
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined;
|
|
257310
|
+
}
|
|
257311
|
+
function buildFallbackResult(layoutMode, minColumnWidth) {
|
|
257312
|
+
return {
|
|
257313
|
+
layoutMode,
|
|
257314
|
+
columnWidths: [minColumnWidth],
|
|
257315
|
+
totalWidth: minColumnWidth,
|
|
257316
|
+
gridColumnCount: 1
|
|
257317
|
+
};
|
|
257318
|
+
}
|
|
257319
|
+
function finalizeResult(layoutMode, widths, minColumnWidth) {
|
|
257320
|
+
if (widths.length === 0)
|
|
257321
|
+
return buildFallbackResult(layoutMode, minColumnWidth);
|
|
257322
|
+
return {
|
|
257323
|
+
layoutMode,
|
|
257324
|
+
columnWidths: widths,
|
|
257325
|
+
totalWidth: sumWidths$1(widths),
|
|
257326
|
+
gridColumnCount: widths.length
|
|
257327
|
+
};
|
|
257328
|
+
}
|
|
257329
|
+
function buildAutoFitWorkingGridInput(block, constraints) {
|
|
257330
|
+
const maxTableWidth = sanitizePositiveNumber(constraints.maxWidth);
|
|
257331
|
+
const layoutMode = resolveLayoutMode(block.attrs?.tableLayout);
|
|
257332
|
+
const preferredTableWidth = resolvePreferredTableWidth(block.attrs?.tableWidth, maxTableWidth);
|
|
257333
|
+
const rawPreferredColumnWidths = normalizePreferredColumnWidths(block.columnWidths);
|
|
257334
|
+
const logicalColumnLimit = resolveTrailingPlaceholderColumnLimit(rawPreferredColumnWidths);
|
|
257335
|
+
let activeRowSpans = [];
|
|
257336
|
+
const rows = block.rows.map((row2) => {
|
|
257337
|
+
const normalized = normalizeRow(row2, preferredTableWidth ?? maxTableWidth, activeRowSpans, logicalColumnLimit);
|
|
257338
|
+
activeRowSpans = normalized.nextActiveRowSpans;
|
|
257339
|
+
return normalized.row;
|
|
257340
|
+
});
|
|
257341
|
+
const preferredColumnWidths = trimTrailingUnoccupiedPlaceholderColumns(rawPreferredColumnWidths, determineGridColumnCount(0, rows));
|
|
257342
|
+
const gridColumnCount = determineGridColumnCount(preferredColumnWidths.length, rows);
|
|
257343
|
+
const preserveAuthoredGrid = shouldPreserveAuthoredGrid({
|
|
257344
|
+
layoutMode,
|
|
257345
|
+
preferredColumnWidths,
|
|
257346
|
+
preferredTableWidth,
|
|
257347
|
+
gridColumnCount
|
|
257348
|
+
});
|
|
257349
|
+
const preserveAutoGrid = shouldPreserveAutoGrid({
|
|
257350
|
+
layoutMode,
|
|
257351
|
+
preferredColumnWidths,
|
|
257352
|
+
preferredTableWidth,
|
|
257353
|
+
gridColumnCount
|
|
257354
|
+
});
|
|
257355
|
+
const preserveExplicitAutoGrid = shouldPreserveExplicitAutoGrid({
|
|
257356
|
+
layoutMode,
|
|
257357
|
+
preferredColumnWidths,
|
|
257358
|
+
preferredTableWidth,
|
|
257359
|
+
gridColumnCount,
|
|
257360
|
+
rows
|
|
257361
|
+
});
|
|
257362
|
+
return {
|
|
257363
|
+
layoutMode,
|
|
257364
|
+
maxTableWidth,
|
|
257365
|
+
...preserveAuthoredGrid ? { preserveAuthoredGrid } : {},
|
|
257366
|
+
...preserveAutoGrid ? { preserveAutoGrid } : {},
|
|
257367
|
+
...preserveExplicitAutoGrid ? { preserveExplicitAutoGrid } : {},
|
|
257368
|
+
preferredTableWidth,
|
|
257369
|
+
preferredColumnWidths,
|
|
257370
|
+
gridColumnCount,
|
|
257371
|
+
rows
|
|
257372
|
+
};
|
|
257373
|
+
}
|
|
257374
|
+
function resolveLayoutMode(tableLayout) {
|
|
257375
|
+
return tableLayout === "fixed" ? "fixed" : "autofit";
|
|
257376
|
+
}
|
|
257377
|
+
function shouldPreserveAuthoredGrid(args$1) {
|
|
257378
|
+
const { layoutMode, preferredColumnWidths, preferredTableWidth, gridColumnCount } = args$1;
|
|
257379
|
+
if (layoutMode !== "fixed")
|
|
257380
|
+
return false;
|
|
257381
|
+
if (preferredTableWidth == null || preferredTableWidth <= 0)
|
|
257382
|
+
return false;
|
|
257383
|
+
if (preferredColumnWidths.length === 0 || preferredColumnWidths.length !== gridColumnCount)
|
|
257384
|
+
return false;
|
|
257385
|
+
const totalPreferredColumnWidth = sumWidths(preferredColumnWidths);
|
|
257386
|
+
return approximatelyEqual(totalPreferredColumnWidth, preferredTableWidth) || isSlightlyUnderPreferredTableWidth(totalPreferredColumnWidth, preferredTableWidth);
|
|
257387
|
+
}
|
|
257388
|
+
function shouldPreserveAutoGrid(args$1) {
|
|
257389
|
+
const { layoutMode, preferredColumnWidths, preferredTableWidth, gridColumnCount } = args$1;
|
|
257390
|
+
if (layoutMode !== "autofit")
|
|
257391
|
+
return false;
|
|
257392
|
+
if (preferredTableWidth != null)
|
|
257393
|
+
return false;
|
|
257394
|
+
if (preferredColumnWidths.length === 0 || preferredColumnWidths.length !== gridColumnCount)
|
|
257395
|
+
return false;
|
|
257396
|
+
if (!hasNonUniformGrid(preferredColumnWidths))
|
|
257397
|
+
return false;
|
|
257398
|
+
return true;
|
|
257399
|
+
}
|
|
257400
|
+
function shouldPreserveExplicitAutoGrid(args$1) {
|
|
257401
|
+
const { layoutMode, preferredColumnWidths, preferredTableWidth, gridColumnCount, rows } = args$1;
|
|
257402
|
+
if (layoutMode !== "autofit")
|
|
257403
|
+
return false;
|
|
257404
|
+
if (preferredTableWidth == null || preferredTableWidth <= 0)
|
|
257405
|
+
return false;
|
|
257406
|
+
if (preferredColumnWidths.length === 0 || preferredColumnWidths.length !== gridColumnCount)
|
|
257407
|
+
return false;
|
|
257408
|
+
if (!hasNonUniformGrid(preferredColumnWidths) && !hasConcreteCellWidthRequest(rows))
|
|
257409
|
+
return false;
|
|
257410
|
+
return approximatelyEqual(sumWidths(preferredColumnWidths), preferredTableWidth);
|
|
257411
|
+
}
|
|
257412
|
+
function hasNonUniformGrid(widths) {
|
|
257413
|
+
if (widths.length <= 1)
|
|
257414
|
+
return true;
|
|
257415
|
+
const firstWidth = widths[0];
|
|
257416
|
+
return widths.some((width) => !approximatelyEqual(width, firstWidth));
|
|
257417
|
+
}
|
|
257418
|
+
function hasConcreteCellWidthRequest(rows) {
|
|
257419
|
+
return rows.some((row2) => row2.cells.some((cell2) => cell2.preferredWidth != null));
|
|
257420
|
+
}
|
|
257421
|
+
function trimTrailingUnoccupiedPlaceholderColumns(widths, occupiedGridColumnCount) {
|
|
257422
|
+
const occupiedCount = Math.max(0, Math.floor(occupiedGridColumnCount));
|
|
257423
|
+
if (occupiedCount <= 0 || widths.length <= occupiedCount)
|
|
257424
|
+
return widths;
|
|
257425
|
+
if (!widths.slice(occupiedCount).every((width) => width <= PLACEHOLDER_COLUMN_MAX_WIDTH))
|
|
257426
|
+
return widths;
|
|
257427
|
+
return widths.slice(0, occupiedCount);
|
|
257428
|
+
}
|
|
257429
|
+
function resolveTrailingPlaceholderColumnLimit(widths) {
|
|
257430
|
+
let trailingPlaceholderCount = 0;
|
|
257431
|
+
for (let index2 = widths.length - 1;index2 >= 0; index2--) {
|
|
257432
|
+
if (widths[index2] > PLACEHOLDER_COLUMN_MAX_WIDTH)
|
|
257433
|
+
break;
|
|
257434
|
+
trailingPlaceholderCount += 1;
|
|
257435
|
+
}
|
|
257436
|
+
if (trailingPlaceholderCount === 0 || trailingPlaceholderCount === widths.length)
|
|
257437
|
+
return;
|
|
257438
|
+
return widths.length - trailingPlaceholderCount;
|
|
257439
|
+
}
|
|
257440
|
+
function normalizePreferredColumnWidths(columnWidths) {
|
|
257441
|
+
if (!Array.isArray(columnWidths))
|
|
257442
|
+
return [];
|
|
257443
|
+
return columnWidths.map((width) => sanitizeNonNegativeNumber(width)).filter((width) => width !== undefined).map((width) => width);
|
|
257444
|
+
}
|
|
257445
|
+
function normalizeRow(row2, percentageBasis, activeRowSpans, logicalColumnLimit) {
|
|
257446
|
+
const rowProps = row2.attrs?.tableRowProperties ?? {};
|
|
257447
|
+
const skippedBeforeCount = sanitizeCount(rowProps.gridBefore);
|
|
257448
|
+
const skippedAfterCount = normalizeSkippedAfterCount(rowProps.gridAfter, rowProps.wAfter, percentageBasis);
|
|
257449
|
+
const cells = Array.isArray(row2.cells) ? row2.cells : [];
|
|
257450
|
+
let columnIndex = advancePastOccupiedColumns(activeRowSpans, 0);
|
|
257451
|
+
const skippedBeforePlacement = buildSkippedColumns(skippedBeforeCount, rowProps.wBefore, percentageBasis, columnIndex, activeRowSpans);
|
|
257452
|
+
columnIndex = skippedBeforePlacement.nextColumnIndex;
|
|
257453
|
+
const normalizedCells = cells.map((cell2) => {
|
|
257454
|
+
columnIndex = advancePastOccupiedColumns(activeRowSpans, columnIndex);
|
|
257455
|
+
const normalizedCell = normalizeCell(cell2, percentageBasis, columnIndex, logicalColumnLimit);
|
|
257456
|
+
columnIndex += normalizedCell.span ?? 1;
|
|
257457
|
+
return normalizedCell;
|
|
257458
|
+
});
|
|
257459
|
+
const skippedAfterPlacement = buildSkippedColumns(skippedAfterCount, rowProps.wAfter, percentageBasis, columnIndex, activeRowSpans);
|
|
257460
|
+
columnIndex = skippedAfterPlacement.nextColumnIndex;
|
|
257461
|
+
const logicalColumnCount = Math.max(columnIndex, resolveOccupiedLogicalColumnCount(activeRowSpans));
|
|
257462
|
+
const nextActiveRowSpans = advanceRowSpans(activeRowSpans);
|
|
257463
|
+
normalizedCells.forEach((cell2, index2) => {
|
|
257464
|
+
const rowSpan = sanitizeCount(cells[index2]?.rowSpan) || 1;
|
|
257465
|
+
if (rowSpan > 1)
|
|
257466
|
+
markRowSpanOccupancy(nextActiveRowSpans, cell2.startColumn, cell2.span ?? 1, rowSpan - 1);
|
|
257467
|
+
});
|
|
257468
|
+
return {
|
|
257469
|
+
row: {
|
|
257470
|
+
skippedBefore: skippedBeforePlacement.columns,
|
|
257471
|
+
cells: normalizedCells,
|
|
257472
|
+
skippedAfter: skippedAfterPlacement.columns,
|
|
257473
|
+
skippedColumns: [...skippedBeforePlacement.columns, ...skippedAfterPlacement.columns],
|
|
257474
|
+
logicalColumnCount
|
|
257475
|
+
},
|
|
257476
|
+
nextActiveRowSpans
|
|
257477
|
+
};
|
|
257478
|
+
}
|
|
257479
|
+
function buildSkippedColumns(count, preferredWidthMeasurement, percentageBasis, startColumnIndex, activeRowSpans) {
|
|
257480
|
+
if (count <= 0)
|
|
257481
|
+
return {
|
|
257482
|
+
columns: [],
|
|
257483
|
+
nextColumnIndex: startColumnIndex
|
|
257484
|
+
};
|
|
257485
|
+
const totalPreferredWidth = resolveMeasurementToPx(preferredWidthMeasurement, percentageBasis);
|
|
257486
|
+
const perColumnPreferredWidth = totalPreferredWidth != null && count > 0 ? Math.max(0, totalPreferredWidth / count) : undefined;
|
|
257487
|
+
const columns = [];
|
|
257488
|
+
let columnIndex = startColumnIndex;
|
|
257489
|
+
for (let index2 = 0;index2 < count; index2++) {
|
|
257490
|
+
columnIndex = advancePastOccupiedColumns(activeRowSpans, columnIndex);
|
|
257491
|
+
columns.push({
|
|
257492
|
+
columnIndex,
|
|
257493
|
+
preferredWidth: perColumnPreferredWidth,
|
|
257494
|
+
minContentWidth: 0,
|
|
257495
|
+
maxContentWidth: 0
|
|
257496
|
+
});
|
|
257497
|
+
columnIndex += 1;
|
|
257498
|
+
}
|
|
257499
|
+
return {
|
|
257500
|
+
columns,
|
|
257501
|
+
nextColumnIndex: columnIndex
|
|
257502
|
+
};
|
|
257503
|
+
}
|
|
257504
|
+
function normalizeSkippedAfterCount(countValue, preferredWidthMeasurement, percentageBasis) {
|
|
257505
|
+
const count = sanitizeCount(countValue);
|
|
257506
|
+
if (count <= 0)
|
|
257507
|
+
return 0;
|
|
257508
|
+
const totalPreferredWidth = resolveMeasurementToPx(preferredWidthMeasurement, percentageBasis);
|
|
257509
|
+
if (totalPreferredWidth != null && totalPreferredWidth <= PLACEHOLDER_COLUMN_MAX_WIDTH * count)
|
|
257510
|
+
return 0;
|
|
257511
|
+
return count;
|
|
257512
|
+
}
|
|
257513
|
+
function normalizeCell(cell2, percentageBasis, startColumn, logicalColumnLimit) {
|
|
257514
|
+
const cellProps = cell2.attrs?.tableCellProperties ?? {};
|
|
257515
|
+
const rawSpan = sanitizeCount(cell2.colSpan) || 1;
|
|
257516
|
+
const span = logicalColumnLimit != null && startColumn < logicalColumnLimit && startColumn + rawSpan > logicalColumnLimit ? Math.max(1, logicalColumnLimit - startColumn) : rawSpan;
|
|
257517
|
+
return {
|
|
257518
|
+
cellId: cell2.id,
|
|
257519
|
+
startColumn,
|
|
257520
|
+
span,
|
|
257521
|
+
preferredWidth: resolveMeasurementToPx(cellProps.cellWidth, percentageBasis)
|
|
257522
|
+
};
|
|
257523
|
+
}
|
|
257524
|
+
function advancePastOccupiedColumns(activeRowSpans, columnIndex) {
|
|
257525
|
+
let nextColumnIndex = columnIndex;
|
|
257526
|
+
while ((activeRowSpans[nextColumnIndex] ?? 0) > 0)
|
|
257527
|
+
nextColumnIndex += 1;
|
|
257528
|
+
return nextColumnIndex;
|
|
257529
|
+
}
|
|
257530
|
+
function resolveOccupiedLogicalColumnCount(activeRowSpans) {
|
|
257531
|
+
for (let index2 = activeRowSpans.length - 1;index2 >= 0; index2--)
|
|
257532
|
+
if ((activeRowSpans[index2] ?? 0) > 0)
|
|
257533
|
+
return index2 + 1;
|
|
257534
|
+
return 0;
|
|
257535
|
+
}
|
|
257536
|
+
function advanceRowSpans(activeRowSpans) {
|
|
257537
|
+
return activeRowSpans.map((remainingRows) => Math.max(0, remainingRows - 1));
|
|
257538
|
+
}
|
|
257539
|
+
function markRowSpanOccupancy(activeRowSpans, startColumn, span, remainingRows) {
|
|
257540
|
+
const boundedSpan = Math.max(1, sanitizeCount(span));
|
|
257541
|
+
for (let offset$1 = 0;offset$1 < boundedSpan; offset$1++) {
|
|
257542
|
+
const columnIndex = startColumn + offset$1;
|
|
257543
|
+
activeRowSpans[columnIndex] = Math.max(activeRowSpans[columnIndex] ?? 0, remainingRows);
|
|
257544
|
+
}
|
|
257545
|
+
}
|
|
257546
|
+
function determineGridColumnCount(preferredColumnCount, rows) {
|
|
257547
|
+
return Math.max(preferredColumnCount, ...rows.map((row2) => {
|
|
257548
|
+
if ("logicalColumnCount" in row2 && typeof row2.logicalColumnCount === "number")
|
|
257549
|
+
return row2.logicalColumnCount;
|
|
257550
|
+
const skippedBefore = row2.skippedBefore?.length ?? 0;
|
|
257551
|
+
const skippedAfter = row2.skippedAfter?.length ?? 0;
|
|
257552
|
+
const cellSpanTotal = (row2.cells ?? []).reduce((sum, cell2) => sum + Math.max(1, cell2.span ?? 1), 0);
|
|
257553
|
+
return skippedBefore + skippedAfter + cellSpanTotal;
|
|
257554
|
+
}), 0);
|
|
257555
|
+
}
|
|
257556
|
+
function resolvePreferredTableWidth(tableWidth, maxWidth) {
|
|
257557
|
+
const resolvedWidth = resolveTableWidthAttr(tableWidth);
|
|
257558
|
+
if (!resolvedWidth)
|
|
257559
|
+
return;
|
|
257560
|
+
if (resolvedWidth.type === "pct")
|
|
257561
|
+
return Math.round(maxWidth * (resolvedWidth.width / OOXML_PCT_DIVISOR));
|
|
257562
|
+
return resolvedWidth.width;
|
|
257563
|
+
}
|
|
257564
|
+
function resolveMeasurementToPx(measurement, percentageBasis) {
|
|
257565
|
+
if (!measurement || typeof measurement !== "object" || !Number.isFinite(measurement.value))
|
|
257566
|
+
return;
|
|
257567
|
+
const value = measurement.value;
|
|
257568
|
+
switch ((measurement.type ?? "dxa").toLowerCase()) {
|
|
257569
|
+
case "dxa":
|
|
257570
|
+
return value / TWIPS_PER_PX$1;
|
|
257571
|
+
case "pct":
|
|
257572
|
+
return Math.round(percentageBasis * (value / OOXML_PCT_DIVISOR));
|
|
257573
|
+
case "px":
|
|
257574
|
+
case "pixel":
|
|
257575
|
+
return value;
|
|
257576
|
+
case "auto":
|
|
257577
|
+
case "nil":
|
|
257578
|
+
return;
|
|
257579
|
+
default:
|
|
257580
|
+
return value;
|
|
257581
|
+
}
|
|
257582
|
+
}
|
|
257583
|
+
function sanitizeCount(value) {
|
|
257584
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
257585
|
+
return 0;
|
|
257586
|
+
return Math.max(0, Math.floor(value));
|
|
257587
|
+
}
|
|
257588
|
+
function sanitizePositiveNumber(value) {
|
|
257589
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0)
|
|
257590
|
+
return 1;
|
|
257591
|
+
return value;
|
|
257592
|
+
}
|
|
257593
|
+
function sanitizeNonNegativeNumber(value) {
|
|
257594
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
|
|
257595
|
+
return;
|
|
257596
|
+
return value;
|
|
257597
|
+
}
|
|
257598
|
+
function sumWidths(widths) {
|
|
257599
|
+
return widths.reduce((sum, width) => sum + Math.max(0, width), 0);
|
|
257600
|
+
}
|
|
257601
|
+
function approximatelyEqual(left$1, right$1) {
|
|
257602
|
+
return Math.abs(left$1 - right$1) <= 0.01;
|
|
257603
|
+
}
|
|
257604
|
+
function isSlightlyUnderPreferredTableWidth(totalColumnWidth, preferredTableWidth) {
|
|
257605
|
+
if (totalColumnWidth <= 0 || totalColumnWidth >= preferredTableWidth)
|
|
257606
|
+
return false;
|
|
257607
|
+
return preferredTableWidth - totalColumnWidth <= preferredTableWidth * 0.05;
|
|
257608
|
+
}
|
|
257609
|
+
function buildTableCellContentMetricsCacheKey(cell2, options) {
|
|
257610
|
+
return stableSerialize({
|
|
257611
|
+
maxWidth: Math.max(1, Math.round(options.maxWidth)),
|
|
257612
|
+
layoutEpoch: options.layoutEpoch ?? null,
|
|
257613
|
+
attrs: cell2.attrs ?? null,
|
|
257614
|
+
paragraph: cell2.paragraph ?? null,
|
|
257615
|
+
blocks: cell2.blocks ?? null
|
|
257616
|
+
});
|
|
257617
|
+
}
|
|
257618
|
+
function buildAutoFitTableResultCacheKey(table2, options) {
|
|
257619
|
+
return stableSerialize({
|
|
257620
|
+
id: table2.id,
|
|
257621
|
+
attrs: table2.attrs ?? null,
|
|
257622
|
+
columnWidths: table2.columnWidths ?? null,
|
|
257623
|
+
rowCount: table2.rows.length,
|
|
257624
|
+
maxWidth: Math.max(1, Math.round(options.maxWidth)),
|
|
257625
|
+
layoutEpoch: options.layoutEpoch ?? null,
|
|
257626
|
+
cellMetricKeys: options.cellMetricKeys,
|
|
257627
|
+
workingGrid: {
|
|
257628
|
+
layoutMode: options.workingInput.layoutMode,
|
|
257629
|
+
gridColumnCount: options.workingInput.gridColumnCount,
|
|
257630
|
+
preserveAuthoredGrid: options.workingInput.preserveAuthoredGrid === true,
|
|
257631
|
+
preserveAutoGrid: options.workingInput.preserveAutoGrid === true,
|
|
257632
|
+
preserveExplicitAutoGrid: options.workingInput.preserveExplicitAutoGrid === true,
|
|
257633
|
+
preferredTableWidth: options.workingInput.preferredTableWidth ?? null,
|
|
257634
|
+
preferredColumnWidths: options.workingInput.preferredColumnWidths,
|
|
257635
|
+
rows: options.workingInput.rows.map((row2) => ({
|
|
257636
|
+
logicalColumnCount: row2.logicalColumnCount,
|
|
257637
|
+
skippedColumns: (row2.skippedColumns ?? []).map((column) => ({
|
|
257638
|
+
columnIndex: column.columnIndex,
|
|
257639
|
+
preferredWidth: column.preferredWidth ?? null
|
|
257640
|
+
})),
|
|
257641
|
+
cells: row2.cells.map((cell2) => ({
|
|
257642
|
+
startColumn: cell2.startColumn,
|
|
257643
|
+
span: cell2.span ?? 1,
|
|
257644
|
+
preferredWidth: cell2.preferredWidth ?? null
|
|
257645
|
+
}))
|
|
257646
|
+
}))
|
|
257647
|
+
},
|
|
257648
|
+
fixedLayout: {
|
|
257649
|
+
columnWidths: options.fixedLayout.columnWidths,
|
|
257650
|
+
totalWidth: options.fixedLayout.totalWidth,
|
|
257651
|
+
gridColumnCount: options.fixedLayout.gridColumnCount,
|
|
257652
|
+
preferredTableWidth: options.fixedLayout.preferredTableWidth ?? null
|
|
257653
|
+
}
|
|
257654
|
+
});
|
|
257655
|
+
}
|
|
257656
|
+
function getCachedAutoFitTableResult(cacheKey) {
|
|
257657
|
+
return autoFitTableResultCache.get(cacheKey);
|
|
257658
|
+
}
|
|
257659
|
+
function setCachedAutoFitTableResult(cacheKey, result) {
|
|
257660
|
+
autoFitTableResultCache.set(cacheKey, result);
|
|
257661
|
+
}
|
|
257662
|
+
async function measureTableCellContentMetrics(cell2, options) {
|
|
257663
|
+
const cacheKey = buildTableCellContentMetricsCacheKey(cell2, options);
|
|
257664
|
+
const cached2 = tableCellMetricsCache.get(cacheKey);
|
|
257665
|
+
if (cached2)
|
|
257666
|
+
return cached2;
|
|
257667
|
+
const horizontalInsets = getHorizontalCellInsets(cell2);
|
|
257668
|
+
const contentBlocks = cell2.blocks ?? (cell2.paragraph ? [cell2.paragraph] : []);
|
|
257669
|
+
if (contentBlocks.length === 0) {
|
|
257670
|
+
const emptyMetrics = {
|
|
257671
|
+
minWidthPx: horizontalInsets,
|
|
257672
|
+
maxWidthPx: horizontalInsets
|
|
257673
|
+
};
|
|
257674
|
+
tableCellMetricsCache.set(cacheKey, emptyMetrics);
|
|
257675
|
+
return emptyMetrics;
|
|
257676
|
+
}
|
|
257677
|
+
let minContentWidthPx = 0;
|
|
257678
|
+
let maxContentWidthPx = 0;
|
|
257679
|
+
for (const block of contentBlocks) {
|
|
257680
|
+
const metrics = await measureIntrinsicBlockWidthMetrics(block, options);
|
|
257681
|
+
minContentWidthPx = Math.max(minContentWidthPx, metrics.minWidthPx);
|
|
257682
|
+
maxContentWidthPx = Math.max(maxContentWidthPx, metrics.maxWidthPx);
|
|
257683
|
+
}
|
|
257684
|
+
const result = {
|
|
257685
|
+
minWidthPx: minContentWidthPx + horizontalInsets,
|
|
257686
|
+
maxWidthPx: maxContentWidthPx + horizontalInsets
|
|
257687
|
+
};
|
|
257688
|
+
tableCellMetricsCache.set(cacheKey, result);
|
|
257689
|
+
return result;
|
|
257690
|
+
}
|
|
257691
|
+
async function measureTableAutoFitContentMetrics(table2, workingInput, fixedLayout, measureBlock$1) {
|
|
257692
|
+
const tableMeasurementBasis = Math.max(1, fixedLayout.totalWidth);
|
|
257693
|
+
const cellMetricKeys = [];
|
|
257694
|
+
const rowMetrics = await Promise.all(table2.rows.map(async (row2, rowIndex) => {
|
|
257695
|
+
const normalizedRow = workingInput.rows[rowIndex] ?? {};
|
|
257696
|
+
return {
|
|
257697
|
+
rowIndex,
|
|
257698
|
+
cells: await Promise.all(row2.cells.map(async (cell2, cellIndex) => {
|
|
257699
|
+
const normalizedCell = normalizedRow.cells?.[cellIndex];
|
|
257700
|
+
const span = normalizedCell?.span ?? cell2.colSpan ?? 1;
|
|
257701
|
+
const measurementMaxWidth = resolveAutoFitCellMeasurementMaxWidth(cell2, normalizedCell, span, fixedLayout, tableMeasurementBasis, workingInput.gridColumnCount);
|
|
257702
|
+
cellMetricKeys.push(buildTableCellContentMetricsCacheKey(cell2, { maxWidth: measurementMaxWidth }));
|
|
257703
|
+
const metrics = await measureTableCellContentMetrics(cell2, {
|
|
257704
|
+
maxWidth: measurementMaxWidth,
|
|
257705
|
+
measureBlock: measureBlock$1
|
|
257706
|
+
});
|
|
257707
|
+
return {
|
|
257708
|
+
cellIndex,
|
|
257709
|
+
span,
|
|
257710
|
+
preferredWidth: normalizedCell?.preferredWidth,
|
|
257711
|
+
minContentWidth: metrics.minWidthPx,
|
|
257712
|
+
maxContentWidth: metrics.maxWidthPx
|
|
257713
|
+
};
|
|
257714
|
+
}))
|
|
257715
|
+
};
|
|
257716
|
+
}));
|
|
257717
|
+
return {
|
|
257718
|
+
rowMetrics,
|
|
257719
|
+
rows: rowMetrics.map((rowMetrics$1, rowIndex) => {
|
|
257720
|
+
const normalizedRow = workingInput.rows[rowIndex] ?? {};
|
|
257721
|
+
return {
|
|
257722
|
+
skippedBefore: normalizedRow.skippedBefore ?? [],
|
|
257723
|
+
cells: rowMetrics$1.cells.map((cellMetrics) => ({
|
|
257724
|
+
span: cellMetrics.span,
|
|
257725
|
+
preferredWidth: cellMetrics.preferredWidth,
|
|
257726
|
+
minContentWidth: cellMetrics.minContentWidth,
|
|
257727
|
+
maxContentWidth: cellMetrics.maxContentWidth
|
|
257728
|
+
})),
|
|
257729
|
+
skippedAfter: normalizedRow.skippedAfter ?? []
|
|
257730
|
+
};
|
|
257731
|
+
}),
|
|
257732
|
+
cellMetricKeys
|
|
257733
|
+
};
|
|
257734
|
+
}
|
|
257735
|
+
async function measureIntrinsicBlockWidthMetrics(block, options) {
|
|
257736
|
+
if (block.kind === "paragraph")
|
|
257737
|
+
return measureParagraphIntrinsicWidthMetrics(block, options.measureBlock);
|
|
257738
|
+
if (block.kind === "table")
|
|
257739
|
+
return measureNestedTableIntrinsicWidthMetrics(block, options);
|
|
257740
|
+
const intrinsicWidth = getIntrinsicAtomicBlockWidth(block);
|
|
257741
|
+
return {
|
|
257742
|
+
minWidthPx: intrinsicWidth,
|
|
257743
|
+
maxWidthPx: intrinsicWidth
|
|
257744
|
+
};
|
|
257745
|
+
}
|
|
257746
|
+
async function measureParagraphIntrinsicWidthMetrics(paragraph2, measureBlock$1) {
|
|
257747
|
+
const maxLineWidth = (await measureBlock$1(paragraph2, {
|
|
257748
|
+
maxWidth: NO_WRAP_MAX_WIDTH,
|
|
257749
|
+
maxHeight: Infinity
|
|
257750
|
+
})).lines.reduce((widest, line) => Math.max(widest, line.width), 0);
|
|
257751
|
+
return {
|
|
257752
|
+
minWidthPx: measureParagraphMinTokenWidth(paragraph2),
|
|
257753
|
+
maxWidthPx: maxLineWidth
|
|
257754
|
+
};
|
|
257755
|
+
}
|
|
257756
|
+
async function measureNestedTableIntrinsicWidthMetrics(table2, options) {
|
|
257757
|
+
const nestedMeasure = await options.measureBlock(table2, {
|
|
257758
|
+
maxWidth: Math.max(1, options.maxWidth),
|
|
257759
|
+
maxHeight: Infinity
|
|
257760
|
+
});
|
|
257761
|
+
if (nestedMeasure.kind !== "table")
|
|
257762
|
+
return {
|
|
257763
|
+
minWidthPx: 0,
|
|
257764
|
+
maxWidthPx: 0
|
|
257765
|
+
};
|
|
257766
|
+
return {
|
|
257767
|
+
minWidthPx: nestedMeasure.totalWidth,
|
|
257768
|
+
maxWidthPx: nestedMeasure.totalWidth
|
|
257769
|
+
};
|
|
257770
|
+
}
|
|
257771
|
+
function measureParagraphMinTokenWidth(paragraph2) {
|
|
257772
|
+
let widestToken = 0;
|
|
257773
|
+
let currentTokenWidth = 0;
|
|
257774
|
+
const flushToken = () => {
|
|
257775
|
+
widestToken = Math.max(widestToken, currentTokenWidth);
|
|
257776
|
+
currentTokenWidth = 0;
|
|
257777
|
+
};
|
|
257778
|
+
for (const run2 of paragraph2.runs) {
|
|
257779
|
+
if (isExplicitLineBreakRun(run2)) {
|
|
257780
|
+
flushToken();
|
|
257781
|
+
continue;
|
|
257782
|
+
}
|
|
257783
|
+
if (isTextLikeRun(run2)) {
|
|
257784
|
+
accumulateTextRunMinTokenWidth(run2, (width) => {
|
|
257785
|
+
currentTokenWidth += width;
|
|
257786
|
+
}, flushToken);
|
|
257787
|
+
continue;
|
|
257788
|
+
}
|
|
257789
|
+
flushToken();
|
|
257790
|
+
if (run2.kind === "image") {
|
|
257791
|
+
widestToken = Math.max(widestToken, run2.width ?? 0);
|
|
257792
|
+
continue;
|
|
257793
|
+
}
|
|
257794
|
+
if (run2.kind === "fieldAnnotation") {
|
|
257795
|
+
widestToken = Math.max(widestToken, measureFieldAnnotationWidth(run2));
|
|
257796
|
+
continue;
|
|
257797
|
+
}
|
|
257798
|
+
if (run2.kind === "math")
|
|
257799
|
+
widestToken = Math.max(widestToken, run2.width ?? 0);
|
|
257800
|
+
}
|
|
257801
|
+
flushToken();
|
|
257802
|
+
return widestToken;
|
|
257803
|
+
}
|
|
257804
|
+
function accumulateTextRunMinTokenWidth(run2, appendTokenPiece, flushToken) {
|
|
257805
|
+
const font = buildFontString$1(run2);
|
|
257806
|
+
let cursor = 0;
|
|
257807
|
+
for (const boundary of run2.text.matchAll(TOKEN_BOUNDARY_PATTERN)) {
|
|
257808
|
+
const boundaryStart = boundary.index ?? cursor;
|
|
257809
|
+
if (boundaryStart > cursor)
|
|
257810
|
+
appendTokenPiece(measureTextRunTokenSlice(run2, cursor, boundaryStart, font));
|
|
257811
|
+
flushToken();
|
|
257812
|
+
cursor = boundaryStart + boundary[0].length;
|
|
257813
|
+
}
|
|
257814
|
+
if (cursor < run2.text.length)
|
|
257815
|
+
appendTokenPiece(measureTextRunTokenSlice(run2, cursor, run2.text.length, font));
|
|
257816
|
+
}
|
|
257817
|
+
function measureTextRunTokenSlice(run2, start$1, end$1, font) {
|
|
257818
|
+
return getMeasuredTextWidth(applyTextTransform$1(run2.text.slice(start$1, end$1), run2, start$1), font, getLetterSpacing(run2), getCanvasContext$1());
|
|
257819
|
+
}
|
|
257820
|
+
function getIntrinsicAtomicBlockWidth(block) {
|
|
257821
|
+
if (block.kind === "image")
|
|
257822
|
+
return block.width ?? 0;
|
|
257823
|
+
if (block.drawingKind === "image")
|
|
257824
|
+
return block.width ?? 0;
|
|
257825
|
+
if (block.drawingKind === "shapeGroup")
|
|
257826
|
+
return block.size?.width ?? block.geometry.width;
|
|
257827
|
+
return block.geometry.width;
|
|
257828
|
+
}
|
|
257829
|
+
function resolveAutoFitCellMeasurementMaxWidth(cell2, normalizedCell, span, fixedLayout, tableWidthBasis, gridColumnCount) {
|
|
257830
|
+
const outerWidth = resolveFixedPassCellOuterWidth(normalizedCell, span, fixedLayout) ?? normalizedCell?.preferredWidth ?? Math.max(1, tableWidthBasis * (Math.max(1, span) / Math.max(1, gridColumnCount || span || 1)));
|
|
257831
|
+
const padding = cell2.attrs?.padding ?? DEFAULT_CELL_PADDING$1;
|
|
257832
|
+
const leftPadding = padding.left ?? DEFAULT_CELL_PADDING$1.left;
|
|
257833
|
+
const rightPadding = padding.right ?? DEFAULT_CELL_PADDING$1.right;
|
|
257834
|
+
const leftBorder = getCellBorderWidthPx(cell2.attrs?.borders?.left);
|
|
257835
|
+
const rightBorder = getCellBorderWidthPx(cell2.attrs?.borders?.right);
|
|
257836
|
+
return Math.max(1, outerWidth - leftPadding - rightPadding - leftBorder - rightBorder);
|
|
257837
|
+
}
|
|
257838
|
+
function resolveFixedPassCellOuterWidth(normalizedCell, fallbackSpan, fixedLayout) {
|
|
257839
|
+
if (normalizedCell?.startColumn == null)
|
|
257840
|
+
return;
|
|
257841
|
+
const span = Math.max(1, normalizedCell.span ?? fallbackSpan);
|
|
257842
|
+
let width = 0;
|
|
257843
|
+
for (let offset$1 = 0;offset$1 < span; offset$1++)
|
|
257844
|
+
width += fixedLayout.columnWidths[normalizedCell.startColumn + offset$1] ?? 0;
|
|
257845
|
+
return width > 0 ? width : undefined;
|
|
257846
|
+
}
|
|
257847
|
+
function getHorizontalCellInsets(cell2) {
|
|
257848
|
+
const padding = cell2.attrs?.padding ?? DEFAULT_CELL_PADDING$1;
|
|
257849
|
+
const leftPadding = padding.left ?? DEFAULT_CELL_PADDING$1.left;
|
|
257850
|
+
const rightPadding = padding.right ?? DEFAULT_CELL_PADDING$1.right;
|
|
257851
|
+
const leftBorder = getCellBorderWidthPx(cell2.attrs?.borders?.left);
|
|
257852
|
+
const rightBorder = getCellBorderWidthPx(cell2.attrs?.borders?.right);
|
|
257853
|
+
return leftPadding + rightPadding + leftBorder + rightBorder;
|
|
257854
|
+
}
|
|
257855
|
+
function getCellBorderWidthPx(border) {
|
|
257856
|
+
if (!border || border.style === "none")
|
|
257857
|
+
return 0;
|
|
257858
|
+
const width = typeof border.width === "number" ? border.width : 0;
|
|
257859
|
+
if (border.style === "thick")
|
|
257860
|
+
return Math.max(width * 2, 3);
|
|
257861
|
+
return Math.max(0, width);
|
|
257862
|
+
}
|
|
257863
|
+
function getCanvasContext$1() {
|
|
257864
|
+
if (!canvasContext$1) {
|
|
257865
|
+
canvasContext$1 = document.createElement("canvas").getContext("2d");
|
|
257866
|
+
if (!canvasContext$1)
|
|
257867
|
+
throw new Error("Failed to create canvas context for AutoFit cell measurement.");
|
|
257868
|
+
}
|
|
257869
|
+
return canvasContext$1;
|
|
257870
|
+
}
|
|
257871
|
+
function buildFontString$1(run2) {
|
|
257872
|
+
const parts = [];
|
|
257873
|
+
if (run2.italic)
|
|
257874
|
+
parts.push("italic");
|
|
257875
|
+
if (run2.bold)
|
|
257876
|
+
parts.push("bold");
|
|
257877
|
+
parts.push(`${normalizeFontSize$1(run2.fontSize)}px`);
|
|
257878
|
+
parts.push(toCssFontFamily(normalizeFontFamily$1(run2.fontFamily)) ?? normalizeFontFamily$1(run2.fontFamily));
|
|
257879
|
+
return parts.join(" ");
|
|
257880
|
+
}
|
|
257881
|
+
function applyTextTransform$1(text5, run2, startOffset = 0) {
|
|
257882
|
+
const transform2 = run2.textTransform;
|
|
257883
|
+
if (!text5 || !transform2 || transform2 === "none")
|
|
257884
|
+
return text5;
|
|
257885
|
+
if (transform2 === "uppercase")
|
|
257886
|
+
return text5.toUpperCase();
|
|
257887
|
+
if (transform2 === "lowercase")
|
|
257888
|
+
return text5.toLowerCase();
|
|
257889
|
+
if (transform2 === "capitalize")
|
|
257890
|
+
return capitalizeText$1(text5, run2.text ?? text5, startOffset);
|
|
257891
|
+
return text5;
|
|
257892
|
+
}
|
|
257893
|
+
function capitalizeText$1(text5, fullText, startOffset) {
|
|
257894
|
+
let result = "";
|
|
257895
|
+
for (let index2 = 0;index2 < text5.length; index2++) {
|
|
257896
|
+
const absoluteIndex = startOffset + index2;
|
|
257897
|
+
const currentChar = text5[index2];
|
|
257898
|
+
const previousChar = absoluteIndex > 0 ? fullText[absoluteIndex - 1] : "";
|
|
257899
|
+
result += isWordCharacter(currentChar) && !isWordCharacter(previousChar) ? currentChar.toUpperCase() : currentChar;
|
|
257900
|
+
}
|
|
257901
|
+
return result;
|
|
257902
|
+
}
|
|
257903
|
+
function measureFieldAnnotationWidth(run2) {
|
|
257904
|
+
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;
|
|
257905
|
+
const font = buildFontString$1({
|
|
257906
|
+
fontFamily: normalizeFontFamily$1(run2.fontFamily ?? "Arial"),
|
|
257907
|
+
fontSize,
|
|
257908
|
+
bold: run2.bold,
|
|
257909
|
+
italic: run2.italic
|
|
257910
|
+
});
|
|
257911
|
+
return getMeasuredTextWidth(applyTextTransform$1(run2.displayLabel || "", { text: run2.displayLabel || "" }), font, 0, getCanvasContext$1()) + (run2.highlighted === false ? 0 : FIELD_ANNOTATION_PILL_PADDING$1);
|
|
257912
|
+
}
|
|
257913
|
+
function isExplicitLineBreakRun(run2) {
|
|
257914
|
+
return run2.kind === "lineBreak" || run2.kind === "break" && run2.breakType === "line";
|
|
257915
|
+
}
|
|
257916
|
+
function isTextLikeRun(run2) {
|
|
257917
|
+
return "text" in run2 && typeof run2.text === "string";
|
|
257918
|
+
}
|
|
257919
|
+
function getLetterSpacing(run2) {
|
|
257920
|
+
return "letterSpacing" in run2 && typeof run2.letterSpacing === "number" ? run2.letterSpacing : 0;
|
|
257921
|
+
}
|
|
257922
|
+
function normalizeFontSize$1(value) {
|
|
257923
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0)
|
|
257924
|
+
return value;
|
|
257925
|
+
if (typeof value === "string") {
|
|
257926
|
+
const parsed = parseFloat(value);
|
|
257927
|
+
if (Number.isFinite(parsed) && parsed > 0)
|
|
257928
|
+
return parsed;
|
|
257929
|
+
}
|
|
257930
|
+
return 12;
|
|
257931
|
+
}
|
|
257932
|
+
function normalizeFontFamily$1(value) {
|
|
257933
|
+
return typeof value === "string" && value.trim().length > 0 ? value : "Arial";
|
|
257934
|
+
}
|
|
257935
|
+
function stableSerialize(value) {
|
|
257936
|
+
if (value === null || typeof value !== "object")
|
|
257937
|
+
return JSON.stringify(value);
|
|
257938
|
+
if (Array.isArray(value))
|
|
257939
|
+
return `[${value.map((item) => stableSerialize(item)).join(",")}]`;
|
|
257940
|
+
return `{${Object.entries(value).sort(([left$1], [right$1]) => left$1.localeCompare(right$1)).map(([key2, entry]) => `${JSON.stringify(key2)}:${stableSerialize(entry)}`).join(",")}}`;
|
|
257941
|
+
}
|
|
257942
|
+
function isWordCharacter(value) {
|
|
257943
|
+
return /[A-Za-z0-9]/.test(value);
|
|
257944
|
+
}
|
|
256401
257945
|
function getTableBorderWidthPx(value) {
|
|
256402
257946
|
if (value == null)
|
|
256403
257947
|
return 0;
|
|
@@ -257888,141 +259432,9 @@ async function measureParagraphBlock(block, maxWidth) {
|
|
|
257888
259432
|
...dropCapMeasure ? { dropCap: dropCapMeasure } : {}
|
|
257889
259433
|
};
|
|
257890
259434
|
}
|
|
257891
|
-
function resolveTableWidth(attrs, maxWidth) {
|
|
257892
|
-
const tableWidthAttr = resolveTableWidthAttr(attrs?.tableWidth);
|
|
257893
|
-
if (!tableWidthAttr)
|
|
257894
|
-
return;
|
|
257895
|
-
if (tableWidthAttr.type === "pct")
|
|
257896
|
-
return Math.round(maxWidth * (tableWidthAttr.width / OOXML_PCT_DIVISOR));
|
|
257897
|
-
else if (tableWidthAttr.type === "px" || tableWidthAttr.type === "pixel" || tableWidthAttr.type === "dxa")
|
|
257898
|
-
return tableWidthAttr.width;
|
|
257899
|
-
}
|
|
257900
259435
|
async function measureTableBlock(block, constraints) {
|
|
257901
|
-
const
|
|
257902
|
-
const
|
|
257903
|
-
let columnWidths;
|
|
257904
|
-
const maxCellCount = Math.max(1, Math.max(...block.rows.map((r$1) => r$1.cells.reduce((sum, cell2) => sum + (cell2.colSpan ?? 1), 0))));
|
|
257905
|
-
const effectiveTargetWidth = resolvedTableWidth != null ? resolvedTableWidth : maxWidth;
|
|
257906
|
-
if (block.columnWidths && block.columnWidths.length > 0) {
|
|
257907
|
-
columnWidths = [...block.columnWidths];
|
|
257908
|
-
const hasExplicitWidth = resolvedTableWidth != null;
|
|
257909
|
-
const hasFixedLayout = block.attrs?.tableLayout === "fixed";
|
|
257910
|
-
if (hasExplicitWidth || hasFixedLayout) {
|
|
257911
|
-
const totalWidth$1 = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
|
|
257912
|
-
const tableWidthType = block.attrs?.tableWidth?.type;
|
|
257913
|
-
const targetWidth = hasExplicitWidth ? effectiveTargetWidth : totalWidth$1;
|
|
257914
|
-
if ((totalWidth$1 > targetWidth || totalWidth$1 < targetWidth && targetWidth > 0 && (tableWidthType === "pct" || hasExplicitWidth && !hasFixedLayout)) && targetWidth > 0 && totalWidth$1 > 0) {
|
|
257915
|
-
const scale = targetWidth / totalWidth$1;
|
|
257916
|
-
columnWidths = columnWidths.map((w) => Math.max(1, Math.round(w * scale)));
|
|
257917
|
-
const scaledSum = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
|
|
257918
|
-
if (scaledSum !== targetWidth && columnWidths.length > 0) {
|
|
257919
|
-
const diff = targetWidth - scaledSum;
|
|
257920
|
-
columnWidths[columnWidths.length - 1] = Math.max(1, columnWidths[columnWidths.length - 1] + diff);
|
|
257921
|
-
}
|
|
257922
|
-
}
|
|
257923
|
-
} else if (columnWidths.length < maxCellCount) {
|
|
257924
|
-
const usedWidth = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
|
|
257925
|
-
const remainingWidth = Math.max(0, effectiveTargetWidth - usedWidth);
|
|
257926
|
-
const missingColumns = maxCellCount - columnWidths.length;
|
|
257927
|
-
const paddingWidth = Math.max(1, Math.floor(remainingWidth / missingColumns));
|
|
257928
|
-
columnWidths.push(...Array.from({ length: missingColumns }, () => paddingWidth));
|
|
257929
|
-
} else if (columnWidths.length > maxCellCount)
|
|
257930
|
-
columnWidths = columnWidths.slice(0, maxCellCount);
|
|
257931
|
-
} else {
|
|
257932
|
-
const columnWidth = Math.max(1, Math.floor(effectiveTargetWidth / maxCellCount));
|
|
257933
|
-
columnWidths = Array.from({ length: maxCellCount }, () => columnWidth);
|
|
257934
|
-
}
|
|
257935
|
-
const isFixedLayout = block.attrs?.tableLayout === "fixed";
|
|
257936
|
-
const gridLooksLikePlaceholder = columnWidths.reduce((a2, b$1) => a2 + b$1, 0) < maxWidth * 0.1;
|
|
257937
|
-
if (!isFixedLayout && gridLooksLikePlaceholder) {
|
|
257938
|
-
const gridColCount = columnWidths.length;
|
|
257939
|
-
const maxContentWidths = new Array(gridColCount).fill(0);
|
|
257940
|
-
const autoFitRowspanTracker = new Array(gridColCount).fill(0);
|
|
257941
|
-
for (const row2 of block.rows) {
|
|
257942
|
-
let colIndex = 0;
|
|
257943
|
-
for (const cell2 of row2.cells) {
|
|
257944
|
-
const colspan = cell2.colSpan ?? 1;
|
|
257945
|
-
const rowspan = cell2.rowSpan ?? 1;
|
|
257946
|
-
while (colIndex < gridColCount && autoFitRowspanTracker[colIndex] > 0) {
|
|
257947
|
-
autoFitRowspanTracker[colIndex]--;
|
|
257948
|
-
colIndex++;
|
|
257949
|
-
}
|
|
257950
|
-
if (colIndex >= gridColCount)
|
|
257951
|
-
break;
|
|
257952
|
-
if (colspan === 1) {
|
|
257953
|
-
const cellPadding = cell2.attrs?.padding ?? DEFAULT_CELL_PADDING;
|
|
257954
|
-
const paddingH = (cellPadding.left ?? 4) + (cellPadding.right ?? 4);
|
|
257955
|
-
const cellBlocks = cell2.blocks ?? (cell2.paragraph ? [cell2.paragraph] : []);
|
|
257956
|
-
let cellMaxWidth = 0;
|
|
257957
|
-
for (const cellBlock of cellBlocks) {
|
|
257958
|
-
const maxMeasure = await measureBlock(cellBlock, {
|
|
257959
|
-
maxWidth: 99999,
|
|
257960
|
-
maxHeight: Infinity
|
|
257961
|
-
});
|
|
257962
|
-
let blockMaxWidth = 0;
|
|
257963
|
-
if (maxMeasure.kind === "paragraph") {
|
|
257964
|
-
for (const line of maxMeasure.lines)
|
|
257965
|
-
if (line.width > blockMaxWidth)
|
|
257966
|
-
blockMaxWidth = line.width;
|
|
257967
|
-
} else if (maxMeasure.kind === "image" || maxMeasure.kind === "drawing")
|
|
257968
|
-
blockMaxWidth = maxMeasure.width;
|
|
257969
|
-
else if (maxMeasure.kind === "table")
|
|
257970
|
-
blockMaxWidth = maxMeasure.totalWidth;
|
|
257971
|
-
else if (maxMeasure.kind === "list") {
|
|
257972
|
-
for (const item of maxMeasure.items)
|
|
257973
|
-
if (item.paragraph) {
|
|
257974
|
-
const gutterWidth = (item.indentLeft ?? 0) + (item.markerWidth ?? 0);
|
|
257975
|
-
for (const line of item.paragraph.lines) {
|
|
257976
|
-
const lineTotal = gutterWidth + line.width;
|
|
257977
|
-
if (lineTotal > blockMaxWidth)
|
|
257978
|
-
blockMaxWidth = lineTotal;
|
|
257979
|
-
}
|
|
257980
|
-
}
|
|
257981
|
-
}
|
|
257982
|
-
if (blockMaxWidth > cellMaxWidth)
|
|
257983
|
-
cellMaxWidth = blockMaxWidth;
|
|
257984
|
-
}
|
|
257985
|
-
const totalWidth$1 = cellMaxWidth + paddingH;
|
|
257986
|
-
if (totalWidth$1 > maxContentWidths[colIndex])
|
|
257987
|
-
maxContentWidths[colIndex] = totalWidth$1;
|
|
257988
|
-
}
|
|
257989
|
-
if (rowspan > 1)
|
|
257990
|
-
for (let c = 0;c < colspan && colIndex + c < gridColCount; c++)
|
|
257991
|
-
autoFitRowspanTracker[colIndex + c] = rowspan - 1;
|
|
257992
|
-
colIndex += colspan;
|
|
257993
|
-
}
|
|
257994
|
-
for (let col = colIndex;col < gridColCount; col++)
|
|
257995
|
-
if (autoFitRowspanTracker[col] > 0)
|
|
257996
|
-
autoFitRowspanTracker[col]--;
|
|
257997
|
-
}
|
|
257998
|
-
const contentTotal = maxContentWidths.reduce((a2, b$1) => a2 + b$1, 0);
|
|
257999
|
-
if (contentTotal > 0)
|
|
258000
|
-
if (contentTotal <= maxWidth) {
|
|
258001
|
-
for (let i4 = 0;i4 < gridColCount; i4++)
|
|
258002
|
-
if (maxContentWidths[i4] > columnWidths[i4])
|
|
258003
|
-
columnWidths[i4] = maxContentWidths[i4];
|
|
258004
|
-
const expandedTotal = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
|
|
258005
|
-
if (expandedTotal > maxWidth && gridColCount > 0) {
|
|
258006
|
-
const scale = maxWidth / expandedTotal;
|
|
258007
|
-
for (let i4 = 0;i4 < gridColCount; i4++)
|
|
258008
|
-
columnWidths[i4] = Math.max(1, Math.round(columnWidths[i4] * scale));
|
|
258009
|
-
const scaledSum = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
|
|
258010
|
-
if (scaledSum !== maxWidth) {
|
|
258011
|
-
const diff = maxWidth - scaledSum;
|
|
258012
|
-
columnWidths[gridColCount - 1] = Math.max(1, columnWidths[gridColCount - 1] + diff);
|
|
258013
|
-
}
|
|
258014
|
-
}
|
|
258015
|
-
} else {
|
|
258016
|
-
const scale = maxWidth / contentTotal;
|
|
258017
|
-
for (let i4 = 0;i4 < gridColCount; i4++)
|
|
258018
|
-
columnWidths[i4] = Math.max(1, Math.round(maxContentWidths[i4] * scale));
|
|
258019
|
-
const scaledSum = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
|
|
258020
|
-
if (scaledSum !== maxWidth && gridColCount > 0) {
|
|
258021
|
-
const diff = maxWidth - scaledSum;
|
|
258022
|
-
columnWidths[gridColCount - 1] = Math.max(1, columnWidths[gridColCount - 1] + diff);
|
|
258023
|
-
}
|
|
258024
|
-
}
|
|
258025
|
-
}
|
|
259436
|
+
const workingInput = buildAutoFitWorkingGridInput(block, { maxWidth: typeof constraints === "number" ? constraints : constraints.maxWidth });
|
|
259437
|
+
const columnWidths = await resolveRuntimeTableColumnWidths(block, workingInput);
|
|
258026
259438
|
const gridColumnCount = columnWidths.length;
|
|
258027
259439
|
const calculateCellWidth = (startCol, colspan) => {
|
|
258028
259440
|
let width = 0;
|
|
@@ -258036,11 +259448,19 @@ async function measureTableBlock(block, constraints) {
|
|
|
258036
259448
|
const spanConstraints = [];
|
|
258037
259449
|
for (let rowIndex = 0;rowIndex < block.rows.length; rowIndex++) {
|
|
258038
259450
|
const row2 = block.rows[rowIndex];
|
|
259451
|
+
const normalizedRow = workingInput.rows[rowIndex];
|
|
258039
259452
|
const cellMeasures = [];
|
|
258040
259453
|
let gridColIndex = 0;
|
|
258041
|
-
for (
|
|
259454
|
+
for (let cellIndex = 0;cellIndex < row2.cells.length; cellIndex++) {
|
|
259455
|
+
const cell2 = row2.cells[cellIndex];
|
|
258042
259456
|
const colspan = cell2.colSpan ?? 1;
|
|
258043
259457
|
const rowspan = cell2.rowSpan ?? 1;
|
|
259458
|
+
const preferredStartColumn = normalizedRow?.cells?.[cellIndex]?.startColumn ?? gridColIndex;
|
|
259459
|
+
while (gridColIndex < gridColumnCount && gridColIndex < preferredStartColumn) {
|
|
259460
|
+
if (rowspanTracker[gridColIndex] > 0)
|
|
259461
|
+
rowspanTracker[gridColIndex]--;
|
|
259462
|
+
gridColIndex++;
|
|
259463
|
+
}
|
|
258044
259464
|
while (gridColIndex < gridColumnCount && rowspanTracker[gridColIndex] > 0) {
|
|
258045
259465
|
rowspanTracker[gridColIndex]--;
|
|
258046
259466
|
gridColIndex++;
|
|
@@ -258143,18 +259563,48 @@ async function measureTableBlock(block, constraints) {
|
|
|
258143
259563
|
const borderWidthH = tableBorderWidths.left + tableBorderWidths.right;
|
|
258144
259564
|
const borderWidthV = tableBorderWidths.top + tableBorderWidths.bottom;
|
|
258145
259565
|
const includeOuterBordersInTotal = (block.attrs?.borderCollapse ?? (block.attrs?.cellSpacing != null ? "separate" : "collapse")) === "separate";
|
|
258146
|
-
const totalWidth = contentWidth + horizontalGaps + (includeOuterBordersInTotal ? borderWidthH : 0);
|
|
258147
|
-
const totalHeight = contentHeight + verticalGaps + (includeOuterBordersInTotal ? borderWidthV : 0);
|
|
258148
259566
|
return {
|
|
258149
259567
|
kind: "table",
|
|
258150
259568
|
rows,
|
|
258151
259569
|
columnWidths,
|
|
258152
|
-
totalWidth,
|
|
258153
|
-
totalHeight,
|
|
259570
|
+
totalWidth: contentWidth + horizontalGaps + (includeOuterBordersInTotal ? borderWidthH : 0),
|
|
259571
|
+
totalHeight: contentHeight + verticalGaps + (includeOuterBordersInTotal ? borderWidthV : 0),
|
|
258154
259572
|
cellSpacingPx: cellSpacingPx > 0 ? cellSpacingPx : undefined,
|
|
258155
259573
|
tableBorderWidths: borderWidthH > 0 || borderWidthV > 0 ? tableBorderWidths : undefined
|
|
258156
259574
|
};
|
|
258157
259575
|
}
|
|
259576
|
+
async function resolveRuntimeTableColumnWidths(block, workingInput) {
|
|
259577
|
+
const fixedLayout = computeFixedTableColumnWidths(workingInput);
|
|
259578
|
+
if (workingInput.layoutMode === "fixed")
|
|
259579
|
+
return fixedLayout.columnWidths;
|
|
259580
|
+
const { contentMetrics, cellMetricKeys } = await buildMeasuredAutoFitContentMetrics(block, workingInput, fixedLayout);
|
|
259581
|
+
const cacheKey = buildAutoFitTableResultCacheKey(block, {
|
|
259582
|
+
maxWidth: workingInput.maxTableWidth,
|
|
259583
|
+
cellMetricKeys,
|
|
259584
|
+
workingInput,
|
|
259585
|
+
fixedLayout
|
|
259586
|
+
});
|
|
259587
|
+
const cached2 = getCachedAutoFitTableResult(cacheKey);
|
|
259588
|
+
if (cached2)
|
|
259589
|
+
return cached2.columnWidths;
|
|
259590
|
+
const result = computeAutoFitColumnWidths({
|
|
259591
|
+
workingInput,
|
|
259592
|
+
fixedLayout,
|
|
259593
|
+
contentMetrics: { rowMetrics: contentMetrics.rowMetrics }
|
|
259594
|
+
});
|
|
259595
|
+
setCachedAutoFitTableResult(cacheKey, {
|
|
259596
|
+
columnWidths: result.columnWidths,
|
|
259597
|
+
totalWidth: result.totalWidth
|
|
259598
|
+
});
|
|
259599
|
+
return result.columnWidths;
|
|
259600
|
+
}
|
|
259601
|
+
async function buildMeasuredAutoFitContentMetrics(block, workingInput, fixedLayout) {
|
|
259602
|
+
const contentMetrics = await measureTableAutoFitContentMetrics(block, workingInput, fixedLayout, measureBlock);
|
|
259603
|
+
return {
|
|
259604
|
+
contentMetrics,
|
|
259605
|
+
cellMetricKeys: contentMetrics.cellMetricKeys
|
|
259606
|
+
};
|
|
259607
|
+
}
|
|
258158
259608
|
async function measureImageBlock(block, constraints) {
|
|
258159
259609
|
const intrinsic = getIntrinsicImageSize(block, constraints.maxWidth);
|
|
258160
259610
|
const isBlockBehindDoc = block.anchor?.behindDoc;
|
|
@@ -259007,7 +260457,7 @@ var Node$13 = class Node$14 {
|
|
|
259007
260457
|
"iPhone",
|
|
259008
260458
|
"iPod"
|
|
259009
260459
|
].includes(navigator.platform);
|
|
259010
|
-
}, OOXML_PCT_DIVISOR = 5000, TWIPS_PER_PX$
|
|
260460
|
+
}, 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) => {
|
|
259011
260461
|
if (!run2 || typeof run2 !== "object")
|
|
259012
260462
|
return false;
|
|
259013
260463
|
return typeof run2.src === "string";
|
|
@@ -278578,9 +280028,17 @@ menclose::after {
|
|
|
278578
280028
|
inlineBorders = normalizeTableBorders(tableProps.borders);
|
|
278579
280029
|
if (typeof tableProps.justification === "string")
|
|
278580
280030
|
hydration.justification = tableProps.justification;
|
|
280031
|
+
const tableIndent = normalizeTableIndent(tableProps.tableIndent);
|
|
280032
|
+
if (tableIndent)
|
|
280033
|
+
hydration.tableIndent = tableIndent;
|
|
280034
|
+
if (typeof tableProps.tableLayout === "string")
|
|
280035
|
+
hydration.tableLayout = tableProps.tableLayout;
|
|
278581
280036
|
const tableWidth = normalizeTableWidth(tableProps.tableWidth);
|
|
278582
280037
|
if (tableWidth)
|
|
278583
280038
|
hydration.tableWidth = tableWidth;
|
|
280039
|
+
const tableCellSpacing = normalizeTableSpacing(tableProps.tableCellSpacing);
|
|
280040
|
+
if (tableCellSpacing)
|
|
280041
|
+
hydration.tableCellSpacing = tableCellSpacing;
|
|
278584
280042
|
}
|
|
278585
280043
|
const styleId = effectiveStyleId === null ? undefined : effectiveStyleId ?? (typeof tableNode.attrs?.tableStyleId === "string" ? tableNode.attrs.tableStyleId : undefined);
|
|
278586
280044
|
if (styleId && context?.translatedLinkedStyles) {
|
|
@@ -278607,8 +280065,18 @@ menclose::after {
|
|
|
278607
280065
|
hydration.cellPadding = inlinePadding;
|
|
278608
280066
|
if (!hydration.justification && resolved.justification)
|
|
278609
280067
|
hydration.justification = resolved.justification;
|
|
278610
|
-
if (resolved.
|
|
278611
|
-
|
|
280068
|
+
if (!hydration.tableIndent && resolved.tableIndent) {
|
|
280069
|
+
const tableIndent = normalizeTableIndent(resolved.tableIndent);
|
|
280070
|
+
if (tableIndent)
|
|
280071
|
+
hydration.tableIndent = tableIndent;
|
|
280072
|
+
}
|
|
280073
|
+
if (!hydration.tableLayout && resolved.tableLayout)
|
|
280074
|
+
hydration.tableLayout = resolved.tableLayout;
|
|
280075
|
+
if (!hydration.tableCellSpacing && resolved.tableCellSpacing) {
|
|
280076
|
+
const tableCellSpacing = normalizeTableSpacing(resolved.tableCellSpacing);
|
|
280077
|
+
if (tableCellSpacing)
|
|
280078
|
+
hydration.tableCellSpacing = tableCellSpacing;
|
|
280079
|
+
}
|
|
278612
280080
|
if (!hydration.tableWidth && resolved.tableWidth) {
|
|
278613
280081
|
const tableWidth = normalizeTableWidth(resolved.tableWidth);
|
|
278614
280082
|
if (tableWidth)
|
|
@@ -278706,7 +280174,41 @@ menclose::after {
|
|
|
278706
280174
|
width: raw,
|
|
278707
280175
|
type: measurement.type
|
|
278708
280176
|
};
|
|
278709
|
-
},
|
|
280177
|
+
}, normalizeTableIndent = (value) => {
|
|
280178
|
+
if (!value || typeof value !== "object")
|
|
280179
|
+
return;
|
|
280180
|
+
const measurement = value;
|
|
280181
|
+
const raw = typeof measurement.width === "number" ? measurement.width : measurement.value;
|
|
280182
|
+
if (typeof raw !== "number")
|
|
280183
|
+
return;
|
|
280184
|
+
if (!measurement.type || measurement.type === "px" || measurement.type === "pixel")
|
|
280185
|
+
return {
|
|
280186
|
+
width: raw,
|
|
280187
|
+
type: measurement.type ?? "px"
|
|
280188
|
+
};
|
|
280189
|
+
if (measurement.type === "dxa")
|
|
280190
|
+
return {
|
|
280191
|
+
width: twipsToPx$2(raw),
|
|
280192
|
+
type: "dxa"
|
|
280193
|
+
};
|
|
280194
|
+
return {
|
|
280195
|
+
width: raw,
|
|
280196
|
+
type: measurement.type
|
|
280197
|
+
};
|
|
280198
|
+
}, normalizeTableSpacing = (value) => {
|
|
280199
|
+
if (!value || typeof value !== "object")
|
|
280200
|
+
return;
|
|
280201
|
+
const measurement = value;
|
|
280202
|
+
if (typeof measurement.value !== "number")
|
|
280203
|
+
return;
|
|
280204
|
+
return {
|
|
280205
|
+
value: measurement.value,
|
|
280206
|
+
type: measurement.type ?? "px"
|
|
280207
|
+
};
|
|
280208
|
+
}, isTableRowNode = (node2) => node2.type === "tableRow" || node2.type === "table_row", isTableCellNode = (node2) => node2.type === "tableCell" || node2.type === "table_cell" || node2.type === "tableHeader" || node2.type === "table_header", isTableSkipPlaceholderCell = (node2) => {
|
|
280209
|
+
const placeholder = node2.attrs?.__placeholder;
|
|
280210
|
+
return placeholder === "gridBefore" || placeholder === "gridAfter";
|
|
280211
|
+
}, convertResolvedCellBorder = (value) => {
|
|
278710
280212
|
if (!value || typeof value !== "object")
|
|
278711
280213
|
return;
|
|
278712
280214
|
const border = value;
|
|
@@ -278974,6 +280476,8 @@ menclose::after {
|
|
|
278974
280476
|
const cells = [];
|
|
278975
280477
|
const rowCnfStyle = rowNode.attrs?.tableRowProperties?.cnfStyle;
|
|
278976
280478
|
rowNode.content.forEach((cellNode, cellIndex) => {
|
|
280479
|
+
if (isTableCellNode(cellNode) && isTableSkipPlaceholderCell(cellNode))
|
|
280480
|
+
return;
|
|
278977
280481
|
const parsedCell = parseTableCell({
|
|
278978
280482
|
cellNode,
|
|
278979
280483
|
rowIndex,
|
|
@@ -279324,7 +280828,7 @@ menclose::after {
|
|
|
279324
280828
|
return true;
|
|
279325
280829
|
}
|
|
279326
280830
|
return false;
|
|
279327
|
-
}, capitalizeText$
|
|
280831
|
+
}, capitalizeText$3 = (text5) => {
|
|
279328
280832
|
if (!text5)
|
|
279329
280833
|
return text5;
|
|
279330
280834
|
let result = "";
|
|
@@ -279334,7 +280838,7 @@ menclose::after {
|
|
|
279334
280838
|
result += isWordChar$3(ch) && !isWordChar$3(prevChar) ? ch.toUpperCase() : ch;
|
|
279335
280839
|
}
|
|
279336
280840
|
return result;
|
|
279337
|
-
}, applyTextTransform$
|
|
280841
|
+
}, applyTextTransform$3 = (text5, transform2) => {
|
|
279338
280842
|
if (!text5 || !transform2 || transform2 === "none")
|
|
279339
280843
|
return text5;
|
|
279340
280844
|
if (transform2 === "uppercase")
|
|
@@ -279342,7 +280846,7 @@ menclose::after {
|
|
|
279342
280846
|
if (transform2 === "lowercase")
|
|
279343
280847
|
return text5.toLowerCase();
|
|
279344
280848
|
if (transform2 === "capitalize")
|
|
279345
|
-
return capitalizeText$
|
|
280849
|
+
return capitalizeText$3(text5);
|
|
279346
280850
|
return text5;
|
|
279347
280851
|
}, countSpaces = (text5) => {
|
|
279348
280852
|
let spaces = 0;
|
|
@@ -280130,7 +281634,7 @@ menclose::after {
|
|
|
280130
281634
|
return false;
|
|
280131
281635
|
const code7 = char.charCodeAt(0);
|
|
280132
281636
|
return code7 >= 48 && code7 <= 57 || code7 >= 65 && code7 <= 90 || code7 >= 97 && code7 <= 122 || char === "'";
|
|
280133
|
-
}, capitalizeText$
|
|
281637
|
+
}, capitalizeText$2 = (text5, fullText, startOffset) => {
|
|
280134
281638
|
if (!text5)
|
|
280135
281639
|
return text5;
|
|
280136
281640
|
const hasFullText = typeof startOffset === "number" && fullText != null;
|
|
@@ -280141,7 +281645,7 @@ menclose::after {
|
|
|
280141
281645
|
result += isWordChar$1(ch) && !isWordChar$1(prevChar) ? ch.toUpperCase() : ch;
|
|
280142
281646
|
}
|
|
280143
281647
|
return result;
|
|
280144
|
-
}, applyTextTransform$
|
|
281648
|
+
}, applyTextTransform$2 = (text5, transform2, fullText, startOffset) => {
|
|
280145
281649
|
if (!text5 || !transform2 || transform2 === "none")
|
|
280146
281650
|
return text5;
|
|
280147
281651
|
if (transform2 === "uppercase")
|
|
@@ -280149,9 +281653,9 @@ menclose::after {
|
|
|
280149
281653
|
if (transform2 === "lowercase")
|
|
280150
281654
|
return text5.toLowerCase();
|
|
280151
281655
|
if (transform2 === "capitalize")
|
|
280152
|
-
return capitalizeText$
|
|
281656
|
+
return capitalizeText$2(text5, fullText, startOffset);
|
|
280153
281657
|
return text5;
|
|
280154
|
-
}, DEFAULT_TAB_INTERVAL_TWIPS$1 = 720, TWIPS_PER_PX$
|
|
281658
|
+
}, 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) => {
|
|
280155
281659
|
const width = run2.width;
|
|
280156
281660
|
return typeof width === "number" ? width : 0;
|
|
280157
281661
|
}, isLineBreakRun$1 = (run2) => run2.kind === "lineBreak" || run2.kind === "break" && run2.breakType === "line", markerFontString = (run2) => {
|
|
@@ -281759,13 +283263,13 @@ menclose::after {
|
|
|
281759
283263
|
if (startA == null)
|
|
281760
283264
|
return false;
|
|
281761
283265
|
return (endA ?? startA + 1) > startB && startA < endB;
|
|
281762
|
-
}, DEFAULT_CELL_PADDING$
|
|
283266
|
+
}, DEFAULT_CELL_PADDING$2, getCellPaddingFromRow = (cellIdx, row2) => {
|
|
281763
283267
|
const padding = row2?.cells?.[cellIdx]?.attrs?.padding ?? {};
|
|
281764
283268
|
return {
|
|
281765
|
-
top: padding.top ?? DEFAULT_CELL_PADDING$
|
|
281766
|
-
bottom: padding.bottom ?? DEFAULT_CELL_PADDING$
|
|
281767
|
-
left: padding.left ?? DEFAULT_CELL_PADDING$
|
|
281768
|
-
right: padding.right ?? DEFAULT_CELL_PADDING$
|
|
283269
|
+
top: padding.top ?? DEFAULT_CELL_PADDING$2.top,
|
|
283270
|
+
bottom: padding.bottom ?? DEFAULT_CELL_PADDING$2.bottom,
|
|
283271
|
+
left: padding.left ?? DEFAULT_CELL_PADDING$2.left,
|
|
283272
|
+
right: padding.right ?? DEFAULT_CELL_PADDING$2.right
|
|
281769
283273
|
};
|
|
281770
283274
|
}, getCellBlocks = (cell2) => {
|
|
281771
283275
|
if (!cell2)
|
|
@@ -286245,7 +287749,41 @@ menclose::after {
|
|
|
286245
287749
|
}
|
|
286246
287750
|
}, EMUS_PER_INCH = 914400, maxSize = 5000, cache, makeKey = (text5, font, letterSpacing) => {
|
|
286247
287751
|
return `${text5}|${font}|${letterSpacing || 0}`;
|
|
286248
|
-
}, fontMetricsCache, MAX_CACHE_SIZE = 1000, METRICS_TEST_STRING = "MHgypbdlÁÉÍ",
|
|
287752
|
+
}, 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 {
|
|
287753
|
+
constructor(maxSize$1) {
|
|
287754
|
+
this.cache = /* @__PURE__ */ new Map;
|
|
287755
|
+
this.maxSize = maxSize$1;
|
|
287756
|
+
}
|
|
287757
|
+
get(key2) {
|
|
287758
|
+
const hit = this.cache.get(key2);
|
|
287759
|
+
if (!hit)
|
|
287760
|
+
return;
|
|
287761
|
+
this.cache.delete(key2);
|
|
287762
|
+
this.cache.set(key2, hit);
|
|
287763
|
+
return hit.value;
|
|
287764
|
+
}
|
|
287765
|
+
set(key2, value) {
|
|
287766
|
+
this.cache.set(key2, { value });
|
|
287767
|
+
this.evictIfNeeded();
|
|
287768
|
+
}
|
|
287769
|
+
clear() {
|
|
287770
|
+
this.cache.clear();
|
|
287771
|
+
}
|
|
287772
|
+
resize(nextSize) {
|
|
287773
|
+
if (!Number.isFinite(nextSize) || nextSize <= 0)
|
|
287774
|
+
return;
|
|
287775
|
+
this.maxSize = nextSize;
|
|
287776
|
+
this.evictIfNeeded();
|
|
287777
|
+
}
|
|
287778
|
+
evictIfNeeded() {
|
|
287779
|
+
while (this.cache.size > this.maxSize) {
|
|
287780
|
+
const oldestKey = this.cache.keys().next().value;
|
|
287781
|
+
if (oldestKey === undefined)
|
|
287782
|
+
break;
|
|
287783
|
+
this.cache.delete(oldestKey);
|
|
287784
|
+
}
|
|
287785
|
+
}
|
|
287786
|
+
}, 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) => {
|
|
286249
287787
|
if (isValidFontSize(value))
|
|
286250
287788
|
return value;
|
|
286251
287789
|
if (typeof value === "string") {
|
|
@@ -288076,12 +289614,12 @@ menclose::after {
|
|
|
288076
289614
|
return;
|
|
288077
289615
|
console.log(...args$1);
|
|
288078
289616
|
}, 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;
|
|
288079
|
-
var
|
|
289617
|
+
var init_src_Dinif16O_es = __esm(() => {
|
|
288080
289618
|
init_rolldown_runtime_Bg48TavK_es();
|
|
288081
|
-
|
|
289619
|
+
init_SuperConverter_Dchjy0My_es();
|
|
288082
289620
|
init_jszip_C49i9kUs_es();
|
|
288083
289621
|
init_uuid_qzgm05fK_es();
|
|
288084
|
-
|
|
289622
|
+
init_create_headless_toolbar_CEcVKzGV_es();
|
|
288085
289623
|
init_constants_DrU4EASo_es();
|
|
288086
289624
|
init_dist_B8HfvhaK_es();
|
|
288087
289625
|
init_unified_Dsuw2be5_es();
|
|
@@ -314784,7 +316322,7 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
314784
316322
|
"even",
|
|
314785
316323
|
"odd"
|
|
314786
316324
|
];
|
|
314787
|
-
TWIPS_PER_PX$
|
|
316325
|
+
TWIPS_PER_PX$2 = 1440 / 96;
|
|
314788
316326
|
init_dist();
|
|
314789
316327
|
measureCache = new MeasureCache;
|
|
314790
316328
|
headerMeasureCache = new HeaderFooterLayoutCache;
|
|
@@ -314813,7 +316351,7 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
314813
316351
|
workerRoundTrip: 10,
|
|
314814
316352
|
layoutStaleness: 100
|
|
314815
316353
|
});
|
|
314816
|
-
DEFAULT_CELL_PADDING$
|
|
316354
|
+
DEFAULT_CELL_PADDING$2 = {
|
|
314817
316355
|
top: 0,
|
|
314818
316356
|
bottom: 0,
|
|
314819
316357
|
left: 4,
|
|
@@ -319420,6 +320958,16 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
319420
320958
|
EMUS_PER_INCH / 96;
|
|
319421
320959
|
cache = /* @__PURE__ */ new Map;
|
|
319422
320960
|
fontMetricsCache = /* @__PURE__ */ new Map;
|
|
320961
|
+
DEFAULT_CELL_PADDING$1 = {
|
|
320962
|
+
top: 0,
|
|
320963
|
+
right: 4,
|
|
320964
|
+
bottom: 0,
|
|
320965
|
+
left: 4
|
|
320966
|
+
};
|
|
320967
|
+
NO_WRAP_MAX_WIDTH = Number.MAX_SAFE_INTEGER;
|
|
320968
|
+
TOKEN_BOUNDARY_PATTERN = /[ \t\f\v\-\u00ad\u2010\u2012\u2013\u2014\u200b\u2028\u2029]+|\r\n|\r|\n|\u2028|\u2029/gu;
|
|
320969
|
+
tableCellMetricsCache = new LruCache(TABLE_CELL_METRICS_CACHE_SIZE);
|
|
320970
|
+
autoFitTableResultCache = new LruCache(TABLE_AUTOFIT_RESULT_CACHE_SIZE);
|
|
319423
320971
|
({ computeTabStops } = engines_exports);
|
|
319424
320972
|
measurementConfig = {
|
|
319425
320973
|
mode: "browser",
|
|
@@ -325292,11 +326840,11 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
325292
326840
|
];
|
|
325293
326841
|
});
|
|
325294
326842
|
|
|
325295
|
-
// ../../packages/superdoc/dist/chunks/create-super-doc-ui-
|
|
326843
|
+
// ../../packages/superdoc/dist/chunks/create-super-doc-ui-HW4PZyuU.es.js
|
|
325296
326844
|
var ALL_TOOLBAR_COMMAND_IDS, EMPTY_ACTIVE_IDS;
|
|
325297
|
-
var
|
|
325298
|
-
|
|
325299
|
-
|
|
326845
|
+
var init_create_super_doc_ui_HW4PZyuU_es = __esm(() => {
|
|
326846
|
+
init_SuperConverter_Dchjy0My_es();
|
|
326847
|
+
init_create_headless_toolbar_CEcVKzGV_es();
|
|
325300
326848
|
ALL_TOOLBAR_COMMAND_IDS = Object.keys(createToolbarRegistry());
|
|
325301
326849
|
EMPTY_ACTIVE_IDS = Object.freeze([]);
|
|
325302
326850
|
});
|
|
@@ -325314,16 +326862,16 @@ var init_zipper_BxRAi0_5_es = __esm(() => {
|
|
|
325314
326862
|
|
|
325315
326863
|
// ../../packages/superdoc/dist/super-editor.es.js
|
|
325316
326864
|
var init_super_editor_es = __esm(() => {
|
|
325317
|
-
|
|
325318
|
-
|
|
326865
|
+
init_src_Dinif16O_es();
|
|
326866
|
+
init_SuperConverter_Dchjy0My_es();
|
|
325319
326867
|
init_jszip_C49i9kUs_es();
|
|
325320
326868
|
init_xml_js_CqGKpaft_es();
|
|
325321
|
-
|
|
326869
|
+
init_create_headless_toolbar_CEcVKzGV_es();
|
|
325322
326870
|
init_constants_DrU4EASo_es();
|
|
325323
326871
|
init_dist_B8HfvhaK_es();
|
|
325324
326872
|
init_unified_Dsuw2be5_es();
|
|
325325
326873
|
init_DocxZipper_CUX64E5K_es();
|
|
325326
|
-
|
|
326874
|
+
init_create_super_doc_ui_HW4PZyuU_es();
|
|
325327
326875
|
init_ui_CGB3qmy3_es();
|
|
325328
326876
|
init_eventemitter3_BJrNoN9D_es();
|
|
325329
326877
|
init_errors_C_DoKMoN_es();
|
|
@@ -408763,10 +410311,38 @@ var DEFAULT_PAGE_WIDTH_TWIPS = 12240, DEFAULT_PAGE_MARGIN_TWIPS = 1440, DEFAULT_
|
|
|
408763
410311
|
return twipsToPixels4(widthTwips);
|
|
408764
410312
|
}
|
|
408765
410313
|
return null;
|
|
410314
|
+
}, getRawRowGridMetadata2 = (row2) => {
|
|
410315
|
+
const trPr = row2?.elements?.find((element3) => element3.name === "w:trPr");
|
|
410316
|
+
const getChild = (name) => trPr?.elements?.find((element3) => element3.name === name);
|
|
410317
|
+
const parseCount = (name) => {
|
|
410318
|
+
const rawValue = getChild(name)?.attributes?.["w:val"];
|
|
410319
|
+
const value = typeof rawValue === "number" ? rawValue : Number.parseInt(rawValue || "0", 10);
|
|
410320
|
+
return Number.isFinite(value) && value > 0 ? value : 0;
|
|
410321
|
+
};
|
|
410322
|
+
const parseMeasurement = (name) => {
|
|
410323
|
+
const node4 = getChild(name);
|
|
410324
|
+
if (!node4?.attributes)
|
|
410325
|
+
return null;
|
|
410326
|
+
const rawValue = node4.attributes["w:w"];
|
|
410327
|
+
const value = typeof rawValue === "number" ? rawValue : Number.parseInt(rawValue || "", 10);
|
|
410328
|
+
if (!Number.isFinite(value) || value <= 0)
|
|
410329
|
+
return null;
|
|
410330
|
+
return {
|
|
410331
|
+
value,
|
|
410332
|
+
type: node4.attributes["w:type"] || "dxa"
|
|
410333
|
+
};
|
|
410334
|
+
};
|
|
410335
|
+
return {
|
|
410336
|
+
gridBefore: parseCount("w:gridBefore"),
|
|
410337
|
+
gridAfter: parseCount("w:gridAfter"),
|
|
410338
|
+
wBefore: parseMeasurement("w:wBefore"),
|
|
410339
|
+
wAfter: parseMeasurement("w:wAfter")
|
|
410340
|
+
};
|
|
408766
410341
|
}, countColumnsInRow2 = (row2) => {
|
|
408767
410342
|
if (!row2?.elements?.length)
|
|
408768
410343
|
return 0;
|
|
408769
|
-
|
|
410344
|
+
const { gridBefore, gridAfter } = getRawRowGridMetadata2(row2);
|
|
410345
|
+
const cellSpanCount = row2.elements.reduce((count, element3) => {
|
|
408770
410346
|
if (element3.name !== "w:tc")
|
|
408771
410347
|
return count;
|
|
408772
410348
|
const tcPr = element3.elements?.find((el) => el.name === "w:tcPr");
|
|
@@ -408774,9 +410350,47 @@ var DEFAULT_PAGE_WIDTH_TWIPS = 12240, DEFAULT_PAGE_MARGIN_TWIPS = 1440, DEFAULT_
|
|
|
408774
410350
|
const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
|
|
408775
410351
|
return count + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
|
|
408776
410352
|
}, 0);
|
|
408777
|
-
|
|
408778
|
-
|
|
408779
|
-
|
|
410353
|
+
return gridBefore + cellSpanCount + gridAfter;
|
|
410354
|
+
}, clampColumnWidthTwips2 = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS2), resolveSkippedColumnSeedWidthsTwips2 = (measurement, span) => {
|
|
410355
|
+
if (!measurement || !Number.isFinite(span) || span <= 0)
|
|
410356
|
+
return [];
|
|
410357
|
+
const resolvedPx = resolveMeasurementWidthPx2(measurement);
|
|
410358
|
+
if (resolvedPx == null || resolvedPx <= 0)
|
|
410359
|
+
return [];
|
|
410360
|
+
const totalTwips = clampColumnWidthTwips2(pixelsToTwips2(resolvedPx));
|
|
410361
|
+
const baseWidth = Math.floor(totalTwips / span);
|
|
410362
|
+
const remainder = totalTwips - baseWidth * span;
|
|
410363
|
+
return Array.from({ length: span }, (_3, index3) => clampColumnWidthTwips2(baseWidth + (index3 < remainder ? 1 : 0)));
|
|
410364
|
+
}, buildFallbackColumnWidthTwips2 = ({ columnCount, totalWidthTwips, rows }) => {
|
|
410365
|
+
const seededWidths = new Array(columnCount).fill(null);
|
|
410366
|
+
for (const row2 of rows) {
|
|
410367
|
+
const { gridBefore, gridAfter, wBefore, wAfter } = getRawRowGridMetadata2(row2);
|
|
410368
|
+
if (gridBefore > 0) {
|
|
410369
|
+
const beforeWidths = resolveSkippedColumnSeedWidthsTwips2(wBefore, gridBefore);
|
|
410370
|
+
beforeWidths.forEach((widthTwips, index3) => {
|
|
410371
|
+
if (index3 < columnCount) {
|
|
410372
|
+
seededWidths[index3] = Math.max(seededWidths[index3] ?? 0, widthTwips);
|
|
410373
|
+
}
|
|
410374
|
+
});
|
|
410375
|
+
}
|
|
410376
|
+
if (gridAfter > 0) {
|
|
410377
|
+
const afterWidths = resolveSkippedColumnSeedWidthsTwips2(wAfter, gridAfter);
|
|
410378
|
+
afterWidths.forEach((widthTwips, index3) => {
|
|
410379
|
+
const targetIndex = columnCount - gridAfter + index3;
|
|
410380
|
+
if (targetIndex >= 0 && targetIndex < columnCount) {
|
|
410381
|
+
seededWidths[targetIndex] = Math.max(seededWidths[targetIndex] ?? 0, widthTwips);
|
|
410382
|
+
}
|
|
410383
|
+
});
|
|
410384
|
+
}
|
|
410385
|
+
}
|
|
410386
|
+
const seededTotalTwips = seededWidths.reduce((sum, widthTwips) => sum + (widthTwips ?? 0), 0);
|
|
410387
|
+
const remainingColumns = seededWidths.filter((widthTwips) => widthTwips == null).length;
|
|
410388
|
+
const minimumRemainingTwips = remainingColumns * MIN_COLUMN_WIDTH_TWIPS2;
|
|
410389
|
+
const effectiveTotalTwips = Math.max(totalWidthTwips, seededTotalTwips + minimumRemainingTwips);
|
|
410390
|
+
const defaultRemainingTwips = remainingColumns > 0 ? clampColumnWidthTwips2((effectiveTotalTwips - seededTotalTwips) / remainingColumns) : 0;
|
|
410391
|
+
return seededWidths.map((widthTwips) => clampColumnWidthTwips2(widthTwips ?? defaultRemainingTwips));
|
|
410392
|
+
}, buildFallbackGridForTable2 = ({ params: params3, rows, tableWidth, tableWidthMeasurement }) => {
|
|
410393
|
+
const columnCount = rows.reduce((max3, row2) => Math.max(max3, countColumnsInRow2(row2)), 0);
|
|
408780
410394
|
if (!columnCount)
|
|
408781
410395
|
return null;
|
|
408782
410396
|
const schemaDefaultPx = getSchemaDefaultColumnWidthPx2(params3);
|
|
@@ -408793,12 +410407,16 @@ var DEFAULT_PAGE_WIDTH_TWIPS = 12240, DEFAULT_PAGE_MARGIN_TWIPS = 1440, DEFAULT_
|
|
|
408793
410407
|
if (totalWidthPx == null) {
|
|
408794
410408
|
totalWidthPx = twipsToPixels4(DEFAULT_CONTENT_WIDTH_TWIPS2);
|
|
408795
410409
|
}
|
|
408796
|
-
const
|
|
408797
|
-
const
|
|
408798
|
-
const
|
|
410410
|
+
const minimumColumnWidthTwips = clampColumnWidthTwips2(pixelsToTwips2(minimumColumnWidthPx));
|
|
410411
|
+
const baseTotalWidthTwips = Math.max(clampColumnWidthTwips2(pixelsToTwips2(totalWidthPx)), minimumColumnWidthTwips * columnCount);
|
|
410412
|
+
const fallbackColumnWidthTwips = buildFallbackColumnWidthTwips2({
|
|
410413
|
+
columnCount,
|
|
410414
|
+
totalWidthTwips: baseTotalWidthTwips,
|
|
410415
|
+
rows
|
|
410416
|
+
});
|
|
408799
410417
|
return {
|
|
408800
|
-
grid:
|
|
408801
|
-
columnWidths:
|
|
410418
|
+
grid: fallbackColumnWidthTwips.map((columnWidthTwips) => ({ col: clampColumnWidthTwips2(columnWidthTwips) })),
|
|
410419
|
+
columnWidths: fallbackColumnWidthTwips.map((columnWidthTwips) => twipsToPixels4(columnWidthTwips))
|
|
408802
410420
|
};
|
|
408803
410421
|
};
|
|
408804
410422
|
var init_tableFallbackHelpers = __esm(() => {
|
|
@@ -437158,31 +438776,13 @@ function mapBorderSizes2(borders, sizeMapper) {
|
|
|
437158
438776
|
}
|
|
437159
438777
|
}
|
|
437160
438778
|
|
|
437161
|
-
// ../../packages/super-editor/src/editors/v1/document-api-adapters/
|
|
437162
|
-
function createSeparatorParagraph2(schema) {
|
|
437163
|
-
const paragraphType = schema.nodes.paragraph;
|
|
437164
|
-
if (!paragraphType)
|
|
437165
|
-
return null;
|
|
437166
|
-
const separatorAttrs = {
|
|
437167
|
-
sdBlockId: v42(),
|
|
437168
|
-
paraId: generateDocxHexId2()
|
|
437169
|
-
};
|
|
437170
|
-
return paragraphType.createAndFill(separatorAttrs) ?? paragraphType.createAndFill();
|
|
437171
|
-
}
|
|
437172
|
-
function buildTableSuccess2(tableAddress, trackedChangeRefs) {
|
|
437173
|
-
return {
|
|
437174
|
-
success: true,
|
|
437175
|
-
table: tableAddress,
|
|
437176
|
-
trackedChangeRefs
|
|
437177
|
-
};
|
|
437178
|
-
}
|
|
438779
|
+
// ../../packages/super-editor/src/editors/v1/document-api-adapters/helpers/table-attr-sync.ts
|
|
437179
438780
|
function syncExtractedTableAttrs2(tp) {
|
|
437180
438781
|
const extracted = {};
|
|
437181
438782
|
extracted.tableStyleId = tp.tableStyleId ?? null;
|
|
437182
438783
|
extracted.justification = tp.justification ?? null;
|
|
437183
438784
|
extracted.tableLayout = tp.tableLayout ?? null;
|
|
437184
|
-
|
|
437185
|
-
extracted.borders = pixelBorders ?? tp.borders ?? null;
|
|
438785
|
+
extracted.borders = convertTableBordersToPixelUnits2(tp.borders) ?? {};
|
|
437186
438786
|
const indent3 = tp.tableIndent;
|
|
437187
438787
|
if (indent3?.value != null) {
|
|
437188
438788
|
extracted.tableIndent = {
|
|
@@ -437195,7 +438795,7 @@ function syncExtractedTableAttrs2(tp) {
|
|
|
437195
438795
|
const spacing = tp.tableCellSpacing;
|
|
437196
438796
|
if (spacing?.value != null) {
|
|
437197
438797
|
extracted.tableCellSpacing = {
|
|
437198
|
-
|
|
438798
|
+
value: twipsToPixels4(spacing.value),
|
|
437199
438799
|
type: spacing.type ?? "dxa"
|
|
437200
438800
|
};
|
|
437201
438801
|
extracted.borderCollapse = "separate";
|
|
@@ -437203,15 +438803,15 @@ function syncExtractedTableAttrs2(tp) {
|
|
|
437203
438803
|
extracted.tableCellSpacing = null;
|
|
437204
438804
|
extracted.borderCollapse = null;
|
|
437205
438805
|
}
|
|
437206
|
-
const
|
|
437207
|
-
if (
|
|
437208
|
-
if (
|
|
437209
|
-
extracted.tableWidth = { value:
|
|
437210
|
-
} else if (
|
|
438806
|
+
const width = tp.tableWidth;
|
|
438807
|
+
if (width) {
|
|
438808
|
+
if (width.type === "pct" && typeof width.value === "number") {
|
|
438809
|
+
extracted.tableWidth = { value: width.value, type: "pct" };
|
|
438810
|
+
} else if (width.type === "auto") {
|
|
437211
438811
|
extracted.tableWidth = { width: 0, type: "auto" };
|
|
437212
|
-
} else if (
|
|
437213
|
-
const widthPx = twipsToPixels4(
|
|
437214
|
-
extracted.tableWidth = widthPx != null ? { width: widthPx, type:
|
|
438812
|
+
} else if (width.value != null) {
|
|
438813
|
+
const widthPx = twipsToPixels4(width.value);
|
|
438814
|
+
extracted.tableWidth = widthPx != null ? { width: widthPx, type: width.type } : null;
|
|
437215
438815
|
} else {
|
|
437216
438816
|
extracted.tableWidth = null;
|
|
437217
438817
|
}
|
|
@@ -437227,7 +438827,101 @@ function convertTableBordersToPixelUnits2(value) {
|
|
|
437227
438827
|
mapBorderSizes2(clone2, eighthPointsToPixels2);
|
|
437228
438828
|
return Object.keys(clone2).length > 0 ? clone2 : undefined;
|
|
437229
438829
|
}
|
|
438830
|
+
function buildWidthAuthoringTableAttrs2(currentAttrs, attrOverrides = {}, tablePropertyOverrides = {}) {
|
|
438831
|
+
const currentTableProps = currentAttrs.tableProperties ?? {};
|
|
438832
|
+
const nextTableWidth = resolveWidthAuthoringTableWidth2(currentAttrs, attrOverrides, tablePropertyOverrides);
|
|
438833
|
+
const updatedTableProps = {
|
|
438834
|
+
...currentTableProps,
|
|
438835
|
+
...tablePropertyOverrides,
|
|
438836
|
+
tableLayout: "fixed"
|
|
438837
|
+
};
|
|
438838
|
+
if (nextTableWidth) {
|
|
438839
|
+
updatedTableProps.tableWidth = nextTableWidth;
|
|
438840
|
+
} else {
|
|
438841
|
+
delete updatedTableProps.tableWidth;
|
|
438842
|
+
}
|
|
438843
|
+
return {
|
|
438844
|
+
...currentAttrs,
|
|
438845
|
+
tableProperties: updatedTableProps,
|
|
438846
|
+
...attrOverrides,
|
|
438847
|
+
...syncExtractedTableAttrs2(updatedTableProps),
|
|
438848
|
+
userEdited: true
|
|
438849
|
+
};
|
|
438850
|
+
}
|
|
438851
|
+
function resolveWidthAuthoringTableWidth2(currentAttrs, attrOverrides, tablePropertyOverrides) {
|
|
438852
|
+
const explicitOverride = normalizeTableWidthMeasurement2(tablePropertyOverrides.tableWidth);
|
|
438853
|
+
if (explicitOverride)
|
|
438854
|
+
return explicitOverride;
|
|
438855
|
+
const gridWidth = sumGridColumnTwips2(attrOverrides.grid ?? currentAttrs.grid);
|
|
438856
|
+
if (gridWidth != null) {
|
|
438857
|
+
return { value: gridWidth, type: "dxa" };
|
|
438858
|
+
}
|
|
438859
|
+
return null;
|
|
438860
|
+
}
|
|
438861
|
+
function sumGridColumnTwips2(grid) {
|
|
438862
|
+
const columns = normalizeGridColumns2(grid);
|
|
438863
|
+
if (!columns || columns.length === 0)
|
|
438864
|
+
return null;
|
|
438865
|
+
const total = columns.reduce((sum, column) => sum + column.col, 0);
|
|
438866
|
+
return total > 0 ? total : null;
|
|
438867
|
+
}
|
|
438868
|
+
function normalizeGridColumns2(grid) {
|
|
438869
|
+
if (Array.isArray(grid)) {
|
|
438870
|
+
const columns = grid.map((width) => normalizeGridWidth2(width)).filter((width) => width != null);
|
|
438871
|
+
return columns.length > 0 ? columns : null;
|
|
438872
|
+
}
|
|
438873
|
+
if (grid && typeof grid === "object") {
|
|
438874
|
+
const rawColWidths = grid.colWidths;
|
|
438875
|
+
if (Array.isArray(rawColWidths)) {
|
|
438876
|
+
const columns = rawColWidths.map((width) => normalizeGridWidth2(width)).filter((width) => width != null);
|
|
438877
|
+
return columns.length > 0 ? columns : null;
|
|
438878
|
+
}
|
|
438879
|
+
}
|
|
438880
|
+
return null;
|
|
438881
|
+
}
|
|
437230
438882
|
function normalizeGridWidth2(width) {
|
|
438883
|
+
if (typeof width === "number" && Number.isFinite(width) && width > 0) {
|
|
438884
|
+
return { col: Math.round(width) };
|
|
438885
|
+
}
|
|
438886
|
+
const value = width?.col;
|
|
438887
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0) {
|
|
438888
|
+
return { col: Math.round(value) };
|
|
438889
|
+
}
|
|
438890
|
+
return null;
|
|
438891
|
+
}
|
|
438892
|
+
function normalizeTableWidthMeasurement2(width) {
|
|
438893
|
+
if (!width || typeof width !== "object")
|
|
438894
|
+
return null;
|
|
438895
|
+
const value = width.value;
|
|
438896
|
+
const type = width.type;
|
|
438897
|
+
if (type !== "dxa" || typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
438898
|
+
return null;
|
|
438899
|
+
}
|
|
438900
|
+
return { value: Math.round(value), type: "dxa" };
|
|
438901
|
+
}
|
|
438902
|
+
var init_table_attr_sync = __esm(() => {
|
|
438903
|
+
init_helpers();
|
|
438904
|
+
});
|
|
438905
|
+
|
|
438906
|
+
// ../../packages/super-editor/src/editors/v1/document-api-adapters/tables-adapter.ts
|
|
438907
|
+
function createSeparatorParagraph2(schema) {
|
|
438908
|
+
const paragraphType = schema.nodes.paragraph;
|
|
438909
|
+
if (!paragraphType)
|
|
438910
|
+
return null;
|
|
438911
|
+
const separatorAttrs = {
|
|
438912
|
+
sdBlockId: v42(),
|
|
438913
|
+
paraId: generateDocxHexId2()
|
|
438914
|
+
};
|
|
438915
|
+
return paragraphType.createAndFill(separatorAttrs) ?? paragraphType.createAndFill();
|
|
438916
|
+
}
|
|
438917
|
+
function buildTableSuccess2(tableAddress, trackedChangeRefs) {
|
|
438918
|
+
return {
|
|
438919
|
+
success: true,
|
|
438920
|
+
table: tableAddress,
|
|
438921
|
+
trackedChangeRefs
|
|
438922
|
+
};
|
|
438923
|
+
}
|
|
438924
|
+
function normalizeGridWidth3(width) {
|
|
437231
438925
|
if (typeof width === "number" && Number.isFinite(width)) {
|
|
437232
438926
|
return { col: Math.round(width) };
|
|
437233
438927
|
}
|
|
@@ -437239,16 +438933,16 @@ function normalizeGridWidth2(width) {
|
|
|
437239
438933
|
}
|
|
437240
438934
|
return { col: DEFAULT_TABLE_GRID_WIDTH_TWIPS2 };
|
|
437241
438935
|
}
|
|
437242
|
-
function
|
|
438936
|
+
function normalizeGridColumns3(grid) {
|
|
437243
438937
|
if (Array.isArray(grid)) {
|
|
437244
438938
|
if (grid.length === 0)
|
|
437245
438939
|
return null;
|
|
437246
|
-
return { columns: grid.map((width) =>
|
|
438940
|
+
return { columns: grid.map((width) => normalizeGridWidth3(width)), format: "array" };
|
|
437247
438941
|
}
|
|
437248
438942
|
if (grid && typeof grid === "object") {
|
|
437249
438943
|
const rawColWidths = grid.colWidths;
|
|
437250
438944
|
if (Array.isArray(rawColWidths) && rawColWidths.length > 0) {
|
|
437251
|
-
return { columns: rawColWidths.map((width) =>
|
|
438945
|
+
return { columns: rawColWidths.map((width) => normalizeGridWidth3(width)), format: "object" };
|
|
437252
438946
|
}
|
|
437253
438947
|
}
|
|
437254
438948
|
return null;
|
|
@@ -437260,17 +438954,17 @@ function serializeGridColumns2(originalGrid, normalized) {
|
|
|
437260
438954
|
return { ...originalGrid, colWidths: normalized.columns };
|
|
437261
438955
|
}
|
|
437262
438956
|
function insertGridColumnWidth2(grid, insertIndex) {
|
|
437263
|
-
const normalized =
|
|
438957
|
+
const normalized = normalizeGridColumns3(grid);
|
|
437264
438958
|
if (!normalized)
|
|
437265
438959
|
return null;
|
|
437266
438960
|
const colWidths = normalized.columns.slice();
|
|
437267
438961
|
const boundedIndex = Math.max(0, Math.min(insertIndex, colWidths.length));
|
|
437268
|
-
const template = colWidths[Math.min(boundedIndex, colWidths.length - 1)] ?? colWidths[colWidths.length - 1] ??
|
|
438962
|
+
const template = colWidths[Math.min(boundedIndex, colWidths.length - 1)] ?? colWidths[colWidths.length - 1] ?? normalizeGridWidth3(null);
|
|
437269
438963
|
colWidths.splice(boundedIndex, 0, { ...template });
|
|
437270
438964
|
return serializeGridColumns2(grid, { ...normalized, columns: colWidths });
|
|
437271
438965
|
}
|
|
437272
438966
|
function removeGridColumnWidth2(grid, deleteIndex) {
|
|
437273
|
-
const normalized =
|
|
438967
|
+
const normalized = normalizeGridColumns3(grid);
|
|
437274
438968
|
if (!normalized || normalized.columns.length <= 1)
|
|
437275
438969
|
return null;
|
|
437276
438970
|
const colWidths = normalized.columns.slice();
|
|
@@ -437278,6 +438972,29 @@ function removeGridColumnWidth2(grid, deleteIndex) {
|
|
|
437278
438972
|
colWidths.splice(boundedIndex, 1);
|
|
437279
438973
|
return serializeGridColumns2(grid, { ...normalized, columns: colWidths });
|
|
437280
438974
|
}
|
|
438975
|
+
function buildFirstRowCellWidthProps2(attrs, cellStartCol, colspan, colwidth, gridColumns) {
|
|
438976
|
+
const currentCellProps = attrs.tableCellProperties && typeof attrs.tableCellProperties === "object" ? attrs.tableCellProperties : {};
|
|
438977
|
+
const spanTwips = resolveSpanWidthTwips2(cellStartCol, colspan, colwidth, gridColumns);
|
|
438978
|
+
if (spanTwips == null)
|
|
438979
|
+
return Object.keys(currentCellProps).length > 0 ? currentCellProps : undefined;
|
|
438980
|
+
return {
|
|
438981
|
+
...currentCellProps,
|
|
438982
|
+
cellWidth: { value: spanTwips, type: "dxa" }
|
|
438983
|
+
};
|
|
438984
|
+
}
|
|
438985
|
+
function resolveSpanWidthTwips2(cellStartCol, colspan, colwidth, gridColumns) {
|
|
438986
|
+
const boundedSpan = Math.max(1, colspan);
|
|
438987
|
+
if (Array.isArray(gridColumns) && cellStartCol >= 0 && cellStartCol + boundedSpan <= gridColumns.length) {
|
|
438988
|
+
const gridSpanTwips = gridColumns.slice(cellStartCol, cellStartCol + boundedSpan).reduce((sum, column) => sum + normalizeGridWidth3(column).col, 0);
|
|
438989
|
+
if (gridSpanTwips > 0)
|
|
438990
|
+
return gridSpanTwips;
|
|
438991
|
+
}
|
|
438992
|
+
const spanWidthPx = colwidth.slice(0, boundedSpan).reduce((sum, width) => sum + (Number.isFinite(width) ? width : 0), 0);
|
|
438993
|
+
if (spanWidthPx > 0) {
|
|
438994
|
+
return Math.round(spanWidthPx * PIXELS_TO_TWIPS2);
|
|
438995
|
+
}
|
|
438996
|
+
return;
|
|
438997
|
+
}
|
|
437281
438998
|
function normalizeCellAttrsForSingleCell2(attrs) {
|
|
437282
438999
|
const currentColwidth = Array.isArray(attrs.colwidth) ? attrs.colwidth : null;
|
|
437283
439000
|
const tableCellProperties = {
|
|
@@ -438185,8 +439902,14 @@ function tablesSetColumnWidthAdapter2(editor, input2, options) {
|
|
|
438185
439902
|
const tablePos = table2.candidate.pos;
|
|
438186
439903
|
const tableStart = tablePos + 1;
|
|
438187
439904
|
const tableNode = table2.candidate.node;
|
|
439905
|
+
const tableAttrs = tableNode.attrs;
|
|
438188
439906
|
const map10 = TableMap2.get(tableNode);
|
|
438189
439907
|
const widthPx = Math.round(input2.widthPt * (96 / 72));
|
|
439908
|
+
const normalizedGrid = normalizeGridColumns3(tableAttrs.grid);
|
|
439909
|
+
const nextGridColumns = normalizedGrid?.columns.slice();
|
|
439910
|
+
if (nextGridColumns && columnIndex < nextGridColumns.length) {
|
|
439911
|
+
nextGridColumns[columnIndex] = { col: Math.round(input2.widthPt * POINTS_TO_TWIPS2) };
|
|
439912
|
+
}
|
|
438190
439913
|
const processed = new Set;
|
|
438191
439914
|
for (let row2 = 0;row2 < map10.height; row2++) {
|
|
438192
439915
|
const index3 = row2 * map10.width + columnIndex;
|
|
@@ -438205,19 +439928,22 @@ function tablesSetColumnWidthAdapter2(editor, input2, options) {
|
|
|
438205
439928
|
while (colwidth.length < colspan)
|
|
438206
439929
|
colwidth.push(0);
|
|
438207
439930
|
colwidth[withinCol] = widthPx;
|
|
438208
|
-
|
|
439931
|
+
const nextAttrs = { ...attrs, colwidth };
|
|
439932
|
+
if (row2 === 0) {
|
|
439933
|
+
const nextCellProps = buildFirstRowCellWidthProps2(attrs, cellStartCol, colspan, colwidth, nextGridColumns);
|
|
439934
|
+
if (nextCellProps) {
|
|
439935
|
+
nextAttrs.tableCellProperties = nextCellProps;
|
|
439936
|
+
} else {
|
|
439937
|
+
delete nextAttrs.tableCellProperties;
|
|
439938
|
+
}
|
|
439939
|
+
}
|
|
439940
|
+
tr.setNodeMarkup(tableStart + pos, null, nextAttrs);
|
|
438209
439941
|
}
|
|
438210
|
-
const
|
|
438211
|
-
|
|
438212
|
-
|
|
438213
|
-
const newColumns = normalizedGrid.columns.slice();
|
|
438214
|
-
newColumns[columnIndex] = { col: Math.round(input2.widthPt * POINTS_TO_TWIPS2) };
|
|
438215
|
-
tr.setNodeMarkup(tablePos, null, {
|
|
438216
|
-
...tableAttrs,
|
|
438217
|
-
grid: serializeGridColumns2(tableAttrs.grid, { ...normalizedGrid, columns: newColumns }),
|
|
438218
|
-
userEdited: true
|
|
438219
|
-
});
|
|
439942
|
+
const tableAttrUpdates = {};
|
|
439943
|
+
if (normalizedGrid && nextGridColumns) {
|
|
439944
|
+
tableAttrUpdates.grid = serializeGridColumns2(tableAttrs.grid, { ...normalizedGrid, columns: nextGridColumns });
|
|
438220
439945
|
}
|
|
439946
|
+
tr.setNodeMarkup(tablePos, null, buildWidthAuthoringTableAttrs2(tableAttrs, tableAttrUpdates));
|
|
438221
439947
|
applyDirectMutationMeta2(tr);
|
|
438222
439948
|
editor.dispatch(tr);
|
|
438223
439949
|
clearIndexCache2(editor);
|
|
@@ -438242,7 +439968,10 @@ function tablesDistributeColumnsAdapter2(editor, input2, options) {
|
|
|
438242
439968
|
const tablePos = candidate.pos;
|
|
438243
439969
|
const tableStart = tablePos + 1;
|
|
438244
439970
|
const tableNode = candidate.node;
|
|
439971
|
+
const tableAttrs = tableNode.attrs;
|
|
438245
439972
|
const map10 = TableMap2.get(tableNode);
|
|
439973
|
+
const normalizedGrid = normalizeGridColumns3(tableAttrs.grid);
|
|
439974
|
+
const nextGridColumns = normalizedGrid?.columns.slice();
|
|
438246
439975
|
const rangeStart = input2.columnRange?.start ?? 0;
|
|
438247
439976
|
const rangeEnd = input2.columnRange?.end ?? map10.width - 1;
|
|
438248
439977
|
const rangeWidth = rangeEnd - rangeStart + 1;
|
|
@@ -438258,6 +439987,13 @@ function tablesDistributeColumnsAdapter2(editor, input2, options) {
|
|
|
438258
439987
|
totalWidth += colwidth?.[withinCol] ?? 100;
|
|
438259
439988
|
}
|
|
438260
439989
|
const evenWidth = Math.round(totalWidth / rangeWidth);
|
|
439990
|
+
if (nextGridColumns) {
|
|
439991
|
+
const evenWidthTwips = Math.max(1, Math.round(evenWidth * PIXELS_TO_TWIPS2));
|
|
439992
|
+
const maxColumn = Math.min(rangeEnd, nextGridColumns.length - 1);
|
|
439993
|
+
for (let col = Math.max(rangeStart, 0);col <= maxColumn; col++) {
|
|
439994
|
+
nextGridColumns[col] = { col: evenWidthTwips };
|
|
439995
|
+
}
|
|
439996
|
+
}
|
|
438261
439997
|
const processed = new Set;
|
|
438262
439998
|
for (let row2 = 0;row2 < map10.height; row2++) {
|
|
438263
439999
|
for (let col = rangeStart;col <= rangeEnd; col++) {
|
|
@@ -438281,22 +440017,23 @@ function tablesDistributeColumnsAdapter2(editor, input2, options) {
|
|
|
438281
440017
|
newColwidth[c] = evenWidth;
|
|
438282
440018
|
}
|
|
438283
440019
|
}
|
|
438284
|
-
|
|
440020
|
+
const nextAttrs = { ...attrs, colwidth: newColwidth };
|
|
440021
|
+
if (row2 === 0) {
|
|
440022
|
+
const nextCellProps = buildFirstRowCellWidthProps2(attrs, cellStartCol, colspan, newColwidth, nextGridColumns);
|
|
440023
|
+
if (nextCellProps) {
|
|
440024
|
+
nextAttrs.tableCellProperties = nextCellProps;
|
|
440025
|
+
} else {
|
|
440026
|
+
delete nextAttrs.tableCellProperties;
|
|
440027
|
+
}
|
|
440028
|
+
}
|
|
440029
|
+
tr.setNodeMarkup(tableStart + pos, null, nextAttrs);
|
|
438285
440030
|
}
|
|
438286
440031
|
}
|
|
438287
|
-
const
|
|
438288
|
-
|
|
438289
|
-
|
|
438290
|
-
if (normalizedGrid) {
|
|
438291
|
-
const newColumns = normalizedGrid.columns.slice();
|
|
438292
|
-
const evenWidthTwips = Math.max(1, Math.round(evenWidth * PIXELS_TO_TWIPS2));
|
|
438293
|
-
const maxColumn = Math.min(rangeEnd, newColumns.length - 1);
|
|
438294
|
-
for (let col = Math.max(rangeStart, 0);col <= maxColumn; col++) {
|
|
438295
|
-
newColumns[col] = { col: evenWidthTwips };
|
|
438296
|
-
}
|
|
438297
|
-
tableAttrUpdates.grid = serializeGridColumns2(tableAttrs.grid, { ...normalizedGrid, columns: newColumns });
|
|
440032
|
+
const tableAttrUpdates = {};
|
|
440033
|
+
if (normalizedGrid && nextGridColumns) {
|
|
440034
|
+
tableAttrUpdates.grid = serializeGridColumns2(tableAttrs.grid, { ...normalizedGrid, columns: nextGridColumns });
|
|
438298
440035
|
}
|
|
438299
|
-
tr.setNodeMarkup(tablePos, null, tableAttrUpdates);
|
|
440036
|
+
tr.setNodeMarkup(tablePos, null, buildWidthAuthoringTableAttrs2(tableAttrs, tableAttrUpdates));
|
|
438300
440037
|
applyDirectMutationMeta2(tr);
|
|
438301
440038
|
editor.dispatch(tr);
|
|
438302
440039
|
clearIndexCache2(editor);
|
|
@@ -438942,6 +440679,10 @@ function tablesSetCellPropertiesAdapter2(editor, input2, options) {
|
|
|
438942
440679
|
tableCellProperties: { ...currentCellProps, ...cellPropUpdates }
|
|
438943
440680
|
};
|
|
438944
440681
|
tr.setNodeMarkup(cellPos, null, newAttrs);
|
|
440682
|
+
if (input2.preferredWidthPt !== undefined) {
|
|
440683
|
+
const tableAttrs = table2.candidate.node.attrs;
|
|
440684
|
+
tr.setNodeMarkup(table2.candidate.pos, null, buildWidthAuthoringTableAttrs2(tableAttrs));
|
|
440685
|
+
}
|
|
438945
440686
|
applyDirectMutationMeta2(tr);
|
|
438946
440687
|
editor.dispatch(tr);
|
|
438947
440688
|
clearIndexCache2(editor);
|
|
@@ -440131,10 +441872,10 @@ var init_tables_adapter = __esm(() => {
|
|
|
440131
441872
|
init_tracked_change_refs();
|
|
440132
441873
|
init_errors4();
|
|
440133
441874
|
init_node_address_resolver();
|
|
440134
|
-
init_helpers();
|
|
440135
441875
|
init_ooxml();
|
|
440136
441876
|
init_document_settings();
|
|
440137
441877
|
init_mutate_part();
|
|
441878
|
+
init_table_attr_sync();
|
|
440138
441879
|
POINTS_TO_PIXELS2 = 96 / 72;
|
|
440139
441880
|
PIXELS_TO_TWIPS2 = 1440 / 96;
|
|
440140
441881
|
WORD_DEFAULT_TBL_LOOK2 = {
|