import s from "../../../../../../_virtual/___vite-browser-external.js";
let { SourceMapConsumer: l, SourceMapGenerator: u } = s, { existsSync: c, readFileSync: p } = s, { dirname: o, join: m } = s;
function d(r) {
  return Buffer ? Buffer.from(r, "base64").toString() : window.atob(r);
}
class a {
  constructor(t, e) {
    if (e.map === !1)
      return;
    this.loadAnnotation(t), this.inline = this.startWith(this.annotation, "data:");
    let n = e.map ? e.map.prev : void 0, i = this.loadMap(e.from, n);
    !this.mapFile && e.from && (this.mapFile = e.from), this.mapFile && (this.root = o(this.mapFile)), i && (this.text = i);
  }
  consumer() {
    return this.consumerCache || (this.consumerCache = new l(this.text)), this.consumerCache;
  }
  withContent() {
    return !!(this.consumer().sourcesContent && this.consumer().sourcesContent.length > 0);
  }
  startWith(t, e) {
    return t ? t.substr(0, e.length) === e : !1;
  }
  getAnnotationURL(t) {
    return t.replace(/^\/\*\s*# sourceMappingURL=/, "").trim();
  }
  loadAnnotation(t) {
    let e = t.match(/\/\*\s*# sourceMappingURL=/gm);
    if (!e)
      return;
    let n = t.lastIndexOf(e.pop()), i = t.indexOf("*/", n);
    n > -1 && i > -1 && (this.annotation = this.getAnnotationURL(t.substring(n, i)));
  }
  decodeInline(t) {
    let e = /^data:application\/json;charset=utf-?8;base64,/, n = /^data:application\/json;base64,/, i = /^data:application\/json;charset=utf-?8,/, f = /^data:application\/json,/;
    if (i.test(t) || f.test(t))
      return decodeURIComponent(t.substr(RegExp.lastMatch.length));
    if (e.test(t) || n.test(t))
      return d(t.substr(RegExp.lastMatch.length));
    let h = t.match(/data:application\/json;([^,]+),/)[1];
    throw new Error("Unsupported source map encoding " + h);
  }
  loadFile(t) {
    if (this.root = o(t), c(t))
      return this.mapFile = t, p(t, "utf-8").toString().trim();
  }
  loadMap(t, e) {
    if (e === !1)
      return !1;
    if (e) {
      if (typeof e == "string")
        return e;
      if (typeof e == "function") {
        let n = e(t);
        if (n) {
          let i = this.loadFile(n);
          if (!i)
            throw new Error(
              "Unable to load previous source map: " + n.toString()
            );
          return i;
        }
      } else {
        if (e instanceof l)
          return u.fromSourceMap(e).toString();
        if (e instanceof u)
          return e.toString();
        if (this.isMap(e))
          return JSON.stringify(e);
        throw new Error(
          "Unsupported previous source map format: " + e.toString()
        );
      }
    } else {
      if (this.inline)
        return this.decodeInline(this.annotation);
      if (this.annotation) {
        let n = this.annotation;
        return t && (n = m(o(t), n)), this.loadFile(n);
      }
    }
  }
  isMap(t) {
    return typeof t != "object" ? !1 : typeof t.mappings == "string" || typeof t._mappings == "string" || Array.isArray(t.sections);
  }
}
var M = a;
a.default = a;
export {
  M as default
};
//# sourceMappingURL=previous-map.js.map
