UNPKG

siphon-cli

Version:

Simple bundler for web applications. 📦🔧🧡

63 lines (62 loc) • 2.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.format = void 0; var types_1 = require("../../../types"); function format(ast, indent, subIndent) { if (indent === void 0) { indent = ""; } if (subIndent === void 0) { subIndent = " "; } var formatted = ""; ast.rules.forEach(function (rule) { if (rule instanceof types_1.StyleRule) { if (rule.selectors.length > 1) formatted += indent + rule.selectors.join(",\n".concat(indent)); else formatted += indent + rule.selectors.join(", "); formatted += " {\n"; Object.entries(rule.notation).forEach(function (entry) { formatted += "".concat(indent).concat(subIndent).concat(entry[0], ": ").concat(entry[1], ";\n"); }); formatted += indent + "}\n"; } else if (rule instanceof types_1.MediaRule) { formatted += indent + "@media " + (rule.params !== "" ? "".concat(rule.params, " ") : "") + "{\n"; formatted += format(rule, indent + subIndent, subIndent); formatted += indent + "}\n"; } else if (rule instanceof types_1.KeyframeRule) { formatted += indent + "@keyframes " + rule.identifier + " {\n"; rule.frames.forEach(function (frame) { formatted += "".concat(indent + subIndent + frame.mark, " {\n"); Object.entries(frame.notation).forEach(function (entry) { formatted += "".concat(indent + subIndent + subIndent) + "".concat(entry[0], ": ").concat(entry[1], ";\n"); }); formatted += indent + subIndent + "}\n"; }); formatted += indent + "}\n"; } else if (rule instanceof types_1.SupportRule) { formatted += "".concat(indent, "@supports").concat(rule.inverseQuery ? " not" : "") + "(".concat(rule.query, ") {\n"); formatted += format(rule, indent + subIndent, subIndent); formatted += indent + "}\n"; } else if (rule instanceof types_1.FontFaceRule) { formatted += "".concat(indent, "@font-face {\n"); formatted += "".concat(indent).concat(subIndent, "font-family: ").concat(rule.family, ";\n"); formatted += "".concat(indent).concat(subIndent, "src: ").concat(rule.source, ";\n"); formatted += "".concat(indent, "}\n"); } else if (rule instanceof types_1.ImportRule) { formatted += "".concat(indent, "@import url(").concat(rule.href, ");\n"); } }); return formatted; } exports.format = format; exports.default = format;