@superdoc-dev/mcp 0.11.0-next.4 → 0.11.0-next.6

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 (3) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +615 -289
  3. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -52208,7 +52208,7 @@ var init_remark_gfm_BhnWr3yf_es = __esm(() => {
52208
52208
  emptyOptions2 = {};
52209
52209
  });
52210
52210
 
52211
- // ../../packages/superdoc/dist/chunks/SuperConverter-B9mZiCO9.es.js
52211
+ // ../../packages/superdoc/dist/chunks/SuperConverter-BSMYiYJm.es.js
52212
52212
  function getExtensionConfigField(extension$1, field, context = { name: "" }) {
52213
52213
  const fieldValue = extension$1.config[field];
52214
52214
  if (typeof fieldValue === "function")
@@ -62157,6 +62157,70 @@ function computeFragmentPmRange(block, lines, fromLine, toLine) {
62157
62157
  pmEnd
62158
62158
  };
62159
62159
  }
62160
+ function resolveAnchoredGraphicY(input) {
62161
+ const { anchor, objectHeight, contentTop, contentBottom, pageBottomMargin = 0, anchorParagraphY = contentTop, firstLineHeight = 0, preRegisteredFallbackToContentTop = false } = input;
62162
+ const offsetV = anchor?.offsetV ?? 0;
62163
+ const vRelativeFrom = anchor?.vRelativeFrom;
62164
+ const alignV = anchor?.alignV;
62165
+ const contentHeight = Math.max(0, contentBottom - contentTop);
62166
+ if (vRelativeFrom === "margin") {
62167
+ if (alignV === "bottom")
62168
+ return contentBottom - objectHeight + offsetV;
62169
+ if (alignV === "center")
62170
+ return contentTop + (contentHeight - objectHeight) / 2 + offsetV;
62171
+ return contentTop + offsetV;
62172
+ }
62173
+ if (vRelativeFrom === "page") {
62174
+ const pageHeight = contentBottom + pageBottomMargin;
62175
+ if (alignV === "bottom")
62176
+ return pageHeight - objectHeight + offsetV;
62177
+ if (alignV === "center")
62178
+ return (pageHeight - objectHeight) / 2 + offsetV;
62179
+ return offsetV;
62180
+ }
62181
+ if (vRelativeFrom === "paragraph") {
62182
+ if (preRegisteredFallbackToContentTop)
62183
+ return contentTop + offsetV;
62184
+ const baseAnchorY = anchorParagraphY;
62185
+ if (alignV === "bottom")
62186
+ return baseAnchorY + firstLineHeight - objectHeight + offsetV;
62187
+ if (alignV === "center")
62188
+ return baseAnchorY + (firstLineHeight - objectHeight) / 2 + offsetV;
62189
+ return baseAnchorY + offsetV;
62190
+ }
62191
+ if (preRegisteredFallbackToContentTop)
62192
+ return contentTop + offsetV;
62193
+ return anchorParagraphY + offsetV;
62194
+ }
62195
+ function resolveAnchoredGraphicX(anchor, columnIndex, columns, objectWidth, margins, pageWidth) {
62196
+ const alignH = anchor.alignH ?? "left";
62197
+ const offsetH = anchor.offsetH ?? 0;
62198
+ const marginLeft = Math.max(0, margins?.left ?? 0);
62199
+ const marginRight = Math.max(0, margins?.right ?? 0);
62200
+ const contentWidth = pageWidth != null ? Math.max(1, pageWidth - (marginLeft + marginRight)) : columns.width;
62201
+ const contentLeft = marginLeft;
62202
+ const columnLeft = contentLeft + columnIndex * (columns.width + columns.gap);
62203
+ const relativeFrom = anchor.hRelativeFrom ?? "column";
62204
+ let baseX;
62205
+ let availableWidth;
62206
+ if (relativeFrom === "page") {
62207
+ baseX = 0;
62208
+ availableWidth = pageWidth != null ? pageWidth : contentWidth + marginLeft + marginRight;
62209
+ } else if (relativeFrom === "margin") {
62210
+ baseX = contentLeft;
62211
+ availableWidth = contentWidth;
62212
+ } else {
62213
+ baseX = columnLeft;
62214
+ availableWidth = columns.width;
62215
+ }
62216
+ if (alignH === "left")
62217
+ return baseX + offsetH;
62218
+ if (alignH === "right")
62219
+ return baseX + availableWidth - objectWidth - offsetH;
62220
+ if (alignH === "center")
62221
+ return baseX + (availableWidth - objectWidth) / 2 + offsetH;
62222
+ return baseX;
62223
+ }
62160
62224
  function widthsEqual(a, b) {
62161
62225
  if (!a && !b)
62162
62226
  return true;
@@ -62183,10 +62247,12 @@ function cloneColumnLayout(columns) {
62183
62247
  }
62184
62248
  function normalizeColumnLayout(input, contentWidth, epsilon = 0.0001) {
62185
62249
  const rawCount = input && Number.isFinite(input.count) ? Math.floor(input.count) : 1;
62186
- const count = Math.max(1, rawCount || 1);
62250
+ let count = Math.max(1, rawCount || 1);
62187
62251
  const gap = Math.max(0, input?.gap ?? 0);
62252
+ 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) : [];
62253
+ if (explicitWidths.length > 0 && explicitWidths.length < count)
62254
+ count = explicitWidths.length;
62188
62255
  const availableWidth = contentWidth - gap * (count - 1);
62189
- 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) : [];
62190
62256
  let widths = explicitWidths.length > 0 ? explicitWidths.slice(0, count) : Array.from({ length: count }, () => availableWidth > 0 ? availableWidth / count : contentWidth);
62191
62257
  if (widths.length < count) {
62192
62258
  const remaining = Math.max(0, availableWidth - widths.reduce((sum, width$1) => sum + width$1, 0));
@@ -67621,6 +67687,8 @@ function handleImageNode$1(node2, params, isAnchor) {
67621
67687
  default:
67622
67688
  break;
67623
67689
  }
67690
+ if (wrap$1.type === "Square" || wrap$1.type === "Tight" || wrap$1.type === "Through" || wrap$1.type === "TopAndBottom")
67691
+ mergeAnchorPaddingIntoWrapDistances(wrap$1, padding);
67624
67692
  const docPr = node2.elements.find((el) => el.name === "wp:docPr");
67625
67693
  const isHidden = isDocPrHidden(docPr);
67626
67694
  let anchorData = null;
@@ -85691,18 +85759,22 @@ function extractColumns(elements) {
85691
85759
  const cols = elements.find((el) => el?.name === "w:cols");
85692
85760
  if (!cols?.attributes)
85693
85761
  return;
85694
- const count = parseColumnCount(cols.attributes["w:num"]);
85762
+ let count = parseColumnCount(cols.attributes["w:num"]);
85695
85763
  const withSeparator = parseColumnSeparator(cols.attributes["w:sep"]);
85696
85764
  const equalWidthRaw = cols.attributes["w:equalWidth"];
85697
85765
  const equalWidth = equalWidthRaw === "0" || equalWidthRaw === 0 || equalWidthRaw === false ? false : equalWidthRaw === "1" || equalWidthRaw === 1 || equalWidthRaw === true ? true : undefined;
85698
85766
  const columnChildren = Array.isArray(cols.elements) ? cols.elements.filter((child) => child?.name === "w:col") : [];
85699
- const gapInches = parseColumnGap(cols.attributes["w:space"] ?? columnChildren.find((child) => child?.attributes?.["w:space"] != null)?.attributes?.["w:space"]);
85767
+ const isExplicit = equalWidth === false;
85768
+ const firstChildSpace = columnChildren.find((child) => child?.attributes?.["w:space"] != null)?.attributes?.["w:space"];
85769
+ const gapInches = parseColumnGap(isExplicit ? firstChildSpace ?? 0 : cols.attributes["w:space"]);
85700
85770
  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);
85771
+ if (isExplicit && widths.length > 0)
85772
+ count = Math.min(count, widths.length);
85701
85773
  return {
85702
85774
  count,
85703
85775
  gap: gapInches * PX_PER_INCH$1,
85704
85776
  withSeparator,
85705
- ...widths.length > 0 ? { widths } : {},
85777
+ ...isExplicit && widths.length > 0 ? { widths } : {},
85706
85778
  ...equalWidth !== undefined ? { equalWidth } : {}
85707
85779
  };
85708
85780
  }
