@extend-ai/react-docx 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -10198,6 +10198,9 @@ var LEADING_COVER_SPACER_EXTRA_HEIGHT_PX = 2;
10198
10198
  var PARAGRAPH_SEGMENT_TOP_BLEED_PX = 22;
10199
10199
  var PARAGRAPH_SEGMENT_DESCENDER_BLEED_PX = 6;
10200
10200
  var PARAGRAPH_SEGMENT_VISUAL_SAFETY_PX = 24;
10201
+ var PARAGRAPH_SEGMENT_FALLBACK_TOP_BLEED_MAX_PX = 4;
10202
+ var PARAGRAPH_SEGMENT_FALLBACK_BOTTOM_BLEED_MAX_PX = 0;
10203
+ var PARAGRAPH_SEGMENT_FALLBACK_VISUAL_SAFETY_PX = 4;
10201
10204
  var INITIAL_PAGINATION_PREMEASURE_PAGE_LIMIT = 8;
10202
10205
  var INITIAL_PAGINATION_PAGE_COUNT_OSCILLATION_DISTINCT_THRESHOLD = 2;
10203
10206
  var INITIAL_PAGINATION_PAGE_COUNT_OSCILLATION_CHANGE_THRESHOLD = 4;
@@ -10534,13 +10537,18 @@ var DOC_SURFACE_STYLE_BY_THEME = {
10534
10537
  boxShadow: "0 2px 10px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.05)"
10535
10538
  },
10536
10539
  dark: {
10537
- backgroundColor: "#111827",
10540
+ backgroundColor: "#0a0a0a",
10538
10541
  color: "#f3f4f6",
10539
10542
  colorScheme: "dark",
10540
10543
  border: "none",
10541
10544
  boxShadow: "0 2px 10px rgba(2, 6, 23, 0.55), 0 1px 2px rgba(2, 6, 23, 0.45)"
10542
10545
  }
10543
10546
  };
10547
+ var NIGHT_READER_INVERSION_FILTER = "invert(1) hue-rotate(180deg)";
10548
+ function appendCssFilters(...filters) {
10549
+ const resolvedFilters = filters.map((filter) => filter?.trim()).filter((filter) => Boolean(filter));
10550
+ return resolvedFilters.length > 0 ? resolvedFilters.join(" ") : void 0;
10551
+ }
10544
10552
  var TABLE_RESIZE_HANDLE_SIZE = 8;
10545
10553
  var TABLE_RESIZE_HANDLE_HIT_SIZE = 16;
10546
10554
  var TABLE_RESIZE_BORDER_SIZE = 1;
@@ -11471,7 +11479,7 @@ function resolveFooterPaginationReservePx(footerSections, layout) {
11471
11479
  floatingFooterBoundaryReservePx
11472
11480
  );
11473
11481
  }
