fix attribute
[roojs1] / buildSDK / cssminiX.js
1 /**
2  * YUI Compressor
3  * Author: Julien Lecomte <jlecomte@yahoo-inc.com>
4  * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
5  * Code licensed under the BSD License:
6  *     http://developer.yahoo.net/yui/license.txt
7  *
8  * This code is a port of Isaac Schlueter's cssmin utility.
9  
10  <script type="text/javascript">
11  */ 
12   
13   
14 // let's see if this works..
15 // should be run from top level..
16
17 var pa = File.getcwd();
18 //println(pack(File.read(pa+'/css/basic-dialog.css')));
19  
20 File.write(pa+'/cssX/roojs.css',
21     
22     pack(File.read(pa+'/cssX/reset-min.css'))+"\n"+
23     pack(File.read(pa+'/cssX/core.css'))+"\n"+
24     pack(File.read(pa+'/cssX/tabs.css'))+"\n"+
25     pack(File.read(pa+'/cssX/form.css'))+"\n"+
26     pack(File.read(pa+'/cssX/button.css')) +"\n"+
27     pack(File.read(pa+'/cssX/toolbar.css'))+"\n"+
28     pack(File.read(pa+'/cssX/resizable.css'))+"\n"+
29     pack(File.read(pa+'/cssX/grid.css'))+"\n"+
30     pack(File.read(pa+'/cssX/layout.css'))+"\n"+
31     pack(File.read(pa+'/cssX/basic-dialog.css'))+"\n"+
32     pack(File.read(pa+'/cssX/dd.css'))+"\n"+
33     pack(File.read(pa+'/cssX/tree.css'))+"\n" +
34     pack(File.read(pa+'/cssX/qtips.css'))+"\n"+
35     pack(File.read(pa+'/cssX/date-picker.css')) +"\n"+
36     pack(File.read(pa+'/cssX/menu.css')) +"\n"+
37     pack(File.read(pa+'/cssX/box.css')) +"\n"+
38     pack(File.read(pa+'/cssX/combo.css')) +"\n"+
39     pack(File.read(pa+'/cssX/editor.css'))+"\n"
40     
41   
42     
43     
44 );
45 println("written cssX/roojs.css");
46 // and the themese...
47 //ytheme-aero.css
48 //ytheme-gray.css
49 //ytheme-vista.css
50
51   
52   
53   
54   
55   
56         // string manip!?
57 function pack(istr) {
58     
59         
60         function removeComments(str)
61         {
62             var r = ''; //ret
63             var si =0;
64             var  iemac = false;
65             
66             while ((si = str.indexOf("/*")) > -1) {
67                 ei = str.indexOf("*/");
68                  
69                 
70                 if (ei >= si + 2) {
71                     if (str.charAt(ei-1) == '\\') {   // eg. /* \*/
72                         si = ei+2;
73                         iemac = true;
74                         // Looks like a comment to hide rules from IE Mac.
75                         // Leave this comment, and the following one, alone...
76                         // shunt:
77                         
78                         r += str.substring(0, ei) ;
79                         str = str.substring(ei);
80                         continue;
81                     }
82                     if (iemac) {
83                         si = ei + 2;
84                         iemac = false;    
85                         r += str.substring(0, ei) ;
86                         str = str.substring(ei+2);
87                         continue;
88                     }
89                     
90                     r += str.substring(0, si) ;
91                     str = str.substring(ei+2);
92                     continue;
93                 }
94                 // did not find end..
95                 r += str.substring(0, 2);
96                 str = str.substring(2);
97                     
98                     
99             }
100                 r += str;
101             return r;
102         }
103         
104         istr = removeComments(istr);
105         //println("after comments remove: " + istr);
106         
107         // Normalize all whitespace strings to single spaces. Easier to work with that way.
108         istr = istr.replace(/\s+/g, ' ');
109
110         // Make a pseudo class for the Box Model Hack ????
111         //css = css.replaceAll("\"\\\\\"}\\\\\"\"", "___PSEUDOCLASSBMH___");
112         istr = istr.replace(/"\\"\}\\"/g, "___PSEUDOCLASSBMH___");
113
114         // Remove the spaces before the things that should not have spaces before them.
115         // But, be careful not to turn "p :link {...}" into "p:link{...}"
116         // Swap out any pseudo-class colons with the token, and then swap back.
117         
118         istr = istr.replace(/(^|\})(([^\{:])+:)+([^\{]*\{)/g, function(m) {
119             return m.replace(/:/g, "___PSEUDOCLASSCOLON___");
120         });
121         
122         
123         istr = istr.replace(/\s+([!{};:>+\(\)\],])/g, "$1");
124         istr = istr.replace(/___PSEUDOCLASSCOLON___/g, ":");
125
126         // Remove the spaces after the things that should not have spaces after them.
127         istr = istr.replace(/([!{}:;>+\(\[,])\s+/g, "$1");
128
129         // Add the semicolon where it's missing.
130         istr = istr.replace(/([^;\}])\}/g, "$1;}");
131
132         // Replace 0(px,em,%) with 0.
133         istr = istr.replace(/([\s:])(0)(px|em|%|in|cm|mm|pc|pt|ex)/g, "$1$2");
134
135         // Replace 0 0 0 0; with 0. (by this time, we have reduced spaces etc..
136         istr = istr.replace(/:0 0 0 0;/g, ":0;");
137         istr = istr.replace(/:0 0 0;/g, ":0;");
138         istr = istr.replace(/:0 0;/g, ":0;");
139         // Replace background-position:0; with background-position:0 0;
140         istr = istr.replace(/background-position:0;/g, "background-position:0 0;");
141
142         // Replace 0.6 to .6, but only when preceded by : or a white-space
143         istr = istr.replace(/(:|\s)0+\.(\d+)/g, "$1.$2");
144
145         // Shorten colors from rgb(51,102,153) to #336699
146         // This makes it more likely that it'll get further compressed in the next step.
147         
148         istr = istr.replace(/rgb\s*\(\s*([0-9,\s]+)\s*\)/g, function(m, c)
149             {
150                 var rgb = c.split(',');
151                 var hx = '';
152                 for (var  i = 0; i < rgb.length; i++) {
153                     var val = parseInt(rgb[i]);
154                     if (val < 16) {
155                         hx+="0";
156                     }
157                     hx+=val.toString(16);
158                     
159                 }
160                 return '#' + hx;
161             });
162         
163          
164
165         // Shorten colors from #AABBCC to #ABC. Note that we want to make sure
166         // the color is not preceded by either ", " or =. Indeed, the property
167         //     filter: chroma(color="#FFFFFF");
168         // would become
169         //     filter: chroma(color="#FFF");
170         // which makes the filter break in IE.
171         
172         istr = istr.replace(/([^"'=\s])(\s*)#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])/g, 
173                 function(m, g1,g2,g3,g4,g5,g6,g7,g8) {
174                     
175                      
176                         
177                         if (g3.toLowerCase() == g4.toLowerCase() &&
178                             g5.toLowerCase() == g6.toLowerCase() &&
179                             g7.toLowerCase() == g8.toLowerCase()) {
180                                 
181                                 return g1+g2+'#' + g3+g5+g7;
182                         }
183                      
184                    
185                     return m;
186                     
187                 });
188          
189         // Remove empty rules.
190         istr = istr.replace(/[^\}]+\{;\}/g, "");
191 /*
192         if (linebreakpos >= 0) {
193             // Some source control tools don't like it when files containing lines longer
194             // than, say 8000 characters, are checked in. The linebreak option is used in
195             // that case to split long lines after a specific column.
196             int i = 0;
197             int linestartpos = 0;
198             sb = new StringBuffer(css);
199             while (i < sb.length()) {
200                 char c = sb.charAt(i++);
201                 if (c == '}' && i - linestartpos > linebreakpos) {
202                     sb.insert(i, '\n');
203                     linestartpos = i;
204                 }
205             }
206
207             css = sb.toString();
208         }
209 */
210         // Replace the pseudo class for the Box Model Hack
211         istr = istr.replace(/___PSEUDOCLASSBMH___/g, "\"\\\\\"}\\\\\"\"");
212
213         // Trim the final string (for any leading or trailing white spaces)
214         istr = istr.replace(/^\s+/g, '');
215         istr = istr.replace(/\s+$/g, '');
216
217
218         // Write the output...
219         return istr;
220 }