UNPKG

j2c

Version:

A tiny CSS in JS solution.

1 lines 4.29 kB
define(function(){"use strict";function n(n,e,r,l,o,s){l=[];for(s in e)if(f.call(e,s))for(o in n)f.call(n,o)&&l.push(t(n[o],e[s],r));return l}function t(n,t,e){return e&&(/^[-\w$]+$/.test(t)&&":-error-bad-sub-selector-"+t||/&/.test(t)&&t.replace(/&/g,n))||n+t}function e(n){return"-"+n.toLowerCase()}function r(n,t,l,o,s,a,i,u,g){if(null!=n)if(/\$/.test(l))for(g in l=l.split("$"))f.call(l,g)&&r(n,t,l[g],o,s,a);else switch(c.call(n=n.valueOf())){case h:for(i=0;i<n.length;i++)r(n[i],t,l,o,s,a);break;case p:l=l&&l+"-";for(i in n)if(f.call(n,i))if(u=n[i],/\$/.test(i))for(g in i=i.split("$"))f.call(i,g)&&r(u,t,l+i[g],o,s,a);else r(u,t,l+i,o,s,a);break;default:for(i=l.replace(/_/g,"-").replace(/[A-Z]/g,e),!s||"animation-name"!=i&&"animation"!=i||(n=n.split(",").map(function(n){return n.replace(/()(?::global\(\s*([-\w]+)\s*\)|()([-\w]+))/,a.l)}).join(",")),/^animation|^transition/.test(i)&&(o=["webkit"]),i=i.replace(/^@/,"*"),g=0;g<o.length;g++)t.push("-",o[g],"-",i,i?":":"",n,";\n");t.push(i,i?":":"",n,";\n")}}function l(n,t,e,r,l,s,a,i){var f;if(/^@(?:namespace|import|charset)$/.test(n))if(c.call(t)==h)for(f=0;f<t.length;f++)e.push(n," ",t[f],";\n");else e.push(n," ",t,";\n");else if(/^@keyframes /.test(n))n=a?n.replace(/( )(?::global\(\s*([-\w]+)\s*\)|()([-\w]+))/,i.l):n,e.push("@-webkit-",n.slice(1)," {\n"),o(t,e,"","",["webkit"]),e.push("}\n"),e.push(n," {\n"),o(t,e,"","",s,a,i),e.push("}\n");else if(/^@extends?$/.test(n)){for(;f=w.exec(l);)n=f[4];if(null==n||!a)return void e.push("@-error-cannot-extend-in-global-context ",JSON.stringify(l),";\n");if(/^@extends?$/.test(n))return void e.push("@-error-no-class-to-extend-in ",JSON.stringify(l),";\n");i.e(c.call(t)==h?t.map(function(n){return n.replace(/()(?::global\(\s*(\.[-\w]+)\s*\)|()\.([-\w]+))/,i.l)}).join(" "):t.replace(/()(?::global\(\s*(\.[-\w]+)\s*\)|()\.([-\w]+))/,i.l),n)}else/^@(?:font-face$|viewport$|page )/.test(n)?o(t,e,n,n,u):/^@global$/.test(n)?o(t,e,r,l,s,0,i):/^@local$/.test(n)?o(t,e,r,l,s,1,i):/^@(?:media |supports |document )./.test(n)?(e.push(n," {\n"),o(t,e,r,l,s,a,i),e.push("}\n")):e.push("@-error-unsupported-at-rule ",JSON.stringify(n),";\n")}function o(e,s,a,i,u,f,w){var b,d,m,$;switch(c.call(e)){case h:for(b=0;b<e.length;b++)o(e[b],s,a,i,u,f,w);break;case p:for(b in e)m=e[b],a&&/^[-\w$]+$/.test(b)?($||($=1,s.push(a||"*"," {\n")),r(m,s,b,u,f,w)):/^@/.test(b)?($=$&&s.push("}\n")&&0,l(b,m,s,a,i,u,f,w)):($=$&&s.push("}\n")&&0,o(m,s,(d=/,/.test(a)||a&&/,/.test(b))?n(a.split(","),(f?b.replace(/()(?::global\(\s*(\.[-\w]+)\s*\)|(\.)([-\w]+))/g,w.l):b).split(","),a).join(","):t(a,f?b.replace(/()(?::global\(\s*(\.[-\w]+)\s*\)|(\.)([-\w]+))/g,w.l):b,a),d?n(i.split(","),b.split(","),i).join(","):t(i,b,i),u,f,w));$&&s.push("}\n");break;case g:s.push(a||":-error-no-selector"," {\n"),r(e,s,"",u,f,w),s.push("}\n")}}function s(t){function e(n,t){for(t=0;t<l.length;t++)n=l[t](n)||n;return n.join("")}t=t||{};var l=[];return t.use=function(){for(var n=arguments,e=0;e<n.length;e++)l.push(n[e]);return t},t.sheet=function(n,t){1===arguments.length&&(t=n,n={});var r,l=b+d++,s={},a=[];for(r in n)r-0!=r-0&&f.call(n,r)&&(s[r]=n[r]);o(t,a,"","",u,1,{e:function(n,t){var e=s[t];s[t]=e.slice(0,e.lastIndexOf(" ")+1)+n+" "+e.slice(e.lastIndexOf(" ")+1)},l:function(n,t,e,r,o){return e?t+e:(s[o]||(s[o]=o+l),t+r+s[o].match(/\S+$/))}}),a=new String(e(a));for(r in s)f.call(s,r)&&(a[r]=s[r]);return a},t.inline=function(n,t,l){return 1===arguments.length&&(t=n,n={}),r(t,l=[],"",u,1,{l:function(t,e,r,l,o){return r?e+r:n[o]?e+l+n[o]:o}}),e(l)},t.prefix=function(t,e){return n(e.map(function(n){return"-"+n+"-"}).concat([""]),[t])},t}function a(n,t,e){return e={},e[n]=t,e}var i={},u=[],c=i.toString,f=i.hasOwnProperty,p=c.call(i),h=c.call(u),g=c.call(""),w=/()(?::global\(\s*(\.[-\w]+)\s*\)|(\.)([-\w]+))/g,b="_j2c_"+Math.floor(4294967296*Math.random()).toString(36)+"_"+Math.floor(4294967296*Math.random()).toString(36)+"_"+Math.floor(4294967296*Math.random()).toString(36)+"_"+Math.floor(4294967296*Math.random()).toString(36)+"_",d=0;return s.global=function(n){return":global("+n+")"},s.kv=a,s.at=function n(t,e,r){if(arguments.length<3){var l=n.bind.apply(n,[null].concat([].slice.call(arguments,0)));return l.toString=function(){return"@"+t+" "+e},l}return a("@"+t+" "+e,r)},s(s),delete s.use,s});