| 17 | }; |
| 18 | |
| 19 | export function resolveSelectorChain( |
| 20 | nodes: SnapshotState['nodes'], |
| 21 | chain: SelectorChain, |
| 22 | options: { |
| 23 | platform: Platform | PublicPlatform; |
| 24 | requireRect?: boolean; |
| 25 | requireUnique?: boolean; |
| 26 | disambiguateAmbiguous?: boolean; |
| 27 | }, |
| 28 | ): SelectorResolution | null { |
| 29 | const requireRect = options.requireRect ?? false; |
| 30 | const requireUnique = options.requireUnique ?? true; |
| 31 | const diagnostics: SelectorDiagnostics[] = []; |
| 32 | for (const [i, selector] of chain.selectors.entries()) { |
| 33 | const summary = analyzeSelectorMatches(nodes, selector, options.platform, requireRect); |
| 34 | diagnostics.push({ selector: selector.raw, matches: summary.count }); |
| 35 | if (summary.count === 0 || !summary.firstNode) continue; |
| 36 | if (requireUnique && summary.count !== 1) { |
| 37 | if (!options.disambiguateAmbiguous || !summary.disambiguated) continue; |
| 38 | return { |
| 39 | node: summary.disambiguated, |
| 40 | selector, |
| 41 | selectorIndex: i, |
| 42 | matches: summary.count, |
| 43 | diagnostics, |
| 44 | }; |
| 45 | } |
| 46 | return { |
| 47 | node: summary.firstNode, |
| 48 | selector, |
| 49 | selectorIndex: i, |
| 50 | matches: summary.count, |
| 51 | diagnostics, |
| 52 | }; |
| 53 | } |
| 54 | return null; |
| 55 | } |
| 56 | |
| 57 | export function findSelectorChainMatch( |
| 58 | nodes: SnapshotState['nodes'], |