-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Hi, @porsager I just notice this thanks to @JAForbes' tweet.
Would you mind adopting the j2c backend API? The general idea is that, rather than having your functions return strings, you pass a backend that accumulates them. So for example
export function selectorBlock(selector, style) {
return selector + '{'
+ stylesToCss((typeof style === 'string' ? stringToObject(style) : style))
+ '}'
}would become
export function selectorBlock(selector, style, backend) {
backend.rule(selector)
stylesToCss((typeof style === 'string' ? stringToObject(style) : style))
backend._rule()
}and
function propToString(style, k) {
return (vendorRegex.test(k) ? '-' : '')
+ camelCaseToHyphen(k) + ':' + style[k] + ';'
}would become
function emitDecl(style, k, backend) {
backend.decl((vendorRegex.test(k) ? '-' : '') + camelCaseToHyphen(k), style[k])
}The main advantage here is that it allows one to write plugins that decorate the backend, like this prefixing plugin that no one uses currently because I've yet to publish j2c v1 that uses the same architecture.
The prefix plugin supports more than one prefix per browser (FF and Edge have some properties that are exclusively available with a webkit prefix), is IIRC 3KB mingzipped and uses feature detection rather than a list of properties/selectors, etc... like autoprefixer and the inline style prefixer.
The architecture makes it trivial to turn one rule into many (e.g. flex-direction => -webkit-box-direction + -webkit-box-orient) without causing the allocation of extra objects.
Edit I can't English tonight...
Edit2: here's the full feature list: https://github.com/j2css/j2c/tree/3039875258bd69f04a16c51b69ca71361b5d5560/plugins/prefix-browser#features