forked from imsky/cssFx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cssfx.min.js
1 lines (1 loc) · 4.97 KB
/
cssfx.min.js
1
var cssFx=cssFx||{};(function(a){function h(a,b){var c=function(a){for(a=0;a<4;a++)try{return a?new ActiveXObject([,"Msxml2","Msxml3","Microsoft"][a]+".XMLHTTP"):new XMLHttpRequest}catch(b){}};if(r=c())r.onreadystatechange=function(){r.readyState==4&&b(r.responseText)},r.open("GET",a,!0),r.send(g)}function i(a,b){return a.replace(b!=g?/\/\*([\s\S]*?)\*\//gim:"","").replace(/\n/gm,"").replace(/^\s\s*/,"").replace(/\s\s*$/,"").replace(/\s{2,}|\t/gm," ")}function j(a,b,c){return((256+a<<8|b)<<8|c).toString(16).slice(1)}function l(a,b){for(var c=b.length,d=0;d<c;d++)if(b[d]==a)return!0;return!1}function m(a,b){for(var c=a.length,d=0;d<c;d++)b.call(this,a[d])}var b="text-overflow",c="-timing-function",d="-duration",e="-image",f="transition",g=null,n="animation",o="border",p="background",q="box-",s="column",t=f,u=["-moz-","-webkit-","-o-","-ms-"],v=[p+"-origin",p+"-size",o+e,o+"-image-outset",o+"-image-repeat",o+"-image-source",o+"-image-width",o+"-radius",q+"shadow",s+"-count",s+"-gap",s+"-rule",s+"-rule-color",s+"-rule-style",s+"-rule-width",s+"-width"],w=[q+"flex",q+"orient",q+"align",q+"ordinal-group",q+"flex-group",q+"pack",q+"direction",q+"lines",q+"sizing",n+d,n+"-name",n+"-delay",n+"-direction",n+"-iteration-count",n+"-play-state",n+c,n+"-fill-mode"],x=["transform","transform-origin",t+"",t+"-property",t+d,t+c,t+"-delay","user-select"],y=[p+"-clip",o+"-bottom-left-radius",o+"-bottom-right-radius",o+"-top-left-radius",o+"-top-right-radius"],z=y.concat(x).concat(v).concat(w),A=["display","opacity",b,p+e,p].concat(z);a.processCSS=function(b){for(var c=[],d=/([\s\S]*?)\{([\s\S]*?)\}/gim,e=/\@import\s+(?:url\([\'\"]|[\'\"])([\w\s\-\_\.\:\/\;\:]+)/gim,f=/@keyframes\s*([^\{]*)\{([^@]*)\}/g,h=0;h<b.length;h++){var j=b[h];j=i(j,1);var l=[],n=e.test(j)&&j.match(e),o=f.test(j)&&j.match(f);e.lastIndex=0,f.lastIndex=0;for(var p=0;p<n.length;p++)b.push(a.fetchCSS([e.exec(n[p])[1]])[0]),e.lastIndex=0;for(var p=0,q=o.length;p<q;p++){j=j.replace(o[p],"");if(keyframe=f.exec(o[p])){for(var r=keyframe[2].match(d),s=[],t=0;t<r.length;t++)(k=d.exec(r[t]))&&s.push(i(k[1])+"{"+a.processDec(k[2],!0)+"}"),d.lastIndex=0;m([0,1,3],function(a){l.push("@"+u[a]+"keyframes "+i(keyframe[1])+"{"+s.join("\n")+"}")})}f.lastIndex=0}var v=d.test(j)&&j.match(d);d.lastIndex=0;for(var w=0,x=v.length;w<x;w++){var y=d.exec(v[w]);if(y!==g)for(var z=i(y[1],1),B=i(y[2],1),C=0,D=A.length;C<D;C++)if(!!~B.indexOf(A[C])){(new_dec=a.processDec(B))&&l.push(z+"{"+new_dec+"}");break}d.lastIndex=0}l.length>0&&c.push(l.join("\n"))}return c},a.insertCSS=function(a){for(var b=0;b<a.length;b++){var c=document.createElement("style");c.setAttribute("type","text/css"),c.styleSheet?c.styleSheet.cssText=a[b]:c.textContent=a[b],document.getElementsByTagName("head")[0].appendChild(c)}},a.processDec=function(a,c){var d="display:",h=":";for(var k=a.split(";"),n=[],o=0;o<k.length;o++)if(!!~k[o].indexOf(h)){var a=k[o].split(h);if(a.length!=2)return!1;var q=i(a[0]),r=i(a[1]),s=[q,r].join(h),t=[];if(l(q,v))t.push(u[0]+s),t.push(u[1]+s);else if(l(q,w))t.push(u[0]+s),t.push(u[1]+s),q==="box-align"?t.push(u[3]+q+":middle"):t.push(u[3]+s);else if(l(q,x))m([0,1,2,3],function(a){if(q==f){var b=r.split(" ")[0];l(b,z)?t.push(u[a]+s.replace(b,u[a]+b)):t.push(u[a]+s)}else if(q=="transition-property"){if(a==0){var c=r.split(","),d=[];m(c,function(b){var c=i(b);l(c,z)&&d.push(u[a]+c)}),t.push(u[a]+q+h+d.join(","))}}else t.push(u[a]+s)});else if(l(q,y))if(q==p+"-clip")r==="padding-box"&&(t.push(u[1]+s),t.push(u[0]+q+":padding"));else{var A=q.split("-");t.push(u[0]+"border-radius-"+A[1]+A[2]+h+r),t.push(u[1]+s)}else switch(q){case"display":r==="box"?m([0,1,3],function(a){t.push(d+u[a]+r)}):r==="inline-block"&&(t.push(d+u[0]+"inline-stack"),t.push("zoom:1;*display:inline"));break;case b:r==="ellipsis"&&t.push(u[2]+s);break;case"opacity":var B=parseInt(parseFloat(r)*100);t.push(u[3]+"filter:progid:DXImageTransform.Microsoft.Alpha(Opacity="+B+")"),t.push("filter: alpha(opacity="+B+")"),t.push(u[0]+s),t.push(u[1]+s);break;case p+e:case p+"-color":case p:var C="linear-gradient";if(!~r.indexOf(C)){if(!!~r.indexOf("rgba")){var F=r.match(/rgba\((.*?)\)/)[1].split(","),G=Math.floor(+i(F[3])*255).toString(16)+j(+i(F[0]),+i(F[1]),+i(F[2]));t.push("filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#"+G+",endColorstr=#"+G+");zoom:1")}}else{var D=r.substr(C.length);q==="background-image"&&(D=r.substr(C.length).match(/\((.*)\)/)[0]);var E=C+D;m([0,1,2,3],function(a){t.push(q+h+u[a]+E)})}break;default:c!==g&&t.push(s)}t.length>0&&n.push(t.join(";"))}return n.length>0?n.join(";"):!1},a.fetchCSS=function(b,c){c===undefined&&(c=function(b){a.insertCSS(a.processCSS([b]))}),h(b,c)};var B=function(){var b=document.getElementsByTagName("style"),c=document.getElementsByTagName("link");for(var d in c)typeof c[d]=="object"&&c[d].className==="cssfx"&&a.fetchCSS(c[d].href);var e=[];for(var d in b)typeof b[d]=="object"&&e.push(b[d].innerHTML);a.insertCSS(a.processCSS(e))};window.addEventListener?window.addEventListener("load",B,!1):window.attachEvent?window.attachEvent("onload",B):g})(cssFx)