@superdoc-dev/cli 0.16.0-next.23 → 0.16.0-next.24

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 +335 -225
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -68342,7 +68342,7 @@ var init_remark_gfm_BhnWr3yf_es = __esm(() => {
68342
68342
  emptyOptions2 = {};
68343
68343
  });
68344
68344
 
68345
- // ../../packages/superdoc/dist/chunks/SuperConverter-B9mZiCO9.es.js
68345
+ // ../../packages/superdoc/dist/chunks/SuperConverter-BSMYiYJm.es.js
68346
68346
  function getExtensionConfigField(extension$1, field, context = { name: "" }) {
68347
68347
  const fieldValue = extension$1.config[field];
68348
68348
  if (typeof fieldValue === "function")
@@ -78291,6 +78291,70 @@ function computeFragmentPmRange(block, lines, fromLine, toLine) {
78291
78291
  pmEnd
78292
78292
  };
78293
78293
  }
78294
+ function resolveAnchoredGraphicY(input) {
78295
+ const { anchor, objectHeight, contentTop, contentBottom, pageBottomMargin = 0, anchorParagraphY = contentTop, firstLineHeight = 0, preRegisteredFallbackToContentTop = false } = input;
78296
+ const offsetV = anchor?.offsetV ?? 0;
78297
+ const vRelativeFrom = anchor?.vRelativeFrom;
78298
+ const alignV = anchor?.alignV;
78299
+ const contentHeight = Math.max(0, contentBottom - contentTop);
78300
+ if (vRelativeFrom === "margin") {
78301
+ if (alignV === "bottom")
78302
+ return contentBottom - objectHeight + offsetV;
78303
+ if (alignV === "center")
78304
+ return contentTop + (contentHeight - objectHeight) / 2 + offsetV;
78305
+ return contentTop + offsetV;
78306
+ }
78307
+ if (vRelativeFrom === "page") {
78308
+ const pageHeight = contentBottom + pageBottomMargin;
78309
+ if (alignV === "bottom")
78310
+ return pageHeight - objectHeight + offsetV;
78311
+ if (alignV === "center")
78312
+ return (pageHeight - objectHeight) / 2 + offsetV;
78313
+ return offsetV;
78314
+ }
78315
+ if (vRelativeFrom === "paragraph") {
78316
+ if (preRegisteredFallbackToContentTop)
78317
+ return contentTop + offsetV;
78318
+ const baseAnchorY = anchorParagraphY;
78319
+ if (alignV === "bottom")
78320
+ return baseAnchorY + firstLineHeight - objectHeight + offsetV;
78321
+ if (alignV === "center")
78322
+ return baseAnchorY + (firstLineHeight - objectHeight) / 2 + offsetV;
78323
+ return baseAnchorY + offsetV;
78324
+ }
78325
+ if (preRegisteredFallbackToContentTop)
78326
+ return contentTop + offsetV;
78327
+ return anchorParagraphY + offsetV;
78328
+ }
78329
+ function resolveAnchoredGraphicX(anchor, columnIndex, columns, objectWidth, margins, pageWidth) {
78330
+ const alignH = anchor.alignH ?? "left";
78331
+ const offsetH = anchor.offsetH ?? 0;
78332
+ const marginLeft = Math.max(0, margins?.left ?? 0);
78333
+ const marginRight = Math.max(0, margins?.right ?? 0);
78334
+ const contentWidth = pageWidth != null ? Math.max(1, pageWidth - (marginLeft + marginRight)) : columns.width;
78335
+ const contentLeft = marginLeft;
78336
+ const columnLeft = contentLeft + columnIndex * (columns.width + columns.gap);
78337
+ const relativeFrom = anchor.hRelativeFrom ?? "column";
78338
+ let baseX;
78339
+ let availableWidth;
78340
+ if (relativeFrom === "page") {
78341
+ baseX = 0;
78342
+ availableWidth = pageWidth != null ? pageWidth : contentWidth + marginLeft + marginRight;
78343
+ } else if (relativeFrom === "margin") {
78344
+ baseX = contentLeft;
78345
+ availableWidth = contentWidth;
78346
+ } else {
78347
+ baseX = columnLeft;
78348
+ availableWidth = columns.width;
78349
+ }
78350
+ if (alignH === "left")
78351
+ return baseX + offsetH;
78352
+ if (alignH === "right")
78353
+ return baseX + availableWidth - objectWidth - offsetH;
78354
+ if (alignH === "center")
78355
+ return baseX + (availableWidth - objectWidth) / 2 + offsetH;
78356
+ return baseX;
78357
+ }
78294
78358
  function widthsEqual(a, b) {
78295
78359
  if (!a && !b)
78296
78360
  return true;
@@ -78317,10 +78381,12 @@ function cloneColumnLayout(columns) {
78317
78381
  }
78318
78382
  function normalizeColumnLayout(input, contentWidth, epsilon = 0.0001) {
78319
78383
  const rawCount = input && Number.isFinite(input.count) ? Math.floor(input.count) : 1;
78320
- const count2 = Math.max(1, rawCount || 1);
78384
+ let count2 = Math.max(1, rawCount || 1);
78321
78385
  const gap = Math.max(0, input?.gap ?? 0);
78386
+ const explicitWidths = input?.equalWidth === false && Array.isArray(input?.widths) && input.widths.length > 0 ? input.widths.filter((width$1) => typeof width$1 === "number" && Number.isFinite(width$1) && width$1 > 0) : [];
78387
+ if (explicitWidths.length > 0 && explicitWidths.length < count2)
78388
+ count2 = explicitWidths.length;
78322
78389
  const availableWidth = contentWidth - gap * (count2 - 1);
78323
- const explicitWidths = Array.isArray(input?.widths) && input.widths.length > 0 ? input.widths.filter((width$1) => typeof width$1 === "number" && Number.isFinite(width$1) && width$1 > 0) : [];
78324
78390
  let widths = explicitWidths.length > 0 ? explicitWidths.slice(0, count2) : Array.from({ length: count2 }, () => availableWidth > 0 ? availableWidth / count2 : contentWidth);
78325
78391
  if (widths.length < count2) {
78326
78392
  const remaining = Math.max(0, availableWidth - widths.reduce((sum, width$1) => sum + width$1, 0));
@@ -83755,6 +83821,8 @@ function handleImageNode$1(node3, params3, isAnchor) {
83755
83821
  default:
83756
83822
  break;
83757
83823
  }
83824
+ if (wrap$1.type === "Square" || wrap$1.type === "Tight" || wrap$1.type === "Through" || wrap$1.type === "TopAndBottom")
83825
+ mergeAnchorPaddingIntoWrapDistances(wrap$1, padding);
83758
83826
  const docPr = node3.elements.find((el) => el.name === "wp:docPr");
83759
83827
  const isHidden = isDocPrHidden(docPr);
83760
83828
  let anchorData = null;
@@ -101825,18 +101893,22 @@ function extractColumns(elements) {
101825
101893
  const cols = elements.find((el) => el?.name === "w:cols");
101826
101894
  if (!cols?.attributes)
101827
101895
  return;
101828
- const count2 = parseColumnCount(cols.attributes["w:num"]);
101896
+ let count2 = parseColumnCount(cols.attributes["w:num"]);
101829
101897
  const withSeparator = parseColumnSeparator(cols.attributes["w:sep"]);
101830
101898
  const equalWidthRaw = cols.attributes["w:equalWidth"];
101831
101899
  const equalWidth = equalWidthRaw === "0" || equalWidthRaw === 0 || equalWidthRaw === false ? false : equalWidthRaw === "1" || equalWidthRaw === 1 || equalWidthRaw === true ? true : undefined;
101832
101900
  const columnChildren = Array.isArray(cols.elements) ? cols.elements.filter((child) => child?.name === "w:col") : [];
101833
- const gapInches = parseColumnGap(cols.attributes["w:space"] ?? columnChildren.find((child) => child?.attributes?.["w:space"] != null)?.attributes?.["w:space"]);
101901
+ const isExplicit = equalWidth === false;
101902
+ const firstChildSpace = columnChildren.find((child) => child?.attributes?.["w:space"] != null)?.attributes?.["w:space"];
101903
+ const gapInches = parseColumnGap(isExplicit ? firstChildSpace ?? 0 : cols.attributes["w:space"]);
101834
101904
  const widths = columnChildren.map((child) => Number(child.attributes?.["w:w"])).filter((widthTwips) => Number.isFinite(widthTwips) && widthTwips > 0).map((widthTwips) => widthTwips / 1440 * PX_PER_INCH$1);
101905
+ if (isExplicit && widths.length > 0)
101906
+ count2 = Math.min(count2, widths.length);
101835
101907
  return {
101836
101908
  count: count2,
101837
101909
  gap: gapInches * PX_PER_INCH$1,
101838
101910
  withSeparator,
101839
- ...widths.length > 0 ? { widths } : {},
101911
+ ...isExplicit && widths.length > 0 ? { widths } : {},
101840
101912
  ...equalWidth !== undefined ? { equalWidth } : {}
101841
101913
  };
101842
101914
  }
@@ -104680,6 +104752,8 @@ function imageNodeToBlock(node3, nextBlockId, positions, _trackedMeta, _trackedC
104680
104752
  const height = typeof size2.height === "number" && Number.isFinite(size2.height) ? size2.height : undefined;
104681
104753
  const explicitDisplay = typeof attrs.display === "string" ? attrs.display : undefined;
104682
104754
  const normalizedWrap = normalizeWrap$1(attrs.wrap);
104755
+ if (normalizedWrap)
104756
+ mergeWrapDistancesFromPadding(normalizedWrap, toBoxSpacing$1(attrs.padding));
104683
104757
  let anchor = normalizeAnchorData(attrs.anchorData, attrs, normalizedWrap?.behindDoc);
104684
104758
  if (!anchor && normalizedWrap) {
104685
104759
  anchor = { isAnchored: true };
@@ -120153,6 +120227,17 @@ var isRegExp = (value) => {
120153
120227
  if (!hasValue || !hasPositive)
120154
120228
  return null;
120155
120229
  return `inset(${percentEdges.top ?? 0}% ${percentEdges.right ?? 0}% ${percentEdges.bottom ?? 0}% ${percentEdges.left ?? 0}%)`;
120230
+ }, mergeAnchorPaddingIntoWrapDistances = (wrap$1, padding) => {
120231
+ if (!wrap$1?.attrs || !padding)
120232
+ return;
120233
+ if (wrap$1.attrs.distTop == null && Number.isFinite(padding.top) && padding.top !== 0)
120234
+ wrap$1.attrs.distTop = padding.top;
120235
+ if (wrap$1.attrs.distBottom == null && Number.isFinite(padding.bottom) && padding.bottom !== 0)
120236
+ wrap$1.attrs.distBottom = padding.bottom;
120237
+ if (wrap$1.attrs.distLeft == null && Number.isFinite(padding.left) && padding.left !== 0)
120238
+ wrap$1.attrs.distLeft = padding.left;
120239
+ if (wrap$1.attrs.distRight == null && Number.isFinite(padding.right) && padding.right !== 0)
120240
+ wrap$1.attrs.distRight = padding.right;
120156
120241
  }, handleShapeDrawing = (params3, node3, graphicData, size2, padding, marginOffset, anchorData, wrap$1, isAnchor, isHidden) => {
120157
120242
  const wsp = graphicData.elements.find((el) => el.name === "wps:wsp");
120158
120243
  const textBoxContent = wsp.elements.find((el) => el.name === "wps:txbx")?.elements?.find((el) => el.name === "w:txbxContent");
@@ -128717,6 +128802,17 @@ var isRegExp = (value) => {
128717
128802
  const parsed = parseFloat(value);
128718
128803
  return Number.isFinite(parsed) ? parsed : undefined;
128719
128804
  }
128805
+ }, mergeWrapDistancesFromPadding = (wrap$1, padding) => {
128806
+ if (!padding || wrap$1.type === "None" || wrap$1.type === "Inline")
128807
+ return;
128808
+ if (wrap$1.distTop == null && padding.top != null)
128809
+ wrap$1.distTop = padding.top;
128810
+ if (wrap$1.distBottom == null && padding.bottom != null)
128811
+ wrap$1.distBottom = padding.bottom;
128812
+ if (wrap$1.distLeft == null && padding.left != null)
128813
+ wrap$1.distLeft = padding.left;
128814
+ if (wrap$1.distRight == null && padding.right != null)
128815
+ wrap$1.distRight = padding.right;
128720
128816
  }, normalizeColor = (value) => {
128721
128817
  if (typeof value !== "string")
128722
128818
  return;
@@ -130525,6 +130621,8 @@ var isRegExp = (value) => {
130525
130621
  return anchor.isAnchored || anchor.hRelativeFrom != null || anchor.vRelativeFrom != null || anchor.alignH != null || anchor.alignV != null || anchor.offsetH != null || anchor.offsetV != null || anchor.behindDoc != null ? anchor : undefined;
130526
130622
  }, buildDrawingBlock = (rawAttrs, nextBlockId, positions, node3, geometry, drawingKind, extraProps) => {
130527
130623
  const normalizedWrap = normalizeWrap$2(rawAttrs.wrap);
130624
+ if (normalizedWrap)
130625
+ mergeWrapDistancesFromPadding(normalizedWrap, toBoxSpacing(rawAttrs.padding));
130528
130626
  const sourceAnchor = isPlainObject3(rawAttrs.sourceAnchor) ? rawAttrs.sourceAnchor : undefined;
130529
130627
  const baseAnchor = normalizeAnchorData$1(rawAttrs.anchorData, rawAttrs, normalizedWrap?.behindDoc);
130530
130628
  const pos = positions.get(node3);
@@ -131579,7 +131677,7 @@ var isRegExp = (value) => {
131579
131677
  state.kern = kernNode.attributes["w:val"];
131580
131678
  }
131581
131679
  }, SuperConverter;
131582
- var init_SuperConverter_B9mZiCO9_es = __esm(() => {
131680
+ var init_SuperConverter_BSMYiYJm_es = __esm(() => {
131583
131681
  init_rolldown_runtime_Bg48TavK_es();
131584
131682
  init_jszip_C49i9kUs_es();
131585
131683
  init_xml_js_CqGKpaft_es();
@@ -170614,7 +170712,7 @@ var init_SuperConverter_B9mZiCO9_es = __esm(() => {
170614
170712
  };
170615
170713
  });
170616
170714
 
170617
- // ../../packages/superdoc/dist/chunks/create-headless-toolbar-pn-wKqsL.es.js
170715
+ // ../../packages/superdoc/dist/chunks/create-headless-toolbar-DeKyOdIi.es.js
170618
170716
  function parseSizeUnit(val = "0") {
170619
170717
  const length3 = val.toString() || "0";
170620
170718
  const value = Number.parseFloat(length3);
@@ -180947,8 +181045,8 @@ var CSS_DIMENSION_REGEX, DOM_SIZE_UNITS, normalizeActorId = (value) => {
180947
181045
  }
180948
181046
  };
180949
181047
  };
180950
- var init_create_headless_toolbar_pn_wKqsL_es = __esm(() => {
180951
- init_SuperConverter_B9mZiCO9_es();
181048
+ var init_create_headless_toolbar_DeKyOdIi_es = __esm(() => {
181049
+ init_SuperConverter_BSMYiYJm_es();
180952
181050
  init_uuid_qzgm05fK_es();
180953
181051
  init_constants_D_X7xF4s_es();
180954
181052
  init_dist_B8HfvhaK_es();
@@ -230111,7 +230209,7 @@ var init_remark_gfm_eZN6yzWQ_es = __esm(() => {
230111
230209
  init_remark_gfm_BhnWr3yf_es();
230112
230210
  });
230113
230211
 
230114
- // ../../packages/superdoc/dist/chunks/src-DvgAvHbj.es.js
230212
+ // ../../packages/superdoc/dist/chunks/src-plIVvSkL.es.js
230115
230213
  function deleteProps(obj, propOrProps) {
230116
230214
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
230117
230215
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -270395,6 +270493,9 @@ function isSettled(status) {
270395
270493
  function normalizeFamilyKey$2(family$1) {
270396
270494
  return family$1.trim().replace(/^["']|["']$/g, "").toLowerCase();
270397
270495
  }
270496
+ function stripFamilyQuotes(family$1) {
270497
+ return family$1.trim().replace(/^["']|["']$/g, "");
270498
+ }
270398
270499
  function splitStack(cssFontFamily) {
270399
270500
  return cssFontFamily.split(",").map((part) => part.trim()).filter(Boolean);
270400
270501
  }
@@ -272004,7 +272105,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
272004
272105
  let currentPageWidth = pageWidth;
272005
272106
  let marginLeft = Math.max(0, currentMargins?.left ?? 0);
272006
272107
  return {
272007
- registerDrawing(drawingBlock, measure, anchorY, columnIndex, pageNumber) {
272108
+ registerDrawing(drawingBlock, measure, resolvedAnchorY, columnIndex, pageNumber) {
272008
272109
  if (!drawingBlock.anchor?.isAnchored)
272009
272110
  return;
272010
272111
  const { wrap: wrap5, anchor } = drawingBlock;
@@ -272014,14 +272115,13 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
272014
272115
  const objectWidth = measure.width ?? 0;
272015
272116
  const objectHeight = measure.height ?? 0;
272016
272117
  const x = computeAnchorX(anchor, columnIndex, currentColumns, objectWidth, currentMargins, currentPageWidth);
272017
- const y$1 = anchorY + (anchor.offsetV ?? 0);
272018
272118
  const zone = {
272019
272119
  imageBlockId: drawingBlock.id,
272020
272120
  pageNumber,
272021
272121
  columnIndex,
272022
272122
  bounds: {
272023
272123
  x,
272024
- y: y$1,
272124
+ y: resolvedAnchorY,
272025
272125
  width: objectWidth,
272026
272126
  height: objectHeight
272027
272127
  },
@@ -272036,7 +272136,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
272036
272136
  };
272037
272137
  zones.push(zone);
272038
272138
  },
272039
- registerTable(tableBlock, measure, anchorY, columnIndex, pageNumber) {
272139
+ registerTable(tableBlock, measure, resolvedAnchorY, columnIndex, pageNumber) {
272040
272140
  if (!tableBlock.anchor?.isAnchored)
272041
272141
  return;
272042
272142
  const { wrap: wrap5, anchor } = tableBlock;
@@ -272045,14 +272145,13 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
272045
272145
  const tableWidth = measure.totalWidth ?? 0;
272046
272146
  const tableHeight = measure.totalHeight ?? 0;
272047
272147
  const x = computeTableAnchorX(anchor, columnIndex, currentColumns, tableWidth, currentMargins, currentPageWidth);
272048
- const y$1 = anchorY + (anchor.offsetV ?? 0);
272049
272148
  const zone = {
272050
272149
  imageBlockId: tableBlock.id,
272051
272150
  pageNumber,
272052
272151
  columnIndex,
272053
272152
  bounds: {
272054
272153
  x,
272055
- y: y$1,
272154
+ y: resolvedAnchorY,
272056
272155
  width: tableWidth,
272057
272156
  height: tableHeight
272058
272157
  },
@@ -272106,12 +272205,12 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
272106
272205
  rightFloats.push(zone);
272107
272206
  let leftBoundary = 0;
272108
272207
  for (const zone of leftFloats) {
272109
- const boundary = zone.bounds.x + zone.bounds.width + zone.distances.left + zone.distances.right;
272208
+ const boundary = zone.bounds.x + zone.bounds.width + zone.distances.right;
272110
272209
  leftBoundary = Math.max(leftBoundary, boundary);
272111
272210
  }
272112
272211
  let rightBoundary = columnOrigin + baseWidth;
272113
272212
  for (const zone of rightFloats) {
272114
- const boundary = zone.bounds.x - zone.distances.left - zone.distances.right;
272213
+ const boundary = zone.bounds.x - zone.distances.left;
272115
272214
  rightBoundary = Math.min(rightBoundary, boundary);
272116
272215
  }
272117
272216
  const availableWidth = rightBoundary - leftBoundary;
@@ -272141,27 +272240,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
272141
272240
  };
272142
272241
  }
272143
272242
  function computeAnchorX(anchor, columnIndex, columns, imageWidth, margins, pageWidth) {
272144
- const alignH = anchor.alignH ?? "left";
272145
- const offsetH = anchor.offsetH ?? 0;
272146
- const marginLeft = Math.max(0, margins?.left ?? 0);
272147
- const marginRight = Math.max(0, margins?.right ?? 0);
272148
- const contentWidth = pageWidth != null ? Math.max(1, pageWidth - (marginLeft + marginRight)) : columns.width;
272149
- const contentLeft = marginLeft;
272150
- const columnLeft = contentLeft + columnIndex * (columns.width + columns.gap);
272151
- const relativeFrom = anchor.hRelativeFrom ?? "column";
272152
- let baseX;
272153
- let availableWidth;
272154
- if (relativeFrom === "page") {
272155
- baseX = 0;
272156
- availableWidth = pageWidth != null ? pageWidth : contentWidth + marginLeft + marginRight;
272157
- } else if (relativeFrom === "margin") {
272158
- baseX = contentLeft;
272159
- availableWidth = contentWidth;
272160
- } else {
272161
- baseX = columnLeft;
272162
- availableWidth = columns.width;
272163
- }
272164
- return alignH === "left" ? baseX + offsetH : alignH === "right" ? baseX + availableWidth - imageWidth - offsetH : alignH === "center" ? baseX + (availableWidth - imageWidth) / 2 + offsetH : baseX;
272243
+ return resolveAnchoredGraphicX(anchor, columnIndex, columns, imageWidth, margins, pageWidth);
272165
272244
  }
272166
272245
  function computeWrapMode(wrap5, _anchor) {
272167
272246
  if (!wrap5)
@@ -272496,6 +272575,30 @@ function normalizeLines(measure) {
272496
272575
  function shouldSuppressOwnSpacing(ownStyleId, ownContextualSpacing, adjacentStyleId) {
272497
272576
  return ownContextualSpacing && !!ownStyleId && !!adjacentStyleId && ownStyleId === adjacentStyleId;
272498
272577
  }
272578
+ function collapseSpacingBefore(spacingBefore, trailingSpacing) {
272579
+ const prevTrailing = trailingSpacing ?? 0;
272580
+ return Math.max(spacingBefore - prevTrailing, 0);
272581
+ }
272582
+ function rewindPreviousParagraphTrailing(cursorY, trailingSpacing) {
272583
+ const prevTrailing = trailingSpacing ?? 0;
272584
+ return prevTrailing > 0 ? cursorY - prevTrailing : cursorY;
272585
+ }
272586
+ function computeParagraphContentStartY(cursorY, spacingBefore, appliedSpacingBefore, trailingSpacing) {
272587
+ if (appliedSpacingBefore || spacingBefore <= 0)
272588
+ return cursorY;
272589
+ return cursorY + collapseSpacingBefore(spacingBefore, trailingSpacing);
272590
+ }
272591
+ function computeParagraphLayoutStartY(input2) {
272592
+ let y$1 = input2.cursorY;
272593
+ let trailingForCollapse = input2.trailingSpacing;
272594
+ if (input2.rewindTrailingFromPrevious) {
272595
+ y$1 = rewindPreviousParagraphTrailing(y$1, input2.trailingSpacing);
272596
+ if ((input2.trailingSpacing ?? 0) > 0)
272597
+ trailingForCollapse = 0;
272598
+ }
272599
+ const effectiveSpacingBefore = input2.suppressSpacingBefore ? 0 : input2.spacingBefore;
272600
+ return computeParagraphContentStartY(y$1, effectiveSpacingBefore, effectiveSpacingBefore === 0, trailingForCollapse);
272601
+ }
272499
272602
  function calculateFirstLineIndent(block, measure) {
272500
272603
  const wordLayout = block.attrs?.wordLayout;
272501
272604
  if (!wordLayout?.firstLineIndentMode)
@@ -272511,52 +272614,75 @@ function layoutParagraphBlock(ctx$1, anchors) {
272511
272614
  const { block, measure, columnWidth, ensurePage, advanceColumn, columnX, floatManager } = ctx$1;
272512
272615
  const remeasureParagraph$1 = ctx$1.remeasureParagraph;
272513
272616
  const frame = getParagraphAttrs(block)?.frame;
272514
- if (anchors?.anchoredDrawings?.length)
272617
+ let lines = normalizeLines(measure);
272618
+ const measurementWidth = lines[0]?.maxWidth;
272619
+ const paraIndent = block.attrs?.indent;
272620
+ const indentLeft = typeof paraIndent?.left === "number" && Number.isFinite(paraIndent.left) ? paraIndent.left : 0;
272621
+ const indentRight = typeof paraIndent?.right === "number" && Number.isFinite(paraIndent.right) ? paraIndent.right : 0;
272622
+ const negativeLeftIndent = indentLeft < 0 ? indentLeft : 0;
272623
+ const negativeRightIndent = indentRight < 0 ? indentRight : 0;
272624
+ const remeasureWidth = Math.max(1, columnWidth - indentLeft - indentRight);
272625
+ let didRemeasureForColumnWidth = false;
272626
+ let remeasuredMarkerInfo;
272627
+ if (typeof remeasureParagraph$1 === "function" && typeof measurementWidth === "number" && measurementWidth > remeasureWidth) {
272628
+ const newMeasure = remeasureParagraph$1(block, columnWidth, calculateFirstLineIndent(block, measure));
272629
+ lines = normalizeLines(newMeasure);
272630
+ didRemeasureForColumnWidth = true;
272631
+ if (newMeasure.marker)
272632
+ remeasuredMarkerInfo = newMeasure.marker;
272633
+ }
272634
+ let fromLine = 0;
272635
+ const attrs = getParagraphAttrs(block);
272636
+ const spacing = attrs?.spacing ?? {};
272637
+ const spacingExplicit = attrs?.spacingExplicit;
272638
+ const styleId$1 = asString2(attrs?.styleId);
272639
+ const contextualSpacing = asBoolean$1(attrs?.contextualSpacing);
272640
+ let spacingBefore = Math.max(0, Number(spacing.before ?? spacing.lineSpaceBefore ?? 0));
272641
+ let spacingAfter = ctx$1.overrideSpacingAfter ?? Math.max(0, Number(spacing.after ?? spacing.lineSpaceAfter ?? 0));
272642
+ if (isEmptyTextParagraph(block) && spacingExplicit) {
272643
+ if (!spacingExplicit.before)
272644
+ spacingBefore = 0;
272645
+ if (!spacingExplicit.after)
272646
+ spacingAfter = 0;
272647
+ }
272648
+ const baseSpacingBefore = spacingBefore;
272649
+ let appliedSpacingBefore = spacingBefore === 0;
272650
+ let lastState = null;
272651
+ const previewState = ensurePage();
272652
+ const rawBorderExpansion = computeBorderVerticalExpansion(attrs?.borders);
272653
+ const currentBorderHash = hashBorders(attrs?.borders);
272654
+ const inBorderGroup = currentBorderHash != null && currentBorderHash === previewState.lastParagraphBorderHash;
272655
+ const borderExpansion = {
272656
+ top: inBorderGroup ? 0 : rawBorderExpansion.top,
272657
+ bottom: rawBorderExpansion.bottom
272658
+ };
272659
+ const paragraphAnchorBaseY = computeParagraphLayoutStartY({
272660
+ cursorY: previewState.cursorY,
272661
+ spacingBefore,
272662
+ trailingSpacing: previewState.trailingSpacing,
272663
+ suppressSpacingBefore: shouldSuppressOwnSpacing(styleId$1, contextualSpacing, previewState.lastParagraphStyleId),
272664
+ rewindTrailingFromPrevious: shouldSuppressOwnSpacing(previewState.lastParagraphStyleId, previewState.lastParagraphContextualSpacing, styleId$1)
272665
+ }) + borderExpansion.top - (inBorderGroup ? rawBorderExpansion.bottom : 0);
272666
+ const registerAnchoredDrawingsAt = (paragraphContentStartY) => {
272667
+ if (!anchors?.anchoredDrawings?.length)
272668
+ return;
272515
272669
  for (const entry of anchors.anchoredDrawings) {
272516
272670
  if (anchors.placedAnchoredIds.has(entry.block.id))
272517
272671
  continue;
272518
272672
  const state = ensurePage();
272519
- const vRelativeFrom = entry.block.anchor?.vRelativeFrom;
272520
- const alignV = entry.block.anchor?.alignV;
272521
- const offsetV = entry.block.anchor?.offsetV ?? 0;
272522
- const imageHeight = entry.measure.height;
272523
272673
  const contentTop = state.topMargin;
272524
272674
  const contentBottom = state.contentBottom;
272525
- const contentHeight = Math.max(0, contentBottom - contentTop);
272526
- let anchorY;
272527
- if (vRelativeFrom === "margin")
272528
- if (alignV === "top")
272529
- anchorY = contentTop + offsetV;
272530
- else if (alignV === "bottom")
272531
- anchorY = contentBottom - imageHeight + offsetV;
272532
- else if (alignV === "center")
272533
- anchorY = contentTop + (contentHeight - imageHeight) / 2 + offsetV;
272534
- else
272535
- anchorY = contentTop + offsetV;
272536
- else if (vRelativeFrom === "page")
272537
- if (alignV === "top")
272538
- anchorY = offsetV;
272539
- else if (alignV === "bottom")
272540
- anchorY = contentBottom + (anchors.pageMargins.bottom ?? 0) - imageHeight + offsetV;
272541
- else if (alignV === "center")
272542
- anchorY = (contentBottom + (anchors.pageMargins.bottom ?? 0) - imageHeight) / 2 + offsetV;
272543
- else
272544
- anchorY = offsetV;
272545
- else if (vRelativeFrom === "paragraph") {
272546
- const baseAnchorY = state.cursorY;
272547
- const firstLineHeight = measure.lines?.[0]?.lineHeight ?? 0;
272548
- if (alignV === "top")
272549
- anchorY = baseAnchorY + offsetV;
272550
- else if (alignV === "bottom")
272551
- anchorY = baseAnchorY + firstLineHeight - imageHeight + offsetV;
272552
- else if (alignV === "center")
272553
- anchorY = baseAnchorY + (firstLineHeight - imageHeight) / 2 + offsetV;
272554
- else
272555
- anchorY = baseAnchorY + offsetV;
272556
- } else
272557
- anchorY = state.cursorY + offsetV;
272675
+ const anchorY = resolveAnchoredGraphicY({
272676
+ anchor: entry.block.anchor,
272677
+ objectHeight: entry.measure.height,
272678
+ contentTop,
272679
+ contentBottom,
272680
+ pageBottomMargin: anchors.pageMargins.bottom ?? 0,
272681
+ anchorParagraphY: paragraphContentStartY,
272682
+ firstLineHeight: measure.lines?.[0]?.lineHeight ?? 0
272683
+ });
272558
272684
  floatManager.registerDrawing(entry.block, entry.measure, anchorY, state.columnIndex, state.page.number);
272559
- const anchorX = entry.block.anchor ? computeAnchorX(entry.block.anchor, state.columnIndex, anchors.columns, entry.measure.width, {
272685
+ const anchorX = entry.block.anchor ? resolveAnchoredGraphicX(entry.block.anchor, state.columnIndex, anchors.columns, entry.measure.width, {
272560
272686
  left: anchors.pageMargins.left,
272561
272687
  right: anchors.pageMargins.right
272562
272688
  }, anchors.pageWidth) : columnX(state.columnIndex);
@@ -272628,40 +272754,8 @@ function layoutParagraphBlock(ctx$1, anchors) {
272628
272754
  }
272629
272755
  anchors.placedAnchoredIds.add(entry.block.id);
272630
272756
  }
272631
- let lines = normalizeLines(measure);
272632
- const measurementWidth = lines[0]?.maxWidth;
272633
- const paraIndent = block.attrs?.indent;
272634
- const indentLeft = typeof paraIndent?.left === "number" && Number.isFinite(paraIndent.left) ? paraIndent.left : 0;
272635
- const indentRight = typeof paraIndent?.right === "number" && Number.isFinite(paraIndent.right) ? paraIndent.right : 0;
272636
- const negativeLeftIndent = indentLeft < 0 ? indentLeft : 0;
272637
- const negativeRightIndent = indentRight < 0 ? indentRight : 0;
272638
- const remeasureWidth = Math.max(1, columnWidth - indentLeft - indentRight);
272639
- let didRemeasureForColumnWidth = false;
272640
- let remeasuredMarkerInfo;
272641
- if (typeof remeasureParagraph$1 === "function" && typeof measurementWidth === "number" && measurementWidth > remeasureWidth) {
272642
- const newMeasure = remeasureParagraph$1(block, columnWidth, calculateFirstLineIndent(block, measure));
272643
- lines = normalizeLines(newMeasure);
272644
- didRemeasureForColumnWidth = true;
272645
- if (newMeasure.marker)
272646
- remeasuredMarkerInfo = newMeasure.marker;
272647
- }
272648
- let fromLine = 0;
272649
- const attrs = getParagraphAttrs(block);
272650
- const spacing = attrs?.spacing ?? {};
272651
- const spacingExplicit = attrs?.spacingExplicit;
272652
- const styleId$1 = asString2(attrs?.styleId);
272653
- const contextualSpacing = asBoolean$1(attrs?.contextualSpacing);
272654
- let spacingBefore = Math.max(0, Number(spacing.before ?? spacing.lineSpaceBefore ?? 0));
272655
- let spacingAfter = ctx$1.overrideSpacingAfter ?? Math.max(0, Number(spacing.after ?? spacing.lineSpaceAfter ?? 0));
272656
- if (isEmptyTextParagraph(block) && spacingExplicit) {
272657
- if (!spacingExplicit.before)
272658
- spacingBefore = 0;
272659
- if (!spacingExplicit.after)
272660
- spacingAfter = 0;
272661
- }
272662
- const baseSpacingBefore = spacingBefore;
272663
- let appliedSpacingBefore = spacingBefore === 0;
272664
- let lastState = null;
272757
+ };
272758
+ registerAnchoredDrawingsAt(paragraphAnchorBaseY);
272665
272759
  if (frame?.wrap === "none") {
272666
272760
  let state = ensurePage();
272667
272761
  if (state.cursorY >= state.contentBottom)
@@ -272703,12 +272797,7 @@ function layoutParagraphBlock(ctx$1, anchors) {
272703
272797
  let didRemeasureForFloats = false;
272704
272798
  if (typeof remeasureParagraph$1 === "function") {
272705
272799
  const tempState = ensurePage();
272706
- let tempY = tempState.cursorY;
272707
- if (!appliedSpacingBefore && spacingBefore > 0) {
272708
- const prevTrailing = tempState.trailingSpacing ?? 0;
272709
- const neededSpacingBefore = Math.max(spacingBefore - prevTrailing, 0);
272710
- tempY += neededSpacingBefore;
272711
- }
272800
+ let tempY = paragraphAnchorBaseY;
272712
272801
  for (let i4 = 0;i4 < lines.length; i4++) {
272713
272802
  const lineY = tempY;
272714
272803
  const lineHeight = lines[i4]?.lineHeight || 0;
@@ -272719,8 +272808,8 @@ function layoutParagraphBlock(ctx$1, anchors) {
272719
272808
  }
272720
272809
  tempY += lineHeight;
272721
272810
  }
272722
- const narrowestRemeasureWidth = Math.max(1, narrowestWidth - indentLeft - indentRight);
272723
- if (narrowestRemeasureWidth < remeasureWidth) {
272811
+ const narrowestRemeasureWidth = narrowestWidth < columnWidth || narrowestOffsetX > 0 ? Math.max(1, narrowestWidth - Math.max(indentLeft, 0) - Math.max(indentRight, 0)) : Math.max(1, narrowestWidth - indentLeft - indentRight);
272812
+ if (narrowestRemeasureWidth < remeasureWidth || narrowestOffsetX > 0) {
272724
272813
  const newMeasure = remeasureParagraph$1(block, narrowestRemeasureWidth, calculateFirstLineIndent(block, measure));
272725
272814
  lines = normalizeLines(newMeasure);
272726
272815
  didRemeasureForFloats = true;
@@ -272728,13 +272817,6 @@ function layoutParagraphBlock(ctx$1, anchors) {
272728
272817
  remeasuredMarkerInfo = newMeasure.marker;
272729
272818
  }
272730
272819
  }
272731
- const rawBorderExpansion = computeBorderVerticalExpansion(attrs?.borders);
272732
- const currentBorderHash = hashBorders(attrs?.borders);
272733
- const inBorderGroup = currentBorderHash != null && currentBorderHash === ensurePage().lastParagraphBorderHash;
272734
- const borderExpansion = {
272735
- top: inBorderGroup ? 0 : rawBorderExpansion.top,
272736
- bottom: rawBorderExpansion.bottom
272737
- };
272738
272820
  while (fromLine < lines.length) {
272739
272821
  let state = ensurePage();
272740
272822
  if (state.trailingSpacing == null)
@@ -272746,13 +272828,12 @@ function layoutParagraphBlock(ctx$1, anchors) {
272746
272828
  if (shouldSuppressOwnSpacing(state.lastParagraphStyleId, state.lastParagraphContextualSpacing, styleId$1)) {
272747
272829
  const prevTrailing = asSafeNumber(state.trailingSpacing);
272748
272830
  if (prevTrailing > 0) {
272749
- state.cursorY -= prevTrailing;
272831
+ state.cursorY = rewindPreviousParagraphTrailing(state.cursorY, prevTrailing);
272750
272832
  state.trailingSpacing = 0;
272751
272833
  }
272752
272834
  }
272753
272835
  if (attrs?.keepLines === true && fromLine === 0) {
272754
- const prevTrailing = state.trailingSpacing ?? 0;
272755
- const neededSpacingBefore = Math.max(spacingBefore - prevTrailing, 0);
272836
+ const neededSpacingBefore = collapseSpacingBefore(spacingBefore, state.trailingSpacing);
272756
272837
  const pageContentHeight = state.contentBottom - state.topMargin;
272757
272838
  const fullHeight = lines.reduce((sum, line) => sum + (line.lineHeight || 0), 0) + borderExpansion.top + borderExpansion.bottom;
272758
272839
  const fitsOnBlankPage = fullHeight + baseSpacingBefore <= pageContentHeight;
@@ -272766,8 +272847,8 @@ function layoutParagraphBlock(ctx$1, anchors) {
272766
272847
  }
272767
272848
  if (!appliedSpacingBefore && spacingBefore > 0)
272768
272849
  while (!appliedSpacingBefore) {
272769
- const prevTrailing = state.trailingSpacing ?? 0;
272770
- const neededSpacingBefore = Math.max(spacingBefore - prevTrailing, 0);
272850
+ state.trailingSpacing;
272851
+ const neededSpacingBefore = collapseSpacingBefore(spacingBefore, state.trailingSpacing);
272771
272852
  if (state.cursorY + neededSpacingBefore > state.contentBottom) {
272772
272853
  if (state.cursorY <= state.topMargin) {
272773
272854
  state.trailingSpacing = 0;
@@ -272889,8 +272970,12 @@ function layoutParagraphBlock(ctx$1, anchors) {
272889
272970
  state.footnoteAnchorsThisPage.push(a2);
272890
272971
  }
272891
272972
  }
272892
- const adjustedX = columnX(state.columnIndex) + offsetX + negativeLeftIndent;
272893
- const adjustedWidth = effectiveColumnWidth - negativeLeftIndent - negativeRightIndent;
272973
+ const floatAdjustedX = columnX(state.columnIndex) + offsetX;
272974
+ const adjustedX = didRemeasureForFloats ? floatAdjustedX + Math.max(negativeLeftIndent, 0) : floatAdjustedX + negativeLeftIndent;
272975
+ const columnRight = columnX(state.columnIndex) + columnWidth;
272976
+ let adjustedWidth = didRemeasureForFloats ? effectiveColumnWidth : effectiveColumnWidth - negativeLeftIndent - negativeRightIndent;
272977
+ if (didRemeasureForFloats)
272978
+ adjustedWidth = Math.min(adjustedWidth, Math.max(1, columnRight - adjustedX));
272894
272979
  const fragment2 = {
272895
272980
  kind: "para",
272896
272981
  blockId: block.id,
@@ -272902,7 +272987,7 @@ function layoutParagraphBlock(ctx$1, anchors) {
272902
272987
  sourceAnchor: block.sourceAnchor,
272903
272988
  ...computeFragmentPmRange2(block, lines, fromLine, slice2.toLine)
272904
272989
  };
272905
- if (didRemeasureForColumnWidth)
272990
+ if (didRemeasureForColumnWidth || didRemeasureForFloats)
272906
272991
  fragment2.lines = lines.slice(fromLine, slice2.toLine);
272907
272992
  if ((measure.marker || remeasuredMarkerInfo) && fromLine === 0) {
272908
272993
  fragment2.markerWidth = (remeasuredMarkerInfo ?? measure.marker)?.markerWidth ?? measure.marker?.markerWidth ?? 0;
@@ -274753,13 +274838,19 @@ function getBalancingHeight(fragment2, measureMap, sectPrMarkerBlockIds) {
274753
274838
  return 0;
274754
274839
  return getFragmentHeight(fragment2, measureMap);
274755
274840
  }
274841
+ function allColumnWidthsEqual(widths) {
274842
+ if (widths.length <= 1)
274843
+ return true;
274844
+ const first$1 = widths[0];
274845
+ return widths.every((w) => Math.abs(w - first$1) <= 0.5);
274846
+ }
274756
274847
  function balanceSectionOnPage(args$1) {
274757
274848
  const { sectionColumns, sectionHasExplicitColumnBreak, sectionIndex, blockSectionMap, fragments } = args$1;
274758
274849
  if (sectionColumns.count <= 1)
274759
274850
  return null;
274760
274851
  if (sectionHasExplicitColumnBreak)
274761
274852
  return null;
274762
- if (sectionColumns.equalWidth === false && Array.isArray(sectionColumns.widths) && sectionColumns.widths.length > 0)
274853
+ if (sectionColumns.equalWidth === false && Array.isArray(sectionColumns.widths) && sectionColumns.widths.length > 0 && !allColumnWidthsEqual(sectionColumns.widths))
274763
274854
  return null;
274764
274855
  const sectionFragments = fragments.filter((f2) => blockSectionMap.get(f2.blockId) === sectionIndex);
274765
274856
  if (sectionFragments.length === 0)
@@ -276012,58 +276103,28 @@ function layoutDocument(blocks2, measures, options = {}) {
276012
276103
  const resolveParagraphlessAnchoredTableY = (block, measure, state) => {
276013
276104
  const contentTop = state.topMargin;
276014
276105
  const contentBottom = state.contentBottom;
276015
- const contentHeight = Math.max(0, contentBottom - contentTop);
276016
276106
  const tableHeight = measure.totalHeight ?? 0;
276017
- const anchor = block.anchor;
276018
- const offsetV = anchor?.offsetV ?? 0;
276019
- const vRelativeFrom = anchor?.vRelativeFrom;
276020
- const alignV = anchor?.alignV;
276021
- if (vRelativeFrom === "margin") {
276022
- if (alignV === "bottom")
276023
- return contentBottom - tableHeight + offsetV;
276024
- if (alignV === "center")
276025
- return contentTop + (contentHeight - tableHeight) / 2 + offsetV;
276026
- return contentTop + offsetV;
276027
- }
276028
- if (vRelativeFrom === "page") {
276029
- if (alignV === "bottom")
276030
- return contentBottom + (state.page.margins?.bottom ?? activeBottomMargin) - tableHeight + offsetV;
276031
- if (alignV === "center")
276032
- return (contentBottom + (state.page.margins?.bottom ?? activeBottomMargin) - tableHeight) / 2 + offsetV;
276033
- return offsetV;
276034
- }
276035
- return contentTop + offsetV;
276107
+ return resolveAnchoredGraphicY({
276108
+ anchor: block.anchor,
276109
+ objectHeight: tableHeight,
276110
+ contentTop,
276111
+ contentBottom,
276112
+ pageBottomMargin: state.page.margins?.bottom ?? activeBottomMargin,
276113
+ preRegisteredFallbackToContentTop: true
276114
+ });
276036
276115
  };
276037
276116
  for (const entry of preRegisteredAnchors) {
276038
276117
  const state = paginator.ensurePage();
276039
- const vRelativeFrom = entry.block.anchor?.vRelativeFrom ?? "paragraph";
276040
- const alignV = entry.block.anchor?.alignV ?? "top";
276041
- const offsetV = entry.block.anchor?.offsetV ?? 0;
276042
- const imageHeight = entry.measure.height ?? 0;
276043
276118
  const contentTop = state.topMargin;
276044
276119
  const contentBottom = state.contentBottom;
276045
- const contentHeight = Math.max(0, contentBottom - contentTop);
276046
- let anchorY;
276047
- if (vRelativeFrom === "margin")
276048
- if (alignV === "top")
276049
- anchorY = contentTop + offsetV;
276050
- else if (alignV === "bottom")
276051
- anchorY = contentBottom - imageHeight + offsetV;
276052
- else if (alignV === "center")
276053
- anchorY = contentTop + (contentHeight - imageHeight) / 2 + offsetV;
276054
- else
276055
- anchorY = contentTop + offsetV;
276056
- else if (vRelativeFrom === "page")
276057
- if (alignV === "top")
276058
- anchorY = offsetV;
276059
- else if (alignV === "bottom")
276060
- anchorY = contentBottom + (state.page.margins?.bottom ?? activeBottomMargin) - imageHeight + offsetV;
276061
- else if (alignV === "center")
276062
- anchorY = (contentBottom + (state.page.margins?.bottom ?? activeBottomMargin) - imageHeight) / 2 + offsetV;
276063
- else
276064
- anchorY = offsetV;
276065
- else
276066
- anchorY = contentTop + offsetV;
276120
+ const anchorY = resolveAnchoredGraphicY({
276121
+ anchor: entry.block.anchor,
276122
+ objectHeight: entry.measure.height ?? 0,
276123
+ contentTop,
276124
+ contentBottom,
276125
+ pageBottomMargin: state.page.margins?.bottom ?? activeBottomMargin,
276126
+ preRegisteredFallbackToContentTop: true
276127
+ });
276067
276128
  const anchorX = entry.block.anchor ? computeAnchorX(entry.block.anchor, state.columnIndex, normalizeColumns(activeColumns, activePageSize.w - (activeLeftMargin + activeRightMargin)), entry.measure.width, {
276068
276129
  left: activeLeftMargin,
276069
276130
  right: activeRightMargin
@@ -276374,7 +276435,6 @@ function layoutDocument(blocks2, measures, options = {}) {
276374
276435
  overrideSpacingAfter = 0;
276375
276436
  }
276376
276437
  }
276377
- const paragraphStartY = paginator.ensurePage().cursorY;
276378
276438
  layoutParagraphBlock({
276379
276439
  block,
276380
276440
  measure,
@@ -276404,7 +276464,12 @@ function layoutDocument(blocks2, measures, options = {}) {
276404
276464
  if (tablesForPara) {
276405
276465
  const state = paginator.ensurePage();
276406
276466
  const columnWidthForTable = getCurrentColumnWidth();
276467
+ let anchorParagraphTopY = state.cursorY;
276468
+ for (const fragment2 of state.page.fragments)
276469
+ if (fragment2.kind === "para" && fragment2.blockId === block.id)
276470
+ anchorParagraphTopY = Math.min(anchorParagraphTopY, fragment2.y);
276407
276471
  let tableBottomY = state.cursorY;
276472
+ let nextStackY = state.cursorY;
276408
276473
  for (const { block: tableBlock, measure: tableMeasure } of tablesForPara) {
276409
276474
  if (placedAnchoredTableIds.has(tableBlock.id))
276410
276475
  continue;
@@ -276412,15 +276477,17 @@ function layoutDocument(blocks2, measures, options = {}) {
276412
276477
  if (columnWidthForTable > 0 && totalWidth >= columnWidthForTable * 0.99)
276413
276478
  continue;
276414
276479
  const offsetV = tableBlock.anchor?.offsetV ?? 0;
276415
- const anchorY = Math.max(paragraphStartY, state.cursorY) + offsetV;
276480
+ const anchorY = Math.max(anchorParagraphTopY, nextStackY) + offsetV;
276416
276481
  floatManager.registerTable(tableBlock, tableMeasure, anchorY, state.columnIndex, state.page.number);
276417
276482
  const tableFragment = createAnchoredTableFragment(tableBlock, tableMeasure, tableBlock.anchor?.offsetH ?? columnX(state.columnIndex), anchorY);
276418
276483
  state.page.fragments.push(tableFragment);
276419
276484
  placedAnchoredTableIds.add(tableBlock.id);
276420
276485
  if ((tableBlock.wrap?.type ?? "None") !== "None") {
276421
276486
  const bottom$1 = anchorY + (tableMeasure.totalHeight ?? 0);
276487
+ const distBottom = tableBlock.wrap?.distBottom ?? 0;
276422
276488
  if (bottom$1 > tableBottomY)
276423
276489
  tableBottomY = bottom$1;
276490
+ nextStackY = bottom$1 + distBottom;
276424
276491
  }
276425
276492
  }
276426
276493
  state.cursorY = tableBottomY;
@@ -310139,7 +310206,7 @@ menclose::after {
310139
310206
  return;
310140
310207
  if (this.#overrides.get(key2) === physical)
310141
310208
  return;
310142
- if ((BUNDLED_SUBSTITUTES[key2] ?? logicalFamily.trim()) === physical) {
310209
+ if (key2 === normalizeFamilyKey$2(physical)) {
310143
310210
  if (this.#overrides.delete(key2)) {
310144
310211
  this.#version += 1;
310145
310212
  this.#cachedSignature = null;
@@ -310191,12 +310258,41 @@ menclose::after {
310191
310258
  reason: "as_requested"
310192
310259
  };
310193
310260
  }
310261
+ #resolveFaceLadder(primary, face, hasFace) {
310262
+ const key2 = normalizeFamilyKey$2(primary);
310263
+ const override = this.#overrides.get(key2);
310264
+ if (override && hasFace(override, face.weight, face.style))
310265
+ return {
310266
+ physical: override,
310267
+ reason: "custom_mapping"
310268
+ };
310269
+ if (hasFace(primary, face.weight, face.style))
310270
+ return {
310271
+ physical: primary,
310272
+ reason: "registered_face"
310273
+ };
310274
+ const bundled = BUNDLED_SUBSTITUTES[key2];
310275
+ if (bundled && hasFace(bundled, face.weight, face.style))
310276
+ return {
310277
+ physical: bundled,
310278
+ reason: "bundled_substitute"
310279
+ };
310280
+ if (override || bundled)
310281
+ return {
310282
+ physical: primary,
310283
+ reason: "fallback_face_absent"
310284
+ };
310285
+ return {
310286
+ physical: primary,
310287
+ reason: "as_requested"
310288
+ };
310289
+ }
310194
310290
  resolveFontFamily(logicalFamily) {
310195
310291
  const primary = splitStack(logicalFamily)[0] ?? logicalFamily;
310196
310292
  const { physical, reason } = this.#physicalFor(primary);
310197
310293
  return {
310198
310294
  logicalFamily,
310199
- physicalFamily: physical,
310295
+ physicalFamily: stripFamilyQuotes(physical),
310200
310296
  reason
310201
310297
  };
310202
310298
  }
@@ -310213,23 +310309,11 @@ menclose::after {
310213
310309
  }
310214
310310
  resolveFace(logicalFamily, face, hasFace) {
310215
310311
  const primary = splitStack(logicalFamily)[0] ?? logicalFamily;
310216
- const { physical, reason } = this.#physicalFor(primary);
310217
- if (reason === "as_requested")
310218
- return {
310219
- logicalFamily,
310220
- physicalFamily: physical,
310221
- reason
310222
- };
310223
- if (hasFace(physical, face.weight, face.style))
310224
- return {
310225
- logicalFamily,
310226
- physicalFamily: physical,
310227
- reason
310228
- };
310312
+ const { physical, reason } = this.#resolveFaceLadder(primary, face, hasFace);
310229
310313
  return {
310230
310314
  logicalFamily,
310231
- physicalFamily: primary,
310232
- reason: "fallback_face_absent"
310315
+ physicalFamily: stripFamilyQuotes(physical),
310316
+ reason
310233
310317
  };
310234
310318
  }
310235
310319
  resolvePhysicalFamilyForFace(cssFontFamily, face, hasFace) {
@@ -310238,12 +310322,10 @@ menclose::after {
310238
310322
  const parts = splitStack(cssFontFamily);
310239
310323
  if (parts.length === 0)
310240
310324
  return cssFontFamily;
310241
- const { physical, reason } = this.#physicalFor(parts[0]);
310242
- if (reason === "as_requested")
310243
- return cssFontFamily;
310244
- if (!hasFace(physical, face.weight, face.style))
310245
- return cssFontFamily;
310246
- return [physical, ...parts.slice(1)].join(", ");
310325
+ const { physical, reason } = this.#resolveFaceLadder(parts[0], face, hasFace);
310326
+ if (reason === "custom_mapping" || reason === "bundled_substitute")
310327
+ return [physical, ...parts.slice(1)].join(", ");
310328
+ return cssFontFamily;
310247
310329
  }
310248
310330
  resolvePrimaryPhysicalFamily(family$1) {
310249
310331
  const primary = splitStack(family$1)[0] ?? family$1;
@@ -310271,6 +310353,7 @@ menclose::after {
310271
310353
  #faceInflight = /* @__PURE__ */ new Map;
310272
310354
  #faceSources = /* @__PURE__ */ new Map;
310273
310355
  #facesByFamily = /* @__PURE__ */ new Map;
310356
+ #providerFaceKeys = /* @__PURE__ */ new Set;
310274
310357
  #warnedFaceFailures = /* @__PURE__ */ new Set;
310275
310358
  constructor(options = {}) {
310276
310359
  this.#fontSet = options.fontSet ?? null;
@@ -310282,7 +310365,9 @@ menclose::after {
310282
310365
  register(descriptor) {
310283
310366
  const { family: family$1, source, descriptors: descriptors2 } = descriptor;
310284
310367
  const identitySource = typeof source === "string" ? canonicalizeFontSource(source) : source;
310285
- const key2 = faceKeyOf$1(family$1, normalizeWeight(descriptors2?.weight), normalizeStyle$1(descriptors2?.style));
310368
+ const weight = normalizeWeight(descriptors2?.weight);
310369
+ const style2 = normalizeStyle$1(descriptors2?.style);
310370
+ const key2 = faceKeyOf$1(family$1, weight, style2);
310286
310371
  if (typeof identitySource === "string") {
310287
310372
  const existingSource = this.#faceSources.get(key2);
310288
310373
  if (existingSource === identitySource)
@@ -310295,7 +310380,11 @@ menclose::after {
310295
310380
  throw new Error(`[superdoc] font face "${key2}" is already registered from a different source ("${existingSource}"); a registered face's source cannot be replaced`);
310296
310381
  }
310297
310382
  if (this.#FontFaceCtor && this.#fontSet) {
310298
- const face = new this.#FontFaceCtor(family$1, source, descriptors2);
310383
+ const face = new this.#FontFaceCtor(family$1, source, {
310384
+ ...descriptors2,
310385
+ weight,
310386
+ style: style2
310387
+ });
310299
310388
  this.#fontSet.add(face);
310300
310389
  this.#managed.set(family$1, face);
310301
310390
  }
@@ -310307,6 +310396,7 @@ menclose::after {
310307
310396
  }
310308
310397
  if (!this.#status.has(family$1))
310309
310398
  this.#status.set(family$1, "unloaded");
310399
+ this.#providerFaceKeys.add(key2);
310310
310400
  this.#trackFace(family$1, key2);
310311
310401
  if (!this.#faceStatus.has(key2))
310312
310402
  this.#faceStatus.set(key2, "unloaded");
@@ -310351,7 +310441,8 @@ menclose::after {
310351
310441
  return "unloaded";
310352
310442
  }
310353
310443
  hasFace(family$1, weight, style2) {
310354
- return this.#facesByFamily.get(normalizeFamilyKey$1(family$1))?.has(faceKeyOf$1(family$1, weight, style2)) ?? false;
310444
+ const key2 = faceKeyOf$1(family$1, weight, style2);
310445
+ return this.#providerFaceKeys.has(key2) && this.#faceStatus.get(key2) !== "failed";
310355
310446
  }
310356
310447
  isAvailable(family$1) {
310357
310448
  if (!this.#fontSet)
@@ -325737,6 +325828,7 @@ menclose::after {
325737
325828
  #requiredFaceKeys = /* @__PURE__ */ new Set;
325738
325829
  #seenAvailable = /* @__PURE__ */ new Set;
325739
325830
  #seenAvailableFaces = /* @__PURE__ */ new Set;
325831
+ #seenFailedFaces = /* @__PURE__ */ new Set;
325740
325832
  #lastSummary = null;
325741
325833
  #loadingDoneHandler = null;
325742
325834
  #lateLoadScheduler;
@@ -325812,9 +325904,18 @@ menclose::after {
325812
325904
  } catch {
325813
325905
  results = [];
325814
325906
  }
325815
- for (const result of results)
325907
+ const failedKeys = [];
325908
+ for (const result of results) {
325909
+ const key2 = faceKeyOf(result.request.family, result.request.weight, result.request.style);
325816
325910
  if (result.status === "loaded")
325817
- this.#seenAvailableFaces.add(faceKeyOf(result.request.family, result.request.weight, result.request.style));
325911
+ this.#seenAvailableFaces.add(key2);
325912
+ else if (result.status === "failed" && !this.#seenFailedFaces.has(key2)) {
325913
+ this.#seenFailedFaces.add(key2);
325914
+ failedKeys.push(key2);
325915
+ }
325916
+ }
325917
+ if (failedKeys.length > 0)
325918
+ this.#scheduleAvailabilityReflow(failedKeys);
325818
325919
  this.#lastSummary = summarizeFaces(results);
325819
325920
  return this.#lastSummary;
325820
325921
  }
@@ -325871,6 +325972,7 @@ menclose::after {
325871
325972
  this.#requiredFamilies = /* @__PURE__ */ new Set;
325872
325973
  this.#seenAvailable.clear();
325873
325974
  this.#seenAvailableFaces.clear();
325975
+ this.#seenFailedFaces.clear();
325874
325976
  this.#lastSummary = null;
325875
325977
  }
325876
325978
  dispose() {
@@ -325936,6 +326038,9 @@ menclose::after {
325936
326038
  }
325937
326039
  if (changedKeys.length === 0)
325938
326040
  return;
326041
+ this.#scheduleAvailabilityReflow(changedKeys);
326042
+ }
326043
+ #scheduleAvailabilityReflow(changedKeys) {
325939
326044
  this.#fontConfigVersion += 1;
325940
326045
  bumpFontConfigVersion();
325941
326046
  this.#invalidateCaches();
@@ -326035,8 +326140,13 @@ menclose::after {
326035
326140
  const registry2 = this.#getGate()?.resolveRegistry();
326036
326141
  if (!registry2)
326037
326142
  throw new Error("[superdoc] fonts.preload: the font registry is not ready yet");
326143
+ const hasFace = (family$1, weight, style2) => registry2.hasFace(family$1, weight, style2);
326144
+ const face = {
326145
+ weight: "400",
326146
+ style: "normal"
326147
+ };
326038
326148
  const requests = families.map((logical) => ({
326039
- family: this.#resolver.resolvePrimaryPhysicalFamily(logical),
326149
+ family: this.#resolver.resolveFace(logical, face, hasFace).physicalFamily,
326040
326150
  weight: "400",
326041
326151
  style: "normal"
326042
326152
  }));
@@ -326153,13 +326263,13 @@ menclose::after {
326153
326263
  return;
326154
326264
  console.log(...args$1);
326155
326265
  }, 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;
326156
- var init_src_DvgAvHbj_es = __esm(() => {
326266
+ var init_src_plIVvSkL_es = __esm(() => {
326157
326267
  init_rolldown_runtime_Bg48TavK_es();
326158
- init_SuperConverter_B9mZiCO9_es();
326268
+ init_SuperConverter_BSMYiYJm_es();
326159
326269
  init_jszip_C49i9kUs_es();
326160
326270
  init_xml_js_CqGKpaft_es();
326161
326271
  init_uuid_qzgm05fK_es();
326162
- init_create_headless_toolbar_pn_wKqsL_es();
326272
+ init_create_headless_toolbar_DeKyOdIi_es();
326163
326273
  init_constants_D_X7xF4s_es();
326164
326274
  init_dist_B8HfvhaK_es();
326165
326275
  init_unified_Dsuw2be5_es();
@@ -360868,11 +360978,11 @@ function print() { __p += __j.call(arguments, '') }
360868
360978
  ]);
360869
360979
  });
360870
360980
 
360871
- // ../../packages/superdoc/dist/chunks/create-super-doc-ui-CxQcY_QQ.es.js
360981
+ // ../../packages/superdoc/dist/chunks/create-super-doc-ui-CJMIa98h.es.js
360872
360982
  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;
360873
- var init_create_super_doc_ui_CxQcY_QQ_es = __esm(() => {
360874
- init_SuperConverter_B9mZiCO9_es();
360875
- init_create_headless_toolbar_pn_wKqsL_es();
360983
+ var init_create_super_doc_ui_CJMIa98h_es = __esm(() => {
360984
+ init_SuperConverter_BSMYiYJm_es();
360985
+ init_create_headless_toolbar_DeKyOdIi_es();
360876
360986
  MOD_ALIASES = new Set([
360877
360987
  "Mod",
360878
360988
  "Meta",
@@ -360914,16 +361024,16 @@ var init_zipper_yaJVJ4z9_es = __esm(() => {
360914
361024
 
360915
361025
  // ../../packages/superdoc/dist/super-editor.es.js
360916
361026
  var init_super_editor_es = __esm(() => {
360917
- init_src_DvgAvHbj_es();
360918
- init_SuperConverter_B9mZiCO9_es();
361027
+ init_src_plIVvSkL_es();
361028
+ init_SuperConverter_BSMYiYJm_es();
360919
361029
  init_jszip_C49i9kUs_es();
360920
361030
  init_xml_js_CqGKpaft_es();
360921
- init_create_headless_toolbar_pn_wKqsL_es();
361031
+ init_create_headless_toolbar_DeKyOdIi_es();
360922
361032
  init_constants_D_X7xF4s_es();
360923
361033
  init_dist_B8HfvhaK_es();
360924
361034
  init_unified_Dsuw2be5_es();
360925
361035
  init_DocxZipper_VodIk8WL_es();
360926
- init_create_super_doc_ui_CxQcY_QQ_es();
361036
+ init_create_super_doc_ui_CJMIa98h_es();
360927
361037
  init_ui_C5PAS9hY_es();
360928
361038
  init_eventemitter3_BnGqBE_Q_es();
360929
361039
  init_errors_CNaD6vcg_es();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc-dev/cli",
3
- "version": "0.16.0-next.23",
3
+ "version": "0.16.0-next.24",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "superdoc": "./dist/index.js"
@@ -33,11 +33,11 @@
33
33
  "access": "public"
34
34
  },
35
35
  "optionalDependencies": {
36
- "@superdoc-dev/cli-darwin-arm64": "0.16.0-next.23",
37
- "@superdoc-dev/cli-darwin-x64": "0.16.0-next.23",
38
- "@superdoc-dev/cli-linux-arm64": "0.16.0-next.23",
39
- "@superdoc-dev/cli-linux-x64": "0.16.0-next.23",
40
- "@superdoc-dev/cli-windows-x64": "0.16.0-next.23"
36
+ "@superdoc-dev/cli-darwin-arm64": "0.16.0-next.24",
37
+ "@superdoc-dev/cli-darwin-x64": "0.16.0-next.24",
38
+ "@superdoc-dev/cli-linux-arm64": "0.16.0-next.24",
39
+ "@superdoc-dev/cli-linux-x64": "0.16.0-next.24",
40
+ "@superdoc-dev/cli-windows-x64": "0.16.0-next.24"
41
41
  },
42
42
  "scripts": {
43
43
  "predev": "node scripts/ensure-superdoc-build.js",