8000 ax-grep/src/static.ts at main · hmmhmmhm/ax-grep · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
1130 lines (1028 loc) · 42.9 KB

static.ts

File metadata and controls

1130 lines (1028 loc) · 42.9 KB
children.push(...collectFlattenedBoilerplateItems(child, context));
}
return children;
}
function hasExplicitNameSource(element: Element): boolean {
return attr(element, "aria-label") !== null || attr(element, "aria-labelledby") !== null || attr(element, "title") !== null;
}
function directText(element: Element, maxLength: number): string {
return normalizeText(
element.children
.filter(isText)
.map((node) => node.data)
.join(" "),
maxLength,
);
}
function descendantText(element: Element, context?: StaticContext, options: DescendantTextOptions = {}): string {
const parts: string[] = [];
const shadowTemplate = element.children.find((child): child is Element => isElement(child) && isDeclarativeShadowTemplate(child));
if (shadowTemplate && context) {
const previousAssignments = context.slotAssignments;
context.slotAssignments = collectSlotAssignments(element);
collectDescendantText(shadowTemplate.children, parts, context, options);
context.slotAssignments = previousAssignments;
return parts.join(" ");
}
collectDescendantText(element.children, parts, context, options);
return parts.join(" ");
}
function collectDescendantText(nodes: AnyNode[], parts: string[], context?: StaticContext, options: DescendantTextOptions = {}): void {
for (const node of nodes) {
if (isText(node)) {
parts.push(node.data);
continue;
}
if (!isElement(node)) continue;
const nodeId = attr(node, "id");
if (nodeId && options.excludeIds?.has(nodeId)) continue;
if (node.name === "slot" && context?.slotAssignments) {
const slotName = attr(node, "name") ?? "";
const assigned = context.slotAssignments.get(slotName) ?? [];
collectDescendantText(assigned.length > 0 ? assigned : node.children, parts, context, options);
continue;
}
if (nonSemanticTags.has(node.name) || node.name === "noscript") continue;
collectDescendantText(node.children, parts, context, options);
}
0