@extend-ai/react-docx 0.6.0 → 0.6.1

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
@@ -7799,107 +7799,6 @@ function parseParagraphsFromClipboard(input) {
7799
7799
  }
7800
7800
  }
7801
7801
 
7802
- // src/docx-import-worker-client.ts
7803
- var import_meta = {};
7804
- var cachedWorker;
7805
- var cachedWorkerUnavailable = false;
7806
- var nextRequestId = 1;
7807
- function resolveWorker() {
7808
- if (cachedWorkerUnavailable) {
7809
- return void 0;
7810
- }
7811
- if (cachedWorker) {
7812
- return cachedWorker;
7813
- }
7814
- if (typeof window === "undefined" || typeof Worker === "undefined" || typeof URL === "undefined") {
7815
- cachedWorkerUnavailable = true;
7816
- return void 0;
7817
- }
7818
- try {
7819
- const workerUrl = new URL(
7820
- "./docx-import-worker.ts",
7821
- import_meta.url
7822
- );
7823
- cachedWorker = new Worker(workerUrl, {
7824
- type: "module",
7825
- name: "docx-import"
7826
- });
7827
- return cachedWorker;
7828
- } catch {
7829
- cachedWorkerUnavailable = true;
7830
- cachedWorker = void 0;
7831
- return void 0;
7832
- }
7833
- }
7834
- async function importDocxOnMainThread(buffer) {
7835
- const pkg = await parseDocx(buffer);
7836
- const model = buildDocModel(pkg);
7837
- return { pkg, model };
7838
- }
7839
- async function importDocxViaWorker(buffer) {
7840
- const worker = resolveWorker();
7841
- if (!worker) {
7842
- return importDocxOnMainThread(buffer);
7843
- }
7844
- const requestId = nextRequestId;
7845
- nextRequestId += 1;
7846
- return new Promise((resolve, reject) => {
7847
- const handleMessage = (event) => {
7848
- const data = event.data;
7849
- if (!data || data.requestId !== requestId) {
7850
- return;
7851
- }
7852
- worker.removeEventListener("message", handleMessage);
7853
- worker.removeEventListener("error", handleError);
7854
- worker.removeEventListener("messageerror", handleMessageError);
7855
- if (data.type === "imported") {
7856
- resolve({ pkg: data.pkg, model: data.model });
7857
- } else {
7858
- reject(new Error(data.message));
7859
- }
7860
- };
7861
- const handleError = (event) => {
7862
- worker.removeEventListener("message", handleMessage);
7863
- worker.removeEventListener("error", handleError);
7864
- worker.removeEventListener("messageerror", handleMessageError);
7865
- const message = event instanceof ErrorEvent && event.message ? event.message : "DOCX import worker crashed";
7866
- try {
7867
- worker.terminate();
7868
- } catch {
7869
- }
7870
- if (cachedWorker === worker) {
7871
- cachedWorker = void 0;
7872
- }
7873
- reject(new Error(message));
7874
- };
7875
- const handleMessageError = () => {
7876
- handleError(new Event("messageerror"));
7877
- };
7878
- worker.addEventListener("message", handleMessage);
7879
- worker.addEventListener("error", handleError);
7880
- worker.addEventListener("messageerror", handleMessageError);
7881
- const request = {
7882
- type: "import",
7883
- requestId,
7884
- buffer
7885
- };
7886
- try {
7887
- worker.postMessage(request, [buffer]);
7888
- } catch (error) {
7889
- worker.removeEventListener("message", handleMessage);
7890
- worker.removeEventListener("error", handleError);
7891
- worker.removeEventListener("messageerror", handleMessageError);
7892
- if (typeof console !== "undefined") {
7893
- console.warn(
7894
- "DOCX import worker postMessage failed; falling back to main thread.",
7895
- error
7896
- );
7897
- }
7898
- importDocxOnMainThread(buffer).then(resolve, reject);
7899
- }
7900
- });
7901
- }
7902
-
7903
7802
  // ../serializer/src/index.ts
