@byomakase/omakase-player 0.2.0 → 0.2.1

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.
@@ -44,7 +44,7 @@ ${Ll(i)}`)}),e.join(`
44
44
  `)}function ym(r){let e=0;return r.forEach(t=>{t.duration>e&&(e=t.duration)}),e}function bm(r){const e=[];return r.forEach(t=>{e.push(_m(t))}),e.join(`
45
45
 
46
46
  `)}function _m(r){const e=[];r.identifier&&e.push(r.identifier);const t=Ca(r.start),i=Ca(r.end),s=r.styles?`${r.styles}`:"";return e.push(`${t} --> ${i} ${s}`),e.push(r.text),e.join(`
47
- `)}function Ca(r){const e=(r%1).toFixed(3);r=Math.round(r-e);const t=Math.floor(r/3600),i=Math.floor((r-t*3600)/60),s=r-t*3600-i*60;return`${`${gr(t,2)}:`}${gr(i,2)}:${gr(s,2)}.${gr(e*1e3,3)}`}var wm={hlsSegment:mm,hlsSegmentPlaylist:gm};const Sm=Pl.parse,Tm=dm.compile,Cm=Ol.segment,Em=wm;var km={parse:Sm,compile:Tm,segment:Cm,hls:Em};class bn{constructor(e,t){this.cues=new Map,this.cuesKeysSorted=[],this.url=e,this.axiosConfig=t}fetch(){return Ki(Qp(this.getUrl(),this.axiosConfig)).pipe(ke(e=>{let t=e.data;try{return km.parse(t,{strict:!0,meta:!0}).cues.forEach(s=>{let n=this.mapCue(s);this.cues.set(n.startTime,n),this.cuesKeysSorted.push(n.startTime)}),this.cuesKeysSorted.sort((s,n)=>s-n),!0}catch(i){return console.error(i),!1}}))}getUrl(){return this.url}hasCues(){return this.cues&&this.cues.size>0}findCue(e){let t=this.findCues(e,e);if(t&&t.length===1)return t[0]}findCues(e,t){let i=this.findCueIndex(e),s=this.findCueIndex(t);return s===-1?[]:this.cuesKeysSorted.slice(i,s+1).map(n=>this.cues.get(n))}getCues(){return[...this.cues.values()]}findCueIndex(e){let t=0,i=this.cuesKeysSorted.length-1;for(;t<=i;){const s=Math.floor((t+i)/2);if(this.cuesKeysSorted[s]===e)return s;this.cuesKeysSorted[s]<e?t=s+1:i=s-1}return i===-1&&(i=0),i}}class _n extends bn{constructor(e,t){super(e,t)}static create(e,t){let i=new _n(e,t);return i.fetch().pipe(ke(s=>i))}mapCue(e){return{id:e.identifier,startTime:new Z(e.start).toDecimalPlaces(3).toNumber(),endTime:new Z(e.end).toDecimalPlaces(3).toNumber(),text:e.text}}}const Ea={listening:!0,style:{height:20,fill:"rgba(255,73,145)",opacity:1,visible:!0}};class xm extends Je{constructor(e,t){super({...Ea,...e,style:{...Ea.style,...e.style}}),this.textTrackCue=this.config.textTrackCue,this.x=this.config.x,this.width=this.config.width,this.listening=this.config.listening,this.subtitlesLane=t,this.subtitlesLane.onSettleLayout$.pipe(I(this.onDestroy$)).subscribe(()=>{let i=this.subtitlesLane.resolveItemHorizontalMeasurement(this.getTextTrackCue());this.setHorizontalMeasurement(i)})}createCanvasNode(){return this.group=new A.Group({x:this.x,y:0,width:this.width,height:this.style.height,visible:this.style.visible,listening:this.listening}),this.backgroundRect=new A.Rect({x:0,y:0,width:this.group.width(),height:this.group.height(),fill:this.style.fill,opacity:this.style.opacity,perfectDrawEnabled:!1,shadowForStrokeEnabled:!1,hitStrokeWidth:0}),this.group.add(this.backgroundRect),this.group}onMeasurementsChange(){this.backgroundRect.size(this.group.getSize())}setPosition(e){this.x=e.x,this.isInitialized()&&this.group.position({x:this.x,y:0})}getPosition(){return this.group.getPosition()}getDimension(){return this.group.getSize()}getRect(){return{...this.getPosition(),...this.getDimension()}}getHorizontalMeasurement(){return{x:this.x,width:this.width}}setHorizontalMeasurement(e){this.x=e.x,this.width=e.width,this.isInitialized()&&this.group.setAttrs({x:this.x,width:this.width}),this.onMeasurementsChange()}setVisible(e){this.style={visible:e},this.isInitialized()&&this.group.visible(e)}getTextTrackCue(){return this.textTrackCue}setTextTrackCue(e){this.textTrackCue=e}compareTo(e){return this.textTrackCue&&e&&this.getTextTrackCue().id===e.getTextTrackCue().id&&this.getTextTrackCue().startTime===e.getTextTrackCue().startTime&&this.getTextTrackCue().endTime===e.getTextTrackCue().endTime?0:-1}}const Pm={...Qi,height:40,paddingTop:0,paddingBottom:0,subtitlesLaneItemOpacity:.9,subtitlesLaneItemFill:"rgba(255,73,145)"};class Us extends er{constructor(e){super({...e,style:{...Pm,...e.style}}),this.subtitlesLaneItemsMap=new Map,this.onSettleLayout$=new V,this._subtitlesVttUrl=this.config.subtitlesVttUrl}createCanvasNode(){return super.createCanvasNode(),this.timecodedGroup=new A.Group({...this.timelinePosition,width:this.timeline.getTimecodedGroupDimension().width,height:this.bodyGroup.height()}),this.timecodedEventCatcher=yi.createEventCatcher({width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.subtitlesLaneItemsGroup=new A.Group({...F.POSITION_TOP_LEFT,y:this.style.paddingTop,width:this.timecodedGroup.width(),height:this.timecodedGroup.height()-(this.style.paddingTop+this.style.paddingBottom)}),this.timecodedGroup.add(this.timecodedEventCatcher),this.timecodedGroup.add(this.subtitlesLaneItemsGroup),this.timeline.addToTimecodedSubtitlesGroup(this.timecodedGroup),this.bodyGroup}settleLayout(){super.settleLayout(),this.timecodedGroup.setAttrs({...this.timelinePosition});let e=this.timeline.getTimecodedGroupHorizontalMeasurement();[this.timecodedGroup,this.timecodedEventCatcher,this.subtitlesLaneItemsGroup].forEach(t=>{t.width(e.width)}),this.onSettleLayout$.next()}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.fetchAndCreateSubtitles()}clearContent(){this.subtitlesVttFile=void 0,this.clearItems()}clearItems(){this.subtitlesLaneItemsMap.forEach(e=>e.destroy()),this.subtitlesLaneItemsMap.clear(),this.subtitlesLaneItemsGroup.destroyChildren()}createEntities(){if(!this.isVttLoaded())return;this.clearItems(),this.subtitlesVttFile.getCues().forEach(t=>{let i=this.resolveItemHorizontalMeasurement(t),s=new xm({...i,textTrackCue:t,style:{height:this.subtitlesLaneItemsGroup.height(),fill:this.style.subtitlesLaneItemFill,opacity:this.style.subtitlesLaneItemOpacity}},this);this.subtitlesLaneItemsMap.set(t.startTime,s),this.subtitlesLaneItemsGroup.add(s.initCanvasNode())})}resolveItemHorizontalMeasurement(e){let t=this.timeline.constrainTimelinePosition(this.timeline.timeToTimelinePosition(e.startTime)),i=this.timeline.constrainTimelinePosition(this.timeline.timeToTimelinePosition(e.endTime));return{x:t,width:i-t}}fetchAndCreateSubtitles(){this.fetchSubtitlesVttFile(this._subtitlesVttUrl).pipe(ct(1)).subscribe(e=>{this.subtitlesVttFile=e,this.createEntities()})}fetchSubtitlesVttFile(e){return e?_n.create(e).pipe(ke(t=>t),gi((t,i)=>Ee(void 0))):Ee(void 0)}isVttLoaded(){return!!this.subtitlesVttFile}get subtitlesVttUrl(){return this._subtitlesVttUrl}set subtitlesVttUrl(e){this._subtitlesVttUrl=e,this.clearContent(),this.fetchAndCreateSubtitles()}}const Am={listening:!1,style:{...F.POSITION_TOP_LEFT,...F.DIMENSION_ZERO,stroke:"rgba(255,73,145)",strokeWidth:5,visible:!1}};class Zs extends Je{constructor(e){super(vi(e,Am)),this.onClick$=new V,this.onMouseOver$=new V,this.onMouseMove$=new V,this.onMouseOut$=new V,this.onMouseLeave$=new V,this.listening=this.config.listening}createCanvasNode(){return this.group=new A.Group({x:this.style.x,y:this.style.y,width:this.style.width,height:this.style.height,visible:this.style.visible,listening:this.listening}),this.backgroundRect=new A.Rect({x:0,y:0,width:this.group.width(),height:this.group.height(),strokeWidth:this.style.strokeWidth,stroke:this.style.stroke}),this.group.add(this.backgroundRect),this.group}afterCanvasNodeInit(){this.group.on("click",e=>{this.onClick$.next({thumbnail:this})}),this.group.on("mouseover",e=>{this.onMouseOver$.next({thumbnail:this})}),this.group.on("mousemove",e=>{this.onMouseMove$.next({thumbnail:this})}),this.group.on("mouseout",e=>{this.onMouseOut$.next({thumbnail:this})}),this.group.on("mouseleave",e=>{this.onMouseLeave$.next({thumbnail:this})})}destroy(){super.destroy()}onMeasurementsChange(){this.backgroundRect.size(this.group.getSize())}setImage(e){this.image&&this.image.destroy(),this.image=e,this.style={width:e.width(),height:e.height()},this.group.setAttrs({...this.image.getSize()}),this.backgroundRect.setAttrs({...this.image.getSize()}),this.group.add(this.image)}setVisible(e){this.style={visible:e},this.isInitialized()&&this.group.visible(e)}setPosition(e){this.style={...e},this.isInitialized()&&this.group.position(e)}setVisibleAndX(e,t){this.style={visible:e,x:t},this.isInitialized()&&this.group.setAttrs({visible:e,x:t})}getPosition(){return this.group.getPosition()}getDimension(){return this.group.getSize()}setDimension(e){this.style={...e},this.isInitialized()&&this.group.size(e),this.onMeasurementsChange()}getRect(){return{...this.getPosition(),...this.getDimension()}}getThumbnailVttCue(){return this.thumbnailVttCue}setThumbnailVttCue(e){this.thumbnailVttCue=e}getImage(){return this.image}compareTo(e){return this.thumbnailVttCue&&e&&this.thumbnailVttCue.url===e.thumbnailVttCue.url?0:-1}}class ss extends bn{constructor(e,t){super(e,t)}static create(e,t){let i=new ss(e,t);return i.fetch().pipe(ke(s=>i))}mapCue(e){return{id:e.identifier,startTime:new Z(e.start).toDecimalPlaces(3).toNumber(),endTime:new Z(e.end).toDecimalPlaces(3).toNumber(),text:e.text,url:this.resolveThumbnailUrl(e)}}resolveThumbnailUrl(e){return this.isUrlAbsolute(e.text)?e.text:this.createThumbnailUrlFromRelativeUrl(e.text)}createThumbnailUrlFromRelativeUrl(e){return this.url.lastIndexOf("/")>2?`${this.url.substring(0,this.url.lastIndexOf("/"))}/${e}`:e}isUrlAbsolute(e){return/^(http(s):\/\/.)[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/.test(e)}}class dt{static createKonvaImage(e){return new se(t=>{A.Image.fromURL(e,i=>{t.next(i),t.complete()},i=>{console.error(i),t.error(i)})})}static createKonvaImageSizedByWidth(e,t){return dt.createKonvaImage(e).pipe(ke(i=>(i.setAttrs({width:t,height:dt.calculateProportionalHeight(t,i)}),i)))}static createKonvaImageSizedByHeight(e,t){return dt.createKonvaImage(e).pipe(ke(i=>(i.setAttrs({width:dt.calculateProportionalWidth(t,i),height:t}),i)))}static calculateProportionalHeight(e,t){return e*t.getAttrs().image.naturalHeight/t.getAttrs().image.naturalWidth}static calculateProportionalWidth(e,t){return e*t.getAttrs().image.naturalWidth/t.getAttrs().image.naturalHeight}}const Om={...Qi,thumbnailHeight:40,thumbnailStroke:"rgba(121,0,255,0.9)",thumbnailStrokeWidth:0,thumbnailHoverScale:1.5,thumbnailHoverStroke:"rgba(0,255,188,0.9)",thumbnailHoverStrokeWidth:5};class js extends er{constructor(e){super({...e,style:{...Om,...e.style}}),this.thumbnailsMap=new Map,this.thumbnailsVisibleSet=new Set,this.onSettleLayout$=new V,this.eventStreamBreaker$=new V,this.onClick$=new V,this._thumbnailVttUrl=this.config.thumbnailVttUrl,this._axiosConfig=this.config.axiosConfig}createCanvasNode(){return super.createCanvasNode(),this.timecodedGroup=new A.Group({...this.timelinePosition,width:this.timeline.getTimecodedGroupDimension().width,height:this.bodyGroup.height()}),this.timecodedEventCatcher=yi.createEventCatcher({width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.thumbnailsGroup=new A.Group({x:0,y:this.style.height/2-this.style.thumbnailHeight/2,width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.timecodedGroup.add(this.timecodedEventCatcher),this.timecodedGroup.add(this.thumbnailsGroup),this.timeline.addToTimecodedThumbnailsGroup(this.timecodedGroup),this.thumbnailHover=new Zs({style:{visible:!1,stroke:this.style.thumbnailHoverStroke,strokeWidth:this.style.thumbnailHoverStrokeWidth}}),this.timeline.addToTimecodedSurfaceGroup(this.thumbnailHover.initCanvasNode()),this.bodyGroup}settleLayout(){super.settleLayout(),this.timecodedGroup.setAttrs({...this.timelinePosition});let e=this.timeline.getTimecodedGroupHorizontalMeasurement();[this.timecodedGroup,this.timecodedEventCatcher,this.thumbnailsGroup].forEach(t=>{t.width(e.width)}),this.onSettleLayout$.next()}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.fetchAndCreateThumbnails(),this.onSettleLayout$.pipe(I(this.onDestroy$)).subscribe(()=>{this.hideThumbnailHover(),this.adjustThumbnails()}),this.onSettleLayout$.pipe(I(this.onDestroy$)).pipe(Io(100)).subscribe(()=>{this.createAndAdjustThumbnails()}),this.timecodedGroup.on("mouseout mouseleave",e=>{this.hideThumbnailHover()})}onMeasurementsChange(){super.onMeasurementsChange(),this.hideThumbnailHover(),this.createAndAdjustThumbnails()}destroy(){super.destroy(),this.timecodedGroup.destroy(),this.thumbnailHover.destroy(),this.fireEventStreamBreaker()}clearContent(){this.fireEventStreamBreaker(),this.thumbnailVttFile=void 0,this.clearItems()}clearItems(){this.thumbnailsMap.forEach(e=>e.destroy()),this.thumbnailsMap.clear(),this.thumbnailsVisibleSet.clear(),this.thumbnailsGroup.destroyChildren()}fireEventStreamBreaker(){this.eventStreamBreaker$&&(this.eventStreamBreaker$.next(),this.eventStreamBreaker$.complete()),this.eventStreamBreaker$=new V}createAndAdjustThumbnails(){this.isVttLoaded()&&(this.resolveVisibleTimestamps(),this.thumbnailVttFile.getCues().forEach(e=>{let t=this.timeline.timeToTimelinePosition(e.startTime),i=this.thumbnailsVisibleSet.has(e.startTime);if(this.timeline.constrainTimelinePosition(t)===t)if(this.thumbnailsMap.has(e.startTime)){let s=this.thumbnailsMap.get(e.startTime);s&&s.setVisibleAndX(i,t)}else i&&(this.thumbnailsMap.set(e.startTime,null),dt.createKonvaImageSizedByHeight(e.url,this.style.thumbnailHeight).subscribe(s=>{let n=this.thumbnailsVisibleSet.has(e.startTime),a=this.createThumbnail(e,s,n);this.thumbnailsMap.set(e.startTime,a),this.thumbnailsGroup.add(a.getCanvasNode())}))}))}adjustThumbnails(){this.isVttLoaded()&&(this.resolveVisibleTimestamps(),this.thumbnailsMap.forEach(e=>{if(e){let t=this.timeline.timeToTimelinePosition(e.getThumbnailVttCue().startTime),i=this.thumbnailsVisibleSet.has(e.getThumbnailVttCue().startTime);e.setVisibleAndX(i,t)}}))}resolveVisibleTimestamps(){let e;this.thumbnailVttFile.getCues().forEach(i=>{let s=this.timeline.timeToTimelinePosition(i.startTime);this.timeline.constrainTimelinePosition(s)===s&&((e?s>=e:!0)?(e=s+this.thumbnailWidth,this.thumbnailsVisibleSet.add(i.startTime)):this.thumbnailsVisibleSet.delete(i.startTime))})}createThumbnail(e,t,i){let s=this.timeline.timeToTimelinePosition(e.startTime),n=new Zs({listening:!0,style:{x:s,y:0,visible:i,stroke:this.style.thumbnailStroke,strokeWidth:this.style.thumbnailStrokeWidth}});return n.setThumbnailVttCue(e),n.initCanvasNode(),n.setImage(t),n.onClick$.pipe(I(this.eventStreamBreaker$)).subscribe(a=>{this.onClick$.next(a)}),n.onMouseOver$.pipe(I(this.eventStreamBreaker$)).subscribe(a=>{this.showThumbnailHover(a.thumbnail)}),n.onMouseMove$.pipe(I(this.eventStreamBreaker$)).subscribe(a=>{this.showThumbnailHover(a.thumbnail)}),n.onMouseOut$.pipe(I(this.eventStreamBreaker$)).subscribe(a=>{this.hideThumbnailHover()}),n.onMouseLeave$.pipe(I(this.eventStreamBreaker$)).subscribe(a=>{this.hideThumbnailHover()}),n}showThumbnailHover(e){if(this.thumbnailHover.setVisible(!0),this.thumbnailHover.compareTo(e)===0){let t=this.resolveThumbnailHoverPosition(e);this.thumbnailHover.setPosition(t),this.thumbnailHover.setVisible(!0)}else dt.createKonvaImageSizedByWidth(e.getThumbnailVttCue().url,e.getImage().width()*this.style.thumbnailHoverScale).subscribe(t=>{this.thumbnailHover.setDimension(t.getSize()),this.thumbnailHover.setImage(t),this.thumbnailHover.setPosition(this.resolveThumbnailHoverPosition(e)),this.thumbnailHover.getCanvasNode().moveToTop()})}hideThumbnailHover(){this.thumbnailHover&&this.thumbnailHover.style.visible&&this.thumbnailHover.setVisible(!1)}resolveThumbnailHoverPosition(e){let t=this.timeline.getTimecodedGroupRect(),i=this.thumbnailHover.getImage().getSize(),s=e.getPosition().x+e.getDimension().width/2-i.width/2,n=e.style.strokeWidth>0?e.style.strokeWidth/2:0;s=s-n<0?n:s+i.width+n>t.width?t.width-i.width-n:s;let h=this.getRect().y+this.thumbnailsGroup.y()+e.getDimension().height/2-this.thumbnailHover.getDimension().height/2;return{x:s,y:h}}fetchAndCreateThumbnails(){this.fetchThumbnailVttFile(this._thumbnailVttUrl,this._axiosConfig,this.style.thumbnailHeight).pipe(ct(1)).subscribe(e=>{e&&(this.thumbnailVttFile=e.thumbnailVttFile,this.thumbnailWidth=e.thumbnailWidth,this.createAndAdjustThumbnails())})}fetchThumbnailVttFile(e,t,i){return e?ss.create(e,t).pipe(Yu(s=>{let n=s.getCues()[0];return dt.createKonvaImageSizedByHeight(n.url,i).pipe(ke(a=>{let o=a.getSize().width;return{thumbnailVttFile:s,thumbnailWidth:o}}))}),gi((s,n)=>Ee(void 0))):Ee(void 0)}isVttLoaded(){return!!this.thumbnailVttFile&&!!this.thumbnailWidth}getThumbnailVttFile(){return this.thumbnailVttFile}get thumbnailVttUrl(){return this._thumbnailVttUrl}set thumbnailVttUrl(e){this._thumbnailVttUrl=e,this.clearContent(),this.fetchAndCreateThumbnails()}}class wn extends bn{constructor(e,t){super(e,t)}static create(e,t){let i=new wn(e,t);return i.fetch().pipe(ke(s=>i))}mapCue(e){let t=e.text.split(","),i=_e.coerce.number().min(-1).max(0).parse(t[0]),s=_e.coerce.number().min(0).max(1).parse(t[1]);return{id:e.identifier,startTime:new Z(e.start).toDecimalPlaces(3).toNumber(),endTime:new Z(e.end).toDecimalPlaces(3).toNumber(),text:e.text,minSample:i,maxSample:s}}}const ka={listening:!1,style:{height:20,cornerRadius:20,opacity:1,visible:!0,maxSampleFillLinearGradientColorStops:[0,"red",.2,"yellow",1,"green"],minSampleFillLinearGradientColorStops:[0,"green",.8,"yellow",1,"red"]}};class Mm extends Je{constructor(e){super({...ka,...e,style:{...ka.style,...e.style}}),this.audioVttCue=this.config.audioVttCue,this.x=this.config.x,this.width=this.config.width,this.listening=this.config.listening}createCanvasNode(){this.group=new A.Group({x:this.x,y:0,width:this.width,height:this.style.height,visible:this.style.visible,listening:this.listening});let e=this.style.height/2,t=this.resolveMaxSampleBarHeight(),i=this.resolveMinSampleBarHeight();return this.maxSampleBar=new A.Rect({x:0,width:this.group.width(),y:e-t,height:t,opacity:this.style.opacity,cornerRadius:[this.style.cornerRadius,this.style.cornerRadius,0,0],fillLinearGradientStartPoint:{x:0,y:-(e-t)},fillLinearGradientEndPoint:{x:0,y:t},fillLinearGradientColorStops:this.style.maxSampleFillLinearGradientColorStops,perfectDrawEnabled:!1,shadowForStrokeEnabled:!1,hitStrokeWidth:0}),this.minSampleBar=new A.Rect({x:0,width:this.group.width(),y:e,height:i,opacity:this.style.opacity,cornerRadius:[0,0,this.style.cornerRadius,this.style.cornerRadius],fillLinearGradientStartPoint:{x:0,y:0},fillLinearGradientEndPoint:{x:0,y:e},fillLinearGradientColorStops:this.style.minSampleFillLinearGradientColorStops,perfectDrawEnabled:!1,shadowForStrokeEnabled:!1,hitStrokeWidth:0}),this.group.add(this.maxSampleBar),this.group.add(this.minSampleBar),this.group}resolveMaxSampleBarHeight(){return new Z(this.audioVttCue.maxSample).mul(this.style.height/2).toDecimalPlaces(2).toNumber()}resolveMinSampleBarHeight(){return new Z(this.audioVttCue.minSample).abs().mul(this.style.height/2).toDecimalPlaces(2).toNumber()}setPosition(e){this.x=e.x,this.isInitialized()&&this.group.position({x:this.x,y:0})}getPosition(){return this.group.getPosition()}getDimension(){return this.group.getSize()}getRect(){return{...this.getPosition(),...this.getDimension()}}getAudioVttCue(){return this.audioVttCue}setAudioVttCue(e){this.audioVttCue=e;let t=this.resolveMaxSampleBarHeight(),i=this.resolveMinSampleBarHeight();this.minSampleBar.setAttrs({height:i}),this.maxSampleBar.setAttrs({y:this.style.height/2-t,height:t,fillLinearGradientStartPoint:{x:0,y:-(this.style.height/2-t)},fillLinearGradientEndPoint:{x:0,y:t}})}}const Lm={...Qi,height:40,paddingTop:0,paddingBottom:0,itemWidth:5,itemMinPadding:2,itemCornerRadius:5,maxSampleFillLinearGradientColorStops:[0,"red",.2,"yellow",1,"green"],minSampleFillLinearGradientColorStops:[0,"green",.8,"yellow",1,"red"]};class Rl extends er{constructor(e){super({...e,style:{...Lm,...e.style}}),this.audioTrackLaneItemsMap=new Map,this.onSettleLayout$=new V,this._audioVttFileUrl=this.config.audioVttFileUrl}createCanvasNode(){return super.createCanvasNode(),this.timecodedGroup=new A.Group({...this.timelinePosition,width:this.timeline.getTimecodedGroupDimension().width,height:this.bodyGroup.height()}),this.timecodedEventCatcher=yi.createEventCatcher({width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.audioTrackLaneItemsGroup=new A.Group({...F.POSITION_TOP_LEFT,y:this.style.paddingTop,width:this.timecodedGroup.width(),height:this.timecodedGroup.height()-(this.style.paddingTop+this.style.paddingBottom)}),this.timecodedGroup.add(this.timecodedEventCatcher),this.timecodedGroup.add(this.audioTrackLaneItemsGroup),this.timeline.addToTimecodedAudioGroup(this.timecodedGroup),this.bodyGroup}settleLayout(){super.settleLayout(),this.timecodedGroup.setAttrs({...this.timelinePosition});let e=this.timeline.getTimecodedGroupHorizontalMeasurement();[this.timecodedGroup,this.timecodedEventCatcher,this.audioTrackLaneItemsGroup].forEach(t=>{t.width(e.width)}),this.onSettleLayout$.next()}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.fetchAndCreateAudioTrack(),this.onSettleLayout$.pipe(I(this.onDestroy$)).subscribe(()=>{this.settlePosition()}),Ou([this.onSettleLayout$,this.timeline.onScroll$]).pipe(I(this.onDestroy$),Io(100)).subscribe(()=>{this.settleAll()})}clearContent(){this.audioVttFile=void 0,this.clearItems()}clearItems(){this.audioTrackLaneItemsMap.forEach(e=>e.destroy()),this.audioTrackLaneItemsMap.clear(),this.audioTrackLaneItemsGroup.destroyChildren()}getVisibleCues(){let e=this.timeline.getVisibleTimeRange();return this.audioVttFile.findCues(e.start,e.end)}createEntities(){if(!this.isVttLoaded())return;this.clearItems();let e=this.getVisibleCues(),t=this.timeline.getTimecodedContainerDimension().width;this.numOfInterpolations=new Z(t+this.style.itemMinPadding).div(this.style.itemWidth+this.style.itemMinPadding).floor().toNumber(),this.itemPadding=new Z(t-this.numOfInterpolations*this.style.itemWidth).div(this.numOfInterpolations-1).toNumber();let i=this.resolveNumOfCuesPerInterpolation(e.length),s=this.resolveCuesInterpolations(e,i);for(let n=0;n<this.numOfInterpolations;n++){let a=s.get(n),o=this.resolveInterpolatedItemPosition(n),h=new Mm({x:o,width:this.style.itemWidth,audioVttCue:a,style:{cornerRadius:this.style.itemCornerRadius,height:this.audioTrackLaneItemsGroup.height(),visible:!0,maxSampleFillLinearGradientColorStops:this.style.maxSampleFillLinearGradientColorStops,minSampleFillLinearGradientColorStops:this.style.minSampleFillLinearGradientColorStops}});this.audioTrackLaneItemsMap.set(n,h),this.audioTrackLaneItemsGroup.add(h.initCanvasNode())}}resolveNumOfCuesPerInterpolation(e){return new Z(e).div(this.numOfInterpolations).floor().toNumber()}resolveCuesInterpolations(e,t){let i=e.length-t*this.numOfInterpolations,s=new Map,n=0;for(let a=0;a<this.numOfInterpolations;a++){let o=t+(a<i?1:0),h=n;n=h+o;let l=e.slice(h,n),d=e[h],u=e[n-1],c=0,p=0;l.forEach(m=>{c+=m.minSample,p+=m.maxSample});let f={id:`${a}`,text:"",minSample:new Z(c).div(o).toDecimalPlaces(3).toNumber(),maxSample:new Z(p).div(o).toDecimalPlaces(3).toNumber(),startTime:d.startTime,endTime:u.endTime};s.set(a,f)}return s}settleAll(){if(!this.isVttLoaded()||this.audioTrackLaneItemsMap.size<1)return;let e=this.getVisibleCues(),t=this.resolveNumOfCuesPerInterpolation(e.length),i=this.resolveCuesInterpolations(e,t);for(let s=0;s<this.numOfInterpolations;s++){let n=i.get(s),a=this.audioTrackLaneItemsMap.get(s);a.setAudioVttCue(n),a.setPosition({x:this.resolveInterpolatedItemPosition(s)})}}resolveInterpolatedItemPosition(e){return Math.abs(this.timeline.getTimecodedGroupHorizontalMeasurement().x)+e*this.style.itemWidth+e*this.itemPadding}settlePosition(){if(!(!this.isVttLoaded()||this.audioTrackLaneItemsMap.size<1))for(let e=0;e<this.numOfInterpolations;e++){let t=this.audioTrackLaneItemsMap.get(e),i=this.timeline.timeToTimelinePosition(t.getAudioVttCue().startTime);t.setPosition({x:i})}}fetchAndCreateAudioTrack(){this.fetchAudioTrackVttFile(this._audioVttFileUrl).pipe(ct(1)).subscribe(e=>{this.audioVttFile=e,this.createEntities()})}fetchAudioTrackVttFile(e){return e?wn.create(e).pipe(ke(t=>t),gi((t,i)=>Ee(void 0))):Ee(void 0)}isVttLoaded(){return!!this.audioVttFile}get audioVttFileUrl(){return this._audioVttFileUrl}set audioVttFileUrl(e){this._audioVttFileUrl=e,this.clearContent(),this.fetchAndCreateAudioTrack()}}function Xs(r){if(r.from===r.to)return;let e=r.from<r.to,t=e?r.to-r.from:r.from-r.to,i=new A.Animation(s=>{let n=A.Easings.StrongEaseInOut(s.time,0,t,r.duration);if(n>=t)r.onUpdateHandler(s,r.to),i.stop(),r.onCompleteHandler&&(r.onCompleteHandler(s,r.to),i=null);else{let a=r.from+n*(e?1:-1);r.onUpdateHandler(s,a)}},r.layer);i.start()}const Rm={...F.POSITION_TOP_LEFT,width:0,zoomMax:1500,scrollStepNumberOfDivisions:10,style:{height:20,backgroundFill:"#000000",backgroundFillOpacity:.3,handleBarFill:"#01a6f0",handleBarOpacity:1,handleOpacity:1}};class Im extends Je{constructor(e){super(vi(e,Rm)),this.onScroll$=new V,this.onZoom$=new V,this.x=this.config.x,this.y=this.config.y,this.width=this.config.width,this.zoomMax=this.config.zoomMax,this.scrollStepNumberOfDivisions=this.config.scrollStepNumberOfDivisions}createCanvasNode(){return this.group=new A.Group({x:this.x,y:this.y,width:this.width,height:this.style.height}),this.background=new A.Rect({...F.POSITION_TOP_LEFT,width:this.group.width(),height:this.style.height,fill:this.style.backgroundFill,opacity:this.style.backgroundFillOpacity}),this.handleGroup=new A.Group({...F.POSITION_TOP_LEFT,width:this.group.width(),height:this.style.height}),this.handleBar=new A.Rect({...F.POSITION_TOP_LEFT,width:this.handleGroup.width(),height:this.style.height,fill:this.style.handleBarFill,opacity:this.style.handleBarOpacity,draggable:!0}),this.leftZoomHandle=new A.Circle({...F.POSITION_TOP_LEFT,fill:this.style.handleBarFill,radius:this.style.height/2,y:this.style.height/2,opacity:this.style.handleOpacity,draggable:!0}),this.rightZoomHandle=new A.Circle({...F.POSITION_TOP_LEFT,fill:this.style.handleBarFill,radius:this.style.height/2,y:this.style.height/2,opacity:this.style.handleOpacity,draggable:!0}),this.handleGroup.add(this.background),this.handleGroup.add(this.handleBar),this.group.add(this.background),this.group.add(this.handleGroup),this.handleGroup.add(this.leftZoomHandle),this.handleGroup.add(this.rightZoomHandle),this.group}afterCanvasNodeInit(){this.styleAdapter.onChange$.pipe(I(this.onDestroy$),$e(n=>!!n)).subscribe(n=>{this.onStyleChange()}),this.group.on("click",n=>{this.clickScrollTo(this.group.getRelativePointerPosition().x)}),this.handleBar.on("dragstart dragmove dragend",n=>{let a=this.handleBar.getPosition(),o=this.getConstrainedHandleBarX(a.x);this.handleBar.setAttrs({x:o,y:0}),this.syncLeftRightHandles(),this.handleBar.getRelativePointerPosition().x>=0&&this.handleBar.getRelativePointerPosition().x<=this.handleBar.width()&&this.onScroll$.next({scrollPercent:this.getScrollHandlePercent()})});let e={scaleX:1.5,scaleY:1.5,duration:.1},t={scaleX:1,scaleY:1,duration:.1};this.leftZoomHandle.on("mouseover",n=>{this.leftZoomHandle.to({...e}),et.cursor("ew-resize")}),this.leftZoomHandle.on("mouseout",n=>{this.leftZoomHandle.to({...t}),et.cursor("default")}),this.rightZoomHandle.on("mouseover",n=>{this.rightZoomHandle.to({...e}),et.cursor("ew-resize")}),this.rightZoomHandle.on("mouseout",n=>{this.rightZoomHandle.to({...t}),et.cursor("default")});let i=n=>{let a=n;return a<0?a=0:this.rightZoomHandle.x()-n<=this.minHandleBarWidth&&(a=this.rightZoomHandle.x()-this.minHandleBarWidth),a};this.leftZoomHandle.on("dragstart dragmove dragend",n=>{let a=this.leftZoomHandle.getPosition(),o=i(a.x);this.leftZoomHandle.setAttrs({x:o,y:this.style.height/2}),this.handleBar.setAttrs({x:o,width:this.rightZoomHandle.x()-o}),this.onZoom$.next({zoomPercent:this.getZoomPercent()})});let s=n=>{let a=n,o=this.group.width();return a>o?a=o:n-this.leftZoomHandle.x()<=this.minHandleBarWidth&&(a=this.leftZoomHandle.x()+this.minHandleBarWidth),a};this.rightZoomHandle.on("dragstart dragmove dragend",n=>{let a=this.rightZoomHandle.getPosition(),o=s(a.x);this.rightZoomHandle.setAttrs({x:o,y:this.style.height/2}),this.handleBar.setAttrs({width:o-this.leftZoomHandle.x()}),this.onZoom$.next({zoomPercent:this.getZoomPercent()})})}onMeasurementsChange(){this.group.width(this.width),this.background.width(this.group.width()),this.handleGroup.width(this.group.width()),this.minHandleBarWidth=this.calculateHandleBarWidthFromZoomRatioPercent(this.zoomMax)}onStyleChange(){this.group.setAttrs({height:this.style.height}),this.background.setAttrs({height:this.style.height,fill:this.style.backgroundFill,opacity:this.style.backgroundFillOpacity}),this.handleGroup.setAttrs({height:this.style.height}),this.handleBar.setAttrs({height:this.style.height,fill:this.style.handleBarFill,opacity:this.style.handleBarOpacity}),this.leftZoomHandle.setAttrs({fill:this.style.handleBarFill,radius:this.style.height/2,y:this.style.height/2,opacity:this.style.handleOpacity}),this.rightZoomHandle.setAttrs({fill:this.style.handleBarFill,radius:this.style.height/2,y:this.style.height/2,opacity:this.style.handleOpacity})}getScrollHandleMaxX(){return this.group.width()-this.handleBar.width()}getConstrainedHandleBarX(e){let t=e;return t<0?t=0:t+this.handleBar.width()>this.group.width()&&(t=this.getScrollHandleMaxX()),t}clickScrollTo(e){let t=this.group.width()/this.scrollStepNumberOfDivisions;if(!(e>=this.handleBar.x()&&e<=this.handleBar.x()+this.handleBar.width())){let i=this.handleBar.x()>e,s=this.handleBar.x()+t*(i?-1:1);i?s=s<e?e:s:s=s+this.handleBar.width()>e?e-this.handleBar.width():s,this.scrollToEased(s)}}scrollTo(e){this.handleBar.x(this.getConstrainedHandleBarX(e)),this.syncLeftRightHandles(),this.onScroll$.next({scrollPercent:this.getScrollHandlePercent()})}scrollToEased(e){let t=this.handleBar.x(),i=this.getConstrainedHandleBarX(e);Xs({layer:this.handleGroup.getLayer(),duration:F.TIMELINE_SCROLL_EASED_DURATION_MS,from:t,to:i,onUpdateHandler:(s,n)=>{this.scrollTo(n)}})}calculateHandleBarWidthFromZoomRatioPercent(e){return new Z(this.group.width()).mul(100).div(e).toNumber()}getZoomPercent(){return this.group.width()===this.handleBar.width()?100:new Z(this.group.width()).mul(100).div(this.handleBar.width()).toNumber()}getScrollHandlePercent(){return this.handleBar.x()===0?0:new Z(this.handleBar.x()).div(this.group.width()-this.handleBar.width()).mul(100).toNumber()}updateScrollHandle(e){let t=e.getScrollHandleHorizontalMeasurement(this.group.width());this.handleBar.setAttrs({...t}),this.syncLeftRightHandles()}syncLeftRightHandles(){this.leftZoomHandle.x(this.handleBar.x()),this.rightZoomHandle.x(this.handleBar.x()+this.handleBar.width())}setWidth(e){this.width=e,this.onMeasurementsChange()}setPosition(e){this.x=e.x,this.y=e.y,this.group.setAttrs({...e})}getPosition(){return this.group.getPosition()}getRect(){return{...this.group.getPosition(),...this.group.getSize()}}}const Nm={style:{...F.POSITION_TOP_LEFT,height:100,fill:"#737373",fillSnapped:"#ffd500",lineWidth:2,symbolY:0,symbolHeight:15,textFontSize:12,textFill:"#0d0f05",textSnappedFill:"#f43530",visible:!1}};class Gm extends Je{constructor(e,t){super(vi(e,Nm)),this.stylesProvider=lt.instance(),this.timeline=t}createCanvasNode(){return this.group=new A.Group({x:this.style.x,y:this.style.y,visible:this.style.visible,listening:!1}),this.line=new A.Line({points:[this.style.x,0,this.style.x,this.style.height],stroke:this.style.fill,strokeWidth:this.style.lineWidth,listening:!1}),this.symbol=new A.Circle({y:this.style.symbolY,fill:this.style.fill,radius:this.style.symbolHeight/2,offsetY:-this.style.symbolHeight/2}),this.group.add(this.symbol),this.group.add(this.line),this.label=new A.Label({...F.POSITION_TOP_LEFT,listening:!1}),this.text=new A.Text({fontSize:this.style.textFontSize,fontFamily:this.stylesProvider.styles.omakasePlayerStyle.fontFamily,fill:this.style.textFill,...F.POSITION_TOP_LEFT,text:"",listening:!1}),this.label.y(-this.text.getSelfRect().height),this.label.add(this.text),this.group.add(this.label),this.group}afterCanvasNodeInit(){this.styleAdapter.onChange$.pipe(I(this.onDestroy$)).subscribe(e=>{this.onMeasurementsChange()}),this.stylesProvider.onChange$.pipe($e(e=>!!e),I(this.onDestroy$)).subscribe(e=>{this.text.setAttrs({fontFamily:this.stylesProvider.styles.omakasePlayerStyle.fontFamily})})}onMeasurementsChange(){this.line.points([this.line.x(),0,this.line.x(),this.style.height])}sync(e,t=!1){this.style.visible||this.toggleVisible(!0);let i=this.timeline.timelinePositionToTimeFormatted(e),s=this.text.getSelfRect(),n=s.width/2,a=-n,o=this.timeline.getTimecodedGroupHorizontalMeasurement();o.width-e<n?a=-s.width+(o.width-e):e<n&&(a=-n+(n-e)),this.group.x(e),this.text.text(i),this.label.x(a),t?(this.line.stroke(this.style.fillSnapped),this.text.fill(this.style.fillSnapped),this.symbol.visible(!1)):(this.line.stroke(this.style.fill),this.text.fill(this.style.fill),this.symbol.visible(!0))}toggleVisible(e){this.style={visible:e},this.group.visible(e)}}const Dm={style:{visible:!0,fill:"#f43530",lineWidth:2,symbolHeight:15,scrubberHeight:15,backgroundFill:"#ffffff",backgroundOpacity:0,playProgressFill:"#008cbc",playProgressOpacity:.5,bufferedFill:"#a2a2a2",bufferedOpacity:1}};class Fm extends Je{constructor(e,t,i){super(vi(e,Dm)),this.timeline=t,this.videoController=i}createCanvasNode(){return this.group=new A.Group({...F.POSITION_TOP_LEFT,listening:!1}),this.background=new A.Rect({...F.POSITION_TOP_LEFT,height:this.style.scrubberHeight,fill:this.style.backgroundFill,opacity:this.style.backgroundOpacity,listening:!1}),this.playProgressBackground=new A.Rect({...F.POSITION_TOP_LEFT,height:this.style.scrubberHeight,fill:this.style.playProgressFill,opacity:this.style.playProgressOpacity,listening:!1}),this.playheadGroup=new A.Group({...F.POSITION_TOP_LEFT,visible:this.style.visible,listening:!1}),this.playheadLine=new A.Line({points:[0,0,0,0],stroke:this.style.fill,strokeWidth:this.style.lineWidth,listening:!1}),this.playheadSymbol=yi.createTriangle({...F.POSITION_TOP_LEFT,height:this.style.symbolHeight,color:this.style.fill}),this.bufferedGroup=new A.Group({...F.POSITION_TOP_LEFT,listening:!1}),this.group.add(this.background),this.group.add(this.bufferedGroup),this.group.add(this.playProgressBackground),this.playheadGroup.add(this.playheadLine),this.playheadGroup.add(this.playheadSymbol),this.group.add(this.playheadGroup),this.group}afterCanvasNodeInit(){this.settleLayout(),this.timeline.onZoom$.pipe(I(this.onDestroy$)).subscribe(e=>{this.settleLayout()}),this.videoController.onVideoLoading$.pipe(I(this.onDestroy$)).subscribe(e=>{this.group.visible(!1)}),this.videoController.onVideoLoaded$.pipe(I(this.onDestroy$)).subscribe(e=>{this.group.visible(!0),this.doPlayProgress(),this.doBufferingProgress()}),this.videoController.onVideoTimeChange$.pipe(I(this.onDestroy$)).subscribe(e=>{this.doPlayProgress()}),this.videoController.onSeeking$.pipe(I(this.onDestroy$)).subscribe(e=>{this.doPlayProgress(),this.doBufferingProgress()}),this.videoController.onBuffering$.pipe(I(this.onDestroy$)).subscribe(e=>{this.doBufferingProgress()})}onMeasurementsChange(){this.settleLayout()}getPlayheadPosition(){return this.playheadGroup.x()}settleLayout(){let e=this.timeline.getTimecodedGroupDimension();[this.group,this.bufferedGroup,this.playheadGroup].forEach(t=>{t.setAttrs({...e})}),[this.background].forEach(t=>{t.setAttrs({width:e.width})}),this.playheadLine.setAttrs({points:[0,0,0,e.height]}),this.doPlayProgress(),this.doBufferingProgress()}doPlayProgress(){let e=this.timeline.timeToTimelinePosition(this.videoController.getCurrentTime());this.playProgressBackground.width(e),this.playheadGroup.x(e)}doBufferingProgress(){let e=this.videoController.getBufferedTimespans();if(e&&e.length>0)if(this.bufferedGroup.hasChildren()){let t=e.length,i=this.bufferedGroup.getChildren().length;t===i?this.bufferedGroup.getChildren().forEach((s,n)=>{let a=e[n],o=this.timeline.timeToTimelinePosition(a.start),h=this.timeline.timeToTimelinePosition(a.end);s.setAttrs({x:o,width:h-o})}):(this.bufferedGroup.getChildren().forEach(s=>s.destroy()),this.createBuffers(e))}else this.createBuffers(e)}createBuffers(e){e.forEach(t=>{let i=this.timeline.timeToTimelinePosition(t.start),s=this.timeline.timeToTimelinePosition(t.end),n=new A.Rect({x:i,y:0,width:s-i,height:this.style.scrubberHeight,fill:this.style.bufferedFill,opacity:this.style.bufferedOpacity,listening:!1});this.bufferedGroup.add(n)})}}const Hm={style:{...F.POSITION_TOP_LEFT,width:150,height:20,textFontSize:20,textFill:"#0d0f05",visible:!0}};class Il extends Je{constructor(e,t){super(vi(e,Hm)),this.stylesProvider=lt.instance(),this.videoEventStreamBreaker$=new V,this.videoController=t}createCanvasNode(){return this.group=new A.Group({x:this.style.x,y:this.style.y,width:this.style.width,height:this.style.height,listening:!1,visible:this.style.visible}),this.text=new A.Text({...F.POSITION_TOP_LEFT,width:this.group.width(),height:this.group.height(),text:"",fontSize:this.style.textFontSize,fontFamily:this.stylesProvider.styles.omakasePlayerStyle.fontFamily,fill:this.style.textFill,visible:!0,align:"left",verticalAlign:"middle"}),this.group.add(this.text),this.group}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.stylesProvider.onChange$.pipe($e(e=>!!e),I(this.onDestroy$)).subscribe(e=>{this.text.setAttrs({fontFamily:this.stylesProvider.styles.omakasePlayerStyle.fontFamily})}),this.videoController.onVideoLoaded$.pipe($e(e=>!!e),I(this.onDestroy$)).subscribe(e=>{this.onVideoLoadedEvent(e)})}onMeasurementsChange(){this.group.width(this.style.width)}fireVideoEventStreamBreaker(){this.videoEventStreamBreaker$&&(this.videoEventStreamBreaker$.next(),this.videoEventStreamBreaker$.complete()),this.videoEventStreamBreaker$=new V}onVideoLoadedEvent(e){this.fireVideoEventStreamBreaker(),this.text.text(this.videoController.formatTimestamp(0)),this.videoController.onVideoTimeChange$.pipe(I(this.videoEventStreamBreaker$)).subscribe(t=>{this.text.text(this.videoController.formatTimestamp(t.currentTime))})}setVisible(e){this.style={visible:e},this.isInitialized()&&this.group.visible(e)}setPosition(e){this.style={...e},this.group.setAttrs({...e}),this.onMeasurementsChange()}getRect(){return this.group.getClientRect()}}const Bm={...Qi,height:60,tickDivisor:5,tickDivisionMinWidth:18,tickFill:"#0d0f05",tickHeight:12,divisionTickFill:"#000000",divisionTickHeight:12*F.GOLDEN_RATIO,timecodeShowFirst:!0,timecodeFontSize:11,timecodeFill:"#0d0f05"};class $m extends er{constructor(e,t){super({...e,style:{...Bm,...e.style}}),this.onClick$=new V,this.onMouseEnter$=new V,this.onMouseOver$=new V,this.onMouseMove$=new V,this.onMouseOut$=new V,this.onMouseLeave$=new V,this.videoController=t}createCanvasNode(){return super.createCanvasNode(),this.timecodedGroup=new A.Group({...this.timelinePosition,width:this.timeline.getTimecodedGroupDimension().width,height:this.bodyGroup.height()}),this.timecodedEventCatcher=yi.createEventCatcher({width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.ticksGroup=new A.Group({...F.POSITION_TOP_LEFT,width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.timecodedGroup.add(this.timecodedEventCatcher),this.timecodedGroup.add(this.ticksGroup),this.timeline.addToTimecodedBaseGroup(this.timecodedGroup),this.timecodeDisplay=new Il({style:{x:10,y:0,width:this.leftGroup.width(),height:this.getRect().height}},this.videoController),this.leftGroup.add(this.timecodeDisplay.initCanvasNode()),this.bodyGroup}settleLayout(){super.settleLayout();let e=this.timeline.getTimecodedGroupHorizontalMeasurement();[this.timecodedGroup,this.timecodedEventCatcher,this.ticksGroup].forEach(t=>{t.width(e.width)}),this.refreshTimeDivisions()}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.timecodedEventCatcher.on("mousemove",e=>{this.onMouseMove$.next({evt:e.evt,position:this.timecodedGroup.getRelativePointerPosition()})}),this.timecodedEventCatcher.on("mouseenter",e=>{this.onMouseEnter$.next({evt:e.evt,position:this.timecodedGroup.getRelativePointerPosition()})}),this.timecodedEventCatcher.on("mouseout",e=>{this.onMouseOut$.next({evt:e.evt,position:this.timecodedGroup.getRelativePointerPosition()})}),this.timecodedEventCatcher.on("mouseleave",e=>{this.onMouseLeave$.next({evt:e.evt,position:this.timecodedGroup.getRelativePointerPosition()})}),this.timecodedEventCatcher.on("click",e=>{this.onClick$.next({evt:e.evt,position:this.timecodedGroup.getRelativePointerPosition()})}),this.videoController.onVideoLoading$.pipe(I(this.onDestroy$)).subscribe(e=>{this.clearContent()}),this.videoController.onVideoLoaded$.pipe(I(this.onDestroy$)).subscribe(e=>{this.settleLayout()})}onStyleChange(){super.onStyleChange(),this.refreshTimeDivisions(!0)}destroy(){super.destroy(),this.timecodedGroup.destroy()}clearContent(){this.ticksGroup.destroyChildren()}refreshTimeDivisions(e=!1){if(!this.isTimelineReady())return;let t=this.style.tickDivisor,i=this.style.tickDivisionMinWidth,s=this.timeline.getTimecodedGroupRect().width,n=this.resolveTimeDivisionWidth(s,i,t,t),a=new Z(s).div(n).round().toNumber(),o=!e&&this.tickTotalDivisions===a&&!(this.ticksGroup.getChildren().length<1);o||this.clearContent(),this.tickDivisionWidth=n,this.tickTotalDivisions=a;let h=0,l=2,d=2,u=5;for(let c=0;c<this.tickTotalDivisions+1;c++){let p=c===0,f=c===this.tickTotalDivisions,m=c%t===0,v=c*this.tickDivisionWidth,_=m?this.style.divisionTickHeight:this.style.tickHeight,w=this.ticksGroup.height()-_,b=this.ticksGroup.height()-this.style.divisionTickHeight-u;if(o)this.ticksGroup.getChildren()[c].x(v);else{let T=new A.Group({x:v,y:h}),M=0,P=new A.Line({points:[M,w,M,w+_],stroke:this.style.tickFill,strokeWidth:1,listening:!1});T.add(P);let G=new A.Text({fontSize:this.style.timecodeFontSize,fontFamily:this.stylesProvider.styles.omakasePlayerStyle.fontFamily,fill:this.style.timecodeFill,text:`${this.timeline.timelinePositionToTimeFormatted(v)}`,listening:!1}),L=G.getSelfRect(),H=p?M+l:f?M-L.width-d:M-L.width/2,$=b-L.height;G.setAttrs({x:H,y:$});let R=m;R=p?this.style.timecodeShowFirst:R,R&&(T.add(G),T.x()+(G.x()>0?0:G.x()),T.y(),G.width()),this.ticksGroup.add(T)}}}resolveTimeDivisionWidth(e,t,i,s){return new Z(e).div(s).floor().greaterThan(t)?this.resolveTimeDivisionWidth(e,t,i,s*i):new Z(e).div(s/i).toNumber()}}const Vm={timelineHTMLElementId:"omakase-timeline",playheadHoverSnapArea:5,zoomScale:1.02,zoomBaseline:100,zoomMax:1500,style:{stageMinWidth:700,backgroundFill:"#f5f5f5",headerBackgroundFill:"#f5f5f5",footerBackgroundFill:"#f5f5f5",scrollbarHeight:15,thumbnailHoverWidth:200,thumbnailHoverStroke:"rgba(255,73,145,0.9)",thumbnailHoverStrokeWidth:5,thumbnailHoverYOffset:0,headerHeight:50,footerHeight:50,leftPanelWidth:200,rightPanelLeftGutterWidth:30,rightPanelRightGutterWidth:30,timecodedContainerClipPadding:20,playheadVisible:!0,playheadFill:"#f43530",playheadLineWidth:2,playheadSymbolHeight:15,playheadScrubberHeight:15,playheadBackgroundFill:"#ffffff",playheadBackgroundOpacity:0,playheadPlayProgressFill:"#008cbc",playheadPlayProgressOpacity:.5,playheadBufferedFill:"#a2a2a2",playheadBufferedOpacity:1}},xa="omakase_scrubber_lane";class zm extends Je{constructor(e,t){super(vi(e,Vm)),this.scrollWithPlayhead=!0,this.syncTimelineWithPlayheadInProgress=!1,this.mouseWheelEnabled=!1,this.leftPanelVisible=!0,this.videoEventBreaker$=new V,this.onScroll$=new V,this.onZoom$=new V,this.timelineHTMLElementId=this.config.timelineHTMLElementId,this.thumbnailVttUrl=this.config.thumbnailVttUrl,this.axiosConfig=this.config.axiosConfig,this.playheadHoverSnapArea=this.config.playheadHoverSnapArea,this.zoomScale=this.config.zoomScale,this.zoomBaseline=this.config.zoomBaseline,this.zoomMax=this.config.zoomMax,this.timecodedGroupNodes=[],this.timelaneLanes=[],this.timelaneLanesMap=new Map,this.timelineHTMLElement=document.getElementById(this.timelineHTMLElementId),this.videoController=t}createCanvasNode(){let e=this.resolveStageDimension();return this.width=e.width,this.stage=new A.Stage({container:this.timelineHTMLElementId,...e}),this.layer=new A.Layer,this.stage.add(this.layer),this.layoutGroup=new A.Group({...F.POSITION_TOP_LEFT}),this.layer.add(this.layoutGroup),this.layoutBackground=new A.Rect({...F.POSITION_TOP_LEFT,fill:this.style.backgroundFill}),this.headerGroup=new A.Group({...F.POSITION_TOP_LEFT}),this.headerBackground=new A.Rect({...F.POSITION_TOP_LEFT,fill:this.style.headerBackgroundFill}),this.footerGroup=new A.Group({...F.POSITION_TOP_LEFT}),this.footerBackground=new A.Rect({...F.POSITION_TOP_LEFT,fill:this.style.footerBackgroundFill}),this.bodyGroup=new A.Group({...F.POSITION_TOP_LEFT}),this.bodyContentGroup=new A.Group({...F.POSITION_TOP_LEFT}),this.leftPanel=new A.Group({...F.POSITION_TOP_LEFT}),this.rightPanel=new A.Group({...F.POSITION_TOP_LEFT}),this.timecodedContainer=new A.Group({...F.POSITION_TOP_LEFT}),this.timecodedGroup=new A.Group({...F.POSITION_TOP_LEFT,draggable:!0}),this.timecodedBaseGroup=new A.Group({...F.POSITION_TOP_LEFT,name:"timecodedBaseGroup"}),this.timecodedThumbnailsGroup=new A.Group({...F.POSITION_TOP_LEFT,name:"timecodedThumbnailsGroup"}),this.timecodedSubtitlesGroup=new A.Group({...F.POSITION_TOP_LEFT,name:"timecodedSubtitlesGroup"}),this.timecodedAudioGroup=new A.Group({...F.POSITION_TOP_LEFT,name:"timecodedAudioGroup"}),this.timecodedMarkersGroup=new A.Group({...F.POSITION_TOP_LEFT,name:"timecodedMarkersGroup"}),this.timecodedSurfaceGroup=new A.Group({...F.POSITION_TOP_LEFT,name:"timecodedSurfaceGroup"}),this.timecodedBackground=new A.Rect({...F.POSITION_TOP_LEFT,fill:"yellow",opacity:0,listening:!1}),this.timecodedEventCatcher=yi.createEventCatcher(),this.thumbnailHover=new Zs({style:{visible:!1,stroke:this.style.thumbnailHoverStroke,strokeWidth:this.style.thumbnailHoverStrokeWidth}}),this.layoutGroup.add(this.layoutBackground),this.layoutGroup.add(this.headerGroup),this.layoutGroup.add(this.footerGroup),this.layoutGroup.add(this.bodyGroup),this.headerGroup.add(this.headerBackground),this.footerGroup.add(this.footerBackground),this.bodyGroup.add(this.bodyContentGroup),this.bodyGroup.add(this.leftPanel),this.bodyGroup.add(this.rightPanel),this.rightPanel.add(this.timecodedContainer),this.timecodedContainer.add(this.timecodedGroup),[this.timecodedBackground,this.timecodedEventCatcher,this.timecodedBaseGroup,this.timecodedThumbnailsGroup,this.timecodedSubtitlesGroup,this.timecodedAudioGroup,this.timecodedMarkersGroup,this.timecodedSurfaceGroup].forEach(t=>{this.timecodedGroupNodes.push(t),this.timecodedGroup.add(t)}),this.scrollbar=new Im({style:{height:this.style.scrollbarHeight}}),this.rightPanel.add(this.scrollbar.initCanvasNode()),this.playhead=new Fm({style:{visible:this.style.playheadVisible,fill:this.style.playheadFill,lineWidth:this.style.playheadLineWidth,symbolHeight:this.style.playheadSymbolHeight,backgroundFill:this.style.playheadBackgroundFill,backgroundOpacity:this.style.playheadBackgroundOpacity,scrubberHeight:this.style.playheadScrubberHeight,playProgressFill:this.style.playheadPlayProgressFill,playProgressOpacity:this.style.playheadPlayProgressOpacity,bufferedFill:this.style.playheadBufferedFill,bufferedOpacity:this.style.playheadBufferedOpacity}},this,this.videoController),this.playheadHover=new Gm({},this),[this.playhead,this.playheadHover].forEach(t=>{this.addToTimecodedSurfaceGroup(t.initCanvasNode())}),this.headerTimecodeDisplay=new Il({style:{x:10,y:10,visible:!1}},this.videoController),this.headerGroup.add(this.headerTimecodeDisplay.initCanvasNode()),this.settleLayout(),this.addToTimecodedSurfaceGroup(this.thumbnailHover.initCanvasNode()),this.scrubberLane=new $m({id:xa,description:""},this.videoController),this.addLanes([this.scrubberLane]),this.stage}afterCanvasNodeInit(){this.videoController.onVideoLoading$.pipe($e(e=>!!e),I(this.onDestroy$)).subscribe(e=>{this.clearContent()}),this.videoController.onVideoLoaded$.pipe($e(e=>!!e),I(this.onDestroy$)).subscribe(e=>{this.onVideoLoadedEvent(e)}),be(window,"resize").pipe(I(this.onDestroy$)).subscribe(e=>{setTimeout(()=>{this.onWindowResize(e)},200)}),this.timecodedGroup.on("mouseenter",e=>{this.playheadHover.toggleVisible(this.videoController.isVideoLoaded())}),this.timecodedGroup.on("mouseleave",e=>{this.playheadHover.toggleVisible(!1)}),this.timecodedGroup.on("mousemove",e=>{if(!this.videoController.isVideoLoaded())return;let t=this.timecodedGroup.getRelativePointerPosition().x;this.playheadHoverMove(t)}),this.timecodedMarkersGroup.on("mousemove",e=>{if(!this.videoController.isVideoLoaded())return;let t=this.timecodedGroup.getRelativePointerPosition().x;this.playheadHoverMove(t)}),this.timecodedGroup.on("wheel",e=>{if(!this.videoController.isVideoLoaded())return;if(this.mouseWheelEnabled){let i=e.evt;i.preventDefault();let s=i.deltaY>0?"IN":"OUT";i.ctrlKey&&(s=s==="IN"?"OUT":"IN"),this.zoomStep(s,this.timecodedGroup.getRelativePointerPosition().x),this.updateScrollWithPlayhead()}let t=this.timecodedGroup.getRelativePointerPosition().x;this.playheadHoverMove(t)}),this.timecodedGroup.on("dragstart dragmove dragend",e=>{if(!this.videoController.isVideoLoaded()){this.timecodedGroup.setAttrs({...F.POSITION_TOP_LEFT});return}if(e.target===this.timecodedGroup){let t=this.timecodedGroup.getPosition();this.timecodedGroup.setAttrs({x:this.getConstrainedTimelineX(t.x),y:0}),this.onScroll$.next(this.createScrollEvent()),this.scrollbar.updateScrollHandle(this)}this.updateScrollWithPlayhead()}),this.timecodedGroup.on("dragmove",e=>{et.cursor("grabbing")}),this.timecodedGroup.on("dragend",e=>{et.cursor("default")}),this.scrubberLane.onMouseMove$.pipe(I(this.onDestroy$)).subscribe(e=>{if(!this.videoController.isVideoLoaded())return;this.mouseWheelEnabled=!0;let t=this.timecodedGroup.getRelativePointerPosition().x,i=this.timelinePositionToTime(t);if(this.thumbnailVttFile){let s=this.thumbnailVttFile.findCue(i);this.showThumbnailHover(s)}}),this.scrubberLane.onMouseEnter$.pipe(I(this.onDestroy$)).subscribe(e=>{this.mouseWheelEnabled=!0}),this.scrubberLane.onMouseLeave$.pipe(I(this.onDestroy$)).subscribe(e=>{this.hideThumbnailHover(),this.mouseWheelEnabled=!1}),this.scrubberLane.onClick$.pipe(I(this.onDestroy$)).subscribe(e=>{if(!this.videoController.isVideoLoaded())return;this.updateScrollWithPlayhead();let t=this.timecodedGroup.getRelativePointerPosition().x;this.playheadHoverMove(t),this.videoController.isVideoLoaded()&&this.videoController.seekToTimestamp(this.timelinePositionToTime(t)).subscribe(()=>{})}),this.scrollbar.onScroll$.pipe(I(this.onDestroy$)).subscribe(e=>{this.videoController.isVideoLoaded()&&(this.setHorizontalScrollPercent(this.scrollbar.getScrollHandlePercent()),this.updateScrollWithPlayhead(),this.onScroll$.next(this.createScrollEvent()))}),this.scrollbar.onZoom$.pipe(I(this.onDestroy$)).subscribe(e=>{this.videoController.isVideoLoaded()&&(this.zoomByPercent(e.zoomPercent,!1),this.updateScrollWithPlayhead())}),this.thumbnailVttUrl&&this.fetchThumbnailVttFile().subscribe()}settleLayout(){this.stage.setAttrs({...this.resolveStageDimension()});let e=this.calculateHeights();this.headerGroup.setAttrs({width:this.width,height:this.style.headerHeight}),this.bodyGroup.setAttrs({y:this.headerGroup.y()+this.headerGroup.height(),width:this.layoutGroup.width(),height:e.bodyHeight}),this.footerGroup.setAttrs({y:this.bodyGroup.y()+this.bodyGroup.height(),width:this.width,height:this.style.footerHeight}),this.layoutGroup.setAttrs({width:this.width,height:e.layoutHeight}),this.layoutBackground.setAttrs({...this.layoutGroup.getSize()}),this.headerBackground.setAttrs({...this.headerGroup.getSize()}),this.footerBackground.setAttrs({...this.footerGroup.getSize()}),[this.bodyContentGroup].forEach(t=>{t.setAttrs({...this.bodyGroup.getSize()})}),[this.leftPanel,this.rightPanel].forEach(t=>{t.setAttrs({height:this.bodyGroup.getSize().height})}),this.leftPanel.setAttrs({width:this.leftPanelVisible?this.style.leftPanelWidth:0,visible:this.leftPanelVisible}),this.rightPanel.setAttrs({x:this.leftPanel.x()+this.leftPanel.width()+this.style.rightPanelLeftGutterWidth,width:this.layoutGroup.width()-(this.leftPanel.width()+this.style.rightPanelLeftGutterWidth+this.style.rightPanelRightGutterWidth)}),[this.timecodedContainer,this.timecodedGroup,...this.timecodedGroupNodes].forEach(t=>{t.setAttrs({...this.rightPanel.getSize()})}),this.timecodedContainer.clipFunc(t=>{t.rect(-this.style.timecodedContainerClipPadding,-500,this.timecodedContainer.width()+2*this.style.timecodedContainerClipPadding,this.timecodedContainer.height()+500)}),this.timecodedThumbnailsGroup.clipFunc(t=>{t.rect(0,0,this.timecodedThumbnailsGroup.width(),this.timecodedThumbnailsGroup.height())}),this.scrollbar.setPosition({...this.scrollbar.getPosition(),y:this.leftPanel.getSize().height}),this.scrollbar.setWidth(this.timecodedContainer.width()),this.scrollbar.updateScrollHandle(this),this.maxTimecodedGroupWidth=this.calculateWidthFromZoomRatioPercent(this.zoomMax),this.playheadHover.style={height:this.timecodedContainer.height()},this.timelaneLanes.forEach(t=>{t.onMeasurementsChange()}),this.playhead.onMeasurementsChange()}onMeasurementsChange(){this.settleLayout();let e=this.getTimecodedGroupDimension();this.timelaneLanes.forEach(t=>{t.onMeasurementsChange()}),this.zoomByWidth(e.width,this.resolveZoomFocus()),this.scrollbar.updateScrollHandle(this)}onWindowResize(e){let t=this.resolveStageDimension();this.width=t.width,this.onMeasurementsChange()}calculateHeights(){let t=this.getLanes().map(i=>i.getDimension().height).reduce((i,s)=>i+s,0);return{bodyHeight:t,layoutHeight:this.style.headerHeight+t+this.style.footerHeight}}resolveStageDimension(){let e=this.getTimelineHTMLElementRect(),t=this.calculateHeights();return{width:e.width>=this.style.stageMinWidth?e.width:this.style.stageMinWidth,height:t.layoutHeight}}getTimelineHTMLElementRect(){return{x:this.timelineHTMLElement.offsetLeft,y:this.timelineHTMLElement.offsetTop,width:this.timelineHTMLElement.offsetWidth,height:this.timelineHTMLElement.offsetHeight}}showThumbnailHover(e){if(e)if(this.thumbnailHover.setVisible(!0),this.thumbnailHover.getThumbnailVttCue()===e){this.thumbnailHover.setThumbnailVttCue(e);let t=this.resolveThumbnailPosition(this.thumbnailHover);this.thumbnailHover.setPosition(t),this.thumbnailHover.getCanvasNode().moveToTop()}else dt.createKonvaImageSizedByWidth(e.url,this.style.thumbnailHoverWidth).subscribe(t=>{this.thumbnailHover.setThumbnailVttCue(e),this.thumbnailHover.setDimension(t.getSize()),this.thumbnailHover.setImage(t),this.thumbnailHover.setPosition(this.resolveThumbnailPosition(this.thumbnailHover)),this.thumbnailHover.getCanvasNode().moveToTop()})}hideThumbnailHover(){this.thumbnailHover&&this.thumbnailHover.setVisible(!1)}resolveThumbnailPosition(e){let t=this.timecodedGroup.getRelativePointerPosition(),i=this.getTimecodedGroupDimension(),s=e.getImage().getSize(),n=t.x-s.width/2,a=e.style.strokeWidth>0?e.style.strokeWidth/2:0;n=n-a<0?a:n+s.width+a>i.width?i.width-s.width-a:n;let h=this.scrubberLane.getRect();return{x:n,y:h.y+h.height+e.style.strokeWidth/2+this.style.thumbnailHoverYOffset}}createScrollEvent(){return{scrollPercent:this.getHorizontalScrollPercent()}}createZoomEvent(){return{zoomPercent:this.getZoomPercent()}}getHorizontalScrollPercent(){if(this.isSnappedStart())return 0;if(this.isSnappedEnd())return 100;{let e=new Z(this.getTimecodedContainerDimension().width-this.getTimecodedGroupDimension().width).abs();return new Z(this.getTimecodedGroupPosition().x).abs().mul(100).div(e).toNumber()}}setHorizontalScrollPercent(e){this.setTimelinePosition(this.calculateTimelineXFromScrollPercent(e))}getScrollHandleHorizontalMeasurement(e){let t=this.getTimecodedGroupDimension().width,i=this.getTimecodedGroupPosition().x,s;return t<=e?s={width:e,x:0}:s={width:new Z(e).mul(e).div(t).round().toNumber(),x:new Z(i).abs().mul(e).div(t).toNumber()},s}scrollTo(e){return e=_e.coerce.number().min(0).max(100).parse(e),this.scrollToPercentEased(e)}scrollToPlayhead(){let e=-this.playhead.getPlayheadPosition()+this.getTimecodedContainerDimension().width/2;return this.scrollToEased(e)}scrollToPercent(e){let t=this.calculateTimelineXFromScrollPercent(e);this.scrollTimeline(t)}scrollToPercentEased(e){let t=this.calculateTimelineXFromScrollPercent(e);return this.scrollToEased(t)}scrollToEased(e){return new se(t=>{let i=this.getTimecodedGroupPosition().x;Xs({layer:this.timecodedGroup.getLayer(),duration:F.TIMELINE_SCROLL_EASED_DURATION_MS,from:i,to:e,onUpdateHandler:(s,n)=>{this.scrollTimeline(n)},onCompleteHandler:(s,n)=>{t.next(this.getHorizontalScrollPercent()),t.complete()}})})}isPlayheadInTimecodedView(){return this.isInVisiblePositionRange(this.playhead.getPlayheadPosition())}updateScrollWithPlayhead(){let e=this.playhead.getPlayheadPosition(),t=e<this.getVisiblePositionRange().start,i=this.isInVisiblePositionRange(e);this.scrollWithPlayhead=i&&!t}syncTimelineWithPlayhead(){return new se(e=>{this.scrollToEased(-this.playhead.getPlayheadPosition()).pipe(ke(t=>{e.next(this.getHorizontalScrollPercent()),e.complete()})).subscribe()})}setTimelinePosition(e){let t=this.getConstrainedTimelineX(e);this.timecodedGroup.x(t)}scrollTimeline(e){let t=this.getTimecodedGroupPosition().x;this.setTimelinePosition(e),this.getTimecodedGroupPosition().x!==t&&(this.scrollbar.updateScrollHandle(this),this.setHorizontalScrollPercent(this.scrollbar.getScrollHandlePercent()),this.onScroll$.next(this.createScrollEvent()))}calculateTimelineXFromScrollPercent(e){e=this.getConstrainedScrollPercent(e);let t=this.getTimecodedGroupDimension(),i=this.getTimecodedContainerDimension();if(t.width>i.width){let s=new Z(i.width-t.width);return new Z(e).mul(s).div(100).toDecimalPlaces(2).toNumber()}else return 0}getZoomPercent(){let e=this.getTimecodedGroupDimension(),t=this.getTimecodedContainerDimension();return e.width>t.width?new Z(e.width).mul(100).div(t.width).round().toNumber():this.zoomBaseline}zoomTo(e){return e=_e.coerce.number().min(this.getZoomBaseline()).max(this.getZoomMax()).parse(e),this.zoomToEased(e)}zoomIn(){return new se(e=>{this.zoomStep("IN",this.timecodedGroup.getRelativePointerPosition().x),e.next(this.getZoomPercent()),e.complete()})}zoomOut(){return new se(e=>{this.zoomStep("OUT",this.timecodedGroup.getRelativePointerPosition().x),e.next(this.getZoomPercent()),e.complete()})}zoomToEased(e){return new se(t=>{e=this.getConstrainedZoomPercent(e);let i=this.getTimecodedGroupDimension().width,s=this.calculateWidthFromZoomRatioPercent(e);Xs({layer:this.timecodedGroup.getLayer(),duration:F.TIMELINE_ZOOM_EASED_DURATION_MS,from:i,to:s,onUpdateHandler:(n,a)=>{this.zoomByWidth(a,this.resolveZoomFocus())},onCompleteHandler:(n,a)=>{t.next(this.getZoomPercent()),t.complete()}})})}zoomStep(e,t){let i=new Z(this.getTimecodedGroupDimension().width),s=(e==="IN"?i.mul(this.zoomScale):i.div(this.zoomScale)).round().toNumber();this.zoomByWidth(s,t)}zoomByPercent(e,t=!0){e=this.getConstrainedZoomPercent(e);let i=this.calculateWidthFromZoomRatioPercent(e);return this.zoomByWidth(i,this.resolveZoomFocus(),t),this.getZoomPercent()}zoomByWidth(e,t,i=!0){let s=this.getTimecodedGroupPosition().x,n=this.getTimecodedGroupDimension().width;e=this.getConstrainedWidth(e);let a=this.calculateNewPosition(e,t);this.hideThumbnailHover(),this.timecodedGroup.setAttrs({width:e,x:a}),this.timecodedGroupNodes.forEach(h=>{h.width(e)}),(this.getTimecodedGroupDimension().width!==n||this.getTimecodedGroupPosition().x!==s)&&(i?this.scrollbar.updateScrollHandle(this):this.playheadHover.toggleVisible(!1),this.setHorizontalScrollPercent(this.scrollbar.getScrollHandlePercent()),this.onZoom$.next(this.createZoomEvent()),this.onScroll$.next(this.createScrollEvent()))}calculateNewPosition(e,t=0){let i=this.getTimecodedGroupPosition().x,s=this.getTimecodedGroupDimension().width,n=this.getTimecodedContainerRect(),a=e>s?"IN":"OUT",o=i;if(e===n.width)o=0;else if(e>n.width){if(t>0){let h=new Z(t).div(s);if(h.greaterThanOrEqualTo(0)&&h.lessThanOrEqualTo(1)){let l=e-s,d=h.mul(l).abs().round().toNumber(),u=i+d*(a==="IN"?-1:1);o=u<0?u:0}}if(e>n.width){let h=n.x+n.width;o+e<=h&&(o=n.width-e)}}return o}resolveZoomFocus(){return this.videoController.isVideoLoaded()?this.resolvePlayheadSyncPosition():this.isSnappedStart()?0:this.isSnappedEnd()?this.getTimecodedGroupDimension().width:this.getTimecodedGroupDimension().width/2}calculateWidthFromZoomRatioPercent(e){return new Z(this.getTimecodedContainerDimension().width).mul(e).div(100).round().toNumber()}getConstrainedWidth(e){let t=this.getTimecodedContainerDimension();return e>=t.width?e<=this.maxTimecodedGroupWidth?e:this.maxTimecodedGroupWidth:t.width}getConstrainedZoomPercent(e){return e<this.zoomBaseline?this.zoomBaseline:e>this.zoomMax?this.zoomMax:e}getConstrainedScrollPercent(e){return e<0?0:e>100?100:e}playheadHoverMove(e){if(this.videoController.isVideoLoaded()&&this.playheadHover){let t=!1;if(!this.videoController.isPlaying()){let i=this.resolvePlayheadSyncPosition();e>i-this.playheadHoverSnapArea&&e<i+this.playheadHoverSnapArea&&(e=i,t=!0)}this.playheadHover.sync(e,t)}}resolvePlayheadSyncPosition(){return this.timeToTimelinePosition(this.videoController.getCurrentTime())}onVideoLoadedEvent(e){this.fireVideoEventBreaker(),this.clearContent(),this.syncVideoMetadata(),this.videoController.onVideoTimeChange$.pipe(I(this.videoEventBreaker$)).subscribe(t=>{this.syncVideoMetadata()}),this.videoController.onPlay$.pipe(I(this.videoEventBreaker$)).subscribe(t=>{this.updateScrollWithPlayhead()})}fireVideoEventBreaker(){this.videoEventBreaker$&&(this.videoEventBreaker$.next(),this.videoEventBreaker$.complete()),this.videoEventBreaker$=new V}setThumbnailVttFile(e){this.thumbnailVttFile=e}syncVideoMetadata(){this.scrollWithPlayhead&&!this.isPlayheadInTimecodedView()&&!this.syncTimelineWithPlayheadInProgress&&(this.syncTimelineWithPlayheadInProgress=!0,this.syncTimelineWithPlayhead().subscribe(e=>{this.syncTimelineWithPlayheadInProgress=!1}))}addLane(e){if(this.timelaneLanesMap.has(e.getId()))throw new Error(`TimelineLane with id=${e.getId()} already exist`);let t=this.timelaneLanes.length<1,i={...F.POSITION_TOP_LEFT};t||(i.y=this.timelaneLanes.map(s=>s.getRect().height).reduce((s,n)=>s+n,0)),e.setTimeline(this),e.setVideoController(this.videoController),e.setTimelinePosition(i),e.initCanvasNode(),this.timelaneLanes.push(e),this.timelaneLanesMap.set(e.getId(),e),this.bodyContentGroup.add(e.getCanvasNode()),this.settleLayout()}removeLane(e){if(!this.timelaneLanesMap.has(e))throw new Error(`TimelineLane with id=${e} doesn't exist`);let t=this.timelaneLanesMap.get(e);this.timelaneLanes.splice(this.timelaneLanes.findIndex(s=>s.getId()===e),1),this.timelaneLanesMap.delete(e),t.clearContent(),t.destroy();let i={...F.POSITION_TOP_LEFT};this.timelaneLanes.forEach(s=>{s.setTimelinePosition({...i}),i.y=i.y+s.getRect().height}),this.timelaneLanes.forEach(s=>{s.onMeasurementsChange()}),this.settleLayout()}getScrollbar(){return this.scrollbar}addLanes(e){e.forEach(t=>this.addLane(t))}getLanes(){return[...this.timelaneLanesMap.values()]}getLane(e){return this.timelaneLanesMap.get(e)}getScrubberLane(){return this.getLane(xa)}getMarkerLane(e){let t=this.getLane(e);return t instanceof Bs?t:void 0}getThumbnailLane(e){let t=this.getLane(e);return t instanceof js?t:void 0}getSubtitlesLane(e){let t=this.getLane(e);return t instanceof Us?t:void 0}getAudioTrackLane(e){let t=this.getLane(e);return t instanceof Rl?t:void 0}createMarkerLane(e){let t=new Bs(e);return this.addLane(t),t}createThumbnailLane(e){let t=new js(e);return this.addLane(t),t}createSubtitlesLane(e){let t=new Us(e);return this.addLane(t),t}isTimelineReady(){return this.videoController.isVideoLoaded()}addToTimecodedBaseGroup(e){this.timecodedBaseGroup.add(e)}addToTimecodedSurfaceGroup(e){this.timecodedSurfaceGroup.add(e)}addToTimecodedMarkersGroup(e){this.timecodedMarkersGroup.add(e)}addToTimecodedThumbnailsGroup(e){this.timecodedThumbnailsGroup.add(e)}addToTimecodedSubtitlesGroup(e){this.timecodedSubtitlesGroup.add(e)}addToTimecodedAudioGroup(e){this.timecodedAudioGroup.add(e)}constrainTimelinePosition(e){let t=this.getTimecodedGroupDimension();return e<0?0:e>t.width?t.width:e}timelinePositionToTime(e){let t=this.constrainTimelinePosition(e);return this.videoController.isVideoLoaded()?new Z(t).mul(this.videoController.getDuration()).div(this.getTimecodedGroupDimension().width).toNumber():0}timelinePositionToTimeFormatted(e){return this.videoController.isVideoLoaded()?this.videoController.formatTimestamp(this.timelinePositionToTime(e)):""}timelinePositionToFrame(e){return this.videoController.isVideoLoaded()?this.videoController.calculateTimeToFrame(this.timelinePositionToTime(e)):0}timeToTimelinePosition(e){return new Z(e).mul(this.getTimecodedGroupDimension().width).div(this.videoController.getDuration()).toNumber()}getConstrainedTimelineX(e){let t=this.getTimecodedGroupDimension(),i=this.getTimecodedContainerDimension();if(t.width<=i.width)return 0;{let s=i.width-t.width;return e<s?s:e>0?0:e}}getBodyGroupRect(){return{...this.bodyGroup.getPosition(),...this.bodyGroup.getSize()}}getLeftPanelRect(){return{...this.leftPanel.getPosition(),...this.leftPanel.getSize()}}getLeftPanelVisible(){return this.leftPanelVisible}getRightPanelRect(){return{...this.rightPanel.getSize(),...this.rightPanel.getPosition()}}getTimecodedContainerDimension(){return this.timecodedContainer.getSize()}getTimecodedContainerPosition(){return this.timecodedContainer.getPosition()}getTimecodedContainerRect(){return{...this.getTimecodedContainerDimension(),...this.getTimecodedContainerPosition()}}getTimecodedGroupDimension(){return this.timecodedGroup.getSize()}getTimecodedGroupPosition(){return this.timecodedGroup.getPosition()}getTimecodedGroupRect(){return{...this.timecodedGroup.getPosition(),...this.timecodedGroup.getSize()}}getTimecodedGroupHorizontalMeasurement(){return{x:this.timecodedGroup.x(),width:this.timecodedGroup.width()}}getRelativePointerPosition(){return this.timecodedGroup.getRelativePointerPosition()}getLayoutGroupDimension(){return this.layoutGroup.getSize()}getLayoutGroupPosition(){return this.layoutGroup.getPosition()}getRect(){return{...this.getLayoutGroupDimension(),...this.getLayoutGroupPosition()}}getVisiblePositionRange(){let e=Math.abs(this.timecodedGroup.x()),t=e+this.timecodedContainer.width();return{start:e,end:t}}isInVisiblePositionRange(e){let t=this.getVisiblePositionRange();return e>=t.start&&e<=t.end}isSnappedStart(){return this.getTimecodedGroupPosition().x===0}isSnappedEnd(){return this.getTimecodedContainerDimension().width-this.getTimecodedGroupDimension().width===this.getTimecodedGroupPosition().x}getVisibleTimeRange(){let e=this.getVisiblePositionRange(),t=this.timelinePositionToTime(e.start),i=this.timelinePositionToTime(e.end);return{start:t,end:i}}getZoomBaseline(){return this.zoomBaseline}getZoomMax(){return this.zoomMax}fetchThumbnailVttFile(){return this.thumbnailVttUrl?ss.create(this.thumbnailVttUrl,this.axiosConfig).pipe(ke(e=>(this.thumbnailVttFile=e,e)),gi((e,t)=>Ee(void 0))):Ee(void 0)}toggleLeftPanelVisible(e){this.leftPanelVisible=e,this.leftPanel.visible(e),this.settleLayout(),this.timelaneLanes.forEach(t=>{t.onMeasurementsChange()}),this.headerTimecodeDisplay.setVisible(!e)}clearContent(){this.setThumbnailVttFile(void 0),this.timelaneLanes.forEach(e=>{e.clearContent()}),this.zoomByPercent(this.zoomBaseline)}}class qs{static timeToFrame(e,t){return t.mul(e).floor().toNumber()}static frameToTime(e,t){return new Z(e).dividedBy(t).toNumber()}}function Wm(r){r.next(),r.complete()}class ti{constructor(){this.resolveUserAgent()}static instance(){return ti._instance||(ti._instance=new ti),ti._instance}resolveUserAgent(){this._userAgent=window.navigator&&window.navigator.userAgent||"",this._isAndroid=/Android/i.test(this._userAgent),this._isFirefox=/Firefox/i.test(this._userAgent),this._isEdge=/Edg/i.test(this._userAgent),this._isChromium=/Chrome/i.test(this._userAgent)||/CriOS/i.test(this._userAgent),this._isChrome=!this.isEdge&&this.isChromium,this._isSafari=/Safari/i.test(this._userAgent)&&!this.isChrome&&!this.isAndroid&&!this.isEdge}get isSafari(){return this._isSafari}get isFirefox(){return this._isFirefox}get isEdge(){return this._isEdge}get isChromium(){return this._isChromium}get isChrome(){return this._isChrome}get isAndroid(){return this._isAndroid}}const Qe=class{static formatVideoTimestamp(r,e){if(r<=0)return Qe.VIDEO_ZERO_TIMESTAMP;const t=Math.floor(r/3600),i=Math.floor(r%3600/60),s=Math.floor(r%60);let n=new Z(qs.timeToFrame(r,e)).mod(e).toNumber();return`${Qe.padZero(t)}:${Qe.padZero(i)}:${Qe.padZero(s)}:${Qe.padZero(n)}`}static padZero(r,e=2){return r.toString().padStart(e,"0")}};let Ys=Qe;Ys.VIDEO_ZERO_TIMESTAMP=`${Qe.padZero(0)}:${Qe.padZero(0)}:${Qe.padZero(0)}:${Qe.padZero(0)}`;class Um{constructor(){this._state={playing:!1,paused:!0,waiting:!1,seeking:!1,buffering:!1,ended:!1},this.onChange$=new Qt(this._state)}updateState(e){let t={...this._state,...e},i=this.compare(this._state,t)===0;this._state=t,i||this.onChange$.next(this._state)}compare(e,t){return e.playing===t.playing&&e.paused===t.paused&&e.waiting===t.waiting&&e.seeking===t.seeking&&e.buffering===t.buffering&&e.ended===t.ended?0:-1}get state(){return this._state}setPlaying(){this.updateState({playing:!0,paused:!1,waiting:!1,seeking:!1,buffering:!1,ended:!1})}setPaused(){this.updateState({playing:!1,paused:!0,waiting:!1,seeking:!1,buffering:!1,ended:!1})}setEnded(){this.updateState({playing:!1,paused:!0,waiting:!1,seeking:!1,buffering:!1,ended:!0})}set waiting(e){this.updateState({waiting:e})}set seeking(e){this.updateState({seeking:e})}set buffering(e){this.updateState({buffering:e})}}function Pa(r){let e;return typeof r=="string"?e=r:r instanceof it?(console.log(r),e=r.errors.map(t=>t.message).join(". ")):r instanceof Error?e=r.message:e="Unexpected error",e}function Zm(r){return{errorMap:(e,t)=>({message:r})}}const We={PAUSE:"pause",WAITING:"waiting",PLAYING:"playing",TIMEUPDATE:"timeupdate",SEEKING:"seeking",SEEKED:"seeked",LOADEDDATA:"loadeddata",LOADEDMETEDATA:"loadedmetadata",ENDED:"ended",PROGRESS:"progress"};class jm{constructor(e,t){if(this.browserProvider=ti.instance(),this.helpMenuGroups=[],this._isVideoLoaded=!1,this.frameDurationSpillOverCorrection=1e-6,this.syncLoopMaxIterations=20,this.seekInProgress=!1,this.videoStalledCheckIntervalMs=700,this.videoFrameCallback$=new Qt(null),this.videoEventBreaker$=new V,this.seekBreaker$=new V,this.onVideoLoaded$=new Qt(void 0),this.onVideoLoading$=new V,this.onPlay$=new V,this.onPause$=new V,this.onVideoTimeChange$=new V,this.onSeeking$=new V,this.onSeeked$=new V,this.onBuffering$=new V,this.onEnded$=new V,this.onAudioSwitched$=new V,this.onPlaybackState$=new V,this.onHelpMenuChange$=new Qt(void 0),this.onVideoError$=new V,this.domController=e,this.crossorigin=t,this.videoElement=this.domController.videoElement,this.videoElement.crossOrigin=this.crossorigin,!this.videoElement)throw new Error("VideoController element not set");this.videoFrameCallback$.subscribe(i=>{i&&(this.seekInProgress||(this.isPlaying()?this.videoTimeChangeHandlerExecutor():this.isPaused()))})}loadVideo(e,t,i){try{return e=ai.url()(e),t=_e.coerce.number().min(0).max(100).parse(t,Zm("Invalid frameRate")),this.onVideoLoading$.next({sourceUrl:e,frameRate:t}),this._isVideoLoaded=!1,this.video=void 0,this.detachVideoEventListeners(),this.videoLoad(e,t,i).pipe(ke(s=>(this.video=s,this.frameRateDecimal=new Z(this.video.frameRate),this.syncStepCurrentTimeMediaTime=new Z(this.video.frameDuration).div(10).toNumber(),this.playbackStateMachine=new Um,this.initEventHandlers(),this.startVideoFrameCallback(),this._isVideoLoaded=!0,this.onVideoLoaded$.next({video:this.video}),s)),gi((s,n)=>{let a=Pa(s);return this.onVideoError$.next({type:"VIDEO_LOAD_ERROR",message:a}),Kn(()=>new Error(a))}))}catch(s){let n=Pa(s);return this.onVideoError$.next({type:"VIDEO_LOAD_ERROR",message:n}),Kn(()=>new Error(n))}}initEventHandlers(){be(this.videoElement,We.PAUSE).pipe(I(this.videoEventBreaker$)).subscribe(e=>{if(this.browserProvider.isSafari){let t=this.getCurrentTime()+this.video.frameDuration;this._seekTimeAndSyncNoEmitEvents(t).subscribe(i=>{this.videoTimeChangeHandlerExecutor(),this.onPause$.next({})})}else this.syncVideoFrames({}).subscribe(t=>{this.videoTimeChangeHandlerExecutor(),this.onPause$.next({})})}),be(this.videoElement,We.WAITING).pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.waiting=!0}),be(this.videoElement,We.PLAYING).pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.setPlaying(),this.videoStalledCheckLastCurrentTime=void 0}),be(this.videoElement,We.PAUSE).pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.setPaused(),this.videoStalledCheckLastCurrentTime=void 0}),be(this.videoElement,We.TIMEUPDATE).pipe(I(this.videoEventBreaker$)).subscribe(e=>{}),be(this.videoElement,We.PROGRESS).pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.onBuffering$.next({bufferedTimespans:this.getBufferedTimespans()})}),be(this.videoElement,We.ENDED).pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.onEnded$.next({})}),this.playbackStateMachine.onChange$.pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.onPlaybackState$.next(e)}),this.onPlay$.pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.setPlaying(),this.videoStalledCheckLastCurrentTime=void 0}),this.onPause$.pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.setPaused(),this.videoStalledCheckLastCurrentTime=void 0}),this.onSeeking$.pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.seeking=!0}),this.onSeeked$.pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.seeking=!1}),this.onEnded$.pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.setEnded(),this.videoStalledCheckLastCurrentTime=void 0}),zu(this.videoStalledCheckIntervalMs).pipe(I(this.videoEventBreaker$)).subscribe(e=>{let t=this.getCurrentTime();if(!this.videoStalledCheckLastCurrentTime){this.videoStalledCheckLastCurrentTime=t;return}if(this.playbackStateMachine.state.playing){let i=this.videoStalledCheckIntervalMs*.8/1e3*this.getPlaybackRate(),s=this.videoStalledCheckLastCurrentTime+i,n=t<s;this.playbackStateMachine.waiting=n,this.videoStalledCheckLastCurrentTime=t}})}getBufferedTimespans(){if(!this.isVideoLoaded())return[];let e=[],t=this.videoElement.buffered;for(let i=0;i<t.length;i++)e.push({start:t.start(i),end:t.end(i)});return e}startVideoFrameCallback(){let e=()=>{this.videoFrameCallbackHandle=this.videoElement.requestVideoFrameCallback((i,s)=>{t({now:i,metadata:s})})},t=i=>{this.videoFrameCallback$.next(i),e()};e()}detachVideoEventListeners(){this.videoEventBreaker$&&(this.videoEventBreaker$.next(),this.videoEventBreaker$.complete()),this.videoEventBreaker$=new V,this.videoElement&&this.videoFrameCallbackHandle&&this.videoElement.cancelVideoFrameCallback(this.videoFrameCallbackHandle)}syncVideoFrames(e){return console.debug("syncFrames - START",e),new se(t=>{let i=new Qt(!1),s=new V,n=this.syncLoopMaxIterations;this.seekBreaker$.pipe(I(s)).subscribe(()=>{console.debug("%csyncFrames - seek breaker triggered","color: gray"),i.next(!0),a()});let a=()=>{Wm(s),t.next(),t.complete(),console.debug("%csyncFrames - END","color: gray")},o=h=>{i.pipe(ct(1)).subscribe(l=>{l?console.debug("%csyncFrames - seek skipped, breaker already triggered","color: gray"):this._seekTimeFireAndForget(h)})};if(this.isPlaying())console.debug("%csyncFrames - SKIPPED: video is playing","color: gray"),a();else{let h=u=>{let c=this.getCurrentTime(),p=this.calculateTimeToFrame(c),f=u?u.metadata.mediaTime:void 0,m=f?this.calculateTimeToFrame(f):void 0;if(this.isPlaying())return console.debug("%csyncFrames - UNKNOWN: video is playing","color: gray"),!0;if(p===0)return console.debug(`%csyncFrames - OK: currentTimeFrame[${p}] === 0`,"color: green"),!0;if(e.seekToFrame){if(e.seekToFrame===p&&(p===m||!m))return console.debug(`%csyncFrames - OK: ((currentTimeFrame[${p}] === mediaTimeFrame[${m}]) || !mediaTimeFrame[${m}])`,"color: green"),!0}else if(p===m||!m)return console.debug(`%csyncFrames - OK: currentTimeFrame[${p}] === mediaTimeFrame[${m}]`,"color: green"),!0;return!1},l,d=u=>{if(console.debug(`syncFrames.syncLoop - START (${this.syncLoopMaxIterations-n})`,{syncConditions:e,videoFrameCallbackData:u,dropped:this.videoElement.getVideoPlaybackQuality()}),this.isPlaying()){a();return}if(h(u)){a();return}let c=this.getCurrentTime(),p=this.calculateTimeToFrame(c),f=u?u.metadata.mediaTime:void 0,m=f?this.calculateTimeToFrame(f):void 0;if(n--<=0){console.debug(`%csyncFrames - TOO MANY SYNCs, EXITING.. : currentTime[${c}], mediaTime[${f}], currentTimeFrame[${p}], mediaTimeFrame[${m}]`,"color: red"),a();return}if(console.debug(`syncFrames - currentTime[${c}], mediaTime[${f}], currentTimeFrame[${p}], mediaTimeFrame[${m}], `),e.seekToFrame)if(l||(l=c),e.seekToFrame===p)if(p===m||!m)console.debug(`%csyncFrames - OK: ((currentTimeFrame[${p}] === mediaTimeFrame[${m}]) || !mediaTimeFrame[${m}])`,"color: green"),a();else{console.debug(`%csyncFrames - CORRECTION SEEK TO FRAME; currentTimeFrame[${p}] ${p>m?">":"<"} mediaTimeFrame[${m}]`,"color: red");let v=Math.abs(p-m);console.debug(`%csyncFrames - frameDiff: ${v}`,"color: orange");let _=this.syncStepCurrentTimeMediaTime*(p>m?1:-1);o(Z.add(c,_).toNumber())}else{console.debug(`%csyncFrames - CORRECTION SEEK TO FRAME; syncConditions.seekToFrame[${e.seekToFrame}] !== currentTimeFrame[${p}] | seekToFrameTimeBaseline=${l}`,"color: red");let v=Math.abs(e.seekToFrame-p),_=v*this.video.frameDuration,b=(e.seekToFrame>=p?Z.add(l,_):Z.sub(l,_)).toNumber();l=b,console.debug(`%csyncFrames - frameDiff: ${v}`,"color: orange"),console.debug(`%csyncFrames - frameCorrectionTime: ${_}`,"color: orange"),console.debug(`%csyncFrames - seekTo: ${b}`,"color: orange"),o(b)}else p===m||!m?(console.debug(`%csyncFrames - OK: currentTimeFrame[${p}] === mediaTimeFrame[${m}]`,"color: green"),a()):(console.debug(`%csyncFrames - CORRECTION; currentTimeFrame[${p}] ${p>m?">":"<"} mediaTimeFrame[${m}]`,"color: red"),p>m?o(Z.add(c,this.syncStepCurrentTimeMediaTime).toNumber()):o(f+this.syncStepCurrentTimeMediaTime));console.debug("syncFrames.syncLoop - END")};this.videoFrameCallback$.pipe(ju((e.seekToFrame,0)),I(s)).subscribe(u=>{console.debug("syncFrames.syncLoop - videoFrameCallback$ trigger",u),d(u)})}})}seekTimeAndSync(e,t={}){return new se(i=>{this.seekInProgress&&(this.seekBreaker$.next(),this.seekBreaker$.complete(),this.seekBreaker$=new V),this.seekInProgress=!0,isNaN(e)||(e=e<0?0:e>this.getDuration()?this.getDuration():e,be(this.videoElement,We.SEEKING).pipe(I(this.seekBreaker$),ct(1)).subscribe(s=>{this.onSeeking$.next({newTime:e,currentTime:this.getCurrentTime()})}),be(this.videoElement,We.SEEKED).pipe(I(this.seekBreaker$),ct(1)).subscribe(s=>{this.syncVideoFrames(t).subscribe(n=>{this.onSeeked$.next({currentTime:this.getCurrentTime()}),this.seekInProgress=!1,i.next(!0),i.complete(),this.videoTimeChangeHandlerExecutor()})}),console.debug(`Seeking to timestamp: ${e}`),this.setCurrentTime(e))})}_seekTimeFireAndForget(e){if(!isNaN(e)){let t=this.getCurrentTime();e=e<0?0:e>this.getDuration()?this.getDuration():e;let i=e>t?"FORWARD":"BACKWARD",s=Z.sub(t,e).abs();console.debug(`Seeking from currentTime[${t}] to newTime[${e}], direction: ${i} ${s.toNumber()}`),this.setCurrentTime(e)}}_seekTimeAndSyncNoEmitEvents(e){return this.isPlaying()?Ee(!1):new se(t=>{isNaN(e)||(e=e<0?0:e>this.getDuration()?this.getDuration():e,be(this.videoElement,We.SEEKED).pipe(hi()).subscribe(i=>{this.syncVideoFrames({}).subscribe(s=>{t.next(!0),t.complete(),this.videoTimeChangeHandlerExecutor()})}),console.debug(`Seeking ${e}`),this.setCurrentTime(e))})}seekFromCurrentTimeAndSync(e,t={}){let i=this.getCurrentTime(),s=Z.add(i,e).toNumber(),n=s>i?"FORWARD":"BACKWARD",a=Z.sub(i,s).abs().toNumber();return console.debug(`Seeking from currentTime ${i} to ${s}, direction: ${n} ${a}`),this.seekTimeAndSync(s,t)}setCurrentTime(e){this.videoElement.currentTime=e}getFrameRateDecimal(){return this.frameRateDecimal}_seekToFrame(e){if(!this.isPlaying()&&!isNaN(e)){if(console.debug(`Seeking to frame: ${e}`),e<=0)return this.seekTimeAndSync(0,{});{let t=this.calculateFrameToTime(e)+new Z(this.frameDurationSpillOverCorrection).toNumber(),i=this.calculateTimeToFrame(t);return i!==e?(console.error(`Frame numbers don't match. Wanted: ${e}, calculated: ${i}`),Ee(!1)):this.seekTimeAndSync(t,{seekToFrame:e,seekToTimestamp:t,currentTime:this.getCurrentTime()}).pipe(ke(s=>s))}}}_seekFromCurrentFrame(e){let t=this.getCurrentFrame(),i=t+e;if(console.debug(`seekFromCurrentFrame - Current frame: ${t}, wanted frame: ${i}`),t!==i){if(i<=0)return this._seekToFrame(0);if(i>=this.getTotalFrames())return this._seekToFrame(this.getTotalFrames());{let s=this.calculateFrameToTime(e);return this.seekFromCurrentTimeAndSync(s,{seekToFrame:i,currentTime:this.getCurrentTime()}).pipe(ke(n=>n))}}else return Ee(!0)}videoTimeChangeHandlerExecutor(){let e=this.getCurrentTime(),t=this.getCurrentFrame();this.onVideoTimeChange$.next({currentTime:e,frame:t})}getPlaybackState(){return this.playbackStateMachine.state}getVideo(){return this.isVideoLoaded()?this.video:void 0}getHTMLVideoElement(){return this.videoElement}calculateTimeToFrame(e){return qs.timeToFrame(e,this.getFrameRateDecimal())}calculateFrameToTime(e){return qs.frameToTime(e,this.getFrameRateDecimal())}play(){this.isVideoLoaded()&&!this.isPlaying()&&this.videoElement.play().then(()=>{this.onPlay$.next({})})}pause(){this.isVideoLoaded()&&this.isPlaying()&&this.videoElement.pause()}togglePlayPause(){this.isPlaying()?this.pause():this.play()}isPlaying(){return this.isVideoLoaded()&&this.videoElement.currentTime>0&&this.videoElement.currentTime<this.getDuration()&&!this.videoElement.paused&&!this.videoElement.ended&&this.videoElement.readyState>this.videoElement.HAVE_CURRENT_DATA}isPaused(){return!this.isPlaying()}isSeeking(){return this.seekInProgress}getCurrentTime(){return this.isVideoLoaded()?this.videoElement.currentTime:0}getPlaybackRate(){return this.isVideoLoaded()?this.videoElement.playbackRate:0}setPlaybackRate(e){if(this.isVideoLoaded()){try{e=_e.coerce.number().min(.1).max(16).default(1).parse(e)}catch{e=1}this.videoElement.playbackRate=e}}getVolume(){return this.isVideoLoaded()?this.videoElement.volume:0}setVolume(e){if(this.isVideoLoaded()){try{e=_e.coerce.number().min(0).max(1).default(1).parse(e)}catch{e=1}this.videoElement.volume=e}}getDuration(){return this.isVideoLoaded()?this.video.duration:0}getFrameRate(){return this.isVideoLoaded()?this.video.frameRate:0}getTotalFrames(){return this.isVideoLoaded()?this.video.totalFrames:0}getCurrentFrame(){return this.isVideoLoaded()?this.calculateTimeToFrame(this.getCurrentTime()):0}seekToFrame(e){return this.isVideoLoaded()?(e=_e.coerce.number().min(0).max(this.getTotalFrames()).parse(e),this._seekToFrame(e)):Ee(!1)}seekFromCurrentFrame(e){return this.isVideoLoaded()?(e=_e.coerce.number().parse(e),this._seekFromCurrentFrame(e)):Ee(!1)}seekPreviousFrame(){return this.isVideoLoaded()?this.seekFromCurrentFrame(-1):Ee(!1)}seekNextFrame(){return this.isVideoLoaded()?this.seekFromCurrentFrame(1):Ee(!1)}seekToTimestamp(e){return this.isVideoLoaded()?(e=_e.coerce.number().parse(e),this.seekTimeAndSync(e)):Ee(!1)}formatTimestamp(e){return this.isVideoLoaded()?(e=_e.coerce.number().min(0).max(this.getDuration()).parse(e),Ys.formatVideoTimestamp(e,this.getFrameRateDecimal())):Ys.VIDEO_ZERO_TIMESTAMP}mute(){this.isVideoLoaded()&&(this.videoElement.muted=!0)}unmute(){this.isVideoLoaded()&&(this.videoElement.muted=!1)}isFullscreen(){return this.isVideoLoaded()?this.domController.isFullscreen():!1}toggleFullscreen(){this.isVideoLoaded()&&this.domController.toggleFullscreen(this.videoElement)}getAudioTracks(){throw new Error("unsupported")}getCurrentAudioTrack(){throw new Error("unsupported")}setAudioTrack(e){throw new Error("unsupported")}isVideoLoaded(){return this._isVideoLoaded}getHls(){throw new Error("Unsupported or video not loaded with Hls.js")}addHelpMenuGroup(e){this.helpMenuGroups.push(e),this.onHelpMenuChange$.next()}getHelpMenuGroups(){return this.helpMenuGroups}destroy(){this.videoEventBreaker$&&(this.videoEventBreaker$.next(),this.videoEventBreaker$.complete()),this.videoElement=null,this.domController=null}}class Xm{constructor(e,t,i,s){this._element=e,this._sourceUrl=t,this._frameRate=i,this._duration=s,this._totalFrames=new Z(this._duration).mul(this._frameRate).toNumber(),this._frameDuration=new Z(1).div(this._frameRate).toNumber()}get element(){return this._element}get sourceUrl(){return this._sourceUrl}get frameRate(){return this._frameRate}get duration(){return this._duration}get totalFrames(){return this._totalFrames}get frameDuration(){return this._frameDuration}}class qm extends jm{constructor(e,t){super(e,t),ze.isSupported()?console.debug("video load with hls.js"):console.error("hls is not supported through MediaSource extensions");let i={...ze.DefaultConfig,enableWorker:!1};this.hls=new ze(i)}videoLoad(e,t,i){return new se(s=>{this.hls.on(ze.Events.ERROR,function(h,l){l.type;let d=l.details;l.fatal,d.includes("audioTrackLoadError")||(s.error(`Error loading video. Hls error details: ${d}`),s.complete())});let n=new se(h=>{this.hls.once(ze.Events.MEDIA_ATTACHED,function(l,d){console.debug("video element and hls.js are now bound together"),h.next(!0),h.complete()})}),a=new se(h=>{this.hls.once(ze.Events.MANIFEST_PARSED,function(l,d){console.debug("manifest loaded, found "+d.levels.length+" quality level"),h.next(!0),h.complete()})}),o=be(this.videoElement,We.LOADEDDATA).pipe(hi());Gu([n,a,o]).pipe(hi()).subscribe(h=>{i=i&&_e.coerce.number().parse(i),i=i||this.videoElement.duration;let l=new Xm(this.videoElement,e,t,i);s.next(l),s.complete()}),this.hls.loadSource(e),this.hls.attachMedia(this.videoElement)})}initEventHandlers(){super.initEventHandlers(),this.hls.on(ze.Events.ERROR,function(e,t){t.type,t.details,t.fatal,console.error(e,t),(t.details===ze.ErrorDetails.BUFFER_STALLED_ERROR||t.details===ze.ErrorDetails.BUFFER_APPEND_ERROR||t.details===ze.ErrorDetails.BUFFER_APPENDING_ERROR)&&(this.videoPlaybackStateHolder.buffering=!0)})}getAudioTracks(){return this.isVideoLoaded?this.hls.audioTracks:null}getCurrentAudioTrack(){return this.getAudioTracks()[this.hls.audioTrack]}setAudioTrack(e){if(!this.isVideoLoaded)return null;let t=this.hls.audioTrack;this.hls.audioTrack=e;let i=this.hls.audioTrack;i>=0&&t!==i&&this.onAudioSwitched$.next({audioTrack:this.getCurrentAudioTrack()})}getHls(){return this.hls}}class Ym{constructor(e){this.hidden=!0,this.id=e.id,this.src=e.src,this.default=e.default,this.label=e.label,this.language=e.language,this.cues=[]}}class Km extends Ym{constructor(e){super(e)}}class Sn{constructor(e){this.subtitlesTracks=new Map,this.onCreate$=new V,this.onRemove$=new V,this.onShow$=new V,this.onHide$=new V,this.videoController=e,this.videoController.onVideoLoaded$.pipe($e(t=>!!t)).subscribe(t=>{this.removeAllTracks()})}getDomTextTrack(e){let t=this.videoController.getHTMLVideoElement().textTracks.getTrackById(e.id);if(t.kind==="subtitles")return t}removeDomTextTrack(e){return this.getDomTextTrack(e)?(this.videoController.getHTMLVideoElement().querySelectorAll("track").forEach(i=>{i.getAttribute("id")===e.id&&i.parentElement.removeChild(i)}),!0):!1}static createHTMLTrackElement(e){let t=document.createElement("track");return t.kind="subtitles",t.id=e.id,t.label=e.label,t.srclang=e.language,t.src=e.src,t.default=e.default,t}createVttTrack(e){return this.videoController.isVideoLoaded?new se(t=>{let i=new Km({...e});this.subtitlesTracks.has(i.id)&&this.removeTrack(i.id),i.element=Sn.createHTMLTrackElement(i),be(i.element,"load").pipe(hi()).subscribe(n=>{this.subtitlesTracks.set(i.id,i),t.next(i),t.complete(),this.onCreate$.next({textTrack:i})}),this.videoController.getHTMLVideoElement().appendChild(i.element);let s=this.getDomTextTrack(i);s.mode="hidden"}):Ee(void 0)}getTracks(){if(this.videoController.isVideoLoaded)return[...this.subtitlesTracks.values()]}removeAllTracks(){this.videoController.isVideoLoaded&&this.subtitlesTracks.forEach((e,t)=>{this.removeTrack(e.id)})}removeTrack(e){if(!this.videoController.isVideoLoaded)return;let t=this.subtitlesTracks.get(e);t&&(this.subtitlesTracks.delete(e),this.removeDomTextTrack(t),this.onRemove$.next({}))}getCurrentTrack(){return this.currentTrack}showTrack(e=void 0){if(!this.videoController.isVideoLoaded||(e=e||(this.getCurrentTrack()?this.getCurrentTrack().id:void 0),!e))return;let t=this.subtitlesTracks.get(e);if(t){let i=this.getDomTextTrack(t);if(i){for(let s=0;s<this.videoController.getHTMLVideoElement().textTracks.length;s++){let n=this.videoController.getHTMLVideoElement().textTracks[s];n.mode="hidden"}i.mode="showing",t.hidden=!1,this.currentTrack=t,this.onShow$.next({})}}}hideTrack(e=void 0){if(!this.videoController.isVideoLoaded||(e=e||(this.getCurrentTrack()?this.getCurrentTrack().id:void 0),!e))return;let t=this.subtitlesTracks.get(e);if(t){let i=this.getDomTextTrack(t);i&&(i.mode="hidden",t.hidden=!0,this.onHide$.next({}))}}destroy(){this.removeAllTracks(),this.videoController=null,this.videoController=void 0}}var Ks={},Jm={get exports(){return Ks},set exports(r){Ks=r}};(function(r){var e=Object.prototype.hasOwnProperty,t="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(t=!1));function s(h,l,d){this.fn=h,this.context=l,this.once=d||!1}function n(h,l,d,u,c){if(typeof d!="function")throw new TypeError("The listener must be a function");var p=new s(d,u||h,c),f=t?t+l:l;return h._events[f]?h._events[f].fn?h._events[f]=[h._events[f],p]:h._events[f].push(p):(h._events[f]=p,h._eventsCount++),h}function a(h,l){--h._eventsCount===0?h._events=new i:delete h._events[l]}function o(){this._events=new i,this._eventsCount=0}o.prototype.eventNames=function(){var l=[],d,u;if(this._eventsCount===0)return l;for(u in d=this._events)e.call(d,u)&&l.push(t?u.slice(1):u);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(d)):l},o.prototype.listeners=function(l){var d=t?t+l:l,u=this._events[d];if(!u)return[];if(u.fn)return[u.fn];for(var c=0,p=u.length,f=new Array(p);c<p;c++)f[c]=u[c].fn;return f},o.prototype.listenerCount=function(l){var d=t?t+l:l,u=this._events[d];return u?u.fn?1:u.length:0},o.prototype.emit=function(l,d,u,c,p,f){var m=t?t+l:l;if(!this._events[m])return!1;var v=this._events[m],_=arguments.length,w,b;if(v.fn){switch(v.once&&this.removeListener(l,v.fn,void 0,!0),_){case 1:return v.fn.call(v.context),!0;case 2:return v.fn.call(v.context,d),!0;case 3:return v.fn.call(v.context,d,u),!0;case 4:return v.fn.call(v.context,d,u,c),!0;case 5:return v.fn.call(v.context,d,u,c,p),!0;case 6:return v.fn.call(v.context,d,u,c,p,f),!0}for(b=1,w=new Array(_-1);b<_;b++)w[b-1]=arguments[b];v.fn.apply(v.context,w)}else{var T=v.length,M;for(b=0;b<T;b++)switch(v[b].once&&this.removeListener(l,v[b].fn,void 0,!0),_){case 1:v[b].fn.call(v[b].context);break;case 2:v[b].fn.call(v[b].context,d);break;case 3:v[b].fn.call(v[b].context,d,u);break;case 4:v[b].fn.call(v[b].context,d,u,c);break;default:if(!w)for(M=1,w=new Array(_-1);M<_;M++)w[M-1]=arguments[M];v[b].fn.apply(v[b].context,w)}}return!0},o.prototype.on=function(l,d,u){return n(this,l,d,u,!1)},o.prototype.once=function(l,d,u){return n(this,l,d,u,!0)},o.prototype.removeListener=function(l,d,u,c){var p=t?t+l:l;if(!this._events[p])return this;if(!d)return a(this,p),this;var f=this._events[p];if(f.fn)f.fn===d&&(!c||f.once)&&(!u||f.context===u)&&a(this,p);else{for(var m=0,v=[],_=f.length;m<_;m++)(f[m].fn!==d||c&&!f[m].once||u&&f[m].context!==u)&&v.push(f[m]);v.length?this._events[p]=v.length===1?v[0]:v:a(this,p)}return this},o.prototype.removeAllListeners=function(l){var d;return l?(d=t?t+l:l,this._events[d]&&a(this,d)):(this._events=new i,this._eventsCount=0),this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prefixed=t,o.EventEmitter=o,r.exports=o})(Jm);const Qm={OMAKASE_SUBTITLES_HIDE:"omakaseSubtitlesHide",OMAKASE_TIMELINE_ZOOM:"omakaseTimelineZoom",OMAKASE_VIDEO_LOADED:"omakaseVideoLoaded",OMAKASE_VIDEO_PAUSE:"omakaseVideoPause",OMAKASE_VIDEO_PLAY:"omakaseVideoPlay",OMAKASE_VIDEO_SEEKED:"omakaseVideoSeeked",OMAKASE_VIDEO_SEEKING:"omakaseVideoSeeking",OMAKASE_VIDEO_BUFFERING:"omakaseVideoBuffering",OMAKASE_VIDEO_ENDED:"omakaseVideoEnded",OMAKASE_VIDEO_TIME_CHANGE:"omakaseVideoTimeChange",OMAKASE_VIDEO_AUDIO_SWITCHED:"omakaseVideoAudioSwitched",OMAKASE_AUDIO_SWITCHED:"omakaseAudioSwitched",OMAKASE_SUBTITLES_CREATE:"omakaseSubtitlesCreate",OMAKASE_SUBTITLES_REMOVE:"omakaseSubtitlesRemove",OMAKASE_SUBTITLES_SHOW:"omakaseSubtitlesShow",OMAKASE_TIMELINE_SCROLL:"omakaseTimelineScroll"};class eg{constructor(e){this.onAudioSwitched$=new V,this.videoController=e}getAudioTracks(){return this.videoController.getAudioTracks()}getCurrentAudioTrack(){return this.videoController.getCurrentAudioTrack()}setAudioTrack(e){let t=this.getCurrentAudioTrack();this.videoController.setAudioTrack(e);let i=this.getCurrentAudioTrack();t!==i&&this.onAudioSwitched$.next({audioTrack:i})}}class Ei{static isFullscreenEnabled(){const e=document;return e.fullscreenEnabled||e.webkitFullscreenEnabled||!!e.webkitCancelFullScreen||e.mozFullScreenEnabled||e.msFullscreenEnabled||!1}static isFullscreen(){const e=document;return!!(e.fullscreenElement||e.webkitFullscreenElement||e.webkitCurrentFullScreenElement||e.mozFullScreenElement||e.msFullscreenElement)}static requestFullscreen(e,t){const i=e??document.documentElement,s=i.requestFullscreen||i.webkitRequestFullscreen||i.webkitRequestFullScreen||i.mozRequestFullScreen||i.msRequestFullscreen;if(!s)throw new Error("Unsupported");return s.call(i,t)}static exitFullscreen(){const e=document,t=e.exitFullscreen||e.webkitExitFullscreen||e.webkitCancelFullScreen||e.mozCancelFullScreen||e.msExitFullscreen;if(!t)throw new Error("Unsupported");return t.call(e)}}const fe={player:"omakase-player",playerWrapper:"omakase-player-wrapper",video:"omakase-video",videoControls:"omakase-video-controls",buttonPlay:"omakase-button-play",buttonPause:"omakase-button-pause",buttonLoading:"omakase-button-loading",buttonError:"omakase-button-error",buttonReplay:"omakase-button-replay",buttonHelp:"omakase-help-button",help:"omakase-help",helpMenu:"omakase-help-menu",errorMessage:"omakase-error-message"};class tg{constructor(e){this._playerHTMLElementId=e,this.divPlayer=this.getElementById(this._playerHTMLElementId),this.createDom()}createDom(){this.divPlayer.classList.add(`${fe.player}`),this.divPlayer.innerHTML=`<div class="${fe.playerWrapper}">
47
+ `)}function Ca(r){const e=(r%1).toFixed(3);r=Math.round(r-e);const t=Math.floor(r/3600),i=Math.floor((r-t*3600)/60),s=r-t*3600-i*60;return`${`${gr(t,2)}:`}${gr(i,2)}:${gr(s,2)}.${gr(e*1e3,3)}`}var wm={hlsSegment:mm,hlsSegmentPlaylist:gm};const Sm=Pl.parse,Tm=dm.compile,Cm=Ol.segment,Em=wm;var km={parse:Sm,compile:Tm,segment:Cm,hls:Em};class bn{constructor(e,t){this.cues=new Map,this.cuesKeysSorted=[],this.url=e,this.axiosConfig=t}fetch(){return Ki(Qp(this.getUrl(),this.axiosConfig)).pipe(ke(e=>{let t=e.data;try{return km.parse(t,{strict:!0,meta:!0}).cues.forEach(s=>{let n=this.mapCue(s);this.cues.set(n.startTime,n),this.cuesKeysSorted.push(n.startTime)}),this.cuesKeysSorted.sort((s,n)=>s-n),!0}catch(i){return console.error(i),!1}}))}getUrl(){return this.url}hasCues(){return this.cues&&this.cues.size>0}findCue(e){let t=this.findCues(e,e);if(t&&t.length===1)return t[0]}findCues(e,t){let i=this.findCueIndex(e),s=this.findCueIndex(t);return s===-1?[]:this.cuesKeysSorted.slice(i,s+1).map(n=>this.cues.get(n))}getCues(){return[...this.cues.values()]}findCueIndex(e){let t=0,i=this.cuesKeysSorted.length-1;for(;t<=i;){const s=Math.floor((t+i)/2);if(this.cuesKeysSorted[s]===e)return s;this.cuesKeysSorted[s]<e?t=s+1:i=s-1}return i===-1&&(i=0),i}}class _n extends bn{constructor(e,t){super(e,t)}static create(e,t){let i=new _n(e,t);return i.fetch().pipe(ke(s=>i))}mapCue(e){return{id:e.identifier,startTime:new Z(e.start).toDecimalPlaces(3).toNumber(),endTime:new Z(e.end).toDecimalPlaces(3).toNumber(),text:e.text}}}const Ea={listening:!0,style:{height:20,fill:"rgba(255,73,145)",opacity:1,visible:!0}};class xm extends Je{constructor(e,t){super({...Ea,...e,style:{...Ea.style,...e.style}}),this.textTrackCue=this.config.textTrackCue,this.x=this.config.x,this.width=this.config.width,this.listening=this.config.listening,this.subtitlesLane=t,this.subtitlesLane.onSettleLayout$.pipe(I(this.onDestroy$)).subscribe(()=>{let i=this.subtitlesLane.resolveItemHorizontalMeasurement(this.getTextTrackCue());this.setHorizontalMeasurement(i)})}createCanvasNode(){return this.group=new A.Group({x:this.x,y:0,width:this.width,height:this.style.height,visible:this.style.visible,listening:this.listening}),this.backgroundRect=new A.Rect({x:0,y:0,width:this.group.width(),height:this.group.height(),fill:this.style.fill,opacity:this.style.opacity,perfectDrawEnabled:!1,shadowForStrokeEnabled:!1,hitStrokeWidth:0}),this.group.add(this.backgroundRect),this.group}onMeasurementsChange(){this.backgroundRect.size(this.group.getSize())}setPosition(e){this.x=e.x,this.isInitialized()&&this.group.position({x:this.x,y:0})}getPosition(){return this.group.getPosition()}getDimension(){return this.group.getSize()}getRect(){return{...this.getPosition(),...this.getDimension()}}getHorizontalMeasurement(){return{x:this.x,width:this.width}}setHorizontalMeasurement(e){this.x=e.x,this.width=e.width,this.isInitialized()&&this.group.setAttrs({x:this.x,width:this.width}),this.onMeasurementsChange()}setVisible(e){this.style={visible:e},this.isInitialized()&&this.group.visible(e)}getTextTrackCue(){return this.textTrackCue}setTextTrackCue(e){this.textTrackCue=e}compareTo(e){return this.textTrackCue&&e&&this.getTextTrackCue().id===e.getTextTrackCue().id&&this.getTextTrackCue().startTime===e.getTextTrackCue().startTime&&this.getTextTrackCue().endTime===e.getTextTrackCue().endTime?0:-1}}const Pm={...Qi,height:40,paddingTop:0,paddingBottom:0,subtitlesLaneItemOpacity:.9,subtitlesLaneItemFill:"rgba(255,73,145)"};class Us extends er{constructor(e){super({...e,style:{...Pm,...e.style}}),this.subtitlesLaneItemsMap=new Map,this.onSettleLayout$=new V,this._subtitlesVttUrl=this.config.subtitlesVttUrl}createCanvasNode(){return super.createCanvasNode(),this.timecodedGroup=new A.Group({...this.timelinePosition,width:this.timeline.getTimecodedGroupDimension().width,height:this.bodyGroup.height()}),this.timecodedEventCatcher=yi.createEventCatcher({width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.subtitlesLaneItemsGroup=new A.Group({...F.POSITION_TOP_LEFT,y:this.style.paddingTop,width:this.timecodedGroup.width(),height:this.timecodedGroup.height()-(this.style.paddingTop+this.style.paddingBottom)}),this.timecodedGroup.add(this.timecodedEventCatcher),this.timecodedGroup.add(this.subtitlesLaneItemsGroup),this.timeline.addToTimecodedSubtitlesGroup(this.timecodedGroup),this.bodyGroup}settleLayout(){super.settleLayout(),this.timecodedGroup.setAttrs({...this.timelinePosition});let e=this.timeline.getTimecodedGroupHorizontalMeasurement();[this.timecodedGroup,this.timecodedEventCatcher,this.subtitlesLaneItemsGroup].forEach(t=>{t.width(e.width)}),this.onSettleLayout$.next()}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.fetchAndCreateSubtitles()}clearContent(){this.subtitlesVttFile=void 0,this.clearItems()}clearItems(){this.subtitlesLaneItemsMap.forEach(e=>e.destroy()),this.subtitlesLaneItemsMap.clear(),this.subtitlesLaneItemsGroup.destroyChildren()}createEntities(){if(!this.isVttLoaded())return;this.clearItems(),this.subtitlesVttFile.getCues().forEach(t=>{let i=this.resolveItemHorizontalMeasurement(t),s=new xm({...i,textTrackCue:t,style:{height:this.subtitlesLaneItemsGroup.height(),fill:this.style.subtitlesLaneItemFill,opacity:this.style.subtitlesLaneItemOpacity}},this);this.subtitlesLaneItemsMap.set(t.startTime,s),this.subtitlesLaneItemsGroup.add(s.initCanvasNode())})}resolveItemHorizontalMeasurement(e){let t=this.timeline.constrainTimelinePosition(this.timeline.timeToTimelinePosition(e.startTime)),i=this.timeline.constrainTimelinePosition(this.timeline.timeToTimelinePosition(e.endTime));return{x:t,width:i-t}}fetchAndCreateSubtitles(){this.fetchSubtitlesVttFile(this._subtitlesVttUrl).pipe(ct(1)).subscribe(e=>{this.subtitlesVttFile=e,this.createEntities()})}fetchSubtitlesVttFile(e){return e?_n.create(e).pipe(ke(t=>t),gi((t,i)=>Ee(void 0))):Ee(void 0)}isVttLoaded(){return!!this.subtitlesVttFile}get subtitlesVttUrl(){return this._subtitlesVttUrl}set subtitlesVttUrl(e){this._subtitlesVttUrl=e,this.clearContent(),this.fetchAndCreateSubtitles()}}const Am={listening:!1,style:{...F.POSITION_TOP_LEFT,...F.DIMENSION_ZERO,stroke:"rgba(255,73,145)",strokeWidth:5,visible:!1}};class Zs extends Je{constructor(e){super(vi(e,Am)),this.onClick$=new V,this.onMouseOver$=new V,this.onMouseMove$=new V,this.onMouseOut$=new V,this.onMouseLeave$=new V,this.listening=this.config.listening}createCanvasNode(){return this.group=new A.Group({x:this.style.x,y:this.style.y,width:this.style.width,height:this.style.height,visible:this.style.visible,listening:this.listening}),this.backgroundRect=new A.Rect({x:0,y:0,width:this.group.width(),height:this.group.height(),strokeWidth:this.style.strokeWidth,stroke:this.style.stroke}),this.group.add(this.backgroundRect),this.group}afterCanvasNodeInit(){this.group.on("click",e=>{this.onClick$.next({thumbnail:this})}),this.group.on("mouseover",e=>{this.onMouseOver$.next({thumbnail:this})}),this.group.on("mousemove",e=>{this.onMouseMove$.next({thumbnail:this})}),this.group.on("mouseout",e=>{this.onMouseOut$.next({thumbnail:this})}),this.group.on("mouseleave",e=>{this.onMouseLeave$.next({thumbnail:this})})}destroy(){super.destroy()}onMeasurementsChange(){this.backgroundRect.size(this.group.getSize())}setImage(e){this.image&&this.image.destroy(),this.image=e,this.style={width:e.width(),height:e.height()},this.group.setAttrs({...this.image.getSize()}),this.backgroundRect.setAttrs({...this.image.getSize()}),this.group.add(this.image)}setVisible(e){this.style={visible:e},this.isInitialized()&&this.group.visible(e)}setPosition(e){this.style={...e},this.isInitialized()&&this.group.position(e)}setVisibleAndX(e,t){this.style={visible:e,x:t},this.isInitialized()&&this.group.setAttrs({visible:e,x:t})}getPosition(){return this.group.getPosition()}getDimension(){return this.group.getSize()}setDimension(e){this.style={...e},this.isInitialized()&&this.group.size(e),this.onMeasurementsChange()}getRect(){return{...this.getPosition(),...this.getDimension()}}getThumbnailVttCue(){return this.thumbnailVttCue}setThumbnailVttCue(e){this.thumbnailVttCue=e}getImage(){return this.image}compareTo(e){return this.thumbnailVttCue&&e&&this.thumbnailVttCue.url===e.thumbnailVttCue.url?0:-1}}class ss extends bn{constructor(e,t){super(e,t)}static create(e,t){let i=new ss(e,t);return i.fetch().pipe(ke(s=>i))}mapCue(e){return{id:e.identifier,startTime:new Z(e.start).toDecimalPlaces(3).toNumber(),endTime:new Z(e.end).toDecimalPlaces(3).toNumber(),text:e.text,url:this.resolveThumbnailUrl(e)}}resolveThumbnailUrl(e){return this.isUrlAbsolute(e.text)?e.text:this.createThumbnailUrlFromRelativeUrl(e.text)}createThumbnailUrlFromRelativeUrl(e){return this.url.lastIndexOf("/")>2?`${this.url.substring(0,this.url.lastIndexOf("/"))}/${e}`:e}isUrlAbsolute(e){return/^(http(s):\/\/.)[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/.test(e)}}class dt{static createKonvaImage(e){return new se(t=>{A.Image.fromURL(e,i=>{t.next(i),t.complete()},i=>{console.error(i),t.error(i)})})}static createKonvaImageSizedByWidth(e,t){return dt.createKonvaImage(e).pipe(ke(i=>(i.setAttrs({width:t,height:dt.calculateProportionalHeight(t,i)}),i)))}static createKonvaImageSizedByHeight(e,t){return dt.createKonvaImage(e).pipe(ke(i=>(i.setAttrs({width:dt.calculateProportionalWidth(t,i),height:t}),i)))}static calculateProportionalHeight(e,t){return e*t.getAttrs().image.naturalHeight/t.getAttrs().image.naturalWidth}static calculateProportionalWidth(e,t){return e*t.getAttrs().image.naturalWidth/t.getAttrs().image.naturalHeight}}const Om={...Qi,thumbnailHeight:40,thumbnailStroke:"rgba(121,0,255,0.9)",thumbnailStrokeWidth:0,thumbnailHoverScale:1.5,thumbnailHoverStroke:"rgba(0,255,188,0.9)",thumbnailHoverStrokeWidth:5};class js extends er{constructor(e){super({...e,style:{...Om,...e.style}}),this.thumbnailsMap=new Map,this.thumbnailsVisibleSet=new Set,this.onSettleLayout$=new V,this.eventStreamBreaker$=new V,this.onClick$=new V,this._thumbnailVttUrl=this.config.thumbnailVttUrl,this._axiosConfig=this.config.axiosConfig}createCanvasNode(){return super.createCanvasNode(),this.timecodedGroup=new A.Group({...this.timelinePosition,width:this.timeline.getTimecodedGroupDimension().width,height:this.bodyGroup.height()}),this.timecodedEventCatcher=yi.createEventCatcher({width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.thumbnailsGroup=new A.Group({x:0,y:this.style.height/2-this.style.thumbnailHeight/2,width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.timecodedGroup.add(this.timecodedEventCatcher),this.timecodedGroup.add(this.thumbnailsGroup),this.timeline.addToTimecodedThumbnailsGroup(this.timecodedGroup),this.thumbnailHover=new Zs({style:{visible:!1,stroke:this.style.thumbnailHoverStroke,strokeWidth:this.style.thumbnailHoverStrokeWidth}}),this.timeline.addToTimecodedSurfaceGroup(this.thumbnailHover.initCanvasNode()),this.bodyGroup}settleLayout(){super.settleLayout(),this.timecodedGroup.setAttrs({...this.timelinePosition});let e=this.timeline.getTimecodedGroupHorizontalMeasurement();[this.timecodedGroup,this.timecodedEventCatcher,this.thumbnailsGroup].forEach(t=>{t.width(e.width)}),this.onSettleLayout$.next()}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.fetchAndCreateThumbnails(),this.onSettleLayout$.pipe(I(this.onDestroy$)).subscribe(()=>{this.hideThumbnailHover(),this.adjustThumbnails()}),this.onSettleLayout$.pipe(I(this.onDestroy$)).pipe(Io(100)).subscribe(()=>{this.createAndAdjustThumbnails()}),this.timecodedGroup.on("mouseout mouseleave",e=>{this.hideThumbnailHover()})}onMeasurementsChange(){super.onMeasurementsChange(),this.hideThumbnailHover(),this.createAndAdjustThumbnails()}destroy(){super.destroy(),this.timecodedGroup.destroy(),this.thumbnailHover.destroy(),this.fireEventStreamBreaker()}clearContent(){this.fireEventStreamBreaker(),this.thumbnailVttFile=void 0,this.clearItems()}clearItems(){this.thumbnailsMap.forEach(e=>e.destroy()),this.thumbnailsMap.clear(),this.thumbnailsVisibleSet.clear(),this.thumbnailsGroup.destroyChildren()}fireEventStreamBreaker(){this.eventStreamBreaker$&&(this.eventStreamBreaker$.next(),this.eventStreamBreaker$.complete()),this.eventStreamBreaker$=new V}createAndAdjustThumbnails(){this.isVttLoaded()&&(this.resolveVisibleTimestamps(),this.thumbnailVttFile.getCues().forEach(e=>{let t=this.timeline.timeToTimelinePosition(e.startTime),i=this.thumbnailsVisibleSet.has(e.startTime);if(this.timeline.constrainTimelinePosition(t)===t)if(this.thumbnailsMap.has(e.startTime)){let s=this.thumbnailsMap.get(e.startTime);s&&s.setVisibleAndX(i,t)}else i&&(this.thumbnailsMap.set(e.startTime,null),dt.createKonvaImageSizedByHeight(e.url,this.style.thumbnailHeight).subscribe(s=>{let n=this.thumbnailsVisibleSet.has(e.startTime),a=this.createThumbnail(e,s,n);this.thumbnailsMap.set(e.startTime,a),this.thumbnailsGroup.add(a.getCanvasNode())}))}))}adjustThumbnails(){this.isVttLoaded()&&(this.resolveVisibleTimestamps(),this.thumbnailsMap.forEach(e=>{if(e){let t=this.timeline.timeToTimelinePosition(e.getThumbnailVttCue().startTime),i=this.thumbnailsVisibleSet.has(e.getThumbnailVttCue().startTime);e.setVisibleAndX(i,t)}}))}resolveVisibleTimestamps(){let e;this.thumbnailVttFile.getCues().forEach(i=>{let s=this.timeline.timeToTimelinePosition(i.startTime);this.timeline.constrainTimelinePosition(s)===s&&((e?s>=e:!0)?(e=s+this.thumbnailWidth,this.thumbnailsVisibleSet.add(i.startTime)):this.thumbnailsVisibleSet.delete(i.startTime))})}createThumbnail(e,t,i){let s=this.timeline.timeToTimelinePosition(e.startTime),n=new Zs({listening:!0,style:{x:s,y:0,visible:i,stroke:this.style.thumbnailStroke,strokeWidth:this.style.thumbnailStrokeWidth}});return n.setThumbnailVttCue(e),n.initCanvasNode(),n.setImage(t),n.onClick$.pipe(I(this.eventStreamBreaker$)).subscribe(a=>{this.onClick$.next(a)}),n.onMouseOver$.pipe(I(this.eventStreamBreaker$)).subscribe(a=>{this.showThumbnailHover(a.thumbnail)}),n.onMouseMove$.pipe(I(this.eventStreamBreaker$)).subscribe(a=>{this.showThumbnailHover(a.thumbnail)}),n.onMouseOut$.pipe(I(this.eventStreamBreaker$)).subscribe(a=>{this.hideThumbnailHover()}),n.onMouseLeave$.pipe(I(this.eventStreamBreaker$)).subscribe(a=>{this.hideThumbnailHover()}),n}showThumbnailHover(e){if(this.thumbnailHover.setVisible(!0),this.thumbnailHover.compareTo(e)===0){let t=this.resolveThumbnailHoverPosition(e);this.thumbnailHover.setPosition(t),this.thumbnailHover.setVisible(!0)}else dt.createKonvaImageSizedByWidth(e.getThumbnailVttCue().url,e.getImage().width()*this.style.thumbnailHoverScale).subscribe(t=>{this.thumbnailHover.setDimension(t.getSize()),this.thumbnailHover.setImage(t),this.thumbnailHover.setPosition(this.resolveThumbnailHoverPosition(e)),this.thumbnailHover.getCanvasNode().moveToTop()})}hideThumbnailHover(){this.thumbnailHover&&this.thumbnailHover.style.visible&&this.thumbnailHover.setVisible(!1)}resolveThumbnailHoverPosition(e){let t=this.timeline.getTimecodedGroupRect(),i=this.thumbnailHover.getImage().getSize(),s=e.getPosition().x+e.getDimension().width/2-i.width/2,n=e.style.strokeWidth>0?e.style.strokeWidth/2:0;s=s-n<0?n:s+i.width+n>t.width?t.width-i.width-n:s;let h=this.getRect().y+this.thumbnailsGroup.y()+e.getDimension().height/2-this.thumbnailHover.getDimension().height/2;return{x:s,y:h}}fetchAndCreateThumbnails(){this.fetchThumbnailVttFile(this._thumbnailVttUrl,this._axiosConfig,this.style.thumbnailHeight).pipe(ct(1)).subscribe(e=>{e&&(this.thumbnailVttFile=e.thumbnailVttFile,this.thumbnailWidth=e.thumbnailWidth,this.createAndAdjustThumbnails())})}fetchThumbnailVttFile(e,t,i){return e?ss.create(e,t).pipe(Yu(s=>{let n=s.getCues()[0];return dt.createKonvaImageSizedByHeight(n.url,i).pipe(ke(a=>{let o=a.getSize().width;return{thumbnailVttFile:s,thumbnailWidth:o}}))}),gi((s,n)=>Ee(void 0))):Ee(void 0)}isVttLoaded(){return!!this.thumbnailVttFile&&!!this.thumbnailWidth}getThumbnailVttFile(){return this.thumbnailVttFile}get thumbnailVttUrl(){return this._thumbnailVttUrl}set thumbnailVttUrl(e){this._thumbnailVttUrl=e,this.clearContent(),this.fetchAndCreateThumbnails()}}class wn extends bn{constructor(e,t){super(e,t)}static create(e,t){let i=new wn(e,t);return i.fetch().pipe(ke(s=>i))}mapCue(e){let t=e.text.split(","),i=_e.coerce.number().min(-1).max(0).parse(t[0]),s=_e.coerce.number().min(0).max(1).parse(t[1]);return{id:e.identifier,startTime:new Z(e.start).toDecimalPlaces(3).toNumber(),endTime:new Z(e.end).toDecimalPlaces(3).toNumber(),text:e.text,minSample:i,maxSample:s}}}const ka={listening:!1,style:{height:20,cornerRadius:20,opacity:1,visible:!0,maxSampleFillLinearGradientColorStops:[0,"red",.2,"yellow",1,"green"],minSampleFillLinearGradientColorStops:[0,"green",.8,"yellow",1,"red"]}};class Mm extends Je{constructor(e){super({...ka,...e,style:{...ka.style,...e.style}}),this.audioVttCue=this.config.audioVttCue,this.x=this.config.x,this.width=this.config.width,this.listening=this.config.listening}createCanvasNode(){this.group=new A.Group({x:this.x,y:0,width:this.width,height:this.style.height,visible:this.style.visible,listening:this.listening});let e=this.style.height/2,t=this.resolveMaxSampleBarHeight(),i=this.resolveMinSampleBarHeight();return this.maxSampleBar=new A.Rect({x:0,width:this.group.width(),y:e-t,height:t,opacity:this.style.opacity,cornerRadius:[this.style.cornerRadius,this.style.cornerRadius,0,0],fillLinearGradientStartPoint:{x:0,y:-(e-t)},fillLinearGradientEndPoint:{x:0,y:t},fillLinearGradientColorStops:this.style.maxSampleFillLinearGradientColorStops,perfectDrawEnabled:!1,shadowForStrokeEnabled:!1,hitStrokeWidth:0}),this.minSampleBar=new A.Rect({x:0,width:this.group.width(),y:e,height:i,opacity:this.style.opacity,cornerRadius:[0,0,this.style.cornerRadius,this.style.cornerRadius],fillLinearGradientStartPoint:{x:0,y:0},fillLinearGradientEndPoint:{x:0,y:e},fillLinearGradientColorStops:this.style.minSampleFillLinearGradientColorStops,perfectDrawEnabled:!1,shadowForStrokeEnabled:!1,hitStrokeWidth:0}),this.group.add(this.maxSampleBar),this.group.add(this.minSampleBar),this.group}resolveMaxSampleBarHeight(){return new Z(this.audioVttCue.maxSample).mul(this.style.height/2).toDecimalPlaces(2).toNumber()}resolveMinSampleBarHeight(){return new Z(this.audioVttCue.minSample).abs().mul(this.style.height/2).toDecimalPlaces(2).toNumber()}setPosition(e){this.x=e.x,this.isInitialized()&&this.group.position({x:this.x,y:0})}getPosition(){return this.group.getPosition()}getDimension(){return this.group.getSize()}getRect(){return{...this.getPosition(),...this.getDimension()}}getAudioVttCue(){return this.audioVttCue}setAudioVttCue(e){this.audioVttCue=e;let t=this.resolveMaxSampleBarHeight(),i=this.resolveMinSampleBarHeight();this.minSampleBar.setAttrs({height:i}),this.maxSampleBar.setAttrs({y:this.style.height/2-t,height:t,fillLinearGradientStartPoint:{x:0,y:-(this.style.height/2-t)},fillLinearGradientEndPoint:{x:0,y:t}})}}const Lm={...Qi,height:40,paddingTop:0,paddingBottom:0,itemWidth:5,itemMinPadding:2,itemCornerRadius:5,maxSampleFillLinearGradientColorStops:[0,"red",.2,"yellow",1,"green"],minSampleFillLinearGradientColorStops:[0,"green",.8,"yellow",1,"red"]};class Rl extends er{constructor(e){super({...e,style:{...Lm,...e.style}}),this.audioTrackLaneItemsMap=new Map,this.onSettleLayout$=new V,this._audioVttFileUrl=this.config.audioVttFileUrl}createCanvasNode(){return super.createCanvasNode(),this.timecodedGroup=new A.Group({...this.timelinePosition,width:this.timeline.getTimecodedGroupDimension().width,height:this.bodyGroup.height()}),this.timecodedEventCatcher=yi.createEventCatcher({width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.audioTrackLaneItemsGroup=new A.Group({...F.POSITION_TOP_LEFT,y:this.style.paddingTop,width:this.timecodedGroup.width(),height:this.timecodedGroup.height()-(this.style.paddingTop+this.style.paddingBottom)}),this.timecodedGroup.add(this.timecodedEventCatcher),this.timecodedGroup.add(this.audioTrackLaneItemsGroup),this.timeline.addToTimecodedAudioGroup(this.timecodedGroup),this.bodyGroup}settleLayout(){super.settleLayout(),this.timecodedGroup.setAttrs({...this.timelinePosition});let e=this.timeline.getTimecodedGroupHorizontalMeasurement();[this.timecodedGroup,this.timecodedEventCatcher,this.audioTrackLaneItemsGroup].forEach(t=>{t.width(e.width)}),this.onSettleLayout$.next()}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.fetchAndCreateAudioTrack(),this.onSettleLayout$.pipe(I(this.onDestroy$)).subscribe(()=>{this.settlePosition()}),Ou([this.onSettleLayout$,this.timeline.onScroll$]).pipe(I(this.onDestroy$),Io(100)).subscribe(()=>{this.settleAll()})}clearContent(){this.audioVttFile=void 0,this.clearItems()}clearItems(){this.audioTrackLaneItemsMap.forEach(e=>e.destroy()),this.audioTrackLaneItemsMap.clear(),this.audioTrackLaneItemsGroup.destroyChildren()}getVisibleCues(){let e=this.timeline.getVisibleTimeRange();return this.audioVttFile.findCues(e.start,e.end)}createEntities(){if(!this.isVttLoaded())return;this.clearItems();let e=this.getVisibleCues(),t=this.timeline.getTimecodedContainerDimension().width;this.numOfInterpolations=new Z(t+this.style.itemMinPadding).div(this.style.itemWidth+this.style.itemMinPadding).floor().toNumber(),this.itemPadding=new Z(t-this.numOfInterpolations*this.style.itemWidth).div(this.numOfInterpolations-1).toNumber();let i=this.resolveNumOfCuesPerInterpolation(e.length),s=this.resolveCuesInterpolations(e,i);for(let n=0;n<this.numOfInterpolations;n++){let a=s.get(n),o=this.resolveInterpolatedItemPosition(n),h=new Mm({x:o,width:this.style.itemWidth,audioVttCue:a,style:{cornerRadius:this.style.itemCornerRadius,height:this.audioTrackLaneItemsGroup.height(),visible:!0,maxSampleFillLinearGradientColorStops:this.style.maxSampleFillLinearGradientColorStops,minSampleFillLinearGradientColorStops:this.style.minSampleFillLinearGradientColorStops}});this.audioTrackLaneItemsMap.set(n,h),this.audioTrackLaneItemsGroup.add(h.initCanvasNode())}}resolveNumOfCuesPerInterpolation(e){return new Z(e).div(this.numOfInterpolations).floor().toNumber()}resolveCuesInterpolations(e,t){let i=e.length-t*this.numOfInterpolations,s=new Map,n=0;for(let a=0;a<this.numOfInterpolations;a++){let o=t+(a<i?1:0),h=n;n=h+o;let l=e.slice(h,n),d=e[h],u=e[n-1],c=0,p=0;l.forEach(m=>{c+=m.minSample,p+=m.maxSample});let f={id:`${a}`,text:"",minSample:new Z(c).div(o).toDecimalPlaces(3).toNumber(),maxSample:new Z(p).div(o).toDecimalPlaces(3).toNumber(),startTime:d.startTime,endTime:u.endTime};s.set(a,f)}return s}settleAll(){if(!this.isVttLoaded()||this.audioTrackLaneItemsMap.size<1)return;let e=this.getVisibleCues(),t=this.resolveNumOfCuesPerInterpolation(e.length),i=this.resolveCuesInterpolations(e,t);for(let s=0;s<this.numOfInterpolations;s++){let n=i.get(s),a=this.audioTrackLaneItemsMap.get(s);a.setAudioVttCue(n),a.setPosition({x:this.resolveInterpolatedItemPosition(s)})}}resolveInterpolatedItemPosition(e){return Math.abs(this.timeline.getTimecodedGroupHorizontalMeasurement().x)+e*this.style.itemWidth+e*this.itemPadding}settlePosition(){if(!(!this.isVttLoaded()||this.audioTrackLaneItemsMap.size<1))for(let e=0;e<this.numOfInterpolations;e++){let t=this.audioTrackLaneItemsMap.get(e),i=this.timeline.timeToTimelinePosition(t.getAudioVttCue().startTime);t.setPosition({x:i})}}fetchAndCreateAudioTrack(){this.fetchAudioTrackVttFile(this._audioVttFileUrl).pipe(ct(1)).subscribe(e=>{this.audioVttFile=e,this.createEntities()})}fetchAudioTrackVttFile(e){return e?wn.create(e).pipe(ke(t=>t),gi((t,i)=>Ee(void 0))):Ee(void 0)}isVttLoaded(){return!!this.audioVttFile}get audioVttFileUrl(){return this._audioVttFileUrl}set audioVttFileUrl(e){this._audioVttFileUrl=e,this.clearContent(),this.fetchAndCreateAudioTrack()}}function Xs(r){if(r.from===r.to)return;let e=r.from<r.to,t=e?r.to-r.from:r.from-r.to,i=new A.Animation(s=>{let n=A.Easings.StrongEaseInOut(s.time,0,t,r.duration);if(n>=t)r.onUpdateHandler(s,r.to),i.stop(),r.onCompleteHandler&&(r.onCompleteHandler(s,r.to),i=null);else{let a=r.from+n*(e?1:-1);r.onUpdateHandler(s,a)}},r.layer);i.start()}const Rm={...F.POSITION_TOP_LEFT,width:0,zoomMax:1500,scrollStepNumberOfDivisions:10,style:{height:20,backgroundFill:"#000000",backgroundFillOpacity:.3,handleBarFill:"#01a6f0",handleBarOpacity:1,handleOpacity:1}};class Im extends Je{constructor(e){super(vi(e,Rm)),this.onScroll$=new V,this.onZoom$=new V,this.x=this.config.x,this.y=this.config.y,this.width=this.config.width,this.zoomMax=this.config.zoomMax,this.scrollStepNumberOfDivisions=this.config.scrollStepNumberOfDivisions}createCanvasNode(){return this.group=new A.Group({x:this.x,y:this.y,width:this.width,height:this.style.height}),this.background=new A.Rect({...F.POSITION_TOP_LEFT,width:this.group.width(),height:this.style.height,fill:this.style.backgroundFill,opacity:this.style.backgroundFillOpacity}),this.handleGroup=new A.Group({...F.POSITION_TOP_LEFT,width:this.group.width(),height:this.style.height}),this.handleBar=new A.Rect({...F.POSITION_TOP_LEFT,width:this.handleGroup.width(),height:this.style.height,fill:this.style.handleBarFill,opacity:this.style.handleBarOpacity,draggable:!0}),this.leftZoomHandle=new A.Circle({...F.POSITION_TOP_LEFT,fill:this.style.handleBarFill,radius:this.style.height/2,y:this.style.height/2,opacity:this.style.handleOpacity,draggable:!0}),this.rightZoomHandle=new A.Circle({...F.POSITION_TOP_LEFT,fill:this.style.handleBarFill,radius:this.style.height/2,y:this.style.height/2,opacity:this.style.handleOpacity,draggable:!0}),this.handleGroup.add(this.background),this.handleGroup.add(this.handleBar),this.group.add(this.background),this.group.add(this.handleGroup),this.handleGroup.add(this.leftZoomHandle),this.handleGroup.add(this.rightZoomHandle),this.group}afterCanvasNodeInit(){this.styleAdapter.onChange$.pipe(I(this.onDestroy$),$e(n=>!!n)).subscribe(n=>{this.onStyleChange()}),this.group.on("click",n=>{this.clickScrollTo(this.group.getRelativePointerPosition().x)}),this.handleBar.on("dragstart dragmove dragend",n=>{let a=this.handleBar.getPosition(),o=this.getConstrainedHandleBarX(a.x);this.handleBar.setAttrs({x:o,y:0}),this.syncLeftRightHandles(),this.handleBar.getRelativePointerPosition().x>=0&&this.handleBar.getRelativePointerPosition().x<=this.handleBar.width()&&this.onScroll$.next({scrollPercent:this.getScrollHandlePercent()})});let e={scaleX:1.5,scaleY:1.5,duration:.1},t={scaleX:1,scaleY:1,duration:.1};this.leftZoomHandle.on("mouseover",n=>{this.leftZoomHandle.to({...e}),et.cursor("ew-resize")}),this.leftZoomHandle.on("mouseout",n=>{this.leftZoomHandle.to({...t}),et.cursor("default")}),this.rightZoomHandle.on("mouseover",n=>{this.rightZoomHandle.to({...e}),et.cursor("ew-resize")}),this.rightZoomHandle.on("mouseout",n=>{this.rightZoomHandle.to({...t}),et.cursor("default")});let i=n=>{let a=n;return a<0?a=0:this.rightZoomHandle.x()-n<=this.minHandleBarWidth&&(a=this.rightZoomHandle.x()-this.minHandleBarWidth),a};this.leftZoomHandle.on("dragstart dragmove dragend",n=>{let a=this.leftZoomHandle.getPosition(),o=i(a.x);this.leftZoomHandle.setAttrs({x:o,y:this.style.height/2}),this.handleBar.setAttrs({x:o,width:this.rightZoomHandle.x()-o}),this.onZoom$.next({zoomPercent:this.getZoomPercent()})});let s=n=>{let a=n,o=this.group.width();return a>o?a=o:n-this.leftZoomHandle.x()<=this.minHandleBarWidth&&(a=this.leftZoomHandle.x()+this.minHandleBarWidth),a};this.rightZoomHandle.on("dragstart dragmove dragend",n=>{let a=this.rightZoomHandle.getPosition(),o=s(a.x);this.rightZoomHandle.setAttrs({x:o,y:this.style.height/2}),this.handleBar.setAttrs({width:o-this.leftZoomHandle.x()}),this.onZoom$.next({zoomPercent:this.getZoomPercent()})})}onMeasurementsChange(){this.group.width(this.width),this.background.width(this.group.width()),this.handleGroup.width(this.group.width()),this.minHandleBarWidth=this.calculateHandleBarWidthFromZoomRatioPercent(this.zoomMax)}onStyleChange(){this.group.setAttrs({height:this.style.height}),this.background.setAttrs({height:this.style.height,fill:this.style.backgroundFill,opacity:this.style.backgroundFillOpacity}),this.handleGroup.setAttrs({height:this.style.height}),this.handleBar.setAttrs({height:this.style.height,fill:this.style.handleBarFill,opacity:this.style.handleBarOpacity}),this.leftZoomHandle.setAttrs({fill:this.style.handleBarFill,radius:this.style.height/2,y:this.style.height/2,opacity:this.style.handleOpacity}),this.rightZoomHandle.setAttrs({fill:this.style.handleBarFill,radius:this.style.height/2,y:this.style.height/2,opacity:this.style.handleOpacity})}getScrollHandleMaxX(){return this.group.width()-this.handleBar.width()}getConstrainedHandleBarX(e){let t=e;return t<0?t=0:t+this.handleBar.width()>this.group.width()&&(t=this.getScrollHandleMaxX()),t}clickScrollTo(e){let t=this.group.width()/this.scrollStepNumberOfDivisions;if(!(e>=this.handleBar.x()&&e<=this.handleBar.x()+this.handleBar.width())){let i=this.handleBar.x()>e,s=this.handleBar.x()+t*(i?-1:1);i?s=s<e?e:s:s=s+this.handleBar.width()>e?e-this.handleBar.width():s,this.scrollToEased(s)}}scrollTo(e){this.handleBar.x(this.getConstrainedHandleBarX(e)),this.syncLeftRightHandles(),this.onScroll$.next({scrollPercent:this.getScrollHandlePercent()})}scrollToEased(e){let t=this.handleBar.x(),i=this.getConstrainedHandleBarX(e);Xs({layer:this.handleGroup.getLayer(),duration:F.TIMELINE_SCROLL_EASED_DURATION_MS,from:t,to:i,onUpdateHandler:(s,n)=>{this.scrollTo(n)}})}calculateHandleBarWidthFromZoomRatioPercent(e){return new Z(this.group.width()).mul(100).div(e).toNumber()}getZoomPercent(){return this.group.width()===this.handleBar.width()?100:new Z(this.group.width()).mul(100).div(this.handleBar.width()).toNumber()}getScrollHandlePercent(){return this.handleBar.x()===0?0:new Z(this.handleBar.x()).div(this.group.width()-this.handleBar.width()).mul(100).toNumber()}updateScrollHandle(e){let t=e.getScrollHandleHorizontalMeasurement(this.group.width());this.handleBar.setAttrs({...t}),this.syncLeftRightHandles()}syncLeftRightHandles(){this.leftZoomHandle.x(this.handleBar.x()),this.rightZoomHandle.x(this.handleBar.x()+this.handleBar.width())}setWidth(e){this.width=e,this.onMeasurementsChange()}setPosition(e){this.x=e.x,this.y=e.y,this.group.setAttrs({...e})}getPosition(){return this.group.getPosition()}getRect(){return{...this.group.getPosition(),...this.group.getSize()}}}const Nm={style:{...F.POSITION_TOP_LEFT,height:100,fill:"#737373",fillSnapped:"#ffd500",lineWidth:2,symbolY:0,symbolHeight:15,textFontSize:12,textFill:"#0d0f05",textSnappedFill:"#f43530",visible:!1}};class Gm extends Je{constructor(e,t){super(vi(e,Nm)),this.stylesProvider=lt.instance(),this.timeline=t}createCanvasNode(){return this.group=new A.Group({x:this.style.x,y:this.style.y,visible:this.style.visible,listening:!1}),this.line=new A.Line({points:[this.style.x,0,this.style.x,this.style.height],stroke:this.style.fill,strokeWidth:this.style.lineWidth,listening:!1}),this.symbol=new A.Circle({y:this.style.symbolY,fill:this.style.fill,radius:this.style.symbolHeight/2,offsetY:-this.style.symbolHeight/2}),this.group.add(this.symbol),this.group.add(this.line),this.label=new A.Label({...F.POSITION_TOP_LEFT,listening:!1}),this.text=new A.Text({fontSize:this.style.textFontSize,fontFamily:this.stylesProvider.styles.omakasePlayerStyle.fontFamily,fill:this.style.textFill,...F.POSITION_TOP_LEFT,text:"",listening:!1}),this.label.y(-this.text.getSelfRect().height),this.label.add(this.text),this.group.add(this.label),this.group}afterCanvasNodeInit(){this.styleAdapter.onChange$.pipe(I(this.onDestroy$)).subscribe(e=>{this.onMeasurementsChange()}),this.stylesProvider.onChange$.pipe($e(e=>!!e),I(this.onDestroy$)).subscribe(e=>{this.text.setAttrs({fontFamily:this.stylesProvider.styles.omakasePlayerStyle.fontFamily})})}onMeasurementsChange(){this.line.points([this.line.x(),0,this.line.x(),this.style.height])}sync(e,t=!1){this.style.visible||this.toggleVisible(!0);let i=this.timeline.timelinePositionToTimeFormatted(e),s=this.text.getSelfRect(),n=s.width/2,a=-n,o=this.timeline.getTimecodedGroupHorizontalMeasurement();o.width-e<n?a=-s.width+(o.width-e):e<n&&(a=-n+(n-e)),this.group.x(e),this.text.text(i),this.label.x(a),t?(this.line.stroke(this.style.fillSnapped),this.text.fill(this.style.fillSnapped),this.symbol.visible(!1)):(this.line.stroke(this.style.fill),this.text.fill(this.style.fill),this.symbol.visible(!0))}toggleVisible(e){this.style={visible:e},this.group.visible(e)}}const Dm={style:{visible:!0,fill:"#f43530",lineWidth:2,symbolHeight:15,scrubberHeight:15,backgroundFill:"#ffffff",backgroundOpacity:0,playProgressFill:"#008cbc",playProgressOpacity:.5,bufferedFill:"#a2a2a2",bufferedOpacity:1}};class Fm extends Je{constructor(e,t,i){super(vi(e,Dm)),this.timeline=t,this.videoController=i}createCanvasNode(){return this.group=new A.Group({...F.POSITION_TOP_LEFT,listening:!1}),this.background=new A.Rect({...F.POSITION_TOP_LEFT,height:this.style.scrubberHeight,fill:this.style.backgroundFill,opacity:this.style.backgroundOpacity,listening:!1}),this.playProgressBackground=new A.Rect({...F.POSITION_TOP_LEFT,height:this.style.scrubberHeight,fill:this.style.playProgressFill,opacity:this.style.playProgressOpacity,listening:!1}),this.playheadGroup=new A.Group({...F.POSITION_TOP_LEFT,visible:this.style.visible,listening:!1}),this.playheadLine=new A.Line({points:[0,0,0,0],stroke:this.style.fill,strokeWidth:this.style.lineWidth,listening:!1}),this.playheadSymbol=yi.createTriangle({...F.POSITION_TOP_LEFT,height:this.style.symbolHeight,color:this.style.fill}),this.bufferedGroup=new A.Group({...F.POSITION_TOP_LEFT,listening:!1}),this.group.add(this.background),this.group.add(this.bufferedGroup),this.group.add(this.playProgressBackground),this.playheadGroup.add(this.playheadLine),this.playheadGroup.add(this.playheadSymbol),this.group.add(this.playheadGroup),this.group}afterCanvasNodeInit(){this.settleLayout(),this.timeline.onZoom$.pipe(I(this.onDestroy$)).subscribe(e=>{this.settleLayout()}),this.videoController.onVideoLoading$.pipe(I(this.onDestroy$)).subscribe(e=>{this.group.visible(!1)}),this.videoController.onVideoLoaded$.pipe(I(this.onDestroy$)).subscribe(e=>{this.group.visible(!0),this.doPlayProgress(),this.doBufferingProgress()}),this.videoController.onVideoTimeChange$.pipe(I(this.onDestroy$)).subscribe(e=>{this.doPlayProgress()}),this.videoController.onSeeking$.pipe(I(this.onDestroy$)).subscribe(e=>{this.doPlayProgress(),this.doBufferingProgress()}),this.videoController.onBuffering$.pipe(I(this.onDestroy$)).subscribe(e=>{this.doBufferingProgress()})}onMeasurementsChange(){this.settleLayout()}getPlayheadPosition(){return this.playheadGroup.x()}settleLayout(){let e=this.timeline.getTimecodedGroupDimension();[this.group,this.bufferedGroup,this.playheadGroup].forEach(t=>{t.setAttrs({...e})}),[this.background].forEach(t=>{t.setAttrs({width:e.width})}),this.playheadLine.setAttrs({points:[0,0,0,e.height]}),this.doPlayProgress(),this.doBufferingProgress()}doPlayProgress(){let e=this.timeline.timeToTimelinePosition(this.videoController.getCurrentTime());this.playProgressBackground.width(e),this.playheadGroup.x(e)}doBufferingProgress(){let e=this.videoController.getBufferedTimespans();if(e&&e.length>0)if(this.bufferedGroup.hasChildren()){let t=e.length,i=this.bufferedGroup.getChildren().length;t===i?this.bufferedGroup.getChildren().forEach((s,n)=>{let a=e[n],o=this.timeline.timeToTimelinePosition(a.start),h=this.timeline.timeToTimelinePosition(a.end);s.setAttrs({x:o,width:h-o})}):(this.bufferedGroup.getChildren().forEach(s=>s.destroy()),this.createBuffers(e))}else this.createBuffers(e)}createBuffers(e){e.forEach(t=>{let i=this.timeline.timeToTimelinePosition(t.start),s=this.timeline.timeToTimelinePosition(t.end),n=new A.Rect({x:i,y:0,width:s-i,height:this.style.scrubberHeight,fill:this.style.bufferedFill,opacity:this.style.bufferedOpacity,listening:!1});this.bufferedGroup.add(n)})}}const Hm={style:{...F.POSITION_TOP_LEFT,width:150,height:20,textFontSize:20,textFill:"#0d0f05",visible:!0}};class Il extends Je{constructor(e,t){super(vi(e,Hm)),this.stylesProvider=lt.instance(),this.videoEventStreamBreaker$=new V,this.videoController=t}createCanvasNode(){return this.group=new A.Group({x:this.style.x,y:this.style.y,width:this.style.width,height:this.style.height,listening:!1,visible:this.style.visible}),this.text=new A.Text({...F.POSITION_TOP_LEFT,width:this.group.width(),height:this.group.height(),text:"",fontSize:this.style.textFontSize,fontFamily:this.stylesProvider.styles.omakasePlayerStyle.fontFamily,fill:this.style.textFill,visible:!0,align:"left",verticalAlign:"middle"}),this.group.add(this.text),this.group}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.stylesProvider.onChange$.pipe($e(e=>!!e),I(this.onDestroy$)).subscribe(e=>{this.text.setAttrs({fontFamily:this.stylesProvider.styles.omakasePlayerStyle.fontFamily})}),this.videoController.onVideoLoaded$.pipe($e(e=>!!e),I(this.onDestroy$)).subscribe(e=>{this.onVideoLoadedEvent(e)})}onMeasurementsChange(){this.group.width(this.style.width)}fireVideoEventStreamBreaker(){this.videoEventStreamBreaker$&&(this.videoEventStreamBreaker$.next(),this.videoEventStreamBreaker$.complete()),this.videoEventStreamBreaker$=new V}onVideoLoadedEvent(e){this.fireVideoEventStreamBreaker(),this.text.text(this.videoController.formatTimestamp(0)),this.videoController.onVideoTimeChange$.pipe(I(this.videoEventStreamBreaker$)).subscribe(t=>{this.text.text(this.videoController.formatTimestamp(t.currentTime))})}setVisible(e){this.style={visible:e},this.isInitialized()&&this.group.visible(e)}setPosition(e){this.style={...e},this.group.setAttrs({...e}),this.onMeasurementsChange()}getRect(){return this.group.getClientRect()}}const Bm={...Qi,height:60,tickDivisor:5,tickDivisionMinWidth:18,tickFill:"#0d0f05",tickHeight:12,divisionTickFill:"#000000",divisionTickHeight:12*F.GOLDEN_RATIO,timecodeShowFirst:!0,timecodeFontSize:11,timecodeFill:"#0d0f05"};class $m extends er{constructor(e,t){super({...e,style:{...Bm,...e.style}}),this.onClick$=new V,this.onMouseEnter$=new V,this.onMouseOver$=new V,this.onMouseMove$=new V,this.onMouseOut$=new V,this.onMouseLeave$=new V,this.videoController=t}createCanvasNode(){return super.createCanvasNode(),this.timecodedGroup=new A.Group({...this.timelinePosition,width:this.timeline.getTimecodedGroupDimension().width,height:this.bodyGroup.height()}),this.timecodedEventCatcher=yi.createEventCatcher({width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.ticksGroup=new A.Group({...F.POSITION_TOP_LEFT,width:this.timecodedGroup.width(),height:this.timecodedGroup.height()}),this.timecodedGroup.add(this.timecodedEventCatcher),this.timecodedGroup.add(this.ticksGroup),this.timeline.addToTimecodedBaseGroup(this.timecodedGroup),this.timecodeDisplay=new Il({style:{x:10,y:0,width:this.leftGroup.width(),height:this.getRect().height}},this.videoController),this.leftGroup.add(this.timecodeDisplay.initCanvasNode()),this.bodyGroup}settleLayout(){super.settleLayout();let e=this.timeline.getTimecodedGroupHorizontalMeasurement();[this.timecodedGroup,this.timecodedEventCatcher,this.ticksGroup].forEach(t=>{t.width(e.width)}),this.refreshTimeDivisions()}afterCanvasNodeInit(){super.afterCanvasNodeInit(),this.timecodedEventCatcher.on("mousemove",e=>{this.onMouseMove$.next({evt:e.evt,position:this.timecodedGroup.getRelativePointerPosition()})}),this.timecodedEventCatcher.on("mouseenter",e=>{this.onMouseEnter$.next({evt:e.evt,position:this.timecodedGroup.getRelativePointerPosition()})}),this.timecodedEventCatcher.on("mouseout",e=>{this.onMouseOut$.next({evt:e.evt,position:this.timecodedGroup.getRelativePointerPosition()})}),this.timecodedEventCatcher.on("mouseleave",e=>{this.onMouseLeave$.next({evt:e.evt,position:this.timecodedGroup.getRelativePointerPosition()})}),this.timecodedEventCatcher.on("click",e=>{this.onClick$.next({evt:e.evt,position:this.timecodedGroup.getRelativePointerPosition()})}),this.videoController.onVideoLoading$.pipe(I(this.onDestroy$)).subscribe(e=>{this.clearContent()}),this.videoController.onVideoLoaded$.pipe(I(this.onDestroy$)).subscribe(e=>{this.settleLayout()})}onStyleChange(){super.onStyleChange(),this.refreshTimeDivisions(!0)}destroy(){super.destroy(),this.timecodedGroup.destroy()}clearContent(){this.ticksGroup.destroyChildren()}refreshTimeDivisions(e=!1){if(!this.isTimelineReady())return;let t=this.style.tickDivisor,i=this.style.tickDivisionMinWidth,s=this.timeline.getTimecodedGroupRect().width,n=this.resolveTimeDivisionWidth(s,i,t,t),a=new Z(s).div(n).round().toNumber(),o=!e&&this.tickTotalDivisions===a&&!(this.ticksGroup.getChildren().length<1);o||this.clearContent(),this.tickDivisionWidth=n,this.tickTotalDivisions=a;let h=0,l=2,d=2,u=5;for(let c=0;c<this.tickTotalDivisions+1;c++){let p=c===0,f=c===this.tickTotalDivisions,m=c%t===0,v=c*this.tickDivisionWidth,_=m?this.style.divisionTickHeight:this.style.tickHeight,w=this.ticksGroup.height()-_,b=this.ticksGroup.height()-this.style.divisionTickHeight-u;if(o)this.ticksGroup.getChildren()[c].x(v);else{let T=new A.Group({x:v,y:h}),M=0,P=new A.Line({points:[M,w,M,w+_],stroke:this.style.tickFill,strokeWidth:1,listening:!1});T.add(P);let G=new A.Text({fontSize:this.style.timecodeFontSize,fontFamily:this.stylesProvider.styles.omakasePlayerStyle.fontFamily,fill:this.style.timecodeFill,text:`${this.timeline.timelinePositionToTimeFormatted(v)}`,listening:!1}),L=G.getSelfRect(),H=p?M+l:f?M-L.width-d:M-L.width/2,$=b-L.height;G.setAttrs({x:H,y:$});let R=m;R=p?this.style.timecodeShowFirst:R,R&&(T.add(G),T.x()+(G.x()>0?0:G.x()),T.y(),G.width()),this.ticksGroup.add(T)}}}resolveTimeDivisionWidth(e,t,i,s){return new Z(e).div(s).floor().greaterThan(t)?this.resolveTimeDivisionWidth(e,t,i,s*i):new Z(e).div(s/i).toNumber()}}const Vm={timelineHTMLElementId:"omakase-timeline",playheadHoverSnapArea:5,zoomScale:1.02,zoomBaseline:100,zoomMax:1500,style:{stageMinWidth:700,backgroundFill:"#f5f5f5",headerBackgroundFill:"#f5f5f5",footerBackgroundFill:"#f5f5f5",scrollbarHeight:15,thumbnailHoverWidth:200,thumbnailHoverStroke:"rgba(255,73,145,0.9)",thumbnailHoverStrokeWidth:5,thumbnailHoverYOffset:0,headerHeight:50,footerHeight:50,leftPanelWidth:200,rightPanelLeftGutterWidth:30,rightPanelRightGutterWidth:30,timecodedContainerClipPadding:20,playheadVisible:!0,playheadFill:"#f43530",playheadLineWidth:2,playheadSymbolHeight:15,playheadScrubberHeight:15,playheadBackgroundFill:"#ffffff",playheadBackgroundOpacity:0,playheadPlayProgressFill:"#008cbc",playheadPlayProgressOpacity:.5,playheadBufferedFill:"#a2a2a2",playheadBufferedOpacity:1}},xa="omakase_scrubber_lane";class zm extends Je{constructor(e,t){super(vi(e,Vm)),this.scrollWithPlayhead=!0,this.syncTimelineWithPlayheadInProgress=!1,this.mouseWheelEnabled=!1,this.leftPanelVisible=!0,this.videoEventBreaker$=new V,this.onScroll$=new V,this.onZoom$=new V,this.timelineHTMLElementId=this.config.timelineHTMLElementId,this.thumbnailVttUrl=this.config.thumbnailVttUrl,this.axiosConfig=this.config.axiosConfig,this.playheadHoverSnapArea=this.config.playheadHoverSnapArea,this.zoomScale=this.config.zoomScale,this.zoomBaseline=this.config.zoomBaseline,this.zoomMax=this.config.zoomMax,this.timecodedGroupNodes=[],this.timelaneLanes=[],this.timelaneLanesMap=new Map,this.timelineHTMLElement=document.getElementById(this.timelineHTMLElementId),this.videoController=t}createCanvasNode(){let e=this.resolveStageDimension();return this.width=e.width,this.stage=new A.Stage({container:this.timelineHTMLElementId,...e}),this.layer=new A.Layer,this.stage.add(this.layer),this.layoutGroup=new A.Group({...F.POSITION_TOP_LEFT}),this.layer.add(this.layoutGroup),this.layoutBackground=new A.Rect({...F.POSITION_TOP_LEFT,fill:this.style.backgroundFill}),this.headerGroup=new A.Group({...F.POSITION_TOP_LEFT}),this.headerBackground=new A.Rect({...F.POSITION_TOP_LEFT,fill:this.style.headerBackgroundFill}),this.footerGroup=new A.Group({...F.POSITION_TOP_LEFT}),this.footerBackground=new A.Rect({...F.POSITION_TOP_LEFT,fill:this.style.footerBackgroundFill}),this.bodyGroup=new A.Group({...F.POSITION_TOP_LEFT}),this.bodyContentGroup=new A.Group({...F.POSITION_TOP_LEFT}),this.leftPanel=new A.Group({...F.POSITION_TOP_LEFT}),this.rightPanel=new A.Group({...F.POSITION_TOP_LEFT}),this.timecodedContainer=new A.Group({...F.POSITION_TOP_LEFT}),this.timecodedGroup=new A.Group({...F.POSITION_TOP_LEFT,draggable:!0}),this.timecodedBaseGroup=new A.Group({...F.POSITION_TOP_LEFT,name:"timecodedBaseGroup"}),this.timecodedThumbnailsGroup=new A.Group({...F.POSITION_TOP_LEFT,name:"timecodedThumbnailsGroup"}),this.timecodedSubtitlesGroup=new A.Group({...F.POSITION_TOP_LEFT,name:"timecodedSubtitlesGroup"}),this.timecodedAudioGroup=new A.Group({...F.POSITION_TOP_LEFT,name:"timecodedAudioGroup"}),this.timecodedMarkersGroup=new A.Group({...F.POSITION_TOP_LEFT,name:"timecodedMarkersGroup"}),this.timecodedSurfaceGroup=new A.Group({...F.POSITION_TOP_LEFT,name:"timecodedSurfaceGroup"}),this.timecodedBackground=new A.Rect({...F.POSITION_TOP_LEFT,fill:"yellow",opacity:0,listening:!1}),this.timecodedEventCatcher=yi.createEventCatcher(),this.thumbnailHover=new Zs({style:{visible:!1,stroke:this.style.thumbnailHoverStroke,strokeWidth:this.style.thumbnailHoverStrokeWidth}}),this.layoutGroup.add(this.layoutBackground),this.layoutGroup.add(this.headerGroup),this.layoutGroup.add(this.footerGroup),this.layoutGroup.add(this.bodyGroup),this.headerGroup.add(this.headerBackground),this.footerGroup.add(this.footerBackground),this.bodyGroup.add(this.bodyContentGroup),this.bodyGroup.add(this.leftPanel),this.bodyGroup.add(this.rightPanel),this.rightPanel.add(this.timecodedContainer),this.timecodedContainer.add(this.timecodedGroup),[this.timecodedBackground,this.timecodedEventCatcher,this.timecodedBaseGroup,this.timecodedThumbnailsGroup,this.timecodedSubtitlesGroup,this.timecodedAudioGroup,this.timecodedMarkersGroup,this.timecodedSurfaceGroup].forEach(t=>{this.timecodedGroupNodes.push(t),this.timecodedGroup.add(t)}),this.scrollbar=new Im({style:{height:this.style.scrollbarHeight}}),this.rightPanel.add(this.scrollbar.initCanvasNode()),this.playhead=new Fm({style:{visible:this.style.playheadVisible,fill:this.style.playheadFill,lineWidth:this.style.playheadLineWidth,symbolHeight:this.style.playheadSymbolHeight,backgroundFill:this.style.playheadBackgroundFill,backgroundOpacity:this.style.playheadBackgroundOpacity,scrubberHeight:this.style.playheadScrubberHeight,playProgressFill:this.style.playheadPlayProgressFill,playProgressOpacity:this.style.playheadPlayProgressOpacity,bufferedFill:this.style.playheadBufferedFill,bufferedOpacity:this.style.playheadBufferedOpacity}},this,this.videoController),this.playheadHover=new Gm({},this),[this.playhead,this.playheadHover].forEach(t=>{this.addToTimecodedSurfaceGroup(t.initCanvasNode())}),this.headerTimecodeDisplay=new Il({style:{x:10,y:10,visible:!1}},this.videoController),this.headerGroup.add(this.headerTimecodeDisplay.initCanvasNode()),this.settleLayout(),this.addToTimecodedSurfaceGroup(this.thumbnailHover.initCanvasNode()),this.scrubberLane=new $m({id:xa,description:""},this.videoController),this.addLanes([this.scrubberLane]),this.stage}afterCanvasNodeInit(){this.videoController.onVideoLoading$.pipe($e(e=>!!e),I(this.onDestroy$)).subscribe(e=>{this.clearContent()}),this.videoController.onVideoLoaded$.pipe($e(e=>!!e),I(this.onDestroy$)).subscribe(e=>{this.onVideoLoadedEvent(e)}),be(window,"resize").pipe(I(this.onDestroy$)).subscribe(e=>{setTimeout(()=>{this.onWindowResize(e)},200)}),this.timecodedGroup.on("mouseenter",e=>{this.playheadHover.toggleVisible(this.videoController.isVideoLoaded())}),this.timecodedGroup.on("mouseleave",e=>{this.playheadHover.toggleVisible(!1)}),this.timecodedGroup.on("mousemove",e=>{if(!this.videoController.isVideoLoaded())return;let t=this.timecodedGroup.getRelativePointerPosition().x;this.playheadHoverMove(t)}),this.timecodedMarkersGroup.on("mousemove",e=>{if(!this.videoController.isVideoLoaded())return;let t=this.timecodedGroup.getRelativePointerPosition().x;this.playheadHoverMove(t)}),this.timecodedGroup.on("wheel",e=>{if(!this.videoController.isVideoLoaded())return;if(this.mouseWheelEnabled){let i=e.evt;i.preventDefault();let s=i.deltaY>0?"IN":"OUT";i.ctrlKey&&(s=s==="IN"?"OUT":"IN"),this.zoomStep(s,this.timecodedGroup.getRelativePointerPosition().x),this.updateScrollWithPlayhead()}let t=this.timecodedGroup.getRelativePointerPosition().x;this.playheadHoverMove(t)}),this.timecodedGroup.on("dragstart dragmove dragend",e=>{if(!this.videoController.isVideoLoaded()){this.timecodedGroup.setAttrs({...F.POSITION_TOP_LEFT});return}if(e.target===this.timecodedGroup){let t=this.timecodedGroup.getPosition();this.timecodedGroup.setAttrs({x:this.getConstrainedTimelineX(t.x),y:0}),this.onScroll$.next(this.createScrollEvent()),this.scrollbar.updateScrollHandle(this)}this.updateScrollWithPlayhead()}),this.timecodedGroup.on("dragmove",e=>{et.cursor("grabbing")}),this.timecodedGroup.on("dragend",e=>{et.cursor("default")}),this.scrubberLane.onMouseMove$.pipe(I(this.onDestroy$)).subscribe(e=>{if(!this.videoController.isVideoLoaded())return;this.mouseWheelEnabled=!0;let t=this.timecodedGroup.getRelativePointerPosition().x,i=this.timelinePositionToTime(t);if(this.thumbnailVttFile){let s=this.thumbnailVttFile.findCue(i);this.showThumbnailHover(s)}}),this.scrubberLane.onMouseEnter$.pipe(I(this.onDestroy$)).subscribe(e=>{this.mouseWheelEnabled=!0}),this.scrubberLane.onMouseLeave$.pipe(I(this.onDestroy$)).subscribe(e=>{this.hideThumbnailHover(),this.mouseWheelEnabled=!1}),this.scrubberLane.onClick$.pipe(I(this.onDestroy$)).subscribe(e=>{if(!this.videoController.isVideoLoaded())return;this.updateScrollWithPlayhead();let t=this.timecodedGroup.getRelativePointerPosition().x;this.playheadHoverMove(t),this.videoController.isVideoLoaded()&&this.videoController.seekToTimestamp(this.timelinePositionToTime(t)).subscribe(()=>{})}),this.scrollbar.onScroll$.pipe(I(this.onDestroy$)).subscribe(e=>{this.videoController.isVideoLoaded()&&(this.setHorizontalScrollPercent(this.scrollbar.getScrollHandlePercent()),this.updateScrollWithPlayhead(),this.onScroll$.next(this.createScrollEvent()))}),this.scrollbar.onZoom$.pipe(I(this.onDestroy$)).subscribe(e=>{this.videoController.isVideoLoaded()&&(this.zoomByPercent(e.zoomPercent,!1),this.updateScrollWithPlayhead())}),this.thumbnailVttUrl&&this.fetchThumbnailVttFile().subscribe()}settleLayout(){this.stage.setAttrs({...this.resolveStageDimension()});let e=this.calculateHeights();this.headerGroup.setAttrs({width:this.width,height:this.style.headerHeight}),this.bodyGroup.setAttrs({y:this.headerGroup.y()+this.headerGroup.height(),width:this.layoutGroup.width(),height:e.bodyHeight}),this.footerGroup.setAttrs({y:this.bodyGroup.y()+this.bodyGroup.height(),width:this.width,height:this.style.footerHeight}),this.layoutGroup.setAttrs({width:this.width,height:e.layoutHeight}),this.layoutBackground.setAttrs({...this.layoutGroup.getSize()}),this.headerBackground.setAttrs({...this.headerGroup.getSize()}),this.footerBackground.setAttrs({...this.footerGroup.getSize()}),[this.bodyContentGroup].forEach(t=>{t.setAttrs({...this.bodyGroup.getSize()})}),[this.leftPanel,this.rightPanel].forEach(t=>{t.setAttrs({height:this.bodyGroup.getSize().height})}),this.leftPanel.setAttrs({width:this.leftPanelVisible?this.style.leftPanelWidth:0,visible:this.leftPanelVisible}),this.rightPanel.setAttrs({x:this.leftPanel.x()+this.leftPanel.width()+this.style.rightPanelLeftGutterWidth,width:this.layoutGroup.width()-(this.leftPanel.width()+this.style.rightPanelLeftGutterWidth+this.style.rightPanelRightGutterWidth)}),[this.timecodedContainer,this.timecodedGroup,...this.timecodedGroupNodes].forEach(t=>{t.setAttrs({...this.rightPanel.getSize()})}),this.timecodedContainer.clipFunc(t=>{t.rect(-this.style.timecodedContainerClipPadding,-500,this.timecodedContainer.width()+2*this.style.timecodedContainerClipPadding,this.timecodedContainer.height()+500)}),this.timecodedThumbnailsGroup.clipFunc(t=>{t.rect(0,0,this.timecodedThumbnailsGroup.width(),this.timecodedThumbnailsGroup.height())}),this.scrollbar.setPosition({...this.scrollbar.getPosition(),y:this.leftPanel.getSize().height}),this.scrollbar.setWidth(this.timecodedContainer.width()),this.scrollbar.updateScrollHandle(this),this.maxTimecodedGroupWidth=this.calculateWidthFromZoomRatioPercent(this.zoomMax),this.playheadHover.style={height:this.timecodedContainer.height()},this.timelaneLanes.forEach(t=>{t.onMeasurementsChange()}),this.playhead.onMeasurementsChange()}onMeasurementsChange(){this.settleLayout();let e=this.getTimecodedGroupDimension();this.timelaneLanes.forEach(t=>{t.onMeasurementsChange()}),this.zoomByWidth(e.width,this.resolveZoomFocus()),this.scrollbar.updateScrollHandle(this)}onWindowResize(e){let t=this.resolveStageDimension();this.width=t.width,this.onMeasurementsChange()}calculateHeights(){let t=this.getLanes().map(i=>i.getDimension().height).reduce((i,s)=>i+s,0);return{bodyHeight:t,layoutHeight:this.style.headerHeight+t+this.style.footerHeight}}resolveStageDimension(){let e=this.getTimelineHTMLElementRect(),t=this.calculateHeights();return{width:e.width>=this.style.stageMinWidth?e.width:this.style.stageMinWidth,height:t.layoutHeight}}getTimelineHTMLElementRect(){return{x:this.timelineHTMLElement.offsetLeft,y:this.timelineHTMLElement.offsetTop,width:this.timelineHTMLElement.offsetWidth,height:this.timelineHTMLElement.offsetHeight}}showThumbnailHover(e){if(e)if(this.thumbnailHover.setVisible(!0),this.thumbnailHover.getThumbnailVttCue()===e){this.thumbnailHover.setThumbnailVttCue(e);let t=this.resolveThumbnailPosition(this.thumbnailHover);this.thumbnailHover.setPosition(t),this.thumbnailHover.getCanvasNode().moveToTop()}else dt.createKonvaImageSizedByWidth(e.url,this.style.thumbnailHoverWidth).subscribe(t=>{this.thumbnailHover.setThumbnailVttCue(e),this.thumbnailHover.setDimension(t.getSize()),this.thumbnailHover.setImage(t),this.thumbnailHover.setPosition(this.resolveThumbnailPosition(this.thumbnailHover)),this.thumbnailHover.getCanvasNode().moveToTop()})}hideThumbnailHover(){this.thumbnailHover&&this.thumbnailHover.setVisible(!1)}resolveThumbnailPosition(e){let t=this.timecodedGroup.getRelativePointerPosition(),i=this.getTimecodedGroupDimension(),s=e.getImage().getSize(),n=t.x-s.width/2,a=e.style.strokeWidth>0?e.style.strokeWidth/2:0;n=n-a<0?a:n+s.width+a>i.width?i.width-s.width-a:n;let h=this.scrubberLane.getRect();return{x:n,y:h.y+h.height+e.style.strokeWidth/2+this.style.thumbnailHoverYOffset}}createScrollEvent(){return{scrollPercent:this.getHorizontalScrollPercent()}}createZoomEvent(){return{zoomPercent:this.getZoomPercent()}}getHorizontalScrollPercent(){if(this.isSnappedStart())return 0;if(this.isSnappedEnd())return 100;{let e=new Z(this.getTimecodedContainerDimension().width-this.getTimecodedGroupDimension().width).abs();return new Z(this.getTimecodedGroupPosition().x).abs().mul(100).div(e).toNumber()}}setHorizontalScrollPercent(e){this.setTimelinePosition(this.calculateTimelineXFromScrollPercent(e))}getScrollHandleHorizontalMeasurement(e){let t=this.getTimecodedGroupDimension().width,i=this.getTimecodedGroupPosition().x,s;return t<=e?s={width:e,x:0}:s={width:new Z(e).mul(e).div(t).round().toNumber(),x:new Z(i).abs().mul(e).div(t).toNumber()},s}scrollTo(e){return e=_e.coerce.number().min(0).max(100).parse(e),this.scrollToPercentEased(e)}scrollToPlayhead(){let e=-this.playhead.getPlayheadPosition()+this.getTimecodedContainerDimension().width/2;return this.scrollToEased(e)}scrollToPercent(e){let t=this.calculateTimelineXFromScrollPercent(e);this.scrollTimeline(t)}scrollToPercentEased(e){let t=this.calculateTimelineXFromScrollPercent(e);return this.scrollToEased(t)}scrollToEased(e){return new se(t=>{let i=this.getTimecodedGroupPosition().x;Xs({layer:this.timecodedGroup.getLayer(),duration:F.TIMELINE_SCROLL_EASED_DURATION_MS,from:i,to:e,onUpdateHandler:(s,n)=>{this.scrollTimeline(n)},onCompleteHandler:(s,n)=>{t.next(this.getHorizontalScrollPercent()),t.complete()}})})}isPlayheadInTimecodedView(){return this.isInVisiblePositionRange(this.playhead.getPlayheadPosition())}updateScrollWithPlayhead(){let e=this.playhead.getPlayheadPosition(),t=e<this.getVisiblePositionRange().start,i=this.isInVisiblePositionRange(e);this.scrollWithPlayhead=i&&!t}syncTimelineWithPlayhead(){return new se(e=>{this.scrollToEased(-this.playhead.getPlayheadPosition()).pipe(ke(t=>{e.next(this.getHorizontalScrollPercent()),e.complete()})).subscribe()})}setTimelinePosition(e){let t=this.getConstrainedTimelineX(e);this.timecodedGroup.x(t)}scrollTimeline(e){let t=this.getTimecodedGroupPosition().x;this.setTimelinePosition(e),this.getTimecodedGroupPosition().x!==t&&(this.scrollbar.updateScrollHandle(this),this.setHorizontalScrollPercent(this.scrollbar.getScrollHandlePercent()),this.onScroll$.next(this.createScrollEvent()))}calculateTimelineXFromScrollPercent(e){e=this.getConstrainedScrollPercent(e);let t=this.getTimecodedGroupDimension(),i=this.getTimecodedContainerDimension();if(t.width>i.width){let s=new Z(i.width-t.width);return new Z(e).mul(s).div(100).toDecimalPlaces(2).toNumber()}else return 0}getZoomPercent(){let e=this.getTimecodedGroupDimension(),t=this.getTimecodedContainerDimension();return e.width>t.width?new Z(e.width).mul(100).div(t.width).round().toNumber():this.zoomBaseline}zoomTo(e){return e=_e.coerce.number().min(this.getZoomBaseline()).max(this.getZoomMax()).parse(e),this.zoomToEased(e)}zoomIn(){return new se(e=>{this.zoomStep("IN",this.timecodedGroup.getRelativePointerPosition().x),e.next(this.getZoomPercent()),e.complete()})}zoomOut(){return new se(e=>{this.zoomStep("OUT",this.timecodedGroup.getRelativePointerPosition().x),e.next(this.getZoomPercent()),e.complete()})}zoomToEased(e){return new se(t=>{e=this.getConstrainedZoomPercent(e);let i=this.getTimecodedGroupDimension().width,s=this.calculateWidthFromZoomRatioPercent(e);Xs({layer:this.timecodedGroup.getLayer(),duration:F.TIMELINE_ZOOM_EASED_DURATION_MS,from:i,to:s,onUpdateHandler:(n,a)=>{this.zoomByWidth(a,this.resolveZoomFocus())},onCompleteHandler:(n,a)=>{t.next(this.getZoomPercent()),t.complete()}})})}zoomStep(e,t){let i=new Z(this.getTimecodedGroupDimension().width),s=(e==="IN"?i.mul(this.zoomScale):i.div(this.zoomScale)).round().toNumber();this.zoomByWidth(s,t)}zoomByPercent(e,t=!0){e=this.getConstrainedZoomPercent(e);let i=this.calculateWidthFromZoomRatioPercent(e);return this.zoomByWidth(i,this.resolveZoomFocus(),t),this.getZoomPercent()}zoomByWidth(e,t,i=!0){let s=this.getTimecodedGroupPosition().x,n=this.getTimecodedGroupDimension().width;e=this.getConstrainedWidth(e);let a=this.calculateNewPosition(e,t);this.hideThumbnailHover(),this.timecodedGroup.setAttrs({width:e,x:a}),this.timecodedGroupNodes.forEach(h=>{h.width(e)}),(this.getTimecodedGroupDimension().width!==n||this.getTimecodedGroupPosition().x!==s)&&(i?this.scrollbar.updateScrollHandle(this):this.playheadHover.toggleVisible(!1),this.setHorizontalScrollPercent(this.scrollbar.getScrollHandlePercent()),this.onZoom$.next(this.createZoomEvent()),this.onScroll$.next(this.createScrollEvent()))}calculateNewPosition(e,t=0){let i=this.getTimecodedGroupPosition().x,s=this.getTimecodedGroupDimension().width,n=this.getTimecodedContainerRect(),a=e>s?"IN":"OUT",o=i;if(e===n.width)o=0;else if(e>n.width){if(t>0){let h=new Z(t).div(s);if(h.greaterThanOrEqualTo(0)&&h.lessThanOrEqualTo(1)){let l=e-s,d=h.mul(l).abs().round().toNumber(),u=i+d*(a==="IN"?-1:1);o=u<0?u:0}}if(e>n.width){let h=n.x+n.width;o+e<=h&&(o=n.width-e)}}return o}resolveZoomFocus(){return this.videoController.isVideoLoaded()?this.resolvePlayheadSyncPosition():this.isSnappedStart()?0:this.isSnappedEnd()?this.getTimecodedGroupDimension().width:this.getTimecodedGroupDimension().width/2}calculateWidthFromZoomRatioPercent(e){return new Z(this.getTimecodedContainerDimension().width).mul(e).div(100).round().toNumber()}getConstrainedWidth(e){let t=this.getTimecodedContainerDimension();return e>=t.width?e<=this.maxTimecodedGroupWidth?e:this.maxTimecodedGroupWidth:t.width}getConstrainedZoomPercent(e){return e<this.zoomBaseline?this.zoomBaseline:e>this.zoomMax?this.zoomMax:e}getConstrainedScrollPercent(e){return e<0?0:e>100?100:e}playheadHoverMove(e){if(this.videoController.isVideoLoaded()&&this.playheadHover){let t=!1;if(!this.videoController.isPlaying()){let i=this.resolvePlayheadSyncPosition();e>i-this.playheadHoverSnapArea&&e<i+this.playheadHoverSnapArea&&(e=i,t=!0)}this.playheadHover.sync(e,t)}}resolvePlayheadSyncPosition(){return this.timeToTimelinePosition(this.videoController.getCurrentTime())}onVideoLoadedEvent(e){this.fireVideoEventBreaker(),this.clearContent(),this.syncVideoMetadata(),this.videoController.onVideoTimeChange$.pipe(I(this.videoEventBreaker$)).subscribe(t=>{this.syncVideoMetadata()}),this.videoController.onPlay$.pipe(I(this.videoEventBreaker$)).subscribe(t=>{this.updateScrollWithPlayhead()})}fireVideoEventBreaker(){this.videoEventBreaker$&&(this.videoEventBreaker$.next(),this.videoEventBreaker$.complete()),this.videoEventBreaker$=new V}setThumbnailVttFile(e){this.thumbnailVttFile=e}syncVideoMetadata(){this.scrollWithPlayhead&&!this.isPlayheadInTimecodedView()&&!this.syncTimelineWithPlayheadInProgress&&(this.syncTimelineWithPlayheadInProgress=!0,this.syncTimelineWithPlayhead().subscribe(e=>{this.syncTimelineWithPlayheadInProgress=!1}))}addLane(e){if(this.timelaneLanesMap.has(e.getId()))throw new Error(`TimelineLane with id=${e.getId()} already exist`);let t=this.timelaneLanes.length<1,i={...F.POSITION_TOP_LEFT};t||(i.y=this.timelaneLanes.map(s=>s.getRect().height).reduce((s,n)=>s+n,0)),e.setTimeline(this),e.setVideoController(this.videoController),e.setTimelinePosition(i),e.initCanvasNode(),this.timelaneLanes.push(e),this.timelaneLanesMap.set(e.getId(),e),this.bodyContentGroup.add(e.getCanvasNode()),this.settleLayout()}removeLane(e){if(!this.timelaneLanesMap.has(e))throw new Error(`TimelineLane with id=${e} doesn't exist`);let t=this.timelaneLanesMap.get(e);this.timelaneLanes.splice(this.timelaneLanes.findIndex(s=>s.getId()===e),1),this.timelaneLanesMap.delete(e),t.clearContent(),t.destroy();let i={...F.POSITION_TOP_LEFT};this.timelaneLanes.forEach(s=>{s.setTimelinePosition({...i}),i.y=i.y+s.getRect().height}),this.timelaneLanes.forEach(s=>{s.onMeasurementsChange()}),this.settleLayout()}getScrollbar(){return this.scrollbar}addLanes(e){e.forEach(t=>this.addLane(t))}getLanes(){return[...this.timelaneLanesMap.values()]}getLane(e){return this.timelaneLanesMap.get(e)}getScrubberLane(){return this.getLane(xa)}getMarkerLane(e){let t=this.getLane(e);return t instanceof Bs?t:void 0}getThumbnailLane(e){let t=this.getLane(e);return t instanceof js?t:void 0}getSubtitlesLane(e){let t=this.getLane(e);return t instanceof Us?t:void 0}getAudioTrackLane(e){let t=this.getLane(e);return t instanceof Rl?t:void 0}createMarkerLane(e){let t=new Bs(e);return this.addLane(t),t}createThumbnailLane(e){let t=new js(e);return this.addLane(t),t}createSubtitlesLane(e){let t=new Us(e);return this.addLane(t),t}isTimelineReady(){return this.videoController.isVideoLoaded()}addToTimecodedBaseGroup(e){this.timecodedBaseGroup.add(e)}addToTimecodedSurfaceGroup(e){this.timecodedSurfaceGroup.add(e)}addToTimecodedMarkersGroup(e){this.timecodedMarkersGroup.add(e)}addToTimecodedThumbnailsGroup(e){this.timecodedThumbnailsGroup.add(e)}addToTimecodedSubtitlesGroup(e){this.timecodedSubtitlesGroup.add(e)}addToTimecodedAudioGroup(e){this.timecodedAudioGroup.add(e)}constrainTimelinePosition(e){let t=this.getTimecodedGroupDimension();return e<0?0:e>t.width?t.width:e}timelinePositionToTime(e){let t=this.constrainTimelinePosition(e);return this.videoController.isVideoLoaded()?new Z(t).mul(this.videoController.getDuration()).div(this.getTimecodedGroupDimension().width).toNumber():0}timelinePositionToTimeFormatted(e){return this.videoController.isVideoLoaded()?this.videoController.formatTimestamp(this.timelinePositionToTime(e)):""}timelinePositionToFrame(e){return this.videoController.isVideoLoaded()?this.videoController.calculateTimeToFrame(this.timelinePositionToTime(e)):0}timeToTimelinePosition(e){return new Z(e).mul(this.getTimecodedGroupDimension().width).div(this.videoController.getDuration()).toNumber()}getConstrainedTimelineX(e){let t=this.getTimecodedGroupDimension(),i=this.getTimecodedContainerDimension();if(t.width<=i.width)return 0;{let s=i.width-t.width;return e<s?s:e>0?0:e}}getBodyGroupRect(){return{...this.bodyGroup.getPosition(),...this.bodyGroup.getSize()}}getLeftPanelRect(){return{...this.leftPanel.getPosition(),...this.leftPanel.getSize()}}getLeftPanelVisible(){return this.leftPanelVisible}getRightPanelRect(){return{...this.rightPanel.getSize(),...this.rightPanel.getPosition()}}getTimecodedContainerDimension(){return this.timecodedContainer.getSize()}getTimecodedContainerPosition(){return this.timecodedContainer.getPosition()}getTimecodedContainerRect(){return{...this.getTimecodedContainerDimension(),...this.getTimecodedContainerPosition()}}getTimecodedGroupDimension(){return this.timecodedGroup.getSize()}getTimecodedGroupPosition(){return this.timecodedGroup.getPosition()}getTimecodedGroupRect(){return{...this.timecodedGroup.getPosition(),...this.timecodedGroup.getSize()}}getTimecodedGroupHorizontalMeasurement(){return{x:this.timecodedGroup.x(),width:this.timecodedGroup.width()}}getRelativePointerPosition(){return this.timecodedGroup.getRelativePointerPosition()}getLayoutGroupDimension(){return this.layoutGroup.getSize()}getLayoutGroupPosition(){return this.layoutGroup.getPosition()}getRect(){return{...this.getLayoutGroupDimension(),...this.getLayoutGroupPosition()}}getVisiblePositionRange(){let e=Math.abs(this.timecodedGroup.x()),t=e+this.timecodedContainer.width();return{start:e,end:t}}isInVisiblePositionRange(e){let t=this.getVisiblePositionRange();return e>=t.start&&e<=t.end}isSnappedStart(){return this.getTimecodedGroupPosition().x===0}isSnappedEnd(){return this.getTimecodedContainerDimension().width-this.getTimecodedGroupDimension().width===this.getTimecodedGroupPosition().x}getVisibleTimeRange(){let e=this.getVisiblePositionRange(),t=this.timelinePositionToTime(e.start),i=this.timelinePositionToTime(e.end);return{start:t,end:i}}getZoomBaseline(){return this.zoomBaseline}getZoomMax(){return this.zoomMax}fetchThumbnailVttFile(){return this.thumbnailVttUrl?ss.create(this.thumbnailVttUrl,this.axiosConfig).pipe(ke(e=>(this.thumbnailVttFile=e,e)),gi((e,t)=>Ee(void 0))):Ee(void 0)}toggleLeftPanelVisible(e){this.leftPanelVisible=e,this.leftPanel.visible(e),this.settleLayout(),this.timelaneLanes.forEach(t=>{t.onMeasurementsChange()}),this.headerTimecodeDisplay.setVisible(!e)}clearContent(){this.setThumbnailVttFile(void 0),this.timelaneLanes.forEach(e=>{e.clearContent()}),this.zoomByPercent(this.zoomBaseline)}}class qs{static timeToFrame(e,t){return t.mul(e).floor().toNumber()}static frameToTime(e,t){return new Z(e).dividedBy(t).toNumber()}}function Wm(r){r.next(),r.complete()}class ti{constructor(){this.resolveUserAgent()}static instance(){return ti._instance||(ti._instance=new ti),ti._instance}resolveUserAgent(){this._userAgent=window.navigator&&window.navigator.userAgent||"",this._isAndroid=/Android/i.test(this._userAgent),this._isFirefox=/Firefox/i.test(this._userAgent),this._isEdge=/Edg/i.test(this._userAgent),this._isChromium=/Chrome/i.test(this._userAgent)||/CriOS/i.test(this._userAgent),this._isChrome=!this.isEdge&&this.isChromium,this._isSafari=/Safari/i.test(this._userAgent)&&!this.isChrome&&!this.isAndroid&&!this.isEdge}get isSafari(){return this._isSafari}get isFirefox(){return this._isFirefox}get isEdge(){return this._isEdge}get isChromium(){return this._isChromium}get isChrome(){return this._isChrome}get isAndroid(){return this._isAndroid}}const Qe=class{static formatVideoTimestamp(r,e){if(r<=0)return Qe.VIDEO_ZERO_TIMESTAMP;const t=Math.floor(r/3600),i=Math.floor(r%3600/60),s=Math.floor(r%60);let n=new Z(qs.timeToFrame(r,e)).mod(e).toNumber();return`${Qe.padZero(t)}:${Qe.padZero(i)}:${Qe.padZero(s)}:${Qe.padZero(n)}`}static padZero(r,e=2){return r.toString().padStart(e,"0")}};let Ys=Qe;Ys.VIDEO_ZERO_TIMESTAMP=`${Qe.padZero(0)}:${Qe.padZero(0)}:${Qe.padZero(0)}:${Qe.padZero(0)}`;class Um{constructor(){this._state={playing:!1,paused:!0,waiting:!1,seeking:!1,buffering:!1,ended:!1},this.onChange$=new Qt(this._state)}updateState(e){let t={...this._state,...e},i=this.compare(this._state,t)===0;this._state=t,i||this.onChange$.next(this._state)}compare(e,t){return e.playing===t.playing&&e.paused===t.paused&&e.waiting===t.waiting&&e.seeking===t.seeking&&e.buffering===t.buffering&&e.ended===t.ended?0:-1}get state(){return this._state}setPlaying(){this.updateState({playing:!0,paused:!1,waiting:!1,seeking:!1,buffering:!1,ended:!1})}setPaused(){this.updateState({playing:!1,paused:!0,waiting:!1,seeking:!1,buffering:!1,ended:!1})}setEnded(){this.updateState({playing:!1,paused:!0,waiting:!1,seeking:!1,buffering:!1,ended:!0})}set waiting(e){this.updateState({waiting:e})}set seeking(e){this.updateState({seeking:e})}set buffering(e){this.updateState({buffering:e})}}function Pa(r){let e;return typeof r=="string"?e=r:r instanceof it?(console.log(r),e=r.errors.map(t=>t.message).join(". ")):r instanceof Error?e=r.message:e="Unexpected error",e}function Zm(r){return{errorMap:(e,t)=>({message:r})}}const We={PAUSE:"pause",WAITING:"waiting",PLAYING:"playing",TIMEUPDATE:"timeupdate",SEEKING:"seeking",SEEKED:"seeked",LOADEDDATA:"loadeddata",LOADEDMETEDATA:"loadedmetadata",ENDED:"ended",PROGRESS:"progress"};class jm{constructor(e,t){if(this.browserProvider=ti.instance(),this.helpMenuGroups=[],this._isVideoLoaded=!1,this.frameDurationSpillOverCorrection=1e-6,this.syncLoopMaxIterations=20,this.seekInProgress=!1,this.videoStalledCheckIntervalMs=700,this.videoFrameCallback$=new Qt(null),this.videoEventBreaker$=new V,this.seekBreaker$=new V,this.onVideoLoaded$=new Qt(void 0),this.onVideoLoading$=new V,this.onPlay$=new V,this.onPause$=new V,this.onVideoTimeChange$=new V,this.onSeeking$=new V,this.onSeeked$=new V,this.onBuffering$=new V,this.onEnded$=new V,this.onAudioSwitched$=new V,this.onPlaybackState$=new V,this.onHelpMenuChange$=new Qt(void 0),this.onVideoError$=new V,this.domController=e,this.crossorigin=t,this.videoElement=this.domController.videoElement,this.videoElement.crossOrigin=this.crossorigin,!this.videoElement)throw new Error("VideoController element not set");this.videoFrameCallback$.subscribe(i=>{i&&(this.seekInProgress||(this.isPlaying()?this.videoTimeChangeHandlerExecutor():this.isPaused()))})}loadVideo(e,t,i){try{return e=ai.url()(e),t=_e.coerce.number().min(0).max(100).parse(t,Zm("Invalid frameRate")),this.onVideoLoading$.next({sourceUrl:e,frameRate:t}),this._isVideoLoaded=!1,this.video=void 0,this.detachVideoEventListeners(),this.videoLoad(e,t,i).pipe(ke(s=>(this.video=s,this.frameRateDecimal=new Z(this.video.frameRate),this.syncStepCurrentTimeMediaTime=new Z(this.video.frameDuration).div(10).toNumber(),this.playbackStateMachine=new Um,this.initEventHandlers(),this.startVideoFrameCallback(),this._isVideoLoaded=!0,this.onVideoLoaded$.next({video:this.video}),s)),gi((s,n)=>{let a=Pa(s);return this.onVideoError$.next({type:"VIDEO_LOAD_ERROR",message:a}),Kn(()=>new Error(a))}))}catch(s){let n=Pa(s);return this.onVideoError$.next({type:"VIDEO_LOAD_ERROR",message:n}),Kn(()=>new Error(n))}}initEventHandlers(){be(this.videoElement,We.PAUSE).pipe(I(this.videoEventBreaker$)).subscribe(e=>{if(this.browserProvider.isSafari){let t=this.getCurrentTime()+this.video.frameDuration;this._seekTimeAndSyncNoEmitEvents(t).subscribe(i=>{this.videoTimeChangeHandlerExecutor(),this.onPause$.next({})})}else this.syncVideoFrames({}).subscribe(t=>{this.videoTimeChangeHandlerExecutor(),this.onPause$.next({})})}),be(this.videoElement,We.WAITING).pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.waiting=!0}),be(this.videoElement,We.PLAYING).pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.setPlaying(),this.videoStalledCheckLastCurrentTime=void 0}),be(this.videoElement,We.PAUSE).pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.setPaused(),this.videoStalledCheckLastCurrentTime=void 0}),be(this.videoElement,We.TIMEUPDATE).pipe(I(this.videoEventBreaker$)).subscribe(e=>{}),be(this.videoElement,We.PROGRESS).pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.onBuffering$.next({bufferedTimespans:this.getBufferedTimespans()})}),be(this.videoElement,We.ENDED).pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.onEnded$.next({})}),this.playbackStateMachine.onChange$.pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.onPlaybackState$.next(e)}),this.onPlay$.pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.setPlaying(),this.videoStalledCheckLastCurrentTime=void 0}),this.onPause$.pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.setPaused(),this.videoStalledCheckLastCurrentTime=void 0}),this.onSeeking$.pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.seeking=!0}),this.onSeeked$.pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.seeking=!1}),this.onEnded$.pipe(I(this.videoEventBreaker$)).subscribe(e=>{this.playbackStateMachine.setEnded(),this.videoStalledCheckLastCurrentTime=void 0}),zu(this.videoStalledCheckIntervalMs).pipe(I(this.videoEventBreaker$)).subscribe(e=>{let t=this.getCurrentTime();if(!this.videoStalledCheckLastCurrentTime){this.videoStalledCheckLastCurrentTime=t;return}if(this.playbackStateMachine.state.playing){let i=this.videoStalledCheckIntervalMs*.8/1e3*this.getPlaybackRate(),s=this.videoStalledCheckLastCurrentTime+i,n=t<s;this.playbackStateMachine.waiting=n,this.videoStalledCheckLastCurrentTime=t}})}getBufferedTimespans(){if(!this.isVideoLoaded())return[];let e=[],t=this.videoElement.buffered;for(let i=0;i<t.length;i++)e.push({start:t.start(i),end:t.end(i)});return e}startVideoFrameCallback(){let e=()=>{this.videoFrameCallbackHandle=this.videoElement.requestVideoFrameCallback((i,s)=>{t({now:i,metadata:s})})},t=i=>{this.videoFrameCallback$.next(i),e()};e()}detachVideoEventListeners(){this.videoEventBreaker$&&(this.videoEventBreaker$.next(),this.videoEventBreaker$.complete()),this.videoEventBreaker$=new V,this.videoElement&&this.videoFrameCallbackHandle&&this.videoElement.cancelVideoFrameCallback(this.videoFrameCallbackHandle)}syncVideoFrames(e){return console.debug("syncFrames - START",e),new se(t=>{let i=new Qt(!1),s=new V,n=this.syncLoopMaxIterations;this.seekBreaker$.pipe(I(s)).subscribe(()=>{console.debug("%csyncFrames - seek breaker triggered","color: gray"),i.next(!0),a()});let a=()=>{Wm(s),t.next(),t.complete(),console.debug("%csyncFrames - END","color: gray")},o=h=>{i.pipe(ct(1)).subscribe(l=>{l?console.debug("%csyncFrames - seek skipped, breaker already triggered","color: gray"):this._seekTimeFireAndForget(h)})};if(this.isPlaying())console.debug("%csyncFrames - SKIPPED: video is playing","color: gray"),a();else{let h=u=>{let c=this.getCurrentTime(),p=this.calculateTimeToFrame(c),f=u?u.metadata.mediaTime:void 0,m=f?this.calculateTimeToFrame(f):void 0;if(this.isPlaying())return console.debug("%csyncFrames - UNKNOWN: video is playing","color: gray"),!0;if(p===0)return console.debug(`%csyncFrames - OK: currentTimeFrame[${p}] === 0`,"color: green"),!0;if(e.seekToFrame){if(e.seekToFrame===p&&(p===m||!m))return console.debug(`%csyncFrames - OK: ((currentTimeFrame[${p}] === mediaTimeFrame[${m}]) || !mediaTimeFrame[${m}])`,"color: green"),!0}else if(p===m||!m)return console.debug(`%csyncFrames - OK: currentTimeFrame[${p}] === mediaTimeFrame[${m}]`,"color: green"),!0;return!1},l,d=u=>{if(console.debug(`syncFrames.syncLoop - START (${this.syncLoopMaxIterations-n})`,{syncConditions:e,videoFrameCallbackData:u,dropped:this.videoElement.getVideoPlaybackQuality()}),this.isPlaying()){a();return}if(h(u)){a();return}let c=this.getCurrentTime(),p=this.calculateTimeToFrame(c),f=u?u.metadata.mediaTime:void 0,m=f?this.calculateTimeToFrame(f):void 0;if(n--<=0){console.debug(`%csyncFrames - TOO MANY SYNCs, EXITING.. : currentTime[${c}], mediaTime[${f}], currentTimeFrame[${p}], mediaTimeFrame[${m}]`,"color: red"),a();return}if(console.debug(`syncFrames - currentTime[${c}], mediaTime[${f}], currentTimeFrame[${p}], mediaTimeFrame[${m}], `),e.seekToFrame)if(l||(l=c),e.seekToFrame===p)if(p===m||!m)console.debug(`%csyncFrames - OK: ((currentTimeFrame[${p}] === mediaTimeFrame[${m}]) || !mediaTimeFrame[${m}])`,"color: green"),a();else{console.debug(`%csyncFrames - CORRECTION SEEK TO FRAME; currentTimeFrame[${p}] ${p>m?">":"<"} mediaTimeFrame[${m}]`,"color: red");let v=Math.abs(p-m);console.debug(`%csyncFrames - frameDiff: ${v}`,"color: orange");let _=this.syncStepCurrentTimeMediaTime*(p>m?1:-1);o(Z.add(c,_).toNumber())}else{console.debug(`%csyncFrames - CORRECTION SEEK TO FRAME; syncConditions.seekToFrame[${e.seekToFrame}] !== currentTimeFrame[${p}] | seekToFrameTimeBaseline=${l}`,"color: red");let v=Math.abs(e.seekToFrame-p),_=v*this.video.frameDuration,b=(e.seekToFrame>=p?Z.add(l,_):Z.sub(l,_)).toNumber();l=b,console.debug(`%csyncFrames - frameDiff: ${v}`,"color: orange"),console.debug(`%csyncFrames - frameCorrectionTime: ${_}`,"color: orange"),console.debug(`%csyncFrames - seekTo: ${b}`,"color: orange"),o(b)}else p===m||!m?(console.debug(`%csyncFrames - OK: currentTimeFrame[${p}] === mediaTimeFrame[${m}]`,"color: green"),a()):(console.debug(`%csyncFrames - CORRECTION; currentTimeFrame[${p}] ${p>m?">":"<"} mediaTimeFrame[${m}]`,"color: red"),p>m?o(Z.add(c,this.syncStepCurrentTimeMediaTime).toNumber()):o(f+this.syncStepCurrentTimeMediaTime));console.debug("syncFrames.syncLoop - END")};this.videoFrameCallback$.pipe(ju((e.seekToFrame,0)),I(s)).subscribe(u=>{console.debug("syncFrames.syncLoop - videoFrameCallback$ trigger",u),d(u)})}})}seekTimeAndSync(e,t={}){return new se(i=>{this.seekInProgress&&(this.seekBreaker$.next(),this.seekBreaker$.complete(),this.seekBreaker$=new V),this.seekInProgress=!0,isNaN(e)||(e=e<0?0:e>this.getDuration()?this.getDuration():e,be(this.videoElement,We.SEEKING).pipe(I(this.seekBreaker$),ct(1)).subscribe(s=>{this.onSeeking$.next({newTime:e,currentTime:this.getCurrentTime()})}),be(this.videoElement,We.SEEKED).pipe(I(this.seekBreaker$),ct(1)).subscribe(s=>{this.syncVideoFrames(t).subscribe(n=>{this.onSeeked$.next({currentTime:this.getCurrentTime()}),this.seekInProgress=!1,i.next(!0),i.complete(),this.videoTimeChangeHandlerExecutor()})}),console.debug(`Seeking to timestamp: ${e}`),this.setCurrentTime(e))})}_seekTimeFireAndForget(e){if(!isNaN(e)){let t=this.getCurrentTime();e=e<0?0:e>this.getDuration()?this.getDuration():e;let i=e>t?"FORWARD":"BACKWARD",s=Z.sub(t,e).abs();console.debug(`Seeking from currentTime[${t}] to newTime[${e}], direction: ${i} ${s.toNumber()}`),this.setCurrentTime(e)}}_seekTimeAndSyncNoEmitEvents(e){return this.isPlaying()?Ee(!1):new se(t=>{isNaN(e)||(e=e<0?0:e>this.getDuration()?this.getDuration():e,be(this.videoElement,We.SEEKED).pipe(hi()).subscribe(i=>{this.syncVideoFrames({}).subscribe(s=>{t.next(!0),t.complete(),this.videoTimeChangeHandlerExecutor()})}),console.debug(`Seeking ${e}`),this.setCurrentTime(e))})}seekFromCurrentTimeAndSync(e,t={}){let i=this.getCurrentTime(),s=Z.add(i,e).toNumber(),n=s>i?"FORWARD":"BACKWARD",a=Z.sub(i,s).abs().toNumber();return console.debug(`Seeking from currentTime ${i} to ${s}, direction: ${n} ${a}`),this.seekTimeAndSync(s,t)}setCurrentTime(e){this.videoElement.currentTime=e}getFrameRateDecimal(){return this.frameRateDecimal}_seekToFrame(e){if(!this.isPlaying()&&!isNaN(e)){if(console.debug(`Seeking to frame: ${e}`),e<=0)return this.seekTimeAndSync(0,{});{let t=this.calculateFrameToTime(e)+new Z(this.frameDurationSpillOverCorrection).toNumber(),i=this.calculateTimeToFrame(t);return i!==e?(console.error(`Frame numbers don't match. Wanted: ${e}, calculated: ${i}`),Ee(!1)):this.seekTimeAndSync(t,{seekToFrame:e,seekToTimestamp:t,currentTime:this.getCurrentTime()}).pipe(ke(s=>s))}}}_seekFromCurrentFrame(e){let t=this.getCurrentFrame(),i=t+e;if(console.debug(`seekFromCurrentFrame - Current frame: ${t}, wanted frame: ${i}`),t!==i){if(i<=0)return this._seekToFrame(0);if(i>=this.getTotalFrames())return this._seekToFrame(this.getTotalFrames());{let s=this.calculateFrameToTime(e);return this.seekFromCurrentTimeAndSync(s,{seekToFrame:i,currentTime:this.getCurrentTime()}).pipe(ke(n=>n))}}else return Ee(!0)}videoTimeChangeHandlerExecutor(){let e=this.getCurrentTime(),t=this.getCurrentFrame();this.onVideoTimeChange$.next({currentTime:e,frame:t})}getPlaybackState(){return this.playbackStateMachine.state}getVideo(){return this.isVideoLoaded()?this.video:void 0}getHTMLVideoElement(){return this.videoElement}calculateTimeToFrame(e){return qs.timeToFrame(e,this.getFrameRateDecimal())}calculateFrameToTime(e){return qs.frameToTime(e,this.getFrameRateDecimal())}play(){this.isVideoLoaded()&&!this.isPlaying()&&this.videoElement.play().then(()=>{this.onPlay$.next({})})}pause(){this.isVideoLoaded()&&this.isPlaying()&&this.videoElement.pause()}togglePlayPause(){this.isPlaying()?this.pause():this.play()}isPlaying(){return this.isVideoLoaded()&&this.videoElement.currentTime>0&&this.videoElement.currentTime<this.getDuration()&&!this.videoElement.paused&&!this.videoElement.ended&&this.videoElement.readyState>this.videoElement.HAVE_CURRENT_DATA}isPaused(){return!this.isPlaying()}isSeeking(){return this.seekInProgress}getCurrentTime(){return this.isVideoLoaded()?this.videoElement.currentTime:0}getPlaybackRate(){return this.isVideoLoaded()?this.videoElement.playbackRate:0}setPlaybackRate(e){if(this.isVideoLoaded()){try{e=_e.coerce.number().min(.1).max(16).default(1).parse(e)}catch{e=1}this.videoElement.playbackRate=e}}getVolume(){return this.isVideoLoaded()?this.videoElement.volume:0}setVolume(e){if(this.isVideoLoaded()){try{e=_e.coerce.number().min(0).max(1).default(1).parse(e)}catch{e=1}this.videoElement.volume=e}}getDuration(){return this.isVideoLoaded()?this.video.duration:0}getFrameRate(){return this.isVideoLoaded()?this.video.frameRate:0}getTotalFrames(){return this.isVideoLoaded()?this.video.totalFrames:0}getCurrentFrame(){return this.isVideoLoaded()?this.calculateTimeToFrame(this.getCurrentTime()):0}seekToFrame(e){return this.isVideoLoaded()?(e=_e.coerce.number().min(0).max(this.getTotalFrames()).parse(e),this._seekToFrame(e)):Ee(!1)}seekFromCurrentFrame(e){return this.isVideoLoaded()?(e=_e.coerce.number().parse(e),this._seekFromCurrentFrame(e)):Ee(!1)}seekPreviousFrame(){return this.isVideoLoaded()?this.seekFromCurrentFrame(-1):Ee(!1)}seekNextFrame(){return this.isVideoLoaded()?this.seekFromCurrentFrame(1):Ee(!1)}seekToTimestamp(e){return this.isVideoLoaded()?(e=_e.coerce.number().parse(e),this.seekTimeAndSync(e)):Ee(!1)}formatTimestamp(e){return this.isVideoLoaded()?(e=_e.coerce.number().min(0).max(this.getDuration()).parse(e),Ys.formatVideoTimestamp(e,this.getFrameRateDecimal())):Ys.VIDEO_ZERO_TIMESTAMP}mute(){this.isVideoLoaded()&&(this.videoElement.muted=!0)}unmute(){this.isVideoLoaded()&&(this.videoElement.muted=!1)}isFullscreen(){return this.isVideoLoaded()?this.domController.isFullscreen():!1}toggleFullscreen(){this.isVideoLoaded()&&this.domController.toggleFullscreen(this.videoElement)}getAudioTracks(){throw new Error("unsupported")}getCurrentAudioTrack(){throw new Error("unsupported")}setAudioTrack(e){throw new Error("unsupported")}isVideoLoaded(){return this._isVideoLoaded}getHls(){throw new Error("Unsupported or video not loaded with Hls.js")}addHelpMenuGroup(e){this.helpMenuGroups.push(e),this.onHelpMenuChange$.next()}getHelpMenuGroups(){return this.helpMenuGroups}destroy(){this.videoEventBreaker$&&(this.videoEventBreaker$.next(),this.videoEventBreaker$.complete()),this.videoElement=null,this.domController=null,this._isVideoLoaded=!1}}class Xm{constructor(e,t,i,s){this._element=e,this._sourceUrl=t,this._frameRate=i,this._duration=s,this._totalFrames=new Z(this._duration).mul(this._frameRate).toNumber(),this._frameDuration=new Z(1).div(this._frameRate).toNumber()}get element(){return this._element}get sourceUrl(){return this._sourceUrl}get frameRate(){return this._frameRate}get duration(){return this._duration}get totalFrames(){return this._totalFrames}get frameDuration(){return this._frameDuration}}class qm extends jm{constructor(e,t){super(e,t),ze.isSupported()?console.debug("video load with hls.js"):console.error("hls is not supported through MediaSource extensions");let i={...ze.DefaultConfig,enableWorker:!1};this.hls=new ze(i)}videoLoad(e,t,i){return new se(s=>{this.hls.on(ze.Events.ERROR,function(h,l){l.type;let d=l.details;l.fatal,d.includes("audioTrackLoadError")||(s.error(`Error loading video. Hls error details: ${d}`),s.complete())});let n=new se(h=>{this.hls.once(ze.Events.MEDIA_ATTACHED,function(l,d){console.debug("video element and hls.js are now bound together"),h.next(!0),h.complete()})}),a=new se(h=>{this.hls.once(ze.Events.MANIFEST_PARSED,function(l,d){console.debug("manifest loaded, found "+d.levels.length+" quality level"),h.next(!0),h.complete()})}),o=be(this.videoElement,We.LOADEDDATA).pipe(hi());Gu([n,a,o]).pipe(hi()).subscribe(h=>{i=i&&_e.coerce.number().parse(i),i=i||this.videoElement.duration;let l=new Xm(this.videoElement,e,t,i);s.next(l),s.complete()}),this.hls.loadSource(e),this.hls.attachMedia(this.videoElement)})}initEventHandlers(){super.initEventHandlers(),this.hls.on(ze.Events.ERROR,function(e,t){t.type,t.details,t.fatal,console.error(e,t),(t.details===ze.ErrorDetails.BUFFER_STALLED_ERROR||t.details===ze.ErrorDetails.BUFFER_APPEND_ERROR||t.details===ze.ErrorDetails.BUFFER_APPENDING_ERROR)&&(this.videoPlaybackStateHolder.buffering=!0)})}getAudioTracks(){return this.isVideoLoaded?this.hls.audioTracks:null}getCurrentAudioTrack(){return this.getAudioTracks()[this.hls.audioTrack]}setAudioTrack(e){if(!this.isVideoLoaded)return null;let t=this.hls.audioTrack;this.hls.audioTrack=e;let i=this.hls.audioTrack;i>=0&&t!==i&&this.onAudioSwitched$.next({audioTrack:this.getCurrentAudioTrack()})}getHls(){return this.hls}}class Ym{constructor(e){this.hidden=!0,this.id=e.id,this.src=e.src,this.default=e.default,this.label=e.label,this.language=e.language,this.cues=[]}}class Km extends Ym{constructor(e){super(e)}}class Sn{constructor(e){this.subtitlesTracks=new Map,this.onCreate$=new V,this.onRemove$=new V,this.onShow$=new V,this.onHide$=new V,this.videoController=e,this.videoController.onVideoLoaded$.pipe($e(t=>!!t)).subscribe(t=>{this.removeAllTracks()})}getDomTextTrack(e){let t=this.videoController.getHTMLVideoElement().textTracks.getTrackById(e.id);if(t.kind==="subtitles")return t}removeDomTextTrack(e){return this.getDomTextTrack(e)?(this.videoController.getHTMLVideoElement().querySelectorAll("track").forEach(i=>{i.getAttribute("id")===e.id&&i.parentElement.removeChild(i)}),!0):!1}static createHTMLTrackElement(e){let t=document.createElement("track");return t.kind="subtitles",t.id=e.id,t.label=e.label,t.srclang=e.language,t.src=e.src,t.default=e.default,t}createVttTrack(e){return this.videoController.isVideoLoaded?new se(t=>{let i=new Km({...e});this.subtitlesTracks.has(i.id)&&this.removeTrack(i.id),i.element=Sn.createHTMLTrackElement(i),be(i.element,"load").pipe(hi()).subscribe(n=>{this.subtitlesTracks.set(i.id,i),t.next(i),t.complete(),this.onCreate$.next({textTrack:i})}),this.videoController.getHTMLVideoElement().appendChild(i.element);let s=this.getDomTextTrack(i);s.mode="hidden"}):Ee(void 0)}getTracks(){if(this.videoController.isVideoLoaded)return[...this.subtitlesTracks.values()]}removeAllTracks(){this.videoController.isVideoLoaded&&this.subtitlesTracks.forEach((e,t)=>{this.removeTrack(e.id)})}removeTrack(e){if(!this.videoController.isVideoLoaded)return;let t=this.subtitlesTracks.get(e);t&&(this.subtitlesTracks.delete(e),this.removeDomTextTrack(t),this.onRemove$.next({}))}getCurrentTrack(){return this.currentTrack}showTrack(e=void 0){if(!this.videoController.isVideoLoaded||(e=e||(this.getCurrentTrack()?this.getCurrentTrack().id:void 0),!e))return;let t=this.subtitlesTracks.get(e);if(t){let i=this.getDomTextTrack(t);if(i){for(let s=0;s<this.videoController.getHTMLVideoElement().textTracks.length;s++){let n=this.videoController.getHTMLVideoElement().textTracks[s];n.mode="hidden"}i.mode="showing",t.hidden=!1,this.currentTrack=t,this.onShow$.next({})}}}hideTrack(e=void 0){if(!this.videoController.isVideoLoaded||(e=e||(this.getCurrentTrack()?this.getCurrentTrack().id:void 0),!e))return;let t=this.subtitlesTracks.get(e);if(t){let i=this.getDomTextTrack(t);i&&(i.mode="hidden",t.hidden=!0,this.onHide$.next({}))}}destroy(){this.removeAllTracks(),this.videoController=null,this.videoController=void 0}}var Ks={},Jm={get exports(){return Ks},set exports(r){Ks=r}};(function(r){var e=Object.prototype.hasOwnProperty,t="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(t=!1));function s(h,l,d){this.fn=h,this.context=l,this.once=d||!1}function n(h,l,d,u,c){if(typeof d!="function")throw new TypeError("The listener must be a function");var p=new s(d,u||h,c),f=t?t+l:l;return h._events[f]?h._events[f].fn?h._events[f]=[h._events[f],p]:h._events[f].push(p):(h._events[f]=p,h._eventsCount++),h}function a(h,l){--h._eventsCount===0?h._events=new i:delete h._events[l]}function o(){this._events=new i,this._eventsCount=0}o.prototype.eventNames=function(){var l=[],d,u;if(this._eventsCount===0)return l;for(u in d=this._events)e.call(d,u)&&l.push(t?u.slice(1):u);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(d)):l},o.prototype.listeners=function(l){var d=t?t+l:l,u=this._events[d];if(!u)return[];if(u.fn)return[u.fn];for(var c=0,p=u.length,f=new Array(p);c<p;c++)f[c]=u[c].fn;return f},o.prototype.listenerCount=function(l){var d=t?t+l:l,u=this._events[d];return u?u.fn?1:u.length:0},o.prototype.emit=function(l,d,u,c,p,f){var m=t?t+l:l;if(!this._events[m])return!1;var v=this._events[m],_=arguments.length,w,b;if(v.fn){switch(v.once&&this.removeListener(l,v.fn,void 0,!0),_){case 1:return v.fn.call(v.context),!0;case 2:return v.fn.call(v.context,d),!0;case 3:return v.fn.call(v.context,d,u),!0;case 4:return v.fn.call(v.context,d,u,c),!0;case 5:return v.fn.call(v.context,d,u,c,p),!0;case 6:return v.fn.call(v.context,d,u,c,p,f),!0}for(b=1,w=new Array(_-1);b<_;b++)w[b-1]=arguments[b];v.fn.apply(v.context,w)}else{var T=v.length,M;for(b=0;b<T;b++)switch(v[b].once&&this.removeListener(l,v[b].fn,void 0,!0),_){case 1:v[b].fn.call(v[b].context);break;case 2:v[b].fn.call(v[b].context,d);break;case 3:v[b].fn.call(v[b].context,d,u);break;case 4:v[b].fn.call(v[b].context,d,u,c);break;default:if(!w)for(M=1,w=new Array(_-1);M<_;M++)w[M-1]=arguments[M];v[b].fn.apply(v[b].context,w)}}return!0},o.prototype.on=function(l,d,u){return n(this,l,d,u,!1)},o.prototype.once=function(l,d,u){return n(this,l,d,u,!0)},o.prototype.removeListener=function(l,d,u,c){var p=t?t+l:l;if(!this._events[p])return this;if(!d)return a(this,p),this;var f=this._events[p];if(f.fn)f.fn===d&&(!c||f.once)&&(!u||f.context===u)&&a(this,p);else{for(var m=0,v=[],_=f.length;m<_;m++)(f[m].fn!==d||c&&!f[m].once||u&&f[m].context!==u)&&v.push(f[m]);v.length?this._events[p]=v.length===1?v[0]:v:a(this,p)}return this},o.prototype.removeAllListeners=function(l){var d;return l?(d=t?t+l:l,this._events[d]&&a(this,d)):(this._events=new i,this._eventsCount=0),this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prefixed=t,o.EventEmitter=o,r.exports=o})(Jm);const Qm={OMAKASE_SUBTITLES_HIDE:"omakaseSubtitlesHide",OMAKASE_TIMELINE_ZOOM:"omakaseTimelineZoom",OMAKASE_VIDEO_LOADED:"omakaseVideoLoaded",OMAKASE_VIDEO_PAUSE:"omakaseVideoPause",OMAKASE_VIDEO_PLAY:"omakaseVideoPlay",OMAKASE_VIDEO_SEEKED:"omakaseVideoSeeked",OMAKASE_VIDEO_SEEKING:"omakaseVideoSeeking",OMAKASE_VIDEO_BUFFERING:"omakaseVideoBuffering",OMAKASE_VIDEO_ENDED:"omakaseVideoEnded",OMAKASE_VIDEO_TIME_CHANGE:"omakaseVideoTimeChange",OMAKASE_VIDEO_AUDIO_SWITCHED:"omakaseVideoAudioSwitched",OMAKASE_AUDIO_SWITCHED:"omakaseAudioSwitched",OMAKASE_SUBTITLES_CREATE:"omakaseSubtitlesCreate",OMAKASE_SUBTITLES_REMOVE:"omakaseSubtitlesRemove",OMAKASE_SUBTITLES_SHOW:"omakaseSubtitlesShow",OMAKASE_TIMELINE_SCROLL:"omakaseTimelineScroll"};class eg{constructor(e){this.onAudioSwitched$=new V,this.videoController=e}getAudioTracks(){return this.videoController.getAudioTracks()}getCurrentAudioTrack(){return this.videoController.getCurrentAudioTrack()}setAudioTrack(e){let t=this.getCurrentAudioTrack();this.videoController.setAudioTrack(e);let i=this.getCurrentAudioTrack();t!==i&&this.onAudioSwitched$.next({audioTrack:i})}}class Ei{static isFullscreenEnabled(){const e=document;return e.fullscreenEnabled||e.webkitFullscreenEnabled||!!e.webkitCancelFullScreen||e.mozFullScreenEnabled||e.msFullscreenEnabled||!1}static isFullscreen(){const e=document;return!!(e.fullscreenElement||e.webkitFullscreenElement||e.webkitCurrentFullScreenElement||e.mozFullScreenElement||e.msFullscreenElement)}static requestFullscreen(e,t){const i=e??document.documentElement,s=i.requestFullscreen||i.webkitRequestFullscreen||i.webkitRequestFullScreen||i.mozRequestFullScreen||i.msRequestFullscreen;if(!s)throw new Error("Unsupported");return s.call(i,t)}static exitFullscreen(){const e=document,t=e.exitFullscreen||e.webkitExitFullscreen||e.webkitCancelFullScreen||e.mozCancelFullScreen||e.msExitFullscreen;if(!t)throw new Error("Unsupported");return t.call(e)}}const fe={player:"omakase-player",playerWrapper:"omakase-player-wrapper",video:"omakase-video",videoControls:"omakase-video-controls",buttonPlay:"omakase-button-play",buttonPause:"omakase-button-pause",buttonLoading:"omakase-button-loading",buttonError:"omakase-button-error",buttonReplay:"omakase-button-replay",buttonHelp:"omakase-help-button",help:"omakase-help",helpMenu:"omakase-help-menu",errorMessage:"omakase-error-message"};class tg{constructor(e){this._playerHTMLElementId=e,this.divPlayer=this.getElementById(this._playerHTMLElementId),this.createDom()}createDom(){this.divPlayer.classList.add(`${fe.player}`),this.divPlayer.innerHTML=`<div class="${fe.playerWrapper}">
48
48
  <video class="${fe.video}"></video>
49
49
 
50
50
  <div class="${fe.help} d-none">