import { r as registerInstance, h, H as Host, g as getElement, c as createEvent } from './index-980f930f.js';
import { c as classnames } from './index-c3e4004b.js';
import { t as throttle } from './index-d1b03e47.js';

const formatTime = (time) => {
  if (!time)
    return '';
  const sec = Math.round(time % 60);
  const min = Math.round((time - sec) / 60);
  return `${min < 10 ? `0${min}` : min}:${sec < 10 ? `0${sec}` : sec}`;
};
const calcDist = (x, y) => {
  return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
};
const normalizeNumber = (number) => {
  return Math.max(-1, Math.min(number, 1));
};
let scene = 'default';
const screenFn = (function () {
  let val;
  const fnMap = [
    [
      'requestFullscreen',
      'exitFullscreen',
      'fullscreenElement',
      'fullscreenEnabled',
      'fullscreenchange',
      'fullscreenerror'
    ],
    // New WebKit
    [
      'webkitRequestFullscreen',
      'webkitExitFullscreen',
      'webkitFullscreenElement',
      'webkitFullscreenEnabled',
      'webkitfullscreenchange',
      'webkitfullscreenerror'
    ],
    // Old WebKit
    [
      'webkitRequestFullScreen',
      'webkitCancelFullScreen',
      'webkitCurrentFullScreenElement',
      'webkitCancelFullScreen',
      'webkitfullscreenchange',
      'webkitfullscreenerror'
    ],
    [
      'mozRequestFullScreen',
      'mozCancelFullScreen',
      'mozFullScreenElement',
      'mozFullScreenEnabled',
      'mozfullscreenchange',
      'mozfullscreenerror'
    ],
    [
      'msRequestFullscreen',
      'msExitFullscreen',
      'msFullscreenElement',
      'msFullscreenEnabled',
      'MSFullscreenChange',
      'MSFullscreenError'
    ]
  ];
  var defaultIOSMap = [
    'webkitEnterFullscreen',
    'webkitExitFullscreen',
    'webkitCurrentFullScreenElement',
    'webkitSupportsFullscreen',
    'fullscreenchange',
    'fullscreenerror'
  ];
  let i = 0;
  const l = fnMap.length;
  const ret = {};
  // This for loop essentially checks the current document object for the property/methods above.
  for (; i < l; i++) {
    val = fnMap[i];
    if (val && val[1] in document) {
      for (i = 0; i < val.length; i++) {
        ret[fnMap[0][i]] = val[i];
      }
      return ret;
    }
  }
  if (!ret[fnMap[0][0]]) {
    scene = 'iOS';
    // when there is no any APIs be set.
    // In IOS, there is no 'webkitEnterFullscreen' property `in document` but video can use it for fullscreen.
    // ref: https://developer.apple.com/documentation/webkitjs/htmlvideoelement/1633500-webkitenterfullscreen
    for (i = 0; i < defaultIOSMap.length; i++) {
      ret[fnMap[0][i]] = defaultIOSMap[i];
    }
  }
  // If it doesn't find any of them, this whole function returns {}
  // and the fn variable is set to this returned value.
  return ret;
})();
const isHls = url => /\.(m3u8)($|\?)/i.test(url);