7904
7803
  var REL_TYPE_IMAGE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
7905
7804
  var REL_TYPE_HYPERLINK = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
@@ -9430,10 +9329,12 @@ function reconcilePageCountCandidateToTargetCountByScalingHeight(options) {
9430
9329
 
9431
9330
  // src/pretext-layout.ts
9432
9331
  var import_pretext = require("@chenglou/pretext");
9433
- var PREPARED_TEXT_CACHE_MAX_ENTRIES = 512;
9434
- var LAYOUT_CACHE_MAX_ENTRIES = 256;
9332
+ var PREPARED_TEXT_CACHE_MAX_ENTRIES = 8192;
9333
+ var LAYOUT_CACHE_MAX_ENTRIES = 4096;
9334
+ var LINE_COUNT_CACHE_MAX_ENTRIES = 16384;
9435
9335
  var preparedTextByKey = /* @__PURE__ */ new Map();
9436
9336
  var layoutByKey = /* @__PURE__ */ new Map();
9337
+ var lineCountByKey = /* @__PURE__ */ new Map();
9437
9338
  var fragmentOffsetAdvancesByFragment = /* @__PURE__ */ new WeakMap();
9438
9339
  var graphemeOffsetsByText = /* @__PURE__ */ new Map();
9439
9340
  var measureCanvas;
@@ -9442,6 +9343,24 @@ var graphemeSegmenter;
9442
9343
  function canUsePretext() {
9443
9344
  return typeof OffscreenCanvas !== "undefined" || typeof document !== "undefined";
9444
9345
  }
9346
+ function getCachedValue(cache, key) {
9347
+ const cached = cache.get(key);
9348
+ if (cached === void 0) {
9349
+ return void 0;
9350
+ }
9351
+ cache.delete(key);
9352
+ cache.set(key, cached);
9353
+ return cached;
9354
+ }
9355
+ function trimCache(cache, maxEntries) {
9356
+ while (cache.size > maxEntries) {
9357
+ const firstKey = cache.keys().next().value;
9358
+ if (firstKey === void 0) {
9359
+ break;
9360
+ }
9361
+ cache.delete(firstKey);
9362
+ }
9363
+ }
9445
9364
  function getMeasureContext() {
9446
9365
  if (!canUsePretext()) {
9447
9366
  return void 0;
@@ -9628,7 +9547,7 @@ function prepareCached(text, font, wordBreak = "normal") {
9628
9547
  return void 0;
9629
9548
  }
9630
9549
  const cacheKey = `${font}\0${wordBreak}\0${text}`;
9631
- const cached = preparedTextByKey.get(cacheKey);
9550
+ const cached = getCachedValue(preparedTextByKey, cacheKey);
9632
9551
  if (cached) {
9633
9552
  return cached;
9634
9553
  }
@@ -9638,13 +9557,7 @@ function prepareCached(text, font, wordBreak = "normal") {
9638
9557
  wordBreak
9639
9558
  });
9640
9559
  preparedTextByKey.set(cacheKey, prepared);
9641
- while (preparedTextByKey.size > PREPARED_TEXT_CACHE_MAX_ENTRIES) {
9642
- const firstKey = preparedTextByKey.keys().next().value;
9643
- if (!firstKey) {
9644
- break;
9645
- }
9646
- preparedTextByKey.delete(firstKey);
9647
- }
9560
+ trimCache(preparedTextByKey, PREPARED_TEXT_CACHE_MAX_ENTRIES);
9648
9561
  return prepared;
9649
9562
  } catch {
9650
9563
  return void 0;
@@ -9655,13 +9568,21 @@ function measurePretextPlainTextLineCount(text, font, containerWidthPx, options)
9655
9568
  return 0;
9656
9569
  }
9657
9570
  const wordBreak = options?.wordBreak ?? "normal";
9571
+ const safeWidth = Math.max(1, Math.round(containerWidthPx));
9572
+ const cacheKey = `line-count\0${font}\0${wordBreak}\0${safeWidth}\0${text}`;
9573
+ const cached = getCachedValue(lineCountByKey, cacheKey);
9574
+ if (cached !== void 0) {
9575
+ return cached;
9576
+ }
9658
9577
  const prepared = prepareCached(text, font, wordBreak);
9659
9578
  if (!prepared) {
9660
9579
  return void 0;
9661
9580
  }
9662
9581
  try {
9663
- const safeWidth = Math.max(1, Math.round(containerWidthPx));
9664
- return (0, import_pretext.measureLineStats)(prepared, safeWidth).lineCount;
9582
+ const lineCount = (0, import_pretext.measureLineStats)(prepared, safeWidth).lineCount;
9583
+ lineCountByKey.set(cacheKey, lineCount);
9584
+ trimCache(lineCountByKey, LINE_COUNT_CACHE_MAX_ENTRIES);
9585
+ return lineCount;
9665
9586
  } catch {
9666
9587
  return void 0;
9667
9588
  }
@@ -9921,7 +9842,7 @@ function layoutTextWithPretextAroundExclusions(text, font, containerWidthPx, lin
9921
9842
  safeLineHeightPx,
9922
9843
  normalizedExclusions
9923
9844
  );
9924
- const cachedLayout = layoutByKey.get(cacheKey);
9845
+ const cachedLayout = getCachedValue(layoutByKey, cacheKey);
9925
9846
  if (cachedLayout) {
9926
9847
  return cachedLayout;
9927
9848
  }
@@ -9995,13 +9916,7 @@ function layoutTextWithPretextAroundExclusions(text, font, containerWidthPx, lin
9995
9916
  exclusions: normalizedExclusions
9996
9917
  };
9997
9918
  layoutByKey.set(cacheKey, nextLayout);
9998
- while (layoutByKey.size > LAYOUT_CACHE_MAX_ENTRIES) {
9999
- const firstKey = layoutByKey.keys().next().value;
10000
- if (!firstKey) {
10001
- break;
10002
- }
10003
- layoutByKey.delete(firstKey);
10004
- }
9919
+ trimCache(layoutByKey, LAYOUT_CACHE_MAX_ENTRIES);
10005
9920
  return nextLayout;
10006
9921
  }
