({
mousemoveCb,
sampling,
doc,
mirror,
}: observerParam)
| 104 | } |
| 105 | |
| 106 | function initMoveObserver({ |
| 107 | mousemoveCb, |
| 108 | sampling, |
| 109 | doc, |
| 110 | mirror, |
| 111 | }: observerParam): listenerHandler { |
| 112 | if (sampling.mousemove === false) { |
| 113 | return () => { |
| 114 | // |
| 115 | }; |
| 116 | } |
| 117 | |
| 118 | const threshold = |
| 119 | typeof sampling.mousemove === 'number' ? sampling.mousemove : 50; |
| 120 | const callbackThreshold = |
| 121 | typeof sampling.mousemoveCallback === 'number' |
| 122 | ? sampling.mousemoveCallback |
| 123 | : 500; |
| 124 | |
| 125 | let positions: mousePosition[] = []; |
| 126 | let timeBaseline: number | null; |
| 127 | const wrappedCb = throttle( |
| 128 | callbackWrapper( |
| 129 | ( |
| 130 | source: |
| 131 | | IncrementalSource.MouseMove |
| 132 | | IncrementalSource.TouchMove |
| 133 | | IncrementalSource.Drag, |
| 134 | ) => { |
| 135 | const totalOffset = Date.now() - timeBaseline!; |
| 136 | mousemoveCb( |
| 137 | positions.map((p) => { |
| 138 | p.timeOffset -= totalOffset; |
| 139 | return p; |
| 140 | }), |
| 141 | source, |
| 142 | ); |
| 143 | positions = []; |
| 144 | timeBaseline = null; |
| 145 | }, |
| 146 | ), |
| 147 | callbackThreshold, |
| 148 | ); |
| 149 | const updatePosition = callbackWrapper( |
| 150 | throttle<MouseEvent | TouchEvent | DragEvent>( |
| 151 | callbackWrapper((evt) => { |
| 152 | const target = getEventTarget(evt); |
| 153 | // 'legacy' here as we could switch to https://developer.mozilla.org/en-US/docs/Web/API/Element/pointermove_event |
| 154 | const { clientX, clientY } = legacy_isTouchEvent(evt) |
| 155 | ? evt.changedTouches[0] |
| 156 | : evt; |
| 157 | if (!timeBaseline) { |
| 158 | timeBaseline = nowTimestamp(); |
| 159 | } |
| 160 | positions.push({ |
| 161 | x: clientX, |
| 162 | y: clientY, |
| 163 | id: mirror.getId(target as Node), |
no test coverage detected
searching dependent graphs…