const VideoControl = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.visible = false;
    this.isDraggingProgressBall = false;
    this.percentage = 0;
    this.progressDimensions = {
      left: 0,
      width: 0
    };
    this.calcPercentage = (pageX) => {
      let pos = pageX - this.progressDimensions.left;
      pos = Math.max(pos, 0);
      pos = Math.min(pos, this.progressDimensions.width);
      return pos / this.progressDimensions.width;
    };
    this.onDragProgressBallStart = () => {
      this.isDraggingProgressBall = true;
      this.hideControlsTimer && clearTimeout(this.hideControlsTimer);
    };
    this.onClickProgress = (e) => {
      e.stopPropagation();
      const percentage = this.calcPercentage(e.pageX);
      this.seekFunc(percentage * this.duration);
      this.toggleVisibility(true);
    };
    this.controls = undefined;
    this.currentTime = undefined;
    this.duration = undefined;
    this.isPlaying = undefined;
    this.pauseFunc = undefined;
    this.playFunc = undefined;
    this.seekFunc = undefined;
    this.showPlayBtn = undefined;
    this.showProgress = undefined;
  }
  onDocumentTouchMove(e) {
    if (!this.isDraggingProgressBall)
      return;
    const touchX = e.touches[0].pageX;
    this.percentage = this.calcPercentage(touchX);
    this.setProgressBall(this.percentage);
    this.setCurrentTime(this.percentage * this.duration);
  }
  onDocumentTouchEnd() {
    if (!this.isDraggingProgressBall)
      return;
    this.isDraggingProgressBall = false;
    this.seekFunc(this.percentage * this.duration);
    this.toggleVisibility(true);
  }
  async setProgressBall(percentage) {
    if (this.progressBallRef) {
      this.progressBallRef.style.left = `${percentage * 100}%`;
    }
  }
  async toggleVisibility(nextVisible) {
    const visible = nextVisible === undefined ? !this.visible : nextVisible;
    if (visible) {
      this.hideControlsTimer && clearTimeout(this.hideControlsTimer);
      if (this.isPlaying) {
        this.hideControlsTimer = setTimeout(() => {
          this.toggleVisibility(false);
        }, 2000);
      }
      this.el.style.visibility = 'visible';
    }
    else {
      this.el.style.visibility = 'hidden';
    }
    this.visible = !!visible;
  }
  async getIsDraggingProgressBall() {
    return this.isDraggingProgressBall;
  }
  async setCurrentTime(time) {
    this.currentTimeRef.innerHTML = formatTime(time);
  }
  render() {
    const { controls, currentTime, duration, isPlaying, pauseFunc, playFunc, showPlayBtn, showProgress } = this;
    const formattedDuration = formatTime(duration);
    let playBtn;
    if (!showPlayBtn) {
      playBtn = null;
    }
    else if (isPlaying) {
      playBtn = h("div", { class: 'taro-video-control-button taro-video-control-button-pause', onClick: pauseFunc });
    }
    else {
      playBtn = h("div", { class: 'taro-video-control-button taro-video-control-button-play', onClick: playFunc });
    }
    return (h(Host, { class: 'taro-video-bar taro-video-bar-full' }, controls && (h("div", { class: 'taro-video-controls' }, playBtn, showProgress && (h("div", { class: 'taro-video-current-time', ref: dom => (this.currentTimeRef = dom) }, formatTime(currentTime))), showProgress && (h("div", { class: 'taro-video-progress-container', onClick: this.onClickProgress }, h("div", { class: 'taro-video-progress', ref: ref => {
        if (!ref)
          return;
        const rect = ref.getBoundingClientRect();
        this.progressDimensions.left = rect.left;
        this.progressDimensions.width = rect.width;
      } }, h("div", { class: 'taro-video-progress-buffered', style: { width: '100%' } }), h("div", { class: 'taro-video-ball', ref: dom => (this.progressBallRef = dom), onTouchStart: this.onDragProgressBallStart, style: {
        left: `${formattedDuration ? (this.currentTime / duration) * 100 : 0}%`
      } }, h("div", { class: 'taro-video-inner' }))))), showProgress && h("div", { class: 'taro-video-duration' }, formattedDuration))), h("slot", null)));
  }
  get el() { return getElement(this); }
};

