Comparing version 1.0.3 to 1.0.4
@@ -7,3 +7,3 @@ /** | ||
* An exceptionally fast, thorough and tiny unused-CSS cleaner | ||
* https://github.com/leeoniya/dropcss (v1.0.3) | ||
* https://github.com/leeoniya/dropcss (v1.0.4) | ||
*/ | ||
@@ -228,8 +228,19 @@ | ||
var PSEUDO_PARENTH = /:[a-z-]+\([^()]*\)/; | ||
function stripAllPseudos(sel) { | ||
return sel.replace(/:?:[a-z-]+(?:\([^()]+\))?/gm, ''); | ||
var olen = sel.length; | ||
for (;;) { | ||
sel = sel.replace(PSEUDO_PARENTH, ''); | ||
if (sel.length == olen) | ||
{ break; } | ||
olen = sel.length; | ||
} | ||
return sel.replace(/:?:[a-z-]+/gm, ''); | ||
} | ||
// pos must already be past opening { | ||
function takeUntilMatchedClosing(css, pos) { | ||
// pos must already be past opening @op | ||
function takeUntilMatchedClosing(css, pos, op, cl) { | ||
var chunk = ''; | ||
@@ -239,5 +250,5 @@ var unclosed = 1; | ||
while (1) { | ||
if (css[pos] == '{') | ||
if (css[pos] == op) | ||
{ unclosed++; } | ||
else if (css[pos] == '}') | ||
else if (css[pos] == cl) | ||
{ unclosed--; } | ||
@@ -319,3 +330,3 @@ | ||
inAt++; | ||
var chunk = takeUntilMatchedClosing(css, pos); | ||
var chunk = takeUntilMatchedClosing(css, pos, '{', '}'); | ||
syncPos({lastIndex: pos + chunk.length}); | ||
@@ -452,3 +463,3 @@ tokens.push(START_AT, pre, AT_CHUNK, chunk); | ||
ATTR: /([\w-]+)(?:(.?=)"?([^\]]*?)"?)?\]/iy, | ||
PSEUDO: /([\w-]+)(?:\(([^)]*)\))?/iy, | ||
PSEUDO: /([\w-]+)(\()?/iy, | ||
MODE: /\s*[:.#\[]\s*/iy, | ||
@@ -493,6 +504,13 @@ COMB: /\s*[>~+]\s*|\s+/iy | ||
m = RE.PSEUDO.exec(sel); | ||
if (m[2] == '(') { | ||
var subsel = takeUntilMatchedClosing(sel, RE.PSEUDO.lastIndex, '(', ')'); | ||
RE.PSEUDO.lastIndex += subsel.length + 1; | ||
m[2] = m[1] == 'not' ? parse$1(subsel) : subsel; | ||
} | ||
toks.splice( | ||
lastComb + 1, | ||
0, | ||
m[2] != null && m[1] == 'not' ? parse$1(m[2]) : m[2], | ||
m[2], | ||
m[1], | ||
@@ -567,3 +585,3 @@ mode$1 | ||
function matchesAttr(el, name, value, matcher) { | ||
function matchesAttr(el, name, selVal, matcher) { | ||
matcher = matcher || '='; | ||
@@ -574,9 +592,15 @@ | ||
if (attrs.has(name)) { | ||
var v = attrs.get(name); | ||
var attrVal = attrs.get(name); | ||
switch (matcher) { | ||
case '=': return value == null || value == v; | ||
case '*=': return v.indexOf(value) != -1; | ||
case '^=': return v.startsWith(value); | ||
case '$=': return v.endsWith(value); | ||
case '=': return selVal == null || selVal == attrVal; | ||
case '*=': return attrVal.indexOf(selVal) != -1; | ||
case '^=': return attrVal.startsWith(selVal); | ||
case '$=': return attrVal.endsWith(selVal); | ||
case '~=': return ( | ||
selVal == attrVal || | ||
attrVal.startsWith(selVal + ' ') || | ||
attrVal.endsWith(' ' + selVal) || | ||
attrVal.indexOf(' ' + selVal + ' ') != -1 | ||
); | ||
} | ||
@@ -796,3 +820,3 @@ } | ||
while (m = RE.exec(css)) { | ||
var ch = takeUntilMatchedClosing(css, RE.lastIndex); | ||
var ch = takeUntilMatchedClosing(css, RE.lastIndex, '{', '}'); | ||
defs.push([m.index, m[0].length + ch.length + 1, m[1]]); | ||
@@ -799,0 +823,0 @@ } |
@@ -7,3 +7,3 @@ /** | ||
* An exceptionally fast, thorough and tiny unused-CSS cleaner | ||
* https://github.com/leeoniya/dropcss (v1.0.3) | ||
* https://github.com/leeoniya/dropcss (v1.0.4) | ||
*/ | ||
@@ -232,8 +232,19 @@ | ||
var PSEUDO_PARENTH = /:[a-z-]+\([^()]*\)/; | ||
function stripAllPseudos(sel) { | ||
return sel.replace(/:?:[a-z-]+(?:\([^()]+\))?/gm, ''); | ||
var olen = sel.length; | ||
for (;;) { | ||
sel = sel.replace(PSEUDO_PARENTH, ''); | ||
if (sel.length == olen) | ||
{ break; } | ||
olen = sel.length; | ||
} | ||
return sel.replace(/:?:[a-z-]+/gm, ''); | ||
} | ||
// pos must already be past opening { | ||
function takeUntilMatchedClosing(css, pos) { | ||
// pos must already be past opening @op | ||
function takeUntilMatchedClosing(css, pos, op, cl) { | ||
var chunk = ''; | ||
@@ -243,5 +254,5 @@ var unclosed = 1; | ||
while (1) { | ||
if (css[pos] == '{') | ||
if (css[pos] == op) | ||
{ unclosed++; } | ||
else if (css[pos] == '}') | ||
else if (css[pos] == cl) | ||
{ unclosed--; } | ||
@@ -323,3 +334,3 @@ | ||
inAt++; | ||
var chunk = takeUntilMatchedClosing(css, pos); | ||
var chunk = takeUntilMatchedClosing(css, pos, '{', '}'); | ||
syncPos({lastIndex: pos + chunk.length}); | ||
@@ -456,3 +467,3 @@ tokens.push(START_AT, pre, AT_CHUNK, chunk); | ||
ATTR: /([\w-]+)(?:(.?=)"?([^\]]*?)"?)?\]/iy, | ||
PSEUDO: /([\w-]+)(?:\(([^)]*)\))?/iy, | ||
PSEUDO: /([\w-]+)(\()?/iy, | ||
MODE: /\s*[:.#\[]\s*/iy, | ||
@@ -497,6 +508,13 @@ COMB: /\s*[>~+]\s*|\s+/iy | ||
m = RE.PSEUDO.exec(sel); | ||
if (m[2] == '(') { | ||
var subsel = takeUntilMatchedClosing(sel, RE.PSEUDO.lastIndex, '(', ')'); | ||
RE.PSEUDO.lastIndex += subsel.length + 1; | ||
m[2] = m[1] == 'not' ? parse$1(subsel) : subsel; | ||
} | ||
toks.splice( | ||
lastComb + 1, | ||
0, | ||
m[2] != null && m[1] == 'not' ? parse$1(m[2]) : m[2], | ||
m[2], | ||
m[1], | ||
@@ -571,3 +589,3 @@ mode$1 | ||
function matchesAttr(el, name, value, matcher) { | ||
function matchesAttr(el, name, selVal, matcher) { | ||
matcher = matcher || '='; | ||
@@ -578,9 +596,15 @@ | ||
if (attrs.has(name)) { | ||
var v = attrs.get(name); | ||
var attrVal = attrs.get(name); | ||
switch (matcher) { | ||
case '=': return value == null || value == v; | ||
case '*=': return v.indexOf(value) != -1; | ||
case '^=': return v.startsWith(value); | ||
case '$=': return v.endsWith(value); | ||
case '=': return selVal == null || selVal == attrVal; | ||
case '*=': return attrVal.indexOf(selVal) != -1; | ||
case '^=': return attrVal.startsWith(selVal); | ||
case '$=': return attrVal.endsWith(selVal); | ||
case '~=': return ( | ||
selVal == attrVal || | ||
attrVal.startsWith(selVal + ' ') || | ||
attrVal.endsWith(' ' + selVal) || | ||
attrVal.indexOf(' ' + selVal + ' ') != -1 | ||
); | ||
} | ||
@@ -800,3 +824,3 @@ } | ||
while (m = RE.exec(css)) { | ||
var ch = takeUntilMatchedClosing(css, RE.lastIndex); | ||
var ch = takeUntilMatchedClosing(css, RE.lastIndex, '{', '}'); | ||
defs.push([m.index, m[0].length + ch.length + 1, m[1]]); | ||
@@ -803,0 +827,0 @@ } |
@@ -1,2 +0,2 @@ | ||
/*! https://github.com/leeoniya/dropcss (v1.0.3) */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).dropcss=t()}(this,function(){"use strict";var e=1,t=2,r=3,n=new Set("area base br col command embed hr img input keygen link meta param source track wbr".split(" ")),a=/<!doctype[^>]*>|<!--[\s\S]*?-->|<script[^>]*>[\s\S]*?<\/script>|<style[^>]*>[\s\S]*?<\/style>|<link[^>]*>|<meta[^>]*>/gim,s=/([\w-]+)(?:="([^"]*)"|='([^']*)'|=(\S+))?/gm,i={TAG_HEAD:/\s*<([a-z0-9_-]+)(?:\s+([^>]*))?>\s*/imy,TEXT:/\s*[^<]*/my,TAG_CLOSE:/\s*<\/[a-z0-9_-]+>\s*/imy};var c=new Set;function o(e,t,r){return{tagName:t,attributes:r,classList:null!=r&&r.has("class")?new Set(r.get("class").split(/\s+/g)):c,parentNode:e,childNodes:[]}}function u(e,t){if(null!=e){var r=e._ofTypes=e._ofTypes||{};if(!(t in r)){var n=0;r[t]=e.childNodes.filter(function(e){if(e.tagName==t)return e._typeIdx=n++,!0})}return r[t]}return null}var l=function(u){var l=function(a){var c,o=0,u=[];function l(e){for(var t in o=e.lastIndex,i)i[t].lastIndex=o}function d(){if(null!=(c=i.TAG_CLOSE.exec(a)))return l(i.TAG_CLOSE),void u.push(r);if(null==(c=i.TAG_HEAD.exec(a)))null!=(c=i.TEXT.exec(a))&&l(i.TEXT);else{l(i.TAG_HEAD);var o=c[1];u.push(e,o);var d=c[2];if(null!=d){for(var f,h=new Map;f=s.exec(d);)h.set(f[1],(f[2]||f[3]||f[4]||"").trim());u.push(t,h)}n.has(o)&&u.push(r)}}for(;o<a.length;)d();return l({lastIndex:0}),u}(u=u.replace(a,"")),d={nodes:[],tag:new Set(["*"]),class:new Set,attr:new Set};!function(n,a){for(var s,i=o(null,"root",c),u=0;u<n.length;u++)switch(n[u]){case e:var l=n[++u],d=c;n[u+1]===t&&(d=n[u+=2]),s=i.childNodes.length,i.childNodes.push(i=o(i,l,d)),a(i,s);break;case r:i=i.parentNode}}(l,function(e,t){return function(e,t,r){e.idx=t;var n=e.attributes;r.tag.add(e.tagName),e.classList.forEach(function(e){return r.class.add(e)}),n.has("id")&&r.attr.add("[id="+n.get("id")+"]"),n.has("type")&&r.attr.add("[type="+n.get("type")+"]"),r.nodes.push(e)}(e,t,d)});return d},d=/\s*\/\*[\s\S]*?\*\/\s*/gm,f=/\s*[>~+.#]\s*|\[[^\]]+\]|\s+/gm,h=1,p=2,m=3,v=4,x=5;function g(e,t){for(var r="",n=1;"{"==e[t]?n++:"}"==e[t]&&n--,0!=n;)r+=e[t++];return r}function y(e){var t,r={RULE_HEAD:/\s*([^{;]+?)\s*[{;]\s*/my,RULE_TAIL:/\s*([^}]*?)\s*\}/my,AT_TAIL:/\s*\}/my,RULE_FULL:/\s*([^{]*?)\{([^}]+?)\}/my},n=0,a=0,s=[];function i(e){for(var t in a=e.lastIndex,r)r[t].lastIndex=a}function c(){if(n>0&&null!=(t=r.AT_TAIL.exec(e)))return n--,s.push(p),void i(r.AT_TAIL);if(null!=(t=r.RULE_HEAD.exec(e))){var c=t[1];if(i(r.RULE_HEAD),"@"==c[0])switch(c.match(/@[a-z-]+/)[0]){case"@media":case"@supports":case"@document":n++,s.push(h,c);break;case"@import":case"@charset":case"@namespace":s.push(x,c+";");break;default:n++;var o=g(e,a);i({lastIndex:a+o.length}),s.push(h,c,x,o)}else s.push(m,(u=t[1],(l=u.split(/\s*,\s*/gm)).push(l.map(function(e){return function(e){return e.replace(/:?:[a-z-]+(?:\([^()]+\))?/gm,"")}(e).trim().replace(f,function(e,t){return e=e.trim(),0==t?e:"."==e||"#"==e?"`"+e:e.length<=1?"`":"`"+e.replace(/['"]/gm,"")}).split(/`+/gm)})),l)),t=r.RULE_TAIL.exec(e),s.push(v,t[1]),i(r.RULE_TAIL)}else a=e.length;var u,l}for(;a<e.length;)c();return s}function b(e){return e.replace(/@[a-z-]+[^{]+\{\s*\}/gm,"")}var k=/^([+-]?\d*)?n([+-]\d+)?$/;function T(e,t){return t==e.tagName||"*"==t}function E(e,t,r,n){n=n||"=";var a=e.attributes;if(a.has(t)){var s=a.get(t);switch(n){case"=":return null==r||r==s;case"*=":return-1!=s.indexOf(r);case"^=":return s.startsWith(r);case"$=":return s.endsWith(r)}}return!1}function _(e,t){return e.classList.has(t)}function A(e,t){var r;if("odd"==t)r=e%2==1;else if("even"==t)r=e%2==0;else if(/^\d+$/.test(t))r=e==+t;else{var n=function(e){var t=k.exec(e);if(null!=t){var r=t[1],n=t[2];return[r=null==r||"+"==r?1:"-"==r?-1:+r,n=null==n?0:+n]}return[0,0]}(t);r=function(e,t,r){if(t<0&&e<=0)return!1;if(-1===e)return r<=t;if(0===e)return r===t;if(1===e)return t<0||r>=t;var n=t%e;return n<0&&(n+=e),e>1?r>=t&&r%e===n:(e*=-1,r<=t&&r%e===n)}(n[0],n[1],e)}return r}function w(e,t){return e.some(function(e){return function e(t,r){for(var n,a,s,i,c,o;r.idx>-1;){switch(t[r.idx]){case"_":n=t[--r.idx],o=T(r.node,n),r.idx--;break;case"#":a=t[--r.idx],o=E(r.node,"id",a,"="),r.idx--;break;case".":n=t[--r.idx],o=_(r.node,n),r.idx--;break;case"[":n=t[--r.idx],s=t[--r.idx],a=t[--r.idx],o=E(r.node,n,a,s),r.idx--;break;case":":n=t[--r.idx],a=t[--r.idx];var l=r.node,d=l.tagName;c=l.idx;var f=(i=l.parentNode)?i.childNodes.length:1,h=void 0;switch(n){case"not":o=!e(a,{node:r.node,idx:a.length-1});break;case"first-child":o=0==c;break;case"last-child":o=c==f-1;break;case"only-child":o=1==f;break;case"nth-child":o=A(c+1,a);break;case"nth-last-child":o=A(f-c,a);break;case"first-of-type":h=u(i,d),o=0==l._typeIdx;break;case"last-of-type":h=u(i,d),o=l._typeIdx==h.length-1;break;case"only-of-type":o=1==(h=u(i,d)).length;break;case"nth-of-type":h=u(i,d),o=A(l._typeIdx+1,a);break;case"nth-last-of-type":o=A((h=u(i,d)).length-l._typeIdx,a)}r.idx--;break;case" ":for(c=--r.idx,o=!1;!o&&null!=(i=r.node.parentNode);)r.idx=c,r.node=i,o=e(t,r);break;case">":r.idx--,null!=(i=r.node.parentNode)?(r.node=i,o=e(t,r)):o=!1;break;case"+":r.idx--,null!=(i=r.node.parentNode)&&r.node.idx>0?(r.node=i.childNodes[r.node.idx-1],o=e(t,r)):o=!1;break;case"~":if(r.idx--,o=!1,c=r.node.idx,null!=(i=r.node.parentNode)&&c>0)for(var p=0;p<c&&!o;p++)r.node=i.childNodes[p],o=e(t,r)}if(!o)break}return o}(t,{idx:t.length-1,node:e})})}var I=function(e,t){return w(e,Array.isArray(t)?t:function e(t){var r,n={IDENT:/([\w*-]+)/iy,ATTR:/([\w-]+)(?:(.?=)"?([^\]]*?)"?)?\]/iy,PSEUDO:/([\w-]+)(?:\(([^)]*)\))?/iy,MODE:/\s*[:.#\[]\s*/iy,COMB:/\s*[>~+]\s*|\s+/iy},a=0,s=[],i=-1;function c(e){for(var t in a=e.lastIndex,n)n[t].lastIndex=a}function o(){var o=!1;if(r=n.COMB.exec(t)){o=!0;var u=r[0].trim();""==u&&(u=" "),s.push(u),c(n.COMB),i=a}else if(r=n.MODE.exec(t)){o=!0;var l=r[0].trim();c(n.MODE),":"==l?(r=n.PSEUDO.exec(t),s.splice(i+1,0,null!=r[2]&&"not"==r[1]?e(r[2]):r[2],r[1],l),c(n.PSEUDO)):"["==l?(r=n.ATTR.exec(t),s.splice(i+1,0,r[3],r[2],r[1],l),c(n.ATTR)):(r=n.IDENT.exec(t),s.push(r[1],l),c(n.IDENT))}else(r=n.IDENT.exec(t))&&(o=!0,s.push(r[1],"_"),c(n.IDENT));return o}for(;a<t.length;)o();return s}(t))},N=/\[([\w-]+)(?:(.?=)"?([^\]]*?)"?)?\]/i,S=/:(?:first|last|nth|only|not)\b/;function L(e,t,r,n,a){a=a||"";for(var s=t.length-1;s>-1;s--){var i=t[s];r.has(i[2])||!0!==n(a+i[2])||(c=e,o=i[0],u=i[1],l="",e=c.slice(0,o)+l+c.slice(o+u))}var c,o,u,l;return e}var D=function(e){return!0};return function(e){for(var t=l(e.html,!e.keepText),r=e.shouldDrop||D,n=y(e.css.replace(d,"")),a={},s=0;s<n.length;s++)if(n[s]===m){var i=n[s+1],c=i[i.length-1];s++;for(var o=0;o<c.length;o++){var u=c[o];e:for(var f=0;f<u.length;f++){var k=u[f],T=!1,_=void 0;if(""!=k){if(k in a)T=a[k];else switch(k[0]){case"#":_=k.substr(1),a[k]=T=t.attr.has("[id="+_+"]");break;case".":_=k.substr(1),a[k]=T=t.class.has(_);break;case"[":if(k.startsWith("[type="))a[k]=T=t.attr.has(k);else{var A=k.match(N);a[k]=T=t.nodes.some(function(e){return E(e,A[1],A[3],A[2])})}break;default:a[k]=T=t.tag.has(k)}if(!T){!0===r(i[o])?i[o]=null:a[i[o]]=!0;break e}}}}}for(var w=0;w<n.length;w++)n[w]===m&&(n[++w].length,n[w]=n[w].filter(function(e){if("string"==typeof e){if(e in a)return a[e];var n=(s=e).replace(/:?:[a-z-]+/gm,function(e){return s.startsWith("::")||!S.test(e)?"":e}).replace(/:[a-z-]+\(\)/gm,"");return""==n||(n in a?a[n]:a[n]=I(t.nodes,n)||!0!==r(e))}var s;return!1}));var O=function(e){for(var t="",r=0,n=0;n<e.length;n++)switch(e[n]){case m:var a=e[++n];(r=a.length)>0&&(t+=a.join());break;case v:r>0&&(t+="{"+e[++n]+"}");break;case h:t+=e[++n]+"{";break;case p:t+="}";break;case x:t+=e[++n]}return b(t)}(n);return{css:b(O=function(e,t){for(var r,n=[],a=new Set,s=/@font-face[\s\S]+?font-family:\s*(['"\w-]+)[^}]+\}/gm;r=s.exec(e);){var i=r[1].replace(/['"]/gm,"");n.push([r.index,r[0].length,i])}for(var c=/font-family:([^;!}]+)/gm;r=c.exec(e);)n.some(function(e){return r.index>e[0]&&r.index<e[0]+e[1]})||r[1].trim().split(",").forEach(function(e){a.add(e.trim().replace(/['"]/gm,""))});return L(e,n,a,t,"@font-face ")}(O=function(e,t){for(var r,n=[],a=new Set,s=/@(?:-\w+-)?keyframes\s+([\w-]+)\s*\{/gm;r=s.exec(e);){var i=g(e,s.lastIndex);n.push([r.index,r[0].length+i.length+1,r[1]])}for(var c=/animation(?:-name)?:([^;!}]+)/gm;r=c.exec(e);)r[1].trim().split(",").forEach(function(e){var t=(e=e.trim()).match(/^\S+/)[0];/^-?[\d.]+m?s/.test(t)&&(t=e.match(/\S+$/)[0]),a.add(t)});return L(e,n,a,t,"@keyframes ")}(O,r),r))}}}); | ||
/*! https://github.com/leeoniya/dropcss (v1.0.4) */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).dropcss=t()}(this,function(){"use strict";var e=1,t=2,n=3,r=new Set("area base br col command embed hr img input keygen link meta param source track wbr".split(" ")),a=/<!doctype[^>]*>|<!--[\s\S]*?-->|<script[^>]*>[\s\S]*?<\/script>|<style[^>]*>[\s\S]*?<\/style>|<link[^>]*>|<meta[^>]*>/gim,s=/([\w-]+)(?:="([^"]*)"|='([^']*)'|=(\S+))?/gm,i={TAG_HEAD:/\s*<([a-z0-9_-]+)(?:\s+([^>]*))?>\s*/imy,TEXT:/\s*[^<]*/my,TAG_CLOSE:/\s*<\/[a-z0-9_-]+>\s*/imy};var c=new Set;function o(e,t,n){return{tagName:t,attributes:n,classList:null!=n&&n.has("class")?new Set(n.get("class").split(/\s+/g)):c,parentNode:e,childNodes:[]}}function l(e,t){if(null!=e){var n=e._ofTypes=e._ofTypes||{};if(!(t in n)){var r=0;n[t]=e.childNodes.filter(function(e){if(e.tagName==t)return e._typeIdx=r++,!0})}return n[t]}return null}var u=function(l){var u=function(a){var c,o=0,l=[];function u(e){for(var t in o=e.lastIndex,i)i[t].lastIndex=o}function d(){if(null!=(c=i.TAG_CLOSE.exec(a)))return u(i.TAG_CLOSE),void l.push(n);if(null==(c=i.TAG_HEAD.exec(a)))null!=(c=i.TEXT.exec(a))&&u(i.TEXT);else{u(i.TAG_HEAD);var o=c[1];l.push(e,o);var d=c[2];if(null!=d){for(var f,h=new Map;f=s.exec(d);)h.set(f[1],(f[2]||f[3]||f[4]||"").trim());l.push(t,h)}r.has(o)&&l.push(n)}}for(;o<a.length;)d();return u({lastIndex:0}),l}(l=l.replace(a,"")),d={nodes:[],tag:new Set(["*"]),class:new Set,attr:new Set};!function(r,a){for(var s,i=o(null,"root",c),l=0;l<r.length;l++)switch(r[l]){case e:var u=r[++l],d=c;r[l+1]===t&&(d=r[l+=2]),s=i.childNodes.length,i.childNodes.push(i=o(i,u,d)),a(i,s);break;case n:i=i.parentNode}}(u,function(e,t){return function(e,t,n){e.idx=t;var r=e.attributes;n.tag.add(e.tagName),e.classList.forEach(function(e){return n.class.add(e)}),r.has("id")&&n.attr.add("[id="+r.get("id")+"]"),r.has("type")&&n.attr.add("[type="+r.get("type")+"]"),n.nodes.push(e)}(e,t,d)});return d},d=/\s*\/\*[\s\S]*?\*\/\s*/gm,f=/\s*[>~+.#]\s*|\[[^\]]+\]|\s+/gm,h=1,p=2,v=3,x=4,m=5;function g(e){var t=e.split(/\s*,\s*/gm);return t.push(t.map(function(e){return function(e){for(var t=e.length;(e=e.replace(y,"")).length!=t;)t=e.length;return e.replace(/:?:[a-z-]+/gm,"")}(e).trim().replace(f,function(e,t){return e=e.trim(),0==t?e:"."==e||"#"==e?"`"+e:e.length<=1?"`":"`"+e.replace(/['"]/gm,"")}).split(/`+/gm)})),t}var y=/:[a-z-]+\([^()]*\)/;function b(e,t,n,r){for(var a="",s=1;e[t]==n?s++:e[t]==r&&s--,0!=s;)a+=e[t++];return a}function k(e){return function(e){var t,n={RULE_HEAD:/\s*([^{;]+?)\s*[{;]\s*/my,RULE_TAIL:/\s*([^}]*?)\s*\}/my,AT_TAIL:/\s*\}/my,RULE_FULL:/\s*([^{]*?)\{([^}]+?)\}/my},r=0,a=0,s=[];function i(e){for(var t in a=e.lastIndex,n)n[t].lastIndex=a}function c(){if(r>0&&null!=(t=n.AT_TAIL.exec(e)))return r--,s.push(p),void i(n.AT_TAIL);if(null!=(t=n.RULE_HEAD.exec(e))){var c=t[1];if(i(n.RULE_HEAD),"@"==c[0])switch(c.match(/@[a-z-]+/)[0]){case"@media":case"@supports":case"@document":r++,s.push(h,c);break;case"@import":case"@charset":case"@namespace":s.push(m,c+";");break;default:r++;var o=b(e,a,"{","}");i({lastIndex:a+o.length}),s.push(h,c,m,o)}else s.push(v,g(t[1])),t=n.RULE_TAIL.exec(e),s.push(x,t[1]),i(n.RULE_TAIL)}else a=e.length}for(;a<e.length;)c();return s}(e=e.replace(d,""))}function E(e){return e.replace(/@[a-z-]+[^{]+\{\s*\}/gm,"")}var T=/^([+-]?\d*)?n([+-]\d+)?$/;function I(e,t){return t==e.tagName||"*"==t}function _(e,t,n,r){r=r||"=";var a=e.attributes;if(a.has(t)){var s=a.get(t);switch(r){case"=":return null==n||n==s;case"*=":return-1!=s.indexOf(n);case"^=":return s.startsWith(n);case"$=":return s.endsWith(n);case"~=":return n==s||s.startsWith(n+" ")||s.endsWith(" "+n)||-1!=s.indexOf(" "+n+" ")}}return!1}function A(e,t){return e.classList.has(t)}function w(e,t){var n;if("odd"==t)n=e%2==1;else if("even"==t)n=e%2==0;else if(/^\d+$/.test(t))n=e==+t;else{var r=function(e){var t=T.exec(e);if(null!=t){var n=t[1],r=t[2];return[n=null==n||"+"==n?1:"-"==n?-1:+n,r=null==r?0:+r]}return[0,0]}(t);n=function(e,t,n){if(t<0&&e<=0)return!1;if(-1===e)return n<=t;if(0===e)return n===t;if(1===e)return t<0||n>=t;var r=t%e;return r<0&&(r+=e),e>1?n>=t&&n%e===r:(e*=-1,n<=t&&n%e===r)}(r[0],r[1],e)}return n}function N(e,t){return e.some(function(e){return function e(t,n){for(var r,a,s,i,c,o;n.idx>-1;){switch(t[n.idx]){case"_":r=t[--n.idx],o=I(n.node,r),n.idx--;break;case"#":a=t[--n.idx],o=_(n.node,"id",a,"="),n.idx--;break;case".":r=t[--n.idx],o=A(n.node,r),n.idx--;break;case"[":r=t[--n.idx],s=t[--n.idx],a=t[--n.idx],o=_(n.node,r,a,s),n.idx--;break;case":":r=t[--n.idx],a=t[--n.idx];var u=n.node,d=u.tagName;c=u.idx;var f=(i=u.parentNode)?i.childNodes.length:1,h=void 0;switch(r){case"not":o=!e(a,{node:n.node,idx:a.length-1});break;case"first-child":o=0==c;break;case"last-child":o=c==f-1;break;case"only-child":o=1==f;break;case"nth-child":o=w(c+1,a);break;case"nth-last-child":o=w(f-c,a);break;case"first-of-type":h=l(i,d),o=0==u._typeIdx;break;case"last-of-type":h=l(i,d),o=u._typeIdx==h.length-1;break;case"only-of-type":o=1==(h=l(i,d)).length;break;case"nth-of-type":h=l(i,d),o=w(u._typeIdx+1,a);break;case"nth-last-of-type":o=w((h=l(i,d)).length-u._typeIdx,a)}n.idx--;break;case" ":for(c=--n.idx,o=!1;!o&&null!=(i=n.node.parentNode);)n.idx=c,n.node=i,o=e(t,n);break;case">":n.idx--,null!=(i=n.node.parentNode)?(n.node=i,o=e(t,n)):o=!1;break;case"+":n.idx--,null!=(i=n.node.parentNode)&&n.node.idx>0?(n.node=i.childNodes[n.node.idx-1],o=e(t,n)):o=!1;break;case"~":if(n.idx--,o=!1,c=n.node.idx,null!=(i=n.node.parentNode)&&c>0)for(var p=0;p<c&&!o;p++)n.node=i.childNodes[p],o=e(t,n)}if(!o)break}return o}(t,{idx:t.length-1,node:e})})}var S=function(e,t){return N(e,Array.isArray(t)?t:function e(t){var n,r={IDENT:/([\w*-]+)/iy,ATTR:/([\w-]+)(?:(.?=)"?([^\]]*?)"?)?\]/iy,PSEUDO:/([\w-]+)(\()?/iy,MODE:/\s*[:.#\[]\s*/iy,COMB:/\s*[>~+]\s*|\s+/iy},a=0,s=[],i=-1;function c(e){for(var t in a=e.lastIndex,r)r[t].lastIndex=a}function o(){var o=!1;if(n=r.COMB.exec(t)){o=!0;var l=n[0].trim();""==l&&(l=" "),s.push(l),c(r.COMB),i=a}else if(n=r.MODE.exec(t)){o=!0;var u=n[0].trim();if(c(r.MODE),":"==u){if("("==(n=r.PSEUDO.exec(t))[2]){var d=b(t,r.PSEUDO.lastIndex,"(",")");r.PSEUDO.lastIndex+=d.length+1,n[2]="not"==n[1]?e(d):d}s.splice(i+1,0,n[2],n[1],u),c(r.PSEUDO)}else"["==u?(n=r.ATTR.exec(t),s.splice(i+1,0,n[3],n[2],n[1],u),c(r.ATTR)):(n=r.IDENT.exec(t),s.push(n[1],u),c(r.IDENT))}else(n=r.IDENT.exec(t))&&(o=!0,s.push(n[1],"_"),c(r.IDENT));return o}for(;a<t.length;)o();return s}(t))},L=/\[([\w-]+)(?:(.?=)"?([^\]]*?)"?)?\]/i,D=/:(?:first|last|nth|only|not)\b/;function O(e,t,n,r,a){a=a||"";for(var s=t.length-1;s>-1;s--){var i=t[s];n.has(i[2])||!0!==r(a+i[2])||(c=e,o=i[0],l=i[1],u="",e=c.slice(0,o)+u+c.slice(o+l))}var c,o,l,u;return e}var U=function(e){return!0};return function(e){for(var t=u(e.html,!e.keepText),n=e.shouldDrop||U,r=k(e.css),a={},s=0;s<r.length;s++)if(r[s]===v){var i=r[s+1],c=i[i.length-1];s++;for(var o=0;o<c.length;o++){var l=c[o];e:for(var d=0;d<l.length;d++){var f=l[d],g=!1,y=void 0;if(""!=f){if(f in a)g=a[f];else switch(f[0]){case"#":y=f.substr(1),a[f]=g=t.attr.has("[id="+y+"]");break;case".":y=f.substr(1),a[f]=g=t.class.has(y);break;case"[":if(f.startsWith("[type="))a[f]=g=t.attr.has(f);else{var T=f.match(L);a[f]=g=t.nodes.some(function(e){return _(e,T[1],T[3],T[2])})}break;default:a[f]=g=t.tag.has(f)}if(!g){!0===n(i[o])?i[o]=null:a[i[o]]=!0;break e}}}}}for(var I=0;I<r.length;I++)r[I]===v&&(r[++I].length,r[I]=r[I].filter(function(e){if("string"==typeof e){if(e in a)return a[e];var r=(s=e).replace(/:?:[a-z-]+/gm,function(e){return s.startsWith("::")||!D.test(e)?"":e}).replace(/:[a-z-]+\(\)/gm,"");return""==r||(r in a?a[r]:a[r]=S(t.nodes,r)||!0!==n(e))}var s;return!1}));var A=function(e){for(var t="",n=0,r=0;r<e.length;r++)switch(e[r]){case v:var a=e[++r];(n=a.length)>0&&(t+=a.join());break;case x:n>0&&(t+="{"+e[++r]+"}");break;case h:t+=e[++r]+"{";break;case p:t+="}";break;case m:t+=e[++r]}return E(t)}(r);return{css:E(A=function(e,t){for(var n,r=[],a=new Set,s=/@font-face[\s\S]+?font-family:\s*(['"\w-]+)[^}]+\}/gm;n=s.exec(e);){var i=n[1].replace(/['"]/gm,"");r.push([n.index,n[0].length,i])}for(var c=/font-family:([^;!}]+)/gm;n=c.exec(e);)r.some(function(e){return n.index>e[0]&&n.index<e[0]+e[1]})||n[1].trim().split(",").forEach(function(e){a.add(e.trim().replace(/['"]/gm,""))});return O(e,r,a,t,"@font-face ")}(A=function(e,t){for(var n,r=[],a=new Set,s=/@(?:-\w+-)?keyframes\s+([\w-]+)\s*\{/gm;n=s.exec(e);){var i=b(e,s.lastIndex,"{","}");r.push([n.index,n[0].length+i.length+1,n[1]])}for(var c=/animation(?:-name)?:([^;!}]+)/gm;n=c.exec(e);)n[1].trim().split(",").forEach(function(e){var t=(e=e.trim()).match(/^\S+/)[0];/^-?[\d.]+m?s/.test(t)&&(t=e.match(/\S+$/)[0]),a.add(t)});return O(e,r,a,t,"@keyframes ")}(A,n),n))}}}); |
{ | ||
"name": "dropcss", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "An exceptionally fast, thorough and tiny unused-CSS cleaner", | ||
@@ -5,0 +5,0 @@ "main": "./dist/dropcss.cjs.js", |
@@ -8,3 +8,3 @@ ## ๐ DropCSS | ||
DropCSS is an exceptionally fast, thorough and tiny ([~8 KB min](https://github.com/leeoniya/dropcss/tree/master/dist/dropcss.min.js)) unused-CSS cleaner; it takes your HTML and CSS as input and returns only the used CSS as output. Its custom HTML and CSS parsers are highly optimized for the 99% use case and thus avoid the overhead of handling malformed markup or stylesheets, so you must provide well-formed input. There is minimal handling for complex escaping rules, so there will always exist cases of valid input that cannot be processed by DropCSS; for these infrequent cases, please [start a discussion](https://github.com/leeoniya/dropcss/issues). | ||
DropCSS is an exceptionally fast, thorough and tiny ([~8.5 KB min](https://github.com/leeoniya/dropcss/tree/master/dist/dropcss.min.js)) unused-CSS cleaner; it takes your HTML and CSS as input and returns only the used CSS as output. Its custom HTML and CSS parsers are highly optimized for the 99% use case and thus avoid the overhead of handling malformed markup or stylesheets, so you must provide well-formed input. There is minimal handling for complex escaping rules, so there will always exist cases of valid input that cannot be processed by DropCSS; for these infrequent cases, please [start a discussion](https://github.com/leeoniya/dropcss/issues). | ||
@@ -92,2 +92,3 @@ As a bonus, DropCSS will also remove unused `@keyframes` and `@font-face` blocks - an out-of-scope, purely intra-CSS optimization. Speaking of which, it's a good idea to run your CSS through a structural optimizer like [clean-css](https://github.com/jakubpawlowicz/clean-css), [csso](https://github.com/css/csso), [cssnano](https://github.com/cssnano/cssnano) or [crass](https://github.com/mattbasta/crass) to re-group selectors, merge redundant rules, etc. It probably makes sense to do this after DropCSS, which can leave redundant blocks, e.g. `.foo, .bar { color: red; }; .bar { width: 50%; }` -> `.bar { color: red; }; .bar { width: 50%; }` if `.foo` is absent from your markup. | ||
- `[attr$=val]` | ||
- `[attr~=val]` | ||
- `:not()` | ||
@@ -94,0 +95,0 @@ - `:first-child` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63313
1630
301