Comparing version 0.7.1 to 0.7.2
@@ -16,7 +16,7 @@ define('j2c', function(){return (function () { | ||
// turned into strings. | ||
function _declarations(o, buf, prefix, vendors, /*var*/ k, v, kk) { | ||
function _declarations(o, buf, prefix, vendors, localize,/*var*/ k, v, kk) { | ||
switch (type.call(o)) { | ||
case ARRAY: | ||
for (k = o.length;k--;) | ||
_declarations(o[k], buf, prefix, vendors); | ||
_declarations(o[k], buf, prefix, vendors, localize); | ||
break; | ||
@@ -29,6 +29,6 @@ case OBJECT: | ||
// "$" was found. | ||
for (kk in k = k.split("$")) if (own.call(k, kk)) | ||
_declarations(v, buf, prefix + k[kk], vendors); | ||
for (kk in k = k.split("$").reverse()) if (own.call(k, kk)) | ||
_declarations(v, buf, prefix + k[kk], vendors, localize); | ||
} else { | ||
_declarations(v, buf, prefix + k, vendors); | ||
_declarations(v, buf, prefix + k, vendors, localize); | ||
} | ||
@@ -43,3 +43,10 @@ } | ||
// `o` is the value. | ||
buf.push(o = (prefix && (prefix).replace(/_/g, "-") + ":") + o + ";"); | ||
k=(prefix && (prefix).replace(/_/g, "-") + ":") | ||
if (localize && k=="animation:") o = o.replace(/([-\w]+)/, localize); | ||
if (localize && k=="animation-name:") o = o.split(',').map(function(o){ | ||
return o.replace(/([-\w]+)/, localize)} | ||
).join(","); | ||
buf.push(o = k + o + ";"); | ||
// vendorify | ||
@@ -46,0 +53,0 @@ for (k = vendors.length; k--;) |
@@ -1,1 +0,1 @@ | ||
define("j2c",function(){return function(){function n(e,r,a,f,o,u,s){switch(t.call(e)){case l:for(o=e.length;o--;)n(e[o],r,a,f);break;case i:a=a&&a+"-";for(o in e)if(u=e[o],o.indexOf("$")+1)for(s in o=o.split("$"))c.call(o,s)&&n(u,r,a+o[s],f);else n(u,r,a+o,f);break;default:for(r.push(e=(a&&a.replace(/_/g,"-")+":")+e+";"),o=f.length;o--;)r.push("-"+f[o]+"-"+e)}}function e(n,e,r,t,i){r=[];for(i in e)if(c.call(e,i))for(t in n)c.call(n,t)&&r.push(n[t]+e[i]);return r}var r=[],t={}.toString,c={}.hasOwnProperty,i=t.call({}),l=t.call(r),a=(t.call(""),"_j2c_"+(1e9*Math.random()|0)+"_"+1*new Date+"_",{});return a.inline=function(e,t,c){return n(e,c=[],"",t||r),c.reverse().join("\n")},a.prefix=function(n,r){return e(r.map(function(n){return"-"+n+"-"}).concat([""]),[n])},a}()}); | ||
define("j2c",function(){return function(){function n(e,r,l,o,f,u,p,s){switch(i.call(e)){case c:for(u=e.length;u--;)n(e[u],r,l,o,f);break;case a:l=l&&l+"-";for(u in e)if(p=e[u],u.indexOf("$")+1)for(s in u=u.split("$").reverse())t.call(u,s)&&n(p,r,l+u[s],o,f);else n(p,r,l+u,o,f);break;default:for(u=l&&l.replace(/_/g,"-")+":",f&&"animation:"==u&&(e=e.replace(/([-\w]+)/,f)),f&&"animation-name:"==u&&(e=e.split(",").map(function(n){return n.replace(/([-\w]+)/,f)}).join(",")),r.push(e=u+e+";"),u=o.length;u--;)r.push("-"+o[u]+"-"+e)}}function e(n,e,r,i,a){r=[];for(a in e)if(t.call(e,a))for(i in n)t.call(n,i)&&r.push(n[i]+e[a]);return r}var r=[],i={}.toString,t={}.hasOwnProperty,a=i.call({}),c=i.call(r),l=(i.call(""),"_j2c_"+(1e9*Math.random()|0)+"_"+1*new Date+"_",{});return l.inline=function(e,i,t){return n(e,t=[],"",i||r),t.reverse().join("\n")},l.prefix=function(n,r){return e(r.map(function(n){return"-"+n+"-"}).concat([""]),[n])},l}()}); |
@@ -16,7 +16,7 @@ module.exports = (function () { | ||
// turned into strings. | ||
function _declarations(o, buf, prefix, vendors, /*var*/ k, v, kk) { | ||
function _declarations(o, buf, prefix, vendors, localize,/*var*/ k, v, kk) { | ||
switch (type.call(o)) { | ||
case ARRAY: | ||
for (k = o.length;k--;) | ||
_declarations(o[k], buf, prefix, vendors); | ||
_declarations(o[k], buf, prefix, vendors, localize); | ||
break; | ||
@@ -29,6 +29,6 @@ case OBJECT: | ||
// "$" was found. | ||
for (kk in k = k.split("$")) if (own.call(k, kk)) | ||
_declarations(v, buf, prefix + k[kk], vendors); | ||
for (kk in k = k.split("$").reverse()) if (own.call(k, kk)) | ||
_declarations(v, buf, prefix + k[kk], vendors, localize); | ||
} else { | ||
_declarations(v, buf, prefix + k, vendors); | ||
_declarations(v, buf, prefix + k, vendors, localize); | ||
} | ||
@@ -43,3 +43,10 @@ } | ||
// `o` is the value. | ||
buf.push(o = (prefix && (prefix).replace(/_/g, "-") + ":") + o + ";"); | ||
k=(prefix && (prefix).replace(/_/g, "-") + ":") | ||
if (localize && k=="animation:") o = o.replace(/([-\w]+)/, localize); | ||
if (localize && k=="animation-name:") o = o.split(',').map(function(o){ | ||
return o.replace(/([-\w]+)/, localize)} | ||
).join(","); | ||
buf.push(o = k + o + ";"); | ||
// vendorify | ||
@@ -46,0 +53,0 @@ for (k = vendors.length; k--;) |
@@ -1,1 +0,1 @@ | ||
module.exports=function(){function n(e,r,i,o,f,u,s){switch(t.call(e)){case c:for(f=e.length;f--;)n(e[f],r,i,o);break;case a:i=i&&i+"-";for(f in e)if(u=e[f],f.indexOf("$")+1)for(s in f=f.split("$"))l.call(f,s)&&n(u,r,i+f[s],o);else n(u,r,i+f,o);break;default:for(r.push(e=(i&&i.replace(/_/g,"-")+":")+e+";"),f=o.length;f--;)r.push("-"+o[f]+"-"+e)}}function e(n,e,r,t,a){r=[];for(a in e)if(l.call(e,a))for(t in n)l.call(n,t)&&r.push(n[t]+e[a]);return r}var r=[],t={}.toString,l={}.hasOwnProperty,a=t.call({}),c=t.call(r),i=(t.call(""),"_j2c_"+(1e9*Math.random()|0)+"_"+1*new Date+"_",{});return i.inline=function(e,t,l){return n(e,l=[],"",t||r),l.reverse().join("\n")},i.prefix=function(n,r){return e(r.map(function(n){return"-"+n+"-"}).concat([""]),[n])},i}(); | ||
module.exports=function(){function n(e,r,c,o,f,u,p,s){switch(a.call(e)){case l:for(u=e.length;u--;)n(e[u],r,c,o,f);break;case i:c=c&&c+"-";for(u in e)if(p=e[u],u.indexOf("$")+1)for(s in u=u.split("$").reverse())t.call(u,s)&&n(p,r,c+u[s],o,f);else n(p,r,c+u,o,f);break;default:for(u=c&&c.replace(/_/g,"-")+":",f&&"animation:"==u&&(e=e.replace(/([-\w]+)/,f)),f&&"animation-name:"==u&&(e=e.split(",").map(function(n){return n.replace(/([-\w]+)/,f)}).join(",")),r.push(e=u+e+";"),u=o.length;u--;)r.push("-"+o[u]+"-"+e)}}function e(n,e,r,a,i){r=[];for(i in e)if(t.call(e,i))for(a in n)t.call(n,a)&&r.push(n[a]+e[i]);return r}var r=[],a={}.toString,t={}.hasOwnProperty,i=a.call({}),l=a.call(r),c=(a.call(""),"_j2c_"+(1e9*Math.random()|0)+"_"+1*new Date+"_",{});return c.inline=function(e,a,t){return n(e,t=[],"",a||r),t.reverse().join("\n")},c.prefix=function(n,r){return e(r.map(function(n){return"-"+n+"-"}).concat([""]),[n])},c}(); |
@@ -16,7 +16,7 @@ export default (function () { | ||
// turned into strings. | ||
function _declarations(o, buf, prefix, vendors, /*var*/ k, v, kk) { | ||
function _declarations(o, buf, prefix, vendors, localize,/*var*/ k, v, kk) { | ||
switch (type.call(o)) { | ||
case ARRAY: | ||
for (k = o.length;k--;) | ||
_declarations(o[k], buf, prefix, vendors); | ||
_declarations(o[k], buf, prefix, vendors, localize); | ||
break; | ||
@@ -29,6 +29,6 @@ case OBJECT: | ||
// "$" was found. | ||
for (kk in k = k.split("$")) if (own.call(k, kk)) | ||
_declarations(v, buf, prefix + k[kk], vendors); | ||
for (kk in k = k.split("$").reverse()) if (own.call(k, kk)) | ||
_declarations(v, buf, prefix + k[kk], vendors, localize); | ||
} else { | ||
_declarations(v, buf, prefix + k, vendors); | ||
_declarations(v, buf, prefix + k, vendors, localize); | ||
} | ||
@@ -43,3 +43,10 @@ } | ||
// `o` is the value. | ||
buf.push(o = (prefix && (prefix).replace(/_/g, "-") + ":") + o + ";"); | ||
k=(prefix && (prefix).replace(/_/g, "-") + ":") | ||
if (localize && k=="animation:") o = o.replace(/([-\w]+)/, localize); | ||
if (localize && k=="animation-name:") o = o.split(',').map(function(o){ | ||
return o.replace(/([-\w]+)/, localize)} | ||
).join(","); | ||
buf.push(o = k + o + ";"); | ||
// vendorify | ||
@@ -46,0 +53,0 @@ for (k = vendors.length; k--;) |
@@ -16,7 +16,7 @@ ;var j2c = (function () { | ||
// turned into strings. | ||
function _declarations(o, buf, prefix, vendors, /*var*/ k, v, kk) { | ||
function _declarations(o, buf, prefix, vendors, localize,/*var*/ k, v, kk) { | ||
switch (type.call(o)) { | ||
case ARRAY: | ||
for (k = o.length;k--;) | ||
_declarations(o[k], buf, prefix, vendors); | ||
_declarations(o[k], buf, prefix, vendors, localize); | ||
break; | ||
@@ -29,6 +29,6 @@ case OBJECT: | ||
// "$" was found. | ||
for (kk in k = k.split("$")) if (own.call(k, kk)) | ||
_declarations(v, buf, prefix + k[kk], vendors); | ||
for (kk in k = k.split("$").reverse()) if (own.call(k, kk)) | ||
_declarations(v, buf, prefix + k[kk], vendors, localize); | ||
} else { | ||
_declarations(v, buf, prefix + k, vendors); | ||
_declarations(v, buf, prefix + k, vendors, localize); | ||
} | ||
@@ -43,3 +43,10 @@ } | ||
// `o` is the value. | ||
buf.push(o = (prefix && (prefix).replace(/_/g, "-") + ":") + o + ";"); | ||
k=(prefix && (prefix).replace(/_/g, "-") + ":") | ||
if (localize && k=="animation:") o = o.replace(/([-\w]+)/, localize); | ||
if (localize && k=="animation-name:") o = o.split(',').map(function(o){ | ||
return o.replace(/([-\w]+)/, localize)} | ||
).join(","); | ||
buf.push(o = k + o + ";"); | ||
// vendorify | ||
@@ -46,0 +53,0 @@ for (k = vendors.length; k--;) |
@@ -1,1 +0,1 @@ | ||
var j2c=function(){function n(r,e,i,f,o,u,s){switch(t.call(r)){case l:for(o=r.length;o--;)n(r[o],e,i,f);break;case c:i=i&&i+"-";for(o in r)if(u=r[o],o.indexOf("$")+1)for(s in o=o.split("$"))a.call(o,s)&&n(u,e,i+o[s],f);else n(u,e,i+o,f);break;default:for(e.push(r=(i&&i.replace(/_/g,"-")+":")+r+";"),o=f.length;o--;)e.push("-"+f[o]+"-"+r)}}function r(n,r,e,t,c){e=[];for(c in r)if(a.call(r,c))for(t in n)a.call(n,t)&&e.push(n[t]+r[c]);return e}var e=[],t={}.toString,a={}.hasOwnProperty,c=t.call({}),l=t.call(e),i=(t.call(""),"_j2c_"+(1e9*Math.random()|0)+"_"+1*new Date+"_",{});return i.inline=function(r,t,a){return n(r,a=[],"",t||e),a.reverse().join("\n")},i.prefix=function(n,e){return r(e.map(function(n){return"-"+n+"-"}).concat([""]),[n])},i}(); | ||
var j2c=function(){function n(e,r,l,o,f,u,p,s){switch(a.call(e)){case c:for(u=e.length;u--;)n(e[u],r,l,o,f);break;case t:l=l&&l+"-";for(u in e)if(p=e[u],u.indexOf("$")+1)for(s in u=u.split("$").reverse())i.call(u,s)&&n(p,r,l+u[s],o,f);else n(p,r,l+u,o,f);break;default:for(u=l&&l.replace(/_/g,"-")+":",f&&"animation:"==u&&(e=e.replace(/([-\w]+)/,f)),f&&"animation-name:"==u&&(e=e.split(",").map(function(n){return n.replace(/([-\w]+)/,f)}).join(",")),r.push(e=u+e+";"),u=o.length;u--;)r.push("-"+o[u]+"-"+e)}}function e(n,e,r,a,t){r=[];for(t in e)if(i.call(e,t))for(a in n)i.call(n,a)&&r.push(n[a]+e[t]);return r}var r=[],a={}.toString,i={}.hasOwnProperty,t=a.call({}),c=a.call(r),l=(a.call(""),"_j2c_"+(1e9*Math.random()|0)+"_"+1*new Date+"_",{});return l.inline=function(e,a,i){return n(e,i=[],"",a||r),i.reverse().join("\n")},l.prefix=function(n,r){return e(r.map(function(n){return"-"+n+"-"}).concat([""]),[n])},l}(); |
@@ -16,7 +16,7 @@ define('j2c', function(){return (function () { | ||
// turned into strings. | ||
function _declarations(o, buf, prefix, vendors, /*var*/ k, v, kk) { | ||
function _declarations(o, buf, prefix, vendors, localize,/*var*/ k, v, kk) { | ||
switch (type.call(o)) { | ||
case ARRAY: | ||
for (k = o.length;k--;) | ||
_declarations(o[k], buf, prefix, vendors); | ||
_declarations(o[k], buf, prefix, vendors, localize); | ||
break; | ||
@@ -29,6 +29,6 @@ case OBJECT: | ||
// "$" was found. | ||
for (kk in k = k.split("$")) if (own.call(k, kk)) | ||
_declarations(v, buf, prefix + k[kk], vendors); | ||
for (kk in k = k.split("$").reverse()) if (own.call(k, kk)) | ||
_declarations(v, buf, prefix + k[kk], vendors, localize); | ||
} else { | ||
_declarations(v, buf, prefix + k, vendors); | ||
_declarations(v, buf, prefix + k, vendors, localize); | ||
} | ||
@@ -43,3 +43,10 @@ } | ||
// `o` is the value. | ||
buf.push(o = (prefix && (prefix).replace(/_/g, "-") + ":") + o + ";"); | ||
k=(prefix && (prefix).replace(/_/g, "-") + ":") | ||
if (localize && k=="animation:") o = o.replace(/([-\w]+)/, localize); | ||
if (localize && k=="animation-name:") o = o.split(',').map(function(o){ | ||
return o.replace(/([-\w]+)/, localize)} | ||
).join(","); | ||
buf.push(o = k + o + ";"); | ||
// vendorify | ||
@@ -64,3 +71,3 @@ for (k = vendors.length; k--;) | ||
function _concat(a, b, selectorP) { | ||
return selectorP && b.indexOf("&") + 1 ? b.replace("&", a) : a + b | ||
return selectorP && b.indexOf("&") + 1 ? b.replace(/&/g, a) : a + b | ||
} | ||
@@ -70,3 +77,3 @@ | ||
// Add rulesets and other CSS statements to the sheet. | ||
function _add(statements, buf, prefix, vendors, /*var*/ k, v, decl) { | ||
function _add(statements, buf, prefix, vendors, localize, /*var*/ k, v, decl) { | ||
// optionally needed in the "[object String]" case | ||
@@ -82,3 +89,3 @@ // where the `statements` variable actually holds | ||
for (k = statements.length;k--;) | ||
_add(statements[k], buf, prefix, vendors); | ||
_add(statements[k], buf, prefix, vendors, localize); | ||
break; | ||
@@ -95,4 +102,5 @@ | ||
} else if (k.match(/^@keyframes /)) { | ||
k = localize ? k.replace(/ ([-\w]+)/, localize) : k | ||
buf.push("}"); | ||
_add(v, buf, "", vendors); | ||
_add(v, buf, "", vendors, localize); | ||
buf.push(k + "{"); | ||
@@ -111,3 +119,3 @@ | ||
buf.push("}"); | ||
_add(v, buf, prefix, vendors); | ||
_add(v, buf, prefix, vendors, localize); | ||
buf.push(k + "{"); | ||
@@ -132,3 +140,3 @@ } | ||
, | ||
vendors | ||
vendors, localize | ||
); | ||
@@ -147,4 +155,4 @@ } | ||
buf.push("}"); | ||
_declarations(decl, buf, "", vendors); | ||
buf.push((prefix || "*") + "{"); | ||
_declarations(decl, buf, "", vendors, localize); | ||
buf.push((localize ? prefix.replace(/\.([-\w]+)/, localize):prefix || "*") + "{"); | ||
break; | ||
@@ -167,10 +175,14 @@ } | ||
j2c.scoped = function(statements, vendors, k) { | ||
var classes = {}, | ||
buf = []; | ||
vendors = vendors || empty; | ||
for (k in statements) if (own.call(statements, k)) { | ||
classes[k] = k.replace(/[^\-\w]/, '') + scope_root + (counter++); | ||
_add(statements[k], buf, "." + classes[k], vendors); | ||
} | ||
j2c.local = function (statements, options) { | ||
options = options || {}; | ||
var suffix = scope_root + counter++ | ||
, global = options.global || [] | ||
, locals = {} | ||
, buf = [] | ||
; | ||
_add(statements, buf, "", options.vendors || empty, function (match, k) { | ||
if (global.indexOf(k) + 1) return match; | ||
locals[k] || locals[k] = k+suffix; | ||
return match + suffix; | ||
}); | ||
buf = new String(_finalize(buf)); | ||
@@ -177,0 +189,0 @@ for (k in statements) if (own.call(statements, k)) buf[k] = classes[k]; |
@@ -1,1 +0,1 @@ | ||
define("j2c",function(){return function(){function n(e,r,t,c,i,o,s){switch(a.call(e)){case u:for(i=e.length;i--;)n(e[i],r,t,c);break;case l:t=t&&t+"-";for(i in e)if(o=e[i],i.indexOf("$")+1)for(s in i=i.split("$"))f.call(i,s)&&n(o,r,t+i[s],c);else n(o,r,t+i,c);break;default:for(r.push(e=(t&&t.replace(/_/g,"-")+":")+e+";"),i=c.length;i--;)r.push("-"+c[i]+"-"+e)}}function e(n,e,t,c,i,a){c=[];for(a in e)if(f.call(e,a))for(i in n)f.call(n,i)&&c.push(r(n[i],e[a],t));return c}function r(n,e,r){return r&&e.indexOf("&")+1?e.replace("&",n):n+e}function t(c,s,h,p,w,d,k){switch(k=c,a.call(c)){case u:for(w=c.length;w--;)t(c[w],s,h,p);break;case l:k={};for(w in c)"@"==w[0]&&(d=c[w],a.call(d)==o?s.push(w+" "+d+";"):w.match(/^@keyframes /)?(s.push("}"),t(d,s,"",p),s.push(w+"{"),s.push("}"),t(d,s,"",["webkit"]),s.push("@-webkit-"+w.slice(1)+"{")):w.match(/^@font-face/)?t(d,s,w,i):(s.push("}"),t(d,s,h,p),s.push(w+"{")));for(w in c)d=c[w],w.match(/^[-\w$]+$/)?k[w]=d:"@"!=w[0]&&t(d,s,h.indexOf(",")+w.indexOf(",")+2?e(h.split(","),w.split(","),1).join(","):r(h,w,1),p);case o:for(w in k)if(f.call(k,w)){s.push("}"),n(k,s,"",p),s.push((h||"*")+"{");break}}}function c(n){return n.reverse().join("\n")}var i=[],a={}.toString,f={}.hasOwnProperty,l=a.call({}),u=a.call(i),o=a.call(""),s="_j2c_"+(1e9*Math.random()|0)+"_"+1*new Date+"_",h=0,p={};return p.inline=function(e,r,t){return n(e,t=[],"",r||i),c(t)},p.sheet=function(n,e,r){return t(n,r=[],"",e||i),c(r)},p.scoped=function(n,e,r){var a={},l=[];e=e||i;for(r in n)f.call(n,r)&&(a[r]=r.replace(/[^\-\w]/,"")+s+h++,t(n[r],l,"."+a[r],e));l=new String(c(l));for(r in n)f.call(n,r)&&(l[r]=a[r]);return l},p.prefix=function(n,r){return e(r.map(function(n){return"-"+n+"-"}).concat([""]),[n])},p}()}); | ||
define("j2c",function(){return function(){function n(e,r,i,t,a,o,s,p){switch(c.call(e)){case u:for(o=e.length;o--;)n(e[o],r,i,t,a);break;case f:i=i&&i+"-";for(o in e)if(s=e[o],o.indexOf("$")+1)for(p in o=o.split("$").reverse())l.call(o,p)&&n(s,r,i+o[p],t,a);else n(s,r,i+o,t,a);break;default:for(o=i&&i.replace(/_/g,"-")+":",a&&"animation:"==o&&(e=e.replace(/([-\w]+)/,a)),a&&"animation-name:"==o&&(e=e.split(",").map(function(n){return n.replace(/([-\w]+)/,a)}).join(",")),r.push(e=o+e+";"),o=t.length;o--;)r.push("-"+t[o]+"-"+e)}}function e(n,e,i,t,a,c){t=[];for(c in e)if(l.call(e,c))for(a in n)l.call(n,a)&&t.push(r(n[a],e[c],i));return t}function r(n,e,r){return r&&e.indexOf("&")+1?e.replace(/&/g,n):n+e}function i(t,s,p,h,w,k,m,d){switch(d=t,c.call(t)){case u:for(k=t.length;k--;)i(t[k],s,p,h,w);break;case f:d={};for(k in t)"@"==k[0]&&(m=t[k],c.call(m)==o?s.push(k+" "+m+";"):k.match(/^@keyframes /)?(k=w?k.replace(/ ([-\w]+)/,w):k,s.push("}"),i(m,s,"",h,w),s.push(k+"{"),s.push("}"),i(m,s,"",["webkit"]),s.push("@-webkit-"+k.slice(1)+"{")):k.match(/^@font-face/)?i(m,s,k,a):(s.push("}"),i(m,s,p,h,w),s.push(k+"{")));for(k in t)m=t[k],k.match(/^[-\w$]+$/)?d[k]=m:"@"!=k[0]&&i(m,s,p.indexOf(",")+k.indexOf(",")+2?e(p.split(","),k.split(","),1).join(","):r(p,k,1),h,w);case o:for(k in d)if(l.call(d,k)){s.push("}"),n(d,s,"",h,w),s.push((w?p.replace(/\.([-\w]+)/,w):p||"*")+"{");break}}}function t(n){return n.reverse().join("\n")}var a=[],c={}.toString,l={}.hasOwnProperty,f=c.call({}),u=c.call(a),o=c.call(""),s="_j2c_"+(1e9*Math.random()|0)+"_"+1*new Date+"_",p=0,h={};return h.inline=function(e,r,i){return n(e,i=[],"",r||a),t(i)},h.sheet=function(n,e,r){return i(n,r=[],"",e||a),t(r)},h.local=function(n,e){e=e||{};var r=s+p++,c=e.global||[],f={},u=[];i(n,u,"",e.vendors||a,function(n,e){return c.indexOf(e)+1?n:(f[e]||f[e]=e+r,n+r)}),u=new String(t(u));for(k in n)l.call(n,k)&&(u[k]=classes[k]);return u},h.prefix=function(n,r){return e(r.map(function(n){return"-"+n+"-"}).concat([""]),[n])},h}()}); |
@@ -16,7 +16,7 @@ module.exports = (function () { | ||
// turned into strings. | ||
function _declarations(o, buf, prefix, vendors, /*var*/ k, v, kk) { | ||
function _declarations(o, buf, prefix, vendors, localize,/*var*/ k, v, kk) { | ||
switch (type.call(o)) { | ||
case ARRAY: | ||
for (k = o.length;k--;) | ||
_declarations(o[k], buf, prefix, vendors); | ||
_declarations(o[k], buf, prefix, vendors, localize); | ||
break; | ||
@@ -29,6 +29,6 @@ case OBJECT: | ||
// "$" was found. | ||
for (kk in k = k.split("$")) if (own.call(k, kk)) | ||
_declarations(v, buf, prefix + k[kk], vendors); | ||
for (kk in k = k.split("$").reverse()) if (own.call(k, kk)) | ||
_declarations(v, buf, prefix + k[kk], vendors, localize); | ||
} else { | ||
_declarations(v, buf, prefix + k, vendors); | ||
_declarations(v, buf, prefix + k, vendors, localize); | ||
} | ||
@@ -43,3 +43,10 @@ } | ||
// `o` is the value. | ||
buf.push(o = (prefix && (prefix).replace(/_/g, "-") + ":") + o + ";"); | ||
k=(prefix && (prefix).replace(/_/g, "-") + ":") | ||
if (localize && k=="animation:") o = o.replace(/([-\w]+)/, localize); | ||
if (localize && k=="animation-name:") o = o.split(',').map(function(o){ | ||
return o.replace(/([-\w]+)/, localize)} | ||
).join(","); | ||
buf.push(o = k + o + ";"); | ||
// vendorify | ||
@@ -64,3 +71,3 @@ for (k = vendors.length; k--;) | ||
function _concat(a, b, selectorP) { | ||
return selectorP && b.indexOf("&") + 1 ? b.replace("&", a) : a + b | ||
return selectorP && b.indexOf("&") + 1 ? b.replace(/&/g, a) : a + b | ||
} | ||
@@ -70,3 +77,3 @@ | ||
// Add rulesets and other CSS statements to the sheet. | ||
function _add(statements, buf, prefix, vendors, /*var*/ k, v, decl) { | ||
function _add(statements, buf, prefix, vendors, localize, /*var*/ k, v, decl) { | ||
// optionally needed in the "[object String]" case | ||
@@ -82,3 +89,3 @@ // where the `statements` variable actually holds | ||
for (k = statements.length;k--;) | ||
_add(statements[k], buf, prefix, vendors); | ||
_add(statements[k], buf, prefix, vendors, localize); | ||
break; | ||
@@ -95,4 +102,5 @@ | ||
} else if (k.match(/^@keyframes /)) { | ||
k = localize ? k.replace(/ ([-\w]+)/, localize) : k | ||
buf.push("}"); | ||
_add(v, buf, "", vendors); | ||
_add(v, buf, "", vendors, localize); | ||
buf.push(k + "{"); | ||
@@ -111,3 +119,3 @@ | ||
buf.push("}"); | ||
_add(v, buf, prefix, vendors); | ||
_add(v, buf, prefix, vendors, localize); | ||
buf.push(k + "{"); | ||
@@ -132,3 +140,3 @@ } | ||
, | ||
vendors | ||
vendors, localize | ||
); | ||
@@ -147,4 +155,4 @@ } | ||
buf.push("}"); | ||
_declarations(decl, buf, "", vendors); | ||
buf.push((prefix || "*") + "{"); | ||
_declarations(decl, buf, "", vendors, localize); | ||
buf.push((localize ? prefix.replace(/\.([-\w]+)/, localize):prefix || "*") + "{"); | ||
break; | ||
@@ -167,10 +175,14 @@ } | ||
j2c.scoped = function(statements, vendors, k) { | ||
var classes = {}, | ||
buf = []; | ||
vendors = vendors || empty; | ||
for (k in statements) if (own.call(statements, k)) { | ||
classes[k] = k.replace(/[^\-\w]/, '') + scope_root + (counter++); | ||
_add(statements[k], buf, "." + classes[k], vendors); | ||
} | ||
j2c.local = function (statements, options) { | ||
options = options || {}; | ||
var suffix = scope_root + counter++ | ||
, global = options.global || [] | ||
, locals = {} | ||
, buf = [] | ||
; | ||
_add(statements, buf, "", options.vendors || empty, function (match, k) { | ||
if (global.indexOf(k) + 1) return match; | ||
locals[k] || locals[k] = k+suffix; | ||
return match + suffix; | ||
}); | ||
buf = new String(_finalize(buf)); | ||
@@ -177,0 +189,0 @@ for (k in statements) if (own.call(statements, k)) buf[k] = classes[k]; |
@@ -1,1 +0,1 @@ | ||
module.exports=function(){function n(e,r,t,c,i,o,s){switch(a.call(e)){case u:for(i=e.length;i--;)n(e[i],r,t,c);break;case f:t=t&&t+"-";for(i in e)if(o=e[i],i.indexOf("$")+1)for(s in i=i.split("$"))l.call(i,s)&&n(o,r,t+i[s],c);else n(o,r,t+i,c);break;default:for(r.push(e=(t&&t.replace(/_/g,"-")+":")+e+";"),i=c.length;i--;)r.push("-"+c[i]+"-"+e)}}function e(n,e,t,c,i,a){c=[];for(a in e)if(l.call(e,a))for(i in n)l.call(n,i)&&c.push(r(n[i],e[a],t));return c}function r(n,e,r){return r&&e.indexOf("&")+1?e.replace("&",n):n+e}function t(c,s,h,p,w,d,k){switch(k=c,a.call(c)){case u:for(w=c.length;w--;)t(c[w],s,h,p);break;case f:k={};for(w in c)"@"==w[0]&&(d=c[w],a.call(d)==o?s.push(w+" "+d+";"):w.match(/^@keyframes /)?(s.push("}"),t(d,s,"",p),s.push(w+"{"),s.push("}"),t(d,s,"",["webkit"]),s.push("@-webkit-"+w.slice(1)+"{")):w.match(/^@font-face/)?t(d,s,w,i):(s.push("}"),t(d,s,h,p),s.push(w+"{")));for(w in c)d=c[w],w.match(/^[-\w$]+$/)?k[w]=d:"@"!=w[0]&&t(d,s,h.indexOf(",")+w.indexOf(",")+2?e(h.split(","),w.split(","),1).join(","):r(h,w,1),p);case o:for(w in k)if(l.call(k,w)){s.push("}"),n(k,s,"",p),s.push((h||"*")+"{");break}}}function c(n){return n.reverse().join("\n")}var i=[],a={}.toString,l={}.hasOwnProperty,f=a.call({}),u=a.call(i),o=a.call(""),s="_j2c_"+(1e9*Math.random()|0)+"_"+1*new Date+"_",h=0,p={};return p.inline=function(e,r,t){return n(e,t=[],"",r||i),c(t)},p.sheet=function(n,e,r){return t(n,r=[],"",e||i),c(r)},p.scoped=function(n,e,r){var a={},f=[];e=e||i;for(r in n)l.call(n,r)&&(a[r]=r.replace(/[^\-\w]/,"")+s+h++,t(n[r],f,"."+a[r],e));f=new String(c(f));for(r in n)l.call(n,r)&&(f[r]=a[r]);return f},p.prefix=function(n,r){return e(r.map(function(n){return"-"+n+"-"}).concat([""]),[n])},p}(); | ||
module.exports=function(){function n(e,r,t,i,a,f,s,p){switch(c.call(e)){case u:for(f=e.length;f--;)n(e[f],r,t,i,a);break;case o:t=t&&t+"-";for(f in e)if(s=e[f],f.indexOf("$")+1)for(p in f=f.split("$").reverse())l.call(f,p)&&n(s,r,t+f[p],i,a);else n(s,r,t+f,i,a);break;default:for(f=t&&t.replace(/_/g,"-")+":",a&&"animation:"==f&&(e=e.replace(/([-\w]+)/,a)),a&&"animation-name:"==f&&(e=e.split(",").map(function(n){return n.replace(/([-\w]+)/,a)}).join(",")),r.push(e=f+e+";"),f=i.length;f--;)r.push("-"+i[f]+"-"+e)}}function e(n,e,t,i,a,c){i=[];for(c in e)if(l.call(e,c))for(a in n)l.call(n,a)&&i.push(r(n[a],e[c],t));return i}function r(n,e,r){return r&&e.indexOf("&")+1?e.replace(/&/g,n):n+e}function t(i,s,p,h,w,k,m,d){switch(d=i,c.call(i)){case u:for(k=i.length;k--;)t(i[k],s,p,h,w);break;case o:d={};for(k in i)"@"==k[0]&&(m=i[k],c.call(m)==f?s.push(k+" "+m+";"):k.match(/^@keyframes /)?(k=w?k.replace(/ ([-\w]+)/,w):k,s.push("}"),t(m,s,"",h,w),s.push(k+"{"),s.push("}"),t(m,s,"",["webkit"]),s.push("@-webkit-"+k.slice(1)+"{")):k.match(/^@font-face/)?t(m,s,k,a):(s.push("}"),t(m,s,p,h,w),s.push(k+"{")));for(k in i)m=i[k],k.match(/^[-\w$]+$/)?d[k]=m:"@"!=k[0]&&t(m,s,p.indexOf(",")+k.indexOf(",")+2?e(p.split(","),k.split(","),1).join(","):r(p,k,1),h,w);case f:for(k in d)if(l.call(d,k)){s.push("}"),n(d,s,"",h,w),s.push((w?p.replace(/\.([-\w]+)/,w):p||"*")+"{");break}}}function i(n){return n.reverse().join("\n")}var a=[],c={}.toString,l={}.hasOwnProperty,o=c.call({}),u=c.call(a),f=c.call(""),s="_j2c_"+(1e9*Math.random()|0)+"_"+1*new Date+"_",p=0,h={};return h.inline=function(e,r,t){return n(e,t=[],"",r||a),i(t)},h.sheet=function(n,e,r){return t(n,r=[],"",e||a),i(r)},h.local=function(n,e){e=e||{};var r=s+p++,c=e.global||[],o={},u=[];t(n,u,"",e.vendors||a,function(n,e){return c.indexOf(e)+1?n:(o[e]||o[e]=e+r,n+r)}),u=new String(i(u));for(k in n)l.call(n,k)&&(u[k]=classes[k]);return u},h.prefix=function(n,r){return e(r.map(function(n){return"-"+n+"-"}).concat([""]),[n])},h}(); |
@@ -16,7 +16,7 @@ export default (function () { | ||
// turned into strings. | ||
function _declarations(o, buf, prefix, vendors, /*var*/ k, v, kk) { | ||
function _declarations(o, buf, prefix, vendors, localize,/*var*/ k, v, kk) { | ||
switch (type.call(o)) { | ||
case ARRAY: | ||
for (k = o.length;k--;) | ||
_declarations(o[k], buf, prefix, vendors); | ||
_declarations(o[k], buf, prefix, vendors, localize); | ||
break; | ||
@@ -29,6 +29,6 @@ case OBJECT: | ||
// "$" was found. | ||
for (kk in k = k.split("$")) if (own.call(k, kk)) | ||
_declarations(v, buf, prefix + k[kk], vendors); | ||
for (kk in k = k.split("$").reverse()) if (own.call(k, kk)) | ||
_declarations(v, buf, prefix + k[kk], vendors, localize); | ||
} else { | ||
_declarations(v, buf, prefix + k, vendors); | ||
_declarations(v, buf, prefix + k, vendors, localize); | ||
} | ||
@@ -43,3 +43,10 @@ } | ||
// `o` is the value. | ||
buf.push(o = (prefix && (prefix).replace(/_/g, "-") + ":") + o + ";"); | ||
k=(prefix && (prefix).replace(/_/g, "-") + ":") | ||
if (localize && k=="animation:") o = o.replace(/([-\w]+)/, localize); | ||
if (localize && k=="animation-name:") o = o.split(',').map(function(o){ | ||
return o.replace(/([-\w]+)/, localize)} | ||
).join(","); | ||
buf.push(o = k + o + ";"); | ||
// vendorify | ||
@@ -64,3 +71,3 @@ for (k = vendors.length; k--;) | ||
function _concat(a, b, selectorP) { | ||
return selectorP && b.indexOf("&") + 1 ? b.replace("&", a) : a + b | ||
return selectorP && b.indexOf("&") + 1 ? b.replace(/&/g, a) : a + b | ||
} | ||
@@ -70,3 +77,3 @@ | ||
// Add rulesets and other CSS statements to the sheet. | ||
function _add(statements, buf, prefix, vendors, /*var*/ k, v, decl) { | ||
function _add(statements, buf, prefix, vendors, localize, /*var*/ k, v, decl) { | ||
// optionally needed in the "[object String]" case | ||
@@ -82,3 +89,3 @@ // where the `statements` variable actually holds | ||
for (k = statements.length;k--;) | ||
_add(statements[k], buf, prefix, vendors); | ||
_add(statements[k], buf, prefix, vendors, localize); | ||
break; | ||
@@ -95,4 +102,5 @@ | ||
} else if (k.match(/^@keyframes /)) { | ||
k = localize ? k.replace(/ ([-\w]+)/, localize) : k | ||
buf.push("}"); | ||
_add(v, buf, "", vendors); | ||
_add(v, buf, "", vendors, localize); | ||
buf.push(k + "{"); | ||
@@ -111,3 +119,3 @@ | ||
buf.push("}"); | ||
_add(v, buf, prefix, vendors); | ||
_add(v, buf, prefix, vendors, localize); | ||
buf.push(k + "{"); | ||
@@ -132,3 +140,3 @@ } | ||
, | ||
vendors | ||
vendors, localize | ||
); | ||
@@ -147,4 +155,4 @@ } | ||
buf.push("}"); | ||
_declarations(decl, buf, "", vendors); | ||
buf.push((prefix || "*") + "{"); | ||
_declarations(decl, buf, "", vendors, localize); | ||
buf.push((localize ? prefix.replace(/\.([-\w]+)/, localize):prefix || "*") + "{"); | ||
break; | ||
@@ -167,10 +175,14 @@ } | ||
j2c.scoped = function(statements, vendors, k) { | ||
var classes = {}, | ||
buf = []; | ||
vendors = vendors || empty; | ||
for (k in statements) if (own.call(statements, k)) { | ||
classes[k] = k.replace(/[^\-\w]/, '') + scope_root + (counter++); | ||
_add(statements[k], buf, "." + classes[k], vendors); | ||
} | ||
j2c.local = function (statements, options) { | ||
options = options || {}; | ||
var suffix = scope_root + counter++ | ||
, global = options.global || [] | ||
, locals = {} | ||
, buf = [] | ||
; | ||
_add(statements, buf, "", options.vendors || empty, function (match, k) { | ||
if (global.indexOf(k) + 1) return match; | ||
locals[k] || locals[k] = k+suffix; | ||
return match + suffix; | ||
}); | ||
buf = new String(_finalize(buf)); | ||
@@ -177,0 +189,0 @@ for (k in statements) if (own.call(statements, k)) buf[k] = classes[k]; |
@@ -16,7 +16,7 @@ ;var j2c = (function () { | ||
// turned into strings. | ||
function _declarations(o, buf, prefix, vendors, /*var*/ k, v, kk) { | ||
function _declarations(o, buf, prefix, vendors, localize,/*var*/ k, v, kk) { | ||
switch (type.call(o)) { | ||
case ARRAY: | ||
for (k = o.length;k--;) | ||
_declarations(o[k], buf, prefix, vendors); | ||
_declarations(o[k], buf, prefix, vendors, localize); | ||
break; | ||
@@ -29,6 +29,6 @@ case OBJECT: | ||
// "$" was found. | ||
for (kk in k = k.split("$")) if (own.call(k, kk)) | ||
_declarations(v, buf, prefix + k[kk], vendors); | ||
for (kk in k = k.split("$").reverse()) if (own.call(k, kk)) | ||
_declarations(v, buf, prefix + k[kk], vendors, localize); | ||
} else { | ||
_declarations(v, buf, prefix + k, vendors); | ||
_declarations(v, buf, prefix + k, vendors, localize); | ||
} | ||
@@ -43,3 +43,10 @@ } | ||
// `o` is the value. | ||
buf.push(o = (prefix && (prefix).replace(/_/g, "-") + ":") + o + ";"); | ||
k=(prefix && (prefix).replace(/_/g, "-") + ":") | ||
if (localize && k=="animation:") o = o.replace(/([-\w]+)/, localize); | ||
if (localize && k=="animation-name:") o = o.split(',').map(function(o){ | ||
return o.replace(/([-\w]+)/, localize)} | ||
).join(","); | ||
buf.push(o = k + o + ";"); | ||
// vendorify | ||
@@ -64,3 +71,3 @@ for (k = vendors.length; k--;) | ||
function _concat(a, b, selectorP) { | ||
return selectorP && b.indexOf("&") + 1 ? b.replace("&", a) : a + b | ||
return selectorP && b.indexOf("&") + 1 ? b.replace(/&/g, a) : a + b | ||
} | ||
@@ -70,3 +77,3 @@ | ||
// Add rulesets and other CSS statements to the sheet. | ||
function _add(statements, buf, prefix, vendors, /*var*/ k, v, decl) { | ||
function _add(statements, buf, prefix, vendors, localize, /*var*/ k, v, decl) { | ||
// optionally needed in the "[object String]" case | ||
@@ -82,3 +89,3 @@ // where the `statements` variable actually holds | ||
for (k = statements.length;k--;) | ||
_add(statements[k], buf, prefix, vendors); | ||
_add(statements[k], buf, prefix, vendors, localize); | ||
break; | ||
@@ -95,4 +102,5 @@ | ||
} else if (k.match(/^@keyframes /)) { | ||
k = localize ? k.replace(/ ([-\w]+)/, localize) : k | ||
buf.push("}"); | ||
_add(v, buf, "", vendors); | ||
_add(v, buf, "", vendors, localize); | ||
buf.push(k + "{"); | ||
@@ -111,3 +119,3 @@ | ||
buf.push("}"); | ||
_add(v, buf, prefix, vendors); | ||
_add(v, buf, prefix, vendors, localize); | ||
buf.push(k + "{"); | ||
@@ -132,3 +140,3 @@ } | ||
, | ||
vendors | ||
vendors, localize | ||
); | ||
@@ -147,4 +155,4 @@ } | ||
buf.push("}"); | ||
_declarations(decl, buf, "", vendors); | ||
buf.push((prefix || "*") + "{"); | ||
_declarations(decl, buf, "", vendors, localize); | ||
buf.push((localize ? prefix.replace(/\.([-\w]+)/, localize):prefix || "*") + "{"); | ||
break; | ||
@@ -167,10 +175,14 @@ } | ||
j2c.scoped = function(statements, vendors, k) { | ||
var classes = {}, | ||
buf = []; | ||
vendors = vendors || empty; | ||
for (k in statements) if (own.call(statements, k)) { | ||
classes[k] = k.replace(/[^\-\w]/, '') + scope_root + (counter++); | ||
_add(statements[k], buf, "." + classes[k], vendors); | ||
} | ||
j2c.local = function (statements, options) { | ||
options = options || {}; | ||
var suffix = scope_root + counter++ | ||
, global = options.global || [] | ||
, locals = {} | ||
, buf = [] | ||
; | ||
_add(statements, buf, "", options.vendors || empty, function (match, k) { | ||
if (global.indexOf(k) + 1) return match; | ||
locals[k] || locals[k] = k+suffix; | ||
return match + suffix; | ||
}); | ||
buf = new String(_finalize(buf)); | ||
@@ -177,0 +189,0 @@ for (k in statements) if (own.call(statements, k)) buf[k] = classes[k]; |
@@ -1,1 +0,1 @@ | ||
var j2c=function(){function n(e,r,c,t,i,o,s){switch(a.call(e)){case u:for(i=e.length;i--;)n(e[i],r,c,t);break;case f:c=c&&c+"-";for(i in e)if(o=e[i],i.indexOf("$")+1)for(s in i=i.split("$"))l.call(i,s)&&n(o,r,c+i[s],t);else n(o,r,c+i,t);break;default:for(r.push(e=(c&&c.replace(/_/g,"-")+":")+e+";"),i=t.length;i--;)r.push("-"+t[i]+"-"+e)}}function e(n,e,c,t,i,a){t=[];for(a in e)if(l.call(e,a))for(i in n)l.call(n,i)&&t.push(r(n[i],e[a],c));return t}function r(n,e,r){return r&&e.indexOf("&")+1?e.replace("&",n):n+e}function c(t,s,h,p,w,d,k){switch(k=t,a.call(t)){case u:for(w=t.length;w--;)c(t[w],s,h,p);break;case f:k={};for(w in t)"@"==w[0]&&(d=t[w],a.call(d)==o?s.push(w+" "+d+";"):w.match(/^@keyframes /)?(s.push("}"),c(d,s,"",p),s.push(w+"{"),s.push("}"),c(d,s,"",["webkit"]),s.push("@-webkit-"+w.slice(1)+"{")):w.match(/^@font-face/)?c(d,s,w,i):(s.push("}"),c(d,s,h,p),s.push(w+"{")));for(w in t)d=t[w],w.match(/^[-\w$]+$/)?k[w]=d:"@"!=w[0]&&c(d,s,h.indexOf(",")+w.indexOf(",")+2?e(h.split(","),w.split(","),1).join(","):r(h,w,1),p);case o:for(w in k)if(l.call(k,w)){s.push("}"),n(k,s,"",p),s.push((h||"*")+"{");break}}}function t(n){return n.reverse().join("\n")}var i=[],a={}.toString,l={}.hasOwnProperty,f=a.call({}),u=a.call(i),o=a.call(""),s="_j2c_"+(1e9*Math.random()|0)+"_"+1*new Date+"_",h=0,p={};return p.inline=function(e,r,c){return n(e,c=[],"",r||i),t(c)},p.sheet=function(n,e,r){return c(n,r=[],"",e||i),t(r)},p.scoped=function(n,e,r){var a={},f=[];e=e||i;for(r in n)l.call(n,r)&&(a[r]=r.replace(/[^\-\w]/,"")+s+h++,c(n[r],f,"."+a[r],e));f=new String(t(f));for(r in n)l.call(n,r)&&(f[r]=a[r]);return f},p.prefix=function(n,r){return e(r.map(function(n){return"-"+n+"-"}).concat([""]),[n])},p}(); | ||
var j2c=function(){function n(e,r,a,i,t,u,s,p){switch(c.call(e)){case o:for(u=e.length;u--;)n(e[u],r,a,i,t);break;case f:a=a&&a+"-";for(u in e)if(s=e[u],u.indexOf("$")+1)for(p in u=u.split("$").reverse())l.call(u,p)&&n(s,r,a+u[p],i,t);else n(s,r,a+u,i,t);break;default:for(u=a&&a.replace(/_/g,"-")+":",t&&"animation:"==u&&(e=e.replace(/([-\w]+)/,t)),t&&"animation-name:"==u&&(e=e.split(",").map(function(n){return n.replace(/([-\w]+)/,t)}).join(",")),r.push(e=u+e+";"),u=i.length;u--;)r.push("-"+i[u]+"-"+e)}}function e(n,e,a,i,t,c){i=[];for(c in e)if(l.call(e,c))for(t in n)l.call(n,t)&&i.push(r(n[t],e[c],a));return i}function r(n,e,r){return r&&e.indexOf("&")+1?e.replace(/&/g,n):n+e}function a(i,s,p,h,w,k,m,d){switch(d=i,c.call(i)){case o:for(k=i.length;k--;)a(i[k],s,p,h,w);break;case f:d={};for(k in i)"@"==k[0]&&(m=i[k],c.call(m)==u?s.push(k+" "+m+";"):k.match(/^@keyframes /)?(k=w?k.replace(/ ([-\w]+)/,w):k,s.push("}"),a(m,s,"",h,w),s.push(k+"{"),s.push("}"),a(m,s,"",["webkit"]),s.push("@-webkit-"+k.slice(1)+"{")):k.match(/^@font-face/)?a(m,s,k,t):(s.push("}"),a(m,s,p,h,w),s.push(k+"{")));for(k in i)m=i[k],k.match(/^[-\w$]+$/)?d[k]=m:"@"!=k[0]&&a(m,s,p.indexOf(",")+k.indexOf(",")+2?e(p.split(","),k.split(","),1).join(","):r(p,k,1),h,w);case u:for(k in d)if(l.call(d,k)){s.push("}"),n(d,s,"",h,w),s.push((w?p.replace(/\.([-\w]+)/,w):p||"*")+"{");break}}}function i(n){return n.reverse().join("\n")}var t=[],c={}.toString,l={}.hasOwnProperty,f=c.call({}),o=c.call(t),u=c.call(""),s="_j2c_"+(1e9*Math.random()|0)+"_"+1*new Date+"_",p=0,h={};return h.inline=function(e,r,a){return n(e,a=[],"",r||t),i(a)},h.sheet=function(n,e,r){return a(n,r=[],"",e||t),i(r)},h.local=function(n,e){e=e||{};var r=s+p++,c=e.global||[],f={},o=[];a(n,o,"",e.vendors||t,function(n,e){return c.indexOf(e)+1?n:(f[e]||f[e]=e+r,n+r)}),o=new String(i(o));for(k in n)l.call(n,k)&&(o[k]=classes[k]);return o},h.prefix=function(n,r){return e(r.map(function(n){return"-"+n+"-"}).concat([""]),[n])},h}(); |
53
j2c.js
@@ -26,7 +26,7 @@ /*/-notice-/*//* | ||
// turned into strings. | ||
function _declarations(o, buf, prefix, vendors, /*var*/ k, v, kk) { | ||
function _declarations(o, buf, prefix, vendors, localize,/*var*/ k, v, kk) { | ||
switch (type.call(o)) { | ||
case ARRAY: | ||
for (k = o.length;k--;) | ||
_declarations(o[k], buf, prefix, vendors); | ||
_declarations(o[k], buf, prefix, vendors, localize); | ||
break; | ||
@@ -39,6 +39,6 @@ case OBJECT: | ||
// "$" was found. | ||
for (kk in k = k.split("$")) if (own.call(k, kk)) | ||
_declarations(v, buf, prefix + k[kk], vendors); | ||
for (kk in k = k.split("$").reverse()) if (own.call(k, kk)) | ||
_declarations(v, buf, prefix + k[kk], vendors, localize); | ||
} else { | ||
_declarations(v, buf, prefix + k, vendors); | ||
_declarations(v, buf, prefix + k, vendors, localize); | ||
} | ||
@@ -53,3 +53,10 @@ } | ||
// `o` is the value. | ||
buf.push(o = (prefix && (prefix).replace(/_/g, "-") + ":") + o + ";"); | ||
k=(prefix && (prefix).replace(/_/g, "-") + ":") | ||
if (localize && k=="animation:") o = o.replace(/([-\w]+)/, localize); | ||
if (localize && k=="animation-name:") o = o.split(',').map(function(o){ | ||
return o.replace(/([-\w]+)/, localize)} | ||
).join(","); | ||
buf.push(o = k + o + ";"); | ||
// vendorify | ||
@@ -87,3 +94,3 @@ for (k = vendors.length; k--;) | ||
function _concat(a, b, selectorP) { | ||
return selectorP && b.indexOf("&") + 1 ? b.replace("&", a) : a + b | ||
return selectorP && b.indexOf("&") + 1 ? b.replace(/&/g, a) : a + b | ||
} | ||
@@ -93,3 +100,3 @@ | ||
// Add rulesets and other CSS statements to the sheet. | ||
function _add(statements, buf, prefix, vendors, /*var*/ k, v, decl) { | ||
function _add(statements, buf, prefix, vendors, localize, /*var*/ k, v, decl) { | ||
// optionally needed in the "[object String]" case | ||
@@ -105,3 +112,3 @@ // where the `statements` variable actually holds | ||
for (k = statements.length;k--;) | ||
_add(statements[k], buf, prefix, vendors); | ||
_add(statements[k], buf, prefix, vendors, localize); | ||
break; | ||
@@ -118,4 +125,5 @@ | ||
} else if (k.match(/^@keyframes /)) { | ||
k = localize ? k.replace(/ ([-\w]+)/, localize) : k | ||
buf.push("}"); | ||
_add(v, buf, "", vendors); | ||
_add(v, buf, "", vendors, localize); | ||
buf.push(k + "{"); | ||
@@ -134,3 +142,3 @@ | ||
buf.push("}"); | ||
_add(v, buf, prefix, vendors); | ||
_add(v, buf, prefix, vendors, localize); | ||
buf.push(k + "{"); | ||
@@ -155,3 +163,3 @@ } | ||
, | ||
vendors | ||
vendors, localize | ||
); | ||
@@ -170,4 +178,4 @@ } | ||
buf.push("}"); | ||
_declarations(decl, buf, "", vendors); | ||
buf.push((prefix || "*") + "{"); | ||
_declarations(decl, buf, "", vendors, localize); | ||
buf.push((localize ? prefix.replace(/\.([-\w]+)/, localize):prefix || "*") + "{"); | ||
break; | ||
@@ -202,2 +210,19 @@ } | ||
} | ||
j2c.local = function (statements, options) { | ||
options = options || {}; | ||
var suffix = scope_root + counter++ | ||
, global = options.global || [] | ||
, locals = {} | ||
, buf = [] | ||
; | ||
_add(statements, buf, "", options.vendors || empty, function (match, k) { | ||
if (global.indexOf(k) + 1) return match; | ||
locals[k] || locals[k] = k+suffix; | ||
return match + suffix; | ||
}); | ||
buf = new String(_finalize(buf)); | ||
for (k in statements) if (own.call(statements, k)) buf[k] = classes[k]; | ||
return buf; | ||
} | ||
/*/-statements-/*/ | ||
@@ -204,0 +229,0 @@ |
{ | ||
"name": "j2c", | ||
"version": "0.7.1", | ||
"version": "0.7.2", | ||
"description": "A JavaScript object to CSS compiler.", | ||
@@ -8,3 +8,4 @@ "main": "dist/j2c.commonjs.js", | ||
"build": "node scripts/build.js", | ||
"test": "node_modules/mocha/bin/mocha --reporter nyan --ui qunit" | ||
"test": "node_modules/mocha/bin/mocha --reporter nyan --ui qunit", | ||
"cover": "node_modules/mocha/bin/mocha --require blanket --ui qunit --reporter mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js" | ||
}, | ||
@@ -21,2 +22,7 @@ "repository": { | ||
}, | ||
"config": { | ||
"blanket": { | ||
"pattern": "//j2c\\.commonjs/" | ||
} | ||
}, | ||
"homepage": "http://j2c.py.gy", | ||
@@ -28,4 +34,7 @@ "devDependencies":{ | ||
"expect.js":"*", | ||
"surgicate":"*" | ||
"surgicate":"*", | ||
"coveralls": "^2.11.2", | ||
"mocha-lcov-reporter": "0.0.2", | ||
"blanket": "^1.1.7" | ||
} | ||
} |
198
README.md
@@ -0,1 +1,4 @@ | ||
[![Build Status](https://travis-ci.org/pygy/j2c.svg?branch=master)](https://travis-ci.org/pygy/j2c) | ||
[![Coverage Status](https://coveralls.io/repos/pygy/j2c/badge.svg?branch=master)](https://coveralls.io/r/pygy/j2c?branch=master) | ||
# j2c | ||
@@ -7,6 +10,3 @@ | ||
---- | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
**Table of Contents** | ||
## Table of Contents | ||
@@ -29,12 +29,7 @@ - [Why?](#why) | ||
- [Scoped sheet for components: `j2c.scoped(...)`](#scoped-sheet-for-components-j2cscoped) | ||
- [Inserting a stylesheet in a document](#inserting-the-stylesheet-in-the-document) | ||
- [Limitations](#limitations) | ||
- [Selectors and properties order](#selectors-and-properties-order) | ||
- [No input validation](#no-input-validation) | ||
- [No pretty printing](#no-pretty-printing) | ||
- [TODO](#todo) | ||
- [License: MIT](#license-mit) | ||
<small>*TOC generated with [DocToc](https://github.com/thlorenz/doctoc), then tweaked a bit.*</small> | ||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
---- | ||
@@ -44,3 +39,3 @@ | ||
* Send small, compact, SASS-like data down the line | ||
* Write your stylsheet in a SASS-like manner | ||
* Simplify your asset pipeline | ||
@@ -97,7 +92,7 @@ * Use the full power of JavaScript for mixins, variables, macros and feature detection | ||
view: function (ctrl) { | ||
return m('.widget', [ | ||
m('style', Widget.styles) | ||
m('h3', { class: Widget.styles.title }), | ||
m('div', { class: Widget.styles.content }) | ||
]) | ||
return <div> | ||
<style>{Widget.styles}</style> | ||
<h3 class="{Widget.styles.title}">Hello</h3> | ||
<div class="{Widget.styles.content}">Foo bar baz</div> | ||
</div> | ||
} | ||
@@ -152,2 +147,13 @@ } | ||
or | ||
```JavaScript | ||
j2c.inline({ | ||
border: [ | ||
"solid 1px grey", | ||
{left: "dashed 3px green"} | ||
] | ||
}) | ||
``` | ||
```CSS | ||
@@ -347,4 +353,16 @@ border: solid 1px grey; | ||
At rules are guarateed to be inserted after the properties and sub-selectors at a given level. This prevents nested `@media` blocks to be overridden by declarations found out of them. | ||
At-rules are guarateed to be inserted after the properties and sub-selectors at a given level. This prevents nested `@media` blocks to be overridden by declarations found out of them. | ||
If you need several media queries where the order of definition is important, or if you need at-rules that must be inserted at the top of a sheet, use arrays. | ||
```JavaScript | ||
j2c.sheet([ | ||
{"@import": "url(foo.css)"}, | ||
{"@namespace": "url(http://www.w3.org/1999/xhtml)"}, | ||
{"@namespace": "svg url(http://www.w3.org/2000/svg)"}, | ||
{ | ||
".your": {sheet:"here"} | ||
} | ||
]) | ||
#### CSS Hacks | ||
@@ -392,3 +410,3 @@ | ||
`j2c.scoped` offers a [`JSS`](https://github.com/jsstyles/jss)-like functionality: | ||
`j2c.scoped` offers a [JSS](https://github.com/jsstyles/jss)-like functionality: | ||
@@ -421,4 +439,28 @@ ```JavaScript | ||
*Caveat:* At the moment, animations defined with `@keyframes` are still part of the global CSS namespace. The same goes for font names defined in `@font-face` blocks. | ||
#### Scoped animations (to be implemented) | ||
```JavaScript | ||
styles = j2c.scoped({ | ||
foo: { | ||
"@keyframes bar": { | ||
//... | ||
}, | ||
" .baz": { | ||
animation: "bar" | ||
} | ||
} | ||
}) | ||
``` | ||
```CSS | ||
._foo_j2c_3465769785678_76876576587_1 { | ||
animation: bar_foo_j2c_3465769785678_76876576587_1 | ||
} | ||
@keyframes bar_foo_j2c_3465769785678_76876576587_1 { | ||
/* ... */ | ||
} | ||
``` | ||
## Vendor prefixes: | ||
@@ -492,2 +534,110 @@ | ||
## Inserting the stylesheet in the document | ||
Foreword: Please note that the following is based on research on the Web, but not effectively tested in Internet explorer at the moment. | ||
### ie9+ | ||
Add a text node to a new `style` element. | ||
```JavaScript | ||
var style = document.createElement('style'); | ||
style.type = 'text/css'; // my not even be needed | ||
style.appendChild(document.createTextNode(sheet)); | ||
``` | ||
In frameworks: | ||
```Handlebars | ||
<style>{sheet}</style> | ||
``` | ||
Sweet, innit? | ||
### ie8+ (sheets up to 32k in ie8) | ||
As above, but with a `link` element and a data URI. | ||
```Handlebars | ||
<link rel="stylesheet" itemprop="stylesheet" href="{'data:,' + encodeURIComponent(sheet)}" /> | ||
``` | ||
Note that ie8 has a 32k limit on the length of data URIs. It supports base 64 in data URIs, but doesn't provide `btoa`, which would not be useful in this context anyway, since base 64 encoded sheets are larger than URI encoded ones. | ||
### ie6+ (unlimited sheet size) | ||
```JavaScript | ||
function stylize(element, sheet){ | ||
element.type = 'text/css'; | ||
if (element.styleSheet){ | ||
element.styleSheet.cssText = sheet; | ||
} else { | ||
element.appendChild(document.createTextNode(sheet)); | ||
} | ||
return element; | ||
} | ||
var style = document.createElement('style') | ||
stylize(style); | ||
document.head.appendChild(style); | ||
``` | ||
For this to work in client-side frameworks, you need to grab a handle on the actual `<style>` DOM node. This means that you must create a custom component/directive. | ||
Here are a few examples: | ||
#### React: | ||
```JavaScript | ||
var j2cComponent = { | ||
render: function(){ | ||
return <style /> | ||
} | ||
componentDidMount: function(){ | ||
stylize(React.findDOMNode(this), this.prop.sheet) | ||
} | ||
} | ||
``` | ||
#### Mithril: | ||
```JavaScript | ||
var j2cComponent = { | ||
view: function(ctrl, args) { | ||
return m("style", { | ||
sheet: args.sheet | ||
config: function(el, isinit, vdom) { | ||
if(!isinit) { | ||
stylize(el, vdom.attrs.sheet); | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
``` | ||
#### Angular v1.3- (1.4 is ie9+) | ||
```JavaScript | ||
module.directive('j2cSheet', function() { | ||
return { | ||
restrict: 'A', | ||
link: function link(scope, element, attrs) { | ||
if (element.tagName.toUpperCase() !== "STYLE") throw 'j2cSheet expects a <style> element'; | ||
stylize(element[0], attrs.j2cSheet); | ||
} | ||
}; | ||
}); | ||
module.directive('j2cInline', function() { | ||
return { | ||
restrict: 'A', | ||
link: function link(scope, element, attrs) { | ||
element[0].style += j2c.inline(attrs.j2cInline); | ||
} | ||
}; | ||
}); | ||
``` | ||
## Limitations | ||
@@ -529,3 +679,3 @@ | ||
### No pretty printing | ||
### Little pretty printing | ||
@@ -538,3 +688,3 @@ `j2c` puts each selector list and properties on their own lines, but doesn't indent or add other white space. | ||
It's up to you to pick distinctive names. | ||
It's up to you to pick distinctive names. This is high on the TODO list. | ||
@@ -545,2 +695,8 @@ ### Vendor prefixes corner cases | ||
## TODO: | ||
- Improve the web site. Move the docs there. | ||
- Test DOM insertion methods in old IE. | ||
- Add scoped animation names and maybe font names too? | ||
## License: MIT |
@@ -371,2 +371,13 @@ var j2c, | ||
test("& &", function() { | ||
check( | ||
j2c.sheet({".foo": { | ||
"& &": { | ||
bar: "baz" | ||
} | ||
}}), | ||
".foo .foo{bar:baz}" | ||
) | ||
}); | ||
test("2 x 2", function() { | ||
@@ -376,3 +387,3 @@ check( | ||
" .foo, .bar":{ | ||
" .baz &, .qux &":{ | ||
" .baz &, .qux":{ | ||
foo:"bar" | ||
@@ -383,3 +394,3 @@ } | ||
".baz p .foo,.baz p .bar,.qux p .foo,.qux p .bar {foo:bar}" | ||
".baz p .foo,.baz p .bar,p .foo .qux ,p .bar .qux {foo:bar}" | ||
) | ||
@@ -602,3 +613,3 @@ }); | ||
; | ||
for (var i = 100; i--;){ | ||
for (var i = 17; i--;){ | ||
o = {" p":{}} | ||
@@ -613,8 +624,50 @@ o[" p"][prop] = 5 | ||
) total++; | ||
o = {" p":{}} | ||
o[" p"][prop] = 5 | ||
o[" p"]["@media (min-width:" + width + "em)"] = {bar:7} | ||
o[" p"]["."+klass] = {foo:6} | ||
if ( | ||
normalize(j2c.sheet(o)) | ||
!= | ||
normalize("p{" + prop +":5;} p." + klass + "{foo:6;} @media (min-width:" + width + "em){p{bar:7;}}") | ||
) total++; | ||
o = {" p":{}} | ||
o[" p"]["."+klass] = {foo:6} | ||
o[" p"][prop] = 5 | ||
o[" p"]["@media (min-width:" + width + "em)"] = {bar:7} | ||
if ( | ||
normalize(j2c.sheet(o)) | ||
!= | ||
normalize("p{" + prop +":5;} p." + klass + "{foo:6;} @media (min-width:" + width + "em){p{bar:7;}}") | ||
) total++; | ||
o = {" p":{}} | ||
o[" p"]["."+klass] = {foo:6} | ||
o[" p"]["@media (min-width:" + width + "em)"] = {bar:7} | ||
o[" p"][prop] = 5 | ||
if ( | ||
normalize(j2c.sheet(o)) | ||
!= | ||
normalize("p{" + prop +":5;} p." + klass + "{foo:6;} @media (min-width:" + width + "em){p{bar:7;}}") | ||
) total++; | ||
o = {" p":{}} | ||
o[" p"]["@media (min-width:" + width + "em)"] = {bar:7} | ||
o[" p"]["."+klass] = {foo:6} | ||
o[" p"][prop] = 5 | ||
if ( | ||
normalize(j2c.sheet(o)) | ||
!= | ||
normalize("p{" + prop +":5;} p." + klass + "{foo:6;} @media (min-width:" + width + "em){p{bar:7;}}") | ||
) total++; | ||
o = {" p":{}} | ||
o[" p"]["@media (min-width:" + width + "em)"] = {bar:7} | ||
o[" p"][prop] = 5 | ||
o[" p"]["."+klass] = {foo:6} | ||
if ( | ||
normalize(j2c.sheet(o)) | ||
!= | ||
normalize("p{" + prop +":5;} p." + klass + "{foo:6;} @media (min-width:" + width + "em){p{bar:7;}}") | ||
) total++; | ||
} | ||
expect(total).to.be(0); | ||
}); | ||
}) | ||
@@ -621,0 +674,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98578
25
1995
691
8