"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.incrementCounter = void 0;
exports.resetState = resetState;
exports.styleTags = void 0;
exports.transformCss = transformCss;
var counter = 0;
var incrementCounter = exports.incrementCounter = function incrementCounter() {
  return counter++;
};

// For tests
function resetState() {
  counter = 0;
  exports.styleTags = styleTags = {};
}
var styleTags = exports.styleTags = {};
function transformCss(css, kremlingSelector) {
  return css.replace(/& ([^{}])+{/g, function (match, cssRule) {
    return match.split(",") // multiple rules on the same line split by a comma
    .map(function (cssSplit) {
      cssSplit = cssSplit.trim();

      // ignore css rules that don't begin with '&'
      if (cssSplit.indexOf("&") === -1) return cssSplit.replace("{", "").trim();
      cssSplit = /[^&](.+)[^{]+/g.exec(cssSplit)[0].trim();
      var builtIn = false;
      if (!/^([.#]\w+)/.test(cssSplit)) {
        builtIn = true;
      }
      // if it's not a built-in selector, prepend the data attribute. Otherwise, append
      return !builtIn ? "".concat(kremlingSelector, " ").concat(cssSplit, ", ").concat(kremlingSelector).concat(cssSplit) : "".concat(kremlingSelector, " ").concat(cssSplit, ", ").concat(cssSplit).concat(kremlingSelector);
    }).join(", ") + " {";
  });
}
//# sourceMappingURL=style-element-utils.js.map