10007
9922
  function layoutItemsWithPretextAroundExclusions(text, items, containerWidthPx, lineHeightPx, exclusions, fallbackFont) {
@@ -10053,7 +9968,7 @@ function layoutItemsWithPretextAroundExclusions(text, items, containerWidthPx, l
10053
9968
  safeLineHeightPx,
10054
9969
  normalizedExclusions
10055
9970
  );
10056
- const cachedLayout = layoutByKey.get(cacheKey);
9971
+ const cachedLayout = getCachedValue(layoutByKey, cacheKey);
10057
9972
  if (cachedLayout) {
10058
9973
  return cachedLayout;
10059
9974
  }
@@ -10167,13 +10082,7 @@ function layoutItemsWithPretextAroundExclusions(text, items, containerWidthPx, l
10167
10082
  exclusions: normalizedExclusions
10168
10083
  };
10169
10084
  layoutByKey.set(cacheKey, nextLayout);
10170
- while (layoutByKey.size > LAYOUT_CACHE_MAX_ENTRIES) {
10171
- const firstKey = layoutByKey.keys().next().value;
10172
- if (!firstKey) {
10173
- break;
10174
- }
10175
- layoutByKey.delete(firstKey);
10176
- }
10085
+ trimCache(layoutByKey, LAYOUT_CACHE_MAX_ENTRIES);
10177
10086
  return nextLayout;
10178
10087
  }
