@arbidocs/react 0.4.57 → 0.4.58

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.
@@ -478,6 +478,19 @@ function clipRange(range, container) {
478
478
  }
479
479
  return clipped;
480
480
  }
481
+ function textClientRects(range, container) {
482
+ const walker = document.createTreeWalker(container, NodeFilter.SHOW_TEXT);
483
+ const rects = [];
484
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
485
+ if (!node.textContent?.trim() || !range.intersectsNode(node)) continue;
486
+ const part = document.createRange();
487
+ part.selectNodeContents(node);
488
+ if (node === range.startContainer) part.setStart(node, range.startOffset);
489
+ if (node === range.endContainer) part.setEnd(node, range.endOffset);
490
+ rects.push(...Array.from(part.getClientRects()));
491
+ }
492
+ return rects;
493
+ }
481
494
  function readSelection(selection, root = document) {
482
495
  if (selection.rangeCount === 0 || selection.isCollapsed) return [];
483
496
  const range = selection.getRangeAt(0);
@@ -491,7 +504,7 @@ function readSelection(selection, root = document) {
491
504
  pages.push({
492
505
  page,
493
506
  box: toPixelRect(overlay.getBoundingClientRect()),
494
- rects: Array.from(clipped.getClientRects(), toPixelRect),
507
+ rects: textClientRects(clipped, container).map(toPixelRect),
495
508
  text: clipped.toString()
496
509
  });
497
510
  });
@@ -501,9 +514,9 @@ function readSelection(selection, root = document) {
501
514
  // src/annotations/useTextSelectionMarks.ts
502
515
  var PAGE_SELECTOR = "[data-page-number]";
503
516
  var TOUCH_SETTLE_MS = 700;
504
- var MOUSE_SETTLE_MS = 60;
505
- var STABLE_CHECKS = 2;
506
- var MAX_SETTLE_ROUNDS = 10;
517
+ var MOUSE_SETTLE_MS = 80;
518
+ var STABLE_CHECKS = 3;
519
+ var MAX_SETTLE_ROUNDS = 12;
507
520
  function useTextSelectionMarks(controller) {
508
521
  const latest = useRef(controller);
509
522
  latest.current = controller;