buildFallbackCSS function presentation ✓ 100.0%

Last updated: 2026-03-05T12:26:14.062Z

Metrics

LOC: 35 Complexity: 7 Params: 1 Coverage: 100.0% (13/13 lines, 0x executed)

Signature

buildFallbackCSS(el: Element): : SmartSelector

Source Code

function buildFallbackCSS(el: Element): SmartSelector {
  if (el.id) return { value: `#${escapeCSS(el.id)}`, strategy: "css" };

  const parts: string[] = [];
  let current: Element | null = el;

  while (current && current !== document.body) {
    let selector = current.tagName.toLowerCase();

    if (current.id) {
      parts.unshift(`#${escapeCSS(current.id)}`);
      break;
    }

    const parent: Element | null = current.parentElement;
    if (parent) {
      const siblings = Array.from(parent.children).filter(
        (c: Element) => c.tagName === current!.tagName,
      );
      if (siblings.length > 1) {
        const index = siblings.indexOf(current) + 1;
        selector += `:nth-of-type(${index})`;
      }
    }

    parts.unshift(selector);
    current = parent;
  }

  return {
    value: parts.join(" > "),
    strategy: "selector-path",
    description: "DOM selector path",
  };
}

Dependencies (Outgoing)

graph LR buildFallbackCSS["buildFallbackCSS"] escapeCSS["escapeCSS"] buildFallbackCSS -->|calls| escapeCSS style buildFallbackCSS fill:#dbeafe,stroke:#2563eb,stroke-width:2px click buildFallbackCSS "9e270d9c7136a3da.html" click escapeCSS "44646aa96f30257e.html"
TargetType
escapeCSS calls

Impact (Incoming)

graph LR buildFallbackCSS["buildFallbackCSS"] buildCSSPath["buildCSSPath"] extractSmartSelectors["extractSmartSelectors"] buildCSSPath -->|calls| buildFallbackCSS extractSmartSelectors -->|calls| buildFallbackCSS style buildFallbackCSS fill:#dbeafe,stroke:#2563eb,stroke-width:2px click buildFallbackCSS "9e270d9c7136a3da.html" click buildCSSPath "2f2f3878eed47f3f.html" click extractSmartSelectors "6f96c46b2e3fc740.html"
SourceType
buildCSSPath calls
extractSmartSelectors calls