11474
- function resolveMeasuredPageContentHeightPx(params) {
11482
+ function resolveMeasuredPageContentHeightDiagnostics(params) {
11475
11483
  const {
11476
11484
  pageLayout,
11477
11485
  fallbackHeightPx,
@@ -11511,34 +11519,41 @@ function resolveMeasuredPageContentHeightPx(params) {
11511
11519
  ) : 0;
11512
11520
  const correctedAllowedBodyBottomPx = Math.max(
11513
11521
  0,
11514
- guardedAllowedBodyBottomPx - renderedBodyOverrunPx - measuredFooterClearanceBufferPx
11522
+ guardedAllowedBodyBottomPx - measuredFooterClearanceBufferPx
11515
11523
  );
11516
- const iterativeMeasuredHeightPx = renderedBodyOverrunPx > 0 && Number.isFinite(effectiveCurrentMeasuredHeightPx) && effectiveCurrentMeasuredHeightPx > 0 ? Math.max(
11524
+ const iterativeMeasuredHeightPx = renderedBodyOverrunPx > 0 && !Number.isFinite(bodyTopPx) && Number.isFinite(effectiveCurrentMeasuredHeightPx) && effectiveCurrentMeasuredHeightPx > 0 ? Math.max(
11517
11525
  120,
11518
11526
  Math.round(
11519
11527
  effectiveCurrentMeasuredHeightPx - renderedBodyOverrunPx - measuredFooterClearanceBufferPx
11520
11528
  )
11521
11529
  ) : void 0;
11530
+ const bodyOverrunsFooter = renderedBodyOverrunPx > 0;
11522
11531
  if (Number.isFinite(bodyTopPx) && correctedAllowedBodyBottomPx > bodyTopPx) {
11523
11532
  const measuredHeaderClearanceBufferPx2 = headerHeightPx > 0 ? MEASURED_PAGE_HEADER_CLEARANCE_BUFFER_PX : 0;
11524
11533
  const correctedHeightPx = Math.max(
11525
11534
  120,
11526
11535
  Math.round(correctedAllowedBodyBottomPx - bodyTopPx)
11527
11536
  );
11528
- return Number.isFinite(iterativeMeasuredHeightPx) ? Math.min(
11529
- Math.max(120, correctedHeightPx - measuredHeaderClearanceBufferPx2),
11530
- Math.max(
11531
- 120,
11532
- iterativeMeasuredHeightPx - measuredHeaderClearanceBufferPx2
11533
- )
11534
- ) : Math.max(120, correctedHeightPx - measuredHeaderClearanceBufferPx2);
11537
+ return {
11538
+ heightPx: Number.isFinite(iterativeMeasuredHeightPx) ? Math.min(
11539
+ Math.max(120, correctedHeightPx - measuredHeaderClearanceBufferPx2),
11540
+ Math.max(
11541
+ 120,
11542
+ iterativeMeasuredHeightPx - measuredHeaderClearanceBufferPx2
11543
+ )
11544
+ ) : Math.max(120, correctedHeightPx - measuredHeaderClearanceBufferPx2),
11545
+ bodyOverrunsFooter
11546
+ };
11535
11547
  }
11536
11548
  const measuredHeaderClearanceBufferPx = headerHeightPx > 0 ? MEASURED_PAGE_HEADER_CLEARANCE_BUFFER_PX : 0;
11537
11549
  const correctedFallbackHeightPx = Math.max(
11538
11550
  120,
11539
11551
  fallbackHeightPx - headerHeightPx - measuredHeaderClearanceBufferPx - footerOverlapPx - renderedBodyOverrunPx - measuredFooterClearanceBufferPx
11540
11552
  );
11541
- return Number.isFinite(iterativeMeasuredHeightPx) ? Math.min(correctedFallbackHeightPx, iterativeMeasuredHeightPx) : correctedFallbackHeightPx;
11553
+ return {
11554
+ heightPx: Number.isFinite(iterativeMeasuredHeightPx) ? Math.min(correctedFallbackHeightPx, iterativeMeasuredHeightPx) : correctedFallbackHeightPx,
11555
+ bodyOverrunsFooter
11556
+ };
11542
11557
  }
11543
11558
  function resolveMeasuredBodyRenderedBottomPx(descendants) {
11544
11559
  let visualBottomPx;
@@ -11556,13 +11571,27 @@ function resolveMeasuredBodyRenderedBottomPx(descendants) {
11556
11571
  });
11557
11572
  return visualBottomPx;
11558
11573
  }
11559
- function stabilizeMeasuredPageContentHeights(current, next) {
11574
+ function stabilizeMeasuredPageContentHeights(current, next, options) {
11560
11575
  return next.map((heightPx, pageIndex) => {
11561
11576
  const roundedNextHeightPx = Math.round(heightPx);
11562
11577
  const currentHeightPx = current[pageIndex];
11563
- return Number.isFinite(currentHeightPx) ? Math.min(Math.round(currentHeightPx), roundedNextHeightPx) : roundedNextHeightPx;
11578
+ const currentPageIdentityKey = options?.currentPageIdentityKeys?.[pageIndex];
11579
+ const nextPageIdentityKey = options?.nextPageIdentityKeys?.[pageIndex];
11580
+ const canPreserveConservativeHeight = currentPageIdentityKey === void 0 || nextPageIdentityKey === void 0 || currentPageIdentityKey === nextPageIdentityKey;
11581
+ return Number.isFinite(currentHeightPx) ? canPreserveConservativeHeight ? Math.min(Math.round(currentHeightPx), roundedNextHeightPx) : roundedNextHeightPx : roundedNextHeightPx;
11564
11582
  });
11565
11583
  }
11584
+ function documentPageNodeSegmentIdentityKey(segment) {
11585
+ const tableRowRangeKey = segment.tableRowRange ? `${segment.tableRowRange.startRowIndex}-${segment.tableRowRange.endRowIndex}` : "none";
11586
+ const tableRowSliceKey = segment.tableRowSlice ? `${segment.tableRowSlice.rowIndex}-${Math.round(
11587
+ segment.tableRowSlice.startOffsetPx
11588
+ )}-${Math.round(segment.tableRowSlice.sliceHeightPx)}` : "none";
11589
+ const paragraphLineRangeKey = segment.paragraphLineRange ? `${segment.paragraphLineRange.startLineIndex}-${segment.paragraphLineRange.endLineIndex}-${segment.paragraphLineRange.totalLineCount}` : "none";
11590
+ return `${segment.nodeIndex}|${tableRowRangeKey}|${tableRowSliceKey}|${paragraphLineRangeKey}`;
11591
+ }
11592
+ function documentPageNodeSegmentsIdentityKey(pageSegments) {
11593
+ return pageSegments.map(documentPageNodeSegmentIdentityKey).join("::");
11594
+ }
11566
11595
  function buildPaginationSectionMetrics(sections, fallbackLayout) {
11567
11596
  const fallbackWidthPx = resolveSectionPaginationContentWidthPx(fallbackLayout);
11568
11597
  const fallbackHeightPx = Math.max(
@@ -11645,10 +11674,11 @@ function scaleMeasuredPageContentHeights(measuredPageContentHeightsPxByPageIndex
11645
11674
  (heightPx) => Math.max(120, Math.round(heightPx * heightScale))
11646
11675
  );
11647
11676
  }
11648
- function resolvePageContentHeightPxForPageSegments(pageSegments, pageIndex, defaultPageContentHeightPx, metricsBySection, measuredPageContentHeightsPxByPageIndex) {
11677
+ function resolvePageContentHeightPxForPageSegments(pageSegments, pageIndex, defaultPageContentHeightPx, metricsBySection, measuredPageContentHeightsPxByPageIndex, measuredPageContentIdentityKeysByPageIndex, pageIdentityKey) {
11649
11678
  const pageContainsOnlySplitParagraphSegments = documentPageContainsOnlySplitParagraphSegments(pageSegments);
11650
11679
  const measuredHeightPx = measuredPageContentHeightsPxByPageIndex?.[pageIndex];
11651
- if (Number.isFinite(measuredHeightPx) && !pageContainsOnlySplitParagraphSegments) {
11680
+ const measuredHeightMatchesCurrentPage = pageIdentityKey === void 0 || measuredPageContentIdentityKeysByPageIndex?.[pageIndex] === void 0 || measuredPageContentIdentityKeysByPageIndex?.[pageIndex] === pageIdentityKey;
11681
+ if (Number.isFinite(measuredHeightPx) && measuredHeightMatchesCurrentPage && !pageContainsOnlySplitParagraphSegments) {
11652
11682
  return Math.max(120, Math.round(measuredHeightPx));
11653
11683
  }
11654
11684
  const firstNodeIndex = pageSegments[0]?.nodeIndex ?? 0;
@@ -11664,6 +11694,17 @@ function resolvePageContentHeightPxForPageSegments(pageSegments, pageIndex, defa
11664
11694
  )
11665
11695
  );
11666
11696
  }
11697
+ function resolveRenderPageContentHeightPxForPageSegments(params) {
11698
+ return resolvePageContentHeightPxForPageSegments(
11699
+ params.pageSegments,
11700
+ params.pageIndex,
11701
+ params.defaultPageContentHeightPx,
11702
+ params.metricsBySection,
11703
+ params.useMeasuredPageContentHeights === false ? void 0 : params.measuredPageContentHeightsPxByPageIndex,
11704
+ params.useMeasuredPageContentHeights === false ? void 0 : params.measuredPageContentIdentityKeysByPageIndex,
11705
+ params.pageIdentityKey
11706
+ );
11707
+ }
11667
11708
  function documentPageContainsOnlySplitParagraphSegments(pageSegments) {
11668
11709
  return pageSegments.length > 0 && pageSegments.every(
11669
11710
  (segment) => !segment.tableRowRange && paragraphSegmentHasPartialLineRange(segment.paragraphLineRange)
@@ -12543,10 +12584,11 @@ function sectionNodesNeedPageWideLayout(nodes, pageWidthPx, contentWidthPx) {
12543
12584
  return false;
12544
12585
  }
12545
12586
  const horizontalRelativeTo = image.floating.horizontalRelativeTo?.toLowerCase();
12546
- if (image.floating.behindDocument || horizontalRelativeTo === "page") {
12587
+ const usesPageWidthAnchorOrigin = horizontalRelativeTo === "page" || horizontalRelativeTo === "margin";
12588
+ if (image.floating.behindDocument && usesPageWidthAnchorOrigin) {
12547
12589
  return true;
12548
12590
  }
12549
- if (shouldRenderAbsoluteFloatingImage(image)) {
12591
+ if (usesPageWidthAnchorOrigin && (shouldRenderAbsoluteFloatingImage(image) || shouldRenderWrappedFloatingImage(image))) {
12550
12592
  return true;
12551
12593
  }
12552
12594
  if (Number.isFinite(image.widthPx) && Number.isFinite(image.floating.xPx) && image.widthPx >= safeContentWidthPx - 12 && image.floating.xPx <= 12) {
@@ -13133,6 +13175,9 @@ function buildSyntheticPretextLayoutSource(text, style) {
13133
13175
  function pretextWordBreakModeForText(text) {
13134
13176
  return KEEP_ALL_SCRIPT_RE.test(text) ? "keep-all" : "normal";
13135
13177
  }
13178
+ function sanitizeRenderedPretextFragmentText(text) {
13179
+ return text.replace(/\r\n?|\n/g, "");
13180
+ }
13136
13181
  function buildParagraphPretextLayoutItems(paragraph, source) {
13137
13182
  const paragraphBaseFontPx = paragraphBaseFontSizePx(paragraph);
13138
13183
  const wordBreak = pretextWordBreakModeForText(source.text);
@@ -14245,6 +14290,20 @@ function paragraphBaseFontSizePx(paragraph) {
14245
14290
  const fontSizePt = dominantRunFontSizePt && dominantRunFontSizePt > 0 ? dominantRunFontSizePt : Number.isFinite(paragraph.style?.headingLevel) ? DEFAULT_PARAGRAPH_FONT_SIZE_PT + Math.max(0, 6 - (paragraph.style?.headingLevel ?? 6)) : DEFAULT_PARAGRAPH_FONT_SIZE_PT;
14246
14291
  return Math.max(10, Math.round(fontSizePt * 96 / 72));
14247
14292
  }
14293
+ function paragraphMaxFontSizePx(paragraph) {
14294
+ const paragraphBaseFontPx = paragraphBaseFontSizePx(paragraph);
14295
+ let maxFontSizePx = paragraphBaseFontPx;
14296
+ paragraph.children.forEach((child) => {
14297
+ if (child.type !== "text" && child.type !== "form-field") {
14298
+ return;
14299
+ }
14300
+ maxFontSizePx = Math.max(
14301
+ maxFontSizePx,
14302
+ resolveMeasureFontSizePx(child.style, paragraphBaseFontPx)
14303
+ );
14304
+ });
14305
+ return Math.max(1, Math.round(maxFontSizePx));
14306
+ }
14248
14307
  function normalizeFontFamilyToken(fontFamily) {
14249
14308
  if (!fontFamily) {
14250
14309
  return void 0;
@@ -15442,6 +15501,34 @@ function resolveParagraphSegmentClipBleedPx(paragraphLineRange) {
15442
15501
  bottomPx: Math.max(0, PARAGRAPH_SEGMENT_DESCENDER_BLEED_PX)
15443
15502
  };
15444
15503
  }
15504
+ function resolveFallbackParagraphSegmentClipBleedPx(paragraph, paragraphLineRange) {
15505
+ if (!paragraphSegmentHasPartialLineRange(paragraphLineRange)) {
15506
+ return {
15507
+ topPx: 0,
15508
+ bottomPx: 0
15509
+ };
15510
+ }
15511
+ const lineHeightPx = Math.max(1, paragraphLineRange?.lineHeightPx ?? 0);
15512
+ const maxFontSizePx = paragraphMaxFontSizePx(paragraph);
15513
+ const glyphOvershootPx = Math.max(
15514
+ 0,
15515
+ Math.ceil((maxFontSizePx - lineHeightPx) / 2)
15516
+ );
15517
+ const ascenderSafetyPx = Math.max(
15518
+ glyphOvershootPx,
15519
+ Math.ceil(lineHeightPx * 0.22)
15520
+ );
15521
+ return {
15522
+ topPx: paragraphLineRange && paragraphLineRange.startLineIndex > 0 ? Math.min(
15523
+ PARAGRAPH_SEGMENT_FALLBACK_TOP_BLEED_MAX_PX,
15524
+ ascenderSafetyPx
15525
+ ) : 0,
15526
+ bottomPx: paragraphLineRange && paragraphLineRange.endLineIndex < paragraphLineRange.totalLineCount ? Math.min(
15527
+ PARAGRAPH_SEGMENT_FALLBACK_BOTTOM_BLEED_MAX_PX,
15528
+ glyphOvershootPx
15529
+ ) : 0
15530
+ };
15531
+ }
15445
15532
  function resolveParagraphSegmentNonFlowReservePx(paragraphLineRange) {
15446
15533
  const bleed = resolveParagraphSegmentClipBleedPx(paragraphLineRange);
15447
15534
  if (bleed.topPx <= 0 && bleed.bottomPx <= 0) {
@@ -15453,6 +15540,20 @@ function resolveParagraphSegmentNonFlowReservePx(paragraphLineRange) {
15453
15540
  );
15454
15541
  return Math.max(0, bleed.topPx) + Math.max(0, bleed.bottomPx) + Math.max(0, PARAGRAPH_SEGMENT_VISUAL_SAFETY_PX, lineHeightSafetyPx);
15455
15542
  }
15543
+ function resolveFallbackParagraphSegmentNonFlowReservePx(paragraph, paragraphLineRange) {
15544
+ const bleed = resolveFallbackParagraphSegmentClipBleedPx(
15545
+ paragraph,
15546
+ paragraphLineRange
15547
+ );
15548
+ if (bleed.topPx <= 0 && bleed.bottomPx <= 0) {
15549
+ return 0;
15550
+ }
15551
+ const lineHeightSafetyPx = Math.max(
15552
+ 0,
15553
+ Math.ceil((paragraphLineRange?.lineHeightPx ?? 0) * 0.15)
15554
+ );
15555
+ return Math.max(0, bleed.topPx) + Math.max(0, bleed.bottomPx) + Math.max(1, PARAGRAPH_SEGMENT_FALLBACK_VISUAL_SAFETY_PX, lineHeightSafetyPx);
15556
+ }
15456
15557
  function paragraphSegmentIdentityMatches(segment, nodeIndex, paragraphLineRange) {
15457
15558
  if (!segment || !paragraphLineRange) {
15458
15559
  return false;
@@ -15792,13 +15893,17 @@ function buildDocumentPageNodeSegments(model, pageContentHeightPx, pageContentWi
15792
15893
  node,
15793
15894
  nodeMetrics.docGridLinePitchPx
15794
15895
  );
15896
+ const paragraphPretextSourceForSegmentRendering = buildParagraphPretextLayoutSource(node, {
15897
+ allowExplicitLineBreakText: true
15898
+ });
15899
+ const paragraphSupportsPretextSegmentRendering = Boolean(
15900
+ paragraphPretextSourceForSegmentRendering
15901
+ );
15795
15902
  const paragraphPretextLineCount = (() => {
15796
15903
  if (!paragraphContainsExplicitLineBreakText(node)) {
15797
15904
  return void 0;
15798
15905
  }
15799
- const pretextSource = buildParagraphPretextLayoutSource(node, {
15800
- allowExplicitLineBreakText: true
15801
- });
15906
+ const pretextSource = paragraphPretextSourceForSegmentRendering;
15802
15907
  if (!pretextSource) {
15803
15908
  return void 0;
15804
15909
  }
@@ -15816,11 +15921,7 @@ function buildDocumentPageNodeSegments(model, pageContentHeightPx, pageContentWi
15816
15921
  );
15817
15922
  return pretextLayout?.lineCount;
15818
15923
  })();
15819
- const supportsImageParagraphLineSplit = paragraphHasImage2(node) && Boolean(
15820
- buildParagraphPretextLayoutSource(node, {
15821
- allowExplicitLineBreakText: true
15822
- })
15823
- );
15924
+ const supportsImageParagraphLineSplit = paragraphHasImage2(node) && paragraphSupportsPretextSegmentRendering;
15824
15925
  const paragraphLineCount = paragraphLineCountWithinWidth(
15825
15926
  node,
15826
15927
  nodeMetrics.pageContentWidthPx,
@@ -15835,6 +15936,18 @@ function buildDocumentPageNodeSegments(model, pageContentHeightPx, pageContentWi
15835
15936
  allowImageParagraphSplit: supportsImageParagraphLineSplit
15836
15937
  }) && (!widowControlEnabled || resolvedParagraphLineCount > 3);
15837
15938
  if (canSplitParagraphAcrossPages && allowParagraphLineSplitting) {
15939
+ const resolveSegmentReservePx = (startLineIndex, endLineIndex) => {
15940
+ const paragraphSegmentRange = {
15941
+ startLineIndex,
15942
+ endLineIndex,
15943
+ totalLineCount: resolvedParagraphLineCount,
15944
+ lineHeightPx: paragraphLineHeightPx
15945
+ };
15946
+ return paragraphSupportsPretextSegmentRendering ? resolveParagraphSegmentNonFlowReservePx(paragraphSegmentRange) : resolveFallbackParagraphSegmentNonFlowReservePx(
15947
+ node,
15948
+ paragraphSegmentRange
15949
+ );
15950
+ };
15838
15951
  let lineCursor = 0;
15839
15952
  let isFirstSegment = true;
15840
15953
  while (lineCursor < resolvedParagraphLineCount) {
@@ -15846,12 +15959,10 @@ function buildDocumentPageNodeSegments(model, pageContentHeightPx, pageContentWi
15846
15959
  0,
15847
15960
  currentPageContentHeightPx - pageConsumedHeightPx
15848
15961
  );
15849
- const allRemainingSegmentReservePx = resolveParagraphSegmentNonFlowReservePx({
15850
- startLineIndex: lineCursor,
15851
- endLineIndex: resolvedParagraphLineCount,
15852
- totalLineCount: resolvedParagraphLineCount,
15853
- lineHeightPx: paragraphLineHeightPx
15854
- });
15962
+ const allRemainingSegmentReservePx = resolveSegmentReservePx(
15963
+ lineCursor,
15964
+ resolvedParagraphLineCount
15965
+ );
15855
15966
  const allRemainingHeightPx = topSpacingPx + linesRemaining * paragraphLineHeightPx + bottomSpacingPx;
15856
15967
  if (allRemainingHeightPx + allRemainingSegmentReservePx <= remainingHeightPx2) {
15857
15968
  currentPageSegments.push({
@@ -15872,15 +15983,10 @@ function buildDocumentPageNodeSegments(model, pageContentHeightPx, pageContentWi
15872
15983
  0,
15873
15984
  linesRemaining - minLinesPerSegment
15874
15985
  );
15875
- const continuingSegmentReservePx = resolveParagraphSegmentNonFlowReservePx({
15876
- startLineIndex: lineCursor,
15877
- endLineIndex: Math.min(
15878
- resolvedParagraphLineCount,
15879
- lineCursor + maxLinesThisPage
15880
- ),
15881
- totalLineCount: resolvedParagraphLineCount,
15882
- lineHeightPx: paragraphLineHeightPx
15883
- });
15986
+ const continuingSegmentReservePx = resolveSegmentReservePx(
15987
+ lineCursor,
15988
+ Math.min(resolvedParagraphLineCount, lineCursor + maxLinesThisPage)
15989
+ );
15884
15990
  const availableForLinesPx = Math.max(
15885
15991
  0,
15886
15992
  remainingHeightPx2 - topSpacingPx - continuingSegmentReservePx
@@ -15919,12 +16025,10 @@ function buildDocumentPageNodeSegments(model, pageContentHeightPx, pageContentWi
15919
16025
  lineCursor + linesThatFit
15920
16026
  );
15921
16027
  while (linesThatFit > minLinesPerSegment) {
15922
- const segmentReservePx = resolveParagraphSegmentNonFlowReservePx({
15923
- startLineIndex: lineCursor,
15924
- endLineIndex: segmentEndLineIndex,
15925
- totalLineCount: resolvedParagraphLineCount,
15926
- lineHeightPx: paragraphLineHeightPx
15927
- });
16028
+ const segmentReservePx = resolveSegmentReservePx(
16029
+ lineCursor,
16030
+ segmentEndLineIndex
16031
+ );
15928
16032
  if (topSpacingPx + (segmentEndLineIndex - lineCursor) * paragraphLineHeightPx + segmentReservePx <= remainingHeightPx2) {
15929
16033
  break;
15930
16034
  }
@@ -16425,17 +16529,18 @@ function wrappedFloatingImageStyle(image, options) {
16425
16529
  });
16426
16530
  const horizontalRelativeTo = floating.horizontalRelativeTo?.toLowerCase();
16427
16531
  const explicitHorizontalInsetPx = hasExplicitHorizontalOffset && !hasExplicitHorizontalAlign && (horizontalRelativeTo === "margin" || horizontalRelativeTo === "page" || horizontalRelativeTo === "column") ? side === "left" ? Math.max(0, leftOffsetPx) : Math.max(0, rightOffsetPx) : 0;
16532
+ const columnAnchoredExplicitInset = explicitHorizontalInsetPx > 0 && horizontalRelativeTo === "column";
16428
16533
  return {
16429
16534
  display: "block",
16430
16535
  ...intrinsicBlockWidthStyle,
16431
16536
  float: side,
16432
16537
  marginTop: topOffsetPx,
16433
16538
  marginBottom: distB,
16434
- marginLeft: side === "left" ? explicitHorizontalInsetPx > 0 ? 0 : hasExplicitHorizontalOffset ? leftOffsetPx : distL + leftOffsetPx : distL,
16435
- marginRight: side === "right" ? explicitHorizontalInsetPx > 0 ? 0 : hasExplicitHorizontalOffset ? rightOffsetPx : distR + rightOffsetPx : distR,
16436
- paddingLeft: side === "left" && explicitHorizontalInsetPx > 0 ? explicitHorizontalInsetPx : void 0,
16437
- paddingRight: side === "right" && explicitHorizontalInsetPx > 0 ? explicitHorizontalInsetPx : void 0,
16438
- boxSizing: explicitHorizontalInsetPx > 0 ? "content-box" : void 0
16539
+ marginLeft: side === "left" ? explicitHorizontalInsetPx > 0 ? columnAnchoredExplicitInset ? distL + explicitHorizontalInsetPx : 0 : hasExplicitHorizontalOffset ? leftOffsetPx : distL + leftOffsetPx : distL,
16540
+ marginRight: side === "right" ? explicitHorizontalInsetPx > 0 ? columnAnchoredExplicitInset ? distR + explicitHorizontalInsetPx : 0 : hasExplicitHorizontalOffset ? rightOffsetPx : distR + rightOffsetPx : distR,
16541
+ paddingLeft: side === "left" && explicitHorizontalInsetPx > 0 && !columnAnchoredExplicitInset ? explicitHorizontalInsetPx : void 0,
16542
+ paddingRight: side === "right" && explicitHorizontalInsetPx > 0 && !columnAnchoredExplicitInset ? explicitHorizontalInsetPx : void 0,
16543
+ boxSizing: explicitHorizontalInsetPx > 0 && !columnAnchoredExplicitInset ? "content-box" : void 0
16439
16544
  };
16440
16545
  }
16441
16546
  function wrappedFloatingImageDualExclusionLayout(image, options) {
@@ -19174,7 +19279,7 @@ function renderParagraphRuns(paragraph, keyPrefix, documentTheme = "light", numb
19174
19279
  (() => {
19175
19280
  const cropLayout = imageCropLayout(child, widthPx, heightPx);
19176
19281
  const imageVisualStyle = {
19177
- filter: child.cssFilter,
19282
+ filter: appendCssFilters(child.cssFilter, options?.imageFilterSuffix),
19178
19283
  opacity: child.cssOpacity
19179
19284
  };
19180
19285
  const imageTransformStyle = resolveImageRenderTransformStyle(child, {
@@ -26719,6 +26824,370 @@ function useDocxEditor(options = {}) {
26719
26824
  commitSectionParagraphText
26720
26825
  };
26721
26826
  }
26827
+ var docxViewerPageSurfaceRegistryByEditor = /* @__PURE__ */ new WeakMap();
26828
+ function docxViewerPageSurfaceRegistryOwner(editor) {
26829
+ return editor.syncPaginationInfo;
26830
+ }
26831
+ function ensureDocxViewerPageSurfaceRegistry(editor) {
26832
+ const owner = docxViewerPageSurfaceRegistryOwner(editor);
26833
+ let registry = docxViewerPageSurfaceRegistryByEditor.get(owner);
26834
+ if (!registry) {
26835
+ registry = {
26836
+ pageElements: /* @__PURE__ */ new Map(),
26837
+ listeners: /* @__PURE__ */ new Set()
26838
+ };
26839
+ docxViewerPageSurfaceRegistryByEditor.set(owner, registry);
26840
+ }
26841
+ return registry;
26842
+ }
26843
+ function subscribeDocxViewerPageSurfaces(editor, listener) {
26844
+ const registry = ensureDocxViewerPageSurfaceRegistry(editor);
26845
+ registry.listeners.add(listener);
26846
+ return () => {
26847
+ registry.listeners.delete(listener);
26848
+ };
26849
+ }
26850
+ function notifyDocxViewerPageSurfaceSubscribers(registry) {
26851
+ registry.listeners.forEach((listener) => {
26852
+ listener();
26853
+ });
26854
+ }
26855
+ function registerDocxViewerPageSurface(editor, pageIndex, element) {
26856
+ const registry = ensureDocxViewerPageSurfaceRegistry(editor);
26857
+ const normalizedPageIndex = Math.max(0, Math.round(pageIndex));
26858
+ const currentElement = registry.pageElements.get(normalizedPageIndex);
26859
+ if (element) {
26860
+ if (currentElement === element) {
26861
+ return;
26862
+ }
26863
+ registry.pageElements.set(normalizedPageIndex, element);
26864
+ notifyDocxViewerPageSurfaceSubscribers(registry);
26865
+ return;
26866
+ }
26867
+ if (!currentElement) {
26868
+ return;
26869
+ }
26870
+ registry.pageElements.delete(normalizedPageIndex);
26871
+ notifyDocxViewerPageSurfaceSubscribers(registry);
26872
+ }
26873
+ function resolveDocxViewerPageSurfaceSize(element, fallbackWidthPx, fallbackHeightPx) {
26874
+ if (element) {
26875
+ const rect = element.getBoundingClientRect();
26876
+ const rectWidthPx = Number.isFinite(rect.width) ? rect.width : 0;
26877
+ const rectHeightPx = Number.isFinite(rect.height) ? rect.height : 0;
26878
+ const offsetWidthPx = Number.isFinite(element.offsetWidth) ? element.offsetWidth : 0;
26879
+ const offsetHeightPx = Number.isFinite(element.offsetHeight) ? element.offsetHeight : 0;
26880
+ const clientWidthPx = Number.isFinite(element.clientWidth) ? element.clientWidth : 0;
26881
+ const clientHeightPx = Number.isFinite(element.clientHeight) ? element.clientHeight : 0;
26882
+ const resolvedWidthPx = Math.max(
26883
+ 0,
26884
+ rectWidthPx,
26885
+ offsetWidthPx,
26886
+ clientWidthPx
26887
+ );
26888
+ const resolvedHeightPx = Math.max(
26889
+ 0,
26890
+ rectHeightPx,
26891
+ offsetHeightPx,
26892
+ clientHeightPx
26893
+ );
26894
+ if (resolvedWidthPx > 0 && resolvedHeightPx > 0) {
26895
+ return {
26896
+ widthPx: Math.round(resolvedWidthPx),
26897
+ heightPx: Math.round(resolvedHeightPx)
26898
+ };
26899
+ }
26900
+ }
26901
+ return {
26902
+ widthPx: Math.max(1, Math.round(fallbackWidthPx)),
26903
+ heightPx: Math.max(1, Math.round(fallbackHeightPx))
26904
+ };
26905
+ }
26906
+ async function rasterizeDocxViewerPageSurfaceToCanvas(params) {
26907
+ if (typeof window === "undefined" || typeof XMLSerializer === "undefined") {
26908
+ throw new Error("DOCX thumbnails require a browser environment.");
26909
+ }
26910
+ const {
26911
+ pageElement,
26912
+ sourceWidthPx,
26913
+ sourceHeightPx,
26914
+ canvas,
26915
+ widthPx,
26916
+ heightPx,
26917
+ pixelWidthPx,
26918
+ pixelHeightPx
26919
+ } = params;
26920
+ const safeSourceWidthPx = Math.max(1, Math.round(sourceWidthPx));
26921
+ const safeSourceHeightPx = Math.max(1, Math.round(sourceHeightPx));
26922
+ const scaleX = widthPx / safeSourceWidthPx;
26923
+ const scaleY = heightPx / safeSourceHeightPx;
26924
+ const serializedPage = new XMLSerializer().serializeToString(
26925
+ pageElement.cloneNode(true)
26926
+ );
26927
+ const svgMarkup = `
26928
+ <svg xmlns="http://www.w3.org/2000/svg" width="${widthPx}" height="${heightPx}" viewBox="0 0 ${widthPx} ${heightPx}">
26929
+ <foreignObject x="0" y="0" width="100%" height="100%">
26930
+ <div xmlns="http://www.w3.org/1999/xhtml" style="width:${widthPx}px;height:${heightPx}px;overflow:hidden;">
26931
+ <div style="width:${safeSourceWidthPx}px;height:${safeSourceHeightPx}px;transform-origin:top left;transform:scale(${scaleX}, ${scaleY});">
26932
+ ${serializedPage}
26933
+ </div>
26934
+ </div>
26935
+ </foreignObject>
26936
+ </svg>
26937
+ `;
26938
+ const blob = new Blob([svgMarkup], {
26939
+ type: "image/svg+xml;charset=utf-8"
26940
+ });
26941
+ const objectUrl = URL.createObjectURL(blob);
26942
+ try {
26943
+ const image = await new Promise((resolve, reject) => {
26944
+ const nextImage = new Image();
26945
+ nextImage.decoding = "async";
26946
+ nextImage.onload = () => resolve(nextImage);
26947
+ nextImage.onerror = () => {
26948
+ reject(new Error("Failed to rasterize DOCX page thumbnail."));
26949
+ };
26950
+ nextImage.src = objectUrl;
26951
+ });
26952
+ canvas.width = Math.max(1, Math.round(pixelWidthPx));
26953
+ canvas.height = Math.max(1, Math.round(pixelHeightPx));
26954
+ canvas.style.width = `${Math.max(1, Math.round(widthPx))}px`;
26955
+ canvas.style.height = `${Math.max(1, Math.round(heightPx))}px`;
26956
+ const context = canvas.getContext("2d");
26957
+ if (!context) {
26958
+ throw new Error("2D canvas context is unavailable for DOCX thumbnails.");
26959
+ }
26960
+ context.setTransform(1, 0, 0, 1, 0, 0);
26961
+ context.clearRect(0, 0, canvas.width, canvas.height);
26962
+ context.imageSmoothingEnabled = true;
26963
+ context.imageSmoothingQuality = "high";
26964
+ context.drawImage(image, 0, 0, canvas.width, canvas.height);
26965
+ } finally {
26966
+ URL.revokeObjectURL(objectUrl);
26967
+ }
26968
+ }
26969
+ function resolveDocxPageThumbnailResolution(options) {
26970
+ const safeSourceWidthPx = Math.max(1, Math.round(options.sourceWidthPx));
26971
+ const safeSourceHeightPx = Math.max(1, Math.round(options.sourceHeightPx));
26972
+ const widthBoundPx = Number.isFinite(options.maxWidthPx) ? Math.max(1, Math.round(options.maxWidthPx)) : 180;
26973
+ const heightBoundPx = Number.isFinite(options.maxHeightPx) ? Math.max(1, Math.round(options.maxHeightPx)) : Number.POSITIVE_INFINITY;
26974
+ const scale = Math.min(
26975
+ 1,
26976
+ widthBoundPx / safeSourceWidthPx,
26977
+ heightBoundPx / safeSourceHeightPx
26978
+ );
26979
+ const pixelRatio = Number.isFinite(options.pixelRatio) ? Math.max(1, Number(options.pixelRatio)) : 1;
26980
+ const widthPx = Math.max(1, Math.round(safeSourceWidthPx * scale));
26981
+ const heightPx = Math.max(1, Math.round(safeSourceHeightPx * scale));
26982
+ return {
26983
+ widthPx,
26984
+ heightPx,
26985
+ pixelWidthPx: Math.max(1, Math.round(widthPx * pixelRatio)),
26986
+ pixelHeightPx: Math.max(1, Math.round(heightPx * pixelRatio)),
26987
+ scale
26988
+ };
26989
+ }
26990
+ function useDocxPageThumbnails(editor, options = {}) {
26991
+ const pageSurfaceRegistryOwner = docxViewerPageSurfaceRegistryOwner(editor);
26992
+ const pageSurfaceRegistryEditor = React.useMemo(
26993
+ () => ({ syncPaginationInfo: editor.syncPaginationInfo }),
26994
+ [pageSurfaceRegistryOwner]
26995
+ );
26996
+ const [pageSurfaceEpoch, setPageSurfaceEpoch] = React.useState(0);
26997
+ const [pageThumbnailStates, setPageThumbnailStates] = React.useState(() => /* @__PURE__ */ new Map());
26998
+ const attachedCanvasByPageRef = React.useRef(
26999
+ /* @__PURE__ */ new Map()
27000
+ );
27001
+ const canvasRefCallbacksRef = React.useRef(/* @__PURE__ */ new Map());
27002
+ const renderToCanvasCallbacksRef = React.useRef(/* @__PURE__ */ new Map());
27003
+ const fallbackLayout = React.useMemo(
27004
+ () => resolveDocumentLayout(editor.model),
27005
+ [editor.model]
27006
+ );
27007
+ const pageSurfaceRegistry = React.useMemo(
27008
+ () => ensureDocxViewerPageSurfaceRegistry(pageSurfaceRegistryEditor),
27009
+ [pageSurfaceRegistryEditor]
27010
+ );
27011
+ React.useEffect(
27012
+ () => subscribeDocxViewerPageSurfaces(
27013
+ pageSurfaceRegistryEditor,
27014
+ () => {
27015
+ setPageSurfaceEpoch((current) => current + 1);
27016
+ }
27017
+ ),
27018
+ [pageSurfaceRegistryEditor]
27019
+ );
27020
+ const mountedPageElements = React.useMemo(
27021
+ () => new Map(pageSurfaceRegistry.pageElements),
27022
+ [pageSurfaceEpoch, pageSurfaceRegistry.pageElements]
27023
+ );
27024
+ const updatePageThumbnailState = React.useCallback(
27025
+ (pageIndex, status, error) => {
27026
+ setPageThumbnailStates((current) => {
27027
+ const next = new Map(current);
27028
+ const previous = next.get(pageIndex);
27029
+ if (previous?.status === status && previous?.error?.message === error?.message) {
27030
+ return current;
27031
+ }
27032
+ next.set(pageIndex, { status, error });
27033
+ return next;
27034
+ });
27035
+ },
27036
+ []
27037
+ );
27038
+ const renderPageThumbnailToCanvas = React.useCallback(
27039
+ async (pageIndex, canvas) => {
27040
+ if (options.disabled) {
27041
+ return;
27042
+ }
27043
+ const targetCanvas = canvas ?? attachedCanvasByPageRef.current.get(pageIndex);
27044
+ if (!targetCanvas) {
27045
+ return;
27046
+ }
27047
+ const pageElement = mountedPageElements.get(pageIndex);
27048
+ if (!pageElement || !pageElement.isConnected) {
27049
+ updatePageThumbnailState(pageIndex, "unavailable");
27050
+ return;
27051
+ }
27052
+ const sourceSize = resolveDocxViewerPageSurfaceSize(
27053
+ pageElement,
27054
+ fallbackLayout.pageWidthPx,
27055
+ fallbackLayout.pageHeightPx
27056
+ );
27057
+ const resolution = resolveDocxPageThumbnailResolution({
27058
+ sourceWidthPx: sourceSize.widthPx,
27059
+ sourceHeightPx: sourceSize.heightPx,
27060
+ maxWidthPx: options.maxWidthPx,
27061
+ maxHeightPx: options.maxHeightPx,
27062
+ pixelRatio: options.pixelRatio
27063
+ });
27064
+ updatePageThumbnailState(pageIndex, "rendering");
27065
+ try {
27066
+ await rasterizeDocxViewerPageSurfaceToCanvas({
27067
+ pageElement,
27068
+ sourceWidthPx: sourceSize.widthPx,
27069
+ sourceHeightPx: sourceSize.heightPx,
27070
+ canvas: targetCanvas,
27071
+ widthPx: resolution.widthPx,
27072
+ heightPx: resolution.heightPx,
27073
+ pixelWidthPx: resolution.pixelWidthPx,
27074
+ pixelHeightPx: resolution.pixelHeightPx
27075
+ });
27076
+ updatePageThumbnailState(pageIndex, "ready");
27077
+ } catch (error) {
27078
+ updatePageThumbnailState(
27079
+ pageIndex,
27080
+ "error",
27081
+ error instanceof Error ? error : new Error("Failed to render DOCX page thumbnail.")
27082
+ );
27083
+ }
27084
+ },
27085
+ [
27086
+ fallbackLayout.pageHeightPx,
27087
+ fallbackLayout.pageWidthPx,
27088
+ mountedPageElements,
27089
+ options.disabled,
27090
+ options.maxHeightPx,
27091
+ options.maxWidthPx,
27092
+ options.pixelRatio,
27093
+ updatePageThumbnailState
27094
+ ]
27095
+ );
27096
+ const rerenderAttachedThumbnails = React.useCallback(async () => {
27097
+ const tasks = [...attachedCanvasByPageRef.current.keys()].map(
27098
+ (pageIndex) => renderPageThumbnailToCanvas(pageIndex)
27099
+ );
27100
+ await Promise.all(tasks);
27101
+ }, [renderPageThumbnailToCanvas]);
27102
+ const renderPageThumbnailToCanvasRef = React.useRef(renderPageThumbnailToCanvas);
27103
+ React.useEffect(() => {
27104
+ renderPageThumbnailToCanvasRef.current = renderPageThumbnailToCanvas;
27105
+ }, [renderPageThumbnailToCanvas]);
27106
+ React.useEffect(() => {
27107
+ canvasRefCallbacksRef.current.clear();
27108
+ renderToCanvasCallbacksRef.current.clear();
27109
+ }, [pageSurfaceRegistryOwner]);
27110
+ React.useEffect(() => {
27111
+ void rerenderAttachedThumbnails();
27112
+ }, [
27113
+ editor.documentLoadNonce,
27114
+ editor.documentTheme,
27115
+ editor.model,
27116
+ mountedPageElements,
27117
+ options.disabled,
27118
+ options.maxHeightPx,
27119
+ options.maxWidthPx,
27120
+ options.pixelRatio,
27121
+ rerenderAttachedThumbnails
27122
+ ]);
27123
+ const thumbnails = React.useMemo(() => {
27124
+ const totalPages = Math.max(1, editor.totalPages);
27125
+ return Array.from({ length: totalPages }, (_, pageIndex) => {
27126
+ const pageElement = mountedPageElements.get(pageIndex);
27127
+ const sourceSize = resolveDocxViewerPageSurfaceSize(
27128
+ pageElement,
27129
+ fallbackLayout.pageWidthPx,
27130
+ fallbackLayout.pageHeightPx
27131
+ );
27132
+ const resolution = resolveDocxPageThumbnailResolution({
27133
+ sourceWidthPx: sourceSize.widthPx,
27134
+ sourceHeightPx: sourceSize.heightPx,
27135
+ maxWidthPx: options.maxWidthPx,
27136
+ maxHeightPx: options.maxHeightPx,
27137
+ pixelRatio: options.pixelRatio
27138
+ });
27139
+ const state = pageThumbnailStates.get(pageIndex);
27140
+ return {
27141
+ pageIndex,
27142
+ pageNumber: pageIndex + 1,
27143
+ sourceWidthPx: sourceSize.widthPx,
27144
+ sourceHeightPx: sourceSize.heightPx,
27145
+ isMounted: Boolean(pageElement && pageElement.isConnected),
27146
+ status: state?.status ?? (pageElement ? "idle" : "unavailable"),
27147
+ error: state?.error,
27148
+ canvasRef: canvasRefCallbacksRef.current.get(pageIndex) ?? (() => {
27149
+ const nextCanvasRef = (canvas) => {
27150
+ if (canvas) {
27151
+ attachedCanvasByPageRef.current.set(pageIndex, canvas);
27152
+ void renderPageThumbnailToCanvasRef.current(pageIndex, canvas);
27153
+ return;
27154
+ }
27155
+ attachedCanvasByPageRef.current.delete(pageIndex);
27156
+ };
27157
+ canvasRefCallbacksRef.current.set(pageIndex, nextCanvasRef);
27158
+ return nextCanvasRef;
27159
+ })(),
27160
+ renderToCanvas: renderToCanvasCallbacksRef.current.get(pageIndex) ?? (() => {
27161
+ const nextRenderToCanvas = async (canvas) => {
27162
+ await renderPageThumbnailToCanvasRef.current(pageIndex, canvas);
27163
+ };
27164
+ renderToCanvasCallbacksRef.current.set(
27165
+ pageIndex,
27166
+ nextRenderToCanvas
27167
+ );
27168
+ return nextRenderToCanvas;
27169
+ })(),
27170
+ ...resolution
27171
+ };
27172
+ });
27173
+ }, [
27174
+ editor.totalPages,
27175
+ fallbackLayout.pageHeightPx,
27176
+ fallbackLayout.pageWidthPx,
27177
+ mountedPageElements,
27178
+ options.maxHeightPx,
27179
+ options.maxWidthPx,
27180
+ options.pixelRatio,
27181
+ pageThumbnailStates
27182
+ ]);
27183
+ return React.useMemo(
27184
+ () => ({
27185
+ thumbnails,
27186
+ rerenderAttachedThumbnails
27187
+ }),
27188
+ [rerenderAttachedThumbnails, thumbnails]
27189
+ );
27190
+ }
26722
27191
  function useDocxDocumentTheme(editor) {
26723
27192
  const setDocumentTheme = React.useCallback(
26724
27193
  (theme) => {
@@ -27780,6 +28249,7 @@ function DocxEditorViewer({
27780
28249
  editor,
27781
28250
  className,
27782
28251
  style,
28252
+ pageBackgroundColor,
27783
28253
  pageGapBackgroundColor,
27784
28254
  deferInitialPaginationPaint = true,
27785
28255
  loadingState,
@@ -27795,10 +28265,14 @@ function DocxEditorViewer({
27795
28265
  onFormFieldDoubleClick,
27796
28266
  mode = "edit"
27797
28267
  }) {
28268
+ const pageSurfaceRegistryOwner = docxViewerPageSurfaceRegistryOwner(editor);
27798
28269
  const trackedChangesEnabled = showTrackedChanges ?? editor.showTrackedChanges;
27799
28270
  const hasTrackedChanges = editor.trackedChanges.length > 0;
27800
28271
  const showTrackedChangeGutter = trackedChangesEnabled;
27801
28272
  const isReadOnly = mode === "read-only" || trackedChangesEnabled;
28273
+ const isNightReaderMode = isReadOnly && editor.documentTheme === "dark";
28274
+ const documentContentTheme = isNightReaderMode ? "light" : editor.documentTheme;
28275
+ const documentContentFilter = isNightReaderMode ? NIGHT_READER_INVERSION_FILTER : void 0;
27802
28276
  const canReplaceDocumentByDrop = mode !== "read-only";
27803
28277
  const formFieldLocationKey = React.useCallback(
27804
28278
  (location) => {
@@ -27814,9 +28288,11 @@ function DocxEditorViewer({
27814
28288
  () => ({
27815
28289
  showTrackedChanges: trackedChangesEnabled,
27816
28290
  numberingDefinitions: editor.model.metadata.numberingDefinitions,
27817
- tocLinkColorByLevel
28291
+ tocLinkColorByLevel,
28292
+ imageFilterSuffix: documentContentFilter
27818
28293
  }),
27819
28294
  [
28295
+ documentContentFilter,
27820
28296
  editor.model.metadata.numberingDefinitions,
27821
28297
  tocLinkColorByLevel,
27822
28298
  trackedChangesEnabled
@@ -27854,6 +28330,8 @@ function DocxEditorViewer({
27854
28330
  /* @__PURE__ */ new Map()
27855
28331
  );
27856
28332
  const pageElementsRef = React.useRef(/* @__PURE__ */ new Map());
28333
+ const pagePlaceholderRefCallbacksRef = React.useRef(/* @__PURE__ */ new Map());
28334
+ const pageSurfaceRefCallbacksRef = React.useRef(/* @__PURE__ */ new Map());
27857
28335
  const trackedChangeCardElementsRef = React.useRef(/* @__PURE__ */ new Map());
27858
28336
  const initialPaginationStableSignatureRef = React.useRef(
27859
28337
  void 0
@@ -27918,6 +28396,54 @@ function DocxEditorViewer({
27918
28396
  measuredPageContentHeightByIndex,
27919
28397
  setMeasuredPageContentHeightByIndex
27920
28398
  ] = React.useState([]);
28399
+ const pagePlaceholderRefForIndex = React.useCallback(
28400
+ (pageIndex) => {
28401
+ const normalizedPageIndex = Math.max(0, Math.round(pageIndex));
28402
+ const cached = pagePlaceholderRefCallbacksRef.current.get(normalizedPageIndex);
28403
+ if (cached) {
28404
+ return cached;
28405
+ }
28406
+ const nextRef = (element) => {
28407
+ if (element) {
28408
+ pageElementsRef.current.set(normalizedPageIndex, element);
28409
+ } else {
28410
+ pageElementsRef.current.delete(normalizedPageIndex);
28411
+ }
28412
+ registerDocxViewerPageSurface(editor, normalizedPageIndex, void 0);
28413
+ };
28414
+ pagePlaceholderRefCallbacksRef.current.set(normalizedPageIndex, nextRef);
28415
+ return nextRef;
28416
+ },
28417
+ [pageSurfaceRegistryOwner]
28418
+ );
28419
+ const pageSurfaceRefForIndex = React.useCallback(
28420
+ (pageIndex) => {
28421
+ const normalizedPageIndex = Math.max(0, Math.round(pageIndex));
28422
+ const cached = pageSurfaceRefCallbacksRef.current.get(normalizedPageIndex);
28423
+ if (cached) {
28424
+ return cached;
28425
+ }
28426
+ const nextRef = (element) => {
28427
+ if (element) {
28428
+ pageElementsRef.current.set(normalizedPageIndex, element);
28429
+ } else {
28430
+ pageElementsRef.current.delete(normalizedPageIndex);
28431
+ }
28432
+ registerDocxViewerPageSurface(editor, normalizedPageIndex, element);
28433
+ };
28434
+ pageSurfaceRefCallbacksRef.current.set(normalizedPageIndex, nextRef);
28435
+ return nextRef;
28436
+ },
28437
+ [pageSurfaceRegistryOwner]
28438
+ );
28439
+ React.useEffect(() => {
28440
+ pagePlaceholderRefCallbacksRef.current.clear();
28441
+ pageSurfaceRefCallbacksRef.current.clear();
28442
+ }, [pageSurfaceRegistryOwner]);
28443
+ const [
28444
+ measuredPageContentIdentityKeysByIndex,
28445
+ setMeasuredPageContentIdentityKeysByIndex
28446
+ ] = React.useState([]);
27921
28447
  const [, setRenderableImageSourceRevision] = React.useState(0);
27922
28448
  const [activeEditableParagraphSegment, setActiveEditableParagraphSegment] = React.useState(void 0);
27923
28449
  const wrappedParagraphTextareaRef = React.useRef(
@@ -27967,6 +28493,7 @@ function DocxEditorViewer({
27967
28493
  }, []);
27968
28494
  React.useEffect(() => {
27969
28495
  setMeasuredPageContentHeightByIndex([]);
28496
+ setMeasuredPageContentIdentityKeysByIndex([]);
27970
28497
  setTableMeasuredRowHeights({});
27971
28498
  setTableRowHeights({});
27972
28499
  setTableColumnWidths({});
@@ -28361,7 +28888,7 @@ function DocxEditorViewer({
28361
28888
  tableDraftLayoutEpoch,
28362
28889
  tableMeasuredRowHeights
28363
28890
  ]);
28364
- const pageNodeSegmentsByPage = React.useMemo(() => {
28891
+ const pageSegmentationPlan = React.useMemo(() => {
28365
28892
  const pageContentHeightPx = Math.max(
28366
28893
  120,
28367
28894
  documentLayout.pageHeightPx - documentLayout.marginsPx.top - documentLayout.marginsPx.bottom
@@ -28372,6 +28899,7 @@ function DocxEditorViewer({
28372
28899
  );
28373
28900
  const suppressSpacingBeforeAfterPageBreak = editor.model.metadata.compatibility?.suppressSpacingBeforeAfterPageBreak === true;
28374
28901
  const preferLastRenderedParagraphStartBreaks = !editor.canUndo && !editor.canRedo;
28902
+ const canUseMeasuredPageContentHeights = !editor.canUndo && !editor.canRedo && !disableMeasuredImportPagination && !floatingMovePreview && !dropCapMovePreview && (measuredPageContentHeightByIndex?.length ?? 0) > 0;
28375
28903
  const buildEstimatedPages = (measuredTableRowHeightsByNodeIndex, measuredPageContentHeightsOverride) => {
28376
28904
  const allowMeasuredPageContentHeights = !editor.canUndo && !editor.canRedo && !disableMeasuredImportPagination && !floatingMovePreview && !dropCapMovePreview;
28377
28905
  const baseMeasuredHeights = !allowMeasuredPageContentHeights || measuredPageContentHeightsOverride === null ? void 0 : measuredPageContentHeightsOverride ?? measuredPageContentHeightByIndex;
@@ -28417,14 +28945,13 @@ function DocxEditorViewer({
28417
28945
  minimumPageCount,
28418
28946
  Math.round(storedDocumentPageCount2)
28419
28947
  ) : void 0;
28420
- let estimatedPages = buildEstimatedPages(
28421
- tableMeasuredRowHeightsForPagination
28948
+ const pureEstimatedPages = buildEstimatedPages(
28949
+ tableMeasuredRowHeightsForPagination,
28950
+ null
28422
28951
  );
28952
+ let estimatedPages = buildEstimatedPages(tableMeasuredRowHeightsForPagination);
28953
+ let estimatedPagesUseMeasuredPageContentHeightsForRender = canUseMeasuredPageContentHeights;
28423
28954
  if (measuredPageContentHeightByIndex && measuredPageContentHeightByIndex.length > 0) {
28424
- const pureEstimatedPages = buildEstimatedPages(
28425
- tableMeasuredRowHeightsForPagination,
28426
- null
28427
- );
28428
28955
  const measuredPagesAreOnlySplitParagraphs = estimatedPages.length > 0 && estimatedPages.every(
28429
28956
  (pageSegments) => documentPageContainsOnlySplitParagraphSegments(pageSegments)
28430
28957
  );
@@ -28433,25 +28960,38 @@ function DocxEditorViewer({
28433
28960
  );
28434
28961
  if (measuredPagesAreOnlySplitParagraphs && purePagesAreOnlySplitParagraphs && pureEstimatedPages.length < estimatedPages.length) {
28435
28962
  estimatedPages = pureEstimatedPages;
28963
+ estimatedPagesUseMeasuredPageContentHeightsForRender = false;
28436
28964
  }
28437
28965
  }
28438
28966
  if (!editor.canUndo && !editor.canRedo && targetPageCount !== void 0 && tableMeasuredRowHeightsForPagination) {
28439
28967
  const candidatePages = [
28440
- estimatedPages,
28441
- buildEstimatedPages(void 0),
28442
- buildEstimatedPages(void 0, null)
28968
+ {
28969
+ pages: estimatedPages,
28970
+ useMeasuredPageContentHeightsForRender: estimatedPagesUseMeasuredPageContentHeightsForRender
28971
+ },
28972
+ {
28973
+ pages: buildEstimatedPages(void 0),
28974
+ useMeasuredPageContentHeightsForRender: canUseMeasuredPageContentHeights
28975
+ },
28976
+ {
28977
+ pages: buildEstimatedPages(void 0, null),
28978
+ useMeasuredPageContentHeightsForRender: false
28979
+ }
28443
28980
  ];
28444
- estimatedPages = candidatePages.reduce((bestCandidate, candidate) => {
28445
- const bestDifference = Math.abs(bestCandidate.length - targetPageCount);
28981
+ const bestCandidate = candidatePages.reduce((best, candidate) => {
28982
+ const bestDifference = Math.abs(best.pages.length - targetPageCount);
28446
28983
  const candidateDifference = Math.abs(
28447
- candidate.length - targetPageCount
28984
+ candidate.pages.length - targetPageCount
28448
28985
  );
28449
- return candidateDifference < bestDifference ? candidate : bestCandidate;
28986
+ return candidateDifference < bestDifference ? candidate : best;
28450
28987
  });
28988
+ estimatedPages = bestCandidate.pages;
28989
+ estimatedPagesUseMeasuredPageContentHeightsForRender = bestCandidate.useMeasuredPageContentHeightsForRender;
28451
28990
  } else if (!editor.canUndo && !editor.canRedo && targetPageCount !== void 0) {
28452
- const pureEstimatedPages = buildEstimatedPages(void 0, null);
28453
- if (Math.abs(pureEstimatedPages.length - targetPageCount) < Math.abs(estimatedPages.length - targetPageCount)) {
28454
- estimatedPages = pureEstimatedPages;
28991
+ const pureEstimatedPages2 = buildEstimatedPages(void 0, null);
28992
+ if (Math.abs(pureEstimatedPages2.length - targetPageCount) < Math.abs(estimatedPages.length - targetPageCount)) {
28993
+ estimatedPages = pureEstimatedPages2;
28994
+ estimatedPagesUseMeasuredPageContentHeightsForRender = false;
28455
28995
  }
28456
28996
  }
28457
28997
  const measuredPageHeightOverridesReduceContent = !editor.canUndo && !editor.canRedo && !floatingMovePreview && !dropCapMovePreview && estimatedPages.some((segments, pageIndex) => {
@@ -28476,7 +29016,10 @@ function DocxEditorViewer({
28476
29016
  )
28477
29017
  );
28478
29018
  if (!Number.isFinite(storedDocumentPageCount2) || storedDocumentPageCount2 <= 0) {
28479
- return estimatedPages;
29019
+ return {
29020
+ pages: estimatedPages,
29021
+ useMeasuredPageContentHeightsForRender: estimatedPagesUseMeasuredPageContentHeightsForRender
29022
+ };
28480
29023
  }
28481
29024
  const resolvedTargetPageCount = targetPageCount ?? minimumPageCount;
28482
29025
  const hasTableInternalPageBreaks = editor.model.nodes.some(
@@ -28492,10 +29035,16 @@ function DocxEditorViewer({
28492
29035
  renderedBreakHintPageCount
28493
29036
  }) && (!measuredPageHeightOverridesReduceContent || allowMeasuredReductionOverPaginationReconciliation);
28494
29037
  if (!allowStoredPageCountReconciliation) {
28495
- return estimatedPages;
29038
+ return {
29039
+ pages: estimatedPages,
29040
+ useMeasuredPageContentHeightsForRender: estimatedPagesUseMeasuredPageContentHeightsForRender
29041
+ };
28496
29042
  }
28497
29043
  if (estimatedPages.length === resolvedTargetPageCount) {
28498
- return estimatedPages;
29044
+ return {
29045
+ pages: estimatedPages,
29046
+ useMeasuredPageContentHeightsForRender: estimatedPagesUseMeasuredPageContentHeightsForRender
29047
+ };
28499
29048
  }
28500
29049
  const reconciliationScales = allowMeasuredReductionOverPaginationReconciliation ? [
28501
29050
  1.02,
@@ -28543,20 +29092,25 @@ function DocxEditorViewer({
28543
29092
  let reconciledPages = reconcileCandidatePages(
28544
29093
  estimatedPages,
28545
29094
  tableMeasuredRowHeightsForPagination,
28546
- measuredPageContentHeightByIndex
29095
+ estimatedPagesUseMeasuredPageContentHeightsForRender ? measuredPageContentHeightByIndex : null
28547
29096
  );
29097
+ let reconciledPagesUseMeasuredPageContentHeightsForRender = estimatedPagesUseMeasuredPageContentHeightsForRender;
28548
29098
  if (!editor.canUndo && !editor.canRedo) {
28549
- const pureEstimatedPages = buildEstimatedPages(void 0, null);
29099
+ const pureEstimatedPages2 = buildEstimatedPages(void 0, null);
28550
29100
  const pureReconciledPages = reconcileCandidatePages(
28551
- pureEstimatedPages,
29101
+ pureEstimatedPages2,
28552
29102
  void 0,
28553
29103
  null
28554
29104
  );
28555
29105
  if (Math.abs(pureReconciledPages.length - resolvedTargetPageCount) < Math.abs(reconciledPages.length - resolvedTargetPageCount)) {
28556
29106
  reconciledPages = pureReconciledPages;
29107
+ reconciledPagesUseMeasuredPageContentHeightsForRender = false;
28557
29108
  }
28558
29109
  }
28559
- return reconciledPages;
29110
+ return {
29111
+ pages: reconciledPages,
29112
+ useMeasuredPageContentHeightsForRender: reconciledPagesUseMeasuredPageContentHeightsForRender
29113
+ };
28560
29114
  }, [
28561
29115
  editor.canRedo,
28562
29116
  editor.canUndo,
@@ -28578,6 +29132,14 @@ function DocxEditorViewer({
28578
29132
  measuredPageContentHeightByIndex,
28579
29133
  tableMeasuredRowHeightsForPagination
28580
29134
  ]);
29135
+ const pageNodeSegmentsByPage = pageSegmentationPlan.pages;
29136
+ const useMeasuredPageContentHeightsForRender = pageSegmentationPlan.useMeasuredPageContentHeightsForRender;
29137
+ const pageNodeSegmentIdentityKeysByPage = React.useMemo(
29138
+ () => pageNodeSegmentsByPage.map(
29139
+ (pageSegments) => documentPageNodeSegmentsIdentityKey(pageSegments)
29140
+ ),
29141
+ [pageNodeSegmentsByPage]
29142
+ );
28581
29143
  const pageIndexByNodeIndex = React.useMemo(() => {
28582
29144
  const indexByNode = /* @__PURE__ */ new Map();
28583
29145
  pageNodeSegmentsByPage.forEach((segments, pageIndex) => {
@@ -29603,6 +30165,9 @@ function DocxEditorViewer({
29603
30165
  setMeasuredPageContentHeightByIndex(
29604
30166
  (current) => current.length === 0 ? current : []
29605
30167
  );
30168
+ setMeasuredPageContentIdentityKeysByIndex(
30169
+ (current) => current.length === 0 ? current : []
30170
+ );
29606
30171
  return;
29607
30172
  }
29608
30173
  if (!paginationMeasurementEnabled) {
@@ -29613,124 +30178,140 @@ function DocxEditorViewer({
29613
30178
  setMeasuredPageContentHeightByIndex(
29614
30179
  (current) => current.length === 0 ? current : []
29615
30180
  );
30181
+ setMeasuredPageContentIdentityKeysByIndex(
30182
+ (current) => current.length === 0 ? current : []
30183
+ );
29616
30184
  return;
29617
30185
  }
29618
30186
  if (Date.now() < paginationMeasurementSuspendUntilRef.current) {
29619
30187
  return;
29620
30188
  }
29621
30189
  const zoomScale = resolveEffectiveZoomScale(rootElement);
29622
- const nextMeasuredHeights = pageNodeSegmentsByPage.map((_, pageIndex) => {
29623
- const pageLayout = pageSectionInfoByIndex[pageIndex]?.layout ?? documentLayout;
29624
- const pageElement = pageElementsRef.current.get(pageIndex);
29625
- const fallbackHeightPx = Math.max(
29626
- 120,
29627
- pageLayout.pageHeightPx - pageLayout.marginsPx.top - pageLayout.marginsPx.bottom
29628
- );
29629
- if (!pageElement) {
29630
- return fallbackHeightPx;
29631
- }
29632
- const headerElement = pageHeaderElementsRef.current.get(pageIndex);
29633
- const bodyElement = pageBodyElementsRef.current.get(pageIndex);
29634
- const footerElement = pageFooterElementsRef.current.get(pageIndex);
29635
- const headerHeightPx = headerElement ? Math.max(
29636
- 0,
29637
- Math.round(headerElement.getBoundingClientRect().height / zoomScale)
29638
- ) : 0;
29639
- const docxFooterTopPx = resolveFooterNodesFloatingBoundaryTopPx(
29640
- pageHeaderAndFooterNodes[pageIndex]?.footerNodes ?? [],
29641
- pageLayout
29642
- );
29643
- let footerTopPx = Number.isFinite(docxFooterTopPx) ? Math.round(docxFooterTopPx) : void 0;
29644
- if (footerElement) {
29645
- const pageRect2 = pageElement.getBoundingClientRect();
29646
- const maxOverflowCapPx = Math.max(
29647
- 16,
29648
- Math.min(
29649
- Math.round(pageLayout.pageHeightPx * 0.12),
29650
- Math.round(
29651
- pageLayout.marginsPx.bottom + pageLayout.footerDistancePx + 24
29652
- )
29653
- )
30190
+ const nextMeasuredPageIdentityKeys = pageNodeSegmentIdentityKeysByPage;
30191
+ const nextMeasuredPageDiagnostics = pageNodeSegmentsByPage.map(
30192
+ (_, pageIndex) => {
30193
+ const pageLayout = pageSectionInfoByIndex[pageIndex]?.layout ?? documentLayout;
30194
+ const pageElement = pageElementsRef.current.get(pageIndex);
30195
+ const fallbackHeightPx = Math.max(
30196
+ 120,
30197
+ pageLayout.pageHeightPx - pageLayout.marginsPx.top - pageLayout.marginsPx.bottom
29654
30198
  );
29655
- const footerFlowBoundaryTopPx = Math.max(
30199
+ if (!pageElement) {
30200
+ return {
30201
+ heightPx: fallbackHeightPx,
30202
+ bodyOverrunsFooter: false
30203
+ };
30204
+ }
30205
+ const headerElement = pageHeaderElementsRef.current.get(pageIndex);
30206
+ const bodyElement = pageBodyElementsRef.current.get(pageIndex);
30207
+ const footerElement = pageFooterElementsRef.current.get(pageIndex);
30208
+ const headerHeightPx = headerElement ? Math.max(
29656
30209
  0,
29657
- pageLayout.pageHeightPx - Math.max(0, pageLayout.footerDistancePx)
30210
+ Math.round(headerElement.getBoundingClientRect().height / zoomScale)
30211
+ ) : 0;
30212
+ const docxFooterTopPx = resolveFooterNodesFloatingBoundaryTopPx(
30213
+ pageHeaderAndFooterNodes[pageIndex]?.footerNodes ?? [],
30214
+ pageLayout
29658
30215
  );
29659
- const minimumRelevantFooterTopPx = Number.isFinite(docxFooterTopPx) ? Math.max(
30216
+ let footerTopPx = Number.isFinite(docxFooterTopPx) ? Math.round(docxFooterTopPx) : void 0;
30217
+ if (footerElement) {
30218
+ const pageRect2 = pageElement.getBoundingClientRect();
30219
+ const maxOverflowCapPx = Math.max(
30220
+ 16,
30221
+ Math.min(
30222
+ Math.round(pageLayout.pageHeightPx * 0.12),
30223
+ Math.round(
30224
+ pageLayout.marginsPx.bottom + pageLayout.footerDistancePx + 24
30225
+ )
30226
+ )
30227
+ );
30228
+ const footerFlowBoundaryTopPx = Math.max(
30229
+ 0,
30230
+ pageLayout.pageHeightPx - Math.max(0, pageLayout.footerDistancePx)
30231
+ );
30232
+ const minimumRelevantFooterTopPx = Number.isFinite(docxFooterTopPx) ? Math.max(
30233
+ 0,
30234
+ Math.min(
30235
+ Math.max(0, footerFlowBoundaryTopPx - maxOverflowCapPx),
30236
+ Math.round(docxFooterTopPx - maxOverflowCapPx)
30237
+ )
30238
+ ) : Math.max(0, footerFlowBoundaryTopPx - maxOverflowCapPx);
30239
+ let visualTop = Number.POSITIVE_INFINITY;
30240
+ footerElement.querySelectorAll("*").forEach((element) => {
30241
+ if (!element.isConnected) {
30242
+ return;
30243
+ }
30244
+ const rect = element.getBoundingClientRect();
30245
+ if (rect.width <= 0 && rect.height <= 0) {
30246
+ return;
30247
+ }
30248
+ const relativeTopPx = (rect.top - pageRect2.top) / zoomScale;
30249
+ if (relativeTopPx < minimumRelevantFooterTopPx - 1) {
30250
+ return;
30251
+ }
30252
+ visualTop = Math.min(visualTop, rect.top);
30253
+ });
30254
+ if (Number.isFinite(visualTop)) {
30255
+ const measuredFooterTopPx = (visualTop - pageRect2.top) / zoomScale;
30256
+ footerTopPx = Number.isFinite(footerTopPx) ? Math.min(
30257
+ Math.round(footerTopPx),
30258
+ Math.round(measuredFooterTopPx)
30259
+ ) : Math.round(measuredFooterTopPx);
30260
+ }
30261
+ }
30262
+ const pageRect = pageElement.getBoundingClientRect();
30263
+ const bodyRect = bodyElement?.getBoundingClientRect();
30264
+ const bodyTopPx = bodyRect ? Math.max(0, Math.round((bodyRect.top - pageRect.top) / zoomScale)) : void 0;
30265
+ const bodyImageCount = bodyElement?.querySelectorAll("[data-docx-image-location]").length ?? 0;
30266
+ const bodyTextTrimmedLength = bodyElement?.textContent?.replace(/\s+/g, "").length ?? 0;
30267
+ const skipBodyBottomAdjustment = bodyImageCount > 0 && bodyTextTrimmedLength === 0;
30268
+ const visualBodyBottom = bodyElement && bodyRect ? resolveMeasuredBodyRenderedBottomPx(
30269
+ Array.from(bodyElement.querySelectorAll("*")).map(
30270
+ (element) => {
30271
+ const rect = element.getBoundingClientRect();
30272
+ return {
30273
+ bottomPx: rect.bottom,
30274
+ widthPx: rect.width,
30275
+ heightPx: rect.height,
30276
+ ignore: !element.isConnected || Boolean(element.closest("[data-docx-image-location]")) || Boolean(
30277
+ element.closest(
30278
+ `[${PAGE_CONTENT_MEASUREMENT_IGNORE_ATTRIBUTE}="true"]`
30279
+ )
30280
+ )
30281
+ };
30282
+ }
30283
+ )
30284
+ ) : void 0;
30285
+ const bodyRenderedBottomPx = bodyRect && Number.isFinite(visualBodyBottom) ? Math.max(
29660
30286
  0,
29661
- Math.min(
29662
- Math.max(0, footerFlowBoundaryTopPx - maxOverflowCapPx),
29663
- Math.round(docxFooterTopPx - maxOverflowCapPx)
30287
+ Math.round(
30288
+ (visualBodyBottom - pageRect.top) / zoomScale
29664
30289
  )
29665
- ) : Math.max(0, footerFlowBoundaryTopPx - maxOverflowCapPx);
29666
- let visualTop = Number.POSITIVE_INFINITY;
29667
- footerElement.querySelectorAll("*").forEach((element) => {
29668
- if (!element.isConnected) {
29669
- return;
29670
- }
29671
- const rect = element.getBoundingClientRect();
29672
- if (rect.width <= 0 && rect.height <= 0) {
29673
- return;
29674
- }
29675
- const relativeTopPx = (rect.top - pageRect2.top) / zoomScale;
29676
- if (relativeTopPx < minimumRelevantFooterTopPx - 1) {
29677
- return;
29678
- }
29679
- visualTop = Math.min(visualTop, rect.top);
30290
+ ) : void 0;
30291
+ return resolveMeasuredPageContentHeightDiagnostics({
30292
+ pageLayout,
30293
+ fallbackHeightPx,
30294
+ headerHeightPx,
30295
+ currentMeasuredHeightPx: measuredPageContentHeightByIndex?.[pageIndex],
30296
+ bodyTopPx,
30297
+ bodyRenderedBottomPx,
30298
+ footerTopPx,
30299
+ skipBodyBottomAdjustment
29680
30300
  });
29681
- if (Number.isFinite(visualTop)) {
29682
- const measuredFooterTopPx = (visualTop - pageRect2.top) / zoomScale;
29683
- footerTopPx = Number.isFinite(footerTopPx) ? Math.min(
29684
- Math.round(footerTopPx),
29685
- Math.round(measuredFooterTopPx)
29686
- ) : Math.round(measuredFooterTopPx);
29687
- }
29688
30301
  }
29689
- const pageRect = pageElement.getBoundingClientRect();
29690
- const bodyRect = bodyElement?.getBoundingClientRect();
29691
- const bodyTopPx = bodyRect ? Math.max(0, Math.round((bodyRect.top - pageRect.top) / zoomScale)) : void 0;
29692
- const bodyImageCount = bodyElement?.querySelectorAll("[data-docx-image-location]").length ?? 0;
29693
- const bodyTextTrimmedLength = bodyElement?.textContent?.replace(/\s+/g, "").length ?? 0;
29694
- const skipBodyBottomAdjustment = bodyImageCount > 0 && bodyTextTrimmedLength === 0;
29695
- const visualBodyBottom = bodyElement && bodyRect ? resolveMeasuredBodyRenderedBottomPx(
29696
- Array.from(bodyElement.querySelectorAll("*")).map(
29697
- (element) => {
29698
- const rect = element.getBoundingClientRect();
29699
- return {
29700
- bottomPx: rect.bottom,
29701
- widthPx: rect.width,
29702
- heightPx: rect.height,
29703
- ignore: !element.isConnected || Boolean(element.closest("[data-docx-image-location]")) || Boolean(
29704
- element.closest(
29705
- `[${PAGE_CONTENT_MEASUREMENT_IGNORE_ATTRIBUTE}="true"]`
29706
- )
29707
- )
29708
- };
29709
- }
29710
- )
29711
- ) : void 0;
29712
- const bodyRenderedBottomPx = bodyRect && Number.isFinite(visualBodyBottom) ? Math.max(
29713
- 0,
29714
- Math.round(
29715
- (visualBodyBottom - pageRect.top) / zoomScale
29716
- )
29717
- ) : void 0;
29718
- return resolveMeasuredPageContentHeightPx({
29719
- pageLayout,
29720
- fallbackHeightPx,
29721
- headerHeightPx,
29722
- currentMeasuredHeightPx: measuredPageContentHeightByIndex?.[pageIndex],
29723
- bodyTopPx,
29724
- bodyRenderedBottomPx,
29725
- footerTopPx,
29726
- skipBodyBottomAdjustment
29727
- });
29728
- });
30302
+ );
30303
+ const nextMeasuredHeights = nextMeasuredPageDiagnostics.map(
30304
+ (diagnostics) => diagnostics.heightPx
30305
+ );
29729
30306
  const frameId = window.requestAnimationFrame(() => {
29730
30307
  setMeasuredPageContentHeightByIndex((current) => {
29731
30308
  const stabilizedHeights = stabilizeMeasuredPageContentHeights(
29732
30309
  current,
29733
- nextMeasuredHeights
30310
+ nextMeasuredHeights,
30311
+ {
30312
+ currentPageIdentityKeys: measuredPageContentIdentityKeysByIndex,
30313
+ nextPageIdentityKeys: nextMeasuredPageIdentityKeys
30314
+ }
29734
30315
  );
29735
30316
  if (current.length === stabilizedHeights.length) {
29736
30317
  let equal = true;
@@ -29748,6 +30329,21 @@ function DocxEditorViewer({
29748
30329
  }
29749
30330
  return stabilizedHeights;
29750
30331
  });
30332
+ setMeasuredPageContentIdentityKeysByIndex((current) => {
30333
+ if (current.length === nextMeasuredPageIdentityKeys.length) {
30334
+ let equal = true;
30335
+ for (let pageIndex = 0; pageIndex < nextMeasuredPageIdentityKeys.length; pageIndex += 1) {
30336
+ if (current[pageIndex] !== nextMeasuredPageIdentityKeys[pageIndex]) {
30337
+ equal = false;
30338
+ break;
30339
+ }
30340
+ }
30341
+ if (equal) {
30342
+ return current;
30343
+ }
30344
+ }
30345
+ return nextMeasuredPageIdentityKeys;
30346
+ });
29751
30347
  });
29752
30348
  return () => {
29753
30349
  window.cancelAnimationFrame(frameId);
@@ -29756,10 +30352,12 @@ function DocxEditorViewer({
29756
30352
  disableMeasuredImportPagination,
29757
30353
  documentLayout,
29758
30354
  measuredPageContentHeightByIndex,
30355
+ measuredPageContentIdentityKeysByIndex,
29759
30356
  paginationMeasurementEnabled,
29760
30357
  paginationMeasurementEpoch,
29761
30358
  pageCount,
29762
30359
  pageNodeSegmentsByPage,
30360
+ pageNodeSegmentIdentityKeysByPage,
29763
30361
  pageSectionInfoByIndex,
29764
30362
  pageHeaderAndFooterNodes
29765
30363
  ]);
@@ -35592,7 +36190,10 @@ function DocxEditorViewer({
35592
36190
  height: run.image.heightPx ? `${run.image.heightPx}px` : void 0,
35593
36191
  verticalAlign: "middle",
35594
36192
  display: "inline-block",
35595
- filter: run.image.cssFilter,
36193
+ filter: appendCssFilters(
36194
+ run.image.cssFilter,
36195
+ documentContentFilter
36196
+ ),
35596
36197
  opacity: run.image.cssOpacity
35597
36198
  }
35598
36199
  },
@@ -35603,14 +36204,15 @@ function DocxEditorViewer({
35603
36204
  overlapStart - run.startOffset,
35604
36205
  overlapEnd - run.startOffset
35605
36206
  );
35606
- if (!slice) {
36207
+ const renderedSlice = sanitizeRenderedPretextFragmentText(slice);
36208
+ if (!renderedSlice) {
35607
36209
  return void 0;
35608
36210
  }
35609
36211
  const textStyle = run.link ? {
35610
- ...linkStyleToCss(run.style, editor.documentTheme),
36212
+ ...linkStyleToCss(run.style, documentContentTheme),
35611
36213
  whiteSpace: "pre"
35612
36214
  } : {
35613
- ...runStyleToCss(run.style, editor.documentTheme),
36215
+ ...runStyleToCss(run.style, documentContentTheme),
35614
36216
  whiteSpace: "pre"
35615
36217
  };
35616
36218
  if (activeSession) {
@@ -35618,7 +36220,7 @@ function DocxEditorViewer({
35618
36220
  "span",
35619
36221
  {
35620
36222
  style: textStyle,
35621
- children: slice
36223
+ children: renderedSlice
35622
36224
  },
35623
36225
  `${keyPrefix}-active-${lineIndex}-${run.key}-${overlapStart}`
35624
36226
  );
@@ -35645,14 +36247,14 @@ function DocxEditorViewer({
35645
36247
  scrollToBookmark(run.link.slice(1));
35646
36248
  },
35647
36249
  style: textStyle,
35648
- children: slice
36250
+ children: renderedSlice
35649
36251
  },
35650
36252
  `${keyPrefix}-fragment-${lineIndex}-${run.key}-${overlapStart}`
35651
36253
  ) : /* @__PURE__ */ jsx(
35652
36254
  "span",
35653
36255
  {
35654
36256
  style: textStyle,
35655
- children: slice
36257
+ children: renderedSlice
35656
36258
  },
35657
36259
  `${keyPrefix}-fragment-${lineIndex}-${run.key}-${overlapStart}`
35658
36260
  );
@@ -36344,7 +36946,7 @@ function DocxEditorViewer({
36344
36946
  return renderParagraphRuns(
36345
36947
  paragraph,
36346
36948
  keyPrefix,
36347
- editor.documentTheme,
36949
+ documentContentTheme,
36348
36950
  numberingLabel,
36349
36951
  scrollToBookmark,
36350
36952
  interactiveBodyFloatingPageOriginPx,
@@ -36412,7 +37014,10 @@ function DocxEditorViewer({
36412
37014
  height: run.image.heightPx ? `${run.image.heightPx}px` : void 0,
36413
37015
  verticalAlign: "middle",
36414
37016
  display: "inline-block",
36415
- filter: run.image.cssFilter,
37017
+ filter: appendCssFilters(
37018
+ run.image.cssFilter,
37019
+ documentContentFilter
37020
+ ),
36416
37021
  opacity: run.image.cssOpacity
36417
37022
  }
36418
37023
  },
@@ -36427,10 +37032,10 @@ function DocxEditorViewer({
36427
37032
  return void 0;
36428
37033
  }
36429
37034
  const textStyle = run.link ? {
36430
- ...linkStyleToCss(run.style, editor.documentTheme),
37035
+ ...linkStyleToCss(run.style, documentContentTheme),
36431
37036
  whiteSpace: "pre"
36432
37037
  } : {
36433
- ...runStyleToCss(run.style, editor.documentTheme),
37038
+ ...runStyleToCss(run.style, documentContentTheme),
36434
37039
  whiteSpace: "pre"
36435
37040
  };
36436
37041
  return run.link ? /* @__PURE__ */ jsx(
@@ -36567,7 +37172,10 @@ function DocxEditorViewer({
36567
37172
  heightPx
36568
37173
  );
36569
37174
  const imageVisualStyle = {
36570
- filter: manualImage.cssFilter,
37175
+ filter: appendCssFilters(
37176
+ manualImage.cssFilter,
37177
+ documentContentFilter
37178
+ ),
36571
37179
  opacity: manualImage.cssOpacity
36572
37180
  };
36573
37181
  const imageTransformStyle = resolveImageRenderTransformStyle(
@@ -36841,7 +37449,10 @@ function DocxEditorViewer({
36841
37449
  verticalAlign: "middle",
36842
37450
  display: "block",
36843
37451
  cursor: isReadOnly ? "default" : "move",
36844
- filter: manualImage.cssFilter,
37452
+ filter: appendCssFilters(
37453
+ manualImage.cssFilter,
37454
+ documentContentFilter
37455
+ ),
36845
37456
  opacity: manualImage.cssOpacity
36846
37457
  }
36847
37458
  }
@@ -37053,7 +37664,10 @@ function DocxEditorViewer({
37053
37664
  verticalAlign: "middle",
37054
37665
  display: "block",
37055
37666
  cursor: isReadOnly ? "default" : "move",
37056
- filter: manualImage.cssFilter,
37667
+ filter: appendCssFilters(
37668
+ manualImage.cssFilter,
37669
+ documentContentFilter
37670
+ ),
37057
37671
  opacity: manualImage.cssOpacity
37058
37672
  }
37059
37673
  }
@@ -37205,7 +37819,7 @@ function DocxEditorViewer({
37205
37819
  });
37206
37820
  }
37207
37821
  if (numberingLabel) {
37208
- const numberingTextStyle = numberingLabel.style ? runStyleToCss(numberingLabel.style, editor.documentTheme) : void 0;
37822
+ const numberingTextStyle = numberingLabel.style ? runStyleToCss(numberingLabel.style, documentContentTheme) : void 0;
37209
37823
  nodes.push(
37210
37824
  /* @__PURE__ */ jsx(
37211
37825
  "span",
@@ -37217,7 +37831,7 @@ function DocxEditorViewer({
37217
37831
  editor.model.metadata.numberingDefinitions,
37218
37832
  numberingLabel,
37219
37833
  numberingTextStyle,
37220
- editor.documentTheme
37834
+ documentContentTheme
37221
37835
  ),
37222
37836
  children: numberingLabel.imageSrc ? /* @__PURE__ */ jsxs(Fragment2, { children: [
37223
37837
  /* @__PURE__ */ jsx(
@@ -37534,7 +38148,7 @@ function DocxEditorViewer({
37534
38148
  {
37535
38149
  style: segment.style ? runStyleToCss(
37536
38150
  segment.style,
37537
- editor.documentTheme
38151
+ documentContentTheme
37538
38152
  ) : void 0,
37539
38153
  children: segment.text
37540
38154
  },
@@ -37548,7 +38162,10 @@ function DocxEditorViewer({
37548
38162
  ) : renderableImageSrc && !showsUnsupportedFallback ? (() => {
37549
38163
  const cropLayout = imageCropLayout(child, widthPx, heightPx);
37550
38164
  const imageVisualStyle = {
37551
- filter: child.cssFilter,
38165
+ filter: appendCssFilters(
38166
+ child.cssFilter,
38167
+ documentContentFilter
38168
+ ),
37552
38169
  opacity: child.cssOpacity
37553
38170
  };
37554
38171
  const imageTransformStyle = resolveImageRenderTransformStyle(
@@ -37814,10 +38431,10 @@ function DocxEditorViewer({
37814
38431
  const compactFieldLayout = compactTabStopFieldLayout || child.sourceKind === "legacy";
37815
38432
  const isTextLikeFormField = child.fieldType === "text" || child.fieldType === "date";
37816
38433
  const inputStyle = {
37817
- ...runStyleToCss(child.style, editor.documentTheme),
38434
+ ...runStyleToCss(child.style, documentContentTheme),
37818
38435
  fontFamily: cssFontFamily(child.style?.fontFamily) ?? "inherit",
37819
38436
  fontSize: child.style?.fontSizePt ? `${child.style.fontSizePt}pt` : "inherit",
37820
- color: themedRunColor(child.style?.color, editor.documentTheme) ?? "inherit",
38437
+ color: themedRunColor(child.style?.color, documentContentTheme) ?? "inherit",
37821
38438
  backgroundColor: isTextLikeFormField ? "rgba(148, 163, 184, 0.16)" : compactFieldLayout ? "transparent" : "#ffffff",
37822
38439
  border: isTextLikeFormField ? "1px solid rgba(148, 163, 184, 0.6)" : compactFieldLayout ? "none" : "1px solid #d4d4d8",
37823
38440
  borderRadius: isTextLikeFormField ? 4 : compactFieldLayout ? 0 : 6,
@@ -37899,7 +38516,7 @@ function DocxEditorViewer({
37899
38516
  cursor: isReadOnly ? "default" : "pointer",
37900
38517
  userSelect: "none",
37901
38518
  outline: "none",
37902
- ...runStyleToCss(child.style, editor.documentTheme)
38519
+ ...runStyleToCss(child.style, documentContentTheme)
37903
38520
  },
37904
38521
  children: checkboxSymbol
37905
38522
  },
@@ -38113,7 +38730,7 @@ function DocxEditorViewer({
38113
38730
  "span",
38114
38731
  {
38115
38732
  style: {
38116
- ...runStyleToCss(child.style, editor.documentTheme),
38733
+ ...runStyleToCss(child.style, documentContentTheme),
38117
38734
  verticalAlign: "super",
38118
38735
  fontSize: "0.75em"
38119
38736
  },
@@ -38158,7 +38775,7 @@ function DocxEditorViewer({
38158
38775
  const bookmarkName = linkHref.slice(1);
38159
38776
  scrollToBookmark(bookmarkName);
38160
38777
  },
38161
- style: linkStyleToCss(child.style, editor.documentTheme),
38778
+ style: linkStyleToCss(child.style, documentContentTheme),
38162
38779
  children: child.text
38163
38780
  },
38164
38781
  runKey
@@ -38173,7 +38790,7 @@ function DocxEditorViewer({
38173
38790
  );
38174
38791
  return;
38175
38792
  }
38176
- const runStyle = runStyleToCss(child.style, editor.documentTheme);
38793
+ const runStyle = runStyleToCss(child.style, documentContentTheme);
38177
38794
  const renderedText = attachTextToPreviousCheckbox(
38178
38795
  paragraph,
38179
38796
  childIndex,
@@ -38253,7 +38870,8 @@ function DocxEditorViewer({
38253
38870
  resizePreview,
38254
38871
  selectedImage,
38255
38872
  setSelectedSectionImageKey,
38256
- editor.documentTheme,
38873
+ documentContentFilter,
38874
+ documentContentTheme,
38257
38875
  editor.selectFormField,
38258
38876
  editor.setFormFieldValue,
38259
38877
  editor.toggleFormCheckbox,
@@ -38448,9 +39066,6 @@ function DocxEditorViewer({
38448
39066
  );
38449
39067
  const paragraphSegmentVisibleHeightPx = paragraphSegmentVisibleLineCount * paragraphSegmentLineHeightPx;
38450
39068
  const paragraphSegmentTranslateYPx = paragraphSegmentStartLine * paragraphSegmentLineHeightPx;
38451
- const paragraphSegmentClipBleed = resolveParagraphSegmentClipBleedPx(paragraphLineRange);
38452
- const paragraphSegmentClipBleedTopPx = paragraphSegmentClipBleed.topPx;
38453
- const paragraphSegmentClipBleedBottomPx = paragraphSegmentClipBleed.bottomPx;
38454
39069
  const paragraphSegmentIsActiveEditable = paragraphSegmentIdentityMatches(
38455
39070
  activeEditableParagraphSegment,
38456
39071
  nodeIndex,
@@ -38499,6 +39114,9 @@ function DocxEditorViewer({
38499
39114
  pretextParagraphSliceEndLine
38500
39115
  ) : void 0;
38501
39116
  const shouldRenderParagraphSegmentWithPretext = hasPartialLineRange && Boolean(pretextParagraphSource) && Boolean(pretextParagraphLayout) && pretextParagraphTotalLines > 0;
39117
+ const paragraphSegmentClipBleed = shouldRenderParagraphSegmentWithPretext ? resolveParagraphSegmentClipBleedPx(paragraphLineRange) : resolveFallbackParagraphSegmentClipBleedPx(node, paragraphLineRange);
39118
+ const paragraphSegmentClipBleedTopPx = paragraphSegmentClipBleed.topPx;
39119
+ const paragraphSegmentClipBleedBottomPx = paragraphSegmentClipBleed.bottomPx;
38502
39120
  const pretextSegmentNumberingMarkerBoxWidthPx = numberingLabel && paragraphSegmentStartLine === 0 ? resolveNumberingMarkerBoxWidthPx(
38503
39121
  node,
38504
39122
  editor.model.metadata.numberingDefinitions,
@@ -38523,8 +39141,8 @@ function DocxEditorViewer({
38523
39141
  node,
38524
39142
  editor.model.metadata.numberingDefinitions,
38525
39143
  numberingLabel,
38526
- numberingLabel.style ? runStyleToCss(numberingLabel.style, editor.documentTheme) : void 0,
38527
- editor.documentTheme
39144
+ numberingLabel.style ? runStyleToCss(numberingLabel.style, documentContentTheme) : void 0,
39145
+ documentContentTheme
38528
39146
  ),
38529
39147
  position: "absolute",
38530
39148
  left: -Math.round(
@@ -38548,7 +39166,8 @@ function DocxEditorViewer({
38548
39166
  verticalAlign: "text-bottom",
38549
39167
  width: numberingLabel.imageWidthPx ?? 12,
38550
39168
  height: numberingLabel.imageHeightPx ?? 12,
38551
- marginRight: 2
39169
+ marginRight: 2,
39170
+ filter: documentContentFilter
38552
39171
  }
38553
39172
  }
38554
39173
  ),
@@ -39696,7 +40315,7 @@ ${currentText.slice(end)}`;
39696
40315
  children: renderHeaderNode(
39697
40316
  cellContent,
39698
40317
  `active-cell-nested-table-${nodeIndex}-${rowIndex}-${cellIndex}-${contentIndex}`,
39699
- editor.documentTheme,
40318
+ documentContentTheme,
39700
40319
  editor.model.metadata.numberingDefinitions,
39701
40320
  headingStyles,
39702
40321
  spannedWidthPx > 0 ? spannedWidthPx : void 0,
@@ -40612,7 +41231,7 @@ ${currentText.slice(end)}`;
40612
41231
  return renderHeaderNode(
40613
41232
  cellContent,
40614
41233
  `body-cell-nested-table-${nodeIndex}-${rowIndex}-${cellIndex}-${contentIndex}`,
40615
- editor.documentTheme,
41234
+ documentContentTheme,
40616
41235
  editor.model.metadata.numberingDefinitions,
40617
41236
  headingStyles,
40618
41237
  spannedWidthPx > 0 ? spannedWidthPx : void 0,
@@ -41294,7 +41913,7 @@ ${currentText.slice(end)}`;
41294
41913
  style: {
41295
41914
  ...runStyleToCss(
41296
41915
  dropCapTextStyle,
41297
- editor.documentTheme
41916
+ documentContentTheme
41298
41917
  ),
41299
41918
  width: "100%",
41300
41919
  minHeight: dropCapHeightPx,
@@ -41311,7 +41930,7 @@ ${currentText.slice(end)}`;
41311
41930
  boxShadow: isSelectedDropCap ? "0 0 0 2px rgba(191, 219, 254, 0.65)" : void 0,
41312
41931
  color: themedRunColor(
41313
41932
  dropCapTextStyle.color,
41314
- editor.documentTheme
41933
+ documentContentTheme
41315
41934
  ) ?? void 0,
41316
41935
  fontFamily: cssFontFamily(dropCapTextStyle.fontFamily) ?? void 0
41317
41936
  }
@@ -41499,7 +42118,7 @@ ${currentText.slice(end)}`;
41499
42118
  style: {
41500
42119
  ...runStyleToCss(
41501
42120
  dropCapTextStyle,
41502
- editor.documentTheme
42121
+ documentContentTheme
41503
42122
  ),
41504
42123
  width: "100%",
41505
42124
  minHeight: dropCapHeightPx,
@@ -41516,7 +42135,7 @@ ${currentText.slice(end)}`;
41516
42135
  boxShadow: isSelectedDropCap ? "0 0 0 2px rgba(191, 219, 254, 0.65)" : void 0,
41517
42136
  color: themedRunColor(
41518
42137
  dropCapTextStyle.color,
41519
- editor.documentTheme
42138
+ documentContentTheme
41520
42139
  ) ?? void 0,
41521
42140
  fontFamily: cssFontFamily(
41522
42141
  dropCapTextStyle.fontFamily
@@ -41781,7 +42400,7 @@ ${currentText.slice(end)}`;
41781
42400
  renderParagraphRuns(
41782
42401
  paragraph,
41783
42402
  `${keyPrefix}-runs`,
41784
- editor.documentTheme,
42403
+ documentContentTheme,
41785
42404
  void 0,
41786
42405
  scrollToBookmark,
41787
42406
  void 0,
@@ -41799,7 +42418,7 @@ ${currentText.slice(end)}`;
41799
42418
  ));
41800
42419
  },
41801
42420
  [
41802
- editor.documentTheme,
42421
+ documentContentTheme,
41803
42422
  endnoteDisplayIndexById,
41804
42423
  footnoteDisplayIndexById,
41805
42424
  renderParagraphRuns,
@@ -41960,13 +42579,7 @@ ${currentText.slice(end)}`;
41960
42579
  "div",
41961
42580
  {
41962
42581
  "data-docx-page-placeholder": "true",
41963
- ref: (element) => {
41964
- if (element) {
41965
- pageElementsRef.current.set(pageIndex, element);
41966
- } else {
41967
- pageElementsRef.current.delete(pageIndex);
41968
- }
41969
- },
42582
+ ref: pagePlaceholderRefForIndex(pageIndex),
41970
42583
  style: {
41971
42584
  height: pageLayout.pageHeightPx,
41972
42585
  width: pageLayout.pageWidthPx
@@ -42058,18 +42671,21 @@ ${currentText.slice(end)}`;
42058
42671
  const isLastPage = pageIndex === pageCount - 1;
42059
42672
  const pageFootnotes = pageFootnotesByIndex[pageIndex] ?? [];
42060
42673
  const pageBottomFootnotes = isLastPage && remainingFootnotes.length > 0 ? [...pageFootnotes, ...remainingFootnotes] : pageFootnotes;
42061
- const pageBodyAvailableHeightPx = resolvePageContentHeightPxForPageSegments(
42062
- pageNodeSegments,
42674
+ const pageBodyAvailableHeightPx = resolveRenderPageContentHeightPxForPageSegments({
42675
+ pageSegments: pageNodeSegments,
42063
42676
  pageIndex,
42064
- Math.max(
42677
+ defaultPageContentHeightPx: Math.max(
42065
42678
  120,
42066
42679
  pageLayout.pageHeightPx - pageLayout.marginsPx.top - pageLayout.marginsPx.bottom
42067
42680
  ),
42068
- paginationSectionMetrics,
42069
- measuredPageContentHeightByIndex
42070
- );
42681
+ metricsBySection: paginationSectionMetrics,
42682
+ measuredPageContentHeightsPxByPageIndex: measuredPageContentHeightByIndex,
42683
+ measuredPageContentIdentityKeysByPageIndex: measuredPageContentIdentityKeysByIndex,
42684
+ pageIdentityKey: pageNodeSegmentIdentityKeysByPage[pageIndex],
42685
+ useMeasuredPageContentHeights: useMeasuredPageContentHeightsForRender
42686
+ });
42071
42687
  const headerFooterBodyDimmed = pageHeaderFooterEditActive;
42072
- const pageBackgroundColor = editor.model.metadata.documentBackgroundColor;
42688
+ const documentPageBackgroundColor = editor.model.metadata.documentBackgroundColor;
42073
42689
  const pageBorders = parseSectionPageBorders(
42074
42690
  pageInfo?.section.sectionPropertiesXml ?? editor.model.metadata.sectionPropertiesXml
42075
42691
  );
@@ -42092,7 +42708,7 @@ ${currentText.slice(end)}`;
42092
42708
  width: pageLayout.pageWidthPx,
42093
42709
  height: pageLayout.pageHeightPx,
42094
42710
  minHeight: pageLayout.pageHeightPx,
42095
- backgroundColor: pageBackgroundColor ?? pageSurfaceBaseStyle.backgroundColor,
42711
+ backgroundColor: pageBackgroundColor ?? documentPageBackgroundColor ?? pageSurfaceBaseStyle.backgroundColor,
42096
42712
  position: "relative",
42097
42713
  paddingTop: pageLayout.marginsPx.top,
42098
42714
  paddingRight: pageLayout.marginsPx.right,
@@ -42156,13 +42772,7 @@ ${currentText.slice(end)}`;
42156
42772
  "div",
42157
42773
  {
42158
42774
  "data-docx-page-surface": "true",
42159
- ref: (element) => {
42160
- if (element) {
42161
- pageElementsRef.current.set(pageIndex, element);
42162
- } else {
42163
- pageElementsRef.current.delete(pageIndex);
42164
- }
42165
- },
42775
+ ref: pageSurfaceRefForIndex(pageIndex),
42166
42776
  style: {
42167
42777
  ...pageSurfaceStyle,
42168
42778
  margin: 0
@@ -42180,7 +42790,8 @@ ${currentText.slice(end)}`;
42180
42790
  height: pageLayout.pageHeightPx,
42181
42791
  overflow: "clip",
42182
42792
  pointerEvents: "none",
42183
- zIndex: 0
42793
+ zIndex: 0,
42794
+ ...documentContentFilter ? { filter: documentContentFilter } : void 0
42184
42795
  },
42185
42796
  children: pageCoverBackgroundImages.map(({ key, image }) => {
42186
42797
  const renderableImageSrc = resolveRenderableImageSource(image);
@@ -42202,7 +42813,10 @@ ${currentText.slice(end)}`;
42202
42813
  height: "100%",
42203
42814
  display: "block",
42204
42815
  objectFit: "cover",
42205
- filter: image.cssFilter,
42816
+ filter: appendCssFilters(
42817
+ image.cssFilter,
42818
+ documentContentFilter
42819
+ ),
42206
42820
  opacity: image.cssOpacity,
42207
42821
  ...resolveImageRenderTransformStyle(image, {
42208
42822
  frameWidthPx: pageLayout.pageWidthPx,
@@ -42220,7 +42834,10 @@ ${currentText.slice(end)}`;
42220
42834
  "div",
42221
42835
  {
42222
42836
  "data-docx-page-border-overlay": "true",
42223
- style: pageBorderOverlayStyle
42837
+ style: {
42838
+ ...pageBorderOverlayStyle,
42839
+ ...documentContentFilter ? { filter: documentContentFilter } : void 0
42840
+ }
42224
42841
  }
42225
42842
  ) : null,
42226
42843
  pageSections.headerNodes.length > 0 ? /* @__PURE__ */ jsx(
@@ -42249,7 +42866,8 @@ ${currentText.slice(end)}`;
42249
42866
  transition: "opacity 120ms ease",
42250
42867
  outline: "none",
42251
42868
  boxShadow: "none",
42252
- zIndex: 1
42869
+ zIndex: 1,
42870
+ ...documentContentFilter ? { filter: documentContentFilter } : void 0
42253
42871
  },
42254
42872
  contentEditable: pageHeaderFooterEditActive && !isReadOnly,
42255
42873
  suppressContentEditableWarning: true,
@@ -42309,7 +42927,7 @@ ${currentText.slice(end)}`;
42309
42927
  (node, index) => renderHeaderNode(
42310
42928
  node,
42311
42929
  `header-${pageIndex}-${index}`,
42312
- editor.documentTheme,
42930
+ documentContentTheme,
42313
42931
  editor.model.metadata.numberingDefinitions,
42314
42932
  headingStyles,
42315
42933
  headerNeedsPageWideLayout ? pageLayout.pageWidthPx : pageContentWidthPx,
@@ -42357,7 +42975,8 @@ ${currentText.slice(end)}`;
42357
42975
  transition: "opacity 120ms ease",
42358
42976
  display: "flex",
42359
42977
  flexDirection: "column",
42360
- minHeight: pageBodyAvailableHeightPx
42978
+ minHeight: pageBodyAvailableHeightPx,
42979
+ ...documentContentFilter ? { filter: documentContentFilter } : void 0
42361
42980
  },
42362
42981
  children: [
42363
42982
  /* @__PURE__ */ jsx("div", { style: { minHeight: 0 }, children: (() => {
@@ -42786,7 +43405,7 @@ ${currentText.slice(end)}`;
42786
43405
  style: {
42787
43406
  marginTop: 8,
42788
43407
  paddingTop: 8,
42789
- borderTop: `1px solid ${editor.documentTheme === "dark" ? "#4b5563" : "#9ca3af"}`,
43408
+ borderTop: `1px solid ${documentContentTheme === "dark" ? "#4b5563" : "#9ca3af"}`,
42790
43409
  display: "grid",
42791
43410
  gap: 6,
42792
43411
  fontSize: 12
@@ -42819,7 +43438,7 @@ ${currentText.slice(end)}`;
42819
43438
  style: {
42820
43439
  marginTop: "auto",
42821
43440
  paddingTop: 8,
42822
- borderTop: `1px solid ${editor.documentTheme === "dark" ? "#4b5563" : "#9ca3af"}`,
43441
+ borderTop: `1px solid ${documentContentTheme === "dark" ? "#4b5563" : "#9ca3af"}`,
42823
43442
  display: "grid",
42824
43443
  gap: 6,
42825
43444
  fontSize: 12
@@ -42923,7 +43542,8 @@ ${currentText.slice(end)}`;
42923
43542
  transition: "opacity 120ms ease",
42924
43543
  outline: "none",
42925
43544
  boxShadow: "none",
42926
- zIndex: 1
43545
+ zIndex: 1,
43546
+ ...documentContentFilter ? { filter: documentContentFilter } : void 0
42927
43547
  },
42928
43548
  contentEditable: pageHeaderFooterEditActive && !isReadOnly,
42929
43549
  suppressContentEditableWarning: true,
@@ -42983,7 +43603,7 @@ ${currentText.slice(end)}`;
42983
43603
  (node, index) => renderHeaderNode(
42984
43604
  node,
42985
43605
  `footer-${pageIndex}-${index}`,
42986
- editor.documentTheme,
43606
+ documentContentTheme,
42987
43607
  editor.model.metadata.numberingDefinitions,
42988
43608
  headingStyles,
42989
43609
  footerNeedsPageWideLayout ? pageLayout.pageWidthPx : pageContentWidthPx,
@@ -45438,6 +46058,7 @@ export {
45438
46058
  resolveDocumentLayout,
45439
46059
  resolveDocumentPageSegmentStartNodeIndex,
45440
46060
  resolveDocumentSectionsFromMetadata2 as resolveDocumentSectionsFromMetadata,
46061
+ resolveDocxPageThumbnailResolution,
45441
46062
  resolvePaginationSectionMetricsIndexForNodeIndex2 as resolvePaginationSectionMetricsIndexForNodeIndex,
45442
46063
  resolveParagraphBeforeSpacingPx2 as resolveParagraphBeforeSpacingPx,
45443
46064
  resolveSectionIndexForNodeIndex2 as resolveSectionIndexForNodeIndex,
@@ -45469,6 +46090,7 @@ export {
45469
46090
  useDocxLineSpacing,
45470
46091
  useDocxModel,
45471
46092
  useDocxPageLayout,
46093
+ useDocxPageThumbnails,
45472
46094
  useDocxPagination,
45473
46095
  useDocxParagraphStyles,
45474
46096
  useDocxTrackChanges,