()
| 84 | }; |
| 85 | |
| 86 | const tick = () => { |
| 87 | if (performance.now() >= deadline) { |
| 88 | stop(); |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | const element = commentRef.current; |
| 93 | if (element && containerRef.current?.contains(element)) { |
| 94 | if (target !== element) { |
| 95 | target = element; |
| 96 | scrollParent = getScrollParent(element); |
| 97 | anchor = undefined; |
| 98 | } |
| 99 | |
| 100 | const position = measure(element); |
| 101 | const previousPosition = anchor; |
| 102 | if ( |
| 103 | !previousPosition || |
| 104 | position.some( |
| 105 | (value, index) => |
| 106 | Math.abs(value - previousPosition[index]) > POSITION_TOLERANCE, |
| 107 | ) |
| 108 | ) { |
| 109 | element.scrollIntoView({ |
| 110 | behavior: 'instant', |
| 111 | block: 'center', |
| 112 | inline: 'nearest', |
| 113 | }); |
| 114 | anchor = measure(element); |
| 115 | stableFrames = 0; |
| 116 | } else { |
| 117 | stableFrames += 1; |
| 118 | } |
| 119 | |
| 120 | if ( |
| 121 | stableFrames >= STABLE_FRAMES && |
| 122 | performance.now() - startedAt >= MIN_SETTLE_MS |
| 123 | ) { |
| 124 | stop(); |
| 125 | return; |
| 126 | } |
| 127 | } else { |
| 128 | anchor = undefined; |
| 129 | stableFrames = 0; |
| 130 | } |
| 131 | |
| 132 | frame = requestAnimationFrame(tick); |
| 133 | }; |
| 134 | |
| 135 | window.addEventListener('wheel', stop, { passive: true }); |
| 136 | window.addEventListener('touchmove', stop, { passive: true }); |
nothing calls this directly
no test coverage detected