@castlabs/prestoplay 6.12.0 → 6.13.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 (62) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/cjs/cl.adobe.js +3 -3
  3. package/cjs/cl.airplay.js +3 -3
  4. package/cjs/cl.broadpeak.js +6 -6
  5. package/cjs/cl.cast.js +106 -106
  6. package/cjs/cl.conviva.js +33 -33
  7. package/cjs/cl.core.js +504 -505
  8. package/cjs/cl.crypto.js +9 -9
  9. package/cjs/cl.dash.js +72 -72
  10. package/cjs/cl.externs.js +53 -50
  11. package/cjs/cl.freewheel.js +22 -22
  12. package/cjs/cl.hls.js +66 -66
  13. package/cjs/cl.hlssmpte.js +6 -6
  14. package/cjs/cl.htmlcue.js +30 -30
  15. package/cjs/cl.ima.js +21 -21
  16. package/cjs/cl.mse.js +269 -267
  17. package/cjs/cl.muxdata.js +14 -14
  18. package/cjs/cl.onboard.js +3 -3
  19. package/cjs/cl.persistent.js +13 -13
  20. package/cjs/cl.playlist.js +6 -6
  21. package/cjs/cl.simid.js +15 -15
  22. package/cjs/cl.smooth.js +71 -71
  23. package/cjs/cl.thumbnails.js +26 -24
  24. package/cjs/cl.tizen.js +68 -68
  25. package/cjs/cl.ttml.js +28 -28
  26. package/cjs/cl.verimatrix.js +5 -5
  27. package/cjs/cl.vimond.js +13 -13
  28. package/cjs/cl.vr.js +19 -19
  29. package/cjs/cl.vtt.js +14 -14
  30. package/cjs/cl.youbora.js +16 -16
  31. package/cjs/polyfill.min.js +26 -23
  32. package/cl.adobe.js +3 -3
  33. package/cl.airplay.js +3 -3
  34. package/cl.broadpeak.js +5 -5
  35. package/cl.cast.js +83 -83
  36. package/cl.conviva.js +27 -27
  37. package/cl.core.js +416 -416
  38. package/cl.crypto.js +9 -9
  39. package/cl.dash.js +67 -67
  40. package/cl.externs.js +53 -50
  41. package/cl.freewheel.js +15 -15
  42. package/cl.hls.js +69 -69
  43. package/cl.hlssmpte.js +5 -5
  44. package/cl.htmlcue.js +26 -26
  45. package/cl.ima.js +15 -15
  46. package/cl.mse.js +232 -231
  47. package/cl.muxdata.js +12 -12
  48. package/cl.onboard.js +4 -4
  49. package/cl.persistent.js +10 -10
  50. package/cl.playlist.js +5 -5
  51. package/cl.simid.js +13 -13
  52. package/cl.smooth.js +59 -59
  53. package/cl.thumbnails.js +19 -17
  54. package/cl.tizen.js +57 -57
  55. package/cl.ttml.js +22 -22
  56. package/cl.verimatrix.js +4 -4
  57. package/cl.vimond.js +8 -8
  58. package/cl.vr.js +14 -14
  59. package/cl.vtt.js +12 -12
  60. package/cl.youbora.js +13 -13
  61. package/package.json +1 -1
  62. package/typings.d.ts +82 -13