10179
10088
  function resolveOffsetAtPoint(layout, x, y) {
@@ -10466,6 +10375,8 @@ var INITIAL_PAGINATION_PAGE_COUNT_OSCILLATION_DISTINCT_THRESHOLD = 2;
10466
10375
  var INITIAL_PAGINATION_PAGE_COUNT_OSCILLATION_CHANGE_THRESHOLD = 4;
10467
10376
  var INITIAL_PAGINATION_BACKGROUND_REFINEMENT_DELAY_MS = 96;
10468
10377
  var DEFAULT_PAGE_VIRTUALIZATION_OVERSCAN = 2;
10378
+ var LARGE_TABLE_PAGE_VIRTUALIZATION_OVERSCAN = 0;
10379
+ var LARGE_TABLE_PAGE_ADJACENT_RENDER_COUNT = 1;
10469
10380
  var DEFAULT_PAGE_VIRTUALIZATION_SETTLE_DELAY_MS = 350;
10470
10381
  var ENABLE_TABLE_ROW_SLICING = true;
10471
10382
  var TOP_AND_BOTTOM_VERTICAL_DRAG_SNAP_PX = 10;
@@ -15303,12 +15214,37 @@ function estimateTabLeaderWrappedLineCountForParagraph(paragraph, maxLineWidthPx
15303
15214
  paragraphBaseFontPx
15304
15215
  );
15305
15216
  }
15217
+ var wrappedLineCountByParagraph = /* @__PURE__ */ new WeakMap();
15218
+ function cachedWrappedLineCountForParagraph(paragraph, widthPx) {
15219
+ return wrappedLineCountByParagraph.get(paragraph)?.get(widthPx);
15220
+ }
15221
+ function rememberWrappedLineCountForParagraph(paragraph, widthPx, lineCount) {
15222
+ let countsByWidth = wrappedLineCountByParagraph.get(paragraph);
15223
+ if (!countsByWidth) {
15224
+ countsByWidth = /* @__PURE__ */ new Map();
15225
+ wrappedLineCountByParagraph.set(paragraph, countsByWidth);
15226
+ }
15227
+ countsByWidth.set(widthPx, lineCount);
15228
+ return lineCount;
15229
+ }
15306
15230
  function estimateWrappedLineCountForParagraph(paragraph, availableWidthPx) {
15307
15231
  const paragraphBaseFontPx = paragraphBaseFontSizePx(paragraph);
15308
15232
  const maxLineWidthPx = Math.max(
15309
15233
  paragraphBaseFontPx * 2,
15310
15234
  Math.round(availableWidthPx)
15311
15235
  );
15236
+ const cachedLineCount = cachedWrappedLineCountForParagraph(
15237
+ paragraph,
15238
+ maxLineWidthPx
15239
+ );
15240
+ if (cachedLineCount !== void 0) {
15241
+ return cachedLineCount;
15242
+ }
15243
+ const rememberLineCount = (lineCount2) => rememberWrappedLineCountForParagraph(
15244
+ paragraph,
15245
+ maxLineWidthPx,
15246
+ Math.max(1, Math.round(lineCount2))
15247
+ );
15312
15248
  const tabStopsPx = resolveParagraphTabStopsPx(paragraph);
15313
15249
  const useTabLeaderLayout = paragraphUsesTabLeaders(paragraph);
15314
15250
  const anchoredTabLayout = paragraphAnchoredTabLayout(paragraph);
@@ -15349,7 +15285,7 @@ function estimateWrappedLineCountForParagraph(paragraph, availableWidthPx) {
15349
15285
  return layout?.lineCount;
15350
15286
  })();
15351
15287
  if (pretextPlainLineCount) {
15352
- return Math.max(1, pretextPlainLineCount);
15288
+ return rememberLineCount(pretextPlainLineCount);
15353
15289
  }
15354
15290
  }
