| 204 | * aus diesem Modul sieht. |
| 205 | */ |
| 206 | const PROBE = (exclusions) => { |
| 207 | const excluded = (node) => exclusions.some((selector) => node.closest(selector) !== null); |
| 208 | |
| 209 | const identify = (node) => { |
| 210 | const testId = node.getAttribute('data-testid'); |
| 211 | if (testId !== null && testId.length > 0) { |
| 212 | return `[${testId}]`; |
| 213 | } |
| 214 | const classes = (node.getAttribute('class') ?? '').split(/\s+/).filter(Boolean); |
| 215 | return classes.length > 0 ? `.${classes[0]}` : node.tagName.toLowerCase(); |
| 216 | }; |
| 217 | |
| 218 | const path = (node) => { |
| 219 | const parts = []; |
| 220 | let current = node; |
| 221 | for (let i = 0; i < 4 && current !== null && current !== document.body; i += 1) { |
| 222 | parts.unshift(identify(current)); |
| 223 | current = current.parentElement; |
| 224 | } |
| 225 | return parts.join(' > '); |
| 226 | }; |
| 227 | |
| 228 | const ownText = (node) => { |
| 229 | let text = ''; |
| 230 | for (const child of node.childNodes) { |
| 231 | if (child.nodeType === Node.TEXT_NODE) { |
| 232 | text += child.nodeValue ?? ''; |
| 233 | } |
| 234 | } |
| 235 | return text.replace(/\s+/g, ' ').trim(); |
| 236 | }; |
| 237 | |
| 238 | const viewport = { width: window.innerWidth, height: window.innerHeight }; |
| 239 | const candidates = []; |
| 240 | const layerKeys = new Set(); |
| 241 | |
| 242 | /** |
| 243 | * Was von einem Rechteck nach allen Kaesten darueber uebrig bleibt. |
| 244 | * |
| 245 | * Jeder Vorfahre mit `overflow != visible` schneidet auf seiner Achse, und |
| 246 | * zuletzt schneidet das Fenster. Das Ergebnis ist die Flaeche, die ein |
| 247 | * Leser wirklich sieht. |
| 248 | */ |
| 249 | const visibleRectOf = (node) => { |
| 250 | const rect = node.getBoundingClientRect(); |
| 251 | let left = rect.left; |
| 252 | let top = rect.top; |
| 253 | let right = rect.right; |
| 254 | let bottom = rect.bottom; |
| 255 | for ( |
| 256 | let current = node.parentElement; |
| 257 | current !== null && current !== document.documentElement; |
| 258 | current = current.parentElement |
| 259 | ) { |
| 260 | const style = window.getComputedStyle(current); |
| 261 | if (style.overflowX === 'visible' && style.overflowY === 'visible') { |
| 262 | continue; |
| 263 | } |