CSSOverviewUnusedDeclarations.js 2.1 KB

123456789101112
  1. export class CSSOverviewUnusedDeclarations{static _add(target,key,item){const values=target.get(key)||[];values.push(item);target.set(key,values);}
  2. static checkForUnusedPositionValues(unusedDeclarations,nodeId,strings,positionIdx,topIdx,leftIdx,rightIdx,bottomIdx){if(strings[positionIdx]!=='static'){return;}
  3. if(strings[topIdx]!=='auto'){const reason=ls`Top applied to a statically positioned element`;this._add(unusedDeclarations,reason,{declaration:`top: ${strings[topIdx]}`,nodeId,});}
  4. if(strings[leftIdx]!=='auto'){const reason=ls`Left applied to a statically positioned element`;this._add(unusedDeclarations,reason,{declaration:`left: ${strings[leftIdx]}`,nodeId,});}
  5. if(strings[rightIdx]!=='auto'){const reason=ls`Right applied to a statically positioned element`;this._add(unusedDeclarations,reason,{declaration:`right: ${strings[rightIdx]}`,nodeId,});}
  6. if(strings[bottomIdx]!=='auto'){const reason=ls`Bottom applied to a statically positioned element`;this._add(unusedDeclarations,reason,{declaration:`bottom: ${strings[bottomIdx]}`,nodeId,});}}
  7. static checkForUnusedWidthAndHeightValues(unusedDeclarations,nodeId,strings,displayIdx,widthIdx,heightIdx){if(strings[displayIdx]!=='inline'){return;}
  8. if(strings[widthIdx]!=='auto'){const reason=ls`Width applied to an inline element`;this._add(unusedDeclarations,reason,{declaration:`width: ${strings[widthIdx]}`,nodeId,});}
  9. if(strings[heightIdx]!=='auto'){const reason=ls`Height applied to an inline element`;this._add(unusedDeclarations,reason,{declaration:`height: ${strings[heightIdx]}`,nodeId,});}}
  10. static checkForInvalidVerticalAlignment(unusedDeclarations,nodeId,strings,displayIdx,verticalAlignIdx){if(strings[displayIdx]==='inline'||strings[displayIdx].startsWith('table')){return;}
  11. if(strings[verticalAlignIdx]!=='baseline'){const reason=ls`Vertical alignment applied to element which is neither inline nor table-cell`;this._add(unusedDeclarations,reason,{declaration:`vertical-align: ${strings[verticalAlignIdx]}`,nodeId,});}}}
  12. self.CssOverview=self.CssOverview||{};CssOverview=CssOverview||{};CssOverview.CSSOverviewUnusedDeclarations=CSSOverviewUnusedDeclarations;