in src/performance/fmp.ts [211:251]
private calcaulteGrades(ele: Element, dpss: ICalScore[]): ICalScore {
const { width, height, left, top } = ele.getBoundingClientRect();
let isInViewPort: boolean = true;
if (WH < top || WW < left) {
isInViewPort = false;
}
let sdp: number = 0;
dpss.forEach((item: any) => {
sdp += item.st;
});
let weight: number = Number(ELE_WEIGHT[ele.tagName as any]) || 1;
// If there is a common element of the background image, it is calculated according to the picture
if (
weight === 1 &&
getStyle(ele, 'background-image') &&
getStyle(ele, 'background-image') !== 'initial' &&
getStyle(ele, 'background-image') !== 'none'
) {
weight = ELE_WEIGHT.IMG;
}
// score = the area of element
let st: number = isInViewPort ? width * height * weight : 0;
let els = [{ ele, st, weight }];
const root = ele;
// The percentage of the current element in the viewport
const areaPercent = this.calculateAreaParent(ele);
// If the sum of the child's weights is greater than the parent's true weight
if (sdp > st * areaPercent || areaPercent === 0) {
st = sdp;
els = [];
for (const item of dpss) {
els = els.concat(item.els);
}
}
return {
dpss,
st,
els,
root,
};
}