import {clpp} from "./cl.core.js";let g={};const _ = clpp._;var f=function(window){'use strict';var EU=function(a){a.a.one(a.m,_.le,()=>DU(a))},DU=function(a){const b=a.m.getSurface().getMedia();if(b)if(a.h){a.a.on(b.textTracks,_.nc,d=>FU(a,d));var c=Array.from(b.textTracks);c.filter(d=>d.kind===_.se).forEach(d=>{FU(a,{track:d})});!GU(c)&&a.l&&(a.g.warn("The metadata track is not present. Changing an audio track in order to enforce the creation of the metadata track."),HU(a,b))}else a.g.warn("The clpp.ttml.TextParser class is not available. Please register the ttml component first.");
else a.g.warn("A video element is not available. Skipping.")},FU=function(a,b){b=b.track;b.kind===_.se&&(a.g.info("The metadata track has been added."),b.mode=_.$d,a.a.on(b,_.yd,c=>IU(a,c)))},GU=function(a){return a.some(b=>b.kind===_.se)},HU=function(a,b){const c=a.m.getTrackManager(),d=c.qa(),e=c.getAudioTracks().find(g=>g!==d);if(e){var f=()=>c.xa(d);a.a.on(b.textTracks,_.nc,g=>{g.track.kind===_.se&&(a.a.off(b.textTracks,_.nc,f),c.xa(d))});c.xa(e)}else a.g.warn("Can't enforce the creation of the metadata track if single audio track. Skipping.")},
IU=function(a,b){const c=JU(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 KU(d);if(e.f===c&&null!==e.a){a.f=d;d=a.h.parseMedia(_.Yi(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)}}})},JU=function(a){return(a=a.m.getTrackManager().wa())&&a.language&&a.language.toLowerCase()},
KU=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(_.ch(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=_.ch(a)?a:null}}};var LU=class{constructor(a,b,c){this.m=a;this.l=b;this.j=c;this.a=new _.Nt;this.h=(a=_.zt(_.xc))?new a(this.m.getConfiguration()):null;this.g=new _.S("clpp.hlssmpte.ImageCueHandler");this.f=null;EU(this)}destroy(){this.a.release();this.f=null;return Promise.resolve()}};var MU=class extends _.Pv{constructor(){super();this.a=null;this.f=!1}onPlayerCreated(){}onContentWillLoad(a){if(this.f=_.Fk()){var b=a.getConfiguration();b=_.Xg(b.hlssmpte||{});typeof b.patchMetadataTrack!==_.Lc&&(b.patchMetadataTrack=!1);_.dh(b.timestampOffset)||(b.timestampOffset=0);this.a=new LU(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",MU);
MU.Id="hlssmpte";_.Ir(new class{create(){return new MU}});};f.call(g, window);