Comments (5)
Hi @pygy
That looks interesting.. I'm a bit behind with various stuff, so I hope its ok if I first take some time to look closer and grok this later on the week?
from bss.
@porsager sure take your time :-)
from bss.
Adding some clarifications, because there are j2c specific bits in the docs.
When you are ready, start here:
The backend/filter API provides a PostCSS-like system without a need to materialize the AST. Your engine calls it like this:
backend.init()
backend.atrule('@-webkit-media', 'media', 'screen', 'rule' /*takes a block of rules*/)
backend.rule('.foo')
backend.decl('color', 'red')
backend._rule()
backend._atrule()
result = backend.done()
Which becomes with the default j2c backend the following string.
@-webkit-media screen {
.foo {
color: red;
}
}
Plugins take the form of a decorator function that takes the backend as argument and return an object with a subset of the backend method:
function autoPxPlugin(next) { // next is the backend so far
return {
decl(prop, value) {
next.decl(
prop,
needsPx(prop, value) ? value + 'px' : value
)
}
}
function needsPx(prop, value){
// left as an exercise for the reader
}
The plugins are baked in when the lib is initialized:
const plugins = [autoPxPlugin]
const backend = plugins.reduce(
(backend, plugin) => Object.assign({}, backend, plugin(backend),
sink // the bare backend
)
The err()
method allows one to display errors in context (try to add or remove a letter from an at-rule in the prefix-plugin playground), and the raw()
method inserts raw text into the buffer. Not sure how useful they would be for bss.
Here's the default j2c
sink:
let buf, err
const sink = {
init: function () {buf=[], err=[]},
done: function () {
if (err.length != 0) throw new Error('j2c error(s): ' + JSON.stringify(err,null,2) + ', in context:\n' + buf.join(''))
return buf.join('')
},
err: function (msg) {
err.push(msg)
buf.push('/* +++ ERROR +++ ' + msg + ' */\n')
},
raw: function (str) {buf.push(str, '\n')},
atrule: function (rule, kind, param, takesBlock) {
buf.push(rule, param && ' ', param, takesBlock ? ' {\n' : ';\n')
},
// close atrule
_atrule: function () {buf.push('}\n')},
rule: function (selector) {buf.push(selector, ' {\n')},
// close rule
_rule: function () {buf.push('}\n')},
decl: function (prop, value) {buf.push(prop, ':', value, ';\n')}
}
Provided you are inserting rules using insertRule()
may have to monitor the nesting level and insert when it reaches 0 when either _rule()
or _atrule()
are called (assuming it is possible for a single call to generate more than one rule).
from bss.
Hi @pygy .. Sorry for not getting back sooner.
bss already does automatic vendor prefixes and eg. px suffixing, but it is also browser only, relying on dom vendor prefix detection to do it.
I've been trying to wrap my head around this, and if I get it right implementing this would mainly be a benefit when generating actual stylesheets outside the browser for eg. SSR right?
I have some ideas for how to make SSR possible with bss, and they might fit well with the j2c backend api, but I also need to do a bit more, such as enabling the function calling style of writing css which bss provides.
I might be misunderstanding some things, so if it's easier to discuss on gitter we can also continue there ;)
from bss.
@porsager The prefix plugin is client-side only at the moment, for SSR, I have a PostCSS adapter that creates a PostCSS AST out of what you feed it, applies PostCSS plugins and walks the resulting tree to call the next
part of the backend...
I had missed the vendor prefix detection in bss... AFAICS, it only prefixes properties. The prefix plugin linked above also prefixes values (keywords, functions, properties as values (transition:
, will-change:
, ...), selectors (pseudo elements, ...), and at-rules (the rules themselves and their parameters where needed e.g. @media (min-resolution: 2dppx)
to whatever the browser supports: -webkit-min-resolution: 2
or min-resolution: 192dpi
, etc. for old Firefox and Opera). It also translates the final flexbox spec to the older variants, sometimes expanding one shortcut property to multiple ones.
I may have missed some things, the full feature list is in the readme.
For gitter, sure, the j2c channel would seem appropriate unless you have one for bss (porsager/bss returns a 404)
from bss.
Related Issues (20)
- POJO style question HOT 7
- using bss-react module just for react HOT 10
- Make shorthands a little magic HOT 13
- Allow multiline property value declarations HOT 2
- v2: Extract shorthands into helpers object
- v2: letter-spacing auto px
- Unit interpolation fails in node HOT 1
- convert fractions to percentage values HOT 6
- assign deeper HOT 3
- document how helpers can be used in lean strings HOT 1
- Simple integration width vuejs. HOT 1
- Line Height when given a unitless value doesn't return as expected HOT 3
- SVGs defined in background data urls don't work HOT 1
- Helpers defined with hyphen-case never get called HOT 1
- `$nest` and `$media` not applying style. HOT 3
- Feature Request: Built-in CSS Class Composition HOT 7
- Partial application overload for binary signature methods HOT 9
- Duplicate selector doesn't concat style. HOT 2
- Debug mode makes bugs harder to find HOT 1
- Some functions don't work on Mozilla Firefox lastest update (97.0) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bss.