diff --git a/dist/dropcss.cjs.js b/dist/dropcss.cjs.js index 337de23..1f4af9c 100644 --- a/dist/dropcss.cjs.js +++ b/dist/dropcss.cjs.js @@ -4,7 +4,7 @@ * * dropcss.js (DropCSS) * An exceptionally fast, thorough and tiny unused-CSS cleaner -* https://github.com/leeoniya/dropcss (v1.0.2) +* https://github.com/leeoniya/dropcss (v1.0.3) */ 'use strict'; diff --git a/dist/dropcss.js b/dist/dropcss.js index 74c5cc7..1852097 100644 --- a/dist/dropcss.js +++ b/dist/dropcss.js @@ -4,7 +4,7 @@ * * dropcss.js (DropCSS) * An exceptionally fast, thorough and tiny unused-CSS cleaner -* https://github.com/leeoniya/dropcss (v1.0.2) +* https://github.com/leeoniya/dropcss (v1.0.3) */ (function (global, factory) { diff --git a/dist/dropcss.min.js b/dist/dropcss.min.js index 6a03869..90d2463 100644 --- a/dist/dropcss.min.js +++ b/dist/dropcss.min.js @@ -1,2 +1,2 @@ -/*! https://github.com/leeoniya/dropcss (v1.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=/]*>||]*>[\s\S]*?<\/script>|]*>[\s\S]*?<\/style>|]*>|]*>/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~+.#]\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=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~+]\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-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;s0&&(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