MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / minifyCss

Function minifyCss

dashboard/build.shared.mjs:288–328  ·  view source on GitHub ↗
(css)

Source from the content-addressed store, hash-verified

286 * around `{}:;,>`, fold `;}`), and `@layer a, b, c;` ordering is preserved.
287 */
288export function minifyCss(css) {
289 let out = "";
290 let buffer = "";
291 let i = 0;
292 const flush = () => {
293 if (buffer) {
294 out += collapseCssWhitespace(buffer);
295 buffer = "";
296 }
297 };
298 while (i < css.length) {
299 const ch = css[i];
300 if (ch === "/" && css[i + 1] === "*") {
301 const end = css.indexOf("*/", i + 2);
302 i = end === -1 ? css.length : end + 2;
303 continue;
304 }
305 if (ch === '"' || ch === "'") {
306 flush();
307 const end = skipCssString(css, i);
308 out += css.slice(i, end);
309 i = end;
310 continue;
311 }
312 if (
313 (ch === "u" || ch === "U") &&
314 (i === 0 || !/[\w-]/.test(css[i - 1])) &&
315 /^url\(/i.test(css.slice(i, i + 4))
316 ) {
317 flush();
318 const end = skipCssUrl(css, i);
319 out += css.slice(i, end);
320 i = end;
321 continue;
322 }
323 buffer += ch;
324 i++;
325 }
326 flush();
327 return out.trim();
328}
329
330function collapseCssWhitespace(segment) {
331 return segment

Callers 3

build-css.test.mjsFile · 0.90
compileTailwindCssFunction · 0.85

Calls 4

flushFunction · 0.85
skipCssStringFunction · 0.85
skipCssUrlFunction · 0.85
testMethod · 0.80

Tested by

no test coverage detected