15355
15291
  if (useTabLeaderLayout) {
@@ -15359,7 +15295,7 @@ function estimateWrappedLineCountForParagraph(paragraph, availableWidthPx) {
15359
15295
  paragraphBaseFontPx
15360
15296
  );
15361
15297
  if (tabLeaderLineCount !== void 0) {
15362
- return tabLeaderLineCount;
15298
+ return rememberLineCount(tabLeaderLineCount);
15363
15299
  }
15364
15300
  }
15365
15301
  let lineCount = 1;
@@ -15477,7 +15413,7 @@ function estimateWrappedLineCountForParagraph(paragraph, availableWidthPx) {
15477
15413
  commitToken(token, child.style);
15478
15414
  }
15479
15415
  }
15480
- return hasVisibleContent ? Math.max(1, lineCount) : 1;
15416
+ return rememberLineCount(hasVisibleContent ? lineCount : 1);
15481
15417
  }
15482
15418
  function paragraphAvailableTextWidthPx(paragraph, availableWidthPx, numberingDefinitions) {
15483
15419
  const safeAvailableWidthPx = Math.max(24, Math.round(availableWidthPx));
@@ -24427,7 +24363,7 @@ function useDocxEditor(options = {}) {
24427
24363
  const [status, setStatus] = React.useState(
24428
24364
  options.initialStatus ?? "Ready"
24429
24365
  );
24430
- const [isImporting, setIsImporting] = React.useState(false);
24366
+ const isImporting = false;
24431
24367
  const [documentTheme, setDocumentThemeState] = React.useState(options.initialDocumentTheme ?? "light");
24432
24368
  const [showTrackedChanges, setShowTrackedChangesState] = React.useState(options.initialShowTrackedChanges ?? false);
24433
24369
  const [paginationInfo, setPaginationInfo] = React.useState({
@@ -24950,40 +24886,26 @@ function useDocxEditor(options = {}) {
24950
24886
  setStatus("Only .docx files are supported");
24951
24887
  return;
24952
24888
  }
24953
- setIsImporting(true);
24954
- setStatus(`Loading ${file.name}\u2026`);
24955
- await new Promise((resolve) => {
24956
- if (typeof requestAnimationFrame === "function") {
24957
- requestAnimationFrame(() => {
24958
- requestAnimationFrame(() => resolve());
24959
- });
24960
- } else {
24961
- setTimeout(resolve, 0);
24962
- }
24963
- });
24964
24889
  try {
24965
24890
  const buffer = await file.arrayBuffer();
24966
- const { pkg, model: nextModel } = await importDocxViaWorker(buffer);
24891
+ const pkg = await parseDocx(buffer);
24967
24892
  await loadEmbeddedFontsFromPackage(pkg);
24968
- React.startTransition(() => {
24969
- setModel(nextModel);
24970
- setDocumentLoadNonce((current) => current + 1);
24971
- setHistory({ past: [], future: [] });
24972
- setHistoryRestoreRequest(void 0);
24973
- setBasePackage(pkg);
24974
- setFileName(file.name);
24975
- setSelection({ kind: "paragraph", nodeIndex: 0 });
24976
- setActiveTextRangeState(void 0);
24977
- setPendingRunStyle(void 0);
24978
- setSelectedFormFieldLocation(void 0);
24979
- });
24893
+ const nextModel = buildDocModel(pkg);
24894
+ setModel(nextModel);
24895
+ setDocumentLoadNonce((current) => current + 1);
24896
+ setHistory({ past: [], future: [] });
24897
+ setHistoryRestoreRequest(void 0);
24898
+ setBasePackage(pkg);
24899
+ setFileName(file.name);
24900
+ setSelection({ kind: "paragraph", nodeIndex: 0 });
24901
+ setActiveTextRangeState(void 0);
24902
+ setPendingRunStyle(void 0);
24903
+ setSelectedFormFieldLocation(void 0);
24980
24904
  setStatus(`Loaded ${file.name}`);
24981
24905
  } catch (error) {
24982
24906
  setStatus(
24983
24907
  `Failed to load file: ${error instanceof Error ? error.message : "Unknown error"}`
24984
24908
  );
24985
- } finally {
24986
- setIsImporting(false);
24987
24909
  }
24988
24910
  },
24989
24911
  [loadEmbeddedFontsFromPackage]
@@ -30782,7 +30704,7 @@ function DocxEditorViewer({
30782
30704
  Number.isFinite(pageVirtualization?.overscan) ? pageVirtualization?.overscan : DEFAULT_PAGE_VIRTUALIZATION_OVERSCAN
30783
30705
  )
30784
30706
  );
30785
- const pageVirtualizationOverscan = hasLargeTableLayoutSurface && !Number.isFinite(pageVirtualization?.overscan) ? 0 : rawPageVirtualizationOverscan;
30707
+ const pageVirtualizationOverscan = hasLargeTableLayoutSurface && !Number.isFinite(pageVirtualization?.overscan) ? LARGE_TABLE_PAGE_VIRTUALIZATION_OVERSCAN : rawPageVirtualizationOverscan;
30786
30708
  const webdriverActive = typeof navigator !== "undefined" && navigator.webdriver === true;
30787
30709
  const internalPageVirtualizationRequested = pageVirtualization?.enabled !== false && !hasExternalVisiblePageRange && !hideDocumentUntilPaginationSettled && isInitialPaginationSettled && !deferInternalPageVirtualization && !webdriverActive && pageCount > 1;
30788
30710
  React.useEffect(() => {
@@ -30877,8 +30799,39 @@ function DocxEditorViewer({
30877
30799
  endPageIndex
30878
30800
  };
30879
30801
  }, [internalPageVirtualizationEnabled, internalVirtualItems, pageCount]);
30802
+ const internalRenderVisiblePageRange = React.useMemo(() => {
30803
+ if (!internalVisiblePageRange) {
30804
+ return void 0;
30805
+ }
30806
+ if (!hasLargeTableLayoutSurface || Number.isFinite(pageVirtualization?.overscan)) {
30807
+ return internalVisiblePageRange;
30808
+ }
30809
+ const scrollDirection = internalPageVirtualizer.scrollDirection;
30810
+ const renderPreviousPage = scrollDirection !== "backward";
30811
+ const renderNextPage = scrollDirection === "backward";
30812
+ const startPageIndex = clampNumber(
30813
+ internalVisiblePageRange.startPageIndex - (renderPreviousPage ? LARGE_TABLE_PAGE_ADJACENT_RENDER_COUNT : 0),
30814
+ 0,
30815
+ pageCount - 1
30816
+ );
30817
+ const endPageIndex = clampNumber(
30818
+ internalVisiblePageRange.endPageIndex + (renderNextPage ? LARGE_TABLE_PAGE_ADJACENT_RENDER_COUNT : 0),
30819
+ startPageIndex,
30820
+ pageCount - 1
30821
+ );
30822
+ return {
30823
+ startPageIndex,
30824
+ endPageIndex
30825
+ };
30826
+ }, [
30827
+ hasLargeTableLayoutSurface,
30828
+ internalPageVirtualizer.scrollDirection,
30829
+ internalVisiblePageRange,
30830
+ pageCount,
30831
+ pageVirtualization?.overscan
30832
+ ]);
30880
30833
  React.useLayoutEffect(() => {
30881
- if (!internalPageVirtualizationEnabled || !internalVirtualScrollElement || typeof window === "undefined") {
30834
+ if (!internalPageVirtualizationEnabled || !internalVirtualScrollElement || internalVirtualItems.length > 0 || typeof window === "undefined") {
30882
30835
  setObservedVisiblePageRange(
30883
30836
  (current) => current === void 0 ? current : void 0
30884
30837
  );
@@ -30993,12 +30946,13 @@ function DocxEditorViewer({
30993
30946
  };
30994
30947
  }, [
30995
30948
  internalPageVirtualizationEnabled,
30949
+ internalVirtualItems.length,
30996
30950
  internalVirtualScrollElement,
30997
30951
  internalVirtualScrollUsesWindow,
30998
30952
  pageCount,
30999
30953
  pageVirtualizationOverscan
31000
30954
  ]);
31001
- const effectiveVisiblePageRange = visiblePageRange ?? observedVisiblePageRange ?? internalVisiblePageRange ?? (internalPageVirtualizationPending ? {
30955
+ const effectiveVisiblePageRange = visiblePageRange ?? internalRenderVisiblePageRange ?? observedVisiblePageRange ?? (internalPageVirtualizationPending ? {
31002
30956
  startPageIndex: 0,
31003
30957
  endPageIndex: Math.min(
31004
30958
  pageCount - 1,
@@ -31186,7 +31140,13 @@ function DocxEditorViewer({
31186
31140
  rootElement.querySelectorAll(
31187
31141
  '[data-docx-page-wrapper="true"][data-index]'
31188
31142
  )
31189
- );
31143
+ ).filter((element) => {
31144
+ const pageIndex = Number.parseInt(
31145
+ element.getAttribute("data-index") ?? "",
31146
+ 10
31147
+ );
31148
+ return Number.isFinite(pageIndex) && pageIndex >= visiblePageStartIndex && pageIndex <= visiblePageEndIndex;
31149
+ });
31190
31150
  const nextElements = new Set(pageWrappers);
31191
31151
  observedElements.forEach((element) => {
31192
31152
  if (!nextElements.has(element)) {
@@ -31222,7 +31182,9 @@ function DocxEditorViewer({
31222
31182
  internalPageVirtualizationEnabled,
31223
31183
  internalPageVirtualizer,
31224
31184
  internalVirtualScrollElement,
31225
- pageCount
31185
+ pageCount,
31186
+ visiblePageEndIndex,
31187
+ visiblePageStartIndex
31226
31188
  ]);
31227
31189
  React.useEffect(() => {
31228
31190
  if (!internalPageVirtualizationEnabled) {
@@ -31735,11 +31697,18 @@ function DocxEditorViewer({
31735
31697
  const nextMeasuredPageDiagnostics = pageNodeSegmentsByPage.map(
31736
31698
  (_, pageIndex) => {
31737
31699
  const pageLayout = pageSectionInfoByIndex[pageIndex]?.layout ?? documentLayout;
31738
- const pageElement = pageElementsRef.current.get(pageIndex);
31739
31700
  const fallbackHeightPx = Math.max(
31740
31701
  120,
31741
31702
  pageLayout.pageHeightPx - pageLayout.marginsPx.top - pageLayout.marginsPx.bottom
31742
31703
  );
31704
+ const pageIsVisible = pageIndex >= visiblePageStartIndex && pageIndex <= visiblePageEndIndex;
31705
+ if (!pageIsVisible) {
31706
+ return {
31707
+ heightPx: measuredPageContentHeightByIndex?.[pageIndex] ?? fallbackHeightPx,
31708
+ bodyOverrunsFooter: false
31709
+ };
31710
+ }
31711
+ const pageElement = pageElementsRef.current.get(pageIndex);
31743
31712
  if (!pageElement) {
31744
31713
  return {
31745
31714
  heightPx: fallbackHeightPx,
@@ -31932,7 +31901,9 @@ function DocxEditorViewer({
31932
31901
  pageNodeSegmentsByPage,
31933
31902
  pageNodeSegmentIdentityKeysByPage,
31934
31903
  pageSectionInfoByIndex,
31935
- pageHeaderAndFooterNodes
31904
+ pageHeaderAndFooterNodes,
31905
+ visiblePageEndIndex,
31906
+ visiblePageStartIndex
31936
31907
  ]);
31937
31908
  React.useEffect(() => {
31938
31909
  if (!deferInitialPaginationPaint || isInitialPaginationSettled || disableMeasuredImportPagination) {