MCPcopy
hub / github.com/benjitaylor/agentation / getAncestorClasses

Function getAncestorClasses

package/src/utils/react-detection.ts:251–275  ·  view source on GitHub ↗

* Collect CSS classes from an element and its ancestors

(element: HTMLElement, maxDepth = 10)

Source from the content-addressed store, hash-verified

249 * Collect CSS classes from an element and its ancestors
250 */
251function 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

Callers 1

getReactComponentNameFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…