Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
view-container / dist / utils / stringifyRules.js
Size: Mime:
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// @flow
const stylis_1 = __importDefault(require("stylis"));
const stylis_rule_sheet_1 = __importDefault(require("stylis-rule-sheet"));
// NOTE: This stylis instance is only used to split rules from SSR'd style tags
const stylisSplitter = new stylis_1.default({
    global: false,
    cascade: true,
    keyframe: false,
    prefix: false,
    compress: false,
    semicolon: true,
});
const stylis = new stylis_1.default({
    global: false,
    cascade: true,
    keyframe: false,
    prefix: true,
    compress: false,
    semicolon: false,
});
// Wrap `insertRulePlugin to build a list of rules,
// and then make our own plugin to return the rules. This
// makes it easier to hook into the existing SSR architecture
let parsingRules = [];
// eslint-disable-next-line consistent-return
const returnRulesPlugin = context => {
    if (context === -2) {
        const parsedRules = parsingRules;
        parsingRules = [];
        return parsedRules;
    }
};
const parseRulesPlugin = stylis_rule_sheet_1.default(rule => {
    parsingRules.push(rule);
});
stylis.use([parseRulesPlugin, returnRulesPlugin]);
stylisSplitter.use([parseRulesPlugin, returnRulesPlugin]);
const stringifyRules = (rules, selector, prefix) => {
    const flatCSS = rules.join('').replace(/^\s*\/\/.*$/gm, ''); // replace JS comments
    const cssStr = selector && prefix ? `${prefix} ${selector} { ${flatCSS} }` : flatCSS;
    return stylis(prefix || !selector ? '' : selector, cssStr);
};
exports.splitByRules = (css) => stylisSplitter('', css);
exports.default = stringifyRules;
//# sourceMappingURL=stringifyRules.js.map