react-pdf-highlighter-plus 1.3.0 → 1.3.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/esm/index.js CHANGED
@@ -1538,13 +1538,13 @@ var PdfHighlighter = ({
1538
1538
  })
1539
1539
  );
1540
1540
  const resizeObserverRef = useRef(null);
1541
- const lastContainerSizeRef = useRef(null);
1542
1541
  const renderRetryTimeoutsRef = useRef(
1543
1542
  []
1544
1543
  );
1545
1544
  const resumeScrollAwayTimeoutRef = useRef(
1546
1545
  null
1547
1546
  );
1547
+ const settleScrollListenerRef = useRef(null);
1548
1548
  const findControllerRef = useRef(null);
1549
1549
  const viewerRef = useRef(null);
1550
1550
  const selectedHighlightCountRef = useRef(0);
@@ -1618,13 +1618,8 @@ var PdfHighlighter = ({
1618
1618
  }, [pdfDocument, recolorKey]);
1619
1619
  useLayoutEffect(() => {
1620
1620
  if (!containerNodeRef.current) return;
1621
- resizeObserverRef.current = new ResizeObserver((entries) => {
1622
- const rect = entries[entries.length - 1]?.contentRect;
1623
- if (!rect) return;
1624
- const last = lastContainerSizeRef.current;
1625
- if (last && last.w === rect.width && last.h === rect.height) return;
1626
- lastContainerSizeRef.current = { w: rect.width, h: rect.height };
1627
- if (last) handleScaleValueRef.current();
1621
+ resizeObserverRef.current = new ResizeObserver(() => {
1622
+ handleScaleValueRef.current();
1628
1623
  });
1629
1624
  resizeObserverRef.current.observe(containerNodeRef.current);
1630
1625
  const doc = containerNodeRef.current.ownerDocument;
@@ -1632,6 +1627,9 @@ var PdfHighlighter = ({
1632
1627
  eventBusRef.current.on("textlayerrendered", handlePageRendered);
1633
1628
  eventBusRef.current.on("pagerendered", handlePageRendered);
1634
1629
  eventBusRef.current.on("pagesinit", handleScaleValue);
1630
+ if (scrolledToHighlightIdRef.current) {
1631
+ resumeScrollAwayListenerAfterNavigation();
1632
+ }
1635
1633
  doc.addEventListener("keydown", handleKeyDown);
1636
1634
  doc.addEventListener("copy", handleCopy, true);
1637
1635
  scheduleRenderHighlightLayers();
@@ -1648,6 +1646,13 @@ var PdfHighlighter = ({
1648
1646
  clearTimeout(resumeScrollAwayTimeoutRef.current);
1649
1647
  resumeScrollAwayTimeoutRef.current = null;
1650
1648
  }
1649
+ if (settleScrollListenerRef.current) {
1650
+ viewerRef.current?.container.removeEventListener(
1651
+ "scroll",
1652
+ settleScrollListenerRef.current
1653
+ );
1654
+ settleScrollListenerRef.current = null;
1655
+ }
1651
1656
  };
1652
1657
  }, [selectionTip, highlights, onSelectionFinished]);
1653
1658
  useEffect(() => {
@@ -2097,13 +2102,27 @@ var PdfHighlighter = ({
2097
2102
  if (!container) return;
2098
2103
  if (resumeScrollAwayTimeoutRef.current) {
2099
2104
  clearTimeout(resumeScrollAwayTimeoutRef.current);
2100
- }
2101
- resumeScrollAwayTimeoutRef.current = setTimeout(() => {
2102
- container.addEventListener("scroll", handleScroll, {
2103
- once: true
2104
- });
2105
2105
  resumeScrollAwayTimeoutRef.current = null;
2106
- }, 1200);
2106
+ }
2107
+ if (settleScrollListenerRef.current) {
2108
+ container.removeEventListener("scroll", settleScrollListenerRef.current);
2109
+ settleScrollListenerRef.current = null;
2110
+ }
2111
+ const QUIET_MS = 150;
2112
+ const onSettleTick = () => {
2113
+ if (resumeScrollAwayTimeoutRef.current) {
2114
+ clearTimeout(resumeScrollAwayTimeoutRef.current);
2115
+ }
2116
+ resumeScrollAwayTimeoutRef.current = setTimeout(() => {
2117
+ container.removeEventListener("scroll", onSettleTick);
2118
+ settleScrollListenerRef.current = null;
2119
+ container.addEventListener("scroll", handleScroll, { once: true });
2120
+ resumeScrollAwayTimeoutRef.current = null;
2121
+ }, QUIET_MS);
2122
+ };
2123
+ settleScrollListenerRef.current = onSettleTick;
2124
+ container.addEventListener("scroll", onSettleTick);
2125
+ onSettleTick();
2107
2126
  };
2108
2127
  const isEditingOrHighlighting = () => {
2109
2128
  return Boolean(selectionRef.current) || Boolean(ghostHighlightRef.current) || isAreaSelectionInProgressRef.current || isEditInProgressRef.current;