Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
makeRuleset(coeffs, biases) {
return ruleset([
/**
* Image rules
*/
// consider all visible img elements
rule(dom('img').when(this.isVisible.bind(this)), note(() => ({isVisible: true})).type('image')),
// and divs, which sometimes have CSS background-images
// TODO: Consider a bonus for <img> tags.
rule(dom('div').when(fnode => this.isVisible(fnode) && this.hasBackgroundImage(fnode)), type('image')),
// better score the closer the element is to the top of the page
rule(type('image'), score(this.isAboveTheFold.bind(this)), {name: 'isAboveTheFoldImage'}),
// better score for larger images
rule(type('image'), score(this.isBig.bind(this)), {name: 'isBig'}),
// bonus for non-extreme aspect ratios, to filter out banners or nav elements
// TODO: Meant to make this a penalty, but it turns out to work as is.
// Try as a penalty.
rule(type('image'), score(this.hasSquareAspectRatio.bind(this)), {name: 'hasSquareAspectRatio'}),
// no background images, even ones that have reasonable aspect ratios
// TODO: If necessary, also look at parents. I've seen them say
// "background" in their IDs as well.
rule(type('image'), score(this.hasBackgroundInID.bind(this)), {name: 'hasBackgroundInID'}),
// return image element(s) with max score