Files: 1fb3b218dfa5c8fc3b7644490d72da2d0530c123 / styles / css / fromMcss.js
1154 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 | const newCss = compile(mixinsStr + '\n' + mcssStr) |
41 | if (newCss == '') { |
42 | console.error('Some broken mcss!', { name, mcssStr, mixinsStr }) |
43 | } |
44 | return newCss |
45 | }) |
46 | } |
47 |
Built with git-ssb-web