Syllabus/themes/piratecare/node_modules/purgecss/lib/purgecss.js

2 lines
9.4 KiB
JavaScript
Raw Normal View History

2020-03-05 04:10:52 +00:00
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}function _interopNamespace(e){if(e&&e.__esModule)return e;var t={};return e&&Object.keys(e).forEach((function(s){var r=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,r.get?r:{enumerable:!0,get:function(){return e[s]}})})),t.default=e,t}Object.defineProperty(exports,"__esModule",{value:!0});var postcss=require("postcss"),selectorParser=_interopDefault(require("postcss-selector-parser")),fs=require("fs"),util=require("util"),glob=_interopDefault(require("glob")),path=_interopDefault(require("path"));const defaultOptions={css:[],content:[],defaultExtractor:e=>e.match(/[A-Za-z0-9_-]+/g)||[],extractors:[],fontFace:!1,keyframes:!1,rejected:!1,stdin:!1,stdout:!1,variables:!1,whitelist:[],whitelistPatterns:[],whitelistPatternsChildren:[]},IGNORE_ANNOTATION_CURRENT="purgecss ignore current",IGNORE_ANNOTATION_NEXT="purgecss ignore",IGNORE_ANNOTATION_START="purgecss start ignore",IGNORE_ANNOTATION_END="purgecss end ignore",CONFIG_FILENAME="purgecss.config.js",ERROR_CONFIG_FILE_LOADING="Error loading the config file",CSS_WHITELIST=["*","::-webkit-scrollbar","::selection",":root","::before","::after"];class VariableNode{constructor(e){this.nodes=[],this.isUsed=!1,this.value=e}}class VariablesStructure{constructor(){this.nodes=new Map,this.usedVariables=new Set}addVariable(e){const{prop:t}=e;if(!this.nodes.has(t)){const s=new VariableNode(e);this.nodes.set(t,s)}}addVariableUsage(e,t){const{prop:s}=e,r=this.nodes.get(s);for(const e of t){const t=e[1];if(this.nodes.has(t)){const e=this.nodes.get(t);r.nodes.push(e)}}}addVariableUsageInProperties(e){for(const t of e){const e=t[1];this.usedVariables.add(e)}}setAsUsed(e){const t=[this.nodes.get(e)];for(;0!==t.length;){const e=t.pop();e.isUsed||(e.isUsed=!0,t.push(...e.nodes))}}removeUnused(){for(const e of this.usedVariables)this.setAsUsed(e);for(const[,e]of this.nodes)e.isUsed||e.value.remove()}}const asyncFs={access:util.promisify(fs.access),readFile:util.promisify(fs.readFile)};async function setOptions(e=CONFIG_FILENAME){let t;try{const s=path.join(process.cwd(),e);t=await new Promise((function(e){e(_interopNamespace(require(s)))}))}catch(e){throw new Error(`${ERROR_CONFIG_FILE_LOADING} ${e.message}`)}return{...defaultOptions,...t}}function extractSelectors(e,t){const s=t(e);return Array.isArray(s)?{attributes:{names:[],values:[]},classes:[],ids:[],tags:[],undetermined:s}:s}function isIgnoreAnnotation(e,t){switch(t){case"next":return e.text.includes("purgecss ignore");case"start":return e.text.includes("purgecss start ignore");case"end":return e.text.includes("purgecss end ignore")}}function isRuleEmpty(e){return!!("rule"===e.type&&!e.selector||e.nodes&&!e.nodes.length||"atrule"===e.type&&(!e.nodes&&!e.params||!e.params&&e.nodes&&!e.nodes.length))}function hasIgnoreAnnotation(e){let t=!1;return e.walkComments(e=>{e&&"comment"===e.type&&e.text.includes("purgecss ignore current")&&(t=!0,e.remove())}),t}function mergeExtractorSelectors(e,t){return{attributes:{names:[...e.attributes.names,...t.attributes.names],values:[...e.attributes.values,...t.attributes.values]},classes:[...e.classes,...t.classes],ids:[...e.ids,...t.ids],tags:[...e.tags,...t.tags],undetermined:[...e.undetermined,...t.undetermined]}}function stripQuotes(e){return e.replace(/(^["'])|(["']$)/g,"")}function isAttributeFound(e,t){if(!t.attributes.names.includes(e.attribute)&&!t.undetermined.includes(e.attribute))return!1;switch(e.operator){case"$=":return t.attributes.values.some(t=>t.endsWith(e.value))||t.undetermined.some(t=>t.endsWith(e.value));case"~=":case"*=":return t.attributes.values.some(t=>t.includes(e.value))||t.undetermined.some(t=>t.includes(e.value));case"=":return t.attributes.values.some(t=>t===e.value)||t.undetermined.some(t=>t===e.value);case"|=":case"^=":return t.attributes.values.some(t=>t.startsWith(e.value))||t.undetermined.some(t=>t.startsWith(e.value));default:return!0}}function isClassFound(e,t){return t.classes.includes(e.value)||t.undetermined.includes(e.value)}function isIdentifierFoun