import X from "./index-inheritsLoose.js";
import y from "./index-stream.js";
import x from "./index-extends.js";
import U from "./index-assertThisInitialized.js";
import w from "./index-decode-b64-to-uint8-array.js";
var G = /* @__PURE__ */ (function(m) {
  X(f, m);
  function f() {
    var s;
    return s = m.call(this) || this, s.buffer = "", s;
  }
  var n = f.prototype;
  return n.push = function(u) {
    var a;
    for (this.buffer += u, a = this.buffer.indexOf(`
`); a > -1; a = this.buffer.indexOf(`
`))
      this.trigger("data", this.buffer.substring(0, a)), this.buffer = this.buffer.substring(a + 1);
  }, f;
})(y), B = "	", D = function(f) {
  var n = /([0-9.]*)?@?([0-9.]*)?/.exec(f || ""), s = {};
  return n[1] && (s.length = parseInt(n[1], 10)), n[2] && (s.offset = parseInt(n[2], 10)), s;
}, H = function() {
  var f = "[^=]*", n = '"[^"]*"|[^,]*', s = "(?:" + f + ")=(?:" + n + ")";
  return new RegExp("(?:^|,)(" + s + ")");
}, b = function(f) {
  for (var n = f.split(H()), s = {}, u = n.length, a; u--; )
    n[u] !== "" && (a = /([^=]*)=(.*)/.exec(n[u]).slice(1), a[0] = a[0].replace(/^\s+|\s+$/g, ""), a[1] = a[1].replace(/^\s+|\s+$/g, ""), a[1] = a[1].replace(/^['"](.*)['"]$/g, "$1"), s[a[0]] = a[1]);
  return s;
}, Y = /* @__PURE__ */ (function(m) {
  X(f, m);
  function f() {
    var s;
    return s = m.call(this) || this, s.customParsers = [], s.tagMappers = [], s;
  }
  var n = f.prototype;
  return n.push = function(u) {
    var a = this, e, t;
    if (u = u.trim(), u.length !== 0) {
      if (u[0] !== "#") {
        this.trigger("data", {
          type: "uri",
          uri: u
        });
        return;
      }
      var g = this.tagMappers.reduce(function(r, E) {
        var T = E(u);
        return T === u ? r : r.concat([T]);
      }, [u]);
      g.forEach(function(r) {
        for (var E = 0; E < a.customParsers.length; E++)
          if (a.customParsers[E].call(a, r))
            return;
        if (r.indexOf("#EXT") !== 0) {
          a.trigger("data", {
            type: "comment",
            text: r.slice(1)
          });
          return;
        }
        if (r = r.replace("\r", ""), e = /^#EXTM3U/.exec(r), e) {
          a.trigger("data", {
            type: "tag",
            tagType: "m3u"
          });
          return;
        }
        if (e = /^#EXTINF:?([0-9\.]*)?,?(.*)?$/.exec(r), e) {
          t = {
            type: "tag",
            tagType: "inf"
          }, e[1] && (t.duration = parseFloat(e[1])), e[2] && (t.title = e[2]), a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-TARGETDURATION:?([0-9.]*)?/.exec(r), e) {
          t = {
            type: "tag",
            tagType: "targetduration"
          }, e[1] && (t.duration = parseInt(e[1], 10)), a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-VERSION:?([0-9.]*)?/.exec(r), e) {
          t = {
            type: "tag",
            tagType: "version"
          }, e[1] && (t.version = parseInt(e[1], 10)), a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-MEDIA-SEQUENCE:?(\-?[0-9.]*)?/.exec(r), e) {
          t = {
            type: "tag",
            tagType: "media-sequence"
          }, e[1] && (t.number = parseInt(e[1], 10)), a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-DISCONTINUITY-SEQUENCE:?(\-?[0-9.]*)?/.exec(r), e) {
          t = {
            type: "tag",
            tagType: "discontinuity-sequence"
          }, e[1] && (t.number = parseInt(e[1], 10)), a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-PLAYLIST-TYPE:?(.*)?$/.exec(r), e) {
          t = {
            type: "tag",
            tagType: "playlist-type"
          }, e[1] && (t.playlistType = e[1]), a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-BYTERANGE:?(.*)?$/.exec(r), e) {
          t = x(D(e[1]), {
            type: "tag",
            tagType: "byterange"
          }), a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-ALLOW-CACHE:?(YES|NO)?/.exec(r), e) {
          t = {
            type: "tag",
            tagType: "allow-cache"
          }, e[1] && (t.allowed = !/NO/.test(e[1])), a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-MAP:?(.*)$/.exec(r), e) {
          if (t = {
            type: "tag",
            tagType: "map"
          }, e[1]) {
            var T = b(e[1]);
            T.URI && (t.uri = T.URI), T.BYTERANGE && (t.byterange = D(T.BYTERANGE));
          }
          a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-STREAM-INF:?(.*)$/.exec(r), e) {
          if (t = {
            type: "tag",
            tagType: "stream-inf"
          }, e[1]) {
            if (t.attributes = b(e[1]), t.attributes.RESOLUTION) {
              var R = t.attributes.RESOLUTION.split("x"), I = {};
              R[0] && (I.width = parseInt(R[0], 10)), R[1] && (I.height = parseInt(R[1], 10)), t.attributes.RESOLUTION = I;
            }
            t.attributes.BANDWIDTH && (t.attributes.BANDWIDTH = parseInt(t.attributes.BANDWIDTH, 10)), t.attributes["PROGRAM-ID"] && (t.attributes["PROGRAM-ID"] = parseInt(t.attributes["PROGRAM-ID"], 10));
          }
          a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-MEDIA:?(.*)$/.exec(r), e) {
          t = {
            type: "tag",
            tagType: "media"
          }, e[1] && (t.attributes = b(e[1])), a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-ENDLIST/.exec(r), e) {
          a.trigger("data", {
            type: "tag",
            tagType: "endlist"
          });
          return;
        }
        if (e = /^#EXT-X-DISCONTINUITY/.exec(r), e) {
          a.trigger("data", {
            type: "tag",
            tagType: "discontinuity"
          });
          return;
        }
        if (e = /^#EXT-X-PROGRAM-DATE-TIME:?(.*)$/.exec(r), e) {
          t = {
            type: "tag",
            tagType: "program-date-time"
          }, e[1] && (t.dateTimeString = e[1], t.dateTimeObject = new Date(e[1])), a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-KEY:?(.*)$/.exec(r), e) {
          t = {
            type: "tag",
            tagType: "key"
          }, e[1] && (t.attributes = b(e[1]), t.attributes.IV && (t.attributes.IV.substring(0, 2).toLowerCase() === "0x" && (t.attributes.IV = t.attributes.IV.substring(2)), t.attributes.IV = t.attributes.IV.match(/.{8}/g), t.attributes.IV[0] = parseInt(t.attributes.IV[0], 16), t.attributes.IV[1] = parseInt(t.attributes.IV[1], 16), t.attributes.IV[2] = parseInt(t.attributes.IV[2], 16), t.attributes.IV[3] = parseInt(t.attributes.IV[3], 16), t.attributes.IV = new Uint32Array(t.attributes.IV))), a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-START:?(.*)$/.exec(r), e) {
          t = {
            type: "tag",
            tagType: "start"
          }, e[1] && (t.attributes = b(e[1]), t.attributes["TIME-OFFSET"] = parseFloat(t.attributes["TIME-OFFSET"]), t.attributes.PRECISE = /YES/.test(t.attributes.PRECISE)), a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-CUE-OUT-CONT:?(.*)?$/.exec(r), e) {
          t = {
            type: "tag",
            tagType: "cue-out-cont"
          }, e[1] ? t.data = e[1] : t.data = "", a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-CUE-OUT:?(.*)?$/.exec(r), e) {
          t = {
            type: "tag",
            tagType: "cue-out"
          }, e[1] ? t.data = e[1] : t.data = "", a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-CUE-IN:?(.*)?$/.exec(r), e) {
          t = {
            type: "tag",
            tagType: "cue-in"
          }, e[1] ? t.data = e[1] : t.data = "", a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-SKIP:(.*)$/.exec(r), e && e[1]) {
          t = {
            type: "tag",
            tagType: "skip"
          }, t.attributes = b(e[1]), t.attributes.hasOwnProperty("SKIPPED-SEGMENTS") && (t.attributes["SKIPPED-SEGMENTS"] = parseInt(t.attributes["SKIPPED-SEGMENTS"], 10)), t.attributes.hasOwnProperty("RECENTLY-REMOVED-DATERANGES") && (t.attributes["RECENTLY-REMOVED-DATERANGES"] = t.attributes["RECENTLY-REMOVED-DATERANGES"].split(B)), a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-PART:(.*)$/.exec(r), e && e[1]) {
          t = {
            type: "tag",
            tagType: "part"
          }, t.attributes = b(e[1]), ["DURATION"].forEach(function(o) {
            t.attributes.hasOwnProperty(o) && (t.attributes[o] = parseFloat(t.attributes[o]));
          }), ["INDEPENDENT", "GAP"].forEach(function(o) {
            t.attributes.hasOwnProperty(o) && (t.attributes[o] = /YES/.test(t.attributes[o]));
          }), t.attributes.hasOwnProperty("BYTERANGE") && (t.attributes.byterange = D(t.attributes.BYTERANGE)), a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-SERVER-CONTROL:(.*)$/.exec(r), e && e[1]) {
          t = {
            type: "tag",
            tagType: "server-control"
          }, t.attributes = b(e[1]), ["CAN-SKIP-UNTIL", "PART-HOLD-BACK", "HOLD-BACK"].forEach(function(o) {
            t.attributes.hasOwnProperty(o) && (t.attributes[o] = parseFloat(t.attributes[o]));
          }), ["CAN-SKIP-DATERANGES", "CAN-BLOCK-RELOAD"].forEach(function(o) {
            t.attributes.hasOwnProperty(o) && (t.attributes[o] = /YES/.test(t.attributes[o]));
          }), a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-PART-INF:(.*)$/.exec(r), e && e[1]) {
          t = {
            type: "tag",
            tagType: "part-inf"
          }, t.attributes = b(e[1]), ["PART-TARGET"].forEach(function(o) {
            t.attributes.hasOwnProperty(o) && (t.attributes[o] = parseFloat(t.attributes[o]));
          }), a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-PRELOAD-HINT:(.*)$/.exec(r), e && e[1]) {
          t = {
            type: "tag",
            tagType: "preload-hint"
          }, t.attributes = b(e[1]), ["BYTERANGE-START", "BYTERANGE-LENGTH"].forEach(function(o) {
            if (t.attributes.hasOwnProperty(o)) {
              t.attributes[o] = parseInt(t.attributes[o], 10);
              var A = o === "BYTERANGE-LENGTH" ? "length" : "offset";
              t.attributes.byterange = t.attributes.byterange || {}, t.attributes.byterange[A] = t.attributes[o], delete t.attributes[o];
            }
          }), a.trigger("data", t);
          return;
        }
        if (e = /^#EXT-X-RENDITION-REPORT:(.*)$/.exec(r), e && e[1]) {
          t = {
            type: "tag",
            tagType: "rendition-report"
          }, t.attributes = b(e[1]), ["LAST-MSN", "LAST-PART"].forEach(function(o) {
            t.attributes.hasOwnProperty(o) && (t.attributes[o] = parseInt(t.attributes[o], 10));
          }), a.trigger("data", t);
          return;
        }
        a.trigger("data", {
          type: "tag",
          data: r.slice(4)
        });
      });
    }
  }, n.addParser = function(u) {
    var a = this, e = u.expression, t = u.customType, g = u.dataParser, r = u.segment;
    typeof g != "function" && (g = function(T) {
      return T;
    }), this.customParsers.push(function(E) {
      var T = e.exec(E);
      if (T)
        return a.trigger("data", {
          type: "custom",
          data: g(E),
          customType: t,
          segment: r
        }), !0;
    });
  }, n.addTagMapper = function(u) {
    var a = u.expression, e = u.map, t = function(r) {
      return a.test(r) ? e(r) : r;
    };
    this.tagMappers.push(t);
  }, f;
})(y), V = function(f) {
  return f.toLowerCase().replace(/-(\w)/g, function(n) {
    return n[1].toUpperCase();
  });
}, S = function(f) {
  var n = {};
  return Object.keys(f).forEach(function(s) {
    n[V(s)] = f[s];
  }), n;
}, C = function(f) {
  var n = f.serverControl, s = f.targetDuration, u = f.partTargetDuration;
  if (n) {
    var a = "#EXT-X-SERVER-CONTROL", e = "holdBack", t = "partHoldBack", g = s && s * 3, r = u && u * 2;
    s && !n.hasOwnProperty(e) && (n[e] = g, this.trigger("info", {
      message: a + " defaulting HOLD-BACK to targetDuration * 3 (" + g + ")."
    })), g && n[e] < g && (this.trigger("warn", {
      message: a + " clamping HOLD-BACK (" + n[e] + ") to targetDuration * 3 (" + g + ")"
    }), n[e] = g), u && !n.hasOwnProperty(t) && (n[t] = u * 3, this.trigger("info", {
      message: a + " defaulting PART-HOLD-BACK to partTargetDuration * 3 (" + n[t] + ")."
    })), u && n[t] < r && (this.trigger("warn", {
      message: a + " clamping PART-HOLD-BACK (" + n[t] + ") to partTargetDuration * 2 (" + r + ")."
    }), n[t] = r);
  }
}, k = /* @__PURE__ */ (function(m) {
  X(f, m);
  function f() {
    var s;
    s = m.call(this) || this, s.lineStream = new G(), s.parseStream = new Y(), s.lineStream.pipe(s.parseStream);
    var u = U(s), a = [], e = {}, t, g, r = !1, E = function() {
    }, T = {
      AUDIO: {},
      VIDEO: {},
      "CLOSED-CAPTIONS": {},
      SUBTITLES: {}
    }, R = "urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed", I = 0;
    s.manifest = {
      allowCache: !0,
      discontinuityStarts: [],
      segments: []
    };
    var o = 0, A = 0;
    return s.on("end", function() {
      e.uri || !e.parts && !e.preloadHints || (!e.map && t && (e.map = t), !e.key && g && (e.key = g), !e.timeline && typeof I == "number" && (e.timeline = I), s.manifest.preloadSegment = e);
    }), s.parseStream.on("data", function(i) {
      var M, l;
      ({
        tag: function() {
          ({
            version: function() {
              i.version && (this.manifest.version = i.version);
            },
            "allow-cache": function() {
              this.manifest.allowCache = i.allowed, "allowed" in i || (this.trigger("info", {
                message: "defaulting allowCache to YES"
              }), this.manifest.allowCache = !0);
            },
            byterange: function() {
              var c = {};
              "length" in i && (e.byterange = c, c.length = i.length, "offset" in i || (i.offset = o)), "offset" in i && (e.byterange = c, c.offset = i.offset), o = c.offset + c.length;
            },
            endlist: function() {
              this.manifest.endList = !0;
            },
            inf: function() {
              "mediaSequence" in this.manifest || (this.manifest.mediaSequence = 0, this.trigger("info", {
                message: "defaulting media sequence to zero"
              })), "discontinuitySequence" in this.manifest || (this.manifest.discontinuitySequence = 0, this.trigger("info", {
                message: "defaulting discontinuity sequence to zero"
              })), i.duration > 0 && (e.duration = i.duration), i.duration === 0 && (e.duration = 0.01, this.trigger("info", {
                message: "updating zero segment duration to a small value"
              })), this.manifest.segments = a;
            },
            key: function() {
              if (!i.attributes) {
                this.trigger("warn", {
                  message: "ignoring key declaration without attribute list"
                });
                return;
              }
              if (i.attributes.METHOD === "NONE") {
                g = null;
                return;
              }
              if (!i.attributes.URI) {
                this.trigger("warn", {
                  message: "ignoring key declaration without URI"
                });
                return;
              }
              if (i.attributes.KEYFORMAT === "com.apple.streamingkeydelivery") {
                this.manifest.contentProtection = this.manifest.contentProtection || {}, this.manifest.contentProtection["com.apple.fps.1_0"] = {
                  attributes: i.attributes
                };
                return;
              }
              if (i.attributes.KEYFORMAT === R) {
                var c = ["SAMPLE-AES", "SAMPLE-AES-CTR", "SAMPLE-AES-CENC"];
                if (c.indexOf(i.attributes.METHOD) === -1) {
                  this.trigger("warn", {
                    message: "invalid key method provided for Widevine"
                  });
                  return;
                }
                if (i.attributes.METHOD === "SAMPLE-AES-CENC" && this.trigger("warn", {
                  message: "SAMPLE-AES-CENC is deprecated, please use SAMPLE-AES-CTR instead"
                }), i.attributes.URI.substring(0, 23) !== "data:text/plain;base64,") {
                  this.trigger("warn", {
                    message: "invalid key URI provided for Widevine"
                  });
                  return;
                }
                if (!(i.attributes.KEYID && i.attributes.KEYID.substring(0, 2) === "0x")) {
                  this.trigger("warn", {
                    message: "invalid key ID provided for Widevine"
                  });
                  return;
                }
                this.manifest.contentProtection = this.manifest.contentProtection || {}, this.manifest.contentProtection["com.widevine.alpha"] = {
                  attributes: {
                    schemeIdUri: i.attributes.KEYFORMAT,
                    // remove '0x' from the key id string
                    keyId: i.attributes.KEYID.substring(2)
                  },
                  // decode the base64-encoded PSSH box
                  pssh: w(i.attributes.URI.split(",")[1])
                };
                return;
              }
              i.attributes.METHOD || this.trigger("warn", {
                message: "defaulting key method to AES-128"
              }), g = {
                method: i.attributes.METHOD || "AES-128",
                uri: i.attributes.URI
              }, typeof i.attributes.IV < "u" && (g.iv = i.attributes.IV);
            },
            "media-sequence": function() {
              if (!isFinite(i.number)) {
                this.trigger("warn", {
                  message: "ignoring invalid media sequence: " + i.number
                });
                return;
              }
              this.manifest.mediaSequence = i.number;
            },
            "discontinuity-sequence": function() {
              if (!isFinite(i.number)) {
                this.trigger("warn", {
                  message: "ignoring invalid discontinuity sequence: " + i.number
                });
                return;
              }
              this.manifest.discontinuitySequence = i.number, I = i.number;
            },
            "playlist-type": function() {
              if (!/VOD|EVENT/.test(i.playlistType)) {
                this.trigger("warn", {
                  message: "ignoring unknown playlist type: " + i.playlist
                });
                return;
              }
              this.manifest.playlistType = i.playlistType;
            },
            map: function() {
              t = {}, i.uri && (t.uri = i.uri), i.byterange && (t.byterange = i.byterange), g && (t.key = g);
            },
            "stream-inf": function() {
              if (this.manifest.playlists = a, this.manifest.mediaGroups = this.manifest.mediaGroups || T, !i.attributes) {
                this.trigger("warn", {
                  message: "ignoring empty stream-inf attributes"
                });
                return;
              }
              e.attributes || (e.attributes = {}), x(e.attributes, i.attributes);
            },
            media: function() {
              if (this.manifest.mediaGroups = this.manifest.mediaGroups || T, !(i.attributes && i.attributes.TYPE && i.attributes["GROUP-ID"] && i.attributes.NAME)) {
                this.trigger("warn", {
                  message: "ignoring incomplete or missing media group"
                });
                return;
              }
              var c = this.manifest.mediaGroups[i.attributes.TYPE];
              c[i.attributes["GROUP-ID"]] = c[i.attributes["GROUP-ID"]] || {}, M = c[i.attributes["GROUP-ID"]], l = {
                default: /yes/i.test(i.attributes.DEFAULT)
              }, l.default ? l.autoselect = !0 : l.autoselect = /yes/i.test(i.attributes.AUTOSELECT), i.attributes.LANGUAGE && (l.language = i.attributes.LANGUAGE), i.attributes.URI && (l.uri = i.attributes.URI), i.attributes["INSTREAM-ID"] && (l.instreamId = i.attributes["INSTREAM-ID"]), i.attributes.CHARACTERISTICS && (l.characteristics = i.attributes.CHARACTERISTICS), i.attributes.FORCED && (l.forced = /yes/i.test(i.attributes.FORCED)), M[i.attributes.NAME] = l;
            },
            discontinuity: function() {
              I += 1, e.discontinuity = !0, this.manifest.discontinuityStarts.push(a.length);
            },
            "program-date-time": function() {
              typeof this.manifest.dateTimeString > "u" && (this.manifest.dateTimeString = i.dateTimeString, this.manifest.dateTimeObject = i.dateTimeObject), e.dateTimeString = i.dateTimeString, e.dateTimeObject = i.dateTimeObject;
            },
            targetduration: function() {
              if (!isFinite(i.duration) || i.duration < 0) {
                this.trigger("warn", {
                  message: "ignoring invalid target duration: " + i.duration
                });
                return;
              }
              this.manifest.targetDuration = i.duration, C.call(this, this.manifest);
            },
            start: function() {
              if (!i.attributes || isNaN(i.attributes["TIME-OFFSET"])) {
                this.trigger("warn", {
                  message: "ignoring start declaration without appropriate attribute list"
                });
                return;
              }
              this.manifest.start = {
                timeOffset: i.attributes["TIME-OFFSET"],
                precise: i.attributes.PRECISE
              };
            },
            "cue-out": function() {
              e.cueOut = i.data;
            },
            "cue-out-cont": function() {
              e.cueOutCont = i.data;
            },
            "cue-in": function() {
              e.cueIn = i.data;
            },
            skip: function() {
              this.manifest.skip = S(i.attributes), this.warnOnMissingAttributes_("#EXT-X-SKIP", i.attributes, ["SKIPPED-SEGMENTS"]);
            },
            part: function() {
              var c = this;
              r = !0;
              var d = this.manifest.segments.length, h = S(i.attributes);
              e.parts = e.parts || [], e.parts.push(h), h.byterange && (h.byterange.hasOwnProperty("offset") || (h.byterange.offset = A), A = h.byterange.offset + h.byterange.length);
              var v = e.parts.length - 1;
              this.warnOnMissingAttributes_("#EXT-X-PART #" + v + " for segment #" + d, i.attributes, ["URI", "DURATION"]), this.manifest.renditionReports && this.manifest.renditionReports.forEach(function(O, P) {
                O.hasOwnProperty("lastPart") || c.trigger("warn", {
                  message: "#EXT-X-RENDITION-REPORT #" + P + " lacks required attribute(s): LAST-PART"
                });
              });
            },
            "server-control": function() {
              var c = this.manifest.serverControl = S(i.attributes);
              c.hasOwnProperty("canBlockReload") || (c.canBlockReload = !1, this.trigger("info", {
                message: "#EXT-X-SERVER-CONTROL defaulting CAN-BLOCK-RELOAD to false"
              })), C.call(this, this.manifest), c.canSkipDateranges && !c.hasOwnProperty("canSkipUntil") && this.trigger("warn", {
                message: "#EXT-X-SERVER-CONTROL lacks required attribute CAN-SKIP-UNTIL which is required when CAN-SKIP-DATERANGES is set"
              });
            },
            "preload-hint": function() {
              var c = this.manifest.segments.length, d = S(i.attributes), h = d.type && d.type === "PART";
              e.preloadHints = e.preloadHints || [], e.preloadHints.push(d), d.byterange && (d.byterange.hasOwnProperty("offset") || (d.byterange.offset = h ? A : 0, h && (A = d.byterange.offset + d.byterange.length)));
              var v = e.preloadHints.length - 1;
              if (this.warnOnMissingAttributes_("#EXT-X-PRELOAD-HINT #" + v + " for segment #" + c, i.attributes, ["TYPE", "URI"]), !!d.type)
                for (var O = 0; O < e.preloadHints.length - 1; O++) {
                  var P = e.preloadHints[O];
                  P.type && P.type === d.type && this.trigger("warn", {
                    message: "#EXT-X-PRELOAD-HINT #" + v + " for segment #" + c + " has the same TYPE " + d.type + " as preload hint #" + O
                  });
                }
            },
            "rendition-report": function() {
              var c = S(i.attributes);
              this.manifest.renditionReports = this.manifest.renditionReports || [], this.manifest.renditionReports.push(c);
              var d = this.manifest.renditionReports.length - 1, h = ["LAST-MSN", "URI"];
              r && h.push("LAST-PART"), this.warnOnMissingAttributes_("#EXT-X-RENDITION-REPORT #" + d, i.attributes, h);
            },
            "part-inf": function() {
              this.manifest.partInf = S(i.attributes), this.warnOnMissingAttributes_("#EXT-X-PART-INF", i.attributes, ["PART-TARGET"]), this.manifest.partInf.partTarget && (this.manifest.partTargetDuration = this.manifest.partInf.partTarget), C.call(this, this.manifest);
            }
          }[i.tagType] || E).call(u);
        },
        uri: function() {
          e.uri = i.uri, a.push(e), this.manifest.targetDuration && !("duration" in e) && (this.trigger("warn", {
            message: "defaulting segment duration to the target duration"
          }), e.duration = this.manifest.targetDuration), g && (e.key = g), e.timeline = I, t && (e.map = t), A = 0, e = {};
        },
        comment: function() {
        },
        custom: function() {
          i.segment ? (e.custom = e.custom || {}, e.custom[i.customType] = i.data) : (this.manifest.custom = this.manifest.custom || {}, this.manifest.custom[i.customType] = i.data);
        }
      })[i.type].call(u);
    }), s;
  }
  var n = f.prototype;
  return n.warnOnMissingAttributes_ = function(u, a, e) {
    var t = [];
    e.forEach(function(g) {
      a.hasOwnProperty(g) || t.push(g);
    }), t.length && this.trigger("warn", {
      message: u + " lacks required attribute(s): " + t.join(", ")
    });
  }, n.push = function(u) {
    this.lineStream.push(u);
  }, n.end = function() {
    this.lineStream.push(`
`), this.trigger("end");
  }, n.addParser = function(u) {
    this.parseStream.addParser(u);
  }, n.addTagMapper = function(u) {
    this.parseStream.addTagMapper(u);
  }, f;
})(y);
export {
  G as LineStream,
  Y as ParseStream,
  k as Parser
};
