"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("./lib-default.cjs");
const parser = require("./lib-parser.cjs");
const _default = require("../../_virtual/default2.cjs");
var DEFAULT = _default.__exports;
var parseStyle = parser.parser;
function isNull(obj) {
  return obj === void 0 || obj === null;
}
function shallowCopyObject(obj) {
  var ret = {};
  for (var i in obj) {
    ret[i] = obj[i];
  }
  return ret;
}
function FilterCSS(options) {
  options = shallowCopyObject(options || {});
  options.whiteList = options.whiteList || DEFAULT.whiteList;
  options.onAttr = options.onAttr || DEFAULT.onAttr;
  options.onIgnoreAttr = options.onIgnoreAttr || DEFAULT.onIgnoreAttr;
  options.safeAttrValue = options.safeAttrValue || DEFAULT.safeAttrValue;
  this.options = options;
}
FilterCSS.prototype.process = function(css2) {
  css2 = css2 || "";
  css2 = css2.toString();
  if (!css2) return "";
  var me = this;
  var options = me.options;
  var whiteList = options.whiteList;
  var onAttr = options.onAttr;
  var onIgnoreAttr = options.onIgnoreAttr;
  var safeAttrValue = options.safeAttrValue;
  var retCSS = parseStyle(css2, function(sourcePosition, position, name, value, source) {
    var check = whiteList[name];
    var isWhite = false;
    if (check === true) isWhite = check;
    else if (typeof check === "function") isWhite = check(value);
    else if (check instanceof RegExp) isWhite = check.test(value);
    if (isWhite !== true) isWhite = false;
    value = safeAttrValue(name, value);
    if (!value) return;
    var opts = {
      position,
      sourcePosition,
      source,
      isWhite
    };
    if (isWhite) {
      var ret = onAttr(name, value, opts);
      if (isNull(ret)) {
        return name + ":" + value;
      } else {
        return ret;
      }
    } else {
      var ret = onIgnoreAttr(name, value, opts);
      if (!isNull(ret)) {
        return ret;
      }
    }
  });
  return retCSS;
};
var css = FilterCSS;
exports.css = css;
//# sourceMappingURL=lib-css.cjs.map
