This repository has been archived by the owner on Feb 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
82 lines (69 loc) · 1.98 KB
/
index.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const { plugin } = require('postcss');
const { ratios, makeBreakpointsMap } = require('@typographist/core');
const { isStep, step } = require('./features/step');
const { isStepFunction, stepFunction } = require('./features/step-function');
const { isBubblingRule, bubblingRule } = require('./features/bubbling-rule');
const { isNestedRule, nestedRule } = require('./features/nested-rule');
const {
isBubblingAtrule,
bubblingAtrule,
} = require('./features/bubbling-atrule');
const { renderUp } = require('./features/up');
const { renderBase } = require('./features/base');
const { renderDown } = require('./features/down');
const { renderBetween } = require('./features/between');
const { renderOnly } = require('./features/only');
const { renderRoot } = require('./features/root');
const defaultConfig = {
base: '16px',
lineHeight: 1.5,
ratio: 1.333,
};
const typographist = plugin(
'typographist',
(config = defaultConfig) => (root) => {
const breakpointsMap = makeBreakpointsMap(config);
root.walkDecls((decl) => {
if (isStep(decl)) {
step(decl, breakpointsMap);
}
if (isStepFunction(decl, breakpointsMap)) {
stepFunction(decl, breakpointsMap);
}
});
root.walkAtRules((atrule) => {
if (isBubblingAtrule(atrule)) {
bubblingAtrule(atrule);
}
});
root.walkAtRules((atrule) => {
const atrules = {
root: renderRoot,
base: renderBase,
up: renderUp,
down: renderDown,
only: renderOnly,
between: renderBetween,
};
if (atrules[atrule.name]) {
atrules[atrule.name](atrule, breakpointsMap);
}
});
root.walkRules((rule) => {
if (isBubblingRule(rule)) {
bubblingRule(rule);
}
if (isNestedRule(rule)) {
nestedRule(rule);
}
});
// Remove empty rules.
root.walkRules((rule) => {
if (!rule.nodes.length) rule.remove();
});
},
);
module.exports = {
ratios,
typographist,
};