@superdoc-dev/cli 0.16.0-next.29 → 0.16.0-next.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +1163 -755
  2. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -68373,7 +68373,7 @@ var init_remark_gfm_BhnWr3yf_es = __esm(() => {
68373
68373
  emptyOptions2 = {};
68374
68374
  });
68375
68375
 
68376
- // ../../packages/superdoc/dist/chunks/SuperConverter-BBjNvGFh.es.js
68376
+ // ../../packages/superdoc/dist/chunks/SuperConverter-bEQ45IUD.es.js
68377
68377
  function getExtensionConfigField(extension$1, field, context = { name: "" }) {
68378
68378
  const fieldValue = extension$1.config[field];
68379
68379
  if (typeof fieldValue === "function")
@@ -78331,70 +78331,6 @@ function computeFragmentPmRange(block, lines, fromLine, toLine) {
78331
78331
  pmEnd
78332
78332
  };
78333
78333
  }
78334
- function resolveAnchoredGraphicY(input) {
78335
- const { anchor, objectHeight, contentTop, contentBottom, pageBottomMargin = 0, anchorParagraphY = contentTop, firstLineHeight = 0, preRegisteredFallbackToContentTop = false } = input;
78336
- const offsetV = anchor?.offsetV ?? 0;
78337
- const vRelativeFrom = anchor?.vRelativeFrom;
78338
- const alignV = anchor?.alignV;
78339
- const contentHeight = Math.max(0, contentBottom - contentTop);
78340
- if (vRelativeFrom === "margin") {
78341
- if (alignV === "bottom")
78342
- return contentBottom - objectHeight + offsetV;
78343
- if (alignV === "center")
78344
- return contentTop + (contentHeight - objectHeight) / 2 + offsetV;
78345
- return contentTop + offsetV;
78346
- }
78347
- if (vRelativeFrom === "page") {
78348
- const pageHeight = contentBottom + pageBottomMargin;
78349
- if (alignV === "bottom")
78350
- return pageHeight - objectHeight + offsetV;
78351
- if (alignV === "center")
78352
- return (pageHeight - objectHeight) / 2 + offsetV;
78353
- return offsetV;
78354
- }
78355
- if (vRelativeFrom === "paragraph") {
78356
- if (preRegisteredFallbackToContentTop)
78357
- return contentTop + offsetV;
78358
- const baseAnchorY = anchorParagraphY;
78359
- if (alignV === "bottom")
78360
- return baseAnchorY + firstLineHeight - objectHeight + offsetV;
78361
- if (alignV === "center")
78362
- return baseAnchorY + (firstLineHeight - objectHeight) / 2 + offsetV;
78363
- return baseAnchorY + offsetV;
78364
- }
78365
- if (preRegisteredFallbackToContentTop)
78366
- return contentTop + offsetV;
78367
- return anchorParagraphY + offsetV;
78368
- }
78369
- function resolveAnchoredGraphicX(anchor, columnIndex, columns, objectWidth, margins, pageWidth) {
78370
- const alignH = anchor.alignH ?? "left";
78371
- const offsetH = anchor.offsetH ?? 0;
78372
- const marginLeft = Math.max(0, margins?.left ?? 0);
78373
- const marginRight = Math.max(0, margins?.right ?? 0);
78374
- const contentWidth = pageWidth != null ? Math.max(1, pageWidth - (marginLeft + marginRight)) : columns.width;
78375
- const contentLeft = marginLeft;
78376
- const columnLeft = contentLeft + columnIndex * (columns.width + columns.gap);
78377
- const relativeFrom = anchor.hRelativeFrom ?? "column";
78378
- let baseX;
78379
- let availableWidth;
78380
- if (relativeFrom === "page") {
78381
- baseX = 0;
78382
- availableWidth = pageWidth != null ? pageWidth : contentWidth + marginLeft + marginRight;
78383
- } else if (relativeFrom === "margin") {
78384
- baseX = contentLeft;
78385
- availableWidth = contentWidth;
78386
- } else {
78387
- baseX = columnLeft;
78388
- availableWidth = columns.width;
78389
- }
78390
- if (alignH === "left")
78391
- return baseX + offsetH;
78392
- if (alignH === "right")
78393
- return baseX + availableWidth - objectWidth - offsetH;
78394
- if (alignH === "center")
78395
- return baseX + (availableWidth - objectWidth) / 2 + offsetH;
78396
- return baseX;
78397
- }
78398
78334
  function widthsEqual(a, b) {
78399
78335
  if (!a && !b)
78400
78336
  return true;
@@ -78438,23 +78374,29 @@ function resolveColumnLayout(input) {
78438
78374
  const resolved = cloneColumnLayout(input);
78439
78375
  resolved.count = count2;
78440
78376
  if (resolveColumnMode(input) === "explicit") {
78441
- if (Array.isArray(resolved.widths))
78442
- resolved.widths = resolved.widths.slice(0, count2);
78443
- if (Array.isArray(resolved.gaps))
78444
- resolved.gaps = resolved.gaps.slice(0, Math.max(0, count2 - 1));
78377
+ if (Array.isArray(resolved.widths)) {
78378
+ const rawGaps = Array.isArray(resolved.gaps) ? resolved.gaps : [];
78379
+ const usable = resolved.widths.map((width, i$1) => ({
78380
+ width,
78381
+ gapAfter: rawGaps[i$1]
78382
+ })).filter((record) => typeof record.width === "number" && Number.isFinite(record.width) && record.width > 0).slice(0, count2);
78383
+ resolved.widths = usable.map((record) => record.width);
78384
+ if (Array.isArray(resolved.gaps))
78385
+ resolved.gaps = usable.slice(0, Math.max(0, count2 - 1)).map((record) => record.gapAfter ?? 0);
78386
+ }
78445
78387
  } else {
78446
78388
  delete resolved.widths;
78447
78389
  delete resolved.gaps;
78448
78390
  }
78449
78391
  return resolved;
78450
78392
  }
78451
- function buildColumnGeometry(widths, gap, withSeparator) {
78393
+ function buildColumnGeometry(widths, gap, withSeparator, gaps) {
78452
78394
  const geometry = [];
78453
78395
  let x = 0;
78454
78396
  for (let i$1 = 0;i$1 < widths.length; i$1 += 1) {
78455
78397
  const width = widths[i$1];
78456
78398
  const isLast = i$1 === widths.length - 1;
78457
- const gapAfter = isLast ? 0 : gap;
78399
+ const gapAfter = isLast ? 0 : gaps?.[i$1] ?? gap;
78458
78400
  const col = {
78459
78401
  index: i$1,
78460
78402
  x,
@@ -78462,7 +78404,7 @@ function buildColumnGeometry(widths, gap, withSeparator) {
78462
78404
  gapAfter
78463
78405
  };
78464
78406
  if (withSeparator && !isLast)
78465
- col.separatorX = x + width + gap / 2;
78407
+ col.separatorX = x + width + gapAfter / 2;
78466
78408
  geometry.push(col);
78467
78409
  x += width + gapAfter;
78468
78410
  }
@@ -78479,11 +78421,9 @@ function normalizeColumnLayout(input, contentWidth, epsilon = 0.0001) {
78479
78421
  const fallbackWidth = count2 - widths.length > 0 ? remaining / (count2 - widths.length) : 0;
78480
78422
  widths.push(...Array.from({ length: count2 - widths.length }, () => fallbackWidth));
78481
78423
  }
78482
- const totalExplicitWidth = widths.reduce((sum, width$1) => sum + width$1, 0);
78483
- if (availableWidth > 0 && totalExplicitWidth > 0) {
78484
- const scale = availableWidth / totalExplicitWidth;
78485
- widths = widths.map((width$1) => Math.max(1, width$1 * scale));
78486
- }
78424
+ if (availableWidth > 0)
78425
+ widths = widths.map((value) => Math.max(1, value));
78426
+ const gaps = explicitWidths.length > 0 && Array.isArray(input?.gaps) ? input.gaps.slice(0, Math.max(0, count2 - 1)) : undefined;
78487
78427
  const width = widths.reduce((max4, value) => Math.max(max4, value), 0);
78488
78428
  if (!Number.isFinite(width) || width <= epsilon)
78489
78429
  return {
@@ -78496,13 +78436,15 @@ function normalizeColumnLayout(input, contentWidth, epsilon = 0.0001) {
78496
78436
  count: count2,
78497
78437
  gap,
78498
78438
  ...widths.length > 0 ? { widths } : {},
78439
+ ...gaps && gaps.length > 0 ? { gaps } : {},
78499
78440
  ...input?.equalWidth !== undefined ? { equalWidth: input.equalWidth } : {},
78500
78441
  ...input?.withSeparator !== undefined ? { withSeparator: input.withSeparator } : {},
78501
78442
  width
78502
78443
  };
78503
78444
  }
78504
78445
  function getColumnGeometry(normalized) {
78505
- return buildColumnGeometry(Array.isArray(normalized.widths) && normalized.widths.length > 0 ? normalized.widths : [normalized.width], normalized.gap, Boolean(normalized.withSeparator));
78446
+ const count2 = Number.isFinite(normalized.count) ? Math.max(1, Math.floor(normalized.count)) : 1;
78447
+ return buildColumnGeometry(Array.isArray(normalized.widths) && normalized.widths.length > 0 ? normalized.widths : new Array(count2).fill(normalized.width), normalized.gap, Boolean(normalized.withSeparator), normalized.gaps);
78506
78448
  }
78507
78449
  function clampColumnIndex(geometry, index2) {
78508
78450
  if (geometry.length === 0)
@@ -78518,6 +78460,18 @@ function getColumnX(geometry, index2, originX = 0) {
78518
78460
  function getColumnSeparatorPositions(geometry, originX = 0) {
78519
78461
  return geometry.filter((col) => typeof col.separatorX === "number").map((col) => originX + col.separatorX);
78520
78462
  }
78463
+ function getColumnAtX(geometry, x, originX = 0) {
78464
+ if (geometry.length === 0)
78465
+ return 0;
78466
+ const cx = x - originX;
78467
+ let result = 0;
78468
+ for (const col of geometry)
78469
+ if (cx >= col.x)
78470
+ result = col.index;
78471
+ else
78472
+ break;
78473
+ return result;
78474
+ }
78521
78475
  function columnRenderLayoutsEqual(a, b) {
78522
78476
  if (!a && !b)
78523
78477
  return true;
@@ -78540,6 +78494,70 @@ function columnRenderLayoutsEqual(a, b) {
78540
78494
  }
78541
78495
  return true;
78542
78496
  }
78497
+ function resolveAnchoredGraphicY(input) {
78498
+ const { anchor, objectHeight, contentTop, contentBottom, pageBottomMargin = 0, anchorParagraphY = contentTop, firstLineHeight = 0, preRegisteredFallbackToContentTop = false } = input;
78499
+ const offsetV = anchor?.offsetV ?? 0;
78500
+ const vRelativeFrom = anchor?.vRelativeFrom;
78501
+ const alignV = anchor?.alignV;
78502
+ const contentHeight = Math.max(0, contentBottom - contentTop);
78503
+ if (vRelativeFrom === "margin") {
78504
+ if (alignV === "bottom")
78505
+ return contentBottom - objectHeight + offsetV;
78506
+ if (alignV === "center")
78507
+ return contentTop + (contentHeight - objectHeight) / 2 + offsetV;
78508
+ return contentTop + offsetV;
78509
+ }
78510
+ if (vRelativeFrom === "page") {
78511
+ const pageHeight = contentBottom + pageBottomMargin;
78512
+ if (alignV === "bottom")
78513
+ return pageHeight - objectHeight + offsetV;
78514
+ if (alignV === "center")
78515
+ return (pageHeight - objectHeight) / 2 + offsetV;
78516
+ return offsetV;
78517
+ }
78518
+ if (vRelativeFrom === "paragraph") {
78519
+ if (preRegisteredFallbackToContentTop)
78520
+ return contentTop + offsetV;
78521
+ const baseAnchorY = anchorParagraphY;
78522
+ if (alignV === "bottom")
78523
+ return baseAnchorY + firstLineHeight - objectHeight + offsetV;
78524
+ if (alignV === "center")
78525
+ return baseAnchorY + (firstLineHeight - objectHeight) / 2 + offsetV;
78526
+ return baseAnchorY + offsetV;
78527
+ }
78528
+ if (preRegisteredFallbackToContentTop)
78529
+ return contentTop + offsetV;
78530
+ return anchorParagraphY + offsetV;
78531
+ }
78532
+ function resolveAnchoredGraphicX(anchor, columnIndex, columns, objectWidth, margins, pageWidth) {
78533
+ const alignH = anchor.alignH ?? "left";
78534
+ const offsetH = anchor.offsetH ?? 0;
78535
+ const marginLeft = Math.max(0, margins?.left ?? 0);
78536
+ const marginRight = Math.max(0, margins?.right ?? 0);
78537
+ const contentWidth = pageWidth != null ? Math.max(1, pageWidth - (marginLeft + marginRight)) : columns.width;
78538
+ const contentLeft = marginLeft;
78539
+ const geometry = getColumnGeometry(columns);
78540
+ const relativeFrom = anchor.hRelativeFrom ?? "column";
78541
+ let baseX;
78542
+ let availableWidth;
78543
+ if (relativeFrom === "page") {
78544
+ baseX = 0;
78545
+ availableWidth = pageWidth != null ? pageWidth : contentWidth + marginLeft + marginRight;
78546
+ } else if (relativeFrom === "margin") {
78547
+ baseX = contentLeft;
78548
+ availableWidth = contentWidth;
78549
+ } else {
78550
+ baseX = getColumnX(geometry, columnIndex, contentLeft);
78551
+ availableWidth = columns.width;
78552
+ }
78553
+ if (alignH === "left")
78554
+ return baseX + offsetH;
78555
+ if (alignH === "right")
78556
+ return baseX + availableWidth - objectWidth - offsetH;
78557
+ if (alignH === "center")
78558
+ return baseX + (availableWidth - objectWidth) / 2 + offsetH;
78559
+ return baseX;
78560
+ }
78543
78561
  function getIdlessSdtContainerKey(metadata) {
78544
78562
  const existingKey = idlessSdtContainerKeys.get(metadata);
78545
78563
  if (existingKey)
@@ -98389,17 +98407,40 @@ function translateAnchorNode(params3) {
98389
98407
  wrapElement.attributes = attributes;
98390
98408
  break;
98391
98409
  }
98392
- case "Through":
98393
98410
  case "Tight": {
98394
98411
  const attributes = {};
98395
98412
  if ("distLeft" in (attrs.wrap.attrs || {}))
98396
98413
  attributes.distL = pixelsToEmu(attrs.wrap.attrs.distLeft);
98397
98414
  if ("distRight" in (attrs.wrap.attrs || {}))
98398
98415
  attributes.distR = pixelsToEmu(attrs.wrap.attrs.distRight);
98399
- if ("distTop" in (attrs.wrap.attrs || {}))
98400
- attributes.distT = pixelsToEmu(attrs.wrap.attrs.distTop);
98416
+ const wrapText = attrs.wrap.attrs?.wrapText || "bothSides";
98417
+ if (wrapText)
98418
+ attributes.wrapText = wrapText;
98419
+ if (Object.keys(attributes).length)
98420
+ wrapElement.attributes = attributes;
98421
+ if (attrs.wrap.attrs?.polygon) {
98422
+ const polygonNode = objToPolygon(attrs.wrap.attrs.polygon);
98423
+ if (polygonNode) {
98424
+ if (attrs.wrap.attrs?.polygonEdited !== undefined)
98425
+ polygonNode.attributes = {
98426
+ ...polygonNode.attributes || {},
98427
+ edited: String(attrs.wrap.attrs.polygonEdited)
98428
+ };
98429
+ wrapElement.elements = [polygonNode];
98430
+ }
98431
+ }
98432
+ break;
98433
+ }
98434
+ case "Through": {
98435
+ const attributes = {};
98401
98436
  if ("distBottom" in (attrs.wrap.attrs || {}))
98402
98437
  attributes.distB = pixelsToEmu(attrs.wrap.attrs.distBottom);
98438
+ if ("distLeft" in (attrs.wrap.attrs || {}))
98439
+ attributes.distL = pixelsToEmu(attrs.wrap.attrs.distLeft);
98440
+ if ("distRight" in (attrs.wrap.attrs || {}))
98441
+ attributes.distR = pixelsToEmu(attrs.wrap.attrs.distRight);
98442
+ if ("distTop" in (attrs.wrap.attrs || {}))
98443
+ attributes.distT = pixelsToEmu(attrs.wrap.attrs.distTop);
98403
98444
  const wrapText = attrs.wrap.attrs?.wrapText || "bothSides";
98404
98445
  if (wrapText)
98405
98446
  attributes.wrapText = wrapText;
@@ -105921,6 +105962,22 @@ function normalizeLegacyBorderStyle(value) {
105921
105962
  return "single";
105922
105963
  }
105923
105964
  }
105965
+ function countFloatingTableContentColumns(node3) {
105966
+ const grid = node3.attrs?.grid;
105967
+ if (Array.isArray(grid) && grid.length > 0)
105968
+ return grid.length;
105969
+ const firstRow = node3.content?.[0];
105970
+ if (!firstRow || !isTableRowNode(firstRow) || !Array.isArray(firstRow.content))
105971
+ return 0;
105972
+ let columns = 0;
105973
+ for (const cellNode of firstRow.content) {
105974
+ if (!cellNode || !isTableCellNode(cellNode))
105975
+ continue;
105976
+ const colSpan = typeof cellNode.attrs?.colspan === "number" ? cellNode.attrs.colspan : 1;
105977
+ columns += colSpan > 0 ? colSpan : 1;
105978
+ }
105979
+ return columns;
105980
+ }
105924
105981
  function extractFloatingTableAnchorWrap(node3) {
105925
105982
  const floatingProps = node3.attrs?.tableProperties?.floatingTableProperties;
105926
105983
  if (!floatingProps)
@@ -105962,9 +106019,11 @@ function extractFloatingTableAnchorWrap(node3) {
105962
106019
  anchor.offsetH = twipsToPx(floatingProps.tblpX);
105963
106020
  if (floatingProps.tblpY !== undefined)
105964
106021
  anchor.offsetV = twipsToPx(floatingProps.tblpY);
105965
- const hasDistances = floatingProps.leftFromText !== undefined || floatingProps.rightFromText !== undefined || floatingProps.topFromText !== undefined || floatingProps.bottomFromText !== undefined;
106022
+ const hasHorizontalDistances = floatingProps.leftFromText !== undefined || floatingProps.rightFromText !== undefined;
106023
+ const hasVerticalDistances = floatingProps.topFromText !== undefined || floatingProps.bottomFromText !== undefined;
106024
+ const hasDistances = hasHorizontalDistances || hasVerticalDistances;
105966
106025
  const wrap$1 = {
105967
- type: "Square",
106026
+ type: countFloatingTableContentColumns(node3) <= 1 && hasHorizontalDistances && !hasVerticalDistances ? "None" : "Square",
105968
106027
  wrapText: "bothSides"
105969
106028
  };
105970
106029
  if (hasDistances) {
@@ -121411,13 +121470,16 @@ var isRegExp = (value) => {
121411
121470
  }, mergeAnchorPaddingIntoWrapDistances = (wrap$1, padding) => {
121412
121471
  if (!wrap$1?.attrs || !padding)
121413
121472
  return;
121414
- if (wrap$1.attrs.distTop == null && Number.isFinite(padding.top) && padding.top !== 0)
121473
+ const type = wrap$1.type;
121474
+ const mergeVertical = type === "Square" || type === "TopAndBottom";
121475
+ const mergeHorizontal = type === "Square" || type === "Tight" || type === "Through";
121476
+ if (mergeVertical && wrap$1.attrs.distTop == null && Number.isFinite(padding.top) && padding.top !== 0)
121415
121477
  wrap$1.attrs.distTop = padding.top;
121416
- if (wrap$1.attrs.distBottom == null && Number.isFinite(padding.bottom) && padding.bottom !== 0)
121478
+ if (mergeVertical && wrap$1.attrs.distBottom == null && Number.isFinite(padding.bottom) && padding.bottom !== 0)
121417
121479
  wrap$1.attrs.distBottom = padding.bottom;
121418
- if (wrap$1.attrs.distLeft == null && Number.isFinite(padding.left) && padding.left !== 0)
121480
+ if (mergeHorizontal && wrap$1.attrs.distLeft == null && Number.isFinite(padding.left) && padding.left !== 0)
121419
121481
  wrap$1.attrs.distLeft = padding.left;
121420
- if (wrap$1.attrs.distRight == null && Number.isFinite(padding.right) && padding.right !== 0)
121482
+ if (mergeHorizontal && wrap$1.attrs.distRight == null && Number.isFinite(padding.right) && padding.right !== 0)
121421
121483
  wrap$1.attrs.distRight = padding.right;
121422
121484
  }, handleShapeDrawing = (params3, node3, graphicData, size2, padding, marginOffset, anchorData, wrap$1, isAnchor, isHidden) => {
121423
121485
  const wsp = graphicData.elements.find((el) => el.name === "wps:wsp");
@@ -130043,13 +130105,15 @@ var isRegExp = (value) => {
130043
130105
  }, mergeWrapDistancesFromPadding = (wrap$1, padding) => {
130044
130106
  if (!padding || wrap$1.type === "None" || wrap$1.type === "Inline")
130045
130107
  return;
130046
- if (wrap$1.distTop == null && padding.top != null)
130108
+ const mergeVertical = wrap$1.type === "Square" || wrap$1.type === "TopAndBottom";
130109
+ const mergeHorizontal = wrap$1.type === "Square" || wrap$1.type === "Tight" || wrap$1.type === "Through";
130110
+ if (mergeVertical && wrap$1.distTop == null && padding.top != null)
130047
130111
  wrap$1.distTop = padding.top;
130048
- if (wrap$1.distBottom == null && padding.bottom != null)
130112
+ if (mergeVertical && wrap$1.distBottom == null && padding.bottom != null)
130049
130113
  wrap$1.distBottom = padding.bottom;
130050
- if (wrap$1.distLeft == null && padding.left != null)
130114
+ if (mergeHorizontal && wrap$1.distLeft == null && padding.left != null)
130051
130115
  wrap$1.distLeft = padding.left;
130052
- if (wrap$1.distRight == null && padding.right != null)
130116
+ if (mergeHorizontal && wrap$1.distRight == null && padding.right != null)
130053
130117
  wrap$1.distRight = padding.right;
130054
130118
  }, normalizeColor = (value) => {
130055
130119
  if (typeof value !== "string")
@@ -133130,7 +133194,7 @@ var isRegExp = (value) => {
133130
133194
  state.kern = kernNode.attributes["w:val"];
133131
133195
  }
133132
133196
  }, SuperConverter;
133133
- var init_SuperConverter_BBjNvGFh_es = __esm(() => {
133197
+ var init_SuperConverter_bEQ45IUD_es = __esm(() => {
133134
133198
  init_rolldown_runtime_Bg48TavK_es();
133135
133199
  init_jszip_C49i9kUs_es();
133136
133200
  init_xml_js_CqGKpaft_es();
@@ -172190,7 +172254,7 @@ var init_SuperConverter_BBjNvGFh_es = __esm(() => {
172190
172254
  };
172191
172255
  });
172192
172256
 
172193
- // ../../packages/superdoc/dist/chunks/create-headless-toolbar-s_kl3MP8.es.js
172257
+ // ../../packages/superdoc/dist/chunks/create-headless-toolbar-BmFWtej0.es.js
172194
172258
  function parseSizeUnit(val = "0") {
172195
172259
  const length3 = val.toString() || "0";
172196
172260
  const value = Number.parseFloat(length3);
@@ -182523,8 +182587,8 @@ var CSS_DIMENSION_REGEX, DOM_SIZE_UNITS, normalizeActorId = (value) => {
182523
182587
  }
182524
182588
  };
182525
182589
  };
182526
- var init_create_headless_toolbar_s_kl3MP8_es = __esm(() => {
182527
- init_SuperConverter_BBjNvGFh_es();
182590
+ var init_create_headless_toolbar_BmFWtej0_es = __esm(() => {
182591
+ init_SuperConverter_bEQ45IUD_es();
182528
182592
  init_uuid_qzgm05fK_es();
182529
182593
  init_constants_D9qj59G2_es();
182530
182594
  init_dist_B8HfvhaK_es();
@@ -231687,7 +231751,7 @@ var init_remark_gfm_eZN6yzWQ_es = __esm(() => {
231687
231751
  init_remark_gfm_BhnWr3yf_es();
231688
231752
  });
231689
231753
 
231690
- // ../../packages/superdoc/dist/chunks/src-DeS9kJS7.es.js
231754
+ // ../../packages/superdoc/dist/chunks/src-BhZiOqOm.es.js
231691
231755
  function deleteProps(obj, propOrProps) {
231692
231756
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
231693
231757
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -244623,13 +244687,13 @@ function processDocumentForMissingRefs(node3, usedIds, fixed) {
244623
244687
  function buildCommentJsonFromText(text5) {
244624
244688
  return text5.replace(/\r\n?/g, `
244625
244689
  `).split(`
244626
- `).map((paragraphText) => ({
244690
+ `).map((paragraphText$1) => ({
244627
244691
  type: "paragraph",
244628
244692
  content: [{
244629
244693
  type: "run",
244630
244694
  content: [{
244631
244695
  type: "text",
244632
- text: paragraphText
244696
+ text: paragraphText$1
244633
244697
  }]
244634
244698
  }]
244635
244699
  }));
@@ -262717,8 +262781,8 @@ function replaceSdtTextContent(editor, target, text5) {
262717
262781
  const paragraph2 = buildEmptyBlockContent(editor, resolved.node);
262718
262782
  if (!paragraph2)
262719
262783
  return false;
262720
- const paragraphText = text5.length > 0 ? buildTextWithTabs(editor.schema, text5, undefined) : null;
262721
- const updatedParagraph = paragraph2.type.create(paragraph2.attrs ?? null, paragraphText, paragraph2.marks);
262784
+ const paragraphText$1 = text5.length > 0 ? buildTextWithTabs(editor.schema, text5, undefined) : null;
262785
+ const updatedParagraph = paragraph2.type.create(paragraph2.attrs ?? null, paragraphText$1, paragraph2.marks);
262722
262786
  tr.replaceWith(innerFrom, innerTo, updatedParagraph);
262723
262787
  dispatchTransaction$1(editor, tr);
262724
262788
  return true;
@@ -274162,7 +274226,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
274162
274226
  };
274163
274227
  const leftFloats = [];
274164
274228
  const rightFloats = [];
274165
- const columnOrigin = marginLeft + columnIndex * (currentColumns.width + currentColumns.gap);
274229
+ const columnOrigin = getColumnX(getColumnGeometry(currentColumns), columnIndex, marginLeft);
274166
274230
  const columnCenter = columnOrigin + baseWidth / 2;
274167
274231
  for (const zone of wrappingZones)
274168
274232
  if (zone.wrapMode === "left")
@@ -274234,7 +274298,7 @@ function computeTableAnchorX(anchor, columnIndex, columns, tableWidth, margins,
274234
274298
  const marginRight = Math.max(0, margins?.right ?? 0);
274235
274299
  const contentWidth = pageWidth != null ? Math.max(1, pageWidth - (marginLeft + marginRight)) : columns.width;
274236
274300
  const contentLeft = marginLeft;
274237
- const columnLeft = contentLeft + columnIndex * (columns.width + columns.gap);
274301
+ const columnLeft = getColumnX(getColumnGeometry(columns), columnIndex, contentLeft);
274238
274302
  const relativeFrom = anchor.hRelativeFrom ?? "column";
274239
274303
  let baseX;
274240
274304
  let availableWidth;
@@ -274570,560 +274634,6 @@ function computeParagraphLayoutStartY(input2) {
274570
274634
  const effectiveSpacingBefore = input2.suppressSpacingBefore ? 0 : input2.spacingBefore;
274571
274635
  return computeParagraphContentStartY(y$1, effectiveSpacingBefore, effectiveSpacingBefore === 0, trailingForCollapse);
274572
274636
  }
274573
- function calculateFirstLineIndent(block, measure) {
274574
- const wordLayout = block.attrs?.wordLayout;
274575
- if (!wordLayout?.firstLineIndentMode)
274576
- return 0;
274577
- if (!wordLayout.marker || !measure.marker)
274578
- return 0;
274579
- const markerWidthRaw = measure.marker.markerWidth ?? wordLayout.marker.markerBoxWidthPx ?? 0;
274580
- const markerWidth = Number.isFinite(markerWidthRaw) && markerWidthRaw >= 0 ? markerWidthRaw : 0;
274581
- const gutterWidthRaw = measure.marker.gutterWidth ?? 0;
274582
- return markerWidth + (Number.isFinite(gutterWidthRaw) && gutterWidthRaw >= 0 ? gutterWidthRaw : 0);
274583
- }
274584
- function layoutParagraphBlock(ctx$1, anchors) {
274585
- const { block, measure, columnWidth, ensurePage, advanceColumn, columnX, floatManager } = ctx$1;
274586
- const remeasureParagraph$1 = ctx$1.remeasureParagraph;
274587
- const frame = getParagraphAttrs(block)?.frame;
274588
- let lines = normalizeLines(measure);
274589
- const measurementWidth = lines[0]?.maxWidth;
274590
- const paraIndent = block.attrs?.indent;
274591
- const indentLeft = typeof paraIndent?.left === "number" && Number.isFinite(paraIndent.left) ? paraIndent.left : 0;
274592
- const indentRight = typeof paraIndent?.right === "number" && Number.isFinite(paraIndent.right) ? paraIndent.right : 0;
274593
- const negativeLeftIndent = indentLeft < 0 ? indentLeft : 0;
274594
- const negativeRightIndent = indentRight < 0 ? indentRight : 0;
274595
- const remeasureWidth = Math.max(1, columnWidth - indentLeft - indentRight);
274596
- let didRemeasureForColumnWidth = false;
274597
- let remeasuredMarkerInfo;
274598
- if (typeof remeasureParagraph$1 === "function" && typeof measurementWidth === "number" && measurementWidth > remeasureWidth) {
274599
- const newMeasure = remeasureParagraph$1(block, columnWidth, calculateFirstLineIndent(block, measure));
274600
- lines = normalizeLines(newMeasure);
274601
- didRemeasureForColumnWidth = true;
274602
- if (newMeasure.marker)
274603
- remeasuredMarkerInfo = newMeasure.marker;
274604
- }
274605
- let fromLine = 0;
274606
- const attrs = getParagraphAttrs(block);
274607
- const spacing = attrs?.spacing ?? {};
274608
- const spacingExplicit = attrs?.spacingExplicit;
274609
- const styleId$1 = asString2(attrs?.styleId);
274610
- const contextualSpacing = asBoolean$1(attrs?.contextualSpacing);
274611
- let spacingBefore = Math.max(0, Number(spacing.before ?? spacing.lineSpaceBefore ?? 0));
274612
- let spacingAfter = ctx$1.overrideSpacingAfter ?? Math.max(0, Number(spacing.after ?? spacing.lineSpaceAfter ?? 0));
274613
- if (isEmptyTextParagraph(block) && spacingExplicit) {
274614
- if (!spacingExplicit.before)
274615
- spacingBefore = 0;
274616
- if (!spacingExplicit.after)
274617
- spacingAfter = 0;
274618
- }
274619
- const baseSpacingBefore = spacingBefore;
274620
- let appliedSpacingBefore = spacingBefore === 0;
274621
- let lastState = null;
274622
- const previewState = ensurePage();
274623
- const rawBorderExpansion = computeBorderVerticalExpansion(attrs?.borders);
274624
- const currentBorderHash = hashBorders(attrs?.borders);
274625
- const inBorderGroup = currentBorderHash != null && currentBorderHash === previewState.lastParagraphBorderHash;
274626
- const borderExpansion = {
274627
- top: inBorderGroup ? 0 : rawBorderExpansion.top,
274628
- bottom: rawBorderExpansion.bottom
274629
- };
274630
- const paragraphAnchorBaseY = computeParagraphLayoutStartY({
274631
- cursorY: previewState.cursorY,
274632
- spacingBefore,
274633
- trailingSpacing: previewState.trailingSpacing,
274634
- suppressSpacingBefore: shouldSuppressOwnSpacing(styleId$1, contextualSpacing, previewState.lastParagraphStyleId),
274635
- rewindTrailingFromPrevious: shouldSuppressOwnSpacing(previewState.lastParagraphStyleId, previewState.lastParagraphContextualSpacing, styleId$1)
274636
- }) + borderExpansion.top - (inBorderGroup ? rawBorderExpansion.bottom : 0);
274637
- const registerAnchoredDrawingsAt = (paragraphContentStartY) => {
274638
- if (!anchors?.anchoredDrawings?.length)
274639
- return;
274640
- for (const entry of anchors.anchoredDrawings) {
274641
- if (anchors.placedAnchoredIds.has(entry.block.id))
274642
- continue;
274643
- const state = ensurePage();
274644
- const contentTop = state.topMargin;
274645
- const contentBottom = state.contentBottom;
274646
- const anchorY = resolveAnchoredGraphicY({
274647
- anchor: entry.block.anchor,
274648
- objectHeight: entry.measure.height,
274649
- contentTop,
274650
- contentBottom,
274651
- pageBottomMargin: anchors.pageMargins.bottom ?? 0,
274652
- anchorParagraphY: paragraphContentStartY,
274653
- firstLineHeight: measure.lines?.[0]?.lineHeight ?? 0
274654
- });
274655
- floatManager.registerDrawing(entry.block, entry.measure, anchorY, state.columnIndex, state.page.number);
274656
- const anchorX = entry.block.anchor ? resolveAnchoredGraphicX(entry.block.anchor, state.columnIndex, anchors.columns, entry.measure.width, {
274657
- left: anchors.pageMargins.left,
274658
- right: anchors.pageMargins.right
274659
- }, anchors.pageWidth) : columnX(state);
274660
- const pmRange = extractBlockPmRange(entry.block);
274661
- if (entry.block.kind === "image" && entry.measure.kind === "image") {
274662
- const pageContentHeight = Math.max(0, state.contentBottom - state.topMargin);
274663
- const relativeFrom = entry.block.anchor?.hRelativeFrom ?? "column";
274664
- const marginLeft = anchors.pageMargins.left ?? 0;
274665
- const marginRight = anchors.pageMargins.right ?? 0;
274666
- let maxWidth;
274667
- if (relativeFrom === "page")
274668
- maxWidth = anchors.columns.count === 1 ? anchors.pageWidth - marginLeft - marginRight : anchors.pageWidth;
274669
- else if (relativeFrom === "margin")
274670
- maxWidth = anchors.pageWidth - marginLeft - marginRight;
274671
- else
274672
- maxWidth = anchors.columns.width;
274673
- const aspectRatio = entry.measure.width > 0 && entry.measure.height > 0 ? entry.measure.width / entry.measure.height : 1;
274674
- const minWidth = 20;
274675
- const minHeight = minWidth / aspectRatio;
274676
- const metadata = {
274677
- originalWidth: entry.measure.width,
274678
- originalHeight: entry.measure.height,
274679
- maxWidth,
274680
- maxHeight: pageContentHeight,
274681
- aspectRatio,
274682
- minWidth,
274683
- minHeight
274684
- };
274685
- const fragment2 = {
274686
- kind: "image",
274687
- blockId: entry.block.id,
274688
- x: anchorX,
274689
- y: anchorY,
274690
- width: entry.measure.width,
274691
- height: entry.measure.height,
274692
- isAnchored: true,
274693
- behindDoc: entry.block.anchor?.behindDoc === true,
274694
- zIndex: getFragmentZIndex(entry.block),
274695
- metadata,
274696
- sourceAnchor: entry.block.sourceAnchor
274697
- };
274698
- if (pmRange.pmStart != null)
274699
- fragment2.pmStart = pmRange.pmStart;
274700
- if (pmRange.pmEnd != null)
274701
- fragment2.pmEnd = pmRange.pmEnd;
274702
- state.page.fragments.push(fragment2);
274703
- } else if (entry.block.kind === "drawing" && entry.measure.kind === "drawing") {
274704
- const fragment2 = {
274705
- kind: "drawing",
274706
- blockId: entry.block.id,
274707
- drawingKind: entry.block.drawingKind,
274708
- x: anchorX,
274709
- y: anchorY,
274710
- width: entry.measure.width,
274711
- height: entry.measure.height,
274712
- geometry: entry.measure.geometry,
274713
- scale: entry.measure.scale,
274714
- isAnchored: true,
274715
- behindDoc: entry.block.anchor?.behindDoc === true,
274716
- zIndex: getFragmentZIndex(entry.block),
274717
- drawingContentId: entry.block.drawingContentId,
274718
- sourceAnchor: entry.block.sourceAnchor
274719
- };
274720
- if (pmRange.pmStart != null)
274721
- fragment2.pmStart = pmRange.pmStart;
274722
- if (pmRange.pmEnd != null)
274723
- fragment2.pmEnd = pmRange.pmEnd;
274724
- state.page.fragments.push(fragment2);
274725
- }
274726
- anchors.placedAnchoredIds.add(entry.block.id);
274727
- }
274728
- };
274729
- registerAnchoredDrawingsAt(paragraphAnchorBaseY);
274730
- if (frame?.wrap === "none") {
274731
- let state = ensurePage();
274732
- if (state.cursorY >= state.contentBottom)
274733
- state = advanceColumn(state);
274734
- const fragmentWidth = lines.reduce((max$2, line) => Math.max(max$2, line.width ?? 0), 0) || columnWidth;
274735
- let x = columnX(state);
274736
- if (frame.xAlign === "right")
274737
- x += columnWidth - fragmentWidth;
274738
- else if (frame.xAlign === "center")
274739
- x += (columnWidth - fragmentWidth) / 2;
274740
- if (typeof frame.x === "number" && Number.isFinite(frame.x))
274741
- x += frame.x;
274742
- const yOffset = typeof frame.y === "number" && Number.isFinite(frame.y) ? frame.y : 0;
274743
- const fragment2 = {
274744
- kind: "para",
274745
- blockId: block.id,
274746
- fromLine: 0,
274747
- toLine: lines.length,
274748
- x,
274749
- y: state.cursorY + yOffset,
274750
- width: fragmentWidth,
274751
- sourceAnchor: block.sourceAnchor,
274752
- ...computeFragmentPmRange2(block, lines, 0, lines.length)
274753
- };
274754
- if (measure.marker || remeasuredMarkerInfo) {
274755
- fragment2.markerWidth = (remeasuredMarkerInfo ?? measure.marker)?.markerWidth ?? measure.marker?.markerWidth ?? 0;
274756
- const markerTextWidth = remeasuredMarkerInfo?.markerTextWidth ?? measure.marker?.markerTextWidth;
274757
- if (markerTextWidth != null)
274758
- fragment2.markerTextWidth = markerTextWidth;
274759
- }
274760
- state.page.fragments.push(fragment2);
274761
- state.trailingSpacing = 0;
274762
- state.lastParagraphStyleId = styleId$1;
274763
- state.lastParagraphContextualSpacing = contextualSpacing;
274764
- return;
274765
- }
274766
- let narrowestWidth = columnWidth;
274767
- let narrowestOffsetX = 0;
274768
- let didRemeasureForFloats = false;
274769
- if (typeof remeasureParagraph$1 === "function") {
274770
- const tempState = ensurePage();
274771
- let tempY = paragraphAnchorBaseY;
274772
- for (let i4 = 0;i4 < lines.length; i4++) {
274773
- const lineY = tempY;
274774
- const lineHeight = lines[i4]?.lineHeight || 0;
274775
- const { width: availableWidth, offsetX: computedOffset } = floatManager.computeAvailableWidth(lineY, lineHeight, columnWidth, tempState.columnIndex, tempState.page.number);
274776
- if (availableWidth < narrowestWidth) {
274777
- narrowestWidth = availableWidth;
274778
- narrowestOffsetX = computedOffset;
274779
- }
274780
- tempY += lineHeight;
274781
- }
274782
- const narrowestRemeasureWidth = narrowestWidth < columnWidth || narrowestOffsetX > 0 ? Math.max(1, narrowestWidth - Math.max(indentLeft, 0) - Math.max(indentRight, 0)) : Math.max(1, narrowestWidth - indentLeft - indentRight);
274783
- if (narrowestRemeasureWidth < remeasureWidth || narrowestOffsetX > 0) {
274784
- const newMeasure = remeasureParagraph$1(block, narrowestRemeasureWidth, calculateFirstLineIndent(block, measure));
274785
- lines = normalizeLines(newMeasure);
274786
- didRemeasureForFloats = true;
274787
- if (newMeasure.marker)
274788
- remeasuredMarkerInfo = newMeasure.marker;
274789
- }
274790
- }
274791
- while (fromLine < lines.length) {
274792
- let state = ensurePage();
274793
- if (state.trailingSpacing == null)
274794
- state.trailingSpacing = 0;
274795
- if (inBorderGroup && fromLine === 0)
274796
- state.cursorY -= rawBorderExpansion.bottom;
274797
- if (shouldSuppressOwnSpacing(styleId$1, contextualSpacing, state.lastParagraphStyleId))
274798
- spacingBefore = 0;
274799
- if (shouldSuppressOwnSpacing(state.lastParagraphStyleId, state.lastParagraphContextualSpacing, styleId$1)) {
274800
- const prevTrailing = asSafeNumber(state.trailingSpacing);
274801
- if (prevTrailing > 0) {
274802
- state.cursorY = rewindPreviousParagraphTrailing(state.cursorY, prevTrailing);
274803
- state.trailingSpacing = 0;
274804
- }
274805
- }
274806
- if (attrs?.keepLines === true && fromLine === 0) {
274807
- const neededSpacingBefore = collapseSpacingBefore(spacingBefore, state.trailingSpacing);
274808
- const pageContentHeight = state.contentBottom - state.topMargin;
274809
- const fullHeight = lines.reduce((sum, line) => sum + (line.lineHeight || 0), 0) + borderExpansion.top + borderExpansion.bottom;
274810
- const fitsOnBlankPage = fullHeight + baseSpacingBefore <= pageContentHeight;
274811
- const remainingHeightAfterSpacing = state.contentBottom - (state.cursorY + neededSpacingBefore);
274812
- if (fitsOnBlankPage && state.page.fragments.length > 0 && fullHeight > remainingHeightAfterSpacing) {
274813
- state = advanceColumn(state);
274814
- spacingBefore = baseSpacingBefore;
274815
- appliedSpacingBefore = spacingBefore === 0;
274816
- continue;
274817
- }
274818
- }
274819
- if (!appliedSpacingBefore && spacingBefore > 0)
274820
- while (!appliedSpacingBefore) {
274821
- state.trailingSpacing;
274822
- const neededSpacingBefore = collapseSpacingBefore(spacingBefore, state.trailingSpacing);
274823
- if (state.cursorY + neededSpacingBefore > state.contentBottom) {
274824
- if (state.cursorY <= state.topMargin) {
274825
- state.trailingSpacing = 0;
274826
- appliedSpacingBefore = true;
274827
- break;
274828
- }
274829
- state = advanceColumn(state);
274830
- if (state.trailingSpacing == null)
274831
- state.trailingSpacing = 0;
274832
- continue;
274833
- }
274834
- if (neededSpacingBefore > 0) {
274835
- state.cursorY += neededSpacingBefore;
274836
- state.maxCursorY = Math.max(state.maxCursorY, state.cursorY);
274837
- }
274838
- state.trailingSpacing = 0;
274839
- appliedSpacingBefore = true;
274840
- }
274841
- else
274842
- state.trailingSpacing = 0;
274843
- const FN_SAFETY_MARGIN_PX = 1;
274844
- const fallbackBandOverhead = (refsTotal) => refsTotal > 0 ? 22 + Math.max(0, refsTotal - 1) * 2 : 0;
274845
- const bandOverhead = (refsTotal) => {
274846
- if (refsTotal <= 0)
274847
- return 0;
274848
- const fromCtx = ctx$1.getFootnoteBandOverhead?.(refsTotal);
274849
- return (typeof fromCtx === "number" && Number.isFinite(fromCtx) && fromCtx >= 0 ? fromCtx : fallbackBandOverhead(refsTotal)) + FN_SAFETY_MARGIN_PX;
274850
- };
274851
- const rawContentBottom = state.contentBottom + state.pageFootnoteReserve;
274852
- const computeEffectiveBottom = (extraDemand, extraRefs) => {
274853
- const totalDemand = extraDemand;
274854
- const totalRefs = state.footnoteRefsThisPage + extraRefs;
274855
- const demandWithOverhead = totalDemand > 0 ? totalDemand + bandOverhead(totalRefs) : 0;
274856
- const reservedSpace = Math.max(state.pageFootnoteReserve, demandWithOverhead);
274857
- const minBodyLineHeight = lines[fromLine]?.lineHeight ?? 0;
274858
- const maxAdditional = Math.max(0, rawContentBottom - state.topMargin - minBodyLineHeight);
274859
- return rawContentBottom - Math.min(reservedSpace, maxAdditional);
274860
- };
274861
- const computeFootnoteClusterDemand = (pmStart, pmEnd) => {
274862
- const candidate = ctx$1.getFootnoteAnchorsForBlockId ? ctx$1.getFootnoteAnchorsForBlockId(block.id, pmStart, pmEnd) : [];
274863
- const committed = state.footnoteAnchorsThisPage ?? [];
274864
- if (candidate.length === 0 && committed.length === 0)
274865
- return 0;
274866
- let demand = 0;
274867
- for (const anchor of committed)
274868
- demand += anchor.fullHeight;
274869
- for (const anchor of candidate)
274870
- demand += anchor.fullHeight;
274871
- return demand;
274872
- };
274873
- const previewRange = computeFragmentPmRange2(block, lines, fromLine, fromLine + 1);
274874
- const previewRefs = ctx$1.getFootnoteRefCountForBlockId ? ctx$1.getFootnoteRefCountForBlockId(block.id, previewRange.pmStart, previewRange.pmEnd) : 0;
274875
- const computePreviewBottom = () => {
274876
- return computeEffectiveBottom(computeFootnoteClusterDemand(previewRange.pmStart ?? 0, previewRange.pmEnd ?? 0), previewRefs);
274877
- };
274878
- let effectiveBottom = computePreviewBottom();
274879
- if (state.cursorY >= effectiveBottom) {
274880
- state = advanceColumn(state);
274881
- effectiveBottom = computePreviewBottom();
274882
- }
274883
- if (effectiveBottom - state.cursorY <= 0) {
274884
- state = advanceColumn(state);
274885
- effectiveBottom = computePreviewBottom();
274886
- }
274887
- const nextLineHeight = lines[fromLine].lineHeight || 0;
274888
- const remainingHeight = effectiveBottom - state.cursorY;
274889
- if (state.page.fragments.length > 0 && remainingHeight < nextLineHeight) {
274890
- state = advanceColumn(state);
274891
- effectiveBottom = computePreviewBottom();
274892
- }
274893
- let effectiveColumnWidth = columnWidth;
274894
- let offsetX = 0;
274895
- if (didRemeasureForFloats) {
274896
- effectiveColumnWidth = narrowestWidth;
274897
- offsetX = narrowestOffsetX;
274898
- }
274899
- const borderVertical = borderExpansion.top + borderExpansion.bottom;
274900
- let toLine = fromLine;
274901
- let height = 0;
274902
- let sliceDemand = 0;
274903
- let sliceRefs = 0;
274904
- while (toLine < lines.length) {
274905
- const lineHeight = lines[toLine].lineHeight || 0;
274906
- const range = computeFragmentPmRange2(block, lines, fromLine, toLine + 1);
274907
- const orderedDemand = computeFootnoteClusterDemand(range.pmStart ?? 0, range.pmEnd ?? 0);
274908
- const nextRefs = ctx$1.getFootnoteRefCountForBlockId ? ctx$1.getFootnoteRefCountForBlockId(block.id, range.pmStart, range.pmEnd) : 0;
274909
- if (toLine === fromLine) {
274910
- height = lineHeight;
274911
- sliceDemand = orderedDemand;
274912
- sliceRefs = nextRefs;
274913
- toLine = fromLine + 1;
274914
- continue;
274915
- }
274916
- if (state.cursorY + height + lineHeight + borderVertical > computeEffectiveBottom(orderedDemand, nextRefs))
274917
- break;
274918
- height += lineHeight;
274919
- sliceDemand = orderedDemand;
274920
- sliceRefs = nextRefs;
274921
- toLine += 1;
274922
- }
274923
- const slice2 = {
274924
- toLine,
274925
- height
274926
- };
274927
- const fragmentHeight = slice2.height;
274928
- if (sliceDemand > 0 || sliceRefs > 0) {
274929
- state.footnoteDemandThisPage = sliceDemand;
274930
- state.footnoteRefsThisPage = (state.footnoteRefsThisPage ?? 0) + sliceRefs;
274931
- }
274932
- if (ctx$1.getFootnoteAnchorsForBlockId) {
274933
- const committedRange = computeFragmentPmRange2(block, lines, fromLine, toLine);
274934
- const newAnchors = ctx$1.getFootnoteAnchorsForBlockId(block.id, committedRange.pmStart, committedRange.pmEnd);
274935
- if (newAnchors.length > 0) {
274936
- if (!state.footnoteAnchorsThisPage)
274937
- state.footnoteAnchorsThisPage = [];
274938
- const seen = new Set(state.footnoteAnchorsThisPage.map((a2) => a2.refId));
274939
- for (const a2 of newAnchors)
274940
- if (!seen.has(a2.refId))
274941
- state.footnoteAnchorsThisPage.push(a2);
274942
- }
274943
- }
274944
- const floatAdjustedX = columnX(state) + offsetX;
274945
- const adjustedX = didRemeasureForFloats ? floatAdjustedX + Math.max(negativeLeftIndent, 0) : floatAdjustedX + negativeLeftIndent;
274946
- const columnRight = columnX(state) + columnWidth;
274947
- let adjustedWidth = didRemeasureForFloats ? effectiveColumnWidth : effectiveColumnWidth - negativeLeftIndent - negativeRightIndent;
274948
- if (didRemeasureForFloats)
274949
- adjustedWidth = Math.min(adjustedWidth, Math.max(1, columnRight - adjustedX));
274950
- const fragment2 = {
274951
- kind: "para",
274952
- blockId: block.id,
274953
- fromLine,
274954
- toLine: slice2.toLine,
274955
- x: adjustedX,
274956
- y: state.cursorY + borderExpansion.top,
274957
- width: adjustedWidth,
274958
- sourceAnchor: block.sourceAnchor,
274959
- ...computeFragmentPmRange2(block, lines, fromLine, slice2.toLine)
274960
- };
274961
- if (didRemeasureForColumnWidth || didRemeasureForFloats)
274962
- fragment2.lines = lines.slice(fromLine, slice2.toLine);
274963
- if ((measure.marker || remeasuredMarkerInfo) && fromLine === 0) {
274964
- fragment2.markerWidth = (remeasuredMarkerInfo ?? measure.marker)?.markerWidth ?? measure.marker?.markerWidth ?? 0;
274965
- const markerTextWidth = remeasuredMarkerInfo?.markerTextWidth ?? measure.marker?.markerTextWidth;
274966
- if (markerTextWidth != null)
274967
- fragment2.markerTextWidth = markerTextWidth;
274968
- const gutterWidth = remeasuredMarkerInfo?.gutterWidth ?? measure.marker?.gutterWidth;
274969
- if (gutterWidth != null)
274970
- fragment2.markerGutter = gutterWidth;
274971
- }
274972
- if (fromLine > 0)
274973
- fragment2.continuesFromPrev = true;
274974
- if (slice2.toLine < lines.length)
274975
- fragment2.continuesOnNext = true;
274976
- const floatAlignment = block.attrs?.floatAlignment;
274977
- if (floatAlignment && (floatAlignment === "right" || floatAlignment === "center")) {
274978
- let maxLineWidth = 0;
274979
- for (let i4 = fromLine;i4 < slice2.toLine; i4++)
274980
- if (lines[i4].width > maxLineWidth)
274981
- maxLineWidth = lines[i4].width;
274982
- if (floatAlignment === "right")
274983
- fragment2.x = columnX(state) + offsetX + (effectiveColumnWidth - maxLineWidth);
274984
- else if (floatAlignment === "center")
274985
- fragment2.x = columnX(state) + offsetX + (effectiveColumnWidth - maxLineWidth) / 2;
274986
- }
274987
- state.page.fragments.push(fragment2);
274988
- state.cursorY += borderExpansion.top + fragmentHeight + borderExpansion.bottom;
274989
- state.maxCursorY = Math.max(state.maxCursorY, state.cursorY);
274990
- lastState = state;
274991
- fromLine = slice2.toLine;
274992
- }
274993
- if (lastState) {
274994
- if (spacingAfter > 0) {
274995
- let targetState = lastState;
274996
- let appliedSpacingAfter = spacingAfter;
274997
- if (targetState.cursorY + spacingAfter > targetState.contentBottom) {
274998
- targetState = advanceColumn(targetState);
274999
- appliedSpacingAfter = 0;
275000
- } else {
275001
- targetState.cursorY += spacingAfter;
275002
- targetState.maxCursorY = Math.max(targetState.maxCursorY, targetState.cursorY);
275003
- }
275004
- targetState.trailingSpacing = appliedSpacingAfter;
275005
- } else
275006
- lastState.trailingSpacing = 0;
275007
- lastState.lastParagraphStyleId = styleId$1;
275008
- lastState.lastParagraphContextualSpacing = contextualSpacing;
275009
- lastState.lastParagraphBorderHash = currentBorderHash;
275010
- }
275011
- }
275012
- function layoutImageBlock({ block, measure, columns, ensurePage, advanceColumn, columnX }) {
275013
- if (block.anchor?.isAnchored)
275014
- return;
275015
- const marginTop = Math.max(0, block.margin?.top ?? 0);
275016
- const marginBottom = Math.max(0, block.margin?.bottom ?? 0);
275017
- const marginLeft = Math.max(0, block.margin?.left ?? 0);
275018
- const marginRight = Math.max(0, block.margin?.right ?? 0);
275019
- const maxWidth = Math.max(0, columns.width - (marginLeft + marginRight));
275020
- let width = measure.width;
275021
- let height = measure.height;
275022
- if (width > maxWidth && maxWidth > 0) {
275023
- const scale = maxWidth / width;
275024
- width = maxWidth;
275025
- height *= scale;
275026
- }
275027
- let state = ensurePage();
275028
- const pageContentHeight = Math.max(0, state.contentBottom - state.topMargin);
275029
- if (height > pageContentHeight && pageContentHeight > 0) {
275030
- const scale = pageContentHeight / height;
275031
- height = pageContentHeight;
275032
- width *= scale;
275033
- }
275034
- const requiredHeight = marginTop + height + marginBottom;
275035
- if (state.cursorY + requiredHeight > state.contentBottom && state.cursorY > state.topMargin)
275036
- state = advanceColumn(state);
275037
- const pmRange = extractBlockPmRange(block);
275038
- const aspectRatio = measure.width > 0 && measure.height > 0 ? measure.width / measure.height : 1;
275039
- const minWidth = 20;
275040
- const minHeight = minWidth / aspectRatio;
275041
- const metadata = {
275042
- originalWidth: measure.width,
275043
- originalHeight: measure.height,
275044
- maxWidth,
275045
- maxHeight: pageContentHeight,
275046
- aspectRatio,
275047
- minWidth,
275048
- minHeight
275049
- };
275050
- const fragment2 = {
275051
- kind: "image",
275052
- blockId: block.id,
275053
- x: columnX(state) + marginLeft,
275054
- y: state.cursorY + marginTop,
275055
- width,
275056
- height,
275057
- pmStart: pmRange.pmStart,
275058
- pmEnd: pmRange.pmEnd,
275059
- metadata,
275060
- sourceAnchor: block.sourceAnchor
275061
- };
275062
- state.page.fragments.push(fragment2);
275063
- state.cursorY += requiredHeight;
275064
- state.maxCursorY = Math.max(state.maxCursorY, state.cursorY);
275065
- }
275066
- function layoutDrawingBlock({ block, measure, columns, ensurePage, advanceColumn, columnX }) {
275067
- if (block.anchor?.isAnchored)
275068
- return;
275069
- const marginTop = Math.max(0, block.margin?.top ?? 0);
275070
- const marginBottom = Math.max(0, block.margin?.bottom ?? 0);
275071
- const marginLeft = Math.max(0, block.margin?.left ?? 0);
275072
- const marginRight = Math.max(0, block.margin?.right ?? 0);
275073
- const maxWidth = Math.max(0, columns.width - (marginLeft + marginRight));
275074
- let width = measure.width;
275075
- let height = measure.height;
275076
- const attrs = block.attrs;
275077
- const indentLeft = typeof attrs?.hrIndentLeft === "number" ? attrs.hrIndentLeft : 0;
275078
- const indentRight = typeof attrs?.hrIndentRight === "number" ? attrs.hrIndentRight : 0;
275079
- const maxWidthForBlock = attrs?.isFullWidth === true && maxWidth > 0 ? Math.max(1, maxWidth - indentLeft - indentRight) : maxWidth;
275080
- const rawWrap = attrs?.wrap;
275081
- const isInlineShapeGroup = block.drawingKind === "shapeGroup" && rawWrap?.type === "Inline";
275082
- const inlineParagraphAlignment = attrs?.inlineParagraphAlignment === "center" || attrs?.inlineParagraphAlignment === "right" ? attrs.inlineParagraphAlignment : undefined;
275083
- if (width > maxWidthForBlock && maxWidthForBlock > 0) {
275084
- const scale = maxWidthForBlock / width;
275085
- width = maxWidthForBlock;
275086
- height *= scale;
275087
- }
275088
- let state = ensurePage();
275089
- const pageContentHeight = Math.max(0, state.contentBottom - state.topMargin);
275090
- if (height > pageContentHeight && pageContentHeight > 0) {
275091
- const scale = pageContentHeight / height;
275092
- height = pageContentHeight;
275093
- width *= scale;
275094
- }
275095
- const requiredHeight = marginTop + height + marginBottom;
275096
- if (state.cursorY + requiredHeight > state.contentBottom && state.cursorY > state.topMargin)
275097
- state = advanceColumn(state);
275098
- const pmRange = extractBlockPmRange(block);
275099
- let x = columnX(state) + marginLeft + indentLeft;
275100
- if (isInlineShapeGroup && inlineParagraphAlignment) {
275101
- const pIndentLeft = typeof attrs?.paragraphIndentLeft === "number" ? attrs.paragraphIndentLeft : 0;
275102
- const pIndentRight = typeof attrs?.paragraphIndentRight === "number" ? attrs.paragraphIndentRight : 0;
275103
- const alignBox = Math.max(0, maxWidthForBlock - pIndentLeft - pIndentRight);
275104
- const extra = Math.max(0, alignBox - width);
275105
- x += pIndentLeft + (inlineParagraphAlignment === "center" ? extra / 2 : extra);
275106
- }
275107
- const fragment2 = {
275108
- kind: "drawing",
275109
- blockId: block.id,
275110
- drawingKind: block.drawingKind,
275111
- x,
275112
- y: state.cursorY + marginTop,
275113
- width,
275114
- height,
275115
- geometry: measure.geometry,
275116
- scale: measure.scale,
275117
- drawingContentId: block.drawingContentId,
275118
- zIndex: getFragmentZIndex(block),
275119
- pmStart: pmRange.pmStart,
275120
- pmEnd: pmRange.pmEnd,
275121
- sourceAnchor: block.sourceAnchor
275122
- };
275123
- state.page.fragments.push(fragment2);
275124
- state.cursorY += requiredHeight;
275125
- state.maxCursorY = Math.max(state.maxCursorY, state.cursorY);
275126
- }
275127
274637
  function describeCellRenderBlocks(cellMeasure, cellBlock, cellPadding) {
275128
274638
  const measuredBlocks = cellMeasure.blocks;
275129
274639
  const blockDataArray = cellBlock?.blocks;
@@ -275384,6 +274894,248 @@ function sumArray(arr) {
275384
274894
  total += v;
275385
274895
  return total;
275386
274896
  }
274897
+ function runText$1(run2) {
274898
+ if (run2.kind != null && run2.kind !== "text")
274899
+ return "";
274900
+ return "text" in run2 && typeof run2.text === "string" ? run2.text : "";
274901
+ }
274902
+ function paragraphText(block) {
274903
+ return block.runs?.map(runText$1).join("") ?? "";
274904
+ }
274905
+ function paragraphMeasureAt(blocks2, measures, index2) {
274906
+ const block = blocks2[index2];
274907
+ const measure = measures[index2];
274908
+ if (block?.kind !== "paragraph" || measure?.kind !== "paragraph")
274909
+ return null;
274910
+ return measure;
274911
+ }
274912
+ function paragraphFirstLineHeight(blocks2, measures, index2) {
274913
+ const measure = paragraphMeasureAt(blocks2, measures, index2);
274914
+ if (!measure)
274915
+ return 0;
274916
+ const firstLine = measure.lines?.[0];
274917
+ if (firstLine?.lineHeight != null && firstLine.lineHeight > 0)
274918
+ return firstLine.lineHeight;
274919
+ return measure.totalHeight ?? 0;
274920
+ }
274921
+ function isSingleLineParagraph(blocks2, measures, index2) {
274922
+ const measure = paragraphMeasureAt(blocks2, measures, index2);
274923
+ if (!measure)
274924
+ return false;
274925
+ const lineCount = measure.lines?.length ?? 0;
274926
+ if (lineCount === 1)
274927
+ return true;
274928
+ return lineCount === 0 && (measure.totalHeight ?? 0) > 0;
274929
+ }
274930
+ function isTextEmptyParagraph(blocks2, index2) {
274931
+ const block = blocks2[index2];
274932
+ if (block.kind !== "paragraph")
274933
+ return false;
274934
+ return paragraphText(block).trim().length === 0;
274935
+ }
274936
+ function findPreviousParagraphIndex(blocks2, fromIndex) {
274937
+ for (let i4 = fromIndex - 1;i4 >= 0; i4 -= 1)
274938
+ if (blocks2[i4].kind === "paragraph")
274939
+ return i4;
274940
+ return null;
274941
+ }
274942
+ function findNextParagraphIndex(blocks2, fromIndex, len3) {
274943
+ for (let i4 = fromIndex + 1;i4 < len3; i4 += 1)
274944
+ if (blocks2[i4].kind === "paragraph")
274945
+ return i4;
274946
+ return null;
274947
+ }
274948
+ function findNearestParagraphIndex$1(blocks2, len3, fromIndex) {
274949
+ return findPreviousParagraphIndex(blocks2, fromIndex) ?? findNextParagraphIndex(blocks2, fromIndex, len3);
274950
+ }
274951
+ function paragraphMeasureHeight(measures, index2) {
274952
+ const measure = measures[index2];
274953
+ if (measure?.kind !== "paragraph")
274954
+ return 0;
274955
+ return measure.totalHeight ?? 0;
274956
+ }
274957
+ function isLineScopedTblpY$1(blocks2, measures, paragraphIndex, offsetV) {
274958
+ const lineHeight = paragraphFirstLineHeight(blocks2, measures, paragraphIndex);
274959
+ if (lineHeight <= 0)
274960
+ return offsetV <= 1;
274961
+ return offsetV <= lineHeight * 1.5;
274962
+ }
274963
+ function isMultiLineParagraph(blocks2, measures, index2) {
274964
+ const measure = paragraphMeasureAt(blocks2, measures, index2);
274965
+ if (!measure)
274966
+ return false;
274967
+ return (measure.lines?.length ?? 0) > 1;
274968
+ }
274969
+ function findForwardCompactOptionLine(blocks2, measures, len3, tableIndex) {
274970
+ for (let i4 = tableIndex + 1;i4 < len3; i4 += 1) {
274971
+ if (blocks2[i4].kind !== "paragraph")
274972
+ continue;
274973
+ if (isTextEmptyParagraph(blocks2, i4))
274974
+ continue;
274975
+ if (!isSingleLineParagraph(blocks2, measures, i4))
274976
+ continue;
274977
+ const height = paragraphMeasureHeight(measures, i4);
274978
+ const lineH = paragraphFirstLineHeight(blocks2, measures, i4);
274979
+ if (height <= 0 || lineH <= 0 || height > lineH * 1.25)
274980
+ continue;
274981
+ const prevIndex = findPreviousParagraphIndex(blocks2, i4);
274982
+ if (prevIndex == null)
274983
+ continue;
274984
+ if (isMultiLineParagraph(blocks2, measures, prevIndex))
274985
+ return i4;
274986
+ if (isCompactOptionLineAfterBody(blocks2, measures, i4, prevIndex))
274987
+ return i4;
274988
+ }
274989
+ return null;
274990
+ }
274991
+ function isCompactOptionLineAfterBody(blocks2, measures, optionIndex, bodyIndex) {
274992
+ if (bodyIndex == null)
274993
+ return false;
274994
+ if (!isSingleLineParagraph(blocks2, measures, optionIndex))
274995
+ return false;
274996
+ const optionHeight = paragraphMeasureHeight(measures, optionIndex);
274997
+ const optionLine = paragraphFirstLineHeight(blocks2, measures, optionIndex);
274998
+ if (optionHeight <= 0 || optionLine <= 0 || optionHeight > optionLine * 1.25)
274999
+ return false;
275000
+ return paragraphMeasureHeight(measures, bodyIndex) > optionHeight * 1.5;
275001
+ }
275002
+ function resolutionWithLineScopedFlag(blocks2, measures, paragraphIndex, offsetV, rawOffsetV, forwardResolved = false) {
275003
+ return {
275004
+ paragraphIndex,
275005
+ offsetV,
275006
+ lineScopedOnAnchor: !forwardResolved && offsetV === rawOffsetV && isLineScopedTblpY$1(blocks2, measures, paragraphIndex, offsetV) && !isTextEmptyParagraph(blocks2, paragraphIndex)
275007
+ };
275008
+ }
275009
+ function paintOffsetThroughAnchorParagraphs(blocks2, measures, len3, tableIndex, anchorParagraphIndex, rawOffsetV) {
275010
+ let consumed = 0;
275011
+ let index2 = findNextParagraphIndex(blocks2, tableIndex, len3);
275012
+ while (index2 != null && index2 <= anchorParagraphIndex) {
275013
+ consumed += paragraphMeasureHeight(measures, index2);
275014
+ if (index2 === anchorParagraphIndex)
275015
+ break;
275016
+ index2 = findNextParagraphIndex(blocks2, index2, len3);
275017
+ }
275018
+ return Math.max(0, rawOffsetV - consumed);
275019
+ }
275020
+ function resolveForwardParagraphByTblpY(blocks2, measures, len3, tableIndex, offsetV) {
275021
+ if (offsetV <= 0)
275022
+ return null;
275023
+ let remaining = offsetV;
275024
+ let index2 = findNextParagraphIndex(blocks2, tableIndex, len3);
275025
+ while (index2 != null) {
275026
+ if (blocks2[index2].kind !== "paragraph") {
275027
+ index2 = findNextParagraphIndex(blocks2, index2, len3);
275028
+ continue;
275029
+ }
275030
+ const height = paragraphMeasureHeight(measures, index2);
275031
+ if (height <= 0) {
275032
+ index2 = findNextParagraphIndex(blocks2, index2, len3);
275033
+ continue;
275034
+ }
275035
+ const lineHeight = paragraphFirstLineHeight(blocks2, measures, index2);
275036
+ if (remaining <= height + 1)
275037
+ return {
275038
+ paragraphIndex: index2,
275039
+ offsetV: lineHeight > 0 ? Math.min(remaining, lineHeight) : remaining,
275040
+ lineScopedOnAnchor: false
275041
+ };
275042
+ remaining -= height;
275043
+ const nextIndex = findNextParagraphIndex(blocks2, index2, len3);
275044
+ if (nextIndex == null && remaining > 0)
275045
+ return {
275046
+ paragraphIndex: index2,
275047
+ offsetV: lineHeight > 0 ? Math.min(remaining, lineHeight) : remaining,
275048
+ lineScopedOnAnchor: false
275049
+ };
275050
+ index2 = nextIndex;
275051
+ }
275052
+ return null;
275053
+ }
275054
+ function walkBackTblpYAnchor(blocks2, measures, startIndex, offsetV) {
275055
+ let candidate = startIndex;
275056
+ while (offsetV > 0) {
275057
+ if (offsetV <= paragraphMeasureHeight(measures, candidate) + 1)
275058
+ break;
275059
+ const earlierIndex = findPreviousParagraphIndex(blocks2, candidate);
275060
+ if (earlierIndex == null)
275061
+ break;
275062
+ candidate = earlierIndex;
275063
+ }
275064
+ return resolutionWithLineScopedFlag(blocks2, measures, candidate, offsetV, offsetV);
275065
+ }
275066
+ function getTableIndentPx(attrs) {
275067
+ const tableIndent = attrs?.tableIndent;
275068
+ return typeof tableIndent?.width === "number" && Number.isFinite(tableIndent.width) ? tableIndent.width : 0;
275069
+ }
275070
+ function horizontalWrapMargin(wrap5) {
275071
+ return (wrap5?.distLeft ?? 0) + (wrap5?.distRight ?? 0);
275072
+ }
275073
+ function measureRoundingSlack(columnCount) {
275074
+ return Math.max(1, columnCount) * 0.5;
275075
+ }
275076
+ function isAnchoredTableFullWidth(block, measure, columnWidth) {
275077
+ if (columnWidth <= 0)
275078
+ return false;
275079
+ const totalWidth = measure.totalWidth ?? 0;
275080
+ const indent2 = getTableIndentPx(block.attrs);
275081
+ const effectiveWidth = totalWidth + horizontalWrapMargin(block.wrap) + Math.max(0, -indent2);
275082
+ const slack = measureRoundingSlack(measure.columnWidths?.length ?? 1);
275083
+ const tblWidth = resolveTableWidthAttr(block.attrs?.tableWidth);
275084
+ if (tblWidth?.type === "pct" && tblWidth.width >= 5000 * 0.99)
275085
+ return true;
275086
+ return effectiveWidth + slack >= columnWidth * ANCHORED_TABLE_FULL_WIDTH_RATIO;
275087
+ }
275088
+ function resolveFloatingTableAnchorResolution(blocks2, measures, len3, tableIndex, tableBlock, paragraphIndexById) {
275089
+ const anchorParagraphId = typeof tableBlock.attrs === "object" && tableBlock.attrs ? tableBlock.attrs.anchorParagraphId : undefined;
275090
+ if (typeof anchorParagraphId === "string") {
275091
+ const explicitIndex = paragraphIndexById.get(anchorParagraphId);
275092
+ if (typeof explicitIndex === "number") {
275093
+ const offsetV$1 = tableBlock.anchor?.offsetV ?? 0;
275094
+ if ((tableBlock.anchor?.vRelativeFrom ?? "paragraph") !== "paragraph")
275095
+ return {
275096
+ paragraphIndex: explicitIndex,
275097
+ offsetV: offsetV$1,
275098
+ lineScopedOnAnchor: false
275099
+ };
275100
+ return resolutionWithLineScopedFlag(blocks2, measures, explicitIndex, offsetV$1, offsetV$1);
275101
+ }
275102
+ }
275103
+ if ((tableBlock.anchor?.vRelativeFrom ?? "paragraph") !== "paragraph") {
275104
+ const fallback = findNearestParagraphIndex$1(blocks2, len3, tableIndex);
275105
+ if (fallback == null)
275106
+ return null;
275107
+ return {
275108
+ paragraphIndex: fallback,
275109
+ offsetV: tableBlock.anchor?.offsetV ?? 0,
275110
+ lineScopedOnAnchor: false
275111
+ };
275112
+ }
275113
+ const offsetV = tableBlock.anchor?.offsetV ?? 0;
275114
+ const prevIndex = findPreviousParagraphIndex(blocks2, tableIndex);
275115
+ const nextIndex = findNextParagraphIndex(blocks2, tableIndex, len3);
275116
+ if (nextIndex != null && isLineScopedTblpY$1(blocks2, measures, nextIndex, offsetV)) {
275117
+ if (!isTextEmptyParagraph(blocks2, nextIndex) && (prevIndex == null || isTextEmptyParagraph(blocks2, prevIndex)))
275118
+ return resolutionWithLineScopedFlag(blocks2, measures, nextIndex, offsetV, offsetV);
275119
+ if (isCompactOptionLineAfterBody(blocks2, measures, nextIndex, prevIndex))
275120
+ return resolutionWithLineScopedFlag(blocks2, measures, nextIndex, offsetV, offsetV);
275121
+ }
275122
+ if (!isLineScopedTblpY$1(blocks2, measures, prevIndex ?? nextIndex ?? tableIndex, offsetV)) {
275123
+ const forwardCompact = findForwardCompactOptionLine(blocks2, measures, len3, tableIndex);
275124
+ if (forwardCompact != null)
275125
+ return {
275126
+ paragraphIndex: forwardCompact,
275127
+ offsetV: paintOffsetThroughAnchorParagraphs(blocks2, measures, len3, tableIndex, forwardCompact, offsetV),
275128
+ lineScopedOnAnchor: false
275129
+ };
275130
+ const forward = resolveForwardParagraphByTblpY(blocks2, measures, len3, tableIndex, offsetV);
275131
+ if (forward != null)
275132
+ return forward;
275133
+ }
275134
+ const startIndex = prevIndex ?? nextIndex;
275135
+ if (startIndex == null)
275136
+ return null;
275137
+ return walkBackTblpYAnchor(blocks2, measures, startIndex, offsetV);
275138
+ }
275387
275139
  function getTableIndentWidth(attrs) {
275388
275140
  if (!attrs)
275389
275141
  return 0;
@@ -275902,13 +275654,12 @@ function layoutMonolithicTable(context) {
275902
275654
  function layoutTableBlock({ block, measure, columnWidth, ensurePage, advanceColumn, columnX }) {
275903
275655
  let treatAsInline = false;
275904
275656
  if (block.anchor?.isAnchored) {
275905
- const totalWidth = measure.totalWidth ?? 0;
275906
- treatAsInline = columnWidth > 0 && totalWidth >= columnWidth * 0.99;
275657
+ treatAsInline = isAnchoredTableFullWidth(block, measure, columnWidth);
275907
275658
  if (!treatAsInline)
275908
275659
  return;
275909
275660
  }
275910
275661
  const floatingProps = block.attrs?.tableProperties?.floatingTableProperties;
275911
- if (floatingProps && Object.keys(floatingProps).length > 0) {
275662
+ if (floatingProps && Object.keys(floatingProps).length > 0 && !treatAsInline) {
275912
275663
  layoutMonolithicTable({
275913
275664
  block,
275914
275665
  measure,
@@ -276168,6 +275919,670 @@ function createAnchoredTableFragment(block, measure, x, y$1) {
276168
275919
  applyTableFragmentPmRange(fragment2, block, measure);
276169
275920
  return fragment2;
276170
275921
  }
275922
+ function isLineScopedTblpY(firstLineHeight, offsetV) {
275923
+ if (firstLineHeight <= 0)
275924
+ return offsetV <= 1;
275925
+ return offsetV <= firstLineHeight * 1.5;
275926
+ }
275927
+ function anchorForLineScopedFormField(anchor, tableHeight, firstLineHeight, layoutOffsetV, lineScopedOnAnchor = false, wrapType = "None") {
275928
+ if (!anchor)
275929
+ return anchor;
275930
+ if ((anchor.vRelativeFrom ?? "paragraph") !== "paragraph")
275931
+ return anchor;
275932
+ if (wrapType !== "None")
275933
+ return anchor;
275934
+ if (!lineScopedOnAnchor)
275935
+ return anchor;
275936
+ const offsetV = layoutOffsetV ?? anchor.offsetV ?? 0;
275937
+ if (anchor.alignV || firstLineHeight <= 0 || tableHeight <= firstLineHeight)
275938
+ return anchor;
275939
+ if (!isLineScopedTblpY(firstLineHeight, offsetV))
275940
+ return anchor;
275941
+ return {
275942
+ ...anchor,
275943
+ vRelativeFrom: "paragraph",
275944
+ alignV: "center",
275945
+ offsetV: 0
275946
+ };
275947
+ }
275948
+ function graphicAnchorY(anchor) {
275949
+ if (!anchor)
275950
+ return;
275951
+ const alignV = anchor.alignV;
275952
+ const mappedAlignV = alignV === "top" || alignV === "center" || alignV === "bottom" ? alignV : undefined;
275953
+ return {
275954
+ vRelativeFrom: anchor.vRelativeFrom,
275955
+ alignV: mappedAlignV,
275956
+ offsetV: anchor.offsetV
275957
+ };
275958
+ }
275959
+ function graphicAnchorH(anchor) {
275960
+ const alignH = anchor.alignH;
275961
+ const mappedAlignH = alignH === "left" || alignH === "center" || alignH === "right" ? alignH : undefined;
275962
+ return {
275963
+ hRelativeFrom: anchor.hRelativeFrom,
275964
+ alignH: mappedAlignH,
275965
+ offsetH: anchor.offsetH
275966
+ };
275967
+ }
275968
+ function calculateFirstLineIndent(block, measure) {
275969
+ const wordLayout = block.attrs?.wordLayout;
275970
+ if (!wordLayout?.firstLineIndentMode)
275971
+ return 0;
275972
+ if (!wordLayout.marker || !measure.marker)
275973
+ return 0;
275974
+ const markerWidthRaw = measure.marker.markerWidth ?? wordLayout.marker.markerBoxWidthPx ?? 0;
275975
+ const markerWidth = Number.isFinite(markerWidthRaw) && markerWidthRaw >= 0 ? markerWidthRaw : 0;
275976
+ const gutterWidthRaw = measure.marker.gutterWidth ?? 0;
275977
+ return markerWidth + (Number.isFinite(gutterWidthRaw) && gutterWidthRaw >= 0 ? gutterWidthRaw : 0);
275978
+ }
275979
+ function layoutParagraphBlock(ctx$1, anchors) {
275980
+ const { block, measure, columnWidth, ensurePage, advanceColumn, columnX, floatManager } = ctx$1;
275981
+ const remeasureParagraph$1 = ctx$1.remeasureParagraph;
275982
+ const frame = getParagraphAttrs(block)?.frame;
275983
+ let lines = normalizeLines(measure);
275984
+ const measurementWidth = lines[0]?.maxWidth;
275985
+ const paraIndent = block.attrs?.indent;
275986
+ const indentLeft = typeof paraIndent?.left === "number" && Number.isFinite(paraIndent.left) ? paraIndent.left : 0;
275987
+ const indentRight = typeof paraIndent?.right === "number" && Number.isFinite(paraIndent.right) ? paraIndent.right : 0;
275988
+ const negativeLeftIndent = indentLeft < 0 ? indentLeft : 0;
275989
+ const negativeRightIndent = indentRight < 0 ? indentRight : 0;
275990
+ const remeasureWidth = Math.max(1, columnWidth - indentLeft - indentRight);
275991
+ let didRemeasureForColumnWidth = false;
275992
+ let remeasuredMarkerInfo;
275993
+ if (typeof remeasureParagraph$1 === "function" && typeof measurementWidth === "number" && measurementWidth > remeasureWidth) {
275994
+ const newMeasure = remeasureParagraph$1(block, columnWidth, calculateFirstLineIndent(block, measure));
275995
+ lines = normalizeLines(newMeasure);
275996
+ didRemeasureForColumnWidth = true;
275997
+ if (newMeasure.marker)
275998
+ remeasuredMarkerInfo = newMeasure.marker;
275999
+ }
276000
+ let fromLine = 0;
276001
+ const attrs = getParagraphAttrs(block);
276002
+ const spacing = attrs?.spacing ?? {};
276003
+ const spacingExplicit = attrs?.spacingExplicit;
276004
+ const styleId$1 = asString2(attrs?.styleId);
276005
+ const contextualSpacing = asBoolean$1(attrs?.contextualSpacing);
276006
+ let spacingBefore = Math.max(0, Number(spacing.before ?? spacing.lineSpaceBefore ?? 0));
276007
+ let spacingAfter = ctx$1.overrideSpacingAfter ?? Math.max(0, Number(spacing.after ?? spacing.lineSpaceAfter ?? 0));
276008
+ const emptyTextParagraph = isEmptyTextParagraph(block);
276009
+ if (emptyTextParagraph && spacingExplicit) {
276010
+ if (!spacingExplicit.before)
276011
+ spacingBefore = 0;
276012
+ if (!spacingExplicit.after)
276013
+ spacingAfter = 0;
276014
+ }
276015
+ const baseSpacingBefore = spacingBefore;
276016
+ let appliedSpacingBefore = spacingBefore === 0;
276017
+ let lastState = null;
276018
+ const previewState = ensurePage();
276019
+ const rawBorderExpansion = computeBorderVerticalExpansion(attrs?.borders);
276020
+ const currentBorderHash = hashBorders(attrs?.borders);
276021
+ const inBorderGroup = currentBorderHash != null && currentBorderHash === previewState.lastParagraphBorderHash;
276022
+ const borderExpansion = {
276023
+ top: inBorderGroup ? 0 : rawBorderExpansion.top,
276024
+ bottom: rawBorderExpansion.bottom
276025
+ };
276026
+ const paragraphAnchorBaseY = computeParagraphLayoutStartY({
276027
+ cursorY: previewState.cursorY,
276028
+ spacingBefore,
276029
+ trailingSpacing: previewState.trailingSpacing,
276030
+ suppressSpacingBefore: shouldSuppressOwnSpacing(styleId$1, contextualSpacing, previewState.lastParagraphStyleId),
276031
+ rewindTrailingFromPrevious: shouldSuppressOwnSpacing(previewState.lastParagraphStyleId, previewState.lastParagraphContextualSpacing, styleId$1)
276032
+ }) + borderExpansion.top - (inBorderGroup ? rawBorderExpansion.bottom : 0);
276033
+ let paragraphContentEndY = paragraphAnchorBaseY;
276034
+ const registerAnchoredDrawingsAt = (paragraphContentStartY) => {
276035
+ if (!anchors?.anchoredDrawings?.length)
276036
+ return;
276037
+ for (const entry of anchors.anchoredDrawings) {
276038
+ if (anchors.placedAnchoredIds.has(entry.block.id))
276039
+ continue;
276040
+ const state = ensurePage();
276041
+ const contentTop = state.topMargin;
276042
+ const contentBottom = state.contentBottom;
276043
+ const anchorY = resolveAnchoredGraphicY({
276044
+ anchor: entry.block.anchor,
276045
+ objectHeight: entry.measure.height,
276046
+ contentTop,
276047
+ contentBottom,
276048
+ pageBottomMargin: anchors.pageMargins.bottom ?? 0,
276049
+ anchorParagraphY: paragraphContentStartY,
276050
+ firstLineHeight: measure.lines?.[0]?.lineHeight ?? 0
276051
+ });
276052
+ floatManager.registerDrawing(entry.block, entry.measure, anchorY, state.columnIndex, state.page.number);
276053
+ const anchorX = entry.block.anchor ? resolveAnchoredGraphicX(entry.block.anchor, state.columnIndex, anchors.columns, entry.measure.width, {
276054
+ left: anchors.pageMargins.left,
276055
+ right: anchors.pageMargins.right
276056
+ }, anchors.pageWidth) : columnX(state);
276057
+ const pmRange = extractBlockPmRange(entry.block);
276058
+ if (entry.block.kind === "image" && entry.measure.kind === "image") {
276059
+ const pageContentHeight = Math.max(0, state.contentBottom - state.topMargin);
276060
+ const relativeFrom = entry.block.anchor?.hRelativeFrom ?? "column";
276061
+ const marginLeft = anchors.pageMargins.left ?? 0;
276062
+ const marginRight = anchors.pageMargins.right ?? 0;
276063
+ let maxWidth;
276064
+ if (relativeFrom === "page")
276065
+ maxWidth = anchors.columns.count === 1 ? anchors.pageWidth - marginLeft - marginRight : anchors.pageWidth;
276066
+ else if (relativeFrom === "margin")
276067
+ maxWidth = anchors.pageWidth - marginLeft - marginRight;
276068
+ else
276069
+ maxWidth = anchors.columns.width;
276070
+ const aspectRatio = entry.measure.width > 0 && entry.measure.height > 0 ? entry.measure.width / entry.measure.height : 1;
276071
+ const minWidth = 20;
276072
+ const minHeight = minWidth / aspectRatio;
276073
+ const metadata = {
276074
+ originalWidth: entry.measure.width,
276075
+ originalHeight: entry.measure.height,
276076
+ maxWidth,
276077
+ maxHeight: pageContentHeight,
276078
+ aspectRatio,
276079
+ minWidth,
276080
+ minHeight
276081
+ };
276082
+ const fragment2 = {
276083
+ kind: "image",
276084
+ blockId: entry.block.id,
276085
+ x: anchorX,
276086
+ y: anchorY,
276087
+ width: entry.measure.width,
276088
+ height: entry.measure.height,
276089
+ isAnchored: true,
276090
+ behindDoc: entry.block.anchor?.behindDoc === true,
276091
+ zIndex: getFragmentZIndex(entry.block),
276092
+ metadata,
276093
+ sourceAnchor: entry.block.sourceAnchor
276094
+ };
276095
+ if (pmRange.pmStart != null)
276096
+ fragment2.pmStart = pmRange.pmStart;
276097
+ if (pmRange.pmEnd != null)
276098
+ fragment2.pmEnd = pmRange.pmEnd;
276099
+ state.page.fragments.push(fragment2);
276100
+ } else if (entry.block.kind === "drawing" && entry.measure.kind === "drawing") {
276101
+ const fragment2 = {
276102
+ kind: "drawing",
276103
+ blockId: entry.block.id,
276104
+ drawingKind: entry.block.drawingKind,
276105
+ x: anchorX,
276106
+ y: anchorY,
276107
+ width: entry.measure.width,
276108
+ height: entry.measure.height,
276109
+ geometry: entry.measure.geometry,
276110
+ scale: entry.measure.scale,
276111
+ isAnchored: true,
276112
+ behindDoc: entry.block.anchor?.behindDoc === true,
276113
+ zIndex: getFragmentZIndex(entry.block),
276114
+ drawingContentId: entry.block.drawingContentId,
276115
+ sourceAnchor: entry.block.sourceAnchor
276116
+ };
276117
+ if (pmRange.pmStart != null)
276118
+ fragment2.pmStart = pmRange.pmStart;
276119
+ if (pmRange.pmEnd != null)
276120
+ fragment2.pmEnd = pmRange.pmEnd;
276121
+ state.page.fragments.push(fragment2);
276122
+ }
276123
+ anchors.placedAnchoredIds.add(entry.block.id);
276124
+ }
276125
+ };
276126
+ registerAnchoredDrawingsAt(paragraphAnchorBaseY);
276127
+ const registerAnchoredTablesAt = (paragraphContentStartY, entries2) => {
276128
+ if (!entries2.length)
276129
+ return;
276130
+ const columnWidthForTable = anchors.columnWidth;
276131
+ let nextStackY = paragraphContentStartY;
276132
+ for (const entry of entries2) {
276133
+ if (anchors.placedAnchoredIds.has(entry.block.id))
276134
+ continue;
276135
+ const totalWidth = entry.measure.totalWidth ?? 0;
276136
+ if (isAnchoredTableFullWidth(entry.block, entry.measure, columnWidthForTable))
276137
+ continue;
276138
+ const state = ensurePage();
276139
+ const contentTop = state.topMargin;
276140
+ const contentBottom = state.contentBottom;
276141
+ const layoutOffsetV = entry.layoutOffsetV;
276142
+ const firstLineHeight = measure.lines?.[0]?.lineHeight ?? 0;
276143
+ const wrapType = entry.block.wrap?.type ?? "None";
276144
+ const anchorY = resolveAnchoredGraphicY({
276145
+ anchor: graphicAnchorY(anchorForLineScopedFormField(layoutOffsetV != null && entry.block.anchor ? {
276146
+ ...entry.block.anchor,
276147
+ offsetV: layoutOffsetV
276148
+ } : entry.block.anchor, entry.measure.totalHeight ?? 0, firstLineHeight, layoutOffsetV, entry.lineScopedOnAnchor === true, wrapType)),
276149
+ objectHeight: entry.measure.totalHeight ?? 0,
276150
+ contentTop,
276151
+ contentBottom,
276152
+ pageBottomMargin: anchors.pageMargins.bottom ?? 0,
276153
+ anchorParagraphY: nextStackY,
276154
+ firstLineHeight: measure.lines?.[0]?.lineHeight ?? 0
276155
+ });
276156
+ floatManager.registerTable(entry.block, entry.measure, anchorY, state.columnIndex, state.page.number);
276157
+ const anchorX = entry.block.anchor ? resolveAnchoredGraphicX(graphicAnchorH(entry.block.anchor), state.columnIndex, anchors.columns, totalWidth, {
276158
+ left: anchors.pageMargins.left,
276159
+ right: anchors.pageMargins.right
276160
+ }, anchors.pageWidth) : columnX(state);
276161
+ state.page.fragments.push(createAnchoredTableFragment(entry.block, entry.measure, anchorX, anchorY));
276162
+ anchors.placedAnchoredIds.add(entry.block.id);
276163
+ if (wrapType !== "None") {
276164
+ const bottom$1 = anchorY + (entry.measure.totalHeight ?? 0);
276165
+ const distBottom = entry.block.wrap?.distBottom ?? 0;
276166
+ nextStackY = Math.max(nextStackY, bottom$1 + distBottom);
276167
+ }
276168
+ }
276169
+ };
276170
+ const anchoredTablesForPara = anchors?.anchoredTables ?? [];
276171
+ const totalLineHeight = lines.reduce((sum, line) => sum + (line.lineHeight ?? 0), 0);
276172
+ const remainingHeightOnStartPage = previewState.contentBottom - paragraphAnchorBaseY;
276173
+ const paragraphWillSpanPages = lines.length > 1 && totalLineHeight > remainingHeightOnStartPage;
276174
+ const shouldPreLayoutSquareTable = (entry) => entry.lineScopedOnAnchor === true && !paragraphWillSpanPages;
276175
+ registerAnchoredTablesAt(paragraphAnchorBaseY, anchoredTablesForPara.filter((entry) => {
276176
+ if ((entry.block.wrap?.type ?? "None") === "None")
276177
+ return true;
276178
+ return shouldPreLayoutSquareTable(entry);
276179
+ }));
276180
+ if (frame?.wrap === "none") {
276181
+ let state = ensurePage();
276182
+ if (state.cursorY >= state.contentBottom)
276183
+ state = advanceColumn(state);
276184
+ const fragmentWidth = lines.reduce((max$2, line) => Math.max(max$2, line.width ?? 0), 0) || columnWidth;
276185
+ let x = columnX(state);
276186
+ if (frame.xAlign === "right")
276187
+ x += columnWidth - fragmentWidth;
276188
+ else if (frame.xAlign === "center")
276189
+ x += (columnWidth - fragmentWidth) / 2;
276190
+ if (typeof frame.x === "number" && Number.isFinite(frame.x))
276191
+ x += frame.x;
276192
+ const yOffset = typeof frame.y === "number" && Number.isFinite(frame.y) ? frame.y : 0;
276193
+ const fragment2 = {
276194
+ kind: "para",
276195
+ blockId: block.id,
276196
+ fromLine: 0,
276197
+ toLine: lines.length,
276198
+ x,
276199
+ y: state.cursorY + yOffset,
276200
+ width: fragmentWidth,
276201
+ sourceAnchor: block.sourceAnchor,
276202
+ ...computeFragmentPmRange2(block, lines, 0, lines.length)
276203
+ };
276204
+ if (measure.marker || remeasuredMarkerInfo) {
276205
+ fragment2.markerWidth = (remeasuredMarkerInfo ?? measure.marker)?.markerWidth ?? measure.marker?.markerWidth ?? 0;
276206
+ const markerTextWidth = remeasuredMarkerInfo?.markerTextWidth ?? measure.marker?.markerTextWidth;
276207
+ if (markerTextWidth != null)
276208
+ fragment2.markerTextWidth = markerTextWidth;
276209
+ }
276210
+ state.page.fragments.push(fragment2);
276211
+ state.trailingSpacing = 0;
276212
+ state.lastParagraphStyleId = styleId$1;
276213
+ state.lastParagraphContextualSpacing = contextualSpacing;
276214
+ return;
276215
+ }
276216
+ let narrowestWidth = columnWidth;
276217
+ let narrowestOffsetX = 0;
276218
+ let didRemeasureForFloats = false;
276219
+ if (typeof remeasureParagraph$1 === "function") {
276220
+ const tempState = ensurePage();
276221
+ let tempY = paragraphAnchorBaseY;
276222
+ for (let i4 = 0;i4 < lines.length; i4++) {
276223
+ const lineY = tempY;
276224
+ const lineHeight = lines[i4]?.lineHeight || 0;
276225
+ const { width: availableWidth, offsetX: computedOffset } = floatManager.computeAvailableWidth(lineY, lineHeight, columnWidth, tempState.columnIndex, tempState.page.number);
276226
+ if (availableWidth < narrowestWidth) {
276227
+ narrowestWidth = availableWidth;
276228
+ narrowestOffsetX = computedOffset;
276229
+ }
276230
+ tempY += lineHeight;
276231
+ }
276232
+ const narrowestRemeasureWidth = narrowestWidth < columnWidth || narrowestOffsetX > 0 ? Math.max(1, narrowestWidth - Math.max(indentLeft, 0) - Math.max(indentRight, 0)) : Math.max(1, narrowestWidth - indentLeft - indentRight);
276233
+ if (narrowestRemeasureWidth < remeasureWidth || narrowestOffsetX > 0) {
276234
+ const newMeasure = remeasureParagraph$1(block, narrowestRemeasureWidth, calculateFirstLineIndent(block, measure));
276235
+ lines = normalizeLines(newMeasure);
276236
+ didRemeasureForFloats = true;
276237
+ if (newMeasure.marker)
276238
+ remeasuredMarkerInfo = newMeasure.marker;
276239
+ }
276240
+ }
276241
+ while (fromLine < lines.length) {
276242
+ let state = ensurePage();
276243
+ if (state.trailingSpacing == null)
276244
+ state.trailingSpacing = 0;
276245
+ if (inBorderGroup && fromLine === 0)
276246
+ state.cursorY -= rawBorderExpansion.bottom;
276247
+ if (shouldSuppressOwnSpacing(styleId$1, contextualSpacing, state.lastParagraphStyleId))
276248
+ spacingBefore = 0;
276249
+ if (shouldSuppressOwnSpacing(state.lastParagraphStyleId, state.lastParagraphContextualSpacing, styleId$1)) {
276250
+ const prevTrailing = asSafeNumber(state.trailingSpacing);
276251
+ if (prevTrailing > 0) {
276252
+ state.cursorY = rewindPreviousParagraphTrailing(state.cursorY, prevTrailing);
276253
+ state.trailingSpacing = 0;
276254
+ }
276255
+ }
276256
+ if (attrs?.keepLines === true && fromLine === 0) {
276257
+ const neededSpacingBefore = collapseSpacingBefore(spacingBefore, state.trailingSpacing);
276258
+ const pageContentHeight = state.contentBottom - state.topMargin;
276259
+ const fullHeight = lines.reduce((sum, line) => sum + (line.lineHeight || 0), 0) + borderExpansion.top + borderExpansion.bottom;
276260
+ const fitsOnBlankPage = fullHeight + baseSpacingBefore <= pageContentHeight;
276261
+ const remainingHeightAfterSpacing = state.contentBottom - (state.cursorY + neededSpacingBefore);
276262
+ if (fitsOnBlankPage && state.page.fragments.length > 0 && fullHeight > remainingHeightAfterSpacing) {
276263
+ state = advanceColumn(state);
276264
+ spacingBefore = baseSpacingBefore;
276265
+ appliedSpacingBefore = spacingBefore === 0;
276266
+ continue;
276267
+ }
276268
+ }
276269
+ if (!appliedSpacingBefore && spacingBefore > 0)
276270
+ while (!appliedSpacingBefore) {
276271
+ state.trailingSpacing;
276272
+ const neededSpacingBefore = collapseSpacingBefore(spacingBefore, state.trailingSpacing);
276273
+ if (state.cursorY + neededSpacingBefore > state.contentBottom) {
276274
+ if (state.cursorY <= state.topMargin) {
276275
+ state.trailingSpacing = 0;
276276
+ appliedSpacingBefore = true;
276277
+ break;
276278
+ }
276279
+ state = advanceColumn(state);
276280
+ if (state.trailingSpacing == null)
276281
+ state.trailingSpacing = 0;
276282
+ continue;
276283
+ }
276284
+ if (neededSpacingBefore > 0) {
276285
+ state.cursorY += neededSpacingBefore;
276286
+ state.maxCursorY = Math.max(state.maxCursorY, state.cursorY);
276287
+ }
276288
+ state.trailingSpacing = 0;
276289
+ appliedSpacingBefore = true;
276290
+ }
276291
+ else
276292
+ state.trailingSpacing = 0;
276293
+ const FN_SAFETY_MARGIN_PX = 1;
276294
+ const fallbackBandOverhead = (refsTotal) => refsTotal > 0 ? 22 + Math.max(0, refsTotal - 1) * 2 : 0;
276295
+ const bandOverhead = (refsTotal) => {
276296
+ if (refsTotal <= 0)
276297
+ return 0;
276298
+ const fromCtx = ctx$1.getFootnoteBandOverhead?.(refsTotal);
276299
+ return (typeof fromCtx === "number" && Number.isFinite(fromCtx) && fromCtx >= 0 ? fromCtx : fallbackBandOverhead(refsTotal)) + FN_SAFETY_MARGIN_PX;
276300
+ };
276301
+ const rawContentBottom = state.contentBottom + state.pageFootnoteReserve;
276302
+ const computeEffectiveBottom = (extraDemand, extraRefs) => {
276303
+ const totalDemand = extraDemand;
276304
+ const totalRefs = state.footnoteRefsThisPage + extraRefs;
276305
+ const demandWithOverhead = totalDemand > 0 ? totalDemand + bandOverhead(totalRefs) : 0;
276306
+ const reservedSpace = Math.max(state.pageFootnoteReserve, demandWithOverhead);
276307
+ const minBodyLineHeight = lines[fromLine]?.lineHeight ?? 0;
276308
+ const maxAdditional = Math.max(0, rawContentBottom - state.topMargin - minBodyLineHeight);
276309
+ return rawContentBottom - Math.min(reservedSpace, maxAdditional);
276310
+ };
276311
+ const computeFootnoteClusterDemand = (pmStart, pmEnd) => {
276312
+ const candidate = ctx$1.getFootnoteAnchorsForBlockId ? ctx$1.getFootnoteAnchorsForBlockId(block.id, pmStart, pmEnd) : [];
276313
+ const committed = state.footnoteAnchorsThisPage ?? [];
276314
+ if (candidate.length === 0 && committed.length === 0)
276315
+ return 0;
276316
+ let demand = 0;
276317
+ for (const anchor of committed)
276318
+ demand += anchor.fullHeight;
276319
+ for (const anchor of candidate)
276320
+ demand += anchor.fullHeight;
276321
+ return demand;
276322
+ };
276323
+ const previewRange = computeFragmentPmRange2(block, lines, fromLine, fromLine + 1);
276324
+ const previewRefs = ctx$1.getFootnoteRefCountForBlockId ? ctx$1.getFootnoteRefCountForBlockId(block.id, previewRange.pmStart, previewRange.pmEnd) : 0;
276325
+ const computePreviewBottom = () => {
276326
+ return computeEffectiveBottom(computeFootnoteClusterDemand(previewRange.pmStart ?? 0, previewRange.pmEnd ?? 0), previewRefs);
276327
+ };
276328
+ let effectiveBottom = computePreviewBottom();
276329
+ if (state.cursorY >= effectiveBottom) {
276330
+ state = advanceColumn(state);
276331
+ effectiveBottom = computePreviewBottom();
276332
+ }
276333
+ if (effectiveBottom - state.cursorY <= 0) {
276334
+ state = advanceColumn(state);
276335
+ effectiveBottom = computePreviewBottom();
276336
+ }
276337
+ const nextLineHeight = lines[fromLine].lineHeight || 0;
276338
+ const remainingHeight = effectiveBottom - state.cursorY;
276339
+ if (state.page.fragments.length > 0 && remainingHeight < nextLineHeight) {
276340
+ state = advanceColumn(state);
276341
+ effectiveBottom = computePreviewBottom();
276342
+ }
276343
+ let effectiveColumnWidth = columnWidth;
276344
+ let offsetX = 0;
276345
+ if (didRemeasureForFloats) {
276346
+ effectiveColumnWidth = narrowestWidth;
276347
+ offsetX = narrowestOffsetX;
276348
+ }
276349
+ const borderVertical = borderExpansion.top + borderExpansion.bottom;
276350
+ let toLine = fromLine;
276351
+ let height = 0;
276352
+ let sliceDemand = 0;
276353
+ let sliceRefs = 0;
276354
+ while (toLine < lines.length) {
276355
+ const lineHeight = lines[toLine].lineHeight || 0;
276356
+ const range = computeFragmentPmRange2(block, lines, fromLine, toLine + 1);
276357
+ const orderedDemand = computeFootnoteClusterDemand(range.pmStart ?? 0, range.pmEnd ?? 0);
276358
+ const nextRefs = ctx$1.getFootnoteRefCountForBlockId ? ctx$1.getFootnoteRefCountForBlockId(block.id, range.pmStart, range.pmEnd) : 0;
276359
+ if (toLine === fromLine) {
276360
+ height = lineHeight;
276361
+ sliceDemand = orderedDemand;
276362
+ sliceRefs = nextRefs;
276363
+ toLine = fromLine + 1;
276364
+ continue;
276365
+ }
276366
+ if (state.cursorY + height + lineHeight + borderVertical > computeEffectiveBottom(orderedDemand, nextRefs))
276367
+ break;
276368
+ height += lineHeight;
276369
+ sliceDemand = orderedDemand;
276370
+ sliceRefs = nextRefs;
276371
+ toLine += 1;
276372
+ }
276373
+ const slice2 = {
276374
+ toLine,
276375
+ height
276376
+ };
276377
+ const fragmentHeight = slice2.height;
276378
+ if (sliceDemand > 0 || sliceRefs > 0) {
276379
+ state.footnoteDemandThisPage = sliceDemand;
276380
+ state.footnoteRefsThisPage = (state.footnoteRefsThisPage ?? 0) + sliceRefs;
276381
+ }
276382
+ if (ctx$1.getFootnoteAnchorsForBlockId) {
276383
+ const committedRange = computeFragmentPmRange2(block, lines, fromLine, toLine);
276384
+ const newAnchors = ctx$1.getFootnoteAnchorsForBlockId(block.id, committedRange.pmStart, committedRange.pmEnd);
276385
+ if (newAnchors.length > 0) {
276386
+ if (!state.footnoteAnchorsThisPage)
276387
+ state.footnoteAnchorsThisPage = [];
276388
+ const seen = new Set(state.footnoteAnchorsThisPage.map((a2) => a2.refId));
276389
+ for (const a2 of newAnchors)
276390
+ if (!seen.has(a2.refId))
276391
+ state.footnoteAnchorsThisPage.push(a2);
276392
+ }
276393
+ }
276394
+ const floatAdjustedX = columnX(state) + offsetX;
276395
+ const adjustedX = didRemeasureForFloats ? floatAdjustedX + Math.max(negativeLeftIndent, 0) : floatAdjustedX + negativeLeftIndent;
276396
+ const columnRight = columnX(state) + columnWidth;
276397
+ let adjustedWidth = didRemeasureForFloats ? effectiveColumnWidth : effectiveColumnWidth - negativeLeftIndent - negativeRightIndent;
276398
+ if (didRemeasureForFloats)
276399
+ adjustedWidth = Math.min(adjustedWidth, Math.max(1, columnRight - adjustedX));
276400
+ const fragment2 = {
276401
+ kind: "para",
276402
+ blockId: block.id,
276403
+ fromLine,
276404
+ toLine: slice2.toLine,
276405
+ x: adjustedX,
276406
+ y: state.cursorY + borderExpansion.top,
276407
+ width: adjustedWidth,
276408
+ sourceAnchor: block.sourceAnchor,
276409
+ ...computeFragmentPmRange2(block, lines, fromLine, slice2.toLine)
276410
+ };
276411
+ if (didRemeasureForColumnWidth || didRemeasureForFloats)
276412
+ fragment2.lines = lines.slice(fromLine, slice2.toLine);
276413
+ if ((measure.marker || remeasuredMarkerInfo) && fromLine === 0) {
276414
+ fragment2.markerWidth = (remeasuredMarkerInfo ?? measure.marker)?.markerWidth ?? measure.marker?.markerWidth ?? 0;
276415
+ const markerTextWidth = remeasuredMarkerInfo?.markerTextWidth ?? measure.marker?.markerTextWidth;
276416
+ if (markerTextWidth != null)
276417
+ fragment2.markerTextWidth = markerTextWidth;
276418
+ const gutterWidth = remeasuredMarkerInfo?.gutterWidth ?? measure.marker?.gutterWidth;
276419
+ if (gutterWidth != null)
276420
+ fragment2.markerGutter = gutterWidth;
276421
+ }
276422
+ if (fromLine > 0)
276423
+ fragment2.continuesFromPrev = true;
276424
+ if (slice2.toLine < lines.length)
276425
+ fragment2.continuesOnNext = true;
276426
+ const floatAlignment = block.attrs?.floatAlignment;
276427
+ if (floatAlignment && (floatAlignment === "right" || floatAlignment === "center")) {
276428
+ let maxLineWidth = 0;
276429
+ for (let i4 = fromLine;i4 < slice2.toLine; i4++)
276430
+ if (lines[i4].width > maxLineWidth)
276431
+ maxLineWidth = lines[i4].width;
276432
+ if (floatAlignment === "right")
276433
+ fragment2.x = columnX(state) + offsetX + (effectiveColumnWidth - maxLineWidth);
276434
+ else if (floatAlignment === "center")
276435
+ fragment2.x = columnX(state) + offsetX + (effectiveColumnWidth - maxLineWidth) / 2;
276436
+ }
276437
+ state.page.fragments.push(fragment2);
276438
+ state.cursorY += borderExpansion.top + fragmentHeight + borderExpansion.bottom;
276439
+ state.maxCursorY = Math.max(state.maxCursorY, state.cursorY);
276440
+ lastState = state;
276441
+ paragraphContentEndY = state.cursorY;
276442
+ fromLine = slice2.toLine;
276443
+ }
276444
+ if (lastState) {
276445
+ if (spacingAfter > 0) {
276446
+ let targetState = lastState;
276447
+ let appliedSpacingAfter = spacingAfter;
276448
+ if (targetState.cursorY + spacingAfter > targetState.contentBottom) {
276449
+ targetState = advanceColumn(targetState);
276450
+ appliedSpacingAfter = 0;
276451
+ } else {
276452
+ targetState.cursorY += spacingAfter;
276453
+ targetState.maxCursorY = Math.max(targetState.maxCursorY, targetState.cursorY);
276454
+ }
276455
+ targetState.trailingSpacing = appliedSpacingAfter;
276456
+ } else
276457
+ lastState.trailingSpacing = 0;
276458
+ lastState.lastParagraphStyleId = styleId$1;
276459
+ lastState.lastParagraphContextualSpacing = contextualSpacing;
276460
+ lastState.lastParagraphBorderHash = currentBorderHash;
276461
+ }
276462
+ const postLayoutAnchoredTables = anchoredTablesForPara.filter((entry) => {
276463
+ return (entry.block.wrap?.type ?? "None") !== "None" && !shouldPreLayoutSquareTable(entry);
276464
+ });
276465
+ if (postLayoutAnchoredTables.length > 0)
276466
+ registerAnchoredTablesAt(emptyTextParagraph && !paragraphWillSpanPages && postLayoutAnchoredTables.some((entry) => {
276467
+ const offsetV = entry.layoutOffsetV ?? entry.block.anchor?.offsetV ?? 0;
276468
+ return entry.lineScopedOnAnchor === false && offsetV > 0;
276469
+ }) ? paragraphAnchorBaseY : paragraphContentEndY, postLayoutAnchoredTables);
276470
+ }
276471
+ function layoutImageBlock({ block, measure, columns, ensurePage, advanceColumn, columnX }) {
276472
+ if (block.anchor?.isAnchored)
276473
+ return;
276474
+ const marginTop = Math.max(0, block.margin?.top ?? 0);
276475
+ const marginBottom = Math.max(0, block.margin?.bottom ?? 0);
276476
+ const marginLeft = Math.max(0, block.margin?.left ?? 0);
276477
+ const marginRight = Math.max(0, block.margin?.right ?? 0);
276478
+ const maxWidth = Math.max(0, columns.width - (marginLeft + marginRight));
276479
+ let width = measure.width;
276480
+ let height = measure.height;
276481
+ if (width > maxWidth && maxWidth > 0) {
276482
+ const scale = maxWidth / width;
276483
+ width = maxWidth;
276484
+ height *= scale;
276485
+ }
276486
+ let state = ensurePage();
276487
+ const pageContentHeight = Math.max(0, state.contentBottom - state.topMargin);
276488
+ if (height > pageContentHeight && pageContentHeight > 0) {
276489
+ const scale = pageContentHeight / height;
276490
+ height = pageContentHeight;
276491
+ width *= scale;
276492
+ }
276493
+ const requiredHeight = marginTop + height + marginBottom;
276494
+ if (state.cursorY + requiredHeight > state.contentBottom && state.cursorY > state.topMargin)
276495
+ state = advanceColumn(state);
276496
+ const pmRange = extractBlockPmRange(block);
276497
+ const aspectRatio = measure.width > 0 && measure.height > 0 ? measure.width / measure.height : 1;
276498
+ const minWidth = 20;
276499
+ const minHeight = minWidth / aspectRatio;
276500
+ const metadata = {
276501
+ originalWidth: measure.width,
276502
+ originalHeight: measure.height,
276503
+ maxWidth,
276504
+ maxHeight: pageContentHeight,
276505
+ aspectRatio,
276506
+ minWidth,
276507
+ minHeight
276508
+ };
276509
+ const fragment2 = {
276510
+ kind: "image",
276511
+ blockId: block.id,
276512
+ x: columnX(state) + marginLeft,
276513
+ y: state.cursorY + marginTop,
276514
+ width,
276515
+ height,
276516
+ pmStart: pmRange.pmStart,
276517
+ pmEnd: pmRange.pmEnd,
276518
+ metadata,
276519
+ sourceAnchor: block.sourceAnchor
276520
+ };
276521
+ state.page.fragments.push(fragment2);
276522
+ state.cursorY += requiredHeight;
276523
+ state.maxCursorY = Math.max(state.maxCursorY, state.cursorY);
276524
+ }
276525
+ function layoutDrawingBlock({ block, measure, columns, ensurePage, advanceColumn, columnX }) {
276526
+ if (block.anchor?.isAnchored)
276527
+ return;
276528
+ const marginTop = Math.max(0, block.margin?.top ?? 0);
276529
+ const marginBottom = Math.max(0, block.margin?.bottom ?? 0);
276530
+ const marginLeft = Math.max(0, block.margin?.left ?? 0);
276531
+ const marginRight = Math.max(0, block.margin?.right ?? 0);
276532
+ const maxWidth = Math.max(0, columns.width - (marginLeft + marginRight));
276533
+ let width = measure.width;
276534
+ let height = measure.height;
276535
+ const attrs = block.attrs;
276536
+ const indentLeft = typeof attrs?.hrIndentLeft === "number" ? attrs.hrIndentLeft : 0;
276537
+ const indentRight = typeof attrs?.hrIndentRight === "number" ? attrs.hrIndentRight : 0;
276538
+ const maxWidthForBlock = attrs?.isFullWidth === true && maxWidth > 0 ? Math.max(1, maxWidth - indentLeft - indentRight) : maxWidth;
276539
+ const rawWrap = attrs?.wrap;
276540
+ const isInlineShapeGroup = block.drawingKind === "shapeGroup" && rawWrap?.type === "Inline";
276541
+ const inlineParagraphAlignment = attrs?.inlineParagraphAlignment === "center" || attrs?.inlineParagraphAlignment === "right" ? attrs.inlineParagraphAlignment : undefined;
276542
+ if (width > maxWidthForBlock && maxWidthForBlock > 0) {
276543
+ const scale = maxWidthForBlock / width;
276544
+ width = maxWidthForBlock;
276545
+ height *= scale;
276546
+ }
276547
+ let state = ensurePage();
276548
+ const pageContentHeight = Math.max(0, state.contentBottom - state.topMargin);
276549
+ if (height > pageContentHeight && pageContentHeight > 0) {
276550
+ const scale = pageContentHeight / height;
276551
+ height = pageContentHeight;
276552
+ width *= scale;
276553
+ }
276554
+ const requiredHeight = marginTop + height + marginBottom;
276555
+ if (state.cursorY + requiredHeight > state.contentBottom && state.cursorY > state.topMargin)
276556
+ state = advanceColumn(state);
276557
+ const pmRange = extractBlockPmRange(block);
276558
+ let x = columnX(state) + marginLeft + indentLeft;
276559
+ if (isInlineShapeGroup && inlineParagraphAlignment) {
276560
+ const pIndentLeft = typeof attrs?.paragraphIndentLeft === "number" ? attrs.paragraphIndentLeft : 0;
276561
+ const pIndentRight = typeof attrs?.paragraphIndentRight === "number" ? attrs.paragraphIndentRight : 0;
276562
+ const alignBox = Math.max(0, maxWidthForBlock - pIndentLeft - pIndentRight);
276563
+ const extra = Math.max(0, alignBox - width);
276564
+ x += pIndentLeft + (inlineParagraphAlignment === "center" ? extra / 2 : extra);
276565
+ }
276566
+ const fragment2 = {
276567
+ kind: "drawing",
276568
+ blockId: block.id,
276569
+ drawingKind: block.drawingKind,
276570
+ x,
276571
+ y: state.cursorY + marginTop,
276572
+ width,
276573
+ height,
276574
+ geometry: measure.geometry,
276575
+ scale: measure.scale,
276576
+ drawingContentId: block.drawingContentId,
276577
+ zIndex: getFragmentZIndex(block),
276578
+ pmStart: pmRange.pmStart,
276579
+ pmEnd: pmRange.pmEnd,
276580
+ sourceAnchor: block.sourceAnchor
276581
+ };
276582
+ state.page.fragments.push(fragment2);
276583
+ state.cursorY += requiredHeight;
276584
+ state.maxCursorY = Math.max(state.maxCursorY, state.cursorY);
276585
+ }
276171
276586
  function buildParagraphIndexById(blocks2, len3) {
276172
276587
  const paragraphIndexById = /* @__PURE__ */ new Map;
276173
276588
  for (let i4 = 0;i4 < len3; i4 += 1) {
@@ -276264,21 +276679,22 @@ function collectAnchoredTables(blocks2, measures) {
276264
276679
  const tableMeasure = measure;
276265
276680
  if (!tableBlock.anchor?.isAnchored)
276266
276681
  continue;
276267
- const anchorParagraphId = typeof tableBlock.attrs === "object" && tableBlock.attrs ? tableBlock.attrs.anchorParagraphId : undefined;
276268
- const anchorParaIndex = resolveAnchorParagraphIndex(blocks2, len3, paragraphIndexById, i4, anchorParagraphId);
276269
- if (anchorParaIndex == null) {
276682
+ const resolution = resolveFloatingTableAnchorResolution(blocks2, measures, len3, i4, tableBlock, paragraphIndexById);
276683
+ if (resolution == null) {
276270
276684
  withoutParagraph.push({
276271
276685
  block: tableBlock,
276272
276686
  measure: tableMeasure
276273
276687
  });
276274
276688
  continue;
276275
276689
  }
276276
- const list5 = byParagraph.get(anchorParaIndex) ?? [];
276690
+ const list5 = byParagraph.get(resolution.paragraphIndex) ?? [];
276277
276691
  list5.push({
276278
276692
  block: tableBlock,
276279
- measure: tableMeasure
276693
+ measure: tableMeasure,
276694
+ layoutOffsetV: resolution.offsetV,
276695
+ lineScopedOnAnchor: resolution.lineScopedOnAnchor
276280
276696
  });
276281
- byParagraph.set(anchorParaIndex, list5);
276697
+ byParagraph.set(resolution.paragraphIndex, list5);
276282
276698
  }
276283
276699
  return {
276284
276700
  byParagraph,
@@ -276872,7 +277288,14 @@ function balanceSectionOnPage(args$1) {
276872
277288
  availableHeight: remainingHeight,
276873
277289
  contentBlocks
276874
277290
  }, DEFAULT_BALANCING_CONFIG);
276875
- const columnX = (columnIndex) => args$1.margins.left + columnIndex * (columnWidth + columnGap);
277291
+ const balancedGeometry = getColumnGeometry({
277292
+ count: columnCount,
277293
+ gap: columnGap,
277294
+ width: columnWidth,
277295
+ ...Array.isArray(sectionColumns.widths) ? { widths: sectionColumns.widths } : {},
277296
+ ...Array.isArray(sectionColumns.gaps) ? { gaps: sectionColumns.gaps } : {}
277297
+ });
277298
+ const columnX = (columnIndex) => getColumnX(balancedGeometry, columnIndex, args$1.margins.left);
276876
277299
  const colCursors = new Array(columnCount).fill(sectionTopY);
276877
277300
  let maxY = sectionTopY;
276878
277301
  for (let i4 = 0;i4 < ordered.length; i4++) {
@@ -278072,7 +278495,6 @@ function layoutDocument(blocks2, measures, options = {}) {
278072
278495
  const anchoredTablesByParagraph = anchoredTables.byParagraph;
278073
278496
  const paragraphlessAnchoredTables = anchoredTables.withoutParagraph;
278074
278497
  const placedAnchoredIds = /* @__PURE__ */ new Set;
278075
- const placedAnchoredTableIds = /* @__PURE__ */ new Set;
278076
278498
  const preRegisteredAnchors = collectPreRegisteredAnchors(blocks2, measures);
278077
278499
  const preRegisteredPositions = /* @__PURE__ */ new Map;
278078
278500
  const resolveParagraphlessAnchoredTableY = (block, measure, state) => {
@@ -278277,13 +278699,7 @@ function layoutDocument(blocks2, measures, options = {}) {
278277
278699
  balanceResult = balanceSectionOnPage({
278278
278700
  fragments: state.page.fragments,
278279
278701
  sectionIndex: endingSectionIndex,
278280
- sectionColumns: {
278281
- count: normalized.count,
278282
- gap: normalized.gap,
278283
- width: normalized.width,
278284
- widths: endingSectionColumns.widths,
278285
- equalWidth: endingSectionColumns.equalWidth
278286
- },
278702
+ sectionColumns: toBalancingColumns(normalized),
278287
278703
  sectionHasExplicitColumnBreak: false,
278288
278704
  blockSectionMap,
278289
278705
  margins: { left: activeLeftMargin },
@@ -278424,8 +278840,10 @@ function layoutDocument(blocks2, measures, options = {}) {
278424
278840
  getFootnoteRefCountForBlockId,
278425
278841
  getFootnoteBandOverhead,
278426
278842
  getFootnoteAnchorsForBlockId
278427
- }, anchorsForPara ? {
278843
+ }, anchorsForPara || tablesForPara ? {
278428
278844
  anchoredDrawings: anchorsForPara,
278845
+ anchoredTables: tablesForPara,
278846
+ columnWidth: getCurrentColumnWidth(),
278429
278847
  pageWidth: activePageSize.w,
278430
278848
  pageMargins: {
278431
278849
  top: activeTopMargin,
@@ -278438,32 +278856,19 @@ function layoutDocument(blocks2, measures, options = {}) {
278438
278856
  } : undefined);
278439
278857
  if (tablesForPara) {
278440
278858
  const state = paginator.ensurePage();
278441
- const columnWidthForTable = getCurrentColumnWidth();
278442
- let anchorParagraphTopY = state.cursorY;
278443
- for (const fragment2 of state.page.fragments)
278444
- if (fragment2.kind === "para" && fragment2.blockId === block.id)
278445
- anchorParagraphTopY = Math.min(anchorParagraphTopY, fragment2.y);
278446
278859
  let tableBottomY = state.cursorY;
278447
- let nextStackY = state.cursorY;
278448
278860
  for (const { block: tableBlock, measure: tableMeasure } of tablesForPara) {
278449
- if (placedAnchoredTableIds.has(tableBlock.id))
278861
+ if (!placedAnchoredIds.has(tableBlock.id))
278450
278862
  continue;
278451
- const totalWidth = tableMeasure.totalWidth ?? 0;
278452
- if (columnWidthForTable > 0 && totalWidth >= columnWidthForTable * 0.99)
278863
+ if ((tableBlock.wrap?.type ?? "None") === "None")
278453
278864
  continue;
278454
- const offsetV = tableBlock.anchor?.offsetV ?? 0;
278455
- const anchorY = Math.max(anchorParagraphTopY, nextStackY) + offsetV;
278456
- floatManager.registerTable(tableBlock, tableMeasure, anchorY, state.columnIndex, state.page.number);
278457
- const tableFragment = createAnchoredTableFragment(tableBlock, tableMeasure, tableBlock.anchor?.offsetH ?? columnX(state), anchorY);
278458
- state.page.fragments.push(tableFragment);
278459
- placedAnchoredTableIds.add(tableBlock.id);
278460
- if ((tableBlock.wrap?.type ?? "None") !== "None") {
278461
- const bottom$1 = anchorY + (tableMeasure.totalHeight ?? 0);
278462
- const distBottom = tableBlock.wrap?.distBottom ?? 0;
278463
- if (bottom$1 > tableBottomY)
278464
- tableBottomY = bottom$1;
278465
- nextStackY = bottom$1 + distBottom;
278466
- }
278865
+ const tableFragment = state.page.fragments.find((fragment2) => fragment2.kind === "table" && fragment2.blockId === tableBlock.id);
278866
+ if (!tableFragment || tableFragment.kind !== "table")
278867
+ continue;
278868
+ const bottom$1 = tableFragment.y + (tableMeasure.totalHeight ?? 0);
278869
+ const distBottom = tableBlock.wrap?.distBottom ?? 0;
278870
+ if (bottom$1 + distBottom > tableBottomY)
278871
+ tableBottomY = bottom$1 + distBottom;
278467
278872
  }
278468
278873
  state.cursorY = tableBottomY;
278469
278874
  state.maxCursorY = Math.max(state.maxCursorY, state.cursorY);
@@ -278622,14 +279027,13 @@ function layoutDocument(blocks2, measures, options = {}) {
278622
279027
  const state = paginator.ensurePage();
278623
279028
  for (const { block: tableBlock, measure: tableMeasure } of paragraphlessAnchoredTables) {
278624
279029
  const columnWidthForTable = getCurrentColumnWidth();
278625
- const totalWidth = tableMeasure.totalWidth ?? 0;
278626
- if (columnWidthForTable > 0 && totalWidth >= columnWidthForTable * 0.99)
279030
+ tableMeasure.totalWidth;
279031
+ if (isAnchoredTableFullWidth(tableBlock, tableMeasure, columnWidthForTable))
278627
279032
  continue;
278628
279033
  const anchorY = resolveParagraphlessAnchoredTableY(tableBlock, tableMeasure, state);
278629
279034
  const anchorX = tableBlock.anchor?.offsetH ?? columnX(state);
278630
279035
  floatManager.registerTable(tableBlock, tableMeasure, anchorY, state.columnIndex, state.page.number);
278631
279036
  state.page.fragments.push(createAnchoredTableFragment(tableBlock, tableMeasure, anchorX, anchorY));
278632
- placedAnchoredTableIds.add(tableBlock.id);
278633
279037
  }
278634
279038
  }
278635
279039
  if (allowSectionBreakOnlyPageFallback && pages.length === 0 && hasOnlySectionBreakBlocks(blocks2))
@@ -278725,13 +279129,7 @@ function layoutDocument(blocks2, measures, options = {}) {
278725
279129
  balanceSectionOnPage({
278726
279130
  fragments: lastPageForSection.fragments,
278727
279131
  sectionIndex: sectionIdx,
278728
- sectionColumns: {
278729
- count: normalized.count,
278730
- gap: normalized.gap,
278731
- width: normalized.width,
278732
- widths: sectionCols.widths,
278733
- equalWidth: sectionCols.equalWidth
278734
- },
279132
+ sectionColumns: toBalancingColumns(normalized),
278735
279133
  sectionHasExplicitColumnBreak: false,
278736
279134
  blockSectionMap,
278737
279135
  margins: { left: sectionLeftMargin },
@@ -278926,6 +279324,16 @@ function layoutHeaderFooter(blocks2, measures, constraints, kind) {
278926
279324
  function normalizeColumns(input2, contentWidth) {
278927
279325
  return normalizeColumnLayout(input2, contentWidth, COLUMN_EPSILON$1);
278928
279326
  }
279327
+ function toBalancingColumns(normalized) {
279328
+ return {
279329
+ count: normalized.count,
279330
+ gap: normalized.gap,
279331
+ width: normalized.width,
279332
+ ...Array.isArray(normalized.widths) ? { widths: normalized.widths } : {},
279333
+ ...Array.isArray(normalized.gaps) ? { gaps: normalized.gaps } : {},
279334
+ ...normalized.equalWidth !== undefined ? { equalWidth: normalized.equalWidth } : {}
279335
+ };
279336
+ }
278929
279337
  function getMeasurementContext() {
278930
279338
  if (measurementCtx)
278931
279339
  return measurementCtx;
@@ -281172,8 +281580,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
281172
281580
  if (columnSlices.length === 0)
281173
281581
  return;
281174
281582
  const columnIndex = Math.max(0, Math.min(columns.count - 1, rawColumnIndex));
281175
- const columnStride = columns.width + columns.gap;
281176
- const columnX = columns.left + columnIndex * columnStride;
281583
+ const columnX = getColumnX(getColumnGeometry(columns), columnIndex, columns.left);
281177
281584
  const contentWidth = Math.min(columns.width, footnoteWidth);
281178
281585
  if (!Number.isFinite(contentWidth) || contentWidth <= 0)
281179
281586
  return;
@@ -282072,6 +282479,16 @@ function percentile(sortedValues, p$12) {
282072
282479
  const weight = index2 - lower;
282073
282480
  return sortedValues[lower] * (1 - weight) + sortedValues[upper] * weight;
282074
282481
  }
282482
+ function resolveColumnsForHit(layout, page, fragmentY) {
282483
+ if (page === undefined)
282484
+ return layout.columns;
282485
+ if (page.columnRegions && typeof fragmentY === "number") {
282486
+ const region = page.columnRegions.find((r$1) => fragmentY >= r$1.yStart && fragmentY < r$1.yEnd);
282487
+ if (region)
282488
+ return region.columns;
282489
+ }
282490
+ return page.columns;
282491
+ }
282075
282492
  function snapToNearestFragment(pageHit, blocks2, measures, pageRelativePoint) {
282076
282493
  const fragments = pageHit.page.fragments.filter((f2) => f2 != null && typeof f2 === "object");
282077
282494
  let nearestHit = null;
@@ -282238,7 +282655,7 @@ function resolvePositionHitFromDomPosition(layout, blocks2, measures, domPos, la
282238
282655
  if (domPos >= fragment2.pmStart && domPos <= fragment2.pmEnd) {
282239
282656
  blockId = fragment2.blockId;
282240
282657
  pageIndex = pi;
282241
- column = determineColumn(layout, fragment2.x);
282658
+ column = determineColumn(layout, fragment2.x, page, fragment2.y);
282242
282659
  const blockIndex = findBlockIndexByFragmentId(blocks2, fragment2.blockId);
282243
282660
  if (blockIndex !== -1) {
282244
282661
  const measure = measures[blockIndex];
@@ -282347,7 +282764,7 @@ function clickToPositionGeometry(layout, blocks2, measures, containerPoint, opti
282347
282764
  const pos = mapPointToPm(block, line, pageRelativePoint.x - fragment2.x, isRTL, availableWidth, alignmentOverride);
282348
282765
  if (pos == null)
282349
282766
  return null;
282350
- const column = determineColumn(layout, fragment2.x);
282767
+ const column = determineColumn(layout, fragment2.x, layout.pages[pageIndex], fragment2.y);
282351
282768
  return {
282352
282769
  pos,
282353
282770
  layoutEpoch,
@@ -282367,7 +282784,7 @@ function clickToPositionGeometry(layout, blocks2, measures, containerPoint, opti
282367
282784
  layoutEpoch,
282368
282785
  blockId: fragment2.blockId,
282369
282786
  pageIndex,
282370
- column: determineColumn(layout, fragment2.x),
282787
+ column: determineColumn(layout, fragment2.x, layout.pages[pageIndex], fragment2.y),
282371
282788
  lineIndex: -1
282372
282789
  };
282373
282790
  }
@@ -282401,7 +282818,7 @@ function clickToPositionGeometry(layout, blocks2, measures, containerPoint, opti
282401
282818
  layoutEpoch,
282402
282819
  blockId: tableHit.fragment.blockId,
282403
282820
  pageIndex,
282404
- column: determineTableColumn(layout, tableHit.fragment),
282821
+ column: determineTableColumn(layout, tableHit.fragment, layout.pages[pageIndex]),
282405
282822
  lineIndex
282406
282823
  };
282407
282824
  }
@@ -282412,7 +282829,7 @@ function clickToPositionGeometry(layout, blocks2, measures, containerPoint, opti
282412
282829
  layoutEpoch,
282413
282830
  blockId: tableHit.fragment.blockId,
282414
282831
  pageIndex,
282415
- column: determineTableColumn(layout, tableHit.fragment),
282832
+ column: determineTableColumn(layout, tableHit.fragment, layout.pages[pageIndex]),
282416
282833
  lineIndex: 0
282417
282834
  };
282418
282835
  }
@@ -282428,7 +282845,7 @@ function clickToPositionGeometry(layout, blocks2, measures, containerPoint, opti
282428
282845
  layoutEpoch,
282429
282846
  blockId: fragment2.blockId,
282430
282847
  pageIndex,
282431
- column: determineColumn(layout, fragment2.x),
282848
+ column: determineColumn(layout, fragment2.x, layout.pages[pageIndex], fragment2.y),
282432
282849
  lineIndex: -1
282433
282850
  };
282434
282851
  }
@@ -282844,7 +283261,7 @@ function pmPosToCharOffset(block, line, pmPos) {
282844
283261
  const pmOffsetInSlice = pmPos - runSlicePmStart;
282845
283262
  const charOffsetInSlice = Math.round(pmOffsetInSlice / runSlicePmRange * runSliceCharCount);
282846
283263
  const result = charOffset + Math.min(charOffsetInSlice, runSliceCharCount);
282847
- const runText$1 = text5;
283264
+ const runText$2 = text5;
282848
283265
  const offsetInRun = result - charOffset - (isFirstRun ? 0 : 0);
282849
283266
  logSelectionMapDebug({
282850
283267
  kind: "pmPosToCharOffset-hit",
@@ -282861,7 +283278,7 @@ function pmPosToCharOffset(block, line, pmPos) {
282861
283278
  pmOffsetInSlice,
282862
283279
  charOffsetInSlice,
282863
283280
  result,
282864
- runTextPreview: runText$1.slice(Math.max(0, offsetInRun - 10), Math.min(runText$1.length, offsetInRun + 10))
283281
+ runTextPreview: runText$2.slice(Math.max(0, offsetInRun - 10), Math.min(runText$2.length, offsetInRun + 10))
282865
283282
  });
282866
283283
  return result;
282867
283284
  }
@@ -320434,7 +320851,7 @@ menclose::after {
320434
320851
  pmStart: start$1,
320435
320852
  pmEnd: (typeof attrs.pmEnd === "number" ? attrs.pmEnd : undefined) ?? (start$1 != null ? start$1 + 1 : undefined)
320436
320853
  };
320437
- }, PX_PER_PT2, getParagraphAttrs = (block) => {
320854
+ }, ANCHORED_TABLE_FULL_WIDTH_RATIO = 0.99, COLUMN_MIN_WIDTH_PX = 25, COLUMN_MAX_WIDTH_PX = 200, ROW_MIN_HEIGHT_PX = 10, MIN_PARTIAL_ROW_HEIGHT = 20, ROW_HEIGHT_EPSILON = 0.1, PX_PER_PT2, getParagraphAttrs = (block) => {
320438
320855
  if (!block.attrs || typeof block.attrs !== "object")
320439
320856
  return;
320440
320857
  return block.attrs;
@@ -320469,7 +320886,7 @@ menclose::after {
320469
320886
  top: (borders.top?.space ?? 0) * PX_PER_PT2 + (borders.top?.width ?? 0),
320470
320887
  bottom: (borders.bottom?.space ?? 0) * PX_PER_PT2 + (borders.bottom?.width ?? 0)
320471
320888
  };
320472
- }, COLUMN_MIN_WIDTH_PX = 25, COLUMN_MAX_WIDTH_PX = 200, ROW_MIN_HEIGHT_PX = 10, MIN_PARTIAL_ROW_HEIGHT = 20, ROW_HEIGHT_EPSILON = 0.1, HEADING_STYLE_PREFIX = "heading", CHAPTER_MARKER_SEPARATOR_RE, CLEAN_CHAPTER_MARKER_RE, DEFAULT_BALANCING_CONFIG, getColumnWidthAt = (columns, columnIndex) => {
320889
+ }, HEADING_STYLE_PREFIX = "heading", CHAPTER_MARKER_SEPARATOR_RE, CLEAN_CHAPTER_MARKER_RE, DEFAULT_BALANCING_CONFIG, getColumnWidthAt = (columns, columnIndex) => {
320473
320890
  if (Array.isArray(columns.widths) && columns.widths.length > 0)
320474
320891
  return columns.widths[Math.max(0, Math.min(columnIndex, columns.widths.length - 1))] ?? columns.width;
320475
320892
  return columns.width;
@@ -322403,23 +322820,13 @@ menclose::after {
322403
322820
  if (fragment2?.kind === "table" && typeof fragment2.columnIndex === "number")
322404
322821
  columnIndex = Math.max(0, Math.min(columns.count - 1, fragment2.columnIndex));
322405
322822
  else if (fragment2 && typeof fragment2.x === "number") {
322406
- const widths = Array.isArray(columns.widths) && columns.widths.length > 0 ? columns.widths : undefined;
322407
- if (widths) {
322408
- let cursorX = columns.left;
322409
- for (let index2 = 0;index2 < columns.count; index2 += 1) {
322410
- const columnWidth = widths[index2] ?? columns.width;
322411
- if (fragment2.x < cursorX + columnWidth + columns.gap / 2) {
322412
- columnIndex = index2;
322413
- break;
322414
- }
322415
- cursorX += columnWidth + columns.gap;
322416
- columnIndex = Math.min(columns.count - 1, index2 + 1);
322823
+ const geometry = getColumnGeometry(columns);
322824
+ columnIndex = Math.max(0, geometry.length - 1);
322825
+ for (const col of geometry)
322826
+ if (fragment2.x < columns.left + col.x + col.width + col.gapAfter / 2) {
322827
+ columnIndex = col.index;
322828
+ break;
322417
322829
  }
322418
- } else {
322419
- const columnStride = columns.width + columns.gap;
322420
- const rawIndex = columnStride > 0 ? Math.floor((fragment2.x - columns.left) / columnStride) : 0;
322421
- columnIndex = Math.max(0, Math.min(columns.count - 1, rawIndex));
322422
- }
322423
322830
  }
322424
322831
  }
322425
322832
  const key2 = footnoteColumnKey(pageIndex, columnIndex);
@@ -322999,20 +323406,21 @@ menclose::after {
322999
323406
  if (block.kind !== "paragraph")
323000
323407
  return false;
323001
323408
  return getParagraphInlineDirection(block.attrs) === "rtl";
323002
- }, determineColumn = (layout, fragmentX) => {
323003
- const columns = layout.columns;
323409
+ }, determineColumn = (layout, fragmentX, page, fragmentY) => {
323410
+ const columns = resolveColumnsForHit(layout, page, fragmentY);
323004
323411
  if (!columns || columns.count <= 1)
323005
323412
  return 0;
323006
- const span = (layout.pageSize.w - columns.gap * (columns.count - 1)) / columns.count + columns.gap;
323007
- const relative = fragmentX;
323008
- const raw = Math.floor(relative / Math.max(span, 1));
323009
- return Math.max(0, Math.min(columns.count - 1, raw));
323010
- }, determineTableColumn = (layout, fragment2) => {
323413
+ const pageWidth = page?.size?.w ?? layout.pageSize.w;
323414
+ const margins = page?.margins ?? layout.pages[0]?.margins;
323415
+ const marginLeft = Math.max(0, margins?.left ?? 0);
323416
+ const marginRight = Math.max(0, margins?.right ?? 0);
323417
+ return getColumnAtX(getColumnGeometry(normalizeColumnLayout(columns, Math.max(1, pageWidth - (marginLeft + marginRight)))), fragmentX, marginLeft);
323418
+ }, determineTableColumn = (layout, fragment2, page) => {
323011
323419
  if (typeof fragment2.columnIndex === "number") {
323012
- const count2 = layout.columns?.count ?? 1;
323420
+ const count2 = resolveColumnsForHit(layout, page, fragment2.y)?.count ?? 1;
323013
323421
  return Math.max(0, Math.min(Math.max(0, count2 - 1), fragment2.columnIndex));
323014
323422
  }
323015
- return determineColumn(layout, fragment2.x);
323423
+ return determineColumn(layout, fragment2.x, page, fragment2.y);
323016
323424
  }, findLineIndexAtY = (lines, offsetY, fromLine, toLine) => {
323017
323425
  if (!lines || lines.length === 0)
323018
323426
  return null;
@@ -329191,13 +329599,13 @@ menclose::after {
329191
329599
  return;
329192
329600
  console.log(...args$1);
329193
329601
  }, 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, TRACKED_MARK_NAMES;
329194
- var init_src_DeS9kJS7_es = __esm(() => {
329602
+ var init_src_BhZiOqOm_es = __esm(() => {
329195
329603
  init_rolldown_runtime_Bg48TavK_es();
329196
- init_SuperConverter_BBjNvGFh_es();
329604
+ init_SuperConverter_bEQ45IUD_es();
329197
329605
  init_jszip_C49i9kUs_es();
329198
329606
  init_xml_js_CqGKpaft_es();
329199
329607
  init_uuid_qzgm05fK_es();
329200
- init_create_headless_toolbar_s_kl3MP8_es();
329608
+ init_create_headless_toolbar_BmFWtej0_es();
329201
329609
  init_constants_D9qj59G2_es();
329202
329610
  init_dist_B8HfvhaK_es();
329203
329611
  init_unified_Dsuw2be5_es();
@@ -364277,11 +364685,11 @@ function print() { __p += __j.call(arguments, '') }
364277
364685
  ]);
364278
364686
  });
364279
364687
 
364280
- // ../../packages/superdoc/dist/chunks/create-super-doc-ui-CZZRzAFm.es.js
364688
+ // ../../packages/superdoc/dist/chunks/create-super-doc-ui-C2hkLuct.es.js
364281
364689
  var MOD_ALIASES, ALT_ALIASES, CTRL_ALIASES, SHIFT_ALIASES, BUILTIN_CONTEXT_MENU_GROUPS, BUILTIN_GROUP_ORDER, RESERVED_PROXY_PROPERTY_NAMES, ALL_TOOLBAR_COMMAND_IDS, EMPTY_ACTIVE_IDS;
364282
- var init_create_super_doc_ui_CZZRzAFm_es = __esm(() => {
364283
- init_SuperConverter_BBjNvGFh_es();
364284
- init_create_headless_toolbar_s_kl3MP8_es();
364690
+ var init_create_super_doc_ui_C2hkLuct_es = __esm(() => {
364691
+ init_SuperConverter_bEQ45IUD_es();
364692
+ init_create_headless_toolbar_BmFWtej0_es();
364285
364693
  MOD_ALIASES = new Set([
364286
364694
  "Mod",
364287
364695
  "Meta",
@@ -364323,16 +364731,16 @@ var init_zipper_yaJVJ4z9_es = __esm(() => {
364323
364731
 
364324
364732
  // ../../packages/superdoc/dist/super-editor.es.js
364325
364733
  var init_super_editor_es = __esm(() => {
364326
- init_src_DeS9kJS7_es();
364327
- init_SuperConverter_BBjNvGFh_es();
364734
+ init_src_BhZiOqOm_es();
364735
+ init_SuperConverter_bEQ45IUD_es();
364328
364736
  init_jszip_C49i9kUs_es();
364329
364737
  init_xml_js_CqGKpaft_es();
364330
- init_create_headless_toolbar_s_kl3MP8_es();
364738
+ init_create_headless_toolbar_BmFWtej0_es();
364331
364739
  init_constants_D9qj59G2_es();
364332
364740
  init_dist_B8HfvhaK_es();
364333
364741
  init_unified_Dsuw2be5_es();
364334
364742
  init_DocxZipper_Bu2Fhqkw_es();
364335
- init_create_super_doc_ui_CZZRzAFm_es();
364743
+ init_create_super_doc_ui_C2hkLuct_es();
364336
364744
  init_ui_C5PAS9hY_es();
364337
364745
  init_eventemitter3_BnGqBE_Q_es();
364338
364746
  init_errors_CNaD6vcg_es();