Files: f7dff5dea73ce76928756982a627d93d49cb1968 / styles / css.js
1027 bytesRaw
1 | const nest = require('depnest') |
2 | const { each, map } = require('libnested') |
3 | const compile = require('micro-css') |
4 | const { assign } = Object |
5 | |
6 | exports.gives = nest('styles.css') |
7 | |
8 | exports.needs = { |
9 | styles: { |
10 | mcss: 'reduce', |
11 | mixins: 'reduce' |
12 | } |
13 | } |
14 | |
15 | exports.create = function (api) { |
16 | return nest('styles.css', css) |
17 | |
18 | function css (sofar = {}) { |
19 | const mcssObj = api.styles.mcss() |
20 | const mixinObj = api.styles.mixins() |
21 | |
22 | const mcssMixinsStr = mixinsToMcss(mixinObj) |
23 | const cssObj = mcssToCss(mcssObj, mcssMixinsStr) |
24 | return assign(sofar, cssObj) |
25 | } |
26 | } |
27 | |
28 | function mixinsToMcss (mixinsObj) { |
29 | var mcss = '' |
30 | each(mixinsObj, (mixinStr, [name]) => { |
31 | // QUESTION: are mixins mcss specific or should we convert to mcss here? |
32 | // as in, mixins are dom style objects and we use something like `inline-style` package |
33 | mcss += mixinStr + '\n' |
34 | }) |
35 | return mcss |
36 | } |
37 | |
38 | function mcssToCss (mcssObj, mixinsStr) { |
39 | return map(mcssObj, (mcssStr, [name]) => { |
40 | return compile(mixinsStr + '\n' + mcssStr) |
41 | }) |
42 | } |
43 |
Built with git-ssb-web