fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
17 lines (14 loc) • 528 B
text/typescript
import { selectorMatches } from './selectorMatches';
import { doesSomeParentMatch } from './doesSomeParentMatch';
/**
* @private
*/
export function elementMatchesRule(element: HTMLElement, selectors: string[]) {
let parentMatching = true;
// start from rightmost selector.
const firstMatching = selectorMatches(element, selectors.pop()!);
if (firstMatching && selectors.length) {
parentMatching = doesSomeParentMatch(element, selectors);
}
return firstMatching && parentMatching && selectors.length === 0;
}