Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

j2c

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

j2c - npm Package Compare versions

Comparing version 1.0.0-1 to 1.0.0-2

gzip

280

dist/j2c.amd.js

@@ -11,2 +11,10 @@ define(function () { 'use strict';

var own = emptyObject.hasOwnProperty;
var freeze = Object.freeze || function(o) {return o};
function Default(target, source) {
for (var k in source) if (own.call(source, k)) {
if (k.indexOf('$') && !(k in target)) target[k] = source[k]
}
return target
}
function cartesian(a,b) {

@@ -38,5 +46,5 @@ var res = [], i, j

/*eslint-disable no-cond-assign*/
while(o = selectorTokenizer.exec(selector)) {
while (o = selectorTokenizer.exec(selector)) {
/*eslint-enable no-cond-assign*/
switch(o[0]){
switch (o[0]) {
case '(': inParen++; break

@@ -62,3 +70,3 @@ case ')': inParen--; break

/*eslint-disable no-cond-assign*/
while(o = ampersandTokenizer.exec(selector)) {
while (o = ampersandTokenizer.exec(selector)) {
/*eslint-enable no-cond-assign*/

@@ -93,3 +101,4 @@ if (o[0] == '&') indices.push(o.index)

*
* @param {object} parser - holds the parser-related methods and state
* @param {object} state - holds the localizer- and walker-related methods
* and state
* @param {object} emit - the contextual emitters to the final buffer

@@ -102,3 +111,3 @@ * @param {string} prefix - the current property or a prefix in case of nested

function declarations(parser, emit, prefix, o, local) {
function declarations(state, emit, prefix, o, local) {
var k, v, kk

@@ -111,3 +120,3 @@ if (o==null) return

declarations(parser, emit, prefix, o[k], local)
declarations(state, emit, prefix, o[k], local)

@@ -124,3 +133,3 @@ break

declarations(parser, emit, prefix + k[kk], v, local)
declarations(state, emit, prefix + k[kk], v, local)

@@ -130,3 +139,3 @@ }

declarations(parser, emit, prefix + k, v, local)
declarations(state, emit, prefix + k, v, local)

@@ -149,6 +158,6 @@ }

// no need to tokenize here a plain `.split(',')` has all bases covered.
// We may 'parser' a comment, but it's not a big deal.
// We may 'localize' a comment, but it's not a big deal.
o = o.split(',').map(function (o) {
return o.replace(/($^)|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/, parser.L)
return o.replace(/(var\([^)]+\))|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/, state.L)

@@ -166,3 +175,4 @@ }).join(',')

*
* @param {object} parser - holds the parser-related methods and state
* @param {object} state - holds the localizer- and walker-related methods
* and state
* @param {object} emit - the contextual emitters to the final buffer

@@ -181,13 +191,17 @@ * @param {array} k - The parsed at-rule, including the parameters,

function atRules(parser, emit, k, v, prefix, local, inAtRule) {
function atRules(state, emit, k, v, prefix, local, inAtRule) {
for (var i = 0; i < parser.$a.length; i++) {
for (var i = 0; i < state.$a.length; i++) {
if (parser.$a[i](parser, emit, k, v, prefix, local, inAtRule)) return
if (state.$a[i](state, emit, k, v, prefix, local, inAtRule)) return
}
// using `/^global$/.test(k[2])` rather that 'global' == k[2] gzips
// slightly better because of the regexps test further down.
// It is slightly less efficient but this isn't a critical path.
if (!k[3] && /^global$/.test(k[2])) {
sheet(parser, emit, prefix, v, 0, inAtRule)
rules(state, emit, prefix, v, 0, inAtRule)

@@ -197,3 +211,3 @@

sheet(parser, emit, prefix, v, 1, inAtRule)
rules(state, emit, prefix, v, 1, inAtRule)

@@ -208,8 +222,7 @@

i = []
flatIter(function(c, s){
s = c.toString()
flatIter(function(adoptee, asString) {
if(!/^\.?[_A-Za-z][-\w]*(?:\s+\.?[_A-Za-z][-\w]*)*$/.test(s)) emit.a('@-error-bad-at-adoptee', JSON.stringify(c), 0)
if(!/^\.?[_A-Za-z][-\w]*(?:\s+\.?[_A-Za-z][-\w]*)*$/.test(asString = adoptee.toString())) emit.a('@-error-bad-at-adoptee', JSON.stringify(adoptee), 0)
else i.push(s.replace(/\./g, ''))
else i.push(asString.replace(/\./g, ''))

@@ -220,5 +233,4 @@ })(v)

if (i.length) {
// console.log("========== I ===========\n", i)
parser.l(k[3] = k[3].replace(/\./g, ''))
parser.n[k[3]] += (' ' + i.join(' '))
state.l(k[3] = k[3].replace(/\./g, ''))
state.n[k[3]] += (' ' + i.join(' '))
}

@@ -240,3 +252,3 @@

declarations(parser, emit, '', v, local)
declarations(state, emit, '', v, local)

@@ -252,4 +264,4 @@ emit.A(k[1], '')

// generated by script/regexps.js
/($^)|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,
parser.L
/(var\([^)]+\))|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,
state.L
)

@@ -263,8 +275,8 @@ }

declarations(parser, emit, '', v, local)
declarations(state, emit, '', v, local)
} else {
sheet(
parser, emit,
rules(
state, emit,
'keyframes' == k[2] ? '' : prefix,

@@ -288,3 +300,4 @@ v, local, 1

*
* @param {object} parser - holds the parser-related methods and state
* @param {object} state - holds the localizer- and walker-related methods
* and state
* @param {object} emit - the contextual emitters to the final buffer

@@ -296,3 +309,3 @@ * @param {string} prefix - the current selector or a prefix in case of nested rules

*/
function sheet(parser, emit, prefix, tree, local, inAtRule) {
function rules(state, emit, prefix, tree, local, inAtRule) {
var k, v, inDeclaration, kk

@@ -306,3 +319,3 @@

if (prefix && /^[-\w$]+$/.test(k)) {
if (prefix.length > 0 && /^[-\w$]+$/.test(k)) {
if (!inDeclaration) {

@@ -317,3 +330,3 @@ inDeclaration = 1

declarations(parser, emit, k[kk], v, local)
declarations(state, emit, k[kk], v, local)

@@ -323,3 +336,3 @@ }

declarations(parser, emit, k, v, local)
declarations(state, emit, k, v, local)

@@ -332,3 +345,3 @@ }

atRules(parser, emit,
atRules(state, emit,
/^(.(?:-[\w]+-)?([_A-Za-z][-\w]*))\b\s*(.*?)\s*$/.exec(k) || [k,'@','',''],

@@ -342,7 +355,7 @@ v, prefix, local, inAtRule

sheet(
parser, emit,
rules(
state, emit,
// `prefix` ... Hefty. Ugly. Sadly necessary.
//
(prefix && (/,/.test(prefix) || /,/.test(k))) ?
(prefix.length > 0 && (/,/.test(prefix) || /,/.test(k))) ?

@@ -353,3 +366,4 @@ /*0*/ (kk = splitSelector(prefix), splitSelector(

k.replace(
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g, parser.L
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,
state.L
) :

@@ -370,3 +384,4 @@

k.replace(
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g, parser.L
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,
state.L
) :

@@ -382,3 +397,4 @@

k.replace(
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g, parser.L
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,
state.L
) :

@@ -399,3 +415,3 @@

sheet(parser, emit, prefix, tree[k], local, inAtRule)
rules(state, emit, prefix, tree[k], local, inAtRule)

@@ -408,5 +424,5 @@ }

emit.s(prefix || ':-error-no-selector')
emit.s(prefix.length > 0 ? prefix : ':-error-no-selector')
declarations(parser, emit, '', tree, local)
declarations(state, emit, '', tree, local)

@@ -476,5 +492,30 @@ }

function j2c() {
// palceholder for the buffer used by the `$sink` handlers
var buf
// the bottom of the 'codegen' stream. Mirrors the `$filter` plugin API.
var $sink = {
// Init
i: function(){buf=[]},
// done (eXit)
x: function (raw) {return raw ? buf : buf.join('')},
// start At-rule
a: function (rule, argument, takesBlock) {
buf.push(rule, argument && ' ',argument, takesBlock ? ' {\n' : ';\n')
},
// end At-rule
A: function () {buf.push('}\n')},
// start Selector
s: function (selector) {buf.push(selector, ' {\n')},
// end Selector
S: function () {buf.push('}\n')},
// declarations
d: function (prop, value) {buf.push(prop, prop && ':', value, ';\n')}
}
var $filters = [closeSelectors]
var $atHandlers = []
var instance = {
var _instance = {
at: at,

@@ -491,3 +532,3 @@ global: global,

_use(emptyArray.slice.call(arguments))
return instance
return _instance
},

@@ -497,40 +538,61 @@ $plugins: []

function _default(target, source) {
for (var k in source) if (own.call(source, k) && k.indexOf('$')) {
if (OBJECT == type.call(source[k]) && OBJECT == type.call(target[k])) _default(target[k], source[k])
else if (!(k in target)) target[k] = source[k]
}
}
var _streams = []
var buf
var $sink = {
i: function(){buf=[]},
x: function (raw) {return raw ? buf : buf.join('')},
a: function (rule, argument, takesBlock) {
buf.push(rule, argument && ' ',argument, takesBlock ? ' {\n' : ';\n')
},
A: function () {buf.push('}\n')},
s: function (selector) {buf.push(selector, ' {\n')},
S: function () {buf.push('}\n')},
d: function (prop, value) {buf.push(prop, prop && ':', value, ';\n')}
}
var streams = []
// The `state` (for the core) / `walker` (for the plugins) tables.
var parsers = [
var _walkers = [
// for j2c.sheet
{
$a: $atHandlers,
// helpers for locaizing class and animation names
L: _localizeReplacer, // second argument to String.prototype.replace
l: _localize, // mangles local names
n: _instance.names, // local => mangled mapping
$a: $atHandlers, // extra at-rules
// The core walker methods, to be provided to plugins
a: atRules,
d: declarations,
L: localizeReplacer,
l: localize,
n: instance.names,
s: sheet
}, {
d: declarations,
L: localizeReplacer,
l: localize,
n: instance.names
r: rules
},
// likewise, for j2c.inline (idem with `$a`, `a` and `s` removed)
{
L: _localizeReplacer,
l: _localize,
n: _instance.names,
d: declarations
}
]
// The main API functions
_instance.sheet = function(tree) {
var emit = _getStream(0)
emit.i()
rules(
_walkers[0],
emit,
'', // prefix
tree,
1, // local, by default
0 // inAtRule
)
return emit.x()
}
_instance.inline = function (tree) {
var emit = _getStream(1)
emit.i()
declarations(
_walkers[1],
emit,
'', // prefix
tree,
1 //local
)
return emit.x()
}
// inner helpers
var _use = flatIter(function(plugin) {

@@ -541,7 +603,7 @@ // `~n` is falsy for `n === -1` and truthy otherwise.

// `a`.
if (~instance.$plugins.indexOf(plugin)) return
if (~_instance.$plugins.indexOf(plugin)) return
instance.$plugins.push(plugin)
_instance.$plugins.push(plugin)
if (type.call(plugin) === FUNCTION) plugin = plugin(instance)
if (type.call(plugin) === FUNCTION) plugin = plugin(_instance)

@@ -558,58 +620,38 @@ if (!plugin) return

Default(_instance.names, plugin.$names || emptyObject)
_use(plugin.$plugins || emptyArray)
$sink = plugin.$sink || $sink
_default(instance, plugin)
Default(_instance, plugin)
})
function getStream(inline) {
if (!streams.length) {
function _getStream(inline) {
if (!_streams.length) {
for(var i = 0; i < 2; i++){
$filters[$filters.length - i] = function(_, inline) {return inline ? {i:$sink.i, d:$sink.d, x:$sink.x} : $sink}
for (var j = $filters.length; j--;) streams[i] = $filters[j](streams[i], !!i, parsers[i])
for (var j = $filters.length; j--;) {
_streams[i] = freeze(Default(
$filters[j](_streams[i], !!i, _walkers[i]),
_streams[i]
))
}
}
}
var res = streams[inline]
var res = _streams[inline]
return res
}
function localize(name) {
if (!instance.names[name]) instance.names[name] = name + instance.suffix
return instance.names[name].match(/^\S+/)
function _localize(name) {
if (!_instance.names[name]) _instance.names[name] = name + _instance.suffix
return _instance.names[name].match(/^\S+/)
}
function localizeReplacer(match, string, global, dot, name) {
function _localizeReplacer(match, string, global, dot, name) {
if (string || global) return string || global
return dot + localize(name)
return dot + _localize(name)
}
/*/-statements-/*/
instance.sheet = function(tree) {
var emit = getStream(0)
emit.i()
sheet(
parsers[0],
emit,
'', // prefix
tree,
1, // local, by default
0 // inAtRule
)
return emit.x()
}
/*/-statements-/*/
instance.inline = function (tree) {
var emit = getStream(1)
emit.i()
declarations(
parsers[1],
emit,
'', // prefix
tree,
1 //local
)
return emit.x()
}
return instance
return _instance
}

@@ -616,0 +658,0 @@

@@ -1,1 +0,1 @@

define(function(){"use strict";function n(n,t){var e,a,r=[];for(a in t)if(v.call(t,a))for(e in n)v.call(n,e)&&r.push(n[e]+t[a]);return r}function t(n){for(var t,e=[],a=[],r=0;t=S.exec(n);)switch(t[0]){case"(":r++;break;case")":r--;break;case",":if(r)break;e.push(t.index)}for(t=e.length;t--;)a.unshift(n.slice(e[t]+1)),n=n.slice(0,e[t]);return a.unshift(n),a}function e(t,e){for(var a,r,i=[],s=[];r=A.exec(t);)"&"==r[0]&&i.push(r.index);for(r=i.length;r--;)s.unshift(t.slice(i[r]+1)),t=t.slice(0,i[r]);for(s.unshift(t),a=[s[0]],r=1;r<s.length;r++)a=n(a,n(e,[s[r]]));return a.join(",")}function a(n){return function t(e){if(m.call(e)===d)for(var a=0;a<e.length;a++)t(e[a]);else n(e)}}function r(n){return"-"+n.toLowerCase()}function i(n,t,e,a,s){var l,o,f;if(null!=a)switch(m.call(a=a.valueOf())){case d:for(l=0;l<a.length;l++)i(n,t,e,a[l],s);break;case $:e=e&&e+"-";for(l in a)if(v.call(a,l))if(o=a[l],/\$/.test(l))for(f in l=l.split("$"))v.call(l,f)&&i(n,t,e+l[f],o,s);else i(n,t,e+l,o,s);break;default:l=e.replace(/_/g,"-").replace(/[A-Z]/g,r),!s||"animation-name"!=l&&"animation"!=l&&"list-style"!=l||(a=a.split(",").map(function(t){return t.replace(/($^)|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,n.L)}).join(",")),t.d(l,a)}}function s(n,t,e,r,s,o,f){for(var u=0;u<n.$a.length;u++)if(n.$a[u](n,t,e,r,s,o,f))return;if(!e[3]&&/^global$/.test(e[2]))l(n,t,s,r,0,f);else if(!e[3]&&/^local$/.test(e[2]))l(n,t,s,r,1,f);else if(e[3]&&/^adopt$/.test(e[2])){if(!o||f)return t.a("@-error-bad-at-adopt-placement",JSON.stringify(e[0]),0);if(!/^\.?[_A-Za-z][-\w]*$/.test(e[3]))return t.a("@-error-bad-at-adopter",e[3],0);u=[],a(function(n,e){e=n.toString(),/^\.?[_A-Za-z][-\w]*(?:\s+\.?[_A-Za-z][-\w]*)*$/.test(e)?u.push(e.replace(/\./g,"")):t.a("@-error-bad-at-adoptee",JSON.stringify(n),0)})(r),u.length&&(n.l(e[3]=e[3].replace(/\./g,"")),n.n[e[3]]+=" "+u.join(" "))}else!e[3]&&/^(?:namespace|import|charset)$/.test(e[2])?a(function(n){t.a(e[0],n)})(r):!e[3]&&/^(?:font-face|viewport)$/.test(e[2])?a(function(a){t.a(e[1],"",1),i(n,t,"",a,o),t.A(e[1],"")})(r):e[3]&&/^(?:media|supports|page|keyframes)$/.test(e[2])?(o&&"keyframes"==e[2]&&(e[3]=e[3].replace(/($^)|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,n.L)),t.a(e[1],e[3],1),"page"==e[2]?i(n,t,"",r,o):l(n,t,"keyframes"==e[2]?"":s,r,o,1),t.A(e[1],e[3])):t.a("@-error-unsupported-at-rule",JSON.stringify(e[0]))}function l(n,a,r,o,f,u){var c,p,g,h;switch(m.call(o)){case $:for(c in o)if(v.call(o,c))if(p=o[c],r&&/^[-\w$]+$/.test(c))if(g||(g=1,a.s(r)),/\$/.test(c))for(h in c=c.split("$"))v.call(c,h)&&i(n,a,c[h],p,f);else i(n,a,c,p,f);else/^@/.test(c)?(g=0,s(n,a,/^(.(?:-[\w]+-)?([_A-Za-z][-\w]*))\b\s*(.*?)\s*$/.exec(c)||[c,"@","",""],p,r,f,u)):(g=0,l(n,a,r&&(/,/.test(r)||/,/.test(c))?(h=t(r),t(f?c.replace(/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,n.L):c).map(function(n){return/&/.test(n)?e(n,h):h.map(function(t){return t+n}).join(",")}).join(",")):/&/.test(c)?e(f?c.replace(/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,n.L):c,[r]):r+(f?c.replace(/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,n.L):c),p,f,u));break;case d:for(c=0;c<o.length;c++)l(n,a,r,o[c],f,u);break;case w:a.s(r||":-error-no-selector"),i(n,a,"",o,f)}}function o(n,t){var e;return t?n:{i:function(){e=0,n.i()},x:function(t){return e&&(n.S(),e=0),n.x(t)},a:function(t,a,r){e&&(n.S(),e=0),n.a(t,a,r)},A:function(t){e&&(n.S(),e=0),n.A(t)},s:function(t){t!==e&&(e&&n.S(),n.s(t),e=t)},d:n.d}}function f(n){return":global("+n+")"}function u(n,t,e){return e={},e[n]=t,e}function c(n,t,e){if(arguments.length<3){var a=c.bind.apply(c,[null].concat([].slice.call(arguments,0)));return a.toString=function(){return"@"+n+" "+t},a}return u("@"+n+" "+t,e)}function p(){function n(t,e){for(var a in e)v.call(e,a)&&a.indexOf("$")&&($==m.call(e[a])&&$==m.call(t[a])?n(t[a],e[a]):a in t||(t[a]=e[a]))}function t(n){if(!A.length)for(var t=0;2>t;t++){h[h.length-t]=function(n,t){return t?{i:S.i,d:S.d,x:S.x}:S};for(var e=h.length;e--;)A[t]=h[e](A[t],!!t,x[t])}var a=A[n];return a}function e(n){return w.names[n]||(w.names[n]=n+w.suffix),w.names[n].match(/^\S+/)}function r(n,t,a,r,i){return t||a?t||a:r+e(i)}var p,h=[o],d=[],w={at:c,global:f,kv:u,names:{},suffix:"__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),use:function(){return _(g.slice.call(arguments)),w},$plugins:[]},S={i:function(){p=[]},x:function(n){return n?p:p.join("")},a:function(n,t,e){p.push(n,t&&" ",t,e?" {\n":";\n")},A:function(){p.push("}\n")},s:function(n){p.push(n," {\n")},S:function(){p.push("}\n")},d:function(n,t){p.push(n,n&&":",t,";\n")}},A=[],x=[{$a:d,a:s,d:i,L:r,l:e,n:w.names,s:l},{d:i,L:r,l:e,n:w.names}],_=a(function(t){~w.$plugins.indexOf(t)||(w.$plugins.push(t),m.call(t)===b&&(t=t(w)),t&&(a(function(n){h.push(n)})(t.$filter||g),a(function(n){d.push(n)})(t.$at||g),S=t.$sink||S,n(w,t)))});return w.sheet=function(n){var e=t(0);return e.i(),l(x[0],e,"",n,1,0),e.x()},w.inline=function(n){var e=t(1);return e.i(),i(x[1],e,"",n,1),e.x()},w}var g=[],h={},m=h.toString,d=m.call(g),$=m.call(h),w=m.call(""),b=m.call(m),v=h.hasOwnProperty,S=/[(),]|"(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\//g,A=/&|"(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\//g,x=p();return"sheet|inline|names|at|global|kv|suffix".split("|").map(function(n){p[n]=x[n]}),p});
define(function(){"use strict";function n(n,t){for(var e in t)S.call(t,e)&&(!e.indexOf("$")||e in n||(n[e]=t[e]));return n}function t(n,t){var e,r,a=[];for(r in t)if(S.call(t,r))for(e in n)S.call(n,e)&&a.push(n[e]+t[r]);return a}function e(n){for(var t,e=[],r=[],a=0;t=x.exec(n);)switch(t[0]){case"(":a++;break;case")":a--;break;case",":if(a)break;e.push(t.index)}for(t=e.length;t--;)r.unshift(n.slice(e[t]+1)),n=n.slice(0,e[t]);return r.unshift(n),r}function r(n,e){for(var r,a,i=[],s=[];a=_.exec(n);)"&"==a[0]&&i.push(a.index);for(a=i.length;a--;)s.unshift(n.slice(i[a]+1)),n=n.slice(0,i[a]);for(s.unshift(n),r=[s[0]],a=1;a<s.length;a++)r=t(r,t(e,[s[a]]));return r.join(",")}function a(n){return function t(e){if(d.call(e)===$)for(var r=0;r<e.length;r++)t(e[r]);else n(e)}}function i(n){return"-"+n.toLowerCase()}function s(n,t,e,r,a){var o,l,u;if(null!=r)switch(d.call(r=r.valueOf())){case $:for(o=0;o<r.length;o++)s(n,t,e,r[o],a);break;case v:e=e&&e+"-";for(o in r)if(S.call(r,o))if(l=r[o],/\$/.test(o))for(u in o=o.split("$"))S.call(o,u)&&s(n,t,e+o[u],l,a);else s(n,t,e+o,l,a);break;default:o=e.replace(/_/g,"-").replace(/[A-Z]/g,i),!a||"animation-name"!=o&&"animation"!=o&&"list-style"!=o||(r=r.split(",").map(function(t){return t.replace(/(var\([^)]+\))|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,n.L)}).join(",")),t.d(o,r)}}function o(n,t,e,r,i,o,u){for(var f=0;f<n.$a.length;f++)if(n.$a[f](n,t,e,r,i,o,u))return;if(!e[3]&&/^global$/.test(e[2]))l(n,t,i,r,0,u);else if(!e[3]&&/^local$/.test(e[2]))l(n,t,i,r,1,u);else if(e[3]&&/^adopt$/.test(e[2])){if(!o||u)return t.a("@-error-bad-at-adopt-placement",JSON.stringify(e[0]),0);if(!/^\.?[_A-Za-z][-\w]*$/.test(e[3]))return t.a("@-error-bad-at-adopter",e[3],0);f=[],a(function(n,e){/^\.?[_A-Za-z][-\w]*(?:\s+\.?[_A-Za-z][-\w]*)*$/.test(e=n.toString())?f.push(e.replace(/\./g,"")):t.a("@-error-bad-at-adoptee",JSON.stringify(n),0)})(r),f.length&&(n.l(e[3]=e[3].replace(/\./g,"")),n.n[e[3]]+=" "+f.join(" "))}else!e[3]&&/^(?:namespace|import|charset)$/.test(e[2])?a(function(n){t.a(e[0],n)})(r):!e[3]&&/^(?:font-face|viewport)$/.test(e[2])?a(function(r){t.a(e[1],"",1),s(n,t,"",r,o),t.A(e[1],"")})(r):e[3]&&/^(?:media|supports|page|keyframes)$/.test(e[2])?(o&&"keyframes"==e[2]&&(e[3]=e[3].replace(/(var\([^)]+\))|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,n.L)),t.a(e[1],e[3],1),"page"==e[2]?s(n,t,"",r,o):l(n,t,"keyframes"==e[2]?"":i,r,o,1),t.A(e[1],e[3])):t.a("@-error-unsupported-at-rule",JSON.stringify(e[0]))}function l(n,t,a,i,u,f){var c,g,p,h;switch(d.call(i)){case v:for(c in i)if(S.call(i,c))if(g=i[c],a.length>0&&/^[-\w$]+$/.test(c))if(p||(p=1,t.s(a)),/\$/.test(c))for(h in c=c.split("$"))S.call(c,h)&&s(n,t,c[h],g,u);else s(n,t,c,g,u);else/^@/.test(c)?(p=0,o(n,t,/^(.(?:-[\w]+-)?([_A-Za-z][-\w]*))\b\s*(.*?)\s*$/.exec(c)||[c,"@","",""],g,a,u,f)):(p=0,l(n,t,a.length>0&&(/,/.test(a)||/,/.test(c))?(h=e(a),e(u?c.replace(/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,n.L):c).map(function(n){return/&/.test(n)?r(n,h):h.map(function(t){return t+n}).join(",")}).join(",")):/&/.test(c)?r(u?c.replace(/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,n.L):c,[a]):a+(u?c.replace(/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,n.L):c),g,u,f));break;case $:for(c=0;c<i.length;c++)l(n,t,a,i[c],u,f);break;case b:t.s(a.length>0?a:":-error-no-selector"),s(n,t,"",i,u)}}function u(n,t){var e;return t?n:{i:function(){e=0,n.i()},x:function(t){return e&&(n.S(),e=0),n.x(t)},a:function(t,r,a){e&&(n.S(),e=0),n.a(t,r,a)},A:function(t){e&&(n.S(),e=0),n.A(t)},s:function(t){t!==e&&(e&&n.S(),n.s(t),e=t)},d:n.d}}function f(n){return":global("+n+")"}function c(n,t,e){return e={},e[n]=t,e}function g(n,t,e){if(arguments.length<3){var r=g.bind.apply(g,[null].concat([].slice.call(arguments,0)));return r.toString=function(){return"@"+n+" "+t},r}return c("@"+n+" "+t,e)}function p(){function t(t){if(!S.length)for(var e=0;2>e;e++){$[$.length-e]=function(n,t){return t?{i:p.i,d:p.d,x:p.x}:p};for(var r=$.length;r--;)S[e]=A(n($[r](S[e],!!e,x[e]),S[e]))}var a=S[t];return a}function e(n){return b.names[n]||(b.names[n]=n+b.suffix),b.names[n].match(/^\S+/)}function r(n,t,r,a,i){return t||r?t||r:a+e(i)}var i,p={i:function(){i=[]},x:function(n){return n?i:i.join("")},a:function(n,t,e){i.push(n,t&&" ",t,e?" {\n":";\n")},A:function(){i.push("}\n")},s:function(n){i.push(n," {\n")},S:function(){i.push("}\n")},d:function(n,t){i.push(n,n&&":",t,";\n")}},$=[u],v=[],b={at:g,global:f,kv:c,names:{},suffix:"__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),use:function(){return _(h.slice.call(arguments)),b},$plugins:[]},S=[],x=[{L:r,l:e,n:b.names,$a:v,a:o,d:s,r:l},{L:r,l:e,n:b.names,d:s}];b.sheet=function(n){var e=t(0);return e.i(),l(x[0],e,"",n,1,0),e.x()},b.inline=function(n){var e=t(1);return e.i(),s(x[1],e,"",n,1),e.x()};var _=a(function(t){~b.$plugins.indexOf(t)||(b.$plugins.push(t),d.call(t)===w&&(t=t(b)),t&&(a(function(n){$.push(n)})(t.$filter||h),a(function(n){v.push(n)})(t.$at||h),n(b.names,t.$names||m),_(t.$plugins||h),p=t.$sink||p,n(b,t)))});return b}var h=[],m={},d=m.toString,$=d.call(h),v=d.call(m),b=d.call(""),w=d.call(d),S=m.hasOwnProperty,A=Object.freeze||function(n){return n},x=/[(),]|"(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\//g,_=/&|"(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\//g,z=p();return"sheet|inline|names|at|global|kv|suffix".split("|").map(function(n){p[n]=z[n]}),p});

@@ -11,2 +11,10 @@ 'use strict';

var own = emptyObject.hasOwnProperty;
var freeze = Object.freeze || function(o) {return o};
function Default(target, source) {
for (var k in source) if (own.call(source, k)) {
if (k.indexOf('$') && !(k in target)) target[k] = source[k]
}
return target
}
function cartesian(a,b) {

@@ -38,5 +46,5 @@ var res = [], i, j

/*eslint-disable no-cond-assign*/
while(o = selectorTokenizer.exec(selector)) {
while (o = selectorTokenizer.exec(selector)) {
/*eslint-enable no-cond-assign*/
switch(o[0]){
switch (o[0]) {
case '(': inParen++; break

@@ -62,3 +70,3 @@ case ')': inParen--; break

/*eslint-disable no-cond-assign*/
while(o = ampersandTokenizer.exec(selector)) {
while (o = ampersandTokenizer.exec(selector)) {
/*eslint-enable no-cond-assign*/

@@ -93,3 +101,4 @@ if (o[0] == '&') indices.push(o.index)

*
* @param {object} parser - holds the parser-related methods and state
* @param {object} state - holds the localizer- and walker-related methods
* and state
* @param {object} emit - the contextual emitters to the final buffer

@@ -102,3 +111,3 @@ * @param {string} prefix - the current property or a prefix in case of nested

function declarations(parser, emit, prefix, o, local) {
function declarations(state, emit, prefix, o, local) {
var k, v, kk

@@ -111,3 +120,3 @@ if (o==null) return

declarations(parser, emit, prefix, o[k], local)
declarations(state, emit, prefix, o[k], local)

@@ -124,3 +133,3 @@ break

declarations(parser, emit, prefix + k[kk], v, local)
declarations(state, emit, prefix + k[kk], v, local)

@@ -130,3 +139,3 @@ }

declarations(parser, emit, prefix + k, v, local)
declarations(state, emit, prefix + k, v, local)

@@ -149,6 +158,6 @@ }

// no need to tokenize here a plain `.split(',')` has all bases covered.
// We may 'parser' a comment, but it's not a big deal.
// We may 'localize' a comment, but it's not a big deal.
o = o.split(',').map(function (o) {
return o.replace(/($^)|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/, parser.L)
return o.replace(/(var\([^)]+\))|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/, state.L)

@@ -166,3 +175,4 @@ }).join(',')

*
* @param {object} parser - holds the parser-related methods and state
* @param {object} state - holds the localizer- and walker-related methods
* and state
* @param {object} emit - the contextual emitters to the final buffer

@@ -181,13 +191,17 @@ * @param {array} k - The parsed at-rule, including the parameters,

function atRules(parser, emit, k, v, prefix, local, inAtRule) {
function atRules(state, emit, k, v, prefix, local, inAtRule) {
for (var i = 0; i < parser.$a.length; i++) {
for (var i = 0; i < state.$a.length; i++) {
if (parser.$a[i](parser, emit, k, v, prefix, local, inAtRule)) return
if (state.$a[i](state, emit, k, v, prefix, local, inAtRule)) return
}
// using `/^global$/.test(k[2])` rather that 'global' == k[2] gzips
// slightly better because of the regexps test further down.
// It is slightly less efficient but this isn't a critical path.
if (!k[3] && /^global$/.test(k[2])) {
sheet(parser, emit, prefix, v, 0, inAtRule)
rules(state, emit, prefix, v, 0, inAtRule)

@@ -197,3 +211,3 @@

sheet(parser, emit, prefix, v, 1, inAtRule)
rules(state, emit, prefix, v, 1, inAtRule)

@@ -208,8 +222,7 @@

i = []
flatIter(function(c, s){
s = c.toString()
flatIter(function(adoptee, asString) {
if(!/^\.?[_A-Za-z][-\w]*(?:\s+\.?[_A-Za-z][-\w]*)*$/.test(s)) emit.a('@-error-bad-at-adoptee', JSON.stringify(c), 0)
if(!/^\.?[_A-Za-z][-\w]*(?:\s+\.?[_A-Za-z][-\w]*)*$/.test(asString = adoptee.toString())) emit.a('@-error-bad-at-adoptee', JSON.stringify(adoptee), 0)
else i.push(s.replace(/\./g, ''))
else i.push(asString.replace(/\./g, ''))

@@ -220,5 +233,4 @@ })(v)

if (i.length) {
// console.log("========== I ===========\n", i)
parser.l(k[3] = k[3].replace(/\./g, ''))
parser.n[k[3]] += (' ' + i.join(' '))
state.l(k[3] = k[3].replace(/\./g, ''))
state.n[k[3]] += (' ' + i.join(' '))
}

@@ -240,3 +252,3 @@

declarations(parser, emit, '', v, local)
declarations(state, emit, '', v, local)

@@ -252,4 +264,4 @@ emit.A(k[1], '')

// generated by script/regexps.js
/($^)|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,
parser.L
/(var\([^)]+\))|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,
state.L
)

@@ -263,8 +275,8 @@ }

declarations(parser, emit, '', v, local)
declarations(state, emit, '', v, local)
} else {
sheet(
parser, emit,
rules(
state, emit,
'keyframes' == k[2] ? '' : prefix,

@@ -288,3 +300,4 @@ v, local, 1

*
* @param {object} parser - holds the parser-related methods and state
* @param {object} state - holds the localizer- and walker-related methods
* and state
* @param {object} emit - the contextual emitters to the final buffer

@@ -296,3 +309,3 @@ * @param {string} prefix - the current selector or a prefix in case of nested rules

*/
function sheet(parser, emit, prefix, tree, local, inAtRule) {
function rules(state, emit, prefix, tree, local, inAtRule) {
var k, v, inDeclaration, kk

@@ -306,3 +319,3 @@

if (prefix && /^[-\w$]+$/.test(k)) {
if (prefix.length > 0 && /^[-\w$]+$/.test(k)) {
if (!inDeclaration) {

@@ -317,3 +330,3 @@ inDeclaration = 1

declarations(parser, emit, k[kk], v, local)
declarations(state, emit, k[kk], v, local)

@@ -323,3 +336,3 @@ }

declarations(parser, emit, k, v, local)
declarations(state, emit, k, v, local)

@@ -332,3 +345,3 @@ }

atRules(parser, emit,
atRules(state, emit,
/^(.(?:-[\w]+-)?([_A-Za-z][-\w]*))\b\s*(.*?)\s*$/.exec(k) || [k,'@','',''],

@@ -342,7 +355,7 @@ v, prefix, local, inAtRule

sheet(
parser, emit,
rules(
state, emit,
// `prefix` ... Hefty. Ugly. Sadly necessary.
//
(prefix && (/,/.test(prefix) || /,/.test(k))) ?
(prefix.length > 0 && (/,/.test(prefix) || /,/.test(k))) ?

@@ -353,3 +366,4 @@ /*0*/ (kk = splitSelector(prefix), splitSelector(

k.replace(
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g, parser.L
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,
state.L
) :

@@ -370,3 +384,4 @@

k.replace(
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g, parser.L
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,
state.L
) :

@@ -382,3 +397,4 @@

k.replace(
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g, parser.L
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,
state.L
) :

@@ -399,3 +415,3 @@

sheet(parser, emit, prefix, tree[k], local, inAtRule)
rules(state, emit, prefix, tree[k], local, inAtRule)

@@ -408,5 +424,5 @@ }

emit.s(prefix || ':-error-no-selector')
emit.s(prefix.length > 0 ? prefix : ':-error-no-selector')
declarations(parser, emit, '', tree, local)
declarations(state, emit, '', tree, local)

@@ -476,5 +492,30 @@ }

function j2c() {
// palceholder for the buffer used by the `$sink` handlers
var buf
// the bottom of the 'codegen' stream. Mirrors the `$filter` plugin API.
var $sink = {
// Init
i: function(){buf=[]},
// done (eXit)
x: function (raw) {return raw ? buf : buf.join('')},
// start At-rule
a: function (rule, argument, takesBlock) {
buf.push(rule, argument && ' ',argument, takesBlock ? ' {\n' : ';\n')
},
// end At-rule
A: function () {buf.push('}\n')},
// start Selector
s: function (selector) {buf.push(selector, ' {\n')},
// end Selector
S: function () {buf.push('}\n')},
// declarations
d: function (prop, value) {buf.push(prop, prop && ':', value, ';\n')}
}
var $filters = [closeSelectors]
var $atHandlers = []
var instance = {
var _instance = {
at: at,

@@ -491,3 +532,3 @@ global: global,

_use(emptyArray.slice.call(arguments))
return instance
return _instance
},

@@ -497,40 +538,61 @@ $plugins: []

function _default(target, source) {
for (var k in source) if (own.call(source, k) && k.indexOf('$')) {
if (OBJECT == type.call(source[k]) && OBJECT == type.call(target[k])) _default(target[k], source[k])
else if (!(k in target)) target[k] = source[k]
}
}
var _streams = []
var buf
var $sink = {
i: function(){buf=[]},
x: function (raw) {return raw ? buf : buf.join('')},
a: function (rule, argument, takesBlock) {
buf.push(rule, argument && ' ',argument, takesBlock ? ' {\n' : ';\n')
},
A: function () {buf.push('}\n')},
s: function (selector) {buf.push(selector, ' {\n')},
S: function () {buf.push('}\n')},
d: function (prop, value) {buf.push(prop, prop && ':', value, ';\n')}
}
var streams = []
// The `state` (for the core) / `walker` (for the plugins) tables.
var parsers = [
var _walkers = [
// for j2c.sheet
{
$a: $atHandlers,
// helpers for locaizing class and animation names
L: _localizeReplacer, // second argument to String.prototype.replace
l: _localize, // mangles local names
n: _instance.names, // local => mangled mapping
$a: $atHandlers, // extra at-rules
// The core walker methods, to be provided to plugins
a: atRules,
d: declarations,
L: localizeReplacer,
l: localize,
n: instance.names,
s: sheet
}, {
d: declarations,
L: localizeReplacer,
l: localize,
n: instance.names
r: rules
},
// likewise, for j2c.inline (idem with `$a`, `a` and `s` removed)
{
L: _localizeReplacer,
l: _localize,
n: _instance.names,
d: declarations
}
]
// The main API functions
_instance.sheet = function(tree) {
var emit = _getStream(0)
emit.i()
rules(
_walkers[0],
emit,
'', // prefix
tree,
1, // local, by default
0 // inAtRule
)
return emit.x()
}
_instance.inline = function (tree) {
var emit = _getStream(1)
emit.i()
declarations(
_walkers[1],
emit,
'', // prefix
tree,
1 //local
)
return emit.x()
}
// inner helpers
var _use = flatIter(function(plugin) {

@@ -541,7 +603,7 @@ // `~n` is falsy for `n === -1` and truthy otherwise.

// `a`.
if (~instance.$plugins.indexOf(plugin)) return
if (~_instance.$plugins.indexOf(plugin)) return
instance.$plugins.push(plugin)
_instance.$plugins.push(plugin)
if (type.call(plugin) === FUNCTION) plugin = plugin(instance)
if (type.call(plugin) === FUNCTION) plugin = plugin(_instance)

@@ -558,58 +620,38 @@ if (!plugin) return

Default(_instance.names, plugin.$names || emptyObject)
_use(plugin.$plugins || emptyArray)
$sink = plugin.$sink || $sink
_default(instance, plugin)
Default(_instance, plugin)
})
function getStream(inline) {
if (!streams.length) {
function _getStream(inline) {
if (!_streams.length) {
for(var i = 0; i < 2; i++){
$filters[$filters.length - i] = function(_, inline) {return inline ? {i:$sink.i, d:$sink.d, x:$sink.x} : $sink}
for (var j = $filters.length; j--;) streams[i] = $filters[j](streams[i], !!i, parsers[i])
for (var j = $filters.length; j--;) {
_streams[i] = freeze(Default(
$filters[j](_streams[i], !!i, _walkers[i]),
_streams[i]
))
}
}
}
var res = streams[inline]
var res = _streams[inline]
return res
}
function localize(name) {
if (!instance.names[name]) instance.names[name] = name + instance.suffix
return instance.names[name].match(/^\S+/)
function _localize(name) {
if (!_instance.names[name]) _instance.names[name] = name + _instance.suffix
return _instance.names[name].match(/^\S+/)
}
function localizeReplacer(match, string, global, dot, name) {
function _localizeReplacer(match, string, global, dot, name) {
if (string || global) return string || global
return dot + localize(name)
return dot + _localize(name)
}
/*/-statements-/*/
instance.sheet = function(tree) {
var emit = getStream(0)
emit.i()
sheet(
parsers[0],
emit,
'', // prefix
tree,
1, // local, by default
0 // inAtRule
)
return emit.x()
}
/*/-statements-/*/
instance.inline = function (tree) {
var emit = getStream(1)
emit.i()
declarations(
parsers[1],
emit,
'', // prefix
tree,
1 //local
)
return emit.x()
}
return instance
return _instance
}

@@ -616,0 +658,0 @@

@@ -1,1 +0,1 @@

"use strict";function cartesian(e,t){var n,a,r=[];for(a in t)if(own.call(t,a))for(n in e)own.call(e,n)&&r.push(e[n]+t[a]);return r}function splitSelector(e){for(var t,n=[],a=[],r=0;t=selectorTokenizer.exec(e);)switch(t[0]){case"(":r++;break;case")":r--;break;case",":if(r)break;n.push(t.index)}for(t=n.length;t--;)a.unshift(e.slice(n[t]+1)),e=e.slice(0,n[t]);return a.unshift(e),a}function ampersand(e,t){for(var n,a,r=[],i=[];a=ampersandTokenizer.exec(e);)"&"==a[0]&&r.push(a.index);for(a=r.length;a--;)i.unshift(e.slice(r[a]+1)),e=e.slice(0,r[a]);for(i.unshift(e),n=[i[0]],a=1;a<i.length;a++)n=cartesian(n,cartesian(t,[i[a]]));return n.join(",")}function flatIter(e){return function t(n){if(type.call(n)===ARRAY)for(var a=0;a<n.length;a++)t(n[a]);else e(n)}}function decamelize(e){return"-"+e.toLowerCase()}function declarations(e,t,n,a,r){var i,s,l;if(null!=a)switch(type.call(a=a.valueOf())){case ARRAY:for(i=0;i<a.length;i++)declarations(e,t,n,a[i],r);break;case OBJECT:n=n&&n+"-";for(i in a)if(own.call(a,i))if(s=a[i],/\$/.test(i))for(l in i=i.split("$"))own.call(i,l)&&declarations(e,t,n+i[l],s,r);else declarations(e,t,n+i,s,r);break;default:i=n.replace(/_/g,"-").replace(/[A-Z]/g,decamelize),!r||"animation-name"!=i&&"animation"!=i&&"list-style"!=i||(a=a.split(",").map(function(t){return t.replace(/($^)|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,e.L)}).join(",")),t.d(i,a)}}function atRules(e,t,n,a,r,i,s){for(var l=0;l<e.$a.length;l++)if(e.$a[l](e,t,n,a,r,i,s))return;if(!n[3]&&/^global$/.test(n[2]))sheet(e,t,r,a,0,s);else if(!n[3]&&/^local$/.test(n[2]))sheet(e,t,r,a,1,s);else if(n[3]&&/^adopt$/.test(n[2])){if(!i||s)return t.a("@-error-bad-at-adopt-placement",JSON.stringify(n[0]),0);if(!/^\.?[_A-Za-z][-\w]*$/.test(n[3]))return t.a("@-error-bad-at-adopter",n[3],0);l=[],flatIter(function(e,n){n=e.toString(),/^\.?[_A-Za-z][-\w]*(?:\s+\.?[_A-Za-z][-\w]*)*$/.test(n)?l.push(n.replace(/\./g,"")):t.a("@-error-bad-at-adoptee",JSON.stringify(e),0)})(a),l.length&&(e.l(n[3]=n[3].replace(/\./g,"")),e.n[n[3]]+=" "+l.join(" "))}else!n[3]&&/^(?:namespace|import|charset)$/.test(n[2])?flatIter(function(e){t.a(n[0],e)})(a):!n[3]&&/^(?:font-face|viewport)$/.test(n[2])?flatIter(function(a){t.a(n[1],"",1),declarations(e,t,"",a,i),t.A(n[1],"")})(a):n[3]&&/^(?:media|supports|page|keyframes)$/.test(n[2])?(i&&"keyframes"==n[2]&&(n[3]=n[3].replace(/($^)|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,e.L)),t.a(n[1],n[3],1),"page"==n[2]?declarations(e,t,"",a,i):sheet(e,t,"keyframes"==n[2]?"":r,a,i,1),t.A(n[1],n[3])):t.a("@-error-unsupported-at-rule",JSON.stringify(n[0]))}function sheet(e,t,n,a,r,i){var s,l,o,c;switch(type.call(a)){case OBJECT:for(s in a)if(own.call(a,s))if(l=a[s],n&&/^[-\w$]+$/.test(s))if(o||(o=1,t.s(n)),/\$/.test(s))for(c in s=s.split("$"))own.call(s,c)&&declarations(e,t,s[c],l,r);else declarations(e,t,s,l,r);else/^@/.test(s)?(o=0,atRules(e,t,/^(.(?:-[\w]+-)?([_A-Za-z][-\w]*))\b\s*(.*?)\s*$/.exec(s)||[s,"@","",""],l,n,r,i)):(o=0,sheet(e,t,n&&(/,/.test(n)||/,/.test(s))?(c=splitSelector(n),splitSelector(r?s.replace(/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,e.L):s).map(function(e){return/&/.test(e)?ampersand(e,c):c.map(function(t){return t+e}).join(",")}).join(",")):/&/.test(s)?ampersand(r?s.replace(/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,e.L):s,[n]):n+(r?s.replace(/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,e.L):s),l,r,i));break;case ARRAY:for(s=0;s<a.length;s++)sheet(e,t,n,a[s],r,i);break;case STRING:t.s(n||":-error-no-selector"),declarations(e,t,"",a,r)}}function closeSelectors(e,t){var n;return t?e:{i:function(){n=0,e.i()},x:function(t){return n&&(e.S(),n=0),e.x(t)},a:function(t,a,r){n&&(e.S(),n=0),e.a(t,a,r)},A:function(t){n&&(e.S(),n=0),e.A(t)},s:function(t){t!==n&&(n&&e.S(),e.s(t),n=t)},d:e.d}}function global(e){return":global("+e+")"}function kv(e,t,n){return n={},n[e]=t,n}function at(e,t,n){if(arguments.length<3){var a=at.bind.apply(at,[null].concat([].slice.call(arguments,0)));return a.toString=function(){return"@"+e+" "+t},a}return kv("@"+e+" "+t,n)}function j2c(){function e(t,n){for(var a in n)own.call(n,a)&&a.indexOf("$")&&(OBJECT==type.call(n[a])&&OBJECT==type.call(t[a])?e(t[a],n[a]):a in t||(t[a]=n[a]))}function t(e){if(!c.length)for(var t=0;2>t;t++){i[i.length-t]=function(e,t){return t?{i:o.i,d:o.d,x:o.x}:o};for(var n=i.length;n--;)c[t]=i[n](c[t],!!t,f[t])}var a=c[e];return a}function n(e){return l.names[e]||(l.names[e]=e+l.suffix),l.names[e].match(/^\S+/)}function a(e,t,a,r,i){return t||a?t||a:r+n(i)}var r,i=[closeSelectors],s=[],l={at:at,global:global,kv:kv,names:{},suffix:"__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),use:function(){return u(emptyArray.slice.call(arguments)),l},$plugins:[]},o={i:function(){r=[]},x:function(e){return e?r:r.join("")},a:function(e,t,n){r.push(e,t&&" ",t,n?" {\n":";\n")},A:function(){r.push("}\n")},s:function(e){r.push(e," {\n")},S:function(){r.push("}\n")},d:function(e,t){r.push(e,e&&":",t,";\n")}},c=[],f=[{$a:s,a:atRules,d:declarations,L:a,l:n,n:l.names,s:sheet},{d:declarations,L:a,l:n,n:l.names}],u=flatIter(function(t){~l.$plugins.indexOf(t)||(l.$plugins.push(t),type.call(t)===FUNCTION&&(t=t(l)),t&&(flatIter(function(e){i.push(e)})(t.$filter||emptyArray),flatIter(function(e){s.push(e)})(t.$at||emptyArray),o=t.$sink||o,e(l,t)))});return l.sheet=function(e){var n=t(0);return n.i(),sheet(f[0],n,"",e,1,0),n.x()},l.inline=function(e){var n=t(1);return n.i(),declarations(f[1],n,"",e,1),n.x()},l}var emptyArray=[],emptyObject={},type=emptyObject.toString,ARRAY=type.call(emptyArray),OBJECT=type.call(emptyObject),STRING=type.call(""),FUNCTION=type.call(type),own=emptyObject.hasOwnProperty,selectorTokenizer=/[(),]|"(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\//g,ampersandTokenizer=/&|"(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\//g,_j2c=j2c();"sheet|inline|names|at|global|kv|suffix".split("|").map(function(e){j2c[e]=_j2c[e]}),module.exports=j2c;
"use strict";function Default(e,t){for(var n in t)own.call(t,n)&&(!n.indexOf("$")||n in e||(e[n]=t[n]));return e}function cartesian(e,t){var n,a,r=[];for(a in t)if(own.call(t,a))for(n in e)own.call(e,n)&&r.push(e[n]+t[a]);return r}function splitSelector(e){for(var t,n=[],a=[],r=0;t=selectorTokenizer.exec(e);)switch(t[0]){case"(":r++;break;case")":r--;break;case",":if(r)break;n.push(t.index)}for(t=n.length;t--;)a.unshift(e.slice(n[t]+1)),e=e.slice(0,n[t]);return a.unshift(e),a}function ampersand(e,t){for(var n,a,r=[],l=[];a=ampersandTokenizer.exec(e);)"&"==a[0]&&r.push(a.index);for(a=r.length;a--;)l.unshift(e.slice(r[a]+1)),e=e.slice(0,r[a]);for(l.unshift(e),n=[l[0]],a=1;a<l.length;a++)n=cartesian(n,cartesian(t,[l[a]]));return n.join(",")}function flatIter(e){return function t(n){if(type.call(n)===ARRAY)for(var a=0;a<n.length;a++)t(n[a]);else e(n)}}function decamelize(e){return"-"+e.toLowerCase()}function declarations(e,t,n,a,r){var l,i,s;if(null!=a)switch(type.call(a=a.valueOf())){case ARRAY:for(l=0;l<a.length;l++)declarations(e,t,n,a[l],r);break;case OBJECT:n=n&&n+"-";for(l in a)if(own.call(a,l))if(i=a[l],/\$/.test(l))for(s in l=l.split("$"))own.call(l,s)&&declarations(e,t,n+l[s],i,r);else declarations(e,t,n+l,i,r);break;default:l=n.replace(/_/g,"-").replace(/[A-Z]/g,decamelize),!r||"animation-name"!=l&&"animation"!=l&&"list-style"!=l||(a=a.split(",").map(function(t){return t.replace(/(var\([^)]+\))|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,e.L)}).join(",")),t.d(l,a)}}function atRules(e,t,n,a,r,l,i){for(var s=0;s<e.$a.length;s++)if(e.$a[s](e,t,n,a,r,l,i))return;if(!n[3]&&/^global$/.test(n[2]))rules(e,t,r,a,0,i);else if(!n[3]&&/^local$/.test(n[2]))rules(e,t,r,a,1,i);else if(n[3]&&/^adopt$/.test(n[2])){if(!l||i)return t.a("@-error-bad-at-adopt-placement",JSON.stringify(n[0]),0);if(!/^\.?[_A-Za-z][-\w]*$/.test(n[3]))return t.a("@-error-bad-at-adopter",n[3],0);s=[],flatIter(function(e,n){/^\.?[_A-Za-z][-\w]*(?:\s+\.?[_A-Za-z][-\w]*)*$/.test(n=e.toString())?s.push(n.replace(/\./g,"")):t.a("@-error-bad-at-adoptee",JSON.stringify(e),0)})(a),s.length&&(e.l(n[3]=n[3].replace(/\./g,"")),e.n[n[3]]+=" "+s.join(" "))}else!n[3]&&/^(?:namespace|import|charset)$/.test(n[2])?flatIter(function(e){t.a(n[0],e)})(a):!n[3]&&/^(?:font-face|viewport)$/.test(n[2])?flatIter(function(a){t.a(n[1],"",1),declarations(e,t,"",a,l),t.A(n[1],"")})(a):n[3]&&/^(?:media|supports|page|keyframes)$/.test(n[2])?(l&&"keyframes"==n[2]&&(n[3]=n[3].replace(/(var\([^)]+\))|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,e.L)),t.a(n[1],n[3],1),"page"==n[2]?declarations(e,t,"",a,l):rules(e,t,"keyframes"==n[2]?"":r,a,l,1),t.A(n[1],n[3])):t.a("@-error-unsupported-at-rule",JSON.stringify(n[0]))}function rules(e,t,n,a,r,l){var i,s,o,c;switch(type.call(a)){case OBJECT:for(i in a)if(own.call(a,i))if(s=a[i],n.length>0&&/^[-\w$]+$/.test(i))if(o||(o=1,t.s(n)),/\$/.test(i))for(c in i=i.split("$"))own.call(i,c)&&declarations(e,t,i[c],s,r);else declarations(e,t,i,s,r);else/^@/.test(i)?(o=0,atRules(e,t,/^(.(?:-[\w]+-)?([_A-Za-z][-\w]*))\b\s*(.*?)\s*$/.exec(i)||[i,"@","",""],s,n,r,l)):(o=0,rules(e,t,n.length>0&&(/,/.test(n)||/,/.test(i))?(c=splitSelector(n),splitSelector(r?i.replace(/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,e.L):i).map(function(e){return/&/.test(e)?ampersand(e,c):c.map(function(t){return t+e}).join(",")}).join(",")):/&/.test(i)?ampersand(r?i.replace(/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,e.L):i,[n]):n+(r?i.replace(/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,e.L):i),s,r,l));break;case ARRAY:for(i=0;i<a.length;i++)rules(e,t,n,a[i],r,l);break;case STRING:t.s(n.length>0?n:":-error-no-selector"),declarations(e,t,"",a,r)}}function closeSelectors(e,t){var n;return t?e:{i:function(){n=0,e.i()},x:function(t){return n&&(e.S(),n=0),e.x(t)},a:function(t,a,r){n&&(e.S(),n=0),e.a(t,a,r)},A:function(t){n&&(e.S(),n=0),e.A(t)},s:function(t){t!==n&&(n&&e.S(),e.s(t),n=t)},d:e.d}}function global(e){return":global("+e+")"}function kv(e,t,n){return n={},n[e]=t,n}function at(e,t,n){if(arguments.length<3){var a=at.bind.apply(at,[null].concat([].slice.call(arguments,0)));return a.toString=function(){return"@"+e+" "+t},a}return kv("@"+e+" "+t,n)}function j2c(){function e(e){if(!o.length)for(var t=0;2>t;t++){l[l.length-t]=function(e,t){return t?{i:r.i,d:r.d,x:r.x}:r};for(var n=l.length;n--;)o[t]=freeze(Default(l[n](o[t],!!t,c[t]),o[t]))}var a=o[e];return a}function t(e){return s.names[e]||(s.names[e]=e+s.suffix),s.names[e].match(/^\S+/)}function n(e,n,a,r,l){return n||a?n||a:r+t(l)}var a,r={i:function(){a=[]},x:function(e){return e?a:a.join("")},a:function(e,t,n){a.push(e,t&&" ",t,n?" {\n":";\n")},A:function(){a.push("}\n")},s:function(e){a.push(e," {\n")},S:function(){a.push("}\n")},d:function(e,t){a.push(e,e&&":",t,";\n")}},l=[closeSelectors],i=[],s={at:at,global:global,kv:kv,names:{},suffix:"__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),use:function(){return u(emptyArray.slice.call(arguments)),s},$plugins:[]},o=[],c=[{L:n,l:t,n:s.names,$a:i,a:atRules,d:declarations,r:rules},{L:n,l:t,n:s.names,d:declarations}];s.sheet=function(t){var n=e(0);return n.i(),rules(c[0],n,"",t,1,0),n.x()},s.inline=function(t){var n=e(1);return n.i(),declarations(c[1],n,"",t,1),n.x()};var u=flatIter(function(e){~s.$plugins.indexOf(e)||(s.$plugins.push(e),type.call(e)===FUNCTION&&(e=e(s)),e&&(flatIter(function(e){l.push(e)})(e.$filter||emptyArray),flatIter(function(e){i.push(e)})(e.$at||emptyArray),Default(s.names,e.$names||emptyObject),u(e.$plugins||emptyArray),r=e.$sink||r,Default(s,e)))});return s}var emptyArray=[],emptyObject={},type=emptyObject.toString,ARRAY=type.call(emptyArray),OBJECT=type.call(emptyObject),STRING=type.call(""),FUNCTION=type.call(type),own=emptyObject.hasOwnProperty,freeze=Object.freeze||function(e){return e},selectorTokenizer=/[(),]|"(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\//g,ampersandTokenizer=/&|"(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\//g,_j2c=j2c();"sheet|inline|names|at|global|kv|suffix".split("|").map(function(e){j2c[e]=_j2c[e]}),module.exports=j2c;

@@ -9,2 +9,10 @@ var emptyArray = [];

var own = emptyObject.hasOwnProperty;
var freeze = Object.freeze || function(o) {return o};
function Default(target, source) {
for (var k in source) if (own.call(source, k)) {
if (k.indexOf('$') && !(k in target)) target[k] = source[k]
}
return target
}
function cartesian(a,b) {

@@ -36,5 +44,5 @@ var res = [], i, j

/*eslint-disable no-cond-assign*/
while(o = selectorTokenizer.exec(selector)) {
while (o = selectorTokenizer.exec(selector)) {
/*eslint-enable no-cond-assign*/
switch(o[0]){
switch (o[0]) {
case '(': inParen++; break

@@ -60,3 +68,3 @@ case ')': inParen--; break

/*eslint-disable no-cond-assign*/
while(o = ampersandTokenizer.exec(selector)) {
while (o = ampersandTokenizer.exec(selector)) {
/*eslint-enable no-cond-assign*/

@@ -91,3 +99,4 @@ if (o[0] == '&') indices.push(o.index)

*
* @param {object} parser - holds the parser-related methods and state
* @param {object} state - holds the localizer- and walker-related methods
* and state
* @param {object} emit - the contextual emitters to the final buffer

@@ -100,3 +109,3 @@ * @param {string} prefix - the current property or a prefix in case of nested

function declarations(parser, emit, prefix, o, local) {
function declarations(state, emit, prefix, o, local) {
var k, v, kk

@@ -109,3 +118,3 @@ if (o==null) return

declarations(parser, emit, prefix, o[k], local)
declarations(state, emit, prefix, o[k], local)

@@ -122,3 +131,3 @@ break

declarations(parser, emit, prefix + k[kk], v, local)
declarations(state, emit, prefix + k[kk], v, local)

@@ -128,3 +137,3 @@ }

declarations(parser, emit, prefix + k, v, local)
declarations(state, emit, prefix + k, v, local)

@@ -147,6 +156,6 @@ }

// no need to tokenize here a plain `.split(',')` has all bases covered.
// We may 'parser' a comment, but it's not a big deal.
// We may 'localize' a comment, but it's not a big deal.
o = o.split(',').map(function (o) {
return o.replace(/($^)|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/, parser.L)
return o.replace(/(var\([^)]+\))|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/, state.L)

@@ -164,3 +173,4 @@ }).join(',')

*
* @param {object} parser - holds the parser-related methods and state
* @param {object} state - holds the localizer- and walker-related methods
* and state
* @param {object} emit - the contextual emitters to the final buffer

@@ -179,13 +189,17 @@ * @param {array} k - The parsed at-rule, including the parameters,

function atRules(parser, emit, k, v, prefix, local, inAtRule) {
function atRules(state, emit, k, v, prefix, local, inAtRule) {
for (var i = 0; i < parser.$a.length; i++) {
for (var i = 0; i < state.$a.length; i++) {
if (parser.$a[i](parser, emit, k, v, prefix, local, inAtRule)) return
if (state.$a[i](state, emit, k, v, prefix, local, inAtRule)) return
}
// using `/^global$/.test(k[2])` rather that 'global' == k[2] gzips
// slightly better because of the regexps test further down.
// It is slightly less efficient but this isn't a critical path.
if (!k[3] && /^global$/.test(k[2])) {
sheet(parser, emit, prefix, v, 0, inAtRule)
rules(state, emit, prefix, v, 0, inAtRule)

@@ -195,3 +209,3 @@

sheet(parser, emit, prefix, v, 1, inAtRule)
rules(state, emit, prefix, v, 1, inAtRule)

@@ -206,8 +220,7 @@

i = []
flatIter(function(c, s){
s = c.toString()
flatIter(function(adoptee, asString) {
if(!/^\.?[_A-Za-z][-\w]*(?:\s+\.?[_A-Za-z][-\w]*)*$/.test(s)) emit.a('@-error-bad-at-adoptee', JSON.stringify(c), 0)
if(!/^\.?[_A-Za-z][-\w]*(?:\s+\.?[_A-Za-z][-\w]*)*$/.test(asString = adoptee.toString())) emit.a('@-error-bad-at-adoptee', JSON.stringify(adoptee), 0)
else i.push(s.replace(/\./g, ''))
else i.push(asString.replace(/\./g, ''))

@@ -218,5 +231,4 @@ })(v)

if (i.length) {
// console.log("========== I ===========\n", i)
parser.l(k[3] = k[3].replace(/\./g, ''))
parser.n[k[3]] += (' ' + i.join(' '))
state.l(k[3] = k[3].replace(/\./g, ''))
state.n[k[3]] += (' ' + i.join(' '))
}

@@ -238,3 +250,3 @@

declarations(parser, emit, '', v, local)
declarations(state, emit, '', v, local)

@@ -250,4 +262,4 @@ emit.A(k[1], '')

// generated by script/regexps.js
/($^)|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,
parser.L
/(var\([^)]+\))|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,
state.L
)

@@ -261,8 +273,8 @@ }

declarations(parser, emit, '', v, local)
declarations(state, emit, '', v, local)
} else {
sheet(
parser, emit,
rules(
state, emit,
'keyframes' == k[2] ? '' : prefix,

@@ -286,3 +298,4 @@ v, local, 1

*
* @param {object} parser - holds the parser-related methods and state
* @param {object} state - holds the localizer- and walker-related methods
* and state
* @param {object} emit - the contextual emitters to the final buffer

@@ -294,3 +307,3 @@ * @param {string} prefix - the current selector or a prefix in case of nested rules

*/
function sheet(parser, emit, prefix, tree, local, inAtRule) {
function rules(state, emit, prefix, tree, local, inAtRule) {
var k, v, inDeclaration, kk

@@ -304,3 +317,3 @@

if (prefix && /^[-\w$]+$/.test(k)) {
if (prefix.length > 0 && /^[-\w$]+$/.test(k)) {
if (!inDeclaration) {

@@ -315,3 +328,3 @@ inDeclaration = 1

declarations(parser, emit, k[kk], v, local)
declarations(state, emit, k[kk], v, local)

@@ -321,3 +334,3 @@ }

declarations(parser, emit, k, v, local)
declarations(state, emit, k, v, local)

@@ -330,3 +343,3 @@ }

atRules(parser, emit,
atRules(state, emit,
/^(.(?:-[\w]+-)?([_A-Za-z][-\w]*))\b\s*(.*?)\s*$/.exec(k) || [k,'@','',''],

@@ -340,7 +353,7 @@ v, prefix, local, inAtRule

sheet(
parser, emit,
rules(
state, emit,
// `prefix` ... Hefty. Ugly. Sadly necessary.
//
(prefix && (/,/.test(prefix) || /,/.test(k))) ?
(prefix.length > 0 && (/,/.test(prefix) || /,/.test(k))) ?

@@ -351,3 +364,4 @@ /*0*/ (kk = splitSelector(prefix), splitSelector(

k.replace(
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g, parser.L
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,
state.L
) :

@@ -368,3 +382,4 @@

k.replace(
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g, parser.L
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,
state.L
) :

@@ -380,3 +395,4 @@

k.replace(
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g, parser.L
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,
state.L
) :

@@ -397,3 +413,3 @@

sheet(parser, emit, prefix, tree[k], local, inAtRule)
rules(state, emit, prefix, tree[k], local, inAtRule)

@@ -406,5 +422,5 @@ }

emit.s(prefix || ':-error-no-selector')
emit.s(prefix.length > 0 ? prefix : ':-error-no-selector')
declarations(parser, emit, '', tree, local)
declarations(state, emit, '', tree, local)

@@ -474,5 +490,30 @@ }

function j2c() {
// palceholder for the buffer used by the `$sink` handlers
var buf
// the bottom of the 'codegen' stream. Mirrors the `$filter` plugin API.
var $sink = {
// Init
i: function(){buf=[]},
// done (eXit)
x: function (raw) {return raw ? buf : buf.join('')},
// start At-rule
a: function (rule, argument, takesBlock) {
buf.push(rule, argument && ' ',argument, takesBlock ? ' {\n' : ';\n')
},
// end At-rule
A: function () {buf.push('}\n')},
// start Selector
s: function (selector) {buf.push(selector, ' {\n')},
// end Selector
S: function () {buf.push('}\n')},
// declarations
d: function (prop, value) {buf.push(prop, prop && ':', value, ';\n')}
}
var $filters = [closeSelectors]
var $atHandlers = []
var instance = {
var _instance = {
at: at,

@@ -489,3 +530,3 @@ global: global,

_use(emptyArray.slice.call(arguments))
return instance
return _instance
},

@@ -495,40 +536,61 @@ $plugins: []

function _default(target, source) {
for (var k in source) if (own.call(source, k) && k.indexOf('$')) {
if (OBJECT == type.call(source[k]) && OBJECT == type.call(target[k])) _default(target[k], source[k])
else if (!(k in target)) target[k] = source[k]
}
}
var _streams = []
var buf
var $sink = {
i: function(){buf=[]},
x: function (raw) {return raw ? buf : buf.join('')},
a: function (rule, argument, takesBlock) {
buf.push(rule, argument && ' ',argument, takesBlock ? ' {\n' : ';\n')
},
A: function () {buf.push('}\n')},
s: function (selector) {buf.push(selector, ' {\n')},
S: function () {buf.push('}\n')},
d: function (prop, value) {buf.push(prop, prop && ':', value, ';\n')}
}
var streams = []
// The `state` (for the core) / `walker` (for the plugins) tables.
var parsers = [
var _walkers = [
// for j2c.sheet
{
$a: $atHandlers,
// helpers for locaizing class and animation names
L: _localizeReplacer, // second argument to String.prototype.replace
l: _localize, // mangles local names
n: _instance.names, // local => mangled mapping
$a: $atHandlers, // extra at-rules
// The core walker methods, to be provided to plugins
a: atRules,
d: declarations,
L: localizeReplacer,
l: localize,
n: instance.names,
s: sheet
}, {
d: declarations,
L: localizeReplacer,
l: localize,
n: instance.names
r: rules
},
// likewise, for j2c.inline (idem with `$a`, `a` and `s` removed)
{
L: _localizeReplacer,
l: _localize,
n: _instance.names,
d: declarations
}
]
// The main API functions
_instance.sheet = function(tree) {
var emit = _getStream(0)
emit.i()
rules(
_walkers[0],
emit,
'', // prefix
tree,
1, // local, by default
0 // inAtRule
)
return emit.x()
}
_instance.inline = function (tree) {
var emit = _getStream(1)
emit.i()
declarations(
_walkers[1],
emit,
'', // prefix
tree,
1 //local
)
return emit.x()
}
// inner helpers
var _use = flatIter(function(plugin) {

@@ -539,7 +601,7 @@ // `~n` is falsy for `n === -1` and truthy otherwise.

// `a`.
if (~instance.$plugins.indexOf(plugin)) return
if (~_instance.$plugins.indexOf(plugin)) return
instance.$plugins.push(plugin)
_instance.$plugins.push(plugin)
if (type.call(plugin) === FUNCTION) plugin = plugin(instance)
if (type.call(plugin) === FUNCTION) plugin = plugin(_instance)

@@ -556,58 +618,38 @@ if (!plugin) return

Default(_instance.names, plugin.$names || emptyObject)
_use(plugin.$plugins || emptyArray)
$sink = plugin.$sink || $sink
_default(instance, plugin)
Default(_instance, plugin)
})
function getStream(inline) {
if (!streams.length) {
function _getStream(inline) {
if (!_streams.length) {
for(var i = 0; i < 2; i++){
$filters[$filters.length - i] = function(_, inline) {return inline ? {i:$sink.i, d:$sink.d, x:$sink.x} : $sink}
for (var j = $filters.length; j--;) streams[i] = $filters[j](streams[i], !!i, parsers[i])
for (var j = $filters.length; j--;) {
_streams[i] = freeze(Default(
$filters[j](_streams[i], !!i, _walkers[i]),
_streams[i]
))
}
}
}
var res = streams[inline]
var res = _streams[inline]
return res
}
function localize(name) {
if (!instance.names[name]) instance.names[name] = name + instance.suffix
return instance.names[name].match(/^\S+/)
function _localize(name) {
if (!_instance.names[name]) _instance.names[name] = name + _instance.suffix
return _instance.names[name].match(/^\S+/)
}
function localizeReplacer(match, string, global, dot, name) {
function _localizeReplacer(match, string, global, dot, name) {
if (string || global) return string || global
return dot + localize(name)
return dot + _localize(name)
}
/*/-statements-/*/
instance.sheet = function(tree) {
var emit = getStream(0)
emit.i()
sheet(
parsers[0],
emit,
'', // prefix
tree,
1, // local, by default
0 // inAtRule
)
return emit.x()
}
/*/-statements-/*/
instance.inline = function (tree) {
var emit = getStream(1)
emit.i()
declarations(
parsers[1],
emit,
'', // prefix
tree,
1 //local
)
return emit.x()
}
return instance
return _instance
}

@@ -614,0 +656,0 @@

@@ -12,2 +12,10 @@ var j2c = (function () {

var own = emptyObject.hasOwnProperty;
var freeze = Object.freeze || function(o) {return o};
function Default(target, source) {
for (var k in source) if (own.call(source, k)) {
if (k.indexOf('$') && !(k in target)) target[k] = source[k]
}
return target
}
function cartesian(a,b) {

@@ -39,5 +47,5 @@ var res = [], i, j

/*eslint-disable no-cond-assign*/
while(o = selectorTokenizer.exec(selector)) {
while (o = selectorTokenizer.exec(selector)) {
/*eslint-enable no-cond-assign*/
switch(o[0]){
switch (o[0]) {
case '(': inParen++; break

@@ -63,3 +71,3 @@ case ')': inParen--; break

/*eslint-disable no-cond-assign*/
while(o = ampersandTokenizer.exec(selector)) {
while (o = ampersandTokenizer.exec(selector)) {
/*eslint-enable no-cond-assign*/

@@ -94,3 +102,4 @@ if (o[0] == '&') indices.push(o.index)

*
* @param {object} parser - holds the parser-related methods and state
* @param {object} state - holds the localizer- and walker-related methods
* and state
* @param {object} emit - the contextual emitters to the final buffer

@@ -103,3 +112,3 @@ * @param {string} prefix - the current property or a prefix in case of nested

function declarations(parser, emit, prefix, o, local) {
function declarations(state, emit, prefix, o, local) {
var k, v, kk

@@ -112,3 +121,3 @@ if (o==null) return

declarations(parser, emit, prefix, o[k], local)
declarations(state, emit, prefix, o[k], local)

@@ -125,3 +134,3 @@ break

declarations(parser, emit, prefix + k[kk], v, local)
declarations(state, emit, prefix + k[kk], v, local)

@@ -131,3 +140,3 @@ }

declarations(parser, emit, prefix + k, v, local)
declarations(state, emit, prefix + k, v, local)

@@ -150,6 +159,6 @@ }

// no need to tokenize here a plain `.split(',')` has all bases covered.
// We may 'parser' a comment, but it's not a big deal.
// We may 'localize' a comment, but it's not a big deal.
o = o.split(',').map(function (o) {
return o.replace(/($^)|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/, parser.L)
return o.replace(/(var\([^)]+\))|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/, state.L)

@@ -167,3 +176,4 @@ }).join(',')

*
* @param {object} parser - holds the parser-related methods and state
* @param {object} state - holds the localizer- and walker-related methods
* and state
* @param {object} emit - the contextual emitters to the final buffer

@@ -182,13 +192,17 @@ * @param {array} k - The parsed at-rule, including the parameters,

function atRules(parser, emit, k, v, prefix, local, inAtRule) {
function atRules(state, emit, k, v, prefix, local, inAtRule) {
for (var i = 0; i < parser.$a.length; i++) {
for (var i = 0; i < state.$a.length; i++) {
if (parser.$a[i](parser, emit, k, v, prefix, local, inAtRule)) return
if (state.$a[i](state, emit, k, v, prefix, local, inAtRule)) return
}
// using `/^global$/.test(k[2])` rather that 'global' == k[2] gzips
// slightly better because of the regexps test further down.
// It is slightly less efficient but this isn't a critical path.
if (!k[3] && /^global$/.test(k[2])) {
sheet(parser, emit, prefix, v, 0, inAtRule)
rules(state, emit, prefix, v, 0, inAtRule)

@@ -198,3 +212,3 @@

sheet(parser, emit, prefix, v, 1, inAtRule)
rules(state, emit, prefix, v, 1, inAtRule)

@@ -209,8 +223,7 @@

i = []
flatIter(function(c, s){
s = c.toString()
flatIter(function(adoptee, asString) {
if(!/^\.?[_A-Za-z][-\w]*(?:\s+\.?[_A-Za-z][-\w]*)*$/.test(s)) emit.a('@-error-bad-at-adoptee', JSON.stringify(c), 0)
if(!/^\.?[_A-Za-z][-\w]*(?:\s+\.?[_A-Za-z][-\w]*)*$/.test(asString = adoptee.toString())) emit.a('@-error-bad-at-adoptee', JSON.stringify(adoptee), 0)
else i.push(s.replace(/\./g, ''))
else i.push(asString.replace(/\./g, ''))

@@ -221,5 +234,4 @@ })(v)

if (i.length) {
// console.log("========== I ===========\n", i)
parser.l(k[3] = k[3].replace(/\./g, ''))
parser.n[k[3]] += (' ' + i.join(' '))
state.l(k[3] = k[3].replace(/\./g, ''))
state.n[k[3]] += (' ' + i.join(' '))
}

@@ -241,3 +253,3 @@

declarations(parser, emit, '', v, local)
declarations(state, emit, '', v, local)

@@ -253,4 +265,4 @@ emit.A(k[1], '')

// generated by script/regexps.js
/($^)|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,
parser.L
/(var\([^)]+\))|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,
state.L
)

@@ -264,8 +276,8 @@ }

declarations(parser, emit, '', v, local)
declarations(state, emit, '', v, local)
} else {
sheet(
parser, emit,
rules(
state, emit,
'keyframes' == k[2] ? '' : prefix,

@@ -289,3 +301,4 @@ v, local, 1

*
* @param {object} parser - holds the parser-related methods and state
* @param {object} state - holds the localizer- and walker-related methods
* and state
* @param {object} emit - the contextual emitters to the final buffer

@@ -297,3 +310,3 @@ * @param {string} prefix - the current selector or a prefix in case of nested rules

*/
function sheet(parser, emit, prefix, tree, local, inAtRule) {
function rules(state, emit, prefix, tree, local, inAtRule) {
var k, v, inDeclaration, kk

@@ -307,3 +320,3 @@

if (prefix && /^[-\w$]+$/.test(k)) {
if (prefix.length > 0 && /^[-\w$]+$/.test(k)) {
if (!inDeclaration) {

@@ -318,3 +331,3 @@ inDeclaration = 1

declarations(parser, emit, k[kk], v, local)
declarations(state, emit, k[kk], v, local)

@@ -324,3 +337,3 @@ }

declarations(parser, emit, k, v, local)
declarations(state, emit, k, v, local)

@@ -333,3 +346,3 @@ }

atRules(parser, emit,
atRules(state, emit,
/^(.(?:-[\w]+-)?([_A-Za-z][-\w]*))\b\s*(.*?)\s*$/.exec(k) || [k,'@','',''],

@@ -343,7 +356,7 @@ v, prefix, local, inAtRule

sheet(
parser, emit,
rules(
state, emit,
// `prefix` ... Hefty. Ugly. Sadly necessary.
//
(prefix && (/,/.test(prefix) || /,/.test(k))) ?
(prefix.length > 0 && (/,/.test(prefix) || /,/.test(k))) ?

@@ -354,3 +367,4 @@ /*0*/ (kk = splitSelector(prefix), splitSelector(

k.replace(
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g, parser.L
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,
state.L
) :

@@ -371,3 +385,4 @@

k.replace(
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g, parser.L
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,
state.L
) :

@@ -383,3 +398,4 @@

k.replace(
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g, parser.L
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,
state.L
) :

@@ -400,3 +416,3 @@

sheet(parser, emit, prefix, tree[k], local, inAtRule)
rules(state, emit, prefix, tree[k], local, inAtRule)

@@ -409,5 +425,5 @@ }

emit.s(prefix || ':-error-no-selector')
emit.s(prefix.length > 0 ? prefix : ':-error-no-selector')
declarations(parser, emit, '', tree, local)
declarations(state, emit, '', tree, local)

@@ -477,5 +493,30 @@ }

function j2c() {
// palceholder for the buffer used by the `$sink` handlers
var buf
// the bottom of the 'codegen' stream. Mirrors the `$filter` plugin API.
var $sink = {
// Init
i: function(){buf=[]},
// done (eXit)
x: function (raw) {return raw ? buf : buf.join('')},
// start At-rule
a: function (rule, argument, takesBlock) {
buf.push(rule, argument && ' ',argument, takesBlock ? ' {\n' : ';\n')
},
// end At-rule
A: function () {buf.push('}\n')},
// start Selector
s: function (selector) {buf.push(selector, ' {\n')},
// end Selector
S: function () {buf.push('}\n')},
// declarations
d: function (prop, value) {buf.push(prop, prop && ':', value, ';\n')}
}
var $filters = [closeSelectors]
var $atHandlers = []
var instance = {
var _instance = {
at: at,

@@ -492,3 +533,3 @@ global: global,

_use(emptyArray.slice.call(arguments))
return instance
return _instance
},

@@ -498,40 +539,61 @@ $plugins: []

function _default(target, source) {
for (var k in source) if (own.call(source, k) && k.indexOf('$')) {
if (OBJECT == type.call(source[k]) && OBJECT == type.call(target[k])) _default(target[k], source[k])
else if (!(k in target)) target[k] = source[k]
}
}
var _streams = []
var buf
var $sink = {
i: function(){buf=[]},
x: function (raw) {return raw ? buf : buf.join('')},
a: function (rule, argument, takesBlock) {
buf.push(rule, argument && ' ',argument, takesBlock ? ' {\n' : ';\n')
},
A: function () {buf.push('}\n')},
s: function (selector) {buf.push(selector, ' {\n')},
S: function () {buf.push('}\n')},
d: function (prop, value) {buf.push(prop, prop && ':', value, ';\n')}
}
var streams = []
// The `state` (for the core) / `walker` (for the plugins) tables.
var parsers = [
var _walkers = [
// for j2c.sheet
{
$a: $atHandlers,
// helpers for locaizing class and animation names
L: _localizeReplacer, // second argument to String.prototype.replace
l: _localize, // mangles local names
n: _instance.names, // local => mangled mapping
$a: $atHandlers, // extra at-rules
// The core walker methods, to be provided to plugins
a: atRules,
d: declarations,
L: localizeReplacer,
l: localize,
n: instance.names,
s: sheet
}, {
d: declarations,
L: localizeReplacer,
l: localize,
n: instance.names
r: rules
},
// likewise, for j2c.inline (idem with `$a`, `a` and `s` removed)
{
L: _localizeReplacer,
l: _localize,
n: _instance.names,
d: declarations
}
]
// The main API functions
_instance.sheet = function(tree) {
var emit = _getStream(0)
emit.i()
rules(
_walkers[0],
emit,
'', // prefix
tree,
1, // local, by default
0 // inAtRule
)
return emit.x()
}
_instance.inline = function (tree) {
var emit = _getStream(1)
emit.i()
declarations(
_walkers[1],
emit,
'', // prefix
tree,
1 //local
)
return emit.x()
}
// inner helpers
var _use = flatIter(function(plugin) {

@@ -542,7 +604,7 @@ // `~n` is falsy for `n === -1` and truthy otherwise.

// `a`.
if (~instance.$plugins.indexOf(plugin)) return
if (~_instance.$plugins.indexOf(plugin)) return
instance.$plugins.push(plugin)
_instance.$plugins.push(plugin)
if (type.call(plugin) === FUNCTION) plugin = plugin(instance)
if (type.call(plugin) === FUNCTION) plugin = plugin(_instance)

@@ -559,58 +621,38 @@ if (!plugin) return

Default(_instance.names, plugin.$names || emptyObject)
_use(plugin.$plugins || emptyArray)
$sink = plugin.$sink || $sink
_default(instance, plugin)
Default(_instance, plugin)
})
function getStream(inline) {
if (!streams.length) {
function _getStream(inline) {
if (!_streams.length) {
for(var i = 0; i < 2; i++){
$filters[$filters.length - i] = function(_, inline) {return inline ? {i:$sink.i, d:$sink.d, x:$sink.x} : $sink}
for (var j = $filters.length; j--;) streams[i] = $filters[j](streams[i], !!i, parsers[i])
for (var j = $filters.length; j--;) {
_streams[i] = freeze(Default(
$filters[j](_streams[i], !!i, _walkers[i]),
_streams[i]
))
}
}
}
var res = streams[inline]
var res = _streams[inline]
return res
}
function localize(name) {
if (!instance.names[name]) instance.names[name] = name + instance.suffix
return instance.names[name].match(/^\S+/)
function _localize(name) {
if (!_instance.names[name]) _instance.names[name] = name + _instance.suffix
return _instance.names[name].match(/^\S+/)
}
function localizeReplacer(match, string, global, dot, name) {
function _localizeReplacer(match, string, global, dot, name) {
if (string || global) return string || global
return dot + localize(name)
return dot + _localize(name)
}
/*/-statements-/*/
instance.sheet = function(tree) {
var emit = getStream(0)
emit.i()
sheet(
parsers[0],
emit,
'', // prefix
tree,
1, // local, by default
0 // inAtRule
)
return emit.x()
}
/*/-statements-/*/
instance.inline = function (tree) {
var emit = getStream(1)
emit.i()
declarations(
parsers[1],
emit,
'', // prefix
tree,
1 //local
)
return emit.x()
}
return instance
return _instance
}

@@ -617,0 +659,0 @@

@@ -1,1 +0,1 @@

var j2c=function(){"use strict";function n(n,t){var e,a,r=[];for(a in t)if(b.call(t,a))for(e in n)b.call(n,e)&&r.push(n[e]+t[a]);return r}function t(n){for(var t,e=[],a=[],r=0;t=S.exec(n);)switch(t[0]){case"(":r++;break;case")":r--;break;case",":if(r)break;e.push(t.index)}for(t=e.length;t--;)a.unshift(n.slice(e[t]+1)),n=n.slice(0,e[t]);return a.unshift(n),a}function e(t,e){for(var a,r,i=[],s=[];r=A.exec(t);)"&"==r[0]&&i.push(r.index);for(r=i.length;r--;)s.unshift(t.slice(i[r]+1)),t=t.slice(0,i[r]);for(s.unshift(t),a=[s[0]],r=1;r<s.length;r++)a=n(a,n(e,[s[r]]));return a.join(",")}function a(n){return function t(e){if(m.call(e)===d)for(var a=0;a<e.length;a++)t(e[a]);else n(e)}}function r(n){return"-"+n.toLowerCase()}function i(n,t,e,a,s){var l,o,u;if(null!=a)switch(m.call(a=a.valueOf())){case d:for(l=0;l<a.length;l++)i(n,t,e,a[l],s);break;case $:e=e&&e+"-";for(l in a)if(b.call(a,l))if(o=a[l],/\$/.test(l))for(u in l=l.split("$"))b.call(l,u)&&i(n,t,e+l[u],o,s);else i(n,t,e+l,o,s);break;default:l=e.replace(/_/g,"-").replace(/[A-Z]/g,r),!s||"animation-name"!=l&&"animation"!=l&&"list-style"!=l||(a=a.split(",").map(function(t){return t.replace(/($^)|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,n.L)}).join(",")),t.d(l,a)}}function s(n,t,e,r,s,o,u){for(var f=0;f<n.$a.length;f++)if(n.$a[f](n,t,e,r,s,o,u))return;if(!e[3]&&/^global$/.test(e[2]))l(n,t,s,r,0,u);else if(!e[3]&&/^local$/.test(e[2]))l(n,t,s,r,1,u);else if(e[3]&&/^adopt$/.test(e[2])){if(!o||u)return t.a("@-error-bad-at-adopt-placement",JSON.stringify(e[0]),0);if(!/^\.?[_A-Za-z][-\w]*$/.test(e[3]))return t.a("@-error-bad-at-adopter",e[3],0);f=[],a(function(n,e){e=n.toString(),/^\.?[_A-Za-z][-\w]*(?:\s+\.?[_A-Za-z][-\w]*)*$/.test(e)?f.push(e.replace(/\./g,"")):t.a("@-error-bad-at-adoptee",JSON.stringify(n),0)})(r),f.length&&(n.l(e[3]=e[3].replace(/\./g,"")),n.n[e[3]]+=" "+f.join(" "))}else!e[3]&&/^(?:namespace|import|charset)$/.test(e[2])?a(function(n){t.a(e[0],n)})(r):!e[3]&&/^(?:font-face|viewport)$/.test(e[2])?a(function(a){t.a(e[1],"",1),i(n,t,"",a,o),t.A(e[1],"")})(r):e[3]&&/^(?:media|supports|page|keyframes)$/.test(e[2])?(o&&"keyframes"==e[2]&&(e[3]=e[3].replace(/($^)|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,n.L)),t.a(e[1],e[3],1),"page"==e[2]?i(n,t,"",r,o):l(n,t,"keyframes"==e[2]?"":s,r,o,1),t.A(e[1],e[3])):t.a("@-error-unsupported-at-rule",JSON.stringify(e[0]))}function l(n,a,r,o,u,f){var c,p,g,h;switch(m.call(o)){case $:for(c in o)if(b.call(o,c))if(p=o[c],r&&/^[-\w$]+$/.test(c))if(g||(g=1,a.s(r)),/\$/.test(c))for(h in c=c.split("$"))b.call(c,h)&&i(n,a,c[h],p,u);else i(n,a,c,p,u);else/^@/.test(c)?(g=0,s(n,a,/^(.(?:-[\w]+-)?([_A-Za-z][-\w]*))\b\s*(.*?)\s*$/.exec(c)||[c,"@","",""],p,r,u,f)):(g=0,l(n,a,r&&(/,/.test(r)||/,/.test(c))?(h=t(r),t(u?c.replace(/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,n.L):c).map(function(n){return/&/.test(n)?e(n,h):h.map(function(t){return t+n}).join(",")}).join(",")):/&/.test(c)?e(u?c.replace(/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,n.L):c,[r]):r+(u?c.replace(/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,n.L):c),p,u,f));break;case d:for(c=0;c<o.length;c++)l(n,a,r,o[c],u,f);break;case v:a.s(r||":-error-no-selector"),i(n,a,"",o,u)}}function o(n,t){var e;return t?n:{i:function(){e=0,n.i()},x:function(t){return e&&(n.S(),e=0),n.x(t)},a:function(t,a,r){e&&(n.S(),e=0),n.a(t,a,r)},A:function(t){e&&(n.S(),e=0),n.A(t)},s:function(t){t!==e&&(e&&n.S(),n.s(t),e=t)},d:n.d}}function u(n){return":global("+n+")"}function f(n,t,e){return e={},e[n]=t,e}function c(n,t,e){if(arguments.length<3){var a=c.bind.apply(c,[null].concat([].slice.call(arguments,0)));return a.toString=function(){return"@"+n+" "+t},a}return f("@"+n+" "+t,e)}function p(){function n(t,e){for(var a in e)b.call(e,a)&&a.indexOf("$")&&($==m.call(e[a])&&$==m.call(t[a])?n(t[a],e[a]):a in t||(t[a]=e[a]))}function t(n){if(!A.length)for(var t=0;2>t;t++){h[h.length-t]=function(n,t){return t?{i:S.i,d:S.d,x:S.x}:S};for(var e=h.length;e--;)A[t]=h[e](A[t],!!t,x[t])}var a=A[n];return a}function e(n){return v.names[n]||(v.names[n]=n+v.suffix),v.names[n].match(/^\S+/)}function r(n,t,a,r,i){return t||a?t||a:r+e(i)}var p,h=[o],d=[],v={at:c,global:u,kv:f,names:{},suffix:"__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),use:function(){return _(g.slice.call(arguments)),v},$plugins:[]},S={i:function(){p=[]},x:function(n){return n?p:p.join("")},a:function(n,t,e){p.push(n,t&&" ",t,e?" {\n":";\n")},A:function(){p.push("}\n")},s:function(n){p.push(n," {\n")},S:function(){p.push("}\n")},d:function(n,t){p.push(n,n&&":",t,";\n")}},A=[],x=[{$a:d,a:s,d:i,L:r,l:e,n:v.names,s:l},{d:i,L:r,l:e,n:v.names}],_=a(function(t){~v.$plugins.indexOf(t)||(v.$plugins.push(t),m.call(t)===w&&(t=t(v)),t&&(a(function(n){h.push(n)})(t.$filter||g),a(function(n){d.push(n)})(t.$at||g),S=t.$sink||S,n(v,t)))});return v.sheet=function(n){var e=t(0);return e.i(),l(x[0],e,"",n,1,0),e.x()},v.inline=function(n){var e=t(1);return e.i(),i(x[1],e,"",n,1),e.x()},v}var g=[],h={},m=h.toString,d=m.call(g),$=m.call(h),v=m.call(""),w=m.call(m),b=h.hasOwnProperty,S=/[(),]|"(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\//g,A=/&|"(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\//g,x=p();return"sheet|inline|names|at|global|kv|suffix".split("|").map(function(n){p[n]=x[n]}),p}();
var j2c=function(){"use strict";function n(n,t){for(var e in t)S.call(t,e)&&(!e.indexOf("$")||e in n||(n[e]=t[e]));return n}function t(n,t){var e,r,a=[];for(r in t)if(S.call(t,r))for(e in n)S.call(n,e)&&a.push(n[e]+t[r]);return a}function e(n){for(var t,e=[],r=[],a=0;t=x.exec(n);)switch(t[0]){case"(":a++;break;case")":a--;break;case",":if(a)break;e.push(t.index)}for(t=e.length;t--;)r.unshift(n.slice(e[t]+1)),n=n.slice(0,e[t]);return r.unshift(n),r}function r(n,e){for(var r,a,i=[],s=[];a=_.exec(n);)"&"==a[0]&&i.push(a.index);for(a=i.length;a--;)s.unshift(n.slice(i[a]+1)),n=n.slice(0,i[a]);for(s.unshift(n),r=[s[0]],a=1;a<s.length;a++)r=t(r,t(e,[s[a]]));return r.join(",")}function a(n){return function t(e){if(d.call(e)===$)for(var r=0;r<e.length;r++)t(e[r]);else n(e)}}function i(n){return"-"+n.toLowerCase()}function s(n,t,e,r,a){var o,l,u;if(null!=r)switch(d.call(r=r.valueOf())){case $:for(o=0;o<r.length;o++)s(n,t,e,r[o],a);break;case v:e=e&&e+"-";for(o in r)if(S.call(r,o))if(l=r[o],/\$/.test(o))for(u in o=o.split("$"))S.call(o,u)&&s(n,t,e+o[u],l,a);else s(n,t,e+o,l,a);break;default:o=e.replace(/_/g,"-").replace(/[A-Z]/g,i),!a||"animation-name"!=o&&"animation"!=o&&"list-style"!=o||(r=r.split(",").map(function(t){return t.replace(/(var\([^)]+\))|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,n.L)}).join(",")),t.d(o,r)}}function o(n,t,e,r,i,o,u){for(var f=0;f<n.$a.length;f++)if(n.$a[f](n,t,e,r,i,o,u))return;if(!e[3]&&/^global$/.test(e[2]))l(n,t,i,r,0,u);else if(!e[3]&&/^local$/.test(e[2]))l(n,t,i,r,1,u);else if(e[3]&&/^adopt$/.test(e[2])){if(!o||u)return t.a("@-error-bad-at-adopt-placement",JSON.stringify(e[0]),0);if(!/^\.?[_A-Za-z][-\w]*$/.test(e[3]))return t.a("@-error-bad-at-adopter",e[3],0);f=[],a(function(n,e){/^\.?[_A-Za-z][-\w]*(?:\s+\.?[_A-Za-z][-\w]*)*$/.test(e=n.toString())?f.push(e.replace(/\./g,"")):t.a("@-error-bad-at-adoptee",JSON.stringify(n),0)})(r),f.length&&(n.l(e[3]=e[3].replace(/\./g,"")),n.n[e[3]]+=" "+f.join(" "))}else!e[3]&&/^(?:namespace|import|charset)$/.test(e[2])?a(function(n){t.a(e[0],n)})(r):!e[3]&&/^(?:font-face|viewport)$/.test(e[2])?a(function(r){t.a(e[1],"",1),s(n,t,"",r,o),t.A(e[1],"")})(r):e[3]&&/^(?:media|supports|page|keyframes)$/.test(e[2])?(o&&"keyframes"==e[2]&&(e[3]=e[3].replace(/(var\([^)]+\))|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,n.L)),t.a(e[1],e[3],1),"page"==e[2]?s(n,t,"",r,o):l(n,t,"keyframes"==e[2]?"":i,r,o,1),t.A(e[1],e[3])):t.a("@-error-unsupported-at-rule",JSON.stringify(e[0]))}function l(n,t,a,i,u,f){var c,g,p,h;switch(d.call(i)){case v:for(c in i)if(S.call(i,c))if(g=i[c],a.length>0&&/^[-\w$]+$/.test(c))if(p||(p=1,t.s(a)),/\$/.test(c))for(h in c=c.split("$"))S.call(c,h)&&s(n,t,c[h],g,u);else s(n,t,c,g,u);else/^@/.test(c)?(p=0,o(n,t,/^(.(?:-[\w]+-)?([_A-Za-z][-\w]*))\b\s*(.*?)\s*$/.exec(c)||[c,"@","",""],g,a,u,f)):(p=0,l(n,t,a.length>0&&(/,/.test(a)||/,/.test(c))?(h=e(a),e(u?c.replace(/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,n.L):c).map(function(n){return/&/.test(n)?r(n,h):h.map(function(t){return t+n}).join(",")}).join(",")):/&/.test(c)?r(u?c.replace(/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,n.L):c,[a]):a+(u?c.replace(/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\/)|:global\(\s*(\.-?[_A-Za-z][-\w]*)\s*\)|(\.)(-?[_A-Za-z][-\w]*)/g,n.L):c),g,u,f));break;case $:for(c=0;c<i.length;c++)l(n,t,a,i[c],u,f);break;case b:t.s(a.length>0?a:":-error-no-selector"),s(n,t,"",i,u)}}function u(n,t){var e;return t?n:{i:function(){e=0,n.i()},x:function(t){return e&&(n.S(),e=0),n.x(t)},a:function(t,r,a){e&&(n.S(),e=0),n.a(t,r,a)},A:function(t){e&&(n.S(),e=0),n.A(t)},s:function(t){t!==e&&(e&&n.S(),n.s(t),e=t)},d:n.d}}function f(n){return":global("+n+")"}function c(n,t,e){return e={},e[n]=t,e}function g(n,t,e){if(arguments.length<3){var r=g.bind.apply(g,[null].concat([].slice.call(arguments,0)));return r.toString=function(){return"@"+n+" "+t},r}return c("@"+n+" "+t,e)}function p(){function t(t){if(!S.length)for(var e=0;2>e;e++){$[$.length-e]=function(n,t){return t?{i:p.i,d:p.d,x:p.x}:p};for(var r=$.length;r--;)S[e]=A(n($[r](S[e],!!e,x[e]),S[e]))}var a=S[t];return a}function e(n){return b.names[n]||(b.names[n]=n+b.suffix),b.names[n].match(/^\S+/)}function r(n,t,r,a,i){return t||r?t||r:a+e(i)}var i,p={i:function(){i=[]},x:function(n){return n?i:i.join("")},a:function(n,t,e){i.push(n,t&&" ",t,e?" {\n":";\n")},A:function(){i.push("}\n")},s:function(n){i.push(n," {\n")},S:function(){i.push("}\n")},d:function(n,t){i.push(n,n&&":",t,";\n")}},$=[u],v=[],b={at:g,global:f,kv:c,names:{},suffix:"__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),use:function(){return _(h.slice.call(arguments)),b},$plugins:[]},S=[],x=[{L:r,l:e,n:b.names,$a:v,a:o,d:s,r:l},{L:r,l:e,n:b.names,d:s}];b.sheet=function(n){var e=t(0);return e.i(),l(x[0],e,"",n,1,0),e.x()},b.inline=function(n){var e=t(1);return e.i(),s(x[1],e,"",n,1),e.x()};var _=a(function(t){~b.$plugins.indexOf(t)||(b.$plugins.push(t),d.call(t)===w&&(t=t(b)),t&&(a(function(n){$.push(n)})(t.$filter||h),a(function(n){v.push(n)})(t.$at||h),n(b.names,t.$names||m),_(t.$plugins||h),p=t.$sink||p,n(b,t)))});return b}var h=[],m={},d=m.toString,$=d.call(h),v=d.call(m),b=d.call(""),w=d.call(d),S=m.hasOwnProperty,A=Object.freeze||function(n){return n},x=/[(),]|"(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\//g,_=/&|"(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\//g,z=p();return"sheet|inline|names|at|global|kv|suffix".split("|").map(function(n){p[n]=z[n]}),p}();
# Change log
## v1.0.0 (WIP)
- Fix: Robust parsing of selectors. Comas, ampersands and class-like parts
in strings are now ignored by the compiler.
```JS
j2c.sheet({'p':{'[foo="&,.bar"]': {color: 'red'}}})
```
produces
```CSS
p[foo="&,.bar"] {color:red}
```
Whereas previous versions would produce
```CSS
[foo="p,p.bar_j2c_ubv4pc_knzcqw_ngjme7_1usit1c_9"] {color: red;}
```
Likewise, `':not(p, a, ul, li)'` (a CSS4 addition) will not be split.
- Local scope is now per instance rather than per sheet.
- `j2c.sheet()` and `j2c.inline()` return plain strings rather than
`String` objects.
- `j2c.names` holds the local -> global mappings for use in the (v)DOM.
- Removed the partial auto-prefix insertion from the core.
- Revamped the plugin system.
- Removed `$postprocess` plugins that were taking and returning the full
buffer.
- Introduced `$filter` system that can patch values on the fly on their
way between the compiler and the buffer.
- Introduced `$sink` plugin that allow to subvert the sheet building
process to implement systems like Radium or Descartes.
- Introduced `$at` filters that can handle at-rules beside the ones that
j2c supports out of the box.
- Revamped the poorly named `@extend` into `@adopt`, based on @tivac's
Modular CSS `composes`. The semantics are too distant from either `@extend`
or `composes` to use their name witout introducing potential confusion,
hence the new name.
So: `j2c.sheet({'@adopt .foo': ['.bar']})` where foo is a local class that adopts the behavior of the global `.bar`.
- Consecutive, identical selectors are deduped in the output.
- Prefixed at-rules are treated like their unprefixed counterparts.
- Added the `at()`, `global()` and `kv()` helpers.
- Added `@local` as a counterpart to `@global`.
- `& > &` with a selector list as parent will perform their cartesian product
like SASS and LESS do.
- 2.2Kb mingzipped (+ ~500 bytes).
## v0.11.1 (2016-03-8)
- Patch bump to fix what `npm` installs by default (I erronously published `v1.0.0-0` on without `--tag next`)
## v0.11.0

@@ -4,0 +60,0 @@

{
"name": "j2c",
"version": "1.0.0-1",
"version": "1.0.0-2",
"description": "A tiny CSS in JS solution.",

@@ -15,3 +15,3 @@ "main": "dist/j2c.commonjs.js",

"cover": "istanbul cover _mocha -- -R nyan --ui qunit && npm run -s check-coverage",
"check-coverage": "istanbul check-coverage --branches 100",
"check-coverage": "istanbul check-coverage --branches -2",
"travis": "npm run build && istanbul cover _mocha --report lcovonly -- -R spec --ui qunit && (codecov || true) && npm run -s check-coverage"

@@ -18,0 +18,0 @@ },

@@ -0,1 +1,5 @@

# Warning, WIP: these docs haven't been updated to match the changes since v0.11
See HISTORY.md for a high level overview of the differences.
# j2c [![npm][npm_img]][npm_url] ![.min.gz][size_img]

@@ -23,2 +27,3 @@

A lean (2.0KB), no hassle CSS in JS solution.

@@ -25,0 +30,0 @@

import {flatIter} from './helpers'
import {sheet} from './sheet'
import {rules} from './rules'
import {declarations} from './declarations'

@@ -8,3 +8,4 @@

*
* @param {object} parser - holds the parser-related methods and state
* @param {object} state - holds the localizer- and walker-related methods
* and state
* @param {object} emit - the contextual emitters to the final buffer

@@ -23,13 +24,17 @@ * @param {array} k - The parsed at-rule, including the parameters,

export function atRules(parser, emit, k, v, prefix, local, inAtRule) {
export function atRules(state, emit, k, v, prefix, local, inAtRule) {
for (var i = 0; i < parser.$a.length; i++) {
for (var i = 0; i < state.$a.length; i++) {
if (parser.$a[i](parser, emit, k, v, prefix, local, inAtRule)) return
if (state.$a[i](state, emit, k, v, prefix, local, inAtRule)) return
}
// using `/^global$/.test(k[2])` rather that 'global' == k[2] gzips
// slightly better because of the regexps test further down.
// It is slightly less efficient but this isn't a critical path.
if (!k[3] && /^global$/.test(k[2])) {
sheet(parser, emit, prefix, v, 0, inAtRule)
rules(state, emit, prefix, v, 0, inAtRule)

@@ -39,3 +44,3 @@

sheet(parser, emit, prefix, v, 1, inAtRule)
rules(state, emit, prefix, v, 1, inAtRule)

@@ -50,8 +55,7 @@

i = []
flatIter(function(c, s){
s = c.toString()
flatIter(function(adoptee, asString) {
if(!/^\.?[_A-Za-z][-\w]*(?:\s+\.?[_A-Za-z][-\w]*)*$/.test(s)) emit.a('@-error-bad-at-adoptee', JSON.stringify(c), 0)
if(!/^\.?[_A-Za-z][-\w]*(?:\s+\.?[_A-Za-z][-\w]*)*$/.test(asString = adoptee.toString())) emit.a('@-error-bad-at-adoptee', JSON.stringify(adoptee), 0)
else i.push(s.replace(/\./g, ''))
else i.push(asString.replace(/\./g, ''))

@@ -62,5 +66,4 @@ })(v)

if (i.length) {
// console.log("========== I ===========\n", i)
parser.l(k[3] = k[3].replace(/\./g, ''))
parser.n[k[3]] += (' ' + i.join(' '))
state.l(k[3] = k[3].replace(/\./g, ''))
state.n[k[3]] += (' ' + i.join(' '))
}

@@ -82,3 +85,3 @@

declarations(parser, emit, '', v, local)
declarations(state, emit, '', v, local)

@@ -94,4 +97,4 @@ emit.A(k[1], '')

// generated by script/regexps.js
/($^)|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,
parser.L
/(var\([^)]+\))|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/,
state.L
)

@@ -105,8 +108,8 @@ }

declarations(parser, emit, '', v, local)
declarations(state, emit, '', v, local)
} else {
sheet(
parser, emit,
rules(
state, emit,
'keyframes' == k[2] ? '' : prefix,

@@ -113,0 +116,0 @@ v, local, 1

@@ -10,3 +10,4 @@ import {own, type, ARRAY, OBJECT} from './helpers'

*
* @param {object} parser - holds the parser-related methods and state
* @param {object} state - holds the localizer- and walker-related methods
* and state
* @param {object} emit - the contextual emitters to the final buffer

@@ -19,3 +20,3 @@ * @param {string} prefix - the current property or a prefix in case of nested

export function declarations(parser, emit, prefix, o, local) {
export function declarations(state, emit, prefix, o, local) {
var k, v, kk

@@ -28,3 +29,3 @@ if (o==null) return

declarations(parser, emit, prefix, o[k], local)
declarations(state, emit, prefix, o[k], local)

@@ -41,3 +42,3 @@ break

declarations(parser, emit, prefix + k[kk], v, local)
declarations(state, emit, prefix + k[kk], v, local)

@@ -47,3 +48,3 @@ }

declarations(parser, emit, prefix + k, v, local)
declarations(state, emit, prefix + k, v, local)

@@ -66,6 +67,6 @@ }

// no need to tokenize here a plain `.split(',')` has all bases covered.
// We may 'parser' a comment, but it's not a big deal.
// We may 'localize' a comment, but it's not a big deal.
o = o.split(',').map(function (o) {
return o.replace(/($^)|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/, parser.L)
return o.replace(/(var\([^)]+\))|:?global\(\s*([_A-Za-z][-\w]*)\s*\)|()(-?[_A-Za-z][-\w]*)/, state.L)

@@ -72,0 +73,0 @@ }).join(',')

@@ -9,5 +9,13 @@ var

FUNCTION = type.call(type),
own = emptyObject.hasOwnProperty
own = emptyObject.hasOwnProperty,
freeze = Object.freeze || function(o) {return o}
function Default(target, source) {
for (var k in source) if (own.call(source, k)) {
if (k.indexOf('$') && !(k in target)) target[k] = source[k]
}
return target
}
function cartesian(a,b) {

@@ -39,5 +47,5 @@ var res = [], i, j

/*eslint-disable no-cond-assign*/
while(o = selectorTokenizer.exec(selector)) {
while (o = selectorTokenizer.exec(selector)) {
/*eslint-enable no-cond-assign*/
switch(o[0]){
switch (o[0]) {
case '(': inParen++; break

@@ -63,3 +71,3 @@ case ')': inParen--; break

/*eslint-disable no-cond-assign*/
while(o = ampersandTokenizer.exec(selector)) {
while (o = ampersandTokenizer.exec(selector)) {
/*eslint-enable no-cond-assign*/

@@ -89,6 +97,6 @@ if (o[0] == '&') indices.push(o.index)

ARRAY, FUNCTION, OBJECT, STRING,
ampersand, cartesian,
ampersand, cartesian, Default,
emptyArray, emptyObject,
flatIter, own,
flatIter, freeze, own,
splitSelector, type
}

@@ -1,3 +0,3 @@

import {own, flatIter, emptyArray, type, FUNCTION, OBJECT} from './helpers'
import {sheet, closeSelectors} from './sheet'
import {Default, emptyArray, emptyObject, flatIter, freeze, type, FUNCTION} from './helpers'
import {closeSelectors, rules} from './rules'
import {declarations} from './declarations'

@@ -9,5 +9,30 @@ import {atRules} from './at-rules'

export default function j2c() {
// palceholder for the buffer used by the `$sink` handlers
var buf
// the bottom of the 'codegen' stream. Mirrors the `$filter` plugin API.
var $sink = {
// Init
i: function(){buf=[]},
// done (eXit)
x: function (raw) {return raw ? buf : buf.join('')},
// start At-rule
a: function (rule, argument, takesBlock) {
buf.push(rule, argument && ' ',argument, takesBlock ? ' {\n' : ';\n')
},
// end At-rule
A: function () {buf.push('}\n')},
// start Selector
s: function (selector) {buf.push(selector, ' {\n')},
// end Selector
S: function () {buf.push('}\n')},
// declarations
d: function (prop, value) {buf.push(prop, prop && ':', value, ';\n')}
}
var $filters = [closeSelectors]
var $atHandlers = []
var instance = {
var _instance = {
at: at,

@@ -24,3 +49,3 @@ global: global,

_use(emptyArray.slice.call(arguments))
return instance
return _instance
},

@@ -30,40 +55,61 @@ $plugins: []

function _default(target, source) {
for (var k in source) if (own.call(source, k) && k.indexOf('$')) {
if (OBJECT == type.call(source[k]) && OBJECT == type.call(target[k])) _default(target[k], source[k])
else if (!(k in target)) target[k] = source[k]
}
}
var _streams = []
var buf
var $sink = {
i: function(){buf=[]},
x: function (raw) {return raw ? buf : buf.join('')},
a: function (rule, argument, takesBlock) {
buf.push(rule, argument && ' ',argument, takesBlock ? ' {\n' : ';\n')
},
A: function () {buf.push('}\n')},
s: function (selector) {buf.push(selector, ' {\n')},
S: function () {buf.push('}\n')},
d: function (prop, value) {buf.push(prop, prop && ':', value, ';\n')}
}
var streams = []
// The `state` (for the core) / `walker` (for the plugins) tables.
var parsers = [
var _walkers = [
// for j2c.sheet
{
$a: $atHandlers,
// helpers for locaizing class and animation names
L: _localizeReplacer, // second argument to String.prototype.replace
l: _localize, // mangles local names
n: _instance.names, // local => mangled mapping
$a: $atHandlers, // extra at-rules
// The core walker methods, to be provided to plugins
a: atRules,
d: declarations,
L: localizeReplacer,
l: localize,
n: instance.names,
s: sheet
}, {
d: declarations,
L: localizeReplacer,
l: localize,
n: instance.names
r: rules
},
// likewise, for j2c.inline (idem with `$a`, `a` and `s` removed)
{
L: _localizeReplacer,
l: _localize,
n: _instance.names,
d: declarations
}
]
// The main API functions
_instance.sheet = function(tree) {
var emit = _getStream(0)
emit.i()
rules(
_walkers[0],
emit,
'', // prefix
tree,
1, // local, by default
0 // inAtRule
)
return emit.x()
}
_instance.inline = function (tree) {
var emit = _getStream(1)
emit.i()
declarations(
_walkers[1],
emit,
'', // prefix
tree,
1 //local
)
return emit.x()
}
// inner helpers
var _use = flatIter(function(plugin) {

@@ -74,7 +120,7 @@ // `~n` is falsy for `n === -1` and truthy otherwise.

// `a`.
if (~instance.$plugins.indexOf(plugin)) return
if (~_instance.$plugins.indexOf(plugin)) return
instance.$plugins.push(plugin)
_instance.$plugins.push(plugin)
if (type.call(plugin) === FUNCTION) plugin = plugin(instance)
if (type.call(plugin) === FUNCTION) plugin = plugin(_instance)

@@ -91,58 +137,38 @@ if (!plugin) return

Default(_instance.names, plugin.$names || emptyObject)
_use(plugin.$plugins || emptyArray)
$sink = plugin.$sink || $sink
_default(instance, plugin)
Default(_instance, plugin)
})
function getStream(inline) {
if (!streams.length) {
function _getStream(inline) {
if (!_streams.length) {
for(var i = 0; i < 2; i++){
$filters[$filters.length - i] = function(_, inline) {return inline ? {i:$sink.i, d:$sink.d, x:$sink.x} : $sink}
for (var j = $filters.length; j--;) streams[i] = $filters[j](streams[i], !!i, parsers[i])
for (var j = $filters.length; j--;) {
_streams[i] = freeze(Default(
$filters[j](_streams[i], !!i, _walkers[i]),
_streams[i]
))
}
}
}
var res = streams[inline]
var res = _streams[inline]
return res
}
function localize(name) {
if (!instance.names[name]) instance.names[name] = name + instance.suffix
return instance.names[name].match(/^\S+/)
function _localize(name) {
if (!_instance.names[name]) _instance.names[name] = name + _instance.suffix
return _instance.names[name].match(/^\S+/)
}
function localizeReplacer(match, string, global, dot, name) {
function _localizeReplacer(match, string, global, dot, name) {
if (string || global) return string || global
return dot + localize(name)
return dot + _localize(name)
}
/*/-statements-/*/
instance.sheet = function(tree) {
var emit = getStream(0)
emit.i()
sheet(
parsers[0],
emit,
'', // prefix
tree,
1, // local, by default
0 // inAtRule
)
return emit.x()
}
/*/-statements-/*/
instance.inline = function (tree) {
var emit = getStream(1)
emit.i()
declarations(
parsers[1],
emit,
'', // prefix
tree,
1 //local
)
return emit.x()
}
return instance
return _instance
}

@@ -149,0 +175,0 @@

@@ -15,7 +15,7 @@ # ./src

Regarding bugs, there's at this point a 3/1 test/code ratio, and 100% test coverage, which allows to catch a lot of possible mistakes. The RegExps are used wisely, mostly for pattern matching or for lexing. The most complex ones are built separately using a library that emulates multi-line regexps.
Regarding bugs, there's at this point a 2.5/1 test/code ratio (after .min.gzippification of both), and 100% test coverage, which allows to catch a lot of possible mistakes. The RegExps are used wisely, mostly for pattern matching or for lexing. The most complex ones are built separately using a library that emulates multi-line regexps.
But most of all, behind the raw for loops and repetitions lies a clean, functional architecture.
Including helpers, `j2c` is built around five almost pure, pattern matching (conceptually) functions that recursively walk down JS objects.
Excluding helpers, `j2c` is built around three almost pure, pattern matching (conceptually) functions that recursively walk down JS objects.

@@ -33,3 +33,3 @@ The side effects are well defined:

`main.js` contains the public API (`j2c.*` functions)
`main.js` and `extras.js` contain the public API (`j2c` and `j2c.*` functions, respectively)

@@ -36,0 +36,0 @@ `sheet.js` handles the selectors part of the tree and dispatch to `at-rules` and `declarations` when needed.

@@ -1079,2 +1079,9 @@ /*eslint-env node, mocha */

test('@keyframes with a CSS variable as name', function(){
var _j2c = j2c(), names = _j2c.names
var css = _j2c.sheet({'@keyframes var(--foo)': {}})
expect(names).not.to.have.key('var')
expect(css).to.contain('@keyframes var(--foo) {')
})
test('a global @keyframes', function() {

@@ -1115,2 +1122,9 @@ var _j2c = j2c(), names = _j2c.names

test('one animation with a CSS variable', function(){
var _j2c = j2c(), names = _j2c.names
var css = _j2c.sheet({p: {animation: 'var(--foo) 1sec'}})
expect(names).not.to.have.key('var')
expect(css).to.contain('animation:var(--foo) 1sec;')
})
test('one animation-name', function() {

@@ -1139,2 +1153,9 @@ var _j2c = j2c(), names = _j2c.names

test('one animation-name with a CSS variable', function() {
var _j2c = j2c(), names = _j2c.names
var css = _j2c.sheet({p: {animation_name: 'var(--foo)'}})
expect(names).not.to.have.key('var')
expect(css).to.contain('animation-name:var(--foo);')
})
test('a nested @global at-rule', function() {

@@ -1391,3 +1412,3 @@ var _j2c = j2c(), names = _j2c.names

J2C().use(
{names: {foo:'theFoo'}}
{$names: {foo:'theFoo'}}
).inline(

@@ -1403,3 +1424,3 @@ {animation:'foo 1sec'}

J2C().use(
{names: {foo:'theFoo'}}
{$names: {foo:'theFoo'}}
).inline(

@@ -1413,3 +1434,3 @@ {animation_name:'foo'}

test('namespaced and non-namespaced animation-name', function() {
var _J2C = J2C().use({names: {foo:'theFoo'}})
var _J2C = J2C().use({$names: {foo:'theFoo'}})
var result = _J2C.inline({animation_name:'foo, bar'})

@@ -1424,3 +1445,3 @@ check(

var result = J2C().use(
{names: {foo:'theFoo', bar:'theBar'}}
{$names: {foo:'theFoo', bar:'theBar'}}
).inline(

@@ -1442,3 +1463,3 @@ {animation:'foo 1sec, bar 2sec'}

test('namespaced class', function() {
var _J2C = J2C().use({names: {foo: 'FOOO'}}), names = _J2C.names
var _J2C = J2C().use({$names: {foo: 'FOOO'}}), names = _J2C.names
var css = _J2C.sheet(

@@ -1452,3 +1473,3 @@ {'.foo': {foo: 'bar', baz: 'qux'}}

test('namespaced class wrapping a global block', function() {
var _J2C = J2C().use({names: {foo: 'FOOO'}}), names = _J2C.names
var _J2C = J2C().use({$names: {foo: 'FOOO'}}), names = _J2C.names
var css = _J2C.sheet(

@@ -1462,3 +1483,3 @@ {'.foo': {'@global': {'.foo': {foo: 'bar', baz: 'qux'}}}}

test('namespaced @keyframes', function(){
var _J2C = J2C().use({names: {bit: 'BOT'}}), names = _J2C.names
var _J2C = J2C().use({$names: {bit: 'BOT'}}), names = _J2C.names
var css = _J2C.sheet(

@@ -1472,3 +1493,3 @@ {'@keyframes bit': {}}

test('namespaced animation', function(){
var _J2C = J2C().use({names: {bit: 'BOT'}}), names = _J2C.names
var _J2C = J2C().use({$names: {bit: 'BOT'}}), names = _J2C.names
var css = _J2C.sheet(

@@ -1482,3 +1503,3 @@ {p: {animation: 'bit 1sec'}}

test('namespaced animation-name', function() {
var _J2C = J2C().use({names: {bit: 'BOT'}}), names = _J2C.names
var _J2C = J2C().use({$names: {bit: 'BOT'}}), names = _J2C.names
var css = _J2C.sheet({p: {animation_name: 'bit'}})

@@ -1490,3 +1511,3 @@ expect(names.bit).to.be('BOT')

test("don't overwrite an existing name", function() {
var _J2C = J2C().use({names: {bit: 'BOT'}}, {names: {bit: 'BUT'}}), names = _J2C.names
var _J2C = J2C().use({$names: {bit: 'BOT'}}, {names: {bit: 'BUT'}}), names = _J2C.names
expect(names.bit).to.be('BOT')

@@ -1544,4 +1565,4 @@ })

},
S: function(selector) {
next.S('h1, ' + selector)
S: function() {
next.S()
}

@@ -1653,2 +1674,19 @@ }

test('filter default', function() {
var acc = []
check(
J2C().use({$filter: function(next) {
return {
s: function(selector){
acc.push(selector)
return next.s(selector + 're')
}
}
}}).sheet({'p': 'bar:baz;'}),
'pre{bar:baz}'
)
expect(acc.length).to.be(1)
expect(acc[0]).to.be('p')
})
////////////////////////////////////

@@ -1661,11 +1699,11 @@ /**/ suite('$at plugins') /**/

function plugin(name) {
return {$at: function(parser, emit, match, v, prefix, local, inAtRule){
return {$at: function(walker, emit, match, v, prefix, local, inAtRule){
expect(match).to.be.an(Array)
expect(parser).to.be.an(Object)
expect(parser).to.have.key('$a')
expect(parser).to.have.key('a')
expect(parser).to.have.key('d')
expect(parser).to.have.key('l')
expect(parser).to.have.key('n')
expect(parser).to.have.key('s')
expect(walker).to.be.an(Object)
expect(walker).to.have.key('$a')
expect(walker).to.have.key('a')
expect(walker).to.have.key('d')
expect(walker).to.have.key('l')
expect(walker).to.have.key('n')
expect(walker).to.have.key('r')

@@ -1700,3 +1738,3 @@ expect(emit).to.be.an(Object)

function plugin(name) {
return {$at: function(parser, emit, match, v){
return {$at: function(walker, emit, match, v){
if (match[2] !== name) return false

@@ -1718,3 +1756,3 @@ emit.a(match[1], v)

test('$at plugin has precedence over default at-rules', function() {
var plugin = {$at: function(parser, emit, match, v){
var plugin = {$at: function(walker, emit, match, v){
if (match[2] !== 'import') return false

@@ -1734,3 +1772,3 @@ emit.a('@intercepted', v)

test('$at plugin that verifies malformed rules are properly passed unparsed', function() {
var plugin = {$at: function(parser, emit, match, v){
var plugin = {$at: function(walker, emit, match, v){

@@ -1759,11 +1797,19 @@ expect(match[0]).to.be('@; hey')

// TODO
//
// - spy on String.prototype.replace and RegExp.prototype.*
// to generate coverage reports for the branches hidden
// in these native functions.
// to generate coverage reports for the branches hidden
// in these native functions.
//
// - verify that all at-rules behave properly in filters
// (wrt selectors and definitions)
// - verify that CSS variables are not localized as if they were names.
// - test `inAtRule` from $at plugins (is it set appropriately?
// - test the `parser` object from within $at and $filter plugins
// - verify that custom at rules take precedence over default ones.
// - test @keyframes nested in selector scope
// (wrt selectors and definitions)
//
// - test `inAtRule` from $at plugins (is it set appropriately?)
//
// - test the `walker` object from within $at and $filter plugins
//
// - verify that custom at rules take precedence over default ones
//
// - test @keyframes nested in selector scope
//
// - Attach new properties using `.use()`. Verify that old ones are not
// overwritten

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc