1import type { DetectedField } from "./detect";2import { isAnyCredentialForm } from "./detect";34export interface AutofillInteractionTargets {5 usernameEl: HTMLInputElement | null;6 passwordEl: HTMLInputElement | null;7 shouldOpen: boolean;8}9101112131415export function resolveAutofillInteractionTargets(16 anchorField: HTMLInputElement,17 fields: DetectedField[],18 explicitSummon = false19): AutofillInteractionTargets {20 const userField = fields.find((f) => f.type === "username" || f.type === "email");21 const pwField = fields.find((f) => f.type === "password");22 const anchorType = anchorField.type.toLowerCase();23 const fallbackType = anchorType === "password" ? "password" : "username";2425 return {26 usernameEl: userField?.el ?? (explicitSummon && fallbackType === "username" ? anchorField : null),27 passwordEl: pwField?.el ?? (explicitSummon && fallbackType === "password" ? anchorField : null),28 shouldOpen: explicitSummon || isAnyCredentialForm(fields),29 };30}