cloudinary-video-player 3.12.1 → 3.12.2-edge.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/dist/134.min.js +8 -0
  2. package/dist/309.min.js +6 -0
  3. package/dist/adaptive-streaming.js +9 -9
  4. package/dist/adaptive-streaming.min.js +2 -2
  5. package/dist/chapters.js +4 -4
  6. package/dist/chapters.min.js +3 -3
  7. package/dist/cld-player-core.js +37 -0
  8. package/dist/cld-player-core.min.js +6 -0
  9. package/dist/cld-video-player-lazy.js +494 -0
  10. package/dist/cld-video-player-lazy.min.js +6 -0
  11. package/dist/cld-video-player.css +2 -2
  12. package/dist/cld-video-player.js +366 -332
  13. package/dist/cld-video-player.light.js +366 -332
  14. package/dist/cld-video-player.light.min.js +4 -4
  15. package/dist/cld-video-player.min.css +2 -2
  16. package/dist/cld-video-player.min.js +4 -4
  17. package/dist/colors.js +4 -4
  18. package/dist/colors.min.js +2 -2
  19. package/dist/dash.js +6 -6
  20. package/dist/dash.min.js +2 -2
  21. package/dist/debug.js +8 -8
  22. package/dist/debug.min.js +3 -3
  23. package/dist/ima.js +9 -9
  24. package/dist/ima.min.js +2 -2
  25. package/dist/interaction-areas.js +11 -11
  26. package/dist/interaction-areas.min.js +2 -2
  27. package/dist/node_modules_lodash_throttle_js.js +8 -8
  28. package/dist/playlist.js +31 -31
  29. package/dist/playlist.min.js +3 -3
  30. package/dist/recommendations-overlay.js +10 -10
  31. package/dist/recommendations-overlay.min.js +2 -2
  32. package/dist/schema.json +19 -0
  33. package/dist/share.js +5 -5
  34. package/dist/share.min.js +3 -3
  35. package/dist/shoppable.js +12 -12
  36. package/dist/shoppable.min.js +2 -2
  37. package/dist/utils_fetch-config_js.js +81 -0
  38. package/dist/video-player_js.js +3111 -0
  39. package/dist/visual-search.js +7 -7
  40. package/dist/visual-search.min.js +2 -2
  41. package/lib/_commonjsHelpers.js +7 -0
  42. package/lib/_videojs-proxy.js +30294 -0
  43. package/lib/abr-strategies.js +31 -0
  44. package/lib/adaptive-streaming.js +468 -2
  45. package/lib/all.js +25 -2
  46. package/lib/chapters.js +205 -1
  47. package/lib/cld-video-player.min.css +5 -22
  48. package/lib/colors.js +59 -1
  49. package/lib/{schema.json → config/configSchema.json} +19 -0
  50. package/lib/dash.js +69943 -2
  51. package/lib/debug.js +322 -1
  52. package/lib/document.js +770 -0
  53. package/lib/download-button.js +48 -0
  54. package/lib/fetch-config.js +93 -0
  55. package/lib/ima.js +6851 -1
  56. package/lib/index.js +27 -0
  57. package/lib/interaction-areas.const.js +24 -0
  58. package/lib/interaction-areas.service.js +469 -0
  59. package/lib/lazy.js +20 -0
  60. package/lib/noop.js +33 -0
  61. package/lib/player-api.js +469 -0
  62. package/lib/player.js +7 -2
  63. package/lib/playlist-panel.js +602 -0
  64. package/lib/playlist.js +637 -1
  65. package/lib/querystring.js +81 -0
  66. package/lib/recommendations-overlay.js +320 -1
  67. package/lib/share.js +129 -1
  68. package/lib/shoppable-post-widget.js +572 -0
  69. package/lib/shoppable-widget.js +77 -0
  70. package/lib/throttle.js +318 -0
  71. package/lib/toNumber.js +134 -0
  72. package/lib/validators-functions.js +485 -0
  73. package/lib/video-player.js +16241 -0
  74. package/lib/videoPlayer.js +7 -2
  75. package/lib/videojs-contrib-hlsjs.js +37638 -0
  76. package/lib/visual-search.js +235 -1
  77. package/package.json +31 -15
  78. package/lib/adaptive-streaming.js.LICENSE.txt +0 -3
  79. package/lib/all.js.LICENSE.txt +0 -25
  80. package/lib/cld-video-player.js +0 -2
  81. package/lib/cld-video-player.js.LICENSE.txt +0 -21
  82. package/lib/dash.js.LICENSE.txt +0 -1842
  83. package/lib/interaction-areas.js +0 -1
  84. package/lib/player.js.LICENSE.txt +0 -21
  85. package/lib/shoppable.js +0 -1
  86. package/lib/videoPlayer.js.LICENSE.txt +0 -21
