UNPKG

siphon-cli

Version:

Simple bundler for web applications. 📦🔧🧡

55 lines (54 loc) • 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var types_1 = require("../../../types"); function minify(ast) { var minified = ""; ast.rules.forEach(function (rule) { if (rule instanceof types_1.StyleRule) { var selectors = rule.selectors.join(","); if (!/'|"/.test(selectors)) selectors = selectors.replace(/([\s]*)\>([\s]*)/g, ">"); minified += "".concat(selectors, "{"); var entries_1 = Object.entries(rule.notation); entries_1.forEach(function (entry, index) { minified += "".concat(entry[0], ":").concat(entry[1].replace(/(\n|\r)+[\s]*/g, "")) + (index === entries_1.length - 1 ? "" : ";"); }); minified += "}"; } else if (rule instanceof types_1.MediaRule) { minified += "@media" + (rule.params.startsWith("(") ? rule.params : " " + rule.params) + "{"; minified += minify(rule) + "}"; } else if (rule instanceof types_1.FontFaceRule) { minified += "@font-face{font-family:".concat(rule.family, ";src:").concat(rule.source, "}"); } else if (rule instanceof types_1.ImportRule) { minified += "@import\"".concat(rule.href, "\";"); } else if (rule instanceof types_1.KeyframeRule) { minified += "@keyframes ".concat(rule.identifier, "{"); rule.frames.forEach(function (frame) { minified += "".concat(frame.mark.replace(/(\n|\r)+[\s]*/g, ""), "{"); var entries = Object.entries(frame.notation); entries.forEach(function (entry, index) { minified += "".concat(entry[0], ":").concat(entry[1]) + (index === entries.length - 1 ? "" : ";"); }); minified += "}"; }); minified += "}"; } else if (rule instanceof types_1.SupportRule) { minified += "@supports".concat(rule.inverseQuery ? " not" : "", "(").concat(rule.query, "){"); minified += "".concat(minify(rule), "}"); } }); return minified; } exports.default = minify;