const indexCss = ".taro-video{display:inline-block;overflow:hidden;position:relative;width:100%;height:225px;line-height:0}.taro-video[hidden]{display:none}.taro-video-container{display:inline-block;position:absolute;left:0;top:0;width:100%;height:100%;background-color:#000;-o-object-position:inherit;object-position:inherit}.taro-video-container.taro-video-type-fullscreen{position:fixed;left:0;right:0;top:0;bottom:0;z-index:999}.taro-video-container.taro-video-type-fullscreen.taro-video-type-rotate-left{-webkit-transform:translate(-50%, -50%) rotate(-90deg);transform:translate(-50%, -50%) rotate(-90deg)}.taro-video-container.taro-video-type-fullscreen.taro-video-type-rotate-right{-webkit-transform:translate(-50%, -50%) rotate(90deg);transform:translate(-50%, -50%) rotate(90deg)}.taro-video-video{width:100%;height:100%;-o-object-position:inherit;object-position:inherit;display:block}.taro-video-cover{display:-ms-flexbox;display:flex;position:absolute;left:0;top:0;bottom:0;z-index:1;-ms-flex-direction:column;flex-direction:column;-ms-flex-pack:center;justify-content:center;-ms-flex-align:center;align-items:center;width:100%;background-color:rgba(1, 1, 1, 0.5);-webkit-box-orient:vertical;-webkit-box-direction:normal;-webkit-box-pack:center;-webkit-box-align:center}.taro-video-cover-play-button{width:40px;height:40px;background-repeat:no-repeat;background-position:50% 50%;background-size:50%}.taro-video-cover-duration{margin-top:10px;line-height:1;font-size:16px;color:#fff}.taro-video-bar{display:-ms-flexbox;display:flex;visibility:hidden;overflow:hidden;position:absolute;right:0;bottom:0;z-index:1;-ms-flex-align:center;align-items:center;padding:0 10px;height:44px;background-color:rgba(0, 0, 0, 0.5);-webkit-box-align:center}.taro-video-bar.taro-video-bar-full{left:0}.taro-video-controls{display:-ms-flexbox;display:flex;-webkit-box-flex:1;-ms-flex-positive:1;flex-grow:1;margin:0 8.5px}.taro-video-control-button{-webkit-box-sizing:content-box;box-sizing:content-box;margin-left:-8.5px;padding:14.5px 12.5px;width:13px;height:15px}.taro-video-control-button::after{display:block;width:100%;height:100%;background-repeat:no-repeat;background-position:50% 50%;background-size:100%;content:\"\"}.taro-video-control-button.taro-video-control-button-play::after,.taro-video-cover-play-button{background-image:url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAeCAYAAAAy2w7YAAAAAXNSR0IArs4c6QAAAWhJREFUSA1j+P///0cgBoHjQGzCQCsAtgJB/AMy5wCxGNXtQ9iBwvoA5BUCMQvVLEQxHpNzDSjkRhXLMM3GKrIeKKpEkYVYjcUu+AMo3ALE3GRZiN1MvKKPgbIRJFuG10j8koeA0gZEW4jfLIKyf4EqpgOxMEELCRpFnIJ3QGU5QMyM00LizCFa1SWgSkeslhFtBGkKVwGVy6FYSJp+klR/A6quB2JOkIWMIK0oNlOf8xBoZDE9LAI7nYn6HsBq4l96WHQEaLUpAyiOaASeAM2NgvuPBpaACt82IEYtfKls0UagecpwXyAzqGTRdaA57sjmYrAptAjUsCkGYlYMg9EFyLQI1IiZB8Ti6Obh5JNh0QmgHlOcBuKSIMGi50C18UDMiMssvOJEWPQLqKYbiHnxGkRIkoBF24DyaoTMIEoeh0W3geI+RBlArCI0iz4D+RVAzEasfqLVAQ19AcSg5LoYiKWI1kiiQgCMBLnEEcfDSgAAAABJRU5ErkJggg==\")}.taro-video-control-button.taro-video-control-button-pause::after{background-image:url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAAgCAYAAAAffCjxAAAAAXNSR0IArs4c6QAAAFlJREFUSA3tksEKACAIQ7X//5zq98wOgQayum8QaGweHhMzG/6OujzKAymn+0LMqivu1XznWmX8/echTIyMyAgTwA72iIwwAexgj8gIE8CO3aMRbDPMaEy5BRGaKcZv8YxRAAAAAElFTkSuQmCC\")}.taro-video-current-time,.taro-video-duration{margin-top:15px;margin-bottom:14.5px;height:14.5px;line-height:14.5px;font-size:12px;color:#cbcbcb}.taro-video-progress-container{position:relative;-ms-flex-positive:2;flex-grow:2;-webkit-box-flex:2}.taro-video-progress{position:relative;margin:21px 12px;height:2px;background-color:rgba(255, 255, 255, 0.4)}.taro-video-progress-buffered{position:absolute;left:0;top:0;width:0;height:100%;background-color:rgba(255, 255, 255, 0.8);-webkit-transition:width 0.1s;transition:width 0.1s}.taro-video-ball{position:absolute;left:0;top:-21px;-webkit-box-sizing:content-box;box-sizing:content-box;margin-left:-22px;padding:14px;width:16px;height:16px}.taro-video-inner{border-radius:50%;width:100%;height:100%;background-color:#fff}.taro-video-danmu-button{margin:0 8.5px;padding:2px 10px;border:1px solid #fff;border-radius:5px;line-height:1;font-size:13px;color:#fff;white-space:nowrap}.taro-video-danmu-button.taro-video-danmu-button-active{border-color:#48c23d;color:#48c23d}.taro-video-fullscreen,.taro-video-mute{-webkit-box-sizing:content-box;box-sizing:content-box;padding:8.5px;width:17px;height:17px;background-repeat:no-repeat;background-position:50% 50%;background-size:50%}.taro-video-fullscreen{background-image:url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAhUlEQVRYR+2WSwrAMAhEnZO3PfmULLooGEFTiIXJ2s/kRY2wzQeb85sE9CRA8jSzY1YfAFzhJBnU1AVgxH2dSiArCnD9QgGzRNnOech48SRABHoSyFb5in3PSbhyo6yvCPQkEM3u7BsPe/0FIvBfAh/vhKmVbO9SWun1qk/PSVi9TcVPBG6R1YIhgWwNpQAAAABJRU5ErkJggg==\")}.taro-video-fullscreen.taro-video-type-fullscreen{background-image:url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABPUlEQVRYR+2Xu0pDURBF1/ZLxNcHKNiIlfhA7C0UBSEE8RNEBNFPUEQEEbGxFiSSSrCwEHsf5E/ccsSUuWfUhKQ40947+y42Z8+ZK/pcinzf9hhwD1xJ2q/qsb0JHAOzkl5y+lGAGnCWICQtZgAS6DxQk3TeLYA6cAo0JSXxjmW7CcwBdUkJurKiDhSA4kBvHbA9CqwBQx2O7BSw8ssU3ALPFRF4knT3nQLbr8B4LjLBOdAAFgJaLUkjbYC9n+zm+i4kXWbmwCqwnRMCHiXthuZAQOzPrxSA4kBxYDAcsH0EzATCfCLpJjOINoCtgFZabg7bk7AFDAeaGpKWgitZTu5N0kQbYBmYrujo9mX0CVxL+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FdnQ6Y2hhbmdlZD0iLyIvPiA8L3JkZjpTZXE+IDwveG1wTU06SGlzdG9yeT4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz459+FoAAABqElEQVRYhc2XPWsVQRSGnxPjF4oGRfxoRQKGWCU2Ft7CykrQWosEyf/If0hhIPgHDEmbNJZqCFxiQEgTUGxsBUVEHgvnyrjZZJO92V1fGIaZnTPvszPszNlQ6VIjnbr/DwCoDLMNak/dUVfUK0f2rQugnlcX/FevWgFQH6gf3autRgHUC+piiXHzAOmtPx9gXgug8itQx9SXwDpw47AGKXZWvXvQmNFCwE3gCXA2dY0Az4GrRzHONA9cU/vAbERsllEOyh31e8USV2mrMPdG9uyn+rDom2/BHHCm5puWKiKmgdtAnz+rvaxO5mNygEvHaZ5BfADuARvAaWBpP4DGFBHfgBngFzClTrUKkCDeA+9S837rAEnbqb7VFcCpVJ/oCmCw959aB1AfAROpudYqgDoOLKRmPyLelAF8bcD4pPoMeAtcB34AT4uDBqXXwFG8XXUU/72MIuK1OgE8Bs6l7mEvo8up7lN1Ge0n9aK6VHMFZvJTr9S3CiALaCQhqZOSvegMIAvu2UVSWpigLC1fbQ0gm6in7qpfLCQbhwGIYcyPQ53/G3YO8BtUtd35bvKcVwAAAABJRU5ErkJggg==\")}.taro-video-mute.taro-video-type-mute{background-image:url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACIAAAAgCAYAAAB3j6rJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAGAGlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxNDAgNzkuMTYwNDUxLCAyMDE3L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lMPcBt4GC3HUYEaj9wF3gVEVPtfNVTwAXgWX7CDKq/1piAZTSZBmim8qJ6sQ3EgDqb/L7kU3MH2NHtl3dQX3r3Ak21UYAYAj4A/cl0JB+RF+uMRj4iQ+p8zt7KYFLdXKHuRi0gacBhV6a6pd5bA6KRNagFJPU9qv5u47toLmW1HnoR8Q5oAK1CVQu4FBHj/wUkaXsb+4pzpVaQFPqXrN7Be4Fx9VztIOr1BLEtmX4A94E/qdwHTKjDWYM6lu81dSlnn3V570BtuLxaMs2rZ/IgYxsBovaoPwsQA4VoFWEm8ql5DiysNyURsQTMpOIMcDYiPhd8xoGr/FtNC2G6FKXD6ihwGdiVHMoeeh8jYlA9ANwE3kTEp3bO6vE03qOONzR1r/q4RGrquaFFxFxE3ALOA9+6jExpdb180y55AhirhaRTatq0GXEzL8+ZIuI9cBJ4WKiartJf9nWV/mty7UfUafW7erpqRGI9EBuprffvu9n6C1KOmsqwI5A1AAAAAElFTkSuQmCC\")}.taro-video-danmu{overflow:visible;position:absolute;left:0;top:0;bottom:0;margin-top:14px;margin-bottom:44px;width:100%;line-height:14px;font-size:14px}.taro-video-danmu-item{position:absolute;left:100%;line-height:1;color:#fff;white-space:nowrap;-webkit-transform:translateX(0);transform:translateX(0);-webkit-transition-property:left, -webkit-transform;transition-property:left, -webkit-transform;transition-property:left, transform;transition-property:left, transform, -webkit-transform;-webkit-transition-duration:3s;transition-duration:3s;-webkit-transition-timing-function:linear;transition-timing-function:linear}.taro-video-toast{display:block;visibility:hidden;position:absolute;left:50%;top:50%;border-radius:5px;background-color:rgba(255, 255, 255, 0.8);pointer-events:none;color:#000;-webkit-transform:translate(-50%, -50%);transform:translate(-50%, -50%)}.taro-video-toast.taro-video-toast-volume{display:block;width:100px;height:100px}.taro-video-toast-volume .taro-video-toast-title{display:block;margin-top:10px;width:100%;line-height:16px;text-align:center;font-size:12px}.taro-video-toast-volume .taro-video-toast-icon{display:block;margin-left:25%;width:50%;height:50%;background-image:url(\"data:image/png;base64,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ZIF9OlKm36QyQV7jEqDDJk5VD58uFgGIGX1Se+6yJFqAKsqI6X84GdDb4Mh0Y5zUqjFYFakUTCXja5QLSmBQHbAL8ahAgT1AeYVreSKLLphGwF/CuAfLJQLldGSTFD75c5d4mNCoWyAqG9gYWGED1AOMKo12ZbiWA/idA++deY2DVTZ0Jh5UJPsFQtD/wDaAHGWl5EzgwaUi2gK4UXS11S0cTIjrMFBtYQdAk4DID0BnAAz4B6wNLgTKKG0VIDBHwqitwpOcW+OOB540FdeipNKbUWFrUtn06o5xOij4KyDuqU0IE3Obl/rLA63pTzm9XA8jKACjdniZAaSKFmUpB1yUhAlTsUEpMh913wEkuTe7rKTzPAHqO44vpKPkFhH3cWWBVV6ogJVYZUgz/tXtIYelzI3Ct0fExIGx6j7iKWBUUveyYBehv1RIjIEsfqziq8Xp4pSBJOYTVJFQcVY3wCFeKUjVGyYfQWB00+5bEVBECrNS+qsOKBpVHNCVWHs+LS7H5PV5pOu9v0+OKEOAXR39w1e1C7wM6AkJ1eLmkRcrpRQiQrqobXO5S3vL3/4kBKMsCknV0k+iasVLUMV3UX5SAPGtED8EOT+L9YENnCasUIXNO2goChFWHqAIRyxXN4qI1BCQg9dJESYq8LnbrCBAR8t50Lig6i0krCRBoVWhVlt45wkBrCRBuRZyPuAguxIPe9lXqhpd9DcZMXOvdkPF0Xu/8dohNUmZ/1QQkuitXr+d4fryuFx3jywQYm6suAqSX8vLTXKJDt4QqO6rtLYspXWZ/nQQkOJTAUJZGIav19q9MvKvN1RUIWKMAY5P3EBBjqO393d4C/gMVHwRQlpx21QAAAABJRU5ErkJggg==\");background-repeat:no-repeat;background-position:50% 50%;background-size:50%;fill:#000}.taro-video-toast-volume .taro-video-toast-value{margin-left:10px;margin-top:5px;width:80px;height:5px}.taro-video-toast-volume .taro-video-toast-value>.taro-video-toast-value-content{overflow:hidden}.taro-video-toast-volume-grids{width:80px;height:5px}.taro-video-toast-volume-grids-item{float:left;width:7.1px;height:5px;background-color:#000}.taro-video-toast-volume-grids-item:not(:first-child){margin-left:1px}.taro-video-toast.taro-video-toast-progress{padding:6px;background-color:rgba(0, 0, 0, 0.8);line-height:18px;font-size:14px;color:#fff}";