package/lib/playlist.js CHANGED
@@ -1 +1,637 @@
1
- (self.cloudinaryVideoPlayerChunkLoading=self.cloudinaryVideoPlayerChunkLoading||[]).push([[33],{5826:(t,e,s)=>{s.d(e,{default:()=>q});var i=s(5871),n=s(1104),r=s(1865),o=s(3686),l=s.n(o),a=s(4679),c=s.n(a);const d=[1,4,5,6,7,10,11],p=["created_at","updated_at"],h=t=>{const e={};return c()(t)?(Object.keys(t).reduce((e,s)=>{const i=l()(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(n.f.UP_COMING_VIDEO_SHOW,this._show),t.on(n.f.UP_COMING_VIDEO_HIDE,this._hide),t.on(n.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"),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`})}};_().registerComponent("PlaylistNextButton",class extends E{constructor(t){super(t,{type:"next"})}handleClick(t){t.stopPropagation(),super.handleClick(t),this.player().cloudinary.playlist().playNext()}});_().registerComponent("PlaylistPreviousButton",class extends E{constructor(t){super(t,{type:"previous"})}handleClick(t){super.handleClick(t),this.player().cloudinary.playlist().playPrevious()}});const T={fluid:!1,show:!0,direction:"vertical",total:4,selector:!1,renderTo:[]},b=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;!1!==t&&(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));const i=e.getInitOptions?e.getInitOptions():{};this._context.source(e,{...i,recommendationOptions:{disableAutoShow:!0,itemBuilder:s}});const n={playlist:this,current:e,next:this.next()};return this.player().trigger("playlistitemchanged",n),this._refreshRecommendations(),this._refreshTextTracks(),e}_defaultRecommendationsResolver(t){return this._defaultRecResolverCache[t.objectId]||(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))}})()},N=(t,e)=>(t.parentNode.insertBefore(e,t),e.appendChild(t),e);var S=s(3066);const P=_().dom||_(),U=_().getComponent("Component"),L={wrap:!1};class O extends U{constructor(t,e){const s={...L,...e};super(t,s),this.player_=t;const i=(t,e)=>{this.options_.fluid=e,this.removeCls(),this.setCls()};s.wrap&&(()=>{const t=this.el();this.videoWrap_=P.createEl("div",{className:"cld-plw-col-player"}),this.contentEl_=this.contentEl_=P.createEl("div",{className:"cld-plw-col-list"}),N(this.player().el(),t),t.appendChild(this.videoWrap_),t.appendChild(this.contentEl_),N(this.player().el(),this.videoWrap_)})(),t.on(n.f.FLUID,i),this.addChild(n.f.PLAYLIST_PANEL,this.options_),this.setCls(),this.dispose=()=>{this.removeLayout(),super.dispose(),t.off(n.f.FLUID,i)}}getCls(){let t=["cld-video-player","cld-plw-layout"];return t.push((0,S.skinClassPrefix)(this.player())),t.push((0,S.playerClassPrefix)(this.player())),this.options_.fluid&&t.push("cld-plw-layout-fluid"),t}setCls(){this.removeClass((0,S.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",O);const k=O,j=class extends k{constructor(t,e){e.wrap=!0,super(t,e)}getCls(){const t=super.getCls();return t.push("cld-plw-horizontal"),t}},D=class extends k{constructor(t,e){e.wrap=!0,super(t,e)}getCls(){const t=super.getCls();return t.push("cld-plw-vertical"),t}},R=class extends k{getCls(){let t=super.getCls();return t.push("cld-plw-custom"),t}createEl(){const t=super.createEl();return this.options_.renderTo.appendChild(t),t}},V=class{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e=((t,e)=>{const s={...T,...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(n.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(n.f.FLUID,s)}}render(){this.options_.useDefaultLayout&&("horizontal"===this.options_.direction?this.layout_=new j(this.player_,this.options_):this.layout_=new D(this.player_,this.options_)),this.options_.useCustomLayout&&(this.layout_=new R(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]:T.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]:T.direction;return"horizontal"!==t&&"vertical"!==t||this.update("direction",{direction:t}),this}},B=_().getComponent("ClickableComponent"),H={item:null,transformation:{width:300,aspect_ratio:"16:9",crop:"pad",background:"black"}},F=class extends B{constructor(t,e){super(t,_().obj.merge(H,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}},M=_().dom||_(),W={source:null,next:!1};class $ extends F{constructor(t,e){super(t,_().obj.merge(W,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=M.createEl("div",{className:"cld-plw-item-info-wrap"}),s=M.createEl("div",{className:"cld-plw-item-title"});if(this.isCurrent()){t.classList.add("cld-plw-panel-item-active");const e=M.createEl("span",{className:"cld-plw-item-title-curr"},{},"Now Playing: ");s.appendChild(e)}const i=M.createEl("span",{className:"cld-plw-item-title"},{},this.getTitle());s.appendChild(i);const n=M.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",$);const G=$,z=_().getComponent("Component");_().registerComponent("playlistPanel",class extends z{constructor(t){super(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{});const e=()=>{this.render()};t.on(n.f.PLAYLIST_ITEM_CHANGED,e),this.render(),this.dispose=()=>{super.dispose(),t.off(n.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 G(this.player(),_().obj.merge(this.options_,{item:t,next:1===e,current:0===e}));this.addChild(s)})}});const Y={format:"json",resource_type:"video",type:"list"},q=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=(0,i.sliceProperties)(e,"chainTarget").chainTarget;let o=null,l=null,a=null;const c=()=>{t.on(n.f.PLAYLIST_CREATED,()=>{a&&a.dispose(),0!=e.playlistWidget?.show&&(t.fluid_&&(e.playlistWidget.fluid=!0),t.cloudinary.fontFace&&(e.playlistWidget.fontFace=t.cloudinary.fontFace),a=new V(t,e.playlistWidget))})};return t.cloudinary.sourcesByTag=async function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=(0,r.KA)(e,Object.assign({},t.cloudinary.cloudinaryConfig(),Y)),n=await fetch(i),o=await n.json(),l=h(o.resources);return s.sorter&&l.sort(s.sorter),l.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 i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return void 0===e?o:(o&&(t.removeClass("vjs-playlist"),o=void 0,t.playlist().dispose(),t.off("cldsourcechanged",l)),((e,s)=>{e instanceof b?(o=e,o.resetState(),o.currentIndex(o.currentIndex())):(o=new b(t.cloudinary,e,s),o.currentIndex(0)),c(),l=(()=>{const e=()=>{o&&!o.currentSource().contains(t.currentSource())&&t.disposePlaylist()};return t.on("cldsourcechanged",e),e})(),t.addClass("vjs-playlist")})(e,i),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(1826);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}},1826:(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}}}]);
1
+ import { j as isPlainObject, k as camelCase, V as VideoSource, P as PLAYER_EVENT, l as sliceProperties, g as getCloudinaryUrl } from './video-player.js';
2
+ import { i as isInteger, P as PlaylistLayout } from './playlist-panel.js';
3
+ import { _ as _vjs } from './_videojs-proxy.js';
4
+ import './_commonjsHelpers.js';
5
+ import './validators-functions.js';
6
+ import './querystring.js';
7
+ import './player-api.js';
8
+ import './toNumber.js';
9
+
10
+ // https://github.com/csnover/js-iso8601/blob/master/iso8601.js
11
+ const numericKeys = [1, 4, 5, 6, 7, 10, 11];
12
+ const parseISO8601 = function (date) {
13
+ let timestamp = 0;
14
+ let struct = 0;
15
+ let minutesOffset = 0;
16
+
17
+ // ES5 §15.9.4.2 states that the string should attempt to be parsed as a Date Time String Format string
18
+ // before falling back to any implementation-specific date parsing, so that’s what we do, even if native
19
+ // implementations could be faster
20
+ // 1 YYYY 2 MM 3 DD 4 HH 5 mm 6 ss 7 msec 8 Z 9 ± 10 tzHH 11 tzmm
21
+ if (struct = /^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2})(?::(\d{2}))?)?)?$/.exec(date)) {
22
+ // avoid NaN timestamps caused by “undefined” values being passed to Date.UTC
23
+ for (let i = 0, k; k = numericKeys[i]; ++i) {
24
+ struct[k] = +struct[k] || 0;
25
+ }
26
+
27
+ // allow undefined days and months
28
+ struct[2] = (+struct[2] || 1) - 1;
29
+ struct[3] = +struct[3] || 1;
30
+ if (struct[8] !== 'Z' && struct[9] !== undefined) {
31
+ minutesOffset = struct[10] * 60 + struct[11];
32
+ if (struct[9] === '+') {
33
+ minutesOffset = 0 - minutesOffset;
34
+ }
35
+ }
36
+ timestamp = Date.UTC(struct[1], struct[2], struct[3], struct[4], struct[5] + minutesOffset, struct[6], struct[7]);
37
+ } else {
38
+ timestamp = NaN;
39
+ }
40
+ return timestamp;
41
+ };
42
+
43
+ const TIME_FIELDS = ['created_at', 'updated_at'];
44
+ const normalizeJsonResponse = obj => {
45
+ const agg = {};
46
+ if (isPlainObject(obj)) {
47
+ Object.keys(obj).reduce((agg, key) => {
48
+ const newKey = camelCase(key);
49
+ if (TIME_FIELDS.indexOf(key) !== -1) {
50
+ agg[newKey] = new Date(parseISO8601(obj[key]));
51
+ } else {
52
+ agg[newKey] = normalizeJsonResponse(obj[key]);
53
+ }
54
+ return agg;
55
+ }, agg);
56
+ return agg;
57
+ } else if (Array.isArray(obj)) {
58
+ return obj.map(item => normalizeJsonResponse(item));
59
+ } else {
60
+ return obj;
61
+ }
62
+ };
63
+
64
+ const DEFAULT_AUTO_ADVANCE = 0;
65
+ const DEFAULT_PRESENT_UPCOMING = 10;
66
+ const UPCOMING_VIDEO_TRANSITION = 1;
67
+ const PLAYLIST_DEFAULTS_OPTIONS = {
68
+ fluid: false,
69
+ show: true,
70
+ direction: 'vertical',
71
+ total: 4,
72
+ selector: false,
73
+ renderTo: []
74
+ };
75
+
76
+ class Playlist {
77
+ constructor(context) {
78
+ let sources = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
79
+ let {
80
+ repeat = false,
81
+ autoAdvance = false,
82
+ presentUpcoming = false
83
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
84
+ this._context = context;
85
+ this._sources = [];
86
+ this._defaultRecResolverCache = {};
87
+ this._currentIndex = null;
88
+ this._recommendationsHandler = null;
89
+ this._autoAdvance = null;
90
+ this._presentUpcoming = null;
91
+ this.addUiComponents();
92
+ this.resetState = () => {
93
+ this.repeat(repeat);
94
+ this.autoAdvance(autoAdvance);
95
+ this.presentUpcoming(presentUpcoming);
96
+ };
97
+ sources.forEach(source => this.enqueue(source));
98
+ this.resetState();
99
+ }
100
+ list() {
101
+ return this._sources;
102
+ }
103
+ player() {
104
+ return this._context.player;
105
+ }
106
+ addUiComponents() {
107
+ const controlBar = this.player().getChild('ControlBar');
108
+ const children = controlBar.children();
109
+ controlBar.addChild('playlistPreviousButton', {}, children.findIndex(c => c.name_ === 'PlayToggle'));
110
+ controlBar.addChild('playlistNextButton', {}, children.findIndex(c => c.name_ === 'PlayToggle') + 1);
111
+ this.player().addChild('upcomingVideoOverlay');
112
+ }
113
+ presentUpcoming(delay) {
114
+ this._presentUpcoming = this._presentUpcoming || {};
115
+ if (delay === undefined) {
116
+ return this._presentUpcoming.delay;
117
+ }
118
+ if (delay === true) {
119
+ delay = DEFAULT_PRESENT_UPCOMING;
120
+ } else if (delay === false) {
121
+ delay = false;
122
+ } else if (!isInteger(delay) || delay < 0) {
123
+ throw new Error('presentUpcoming \'delay\' must be either a boolean or a positive integer.');
124
+ }
125
+ this._presentUpcoming.delay = delay;
126
+ this._setupPresentUpcoming();
127
+ return this._presentUpcoming.delay;
128
+ }
129
+ autoAdvance(delay) {
130
+ this._autoAdvance = this._autoAdvance || {};
131
+ if (delay === undefined) {
132
+ return this._autoAdvance.delay;
133
+ }
134
+ if (delay === true) {
135
+ delay = DEFAULT_AUTO_ADVANCE;
136
+ } else if (delay === false) {
137
+ delay = false;
138
+ } else if (!isInteger(delay) || delay < 0) {
139
+ throw new Error('Auto advance \'delay\' must be either a boolean or a positive integer.');
140
+ }
141
+ this._autoAdvance.delay = delay;
142
+ this._setupAutoAdvance();
143
+ return this._autoAdvance.delay;
144
+ }
145
+ _setupAutoAdvance() {
146
+ this._resetAutoAdvance();
147
+ const delay = this._autoAdvance.delay;
148
+ if (delay === false) {
149
+ return;
150
+ }
151
+ const trigger = () => {
152
+ if (this.player().ended()) {
153
+ this._autoAdvance.timeout = setTimeout(() => {
154
+ this.playNext();
155
+ }, delay * 1000);
156
+ }
157
+ };
158
+ this._autoAdvance = {
159
+ delay,
160
+ trigger
161
+ };
162
+ this._context.on('ended', this._autoAdvance.trigger);
163
+ }
164
+ dispose() {
165
+ this._resetAutoAdvance();
166
+ this._resetPresentUpcoming();
167
+ this._resetRecommendations();
168
+ }
169
+ _resetPresentUpcoming() {
170
+ this.player().trigger('upcomingvideohide');
171
+ if (!this._presentUpcoming) {
172
+ this._presentUpcoming = {};
173
+ }
174
+ if (this._presentUpcoming.trigger) {
175
+ this._context.off('timeupdate', this._presentUpcoming.trigger);
176
+ }
177
+ this._presentUpcoming.trigger = null;
178
+ this._presentUpcoming.showTriggered = false;
179
+ }
180
+ _setupPresentUpcoming() {
181
+ this._resetPresentUpcoming();
182
+ const delay = this._presentUpcoming.delay;
183
+ if (delay === false) {
184
+ return;
185
+ }
186
+ this._presentUpcoming.trigger = () => {
187
+ const currentTime = this.player().currentTime();
188
+ const duration = this.player().duration();
189
+ const remainingTime = duration - currentTime;
190
+ if (remainingTime < UPCOMING_VIDEO_TRANSITION + 0.5) {
191
+ if (this._presentUpcoming.showTriggered) {
192
+ this.player().trigger('upcomingvideohide');
193
+ this._presentUpcoming.showTriggered = false;
194
+ }
195
+ } else if (remainingTime <= this._presentUpcoming.delay && !this._presentUpcoming.showTriggered && !this.player().loop()) {
196
+ this.player().trigger('upcomingvideoshow');
197
+ this._presentUpcoming.showTriggered = true;
198
+ } else if (this._presentUpcoming.showTriggered && (remainingTime > this._presentUpcoming.delay || this.player().loop())) {
199
+ this.player().trigger('upcomingvideohide');
200
+ this._presentUpcoming.showTriggered = false;
201
+ }
202
+ };
203
+ this._context.on('timeupdate', this._presentUpcoming.trigger);
204
+ }
205
+ _resetAutoAdvance() {
206
+ if (!this._autoAdvance) {
207
+ this._autoAdvance = {};
208
+ }
209
+ if (this._autoAdvance.timeout) {
210
+ clearTimeout(this._autoAdvance.timeout);
211
+ }
212
+ if (this._autoAdvance.trigger) {
213
+ this._context.off('ended', this._autoAdvance.trigger);
214
+ }
215
+ this._autoAdvance.timeout = null;
216
+ this._autoAdvance.trigger = null;
217
+ }
218
+ _resetRecommendations() {
219
+ if (this._recommendationsHandler) {
220
+ this._context.off('ended', this._recommendationsHandler);
221
+ }
222
+ }
223
+ _refreshRecommendations() {
224
+ this._resetRecommendations();
225
+ this._recommendationsHandler = () => {
226
+ if (this.autoAdvance() === false && this._context.autoShowRecommendations()) {
227
+ this.player().trigger('recommendationsshow');
228
+ }
229
+ };
230
+ this._context.on('ended', this._recommendationsHandler);
231
+ }
232
+ _refreshTextTracks() {
233
+ this.player().trigger('refreshTextTracks', this.currentSource().textTracks());
234
+ }
235
+ _recommendationItemBuilder(source) {
236
+ const defaultResolver = this._defaultRecResolverCache[source.objectId];
237
+ if (source.recommendations() && (!defaultResolver || source.recommendations() !== defaultResolver)) {
238
+ return;
239
+ }
240
+ return source => ({
241
+ source,
242
+ action: () => this.playItem(source)
243
+ });
244
+ }
245
+ currentIndex(index) {
246
+ if (index === undefined) {
247
+ return this._currentIndex;
248
+ }
249
+ if (index >= this.length() || index < 0) {
250
+ throw new Error('Invalid playlist index.');
251
+ }
252
+ this._currentIndex = index;
253
+ const current = this.currentSource();
254
+ const itemBuilder = this._recommendationItemBuilder(current);
255
+ if (!current.recommendations()) {
256
+ current.recommendations(this._defaultRecommendationsResolver(current));
257
+ }
258
+
259
+ // Extract source options for analytics
260
+ const sourceOptions = current.getInitOptions ? current.getInitOptions() : {};
261
+ this._context.source(current, {
262
+ ...sourceOptions,
263
+ recommendationOptions: {
264
+ disableAutoShow: true,
265
+ itemBuilder
266
+ }
267
+ });
268
+ const eventData = {
269
+ playlist: this,
270
+ current,
271
+ next: this.next()
272
+ };
273
+ this.player().trigger('playlistitemchanged', eventData);
274
+ this._refreshRecommendations();
275
+ this._refreshTextTracks();
276
+ return current;
277
+ }
278
+ _defaultRecommendationsResolver(source) {
279
+ const defaultResolver = this._defaultRecResolverCache[source.objectId];
280
+ if (defaultResolver) {
281
+ return defaultResolver;
282
+ }
283
+ this._defaultRecResolverCache[source.objectId] = () => {
284
+ let index = this.list().indexOf(source);
285
+ const items = [];
286
+ const numOfItems = Math.min(4, this.length() - 1);
287
+ while (items.length < numOfItems) {
288
+ index = this.nextIndex(index);
289
+ if (index === -1) {
290
+ break;
291
+ }
292
+ const source = this.list()[index];
293
+ items.push(source);
294
+ }
295
+ return items;
296
+ };
297
+ return this._defaultRecResolverCache[source.objectId];
298
+ }
299
+ buildSource(source) {
300
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
301
+ return this._context.buildSource(source, options);
302
+ }
303
+ enqueue(source) {
304
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
305
+ const src = source instanceof VideoSource ? source : this.buildSource(source, options);
306
+ this._sources.push(src);
307
+ return src;
308
+ }
309
+ playItem(item) {
310
+ let index = this.list().indexOf(item);
311
+ if (index === -1) {
312
+ throw new Error('Invalid playlist item.');
313
+ }
314
+ this.playAtIndex(index);
315
+ }
316
+ playAtIndex(index) {
317
+ this.currentIndex(index);
318
+ this.player().play();
319
+ return this.currentSource();
320
+ }
321
+ currentSource() {
322
+ return this.list()[this.currentIndex()];
323
+ }
324
+ removeAt(index) {
325
+ if (index >= this.length() || index < 0) {
326
+ throw new Error('Invalid playlist index.');
327
+ }
328
+ this._sources.splice(index, 1);
329
+ return this;
330
+ }
331
+ repeat(repeat) {
332
+ if (repeat === undefined) {
333
+ return this._repeat;
334
+ }
335
+ this._repeat = !!repeat;
336
+ return this._repeat;
337
+ }
338
+ first() {
339
+ return this.list()[0];
340
+ }
341
+ last() {
342
+ return this.list()[this.length() - 1];
343
+ }
344
+ next() {
345
+ const nextIndex = this.nextIndex();
346
+ if (nextIndex === -1) {
347
+ return null;
348
+ }
349
+ return this.list()[nextIndex];
350
+ }
351
+ nextIndex(index) {
352
+ index = index !== undefined ? index : this.currentIndex();
353
+ if (index >= this.length() || index < 0) {
354
+ throw new Error('Invalid playlist index.');
355
+ }
356
+ const isLast = index === this.length() - 1;
357
+ let nextIndex = index + 1;
358
+ if (isLast) {
359
+ if (this.repeat()) {
360
+ nextIndex = 0;
361
+ } else {
362
+ return -1;
363
+ }
364
+ }
365
+ return nextIndex;
366
+ }
367
+ previousIndex() {
368
+ if (this.isFirst()) {
369
+ return -1;
370
+ }
371
+ return this.currentIndex() - 1;
372
+ }
373
+ playFirst() {
374
+ return this.playAtIndex(0);
375
+ }
376
+ playLast() {
377
+ const lastIndex = this.list().length - 1;
378
+ return this.playAtIndex(lastIndex);
379
+ }
380
+ isLast() {
381
+ return this.currentIndex() >= this.length() - 1;
382
+ }
383
+ isFirst() {
384
+ return this.currentIndex() === 0;
385
+ }
386
+ length() {
387
+ return this.list().length;
388
+ }
389
+ playNext() {
390
+ let nextIndex = this.nextIndex();
391
+ if (nextIndex === -1) {
392
+ return null;
393
+ }
394
+ return this.playAtIndex(nextIndex);
395
+ }
396
+ playPrevious() {
397
+ let previousIndex = this.previousIndex();
398
+ if (previousIndex === -1) {
399
+ return null;
400
+ }
401
+ return this.playAtIndex(previousIndex);
402
+ }
403
+ playlistByTag = (() => {
404
+ var _this = this;
405
+ return function (tag) {
406
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
407
+ return _this.player().sourcesByTag(tag, options).then(sources => _this.player().playlist(sources, options));
408
+ };
409
+ })();
410
+ }
411
+
412
+ class PlaylistLayoutHorizontal extends PlaylistLayout {
413
+ constructor(player, options) {
414
+ options.wrap = true;
415
+ super(player, options);
416
+ }
417
+ getCls() {
418
+ const cls = super.getCls();
419
+ cls.push('cld-plw-horizontal');
420
+ return cls;
421
+ }
422
+ }
423
+
424
+ class PlaylistLayoutVertical extends PlaylistLayout {
425
+ constructor(player, options) {
426
+ options.wrap = true;
427
+ super(player, options);
428
+ }
429
+ getCls() {
430
+ const cls = super.getCls();
431
+ cls.push('cld-plw-vertical');
432
+ return cls;
433
+ }
434
+ }
435
+
436
+ class PlaylistLayoutCustom extends PlaylistLayout {
437
+ getCls() {
438
+ let cls = super.getCls();
439
+ cls.push('cld-plw-custom');
440
+ return cls;
441
+ }
442
+ createEl() {
443
+ const el = super.createEl();
444
+ this.options_.renderTo.appendChild(el);
445
+ return el;
446
+ }
447
+ }
448
+
449
+ const modifyOptions = (player, opt) => {
450
+ const options = {
451
+ ...PLAYLIST_DEFAULTS_OPTIONS,
452
+ ...opt
453
+ };
454
+ if (options.show && typeof options.selector === 'string') {
455
+ options.useDefaultLayout = false;
456
+ options.useCustomLayout = true;
457
+ options.renderTo = document.querySelector(options.selector);
458
+ options.showAll = true;
459
+ if (!options.renderTo.length === 0) {
460
+ throw new Error(`Couldn't find element(s) by selector '${options.selector}' for playlist`);
461
+ }
462
+ }
463
+ if (options.show && !options.selector) {
464
+ options.useDefaultLayout = true;
465
+ options.useCustomLayout = false;
466
+ }
467
+ options.direction = options.direction.toLowerCase() === 'horizontal' ? 'horizontal' : 'vertical';
468
+ options.skin = player.options_.skin;
469
+ return options;
470
+ };
471
+ class PlaylistWidget {
472
+ constructor(player) {
473
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
474
+ options = modifyOptions(player, options);
475
+ this.options_ = options;
476
+ this.player_ = player;
477
+ this.render();
478
+ const fluidHandler = (e, fluid) => {
479
+ this.options_.fluid = fluid;
480
+ };
481
+ player.on(PLAYER_EVENT.FLUID, fluidHandler);
482
+ this.options = options => {
483
+ if (!options) {
484
+ return this.options_;
485
+ }
486
+ this.options_ = _vjs.obj.merge(this.options_, options);
487
+ player.trigger('playlistwidgetoption', this.options_.playlistWidget);
488
+ return this.options_;
489
+ };
490
+ this.dispose = () => {
491
+ this.layout_.dispose();
492
+ player.off(PLAYER_EVENT.FLUID, fluidHandler);
493
+ };
494
+ }
495
+ render() {
496
+ if (this.options_.useDefaultLayout) {
497
+ if (this.options_.direction === 'horizontal') {
498
+ this.layout_ = new PlaylistLayoutHorizontal(this.player_, this.options_);
499
+ } else {
500
+ this.layout_ = new PlaylistLayoutVertical(this.player_, this.options_);
501
+ }
502
+ }
503
+ if (this.options_.useCustomLayout) {
504
+ this.layout_ = new PlaylistLayoutCustom(this.player_, this.options_);
505
+ }
506
+ }
507
+ getLayout() {
508
+ return this.layout_;
509
+ }
510
+ update(optionName, optionValue) {
511
+ this.options(optionValue);
512
+ if (optionName === 'direction') {
513
+ this.layout_.removeLayout();
514
+ this.layout_.dispose();
515
+ this.render();
516
+ } else {
517
+ this.layout_.update(optionName, this.options_);
518
+ }
519
+ }
520
+ setSkin() {
521
+ this.layout_.setCls();
522
+ }
523
+ total() {
524
+ let totalNumber = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : PLAYLIST_DEFAULTS_OPTIONS.total;
525
+ const total = parseInt(totalNumber, 10);
526
+ if (total !== this.options_.total && typeof total === 'number' && total > 0) {
527
+ this.update('total', {
528
+ total: total
529
+ });
530
+ }
531
+ return this;
532
+ }
533
+ direction() {
534
+ let direction = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : PLAYLIST_DEFAULTS_OPTIONS.direction;
535
+ if (direction === 'horizontal' || direction === 'vertical') {
536
+ this.update('direction', {
537
+ direction: direction
538
+ });
539
+ }
540
+ return this;
541
+ }
542
+ }
543
+
544
+ const LIST_BY_TAG_PARAMS = {
545
+ format: 'json',
546
+ resource_type: 'video',
547
+ type: 'list'
548
+ };
549
+ const playlist = function (player) {
550
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
551
+ const chainTarget = sliceProperties(options, 'chainTarget').chainTarget;
552
+ let playlistInstance = null;
553
+ let playlistDisposer = null;
554
+ let playlistWidget = null;
555
+ const initPlaylistWidget = () => {
556
+ player.on(PLAYER_EVENT.PLAYLIST_CREATED, () => {
557
+ if (playlistWidget) {
558
+ playlistWidget.dispose();
559
+ }
560
+ if (options.playlistWidget?.show != false) {
561
+ if (player.fluid_) {
562
+ options.playlistWidget.fluid = true;
563
+ }
564
+ if (player.cloudinary.fontFace) {
565
+ options.playlistWidget.fontFace = player.cloudinary.fontFace;
566
+ }
567
+ playlistWidget = new PlaylistWidget(player, options.playlistWidget);
568
+ }
569
+ });
570
+ };
571
+ const disposePlaylist = () => {
572
+ player.removeClass('vjs-playlist');
573
+ playlistInstance = undefined;
574
+ player.playlist().dispose();
575
+ player.off('cldsourcechanged', playlistDisposer);
576
+ };
577
+ const addPlaylistDisposer = () => {
578
+ const disposer = () => {
579
+ if (playlistInstance && !playlistInstance.currentSource().contains(player.currentSource())) {
580
+ player.disposePlaylist();
581
+ }
582
+ };
583
+ player.on('cldsourcechanged', disposer);
584
+ return disposer;
585
+ };
586
+ const createPlaylist = (sources, options) => {
587
+ if (sources instanceof Playlist) {
588
+ playlistInstance = sources;
589
+ playlistInstance.resetState();
590
+ playlistInstance.currentIndex(playlistInstance.currentIndex());
591
+ } else {
592
+ playlistInstance = new Playlist(player.cloudinary, sources, options);
593
+ playlistInstance.currentIndex(0);
594
+ }
595
+ initPlaylistWidget();
596
+ playlistDisposer = addPlaylistDisposer();
597
+ player.addClass('vjs-playlist');
598
+ };
599
+ player.cloudinary.sourcesByTag = async function (tag) {
600
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
601
+ const url = getCloudinaryUrl(tag, Object.assign({}, player.cloudinary.cloudinaryConfig(), LIST_BY_TAG_PARAMS));
602
+ const result = await fetch(url);
603
+ const json = await result.json();
604
+ const resources = normalizeJsonResponse(json.resources);
605
+ if (options.sorter) {
606
+ resources.sort(options.sorter);
607
+ }
608
+ const sources = resources.map(resource => {
609
+ let sourceParams = options.sourceParams || {};
610
+ if (typeof sourceParams === 'function') {
611
+ sourceParams = sourceParams(resource);
612
+ }
613
+ const info = resource.context && resource.context.custom || {};
614
+ const source = Object.assign({
615
+ info
616
+ }, sourceParams, {
617
+ publicId: resource.publicId
618
+ });
619
+ return player.cloudinary.buildSource(source);
620
+ });
621
+ return sources;
622
+ };
623
+ return function (sources) {
624
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
625
+ if (sources === undefined) {
626
+ return playlistInstance;
627
+ }
628
+ if (playlistInstance) {
629
+ disposePlaylist();
630
+ }
631
+ createPlaylist(sources, options);
632
+ player.trigger('playlistcreated');
633
+ return chainTarget;
634
+ };
635
+ };
636
+
637
+ export { playlist as default };