UNPKG

postcss-no-important

Version:
3 lines 1.43 kB
function c(r){return r instanceof Set?r:new Set(r)}function f(r,a){return a.some(p=>p instanceof RegExp?p.test(r):r.includes(p))}var i="postcss-no-important",u=(r={})=>{let{removeAll:a=true,properties:p=[],exclude:S=[],preserveSelectors:T=[],verbose:m=false,reportChanges:v=false}=r,y=c(p),x=c(S),e={total:0,properties:new Map,selectors:new Map},g=0;return {postcssPlugin:i,Once(){m&&(g=performance.now());},Declaration(o,{result:l}){if(!o.important)return;let t=o.parent;if(t&&"selector"in t&&f(t.selector,T))return;if(a?!x.has(o.prop):y.has(o.prop)){if(o.important=false,e.total++,e.properties.set(o.prop,(e.properties.get(o.prop)??0)+1),t&&"selector"in t){let s=t.selector;e.selectors.set(s,(e.selectors.get(s)??0)+1);}if(v){let s={type:"removal",plugin:i,prop:o.prop};t&&"selector"in t&&(s.selector=t.selector),l.messages.push(s);}}},OnceExit(o,{result:l}){if(m&&e.total>0&&(e.processingTime=performance.now()-g,console.log(` ${i} - Removal Summary:`),console.log(`Total removed: ${e.total}`),console.log(`Processing time: ${e.processingTime.toFixed(2)}ms`),e.properties.size>0)){console.log(` Top properties:`);let t=Array.from(e.properties.entries()).sort(([,n],[,s])=>s-n).slice(0,5);for(let[n,s]of t)console.log(` ${n}: ${s}`);}{let t={total:e.total};e.processingTime!==void 0&&(t.processingTime=e.processingTime);let n={type:"statistics",plugin:i,stats:t};l.messages.push(n);}}}};u.postcss=true;var P=u;export{P as default};