/
prefixfree.min.js
14 lines (14 loc) · 4.16 KB
/
prefixfree.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
* PrefixFree 1.0.4
* @author Lea Verou
* MIT license
*/
(function(l){function k(a,d){return[].slice.call((d||document).querySelectorAll(a))}if(window.getComputedStyle&&window.addEventListener){var a=window.PrefixFree={prefixCSS:function(b,d){function e(f,d,e,c){f=a[f];d=d||(c!=void 0?c:"")+g+"$1"+(e!=void 0?e:"");f.length&&(f=RegExp((c!=void 0?c:"\\b")+"("+f.join("|")+")"+(e!=void 0?e:"\\b"),"gi"),b=b.replace(f,d))}var g=a.prefix;e("functions",g+"$1(","\\s*\\(");e("keywords",null);e("properties",g+"$1:","\\s*:");if(a.properties.length){var c=RegExp("\\b("+
a.properties.join("|")+")(?!:)","gi");e("valueProperties",function(a){return a.replace(c,g+"$1")},":(.+?);")}d&&(e("selectors",a.prefixSelector,"\\b",""),e("atrules",null,void 0,"@"));return b=b.replace(RegExp("-"+g,"g"),"-")},process:{link:function(b){try{if(!/\bstylesheet\b/i.test(b.rel)||!b.sheet.cssRules)return}catch(d){return}var e=b.getAttribute("href")||b.getAttribute("data-href"),g=e.replace(/[^\/]+$/,""),c=b.parentNode,f=new XMLHttpRequest;f.open("GET",e);f.onreadystatechange=function(){if(f.readyState===
4){var d=f.responseText;if(d&&b.parentNode){var d=a.prefixCSS(d,true),d=d.replace(/url\((?:'|")?(.+?)(?:'|")?\)/gi,function(a,b){return!/^([a-z]{3,10}:|\/)/i.test(b)?'url("'+g+b+'")':a}),e=document.createElement("style");e.textContent=d;c.insertBefore(e,b);c.removeChild(b)}}};f.send(null)},styleElement:function(b){b.textContent=a.prefixCSS(b.textContent,true)},styleAttribute:function(b){var d=b.getAttribute("style"),d=a.prefixCSS(d);b.setAttribute("style",d)}},prefixSelector:function(b){return b.replace(/^:{1,2}/,
function(b){return b+a.prefix})},prefixProperty:function(b,d){var e=a.prefix+b;return d?a.camelCase(e):e},camelCase:function(a){return a.replace(/-([a-z])/g,function(a,b){return b.toUpperCase()}).replace("-","")},deCamelCase:function(a){return a.replace(/[A-Z]/g,function(a){return"-"+a.toLowerCase()})}};(function(){var b={},d="",e=0,g=[],c=getComputedStyle(document.documentElement,null),f=document.createElement("div").style,h=function(c){g.indexOf(c)===-1&&g.push(c);if(c.indexOf("-")>-1){var i=c.split("-");
if(c.charAt(0)==="-"){var c=i[1],h=++b[c]||1;b[c]=h;for(e<h&&(d=c,e=h);i.length>3;)i.pop(),h=i.join("-"),a.camelCase(h)in f&&(c=g,c.indexOf(h)===-1&&c.push(h))}}};if(c.length>0)for(var i=0;i<c.length;i++)h(c[i]);else for(var j in c)h(a.deCamelCase(j));a.prefix="-"+d+"-";a.Prefix=a.camelCase(a.prefix);g.sort();a.properties=[];for(i=0;i<g.length;i++){j=g[i];if(j.charAt(0)!=="-")break;j.indexOf(a.prefix)===0&&(c=j.slice(a.prefix.length),g.indexOf(c)===-1&&a.properties.push(c))}a.Prefix=="Ms"&&!("transform"in
f)&&!("MsTransform"in f)&&"msTransform"in f&&a.properties.push("transform","transform-origin");a.properties.sort()})();(function(){function b(a,b){g[b]="";g[b]=a;return!!g[b]}var d={"linear-gradient":{property:"backgroundImage",params:"red, teal"},calc:{property:"width",params:"1px + 5%"},element:{property:"backgroundImage",params:"#foo"}},e={initial:"color","zoom-in":"cursor","zoom-out":"cursor"};d["repeating-linear-gradient"]=d["repeating-radial-gradient"]=d["radial-gradient"]=d["linear-gradient"];
a.functions=[];a.keywords=[];var g=document.createElement("div").style,c;for(c in d){var f=d[c],h=f.property,f=c+"("+f.params+")";!b(f,h)&&b(a.prefix+f,h)&&a.functions.push(c)}for(var i in e)h=e[i],!b(i,h)&&b(a.prefix+i,h)&&a.keywords.push(i)})();(function(){function b(a){g.textContent=a+"{}";return!!g.sheet.cssRules.length}var d={":read-only":null,":read-write":null,":any-link":null,"::selection":null},e={keyframes:"name",viewport:null,document:'regexp(".")'};a.selectors=[];a.atrules=[];var g=l.appendChild(document.createElement("style")),
c;for(c in d){var f=c+(d[c]?"("+d[c]+")":"");!b(f)&&b(a.prefixSelector(f))&&a.selectors.push(c)}for(var h in e)f=h+" "+(e[h]||""),!b("@"+f)&&b("@"+a.prefix+f)&&a.atrules.push(h);l.removeChild(g)})();a.valueProperties=["transition","transition-property"];k('link[rel~="stylesheet"]').forEach(a.process.link);l.className+=" "+a.prefix;document.addEventListener("DOMContentLoaded",function(){k('link[rel~="stylesheet"]').forEach(a.process.link);k("style").forEach(a.process.styleElement);k("[style]").forEach(a.process.styleAttribute)},
false)}})(document.documentElement);