-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcss.js
43 lines (32 loc) · 1.08 KB
/
css.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { tw } from 'twind';
function bem(block, els) {
let ret = {};
for (let [k, v] of Object.entries(els)) {
Object.defineProperty(ret, k, {
get: () => {
let fn = (...args) => {
if (typeof v === 'function') { v = v(...args || []) }
let ret = [[block, k !== 'root' && k].filter(Boolean).join('-'), ...tw(v).split(/\s/)];
let override = (ret.overrides || {})[k];
if (override) {
if (typeof override === 'function') { override = override(...args || []) }
override = override.trim().split(/\s/).map(x => x.trim()).filter(Boolean);;
for (let x of override) {
let neg = x.startsWith('-');
let atom = x.split('-')[neg ? 1 : 0];
console.log(atom);
ret = ret.filter(y => !y.startsWith(atom));
if (!neg) { ret.push(tw(x)) }
}
console.log(ret);
}
return ret.join(' ');
};
fn.toString = () => fn();
return fn;
},
});
}
return ret;
}
export { bem, tw };