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
8 * This code is a port of Isaac Schlueter's cssmin utility.
10 <script type="text/javascript">
14 // let's see if this works..
15 // should be run from top level..
17 var pa = File.getcwd();
18 //println(pack(File.read(pa+'/css/basic-dialog.css')));
20 File.write(pa+'/css/roojs.css',
22 pack(File.read(pa+'/css/reset-min.css'))+"\n"+
23 pack(File.read(pa+'/css/core.css'))+"\n"+
24 pack(File.read(pa+'/css/tabs.css'))+"\n"+
25 pack(File.read(pa+'/css/form.css'))+"\n"+
26 pack(File.read(pa+'/css/button.css')) +"\n"+
27 pack(File.read(pa+'/css/toolbar.css'))+"\n"+
28 pack(File.read(pa+'/css/resizable.css'))+"\n"+
29 pack(File.read(pa+'/css/grid.css'))+"\n"+
30 pack(File.read(pa+'/css/layout.css'))+"\n"+
31 pack(File.read(pa+'/css/basic-dialog.css'))+"\n"+
32 pack(File.read(pa+'/css/dd.css'))+"\n"+
33 pack(File.read(pa+'/css/tree.css'))+"\n" +
34 pack(File.read(pa+'/css/qtips.css'))+"\n"+
35 pack(File.read(pa+'/css/date.css')) +"\n"+
36 //pack(File.read(pa+'/css/menu.css')) +"\n"+
37 //pack(File.read(pa+'/css/box.css')) +"\n"+
38 pack(File.read(pa+'/css/combo.css')) +"\n"+
40 pack(File.read(pa+'/css/inline-editor.css'))+"\n"
46 println("written css/roojs.css");
61 function removeComments(str)
67 while ((si = str.indexOf("/*")) > -1) {
68 ei = str.indexOf("*/");
72 if (str.charAt(ei-1) == '\\') { // eg. /* \*/
75 // Looks like a comment to hide rules from IE Mac.
76 // Leave this comment, and the following one, alone...
79 r += str.substring(0, ei) ;
80 str = str.substring(ei);
86 r += str.substring(0, ei) ;
87 str = str.substring(ei+2);
91 r += str.substring(0, si) ;
92 str = str.substring(ei+2);
96 r += str.substring(0, 2);
97 str = str.substring(2);
105 istr = removeComments(istr);
106 //println("after comments remove: " + istr);
108 // Normalize all whitespace strings to single spaces. Easier to work with that way.
109 istr = istr.replace(/\s+/g, ' ');
111 // Make a pseudo class for the Box Model Hack ????
112 //css = css.replaceAll("\"\\\\\"}\\\\\"\"", "___PSEUDOCLASSBMH___");
113 istr = istr.replace(/"\\"\}\\"/g, "___PSEUDOCLASSBMH___");
115 // Remove the spaces before the things that should not have spaces before them.
116 // But, be careful not to turn "p :link {...}" into "p:link{...}"
117 // Swap out any pseudo-class colons with the token, and then swap back.
119 istr = istr.replace(/(^|\})(([^\{:])+:)+([^\{]*\{)/g, function(m) {
120 return m.replace(/:/g, "___PSEUDOCLASSCOLON___");
124 istr = istr.replace(/\s+([!{};:>+\(\)\],])/g, "$1");
125 istr = istr.replace(/___PSEUDOCLASSCOLON___/g, ":");
127 // Remove the spaces after the things that should not have spaces after them.
128 istr = istr.replace(/([!{}:;>+\(\[,])\s+/g, "$1");
130 // Add the semicolon where it's missing.
131 istr = istr.replace(/([^;\}])\}/g, "$1;}");
133 // Replace 0(px,em,%) with 0.
134 istr = istr.replace(/([\s:])(0)(px|em|%|in|cm|mm|pc|pt|ex)/g, "$1$2");
136 // Replace 0 0 0 0; with 0. (by this time, we have reduced spaces etc..
137 istr = istr.replace(/:0 0 0 0;/g, ":0;");
138 istr = istr.replace(/:0 0 0;/g, ":0;");
139 istr = istr.replace(/:0 0;/g, ":0;");
140 // Replace background-position:0; with background-position:0 0;
141 istr = istr.replace(/background-position:0;/g, "background-position:0 0;");
143 // Replace 0.6 to .6, but only when preceded by : or a white-space
144 istr = istr.replace(/(:|\s)0+\.(\d+)/g, "$1.$2");
146 // Shorten colors from rgb(51,102,153) to #336699
147 // This makes it more likely that it'll get further compressed in the next step.
149 istr = istr.replace(/rgb\s*\(\s*([0-9,\s]+)\s*\)/g, function(m, c)
151 var rgb = c.split(',');
153 for (var i = 0; i < rgb.length; i++) {
154 var val = parseInt(rgb[i]);
158 hx+=val.toString(16);
166 // Shorten colors from #AABBCC to #ABC. Note that we want to make sure
167 // the color is not preceded by either ", " or =. Indeed, the property
168 // filter: chroma(color="#FFFFFF");
170 // filter: chroma(color="#FFF");
171 // which makes the filter break in IE.
173 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,
174 function(m, g1,g2,g3,g4,g5,g6,g7,g8) {
178 if (g3.toLowerCase() == g4.toLowerCase() &&
179 g5.toLowerCase() == g6.toLowerCase() &&
180 g7.toLowerCase() == g8.toLowerCase()) {
182 return g1+g2+'#' + g3+g5+g7;
190 // Remove empty rules.
191 istr = istr.replace(/[^\}]+\{;\}/g, "");
193 if (linebreakpos >= 0) {
194 // Some source control tools don't like it when files containing lines longer
195 // than, say 8000 characters, are checked in. The linebreak option is used in
196 // that case to split long lines after a specific column.
198 int linestartpos = 0;
199 sb = new StringBuffer(css);
200 while (i < sb.length()) {
201 char c = sb.charAt(i++);
202 if (c == '}' && i - linestartpos > linebreakpos) {
211 // Replace the pseudo class for the Box Model Hack
212 istr = istr.replace(/___PSEUDOCLASSBMH___/g, "\"\\\\\"}\\\\\"\"");
214 // Trim the final string (for any leading or trailing white spaces)
215 istr = istr.replace(/^\s+/g, '');
216 istr = istr.replace(/\s+$/g, '');
219 // Write the output...