forked from imsky/cssFx
/
cssfx.min.js
1 lines (1 loc) · 5.66 KB
/
cssfx.min.js
1
var cssFx=cssFx||{};(function(n){var g="text-overflow",tt="-timing-function",it="-duration",b="-image",rt="transition",s=null;function ct(n,t){var i=function(n){for(n=0;n<4;n++)try{return n?new ActiveXObject([,"Msxml2","Msxml3","Microsoft"][n]+".XMLHTTP"):new XMLHttpRequest}catch(t){}};(r=i())&&(r.onreadystatechange=function(){r.readyState==4&&t(r.responseText)},r.open("GET",n,!0),r.send(s))}function lt(n){var i=window,c="complete",h="readystatechange",r=!1,l=r,a=!0,t=i.document,s=t.documentElement,e=t.addEventListener?"addEventListener":"attachEvent",v=t.addEventListener?"removeEventListener":"detachEvent",f=t.addEventListener?"":"on",u=function(e){(e.type!=h||t.readyState==c)&&((e.type=="load"?i:t)[v](f+e.type,u,r),!l&&(l=!0)&&n.call(i,e.type||e))},o=function(){try{s.doScroll("left")}catch(n){setTimeout(o,50);return}u("poll")};if(t.readyState==c)n.call(i,"lazy");else{if(t.createEventObject&&s.doScroll){try{a=!i.frameElement}catch(y){}a&&o()}t[e](f+"DOMContentLoaded",u,r),t[e](f+h,u,r),i[e](f+"load",u,r)}}function i(n,t){return n.replace(t!=s?/\/\*([\s\S]*?)\*\//gim:"","").replace(/\n/gm,"").replace(/^\s\s*/,"").replace(/\s\s*$/,"").replace(/\s{2,}|\t/gm," ")}function at(n,t,i){return((256+n<<8|t)<<8|i).toString(16).slice(1)}function c(n,t){for(var r=t.length,i=0;i<r;i++)if(t[i]==n)return!0;return!1}function y(n,t){for(var r=n.length,i=0;i<r;i++)t.call(this,n[i])}var o="animation",u="border",e="background",f="box-",h="column",v=rt,t=["-moz-","-webkit-","-o-","-ms-"],l=t[0],a=t[1],ht=t[2],p=t[3],ft=[e+"-origin",e+"-size",u+b,u+"-image-outset",u+"-image-repeat",u+"-image-source",u+"-image-width",u+"-radius",f+"shadow",h+"-count",h+"-gap",h+"-rule",h+"-rule-color",h+"-rule-style",h+"-rule-width",h+"-width"],ot=[f+"flex",f+"orient",f+"align",f+"ordinal-group",f+"flex-group",f+"pack",f+"direction",f+"lines",f+"sizing",o+it,o+"-name",o+"-delay",o+"-direction",o+"-iteration-count",o+"-play-state",o+tt,o+"-fill-mode"],et=["transform","transform-origin",v,v+"-property",v+it,v+tt,v+"-delay","user-select"],st=[e+"-clip",u+"-bottom-left-radius",u+"-bottom-right-radius",u+"-top-left-radius",u+"-top-right-radius"],w=st.concat(et).concat(ft).concat(ot),nt=["display","opacity",g,e+b,e].concat(w),ut="filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='{1}', endColorstr='{2}',GradientType=0)",d;n.processCSS=function(r,u){for(var ot=[],o=/([\s\S]*?)\{([\s\S]*?)\}/gim,c=/\@import\s+(?:url\([\'\"]?(.*)[\'\"]?\))\s*\;?/gim,h=/@keyframes\s*([^\{]*)\{([^@]*)\}/g,l,lt,f,ht,ut,ft,v,tt,w,ct,p,st,it,a,et,b=0;b<r.length;b++){var e=i(r[b],1),d=[],g=c.test(e)&&e.match(c),rt=h.test(e)&&e.match(h);for(c.lastIndex=0,h.lastIndex=0,f=0;f<g.length;f++)e=e.replace(g[f],""),l=c.exec(g[f])[1],lt=l[0]=="/"?l:u.replace(/[^\/]*?$/,"")+l,n.fetchCSS(lt,function(t){n.insertCSS(n.processCSS([t],u))}),c.lastIndex=0;for(f=0,ht=rt.length;f<ht;f++){if(e=e.replace(rt[f],""),keyframe=h.exec(rt[f])){for(ut=keyframe[2].match(o),ft=[],v=0;v<ut.length;v++)(k=o.exec(ut[v]))&&ft.push(i(k[1])+"{"+n.processDec(k[2],!0)+"}"),o.lastIndex=0;y([0,1,3],function(n){d.push("@"+t[n]+"keyframes "+i(keyframe[1])+"{"+ft.join("\n")+"}")})}h.lastIndex=0}for(tt=o.test(e)&&e.match(o),o.lastIndex=0,w=0,ct=tt.length;w<ct;w++){if(p=o.exec(tt[w]),p!==s)for(st=i(p[1],1),it=i(p[2],1),a=0,et=nt.length;a<et;a++)if(!!~it.indexOf(nt[a])){(new_dec=n.processDec(it))&&d.push(st+"{"+new_dec+"}");break}o.lastIndex=0}d.length&&ot.push(d.join("\n"))}return ot},n.insertCSS=function(n){for(var t,i=0;i<n.length;i++)t=document.createElement("style"),t.setAttribute("type","text/css"),t.styleSheet?t.styleSheet.cssText=n[i]:t.textContent=n[i],document.getElementsByTagName("head")[0].appendChild(t)},n.processDec=function(n,r){var wt="display:",k=":";for(var lt=n.split(";"),vt=[],n,yt,pt,it,d,bt,v,tt,ct,nt=0;nt<lt.length;nt++)if(!!~lt[nt].indexOf(k)){if(n=lt[nt].split(k),n.length!=2)return!1;var f=i(n[0]),h=i(n[1]),o=[f,h].join(k),u=[];if(c(f,ft))u.push(l+o,a+o);else if(c(f,ot))u.push(l+o,a+o,f=="box-align"?p+f+":middle":p+o);else if(c(f,et))y([0,1,2,3],function(n){var r,s,e;f==rt?(r=h.split(" ")[0],c(r,w)?u.push(t[n]+o.replace(r,t[n]+r)):u.push(t[n]+o)):f=="transition-property"?n==0&&(s=h.split(","),e=[],y(s,function(r){var u=i(r);c(u,w)&&e.push(t[n]+u)}),u.push(t[n]+f+k+e.join(","))):u.push(t[n]+o)});else if(c(f,st))f==e+"-clip"?h==="padding-box"&&u.push(a+o,l+f+":padding"):(yt=f.split("-"),u.push(l+"border-radius-"+yt[1]+yt[2]+k+h,a+o));else switch(f){case"display":h=="box"?y([0,1,3],function(n){u.push(wt+t[n]+h)}):h=="inline-block"&&u.push(wt+l+"inline-stack","zoom:1;*display:inline");break;case g:h=="ellipsis"&&u.push(ht+o);break;case"opacity":pt=Math.round(h*100),u.push(p+"filter:progid:DXImageTransform.Microsoft.Alpha(Opacity="+pt+")","filter: alpha(opacity="+pt+")",l+o,a+o);break;case e+b:case e+"-color":case e:it="linear-gradient",~h.indexOf(it)?(d=new RegExp(it+"\\s?\\((.*)\\)","ig").exec(h),d[1]!=s&&(d=d[1],bt=it+"("+d+")",y([0,1,2,3],function(n){u.push(f+k+t[n]+bt)}),v=d.match(/\#([a-z0-9]{3,})/g),v.length>1&&v[v.length-1]!=s&&u.push(ut.replace("{1}",v[0]).replace("{2}",v[v.length-1])))):!~h.indexOf("rgba")||(tt=h.match(/rgba\((.*?)\)/)[1].split(","),ct=Math.floor(+i(tt[3])*255).toString(16)+at(+i(tt[0]),+i(tt[1]),+i(tt[2])),u.push(ut.replace("{1}","#"+ct).replace("{2}","#"+ct)+";zoom:1"));break;default:r!=s&&u.push(o)}u.length&&vt.push(u.join(";"))}return vt.length&&vt.join(";")},n.fetchCSS=function(t,i){ct(t,i==s?function(i){n.insertCSS(n.processCSS([i],t))}:i)},d=function(){var u=document.getElementsByTagName("style"),r=document.getElementsByTagName("link"),i,t;for(t in r)typeof r[t]=="object"&&r[t].className==="cssfx"&&n.fetchCSS(r[t].href);i=[];for(t in u)typeof u[t]=="object"&&i.push(u[t].innerHTML);i.length&&n.insertCSS(n.processCSS(i))},lt(d)})(cssFx);