@flowplayer/player
Version:
video player for the future
2 lines (1 loc) • 3.75 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.cuepoints=t())}(this,function(){"use strict";const e="cuepoints",t="cuepointstart",n="cuepointend";var o=Object.freeze({__proto__:null,CUEPOINTS:e,CUEPOINT_START:t,CUEPOINT_END:n});const r="flowplayer-cue",i=(e,t)=>new(((e,t)=>{const n=e.get(t);if(!n)throw new Error(`no flowplayer component with the name ${t} exists`);const o=window.customElements.get(t);if(!o)throw new Error(`no default flowplayer component with the name ${t} exists`);const r=window.customElements.get(n);return"function"!=typeof r?o:r})(e._customElements,t))(e);function s(e,t,n){const o=function(e,t){const n=new CustomEvent(e,{detail:t,cancelable:!0});return t&&Object.defineProperty(n,"data",{get:()=>t}),n}(t,n);return e.dispatchEvent(o),e}function c(e){const t=e._customElements.get(r);t&&Array.from(e.root.querySelectorAll(t)).forEach(e=>{e.remove()})}function u(e,t){var n;const o=function(e,t){const n=e._customElements.get(t);return n&&e.root.querySelector(n)||void 0}(e,"flowplayer-timeline-bar"),c=e.duration,u=null===(n=null==e?void 0:e.opts)||void 0===n?void 0:n.draw_cuepoints;o&&!e.hasState("is-live")&&isFinite(c)&&Array.isArray(t)&&u&&t.forEach(t=>{if(void 0===t.startTime||t.startTime<0||!t.endTime||t.startTime===t.endTime)return;const n=Math.round(t.startTime/c*1e3)/10;if(n>100||n<0)return;const u=t.endTime-t.startTime,a=i(e,r);s(a,"cue:attributes",{left:n+"%",width:u/c*100+"%"}),o.append(a)})}!function(){let e=!1;try{const t=Object.defineProperty({},"passive",{get:function(){e=!0}});window.addEventListener("testPassive",null,t),window.removeEventListener("testPassive",null,t)}catch(e){}}();class FlowplayerComponent extends HTMLElement{constructor(e){super(),this.player=e}}class CueComponent extends FlowplayerComponent{constructor(e){super(e),this.className="fp-cuepoint",this.addEventListener("cue:attributes",e=>{this.style.setProperty("left",e.detail.left),this.style.setProperty("width",e.detail.width)})}}var a;const l=((a=class Cuepoints{constructor(e){((e,t,n)=>{window.customElements.get(t)||window.customElements.define(t,n),e.customElements.get(t)||e.customElements.set(t,t)})(e,r,CueComponent)}init(o,r,i){if(!i.reaper)return;const s=i.addTextTrack("metadata","fp-cuepoints");s.removeCue=function(e){this===a&&TextTrack.prototype.removeCue.call(s,e)},i.reaper.set("cuepoints",[]),i.on("config",function(t){var n;if(!i.reaper)return;(null===(n=t.data)||void 0===n?void 0:n.cuepoints)!==i.reaper.get("cuepoints")&&i.emit(e,{cuepoints:o.cuepoints})}),i.on("durationchange",()=>{i.reaper&&(c(i),u(i,i.reaper.get("cuepoints")))}),i.on(e,e=>{var o;if(!i.reaper)return;const r=(null===(o=e.data)||void 0===o?void 0:o.cuepoints)||[];i.reaper.set("cuepoints",r),Array.from(s.cues||{length:0}).forEach(e=>s.removeCue.call(this.constructor,e)),c(i),r.map(function(e){return function(e,o){try{const r=new VTTCue(o.startTime,o.endTime,o.text||"");return r.id=o.id||"",r.onenter=e.emit.bind(e,t,{cuepoint:o}),r.onexit=e.emit.bind(e,n,{cuepoint:o}),r}catch(e){if(o.startTime===o.endTime)return console.warn("Cue(:error)> startTime cannot equal endTime on this platform");throw e}}(i,e)}).forEach(function(e){e&&s.addCue(e)}),u(i,r)})}}).pluginName="cuepoints",a.events=o,a);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 n=e.flowplayer;return"function"==typeof n?(n(t),t):(Array.isArray(n.extensions)||(n.extensions=[]),~n.extensions.indexOf(t)||n.extensions.push(t),t)}(window,l)});