@flowplayer/player
Version:
video player for the future
2 lines (1 loc) • 6.82 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e="undefined"!=typeof globalThis?globalThis:e||self).flowplayer=e.flowplayer||{},e.flowplayer.tizen=t())}(this,(function(){"use strict";var e={BACK:"Back",BACK1:"XF86Back",EXIT:"Exit",ENTER:"Enter",PLAY:"MediaPlay",PAUSE:"MediaPause",REWIND:"MediaRewind",FORWARD:"MediaFastForward",ARROW_LEFT:"ArrowLeft",ARROW_UP:"ArrowUp",ARROW_RIGHT:"ArrowRight",ARROW_DOWN:"ArrowDown"};const t="is-hovered",s=(e,t)=>new(((e,t)=>{const s=e.get(t);if(!s)throw new Error(`no flowplayer component with the name ${t} exists`);const n=window.customElements.get(t);if(!n)throw new Error(`no default flowplayer component with the name ${t} exists`);const i=window.customElements.get(s);return"function"!=typeof i?n:i})(e._customElements,t))(e);class FlowplayerComponent extends HTMLElement{constructor(e){super(),this.player=e}}class TvMenu extends FlowplayerComponent{constructor(e){super(e),this.classList.add("tv-menu"),e.on("src",()=>this.classList.remove("is-open"))}open(){var e;this.player.emit("tv-menu:will-open"),this.classList.add("is-open"),null===(e=this.getMenus()[0].querySelector("li"))||void 0===e||e.focus()}close(){const e=new CustomEvent("tv-menu:will-close",{cancelable:!0});this.player.dispatchEvent(e),e.defaultPrevented||this.classList.remove("is-open")}append(e){super.append(e.menu)}is_empty(){return!this.getMenus().length}find_focusable_menu(e,t){const s=this.getMenus();return(t?s:s.slice(0).reverse()).find((t,s,n)=>s>n.indexOf(e))}getMenus(){return Array.from(this.children).filter(e=>"none"!==e.style.display)}}const n="is-tv-seeking";let i=void 0;function o(e,t){e.enqueueSeek(t)&&function(e){e.setState("is-kb-active",!0),clearTimeout(i),i=setTimeout((function(){e.setState("is-kb-active",!1)}),2500)}(e)}var r;const a=((r=class Tizen extends class TvPlugin{constructor(e){this.umd=e,this.should_restart=!1,this.previous_current_time=0,((e,t,s)=>{window.customElements.get(t)||window.customElements.define(t,s),e.customElements.get(t)||e.customElements.set(t,t)})(e,"flowplayer-tv-menu",TvMenu)}init(e,t,n){n.setState("is-tv",!0),this.menu=s(n,"flowplayer-tv-menu"),t.append(this.menu)}keydown_listener(e,t,s,n,i){const o=this.is_linearAd_on(s);return o||e!==t.ARROW_UP||n.classList.contains("is-open")||n.is_empty()?!o&&n.classList.contains("is-open")?this.menu_handler(e,t,n):void this.main_handler(e,t,s,o,i):n.open()}menu_handler(e,t,s){var n,i,o;if([t.BACK,t.BACK1,t.EXIT].includes(e))return s.close();if([t.ARROW_UP,t.ARROW_DOWN,t.ARROW_RIGHT,t.ARROW_LEFT,t.ENTER].includes(e)){const r=document.activeElement,a=null===(n=document.activeElement)||void 0===n?void 0:n.closest(".fp-menu");if(!r||!a)return;if(e===t.ENTER)return r.dispatchEvent(new Event("click"));if(e===t.ARROW_DOWN&&r.nextSibling)return r.nextSibling.focus();if(e===t.ARROW_UP&&r.previousSibling)return r.previousSibling.focus();if([t.ARROW_RIGHT,t.ARROW_LEFT].includes(e))return null===(o=null===(i=s.find_focusable_menu(a,e===t.ARROW_RIGHT))||void 0===i?void 0:i.querySelector("li"))||void 0===o?void 0:o.focus()}}main_handler(e,t,s,n,i){switch(e){case t.ENTER:return this.on_enter(s,n);case t.PLAY:return this.on_play(s,n);case t.PAUSE:return s.togglePlay(!1);case t.FORWARD:case t.ARROW_RIGHT:return this.on_seek(s,i||10,n);case t.REWIND:case t.ARROW_LEFT:return this.on_seek(s,-(i||10),n);case t.BACK:case t.BACK2:case t.BACK1:case t.EXIT:return this.on_exit(s,n);case t.ARROW_DOWN:return this.on_arrow_down(s,n)}}on_play(e,s){return s?e.togglePlay(!0):(this.is_live_status_focused()&&!e.hasState(t)&&this.live_status_toggle_focus(e,!1),e.hasState(n)?void this.on_seek_end(e,!1):e.togglePlay(!0))}on_enter(e,t){var s;return t?e.togglePlay():this.is_live_status_focused()?(null===(s=e.root.querySelector(".fp-live-status"))||void 0===s||s.dispatchEvent(new Event("click")),this.live_status_toggle_focus(e,!1)):e.hasState(n)?this.on_seek_end(e,!1):e.togglePlay()}on_exit(e,s){return s?e.emit("fullscreen:exit"):this.is_live_status_focused()?this.live_status_toggle_focus(e,!1):e.hasState(n)?this.on_seek_end(e,!0):e.hasState(t)?e.setState(t,!1):e.emit("fullscreen:exit")}on_arrow_down(e,s){if(clearTimeout(this.hover_timeout),this.hover_timeout=setTimeout(()=>{e.setState(t,!1),this.live_status_toggle_focus(e,!1)},2e3),!e.hasState(t)&&!e.hasState("is-paused"))return e.setState(t,!0);s||!e.hasState("is-live")||e.hasState("no-timeline")||this.live_status_toggle_focus(e,!0)}on_seek(e,t,s){s||e.hasState("is-live")&&e.hasState("no-timeline")||(e.hasState(n)||(this.should_restart=!e.hasState("is-paused"),this.previous_current_time=e.currentTime),e.paused||e.togglePlay(!1),e.setState(n,!0),o(e,t))}on_seek_end(e,t){e.setState(n,!1),t&&(e.currentTime=this.previous_current_time),t&&!this.should_restart||e.togglePlay(!0)}live_status_toggle_focus(e,t){const s=e.root.querySelector(".fp-live-status");s&&(t?s.focus():s.blur())}is_live_status_focused(){var e;const t=document.activeElement;return null===(e=null==t?void 0:t.classList)||void 0===e?void 0:e.contains("fp-live-status")}is_linearAd_on(e){var t,s;return!(!e.hasState("ad-paused")&&!e.hasState("ad-playing")||!(null===(s=null===(t=null==e?void 0:e.ads)||void 0===t?void 0:t.adapter)||void 0===s?void 0:s._adLinear))}}{init(t,s,n){(function(){const e="undefined"!=typeof document&&"undefined"!=typeof window,t=e?navigator.userAgent:"",s=/iP(hone|od)/i.test(t)&&!/iPad/.test(t)&&!/IEMobile/i.test(t),n=/Android/.test(t)&&!/Firefox/.test(t),i=/^((?!chrome|android).)*safari/i.test(t),o=/chrome|crios/i.test(t)&&!/opr|opera|chromium|edg|ucbrowser|googlebot/i.test(t),r=/firefox|fxios/i.test(t)&&!/seamonkey/i.test(t),a=/edg/i.test(t),u=/opr|opera/i.test(t),l=/SamsungBrowser/.test(t),c=l&&/SMART-TV/.test(t);return{controls:!s,video:function(t){return e&&document.createElement("video").canPlayType(t)},lang:e&&window.navigator.language,android:n,iphone:s,safari:i,edge:a,opera:u,chrome:o,firefox:r,ios:e&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,samsung:l,samsung_tv:l&&c,touch:"ontouchstart"in window,tizen:"tizen"in window,webOS:"webos"in window}})().tizen&&(super.init(t,s,n),document.addEventListener("keydown",s=>{setTimeout(()=>{var i;!s.defaultPrevented&&Object.values(e).includes(s.key)&&this.keydown_listener(s.key,e,n,this.menu,null===(i=t.tizen)||void 0===i?void 0:i.seek_step)},0)}))}}).pluginName="tizen",r.events={EXIT_FULLSCREEN:"fullscreen:exit"},r);return function(e,t){if("object"==typeof exports&&"undefined"!=typeof module)return t;if(null===document.currentScript)return t;"flowplayer"in e||(e.flowplayer={extensions:[]});const s=e.flowplayer;return"function"==typeof s?(s(t),t):(Array.isArray(s.extensions)||(s.extensions=[]),~s.extensions.indexOf(t)||s.extensions.push(t),t)}(window,a)}));