git ssb

2+

mixmix / ticktack



Tree: 8ccabc90fba9a7c635b9453d773451639310d17d

Files: 8ccabc90fba9a7c635b9453d773451639310d17d / styles / css / fromMcss.js

1158 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 = nest({
9 'styles.mcss': 'reduce',
10 'styles.mixins': 'reduce'
11})
12
13exports.create = function (api) {
14 return nest('styles.css', css)
15
16 function css (sofar = {}) {
17 const mcssObj = api.styles.mcss()
18 const mixinObj = api.styles.mixins()
19
20 const mcssMixinsStr = mixinsToMcss(mixinObj)
21 const cssObj = mcssToCss(mcssObj, mcssMixinsStr)
22 return assign(sofar, cssObj)
23 }
24}
25
26function mixinsToMcss (mixinsObj) {
27 var mcss = ''
28 each(mixinsObj, (mixinStr, [name]) => {
29 // QUESTION: are mixins mcss specific or should we convert to mcss here?
30 // as in, mixins are dom style objects and we use something like `inline-style` package
31 mcss += mixinStr + '\n'
32 })
33 return mcss
34}
35
36function mcssToCss (mcssObj, mixinsStr) {
37 return map(mcssObj, (mcssStr, [name]) => {
38 const newCss = compile(mixinsStr + '\n' + mcssStr)
39 if (newCss == '') {
40 console.error('Some broken mcss!', { name, mcssStr, mixinsStr })
41 }
42 return newCss
43 })
44}
45

Built with git-ssb-web