var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  return value;
};
var __accessCheck = (obj, member, msg) => {
  if (!member.has(obj))
    throw TypeError("Cannot " + msg);
};
var __privateGet = (obj, member, getter) => {
  __accessCheck(obj, member, "read from private field");
  return getter ? getter.call(obj) : member.get(obj);
};
var __privateAdd = (obj, member, value) => {
  if (member.has(obj))
    throw TypeError("Cannot add the same private member more than once");
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
};
var __privateSet = (obj, member, value, setter) => {
  __accessCheck(obj, member, "write to private field");
  setter ? setter.call(obj, value) : member.set(obj, value);
  return value;
};
var __privateMethod = (obj, member, method) => {
  __accessCheck(obj, member, "access private method");
  return method;
};
var _addTrackCallback, _removeTrackCallback, _changeCallback, _tracks, tracks_get, _addRenditionCallback, _removeRenditionCallback, _changeCallback2, _selected, _selected2, _addRenditionCallback2, _removeRenditionCallback2, _changeCallback3, _selected3, _addTrackCallback2, _removeTrackCallback2, _changeCallback4, _tracks2, tracks_get2, _enabled;
const Events = [
  "abort",
  "canplay",
  "canplaythrough",
  "durationchange",
  "emptied",
  "encrypted",
  "ended",
  "error",
  "loadeddata",
  "loadedmetadata",
  "loadstart",
  "pause",
  "play",
  "playing",
  "progress",
  "ratechange",
  "seeked",
  "seeking",
  "stalled",
  "suspend",
  "timeupdate",
  "volumechange",
  "waiting",
  "waitingforkey",
  "resize",
  "enterpictureinpicture",
  "leavepictureinpicture",
  "webkitbeginfullscreen",
  "webkitendfullscreen",
  "webkitpresentationmodechanged"
];
const Attributes = [
  "autopictureinpicture",
  "disablepictureinpicture",
  "disableremoteplayback",
  "autoplay",
  "controls",
  "controlslist",
  "crossorigin",
  "loop",
  "muted",
  "playsinline",
  "poster",
  "preload",
  "src"
];
function getAudioTemplateHTML(attrs) {
  return (
    /*html*/
    `
    <style>
      :host {
        display: inline-flex;
        line-height: 0;
        flex-direction: column;
        justify-content: end;
      }

      audio {
        width: 100%;
      }
    </style>
    <slot name="media">
      <audio${serializeAttributes(attrs)}></audio>
    </slot>
    <slot></slot>
  `
  );
}
function getVideoTemplateHTML(attrs) {
  return (
    /*html*/
    `
    <style>
      :host {
        display: inline-block;
        line-height: 0;
      }

      video {
        max-width: 100%;
        max-height: 100%;
        min-width: 100%;
        min-height: 100%;
        object-fit: var(--media-object-fit, contain);
        object-position: var(--media-object-position, 50% 50%);
      }

      video::-webkit-media-text-track-container {
        transform: var(--media-webkit-text-track-transform);
        transition: var(--media-webkit-text-track-transition);
      }
    </style>
    <slot name="media">
      <video${serializeAttributes(attrs)}></video>
    </slot>
    <slot></slot>
  `
  );
}
function CustomMediaMixin(superclass, { tag, is }) {
  var _a, _b, _c, _isDefined, _define, define_fn, _isInit, _nativeEl, _childMap, _childObserver, _slotChangeHandler, _init, init_fn, _setupListeners, setupListeners_fn, _syncMediaChildren, syncMediaChildren_fn, _syncMediaChildAttribute, syncMediaChildAttribute_fn, _enableDefaultTrack, enableDefaultTrack_fn, _upgradeProperty, upgradeProperty_fn, _forwardAttribute, forwardAttribute_fn;
  const nativeElTest = (_b = (_a = globalThis.document) == null ? void 0 : _a.createElement) == null ? void 0 : _b.call(_a, tag, { is });
  const nativeElProps = nativeElTest ? getNativeElProps(nativeElTest) : [];
  return _c = class extends superclass {
    constructor() {
      super(...arguments);
      __privateAdd(this, _init);
      __privateAdd(this, _setupListeners);
      __privateAdd(this, _syncMediaChildren);
      __privateAdd(this, _syncMediaChildAttribute);
      __privateAdd(this, _enableDefaultTrack);
      __privateAdd(this, _upgradeProperty);
      __privateAdd(this, _forwardAttribute);
      // Private fields
      __privateAdd(this, _isInit, false);
      __privateAdd(this, _nativeEl, null);
      __privateAdd(this, _childMap, /* @__PURE__ */ new Map());
      __privateAdd(this, _childObserver, void 0);
      __privateAdd(this, _slotChangeHandler, void 0);
      __publicField(this, "get");
      __publicField(this, "set");
      __publicField(this, "call");
    }
    static get observedAttributes() {
      var _a2, _b2;
      __privateMethod(_a2 = _c, _define, define_fn).call(_a2);
      const natAttrs = ((_b2 = nativeElTest == null ? void 0 : nativeElTest.constructor) == null ? void 0 : _b2.observedAttributes) ?? [];
      return [
        ...natAttrs,
        ...Attributes
      ];
    }
    // If the custom element is defined before the custom element's HTML is parsed
    // no attributes will be available in the constructor (construction process).
    // Wait until initializing in the attributeChangedCallback or
    // connectedCallback or accessing any properties.
    get nativeEl() {
      var _a2;
      __privateMethod(this, _init, init_fn).call(this);
      return __privateGet(this, _nativeEl) ?? this.querySelector(":scope > [slot=media]") ?? this.querySelector(tag) ?? ((_a2 = this.shadowRoot) == null ? void 0 : _a2.querySelector(tag)) ?? null;
    }
    set nativeEl(val) {
      __privateSet(this, _nativeEl, val);
    }
    get defaultMuted() {
      return this.hasAttribute("muted");
    }
    set defaultMuted(val) {
      this.toggleAttribute("muted", val);
    }
    get src() {
      return this.getAttribute("src");
    }
    set src(val) {
      this.setAttribute("src", `${val}`);
    }
    get preload() {
      var _a2;
      return this.getAttribute("preload") ?? ((_a2 = this.nativeEl) == null ? void 0 : _a2.preload);
    }
    set preload(val) {
      this.setAttribute("preload", `${val}`);
    }
    init() {
      if (!this.shadowRoot) {
        this.attachShadow({ mode: "open" });
        const attrs = namedNodeMapToObject(this.attributes);
        if (is)
          attrs.is = is;
        if (tag)
          attrs.part = tag;
        this.shadowRoot.innerHTML = this.constructor.getTemplateHTML(attrs);
      }
      this.nativeEl.muted = this.hasAttribute("muted");
      for (const prop of nativeElProps) {
        __privateMethod(this, _upgradeProperty, upgradeProperty_fn).call(this, prop);
      }
      __privateMethod(this, _setupListeners, setupListeners_fn).call(this);
    }
    handleEvent(event) {
      if (event.target === this.nativeEl) {
        this.dispatchEvent(new CustomEvent(event.type, { detail: event.detail }));
      }
    }
    attributeChangedCallback(attrName, oldValue, newValue) {
      __privateMethod(this, _init, init_fn).call(this);
      __privateMethod(this, _forwardAttribute, forwardAttribute_fn).call(this, attrName, oldValue, newValue);
    }
    connectedCallback() {
      __privateMethod(this, _init, init_fn).call(this);
      if (!__privateGet(this, _slotChangeHandler)) {
        __privateMethod(this, _setupListeners, setupListeners_fn).call(this);
      }
    }
    disconnectedCallback() {
      var _a2, _b2, _c2;
      (_a2 = __privateGet(this, _childObserver)) == null ? void 0 : _a2.disconnect();
      __privateSet(this, _childObserver, void 0);
      if (__privateGet(this, _slotChangeHandler)) {
        (_b2 = this.shadowRoot) == null ? void 0 : _b2.removeEventListener("slotchange", __privateGet(this, _slotChangeHandler));
        __privateSet(this, _slotChangeHandler, void 0);
      }
      for (const type of this.constructor.Events) {
        (_c2 = this.shadowRoot) == null ? void 0 : _c2.removeEventListener(type, this, true);
      }
      __privateGet(this, _childMap).forEach((clone) => clone.remove());
      __privateGet(this, _childMap).clear();
      __privateSet(this, _nativeEl, null);
    }
  }, _isDefined = new WeakMap(), _define = new WeakSet(), define_fn = function() {
    if (__privateGet(this, _isDefined))
      return;
    __privateSet(this, _isDefined, true);
    const propsToAttrs = new Set(this.observedAttributes);
    propsToAttrs.delete("muted");
    for (const prop of nativeElProps) {
      if (prop in this.prototype)
        continue;
      if (typeof nativeElTest[prop] === "function") {
        this.prototype[prop] = function(...args) {
          __privateMethod(this, _init, init_fn).call(this);
          const fn = () => {
            var _a2;
            if (this.call)
              return this.call(prop, ...args);
            const nativeFn = (_a2 = this.nativeEl) == null ? void 0 : _a2[prop];
            return nativeFn == null ? void 0 : nativeFn.apply(this.nativeEl, args);
          };
          return fn();
        };
      } else {
        const config = {
          get() {
            var _a2, _b2;
            __privateMethod(this, _init, init_fn).call(this);
            const attr = prop.toLowerCase();
            if (propsToAttrs.has(attr)) {
              const val = this.getAttribute(attr);
              return val === null ? false : val === "" ? true : val;
            }
            return ((_a2 = this.get) == null ? void 0 : _a2.call(this, prop)) ?? ((_b2 = this.nativeEl) == null ? void 0 : _b2[prop]);
          }
        };
        if (prop !== prop.toUpperCase()) {
          config.set = function(val) {
            __privateMethod(this, _init, init_fn).call(this);
            const attr = prop.toLowerCase();
            if (propsToAttrs.has(attr)) {
              if (val === true || val === false || val == null) {
                this.toggleAttribute(attr, Boolean(val));
              } else {
                this.setAttribute(attr, val);
              }
              return;
            }
            if (this.set) {
              this.set(prop, val);
              return;
            }
            if (this.nativeEl) {
              this.nativeEl[prop] = val;
            }
          };
        }
        Object.defineProperty(this.prototype, prop, config);
      }
    }
  }, _isInit = new WeakMap(), _nativeEl = new WeakMap(), _childMap = new WeakMap(), _childObserver = new WeakMap(), _slotChangeHandler = new WeakMap(), _init = new WeakSet(), init_fn = function() {
    if (__privateGet(this, _isInit))
      return;
    __privateSet(this, _isInit, true);
    this.init();
  }, _setupListeners = new WeakSet(), setupListeners_fn = function() {
    var _a2, _b2;
    __privateSet(this, _childObserver, new MutationObserver(__privateMethod(this, _syncMediaChildAttribute, syncMediaChildAttribute_fn).bind(this)));
    __privateSet(this, _slotChangeHandler, () => __privateMethod(this, _syncMediaChildren, syncMediaChildren_fn).call(this));
    (_a2 = this.shadowRoot) == null ? void 0 : _a2.addEventListener("slotchange", __privateGet(this, _slotChangeHandler));
    __privateMethod(this, _syncMediaChildren, syncMediaChildren_fn).call(this);
    for (const type of this.constructor.Events) {
      (_b2 = this.shadowRoot) == null ? void 0 : _b2.addEventListener(type, this, true);
    }
  }, _syncMediaChildren = new WeakSet(), syncMediaChildren_fn = function() {
    var _a2;
    const removeNativeChildren = new Map(__privateGet(this, _childMap));
    const defaultSlot = (_a2 = this.shadowRoot) == null ? void 0 : _a2.querySelector("slot:not([name])");
    const mediaChildren = defaultSlot == null ? void 0 : defaultSlot.assignedElements({ flatten: true }).filter((el) => ["track", "source"].includes(el.localName));
    mediaChildren.forEach((el) => {
      var _a3, _b2;
      removeNativeChildren.delete(el);
      let clone = __privateGet(this, _childMap).get(el);
      if (!clone) {
        clone = el.cloneNode();
        __privateGet(this, _childMap).set(el, clone);
        (_a3 = __privateGet(this, _childObserver)) == null ? void 0 : _a3.observe(el, { attributes: true });
      }
      (_b2 = this.nativeEl) == null ? void 0 : _b2.append(clone);
      __privateMethod(this, _enableDefaultTrack, enableDefaultTrack_fn).call(this, clone);
    });
    removeNativeChildren.forEach((clone, el) => {
      clone.remove();
      __privateGet(this, _childMap).delete(el);
    });
  }, _syncMediaChildAttribute = new WeakSet(), syncMediaChildAttribute_fn = function(mutations) {
    for (const mutation of mutations) {
      if (mutation.type === "attributes") {
        const { target, attributeName } = mutation;
        const clone = __privateGet(this, _childMap).get(target);
        if (clone && attributeName) {
          clone.setAttribute(attributeName, target.getAttribute(attributeName) ?? "");
          __privateMethod(this, _enableDefaultTrack, enableDefaultTrack_fn).call(this, clone);
        }
      }
    }
  }, _enableDefaultTrack = new WeakSet(), enableDefaultTrack_fn = function(trackEl) {
    if (trackEl && trackEl.localName === "track" && trackEl.default && (trackEl.kind === "chapters" || trackEl.kind === "metadata") && trackEl.track.mode === "disabled") {
      trackEl.track.mode = "hidden";
    }
  }, _upgradeProperty = new WeakSet(), upgradeProperty_fn = function(prop) {
    if (Object.prototype.hasOwnProperty.call(this, prop)) {
      const value = this[prop];
      delete this[prop];
      this[prop] = value;
    }
  }, _forwardAttribute = new WeakSet(), forwardAttribute_fn = function(attrName, _oldValue, newValue) {
    var _a2, _b2, _c2;
    if (["id", "class"].includes(attrName))
      return;
    if (!_c.observedAttributes.includes(attrName) && this.constructor.observedAttributes.includes(attrName)) {
      return;
    }
    if (newValue === null) {
      (_a2 = this.nativeEl) == null ? void 0 : _a2.removeAttribute(attrName);
    } else if (((_b2 = this.nativeEl) == null ? void 0 : _b2.getAttribute(attrName)) !== newValue) {
      (_c2 = this.nativeEl) == null ? void 0 : _c2.setAttribute(attrName, newValue);
    }
  }, __privateAdd(_c, _define), __publicField(_c, "getTemplateHTML", tag.endsWith("audio") ? getAudioTemplateHTML : getVideoTemplateHTML), __publicField(_c, "shadowRootOptions", { mode: "open" }), __publicField(_c, "Events", Events), __privateAdd(_c, _isDefined, false), _c;
}
function getNativeElProps(nativeElTest) {
  const nativeElProps = [];
  for (let proto = Object.getPrototypeOf(nativeElTest); proto && proto !== HTMLElement.prototype; proto = Object.getPrototypeOf(proto)) {
    const props = Object.getOwnPropertyNames(proto);
    nativeElProps.push(...props);
  }
  return nativeElProps;
}
function serializeAttributes(attrs) {
  let html = "";
  for (const key in attrs) {
    if (!Attributes.includes(key))
      continue;
    const value = attrs[key];
    if (value === "")
      html += ` ${key}`;
    else
      html += ` ${key}="${value}"`;
  }
  return html;
}
function namedNodeMapToObject(namedNodeMap) {
  const obj = {};
  for (const attr of namedNodeMap) {
    obj[attr.name] = attr.value;
  }
  return obj;
}
const CustomVideoElement = CustomMediaMixin(globalThis.HTMLElement ?? class {
}, {
  tag: "video"
});
CustomMediaMixin(globalThis.HTMLElement ?? class {
}, {
  tag: "audio"
});
class TrackEvent extends Event {
  constructor(type, init) {
    super(type);
    __publicField(this, "track");
    this.track = init.track;
  }
}
const privateProps = /* @__PURE__ */ new WeakMap();
function getPrivate(instance) {
  return privateProps.get(instance) ?? setPrivate(instance, {});
}
function setPrivate(instance, props) {
  let saved = privateProps.get(instance);
  if (!saved)
    privateProps.set(instance, saved = {});
  return Object.assign(saved, props);
}
function addVideoTrack(media, track) {
  const trackList = media.videoTracks;
  getPrivate(track).media = new WeakRef(media);
  if (!getPrivate(track).renditionSet) {
    getPrivate(track).renditionSet = /* @__PURE__ */ new Set();
  }
  const trackSet = getPrivate(trackList).trackSet;
  trackSet.add(track);
  const index = trackSet.size - 1;
  if (!(index in VideoTrackList.prototype)) {
    Object.defineProperty(VideoTrackList.prototype, index, {
      get() {
        return [...getPrivate(this).trackSet][index];
      }
    });
  }
  queueMicrotask(() => {
    trackList.dispatchEvent(new TrackEvent("addtrack", { track }));
  });
}
function removeVideoTrack(track) {
  var _a, _b;
  const trackList = (_b = (_a = getPrivate(track).media) == null ? void 0 : _a.deref()) == null ? void 0 : _b.videoTracks;
  if (!trackList)
    return;
  const trackSet = getPrivate(trackList).trackSet;
  trackSet.delete(track);
  queueMicrotask(() => {
    trackList.dispatchEvent(new TrackEvent("removetrack", { track }));
  });
}
function selectedChanged$2(selected) {
  var _a, _b;
  const trackList = ((_b = (_a = getPrivate(selected).media) == null ? void 0 : _a.deref()) == null ? void 0 : _b.videoTracks) ?? [];
  let hasUnselected = false;
  for (const track of trackList) {
    if (track === selected)
      continue;
    track.selected = false;
    hasUnselected = true;
  }
  if (hasUnselected) {
    if (getPrivate(trackList).changeRequested)
      return;
    getPrivate(trackList).changeRequested = true;
    queueMicrotask(() => {
      delete getPrivate(trackList).changeRequested;
      trackList.dispatchEvent(new Event("change"));
    });
  }
}
class VideoTrackList extends EventTarget {
  constructor() {
    super();
    __privateAdd(this, _tracks);
    __privateAdd(this, _addTrackCallback, void 0);
    __privateAdd(this, _removeTrackCallback, void 0);
    __privateAdd(this, _changeCallback, void 0);
    getPrivate(this).trackSet = /* @__PURE__ */ new Set();
  }
  [Symbol.iterator]() {
    return __privateGet(this, _tracks, tracks_get).values();
  }
  get length() {
    return __privateGet(this, _tracks, tracks_get).size;
  }
  getTrackById(id) {
    return [...__privateGet(this, _tracks, tracks_get)].find((track) => track.id === id) ?? null;
  }
  get selectedIndex() {
    return [...__privateGet(this, _tracks, tracks_get)].findIndex((track) => track.selected);
  }
  get onaddtrack() {
    return __privateGet(this, _addTrackCallback);
  }
  set onaddtrack(callback) {
    if (__privateGet(this, _addTrackCallback)) {
      this.removeEventListener("addtrack", __privateGet(this, _addTrackCallback));
      __privateSet(this, _addTrackCallback, void 0);
    }
    if (typeof callback == "function") {
      __privateSet(this, _addTrackCallback, callback);
      this.addEventListener("addtrack", callback);
    }
  }
  get onremovetrack() {
    return __privateGet(this, _removeTrackCallback);
  }
  set onremovetrack(callback) {
    if (__privateGet(this, _removeTrackCallback)) {
      this.removeEventListener("removetrack", __privateGet(this, _removeTrackCallback));
      __privateSet(this, _removeTrackCallback, void 0);
    }
    if (typeof callback == "function") {
      __privateSet(this, _removeTrackCallback, callback);
      this.addEventListener("removetrack", callback);
    }
  }
  get onchange() {
    return __privateGet(this, _changeCallback);
  }
  set onchange(callback) {
    if (__privateGet(this, _changeCallback)) {
      this.removeEventListener("change", __privateGet(this, _changeCallback));
      __privateSet(this, _changeCallback, void 0);
    }
    if (typeof callback == "function") {
      __privateSet(this, _changeCallback, callback);
      this.addEventListener("change", callback);
    }
  }
}
_addTrackCallback = new WeakMap();
_removeTrackCallback = new WeakMap();
_changeCallback = new WeakMap();
_tracks = new WeakSet();
tracks_get = function() {
  return getPrivate(this).trackSet;
};
class RenditionEvent extends Event {
  constructor(type, init) {
    super(type);
    __publicField(this, "rendition");
    this.rendition = init.rendition;
  }
}
function addRendition$1(track, rendition) {
  var _a, _b;
  const renditionList = (_b = (_a = getPrivate(track).media) == null ? void 0 : _a.deref()) == null ? void 0 : _b.videoRenditions;
  getPrivate(rendition).media = getPrivate(track).media;
  getPrivate(rendition).track = track;
  const renditionSet = getPrivate(track).renditionSet;
  renditionSet.add(rendition);
  const index = renditionSet.size - 1;
  if (!(index in VideoRenditionList.prototype)) {
    Object.defineProperty(VideoRenditionList.prototype, index, {
      get() {
        return getCurrentRenditions$1(this)[index];
      }
    });
  }
  queueMicrotask(() => {
    if (!renditionList || !track.selected)
      return;
    renditionList.dispatchEvent(new RenditionEvent("addrendition", { rendition }));
  });
}
function removeRendition$1(rendition) {
  var _a, _b;
  const renditionList = (_b = (_a = getPrivate(rendition).media) == null ? void 0 : _a.deref()) == null ? void 0 : _b.videoRenditions;
  const track = getPrivate(rendition).track;
  const renditionSet = getPrivate(track).renditionSet;
  renditionSet.delete(rendition);
  queueMicrotask(() => {
    const track2 = getPrivate(rendition).track;
    if (!renditionList || !track2.selected)
      return;
    renditionList.dispatchEvent(new RenditionEvent("removerendition", { rendition }));
  });
}
function selectedChanged$1(rendition) {
  var _a, _b;
  const renditionList = (_b = (_a = getPrivate(rendition).media) == null ? void 0 : _a.deref()) == null ? void 0 : _b.videoRenditions;
  if (!renditionList || getPrivate(renditionList).changeRequested)
    return;
  getPrivate(renditionList).changeRequested = true;
  queueMicrotask(() => {
    delete getPrivate(renditionList).changeRequested;
    const track = getPrivate(rendition).track;
    if (!track.selected)
      return;
    renditionList.dispatchEvent(new Event("change"));
  });
}
function getCurrentRenditions$1(renditionList) {
  var _a;
  const media = (_a = getPrivate(renditionList).media) == null ? void 0 : _a.deref();
  if (!media)
    return [];
  return [...media.videoTracks].filter((track) => track.selected).flatMap((track) => [...getPrivate(track).renditionSet]);
}
class VideoRenditionList extends EventTarget {
  constructor() {
    super(...arguments);
    __privateAdd(this, _addRenditionCallback, void 0);
    __privateAdd(this, _removeRenditionCallback, void 0);
    __privateAdd(this, _changeCallback2, void 0);
  }
  [Symbol.iterator]() {
    return getCurrentRenditions$1(this).values();
  }
  get length() {
    return getCurrentRenditions$1(this).length;
  }
  getRenditionById(id) {
    return getCurrentRenditions$1(this).find((rendition) => `${rendition.id}` === `${id}`) ?? null;
  }
  get selectedIndex() {
    return getCurrentRenditions$1(this).findIndex((rendition) => rendition.selected);
  }
  set selectedIndex(index) {
    for (const [i, rendition] of getCurrentRenditions$1(this).entries()) {
      rendition.selected = i === index;
    }
  }
  get onaddrendition() {
    return __privateGet(this, _addRenditionCallback);
  }
  set onaddrendition(callback) {
    if (__privateGet(this, _addRenditionCallback)) {
      this.removeEventListener("addrendition", __privateGet(this, _addRenditionCallback));
      __privateSet(this, _addRenditionCallback, void 0);
    }
    if (typeof callback == "function") {
      __privateSet(this, _addRenditionCallback, callback);
      this.addEventListener("addrendition", callback);
    }
  }
  get onremoverendition() {
    return __privateGet(this, _removeRenditionCallback);
  }
  set onremoverendition(callback) {
    if (__privateGet(this, _removeRenditionCallback)) {
      this.removeEventListener("removerendition", __privateGet(this, _removeRenditionCallback));
      __privateSet(this, _removeRenditionCallback, void 0);
    }
    if (typeof callback == "function") {
      __privateSet(this, _removeRenditionCallback, callback);
      this.addEventListener("removerendition", callback);
    }
  }
  get onchange() {
    return __privateGet(this, _changeCallback2);
  }
  set onchange(callback) {
    if (__privateGet(this, _changeCallback2)) {
      this.removeEventListener("change", __privateGet(this, _changeCallback2));
      __privateSet(this, _changeCallback2, void 0);
    }
    if (typeof callback == "function") {
      __privateSet(this, _changeCallback2, callback);
      this.addEventListener("change", callback);
    }
  }
}
_addRenditionCallback = new WeakMap();
_removeRenditionCallback = new WeakMap();
_changeCallback2 = new WeakMap();
class VideoRendition {
  constructor() {
    __publicField(this, "src");
    __publicField(this, "id");
    __publicField(this, "width");
    __publicField(this, "height");
    __publicField(this, "bitrate");
    __publicField(this, "frameRate");
    __publicField(this, "codec");
    __privateAdd(this, _selected, false);
  }
  get selected() {
    return __privateGet(this, _selected);
  }
  set selected(val) {
    if (__privateGet(this, _selected) === val)
      return;
    __privateSet(this, _selected, val);
    selectedChanged$1(this);
  }
}
_selected = new WeakMap();
class VideoTrack {
  constructor() {
    __publicField(this, "id");
    __publicField(this, "kind");
    __publicField(this, "label", "");
    __publicField(this, "language", "");
    __publicField(this, "sourceBuffer");
    __privateAdd(this, _selected2, false);
  }
  addRendition(src, width, height, codec, bitrate, frameRate) {
    const rendition = new VideoRendition();
    rendition.src = src;
    rendition.width = width;
    rendition.height = height;
    rendition.frameRate = frameRate;
    rendition.bitrate = bitrate;
    rendition.codec = codec;
    addRendition$1(this, rendition);
    return rendition;
  }
  removeRendition(rendition) {
    removeRendition$1(rendition);
  }
  get selected() {
    return __privateGet(this, _selected2);
  }
  set selected(val) {
    if (__privateGet(this, _selected2) === val)
      return;
    __privateSet(this, _selected2, val);
    if (val !== true)
      return;
    selectedChanged$2(this);
  }
}
_selected2 = new WeakMap();
function addRendition(track, rendition) {
  var _a, _b;
  const renditionList = (_b = (_a = getPrivate(track).media) == null ? void 0 : _a.deref()) == null ? void 0 : _b.audioRenditions;
  getPrivate(rendition).media = getPrivate(track).media;
  getPrivate(rendition).track = track;
  const renditionSet = getPrivate(track).renditionSet;
  renditionSet.add(rendition);
  const index = renditionSet.size - 1;
  if (!(index in AudioRenditionList.prototype)) {
    Object.defineProperty(AudioRenditionList.prototype, index, {
      get() {
        return getCurrentRenditions(this)[index];
      }
    });
  }
  queueMicrotask(() => {
    if (!renditionList || !track.enabled)
      return;
    renditionList.dispatchEvent(new RenditionEvent("addrendition", { rendition }));
  });
}
function removeRendition(rendition) {
  var _a, _b;
  const renditionList = (_b = (_a = getPrivate(rendition).media) == null ? void 0 : _a.deref()) == null ? void 0 : _b.audioRenditions;
  const track = getPrivate(rendition).track;
  const renditionSet = getPrivate(track).renditionSet;
  renditionSet.delete(rendition);
  queueMicrotask(() => {
    const track2 = getPrivate(rendition).track;
    if (!renditionList || !track2.enabled)
      return;
    renditionList.dispatchEvent(new RenditionEvent("removerendition", { rendition }));
  });
}
function selectedChanged(rendition) {
  var _a, _b;
  const renditionList = (_b = (_a = getPrivate(rendition).media) == null ? void 0 : _a.deref()) == null ? void 0 : _b.audioRenditions;
  if (!renditionList || getPrivate(renditionList).changeRequested)
    return;
  getPrivate(renditionList).changeRequested = true;
  queueMicrotask(() => {
    delete getPrivate(renditionList).changeRequested;
    const track = getPrivate(rendition).track;
    if (!track.enabled)
      return;
    renditionList.dispatchEvent(new Event("change"));
  });
}
function getCurrentRenditions(renditionList) {
  var _a;
  const media = (_a = getPrivate(renditionList).media) == null ? void 0 : _a.deref();
  if (!media)
    return [];
  return [...media.audioTracks].filter((track) => track.enabled).flatMap((track) => [...getPrivate(track).renditionSet]);
}
class AudioRenditionList extends EventTarget {
  constructor() {
    super(...arguments);
    __privateAdd(this, _addRenditionCallback2, void 0);
    __privateAdd(this, _removeRenditionCallback2, void 0);
    __privateAdd(this, _changeCallback3, void 0);
  }
  [Symbol.iterator]() {
    return getCurrentRenditions(this).values();
  }
  get length() {
    return getCurrentRenditions(this).length;
  }
  getRenditionById(id) {
    return getCurrentRenditions(this).find((rendition) => `${rendition.id}` === `${id}`) ?? null;
  }
  get selectedIndex() {
    return getCurrentRenditions(this).findIndex((rendition) => rendition.selected);
  }
  set selectedIndex(index) {
    for (const [i, rendition] of getCurrentRenditions(this).entries()) {
      rendition.selected = i === index;
    }
  }
  get onaddrendition() {
    return __privateGet(this, _addRenditionCallback2);
  }
  set onaddrendition(callback) {
    if (__privateGet(this, _addRenditionCallback2)) {
      this.removeEventListener("addrendition", __privateGet(this, _addRenditionCallback2));
      __privateSet(this, _addRenditionCallback2, void 0);
    }
    if (typeof callback == "function") {
      __privateSet(this, _addRenditionCallback2, callback);
      this.addEventListener("addrendition", callback);
    }
  }
  get onremoverendition() {
    return __privateGet(this, _removeRenditionCallback2);
  }
  set onremoverendition(callback) {
    if (__privateGet(this, _removeRenditionCallback2)) {
      this.removeEventListener("removerendition", __privateGet(this, _removeRenditionCallback2));
      __privateSet(this, _removeRenditionCallback2, void 0);
    }
    if (typeof callback == "function") {
      __privateSet(this, _removeRenditionCallback2, callback);
      this.addEventListener("removerendition", callback);
    }
  }
  get onchange() {
    return __privateGet(this, _changeCallback3);
  }
  set onchange(callback) {
    if (__privateGet(this, _changeCallback3)) {
      this.removeEventListener("change", __privateGet(this, _changeCallback3));
      __privateSet(this, _changeCallback3, void 0);
    }
    if (typeof callback == "function") {
      __privateSet(this, _changeCallback3, callback);
      this.addEventListener("change", callback);
    }
  }
}
_addRenditionCallback2 = new WeakMap();
_removeRenditionCallback2 = new WeakMap();
_changeCallback3 = new WeakMap();
class AudioRendition {
  constructor() {
    __publicField(this, "src");
    __publicField(this, "id");
    __publicField(this, "bitrate");
    __publicField(this, "codec");
    __privateAdd(this, _selected3, false);
  }
  get selected() {
    return __privateGet(this, _selected3);
  }
  set selected(val) {
    if (__privateGet(this, _selected3) === val)
      return;
    __privateSet(this, _selected3, val);
    selectedChanged(this);
  }
}
_selected3 = new WeakMap();
function addAudioTrack(media, track) {
  const trackList = media.audioTracks;
  getPrivate(track).media = new WeakRef(media);
  if (!getPrivate(track).renditionSet) {
    getPrivate(track).renditionSet = /* @__PURE__ */ new Set();
  }
  const trackSet = getPrivate(trackList).trackSet;
  trackSet.add(track);
  const index = trackSet.size - 1;
  if (!(index in AudioTrackList.prototype)) {
    Object.defineProperty(AudioTrackList.prototype, index, {
      get() {
        return [...getPrivate(this).trackSet][index];
      }
    });
  }
  queueMicrotask(() => {
    trackList.dispatchEvent(new TrackEvent("addtrack", { track }));
  });
}
function removeAudioTrack(track) {
  var _a, _b;
  const trackList = (_b = (_a = getPrivate(track).media) == null ? void 0 : _a.deref()) == null ? void 0 : _b.audioTracks;
  if (!trackList)
    return;
  const trackSet = getPrivate(trackList).trackSet;
  trackSet.delete(track);
  queueMicrotask(() => {
    trackList.dispatchEvent(new TrackEvent("removetrack", { track }));
  });
}
function enabledChanged(track) {
  var _a, _b;
  const trackList = (_b = (_a = getPrivate(track).media) == null ? void 0 : _a.deref()) == null ? void 0 : _b.audioTracks;
  if (!trackList || getPrivate(trackList).changeRequested)
    return;
  getPrivate(trackList).changeRequested = true;
  queueMicrotask(() => {
    delete getPrivate(trackList).changeRequested;
    trackList.dispatchEvent(new Event("change"));
  });
}
class AudioTrackList extends EventTarget {
  constructor() {
    super();
    __privateAdd(this, _tracks2);
    __privateAdd(this, _addTrackCallback2, void 0);
    __privateAdd(this, _removeTrackCallback2, void 0);
    __privateAdd(this, _changeCallback4, void 0);
    getPrivate(this).trackSet = /* @__PURE__ */ new Set();
  }
  [Symbol.iterator]() {
    return __privateGet(this, _tracks2, tracks_get2).values();
  }
  get length() {
    return __privateGet(this, _tracks2, tracks_get2).size;
  }
  getTrackById(id) {
    return [...__privateGet(this, _tracks2, tracks_get2)].find((track) => track.id === id) ?? null;
  }
  get onaddtrack() {
    return __privateGet(this, _addTrackCallback2);
  }
  set onaddtrack(callback) {
    if (__privateGet(this, _addTrackCallback2)) {
      this.removeEventListener("addtrack", __privateGet(this, _addTrackCallback2));
      __privateSet(this, _addTrackCallback2, void 0);
    }
    if (typeof callback == "function") {
      __privateSet(this, _addTrackCallback2, callback);
      this.addEventListener("addtrack", callback);
    }
  }
  get onremovetrack() {
    return __privateGet(this, _removeTrackCallback2);
  }
  set onremovetrack(callback) {
    if (__privateGet(this, _removeTrackCallback2)) {
      this.removeEventListener("removetrack", __privateGet(this, _removeTrackCallback2));
      __privateSet(this, _removeTrackCallback2, void 0);
    }
    if (typeof callback == "function") {
      __privateSet(this, _removeTrackCallback2, callback);
      this.addEventListener("removetrack", callback);
    }
  }
  get onchange() {
    return __privateGet(this, _changeCallback4);
  }
  set onchange(callback) {
    if (__privateGet(this, _changeCallback4)) {
      this.removeEventListener("change", __privateGet(this, _changeCallback4));
      __privateSet(this, _changeCallback4, void 0);
    }
    if (typeof callback == "function") {
      __privateSet(this, _changeCallback4, callback);
      this.addEventListener("change", callback);
    }
  }
}
_addTrackCallback2 = new WeakMap();
_removeTrackCallback2 = new WeakMap();
_changeCallback4 = new WeakMap();
_tracks2 = new WeakSet();
tracks_get2 = function() {
  return getPrivate(this).trackSet;
};
class AudioTrack {
  constructor() {
    __publicField(this, "id");
    __publicField(this, "kind");
    __publicField(this, "label", "");
    __publicField(this, "language", "");
    __publicField(this, "sourceBuffer");
    __privateAdd(this, _enabled, false);
  }
  addRendition(src, codec, bitrate) {
    const rendition = new AudioRendition();
    rendition.src = src;
    rendition.codec = codec;
    rendition.bitrate = bitrate;
    addRendition(this, rendition);
    return rendition;
  }
  removeRendition(rendition) {
    removeRendition(rendition);
  }
  get enabled() {
    return __privateGet(this, _enabled);
  }
  set enabled(val) {
    if (__privateGet(this, _enabled) === val)
      return;
    __privateSet(this, _enabled, val);
    enabledChanged(this);
  }
}
_enabled = new WeakMap();
const nativeVideoTracksFn = getBaseMediaTracksFn(globalThis.HTMLMediaElement, "video");
const nativeAudioTracksFn = getBaseMediaTracksFn(globalThis.HTMLMediaElement, "audio");
function MediaTracksMixin(MediaElementClass) {
  if (!(MediaElementClass == null ? void 0 : MediaElementClass.prototype))
    return MediaElementClass;
  const videoTracksFn = getBaseMediaTracksFn(MediaElementClass, "video");
  if (!videoTracksFn || `${videoTracksFn}`.includes("[native code]")) {
    Object.defineProperty(MediaElementClass.prototype, "videoTracks", {
      get() {
        return getVideoTracks(this);
      }
    });
  }
  const audioTracksFn = getBaseMediaTracksFn(MediaElementClass, "audio");
  if (!audioTracksFn || `${audioTracksFn}`.includes("[native code]")) {
    Object.defineProperty(MediaElementClass.prototype, "audioTracks", {
      get() {
        return getAudioTracks(this);
      }
    });
  }
  if (!("addVideoTrack" in MediaElementClass.prototype)) {
    MediaElementClass.prototype.addVideoTrack = function(kind, label = "", language = "") {
      const track = new VideoTrack();
      track.kind = kind;
      track.label = label;
      track.language = language;
      addVideoTrack(this, track);
      return track;
    };
  }
  if (!("removeVideoTrack" in MediaElementClass.prototype)) {
    MediaElementClass.prototype.removeVideoTrack = removeVideoTrack;
  }
  if (!("addAudioTrack" in MediaElementClass.prototype)) {
    MediaElementClass.prototype.addAudioTrack = function(kind, label = "", language = "") {
      const track = new AudioTrack();
      track.kind = kind;
      track.label = label;
      track.language = language;
      addAudioTrack(this, track);
      return track;
    };
  }
  if (!("removeAudioTrack" in MediaElementClass.prototype)) {
    MediaElementClass.prototype.removeAudioTrack = removeAudioTrack;
  }
  if (!("videoRenditions" in MediaElementClass.prototype)) {
    Object.defineProperty(MediaElementClass.prototype, "videoRenditions", {
      get() {
        return initVideoRenditions(this);
      }
    });
  }
  const initVideoRenditions = (media) => {
    let renditions = getPrivate(media).videoRenditions;
    if (!renditions) {
      renditions = new VideoRenditionList();
      getPrivate(renditions).media = new WeakRef(media);
      getPrivate(media).videoRenditions = renditions;
    }
    return renditions;
  };
  if (!("audioRenditions" in MediaElementClass.prototype)) {
    Object.defineProperty(MediaElementClass.prototype, "audioRenditions", {
      get() {
        return initAudioRenditions(this);
      }
    });
  }
  const initAudioRenditions = (media) => {
    let renditions = getPrivate(media).audioRenditions;
    if (!renditions) {
      renditions = new AudioRenditionList();
      getPrivate(renditions).media = new WeakRef(media);
      getPrivate(media).audioRenditions = renditions;
    }
    return renditions;
  };
  return MediaElementClass;
}
function getBaseMediaTracksFn(MediaElementClass, type) {
  var _a;
  if (MediaElementClass == null ? void 0 : MediaElementClass.prototype) {
    return (_a = Object.getOwnPropertyDescriptor(MediaElementClass.prototype, `${type}Tracks`)) == null ? void 0 : _a.get;
  }
}
function getVideoTracks(media) {
  let tracks = getPrivate(media).videoTracks;
  if (!tracks) {
    tracks = new VideoTrackList();
    getPrivate(media).videoTracks = tracks;
    if (nativeVideoTracksFn) {
      const nativeTracks = nativeVideoTracksFn.call(media.nativeEl ?? media);
      for (const nativeTrack of nativeTracks) {
        addVideoTrack(media, nativeTrack);
      }
      const onChange = () => {
        tracks.dispatchEvent(new Event("change"));
      };
      const onAddTrack = (event) => {
        if ([...tracks].some((t) => t instanceof VideoTrack)) {
          for (const nativeTrack of nativeTracks) {
            removeVideoTrack(nativeTrack);
          }
          return;
        }
        addVideoTrack(media, event.track);
      };
      const onRemoveTrack = (event) => {
        removeVideoTrack(event.track);
      };
      nativeTracks.addEventListener("change", onChange);
      nativeTracks.addEventListener("addtrack", onAddTrack);
      nativeTracks.addEventListener("removetrack", onRemoveTrack);
    }
  }
  return tracks;
}
function getAudioTracks(media) {
  let tracks = getPrivate(media).audioTracks;
  if (!tracks) {
    tracks = new AudioTrackList();
    getPrivate(media).audioTracks = tracks;
    if (nativeAudioTracksFn) {
      const nativeTracks = nativeAudioTracksFn.call(media.nativeEl ?? media);
      for (const nativeTrack of nativeTracks) {
        addAudioTrack(media, nativeTrack);
      }
      const onChange = () => {
        tracks.dispatchEvent(new Event("change"));
      };
      const onAddTrack = (event) => {
        if ([...tracks].some((t) => t instanceof AudioTrack)) {
          for (const nativeTrack of nativeTracks) {
            removeAudioTrack(nativeTrack);
          }
          return;
        }
        addAudioTrack(media, event.track);
      };
      const onRemoveTrack = (event) => {
        removeAudioTrack(event.track);
      };
      nativeTracks.addEventListener("change", onChange);
      nativeTracks.addEventListener("addtrack", onAddTrack);
      nativeTracks.addEventListener("removetrack", onRemoveTrack);
    }
  }
  return tracks;
}
export {
  CustomVideoElement as C,
  MediaTracksMixin as M
};
