cloudinary-video-player
Version:
Cloudinary Video Player
2 lines • 19.8 kB
JavaScript
(self.cloudinaryVideoPlayerChunkLoading=self.cloudinaryVideoPlayerChunkLoading||[]).push([[33],{5826:(t,e,s)=>{"use strict";s.d(e,{default:()=>K});var i=s(4679),n=s.n(i),r=s(5871),o=s(1104),l=s(9388),a=s(3686),c=s.n(a);const d=[1,4,5,6,7,10,11],p=["created_at","updated_at"],h=t=>{const e={};return n()(t)?(Object.keys(t).reduce(((e,s)=>{const i=c()(s);return-1!==p.indexOf(s)?e[i]=new Date(function(t){let e=0,s=0,i=0;if(s=/^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2})(?::(\d{2}))?)?)?$/.exec(t)){for(let t,e=0;t=d[e];++e)s[t]=+s[t]||0;s[2]=(+s[2]||1)-1,s[3]=+s[3]||1,"Z"!==s[8]&&void 0!==s[9]&&(i=60*s[10]+s[11],"+"===s[9]&&(i=0-i)),e=Date.UTC(s[1],s[2],s[3],s[4],s[5]+i,s[6],s[7])}else e=NaN;return e}(t[s])):e[i]=h(t[s]),e}),e),e):Array.isArray(t)?t.map((t=>h(t))):t};var u=s(5381),m=s(4466),g=s.n(m),y=s(6673),_=s.n(y);const v=_().dom||_(),f=_().getComponent("Component"),C=_().getComponent("ClickableComponent");class x extends C{static DISABLE_TRANSITION_CLASS="disable-transition";static VJS_UPCOMING_VIDEO_SHOW="vjs-upcoming-video-show";constructor(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];super(t,...s),this._setEvents(t)}_setEvents(t){t.on(o.f.UP_COMING_VIDEO_SHOW,this._show),t.on(o.f.UP_COMING_VIDEO_HIDE,this._hide),t.on(o.f.PLAYLIST_ITEM_CHANGED,this._onPlaylistItemChange)}_hide=()=>{this.removeClass(x.VJS_UPCOMING_VIDEO_SHOW)};_disableTransition(t){this.addClass(x.DISABLE_TRANSITION_CLASS),t(),this.removeClass(x.DISABLE_TRANSITION_CLASS)}_onPlaylistItemChange=(t,e)=>{this._hide(),this._disableTransition((()=>{e.next&&this.setItem(e.next)}))};_show=()=>{const t=this.player().ima,e="object"===t&&t.getAdsManager();e&&e.getCurrentAd()&&!e.getCurrentAd().isLinear()||this.addClass(x.VJS_UPCOMING_VIDEO_SHOW)};setTitle(t){this.getChild("upcomingVideoOverlayContent").getChild("upcomingVideoOverlayBar").getChild("upcomingVideoOverlayTitle").setContent(t.info().title||t.publicId())}setItem(t){this._source=t;const e=parseInt(window.getComputedStyle(this.el(),null).getPropertyValue("max-width"),10),s={crop:"pad",background:"auto:predominant",width:e,height:Math.round(e*(9/16))},i=this.getChild("upcomingVideoOverlayContent");this.setTitle(t),i.el().style.backgroundImage=`url("${this._source.poster().url({transformation:s})}")`}handleClick(){super.handleClick(event),this.player().cloudinary.playlist().playNext()}createEl(){return super.createEl("div",{className:"vjs-upcoming-video"})}}class I extends f{createEl(){return super.createEl("div",{className:"upcoming-video-overlay aspect-ratio-content"})}}class w extends f{createEl(){return super.createEl("div",{className:"vjs-upcoming-video-bar"})}}x.prototype.options_={children:["upcomingVideoOverlayContent"]},_().registerComponent("upcomingVideoOverlay",x),I.prototype.options_={children:["upcomingVideoOverlayBar"]},_().registerComponent("upcomingVideoOverlayContent",I),w.prototype.options_={children:["upcomingVideoOverlayTitle","playlistNextButton"]},_().registerComponent("upcomingVideoOverlayBar",w),_().registerComponent("upcomingVideoOverlayTitle",class extends f{setContent(t){this._contentSpan.innerText=t}createEl(){const t=super.createEl("div",{className:"vjs-control vjs-upcoming-video-title"}),e=v.createEl("div",{className:"vjs-upcoming-video-title-display",innerHTML:'<span class="vjs-control-text">Next up</span>Next up: '});return this._contentSpan=v.createEl("span",{className:"vjs-upcoming-video-title-display-label"}),e.appendChild(this._contentSpan),t.appendChild(e),t}});const A=_().getComponent("ClickableComponent");const E=class extends A{constructor(t,e){super(t,e);const s=e.type;if(!s&&"previous"!==s&&"next"!==s)throw new Error("Type must be either 'previous' or 'next'")}createEl(){const t=this.options_.type,e=`vjs-icon-${t}-item`;return _().dom.createEl("button",{className:`vjs-control vjs-playlist-button vjs-button ${e}`,ariaLabel:`Playlist ${t} item`})}};class T extends E{constructor(t){super(t,{type:"next"})}handleClick(t){t.stopPropagation(),super.handleClick(t),this.player().cloudinary.playlist().playNext()}}_().registerComponent("PlaylistNextButton",T);class b extends E{constructor(t){super(t,{type:"previous"})}handleClick(t){super.handleClick(t),this.player().cloudinary.playlist().playPrevious()}}_().registerComponent("PlaylistPreviousButton",b);const N={fluid:!1,show:!0,direction:"vertical",total:4,selector:!1,renderTo:[]};const S=class{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],{repeat:s=!1,autoAdvance:i=!1,presentUpcoming:n=!1}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this._context=t,this._sources=[],this._defaultRecResolverCache={},this._currentIndex=null,this._recommendationsHandler=null,this._autoAdvance=null,this._presentUpcoming=null,this.addUiComponents(),this.resetState=()=>{this.repeat(s),this.autoAdvance(i),this.presentUpcoming(n)},e.forEach((t=>this.enqueue(t))),this.resetState()}list(){return this._sources}player(){return this._context.player}addUiComponents(){const t=this.player().getChild("ControlBar"),e=t.children();t.addChild("playlistPreviousButton",{},e.findIndex((t=>"PlayToggle"===t.name_))),t.addChild("playlistNextButton",{},e.findIndex((t=>"PlayToggle"===t.name_))+1),this.player().addChild("upcomingVideoOverlay")}presentUpcoming(t){if(this._presentUpcoming=this._presentUpcoming||{},void 0===t)return this._presentUpcoming.delay;if(!0===t)t=10;else if(!1===t)t=!1;else if(!g()(t)||t<0)throw new Error("presentUpcoming 'delay' must be either a boolean or a positive integer.");return this._presentUpcoming.delay=t,this._setupPresentUpcoming(),this._presentUpcoming.delay}autoAdvance(t){if(this._autoAdvance=this._autoAdvance||{},void 0===t)return this._autoAdvance.delay;if(!0===t)t=0;else if(!1===t)t=!1;else if(!g()(t)||t<0)throw new Error("Auto advance 'delay' must be either a boolean or a positive integer.");return this._autoAdvance.delay=t,this._setupAutoAdvance(),this._autoAdvance.delay}_setupAutoAdvance(){this._resetAutoAdvance();const t=this._autoAdvance.delay;if(!1===t)return;this._autoAdvance={delay:t,trigger:()=>{this.player().ended()&&(this._autoAdvance.timeout=setTimeout((()=>{this.playNext()}),1e3*t))}},this._context.on("ended",this._autoAdvance.trigger)}dispose(){this._resetAutoAdvance(),this._resetPresentUpcoming(),this._resetRecommendations()}_resetPresentUpcoming(){this.player().trigger("upcomingvideohide"),this._presentUpcoming||(this._presentUpcoming={}),this._presentUpcoming.trigger&&this._context.off("timeupdate",this._presentUpcoming.trigger),this._presentUpcoming.trigger=null,this._presentUpcoming.showTriggered=!1}_setupPresentUpcoming(){this._resetPresentUpcoming();!1!==this._presentUpcoming.delay&&(this._presentUpcoming.trigger=()=>{const t=this.player().currentTime(),e=this.player().duration()-t;e<1.5?this._presentUpcoming.showTriggered&&(this.player().trigger("upcomingvideohide"),this._presentUpcoming.showTriggered=!1):e<=this._presentUpcoming.delay&&!this._presentUpcoming.showTriggered&&!this.player().loop()?(this.player().trigger("upcomingvideoshow"),this._presentUpcoming.showTriggered=!0):this._presentUpcoming.showTriggered&&(e>this._presentUpcoming.delay||this.player().loop())&&(this.player().trigger("upcomingvideohide"),this._presentUpcoming.showTriggered=!1)},this._context.on("timeupdate",this._presentUpcoming.trigger))}_resetAutoAdvance(){this._autoAdvance||(this._autoAdvance={}),this._autoAdvance.timeout&&clearTimeout(this._autoAdvance.timeout),this._autoAdvance.trigger&&this._context.off("ended",this._autoAdvance.trigger),this._autoAdvance.timeout=null,this._autoAdvance.trigger=null}_resetRecommendations(){this._recommendationsHandler&&this._context.off("ended",this._recommendationsHandler)}_refreshRecommendations(){this._resetRecommendations(),this._recommendationsHandler=()=>{!1===this.autoAdvance()&&this._context.autoShowRecommendations()&&this.player().trigger("recommendationsshow")},this._context.on("ended",this._recommendationsHandler)}_refreshTextTracks(){this.player().trigger("refreshTextTracks",this.currentSource().textTracks())}_recommendationItemBuilder(t){const e=this._defaultRecResolverCache[t.objectId];if(!t.recommendations()||e&&t.recommendations()===e)return t=>({source:t,action:()=>this.playItem(t)})}currentIndex(t){if(void 0===t)return this._currentIndex;if(t>=this.length()||t<0)throw new Error("Invalid playlist index.");this._currentIndex=t;const e=this.currentSource(),s=this._recommendationItemBuilder(e);e.recommendations()||e.recommendations(this._defaultRecommendationsResolver(e)),this._context.source(e,{recommendationOptions:{disableAutoShow:!0,itemBuilder:s}});const i={playlist:this,current:e,next:this.next()};return this.player().trigger("playlistitemchanged",i),this._refreshRecommendations(),this._refreshTextTracks(),e}_defaultRecommendationsResolver(t){const e=this._defaultRecResolverCache[t.objectId];return e||(this._defaultRecResolverCache[t.objectId]=()=>{let e=this.list().indexOf(t);const s=[],i=Math.min(4,this.length()-1);for(;s.length<i&&(e=this.nextIndex(e),-1!==e);){const t=this.list()[e];s.push(t)}return s},this._defaultRecResolverCache[t.objectId])}buildSource(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this._context.buildSource(t,e)}enqueue(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=t instanceof u.A?t:this.buildSource(t,e);return this._sources.push(s),s}playItem(t){let e=this.list().indexOf(t);if(-1===e)throw new Error("Invalid playlist item.");this.playAtIndex(e)}playAtIndex(t){return this.currentIndex(t),this.player().play(),this.currentSource()}currentSource(){return this.list()[this.currentIndex()]}removeAt(t){if(t>=this.length()||t<0)throw new Error("Invalid playlist index.");return this._sources.splice(t,1),this}repeat(t){return void 0===t||(this._repeat=!!t),this._repeat}first(){return this.list()[0]}last(){return this.list()[this.length()-1]}next(){const t=this.nextIndex();return-1===t?null:this.list()[t]}nextIndex(t){if((t=void 0!==t?t:this.currentIndex())>=this.length()||t<0)throw new Error("Invalid playlist index.");let e=t+1;if(t===this.length()-1){if(!this.repeat())return-1;e=0}return e}previousIndex(){return this.isFirst()?-1:this.currentIndex()-1}playFirst(){return this.playAtIndex(0)}playLast(){const t=this.list().length-1;return this.playAtIndex(t)}isLast(){return this.currentIndex()>=this.length()-1}isFirst(){return 0===this.currentIndex()}length(){return this.list().length}playNext(){let t=this.nextIndex();return-1===t?null:this.playAtIndex(t)}playPrevious(){let t=this.previousIndex();return-1===t?null:this.playAtIndex(t)}playlistByTag=(()=>{var t=this;return function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t.player().sourcesByTag(e,s).then((e=>t.player().playlist(e,s)))}})()},P=(t,e)=>(t.parentNode.insertBefore(e,t),e.appendChild(t),e);var U=s(3066);const L=_().dom||_(),O=_().getComponent("Component"),k={wrap:!1};class j extends O{constructor(t,e){const s={...k,...e};super(t,s),this.player_=t;const i=(t,e)=>{this.options_.fluid=e,this.removeCls(),this.setCls()},n=()=>{const t=this.el();this.videoWrap_=L.createEl("div",{className:"cld-plw-col-player"}),this.contentEl_=this.contentEl_=L.createEl("div",{className:"cld-plw-col-list"}),P(this.player().el(),t),t.appendChild(this.videoWrap_),t.appendChild(this.contentEl_),P(this.player().el(),this.videoWrap_)};s.wrap&&n(),t.on(o.f.FLUID,i),this.addChild(o.f.PLAYLIST_PANEL,this.options_),this.setCls(),this.dispose=()=>{this.removeLayout(),super.dispose(),t.off(o.f.FLUID,i)}}getCls(){let t=["cld-video-player","cld-plw-layout"];return t.push((0,U.skinClassPrefix)(this.player())),t.push((0,U.playerClassPrefix)(this.player())),this.options_.fluid&&t.push("cld-plw-layout-fluid"),t}setCls(){this.removeClass((0,U.skinClassPrefix)(this.player())),this.getCls().forEach((t=>{this.addClass(t)}))}removeCls(){this.getCls().forEach((t=>{this.removeClass(t)}))}update(t,e){this.options(e),this.removeChild("PlaylistPanel"),this.addChild("PlaylistPanel",this.options_),this.trigger("playlistlayoutupdate")}removeLayout(){const t=this.el().parentElement;t&&t.appendChild(this.player().el())}createEl(){const t=super.createEl("div");return t.style.fontFamily=this.player().el().style.fontFamily,t}}_().registerComponent("playlistLayout",j);const D=j;const R=class extends D{constructor(t,e){e.wrap=!0,super(t,e)}getCls(){const t=super.getCls();return t.push("cld-plw-horizontal"),t}};const V=class extends D{constructor(t,e){e.wrap=!0,super(t,e)}getCls(){const t=super.getCls();return t.push("cld-plw-vertical"),t}};const B=class extends D{getCls(){let t=super.getCls();return t.push("cld-plw-custom"),t}createEl(){const t=super.createEl();return this.options_.renderTo.appendChild(t),t}};const H=class{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e=((t,e)=>{const s={...N,...e};if(s.show&&"string"==typeof s.selector&&(s.useDefaultLayout=!1,s.useCustomLayout=!0,s.renderTo=document.querySelector(s.selector),s.showAll=!0,0===!s.renderTo.length))throw new Error(`Couldn't find element(s) by selector '${s.selector}' for playlist`);return s.show&&!s.selector&&(s.useDefaultLayout=!0,s.useCustomLayout=!1),s.direction="horizontal"===s.direction.toLowerCase()?"horizontal":"vertical",s.skin=t.options_.skin,s})(t,e),this.options_=e,this.player_=t,this.render();const s=(t,e)=>{this.options_.fluid=e};t.on(o.f.FLUID,s),this.options=e=>e?(this.options_=_().obj.merge(this.options_,e),t.trigger("playlistwidgetoption",this.options_.playlistWidget),this.options_):this.options_,this.dispose=()=>{this.layout_.dispose(),t.off(o.f.FLUID,s)}}render(){this.options_.useDefaultLayout&&("horizontal"===this.options_.direction?this.layout_=new R(this.player_,this.options_):this.layout_=new V(this.player_,this.options_)),this.options_.useCustomLayout&&(this.layout_=new B(this.player_,this.options_))}getLayout(){return this.layout_}update(t,e){this.options(e),"direction"===t?(this.layout_.removeLayout(),this.layout_.dispose(),this.render()):this.layout_.update(t,this.options_)}setSkin(){this.layout_.setCls()}total(){const t=parseInt(arguments.length>0&&void 0!==arguments[0]?arguments[0]:N.total,10);return t!==this.options_.total&&"number"==typeof t&&t>0&&this.update("total",{total:t}),this}direction(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:N.direction;return"horizontal"!==t&&"vertical"!==t||this.update("direction",{direction:t}),this}},F=_().getComponent("ClickableComponent"),M={item:null,transformation:{width:300,aspect_ratio:"16:9",crop:"pad",background:"black"}};const W=class extends F{constructor(t,e){super(t,_().obj.merge(M,e))}getItem(){return this.options_.item}getTitle(){return this.getItem().info().title}getDuration(){return" "}getThumbnail(){return this.getItem().poster().url({transformation:this.options_.transformation})}handleClick(t){t.preventDefault()}createControlTextEl(){}createEl(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"a";const e=super.createEl(t,{className:"cld-thumbnail",href:"#"}),s=super.createEl("img",{className:"cld-thumbnail-img",src:this.getThumbnail()});return e.appendChild(s),e.style.backgroundImage=`url('${this.getThumbnail()}')`,e}},$=_().dom||_(),G={source:null,next:!1};class z extends W{constructor(t,e){super(t,_().obj.merge(G,e))}handleClick(t){super.handleClick(t),this.play()}play(){const t=this.getItem(),e=this.player().cloudinary.playlist().list().indexOf(t);if(-1===e)throw new Error("Invalid playlist item...");this.player().cloudinary.playlist().playAtIndex(e)}isCurrent(){return this.options_.current}getTitle(){return super.getTitle()}getDuration(){return super.getDuration()}createEl(){const t=super.createEl();t.classList.add("cld-plw-panel-item");const e=$.createEl("div",{className:"cld-plw-item-info-wrap"}),s=$.createEl("div",{className:"cld-plw-item-title"});if(this.isCurrent()){t.classList.add("cld-plw-panel-item-active");const e=$.createEl("span",{className:"cld-plw-item-title-curr"},{},"Now Playing: ");s.appendChild(e)}const i=$.createEl("span",{className:"cld-plw-item-title"},{},this.getTitle());s.appendChild(i);const n=$.createEl("div",{className:"cld-plw-item-duration"},{},this.getDuration());return e.appendChild(s),e.appendChild(n),t&&t.appendChild(e),t.appendChild(e),t}}_().registerComponent("playlistPanelItem",z);const Y=z,q=_().getComponent("Component");class J extends q{constructor(t){super(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{});const e=()=>{this.render()};t.on(o.f.PLAYLIST_ITEM_CHANGED,e),this.render(),this.dispose=()=>{super.dispose(),t.off(o.f.PLAYLIST_ITEM_CHANGED,e)}}createEl(){const t=super.createEl();return t.classList.add("cld-plw-panel"),t}removeAll(){const t=this.children();for(let e=t.length-1;e>=0;--e)this.removeChild(t[e])}getItems(){const t=this.player().cloudinary.playlist(),e=t._repeat;if(this.options_.showAll)return t.list();const s=[],i=this.options_.total;let n=t.currentIndex(),r=t.list()[n];for(s.push(r);s.length<i;){if(n=t.nextIndex(n),-1===n){if(!e&&s.length>0)break;n=0}r=t.list()[n],s.push(r)}return s}render(){const t=this.getItems();this.removeAll(),t.forEach(((t,e)=>{const s=new Y(this.player(),_().obj.merge(this.options_,{item:t,next:1===e,current:0===e}));this.addChild(s)}))}}_().registerComponent("playlistPanel",J);const Z={format:"json",resource_type:"video",type:"list"},K=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=(0,r.sliceProperties)(e,"chainTarget").chainTarget;let i=null,a=null,c=null;const d=()=>{t.on(o.f.PLAYLIST_CREATED,(()=>{c&&c.dispose(),n()(e.playlistWidget)&&(t.fluid_&&(e.playlistWidget.fluid=!0),t.cloudinary.fontFace&&(e.playlistWidget.fontFace=t.cloudinary.fontFace),c=new H(t,e.playlistWidget))}))},p=(e,s)=>{e instanceof S?(i=e,i.resetState(),i.currentIndex(i.currentIndex())):(i=new S(t.cloudinary,e,s),i.currentIndex(0)),d(),a=(()=>{const e=()=>{i&&!i.currentSource().contains(t.currentSource())&&t.disposePlaylist()};return t.on("cldsourcechanged",e),e})(),t.addClass("vjs-playlist")};return t.cloudinary.sourcesByTag=async function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=(0,l.KA)(e,Object.assign({},t.cloudinary.cloudinaryConfig(),Z)),n=await fetch(i),r=await n.json(),o=h(r.resources);s.sorter&&o.sort(s.sorter);return o.map((e=>{let i=s.sourceParams||{};"function"==typeof i&&(i=i(e));const n=e.context&&e.context.custom||{},r=Object.assign({info:n},i,{publicId:e.publicId});return t.cloudinary.buildSource(r)}))},function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return void 0===e?i:(i&&(t.removeClass("vjs-playlist"),i=void 0,t.playlist().dispose(),t.off("cldsourcechanged",a)),p(e,n),t.trigger("playlistcreated"),s)}}},8812:(t,e,s)=>{var i=s(2140),n=/^\s+/;t.exports=function(t){return t?t.slice(0,i(t)+1).replace(n,""):t}},2140:t=>{var e=/\s/;t.exports=function(t){for(var s=t.length;s--&&e.test(t.charAt(s)););return s}},4466:(t,e,s)=>{var i=s(9445);t.exports=function(t){return"number"==typeof t&&t==i(t)}},4764:(t,e,s)=>{var i=s(5378),n=1/0;t.exports=function(t){return t?(t=i(t))===n||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0}},9445:(t,e,s)=>{var i=s(4764);t.exports=function(t){var e=i(t),s=e%1;return e==e?s?e-s:e:0}},5378:(t,e,s)=>{var i=s(8812),n=s(8953),r=s(5414),o=/^[-+]0x[0-9a-f]+$/i,l=/^0b[01]+$/i,a=/^0o[0-7]+$/i,c=parseInt;t.exports=function(t){if("number"==typeof t)return t;if(r(t))return NaN;if(n(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=n(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=i(t);var s=l.test(t);return s||a.test(t)?c(t.slice(2),s?2:8):o.test(t)?NaN:+t}}}]);
//# sourceMappingURL=playlist.light.min.js.map