@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.cjs CHANGED
@@ -73,6 +73,7 @@ __export(index_exports, {
73
73
  resolveDocumentLayout: () => resolveDocumentLayout,
74
74
  resolveDocumentPageSegmentStartNodeIndex: () => resolveDocumentPageSegmentStartNodeIndex,
75
75
  resolveDocumentSectionsFromMetadata: () => resolveDocumentSectionsFromMetadata2,
76
+ resolveDocxPageThumbnailResolution: () => resolveDocxPageThumbnailResolution,
76
77
  resolvePaginationSectionMetricsIndexForNodeIndex: () => resolvePaginationSectionMetricsIndexForNodeIndex2,
77
78
  resolveParagraphBeforeSpacingPx: () => resolveParagraphBeforeSpacingPx2,
78
79
  resolveSectionIndexForNodeIndex: () => resolveSectionIndexForNodeIndex2,
@@ -104,6 +105,7 @@ __export(index_exports, {
104
105
  useDocxLineSpacing: () => useDocxLineSpacing,
105
106
  useDocxModel: () => useDocxModel,
106
107
  useDocxPageLayout: () => useDocxPageLayout,
108
+ useDocxPageThumbnails: () => useDocxPageThumbnails,
107
109
  useDocxPagination: () => useDocxPagination,
108
110
  useDocxParagraphStyles: () => useDocxParagraphStyles,
109
111
  useDocxTrackChanges: () => useDocxTrackChanges,
@@ -10306,6 +10308,9 @@ var LEADING_COVER_SPACER_EXTRA_HEIGHT_PX = 2;
10306
10308
  var PARAGRAPH_SEGMENT_TOP_BLEED_PX = 22;
10307
10309
  var PARAGRAPH_SEGMENT_DESCENDER_BLEED_PX = 6;
10308
10310
  var PARAGRAPH_SEGMENT_VISUAL_SAFETY_PX = 24;
10311
+ var PARAGRAPH_SEGMENT_FALLBACK_TOP_BLEED_MAX_PX = 4;
10312
+ var PARAGRAPH_SEGMENT_FALLBACK_BOTTOM_BLEED_MAX_PX = 0;
10313
+ var PARAGRAPH_SEGMENT_FALLBACK_VISUAL_SAFETY_PX = 4;
10309
10314
  var INITIAL_PAGINATION_PREMEASURE_PAGE_LIMIT = 8;
10310
10315
  var INITIAL_PAGINATION_PAGE_COUNT_OSCILLATION_DISTINCT_THRESHOLD = 2;
10311
10316
  var INITIAL_PAGINATION_PAGE_COUNT_OSCILLATION_CHANGE_THRESHOLD = 4;
@@ -10642,13 +10647,18 @@ var DOC_SURFACE_STYLE_BY_THEME = {
10642
10647
  boxShadow: "0 2px 10px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.05)"
10643
10648
  },
10644
10649
  dark: {
10645
- backgroundColor: "#111827",
10650
+ backgroundColor: "#0a0a0a",
10646
10651
  color: "#f3f4f6",
10647
10652
  colorScheme: "dark",
10648
10653
  border: "none",
10649
10654
  boxShadow: "0 2px 10px rgba(2, 6, 23, 0.55), 0 1px 2px rgba(2, 6, 23, 0.45)"
10650
10655
  }
10651
10656
  };
10657
+ var NIGHT_READER_INVERSION_FILTER = "invert(1) hue-rotate(180deg)";
10658
+ function appendCssFilters(...filters) {
10659
+ const resolvedFilters = filters.map((filter) => filter?.trim()).filter((filter) => Boolean(filter));
10660
+ return resolvedFilters.length > 0 ? resolvedFilters.join(" ") : void 0;
10661
+ }
10652
10662
  var TABLE_RESIZE_HANDLE_SIZE = 8;
10653
10663
  var TABLE_RESIZE_HANDLE_HIT_SIZE = 16;
10654
10664
  var TABLE_RESIZE_BORDER_SIZE = 1;
@@ -11579,7 +11589,7 @@ function resolveFooterPaginationReservePx(footerSections, layout) {
11579
11589
  floatingFooterBoundaryReservePx
11580
11590
  );
11581
11591
  }
11582
- function resolveMeasuredPageContentHeightPx(params) {
11592
+ function resolveMeasuredPageContentHeightDiagnostics(params) {
11583
11593
  const {
11584
11594
  pageLayout,
11585
11595
  fallbackHeightPx,
@@ -11619,34 +11629,41 @@ function resolveMeasuredPageContentHeightPx(params) {
11619
11629
  ) : 0;
11620
11630
  const correctedAllowedBodyBottomPx = Math.max(
11621
11631
  0,
11622
- guardedAllowedBodyBottomPx - renderedBodyOverrunPx - measuredFooterClearanceBufferPx
11632
+ guardedAllowedBodyBottomPx - measuredFooterClearanceBufferPx
11623
11633
  );
11624
- const iterativeMeasuredHeightPx = renderedBodyOverrunPx > 0 && Number.isFinite(effectiveCurrentMeasuredHeightPx) && effectiveCurrentMeasuredHeightPx > 0 ? Math.max(
11634
+ const iterativeMeasuredHeightPx = renderedBodyOverrunPx > 0 && !Number.isFinite(bodyTopPx) && Number.isFinite(effectiveCurrentMeasuredHeightPx) && effectiveCurrentMeasuredHeightPx > 0 ? Math.max(
11625
11635
  120,
11626
11636
  Math.round(
11627
11637
  effectiveCurrentMeasuredHeightPx - renderedBodyOverrunPx - measuredFooterClearanceBufferPx
11628
11638
  )
11629
11639
  ) : void 0;
11640
+ const bodyOverrunsFooter = renderedBodyOverrunPx > 0;
11630
11641
  if (Number.isFinite(bodyTopPx) && correctedAllowedBodyBottomPx > bodyTopPx) {
11631
11642
  const measuredHeaderClearanceBufferPx2 = headerHeightPx > 0 ? MEASURED_PAGE_HEADER_CLEARANCE_BUFFER_PX : 0;
11632
11643
  const correctedHeightPx = Math.max(
11633
11644
  120,
11634
11645
  Math.round(correctedAllowedBodyBottomPx - bodyTopPx)
11635
11646
  );
11636
- return Number.isFinite(iterativeMeasuredHeightPx) ? Math.min(
11637
- Math.max(120, correctedHeightPx - measuredHeaderClearanceBufferPx2),
11638
- Math.max(
11639
- 120,
11640
- iterativeMeasuredHeightPx - measuredHeaderClearanceBufferPx2
11641
- )
11642
- ) : Math.max(120, correctedHeightPx - measuredHeaderClearanceBufferPx2);
11647
+ return {
11648
+ heightPx: Number.isFinite(iterativeMeasuredHeightPx) ? Math.min(
11649
+ Math.max(120, correctedHeightPx - measuredHeaderClearanceBufferPx2),
11650
+ Math.max(
11651
+ 120,
11652
+ iterativeMeasuredHeightPx - measuredHeaderClearanceBufferPx2
11653
+ )
11654
+ ) : Math.max(120, correctedHeightPx - measuredHeaderClearanceBufferPx2),
11655
+ bodyOverrunsFooter
11656
+ };
11643
11657
  }
11644
11658
  const measuredHeaderClearanceBufferPx = headerHeightPx > 0 ? MEASURED_PAGE_HEADER_CLEARANCE_BUFFER_PX : 0;
11645
11659
  const correctedFallbackHeightPx = Math.max(
11646
11660
  120,
11647
11661
  fallbackHeightPx - headerHeightPx - measuredHeaderClearanceBufferPx - footerOverlapPx - renderedBodyOverrunPx - measuredFooterClearanceBufferPx
11648
11662
  );
11649
- return Number.isFinite(iterativeMeasuredHeightPx) ? Math.min(correctedFallbackHeightPx, iterativeMeasuredHeightPx) : correctedFallbackHeightPx;
11663
+ return {
11664
+ heightPx: Number.isFinite(iterativeMeasuredHeightPx) ? Math.min(correctedFallbackHeightPx, iterativeMeasuredHeightPx) : correctedFallbackHeightPx,
11665
+ bodyOverrunsFooter
11666
+ };
11650
11667
  }
11651
11668
  function resolveMeasuredBodyRenderedBottomPx(descendants) {
11652
11669
  let visualBottomPx;
@@ -11664,13 +11681,27 @@ function resolveMeasuredBodyRenderedBottomPx(descendants) {
11664
11681
  });
11665
11682
  return visualBottomPx;
11666
11683
  }
11667
- function stabilizeMeasuredPageContentHeights(current, next) {
11684
+ function stabilizeMeasuredPageContentHeights(current, next, options) {
11668
11685
  return next.map((heightPx, pageIndex) => {
11669
11686
  const roundedNextHeightPx = Math.round(heightPx);
11670
11687
  const currentHeightPx = current[pageIndex];
11671
- return Number.isFinite(currentHeightPx) ? Math.min(Math.round(currentHeightPx), roundedNextHeightPx) : roundedNextHeightPx;
11688
+ const currentPageIdentityKey = options?.currentPageIdentityKeys?.[pageIndex];
11689
+ const nextPageIdentityKey = options?.nextPageIdentityKeys?.[pageIndex];
11690
+ const canPreserveConservativeHeight = currentPageIdentityKey === void 0 || nextPageIdentityKey === void 0 || currentPageIdentityKey === nextPageIdentityKey;
11691
+ return Number.isFinite(currentHeightPx) ? canPreserveConservativeHeight ? Math.min(Math.round(currentHeightPx), roundedNextHeightPx) : roundedNextHeightPx : roundedNextHeightPx;
11672
11692
  });
11673
11693
  }
11694
+ function documentPageNodeSegmentIdentityKey(segment) {
11695
+ const tableRowRangeKey = segment.tableRowRange ? `${segment.tableRowRange.startRowIndex}-${segment.tableRowRange.endRowIndex}` : "none";
11696
+ const tableRowSliceKey = segment.tableRowSlice ? `${segment.tableRowSlice.rowIndex}-${Math.round(
11697
+ segment.tableRowSlice.startOffsetPx
11698
+ )}-${Math.round(segment.tableRowSlice.sliceHeightPx)}` : "none";
11699
+ const paragraphLineRangeKey = segment.paragraphLineRange ? `${segment.paragraphLineRange.startLineIndex}-${segment.paragraphLineRange.endLineIndex}-${segment.paragraphLineRange.totalLineCount}` : "none";
11700
+ return `${segment.nodeIndex}|${tableRowRangeKey}|${tableRowSliceKey}|${paragraphLineRangeKey}`;
11701
+ }
11702
+ function documentPageNodeSegmentsIdentityKey(pageSegments) {
11703
+ return pageSegments.map(documentPageNodeSegmentIdentityKey).join("::");
11704
+ }
11674
11705
  function buildPaginationSectionMetrics(sections, fallbackLayout) {
11675
11706
  const fallbackWidthPx = resolveSectionPaginationContentWidthPx(fallbackLayout);
11676
11707
  const fallbackHeightPx = Math.max(
@@ -11753,10 +11784,11 @@ function scaleMeasuredPageContentHeights(measuredPageContentHeightsPxByPageIndex
11753
11784
  (heightPx) => Math.max(120, Math.round(heightPx * heightScale))
11754
11785
  );
11755
11786
  }
11756
- function resolvePageContentHeightPxForPageSegments(pageSegments, pageIndex, defaultPageContentHeightPx, metricsBySection, measuredPageContentHeightsPxByPageIndex) {
11787
+ function resolvePageContentHeightPxForPageSegments(pageSegments, pageIndex, defaultPageContentHeightPx, metricsBySection, measuredPageContentHeightsPxByPageIndex, measuredPageContentIdentityKeysByPageIndex, pageIdentityKey) {
11757
11788
  const pageContainsOnlySplitParagraphSegments = documentPageContainsOnlySplitParagraphSegments(pageSegments);
11758
11789
  const measuredHeightPx = measuredPageContentHeightsPxByPageIndex?.[pageIndex];
11759
- if (Number.isFinite(measuredHeightPx) && !pageContainsOnlySplitParagraphSegments) {
11790
+ const measuredHeightMatchesCurrentPage = pageIdentityKey === void 0 || measuredPageContentIdentityKeysByPageIndex?.[pageIndex] === void 0 || measuredPageContentIdentityKeysByPageIndex?.[pageIndex] === pageIdentityKey;
11791
+ if (Number.isFinite(measuredHeightPx) && measuredHeightMatchesCurrentPage && !pageContainsOnlySplitParagraphSegments) {
11760
11792
  return Math.max(120, Math.round(measuredHeightPx));
11761
11793
  }
11762
11794
  const firstNodeIndex = pageSegments[0]?.nodeIndex ?? 0;
@@ -11772,6 +11804,17 @@ function resolvePageContentHeightPxForPageSegments(pageSegments, pageIndex, defa
11772
11804
  )
11773
11805
  );
11774
11806
  }
11807
+ function resolveRenderPageContentHeightPxForPageSegments(params) {
11808
+ return resolvePageContentHeightPxForPageSegments(
11809
+ params.pageSegments,
11810
+ params.pageIndex,
11811
+ params.defaultPageContentHeightPx,
11812
+ params.metricsBySection,
11813
+ params.useMeasuredPageContentHeights === false ? void 0 : params.measuredPageContentHeightsPxByPageIndex,
11814
+ params.useMeasuredPageContentHeights === false ? void 0 : params.measuredPageContentIdentityKeysByPageIndex,
11815
+ params.pageIdentityKey
11816
+ );
11817
+ }
11775
11818
  function documentPageContainsOnlySplitParagraphSegments(pageSegments) {
11776
11819
  return pageSegments.length > 0 && pageSegments.every(
11777
11820
  (segment) => !segment.tableRowRange && paragraphSegmentHasPartialLineRange(segment.paragraphLineRange)
@@ -12651,10 +12694,11 @@ function sectionNodesNeedPageWideLayout(nodes, pageWidthPx, contentWidthPx) {
12651
12694
  return false;
12652
12695
  }
12653
12696
  const horizontalRelativeTo = image.floating.horizontalRelativeTo?.toLowerCase();
12654
- if (image.floating.behindDocument || horizontalRelativeTo === "page") {
12697
+ const usesPageWidthAnchorOrigin = horizontalRelativeTo === "page" || horizontalRelativeTo === "margin";
12698
+ if (image.floating.behindDocument && usesPageWidthAnchorOrigin) {
12655
12699
  return true;
12656
12700
  }
12657
- if (shouldRenderAbsoluteFloatingImage(image)) {
12701
+ if (usesPageWidthAnchorOrigin && (shouldRenderAbsoluteFloatingImage(image) || shouldRenderWrappedFloatingImage(image))) {
12658
12702
  return true;
12659
12703
  }
12660
12704
  if (Number.isFinite(image.widthPx) && Number.isFinite(image.floating.xPx) && image.widthPx >= safeContentWidthPx - 12 && image.floating.xPx <= 12) {
@@ -13241,6 +13285,9 @@ function buildSyntheticPretextLayoutSource(text, style) {
13241
13285
  function pretextWordBreakModeForText(text) {
13242
13286
  return KEEP_ALL_SCRIPT_RE.test(text) ? "keep-all" : "normal";
13243
13287
  }
13288
+ function sanitizeRenderedPretextFragmentText(text) {
13289
+ return text.replace(/\r\n?|\n/g, "");
13290
+ }
13244
13291
  function buildParagraphPretextLayoutItems(paragraph, source) {
13245
13292
  const paragraphBaseFontPx = paragraphBaseFontSizePx(paragraph);
13246
13293
  const wordBreak = pretextWordBreakModeForText(source.text);
@@ -14353,6 +14400,20 @@ function paragraphBaseFontSizePx(paragraph) {
14353
14400
  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;
14354
14401
  return Math.max(10, Math.round(fontSizePt * 96 / 72));
14355
14402
  }
14403
+ function paragraphMaxFontSizePx(paragraph) {
14404
+ const paragraphBaseFontPx = paragraphBaseFontSizePx(paragraph);
14405
+ let maxFontSizePx = paragraphBaseFontPx;
14406
+ paragraph.children.forEach((child) => {
14407
+ if (child.type !== "text" && child.type !== "form-field") {
14408
+ return;
14409
+ }
14410
+ maxFontSizePx = Math.max(
14411
+ maxFontSizePx,
14412
+ resolveMeasureFontSizePx(child.style, paragraphBaseFontPx)
14413
+ );
14414
+ });
14415
+ return Math.max(1, Math.round(maxFontSizePx));
14416
+ }
14356
14417
  function normalizeFontFamilyToken(fontFamily) {
14357
14418
  if (!fontFamily) {
14358
14419
  return void 0;
@@ -15550,6 +15611,34 @@ function resolveParagraphSegmentClipBleedPx(paragraphLineRange) {
15550
15611
  bottomPx: Math.max(0, PARAGRAPH_SEGMENT_DESCENDER_BLEED_PX)
15551
15612
  };
15552
15613
  }
15614
+ function resolveFallbackParagraphSegmentClipBleedPx(paragraph, paragraphLineRange) {
15615
+ if (!paragraphSegmentHasPartialLineRange(paragraphLineRange)) {
15616
+ return {
15617
+ topPx: 0,
15618
+ bottomPx: 0
15619
+ };
15620
+ }
15621
+ const lineHeightPx = Math.max(1, paragraphLineRange?.lineHeightPx ?? 0);
15622
+ const maxFontSizePx = paragraphMaxFontSizePx(paragraph);
15623
+ const glyphOvershootPx = Math.max(
15624
+ 0,
15625
+ Math.ceil((maxFontSizePx - lineHeightPx) / 2)
15626
+ );
15627
+ const ascenderSafetyPx = Math.max(
15628
+ glyphOvershootPx,
15629
+ Math.ceil(lineHeightPx * 0.22)
15630
+ );
15631
+ return {
15632
+ topPx: paragraphLineRange && paragraphLineRange.startLineIndex > 0 ? Math.min(
15633
+ PARAGRAPH_SEGMENT_FALLBACK_TOP_BLEED_MAX_PX,
15634
+ ascenderSafetyPx
15635
+ ) : 0,
15636
+ bottomPx: paragraphLineRange && paragraphLineRange.endLineIndex < paragraphLineRange.totalLineCount ? Math.min(
15637
+ PARAGRAPH_SEGMENT_FALLBACK_BOTTOM_BLEED_MAX_PX,
15638
+ glyphOvershootPx
15639
+ ) : 0
15640
+ };
15641
+ }
15553
15642
  function resolveParagraphSegmentNonFlowReservePx(paragraphLineRange) {
15554
15643
  const bleed = resolveParagraphSegmentClipBleedPx(paragraphLineRange);
15555
15644
  if (bleed.topPx <= 0 && bleed.bottomPx <= 0) {
@@ -15561,6 +15650,20 @@ function resolveParagraphSegmentNonFlowReservePx(paragraphLineRange) {
15561
15650
  );
15562
15651
  return Math.max(0, bleed.topPx) + Math.max(0, bleed.bottomPx) + Math.max(0, PARAGRAPH_SEGMENT_VISUAL_SAFETY_PX, lineHeightSafetyPx);
15563
15652
  }
15653
+ function resolveFallbackParagraphSegmentNonFlowReservePx(paragraph, paragraphLineRange) {
15654
+ const bleed = resolveFallbackParagraphSegmentClipBleedPx(
15655
+ paragraph,
15656
+ paragraphLineRange
15657
+ );
15658
+ if (bleed.topPx <= 0 && bleed.bottomPx <= 0) {
15659
+ return 0;
15660
+ }
15661
+ const lineHeightSafetyPx = Math.max(
15662
+ 0,
15663
+ Math.ceil((paragraphLineRange?.lineHeightPx ?? 0) * 0.15)
15664
+ );
15665
+ return Math.max(0, bleed.topPx) + Math.max(0, bleed.bottomPx) + Math.max(1, PARAGRAPH_SEGMENT_FALLBACK_VISUAL_SAFETY_PX, lineHeightSafetyPx);
15666
+ }
15564
15667
  function paragraphSegmentIdentityMatches(segment, nodeIndex, paragraphLineRange) {
15565
15668
  if (!segment || !paragraphLineRange) {
15566
15669
  return false;
@@ -15900,13 +16003,17 @@ function buildDocumentPageNodeSegments(model, pageContentHeightPx, pageContentWi
15900
16003
  node,
15901
16004
  nodeMetrics.docGridLinePitchPx
15902
16005
  );
16006
+ const paragraphPretextSourceForSegmentRendering = buildParagraphPretextLayoutSource(node, {
16007
+ allowExplicitLineBreakText: true
16008
+ });
16009
+ const paragraphSupportsPretextSegmentRendering = Boolean(
16010
+ paragraphPretextSourceForSegmentRendering
16011
+ );
15903
16012
  const paragraphPretextLineCount = (() => {
15904
16013
  if (!paragraphContainsExplicitLineBreakText(node)) {
15905
16014
  return void 0;
15906
16015
  }
15907
- const pretextSource = buildParagraphPretextLayoutSource(node, {
15908
- allowExplicitLineBreakText: true
15909
- });
16016
+ const pretextSource = paragraphPretextSourceForSegmentRendering;
15910
16017
  if (!pretextSource) {
15911
16018
  return void 0;
15912
16019
  }
@@ -15924,11 +16031,7 @@ function buildDocumentPageNodeSegments(model, pageContentHeightPx, pageContentWi
15924
16031
  );
15925
16032
  return pretextLayout?.lineCount;
15926
16033
  })();
15927
- const supportsImageParagraphLineSplit = paragraphHasImage2(node) && Boolean(
15928
- buildParagraphPretextLayoutSource(node, {
15929
- allowExplicitLineBreakText: true
15930
- })
15931
- );
16034
+ const supportsImageParagraphLineSplit = paragraphHasImage2(node) && paragraphSupportsPretextSegmentRendering;
15932
16035
  const paragraphLineCount = paragraphLineCountWithinWidth(
15933
16036
  node,
15934
16037
  nodeMetrics.pageContentWidthPx,
@@ -15943,6 +16046,18 @@ function buildDocumentPageNodeSegments(model, pageContentHeightPx, pageContentWi
15943
16046
  allowImageParagraphSplit: supportsImageParagraphLineSplit
15944
16047
  }) && (!widowControlEnabled || resolvedParagraphLineCount > 3);
15945
16048
  if (canSplitParagraphAcrossPages && allowParagraphLineSplitting) {
16049
+ const resolveSegmentReservePx = (startLineIndex, endLineIndex) => {
16050
+ const paragraphSegmentRange = {
16051
+ startLineIndex,
16052
+ endLineIndex,
16053
+ totalLineCount: resolvedParagraphLineCount,
16054
+ lineHeightPx: paragraphLineHeightPx
16055
+ };
16056
+ return paragraphSupportsPretextSegmentRendering ? resolveParagraphSegmentNonFlowReservePx(paragraphSegmentRange) : resolveFallbackParagraphSegmentNonFlowReservePx(
16057
+ node,
16058
+ paragraphSegmentRange
16059
+ );
16060
+ };
15946
16061
  let lineCursor = 0;
15947
16062
  let isFirstSegment = true;
15948
16063
  while (lineCursor < resolvedParagraphLineCount) {
@@ -15954,12 +16069,10 @@ function buildDocumentPageNodeSegments(model, pageContentHeightPx, pageContentWi
15954
16069
  0,
15955
16070
  currentPageContentHeightPx - pageConsumedHeightPx
15956
16071
  );
15957
- const allRemainingSegmentReservePx = resolveParagraphSegmentNonFlowReservePx({
15958
- startLineIndex: lineCursor,
15959
- endLineIndex: resolvedParagraphLineCount,
15960
- totalLineCount: resolvedParagraphLineCount,
15961
- lineHeightPx: paragraphLineHeightPx
15962
- });
16072
+ const allRemainingSegmentReservePx = resolveSegmentReservePx(
16073
+ lineCursor,
16074
+ resolvedParagraphLineCount
16075
+ );
15963
16076
  const allRemainingHeightPx = topSpacingPx + linesRemaining * paragraphLineHeightPx + bottomSpacingPx;
15964
16077
  if (allRemainingHeightPx + allRemainingSegmentReservePx <= remainingHeightPx2) {
15965
16078
  currentPageSegments.push({
@@ -15980,15 +16093,10 @@ function buildDocumentPageNodeSegments(model, pageContentHeightPx, pageContentWi
15980
16093
  0,
15981
16094
  linesRemaining - minLinesPerSegment
15982
16095
  );
15983
- const continuingSegmentReservePx = resolveParagraphSegmentNonFlowReservePx({
15984
- startLineIndex: lineCursor,
15985
- endLineIndex: Math.min(
15986
- resolvedParagraphLineCount,
15987
- lineCursor + maxLinesThisPage
15988
- ),
15989
- totalLineCount: resolvedParagraphLineCount,
15990
- lineHeightPx: paragraphLineHeightPx
15991
- });
16096
+ const continuingSegmentReservePx = resolveSegmentReservePx(
16097
+ lineCursor,
16098
+ Math.min(resolvedParagraphLineCount, lineCursor + maxLinesThisPage)
16099
+ );
15992
16100
  const availableForLinesPx = Math.max(
15993
16101
  0,
15994
16102
  remainingHeightPx2 - topSpacingPx - continuingSegmentReservePx
@@ -16027,12 +16135,10 @@ function buildDocumentPageNodeSegments(model, pageContentHeightPx, pageContentWi
16027
16135
  lineCursor + linesThatFit
16028
16136
  );
16029
16137
  while (linesThatFit > minLinesPerSegment) {
16030
- const segmentReservePx = resolveParagraphSegmentNonFlowReservePx({
16031
- startLineIndex: lineCursor,
16032
- endLineIndex: segmentEndLineIndex,
16033
- totalLineCount: resolvedParagraphLineCount,
16034
- lineHeightPx: paragraphLineHeightPx
16035
- });
16138
+ const segmentReservePx = resolveSegmentReservePx(
16139
+ lineCursor,
16140
+ segmentEndLineIndex
16141
+ );
16036
16142
  if (topSpacingPx + (segmentEndLineIndex - lineCursor) * paragraphLineHeightPx + segmentReservePx <= remainingHeightPx2) {
16037
16143
  break;
16038
16144
  }
@@ -16533,17 +16639,18 @@ function wrappedFloatingImageStyle(image, options) {
16533
16639
  });
16534
16640
  const horizontalRelativeTo = floating.horizontalRelativeTo?.toLowerCase();
16535
16641
  const explicitHorizontalInsetPx = hasExplicitHorizontalOffset && !hasExplicitHorizontalAlign && (horizontalRelativeTo === "margin" || horizontalRelativeTo === "page" || horizontalRelativeTo === "column") ? side === "left" ? Math.max(0, leftOffsetPx) : Math.max(0, rightOffsetPx) : 0;
16642
+ const columnAnchoredExplicitInset = explicitHorizontalInsetPx > 0 && horizontalRelativeTo === "column";
16536
16643
  return {
16537
16644
  display: "block",
16538
16645
  ...intrinsicBlockWidthStyle,
16539
16646
  float: side,
16540
16647
  marginTop: topOffsetPx,
16541
16648
  marginBottom: distB,
16542
- marginLeft: side === "left" ? explicitHorizontalInsetPx > 0 ? 0 : hasExplicitHorizontalOffset ? leftOffsetPx : distL + leftOffsetPx : distL,
16543
- marginRight: side === "right" ? explicitHorizontalInsetPx > 0 ? 0 : hasExplicitHorizontalOffset ? rightOffsetPx : distR + rightOffsetPx : distR,
16544
- paddingLeft: side === "left" && explicitHorizontalInsetPx > 0 ? explicitHorizontalInsetPx : void 0,
16545
- paddingRight: side === "right" && explicitHorizontalInsetPx > 0 ? explicitHorizontalInsetPx : void 0,
16546
- boxSizing: explicitHorizontalInsetPx > 0 ? "content-box" : void 0
16649
+ marginLeft: side === "left" ? explicitHorizontalInsetPx > 0 ? columnAnchoredExplicitInset ? distL + explicitHorizontalInsetPx : 0 : hasExplicitHorizontalOffset ? leftOffsetPx : distL + leftOffsetPx : distL,
16650
+ marginRight: side === "right" ? explicitHorizontalInsetPx > 0 ? columnAnchoredExplicitInset ? distR + explicitHorizontalInsetPx : 0 : hasExplicitHorizontalOffset ? rightOffsetPx : distR + rightOffsetPx : distR,
16651
+ paddingLeft: side === "left" && explicitHorizontalInsetPx > 0 && !columnAnchoredExplicitInset ? explicitHorizontalInsetPx : void 0,
16652
+ paddingRight: side === "right" && explicitHorizontalInsetPx > 0 && !columnAnchoredExplicitInset ? explicitHorizontalInsetPx : void 0,
16653
+ boxSizing: explicitHorizontalInsetPx > 0 && !columnAnchoredExplicitInset ? "content-box" : void 0
16547
16654
  };
16548
16655
  }
16549
16656
  function wrappedFloatingImageDualExclusionLayout(image, options) {
@@ -19282,7 +19389,7 @@ function renderParagraphRuns(paragraph, keyPrefix, documentTheme = "light", numb
19282
19389
  (() => {
19283
19390
  const cropLayout = imageCropLayout(child, widthPx, heightPx);
19284
19391
  const imageVisualStyle = {
19285
- filter: child.cssFilter,
19392
+ filter: appendCssFilters(child.cssFilter, options?.imageFilterSuffix),
19286
19393
  opacity: child.cssOpacity
19287
19394
  };
19288
19395
  const imageTransformStyle = resolveImageRenderTransformStyle(child, {
@@ -26827,6 +26934,370 @@ function useDocxEditor(options = {}) {
26827
26934
  commitSectionParagraphText
26828
26935
  };
26829
26936
  }
26937
+ var docxViewerPageSurfaceRegistryByEditor = /* @__PURE__ */ new WeakMap();
26938
+ function docxViewerPageSurfaceRegistryOwner(editor) {
26939
+ return editor.syncPaginationInfo;
26940
+ }
26941
+ function ensureDocxViewerPageSurfaceRegistry(editor) {
26942
+ const owner = docxViewerPageSurfaceRegistryOwner(editor);
26943
+ let registry = docxViewerPageSurfaceRegistryByEditor.get(owner);
26944
+ if (!registry) {
26945
+ registry = {
26946
+ pageElements: /* @__PURE__ */ new Map(),
26947
+ listeners: /* @__PURE__ */ new Set()
26948
+ };
26949
+ docxViewerPageSurfaceRegistryByEditor.set(owner, registry);
26950
+ }
26951
+ return registry;
26952
+ }
26953
+ function subscribeDocxViewerPageSurfaces(editor, listener) {
26954
+ const registry = ensureDocxViewerPageSurfaceRegistry(editor);
26955
+ registry.listeners.add(listener);
26956
+ return () => {
26957
+ registry.listeners.delete(listener);
26958
+ };
26959
+ }
26960
+ function notifyDocxViewerPageSurfaceSubscribers(registry) {
26961
+ registry.listeners.forEach((listener) => {
26962
+ listener();
26963
+ });
26964
+ }
26965
+ function registerDocxViewerPageSurface(editor, pageIndex, element) {
26966
+ const registry = ensureDocxViewerPageSurfaceRegistry(editor);
26967
+ const normalizedPageIndex = Math.max(0, Math.round(pageIndex));
26968
+ const currentElement = registry.pageElements.get(normalizedPageIndex);
26969
+ if (element) {
26970
+ if (currentElement === element) {
26971
+ return;
26972
+ }
26973
+ registry.pageElements.set(normalizedPageIndex, element);
26974
+ notifyDocxViewerPageSurfaceSubscribers(registry);
26975
+ return;
26976
+ }
26977
+ if (!currentElement) {
26978
+ return;
26979
+ }
26980
+ registry.pageElements.delete(normalizedPageIndex);
26981
+ notifyDocxViewerPageSurfaceSubscribers(registry);
26982
+ }
26983
+ function resolveDocxViewerPageSurfaceSize(element, fallbackWidthPx, fallbackHeightPx) {
26984
+ if (element) {
26985
+ const rect = element.getBoundingClientRect();
26986
+ const rectWidthPx = Number.isFinite(rect.width) ? rect.width : 0;
26987
+ const rectHeightPx = Number.isFinite(rect.height) ? rect.height : 0;
26988
+ const offsetWidthPx = Number.isFinite(element.offsetWidth) ? element.offsetWidth : 0;
26989
+ const offsetHeightPx = Number.isFinite(element.offsetHeight) ? element.offsetHeight : 0;
26990
+ const clientWidthPx = Number.isFinite(element.clientWidth) ? element.clientWidth : 0;
26991
+ const clientHeightPx = Number.isFinite(element.clientHeight) ? element.clientHeight : 0;
26992
+ const resolvedWidthPx = Math.max(
26993
+ 0,
26994
+ rectWidthPx,
26995
+ offsetWidthPx,
26996
+ clientWidthPx
26997
+ );
26998
+ const resolvedHeightPx = Math.max(
26999
+ 0,
27000
+ rectHeightPx,
27001
+ offsetHeightPx,
27002
+ clientHeightPx
27003
+ );
27004
+ if (resolvedWidthPx > 0 && resolvedHeightPx > 0) {
27005
+ return {
27006
+ widthPx: Math.round(resolvedWidthPx),
27007
+ heightPx: Math.round(resolvedHeightPx)
27008
+ };
27009
+ }
27010
+ }
27011
+ return {
27012
+ widthPx: Math.max(1, Math.round(fallbackWidthPx)),
27013
+ heightPx: Math.max(1, Math.round(fallbackHeightPx))
27014
+ };
27015
+ }
27016
+ async function rasterizeDocxViewerPageSurfaceToCanvas(params) {
27017
+ if (typeof window === "undefined" || typeof XMLSerializer === "undefined") {
27018
+ throw new Error("DOCX thumbnails require a browser environment.");
27019
+ }
27020
+ const {
27021
+ pageElement,
27022
+ sourceWidthPx,
27023
+ sourceHeightPx,
27024
+ canvas,
27025
+ widthPx,
27026
+ heightPx,
27027
+ pixelWidthPx,
27028
+ pixelHeightPx
27029
+ } = params;
27030
+ const safeSourceWidthPx = Math.max(1, Math.round(sourceWidthPx));
27031
+ const safeSourceHeightPx = Math.max(1, Math.round(sourceHeightPx));
27032
+ const scaleX = widthPx / safeSourceWidthPx;
27033
+ const scaleY = heightPx / safeSourceHeightPx;
27034
+ const serializedPage = new XMLSerializer().serializeToString(
27035
+ pageElement.cloneNode(true)
27036
+ );
27037
+ const svgMarkup = `
27038
+ <svg xmlns="http://www.w3.org/2000/svg" width="${widthPx}" height="${heightPx}" viewBox="0 0 ${widthPx} ${heightPx}">
27039
+ <foreignObject x="0" y="0" width="100%" height="100%">
27040
+ <div xmlns="http://www.w3.org/1999/xhtml" style="width:${widthPx}px;height:${heightPx}px;overflow:hidden;">
27041
+ <div style="width:${safeSourceWidthPx}px;height:${safeSourceHeightPx}px;transform-origin:top left;transform:scale(${scaleX}, ${scaleY});">
27042
+ ${serializedPage}
27043
+ </div>
27044
+ </div>
27045
+ </foreignObject>
27046
+ </svg>
27047
+ `;
27048
+ const blob = new Blob([svgMarkup], {
27049
+ type: "image/svg+xml;charset=utf-8"
27050
+ });
27051
+ const objectUrl = URL.createObjectURL(blob);
27052
+ try {
27053
+ const image = await new Promise((resolve, reject) => {
27054
+ const nextImage = new Image();
27055
+ nextImage.decoding = "async";
27056
+ nextImage.onload = () => resolve(nextImage);
27057
+ nextImage.onerror = () => {
27058
+ reject(new Error("Failed to rasterize DOCX page thumbnail."));
27059
+ };
27060
+ nextImage.src = objectUrl;
27061
+ });
27062
+ canvas.width = Math.max(1, Math.round(pixelWidthPx));
27063
+ canvas.height = Math.max(1, Math.round(pixelHeightPx));
27064
+ canvas.style.width = `${Math.max(1, Math.round(widthPx))}px`;
27065
+ canvas.style.height = `${Math.max(1, Math.round(heightPx))}px`;
27066
+ const context = canvas.getContext("2d");
27067
+ if (!context) {
27068
+ throw new Error("2D canvas context is unavailable for DOCX thumbnails.");
27069
+ }
27070
+ context.setTransform(1, 0, 0, 1, 0, 0);
27071
+ context.clearRect(0, 0, canvas.width, canvas.height);
27072
+ context.imageSmoothingEnabled = true;
27073
+ context.imageSmoothingQuality = "high";
27074
+ context.drawImage(image, 0, 0, canvas.width, canvas.height);
27075
+ } finally {
27076
+ URL.revokeObjectURL(objectUrl);
27077
+ }
27078
+ }
27079
+ function resolveDocxPageThumbnailResolution(options) {
27080
+ const safeSourceWidthPx = Math.max(1, Math.round(options.sourceWidthPx));
27081
+ const safeSourceHeightPx = Math.max(1, Math.round(options.sourceHeightPx));
27082
+ const widthBoundPx = Number.isFinite(options.maxWidthPx) ? Math.max(1, Math.round(options.maxWidthPx)) : 180;
27083
+ const heightBoundPx = Number.isFinite(options.maxHeightPx) ? Math.max(1, Math.round(options.maxHeightPx)) : Number.POSITIVE_INFINITY;
27084
+ const scale = Math.min(
27085
+ 1,
27086
+ widthBoundPx / safeSourceWidthPx,
27087
+ heightBoundPx / safeSourceHeightPx
27088
+ );
27089
+ const pixelRatio = Number.isFinite(options.pixelRatio) ? Math.max(1, Number(options.pixelRatio)) : 1;
27090
+ const widthPx = Math.max(1, Math.round(safeSourceWidthPx * scale));
27091
+ const heightPx = Math.max(1, Math.round(safeSourceHeightPx * scale));
27092
+ return {
27093
+ widthPx,
27094
+ heightPx,
27095
+ pixelWidthPx: Math.max(1, Math.round(widthPx * pixelRatio)),
27096
+ pixelHeightPx: Math.max(1, Math.round(heightPx * pixelRatio)),
27097
+ scale
27098
+ };
27099
+ }
27100
+ function useDocxPageThumbnails(editor, options = {}) {
27101
+ const pageSurfaceRegistryOwner = docxViewerPageSurfaceRegistryOwner(editor);
27102
+ const pageSurfaceRegistryEditor = React.useMemo(
27103
+ () => ({ syncPaginationInfo: editor.syncPaginationInfo }),
27104
+ [pageSurfaceRegistryOwner]
27105
+ );
27106
+ const [pageSurfaceEpoch, setPageSurfaceEpoch] = React.useState(0);
27107
+ const [pageThumbnailStates, setPageThumbnailStates] = React.useState(() => /* @__PURE__ */ new Map());
27108
+ const attachedCanvasByPageRef = React.useRef(
27109
+ /* @__PURE__ */ new Map()
27110
+ );
27111
+ const canvasRefCallbacksRef = React.useRef(/* @__PURE__ */ new Map());
27112
+ const renderToCanvasCallbacksRef = React.useRef(/* @__PURE__ */ new Map());
27113
+ const fallbackLayout = React.useMemo(
27114
+ () => resolveDocumentLayout(editor.model),
27115
+ [editor.model]
27116
+ );
27117
+ const pageSurfaceRegistry = React.useMemo(
27118
+ () => ensureDocxViewerPageSurfaceRegistry(pageSurfaceRegistryEditor),
27119
+ [pageSurfaceRegistryEditor]
27120
+ );
27121
+ React.useEffect(
27122
+ () => subscribeDocxViewerPageSurfaces(
27123
+ pageSurfaceRegistryEditor,
27124
+ () => {
27125
+ setPageSurfaceEpoch((current) => current + 1);
27126
+ }
27127
+ ),
27128
+ [pageSurfaceRegistryEditor]
27129
+ );
27130
+ const mountedPageElements = React.useMemo(
27131
+ () => new Map(pageSurfaceRegistry.pageElements),
27132
+ [pageSurfaceEpoch, pageSurfaceRegistry.pageElements]
27133
+ );
27134
+ const updatePageThumbnailState = React.useCallback(
27135
+ (pageIndex, status, error) => {
27136
+ setPageThumbnailStates((current) => {
27137
+ const next = new Map(current);
27138
+ const previous = next.get(pageIndex);
27139
+ if (previous?.status === status && previous?.error?.message === error?.message) {
27140
+ return current;
27141
+ }
27142
+ next.set(pageIndex, { status, error });
27143
+ return next;
27144
+ });
27145
+ },
27146
+ []
27147
+ );
27148
+ const renderPageThumbnailToCanvas = React.useCallback(
27149
+ async (pageIndex, canvas) => {
27150
+ if (options.disabled) {
27151
+ return;
27152
+ }
27153
+ const targetCanvas = canvas ?? attachedCanvasByPageRef.current.get(pageIndex);
27154
+ if (!targetCanvas) {
27155
+ return;
27156
+ }
27157
+ const pageElement = mountedPageElements.get(pageIndex);
27158
+ if (!pageElement || !pageElement.isConnected) {
27159
+ updatePageThumbnailState(pageIndex, "unavailable");
27160
+ return;
27161
+ }
27162
+ const sourceSize = resolveDocxViewerPageSurfaceSize(
27163
+ pageElement,
27164
+ fallbackLayout.pageWidthPx,
27165
+ fallbackLayout.pageHeightPx
27166
+ );
27167
+ const resolution = resolveDocxPageThumbnailResolution({
27168
+ sourceWidthPx: sourceSize.widthPx,
27169
+ sourceHeightPx: sourceSize.heightPx,
27170
+ maxWidthPx: options.maxWidthPx,
27171
+ maxHeightPx: options.maxHeightPx,
27172
+ pixelRatio: options.pixelRatio
27173
+ });
27174
+ updatePageThumbnailState(pageIndex, "rendering");
27175
+ try {
27176
+ await rasterizeDocxViewerPageSurfaceToCanvas({
27177
+ pageElement,
27178
+ sourceWidthPx: sourceSize.widthPx,
27179
+ sourceHeightPx: sourceSize.heightPx,
27180
+ canvas: targetCanvas,
27181
+ widthPx: resolution.widthPx,
27182
+ heightPx: resolution.heightPx,
27183
+ pixelWidthPx: resolution.pixelWidthPx,
27184
+ pixelHeightPx: resolution.pixelHeightPx
27185
+ });
27186
+ updatePageThumbnailState(pageIndex, "ready");
27187
+ } catch (error) {
27188
+ updatePageThumbnailState(
27189
+ pageIndex,
27190
+ "error",
27191
+ error instanceof Error ? error : new Error("Failed to render DOCX page thumbnail.")
27192
+ );
27193
+ }
27194
+ },
27195
+ [
27196
+ fallbackLayout.pageHeightPx,
27197
+ fallbackLayout.pageWidthPx,
27198
+ mountedPageElements,
27199
+ options.disabled,
27200
+ options.maxHeightPx,
27201
+ options.maxWidthPx,
27202
+ options.pixelRatio,
27203
+ updatePageThumbnailState
27204
+ ]
27205
+ );
27206
+ const rerenderAttachedThumbnails = React.useCallback(async () => {
27207
+ const tasks = [...attachedCanvasByPageRef.current.keys()].map(
27208
+ (pageIndex) => renderPageThumbnailToCanvas(pageIndex)
27209
+ );
27210
+ await Promise.all(tasks);
27211
+ }, [renderPageThumbnailToCanvas]);
27212
+ const renderPageThumbnailToCanvasRef = React.useRef(renderPageThumbnailToCanvas);
27213
+ React.useEffect(() => {
27214
+ renderPageThumbnailToCanvasRef.current = renderPageThumbnailToCanvas;
27215
+ }, [renderPageThumbnailToCanvas]);
27216
+ React.useEffect(() => {
27217
+ canvasRefCallbacksRef.current.clear();
27218
+ renderToCanvasCallbacksRef.current.clear();
27219
+ }, [pageSurfaceRegistryOwner]);
27220
+ React.useEffect(() => {
27221
+ void rerenderAttachedThumbnails();
27222
+ }, [
27223
+ editor.documentLoadNonce,
27224
+ editor.documentTheme,
27225
+ editor.model,
27226
+ mountedPageElements,
27227
+ options.disabled,
27228
+ options.maxHeightPx,
27229
+ options.maxWidthPx,
27230
+ options.pixelRatio,
27231
+ rerenderAttachedThumbnails
27232
+ ]);
27233
+ const thumbnails = React.useMemo(() => {
27234
+ const totalPages = Math.max(1, editor.totalPages);
27235
+ return Array.from({ length: totalPages }, (_, pageIndex) => {
27236
+ const pageElement = mountedPageElements.get(pageIndex);
27237
+ const sourceSize = resolveDocxViewerPageSurfaceSize(
27238
+ pageElement,
27239
+ fallbackLayout.pageWidthPx,
27240
+ fallbackLayout.pageHeightPx
27241
+ );
27242
+ const resolution = resolveDocxPageThumbnailResolution({
27243
+ sourceWidthPx: sourceSize.widthPx,
27244
+ sourceHeightPx: sourceSize.heightPx,
27245
+ maxWidthPx: options.maxWidthPx,
27246
+ maxHeightPx: options.maxHeightPx,
27247
+ pixelRatio: options.pixelRatio
27248
+ });
27249
+ const state = pageThumbnailStates.get(pageIndex);
27250
+ return {
27251
+ pageIndex,
27252
+ pageNumber: pageIndex + 1,
27253
+ sourceWidthPx: sourceSize.widthPx,
27254
+ sourceHeightPx: sourceSize.heightPx,
27255
+ isMounted: Boolean(pageElement && pageElement.isConnected),
27256
+ status: state?.status ?? (pageElement ? "idle" : "unavailable"),
27257
+ error: state?.error,
27258
+ canvasRef: canvasRefCallbacksRef.current.get(pageIndex) ?? (() => {
27259
+ const nextCanvasRef = (canvas) => {
27260
+ if (canvas) {
27261
+ attachedCanvasByPageRef.current.set(pageIndex, canvas);
27262
+ void renderPageThumbnailToCanvasRef.current(pageIndex, canvas);
27263
+ return;
27264
+ }
27265
+ attachedCanvasByPageRef.current.delete(pageIndex);
27266
+ };
27267
+ canvasRefCallbacksRef.current.set(pageIndex, nextCanvasRef);
27268
+ return nextCanvasRef;
27269
+ })(),
27270
+ renderToCanvas: renderToCanvasCallbacksRef.current.get(pageIndex) ?? (() => {
27271
+ const nextRenderToCanvas = async (canvas) => {
27272
+ await renderPageThumbnailToCanvasRef.current(pageIndex, canvas);
27273
+ };
27274
+ renderToCanvasCallbacksRef.current.set(
27275
+ pageIndex,
27276
+ nextRenderToCanvas
27277
+ );
27278
+ return nextRenderToCanvas;
27279
+ })(),
27280
+ ...resolution
27281
+ };
27282
+ });
27283
+ }, [
27284
+ editor.totalPages,
27285
+ fallbackLayout.pageHeightPx,
27286
+ fallbackLayout.pageWidthPx,
27287
+ mountedPageElements,
27288
+ options.maxHeightPx,
27289
+ options.maxWidthPx,
27290
+ options.pixelRatio,
27291
+ pageThumbnailStates
27292
+ ]);
27293
+ return React.useMemo(
27294
+ () => ({
27295
+ thumbnails,
27296
+ rerenderAttachedThumbnails
27297
+ }),
27298
+ [rerenderAttachedThumbnails, thumbnails]
27299
+ );
27300
+ }
26830
27301
  function useDocxDocumentTheme(editor) {
26831
27302
  const setDocumentTheme = React.useCallback(
26832
27303
  (theme) => {
@@ -27888,6 +28359,7 @@ function DocxEditorViewer({
27888
28359
  editor,
27889
28360
  className,
27890
28361
  style,
28362
+ pageBackgroundColor,
27891
28363
  pageGapBackgroundColor,
27892
28364
  deferInitialPaginationPaint = true,
27893
28365
  loadingState,
@@ -27903,10 +28375,14 @@ function DocxEditorViewer({
27903
28375
  onFormFieldDoubleClick,
27904
28376
  mode = "edit"
27905
28377
  }) {
28378
+ const pageSurfaceRegistryOwner = docxViewerPageSurfaceRegistryOwner(editor);
27906
28379
  const trackedChangesEnabled = showTrackedChanges ?? editor.showTrackedChanges;
27907
28380
  const hasTrackedChanges = editor.trackedChanges.length > 0;
27908
28381
  const showTrackedChangeGutter = trackedChangesEnabled;
27909
28382
  const isReadOnly = mode === "read-only" || trackedChangesEnabled;
28383
+ const isNightReaderMode = isReadOnly && editor.documentTheme === "dark";
28384
+ const documentContentTheme = isNightReaderMode ? "light" : editor.documentTheme;
28385
+ const documentContentFilter = isNightReaderMode ? NIGHT_READER_INVERSION_FILTER : void 0;
27910
28386
  const canReplaceDocumentByDrop = mode !== "read-only";
27911
28387
  const formFieldLocationKey = React.useCallback(
27912
28388
  (location) => {
@@ -27922,9 +28398,11 @@ function DocxEditorViewer({
27922
28398
  () => ({
27923
28399
  showTrackedChanges: trackedChangesEnabled,
27924
28400
  numberingDefinitions: editor.model.metadata.numberingDefinitions,
27925
- tocLinkColorByLevel
28401
+ tocLinkColorByLevel,
28402
+ imageFilterSuffix: documentContentFilter
27926
28403
  }),
27927
28404
  [
28405
+ documentContentFilter,
27928
28406
  editor.model.metadata.numberingDefinitions,
27929
28407
  tocLinkColorByLevel,
27930
28408
  trackedChangesEnabled
@@ -27962,6 +28440,8 @@ function DocxEditorViewer({
27962
28440
  /* @__PURE__ */ new Map()
27963
28441
  );
27964
28442
  const pageElementsRef = React.useRef(/* @__PURE__ */ new Map());
28443
+ const pagePlaceholderRefCallbacksRef = React.useRef(/* @__PURE__ */ new Map());
28444
+ const pageSurfaceRefCallbacksRef = React.useRef(/* @__PURE__ */ new Map());
27965
28445
  const trackedChangeCardElementsRef = React.useRef(/* @__PURE__ */ new Map());
27966
28446
  const initialPaginationStableSignatureRef = React.useRef(
27967
28447
  void 0
@@ -28026,6 +28506,54 @@ function DocxEditorViewer({
28026
28506
  measuredPageContentHeightByIndex,
28027
28507
  setMeasuredPageContentHeightByIndex
28028
28508
  ] = React.useState([]);
28509
+ const pagePlaceholderRefForIndex = React.useCallback(
28510
+ (pageIndex) => {
28511
+ const normalizedPageIndex = Math.max(0, Math.round(pageIndex));
28512
+ const cached = pagePlaceholderRefCallbacksRef.current.get(normalizedPageIndex);
28513
+ if (cached) {
28514
+ return cached;
28515
+ }
28516
+ const nextRef = (element) => {
28517
+ if (element) {
28518
+ pageElementsRef.current.set(normalizedPageIndex, element);
28519
+ } else {
28520
+ pageElementsRef.current.delete(normalizedPageIndex);
28521
+ }
28522
+ registerDocxViewerPageSurface(editor, normalizedPageIndex, void 0);
28523
+ };
28524
+ pagePlaceholderRefCallbacksRef.current.set(normalizedPageIndex, nextRef);
28525
+ return nextRef;
28526
+ },
28527
+ [pageSurfaceRegistryOwner]
28528
+ );
28529
+ const pageSurfaceRefForIndex = React.useCallback(
28530
+ (pageIndex) => {
28531
+ const normalizedPageIndex = Math.max(0, Math.round(pageIndex));
28532
+ const cached = pageSurfaceRefCallbacksRef.current.get(normalizedPageIndex);
28533
+ if (cached) {
28534
+ return cached;
28535
+ }
28536
+ const nextRef = (element) => {
28537
+ if (element) {
28538
+ pageElementsRef.current.set(normalizedPageIndex, element);
28539
+ } else {
28540
+ pageElementsRef.current.delete(normalizedPageIndex);
28541
+ }
28542
+ registerDocxViewerPageSurface(editor, normalizedPageIndex, element);
28543
+ };
28544
+ pageSurfaceRefCallbacksRef.current.set(normalizedPageIndex, nextRef);
28545
+ return nextRef;
28546
+ },
28547
+ [pageSurfaceRegistryOwner]
28548
+ );
28549
+ React.useEffect(() => {
28550
+ pagePlaceholderRefCallbacksRef.current.clear();
28551
+ pageSurfaceRefCallbacksRef.current.clear();
28552
+ }, [pageSurfaceRegistryOwner]);
28553
+ const [
28554
+ measuredPageContentIdentityKeysByIndex,
28555
+ setMeasuredPageContentIdentityKeysByIndex
28556
+ ] = React.useState([]);
28029
28557
  const [, setRenderableImageSourceRevision] = React.useState(0);
28030
28558
  const [activeEditableParagraphSegment, setActiveEditableParagraphSegment] = React.useState(void 0);
28031
28559
  const wrappedParagraphTextareaRef = React.useRef(
@@ -28075,6 +28603,7 @@ function DocxEditorViewer({
28075
28603
  }, []);
28076
28604
  React.useEffect(() => {
28077
28605
  setMeasuredPageContentHeightByIndex([]);
28606
+ setMeasuredPageContentIdentityKeysByIndex([]);
28078
28607
  setTableMeasuredRowHeights({});
28079
28608
  setTableRowHeights({});
28080
28609
  setTableColumnWidths({});
@@ -28469,7 +28998,7 @@ function DocxEditorViewer({
28469
28998
  tableDraftLayoutEpoch,
28470
28999
  tableMeasuredRowHeights
28471
29000
  ]);
28472
- const pageNodeSegmentsByPage = React.useMemo(() => {
29001
+ const pageSegmentationPlan = React.useMemo(() => {
28473
29002
  const pageContentHeightPx = Math.max(
28474
29003
  120,
28475
29004
  documentLayout.pageHeightPx - documentLayout.marginsPx.top - documentLayout.marginsPx.bottom
@@ -28480,6 +29009,7 @@ function DocxEditorViewer({
28480
29009
  );
28481
29010
  const suppressSpacingBeforeAfterPageBreak = editor.model.metadata.compatibility?.suppressSpacingBeforeAfterPageBreak === true;
28482
29011
  const preferLastRenderedParagraphStartBreaks = !editor.canUndo && !editor.canRedo;
29012
+ const canUseMeasuredPageContentHeights = !editor.canUndo && !editor.canRedo && !disableMeasuredImportPagination && !floatingMovePreview && !dropCapMovePreview && (measuredPageContentHeightByIndex?.length ?? 0) > 0;
28483
29013
  const buildEstimatedPages = (measuredTableRowHeightsByNodeIndex, measuredPageContentHeightsOverride) => {
28484
29014
  const allowMeasuredPageContentHeights = !editor.canUndo && !editor.canRedo && !disableMeasuredImportPagination && !floatingMovePreview && !dropCapMovePreview;
28485
29015
  const baseMeasuredHeights = !allowMeasuredPageContentHeights || measuredPageContentHeightsOverride === null ? void 0 : measuredPageContentHeightsOverride ?? measuredPageContentHeightByIndex;
@@ -28525,14 +29055,13 @@ function DocxEditorViewer({
28525
29055
  minimumPageCount,
28526
29056
  Math.round(storedDocumentPageCount2)
28527
29057
  ) : void 0;
28528
- let estimatedPages = buildEstimatedPages(
28529
- tableMeasuredRowHeightsForPagination
29058
+ const pureEstimatedPages = buildEstimatedPages(
29059
+ tableMeasuredRowHeightsForPagination,
29060
+ null
28530
29061
  );
29062
+ let estimatedPages = buildEstimatedPages(tableMeasuredRowHeightsForPagination);
29063
+ let estimatedPagesUseMeasuredPageContentHeightsForRender = canUseMeasuredPageContentHeights;
28531
29064
  if (measuredPageContentHeightByIndex && measuredPageContentHeightByIndex.length > 0) {
28532
- const pureEstimatedPages = buildEstimatedPages(
28533
- tableMeasuredRowHeightsForPagination,
28534
- null
28535
- );
28536
29065
  const measuredPagesAreOnlySplitParagraphs = estimatedPages.length > 0 && estimatedPages.every(
28537
29066
  (pageSegments) => documentPageContainsOnlySplitParagraphSegments(pageSegments)
28538
29067
  );
@@ -28541,25 +29070,38 @@ function DocxEditorViewer({
28541
29070
  );
28542
29071
  if (measuredPagesAreOnlySplitParagraphs && purePagesAreOnlySplitParagraphs && pureEstimatedPages.length < estimatedPages.length) {
28543
29072
  estimatedPages = pureEstimatedPages;
29073
+ estimatedPagesUseMeasuredPageContentHeightsForRender = false;
28544
29074
  }
28545
29075
  }
28546
29076
  if (!editor.canUndo && !editor.canRedo && targetPageCount !== void 0 && tableMeasuredRowHeightsForPagination) {
28547
29077
  const candidatePages = [
28548
- estimatedPages,
28549
- buildEstimatedPages(void 0),
28550
- buildEstimatedPages(void 0, null)
29078
+ {
29079
+ pages: estimatedPages,
29080
+ useMeasuredPageContentHeightsForRender: estimatedPagesUseMeasuredPageContentHeightsForRender
29081
+ },
29082
+ {
29083
+ pages: buildEstimatedPages(void 0),
29084
+ useMeasuredPageContentHeightsForRender: canUseMeasuredPageContentHeights
29085
+ },
29086
+ {
29087
+ pages: buildEstimatedPages(void 0, null),
29088
+ useMeasuredPageContentHeightsForRender: false
29089
+ }
28551
29090
  ];
28552
- estimatedPages = candidatePages.reduce((bestCandidate, candidate) => {
28553
- const bestDifference = Math.abs(bestCandidate.length - targetPageCount);
29091
+ const bestCandidate = candidatePages.reduce((best, candidate) => {
29092
+ const bestDifference = Math.abs(best.pages.length - targetPageCount);
28554
29093
  const candidateDifference = Math.abs(
28555
- candidate.length - targetPageCount
29094
+ candidate.pages.length - targetPageCount
28556
29095
  );
28557
- return candidateDifference < bestDifference ? candidate : bestCandidate;
29096
+ return candidateDifference < bestDifference ? candidate : best;
28558
29097
  });
29098
+ estimatedPages = bestCandidate.pages;
29099
+ estimatedPagesUseMeasuredPageContentHeightsForRender = bestCandidate.useMeasuredPageContentHeightsForRender;
28559
29100
  } else if (!editor.canUndo && !editor.canRedo && targetPageCount !== void 0) {
28560
- const pureEstimatedPages = buildEstimatedPages(void 0, null);
28561
- if (Math.abs(pureEstimatedPages.length - targetPageCount) < Math.abs(estimatedPages.length - targetPageCount)) {
28562
- estimatedPages = pureEstimatedPages;
29101
+ const pureEstimatedPages2 = buildEstimatedPages(void 0, null);
29102
+ if (Math.abs(pureEstimatedPages2.length - targetPageCount) < Math.abs(estimatedPages.length - targetPageCount)) {
29103
+ estimatedPages = pureEstimatedPages2;
29104
+ estimatedPagesUseMeasuredPageContentHeightsForRender = false;
28563
29105
  }
28564
29106
  }
28565
29107
  const measuredPageHeightOverridesReduceContent = !editor.canUndo && !editor.canRedo && !floatingMovePreview && !dropCapMovePreview && estimatedPages.some((segments, pageIndex) => {
@@ -28584,7 +29126,10 @@ function DocxEditorViewer({
28584
29126
  )
28585
29127
  );
28586
29128
  if (!Number.isFinite(storedDocumentPageCount2) || storedDocumentPageCount2 <= 0) {
28587
- return estimatedPages;
29129
+ return {
29130
+ pages: estimatedPages,
29131
+ useMeasuredPageContentHeightsForRender: estimatedPagesUseMeasuredPageContentHeightsForRender
29132
+ };
28588
29133
  }
28589
29134
  const resolvedTargetPageCount = targetPageCount ?? minimumPageCount;
28590
29135
  const hasTableInternalPageBreaks = editor.model.nodes.some(
@@ -28600,10 +29145,16 @@ function DocxEditorViewer({
28600
29145
  renderedBreakHintPageCount
28601
29146
  }) && (!measuredPageHeightOverridesReduceContent || allowMeasuredReductionOverPaginationReconciliation);
28602
29147
  if (!allowStoredPageCountReconciliation) {
28603
- return estimatedPages;
29148
+ return {
29149
+ pages: estimatedPages,
29150
+ useMeasuredPageContentHeightsForRender: estimatedPagesUseMeasuredPageContentHeightsForRender
29151
+ };
28604
29152
  }
28605
29153
  if (estimatedPages.length === resolvedTargetPageCount) {
28606
- return estimatedPages;
29154
+ return {
29155
+ pages: estimatedPages,
29156
+ useMeasuredPageContentHeightsForRender: estimatedPagesUseMeasuredPageContentHeightsForRender
29157
+ };
28607
29158
  }
28608
29159
  const reconciliationScales = allowMeasuredReductionOverPaginationReconciliation ? [
28609
29160
  1.02,
@@ -28651,20 +29202,25 @@ function DocxEditorViewer({
28651
29202
  let reconciledPages = reconcileCandidatePages(
28652
29203
  estimatedPages,
28653
29204
  tableMeasuredRowHeightsForPagination,
28654
- measuredPageContentHeightByIndex
29205
+ estimatedPagesUseMeasuredPageContentHeightsForRender ? measuredPageContentHeightByIndex : null
28655
29206
  );
29207
+ let reconciledPagesUseMeasuredPageContentHeightsForRender = estimatedPagesUseMeasuredPageContentHeightsForRender;
28656
29208
  if (!editor.canUndo && !editor.canRedo) {
28657
- const pureEstimatedPages = buildEstimatedPages(void 0, null);
29209
+ const pureEstimatedPages2 = buildEstimatedPages(void 0, null);
28658
29210
  const pureReconciledPages = reconcileCandidatePages(
28659
- pureEstimatedPages,
29211
+ pureEstimatedPages2,
28660
29212
  void 0,
28661
29213
  null
28662
29214
  );
28663
29215
  if (Math.abs(pureReconciledPages.length - resolvedTargetPageCount) < Math.abs(reconciledPages.length - resolvedTargetPageCount)) {
28664
29216
  reconciledPages = pureReconciledPages;
29217
+ reconciledPagesUseMeasuredPageContentHeightsForRender = false;
28665
29218
  }
28666
29219
  }
28667
- return reconciledPages;
29220
+ return {
29221
+ pages: reconciledPages,
29222
+ useMeasuredPageContentHeightsForRender: reconciledPagesUseMeasuredPageContentHeightsForRender
29223
+ };
28668
29224
  }, [
28669
29225
  editor.canRedo,
28670
29226
  editor.canUndo,
@@ -28686,6 +29242,14 @@ function DocxEditorViewer({
28686
29242
  measuredPageContentHeightByIndex,
28687
29243
  tableMeasuredRowHeightsForPagination
28688
29244
  ]);
29245
+ const pageNodeSegmentsByPage = pageSegmentationPlan.pages;
29246
+ const useMeasuredPageContentHeightsForRender = pageSegmentationPlan.useMeasuredPageContentHeightsForRender;
29247
+ const pageNodeSegmentIdentityKeysByPage = React.useMemo(
29248
+ () => pageNodeSegmentsByPage.map(
29249
+ (pageSegments) => documentPageNodeSegmentsIdentityKey(pageSegments)
29250
+ ),
29251
+ [pageNodeSegmentsByPage]
29252
+ );
28689
29253
  const pageIndexByNodeIndex = React.useMemo(() => {
28690
29254
  const indexByNode = /* @__PURE__ */ new Map();
28691
29255
  pageNodeSegmentsByPage.forEach((segments, pageIndex) => {
@@ -29711,6 +30275,9 @@ function DocxEditorViewer({
29711
30275
  setMeasuredPageContentHeightByIndex(
29712
30276
  (current) => current.length === 0 ? current : []
29713
30277
  );
30278
+ setMeasuredPageContentIdentityKeysByIndex(
30279
+ (current) => current.length === 0 ? current : []
30280
+ );
29714
30281
  return;
29715
30282
  }
29716
30283
  if (!paginationMeasurementEnabled) {
@@ -29721,124 +30288,140 @@ function DocxEditorViewer({
29721
30288
  setMeasuredPageContentHeightByIndex(
29722
30289
  (current) => current.length === 0 ? current : []
29723
30290
  );
30291
+ setMeasuredPageContentIdentityKeysByIndex(
30292
+ (current) => current.length === 0 ? current : []
30293
+ );
29724
30294
  return;
29725
30295
  }
29726
30296
  if (Date.now() < paginationMeasurementSuspendUntilRef.current) {
29727
30297
  return;
29728
30298
  }
29729
30299
  const zoomScale = resolveEffectiveZoomScale(rootElement);
29730
- const nextMeasuredHeights = pageNodeSegmentsByPage.map((_, pageIndex) => {
29731
- const pageLayout = pageSectionInfoByIndex[pageIndex]?.layout ?? documentLayout;
29732
- const pageElement = pageElementsRef.current.get(pageIndex);
29733
- const fallbackHeightPx = Math.max(
29734
- 120,
29735
- pageLayout.pageHeightPx - pageLayout.marginsPx.top - pageLayout.marginsPx.bottom
29736
- );
29737
- if (!pageElement) {
29738
- return fallbackHeightPx;
29739
- }
29740
- const headerElement = pageHeaderElementsRef.current.get(pageIndex);
29741
- const bodyElement = pageBodyElementsRef.current.get(pageIndex);
29742
- const footerElement = pageFooterElementsRef.current.get(pageIndex);
29743
- const headerHeightPx = headerElement ? Math.max(
29744
- 0,
29745
- Math.round(headerElement.getBoundingClientRect().height / zoomScale)
29746
- ) : 0;
29747
- const docxFooterTopPx = resolveFooterNodesFloatingBoundaryTopPx(
29748
- pageHeaderAndFooterNodes[pageIndex]?.footerNodes ?? [],
29749
- pageLayout
29750
- );
29751
- let footerTopPx = Number.isFinite(docxFooterTopPx) ? Math.round(docxFooterTopPx) : void 0;
29752
- if (footerElement) {
29753
- const pageRect2 = pageElement.getBoundingClientRect();
29754
- const maxOverflowCapPx = Math.max(
29755
- 16,
29756
- Math.min(
29757
- Math.round(pageLayout.pageHeightPx * 0.12),
29758
- Math.round(
29759
- pageLayout.marginsPx.bottom + pageLayout.footerDistancePx + 24
29760
- )
29761
- )
30300
+ const nextMeasuredPageIdentityKeys = pageNodeSegmentIdentityKeysByPage;
30301
+ const nextMeasuredPageDiagnostics = pageNodeSegmentsByPage.map(
30302
+ (_, pageIndex) => {
30303
+ const pageLayout = pageSectionInfoByIndex[pageIndex]?.layout ?? documentLayout;
30304
+ const pageElement = pageElementsRef.current.get(pageIndex);
30305
+ const fallbackHeightPx = Math.max(
30306
+ 120,
30307
+ pageLayout.pageHeightPx - pageLayout.marginsPx.top - pageLayout.marginsPx.bottom
29762
30308
  );
29763
- const footerFlowBoundaryTopPx = Math.max(
30309
+ if (!pageElement) {
30310
+ return {
30311
+ heightPx: fallbackHeightPx,
30312
+ bodyOverrunsFooter: false
30313
+ };
30314
+ }
30315
+ const headerElement = pageHeaderElementsRef.current.get(pageIndex);
30316
+ const bodyElement = pageBodyElementsRef.current.get(pageIndex);
30317
+ const footerElement = pageFooterElementsRef.current.get(pageIndex);
30318
+ const headerHeightPx = headerElement ? Math.max(
29764
30319
  0,
29765
- pageLayout.pageHeightPx - Math.max(0, pageLayout.footerDistancePx)
30320
+ Math.round(headerElement.getBoundingClientRect().height / zoomScale)
30321
+ ) : 0;
30322
+ const docxFooterTopPx = resolveFooterNodesFloatingBoundaryTopPx(
30323
+ pageHeaderAndFooterNodes[pageIndex]?.footerNodes ?? [],
30324
+ pageLayout
29766
30325
  );
29767
- const minimumRelevantFooterTopPx = Number.isFinite(docxFooterTopPx) ? Math.max(
30326
+ let footerTopPx = Number.isFinite(docxFooterTopPx) ? Math.round(docxFooterTopPx) : void 0;
30327
+ if (footerElement) {
30328
+ const pageRect2 = pageElement.getBoundingClientRect();
30329
+ const maxOverflowCapPx = Math.max(
30330
+ 16,
30331
+ Math.min(
30332
+ Math.round(pageLayout.pageHeightPx * 0.12),
30333
+ Math.round(
30334
+ pageLayout.marginsPx.bottom + pageLayout.footerDistancePx + 24
30335
+ )
30336
+ )
30337
+ );
30338
+ const footerFlowBoundaryTopPx = Math.max(
30339
+ 0,
30340
+ pageLayout.pageHeightPx - Math.max(0, pageLayout.footerDistancePx)
30341
+ );
30342
+ const minimumRelevantFooterTopPx = Number.isFinite(docxFooterTopPx) ? Math.max(
30343
+ 0,
30344
+ Math.min(
30345
+ Math.max(0, footerFlowBoundaryTopPx - maxOverflowCapPx),
30346
+ Math.round(docxFooterTopPx - maxOverflowCapPx)
30347
+ )
30348
+ ) : Math.max(0, footerFlowBoundaryTopPx - maxOverflowCapPx);
30349
+ let visualTop = Number.POSITIVE_INFINITY;
30350
+ footerElement.querySelectorAll("*").forEach((element) => {
30351
+ if (!element.isConnected) {
30352
+ return;
30353
+ }
30354
+ const rect = element.getBoundingClientRect();
30355
+ if (rect.width <= 0 && rect.height <= 0) {
30356
+ return;
30357
+ }
30358
+ const relativeTopPx = (rect.top - pageRect2.top) / zoomScale;
30359
+ if (relativeTopPx < minimumRelevantFooterTopPx - 1) {
30360
+ return;
30361
+ }
30362
+ visualTop = Math.min(visualTop, rect.top);
30363
+ });
30364
+ if (Number.isFinite(visualTop)) {
30365
+ const measuredFooterTopPx = (visualTop - pageRect2.top) / zoomScale;
30366
+ footerTopPx = Number.isFinite(footerTopPx) ? Math.min(
30367
+ Math.round(footerTopPx),
30368
+ Math.round(measuredFooterTopPx)
30369
+ ) : Math.round(measuredFooterTopPx);
30370
+ }
30371
+ }
30372
+ const pageRect = pageElement.getBoundingClientRect();
30373
+ const bodyRect = bodyElement?.getBoundingClientRect();
30374
+ const bodyTopPx = bodyRect ? Math.max(0, Math.round((bodyRect.top - pageRect.top) / zoomScale)) : void 0;
30375
+ const bodyImageCount = bodyElement?.querySelectorAll("[data-docx-image-location]").length ?? 0;
30376
+ const bodyTextTrimmedLength = bodyElement?.textContent?.replace(/\s+/g, "").length ?? 0;
30377
+ const skipBodyBottomAdjustment = bodyImageCount > 0 && bodyTextTrimmedLength === 0;
30378
+ const visualBodyBottom = bodyElement && bodyRect ? resolveMeasuredBodyRenderedBottomPx(
30379
+ Array.from(bodyElement.querySelectorAll("*")).map(
30380
+ (element) => {
30381
+ const rect = element.getBoundingClientRect();
30382
+ return {
30383
+ bottomPx: rect.bottom,
30384
+ widthPx: rect.width,
30385
+ heightPx: rect.height,
30386
+ ignore: !element.isConnected || Boolean(element.closest("[data-docx-image-location]")) || Boolean(
30387
+ element.closest(
30388
+ `[${PAGE_CONTENT_MEASUREMENT_IGNORE_ATTRIBUTE}="true"]`
30389
+ )
30390
+ )
30391
+ };
30392
+ }
30393
+ )
30394
+ ) : void 0;
30395
+ const bodyRenderedBottomPx = bodyRect && Number.isFinite(visualBodyBottom) ? Math.max(
29768
30396
  0,
29769
- Math.min(
29770
- Math.max(0, footerFlowBoundaryTopPx - maxOverflowCapPx),
29771
- Math.round(docxFooterTopPx - maxOverflowCapPx)
30397
+ Math.round(
30398
+ (visualBodyBottom - pageRect.top) / zoomScale
29772
30399
  )
29773
- ) : Math.max(0, footerFlowBoundaryTopPx - maxOverflowCapPx);
29774
- let visualTop = Number.POSITIVE_INFINITY;
29775
- footerElement.querySelectorAll("*").forEach((element) => {
29776
- if (!element.isConnected) {
29777
- return;
29778
- }
29779
- const rect = element.getBoundingClientRect();
29780
- if (rect.width <= 0 && rect.height <= 0) {
29781
- return;
29782
- }
29783
- const relativeTopPx = (rect.top - pageRect2.top) / zoomScale;
29784
- if (relativeTopPx < minimumRelevantFooterTopPx - 1) {
29785
- return;
29786
- }
29787
- visualTop = Math.min(visualTop, rect.top);
30400
+ ) : void 0;
30401
+ return resolveMeasuredPageContentHeightDiagnostics({
30402
+ pageLayout,
30403
+ fallbackHeightPx,
30404
+ headerHeightPx,
30405
+ currentMeasuredHeightPx: measuredPageContentHeightByIndex?.[pageIndex],
30406
+ bodyTopPx,
30407
+ bodyRenderedBottomPx,
30408
+ footerTopPx,
30409
+ skipBodyBottomAdjustment
29788
30410
  });
29789
- if (Number.isFinite(visualTop)) {
29790
- const measuredFooterTopPx = (visualTop - pageRect2.top) / zoomScale;
29791
- footerTopPx = Number.isFinite(footerTopPx) ? Math.min(
29792
- Math.round(footerTopPx),
29793
- Math.round(measuredFooterTopPx)
29794
- ) : Math.round(measuredFooterTopPx);
29795
- }
29796
30411
  }
29797
- const pageRect = pageElement.getBoundingClientRect();
29798
- const bodyRect = bodyElement?.getBoundingClientRect();
29799
- const bodyTopPx = bodyRect ? Math.max(0, Math.round((bodyRect.top - pageRect.top) / zoomScale)) : void 0;
29800
- const bodyImageCount = bodyElement?.querySelectorAll("[data-docx-image-location]").length ?? 0;
29801
- const bodyTextTrimmedLength = bodyElement?.textContent?.replace(/\s+/g, "").length ?? 0;
29802
- const skipBodyBottomAdjustment = bodyImageCount > 0 && bodyTextTrimmedLength === 0;
29803
- const visualBodyBottom = bodyElement && bodyRect ? resolveMeasuredBodyRenderedBottomPx(
29804
- Array.from(bodyElement.querySelectorAll("*")).map(
29805
- (element) => {
29806
- const rect = element.getBoundingClientRect();
29807
- return {
29808
- bottomPx: rect.bottom,
29809
- widthPx: rect.width,
29810
- heightPx: rect.height,
29811
- ignore: !element.isConnected || Boolean(element.closest("[data-docx-image-location]")) || Boolean(
29812
- element.closest(
29813
- `[${PAGE_CONTENT_MEASUREMENT_IGNORE_ATTRIBUTE}="true"]`
29814
- )
29815
- )
29816
- };
29817
- }
29818
- )
29819
- ) : void 0;
29820
- const bodyRenderedBottomPx = bodyRect && Number.isFinite(visualBodyBottom) ? Math.max(
29821
- 0,
29822
- Math.round(
29823
- (visualBodyBottom - pageRect.top) / zoomScale
29824
- )
29825
- ) : void 0;
29826
- return resolveMeasuredPageContentHeightPx({
29827
- pageLayout,
29828
- fallbackHeightPx,
29829
- headerHeightPx,
29830
- currentMeasuredHeightPx: measuredPageContentHeightByIndex?.[pageIndex],
29831
- bodyTopPx,
29832
- bodyRenderedBottomPx,
29833
- footerTopPx,
29834
- skipBodyBottomAdjustment
29835
- });
29836
- });
30412
+ );
30413
+ const nextMeasuredHeights = nextMeasuredPageDiagnostics.map(
30414
+ (diagnostics) => diagnostics.heightPx
30415
+ );
29837
30416
  const frameId = window.requestAnimationFrame(() => {
29838
30417
  setMeasuredPageContentHeightByIndex((current) => {
29839
30418
  const stabilizedHeights = stabilizeMeasuredPageContentHeights(
29840
30419
  current,
29841
- nextMeasuredHeights
30420
+ nextMeasuredHeights,
30421
+ {
30422
+ currentPageIdentityKeys: measuredPageContentIdentityKeysByIndex,
30423
+ nextPageIdentityKeys: nextMeasuredPageIdentityKeys
30424
+ }
29842
30425
  );
29843
30426
  if (current.length === stabilizedHeights.length) {
29844
30427
  let equal = true;
@@ -29856,6 +30439,21 @@ function DocxEditorViewer({
29856
30439
  }
29857
30440
  return stabilizedHeights;
29858
30441
  });
30442
+ setMeasuredPageContentIdentityKeysByIndex((current) => {
30443
+ if (current.length === nextMeasuredPageIdentityKeys.length) {
30444
+ let equal = true;
30445
+ for (let pageIndex = 0; pageIndex < nextMeasuredPageIdentityKeys.length; pageIndex += 1) {
30446
+ if (current[pageIndex] !== nextMeasuredPageIdentityKeys[pageIndex]) {
30447
+ equal = false;
30448
+ break;
30449
+ }
30450
+ }
30451
+ if (equal) {
30452
+ return current;
30453
+ }
30454
+ }
30455
+ return nextMeasuredPageIdentityKeys;
30456
+ });
29859
30457
  });
29860
30458
  return () => {
29861
30459
  window.cancelAnimationFrame(frameId);
@@ -29864,10 +30462,12 @@ function DocxEditorViewer({
29864
30462
  disableMeasuredImportPagination,
29865
30463
  documentLayout,
29866
30464
  measuredPageContentHeightByIndex,
30465
+ measuredPageContentIdentityKeysByIndex,
29867
30466
  paginationMeasurementEnabled,
29868
30467
  paginationMeasurementEpoch,
29869
30468
  pageCount,
29870
30469
  pageNodeSegmentsByPage,
30470
+ pageNodeSegmentIdentityKeysByPage,
29871
30471
  pageSectionInfoByIndex,
29872
30472
  pageHeaderAndFooterNodes
29873
30473
  ]);
@@ -35700,7 +36300,10 @@ function DocxEditorViewer({
35700
36300
  height: run.image.heightPx ? `${run.image.heightPx}px` : void 0,
35701
36301
  verticalAlign: "middle",
35702
36302
  display: "inline-block",
35703
- filter: run.image.cssFilter,
36303
+ filter: appendCssFilters(
36304
+ run.image.cssFilter,
36305
+ documentContentFilter
36306
+ ),
35704
36307
  opacity: run.image.cssOpacity
35705
36308
  }
35706
36309
  },
@@ -35711,14 +36314,15 @@ function DocxEditorViewer({
35711
36314
  overlapStart - run.startOffset,
35712
36315
  overlapEnd - run.startOffset
35713
36316
  );
35714
- if (!slice) {
36317
+ const renderedSlice = sanitizeRenderedPretextFragmentText(slice);
36318
+ if (!renderedSlice) {
35715
36319
  return void 0;
35716
36320
  }
35717
36321
  const textStyle = run.link ? {
35718
- ...linkStyleToCss(run.style, editor.documentTheme),
36322
+ ...linkStyleToCss(run.style, documentContentTheme),
35719
36323
  whiteSpace: "pre"
35720
36324
  } : {
35721
- ...runStyleToCss(run.style, editor.documentTheme),
36325
+ ...runStyleToCss(run.style, documentContentTheme),
35722
36326
  whiteSpace: "pre"
35723
36327
  };
35724
36328
  if (activeSession) {
@@ -35726,7 +36330,7 @@ function DocxEditorViewer({
35726
36330
  "span",
35727
36331
  {
35728
36332
  style: textStyle,
35729
- children: slice
36333
+ children: renderedSlice
35730
36334
  },
35731
36335
  `${keyPrefix}-active-${lineIndex}-${run.key}-${overlapStart}`
35732
36336
  );
@@ -35753,14 +36357,14 @@ function DocxEditorViewer({
35753
36357
  scrollToBookmark(run.link.slice(1));
35754
36358
  },
35755
36359
  style: textStyle,
35756
- children: slice
36360
+ children: renderedSlice
35757
36361
  },
35758
36362
  `${keyPrefix}-fragment-${lineIndex}-${run.key}-${overlapStart}`
35759
36363
  ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
35760
36364
  "span",
35761
36365
  {
35762
36366
  style: textStyle,
35763
- children: slice
36367
+ children: renderedSlice
35764
36368
  },
35765
36369
  `${keyPrefix}-fragment-${lineIndex}-${run.key}-${overlapStart}`
35766
36370
  );
@@ -36452,7 +37056,7 @@ function DocxEditorViewer({
36452
37056
  return renderParagraphRuns(
36453
37057
  paragraph,
36454
37058
  keyPrefix,
36455
- editor.documentTheme,
37059
+ documentContentTheme,
36456
37060
  numberingLabel,
36457
37061
  scrollToBookmark,
36458
37062
  interactiveBodyFloatingPageOriginPx,
@@ -36520,7 +37124,10 @@ function DocxEditorViewer({
36520
37124
  height: run.image.heightPx ? `${run.image.heightPx}px` : void 0,
36521
37125
  verticalAlign: "middle",
36522
37126
  display: "inline-block",
36523
- filter: run.image.cssFilter,
37127
+ filter: appendCssFilters(
37128
+ run.image.cssFilter,
37129
+ documentContentFilter
37130
+ ),
36524
37131
  opacity: run.image.cssOpacity
36525
37132
  }
36526
37133
  },
@@ -36535,10 +37142,10 @@ function DocxEditorViewer({
36535
37142
  return void 0;
36536
37143
  }
36537
37144
  const textStyle = run.link ? {
36538
- ...linkStyleToCss(run.style, editor.documentTheme),
37145
+ ...linkStyleToCss(run.style, documentContentTheme),
36539
37146
  whiteSpace: "pre"
36540
37147
  } : {
36541
- ...runStyleToCss(run.style, editor.documentTheme),
37148
+ ...runStyleToCss(run.style, documentContentTheme),
36542
37149
  whiteSpace: "pre"
36543
37150
  };
36544
37151
  return run.link ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -36675,7 +37282,10 @@ function DocxEditorViewer({
36675
37282
  heightPx
36676
37283
  );
36677
37284
  const imageVisualStyle = {
36678
- filter: manualImage.cssFilter,
37285
+ filter: appendCssFilters(
37286
+ manualImage.cssFilter,
37287
+ documentContentFilter
37288
+ ),
36679
37289
  opacity: manualImage.cssOpacity
36680
37290
  };
36681
37291
  const imageTransformStyle = resolveImageRenderTransformStyle(
@@ -36949,7 +37559,10 @@ function DocxEditorViewer({
36949
37559
  verticalAlign: "middle",
36950
37560
  display: "block",
36951
37561
  cursor: isReadOnly ? "default" : "move",
36952
- filter: manualImage.cssFilter,
37562
+ filter: appendCssFilters(
37563
+ manualImage.cssFilter,
37564
+ documentContentFilter
37565
+ ),
36953
37566
  opacity: manualImage.cssOpacity
36954
37567
  }
36955
37568
  }
@@ -37161,7 +37774,10 @@ function DocxEditorViewer({
37161
37774
  verticalAlign: "middle",
37162
37775
  display: "block",
37163
37776
  cursor: isReadOnly ? "default" : "move",
37164
- filter: manualImage.cssFilter,
37777
+ filter: appendCssFilters(
37778
+ manualImage.cssFilter,
37779
+ documentContentFilter
37780
+ ),
37165
37781
  opacity: manualImage.cssOpacity
37166
37782
  }
37167
37783
  }
@@ -37313,7 +37929,7 @@ function DocxEditorViewer({
37313
37929
  });
37314
37930
  }
37315
37931
  if (numberingLabel) {
37316
- const numberingTextStyle = numberingLabel.style ? runStyleToCss(numberingLabel.style, editor.documentTheme) : void 0;
37932
+ const numberingTextStyle = numberingLabel.style ? runStyleToCss(numberingLabel.style, documentContentTheme) : void 0;
37317
37933
  nodes.push(
37318
37934
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
37319
37935
  "span",
@@ -37325,7 +37941,7 @@ function DocxEditorViewer({
37325
37941
  editor.model.metadata.numberingDefinitions,
37326
37942
  numberingLabel,
37327
37943
  numberingTextStyle,
37328
- editor.documentTheme
37944
+ documentContentTheme
37329
37945
  ),
37330
37946
  children: numberingLabel.imageSrc ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
37331
37947
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -37642,7 +38258,7 @@ function DocxEditorViewer({
37642
38258
  {
37643
38259
  style: segment.style ? runStyleToCss(
37644
38260
  segment.style,
37645
- editor.documentTheme
38261
+ documentContentTheme
37646
38262
  ) : void 0,
37647
38263
  children: segment.text
37648
38264
  },
@@ -37656,7 +38272,10 @@ function DocxEditorViewer({
37656
38272
  ) : renderableImageSrc && !showsUnsupportedFallback ? (() => {
37657
38273
  const cropLayout = imageCropLayout(child, widthPx, heightPx);
37658
38274
  const imageVisualStyle = {
37659
- filter: child.cssFilter,
38275
+ filter: appendCssFilters(
38276
+ child.cssFilter,
38277
+ documentContentFilter
38278
+ ),
37660
38279
  opacity: child.cssOpacity
37661
38280
  };
37662
38281
  const imageTransformStyle = resolveImageRenderTransformStyle(
@@ -37922,10 +38541,10 @@ function DocxEditorViewer({
37922
38541
  const compactFieldLayout = compactTabStopFieldLayout || child.sourceKind === "legacy";
37923
38542
  const isTextLikeFormField = child.fieldType === "text" || child.fieldType === "date";
37924
38543
  const inputStyle = {
37925
- ...runStyleToCss(child.style, editor.documentTheme),
38544
+ ...runStyleToCss(child.style, documentContentTheme),
37926
38545
  fontFamily: cssFontFamily(child.style?.fontFamily) ?? "inherit",
37927
38546
  fontSize: child.style?.fontSizePt ? `${child.style.fontSizePt}pt` : "inherit",
37928
- color: themedRunColor(child.style?.color, editor.documentTheme) ?? "inherit",
38547
+ color: themedRunColor(child.style?.color, documentContentTheme) ?? "inherit",
37929
38548
  backgroundColor: isTextLikeFormField ? "rgba(148, 163, 184, 0.16)" : compactFieldLayout ? "transparent" : "#ffffff",
37930
38549
  border: isTextLikeFormField ? "1px solid rgba(148, 163, 184, 0.6)" : compactFieldLayout ? "none" : "1px solid #d4d4d8",
37931
38550
  borderRadius: isTextLikeFormField ? 4 : compactFieldLayout ? 0 : 6,
@@ -38007,7 +38626,7 @@ function DocxEditorViewer({
38007
38626
  cursor: isReadOnly ? "default" : "pointer",
38008
38627
  userSelect: "none",
38009
38628
  outline: "none",
38010
- ...runStyleToCss(child.style, editor.documentTheme)
38629
+ ...runStyleToCss(child.style, documentContentTheme)
38011
38630
  },
38012
38631
  children: checkboxSymbol
38013
38632
  },
@@ -38221,7 +38840,7 @@ function DocxEditorViewer({
38221
38840
  "span",
38222
38841
  {
38223
38842
  style: {
38224
- ...runStyleToCss(child.style, editor.documentTheme),
38843
+ ...runStyleToCss(child.style, documentContentTheme),
38225
38844
  verticalAlign: "super",
38226
38845
  fontSize: "0.75em"
38227
38846
  },
@@ -38266,7 +38885,7 @@ function DocxEditorViewer({
38266
38885
  const bookmarkName = linkHref.slice(1);
38267
38886
  scrollToBookmark(bookmarkName);
38268
38887
  },
38269
- style: linkStyleToCss(child.style, editor.documentTheme),
38888
+ style: linkStyleToCss(child.style, documentContentTheme),
38270
38889
  children: child.text
38271
38890
  },
38272
38891
  runKey
@@ -38281,7 +38900,7 @@ function DocxEditorViewer({
38281
38900
  );
38282
38901
  return;
38283
38902
  }
38284
- const runStyle = runStyleToCss(child.style, editor.documentTheme);
38903
+ const runStyle = runStyleToCss(child.style, documentContentTheme);
38285
38904
  const renderedText = attachTextToPreviousCheckbox(
38286
38905
  paragraph,
38287
38906
  childIndex,
@@ -38361,7 +38980,8 @@ function DocxEditorViewer({
38361
38980
  resizePreview,
38362
38981
  selectedImage,
38363
38982
  setSelectedSectionImageKey,
38364
- editor.documentTheme,
38983
+ documentContentFilter,
38984
+ documentContentTheme,
38365
38985
  editor.selectFormField,
38366
38986
  editor.setFormFieldValue,
38367
38987
  editor.toggleFormCheckbox,
@@ -38556,9 +39176,6 @@ function DocxEditorViewer({
38556
39176
  );
38557
39177
  const paragraphSegmentVisibleHeightPx = paragraphSegmentVisibleLineCount * paragraphSegmentLineHeightPx;
38558
39178
  const paragraphSegmentTranslateYPx = paragraphSegmentStartLine * paragraphSegmentLineHeightPx;
38559
- const paragraphSegmentClipBleed = resolveParagraphSegmentClipBleedPx(paragraphLineRange);
38560
- const paragraphSegmentClipBleedTopPx = paragraphSegmentClipBleed.topPx;
38561
- const paragraphSegmentClipBleedBottomPx = paragraphSegmentClipBleed.bottomPx;
38562
39179
  const paragraphSegmentIsActiveEditable = paragraphSegmentIdentityMatches(
38563
39180
  activeEditableParagraphSegment,
38564
39181
  nodeIndex,
@@ -38607,6 +39224,9 @@ function DocxEditorViewer({
38607
39224
  pretextParagraphSliceEndLine
38608
39225
  ) : void 0;
38609
39226
  const shouldRenderParagraphSegmentWithPretext = hasPartialLineRange && Boolean(pretextParagraphSource) && Boolean(pretextParagraphLayout) && pretextParagraphTotalLines > 0;
39227
+ const paragraphSegmentClipBleed = shouldRenderParagraphSegmentWithPretext ? resolveParagraphSegmentClipBleedPx(paragraphLineRange) : resolveFallbackParagraphSegmentClipBleedPx(node, paragraphLineRange);
39228
+ const paragraphSegmentClipBleedTopPx = paragraphSegmentClipBleed.topPx;
39229
+ const paragraphSegmentClipBleedBottomPx = paragraphSegmentClipBleed.bottomPx;
38610
39230
  const pretextSegmentNumberingMarkerBoxWidthPx = numberingLabel && paragraphSegmentStartLine === 0 ? resolveNumberingMarkerBoxWidthPx(
38611
39231
  node,
38612
39232
  editor.model.metadata.numberingDefinitions,
@@ -38631,8 +39251,8 @@ function DocxEditorViewer({
38631
39251
  node,
38632
39252
  editor.model.metadata.numberingDefinitions,
38633
39253
  numberingLabel,
38634
- numberingLabel.style ? runStyleToCss(numberingLabel.style, editor.documentTheme) : void 0,
38635
- editor.documentTheme
39254
+ numberingLabel.style ? runStyleToCss(numberingLabel.style, documentContentTheme) : void 0,
39255
+ documentContentTheme
38636
39256
  ),
38637
39257
  position: "absolute",
38638
39258
  left: -Math.round(
@@ -38656,7 +39276,8 @@ function DocxEditorViewer({
38656
39276
  verticalAlign: "text-bottom",
38657
39277
  width: numberingLabel.imageWidthPx ?? 12,
38658
39278
  height: numberingLabel.imageHeightPx ?? 12,
38659
- marginRight: 2
39279
+ marginRight: 2,
39280
+ filter: documentContentFilter
38660
39281
  }
38661
39282
  }
38662
39283
  ),
@@ -39804,7 +40425,7 @@ ${currentText.slice(end)}`;
39804
40425
  children: renderHeaderNode(
39805
40426
  cellContent,
39806
40427
  `active-cell-nested-table-${nodeIndex}-${rowIndex}-${cellIndex}-${contentIndex}`,
39807
- editor.documentTheme,
40428
+ documentContentTheme,
39808
40429
  editor.model.metadata.numberingDefinitions,
39809
40430
  headingStyles,
39810
40431
  spannedWidthPx > 0 ? spannedWidthPx : void 0,
@@ -40720,7 +41341,7 @@ ${currentText.slice(end)}`;
40720
41341
  return renderHeaderNode(
40721
41342
  cellContent,
40722
41343
  `body-cell-nested-table-${nodeIndex}-${rowIndex}-${cellIndex}-${contentIndex}`,
40723
- editor.documentTheme,
41344
+ documentContentTheme,
40724
41345
  editor.model.metadata.numberingDefinitions,
40725
41346
  headingStyles,
40726
41347
  spannedWidthPx > 0 ? spannedWidthPx : void 0,
@@ -41402,7 +42023,7 @@ ${currentText.slice(end)}`;
41402
42023
  style: {
41403
42024
  ...runStyleToCss(
41404
42025
  dropCapTextStyle,
41405
- editor.documentTheme
42026
+ documentContentTheme
41406
42027
  ),
41407
42028
  width: "100%",
41408
42029
  minHeight: dropCapHeightPx,
@@ -41419,7 +42040,7 @@ ${currentText.slice(end)}`;
41419
42040
  boxShadow: isSelectedDropCap ? "0 0 0 2px rgba(191, 219, 254, 0.65)" : void 0,
41420
42041
  color: themedRunColor(
41421
42042
  dropCapTextStyle.color,
41422
- editor.documentTheme
42043
+ documentContentTheme
41423
42044
  ) ?? void 0,
41424
42045
  fontFamily: cssFontFamily(dropCapTextStyle.fontFamily) ?? void 0
41425
42046
  }
@@ -41607,7 +42228,7 @@ ${currentText.slice(end)}`;
41607
42228
  style: {
41608
42229
  ...runStyleToCss(
41609
42230
  dropCapTextStyle,
41610
- editor.documentTheme
42231
+ documentContentTheme
41611
42232
  ),
41612
42233
  width: "100%",
41613
42234
  minHeight: dropCapHeightPx,
@@ -41624,7 +42245,7 @@ ${currentText.slice(end)}`;
41624
42245
  boxShadow: isSelectedDropCap ? "0 0 0 2px rgba(191, 219, 254, 0.65)" : void 0,
41625
42246
  color: themedRunColor(
41626
42247
  dropCapTextStyle.color,
41627
- editor.documentTheme
42248
+ documentContentTheme
41628
42249
  ) ?? void 0,
41629
42250
  fontFamily: cssFontFamily(
41630
42251
  dropCapTextStyle.fontFamily
@@ -41889,7 +42510,7 @@ ${currentText.slice(end)}`;
41889
42510
  renderParagraphRuns(
41890
42511
  paragraph,
41891
42512
  `${keyPrefix}-runs`,
41892
- editor.documentTheme,
42513
+ documentContentTheme,
41893
42514
  void 0,
41894
42515
  scrollToBookmark,
41895
42516
  void 0,
@@ -41907,7 +42528,7 @@ ${currentText.slice(end)}`;
41907
42528
  ));
41908
42529
  },
41909
42530
  [
41910
- editor.documentTheme,
42531
+ documentContentTheme,
41911
42532
  endnoteDisplayIndexById,
41912
42533
  footnoteDisplayIndexById,
41913
42534
  renderParagraphRuns,
@@ -42068,13 +42689,7 @@ ${currentText.slice(end)}`;
42068
42689
  "div",
42069
42690
  {
42070
42691
  "data-docx-page-placeholder": "true",
42071
- ref: (element) => {
42072
- if (element) {
42073
- pageElementsRef.current.set(pageIndex, element);
42074
- } else {
42075
- pageElementsRef.current.delete(pageIndex);
42076
- }
42077
- },
42692
+ ref: pagePlaceholderRefForIndex(pageIndex),
42078
42693
  style: {
42079
42694
  height: pageLayout.pageHeightPx,
42080
42695
  width: pageLayout.pageWidthPx
@@ -42166,18 +42781,21 @@ ${currentText.slice(end)}`;
42166
42781
  const isLastPage = pageIndex === pageCount - 1;
42167
42782
  const pageFootnotes = pageFootnotesByIndex[pageIndex] ?? [];
42168
42783
  const pageBottomFootnotes = isLastPage && remainingFootnotes.length > 0 ? [...pageFootnotes, ...remainingFootnotes] : pageFootnotes;
42169
- const pageBodyAvailableHeightPx = resolvePageContentHeightPxForPageSegments(
42170
- pageNodeSegments,
42784
+ const pageBodyAvailableHeightPx = resolveRenderPageContentHeightPxForPageSegments({
42785
+ pageSegments: pageNodeSegments,
42171
42786
  pageIndex,
42172
- Math.max(
42787
+ defaultPageContentHeightPx: Math.max(
42173
42788
  120,
42174
42789
  pageLayout.pageHeightPx - pageLayout.marginsPx.top - pageLayout.marginsPx.bottom
42175
42790
  ),
42176
- paginationSectionMetrics,
42177
- measuredPageContentHeightByIndex
42178
- );
42791
+ metricsBySection: paginationSectionMetrics,
42792
+ measuredPageContentHeightsPxByPageIndex: measuredPageContentHeightByIndex,
42793
+ measuredPageContentIdentityKeysByPageIndex: measuredPageContentIdentityKeysByIndex,
42794
+ pageIdentityKey: pageNodeSegmentIdentityKeysByPage[pageIndex],
42795
+ useMeasuredPageContentHeights: useMeasuredPageContentHeightsForRender
42796
+ });
42179
42797
  const headerFooterBodyDimmed = pageHeaderFooterEditActive;
42180
- const pageBackgroundColor = editor.model.metadata.documentBackgroundColor;
42798
+ const documentPageBackgroundColor = editor.model.metadata.documentBackgroundColor;
42181
42799
  const pageBorders = parseSectionPageBorders(
42182
42800
  pageInfo?.section.sectionPropertiesXml ?? editor.model.metadata.sectionPropertiesXml
42183
42801
  );
@@ -42200,7 +42818,7 @@ ${currentText.slice(end)}`;
42200
42818
  width: pageLayout.pageWidthPx,
42201
42819
  height: pageLayout.pageHeightPx,
42202
42820
  minHeight: pageLayout.pageHeightPx,
42203
- backgroundColor: pageBackgroundColor ?? pageSurfaceBaseStyle.backgroundColor,
42821
+ backgroundColor: pageBackgroundColor ?? documentPageBackgroundColor ?? pageSurfaceBaseStyle.backgroundColor,
42204
42822
  position: "relative",
42205
42823
  paddingTop: pageLayout.marginsPx.top,
42206
42824
  paddingRight: pageLayout.marginsPx.right,
@@ -42264,13 +42882,7 @@ ${currentText.slice(end)}`;
42264
42882
  "div",
42265
42883
  {
42266
42884
  "data-docx-page-surface": "true",
42267
- ref: (element) => {
42268
- if (element) {
42269
- pageElementsRef.current.set(pageIndex, element);
42270
- } else {
42271
- pageElementsRef.current.delete(pageIndex);
42272
- }
42273
- },
42885
+ ref: pageSurfaceRefForIndex(pageIndex),
42274
42886
  style: {
42275
42887
  ...pageSurfaceStyle,
42276
42888
  margin: 0
@@ -42288,7 +42900,8 @@ ${currentText.slice(end)}`;
42288
42900
  height: pageLayout.pageHeightPx,
42289
42901
  overflow: "clip",
42290
42902
  pointerEvents: "none",
42291
- zIndex: 0
42903
+ zIndex: 0,
42904
+ ...documentContentFilter ? { filter: documentContentFilter } : void 0
42292
42905
  },
42293
42906
  children: pageCoverBackgroundImages.map(({ key, image }) => {
42294
42907
  const renderableImageSrc = resolveRenderableImageSource(image);
@@ -42310,7 +42923,10 @@ ${currentText.slice(end)}`;
42310
42923
  height: "100%",
42311
42924
  display: "block",
42312
42925
  objectFit: "cover",
42313
- filter: image.cssFilter,
42926
+ filter: appendCssFilters(
42927
+ image.cssFilter,
42928
+ documentContentFilter
42929
+ ),
42314
42930
  opacity: image.cssOpacity,
42315
42931
  ...resolveImageRenderTransformStyle(image, {
42316
42932
  frameWidthPx: pageLayout.pageWidthPx,
@@ -42328,7 +42944,10 @@ ${currentText.slice(end)}`;
42328
42944
  "div",
42329
42945
  {
42330
42946
  "data-docx-page-border-overlay": "true",
42331
- style: pageBorderOverlayStyle
42947
+ style: {
42948
+ ...pageBorderOverlayStyle,
42949
+ ...documentContentFilter ? { filter: documentContentFilter } : void 0
42950
+ }
42332
42951
  }
42333
42952
  ) : null,
42334
42953
  pageSections.headerNodes.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -42357,7 +42976,8 @@ ${currentText.slice(end)}`;
42357
42976
  transition: "opacity 120ms ease",
42358
42977
  outline: "none",
42359
42978
  boxShadow: "none",
42360
- zIndex: 1
42979
+ zIndex: 1,
42980
+ ...documentContentFilter ? { filter: documentContentFilter } : void 0
42361
42981
  },
42362
42982
  contentEditable: pageHeaderFooterEditActive && !isReadOnly,
42363
42983
  suppressContentEditableWarning: true,
@@ -42417,7 +43037,7 @@ ${currentText.slice(end)}`;
42417
43037
  (node, index) => renderHeaderNode(
42418
43038
  node,
42419
43039
  `header-${pageIndex}-${index}`,
42420
- editor.documentTheme,
43040
+ documentContentTheme,
42421
43041
  editor.model.metadata.numberingDefinitions,
42422
43042
  headingStyles,
42423
43043
  headerNeedsPageWideLayout ? pageLayout.pageWidthPx : pageContentWidthPx,
@@ -42465,7 +43085,8 @@ ${currentText.slice(end)}`;
42465
43085
  transition: "opacity 120ms ease",
42466
43086
  display: "flex",
42467
43087
  flexDirection: "column",
42468
- minHeight: pageBodyAvailableHeightPx
43088
+ minHeight: pageBodyAvailableHeightPx,
43089
+ ...documentContentFilter ? { filter: documentContentFilter } : void 0
42469
43090
  },
42470
43091
  children: [
42471
43092
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { minHeight: 0 }, children: (() => {
@@ -42894,7 +43515,7 @@ ${currentText.slice(end)}`;
42894
43515
  style: {
42895
43516
  marginTop: 8,
42896
43517
  paddingTop: 8,
42897
- borderTop: `1px solid ${editor.documentTheme === "dark" ? "#4b5563" : "#9ca3af"}`,
43518
+ borderTop: `1px solid ${documentContentTheme === "dark" ? "#4b5563" : "#9ca3af"}`,
42898
43519
  display: "grid",
42899
43520
  gap: 6,
42900
43521
  fontSize: 12
@@ -42927,7 +43548,7 @@ ${currentText.slice(end)}`;
42927
43548
  style: {
42928
43549
  marginTop: "auto",
42929
43550
  paddingTop: 8,
42930
- borderTop: `1px solid ${editor.documentTheme === "dark" ? "#4b5563" : "#9ca3af"}`,
43551
+ borderTop: `1px solid ${documentContentTheme === "dark" ? "#4b5563" : "#9ca3af"}`,
42931
43552
  display: "grid",
42932
43553
  gap: 6,
42933
43554
  fontSize: 12
@@ -43031,7 +43652,8 @@ ${currentText.slice(end)}`;
43031
43652
  transition: "opacity 120ms ease",
43032
43653
  outline: "none",
43033
43654
  boxShadow: "none",
43034
- zIndex: 1
43655
+ zIndex: 1,
43656
+ ...documentContentFilter ? { filter: documentContentFilter } : void 0
43035
43657
  },
43036
43658
  contentEditable: pageHeaderFooterEditActive && !isReadOnly,
43037
43659
  suppressContentEditableWarning: true,
@@ -43091,7 +43713,7 @@ ${currentText.slice(end)}`;
43091
43713
  (node, index) => renderHeaderNode(
43092
43714
  node,
43093
43715
  `footer-${pageIndex}-${index}`,
43094
- editor.documentTheme,
43716
+ documentContentTheme,
43095
43717
  editor.model.metadata.numberingDefinitions,
43096
43718
  headingStyles,
43097
43719
  footerNeedsPageWideLayout ? pageLayout.pageWidthPx : pageContentWidthPx,
@@ -45547,6 +46169,7 @@ function ReactDocxViewer({
45547
46169
  resolveDocumentLayout,
45548
46170
  resolveDocumentPageSegmentStartNodeIndex,
45549
46171
  resolveDocumentSectionsFromMetadata,
46172
+ resolveDocxPageThumbnailResolution,
45550
46173
  resolvePaginationSectionMetricsIndexForNodeIndex,
45551
46174
  resolveParagraphBeforeSpacingPx,
45552
46175
  resolveSectionIndexForNodeIndex,
@@ -45578,6 +46201,7 @@ function ReactDocxViewer({
45578
46201
  useDocxLineSpacing,
45579
46202
  useDocxModel,
45580
46203
  useDocxPageLayout,
46204
+ useDocxPageThumbnails,
45581
46205
  useDocxPagination,
45582
46206
  useDocxParagraphStyles,
45583
46207
  useDocxTrackChanges,