Files
old-cto-as-you-go/CTOAsYouGo/node_modules/purgecss/lib/purgecss.esm.js

2 lines
8.4 KiB
JavaScript
Raw Normal View History

2023-07-05 11:02:15 +02:00
import{parse as t}from"postcss";import e from"postcss-selector-parser";import{access as s,readFile as r,constants as i}from"fs";import{promisify as n}from"util";import o from"glob";import a from"path";const c={css:[],content:[],defaultExtractor:t=>t.match(/[A-Za-z0-9_-]+/g)||[],extractors:[],fontFace:!1,keyframes:!1,rejected:!1,stdin:!1,stdout:!1,variables:!1,whitelist:[],whitelistPatterns:[],whitelistPatternsChildren:[]},u=["*","::-webkit-scrollbar","::selection",":root","::before","::after"];class h{constructor(t){this.nodes=[],this.isUsed=!1,this.value=t}}class l{constructor(){this.nodes=new Map,this.usedVariables=new Set}addVariable(t){const{prop:e}=t;if(!this.nodes.has(e)){const s=new h(t);this.nodes.set(e,s)}}addVariableUsage(t,e){const{prop:s}=t,r=this.nodes.get(s);for(const t of e){const e=t[1];if(this.nodes.has(e)){const t=this.nodes.get(e);null==r||r.nodes.push(t)}}}addVariableUsageInProperties(t){for(const e of t){const t=e[1];this.usedVariables.add(t)}}setAsUsed(t){const e=[this.nodes.get(t)];for(;0!==e.length;){const t=e.pop();t&&!t.isUsed&&(t.isUsed=!0,e.push(...t.nodes))}}removeUnused(){for(const t of this.usedVariables)this.setAsUsed(t);for(const[,t]of this.nodes)t.isUsed||t.value.remove()}}function d(t,e){e&&e.forEach(t.add,t)}class f{constructor(t){this.undetermined=new Set,this.attrNames=new Set,this.attrValues=new Set,this.classes=new Set,this.ids=new Set,this.tags=new Set,this.merge(t)}merge(t){return Array.isArray(t)?d(this.undetermined,t):t instanceof f?(d(this.undetermined,t.undetermined),d(this.attrNames,t.attrNames),d(this.attrValues,t.attrValues),d(this.classes,t.classes),d(this.ids,t.ids),d(this.tags,t.tags)):(d(this.undetermined,t.undetermined),t.attributes&&(d(this.attrNames,t.attributes.names),d(this.attrValues,t.attributes.values)),d(this.classes,t.classes),d(this.ids,t.ids),d(this.tags,t.tags)),this}hasAttrName(t){return this.attrNames.has(t)||this.undetermined.has(t)}someAttrValue(t){for(const e of this.attrValues)if(t(e))return!0;for(const e of this.undetermined)if(t(e))return!0;return!1}hasAttrPrefix(t){return this.someAttrValue(e=>e.startsWith(t))}hasAttrSuffix(t){return this.someAttrValue(e=>e.endsWith(t))}hasAttrSubstr(t){return this.someAttrValue(e=>e.includes(t))}hasAttrValue(t){return this.attrValues.has(t)||this.undetermined.has(t)}hasClass(t){return this.classes.has(t)||this.undetermined.has(t)}hasId(t){return this.ids.has(t)||this.undetermined.has(t)}hasTag(t){return this.tags.has(t)||this.undetermined.has(t)}}const m={access:n(s),readFile:n(r)};async function p(t="purgecss.config.js"){let e;try{const s=a.join(process.cwd(),t);e=await import(s)}catch(t){throw new Error(`Error loading the config file ${t.message}`)}return{...c,...e}}async function g(t,e){return new f(await e(t))}function v(t,e){switch(e){case"next":return t.text.includes("purgecss ignore");case"start":return t.text.includes("purgecss start ignore");case"end":return t.text.includes("purgecss end ignore")}}function y(...t){const e=new f([]);return t.forEach(e.merge,e),e}function w(t){return t.replace(/(^["'])|(["']$)/g,"")}function S(t,e){if(!e.hasAttrName(t.attribute))return!1;if(void 0===t.value)return!0;switch(t.operator){case"$=":return e.hasAttrSuffix(t.value);case"~=":case"*=":return e.hasAttrSubstr(t.value);case"=":return e.hasAttrValue(t.value);case"|=":case"^=":return e.hasAttrPrefix(t.value);default:return!0}}function b(t,e){return e.hasId(t.value)}function F(t,e){return e.hasTag(t.value)}class x{constructor(){this.ignore=!1,this.atRules={fontFace:[],keyframes:[]},this.usedAnimations=new Set,this.usedFontFaces=new Set,this.selectorsRemoved=new Set,this.variablesStructure=new l,this.options=c}collectDeclarationsData(t){const{prop:e,value:s}=t;if(this.options.variables){const r=function(t,e){const s=[];return t.replace(e,(function(){const e=arguments,r=Array.prototype.slice.call(e,0,-2);return r.input=e[e.length-1],r.index=e[e.length-2],s.push(r),t})),s}(s,/var\((.+?)[,)]/g);e.startsWith("--")?(this.variablesStructure.addVariable(t),r.length>0&&this.variablesStructure.addVariableUsage(t,r)):r.length>0&&t