import n from "./index-window.js";
var u = {
  // to determine mime types
  mp4: /^(av0?1|avc0?[1234]|vp0?9|flac|opus|mp3|mp4a|mp4v|stpp.ttml.im1t)/,
  webm: /^(vp0?[89]|av0?1|opus|vorbis)/,
  ogg: /^(vp0?[89]|theora|flac|opus|vorbis)/,
  // to determine if a codec is audio or video
  video: /^(av0?1|avc0?[1234]|vp0?[89]|hvc1|hev1|theora|mp4v)/,
  audio: /^(mp4a|flac|vorbis|opus|ac-[34]|ec-3|alac|mp3|speex|aac)/,
  text: /^(stpp.ttml.im1t)/,
  // mux.js support regex
  muxerVideo: /^(avc0?1)/,
  muxerAudio: /^(mp4a)/,
  // match nothing as muxer does not support text right now.
  // there cannot never be a character before the start of a string
  // so this matches nothing.
  muxerText: /a^/
}, m = ["video", "audio", "text"], f = ["Video", "Audio", "Text"], d = function(e) {
  return e && e.replace(/avc1\.(\d+)\.(\d+)/i, function(r, t, a) {
    var i = ("00" + Number(t).toString(16)).slice(-2), s = ("00" + Number(a).toString(16)).slice(-2);
    return "avc1." + i + "00" + s;
  });
}, c = function(e) {
  e === void 0 && (e = "");
  var r = e.split(","), t = [];
  return r.forEach(function(a) {
    a = a.trim();
    var i;
    m.forEach(function(s) {
      var p = u[s].exec(a.toLowerCase());
      if (!(!p || p.length <= 1)) {
        i = s;
        var v = a.substring(0, p[1].length), l = a.replace(v, "");
        t.push({
          type: v,
          details: l,
          mediaType: s
        });
      }
    }), i || t.push({
      type: a,
      details: "",
      mediaType: "unknown"
    });
  }), t;
}, w = function(e, r) {
  if (!e.mediaGroups.AUDIO || !r)
    return null;
  var t = e.mediaGroups.AUDIO[r];
  if (!t)
    return null;
  for (var a in t) {
    var i = t[a];
    if (i.default && i.playlists)
      return c(i.playlists[0].attributes.CODECS);
  }
  return null;
}, C = function(e) {
  return e === void 0 && (e = ""), u.audio.test(e.trim().toLowerCase());
}, x = function(e) {
  return e === void 0 && (e = ""), u.text.test(e.trim().toLowerCase());
}, y = function(e) {
  if (!(!e || typeof e != "string")) {
    var r = e.toLowerCase().split(",").map(function(i) {
      return d(i.trim());
    }), t = "video";
    r.length === 1 && C(r[0]) ? t = "audio" : r.length === 1 && x(r[0]) && (t = "application");
    var a = "mp4";
    return r.every(function(i) {
      return u.mp4.test(i);
    }) ? a = "mp4" : r.every(function(i) {
      return u.webm.test(i);
    }) ? a = "webm" : r.every(function(i) {
      return u.ogg.test(i);
    }) && (a = "ogg"), t + "/" + a + ';codecs="' + e + '"';
  }
}, b = function(e) {
  return e === void 0 && (e = ""), n.MediaSource && n.MediaSource.isTypeSupported && n.MediaSource.isTypeSupported(y(e)) || !1;
}, g = function(e) {
  return e === void 0 && (e = ""), e.toLowerCase().split(",").every(function(r) {
    r = r.trim();
    for (var t = 0; t < f.length; t++) {
      var a = f[t];
      if (u["muxer" + a].test(r))
        return !0;
    }
    return !1;
  });
}, D = "mp4a.40.2", T = "avc1.4d400d";
export {
  D as DEFAULT_AUDIO_CODEC,
  T as DEFAULT_VIDEO_CODEC,
  b as browserSupportsCodec,
  w as codecsFromDefault,
  y as getMimeForCodec,
  C as isAudioCodec,
  x as isTextCodec,
  g as muxerSupportsCodec,
  c as parseCodecs,
  d as translateLegacyCodec
};
