import { u as util } from "./lib-util.js";
var _ = util;
function parseStyle(css, onAttr) {
  css = _.trimRight(css);
  if (css[css.length - 1] !== ";") css += ";";
  var cssLength = css.length;
  var isParenthesisOpen = false;
  var lastPos = 0;
  var i = 0;
  var retCSS = "";
  function addNewAttr() {
    if (!isParenthesisOpen) {
      var source = _.trim(css.slice(lastPos, i));
      var j2 = source.indexOf(":");
      if (j2 !== -1) {
        var name = _.trim(source.slice(0, j2));
        var value = _.trim(source.slice(j2 + 1));
        if (name) {
          var ret = onAttr(lastPos, retCSS.length, name, value, source);
          if (ret) retCSS += ret + "; ";
        }
      }
    }
    lastPos = i + 1;
  }
  for (; i < cssLength; i++) {
    var c = css[i];
    if (c === "/" && css[i + 1] === "*") {
      var j = css.indexOf("*/", i + 2);
      if (j === -1) break;
      i = j + 1;
      lastPos = i + 1;
      isParenthesisOpen = false;
    } else if (c === "(") {
      isParenthesisOpen = true;
    } else if (c === ")") {
      isParenthesisOpen = false;
    } else if (c === ";") {
      if (isParenthesisOpen) ;
      else {
        addNewAttr();
      }
    } else if (c === "\n") {
      addNewAttr();
    }
  }
  return _.trim(retCSS);
}
var parser = parseStyle;
export {
  parser as p
};
//# sourceMappingURL=lib-parser.js.map
