-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort.js
120 lines (116 loc) · 2.46 KB
/
sort.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// TODO: variants
export const variants = ['hover'].map((v) => `(${v}:)?`).join('');
export let order = [
'container',
'position',
'zIndex',
{ name: 'display', overrides: [{ rule: 'hidden', place: ['before', 'block'] }] },
'visibility',
'pointerEvents',
{ name: 'flexDirection', overrides: [{ rule: 'flex-col', place: ['before', 'flex-row'] }] },
'flexWrap',
'flexGrow',
'flexShrink',
'gridAutoFlow',
'gridTemplateColumns',
'gridAutoColumns',
'gridColumn',
'gridColumnStart',
'gridColumnEnd',
'gridTemplateRows',
'gridAutoRows',
'gridRow',
'gridRowStart',
'gridRowEnd',
'order',
'justifyContent',
'justifyItems',
'justifySelf',
'alignContent',
'alignItems',
'alignSelf',
'placeContent',
'placeItems',
'placeSelf',
'objectFit',
'objectPosition',
'overflow',
'overscrollBehavior',
'inset',
'width',
'minWidth',
'maxWidth',
'height',
'minHeight',
'maxHeight',
'cursor',
'textAlign',
'verticalAlign',
'listStyleType',
'textTransform',
'fontStyle',
'textDecoration',
'fontWeight',
'fontSize',
'textColor',
'textOpacity',
'letterSpacing',
'lineHeight',
'textOverflow',
'whitespace',
'wordBreak',
'placeholderColor',
'placeholderOpacity',
'backgroundPosition',
'backgroundRepeat',
'backgroundSize',
'backgroundColor',
'backgroundOpacity',
'backgroundImage',
'gradientColorStops',
'backgroundAttachment',
'backgroundBlendMode',
'backgroundClip',
'opacity',
'boxShadow',
'borderStyle',
'borderWidth',
'borderColor',
'borderOpacity',
'borderRadius',
'borderCollapse',
'outline',
'ringWidth',
'ringOpacity',
'ringOffsetWidth',
'transform',
'transformOrigin',
'scale',
'rotate',
'translate',
'skew',
'transitionProperty',
'transitionDuration',
'transitionDelay',
'transitionTimingFunction',
'animation',
'boxSizing',
'padding',
'space',
'gap',
'margin',
];
// TODO: Add an option to disable inserting breakpoints.
export function sortClasses(classnames, byClassname) {
// Remove unwanted repeated spaces:
classnames = classnames.replace(/\s+/g, ' ');
const leadingSpace = classnames[0] === ' ';
const trailingSpace = classnames[classnames.length - 1] === ' ';
const sorted = classnames
.split(' ')
.sort((a, b) => byClassname[a] - byClassname[b])
.join(' ')
.trim();
// Make sure leading or trailing spaces are preserved.
return `${leadingSpace ? ' ' : ''}${sorted}${trailingSpace ? ' ' : ''}`;
}