const Video = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.onPlay = createEvent(this, "play", 7);
    this.onPause = createEvent(this, "pause", 7);
    this.onEnded = createEvent(this, "ended", 7);
    this.onTimeUpdate = createEvent(this, "timeupdate", 7);
    this.onError = createEvent(this, "error", 7);
    this.onFullScreenChange = createEvent(this, "fullscreenchange", 7);
    this.onProgress = createEvent(this, "progress", 7);
    this.onLoadedMetaData = createEvent(this, "loadedmetadata", 7);
    this.currentTime = 0;
    this.isDraggingProgress = false;
    this.gestureType = 'none';
    this.analyzeGesture = (e) => {
      var _a;
      const obj = {
        type: 'none'
      };
      const nowX = e.touches[0].screenX;
      const nowY = e.touches[0].screenY;
      const distX = nowX - this.lastTouchScreenX;
      const distY = nowY - this.lastTouchScreenY;
      const enableVslideGesture = this.isFullScreen ? this.vslideGestureInFullscreen : this.vslideGesture;
      if (this.gestureType === 'none') {
        // 两点间距离
        const dist = calcDist(distX, distY);
        // 没有移动
        if (dist < 10)
          return obj;
        if (Math.abs(distY) >= Math.abs(distX)) {
          // 垂直方向移动：调整音量
          if (enableVslideGesture) {
            this.gestureType = 'adjustVolume';
            this.lastVolume = this.videoRef.volume;
          }
          else {
            return obj;
          }
        }
        else if (Math.abs(distY) < Math.abs(distX)) {
          // 水平方向移动：调整进度
          if (this.enableProgressGesture) {
            this.gestureType = 'adjustProgress';
            this.lastPercentage = this.currentTime / ((_a = this.duration) !== null && _a !== void 0 ? _a : this._duration);
          }
          else {
            return obj;
          }
        }
      }
      obj.type = this.gestureType;
      obj.dataX = normalizeNumber(distX / 200);
      obj.dataY = normalizeNumber(distY / 200);
      return obj;
    };
    this.loadNativePlayer = () => {
      var _a, _b;
      if (this.videoRef) {
        this.videoRef.src = this.src;
        (_b = (_a = this.videoRef).load) === null || _b === void 0 ? void 0 : _b.call(_a);
      }
    };
    this.init = () => {
      const { src, videoRef } = this;
      if (isHls(src)) {
        import(
        /* webpackExports: ["default"] */
        './hls-4018c7ea.js').then(e => {
          const Hls = e.default;
          this.HLS = Hls;
          if (Hls.isSupported()) {
            if (this.hls) {
              this.hls.destroy();
            }
            this.hls = new Hls();
            this.hls.loadSource(src);
            this.hls.attachMedia(videoRef);
            this.hls.on(Hls.Events.MANIFEST_PARSED, () => {
              this.autoplay && this.play();
            });
            this.hls.on(Hls.Events.ERROR, (_, data) => {
              this.handleError(data);
            });
          }
          else if (videoRef.canPlayType('application/vnd.apple.mpegurl')) {
            this.loadNativePlayer();
          }
          else {
            console.error('该浏览器不支持 HLS 播放');
          }
        });
      }
      else {
        this.loadNativePlayer();
      }
    };
    this.handlePlay = () => {
      this.isPlaying = true;
      this.isFirst = false;
      this.controlsRef.toggleVisibility(true);
      this.onPlay.emit();
    };
    this.handlePause = () => {
      this.isPlaying = false;
      this.controlsRef.toggleVisibility(true);
      this.onPause.emit();
    };
    this.handleEnded = () => {
      this.isFirst = true;
      this.pause();
      this.controlsRef.toggleVisibility();
      this.onEnded.emit();
    };
    this.handleTimeUpdate = throttle(async (e) => {
      var _a, _b;
      this.currentTime = this.videoRef.currentTime;
      const duration = this.duration || this._duration;
      const isControlDragging = await this.controlsRef.getIsDraggingProgressBall();
      if (this.controls && this.showProgress) {
        if (!isControlDragging && !this.isDraggingProgress) {
          this.controlsRef.setProgressBall(this.currentTime / duration);
          this.controlsRef.setCurrentTime(this.currentTime);
        }
      }
      this.danmuRef.tick(this.currentTime);
      this.onTimeUpdate.emit({
        duration: (_a = e.target) === null || _a === void 0 ? void 0 : _a.duration,
        currentTime: (_b = e.target) === null || _b === void 0 ? void 0 : _b.currentTime
      });
      if (this.duration) {
        if (this.currentTime >= this.duration) {
          this.seek(0);
          this.handleEnded();
        }
      }
    }, 250);
    this.handleError = e => {
      var _a, _b;
      if (this.hls) {
        switch (e.type) {
          case this.HLS.ErrorTypes.NETWORK_ERROR:
            // try to recover network error
            this.onError.emit({ errMsg: e.response });
            this.hls.startLoad();
            break;
          case this.HLS.ErrorTypes.MEDIA_ERROR:
            this.onError.emit({ errMsg: e.reason || '媒体错误,请重试' });
            this.hls.recoverMediaError();
            break;
        }
      }
      else {
        this.onError.emit({
          errMsg: (_b = (_a = e.target) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.message,
        });
      }
    };
    this.handleDurationChange = () => {
      this._duration = this.videoRef.duration;
    };
    this.handleProgress = () => {
      this.onProgress.emit();
    };
    this.handleLoadedMetaData = (e) => {
      const target = e.target;
      this.onLoadedMetaData.emit({
        width: target.videoWidth,
        height: target.videoHeight,
        duration: target.duration
      });
    };
    this._play = () => this.videoRef.play();
    this._pause = () => this.videoRef.pause();
    this._stop = () => {
      this.videoRef.pause();
      this._seek(0);
    };
    this._seek = (position) => {
      this.videoRef.currentTime = position;
    };
    this.onTouchStartContainer = (e) => {
      this.lastTouchScreenX = e.touches[0].screenX;
      this.lastTouchScreenY = e.touches[0].screenY;
    };
    this.onClickContainer = () => {
      if (this.enablePlayGesture) {
        const now = Date.now();
        if (now - this.lastClickedTime < 300) {
          // 双击
          this.isPlaying ? this.pause() : this.play();
        }
        this.lastClickedTime = now;
      }
      this.controlsRef.toggleVisibility();
    };
    this.onClickFullScreenBtn = (e) => {
      e.stopPropagation();
      this.toggleFullScreen();
    };
    this.handleFullScreenChange = e => {
      // 全屏后，"退出"走的是浏览器事件，在此同步状态
      const timestamp = new Date().getTime();
      if (!e.detail && this.isFullScreen && !document[screenFn.fullscreenElement] && timestamp - this.fullScreenTimestamp > 100) {
        this.toggleFullScreen(false);
      }
    };
    this.toggleFullScreen = (isFullScreen = !this.isFullScreen) => {
      this.isFullScreen = isFullScreen; // this.videoRef?.['webkitDisplayingFullscreen']
      this.controlsRef.toggleVisibility(true);
      this.fullScreenTimestamp = new Date().getTime();
      this.onFullScreenChange.emit({
        fullScreen: this.isFullScreen,
        direction: 'vertical'
      });
      if (this.isFullScreen && !document[screenFn.fullscreenElement]) {
        setTimeout(() => {
          this.videoRef[screenFn.requestFullscreen]({ navigationUI: 'auto' });
        }, 0);
      }
      else {
        document[screenFn.exitFullscreen]();
      }
    };
    this.toggleMute = (e) => {
      e.stopPropagation();
      this.videoRef.muted = !this.isMute;
      this.controlsRef.toggleVisibility(true);
      this.isMute = !this.isMute;
    };
    this.toggleDanmu = (e) => {
      e.stopPropagation();
      this.controlsRef.toggleVisibility(true);
      this._enableDanmu = !this._enableDanmu;
    };
    this.src = undefined;
    this.duration = undefined;
    this.controls = true;
    this.autoplay = false;
    this.loop = false;
    this.muted = false;
    this.initialTime = 0;
    this.poster = undefined;
    this.objectFit = 'contain';
    this.showProgress = true;
    this.showFullscreenBtn = true;
    this.showPlayBtn = true;
    this.showCenterPlayBtn = true;
    this.showMuteBtn = false;
    this.danmuList = undefined;
    this.danmuBtn = false;
    this.enableDanmu = false;
    this.enablePlayGesture = false;
    this.enableProgressGesture = true;
    this.vslideGesture = false;
    this.vslideGestureInFullscreen = true;
    this.nativeProps = {};
    this._duration = undefined;
    this._enableDanmu = false;
    this.isPlaying = false;
    this.isFirst = true;
    this.isFullScreen = false;
    this.fullScreenTimestamp = new Date().getTime();
    this.isMute = false;
  }
  componentWillLoad() {
    this._enableDanmu = this.enableDanmu;
  }
  componentDidLoad() {
    var _a, _b;
    this.init();
    if (this.initialTime) {
      this.videoRef.currentTime = this.initialTime;
    }
    // 目前只支持 danmuList 初始化弹幕列表，还未支持更新弹幕列表
    (_b = (_a = this.danmuRef).sendDanmu) === null || _b === void 0 ? void 0 : _b.call(_a, this.danmuList);
    if (document.addEventListener) {
      document.addEventListener(screenFn.fullscreenchange, this.handleFullScreenChange);
    }
    if (this.videoRef && scene === 'iOS') {
      // NOTE: iOS 场景下 fullscreenchange 并不会在退出全屏状态下触发，仅 webkitpresentationmodechanged 与 webkitendfullscreen 可替代
      this.videoRef.addEventListener('webkitendfullscreen', this.handleFullScreenChange);
    }
  }
  componentDidRender() {
  }
  disconnectedCallback() {
    if (document.removeEventListener) {
      document.removeEventListener(screenFn.fullscreenchange, this.handleFullScreenChange);
    }
    if (this.videoRef && scene === 'iOS') {
      this.videoRef.removeEventListener('webkitendfullscreen', this.handleFullScreenChange);
    }
  }
  watchEnableDanmu(newVal) {
    this._enableDanmu = newVal;
  }
  watchSrc() {
    this.init();
  }
  async onDocumentTouchMove(e) {
    if (this.lastTouchScreenX === undefined || this.lastTouchScreenY === undefined)
      return;
    if (await this.controlsRef.getIsDraggingProgressBall())
      return;
    const gestureObj = this.analyzeGesture(e);
    if (gestureObj.type === 'adjustVolume') {
      this.toastVolumeRef.style.visibility = 'visible';
      const nextVolume = Math.max(Math.min(this.lastVolume - gestureObj.dataY, 1), 0);
      this.videoRef.volume = nextVolume;
      this.toastVolumeBarRef.style.width = `${nextVolume * 100}%`;
    }
    else if (gestureObj.type === 'adjustProgress') {
      this.isDraggingProgress = true;
      this.nextPercentage = Math.max(Math.min(this.lastPercentage + (gestureObj.dataX || 0), 1), 0);
      if (this.controls && this.showProgress) {
        this.controlsRef.setProgressBall(this.nextPercentage);
        this.controlsRef.toggleVisibility(true);
      }
      const duration = this.duration || this._duration;
      this.toastProgressTitleRef.innerHTML = `${formatTime(this.nextPercentage * duration)} / ${formatTime(duration)}`;
      this.toastProgressRef.style.visibility = 'visible';
    }
  }
  onDocumentTouchEnd() {
    var _a;
    if (this.gestureType === 'adjustVolume') {
      this.toastVolumeRef.style.visibility = 'hidden';
    }
    else if (this.gestureType === 'adjustProgress') {
      this.toastProgressRef.style.visibility = 'hidden';
    }
    if (this.isDraggingProgress) {
      this.isDraggingProgress = false;
      this.seek(this.nextPercentage * ((_a = this.duration) !== null && _a !== void 0 ? _a : this._duration));
    }
    this.gestureType = 'none';
    this.lastTouchScreenX = undefined;
    this.lastTouchScreenY = undefined;
  }
  async getHlsObject() {
    // Note: H5 端专属方法，获取 HLS 实例 fix #11894
    return this.hls;
  }
  /** 播放视频 */
  async play() {
    this._play();
  }
  /** 暂停视频 */
  async pause() {
    this._pause();
  }
  /** 停止视频 */
  async stop() {
    this._stop();
  }
  /** 跳转到指定位置 */
  async seek(position) {
    this._seek(position);
  }
  /** 进入全屏。若有自定义内容需在全屏时展示，需将内容节点放置到 video 节点内。 */
  async requestFullScreen() {
    this.toggleFullScreen(true);
  }
  /** 退出全屏 */
  async exitFullScreen() {
    this.toggleFullScreen(false);
  }
  render() {
    const { controls, autoplay, loop, muted, poster, objectFit, isFirst, isMute, isFullScreen, showCenterPlayBtn, isPlaying, _enableDanmu, showMuteBtn, danmuBtn, showFullscreenBtn, nativeProps } = this;
    const duration = this.duration || this._duration;
    const durationTime = formatTime(duration);
    return (h(Host, { class: classnames('taro-video-container', {
        'taro-video-type-fullscreen': isFullScreen
      }), onTouchStart: this.onTouchStartContainer, onClick: this.onClickContainer }, h("video", Object.assign({ class: 'taro-video-video', style: {
        'object-fit': objectFit
      }, ref: dom => {
        if (dom) {
          this.videoRef = dom;
        }
      }, autoplay: autoplay, loop: loop, muted: muted, poster: controls ? poster : undefined, playsinline: true, "webkit-playsinline": true, onPlay: this.handlePlay, onPause: this.handlePause, onEnded: this.handleEnded, onTimeUpdate: this.handleTimeUpdate, onError: this.handleError, onDurationChange: this.handleDurationChange, onProgress: this.handleProgress, onLoadedMetaData: this.handleLoadedMetaData }, nativeProps), "\u6682\u65F6\u4E0D\u652F\u6301\u64AD\u653E\u8BE5\u89C6\u9891"), h("taro-video-danmu", { ref: dom => {
        if (dom) {
          this.danmuRef = dom;
        }
      }, enable: _enableDanmu }), isFirst && showCenterPlayBtn && !isPlaying && (h("div", { class: 'taro-video-cover' }, h("div", { class: 'taro-video-cover-play-button', onClick: () => this.play() }), h("p", { class: 'taro-video-cover-duration' }, durationTime))), h("taro-video-control", { ref: dom => {
        if (dom) {
          this.controlsRef = dom;
        }
      }, controls: controls, currentTime: this.currentTime, duration: duration, isPlaying: this.isPlaying, pauseFunc: this._pause, playFunc: this._play, seekFunc: this._seek, showPlayBtn: this.showPlayBtn, showProgress: this.showProgress }, showMuteBtn && (h("div", { class: classnames('taro-video-mute', {
        'taro-video-type-mute': isMute
      }), onClick: this.toggleMute })), danmuBtn && (h("div", { class: classnames('taro-video-danmu-button', {
        'taro-video-danmu-button-active': _enableDanmu
      }), onClick: this.toggleDanmu }, "\u5F39\u5E55")), showFullscreenBtn && (h("div", { class: classnames('taro-video-fullscreen', {
        'taro-video-type-fullscreen': isFullScreen
      }), onClick: this.onClickFullScreenBtn }))), h("div", { class: 'taro-video-toast taro-video-toast-volume', ref: dom => {
        if (dom) {
          this.toastVolumeRef = dom;
        }
      } }, h("div", { class: 'taro-video-toast-title' }, "\u97F3\u91CF"), h("div", { class: 'taro-video-toast-icon' }), h("div", { class: 'taro-video-toast-value' }, h("div", { class: 'taro-video-toast-value-content', ref: dom => {
        if (dom) {
          this.toastVolumeBarRef = dom;
        }
      } }, h("div", { class: 'taro-video-toast-volume-grids' }, Array(10).fill(1).map(() => (h("div", { class: 'taro-video-toast-volume-grids-item' }))))))), h("div", { class: 'taro-video-toast taro-video-toast-progress', ref: dom => {
        if (dom) {
          this.toastProgressRef = dom;
        }
      } }, h("div", { class: 'taro-video-toast-title', ref: dom => {
        if (dom) {
          this.toastProgressTitleRef = dom;
        }
      } }))));
  }
  get el() { return getElement(this); }
  static get watchers() { return {
    "enableDanmu": ["watchEnableDanmu"],
    "src": ["watchSrc"]
  }; }
};
Video.style = indexCss;

