-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostcss-pure-grid.js
66 lines (52 loc) · 2.18 KB
/
postcss-pure-grid.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
import postcss from 'postcss';
export default postcss.plugin('postcss-pure-grid', (opts) => {
var calculateWidth = (column, maxcolumns) => {
let width = ((100 / maxcolumns) * column);
if (Number(width) === width && width % 1 === 0) {
return width;
} else {
return width.toFixed(4);
}
};
var value = /\s*(\d+)\s*\/\s*(\d+)\s*/;
return (css) => {
css.walkDecls(/^pure-grid-offset/, (decl) => {
var match;
if (match = value.exec(decl.value)) {
var column = match[1];
var maxcolumns = match[2];
decl.parent.append({prop: 'margin-left', value: calculateWidth(column, maxcolumns) + '%'});
decl.remove();
} else {
throw decl.error('Invalid declaration', { plugin: 'postcss-pure-grid' });
}
});
css.walkDecls(/^pure-grid-unit/, (decl) => {
var match;
if (match = value.exec(decl.value)) {
var column = match[1];
var maxcolumns = match[2];
decl.parent.append({prop: 'display', value: 'inline-block'});
decl.parent.append({prop: 'zoom', value: '1'});
decl.parent.append({prop: 'letter-spacing', value: 'normal'});
decl.parent.append({prop: 'word-spacing', value: 'normal'});
decl.parent.append({prop: 'vertical-align', value: 'top'});
decl.parent.append({prop: 'text-rendering', value: 'auto'});
decl.parent.append({prop: 'float', value: 'left'});
decl.parent.append({prop: 'width', value: calculateWidth(column, maxcolumns) + '%'});
decl.remove();
} else {
throw decl.error('Invalid declaration', { plugin: 'postcss-pure-grid' });
}
});
css.walkDecls(/^pure-grid-group/, (decl) => {
decl.parent.append({prop: 'letter-spacing', value: '-0.31em'});
decl.parent.append({prop: 'text-rendering', value: 'optimizespeed'});
decl.parent.append({prop: 'font-family', value: 'FreeSans, Arimo, "Droid Sans", Helvetica, Arial, sans-serif'});
decl.parent.append({prop: 'display', value: 'flex'});
decl.parent.append({prop: 'flex-flow', value: decl.value});
decl.parent.append({prop: 'align-content', value: 'flex-start'});
decl.remove();
});
}
});