text: define(["exports", "../../../lit/index.js"], function (_exports, _index) {
    "use strict";
  
    Object.defineProperty(_exports, "__esModule", {
      value: true
    });
    _exports.A11yMediaYoutube = void 0;
  
    var _templateObject_a64ea970feb911eb8439e3eec9305af7, _templateObject2_a64ea970feb911eb8439e3eec9305af7;
  
    function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
  
    function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { babelHelpers.defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  
    function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = babelHelpers.getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = babelHelpers.getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return babelHelpers.possibleConstructorReturn(this, result); }; }
  
    function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  
    /**
     * `a11y-media-youtube`
     * uses YouTubeAPI to create and control an embedded YouTube video.
     * @element a11y-media-youtube
     */
    var A11yMediaYoutube = /*#__PURE__*/function (_LitElement) {
      babelHelpers.inherits(A11yMediaYoutube, _LitElement);
  
      var _super = _createSuper(A11yMediaYoutube);
  
      /**
       * life cycle, element is afixed to the DOM
       * Makes sure there is a utility ready and listening for elements.
       */
      function A11yMediaYoutube() {
        var _this;
  
        babelHelpers.classCallCheck(this, A11yMediaYoutube);
        _this = _super.call(this);
        _this.autoplay = false;
        _this.height = "100%";
        _this.loop = false;
        _this.playbackRate = 1;
        _this.preload = "metadata";
        _this.muted = false;
        _this.volume = 0.7;
        _this.width = "100%";
        _this.__video = null;
        _this.__yt = null;
        return _this;
      }
      /**
       * single instance of YouTube iframe script
       * @readonly
       * @returns {object} script tag
       */
  
  
      babelHelpers.createClass(A11yMediaYoutube, [{
        key: "render",
        value: //render function
        function render() {
          return (0, _index.html)(_templateObject_a64ea970feb911eb8439e3eec9305af7 || (_templateObject_a64ea970feb911eb8439e3eec9305af7 = babelHelpers.taggedTemplateLiteral([" <slot></slot> "])));
        } // properties available to the custom element for data binding
  
      }, {
        key: "api",
        get: function get() {
          var scriptid = "a11y-media-youtube-api",
              ytapi = window.document.getElementById(scriptid);
          /* only add if script doesn't already exist */
  
          if (!ytapi) {
            ytapi = document.createElement("script");
            ytapi.setAttribute("id", scriptid);
            ytapi.setAttribute("src", "https://www.youtube.com/iframe_api");
            ytapi.setAttribute("type", "text/javascript");
            window.document.body.appendChild(ytapi);
          }
  
          return ytapi;
        }
        /**
         * returns buffered media
         * @readonly
         * @returns {number} seconds of buffered media
         */
  
      }, {
        key: "buffered",
        get: function get() {
          return this.__yt && this.__yt.buffered && this.__yt.buffered.length > 0 ? this.__yt.buffered.end(0) : -1;
        }
        /**
         * elapsed time of video
         * @readonly
         * @returns {number} time in seconds
         */
  
      }, {
        key: "currentTime",
        get: function get() {
          return this.__yt && this.__yt.getCurrentTime ? this.__yt.getCurrentTime() : undefined;
        }
        /**
         * duration of video
         * @readonly
         * @returns {number} duration in seconds
         */
  
      }, {
        key: "duration",
        get: function get() {
          return this.__yt && this.__yt.getDuration ? this.__yt.getDuration() : 0;
        }
        /**
         * whether video playback is paused
         * @readonly
         * @returns {boolean}
         */
  
      }, {
        key: "paused",
        get: function get() {
          return this.__yt && this.__yt.getPlayerState ? this.__yt.getPlayerState() !== 1 : true;
        }
        /**
         * seekable range of video
         * @readonly
         * @returns {object} TimeRanges object
         */
  
      }, {
        key: "seekable",
        get: function get() {
          var _this2 = this;
  
          var seekable = {
            length: 0
          };
  
          if (this.duration > 0) {
            seekable.length = 1;
  
            seekable.start = function (index) {
              return 0;
            };
  
            seekable.end = function (index) {
              return _this2.duration;
            };
          }
  
          return seekable;
        }
        /**
         * initializes singleton to manage a11y-manager-youtube instances
         */
  
      }, {
        key: "init",
        value: function init() {
          window.A11yMediaYoutubeManager = window.A11yMediaYoutubeManager || {
            /* gets iframes for all  */
            getIframes: function getIframes() {
              window.A11yMediaYoutubeManager.queue.forEach(function (instance) {
                return instance.__yt = instance._preloadVideo(true);
              });
              window.A11yMediaYoutubeManager.queue = [];
            },
            queue: [] //array of instances waiting for iframes
  
          };
          window.A11yMediaYoutubeManager.queue.push(this);
          /* checks for api and either uses it to get iframes or gets it */
  
          if (window.A11yMediaYoutubeManager.api) {
            if (window.YT) window.A11yMediaYoutubeManager.getIframes();
          } else {
            window.onYouTubeIframeAPIReady = function (e) {
              return window.A11yMediaYoutubeManager.getIframes();
            }, window.A11yMediaYoutubeManager.api = this.api;
          }
        }
        /**
         * @param {map} changedProperties the properties that have changed
         */
  
      }, {
        key: "updated",
        value: function updated(changedProperties) {
          var _this3 = this;
  
          var iframeChanged = false,
              videoChanged = false,
              autoChanged = false;
          changedProperties.forEach(function (oldValue, propName) {
            if (propName === "muted") _this3.setMute(_this3.muted);
            if (propName === "duration" && _this3.duration > 0) _this3._handleMediaLoaded();
            if (propName === "loop") _this3.setLoop(_this3.loop);
            if (propName === "currentTime") _this3.seek(_this3.currentTime);
            if (propName === "playbackRate") _this3.setPlaybackRate(_this3.playbackRate);
            if (propName === "volume") _this3.setVolume(_this3.volume);
            /* reload one batch of changes at a time */
  
            if (propName === "videoId" && !!_this3.videoId && !_this3.__yt) _this3.init();
            if (["id", "height", "width", "preload"].includes(propName) && _this3.__yt) iframeChanged = true;
            if (["autoplay", "videoId", "__video"].includes(propName) && _this3.__video) videoChanged = true;
            if (["preload", "t"].includes(propName) && (_this3.preload === "auto" || _this3.t)) autoChanged = true;
          });
          /* reload iframe changes first, video changes will update based on iframe */
  
          if (iframeChanged) {
            this.__yt = this._preloadVideo(true);
          } else if (videoChanged) {
            this._loadVideo();
  
            if (autoChanged) this._autoMetadata();
          }
        }
        /**
         * plays video
         */
  
      }, {
        key: "play",
        value: function play() {
          if (!this.__yt) this.__yt = this._preloadVideo(false);
  
          if (!!this.__yt && !!this.__yt.playVideo && !!this.__video && !!this.videoId) {
            this.__playQueued = true;
  
            var yt = this.__yt,
                fn = function fn() {
              yt.playVideo();
              this.__playQueued = false;
            };
  
            setTimeout(fn, 1000);
          }
        }
        /**
         * pauses video
         */
  
      }, {
        key: "pause",
        value: function pause() {
          if (this.__yt && this.__yt.pauseVideo) this.__yt.pauseVideo();
        }
        /**
         * seeks video
         * @param {number} time in seconds
         */
  
      }, {
        key: "seek",
        value: function seek() {
          var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
          var root = this;
  
          if (this.__yt && this.__yt.seekTo) {
            this.__yt.seekTo(time, true);
          }
        }
        /**
         * sets video looping
         * @param {boolean} whether video should loop after playback finishes
         */
  
      }, {
        key: "setLoop",
        value: function setLoop(loop) {
          if (this.__yt && this.__yt.setLoop) this.media.setLoop(loop);
        }
        /**
         * mutes or unmutes video
         * @param {boolean} whether the video should be muted
         */
  
      }, {
        key: "setMute",
        value: function setMute(muted) {
          if (this.__yt) {
            if (muted && this.__yt.mute) {
              this.__yt.mute();
            } else if (this.__yt.unMute) {
              this.__yt.unMute();
            }
          }
        }
        /**
         * sets playbackRate function
         * @param {number} playback rate X normal speed
         */
  
      }, {
        key: "setPlaybackRate",
        value: function setPlaybackRate(value) {
          if (this.__yt && this.__yt.setPlaybackRate) this.__yt.setPlaybackRate(value);
        }
        /**
         * sets video volume
         * @param {number} volume from 1 - 10
         */
  
      }, {
        key: "setVolume",
        value: function setVolume() {
          var volume = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0.7;
          if (this.__yt) this.__yt.setVolume(volume * 100);
        }
        /**
         * returns time in seconds of a string, such as 00:00:00.0, 0h0m0.0s, or 0hh0mm0.0ss
         * @param {string} time
         * @returns {float} seconds
         */
  
      }, {
        key: "_getSeconds",
        value: function _getSeconds() {
          var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
          var units = time.replace(/[hm]{1,2}&?/g, ":0").replace(/[s]{1,2}$/g, "").split(/:/),
              hh = units.length > 2 ? parseInt(units[units.length - 3]) : 0,
              mm = units.length > 1 ? parseInt(units[units.length - 2]) : 0,
              ss = units.length > 0 ? parseFloat(units[units.length - 1]) : 0;
          return hh * 3600 + mm * 60 + ss;
        }
        /**
         * Fires as YouTube after video src is loaded
         * @event mediastatechange
         */
  
      }, {
        key: "_handleMediaStateChange",
        value: function _handleMediaStateChange(e) {
          this.dispatchEvent(new CustomEvent("mediastatechange", {
            bubbles: true,
            cancelable: true,
            composed: true,
            detail: e
          }));
        }
        /**
         * Fires as YouTube video time changes
         * @event timeupdate
         */
  
      }, {
        key: "_handleMediaLoaded",
        value: function _handleMediaLoaded(e) {
          this.dispatchEvent(new CustomEvent("loadedmetadata", {
            bubbles: true,
            cancelable: true,
            composed: true,
            detail: this
          }));
        }
        /**
         * Fires as YouTube video time changes
         * @event timeupdate
         */
  
      }, {
        key: "_handleTimeupdate",
        value: function _handleTimeupdate() {
          this.dispatchEvent(new CustomEvent("timeupdate", {
            bubbles: true,
            cancelable: true,
            composed: true,
            detail: this
          }));
        }
        /**
         * loads metadata by playing a small clip on mute and stopping
         */
  
      }, {
        key: "_autoMetadata",
        value: function _autoMetadata() {
          var _this4 = this;
  
          var seek = this.t || 0,
              autoplay = this.autoplay;
          this.setMute(true);
  
          this.__yt.playVideo();
  
          var timeout = 120000,
              checkDuration = setInterval(function () {
            timeout--; //give the video up to 2 minute to attempt preload
  
            if (_this4.duration && _this4.duration > 0 || timeout <= 0) {
              _this4.pause();
  
              _this4.setMute(_this4.muted);
  
              clearInterval(checkDuration);
  
              _this4.seek(seek);
  
              if (autoplay) _this4.play();
            }
          }, 1);
          this.seek(seek);
        }
        /**
         * loads video (and optionally preloads) from video data object {videoId, optional start timecode, }
         * @param {string} preload mode for preloading: `auto`, `metadata`, `none`
         */
  
      }, {
        key: "_loadVideo",
        value: function _loadVideo() {
          var preload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.preload;
          if (!!this.videoId) this.__video.cueVideoById({
            videoId: this.videoId
          });
        }
        /**
         * initializes the youtube player for a given element
         * See https://developers.google.com/youtube/player_parameters for more information
         *
         * @returns {object} the YouTube player object
         */
  
      }, {
        key: "_preloadVideo",
        value: function _preloadVideo() {
          var _this5 = this;
  
          var auto = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
          var root = this,
              load = (!auto || this.preload !== "none") && this.videoId && !this.__video,
              div = document.createElement("div"),
              divid = "container-".concat(this.id),
              youtube = null;
          document.body.appendChild(div);
          div.setAttribute("id", divid);
  
          if (load) {
            var setYT = function setYT(e) {
              return _this5.__video = e.target;
            },
                port = window.location.port ? ":".concat(window.location.port) : "",
                origin = "//".concat(window.location.hostname).concat(port);
  
            youtube = new YT.Player(divid, {
              width: root.width,
              height: root.height,
              events: {
                onReady: setYT
              },
              playerVars: {
                color: "white",
                controls: 0,
                autoplay: root.autoplay,
                disablekb: 1,
                enablejsapi: 1,
                origin: origin,
                iv_load_policy: 3,
                modestbranding: 1,
                //todo research playsinline
                rel: 0,
                widget_referrer: window.location.href
              }
            });
            youtube.timeupdate;
            youtube.addEventListener("onStateChange", function (e) {
              if (root.paused) {
                clearInterval(youtube.timeupdate);
              } else {
                youtube.timeupdate = setInterval(function () {
                  return root._handleTimeupdate();
                }, 1);
              }
  
              _this5._handleMediaStateChange(e);
            });
            this.appendChild(youtube.getIframe());
            div.remove();
          }
  
          return youtube;
        }
        /**
         * removes iframe aand resets container
         */
  
      }, {
        key: "_removeIframe",
        value: function _removeIframe() {
          if (this.__yt) {
            this.__yt.remove;
  
            try {
              this.__yt.destroy();
            } catch (e) {
              console.warn(e);
            }
          }
  
          this.innerHTML = "";
        }
      }, {
        key: "disconnectedCallback",
        value: function disconnectedCallback() {
          this._removeIframe();
  
          babelHelpers.get(babelHelpers.getPrototypeOf(A11yMediaYoutube.prototype), "disconnectedCallback", this).call(this);
        }
      }], [{
        key: "tag",
        get: // properties available to the custom element for data binding
  
        /**
         * Store the tag name to make it easier to obtain directly.
          */
        function get() {
          return "a11y-media-youtube";
        } //styles function
  
      }, {
        key: "styles",
        get: function get() {
          return [(0, _index.css)(_templateObject2_a64ea970feb911eb8439e3eec9305af7 || (_templateObject2_a64ea970feb911eb8439e3eec9305af7 = babelHelpers.taggedTemplateLiteral(["\n        iframe .ytp-pause-overlay {\n          display: none !important;\n        }\n      "])))];
        }
      }, {
        key: "properties",
        get: function get() {
          return _objectSpread(_objectSpread({}, babelHelpers.get(babelHelpers.getPrototypeOf(A11yMediaYoutube), "properties", this)), {}, {
            /**
             * a11y-media-youtube unique id
             */
            id: {
              type: String
            },
  
            /**
             * video loops back to start
             */
            autoplay: {
              type: Boolean
            },
  
            /**
             * height of the embedded video
             */
            height: {
              type: String
            },
  
            /**
             * video loops back to start
             */
            loop: {
              type: Boolean
            },
  
            /**
             * video muted
             */
            muted: {
              type: Boolean
            },
  
            /**
             * preload settings
             */
            preload: {
              type: String,
              attribute: "preload",
              reflect: true
            },
  
            /**
             * video playback rate
             */
            playbackRate: {
              type: Number
            },
  
            /**
             * youTube's unique identifier for the video
             */
            t: {
              type: Number,
              attribute: "t",
              reflect: true
            },
  
            /**
             * youTube's unique identifier for the video
             */
            videoId: {
              type: String,
              attribute: "video-id",
              reflect: true
            },
  
            /**
             * volume between 0 and 100
             */
            volume: {
              type: Number
            },
  
            /**
             * width of the embedded video
             */
            width: {
              type: String
            },
  
            /**
             * video object
             */
            __video: {
              type: Object
            },
  
            /**
             * youtube object
             */
            __yt: {
              type: Object
            }
          });
        }
      }]);
      return A11yMediaYoutube;
    }(_index.LitElement);
  
    _exports.A11yMediaYoutube = A11yMediaYoutube;
    window.customElements.define(A11yMediaYoutube.tag, A11yMediaYoutube);
  });