@superdoc-dev/mcp 0.3.0-next.16 → 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 +2333 -415
- package/package.json +3 -3
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) => {
|
|
@@ -198887,6 +198951,18 @@ function calculateTabWidth(params$1) {
|
|
|
198887
198951
|
tabStopPosUsed: nextStop.pos
|
|
198888
198952
|
};
|
|
198889
198953
|
}
|
|
198954
|
+
function resolveTableWidthAttr(value) {
|
|
198955
|
+
if (!value || typeof value !== "object")
|
|
198956
|
+
return null;
|
|
198957
|
+
const measurement = value;
|
|
198958
|
+
const width = measurement.width ?? measurement.value;
|
|
198959
|
+
if (typeof width !== "number" || !Number.isFinite(width) || width <= 0)
|
|
198960
|
+
return null;
|
|
198961
|
+
return {
|
|
198962
|
+
width,
|
|
198963
|
+
type: measurement.type
|
|
198964
|
+
};
|
|
198965
|
+
}
|
|
198890
198966
|
function resolveColumnWidths(columns, availableWidth) {
|
|
198891
198967
|
const width = availableWidth / columns.length;
|
|
198892
198968
|
return columns.map(() => width);
|
|
@@ -198918,7 +198994,7 @@ function getCellSpacingPx(cellSpacing) {
|
|
|
198918
198994
|
const v = cellSpacing.value;
|
|
198919
198995
|
if (typeof v !== "number" || !Number.isFinite(v))
|
|
198920
198996
|
return 0;
|
|
198921
|
-
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;
|
|
198922
198998
|
return Math.max(0, asPx);
|
|
198923
198999
|
}
|
|
198924
199000
|
function coerceRelativeHeight(raw) {
|
|
@@ -213395,7 +213471,8 @@ function executeTextSelector(editor, index2, query, diagnostics) {
|
|
|
213395
213471
|
const rawResult = requireEditorCommand(editor.commands?.search, "find (search)")(pattern, {
|
|
213396
213472
|
highlight: false,
|
|
213397
213473
|
caseSensitive: selector.caseSensitive ?? false,
|
|
213398
|
-
maxMatches: Infinity
|
|
213474
|
+
maxMatches: Infinity,
|
|
213475
|
+
searchModel: "visible"
|
|
213399
213476
|
});
|
|
213400
213477
|
if (!Array.isArray(rawResult))
|
|
213401
213478
|
throw new DocumentApiAdapterError("CAPABILITY_UNAVAILABLE", "Editor search command returned an unexpected result format.");
|
|
@@ -220530,6 +220607,28 @@ function toNotFoundError(input2) {
|
|
|
220530
220607
|
function isSameTarget(left$1, right$1) {
|
|
220531
220608
|
return left$1.blockId === right$1.blockId && left$1.range.start === right$1.range.start && left$1.range.end === right$1.range.end;
|
|
220532
220609
|
}
|
|
220610
|
+
function isTextAddressShape(target) {
|
|
220611
|
+
if (!target || typeof target !== "object")
|
|
220612
|
+
return false;
|
|
220613
|
+
const t = target;
|
|
220614
|
+
if (t.kind !== "text")
|
|
220615
|
+
return false;
|
|
220616
|
+
if (typeof t.blockId !== "string")
|
|
220617
|
+
return false;
|
|
220618
|
+
return isTextRangeShape(t.range);
|
|
220619
|
+
}
|
|
220620
|
+
function isTextRangeShape(range) {
|
|
220621
|
+
if (!range || typeof range !== "object")
|
|
220622
|
+
return false;
|
|
220623
|
+
const r$1 = range;
|
|
220624
|
+
return Number.isInteger(r$1.start) && Number.isInteger(r$1.end) && r$1.start <= r$1.end;
|
|
220625
|
+
}
|
|
220626
|
+
function isTextSegmentShape(segment) {
|
|
220627
|
+
if (!segment || typeof segment !== "object")
|
|
220628
|
+
return false;
|
|
220629
|
+
const seg = segment;
|
|
220630
|
+
return typeof seg.blockId === "string" && isTextRangeShape(seg.range);
|
|
220631
|
+
}
|
|
220533
220632
|
function isTextTargetShape(target) {
|
|
220534
220633
|
if (!target || typeof target !== "object")
|
|
220535
220634
|
return false;
|
|
@@ -220538,17 +220637,19 @@ function isTextTargetShape(target) {
|
|
|
220538
220637
|
return false;
|
|
220539
220638
|
if (!Array.isArray(t.segments) || t.segments.length === 0)
|
|
220540
220639
|
return false;
|
|
220541
|
-
if (
|
|
220640
|
+
if (!t.segments.every(isTextSegmentShape))
|
|
220542
220641
|
return false;
|
|
220543
220642
|
return true;
|
|
220544
220643
|
}
|
|
220545
220644
|
function targetToSegments(target) {
|
|
220645
|
+
if (isTextAddressShape(target))
|
|
220646
|
+
return [{
|
|
220647
|
+
blockId: target.blockId,
|
|
220648
|
+
range: target.range
|
|
220649
|
+
}];
|
|
220546
220650
|
if (isTextTargetShape(target))
|
|
220547
220651
|
return [...target.segments];
|
|
220548
|
-
return
|
|
220549
|
-
blockId: target.blockId,
|
|
220550
|
-
range: target.range
|
|
220551
|
-
}];
|
|
220652
|
+
return null;
|
|
220552
220653
|
}
|
|
220553
220654
|
function listCommentAnchorsSafe(editor) {
|
|
220554
220655
|
try {
|
|
@@ -220766,6 +220867,15 @@ function addCommentHandler(editor, input2, options) {
|
|
|
220766
220867
|
}
|
|
220767
220868
|
};
|
|
220768
220869
|
const segments = targetToSegments(target);
|
|
220870
|
+
if (!segments)
|
|
220871
|
+
return {
|
|
220872
|
+
success: false,
|
|
220873
|
+
failure: {
|
|
220874
|
+
code: "INVALID_TARGET",
|
|
220875
|
+
message: "Comment target must be a TextAddress or TextTarget.",
|
|
220876
|
+
details: { target }
|
|
220877
|
+
}
|
|
220878
|
+
};
|
|
220769
220879
|
for (const seg of segments)
|
|
220770
220880
|
if (seg.range.start === seg.range.end)
|
|
220771
220881
|
return {
|
|
@@ -225685,8 +225795,9 @@ function resolveCurrentSelectionInfo(editor, input2) {
|
|
|
225685
225795
|
activeCommentIds: [],
|
|
225686
225796
|
activeChangeIds: []
|
|
225687
225797
|
};
|
|
225688
|
-
const
|
|
225689
|
-
const
|
|
225798
|
+
const sel = state.selection;
|
|
225799
|
+
const { from: from$1, to, empty: empty$1 } = sel;
|
|
225800
|
+
const segments = shouldProjectTextTarget(sel) ? collectTextSegments(state.doc, from$1, to) : null;
|
|
225690
225801
|
const target = segments && segments.length > 0 ? buildTextTarget(segments) : null;
|
|
225691
225802
|
const activeMarks = collectActiveMarks(state, from$1, to);
|
|
225692
225803
|
const { commentIds: activeCommentIds, changeIds: activeChangeRawIds } = collectActiveEntityIds(state, from$1, to);
|
|
@@ -225707,6 +225818,15 @@ function buildTextTarget(segments) {
|
|
|
225707
225818
|
segments
|
|
225708
225819
|
};
|
|
225709
225820
|
}
|
|
225821
|
+
function shouldProjectTextTarget(selection) {
|
|
225822
|
+
if (!selection || typeof selection !== "object")
|
|
225823
|
+
return false;
|
|
225824
|
+
if (selection instanceof NodeSelection)
|
|
225825
|
+
return false;
|
|
225826
|
+
if ("$anchorCell" in selection)
|
|
225827
|
+
return false;
|
|
225828
|
+
return true;
|
|
225829
|
+
}
|
|
225710
225830
|
function collectTextSegments(doc$12, from$1, to) {
|
|
225711
225831
|
const segments = [];
|
|
225712
225832
|
let abort = false;
|
|
@@ -226059,29 +226179,12 @@ function toTableFailure(code7, message, details) {
|
|
|
226059
226179
|
}
|
|
226060
226180
|
};
|
|
226061
226181
|
}
|
|
226062
|
-
function createSeparatorParagraph(schema) {
|
|
226063
|
-
const paragraphType = schema.nodes.paragraph;
|
|
226064
|
-
if (!paragraphType)
|
|
226065
|
-
return null;
|
|
226066
|
-
const separatorAttrs = {
|
|
226067
|
-
sdBlockId: v4_default(),
|
|
226068
|
-
paraId: generateDocxHexId()
|
|
226069
|
-
};
|
|
226070
|
-
return paragraphType.createAndFill(separatorAttrs) ?? paragraphType.createAndFill();
|
|
226071
|
-
}
|
|
226072
|
-
function buildTableSuccess(tableAddress, trackedChangeRefs) {
|
|
226073
|
-
return {
|
|
226074
|
-
success: true,
|
|
226075
|
-
table: tableAddress,
|
|
226076
|
-
trackedChangeRefs
|
|
226077
|
-
};
|
|
226078
|
-
}
|
|
226079
226182
|
function syncExtractedTableAttrs(tp) {
|
|
226080
226183
|
const extracted = {};
|
|
226081
226184
|
extracted.tableStyleId = tp.tableStyleId ?? null;
|
|
226082
226185
|
extracted.justification = tp.justification ?? null;
|
|
226083
226186
|
extracted.tableLayout = tp.tableLayout ?? null;
|
|
226084
|
-
extracted.borders = convertTableBordersToPixelUnits(tp.borders) ??
|
|
226187
|
+
extracted.borders = convertTableBordersToPixelUnits(tp.borders) ?? {};
|
|
226085
226188
|
const indent2 = tp.tableIndent;
|
|
226086
226189
|
if (indent2?.value != null)
|
|
226087
226190
|
extracted.tableIndent = {
|
|
@@ -226093,7 +226196,7 @@ function syncExtractedTableAttrs(tp) {
|
|
|
226093
226196
|
const spacing = tp.tableCellSpacing;
|
|
226094
226197
|
if (spacing?.value != null) {
|
|
226095
226198
|
extracted.tableCellSpacing = {
|
|
226096
|
-
|
|
226199
|
+
value: twipsToPixels(spacing.value),
|
|
226097
226200
|
type: spacing.type ?? "dxa"
|
|
226098
226201
|
};
|
|
226099
226202
|
extracted.borderCollapse = "separate";
|
|
@@ -226101,23 +226204,23 @@ function syncExtractedTableAttrs(tp) {
|
|
|
226101
226204
|
extracted.tableCellSpacing = null;
|
|
226102
226205
|
extracted.borderCollapse = null;
|
|
226103
226206
|
}
|
|
226104
|
-
const
|
|
226105
|
-
if (
|
|
226106
|
-
if (
|
|
226207
|
+
const width = tp.tableWidth;
|
|
226208
|
+
if (width)
|
|
226209
|
+
if (width.type === "pct" && typeof width.value === "number")
|
|
226107
226210
|
extracted.tableWidth = {
|
|
226108
|
-
value:
|
|
226211
|
+
value: width.value,
|
|
226109
226212
|
type: "pct"
|
|
226110
226213
|
};
|
|
226111
|
-
else if (
|
|
226214
|
+
else if (width.type === "auto")
|
|
226112
226215
|
extracted.tableWidth = {
|
|
226113
226216
|
width: 0,
|
|
226114
226217
|
type: "auto"
|
|
226115
226218
|
};
|
|
226116
|
-
else if (
|
|
226117
|
-
const widthPx = twipsToPixels(
|
|
226219
|
+
else if (width.value != null) {
|
|
226220
|
+
const widthPx = twipsToPixels(width.value);
|
|
226118
226221
|
extracted.tableWidth = widthPx != null ? {
|
|
226119
226222
|
width: widthPx,
|
|
226120
|
-
type:
|
|
226223
|
+
type: width.type
|
|
226121
226224
|
} : null;
|
|
226122
226225
|
} else
|
|
226123
226226
|
extracted.tableWidth = null;
|
|
@@ -226132,6 +226235,95 @@ function convertTableBordersToPixelUnits(value) {
|
|
|
226132
226235
|
mapBorderSizes(clone2, eighthPointsToPixels);
|
|
226133
226236
|
return Object.keys(clone2).length > 0 ? clone2 : undefined;
|
|
226134
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
|
+
}
|
|
226135
226327
|
function normalizeGridWidth(width) {
|
|
226136
226328
|
if (typeof width === "number" && Number.isFinite(width))
|
|
226137
226329
|
return { col: Math.round(width) };
|
|
@@ -226194,6 +226386,30 @@ function removeGridColumnWidth(grid, deleteIndex) {
|
|
|
226194
226386
|
columns: colWidths
|
|
226195
226387
|
});
|
|
226196
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
|
+
}
|
|
226197
226413
|
function normalizeCellAttrsForSingleCell(attrs) {
|
|
226198
226414
|
const currentColwidth = Array.isArray(attrs.colwidth) ? attrs.colwidth : null;
|
|
226199
226415
|
const tableCellProperties = { ...attrs.tableCellProperties ?? {} };
|
|
@@ -227071,8 +227287,13 @@ function tablesSetColumnWidthAdapter(editor, input2, options) {
|
|
|
227071
227287
|
const tablePos = table2.candidate.pos;
|
|
227072
227288
|
const tableStart = tablePos + 1;
|
|
227073
227289
|
const tableNode = table2.candidate.node;
|
|
227290
|
+
const tableAttrs = tableNode.attrs;
|
|
227074
227291
|
const map$12 = TableMap.get(tableNode);
|
|
227075
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) };
|
|
227076
227297
|
const processed = /* @__PURE__ */ new Set;
|
|
227077
227298
|
for (let row2 = 0;row2 < map$12.height; row2++) {
|
|
227078
227299
|
const index2 = row2 * map$12.width + columnIndex;
|
|
@@ -227086,29 +227307,31 @@ function tablesSetColumnWidthAdapter(editor, input2, options) {
|
|
|
227086
227307
|
const attrs = cell2.attrs;
|
|
227087
227308
|
const colspan = attrs.colspan || 1;
|
|
227088
227309
|
const colwidth = attrs.colwidth?.slice() ?? [];
|
|
227089
|
-
const
|
|
227310
|
+
const cellStartCol = map$12.colCount(pos);
|
|
227311
|
+
const withinCol = columnIndex - cellStartCol;
|
|
227090
227312
|
while (colwidth.length < colspan)
|
|
227091
227313
|
colwidth.push(0);
|
|
227092
227314
|
colwidth[withinCol] = widthPx;
|
|
227093
|
-
|
|
227315
|
+
const nextAttrs = {
|
|
227094
227316
|
...attrs,
|
|
227095
227317
|
colwidth
|
|
227096
|
-
}
|
|
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);
|
|
227097
227327
|
}
|
|
227098
|
-
const
|
|
227099
|
-
|
|
227100
|
-
|
|
227101
|
-
|
|
227102
|
-
|
|
227103
|
-
tr.setNodeMarkup(tablePos, null, {
|
|
227104
|
-
...tableAttrs,
|
|
227105
|
-
grid: serializeGridColumns(tableAttrs.grid, {
|
|
227106
|
-
...normalizedGrid,
|
|
227107
|
-
columns: newColumns
|
|
227108
|
-
}),
|
|
227109
|
-
userEdited: true
|
|
227328
|
+
const tableAttrUpdates = {};
|
|
227329
|
+
if (normalizedGrid && nextGridColumns)
|
|
227330
|
+
tableAttrUpdates.grid = serializeGridColumns(tableAttrs.grid, {
|
|
227331
|
+
...normalizedGrid,
|
|
227332
|
+
columns: nextGridColumns
|
|
227110
227333
|
});
|
|
227111
|
-
|
|
227334
|
+
tr.setNodeMarkup(tablePos, null, buildWidthAuthoringTableAttrs(tableAttrs, tableAttrUpdates));
|
|
227112
227335
|
applyDirectMutationMeta(tr);
|
|
227113
227336
|
editor.dispatch(tr);
|
|
227114
227337
|
clearIndexCache(editor);
|
|
@@ -227132,7 +227355,10 @@ function tablesDistributeColumnsAdapter(editor, input2, options) {
|
|
|
227132
227355
|
const tablePos = candidate.pos;
|
|
227133
227356
|
const tableStart = tablePos + 1;
|
|
227134
227357
|
const tableNode = candidate.node;
|
|
227358
|
+
const tableAttrs = tableNode.attrs;
|
|
227135
227359
|
const map$12 = TableMap.get(tableNode);
|
|
227360
|
+
const normalizedGrid = normalizeGridColumns(tableAttrs.grid);
|
|
227361
|
+
const nextGridColumns = normalizedGrid?.columns.slice();
|
|
227136
227362
|
const rangeStart = input2.columnRange?.start ?? 0;
|
|
227137
227363
|
const rangeEnd = input2.columnRange?.end ?? map$12.width - 1;
|
|
227138
227364
|
const rangeWidth = rangeEnd - rangeStart + 1;
|
|
@@ -227148,6 +227374,12 @@ function tablesDistributeColumnsAdapter(editor, input2, options) {
|
|
|
227148
227374
|
totalWidth += colwidth?.[withinCol] ?? 100;
|
|
227149
227375
|
}
|
|
227150
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
|
+
}
|
|
227151
227383
|
const processed = /* @__PURE__ */ new Set;
|
|
227152
227384
|
for (let row2 = 0;row2 < map$12.height; row2++)
|
|
227153
227385
|
for (let col = rangeStart;col <= rangeEnd; col++) {
|
|
@@ -227170,29 +227402,26 @@ function tablesDistributeColumnsAdapter(editor, input2, options) {
|
|
|
227170
227402
|
if (absCol >= rangeStart && absCol <= rangeEnd)
|
|
227171
227403
|
newColwidth[c] = evenWidth;
|
|
227172
227404
|
}
|
|
227173
|
-
|
|
227405
|
+
const nextAttrs = {
|
|
227174
227406
|
...attrs,
|
|
227175
227407
|
colwidth: newColwidth
|
|
227176
|
-
}
|
|
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);
|
|
227177
227417
|
}
|
|
227178
|
-
const
|
|
227179
|
-
|
|
227180
|
-
const tableAttrUpdates = {
|
|
227181
|
-
...tableAttrs,
|
|
227182
|
-
userEdited: true
|
|
227183
|
-
};
|
|
227184
|
-
if (normalizedGrid) {
|
|
227185
|
-
const newColumns = normalizedGrid.columns.slice();
|
|
227186
|
-
const evenWidthTwips = Math.max(1, Math.round(evenWidth * PIXELS_TO_TWIPS));
|
|
227187
|
-
const maxColumn = Math.min(rangeEnd, newColumns.length - 1);
|
|
227188
|
-
for (let col = Math.max(rangeStart, 0);col <= maxColumn; col++)
|
|
227189
|
-
newColumns[col] = { col: evenWidthTwips };
|
|
227418
|
+
const tableAttrUpdates = {};
|
|
227419
|
+
if (normalizedGrid && nextGridColumns)
|
|
227190
227420
|
tableAttrUpdates.grid = serializeGridColumns(tableAttrs.grid, {
|
|
227191
227421
|
...normalizedGrid,
|
|
227192
|
-
columns:
|
|
227422
|
+
columns: nextGridColumns
|
|
227193
227423
|
});
|
|
227194
|
-
|
|
227195
|
-
tr.setNodeMarkup(tablePos, null, tableAttrUpdates);
|
|
227424
|
+
tr.setNodeMarkup(tablePos, null, buildWidthAuthoringTableAttrs(tableAttrs, tableAttrUpdates));
|
|
227196
227425
|
applyDirectMutationMeta(tr);
|
|
227197
227426
|
editor.dispatch(tr);
|
|
227198
227427
|
clearIndexCache(editor);
|
|
@@ -227776,6 +228005,10 @@ function tablesSetCellPropertiesAdapter(editor, input2, options) {
|
|
|
227776
228005
|
}
|
|
227777
228006
|
};
|
|
227778
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
|
+
}
|
|
227779
228012
|
applyDirectMutationMeta(tr);
|
|
227780
228013
|
editor.dispatch(tr);
|
|
227781
228014
|
clearIndexCache(editor);
|
|
@@ -242307,7 +242540,7 @@ function normalizeFieldAnnotationMetadata(attrs) {
|
|
|
242307
242540
|
borderColor: normalizeColorValue2(attrs.borderColor),
|
|
242308
242541
|
highlighted: toBoolean$2(attrs.highlighted, true),
|
|
242309
242542
|
fontFamily: toNullableString(attrs.fontFamily),
|
|
242310
|
-
fontSize: normalizeFontSize$
|
|
242543
|
+
fontSize: normalizeFontSize$2(attrs.fontSize),
|
|
242311
242544
|
textColor: normalizeColorValue2(attrs.textColor) ?? null,
|
|
242312
242545
|
textHighlight: normalizeColorValue2(attrs.textHighlight) ?? null,
|
|
242313
242546
|
linkUrl: toNullableString(attrs.linkUrl),
|
|
@@ -242401,7 +242634,7 @@ function normalizeColorValue2(value) {
|
|
|
242401
242634
|
return;
|
|
242402
242635
|
return trimmed;
|
|
242403
242636
|
}
|
|
242404
|
-
function normalizeFontSize$
|
|
242637
|
+
function normalizeFontSize$2(value) {
|
|
242405
242638
|
if (value == null)
|
|
242406
242639
|
return null;
|
|
242407
242640
|
if (typeof value === "number")
|
|
@@ -244003,11 +244236,15 @@ function tableNodeToBlock(node2, { nextBlockId, positions, storyKey, trackedChan
|
|
|
244003
244236
|
tableAttrs.tableWidth = hydratedTableStyle.tableWidth;
|
|
244004
244237
|
if (node2.attrs?.tableIndent && typeof node2.attrs.tableIndent === "object")
|
|
244005
244238
|
tableAttrs.tableIndent = { ...node2.attrs.tableIndent };
|
|
244239
|
+
else if (hydratedTableStyle?.tableIndent)
|
|
244240
|
+
tableAttrs.tableIndent = { ...hydratedTableStyle.tableIndent };
|
|
244006
244241
|
if (defaultCellPadding && typeof defaultCellPadding === "object")
|
|
244007
244242
|
tableAttrs.defaultCellPadding = { ...defaultCellPadding };
|
|
244008
244243
|
const tableLayout = node2.attrs?.tableLayout;
|
|
244009
244244
|
if (tableLayout)
|
|
244010
244245
|
tableAttrs.tableLayout = tableLayout;
|
|
244246
|
+
else if (hydratedTableStyle?.tableLayout)
|
|
244247
|
+
tableAttrs.tableLayout = hydratedTableStyle.tableLayout;
|
|
244011
244248
|
const tableProperties = node2.attrs?.tableProperties;
|
|
244012
244249
|
if (tableProperties && typeof tableProperties === "object")
|
|
244013
244250
|
tableAttrs.tableProperties = tableProperties;
|
|
@@ -245970,23 +246207,37 @@ function applyTableIndent(x, width, indent2, columnWidth) {
|
|
|
245970
246207
|
x: shiftedX,
|
|
245971
246208
|
width: Math.max(0, width - indent2)
|
|
245972
246209
|
};
|
|
246210
|
+
if (width > columnWidth)
|
|
246211
|
+
return {
|
|
246212
|
+
x: shiftedX,
|
|
246213
|
+
width
|
|
246214
|
+
};
|
|
245973
246215
|
const maxWidthWithinColumn = Math.max(0, columnWidth - indent2);
|
|
245974
246216
|
return {
|
|
245975
246217
|
x: shiftedX,
|
|
245976
246218
|
width: Math.min(width, maxWidthWithinColumn)
|
|
245977
246219
|
};
|
|
245978
246220
|
}
|
|
246221
|
+
function resolveRenderedTableWidth(columnWidth, measuredWidth, attrs) {
|
|
246222
|
+
const safeMeasuredWidth = Number.isFinite(measuredWidth) && measuredWidth > 0 ? measuredWidth : Math.max(0, columnWidth);
|
|
246223
|
+
const configuredWidth = resolveTableWidthAttr(attrs?.tableWidth);
|
|
246224
|
+
if (!configuredWidth)
|
|
246225
|
+
return safeMeasuredWidth;
|
|
246226
|
+
if (configuredWidth.type === "pct")
|
|
246227
|
+
return Math.max(0, Math.round(columnWidth * (configuredWidth.width / OOXML_PCT_DIVISOR)));
|
|
246228
|
+
return safeMeasuredWidth;
|
|
246229
|
+
}
|
|
245979
246230
|
function resolveTableFrame(baseX, columnWidth, tableWidth, attrs) {
|
|
245980
|
-
const width =
|
|
246231
|
+
const width = resolveRenderedTableWidth(columnWidth, tableWidth, attrs);
|
|
245981
246232
|
const justification = typeof attrs?.justification === "string" ? attrs.justification : undefined;
|
|
245982
246233
|
if (justification === "center")
|
|
245983
246234
|
return {
|
|
245984
|
-
x: baseX +
|
|
246235
|
+
x: baseX + (columnWidth - width) / 2,
|
|
245985
246236
|
width
|
|
245986
246237
|
};
|
|
245987
246238
|
if (justification === "right" || justification === "end")
|
|
245988
246239
|
return {
|
|
245989
|
-
x: baseX +
|
|
246240
|
+
x: baseX + (columnWidth - width),
|
|
245990
246241
|
width
|
|
245991
246242
|
};
|
|
245992
246243
|
return applyTableIndent(baseX, width, getTableIndentWidth(attrs), columnWidth);
|
|
@@ -246416,13 +246667,14 @@ function layoutMonolithicTable(context) {
|
|
|
246416
246667
|
state = context.ensurePage();
|
|
246417
246668
|
const height = Math.min(context.measure.totalHeight, state.contentBottom - state.cursorY);
|
|
246418
246669
|
const baseX = context.columnX(state.columnIndex);
|
|
246419
|
-
const baseWidth = Math.
|
|
246670
|
+
const baseWidth = Math.max(0, context.measure.totalWidth || context.columnWidth);
|
|
246420
246671
|
const { x, width } = resolveTableFrame(baseX, context.columnWidth, baseWidth, context.block.attrs);
|
|
246421
246672
|
const columnWidths = rescaleColumnWidths(context.measure.columnWidths, context.measure.totalWidth, width);
|
|
246422
246673
|
const metadata = generateFragmentMetadata(context.measure, context.block, 0, context.block.rows.length, 0, columnWidths);
|
|
246423
246674
|
const fragment = {
|
|
246424
246675
|
kind: "table",
|
|
246425
246676
|
blockId: context.block.id,
|
|
246677
|
+
columnIndex: state.columnIndex,
|
|
246426
246678
|
fromRow: 0,
|
|
246427
246679
|
toRow: context.block.rows.length,
|
|
246428
246680
|
x,
|
|
@@ -246494,12 +246746,13 @@ function layoutTableBlock({ block, measure, columnWidth, ensurePage, advanceColu
|
|
|
246494
246746
|
let pendingPartialRow = null;
|
|
246495
246747
|
if (block.rows.length === 0 && measure.totalHeight > 0) {
|
|
246496
246748
|
const height = Math.min(measure.totalHeight, state.contentBottom - state.cursorY);
|
|
246497
|
-
const { x, width } = resolveTableFrame(columnX(state.columnIndex), columnWidth, Math.
|
|
246749
|
+
const { x, width } = resolveTableFrame(columnX(state.columnIndex), columnWidth, Math.max(0, measure.totalWidth || columnWidth), block.attrs);
|
|
246498
246750
|
const columnWidths = rescaleColumnWidths(measure.columnWidths, measure.totalWidth, width);
|
|
246499
246751
|
const metadata = generateFragmentMetadata(measure, block, 0, 0, 0, columnWidths);
|
|
246500
246752
|
const fragment = {
|
|
246501
246753
|
kind: "table",
|
|
246502
246754
|
blockId: block.id,
|
|
246755
|
+
columnIndex: state.columnIndex,
|
|
246503
246756
|
fromRow: 0,
|
|
246504
246757
|
toRow: 0,
|
|
246505
246758
|
x,
|
|
@@ -246564,11 +246817,12 @@ function layoutTableBlock({ block, measure, columnWidth, ensurePage, advanceColu
|
|
|
246564
246817
|
});
|
|
246565
246818
|
const fragmentHeight$1 = computeFragmentHeight$1(measure, rowIndex, rowIndex + 1, repeatHeaderCount, borderCollapse, continuationPartialRow);
|
|
246566
246819
|
if (fragmentHeight$1 > 0 && madeProgress) {
|
|
246567
|
-
const { x: x$1, width: width$1 } = resolveTableFrame(columnX(state.columnIndex), columnWidth, Math.
|
|
246820
|
+
const { x: x$1, width: width$1 } = resolveTableFrame(columnX(state.columnIndex), columnWidth, Math.max(0, measure.totalWidth || columnWidth), block.attrs);
|
|
246568
246821
|
const scaledWidths$1 = rescaleColumnWidths(measure.columnWidths, measure.totalWidth, width$1);
|
|
246569
246822
|
const fragment$1 = {
|
|
246570
246823
|
kind: "table",
|
|
246571
246824
|
blockId: block.id,
|
|
246825
|
+
columnIndex: state.columnIndex,
|
|
246572
246826
|
fromRow: rowIndex,
|
|
246573
246827
|
toRow: rowIndex + 1,
|
|
246574
246828
|
x: x$1,
|
|
@@ -246620,11 +246874,12 @@ function layoutTableBlock({ block, measure, columnWidth, ensurePage, advanceColu
|
|
|
246620
246874
|
}
|
|
246621
246875
|
const forcedEndRow = bodyStartRow + 1;
|
|
246622
246876
|
const fragmentHeight$1 = computeFragmentHeight$1(measure, bodyStartRow, forcedEndRow, repeatHeaderCount, borderCollapse, forcedPartialRow);
|
|
246623
|
-
const { x: x$1, width: width$1 } = resolveTableFrame(columnX(state.columnIndex), columnWidth, Math.
|
|
246877
|
+
const { x: x$1, width: width$1 } = resolveTableFrame(columnX(state.columnIndex), columnWidth, Math.max(0, measure.totalWidth || columnWidth), block.attrs);
|
|
246624
246878
|
const scaledWidths$1 = rescaleColumnWidths(measure.columnWidths, measure.totalWidth, width$1);
|
|
246625
246879
|
const fragment$1 = {
|
|
246626
246880
|
kind: "table",
|
|
246627
246881
|
blockId: block.id,
|
|
246882
|
+
columnIndex: state.columnIndex,
|
|
246628
246883
|
fromRow: bodyStartRow,
|
|
246629
246884
|
toRow: forcedEndRow,
|
|
246630
246885
|
x: x$1,
|
|
@@ -246649,11 +246904,12 @@ function layoutTableBlock({ block, measure, columnWidth, ensurePage, advanceColu
|
|
|
246649
246904
|
continue;
|
|
246650
246905
|
}
|
|
246651
246906
|
const fragmentHeight = computeFragmentHeight$1(measure, bodyStartRow, endRow, repeatHeaderCount, borderCollapse, partialRow);
|
|
246652
|
-
const { x, width } = resolveTableFrame(columnX(state.columnIndex), columnWidth, Math.
|
|
246907
|
+
const { x, width } = resolveTableFrame(columnX(state.columnIndex), columnWidth, Math.max(0, measure.totalWidth || columnWidth), block.attrs);
|
|
246653
246908
|
const scaledWidths = rescaleColumnWidths(measure.columnWidths, measure.totalWidth, width);
|
|
246654
246909
|
const fragment = {
|
|
246655
246910
|
kind: "table",
|
|
246656
246911
|
blockId: block.id,
|
|
246912
|
+
columnIndex: state.columnIndex,
|
|
246657
246913
|
fromRow: bodyStartRow,
|
|
246658
246914
|
toRow: endRow,
|
|
246659
246915
|
x,
|
|
@@ -248907,7 +249163,7 @@ function measureCharacterX(block, line, charOffset, availableWidthOverride, alig
|
|
|
248907
249163
|
}
|
|
248908
249164
|
const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text ?? "";
|
|
248909
249165
|
const runLength = text5.length;
|
|
248910
|
-
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);
|
|
248911
249167
|
if (currentCharOffset + runLength >= charOffset) {
|
|
248912
249168
|
const offsetInRun = charOffset - currentCharOffset;
|
|
248913
249169
|
ctx$1.font = getRunFontString(run2);
|
|
@@ -248956,7 +249212,7 @@ function measureCharacterXSegmentBased(block, line, charOffset, ctx$1) {
|
|
|
248956
249212
|
return segmentBaseX + (offsetInSegment > 0 ? segment.width ?? 0 : 0);
|
|
248957
249213
|
if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math")
|
|
248958
249214
|
return segmentBaseX + (offsetInSegment >= segmentChars ? segment.width ?? 0 : 0);
|
|
248959
|
-
const textUpToTarget = applyTextTransform$
|
|
249215
|
+
const textUpToTarget = applyTextTransform$3(run2.text ?? "", "textTransform" in run2 ? run2.textTransform : undefined).slice(segment.fromChar, segment.toChar).slice(0, offsetInSegment);
|
|
248960
249216
|
ctx$1.font = getRunFontString(run2);
|
|
248961
249217
|
const measured = ctx$1.measureText(textUpToTarget);
|
|
248962
249218
|
const spacingWidth = computeLetterSpacingWidth(run2, offsetInSegment, segmentChars);
|
|
@@ -249049,7 +249305,7 @@ function findCharacterAtX(block, line, x, pmStart, availableWidthOverride, align
|
|
|
249049
249305
|
}
|
|
249050
249306
|
const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text ?? "";
|
|
249051
249307
|
const runLength = text5.length;
|
|
249052
|
-
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);
|
|
249053
249309
|
if (runLength === 0)
|
|
249054
249310
|
continue;
|
|
249055
249311
|
ctx$1.font = getRunFontString(run2);
|
|
@@ -249692,7 +249948,7 @@ function measureRunSliceWidth(run2, fromChar, toChar) {
|
|
|
249692
249948
|
const context = getCtx();
|
|
249693
249949
|
const fullText = runText(run2);
|
|
249694
249950
|
const transform2 = isTextRun$3(run2) ? run2.textTransform : undefined;
|
|
249695
|
-
const text5 = applyTextTransform$
|
|
249951
|
+
const text5 = applyTextTransform$2(fullText.slice(fromChar, toChar), transform2, fullText, fromChar);
|
|
249696
249952
|
if (!context) {
|
|
249697
249953
|
const size$1 = (isTextRun$3(run2) ? run2 : null)?.fontSize ?? 16;
|
|
249698
249954
|
return Math.max(1, text5.length * (size$1 * 0.6));
|
|
@@ -250749,32 +251005,12 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
|
|
|
250749
251005
|
return;
|
|
250750
251006
|
if (!block || block.kind !== "table")
|
|
250751
251007
|
return;
|
|
250752
|
-
const
|
|
250753
|
-
|
|
250754
|
-
let tableX = columnX;
|
|
250755
|
-
const justification = typeof block.attrs?.justification === "string" ? block.attrs.justification : undefined;
|
|
250756
|
-
if (justification === "center")
|
|
250757
|
-
tableX = columnX + Math.max(0, (contentWidth - tableWidth) / 2);
|
|
250758
|
-
else if (justification === "right" || justification === "end")
|
|
250759
|
-
tableX = columnX + Math.max(0, contentWidth - tableWidth);
|
|
250760
|
-
else {
|
|
250761
|
-
const indentValue = block.attrs?.tableIndent?.width;
|
|
250762
|
-
const indent2 = typeof indentValue === "number" && Number.isFinite(indentValue) ? indentValue : 0;
|
|
250763
|
-
tableX += indent2;
|
|
250764
|
-
tableWidth = Math.max(0, tableWidth - indent2);
|
|
250765
|
-
}
|
|
250766
|
-
let fragmentColumnWidths;
|
|
250767
|
-
if (tableWidthRaw > tableWidth && measure.columnWidths && measure.columnWidths.length > 0 && tableWidthRaw > 0) {
|
|
250768
|
-
const scale = tableWidth / tableWidthRaw;
|
|
250769
|
-
fragmentColumnWidths = measure.columnWidths.map((w) => Math.max(1, Math.round(w * scale)));
|
|
250770
|
-
const scaledSum = fragmentColumnWidths.reduce((a2, b$1) => a2 + b$1, 0);
|
|
250771
|
-
const target = Math.round(tableWidth);
|
|
250772
|
-
if (scaledSum !== target && fragmentColumnWidths.length > 0)
|
|
250773
|
-
fragmentColumnWidths[fragmentColumnWidths.length - 1] = Math.max(1, fragmentColumnWidths[fragmentColumnWidths.length - 1] + (target - scaledSum));
|
|
250774
|
-
}
|
|
251008
|
+
const { x: tableX, width: tableWidth } = resolveTableFrame(columnX, contentWidth, Math.max(0, measure.totalWidth ?? contentWidth), block.attrs);
|
|
251009
|
+
const fragmentColumnWidths = rescaleColumnWidths(measure.columnWidths, measure.totalWidth, tableWidth);
|
|
250775
251010
|
page.fragments.push({
|
|
250776
251011
|
kind: "table",
|
|
250777
251012
|
blockId: range.blockId,
|
|
251013
|
+
columnIndex,
|
|
250778
251014
|
fromRow: 0,
|
|
250779
251015
|
toRow: block.rows.length,
|
|
250780
251016
|
x: tableX,
|
|
@@ -251517,7 +251753,7 @@ function clickToPositionGeometry(layout, blocks2, measures, containerPoint, opti
|
|
|
251517
251753
|
layoutEpoch,
|
|
251518
251754
|
blockId: tableHit.fragment.blockId,
|
|
251519
251755
|
pageIndex,
|
|
251520
|
-
column:
|
|
251756
|
+
column: determineTableColumn(layout, tableHit.fragment),
|
|
251521
251757
|
lineIndex
|
|
251522
251758
|
};
|
|
251523
251759
|
}
|
|
@@ -251528,7 +251764,7 @@ function clickToPositionGeometry(layout, blocks2, measures, containerPoint, opti
|
|
|
251528
251764
|
layoutEpoch,
|
|
251529
251765
|
blockId: tableHit.fragment.blockId,
|
|
251530
251766
|
pageIndex,
|
|
251531
|
-
column:
|
|
251767
|
+
column: determineTableColumn(layout, tableHit.fragment),
|
|
251532
251768
|
lineIndex: 0
|
|
251533
251769
|
};
|
|
251534
251770
|
}
|
|
@@ -252979,7 +253215,7 @@ function areNumberListsEqual(left$1, right$1) {
|
|
|
252979
253215
|
return false;
|
|
252980
253216
|
return true;
|
|
252981
253217
|
}
|
|
252982
|
-
function isWordCharacter(char) {
|
|
253218
|
+
function isWordCharacter$1(char) {
|
|
252983
253219
|
if (!char)
|
|
252984
253220
|
return false;
|
|
252985
253221
|
return WORD_CHARACTER_REGEX.test(char);
|
|
@@ -253062,17 +253298,17 @@ function computeWordSelectionRangeAt(state, pos) {
|
|
|
253062
253298
|
const parentStart = textblockPos.start();
|
|
253063
253299
|
const parentEnd = textblockPos.end();
|
|
253064
253300
|
const sampleEnd = Math.min(pos + 1, parentEnd);
|
|
253065
|
-
if (!isWordCharacter(state.doc.textBetween(pos, sampleEnd, "\x00", "\x00")))
|
|
253301
|
+
if (!isWordCharacter$1(state.doc.textBetween(pos, sampleEnd, "\x00", "\x00")))
|
|
253066
253302
|
return null;
|
|
253067
253303
|
let startPos = pos;
|
|
253068
253304
|
while (startPos > parentStart) {
|
|
253069
|
-
if (!isWordCharacter(state.doc.textBetween(startPos - 1, startPos, "\x00", "\x00")))
|
|
253305
|
+
if (!isWordCharacter$1(state.doc.textBetween(startPos - 1, startPos, "\x00", "\x00")))
|
|
253070
253306
|
break;
|
|
253071
253307
|
startPos -= 1;
|
|
253072
253308
|
}
|
|
253073
253309
|
let endPos = pos;
|
|
253074
253310
|
while (endPos < parentEnd) {
|
|
253075
|
-
if (!isWordCharacter(state.doc.textBetween(endPos, endPos + 1, "\x00", "\x00")))
|
|
253311
|
+
if (!isWordCharacter$1(state.doc.textBetween(endPos, endPos + 1, "\x00", "\x00")))
|
|
253076
253312
|
break;
|
|
253077
253313
|
endPos += 1;
|
|
253078
253314
|
}
|
|
@@ -256343,6 +256579,1369 @@ function getFontMetrics(ctx$1, fontInfo, mode, fonts) {
|
|
|
256343
256579
|
fontMetricsCache.set(key2, result);
|
|
256344
256580
|
return result;
|
|
256345
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
|
+
}
|
|
256346
257945
|
function getTableBorderWidthPx(value) {
|
|
256347
257946
|
if (value == null)
|
|
256348
257947
|
return 0;
|
|
@@ -257833,161 +259432,9 @@ async function measureParagraphBlock(block, maxWidth) {
|
|
|
257833
259432
|
...dropCapMeasure ? { dropCap: dropCapMeasure } : {}
|
|
257834
259433
|
};
|
|
257835
259434
|
}
|
|
257836
|
-
function validateTableWidthValue(attr) {
|
|
257837
|
-
const value = attr.width ?? attr.value;
|
|
257838
|
-
if (typeof value === "number" && Number.isFinite(value) && value > 0)
|
|
257839
|
-
return value;
|
|
257840
|
-
}
|
|
257841
|
-
function resolveTableWidth(attrs, maxWidth) {
|
|
257842
|
-
const tableWidthAttr = attrs?.tableWidth;
|
|
257843
|
-
if (!tableWidthAttr || typeof tableWidthAttr !== "object")
|
|
257844
|
-
return;
|
|
257845
|
-
const typedAttr = tableWidthAttr;
|
|
257846
|
-
const validValue = validateTableWidthValue(typedAttr);
|
|
257847
|
-
if (validValue === undefined)
|
|
257848
|
-
return;
|
|
257849
|
-
if (typedAttr.type === "pct")
|
|
257850
|
-
return Math.round(maxWidth * (validValue / OOXML_PCT_DIVISOR));
|
|
257851
|
-
else if (typedAttr.type === "px" || typedAttr.type === "pixel" || typedAttr.type === "dxa")
|
|
257852
|
-
return validValue;
|
|
257853
|
-
}
|
|
257854
259435
|
async function measureTableBlock(block, constraints) {
|
|
257855
|
-
const
|
|
257856
|
-
const
|
|
257857
|
-
let columnWidths;
|
|
257858
|
-
const maxCellCount = Math.max(1, Math.max(...block.rows.map((r$1) => r$1.cells.reduce((sum, cell2) => sum + (cell2.colSpan ?? 1), 0))));
|
|
257859
|
-
const effectiveTargetWidth = resolvedTableWidth != null ? Math.min(resolvedTableWidth, maxWidth) : maxWidth;
|
|
257860
|
-
if (block.columnWidths && block.columnWidths.length > 0) {
|
|
257861
|
-
columnWidths = [...block.columnWidths];
|
|
257862
|
-
const hasExplicitWidth = resolvedTableWidth != null;
|
|
257863
|
-
const hasFixedLayout = block.attrs?.tableLayout === "fixed";
|
|
257864
|
-
if (hasExplicitWidth || hasFixedLayout) {
|
|
257865
|
-
const totalWidth$1 = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
|
|
257866
|
-
const tableWidthType = block.attrs?.tableWidth?.type;
|
|
257867
|
-
if ((totalWidth$1 > effectiveTargetWidth || totalWidth$1 < effectiveTargetWidth && effectiveTargetWidth > 0 && (tableWidthType === "pct" || hasExplicitWidth && !hasFixedLayout)) && effectiveTargetWidth > 0 && totalWidth$1 > 0) {
|
|
257868
|
-
const scale = effectiveTargetWidth / totalWidth$1;
|
|
257869
|
-
columnWidths = columnWidths.map((w) => Math.max(1, Math.round(w * scale)));
|
|
257870
|
-
const scaledSum = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
|
|
257871
|
-
if (scaledSum !== effectiveTargetWidth && columnWidths.length > 0) {
|
|
257872
|
-
const diff = effectiveTargetWidth - scaledSum;
|
|
257873
|
-
columnWidths[columnWidths.length - 1] = Math.max(1, columnWidths[columnWidths.length - 1] + diff);
|
|
257874
|
-
}
|
|
257875
|
-
}
|
|
257876
|
-
} else {
|
|
257877
|
-
if (columnWidths.length < maxCellCount) {
|
|
257878
|
-
const usedWidth = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
|
|
257879
|
-
const remainingWidth = Math.max(0, effectiveTargetWidth - usedWidth);
|
|
257880
|
-
const missingColumns = maxCellCount - columnWidths.length;
|
|
257881
|
-
const paddingWidth = Math.max(1, Math.floor(remainingWidth / missingColumns));
|
|
257882
|
-
columnWidths.push(...Array.from({ length: missingColumns }, () => paddingWidth));
|
|
257883
|
-
} else if (columnWidths.length > maxCellCount)
|
|
257884
|
-
columnWidths = columnWidths.slice(0, maxCellCount);
|
|
257885
|
-
const totalWidth$1 = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
|
|
257886
|
-
if (totalWidth$1 > effectiveTargetWidth && effectiveTargetWidth > 0) {
|
|
257887
|
-
const scale = effectiveTargetWidth / totalWidth$1;
|
|
257888
|
-
columnWidths = columnWidths.map((w) => Math.max(1, Math.round(w * scale)));
|
|
257889
|
-
const scaledSum = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
|
|
257890
|
-
if (scaledSum !== effectiveTargetWidth && columnWidths.length > 0) {
|
|
257891
|
-
const diff = effectiveTargetWidth - scaledSum;
|
|
257892
|
-
columnWidths[columnWidths.length - 1] = Math.max(1, columnWidths[columnWidths.length - 1] + diff);
|
|
257893
|
-
}
|
|
257894
|
-
}
|
|
257895
|
-
}
|
|
257896
|
-
} else {
|
|
257897
|
-
const columnWidth = Math.max(1, Math.floor(effectiveTargetWidth / maxCellCount));
|
|
257898
|
-
columnWidths = Array.from({ length: maxCellCount }, () => columnWidth);
|
|
257899
|
-
}
|
|
257900
|
-
const isFixedLayout = block.attrs?.tableLayout === "fixed";
|
|
257901
|
-
const gridLooksLikePlaceholder = columnWidths.reduce((a2, b$1) => a2 + b$1, 0) < maxWidth * 0.1;
|
|
257902
|
-
if (!isFixedLayout && gridLooksLikePlaceholder) {
|
|
257903
|
-
const gridColCount = columnWidths.length;
|
|
257904
|
-
const maxContentWidths = new Array(gridColCount).fill(0);
|
|
257905
|
-
const autoFitRowspanTracker = new Array(gridColCount).fill(0);
|
|
257906
|
-
for (const row2 of block.rows) {
|
|
257907
|
-
let colIndex = 0;
|
|
257908
|
-
for (const cell2 of row2.cells) {
|
|
257909
|
-
const colspan = cell2.colSpan ?? 1;
|
|
257910
|
-
const rowspan = cell2.rowSpan ?? 1;
|
|
257911
|
-
while (colIndex < gridColCount && autoFitRowspanTracker[colIndex] > 0) {
|
|
257912
|
-
autoFitRowspanTracker[colIndex]--;
|
|
257913
|
-
colIndex++;
|
|
257914
|
-
}
|
|
257915
|
-
if (colIndex >= gridColCount)
|
|
257916
|
-
break;
|
|
257917
|
-
if (colspan === 1) {
|
|
257918
|
-
const cellPadding = cell2.attrs?.padding ?? DEFAULT_CELL_PADDING;
|
|
257919
|
-
const paddingH = (cellPadding.left ?? 4) + (cellPadding.right ?? 4);
|
|
257920
|
-
const cellBlocks = cell2.blocks ?? (cell2.paragraph ? [cell2.paragraph] : []);
|
|
257921
|
-
let cellMaxWidth = 0;
|
|
257922
|
-
for (const cellBlock of cellBlocks) {
|
|
257923
|
-
const maxMeasure = await measureBlock(cellBlock, {
|
|
257924
|
-
maxWidth: 99999,
|
|
257925
|
-
maxHeight: Infinity
|
|
257926
|
-
});
|
|
257927
|
-
let blockMaxWidth = 0;
|
|
257928
|
-
if (maxMeasure.kind === "paragraph") {
|
|
257929
|
-
for (const line of maxMeasure.lines)
|
|
257930
|
-
if (line.width > blockMaxWidth)
|
|
257931
|
-
blockMaxWidth = line.width;
|
|
257932
|
-
} else if (maxMeasure.kind === "image" || maxMeasure.kind === "drawing")
|
|
257933
|
-
blockMaxWidth = maxMeasure.width;
|
|
257934
|
-
else if (maxMeasure.kind === "table")
|
|
257935
|
-
blockMaxWidth = maxMeasure.totalWidth;
|
|
257936
|
-
else if (maxMeasure.kind === "list") {
|
|
257937
|
-
for (const item of maxMeasure.items)
|
|
257938
|
-
if (item.paragraph) {
|
|
257939
|
-
const gutterWidth = (item.indentLeft ?? 0) + (item.markerWidth ?? 0);
|
|
257940
|
-
for (const line of item.paragraph.lines) {
|
|
257941
|
-
const lineTotal = gutterWidth + line.width;
|
|
257942
|
-
if (lineTotal > blockMaxWidth)
|
|
257943
|
-
blockMaxWidth = lineTotal;
|
|
257944
|
-
}
|
|
257945
|
-
}
|
|
257946
|
-
}
|
|
257947
|
-
if (blockMaxWidth > cellMaxWidth)
|
|
257948
|
-
cellMaxWidth = blockMaxWidth;
|
|
257949
|
-
}
|
|
257950
|
-
const totalWidth$1 = cellMaxWidth + paddingH;
|
|
257951
|
-
if (totalWidth$1 > maxContentWidths[colIndex])
|
|
257952
|
-
maxContentWidths[colIndex] = totalWidth$1;
|
|
257953
|
-
}
|
|
257954
|
-
if (rowspan > 1)
|
|
257955
|
-
for (let c = 0;c < colspan && colIndex + c < gridColCount; c++)
|
|
257956
|
-
autoFitRowspanTracker[colIndex + c] = rowspan - 1;
|
|
257957
|
-
colIndex += colspan;
|
|
257958
|
-
}
|
|
257959
|
-
for (let col = colIndex;col < gridColCount; col++)
|
|
257960
|
-
if (autoFitRowspanTracker[col] > 0)
|
|
257961
|
-
autoFitRowspanTracker[col]--;
|
|
257962
|
-
}
|
|
257963
|
-
const contentTotal = maxContentWidths.reduce((a2, b$1) => a2 + b$1, 0);
|
|
257964
|
-
if (contentTotal > 0)
|
|
257965
|
-
if (contentTotal <= maxWidth) {
|
|
257966
|
-
for (let i4 = 0;i4 < gridColCount; i4++)
|
|
257967
|
-
if (maxContentWidths[i4] > columnWidths[i4])
|
|
257968
|
-
columnWidths[i4] = maxContentWidths[i4];
|
|
257969
|
-
const expandedTotal = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
|
|
257970
|
-
if (expandedTotal > maxWidth && gridColCount > 0) {
|
|
257971
|
-
const scale = maxWidth / expandedTotal;
|
|
257972
|
-
for (let i4 = 0;i4 < gridColCount; i4++)
|
|
257973
|
-
columnWidths[i4] = Math.max(1, Math.round(columnWidths[i4] * scale));
|
|
257974
|
-
const scaledSum = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
|
|
257975
|
-
if (scaledSum !== maxWidth) {
|
|
257976
|
-
const diff = maxWidth - scaledSum;
|
|
257977
|
-
columnWidths[gridColCount - 1] = Math.max(1, columnWidths[gridColCount - 1] + diff);
|
|
257978
|
-
}
|
|
257979
|
-
}
|
|
257980
|
-
} else {
|
|
257981
|
-
const scale = maxWidth / contentTotal;
|
|
257982
|
-
for (let i4 = 0;i4 < gridColCount; i4++)
|
|
257983
|
-
columnWidths[i4] = Math.max(1, Math.round(maxContentWidths[i4] * scale));
|
|
257984
|
-
const scaledSum = columnWidths.reduce((a2, b$1) => a2 + b$1, 0);
|
|
257985
|
-
if (scaledSum !== maxWidth && gridColCount > 0) {
|
|
257986
|
-
const diff = maxWidth - scaledSum;
|
|
257987
|
-
columnWidths[gridColCount - 1] = Math.max(1, columnWidths[gridColCount - 1] + diff);
|
|
257988
|
-
}
|
|
257989
|
-
}
|
|
257990
|
-
}
|
|
259436
|
+
const workingInput = buildAutoFitWorkingGridInput(block, { maxWidth: typeof constraints === "number" ? constraints : constraints.maxWidth });
|
|
259437
|
+
const columnWidths = await resolveRuntimeTableColumnWidths(block, workingInput);
|
|
257991
259438
|
const gridColumnCount = columnWidths.length;
|
|
257992
259439
|
const calculateCellWidth = (startCol, colspan) => {
|
|
257993
259440
|
let width = 0;
|
|
@@ -258001,11 +259448,19 @@ async function measureTableBlock(block, constraints) {
|
|
|
258001
259448
|
const spanConstraints = [];
|
|
258002
259449
|
for (let rowIndex = 0;rowIndex < block.rows.length; rowIndex++) {
|
|
258003
259450
|
const row2 = block.rows[rowIndex];
|
|
259451
|
+
const normalizedRow = workingInput.rows[rowIndex];
|
|
258004
259452
|
const cellMeasures = [];
|
|
258005
259453
|
let gridColIndex = 0;
|
|
258006
|
-
for (
|
|
259454
|
+
for (let cellIndex = 0;cellIndex < row2.cells.length; cellIndex++) {
|
|
259455
|
+
const cell2 = row2.cells[cellIndex];
|
|
258007
259456
|
const colspan = cell2.colSpan ?? 1;
|
|
258008
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
|
+
}
|
|
258009
259464
|
while (gridColIndex < gridColumnCount && rowspanTracker[gridColIndex] > 0) {
|
|
258010
259465
|
rowspanTracker[gridColIndex]--;
|
|
258011
259466
|
gridColIndex++;
|
|
@@ -258108,18 +259563,48 @@ async function measureTableBlock(block, constraints) {
|
|
|
258108
259563
|
const borderWidthH = tableBorderWidths.left + tableBorderWidths.right;
|
|
258109
259564
|
const borderWidthV = tableBorderWidths.top + tableBorderWidths.bottom;
|
|
258110
259565
|
const includeOuterBordersInTotal = (block.attrs?.borderCollapse ?? (block.attrs?.cellSpacing != null ? "separate" : "collapse")) === "separate";
|
|
258111
|
-
const totalWidth = contentWidth + horizontalGaps + (includeOuterBordersInTotal ? borderWidthH : 0);
|
|
258112
|
-
const totalHeight = contentHeight + verticalGaps + (includeOuterBordersInTotal ? borderWidthV : 0);
|
|
258113
259566
|
return {
|
|
258114
259567
|
kind: "table",
|
|
258115
259568
|
rows,
|
|
258116
259569
|
columnWidths,
|
|
258117
|
-
totalWidth,
|
|
258118
|
-
totalHeight,
|
|
259570
|
+
totalWidth: contentWidth + horizontalGaps + (includeOuterBordersInTotal ? borderWidthH : 0),
|
|
259571
|
+
totalHeight: contentHeight + verticalGaps + (includeOuterBordersInTotal ? borderWidthV : 0),
|
|
258119
259572
|
cellSpacingPx: cellSpacingPx > 0 ? cellSpacingPx : undefined,
|
|
258120
259573
|
tableBorderWidths: borderWidthH > 0 || borderWidthV > 0 ? tableBorderWidths : undefined
|
|
258121
259574
|
};
|
|
258122
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
|
+
}
|
|
258123
259608
|
async function measureImageBlock(block, constraints) {
|
|
258124
259609
|
const intrinsic = getIntrinsicImageSize(block, constraints.maxWidth);
|
|
258125
259610
|
const isBlockBehindDoc = block.anchor?.behindDoc;
|
|
@@ -258972,7 +260457,7 @@ var Node$13 = class Node$14 {
|
|
|
258972
260457
|
"iPhone",
|
|
258973
260458
|
"iPod"
|
|
258974
260459
|
].includes(navigator.platform);
|
|
258975
|
-
}, 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) => {
|
|
258976
260461
|
if (!run2 || typeof run2 !== "object")
|
|
258977
260462
|
return false;
|
|
258978
260463
|
return typeof run2.src === "string";
|
|
@@ -268799,7 +270284,7 @@ var Node$13 = class Node$14 {
|
|
|
268799
270284
|
this.deco = deco;
|
|
268800
270285
|
}
|
|
268801
270286
|
}, searchKey, BLOCK_SEPARATOR = `
|
|
268802
|
-
`, ATOM_PLACEHOLDER = "", SearchIndex, customSearchHighlightsKey, isRegExp2 = (value) => Object.prototype.toString.call(value) === "[object RegExp]", SEARCH_POSITION_TRACKER_TYPE = "search-match", mapIndexMatchesToDocMatches = ({ searchIndex, indexMatches, doc: doc$12, positionTracker }) => {
|
|
270287
|
+
`, ATOM_PLACEHOLDER = "", DELETION_BARRIER = "\x00", DEFAULT_SEARCH_MODEL$1 = "raw", hasTrackDeleteMark$1 = (node2) => node2?.marks?.some((mark2) => mark2?.type?.name === "trackDelete") ?? false, SearchIndex, customSearchHighlightsKey, isRegExp2 = (value) => Object.prototype.toString.call(value) === "[object RegExp]", SEARCH_POSITION_TRACKER_TYPE = "search-match", DEFAULT_SEARCH_MODEL = "raw", normalizeSearchModel = (value) => value === "visible" ? "visible" : DEFAULT_SEARCH_MODEL, mapIndexMatchesToDocMatches = ({ searchIndex, indexMatches, doc: doc$12, positionTracker }) => {
|
|
268803
270288
|
const matches2 = [];
|
|
268804
270289
|
for (const indexMatch of indexMatches) {
|
|
268805
270290
|
const ranges = searchIndex.offsetRangeToDocRanges(indexMatch.start, indexMatch.end);
|
|
@@ -270136,7 +271621,7 @@ var Node$13 = class Node$14 {
|
|
|
270136
271621
|
});
|
|
270137
271622
|
const renderSearchDropdown = () => {
|
|
270138
271623
|
const handleSubmit = ({ value }) => {
|
|
270139
|
-
superToolbar.activeEditor.commands.search(value);
|
|
271624
|
+
superToolbar.activeEditor.commands.search(value, { searchModel: "visible" });
|
|
270140
271625
|
};
|
|
270141
271626
|
return exports_vue.h("div", {}, [exports_vue.h(SearchInput_default, {
|
|
270142
271627
|
onSubmit: handleSubmit,
|
|
@@ -278543,9 +280028,17 @@ menclose::after {
|
|
|
278543
280028
|
inlineBorders = normalizeTableBorders(tableProps.borders);
|
|
278544
280029
|
if (typeof tableProps.justification === "string")
|
|
278545
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;
|
|
278546
280036
|
const tableWidth = normalizeTableWidth(tableProps.tableWidth);
|
|
278547
280037
|
if (tableWidth)
|
|
278548
280038
|
hydration.tableWidth = tableWidth;
|
|
280039
|
+
const tableCellSpacing = normalizeTableSpacing(tableProps.tableCellSpacing);
|
|
280040
|
+
if (tableCellSpacing)
|
|
280041
|
+
hydration.tableCellSpacing = tableCellSpacing;
|
|
278549
280042
|
}
|
|
278550
280043
|
const styleId = effectiveStyleId === null ? undefined : effectiveStyleId ?? (typeof tableNode.attrs?.tableStyleId === "string" ? tableNode.attrs.tableStyleId : undefined);
|
|
278551
280044
|
if (styleId && context?.translatedLinkedStyles) {
|
|
@@ -278572,8 +280065,18 @@ menclose::after {
|
|
|
278572
280065
|
hydration.cellPadding = inlinePadding;
|
|
278573
280066
|
if (!hydration.justification && resolved.justification)
|
|
278574
280067
|
hydration.justification = resolved.justification;
|
|
278575
|
-
if (resolved.
|
|
278576
|
-
|
|
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
|
+
}
|
|
278577
280080
|
if (!hydration.tableWidth && resolved.tableWidth) {
|
|
278578
280081
|
const tableWidth = normalizeTableWidth(resolved.tableWidth);
|
|
278579
280082
|
if (tableWidth)
|
|
@@ -278671,7 +280174,41 @@ menclose::after {
|
|
|
278671
280174
|
width: raw,
|
|
278672
280175
|
type: measurement.type
|
|
278673
280176
|
};
|
|
278674
|
-
},
|
|
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) => {
|
|
278675
280212
|
if (!value || typeof value !== "object")
|
|
278676
280213
|
return;
|
|
278677
280214
|
const border = value;
|
|
@@ -278939,6 +280476,8 @@ menclose::after {
|
|
|
278939
280476
|
const cells = [];
|
|
278940
280477
|
const rowCnfStyle = rowNode.attrs?.tableRowProperties?.cnfStyle;
|
|
278941
280478
|
rowNode.content.forEach((cellNode, cellIndex) => {
|
|
280479
|
+
if (isTableCellNode(cellNode) && isTableSkipPlaceholderCell(cellNode))
|
|
280480
|
+
return;
|
|
278942
280481
|
const parsedCell = parseTableCell({
|
|
278943
280482
|
cellNode,
|
|
278944
280483
|
rowIndex,
|
|
@@ -279289,7 +280828,7 @@ menclose::after {
|
|
|
279289
280828
|
return true;
|
|
279290
280829
|
}
|
|
279291
280830
|
return false;
|
|
279292
|
-
}, capitalizeText$
|
|
280831
|
+
}, capitalizeText$3 = (text5) => {
|
|
279293
280832
|
if (!text5)
|
|
279294
280833
|
return text5;
|
|
279295
280834
|
let result = "";
|
|
@@ -279299,7 +280838,7 @@ menclose::after {
|
|
|
279299
280838
|
result += isWordChar$3(ch) && !isWordChar$3(prevChar) ? ch.toUpperCase() : ch;
|
|
279300
280839
|
}
|
|
279301
280840
|
return result;
|
|
279302
|
-
}, applyTextTransform$
|
|
280841
|
+
}, applyTextTransform$3 = (text5, transform2) => {
|
|
279303
280842
|
if (!text5 || !transform2 || transform2 === "none")
|
|
279304
280843
|
return text5;
|
|
279305
280844
|
if (transform2 === "uppercase")
|
|
@@ -279307,7 +280846,7 @@ menclose::after {
|
|
|
279307
280846
|
if (transform2 === "lowercase")
|
|
279308
280847
|
return text5.toLowerCase();
|
|
279309
280848
|
if (transform2 === "capitalize")
|
|
279310
|
-
return capitalizeText$
|
|
280849
|
+
return capitalizeText$3(text5);
|
|
279311
280850
|
return text5;
|
|
279312
280851
|
}, countSpaces = (text5) => {
|
|
279313
280852
|
let spaces = 0;
|
|
@@ -280095,7 +281634,7 @@ menclose::after {
|
|
|
280095
281634
|
return false;
|
|
280096
281635
|
const code7 = char.charCodeAt(0);
|
|
280097
281636
|
return code7 >= 48 && code7 <= 57 || code7 >= 65 && code7 <= 90 || code7 >= 97 && code7 <= 122 || char === "'";
|
|
280098
|
-
}, capitalizeText$
|
|
281637
|
+
}, capitalizeText$2 = (text5, fullText, startOffset) => {
|
|
280099
281638
|
if (!text5)
|
|
280100
281639
|
return text5;
|
|
280101
281640
|
const hasFullText = typeof startOffset === "number" && fullText != null;
|
|
@@ -280106,7 +281645,7 @@ menclose::after {
|
|
|
280106
281645
|
result += isWordChar$1(ch) && !isWordChar$1(prevChar) ? ch.toUpperCase() : ch;
|
|
280107
281646
|
}
|
|
280108
281647
|
return result;
|
|
280109
|
-
}, applyTextTransform$
|
|
281648
|
+
}, applyTextTransform$2 = (text5, transform2, fullText, startOffset) => {
|
|
280110
281649
|
if (!text5 || !transform2 || transform2 === "none")
|
|
280111
281650
|
return text5;
|
|
280112
281651
|
if (transform2 === "uppercase")
|
|
@@ -280114,9 +281653,9 @@ menclose::after {
|
|
|
280114
281653
|
if (transform2 === "lowercase")
|
|
280115
281654
|
return text5.toLowerCase();
|
|
280116
281655
|
if (transform2 === "capitalize")
|
|
280117
|
-
return capitalizeText$
|
|
281656
|
+
return capitalizeText$2(text5, fullText, startOffset);
|
|
280118
281657
|
return text5;
|
|
280119
|
-
}, 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) => {
|
|
280120
281659
|
const width = run2.width;
|
|
280121
281660
|
return typeof width === "number" ? width : 0;
|
|
280122
281661
|
}, isLineBreakRun$1 = (run2) => run2.kind === "lineBreak" || run2.kind === "break" && run2.breakType === "line", markerFontString = (run2) => {
|
|
@@ -280895,7 +282434,9 @@ menclose::after {
|
|
|
280895
282434
|
let columnIndex = 0;
|
|
280896
282435
|
if (columns && columns.count > 1 && page) {
|
|
280897
282436
|
const fragment = findFragmentForPos(page, ref$1.pos);
|
|
280898
|
-
if (fragment && typeof fragment.
|
|
282437
|
+
if (fragment?.kind === "table" && typeof fragment.columnIndex === "number")
|
|
282438
|
+
columnIndex = Math.max(0, Math.min(columns.count - 1, fragment.columnIndex));
|
|
282439
|
+
else if (fragment && typeof fragment.x === "number") {
|
|
280899
282440
|
const widths = Array.isArray(columns.widths) && columns.widths.length > 0 ? columns.widths : undefined;
|
|
280900
282441
|
if (widths) {
|
|
280901
282442
|
let cursorX = columns.left;
|
|
@@ -281497,6 +283038,12 @@ menclose::after {
|
|
|
281497
283038
|
const relative = fragmentX;
|
|
281498
283039
|
const raw = Math.floor(relative / Math.max(span, 1));
|
|
281499
283040
|
return Math.max(0, Math.min(columns.count - 1, raw));
|
|
283041
|
+
}, determineTableColumn = (layout, fragment) => {
|
|
283042
|
+
if (typeof fragment.columnIndex === "number") {
|
|
283043
|
+
const count = layout.columns?.count ?? 1;
|
|
283044
|
+
return Math.max(0, Math.min(Math.max(0, count - 1), fragment.columnIndex));
|
|
283045
|
+
}
|
|
283046
|
+
return determineColumn(layout, fragment.x);
|
|
281500
283047
|
}, findLineIndexAtY = (lines, offsetY, fromLine, toLine) => {
|
|
281501
283048
|
if (!lines || lines.length === 0)
|
|
281502
283049
|
return null;
|
|
@@ -281716,13 +283263,13 @@ menclose::after {
|
|
|
281716
283263
|
if (startA == null)
|
|
281717
283264
|
return false;
|
|
281718
283265
|
return (endA ?? startA + 1) > startB && startA < endB;
|
|
281719
|
-
}, DEFAULT_CELL_PADDING$
|
|
283266
|
+
}, DEFAULT_CELL_PADDING$2, getCellPaddingFromRow = (cellIdx, row2) => {
|
|
281720
283267
|
const padding = row2?.cells?.[cellIdx]?.attrs?.padding ?? {};
|
|
281721
283268
|
return {
|
|
281722
|
-
top: padding.top ?? DEFAULT_CELL_PADDING$
|
|
281723
|
-
bottom: padding.bottom ?? DEFAULT_CELL_PADDING$
|
|
281724
|
-
left: padding.left ?? DEFAULT_CELL_PADDING$
|
|
281725
|
-
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
|
|
281726
283273
|
};
|
|
281727
283274
|
}, getCellBlocks = (cell2) => {
|
|
281728
283275
|
if (!cell2)
|
|
@@ -286202,7 +287749,41 @@ menclose::after {
|
|
|
286202
287749
|
}
|
|
286203
287750
|
}, EMUS_PER_INCH = 914400, maxSize = 5000, cache, makeKey = (text5, font, letterSpacing) => {
|
|
286204
287751
|
return `${text5}|${font}|${letterSpacing || 0}`;
|
|
286205
|
-
}, 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) => {
|
|
286206
287787
|
if (isValidFontSize(value))
|
|
286207
287788
|
return value;
|
|
286208
287789
|
if (typeof value === "string") {
|
|
@@ -288033,12 +289614,12 @@ menclose::after {
|
|
|
288033
289614
|
return;
|
|
288034
289615
|
console.log(...args$1);
|
|
288035
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;
|
|
288036
|
-
var
|
|
289617
|
+
var init_src_Dinif16O_es = __esm(() => {
|
|
288037
289618
|
init_rolldown_runtime_Bg48TavK_es();
|
|
288038
|
-
|
|
289619
|
+
init_SuperConverter_Dchjy0My_es();
|
|
288039
289620
|
init_jszip_C49i9kUs_es();
|
|
288040
289621
|
init_uuid_qzgm05fK_es();
|
|
288041
|
-
|
|
289622
|
+
init_create_headless_toolbar_CEcVKzGV_es();
|
|
288042
289623
|
init_constants_DrU4EASo_es();
|
|
288043
289624
|
init_dist_B8HfvhaK_es();
|
|
288044
289625
|
init_unified_Dsuw2be5_es();
|
|
@@ -288064,6 +289645,7 @@ var init_src_CCV76OsP_es = __esm(() => {
|
|
|
288064
289645
|
measureRowHeights: () => measureRowHeights,
|
|
288065
289646
|
resolveColumnWidths: () => resolveColumnWidths,
|
|
288066
289647
|
resolveSpacingIndent: () => resolveSpacingIndent,
|
|
289648
|
+
resolveTableWidthAttr: () => resolveTableWidthAttr,
|
|
288067
289649
|
scaleWrapPolygon: () => scaleWrapPolygon
|
|
288068
289650
|
}, 1);
|
|
288069
289651
|
floor2 = Math.floor;
|
|
@@ -305416,19 +306998,69 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
305416
306998
|
valid = false;
|
|
305417
306999
|
docSize = 0;
|
|
305418
307000
|
doc = null;
|
|
305419
|
-
|
|
305420
|
-
|
|
307001
|
+
searchModel = DEFAULT_SEARCH_MODEL$1;
|
|
307002
|
+
build(doc$12, options = {}) {
|
|
307003
|
+
const searchModel = options?.searchModel === "visible" ? "visible" : DEFAULT_SEARCH_MODEL$1;
|
|
307004
|
+
if (searchModel === "visible")
|
|
307005
|
+
this.#buildVisible(doc$12);
|
|
307006
|
+
else
|
|
307007
|
+
this.text = doc$12.textBetween(0, doc$12.content.size, BLOCK_SEPARATOR, ATOM_PLACEHOLDER);
|
|
305421
307008
|
this.segments = [];
|
|
305422
307009
|
this.docSize = doc$12.content.size;
|
|
305423
307010
|
this.doc = doc$12;
|
|
307011
|
+
this.searchModel = searchModel;
|
|
305424
307012
|
let offset$1 = 0;
|
|
307013
|
+
const visibleContext = searchModel === "visible" ? { deletionBarrierActive: false } : null;
|
|
305425
307014
|
this.#walkNodeContent(doc$12, 0, offset$1, (segment) => {
|
|
305426
307015
|
this.segments.push(segment);
|
|
305427
307016
|
offset$1 = segment.offsetEnd;
|
|
305428
|
-
});
|
|
307017
|
+
}, searchModel, visibleContext);
|
|
305429
307018
|
this.valid = true;
|
|
305430
307019
|
}
|
|
305431
|
-
#
|
|
307020
|
+
#buildVisible(doc$12) {
|
|
307021
|
+
const parts = [];
|
|
307022
|
+
let emittedDeletionBarrier = false;
|
|
307023
|
+
const appendDeletionBarrier = () => {
|
|
307024
|
+
if (emittedDeletionBarrier)
|
|
307025
|
+
return;
|
|
307026
|
+
parts.push(DELETION_BARRIER);
|
|
307027
|
+
emittedDeletionBarrier = true;
|
|
307028
|
+
};
|
|
307029
|
+
const walkNodeContent2 = (node2) => {
|
|
307030
|
+
let isFirstChild = true;
|
|
307031
|
+
node2.forEach((child) => {
|
|
307032
|
+
if (child.isBlock && !isFirstChild) {
|
|
307033
|
+
parts.push(BLOCK_SEPARATOR);
|
|
307034
|
+
emittedDeletionBarrier = false;
|
|
307035
|
+
}
|
|
307036
|
+
walkNode2(child);
|
|
307037
|
+
isFirstChild = false;
|
|
307038
|
+
});
|
|
307039
|
+
};
|
|
307040
|
+
const walkNode2 = (node2) => {
|
|
307041
|
+
if (node2.isText) {
|
|
307042
|
+
const text5 = node2.text || "";
|
|
307043
|
+
if (!text5.length)
|
|
307044
|
+
return;
|
|
307045
|
+
if (hasTrackDeleteMark$1(node2)) {
|
|
307046
|
+
appendDeletionBarrier();
|
|
307047
|
+
return;
|
|
307048
|
+
}
|
|
307049
|
+
parts.push(text5);
|
|
307050
|
+
emittedDeletionBarrier = false;
|
|
307051
|
+
return;
|
|
307052
|
+
}
|
|
307053
|
+
if (node2.isLeaf) {
|
|
307054
|
+
parts.push(ATOM_PLACEHOLDER);
|
|
307055
|
+
emittedDeletionBarrier = false;
|
|
307056
|
+
return;
|
|
307057
|
+
}
|
|
307058
|
+
walkNodeContent2(node2);
|
|
307059
|
+
};
|
|
307060
|
+
walkNodeContent2(doc$12);
|
|
307061
|
+
this.text = parts.join("");
|
|
307062
|
+
}
|
|
307063
|
+
#walkNodeContent(node2, contentStart, offset$1, addSegment, searchModel = DEFAULT_SEARCH_MODEL$1, context = null) {
|
|
305432
307064
|
let currentOffset = offset$1;
|
|
305433
307065
|
let isFirstChild = true;
|
|
305434
307066
|
node2.forEach((child, childContentOffset) => {
|
|
@@ -305442,16 +307074,34 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
305442
307074
|
kind: "blockSep"
|
|
305443
307075
|
});
|
|
305444
307076
|
currentOffset += 1;
|
|
307077
|
+
if (context && searchModel === "visible")
|
|
307078
|
+
context.deletionBarrierActive = false;
|
|
305445
307079
|
}
|
|
305446
|
-
currentOffset = this.#walkNode(child, childDocPos, currentOffset, addSegment);
|
|
307080
|
+
currentOffset = this.#walkNode(child, childDocPos, currentOffset, addSegment, searchModel, context);
|
|
305447
307081
|
isFirstChild = false;
|
|
305448
307082
|
});
|
|
305449
307083
|
return currentOffset;
|
|
305450
307084
|
}
|
|
305451
|
-
#walkNode(node2, docPos, offset$1, addSegment) {
|
|
307085
|
+
#walkNode(node2, docPos, offset$1, addSegment, searchModel = DEFAULT_SEARCH_MODEL$1, context = null) {
|
|
305452
307086
|
if (node2.isText) {
|
|
307087
|
+
if (searchModel === "visible" && hasTrackDeleteMark$1(node2)) {
|
|
307088
|
+
if (context?.deletionBarrierActive)
|
|
307089
|
+
return offset$1;
|
|
307090
|
+
addSegment({
|
|
307091
|
+
offsetStart: offset$1,
|
|
307092
|
+
offsetEnd: offset$1 + 1,
|
|
307093
|
+
docFrom: docPos,
|
|
307094
|
+
docTo: docPos,
|
|
307095
|
+
kind: "atom"
|
|
307096
|
+
});
|
|
307097
|
+
if (context)
|
|
307098
|
+
context.deletionBarrierActive = true;
|
|
307099
|
+
return offset$1 + 1;
|
|
307100
|
+
}
|
|
305453
307101
|
const text5 = node2.text || "";
|
|
305454
307102
|
if (text5.length > 0) {
|
|
307103
|
+
if (context && searchModel === "visible")
|
|
307104
|
+
context.deletionBarrierActive = false;
|
|
305455
307105
|
addSegment({
|
|
305456
307106
|
offsetStart: offset$1,
|
|
305457
307107
|
offsetEnd: offset$1 + text5.length,
|
|
@@ -305464,6 +307114,8 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
305464
307114
|
return offset$1;
|
|
305465
307115
|
}
|
|
305466
307116
|
if (node2.isLeaf) {
|
|
307117
|
+
if (context && searchModel === "visible")
|
|
307118
|
+
context.deletionBarrierActive = false;
|
|
305467
307119
|
if (node2.type.name === "hard_break") {
|
|
305468
307120
|
addSegment({
|
|
305469
307121
|
offsetStart: offset$1,
|
|
@@ -305483,17 +307135,18 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
305483
307135
|
});
|
|
305484
307136
|
return offset$1 + 1;
|
|
305485
307137
|
}
|
|
305486
|
-
return this.#walkNodeContent(node2, docPos + 1, offset$1, addSegment);
|
|
307138
|
+
return this.#walkNodeContent(node2, docPos + 1, offset$1, addSegment, searchModel, context);
|
|
305487
307139
|
}
|
|
305488
307140
|
invalidate() {
|
|
305489
307141
|
this.valid = false;
|
|
305490
307142
|
}
|
|
305491
|
-
isStale(doc$12) {
|
|
305492
|
-
|
|
307143
|
+
isStale(doc$12, options = {}) {
|
|
307144
|
+
const searchModel = options?.searchModel === "visible" ? "visible" : DEFAULT_SEARCH_MODEL$1;
|
|
307145
|
+
return !this.valid || this.doc !== doc$12 || this.searchModel !== searchModel;
|
|
305493
307146
|
}
|
|
305494
|
-
ensureValid(doc$12) {
|
|
305495
|
-
if (this.isStale(doc$12))
|
|
305496
|
-
this.build(doc$12);
|
|
307147
|
+
ensureValid(doc$12, options = {}) {
|
|
307148
|
+
if (this.isStale(doc$12, options))
|
|
307149
|
+
this.build(doc$12, options);
|
|
305497
307150
|
}
|
|
305498
307151
|
offsetRangeToDocRanges(start$1, end$1) {
|
|
305499
307152
|
const ranges = [];
|
|
@@ -305643,7 +307296,8 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
305643
307296
|
activeMatchIndex: -1,
|
|
305644
307297
|
query: "",
|
|
305645
307298
|
caseSensitive: false,
|
|
305646
|
-
ignoreDiacritics: false
|
|
307299
|
+
ignoreDiacritics: false,
|
|
307300
|
+
searchModel: DEFAULT_SEARCH_MODEL
|
|
305647
307301
|
};
|
|
305648
307302
|
},
|
|
305649
307303
|
addPmPlugins() {
|
|
@@ -305657,8 +307311,11 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
305657
307311
|
if (storage?.searchIndex)
|
|
305658
307312
|
storage.searchIndex.invalidate();
|
|
305659
307313
|
if (storage?.query) {
|
|
305660
|
-
storage.searchIndex.ensureValid(newState.doc);
|
|
305661
|
-
const indexMatches = (storage.ignoreDiacritics ? (q$1, opts) => storage.searchIndex.searchIgnoringDiacritics(q$1, opts) : (q$1, opts) => storage.searchIndex.search(q$1, opts))(storage.query, {
|
|
307314
|
+
storage.searchIndex.ensureValid(newState.doc, { searchModel: storage.searchModel ?? DEFAULT_SEARCH_MODEL });
|
|
307315
|
+
const indexMatches = (storage.ignoreDiacritics ? (q$1, opts) => storage.searchIndex.searchIgnoringDiacritics(q$1, opts) : (q$1, opts) => storage.searchIndex.search(q$1, opts))(storage.query, {
|
|
307316
|
+
caseSensitive: storage.caseSensitive,
|
|
307317
|
+
searchModel: storage.searchModel ?? DEFAULT_SEARCH_MODEL
|
|
307318
|
+
});
|
|
305662
307319
|
const refreshed = mapIndexMatchesToDocMatches({
|
|
305663
307320
|
searchIndex: storage.searchIndex,
|
|
305664
307321
|
indexMatches,
|
|
@@ -305756,11 +307413,12 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
305756
307413
|
} catch {}
|
|
305757
307414
|
return true;
|
|
305758
307415
|
},
|
|
305759
|
-
search: (patternInput, options = {}) => ({ state,
|
|
307416
|
+
search: (patternInput, options = {}) => ({ state, editor }) => {
|
|
305760
307417
|
if (options != null && (typeof options !== "object" || Array.isArray(options)))
|
|
305761
307418
|
throw new TypeError("Search options must be an object");
|
|
305762
307419
|
const highlight = typeof options?.highlight === "boolean" ? options.highlight : true;
|
|
305763
307420
|
const maxMatches = typeof options?.maxMatches === "number" ? options.maxMatches : 1000;
|
|
307421
|
+
const searchModel = normalizeSearchModel(options?.searchModel);
|
|
305764
307422
|
let caseSensitive = false;
|
|
305765
307423
|
let searchPattern = patternInput;
|
|
305766
307424
|
if (isRegExp2(patternInput)) {
|
|
@@ -305777,12 +307435,14 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
305777
307435
|
const positionTracker = getPositionTracker(editor);
|
|
305778
307436
|
positionTracker?.untrackByType?.(SEARCH_POSITION_TRACKER_TYPE);
|
|
305779
307437
|
const searchIndex = this.storage.searchIndex;
|
|
305780
|
-
searchIndex.ensureValid(state.doc);
|
|
307438
|
+
searchIndex.ensureValid(state.doc, { searchModel });
|
|
307439
|
+
this.storage.searchModel = searchModel;
|
|
305781
307440
|
const resultMatches = mapIndexMatchesToDocMatches({
|
|
305782
307441
|
searchIndex,
|
|
305783
307442
|
indexMatches: searchIndex.search(searchPattern, {
|
|
305784
307443
|
caseSensitive,
|
|
305785
|
-
maxMatches
|
|
307444
|
+
maxMatches,
|
|
307445
|
+
searchModel
|
|
305786
307446
|
}),
|
|
305787
307447
|
doc: state.doc,
|
|
305788
307448
|
positionTracker
|
|
@@ -305827,9 +307487,11 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
305827
307487
|
const caseSensitive = options.caseSensitive ?? false;
|
|
305828
307488
|
const ignoreDiacritics = options.ignoreDiacritics ?? false;
|
|
305829
307489
|
const highlight = options.highlight ?? true;
|
|
307490
|
+
const searchModel = normalizeSearchModel(options.searchModel);
|
|
305830
307491
|
this.storage.query = query;
|
|
305831
307492
|
this.storage.caseSensitive = caseSensitive;
|
|
305832
307493
|
this.storage.ignoreDiacritics = ignoreDiacritics;
|
|
307494
|
+
this.storage.searchModel = searchModel;
|
|
305833
307495
|
const positionTracker = getPositionTracker(editor);
|
|
305834
307496
|
positionTracker?.untrackByType?.(SEARCH_POSITION_TRACKER_TYPE);
|
|
305835
307497
|
if (!query) {
|
|
@@ -305842,10 +307504,16 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
305842
307504
|
};
|
|
305843
307505
|
}
|
|
305844
307506
|
const searchIndex = this.storage.searchIndex;
|
|
305845
|
-
searchIndex.ensureValid(state.doc);
|
|
307507
|
+
searchIndex.ensureValid(state.doc, { searchModel });
|
|
305846
307508
|
const resultMatches = mapIndexMatchesToDocMatches({
|
|
305847
307509
|
searchIndex,
|
|
305848
|
-
indexMatches: ignoreDiacritics ? searchIndex.searchIgnoringDiacritics(query, {
|
|
307510
|
+
indexMatches: ignoreDiacritics ? searchIndex.searchIgnoringDiacritics(query, {
|
|
307511
|
+
caseSensitive,
|
|
307512
|
+
searchModel
|
|
307513
|
+
}) : searchIndex.search(query, {
|
|
307514
|
+
caseSensitive,
|
|
307515
|
+
searchModel
|
|
307516
|
+
}),
|
|
305849
307517
|
doc: state.doc,
|
|
305850
307518
|
positionTracker
|
|
305851
307519
|
});
|
|
@@ -305865,9 +307533,10 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
305865
307533
|
this.storage.query = "";
|
|
305866
307534
|
this.storage.caseSensitive = false;
|
|
305867
307535
|
this.storage.ignoreDiacritics = false;
|
|
307536
|
+
this.storage.searchModel = DEFAULT_SEARCH_MODEL;
|
|
305868
307537
|
return true;
|
|
305869
307538
|
},
|
|
305870
|
-
nextSearchMatch: () => ({
|
|
307539
|
+
nextSearchMatch: () => ({ editor }) => {
|
|
305871
307540
|
const matches2 = this.storage.searchResults;
|
|
305872
307541
|
if (!matches2 || matches2.length === 0)
|
|
305873
307542
|
return {
|
|
@@ -305883,7 +307552,7 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
305883
307552
|
match: match$1
|
|
305884
307553
|
};
|
|
305885
307554
|
},
|
|
305886
|
-
previousSearchMatch: () => ({
|
|
307555
|
+
previousSearchMatch: () => ({ editor }) => {
|
|
305887
307556
|
const matches2 = this.storage.searchResults;
|
|
305888
307557
|
if (!matches2 || matches2.length === 0)
|
|
305889
307558
|
return {
|
|
@@ -305899,7 +307568,7 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
305899
307568
|
match: match$1
|
|
305900
307569
|
};
|
|
305901
307570
|
},
|
|
305902
|
-
replaceSearchMatch: (replacement) => ({ state, dispatch,
|
|
307571
|
+
replaceSearchMatch: (replacement) => ({ state, dispatch, commands: commands$1 }) => {
|
|
305903
307572
|
const matches2 = this.storage.searchResults;
|
|
305904
307573
|
const activeIdx = this.storage.activeMatchIndex;
|
|
305905
307574
|
if (!matches2 || activeIdx < 0 || activeIdx >= matches2.length)
|
|
@@ -305921,7 +307590,8 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
305921
307590
|
const result = commands$1.setSearchSession(this.storage.query, {
|
|
305922
307591
|
caseSensitive: this.storage.caseSensitive,
|
|
305923
307592
|
ignoreDiacritics: this.storage.ignoreDiacritics,
|
|
305924
|
-
highlight: this.storage.highlightEnabled
|
|
307593
|
+
highlight: this.storage.highlightEnabled,
|
|
307594
|
+
searchModel: this.storage.searchModel
|
|
305925
307595
|
});
|
|
305926
307596
|
if (result.matches.length > 0) {
|
|
305927
307597
|
const newIdx = Math.min(activeIdx, result.matches.length - 1);
|
|
@@ -314652,7 +316322,7 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
314652
316322
|
"even",
|
|
314653
316323
|
"odd"
|
|
314654
316324
|
];
|
|
314655
|
-
TWIPS_PER_PX$
|
|
316325
|
+
TWIPS_PER_PX$2 = 1440 / 96;
|
|
314656
316326
|
init_dist();
|
|
314657
316327
|
measureCache = new MeasureCache;
|
|
314658
316328
|
headerMeasureCache = new HeaderFooterLayoutCache;
|
|
@@ -314681,7 +316351,7 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
314681
316351
|
workerRoundTrip: 10,
|
|
314682
316352
|
layoutStaleness: 100
|
|
314683
316353
|
});
|
|
314684
|
-
DEFAULT_CELL_PADDING$
|
|
316354
|
+
DEFAULT_CELL_PADDING$2 = {
|
|
314685
316355
|
top: 0,
|
|
314686
316356
|
bottom: 0,
|
|
314687
316357
|
left: 4,
|
|
@@ -319288,6 +320958,16 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
319288
320958
|
EMUS_PER_INCH / 96;
|
|
319289
320959
|
cache = /* @__PURE__ */ new Map;
|
|
319290
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);
|
|
319291
320971
|
({ computeTabStops } = engines_exports);
|
|
319292
320972
|
measurementConfig = {
|
|
319293
320973
|
mode: "browser",
|
|
@@ -325160,11 +326840,11 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
325160
326840
|
];
|
|
325161
326841
|
});
|
|
325162
326842
|
|
|
325163
|
-
// ../../packages/superdoc/dist/chunks/create-super-doc-ui-
|
|
326843
|
+
// ../../packages/superdoc/dist/chunks/create-super-doc-ui-HW4PZyuU.es.js
|
|
325164
326844
|
var ALL_TOOLBAR_COMMAND_IDS, EMPTY_ACTIVE_IDS;
|
|
325165
|
-
var
|
|
325166
|
-
|
|
325167
|
-
|
|
326845
|
+
var init_create_super_doc_ui_HW4PZyuU_es = __esm(() => {
|
|
326846
|
+
init_SuperConverter_Dchjy0My_es();
|
|
326847
|
+
init_create_headless_toolbar_CEcVKzGV_es();
|
|
325168
326848
|
ALL_TOOLBAR_COMMAND_IDS = Object.keys(createToolbarRegistry());
|
|
325169
326849
|
EMPTY_ACTIVE_IDS = Object.freeze([]);
|
|
325170
326850
|
});
|
|
@@ -325182,16 +326862,16 @@ var init_zipper_BxRAi0_5_es = __esm(() => {
|
|
|
325182
326862
|
|
|
325183
326863
|
// ../../packages/superdoc/dist/super-editor.es.js
|
|
325184
326864
|
var init_super_editor_es = __esm(() => {
|
|
325185
|
-
|
|
325186
|
-
|
|
326865
|
+
init_src_Dinif16O_es();
|
|
326866
|
+
init_SuperConverter_Dchjy0My_es();
|
|
325187
326867
|
init_jszip_C49i9kUs_es();
|
|
325188
326868
|
init_xml_js_CqGKpaft_es();
|
|
325189
|
-
|
|
326869
|
+
init_create_headless_toolbar_CEcVKzGV_es();
|
|
325190
326870
|
init_constants_DrU4EASo_es();
|
|
325191
326871
|
init_dist_B8HfvhaK_es();
|
|
325192
326872
|
init_unified_Dsuw2be5_es();
|
|
325193
326873
|
init_DocxZipper_CUX64E5K_es();
|
|
325194
|
-
|
|
326874
|
+
init_create_super_doc_ui_HW4PZyuU_es();
|
|
325195
326875
|
init_ui_CGB3qmy3_es();
|
|
325196
326876
|
init_eventemitter3_BJrNoN9D_es();
|
|
325197
326877
|
init_errors_C_DoKMoN_es();
|
|
@@ -364932,7 +366612,8 @@ function executeTextSelector2(editor, index2, query2, diagnostics) {
|
|
|
364932
366612
|
const rawResult = search4(pattern, {
|
|
364933
366613
|
highlight: false,
|
|
364934
366614
|
caseSensitive: selector.caseSensitive ?? false,
|
|
364935
|
-
maxMatches: Infinity
|
|
366615
|
+
maxMatches: Infinity,
|
|
366616
|
+
searchModel: "visible"
|
|
364936
366617
|
});
|
|
364937
366618
|
if (!Array.isArray(rawResult)) {
|
|
364938
366619
|
throw new DocumentApiAdapterError3("CAPABILITY_UNAVAILABLE", "Editor search command returned an unexpected result format.");
|
|
@@ -408630,10 +410311,38 @@ var DEFAULT_PAGE_WIDTH_TWIPS = 12240, DEFAULT_PAGE_MARGIN_TWIPS = 1440, DEFAULT_
|
|
|
408630
410311
|
return twipsToPixels4(widthTwips);
|
|
408631
410312
|
}
|
|
408632
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
|
+
};
|
|
408633
410341
|
}, countColumnsInRow2 = (row2) => {
|
|
408634
410342
|
if (!row2?.elements?.length)
|
|
408635
410343
|
return 0;
|
|
408636
|
-
|
|
410344
|
+
const { gridBefore, gridAfter } = getRawRowGridMetadata2(row2);
|
|
410345
|
+
const cellSpanCount = row2.elements.reduce((count, element3) => {
|
|
408637
410346
|
if (element3.name !== "w:tc")
|
|
408638
410347
|
return count;
|
|
408639
410348
|
const tcPr = element3.elements?.find((el) => el.name === "w:tcPr");
|
|
@@ -408641,9 +410350,47 @@ var DEFAULT_PAGE_WIDTH_TWIPS = 12240, DEFAULT_PAGE_MARGIN_TWIPS = 1440, DEFAULT_
|
|
|
408641
410350
|
const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
|
|
408642
410351
|
return count + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
|
|
408643
410352
|
}, 0);
|
|
408644
|
-
|
|
408645
|
-
|
|
408646
|
-
|
|
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);
|
|
408647
410394
|
if (!columnCount)
|
|
408648
410395
|
return null;
|
|
408649
410396
|
const schemaDefaultPx = getSchemaDefaultColumnWidthPx2(params3);
|
|
@@ -408660,12 +410407,16 @@ var DEFAULT_PAGE_WIDTH_TWIPS = 12240, DEFAULT_PAGE_MARGIN_TWIPS = 1440, DEFAULT_
|
|
|
408660
410407
|
if (totalWidthPx == null) {
|
|
408661
410408
|
totalWidthPx = twipsToPixels4(DEFAULT_CONTENT_WIDTH_TWIPS2);
|
|
408662
410409
|
}
|
|
408663
|
-
const
|
|
408664
|
-
const
|
|
408665
|
-
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
|
+
});
|
|
408666
410417
|
return {
|
|
408667
|
-
grid:
|
|
408668
|
-
columnWidths:
|
|
410418
|
+
grid: fallbackColumnWidthTwips.map((columnWidthTwips) => ({ col: clampColumnWidthTwips2(columnWidthTwips) })),
|
|
410419
|
+
columnWidths: fallbackColumnWidthTwips.map((columnWidthTwips) => twipsToPixels4(columnWidthTwips))
|
|
408669
410420
|
};
|
|
408670
410421
|
};
|
|
408671
410422
|
var init_tableFallbackHelpers = __esm(() => {
|
|
@@ -430822,6 +432573,28 @@ function toNotFoundError2(input2) {
|
|
|
430822
432573
|
function isSameTarget2(left2, right2) {
|
|
430823
432574
|
return left2.blockId === right2.blockId && left2.range.start === right2.range.start && left2.range.end === right2.range.end;
|
|
430824
432575
|
}
|
|
432576
|
+
function isTextAddressShape2(target) {
|
|
432577
|
+
if (!target || typeof target !== "object")
|
|
432578
|
+
return false;
|
|
432579
|
+
const t = target;
|
|
432580
|
+
if (t.kind !== "text")
|
|
432581
|
+
return false;
|
|
432582
|
+
if (typeof t.blockId !== "string")
|
|
432583
|
+
return false;
|
|
432584
|
+
return isTextRangeShape2(t.range);
|
|
432585
|
+
}
|
|
432586
|
+
function isTextRangeShape2(range) {
|
|
432587
|
+
if (!range || typeof range !== "object")
|
|
432588
|
+
return false;
|
|
432589
|
+
const r2 = range;
|
|
432590
|
+
return Number.isInteger(r2.start) && Number.isInteger(r2.end) && r2.start <= r2.end;
|
|
432591
|
+
}
|
|
432592
|
+
function isTextSegmentShape2(segment) {
|
|
432593
|
+
if (!segment || typeof segment !== "object")
|
|
432594
|
+
return false;
|
|
432595
|
+
const seg = segment;
|
|
432596
|
+
return typeof seg.blockId === "string" && isTextRangeShape2(seg.range);
|
|
432597
|
+
}
|
|
430825
432598
|
function isTextTargetShape2(target) {
|
|
430826
432599
|
if (!target || typeof target !== "object")
|
|
430827
432600
|
return false;
|
|
@@ -430830,14 +432603,16 @@ function isTextTargetShape2(target) {
|
|
|
430830
432603
|
return false;
|
|
430831
432604
|
if (!Array.isArray(t.segments) || t.segments.length === 0)
|
|
430832
432605
|
return false;
|
|
430833
|
-
if (
|
|
432606
|
+
if (!t.segments.every(isTextSegmentShape2))
|
|
430834
432607
|
return false;
|
|
430835
432608
|
return true;
|
|
430836
432609
|
}
|
|
430837
432610
|
function targetToSegments2(target) {
|
|
432611
|
+
if (isTextAddressShape2(target))
|
|
432612
|
+
return [{ blockId: target.blockId, range: target.range }];
|
|
430838
432613
|
if (isTextTargetShape2(target))
|
|
430839
432614
|
return [...target.segments];
|
|
430840
|
-
return
|
|
432615
|
+
return null;
|
|
430841
432616
|
}
|
|
430842
432617
|
function listCommentAnchorsSafe2(editor) {
|
|
430843
432618
|
try {
|
|
@@ -431044,6 +432819,16 @@ function addCommentHandler2(editor, input2, options) {
|
|
|
431044
432819
|
};
|
|
431045
432820
|
}
|
|
431046
432821
|
const segments = targetToSegments2(target);
|
|
432822
|
+
if (!segments) {
|
|
432823
|
+
return {
|
|
432824
|
+
success: false,
|
|
432825
|
+
failure: {
|
|
432826
|
+
code: "INVALID_TARGET",
|
|
432827
|
+
message: "Comment target must be a TextAddress or TextTarget.",
|
|
432828
|
+
details: { target }
|
|
432829
|
+
}
|
|
432830
|
+
};
|
|
432831
|
+
}
|
|
431047
432832
|
for (const seg of segments) {
|
|
431048
432833
|
if (seg.range.start === seg.range.end) {
|
|
431049
432834
|
return {
|
|
@@ -436570,7 +438355,7 @@ function resolveCurrentSelectionInfo2(editor, input2) {
|
|
|
436570
438355
|
}
|
|
436571
438356
|
const sel = state.selection;
|
|
436572
438357
|
const { from: from4, to, empty: empty6 } = sel;
|
|
436573
|
-
const segments = collectTextSegments2(state.doc, from4, to);
|
|
438358
|
+
const segments = shouldProjectTextTarget2(sel) ? collectTextSegments2(state.doc, from4, to) : null;
|
|
436574
438359
|
const target = segments && segments.length > 0 ? buildTextTarget3(segments) : null;
|
|
436575
438360
|
const activeMarks = collectActiveMarks2(state, from4, to);
|
|
436576
438361
|
const { commentIds: activeCommentIds, changeIds: activeChangeRawIds } = collectActiveEntityIds2(state, from4, to);
|
|
@@ -436593,6 +438378,15 @@ function buildTextTarget3(segments) {
|
|
|
436593
438378
|
segments
|
|
436594
438379
|
};
|
|
436595
438380
|
}
|
|
438381
|
+
function shouldProjectTextTarget2(selection) {
|
|
438382
|
+
if (!selection || typeof selection !== "object")
|
|
438383
|
+
return false;
|
|
438384
|
+
if (selection instanceof NodeSelection3)
|
|
438385
|
+
return false;
|
|
438386
|
+
if ("$anchorCell" in selection)
|
|
438387
|
+
return false;
|
|
438388
|
+
return true;
|
|
438389
|
+
}
|
|
436596
438390
|
function collectTextSegments2(doc6, from4, to) {
|
|
436597
438391
|
const segments = [];
|
|
436598
438392
|
let abort = false;
|
|
@@ -436737,6 +438531,7 @@ function markTypesPresentEverywhere2(doc6, from4, to) {
|
|
|
436737
438531
|
}
|
|
436738
438532
|
var COMMENT_MARK_NAME4 = "commentMark", TRACK_CHANGE_MARK_NAMES2;
|
|
436739
438533
|
var init_selection_info_resolver = __esm(() => {
|
|
438534
|
+
init_dist5();
|
|
436740
438535
|
init_tracked_change_resolver();
|
|
436741
438536
|
TRACK_CHANGE_MARK_NAMES2 = new Set(["trackInsert", "trackDelete", "trackFormat"]);
|
|
436742
438537
|
});
|
|
@@ -436981,31 +438776,13 @@ function mapBorderSizes2(borders, sizeMapper) {
|
|
|
436981
438776
|
}
|
|
436982
438777
|
}
|
|
436983
438778
|
|
|
436984
|
-
// ../../packages/super-editor/src/editors/v1/document-api-adapters/
|
|
436985
|
-
function createSeparatorParagraph2(schema) {
|
|
436986
|
-
const paragraphType = schema.nodes.paragraph;
|
|
436987
|
-
if (!paragraphType)
|
|
436988
|
-
return null;
|
|
436989
|
-
const separatorAttrs = {
|
|
436990
|
-
sdBlockId: v42(),
|
|
436991
|
-
paraId: generateDocxHexId2()
|
|
436992
|
-
};
|
|
436993
|
-
return paragraphType.createAndFill(separatorAttrs) ?? paragraphType.createAndFill();
|
|
436994
|
-
}
|
|
436995
|
-
function buildTableSuccess2(tableAddress, trackedChangeRefs) {
|
|
436996
|
-
return {
|
|
436997
|
-
success: true,
|
|
436998
|
-
table: tableAddress,
|
|
436999
|
-
trackedChangeRefs
|
|
437000
|
-
};
|
|
437001
|
-
}
|
|
438779
|
+
// ../../packages/super-editor/src/editors/v1/document-api-adapters/helpers/table-attr-sync.ts
|
|
437002
438780
|
function syncExtractedTableAttrs2(tp) {
|
|
437003
438781
|
const extracted = {};
|
|
437004
438782
|
extracted.tableStyleId = tp.tableStyleId ?? null;
|
|
437005
438783
|
extracted.justification = tp.justification ?? null;
|
|
437006
438784
|
extracted.tableLayout = tp.tableLayout ?? null;
|
|
437007
|
-
|
|
437008
|
-
extracted.borders = pixelBorders ?? tp.borders ?? null;
|
|
438785
|
+
extracted.borders = convertTableBordersToPixelUnits2(tp.borders) ?? {};
|
|
437009
438786
|
const indent3 = tp.tableIndent;
|
|
437010
438787
|
if (indent3?.value != null) {
|
|
437011
438788
|
extracted.tableIndent = {
|
|
@@ -437018,7 +438795,7 @@ function syncExtractedTableAttrs2(tp) {
|
|
|
437018
438795
|
const spacing = tp.tableCellSpacing;
|
|
437019
438796
|
if (spacing?.value != null) {
|
|
437020
438797
|
extracted.tableCellSpacing = {
|
|
437021
|
-
|
|
438798
|
+
value: twipsToPixels4(spacing.value),
|
|
437022
438799
|
type: spacing.type ?? "dxa"
|
|
437023
438800
|
};
|
|
437024
438801
|
extracted.borderCollapse = "separate";
|
|
@@ -437026,15 +438803,15 @@ function syncExtractedTableAttrs2(tp) {
|
|
|
437026
438803
|
extracted.tableCellSpacing = null;
|
|
437027
438804
|
extracted.borderCollapse = null;
|
|
437028
438805
|
}
|
|
437029
|
-
const
|
|
437030
|
-
if (
|
|
437031
|
-
if (
|
|
437032
|
-
extracted.tableWidth = { value:
|
|
437033
|
-
} 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") {
|
|
437034
438811
|
extracted.tableWidth = { width: 0, type: "auto" };
|
|
437035
|
-
} else if (
|
|
437036
|
-
const widthPx = twipsToPixels4(
|
|
437037
|
-
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;
|
|
437038
438815
|
} else {
|
|
437039
438816
|
extracted.tableWidth = null;
|
|
437040
438817
|
}
|
|
@@ -437050,7 +438827,101 @@ function convertTableBordersToPixelUnits2(value) {
|
|
|
437050
438827
|
mapBorderSizes2(clone2, eighthPointsToPixels2);
|
|
437051
438828
|
return Object.keys(clone2).length > 0 ? clone2 : undefined;
|
|
437052
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
|
+
}
|
|
437053
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) {
|
|
437054
438925
|
if (typeof width === "number" && Number.isFinite(width)) {
|
|
437055
438926
|
return { col: Math.round(width) };
|
|
437056
438927
|
}
|
|
@@ -437062,16 +438933,16 @@ function normalizeGridWidth2(width) {
|
|
|
437062
438933
|
}
|
|
437063
438934
|
return { col: DEFAULT_TABLE_GRID_WIDTH_TWIPS2 };
|
|
437064
438935
|
}
|
|
437065
|
-
function
|
|
438936
|
+
function normalizeGridColumns3(grid) {
|
|
437066
438937
|
if (Array.isArray(grid)) {
|
|
437067
438938
|
if (grid.length === 0)
|
|
437068
438939
|
return null;
|
|
437069
|
-
return { columns: grid.map((width) =>
|
|
438940
|
+
return { columns: grid.map((width) => normalizeGridWidth3(width)), format: "array" };
|
|
437070
438941
|
}
|
|
437071
438942
|
if (grid && typeof grid === "object") {
|
|
437072
438943
|
const rawColWidths = grid.colWidths;
|
|
437073
438944
|
if (Array.isArray(rawColWidths) && rawColWidths.length > 0) {
|
|
437074
|
-
return { columns: rawColWidths.map((width) =>
|
|
438945
|
+
return { columns: rawColWidths.map((width) => normalizeGridWidth3(width)), format: "object" };
|
|
437075
438946
|
}
|
|
437076
438947
|
}
|
|
437077
438948
|
return null;
|
|
@@ -437083,17 +438954,17 @@ function serializeGridColumns2(originalGrid, normalized) {
|
|
|
437083
438954
|
return { ...originalGrid, colWidths: normalized.columns };
|
|
437084
438955
|
}
|
|
437085
438956
|
function insertGridColumnWidth2(grid, insertIndex) {
|
|
437086
|
-
const normalized =
|
|
438957
|
+
const normalized = normalizeGridColumns3(grid);
|
|
437087
438958
|
if (!normalized)
|
|
437088
438959
|
return null;
|
|
437089
438960
|
const colWidths = normalized.columns.slice();
|
|
437090
438961
|
const boundedIndex = Math.max(0, Math.min(insertIndex, colWidths.length));
|
|
437091
|
-
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);
|
|
437092
438963
|
colWidths.splice(boundedIndex, 0, { ...template });
|
|
437093
438964
|
return serializeGridColumns2(grid, { ...normalized, columns: colWidths });
|
|
437094
438965
|
}
|
|
437095
438966
|
function removeGridColumnWidth2(grid, deleteIndex) {
|
|
437096
|
-
const normalized =
|
|
438967
|
+
const normalized = normalizeGridColumns3(grid);
|
|
437097
438968
|
if (!normalized || normalized.columns.length <= 1)
|
|
437098
438969
|
return null;
|
|
437099
438970
|
const colWidths = normalized.columns.slice();
|
|
@@ -437101,6 +438972,29 @@ function removeGridColumnWidth2(grid, deleteIndex) {
|
|
|
437101
438972
|
colWidths.splice(boundedIndex, 1);
|
|
437102
438973
|
return serializeGridColumns2(grid, { ...normalized, columns: colWidths });
|
|
437103
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
|
+
}
|
|
437104
438998
|
function normalizeCellAttrsForSingleCell2(attrs) {
|
|
437105
438999
|
const currentColwidth = Array.isArray(attrs.colwidth) ? attrs.colwidth : null;
|
|
437106
439000
|
const tableCellProperties = {
|
|
@@ -438008,8 +439902,14 @@ function tablesSetColumnWidthAdapter2(editor, input2, options) {
|
|
|
438008
439902
|
const tablePos = table2.candidate.pos;
|
|
438009
439903
|
const tableStart = tablePos + 1;
|
|
438010
439904
|
const tableNode = table2.candidate.node;
|
|
439905
|
+
const tableAttrs = tableNode.attrs;
|
|
438011
439906
|
const map10 = TableMap2.get(tableNode);
|
|
438012
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
|
+
}
|
|
438013
439913
|
const processed = new Set;
|
|
438014
439914
|
for (let row2 = 0;row2 < map10.height; row2++) {
|
|
438015
439915
|
const index3 = row2 * map10.width + columnIndex;
|
|
@@ -438028,19 +439928,22 @@ function tablesSetColumnWidthAdapter2(editor, input2, options) {
|
|
|
438028
439928
|
while (colwidth.length < colspan)
|
|
438029
439929
|
colwidth.push(0);
|
|
438030
439930
|
colwidth[withinCol] = widthPx;
|
|
438031
|
-
|
|
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);
|
|
438032
439941
|
}
|
|
438033
|
-
const
|
|
438034
|
-
|
|
438035
|
-
|
|
438036
|
-
const newColumns = normalizedGrid.columns.slice();
|
|
438037
|
-
newColumns[columnIndex] = { col: Math.round(input2.widthPt * POINTS_TO_TWIPS2) };
|
|
438038
|
-
tr.setNodeMarkup(tablePos, null, {
|
|
438039
|
-
...tableAttrs,
|
|
438040
|
-
grid: serializeGridColumns2(tableAttrs.grid, { ...normalizedGrid, columns: newColumns }),
|
|
438041
|
-
userEdited: true
|
|
438042
|
-
});
|
|
439942
|
+
const tableAttrUpdates = {};
|
|
439943
|
+
if (normalizedGrid && nextGridColumns) {
|
|
439944
|
+
tableAttrUpdates.grid = serializeGridColumns2(tableAttrs.grid, { ...normalizedGrid, columns: nextGridColumns });
|
|
438043
439945
|
}
|
|
439946
|
+
tr.setNodeMarkup(tablePos, null, buildWidthAuthoringTableAttrs2(tableAttrs, tableAttrUpdates));
|
|
438044
439947
|
applyDirectMutationMeta2(tr);
|
|
438045
439948
|
editor.dispatch(tr);
|
|
438046
439949
|
clearIndexCache2(editor);
|
|
@@ -438065,7 +439968,10 @@ function tablesDistributeColumnsAdapter2(editor, input2, options) {
|
|
|
438065
439968
|
const tablePos = candidate.pos;
|
|
438066
439969
|
const tableStart = tablePos + 1;
|
|
438067
439970
|
const tableNode = candidate.node;
|
|
439971
|
+
const tableAttrs = tableNode.attrs;
|
|
438068
439972
|
const map10 = TableMap2.get(tableNode);
|
|
439973
|
+
const normalizedGrid = normalizeGridColumns3(tableAttrs.grid);
|
|
439974
|
+
const nextGridColumns = normalizedGrid?.columns.slice();
|
|
438069
439975
|
const rangeStart = input2.columnRange?.start ?? 0;
|
|
438070
439976
|
const rangeEnd = input2.columnRange?.end ?? map10.width - 1;
|
|
438071
439977
|
const rangeWidth = rangeEnd - rangeStart + 1;
|
|
@@ -438081,6 +439987,13 @@ function tablesDistributeColumnsAdapter2(editor, input2, options) {
|
|
|
438081
439987
|
totalWidth += colwidth?.[withinCol] ?? 100;
|
|
438082
439988
|
}
|
|
438083
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
|
+
}
|
|
438084
439997
|
const processed = new Set;
|
|
438085
439998
|
for (let row2 = 0;row2 < map10.height; row2++) {
|
|
438086
439999
|
for (let col = rangeStart;col <= rangeEnd; col++) {
|
|
@@ -438104,22 +440017,23 @@ function tablesDistributeColumnsAdapter2(editor, input2, options) {
|
|
|
438104
440017
|
newColwidth[c] = evenWidth;
|
|
438105
440018
|
}
|
|
438106
440019
|
}
|
|
438107
|
-
|
|
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);
|
|
438108
440030
|
}
|
|
438109
440031
|
}
|
|
438110
|
-
const
|
|
438111
|
-
|
|
438112
|
-
|
|
438113
|
-
if (normalizedGrid) {
|
|
438114
|
-
const newColumns = normalizedGrid.columns.slice();
|
|
438115
|
-
const evenWidthTwips = Math.max(1, Math.round(evenWidth * PIXELS_TO_TWIPS2));
|
|
438116
|
-
const maxColumn = Math.min(rangeEnd, newColumns.length - 1);
|
|
438117
|
-
for (let col = Math.max(rangeStart, 0);col <= maxColumn; col++) {
|
|
438118
|
-
newColumns[col] = { col: evenWidthTwips };
|
|
438119
|
-
}
|
|
438120
|
-
tableAttrUpdates.grid = serializeGridColumns2(tableAttrs.grid, { ...normalizedGrid, columns: newColumns });
|
|
440032
|
+
const tableAttrUpdates = {};
|
|
440033
|
+
if (normalizedGrid && nextGridColumns) {
|
|
440034
|
+
tableAttrUpdates.grid = serializeGridColumns2(tableAttrs.grid, { ...normalizedGrid, columns: nextGridColumns });
|
|
438121
440035
|
}
|
|
438122
|
-
tr.setNodeMarkup(tablePos, null, tableAttrUpdates);
|
|
440036
|
+
tr.setNodeMarkup(tablePos, null, buildWidthAuthoringTableAttrs2(tableAttrs, tableAttrUpdates));
|
|
438123
440037
|
applyDirectMutationMeta2(tr);
|
|
438124
440038
|
editor.dispatch(tr);
|
|
438125
440039
|
clearIndexCache2(editor);
|
|
@@ -438765,6 +440679,10 @@ function tablesSetCellPropertiesAdapter2(editor, input2, options) {
|
|
|
438765
440679
|
tableCellProperties: { ...currentCellProps, ...cellPropUpdates }
|
|
438766
440680
|
};
|
|
438767
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
|
+
}
|
|
438768
440686
|
applyDirectMutationMeta2(tr);
|
|
438769
440687
|
editor.dispatch(tr);
|
|
438770
440688
|
clearIndexCache2(editor);
|
|
@@ -439954,10 +441872,10 @@ var init_tables_adapter = __esm(() => {
|
|
|
439954
441872
|
init_tracked_change_refs();
|
|
439955
441873
|
init_errors4();
|
|
439956
441874
|
init_node_address_resolver();
|
|
439957
|
-
init_helpers();
|
|
439958
441875
|
init_ooxml();
|
|
439959
441876
|
init_document_settings();
|
|
439960
441877
|
init_mutate_part();
|
|
441878
|
+
init_table_attr_sync();
|
|
439961
441879
|
POINTS_TO_PIXELS2 = 96 / 72;
|
|
439962
441880
|
PIXELS_TO_TWIPS2 = 1440 / 96;
|
|
439963
441881
|
WORD_DEFAULT_TBL_LOOK2 = {
|