@@ -88546,6 +88618,8 @@ function imageNodeToBlock(node2, nextBlockId, positions, _trackedMeta, _trackedC
88546
88618
  const height = typeof size.height === "number" && Number.isFinite(size.height) ? size.height : undefined;
88547
88619
  const explicitDisplay = typeof attrs.display === "string" ? attrs.display : undefined;
88548
88620
  const normalizedWrap = normalizeWrap$1(attrs.wrap);
88621
+ if (normalizedWrap)
88622
+ mergeWrapDistancesFromPadding(normalizedWrap, toBoxSpacing$1(attrs.padding));
88549
88623
  let anchor = normalizeAnchorData(attrs.anchorData, attrs, normalizedWrap?.behindDoc);
88550
88624
  if (!anchor && normalizedWrap) {
88551
88625
  anchor = { isAnchored: true };
@@ -104019,6 +104093,17 @@ var isRegExp = (value) => {
104019
104093
  if (!hasValue || !hasPositive)
104020
104094
  return null;
104021
104095
  return `inset(${percentEdges.top ?? 0}% ${percentEdges.right ?? 0}% ${percentEdges.bottom ?? 0}% ${percentEdges.left ?? 0}%)`;
104096
+ }, mergeAnchorPaddingIntoWrapDistances = (wrap$1, padding) => {
104097
+ if (!wrap$1?.attrs || !padding)
104098
+ return;
104099
+ if (wrap$1.attrs.distTop == null && Number.isFinite(padding.top) && padding.top !== 0)
104100
+ wrap$1.attrs.distTop = padding.top;
104101
+ if (wrap$1.attrs.distBottom == null && Number.isFinite(padding.bottom) && padding.bottom !== 0)
104102
+ wrap$1.attrs.distBottom = padding.bottom;
104103
+ if (wrap$1.attrs.distLeft == null && Number.isFinite(padding.left) && padding.left !== 0)
104104
+ wrap$1.attrs.distLeft = padding.left;
104105
+ if (wrap$1.attrs.distRight == null && Number.isFinite(padding.right) && padding.right !== 0)
104106
+ wrap$1.attrs.distRight = padding.right;
104022
104107
  }, handleShapeDrawing = (params, node2, graphicData, size, padding, marginOffset, anchorData, wrap$1, isAnchor, isHidden) => {
104023
104108
  const wsp = graphicData.elements.find((el) => el.name === "wps:wsp");
104024
104109
  const textBoxContent = wsp.elements.find((el) => el.name === "wps:txbx")?.elements?.find((el) => el.name === "w:txbxContent");
@@ -112583,6 +112668,17 @@ var isRegExp = (value) => {
112583
112668
  const parsed = parseFloat(value);
112584
112669
  return Number.isFinite(parsed) ? parsed : undefined;
112585
112670
  }
112671
+ }, mergeWrapDistancesFromPadding = (wrap$1, padding) => {
112672
+ if (!padding || wrap$1.type === "None" || wrap$1.type === "Inline")
112673
+ return;
112674
+ if (wrap$1.distTop == null && padding.top != null)
112675
+ wrap$1.distTop = padding.top;
112676
+ if (wrap$1.distBottom == null && padding.bottom != null)
112677
+ wrap$1.distBottom = padding.bottom;
112678
+ if (wrap$1.distLeft == null && padding.left != null)
112679
+ wrap$1.distLeft = padding.left;
112680
+ if (wrap$1.distRight == null && padding.right != null)
112681
+ wrap$1.distRight = padding.right;
112586
112682
  }, normalizeColor = (value) => {
112587
112683
  if (typeof value !== "string")
112588
112684
  return;
@@ -114391,6 +114487,8 @@ var isRegExp = (value) => {
114391
114487
  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;
114392
114488
  }, buildDrawingBlock = (rawAttrs, nextBlockId, positions, node2, geometry, drawingKind, extraProps) => {
114393
114489
  const normalizedWrap = normalizeWrap$2(rawAttrs.wrap);
114490
+ if (normalizedWrap)
114491
+ mergeWrapDistancesFromPadding(normalizedWrap, toBoxSpacing(rawAttrs.padding));
114394
114492
  const sourceAnchor = isPlainObject4(rawAttrs.sourceAnchor) ? rawAttrs.sourceAnchor : undefined;
114395
114493
  const baseAnchor = normalizeAnchorData$1(rawAttrs.anchorData, rawAttrs, normalizedWrap?.behindDoc);
114396
114494
  const pos = positions.get(node2);
@@ -115445,7 +115543,7 @@ var isRegExp = (value) => {
115445
115543
  state.kern = kernNode.attributes["w:val"];
115446
115544
  }
115447
115545
  }, SuperConverter;
115448
- var init_SuperConverter_B9mZiCO9_es = __esm(() => {
115546
+ var init_SuperConverter_BSMYiYJm_es = __esm(() => {
115449
115547
  init_rolldown_runtime_Bg48TavK_es();
115450
115548
  init_jszip_C49i9kUs_es();
115451
115549
  init_xml_js_CqGKpaft_es();
@@ -154480,7 +154578,7 @@ var init_SuperConverter_B9mZiCO9_es = __esm(() => {
154480
154578
  };
154481
154579
  });
154482
154580
 
154483
- // ../../packages/superdoc/dist/chunks/create-headless-toolbar-pn-wKqsL.es.js
154581
+ // ../../packages/superdoc/dist/chunks/create-headless-toolbar-DeKyOdIi.es.js
154484
154582
  function parseSizeUnit(val = "0") {
154485
154583
  const length = val.toString() || "0";
154486
154584
  const value = Number.parseFloat(length);
@@ -164813,8 +164911,8 @@ var CSS_DIMENSION_REGEX, DOM_SIZE_UNITS, normalizeActorId = (value) => {
164813
164911
  }
164814
164912
  };
164815
164913
  };
164816
- var init_create_headless_toolbar_pn_wKqsL_es = __esm(() => {
164817
- init_SuperConverter_B9mZiCO9_es();
164914
+ var init_create_headless_toolbar_DeKyOdIi_es = __esm(() => {
164915
+ init_SuperConverter_BSMYiYJm_es();
164818
164916
  init_uuid_qzgm05fK_es();
164819
164917
  init_constants_D_X7xF4s_es();
164820
164918
  init_dist_B8HfvhaK_es();
@@ -219498,7 +219596,7 @@ var init_remark_gfm_eZN6yzWQ_es = __esm(() => {
219498
219596
  init_remark_gfm_BhnWr3yf_es();
219499
219597
  });
219500
219598
 
219501
- // ../../packages/superdoc/dist/chunks/src-B1aSE-tB.es.js
219599
+ // ../../packages/superdoc/dist/chunks/src-plIVvSkL.es.js
219502
219600
  function deleteProps(obj, propOrProps) {
219503
219601
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
219504
219602
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -259649,6 +259747,9 @@ function isSettled(status) {
259649
259747
  function normalizeFamilyKey$2(family$1) {
259650
259748
  return family$1.trim().replace(/^["']|["']$/g, "").toLowerCase();
259651
259749
  }
259750
+ function stripFamilyQuotes(family$1) {
259751
+ return family$1.trim().replace(/^["']|["']$/g, "");
259752
+ }
259652
259753
  function splitStack(cssFontFamily) {
259653
259754
  return cssFontFamily.split(",").map((part) => part.trim()).filter(Boolean);
259654
259755
  }
@@ -259661,8 +259762,8 @@ function resolveFontFamily2(logicalFamily) {
259661
259762
  function resolvePhysicalFamily(cssFontFamily) {
259662
259763
  return defaultResolver.resolvePhysicalFamily(cssFontFamily);
259663
259764
  }
259664
- function resolvePrimaryPhysicalFamily(family$1) {
259665
- return defaultResolver.resolvePrimaryPhysicalFamily(family$1);
259765
+ function resolveFace(logicalFamily, face, hasFace) {
259766
+ return defaultResolver.resolveFace(logicalFamily, face, hasFace);
259666
259767
  }
259667
259768
  function getFontConfigVersion() {
259668
259769
  return fontConfigVersion;
@@ -259772,6 +259873,40 @@ function buildFontReport(logicalFamilies, registry3, resolver2) {
259772
259873
  }
259773
259874
  return report;
259774
259875
  }
259876
+ function buildFaceReport(usedFaces, registry3, resolver2) {
259877
+ const hasFace = (family$1, weight, style2) => registry3.hasFace(family$1, weight, style2);
259878
+ const seen = /* @__PURE__ */ new Set;
259879
+ const report = [];
259880
+ for (const { logicalFamily, weight, style: style2 } of usedFaces) {
259881
+ if (!logicalFamily)
259882
+ continue;
259883
+ const key2 = `${logicalFamily.toLowerCase()}|${weight}|${style2}`;
259884
+ if (seen.has(key2))
259885
+ continue;
259886
+ seen.add(key2);
259887
+ const face = {
259888
+ weight,
259889
+ style: style2
259890
+ };
259891
+ const { physicalFamily, reason } = resolver2 ? resolver2.resolveFace(logicalFamily, face, hasFace) : resolveFace(logicalFamily, face, hasFace);
259892
+ const loadStatus = registry3.getFaceStatus({
259893
+ family: physicalFamily,
259894
+ weight,
259895
+ style: style2
259896
+ });
259897
+ const missing = reason === "fallback_face_absent" || isSettled(loadStatus) && loadStatus !== "loaded";
259898
+ report.push({
259899
+ logicalFamily,
259900
+ physicalFamily,
259901
+ reason,
259902
+ loadStatus,
259903
+ exportFamily: logicalFamily,
259904
+ missing,
259905
+ face
259906
+ });
259907
+ }
259908
+ return report;
259909
+ }
259775
259910
  function quoteFamily(family$1) {
259776
259911
  return `"${family$1.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
259777
259912
  }
@@ -261224,7 +261359,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
261224
261359
  let currentPageWidth = pageWidth;
261225
261360
  let marginLeft = Math.max(0, currentMargins?.left ?? 0);
261226
261361
  return {
261227
- registerDrawing(drawingBlock, measure, anchorY, columnIndex, pageNumber) {
261362
+ registerDrawing(drawingBlock, measure, resolvedAnchorY, columnIndex, pageNumber) {
261228
261363
  if (!drawingBlock.anchor?.isAnchored)
261229
261364
  return;
261230
261365
  const { wrap: wrap4, anchor } = drawingBlock;
@@ -261234,14 +261369,13 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
261234
261369
  const objectWidth = measure.width ?? 0;
261235
261370
  const objectHeight = measure.height ?? 0;
261236
261371
  const x = computeAnchorX(anchor, columnIndex, currentColumns, objectWidth, currentMargins, currentPageWidth);
261237
- const y$1 = anchorY + (anchor.offsetV ?? 0);
261238
261372
  const zone = {
261239
261373
  imageBlockId: drawingBlock.id,
261240
261374
  pageNumber,
261241
261375
  columnIndex,
261242
261376
  bounds: {
261243
261377
  x,
261244
- y: y$1,
261378
+ y: resolvedAnchorY,
261245
261379
  width: objectWidth,
261246
261380
  height: objectHeight
261247
261381
  },
@@ -261256,7 +261390,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
261256
261390
  };
261257
261391
  zones.push(zone);
261258
261392
  },
261259
- registerTable(tableBlock, measure, anchorY, columnIndex, pageNumber) {
261393
+ registerTable(tableBlock, measure, resolvedAnchorY, columnIndex, pageNumber) {
261260
261394
  if (!tableBlock.anchor?.isAnchored)
261261
261395
  return;
261262
261396
  const { wrap: wrap4, anchor } = tableBlock;
@@ -261265,14 +261399,13 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
261265
261399
  const tableWidth = measure.totalWidth ?? 0;
261266
261400
  const tableHeight = measure.totalHeight ?? 0;
261267
261401
  const x = computeTableAnchorX(anchor, columnIndex, currentColumns, tableWidth, currentMargins, currentPageWidth);
261268
- const y$1 = anchorY + (anchor.offsetV ?? 0);
261269
261402
  const zone = {
261270
261403
  imageBlockId: tableBlock.id,
261271
261404
  pageNumber,
261272
261405
  columnIndex,
261273
261406
  bounds: {
261274
261407
  x,
261275
- y: y$1,
261408
+ y: resolvedAnchorY,
261276
261409
  width: tableWidth,
261277
261410
  height: tableHeight
261278
261411
  },
@@ -261326,12 +261459,12 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
261326
261459
  rightFloats.push(zone);
261327
261460
  let leftBoundary = 0;
261328
261461
  for (const zone of leftFloats) {
261329
- const boundary = zone.bounds.x + zone.bounds.width + zone.distances.left + zone.distances.right;
261462
+ const boundary = zone.bounds.x + zone.bounds.width + zone.distances.right;
261330
261463
  leftBoundary = Math.max(leftBoundary, boundary);
261331
261464
  }
261332
261465
  let rightBoundary = columnOrigin + baseWidth;
261333
261466
  for (const zone of rightFloats) {
261334
- const boundary = zone.bounds.x - zone.distances.left - zone.distances.right;
261467
+ const boundary = zone.bounds.x - zone.distances.left;
261335
261468
  rightBoundary = Math.min(rightBoundary, boundary);
261336
261469
  }
261337
261470
  const availableWidth = rightBoundary - leftBoundary;
@@ -261361,27 +261494,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
261361
261494
  };
261362
261495
  }
261363
261496
  function computeAnchorX(anchor, columnIndex, columns, imageWidth, margins, pageWidth) {
261364
- const alignH = anchor.alignH ?? "left";
261365
- const offsetH = anchor.offsetH ?? 0;
261366
- const marginLeft = Math.max(0, margins?.left ?? 0);
261367
- const marginRight = Math.max(0, margins?.right ?? 0);
261368
- const contentWidth = pageWidth != null ? Math.max(1, pageWidth - (marginLeft + marginRight)) : columns.width;
261369
- const contentLeft = marginLeft;
261370
- const columnLeft = contentLeft + columnIndex * (columns.width + columns.gap);
261371
- const relativeFrom = anchor.hRelativeFrom ?? "column";
261372
- let baseX;
261373
- let availableWidth;
261374
- if (relativeFrom === "page") {
261375
- baseX = 0;
261376
- availableWidth = pageWidth != null ? pageWidth : contentWidth + marginLeft + marginRight;
261377
- } else if (relativeFrom === "margin") {
261378
- baseX = contentLeft;
261379
- availableWidth = contentWidth;
261380
- } else {
261381
- baseX = columnLeft;
261382
- availableWidth = columns.width;
261383
- }
261384
- return alignH === "left" ? baseX + offsetH : alignH === "right" ? baseX + availableWidth - imageWidth - offsetH : alignH === "center" ? baseX + (availableWidth - imageWidth) / 2 + offsetH : baseX;
261497
+ return resolveAnchoredGraphicX(anchor, columnIndex, columns, imageWidth, margins, pageWidth);
261385
261498
  }
261386
261499
  function computeWrapMode(wrap4, _anchor) {
261387
261500
  if (!wrap4)
@@ -261716,6 +261829,30 @@ function normalizeLines(measure) {
261716
261829
  function shouldSuppressOwnSpacing(ownStyleId, ownContextualSpacing, adjacentStyleId) {
261717
261830
  return ownContextualSpacing && !!ownStyleId && !!adjacentStyleId && ownStyleId === adjacentStyleId;
261718
261831
  }
261832
+ function collapseSpacingBefore(spacingBefore, trailingSpacing) {
261833
+ const prevTrailing = trailingSpacing ?? 0;
261834
+ return Math.max(spacingBefore - prevTrailing, 0);
261835
+ }
261836
+ function rewindPreviousParagraphTrailing(cursorY, trailingSpacing) {
261837
+ const prevTrailing = trailingSpacing ?? 0;
261838
+ return prevTrailing > 0 ? cursorY - prevTrailing : cursorY;
261839
+ }
261840
+ function computeParagraphContentStartY(cursorY, spacingBefore, appliedSpacingBefore, trailingSpacing) {
261841
+ if (appliedSpacingBefore || spacingBefore <= 0)
261842
+ return cursorY;
261843
+ return cursorY + collapseSpacingBefore(spacingBefore, trailingSpacing);
261844
+ }
261845
+ function computeParagraphLayoutStartY(input2) {
261846
+ let y$1 = input2.cursorY;
261847
+ let trailingForCollapse = input2.trailingSpacing;
261848
+ if (input2.rewindTrailingFromPrevious) {
261849
+ y$1 = rewindPreviousParagraphTrailing(y$1, input2.trailingSpacing);
261850
+ if ((input2.trailingSpacing ?? 0) > 0)
261851
+ trailingForCollapse = 0;
261852
+ }
261853
+ const effectiveSpacingBefore = input2.suppressSpacingBefore ? 0 : input2.spacingBefore;
261854
+ return computeParagraphContentStartY(y$1, effectiveSpacingBefore, effectiveSpacingBefore === 0, trailingForCollapse);
261855
+ }
261719
261856
  function calculateFirstLineIndent(block, measure) {
261720
261857
  const wordLayout = block.attrs?.wordLayout;
261721
261858
  if (!wordLayout?.firstLineIndentMode)
@@ -261731,52 +261868,75 @@ function layoutParagraphBlock(ctx$1, anchors) {
261731
261868
  const { block, measure, columnWidth, ensurePage, advanceColumn, columnX, floatManager } = ctx$1;
261732
261869
  const remeasureParagraph$1 = ctx$1.remeasureParagraph;
261733
261870
  const frame = getParagraphAttrs(block)?.frame;
261734
- if (anchors?.anchoredDrawings?.length)
261871
+ let lines = normalizeLines(measure);
261872
+ const measurementWidth = lines[0]?.maxWidth;
261873
+ const paraIndent = block.attrs?.indent;
261874
+ const indentLeft = typeof paraIndent?.left === "number" && Number.isFinite(paraIndent.left) ? paraIndent.left : 0;
261875
+ const indentRight = typeof paraIndent?.right === "number" && Number.isFinite(paraIndent.right) ? paraIndent.right : 0;
261876
+ const negativeLeftIndent = indentLeft < 0 ? indentLeft : 0;
261877
+ const negativeRightIndent = indentRight < 0 ? indentRight : 0;
261878
+ const remeasureWidth = Math.max(1, columnWidth - indentLeft - indentRight);
261879
+ let didRemeasureForColumnWidth = false;
261880
+ let remeasuredMarkerInfo;
261881
+ if (typeof remeasureParagraph$1 === "function" && typeof measurementWidth === "number" && measurementWidth > remeasureWidth) {
261882
+ const newMeasure = remeasureParagraph$1(block, columnWidth, calculateFirstLineIndent(block, measure));
261883
+ lines = normalizeLines(newMeasure);
261884
+ didRemeasureForColumnWidth = true;
261885
+ if (newMeasure.marker)
261886
+ remeasuredMarkerInfo = newMeasure.marker;
261887
+ }
261888
+ let fromLine = 0;
261889
+ const attrs = getParagraphAttrs(block);
261890
+ const spacing = attrs?.spacing ?? {};
261891
+ const spacingExplicit = attrs?.spacingExplicit;
261892
+ const styleId$1 = asString2(attrs?.styleId);
261893
+ const contextualSpacing = asBoolean$1(attrs?.contextualSpacing);
261894
+ let spacingBefore = Math.max(0, Number(spacing.before ?? spacing.lineSpaceBefore ?? 0));
261895
+ let spacingAfter = ctx$1.overrideSpacingAfter ?? Math.max(0, Number(spacing.after ?? spacing.lineSpaceAfter ?? 0));
261896
+ if (isEmptyTextParagraph(block) && spacingExplicit) {
261897
+ if (!spacingExplicit.before)
261898
+ spacingBefore = 0;
261899
+ if (!spacingExplicit.after)
261900
+ spacingAfter = 0;
261901
+ }
261902
+ const baseSpacingBefore = spacingBefore;
261903
+ let appliedSpacingBefore = spacingBefore === 0;
261904
+ let lastState = null;
261905
+ const previewState = ensurePage();
261906
+ const rawBorderExpansion = computeBorderVerticalExpansion(attrs?.borders);
261907
+ const currentBorderHash = hashBorders(attrs?.borders);
261908
+ const inBorderGroup = currentBorderHash != null && currentBorderHash === previewState.lastParagraphBorderHash;
261909
+ const borderExpansion = {
261910
+ top: inBorderGroup ? 0 : rawBorderExpansion.top,
261911
+ bottom: rawBorderExpansion.bottom
261912
+ };
261913
+ const paragraphAnchorBaseY = computeParagraphLayoutStartY({
261914
+ cursorY: previewState.cursorY,
261915
+ spacingBefore,
261916
+ trailingSpacing: previewState.trailingSpacing,
261917
+ suppressSpacingBefore: shouldSuppressOwnSpacing(styleId$1, contextualSpacing, previewState.lastParagraphStyleId),
261918
+ rewindTrailingFromPrevious: shouldSuppressOwnSpacing(previewState.lastParagraphStyleId, previewState.lastParagraphContextualSpacing, styleId$1)
261919
+ }) + borderExpansion.top - (inBorderGroup ? rawBorderExpansion.bottom : 0);
261920
+ const registerAnchoredDrawingsAt = (paragraphContentStartY) => {
261921
+ if (!anchors?.anchoredDrawings?.length)
261922
+ return;
261735
261923
  for (const entry of anchors.anchoredDrawings) {
261736
261924
  if (anchors.placedAnchoredIds.has(entry.block.id))
261737
261925
  continue;
261738
261926
  const state = ensurePage();
261739
- const vRelativeFrom = entry.block.anchor?.vRelativeFrom;
261740
- const alignV = entry.block.anchor?.alignV;
261741
- const offsetV = entry.block.anchor?.offsetV ?? 0;
261742
- const imageHeight = entry.measure.height;
261743
261927
  const contentTop = state.topMargin;
261744
261928
  const contentBottom = state.contentBottom;
261745
- const contentHeight = Math.max(0, contentBottom - contentTop);
261746
- let anchorY;
261747
- if (vRelativeFrom === "margin")
261748
- if (alignV === "top")
261749
- anchorY = contentTop + offsetV;
261750
- else if (alignV === "bottom")
261751
- anchorY = contentBottom - imageHeight + offsetV;
261752
- else if (alignV === "center")
261753
- anchorY = contentTop + (contentHeight - imageHeight) / 2 + offsetV;
261754
- else
261755
- anchorY = contentTop + offsetV;
261756
- else if (vRelativeFrom === "page")
261757
- if (alignV === "top")
261758
- anchorY = offsetV;
261759
- else if (alignV === "bottom")
261760
- anchorY = contentBottom + (anchors.pageMargins.bottom ?? 0) - imageHeight + offsetV;
261761
- else if (alignV === "center")
261762
- anchorY = (contentBottom + (anchors.pageMargins.bottom ?? 0) - imageHeight) / 2 + offsetV;
261763
- else
261764
- anchorY = offsetV;
261765
- else if (vRelativeFrom === "paragraph") {
261766
- const baseAnchorY = state.cursorY;
261767
- const firstLineHeight = measure.lines?.[0]?.lineHeight ?? 0;
261768
- if (alignV === "top")
261769
- anchorY = baseAnchorY + offsetV;
261770
- else if (alignV === "bottom")
261771
- anchorY = baseAnchorY + firstLineHeight - imageHeight + offsetV;
261772
- else if (alignV === "center")
261773
- anchorY = baseAnchorY + (firstLineHeight - imageHeight) / 2 + offsetV;
261774
- else
261775
- anchorY = baseAnchorY + offsetV;
261776
- } else
261777
- anchorY = state.cursorY + offsetV;
261929
+ const anchorY = resolveAnchoredGraphicY({
261930
+ anchor: entry.block.anchor,
261931
+ objectHeight: entry.measure.height,
261932
+ contentTop,
261933
+ contentBottom,
261934
+ pageBottomMargin: anchors.pageMargins.bottom ?? 0,
261935
+ anchorParagraphY: paragraphContentStartY,
261936
+ firstLineHeight: measure.lines?.[0]?.lineHeight ?? 0
261937
+ });
261778
261938
  floatManager.registerDrawing(entry.block, entry.measure, anchorY, state.columnIndex, state.page.number);
261779
- const anchorX = entry.block.anchor ? computeAnchorX(entry.block.anchor, state.columnIndex, anchors.columns, entry.measure.width, {
261939
+ const anchorX = entry.block.anchor ? resolveAnchoredGraphicX(entry.block.anchor, state.columnIndex, anchors.columns, entry.measure.width, {
261780
261940
  left: anchors.pageMargins.left,
261781
261941
  right: anchors.pageMargins.right
261782
261942
  }, anchors.pageWidth) : columnX(state.columnIndex);
@@ -261848,40 +262008,8 @@ function layoutParagraphBlock(ctx$1, anchors) {
261848
262008
  }
261849
262009
  anchors.placedAnchoredIds.add(entry.block.id);
261850
262010
  }
261851
- let lines = normalizeLines(measure);
261852
- const measurementWidth = lines[0]?.maxWidth;
261853
- const paraIndent = block.attrs?.indent;
261854
- const indentLeft = typeof paraIndent?.left === "number" && Number.isFinite(paraIndent.left) ? paraIndent.left : 0;
261855
- const indentRight = typeof paraIndent?.right === "number" && Number.isFinite(paraIndent.right) ? paraIndent.right : 0;
261856
- const negativeLeftIndent = indentLeft < 0 ? indentLeft : 0;
261857
- const negativeRightIndent = indentRight < 0 ? indentRight : 0;
261858
- const remeasureWidth = Math.max(1, columnWidth - indentLeft - indentRight);
261859
- let didRemeasureForColumnWidth = false;
261860
- let remeasuredMarkerInfo;
261861
- if (typeof remeasureParagraph$1 === "function" && typeof measurementWidth === "number" && measurementWidth > remeasureWidth) {
261862
- const newMeasure = remeasureParagraph$1(block, columnWidth, calculateFirstLineIndent(block, measure));
261863
- lines = normalizeLines(newMeasure);
261864
- didRemeasureForColumnWidth = true;
261865
- if (newMeasure.marker)
261866
- remeasuredMarkerInfo = newMeasure.marker;
261867
- }
261868
- let fromLine = 0;
261869
- const attrs = getParagraphAttrs(block);
261870
- const spacing = attrs?.spacing ?? {};
261871
- const spacingExplicit = attrs?.spacingExplicit;
261872
- const styleId$1 = asString2(attrs?.styleId);
261873
- const contextualSpacing = asBoolean$1(attrs?.contextualSpacing);
261874
- let spacingBefore = Math.max(0, Number(spacing.before ?? spacing.lineSpaceBefore ?? 0));
261875
- let spacingAfter = ctx$1.overrideSpacingAfter ?? Math.max(0, Number(spacing.after ?? spacing.lineSpaceAfter ?? 0));
261876
- if (isEmptyTextParagraph(block) && spacingExplicit) {
261877
- if (!spacingExplicit.before)
261878
- spacingBefore = 0;
261879
- if (!spacingExplicit.after)
261880
- spacingAfter = 0;
261881
- }
261882
- const baseSpacingBefore = spacingBefore;
261883
- let appliedSpacingBefore = spacingBefore === 0;
261884
- let lastState = null;
262011
+ };
262012
+ registerAnchoredDrawingsAt(paragraphAnchorBaseY);
261885
262013
  if (frame?.wrap === "none") {
261886
262014
  let state = ensurePage();
261887
262015
  if (state.cursorY >= state.contentBottom)
@@ -261923,12 +262051,7 @@ function layoutParagraphBlock(ctx$1, anchors) {
261923
262051
  let didRemeasureForFloats = false;
261924
262052
  if (typeof remeasureParagraph$1 === "function") {
261925
262053
  const tempState = ensurePage();
261926
- let tempY = tempState.cursorY;
261927
- if (!appliedSpacingBefore && spacingBefore > 0) {
261928
- const prevTrailing = tempState.trailingSpacing ?? 0;
261929
- const neededSpacingBefore = Math.max(spacingBefore - prevTrailing, 0);
261930
- tempY += neededSpacingBefore;
261931
- }
262054
+ let tempY = paragraphAnchorBaseY;
261932
262055
  for (let i4 = 0;i4 < lines.length; i4++) {
261933
262056
  const lineY = tempY;
261934
262057
  const lineHeight = lines[i4]?.lineHeight || 0;
@@ -261939,8 +262062,8 @@ function layoutParagraphBlock(ctx$1, anchors) {
261939
262062
  }
261940
262063
  tempY += lineHeight;
261941
262064
  }
261942
- const narrowestRemeasureWidth = Math.max(1, narrowestWidth - indentLeft - indentRight);
261943
- if (narrowestRemeasureWidth < remeasureWidth) {
262065
+ const narrowestRemeasureWidth = narrowestWidth < columnWidth || narrowestOffsetX > 0 ? Math.max(1, narrowestWidth - Math.max(indentLeft, 0) - Math.max(indentRight, 0)) : Math.max(1, narrowestWidth - indentLeft - indentRight);
262066
+ if (narrowestRemeasureWidth < remeasureWidth || narrowestOffsetX > 0) {
261944
262067
  const newMeasure = remeasureParagraph$1(block, narrowestRemeasureWidth, calculateFirstLineIndent(block, measure));
261945
262068
  lines = normalizeLines(newMeasure);
261946
262069
  didRemeasureForFloats = true;
@@ -261948,13 +262071,6 @@ function layoutParagraphBlock(ctx$1, anchors) {
261948
262071
  remeasuredMarkerInfo = newMeasure.marker;
261949
262072
  }
261950
262073
  }
261951
- const rawBorderExpansion = computeBorderVerticalExpansion(attrs?.borders);
261952
- const currentBorderHash = hashBorders(attrs?.borders);
261953
- const inBorderGroup = currentBorderHash != null && currentBorderHash === ensurePage().lastParagraphBorderHash;
261954
- const borderExpansion = {
261955
- top: inBorderGroup ? 0 : rawBorderExpansion.top,
261956
- bottom: rawBorderExpansion.bottom
261957
- };
261958
262074
  while (fromLine < lines.length) {
261959
262075
  let state = ensurePage();
261960
262076
  if (state.trailingSpacing == null)
@@ -261966,13 +262082,12 @@ function layoutParagraphBlock(ctx$1, anchors) {
261966
262082
  if (shouldSuppressOwnSpacing(state.lastParagraphStyleId, state.lastParagraphContextualSpacing, styleId$1)) {
261967
262083
  const prevTrailing = asSafeNumber(state.trailingSpacing);
261968
262084
  if (prevTrailing > 0) {
261969
- state.cursorY -= prevTrailing;
262085
+ state.cursorY = rewindPreviousParagraphTrailing(state.cursorY, prevTrailing);
261970
262086
  state.trailingSpacing = 0;
261971
262087
  }
261972
262088
  }
261973
262089
  if (attrs?.keepLines === true && fromLine === 0) {
261974
- const prevTrailing = state.trailingSpacing ?? 0;
261975
- const neededSpacingBefore = Math.max(spacingBefore - prevTrailing, 0);
262090
+ const neededSpacingBefore = collapseSpacingBefore(spacingBefore, state.trailingSpacing);
261976
262091
  const pageContentHeight = state.contentBottom - state.topMargin;
261977
262092
  const fullHeight = lines.reduce((sum, line) => sum + (line.lineHeight || 0), 0) + borderExpansion.top + borderExpansion.bottom;
261978
262093
  const fitsOnBlankPage = fullHeight + baseSpacingBefore <= pageContentHeight;
@@ -261986,8 +262101,8 @@ function layoutParagraphBlock(ctx$1, anchors) {
261986
262101
  }
261987
262102
  if (!appliedSpacingBefore && spacingBefore > 0)
261988
262103
  while (!appliedSpacingBefore) {
261989
- const prevTrailing = state.trailingSpacing ?? 0;
261990
- const neededSpacingBefore = Math.max(spacingBefore - prevTrailing, 0);
262104
+ state.trailingSpacing;
262105
+ const neededSpacingBefore = collapseSpacingBefore(spacingBefore, state.trailingSpacing);
261991
262106
  if (state.cursorY + neededSpacingBefore > state.contentBottom) {
261992
262107
  if (state.cursorY <= state.topMargin) {
261993
262108
  state.trailingSpacing = 0;
@@ -262109,8 +262224,12 @@ function layoutParagraphBlock(ctx$1, anchors) {
262109
262224
  state.footnoteAnchorsThisPage.push(a2);
262110
262225
  }
262111
262226
  }
262112
- const adjustedX = columnX(state.columnIndex) + offsetX + negativeLeftIndent;
262113
- const adjustedWidth = effectiveColumnWidth - negativeLeftIndent - negativeRightIndent;
262227
+ const floatAdjustedX = columnX(state.columnIndex) + offsetX;
262228
+ const adjustedX = didRemeasureForFloats ? floatAdjustedX + Math.max(negativeLeftIndent, 0) : floatAdjustedX + negativeLeftIndent;
262229
+ const columnRight = columnX(state.columnIndex) + columnWidth;
262230
+ let adjustedWidth = didRemeasureForFloats ? effectiveColumnWidth : effectiveColumnWidth - negativeLeftIndent - negativeRightIndent;
262231
+ if (didRemeasureForFloats)
262232
+ adjustedWidth = Math.min(adjustedWidth, Math.max(1, columnRight - adjustedX));
262114
262233
  const fragment = {
262115
262234
  kind: "para",
262116
262235
  blockId: block.id,
@@ -262122,7 +262241,7 @@ function layoutParagraphBlock(ctx$1, anchors) {
262122
262241
  sourceAnchor: block.sourceAnchor,
262123
262242
  ...computeFragmentPmRange2(block, lines, fromLine, slice2.toLine)
262124
262243
  };
262125
- if (didRemeasureForColumnWidth)
262244
+ if (didRemeasureForColumnWidth || didRemeasureForFloats)
262126
262245
  fragment.lines = lines.slice(fromLine, slice2.toLine);
262127
262246
  if ((measure.marker || remeasuredMarkerInfo) && fromLine === 0) {
262128
262247
  fragment.markerWidth = (remeasuredMarkerInfo ?? measure.marker)?.markerWidth ?? measure.marker?.markerWidth ?? 0;
@@ -263973,13 +264092,19 @@ function getBalancingHeight(fragment, measureMap, sectPrMarkerBlockIds) {
263973
264092
  return 0;
263974
264093
  return getFragmentHeight(fragment, measureMap);
263975
264094
  }
264095
+ function allColumnWidthsEqual(widths) {
264096
+ if (widths.length <= 1)
264097
+ return true;
264098
+ const first$1 = widths[0];
264099
+ return widths.every((w) => Math.abs(w - first$1) <= 0.5);
264100
+ }
263976
264101
  function balanceSectionOnPage(args$1) {
263977
264102
  const { sectionColumns, sectionHasExplicitColumnBreak, sectionIndex, blockSectionMap, fragments } = args$1;
263978
264103
  if (sectionColumns.count <= 1)
263979
264104
  return null;
263980
264105
  if (sectionHasExplicitColumnBreak)
263981
264106
  return null;
263982
- if (sectionColumns.equalWidth === false && Array.isArray(sectionColumns.widths) && sectionColumns.widths.length > 0)
264107
+ if (sectionColumns.equalWidth === false && Array.isArray(sectionColumns.widths) && sectionColumns.widths.length > 0 && !allColumnWidthsEqual(sectionColumns.widths))
263983
264108
  return null;
263984
264109
  const sectionFragments = fragments.filter((f2) => blockSectionMap.get(f2.blockId) === sectionIndex);
263985
264110
  if (sectionFragments.length === 0)
@@ -265232,58 +265357,28 @@ function layoutDocument(blocks2, measures, options = {}) {
265232
265357
  const resolveParagraphlessAnchoredTableY = (block, measure, state) => {
265233
265358
  const contentTop = state.topMargin;
265234
265359
  const contentBottom = state.contentBottom;
265235
- const contentHeight = Math.max(0, contentBottom - contentTop);
265236
265360
  const tableHeight = measure.totalHeight ?? 0;
265237
- const anchor = block.anchor;
265238
- const offsetV = anchor?.offsetV ?? 0;
265239
- const vRelativeFrom = anchor?.vRelativeFrom;
265240
- const alignV = anchor?.alignV;
265241
- if (vRelativeFrom === "margin") {
265242
- if (alignV === "bottom")
265243
- return contentBottom - tableHeight + offsetV;
265244
- if (alignV === "center")
265245
- return contentTop + (contentHeight - tableHeight) / 2 + offsetV;
265246
- return contentTop + offsetV;
265247
- }
265248
- if (vRelativeFrom === "page") {
265249
- if (alignV === "bottom")
265250
- return contentBottom + (state.page.margins?.bottom ?? activeBottomMargin) - tableHeight + offsetV;
265251
- if (alignV === "center")
265252
- return (contentBottom + (state.page.margins?.bottom ?? activeBottomMargin) - tableHeight) / 2 + offsetV;
265253
- return offsetV;
265254
- }
265255
- return contentTop + offsetV;
265361
+ return resolveAnchoredGraphicY({
265362
+ anchor: block.anchor,
265363
+ objectHeight: tableHeight,
265364
+ contentTop,
265365
+ contentBottom,
265366
+ pageBottomMargin: state.page.margins?.bottom ?? activeBottomMargin,
265367
+ preRegisteredFallbackToContentTop: true
265368
+ });
265256
265369
  };
265257
265370
  for (const entry of preRegisteredAnchors) {
265258
265371
  const state = paginator.ensurePage();
265259
- const vRelativeFrom = entry.block.anchor?.vRelativeFrom ?? "paragraph";
265260
- const alignV = entry.block.anchor?.alignV ?? "top";
265261
- const offsetV = entry.block.anchor?.offsetV ?? 0;
265262
- const imageHeight = entry.measure.height ?? 0;
265263
265372
  const contentTop = state.topMargin;
265264
265373
  const contentBottom = state.contentBottom;
265265
- const contentHeight = Math.max(0, contentBottom - contentTop);
265266
- let anchorY;
265267
- if (vRelativeFrom === "margin")
265268
- if (alignV === "top")
265269
- anchorY = contentTop + offsetV;
265270
- else if (alignV === "bottom")
265271
- anchorY = contentBottom - imageHeight + offsetV;
265272
- else if (alignV === "center")
265273
- anchorY = contentTop + (contentHeight - imageHeight) / 2 + offsetV;
265274
- else
265275
- anchorY = contentTop + offsetV;
265276
- else if (vRelativeFrom === "page")
265277
- if (alignV === "top")
265278
- anchorY = offsetV;
265279
- else if (alignV === "bottom")
265280
- anchorY = contentBottom + (state.page.margins?.bottom ?? activeBottomMargin) - imageHeight + offsetV;
265281
- else if (alignV === "center")
265282
- anchorY = (contentBottom + (state.page.margins?.bottom ?? activeBottomMargin) - imageHeight) / 2 + offsetV;
265283
- else
265284
- anchorY = offsetV;
265285
- else
265286
- anchorY = contentTop + offsetV;
265374
+ const anchorY = resolveAnchoredGraphicY({
265375
+ anchor: entry.block.anchor,
265376
+ objectHeight: entry.measure.height ?? 0,
265377
+ contentTop,
265378
+ contentBottom,
265379
+ pageBottomMargin: state.page.margins?.bottom ?? activeBottomMargin,
265380
+ preRegisteredFallbackToContentTop: true
265381
+ });
265287
265382
  const anchorX = entry.block.anchor ? computeAnchorX(entry.block.anchor, state.columnIndex, normalizeColumns(activeColumns, activePageSize.w - (activeLeftMargin + activeRightMargin)), entry.measure.width, {
265288
265383
  left: activeLeftMargin,
265289
265384
  right: activeRightMargin
@@ -265594,7 +265689,6 @@ function layoutDocument(blocks2, measures, options = {}) {
265594
265689
  overrideSpacingAfter = 0;
265595
265690
  }
265596
265691
  }
265597
- const paragraphStartY = paginator.ensurePage().cursorY;
265598
265692
  layoutParagraphBlock({
265599
265693
  block,
265600
265694
  measure,
@@ -265624,7 +265718,12 @@ function layoutDocument(blocks2, measures, options = {}) {
265624
265718
  if (tablesForPara) {
265625
265719
  const state = paginator.ensurePage();
265626
265720
  const columnWidthForTable = getCurrentColumnWidth();
265721
+ let anchorParagraphTopY = state.cursorY;
265722
+ for (const fragment of state.page.fragments)
265723
+ if (fragment.kind === "para" && fragment.blockId === block.id)
265724
+ anchorParagraphTopY = Math.min(anchorParagraphTopY, fragment.y);
265627
265725
  let tableBottomY = state.cursorY;
265726
+ let nextStackY = state.cursorY;
265628
265727
  for (const { block: tableBlock, measure: tableMeasure } of tablesForPara) {
265629
265728
  if (placedAnchoredTableIds.has(tableBlock.id))
265630
265729
  continue;
@@ -265632,15 +265731,17 @@ function layoutDocument(blocks2, measures, options = {}) {
265632
265731
  if (columnWidthForTable > 0 && totalWidth >= columnWidthForTable * 0.99)
265633
265732
  continue;
265634
265733
  const offsetV = tableBlock.anchor?.offsetV ?? 0;
265635
- const anchorY = Math.max(paragraphStartY, state.cursorY) + offsetV;
265734
+ const anchorY = Math.max(anchorParagraphTopY, nextStackY) + offsetV;
265636
265735
  floatManager.registerTable(tableBlock, tableMeasure, anchorY, state.columnIndex, state.page.number);
265637
265736
  const tableFragment = createAnchoredTableFragment(tableBlock, tableMeasure, tableBlock.anchor?.offsetH ?? columnX(state.columnIndex), anchorY);
265638
265737
  state.page.fragments.push(tableFragment);
265639
265738
  placedAnchoredTableIds.add(tableBlock.id);
265640
265739
  if ((tableBlock.wrap?.type ?? "None") !== "None") {
265641
265740
  const bottom$1 = anchorY + (tableMeasure.totalHeight ?? 0);
265741
+ const distBottom = tableBlock.wrap?.distBottom ?? 0;
265642
265742
  if (bottom$1 > tableBottomY)
265643
265743
  tableBottomY = bottom$1;
265744
+ nextStackY = bottom$1 + distBottom;
265644
265745
  }
265645
265746
  }
265646
265747
  state.cursorY = tableBottomY;
@@ -275321,7 +275422,11 @@ function buildFontString$1(run2, fontContext) {
275321
275422
  if (run2.bold)
275322
275423
  parts.push("bold");
275323
275424
  parts.push(`${normalizeFontSize$1(run2.fontSize)}px`);
275324
- const physicalFamily = normalizeFontFamily$1(fontContext.resolvePhysical(normalizeFontFamily$1(run2.fontFamily)));
275425
+ const face = {
275426
+ weight: run2.bold ? "700" : "400",
275427
+ style: run2.italic ? "italic" : "normal"
275428
+ };
275429
+ const physicalFamily = normalizeFontFamily$1(fontContext.resolvePhysical(normalizeFontFamily$1(run2.fontFamily), face));
275325
275430
  parts.push(toCssFontFamily(physicalFamily) ?? physicalFamily);
275326
275431
  return parts.join(" ");
275327
275432
  }
@@ -275428,6 +275533,12 @@ function getCanvasContext() {
275428
275533
  }
275429
275534
  return canvasContext;
275430
275535
  }
275536
+ function faceOf(run2) {
275537
+ return {
275538
+ weight: run2.bold ? "700" : "400",
275539
+ style: run2.italic ? "italic" : "normal"
275540
+ };
275541
+ }
275431
275542
  function buildFontString(run2, fontContext) {
275432
275543
  const parts = [];
275433
275544
  if (run2.italic)
@@ -275435,7 +275546,7 @@ function buildFontString(run2, fontContext) {
275435
275546
  if (run2.bold)
275436
275547
  parts.push("bold");
275437
275548
  parts.push(`${run2.fontSize}px`);
275438
- const physicalFamily = fontContext.resolvePhysical(run2.fontFamily);
275549
+ const physicalFamily = fontContext.resolvePhysical(run2.fontFamily, faceOf(run2));
275439
275550
  if (measurementConfig.mode === "deterministic")
275440
275551
  parts.push(measurementConfig.fonts.fallbackStack.length > 0 ? measurementConfig.fonts.fallbackStack.join(", ") : measurementConfig.fonts.deterministicFamily);
275441
275552
  else
@@ -275502,7 +275613,7 @@ function lineHeightFontSize(run2) {
275502
275613
  }
275503
275614
  function getFontInfoFromRun(run2, fontContext) {
275504
275615
  return {
275505
- fontFamily: normalizeFontFamily(fontContext.resolvePhysical(run2.fontFamily)),
275616
+ fontFamily: normalizeFontFamily(fontContext.resolvePhysical(run2.fontFamily, faceOf(run2))),
275506
275617
  fontSize: normalizeFontSize2(lineHeightFontSize(run2)),
275507
275618
  bold: run2.bold,
275508
275619
  italic: run2.italic
@@ -276305,7 +276416,7 @@ async function measureParagraphBlock(block, maxWidth, fontContext) {
276305
276416
  if (isFieldAnnotationRun(run2)) {
276306
276417
  const displayText = applyTextTransform(run2.displayLabel || "", run2);
276307
276418
  const annotationFontSize = typeof run2.fontSize === "number" ? run2.fontSize : typeof run2.fontSize === "string" ? parseFloat(run2.fontSize) || DEFAULT_FIELD_ANNOTATION_FONT_SIZE : DEFAULT_FIELD_ANNOTATION_FONT_SIZE;
276308
- const annotationFontFamily = fontContext.resolvePhysical(run2.fontFamily || "Arial, sans-serif");
276419
+ const annotationFontFamily = fontContext.resolvePhysical(run2.fontFamily || "Arial, sans-serif", faceOf(run2));
276309
276420
  const fontWeight = run2.bold ? "bold" : "normal";
276310
276421
  ctx$1.font = `${run2.italic ? "italic" : "normal"} ${fontWeight} ${annotationFontSize}px ${annotationFontFamily}`;
276311
276422
  const textWidth = displayText ? ctx$1.measureText(displayText).width : 0;
@@ -277363,7 +277474,7 @@ async function measureListBlock(block, constraints, fontContext) {
277363
277474
  totalHeight
277364
277475
  };
277365
277476
  }
277366
- async function layoutPerRIdHeaderFooters(headerFooterInput, layout, sectionMetadata, deps, fontResolver) {
277477
+ async function layoutPerRIdHeaderFooters(headerFooterInput, layout, sectionMetadata, deps, fontResolver, hasFace, effectiveSignature) {
277367
277478
  deps.headerLayoutsByRId.clear();
277368
277479
  deps.footerLayoutsByRId.clear();
277369
277480
  if (!headerFooterInput)
@@ -277386,21 +277497,21 @@ async function layoutPerRIdHeaderFooters(headerFooterInput, layout, sectionMetad
277386
277497
  };
277387
277498
  };
277388
277499
  if (sectionMetadata.length > 1 && sectionMetadata.some((s2) => s2.margins || s2.pageSize)) {
277389
- await layoutWithPerSectionConstraints("header", headerBlocksByRId, sectionMetadata, constraints, pageResolver, deps.headerLayoutsByRId, fontResolver);
277390
- await layoutWithPerSectionConstraints("footer", footerBlocksByRId, sectionMetadata, constraints, pageResolver, deps.footerLayoutsByRId, fontResolver);
277500
+ await layoutWithPerSectionConstraints("header", headerBlocksByRId, sectionMetadata, constraints, pageResolver, deps.headerLayoutsByRId, fontResolver, hasFace, effectiveSignature);
277501
+ await layoutWithPerSectionConstraints("footer", footerBlocksByRId, sectionMetadata, constraints, pageResolver, deps.footerLayoutsByRId, fontResolver, hasFace, effectiveSignature);
277391
277502
  } else {
277392
277503
  const effectiveHeaderRefsBySection = buildEffectiveHeaderFooterRefsBySection(sectionMetadata, "header");
277393
277504
  const effectiveFooterRefsBySection = buildEffectiveHeaderFooterRefsBySection(sectionMetadata, "footer");
277394
- await layoutBlocksByRId("header", headerBlocksByRId, collectReferencedHeaderFooterRIds(effectiveHeaderRefsBySection), constraints, pageResolver, deps.headerLayoutsByRId, fontResolver);
277395
- await layoutBlocksByRId("footer", footerBlocksByRId, collectReferencedHeaderFooterRIds(effectiveFooterRefsBySection), constraints, pageResolver, deps.footerLayoutsByRId, fontResolver);
277505
+ await layoutBlocksByRId("header", headerBlocksByRId, collectReferencedHeaderFooterRIds(effectiveHeaderRefsBySection), constraints, pageResolver, deps.headerLayoutsByRId, fontResolver, hasFace, effectiveSignature);
277506
+ await layoutBlocksByRId("footer", footerBlocksByRId, collectReferencedHeaderFooterRIds(effectiveFooterRefsBySection), constraints, pageResolver, deps.footerLayoutsByRId, fontResolver, hasFace, effectiveSignature);
277396
277507
  }
277397
277508
  }
277398
- async function layoutBlocksByRId(kind, blocksByRId, referencedRIds, constraints, pageResolver, layoutsByRId, fontResolver) {
277509
+ async function layoutBlocksByRId(kind, blocksByRId, referencedRIds, constraints, pageResolver, layoutsByRId, fontResolver, hasFace, effectiveSignature) {
277399
277510
  if (!blocksByRId || referencedRIds.size === 0)
277400
277511
  return;
277401
- const fontSignature = fontResolver?.signature ?? "";
277512
+ const fontSignature = effectiveSignature ?? "";
277402
277513
  const fontMeasureContext = fontResolver ? {
277403
- resolvePhysical: (css) => fontResolver.resolvePhysicalFamily(css),
277514
+ resolvePhysical: (css, face) => hasFace ? fontResolver.resolvePhysicalFamilyForFace(css, face, hasFace) : fontResolver.resolvePhysicalFamily(css),
277404
277515
  fontSignature
277405
277516
  } : undefined;
277406
277517
  for (const [rId, blocks2] of blocksByRId) {
@@ -277455,12 +277566,12 @@ function adjustFramePositionsForContentWidth(layout, blocks2, effectiveWidth, co
277455
277566
  fragment.x -= widthDiff / 2;
277456
277567
  }
277457
277568
  }
277458
- async function layoutWithPerSectionConstraints(kind, blocksByRId, sectionMetadata, fallbackConstraints, pageResolver, layoutsByRId, fontResolver) {
277569
+ async function layoutWithPerSectionConstraints(kind, blocksByRId, sectionMetadata, fallbackConstraints, pageResolver, layoutsByRId, fontResolver, hasFace, effectiveSignature) {
277459
277570
  if (!blocksByRId)
277460
277571
  return;
277461
- const fontSignature = fontResolver?.signature ?? "";
277572
+ const fontSignature = effectiveSignature ?? "";
277462
277573
  const fontMeasureContext = fontResolver ? {
277463
- resolvePhysical: (css) => fontResolver.resolvePhysicalFamily(css),
277574
+ resolvePhysical: (css, face) => hasFace ? fontResolver.resolvePhysicalFamilyForFace(css, face, hasFace) : fontResolver.resolvePhysicalFamily(css),
277464
277575
  fontSignature
277465
277576
  } : undefined;
277466
277577
  const groups = buildSectionAwareHeaderFooterMeasurementGroups(kind, blocksByRId, sectionMetadata, fallbackConstraints);
@@ -278129,80 +278240,136 @@ function defaultScheduleMicrotask(callback) {
278129
278240
  }
278130
278241
  Promise.resolve().then(callback);
278131
278242
  }
278132
- function faceKey(req) {
278133
- return `${req.family.toLowerCase()}|${req.weight}|${req.style}`;
278243
+ function primaryFamily(css) {
278244
+ const comma = css.indexOf(",");
278245
+ return (comma === -1 ? css : css.slice(0, comma)).trim().replace(/^["']|["']$/g, "");
278134
278246
  }
278135
- function collect(out, node2, resolve2) {
278247
+ function makeResolveFace(resolver2, hasFace) {
278248
+ if (resolver2 && hasFace)
278249
+ return (logical, face) => {
278250
+ const r$1 = resolver2.resolveFace(logical, face, hasFace);
278251
+ return {
278252
+ physicalFamily: r$1.physicalFamily,
278253
+ reason: r$1.reason
278254
+ };
278255
+ };
278256
+ if (resolver2)
278257
+ return (logical) => {
278258
+ const r$1 = resolver2.resolveFontFamily(logical);
278259
+ return {
278260
+ physicalFamily: r$1.physicalFamily,
278261
+ reason: r$1.reason
278262
+ };
278263
+ };
278264
+ return (logical) => {
278265
+ const r$1 = resolveFontFamily2(logical);
278266
+ return {
278267
+ physicalFamily: r$1.physicalFamily,
278268
+ reason: r$1.reason
278269
+ };
278270
+ };
278271
+ }
278272
+ function collect(acc, node2, resolveFace$1) {
278136
278273
  if (!node2 || typeof node2.fontFamily !== "string" || !node2.fontFamily)
278137
278274
  return;
278138
- const family$1 = resolve2(node2.fontFamily);
278139
- if (!family$1)
278275
+ const weight = node2.bold === true ? "700" : "400";
278276
+ const style2 = node2.italic === true ? "italic" : "normal";
278277
+ const logicalPrimary = primaryFamily(node2.fontFamily);
278278
+ if (!logicalPrimary)
278140
278279
  return;
278141
- const req = {
278142
- family: family$1,
278143
- weight: node2.bold === true ? "700" : "400",
278144
- style: node2.italic === true ? "italic" : "normal"
278145
- };
278146
- const key2 = faceKey(req);
278147
- if (!out.has(key2))
278148
- out.set(key2, req);
278280
+ const usedKey = `${logicalPrimary.toLowerCase()}|${weight}|${style2}`;
278281
+ if (acc.usedFaces.has(usedKey))
278282
+ return;
278283
+ const { physicalFamily, reason } = resolveFace$1(node2.fontFamily, {
278284
+ weight,
278285
+ style: style2
278286
+ });
278287
+ acc.usedFaces.set(usedKey, {
278288
+ logicalFamily: logicalPrimary,
278289
+ weight,
278290
+ style: style2
278291
+ });
278292
+ acc.sigEntries.set(usedKey, [
278293
+ logicalPrimary.toLowerCase(),
278294
+ weight,
278295
+ style2,
278296
+ (physicalFamily || "").toLowerCase(),
278297
+ reason
278298
+ ]);
278299
+ if (physicalFamily) {
278300
+ const reqKey = `${physicalFamily.toLowerCase()}|${weight}|${style2}`;
278301
+ if (!acc.requiredFaces.has(reqKey))
278302
+ acc.requiredFaces.set(reqKey, {
278303
+ family: physicalFamily,
278304
+ weight,
278305
+ style: style2
278306
+ });
278307
+ }
278149
278308
  }
278150
- function collectRuns(out, runs2, resolve2) {
278309
+ function collectRuns(acc, runs2, resolveFace$1) {
278151
278310
  if (!runs2)
278152
278311
  return;
278153
278312
  for (const run2 of runs2) {
278154
278313
  const bearing = run2;
278155
278314
  if (run2.kind === "fieldAnnotation" && (typeof bearing.fontFamily !== "string" || !bearing.fontFamily))
278156
- collect(out, {
278315
+ collect(acc, {
278157
278316
  ...bearing,
278158
278317
  fontFamily: "Arial"
278159
- }, resolve2);
278318
+ }, resolveFace$1);
278160
278319
  else
278161
- collect(out, bearing, resolve2);
278320
+ collect(acc, bearing, resolveFace$1);
278162
278321
  }
278163
278322
  }
278164
- function collectParagraph(out, paragraph2, resolve2) {
278323
+ function collectParagraph(acc, paragraph2, resolveFace$1) {
278165
278324
  if (!paragraph2)
278166
278325
  return;
278167
- collectRuns(out, paragraph2.runs, resolve2);
278168
- collect(out, paragraph2.attrs?.wordLayout?.marker?.run, resolve2);
278169
- collect(out, paragraph2.attrs?.dropCapDescriptor?.run, resolve2);
278326
+ collectRuns(acc, paragraph2.runs, resolveFace$1);
278327
+ collect(acc, paragraph2.attrs?.wordLayout?.marker?.run, resolveFace$1);
278328
+ collect(acc, paragraph2.attrs?.dropCapDescriptor?.run, resolveFace$1);
278170
278329
  }
278171
- function collectTable(out, table2, resolve2) {
278330
+ function collectTable(acc, table2, resolveFace$1) {
278172
278331
  for (const row2 of table2.rows)
278173
278332
  for (const cell2 of row2.cells) {
278174
- collectParagraph(out, cell2.paragraph, resolve2);
278333
+ collectParagraph(acc, cell2.paragraph, resolveFace$1);
278175
278334
  if (cell2.blocks)
278176
278335
  for (const b$1 of cell2.blocks)
278177
- collectBlock(out, b$1, resolve2);
278336
+ collectBlock(acc, b$1, resolveFace$1);
278178
278337
  }
278179
278338
  }
278180
- function collectList(out, list5, resolve2) {
278339
+ function collectList(acc, list5, resolveFace$1) {
278181
278340
  for (const item of list5.items)
278182
- collectParagraph(out, item.paragraph, resolve2);
278341
+ collectParagraph(acc, item.paragraph, resolveFace$1);
278183
278342
  }
278184
- function collectBlock(out, block, resolve2) {
278343
+ function collectBlock(acc, block, resolveFace$1) {
278185
278344
  switch (block.kind) {
278186
278345
  case "paragraph":
278187
- collectParagraph(out, block, resolve2);
278346
+ collectParagraph(acc, block, resolveFace$1);
278188
278347
  break;
278189
278348
  case "table":
278190
- collectTable(out, block, resolve2);
278349
+ collectTable(acc, block, resolveFace$1);
278191
278350
  break;
278192
278351
  case "list":
278193
- collectList(out, block, resolve2);
278352
+ collectList(acc, block, resolveFace$1);
278194
278353
  break;
278195
278354
  default:
278196
278355
  break;
278197
278356
  }
278198
278357
  }
278199
- function planRequiredFontFaces(blocks2, resolver2) {
278200
- const resolve2 = resolver2 ? (family$1) => resolver2.resolvePrimaryPhysicalFamily(family$1) : resolvePrimaryPhysicalFamily;
278201
- const out = /* @__PURE__ */ new Map;
278358
+ function planFontFaces(blocks2, resolver2, hasFace) {
278359
+ const resolveFace$1 = makeResolveFace(resolver2, hasFace);
278360
+ const acc = {
278361
+ requiredFaces: /* @__PURE__ */ new Map,
278362
+ usedFaces: /* @__PURE__ */ new Map,
278363
+ sigEntries: /* @__PURE__ */ new Map
278364
+ };
278202
278365
  if (blocks2)
278203
278366
  for (const block of blocks2)
278204
- collectBlock(out, block, resolve2);
278205
- return [...out.values()];
278367
+ collectBlock(acc, block, resolveFace$1);
278368
+ return {
278369
+ requiredFaces: [...acc.requiredFaces.values()],
278370
+ usedFaces: [...acc.usedFaces.values()],
278371
+ effectiveSignature: acc.sigEntries.size === 0 ? "" : JSON.stringify([...acc.sigEntries.entries()].sort(([a2], [b$1]) => a2 < b$1 ? -1 : a2 > b$1 ? 1 : 0).map(([, tuple3]) => tuple3))
278372
+ };
278206
278373
  }
278207
278374
  function buildSemanticFootnoteBlocks(input2, footnotesMode) {
278208
278375
  if (!input2 || input2.refs.length === 0 || input2.blocksById.size === 0)
@@ -299293,7 +299460,7 @@ menclose::after {
299293
299460
  return;
299294
299461
  if (this.#overrides.get(key2) === physical)
299295
299462
  return;
299296
- if ((BUNDLED_SUBSTITUTES[key2] ?? logicalFamily.trim()) === physical) {
299463
+ if (key2 === normalizeFamilyKey$2(physical)) {
299297
299464
  if (this.#overrides.delete(key2)) {
299298
299465
  this.#version += 1;
299299
299466
  this.#cachedSignature = null;
@@ -299345,12 +299512,41 @@ menclose::after {
299345
299512
  reason: "as_requested"
299346
299513
  };
299347
299514
  }
299515
+ #resolveFaceLadder(primary, face, hasFace) {
299516
+ const key2 = normalizeFamilyKey$2(primary);
299517
+ const override = this.#overrides.get(key2);
299518
+ if (override && hasFace(override, face.weight, face.style))
299519
+ return {
299520
+ physical: override,
299521
+ reason: "custom_mapping"
299522
+ };
299523
+ if (hasFace(primary, face.weight, face.style))
299524
+ return {
299525
+ physical: primary,
299526
+ reason: "registered_face"
299527
+ };
299528
+ const bundled = BUNDLED_SUBSTITUTES[key2];
299529
+ if (bundled && hasFace(bundled, face.weight, face.style))
299530
+ return {
299531
+ physical: bundled,
299532
+ reason: "bundled_substitute"
299533
+ };
299534
+ if (override || bundled)
299535
+ return {
299536
+ physical: primary,
299537
+ reason: "fallback_face_absent"
299538
+ };
299539
+ return {
299540
+ physical: primary,
299541
+ reason: "as_requested"
299542
+ };
299543
+ }
299348
299544
  resolveFontFamily(logicalFamily) {
299349
299545
  const primary = splitStack(logicalFamily)[0] ?? logicalFamily;
299350
299546
  const { physical, reason } = this.#physicalFor(primary);
299351
299547
  return {
299352
299548
  logicalFamily,
299353
- physicalFamily: physical,
299549
+ physicalFamily: stripFamilyQuotes(physical),
299354
299550
  reason
299355
299551
  };
299356
299552
  }
@@ -299365,6 +299561,26 @@ menclose::after {
299365
299561
  return cssFontFamily;
299366
299562
  return [physical, ...parts.slice(1)].join(", ");
299367
299563
  }
299564
+ resolveFace(logicalFamily, face, hasFace) {
299565
+ const primary = splitStack(logicalFamily)[0] ?? logicalFamily;
299566
+ const { physical, reason } = this.#resolveFaceLadder(primary, face, hasFace);
299567
+ return {
299568
+ logicalFamily,
299569
+ physicalFamily: stripFamilyQuotes(physical),
299570
+ reason
299571
+ };
299572
+ }
299573
+ resolvePhysicalFamilyForFace(cssFontFamily, face, hasFace) {
299574
+ if (!cssFontFamily)
299575
+ return cssFontFamily;
299576
+ const parts = splitStack(cssFontFamily);
299577
+ if (parts.length === 0)
299578
+ return cssFontFamily;
299579
+ const { physical, reason } = this.#resolveFaceLadder(parts[0], face, hasFace);
299580
+ if (reason === "custom_mapping" || reason === "bundled_substitute")
299581
+ return [physical, ...parts.slice(1)].join(", ");
299582
+ return cssFontFamily;
299583
+ }
299368
299584
  resolvePrimaryPhysicalFamily(family$1) {
299369
299585
  const primary = splitStack(family$1)[0] ?? family$1;
299370
299586
  return this.#physicalFor(primary).physical;
@@ -299391,6 +299607,7 @@ menclose::after {
299391
299607
  #faceInflight = /* @__PURE__ */ new Map;
299392
299608
  #faceSources = /* @__PURE__ */ new Map;
299393
299609
  #facesByFamily = /* @__PURE__ */ new Map;
299610
+ #providerFaceKeys = /* @__PURE__ */ new Set;
299394
299611
  #warnedFaceFailures = /* @__PURE__ */ new Set;
299395
299612
  constructor(options = {}) {
299396
299613
  this.#fontSet = options.fontSet ?? null;
@@ -299402,7 +299619,9 @@ menclose::after {
299402
299619
  register(descriptor) {
299403
299620
  const { family: family$1, source, descriptors: descriptors2 } = descriptor;
299404
299621
  const identitySource = typeof source === "string" ? canonicalizeFontSource(source) : source;
299405
- const key2 = faceKeyOf$1(family$1, normalizeWeight(descriptors2?.weight), normalizeStyle$1(descriptors2?.style));
299622
+ const weight = normalizeWeight(descriptors2?.weight);
299623
+ const style2 = normalizeStyle$1(descriptors2?.style);
299624
+ const key2 = faceKeyOf$1(family$1, weight, style2);
299406
299625
  if (typeof identitySource === "string") {
299407
299626
  const existingSource = this.#faceSources.get(key2);
299408
299627
  if (existingSource === identitySource)
@@ -299415,7 +299634,11 @@ menclose::after {
299415
299634
  throw new Error(`[superdoc] font face "${key2}" is already registered from a different source ("${existingSource}"); a registered face's source cannot be replaced`);
299416
299635
  }
299417
299636
  if (this.#FontFaceCtor && this.#fontSet) {
299418
- const face = new this.#FontFaceCtor(family$1, source, descriptors2);
299637
+ const face = new this.#FontFaceCtor(family$1, source, {
299638
+ ...descriptors2,
299639
+ weight,
299640
+ style: style2
299641
+ });
299419
299642
  this.#fontSet.add(face);
299420
299643
  this.#managed.set(family$1, face);
299421
299644
  }
@@ -299427,6 +299650,7 @@ menclose::after {
299427
299650
  }
299428
299651
  if (!this.#status.has(family$1))
299429
299652
  this.#status.set(family$1, "unloaded");
299653
+ this.#providerFaceKeys.add(key2);
299430
299654
  this.#trackFace(family$1, key2);
299431
299655
  if (!this.#faceStatus.has(key2))
299432
299656
  this.#faceStatus.set(key2, "unloaded");
@@ -299470,6 +299694,10 @@ menclose::after {
299470
299694
  return s2;
299471
299695
  return "unloaded";
299472
299696
  }
299697
+ hasFace(family$1, weight, style2) {
299698
+ const key2 = faceKeyOf$1(family$1, weight, style2);
299699
+ return this.#providerFaceKeys.has(key2) && this.#faceStatus.get(key2) !== "failed";
299700
+ }
299473
299701
  isAvailable(family$1) {
299474
299702
  if (!this.#fontSet)
299475
299703
  return false;
@@ -299962,7 +300190,7 @@ menclose::after {
299962
300190
  if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
299963
300191
  return;
299964
300192
  return value;
299965
- }, resolvePainterMarkerTextWidth = (markerTextWidthPx, marker) => getFiniteNonNegativeNumber(markerTextWidthPx) ?? getFiniteNonNegativeNumber(marker.glyphWidthPx) ?? getFiniteNonNegativeNumber(marker.markerBoxWidthPx) ?? 0, resolvePainterListMarkerGeometry = ({ wordLayout, indentLeftPx, hangingIndentPx, firstLineIndentPx, markerTextWidthPx }) => resolveListMarkerGeometry(wordLayout, indentLeftPx, firstLineIndentPx, hangingIndentPx, (_markerText, marker) => resolvePainterMarkerTextWidth(markerTextWidthPx, marker)), resolvePainterListTextStartPx = ({ wordLayout, indentLeftPx, hangingIndentPx, firstLineIndentPx, markerTextWidthPx }) => resolveListTextStartPx(wordLayout, indentLeftPx, firstLineIndentPx, hangingIndentPx, (_markerText, marker) => resolvePainterMarkerTextWidth(markerTextWidthPx, marker)), isMarkerSuffix = (suffix) => suffix === "tab" || suffix === "space" || suffix === "nothing", createListMarkerElement = (doc$12, markerText, run2, sourceAnchor, resolvePhysical = resolvePhysicalFamily) => {
300193
+ }, resolvePainterMarkerTextWidth = (markerTextWidthPx, marker) => getFiniteNonNegativeNumber(markerTextWidthPx) ?? getFiniteNonNegativeNumber(marker.glyphWidthPx) ?? getFiniteNonNegativeNumber(marker.markerBoxWidthPx) ?? 0, resolvePainterListMarkerGeometry = ({ wordLayout, indentLeftPx, hangingIndentPx, firstLineIndentPx, markerTextWidthPx }) => resolveListMarkerGeometry(wordLayout, indentLeftPx, firstLineIndentPx, hangingIndentPx, (_markerText, marker) => resolvePainterMarkerTextWidth(markerTextWidthPx, marker)), resolvePainterListTextStartPx = ({ wordLayout, indentLeftPx, hangingIndentPx, firstLineIndentPx, markerTextWidthPx }) => resolveListTextStartPx(wordLayout, indentLeftPx, firstLineIndentPx, hangingIndentPx, (_markerText, marker) => resolvePainterMarkerTextWidth(markerTextWidthPx, marker)), isMarkerSuffix = (suffix) => suffix === "tab" || suffix === "space" || suffix === "nothing", createListMarkerElement = (doc$12, markerText, run2, sourceAnchor, resolvePhysical = (css) => resolvePhysicalFamily(css)) => {
299966
300194
  const markerContainer = doc$12.createElement("span");
299967
300195
  markerContainer.classList.add(DOM_CLASS_NAMES.LIST_MARKER);
299968
300196
  markerContainer.style.display = "inline-block";
@@ -299972,7 +300200,10 @@ menclose::after {
299972
300200
  markerEl.textContent = markerText;
299973
300201
  markerEl.style.pointerEvents = "none";
299974
300202
  const cssFontFamily = toCssFontFamily(run2.fontFamily) ?? run2.fontFamily ?? "";
299975
- markerEl.style.fontFamily = resolvePhysical(cssFontFamily);
300203
+ markerEl.style.fontFamily = resolvePhysical(cssFontFamily, {
300204
+ weight: run2.bold ? "700" : "400",
300205
+ style: run2.italic ? "italic" : "normal"
300206
+ });
299976
300207
  if (run2.fontSize != null)
299977
300208
  markerEl.style.fontSize = `${run2.fontSize}px`;
299978
300209
  markerEl.style.fontWeight = run2.bold ? "bold" : "";
@@ -299990,7 +300221,7 @@ menclose::after {
299990
300221
  applySourceAnchorDataset(markerEl, sourceAnchor);
299991
300222
  return markerContainer;
299992
300223
  }, renderLegacyListMarker = (params$1) => {
299993
- const { doc: doc$12, lineEl, wordLayout, markerLayout, markerMeasure, markerTextWidthPx, indentLeftPx, hangingIndentPx, firstLineIndentPx, isRtl, sourceAnchor, resolvePhysical = resolvePhysicalFamily } = params$1;
300224
+ const { doc: doc$12, lineEl, wordLayout, markerLayout, markerMeasure, markerTextWidthPx, indentLeftPx, hangingIndentPx, firstLineIndentPx, isRtl, sourceAnchor, resolvePhysical = (css) => resolvePhysicalFamily(css) } = params$1;
299994
300225
  const markerTextWidth = markerTextWidthPx ?? markerMeasure?.markerTextWidth ?? 0;
299995
300226
  const markerGeometry = markerLayout?.justification === "left" && wordLayout?.firstLineIndentMode !== true && typeof markerTextWidth === "number" && Number.isFinite(markerTextWidth) && markerTextWidth >= 0 ? resolvePainterListMarkerGeometry({
299996
300227
  wordLayout,
@@ -300048,7 +300279,7 @@ menclose::after {
300048
300279
  prependMarkerSuffix(doc$12, lineEl, isMarkerSuffix(suffix) ? suffix : undefined, suffixWidthPx, markerLayout?.run?.fontSize);
300049
300280
  lineEl.prepend(markerContainer);
300050
300281
  }, renderResolvedListMarker = (params$1) => {
300051
- const { doc: doc$12, lineEl, marker, isRtl, sourceAnchor, resolvePhysical = resolvePhysicalFamily } = params$1;
300282
+ const { doc: doc$12, lineEl, marker, isRtl, sourceAnchor, resolvePhysical } = params$1;
300052
300283
  if (isRtl)
300053
300284
  lineEl.style.paddingRight = `${marker.firstLinePaddingLeftPx}px`;
300054
300285
  else
@@ -300323,7 +300554,7 @@ menclose::after {
300323
300554
  skipJustifyOverride: (resolvedLine?.skipJustify ?? false) || hasMultipleExplicitPositionedSegments
300324
300555
  }) ? Math.max(lineWidth, availableWidth) : lineWidth;
300325
300556
  }, renderResolvedLines = (params$1) => {
300326
- const { frameEl, block, resolvedContent: content3, markerTextWidth, renderLine: renderLine$1, captureLineSnapshot, convertFinalParagraphMark, lineTopOffset = 0, sourceAnchor, resolvePhysical = resolvePhysicalFamily } = params$1;
300557
+ const { frameEl, block, resolvedContent: content3, markerTextWidth, renderLine: renderLine$1, captureLineSnapshot, convertFinalParagraphMark, lineTopOffset = 0, sourceAnchor, resolvePhysical = (css) => resolvePhysicalFamily(css) } = params$1;
300327
300558
  const renderedLines = [];
300328
300559
  const resolvedMarker = content3.marker;
300329
300560
  const expandedRunsForBlock = expandRunsForInlineNewlines(block.runs);
@@ -300377,7 +300608,7 @@ menclose::after {
300377
300608
  renderedLines
300378
300609
  };
300379
300610
  }, renderMeasuredLines = (params$1) => {
300380
- const { doc: doc$12, frameEl, block, measure, containerKind, width, localStartLine, localEndLine, linesOverride, lineIndexOffset = 0, continuesFromPrev, continuesOnNext, markerWidth, markerTextWidth, wordLayout, renderLine: renderLine$1, captureLineSnapshot, convertFinalParagraphMark, lineTopOffset = 0, sourceAnchor, resolvePhysical = resolvePhysicalFamily } = params$1;
300611
+ const { doc: doc$12, frameEl, block, measure, containerKind, width, localStartLine, localEndLine, linesOverride, lineIndexOffset = 0, continuesFromPrev, continuesOnNext, markerWidth, markerTextWidth, wordLayout, renderLine: renderLine$1, captureLineSnapshot, convertFinalParagraphMark, lineTopOffset = 0, sourceAnchor, resolvePhysical = (css) => resolvePhysicalFamily(css) } = params$1;
300381
300612
  const lines = linesOverride ?? measure.lines ?? [];
300382
300613
  const paraIndent = block.attrs?.indent;
300383
300614
  const paraIndentLeft = paraIndent?.left ?? 0;
@@ -301648,7 +301879,7 @@ menclose::after {
301648
301879
  else
301649
301880
  delete el.dataset.continuesOnNext;
301650
301881
  }, isMinimalWordLayout$2 = (value) => isMinimalWordLayout(value), renderParagraphFragment = (params$1) => {
301651
- const { doc: doc$12, fragment, sdtBoundary, betweenInfo, resolvedItem, applyStyles: applyStyles$3, applyResolvedFragmentFrame, applyFragmentFrame, applySdtDataset: applySdtDataset$1, applyContainerSdtDataset: applyContainerSdtDataset$1, renderLine: renderLine$1, captureLineSnapshot, createErrorPlaceholder, contentControlsChrome, resolvePhysical = resolvePhysicalFamily } = params$1;
301882
+ const { doc: doc$12, fragment, sdtBoundary, betweenInfo, resolvedItem, applyStyles: applyStyles$3, applyResolvedFragmentFrame, applyFragmentFrame, applySdtDataset: applySdtDataset$1, applyContainerSdtDataset: applyContainerSdtDataset$1, renderLine: renderLine$1, captureLineSnapshot, createErrorPlaceholder, contentControlsChrome, resolvePhysical = (css) => resolvePhysicalFamily(css) } = params$1;
301652
301883
  try {
301653
301884
  if (!doc$12)
301654
301885
  throw new Error("DomPainter: document is not available");
@@ -301727,12 +301958,15 @@ menclose::after {
301727
301958
  });
301728
301959
  return createErrorPlaceholder(fragment.blockId, error48);
301729
301960
  }
301730
- }, renderDropCap = (doc$12, descriptor, measure, resolvePhysical = resolvePhysicalFamily) => {
301961
+ }, renderDropCap = (doc$12, descriptor, measure, resolvePhysical = (css) => resolvePhysicalFamily(css)) => {
301731
301962
  const { run: run2, mode } = descriptor;
301732
301963
  const dropCapEl = doc$12.createElement("span");
301733
301964
  dropCapEl.classList.add("superdoc-drop-cap");
301734
301965
  dropCapEl.textContent = run2.text;
301735
- dropCapEl.style.fontFamily = resolvePhysical(run2.fontFamily);
301966
+ dropCapEl.style.fontFamily = resolvePhysical(run2.fontFamily, {
301967
+ weight: run2.bold ? "700" : "400",
301968
+ style: run2.italic ? "italic" : "normal"
301969
+ });
301736
301970
  dropCapEl.style.fontSize = `${run2.fontSize}px`;
301737
301971
  if (run2.bold)
301738
301972
  dropCapEl.style.fontWeight = "bold";
@@ -301848,7 +302082,10 @@ menclose::after {
301848
302082
  }, applyRunStyles = (element3, run2, _isLink = false, resolvePhysical = resolvePhysicalFamily) => {
301849
302083
  if (run2.kind === "tab" || run2.kind === "image" || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math")
301850
302084
  return;
301851
- element3.style.fontFamily = resolvePhysical(run2.fontFamily);
302085
+ element3.style.fontFamily = resolvePhysical(run2.fontFamily, {
302086
+ weight: run2.bold ? "700" : "400",
302087
+ style: run2.italic ? "italic" : "normal"
302088
+ });
301852
302089
  element3.style.fontSize = `${run2.fontSize}px`;
301853
302090
  if (run2.bold)
301854
302091
  element3.style.fontWeight = "bold";
@@ -302031,7 +302268,10 @@ menclose::after {
302031
302268
  }
302032
302269
  {
302033
302270
  const resolvePhysical = context.resolvePhysical ?? resolvePhysicalFamily;
302034
- annotation.style.fontFamily = resolvePhysical(run2.fontFamily || "Arial, sans-serif");
302271
+ annotation.style.fontFamily = resolvePhysical(run2.fontFamily || "Arial, sans-serif", {
302272
+ weight: run2.bold ? "700" : "400",
302273
+ style: run2.italic ? "italic" : "normal"
302274
+ });
302035
302275
  }
302036
302276
  {
302037
302277
  const fontSize = run2.fontSize ? typeof run2.fontSize === "number" ? `${run2.fontSize}pt` : run2.fontSize : BROWSER_DEFAULT_FONT_SIZE;
@@ -313963,11 +314203,11 @@ menclose::after {
313963
314203
  #resolveResult(result, storyId) {
313964
314204
  return resolveResult(result, storyId, this.#options.getFontSignature?.() ?? "");
313965
314205
  }
313966
- async layoutPerRId(headerFooterInput, layout, sectionMetadata, fontResolver) {
314206
+ async layoutPerRId(headerFooterInput, layout, sectionMetadata, fontResolver, hasFace, effectiveSignature) {
313967
314207
  await layoutPerRIdHeaderFooters(headerFooterInput, layout, sectionMetadata, {
313968
314208
  headerLayoutsByRId: this.#headerLayoutsByRId,
313969
314209
  footerLayoutsByRId: this.#footerLayoutsByRId
313970
- }, fontResolver);
314210
+ }, fontResolver, hasFace, effectiveSignature);
313971
314211
  this.#resolvedHeaderByRId.clear();
313972
314212
  for (const [key2, result] of this.#headerLayoutsByRId)
313973
314213
  this.#resolvedHeaderByRId.set(key2, this.#resolveResult(result, storyIdFromHeaderFooterLayoutKey(key2)));
@@ -314825,6 +315065,7 @@ menclose::after {
314825
315065
  }, FontReadinessGate = class {
314826
315066
  #getDocumentFonts;
314827
315067
  #getRequiredFaces;
315068
+ #getUsedFaces;
314828
315069
  #resolveFamilies;
314829
315070
  #fontResolver;
314830
315071
  #requestReflow;
@@ -314834,18 +315075,21 @@ menclose::after {
314834
315075
  #timeoutMs;
314835
315076
  #invalidateCaches;
314836
315077
  #context = null;
315078
+ #packInstalledFor = null;
314837
315079
  #fontConfigVersion = 0;
314838
315080
  #requiredSignature = "";
314839
315081
  #requiredFamilies = /* @__PURE__ */ new Set;
314840
315082
  #requiredFaceKeys = /* @__PURE__ */ new Set;
314841
315083
  #seenAvailable = /* @__PURE__ */ new Set;
314842
315084
  #seenAvailableFaces = /* @__PURE__ */ new Set;
315085
+ #seenFailedFaces = /* @__PURE__ */ new Set;
314843
315086
  #lastSummary = null;
314844
315087
  #loadingDoneHandler = null;
314845
315088
  #lateLoadScheduler;
314846
315089
  constructor(options) {
314847
315090
  this.#getDocumentFonts = options.getDocumentFonts;
314848
315091
  this.#getRequiredFaces = options.getRequiredFaces ?? null;
315092
+ this.#getUsedFaces = options.getUsedFaces ?? null;
314849
315093
  this.#fontResolver = options.fontResolver ?? null;
314850
315094
  const resolver2 = this.#fontResolver;
314851
315095
  this.#resolveFamilies = options.resolveFamilies ?? (resolver2 ? (families) => resolver2.resolvePhysicalFamilies(families) : (families) => families);
@@ -314870,13 +315114,19 @@ menclose::after {
314870
315114
  return this.#lastSummary;
314871
315115
  }
314872
315116
  getReport() {
314873
- let logical = [];
315117
+ let declared = [];
314874
315118
  try {
314875
- logical = this.#getDocumentFonts();
315119
+ declared = this.#getDocumentFonts();
314876
315120
  } catch {
314877
315121
  return [];
314878
315122
  }
314879
- return buildFontReport(logical, this.#resolveContext().registry, this.#fontResolver ?? undefined);
315123
+ const registry3 = this.#resolveContext().registry;
315124
+ const resolver2 = this.#fontResolver ?? undefined;
315125
+ const usedFaces = this.#getUsedFaces?.() ?? [];
315126
+ const faceRows = buildFaceReport(usedFaces, registry3, resolver2);
315127
+ const usedFamilies = new Set(usedFaces.map((u) => u.logicalFamily.toLowerCase()));
315128
+ const declaredRows = buildFontReport(declared.filter((family$1) => family$1 && !usedFamilies.has(family$1.toLowerCase())), registry3, resolver2);
315129
+ return [...faceRows, ...declaredRows];
314880
315130
  }
314881
315131
  async ensureReadyForMeasure() {
314882
315132
  if (this.#getRequiredFaces)
@@ -314908,9 +315158,18 @@ menclose::after {
314908
315158
  } catch {
314909
315159
  results = [];
314910
315160
  }
314911
- for (const result of results)
315161
+ const failedKeys = [];
315162
+ for (const result of results) {
315163
+ const key2 = faceKeyOf(result.request.family, result.request.weight, result.request.style);
314912
315164
  if (result.status === "loaded")
314913
- this.#seenAvailableFaces.add(faceKeyOf(result.request.family, result.request.weight, result.request.style));
315165
+ this.#seenAvailableFaces.add(key2);
315166
+ else if (result.status === "failed" && !this.#seenFailedFaces.has(key2)) {
315167
+ this.#seenFailedFaces.add(key2);
315168
+ failedKeys.push(key2);
315169
+ }
315170
+ }
315171
+ if (failedKeys.length > 0)
315172
+ this.#scheduleAvailabilityReflow(failedKeys);
314914
315173
  this.#lastSummary = summarizeFaces(results);
314915
315174
  return this.#lastSummary;
314916
315175
  }
@@ -314967,6 +315226,7 @@ menclose::after {
314967
315226
  this.#requiredFamilies = /* @__PURE__ */ new Set;
314968
315227
  this.#seenAvailable.clear();
314969
315228
  this.#seenAvailableFaces.clear();
315229
+ this.#seenFailedFaces.clear();
314970
315230
  this.#lastSummary = null;
314971
315231
  }
314972
315232
  dispose() {
@@ -314986,10 +315246,12 @@ menclose::after {
314986
315246
  fontSet,
314987
315247
  registry: registry3
314988
315248
  };
314989
- if (fontSet && this.#onRegistryResolved)
315249
+ if (this.#onRegistryResolved && registry3 !== this.#packInstalledFor) {
315250
+ this.#packInstalledFor = registry3;
314990
315251
  try {
314991
315252
  this.#onRegistryResolved(registry3);
314992
315253
  } catch {}
315254
+ }
314993
315255
  return this.#context;
314994
315256
  }
314995
315257
  #ensureSubscribed() {
@@ -315030,6 +315292,9 @@ menclose::after {
315030
315292
  }
315031
315293
  if (changedKeys.length === 0)
315032
315294
  return;
315295
+ this.#scheduleAvailabilityReflow(changedKeys);
315296
+ }
315297
+ #scheduleAvailabilityReflow(changedKeys) {
315033
315298
  this.#fontConfigVersion += 1;
315034
315299
  bumpFontConfigVersion();
315035
315300
  this.#invalidateCaches();
@@ -315129,8 +315394,13 @@ menclose::after {
315129
315394
  const registry3 = this.#getGate()?.resolveRegistry();
315130
315395
  if (!registry3)
315131
315396
  throw new Error("[superdoc] fonts.preload: the font registry is not ready yet");
315397
+ const hasFace = (family$1, weight, style2) => registry3.hasFace(family$1, weight, style2);
315398
+ const face = {
315399
+ weight: "400",
315400
+ style: "normal"
315401
+ };
315132
315402
  const requests = families.map((logical) => ({
315133
- family: this.#resolver.resolvePrimaryPhysicalFamily(logical),
315403
+ family: this.#resolver.resolveFace(logical, face, hasFace).physicalFamily,
315134
315404
  weight: "400",
315135
315405
  style: "normal"
315136
315406
  }));
@@ -315247,13 +315517,13 @@ menclose::after {
315247
315517
  return;
315248
315518
  console.log(...args$1);
315249
315519
  }, 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;
315250
- var init_src_B1aSE_tB_es = __esm(() => {
315520
+ var init_src_plIVvSkL_es = __esm(() => {
315251
315521
  init_rolldown_runtime_Bg48TavK_es();
315252
- init_SuperConverter_B9mZiCO9_es();
315522
+ init_SuperConverter_BSMYiYJm_es();
315253
315523
  init_jszip_C49i9kUs_es();
315254
315524
  init_xml_js_CqGKpaft_es();
315255
315525
  init_uuid_qzgm05fK_es();
315256
- init_create_headless_toolbar_pn_wKqsL_es();
315526
+ init_create_headless_toolbar_DeKyOdIi_es();
315257
315527
  init_constants_D_X7xF4s_es();
315258
315528
  init_dist_B8HfvhaK_es();
315259
315529
  init_unified_Dsuw2be5_es();
@@ -342137,7 +342407,7 @@ function print() { __p += __j.call(arguments, '') }
342137
342407
  });
342138
342408
  defaultResolver = new FontResolver;
342139
342409
  DEFAULT_FONT_MEASURE_CONTEXT = Object.freeze({
342140
- resolvePhysical: resolvePhysicalFamily,
342410
+ resolvePhysical: (cssFontFamily, _face) => resolvePhysicalFamily(cssFontFamily),
342141
342411
  fontSignature: ""
342142
342412
  });
342143
342413
  BUNDLED_MANIFEST = Object.freeze([
@@ -343421,7 +343691,10 @@ function print() { __p += __j.call(arguments, '') }
343421
343691
  }
343422
343692
  });
343423
343693
  #fontPlanBlocks = null;
343694
+ #fontPlan = null;
343695
+ #hasFace = (family$1, weight, style2) => this.#fontGate ? this.#fontGate.resolveRegistry().hasFace(family$1, weight, style2) : false;
343424
343696
  #lastFontsChangedKey = null;
343697
+ #lastFontsChangedVersion = -1;
343425
343698
  #lastFontsChangedPayload = null;
343426
343699
  #shouldScrollSelectionIntoView = false;
343427
343700
  #suppressSelectionScrollUntilRaf = false;
@@ -343652,7 +343925,7 @@ function print() { __p += __j.call(arguments, '') }
343652
343925
  initBudgetMs: HEADER_FOOTER_INIT_BUDGET_MS,
343653
343926
  defaultPageSize: DEFAULT_PAGE_SIZE,
343654
343927
  defaultMargins: DEFAULT_MARGINS,
343655
- getFontSignature: () => this.#fontResolver.signature
343928
+ getFontSignature: () => this.#layoutFontSignature
343656
343929
  });
343657
343930
  this.#headerFooterSession.setHoverElements({
343658
343931
  hoverOverlay: this.#hoverOverlay,
@@ -343707,7 +343980,8 @@ function print() { __p += __j.call(arguments, '') }
343707
343980
  return this.#editor.converter?.getDocumentFonts?.() ?? [];
343708
343981
  },
343709
343982
  requestReflow: () => this.#requestFontReflow(),
343710
- getRequiredFaces: () => planRequiredFontFaces(this.#fontPlanBlocks, this.#fontResolver),
343983
+ getRequiredFaces: () => this.#fontPlan?.requiredFaces ?? [],
343984
+ getUsedFaces: () => this.#fontPlan?.usedFaces ?? [],
343711
343985
  fontResolver: this.#fontResolver,
343712
343986
  onRegistryResolved: (registry3) => installBundledSubstitutes(registry3, {
343713
343987
  assetBaseUrl: this.#options.fontAssets?.assetBaseUrl,
@@ -344682,7 +344956,7 @@ function print() { __p += __j.call(arguments, '') }
344682
344956
  return this.#fontGate?.getReport() ?? [];
344683
344957
  }
344684
344958
  getMissingFonts() {
344685
- return this.getFontReport().filter((record3) => record3.missing).map((record3) => record3.logicalFamily);
344959
+ return [...new Set(this.getFontReport().filter((record3) => record3.missing).map((record3) => record3.logicalFamily))];
344686
344960
  }
344687
344961
  mapFonts(mappings) {
344688
344962
  this.#fontController.map(mappings);
@@ -344711,14 +344985,17 @@ function print() { __p += __j.call(arguments, '') }
344711
344985
  if (!gate)
344712
344986
  return;
344713
344987
  const version$1 = gate.fontConfigVersion;
344714
- const key2 = `${version$1}|${summary ? summary.results.map((result) => `${result.family}:${result.status}`).sort().join(",") : ""}`;
344988
+ const statusKey = summary ? summary.results.map((result) => `${result.family}:${result.status}`).sort().join(",") : "";
344989
+ const key2 = `${version$1}|${this.#fontPlan?.effectiveSignature ?? ""}|${statusKey}`;
344715
344990
  if (key2 === this.#lastFontsChangedKey)
344716
344991
  return;
344717
344992
  const isInitial = this.#lastFontsChangedKey === null;
344993
+ const epochBumped = !isInitial && version$1 !== this.#lastFontsChangedVersion;
344718
344994
  this.#lastFontsChangedKey = key2;
344995
+ this.#lastFontsChangedVersion = version$1;
344719
344996
  const pendingSource = this.#nextFontsChangedSource;
344720
344997
  this.#nextFontsChangedSource = null;
344721
- const source = isInitial ? "initial" : pendingSource ?? "late-load";
344998
+ const source = isInitial ? "initial" : pendingSource ?? (epochBumped ? "late-load" : "render-change");
344722
344999
  let resolutions;
344723
345000
  try {
344724
345001
  resolutions = gate.getReport();
@@ -344726,9 +345003,9 @@ function print() { __p += __j.call(arguments, '') }
344726
345003
  return;
344727
345004
  }
344728
345005
  const payload = {
344729
- documentFonts: resolutions.map((record3) => record3.logicalFamily),
345006
+ documentFonts: [...new Set(resolutions.map((record3) => record3.logicalFamily))],
344730
345007
  resolutions,
344731
- missingFonts: resolutions.filter((record3) => record3.missing).map((record3) => record3.logicalFamily),
345008
+ missingFonts: [...new Set(resolutions.filter((record3) => record3.missing).map((record3) => record3.logicalFamily))],
344732
345009
  loadSummary: summary ?? {
344733
345010
  loaded: 0,
344734
345011
  failed: 0,
@@ -344750,7 +345027,10 @@ function print() { __p += __j.call(arguments, '') }
344750
345027
  #resetFontReportStateForDocumentChange() {
344751
345028
  this.#nextFontsChangedSource = null;
344752
345029
  this.#lastFontsChangedKey = null;
345030
+ this.#lastFontsChangedVersion = -1;
344753
345031
  this.#lastFontsChangedPayload = null;
345032
+ this.#fontPlan = null;
345033
+ this.#fontPlanBlocks = null;
344754
345034
  }
344755
345035
  getLayoutOptions() {
344756
345036
  return { ...this.#layoutOptions };
@@ -344900,7 +345180,7 @@ function print() { __p += __j.call(arguments, '') }
344900
345180
  flowMode: this.#layoutOptions.flowMode ?? "paginated",
344901
345181
  blocks: blocks2,
344902
345182
  measures,
344903
- fontSignature: this.#fontResolver.signature
345183
+ fontSignature: this.#layoutFontSignature
344904
345184
  });
344905
345185
  const isSemanticFlow = this.#layoutOptions.flowMode === "semantic";
344906
345186
  this.#ensurePainter();
@@ -347109,10 +347389,10 @@ function print() { __p += __j.call(arguments, '') }
347109
347389
  const previousBlocks = this.#layoutState.blocks;
347110
347390
  const previousLayout = this.#layoutState.layout;
347111
347391
  const previousMeasures = this.#layoutState.measures;
347112
- const resolvePhysical = (css) => this.#fontResolver.resolvePhysicalFamily(css);
347113
- const fontSignature = this.#fontResolver.signature;
347392
+ const resolvePhysical = (css, face) => this.#fontResolver.resolvePhysicalFamilyForFace(css, face, this.#hasFace);
347393
+ let fontSignature = "";
347114
347394
  const previousFontSignature = this.#layoutFontSignature;
347115
- const fontMeasureContext = {
347395
+ let fontMeasureContext = {
347116
347396
  resolvePhysical,
347117
347397
  fontSignature
347118
347398
  };
@@ -347134,6 +347414,12 @@ function print() { __p += __j.call(arguments, '') }
347134
347414
  ...headerFooterInput ? this.#collectHeaderFooterFaceBlocks(headerFooterInput) : [],
347135
347415
  ...!isSemanticFlow && footnotesLayoutInput?.blocksById ? [...footnotesLayoutInput.blocksById.values()].flat() : []
347136
347416
  ];
347417
+ this.#fontPlan = planFontFaces(this.#fontPlanBlocks, this.#fontResolver, this.#hasFace);
347418
+ fontSignature = this.#fontPlan.effectiveSignature;
347419
+ fontMeasureContext = {
347420
+ resolvePhysical,
347421
+ fontSignature
347422
+ };
347137
347423
  const fontSummary = await this.#fontGate?.ensureReadyForMeasure() ?? null;
347138
347424
  this.#emitFontsChangedIfChanged(fontSummary);
347139
347425
  } catch {}
@@ -347293,7 +347579,7 @@ function print() { __p += __j.call(arguments, '') }
347293
347579
  pageGap: this.#layoutState.layout?.pageGap ?? effectiveGap,
347294
347580
  showFormattingMarks: this.#layoutOptions.showFormattingMarks ?? false,
347295
347581
  contentControlsChrome: this.#layoutOptions.contentControlsChrome ?? "default",
347296
- resolvePhysical: (css) => this.#fontResolver.resolvePhysicalFamily(css)
347582
+ resolvePhysical: (css, face) => this.#fontResolver.resolvePhysicalFamilyForFace(css, face, this.#hasFace)
347297
347583
  });
347298
347584
  const currentZoom = this.#layoutOptions.zoom ?? 1;
347299
347585
  if (currentZoom !== 1)
@@ -348045,7 +348331,7 @@ function print() { __p += __j.call(arguments, '') }
348045
348331
  }
348046
348332
  async#layoutPerRIdHeaderFooters(headerFooterInput, layout, sectionMetadata) {
348047
348333
  if (this.#headerFooterSession)
348048
- await this.#headerFooterSession.layoutPerRId(headerFooterInput, layout, sectionMetadata, this.#fontResolver);
348334
+ await this.#headerFooterSession.layoutPerRId(headerFooterInput, layout, sectionMetadata, this.#fontResolver, this.#hasFace, this.#fontPlan?.effectiveSignature ?? "");
348049
348335
  }
348050
348336
  #updateDecorationProviders(resolvedLayout) {
348051
348337
  this.#headerFooterSession?.updateDecorationProviders(resolvedLayout);
@@ -349946,11 +350232,11 @@ function print() { __p += __j.call(arguments, '') }
349946
350232
  ]);
349947
350233
  });
349948
350234
 
349949
- // ../../packages/superdoc/dist/chunks/create-super-doc-ui-CxQcY_QQ.es.js
350235
+ // ../../packages/superdoc/dist/chunks/create-super-doc-ui-CJMIa98h.es.js
349950
350236
  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;
349951
- var init_create_super_doc_ui_CxQcY_QQ_es = __esm(() => {
349952
- init_SuperConverter_B9mZiCO9_es();
349953
- init_create_headless_toolbar_pn_wKqsL_es();
350237
+ var init_create_super_doc_ui_CJMIa98h_es = __esm(() => {
350238
+ init_SuperConverter_BSMYiYJm_es();
350239
+ init_create_headless_toolbar_DeKyOdIi_es();
349954
350240
  MOD_ALIASES = new Set([
349955
350241
  "Mod",
349956
350242
  "Meta",
@@ -349992,16 +350278,16 @@ var init_zipper_yaJVJ4z9_es = __esm(() => {
349992
350278
 
349993
350279
  // ../../packages/superdoc/dist/super-editor.es.js
349994
350280
  var init_super_editor_es = __esm(() => {
349995
- init_src_B1aSE_tB_es();
349996
- init_SuperConverter_B9mZiCO9_es();
350281
+ init_src_plIVvSkL_es();
350282
+ init_SuperConverter_BSMYiYJm_es();
349997
350283
  init_jszip_C49i9kUs_es();
349998
350284
  init_xml_js_CqGKpaft_es();
349999
- init_create_headless_toolbar_pn_wKqsL_es();
350285
+ init_create_headless_toolbar_DeKyOdIi_es();
350000
350286
  init_constants_D_X7xF4s_es();
350001
350287
  init_dist_B8HfvhaK_es();
350002
350288
  init_unified_Dsuw2be5_es();
350003
350289
  init_DocxZipper_VodIk8WL_es();
350004
- init_create_super_doc_ui_CxQcY_QQ_es();
350290
+ init_create_super_doc_ui_CJMIa98h_es();
350005
350291
  init_ui_C5PAS9hY_es();
350006
350292
  init_eventemitter3_BnGqBE_Q_es();
350007
350293
  init_errors_CNaD6vcg_es();
@@ -371381,19 +371667,24 @@ function extractColumns2(elements) {
371381
371667
  const cols = elements.find((el) => el?.name === "w:cols");
371382
371668
  if (!cols?.attributes)
371383
371669
  return;
371384
- const count = parseColumnCount2(cols.attributes["w:num"]);
371670
+ let count = parseColumnCount2(cols.attributes["w:num"]);
371385
371671
  const withSeparator = parseColumnSeparator2(cols.attributes["w:sep"]);
371386
371672
  const equalWidthRaw = cols.attributes["w:equalWidth"];
371387
371673
  const equalWidth = equalWidthRaw === "0" || equalWidthRaw === 0 || equalWidthRaw === false ? false : equalWidthRaw === "1" || equalWidthRaw === 1 || equalWidthRaw === true ? true : undefined;
371388
371674
  const columnChildren = Array.isArray(cols.elements) ? cols.elements.filter((child) => child?.name === "w:col") : [];
371389
- const gapTwips = cols.attributes["w:space"] ?? columnChildren.find((child) => child?.attributes?.["w:space"] != null)?.attributes?.["w:space"];
371675
+ const isExplicit = equalWidth === false;
371676
+ const firstChildSpace = columnChildren.find((child) => child?.attributes?.["w:space"] != null)?.attributes?.["w:space"];
371677
+ const gapTwips = isExplicit ? firstChildSpace ?? 0 : cols.attributes["w:space"];
371390
371678
  const gapInches = parseColumnGap2(gapTwips);
371391
371679
  const widths = columnChildren.map((child) => Number(child.attributes?.["w:w"])).filter((widthTwips) => Number.isFinite(widthTwips) && widthTwips > 0).map((widthTwips) => widthTwips / 1440 * PX_PER_INCH);
371680
+ if (isExplicit && widths.length > 0) {
371681
+ count = Math.min(count, widths.length);
371682
+ }
371392
371683
  const result = {
371393
371684
  count,
371394
371685
  gap: gapInches * PX_PER_INCH,
371395
371686
  withSeparator,
371396
- ...widths.length > 0 ? { widths } : {},
371687
+ ...isExplicit && widths.length > 0 ? { widths } : {},
371397
371688
  ...equalWidth !== undefined ? { equalWidth } : {}
371398
371689
  };
371399
371690
  return result;
@@ -372120,6 +372411,17 @@ var twipsToPx3 = (value) => value / TWIPS_PER_INCH2 * PX_PER_INCH2, ptToPx2 = (p
372120
372411
  return Number.isFinite(parsed) ? parsed : undefined;
372121
372412
  }
372122
372413
  return;
372414
+ }, mergeWrapDistancesFromPadding2 = (wrap4, padding) => {
372415
+ if (!padding || wrap4.type === "None" || wrap4.type === "Inline")
372416
+ return;
372417
+ if (wrap4.distTop == null && padding.top != null)
372418
+ wrap4.distTop = padding.top;
372419
+ if (wrap4.distBottom == null && padding.bottom != null)
372420
+ wrap4.distBottom = padding.bottom;
372421
+ if (wrap4.distLeft == null && padding.left != null)
372422
+ wrap4.distLeft = padding.left;
372423
+ if (wrap4.distRight == null && padding.right != null)
372424
+ wrap4.distRight = padding.right;
372123
372425
  }, normalizeColor2 = (value) => {
372124
372426
  if (typeof value !== "string")
372125
372427
  return;
@@ -380847,6 +381149,9 @@ var WRAP_TYPES2, WRAP_TEXT_VALUES2, H_RELATIVE_VALUES2, V_RELATIVE_VALUES2, H_AL
380847
381149
  return hasData ? anchor : undefined;
380848
381150
  }, buildDrawingBlock2 = (rawAttrs, nextBlockId, positions, node3, geometry, drawingKind, extraProps) => {
380849
381151
  const normalizedWrap = normalizeWrap3(rawAttrs.wrap);
381152
+ if (normalizedWrap) {
381153
+ mergeWrapDistancesFromPadding2(normalizedWrap, toBoxSpacing2(rawAttrs.padding));
381154
+ }
380850
381155
  const sourceAnchor = isPlainObject8(rawAttrs.sourceAnchor) ? rawAttrs.sourceAnchor : undefined;
380851
381156
  const baseAnchor = normalizeAnchorData2(rawAttrs.anchorData, rawAttrs, normalizedWrap?.behindDoc);
380852
381157
  const pos = positions.get(node3);
@@ -381000,6 +381305,9 @@ function imageNodeToBlock2(node3, nextBlockId, positions, _trackedMeta, _tracked
381000
381305
  const height = typeof size3.height === "number" && Number.isFinite(size3.height) ? size3.height : undefined;
381001
381306
  const explicitDisplay = typeof attrs.display === "string" ? attrs.display : undefined;
381002
381307
  const normalizedWrap = normalizeWrap4(attrs.wrap);
381308
+ if (normalizedWrap) {
381309
+ mergeWrapDistancesFromPadding2(normalizedWrap, toBoxSpacing3(attrs.padding));
381310
+ }
381003
381311
  let anchor = normalizeAnchorData3(attrs.anchorData, attrs, normalizedWrap?.behindDoc);
381004
381312
  if (!anchor && normalizedWrap) {
381005
381313
  anchor = { isAnchored: true };
@@ -437658,6 +437966,9 @@ function handleImageNode3(node4, params3, isAnchor) {
437658
437966
  default:
437659
437967
  break;
437660
437968
  }
437969
+ if (wrap6.type === "Square" || wrap6.type === "Tight" || wrap6.type === "Through" || wrap6.type === "TopAndBottom") {
437970
+ mergeAnchorPaddingIntoWrapDistances2(wrap6, padding);
437971
+ }
437661
437972
  const docPr = node4.elements.find((el) => el.name === "wp:docPr");
437662
437973
  const isHidden = isDocPrHidden2(docPr);
437663
437974
  let anchorData = null;
@@ -438182,6 +438493,21 @@ var DRAWING_XML_TAG2 = "w:drawing", SHAPE_URI2 = "http://schemas.microsoft.com/o
438182
438493
  const bottom2 = percentEdges.bottom ?? 0;
438183
438494
  const left2 = percentEdges.left ?? 0;
438184
438495
  return `inset(${top}% ${right2}% ${bottom2}% ${left2}%)`;
438496
+ }, mergeAnchorPaddingIntoWrapDistances2 = (wrap6, padding) => {
438497
+ if (!wrap6?.attrs || !padding)
438498
+ return;
438499
+ if (wrap6.attrs.distTop == null && Number.isFinite(padding.top) && padding.top !== 0) {
438500
+ wrap6.attrs.distTop = padding.top;
438501
+ }
438502
+ if (wrap6.attrs.distBottom == null && Number.isFinite(padding.bottom) && padding.bottom !== 0) {
438503
+ wrap6.attrs.distBottom = padding.bottom;
438504
+ }
438505
+ if (wrap6.attrs.distLeft == null && Number.isFinite(padding.left) && padding.left !== 0) {
438506
+ wrap6.attrs.distLeft = padding.left;
438507
+ }
438508
+ if (wrap6.attrs.distRight == null && Number.isFinite(padding.right) && padding.right !== 0) {
438509
+ wrap6.attrs.distRight = padding.right;
438510
+ }
438185
438511
  }, handleShapeDrawing2 = (params3, node4, graphicData, size3, padding, marginOffset, anchorData, wrap6, isAnchor, isHidden) => {
438186
438512
  const wsp = graphicData.elements.find((el) => el.name === "wps:wsp");
438187
438513
  const textBox = wsp.elements.find((el) => el.name === "wps:txbx");