import{tokenizer as e,isTokenWhitespace as r,isTokenComment as t}from"@csstools/css-tokenizer";const s=/license|copyright|sourcemappingurl/i,o=/\s|\/\*/,n=/^layer$/i;function minify(s,n){if(!n)return n;if(s.has(n))return s.get(n);const a=n.trim();if(""===a)return s.set(n,""),"";if(!o.test(a))return s.set(n,a),a;let i=!1,c=!1,m="";const f=e({css:a});for(;!f.endOfFile();){const e=f.nextToken();r(e)?(i||(m+=" "),i=!0,c=!1):t(e)?(c||(m+="/**/"),i=!1,c=!0):(i=!1,c=!1,m+=e[1])}return s.set(n,m),m}function removeEmptyNodes(e){if("rule"===e.type){if(0===e.nodes?.length){const r=e.parent;return!!r&&(e.remove(),removeEmptyNodes(r),!0)}}else if("atrule"===e.type&&0===e.nodes?.length&&!n.test(e.name)){const r=e.parent;return!!r&&(e.remove(),removeEmptyNodes(r),!0)}return!1}function setSemicolon(e){if(!e.raws.semicolon)return;const r=e.last;"decl"===r?.type&&r.variable||(e.raws.semicolon=!1)}const creator=()=>{const e=new Map;return{postcssPlugin:"postcss-minify",OnceExit(r){r.raws.before="",r.raws.after="\n",r.walk(r=>{switch(r.type){case"atrule":if(removeEmptyNodes(r))return;return r.raws.after="",r.raws.afterName=" ",r.raws.before="",r.raws.between="",r.raws.params=void 0,setSemicolon(r),void(r.params=minify(e,r.params));case"rule":if(removeEmptyNodes(r))return;return r.raws.after="",r.raws.before="",r.raws.between="",r.raws.selector=void 0,setSemicolon(r),void(r.selector=minify(e,r.selector));case"decl":return r.prop.startsWith("--")?void(r.raws.before=""):(r.raws.before="",r.raws.between=":",r.raws.important=r.important?"!important":"",r.raws.value=void 0,void(r.value=minify(e,r.value)));case"comment":if(r.text.startsWith("!")||s.test(r.text))return void(r.raws.before="");r.remove()}})}}};creator.postcss=!0;export{creator as default,creator as"module.exports"};
