@superdoc-dev/mcp 0.11.0-next.11 → 0.11.0-next.12

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 +1238 -772
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -52211,7 +52211,7 @@ var init_remark_gfm_BhnWr3yf_es = __esm(() => {
52211
52211
  emptyOptions2 = {};
52212
52212
  });
52213
52213
 
52214
- // ../../packages/superdoc/dist/chunks/SuperConverter-BBjNvGFh.es.js
52214
+ // ../../packages/superdoc/dist/chunks/SuperConverter-bEQ45IUD.es.js
52215
52215
  function getExtensionConfigField(extension$1, field, context = { name: "" }) {
52216
52216
  const fieldValue = extension$1.config[field];
52217
52217
  if (typeof fieldValue === "function")
@@ -62169,70 +62169,6 @@ function computeFragmentPmRange(block, lines, fromLine, toLine) {
62169
62169
  pmEnd
62170
62170
  };
62171
62171
  }
62172
- function resolveAnchoredGraphicY(input) {
62173
- const { anchor, objectHeight, contentTop, contentBottom, pageBottomMargin = 0, anchorParagraphY = contentTop, firstLineHeight = 0, preRegisteredFallbackToContentTop = false } = input;
62174
- const offsetV = anchor?.offsetV ?? 0;
62175
- const vRelativeFrom = anchor?.vRelativeFrom;
62176
- const alignV = anchor?.alignV;
62177
- const contentHeight = Math.max(0, contentBottom - contentTop);
62178
- if (vRelativeFrom === "margin") {
62179
- if (alignV === "bottom")
62180
- return contentBottom - objectHeight + offsetV;
62181
- if (alignV === "center")
62182
- return contentTop + (contentHeight - objectHeight) / 2 + offsetV;
62183
- return contentTop + offsetV;
62184
- }
62185
- if (vRelativeFrom === "page") {
62186
- const pageHeight = contentBottom + pageBottomMargin;
62187
- if (alignV === "bottom")
62188
- return pageHeight - objectHeight + offsetV;
62189
- if (alignV === "center")
62190
- return (pageHeight - objectHeight) / 2 + offsetV;
62191
- return offsetV;
62192
- }
62193
- if (vRelativeFrom === "paragraph") {
62194
- if (preRegisteredFallbackToContentTop)
62195
- return contentTop + offsetV;
62196
- const baseAnchorY = anchorParagraphY;
62197
- if (alignV === "bottom")
62198
- return baseAnchorY + firstLineHeight - objectHeight + offsetV;
62199
- if (alignV === "center")
62200
- return baseAnchorY + (firstLineHeight - objectHeight) / 2 + offsetV;
62201
- return baseAnchorY + offsetV;
62202
- }
62203
- if (preRegisteredFallbackToContentTop)
62204
- return contentTop + offsetV;
62205
- return anchorParagraphY + offsetV;
62206
- }
62207
- function resolveAnchoredGraphicX(anchor, columnIndex, columns, objectWidth, margins, pageWidth) {
62208
- const alignH = anchor.alignH ?? "left";
62209
- const offsetH = anchor.offsetH ?? 0;
62210
- const marginLeft = Math.max(0, margins?.left ?? 0);
62211
- const marginRight = Math.max(0, margins?.right ?? 0);
62212
- const contentWidth = pageWidth != null ? Math.max(1, pageWidth - (marginLeft + marginRight)) : columns.width;
62213
- const contentLeft = marginLeft;
62214
- const columnLeft = contentLeft + columnIndex * (columns.width + columns.gap);
62215
- const relativeFrom = anchor.hRelativeFrom ?? "column";
62216
- let baseX;
62217
- let availableWidth;
62218
- if (relativeFrom === "page") {
62219
- baseX = 0;
62220
- availableWidth = pageWidth != null ? pageWidth : contentWidth + marginLeft + marginRight;
62221
- } else if (relativeFrom === "margin") {
62222
- baseX = contentLeft;
62223
- availableWidth = contentWidth;
62224
- } else {
62225
- baseX = columnLeft;
62226
- availableWidth = columns.width;
62227
- }
62228
- if (alignH === "left")
62229
- return baseX + offsetH;
62230
- if (alignH === "right")
62231
- return baseX + availableWidth - objectWidth - offsetH;
62232
- if (alignH === "center")
62233
- return baseX + (availableWidth - objectWidth) / 2 + offsetH;
62234
- return baseX;
62235
- }
62236
62172
  function widthsEqual(a, b) {
62237
62173
  if (!a && !b)
62238
62174
  return true;
@@ -62276,23 +62212,29 @@ function resolveColumnLayout(input) {
62276
62212
  const resolved = cloneColumnLayout(input);
62277
62213
  resolved.count = count;
62278
62214
  if (resolveColumnMode(input) === "explicit") {
62279
- if (Array.isArray(resolved.widths))
62280
- resolved.widths = resolved.widths.slice(0, count);
62281
- if (Array.isArray(resolved.gaps))
62282
- resolved.gaps = resolved.gaps.slice(0, Math.max(0, count - 1));
62215
+ if (Array.isArray(resolved.widths)) {
62216
+ const rawGaps = Array.isArray(resolved.gaps) ? resolved.gaps : [];
62217
+ const usable = resolved.widths.map((width, i$1) => ({
62218
+ width,
62219
+ gapAfter: rawGaps[i$1]
62220
+ })).filter((record3) => typeof record3.width === "number" && Number.isFinite(record3.width) && record3.width > 0).slice(0, count);
62221
+ resolved.widths = usable.map((record3) => record3.width);
62222
+ if (Array.isArray(resolved.gaps))
62223
+ resolved.gaps = usable.slice(0, Math.max(0, count - 1)).map((record3) => record3.gapAfter ?? 0);
62224
+ }
62283
62225
  } else {
62284
62226
  delete resolved.widths;
62285
62227
  delete resolved.gaps;
62286
62228
  }
62287
62229
  return resolved;
62288
62230
  }
62289
- function buildColumnGeometry(widths, gap, withSeparator) {
62231
+ function buildColumnGeometry(widths, gap, withSeparator, gaps) {
62290
62232
  const geometry = [];
62291
62233
  let x = 0;
62292
62234
  for (let i$1 = 0;i$1 < widths.length; i$1 += 1) {
62293
62235
  const width = widths[i$1];
62294
62236
  const isLast = i$1 === widths.length - 1;
62295
- const gapAfter = isLast ? 0 : gap;
62237
+ const gapAfter = isLast ? 0 : gaps?.[i$1] ?? gap;
62296
62238
  const col = {
62297
62239
  index: i$1,
62298
62240
  x,
@@ -62300,7 +62242,7 @@ function buildColumnGeometry(widths, gap, withSeparator) {
62300
62242
  gapAfter
62301
62243
  };
62302
62244
  if (withSeparator && !isLast)
62303
- col.separatorX = x + width + gap / 2;
62245
+ col.separatorX = x + width + gapAfter / 2;
62304
62246
  geometry.push(col);
62305
62247
  x += width + gapAfter;
62306
62248
  }
@@ -62317,11 +62259,9 @@ function normalizeColumnLayout(input, contentWidth, epsilon = 0.0001) {
62317
62259
  const fallbackWidth = count - widths.length > 0 ? remaining / (count - widths.length) : 0;
62318
62260
  widths.push(...Array.from({ length: count - widths.length }, () => fallbackWidth));
62319
62261
  }
62320
- const totalExplicitWidth = widths.reduce((sum, width$1) => sum + width$1, 0);
62321
- if (availableWidth > 0 && totalExplicitWidth > 0) {
62322
- const scale = availableWidth / totalExplicitWidth;
62323
- widths = widths.map((width$1) => Math.max(1, width$1 * scale));
62324
- }
62262
+ if (availableWidth > 0)
62263
+ widths = widths.map((value) => Math.max(1, value));
62264
+ const gaps = explicitWidths.length > 0 && Array.isArray(input?.gaps) ? input.gaps.slice(0, Math.max(0, count - 1)) : undefined;
62325
62265
  const width = widths.reduce((max, value) => Math.max(max, value), 0);
62326
62266
  if (!Number.isFinite(width) || width <= epsilon)
62327
62267
  return {
@@ -62334,13 +62274,15 @@ function normalizeColumnLayout(input, contentWidth, epsilon = 0.0001) {
62334
62274
  count,
62335
62275
  gap,
62336
62276
  ...widths.length > 0 ? { widths } : {},
62277
+ ...gaps && gaps.length > 0 ? { gaps } : {},
62337
62278
  ...input?.equalWidth !== undefined ? { equalWidth: input.equalWidth } : {},
62338
62279
  ...input?.withSeparator !== undefined ? { withSeparator: input.withSeparator } : {},
62339
62280
  width
62340
62281
  };
62341
62282
  }
62342
62283
  function getColumnGeometry(normalized) {
62343
- return buildColumnGeometry(Array.isArray(normalized.widths) && normalized.widths.length > 0 ? normalized.widths : [normalized.width], normalized.gap, Boolean(normalized.withSeparator));
62284
+ const count = Number.isFinite(normalized.count) ? Math.max(1, Math.floor(normalized.count)) : 1;
62285
+ return buildColumnGeometry(Array.isArray(normalized.widths) && normalized.widths.length > 0 ? normalized.widths : new Array(count).fill(normalized.width), normalized.gap, Boolean(normalized.withSeparator), normalized.gaps);
62344
62286
  }
62345
62287
  function clampColumnIndex(geometry, index2) {
62346
62288
  if (geometry.length === 0)
@@ -62356,6 +62298,18 @@ function getColumnX(geometry, index2, originX = 0) {
62356
62298
  function getColumnSeparatorPositions(geometry, originX = 0) {
62357
62299
  return geometry.filter((col) => typeof col.separatorX === "number").map((col) => originX + col.separatorX);
62358
62300
  }
62301
+ function getColumnAtX(geometry, x, originX = 0) {
62302
+ if (geometry.length === 0)
62303
+ return 0;
62304
+ const cx = x - originX;
62305
+ let result = 0;
62306
+ for (const col of geometry)
62307
+ if (cx >= col.x)
62308
+ result = col.index;
62309
+ else
62310
+ break;
62311
+ return result;
62312
+ }
62359
62313
  function columnRenderLayoutsEqual(a, b) {
62360
62314
  if (!a && !b)
62361
62315
  return true;
@@ -62378,6 +62332,70 @@ function columnRenderLayoutsEqual(a, b) {
62378
62332
  }
62379
62333
  return true;
62380
62334
  }
62335
+ function resolveAnchoredGraphicY(input) {
62336
+ const { anchor, objectHeight, contentTop, contentBottom, pageBottomMargin = 0, anchorParagraphY = contentTop, firstLineHeight = 0, preRegisteredFallbackToContentTop = false } = input;
62337
+ const offsetV = anchor?.offsetV ?? 0;
62338
+ const vRelativeFrom = anchor?.vRelativeFrom;
62339
+ const alignV = anchor?.alignV;
62340
+ const contentHeight = Math.max(0, contentBottom - contentTop);
62341
+ if (vRelativeFrom === "margin") {
62342
+ if (alignV === "bottom")
62343
+ return contentBottom - objectHeight + offsetV;
62344
+ if (alignV === "center")
62345
+ return contentTop + (contentHeight - objectHeight) / 2 + offsetV;
62346
+ return contentTop + offsetV;
62347
+ }
62348
+ if (vRelativeFrom === "page") {
62349
+ const pageHeight = contentBottom + pageBottomMargin;
62350
+ if (alignV === "bottom")
62351
+ return pageHeight - objectHeight + offsetV;
62352
+ if (alignV === "center")
62353
+ return (pageHeight - objectHeight) / 2 + offsetV;
62354
+ return offsetV;
62355
+ }
62356
+ if (vRelativeFrom === "paragraph") {
62357
+ if (preRegisteredFallbackToContentTop)
62358
+ return contentTop + offsetV;
62359
+ const baseAnchorY = anchorParagraphY;
62360
+ if (alignV === "bottom")
62361
+ return baseAnchorY + firstLineHeight - objectHeight + offsetV;
62362
+ if (alignV === "center")
62363
+ return baseAnchorY + (firstLineHeight - objectHeight) / 2 + offsetV;
62364
+ return baseAnchorY + offsetV;
62365
+ }
62366
+ if (preRegisteredFallbackToContentTop)
62367
+ return contentTop + offsetV;
62368
+ return anchorParagraphY + offsetV;
62369
+ }
62370
+ function resolveAnchoredGraphicX(anchor, columnIndex, columns, objectWidth, margins, pageWidth) {
62371
+ const alignH = anchor.alignH ?? "left";
62372
+ const offsetH = anchor.offsetH ?? 0;
62373
+ const marginLeft = Math.max(0, margins?.left ?? 0);
62374
+ const marginRight = Math.max(0, margins?.right ?? 0);
62375
+ const contentWidth = pageWidth != null ? Math.max(1, pageWidth - (marginLeft + marginRight)) : columns.width;
62376
+ const contentLeft = marginLeft;
62377
+ const geometry = getColumnGeometry(columns);
62378
+ const relativeFrom = anchor.hRelativeFrom ?? "column";
62379
+ let baseX;
62380
+ let availableWidth;
62381
+ if (relativeFrom === "page") {
62382
+ baseX = 0;
62383
+ availableWidth = pageWidth != null ? pageWidth : contentWidth + marginLeft + marginRight;
62384
+ } else if (relativeFrom === "margin") {
62385
+ baseX = contentLeft;
62386
+ availableWidth = contentWidth;
62387
+ } else {
62388
+ baseX = getColumnX(geometry, columnIndex, contentLeft);
62389
+ availableWidth = columns.width;
62390
+ }
62391
+ if (alignH === "left")
62392
+ return baseX + offsetH;
62393
+ if (alignH === "right")
62394
+ return baseX + availableWidth - objectWidth - offsetH;
62395
+ if (alignH === "center")
62396
+ return baseX + (availableWidth - objectWidth) / 2 + offsetH;
62397
+ return baseX;
62398
+ }
62381
62399
  function getIdlessSdtContainerKey(metadata) {
62382
62400
  const existingKey = idlessSdtContainerKeys.get(metadata);
62383
62401
  if (existingKey)
@@ -82227,17 +82245,40 @@ function translateAnchorNode(params) {
82227
82245
  wrapElement.attributes = attributes;
82228
82246
  break;
82229
82247
  }
82230
- case "Through":
82231
82248
  case "Tight": {
82232
82249
  const attributes = {};
82233
82250
  if ("distLeft" in (attrs.wrap.attrs || {}))
82234
82251
  attributes.distL = pixelsToEmu(attrs.wrap.attrs.distLeft);
82235
82252
  if ("distRight" in (attrs.wrap.attrs || {}))
82236
82253
  attributes.distR = pixelsToEmu(attrs.wrap.attrs.distRight);
82237
- if ("distTop" in (attrs.wrap.attrs || {}))
82238
- attributes.distT = pixelsToEmu(attrs.wrap.attrs.distTop);
82254
+ const wrapText = attrs.wrap.attrs?.wrapText || "bothSides";
82255
+ if (wrapText)
82256
+ attributes.wrapText = wrapText;
82257
+ if (Object.keys(attributes).length)
82258
+ wrapElement.attributes = attributes;
82259
+ if (attrs.wrap.attrs?.polygon) {
82260
+ const polygonNode = objToPolygon(attrs.wrap.attrs.polygon);
82261
+ if (polygonNode) {
82262
+ if (attrs.wrap.attrs?.polygonEdited !== undefined)
82263
+ polygonNode.attributes = {
82264
+ ...polygonNode.attributes || {},
82265
+ edited: String(attrs.wrap.attrs.polygonEdited)
82266
+ };
82267
+ wrapElement.elements = [polygonNode];
82268
+ }
82269
+ }
82270
+ break;
82271
+ }
82272
+ case "Through": {
82273
+ const attributes = {};
82239
82274
  if ("distBottom" in (attrs.wrap.attrs || {}))
82240
82275
  attributes.distB = pixelsToEmu(attrs.wrap.attrs.distBottom);
82276
+ if ("distLeft" in (attrs.wrap.attrs || {}))
82277
+ attributes.distL = pixelsToEmu(attrs.wrap.attrs.distLeft);
82278
+ if ("distRight" in (attrs.wrap.attrs || {}))
82279
+ attributes.distR = pixelsToEmu(attrs.wrap.attrs.distRight);
82280
+ if ("distTop" in (attrs.wrap.attrs || {}))
82281
+ attributes.distT = pixelsToEmu(attrs.wrap.attrs.distTop);
82241
82282
  const wrapText = attrs.wrap.attrs?.wrapText || "bothSides";
82242
82283
  if (wrapText)
82243
82284
  attributes.wrapText = wrapText;
@@ -89759,6 +89800,22 @@ function normalizeLegacyBorderStyle(value) {
89759
89800
  return "single";
89760
89801
  }
89761
89802
  }
89803
+ function countFloatingTableContentColumns(node2) {
89804
+ const grid = node2.attrs?.grid;
89805
+ if (Array.isArray(grid) && grid.length > 0)
89806
+ return grid.length;
89807
+ const firstRow = node2.content?.[0];
89808
+ if (!firstRow || !isTableRowNode(firstRow) || !Array.isArray(firstRow.content))
89809
+ return 0;
89810
+ let columns = 0;
89811
+ for (const cellNode of firstRow.content) {
89812
+ if (!cellNode || !isTableCellNode(cellNode))
89813
+ continue;
89814
+ const colSpan = typeof cellNode.attrs?.colspan === "number" ? cellNode.attrs.colspan : 1;
89815
+ columns += colSpan > 0 ? colSpan : 1;
89816
+ }
89817
+ return columns;
89818
+ }
89762
89819
  function extractFloatingTableAnchorWrap(node2) {
89763
89820
  const floatingProps = node2.attrs?.tableProperties?.floatingTableProperties;
89764
89821
  if (!floatingProps)
@@ -89800,9 +89857,11 @@ function extractFloatingTableAnchorWrap(node2) {
89800
89857
  anchor.offsetH = twipsToPx(floatingProps.tblpX);
89801
89858
  if (floatingProps.tblpY !== undefined)
89802
89859
  anchor.offsetV = twipsToPx(floatingProps.tblpY);
89803
- const hasDistances = floatingProps.leftFromText !== undefined || floatingProps.rightFromText !== undefined || floatingProps.topFromText !== undefined || floatingProps.bottomFromText !== undefined;
89860
+ const hasHorizontalDistances = floatingProps.leftFromText !== undefined || floatingProps.rightFromText !== undefined;
89861
+ const hasVerticalDistances = floatingProps.topFromText !== undefined || floatingProps.bottomFromText !== undefined;
89862
+ const hasDistances = hasHorizontalDistances || hasVerticalDistances;
89804
89863
  const wrap$1 = {
89805
- type: "Square",
89864
+ type: countFloatingTableContentColumns(node2) <= 1 && hasHorizontalDistances && !hasVerticalDistances ? "None" : "Square",
89806
89865
  wrapText: "bothSides"
89807
89866
  };
89808
89867
  if (hasDistances) {
@@ -105249,13 +105308,16 @@ var isRegExp = (value) => {
105249
105308
  }, mergeAnchorPaddingIntoWrapDistances = (wrap$1, padding) => {
105250
105309
  if (!wrap$1?.attrs || !padding)
105251
105310
  return;
105252
- if (wrap$1.attrs.distTop == null && Number.isFinite(padding.top) && padding.top !== 0)
105311
+ const type = wrap$1.type;
105312
+ const mergeVertical = type === "Square" || type === "TopAndBottom";
105313
+ const mergeHorizontal = type === "Square" || type === "Tight" || type === "Through";
105314
+ if (mergeVertical && wrap$1.attrs.distTop == null && Number.isFinite(padding.top) && padding.top !== 0)
105253
105315
  wrap$1.attrs.distTop = padding.top;
105254
- if (wrap$1.attrs.distBottom == null && Number.isFinite(padding.bottom) && padding.bottom !== 0)
105316
+ if (mergeVertical && wrap$1.attrs.distBottom == null && Number.isFinite(padding.bottom) && padding.bottom !== 0)
105255
105317
  wrap$1.attrs.distBottom = padding.bottom;
105256
- if (wrap$1.attrs.distLeft == null && Number.isFinite(padding.left) && padding.left !== 0)
105318
+ if (mergeHorizontal && wrap$1.attrs.distLeft == null && Number.isFinite(padding.left) && padding.left !== 0)
105257
105319
  wrap$1.attrs.distLeft = padding.left;
105258
- if (wrap$1.attrs.distRight == null && Number.isFinite(padding.right) && padding.right !== 0)
105320
+ if (mergeHorizontal && wrap$1.attrs.distRight == null && Number.isFinite(padding.right) && padding.right !== 0)
105259
105321
  wrap$1.attrs.distRight = padding.right;
105260
105322
  }, handleShapeDrawing = (params, node2, graphicData, size, padding, marginOffset, anchorData, wrap$1, isAnchor, isHidden) => {
105261
105323
  const wsp = graphicData.elements.find((el) => el.name === "wps:wsp");
@@ -113881,13 +113943,15 @@ var isRegExp = (value) => {
113881
113943
  }, mergeWrapDistancesFromPadding = (wrap$1, padding) => {
113882
113944
  if (!padding || wrap$1.type === "None" || wrap$1.type === "Inline")
113883
113945
  return;
113884
- if (wrap$1.distTop == null && padding.top != null)
113946
+ const mergeVertical = wrap$1.type === "Square" || wrap$1.type === "TopAndBottom";
113947
+ const mergeHorizontal = wrap$1.type === "Square" || wrap$1.type === "Tight" || wrap$1.type === "Through";
113948
+ if (mergeVertical && wrap$1.distTop == null && padding.top != null)
113885
113949
  wrap$1.distTop = padding.top;
113886
- if (wrap$1.distBottom == null && padding.bottom != null)
113950
+ if (mergeVertical && wrap$1.distBottom == null && padding.bottom != null)
113887
113951
  wrap$1.distBottom = padding.bottom;
113888
- if (wrap$1.distLeft == null && padding.left != null)
113952
+ if (mergeHorizontal && wrap$1.distLeft == null && padding.left != null)
113889
113953
  wrap$1.distLeft = padding.left;
113890
- if (wrap$1.distRight == null && padding.right != null)
113954
+ if (mergeHorizontal && wrap$1.distRight == null && padding.right != null)
113891
113955
  wrap$1.distRight = padding.right;
113892
113956
  }, normalizeColor = (value) => {
113893
113957
  if (typeof value !== "string")
@@ -116968,7 +117032,7 @@ var isRegExp = (value) => {
116968
117032
  state.kern = kernNode.attributes["w:val"];
116969
117033
  }
116970
117034
  }, SuperConverter;
116971
- var init_SuperConverter_BBjNvGFh_es = __esm(() => {
117035
+ var init_SuperConverter_bEQ45IUD_es = __esm(() => {
116972
117036
  init_rolldown_runtime_Bg48TavK_es();
116973
117037
  init_jszip_C49i9kUs_es();
116974
117038
  init_xml_js_CqGKpaft_es();
@@ -156028,7 +156092,7 @@ var init_SuperConverter_BBjNvGFh_es = __esm(() => {
156028
156092
  };
156029
156093
  });
156030
156094
 
156031
- // ../../packages/superdoc/dist/chunks/create-headless-toolbar-s_kl3MP8.es.js
156095
+ // ../../packages/superdoc/dist/chunks/create-headless-toolbar-BmFWtej0.es.js
156032
156096
  function parseSizeUnit(val = "0") {
156033
156097
  const length = val.toString() || "0";
156034
156098
  const value = Number.parseFloat(length);
@@ -166361,8 +166425,8 @@ var CSS_DIMENSION_REGEX, DOM_SIZE_UNITS, normalizeActorId = (value) => {
166361
166425
  }
166362
166426
  };
166363
166427
  };
166364
- var init_create_headless_toolbar_s_kl3MP8_es = __esm(() => {
166365
- init_SuperConverter_BBjNvGFh_es();
166428
+ var init_create_headless_toolbar_BmFWtej0_es = __esm(() => {
166429
+ init_SuperConverter_bEQ45IUD_es();
166366
166430
  init_uuid_qzgm05fK_es();
166367
166431
  init_constants_D9qj59G2_es();
166368
166432
  init_dist_B8HfvhaK_es();
@@ -221046,7 +221110,7 @@ var init_remark_gfm_eZN6yzWQ_es = __esm(() => {
221046
221110
  init_remark_gfm_BhnWr3yf_es();
221047
221111
  });
221048
221112
 
221049
- // ../../packages/superdoc/dist/chunks/src-DeS9kJS7.es.js
221113
+ // ../../packages/superdoc/dist/chunks/src-BhZiOqOm.es.js
221050
221114
  function deleteProps(obj, propOrProps) {
221051
221115
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
221052
221116
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -233982,13 +234046,13 @@ function processDocumentForMissingRefs(node2, usedIds, fixed) {
233982
234046
  function buildCommentJsonFromText(text5) {
233983
234047
  return text5.replace(/\r\n?/g, `
233984
234048
  `).split(`
233985
- `).map((paragraphText) => ({
234049
+ `).map((paragraphText$1) => ({
233986
234050
  type: "paragraph",
233987
234051
  content: [{
233988
234052
  type: "run",
233989
234053
  content: [{
233990
234054
  type: "text",
233991
- text: paragraphText
234055
+ text: paragraphText$1
233992
234056
  }]
233993
234057
  }]
233994
234058
  }));
@@ -251943,8 +252007,8 @@ function replaceSdtTextContent(editor, target, text5) {
251943
252007
  const paragraph2 = buildEmptyBlockContent(editor, resolved.node);
251944
252008
  if (!paragraph2)
251945
252009
  return false;
251946
- const paragraphText = text5.length > 0 ? buildTextWithTabs(editor.schema, text5, undefined) : null;
251947
- const updatedParagraph = paragraph2.type.create(paragraph2.attrs ?? null, paragraphText, paragraph2.marks);
252010
+ const paragraphText$1 = text5.length > 0 ? buildTextWithTabs(editor.schema, text5, undefined) : null;
252011
+ const updatedParagraph = paragraph2.type.create(paragraph2.attrs ?? null, paragraphText$1, paragraph2.marks);
251948
252012
  tr.replaceWith(innerFrom, innerTo, updatedParagraph);
251949
252013
  dispatchTransaction$1(editor, tr);
251950
252014
  return true;
@@ -263388,7 +263452,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
263388
263452
  };
263389
263453
  const leftFloats = [];
263390
263454
  const rightFloats = [];
263391
- const columnOrigin = marginLeft + columnIndex * (currentColumns.width + currentColumns.gap);
263455
+ const columnOrigin = getColumnX(getColumnGeometry(currentColumns), columnIndex, marginLeft);
263392
263456
  const columnCenter = columnOrigin + baseWidth / 2;
263393
263457
  for (const zone of wrappingZones)
263394
263458
  if (zone.wrapMode === "left")
@@ -263460,7 +263524,7 @@ function computeTableAnchorX(anchor, columnIndex, columns, tableWidth, margins,
263460
263524
  const marginRight = Math.max(0, margins?.right ?? 0);
263461
263525
  const contentWidth = pageWidth != null ? Math.max(1, pageWidth - (marginLeft + marginRight)) : columns.width;
263462
263526
  const contentLeft = marginLeft;
263463
- const columnLeft = contentLeft + columnIndex * (columns.width + columns.gap);
263527
+ const columnLeft = getColumnX(getColumnGeometry(columns), columnIndex, contentLeft);
263464
263528
  const relativeFrom = anchor.hRelativeFrom ?? "column";
263465
263529
  let baseX;
263466
263530
  let availableWidth;
@@ -263796,560 +263860,6 @@ function computeParagraphLayoutStartY(input2) {
263796
263860
  const effectiveSpacingBefore = input2.suppressSpacingBefore ? 0 : input2.spacingBefore;
263797
263861
  return computeParagraphContentStartY(y$1, effectiveSpacingBefore, effectiveSpacingBefore === 0, trailingForCollapse);
263798
263862
  }
263799
- function calculateFirstLineIndent(block, measure) {
263800
- const wordLayout = block.attrs?.wordLayout;
263801
- if (!wordLayout?.firstLineIndentMode)
263802
- return 0;
263803
- if (!wordLayout.marker || !measure.marker)
263804
- return 0;
263805
- const markerWidthRaw = measure.marker.markerWidth ?? wordLayout.marker.markerBoxWidthPx ?? 0;
263806
- const markerWidth = Number.isFinite(markerWidthRaw) && markerWidthRaw >= 0 ? markerWidthRaw : 0;
263807
- const gutterWidthRaw = measure.marker.gutterWidth ?? 0;
263808
- return markerWidth + (Number.isFinite(gutterWidthRaw) && gutterWidthRaw >= 0 ? gutterWidthRaw : 0);
263809
- }
263810
- function layoutParagraphBlock(ctx$1, anchors) {
263811
- const { block, measure, columnWidth, ensurePage, advanceColumn, columnX, floatManager } = ctx$1;
263812
- const remeasureParagraph$1 = ctx$1.remeasureParagraph;
263813
- const frame = getParagraphAttrs(block)?.frame;
263814
- let lines = normalizeLines(measure);
263815
- const measurementWidth = lines[0]?.maxWidth;
263816
- const paraIndent = block.attrs?.indent;
263817
- const indentLeft = typeof paraIndent?.left === "number" && Number.isFinite(paraIndent.left) ? paraIndent.left : 0;
263818
- const indentRight = typeof paraIndent?.right === "number" && Number.isFinite(paraIndent.right) ? paraIndent.right : 0;
263819
- const negativeLeftIndent = indentLeft < 0 ? indentLeft : 0;
263820
- const negativeRightIndent = indentRight < 0 ? indentRight : 0;
263821
- const remeasureWidth = Math.max(1, columnWidth - indentLeft - indentRight);
263822
- let didRemeasureForColumnWidth = false;
263823
- let remeasuredMarkerInfo;
263824
- if (typeof remeasureParagraph$1 === "function" && typeof measurementWidth === "number" && measurementWidth > remeasureWidth) {
263825
- const newMeasure = remeasureParagraph$1(block, columnWidth, calculateFirstLineIndent(block, measure));
263826
- lines = normalizeLines(newMeasure);
263827
- didRemeasureForColumnWidth = true;
263828
- if (newMeasure.marker)
263829
- remeasuredMarkerInfo = newMeasure.marker;
263830
- }
263831
- let fromLine = 0;
263832
- const attrs = getParagraphAttrs(block);
263833
- const spacing = attrs?.spacing ?? {};
263834
- const spacingExplicit = attrs?.spacingExplicit;
263835
- const styleId$1 = asString2(attrs?.styleId);
263836
- const contextualSpacing = asBoolean$1(attrs?.contextualSpacing);
263837
- let spacingBefore = Math.max(0, Number(spacing.before ?? spacing.lineSpaceBefore ?? 0));
263838
- let spacingAfter = ctx$1.overrideSpacingAfter ?? Math.max(0, Number(spacing.after ?? spacing.lineSpaceAfter ?? 0));
263839
- if (isEmptyTextParagraph(block) && spacingExplicit) {
263840
- if (!spacingExplicit.before)
263841
- spacingBefore = 0;
263842
- if (!spacingExplicit.after)
263843
- spacingAfter = 0;
263844
- }
263845
- const baseSpacingBefore = spacingBefore;
263846
- let appliedSpacingBefore = spacingBefore === 0;
263847
- let lastState = null;
263848
- const previewState = ensurePage();
263849
- const rawBorderExpansion = computeBorderVerticalExpansion(attrs?.borders);
263850
- const currentBorderHash = hashBorders(attrs?.borders);
263851
- const inBorderGroup = currentBorderHash != null && currentBorderHash === previewState.lastParagraphBorderHash;
263852
- const borderExpansion = {
263853
- top: inBorderGroup ? 0 : rawBorderExpansion.top,
263854
- bottom: rawBorderExpansion.bottom
263855
- };
263856
- const paragraphAnchorBaseY = computeParagraphLayoutStartY({
263857
- cursorY: previewState.cursorY,
263858
- spacingBefore,
263859
- trailingSpacing: previewState.trailingSpacing,
263860
- suppressSpacingBefore: shouldSuppressOwnSpacing(styleId$1, contextualSpacing, previewState.lastParagraphStyleId),
263861
- rewindTrailingFromPrevious: shouldSuppressOwnSpacing(previewState.lastParagraphStyleId, previewState.lastParagraphContextualSpacing, styleId$1)
263862
- }) + borderExpansion.top - (inBorderGroup ? rawBorderExpansion.bottom : 0);
263863
- const registerAnchoredDrawingsAt = (paragraphContentStartY) => {
263864
- if (!anchors?.anchoredDrawings?.length)
263865
- return;
263866
- for (const entry of anchors.anchoredDrawings) {
263867
- if (anchors.placedAnchoredIds.has(entry.block.id))
263868
- continue;
263869
- const state = ensurePage();
263870
- const contentTop = state.topMargin;
263871
- const contentBottom = state.contentBottom;
263872
- const anchorY = resolveAnchoredGraphicY({
263873
- anchor: entry.block.anchor,
263874
- objectHeight: entry.measure.height,
263875
- contentTop,
263876
- contentBottom,
263877
- pageBottomMargin: anchors.pageMargins.bottom ?? 0,
263878
- anchorParagraphY: paragraphContentStartY,
263879
- firstLineHeight: measure.lines?.[0]?.lineHeight ?? 0
263880
- });
263881
- floatManager.registerDrawing(entry.block, entry.measure, anchorY, state.columnIndex, state.page.number);
263882
- const anchorX = entry.block.anchor ? resolveAnchoredGraphicX(entry.block.anchor, state.columnIndex, anchors.columns, entry.measure.width, {
263883
- left: anchors.pageMargins.left,
263884
- right: anchors.pageMargins.right
263885
- }, anchors.pageWidth) : columnX(state);
263886
- const pmRange = extractBlockPmRange(entry.block);
263887
- if (entry.block.kind === "image" && entry.measure.kind === "image") {
263888
- const pageContentHeight = Math.max(0, state.contentBottom - state.topMargin);
263889
- const relativeFrom = entry.block.anchor?.hRelativeFrom ?? "column";
263890
- const marginLeft = anchors.pageMargins.left ?? 0;
263891
- const marginRight = anchors.pageMargins.right ?? 0;
263892
- let maxWidth;
263893
- if (relativeFrom === "page")
263894
- maxWidth = anchors.columns.count === 1 ? anchors.pageWidth - marginLeft - marginRight : anchors.pageWidth;
263895
- else if (relativeFrom === "margin")
263896
- maxWidth = anchors.pageWidth - marginLeft - marginRight;
263897
- else
263898
- maxWidth = anchors.columns.width;
263899
- const aspectRatio = entry.measure.width > 0 && entry.measure.height > 0 ? entry.measure.width / entry.measure.height : 1;
263900
- const minWidth = 20;
263901
- const minHeight = minWidth / aspectRatio;
263902
- const metadata = {
263903
- originalWidth: entry.measure.width,
263904
- originalHeight: entry.measure.height,
263905
- maxWidth,
263906
- maxHeight: pageContentHeight,
263907
- aspectRatio,
263908
- minWidth,
263909
- minHeight
263910
- };
263911
- const fragment = {
263912
- kind: "image",
263913
- blockId: entry.block.id,
263914
- x: anchorX,
263915
- y: anchorY,
263916
- width: entry.measure.width,
263917
- height: entry.measure.height,
263918
- isAnchored: true,
263919
- behindDoc: entry.block.anchor?.behindDoc === true,
263920
- zIndex: getFragmentZIndex(entry.block),
263921
- metadata,
263922
- sourceAnchor: entry.block.sourceAnchor
263923
- };
263924
- if (pmRange.pmStart != null)
263925
- fragment.pmStart = pmRange.pmStart;
263926
- if (pmRange.pmEnd != null)
263927
- fragment.pmEnd = pmRange.pmEnd;
263928
- state.page.fragments.push(fragment);
263929
- } else if (entry.block.kind === "drawing" && entry.measure.kind === "drawing") {
263930
- const fragment = {
263931
- kind: "drawing",
263932
- blockId: entry.block.id,
263933
- drawingKind: entry.block.drawingKind,
263934
- x: anchorX,
263935
- y: anchorY,
263936
- width: entry.measure.width,
263937
- height: entry.measure.height,
263938
- geometry: entry.measure.geometry,
263939
- scale: entry.measure.scale,
263940
- isAnchored: true,
263941
- behindDoc: entry.block.anchor?.behindDoc === true,
263942
- zIndex: getFragmentZIndex(entry.block),
263943
- drawingContentId: entry.block.drawingContentId,
263944
- sourceAnchor: entry.block.sourceAnchor
263945
- };
263946
- if (pmRange.pmStart != null)
263947
- fragment.pmStart = pmRange.pmStart;
263948
- if (pmRange.pmEnd != null)
263949
- fragment.pmEnd = pmRange.pmEnd;
263950
- state.page.fragments.push(fragment);
263951
- }
263952
- anchors.placedAnchoredIds.add(entry.block.id);
263953
- }
263954
- };
263955
- registerAnchoredDrawingsAt(paragraphAnchorBaseY);
263956
- if (frame?.wrap === "none") {
263957
- let state = ensurePage();
263958
- if (state.cursorY >= state.contentBottom)
263959
- state = advanceColumn(state);
263960
- const fragmentWidth = lines.reduce((max$2, line) => Math.max(max$2, line.width ?? 0), 0) || columnWidth;
263961
- let x = columnX(state);
263962
- if (frame.xAlign === "right")
263963
- x += columnWidth - fragmentWidth;
263964
- else if (frame.xAlign === "center")
263965
- x += (columnWidth - fragmentWidth) / 2;
263966
- if (typeof frame.x === "number" && Number.isFinite(frame.x))
263967
- x += frame.x;
263968
- const yOffset = typeof frame.y === "number" && Number.isFinite(frame.y) ? frame.y : 0;
263969
- const fragment = {
263970
- kind: "para",
263971
- blockId: block.id,
263972
- fromLine: 0,
263973
- toLine: lines.length,
263974
- x,
263975
- y: state.cursorY + yOffset,
263976
- width: fragmentWidth,
263977
- sourceAnchor: block.sourceAnchor,
263978
- ...computeFragmentPmRange2(block, lines, 0, lines.length)
263979
- };
263980
- if (measure.marker || remeasuredMarkerInfo) {
263981
- fragment.markerWidth = (remeasuredMarkerInfo ?? measure.marker)?.markerWidth ?? measure.marker?.markerWidth ?? 0;
263982
- const markerTextWidth = remeasuredMarkerInfo?.markerTextWidth ?? measure.marker?.markerTextWidth;
263983
- if (markerTextWidth != null)
263984
- fragment.markerTextWidth = markerTextWidth;
263985
- }
263986
- state.page.fragments.push(fragment);
263987
- state.trailingSpacing = 0;
263988
- state.lastParagraphStyleId = styleId$1;
263989
- state.lastParagraphContextualSpacing = contextualSpacing;
263990
- return;
263991
- }
263992
- let narrowestWidth = columnWidth;
263993
- let narrowestOffsetX = 0;
263994
- let didRemeasureForFloats = false;
263995
- if (typeof remeasureParagraph$1 === "function") {
263996
- const tempState = ensurePage();
263997
- let tempY = paragraphAnchorBaseY;
263998
- for (let i4 = 0;i4 < lines.length; i4++) {
263999
- const lineY = tempY;
264000
- const lineHeight = lines[i4]?.lineHeight || 0;
264001
- const { width: availableWidth, offsetX: computedOffset } = floatManager.computeAvailableWidth(lineY, lineHeight, columnWidth, tempState.columnIndex, tempState.page.number);
264002
- if (availableWidth < narrowestWidth) {
264003
- narrowestWidth = availableWidth;
264004
- narrowestOffsetX = computedOffset;
264005
- }
264006
- tempY += lineHeight;
264007
- }
264008
- const narrowestRemeasureWidth = narrowestWidth < columnWidth || narrowestOffsetX > 0 ? Math.max(1, narrowestWidth - Math.max(indentLeft, 0) - Math.max(indentRight, 0)) : Math.max(1, narrowestWidth - indentLeft - indentRight);
264009
- if (narrowestRemeasureWidth < remeasureWidth || narrowestOffsetX > 0) {
264010
- const newMeasure = remeasureParagraph$1(block, narrowestRemeasureWidth, calculateFirstLineIndent(block, measure));
264011
- lines = normalizeLines(newMeasure);
264012
- didRemeasureForFloats = true;
264013
- if (newMeasure.marker)
264014
- remeasuredMarkerInfo = newMeasure.marker;
264015
- }
264016
- }
264017
- while (fromLine < lines.length) {
264018
- let state = ensurePage();
264019
- if (state.trailingSpacing == null)
264020
- state.trailingSpacing = 0;
264021
- if (inBorderGroup && fromLine === 0)
264022
- state.cursorY -= rawBorderExpansion.bottom;
264023
- if (shouldSuppressOwnSpacing(styleId$1, contextualSpacing, state.lastParagraphStyleId))
264024
- spacingBefore = 0;
264025
- if (shouldSuppressOwnSpacing(state.lastParagraphStyleId, state.lastParagraphContextualSpacing, styleId$1)) {
264026
- const prevTrailing = asSafeNumber(state.trailingSpacing);
264027
- if (prevTrailing > 0) {
264028
- state.cursorY = rewindPreviousParagraphTrailing(state.cursorY, prevTrailing);
264029
- state.trailingSpacing = 0;
264030
- }
264031
- }
264032
- if (attrs?.keepLines === true && fromLine === 0) {
264033
- const neededSpacingBefore = collapseSpacingBefore(spacingBefore, state.trailingSpacing);
264034
- const pageContentHeight = state.contentBottom - state.topMargin;
264035
- const fullHeight = lines.reduce((sum, line) => sum + (line.lineHeight || 0), 0) + borderExpansion.top + borderExpansion.bottom;
264036
- const fitsOnBlankPage = fullHeight + baseSpacingBefore <= pageContentHeight;
264037
- const remainingHeightAfterSpacing = state.contentBottom - (state.cursorY + neededSpacingBefore);
264038
- if (fitsOnBlankPage && state.page.fragments.length > 0 && fullHeight > remainingHeightAfterSpacing) {
264039
- state = advanceColumn(state);
264040
- spacingBefore = baseSpacingBefore;
264041
- appliedSpacingBefore = spacingBefore === 0;
264042
- continue;
264043
- }
264044
- }
264045
- if (!appliedSpacingBefore && spacingBefore > 0)
264046
- while (!appliedSpacingBefore) {
264047
- state.trailingSpacing;
264048
- const neededSpacingBefore = collapseSpacingBefore(spacingBefore, state.trailingSpacing);
264049
- if (state.cursorY + neededSpacingBefore > state.contentBottom) {
264050
- if (state.cursorY <= state.topMargin) {
264051
- state.trailingSpacing = 0;
264052
- appliedSpacingBefore = true;
264053
- break;
264054
- }
264055
- state = advanceColumn(state);
264056
- if (state.trailingSpacing == null)
264057
- state.trailingSpacing = 0;
264058
- continue;
264059
- }
264060
- if (neededSpacingBefore > 0) {
264061
- state.cursorY += neededSpacingBefore;
264062
- state.maxCursorY = Math.max(state.maxCursorY, state.cursorY);
264063
- }
264064
- state.trailingSpacing = 0;
264065
- appliedSpacingBefore = true;
264066
- }
264067
- else
264068
- state.trailingSpacing = 0;
264069
- const FN_SAFETY_MARGIN_PX = 1;
264070
- const fallbackBandOverhead = (refsTotal) => refsTotal > 0 ? 22 + Math.max(0, refsTotal - 1) * 2 : 0;
264071
- const bandOverhead = (refsTotal) => {
264072
- if (refsTotal <= 0)
264073
- return 0;
264074
- const fromCtx = ctx$1.getFootnoteBandOverhead?.(refsTotal);
264075
- return (typeof fromCtx === "number" && Number.isFinite(fromCtx) && fromCtx >= 0 ? fromCtx : fallbackBandOverhead(refsTotal)) + FN_SAFETY_MARGIN_PX;
264076
- };
264077
- const rawContentBottom = state.contentBottom + state.pageFootnoteReserve;
264078
- const computeEffectiveBottom = (extraDemand, extraRefs) => {
264079
- const totalDemand = extraDemand;
264080
- const totalRefs = state.footnoteRefsThisPage + extraRefs;
264081
- const demandWithOverhead = totalDemand > 0 ? totalDemand + bandOverhead(totalRefs) : 0;
264082
- const reservedSpace = Math.max(state.pageFootnoteReserve, demandWithOverhead);
264083
- const minBodyLineHeight = lines[fromLine]?.lineHeight ?? 0;
264084
- const maxAdditional = Math.max(0, rawContentBottom - state.topMargin - minBodyLineHeight);
264085
- return rawContentBottom - Math.min(reservedSpace, maxAdditional);
264086
- };
264087
- const computeFootnoteClusterDemand = (pmStart, pmEnd) => {
264088
- const candidate = ctx$1.getFootnoteAnchorsForBlockId ? ctx$1.getFootnoteAnchorsForBlockId(block.id, pmStart, pmEnd) : [];
264089
- const committed = state.footnoteAnchorsThisPage ?? [];
264090
- if (candidate.length === 0 && committed.length === 0)
264091
- return 0;
264092
- let demand = 0;
264093
- for (const anchor of committed)
264094
- demand += anchor.fullHeight;
264095
- for (const anchor of candidate)
264096
- demand += anchor.fullHeight;
264097
- return demand;
264098
- };
264099
- const previewRange = computeFragmentPmRange2(block, lines, fromLine, fromLine + 1);
264100
- const previewRefs = ctx$1.getFootnoteRefCountForBlockId ? ctx$1.getFootnoteRefCountForBlockId(block.id, previewRange.pmStart, previewRange.pmEnd) : 0;
264101
- const computePreviewBottom = () => {
264102
- return computeEffectiveBottom(computeFootnoteClusterDemand(previewRange.pmStart ?? 0, previewRange.pmEnd ?? 0), previewRefs);
264103
- };
264104
- let effectiveBottom = computePreviewBottom();
264105
- if (state.cursorY >= effectiveBottom) {
264106
- state = advanceColumn(state);
264107
- effectiveBottom = computePreviewBottom();
264108
- }
264109
- if (effectiveBottom - state.cursorY <= 0) {
264110
- state = advanceColumn(state);
264111
- effectiveBottom = computePreviewBottom();
264112
- }
264113
- const nextLineHeight = lines[fromLine].lineHeight || 0;
264114
- const remainingHeight = effectiveBottom - state.cursorY;
264115
- if (state.page.fragments.length > 0 && remainingHeight < nextLineHeight) {
264116
- state = advanceColumn(state);
264117
- effectiveBottom = computePreviewBottom();
264118
- }
264119
- let effectiveColumnWidth = columnWidth;
264120
- let offsetX = 0;
264121
- if (didRemeasureForFloats) {
264122
- effectiveColumnWidth = narrowestWidth;
264123
- offsetX = narrowestOffsetX;
264124
- }
264125
- const borderVertical = borderExpansion.top + borderExpansion.bottom;
264126
- let toLine = fromLine;
264127
- let height = 0;
264128
- let sliceDemand = 0;
264129
- let sliceRefs = 0;
264130
- while (toLine < lines.length) {
264131
- const lineHeight = lines[toLine].lineHeight || 0;
264132
- const range = computeFragmentPmRange2(block, lines, fromLine, toLine + 1);
264133
- const orderedDemand = computeFootnoteClusterDemand(range.pmStart ?? 0, range.pmEnd ?? 0);
264134
- const nextRefs = ctx$1.getFootnoteRefCountForBlockId ? ctx$1.getFootnoteRefCountForBlockId(block.id, range.pmStart, range.pmEnd) : 0;
264135
- if (toLine === fromLine) {
264136
- height = lineHeight;
264137
- sliceDemand = orderedDemand;
264138
- sliceRefs = nextRefs;
264139
- toLine = fromLine + 1;
264140
- continue;
264141
- }
264142
- if (state.cursorY + height + lineHeight + borderVertical > computeEffectiveBottom(orderedDemand, nextRefs))
264143
- break;
264144
- height += lineHeight;
264145
- sliceDemand = orderedDemand;
264146
- sliceRefs = nextRefs;
264147
- toLine += 1;
264148
- }
264149
- const slice2 = {
264150
- toLine,
264151
- height
264152
- };
264153
- const fragmentHeight = slice2.height;
264154
- if (sliceDemand > 0 || sliceRefs > 0) {
264155
- state.footnoteDemandThisPage = sliceDemand;
264156
- state.footnoteRefsThisPage = (state.footnoteRefsThisPage ?? 0) + sliceRefs;
264157
- }
264158
- if (ctx$1.getFootnoteAnchorsForBlockId) {
264159
- const committedRange = computeFragmentPmRange2(block, lines, fromLine, toLine);
264160
- const newAnchors = ctx$1.getFootnoteAnchorsForBlockId(block.id, committedRange.pmStart, committedRange.pmEnd);
264161
- if (newAnchors.length > 0) {
264162
- if (!state.footnoteAnchorsThisPage)
264163
- state.footnoteAnchorsThisPage = [];
264164
- const seen = new Set(state.footnoteAnchorsThisPage.map((a2) => a2.refId));
264165
- for (const a2 of newAnchors)
264166
- if (!seen.has(a2.refId))
264167
- state.footnoteAnchorsThisPage.push(a2);
264168
- }
264169
- }
264170
- const floatAdjustedX = columnX(state) + offsetX;
264171
- const adjustedX = didRemeasureForFloats ? floatAdjustedX + Math.max(negativeLeftIndent, 0) : floatAdjustedX + negativeLeftIndent;
264172
- const columnRight = columnX(state) + columnWidth;
264173
- let adjustedWidth = didRemeasureForFloats ? effectiveColumnWidth : effectiveColumnWidth - negativeLeftIndent - negativeRightIndent;
264174
- if (didRemeasureForFloats)
264175
- adjustedWidth = Math.min(adjustedWidth, Math.max(1, columnRight - adjustedX));
264176
- const fragment = {
264177
- kind: "para",
264178
- blockId: block.id,
264179
- fromLine,
264180
- toLine: slice2.toLine,
264181
- x: adjustedX,
264182
- y: state.cursorY + borderExpansion.top,
264183
- width: adjustedWidth,
264184
- sourceAnchor: block.sourceAnchor,
264185
- ...computeFragmentPmRange2(block, lines, fromLine, slice2.toLine)
264186
- };
264187
- if (didRemeasureForColumnWidth || didRemeasureForFloats)
264188
- fragment.lines = lines.slice(fromLine, slice2.toLine);
264189
- if ((measure.marker || remeasuredMarkerInfo) && fromLine === 0) {
264190
- fragment.markerWidth = (remeasuredMarkerInfo ?? measure.marker)?.markerWidth ?? measure.marker?.markerWidth ?? 0;
264191
- const markerTextWidth = remeasuredMarkerInfo?.markerTextWidth ?? measure.marker?.markerTextWidth;
264192
- if (markerTextWidth != null)
264193
- fragment.markerTextWidth = markerTextWidth;
264194
- const gutterWidth = remeasuredMarkerInfo?.gutterWidth ?? measure.marker?.gutterWidth;
264195
- if (gutterWidth != null)
264196
- fragment.markerGutter = gutterWidth;
264197
- }
264198
- if (fromLine > 0)
264199
- fragment.continuesFromPrev = true;
264200
- if (slice2.toLine < lines.length)
264201
- fragment.continuesOnNext = true;
264202
- const floatAlignment = block.attrs?.floatAlignment;
264203
- if (floatAlignment && (floatAlignment === "right" || floatAlignment === "center")) {
264204
- let maxLineWidth = 0;
264205
- for (let i4 = fromLine;i4 < slice2.toLine; i4++)
264206
- if (lines[i4].width > maxLineWidth)
264207
- maxLineWidth = lines[i4].width;
264208
- if (floatAlignment === "right")
264209
- fragment.x = columnX(state) + offsetX + (effectiveColumnWidth - maxLineWidth);
264210
- else if (floatAlignment === "center")
264211
- fragment.x = columnX(state) + offsetX + (effectiveColumnWidth - maxLineWidth) / 2;
264212
- }
264213
- state.page.fragments.push(fragment);
264214
- state.cursorY += borderExpansion.top + fragmentHeight + borderExpansion.bottom;
264215
- state.maxCursorY = Math.max(state.maxCursorY, state.cursorY);
264216
- lastState = state;
264217
- fromLine = slice2.toLine;
264218
- }
264219
- if (lastState) {
264220
- if (spacingAfter > 0) {
264221
- let targetState = lastState;
264222
- let appliedSpacingAfter = spacingAfter;
264223
- if (targetState.cursorY + spacingAfter > targetState.contentBottom) {
264224
- targetState = advanceColumn(targetState);
264225
- appliedSpacingAfter = 0;
264226
- } else {
264227
- targetState.cursorY += spacingAfter;
264228
- targetState.maxCursorY = Math.max(targetState.maxCursorY, targetState.cursorY);
264229
- }
264230
- targetState.trailingSpacing = appliedSpacingAfter;
264231
- } else
264232
- lastState.trailingSpacing = 0;
264233
- lastState.lastParagraphStyleId = styleId$1;
264234
- lastState.lastParagraphContextualSpacing = contextualSpacing;
264235
- lastState.lastParagraphBorderHash = currentBorderHash;
264236
- }
264237
- }
264238
- function layoutImageBlock({ block, measure, columns, ensurePage, advanceColumn, columnX }) {
264239
- if (block.anchor?.isAnchored)
264240
- return;
264241
- const marginTop = Math.max(0, block.margin?.top ?? 0);
264242
- const marginBottom = Math.max(0, block.margin?.bottom ?? 0);
264243
- const marginLeft = Math.max(0, block.margin?.left ?? 0);
264244
- const marginRight = Math.max(0, block.margin?.right ?? 0);
264245
- const maxWidth = Math.max(0, columns.width - (marginLeft + marginRight));
264246
- let width = measure.width;
264247
- let height = measure.height;
264248
- if (width > maxWidth && maxWidth > 0) {
264249
- const scale = maxWidth / width;
264250
- width = maxWidth;
264251
- height *= scale;
264252
- }
264253
- let state = ensurePage();
264254
- const pageContentHeight = Math.max(0, state.contentBottom - state.topMargin);
264255
- if (height > pageContentHeight && pageContentHeight > 0) {
264256
- const scale = pageContentHeight / height;
264257
- height = pageContentHeight;
264258
- width *= scale;
264259
- }
264260
- const requiredHeight = marginTop + height + marginBottom;
264261
- if (state.cursorY + requiredHeight > state.contentBottom && state.cursorY > state.topMargin)
264262
- state = advanceColumn(state);
264263
- const pmRange = extractBlockPmRange(block);
264264
- const aspectRatio = measure.width > 0 && measure.height > 0 ? measure.width / measure.height : 1;
264265
- const minWidth = 20;
264266
- const minHeight = minWidth / aspectRatio;
264267
- const metadata = {
264268
- originalWidth: measure.width,
264269
- originalHeight: measure.height,
264270
- maxWidth,
264271
- maxHeight: pageContentHeight,
264272
- aspectRatio,
264273
- minWidth,
264274
- minHeight
264275
- };
264276
- const fragment = {
264277
- kind: "image",
264278
- blockId: block.id,
264279
- x: columnX(state) + marginLeft,
264280
- y: state.cursorY + marginTop,
264281
- width,
264282
- height,
264283
- pmStart: pmRange.pmStart,
264284
- pmEnd: pmRange.pmEnd,
264285
- metadata,
264286
- sourceAnchor: block.sourceAnchor
264287
- };
264288
- state.page.fragments.push(fragment);
264289
- state.cursorY += requiredHeight;
264290
- state.maxCursorY = Math.max(state.maxCursorY, state.cursorY);
264291
- }
264292
- function layoutDrawingBlock({ block, measure, columns, ensurePage, advanceColumn, columnX }) {
264293
- if (block.anchor?.isAnchored)
264294
- return;
264295
- const marginTop = Math.max(0, block.margin?.top ?? 0);
264296
- const marginBottom = Math.max(0, block.margin?.bottom ?? 0);
264297
- const marginLeft = Math.max(0, block.margin?.left ?? 0);
264298
- const marginRight = Math.max(0, block.margin?.right ?? 0);
264299
- const maxWidth = Math.max(0, columns.width - (marginLeft + marginRight));
264300
- let width = measure.width;
264301
- let height = measure.height;
264302
- const attrs = block.attrs;
264303
- const indentLeft = typeof attrs?.hrIndentLeft === "number" ? attrs.hrIndentLeft : 0;
264304
- const indentRight = typeof attrs?.hrIndentRight === "number" ? attrs.hrIndentRight : 0;
264305
- const maxWidthForBlock = attrs?.isFullWidth === true && maxWidth > 0 ? Math.max(1, maxWidth - indentLeft - indentRight) : maxWidth;
264306
- const rawWrap = attrs?.wrap;
264307
- const isInlineShapeGroup = block.drawingKind === "shapeGroup" && rawWrap?.type === "Inline";
264308
- const inlineParagraphAlignment = attrs?.inlineParagraphAlignment === "center" || attrs?.inlineParagraphAlignment === "right" ? attrs.inlineParagraphAlignment : undefined;
264309
- if (width > maxWidthForBlock && maxWidthForBlock > 0) {
264310
- const scale = maxWidthForBlock / width;
264311
- width = maxWidthForBlock;
264312
- height *= scale;
264313
- }
264314
- let state = ensurePage();
264315
- const pageContentHeight = Math.max(0, state.contentBottom - state.topMargin);
264316
- if (height > pageContentHeight && pageContentHeight > 0) {
264317
- const scale = pageContentHeight / height;
264318
- height = pageContentHeight;
264319
- width *= scale;
264320
- }
264321
- const requiredHeight = marginTop + height + marginBottom;
264322
- if (state.cursorY + requiredHeight > state.contentBottom && state.cursorY > state.topMargin)
264323
- state = advanceColumn(state);
264324
- const pmRange = extractBlockPmRange(block);
264325
- let x = columnX(state) + marginLeft + indentLeft;
264326
- if (isInlineShapeGroup && inlineParagraphAlignment) {
264327
- const pIndentLeft = typeof attrs?.paragraphIndentLeft === "number" ? attrs.paragraphIndentLeft : 0;
264328
- const pIndentRight = typeof attrs?.paragraphIndentRight === "number" ? attrs.paragraphIndentRight : 0;
264329
- const alignBox = Math.max(0, maxWidthForBlock - pIndentLeft - pIndentRight);
264330
- const extra = Math.max(0, alignBox - width);
264331
- x += pIndentLeft + (inlineParagraphAlignment === "center" ? extra / 2 : extra);
264332
- }
264333
- const fragment = {
264334
- kind: "drawing",
264335
- blockId: block.id,
264336
- drawingKind: block.drawingKind,
264337
- x,
264338
- y: state.cursorY + marginTop,
264339
- width,
264340
- height,
264341
- geometry: measure.geometry,
264342
- scale: measure.scale,
264343
- drawingContentId: block.drawingContentId,
264344
- zIndex: getFragmentZIndex(block),
264345
- pmStart: pmRange.pmStart,
264346
- pmEnd: pmRange.pmEnd,
264347
- sourceAnchor: block.sourceAnchor
264348
- };
264349
- state.page.fragments.push(fragment);
264350
- state.cursorY += requiredHeight;
264351
- state.maxCursorY = Math.max(state.maxCursorY, state.cursorY);
264352
- }
264353
263863
  function describeCellRenderBlocks(cellMeasure, cellBlock, cellPadding) {
264354
263864
  const measuredBlocks = cellMeasure.blocks;
264355
263865
  const blockDataArray = cellBlock?.blocks;
@@ -264610,6 +264120,248 @@ function sumArray(arr) {
264610
264120
  total += v;
264611
264121
  return total;
264612
264122
  }
264123
+ function runText$1(run2) {
264124
+ if (run2.kind != null && run2.kind !== "text")
264125
+ return "";
264126
+ return "text" in run2 && typeof run2.text === "string" ? run2.text : "";
264127
+ }
264128
+ function paragraphText(block) {
264129
+ return block.runs?.map(runText$1).join("") ?? "";
264130
+ }
264131
+ function paragraphMeasureAt(blocks2, measures, index2) {
264132
+ const block = blocks2[index2];
264133
+ const measure = measures[index2];
264134
+ if (block?.kind !== "paragraph" || measure?.kind !== "paragraph")
264135
+ return null;
264136
+ return measure;
264137
+ }
264138
+ function paragraphFirstLineHeight(blocks2, measures, index2) {
264139
+ const measure = paragraphMeasureAt(blocks2, measures, index2);
264140
+ if (!measure)
264141
+ return 0;
264142
+ const firstLine = measure.lines?.[0];
264143
+ if (firstLine?.lineHeight != null && firstLine.lineHeight > 0)
264144
+ return firstLine.lineHeight;
264145
+ return measure.totalHeight ?? 0;
264146
+ }
264147
+ function isSingleLineParagraph(blocks2, measures, index2) {
264148
+ const measure = paragraphMeasureAt(blocks2, measures, index2);
264149
+ if (!measure)
264150
+ return false;
264151
+ const lineCount = measure.lines?.length ?? 0;
264152
+ if (lineCount === 1)
264153
+ return true;
264154
+ return lineCount === 0 && (measure.totalHeight ?? 0) > 0;
264155
+ }
264156
+ function isTextEmptyParagraph(blocks2, index2) {
264157
+ const block = blocks2[index2];
264158
+ if (block.kind !== "paragraph")
264159
+ return false;
264160
+ return paragraphText(block).trim().length === 0;
264161
+ }
264162
+ function findPreviousParagraphIndex(blocks2, fromIndex) {
264163
+ for (let i4 = fromIndex - 1;i4 >= 0; i4 -= 1)
264164
+ if (blocks2[i4].kind === "paragraph")
264165
+ return i4;
264166
+ return null;
264167
+ }
264168
+ function findNextParagraphIndex(blocks2, fromIndex, len3) {
264169
+ for (let i4 = fromIndex + 1;i4 < len3; i4 += 1)
264170
+ if (blocks2[i4].kind === "paragraph")
264171
+ return i4;
264172
+ return null;
264173
+ }
264174
+ function findNearestParagraphIndex$1(blocks2, len3, fromIndex) {
264175
+ return findPreviousParagraphIndex(blocks2, fromIndex) ?? findNextParagraphIndex(blocks2, fromIndex, len3);
264176
+ }
264177
+ function paragraphMeasureHeight(measures, index2) {
264178
+ const measure = measures[index2];
264179
+ if (measure?.kind !== "paragraph")
264180
+ return 0;
264181
+ return measure.totalHeight ?? 0;
264182
+ }
264183
+ function isLineScopedTblpY$1(blocks2, measures, paragraphIndex, offsetV) {
264184
+ const lineHeight = paragraphFirstLineHeight(blocks2, measures, paragraphIndex);
264185
+ if (lineHeight <= 0)
264186
+ return offsetV <= 1;
264187
+ return offsetV <= lineHeight * 1.5;
264188
+ }
264189
+ function isMultiLineParagraph(blocks2, measures, index2) {
264190
+ const measure = paragraphMeasureAt(blocks2, measures, index2);
264191
+ if (!measure)
264192
+ return false;
264193
+ return (measure.lines?.length ?? 0) > 1;
264194
+ }
264195
+ function findForwardCompactOptionLine(blocks2, measures, len3, tableIndex) {
264196
+ for (let i4 = tableIndex + 1;i4 < len3; i4 += 1) {
264197
+ if (blocks2[i4].kind !== "paragraph")
264198
+ continue;
264199
+ if (isTextEmptyParagraph(blocks2, i4))
264200
+ continue;
264201
+ if (!isSingleLineParagraph(blocks2, measures, i4))
264202
+ continue;
264203
+ const height = paragraphMeasureHeight(measures, i4);
264204
+ const lineH = paragraphFirstLineHeight(blocks2, measures, i4);
264205
+ if (height <= 0 || lineH <= 0 || height > lineH * 1.25)
264206
+ continue;
264207
+ const prevIndex = findPreviousParagraphIndex(blocks2, i4);
264208
+ if (prevIndex == null)
264209
+ continue;
264210
+ if (isMultiLineParagraph(blocks2, measures, prevIndex))
264211
+ return i4;
264212
+ if (isCompactOptionLineAfterBody(blocks2, measures, i4, prevIndex))
264213
+ return i4;
264214
+ }
264215
+ return null;
264216
+ }
264217
+ function isCompactOptionLineAfterBody(blocks2, measures, optionIndex, bodyIndex) {
264218
+ if (bodyIndex == null)
264219
+ return false;
264220
+ if (!isSingleLineParagraph(blocks2, measures, optionIndex))
264221
+ return false;
264222
+ const optionHeight = paragraphMeasureHeight(measures, optionIndex);
264223
+ const optionLine = paragraphFirstLineHeight(blocks2, measures, optionIndex);
264224
+ if (optionHeight <= 0 || optionLine <= 0 || optionHeight > optionLine * 1.25)
264225
+ return false;
264226
+ return paragraphMeasureHeight(measures, bodyIndex) > optionHeight * 1.5;
264227
+ }
264228
+ function resolutionWithLineScopedFlag(blocks2, measures, paragraphIndex, offsetV, rawOffsetV, forwardResolved = false) {
264229
+ return {
264230
+ paragraphIndex,
264231
+ offsetV,
264232
+ lineScopedOnAnchor: !forwardResolved && offsetV === rawOffsetV && isLineScopedTblpY$1(blocks2, measures, paragraphIndex, offsetV) && !isTextEmptyParagraph(blocks2, paragraphIndex)
264233
+ };
264234
+ }
264235
+ function paintOffsetThroughAnchorParagraphs(blocks2, measures, len3, tableIndex, anchorParagraphIndex, rawOffsetV) {
264236
+ let consumed = 0;
264237
+ let index2 = findNextParagraphIndex(blocks2, tableIndex, len3);
264238
+ while (index2 != null && index2 <= anchorParagraphIndex) {
264239
+ consumed += paragraphMeasureHeight(measures, index2);
264240
+ if (index2 === anchorParagraphIndex)
264241
+ break;
264242
+ index2 = findNextParagraphIndex(blocks2, index2, len3);
264243
+ }
264244
+ return Math.max(0, rawOffsetV - consumed);
264245
+ }
264246
+ function resolveForwardParagraphByTblpY(blocks2, measures, len3, tableIndex, offsetV) {
264247
+ if (offsetV <= 0)
264248
+ return null;
264249
+ let remaining = offsetV;
264250
+ let index2 = findNextParagraphIndex(blocks2, tableIndex, len3);
264251
+ while (index2 != null) {
264252
+ if (blocks2[index2].kind !== "paragraph") {
264253
+ index2 = findNextParagraphIndex(blocks2, index2, len3);
264254
+ continue;
264255
+ }
264256
+ const height = paragraphMeasureHeight(measures, index2);
264257
+ if (height <= 0) {
264258
+ index2 = findNextParagraphIndex(blocks2, index2, len3);
264259
+ continue;
264260
+ }
264261
+ const lineHeight = paragraphFirstLineHeight(blocks2, measures, index2);
264262
+ if (remaining <= height + 1)
264263
+ return {
264264
+ paragraphIndex: index2,
264265
+ offsetV: lineHeight > 0 ? Math.min(remaining, lineHeight) : remaining,
264266
+ lineScopedOnAnchor: false
264267
+ };
264268
+ remaining -= height;
264269
+ const nextIndex = findNextParagraphIndex(blocks2, index2, len3);
264270
+ if (nextIndex == null && remaining > 0)
264271
+ return {
264272
+ paragraphIndex: index2,
264273
+ offsetV: lineHeight > 0 ? Math.min(remaining, lineHeight) : remaining,
264274
+ lineScopedOnAnchor: false
264275
+ };
264276
+ index2 = nextIndex;
264277
+ }
264278
+ return null;
264279
+ }
264280
+ function walkBackTblpYAnchor(blocks2, measures, startIndex, offsetV) {
264281
+ let candidate = startIndex;
264282
+ while (offsetV > 0) {
264283
+ if (offsetV <= paragraphMeasureHeight(measures, candidate) + 1)
264284
+ break;
264285
+ const earlierIndex = findPreviousParagraphIndex(blocks2, candidate);
264286
+ if (earlierIndex == null)
264287
+ break;
264288
+ candidate = earlierIndex;
264289
+ }
264290
+ return resolutionWithLineScopedFlag(blocks2, measures, candidate, offsetV, offsetV);
264291
+ }
264292
+ function getTableIndentPx(attrs) {
264293
+ const tableIndent = attrs?.tableIndent;
264294
+ return typeof tableIndent?.width === "number" && Number.isFinite(tableIndent.width) ? tableIndent.width : 0;
264295
+ }
264296
+ function horizontalWrapMargin(wrap4) {
264297
+ return (wrap4?.distLeft ?? 0) + (wrap4?.distRight ?? 0);
264298
+ }
264299
+ function measureRoundingSlack(columnCount) {
264300
+ return Math.max(1, columnCount) * 0.5;
264301
+ }
264302
+ function isAnchoredTableFullWidth(block, measure, columnWidth) {
264303
+ if (columnWidth <= 0)
264304
+ return false;
264305
+ const totalWidth = measure.totalWidth ?? 0;
264306
+ const indent2 = getTableIndentPx(block.attrs);
264307
+ const effectiveWidth = totalWidth + horizontalWrapMargin(block.wrap) + Math.max(0, -indent2);
264308
+ const slack = measureRoundingSlack(measure.columnWidths?.length ?? 1);
264309
+ const tblWidth = resolveTableWidthAttr(block.attrs?.tableWidth);
264310
+ if (tblWidth?.type === "pct" && tblWidth.width >= 5000 * 0.99)
264311
+ return true;
264312
+ return effectiveWidth + slack >= columnWidth * ANCHORED_TABLE_FULL_WIDTH_RATIO;
264313
+ }
264314
+ function resolveFloatingTableAnchorResolution(blocks2, measures, len3, tableIndex, tableBlock, paragraphIndexById) {
264315
+ const anchorParagraphId = typeof tableBlock.attrs === "object" && tableBlock.attrs ? tableBlock.attrs.anchorParagraphId : undefined;
264316
+ if (typeof anchorParagraphId === "string") {
264317
+ const explicitIndex = paragraphIndexById.get(anchorParagraphId);
264318
+ if (typeof explicitIndex === "number") {
264319
+ const offsetV$1 = tableBlock.anchor?.offsetV ?? 0;
264320
+ if ((tableBlock.anchor?.vRelativeFrom ?? "paragraph") !== "paragraph")
264321
+ return {
264322
+ paragraphIndex: explicitIndex,
264323
+ offsetV: offsetV$1,
264324
+ lineScopedOnAnchor: false
264325
+ };
264326
+ return resolutionWithLineScopedFlag(blocks2, measures, explicitIndex, offsetV$1, offsetV$1);
264327
+ }
264328
+ }
264329
+ if ((tableBlock.anchor?.vRelativeFrom ?? "paragraph") !== "paragraph") {
264330
+ const fallback = findNearestParagraphIndex$1(blocks2, len3, tableIndex);
264331
+ if (fallback == null)
264332
+ return null;
264333
+ return {
264334
+ paragraphIndex: fallback,
264335
+ offsetV: tableBlock.anchor?.offsetV ?? 0,
264336
+ lineScopedOnAnchor: false
264337
+ };
264338
+ }
264339
+ const offsetV = tableBlock.anchor?.offsetV ?? 0;
264340
+ const prevIndex = findPreviousParagraphIndex(blocks2, tableIndex);
264341
+ const nextIndex = findNextParagraphIndex(blocks2, tableIndex, len3);
264342
+ if (nextIndex != null && isLineScopedTblpY$1(blocks2, measures, nextIndex, offsetV)) {
264343
+ if (!isTextEmptyParagraph(blocks2, nextIndex) && (prevIndex == null || isTextEmptyParagraph(blocks2, prevIndex)))
264344
+ return resolutionWithLineScopedFlag(blocks2, measures, nextIndex, offsetV, offsetV);
264345
+ if (isCompactOptionLineAfterBody(blocks2, measures, nextIndex, prevIndex))
264346
+ return resolutionWithLineScopedFlag(blocks2, measures, nextIndex, offsetV, offsetV);
264347
+ }
264348
+ if (!isLineScopedTblpY$1(blocks2, measures, prevIndex ?? nextIndex ?? tableIndex, offsetV)) {
264349
+ const forwardCompact = findForwardCompactOptionLine(blocks2, measures, len3, tableIndex);
264350
+ if (forwardCompact != null)
264351
+ return {
264352
+ paragraphIndex: forwardCompact,
264353
+ offsetV: paintOffsetThroughAnchorParagraphs(blocks2, measures, len3, tableIndex, forwardCompact, offsetV),
264354
+ lineScopedOnAnchor: false
264355
+ };
264356
+ const forward = resolveForwardParagraphByTblpY(blocks2, measures, len3, tableIndex, offsetV);
264357
+ if (forward != null)
264358
+ return forward;
264359
+ }
264360
+ const startIndex = prevIndex ?? nextIndex;
264361
+ if (startIndex == null)
264362
+ return null;
264363
+ return walkBackTblpYAnchor(blocks2, measures, startIndex, offsetV);
264364
+ }
264613
264365
  function getTableIndentWidth(attrs) {
264614
264366
  if (!attrs)
264615
264367
  return 0;
@@ -265128,13 +264880,12 @@ function layoutMonolithicTable(context) {
265128
264880
  function layoutTableBlock({ block, measure, columnWidth, ensurePage, advanceColumn, columnX }) {
265129
264881
  let treatAsInline = false;
265130
264882
  if (block.anchor?.isAnchored) {
265131
- const totalWidth = measure.totalWidth ?? 0;
265132
- treatAsInline = columnWidth > 0 && totalWidth >= columnWidth * 0.99;
264883
+ treatAsInline = isAnchoredTableFullWidth(block, measure, columnWidth);
265133
264884
  if (!treatAsInline)
265134
264885
  return;
265135
264886
  }
265136
264887
  const floatingProps = block.attrs?.tableProperties?.floatingTableProperties;
265137
- if (floatingProps && Object.keys(floatingProps).length > 0) {
264888
+ if (floatingProps && Object.keys(floatingProps).length > 0 && !treatAsInline) {
265138
264889
  layoutMonolithicTable({
265139
264890
  block,
265140
264891
  measure,
@@ -265394,6 +265145,670 @@ function createAnchoredTableFragment(block, measure, x, y$1) {
265394
265145
  applyTableFragmentPmRange(fragment, block, measure);
265395
265146
  return fragment;
265396
265147
  }
265148
+ function isLineScopedTblpY(firstLineHeight, offsetV) {
265149
+ if (firstLineHeight <= 0)
265150
+ return offsetV <= 1;
265151
+ return offsetV <= firstLineHeight * 1.5;
265152
+ }
265153
+ function anchorForLineScopedFormField(anchor, tableHeight, firstLineHeight, layoutOffsetV, lineScopedOnAnchor = false, wrapType = "None") {
265154
+ if (!anchor)
265155
+ return anchor;
265156
+ if ((anchor.vRelativeFrom ?? "paragraph") !== "paragraph")
265157
+ return anchor;
265158
+ if (wrapType !== "None")
265159
+ return anchor;
265160
+ if (!lineScopedOnAnchor)
265161
+ return anchor;
265162
+ const offsetV = layoutOffsetV ?? anchor.offsetV ?? 0;
265163
+ if (anchor.alignV || firstLineHeight <= 0 || tableHeight <= firstLineHeight)
265164
+ return anchor;
265165
+ if (!isLineScopedTblpY(firstLineHeight, offsetV))
265166
+ return anchor;
265167
+ return {
265168
+ ...anchor,
265169
+ vRelativeFrom: "paragraph",
265170
+ alignV: "center",
265171
+ offsetV: 0
265172
+ };
265173
+ }
265174
+ function graphicAnchorY(anchor) {
265175
+ if (!anchor)
265176
+ return;
265177
+ const alignV = anchor.alignV;
265178
+ const mappedAlignV = alignV === "top" || alignV === "center" || alignV === "bottom" ? alignV : undefined;
265179
+ return {
265180
+ vRelativeFrom: anchor.vRelativeFrom,
265181
+ alignV: mappedAlignV,
265182
+ offsetV: anchor.offsetV
265183
+ };
265184
+ }
265185
+ function graphicAnchorH(anchor) {
265186
+ const alignH = anchor.alignH;
265187
+ const mappedAlignH = alignH === "left" || alignH === "center" || alignH === "right" ? alignH : undefined;
265188
+ return {
265189
+ hRelativeFrom: anchor.hRelativeFrom,
265190
+ alignH: mappedAlignH,
265191
+ offsetH: anchor.offsetH
265192
+ };
265193
+ }
265194
+ function calculateFirstLineIndent(block, measure) {
265195
+ const wordLayout = block.attrs?.wordLayout;
265196
+ if (!wordLayout?.firstLineIndentMode)
265197
+ return 0;
265198
+ if (!wordLayout.marker || !measure.marker)
265199
+ return 0;
265200
+ const markerWidthRaw = measure.marker.markerWidth ?? wordLayout.marker.markerBoxWidthPx ?? 0;
265201
+ const markerWidth = Number.isFinite(markerWidthRaw) && markerWidthRaw >= 0 ? markerWidthRaw : 0;
265202
+ const gutterWidthRaw = measure.marker.gutterWidth ?? 0;
265203
+ return markerWidth + (Number.isFinite(gutterWidthRaw) && gutterWidthRaw >= 0 ? gutterWidthRaw : 0);
265204
+ }
265205
+ function layoutParagraphBlock(ctx$1, anchors) {
265206
+ const { block, measure, columnWidth, ensurePage, advanceColumn, columnX, floatManager } = ctx$1;
265207
+ const remeasureParagraph$1 = ctx$1.remeasureParagraph;
265208
+ const frame = getParagraphAttrs(block)?.frame;
265209
+ let lines = normalizeLines(measure);
265210
+ const measurementWidth = lines[0]?.maxWidth;
265211
+ const paraIndent = block.attrs?.indent;
265212
+ const indentLeft = typeof paraIndent?.left === "number" && Number.isFinite(paraIndent.left) ? paraIndent.left : 0;
265213
+ const indentRight = typeof paraIndent?.right === "number" && Number.isFinite(paraIndent.right) ? paraIndent.right : 0;
265214
+ const negativeLeftIndent = indentLeft < 0 ? indentLeft : 0;
265215
+ const negativeRightIndent = indentRight < 0 ? indentRight : 0;
265216
+ const remeasureWidth = Math.max(1, columnWidth - indentLeft - indentRight);
265217
+ let didRemeasureForColumnWidth = false;
265218
+ let remeasuredMarkerInfo;
265219
+ if (typeof remeasureParagraph$1 === "function" && typeof measurementWidth === "number" && measurementWidth > remeasureWidth) {
265220
+ const newMeasure = remeasureParagraph$1(block, columnWidth, calculateFirstLineIndent(block, measure));
265221
+ lines = normalizeLines(newMeasure);
265222
+ didRemeasureForColumnWidth = true;
265223
+ if (newMeasure.marker)
265224
+ remeasuredMarkerInfo = newMeasure.marker;
265225
+ }
265226
+ let fromLine = 0;
265227
+ const attrs = getParagraphAttrs(block);
265228
+ const spacing = attrs?.spacing ?? {};
265229
+ const spacingExplicit = attrs?.spacingExplicit;
265230
+ const styleId$1 = asString2(attrs?.styleId);
265231
+ const contextualSpacing = asBoolean$1(attrs?.contextualSpacing);
265232
+ let spacingBefore = Math.max(0, Number(spacing.before ?? spacing.lineSpaceBefore ?? 0));
265233
+ let spacingAfter = ctx$1.overrideSpacingAfter ?? Math.max(0, Number(spacing.after ?? spacing.lineSpaceAfter ?? 0));
265234
+ const emptyTextParagraph = isEmptyTextParagraph(block);
265235
+ if (emptyTextParagraph && spacingExplicit) {
265236
+ if (!spacingExplicit.before)
265237
+ spacingBefore = 0;
265238
+ if (!spacingExplicit.after)
265239
+ spacingAfter = 0;
265240
+ }
265241
+ const baseSpacingBefore = spacingBefore;
265242
+ let appliedSpacingBefore = spacingBefore === 0;
265243
+ let lastState = null;
265244
+ const previewState = ensurePage();
265245
+ const rawBorderExpansion = computeBorderVerticalExpansion(attrs?.borders);
265246
+ const currentBorderHash = hashBorders(attrs?.borders);
265247
+ const inBorderGroup = currentBorderHash != null && currentBorderHash === previewState.lastParagraphBorderHash;
265248
+ const borderExpansion = {
265249
+ top: inBorderGroup ? 0 : rawBorderExpansion.top,
265250
+ bottom: rawBorderExpansion.bottom
265251
+ };
265252
+ const paragraphAnchorBaseY = computeParagraphLayoutStartY({
265253
+ cursorY: previewState.cursorY,
265254
+ spacingBefore,
265255
+ trailingSpacing: previewState.trailingSpacing,
265256
+ suppressSpacingBefore: shouldSuppressOwnSpacing(styleId$1, contextualSpacing, previewState.lastParagraphStyleId),
265257
+ rewindTrailingFromPrevious: shouldSuppressOwnSpacing(previewState.lastParagraphStyleId, previewState.lastParagraphContextualSpacing, styleId$1)
265258
+ }) + borderExpansion.top - (inBorderGroup ? rawBorderExpansion.bottom : 0);
265259
+ let paragraphContentEndY = paragraphAnchorBaseY;
265260
+ const registerAnchoredDrawingsAt = (paragraphContentStartY) => {
265261
+ if (!anchors?.anchoredDrawings?.length)
265262
+ return;
265263
+ for (const entry of anchors.anchoredDrawings) {
265264
+ if (anchors.placedAnchoredIds.has(entry.block.id))
265265
+ continue;
265266
+ const state = ensurePage();
265267
+ const contentTop = state.topMargin;
265268
+ const contentBottom = state.contentBottom;
265269
+ const anchorY = resolveAnchoredGraphicY({
265270
+ anchor: entry.block.anchor,
265271
+ objectHeight: entry.measure.height,
265272
+ contentTop,
265273
+ contentBottom,
265274
+ pageBottomMargin: anchors.pageMargins.bottom ?? 0,
265275
+ anchorParagraphY: paragraphContentStartY,
265276
+ firstLineHeight: measure.lines?.[0]?.lineHeight ?? 0
265277
+ });
265278
+ floatManager.registerDrawing(entry.block, entry.measure, anchorY, state.columnIndex, state.page.number);
265279
+ const anchorX = entry.block.anchor ? resolveAnchoredGraphicX(entry.block.anchor, state.columnIndex, anchors.columns, entry.measure.width, {
265280
+ left: anchors.pageMargins.left,
265281
+ right: anchors.pageMargins.right
265282
+ }, anchors.pageWidth) : columnX(state);
265283
+ const pmRange = extractBlockPmRange(entry.block);
265284
+ if (entry.block.kind === "image" && entry.measure.kind === "image") {
265285
+ const pageContentHeight = Math.max(0, state.contentBottom - state.topMargin);
265286
+ const relativeFrom = entry.block.anchor?.hRelativeFrom ?? "column";
265287
+ const marginLeft = anchors.pageMargins.left ?? 0;
265288
+ const marginRight = anchors.pageMargins.right ?? 0;
265289
+ let maxWidth;
265290
+ if (relativeFrom === "page")
265291
+ maxWidth = anchors.columns.count === 1 ? anchors.pageWidth - marginLeft - marginRight : anchors.pageWidth;
265292
+ else if (relativeFrom === "margin")
265293
+ maxWidth = anchors.pageWidth - marginLeft - marginRight;
265294
+ else
265295
+ maxWidth = anchors.columns.width;
265296
+ const aspectRatio = entry.measure.width > 0 && entry.measure.height > 0 ? entry.measure.width / entry.measure.height : 1;
265297
+ const minWidth = 20;
265298
+ const minHeight = minWidth / aspectRatio;
265299
+ const metadata = {
265300
+ originalWidth: entry.measure.width,
265301
+ originalHeight: entry.measure.height,
265302
+ maxWidth,
265303
+ maxHeight: pageContentHeight,
265304
+ aspectRatio,
265305
+ minWidth,
265306
+ minHeight
265307
+ };
265308
+ const fragment = {
265309
+ kind: "image",
265310
+ blockId: entry.block.id,
265311
+ x: anchorX,
265312
+ y: anchorY,
265313
+ width: entry.measure.width,
265314
+ height: entry.measure.height,
265315
+ isAnchored: true,
265316
+ behindDoc: entry.block.anchor?.behindDoc === true,
265317
+ zIndex: getFragmentZIndex(entry.block),
265318
+ metadata,
265319
+ sourceAnchor: entry.block.sourceAnchor
265320
+ };
265321
+ if (pmRange.pmStart != null)
265322
+ fragment.pmStart = pmRange.pmStart;
265323
+ if (pmRange.pmEnd != null)
265324
+ fragment.pmEnd = pmRange.pmEnd;
265325
+ state.page.fragments.push(fragment);
265326
+ } else if (entry.block.kind === "drawing" && entry.measure.kind === "drawing") {
265327
+ const fragment = {
265328
+ kind: "drawing",
265329
+ blockId: entry.block.id,
265330
+ drawingKind: entry.block.drawingKind,
265331
+ x: anchorX,
265332
+ y: anchorY,
265333
+ width: entry.measure.width,
265334
+ height: entry.measure.height,
265335
+ geometry: entry.measure.geometry,
265336
+ scale: entry.measure.scale,
265337
+ isAnchored: true,
265338
+ behindDoc: entry.block.anchor?.behindDoc === true,
265339
+ zIndex: getFragmentZIndex(entry.block),
265340
+ drawingContentId: entry.block.drawingContentId,
265341
+ sourceAnchor: entry.block.sourceAnchor
265342
+ };
265343
+ if (pmRange.pmStart != null)
265344
+ fragment.pmStart = pmRange.pmStart;
265345
+ if (pmRange.pmEnd != null)
265346
+ fragment.pmEnd = pmRange.pmEnd;
265347
+ state.page.fragments.push(fragment);
265348
+ }
265349
+ anchors.placedAnchoredIds.add(entry.block.id);
265350
+ }
265351
+ };
265352
+ registerAnchoredDrawingsAt(paragraphAnchorBaseY);
265353
+ const registerAnchoredTablesAt = (paragraphContentStartY, entries) => {
265354
+ if (!entries.length)
265355
+ return;
265356
+ const columnWidthForTable = anchors.columnWidth;
265357
+ let nextStackY = paragraphContentStartY;
265358
+ for (const entry of entries) {
265359
+ if (anchors.placedAnchoredIds.has(entry.block.id))
265360
+ continue;
265361
+ const totalWidth = entry.measure.totalWidth ?? 0;
265362
+ if (isAnchoredTableFullWidth(entry.block, entry.measure, columnWidthForTable))
265363
+ continue;
265364
+ const state = ensurePage();
265365
+ const contentTop = state.topMargin;
265366
+ const contentBottom = state.contentBottom;
265367
+ const layoutOffsetV = entry.layoutOffsetV;
265368
+ const firstLineHeight = measure.lines?.[0]?.lineHeight ?? 0;
265369
+ const wrapType = entry.block.wrap?.type ?? "None";
265370
+ const anchorY = resolveAnchoredGraphicY({
265371
+ anchor: graphicAnchorY(anchorForLineScopedFormField(layoutOffsetV != null && entry.block.anchor ? {
265372
+ ...entry.block.anchor,
265373
+ offsetV: layoutOffsetV
265374
+ } : entry.block.anchor, entry.measure.totalHeight ?? 0, firstLineHeight, layoutOffsetV, entry.lineScopedOnAnchor === true, wrapType)),
265375
+ objectHeight: entry.measure.totalHeight ?? 0,
265376
+ contentTop,
265377
+ contentBottom,
265378
+ pageBottomMargin: anchors.pageMargins.bottom ?? 0,
265379
+ anchorParagraphY: nextStackY,
265380
+ firstLineHeight: measure.lines?.[0]?.lineHeight ?? 0
265381
+ });
265382
+ floatManager.registerTable(entry.block, entry.measure, anchorY, state.columnIndex, state.page.number);
265383
+ const anchorX = entry.block.anchor ? resolveAnchoredGraphicX(graphicAnchorH(entry.block.anchor), state.columnIndex, anchors.columns, totalWidth, {
265384
+ left: anchors.pageMargins.left,
265385
+ right: anchors.pageMargins.right
265386
+ }, anchors.pageWidth) : columnX(state);
265387
+ state.page.fragments.push(createAnchoredTableFragment(entry.block, entry.measure, anchorX, anchorY));
265388
+ anchors.placedAnchoredIds.add(entry.block.id);
265389
+ if (wrapType !== "None") {
265390
+ const bottom$1 = anchorY + (entry.measure.totalHeight ?? 0);
265391
+ const distBottom = entry.block.wrap?.distBottom ?? 0;
265392
+ nextStackY = Math.max(nextStackY, bottom$1 + distBottom);
265393
+ }
265394
+ }
265395
+ };
265396
+ const anchoredTablesForPara = anchors?.anchoredTables ?? [];
265397
+ const totalLineHeight = lines.reduce((sum, line) => sum + (line.lineHeight ?? 0), 0);
265398
+ const remainingHeightOnStartPage = previewState.contentBottom - paragraphAnchorBaseY;
265399
+ const paragraphWillSpanPages = lines.length > 1 && totalLineHeight > remainingHeightOnStartPage;
265400
+ const shouldPreLayoutSquareTable = (entry) => entry.lineScopedOnAnchor === true && !paragraphWillSpanPages;
265401
+ registerAnchoredTablesAt(paragraphAnchorBaseY, anchoredTablesForPara.filter((entry) => {
265402
+ if ((entry.block.wrap?.type ?? "None") === "None")
265403
+ return true;
265404
+ return shouldPreLayoutSquareTable(entry);
265405
+ }));
265406
+ if (frame?.wrap === "none") {
265407
+ let state = ensurePage();
265408
+ if (state.cursorY >= state.contentBottom)
265409
+ state = advanceColumn(state);
265410
+ const fragmentWidth = lines.reduce((max$2, line) => Math.max(max$2, line.width ?? 0), 0) || columnWidth;
265411
+ let x = columnX(state);
265412
+ if (frame.xAlign === "right")
265413
+ x += columnWidth - fragmentWidth;
265414
+ else if (frame.xAlign === "center")
265415
+ x += (columnWidth - fragmentWidth) / 2;
265416
+ if (typeof frame.x === "number" && Number.isFinite(frame.x))
265417
+ x += frame.x;
265418
+ const yOffset = typeof frame.y === "number" && Number.isFinite(frame.y) ? frame.y : 0;
265419
+ const fragment = {
265420
+ kind: "para",
265421
+ blockId: block.id,
265422
+ fromLine: 0,
265423
+ toLine: lines.length,
265424
+ x,
265425
+ y: state.cursorY + yOffset,
265426
+ width: fragmentWidth,
265427
+ sourceAnchor: block.sourceAnchor,
265428
+ ...computeFragmentPmRange2(block, lines, 0, lines.length)
265429
+ };
265430
+ if (measure.marker || remeasuredMarkerInfo) {
265431
+ fragment.markerWidth = (remeasuredMarkerInfo ?? measure.marker)?.markerWidth ?? measure.marker?.markerWidth ?? 0;
265432
+ const markerTextWidth = remeasuredMarkerInfo?.markerTextWidth ?? measure.marker?.markerTextWidth;
265433
+ if (markerTextWidth != null)
265434
+ fragment.markerTextWidth = markerTextWidth;
265435
+ }
265436
+ state.page.fragments.push(fragment);
265437
+ state.trailingSpacing = 0;
265438
+ state.lastParagraphStyleId = styleId$1;
265439
+ state.lastParagraphContextualSpacing = contextualSpacing;
265440
+ return;
265441
+ }
265442
+ let narrowestWidth = columnWidth;
265443
+ let narrowestOffsetX = 0;
265444
+ let didRemeasureForFloats = false;
265445
+ if (typeof remeasureParagraph$1 === "function") {
265446
+ const tempState = ensurePage();
265447
+ let tempY = paragraphAnchorBaseY;
265448
+ for (let i4 = 0;i4 < lines.length; i4++) {
265449
+ const lineY = tempY;
265450
+ const lineHeight = lines[i4]?.lineHeight || 0;
265451
+ const { width: availableWidth, offsetX: computedOffset } = floatManager.computeAvailableWidth(lineY, lineHeight, columnWidth, tempState.columnIndex, tempState.page.number);
265452
+ if (availableWidth < narrowestWidth) {
265453
+ narrowestWidth = availableWidth;
265454
+ narrowestOffsetX = computedOffset;
265455
+ }
265456
+ tempY += lineHeight;
265457
+ }
265458
+ const narrowestRemeasureWidth = narrowestWidth < columnWidth || narrowestOffsetX > 0 ? Math.max(1, narrowestWidth - Math.max(indentLeft, 0) - Math.max(indentRight, 0)) : Math.max(1, narrowestWidth - indentLeft - indentRight);
265459
+ if (narrowestRemeasureWidth < remeasureWidth || narrowestOffsetX > 0) {
265460
+ const newMeasure = remeasureParagraph$1(block, narrowestRemeasureWidth, calculateFirstLineIndent(block, measure));
265461
+ lines = normalizeLines(newMeasure);
265462
+ didRemeasureForFloats = true;
265463
+ if (newMeasure.marker)
265464
+ remeasuredMarkerInfo = newMeasure.marker;
265465
+ }
265466
+ }
265467
+ while (fromLine < lines.length) {
265468
+ let state = ensurePage();
265469
+ if (state.trailingSpacing == null)
265470
+ state.trailingSpacing = 0;
265471
+ if (inBorderGroup && fromLine === 0)
265472
+ state.cursorY -= rawBorderExpansion.bottom;
265473
+ if (shouldSuppressOwnSpacing(styleId$1, contextualSpacing, state.lastParagraphStyleId))
265474
+ spacingBefore = 0;
265475
+ if (shouldSuppressOwnSpacing(state.lastParagraphStyleId, state.lastParagraphContextualSpacing, styleId$1)) {
265476
+ const prevTrailing = asSafeNumber(state.trailingSpacing);
265477
+ if (prevTrailing > 0) {
265478
+ state.cursorY = rewindPreviousParagraphTrailing(state.cursorY, prevTrailing);
265479
+ state.trailingSpacing = 0;
265480
+ }
265481
+ }
265482
+ if (attrs?.keepLines === true && fromLine === 0) {
265483
+ const neededSpacingBefore = collapseSpacingBefore(spacingBefore, state.trailingSpacing);
265484
+ const pageContentHeight = state.contentBottom - state.topMargin;
265485
+ const fullHeight = lines.reduce((sum, line) => sum + (line.lineHeight || 0), 0) + borderExpansion.top + borderExpansion.bottom;
265486
+ const fitsOnBlankPage = fullHeight + baseSpacingBefore <= pageContentHeight;
265487
+ const remainingHeightAfterSpacing = state.contentBottom - (state.cursorY + neededSpacingBefore);
265488
+ if (fitsOnBlankPage && state.page.fragments.length > 0 && fullHeight > remainingHeightAfterSpacing) {
265489
+ state = advanceColumn(state);
265490
+ spacingBefore = baseSpacingBefore;
265491
+ appliedSpacingBefore = spacingBefore === 0;
265492
+ continue;
265493
+ }
265494
+ }
265495
+ if (!appliedSpacingBefore && spacingBefore > 0)
265496
+ while (!appliedSpacingBefore) {
265497
+ state.trailingSpacing;
265498
+ const neededSpacingBefore = collapseSpacingBefore(spacingBefore, state.trailingSpacing);
265499
+ if (state.cursorY + neededSpacingBefore > state.contentBottom) {
265500
+ if (state.cursorY <= state.topMargin) {
265501
+ state.trailingSpacing = 0;
265502
+ appliedSpacingBefore = true;
265503
+ break;
265504
+ }
265505
+ state = advanceColumn(state);
265506
+ if (state.trailingSpacing == null)
265507
+ state.trailingSpacing = 0;
265508
+ continue;
265509
+ }
265510
+ if (neededSpacingBefore > 0) {
265511
+ state.cursorY += neededSpacingBefore;
265512
+ state.maxCursorY = Math.max(state.maxCursorY, state.cursorY);
265513
+ }
265514
+ state.trailingSpacing = 0;
265515
+ appliedSpacingBefore = true;
265516
+ }
265517
+ else
265518
+ state.trailingSpacing = 0;
265519
+ const FN_SAFETY_MARGIN_PX = 1;
265520
+ const fallbackBandOverhead = (refsTotal) => refsTotal > 0 ? 22 + Math.max(0, refsTotal - 1) * 2 : 0;
265521
+ const bandOverhead = (refsTotal) => {
265522
+ if (refsTotal <= 0)
265523
+ return 0;
265524
+ const fromCtx = ctx$1.getFootnoteBandOverhead?.(refsTotal);
265525
+ return (typeof fromCtx === "number" && Number.isFinite(fromCtx) && fromCtx >= 0 ? fromCtx : fallbackBandOverhead(refsTotal)) + FN_SAFETY_MARGIN_PX;
265526
+ };
265527
+ const rawContentBottom = state.contentBottom + state.pageFootnoteReserve;
265528
+ const computeEffectiveBottom = (extraDemand, extraRefs) => {
265529
+ const totalDemand = extraDemand;
265530
+ const totalRefs = state.footnoteRefsThisPage + extraRefs;
265531
+ const demandWithOverhead = totalDemand > 0 ? totalDemand + bandOverhead(totalRefs) : 0;
265532
+ const reservedSpace = Math.max(state.pageFootnoteReserve, demandWithOverhead);
265533
+ const minBodyLineHeight = lines[fromLine]?.lineHeight ?? 0;
265534
+ const maxAdditional = Math.max(0, rawContentBottom - state.topMargin - minBodyLineHeight);
265535
+ return rawContentBottom - Math.min(reservedSpace, maxAdditional);
265536
+ };
265537
+ const computeFootnoteClusterDemand = (pmStart, pmEnd) => {
265538
+ const candidate = ctx$1.getFootnoteAnchorsForBlockId ? ctx$1.getFootnoteAnchorsForBlockId(block.id, pmStart, pmEnd) : [];
265539
+ const committed = state.footnoteAnchorsThisPage ?? [];
265540
+ if (candidate.length === 0 && committed.length === 0)
265541
+ return 0;
265542
+ let demand = 0;
265543
+ for (const anchor of committed)
265544
+ demand += anchor.fullHeight;
265545
+ for (const anchor of candidate)
265546
+ demand += anchor.fullHeight;
265547
+ return demand;
265548
+ };
265549
+ const previewRange = computeFragmentPmRange2(block, lines, fromLine, fromLine + 1);
265550
+ const previewRefs = ctx$1.getFootnoteRefCountForBlockId ? ctx$1.getFootnoteRefCountForBlockId(block.id, previewRange.pmStart, previewRange.pmEnd) : 0;
265551
+ const computePreviewBottom = () => {
265552
+ return computeEffectiveBottom(computeFootnoteClusterDemand(previewRange.pmStart ?? 0, previewRange.pmEnd ?? 0), previewRefs);
265553
+ };
265554
+ let effectiveBottom = computePreviewBottom();
265555
+ if (state.cursorY >= effectiveBottom) {
265556
+ state = advanceColumn(state);
265557
+ effectiveBottom = computePreviewBottom();
265558
+ }
265559
+ if (effectiveBottom - state.cursorY <= 0) {
265560
+ state = advanceColumn(state);
265561
+ effectiveBottom = computePreviewBottom();
265562
+ }
265563
+ const nextLineHeight = lines[fromLine].lineHeight || 0;
265564
+ const remainingHeight = effectiveBottom - state.cursorY;
265565
+ if (state.page.fragments.length > 0 && remainingHeight < nextLineHeight) {
265566
+ state = advanceColumn(state);
265567
+ effectiveBottom = computePreviewBottom();
265568
+ }
265569
+ let effectiveColumnWidth = columnWidth;
265570
+ let offsetX = 0;
265571
+ if (didRemeasureForFloats) {
265572
+ effectiveColumnWidth = narrowestWidth;
265573
+ offsetX = narrowestOffsetX;
265574
+ }
265575
+ const borderVertical = borderExpansion.top + borderExpansion.bottom;
265576
+ let toLine = fromLine;
265577
+ let height = 0;
265578
+ let sliceDemand = 0;
265579
+ let sliceRefs = 0;
265580
+ while (toLine < lines.length) {
265581
+ const lineHeight = lines[toLine].lineHeight || 0;
265582
+ const range = computeFragmentPmRange2(block, lines, fromLine, toLine + 1);
265583
+ const orderedDemand = computeFootnoteClusterDemand(range.pmStart ?? 0, range.pmEnd ?? 0);
265584
+ const nextRefs = ctx$1.getFootnoteRefCountForBlockId ? ctx$1.getFootnoteRefCountForBlockId(block.id, range.pmStart, range.pmEnd) : 0;
265585
+ if (toLine === fromLine) {
265586
+ height = lineHeight;
265587
+ sliceDemand = orderedDemand;
265588
+ sliceRefs = nextRefs;
265589
+ toLine = fromLine + 1;
265590
+ continue;
265591
+ }
265592
+ if (state.cursorY + height + lineHeight + borderVertical > computeEffectiveBottom(orderedDemand, nextRefs))
265593
+ break;
265594
+ height += lineHeight;
265595
+ sliceDemand = orderedDemand;
265596
+ sliceRefs = nextRefs;
265597
+ toLine += 1;
265598
+ }
265599
+ const slice2 = {
265600
+ toLine,
265601
+ height
265602
+ };
265603
+ const fragmentHeight = slice2.height;
265604
+ if (sliceDemand > 0 || sliceRefs > 0) {
265605
+ state.footnoteDemandThisPage = sliceDemand;
265606
+ state.footnoteRefsThisPage = (state.footnoteRefsThisPage ?? 0) + sliceRefs;
265607
+ }
265608
+ if (ctx$1.getFootnoteAnchorsForBlockId) {
265609
+ const committedRange = computeFragmentPmRange2(block, lines, fromLine, toLine);
265610
+ const newAnchors = ctx$1.getFootnoteAnchorsForBlockId(block.id, committedRange.pmStart, committedRange.pmEnd);
265611
+ if (newAnchors.length > 0) {
265612
+ if (!state.footnoteAnchorsThisPage)
265613
+ state.footnoteAnchorsThisPage = [];
265614
+ const seen = new Set(state.footnoteAnchorsThisPage.map((a2) => a2.refId));
265615
+ for (const a2 of newAnchors)
265616
+ if (!seen.has(a2.refId))
265617
+ state.footnoteAnchorsThisPage.push(a2);
265618
+ }
265619
+ }
265620
+ const floatAdjustedX = columnX(state) + offsetX;
265621
+ const adjustedX = didRemeasureForFloats ? floatAdjustedX + Math.max(negativeLeftIndent, 0) : floatAdjustedX + negativeLeftIndent;
265622
+ const columnRight = columnX(state) + columnWidth;
265623
+ let adjustedWidth = didRemeasureForFloats ? effectiveColumnWidth : effectiveColumnWidth - negativeLeftIndent - negativeRightIndent;
265624
+ if (didRemeasureForFloats)
265625
+ adjustedWidth = Math.min(adjustedWidth, Math.max(1, columnRight - adjustedX));
265626
+ const fragment = {
265627
+ kind: "para",
265628
+ blockId: block.id,
265629
+ fromLine,
265630
+ toLine: slice2.toLine,
265631
+ x: adjustedX,
265632
+ y: state.cursorY + borderExpansion.top,
265633
+ width: adjustedWidth,
265634
+ sourceAnchor: block.sourceAnchor,
265635
+ ...computeFragmentPmRange2(block, lines, fromLine, slice2.toLine)
265636
+ };
265637
+ if (didRemeasureForColumnWidth || didRemeasureForFloats)
265638
+ fragment.lines = lines.slice(fromLine, slice2.toLine);
265639
+ if ((measure.marker || remeasuredMarkerInfo) && fromLine === 0) {
265640
+ fragment.markerWidth = (remeasuredMarkerInfo ?? measure.marker)?.markerWidth ?? measure.marker?.markerWidth ?? 0;
265641
+ const markerTextWidth = remeasuredMarkerInfo?.markerTextWidth ?? measure.marker?.markerTextWidth;
265642
+ if (markerTextWidth != null)
265643
+ fragment.markerTextWidth = markerTextWidth;
265644
+ const gutterWidth = remeasuredMarkerInfo?.gutterWidth ?? measure.marker?.gutterWidth;
265645
+ if (gutterWidth != null)
265646
+ fragment.markerGutter = gutterWidth;
265647
+ }
265648
+ if (fromLine > 0)
265649
+ fragment.continuesFromPrev = true;
265650
+ if (slice2.toLine < lines.length)
265651
+ fragment.continuesOnNext = true;
265652
+ const floatAlignment = block.attrs?.floatAlignment;
265653
+ if (floatAlignment && (floatAlignment === "right" || floatAlignment === "center")) {
265654
+ let maxLineWidth = 0;
265655
+ for (let i4 = fromLine;i4 < slice2.toLine; i4++)
265656
+ if (lines[i4].width > maxLineWidth)
265657
+ maxLineWidth = lines[i4].width;
265658
+ if (floatAlignment === "right")
265659
+ fragment.x = columnX(state) + offsetX + (effectiveColumnWidth - maxLineWidth);
265660
+ else if (floatAlignment === "center")
265661
+ fragment.x = columnX(state) + offsetX + (effectiveColumnWidth - maxLineWidth) / 2;
265662
+ }
265663
+ state.page.fragments.push(fragment);
265664
+ state.cursorY += borderExpansion.top + fragmentHeight + borderExpansion.bottom;
265665
+ state.maxCursorY = Math.max(state.maxCursorY, state.cursorY);
265666
+ lastState = state;
265667
+ paragraphContentEndY = state.cursorY;
265668
+ fromLine = slice2.toLine;
265669
+ }
265670
+ if (lastState) {
265671
+ if (spacingAfter > 0) {
265672
+ let targetState = lastState;
265673
+ let appliedSpacingAfter = spacingAfter;
265674
+ if (targetState.cursorY + spacingAfter > targetState.contentBottom) {
265675
+ targetState = advanceColumn(targetState);
265676
+ appliedSpacingAfter = 0;
265677
+ } else {
265678
+ targetState.cursorY += spacingAfter;
265679
+ targetState.maxCursorY = Math.max(targetState.maxCursorY, targetState.cursorY);
265680
+ }
265681
+ targetState.trailingSpacing = appliedSpacingAfter;
265682
+ } else
265683
+ lastState.trailingSpacing = 0;
265684
+ lastState.lastParagraphStyleId = styleId$1;
265685
+ lastState.lastParagraphContextualSpacing = contextualSpacing;
265686
+ lastState.lastParagraphBorderHash = currentBorderHash;
265687
+ }
265688
+ const postLayoutAnchoredTables = anchoredTablesForPara.filter((entry) => {
265689
+ return (entry.block.wrap?.type ?? "None") !== "None" && !shouldPreLayoutSquareTable(entry);
265690
+ });
265691
+ if (postLayoutAnchoredTables.length > 0)
265692
+ registerAnchoredTablesAt(emptyTextParagraph && !paragraphWillSpanPages && postLayoutAnchoredTables.some((entry) => {
265693
+ const offsetV = entry.layoutOffsetV ?? entry.block.anchor?.offsetV ?? 0;
265694
+ return entry.lineScopedOnAnchor === false && offsetV > 0;
265695
+ }) ? paragraphAnchorBaseY : paragraphContentEndY, postLayoutAnchoredTables);
265696
+ }
265697
+ function layoutImageBlock({ block, measure, columns, ensurePage, advanceColumn, columnX }) {
265698
+ if (block.anchor?.isAnchored)
265699
+ return;
265700
+ const marginTop = Math.max(0, block.margin?.top ?? 0);
265701
+ const marginBottom = Math.max(0, block.margin?.bottom ?? 0);
265702
+ const marginLeft = Math.max(0, block.margin?.left ?? 0);
265703
+ const marginRight = Math.max(0, block.margin?.right ?? 0);
265704
+ const maxWidth = Math.max(0, columns.width - (marginLeft + marginRight));
265705
+ let width = measure.width;
265706
+ let height = measure.height;
265707
+ if (width > maxWidth && maxWidth > 0) {
265708
+ const scale = maxWidth / width;
265709
+ width = maxWidth;
265710
+ height *= scale;
265711
+ }
265712
+ let state = ensurePage();
265713
+ const pageContentHeight = Math.max(0, state.contentBottom - state.topMargin);
265714
+ if (height > pageContentHeight && pageContentHeight > 0) {
265715
+ const scale = pageContentHeight / height;
265716
+ height = pageContentHeight;
265717
+ width *= scale;
265718
+ }
265719
+ const requiredHeight = marginTop + height + marginBottom;
265720
+ if (state.cursorY + requiredHeight > state.contentBottom && state.cursorY > state.topMargin)
265721
+ state = advanceColumn(state);
265722
+ const pmRange = extractBlockPmRange(block);
265723
+ const aspectRatio = measure.width > 0 && measure.height > 0 ? measure.width / measure.height : 1;
265724
+ const minWidth = 20;
265725
+ const minHeight = minWidth / aspectRatio;
265726
+ const metadata = {
265727
+ originalWidth: measure.width,
265728
+ originalHeight: measure.height,
265729
+ maxWidth,
265730
+ maxHeight: pageContentHeight,
265731
+ aspectRatio,
265732
+ minWidth,
265733
+ minHeight
265734
+ };
265735
+ const fragment = {
265736
+ kind: "image",
265737
+ blockId: block.id,
265738
+ x: columnX(state) + marginLeft,
265739
+ y: state.cursorY + marginTop,
265740
+ width,
265741
+ height,
265742
+ pmStart: pmRange.pmStart,
265743
+ pmEnd: pmRange.pmEnd,
265744
+ metadata,
265745
+ sourceAnchor: block.sourceAnchor
265746
+ };
265747
+ state.page.fragments.push(fragment);
265748
+ state.cursorY += requiredHeight;
265749
+ state.maxCursorY = Math.max(state.maxCursorY, state.cursorY);
265750
+ }
265751
+ function layoutDrawingBlock({ block, measure, columns, ensurePage, advanceColumn, columnX }) {
265752
+ if (block.anchor?.isAnchored)
265753
+ return;
265754
+ const marginTop = Math.max(0, block.margin?.top ?? 0);
265755
+ const marginBottom = Math.max(0, block.margin?.bottom ?? 0);
265756
+ const marginLeft = Math.max(0, block.margin?.left ?? 0);
265757
+ const marginRight = Math.max(0, block.margin?.right ?? 0);
265758
+ const maxWidth = Math.max(0, columns.width - (marginLeft + marginRight));
265759
+ let width = measure.width;
265760
+ let height = measure.height;
265761
+ const attrs = block.attrs;
265762
+ const indentLeft = typeof attrs?.hrIndentLeft === "number" ? attrs.hrIndentLeft : 0;
265763
+ const indentRight = typeof attrs?.hrIndentRight === "number" ? attrs.hrIndentRight : 0;
265764
+ const maxWidthForBlock = attrs?.isFullWidth === true && maxWidth > 0 ? Math.max(1, maxWidth - indentLeft - indentRight) : maxWidth;
265765
+ const rawWrap = attrs?.wrap;
265766
+ const isInlineShapeGroup = block.drawingKind === "shapeGroup" && rawWrap?.type === "Inline";
265767
+ const inlineParagraphAlignment = attrs?.inlineParagraphAlignment === "center" || attrs?.inlineParagraphAlignment === "right" ? attrs.inlineParagraphAlignment : undefined;
265768
+ if (width > maxWidthForBlock && maxWidthForBlock > 0) {
265769
+ const scale = maxWidthForBlock / width;
265770
+ width = maxWidthForBlock;
265771
+ height *= scale;
265772
+ }
265773
+ let state = ensurePage();
265774
+ const pageContentHeight = Math.max(0, state.contentBottom - state.topMargin);
265775
+ if (height > pageContentHeight && pageContentHeight > 0) {
265776
+ const scale = pageContentHeight / height;
265777
+ height = pageContentHeight;
265778
+ width *= scale;
265779
+ }
265780
+ const requiredHeight = marginTop + height + marginBottom;
265781
+ if (state.cursorY + requiredHeight > state.contentBottom && state.cursorY > state.topMargin)
265782
+ state = advanceColumn(state);
265783
+ const pmRange = extractBlockPmRange(block);
265784
+ let x = columnX(state) + marginLeft + indentLeft;
265785
+ if (isInlineShapeGroup && inlineParagraphAlignment) {
265786
+ const pIndentLeft = typeof attrs?.paragraphIndentLeft === "number" ? attrs.paragraphIndentLeft : 0;
265787
+ const pIndentRight = typeof attrs?.paragraphIndentRight === "number" ? attrs.paragraphIndentRight : 0;
265788
+ const alignBox = Math.max(0, maxWidthForBlock - pIndentLeft - pIndentRight);
265789
+ const extra = Math.max(0, alignBox - width);
265790
+ x += pIndentLeft + (inlineParagraphAlignment === "center" ? extra / 2 : extra);
265791
+ }
265792
+ const fragment = {
265793
+ kind: "drawing",
265794
+ blockId: block.id,
265795
+ drawingKind: block.drawingKind,
265796
+ x,
265797
+ y: state.cursorY + marginTop,
265798
+ width,
265799
+ height,
265800
+ geometry: measure.geometry,
265801
+ scale: measure.scale,
265802
+ drawingContentId: block.drawingContentId,
265803
+ zIndex: getFragmentZIndex(block),
265804
+ pmStart: pmRange.pmStart,
265805
+ pmEnd: pmRange.pmEnd,
265806
+ sourceAnchor: block.sourceAnchor
265807
+ };
265808
+ state.page.fragments.push(fragment);
265809
+ state.cursorY += requiredHeight;
265810
+ state.maxCursorY = Math.max(state.maxCursorY, state.cursorY);
265811
+ }
265397
265812
  function buildParagraphIndexById(blocks2, len3) {
265398
265813
  const paragraphIndexById = /* @__PURE__ */ new Map;
265399
265814
  for (let i4 = 0;i4 < len3; i4 += 1) {
@@ -265490,21 +265905,22 @@ function collectAnchoredTables(blocks2, measures) {
265490
265905
  const tableMeasure = measure;
265491
265906
  if (!tableBlock.anchor?.isAnchored)
265492
265907
  continue;
265493
- const anchorParagraphId = typeof tableBlock.attrs === "object" && tableBlock.attrs ? tableBlock.attrs.anchorParagraphId : undefined;
265494
- const anchorParaIndex = resolveAnchorParagraphIndex(blocks2, len3, paragraphIndexById, i4, anchorParagraphId);
265495
- if (anchorParaIndex == null) {
265908
+ const resolution = resolveFloatingTableAnchorResolution(blocks2, measures, len3, i4, tableBlock, paragraphIndexById);
265909
+ if (resolution == null) {
265496
265910
  withoutParagraph.push({
265497
265911
  block: tableBlock,
265498
265912
  measure: tableMeasure
265499
265913
  });
265500
265914
  continue;
265501
265915
  }
265502
- const list5 = byParagraph.get(anchorParaIndex) ?? [];
265916
+ const list5 = byParagraph.get(resolution.paragraphIndex) ?? [];
265503
265917
  list5.push({
265504
265918
  block: tableBlock,
265505
- measure: tableMeasure
265919
+ measure: tableMeasure,
265920
+ layoutOffsetV: resolution.offsetV,
265921
+ lineScopedOnAnchor: resolution.lineScopedOnAnchor
265506
265922
  });
265507
- byParagraph.set(anchorParaIndex, list5);
265923
+ byParagraph.set(resolution.paragraphIndex, list5);
265508
265924
  }
265509
265925
  return {
265510
265926
  byParagraph,
@@ -266098,7 +266514,14 @@ function balanceSectionOnPage(args$1) {
266098
266514
  availableHeight: remainingHeight,
266099
266515
  contentBlocks
266100
266516
  }, DEFAULT_BALANCING_CONFIG);
266101
- const columnX = (columnIndex) => args$1.margins.left + columnIndex * (columnWidth + columnGap);
266517
+ const balancedGeometry = getColumnGeometry({
266518
+ count: columnCount,
266519
+ gap: columnGap,
266520
+ width: columnWidth,
266521
+ ...Array.isArray(sectionColumns.widths) ? { widths: sectionColumns.widths } : {},
266522
+ ...Array.isArray(sectionColumns.gaps) ? { gaps: sectionColumns.gaps } : {}
266523
+ });
266524
+ const columnX = (columnIndex) => getColumnX(balancedGeometry, columnIndex, args$1.margins.left);
266102
266525
  const colCursors = new Array(columnCount).fill(sectionTopY);
266103
266526
  let maxY = sectionTopY;
266104
266527
  for (let i4 = 0;i4 < ordered.length; i4++) {
@@ -267298,7 +267721,6 @@ function layoutDocument(blocks2, measures, options = {}) {
267298
267721
  const anchoredTablesByParagraph = anchoredTables.byParagraph;
267299
267722
  const paragraphlessAnchoredTables = anchoredTables.withoutParagraph;
267300
267723
  const placedAnchoredIds = /* @__PURE__ */ new Set;
267301
- const placedAnchoredTableIds = /* @__PURE__ */ new Set;
267302
267724
  const preRegisteredAnchors = collectPreRegisteredAnchors(blocks2, measures);
267303
267725
  const preRegisteredPositions = /* @__PURE__ */ new Map;
267304
267726
  const resolveParagraphlessAnchoredTableY = (block, measure, state) => {
@@ -267503,13 +267925,7 @@ function layoutDocument(blocks2, measures, options = {}) {
267503
267925
  balanceResult = balanceSectionOnPage({
267504
267926
  fragments: state.page.fragments,
267505
267927
  sectionIndex: endingSectionIndex,
267506
- sectionColumns: {
267507
- count: normalized.count,
267508
- gap: normalized.gap,
267509
- width: normalized.width,
267510
- widths: endingSectionColumns.widths,
267511
- equalWidth: endingSectionColumns.equalWidth
267512
- },
267928
+ sectionColumns: toBalancingColumns(normalized),
267513
267929
  sectionHasExplicitColumnBreak: false,
267514
267930
  blockSectionMap,
267515
267931
  margins: { left: activeLeftMargin },
@@ -267650,8 +268066,10 @@ function layoutDocument(blocks2, measures, options = {}) {
267650
268066
  getFootnoteRefCountForBlockId,
267651
268067
  getFootnoteBandOverhead,
267652
268068
  getFootnoteAnchorsForBlockId
267653
- }, anchorsForPara ? {
268069
+ }, anchorsForPara || tablesForPara ? {
267654
268070
  anchoredDrawings: anchorsForPara,
268071
+ anchoredTables: tablesForPara,
268072
+ columnWidth: getCurrentColumnWidth(),
267655
268073
  pageWidth: activePageSize.w,
267656
268074
  pageMargins: {
267657
268075
  top: activeTopMargin,
@@ -267664,32 +268082,19 @@ function layoutDocument(blocks2, measures, options = {}) {
267664
268082
  } : undefined);
267665
268083
  if (tablesForPara) {
267666
268084
  const state = paginator.ensurePage();
267667
- const columnWidthForTable = getCurrentColumnWidth();
267668
- let anchorParagraphTopY = state.cursorY;
267669
- for (const fragment of state.page.fragments)
267670
- if (fragment.kind === "para" && fragment.blockId === block.id)
267671
- anchorParagraphTopY = Math.min(anchorParagraphTopY, fragment.y);
267672
268085
  let tableBottomY = state.cursorY;
267673
- let nextStackY = state.cursorY;
267674
268086
  for (const { block: tableBlock, measure: tableMeasure } of tablesForPara) {
267675
- if (placedAnchoredTableIds.has(tableBlock.id))
268087
+ if (!placedAnchoredIds.has(tableBlock.id))
267676
268088
  continue;
267677
- const totalWidth = tableMeasure.totalWidth ?? 0;
267678
- if (columnWidthForTable > 0 && totalWidth >= columnWidthForTable * 0.99)
268089
+ if ((tableBlock.wrap?.type ?? "None") === "None")
267679
268090
  continue;
267680
- const offsetV = tableBlock.anchor?.offsetV ?? 0;
267681
- const anchorY = Math.max(anchorParagraphTopY, nextStackY) + offsetV;
267682
- floatManager.registerTable(tableBlock, tableMeasure, anchorY, state.columnIndex, state.page.number);
267683
- const tableFragment = createAnchoredTableFragment(tableBlock, tableMeasure, tableBlock.anchor?.offsetH ?? columnX(state), anchorY);
267684
- state.page.fragments.push(tableFragment);
267685
- placedAnchoredTableIds.add(tableBlock.id);
267686
- if ((tableBlock.wrap?.type ?? "None") !== "None") {
267687
- const bottom$1 = anchorY + (tableMeasure.totalHeight ?? 0);
267688
- const distBottom = tableBlock.wrap?.distBottom ?? 0;
267689
- if (bottom$1 > tableBottomY)
267690
- tableBottomY = bottom$1;
267691
- nextStackY = bottom$1 + distBottom;
267692
- }
268091
+ const tableFragment = state.page.fragments.find((fragment) => fragment.kind === "table" && fragment.blockId === tableBlock.id);
268092
+ if (!tableFragment || tableFragment.kind !== "table")
268093
+ continue;
268094
+ const bottom$1 = tableFragment.y + (tableMeasure.totalHeight ?? 0);
268095
+ const distBottom = tableBlock.wrap?.distBottom ?? 0;
268096
+ if (bottom$1 + distBottom > tableBottomY)
268097
+ tableBottomY = bottom$1 + distBottom;
267693
268098
  }
267694
268099
  state.cursorY = tableBottomY;
267695
268100
  state.maxCursorY = Math.max(state.maxCursorY, state.cursorY);
@@ -267848,14 +268253,13 @@ function layoutDocument(blocks2, measures, options = {}) {
267848
268253
  const state = paginator.ensurePage();
267849
268254
  for (const { block: tableBlock, measure: tableMeasure } of paragraphlessAnchoredTables) {
267850
268255
  const columnWidthForTable = getCurrentColumnWidth();
267851
- const totalWidth = tableMeasure.totalWidth ?? 0;
267852
- if (columnWidthForTable > 0 && totalWidth >= columnWidthForTable * 0.99)
268256
+ tableMeasure.totalWidth;
268257
+ if (isAnchoredTableFullWidth(tableBlock, tableMeasure, columnWidthForTable))
267853
268258
  continue;
267854
268259
  const anchorY = resolveParagraphlessAnchoredTableY(tableBlock, tableMeasure, state);
267855
268260
  const anchorX = tableBlock.anchor?.offsetH ?? columnX(state);
267856
268261
  floatManager.registerTable(tableBlock, tableMeasure, anchorY, state.columnIndex, state.page.number);
267857
268262
  state.page.fragments.push(createAnchoredTableFragment(tableBlock, tableMeasure, anchorX, anchorY));
267858
- placedAnchoredTableIds.add(tableBlock.id);
267859
268263
  }
267860
268264
  }
267861
268265
  if (allowSectionBreakOnlyPageFallback && pages.length === 0 && hasOnlySectionBreakBlocks(blocks2))
@@ -267951,13 +268355,7 @@ function layoutDocument(blocks2, measures, options = {}) {
267951
268355
  balanceSectionOnPage({
267952
268356
  fragments: lastPageForSection.fragments,
267953
268357
  sectionIndex: sectionIdx,
267954
- sectionColumns: {
267955
- count: normalized.count,
267956
- gap: normalized.gap,
267957
- width: normalized.width,
267958
- widths: sectionCols.widths,
267959
- equalWidth: sectionCols.equalWidth
267960
- },
268358
+ sectionColumns: toBalancingColumns(normalized),
267961
268359
  sectionHasExplicitColumnBreak: false,
267962
268360
  blockSectionMap,
267963
268361
  margins: { left: sectionLeftMargin },
@@ -268152,6 +268550,16 @@ function layoutHeaderFooter(blocks2, measures, constraints, kind) {
268152
268550
  function normalizeColumns(input2, contentWidth) {
268153
268551
  return normalizeColumnLayout(input2, contentWidth, COLUMN_EPSILON$1);
268154
268552
  }
268553
+ function toBalancingColumns(normalized) {
268554
+ return {
268555
+ count: normalized.count,
268556
+ gap: normalized.gap,
268557
+ width: normalized.width,
268558
+ ...Array.isArray(normalized.widths) ? { widths: normalized.widths } : {},
268559
+ ...Array.isArray(normalized.gaps) ? { gaps: normalized.gaps } : {},
268560
+ ...normalized.equalWidth !== undefined ? { equalWidth: normalized.equalWidth } : {}
268561
+ };
268562
+ }
268155
268563
  function getMeasurementContext() {
268156
268564
  if (measurementCtx)
268157
268565
  return measurementCtx;
@@ -270398,8 +270806,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
270398
270806
  if (columnSlices.length === 0)
270399
270807
  return;
270400
270808
  const columnIndex = Math.max(0, Math.min(columns.count - 1, rawColumnIndex));
270401
- const columnStride = columns.width + columns.gap;
270402
- const columnX = columns.left + columnIndex * columnStride;
270809
+ const columnX = getColumnX(getColumnGeometry(columns), columnIndex, columns.left);
270403
270810
  const contentWidth = Math.min(columns.width, footnoteWidth);
270404
270811
  if (!Number.isFinite(contentWidth) || contentWidth <= 0)
270405
270812
  return;
@@ -271298,6 +271705,16 @@ function percentile(sortedValues, p$12) {
271298
271705
  const weight = index2 - lower;
271299
271706
  return sortedValues[lower] * (1 - weight) + sortedValues[upper] * weight;
271300
271707
  }
271708
+ function resolveColumnsForHit(layout, page, fragmentY) {
271709
+ if (page === undefined)
271710
+ return layout.columns;
271711
+ if (page.columnRegions && typeof fragmentY === "number") {
271712
+ const region = page.columnRegions.find((r$1) => fragmentY >= r$1.yStart && fragmentY < r$1.yEnd);
271713
+ if (region)
271714
+ return region.columns;
271715
+ }
271716
+ return page.columns;
271717
+ }
271301
271718
  function snapToNearestFragment(pageHit, blocks2, measures, pageRelativePoint) {
271302
271719
  const fragments = pageHit.page.fragments.filter((f2) => f2 != null && typeof f2 === "object");
271303
271720
  let nearestHit = null;
@@ -271464,7 +271881,7 @@ function resolvePositionHitFromDomPosition(layout, blocks2, measures, domPos, la
271464
271881
  if (domPos >= fragment.pmStart && domPos <= fragment.pmEnd) {
271465
271882
  blockId = fragment.blockId;
271466
271883
  pageIndex = pi;
271467
- column = determineColumn(layout, fragment.x);
271884
+ column = determineColumn(layout, fragment.x, page, fragment.y);
271468
271885
  const blockIndex = findBlockIndexByFragmentId(blocks2, fragment.blockId);
271469
271886
  if (blockIndex !== -1) {
271470
271887
  const measure = measures[blockIndex];
@@ -271573,7 +271990,7 @@ function clickToPositionGeometry(layout, blocks2, measures, containerPoint, opti
271573
271990
  const pos = mapPointToPm(block, line, pageRelativePoint.x - fragment.x, isRTL, availableWidth, alignmentOverride);
271574
271991
  if (pos == null)
271575
271992
  return null;
271576
- const column = determineColumn(layout, fragment.x);
271993
+ const column = determineColumn(layout, fragment.x, layout.pages[pageIndex], fragment.y);
271577
271994
  return {
271578
271995
  pos,
271579
271996
  layoutEpoch,
@@ -271593,7 +272010,7 @@ function clickToPositionGeometry(layout, blocks2, measures, containerPoint, opti
271593
272010
  layoutEpoch,
271594
272011
  blockId: fragment.blockId,
271595
272012
  pageIndex,
271596
- column: determineColumn(layout, fragment.x),
272013
+ column: determineColumn(layout, fragment.x, layout.pages[pageIndex], fragment.y),
271597
272014
  lineIndex: -1
271598
272015
  };
271599
272016
  }
@@ -271627,7 +272044,7 @@ function clickToPositionGeometry(layout, blocks2, measures, containerPoint, opti
271627
272044
  layoutEpoch,
271628
272045
  blockId: tableHit.fragment.blockId,
271629
272046
  pageIndex,
271630
- column: determineTableColumn(layout, tableHit.fragment),
272047
+ column: determineTableColumn(layout, tableHit.fragment, layout.pages[pageIndex]),
271631
272048
  lineIndex
271632
272049
  };
271633
272050
  }
@@ -271638,7 +272055,7 @@ function clickToPositionGeometry(layout, blocks2, measures, containerPoint, opti
271638
272055
  layoutEpoch,
271639
272056
  blockId: tableHit.fragment.blockId,
271640
272057
  pageIndex,
271641
- column: determineTableColumn(layout, tableHit.fragment),
272058
+ column: determineTableColumn(layout, tableHit.fragment, layout.pages[pageIndex]),
271642
272059
  lineIndex: 0
271643
272060
  };
271644
272061
  }
@@ -271654,7 +272071,7 @@ function clickToPositionGeometry(layout, blocks2, measures, containerPoint, opti
271654
272071
  layoutEpoch,
271655
272072
  blockId: fragment.blockId,
271656
272073
  pageIndex,
271657
- column: determineColumn(layout, fragment.x),
272074
+ column: determineColumn(layout, fragment.x, layout.pages[pageIndex], fragment.y),
271658
272075
  lineIndex: -1
271659
272076
  };
271660
272077
  }
@@ -272070,7 +272487,7 @@ function pmPosToCharOffset(block, line, pmPos) {
272070
272487
  const pmOffsetInSlice = pmPos - runSlicePmStart;
272071
272488
  const charOffsetInSlice = Math.round(pmOffsetInSlice / runSlicePmRange * runSliceCharCount);
272072
272489
  const result = charOffset + Math.min(charOffsetInSlice, runSliceCharCount);
272073
- const runText$1 = text5;
272490
+ const runText$2 = text5;
272074
272491
  const offsetInRun = result - charOffset - (isFirstRun ? 0 : 0);
272075
272492
  logSelectionMapDebug({
272076
272493
  kind: "pmPosToCharOffset-hit",
@@ -272087,7 +272504,7 @@ function pmPosToCharOffset(block, line, pmPos) {
272087
272504
  pmOffsetInSlice,
272088
272505
  charOffsetInSlice,
272089
272506
  result,
272090
- runTextPreview: runText$1.slice(Math.max(0, offsetInRun - 10), Math.min(runText$1.length, offsetInRun + 10))
272507
+ runTextPreview: runText$2.slice(Math.max(0, offsetInRun - 10), Math.min(runText$2.length, offsetInRun + 10))
272091
272508
  });
272092
272509
  return result;
272093
272510
  }
@@ -309660,7 +310077,7 @@ menclose::after {
309660
310077
  pmStart: start$1,
309661
310078
  pmEnd: (typeof attrs.pmEnd === "number" ? attrs.pmEnd : undefined) ?? (start$1 != null ? start$1 + 1 : undefined)
309662
310079
  };
309663
- }, PX_PER_PT2, getParagraphAttrs = (block) => {
310080
+ }, 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) => {
309664
310081
  if (!block.attrs || typeof block.attrs !== "object")
309665
310082
  return;
309666
310083
  return block.attrs;
@@ -309695,7 +310112,7 @@ menclose::after {
309695
310112
  top: (borders.top?.space ?? 0) * PX_PER_PT2 + (borders.top?.width ?? 0),
309696
310113
  bottom: (borders.bottom?.space ?? 0) * PX_PER_PT2 + (borders.bottom?.width ?? 0)
309697
310114
  };
309698
- }, 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) => {
310115
+ }, HEADING_STYLE_PREFIX = "heading", CHAPTER_MARKER_SEPARATOR_RE, CLEAN_CHAPTER_MARKER_RE, DEFAULT_BALANCING_CONFIG, getColumnWidthAt = (columns, columnIndex) => {
309699
310116
  if (Array.isArray(columns.widths) && columns.widths.length > 0)
309700
310117
  return columns.widths[Math.max(0, Math.min(columnIndex, columns.widths.length - 1))] ?? columns.width;
309701
310118
  return columns.width;
@@ -311629,23 +312046,13 @@ menclose::after {
311629
312046
  if (fragment?.kind === "table" && typeof fragment.columnIndex === "number")
311630
312047
  columnIndex = Math.max(0, Math.min(columns.count - 1, fragment.columnIndex));
311631
312048
  else if (fragment && typeof fragment.x === "number") {
311632
- const widths = Array.isArray(columns.widths) && columns.widths.length > 0 ? columns.widths : undefined;
311633
- if (widths) {
311634
- let cursorX = columns.left;
311635
- for (let index2 = 0;index2 < columns.count; index2 += 1) {
311636
- const columnWidth = widths[index2] ?? columns.width;
311637
- if (fragment.x < cursorX + columnWidth + columns.gap / 2) {
311638
- columnIndex = index2;
311639
- break;
311640
- }
311641
- cursorX += columnWidth + columns.gap;
311642
- columnIndex = Math.min(columns.count - 1, index2 + 1);
312049
+ const geometry = getColumnGeometry(columns);
312050
+ columnIndex = Math.max(0, geometry.length - 1);
312051
+ for (const col of geometry)
312052
+ if (fragment.x < columns.left + col.x + col.width + col.gapAfter / 2) {
312053
+ columnIndex = col.index;
312054
+ break;
311643
312055
  }
311644
- } else {
311645
- const columnStride = columns.width + columns.gap;
311646
- const rawIndex = columnStride > 0 ? Math.floor((fragment.x - columns.left) / columnStride) : 0;
311647
- columnIndex = Math.max(0, Math.min(columns.count - 1, rawIndex));
311648
- }
311649
312056
  }
311650
312057
  }
311651
312058
  const key2 = footnoteColumnKey(pageIndex, columnIndex);
@@ -312225,20 +312632,21 @@ menclose::after {
312225
312632
  if (block.kind !== "paragraph")
312226
312633
  return false;
312227
312634
  return getParagraphInlineDirection(block.attrs) === "rtl";
312228
- }, determineColumn = (layout, fragmentX) => {
312229
- const columns = layout.columns;
312635
+ }, determineColumn = (layout, fragmentX, page, fragmentY) => {
312636
+ const columns = resolveColumnsForHit(layout, page, fragmentY);
312230
312637
  if (!columns || columns.count <= 1)
312231
312638
  return 0;
312232
- const span = (layout.pageSize.w - columns.gap * (columns.count - 1)) / columns.count + columns.gap;
312233
- const relative = fragmentX;
312234
- const raw = Math.floor(relative / Math.max(span, 1));
312235
- return Math.max(0, Math.min(columns.count - 1, raw));
312236
- }, determineTableColumn = (layout, fragment) => {
312639
+ const pageWidth = page?.size?.w ?? layout.pageSize.w;
312640
+ const margins = page?.margins ?? layout.pages[0]?.margins;
312641
+ const marginLeft = Math.max(0, margins?.left ?? 0);
312642
+ const marginRight = Math.max(0, margins?.right ?? 0);
312643
+ return getColumnAtX(getColumnGeometry(normalizeColumnLayout(columns, Math.max(1, pageWidth - (marginLeft + marginRight)))), fragmentX, marginLeft);
312644
+ }, determineTableColumn = (layout, fragment, page) => {
312237
312645
  if (typeof fragment.columnIndex === "number") {
312238
- const count = layout.columns?.count ?? 1;
312646
+ const count = resolveColumnsForHit(layout, page, fragment.y)?.count ?? 1;
312239
312647
  return Math.max(0, Math.min(Math.max(0, count - 1), fragment.columnIndex));
312240
312648
  }
312241
- return determineColumn(layout, fragment.x);
312649
+ return determineColumn(layout, fragment.x, page, fragment.y);
312242
312650
  }, findLineIndexAtY = (lines, offsetY, fromLine, toLine) => {
312243
312651
  if (!lines || lines.length === 0)
312244
312652
  return null;
@@ -318417,13 +318825,13 @@ menclose::after {
318417
318825
  return;
318418
318826
  console.log(...args$1);
318419
318827
  }, 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;
318420
- var init_src_DeS9kJS7_es = __esm(() => {
318828
+ var init_src_BhZiOqOm_es = __esm(() => {
318421
318829
  init_rolldown_runtime_Bg48TavK_es();
318422
- init_SuperConverter_BBjNvGFh_es();
318830
+ init_SuperConverter_bEQ45IUD_es();
318423
318831
  init_jszip_C49i9kUs_es();
318424
318832
  init_xml_js_CqGKpaft_es();
318425
318833
  init_uuid_qzgm05fK_es();
318426
- init_create_headless_toolbar_s_kl3MP8_es();
318834
+ init_create_headless_toolbar_BmFWtej0_es();
318427
318835
  init_constants_D9qj59G2_es();
318428
318836
  init_dist_B8HfvhaK_es();
318429
318837
  init_unified_Dsuw2be5_es();
@@ -353503,11 +353911,11 @@ function print() { __p += __j.call(arguments, '') }
353503
353911
  ]);
353504
353912
  });
353505
353913
 
353506
- // ../../packages/superdoc/dist/chunks/create-super-doc-ui-CZZRzAFm.es.js
353914
+ // ../../packages/superdoc/dist/chunks/create-super-doc-ui-C2hkLuct.es.js
353507
353915
  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;
353508
- var init_create_super_doc_ui_CZZRzAFm_es = __esm(() => {
353509
- init_SuperConverter_BBjNvGFh_es();
353510
- init_create_headless_toolbar_s_kl3MP8_es();
353916
+ var init_create_super_doc_ui_C2hkLuct_es = __esm(() => {
353917
+ init_SuperConverter_bEQ45IUD_es();
353918
+ init_create_headless_toolbar_BmFWtej0_es();
353511
353919
  MOD_ALIASES = new Set([
353512
353920
  "Mod",
353513
353921
  "Meta",
@@ -353549,16 +353957,16 @@ var init_zipper_yaJVJ4z9_es = __esm(() => {
353549
353957
 
353550
353958
  // ../../packages/superdoc/dist/super-editor.es.js
353551
353959
  var init_super_editor_es = __esm(() => {
353552
- init_src_DeS9kJS7_es();
353553
- init_SuperConverter_BBjNvGFh_es();
353960
+ init_src_BhZiOqOm_es();
353961
+ init_SuperConverter_bEQ45IUD_es();
353554
353962
  init_jszip_C49i9kUs_es();
353555
353963
  init_xml_js_CqGKpaft_es();
353556
- init_create_headless_toolbar_s_kl3MP8_es();
353964
+ init_create_headless_toolbar_BmFWtej0_es();
353557
353965
  init_constants_D9qj59G2_es();
353558
353966
  init_dist_B8HfvhaK_es();
353559
353967
  init_unified_Dsuw2be5_es();
353560
353968
  init_DocxZipper_Bu2Fhqkw_es();
353561
- init_create_super_doc_ui_CZZRzAFm_es();
353969
+ init_create_super_doc_ui_C2hkLuct_es();
353562
353970
  init_ui_C5PAS9hY_es();
353563
353971
  init_eventemitter3_BnGqBE_Q_es();
353564
353972
  init_errors_CNaD6vcg_es();
@@ -375150,6 +375558,8 @@ function scaleFontSizeForVerticalText2(fontSize, formatting) {
375150
375558
  var SUBSCRIPT_SUPERSCRIPT_SCALE2 = 0.65, BASELINE_SHIFT_EPSILON2 = 0.000001;
375151
375559
  // ../../packages/layout-engine/contracts/src/pm-range.ts
375152
375560
  var init_pm_range = () => {};
375561
+ // ../../packages/layout-engine/contracts/src/graphic-placement.ts
375562
+ var init_graphic_placement = () => {};
375153
375563
  // ../../packages/layout-engine/contracts/src/author-colors.ts
375154
375564
  var init_author_colors = () => {};
375155
375565
 
@@ -375375,6 +375785,7 @@ var init_engines = () => {};
375375
375785
  var init_src2 = __esm(() => {
375376
375786
  init_justify_utils();
375377
375787
  init_pm_range();
375788
+ init_graphic_placement();
375378
375789
  init_author_colors();
375379
375790
  init_sdt_container();
375380
375791
  init_page_ref_anchor();
@@ -375899,13 +376310,15 @@ var twipsToPx3 = (value) => value / TWIPS_PER_INCH2 * PX_PER_INCH2, ptToPx2 = (p
375899
376310
  }, mergeWrapDistancesFromPadding2 = (wrap4, padding) => {
375900
376311
  if (!padding || wrap4.type === "None" || wrap4.type === "Inline")
375901
376312
  return;
375902
- if (wrap4.distTop == null && padding.top != null)
376313
+ const mergeVertical = wrap4.type === "Square" || wrap4.type === "TopAndBottom";
376314
+ const mergeHorizontal = wrap4.type === "Square" || wrap4.type === "Tight" || wrap4.type === "Through";
376315
+ if (mergeVertical && wrap4.distTop == null && padding.top != null)
375903
376316
  wrap4.distTop = padding.top;
375904
- if (wrap4.distBottom == null && padding.bottom != null)
376317
+ if (mergeVertical && wrap4.distBottom == null && padding.bottom != null)
375905
376318
  wrap4.distBottom = padding.bottom;
375906
- if (wrap4.distLeft == null && padding.left != null)
376319
+ if (mergeHorizontal && wrap4.distLeft == null && padding.left != null)
375907
376320
  wrap4.distLeft = padding.left;
375908
- if (wrap4.distRight == null && padding.right != null)
376321
+ if (mergeHorizontal && wrap4.distRight == null && padding.right != null)
375909
376322
  wrap4.distRight = padding.right;
375910
376323
  }, normalizeColor2 = (value) => {
375911
376324
  if (typeof value !== "string")
@@ -385791,6 +386204,24 @@ function normalizeLegacyBorderStyle2(value) {
385791
386204
  return "single";
385792
386205
  }
385793
386206
  }
386207
+ function countFloatingTableContentColumns2(node3) {
386208
+ const grid = node3.attrs?.grid;
386209
+ if (Array.isArray(grid) && grid.length > 0) {
386210
+ return grid.length;
386211
+ }
386212
+ const firstRow = node3.content?.[0];
386213
+ if (!firstRow || !isTableRowNode2(firstRow) || !Array.isArray(firstRow.content)) {
386214
+ return 0;
386215
+ }
386216
+ let columns = 0;
386217
+ for (const cellNode of firstRow.content) {
386218
+ if (!cellNode || !isTableCellNode2(cellNode))
386219
+ continue;
386220
+ const colSpan = typeof cellNode.attrs?.colspan === "number" ? cellNode.attrs.colspan : 1;
386221
+ columns += colSpan > 0 ? colSpan : 1;
386222
+ }
386223
+ return columns;
386224
+ }
385794
386225
  function extractFloatingTableAnchorWrap2(node3) {
385795
386226
  const tableProperties = node3.attrs?.tableProperties;
385796
386227
  const floatingProps = tableProperties?.floatingTableProperties;
@@ -385840,9 +386271,13 @@ function extractFloatingTableAnchorWrap2(node3) {
385840
386271
  if (floatingProps.tblpY !== undefined) {
385841
386272
  anchor.offsetV = twipsToPx3(floatingProps.tblpY);
385842
386273
  }
385843
- const hasDistances = floatingProps.leftFromText !== undefined || floatingProps.rightFromText !== undefined || floatingProps.topFromText !== undefined || floatingProps.bottomFromText !== undefined;
386274
+ const hasHorizontalDistances = floatingProps.leftFromText !== undefined || floatingProps.rightFromText !== undefined;
386275
+ const hasVerticalDistances = floatingProps.topFromText !== undefined || floatingProps.bottomFromText !== undefined;
386276
+ const hasDistances = hasHorizontalDistances || hasVerticalDistances;
386277
+ const contentColumnCount = countFloatingTableContentColumns2(node3);
386278
+ const isSingleCellHorizontalOverlay = contentColumnCount <= 1 && hasHorizontalDistances && !hasVerticalDistances;
385844
386279
  const wrap4 = {
385845
- type: "Square",
386280
+ type: isSingleCellHorizontalOverlay ? "None" : "Square",
385846
386281
  wrapText: "bothSides"
385847
386282
  };
385848
386283
  if (hasDistances) {
@@ -442689,16 +443124,19 @@ var DRAWING_XML_TAG2 = "w:drawing", SHAPE_URI2 = "http://schemas.microsoft.com/o
442689
443124
  }, mergeAnchorPaddingIntoWrapDistances2 = (wrap6, padding) => {
442690
443125
  if (!wrap6?.attrs || !padding)
442691
443126
  return;
442692
- if (wrap6.attrs.distTop == null && Number.isFinite(padding.top) && padding.top !== 0) {
443127
+ const type = wrap6.type;
443128
+ const mergeVertical = type === "Square" || type === "TopAndBottom";
443129
+ const mergeHorizontal = type === "Square" || type === "Tight" || type === "Through";
443130
+ if (mergeVertical && wrap6.attrs.distTop == null && Number.isFinite(padding.top) && padding.top !== 0) {
442693
443131
  wrap6.attrs.distTop = padding.top;
442694
443132
  }
442695
- if (wrap6.attrs.distBottom == null && Number.isFinite(padding.bottom) && padding.bottom !== 0) {
443133
+ if (mergeVertical && wrap6.attrs.distBottom == null && Number.isFinite(padding.bottom) && padding.bottom !== 0) {
442696
443134
  wrap6.attrs.distBottom = padding.bottom;
442697
443135
  }
442698
- if (wrap6.attrs.distLeft == null && Number.isFinite(padding.left) && padding.left !== 0) {
443136
+ if (mergeHorizontal && wrap6.attrs.distLeft == null && Number.isFinite(padding.left) && padding.left !== 0) {
442699
443137
  wrap6.attrs.distLeft = padding.left;
442700
443138
  }
442701
- if (wrap6.attrs.distRight == null && Number.isFinite(padding.right) && padding.right !== 0) {
443139
+ if (mergeHorizontal && wrap6.attrs.distRight == null && Number.isFinite(padding.right) && padding.right !== 0) {
442702
443140
  wrap6.attrs.distRight = padding.right;
442703
443141
  }
442704
443142
  }, handleShapeDrawing2 = (params3, node4, graphicData, size3, padding, marginOffset, anchorData, wrap6, isAnchor, isHidden) => {
@@ -443886,7 +444324,6 @@ function translateAnchorNode2(params3) {
443886
444324
  }
443887
444325
  break;
443888
444326
  }
443889
- case "Through":
443890
444327
  case "Tight": {
443891
444328
  const attributes = {};
443892
444329
  if ("distLeft" in (attrs.wrap.attrs || {})) {
@@ -443895,12 +444332,41 @@ function translateAnchorNode2(params3) {
443895
444332
  if ("distRight" in (attrs.wrap.attrs || {})) {
443896
444333
  attributes.distR = pixelsToEmu2(attrs.wrap.attrs.distRight);
443897
444334
  }
443898
- if ("distTop" in (attrs.wrap.attrs || {})) {
443899
- attributes.distT = pixelsToEmu2(attrs.wrap.attrs.distTop);
444335
+ const wrapText = attrs.wrap.attrs?.wrapText || "bothSides";
444336
+ if (wrapText) {
444337
+ attributes.wrapText = wrapText;
444338
+ }
444339
+ if (Object.keys(attributes).length) {
444340
+ wrapElement.attributes = attributes;
444341
+ }
444342
+ if (attrs.wrap.attrs?.polygon) {
444343
+ const polygonNode = objToPolygon2(attrs.wrap.attrs.polygon);
444344
+ if (polygonNode) {
444345
+ if (attrs.wrap.attrs?.polygonEdited !== undefined) {
444346
+ polygonNode.attributes = {
444347
+ ...polygonNode.attributes || {},
444348
+ edited: String(attrs.wrap.attrs.polygonEdited)
444349
+ };
444350
+ }
444351
+ wrapElement.elements = [polygonNode];
444352
+ }
443900
444353
  }
444354
+ break;
444355
+ }
444356
+ case "Through": {
444357
+ const attributes = {};
443901
444358
  if ("distBottom" in (attrs.wrap.attrs || {})) {
443902
444359
  attributes.distB = pixelsToEmu2(attrs.wrap.attrs.distBottom);
443903
444360
  }
444361
+ if ("distLeft" in (attrs.wrap.attrs || {})) {
444362
+ attributes.distL = pixelsToEmu2(attrs.wrap.attrs.distLeft);
444363
+ }
444364
+ if ("distRight" in (attrs.wrap.attrs || {})) {
444365
+ attributes.distR = pixelsToEmu2(attrs.wrap.attrs.distRight);
444366
+ }
444367
+ if ("distTop" in (attrs.wrap.attrs || {})) {
444368
+ attributes.distT = pixelsToEmu2(attrs.wrap.attrs.distTop);
444369
+ }
443904
444370
  const wrapText = attrs.wrap.attrs?.wrapText || "bothSides";
443905
444371
  if (wrapText) {
443906
444372
  attributes.wrapText = wrapText;
@@ -469433,7 +469899,7 @@ function buildCommentJsonFromText2(text9) {
469433
469899
  const normalized = text9.replace(/\r\n?/g, `
469434
469900
  `);
469435
469901
  return normalized.split(`
469436
- `).map((paragraphText) => ({
469902
+ `).map((paragraphText2) => ({
469437
469903
  type: "paragraph",
469438
469904
  content: [
469439
469905
  {
@@ -469441,7 +469907,7 @@ function buildCommentJsonFromText2(text9) {
469441
469907
  content: [
469442
469908
  {
469443
469909
  type: "text",
469444
- text: paragraphText
469910
+ text: paragraphText2
469445
469911
  }
469446
469912
  ]
469447
469913
  }
@@ -496576,8 +497042,8 @@ function replaceSdtTextContent2(editor, target, text9) {
496576
497042
  const paragraph4 = buildEmptyBlockContent2(editor, resolved.node);
496577
497043
  if (!paragraph4)
496578
497044
  return false;
496579
- const paragraphText = text9.length > 0 ? buildTextWithTabs2(editor.schema, text9, undefined) : null;
496580
- const updatedParagraph = paragraph4.type.create(paragraph4.attrs ?? null, paragraphText, paragraph4.marks);
497045
+ const paragraphText2 = text9.length > 0 ? buildTextWithTabs2(editor.schema, text9, undefined) : null;
497046
+ const updatedParagraph = paragraph4.type.create(paragraph4.attrs ?? null, paragraphText2, paragraph4.marks);
496581
497047
  tr.replaceWith(innerFrom, innerTo, updatedParagraph);
496582
497048
  dispatchTransaction5(editor, tr);
496583
497049
  return true;