git ssb

2+

mixmix / ticktack



Tree: 35ee32eefff5c36f236876e4918c46cbeb22ef6d

Files: 35ee32eefff5c36f236876e4918c46cbeb22ef6d / styles / css / fromMcss.js

1154 bytesRaw
1const nest = require('depnest')
2const { each, map } = require('libnested')
3const compile = require('micro-css')
4const { assign } = Object
5
6exports.gives = nest('styles.css')
7
8exports.needs = {
9 styles: {
10 mcss: 'reduce',
11 mixins: 'reduce'
12 }
13}
14
15exports.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
28function 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
38function 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