1
1
<?php
2
2
3
- // Grab contents of css file
4
- // $file = file_get_contents(' tailwind.css');
5
- $ file = file_get_contents ( ' tailwind-ui.css ' );
3
+ // Get latest versions of these two files from
4
+ // https://unpkg.com/tailwindcss@%5E1.0/dist/ tailwind.css
5
+ // https://cdn.jsdelivr.net/npm/@tailwindcss/ui@latest/dist/ tailwind-ui.css
6
6
7
- // Strip comments
8
- $ pattern = '!/\*[^*]*\*+([^/][^*]*\*+)*/! ' ;
9
- $ stripped = preg_replace ($ pattern , '' , $ file );
7
+ $ classes ['tailwind.css ' ] = extractClasses (file_get_contents ('tailwind.css ' ));
8
+ $ classes ['tailwind-ui.css ' ] = extractClasses (file_get_contents ('tailwind-ui.css ' ));
10
9
11
- // Strip out everything between { and }
12
- $ pattern = '/(?<=\{)(.*?)(?=\})/s ' ;
13
- $ stripped = preg_replace ($ pattern , '' , $ stripped );
10
+ function extractClasses ($ file )
11
+ {
12
+ // Strip comments
13
+ $ pattern = '!/\*[^*]*\*+([^/][^*]*\*+)*/! ' ;
14
+ $ stripped = preg_replace ($ pattern , '' , $ file );
14
15
15
- // Remove double line breaks
16
- $ stripped = str_replace ("\n\n" , "\n" , $ stripped );
16
+ // Strip out everything between { and }
17
+ $ pattern = '/(?<=\{)(.*?)(?=\})/s ' ;
18
+ $ stripped = preg_replace ($ pattern , '' , $ stripped );
17
19
18
- // Convert every line to array
19
- $ classes = explode ( "\n" , $ stripped );
20
+ // Remove double line breaks
21
+ $ stripped = str_replace ( "\n\n" , "\n" , $ stripped );
20
22
21
- $ keepers = [];
23
+ // Convert every line to array
24
+ $ classes = explode ("\n" , $ stripped );
22
25
23
- for ($ i = 0 ; $ i < count ($ classes ); $ i ++) {
24
- $ match = trim ($ classes [$ i ]);
26
+ $ keepers = [];
25
27
26
- $ match = stripslashes ($ match );
28
+ for ($ i = 0 ; $ i < count ($ classes ); $ i ++) {
29
+ $ match = trim ($ classes [$ i ]);
27
30
28
- $ excludeThesePrefixes = [
29
- '.sm: ' ,
30
- '.md: ' ,
31
- '.lg: ' ,
32
- '.xl: ' ,
31
+ $ match = stripslashes ($ match );
33
32
34
- '.form ' ,
33
+ $ excludeThesePrefixes = [
34
+ '.sm: ' ,
35
+ '.md: ' ,
36
+ '.lg: ' ,
37
+ '.xl: ' ,
35
38
36
- '.group:hover ' ,
37
- '.group:focus ' ,
38
- ];
39
+ '.form ' ,
39
40
40
- if ( substr ( $ match , 0 , 1 ) !== ' . ' ) {
41
- continue ;
42
- }
41
+ ' .group:hover ' ,
42
+ ' .group:focus ' ,
43
+ ];
43
44
44
- foreach ($ excludeThesePrefixes as $ exclude ) {
45
- if (strpos ($ match , $ exclude ) === 0 ) {
46
- continue 2 ;
45
+ if (substr ($ match , 0 , 1 ) !== '. ' ) {
46
+ continue ;
47
+ }
48
+
49
+ foreach ($ excludeThesePrefixes as $ exclude ) {
50
+ if (strpos ($ match , $ exclude ) === 0 ) {
51
+ continue 2 ;
52
+ }
47
53
}
48
- }
49
54
50
- $ stripThese = [
51
- '. ' ,
52
- ' {} ' ,
53
- ':focus:-ms-input-placeholder ' ,
54
- ':focus::-ms-input-placeholder ' ,
55
- ':focus::placeholder ' ,
56
- '::placeholder ' ,
57
- '::-ms-input-placeholder ' ,
58
- ':-ms-input-placeholder ' ,
59
- '::-moz-placeholder ' ,
60
- '::-webkit-input-placeholder ' ,
61
- ':focus-within ' ,
62
- ':focus ' ,
63
- ];
64
-
65
- foreach ($ stripThese as $ strip ) {
66
- $ match = str_replace ($ strip , '' , $ match );
55
+ $ stripThese = [
56
+ '. ' ,
57
+ ' {} ' ,
58
+ ':focus:-ms-input-placeholder ' ,
59
+ ':focus::-ms-input-placeholder ' ,
60
+ ':focus::placeholder ' ,
61
+ '::placeholder ' ,
62
+ '::-ms-input-placeholder ' ,
63
+ ':-ms-input-placeholder ' ,
64
+ '::-moz-placeholder ' ,
65
+ '::-webkit-input-placeholder ' ,
66
+ ':focus-within ' ,
67
+ ':focus ' ,
68
+ ':hover ' ,
69
+ ' > :not(template) ~ :not(template) ' ,
70
+ ];
71
+
72
+ foreach ($ stripThese as $ strip ) {
73
+ $ match = str_replace ($ strip , '' , $ match );
74
+ }
75
+
76
+ $ keepers [] = sprintf (' \'%s \', ' , $ match );
67
77
}
68
78
69
- $ keepers [] = sprintf ( ' \' %s \' , ' , $ match ) ;
79
+ return $ keepers ;
70
80
}
71
81
82
+ $ keepers = array_merge ($ classes ['tailwind.css ' ], $ classes ['tailwind-ui.css ' ]);
83
+
84
+ sort ($ keepers );
85
+
72
86
$ file = '
73
87
export default {
74
88
data() {
@@ -81,4 +95,4 @@ classes: [
81
95
};
82
96
' ;
83
97
84
- file_put_contents ('tailwind-classes.js ' , $ file );
98
+ file_put_contents ('src/views/ tailwind-classes.js ' , $ file );
0 commit comments