const VideoDanmu = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.list = [];
    this.danmuElList = [];
    this.currentTime = 0;
    this.enable = false;
    this.danmuList = [];
  }
  ensureProperties(danmu) {
    const clonedDanmu = Object.assign({}, danmu);
    if (!('time' in danmu)) {
      clonedDanmu.time = this.currentTime;
    }
    clonedDanmu.key = Math.random();
    clonedDanmu.bottom = `${Math.random() * 90 + 5}%`;
    return clonedDanmu;
  }
  async sendDanmu(danmuList = []) {
    if (Array.isArray(danmuList)) {
      this.list = [
        ...this.list,
        ...danmuList.map(danmu => this.ensureProperties(danmu))
      ];
    }
    else {
      const danmu = danmuList;
      this.list = [
        ...this.list,
        Object.assign({}, this.ensureProperties(danmu))
      ];
    }
  }
  async tick(currentTime) {
    this.currentTime = currentTime;
    if (!this.enable)
      return;
    const danmuList = this.list;
    /**
     * @todo 这个判断对拖拽进度的处理不严谨
     */
    const newDanmuList = danmuList.filter(({ time }) => {
      return currentTime - time < 4 && currentTime > time;
    });
    let shouldUpdate = false;
    const oldDanmuList = this.danmuList;
    if (newDanmuList.length !== oldDanmuList.length) {
      shouldUpdate = true;
    }
    else {
      shouldUpdate = newDanmuList.some(({ key }) => {
        return oldDanmuList.every((danmu) => {
          return key !== danmu.key;
        });
      });
    }
    if (shouldUpdate) {
      this.danmuList = newDanmuList;
    }
  }
  componentDidUpdate() {
    requestAnimationFrame(() => {
      setTimeout(() => {
        const danmuElList = this.danmuElList.splice(0);
        danmuElList.forEach(danmu => {
          danmu.style.left = '0';
          danmu.style.webkitTransform = 'translateX(-100%)';
          danmu.style.transform = 'translateX(-100%)';
        });
      });
    });
  }
  render() {
    if (!this.enable)
      return '';
    return (h(Host, { class: 'taro-video-danmu' }, this.danmuList.map(({ text, color, bottom, key }) => (h("p", { class: 'taro-video-danmu-item', key: key, style: {
        color,
        bottom
      }, ref: ref => {
        if (ref) {
          this.danmuElList.push(ref);
        }
      } }, text)))));
  }
};

export { VideoControl as taro_video_control, Video as taro_video_core, VideoDanmu as taro_video_danmu };
