@extend-ai/react-docx 0.7.0-alpha.5 → 0.7.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -5235,6 +5235,10 @@ function resolveEffectiveZoomScale(element) {
5235
5235
  }
5236
5236
  return Number.isFinite(scale) && scale > 0 ? scale : 1;
5237
5237
  }
5238
+ function normalizePageVirtualizationZoomScale(value) {
5239
+ const scale = Number(value);
5240
+ return Number.isFinite(scale) && scale > 0 ? scale : void 0;
5241
+ }
5238
5242
  var DOC_SURFACE_STYLE_BY_THEME = {
5239
5243
  light: {
5240
5244
  backgroundColor: "#ffffff",
@@ -26643,6 +26647,17 @@ function DocxEditorViewer({
26643
26647
  const pageVirtualizationOverscan = hasLargeTableLayoutSurface && !Number.isFinite(pageVirtualization?.overscan) ? LARGE_TABLE_PAGE_VIRTUALIZATION_OVERSCAN : rawPageVirtualizationOverscan;
26644
26648
  const webdriverActive = typeof navigator !== "undefined" && navigator.webdriver === true;
26645
26649
  const internalPageVirtualizationRequested = pageVirtualization?.enabled !== false && !hasExternalVisiblePageRange && !hideDocumentUntilPaginationSettled && isInitialPaginationSettled && !deferInternalPageVirtualization && !webdriverActive && pageCount > 1;
26650
+ const explicitPageVirtualizationScrollElement = pageVirtualization?.scrollElement ?? null;
26651
+ const explicitPageVirtualizationZoomScale = normalizePageVirtualizationZoomScale(pageVirtualization?.zoomScale);
26652
+ const resolveViewerMeasurementZoomScale = React.useCallback(
26653
+ (rootElement, fallback = 1) => {
26654
+ if (explicitPageVirtualizationZoomScale !== void 0) {
26655
+ return explicitPageVirtualizationZoomScale;
26656
+ }
26657
+ return rootElement ? resolveEffectiveZoomScale(rootElement) : fallback;
26658
+ },
26659
+ [explicitPageVirtualizationZoomScale]
26660
+ );
26646
26661
  React.useEffect(() => {
26647
26662
  setDeferInternalPageVirtualization(!hasLargeTableLayoutSurface);
26648
26663
  }, [editor.documentLoadNonce, hasLargeTableLayoutSurface]);
@@ -26673,9 +26688,14 @@ function DocxEditorViewer({
26673
26688
  return;
26674
26689
  }
26675
26690
  setInternalVirtualScrollElement(
26676
- nearestScrollableAncestor(viewerRootRef.current)
26691
+ explicitPageVirtualizationScrollElement instanceof HTMLElement ? explicitPageVirtualizationScrollElement : nearestScrollableAncestor(viewerRootRef.current)
26677
26692
  );
26678
- }, [editor.documentLoadNonce, pageCount, trackedChangesEnabled]);
26693
+ }, [
26694
+ editor.documentLoadNonce,
26695
+ explicitPageVirtualizationScrollElement,
26696
+ pageCount,
26697
+ trackedChangesEnabled
26698
+ ]);
26679
26699
  const [zoomProbeNonce, setZoomProbeNonce] = React.useState(0);
26680
26700
  React.useEffect(() => {
26681
26701
  if (typeof window === "undefined") {
@@ -26704,11 +26724,22 @@ function DocxEditorViewer({
26704
26724
  if (!rootElement) {
26705
26725
  return;
26706
26726
  }
26707
- const nextScale = Math.round(resolveEffectiveZoomScale(rootElement) * 100) / 100;
26727
+ const nextScale = Math.round(
26728
+ resolveViewerMeasurementZoomScale(
26729
+ rootElement,
26730
+ virtualizerMeasurementScale
26731
+ ) * 100
26732
+ ) / 100;
26708
26733
  setVirtualizerMeasurementScale(
26709
26734
  (current) => Math.abs(current - nextScale) < 5e-3 ? current : nextScale
26710
26735
  );
26711
- }, [editor.documentLoadNonce, pageCount, zoomProbeNonce]);
26736
+ }, [
26737
+ editor.documentLoadNonce,
26738
+ pageCount,
26739
+ resolveViewerMeasurementZoomScale,
26740
+ virtualizerMeasurementScale,
26741
+ zoomProbeNonce
26742
+ ]);
26712
26743
  const internalPageVirtualizationEnabled = internalPageVirtualizationRequested && internalVirtualScrollElement !== null;
26713
26744
  const internalPageVirtualizationPending = typeof window !== "undefined" && internalPageVirtualizationRequested && internalVirtualScrollElement === null;
26714
26745
  const internalVirtualScrollUsesWindow = typeof document !== "undefined" && internalVirtualScrollElement !== null && (internalVirtualScrollElement === document.scrollingElement || internalVirtualScrollElement === document.documentElement || internalVirtualScrollElement === document.body);
@@ -27110,7 +27141,7 @@ function DocxEditorViewer({
27110
27141
  const next = new Map(current);
27111
27142
  let changed = false;
27112
27143
  const rootElement = viewerRootRef.current;
27113
- const zoomScale = rootElement ? resolveEffectiveZoomScale(rootElement) : 1;
27144
+ const zoomScale = resolveViewerMeasurementZoomScale(rootElement, 1);
27114
27145
  paragraphElementsRef.current.forEach((element, nodeIndex) => {
27115
27146
  if (!element.isConnected || element.dataset.docxParagraphPartialLineRange === "true" || element.closest('[data-docx-header-footer-region="footer"]') || element.closest('[data-docx-header-footer-region="header"]')) {
27116
27147
  return;
@@ -27139,6 +27170,7 @@ function DocxEditorViewer({
27139
27170
  }, [
27140
27171
  editor.documentLoadNonce,
27141
27172
  pageNodeSegmentIdentityKeysByPage,
27173
+ resolveViewerMeasurementZoomScale,
27142
27174
  visiblePageEndIndex,
27143
27175
  visiblePageStartIndex
27144
27176
  ]);
@@ -27660,7 +27692,7 @@ function DocxEditorViewer({
27660
27692
  );
27661
27693
  return;
27662
27694
  }
27663
- const zoomScale = resolveEffectiveZoomScale(rootElement);
27695
+ const zoomScale = resolveViewerMeasurementZoomScale(rootElement, 1);
27664
27696
  const next = {};
27665
27697
  for (let pageIndex = 0; pageIndex < pageCount; pageIndex += 1) {
27666
27698
  if (!isPageVisible(pageIndex)) {
@@ -27747,6 +27779,7 @@ function DocxEditorViewer({
27747
27779
  pageCount,
27748
27780
  pageHeaderAndFooterNodes,
27749
27781
  pageSectionInfoByIndex,
27782
+ resolveViewerMeasurementZoomScale,
27750
27783
  visiblePageEndIndex,
27751
27784
  visiblePageStartIndex
27752
27785
  ]);
@@ -27776,7 +27809,7 @@ function DocxEditorViewer({
27776
27809
  if (Date.now() < paginationMeasurementSuspendUntilRef.current) {
27777
27810
  return;
27778
27811
  }
27779
- const zoomScale = resolveEffectiveZoomScale(rootElement);
27812
+ const zoomScale = resolveViewerMeasurementZoomScale(rootElement, 1);
27780
27813
  const nextMeasuredPageIdentityKeys = pageNodeSegmentIdentityKeysByPage;
27781
27814
  const nextMeasuredPageDiagnostics = pageNodeSegmentsByPage.map(
27782
27815
  (_, pageIndex) => {
@@ -27991,6 +28024,7 @@ function DocxEditorViewer({
27991
28024
  pageNodeSegmentIdentityKeysByPage,
27992
28025
  pageSectionInfoByIndex,
27993
28026
  pageHeaderAndFooterNodes,
28027
+ resolveViewerMeasurementZoomScale,
27994
28028
  visiblePageEndIndex,
27995
28029
  visiblePageStartIndex
27996
28030
  ]);
@@ -32425,7 +32459,10 @@ function DocxEditorViewer({
32425
32459
  return;
32426
32460
  }
32427
32461
  const rootElement = viewerRootRef.current;
32428
- const zoomScale = rootElement ? resolveEffectiveZoomScale(rootElement) : virtualizerMeasurementScale;
32462
+ const zoomScale = resolveViewerMeasurementZoomScale(
32463
+ rootElement,
32464
+ virtualizerMeasurementScale
32465
+ );
32429
32466
  const nextMeasuredHeights = {};
32430
32467
  editor.model.nodes.forEach((node, nodeIndex) => {
32431
32468
  if (node.type !== "table") {
@@ -32567,6 +32604,7 @@ function DocxEditorViewer({
32567
32604
  pageContentWidthPxByNodeIndex,
32568
32605
  paginationMeasurementEnabled,
32569
32606
  paginationMeasurementEpoch,
32607
+ resolveViewerMeasurementZoomScale,
32570
32608
  tableMeasuredRowHeights,
32571
32609
  tableColumnWidths,
32572
32610
  tableRowHeights,