package/cl.freewheel.js CHANGED
@@ -1,19 +1,19 @@
1
- import {clpp} from "./cl.core.js";let g={};const _ = clpp._;var f=function(window){'use strict';var WN="clpp-freewheel",XN="clpp.freewheel.AdsManagerFactory",YN="freewheel",ZN=function(a){switch(a){case 0:return tv.freewheel.SDK.ADUNIT_PREROLL;case 1:return tv.freewheel.SDK.ADUNIT_MIDROLL;case 2:return tv.freewheel.SDK.ADUNIT_POSTROLL;default:return""}},$N=function(a){const b=[];typeof a.networkId!==_.r&&b.push("networkId");typeof a.serverUrl!==_.tf&&b.push("serverUrl");typeof a.profileId!==_.tf&&b.push("profileId");typeof a.videoAssetId!==_.tf&&typeof a.videoAssetId!==_.r&&b.push("videoAssetId");
2
- if(b.length)throw new _.H(1,9,12001,{missingKeys:b.join(", ")});},aO=function(){return _.x(function*(){var a=new _.Ws;let b=tv.freewheel.SDK.VIDEO_ASSET_AUTO_PLAY_TYPE_NONE;const c=yield a.canPlay(!1);a=yield a.canPlay(!0);c?b=tv.freewheel.SDK.VIDEO_ASSET_AUTO_PLAY_TYPE_ATTENDED:a&&(b=tv.freewheel.SDK.VIDEO_ASSET_AUTO_PLAY_TYPE_UNATTENDED);return b})},bO=function(a){a.g.on(a.a,tv.freewheel.SDK.EVENT_REQUEST_COMPLETE,a.H.bind(a));a.g.on(a.a,tv.freewheel.SDK.EVENT_SLOT_STARTED,a.J.bind(a));a.g.on(a.a,
3
- tv.freewheel.SDK.EVENT_SLOT_ENDED,a.I.bind(a));a.g.on(a.a,tv.freewheel.SDK.EVENT_AD,a.G.bind(a));a.g.on(a.m,_.Af,a.F.bind(a));a.g.on(a.m,_.qf,a.C.bind(a))},eO=function(a){return _.x(function*(){a.B.length?(cO(a),a.f=a.B.shift(),a.f.play()):(dO(a),yield a.m.a.play())})},dO=function(a){const b=a.m.ac(YN).vc();b&&a.m.getSurface().hide(b);a.m.getSurface().showMediaElement()},cO=function(a){const b=a.m.ac(YN).vc();b&&(a.m.getSurface().show(b),a.m.getSurface().hideMediaElement(),a.a.registerVideoDisplayBase(WN),
4
- a.m.isMuted()?a.setVolume(0):a.setVolume(a.m.getVolume()||1))},fO=function(a){a.A.length?(cO(a),a.f=a.A.shift(),a.f.play()):dO(a)},gO=function(a,b,c){var d=null;a.a&&c&&(c.adInstance||c.slot)&&(c=(d=c.adInstance||null)?d.getSlot():c.slot,d={ad:new Y(a.a,c,d)});a.m.trigger(new _.F(b,d))},hO=class extends _.ft{constructor(){super();this.f=this.a=null}onPlayerCreated(a){if(window.tv&&tv.freewheel&&tv.freewheel.SDK)this.a=_.Hn(_.yd,{id:WN}),this.f=_.Hn(_.w,{"class":_.Xc}),this.a.appendChild(this.f),a.getSurface().addElementToContainer(this.a,
5
- !0),a.getSurface().hide(this.a);else a.onError(new _.H(1,9,12E3))}onPlayerWillDestroy(a){this.a&&(a.getSurface().removeElementFromContainer(this.a),this.f=this.a=null)}id(){return YN}vc(){return this.a}kg(){return this.f}};_.z("clpp.freewheel.FreeWheelPlugin",hO);hO.prototype.getAdVideo=hO.prototype.kg;hO.prototype.getAdContainer=hO.prototype.vc;hO.Id=YN;hO.AD_CONTAINER_ID=WN;_.oo(new class{create(){return new hO}});var Y=class{constructor(a,b,c){this.g=a;this.f=b;this.a=c}rb(){return"FreeWheel AdManager SDK"}sb(){return tv.freewheel.SDK.version}yb(){return 0}getId(){return this.a?this.a.getAdId():""}getCreativeId(){const a=(this.a||{})._creativeId;return typeof a===_.tf?a:""}getApiFramework(){return this.a?this.a.getActiveCreativeRendition().getCreativeApi():""}getAdSystem(){return""}getAdvertiserName(){return""}getTitle(){return""}getDuration(){return this.a?this.a.getActiveCreativeRendition().getDuration():
1
+ import {clpp} from "./cl.core.js";let g={};const _ = clpp._;var f=function(window){'use strict';var gO="clpp-freewheel",hO="clpp.freewheel.AdsManagerFactory",iO="freewheel",jO=function(a){switch(a){case 0:return tv.freewheel.SDK.ADUNIT_PREROLL;case 1:return tv.freewheel.SDK.ADUNIT_MIDROLL;case 2:return tv.freewheel.SDK.ADUNIT_POSTROLL;default:return""}},kO=function(a){const b=[];typeof a.networkId!==_.r&&b.push("networkId");typeof a.serverUrl!==_.uf&&b.push("serverUrl");typeof a.profileId!==_.uf&&b.push("profileId");typeof a.videoAssetId!==_.uf&&typeof a.videoAssetId!==_.r&&b.push("videoAssetId");
2
+ if(b.length)throw new _.H(1,9,12001,{missingKeys:b.join(", ")});},lO=function(){return _.x(function*(){var a=new _.bt;let b=tv.freewheel.SDK.VIDEO_ASSET_AUTO_PLAY_TYPE_NONE;const c=yield a.canPlay(!1);a=yield a.canPlay(!0);c?b=tv.freewheel.SDK.VIDEO_ASSET_AUTO_PLAY_TYPE_ATTENDED:a&&(b=tv.freewheel.SDK.VIDEO_ASSET_AUTO_PLAY_TYPE_UNATTENDED);return b})},mO=function(a){a.g.on(a.a,tv.freewheel.SDK.EVENT_REQUEST_COMPLETE,a.H.bind(a));a.g.on(a.a,tv.freewheel.SDK.EVENT_SLOT_STARTED,a.J.bind(a));a.g.on(a.a,
3
+ tv.freewheel.SDK.EVENT_SLOT_ENDED,a.I.bind(a));a.g.on(a.a,tv.freewheel.SDK.EVENT_AD,a.G.bind(a));a.g.on(a.m,_.Bf,a.F.bind(a));a.g.on(a.m,_.rf,a.C.bind(a))},pO=function(a){return _.x(function*(){a.B.length?(nO(a),a.f=a.B.shift(),a.f.play()):(oO(a),yield a.m.a.play())})},oO=function(a){const b=a.m.ac(iO).vc();b&&a.m.getSurface().hide(b);a.m.getSurface().showMediaElement()},nO=function(a){const b=a.m.ac(iO).vc();b&&(a.m.getSurface().show(b),a.m.getSurface().hideMediaElement(),a.a.registerVideoDisplayBase(gO),
4
+ a.m.isMuted()?a.setVolume(0):a.setVolume(a.m.getVolume()||1))},qO=function(a){a.A.length?(nO(a),a.f=a.A.shift(),a.f.play()):oO(a)},rO=function(a,b,c){var d=null;a.a&&c&&(c.adInstance||c.slot)&&(c=(d=c.adInstance||null)?d.getSlot():c.slot,d={ad:new Y(a.a,c,d)});a.m.trigger(new _.F(b,d))},sO=class extends _.jt{constructor(){super();this.f=this.a=null}onPlayerCreated(a){if(window.tv&&tv.freewheel&&tv.freewheel.SDK)this.a=_.Kn(_.zd,{id:gO}),this.f=_.Kn(_.w,{"class":_.Xc}),this.a.appendChild(this.f),a.getSurface().addElementToContainer(this.a,
5
+ !0),a.getSurface().hide(this.a);else a.onError(new _.H(1,9,12E3))}onPlayerWillDestroy(a){this.a&&(a.getSurface().removeElementFromContainer(this.a),this.f=this.a=null)}id(){return iO}vc(){return this.a}jg(){return this.f}};_.z("clpp.freewheel.FreeWheelPlugin",sO);sO.prototype.getAdVideo=sO.prototype.jg;sO.prototype.getAdContainer=sO.prototype.vc;sO.Id=iO;sO.AD_CONTAINER_ID=gO;_.ro(new class{create(){return new sO}});var Y=class{constructor(a,b,c){this.g=a;this.f=b;this.a=c}rb(){return"FreeWheel AdManager SDK"}sb(){return tv.freewheel.SDK.version}yb(){return 0}getId(){return this.a?this.a.getAdId():""}getCreativeId(){const a=(this.a||{})._creativeId;return typeof a===_.uf?a:""}getApiFramework(){return this.a?this.a.getActiveCreativeRendition().getCreativeApi():""}getAdSystem(){return""}getAdvertiserName(){return""}getTitle(){return""}getDuration(){return this.a?this.a.getActiveCreativeRendition().getDuration():
6
6
  0}getSkipTimeOffset(){return 0}ec(){return!1}Lb(){return this.a&&this.a.getEventCallbackUrls(tv.freewheel.SDK.EVENT_AD_CLICK,tv.freewheel.SDK.EVENT_TYPE_CLICK)[0]||""}getMediaUrl(){return this.a?this.a.getActiveCreativeRendition().getPrimaryCreativeRenditionAsset().getUrl():""}vb(){return this.a?this.a.getActiveCreativeRendition().getWidth():0}ub(){return this.a?this.a.getActiveCreativeRendition().getHeight():0}ib(){return 0}Va(){switch(this.f.getTimePositionClass()){case tv.freewheel.SDK.TIME_POSITION_CLASS_PREROLL:return 0;
7
7
  case tv.freewheel.SDK.TIME_POSITION_CLASS_POSTROLL:return 2;default:return 1}}getPodIndex(){switch(this.Va()){case 0:return 0;case 2:return-1}return this.g.getSlotsByTimePositionClass(tv.freewheel.SDK.TIME_POSITION_CLASS_MIDROLL).indexOf(this.f)+1}Mb(){switch(this.Va()){case 0:return 0;case 2:return-1;default:return this.f.getTimePosition()}}Nb(){return this.a?this.f.getAdInstances().indexOf(this.a)+1:1}xb(){return this.f.getAdCount()}getWrapperAdIds(){return[]}getWrapperAdSystems(){return[]}getWrapperCreativeIds(){return[]}};
8
8
  Y.prototype.getWrapperCreativeIds=Y.prototype.getWrapperCreativeIds;Y.prototype.getWrapperAdSystems=Y.prototype.getWrapperAdSystems;Y.prototype.getWrapperAdIds=Y.prototype.getWrapperAdIds;Y.prototype.getSequenceLength=Y.prototype.xb;Y.prototype.getPositionInSequence=Y.prototype.Nb;Y.prototype.getPodTimeOffset=Y.prototype.Mb;Y.prototype.getPodIndex=Y.prototype.getPodIndex;Y.prototype.getPodType=Y.prototype.Va;Y.prototype.getMediaBitrate=Y.prototype.ib;Y.prototype.getMediaHeight=Y.prototype.ub;
9
9
  Y.prototype.getMediaWidth=Y.prototype.vb;Y.prototype.getMediaUrl=Y.prototype.getMediaUrl;Y.prototype.getClickThroughUrl=Y.prototype.Lb;Y.prototype.isBumper=Y.prototype.ec;Y.prototype.getSkipTimeOffset=Y.prototype.getSkipTimeOffset;Y.prototype.getDuration=Y.prototype.getDuration;Y.prototype.getTitle=Y.prototype.getTitle;Y.prototype.getAdvertiserName=Y.prototype.getAdvertiserName;Y.prototype.getAdSystem=Y.prototype.getAdSystem;Y.prototype.getApiFramework=Y.prototype.getApiFramework;
10
- Y.prototype.getCreativeId=Y.prototype.getCreativeId;Y.prototype.getId=Y.prototype.getId;Y.prototype.getTechnology=Y.prototype.yb;Y.prototype.getAdManagerVersion=Y.prototype.sb;Y.prototype.getAdManagerName=Y.prototype.rb;var iO=class{constructor(a){this.a=a}getCuePoints(){return this.a.getTemporalSlots().map(a=>{switch(a.getTimePositionClass()){case tv.freewheel.SDK.TIME_POSITION_CLASS_PREROLL:return 0;case tv.freewheel.SDK.TIME_POSITION_CLASS_POSTROLL:return-1;default:return a.getTimePosition()}})}Ob(){return 0<this.a.getSlotsByTimePositionClass(tv.freewheel.SDK.TIME_POSITION_CLASS_PREROLL).length}jb(){return 0<this.a.getSlotsByTimePositionClass(tv.freewheel.SDK.TIME_POSITION_CLASS_POSTROLL).length}};
11
- iO.prototype.hasPostroll=iO.prototype.jb;iO.prototype.hasPreroll=iO.prototype.Ob;iO.prototype.getCuePoints=iO.prototype.getCuePoints;var jO=class{constructor(a){this.h=new _.R("clpp.freewheel.AdsManager");this.m=a;this.g=new _.br;this.w=new tv.freewheel.SDK.AdManager;this.f=this.a=null;this.B=[];this.o=[];this.A=[];this.l=new _.sm;this.j=null}load(){const a=this;return _.x(function*(){const b=a.m.getConfiguration().freewheel||{};try{$N(b)}catch(d){return a.m.onError(d),a.l.resolve(),a.l}a.w.setNetwork(b.networkId);a.w.setServer(b.serverUrl);a.a=a.w.newContext();a.a.setProfile(b.profileId);typeof b.siteSectionId!==_.tf&&typeof b.siteSectionId!==
12
- _.r||a.a.setSiteSection(b.siteSectionId);const c=yield aO();a.a.setVideoAsset(b.videoAssetId,a.m.getDuration(),void 0,void 0,c);if(Array.isArray(b.pods))for(const d of b.pods)a.a.addTemporalSlot(d.id,ZN(d.type),d.position,d.slotProfile,d.cuepointSequence,d.maxDuration,d.minDuration,d.acceptContentType);b.keyValues&&typeof b.keyValues===_.te&&Object.keys(b.keyValues).forEach(d=>a.a.addKeyValue(d,b.keyValues[d]));a.a.setParameter(tv.freewheel.SDK.PARAMETER_EXTENSION_CONTENT_VIDEO_ENABLED,!1,tv.freewheel.SDK.PARAMETER_LEVEL_GLOBAL);
13
- if(Array.isArray(b.parameters))for(const d of b.parameters)a.a.setParameter(d.name,d.value,d.level);bO(a);a.a.submitRequest();return a.l})}start(){const a=this;return _.x(function*(){yield eO(a)})}resume(){this.f&&this.f.resume()}pause(){this.f&&this.f.pause()}skip(){this.f&&this.f.skipCurrentAd()}getVolume(){return this.a?this.a.getAdVolume():1}setVolume(a){this.a&&this.a.setAdVolume(a)}getPosition(){return this.f?this.f.getPlayheadTime():-1}dispose(){const a=this;return _.x(function*(){a.g.release();
14
- a.j&&(a.j.stop(),a.j=null);dO(a);a.a&&(a.a.dispose(),a.a=null)})}H(a){if(a.success)this.B=this.a.getSlotsByTimePositionClass(tv.freewheel.SDK.TIME_POSITION_CLASS_PREROLL),this.o=this.a.getSlotsByTimePositionClass(tv.freewheel.SDK.TIME_POSITION_CLASS_MIDROLL),this.A=this.a.getSlotsByTimePositionClass(tv.freewheel.SDK.TIME_POSITION_CLASS_POSTROLL),this.m.trigger(new _.F(_.nc,{adsTimeline:new iO(this.a)})),this.j=new _.Us(this.m.getSurface(),(b,c)=>this.a.resize(b,c),this.m.ac(YN).f);else this.m.onError(new _.H(1,
15
- 9,10003,{errorType:0},void 0));this.l.resolve()}J(a){gO(this,_.Wb,a);this.j.start()}I(a){this.f=null;a=a.slot;gO(this,_.Xb);this.j.stop();if(a)switch(a.getTimePositionClass()){case tv.freewheel.SDK.TIME_POSITION_CLASS_PREROLL:eO(this);break;case tv.freewheel.SDK.TIME_POSITION_CLASS_MIDROLL:dO(this);this.m.play();break;case tv.freewheel.SDK.TIME_POSITION_CLASS_POSTROLL:fO(this)}}G(a){const b=a.subType;this.h.debug("ad event",b);switch(b){case tv.freewheel.SDK.EVENT_AD_IMPRESSION:gO(this,_.jc,a);gO(this,
16
- _.cc,a);break;case tv.freewheel.SDK.EVENT_AD_IMPRESSION_END:gO(this,_.kc,a);break;case tv.freewheel.SDK.EVENT_AD_FIRST_QUARTILE:gO(this,_.bc,a);break;case tv.freewheel.SDK.EVENT_AD_MIDPOINT:gO(this,_.ec,a);break;case tv.freewheel.SDK.EVENT_AD_THIRD_QUARTILE:gO(this,_.lc,a);break;case tv.freewheel.SDK.EVENT_AD_COMPLETE:gO(this,_.ac,a);break;case tv.freewheel.SDK.EVENT_AD_CLICK:gO(this,_.$b,a);break;case tv.freewheel.SDK.EVENT_AD_PAUSE:gO(this,_.fc,a);break;case tv.freewheel.SDK.EVENT_AD_RESUME:gO(this,
17
- _.hc,a);break;case tv.freewheel.SDK.EVENT_AD_SKIPPED:gO(this,_.ic,a);break;case tv.freewheel.SDK.EVENT_AD_BUFFERING_START:gO(this,_.Yb,a);break;case tv.freewheel.SDK.EVENT_AD_BUFFERING_END:gO(this,_.gc,a);break;case tv.freewheel.SDK.EVENT_ERROR:this.m.onError(new _.H(1,9,10003,{errorType:1},{fwCode:a[tv.freewheel.SDK.INFO_KEY_ERROR_CODE],fwInfo:a[tv.freewheel.SDK.INFO_KEY_ERROR_INFO],fwModule:a[tv.freewheel.SDK.INFO_KEY_ERROR_MODULE]}))}}F(){if(!this.f){var a=this.m.getPosition();if(this.f=this.o.find(b=>
18
- .5>Math.abs(a-b.getTimePosition()))||null){const b=this.o.findIndex(c=>c===this.f);this.o.splice(b,1);this.m.pause();cO(this);this.f.play()}}}C(a){if((a=a.detail)&&this.a)switch(a.currentState){case _.nn:this.a.setVideoState(tv.freewheel.SDK.VIDEO_STATE_PLAYING);break;case _.mn:this.a.setVideoState(tv.freewheel.SDK.VIDEO_STATE_PAUSED);break;case _.bn:this.a.setVideoState(tv.freewheel.SDK.VIDEO_STATE_COMPLETED);fO(this);break;case _.kn:case _.jn:this.a.setVideoState(tv.freewheel.SDK.VIDEO_STATE_STOPPED)}}};
19
- jO.prototype.getPosition=jO.prototype.getPosition;jO.prototype.setVolume=jO.prototype.setVolume;jO.prototype.getVolume=jO.prototype.getVolume;jO.prototype.skip=jO.prototype.skip;jO.prototype.pause=jO.prototype.pause;jO.prototype.resume=jO.prototype.resume;jO.prototype.start=jO.prototype.start;var kO=class{constructor(){this.a=new _.R(XN)}name(){return XN}da(a,b){return a.namespace()===_.dd?!1:window.tv&&tv.freewheel&&tv.freewheel.SDK?!(!b||!b.freewheel):(this.a.warn("FreeWheel SDK is not loaded."),!1)}create(a){return new jO(a)}};kO.prototype.create=kO.prototype.create;kO.prototype.isSupported=kO.prototype.da;kO.prototype.name=kO.prototype.name;_.En(new kO);};f.call(g, window);
10
+ Y.prototype.getCreativeId=Y.prototype.getCreativeId;Y.prototype.getId=Y.prototype.getId;Y.prototype.getTechnology=Y.prototype.yb;Y.prototype.getAdManagerVersion=Y.prototype.sb;Y.prototype.getAdManagerName=Y.prototype.rb;var tO=class{constructor(a){this.a=a}getCuePoints(){return this.a.getTemporalSlots().map(a=>{switch(a.getTimePositionClass()){case tv.freewheel.SDK.TIME_POSITION_CLASS_PREROLL:return 0;case tv.freewheel.SDK.TIME_POSITION_CLASS_POSTROLL:return-1;default:return a.getTimePosition()}})}Ob(){return 0<this.a.getSlotsByTimePositionClass(tv.freewheel.SDK.TIME_POSITION_CLASS_PREROLL).length}jb(){return 0<this.a.getSlotsByTimePositionClass(tv.freewheel.SDK.TIME_POSITION_CLASS_POSTROLL).length}};
11
+ tO.prototype.hasPostroll=tO.prototype.jb;tO.prototype.hasPreroll=tO.prototype.Ob;tO.prototype.getCuePoints=tO.prototype.getCuePoints;var uO=class{constructor(a){this.h=new _.R("clpp.freewheel.AdsManager");this.m=a;this.g=new _.hr;this.w=new tv.freewheel.SDK.AdManager;this.f=this.a=null;this.B=[];this.o=[];this.A=[];this.l=new _.vm;this.j=null}load(){const a=this;return _.x(function*(){const b=a.m.getConfiguration().freewheel||{};try{kO(b)}catch(d){return a.m.onError(d),a.l.resolve(),a.l}a.w.setNetwork(b.networkId);a.w.setServer(b.serverUrl);a.a=a.w.newContext();a.a.setProfile(b.profileId);typeof b.siteSectionId!==_.uf&&typeof b.siteSectionId!==
12
+ _.r||a.a.setSiteSection(b.siteSectionId);const c=yield lO();a.a.setVideoAsset(b.videoAssetId,a.m.getDuration(),void 0,void 0,c);if(Array.isArray(b.pods))for(const d of b.pods)a.a.addTemporalSlot(d.id,jO(d.type),d.position,d.slotProfile,d.cuepointSequence,d.maxDuration,d.minDuration,d.acceptContentType);b.keyValues&&typeof b.keyValues===_.ue&&Object.keys(b.keyValues).forEach(d=>a.a.addKeyValue(d,b.keyValues[d]));a.a.setParameter(tv.freewheel.SDK.PARAMETER_EXTENSION_CONTENT_VIDEO_ENABLED,!1,tv.freewheel.SDK.PARAMETER_LEVEL_GLOBAL);
13
+ if(Array.isArray(b.parameters))for(const d of b.parameters)a.a.setParameter(d.name,d.value,d.level);mO(a);a.a.submitRequest();return a.l})}start(){const a=this;return _.x(function*(){yield pO(a)})}resume(){this.f&&this.f.resume()}pause(){this.f&&this.f.pause()}skip(){this.f&&this.f.skipCurrentAd()}getVolume(){return this.a?this.a.getAdVolume():1}setVolume(a){this.a&&this.a.setAdVolume(a)}getPosition(){return this.f?this.f.getPlayheadTime():-1}dispose(){const a=this;return _.x(function*(){a.g.release();
14
+ a.j&&(a.j.stop(),a.j=null);oO(a);a.a&&(a.a.dispose(),a.a=null)})}H(a){if(a.success)this.B=this.a.getSlotsByTimePositionClass(tv.freewheel.SDK.TIME_POSITION_CLASS_PREROLL),this.o=this.a.getSlotsByTimePositionClass(tv.freewheel.SDK.TIME_POSITION_CLASS_MIDROLL),this.A=this.a.getSlotsByTimePositionClass(tv.freewheel.SDK.TIME_POSITION_CLASS_POSTROLL),this.m.trigger(new _.F(_.nc,{adsTimeline:new tO(this.a)})),this.j=new _.$s(this.m.getSurface(),(b,c)=>this.a.resize(b,c),this.m.ac(iO).f);else this.m.onError(new _.H(1,
15
+ 9,10003,{errorType:0},void 0));this.l.resolve()}J(a){rO(this,_.Wb,a);this.j.start()}I(a){this.f=null;a=a.slot;rO(this,_.Xb);this.j.stop();if(a)switch(a.getTimePositionClass()){case tv.freewheel.SDK.TIME_POSITION_CLASS_PREROLL:pO(this);break;case tv.freewheel.SDK.TIME_POSITION_CLASS_MIDROLL:oO(this);this.m.play();break;case tv.freewheel.SDK.TIME_POSITION_CLASS_POSTROLL:qO(this)}}G(a){const b=a.subType;this.h.debug("ad event",b);switch(b){case tv.freewheel.SDK.EVENT_AD_IMPRESSION:rO(this,_.jc,a);rO(this,
16
+ _.cc,a);break;case tv.freewheel.SDK.EVENT_AD_IMPRESSION_END:rO(this,_.kc,a);break;case tv.freewheel.SDK.EVENT_AD_FIRST_QUARTILE:rO(this,_.bc,a);break;case tv.freewheel.SDK.EVENT_AD_MIDPOINT:rO(this,_.ec,a);break;case tv.freewheel.SDK.EVENT_AD_THIRD_QUARTILE:rO(this,_.lc,a);break;case tv.freewheel.SDK.EVENT_AD_COMPLETE:rO(this,_.ac,a);break;case tv.freewheel.SDK.EVENT_AD_CLICK:rO(this,_.$b,a);break;case tv.freewheel.SDK.EVENT_AD_PAUSE:rO(this,_.fc,a);break;case tv.freewheel.SDK.EVENT_AD_RESUME:rO(this,
17
+ _.hc,a);break;case tv.freewheel.SDK.EVENT_AD_SKIPPED:rO(this,_.ic,a);break;case tv.freewheel.SDK.EVENT_AD_BUFFERING_START:rO(this,_.Yb,a);break;case tv.freewheel.SDK.EVENT_AD_BUFFERING_END:rO(this,_.gc,a);break;case tv.freewheel.SDK.EVENT_ERROR:this.m.onError(new _.H(1,9,10003,{errorType:1},{fwCode:a[tv.freewheel.SDK.INFO_KEY_ERROR_CODE],fwInfo:a[tv.freewheel.SDK.INFO_KEY_ERROR_INFO],fwModule:a[tv.freewheel.SDK.INFO_KEY_ERROR_MODULE]}))}}F(){if(!this.f){var a=this.m.getPosition();if(this.f=this.o.find(b=>
18
+ .5>Math.abs(a-b.getTimePosition()))||null){const b=this.o.findIndex(c=>c===this.f);this.o.splice(b,1);this.m.pause();nO(this);this.f.play()}}}C(a){if((a=a.detail)&&this.a)switch(a.currentState){case _.qn:this.a.setVideoState(tv.freewheel.SDK.VIDEO_STATE_PLAYING);break;case _.pn:this.a.setVideoState(tv.freewheel.SDK.VIDEO_STATE_PAUSED);break;case _.en:this.a.setVideoState(tv.freewheel.SDK.VIDEO_STATE_COMPLETED);qO(this);break;case _.nn:case _.mn:this.a.setVideoState(tv.freewheel.SDK.VIDEO_STATE_STOPPED)}}};
19
+ uO.prototype.getPosition=uO.prototype.getPosition;uO.prototype.setVolume=uO.prototype.setVolume;uO.prototype.getVolume=uO.prototype.getVolume;uO.prototype.skip=uO.prototype.skip;uO.prototype.pause=uO.prototype.pause;uO.prototype.resume=uO.prototype.resume;uO.prototype.start=uO.prototype.start;var vO=class{constructor(){this.a=new _.R(hO)}name(){return hO}da(a,b){return a.namespace()===_.dd?!1:window.tv&&tv.freewheel&&tv.freewheel.SDK?!(!b||!b.freewheel):(this.a.warn("FreeWheel SDK is not loaded."),!1)}create(a){return new uO(a)}};vO.prototype.create=vO.prototype.create;vO.prototype.isSupported=vO.prototype.da;vO.prototype.name=vO.prototype.name;_.Hn(new vO);};f.call(g, window);
package/cl.hls.js CHANGED
@@ -1,69 +1,69 @@
1
- import {clpp} from "./cl.core.js";import './cl.mse.js';let g={};const _ = clpp._;var f=function(window){'use strict';var vD="CLOSED-CAPTIONS",wD="Could not parse MP4 segment start time.",xD="DURATION",yD="EXT-X-STREAM-INF",zD="Failed to infer discontinuity number",AD="Guessing audio-only",BD="METHOD",CD="SAMPLE-AES-CTR",DD="SUBTITLES",ED="Two EXT-X-KEY tags, one with METHOD\x3dAES-128 are applied to one ",FD="application/vnd.apple.mpegurl",GD="sample",HD="whole-segment",ID=function(a,b){return _.I(a,b,void 0,{required:!0})},JD=function(a){if(1>a.a)throw _.Nk();--a.a},KD=function(a){if(null!==a&&void 0!==
2
- a)return Number(a)},LD=function(a,b){return a.filter(c=>c.name===b)},MD=function(a,b){const c=Array.isArray(b)?b:[b];return a.filter(d=>{d=ID(d,_.Eb);return c.includes(d)})},ND=function(a,b){return a.some(c=>c.name===b)},OD=function(a,b,c){c=void 0===c?{}:c;a=a.find(d=>d.name===b)||null;if(!a&&c.required)throw new _.H(_.G,4,4024,{missingTag:b});return a},PD=function(a){var b=OD(a,"EXT-X-TILES");if(!b)return{Ze:1,Cf:1,durationPerTile:null};a=_.I(b,"LAYOUT")||"1x1";b=(b=_.I(b,xD))?Number(b):null;const [c,
3
- d]=a.split("x").map(e=>parseInt(e,10));return{Ze:c,Cf:d,durationPerTile:b}},QD=function(a,b){return _.Vx([a],[b])[0]},RD=function(a){const b=new Set;a.variants.forEach(c=>{c.audio&&b.add(c.audio);c.video&&b.add(c.video)});a.textStreams.forEach(c=>b.add(c));a.thumbStreams.forEach(c=>b.add(c));return Array.from(b)},SD=function(a,b){Array.isArray(a)||(a=[a]);a.forEach(c=>{for(const d of RD(c))b(d,c)})},TD=function(a){return a.some(b=>ND(b.X,_.Ca))},UD=function(a){return a.type===_.p||a.type===_.w},VD=
4
- function(a){const b=OD(a,_.Ha);if(OD(a,_.Ca))return _.ox;if(!b)return"LIVE";if(b.value===_.ox)return _.ox;if("EVENT"===b.value)return"EVENT";throw new _.H(_.G,4,4044,`Invalid EXT-X-PLAYLIST-TYPE value: ${b.value}`);},WD=function(a){a={AUDIO:_.p,VIDEO:_.w,SUBTITLES:_.t,"CLOSED-CAPTIONS":_.t}[a.toUpperCase()];if(!a)throw new _.H(_.G,4,4044,"EXT-X-MEDIA tag has an invalid TYPE attribute.");return a},XD=function(a,b,c){c=void 0===c?!1:c;var d=0;let e=null;if(a){d=a.split("@");a=Number(d[0]);if(0>=a)throw new _.H(_.G,
5
- 4,4044,"Byte range length must be positive.");if(d[1]){if(d=Number(d[1]),0>d)throw new _.H(_.G,4,4044,"Byte range start byte must not be negative.");}else{if(c)throw new _.H(_.G,4,4044,"Invalid byte range, offset is required but missing.");if(null==b)throw new _.H(_.G,4,4044,"Invalid byte range, cannot calculate offset based on previous byte ranges.");d=b+1}e=d+a-1}return{ta:d,ha:e}},YD=function(a,b){a=OD(a,_.ya);return XD(a?a.value:null,b)},ZD=function(a){a=OD(a,"EXTINF",{required:!0}).value.split(",");
6
- return{duration:Number(a[0]),title:a[1]||null}},$D=function(a,b){b=void 0===b?{}:b;const c={gd:!1,Vf:!1,Wf:null,tg:null,mf:null};a=OD(a,_.Ka,{required:b.sf});if(!a)return c;const d=e=>null==e?null:Number(e);c.gd="YES"===_.I(a,"CAN-BLOCK-RELOAD");c.Vf="YES"===_.I(a,"CAN-SKIP-DATERANGES");c.Wf=d(_.I(a,"CAN-SKIP-UNTIL"));c.tg=d(_.I(a,"HOLD-BACK"));c.mf=d(_.I(a,"PART-HOLD-BACK",void 0,{required:b.sf}));return c},aE=function(a,b,c){c=void 0===c?!1:c;a=_.I(a,"BYTERANGE");return XD(a,b,c)},cE=function(a,
7
- b){const c=YD(a.X,null);return new bE(0,0,0,()=>[a.a],c.ta,c.ha,0,b)},dE=function(a,b){if(null==a)return null;a=Object.assign({},a);null==a.iv&&(a.iv=_.ii(new Uint8Array(12),new Uint8Array([b>>24&255,b>>16&255,b>>8&255,b&255])));return a},eE=function(a){let b=Infinity,c=Infinity;RD(a).filter(UD).forEach(d=>{{d=d.S;var e=d[0].startTime;const f=d[d.length-1].endTime;d=e;e=f-e}b=Math.min(b,d);c=Math.min(c,e)});return{Bc:b,duration:c}},fE=function(a){return a.map(b=>{({duration:b}=eE(b));return b}).reduce((b,
8
- c)=>b+c,0)},gE=function(a){return(a.video?a.video.xa:"")+" - "+(a.audio?a.audio.xa:"")},hE=function(a,b,c){if(b===_.ox)return{delay:0,bd:0};b=OD(a,_.Ga);if(c&&b)return c=Number(ID(b,"PART-TARGET")),{mf:a}=$D(a,{sf:!0}),{delay:a,bd:c};a=OD(a,_.Ma,{required:!0});a=Number(a.value);return{delay:3*a,bd:a}},iE=function(a){const b=[];SD(a,c=>{b.push(c.zg)});return{delay:Math.max(...b.map(c=>c.delay)),bd:Math.min(...b.map(c=>c.bd))}},kE=function(a){const b=new Map;a.forEach(c=>{var d=jE(c).groupId;b.has(d)?
9
- (d=b.get(d),d.includes(c)||d.push(c)):b.set(d,[c])});return b},lE=function(a){const b=new Map;for(const c of a){a=_.I(c,_.Za);a=_.Ch(a||_.Df);const d=ID(c,_.Sa),e=ID(c,"INSTREAM-ID");b.has(d)||b.set(d,new Map);b.get(d).set(e,a)}return b},nE=function(a){a=a.audio.concat(a.video);for(const b of a)a=jE(b).codecs.split(",").filter(c=>"mp4a.40.34"!==c),mE(b,a)},oE=function(a,b){if(!a)return null;const c=a.xa;return b.find(d=>jE(d).xa===c)||null},pE=function(a){for(const b of a)if(b.startsWith("#EXT-")&&
10
- (a=_.ni(0,b),_.Br.has(a.name)))return 1;return 0},qE=function(a){a=LD(a,"EXT-X-DEFINE").map(b=>{const c=_.I(b,"NAME");if(!c)return null;b=ID(b,"VALUE");return{name:c,value:b}}).filter(Boolean);return new Map(a.map(b=>[b.name,b.value]))},rE=function(a,b){return a.replace(/\{\$([a-zA-Z0-9_-]+)\}/g,(c,d)=>{c=b.get(d);if(null==c)throw new _.H(_.G,4,4044,`Undefined variable '${d}'`);return c})},sE=function(a,b){a.forEach(c=>{c.attributes.forEach(d=>{d.value=rE(d.value,b)})})},tE=function(a,b,c){sE(a,c);
11
- b.forEach(d=>{sE(d.X,c)})},wE=function(a,b,c){const d=[];for(let e=1;e<b.length;e++){const f=uE(a,b[e]);d.push(f);if(f.name===yD){const g=b[e+1];if(!g)throw new _.H(_.G,4,4044,"EXT-X-STREAM-INF is not followed by a URI.");f.attributes.push(new _.li(_.Gb,g));e++}}a.a=qE(d);tE(d,[],a.a);return new vE(c,0,d)},zE=function(a,b,c){let d=[];for(var e=1;e<b.length;){const f=uE(a,b[e]);if(_.Cr.has(f.name))break;d.push(f);e++}b=xE(a,c,b.slice(e));e=b.S;d=d.concat(b.X);a=yE(a,d);tE(d,e,a);return new vE(c,1,
12
- d,b.S)},AE=function(a,b,c){b=b.trim().split(/\n+/m).map(d=>d.trim()).filter(d=>d.length&&!/^#(?!EXT)/m.test(d));if(!/^#EXTM3U($|[ \t\n])/m.test(b[0]))throw new _.H(_.G,4,4015);return 0===pE(b)?wE(a,b,c):zE(a,b,c)},uE=function(a,b){return _.ni(a.f++,b)},xE=function(a,b,c){const d=[],e=[];let f=[],g=[];c.forEach(h=>{/^(#EXT)/.test(h)?(h=uE(a,h),_.Br.has(h.name)||_.Er.has(h.name)?d.push(h):_.Dr.has(h.name)?"EXT-X-PART"===h.name?g.push(h):h.name===_.Ia&&"PART"===_.I(h,_.Eb)&&g.push(h):f.push(h)):/^#(?!EXT)/m.test(h)||
13
- (h=QD(b,h.trim()),e.push(new BE(h,f,g)),f=[],g=[])});0<g.length&&e.push(new BE(null,f,g));return{S:e,X:d}},yE=function(a,b){const c=LD(b,"EXT-X-DEFINE"),d=qE(b);c.map(e=>_.I(e,"IMPORT")).filter(Boolean).forEach(e=>{const f=a.a.get(e);if(null==f)throw new _.H(_.G,4,4044,`Cannot import variable '${e}' as it is not defined `+"in the master playlist");d.set(e,f)});return d},CE=function(a){return 0>a?[]:Array.from({length:a},(b,c)=>c)},DE=function(a,b=0){return b+10<=a.length&&73===a[b]&&68===a[b+1]&&
14
- 51===a[b+2]&&255>a[b+3]&&255>a[b+4]&&128>a[b+6]&&128>a[b+7]&&128>a[b+8]&&128>a[b+9]?!0:!1},EE=function(a){function b(h,k,l){let m="";for(;k<l;k++)m+="%"+("00"+h[k].toString(16)).slice(-2);return m}function c(h){return h[0]<<21|h[1]<<14|h[2]<<7|h[3]}function d(){throw new _.H(_.G,4,4030);}DE(a)||d();let e=10;a[5]&64&&(e=e+4+c(a.subarray(10,14)));do{var f=c(a.subarray(e+4,e+8));1>f&&d();var g=String.fromCharCode(a[e],a[e+1],a[e+2],a[e+3]);if("PRIV"===g){g=a.subarray(e+10,e+f+10);for(let h=0;h<g.byteLength;h++)if(0===
15
- g[h]){if("com.apple.streaming.transportStreamTimestamp"===unescape(b(g,0,h)))return a=g.subarray(h+1),f=(a[3]&1)<<30|a[4]<<22|a[5]<<14|a[6]<<6|a[7]>>>2,f*=4,f+=a[7]&3,Math.round(f/9E4);break}}DE(a,e)||d();e+=10;e+=f}while(e<a.byteLength);return d()},FE=function(a,b){let c=null,d=0;try{(new _.dl).L(_.oe,_.Wk).L(_.Bf,_.Wk).L(_.je,_.Wk).$("mdhd",g=>{g.reader.skip(0==g.version?8:16);d=_.P(g.reader);g.parser.stop()}).parse(b,!0)}catch(g){c=g}if(c||!d)throw _.Xs.error("Unable to find timescale in init segment!"),
16
- new _.H(_.G,4,4030,wD,c);let e=0,f=!1;try{(new _.dl).L("moof",_.Wk).L("traf",_.Wk).$("tfdt",g=>{var h=d;if(0===g.version)h=_.P(g.reader)/h;else{{const k=_.P(g.reader),l=_.P(g.reader);if(!(2097151>=k||h>=Math.pow(2,12)))throw Error("Cannot accurately parse MP4 timestamp, base time is too high and timescale is \x3c\x3d 2^12");h=k/h*Math.pow(2,32)+l/h}}e=h;f=!0;g.parser.stop()}).parse(a,!0)}catch(g){c=g}if(c||!f)throw new _.H(_.G,4,4030,wD,c);return e},GE=function(a){for(;a.getPosition()<a.Ca()-1;){const b=
17
- a.getPosition();if(71===_.Ok(a))return JD(a),b}return-1},HE=function(a){function b(){d.seek(e+188);f=_.Ok(d);71!=f&&(d.seek(e+192),f=_.Ok(d));71!=f&&(d.seek(e+204),f=_.Ok(d));71!=f&&c();JD(d)}function c(){throw new _.H(_.G,4,4030);}const d=new _.Ql(new DataView(a),!1);let e=0,f=0;e=GE(d);0>e&&(_.Xs.error("Unable to find sync byte in TS after scanning."),c());for(;;){e=d.getPosition();f=_.Ok(d);71!=f&&c();a=_.Pk(d);if(8191===(a&8191)){b();continue}if(!(a&16384)){b();continue}a=(_.Ok(d)&48)>>4;0!=a&&
18
- 2!=a||c();3==a&&(a=_.Ok(d),d.skip(a));if(1!=_.P(d)>>8){b();continue}d.skip(3);a=_.Ok(d)>>6;0!=a&&1!=a||c();0==_.Ok(d)&&c();a=_.Ok(d);const g=_.Pk(d),h=_.Pk(d);return(1073741824*((a&14)>>1)+((g&65534)<<14|(h&65534)>>1))/9E4}},KE=function(a){const b=IE(a),c=JE(a);a.forEach(d=>{const e=d.S,f=e.findIndex(h=>h.ea===b);let g=e.findIndex(h=>h.ea===c+1);-1===g&&(g=e.length);d.S=e.slice(f,g)})},JE=function(a){a=a.map(b=>b.S[b.S.length-1].ea);return Math.min(...a)},IE=function(a){a=a.map(b=>b.S[0].ea);return Math.max(...a)},
19
- NE=function(a){var b=ID(a,BD);if(!LE.includes(b))return ME.error("PlayReady in HLS is only supported with [",LE.join(", "),"], not",b),null;a=ID(a,_.Gb);b=_.Mq(a);a=null;b=_.J(b.data);try{a=_.Lx(_.Xl(b))}catch(c){a=b}return _.Wx(_.pd,[{initDataType:_.Sc,initData:a}],"")},PE=function(a){if(0===a.length)return OE();if(a.some(c=>c.type===HD)||a.every(c=>c.type===_.se))return a[0];a=a.filter(c=>c.type===GD);const b=_.gh(a.flatMap(c=>c.drmInfos));return{keyInfo:null,keyId:a[a.length-1].keyId,type:GD,drmInfos:b}},
20
- SE=function(a){a=QE(a);if(a.some(b=>RE(b))&&1<a.length)throw new _.H(_.G,4,4046,"Two EXT-X-KEY tags, one with METHOD\x3dAES-128 are applied to one playlist.");},RE=function(a){return LD(a.X,_.Da).some(b=>"AES-128"===_.I(b,BD))},UE=function(a,b,c){return QE(a).map(d=>TE(d.X,b,c))},VE=function(a){return a.filter(b=>ND(b.X,_.Da)).length},QE=function(a){return a.filter(b=>ND(b.X,_.Da))},TE=function(a,b,c){a=LD(a,_.Da);if(0===a.length)return null;var d=ID(a[0],BD);if(1===a.length){if("NONE"===d)return OE();
21
- if("AES-128"===d)return a=a[0],d=_.I(a,"IV",""),{type:HD,keyInfo:{method:"AES-128",url:QD(b,ID(a,_.Gb)),iv:d?_.fi((d||"0x").slice(2)):null},drmInfos:[],keyId:null}}b=a.map(e=>ID(e,BD));if(!b.every(e=>"SAMPLE-AES"===e)&&!b.every(e=>e===CD))throw WE.warn(`EXT-X-KEY methods ${b.join(", ")} are incompatible.`),new _.H(_.G,4,4044,"Multiple EXT-X-KEY tags with incompatible METHOD values.");b=a.map(e=>{const f=_.I(e,"KEYFORMAT","identity");{const g=XE[f]||null;e=g?g(e,c):null}e||WE.warn("Unsupported HLS KEYFORMAT",
22
- f);return e}).filter(Boolean);if(0===b.length)throw new _.H(_.G,4,4026);return{keyInfo:null,keyId:b.map(e=>e.keyIds).reduce((e,f)=>e.concat(f),[]).reverse()[0]||null,type:GD,drmInfos:b}},OE=function(){return{type:_.se,keyInfo:null,drmInfos:[],keyId:null}},YE=function(a,b,c){return _.x(function*(){const d=b.f(),e=_.yy(b.Ka(),b.ta,b.ta+2048-1,a.a.attemptParameters);e.type=2;const f=_.yy(b.Ka(),b.ta,b.ha,a.a.attemptParameters);f.type=2;d&&(f.keyInfo=d);try{return yield a.f(c?f:e)}catch(g){if(7001===
23
- g.code||c)throw g;a.h.warn("Unable to fetch a partial HLS segment! Falling back to a full segment request, which is expensive! Your server should support Range requests and CORS pre-flights.",e.uris[0]);try{return yield a.f(f)}catch(h){throw a.h.error("Failed to fetch media segment to parse its start timestamp.",f.uris[0],h),new _.H(_.G,4,4030,"Failed to fetch the media segment.");}}})},ZE=function(a,b,c,d,e,f){return _.x(function*(){a.h.debug("Fetching segment to find start time");if("audio/mpeg"===
24
- d||d===_.Fc||d===_.Ec)return 0;if(d===_.Dc){var g=yield YE(a,c,f);const h=_.J(g.data);return DE(h)?EE(h):HE(g.data)}if(d===_.Of||d===_.Gc)return g=[YE(a,c,f)],b&&g.push(YE(a,b,!0)),g=yield Promise.all(g),FE(g[0].data,(g[1]||g[0]).data);if(d===_.Nf)return g=yield YE(a,c,f),HE(g.data);if(!_.ey(`${d.split("/")[0]||""}/mp4;codecs="${e}"`))return 0;throw new _.H(_.G,4,4030);})},$E=function(a,b){a=a.map(c=>c.streams[b]);return a.some(c=>null==c)?null:a},mE=function(a,b){a.streams.forEach(c=>{c.codecs=b.join(",")})},
25
- aF=function(a,b){a=a.streams.find(c=>{c=c.S;return c[0].position<=b&&b<=c[c.length-1].position});return null==a?null:a.S.find(c=>c.position===b)||null},jE=function(a){return a.streams[0]},bF=function(a,b){a.streams.forEach(c=>{c.Fd=b})},cF=function(a,b){a.streams.forEach(c=>{c.width=b})},dF=function(a,b){a.streams.forEach(c=>{c.height=b})},eF=function(a,b){a.streams.forEach(c=>{c.frameRate=b})},fF=function(a,b){a.streams.forEach(c=>{c.bandwidth=b})},gF=function(a,b){a=a.map(c=>c.a[b]);return a.some(c=>
26
- null==c)?null:a},hF=function(a,b){const c=new Set(a.map(d=>d.ea));return b.filter(d=>!c.has(d.ea))},kF=function(a,b){for(;a[0].ea<b[0].ea;)a.splice(0,1);var c=a[0];let d=b[0];iF(c,d)||jF(c,d);const e=a.length-1;c=a[e];d=b[e];0<e&&!iF(c,d)&&jF(c,d);for(c=e+1;c<b.length;)a.push(b[c]),c++},lF=function(a,b){const c=a[a.length-1];var d=b.findIndex(f=>f.ea===c.ea);const e=b[d];iF(c,e)||jF(c,e);for(d+=1;d<b.length;d++)a.push(b[d])},qF=function(a,b,c,d){var e=a[0].length();e=CE(e).map(f=>{var g=gF(a,f)||
27
- [];const h=$E(b,f)||[];{f=$E(c,f)||[];const k=[...mF(g),...h,...f].filter(Boolean);nF(k);const {ea:l,duration:m}=k[0];g={variants:g,textStreams:h,thumbStreams:f,startTime:0,id:`P${l}`,endTime:m,duration:m,ea:l}}return g});d&&oF(e[0]);pF(e);return e},mF=function(a){a=new Set(a.flatMap(b=>[b.video,b.audio]).filter(Boolean));return Array.from(a)},oF=function(a){const b=mF(a.variants)[0].S[0].wa;a.startTime+=b;a.endTime+=b},pF=function(a){for(let b=0;b<a.length;b++){const c=a[b],d=a[b-1];c.startTime=
28
- d?d.endTime:c.startTime;c.endTime=c.startTime+c.duration}},iF=function(a,b){return a.startTime===b.startTime&&a.endTime===b.endTime},jF=function(a,b){a.startTime=b.startTime;a.endTime=b.endTime;a.duration=b.duration;rF(a.variants,b.variants);sF(RD(a),RD(b))},rF=function(a,b){const c=new Map(a.map(d=>[gE(d),d]));b.forEach(d=>{c.get(gE(d)).drmInfos=d.drmInfos})},sF=function(a,b){const c=new Map(a.map(d=>[d.xa,d]));b.forEach(d=>{const e=c.get(d.xa);e.S=d.S;e.segmentIndex.replace(d.S);e.Bc=d.Bc;e.be=
29
- d.be;e.duration=d.duration;e.Re=d.Re;e.encrypted=d.encrypted;e.drmInfos=d.drmInfos;e.keyId=d.keyId})},nF=function(a){const b=tF(a);a.forEach(c=>{_.uy(c.segmentIndex,b);c.duration=b;c.be=c.Bc+b})},tF=function(a){let b=Infinity;a.filter(UD).forEach(c=>{b=Math.min(b,c.duration)});return b},uF=function(a,b){SD(b,(c,d)=>{_.By(a,c.S,d.startTime)})},vF=function(a){return null===a.g?[]:[a.g.audio,a.g.video].filter(b=>b).map(b=>b.xa)},wF=function(a,b){return _.x(function*(){var c=_.si([b],a.a.attemptParameters);
30
- c.type=1;c=yield a.C(c);let d="";try{d=_.Ph(c.data)}catch(e){throw new _.H(_.G,4,4042);}d=d.replace(/\r\n|\r(?=[^\n]|$)/gm,"\n");d=d.trim();return{text:d,response:c}})},AF=function(a,b){return _.x(function*(){var c=xF(a,b,a.o,"");if(1===c.type){c=_.xr(c.S[0].a)||"";c=null!=_.wr.video[c]?_.w:null!=_.wr.audio[c]?_.p:null;var d="";c===_.w?d="avc1.42E01E":c===_.p&&(d="mp4a.40.2");{c=a.J;var e=a.o;d=a.a.hlsDefaultCodecs||d;var f=[];const q=[];q.push(new _.li(_.la,"0"));q.push(new _.li(_.Gb,e));d.length&&
31
- q.push(new _.li(_.na,d));f.push(new _.mi(c.f++,yD,q));c=new vE(e,0,f)}}d=c.X;c=LD(d,"EXT-X-MEDIA");e=LD(d,yD);d=LD(d,"EXT-X-IMAGE-STREAM-INF");c={Ac:{Qf:MD(c,["AUDIO",_.Mb]),closedCaptions:MD(c,vD),$g:MD(c,DD)},cd:e,Vd:d};const {periods:g,nf:h,Af:k}=yield yF(a,c);if(!a.D)throw new _.H(_.G,7,7001);c=iE(g[0]);e=!0;d=null;f=0;zF(a)||(e=!1,d=0,f=c.delay);d=f=new _.lD(d,f,!0);d.j=e;d.l=e;uF(f,g);h&&(f.H={offsetDateTime:h-_.Gy(f,0),seekRangeStartDateTime:h});e=f;if(!zF(a)){a.G=c.bd;c=0;for(var l of a.f.values())c=
32
- Math.max(c,l.streams[0].Bc);for(l=0;95443.7176888889<=c;)l+=95443.7176888889,c-=95443.7176888889;if(l){a.h.debug("Offsetting live streams by",l,"to compensate for rollover");for(var m of a.f.values())c=m.streams[0],95443.7176888889>c.Bc?(a.h.debug("Offset applied to",c.type),c.segmentIndex.offset(l)):a.h.debug("Offset NOT applied to",c.type)}}m=fE(g);"LIVE"===a.l||"EVENT"===a.l?(m=Math.max(m,e.F),isNaN(a.a.availabilityWindowOverride)||(m=a.a.availabilityWindowOverride),e.w=m):a.l===_.ox&&(e.f=m);
33
- if(k)for(var n of k)a.D.onTimelineCueAdded({schemeIdUri:n.schemeIdUri,Pa:n.Pa,value:"",startTime:n.startTime,endTime:n.endTime,id:n.id,type:_.Ug,eventElement:null});n={presentationTimeline:e,adaptedPeriods:[...g],periods:g,offlineSessionIds:[],minBufferTime:0};a.h.debug("HLS playlist parsed",n);return n})},CF=function(a,b){return Promise.all(b.map(c=>BF(a,c)))},EF=function(a,b){b.forEach(c=>{a:{var d=a.f.get(c.a),e=!zF(a),f=OD(c.X,_.Ba);if(f)var g=Number(f.value);else{d?(f=d.streams[d.streams.length-
34
- 1].S,f=f[f.length-1].ea):f=0;if(e&&0<f)try{{const k=OD(c.X,_.Fa);if(!k)throw DF.error("Failed to infer discontinuity number, because EXT-X-MEDIA-SEQUENCE tag is missing."),Error(zD);const l=Number(k.value),m=aF(d,l);if(!m)throw DF.error("Failed to infer discontinuity number, could not find the appropriate segment in the previous playlist"+` (segment position = ${l})`),Error(zD);var h=m.ea}g=h;break a}catch(k){throw new _.H(_.G,4,4024,"EXT-X-DISCONTINUITY-SEQUENCE tag is required for discontinuous HLS live streams.");
35
- }g=0}}c=c.S||[];for(const k of c)ND(k.X,_.Aa)&&g++,k.ea=g});KE(b)},HF=function(a,b){return _.x(function*(){const {textStreams:c,thumbStreams:d,Rf:e}=yield FF(a,b);var f=a.w.periods[0].variants;a.a.hlsLowLatency&&null!==a.g&&(f=f.filter(g=>g.id===a.g.id));f=f.map(g=>{const h=oE(g.audio,e),k=oE(g.video,e);g=GF(a,h,k,g.bandwidth);if(!g)throw new _.H(_.G,4,4047,{message:"Video and audio are encrypted in an incompatible way.",Dh:k?jE(k).xa:void 0,audio:h?jE(h).xa:void 0});return g});return qF(f,c,d,!0)})},
36
- JF=function(a,b,c){IF(a,_.ox);b.j=!0;b.l=!0;b.f=c[c.length-1].endTime},IF=function(a,b){a.l=b;zF(a)&&a.j.stop()},xF=function(a,b,c,d){a=AE(a.J,b,c);a.a=d;KF(a);return a},yF=function(a,b){return _.x(function*(){var c=lE(b.Ac.closedCaptions),d=LF(a,b.cd),e=yield MF(a,b);const f=Object.values(e).flat().map(h=>h.Ea);EF(a,f);var g=yield NF(a,e.Ie,d);c=yield OF(a,e.cd,g,c);d=yield PF(a,e.Zg,d);g=yield QF(a,e.Vd);e=RF(a,e);c=qF(c,d,g,!zF(a));a.D.filterAllPeriods(c);return zF(a)?(d=null,e&&(d=SF(f,e)),{periods:c,
37
- nf:null,Af:d}):{periods:c,nf:e,Af:null}})},FF=function(a,b){return _.x(function*(){const c=g=>jE(g.stream).type===_.w||jE(g.stream).type===_.p;var d=b.filter(c),e=b.filter(g=>!c(g)),f=g=>{g=g.map(h=>{var k=jE(h.stream);k={language:k.language,channelsCount:k.channelsCount,spatialAudio:k.spatialAudio,closedCaptions:k.closedCaptions,primary:k.primary,kind:k.kind||null,groupId:k.groupId,type:k.type,codecs:k.codecs,name:k.originalId,uri:k.xa,Dd:{width:k.width,height:k.height,frameRate:k.frameRate}};h=
38
- Object.assign({},{Ea:h.Ea},k);return TF(a,h)});return Promise.all(g)};d=yield f(d);f=yield f(e);UF(a,d.concat(f));e=f.filter(g=>jE(g).type===_.Gx);f=f.filter(g=>jE(g).type===_.Sd);return{textStreams:e,thumbStreams:f,Rf:d}})},GF=function(a,b,c,d){const e=[],f=(c||b).length();for(let m=0;m<f;m++){var g=b?b.streams[m]||null:null,h=c?c.streams[m]||null:null,k=g,l=h;k=k&&l?_.cy(k.drmInfos,l.drmInfos)?_.by(k.drmInfos,l.drmInfos):null:k?k.drmInfos:l?l.drmInfos:null;if(!k)return null;l=d;g={id:a.H++,language:g?
39
- g.language:_.Df,primary:!!g&&g.primary||!!h&&h.primary,audio:g,video:h,bandwidth:l,drmInfos:k,allowedByApplication:!0,allowedByKeySystem:!0};e.push(g)}return new VF(e)},TF=function(a,b){return _.x(function*(){const c=b.Ea,d=b.codecs,e=b.type,f=b.Rc,g=b.groupId,h=b.primary;var k=b.kind;const l=b.name,m=b.channelsCount,n=b.spatialAudio,q=b.closedCaptions,u=b.Dd,v=_.Ch(f||_.Df);if(1!==c.type)throw new _.H(_.G,4,4017);var y=VD(c.X);IF(a,y);const A=hE(c.X,y,a.a.hlsLowLatency||!1);y=yield WF(a,c,e,d);const D=
40
- a.a.hlsLowLatency?_.kB:_.wx;let E=k;e!==_.t||k||(E=_.Gx);const {gd:O}=$D(c.X);k=y.map(tb=>{const Nb=tb.S,Yc=tb.bg,Pf=tb.mimeType;tb=tb.ea;const Va=Nb[0].startTime,Xd=Nb[Nb.length-1].endTime,tc=Xd-Va,ea=new _.mD(Nb),bb=Nb[0].initSegment||null;return{id:a.H++,originalId:l,createSegmentIndex:Promise.resolve.bind(Promise),findSegmentPosition:ea.f.bind(ea),getSegmentReference:ea.get.bind(ea),adjustSegmentDurations:ea.g.bind(ea),getDuration:ea.getDuration.bind(ea),segmentIndex:ea,segmentLookupStrategy:D,
41
- initSegmentReference:bb,mimeType:Pf,codecs:d,kind:E,Re:Yc.type,encrypted:Yc.type===GD,keyId:Yc.keyId,language:v,originalLanguage:f||_.Df,label:l,type:e,primary:h,trickModeVideo:null,emsgSchemeIdUris:null,frameRate:u?u.frameRate:void 0,width:u?u.width:void 0,height:u?u.height:void 0,bandwidth:void 0,roles:[],channelsCount:m,spatialAudio:n,closedCaptions:q,keyInfo:Yc.keyInfo,S:Nb,drmInfos:Yc.drmInfos,ea:tb,xa:c.a,Fd:c.f,Bc:Va,be:Xd,duration:tc,gd:O,groupId:g,zg:A}});return new XF(k)})},UF=function(a,
42
- b){b.forEach(c=>{a.f.a.set(jE(c).xa,c)})},LF=function(a,b){const c=new Map;for(const f of b){var d=_.I(f,"AUDIO");b=_.I(f,_.Mb);var e=_.I(f,DD);const g=YF(a,f);if(e){const h=_.$i(_.t,g);c.set(e,h);e=g.indexOf(h);-1<e&&g.splice(e,1)}d&&(e=ZF(_.p,g),c.set(d,e));b&&(d=ZF(_.w,g),c.set(b,d))}return c},MF=function(a,b){return _.x(function*(){const c=yield Promise.all([$F(a,b.Ac.Qf),$F(a,b.Ac.$g),$F(a,b.cd),$F(a,b.Vd)]),[d,e,f,g]=c;return{Ie:d,Zg:e,cd:f,Vd:g}})},NF=function(a,b,c){return _.x(function*(){if(0===
43
- b.length)return new Map;var d=[aG(a,b[0],c)];yield d[0];d=d.concat(b.slice(1).map(e=>aG(a,e,c)));d=yield Promise.all(d);return kE(d)})},OF=function(a,b,c,d){return _.x(function*(){const e=new Set;var f=[...b];let g=0;var h=Infinity;for(let k=0;k<f.length;++k){const l=Number(ID(f[k].tag,_.la));l<h&&(h=l,g=k)}h=f.splice(g,1).pop();h=yield bG(a,h,c,d,e);f=f.map(k=>bG(a,k,c,d,e));f=yield Promise.all(f);f.splice(g,0,h);return f.reduce(_.Tx,[])})},PF=function(a,b,c){return Promise.all(b.map(d=>aG(a,d,c)))},
44
- QF=function(a,b){return Promise.all(b.map(c=>cG(a,c)))},RF=function(a,b){b=[...b.cd,...b.Ie].map(d=>d.Ea).flatMap(d=>d.S[0].X);b=OD(b,_.Ja);if(!b)return null;const c=(new Date(b.value)).getTime();return isNaN(c)?(a.h.warn("Failed to parse EXT-X-PROGRAM-DATE-TIME tag "+`value (value: ${b.value}).`),null):c/1E3},zF=function(a){return a.l===_.ox},SF=function(a,b){return(a=a.find(c=>null!==OD(c.X,_.za)))?a.X.filter(c=>c.name===_.za).map(c=>{a:{var d=_.I(c,"ID"),e=_.I(c,"START-DATE");if(null===d||null===
45
- e)_.Ar.warn("Invalid EXT-X-DATERANGE missing mandatory ID or START-DATE attribute, ignoring the EXT-X-DATERANGE tag.",c),c=null;else{var f=new Date(e);e=f.getTime()/1E3-b;d={id:d,startTime:e,startDate:f};var g=KD(_.I(c,xD));void 0!==g&&0<=g&&(d.duration=g);var h=KD(_.I(c,"PLANNED-DURATION"));void 0!==h&&0<=h&&(d.plannedDuration=h);var k=_.I(c,"CLASS");null!==k&&(d.schemeIdUri=k);var l=_.I(c,"END-DATE");l=l?new Date(l):null;null!==l&&l.getTime()>=f.getTime()&&(d.endDate=l);{const q=c.attributes;if(null==
46
- q)var m=null;else{f={};for(m of q)m.name.startsWith("X-")&&(f[m.name]=m.value);m=_.vg(f)?f:null}}m=m||{};if(k===_.od){f=c.attributes;if(null==f)var n=null;else{k={};for(n of f)switch(n.name){case _.Tb:k[_.Tb]=n.value;break;case _.Sb:k[_.Sb]=n.value;break;case _.Vb:k[_.Vb]=KD(n.value);break;case _.Ub:k[_.Ub]=KD(n.value);break;case "X-SNAP":k["X-SNAP"]=n.value.split(",");break;case "X-RESTRICT":k["X-SNAP"]=n.value.split(",")}k[_.Tb]&&k[_.Sb]||!k[_.Tb]&&!k[_.Sb]?(_.Ar.warn("Invalid EXT-X-DATERANGE Interstitial attributes X-ASSET-URI, X-ASSET-LIST"),
47
- n=null):n=_.vg(k)?k:null}if(null===n){_.Ar.warn("Invalid interstitial attributes, ignoring the EXT-X-DATERANGE tag.",c);c=null;break a}m=Object.assign(m,n)}_.vg(m)&&(d.Pa=m);d.endTime=l?l.getTime()/1E3:g?e+g:h?e+h:e;d.type="hls-daterange";c=d}}return c}).filter(Boolean):null},$F=function(a,b){return _.x(function*(){return(yield Promise.all(b.map(c=>_.x(function*(){const d=yield dG(a,c);return d?{tag:c,Ea:d}:null})))).filter(Boolean)})},BF=function(a,b){return _.x(function*(){var c=new _.qh(jE(b).Fd);
48
- if(a.a.hlsLowLatency&&jE(b).gd){var d=b.streams[b.streams.length-1].segmentIndex;if(d=d.a[d.a.length-1]){var e=d.a,f=e.length-1;d={Cg:d.position,Ig:e&&0<e.length?f:null}}else d=null;if(e=d)d=e.Cg,e=e.Ig,f=_.Mi(c.a.toString()),f._HLS_msn=d.toString(),null===e&&f._HLS_part&&delete f._HLS_part,null!==e&&(f._HLS_part=e.toString()),d=_.Li(f,!0),d=new _.xh(d),_.th(c,d)}const {response:g,text:h}=yield wF(a,c.toString());c=jE(b).xa;d=jE(b).Fd;e=g.uri;d!==e&&(d=e,bF(b,d));c=xF(a,h,d,c);return{stream:b,Ea:c}})},
49
- YF=function(a,b){var c=_.I(b,_.na,a.a.hlsDefaultCodecs||"avc1.42E01E,mp4a.40.2").split(/\s*,\s*/);b=new Set;const d=[];for(const e of c)c=_.ky(e)[0],b.has(c)?a.h.debug("Ignoring duplicate codec"):(d.push(e),b.add(c));return d},ZF=function(a,b){if(1===b.length)return b[0];a=_.$i(a,b);if(null!=a)return a;throw new _.H(_.G,4,4025,{codecList:b});},aG=function(a,b,c){return _.x(function*(){const d=b.tag,e=b.Ea;return eG(a,e.a,()=>_.x(function*(){const f=ID(d,_.Sa),g=WD(ID(d,_.Eb));var h=ID(d,_.Eb).toUpperCase();
50
- if(WD(h)!==_.t)h=null;else{var k=d.getAttribute("FORCED");k=!(!k||!k.value||"YES"!==k.value.toUpperCase());var l=_.Gx;h===vD&&(l=_.tx);k&&(l="forced");h=l}k=c.get(f)||"";l=_.I(d,_.Za);const m=_.I(d,"NAME"),n=d.getAttribute("DEFAULT"),q=d.getAttribute("AUTOSELECT");var u=_.I(d,"CHANNELS");u=g===_.p?u?parseInt(u.split("/")[0],10):null:null;var v=g===_.p?(v=_.I(d,"CHANNELS"))?v.includes("/JOC"):!1:!1;return yield TF(a,{Ea:e,codecs:k,type:g,Rc:l,primary:!!n&&!!q,name:m,channelsCount:u,spatialAudio:v,
51
- groupId:f,kind:h,closedCaptions:null,Dd:null})}))})},cG=function(a,b){return _.x(function*(){const c=b.tag,d=b.Ea;return eG(a,d.a,()=>_.x(function*(){var e=_.I(c,_.na)||"jpg",f=_.I(c,_.Za);const g=_.I(c,"NAME");e=yield TF(a,{Ea:d,codecs:e,type:_.Sd,Rc:f,name:g,primary:!1,kind:null,channelsCount:null,spatialAudio:!1,closedCaptions:null,groupId:null,Dd:null});(f=_.I(c,_.la))&&fF(e,Number(f));return e}))})},bG=function(a,b,c,d,e){return _.x(function*(){var f=b.tag,g=Number(ID(f,_.la));if(null!=f.getAttribute("FRAME-RATE")||
52
- null!=f.getAttribute(_.ub)){var h=_.I(f,"FRAME-RATE");f=_.I(f,_.ub);var [k,l]=f?f.split("x"):[null,null];h={frameRate:KD(h),width:KD(k),height:KD(l)}}else h=null;if(f=yield fG(a,b,h,c,d)){h=f.video;f=f.audio;var m=0<f.length?f:[null];h=0<h.length?h:[null];f=[];for(const n of m)for(const q of h){m=(q?jE(q).xa:"")+" - "+(n?jE(n).xa:"");if(e.has(m)){a.h.debug("Skipping variant which only differs in text streams.");continue}const u=GF(a,n,q,g);null==u?a.h.warn("Incompatible DRM info in HLS variant. Skipping."):
53
- (f.push(u),e.add(m))}g=f}else g=[];return g})},fG=function(a,b,c,d,e){return _.x(function*(){var f=b.tag,g=b.Ea;let h=YF(a,f);var k=_.I(f,"AUDIO"),l=_.I(f,_.Mb),m=k||l;m=m&&d.has(m)?d.get(m):[];k={audio:k?m:[],video:l?m:[]};a.h.debug("Guessing stream type for",f.toString());f=!1;const n=g.a;g=k.audio.find(q=>q.xa===n);l=_.$i(_.w,h);l=c||l;1!==h.length||l?!m.length&&1<h.length?(a.h.debug("Guessing multiplexed audio+video"),g=_.w,h=[h.join(",")]):k.audio.length&&g?(a.h.debug(AD),g=_.p,f=!0):k.video.length?
54
- (a.h.debug(AD),g=_.p):(a.h.debug("Guessing video-only"),g=_.w):(g=_.p,a.h.debug(AD));l=null;f||(l=yield gG(a,b,h,g,e,c));if(null==l)return null;k[g]=[l];g===_.p&&c&&m.forEach(q=>{cF(q,c.width);dF(q,c.height);eF(q,c.frameRate)});nE(k);return k})},gG=function(a,b,c,d,e,f){return _.x(function*(){const g=b.tag,h=b.Ea;return eG(a,h.a,()=>_.x(function*(){var k=_.I(g,vD);let l=null;d===_.w&&k&&"NONE"!==k&&(l=e.get(k));k=ZF(d,c);return yield TF(a,{Ea:h,codecs:k,type:d,closedCaptions:l,primary:!1,kind:null,
55
- Rc:null,name:null,channelsCount:null,spatialAudio:!1,groupId:null,Dd:f})}))})},eG=function(a,b,c){if(a.f.has(b))return a=a.f.get(b),Promise.resolve(a);if(a.f.f.has(b))return a.f.f.get(b)||null;c=c();a.f.set(b,c);return c},WF=function(a,b,c,d){return _.x(function*(){var e=b.a,f=b.S;var g=void 0===g?0:g;var h=(h=OD(b.X,_.Fa))?Number(h.value):g;g=[];!zF(a)&&SE(f);e=yield hG(a,b.f,e,f,h,c,d);if(0===f.length)f=[];else{var k=[],l=[];for(var m of f)ND(m.X,_.Aa)&&0<l.length&&(k.push(l),l=[]),l.push(m);k.push(l);
56
- f=k}for(m=0;m<f.length;m++)k=f[m],l=yield iG(a,b.f,k,h,e,c,d,g[g.length-1]||null,f.length),g.push(l),h+=k.length;jG(g);return g})},dG=function(a,b){return _.x(function*(){var c="EXT-X-MEDIA"!==b.name?!0:_.I(b,_.Eb)===DD;c=_.I(b,_.Gb,void 0,{required:c});if(!c)return null;const d=QD(a.o,c),{response:e,text:f}=yield wF(a,d);return xF(a,f,e.uri,c)})},KF=function(a){1===a.type&&a.S.forEach((b,c)=>{if(ND(b.X,_.Ea)&&!ND(b.X,_.Aa)&&0<c)throw new _.H(_.G,4,4046,"Media playlist contains an EXT-X-MAP tag not accompanied by an EXT-X-DISCONTINUITY tag.");
57
- })},jG=function(a){if(1<(new Set(a.map(b=>b.mimeType))).size)throw new _.H(_.G,4,4045,"Media playlist contains discontinuities with different MIME types. This is valid, but not yet supported.");},kG=function(a){a=a.map(b=>b.a?b.a:b.f.map(c=>_.I(c,_.Gb))||null).map(b=>_.xr(b));if(1<(new Set(a)).size)throw new _.H(_.G,4,4044,"Unexpected change in file format.");},lG=function(a,b,c){a=LD(a.X,_.Ea);if(1<a.length)throw new _.H(_.G,4,4020);a=a[0];if(!a)return null;const d=ID(a,_.Gb),e=QD(b,d);b=aE(a,null,
58
- !0);return new _.iD(()=>[e],b.ta,b.ha,c)},mG=function(a,b,c,d,e,f,g){const h=[];for(const q of _.$x(b.f)){b=q.af;const u=q.item;{var k=0===b,l=k?a:h[h.length-1],m=k?d:l.endTime,n=Number(_.I(u,xD));n=m+n;k=aE(u,k?null:l.ha,k);l=_.I(u,_.Gb);const v=(l=QD(g,l))?[l]:[];m=new bE(c,m,n,()=>v,k.ta,k.ha,e,f,!1,null,null,null,null);if("YES"===_.I(u,"INDEPENDENT")||0===b)m.g=!0;h.push(m)}}return h},nG=function(a,b,c,d,e,f,g,h,k,l,m){const n=c.X;var q=c.a;const u=null!=q,v=q?[q]:[];if(!u&&!a.a.hlsLowLatency)return null;
59
- a=0;q={ta:0,ha:null};let y=null;u?({duration:c}=ZD(n),a=e+c,q=YD(n,b?b.ha:null)):(b=mG(b,c,d,e,f,g,k),a=b[b.length-1].endTime,y=b);h=h===_.Sd?PD(n):null;d=new bE(d,e,a,()=>v,q.ta,q.ha,f,g,!1,null,h?h.Ze:null,h?h.Cf:null,h?h.durationPerTile:null,y);d.ea=l;d.initSegment=m||void 0;return d},hG=function(a,b,c,d,e,f,g){return _.x(function*(){var h=d[0];if(null!=a.B)return a.B;if(!zF(a)&&a.w)try{var k=a.f.get(c);var l=k?aF(k,e)||null:null;if(!l)throw new _.H(_.G,4,4030,"Segment not found in pervious playlist update.");
60
- var m=l.startTime+l.wa;a.h.debug(`Setting playlist start time to ${m}.`);return a.B=m}catch(n){if(h=a.f.get(c))m=h.streams[h.streams.length-1].S,m=m[m.length-1],a.h.warn(`Last #EXT-X-MEDIA-SEQUENCE values ${h.streams[0].S[0].position} - ${m.position}`+`, new values ${e} - ${e+d.length-1}.`,b,h);throw new _.H(_.G,4,4047,{message:"The updated playlist does not share any segments with the previous one.",uri:c});}m=yield oG(a,f,g,h);k=TE(h.X,a.o,m)||OE();l=lG(h,b,k.keyInfo);k=dE(k.keyInfo,e);h=yield pG(a,
61
- l,h,k,m,g);a.h.debug(`Setting playlist start time to ${h}.`);return a.B=h})},iG=function(a,b,c,d,e,f,g,h,k){return _.x(function*(){var l=c[0],m=null==h;kG(c);const n=yield oG(a,f,g,l);var q=a.o,u=h?h.yg:null;var v=1===k;if(c.slice(1).some(RE))throw new _.H(_.G,4,4046,v?"Media playlist contains an EXT-X-KEY tag with METHOD\x3dAES-128 which is not at the beginning of the playlist.":"Media playlist contains an EXT-X-KEY tag with METHOD\x3dAES-128 which is not marked by an EXT-X-DISCONTINUITY tag and is not at the beginning of the playlist.");
62
- if(ND(c[0].X,_.Da)||null===u)if((u=TE(c[0].X,q,n))&&u.type===HD){if(1<VE(c))throw new _.H(_.G,4,4046,ED+`${v?"playlist":"discontinuity"}.`);v=[u]}else v=UE(c,q,n),v=0===v.length?[OE()]:v;else if(q=UE(c,q,n),u.type===_.se||u.type===GD)v=[u,...q];else{if(0<VE(c))throw new _.H(_.G,4,4046,ED+`${v?"playlist":"discontinuity"}.`);v=[u]}q=v;v=q[q.length-1];q=PE(q);u=lG(l,b,q.keyInfo)||(h?h.ug:null);var y=dE(q.keyInfo,d);const A=l.ea;l=m?e:yield qG(a,A,u,l,d,y,n,g);m=[];for(y=0;y<c.length;y++){var D=c[y];
63
- const E=m[m.length-1]||null,O=0===y?0:E.endTime,tb=d+y,Nb=dE(q.keyInfo,tb);(D=nG(a,E,D,tb,O,l,Nb,f,b,A,u))&&m.push(D)}return{S:m,bg:q,yg:v,mimeType:n,endTime:m[m.length-1].endTime,ea:A,ug:u}})},oG=function(a,b,c,d){return _.x(function*(){const e=d.a;var f=OD(d.X,_.Ea);f=f?ID(f,_.Gb):null;return rG(a,b,c,e,f)})},pG=function(a,b,c,d,e,f){return _.x(function*(){if(null==c.a)return 0;const g=cE(c,d);return ZE(a.K,b,g,e,f,null!=d)})},qG=function(a,b,c,d,e,f,g,h){return _.x(function*(){if(a.F.has(b))return a.F.get(b);
64
- const k=yield pG(a,c,d,f,g,h);a.h.debug(`Segment #${e} has raw media timestamp `+`${k} s.`);a.F.set(b,k);return k})},rG=function(a,b,c,d,e){return _.x(function*(){const f=[d,e].filter(Boolean);var g=_.cj(f,b,c);if(g)return g;g=_.si([d],a.a.attemptParameters);g.method="HEAD";g.type=2;g=(yield a.C(g)).headers["content-type"];if(!g)throw new _.H(_.G,4,4021,"Unknown MIME type of: "+f.join(", "));return g.split(";")[0]})},vE=class{constructor(a,b,c,d){if(1===b){if(!d||0===d.length)throw new _.H(_.G,4,
65
- 4043,"Media playlist must have at least one segment!");if(null==d[0].a)throw new _.H(_.G,4,4043,"Media playlist must have at least one full segment!");}this.f=a;this.a="";this.type=b;this.X=c;this.S=1===b?d:null}},BE=class{constructor(a,b,c){c=void 0===c?[]:c;this.X=b;this.a=a;this.f=c;this.ea=-1}},bE=class extends _.Ly{constructor(a,b,c,d,e,f,g,h,k,l,m,n,q,u){u=void 0===u?[]:u;super(a,b,c,d,e,f,g,void 0===h?null:h,void 0===k?!1:k,void 0===l?null:l,void 0===m?null:m,void 0===n?null:n,void 0===q?null:
66
- q,u);this.initSegment=void 0;this.ea=0}},sG=class{constructor(){this.f=0;this.a=new Map}},tG=class{constructor(){this.a=new Map;this.f=new Map}set(a,b){this.f.set(a,b);return b.then(c=>this.a.set(a,c)).catch(()=>{}).then(()=>this.f.delete(a))}has(a){return this.a.has(a)}get(a){return this.a.get(a)||null}values(){return Array.from(this.a.values())}clear(){this.f.clear();this.a.clear()}},DF=new _.R("clpp.hls.DiscontinuityUtils");var XE={"com.apple.streamingkeydelivery":function(a,b){if(b===_.Nf)throw new _.H(_.G,4,4041);if(ID(a,BD)===CD)throw new _.H(_.G,4,4044,"EXT-X-KEY:METHOD SAMPLE-AES-CTR is not supported in FairPlay.");return _.Wx(_.nd,[{initDataType:_.nf,initData:new Uint8Array(0)}],"")},"com.microsoft.playready":NE,"urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95":NE,"urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed":function(a){var b=ID(a,BD);if(!LE.includes(b))return ME.error("Widevine in HLS is only supported with [",
67
- LE.join(", "),"], not",b),null;b=ID(a,_.Gb);b=_.Mq(b);b=_.J(b.data);b=_.Wx(_.sd,[{initDataType:_.Sc,initData:b}],"");if(a=_.I(a,"KEYID"))b.keyIds=[a.substr(2).toLowerCase()];return b}},LE=["SAMPLE-AES",CD],ME=new _.R("clpp.hls.DrmParser");var WE=new _.R("clpp.hls.EncryptionUtils");var uG=class{constructor(a){this.h=new _.R("clpp.hls.MediaReader");this.f=a;this.a={attemptParameters:_.pi()}}};var XF=class{constructor(a){this.streams=a}length(){return this.streams.length}};var VF=class{constructor(a){this.a=a}length(){return this.a.length}};var vG=class{constructor(){this.a=this.D=null;this.H=1;this.f=new tG;this.o="";this.J=new sG;this.G=0;this.g=null;this.j=new _.kj(()=>{this.Bb()});this.l=_.ox;this.w=null;this.A=new _.Fr;this.B=null;this.h=new _.R("clpp.hls.HlsParser");this.F=new Map;this.K=new uG(this.C.bind(this));this.I=!1}configure(a){this.a=a;this.K.a=a}setCurrentVariant(a){this.g=a}start(a,b){const c=this;return _.x(function*(){if(c.I)throw Error("start() may be called only once!");c.I=!0;c.D=b;const {response:d,text:e}=yield wF(c,
68
- a);c.o=d.uri;const f=yield AF(c,e);c.w=f;const g=c.G;0<g&&c.j.ca(g);return f})}stop(){this.j&&(this.j.stop(),this.j=null);const a=[];this.A&&(a.push(this.A.destroy()),this.A=null);this.f.clear();this.w=this.a=this.D=this.g=null;return Promise.all(a)}onExpirationUpdated(){}update(){const a=this;return _.x(function*(){const b=a.w;if(!zF(a)&&b){var c=b.presentationTimeline;"LIVE"===a.l&&(a.B=null);var d=Array.from(a.f.values());if(a.a.hlsLowLatency&&null!==a.g){const f=vF(a);d=d.filter(g=>f.includes(jE(g).xa))}var e=
69
- yield CF(a,d);d=e.map(f=>f.Ea);EF(a,d);e=yield HF(a,e);hF(b.periods,e).forEach(f=>{a.D.filterNewPeriod(f)});kF(b.periods,e);lF(b.adaptedPeriods,e);uF(c,e);TD(d)&&JF(a,c,e)}})}Bb(){const a=this;return _.x(function*(){a.h.debug(_.nx);if(a.D)try{yield a.update(),a.j.ca(a.G)}catch(b){if(!(b instanceof _.H))throw b;a.D&&(a.D.onError(b),1===b.severity&&a.j.ca(.1))}})}C(a){if(!this.A)throw new _.H(_.G,7,7001);a=this.D.networkingEngine.fetch(a);_.zi(this.A,a);return a.P}};_.z("clpp.hls.HlsComponent",class extends _.Ds{f(){_.pq.m3u8=vG;_.nq[_.fk]=vG;_.nq[FD]=vG}a(){_.Sy("m3u8");_.Ty(_.fk);_.Ty(FD)}id(){return"hls"}});};f.call(g, window);
1
+ import {clpp} from "./cl.core.js";import './cl.mse.js';let g={};const _ = clpp._;var f=function(window){'use strict';var GD="CLOSED-CAPTIONS",HD="Could not parse MP4 segment start time.",ID="DURATION",JD="EXT-X-STREAM-INF",KD="Failed to infer discontinuity number",LD="Guessing audio-only",MD="METHOD",ND="SAMPLE-AES-CTR",OD="SUBTITLES",PD="Two EXT-X-KEY tags, one with METHOD\x3dAES-128 are applied to one ",QD="application/vnd.apple.mpegurl",RD="sample",SD="whole-segment",TD=function(a,b){return _.I(a,b,void 0,{required:!0})},UD=function(a){if(1>a.a)throw _.Ok();--a.a},VD=function(a){if(null!==a&&void 0!==
2
+ a)return Number(a)},WD=function(a,b){return a.filter(c=>c.name===b)},XD=function(a,b){const c=Array.isArray(b)?b:[b];return a.filter(d=>{d=TD(d,_.Eb);return c.includes(d)})},YD=function(a,b){return a.some(c=>c.name===b)},ZD=function(a,b,c){c=void 0===c?{}:c;a=a.find(d=>d.name===b)||null;if(!a&&c.required)throw new _.H(_.G,4,4024,{missingTag:b});return a},$D=function(a){var b=ZD(a,"EXT-X-TILES");if(!b)return{Ze:1,Bf:1,durationPerTile:null};a=_.I(b,"LAYOUT")||"1x1";b=(b=_.I(b,ID))?Number(b):null;const [c,
3
+ d]=a.split("x").map(e=>parseInt(e,10));return{Ze:c,Bf:d,durationPerTile:b}},aE=function(a,b){return _.by([a],[b])[0]},bE=function(a){const b=new Set;a.variants.forEach(c=>{c.audio&&b.add(c.audio);c.video&&b.add(c.video)});a.textStreams.forEach(c=>b.add(c));a.thumbStreams.forEach(c=>b.add(c));return Array.from(b)},cE=function(a,b){Array.isArray(a)||(a=[a]);a.forEach(c=>{for(const d of bE(c))b(d,c)})},dE=function(a){return a.some(b=>YD(b.X,_.Ca))},eE=function(a){return a.type===_.p||a.type===_.w},fE=
4
+ function(a){const b=ZD(a,_.Ha);if(ZD(a,_.Ca))return _.vx;if(!b)return"LIVE";if(b.value===_.vx)return _.vx;if("EVENT"===b.value)return"EVENT";throw new _.H(_.G,4,4044,`Invalid EXT-X-PLAYLIST-TYPE value: ${b.value}`);},gE=function(a){a={AUDIO:_.p,VIDEO:_.w,SUBTITLES:_.u,"CLOSED-CAPTIONS":_.u}[a.toUpperCase()];if(!a)throw new _.H(_.G,4,4044,"EXT-X-MEDIA tag has an invalid TYPE attribute.");return a},hE=function(a,b,c){c=void 0===c?!1:c;var d=0;let e=null;if(a){d=a.split("@");a=Number(d[0]);if(0>=a)throw new _.H(_.G,
5
+ 4,4044,"Byte range length must be positive.");if(d[1]){if(d=Number(d[1]),0>d)throw new _.H(_.G,4,4044,"Byte range start byte must not be negative.");}else{if(c)throw new _.H(_.G,4,4044,"Invalid byte range, offset is required but missing.");if(null==b)throw new _.H(_.G,4,4044,"Invalid byte range, cannot calculate offset based on previous byte ranges.");d=b+1}e=d+a-1}return{ta:d,ha:e}},iE=function(a,b){a=ZD(a,_.ya);return hE(a?a.value:null,b)},jE=function(a){a=ZD(a,"EXTINF",{required:!0}).value.split(",");
6
+ return{duration:Number(a[0]),title:a[1]||null}},kE=function(a,b){b=void 0===b?{}:b;const c={gd:!1,Uf:!1,Vf:null,sg:null,mf:null};a=ZD(a,_.Ka,{required:b.sf});if(!a)return c;const d=e=>null==e?null:Number(e);c.gd="YES"===_.I(a,"CAN-BLOCK-RELOAD");c.Uf="YES"===_.I(a,"CAN-SKIP-DATERANGES");c.Vf=d(_.I(a,"CAN-SKIP-UNTIL"));c.sg=d(_.I(a,"HOLD-BACK"));c.mf=d(_.I(a,"PART-HOLD-BACK",void 0,{required:b.sf}));return c},lE=function(a,b,c){c=void 0===c?!1:c;a=_.I(a,"BYTERANGE");return hE(a,b,c)},nE=function(a,
7
+ b){const c=iE(a.X,null);return new mE(0,0,0,()=>[a.a],c.ta,c.ha,0,b)},oE=function(a,b){if(null==a)return null;a=Object.assign({},a);null==a.iv&&(a.iv=_.ji(new Uint8Array(12),new Uint8Array([b>>24&255,b>>16&255,b>>8&255,b&255])));return a},pE=function(a){let b=Infinity,c=Infinity;bE(a).filter(eE).forEach(d=>{{d=d.S;var e=d[0].startTime;const f=d[d.length-1].endTime;d=e;e=f-e}b=Math.min(b,d);c=Math.min(c,e)});return{Bc:b,duration:c}},qE=function(a){return a.map(b=>{({duration:b}=pE(b));return b}).reduce((b,
8
+ c)=>b+c,0)},rE=function(a){return(a.video?a.video.xa:"")+" - "+(a.audio?a.audio.xa:"")},sE=function(a,b,c){if(b===_.vx)return{delay:0,bd:0};b=ZD(a,_.Ga);if(c&&b)return c=Number(TD(b,"PART-TARGET")),{mf:a}=kE(a,{sf:!0}),{delay:a,bd:c};a=ZD(a,_.Ma,{required:!0});a=Number(a.value);return{delay:3*a,bd:a}},tE=function(a){const b=[];cE(a,c=>{b.push(c.yg)});return{delay:Math.max(...b.map(c=>c.delay)),bd:Math.min(...b.map(c=>c.bd))}},vE=function(a){const b=new Map;a.forEach(c=>{var d=uE(c).groupId;b.has(d)?
9
+ (d=b.get(d),d.includes(c)||d.push(c)):b.set(d,[c])});return b},wE=function(a){const b=new Map;for(const c of a){a=_.I(c,_.Za);a=_.Dh(a||_.Ef);const d=TD(c,_.Sa),e=TD(c,"INSTREAM-ID");b.has(d)||b.set(d,new Map);b.get(d).set(e,a)}return b},yE=function(a){a=a.audio.concat(a.video);for(const b of a)a=uE(b).codecs.split(",").filter(c=>"mp4a.40.34"!==c),xE(b,a)},zE=function(a,b){if(!a)return null;const c=a.xa;return b.find(d=>uE(d).xa===c)||null},AE=function(a){for(const b of a)if(b.startsWith("#EXT-")&&
10
+ (a=_.oi(0,b),_.Hr.has(a.name)))return 1;return 0},BE=function(a){a=WD(a,"EXT-X-DEFINE").map(b=>{const c=_.I(b,"NAME");if(!c)return null;b=TD(b,"VALUE");return{name:c,value:b}}).filter(Boolean);return new Map(a.map(b=>[b.name,b.value]))},CE=function(a,b){return a.replace(/\{\$([a-zA-Z0-9_-]+)\}/g,(c,d)=>{c=b.get(d);if(null==c)throw new _.H(_.G,4,4044,`Undefined variable '${d}'`);return c})},DE=function(a,b){a.forEach(c=>{c.attributes.forEach(d=>{d.value=CE(d.value,b)})})},EE=function(a,b,c){DE(a,c);
11
+ b.forEach(d=>{DE(d.X,c)})},HE=function(a,b,c){const d=[];for(let e=1;e<b.length;e++){const f=FE(a,b[e]);d.push(f);if(f.name===JD){const g=b[e+1];if(!g)throw new _.H(_.G,4,4044,"EXT-X-STREAM-INF is not followed by a URI.");f.attributes.push(new _.mi(_.Gb,g));e++}}a.a=BE(d);EE(d,[],a.a);return new GE(c,0,d)},KE=function(a,b,c){let d=[];for(var e=1;e<b.length;){const f=FE(a,b[e]);if(_.Ir.has(f.name))break;d.push(f);e++}b=IE(a,c,b.slice(e));e=b.S;d=d.concat(b.X);a=JE(a,d);EE(d,e,a);return new GE(c,1,
12
+ d,b.S)},LE=function(a,b,c){b=b.trim().split(/\n+/m).map(d=>d.trim()).filter(d=>d.length&&!/^#(?!EXT)/m.test(d));if(!/^#EXTM3U($|[ \t\n])/m.test(b[0]))throw new _.H(_.G,4,4015);return 0===AE(b)?HE(a,b,c):KE(a,b,c)},FE=function(a,b){return _.oi(a.f++,b)},IE=function(a,b,c){const d=[],e=[];let f=[],g=[];c.forEach(h=>{/^(#EXT)/.test(h)?(h=FE(a,h),_.Hr.has(h.name)||_.Kr.has(h.name)?d.push(h):_.Jr.has(h.name)?"EXT-X-PART"===h.name?g.push(h):h.name===_.Ia&&"PART"===_.I(h,_.Eb)&&g.push(h):f.push(h)):/^#(?!EXT)/m.test(h)||
13
+ (h=aE(b,h.trim()),e.push(new ME(h,f,g)),f=[],g=[])});0<g.length&&e.push(new ME(null,f,g));return{S:e,X:d}},JE=function(a,b){const c=WD(b,"EXT-X-DEFINE"),d=BE(b);c.map(e=>_.I(e,"IMPORT")).filter(Boolean).forEach(e=>{const f=a.a.get(e);if(null==f)throw new _.H(_.G,4,4044,`Cannot import variable '${e}' as it is not defined `+"in the master playlist");d.set(e,f)});return d},NE=function(a){return 0>a?[]:Array.from({length:a},(b,c)=>c)},OE=function(a,b=0){return b+10<=a.length&&73===a[b]&&68===a[b+1]&&
14
+ 51===a[b+2]&&255>a[b+3]&&255>a[b+4]&&128>a[b+6]&&128>a[b+7]&&128>a[b+8]&&128>a[b+9]?!0:!1},PE=function(a){function b(h,k,l){let m="";for(;k<l;k++)m+="%"+("00"+h[k].toString(16)).slice(-2);return m}function c(h){return h[0]<<21|h[1]<<14|h[2]<<7|h[3]}function d(){throw new _.H(_.G,4,4030);}OE(a)||d();let e=10;a[5]&64&&(e=e+4+c(a.subarray(10,14)));do{var f=c(a.subarray(e+4,e+8));1>f&&d();var g=String.fromCharCode(a[e],a[e+1],a[e+2],a[e+3]);if("PRIV"===g){g=a.subarray(e+10,e+f+10);for(let h=0;h<g.byteLength;h++)if(0===
15
+ g[h]){if("com.apple.streaming.transportStreamTimestamp"===unescape(b(g,0,h)))return a=g.subarray(h+1),f=(a[3]&1)<<30|a[4]<<22|a[5]<<14|a[6]<<6|a[7]>>>2,f*=4,f+=a[7]&3,Math.round(f/9E4);break}}OE(a,e)||d();e+=10;e+=f}while(e<a.byteLength);return d()},QE=function(a,b){let c=null,d=0;try{(new _.el).L(_.pe,_.Xk).L(_.Cf,_.Xk).L(_.ke,_.Xk).$("mdhd",g=>{g.reader.skip(0==g.version?8:16);d=_.P(g.reader);g.parser.stop()}).parse(b,!0)}catch(g){c=g}if(c||!d)throw _.ct.error("Unable to find timescale in init segment!"),
16
+ new _.H(_.G,4,4030,HD,c);let e=0,f=!1;try{(new _.el).L("moof",_.Xk).L("traf",_.Xk).$("tfdt",g=>{var h=d;if(0===g.version)h=_.P(g.reader)/h;else{{const k=_.P(g.reader),l=_.P(g.reader);if(!(2097151>=k||h>=Math.pow(2,12)))throw Error("Cannot accurately parse MP4 timestamp, base time is too high and timescale is \x3c\x3d 2^12");h=k/h*Math.pow(2,32)+l/h}}e=h;f=!0;g.parser.stop()}).parse(a,!0)}catch(g){c=g}if(c||!f)throw new _.H(_.G,4,4030,HD,c);return e},RE=function(a){for(;a.getPosition()<a.Ca()-1;){const b=
17
+ a.getPosition();if(71===_.Pk(a))return UD(a),b}return-1},SE=function(a){function b(){d.seek(e+188);f=_.Pk(d);71!=f&&(d.seek(e+192),f=_.Pk(d));71!=f&&(d.seek(e+204),f=_.Pk(d));71!=f&&c();UD(d)}function c(){throw new _.H(_.G,4,4030);}const d=new _.Rl(new DataView(a),!1);let e=0,f=0;e=RE(d);0>e&&(_.ct.error("Unable to find sync byte in TS after scanning."),c());for(;;){e=d.getPosition();f=_.Pk(d);71!=f&&c();a=_.Qk(d);if(8191===(a&8191)){b();continue}if(!(a&16384)){b();continue}a=(_.Pk(d)&48)>>4;0!=a&&
18
+ 2!=a||c();3==a&&(a=_.Pk(d),d.skip(a));if(1!=_.P(d)>>8){b();continue}d.skip(3);a=_.Pk(d)>>6;0!=a&&1!=a||c();0==_.Pk(d)&&c();a=_.Pk(d);const g=_.Qk(d),h=_.Qk(d);return(1073741824*((a&14)>>1)+((g&65534)<<14|(h&65534)>>1))/9E4}},VE=function(a){const b=TE(a),c=UE(a);a.forEach(d=>{const e=d.S,f=e.findIndex(h=>h.fa===b);let g=e.findIndex(h=>h.fa===c+1);-1===g&&(g=e.length);d.S=e.slice(f,g)})},UE=function(a){a=a.map(b=>b.S[b.S.length-1].fa);return Math.min(...a)},TE=function(a){a=a.map(b=>b.S[0].fa);return Math.max(...a)},
19
+ YE=function(a){var b=TD(a,MD);if(!WE.includes(b))return XE.error("PlayReady in HLS is only supported with [",WE.join(", "),"], not",b),null;a=TD(a,_.Gb);b=_.Uq(a);a=null;b=_.J(b.data);try{a=_.Sx(_.Yl(b))}catch(c){a=b}return _.cy(_.pd,[{initDataType:_.Sc,initData:a}],"")},$E=function(a){if(0===a.length)return ZE();if(a.some(c=>c.type===SD)||a.every(c=>c.type===_.te))return a[0];a=a.filter(c=>c.type===RD);const b=_.hh(a.flatMap(c=>c.drmInfos));return{keyInfo:null,keyId:a[a.length-1].keyId,type:RD,drmInfos:b}},
20
+ cF=function(a){a=aF(a);if(a.some(b=>bF(b))&&1<a.length)throw new _.H(_.G,4,4046,"Two EXT-X-KEY tags, one with METHOD\x3dAES-128 are applied to one playlist.");},bF=function(a){return WD(a.X,_.Da).some(b=>"AES-128"===_.I(b,MD))},eF=function(a,b,c){return aF(a).map(d=>dF(d.X,b,c))},fF=function(a){return a.filter(b=>YD(b.X,_.Da)).length},aF=function(a){return a.filter(b=>YD(b.X,_.Da))},dF=function(a,b,c){a=WD(a,_.Da);if(0===a.length)return null;var d=TD(a[0],MD);if(1===a.length){if("NONE"===d)return ZE();
21
+ if("AES-128"===d)return a=a[0],d=_.I(a,"IV",""),{type:SD,keyInfo:{method:"AES-128",url:aE(b,TD(a,_.Gb)),iv:d?_.gi((d||"0x").slice(2)):null},drmInfos:[],keyId:null}}b=a.map(e=>TD(e,MD));if(!b.every(e=>"SAMPLE-AES"===e)&&!b.every(e=>e===ND))throw gF.warn(`EXT-X-KEY methods ${b.join(", ")} are incompatible.`),new _.H(_.G,4,4044,"Multiple EXT-X-KEY tags with incompatible METHOD values.");b=a.map(e=>{const f=_.I(e,"KEYFORMAT","identity");{const g=hF[f]||null;e=g?g(e,c):null}e||gF.warn("Unsupported HLS KEYFORMAT",
22
+ f);return e}).filter(Boolean);if(0===b.length)throw new _.H(_.G,4,4026);return{keyInfo:null,keyId:b.map(e=>e.keyIds).reduce((e,f)=>e.concat(f),[]).reverse()[0]||null,type:RD,drmInfos:b}},ZE=function(){return{type:_.te,keyInfo:null,drmInfos:[],keyId:null}},iF=function(a,b,c){return _.x(function*(){const d=b.f(),e=_.Fy(b.La(),b.ta,b.ta+2048-1,a.a.attemptParameters);e.type=2;const f=_.Fy(b.La(),b.ta,b.ha,a.a.attemptParameters);f.type=2;d&&(f.keyInfo=d);try{return yield a.f(c?f:e)}catch(g){if(7001===
23
+ g.code||c)throw g;a.h.warn("Unable to fetch a partial HLS segment! Falling back to a full segment request, which is expensive! Your server should support Range requests and CORS pre-flights.",e.uris[0]);try{return yield a.f(f)}catch(h){throw a.h.error("Failed to fetch media segment to parse its start timestamp.",f.uris[0],h),new _.H(_.G,4,4030,"Failed to fetch the media segment.");}}})},jF=function(a,b,c,d,e,f){return _.x(function*(){a.h.debug("Fetching segment to find start time");if("audio/mpeg"===
24
+ d||d===_.Fc||d===_.Ec)return 0;if(d===_.Dc){var g=yield iF(a,c,f);const h=_.J(g.data);return OE(h)?PE(h):SE(g.data)}if(d===_.Pf||d===_.Gc)return g=[iF(a,c,f)],b&&g.push(iF(a,b,!0)),g=yield Promise.all(g),QE(g[0].data,(g[1]||g[0]).data);if(d===_.Of)return g=yield iF(a,c,f),SE(g.data);if(!_.ly(`${d.split("/")[0]||""}/mp4;codecs="${e}"`))return 0;throw new _.H(_.G,4,4030);})},kF=function(a,b){a=a.map(c=>c.streams[b]);return a.some(c=>null==c)?null:a},xE=function(a,b){a.streams.forEach(c=>{c.codecs=b.join(",")})},
25
+ lF=function(a,b){a=a.streams.find(c=>{c=c.S;return c[0].position<=b&&b<=c[c.length-1].position});return null==a?null:a.S.find(c=>c.position===b)||null},uE=function(a){return a.streams[0]},mF=function(a,b){a.streams.forEach(c=>{c.Fd=b})},nF=function(a,b){a.streams.forEach(c=>{c.width=b})},oF=function(a,b){a.streams.forEach(c=>{c.height=b})},pF=function(a,b){a.streams.forEach(c=>{c.frameRate=b})},qF=function(a,b){a.streams.forEach(c=>{c.bandwidth=b})},rF=function(a,b){a=a.map(c=>c.a[b]);return a.some(c=>
26
+ null==c)?null:a},sF=function(a,b){const c=new Set(a.map(d=>d.fa));return b.filter(d=>!c.has(d.fa))},vF=function(a,b){for(;a[0].fa<b[0].fa;)a.splice(0,1);var c=a[0];let d=b[0];tF(c,d)||uF(c,d);const e=a.length-1;c=a[e];d=b[e];0<e&&!tF(c,d)&&uF(c,d);for(c=e+1;c<b.length;)a.push(b[c]),c++},wF=function(a,b){const c=a[a.length-1];var d=b.findIndex(f=>f.fa===c.fa);const e=b[d];tF(c,e)||uF(c,e);for(d+=1;d<b.length;d++)a.push(b[d])},BF=function(a,b,c,d){var e=a[0].length();e=NE(e).map(f=>{var g=rF(a,f)||
27
+ [];const h=kF(b,f)||[];{f=kF(c,f)||[];const k=[...xF(g),...h,...f].filter(Boolean);yF(k);const {fa:l,duration:m}=k[0];g={variants:g,textStreams:h,thumbStreams:f,startTime:0,id:`P${l}`,endTime:m,duration:m,fa:l}}return g});d&&zF(e[0]);AF(e);return e},xF=function(a){a=new Set(a.flatMap(b=>[b.video,b.audio]).filter(Boolean));return Array.from(a)},zF=function(a){const b=xF(a.variants)[0].S[0].wa;a.startTime+=b;a.endTime+=b},AF=function(a){for(let b=0;b<a.length;b++){const c=a[b],d=a[b-1];c.startTime=
28
+ d?d.endTime:c.startTime;c.endTime=c.startTime+c.duration}},tF=function(a,b){return a.startTime===b.startTime&&a.endTime===b.endTime},uF=function(a,b){a.startTime=b.startTime;a.endTime=b.endTime;a.duration=b.duration;CF(a.variants,b.variants);DF(bE(a),bE(b))},CF=function(a,b){const c=new Map(a.map(d=>[rE(d),d]));b.forEach(d=>{c.get(rE(d)).drmInfos=d.drmInfos})},DF=function(a,b){const c=new Map(a.map(d=>[d.xa,d]));b.forEach(d=>{const e=c.get(d.xa);e.S=d.S;e.segmentIndex.replace(d.S);e.Bc=d.Bc;e.ae=
29
+ d.ae;e.duration=d.duration;e.Qe=d.Qe;e.encrypted=d.encrypted;e.drmInfos=d.drmInfos;e.keyId=d.keyId})},yF=function(a){const b=EF(a);a.forEach(c=>{_.By(c.segmentIndex,b);c.duration=b;c.ae=c.Bc+b})},EF=function(a){let b=Infinity;a.filter(eE).forEach(c=>{b=Math.min(b,c.duration)});return b},FF=function(a,b){cE(b,(c,d)=>{_.Jy(a,c.S,d.startTime)})},GF=function(a){return null===a.g?[]:[a.g.audio,a.g.video].filter(b=>b).map(b=>b.xa)},HF=function(a,b){return _.x(function*(){var c=_.ti([b],a.a.attemptParameters);
30
+ c.type=1;c=yield a.C(c);let d="";try{d=_.Qh(c.data)}catch(e){throw new _.H(_.G,4,4042);}d=d.replace(/\r\n|\r(?=[^\n]|$)/gm,"\n");d=d.trim();return{text:d,response:c}})},LF=function(a,b){return _.x(function*(){var c=IF(a,b,a.o,"");if(1===c.type){c=_.Dr(c.S[0].a)||"";c=null!=_.Cr.video[c]?_.w:null!=_.Cr.audio[c]?_.p:null;var d="";c===_.w?d="avc1.42E01E":c===_.p&&(d="mp4a.40.2");{c=a.J;var e=a.o;d=a.a.hlsDefaultCodecs||d;var f=[];const q=[];q.push(new _.mi(_.la,"0"));q.push(new _.mi(_.Gb,e));d.length&&
31
+ q.push(new _.mi(_.na,d));f.push(new _.ni(c.f++,JD,q));c=new GE(e,0,f)}}d=c.X;c=WD(d,"EXT-X-MEDIA");e=WD(d,JD);d=WD(d,"EXT-X-IMAGE-STREAM-INF");c={Ac:{Pf:XD(c,["AUDIO",_.Mb]),closedCaptions:XD(c,GD),$g:XD(c,OD)},cd:e,Ud:d};const {periods:g,nf:h,zf:k}=yield JF(a,c);if(!a.D)throw new _.H(_.G,7,7001);c=tE(g[0]);e=!0;d=null;f=0;KF(a)||(e=!1,d=0,f=c.delay);d=f=new _.wD(d,f,!0);d.j=e;d.l=e;FF(f,g);h&&(f.H={offsetDateTime:h-_.Oy(f,0),seekRangeStartDateTime:h});e=f;if(!KF(a)){a.G=c.bd;c=0;for(var l of a.f.values())c=
32
+ Math.max(c,l.streams[0].Bc);for(l=0;95443.7176888889<=c;)l+=95443.7176888889,c-=95443.7176888889;if(l){a.h.debug("Offsetting live streams by",l,"to compensate for rollover");for(var m of a.f.values())c=m.streams[0],95443.7176888889>c.Bc?(a.h.debug("Offset applied to",c.type),c.segmentIndex.offset(l)):a.h.debug("Offset NOT applied to",c.type)}}m=qE(g);"LIVE"===a.l||"EVENT"===a.l?(m=Math.max(m,e.F),isNaN(a.a.availabilityWindowOverride)||(m=a.a.availabilityWindowOverride),e.w=m):a.l===_.vx&&(e.f=m);
33
+ if(k)for(var n of k)a.D.onTimelineCueAdded({schemeIdUri:n.schemeIdUri,Pa:n.Pa,value:"",startTime:n.startTime,endTime:n.endTime,id:n.id,type:_.Vg,eventElement:null});n={presentationTimeline:e,adaptedPeriods:[...g],periods:g,offlineSessionIds:[],minBufferTime:0};a.h.debug("HLS playlist parsed",n);return n})},NF=function(a,b){return Promise.all(b.map(c=>MF(a,c)))},PF=function(a,b){b.forEach(c=>{a:{var d=a.f.get(c.a),e=!KF(a),f=ZD(c.X,_.Ba);if(f)var g=Number(f.value);else{d?(f=d.streams[d.streams.length-
34
+ 1].S,f=f[f.length-1].fa):f=0;if(e&&0<f)try{{const k=ZD(c.X,_.Fa);if(!k)throw OF.error("Failed to infer discontinuity number, because EXT-X-MEDIA-SEQUENCE tag is missing."),Error(KD);const l=Number(k.value),m=lF(d,l);if(!m)throw OF.error("Failed to infer discontinuity number, could not find the appropriate segment in the previous playlist"+` (segment position = ${l})`),Error(KD);var h=m.fa}g=h;break a}catch(k){throw new _.H(_.G,4,4024,"EXT-X-DISCONTINUITY-SEQUENCE tag is required for discontinuous HLS live streams.");
35
+ }g=0}}c=c.S||[];for(const k of c)YD(k.X,_.Aa)&&g++,k.fa=g});VE(b)},SF=function(a,b){return _.x(function*(){const {textStreams:c,thumbStreams:d,Qf:e}=yield QF(a,b);var f=a.w.periods[0].variants;a.a.hlsLowLatency&&null!==a.g&&(f=f.filter(g=>g.id===a.g.id));f=f.map(g=>{const h=zE(g.audio,e),k=zE(g.video,e);g=RF(a,h,k,g.bandwidth);if(!g)throw new _.H(_.G,4,4047,{message:"Video and audio are encrypted in an incompatible way.",Eh:k?uE(k).xa:void 0,audio:h?uE(h).xa:void 0});return g});return BF(f,c,d,!0)})},
36
+ UF=function(a,b,c){TF(a,_.vx);b.j=!0;b.l=!0;b.f=c[c.length-1].endTime},TF=function(a,b){a.l=b;KF(a)&&a.j.stop()},IF=function(a,b,c,d){a=LE(a.J,b,c);a.a=d;VF(a);return a},JF=function(a,b){return _.x(function*(){var c=wE(b.Ac.closedCaptions),d=WF(a,b.cd),e=yield XF(a,b);const f=Object.values(e).flat().map(h=>h.Ea);PF(a,f);var g=yield YF(a,e.He,d);c=yield ZF(a,e.cd,g,c);d=yield $F(a,e.Zg,d);g=yield aG(a,e.Ud);e=bG(a,e);c=BF(c,d,g,!KF(a));a.D.filterAllPeriods(c);return KF(a)?(d=null,e&&(d=cG(f,e)),{periods:c,
37
+ nf:null,zf:d}):{periods:c,nf:e,zf:null}})},QF=function(a,b){return _.x(function*(){const c=g=>uE(g.stream).type===_.w||uE(g.stream).type===_.p;var d=b.filter(c),e=b.filter(g=>!c(g)),f=g=>{g=g.map(h=>{var k=uE(h.stream);k={language:k.language,channelsCount:k.channelsCount,spatialAudio:k.spatialAudio,closedCaptions:k.closedCaptions,primary:k.primary,kind:k.kind||null,groupId:k.groupId,type:k.type,codecs:k.codecs,name:k.originalId,uri:k.xa,Dd:{width:k.width,height:k.height,frameRate:k.frameRate}};h=
38
+ Object.assign({},{Ea:h.Ea},k);return dG(a,h)});return Promise.all(g)};d=yield f(d);f=yield f(e);eG(a,d.concat(f));e=f.filter(g=>uE(g).type===_.Nx);f=f.filter(g=>uE(g).type===_.Td);return{textStreams:e,thumbStreams:f,Qf:d}})},RF=function(a,b,c,d){const e=[],f=(c||b).length();for(let m=0;m<f;m++){var g=b?b.streams[m]||null:null,h=c?c.streams[m]||null:null,k=g,l=h;k=k&&l?_.jy(k.drmInfos,l.drmInfos)?_.iy(k.drmInfos,l.drmInfos):null:k?k.drmInfos:l?l.drmInfos:null;if(!k)return null;l=d;g={id:a.H++,language:g?
39
+ g.language:_.Ef,primary:!!g&&g.primary||!!h&&h.primary,audio:g,video:h,bandwidth:l,drmInfos:k,allowedByApplication:!0,allowedByKeySystem:!0};e.push(g)}return new fG(e)},dG=function(a,b){return _.x(function*(){const c=b.Ea,d=b.codecs,e=b.type,f=b.Rc,g=b.groupId,h=b.primary;var k=b.kind;const l=b.name,m=b.channelsCount,n=b.spatialAudio,q=b.closedCaptions,t=b.Dd,v=_.Dh(f||_.Ef);if(1!==c.type)throw new _.H(_.G,4,4017);var y=fE(c.X);TF(a,y);const A=sE(c.X,y,a.a.hlsLowLatency||!1);y=yield gG(a,c,e,d);const D=
40
+ a.a.hlsLowLatency?_.vB:_.Dx;let E=k;e!==_.u||k||(E=_.Nx);const {gd:O}=kE(c.X);k=y.map(tb=>{const Nb=tb.S,Zc=tb.ag,Qf=tb.mimeType;tb=tb.fa;const Va=Nb[0].startTime,Yd=Nb[Nb.length-1].endTime,uc=Yd-Va,ea=new _.xD(Nb),bb=Nb[0].initSegment||null;return{id:a.H++,originalId:l,createSegmentIndex:Promise.resolve.bind(Promise),findSegmentPosition:ea.f.bind(ea),getSegmentReference:ea.get.bind(ea),adjustSegmentDurations:ea.g.bind(ea),getDuration:ea.getDuration.bind(ea),segmentIndex:ea,segmentLookupStrategy:D,
41
+ initSegmentReference:bb,mimeType:Qf,codecs:d,kind:E,Qe:Zc.type,encrypted:Zc.type===RD,keyId:Zc.keyId,language:v,originalLanguage:f||_.Ef,label:l,type:e,primary:h,trickModeVideo:null,emsgSchemeIdUris:null,frameRate:t?t.frameRate:void 0,width:t?t.width:void 0,height:t?t.height:void 0,bandwidth:void 0,roles:[],channelsCount:m,spatialAudio:n,closedCaptions:q,keyInfo:Zc.keyInfo,S:Nb,drmInfos:Zc.drmInfos,fa:tb,xa:c.a,Fd:c.f,Bc:Va,ae:Yd,duration:uc,gd:O,groupId:g,yg:A}});return new hG(k)})},eG=function(a,
42
+ b){b.forEach(c=>{a.f.a.set(uE(c).xa,c)})},WF=function(a,b){const c=new Map;for(const f of b){var d=_.I(f,"AUDIO");b=_.I(f,_.Mb);var e=_.I(f,OD);const g=iG(a,f);if(e){const h=_.aj(_.u,g);c.set(e,h);e=g.indexOf(h);-1<e&&g.splice(e,1)}d&&(e=jG(_.p,g),c.set(d,e));b&&(d=jG(_.w,g),c.set(b,d))}return c},XF=function(a,b){return _.x(function*(){const c=yield Promise.all([kG(a,b.Ac.Pf),kG(a,b.Ac.$g),kG(a,b.cd),kG(a,b.Ud)]),[d,e,f,g]=c;return{He:d,Zg:e,cd:f,Ud:g}})},YF=function(a,b,c){return _.x(function*(){if(0===
43
+ b.length)return new Map;var d=[lG(a,b[0],c)];yield d[0];d=d.concat(b.slice(1).map(e=>lG(a,e,c)));d=yield Promise.all(d);return vE(d)})},ZF=function(a,b,c,d){return _.x(function*(){const e=new Set;var f=[...b];let g=0;var h=Infinity;for(let k=0;k<f.length;++k){const l=Number(TD(f[k].tag,_.la));l<h&&(h=l,g=k)}h=f.splice(g,1).pop();h=yield mG(a,h,c,d,e);f=f.map(k=>mG(a,k,c,d,e));f=yield Promise.all(f);f.splice(g,0,h);return f.reduce(_.$x,[])})},$F=function(a,b,c){return Promise.all(b.map(d=>lG(a,d,c)))},
44
+ aG=function(a,b){return Promise.all(b.map(c=>nG(a,c)))},bG=function(a,b){b=[...b.cd,...b.He].map(d=>d.Ea).flatMap(d=>d.S[0].X);b=ZD(b,_.Ja);if(!b)return null;const c=(new Date(b.value)).getTime();return isNaN(c)?(a.h.warn("Failed to parse EXT-X-PROGRAM-DATE-TIME tag "+`value (value: ${b.value}).`),null):c/1E3},KF=function(a){return a.l===_.vx},cG=function(a,b){return(a=a.find(c=>null!==ZD(c.X,_.za)))?a.X.filter(c=>c.name===_.za).map(c=>{a:{var d=_.I(c,"ID"),e=_.I(c,"START-DATE");if(null===d||null===
45
+ e)_.Gr.warn("Invalid EXT-X-DATERANGE missing mandatory ID or START-DATE attribute, ignoring the EXT-X-DATERANGE tag.",c),c=null;else{var f=new Date(e);e=f.getTime()/1E3-b;d={id:d,startTime:e,startDate:f};var g=VD(_.I(c,ID));void 0!==g&&0<=g&&(d.duration=g);var h=VD(_.I(c,"PLANNED-DURATION"));void 0!==h&&0<=h&&(d.plannedDuration=h);var k=_.I(c,"CLASS");null!==k&&(d.schemeIdUri=k);var l=_.I(c,"END-DATE");l=l?new Date(l):null;null!==l&&l.getTime()>=f.getTime()&&(d.endDate=l);{const q=c.attributes;if(null==
46
+ q)var m=null;else{f={};for(m of q)m.name.startsWith("X-")&&(f[m.name]=m.value);m=_.wg(f)?f:null}}m=m||{};if(k===_.od){f=c.attributes;if(null==f)var n=null;else{k={};for(n of f)switch(n.name){case _.Tb:k[_.Tb]=n.value;break;case _.Sb:k[_.Sb]=n.value;break;case _.Vb:k[_.Vb]=VD(n.value);break;case _.Ub:k[_.Ub]=VD(n.value);break;case "X-SNAP":k["X-SNAP"]=n.value.split(",");break;case "X-RESTRICT":k["X-SNAP"]=n.value.split(",")}k[_.Tb]&&k[_.Sb]||!k[_.Tb]&&!k[_.Sb]?(_.Gr.warn("Invalid EXT-X-DATERANGE Interstitial attributes X-ASSET-URI, X-ASSET-LIST"),
47
+ n=null):n=_.wg(k)?k:null}if(null===n){_.Gr.warn("Invalid interstitial attributes, ignoring the EXT-X-DATERANGE tag.",c);c=null;break a}m=Object.assign(m,n)}_.wg(m)&&(d.Pa=m);d.endTime=l?l.getTime()/1E3:g?e+g:h?e+h:e;d.type="hls-daterange";c=d}}return c}).filter(Boolean):null},kG=function(a,b){return _.x(function*(){return(yield Promise.all(b.map(c=>_.x(function*(){const d=yield oG(a,c);return d?{tag:c,Ea:d}:null})))).filter(Boolean)})},MF=function(a,b){return _.x(function*(){var c=new _.rh(uE(b).Fd);
48
+ if(a.a.hlsLowLatency&&uE(b).gd){var d=b.streams[b.streams.length-1].segmentIndex;if(d=d.a[d.a.length-1]){var e=d.a,f=e.length-1;d={Bg:d.position,Hg:e&&0<e.length?f:null}}else d=null;if(e=d)d=e.Bg,e=e.Hg,f=_.Ni(c.a.toString()),f._HLS_msn=d.toString(),null===e&&f._HLS_part&&delete f._HLS_part,null!==e&&(f._HLS_part=e.toString()),d=_.Mi(f,!0),d=new _.yh(d),_.uh(c,d)}const {response:g,text:h}=yield HF(a,c.toString());c=uE(b).xa;d=uE(b).Fd;e=g.uri;d!==e&&(d=e,mF(b,d));c=IF(a,h,d,c);return{stream:b,Ea:c}})},
49
+ iG=function(a,b){var c=_.I(b,_.na,a.a.hlsDefaultCodecs||"avc1.42E01E,mp4a.40.2").split(/\s*,\s*/);b=new Set;const d=[];for(const e of c)c=_.ry(e)[0],b.has(c)?a.h.debug("Ignoring duplicate codec"):(d.push(e),b.add(c));return d},jG=function(a,b){if(1===b.length)return b[0];a=_.aj(a,b);if(null!=a)return a;throw new _.H(_.G,4,4025,{codecList:b});},lG=function(a,b,c){return _.x(function*(){const d=b.tag,e=b.Ea;return pG(a,e.a,()=>_.x(function*(){const f=TD(d,_.Sa),g=gE(TD(d,_.Eb));var h=TD(d,_.Eb).toUpperCase();
50
+ if(gE(h)!==_.u)h=null;else{var k=d.getAttribute("FORCED");k=!(!k||!k.value||"YES"!==k.value.toUpperCase());var l=_.Nx;h===GD&&(l=_.Ax);k&&(l="forced");h=l}k=c.get(f)||"";l=_.I(d,_.Za);const m=_.I(d,"NAME"),n=d.getAttribute("DEFAULT"),q=d.getAttribute("AUTOSELECT");var t=_.I(d,"CHANNELS");t=g===_.p?t?parseInt(t.split("/")[0],10):null:null;var v=g===_.p?(v=_.I(d,"CHANNELS"))?v.includes("/JOC"):!1:!1;return yield dG(a,{Ea:e,codecs:k,type:g,Rc:l,primary:!!n&&!!q,name:m,channelsCount:t,spatialAudio:v,
51
+ groupId:f,kind:h,closedCaptions:null,Dd:null})}))})},nG=function(a,b){return _.x(function*(){const c=b.tag,d=b.Ea;return pG(a,d.a,()=>_.x(function*(){var e=_.I(c,_.na)||"jpg",f=_.I(c,_.Za);const g=_.I(c,"NAME");e=yield dG(a,{Ea:d,codecs:e,type:_.Td,Rc:f,name:g,primary:!1,kind:null,channelsCount:null,spatialAudio:!1,closedCaptions:null,groupId:null,Dd:null});(f=_.I(c,_.la))&&qF(e,Number(f));return e}))})},mG=function(a,b,c,d,e){return _.x(function*(){var f=b.tag,g=Number(TD(f,_.la));if(null!=f.getAttribute("FRAME-RATE")||
52
+ null!=f.getAttribute(_.ub)){var h=_.I(f,"FRAME-RATE");f=_.I(f,_.ub);var [k,l]=f?f.split("x"):[null,null];h={frameRate:VD(h),width:VD(k),height:VD(l)}}else h=null;if(f=yield qG(a,b,h,c,d)){h=f.video;f=f.audio;var m=0<f.length?f:[null];h=0<h.length?h:[null];f=[];for(const n of m)for(const q of h){m=(q?uE(q).xa:"")+" - "+(n?uE(n).xa:"");if(e.has(m)){a.h.debug("Skipping variant which only differs in text streams.");continue}const t=RF(a,n,q,g);null==t?a.h.warn("Incompatible DRM info in HLS variant. Skipping."):
53
+ (f.push(t),e.add(m))}g=f}else g=[];return g})},qG=function(a,b,c,d,e){return _.x(function*(){var f=b.tag,g=b.Ea;let h=iG(a,f);var k=_.I(f,"AUDIO"),l=_.I(f,_.Mb),m=k||l;m=m&&d.has(m)?d.get(m):[];k={audio:k?m:[],video:l?m:[]};a.h.debug("Guessing stream type for",f.toString());f=!1;const n=g.a;g=k.audio.find(q=>q.xa===n);l=_.aj(_.w,h);l=c||l;1!==h.length||l?!m.length&&1<h.length?(a.h.debug("Guessing multiplexed audio+video"),g=_.w,h=[h.join(",")]):k.audio.length&&g?(a.h.debug(LD),g=_.p,f=!0):k.video.length?
54
+ (a.h.debug(LD),g=_.p):(a.h.debug("Guessing video-only"),g=_.w):(g=_.p,a.h.debug(LD));l=null;f||(l=yield rG(a,b,h,g,e,c));if(null==l)return null;k[g]=[l];g===_.p&&c&&m.forEach(q=>{nF(q,c.width);oF(q,c.height);pF(q,c.frameRate)});yE(k);return k})},rG=function(a,b,c,d,e,f){return _.x(function*(){const g=b.tag,h=b.Ea;return pG(a,h.a,()=>_.x(function*(){var k=_.I(g,GD);let l=null;d===_.w&&k&&"NONE"!==k&&(l=e.get(k));k=jG(d,c);return yield dG(a,{Ea:h,codecs:k,type:d,closedCaptions:l,primary:!1,kind:null,
55
+ Rc:null,name:null,channelsCount:null,spatialAudio:!1,groupId:null,Dd:f})}))})},pG=function(a,b,c){if(a.f.has(b))return a=a.f.get(b),Promise.resolve(a);if(a.f.f.has(b))return a.f.f.get(b)||null;c=c();a.f.set(b,c);return c},gG=function(a,b,c,d){return _.x(function*(){var e=b.a,f=b.S;var g=void 0===g?0:g;var h=(h=ZD(b.X,_.Fa))?Number(h.value):g;g=[];!KF(a)&&cF(f);e=yield sG(a,b.f,e,f,h,c,d);if(0===f.length)f=[];else{var k=[],l=[];for(var m of f)YD(m.X,_.Aa)&&0<l.length&&(k.push(l),l=[]),l.push(m);k.push(l);
56
+ f=k}for(m=0;m<f.length;m++)k=f[m],l=yield tG(a,b.f,k,h,e,c,d,g[g.length-1]||null,f.length),g.push(l),h+=k.length;uG(g);return g})},oG=function(a,b){return _.x(function*(){var c="EXT-X-MEDIA"!==b.name?!0:_.I(b,_.Eb)===OD;c=_.I(b,_.Gb,void 0,{required:c});if(!c)return null;const d=aE(a.o,c),{response:e,text:f}=yield HF(a,d);return IF(a,f,e.uri,c)})},VF=function(a){1===a.type&&a.S.forEach((b,c)=>{if(YD(b.X,_.Ea)&&!YD(b.X,_.Aa)&&0<c)throw new _.H(_.G,4,4046,"Media playlist contains an EXT-X-MAP tag not accompanied by an EXT-X-DISCONTINUITY tag.");
57
+ })},uG=function(a){if(1<(new Set(a.map(b=>b.mimeType))).size)throw new _.H(_.G,4,4045,"Media playlist contains discontinuities with different MIME types. This is valid, but not yet supported.");},vG=function(a){a=a.map(b=>b.a?b.a:b.f.map(c=>_.I(c,_.Gb))||null).map(b=>_.Dr(b));if(1<(new Set(a)).size)throw new _.H(_.G,4,4044,"Unexpected change in file format.");},wG=function(a,b,c){a=WD(a.X,_.Ea);if(1<a.length)throw new _.H(_.G,4,4020);a=a[0];if(!a)return null;const d=TD(a,_.Gb),e=aE(b,d);b=lE(a,null,
58
+ !0);return new _.tD(()=>[e],b.ta,b.ha,c)},xG=function(a,b,c,d,e,f,g){const h=[];for(const q of _.gy(b.f)){b=q.af;const t=q.item;{var k=0===b,l=k?a:h[h.length-1],m=k?d:l.endTime,n=Number(_.I(t,ID));n=m+n;k=lE(t,k?null:l.ha,k);l=_.I(t,_.Gb);const v=(l=aE(g,l))?[l]:[];m=new mE(c,m,n,()=>v,k.ta,k.ha,e,f,!1,null,null,null,null);if("YES"===_.I(t,"INDEPENDENT")||0===b)m.g=!0;h.push(m)}}return h},yG=function(a,b,c,d,e,f,g,h,k,l,m){const n=c.X;var q=c.a;const t=null!=q,v=q?[q]:[];if(!t&&!a.a.hlsLowLatency)return null;
59
+ a=0;q={ta:0,ha:null};let y=null;t?({duration:c}=jE(n),a=e+c,q=iE(n,b?b.ha:null)):(b=xG(b,c,d,e,f,g,k),a=b[b.length-1].endTime,y=b);h=h===_.Td?$D(n):null;d=new mE(d,e,a,()=>v,q.ta,q.ha,f,g,!1,null,h?h.Ze:null,h?h.Bf:null,h?h.durationPerTile:null,y);d.fa=l;d.initSegment=m||void 0;return d},sG=function(a,b,c,d,e,f,g){return _.x(function*(){var h=d[0];if(null!=a.B)return a.B;if(!KF(a)&&a.w)try{var k=a.f.get(c);var l=k?lF(k,e)||null:null;if(!l)throw new _.H(_.G,4,4030,"Segment not found in pervious playlist update.");
60
+ var m=l.startTime+l.wa;a.h.debug(`Setting playlist start time to ${m}.`);return a.B=m}catch(n){if(h=a.f.get(c))m=h.streams[h.streams.length-1].S,m=m[m.length-1],a.h.warn(`Last #EXT-X-MEDIA-SEQUENCE values ${h.streams[0].S[0].position} - ${m.position}`+`, new values ${e} - ${e+d.length-1}.`,b,h);throw new _.H(_.G,4,4047,{message:"The updated playlist does not share any segments with the previous one.",uri:c});}m=yield zG(a,f,g,h);k=dF(h.X,a.o,m)||ZE();l=wG(h,b,k.keyInfo);k=oE(k.keyInfo,e);h=yield AG(a,
61
+ l,h,k,m,g);a.h.debug(`Setting playlist start time to ${h}.`);return a.B=h})},tG=function(a,b,c,d,e,f,g,h,k){return _.x(function*(){var l=c[0],m=null==h;vG(c);const n=yield zG(a,f,g,l);var q=a.o,t=h?h.xg:null;var v=1===k;if(c.slice(1).some(bF))throw new _.H(_.G,4,4046,v?"Media playlist contains an EXT-X-KEY tag with METHOD\x3dAES-128 which is not at the beginning of the playlist.":"Media playlist contains an EXT-X-KEY tag with METHOD\x3dAES-128 which is not marked by an EXT-X-DISCONTINUITY tag and is not at the beginning of the playlist.");
62
+ if(YD(c[0].X,_.Da)||null===t)if((t=dF(c[0].X,q,n))&&t.type===SD){if(1<fF(c))throw new _.H(_.G,4,4046,PD+`${v?"playlist":"discontinuity"}.`);v=[t]}else v=eF(c,q,n),v=0===v.length?[ZE()]:v;else if(q=eF(c,q,n),t.type===_.te||t.type===RD)v=[t,...q];else{if(0<fF(c))throw new _.H(_.G,4,4046,PD+`${v?"playlist":"discontinuity"}.`);v=[t]}q=v;v=q[q.length-1];q=$E(q);t=wG(l,b,q.keyInfo)||(h?h.tg:null);var y=oE(q.keyInfo,d);const A=l.fa;l=m?e:yield BG(a,A,t,l,d,y,n,g);m=[];for(y=0;y<c.length;y++){var D=c[y];
63
+ const E=m[m.length-1]||null,O=0===y?0:E.endTime,tb=d+y,Nb=oE(q.keyInfo,tb);(D=yG(a,E,D,tb,O,l,Nb,f,b,A,t))&&m.push(D)}return{S:m,ag:q,xg:v,mimeType:n,endTime:m[m.length-1].endTime,fa:A,tg:t}})},zG=function(a,b,c,d){return _.x(function*(){const e=d.a;var f=ZD(d.X,_.Ea);f=f?TD(f,_.Gb):null;return CG(a,b,c,e,f)})},AG=function(a,b,c,d,e,f){return _.x(function*(){if(null==c.a)return 0;const g=nE(c,d);return jF(a.K,b,g,e,f,null!=d)})},BG=function(a,b,c,d,e,f,g,h){return _.x(function*(){if(a.F.has(b))return a.F.get(b);
64
+ const k=yield AG(a,c,d,f,g,h);a.h.debug(`Segment #${e} has raw media timestamp `+`${k} s.`);a.F.set(b,k);return k})},CG=function(a,b,c,d,e){return _.x(function*(){const f=[d,e].filter(Boolean);var g=_.dj(f,b,c);if(g)return g;g=_.ti([d],a.a.attemptParameters);g.method="HEAD";g.type=2;g=(yield a.C(g)).headers["content-type"];if(!g)throw new _.H(_.G,4,4021,"Unknown MIME type of: "+f.join(", "));return g.split(";")[0]})},GE=class{constructor(a,b,c,d){if(1===b){if(!d||0===d.length)throw new _.H(_.G,4,
65
+ 4043,"Media playlist must have at least one segment!");if(null==d[0].a)throw new _.H(_.G,4,4043,"Media playlist must have at least one full segment!");}this.f=a;this.a="";this.type=b;this.X=c;this.S=1===b?d:null}},ME=class{constructor(a,b,c){c=void 0===c?[]:c;this.X=b;this.a=a;this.f=c;this.fa=-1}},mE=class extends _.Ty{constructor(a,b,c,d,e,f,g,h,k,l,m,n,q,t){t=void 0===t?[]:t;super(a,b,c,d,e,f,g,void 0===h?null:h,void 0===k?!1:k,void 0===l?null:l,void 0===m?null:m,void 0===n?null:n,void 0===q?null:
66
+ q,t);this.initSegment=void 0;this.fa=0}},DG=class{constructor(){this.f=0;this.a=new Map}},EG=class{constructor(){this.a=new Map;this.f=new Map}set(a,b){this.f.set(a,b);return b.then(c=>this.a.set(a,c)).catch(()=>{}).then(()=>this.f.delete(a))}has(a){return this.a.has(a)}get(a){return this.a.get(a)||null}values(){return Array.from(this.a.values())}clear(){this.f.clear();this.a.clear()}},OF=new _.R("clpp.hls.DiscontinuityUtils");var hF={"com.apple.streamingkeydelivery":function(a,b){if(b===_.Of)throw new _.H(_.G,4,4041);if(TD(a,MD)===ND)throw new _.H(_.G,4,4044,"EXT-X-KEY:METHOD SAMPLE-AES-CTR is not supported in FairPlay.");return _.cy(_.nd,[{initDataType:_.of,initData:new Uint8Array(0)}],"")},"com.microsoft.playready":YE,"urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95":YE,"urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed":function(a){var b=TD(a,MD);if(!WE.includes(b))return XE.error("Widevine in HLS is only supported with [",
67
+ WE.join(", "),"], not",b),null;b=TD(a,_.Gb);b=_.Uq(b);b=_.J(b.data);b=_.cy(_.rd,[{initDataType:_.Sc,initData:b}],"");if(a=_.I(a,"KEYID"))b.keyIds=[a.substr(2).toLowerCase()];return b}},WE=["SAMPLE-AES",ND],XE=new _.R("clpp.hls.DrmParser");var gF=new _.R("clpp.hls.EncryptionUtils");var FG=class{constructor(a){this.h=new _.R("clpp.hls.MediaReader");this.f=a;this.a={attemptParameters:_.qi()}}};var hG=class{constructor(a){this.streams=a}length(){return this.streams.length}};var fG=class{constructor(a){this.a=a}length(){return this.a.length}};var GG=class{constructor(){this.a=this.D=null;this.H=1;this.f=new EG;this.o="";this.J=new DG;this.G=0;this.g=null;this.j=new _.lj(()=>{this.Bb()});this.l=_.vx;this.w=null;this.A=new _.Lr;this.B=null;this.h=new _.R("clpp.hls.HlsParser");this.F=new Map;this.K=new FG(this.C.bind(this));this.I=!1}configure(a){this.a=a;this.K.a=a}setCurrentVariant(a){this.g=a}start(a,b){const c=this;return _.x(function*(){if(c.I)throw Error("start() may be called only once!");c.I=!0;c.D=b;const {response:d,text:e}=yield HF(c,
68
+ a);c.o=d.uri;const f=yield LF(c,e);c.w=f;const g=c.G;0<g&&c.j.ca(g);return f})}stop(){this.j&&(this.j.stop(),this.j=null);const a=[];this.A&&(a.push(this.A.destroy()),this.A=null);this.f.clear();this.w=this.a=this.D=this.g=null;return Promise.all(a)}onExpirationUpdated(){}update(){const a=this;return _.x(function*(){const b=a.w;if(!KF(a)&&b){var c=b.presentationTimeline;"LIVE"===a.l&&(a.B=null);var d=Array.from(a.f.values());if(a.a.hlsLowLatency&&null!==a.g){const f=GF(a);d=d.filter(g=>f.includes(uE(g).xa))}var e=
69
+ yield NF(a,d);d=e.map(f=>f.Ea);PF(a,d);e=yield SF(a,e);sF(b.periods,e).forEach(f=>{a.D.filterNewPeriod(f)});vF(b.periods,e);wF(b.adaptedPeriods,e);FF(c,e);dE(d)&&UF(a,c,e)}})}Bb(){const a=this;return _.x(function*(){a.h.debug(_.ux);if(a.D)try{yield a.update(),a.j.ca(a.G)}catch(b){if(!(b instanceof _.H))throw b;a.D&&(a.D.onError(b),1===b.severity&&a.j.ca(.1))}})}C(a){if(!this.A)throw new _.H(_.G,7,7001);a=this.D.networkingEngine.fetch(a);_.Ai(this.A,a);return a.P}};_.z("clpp.hls.HlsComponent",class extends _.Js{f(){_.sq.m3u8=GG;_.qq[_.gk]=GG;_.qq[QD]=GG}a(){_.$y("m3u8");_.az(_.gk);_.az(QD)}id(){return"hls"}});};f.call(g, window);
package/cl.hlssmpte.js CHANGED
@@ -1,5 +1,5 @@
1
- import {clpp} from "./cl.core.js";let g={};const _ = clpp._;var f=function(window){'use strict';var NN=function(a){a.a.one(a.m,_.ee,()=>MN(a))},MN=function(a){const b=a.m.getSurface().getMedia();if(b)if(a.g){a.a.on(b.textTracks,_.mc,d=>ON(a,d));var c=Array.from(b.textTracks);c.filter(d=>d.kind===_.le).forEach(d=>{ON(a,{track:d})});!PN(c)&&a.l&&(a.h.warn("The metadata track is not present. Changing an audio track in order to enforce the creation of the metadata track."),QN(a,b))}else a.h.warn("The clpp.ttml.TextParser class is not available. Please register the ttml component first.");
2
- else a.h.warn("A video element is not available. Skipping.")},ON=function(a,b){b=b.track;b.kind===_.le&&(a.h.info("The metadata track has been added."),b.mode=_.Qd,a.a.on(b,_.vd,c=>RN(a,c)))},PN=function(a){return a.some(b=>b.kind===_.le)},QN=function(a,b){const c=a.m.getTrackManager(),d=c.oa(),e=c.getAudioTracks().find(g=>g!==d);if(e){var f=()=>c.sa(d);a.a.on(b.textTracks,_.mc,g=>{g.track.kind===_.le&&(a.a.off(b.textTracks,_.mc,f),c.sa(d))});c.sa(e)}else a.h.warn("Can't enforce the creation of the metadata track if single audio track. Skipping.")},
3
- RN=function(a,b){const c=SN(a);c&&Array.from(b.target.activeCues||[]).forEach(d=>{if(d!==a.f&&Number.isFinite(d.startTime)&&Number.isFinite(d.endTime)&&"org.id3"===d.type&&d.value&&"TXXX"===d.value.key){var e=new TN(d);if(e.f===c&&null!==e.a){a.f=d;d=a.g.parseMedia(_.Th(e.a),{periodStart:a.j,segmentStart:e.startTime,segmentEnd:e.endTime});const f=a.m.getTextDisplayer();f.remove(0,e.startTime);f.append(d.cues,d.styles)}}})},SN=function(a){return(a=a.m.getTrackManager().pa())&&a.language&&a.language.toLowerCase()},
4
- TN=class{constructor(a){this.startTime=a.startTime;this.endTime=a.endTime;this.a=this.f=null;a=a.value;if(!_.B(a)){a:{var b=a.info;if(_.zg(b)&&(b=b.toLowerCase().match(/lang:(\w+)/))&&b[1]){b=b[1].toLowerCase();break a}b=null}this.f=b;a=a.data;this.a=a=_.zg(a)?a:null}}};var UN=class{constructor(a,b,c){this.m=a;this.l=b;this.j=c;this.a=new _.br;this.g=(a=_.Oq[_.Ac]||null)?new a(this.m.getConfiguration()):null;this.h=new _.R("clpp.hlssmpte.ImageCueHandler");this.f=null;NN(this)}destroy(){this.a.release();this.f=null;return Promise.resolve()}};var VN=class extends _.ft{constructor(){super();this.a=null;this.f=!1}onPlayerCreated(){}onContentWillLoad(a){if(this.f=_.yj()){var b=a.getConfiguration();b=_.tg(b.hlssmpte||{});typeof b.patchMetadataTrack!==_.Kc&&(b.patchMetadataTrack=!1);_.Ag(b.timestampOffset)||(b.timestampOffset=0);this.a=new UN(a,b.patchMetadataTrack,b.timestampOffset)}}onPlayerWillDestroy(){const a=this;return _.x(function*(){a.a&&(yield a.a.destroy(),a.a=null)})}id(){return"hlssmpte"}};_.z("clpp.hlssmpte.HlsSmptePlugin",VN);
5
- VN.Id="hlssmpte";_.oo(new class{create(){return new VN}});};f.call(g, window);
1
+ import {clpp} from "./cl.core.js";let g={};const _ = clpp._;var f=function(window){'use strict';var YN=function(a){a.a.one(a.m,_.fe,()=>XN(a))},XN=function(a){const b=a.m.getSurface().getMedia();if(b)if(a.g){a.a.on(b.textTracks,_.mc,d=>ZN(a,d));var c=Array.from(b.textTracks);c.filter(d=>d.kind===_.me).forEach(d=>{ZN(a,{track:d})});!$N(c)&&a.l&&(a.h.warn("The metadata track is not present. Changing an audio track in order to enforce the creation of the metadata track."),aO(a,b))}else a.h.warn("The clpp.ttml.TextParser class is not available. Please register the ttml component first.");
2
+ else a.h.warn("A video element is not available. Skipping.")},ZN=function(a,b){b=b.track;b.kind===_.me&&(a.h.info("The metadata track has been added."),b.mode=_.Rd,a.a.on(b,_.vd,c=>bO(a,c)))},$N=function(a){return a.some(b=>b.kind===_.me)},aO=function(a,b){const c=a.m.getTrackManager(),d=c.oa(),e=c.getAudioTracks().find(g=>g!==d);if(e){var f=()=>c.sa(d);a.a.on(b.textTracks,_.mc,g=>{g.track.kind===_.me&&(a.a.off(b.textTracks,_.mc,f),c.sa(d))});c.sa(e)}else a.h.warn("Can't enforce the creation of the metadata track if single audio track. Skipping.")},
3
+ bO=function(a,b){const c=cO(a);c&&Array.from(b.target.activeCues||[]).forEach(d=>{if(d!==a.f&&Number.isFinite(d.startTime)&&Number.isFinite(d.endTime)&&"org.id3"===d.type&&d.value&&"TXXX"===d.value.key){var e=new dO(d);if(e.f===c&&null!==e.a){a.f=d;d=a.g.parseMedia(_.Uh(e.a),{periodStart:a.j,segmentStart:e.startTime,segmentEnd:e.endTime});const f=a.m.getTextDisplayer();f.remove(0,e.startTime);f.append(d.cues,d.styles)}}})},cO=function(a){return(a=a.m.getTrackManager().pa())&&a.language&&a.language.toLowerCase()},
4
+ dO=class{constructor(a){this.startTime=a.startTime;this.endTime=a.endTime;this.a=this.f=null;a=a.value;if(!_.B(a)){a:{var b=a.info;if(_.Ag(b)&&(b=b.toLowerCase().match(/lang:(\w+)/))&&b[1]){b=b[1].toLowerCase();break a}b=null}this.f=b;a=a.data;this.a=a=_.Ag(a)?a:null}}};var eO=class{constructor(a,b,c){this.m=a;this.l=b;this.j=c;this.a=new _.hr;this.g=(a=_.Wq[_.Ac]||null)?new a(this.m.getConfiguration()):null;this.h=new _.R("clpp.hlssmpte.ImageCueHandler");this.f=null;YN(this)}destroy(){this.a.release();this.f=null;return Promise.resolve()}};var fO=class extends _.jt{constructor(){super();this.a=null;this.f=!1}onPlayerCreated(){}onContentWillLoad(a){if(this.f=_.zj()){var b=a.getConfiguration();b=_.ug(b.hlssmpte||{});typeof b.patchMetadataTrack!==_.Kc&&(b.patchMetadataTrack=!1);_.Bg(b.timestampOffset)||(b.timestampOffset=0);this.a=new eO(a,b.patchMetadataTrack,b.timestampOffset)}}onPlayerWillDestroy(){const a=this;return _.x(function*(){a.a&&(yield a.a.destroy(),a.a=null)})}id(){return"hlssmpte"}};_.z("clpp.hlssmpte.HlsSmptePlugin",fO);
5
+ fO.Id="hlssmpte";_.ro(new class{create(){return new fO}});};f.call(g, window);
package/cl.htmlcue.js CHANGED
@@ -1,26 +1,26 @@
1
- import {clpp} from "./cl.core.js";let g={};const _ = clpp._;var f=function(window){'use strict';var DM="Unsupported unit",EM="clpp-text-plain",FM="clpp-text-ttml",GM="clpp.htmlcue.HtmlTextDisplayer",HM="initial",IM=function(a){return _.gh(a,{Oe:(b,c)=>b.md(c)})},JM=function(a,b){if(0===b.length)return a;let c=a;a=a.findIndex(d=>d.startTime>=b[0].startTime);0<=a&&(c=c.slice(0,a));return c.concat(b)},KM=function(a,b){let c=0,d=a.length-1;for(;c<=d;){const e=c+d>>1,f=b(a[e]);if(0===f)return e;0<f?c=e+1:d=e-1}return-1},LM=function(a){if(!a.input)return null;var b=a.input.match(/^([^<]*)(<[^>]+>?)?/);
2
- b=b[1]?b[1]:b[2];a.input=a.input.substr(b.length);return b},NM=function(a){let b=null;for(;b=a.match(/&(amp|lt|gt|lrm|rlm|nbsp);/);)a=a.replace(b[0],c=>MM[c]);return a},PM=function(a,b){OM(a,b);Array.from(b.getElementsByTagName("*")).forEach(c=>{OM(a,c)})},OM=function(a,b){for(const c in a)null!=a[c]&&(b.style[c]=a[c])},QM=function(a,b){return 0===a?"0":a+b},RM=function(a,b){return 1>Math.abs(a-b)||a<b},SM=function(a,b){return a<b&&1<Math.abs(a-b)},TM=function(a,b){return a>b&&1<Math.abs(a-b)},UM=
3
- function(a,b){return 1>Math.abs(a-b)||a>b},WM=function(a){const b=a.getBoundingClientRect();var c=getComputedStyle(a,null);const d=parseFloat(c.getPropertyValue("border-left-width"))||0,e=parseFloat(c.getPropertyValue("border-right-width"))||0;var f=parseFloat(c.getPropertyValue("border-top-width"))||0;c=parseFloat(c.getPropertyValue("border-bottom-width"))||0;const g=(b.top||a.offsetTop)+f;f=(b.height||a.offsetHeight)-f-c;return new VM(b.left+d,b.right+e,g,(b.bottom||g+f)+c,f,(b.width||a.offsetWidth)-
4
- d-e)},XM=function(a){return new VM(a.left,a.f,a.top,a.a,a.height,a.width)},YM=function(a,b){return b.some(c=>SM(a.left,c.f)&&TM(a.f,c.left)&&SM(a.top,c.a)&&TM(a.a,c.top))},ZM=function(a,b){return UM(a.top,b.top)&&RM(a.a,b.a)&&UM(a.left,b.left)&&RM(a.f,b.f)},$M=function(a,b,c){switch(c){case "+x":return SM(a.left,b.left);case "-x":return TM(a.f,b.f);case "+y":return SM(a.top,b.top);case "-y":return TM(a.a,b.a);default:throw Error("Unknown axis");}},aN=function(a){return a.f.writingMode===_.fr},bN=
5
- function(a){var b=a.a.childNodes[0],c=a.a.getBoundingClientRect();const d=b.getClientRects();b=c.height/d.length;c=c.width/d.length;return aN(a)?b:c},cN=function(a){switch(a.f.writingMode){case _.fr:return"horizontal-tb";case _.Lf:return _.Lf;case _.Mf:return _.Mf;default:throw Error("Unknown writing mode");}},dN=function(a){switch(a.f.positionAlign){case _.ce:return _.Wd;case "auto":case _.Tc:return _.er;case _.de:return _.gf}return a.f.textAlign},eN=function(a,b){if(typeof a.f.position===_.r&&typeof a.f.size===
6
- _.r)switch(b){case _.ce:return a.f.position;case "auto":case _.Tc:return a.f.position-a.f.size/2;case _.de:return a.f.position-a.f.size}return 0},fN=function(a){if(!a.f.positionAlign)switch(a.f.textAlign){case _.Wd:case _.Wd:return _.ce;case _.er:return _.Tc;case _.gf:case _.gf:return _.de}return a.f.positionAlign},iN=function(a,b,c){return(gN(a)||hN(a))&&_.Ag(c)?QM(c,_.$e):gN(a)&&_.B(c)?QM(0,_.$e):aN(a)&&_.Ag(b)?QM(b,"%"):HM},jN=function(a,b,c){return aN(a)&&_.Ag(c)?QM(c,_.$e):(gN(a)||hN(a))&&_.Ag(b)?
7
- QM(b,"%"):HM},hN=function(a){return a.f.writingMode===_.Mf},gN=function(a){return a.f.writingMode===_.Lf},kN=function(a,b){if(a.j)switch(b.writingMode){case _.fr:return["-y"];case _.Lf:return["+x"];case _.Mf:return["-x"]}a=[];switch(b.writingMode){case _.fr:a=["+y","-y"];break;case _.Lf:a=["+x","-x"];break;case _.Mf:a=["-x","+x"]}0>b.line&&(a=a.reverse());return a},lN=function(a){for(a.g=[];0<a.f.childNodes.length;)a.f.removeChild(a.f.childNodes[0]);a.a=WM(a.l.a)},mN=function(a,b){lN(a.g);a.l.unshift(b);
8
- for(const c of a.l)a.g.append(c)},nN=function(a,b,c){a=a.f;const d=a.viewportAnchorUnits;if(d===_.mr)return a.viewportAnchorY/100*c-a.regionAnchorY/100*b;if(0===d)return a.viewportAnchorY-a.regionAnchorY;throw Error(DM);},pN=function(a,b,c,d){const e=document.createElement(_.vf),f=e.dataset;f.name=b;f.for=c;d&&(f.name=`${b} (sandbox)`,f.sandbox=!0);c=document.head;c.appendChild(e);oN(a,c,b);a.h.debug(`Created HTML style element #${b}.`);return e.sheet},qN=function(a,b){a=`.${a.j} .clpp-text-container`;
9
- const c=`${a} .clpp-text-cue`;return b=b.replace(/::cue\((#[^)]+)\)/g,`${a} $1`).replace(/::cue\(([^)]+)\)/g,`${c} $1`).replace(/::cue-region\(([^)]+)\)/g,`${a} $1 .clpp-text-cue`).replace(/::cue/g,c).replace(/::cue-region/g,`${a} .clpp-text-cue-region .clpp-text-cue`).replace(/::ttml/g,a)},rN=function(a,b){let c=!1;try{a.f.insertRule(b,0);const d=a.f.cssRules[0];d instanceof CSSStyleRule&&(c=d.selectorText.split(",").every(e=>0===e.trim().indexOf(`.${a.j} `)))}catch(d){}0<a.f.cssRules.length&&a.f.deleteRule(0);
10
- return c},sN=function(a){if(null!=a.a){for(;0<a.a.cssRules.length;)a.a.deleteRule(0);a.l=[]}},oN=function(a,b,c){const d=new MutationObserver(e=>{e.forEach(f=>{f.removedNodes.forEach(g=>{g.id===c&&a.h.error(`PRESTOplay HTML style element #${c} has `+"been unexpectedly removed! Some styles will not work!")})})});d.observe(b,{subtree:!1,childList:!0});a.o.push(()=>d.disconnect())},tN=function(a){a=_.tg(a.getConfiguration().htmlcue||{});_.B(a.stretchSmpteImage)&&(a.stretchSmpteImage=!1);_.B(a.enableResizeObserver)&&
11
- (a.enableResizeObserver=!0);return a},zN=function(a,b){if((b||a.l)&&a.F){var c=a.m.getPosition();if(b||a.J!==c&&a.m.getState()===_.nn)if(a.J=c,c=uN(a,c),b||(b=a.o,b=!(null===b&&null===c||null!==b&&null!==c&&b.start===c.start&&b.end===c.end)),b&&(a.o=c,vN(a),c)){b={color:a.getFontColor()||void 0,backgroundColor:a.getBackgroundColor()||void 0,fontFamily:a.getFontFamily()||void 0,textShadow:_.Wq(a)||void 0};c=a.f.slice(c.start,c.end+1);for(const k of c){c=a;var d=k,e=b,f=c.a.a,g=null;switch(d.payloadType){case _.Yf:g=
12
- "clpp-text-vtt";break;case _.Cf:g=FM;break;case _.dr:g=EM}g&&!f.classList.contains(g)&&_.In(f,g);f=WM(c.a.a);if(0===f.width||0===f.height)c.h.warn("The height or width of the `.clpp-text-container` element is zero. Captions will not be displayed. Please check if the `clpp.styles.css` file has been included.");else{OM({fontSize:wN(c,d.containerRows)},c.a.a);f=null;g=d.payloadType===_.Yf;var h=d.payloadType===_.Cf;d.region&&(g||h||d.backgroundImage)&&(c.B.has(d.region.id)?f=c.B.get(d.region.id):(f=
13
- new xN(d.region,{}),c.B.set(d.region.id,f),mN(c.a,f)));d=new yN(d,c.M,e);f?mN(f,d):mN(c.a,d)}}}}},AN=function(a){vN(a);a.J=null;a.o=null;a.f=[]},BN=function(a,b){return a.startTime<=b&&a.endTime>b},uN=function(a,b){var c=KM(a.f,d=>BN(d,b)?0:b!==d.startTime?b-d.startTime:b-d.endTime);if(-1===c)return null;{let d=c;for(;0<=d-1&&BN(a.f[d-1],b);)d--;for(;c+1<a.f.length&&BN(a.f[c+1],b);)c++;return{start:d,end:c}}},vN=function(a){a.B.clear();if(a.a){const b=a.a.a;b.classList.remove("clpp-text-vtt");b.classList.remove(FM);
14
- b.classList.remove(EM);a=a.a;lN(a.g);a.l=[]}},wN=function(a,b){const c=WM(a.a.a).height;if(null!==a.I)return a.getFontSize();if(null!==a.C)return a=a.getFontSizePercent(),`${Math.round(c*a)}px`;if(typeof b===_.r&&0<b)return`${Math.round(c/b)}px`;a=a.getFontSizePercent();return`${Math.round(c*a)}px`},FN=class{parse(a){a={input:a};const b=_.Kn(_.yd),c=[];let d=b;for(var e;null!==(e=LM(a));)if("\x3c"===e[0])if("/"===e[1])c.length&&c[c.length-1]===e.substr(2).replace("\x3e","")&&(c.pop(),d=d.parentNode);
15
- else{if(e=e.match(/^<([^.\s/0-9>]+)(\.[^\s\\>]+)?([^>\\]+)?(\\?)>?$/)){var f=e[1];var g=e[3];var h=CN[f];h?(h=_.Kn(h),(f=DN[f])&&g&&h.setAttribute(f,g.trim()),g=h):g=null;!g||EN[g.localName]&&EN[g.localName]!==d.localName||(e[2]&&(g.className=e[2].substr(1).replace(/\./g," ")),c.push(e[1]),d.appendChild(g),d=g)}}else d.appendChild(document.createTextNode(NM(e)));return b}},CN={c:"c",i:"i",b:"b",u:"u",ruby:"ruby",rt:"rt",v:"v",lang:"lang"},DN={v:"voice",lang:"lang"},EN={rt:"ruby"},MM={"\x26amp;":"\x26",
16
- "\x26lt;":"\x3c","\x26gt;":"\x3e","\x26lrm;":"\u200e","\x26rlm;":"\u200f","\x26nbsp;":"\u00a0"};var VM=class{constructor(a,b,c,d,e,f){this.left=a;this.f=b;this.top=c;this.a=d;this.height=e;this.width=f}};var GN=class{constructor(a,b,c){this.id=a;this.w=b;this.B=c;this.a=this.o();this.j=!1}init(){this.j=!0}A(){return!1}};var yN=class extends GN{constructor(a,b,c){super(a.id,"clpp-text-cue",{});this.l=b;this.f=a;this.g=!!this.f.backgroundImage;this.C=c}A(){return!this.g&&!(this.f.region&&this.f.region.displayAlign)}init(a){super.init(a);if(this.g)_.In(this.a,"clpp-text-cue-image"),this.a.style.backgroundImage=`url("${this.f.backgroundImage}")`,this.l.stretchSmpteImage&&(this.a.style.backgroundSize="contain");else if(a){var b=this.f;if(b.payloadType===_.Cf){var c=_.Kn(_.yd);c.innerHTML=b.payload;b=c}else b.payloadType===
17
- _.Yf?b=(new FN).parse(b.payload):(c=_.Kn(_.yd),c.textContent=b.payload,b=c);_.In(b,this.w);this.id&&(b.id=this.id);for(d of this.f.cssClassList)_.In(b,d);OM({writingMode:cN(this)},b);var d=b;this.a.appendChild(d);_.In(this.a,"clpp-text-wrapper");for(var e of this.f.cssClassList)_.In(this.a,`clpp-text-wrapper__${e}`);_.B(this.f.line)&&(this.f.lineInterpretation=_.gr,this.f.line=aN(this)?-1:0);e=cN(this);OM({writingMode:e,webkitWritingMode:e,direction:HM,textAlign:dN(this)},this.a);if(!this.f.region||
18
- !this.f.region.displayAlign){e=eN(this,fN(this));OM({position:"absolute",left:iN(this,e,null),right:hN(this)&&_.B(null)?QM(0,_.$e):HM,top:jN(this,e,null),width:aN(this)?QM(this.f.size,"%"):HM,height:gN(this)||hN(this)?QM(this.f.size,"%"):HM},this.a);b=this.f;a=aN(this)?a.height:a.width;c=bN(this);if(b.lineInterpretation===_.gr){var f=c*Math.round(b.line);Math.abs(f)>a&&(f=c*(0>b.line?0:-1));0>f&&(f+=a)}else{f=c/a*100;let g=b.line;switch(b.lineAlign){case _.Tc:g-=f/2;break;case _.Kd:g-=f}f=Math.round(g/
19
- 100*a)}hN(this)&&(f=a-f-c);a=f;OM({left:iN(this,e,a),right:hN(this)&&_.B(a)?QM(0,_.$e):HM,top:jN(this,e,a)},this.a)}PM(this.C,d)}}o(){return _.Kn(_.yd)}};var HN=class{constructor(a,b){this.l=a;this.f=a.a;this.j=void 0===b?!1:b;this.a=WM(a.a);this.g=[]}append(a){const b=a.a;b.style.visibility=_.Qd;this.f.appendChild(b);a.j||a.init(this.a);if(a.A()){a:{var c=WM(a.a);var d=kN(this,a.f),e=bN(a);const g=XM(c);let h=null,k=0;for(const l of d){for(;$M(c,this.a,l)||ZM(c,this.a)&&YM(c,this.g);){d=c;var f=e;switch(l){case "+x":d.left+=f;d.f+=f;break;case "-x":d.left-=f;d.f-=f;break;case "+y":d.top+=f;d.a+=f;break;case "-y":d.top-=f,d.a-=f}}if(this.j||ZM(c,this.a))break a;
20
- d=this.a;d=Math.max(0,Math.min(c.f,d.f)-Math.max(c.left,d.left))*Math.max(0,Math.min(c.a,d.a)-Math.max(c.top,d.top))/(c.height*c.width);d>k&&(h=XM(c),k=d);c=XM(g)}c=h||g}OM({top:QM(c.top-this.a.top,_.$e),bottom:QM(this.a.a-c.a,_.$e),left:QM(c.left-this.a.left,_.$e),right:QM(this.a.f-c.f,_.$e),height:QM(c.height,_.$e),width:QM(c.width,_.$e)},a.a)}b.style.visibility="visible";this.g.push(WM(a.a))}};var IN=class extends GN{constructor(a,b,c){super(a,b,c);this.g=null;this.l=[]}init(){this.g=new HN(this);this.j=!0}o(){const a=_.Kn(_.yd);_.In(a,this.w);this.id&&(a.id=this.id);return a}};var xN=class extends IN{constructor(a,b){super(a.id,"clpp-text-cue-region",b);this.f=a}init(a){a:{var b=this.f;switch(b.widthUnits){case 0:b=b.width;break a;case _.mr:b=b.width/100*a.width;break a;default:throw Error(DM);}}var c=this.f;var d=c.viewportAnchorUnits;if(d===_.mr)c=c.viewportAnchorX/100*a.width-c.regionAnchorX/100*b;else if(0===d)c=c.viewportAnchorX-c.regionAnchorX;else throw Error(DM);d=a.height;const e=nN(this,d,a.height);OM(this.B,this.a);OM({left:QM(c,_.$e),top:QM(e,_.$e),width:QM(b,
21
- _.$e),height:QM(d,_.$e)},this.a);this.f.writingMode&&OM({display:"flex","flex-direction":this.f.writingMode},this.a);this.f.displayAlign&&OM({"justify-content":this.f.displayAlign},this.a);for(var f of this.f.cssClassList)_.In(this.a,f);a:switch(f=this.f,f.heightUnits){case 0:f=f.height;break a;case _.mr:f=f.height/100*a.height;break a;case 2:f=f.height;c=new yN(new _.jr(0,1,"Lorem ipsum",_.dr),{},{});b=c.a;this.a.appendChild(b);c.init(WM(this.a));c=b.getBoundingClientRect().height;this.a.removeChild(b);
22
- b=c;f*=b;break a;default:throw Error(DM);}a=nN(this,f,a.height);OM({top:QM(a,_.$e),height:QM(f,_.$e)},this.a);this.g=new HN(this,!0);this.j=!0}getId(){return this.f.id}};var JN=class{constructor(a,b){this.h=new _.R("clpp.htmlcue.StyleManager");this.o=[];this.j=a.getSurface().getUniqueCssClass();this.g=b;this.l=[];this.a=pN(this,this.g,this.j);this.f=pN(this,this.g,this.j,!0);this.f.disabled=!0;this.h.debug(`Stylesheet ${this.g} has been created.`)}appendRule(a){if(null!=this.a&&!this.l.some(b=>b===a)){const b=qN(this,a);if(rN(this,b)){try{this.a.insertRule(b,this.a.cssRules.length),this.h.debug(`Added CSS rule ${b}`)}catch(c){this.h.error(`An error occurred when adding a CSS rule: ${b}`)}this.l.push(a)}else this.h.warn(`Stylesheet ${this.g} ignoring the CSS rule `+
23
- `because it's not safe: ${b}`)}}destroy(){const a=this;return _.x(function*(){null!=a.a&&(a.o.forEach(b=>b()),a.o=[],sN(a),document.head.removeChild(a.a.ownerNode),document.head.removeChild(a.f.ownerNode),a.a=null,a.f=null,a.h.debug(`Stylesheet ${a.g} has been destroyed.`))})}};var KN=class extends _.ct{constructor(a){super(a);this.h=new _.R(GM);this.m=a;this.M=tN(a);this.l=!1;this.f=[];this.F=a.getSurface().getContainer();this.j=new JN(a,"CLPP Subtitle Styles");this.a=new IN(null,"clpp-text-container",{});this.A=new _.Us(a.getSurface(),this.V.bind(this));this.J=null;this.F?(this.F.appendChild(this.a.a),this.a.init(null)):this.h.warn("No container element! Subtitles will not appear. Please check your player surface configuration or switch to NativeTextDisplayer.");this.G=
24
- new _.kj(()=>{zN(this)});this.B=new Map;this.o=null}append(a,b){if(null!=this.j&&0!==a.length){for(const c of b)this.j.appendRule(c);a.sort((c,d)=>c.startTime!==d.startTime?c.startTime-d.startTime:c.endTime-d.endTime);this.f=JM(this.f,IM(a));this.o=null;zN(this,!1)}}g(){null==this.j||zN(this,!0)}destroy(){const a=this;return _.x(function*(){null!=a.j&&(AN(a),a.G.stop(),yield a.j.destroy(),a.j=null,a.F.removeChild(a.a.a),a.a=null,a.A.stop(),a.A=null,a.l=!1)})}remove(a,b){if(null==this.j)return!1;this.f=
25
- this.f.filter(c=>c.startTime<a||c.endTime>=b);this.o=null;zN(this,!0);return!0}isTextVisible(){return this.l}setTextVisibility(a){null!=this.j&&this.l!==a&&((this.l=a)?(this.G.$a(.25),this.M.enableResizeObserver&&this.A.start(),zN(this,!0)):(this.G.stop(),this.A.stop(),AN(this)))}Nc(){return this.f}V(){zN(this,!0)}};_.z(GM,KN);KN.prototype.setTextVisibility=KN.prototype.setTextVisibility;KN.prototype.isTextVisible=KN.prototype.isTextVisible;KN.prototype.remove=KN.prototype.remove;
26
- KN.prototype.destroy=KN.prototype.destroy;KN.prototype.append=KN.prototype.append;var LN=class{da(a){return!!a.enableHtmlCue&&!_.Aj()}create(a){return new KN(a)}};_.z("clpp.htmlcue.HtmlCueComponent",class extends _.Ds{f(){_.Rm(_.Rd,new LN)}a(){_.Pm.has(_.Rd)&&(_.Pm.delete(_.Rd),_.Qm.info("Removed factory: 'html'"))}id(){return _.wf}});};f.call(g, window);
1
+ import {clpp} from "./cl.core.js";let g={};const _ = clpp._;var f=function(window){'use strict';var OM="Unsupported unit",PM="clpp-text-plain",QM="clpp-text-ttml",RM="clpp.htmlcue.HtmlTextDisplayer",SM="initial",TM=function(a){return _.hh(a,{Ne:(b,c)=>b.md(c)})},UM=function(a,b){if(0===b.length)return a;let c=a;a=a.findIndex(d=>d.startTime>=b[0].startTime);0<=a&&(c=c.slice(0,a));return c.concat(b)},VM=function(a,b){let c=0,d=a.length-1;for(;c<=d;){const e=c+d>>1,f=b(a[e]);if(0===f)return e;0<f?c=e+1:d=e-1}return-1},WM=function(a){if(!a.input)return null;var b=a.input.match(/^([^<]*)(<[^>]+>?)?/);
2
+ b=b[1]?b[1]:b[2];a.input=a.input.substr(b.length);return b},YM=function(a){let b=null;for(;b=a.match(/&(amp|lt|gt|lrm|rlm|nbsp);/);)a=a.replace(b[0],c=>XM[c]);return a},$M=function(a,b){ZM(a,b);Array.from(b.getElementsByTagName("*")).forEach(c=>{ZM(a,c)})},ZM=function(a,b){for(const c in a)null!=a[c]&&(b.style[c]=a[c])},aN=function(a,b){return 0===a?"0":a+b},bN=function(a,b){return 1>Math.abs(a-b)||a<b},cN=function(a,b){return a<b&&1<Math.abs(a-b)},dN=function(a,b){return a>b&&1<Math.abs(a-b)},eN=
3
+ function(a,b){return 1>Math.abs(a-b)||a>b},gN=function(a){const b=a.getBoundingClientRect();var c=getComputedStyle(a,null);const d=parseFloat(c.getPropertyValue("border-left-width"))||0,e=parseFloat(c.getPropertyValue("border-right-width"))||0;var f=parseFloat(c.getPropertyValue("border-top-width"))||0;c=parseFloat(c.getPropertyValue("border-bottom-width"))||0;const g=(b.top||a.offsetTop)+f;f=(b.height||a.offsetHeight)-f-c;return new fN(b.left+d,b.right+e,g,(b.bottom||g+f)+c,f,(b.width||a.offsetWidth)-
4
+ d-e)},hN=function(a){return new fN(a.left,a.f,a.top,a.a,a.height,a.width)},iN=function(a,b){return b.some(c=>cN(a.left,c.f)&&dN(a.f,c.left)&&cN(a.top,c.a)&&dN(a.a,c.top))},jN=function(a,b){return eN(a.top,b.top)&&bN(a.a,b.a)&&eN(a.left,b.left)&&bN(a.f,b.f)},kN=function(a,b,c){switch(c){case "+x":return cN(a.left,b.left);case "-x":return dN(a.f,b.f);case "+y":return cN(a.top,b.top);case "-y":return dN(a.a,b.a);default:throw Error("Unknown axis");}},lN=function(a){return a.f.writingMode===_.lr},mN=
5
+ function(a){var b=a.a.childNodes[0],c=a.a.getBoundingClientRect();const d=b.getClientRects();b=c.height/d.length;c=c.width/d.length;return lN(a)?b:c},nN=function(a){switch(a.f.writingMode){case _.lr:return"horizontal-tb";case _.Mf:return _.Mf;case _.Nf:return _.Nf;default:throw Error("Unknown writing mode");}},oN=function(a){switch(a.f.positionAlign){case _.de:return _.Xd;case "auto":case _.Tc:return _.kr;case _.ee:return _.hf}return a.f.textAlign},pN=function(a,b){if(typeof a.f.position===_.r&&typeof a.f.size===
6
+ _.r)switch(b){case _.de:return a.f.position;case "auto":case _.Tc:return a.f.position-a.f.size/2;case _.ee:return a.f.position-a.f.size}return 0},qN=function(a){if(!a.f.positionAlign)switch(a.f.textAlign){case _.Xd:case _.Xd:return _.de;case _.kr:return _.Tc;case _.hf:case _.hf:return _.ee}return a.f.positionAlign},tN=function(a,b,c){return(rN(a)||sN(a))&&_.Bg(c)?aN(c,_.af):rN(a)&&_.B(c)?aN(0,_.af):lN(a)&&_.Bg(b)?aN(b,"%"):SM},uN=function(a,b,c){return lN(a)&&_.Bg(c)?aN(c,_.af):(rN(a)||sN(a))&&_.Bg(b)?
7
+ aN(b,"%"):SM},sN=function(a){return a.f.writingMode===_.Nf},rN=function(a){return a.f.writingMode===_.Mf},vN=function(a,b){if(a.j)switch(b.writingMode){case _.lr:return["-y"];case _.Mf:return["+x"];case _.Nf:return["-x"]}a=[];switch(b.writingMode){case _.lr:a=["+y","-y"];break;case _.Mf:a=["+x","-x"];break;case _.Nf:a=["-x","+x"]}0>b.line&&(a=a.reverse());return a},wN=function(a){for(a.g=[];0<a.f.childNodes.length;)a.f.removeChild(a.f.childNodes[0]);a.a=gN(a.l.a)},xN=function(a,b){wN(a.g);a.l.unshift(b);
8
+ for(const c of a.l)a.g.append(c)},yN=function(a,b,c){a=a.f;const d=a.viewportAnchorUnits;if(d===_.sr)return a.viewportAnchorY/100*c-a.regionAnchorY/100*b;if(0===d)return a.viewportAnchorY-a.regionAnchorY;throw Error(OM);},AN=function(a,b,c,d){const e=document.createElement(_.wf),f=e.dataset;f.name=b;f.for=c;d&&(f.name=`${b} (sandbox)`,f.sandbox=!0);c=document.head;c.appendChild(e);zN(a,c,b);a.h.debug(`Created HTML style element #${b}.`);return e.sheet},BN=function(a,b){a=`.${a.j} .clpp-text-container`;
9
+ const c=`${a} .clpp-text-cue`;return b=b.replace(/::cue\((#[^)]+)\)/g,`${a} $1`).replace(/::cue\(([^)]+)\)/g,`${c} $1`).replace(/::cue-region\(([^)]+)\)/g,`${a} $1 .clpp-text-cue`).replace(/::cue/g,c).replace(/::cue-region/g,`${a} .clpp-text-cue-region .clpp-text-cue`).replace(/::ttml/g,a)},CN=function(a,b){let c=!1;try{a.f.insertRule(b,0);const d=a.f.cssRules[0];d instanceof CSSStyleRule&&(c=d.selectorText.split(",").every(e=>0===e.trim().indexOf(`.${a.j} `)))}catch(d){}0<a.f.cssRules.length&&a.f.deleteRule(0);
10
+ return c},DN=function(a){if(null!=a.a){for(;0<a.a.cssRules.length;)a.a.deleteRule(0);a.l=[]}},zN=function(a,b,c){const d=new MutationObserver(e=>{e.forEach(f=>{f.removedNodes.forEach(g=>{g.id===c&&a.h.error(`PRESTOplay HTML style element #${c} has `+"been unexpectedly removed! Some styles will not work!")})})});d.observe(b,{subtree:!1,childList:!0});a.o.push(()=>d.disconnect())},EN=function(a){a=_.ug(a.getConfiguration().htmlcue||{});_.B(a.stretchSmpteImage)&&(a.stretchSmpteImage=!1);_.B(a.enableResizeObserver)&&
11
+ (a.enableResizeObserver=!0);return a},KN=function(a,b){if((b||a.l)&&a.F){var c=a.m.getPosition();if(b||a.J!==c&&a.m.getState()===_.qn)if(a.J=c,c=FN(a,c),b||(b=a.o,b=!(null===b&&null===c||null!==b&&null!==c&&b.start===c.start&&b.end===c.end)),b&&(a.o=c,GN(a),c)){b={color:a.getFontColor()||void 0,backgroundColor:a.getBackgroundColor()||void 0,fontFamily:a.getFontFamily()||void 0,textShadow:_.br(a)||void 0};c=a.f.slice(c.start,c.end+1);for(const k of c){c=a;var d=k,e=b,f=c.a.a,g=null;switch(d.payloadType){case _.Zf:g=
12
+ "clpp-text-vtt";break;case _.Df:g=QM;break;case _.jr:g=PM}g&&!f.classList.contains(g)&&_.Ln(f,g);f=gN(c.a.a);if(0===f.width||0===f.height)c.h.warn("The height or width of the `.clpp-text-container` element is zero. Captions will not be displayed. Please check if the `clpp.styles.css` file has been included.");else{ZM({fontSize:HN(c,d.containerRows)},c.a.a);f=null;g=d.payloadType===_.Zf;var h=d.payloadType===_.Df;d.region&&(g||h||d.backgroundImage)&&(c.B.has(d.region.id)?f=c.B.get(d.region.id):(f=
13
+ new IN(d.region,{}),c.B.set(d.region.id,f),xN(c.a,f)));d=new JN(d,c.M,e);f?xN(f,d):xN(c.a,d)}}}}},LN=function(a){GN(a);a.J=null;a.o=null;a.f=[]},MN=function(a,b){return a.startTime<=b&&a.endTime>b},FN=function(a,b){var c=VM(a.f,d=>MN(d,b)?0:b!==d.startTime?b-d.startTime:b-d.endTime);if(-1===c)return null;{let d=c;for(;0<=d-1&&MN(a.f[d-1],b);)d--;for(;c+1<a.f.length&&MN(a.f[c+1],b);)c++;return{start:d,end:c}}},GN=function(a){a.B.clear();if(a.a){const b=a.a.a;b.classList.remove("clpp-text-vtt");b.classList.remove(QM);
14
+ b.classList.remove(PM);a=a.a;wN(a.g);a.l=[]}},HN=function(a,b){const c=gN(a.a.a).height;if(null!==a.I)return a.getFontSize();if(null!==a.C)return a=a.getFontSizePercent(),`${Math.round(c*a)}px`;if(typeof b===_.r&&0<b)return`${Math.round(c/b)}px`;a=a.getFontSizePercent();return`${Math.round(c*a)}px`},QN=class{parse(a){a={input:a};const b=_.Nn(_.zd),c=[];let d=b;for(var e;null!==(e=WM(a));)if("\x3c"===e[0])if("/"===e[1])c.length&&c[c.length-1]===e.substr(2).replace("\x3e","")&&(c.pop(),d=d.parentNode);
15
+ else{if(e=e.match(/^<([^.\s/0-9>]+)(\.[^\s\\>]+)?([^>\\]+)?(\\?)>?$/)){var f=e[1];var g=e[3];var h=NN[f];h?(h=_.Nn(h),(f=ON[f])&&g&&h.setAttribute(f,g.trim()),g=h):g=null;!g||PN[g.localName]&&PN[g.localName]!==d.localName||(e[2]&&(g.className=e[2].substr(1).replace(/\./g," ")),c.push(e[1]),d.appendChild(g),d=g)}}else d.appendChild(document.createTextNode(YM(e)));return b}},NN={c:"c",i:"i",b:"b",u:"u",ruby:"ruby",rt:"rt",v:"v",lang:"lang"},ON={v:"voice",lang:"lang"},PN={rt:"ruby"},XM={"\x26amp;":"\x26",
16
+ "\x26lt;":"\x3c","\x26gt;":"\x3e","\x26lrm;":"\u200e","\x26rlm;":"\u200f","\x26nbsp;":"\u00a0"};var fN=class{constructor(a,b,c,d,e,f){this.left=a;this.f=b;this.top=c;this.a=d;this.height=e;this.width=f}};var RN=class{constructor(a,b,c){this.id=a;this.w=b;this.B=c;this.a=this.o();this.j=!1}init(){this.j=!0}A(){return!1}};var JN=class extends RN{constructor(a,b,c){super(a.id,"clpp-text-cue",{});this.l=b;this.f=a;this.g=!!this.f.backgroundImage;this.C=c}A(){return!this.g&&!(this.f.region&&this.f.region.displayAlign)}init(a){super.init(a);if(this.g)_.Ln(this.a,"clpp-text-cue-image"),this.a.style.backgroundImage=`url("${this.f.backgroundImage}")`,this.l.stretchSmpteImage&&(this.a.style.backgroundSize="contain");else if(a){var b=this.f;if(b.payloadType===_.Df){var c=_.Nn(_.zd);c.innerHTML=b.payload;b=c}else b.payloadType===
17
+ _.Zf?b=(new QN).parse(b.payload):(c=_.Nn(_.zd),c.textContent=b.payload,b=c);_.Ln(b,this.w);this.id&&(b.id=this.id);for(d of this.f.cssClassList)_.Ln(b,d);ZM({writingMode:nN(this)},b);var d=b;this.a.appendChild(d);_.Ln(this.a,"clpp-text-wrapper");for(var e of this.f.cssClassList)_.Ln(this.a,`clpp-text-wrapper__${e}`);_.B(this.f.line)&&(this.f.lineInterpretation=_.mr,this.f.line=lN(this)?-1:0);e=nN(this);ZM({writingMode:e,webkitWritingMode:e,direction:SM,textAlign:oN(this)},this.a);if(!this.f.region||
18
+ !this.f.region.displayAlign){e=pN(this,qN(this));ZM({position:"absolute",left:tN(this,e,null),right:sN(this)&&_.B(null)?aN(0,_.af):SM,top:uN(this,e,null),width:lN(this)?aN(this.f.size,"%"):SM,height:rN(this)||sN(this)?aN(this.f.size,"%"):SM},this.a);b=this.f;a=lN(this)?a.height:a.width;c=mN(this);if(b.lineInterpretation===_.mr){var f=c*Math.round(b.line);Math.abs(f)>a&&(f=c*(0>b.line?0:-1));0>f&&(f+=a)}else{f=c/a*100;let g=b.line;switch(b.lineAlign){case _.Tc:g-=f/2;break;case _.Ld:g-=f}f=Math.round(g/
19
+ 100*a)}sN(this)&&(f=a-f-c);a=f;ZM({left:tN(this,e,a),right:sN(this)&&_.B(a)?aN(0,_.af):SM,top:uN(this,e,a)},this.a)}$M(this.C,d)}}o(){return _.Nn(_.zd)}};var SN=class{constructor(a,b){this.l=a;this.f=a.a;this.j=void 0===b?!1:b;this.a=gN(a.a);this.g=[]}append(a){const b=a.a;b.style.visibility=_.Rd;this.f.appendChild(b);a.j||a.init(this.a);if(a.A()){a:{var c=gN(a.a);var d=vN(this,a.f),e=mN(a);const g=hN(c);let h=null,k=0;for(const l of d){for(;kN(c,this.a,l)||jN(c,this.a)&&iN(c,this.g);){d=c;var f=e;switch(l){case "+x":d.left+=f;d.f+=f;break;case "-x":d.left-=f;d.f-=f;break;case "+y":d.top+=f;d.a+=f;break;case "-y":d.top-=f,d.a-=f}}if(this.j||jN(c,this.a))break a;
20
+ d=this.a;d=Math.max(0,Math.min(c.f,d.f)-Math.max(c.left,d.left))*Math.max(0,Math.min(c.a,d.a)-Math.max(c.top,d.top))/(c.height*c.width);d>k&&(h=hN(c),k=d);c=hN(g)}c=h||g}ZM({top:aN(c.top-this.a.top,_.af),bottom:aN(this.a.a-c.a,_.af),left:aN(c.left-this.a.left,_.af),right:aN(this.a.f-c.f,_.af),height:aN(c.height,_.af),width:aN(c.width,_.af)},a.a)}b.style.visibility="visible";this.g.push(gN(a.a))}};var TN=class extends RN{constructor(a,b,c){super(a,b,c);this.g=null;this.l=[]}init(){this.g=new SN(this);this.j=!0}o(){const a=_.Nn(_.zd);_.Ln(a,this.w);this.id&&(a.id=this.id);return a}};var IN=class extends TN{constructor(a,b){super(a.id,"clpp-text-cue-region",b);this.f=a}init(a){a:{var b=this.f;switch(b.widthUnits){case 0:b=b.width;break a;case _.sr:b=b.width/100*a.width;break a;default:throw Error(OM);}}var c=this.f;var d=c.viewportAnchorUnits;if(d===_.sr)c=c.viewportAnchorX/100*a.width-c.regionAnchorX/100*b;else if(0===d)c=c.viewportAnchorX-c.regionAnchorX;else throw Error(OM);d=a.height;const e=yN(this,d,a.height);ZM(this.B,this.a);ZM({left:aN(c,_.af),top:aN(e,_.af),width:aN(b,
21
+ _.af),height:aN(d,_.af)},this.a);this.f.writingMode&&ZM({display:"flex","flex-direction":this.f.writingMode},this.a);this.f.displayAlign&&ZM({"justify-content":this.f.displayAlign},this.a);for(var f of this.f.cssClassList)_.Ln(this.a,f);a:switch(f=this.f,f.heightUnits){case 0:f=f.height;break a;case _.sr:f=f.height/100*a.height;break a;case 2:f=f.height;c=new JN(new _.pr(0,1,"Lorem ipsum",_.jr),{},{});b=c.a;this.a.appendChild(b);c.init(gN(this.a));c=b.getBoundingClientRect().height;this.a.removeChild(b);
22
+ b=c;f*=b;break a;default:throw Error(OM);}a=yN(this,f,a.height);ZM({top:aN(a,_.af),height:aN(f,_.af)},this.a);this.g=new SN(this,!0);this.j=!0}getId(){return this.f.id}};var UN=class{constructor(a,b){this.h=new _.R("clpp.htmlcue.StyleManager");this.o=[];this.j=a.getSurface().getUniqueCssClass();this.g=b;this.l=[];this.a=AN(this,this.g,this.j);this.f=AN(this,this.g,this.j,!0);this.f.disabled=!0;this.h.debug(`Stylesheet ${this.g} has been created.`)}appendRule(a){if(null!=this.a&&!this.l.some(b=>b===a)){const b=BN(this,a);if(CN(this,b)){try{this.a.insertRule(b,this.a.cssRules.length),this.h.debug(`Added CSS rule ${b}`)}catch(c){this.h.error(`An error occurred when adding a CSS rule: ${b}`)}this.l.push(a)}else this.h.warn(`Stylesheet ${this.g} ignoring the CSS rule `+
23
+ `because it's not safe: ${b}`)}}destroy(){const a=this;return _.x(function*(){null!=a.a&&(a.o.forEach(b=>b()),a.o=[],DN(a),document.head.removeChild(a.a.ownerNode),document.head.removeChild(a.f.ownerNode),a.a=null,a.f=null,a.h.debug(`Stylesheet ${a.g} has been destroyed.`))})}};var VN=class extends _.gt{constructor(a){super(a);this.h=new _.R(RM);this.m=a;this.M=EN(a);this.l=!1;this.f=[];this.F=a.getSurface().getContainer();this.j=new UN(a,"CLPP Subtitle Styles");this.a=new TN(null,"clpp-text-container",{});this.A=new _.$s(a.getSurface(),this.V.bind(this));this.J=null;this.F?(this.F.appendChild(this.a.a),this.a.init(null)):this.h.warn("No container element! Subtitles will not appear. Please check your player surface configuration or switch to NativeTextDisplayer.");this.G=
24
+ new _.lj(()=>{KN(this)});this.B=new Map;this.o=null}append(a,b){if(null!=this.j&&0!==a.length){for(const c of b)this.j.appendRule(c);a.sort((c,d)=>c.startTime!==d.startTime?c.startTime-d.startTime:c.endTime-d.endTime);this.f=UM(this.f,TM(a));this.o=null;KN(this,!1)}}g(){null==this.j||KN(this,!0)}destroy(){const a=this;return _.x(function*(){null!=a.j&&(LN(a),a.G.stop(),yield a.j.destroy(),a.j=null,a.F.removeChild(a.a.a),a.a=null,a.A.stop(),a.A=null,a.l=!1)})}remove(a,b){if(null==this.j)return!1;this.f=
25
+ this.f.filter(c=>c.startTime<a||c.endTime>=b);this.o=null;KN(this,!0);return!0}isTextVisible(){return this.l}setTextVisibility(a){null!=this.j&&this.l!==a&&((this.l=a)?(this.G.$a(.25),this.M.enableResizeObserver&&this.A.start(),KN(this,!0)):(this.G.stop(),this.A.stop(),LN(this)))}Nc(){return this.f}V(){KN(this,!0)}};_.z(RM,VN);VN.prototype.setTextVisibility=VN.prototype.setTextVisibility;VN.prototype.isTextVisible=VN.prototype.isTextVisible;VN.prototype.remove=VN.prototype.remove;
26
+ VN.prototype.destroy=VN.prototype.destroy;VN.prototype.append=VN.prototype.append;var WN=class{da(a){return!!a.enableHtmlCue&&!_.Bj()}create(a){return new VN(a)}};_.z("clpp.htmlcue.HtmlCueComponent",class extends _.Js{f(){_.Um(_.Sd,new WN)}a(){_.Sm.has(_.Sd)&&(_.Sm.delete(_.Sd),_.Tm.info("Removed factory: 'html'"))}id(){return _.xf}});};f.call(g, window);