conceptually, s4c(elementName, sheet)
would call j2c.sheet({'.PLACEHOLDER': sheet})
I have a filter plugin that I put at the start of the backend, and that incrementally hashes the sheet as it is built and buffers what it was passed to in an array.
If the hash is not known, call the rest of the backend with what was buffered, replacing the PLACEHOLDER class with the hash. The rest of the backend applies the prefixes and other tricks, and the sink inserts the rules in a stylesheet.
s4c
returns a component, the sheet is created and hashed when the element is initialized. If the sheet has functions (for attrs/props-based customization), it is recreated before updates.
I'll need some help for the v1 docs. The general API is
const j2c = new J2c(options)
const cssText = j2c.sheet({'.foo': {color: 'red'}})
j2c.names.foo // "random_prefix_1_foo"
const otherCssText = j2c.sheet({'.bar': {color: 'red'}})
j2c.names.bar // "random_prefix_1_bar"
// shares all the options of the first instance except the prefix and `names` dict
const otherInstance = j2c.ns()
Object.keys(otherInstance.names).length // 0
const cssText = otherInstance.sheet({'.foo': {color: 'red'}})
otherInstance.names.foo // "random_prefix_2_foo"
The idea is that the initial setup (new J2c(options)
) is potentially costly (creation of many closures to generate the various parts of the processors with the plugin calls inlined). in order to get better perf out of the result.
The advice I'm seeking would be how to name local instance with their own prefix... J2c
/j2c
seems Ok for the constructor and main instance...
.ns()
for a given length, or by passing a string to be used as prefix (BEM-style).
@ArthurClemens the next docs already have more about at-rules actually:
All standard CSS at-rules are available out of the box, most importantly:
@media
and@supports
, which can be nested anywhere in the sheet, SASS-style.@keyframes
@font-face
position: fixed
...
.mjs
, this combination works for both.
module
should have pointed to main.js
that only exports the public function, the other exports in plugin.js
are meant for testing IIRC
mjs
mandatory for modules with Webpack 4?