* Collect CSS classes from an element and its ancestors
(element: HTMLElement, maxDepth = 10)
| 249 | * Collect CSS classes from an element and its ancestors |
| 250 | */ |
| 251 | function getAncestorClasses(element: HTMLElement, maxDepth = 10): Set<string> { |
| 252 | const classes = new Set<string>(); |
| 253 | let current: HTMLElement | null = element; |
| 254 | let depth = 0; |
| 255 | |
| 256 | while (current && depth < maxDepth) { |
| 257 | if (current.className && typeof current.className === "string") { |
| 258 | current.className.split(/\s+/).forEach((cls) => { |
| 259 | if (cls.length > 1) { |
| 260 | // Normalize: remove CSS module hashes, convert to lowercase |
| 261 | const normalized = cls |
| 262 | .replace(/[_][a-zA-Z0-9]{5,}.*$/, "") |
| 263 | .toLowerCase(); |
| 264 | if (normalized.length > 1) { |
| 265 | classes.add(normalized); |
| 266 | } |
| 267 | } |
| 268 | }); |
| 269 | } |
| 270 | current = current.parentElement; |
| 271 | depth++; |
| 272 | } |
| 273 | |
| 274 | return classes; |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * Check if a component name correlates with any DOM class |
no outgoing calls
no test coverage detected
searching dependent graphs…