plyr.js 307 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321
  1. typeof navigator === "object" && (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  3. typeof define === 'function' && define.amd ? define('Plyr', factory) :
  4. (global = global || self, global.Plyr = factory());
  5. }(this, (function () { 'use strict';
  6. function _classCallCheck(instance, Constructor) {
  7. if (!(instance instanceof Constructor)) {
  8. throw new TypeError("Cannot call a class as a function");
  9. }
  10. }
  11. function _defineProperties(target, props) {
  12. for (var i = 0; i < props.length; i++) {
  13. var descriptor = props[i];
  14. descriptor.enumerable = descriptor.enumerable || false;
  15. descriptor.configurable = true;
  16. if ("value" in descriptor) descriptor.writable = true;
  17. Object.defineProperty(target, descriptor.key, descriptor);
  18. }
  19. }
  20. function _createClass(Constructor, protoProps, staticProps) {
  21. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  22. if (staticProps) _defineProperties(Constructor, staticProps);
  23. return Constructor;
  24. }
  25. function _defineProperty(obj, key, value) {
  26. if (key in obj) {
  27. Object.defineProperty(obj, key, {
  28. value: value,
  29. enumerable: true,
  30. configurable: true,
  31. writable: true
  32. });
  33. } else {
  34. obj[key] = value;
  35. }
  36. return obj;
  37. }
  38. function ownKeys(object, enumerableOnly) {
  39. var keys = Object.keys(object);
  40. if (Object.getOwnPropertySymbols) {
  41. var symbols = Object.getOwnPropertySymbols(object);
  42. if (enumerableOnly) symbols = symbols.filter(function (sym) {
  43. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  44. });
  45. keys.push.apply(keys, symbols);
  46. }
  47. return keys;
  48. }
  49. function _objectSpread2(target) {
  50. for (var i = 1; i < arguments.length; i++) {
  51. var source = arguments[i] != null ? arguments[i] : {};
  52. if (i % 2) {
  53. ownKeys(Object(source), true).forEach(function (key) {
  54. _defineProperty(target, key, source[key]);
  55. });
  56. } else if (Object.getOwnPropertyDescriptors) {
  57. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  58. } else {
  59. ownKeys(Object(source)).forEach(function (key) {
  60. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  61. });
  62. }
  63. }
  64. return target;
  65. }
  66. function _objectWithoutPropertiesLoose(source, excluded) {
  67. if (source == null) return {};
  68. var target = {};
  69. var sourceKeys = Object.keys(source);
  70. var key, i;
  71. for (i = 0; i < sourceKeys.length; i++) {
  72. key = sourceKeys[i];
  73. if (excluded.indexOf(key) >= 0) continue;
  74. target[key] = source[key];
  75. }
  76. return target;
  77. }
  78. function _objectWithoutProperties(source, excluded) {
  79. if (source == null) return {};
  80. var target = _objectWithoutPropertiesLoose(source, excluded);
  81. var key, i;
  82. if (Object.getOwnPropertySymbols) {
  83. var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
  84. for (i = 0; i < sourceSymbolKeys.length; i++) {
  85. key = sourceSymbolKeys[i];
  86. if (excluded.indexOf(key) >= 0) continue;
  87. if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
  88. target[key] = source[key];
  89. }
  90. }
  91. return target;
  92. }
  93. function _slicedToArray(arr, i) {
  94. return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
  95. }
  96. function _toConsumableArray(arr) {
  97. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
  98. }
  99. function _arrayWithoutHoles(arr) {
  100. if (Array.isArray(arr)) return _arrayLikeToArray(arr);
  101. }
  102. function _arrayWithHoles(arr) {
  103. if (Array.isArray(arr)) return arr;
  104. }
  105. function _iterableToArray(iter) {
  106. if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
  107. }
  108. function _iterableToArrayLimit(arr, i) {
  109. if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
  110. var _arr = [];
  111. var _n = true;
  112. var _d = false;
  113. var _e = undefined;
  114. try {
  115. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  116. _arr.push(_s.value);
  117. if (i && _arr.length === i) break;
  118. }
  119. } catch (err) {
  120. _d = true;
  121. _e = err;
  122. } finally {
  123. try {
  124. if (!_n && _i["return"] != null) _i["return"]();
  125. } finally {
  126. if (_d) throw _e;
  127. }
  128. }
  129. return _arr;
  130. }
  131. function _unsupportedIterableToArray(o, minLen) {
  132. if (!o) return;
  133. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  134. var n = Object.prototype.toString.call(o).slice(8, -1);
  135. if (n === "Object" && o.constructor) n = o.constructor.name;
  136. if (n === "Map" || n === "Set") return Array.from(o);
  137. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  138. }
  139. function _arrayLikeToArray(arr, len) {
  140. if (len == null || len > arr.length) len = arr.length;
  141. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  142. return arr2;
  143. }
  144. function _nonIterableSpread() {
  145. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  146. }
  147. function _nonIterableRest() {
  148. throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  149. }
  150. function _classCallCheck$1(e, t) {
  151. if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function");
  152. }
  153. function _defineProperties$1(e, t) {
  154. for (var n = 0; n < t.length; n++) {
  155. var r = t[n];
  156. r.enumerable = r.enumerable || !1, r.configurable = !0, "value" in r && (r.writable = !0), Object.defineProperty(e, r.key, r);
  157. }
  158. }
  159. function _createClass$1(e, t, n) {
  160. return t && _defineProperties$1(e.prototype, t), n && _defineProperties$1(e, n), e;
  161. }
  162. function _defineProperty$1(e, t, n) {
  163. return t in e ? Object.defineProperty(e, t, {
  164. value: n,
  165. enumerable: !0,
  166. configurable: !0,
  167. writable: !0
  168. }) : e[t] = n, e;
  169. }
  170. function ownKeys$1(e, t) {
  171. var n = Object.keys(e);
  172. if (Object.getOwnPropertySymbols) {
  173. var r = Object.getOwnPropertySymbols(e);
  174. t && (r = r.filter(function (t) {
  175. return Object.getOwnPropertyDescriptor(e, t).enumerable;
  176. })), n.push.apply(n, r);
  177. }
  178. return n;
  179. }
  180. function _objectSpread2$1(e) {
  181. for (var t = 1; t < arguments.length; t++) {
  182. var n = null != arguments[t] ? arguments[t] : {};
  183. t % 2 ? ownKeys$1(Object(n), !0).forEach(function (t) {
  184. _defineProperty$1(e, t, n[t]);
  185. }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) : ownKeys$1(Object(n)).forEach(function (t) {
  186. Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(n, t));
  187. });
  188. }
  189. return e;
  190. }
  191. var defaults = {
  192. addCSS: !0,
  193. thumbWidth: 15,
  194. watch: !0
  195. };
  196. function matches(e, t) {
  197. return function () {
  198. return Array.from(document.querySelectorAll(t)).includes(this);
  199. }.call(e, t);
  200. }
  201. function trigger(e, t) {
  202. if (e && t) {
  203. var n = new Event(t, {
  204. bubbles: !0
  205. });
  206. e.dispatchEvent(n);
  207. }
  208. }
  209. var getConstructor = function getConstructor(e) {
  210. return null != e ? e.constructor : null;
  211. },
  212. instanceOf = function instanceOf(e, t) {
  213. return !!(e && t && e instanceof t);
  214. },
  215. isNullOrUndefined = function isNullOrUndefined(e) {
  216. return null == e;
  217. },
  218. isObject = function isObject(e) {
  219. return getConstructor(e) === Object;
  220. },
  221. isNumber = function isNumber(e) {
  222. return getConstructor(e) === Number && !Number.isNaN(e);
  223. },
  224. isString = function isString(e) {
  225. return getConstructor(e) === String;
  226. },
  227. isBoolean = function isBoolean(e) {
  228. return getConstructor(e) === Boolean;
  229. },
  230. isFunction = function isFunction(e) {
  231. return getConstructor(e) === Function;
  232. },
  233. isArray = function isArray(e) {
  234. return Array.isArray(e);
  235. },
  236. isNodeList = function isNodeList(e) {
  237. return instanceOf(e, NodeList);
  238. },
  239. isElement = function isElement(e) {
  240. return instanceOf(e, Element);
  241. },
  242. isEvent = function isEvent(e) {
  243. return instanceOf(e, Event);
  244. },
  245. isEmpty = function isEmpty(e) {
  246. return isNullOrUndefined(e) || (isString(e) || isArray(e) || isNodeList(e)) && !e.length || isObject(e) && !Object.keys(e).length;
  247. },
  248. is = {
  249. nullOrUndefined: isNullOrUndefined,
  250. object: isObject,
  251. number: isNumber,
  252. string: isString,
  253. boolean: isBoolean,
  254. function: isFunction,
  255. array: isArray,
  256. nodeList: isNodeList,
  257. element: isElement,
  258. event: isEvent,
  259. empty: isEmpty
  260. };
  261. function getDecimalPlaces(e) {
  262. var t = "".concat(e).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
  263. return t ? Math.max(0, (t[1] ? t[1].length : 0) - (t[2] ? +t[2] : 0)) : 0;
  264. }
  265. function round(e, t) {
  266. if (1 > t) {
  267. var n = getDecimalPlaces(t);
  268. return parseFloat(e.toFixed(n));
  269. }
  270. return Math.round(e / t) * t;
  271. }
  272. var RangeTouch = function () {
  273. function e(t, n) {
  274. _classCallCheck$1(this, e), is.element(t) ? this.element = t : is.string(t) && (this.element = document.querySelector(t)), is.element(this.element) && is.empty(this.element.rangeTouch) && (this.config = _objectSpread2$1({}, defaults, {}, n), this.init());
  275. }
  276. return _createClass$1(e, [{
  277. key: "init",
  278. value: function value() {
  279. e.enabled && (this.config.addCSS && (this.element.style.userSelect = "none", this.element.style.webKitUserSelect = "none", this.element.style.touchAction = "manipulation"), this.listeners(!0), this.element.rangeTouch = this);
  280. }
  281. }, {
  282. key: "destroy",
  283. value: function value() {
  284. e.enabled && (this.config.addCSS && (this.element.style.userSelect = "", this.element.style.webKitUserSelect = "", this.element.style.touchAction = ""), this.listeners(!1), this.element.rangeTouch = null);
  285. }
  286. }, {
  287. key: "listeners",
  288. value: function value(e) {
  289. var t = this,
  290. n = e ? "addEventListener" : "removeEventListener";
  291. ["touchstart", "touchmove", "touchend"].forEach(function (e) {
  292. t.element[n](e, function (e) {
  293. return t.set(e);
  294. }, !1);
  295. });
  296. }
  297. }, {
  298. key: "get",
  299. value: function value(t) {
  300. if (!e.enabled || !is.event(t)) return null;
  301. var n,
  302. r = t.target,
  303. i = t.changedTouches[0],
  304. o = parseFloat(r.getAttribute("min")) || 0,
  305. s = parseFloat(r.getAttribute("max")) || 100,
  306. u = parseFloat(r.getAttribute("step")) || 1,
  307. c = r.getBoundingClientRect(),
  308. a = 100 / c.width * (this.config.thumbWidth / 2) / 100;
  309. return 0 > (n = 100 / c.width * (i.clientX - c.left)) ? n = 0 : 100 < n && (n = 100), 50 > n ? n -= (100 - 2 * n) * a : 50 < n && (n += 2 * (n - 50) * a), o + round(n / 100 * (s - o), u);
  310. }
  311. }, {
  312. key: "set",
  313. value: function value(t) {
  314. e.enabled && is.event(t) && !t.target.disabled && (t.preventDefault(), t.target.value = this.get(t), trigger(t.target, "touchend" === t.type ? "change" : "input"));
  315. }
  316. }], [{
  317. key: "setup",
  318. value: function value(t) {
  319. var n = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : {},
  320. r = null;
  321. if (is.empty(t) || is.string(t) ? r = Array.from(document.querySelectorAll(is.string(t) ? t : 'input[type="range"]')) : is.element(t) ? r = [t] : is.nodeList(t) ? r = Array.from(t) : is.array(t) && (r = t.filter(is.element)), is.empty(r)) return null;
  322. var i = _objectSpread2$1({}, defaults, {}, n);
  323. if (is.string(t) && i.watch) {
  324. var o = new MutationObserver(function (n) {
  325. Array.from(n).forEach(function (n) {
  326. Array.from(n.addedNodes).forEach(function (n) {
  327. is.element(n) && matches(n, t) && new e(n, i);
  328. });
  329. });
  330. });
  331. o.observe(document.body, {
  332. childList: !0,
  333. subtree: !0
  334. });
  335. }
  336. return r.map(function (t) {
  337. return new e(t, n);
  338. });
  339. }
  340. }, {
  341. key: "enabled",
  342. get: function get() {
  343. return "ontouchstart" in document.documentElement;
  344. }
  345. }]), e;
  346. }();
  347. // ==========================================================================
  348. // Type checking utils
  349. // ==========================================================================
  350. var getConstructor$1 = function getConstructor(input) {
  351. return input !== null && typeof input !== 'undefined' ? input.constructor : null;
  352. };
  353. var instanceOf$1 = function instanceOf(input, constructor) {
  354. return Boolean(input && constructor && input instanceof constructor);
  355. };
  356. var isNullOrUndefined$1 = function isNullOrUndefined(input) {
  357. return input === null || typeof input === 'undefined';
  358. };
  359. var isObject$1 = function isObject(input) {
  360. return getConstructor$1(input) === Object;
  361. };
  362. var isNumber$1 = function isNumber(input) {
  363. return getConstructor$1(input) === Number && !Number.isNaN(input);
  364. };
  365. var isString$1 = function isString(input) {
  366. return getConstructor$1(input) === String;
  367. };
  368. var isBoolean$1 = function isBoolean(input) {
  369. return getConstructor$1(input) === Boolean;
  370. };
  371. var isFunction$1 = function isFunction(input) {
  372. return getConstructor$1(input) === Function;
  373. };
  374. var isArray$1 = function isArray(input) {
  375. return Array.isArray(input);
  376. };
  377. var isWeakMap = function isWeakMap(input) {
  378. return instanceOf$1(input, WeakMap);
  379. };
  380. var isNodeList$1 = function isNodeList(input) {
  381. return instanceOf$1(input, NodeList);
  382. };
  383. var isElement$1 = function isElement(input) {
  384. return instanceOf$1(input, Element);
  385. };
  386. var isTextNode = function isTextNode(input) {
  387. return getConstructor$1(input) === Text;
  388. };
  389. var isEvent$1 = function isEvent(input) {
  390. return instanceOf$1(input, Event);
  391. };
  392. var isKeyboardEvent = function isKeyboardEvent(input) {
  393. return instanceOf$1(input, KeyboardEvent);
  394. };
  395. var isCue = function isCue(input) {
  396. return instanceOf$1(input, window.TextTrackCue) || instanceOf$1(input, window.VTTCue);
  397. };
  398. var isTrack = function isTrack(input) {
  399. return instanceOf$1(input, TextTrack) || !isNullOrUndefined$1(input) && isString$1(input.kind);
  400. };
  401. var isPromise = function isPromise(input) {
  402. return instanceOf$1(input, Promise) && isFunction$1(input.then);
  403. };
  404. var isEmpty$1 = function isEmpty(input) {
  405. return isNullOrUndefined$1(input) || (isString$1(input) || isArray$1(input) || isNodeList$1(input)) && !input.length || isObject$1(input) && !Object.keys(input).length;
  406. };
  407. var isUrl = function isUrl(input) {
  408. // Accept a URL object
  409. if (instanceOf$1(input, window.URL)) {
  410. return true;
  411. } // Must be string from here
  412. if (!isString$1(input)) {
  413. return false;
  414. } // Add the protocol if required
  415. var string = input;
  416. if (!input.startsWith('http://') || !input.startsWith('https://')) {
  417. string = "http://".concat(input);
  418. }
  419. try {
  420. return !isEmpty$1(new URL(string).hostname);
  421. } catch (e) {
  422. return false;
  423. }
  424. };
  425. var is$1 = {
  426. nullOrUndefined: isNullOrUndefined$1,
  427. object: isObject$1,
  428. number: isNumber$1,
  429. string: isString$1,
  430. boolean: isBoolean$1,
  431. function: isFunction$1,
  432. array: isArray$1,
  433. weakMap: isWeakMap,
  434. nodeList: isNodeList$1,
  435. element: isElement$1,
  436. textNode: isTextNode,
  437. event: isEvent$1,
  438. keyboardEvent: isKeyboardEvent,
  439. cue: isCue,
  440. track: isTrack,
  441. promise: isPromise,
  442. url: isUrl,
  443. empty: isEmpty$1
  444. };
  445. // ==========================================================================
  446. var transitionEndEvent = function () {
  447. var element = document.createElement('span');
  448. var events = {
  449. WebkitTransition: 'webkitTransitionEnd',
  450. MozTransition: 'transitionend',
  451. OTransition: 'oTransitionEnd otransitionend',
  452. transition: 'transitionend'
  453. };
  454. var type = Object.keys(events).find(function (event) {
  455. return element.style[event] !== undefined;
  456. });
  457. return is$1.string(type) ? events[type] : false;
  458. }(); // Force repaint of element
  459. function repaint(element, delay) {
  460. setTimeout(function () {
  461. try {
  462. // eslint-disable-next-line no-param-reassign
  463. element.hidden = true; // eslint-disable-next-line no-unused-expressions
  464. element.offsetHeight; // eslint-disable-next-line no-param-reassign
  465. element.hidden = false;
  466. } catch (e) {// Do nothing
  467. }
  468. }, delay);
  469. }
  470. // ==========================================================================
  471. // Browser sniffing
  472. // Unfortunately, due to mixed support, UA sniffing is required
  473. // ==========================================================================
  474. var browser = {
  475. isIE:
  476. /* @cc_on!@ */
  477. !!document.documentMode,
  478. isEdge: window.navigator.userAgent.includes('Edge'),
  479. isWebkit: 'WebkitAppearance' in document.documentElement.style && !/Edge/.test(navigator.userAgent),
  480. isIPhone: /(iPhone|iPod)/gi.test(navigator.platform),
  481. isIos: /(iPad|iPhone|iPod)/gi.test(navigator.platform)
  482. };
  483. function cloneDeep(object) {
  484. return JSON.parse(JSON.stringify(object));
  485. } // Get a nested value in an object
  486. function getDeep(object, path) {
  487. return path.split('.').reduce(function (obj, key) {
  488. return obj && obj[key];
  489. }, object);
  490. } // Deep extend destination object with N more objects
  491. function extend() {
  492. var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  493. for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  494. sources[_key - 1] = arguments[_key];
  495. }
  496. if (!sources.length) {
  497. return target;
  498. }
  499. var source = sources.shift();
  500. if (!is$1.object(source)) {
  501. return target;
  502. }
  503. Object.keys(source).forEach(function (key) {
  504. if (is$1.object(source[key])) {
  505. if (!Object.keys(target).includes(key)) {
  506. Object.assign(target, _defineProperty({}, key, {}));
  507. }
  508. extend(target[key], source[key]);
  509. } else {
  510. Object.assign(target, _defineProperty({}, key, source[key]));
  511. }
  512. });
  513. return extend.apply(void 0, [target].concat(sources));
  514. }
  515. function wrap(elements, wrapper) {
  516. // Convert `elements` to an array, if necessary.
  517. var targets = elements.length ? elements : [elements]; // Loops backwards to prevent having to clone the wrapper on the
  518. // first element (see `child` below).
  519. Array.from(targets).reverse().forEach(function (element, index) {
  520. var child = index > 0 ? wrapper.cloneNode(true) : wrapper; // Cache the current parent and sibling.
  521. var parent = element.parentNode;
  522. var sibling = element.nextSibling; // Wrap the element (is automatically removed from its current
  523. // parent).
  524. child.appendChild(element); // If the element had a sibling, insert the wrapper before
  525. // the sibling to maintain the HTML structure; otherwise, just
  526. // append it to the parent.
  527. if (sibling) {
  528. parent.insertBefore(child, sibling);
  529. } else {
  530. parent.appendChild(child);
  531. }
  532. });
  533. } // Set attributes
  534. function setAttributes(element, attributes) {
  535. if (!is$1.element(element) || is$1.empty(attributes)) {
  536. return;
  537. } // Assume null and undefined attributes should be left out,
  538. // Setting them would otherwise convert them to "null" and "undefined"
  539. Object.entries(attributes).filter(function (_ref) {
  540. var _ref2 = _slicedToArray(_ref, 2),
  541. value = _ref2[1];
  542. return !is$1.nullOrUndefined(value);
  543. }).forEach(function (_ref3) {
  544. var _ref4 = _slicedToArray(_ref3, 2),
  545. key = _ref4[0],
  546. value = _ref4[1];
  547. return element.setAttribute(key, value);
  548. });
  549. } // Create a DocumentFragment
  550. function createElement(type, attributes, text) {
  551. // Create a new <element>
  552. var element = document.createElement(type); // Set all passed attributes
  553. if (is$1.object(attributes)) {
  554. setAttributes(element, attributes);
  555. } // Add text node
  556. if (is$1.string(text)) {
  557. element.innerText = text;
  558. } // Return built element
  559. return element;
  560. } // Inaert an element after another
  561. function insertAfter(element, target) {
  562. if (!is$1.element(element) || !is$1.element(target)) {
  563. return;
  564. }
  565. target.parentNode.insertBefore(element, target.nextSibling);
  566. } // Insert a DocumentFragment
  567. function insertElement(type, parent, attributes, text) {
  568. if (!is$1.element(parent)) {
  569. return;
  570. }
  571. parent.appendChild(createElement(type, attributes, text));
  572. } // Remove element(s)
  573. function removeElement(element) {
  574. if (is$1.nodeList(element) || is$1.array(element)) {
  575. Array.from(element).forEach(removeElement);
  576. return;
  577. }
  578. if (!is$1.element(element) || !is$1.element(element.parentNode)) {
  579. return;
  580. }
  581. element.parentNode.removeChild(element);
  582. } // Remove all child elements
  583. function emptyElement(element) {
  584. if (!is$1.element(element)) {
  585. return;
  586. }
  587. var length = element.childNodes.length;
  588. while (length > 0) {
  589. element.removeChild(element.lastChild);
  590. length -= 1;
  591. }
  592. } // Replace element
  593. function replaceElement(newChild, oldChild) {
  594. if (!is$1.element(oldChild) || !is$1.element(oldChild.parentNode) || !is$1.element(newChild)) {
  595. return null;
  596. }
  597. oldChild.parentNode.replaceChild(newChild, oldChild);
  598. return newChild;
  599. } // Get an attribute object from a string selector
  600. function getAttributesFromSelector(sel, existingAttributes) {
  601. // For example:
  602. // '.test' to { class: 'test' }
  603. // '#test' to { id: 'test' }
  604. // '[data-test="test"]' to { 'data-test': 'test' }
  605. if (!is$1.string(sel) || is$1.empty(sel)) {
  606. return {};
  607. }
  608. var attributes = {};
  609. var existing = extend({}, existingAttributes);
  610. sel.split(',').forEach(function (s) {
  611. // Remove whitespace
  612. var selector = s.trim();
  613. var className = selector.replace('.', '');
  614. var stripped = selector.replace(/[[\]]/g, ''); // Get the parts and value
  615. var parts = stripped.split('=');
  616. var _parts = _slicedToArray(parts, 1),
  617. key = _parts[0];
  618. var value = parts.length > 1 ? parts[1].replace(/["']/g, '') : ''; // Get the first character
  619. var start = selector.charAt(0);
  620. switch (start) {
  621. case '.':
  622. // Add to existing classname
  623. if (is$1.string(existing.class)) {
  624. attributes.class = "".concat(existing.class, " ").concat(className);
  625. } else {
  626. attributes.class = className;
  627. }
  628. break;
  629. case '#':
  630. // ID selector
  631. attributes.id = selector.replace('#', '');
  632. break;
  633. case '[':
  634. // Attribute selector
  635. attributes[key] = value;
  636. break;
  637. }
  638. });
  639. return extend(existing, attributes);
  640. } // Toggle hidden
  641. function toggleHidden(element, hidden) {
  642. if (!is$1.element(element)) {
  643. return;
  644. }
  645. var hide = hidden;
  646. if (!is$1.boolean(hide)) {
  647. hide = !element.hidden;
  648. } // eslint-disable-next-line no-param-reassign
  649. element.hidden = hide;
  650. } // Mirror Element.classList.toggle, with IE compatibility for "force" argument
  651. function toggleClass(element, className, force) {
  652. if (is$1.nodeList(element)) {
  653. return Array.from(element).map(function (e) {
  654. return toggleClass(e, className, force);
  655. });
  656. }
  657. if (is$1.element(element)) {
  658. var method = 'toggle';
  659. if (typeof force !== 'undefined') {
  660. method = force ? 'add' : 'remove';
  661. }
  662. element.classList[method](className);
  663. return element.classList.contains(className);
  664. }
  665. return false;
  666. } // Has class name
  667. function hasClass(element, className) {
  668. return is$1.element(element) && element.classList.contains(className);
  669. } // Element matches selector
  670. function matches$1(element, selector) {
  671. var _Element = Element,
  672. prototype = _Element.prototype;
  673. function match() {
  674. return Array.from(document.querySelectorAll(selector)).includes(this);
  675. }
  676. var method = prototype.matches || prototype.webkitMatchesSelector || prototype.mozMatchesSelector || prototype.msMatchesSelector || match;
  677. return method.call(element, selector);
  678. } // Closest ancestor element matching selector (also tests element itself)
  679. function closest(element, selector) {
  680. var _Element2 = Element,
  681. prototype = _Element2.prototype; // https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill
  682. function closestElement() {
  683. var el = this;
  684. do {
  685. if (matches$1.matches(el, selector)) return el;
  686. el = el.parentElement || el.parentNode;
  687. } while (el !== null && el.nodeType === 1);
  688. return null;
  689. }
  690. var method = prototype.closest || closestElement;
  691. return method.call(element, selector);
  692. } // Find all elements
  693. function getElements(selector) {
  694. return this.elements.container.querySelectorAll(selector);
  695. } // Find a single element
  696. function getElement(selector) {
  697. return this.elements.container.querySelector(selector);
  698. } // Set focus and tab focus class
  699. function setFocus() {
  700. var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  701. var tabFocus = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  702. if (!is$1.element(element)) {
  703. return;
  704. } // Set regular focus
  705. element.focus({
  706. preventScroll: true
  707. }); // If we want to mimic keyboard focus via tab
  708. if (tabFocus) {
  709. toggleClass(element, this.config.classNames.tabFocus);
  710. }
  711. }
  712. var defaultCodecs = {
  713. 'audio/ogg': 'vorbis',
  714. 'audio/wav': '1',
  715. 'video/webm': 'vp8, vorbis',
  716. 'video/mp4': 'avc1.42E01E, mp4a.40.2',
  717. 'video/ogg': 'theora'
  718. }; // Check for feature support
  719. var support = {
  720. // Basic support
  721. audio: 'canPlayType' in document.createElement('audio'),
  722. video: 'canPlayType' in document.createElement('video'),
  723. // Check for support
  724. // Basic functionality vs full UI
  725. check: function check(type, provider, playsinline) {
  726. var canPlayInline = browser.isIPhone && playsinline && support.playsinline;
  727. var api = support[type] || provider !== 'html5';
  728. var ui = api && support.rangeInput && (type !== 'video' || !browser.isIPhone || canPlayInline);
  729. return {
  730. api: api,
  731. ui: ui
  732. };
  733. },
  734. // Picture-in-picture support
  735. // Safari & Chrome only currently
  736. pip: function () {
  737. if (browser.isIPhone) {
  738. return false;
  739. } // Safari
  740. // https://developer.apple.com/documentation/webkitjs/adding_picture_in_picture_to_your_safari_media_controls
  741. if (is$1.function(createElement('video').webkitSetPresentationMode)) {
  742. return true;
  743. } // Chrome
  744. // https://developers.google.com/web/updates/2018/10/watch-video-using-picture-in-picture
  745. if (document.pictureInPictureEnabled && !createElement('video').disablePictureInPicture) {
  746. return true;
  747. }
  748. return false;
  749. }(),
  750. // Airplay support
  751. // Safari only currently
  752. airplay: is$1.function(window.WebKitPlaybackTargetAvailabilityEvent),
  753. // Inline playback support
  754. // https://webkit.org/blog/6784/new-video-policies-for-ios/
  755. playsinline: 'playsInline' in document.createElement('video'),
  756. // Check for mime type support against a player instance
  757. // Credits: http://diveintohtml5.info/everything.html
  758. // Related: http://www.leanbackplayer.com/test/h5mt.html
  759. mime: function mime(input) {
  760. if (is$1.empty(input)) {
  761. return false;
  762. }
  763. var _input$split = input.split('/'),
  764. _input$split2 = _slicedToArray(_input$split, 1),
  765. mediaType = _input$split2[0];
  766. var type = input; // Verify we're using HTML5 and there's no media type mismatch
  767. if (!this.isHTML5 || mediaType !== this.type) {
  768. return false;
  769. } // Add codec if required
  770. if (Object.keys(defaultCodecs).includes(type)) {
  771. type += "; codecs=\"".concat(defaultCodecs[input], "\"");
  772. }
  773. try {
  774. return Boolean(type && this.media.canPlayType(type).replace(/no/, ''));
  775. } catch (e) {
  776. return false;
  777. }
  778. },
  779. // Check for textTracks support
  780. textTracks: 'textTracks' in document.createElement('video'),
  781. // <input type="range"> Sliders
  782. rangeInput: function () {
  783. var range = document.createElement('input');
  784. range.type = 'range';
  785. return range.type === 'range';
  786. }(),
  787. // Touch
  788. // NOTE: Remember a device can be mouse + touch enabled so we check on first touch event
  789. touch: 'ontouchstart' in document.documentElement,
  790. // Detect transitions support
  791. transitions: transitionEndEvent !== false,
  792. // Reduced motion iOS & MacOS setting
  793. // https://webkit.org/blog/7551/responsive-design-for-motion/
  794. reducedMotion: 'matchMedia' in window && window.matchMedia('(prefers-reduced-motion)').matches
  795. };
  796. // https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
  797. // https://www.youtube.com/watch?v=NPM6172J22g
  798. var supportsPassiveListeners = function () {
  799. // Test via a getter in the options object to see if the passive property is accessed
  800. var supported = false;
  801. try {
  802. var options = Object.defineProperty({}, 'passive', {
  803. get: function get() {
  804. supported = true;
  805. return null;
  806. }
  807. });
  808. window.addEventListener('test', null, options);
  809. window.removeEventListener('test', null, options);
  810. } catch (e) {// Do nothing
  811. }
  812. return supported;
  813. }(); // Toggle event listener
  814. function toggleListener(element, event, callback) {
  815. var _this = this;
  816. var toggle = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  817. var passive = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
  818. var capture = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
  819. // Bail if no element, event, or callback
  820. if (!element || !('addEventListener' in element) || is$1.empty(event) || !is$1.function(callback)) {
  821. return;
  822. } // Allow multiple events
  823. var events = event.split(' '); // Build options
  824. // Default to just the capture boolean for browsers with no passive listener support
  825. var options = capture; // If passive events listeners are supported
  826. if (supportsPassiveListeners) {
  827. options = {
  828. // Whether the listener can be passive (i.e. default never prevented)
  829. passive: passive,
  830. // Whether the listener is a capturing listener or not
  831. capture: capture
  832. };
  833. } // If a single node is passed, bind the event listener
  834. events.forEach(function (type) {
  835. if (_this && _this.eventListeners && toggle) {
  836. // Cache event listener
  837. _this.eventListeners.push({
  838. element: element,
  839. type: type,
  840. callback: callback,
  841. options: options
  842. });
  843. }
  844. element[toggle ? 'addEventListener' : 'removeEventListener'](type, callback, options);
  845. });
  846. } // Bind event handler
  847. function on(element) {
  848. var events = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  849. var callback = arguments.length > 2 ? arguments[2] : undefined;
  850. var passive = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
  851. var capture = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
  852. toggleListener.call(this, element, events, callback, true, passive, capture);
  853. } // Unbind event handler
  854. function off(element) {
  855. var events = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  856. var callback = arguments.length > 2 ? arguments[2] : undefined;
  857. var passive = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
  858. var capture = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
  859. toggleListener.call(this, element, events, callback, false, passive, capture);
  860. } // Bind once-only event handler
  861. function once(element) {
  862. var _this2 = this;
  863. var events = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  864. var callback = arguments.length > 2 ? arguments[2] : undefined;
  865. var passive = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
  866. var capture = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
  867. var onceCallback = function onceCallback() {
  868. off(element, events, onceCallback, passive, capture);
  869. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  870. args[_key] = arguments[_key];
  871. }
  872. callback.apply(_this2, args);
  873. };
  874. toggleListener.call(this, element, events, onceCallback, true, passive, capture);
  875. } // Trigger event
  876. function triggerEvent(element) {
  877. var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  878. var bubbles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  879. var detail = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  880. // Bail if no element
  881. if (!is$1.element(element) || is$1.empty(type)) {
  882. return;
  883. } // Create and dispatch the event
  884. var event = new CustomEvent(type, {
  885. bubbles: bubbles,
  886. detail: _objectSpread2(_objectSpread2({}, detail), {}, {
  887. plyr: this
  888. })
  889. }); // Dispatch the event
  890. element.dispatchEvent(event);
  891. } // Unbind all cached event listeners
  892. function unbindListeners() {
  893. if (this && this.eventListeners) {
  894. this.eventListeners.forEach(function (item) {
  895. var element = item.element,
  896. type = item.type,
  897. callback = item.callback,
  898. options = item.options;
  899. element.removeEventListener(type, callback, options);
  900. });
  901. this.eventListeners = [];
  902. }
  903. } // Run method when / if player is ready
  904. function ready() {
  905. var _this3 = this;
  906. return new Promise(function (resolve) {
  907. return _this3.ready ? setTimeout(resolve, 0) : on.call(_this3, _this3.elements.container, 'ready', resolve);
  908. }).then(function () {});
  909. }
  910. /**
  911. * Silence a Promise-like object.
  912. * This is useful for avoiding non-harmful, but potentially confusing "uncaught
  913. * play promise" rejection error messages.
  914. * @param {Object} value An object that may or may not be `Promise`-like.
  915. */
  916. function silencePromise(value) {
  917. if (is$1.promise(value)) {
  918. value.then(null, function () {});
  919. }
  920. }
  921. function validateRatio(input) {
  922. if (!is$1.array(input) && (!is$1.string(input) || !input.includes(':'))) {
  923. return false;
  924. }
  925. var ratio = is$1.array(input) ? input : input.split(':');
  926. return ratio.map(Number).every(is$1.number);
  927. }
  928. function reduceAspectRatio(ratio) {
  929. if (!is$1.array(ratio) || !ratio.every(is$1.number)) {
  930. return null;
  931. }
  932. var _ratio = _slicedToArray(ratio, 2),
  933. width = _ratio[0],
  934. height = _ratio[1];
  935. var getDivider = function getDivider(w, h) {
  936. return h === 0 ? w : getDivider(h, w % h);
  937. };
  938. var divider = getDivider(width, height);
  939. return [width / divider, height / divider];
  940. }
  941. function getAspectRatio(input) {
  942. var parse = function parse(ratio) {
  943. return validateRatio(ratio) ? ratio.split(':').map(Number) : null;
  944. }; // Try provided ratio
  945. var ratio = parse(input); // Get from config
  946. if (ratio === null) {
  947. ratio = parse(this.config.ratio);
  948. } // Get from embed
  949. if (ratio === null && !is$1.empty(this.embed) && is$1.array(this.embed.ratio)) {
  950. ratio = this.embed.ratio;
  951. } // Get from HTML5 video
  952. if (ratio === null && this.isHTML5) {
  953. var _this$media = this.media,
  954. videoWidth = _this$media.videoWidth,
  955. videoHeight = _this$media.videoHeight;
  956. ratio = reduceAspectRatio([videoWidth, videoHeight]);
  957. }
  958. return ratio;
  959. } // Set aspect ratio for responsive container
  960. function setAspectRatio(input) {
  961. if (!this.isVideo) {
  962. return {};
  963. }
  964. var wrapper = this.elements.wrapper;
  965. var ratio = getAspectRatio.call(this, input);
  966. var _ref = is$1.array(ratio) ? ratio : [0, 0],
  967. _ref2 = _slicedToArray(_ref, 2),
  968. w = _ref2[0],
  969. h = _ref2[1];
  970. var padding = 100 / w * h;
  971. wrapper.style.paddingBottom = "".concat(padding, "%"); // For Vimeo we have an extra <div> to hide the standard controls and UI
  972. if (this.isVimeo && !this.config.vimeo.premium && this.supported.ui) {
  973. var height = 100 / this.media.offsetWidth * parseInt(window.getComputedStyle(this.media).paddingBottom, 10);
  974. var offset = (height - padding) / (height / 50);
  975. this.media.style.transform = "translateY(-".concat(offset, "%)");
  976. } else if (this.isHTML5) {
  977. wrapper.classList.toggle(this.config.classNames.videoFixedRatio, ratio !== null);
  978. }
  979. return {
  980. padding: padding,
  981. ratio: ratio
  982. };
  983. }
  984. // ==========================================================================
  985. var html5 = {
  986. getSources: function getSources() {
  987. var _this = this;
  988. if (!this.isHTML5) {
  989. return [];
  990. }
  991. var sources = Array.from(this.media.querySelectorAll('source')); // Filter out unsupported sources (if type is specified)
  992. return sources.filter(function (source) {
  993. var type = source.getAttribute('type');
  994. if (is$1.empty(type)) {
  995. return true;
  996. }
  997. return support.mime.call(_this, type);
  998. });
  999. },
  1000. // Get quality levels
  1001. getQualityOptions: function getQualityOptions() {
  1002. // Whether we're forcing all options (e.g. for streaming)
  1003. if (this.config.quality.forced) {
  1004. return this.config.quality.options;
  1005. } // Get sizes from <source> elements
  1006. return html5.getSources.call(this).map(function (source) {
  1007. return Number(source.getAttribute('data-res'));
  1008. }).filter(Boolean);
  1009. },
  1010. setup: function setup() {
  1011. if (!this.isHTML5) {
  1012. return;
  1013. }
  1014. var player = this; // Set speed options from config
  1015. player.options.speed = player.config.speed.options; // Set aspect ratio if fixed
  1016. if (!is$1.empty(this.config.ratio)) {
  1017. setAspectRatio.call(player);
  1018. } // Quality
  1019. Object.defineProperty(player.media, 'quality', {
  1020. get: function get() {
  1021. // Get sources
  1022. var sources = html5.getSources.call(player);
  1023. var source = sources.find(function (s) {
  1024. return s.getAttribute('src') === player.source;
  1025. }); // Return size, if match is found
  1026. return source && Number(source.getAttribute('data-res'));
  1027. },
  1028. set: function set(input) {
  1029. if (player.quality === input) {
  1030. return;
  1031. } // If we're using an an external handler...
  1032. if (player.config.quality.forced && is$1.function(player.config.quality.onChange)) {
  1033. player.config.quality.onChange(input);
  1034. } else {
  1035. // Get sources
  1036. var sources = html5.getSources.call(player); // Get first match for requested size
  1037. var source = sources.find(function (s) {
  1038. return Number(s.getAttribute('data-res')) === input;
  1039. }); // No matching source found
  1040. if (!source) {
  1041. return;
  1042. } // Get current state
  1043. var _player$media = player.media,
  1044. currentTime = _player$media.currentTime,
  1045. paused = _player$media.paused,
  1046. preload = _player$media.preload,
  1047. readyState = _player$media.readyState,
  1048. playbackRate = _player$media.playbackRate; // Set new source
  1049. player.media.src = source.getAttribute('src'); // Prevent loading if preload="none" and the current source isn't loaded (#1044)
  1050. if (preload !== 'none' || readyState) {
  1051. // Restore time
  1052. player.once('loadedmetadata', function () {
  1053. player.speed = playbackRate;
  1054. player.currentTime = currentTime; // Resume playing
  1055. if (!paused) {
  1056. silencePromise(player.play());
  1057. }
  1058. }); // Load new source
  1059. player.media.load();
  1060. }
  1061. } // Trigger change event
  1062. triggerEvent.call(player, player.media, 'qualitychange', false, {
  1063. quality: input
  1064. });
  1065. }
  1066. });
  1067. },
  1068. // Cancel current network requests
  1069. // See https://github.com/sampotts/plyr/issues/174
  1070. cancelRequests: function cancelRequests() {
  1071. if (!this.isHTML5) {
  1072. return;
  1073. } // Remove child sources
  1074. removeElement(html5.getSources.call(this)); // Set blank video src attribute
  1075. // This is to prevent a MEDIA_ERR_SRC_NOT_SUPPORTED error
  1076. // Info: http://stackoverflow.com/questions/32231579/how-to-properly-dispose-of-an-html5-video-and-close-socket-or-connection
  1077. this.media.setAttribute('src', this.config.blankVideo); // Load the new empty source
  1078. // This will cancel existing requests
  1079. // See https://github.com/sampotts/plyr/issues/174
  1080. this.media.load(); // Debugging
  1081. this.debug.log('Cancelled network requests');
  1082. }
  1083. };
  1084. // ==========================================================================
  1085. function dedupe(array) {
  1086. if (!is$1.array(array)) {
  1087. return array;
  1088. }
  1089. return array.filter(function (item, index) {
  1090. return array.indexOf(item) === index;
  1091. });
  1092. } // Get the closest value in an array
  1093. function closest$1(array, value) {
  1094. if (!is$1.array(array) || !array.length) {
  1095. return null;
  1096. }
  1097. return array.reduce(function (prev, curr) {
  1098. return Math.abs(curr - value) < Math.abs(prev - value) ? curr : prev;
  1099. });
  1100. }
  1101. // ==========================================================================
  1102. function generateId(prefix) {
  1103. return "".concat(prefix, "-").concat(Math.floor(Math.random() * 10000));
  1104. } // Format string
  1105. function format(input) {
  1106. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  1107. args[_key - 1] = arguments[_key];
  1108. }
  1109. if (is$1.empty(input)) {
  1110. return input;
  1111. }
  1112. return input.toString().replace(/{(\d+)}/g, function (match, i) {
  1113. return args[i].toString();
  1114. });
  1115. } // Get percentage
  1116. function getPercentage(current, max) {
  1117. if (current === 0 || max === 0 || Number.isNaN(current) || Number.isNaN(max)) {
  1118. return 0;
  1119. }
  1120. return (current / max * 100).toFixed(2);
  1121. } // Replace all occurances of a string in a string
  1122. var replaceAll = function replaceAll() {
  1123. var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  1124. var find = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  1125. var replace = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
  1126. return input.replace(new RegExp(find.toString().replace(/([.*+?^=!:${}()|[\]/\\])/g, '\\$1'), 'g'), replace.toString());
  1127. }; // Convert to title case
  1128. var toTitleCase = function toTitleCase() {
  1129. var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  1130. return input.toString().replace(/\w\S*/g, function (text) {
  1131. return text.charAt(0).toUpperCase() + text.substr(1).toLowerCase();
  1132. });
  1133. }; // Convert string to pascalCase
  1134. function toPascalCase() {
  1135. var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  1136. var string = input.toString(); // Convert kebab case
  1137. string = replaceAll(string, '-', ' '); // Convert snake case
  1138. string = replaceAll(string, '_', ' '); // Convert to title case
  1139. string = toTitleCase(string); // Convert to pascal case
  1140. return replaceAll(string, ' ', '');
  1141. } // Convert string to pascalCase
  1142. function toCamelCase() {
  1143. var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  1144. var string = input.toString(); // Convert to pascal case
  1145. string = toPascalCase(string); // Convert first character to lowercase
  1146. return string.charAt(0).toLowerCase() + string.slice(1);
  1147. } // Remove HTML from a string
  1148. function stripHTML(source) {
  1149. var fragment = document.createDocumentFragment();
  1150. var element = document.createElement('div');
  1151. fragment.appendChild(element);
  1152. element.innerHTML = source;
  1153. return fragment.firstChild.innerText;
  1154. } // Like outerHTML, but also works for DocumentFragment
  1155. function getHTML(element) {
  1156. var wrapper = document.createElement('div');
  1157. wrapper.appendChild(element);
  1158. return wrapper.innerHTML;
  1159. }
  1160. var resources = {
  1161. pip: 'PIP',
  1162. airplay: 'AirPlay',
  1163. html5: 'HTML5',
  1164. vimeo: 'Vimeo',
  1165. youtube: 'YouTube'
  1166. };
  1167. var i18n = {
  1168. get: function get() {
  1169. var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  1170. var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1171. if (is$1.empty(key) || is$1.empty(config)) {
  1172. return '';
  1173. }
  1174. var string = getDeep(config.i18n, key);
  1175. if (is$1.empty(string)) {
  1176. if (Object.keys(resources).includes(key)) {
  1177. return resources[key];
  1178. }
  1179. return '';
  1180. }
  1181. var replace = {
  1182. '{seektime}': config.seekTime,
  1183. '{title}': config.title
  1184. };
  1185. Object.entries(replace).forEach(function (_ref) {
  1186. var _ref2 = _slicedToArray(_ref, 2),
  1187. k = _ref2[0],
  1188. v = _ref2[1];
  1189. string = replaceAll(string, k, v);
  1190. });
  1191. return string;
  1192. }
  1193. };
  1194. var Storage = /*#__PURE__*/function () {
  1195. function Storage(player) {
  1196. _classCallCheck(this, Storage);
  1197. this.enabled = player.config.storage.enabled;
  1198. this.key = player.config.storage.key;
  1199. } // Check for actual support (see if we can use it)
  1200. _createClass(Storage, [{
  1201. key: "get",
  1202. value: function get(key) {
  1203. if (!Storage.supported || !this.enabled) {
  1204. return null;
  1205. }
  1206. var store = window.localStorage.getItem(this.key);
  1207. if (is$1.empty(store)) {
  1208. return null;
  1209. }
  1210. var json = JSON.parse(store);
  1211. return is$1.string(key) && key.length ? json[key] : json;
  1212. }
  1213. }, {
  1214. key: "set",
  1215. value: function set(object) {
  1216. // Bail if we don't have localStorage support or it's disabled
  1217. if (!Storage.supported || !this.enabled) {
  1218. return;
  1219. } // Can only store objectst
  1220. if (!is$1.object(object)) {
  1221. return;
  1222. } // Get current storage
  1223. var storage = this.get(); // Default to empty object
  1224. if (is$1.empty(storage)) {
  1225. storage = {};
  1226. } // Update the working copy of the values
  1227. extend(storage, object); // Update storage
  1228. window.localStorage.setItem(this.key, JSON.stringify(storage));
  1229. }
  1230. }], [{
  1231. key: "supported",
  1232. get: function get() {
  1233. try {
  1234. if (!('localStorage' in window)) {
  1235. return false;
  1236. }
  1237. var test = '___test'; // Try to use it (it might be disabled, e.g. user is in private mode)
  1238. // see: https://github.com/sampotts/plyr/issues/131
  1239. window.localStorage.setItem(test, test);
  1240. window.localStorage.removeItem(test);
  1241. return true;
  1242. } catch (e) {
  1243. return false;
  1244. }
  1245. }
  1246. }]);
  1247. return Storage;
  1248. }();
  1249. // ==========================================================================
  1250. // Fetch wrapper
  1251. // Using XHR to avoid issues with older browsers
  1252. // ==========================================================================
  1253. function fetch(url) {
  1254. var responseType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'text';
  1255. return new Promise(function (resolve, reject) {
  1256. try {
  1257. var request = new XMLHttpRequest(); // Check for CORS support
  1258. if (!('withCredentials' in request)) {
  1259. return;
  1260. }
  1261. request.addEventListener('load', function () {
  1262. if (responseType === 'text') {
  1263. try {
  1264. resolve(JSON.parse(request.responseText));
  1265. } catch (e) {
  1266. resolve(request.responseText);
  1267. }
  1268. } else {
  1269. resolve(request.response);
  1270. }
  1271. });
  1272. request.addEventListener('error', function () {
  1273. throw new Error(request.status);
  1274. });
  1275. request.open('GET', url, true); // Set the required response type
  1276. request.responseType = responseType;
  1277. request.send();
  1278. } catch (e) {
  1279. reject(e);
  1280. }
  1281. });
  1282. }
  1283. // ==========================================================================
  1284. function loadSprite(url, id) {
  1285. if (!is$1.string(url)) {
  1286. return;
  1287. }
  1288. var prefix = 'cache';
  1289. var hasId = is$1.string(id);
  1290. var isCached = false;
  1291. var exists = function exists() {
  1292. return document.getElementById(id) !== null;
  1293. };
  1294. var update = function update(container, data) {
  1295. // eslint-disable-next-line no-param-reassign
  1296. container.innerHTML = data; // Check again incase of race condition
  1297. if (hasId && exists()) {
  1298. return;
  1299. } // Inject the SVG to the body
  1300. document.body.insertAdjacentElement('afterbegin', container);
  1301. }; // Only load once if ID set
  1302. if (!hasId || !exists()) {
  1303. var useStorage = Storage.supported; // Create container
  1304. var container = document.createElement('div');
  1305. container.setAttribute('hidden', '');
  1306. if (hasId) {
  1307. container.setAttribute('id', id);
  1308. } // Check in cache
  1309. if (useStorage) {
  1310. var cached = window.localStorage.getItem("".concat(prefix, "-").concat(id));
  1311. isCached = cached !== null;
  1312. if (isCached) {
  1313. var data = JSON.parse(cached);
  1314. update(container, data.content);
  1315. }
  1316. } // Get the sprite
  1317. fetch(url).then(function (result) {
  1318. if (is$1.empty(result)) {
  1319. return;
  1320. }
  1321. if (useStorage) {
  1322. window.localStorage.setItem("".concat(prefix, "-").concat(id), JSON.stringify({
  1323. content: result
  1324. }));
  1325. }
  1326. update(container, result);
  1327. }).catch(function () {});
  1328. }
  1329. }
  1330. // ==========================================================================
  1331. var getHours = function getHours(value) {
  1332. return Math.trunc(value / 60 / 60 % 60, 10);
  1333. };
  1334. var getMinutes = function getMinutes(value) {
  1335. return Math.trunc(value / 60 % 60, 10);
  1336. };
  1337. var getSeconds = function getSeconds(value) {
  1338. return Math.trunc(value % 60, 10);
  1339. }; // Format time to UI friendly string
  1340. function formatTime() {
  1341. var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  1342. var displayHours = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  1343. var inverted = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  1344. // Bail if the value isn't a number
  1345. if (!is$1.number(time)) {
  1346. return formatTime(undefined, displayHours, inverted);
  1347. } // Format time component to add leading zero
  1348. var format = function format(value) {
  1349. return "0".concat(value).slice(-2);
  1350. }; // Breakdown to hours, mins, secs
  1351. var hours = getHours(time);
  1352. var mins = getMinutes(time);
  1353. var secs = getSeconds(time); // Do we need to display hours?
  1354. if (displayHours || hours > 0) {
  1355. hours = "".concat(hours, ":");
  1356. } else {
  1357. hours = '';
  1358. } // Render
  1359. return "".concat(inverted && time > 0 ? '-' : '').concat(hours).concat(format(mins), ":").concat(format(secs));
  1360. }
  1361. var controls = {
  1362. // Get icon URL
  1363. getIconUrl: function getIconUrl() {
  1364. var url = new URL(this.config.iconUrl, window.location);
  1365. var cors = url.host !== window.location.host || browser.isIE && !window.svg4everybody;
  1366. return {
  1367. url: this.config.iconUrl,
  1368. cors: cors
  1369. };
  1370. },
  1371. // Find the UI controls
  1372. findElements: function findElements() {
  1373. try {
  1374. this.elements.controls = getElement.call(this, this.config.selectors.controls.wrapper); // Buttons
  1375. this.elements.buttons = {
  1376. play: getElements.call(this, this.config.selectors.buttons.play),
  1377. pause: getElement.call(this, this.config.selectors.buttons.pause),
  1378. restart: getElement.call(this, this.config.selectors.buttons.restart),
  1379. rewind: getElement.call(this, this.config.selectors.buttons.rewind),
  1380. fastForward: getElement.call(this, this.config.selectors.buttons.fastForward),
  1381. mute: getElement.call(this, this.config.selectors.buttons.mute),
  1382. pip: getElement.call(this, this.config.selectors.buttons.pip),
  1383. airplay: getElement.call(this, this.config.selectors.buttons.airplay),
  1384. settings: getElement.call(this, this.config.selectors.buttons.settings),
  1385. captions: getElement.call(this, this.config.selectors.buttons.captions),
  1386. fullscreen: getElement.call(this, this.config.selectors.buttons.fullscreen)
  1387. }; // Progress
  1388. this.elements.progress = getElement.call(this, this.config.selectors.progress); // Inputs
  1389. this.elements.inputs = {
  1390. seek: getElement.call(this, this.config.selectors.inputs.seek),
  1391. volume: getElement.call(this, this.config.selectors.inputs.volume)
  1392. }; // Display
  1393. this.elements.display = {
  1394. buffer: getElement.call(this, this.config.selectors.display.buffer),
  1395. currentTime: getElement.call(this, this.config.selectors.display.currentTime),
  1396. duration: getElement.call(this, this.config.selectors.display.duration)
  1397. }; // Seek tooltip
  1398. if (is$1.element(this.elements.progress)) {
  1399. this.elements.display.seekTooltip = this.elements.progress.querySelector(".".concat(this.config.classNames.tooltip));
  1400. }
  1401. return true;
  1402. } catch (error) {
  1403. // Log it
  1404. this.debug.warn('It looks like there is a problem with your custom controls HTML', error); // Restore native video controls
  1405. this.toggleNativeControls(true);
  1406. return false;
  1407. }
  1408. },
  1409. // Create <svg> icon
  1410. createIcon: function createIcon(type, attributes) {
  1411. var namespace = 'http://www.w3.org/2000/svg';
  1412. var iconUrl = controls.getIconUrl.call(this);
  1413. var iconPath = "".concat(!iconUrl.cors ? iconUrl.url : '', "#").concat(this.config.iconPrefix); // Create <svg>
  1414. var icon = document.createElementNS(namespace, 'svg');
  1415. setAttributes(icon, extend(attributes, {
  1416. 'aria-hidden': 'true',
  1417. focusable: 'false'
  1418. })); // Create the <use> to reference sprite
  1419. var use = document.createElementNS(namespace, 'use');
  1420. var path = "".concat(iconPath, "-").concat(type); // Set `href` attributes
  1421. // https://github.com/sampotts/plyr/issues/460
  1422. // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/xlink:href
  1423. if ('href' in use) {
  1424. use.setAttributeNS('http://www.w3.org/1999/xlink', 'href', path);
  1425. } // Always set the older attribute even though it's "deprecated" (it'll be around for ages)
  1426. use.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', path); // Add <use> to <svg>
  1427. icon.appendChild(use);
  1428. return icon;
  1429. },
  1430. // Create hidden text label
  1431. createLabel: function createLabel(key) {
  1432. var attr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1433. var text = i18n.get(key, this.config);
  1434. var attributes = _objectSpread2(_objectSpread2({}, attr), {}, {
  1435. class: [attr.class, this.config.classNames.hidden].filter(Boolean).join(' ')
  1436. });
  1437. return createElement('span', attributes, text);
  1438. },
  1439. // Create a badge
  1440. createBadge: function createBadge(text) {
  1441. if (is$1.empty(text)) {
  1442. return null;
  1443. }
  1444. var badge = createElement('span', {
  1445. class: this.config.classNames.menu.value
  1446. });
  1447. badge.appendChild(createElement('span', {
  1448. class: this.config.classNames.menu.badge
  1449. }, text));
  1450. return badge;
  1451. },
  1452. // Create a <button>
  1453. createButton: function createButton(buttonType, attr) {
  1454. var _this = this;
  1455. var attributes = extend({}, attr);
  1456. var type = toCamelCase(buttonType);
  1457. var props = {
  1458. element: 'button',
  1459. toggle: false,
  1460. label: null,
  1461. icon: null,
  1462. labelPressed: null,
  1463. iconPressed: null
  1464. };
  1465. ['element', 'icon', 'label'].forEach(function (key) {
  1466. if (Object.keys(attributes).includes(key)) {
  1467. props[key] = attributes[key];
  1468. delete attributes[key];
  1469. }
  1470. }); // Default to 'button' type to prevent form submission
  1471. if (props.element === 'button' && !Object.keys(attributes).includes('type')) {
  1472. attributes.type = 'button';
  1473. } // Set class name
  1474. if (Object.keys(attributes).includes('class')) {
  1475. if (!attributes.class.split(' ').some(function (c) {
  1476. return c === _this.config.classNames.control;
  1477. })) {
  1478. extend(attributes, {
  1479. class: "".concat(attributes.class, " ").concat(this.config.classNames.control)
  1480. });
  1481. }
  1482. } else {
  1483. attributes.class = this.config.classNames.control;
  1484. } // Large play button
  1485. switch (buttonType) {
  1486. case 'play':
  1487. props.toggle = true;
  1488. props.label = 'play';
  1489. props.labelPressed = 'pause';
  1490. props.icon = 'play';
  1491. props.iconPressed = 'pause';
  1492. break;
  1493. case 'mute':
  1494. props.toggle = true;
  1495. props.label = 'mute';
  1496. props.labelPressed = 'unmute';
  1497. props.icon = 'volume';
  1498. props.iconPressed = 'muted';
  1499. break;
  1500. case 'captions':
  1501. props.toggle = true;
  1502. props.label = 'enableCaptions';
  1503. props.labelPressed = 'disableCaptions';
  1504. props.icon = 'captions-off';
  1505. props.iconPressed = 'captions-on';
  1506. break;
  1507. case 'fullscreen':
  1508. props.toggle = true;
  1509. props.label = 'enterFullscreen';
  1510. props.labelPressed = 'exitFullscreen';
  1511. props.icon = 'enter-fullscreen';
  1512. props.iconPressed = 'exit-fullscreen';
  1513. break;
  1514. case 'play-large':
  1515. attributes.class += " ".concat(this.config.classNames.control, "--overlaid");
  1516. type = 'play';
  1517. props.label = 'play';
  1518. props.icon = 'play';
  1519. break;
  1520. default:
  1521. if (is$1.empty(props.label)) {
  1522. props.label = type;
  1523. }
  1524. if (is$1.empty(props.icon)) {
  1525. props.icon = buttonType;
  1526. }
  1527. }
  1528. var button = createElement(props.element); // Setup toggle icon and labels
  1529. if (props.toggle) {
  1530. // Icon
  1531. button.appendChild(controls.createIcon.call(this, props.iconPressed, {
  1532. class: 'icon--pressed'
  1533. }));
  1534. button.appendChild(controls.createIcon.call(this, props.icon, {
  1535. class: 'icon--not-pressed'
  1536. })); // Label/Tooltip
  1537. button.appendChild(controls.createLabel.call(this, props.labelPressed, {
  1538. class: 'label--pressed'
  1539. }));
  1540. button.appendChild(controls.createLabel.call(this, props.label, {
  1541. class: 'label--not-pressed'
  1542. }));
  1543. } else {
  1544. button.appendChild(controls.createIcon.call(this, props.icon));
  1545. button.appendChild(controls.createLabel.call(this, props.label));
  1546. } // Merge and set attributes
  1547. extend(attributes, getAttributesFromSelector(this.config.selectors.buttons[type], attributes));
  1548. setAttributes(button, attributes); // We have multiple play buttons
  1549. if (type === 'play') {
  1550. if (!is$1.array(this.elements.buttons[type])) {
  1551. this.elements.buttons[type] = [];
  1552. }
  1553. this.elements.buttons[type].push(button);
  1554. } else {
  1555. this.elements.buttons[type] = button;
  1556. }
  1557. return button;
  1558. },
  1559. // Create an <input type='range'>
  1560. createRange: function createRange(type, attributes) {
  1561. // Seek input
  1562. var input = createElement('input', extend(getAttributesFromSelector(this.config.selectors.inputs[type]), {
  1563. type: 'range',
  1564. min: 0,
  1565. max: 100,
  1566. step: 0.01,
  1567. value: 0,
  1568. autocomplete: 'off',
  1569. // A11y fixes for https://github.com/sampotts/plyr/issues/905
  1570. role: 'slider',
  1571. 'aria-label': i18n.get(type, this.config),
  1572. 'aria-valuemin': 0,
  1573. 'aria-valuemax': 100,
  1574. 'aria-valuenow': 0
  1575. }, attributes));
  1576. this.elements.inputs[type] = input; // Set the fill for webkit now
  1577. controls.updateRangeFill.call(this, input); // Improve support on touch devices
  1578. RangeTouch.setup(input);
  1579. return input;
  1580. },
  1581. // Create a <progress>
  1582. createProgress: function createProgress(type, attributes) {
  1583. var progress = createElement('progress', extend(getAttributesFromSelector(this.config.selectors.display[type]), {
  1584. min: 0,
  1585. max: 100,
  1586. value: 0,
  1587. role: 'progressbar',
  1588. 'aria-hidden': true
  1589. }, attributes)); // Create the label inside
  1590. if (type !== 'volume') {
  1591. progress.appendChild(createElement('span', null, '0'));
  1592. var suffixKey = {
  1593. played: 'played',
  1594. buffer: 'buffered'
  1595. }[type];
  1596. var suffix = suffixKey ? i18n.get(suffixKey, this.config) : '';
  1597. progress.innerText = "% ".concat(suffix.toLowerCase());
  1598. }
  1599. this.elements.display[type] = progress;
  1600. return progress;
  1601. },
  1602. // Create time display
  1603. createTime: function createTime(type, attrs) {
  1604. var attributes = getAttributesFromSelector(this.config.selectors.display[type], attrs);
  1605. var container = createElement('div', extend(attributes, {
  1606. class: "".concat(attributes.class ? attributes.class : '', " ").concat(this.config.classNames.display.time, " ").trim(),
  1607. 'aria-label': i18n.get(type, this.config)
  1608. }), '00:00'); // Reference for updates
  1609. this.elements.display[type] = container;
  1610. return container;
  1611. },
  1612. // Bind keyboard shortcuts for a menu item
  1613. // We have to bind to keyup otherwise Firefox triggers a click when a keydown event handler shifts focus
  1614. // https://bugzilla.mozilla.org/show_bug.cgi?id=1220143
  1615. bindMenuItemShortcuts: function bindMenuItemShortcuts(menuItem, type) {
  1616. var _this2 = this;
  1617. // Navigate through menus via arrow keys and space
  1618. on.call(this, menuItem, 'keydown keyup', function (event) {
  1619. // We only care about space and ⬆️ ⬇️️ ➡️
  1620. if (![32, 38, 39, 40].includes(event.which)) {
  1621. return;
  1622. } // Prevent play / seek
  1623. event.preventDefault();
  1624. event.stopPropagation(); // We're just here to prevent the keydown bubbling
  1625. if (event.type === 'keydown') {
  1626. return;
  1627. }
  1628. var isRadioButton = matches$1(menuItem, '[role="menuitemradio"]'); // Show the respective menu
  1629. if (!isRadioButton && [32, 39].includes(event.which)) {
  1630. controls.showMenuPanel.call(_this2, type, true);
  1631. } else {
  1632. var target;
  1633. if (event.which !== 32) {
  1634. if (event.which === 40 || isRadioButton && event.which === 39) {
  1635. target = menuItem.nextElementSibling;
  1636. if (!is$1.element(target)) {
  1637. target = menuItem.parentNode.firstElementChild;
  1638. }
  1639. } else {
  1640. target = menuItem.previousElementSibling;
  1641. if (!is$1.element(target)) {
  1642. target = menuItem.parentNode.lastElementChild;
  1643. }
  1644. }
  1645. setFocus.call(_this2, target, true);
  1646. }
  1647. }
  1648. }, false); // Enter will fire a `click` event but we still need to manage focus
  1649. // So we bind to keyup which fires after and set focus here
  1650. on.call(this, menuItem, 'keyup', function (event) {
  1651. if (event.which !== 13) {
  1652. return;
  1653. }
  1654. controls.focusFirstMenuItem.call(_this2, null, true);
  1655. });
  1656. },
  1657. // Create a settings menu item
  1658. createMenuItem: function createMenuItem(_ref) {
  1659. var _this3 = this;
  1660. var value = _ref.value,
  1661. list = _ref.list,
  1662. type = _ref.type,
  1663. title = _ref.title,
  1664. _ref$badge = _ref.badge,
  1665. badge = _ref$badge === void 0 ? null : _ref$badge,
  1666. _ref$checked = _ref.checked,
  1667. checked = _ref$checked === void 0 ? false : _ref$checked;
  1668. var attributes = getAttributesFromSelector(this.config.selectors.inputs[type]);
  1669. var menuItem = createElement('button', extend(attributes, {
  1670. type: 'button',
  1671. role: 'menuitemradio',
  1672. class: "".concat(this.config.classNames.control, " ").concat(attributes.class ? attributes.class : '').trim(),
  1673. 'aria-checked': checked,
  1674. value: value
  1675. }));
  1676. var flex = createElement('span'); // We have to set as HTML incase of special characters
  1677. flex.innerHTML = title;
  1678. if (is$1.element(badge)) {
  1679. flex.appendChild(badge);
  1680. }
  1681. menuItem.appendChild(flex); // Replicate radio button behaviour
  1682. Object.defineProperty(menuItem, 'checked', {
  1683. enumerable: true,
  1684. get: function get() {
  1685. return menuItem.getAttribute('aria-checked') === 'true';
  1686. },
  1687. set: function set(check) {
  1688. // Ensure exclusivity
  1689. if (check) {
  1690. Array.from(menuItem.parentNode.children).filter(function (node) {
  1691. return matches$1(node, '[role="menuitemradio"]');
  1692. }).forEach(function (node) {
  1693. return node.setAttribute('aria-checked', 'false');
  1694. });
  1695. }
  1696. menuItem.setAttribute('aria-checked', check ? 'true' : 'false');
  1697. }
  1698. });
  1699. this.listeners.bind(menuItem, 'click keyup', function (event) {
  1700. if (is$1.keyboardEvent(event) && event.which !== 32) {
  1701. return;
  1702. }
  1703. event.preventDefault();
  1704. event.stopPropagation();
  1705. menuItem.checked = true;
  1706. switch (type) {
  1707. case 'language':
  1708. _this3.currentTrack = Number(value);
  1709. break;
  1710. case 'quality':
  1711. _this3.quality = value;
  1712. break;
  1713. case 'speed':
  1714. _this3.speed = parseFloat(value);
  1715. break;
  1716. }
  1717. controls.showMenuPanel.call(_this3, 'home', is$1.keyboardEvent(event));
  1718. }, type, false);
  1719. controls.bindMenuItemShortcuts.call(this, menuItem, type);
  1720. list.appendChild(menuItem);
  1721. },
  1722. // Format a time for display
  1723. formatTime: function formatTime$1() {
  1724. var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  1725. var inverted = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  1726. // Bail if the value isn't a number
  1727. if (!is$1.number(time)) {
  1728. return time;
  1729. } // Always display hours if duration is over an hour
  1730. var forceHours = getHours(this.duration) > 0;
  1731. return formatTime(time, forceHours, inverted);
  1732. },
  1733. // Update the displayed time
  1734. updateTimeDisplay: function updateTimeDisplay() {
  1735. var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  1736. var time = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  1737. var inverted = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  1738. // Bail if there's no element to display or the value isn't a number
  1739. if (!is$1.element(target) || !is$1.number(time)) {
  1740. return;
  1741. } // eslint-disable-next-line no-param-reassign
  1742. target.innerText = controls.formatTime(time, inverted);
  1743. },
  1744. // Update volume UI and storage
  1745. updateVolume: function updateVolume() {
  1746. if (!this.supported.ui) {
  1747. return;
  1748. } // Update range
  1749. if (is$1.element(this.elements.inputs.volume)) {
  1750. controls.setRange.call(this, this.elements.inputs.volume, this.muted ? 0 : this.volume);
  1751. } // Update mute state
  1752. if (is$1.element(this.elements.buttons.mute)) {
  1753. this.elements.buttons.mute.pressed = this.muted || this.volume === 0;
  1754. }
  1755. },
  1756. // Update seek value and lower fill
  1757. setRange: function setRange(target) {
  1758. var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  1759. if (!is$1.element(target)) {
  1760. return;
  1761. } // eslint-disable-next-line
  1762. target.value = value; // Webkit range fill
  1763. controls.updateRangeFill.call(this, target);
  1764. },
  1765. // Update <progress> elements
  1766. updateProgress: function updateProgress(event) {
  1767. var _this4 = this;
  1768. if (!this.supported.ui || !is$1.event(event)) {
  1769. return;
  1770. }
  1771. var value = 0;
  1772. var setProgress = function setProgress(target, input) {
  1773. var val = is$1.number(input) ? input : 0;
  1774. var progress = is$1.element(target) ? target : _this4.elements.display.buffer; // Update value and label
  1775. if (is$1.element(progress)) {
  1776. progress.value = val; // Update text label inside
  1777. var label = progress.getElementsByTagName('span')[0];
  1778. if (is$1.element(label)) {
  1779. label.childNodes[0].nodeValue = val;
  1780. }
  1781. }
  1782. };
  1783. if (event) {
  1784. switch (event.type) {
  1785. // Video playing
  1786. case 'timeupdate':
  1787. case 'seeking':
  1788. case 'seeked':
  1789. value = getPercentage(this.currentTime, this.duration); // Set seek range value only if it's a 'natural' time event
  1790. if (event.type === 'timeupdate') {
  1791. controls.setRange.call(this, this.elements.inputs.seek, value);
  1792. }
  1793. break;
  1794. // Check buffer status
  1795. case 'playing':
  1796. case 'progress':
  1797. setProgress(this.elements.display.buffer, this.buffered * 100);
  1798. break;
  1799. }
  1800. }
  1801. },
  1802. // Webkit polyfill for lower fill range
  1803. updateRangeFill: function updateRangeFill(target) {
  1804. // Get range from event if event passed
  1805. var range = is$1.event(target) ? target.target : target; // Needs to be a valid <input type='range'>
  1806. if (!is$1.element(range) || range.getAttribute('type') !== 'range') {
  1807. return;
  1808. } // Set aria values for https://github.com/sampotts/plyr/issues/905
  1809. if (matches$1(range, this.config.selectors.inputs.seek)) {
  1810. range.setAttribute('aria-valuenow', this.currentTime);
  1811. var currentTime = controls.formatTime(this.currentTime);
  1812. var duration = controls.formatTime(this.duration);
  1813. var format = i18n.get('seekLabel', this.config);
  1814. range.setAttribute('aria-valuetext', format.replace('{currentTime}', currentTime).replace('{duration}', duration));
  1815. } else if (matches$1(range, this.config.selectors.inputs.volume)) {
  1816. var percent = range.value * 100;
  1817. range.setAttribute('aria-valuenow', percent);
  1818. range.setAttribute('aria-valuetext', "".concat(percent.toFixed(1), "%"));
  1819. } else {
  1820. range.setAttribute('aria-valuenow', range.value);
  1821. } // WebKit only
  1822. if (!browser.isWebkit) {
  1823. return;
  1824. } // Set CSS custom property
  1825. range.style.setProperty('--value', "".concat(range.value / range.max * 100, "%"));
  1826. },
  1827. // Update hover tooltip for seeking
  1828. updateSeekTooltip: function updateSeekTooltip(event) {
  1829. var _this5 = this;
  1830. // Bail if setting not true
  1831. if (!this.config.tooltips.seek || !is$1.element(this.elements.inputs.seek) || !is$1.element(this.elements.display.seekTooltip) || this.duration === 0) {
  1832. return;
  1833. }
  1834. var visible = "".concat(this.config.classNames.tooltip, "--visible");
  1835. var toggle = function toggle(show) {
  1836. return toggleClass(_this5.elements.display.seekTooltip, visible, show);
  1837. }; // Hide on touch
  1838. if (this.touch) {
  1839. toggle(false);
  1840. return;
  1841. } // Determine percentage, if already visible
  1842. var percent = 0;
  1843. var clientRect = this.elements.progress.getBoundingClientRect();
  1844. if (is$1.event(event)) {
  1845. percent = 100 / clientRect.width * (event.pageX - clientRect.left);
  1846. } else if (hasClass(this.elements.display.seekTooltip, visible)) {
  1847. percent = parseFloat(this.elements.display.seekTooltip.style.left, 10);
  1848. } else {
  1849. return;
  1850. } // Set bounds
  1851. if (percent < 0) {
  1852. percent = 0;
  1853. } else if (percent > 100) {
  1854. percent = 100;
  1855. } // Display the time a click would seek to
  1856. controls.updateTimeDisplay.call(this, this.elements.display.seekTooltip, this.duration / 100 * percent); // Set position
  1857. this.elements.display.seekTooltip.style.left = "".concat(percent, "%"); // Show/hide the tooltip
  1858. // If the event is a moues in/out and percentage is inside bounds
  1859. if (is$1.event(event) && ['mouseenter', 'mouseleave'].includes(event.type)) {
  1860. toggle(event.type === 'mouseenter');
  1861. }
  1862. },
  1863. // Handle time change event
  1864. timeUpdate: function timeUpdate(event) {
  1865. // Only invert if only one time element is displayed and used for both duration and currentTime
  1866. var invert = !is$1.element(this.elements.display.duration) && this.config.invertTime; // Duration
  1867. controls.updateTimeDisplay.call(this, this.elements.display.currentTime, invert ? this.duration - this.currentTime : this.currentTime, invert); // Ignore updates while seeking
  1868. if (event && event.type === 'timeupdate' && this.media.seeking) {
  1869. return;
  1870. } // Playing progress
  1871. controls.updateProgress.call(this, event);
  1872. },
  1873. // Show the duration on metadataloaded or durationchange events
  1874. durationUpdate: function durationUpdate() {
  1875. // Bail if no UI or durationchange event triggered after playing/seek when invertTime is false
  1876. if (!this.supported.ui || !this.config.invertTime && this.currentTime) {
  1877. return;
  1878. } // If duration is the 2**32 (shaka), Infinity (HLS), DASH-IF (Number.MAX_SAFE_INTEGER || Number.MAX_VALUE) indicating live we hide the currentTime and progressbar.
  1879. // https://github.com/video-dev/hls.js/blob/5820d29d3c4c8a46e8b75f1e3afa3e68c1a9a2db/src/controller/buffer-controller.js#L415
  1880. // https://github.com/google/shaka-player/blob/4d889054631f4e1cf0fbd80ddd2b71887c02e232/lib/media/streaming_engine.js#L1062
  1881. // https://github.com/Dash-Industry-Forum/dash.js/blob/69859f51b969645b234666800d4cb596d89c602d/src/dash/models/DashManifestModel.js#L338
  1882. if (this.duration >= Math.pow(2, 32)) {
  1883. toggleHidden(this.elements.display.currentTime, true);
  1884. toggleHidden(this.elements.progress, true);
  1885. return;
  1886. } // Update ARIA values
  1887. if (is$1.element(this.elements.inputs.seek)) {
  1888. this.elements.inputs.seek.setAttribute('aria-valuemax', this.duration);
  1889. } // If there's a spot to display duration
  1890. var hasDuration = is$1.element(this.elements.display.duration); // If there's only one time display, display duration there
  1891. if (!hasDuration && this.config.displayDuration && this.paused) {
  1892. controls.updateTimeDisplay.call(this, this.elements.display.currentTime, this.duration);
  1893. } // If there's a duration element, update content
  1894. if (hasDuration) {
  1895. controls.updateTimeDisplay.call(this, this.elements.display.duration, this.duration);
  1896. } // Update the tooltip (if visible)
  1897. controls.updateSeekTooltip.call(this);
  1898. },
  1899. // Hide/show a tab
  1900. toggleMenuButton: function toggleMenuButton(setting, toggle) {
  1901. toggleHidden(this.elements.settings.buttons[setting], !toggle);
  1902. },
  1903. // Update the selected setting
  1904. updateSetting: function updateSetting(setting, container, input) {
  1905. var pane = this.elements.settings.panels[setting];
  1906. var value = null;
  1907. var list = container;
  1908. if (setting === 'captions') {
  1909. value = this.currentTrack;
  1910. } else {
  1911. value = !is$1.empty(input) ? input : this[setting]; // Get default
  1912. if (is$1.empty(value)) {
  1913. value = this.config[setting].default;
  1914. } // Unsupported value
  1915. if (!is$1.empty(this.options[setting]) && !this.options[setting].includes(value)) {
  1916. this.debug.warn("Unsupported value of '".concat(value, "' for ").concat(setting));
  1917. return;
  1918. } // Disabled value
  1919. if (!this.config[setting].options.includes(value)) {
  1920. this.debug.warn("Disabled value of '".concat(value, "' for ").concat(setting));
  1921. return;
  1922. }
  1923. } // Get the list if we need to
  1924. if (!is$1.element(list)) {
  1925. list = pane && pane.querySelector('[role="menu"]');
  1926. } // If there's no list it means it's not been rendered...
  1927. if (!is$1.element(list)) {
  1928. return;
  1929. } // Update the label
  1930. var label = this.elements.settings.buttons[setting].querySelector(".".concat(this.config.classNames.menu.value));
  1931. label.innerHTML = controls.getLabel.call(this, setting, value); // Find the radio option and check it
  1932. var target = list && list.querySelector("[value=\"".concat(value, "\"]"));
  1933. if (is$1.element(target)) {
  1934. target.checked = true;
  1935. }
  1936. },
  1937. // Translate a value into a nice label
  1938. getLabel: function getLabel(setting, value) {
  1939. switch (setting) {
  1940. case 'speed':
  1941. return value === 1 ? i18n.get('normal', this.config) : "".concat(value, "&times;");
  1942. case 'quality':
  1943. if (is$1.number(value)) {
  1944. var label = i18n.get("qualityLabel.".concat(value), this.config);
  1945. if (!label.length) {
  1946. return "".concat(value, "p");
  1947. }
  1948. return label;
  1949. }
  1950. return toTitleCase(value);
  1951. case 'captions':
  1952. return captions.getLabel.call(this);
  1953. default:
  1954. return null;
  1955. }
  1956. },
  1957. // Set the quality menu
  1958. setQualityMenu: function setQualityMenu(options) {
  1959. var _this6 = this;
  1960. // Menu required
  1961. if (!is$1.element(this.elements.settings.panels.quality)) {
  1962. return;
  1963. }
  1964. var type = 'quality';
  1965. var list = this.elements.settings.panels.quality.querySelector('[role="menu"]'); // Set options if passed and filter based on uniqueness and config
  1966. if (is$1.array(options)) {
  1967. this.options.quality = dedupe(options).filter(function (quality) {
  1968. return _this6.config.quality.options.includes(quality);
  1969. });
  1970. } // Toggle the pane and tab
  1971. var toggle = !is$1.empty(this.options.quality) && this.options.quality.length > 1;
  1972. controls.toggleMenuButton.call(this, type, toggle); // Empty the menu
  1973. emptyElement(list); // Check if we need to toggle the parent
  1974. controls.checkMenu.call(this); // If we're hiding, nothing more to do
  1975. if (!toggle) {
  1976. return;
  1977. } // Get the badge HTML for HD, 4K etc
  1978. var getBadge = function getBadge(quality) {
  1979. var label = i18n.get("qualityBadge.".concat(quality), _this6.config);
  1980. if (!label.length) {
  1981. return null;
  1982. }
  1983. return controls.createBadge.call(_this6, label);
  1984. }; // Sort options by the config and then render options
  1985. this.options.quality.sort(function (a, b) {
  1986. var sorting = _this6.config.quality.options;
  1987. return sorting.indexOf(a) > sorting.indexOf(b) ? 1 : -1;
  1988. }).forEach(function (quality) {
  1989. controls.createMenuItem.call(_this6, {
  1990. value: quality,
  1991. list: list,
  1992. type: type,
  1993. title: controls.getLabel.call(_this6, 'quality', quality),
  1994. badge: getBadge(quality)
  1995. });
  1996. });
  1997. controls.updateSetting.call(this, type, list);
  1998. },
  1999. // Set the looping options
  2000. /* setLoopMenu() {
  2001. // Menu required
  2002. if (!is.element(this.elements.settings.panels.loop)) {
  2003. return;
  2004. }
  2005. const options = ['start', 'end', 'all', 'reset'];
  2006. const list = this.elements.settings.panels.loop.querySelector('[role="menu"]');
  2007. // Show the pane and tab
  2008. toggleHidden(this.elements.settings.buttons.loop, false);
  2009. toggleHidden(this.elements.settings.panels.loop, false);
  2010. // Toggle the pane and tab
  2011. const toggle = !is.empty(this.loop.options);
  2012. controls.toggleMenuButton.call(this, 'loop', toggle);
  2013. // Empty the menu
  2014. emptyElement(list);
  2015. options.forEach(option => {
  2016. const item = createElement('li');
  2017. const button = createElement(
  2018. 'button',
  2019. extend(getAttributesFromSelector(this.config.selectors.buttons.loop), {
  2020. type: 'button',
  2021. class: this.config.classNames.control,
  2022. 'data-plyr-loop-action': option,
  2023. }),
  2024. i18n.get(option, this.config)
  2025. );
  2026. if (['start', 'end'].includes(option)) {
  2027. const badge = controls.createBadge.call(this, '00:00');
  2028. button.appendChild(badge);
  2029. }
  2030. item.appendChild(button);
  2031. list.appendChild(item);
  2032. });
  2033. }, */
  2034. // Get current selected caption language
  2035. // TODO: rework this to user the getter in the API?
  2036. // Set a list of available captions languages
  2037. setCaptionsMenu: function setCaptionsMenu() {
  2038. var _this7 = this;
  2039. // Menu required
  2040. if (!is$1.element(this.elements.settings.panels.captions)) {
  2041. return;
  2042. } // TODO: Captions or language? Currently it's mixed
  2043. var type = 'captions';
  2044. var list = this.elements.settings.panels.captions.querySelector('[role="menucaptions"]');
  2045. var tracks = captions.getTracks.call(this);
  2046. var toggle = Boolean(tracks.length); // Toggle the pane and tab
  2047. controls.toggleMenuButton.call(this, type, toggle); // Empty the menu
  2048. emptyElement(list); // Check if we need to toggle the parent
  2049. controls.checkMenu.call(this); // If there's no captions, bail
  2050. if (!toggle) {
  2051. return;
  2052. } // Generate options data
  2053. var options = tracks.map(function (track, value) {
  2054. return {
  2055. value: value,
  2056. checked: _this7.captions.toggled && _this7.currentTrack === value,
  2057. title: captions.getLabel.call(_this7, track),
  2058. badge: track.language && controls.createBadge.call(_this7, track.language.toUpperCase()),
  2059. list: list,
  2060. type: 'language'
  2061. };
  2062. }); // Add the "Disabled" option to turn off captions
  2063. options.unshift({
  2064. value: -1,
  2065. checked: !this.captions.toggled,
  2066. title: i18n.get('disabled', this.config),
  2067. list: list,
  2068. type: 'language'
  2069. }); // Generate options
  2070. options.forEach(controls.createMenuItem.bind(this));
  2071. controls.updateSetting.call(this, type, list);
  2072. },
  2073. // Set a list of available captions languages
  2074. setSpeedMenu: function setSpeedMenu() {
  2075. var _this8 = this;
  2076. // Menu required
  2077. if (!is$1.element(this.elements.settings.panels.speed)) {
  2078. return;
  2079. }
  2080. var type = 'speed';
  2081. var list = this.elements.settings.panels.speed.querySelector('[role="menu"]'); // Filter out invalid speeds
  2082. this.options.speed = this.options.speed.filter(function (o) {
  2083. return o >= _this8.minimumSpeed && o <= _this8.maximumSpeed;
  2084. }); // Toggle the pane and tab
  2085. var toggle = !is$1.empty(this.options.speed) && this.options.speed.length > 1;
  2086. controls.toggleMenuButton.call(this, type, toggle); // Empty the menu
  2087. emptyElement(list); // Check if we need to toggle the parent
  2088. controls.checkMenu.call(this); // If we're hiding, nothing more to do
  2089. if (!toggle) {
  2090. return;
  2091. } // Create items
  2092. this.options.speed.forEach(function (speed) {
  2093. controls.createMenuItem.call(_this8, {
  2094. value: speed,
  2095. list: list,
  2096. type: type,
  2097. title: controls.getLabel.call(_this8, 'speed', speed)
  2098. });
  2099. });
  2100. controls.updateSetting.call(this, type, list);
  2101. },
  2102. // Check if we need to hide/show the settings menu
  2103. checkMenu: function checkMenu() {
  2104. var buttons = this.elements.settings.buttons;
  2105. var visible = !is$1.empty(buttons) && Object.values(buttons).some(function (button) {
  2106. return !button.hidden;
  2107. });
  2108. toggleHidden(this.elements.settings.menu, !visible);
  2109. },
  2110. // Focus the first menu item in a given (or visible) menu
  2111. focusFirstMenuItem: function focusFirstMenuItem(pane) {
  2112. var tabFocus = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  2113. if (this.elements.settings.popup.hidden) {
  2114. return;
  2115. }
  2116. var target = pane;
  2117. if (!is$1.element(target)) {
  2118. target = Object.values(this.elements.settings.panels).find(function (p) {
  2119. return !p.hidden;
  2120. });
  2121. }
  2122. var firstItem = target.querySelector('[role^="menuitem"]');
  2123. setFocus.call(this, firstItem, tabFocus);
  2124. },
  2125. // Show/hide menu
  2126. toggleMenu: function toggleMenu(input) {
  2127. var popup = this.elements.settings.popup;
  2128. var button = this.elements.buttons.settings; // Menu and button are required
  2129. if (!is$1.element(popup) || !is$1.element(button)) {
  2130. return;
  2131. } // True toggle by default
  2132. var hidden = popup.hidden;
  2133. var show = hidden;
  2134. if (is$1.boolean(input)) {
  2135. show = input;
  2136. } else if (is$1.keyboardEvent(input) && input.which === 27) {
  2137. show = false;
  2138. } else if (is$1.event(input)) {
  2139. // If Plyr is in a shadowDOM, the event target is set to the component, instead of the
  2140. // Element in the shadowDOM. The path, if available, is complete.
  2141. var target = is$1.function(input.composedPath) ? input.composedPath()[0] : input.target;
  2142. var isMenuItem = popup.contains(target); // If the click was inside the menu or if the click
  2143. // wasn't the button or menu item and we're trying to
  2144. // show the menu (a doc click shouldn't show the menu)
  2145. if (isMenuItem || !isMenuItem && input.target !== button && show) {
  2146. return;
  2147. }
  2148. } // Set button attributes
  2149. button.setAttribute('aria-expanded', show); // Show the actual popup
  2150. toggleHidden(popup, !show); // Add class hook
  2151. toggleClass(this.elements.container, this.config.classNames.menu.open, show); // Focus the first item if key interaction
  2152. if (show && is$1.keyboardEvent(input)) {
  2153. controls.focusFirstMenuItem.call(this, null, true);
  2154. } else if (!show && !hidden) {
  2155. // If closing, re-focus the button
  2156. setFocus.call(this, button, is$1.keyboardEvent(input));
  2157. }
  2158. },
  2159. // Get the natural size of a menu panel
  2160. getMenuSize: function getMenuSize(tab) {
  2161. var clone = tab.cloneNode(true);
  2162. clone.style.position = 'absolute';
  2163. clone.style.opacity = 0;
  2164. clone.removeAttribute('hidden'); // Append to parent so we get the "real" size
  2165. tab.parentNode.appendChild(clone); // Get the sizes before we remove
  2166. var width = clone.scrollWidth;
  2167. var height = clone.scrollHeight; // Remove from the DOM
  2168. removeElement(clone);
  2169. return {
  2170. width: width,
  2171. height: height
  2172. };
  2173. },
  2174. // Show a panel in the menu
  2175. showMenuPanel: function showMenuPanel() {
  2176. var _this9 = this;
  2177. var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  2178. var tabFocus = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  2179. var target = this.elements.container.querySelector("#plyr-settings-".concat(this.id, "-").concat(type)); // Nothing to show, bail
  2180. if (!is$1.element(target)) {
  2181. return;
  2182. } // Hide all other panels
  2183. var container = target.parentNode;
  2184. var current = Array.from(container.children).find(function (node) {
  2185. return !node.hidden;
  2186. }); // If we can do fancy animations, we'll animate the height/width
  2187. if (support.transitions && !support.reducedMotion) {
  2188. // Set the current width as a base
  2189. container.style.width = "".concat(current.scrollWidth, "px");
  2190. container.style.height = "".concat(current.scrollHeight, "px"); // Get potential sizes
  2191. var size = controls.getMenuSize.call(this, target); // Restore auto height/width
  2192. var restore = function restore(event) {
  2193. // We're only bothered about height and width on the container
  2194. if (event.target !== container || !['width', 'height'].includes(event.propertyName)) {
  2195. return;
  2196. } // Revert back to auto
  2197. container.style.width = '';
  2198. container.style.height = ''; // Only listen once
  2199. off.call(_this9, container, transitionEndEvent, restore);
  2200. }; // Listen for the transition finishing and restore auto height/width
  2201. on.call(this, container, transitionEndEvent, restore); // Set dimensions to target
  2202. container.style.width = "".concat(size.width, "px");
  2203. container.style.height = "".concat(size.height, "px");
  2204. } // Set attributes on current tab
  2205. toggleHidden(current, true); // Set attributes on target
  2206. toggleHidden(target, false); // Focus the first item
  2207. controls.focusFirstMenuItem.call(this, target, tabFocus);
  2208. },
  2209. // Set the download URL
  2210. setDownloadUrl: function setDownloadUrl() {
  2211. var button = this.elements.buttons.download; // Bail if no button
  2212. if (!is$1.element(button)) {
  2213. return;
  2214. } // Set attribute
  2215. button.setAttribute('href', this.download);
  2216. },
  2217. // Build the default HTML
  2218. create: function create(data) {
  2219. var _this10 = this;
  2220. var bindMenuItemShortcuts = controls.bindMenuItemShortcuts,
  2221. createButton = controls.createButton,
  2222. createProgress = controls.createProgress,
  2223. createRange = controls.createRange,
  2224. createTime = controls.createTime,
  2225. setQualityMenu = controls.setQualityMenu,
  2226. setSpeedMenu = controls.setSpeedMenu,
  2227. showMenuPanel = controls.showMenuPanel;
  2228. this.elements.controls = null; // Larger overlaid play button
  2229. if (is$1.array(this.config.controls) && this.config.controls.includes('play-large')) {
  2230. this.elements.container.appendChild(createButton.call(this, 'play-large'));
  2231. } // Create the container
  2232. var container = createElement('div', getAttributesFromSelector(this.config.selectors.controls.wrapper));
  2233. this.elements.controls = container; // Default item attributes
  2234. var defaultAttributes = {
  2235. class: 'plyr__controls__item'
  2236. }; // Loop through controls in order
  2237. dedupe(is$1.array(this.config.controls) ? this.config.controls : []).forEach(function (control) {
  2238. // Restart button
  2239. if (control === 'restart') {
  2240. container.appendChild(createButton.call(_this10, 'restart', defaultAttributes));
  2241. } // Rewind button
  2242. if (control === 'rewind') {
  2243. container.appendChild(createButton.call(_this10, 'rewind', defaultAttributes));
  2244. } // Play/Pause button
  2245. if (control === 'play') {
  2246. container.appendChild(createButton.call(_this10, 'play', defaultAttributes));
  2247. } // Fast forward button
  2248. if (control === 'fast-forward') {
  2249. container.appendChild(createButton.call(_this10, 'fast-forward', defaultAttributes));
  2250. } // Progress
  2251. if (control === 'progress') {
  2252. var progressContainer = createElement('div', {
  2253. class: "".concat(defaultAttributes.class, " plyr__progress__container")
  2254. });
  2255. var progress = createElement('div', getAttributesFromSelector(_this10.config.selectors.progress)); // Seek range slider
  2256. progress.appendChild(createRange.call(_this10, 'seek', {
  2257. id: "plyr-seek-".concat(data.id)
  2258. })); // Buffer progress
  2259. progress.appendChild(createProgress.call(_this10, 'buffer')); // TODO: Add loop display indicator
  2260. // Seek tooltip
  2261. if (_this10.config.tooltips.seek) {
  2262. var tooltip = createElement('span', {
  2263. class: _this10.config.classNames.tooltip
  2264. }, '00:00');
  2265. progress.appendChild(tooltip);
  2266. _this10.elements.display.seekTooltip = tooltip;
  2267. }
  2268. _this10.elements.progress = progress;
  2269. progressContainer.appendChild(_this10.elements.progress);
  2270. container.appendChild(progressContainer);
  2271. } // Media current time display
  2272. if (control === 'current-time') {
  2273. container.appendChild(createTime.call(_this10, 'currentTime', defaultAttributes));
  2274. } // Media duration display
  2275. if (control === 'duration') {
  2276. container.appendChild(createTime.call(_this10, 'duration', defaultAttributes));
  2277. } // Volume controls
  2278. if (control === 'mute' || control === 'volume') {
  2279. var volume = _this10.elements.volume; // Create the volume container if needed
  2280. if (!is$1.element(volume) || !container.contains(volume)) {
  2281. volume = createElement('div', extend({}, defaultAttributes, {
  2282. class: "".concat(defaultAttributes.class, " plyr__volume").trim()
  2283. }));
  2284. _this10.elements.volume = volume;
  2285. container.appendChild(volume);
  2286. } // Toggle mute button
  2287. if (control === 'mute') {
  2288. volume.appendChild(createButton.call(_this10, 'mute'));
  2289. } // Volume range control
  2290. // Ignored on iOS as it's handled globally
  2291. // https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html
  2292. if (control === 'volume' && !browser.isIos) {
  2293. // Set the attributes
  2294. var attributes = {
  2295. max: 1,
  2296. step: 0.05,
  2297. value: _this10.config.volume
  2298. }; // Create the volume range slider
  2299. volume.appendChild(createRange.call(_this10, 'volume', extend(attributes, {
  2300. id: "plyr-volume-".concat(data.id)
  2301. })));
  2302. }
  2303. } // Toggle captions button
  2304. if (control === 'captions') {
  2305. container.appendChild(createButton.call(_this10, 'captions', defaultAttributes));
  2306. } // Settings button / menu
  2307. if (control === 'settings' && !is$1.empty(_this10.config.settings)) {
  2308. var wrapper = createElement('div', extend({}, defaultAttributes, {
  2309. class: "".concat(defaultAttributes.class, " plyr__menu").trim(),
  2310. hidden: ''
  2311. }));
  2312. wrapper.appendChild(createButton.call(_this10, 'settings', {
  2313. 'aria-haspopup': true,
  2314. 'aria-controls': "plyr-settings-".concat(data.id),
  2315. 'aria-expanded': false
  2316. }));
  2317. var popup = createElement('div', {
  2318. class: 'plyr__menu__container',
  2319. id: "plyr-settings-".concat(data.id),
  2320. hidden: ''
  2321. });
  2322. var inner = createElement('div');
  2323. var home = createElement('div', {
  2324. id: "plyr-settings-".concat(data.id, "-home")
  2325. }); // Create the menu
  2326. var menu = createElement('div', {
  2327. role: 'menu'
  2328. });
  2329. home.appendChild(menu);
  2330. inner.appendChild(home);
  2331. _this10.elements.settings.panels.home = home; // Build the menu items
  2332. _this10.config.settings.forEach(function (type) {
  2333. // TODO: bundle this with the createMenuItem helper and bindings
  2334. var menuItem = createElement('button', extend(getAttributesFromSelector(_this10.config.selectors.buttons.settings), {
  2335. type: 'button',
  2336. class: "".concat(_this10.config.classNames.control, " ").concat(_this10.config.classNames.control, "--forward"),
  2337. role: 'menuitem',
  2338. 'aria-haspopup': true,
  2339. hidden: ''
  2340. })); // Bind menu shortcuts for keyboard users
  2341. bindMenuItemShortcuts.call(_this10, menuItem, type); // Show menu on click
  2342. on.call(_this10, menuItem, 'click', function () {
  2343. showMenuPanel.call(_this10, type, false);
  2344. });
  2345. var flex = createElement('span', null, i18n.get(type, _this10.config));
  2346. var value = createElement('span', {
  2347. class: _this10.config.classNames.menu.value
  2348. }); // Speed contains HTML entities
  2349. value.innerHTML = data[type];
  2350. flex.appendChild(value);
  2351. menuItem.appendChild(flex);
  2352. menu.appendChild(menuItem); // Build the panes
  2353. var pane = createElement('div', {
  2354. id: "plyr-settings-".concat(data.id, "-").concat(type),
  2355. hidden: ''
  2356. }); // Back button
  2357. var backButton = createElement('button', {
  2358. type: 'button',
  2359. class: "".concat(_this10.config.classNames.control, " ").concat(_this10.config.classNames.control, "--back")
  2360. }); // Visible label
  2361. backButton.appendChild(createElement('span', {
  2362. 'aria-hidden': true
  2363. }, i18n.get(type, _this10.config))); // Screen reader label
  2364. backButton.appendChild(createElement('span', {
  2365. class: _this10.config.classNames.hidden
  2366. }, i18n.get('menuBack', _this10.config))); // Go back via keyboard
  2367. on.call(_this10, pane, 'keydown', function (event) {
  2368. // We only care about <-
  2369. if (event.which !== 37) {
  2370. return;
  2371. } // Prevent seek
  2372. event.preventDefault();
  2373. event.stopPropagation(); // Show the respective menu
  2374. showMenuPanel.call(_this10, 'home', true);
  2375. }, false); // Go back via button click
  2376. on.call(_this10, backButton, 'click', function () {
  2377. showMenuPanel.call(_this10, 'home', false);
  2378. }); // Add to pane
  2379. pane.appendChild(backButton); // Menu
  2380. pane.appendChild(createElement('div', {
  2381. role: 'menu'
  2382. })); // Menu Captions
  2383. pane.appendChild(createElement('div', {
  2384. role: 'menucaptions'
  2385. }));
  2386. inner.appendChild(pane);
  2387. _this10.elements.settings.buttons[type] = menuItem;
  2388. _this10.elements.settings.panels[type] = pane;
  2389. });
  2390. popup.appendChild(inner);
  2391. wrapper.appendChild(popup);
  2392. container.appendChild(wrapper);
  2393. _this10.elements.settings.popup = popup;
  2394. _this10.elements.settings.menu = wrapper;
  2395. } // Picture in picture button
  2396. if (control === 'pip' && support.pip) {
  2397. container.appendChild(createButton.call(_this10, 'pip', defaultAttributes));
  2398. } // Airplay button
  2399. if (control === 'airplay' && support.airplay) {
  2400. container.appendChild(createButton.call(_this10, 'airplay', defaultAttributes));
  2401. } // Download button
  2402. if (control === 'download') {
  2403. var _attributes = extend({}, defaultAttributes, {
  2404. element: 'a',
  2405. href: _this10.download,
  2406. target: '_blank'
  2407. }); // Set download attribute for HTML5 only
  2408. if (_this10.isHTML5) {
  2409. _attributes.download = '';
  2410. }
  2411. var download = _this10.config.urls.download;
  2412. if (!is$1.url(download) && _this10.isEmbed) {
  2413. extend(_attributes, {
  2414. icon: "logo-".concat(_this10.provider),
  2415. label: _this10.provider
  2416. });
  2417. }
  2418. container.appendChild(createButton.call(_this10, 'download', _attributes));
  2419. } // Toggle fullscreen button
  2420. if (control === 'fullscreen') {
  2421. container.appendChild(createButton.call(_this10, 'fullscreen', defaultAttributes));
  2422. }
  2423. }); // Set available quality levels
  2424. if (this.isHTML5) {
  2425. setQualityMenu.call(this, html5.getQualityOptions.call(this));
  2426. }
  2427. setSpeedMenu.call(this);
  2428. return container;
  2429. },
  2430. // Insert controls
  2431. inject: function inject() {
  2432. var _this11 = this;
  2433. // Sprite
  2434. if (this.config.loadSprite) {
  2435. var icon = controls.getIconUrl.call(this); // Only load external sprite using AJAX
  2436. if (icon.cors) {
  2437. loadSprite(icon.url, 'sprite-plyr');
  2438. }
  2439. } // Create a unique ID
  2440. this.id = Math.floor(Math.random() * 10000); // Null by default
  2441. var container = null;
  2442. this.elements.controls = null; // Set template properties
  2443. var props = {
  2444. id: this.id,
  2445. seektime: this.config.seekTime,
  2446. title: this.config.title
  2447. };
  2448. var update = true; // If function, run it and use output
  2449. if (is$1.function(this.config.controls)) {
  2450. this.config.controls = this.config.controls.call(this, props);
  2451. } // Convert falsy controls to empty array (primarily for empty strings)
  2452. if (!this.config.controls) {
  2453. this.config.controls = [];
  2454. }
  2455. if (is$1.element(this.config.controls) || is$1.string(this.config.controls)) {
  2456. // HTMLElement or Non-empty string passed as the option
  2457. container = this.config.controls;
  2458. } else {
  2459. // Create controls
  2460. container = controls.create.call(this, {
  2461. id: this.id,
  2462. seektime: this.config.seekTime,
  2463. speed: this.speed,
  2464. quality: this.quality,
  2465. captions: captions.getLabel.call(this) // TODO: Looping
  2466. // loop: 'None',
  2467. });
  2468. update = false;
  2469. } // Replace props with their value
  2470. var replace = function replace(input) {
  2471. var result = input;
  2472. Object.entries(props).forEach(function (_ref2) {
  2473. var _ref3 = _slicedToArray(_ref2, 2),
  2474. key = _ref3[0],
  2475. value = _ref3[1];
  2476. result = replaceAll(result, "{".concat(key, "}"), value);
  2477. });
  2478. return result;
  2479. }; // Update markup
  2480. if (update) {
  2481. if (is$1.string(this.config.controls)) {
  2482. container = replace(container);
  2483. }
  2484. } // Controls container
  2485. var target; // Inject to custom location
  2486. if (is$1.string(this.config.selectors.controls.container)) {
  2487. target = document.querySelector(this.config.selectors.controls.container);
  2488. } // Inject into the container by default
  2489. if (!is$1.element(target)) {
  2490. target = this.elements.container;
  2491. } // Inject controls HTML (needs to be before captions, hence "afterbegin")
  2492. var insertMethod = is$1.element(container) ? 'insertAdjacentElement' : 'insertAdjacentHTML';
  2493. target[insertMethod]('afterbegin', container); // Find the elements if need be
  2494. if (!is$1.element(this.elements.controls)) {
  2495. controls.findElements.call(this);
  2496. } // Add pressed property to buttons
  2497. if (!is$1.empty(this.elements.buttons)) {
  2498. var addProperty = function addProperty(button) {
  2499. var className = _this11.config.classNames.controlPressed;
  2500. Object.defineProperty(button, 'pressed', {
  2501. enumerable: true,
  2502. get: function get() {
  2503. return hasClass(button, className);
  2504. },
  2505. set: function set() {
  2506. var pressed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  2507. toggleClass(button, className, pressed);
  2508. }
  2509. });
  2510. }; // Toggle classname when pressed property is set
  2511. Object.values(this.elements.buttons).filter(Boolean).forEach(function (button) {
  2512. if (is$1.array(button) || is$1.nodeList(button)) {
  2513. Array.from(button).filter(Boolean).forEach(addProperty);
  2514. } else {
  2515. addProperty(button);
  2516. }
  2517. });
  2518. } // Edge sometimes doesn't finish the paint so force a repaint
  2519. if (browser.isEdge) {
  2520. repaint(target);
  2521. } // Setup tooltips
  2522. if (this.config.tooltips.controls) {
  2523. var _this$config = this.config,
  2524. classNames = _this$config.classNames,
  2525. selectors = _this$config.selectors;
  2526. var selector = "".concat(selectors.controls.wrapper, " ").concat(selectors.labels, " .").concat(classNames.hidden);
  2527. var labels = getElements.call(this, selector);
  2528. Array.from(labels).forEach(function (label) {
  2529. toggleClass(label, _this11.config.classNames.hidden, false);
  2530. toggleClass(label, _this11.config.classNames.tooltip, true);
  2531. });
  2532. }
  2533. }
  2534. };
  2535. /**
  2536. * Parse a string to a URL object
  2537. * @param {String} input - the URL to be parsed
  2538. * @param {Boolean} safe - failsafe parsing
  2539. */
  2540. function parseUrl(input) {
  2541. var safe = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  2542. var url = input;
  2543. if (safe) {
  2544. var parser = document.createElement('a');
  2545. parser.href = url;
  2546. url = parser.href;
  2547. }
  2548. try {
  2549. return new URL(url);
  2550. } catch (e) {
  2551. return null;
  2552. }
  2553. } // Convert object to URLSearchParams
  2554. function buildUrlParams(input) {
  2555. var params = new URLSearchParams();
  2556. if (is$1.object(input)) {
  2557. Object.entries(input).forEach(function (_ref) {
  2558. var _ref2 = _slicedToArray(_ref, 2),
  2559. key = _ref2[0],
  2560. value = _ref2[1];
  2561. params.set(key, value);
  2562. });
  2563. }
  2564. return params;
  2565. }
  2566. var captions = {
  2567. // Setup captions
  2568. setup: function setup() {
  2569. // Requires UI support
  2570. if (!this.supported.ui) {
  2571. return;
  2572. } // Only Vimeo and HTML5 video supported at this point
  2573. if (!this.isVideo || this.isYouTube || this.isHTML5 && !support.textTracks) {
  2574. // Clear menu and hide
  2575. if (is$1.array(this.config.controls) && this.config.controls.includes('settings') && this.config.settings.includes('captions')) {
  2576. controls.setCaptionsMenu.call(this);
  2577. }
  2578. return;
  2579. } // Inject the container
  2580. if (!is$1.element(this.elements.captions)) {
  2581. this.elements.captions = createElement('div', getAttributesFromSelector(this.config.selectors.captions));
  2582. insertAfter(this.elements.captions, this.elements.wrapper);
  2583. } // Fix IE captions if CORS is used
  2584. // Fetch captions and inject as blobs instead (data URIs not supported!)
  2585. if (browser.isIE && window.URL) {
  2586. var elements = this.media.querySelectorAll('track');
  2587. Array.from(elements).forEach(function (track) {
  2588. var src = track.getAttribute('src');
  2589. var url = parseUrl(src);
  2590. if (url !== null && url.hostname !== window.location.href.hostname && ['http:', 'https:'].includes(url.protocol)) {
  2591. fetch(src, 'blob').then(function (blob) {
  2592. track.setAttribute('src', window.URL.createObjectURL(blob));
  2593. }).catch(function () {
  2594. removeElement(track);
  2595. });
  2596. }
  2597. });
  2598. } // Get and set initial data
  2599. // The "preferred" options are not realized unless / until the wanted language has a match
  2600. // * languages: Array of user's browser languages.
  2601. // * language: The language preferred by user settings or config
  2602. // * active: The state preferred by user settings or config
  2603. // * toggled: The real captions state
  2604. var browserLanguages = navigator.languages || [navigator.language || navigator.userLanguage || 'en'];
  2605. var languages = dedupe(browserLanguages.map(function (language) {
  2606. return language.split('-')[0];
  2607. }));
  2608. var language = (this.storage.get('language') || this.config.captions.language || 'auto').toLowerCase(); // Use first browser language when language is 'auto'
  2609. if (language === 'auto') {
  2610. var _languages = _slicedToArray(languages, 1);
  2611. language = _languages[0];
  2612. }
  2613. var active = this.storage.get('captions');
  2614. if (!is$1.boolean(active)) {
  2615. active = this.config.captions.active;
  2616. }
  2617. Object.assign(this.captions, {
  2618. toggled: false,
  2619. active: active,
  2620. language: language,
  2621. languages: languages
  2622. }); // Watch changes to textTracks and update captions menu
  2623. if (this.isHTML5) {
  2624. var trackEvents = this.config.captions.update ? 'addtrack removetrack' : 'removetrack';
  2625. on.call(this, this.media.textTracks, trackEvents, captions.update.bind(this));
  2626. } // Update available languages in list next tick (the event must not be triggered before the listeners)
  2627. setTimeout(captions.update.bind(this), 0);
  2628. },
  2629. // Update available language options in settings based on tracks
  2630. update: function update() {
  2631. var _this = this;
  2632. var tracks = captions.getTracks.call(this, true); // Get the wanted language
  2633. var _this$captions = this.captions,
  2634. active = _this$captions.active,
  2635. language = _this$captions.language,
  2636. meta = _this$captions.meta,
  2637. currentTrackNode = _this$captions.currentTrackNode;
  2638. var languageExists = Boolean(tracks.find(function (track) {
  2639. return track.language === language;
  2640. })); // Handle tracks (add event listener and "pseudo"-default)
  2641. if (this.isHTML5 && this.isVideo) {
  2642. tracks.filter(function (track) {
  2643. return !meta.get(track);
  2644. }).forEach(function (track) {
  2645. _this.debug.log('Track added', track); // Attempt to store if the original dom element was "default"
  2646. meta.set(track, {
  2647. default: track.mode === 'showing'
  2648. }); // Turn off native caption rendering to avoid double captions
  2649. // Note: mode='hidden' forces a track to download. To ensure every track
  2650. // isn't downloaded at once, only 'showing' tracks should be reassigned
  2651. // eslint-disable-next-line no-param-reassign
  2652. if (track.mode === 'showing') {
  2653. // eslint-disable-next-line no-param-reassign
  2654. track.mode = 'hidden';
  2655. } // Add event listener for cue changes
  2656. on.call(_this, track, 'cuechange', function () {
  2657. return captions.updateCues.call(_this);
  2658. });
  2659. });
  2660. } // Update language first time it matches, or if the previous matching track was removed
  2661. if (languageExists && this.language !== language || !tracks.includes(currentTrackNode)) {
  2662. captions.setLanguage.call(this, language);
  2663. captions.toggle.call(this, active && languageExists);
  2664. } // Enable or disable captions based on track length
  2665. toggleClass(this.elements.container, this.config.classNames.captions.enabled, !is$1.empty(tracks)); // Update available languages in list
  2666. if (is$1.array(this.config.controls) && this.config.controls.includes('settings') && this.config.settings.includes('captions')) {
  2667. controls.setCaptionsMenu.call(this);
  2668. }
  2669. },
  2670. // Toggle captions display
  2671. // Used internally for the toggleCaptions method, with the passive option forced to false
  2672. toggle: function toggle(input) {
  2673. var _this2 = this;
  2674. var passive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  2675. // If there's no full support
  2676. if (!this.supported.ui) {
  2677. return;
  2678. }
  2679. var toggled = this.captions.toggled; // Current state
  2680. var activeClass = this.config.classNames.captions.active; // Get the next state
  2681. // If the method is called without parameter, toggle based on current value
  2682. var active = is$1.nullOrUndefined(input) ? !toggled : input; // Update state and trigger event
  2683. if (active !== toggled) {
  2684. // When passive, don't override user preferences
  2685. if (!passive) {
  2686. this.captions.active = active;
  2687. this.storage.set({
  2688. captions: active
  2689. });
  2690. } // Force language if the call isn't passive and there is no matching language to toggle to
  2691. if (!this.language && active && !passive) {
  2692. var tracks = captions.getTracks.call(this);
  2693. var track = captions.findTrack.call(this, [this.captions.language].concat(_toConsumableArray(this.captions.languages)), true); // Override user preferences to avoid switching languages if a matching track is added
  2694. this.captions.language = track.language; // Set caption, but don't store in localStorage as user preference
  2695. captions.set.call(this, tracks.indexOf(track));
  2696. return;
  2697. } // Toggle button if it's enabled
  2698. if (this.elements.buttons.captions) {
  2699. this.elements.buttons.captions.pressed = active;
  2700. } // Add class hook
  2701. toggleClass(this.elements.container, activeClass, active);
  2702. this.captions.toggled = active; // Update settings menu
  2703. controls.updateSetting.call(this, 'captions'); // Trigger event (not used internally)
  2704. triggerEvent.call(this, this.media, active ? 'captionsenabled' : 'captionsdisabled');
  2705. } // Wait for the call stack to clear before setting mode='hidden'
  2706. // on the active track - forcing the browser to download it
  2707. setTimeout(function () {
  2708. if (active && _this2.captions.toggled) {
  2709. _this2.captions.currentTrackNode.mode = 'hidden';
  2710. }
  2711. });
  2712. },
  2713. // Set captions by track index
  2714. // Used internally for the currentTrack setter with the passive option forced to false
  2715. set: function set(index) {
  2716. var passive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  2717. var tracks = captions.getTracks.call(this); // Disable captions if setting to -1
  2718. if (index === -1) {
  2719. captions.toggle.call(this, false, passive);
  2720. return;
  2721. }
  2722. if (!is$1.number(index)) {
  2723. this.debug.warn('Invalid caption argument', index);
  2724. return;
  2725. }
  2726. if (!(index in tracks)) {
  2727. this.debug.warn('Track not found', index);
  2728. return;
  2729. }
  2730. if (this.captions.currentTrack !== index) {
  2731. this.captions.currentTrack = index;
  2732. var track = tracks[index];
  2733. var _ref = track || {},
  2734. language = _ref.language; // Store reference to node for invalidation on remove
  2735. this.captions.currentTrackNode = track; // Update settings menu
  2736. controls.updateSetting.call(this, 'captions'); // When passive, don't override user preferences
  2737. if (!passive) {
  2738. this.captions.language = language;
  2739. this.storage.set({
  2740. language: language
  2741. });
  2742. } // Handle Vimeo captions
  2743. if (this.isVimeo) {
  2744. this.embed.enableTextTrack(language);
  2745. } // Trigger event
  2746. triggerEvent.call(this, this.media, 'languagechange');
  2747. } // Show captions
  2748. captions.toggle.call(this, true, passive);
  2749. if (this.isHTML5 && this.isVideo) {
  2750. // If we change the active track while a cue is already displayed we need to update it
  2751. captions.updateCues.call(this);
  2752. }
  2753. },
  2754. // Set captions by language
  2755. // Used internally for the language setter with the passive option forced to false
  2756. setLanguage: function setLanguage(input) {
  2757. var passive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  2758. if (!is$1.string(input)) {
  2759. this.debug.warn('Invalid language argument', input);
  2760. return;
  2761. } // Normalize
  2762. var language = input.toLowerCase();
  2763. this.captions.language = language; // Set currentTrack
  2764. var tracks = captions.getTracks.call(this);
  2765. var track = captions.findTrack.call(this, [language]);
  2766. captions.set.call(this, tracks.indexOf(track), passive);
  2767. },
  2768. // Get current valid caption tracks
  2769. // If update is false it will also ignore tracks without metadata
  2770. // This is used to "freeze" the language options when captions.update is false
  2771. getTracks: function getTracks() {
  2772. var _this3 = this;
  2773. var update = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  2774. // Handle media or textTracks missing or null
  2775. var tracks = Array.from((this.media || {}).textTracks || []); // For HTML5, use cache instead of current tracks when it exists (if captions.update is false)
  2776. // Filter out removed tracks and tracks that aren't captions/subtitles (for example metadata)
  2777. return tracks.filter(function (track) {
  2778. return !_this3.isHTML5 || update || _this3.captions.meta.has(track);
  2779. }).filter(function (track) {
  2780. return ['captions', 'subtitles'].includes(track.kind);
  2781. });
  2782. },
  2783. // Match tracks based on languages and get the first
  2784. findTrack: function findTrack(languages) {
  2785. var _this4 = this;
  2786. var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  2787. var tracks = captions.getTracks.call(this);
  2788. var sortIsDefault = function sortIsDefault(track) {
  2789. return Number((_this4.captions.meta.get(track) || {}).default);
  2790. };
  2791. var sorted = Array.from(tracks).sort(function (a, b) {
  2792. return sortIsDefault(b) - sortIsDefault(a);
  2793. });
  2794. var track;
  2795. languages.every(function (language) {
  2796. track = sorted.find(function (t) {
  2797. return t.language === language;
  2798. });
  2799. return !track; // Break iteration if there is a match
  2800. }); // If no match is found but is required, get first
  2801. return track || (force ? sorted[0] : undefined);
  2802. },
  2803. // Get the current track
  2804. getCurrentTrack: function getCurrentTrack() {
  2805. return captions.getTracks.call(this)[this.currentTrack];
  2806. },
  2807. // Get UI label for track
  2808. getLabel: function getLabel(track) {
  2809. var currentTrack = track;
  2810. if (!is$1.track(currentTrack) && support.textTracks && this.captions.toggled) {
  2811. currentTrack = captions.getCurrentTrack.call(this);
  2812. }
  2813. if (is$1.track(currentTrack)) {
  2814. if (!is$1.empty(currentTrack.label)) {
  2815. return currentTrack.label;
  2816. }
  2817. if (!is$1.empty(currentTrack.language)) {
  2818. return track.language.toUpperCase();
  2819. }
  2820. return i18n.get('enabled', this.config);
  2821. }
  2822. return i18n.get('disabled', this.config);
  2823. },
  2824. // Update captions using current track's active cues
  2825. // Also optional array argument in case there isn't any track (ex: vimeo)
  2826. updateCues: function updateCues(input) {
  2827. // Requires UI
  2828. if (!this.supported.ui) {
  2829. return;
  2830. }
  2831. if (!is$1.element(this.elements.captions)) {
  2832. this.debug.warn('No captions element to render to');
  2833. return;
  2834. } // Only accept array or empty input
  2835. if (!is$1.nullOrUndefined(input) && !Array.isArray(input)) {
  2836. this.debug.warn('updateCues: Invalid input', input);
  2837. return;
  2838. }
  2839. var cues = input; // Get cues from track
  2840. if (!cues) {
  2841. var track = captions.getCurrentTrack.call(this);
  2842. cues = Array.from((track || {}).activeCues || []).map(function (cue) {
  2843. return cue.getCueAsHTML();
  2844. }).map(getHTML);
  2845. } // Set new caption text
  2846. var content = cues.map(function (cueText) {
  2847. return cueText.trim();
  2848. }).join('\n');
  2849. var changed = content !== this.elements.captions.innerHTML;
  2850. if (changed) {
  2851. // Empty the container and create a new child element
  2852. emptyElement(this.elements.captions);
  2853. var caption = createElement('span', getAttributesFromSelector(this.config.selectors.caption));
  2854. caption.innerHTML = content;
  2855. this.elements.captions.appendChild(caption); // Trigger event
  2856. triggerEvent.call(this, this.media, 'cuechange');
  2857. }
  2858. }
  2859. };
  2860. // ==========================================================================
  2861. // Plyr default config
  2862. // ==========================================================================
  2863. var defaults$1 = {
  2864. // Disable
  2865. enabled: true,
  2866. // Custom media title
  2867. title: '',
  2868. // Logging to console
  2869. debug: false,
  2870. // Auto play (if supported)
  2871. autoplay: false,
  2872. // Only allow one media playing at once (vimeo only)
  2873. autopause: true,
  2874. // Allow inline playback on iOS (this effects YouTube/Vimeo - HTML5 requires the attribute present)
  2875. // TODO: Remove iosNative fullscreen option in favour of this (logic needs work)
  2876. playsinline: true,
  2877. // Default time to skip when rewind/fast forward
  2878. seekTime: 10,
  2879. // Default volume
  2880. volume: 1,
  2881. muted: false,
  2882. // Pass a custom duration
  2883. duration: null,
  2884. // Display the media duration on load in the current time position
  2885. // If you have opted to display both duration and currentTime, this is ignored
  2886. displayDuration: true,
  2887. // Invert the current time to be a countdown
  2888. invertTime: true,
  2889. // Clicking the currentTime inverts it's value to show time left rather than elapsed
  2890. toggleInvert: true,
  2891. // Force an aspect ratio
  2892. // The format must be `'w:h'` (e.g. `'16:9'`)
  2893. ratio: null,
  2894. // Click video container to play/pause
  2895. clickToPlay: true,
  2896. // Auto hide the controls
  2897. hideControls: true,
  2898. // Reset to start when playback ended
  2899. resetOnEnd: false,
  2900. // Disable the standard context menu
  2901. disableContextMenu: true,
  2902. // Sprite (for icons)
  2903. loadSprite: true,
  2904. iconPrefix: 'plyr',
  2905. iconUrl: '/theme/modules/plyr/plyr.svg',
  2906. // Blank video (used to prevent errors on source change)
  2907. blankVideo: '/theme/modules/plyr/blank.webm',
  2908. // Quality default
  2909. quality: {
  2910. default: 576,
  2911. // The options to display in the UI, if available for the source media
  2912. options: [4320, 2880, 2160, 1440, 1080, 720, 576, 480, 360, 240],
  2913. forced: false,
  2914. onChange: null
  2915. },
  2916. // Set loops
  2917. loop: {
  2918. active: false // start: null,
  2919. // end: null,
  2920. },
  2921. // Speed default and options to display
  2922. speed: {
  2923. selected: 1,
  2924. // The options to display in the UI, if available for the source media (e.g. Vimeo and YouTube only support 0.5x-4x)
  2925. options: [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 4]
  2926. },
  2927. // Keyboard shortcut settings
  2928. keyboard: {
  2929. focused: true,
  2930. global: false
  2931. },
  2932. // Display tooltips
  2933. tooltips: {
  2934. controls: false,
  2935. seek: true
  2936. },
  2937. // Captions settings
  2938. captions: {
  2939. active: false,
  2940. language: 'auto',
  2941. // Listen to new tracks added after Plyr is initialized.
  2942. // This is needed for streaming captions, but may result in unselectable options
  2943. update: false
  2944. },
  2945. // Fullscreen settings
  2946. fullscreen: {
  2947. enabled: true,
  2948. // Allow fullscreen?
  2949. fallback: true,
  2950. // Fallback using full viewport/window
  2951. iosNative: false // Use the native fullscreen in iOS (disables custom controls)
  2952. // Selector for the fullscreen container so contextual / non-player content can remain visible in fullscreen mode
  2953. // Non-ancestors of the player element will be ignored
  2954. // container: null, // defaults to the player element
  2955. },
  2956. // Local storage
  2957. storage: {
  2958. enabled: true,
  2959. key: 'plyr'
  2960. },
  2961. // Default controls
  2962. controls: ['play-large', // 'restart',
  2963. // 'rewind',
  2964. 'play', // 'fast-forward',
  2965. 'progress', 'current-time', // 'duration',
  2966. 'mute', 'volume', 'captions', 'settings', 'pip', 'airplay', // 'download',
  2967. 'fullscreen'],
  2968. settings: ['captions', 'quality', 'speed'],
  2969. // Localisation
  2970. i18n: {
  2971. restart: 'Restart',
  2972. rewind: 'Rewind {seektime}s',
  2973. play: 'Play',
  2974. pause: 'Pause',
  2975. fastForward: 'Forward {seektime}s',
  2976. seek: 'Seek',
  2977. seekLabel: '{currentTime} of {duration}',
  2978. played: 'Played',
  2979. buffered: 'Buffered',
  2980. currentTime: 'Current time',
  2981. duration: 'Duration',
  2982. volume: 'Volume',
  2983. mute: 'Mute',
  2984. unmute: 'Unmute',
  2985. enableCaptions: 'Enable captions',
  2986. disableCaptions: 'Disable captions',
  2987. download: 'Download',
  2988. enterFullscreen: 'Enter fullscreen',
  2989. exitFullscreen: 'Exit fullscreen',
  2990. frameTitle: 'Player for {title}',
  2991. captions: 'Captions',
  2992. settings: 'Settings',
  2993. pip: 'PIP',
  2994. menuBack: 'Go back to previous menu',
  2995. speed: 'Speed',
  2996. normal: 'Normal',
  2997. quality: 'Quality',
  2998. loop: 'Loop',
  2999. start: 'Start',
  3000. end: 'End',
  3001. all: 'All',
  3002. reset: 'Reset',
  3003. disabled: 'Disabled',
  3004. enabled: 'Enabled',
  3005. advertisement: 'Ad',
  3006. qualityBadge: {
  3007. 2160: '4K',
  3008. 1440: 'HD',
  3009. 1080: 'HD',
  3010. 720: 'HD',
  3011. 576: 'SD',
  3012. 480: 'SD'
  3013. }
  3014. },
  3015. // URLs
  3016. urls: {
  3017. download: null,
  3018. vimeo: {
  3019. sdk: 'https://player.vimeo.com/api/player.js',
  3020. iframe: 'https://player.vimeo.com/video/{0}?{1}',
  3021. api: 'https://vimeo.com/api/v2/video/{0}.json'
  3022. },
  3023. youtube: {
  3024. sdk: 'https://www.youtube.com/iframe_api',
  3025. api: 'https://noembed.com/embed?url=https://www.youtube.com/watch?v={0}'
  3026. },
  3027. googleIMA: {
  3028. sdk: 'https://imasdk.googleapis.com/js/sdkloader/ima3.js'
  3029. }
  3030. },
  3031. // Custom control listeners
  3032. listeners: {
  3033. seek: null,
  3034. play: null,
  3035. pause: null,
  3036. restart: null,
  3037. rewind: null,
  3038. fastForward: null,
  3039. mute: null,
  3040. volume: null,
  3041. captions: null,
  3042. download: null,
  3043. fullscreen: null,
  3044. pip: null,
  3045. airplay: null,
  3046. speed: null,
  3047. quality: null,
  3048. loop: null,
  3049. language: null
  3050. },
  3051. // Events to watch and bubble
  3052. events: [// Events to watch on HTML5 media elements and bubble
  3053. // https://developer.mozilla.org/en/docs/Web/Guide/Events/Media_events
  3054. 'ended', 'progress', 'stalled', 'playing', 'waiting', 'canplay', 'canplaythrough', 'loadstart', 'loadeddata', 'loadedmetadata', 'timeupdate', 'volumechange', 'play', 'pause', 'error', 'seeking', 'seeked', 'emptied', 'ratechange', 'cuechange', // Custom events
  3055. 'download', 'enterfullscreen', 'exitfullscreen', 'captionsenabled', 'captionsdisabled', 'languagechange', 'controlshidden', 'controlsshown', 'ready', // YouTube
  3056. 'statechange', // Quality
  3057. 'qualitychange', // Ads
  3058. 'adsloaded', 'adscontentpause', 'adscontentresume', 'adstarted', 'adsmidpoint', 'adscomplete', 'adsallcomplete', 'adsimpression', 'adsclick'],
  3059. // Selectors
  3060. // Change these to match your template if using custom HTML
  3061. selectors: {
  3062. editable: 'input, textarea, select, [contenteditable]',
  3063. container: '.plyr',
  3064. controls: {
  3065. container: null,
  3066. wrapper: '.plyr__controls'
  3067. },
  3068. labels: '[data-plyr]',
  3069. buttons: {
  3070. play: '[data-plyr="play"]',
  3071. pause: '[data-plyr="pause"]',
  3072. restart: '[data-plyr="restart"]',
  3073. rewind: '[data-plyr="rewind"]',
  3074. fastForward: '[data-plyr="fast-forward"]',
  3075. mute: '[data-plyr="mute"]',
  3076. captions: '[data-plyr="captions"]',
  3077. download: '[data-plyr="download"]',
  3078. fullscreen: '[data-plyr="fullscreen"]',
  3079. pip: '[data-plyr="pip"]',
  3080. airplay: '[data-plyr="airplay"]',
  3081. settings: '[data-plyr="settings"]',
  3082. loop: '[data-plyr="loop"]'
  3083. },
  3084. inputs: {
  3085. seek: '[data-plyr="seek"]',
  3086. volume: '[data-plyr="volume"]',
  3087. speed: '[data-plyr="speed"]',
  3088. language: '[data-plyr="language"]',
  3089. quality: '[data-plyr="quality"]'
  3090. },
  3091. display: {
  3092. currentTime: '.plyr__time--current',
  3093. duration: '.plyr__time--duration',
  3094. buffer: '.plyr__progress__buffer',
  3095. loop: '.plyr__progress__loop',
  3096. // Used later
  3097. volume: '.plyr__volume--display'
  3098. },
  3099. progress: '.plyr__progress',
  3100. captions: '.plyr__captions',
  3101. caption: '.plyr__caption'
  3102. },
  3103. // Class hooks added to the player in different states
  3104. classNames: {
  3105. type: 'plyr--{0}',
  3106. provider: 'plyr--{0}',
  3107. video: 'plyr__video-wrapper',
  3108. embed: 'plyr__video-embed',
  3109. videoFixedRatio: 'plyr__video-wrapper--fixed-ratio',
  3110. embedContainer: 'plyr__video-embed__container',
  3111. poster: 'plyr__poster',
  3112. posterEnabled: 'plyr__poster-enabled',
  3113. ads: 'plyr__ads',
  3114. control: 'plyr__control',
  3115. controlPressed: 'plyr__control--pressed',
  3116. playing: 'plyr--playing',
  3117. paused: 'plyr--paused',
  3118. stopped: 'plyr--stopped',
  3119. loading: 'plyr--loading',
  3120. hover: 'plyr--hover',
  3121. tooltip: 'plyr__tooltip',
  3122. cues: 'plyr__cues',
  3123. hidden: 'plyr__sr-only',
  3124. hideControls: 'plyr--hide-controls',
  3125. isIos: 'plyr--is-ios',
  3126. isTouch: 'plyr--is-touch',
  3127. uiSupported: 'plyr--full-ui',
  3128. noTransition: 'plyr--no-transition',
  3129. display: {
  3130. time: 'plyr__time'
  3131. },
  3132. menu: {
  3133. value: 'plyr__menu__value',
  3134. badge: 'plyr__badge',
  3135. open: 'plyr--menu-open'
  3136. },
  3137. captions: {
  3138. enabled: 'plyr--captions-enabled',
  3139. active: 'plyr--captions-active'
  3140. },
  3141. fullscreen: {
  3142. enabled: 'plyr--fullscreen-enabled',
  3143. fallback: 'plyr--fullscreen-fallback'
  3144. },
  3145. pip: {
  3146. supported: 'plyr--pip-supported',
  3147. active: 'plyr--pip-active'
  3148. },
  3149. airplay: {
  3150. supported: 'plyr--airplay-supported',
  3151. active: 'plyr--airplay-active'
  3152. },
  3153. tabFocus: 'plyr__tab-focus',
  3154. previewThumbnails: {
  3155. // Tooltip thumbs
  3156. thumbContainer: 'plyr__preview-thumb',
  3157. thumbContainerShown: 'plyr__preview-thumb--is-shown',
  3158. imageContainer: 'plyr__preview-thumb__image-container',
  3159. timeContainer: 'plyr__preview-thumb__time-container',
  3160. // Scrubbing
  3161. scrubbingContainer: 'plyr__preview-scrubbing',
  3162. scrubbingContainerShown: 'plyr__preview-scrubbing--is-shown'
  3163. }
  3164. },
  3165. // Embed attributes
  3166. attributes: {
  3167. embed: {
  3168. provider: 'data-plyr-provider',
  3169. id: 'data-plyr-embed-id'
  3170. }
  3171. },
  3172. // Advertisements plugin
  3173. // Register for an account here: http://vi.ai/publisher-video-monetization/?aid=plyrio
  3174. ads: {
  3175. enabled: false,
  3176. publisherId: '',
  3177. tagUrl: ''
  3178. },
  3179. // Preview Thumbnails plugin
  3180. previewThumbnails: {
  3181. enabled: false,
  3182. src: ''
  3183. },
  3184. // Vimeo plugin
  3185. vimeo: {
  3186. byline: false,
  3187. portrait: false,
  3188. title: false,
  3189. speed: true,
  3190. transparent: false,
  3191. // Whether the owner of the video has a Pro or Business account
  3192. // (which allows us to properly hide controls without CSS hacks, etc)
  3193. premium: false,
  3194. // Custom settings from Plyr
  3195. referrerPolicy: null // https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/referrerPolicy
  3196. },
  3197. // YouTube plugin
  3198. youtube: {
  3199. noCookie: true,
  3200. // Whether to use an alternative version of YouTube without cookies
  3201. rel: 0,
  3202. // No related vids
  3203. showinfo: 0,
  3204. // Hide info
  3205. iv_load_policy: 3,
  3206. // Hide annotations
  3207. modestbranding: 1 // Hide logos as much as possible (they still show one in the corner when paused)
  3208. }
  3209. };
  3210. // ==========================================================================
  3211. // Plyr states
  3212. // ==========================================================================
  3213. var pip = {
  3214. active: 'picture-in-picture',
  3215. inactive: 'inline'
  3216. };
  3217. // ==========================================================================
  3218. // Plyr supported types and providers
  3219. // ==========================================================================
  3220. var providers = {
  3221. html5: 'html5',
  3222. youtube: 'youtube',
  3223. vimeo: 'vimeo'
  3224. };
  3225. var types = {
  3226. audio: 'audio',
  3227. video: 'video'
  3228. };
  3229. /**
  3230. * Get provider by URL
  3231. * @param {String} url
  3232. */
  3233. function getProviderByUrl(url) {
  3234. // YouTube
  3235. if (/^(https?:\/\/)?(www\.)?(youtube\.com|youtube-nocookie\.com|youtu\.?be)\/.+$/.test(url)) {
  3236. return providers.youtube;
  3237. } // Vimeo
  3238. if (/^https?:\/\/player.vimeo.com\/video\/\d{0,9}(?=\b|\/)/.test(url)) {
  3239. return providers.vimeo;
  3240. }
  3241. return null;
  3242. }
  3243. // ==========================================================================
  3244. // Console wrapper
  3245. // ==========================================================================
  3246. var noop = function noop() {};
  3247. var Console = /*#__PURE__*/function () {
  3248. function Console() {
  3249. var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  3250. _classCallCheck(this, Console);
  3251. this.enabled = window.console && enabled;
  3252. if (this.enabled) {
  3253. this.log('Debugging enabled');
  3254. }
  3255. }
  3256. _createClass(Console, [{
  3257. key: "log",
  3258. get: function get() {
  3259. // eslint-disable-next-line no-console
  3260. return this.enabled ? Function.prototype.bind.call(console.log, console) : noop;
  3261. }
  3262. }, {
  3263. key: "warn",
  3264. get: function get() {
  3265. // eslint-disable-next-line no-console
  3266. return this.enabled ? Function.prototype.bind.call(console.warn, console) : noop;
  3267. }
  3268. }, {
  3269. key: "error",
  3270. get: function get() {
  3271. // eslint-disable-next-line no-console
  3272. return this.enabled ? Function.prototype.bind.call(console.error, console) : noop;
  3273. }
  3274. }]);
  3275. return Console;
  3276. }();
  3277. var Fullscreen = /*#__PURE__*/function () {
  3278. function Fullscreen(player) {
  3279. var _this = this;
  3280. _classCallCheck(this, Fullscreen);
  3281. // Keep reference to parent
  3282. this.player = player; // Get prefix
  3283. this.prefix = Fullscreen.prefix;
  3284. this.property = Fullscreen.property; // Scroll position
  3285. this.scrollPosition = {
  3286. x: 0,
  3287. y: 0
  3288. }; // Force the use of 'full window/browser' rather than fullscreen
  3289. this.forceFallback = player.config.fullscreen.fallback === 'force'; // Get the fullscreen element
  3290. // Checks container is an ancestor, defaults to null
  3291. this.player.elements.fullscreen = player.config.fullscreen.container && closest(this.player.elements.container, player.config.fullscreen.container); // Register event listeners
  3292. // Handle event (incase user presses escape etc)
  3293. on.call(this.player, document, this.prefix === 'ms' ? 'MSFullscreenChange' : "".concat(this.prefix, "fullscreenchange"), function () {
  3294. // TODO: Filter for target??
  3295. _this.onChange();
  3296. }); // Fullscreen toggle on double click
  3297. on.call(this.player, this.player.elements.container, 'dblclick', function (event) {
  3298. // Ignore double click in controls
  3299. if (is$1.element(_this.player.elements.controls) && _this.player.elements.controls.contains(event.target)) {
  3300. return;
  3301. }
  3302. _this.toggle();
  3303. }); // Tap focus when in fullscreen
  3304. on.call(this, this.player.elements.container, 'keydown', function (event) {
  3305. return _this.trapFocus(event);
  3306. }); // Update the UI
  3307. this.update();
  3308. } // Determine if native supported
  3309. _createClass(Fullscreen, [{
  3310. key: "onChange",
  3311. value: function onChange() {
  3312. if (!this.enabled) {
  3313. return;
  3314. } // Update toggle button
  3315. var button = this.player.elements.buttons.fullscreen;
  3316. if (is$1.element(button)) {
  3317. button.pressed = this.active;
  3318. } // Trigger an event
  3319. triggerEvent.call(this.player, this.target, this.active ? 'enterfullscreen' : 'exitfullscreen', true);
  3320. }
  3321. }, {
  3322. key: "toggleFallback",
  3323. value: function toggleFallback() {
  3324. var toggle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  3325. // Store or restore scroll position
  3326. if (toggle) {
  3327. this.scrollPosition = {
  3328. x: window.scrollX || 0,
  3329. y: window.scrollY || 0
  3330. };
  3331. } else {
  3332. window.scrollTo(this.scrollPosition.x, this.scrollPosition.y);
  3333. } // Toggle scroll
  3334. document.body.style.overflow = toggle ? 'hidden' : ''; // Toggle class hook
  3335. toggleClass(this.target, this.player.config.classNames.fullscreen.fallback, toggle); // Force full viewport on iPhone X+
  3336. if (browser.isIos) {
  3337. var viewport = document.head.querySelector('meta[name="viewport"]');
  3338. var property = 'viewport-fit=cover'; // Inject the viewport meta if required
  3339. if (!viewport) {
  3340. viewport = document.createElement('meta');
  3341. viewport.setAttribute('name', 'viewport');
  3342. } // Check if the property already exists
  3343. var hasProperty = is$1.string(viewport.content) && viewport.content.includes(property);
  3344. if (toggle) {
  3345. this.cleanupViewport = !hasProperty;
  3346. if (!hasProperty) {
  3347. viewport.content += ",".concat(property);
  3348. }
  3349. } else if (this.cleanupViewport) {
  3350. viewport.content = viewport.content.split(',').filter(function (part) {
  3351. return part.trim() !== property;
  3352. }).join(',');
  3353. }
  3354. } // Toggle button and fire events
  3355. this.onChange();
  3356. } // Trap focus inside container
  3357. }, {
  3358. key: "trapFocus",
  3359. value: function trapFocus(event) {
  3360. // Bail if iOS, not active, not the tab key
  3361. if (browser.isIos || !this.active || event.key !== 'Tab' || event.keyCode !== 9) {
  3362. return;
  3363. } // Get the current focused element
  3364. var focused = document.activeElement;
  3365. var focusable = getElements.call(this.player, 'a[href], button:not(:disabled), input:not(:disabled), [tabindex]');
  3366. var _focusable = _slicedToArray(focusable, 1),
  3367. first = _focusable[0];
  3368. var last = focusable[focusable.length - 1];
  3369. if (focused === last && !event.shiftKey) {
  3370. // Move focus to first element that can be tabbed if Shift isn't used
  3371. first.focus();
  3372. event.preventDefault();
  3373. } else if (focused === first && event.shiftKey) {
  3374. // Move focus to last element that can be tabbed if Shift is used
  3375. last.focus();
  3376. event.preventDefault();
  3377. }
  3378. } // Update UI
  3379. }, {
  3380. key: "update",
  3381. value: function update() {
  3382. if (this.enabled) {
  3383. var mode;
  3384. if (this.forceFallback) {
  3385. mode = 'Fallback (forced)';
  3386. } else if (Fullscreen.native) {
  3387. mode = 'Native';
  3388. } else {
  3389. mode = 'Fallback';
  3390. }
  3391. this.player.debug.log("".concat(mode, " fullscreen enabled"));
  3392. } else {
  3393. this.player.debug.log('Fullscreen not supported and fallback disabled');
  3394. } // Add styling hook to show button
  3395. toggleClass(this.player.elements.container, this.player.config.classNames.fullscreen.enabled, this.enabled);
  3396. } // Make an element fullscreen
  3397. }, {
  3398. key: "enter",
  3399. value: function enter() {
  3400. if (!this.enabled) {
  3401. return;
  3402. } // iOS native fullscreen doesn't need the request step
  3403. if (browser.isIos && this.player.config.fullscreen.iosNative) {
  3404. this.target.webkitEnterFullscreen();
  3405. } else if (!Fullscreen.native || this.forceFallback) {
  3406. this.toggleFallback(true);
  3407. } else if (!this.prefix) {
  3408. this.target.requestFullscreen({
  3409. navigationUI: 'hide'
  3410. });
  3411. } else if (!is$1.empty(this.prefix)) {
  3412. this.target["".concat(this.prefix, "Request").concat(this.property)]();
  3413. }
  3414. } // Bail from fullscreen
  3415. }, {
  3416. key: "exit",
  3417. value: function exit() {
  3418. if (!this.enabled) {
  3419. return;
  3420. } // iOS native fullscreen
  3421. if (browser.isIos && this.player.config.fullscreen.iosNative) {
  3422. this.target.webkitExitFullscreen();
  3423. silencePromise(this.player.play());
  3424. } else if (!Fullscreen.native || this.forceFallback) {
  3425. this.toggleFallback(false);
  3426. } else if (!this.prefix) {
  3427. (document.cancelFullScreen || document.exitFullscreen).call(document);
  3428. } else if (!is$1.empty(this.prefix)) {
  3429. var action = this.prefix === 'moz' ? 'Cancel' : 'Exit';
  3430. document["".concat(this.prefix).concat(action).concat(this.property)]();
  3431. }
  3432. } // Toggle state
  3433. }, {
  3434. key: "toggle",
  3435. value: function toggle() {
  3436. if (!this.active) {
  3437. this.enter();
  3438. } else {
  3439. this.exit();
  3440. }
  3441. }
  3442. }, {
  3443. key: "usingNative",
  3444. // If we're actually using native
  3445. get: function get() {
  3446. return Fullscreen.native && !this.forceFallback;
  3447. } // Get the prefix for handlers
  3448. }, {
  3449. key: "enabled",
  3450. // Determine if fullscreen is enabled
  3451. get: function get() {
  3452. return (Fullscreen.native || this.player.config.fullscreen.fallback) && this.player.config.fullscreen.enabled && this.player.supported.ui && this.player.isVideo;
  3453. } // Get active state
  3454. }, {
  3455. key: "active",
  3456. get: function get() {
  3457. if (!this.enabled) {
  3458. return false;
  3459. } // Fallback using classname
  3460. if (!Fullscreen.native || this.forceFallback) {
  3461. return hasClass(this.target, this.player.config.classNames.fullscreen.fallback);
  3462. }
  3463. var element = !this.prefix ? document.fullscreenElement : document["".concat(this.prefix).concat(this.property, "Element")];
  3464. return element && element.shadowRoot ? element === this.target.getRootNode().host : element === this.target;
  3465. } // Get target element
  3466. }, {
  3467. key: "target",
  3468. get: function get() {
  3469. return browser.isIos && this.player.config.fullscreen.iosNative ? this.player.media : this.player.elements.fullscreen || this.player.elements.container;
  3470. }
  3471. }], [{
  3472. key: "native",
  3473. get: function get() {
  3474. return !!(document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled);
  3475. }
  3476. }, {
  3477. key: "prefix",
  3478. get: function get() {
  3479. // No prefix
  3480. if (is$1.function(document.exitFullscreen)) {
  3481. return '';
  3482. } // Check for fullscreen support by vendor prefix
  3483. var value = '';
  3484. var prefixes = ['webkit', 'moz', 'ms'];
  3485. prefixes.some(function (pre) {
  3486. if (is$1.function(document["".concat(pre, "ExitFullscreen")]) || is$1.function(document["".concat(pre, "CancelFullScreen")])) {
  3487. value = pre;
  3488. return true;
  3489. }
  3490. return false;
  3491. });
  3492. return value;
  3493. }
  3494. }, {
  3495. key: "property",
  3496. get: function get() {
  3497. return this.prefix === 'moz' ? 'FullScreen' : 'Fullscreen';
  3498. }
  3499. }]);
  3500. return Fullscreen;
  3501. }();
  3502. // ==========================================================================
  3503. // Load image avoiding xhr/fetch CORS issues
  3504. // Server status can't be obtained this way unfortunately, so this uses "naturalWidth" to determine if the image has loaded
  3505. // By default it checks if it is at least 1px, but you can add a second argument to change this
  3506. // ==========================================================================
  3507. function loadImage(src) {
  3508. var minWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  3509. return new Promise(function (resolve, reject) {
  3510. var image = new Image();
  3511. var handler = function handler() {
  3512. delete image.onload;
  3513. delete image.onerror;
  3514. (image.naturalWidth >= minWidth ? resolve : reject)(image);
  3515. };
  3516. Object.assign(image, {
  3517. onload: handler,
  3518. onerror: handler,
  3519. src: src
  3520. });
  3521. });
  3522. }
  3523. var ui = {
  3524. addStyleHook: function addStyleHook() {
  3525. toggleClass(this.elements.container, this.config.selectors.container.replace('.', ''), true);
  3526. toggleClass(this.elements.container, this.config.classNames.uiSupported, this.supported.ui);
  3527. },
  3528. // Toggle native HTML5 media controls
  3529. toggleNativeControls: function toggleNativeControls() {
  3530. var toggle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  3531. if (toggle && this.isHTML5) {
  3532. this.media.setAttribute('controls', '');
  3533. } else {
  3534. this.media.removeAttribute('controls');
  3535. }
  3536. },
  3537. // Setup the UI
  3538. build: function build() {
  3539. var _this = this;
  3540. // Re-attach media element listeners
  3541. // TODO: Use event bubbling?
  3542. this.listeners.media(); // Don't setup interface if no support
  3543. if (!this.supported.ui) {
  3544. this.debug.warn("Basic support only for ".concat(this.provider, " ").concat(this.type)); // Restore native controls
  3545. ui.toggleNativeControls.call(this, true); // Bail
  3546. return;
  3547. } // Inject custom controls if not present
  3548. if (!is$1.element(this.elements.controls)) {
  3549. // Inject custom controls
  3550. controls.inject.call(this); // Re-attach control listeners
  3551. this.listeners.controls();
  3552. } // Remove native controls
  3553. ui.toggleNativeControls.call(this); // Setup captions for HTML5
  3554. if (this.isHTML5) {
  3555. captions.setup.call(this);
  3556. } // Reset volume
  3557. this.volume = null; // Reset mute state
  3558. this.muted = null; // Reset loop state
  3559. this.loop = null; // Reset quality setting
  3560. this.quality = null; // Reset speed
  3561. this.speed = null; // Reset volume display
  3562. controls.updateVolume.call(this); // Reset time display
  3563. controls.timeUpdate.call(this); // Update the UI
  3564. ui.checkPlaying.call(this); // Check for picture-in-picture support
  3565. toggleClass(this.elements.container, this.config.classNames.pip.supported, support.pip && this.isHTML5 && this.isVideo); // Check for airplay support
  3566. toggleClass(this.elements.container, this.config.classNames.airplay.supported, support.airplay && this.isHTML5); // Add iOS class
  3567. toggleClass(this.elements.container, this.config.classNames.isIos, browser.isIos); // Add touch class
  3568. toggleClass(this.elements.container, this.config.classNames.isTouch, this.touch); // Ready for API calls
  3569. this.ready = true; // Ready event at end of execution stack
  3570. setTimeout(function () {
  3571. triggerEvent.call(_this, _this.media, 'ready');
  3572. }, 0); // Set the title
  3573. ui.setTitle.call(this); // Assure the poster image is set, if the property was added before the element was created
  3574. if (this.poster) {
  3575. ui.setPoster.call(this, this.poster, false).catch(function () {});
  3576. } // Manually set the duration if user has overridden it.
  3577. // The event listeners for it doesn't get called if preload is disabled (#701)
  3578. if (this.config.duration) {
  3579. controls.durationUpdate.call(this);
  3580. }
  3581. },
  3582. // Setup aria attribute for play and iframe title
  3583. setTitle: function setTitle() {
  3584. // Find the current text
  3585. var label = i18n.get('play', this.config); // If there's a media title set, use that for the label
  3586. if (is$1.string(this.config.title) && !is$1.empty(this.config.title)) {
  3587. label += ", ".concat(this.config.title);
  3588. } // If there's a play button, set label
  3589. Array.from(this.elements.buttons.play || []).forEach(function (button) {
  3590. button.setAttribute('aria-label', label);
  3591. }); // Set iframe title
  3592. // https://github.com/sampotts/plyr/issues/124
  3593. if (this.isEmbed) {
  3594. var iframe = getElement.call(this, 'iframe');
  3595. if (!is$1.element(iframe)) {
  3596. return;
  3597. } // Default to media type
  3598. var title = !is$1.empty(this.config.title) ? this.config.title : 'video';
  3599. var format = i18n.get('frameTitle', this.config);
  3600. iframe.setAttribute('title', format.replace('{title}', title));
  3601. }
  3602. },
  3603. // Toggle poster
  3604. togglePoster: function togglePoster(enable) {
  3605. toggleClass(this.elements.container, this.config.classNames.posterEnabled, enable);
  3606. },
  3607. // Set the poster image (async)
  3608. // Used internally for the poster setter, with the passive option forced to false
  3609. setPoster: function setPoster(poster) {
  3610. var _this2 = this;
  3611. var passive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  3612. // Don't override if call is passive
  3613. if (passive && this.poster) {
  3614. return Promise.reject(new Error('Poster already set'));
  3615. } // Set property synchronously to respect the call order
  3616. this.media.setAttribute('data-poster', poster); // Wait until ui is ready
  3617. return ready.call(this) // Load image
  3618. .then(function () {
  3619. return loadImage(poster);
  3620. }).catch(function (err) {
  3621. // Hide poster on error unless it's been set by another call
  3622. if (poster === _this2.poster) {
  3623. ui.togglePoster.call(_this2, false);
  3624. } // Rethrow
  3625. throw err;
  3626. }).then(function () {
  3627. // Prevent race conditions
  3628. if (poster !== _this2.poster) {
  3629. throw new Error('setPoster cancelled by later call to setPoster');
  3630. }
  3631. }).then(function () {
  3632. Object.assign(_this2.elements.poster.style, {
  3633. backgroundImage: "url('".concat(poster, "')"),
  3634. // Reset backgroundSize as well (since it can be set to "cover" for padded thumbnails for youtube)
  3635. backgroundSize: ''
  3636. });
  3637. ui.togglePoster.call(_this2, true);
  3638. return poster;
  3639. });
  3640. },
  3641. // Check playing state
  3642. checkPlaying: function checkPlaying(event) {
  3643. var _this3 = this;
  3644. // Class hooks
  3645. toggleClass(this.elements.container, this.config.classNames.playing, this.playing);
  3646. toggleClass(this.elements.container, this.config.classNames.paused, this.paused);
  3647. toggleClass(this.elements.container, this.config.classNames.stopped, this.stopped); // Set state
  3648. Array.from(this.elements.buttons.play || []).forEach(function (target) {
  3649. Object.assign(target, {
  3650. pressed: _this3.playing
  3651. });
  3652. target.setAttribute('aria-label', i18n.get(_this3.playing ? 'pause' : 'play', _this3.config));
  3653. }); // Only update controls on non timeupdate events
  3654. if (is$1.event(event) && event.type === 'timeupdate') {
  3655. return;
  3656. } // Toggle controls
  3657. ui.toggleControls.call(this);
  3658. },
  3659. // Check if media is loading
  3660. checkLoading: function checkLoading(event) {
  3661. var _this4 = this;
  3662. this.loading = ['stalled', 'waiting'].includes(event.type); // Clear timer
  3663. clearTimeout(this.timers.loading); // Timer to prevent flicker when seeking
  3664. this.timers.loading = setTimeout(function () {
  3665. // Update progress bar loading class state
  3666. toggleClass(_this4.elements.container, _this4.config.classNames.loading, _this4.loading); // Update controls visibility
  3667. ui.toggleControls.call(_this4);
  3668. }, this.loading ? 250 : 0);
  3669. },
  3670. // Toggle controls based on state and `force` argument
  3671. toggleControls: function toggleControls(force) {
  3672. var controlsElement = this.elements.controls;
  3673. if (controlsElement && this.config.hideControls) {
  3674. // Don't hide controls if a touch-device user recently seeked. (Must be limited to touch devices, or it occasionally prevents desktop controls from hiding.)
  3675. var recentTouchSeek = this.touch && this.lastSeekTime + 2000 > Date.now(); // Show controls if force, loading, paused, button interaction, or recent seek, otherwise hide
  3676. this.toggleControls(Boolean(force || this.loading || this.paused || controlsElement.pressed || controlsElement.hover || recentTouchSeek));
  3677. }
  3678. },
  3679. // Migrate any custom properties from the media to the parent
  3680. migrateStyles: function migrateStyles() {
  3681. var _this5 = this;
  3682. // Loop through values (as they are the keys when the object is spread 🤔)
  3683. Object.values(_objectSpread2({}, this.media.style)) // We're only fussed about Plyr specific properties
  3684. .filter(function (key) {
  3685. return !is$1.empty(key) && key.startsWith('--plyr');
  3686. }).forEach(function (key) {
  3687. // Set on the container
  3688. _this5.elements.container.style.setProperty(key, _this5.media.style.getPropertyValue(key)); // Clean up from media element
  3689. _this5.media.style.removeProperty(key);
  3690. }); // Remove attribute if empty
  3691. if (is$1.empty(this.media.style)) {
  3692. this.media.removeAttribute('style');
  3693. }
  3694. }
  3695. };
  3696. var Listeners = /*#__PURE__*/function () {
  3697. function Listeners(player) {
  3698. _classCallCheck(this, Listeners);
  3699. this.player = player;
  3700. this.lastKey = null;
  3701. this.focusTimer = null;
  3702. this.lastKeyDown = null;
  3703. this.handleKey = this.handleKey.bind(this);
  3704. this.toggleMenu = this.toggleMenu.bind(this);
  3705. this.setTabFocus = this.setTabFocus.bind(this);
  3706. this.firstTouch = this.firstTouch.bind(this);
  3707. } // Handle key presses
  3708. _createClass(Listeners, [{
  3709. key: "handleKey",
  3710. value: function handleKey(event) {
  3711. var player = this.player;
  3712. var elements = player.elements;
  3713. var code = event.keyCode ? event.keyCode : event.which;
  3714. var pressed = event.type === 'keydown';
  3715. var repeat = pressed && code === this.lastKey; // Bail if a modifier key is set
  3716. if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) {
  3717. return;
  3718. } // If the event is bubbled from the media element
  3719. // Firefox doesn't get the keycode for whatever reason
  3720. if (!is$1.number(code)) {
  3721. return;
  3722. } // Seek by the number keys
  3723. var seekByKey = function seekByKey() {
  3724. // Divide the max duration into 10th's and times by the number value
  3725. player.currentTime = player.duration / 10 * (code - 48);
  3726. }; // Handle the key on keydown
  3727. // Reset on keyup
  3728. if (pressed) {
  3729. // Check focused element
  3730. // and if the focused element is not editable (e.g. text input)
  3731. // and any that accept key input http://webaim.org/techniques/keyboard/
  3732. var focused = document.activeElement;
  3733. if (is$1.element(focused)) {
  3734. var editable = player.config.selectors.editable;
  3735. var seek = elements.inputs.seek;
  3736. if (focused !== seek && matches$1(focused, editable)) {
  3737. return;
  3738. }
  3739. if (event.which === 32 && matches$1(focused, 'button, [role^="menuitem"]')) {
  3740. return;
  3741. }
  3742. } // Which keycodes should we prevent default
  3743. var preventDefault = [32, 37, 38, 39, 40, 48, 49, 50, 51, 52, 53, 54, 56, 57, 67, 70, 73, 75, 76, 77, 79]; // If the code is found prevent default (e.g. prevent scrolling for arrows)
  3744. if (preventDefault.includes(code)) {
  3745. event.preventDefault();
  3746. event.stopPropagation();
  3747. }
  3748. switch (code) {
  3749. case 48:
  3750. case 49:
  3751. case 50:
  3752. case 51:
  3753. case 52:
  3754. case 53:
  3755. case 54:
  3756. case 55:
  3757. case 56:
  3758. case 57:
  3759. // 0-9
  3760. if (!repeat) {
  3761. seekByKey();
  3762. }
  3763. break;
  3764. case 32:
  3765. case 75:
  3766. // Space and K key
  3767. if (!repeat) {
  3768. silencePromise(player.togglePlay());
  3769. }
  3770. break;
  3771. case 38:
  3772. // Arrow up
  3773. player.increaseVolume(0.1);
  3774. break;
  3775. case 40:
  3776. // Arrow down
  3777. player.decreaseVolume(0.1);
  3778. break;
  3779. case 77:
  3780. // M key
  3781. if (!repeat) {
  3782. player.muted = !player.muted;
  3783. }
  3784. break;
  3785. case 39:
  3786. // Arrow forward
  3787. player.forward();
  3788. break;
  3789. case 37:
  3790. // Arrow back
  3791. player.rewind();
  3792. break;
  3793. case 70:
  3794. // F key
  3795. player.fullscreen.toggle();
  3796. break;
  3797. case 67:
  3798. // C key
  3799. if (!repeat) {
  3800. player.toggleCaptions();
  3801. }
  3802. break;
  3803. case 76:
  3804. // L key
  3805. player.loop = !player.loop;
  3806. break;
  3807. } // Escape is handle natively when in full screen
  3808. // So we only need to worry about non native
  3809. if (code === 27 && !player.fullscreen.usingNative && player.fullscreen.active) {
  3810. player.fullscreen.toggle();
  3811. } // Store last code for next cycle
  3812. this.lastKey = code;
  3813. } else {
  3814. this.lastKey = null;
  3815. }
  3816. } // Toggle menu
  3817. }, {
  3818. key: "toggleMenu",
  3819. value: function toggleMenu(event) {
  3820. controls.toggleMenu.call(this.player, event);
  3821. } // Device is touch enabled
  3822. }, {
  3823. key: "firstTouch",
  3824. value: function firstTouch() {
  3825. var player = this.player;
  3826. var elements = player.elements;
  3827. player.touch = true; // Add touch class
  3828. toggleClass(elements.container, player.config.classNames.isTouch, true);
  3829. }
  3830. }, {
  3831. key: "setTabFocus",
  3832. value: function setTabFocus(event) {
  3833. var player = this.player;
  3834. var elements = player.elements;
  3835. clearTimeout(this.focusTimer); // Ignore any key other than tab
  3836. if (event.type === 'keydown' && event.which !== 9) {
  3837. return;
  3838. } // Store reference to event timeStamp
  3839. if (event.type === 'keydown') {
  3840. this.lastKeyDown = event.timeStamp;
  3841. } // Remove current classes
  3842. var removeCurrent = function removeCurrent() {
  3843. var className = player.config.classNames.tabFocus;
  3844. var current = getElements.call(player, ".".concat(className));
  3845. toggleClass(current, className, false);
  3846. }; // Determine if a key was pressed to trigger this event
  3847. var wasKeyDown = event.timeStamp - this.lastKeyDown <= 20; // Ignore focus events if a key was pressed prior
  3848. if (event.type === 'focus' && !wasKeyDown) {
  3849. return;
  3850. } // Remove all current
  3851. removeCurrent(); // Delay the adding of classname until the focus has changed
  3852. // This event fires before the focusin event
  3853. if (event.type !== 'focusout') {
  3854. this.focusTimer = setTimeout(function () {
  3855. var focused = document.activeElement; // Ignore if current focus element isn't inside the player
  3856. if (!elements.container.contains(focused)) {
  3857. return;
  3858. }
  3859. toggleClass(document.activeElement, player.config.classNames.tabFocus, true);
  3860. }, 10);
  3861. }
  3862. } // Global window & document listeners
  3863. }, {
  3864. key: "global",
  3865. value: function global() {
  3866. var toggle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  3867. var player = this.player; // Keyboard shortcuts
  3868. if (player.config.keyboard.global) {
  3869. toggleListener.call(player, window, 'keydown keyup', this.handleKey, toggle, false);
  3870. } // Click anywhere closes menu
  3871. toggleListener.call(player, document.body, 'click', this.toggleMenu, toggle); // Detect touch by events
  3872. once.call(player, document.body, 'touchstart', this.firstTouch); // Tab focus detection
  3873. toggleListener.call(player, document.body, 'keydown focus blur focusout', this.setTabFocus, toggle, false, true);
  3874. } // Container listeners
  3875. }, {
  3876. key: "container",
  3877. value: function container() {
  3878. var player = this.player;
  3879. var config = player.config,
  3880. elements = player.elements,
  3881. timers = player.timers; // Keyboard shortcuts
  3882. if (!config.keyboard.global && config.keyboard.focused) {
  3883. on.call(player, elements.container, 'keydown keyup', this.handleKey, false);
  3884. } // Toggle controls on mouse events and entering fullscreen
  3885. on.call(player, elements.container, 'mousemove mouseleave touchstart touchmove enterfullscreen exitfullscreen', function (event) {
  3886. var controlsElement = elements.controls; // Remove button states for fullscreen
  3887. if (controlsElement && event.type === 'enterfullscreen') {
  3888. controlsElement.pressed = false;
  3889. controlsElement.hover = false;
  3890. } // Show, then hide after a timeout unless another control event occurs
  3891. var show = ['touchstart', 'touchmove', 'mousemove'].includes(event.type);
  3892. var delay = 0;
  3893. if (show) {
  3894. ui.toggleControls.call(player, true); // Use longer timeout for touch devices
  3895. delay = player.touch ? 3000 : 2000;
  3896. } // Clear timer
  3897. clearTimeout(timers.controls); // Set new timer to prevent flicker when seeking
  3898. timers.controls = setTimeout(function () {
  3899. return ui.toggleControls.call(player, false);
  3900. }, delay);
  3901. }); // Set a gutter for Vimeo
  3902. var setGutter = function setGutter(ratio, padding, toggle) {
  3903. if (!player.isVimeo || player.config.vimeo.premium) {
  3904. return;
  3905. }
  3906. var target = player.elements.wrapper.firstChild;
  3907. var _ratio = _slicedToArray(ratio, 2),
  3908. y = _ratio[1];
  3909. var _getAspectRatio$call = getAspectRatio.call(player),
  3910. _getAspectRatio$call2 = _slicedToArray(_getAspectRatio$call, 2),
  3911. videoX = _getAspectRatio$call2[0],
  3912. videoY = _getAspectRatio$call2[1];
  3913. target.style.maxWidth = toggle ? "".concat(y / videoY * videoX, "px") : null;
  3914. target.style.margin = toggle ? '0 auto' : null;
  3915. }; // Resize on fullscreen change
  3916. var setPlayerSize = function setPlayerSize(measure) {
  3917. // If we don't need to measure the viewport
  3918. if (!measure) {
  3919. return setAspectRatio.call(player);
  3920. }
  3921. var rect = elements.container.getBoundingClientRect();
  3922. var width = rect.width,
  3923. height = rect.height;
  3924. return setAspectRatio.call(player, "".concat(width, ":").concat(height));
  3925. };
  3926. var resized = function resized() {
  3927. clearTimeout(timers.resized);
  3928. timers.resized = setTimeout(setPlayerSize, 50);
  3929. };
  3930. on.call(player, elements.container, 'enterfullscreen exitfullscreen', function (event) {
  3931. var _player$fullscreen = player.fullscreen,
  3932. target = _player$fullscreen.target,
  3933. usingNative = _player$fullscreen.usingNative; // Ignore events not from target
  3934. if (target !== elements.container) {
  3935. return;
  3936. } // If it's not an embed and no ratio specified
  3937. if (!player.isEmbed && is$1.empty(player.config.ratio)) {
  3938. return;
  3939. }
  3940. var isEnter = event.type === 'enterfullscreen'; // Set the player size when entering fullscreen to viewport size
  3941. var _setPlayerSize = setPlayerSize(isEnter),
  3942. padding = _setPlayerSize.padding,
  3943. ratio = _setPlayerSize.ratio; // Set Vimeo gutter
  3944. setGutter(ratio, padding, isEnter); // If not using native browser fullscreen API, we need to check for resizes of viewport
  3945. if (!usingNative) {
  3946. if (isEnter) {
  3947. on.call(player, window, 'resize', resized);
  3948. } else {
  3949. off.call(player, window, 'resize', resized);
  3950. }
  3951. }
  3952. });
  3953. } // Listen for media events
  3954. }, {
  3955. key: "media",
  3956. value: function media() {
  3957. var _this = this;
  3958. var player = this.player;
  3959. var elements = player.elements; // Time change on media
  3960. on.call(player, player.media, 'timeupdate seeking seeked', function (event) {
  3961. return controls.timeUpdate.call(player, event);
  3962. }); // Display duration
  3963. on.call(player, player.media, 'durationchange loadeddata loadedmetadata', function (event) {
  3964. return controls.durationUpdate.call(player, event);
  3965. }); // Handle the media finishing
  3966. on.call(player, player.media, 'ended', function () {
  3967. // Show poster on end
  3968. if (player.isHTML5 && player.isVideo && player.config.resetOnEnd) {
  3969. // Restart
  3970. player.restart(); // Call pause otherwise IE11 will start playing the video again
  3971. player.pause();
  3972. }
  3973. }); // Check for buffer progress
  3974. on.call(player, player.media, 'progress playing seeking seeked', function (event) {
  3975. return controls.updateProgress.call(player, event);
  3976. }); // Handle volume changes
  3977. on.call(player, player.media, 'volumechange', function (event) {
  3978. return controls.updateVolume.call(player, event);
  3979. }); // Handle play/pause
  3980. on.call(player, player.media, 'playing play pause ended emptied timeupdate', function (event) {
  3981. return ui.checkPlaying.call(player, event);
  3982. }); // Loading state
  3983. on.call(player, player.media, 'waiting canplay seeked playing', function (event) {
  3984. return ui.checkLoading.call(player, event);
  3985. }); // Click video
  3986. if (player.supported.ui && player.config.clickToPlay && !player.isAudio) {
  3987. // Re-fetch the wrapper
  3988. var wrapper = getElement.call(player, ".".concat(player.config.classNames.video)); // Bail if there's no wrapper (this should never happen)
  3989. if (!is$1.element(wrapper)) {
  3990. return;
  3991. } // On click play, pause or restart
  3992. on.call(player, elements.container, 'click', function (event) {
  3993. var targets = [elements.container, wrapper]; // Ignore if click if not container or in video wrapper
  3994. if (!targets.includes(event.target) && !wrapper.contains(event.target)) {
  3995. return;
  3996. } // Touch devices will just show controls (if hidden)
  3997. if (player.touch && player.config.hideControls) {
  3998. return;
  3999. }
  4000. if (player.ended) {
  4001. _this.proxy(event, player.restart, 'restart');
  4002. _this.proxy(event, function () {
  4003. silencePromise(player.play());
  4004. }, 'play');
  4005. } else {
  4006. _this.proxy(event, function () {
  4007. silencePromise(player.togglePlay());
  4008. }, 'play');
  4009. }
  4010. });
  4011. } // Disable right click
  4012. if (player.supported.ui && player.config.disableContextMenu) {
  4013. on.call(player, elements.wrapper, 'contextmenu', function (event) {
  4014. event.preventDefault();
  4015. }, false);
  4016. } // Volume change
  4017. on.call(player, player.media, 'volumechange', function () {
  4018. // Save to storage
  4019. player.storage.set({
  4020. volume: player.volume,
  4021. muted: player.muted
  4022. });
  4023. }); // Speed change
  4024. on.call(player, player.media, 'ratechange', function () {
  4025. // Update UI
  4026. controls.updateSetting.call(player, 'speed'); // Save to storage
  4027. player.storage.set({
  4028. speed: player.speed
  4029. });
  4030. }); // Quality change
  4031. on.call(player, player.media, 'qualitychange', function (event) {
  4032. // Update UI
  4033. controls.updateSetting.call(player, 'quality', null, event.detail.quality);
  4034. }); // Update download link when ready and if quality changes
  4035. on.call(player, player.media, 'ready qualitychange', function () {
  4036. controls.setDownloadUrl.call(player);
  4037. }); // Proxy events to container
  4038. // Bubble up key events for Edge
  4039. var proxyEvents = player.config.events.concat(['keyup', 'keydown']).join(' ');
  4040. on.call(player, player.media, proxyEvents, function (event) {
  4041. var _event$detail = event.detail,
  4042. detail = _event$detail === void 0 ? {} : _event$detail; // Get error details from media
  4043. if (event.type === 'error') {
  4044. detail = player.media.error;
  4045. }
  4046. triggerEvent.call(player, elements.container, event.type, true, detail);
  4047. });
  4048. } // Run default and custom handlers
  4049. }, {
  4050. key: "proxy",
  4051. value: function proxy(event, defaultHandler, customHandlerKey) {
  4052. var player = this.player;
  4053. var customHandler = player.config.listeners[customHandlerKey];
  4054. var hasCustomHandler = is$1.function(customHandler);
  4055. var returned = true; // Execute custom handler
  4056. if (hasCustomHandler) {
  4057. returned = customHandler.call(player, event);
  4058. } // Only call default handler if not prevented in custom handler
  4059. if (returned !== false && is$1.function(defaultHandler)) {
  4060. defaultHandler.call(player, event);
  4061. }
  4062. } // Trigger custom and default handlers
  4063. }, {
  4064. key: "bind",
  4065. value: function bind(element, type, defaultHandler, customHandlerKey) {
  4066. var _this2 = this;
  4067. var passive = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
  4068. var player = this.player;
  4069. var customHandler = player.config.listeners[customHandlerKey];
  4070. var hasCustomHandler = is$1.function(customHandler);
  4071. on.call(player, element, type, function (event) {
  4072. return _this2.proxy(event, defaultHandler, customHandlerKey);
  4073. }, passive && !hasCustomHandler);
  4074. } // Listen for control events
  4075. }, {
  4076. key: "controls",
  4077. value: function controls$1() {
  4078. var _this3 = this;
  4079. var player = this.player;
  4080. var elements = player.elements; // IE doesn't support input event, so we fallback to change
  4081. var inputEvent = browser.isIE ? 'change' : 'input'; // Play/pause toggle
  4082. if (elements.buttons.play) {
  4083. Array.from(elements.buttons.play).forEach(function (button) {
  4084. _this3.bind(button, 'click', function () {
  4085. silencePromise(player.togglePlay());
  4086. }, 'play');
  4087. });
  4088. } // Pause
  4089. this.bind(elements.buttons.restart, 'click', player.restart, 'restart'); // Rewind
  4090. this.bind(elements.buttons.rewind, 'click', player.rewind, 'rewind'); // Rewind
  4091. this.bind(elements.buttons.fastForward, 'click', player.forward, 'fastForward'); // Mute toggle
  4092. this.bind(elements.buttons.mute, 'click', function () {
  4093. player.muted = !player.muted;
  4094. }, 'mute'); // Captions toggle
  4095. this.bind(elements.buttons.captions, 'click', function () {
  4096. return player.toggleCaptions();
  4097. }); // Download
  4098. this.bind(elements.buttons.download, 'click', function () {
  4099. triggerEvent.call(player, player.media, 'download');
  4100. }, 'download'); // Fullscreen toggle
  4101. this.bind(elements.buttons.fullscreen, 'click', function () {
  4102. player.fullscreen.toggle();
  4103. }, 'fullscreen'); // Picture-in-Picture
  4104. this.bind(elements.buttons.pip, 'click', function () {
  4105. player.pip = 'toggle';
  4106. }, 'pip'); // Airplay
  4107. this.bind(elements.buttons.airplay, 'click', player.airplay, 'airplay'); // Settings menu - click toggle
  4108. this.bind(elements.buttons.settings, 'click', function (event) {
  4109. // Prevent the document click listener closing the menu
  4110. event.stopPropagation();
  4111. event.preventDefault();
  4112. controls.toggleMenu.call(player, event);
  4113. }, null, false); // Can't be passive as we're preventing default
  4114. // Settings menu - keyboard toggle
  4115. // We have to bind to keyup otherwise Firefox triggers a click when a keydown event handler shifts focus
  4116. // https://bugzilla.mozilla.org/show_bug.cgi?id=1220143
  4117. this.bind(elements.buttons.settings, 'keyup', function (event) {
  4118. var code = event.which; // We only care about space and return
  4119. if (![13, 32].includes(code)) {
  4120. return;
  4121. } // Because return triggers a click anyway, all we need to do is set focus
  4122. if (code === 13) {
  4123. controls.focusFirstMenuItem.call(player, null, true);
  4124. return;
  4125. } // Prevent scroll
  4126. event.preventDefault(); // Prevent playing video (Firefox)
  4127. event.stopPropagation(); // Toggle menu
  4128. controls.toggleMenu.call(player, event);
  4129. }, null, false // Can't be passive as we're preventing default
  4130. ); // Escape closes menu
  4131. this.bind(elements.settings.menu, 'keydown', function (event) {
  4132. if (event.which === 27) {
  4133. controls.toggleMenu.call(player, event);
  4134. }
  4135. }); // Set range input alternative "value", which matches the tooltip time (#954)
  4136. this.bind(elements.inputs.seek, 'mousedown mousemove', function (event) {
  4137. var rect = elements.progress.getBoundingClientRect();
  4138. var percent = 100 / rect.width * (event.pageX - rect.left);
  4139. event.currentTarget.setAttribute('seek-value', percent);
  4140. }); // Pause while seeking
  4141. this.bind(elements.inputs.seek, 'mousedown mouseup keydown keyup touchstart touchend', function (event) {
  4142. var seek = event.currentTarget;
  4143. var code = event.keyCode ? event.keyCode : event.which;
  4144. var attribute = 'play-on-seeked';
  4145. if (is$1.keyboardEvent(event) && code !== 39 && code !== 37) {
  4146. return;
  4147. } // Record seek time so we can prevent hiding controls for a few seconds after seek
  4148. player.lastSeekTime = Date.now(); // Was playing before?
  4149. var play = seek.hasAttribute(attribute); // Done seeking
  4150. var done = ['mouseup', 'touchend', 'keyup'].includes(event.type); // If we're done seeking and it was playing, resume playback
  4151. if (play && done) {
  4152. seek.removeAttribute(attribute);
  4153. silencePromise(player.play());
  4154. } else if (!done && player.playing) {
  4155. seek.setAttribute(attribute, '');
  4156. player.pause();
  4157. }
  4158. }); // Fix range inputs on iOS
  4159. // Super weird iOS bug where after you interact with an <input type="range">,
  4160. // it takes over further interactions on the page. This is a hack
  4161. if (browser.isIos) {
  4162. var inputs = getElements.call(player, 'input[type="range"]');
  4163. Array.from(inputs).forEach(function (input) {
  4164. return _this3.bind(input, inputEvent, function (event) {
  4165. return repaint(event.target);
  4166. });
  4167. });
  4168. } // Seek
  4169. this.bind(elements.inputs.seek, inputEvent, function (event) {
  4170. var seek = event.currentTarget; // If it exists, use seek-value instead of "value" for consistency with tooltip time (#954)
  4171. var seekTo = seek.getAttribute('seek-value');
  4172. if (is$1.empty(seekTo)) {
  4173. seekTo = seek.value;
  4174. }
  4175. seek.removeAttribute('seek-value');
  4176. player.currentTime = seekTo / seek.max * player.duration;
  4177. }, 'seek'); // Seek tooltip
  4178. this.bind(elements.progress, 'mouseenter mouseleave mousemove', function (event) {
  4179. return controls.updateSeekTooltip.call(player, event);
  4180. }); // Preview thumbnails plugin
  4181. // TODO: Really need to work on some sort of plug-in wide event bus or pub-sub for this
  4182. this.bind(elements.progress, 'mousemove touchmove', function (event) {
  4183. var previewThumbnails = player.previewThumbnails;
  4184. if (previewThumbnails && previewThumbnails.loaded) {
  4185. previewThumbnails.startMove(event);
  4186. }
  4187. }); // Hide thumbnail preview - on mouse click, mouse leave, and video play/seek. All four are required, e.g., for buffering
  4188. this.bind(elements.progress, 'mouseleave touchend click', function () {
  4189. var previewThumbnails = player.previewThumbnails;
  4190. if (previewThumbnails && previewThumbnails.loaded) {
  4191. previewThumbnails.endMove(false, true);
  4192. }
  4193. }); // Show scrubbing preview
  4194. this.bind(elements.progress, 'mousedown touchstart', function (event) {
  4195. var previewThumbnails = player.previewThumbnails;
  4196. if (previewThumbnails && previewThumbnails.loaded) {
  4197. previewThumbnails.startScrubbing(event);
  4198. }
  4199. });
  4200. this.bind(elements.progress, 'mouseup touchend', function (event) {
  4201. var previewThumbnails = player.previewThumbnails;
  4202. if (previewThumbnails && previewThumbnails.loaded) {
  4203. previewThumbnails.endScrubbing(event);
  4204. }
  4205. }); // Polyfill for lower fill in <input type="range"> for webkit
  4206. if (browser.isWebkit) {
  4207. Array.from(getElements.call(player, 'input[type="range"]')).forEach(function (element) {
  4208. _this3.bind(element, 'input', function (event) {
  4209. return controls.updateRangeFill.call(player, event.target);
  4210. });
  4211. });
  4212. } // Current time invert
  4213. // Only if one time element is used for both currentTime and duration
  4214. if (player.config.toggleInvert && !is$1.element(elements.display.duration)) {
  4215. this.bind(elements.display.currentTime, 'click', function () {
  4216. // Do nothing if we're at the start
  4217. if (player.currentTime === 0) {
  4218. return;
  4219. }
  4220. player.config.invertTime = !player.config.invertTime;
  4221. controls.timeUpdate.call(player);
  4222. });
  4223. } // Volume
  4224. this.bind(elements.inputs.volume, inputEvent, function (event) {
  4225. player.volume = event.target.value;
  4226. }, 'volume'); // Update controls.hover state (used for ui.toggleControls to avoid hiding when interacting)
  4227. this.bind(elements.controls, 'mouseenter mouseleave', function (event) {
  4228. elements.controls.hover = !player.touch && event.type === 'mouseenter';
  4229. }); // Also update controls.hover state for any non-player children of fullscreen element (as above)
  4230. if (elements.fullscreen) {
  4231. Array.from(elements.fullscreen.children).filter(function (c) {
  4232. return !c.contains(elements.container);
  4233. }).forEach(function (child) {
  4234. _this3.bind(child, 'mouseenter mouseleave', function (event) {
  4235. elements.controls.hover = !player.touch && event.type === 'mouseenter';
  4236. });
  4237. });
  4238. } // Update controls.pressed state (used for ui.toggleControls to avoid hiding when interacting)
  4239. this.bind(elements.controls, 'mousedown mouseup touchstart touchend touchcancel', function (event) {
  4240. elements.controls.pressed = ['mousedown', 'touchstart'].includes(event.type);
  4241. }); // Show controls when they receive focus (e.g., when using keyboard tab key)
  4242. this.bind(elements.controls, 'focusin', function () {
  4243. var config = player.config,
  4244. timers = player.timers; // Skip transition to prevent focus from scrolling the parent element
  4245. toggleClass(elements.controls, config.classNames.noTransition, true); // Toggle
  4246. ui.toggleControls.call(player, true); // Restore transition
  4247. setTimeout(function () {
  4248. toggleClass(elements.controls, config.classNames.noTransition, false);
  4249. }, 0); // Delay a little more for mouse users
  4250. var delay = _this3.touch ? 3000 : 4000; // Clear timer
  4251. clearTimeout(timers.controls); // Hide again after delay
  4252. timers.controls = setTimeout(function () {
  4253. return ui.toggleControls.call(player, false);
  4254. }, delay);
  4255. }); // Mouse wheel for volume
  4256. this.bind(elements.inputs.volume, 'wheel', function (event) {
  4257. // Detect "natural" scroll - suppored on OS X Safari only
  4258. // Other browsers on OS X will be inverted until support improves
  4259. var inverted = event.webkitDirectionInvertedFromDevice; // Get delta from event. Invert if `inverted` is true
  4260. var _map = [event.deltaX, -event.deltaY].map(function (value) {
  4261. return inverted ? -value : value;
  4262. }),
  4263. _map2 = _slicedToArray(_map, 2),
  4264. x = _map2[0],
  4265. y = _map2[1]; // Using the biggest delta, normalize to 1 or -1 (or 0 if no delta)
  4266. var direction = Math.sign(Math.abs(x) > Math.abs(y) ? x : y); // Change the volume by 2%
  4267. player.increaseVolume(direction / 50); // Don't break page scrolling at max and min
  4268. var volume = player.media.volume;
  4269. if (direction === 1 && volume < 1 || direction === -1 && volume > 0) {
  4270. event.preventDefault();
  4271. }
  4272. }, 'volume', false);
  4273. }
  4274. }]);
  4275. return Listeners;
  4276. }();
  4277. var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  4278. function createCommonjsModule(fn, module) {
  4279. return module = { exports: {} }, fn(module, module.exports), module.exports;
  4280. }
  4281. var loadjs_umd = createCommonjsModule(function (module, exports) {
  4282. (function (root, factory) {
  4283. {
  4284. module.exports = factory();
  4285. }
  4286. })(commonjsGlobal, function () {
  4287. /**
  4288. * Global dependencies.
  4289. * @global {Object} document - DOM
  4290. */
  4291. var devnull = function devnull() {},
  4292. bundleIdCache = {},
  4293. bundleResultCache = {},
  4294. bundleCallbackQueue = {};
  4295. /**
  4296. * Subscribe to bundle load event.
  4297. * @param {string[]} bundleIds - Bundle ids
  4298. * @param {Function} callbackFn - The callback function
  4299. */
  4300. function subscribe(bundleIds, callbackFn) {
  4301. // listify
  4302. bundleIds = bundleIds.push ? bundleIds : [bundleIds];
  4303. var depsNotFound = [],
  4304. i = bundleIds.length,
  4305. numWaiting = i,
  4306. fn,
  4307. bundleId,
  4308. r,
  4309. q; // define callback function
  4310. fn = function fn(bundleId, pathsNotFound) {
  4311. if (pathsNotFound.length) depsNotFound.push(bundleId);
  4312. numWaiting--;
  4313. if (!numWaiting) callbackFn(depsNotFound);
  4314. }; // register callback
  4315. while (i--) {
  4316. bundleId = bundleIds[i]; // execute callback if in result cache
  4317. r = bundleResultCache[bundleId];
  4318. if (r) {
  4319. fn(bundleId, r);
  4320. continue;
  4321. } // add to callback queue
  4322. q = bundleCallbackQueue[bundleId] = bundleCallbackQueue[bundleId] || [];
  4323. q.push(fn);
  4324. }
  4325. }
  4326. /**
  4327. * Publish bundle load event.
  4328. * @param {string} bundleId - Bundle id
  4329. * @param {string[]} pathsNotFound - List of files not found
  4330. */
  4331. function publish(bundleId, pathsNotFound) {
  4332. // exit if id isn't defined
  4333. if (!bundleId) return;
  4334. var q = bundleCallbackQueue[bundleId]; // cache result
  4335. bundleResultCache[bundleId] = pathsNotFound; // exit if queue is empty
  4336. if (!q) return; // empty callback queue
  4337. while (q.length) {
  4338. q[0](bundleId, pathsNotFound);
  4339. q.splice(0, 1);
  4340. }
  4341. }
  4342. /**
  4343. * Execute callbacks.
  4344. * @param {Object or Function} args - The callback args
  4345. * @param {string[]} depsNotFound - List of dependencies not found
  4346. */
  4347. function executeCallbacks(args, depsNotFound) {
  4348. // accept function as argument
  4349. if (args.call) args = {
  4350. success: args
  4351. }; // success and error callbacks
  4352. if (depsNotFound.length) (args.error || devnull)(depsNotFound);else (args.success || devnull)(args);
  4353. }
  4354. /**
  4355. * Load individual file.
  4356. * @param {string} path - The file path
  4357. * @param {Function} callbackFn - The callback function
  4358. */
  4359. function loadFile(path, callbackFn, args, numTries) {
  4360. var doc = document,
  4361. async = args.async,
  4362. maxTries = (args.numRetries || 0) + 1,
  4363. beforeCallbackFn = args.before || devnull,
  4364. pathname = path.replace(/[\?|#].*$/, ''),
  4365. pathStripped = path.replace(/^(css|img)!/, ''),
  4366. isLegacyIECss,
  4367. e;
  4368. numTries = numTries || 0;
  4369. if (/(^css!|\.css$)/.test(pathname)) {
  4370. // css
  4371. e = doc.createElement('link');
  4372. e.rel = 'stylesheet';
  4373. e.href = pathStripped; // tag IE9+
  4374. isLegacyIECss = 'hideFocus' in e; // use preload in IE Edge (to detect load errors)
  4375. if (isLegacyIECss && e.relList) {
  4376. isLegacyIECss = 0;
  4377. e.rel = 'preload';
  4378. e.as = 'style';
  4379. }
  4380. } else if (/(^img!|\.(png|gif|jpg|svg|webp)$)/.test(pathname)) {
  4381. // image
  4382. e = doc.createElement('img');
  4383. e.src = pathStripped;
  4384. } else {
  4385. // javascript
  4386. e = doc.createElement('script');
  4387. e.src = path;
  4388. e.async = async === undefined ? true : async;
  4389. }
  4390. e.onload = e.onerror = e.onbeforeload = function (ev) {
  4391. var result = ev.type[0]; // treat empty stylesheets as failures to get around lack of onerror
  4392. // support in IE9-11
  4393. if (isLegacyIECss) {
  4394. try {
  4395. if (!e.sheet.cssText.length) result = 'e';
  4396. } catch (x) {
  4397. // sheets objects created from load errors don't allow access to
  4398. // `cssText` (unless error is Code:18 SecurityError)
  4399. if (x.code != 18) result = 'e';
  4400. }
  4401. } // handle retries in case of load failure
  4402. if (result == 'e') {
  4403. // increment counter
  4404. numTries += 1; // exit function and try again
  4405. if (numTries < maxTries) {
  4406. return loadFile(path, callbackFn, args, numTries);
  4407. }
  4408. } else if (e.rel == 'preload' && e.as == 'style') {
  4409. // activate preloaded stylesheets
  4410. return e.rel = 'stylesheet'; // jshint ignore:line
  4411. } // execute callback
  4412. callbackFn(path, result, ev.defaultPrevented);
  4413. }; // add to document (unless callback returns `false`)
  4414. if (beforeCallbackFn(path, e) !== false) doc.head.appendChild(e);
  4415. }
  4416. /**
  4417. * Load multiple files.
  4418. * @param {string[]} paths - The file paths
  4419. * @param {Function} callbackFn - The callback function
  4420. */
  4421. function loadFiles(paths, callbackFn, args) {
  4422. // listify paths
  4423. paths = paths.push ? paths : [paths];
  4424. var numWaiting = paths.length,
  4425. x = numWaiting,
  4426. pathsNotFound = [],
  4427. fn,
  4428. i; // define callback function
  4429. fn = function fn(path, result, defaultPrevented) {
  4430. // handle error
  4431. if (result == 'e') pathsNotFound.push(path); // handle beforeload event. If defaultPrevented then that means the load
  4432. // will be blocked (ex. Ghostery/ABP on Safari)
  4433. if (result == 'b') {
  4434. if (defaultPrevented) pathsNotFound.push(path);else return;
  4435. }
  4436. numWaiting--;
  4437. if (!numWaiting) callbackFn(pathsNotFound);
  4438. }; // load scripts
  4439. for (i = 0; i < x; i++) {
  4440. loadFile(paths[i], fn, args);
  4441. }
  4442. }
  4443. /**
  4444. * Initiate script load and register bundle.
  4445. * @param {(string|string[])} paths - The file paths
  4446. * @param {(string|Function|Object)} [arg1] - The (1) bundleId or (2) success
  4447. * callback or (3) object literal with success/error arguments, numRetries,
  4448. * etc.
  4449. * @param {(Function|Object)} [arg2] - The (1) success callback or (2) object
  4450. * literal with success/error arguments, numRetries, etc.
  4451. */
  4452. function loadjs(paths, arg1, arg2) {
  4453. var bundleId, args; // bundleId (if string)
  4454. if (arg1 && arg1.trim) bundleId = arg1; // args (default is {})
  4455. args = (bundleId ? arg2 : arg1) || {}; // throw error if bundle is already defined
  4456. if (bundleId) {
  4457. if (bundleId in bundleIdCache) {
  4458. throw "LoadJS";
  4459. } else {
  4460. bundleIdCache[bundleId] = true;
  4461. }
  4462. }
  4463. function loadFn(resolve, reject) {
  4464. loadFiles(paths, function (pathsNotFound) {
  4465. // execute callbacks
  4466. executeCallbacks(args, pathsNotFound); // resolve Promise
  4467. if (resolve) {
  4468. executeCallbacks({
  4469. success: resolve,
  4470. error: reject
  4471. }, pathsNotFound);
  4472. } // publish bundle load event
  4473. publish(bundleId, pathsNotFound);
  4474. }, args);
  4475. }
  4476. if (args.returnPromise) return new Promise(loadFn);else loadFn();
  4477. }
  4478. /**
  4479. * Execute callbacks when dependencies have been satisfied.
  4480. * @param {(string|string[])} deps - List of bundle ids
  4481. * @param {Object} args - success/error arguments
  4482. */
  4483. loadjs.ready = function ready(deps, args) {
  4484. // subscribe to bundle load event
  4485. subscribe(deps, function (depsNotFound) {
  4486. // execute callbacks
  4487. executeCallbacks(args, depsNotFound);
  4488. });
  4489. return loadjs;
  4490. };
  4491. /**
  4492. * Manually satisfy bundle dependencies.
  4493. * @param {string} bundleId - The bundle id
  4494. */
  4495. loadjs.done = function done(bundleId) {
  4496. publish(bundleId, []);
  4497. };
  4498. /**
  4499. * Reset loadjs dependencies statuses
  4500. */
  4501. loadjs.reset = function reset() {
  4502. bundleIdCache = {};
  4503. bundleResultCache = {};
  4504. bundleCallbackQueue = {};
  4505. };
  4506. /**
  4507. * Determine if bundle has already been defined
  4508. * @param String} bundleId - The bundle id
  4509. */
  4510. loadjs.isDefined = function isDefined(bundleId) {
  4511. return bundleId in bundleIdCache;
  4512. }; // export
  4513. return loadjs;
  4514. });
  4515. });
  4516. // ==========================================================================
  4517. function loadScript(url) {
  4518. return new Promise(function (resolve, reject) {
  4519. loadjs_umd(url, {
  4520. success: resolve,
  4521. error: reject
  4522. });
  4523. });
  4524. }
  4525. function parseId(url) {
  4526. if (is$1.empty(url)) {
  4527. return null;
  4528. }
  4529. if (is$1.number(Number(url))) {
  4530. return url;
  4531. }
  4532. var regex = /^.*(vimeo.com\/|video\/)(\d+).*/;
  4533. return url.match(regex) ? RegExp.$2 : url;
  4534. } // Set playback state and trigger change (only on actual change)
  4535. function assurePlaybackState(play) {
  4536. if (play && !this.embed.hasPlayed) {
  4537. this.embed.hasPlayed = true;
  4538. }
  4539. if (this.media.paused === play) {
  4540. this.media.paused = !play;
  4541. triggerEvent.call(this, this.media, play ? 'play' : 'pause');
  4542. }
  4543. }
  4544. var vimeo = {
  4545. setup: function setup() {
  4546. var player = this; // Add embed class for responsive
  4547. toggleClass(player.elements.wrapper, player.config.classNames.embed, true); // Set speed options from config
  4548. player.options.speed = player.config.speed.options; // Set intial ratio
  4549. setAspectRatio.call(player); // Load the SDK if not already
  4550. if (!is$1.object(window.Vimeo)) {
  4551. loadScript(player.config.urls.vimeo.sdk).then(function () {
  4552. vimeo.ready.call(player);
  4553. }).catch(function (error) {
  4554. player.debug.warn('Vimeo SDK (player.js) failed to load', error);
  4555. });
  4556. } else {
  4557. vimeo.ready.call(player);
  4558. }
  4559. },
  4560. // API Ready
  4561. ready: function ready() {
  4562. var _this = this;
  4563. var player = this;
  4564. var config = player.config.vimeo;
  4565. var premium = config.premium,
  4566. referrerPolicy = config.referrerPolicy,
  4567. frameParams = _objectWithoutProperties(config, ["premium", "referrerPolicy"]); // If the owner has a pro or premium account then we can hide controls etc
  4568. if (premium) {
  4569. Object.assign(frameParams, {
  4570. controls: false,
  4571. sidedock: false
  4572. });
  4573. } // Get Vimeo params for the iframe
  4574. var params = buildUrlParams(_objectSpread2({
  4575. loop: player.config.loop.active,
  4576. autoplay: player.autoplay,
  4577. muted: player.muted,
  4578. gesture: 'media',
  4579. playsinline: !this.config.fullscreen.iosNative
  4580. }, frameParams)); // Get the source URL or ID
  4581. var source = player.media.getAttribute('src'); // Get from <div> if needed
  4582. if (is$1.empty(source)) {
  4583. source = player.media.getAttribute(player.config.attributes.embed.id);
  4584. }
  4585. var id = parseId(source); // Build an iframe
  4586. var iframe = createElement('iframe');
  4587. var src = format(player.config.urls.vimeo.iframe, id, params);
  4588. iframe.setAttribute('src', src);
  4589. iframe.setAttribute('allowfullscreen', '');
  4590. iframe.setAttribute('allow', 'autoplay,fullscreen,picture-in-picture'); // Set the referrer policy if required
  4591. if (!is$1.empty(referrerPolicy)) {
  4592. iframe.setAttribute('referrerPolicy', referrerPolicy);
  4593. } // Inject the package
  4594. var poster = player.poster;
  4595. if (premium) {
  4596. iframe.setAttribute('data-poster', poster);
  4597. player.media = replaceElement(iframe, player.media);
  4598. } else {
  4599. var wrapper = createElement('div', {
  4600. class: player.config.classNames.embedContainer,
  4601. 'data-poster': poster
  4602. });
  4603. wrapper.appendChild(iframe);
  4604. player.media = replaceElement(wrapper, player.media);
  4605. } // Get poster image
  4606. fetch(format(player.config.urls.vimeo.api, id), 'json').then(function (response) {
  4607. if (is$1.empty(response)) {
  4608. return;
  4609. } // Get the URL for thumbnail
  4610. var url = new URL(response[0].thumbnail_large); // Get original image
  4611. url.pathname = "".concat(url.pathname.split('_')[0], ".jpg"); // Set and show poster
  4612. ui.setPoster.call(player, url.href).catch(function () {});
  4613. }); // Setup instance
  4614. // https://github.com/vimeo/player.js
  4615. player.embed = new window.Vimeo.Player(iframe, {
  4616. autopause: player.config.autopause,
  4617. muted: player.muted
  4618. });
  4619. player.media.paused = true;
  4620. player.media.currentTime = 0; // Disable native text track rendering
  4621. if (player.supported.ui) {
  4622. player.embed.disableTextTrack();
  4623. } // Create a faux HTML5 API using the Vimeo API
  4624. player.media.play = function () {
  4625. assurePlaybackState.call(player, true);
  4626. return player.embed.play();
  4627. };
  4628. player.media.pause = function () {
  4629. assurePlaybackState.call(player, false);
  4630. return player.embed.pause();
  4631. };
  4632. player.media.stop = function () {
  4633. player.pause();
  4634. player.currentTime = 0;
  4635. }; // Seeking
  4636. var currentTime = player.media.currentTime;
  4637. Object.defineProperty(player.media, 'currentTime', {
  4638. get: function get() {
  4639. return currentTime;
  4640. },
  4641. set: function set(time) {
  4642. // Vimeo will automatically play on seek if the video hasn't been played before
  4643. // Get current paused state and volume etc
  4644. var embed = player.embed,
  4645. media = player.media,
  4646. paused = player.paused,
  4647. volume = player.volume;
  4648. var restorePause = paused && !embed.hasPlayed; // Set seeking state and trigger event
  4649. media.seeking = true;
  4650. triggerEvent.call(player, media, 'seeking'); // If paused, mute until seek is complete
  4651. Promise.resolve(restorePause && embed.setVolume(0)) // Seek
  4652. .then(function () {
  4653. return embed.setCurrentTime(time);
  4654. }) // Restore paused
  4655. .then(function () {
  4656. return restorePause && embed.pause();
  4657. }) // Restore volume
  4658. .then(function () {
  4659. return restorePause && embed.setVolume(volume);
  4660. }).catch(function () {// Do nothing
  4661. });
  4662. }
  4663. }); // Playback speed
  4664. var speed = player.config.speed.selected;
  4665. Object.defineProperty(player.media, 'playbackRate', {
  4666. get: function get() {
  4667. return speed;
  4668. },
  4669. set: function set(input) {
  4670. player.embed.setPlaybackRate(input).then(function () {
  4671. speed = input;
  4672. triggerEvent.call(player, player.media, 'ratechange');
  4673. }).catch(function () {
  4674. // Cannot set Playback Rate, Video is probably not on Pro account
  4675. player.options.speed = [1];
  4676. });
  4677. }
  4678. }); // Volume
  4679. var volume = player.config.volume;
  4680. Object.defineProperty(player.media, 'volume', {
  4681. get: function get() {
  4682. return volume;
  4683. },
  4684. set: function set(input) {
  4685. player.embed.setVolume(input).then(function () {
  4686. volume = input;
  4687. triggerEvent.call(player, player.media, 'volumechange');
  4688. });
  4689. }
  4690. }); // Muted
  4691. var muted = player.config.muted;
  4692. Object.defineProperty(player.media, 'muted', {
  4693. get: function get() {
  4694. return muted;
  4695. },
  4696. set: function set(input) {
  4697. var toggle = is$1.boolean(input) ? input : false;
  4698. player.embed.setVolume(toggle ? 0 : player.config.volume).then(function () {
  4699. muted = toggle;
  4700. triggerEvent.call(player, player.media, 'volumechange');
  4701. });
  4702. }
  4703. }); // Loop
  4704. var loop = player.config.loop;
  4705. Object.defineProperty(player.media, 'loop', {
  4706. get: function get() {
  4707. return loop;
  4708. },
  4709. set: function set(input) {
  4710. var toggle = is$1.boolean(input) ? input : player.config.loop.active;
  4711. player.embed.setLoop(toggle).then(function () {
  4712. loop = toggle;
  4713. });
  4714. }
  4715. }); // Source
  4716. var currentSrc;
  4717. player.embed.getVideoUrl().then(function (value) {
  4718. currentSrc = value;
  4719. controls.setDownloadUrl.call(player);
  4720. }).catch(function (error) {
  4721. _this.debug.warn(error);
  4722. });
  4723. Object.defineProperty(player.media, 'currentSrc', {
  4724. get: function get() {
  4725. return currentSrc;
  4726. }
  4727. }); // Ended
  4728. Object.defineProperty(player.media, 'ended', {
  4729. get: function get() {
  4730. return player.currentTime === player.duration;
  4731. }
  4732. }); // Set aspect ratio based on video size
  4733. Promise.all([player.embed.getVideoWidth(), player.embed.getVideoHeight()]).then(function (dimensions) {
  4734. var _dimensions = _slicedToArray(dimensions, 2),
  4735. width = _dimensions[0],
  4736. height = _dimensions[1];
  4737. player.embed.ratio = [width, height];
  4738. setAspectRatio.call(_this);
  4739. }); // Set autopause
  4740. player.embed.setAutopause(player.config.autopause).then(function (state) {
  4741. player.config.autopause = state;
  4742. }); // Get title
  4743. player.embed.getVideoTitle().then(function (title) {
  4744. player.config.title = title;
  4745. ui.setTitle.call(_this);
  4746. }); // Get current time
  4747. player.embed.getCurrentTime().then(function (value) {
  4748. currentTime = value;
  4749. triggerEvent.call(player, player.media, 'timeupdate');
  4750. }); // Get duration
  4751. player.embed.getDuration().then(function (value) {
  4752. player.media.duration = value;
  4753. triggerEvent.call(player, player.media, 'durationchange');
  4754. }); // Get captions
  4755. player.embed.getTextTracks().then(function (tracks) {
  4756. player.media.textTracks = tracks;
  4757. captions.setup.call(player);
  4758. });
  4759. player.embed.on('cuechange', function (_ref) {
  4760. var _ref$cues = _ref.cues,
  4761. cues = _ref$cues === void 0 ? [] : _ref$cues;
  4762. var strippedCues = cues.map(function (cue) {
  4763. return stripHTML(cue.text);
  4764. });
  4765. captions.updateCues.call(player, strippedCues);
  4766. });
  4767. player.embed.on('loaded', function () {
  4768. // Assure state and events are updated on autoplay
  4769. player.embed.getPaused().then(function (paused) {
  4770. assurePlaybackState.call(player, !paused);
  4771. if (!paused) {
  4772. triggerEvent.call(player, player.media, 'playing');
  4773. }
  4774. });
  4775. if (is$1.element(player.embed.element) && player.supported.ui) {
  4776. var frame = player.embed.element; // Fix keyboard focus issues
  4777. // https://github.com/sampotts/plyr/issues/317
  4778. frame.setAttribute('tabindex', -1);
  4779. }
  4780. });
  4781. player.embed.on('bufferstart', function () {
  4782. triggerEvent.call(player, player.media, 'waiting');
  4783. });
  4784. player.embed.on('bufferend', function () {
  4785. triggerEvent.call(player, player.media, 'playing');
  4786. });
  4787. player.embed.on('play', function () {
  4788. assurePlaybackState.call(player, true);
  4789. triggerEvent.call(player, player.media, 'playing');
  4790. });
  4791. player.embed.on('pause', function () {
  4792. assurePlaybackState.call(player, false);
  4793. });
  4794. player.embed.on('timeupdate', function (data) {
  4795. player.media.seeking = false;
  4796. currentTime = data.seconds;
  4797. triggerEvent.call(player, player.media, 'timeupdate');
  4798. });
  4799. player.embed.on('progress', function (data) {
  4800. player.media.buffered = data.percent;
  4801. triggerEvent.call(player, player.media, 'progress'); // Check all loaded
  4802. if (parseInt(data.percent, 10) === 1) {
  4803. triggerEvent.call(player, player.media, 'canplaythrough');
  4804. } // Get duration as if we do it before load, it gives an incorrect value
  4805. // https://github.com/sampotts/plyr/issues/891
  4806. player.embed.getDuration().then(function (value) {
  4807. if (value !== player.media.duration) {
  4808. player.media.duration = value;
  4809. triggerEvent.call(player, player.media, 'durationchange');
  4810. }
  4811. });
  4812. });
  4813. player.embed.on('seeked', function () {
  4814. player.media.seeking = false;
  4815. triggerEvent.call(player, player.media, 'seeked');
  4816. });
  4817. player.embed.on('ended', function () {
  4818. player.media.paused = true;
  4819. triggerEvent.call(player, player.media, 'ended');
  4820. });
  4821. player.embed.on('error', function (detail) {
  4822. player.media.error = detail;
  4823. triggerEvent.call(player, player.media, 'error');
  4824. }); // Rebuild UI
  4825. setTimeout(function () {
  4826. return ui.build.call(player);
  4827. }, 0);
  4828. }
  4829. };
  4830. // ==========================================================================
  4831. function parseId$1(url) {
  4832. if (is$1.empty(url)) {
  4833. return null;
  4834. }
  4835. var regex = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/;
  4836. return url.match(regex) ? RegExp.$2 : url;
  4837. } // Set playback state and trigger change (only on actual change)
  4838. function assurePlaybackState$1(play) {
  4839. if (play && !this.embed.hasPlayed) {
  4840. this.embed.hasPlayed = true;
  4841. }
  4842. if (this.media.paused === play) {
  4843. this.media.paused = !play;
  4844. triggerEvent.call(this, this.media, play ? 'play' : 'pause');
  4845. }
  4846. }
  4847. function getHost(config) {
  4848. if (config.noCookie) {
  4849. return 'https://www.youtube-nocookie.com';
  4850. }
  4851. if (window.location.protocol === 'http:') {
  4852. return 'http://www.youtube.com';
  4853. } // Use YouTube's default
  4854. return undefined;
  4855. }
  4856. var youtube = {
  4857. setup: function setup() {
  4858. var _this = this;
  4859. // Add embed class for responsive
  4860. toggleClass(this.elements.wrapper, this.config.classNames.embed, true); // Setup API
  4861. if (is$1.object(window.YT) && is$1.function(window.YT.Player)) {
  4862. youtube.ready.call(this);
  4863. } else {
  4864. // Reference current global callback
  4865. var callback = window.onYouTubeIframeAPIReady; // Set callback to process queue
  4866. window.onYouTubeIframeAPIReady = function () {
  4867. // Call global callback if set
  4868. if (is$1.function(callback)) {
  4869. callback();
  4870. }
  4871. youtube.ready.call(_this);
  4872. }; // Load the SDK
  4873. loadScript(this.config.urls.youtube.sdk).catch(function (error) {
  4874. _this.debug.warn('YouTube API failed to load', error);
  4875. });
  4876. }
  4877. },
  4878. // Get the media title
  4879. getTitle: function getTitle(videoId) {
  4880. var _this2 = this;
  4881. var url = format(this.config.urls.youtube.api, videoId);
  4882. fetch(url).then(function (data) {
  4883. if (is$1.object(data)) {
  4884. var title = data.title,
  4885. height = data.height,
  4886. width = data.width; // Set title
  4887. _this2.config.title = title;
  4888. ui.setTitle.call(_this2); // Set aspect ratio
  4889. _this2.embed.ratio = [width, height];
  4890. }
  4891. setAspectRatio.call(_this2);
  4892. }).catch(function () {
  4893. // Set aspect ratio
  4894. setAspectRatio.call(_this2);
  4895. });
  4896. },
  4897. // API ready
  4898. ready: function ready() {
  4899. var player = this; // Ignore already setup (race condition)
  4900. var currentId = player.media && player.media.getAttribute('id');
  4901. if (!is$1.empty(currentId) && currentId.startsWith('youtube-')) {
  4902. return;
  4903. } // Get the source URL or ID
  4904. var source = player.media.getAttribute('src'); // Get from <div> if needed
  4905. if (is$1.empty(source)) {
  4906. source = player.media.getAttribute(this.config.attributes.embed.id);
  4907. } // Replace the <iframe> with a <div> due to YouTube API issues
  4908. var videoId = parseId$1(source);
  4909. var id = generateId(player.provider); // Get poster, if already set
  4910. var poster = player.poster; // Replace media element
  4911. var container = createElement('div', {
  4912. id: id,
  4913. 'data-poster': poster
  4914. });
  4915. player.media = replaceElement(container, player.media); // Id to poster wrapper
  4916. var posterSrc = function posterSrc(s) {
  4917. return "https://i.ytimg.com/vi/".concat(videoId, "/").concat(s, "default.jpg");
  4918. }; // Check thumbnail images in order of quality, but reject fallback thumbnails (120px wide)
  4919. loadImage(posterSrc('maxres'), 121) // Higest quality and unpadded
  4920. .catch(function () {
  4921. return loadImage(posterSrc('sd'), 121);
  4922. }) // 480p padded 4:3
  4923. .catch(function () {
  4924. return loadImage(posterSrc('hq'));
  4925. }) // 360p padded 4:3. Always exists
  4926. .then(function (image) {
  4927. return ui.setPoster.call(player, image.src);
  4928. }).then(function (src) {
  4929. // If the image is padded, use background-size "cover" instead (like youtube does too with their posters)
  4930. if (!src.includes('maxres')) {
  4931. player.elements.poster.style.backgroundSize = 'cover';
  4932. }
  4933. }).catch(function () {});
  4934. var config = player.config.youtube; // Setup instance
  4935. // https://developers.google.com/youtube/iframe_api_reference
  4936. player.embed = new window.YT.Player(id, {
  4937. videoId: videoId,
  4938. host: getHost(config),
  4939. playerVars: extend({}, {
  4940. autoplay: player.config.autoplay ? 1 : 0,
  4941. // Autoplay
  4942. hl: player.config.hl,
  4943. // iframe interface language
  4944. controls: player.supported.ui ? 0 : 1,
  4945. // Only show controls if not fully supported
  4946. disablekb: 1,
  4947. // Disable keyboard as we handle it
  4948. playsinline: !player.config.fullscreen.iosNative ? 1 : 0,
  4949. // Allow iOS inline playback
  4950. // Captions are flaky on YouTube
  4951. cc_load_policy: player.captions.active ? 1 : 0,
  4952. cc_lang_pref: player.config.captions.language,
  4953. // Tracking for stats
  4954. widget_referrer: window ? window.location.href : null
  4955. }, config),
  4956. events: {
  4957. onError: function onError(event) {
  4958. // YouTube may fire onError twice, so only handle it once
  4959. if (!player.media.error) {
  4960. var code = event.data; // Messages copied from https://developers.google.com/youtube/iframe_api_reference#onError
  4961. var message = {
  4962. 2: 'The request contains an invalid parameter value. For example, this error occurs if you specify a video ID that does not have 11 characters, or if the video ID contains invalid characters, such as exclamation points or asterisks.',
  4963. 5: 'The requested content cannot be played in an HTML5 player or another error related to the HTML5 player has occurred.',
  4964. 100: 'The video requested was not found. This error occurs when a video has been removed (for any reason) or has been marked as private.',
  4965. 101: 'The owner of the requested video does not allow it to be played in embedded players.',
  4966. 150: 'The owner of the requested video does not allow it to be played in embedded players.'
  4967. }[code] || 'An unknown error occured';
  4968. player.media.error = {
  4969. code: code,
  4970. message: message
  4971. };
  4972. triggerEvent.call(player, player.media, 'error');
  4973. }
  4974. },
  4975. onPlaybackRateChange: function onPlaybackRateChange(event) {
  4976. // Get the instance
  4977. var instance = event.target; // Get current speed
  4978. player.media.playbackRate = instance.getPlaybackRate();
  4979. triggerEvent.call(player, player.media, 'ratechange');
  4980. },
  4981. onReady: function onReady(event) {
  4982. // Bail if onReady has already been called. See issue #1108
  4983. if (is$1.function(player.media.play)) {
  4984. return;
  4985. } // Get the instance
  4986. var instance = event.target; // Get the title
  4987. youtube.getTitle.call(player, videoId); // Create a faux HTML5 API using the YouTube API
  4988. player.media.play = function () {
  4989. assurePlaybackState$1.call(player, true);
  4990. instance.playVideo();
  4991. };
  4992. player.media.pause = function () {
  4993. assurePlaybackState$1.call(player, false);
  4994. instance.pauseVideo();
  4995. };
  4996. player.media.stop = function () {
  4997. instance.stopVideo();
  4998. };
  4999. player.media.duration = instance.getDuration();
  5000. player.media.paused = true; // Seeking
  5001. player.media.currentTime = 0;
  5002. Object.defineProperty(player.media, 'currentTime', {
  5003. get: function get() {
  5004. return Number(instance.getCurrentTime());
  5005. },
  5006. set: function set(time) {
  5007. // If paused and never played, mute audio preventively (YouTube starts playing on seek if the video hasn't been played yet).
  5008. if (player.paused && !player.embed.hasPlayed) {
  5009. player.embed.mute();
  5010. } // Set seeking state and trigger event
  5011. player.media.seeking = true;
  5012. triggerEvent.call(player, player.media, 'seeking'); // Seek after events sent
  5013. instance.seekTo(time);
  5014. }
  5015. }); // Playback speed
  5016. Object.defineProperty(player.media, 'playbackRate', {
  5017. get: function get() {
  5018. return instance.getPlaybackRate();
  5019. },
  5020. set: function set(input) {
  5021. instance.setPlaybackRate(input);
  5022. }
  5023. }); // Volume
  5024. var volume = player.config.volume;
  5025. Object.defineProperty(player.media, 'volume', {
  5026. get: function get() {
  5027. return volume;
  5028. },
  5029. set: function set(input) {
  5030. volume = input;
  5031. instance.setVolume(volume * 100);
  5032. triggerEvent.call(player, player.media, 'volumechange');
  5033. }
  5034. }); // Muted
  5035. var muted = player.config.muted;
  5036. Object.defineProperty(player.media, 'muted', {
  5037. get: function get() {
  5038. return muted;
  5039. },
  5040. set: function set(input) {
  5041. var toggle = is$1.boolean(input) ? input : muted;
  5042. muted = toggle;
  5043. instance[toggle ? 'mute' : 'unMute']();
  5044. triggerEvent.call(player, player.media, 'volumechange');
  5045. }
  5046. }); // Source
  5047. Object.defineProperty(player.media, 'currentSrc', {
  5048. get: function get() {
  5049. return instance.getVideoUrl();
  5050. }
  5051. }); // Ended
  5052. Object.defineProperty(player.media, 'ended', {
  5053. get: function get() {
  5054. return player.currentTime === player.duration;
  5055. }
  5056. }); // Get available speeds
  5057. var speeds = instance.getAvailablePlaybackRates(); // Filter based on config
  5058. player.options.speed = speeds.filter(function (s) {
  5059. return player.config.speed.options.includes(s);
  5060. }); // Set the tabindex to avoid focus entering iframe
  5061. if (player.supported.ui) {
  5062. player.media.setAttribute('tabindex', -1);
  5063. }
  5064. triggerEvent.call(player, player.media, 'timeupdate');
  5065. triggerEvent.call(player, player.media, 'durationchange'); // Reset timer
  5066. clearInterval(player.timers.buffering); // Setup buffering
  5067. player.timers.buffering = setInterval(function () {
  5068. // Get loaded % from YouTube
  5069. player.media.buffered = instance.getVideoLoadedFraction(); // Trigger progress only when we actually buffer something
  5070. if (player.media.lastBuffered === null || player.media.lastBuffered < player.media.buffered) {
  5071. triggerEvent.call(player, player.media, 'progress');
  5072. } // Set last buffer point
  5073. player.media.lastBuffered = player.media.buffered; // Bail if we're at 100%
  5074. if (player.media.buffered === 1) {
  5075. clearInterval(player.timers.buffering); // Trigger event
  5076. triggerEvent.call(player, player.media, 'canplaythrough');
  5077. }
  5078. }, 200); // Rebuild UI
  5079. setTimeout(function () {
  5080. return ui.build.call(player);
  5081. }, 50);
  5082. },
  5083. onStateChange: function onStateChange(event) {
  5084. // Get the instance
  5085. var instance = event.target; // Reset timer
  5086. clearInterval(player.timers.playing);
  5087. var seeked = player.media.seeking && [1, 2].includes(event.data);
  5088. if (seeked) {
  5089. // Unset seeking and fire seeked event
  5090. player.media.seeking = false;
  5091. triggerEvent.call(player, player.media, 'seeked');
  5092. } // Handle events
  5093. // -1 Unstarted
  5094. // 0 Ended
  5095. // 1 Playing
  5096. // 2 Paused
  5097. // 3 Buffering
  5098. // 5 Video cued
  5099. switch (event.data) {
  5100. case -1:
  5101. // Update scrubber
  5102. triggerEvent.call(player, player.media, 'timeupdate'); // Get loaded % from YouTube
  5103. player.media.buffered = instance.getVideoLoadedFraction();
  5104. triggerEvent.call(player, player.media, 'progress');
  5105. break;
  5106. case 0:
  5107. assurePlaybackState$1.call(player, false); // YouTube doesn't support loop for a single video, so mimick it.
  5108. if (player.media.loop) {
  5109. // YouTube needs a call to `stopVideo` before playing again
  5110. instance.stopVideo();
  5111. instance.playVideo();
  5112. } else {
  5113. triggerEvent.call(player, player.media, 'ended');
  5114. }
  5115. break;
  5116. case 1:
  5117. // Restore paused state (YouTube starts playing on seek if the video hasn't been played yet)
  5118. if (!player.config.autoplay && player.media.paused && !player.embed.hasPlayed) {
  5119. player.media.pause();
  5120. } else {
  5121. assurePlaybackState$1.call(player, true);
  5122. triggerEvent.call(player, player.media, 'playing'); // Poll to get playback progress
  5123. player.timers.playing = setInterval(function () {
  5124. triggerEvent.call(player, player.media, 'timeupdate');
  5125. }, 50); // Check duration again due to YouTube bug
  5126. // https://github.com/sampotts/plyr/issues/374
  5127. // https://code.google.com/p/gdata-issues/issues/detail?id=8690
  5128. if (player.media.duration !== instance.getDuration()) {
  5129. player.media.duration = instance.getDuration();
  5130. triggerEvent.call(player, player.media, 'durationchange');
  5131. }
  5132. }
  5133. break;
  5134. case 2:
  5135. // Restore audio (YouTube starts playing on seek if the video hasn't been played yet)
  5136. if (!player.muted) {
  5137. player.embed.unMute();
  5138. }
  5139. assurePlaybackState$1.call(player, false);
  5140. break;
  5141. case 3:
  5142. // Trigger waiting event to add loading classes to container as the video buffers.
  5143. triggerEvent.call(player, player.media, 'waiting');
  5144. break;
  5145. }
  5146. triggerEvent.call(player, player.elements.container, 'statechange', false, {
  5147. code: event.data
  5148. });
  5149. }
  5150. }
  5151. });
  5152. }
  5153. };
  5154. // ==========================================================================
  5155. var media = {
  5156. // Setup media
  5157. setup: function setup() {
  5158. // If there's no media, bail
  5159. if (!this.media) {
  5160. this.debug.warn('No media element found!');
  5161. return;
  5162. } // Add type class
  5163. toggleClass(this.elements.container, this.config.classNames.type.replace('{0}', this.type), true); // Add provider class
  5164. toggleClass(this.elements.container, this.config.classNames.provider.replace('{0}', this.provider), true); // Add video class for embeds
  5165. // This will require changes if audio embeds are added
  5166. if (this.isEmbed) {
  5167. toggleClass(this.elements.container, this.config.classNames.type.replace('{0}', 'video'), true);
  5168. } // Inject the player wrapper
  5169. if (this.isVideo) {
  5170. // Create the wrapper div
  5171. this.elements.wrapper = createElement('div', {
  5172. class: this.config.classNames.video
  5173. }); // Wrap the video in a container
  5174. wrap(this.media, this.elements.wrapper); // Poster image container
  5175. this.elements.poster = createElement('div', {
  5176. class: this.config.classNames.poster
  5177. });
  5178. this.elements.wrapper.appendChild(this.elements.poster);
  5179. }
  5180. if (this.isHTML5) {
  5181. html5.setup.call(this);
  5182. } else if (this.isYouTube) {
  5183. youtube.setup.call(this);
  5184. } else if (this.isVimeo) {
  5185. vimeo.setup.call(this);
  5186. }
  5187. }
  5188. };
  5189. var destroy = function destroy(instance) {
  5190. // Destroy our adsManager
  5191. if (instance.manager) {
  5192. instance.manager.destroy();
  5193. } // Destroy our adsManager
  5194. if (instance.elements.displayContainer) {
  5195. instance.elements.displayContainer.destroy();
  5196. }
  5197. instance.elements.container.remove();
  5198. };
  5199. var Ads = /*#__PURE__*/function () {
  5200. /**
  5201. * Ads constructor.
  5202. * @param {Object} player
  5203. * @return {Ads}
  5204. */
  5205. function Ads(player) {
  5206. var _this = this;
  5207. _classCallCheck(this, Ads);
  5208. this.player = player;
  5209. this.config = player.config.ads;
  5210. this.playing = false;
  5211. this.initialized = false;
  5212. this.elements = {
  5213. container: null,
  5214. displayContainer: null
  5215. };
  5216. this.manager = null;
  5217. this.loader = null;
  5218. this.cuePoints = null;
  5219. this.events = {};
  5220. this.safetyTimer = null;
  5221. this.countdownTimer = null; // Setup a promise to resolve when the IMA manager is ready
  5222. this.managerPromise = new Promise(function (resolve, reject) {
  5223. // The ad is loaded and ready
  5224. _this.on('loaded', resolve); // Ads failed
  5225. _this.on('error', reject);
  5226. });
  5227. this.load();
  5228. }
  5229. _createClass(Ads, [{
  5230. key: "load",
  5231. /**
  5232. * Load the IMA SDK
  5233. */
  5234. value: function load() {
  5235. var _this2 = this;
  5236. if (!this.enabled) {
  5237. return;
  5238. } // Check if the Google IMA3 SDK is loaded or load it ourselves
  5239. if (!is$1.object(window.google) || !is$1.object(window.google.ima)) {
  5240. loadScript(this.player.config.urls.googleIMA.sdk).then(function () {
  5241. _this2.ready();
  5242. }).catch(function () {
  5243. // Script failed to load or is blocked
  5244. _this2.trigger('error', new Error('Google IMA SDK failed to load'));
  5245. });
  5246. } else {
  5247. this.ready();
  5248. }
  5249. }
  5250. /**
  5251. * Get the ads instance ready
  5252. */
  5253. }, {
  5254. key: "ready",
  5255. value: function ready() {
  5256. var _this3 = this;
  5257. // Double check we're enabled
  5258. if (!this.enabled) {
  5259. destroy(this);
  5260. } // Start ticking our safety timer. If the whole advertisement
  5261. // thing doesn't resolve within our set time; we bail
  5262. this.startSafetyTimer(12000, 'ready()'); // Clear the safety timer
  5263. this.managerPromise.then(function () {
  5264. _this3.clearSafetyTimer('onAdsManagerLoaded()');
  5265. }); // Set listeners on the Plyr instance
  5266. this.listeners(); // Setup the IMA SDK
  5267. this.setupIMA();
  5268. } // Build the tag URL
  5269. }, {
  5270. key: "setupIMA",
  5271. /**
  5272. * In order for the SDK to display ads for our video, we need to tell it where to put them,
  5273. * so here we define our ad container. This div is set up to render on top of the video player.
  5274. * Using the code below, we tell the SDK to render ads within that div. We also provide a
  5275. * handle to the content video player - the SDK will poll the current time of our player to
  5276. * properly place mid-rolls. After we create the ad display container, we initialize it. On
  5277. * mobile devices, this initialization is done as the result of a user action.
  5278. */
  5279. value: function setupIMA() {
  5280. var _this4 = this;
  5281. // Create the container for our advertisements
  5282. this.elements.container = createElement('div', {
  5283. class: this.player.config.classNames.ads
  5284. });
  5285. this.player.elements.container.appendChild(this.elements.container); // So we can run VPAID2
  5286. google.ima.settings.setVpaidMode(google.ima.ImaSdkSettings.VpaidMode.ENABLED); // Set language
  5287. google.ima.settings.setLocale(this.player.config.ads.language); // Set playback for iOS10+
  5288. google.ima.settings.setDisableCustomPlaybackForIOS10Plus(this.player.config.playsinline); // We assume the adContainer is the video container of the plyr element that will house the ads
  5289. this.elements.displayContainer = new google.ima.AdDisplayContainer(this.elements.container, this.player.media); // Create ads loader
  5290. this.loader = new google.ima.AdsLoader(this.elements.displayContainer); // Listen and respond to ads loaded and error events
  5291. this.loader.addEventListener(google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, function (event) {
  5292. return _this4.onAdsManagerLoaded(event);
  5293. }, false);
  5294. this.loader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, function (error) {
  5295. return _this4.onAdError(error);
  5296. }, false); // Request video ads to be pre-loaded
  5297. this.requestAds();
  5298. }
  5299. /**
  5300. * Request advertisements
  5301. */
  5302. }, {
  5303. key: "requestAds",
  5304. value: function requestAds() {
  5305. var container = this.player.elements.container;
  5306. try {
  5307. // Request video ads
  5308. var request = new google.ima.AdsRequest();
  5309. request.adTagUrl = this.tagUrl; // Specify the linear and nonlinear slot sizes. This helps the SDK
  5310. // to select the correct creative if multiple are returned
  5311. request.linearAdSlotWidth = container.offsetWidth;
  5312. request.linearAdSlotHeight = container.offsetHeight;
  5313. request.nonLinearAdSlotWidth = container.offsetWidth;
  5314. request.nonLinearAdSlotHeight = container.offsetHeight; // We only overlay ads as we only support video.
  5315. request.forceNonLinearFullSlot = false; // Mute based on current state
  5316. request.setAdWillPlayMuted(!this.player.muted);
  5317. this.loader.requestAds(request);
  5318. } catch (e) {
  5319. this.onAdError(e);
  5320. }
  5321. }
  5322. /**
  5323. * Update the ad countdown
  5324. * @param {Boolean} start
  5325. */
  5326. }, {
  5327. key: "pollCountdown",
  5328. value: function pollCountdown() {
  5329. var _this5 = this;
  5330. var start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  5331. if (!start) {
  5332. clearInterval(this.countdownTimer);
  5333. this.elements.container.removeAttribute('data-badge-text');
  5334. return;
  5335. }
  5336. var update = function update() {
  5337. var time = formatTime(Math.max(_this5.manager.getRemainingTime(), 0));
  5338. var label = "".concat(i18n.get('advertisement', _this5.player.config), " - ").concat(time);
  5339. _this5.elements.container.setAttribute('data-badge-text', label);
  5340. };
  5341. this.countdownTimer = setInterval(update, 100);
  5342. }
  5343. /**
  5344. * This method is called whenever the ads are ready inside the AdDisplayContainer
  5345. * @param {Event} adsManagerLoadedEvent
  5346. */
  5347. }, {
  5348. key: "onAdsManagerLoaded",
  5349. value: function onAdsManagerLoaded(event) {
  5350. var _this6 = this;
  5351. // Load could occur after a source change (race condition)
  5352. if (!this.enabled) {
  5353. return;
  5354. } // Get the ads manager
  5355. var settings = new google.ima.AdsRenderingSettings(); // Tell the SDK to save and restore content video state on our behalf
  5356. settings.restoreCustomPlaybackStateOnAdBreakComplete = true;
  5357. settings.enablePreloading = true; // The SDK is polling currentTime on the contentPlayback. And needs a duration
  5358. // so it can determine when to start the mid- and post-roll
  5359. this.manager = event.getAdsManager(this.player, settings); // Get the cue points for any mid-rolls by filtering out the pre- and post-roll
  5360. this.cuePoints = this.manager.getCuePoints(); // Add listeners to the required events
  5361. // Advertisement error events
  5362. this.manager.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, function (error) {
  5363. return _this6.onAdError(error);
  5364. }); // Advertisement regular events
  5365. Object.keys(google.ima.AdEvent.Type).forEach(function (type) {
  5366. _this6.manager.addEventListener(google.ima.AdEvent.Type[type], function (e) {
  5367. return _this6.onAdEvent(e);
  5368. });
  5369. }); // Resolve our adsManager
  5370. this.trigger('loaded');
  5371. }
  5372. }, {
  5373. key: "addCuePoints",
  5374. value: function addCuePoints() {
  5375. var _this7 = this;
  5376. // Add advertisement cue's within the time line if available
  5377. if (!is$1.empty(this.cuePoints)) {
  5378. this.cuePoints.forEach(function (cuePoint) {
  5379. if (cuePoint !== 0 && cuePoint !== -1 && cuePoint < _this7.player.duration) {
  5380. var seekElement = _this7.player.elements.progress;
  5381. if (is$1.element(seekElement)) {
  5382. var cuePercentage = 100 / _this7.player.duration * cuePoint;
  5383. var cue = createElement('span', {
  5384. class: _this7.player.config.classNames.cues
  5385. });
  5386. cue.style.left = "".concat(cuePercentage.toString(), "%");
  5387. seekElement.appendChild(cue);
  5388. }
  5389. }
  5390. });
  5391. }
  5392. }
  5393. /**
  5394. * This is where all the event handling takes place. Retrieve the ad from the event. Some
  5395. * events (e.g. ALL_ADS_COMPLETED) don't have the ad object associated
  5396. * https://developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#ima.AdEvent.Type
  5397. * @param {Event} event
  5398. */
  5399. }, {
  5400. key: "onAdEvent",
  5401. value: function onAdEvent(event) {
  5402. var _this8 = this;
  5403. var container = this.player.elements.container; // Retrieve the ad from the event. Some events (e.g. ALL_ADS_COMPLETED)
  5404. // don't have ad object associated
  5405. var ad = event.getAd();
  5406. var adData = event.getAdData(); // Proxy event
  5407. var dispatchEvent = function dispatchEvent(type) {
  5408. triggerEvent.call(_this8.player, _this8.player.media, "ads".concat(type.replace(/_/g, '').toLowerCase()));
  5409. }; // Bubble the event
  5410. dispatchEvent(event.type);
  5411. switch (event.type) {
  5412. case google.ima.AdEvent.Type.LOADED:
  5413. // This is the first event sent for an ad - it is possible to determine whether the
  5414. // ad is a video ad or an overlay
  5415. this.trigger('loaded'); // Start countdown
  5416. this.pollCountdown(true);
  5417. if (!ad.isLinear()) {
  5418. // Position AdDisplayContainer correctly for overlay
  5419. ad.width = container.offsetWidth;
  5420. ad.height = container.offsetHeight;
  5421. } // console.info('Ad type: ' + event.getAd().getAdPodInfo().getPodIndex());
  5422. // console.info('Ad time: ' + event.getAd().getAdPodInfo().getTimeOffset());
  5423. break;
  5424. case google.ima.AdEvent.Type.STARTED:
  5425. // Set volume to match player
  5426. this.manager.setVolume(this.player.volume);
  5427. break;
  5428. case google.ima.AdEvent.Type.ALL_ADS_COMPLETED:
  5429. // All ads for the current videos are done. We can now request new advertisements
  5430. // in case the video is re-played
  5431. // TODO: Example for what happens when a next video in a playlist would be loaded.
  5432. // So here we load a new video when all ads are done.
  5433. // Then we load new ads within a new adsManager. When the video
  5434. // Is started - after - the ads are loaded, then we get ads.
  5435. // You can also easily test cancelling and reloading by running
  5436. // player.ads.cancel() and player.ads.play from the console I guess.
  5437. // this.player.source = {
  5438. // type: 'video',
  5439. // title: 'View From A Blue Moon',
  5440. // sources: [{
  5441. // src:
  5442. // 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.mp4', type:
  5443. // 'video/mp4', }], poster:
  5444. // 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.jpg', tracks:
  5445. // [ { kind: 'captions', label: 'English', srclang: 'en', src:
  5446. // 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.en.vtt',
  5447. // default: true, }, { kind: 'captions', label: 'French', srclang: 'fr', src:
  5448. // 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.fr.vtt', }, ],
  5449. // };
  5450. // TODO: So there is still this thing where a video should only be allowed to start
  5451. // playing when the IMA SDK is ready or has failed
  5452. if (this.player.ended) {
  5453. this.loadAds();
  5454. } else {
  5455. // The SDK won't allow new ads to be called without receiving a contentComplete()
  5456. this.loader.contentComplete();
  5457. }
  5458. break;
  5459. case google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED:
  5460. // This event indicates the ad has started - the video player can adjust the UI,
  5461. // for example display a pause button and remaining time. Fired when content should
  5462. // be paused. This usually happens right before an ad is about to cover the content
  5463. this.pauseContent();
  5464. break;
  5465. case google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED:
  5466. // This event indicates the ad has finished - the video player can perform
  5467. // appropriate UI actions, such as removing the timer for remaining time detection.
  5468. // Fired when content should be resumed. This usually happens when an ad finishes
  5469. // or collapses
  5470. this.pollCountdown();
  5471. this.resumeContent();
  5472. break;
  5473. case google.ima.AdEvent.Type.LOG:
  5474. if (adData.adError) {
  5475. this.player.debug.warn("Non-fatal ad error: ".concat(adData.adError.getMessage()));
  5476. }
  5477. break;
  5478. }
  5479. }
  5480. /**
  5481. * Any ad error handling comes through here
  5482. * @param {Event} event
  5483. */
  5484. }, {
  5485. key: "onAdError",
  5486. value: function onAdError(event) {
  5487. this.cancel();
  5488. this.player.debug.warn('Ads error', event);
  5489. }
  5490. /**
  5491. * Setup hooks for Plyr and window events. This ensures
  5492. * the mid- and post-roll launch at the correct time. And
  5493. * resize the advertisement when the player resizes
  5494. */
  5495. }, {
  5496. key: "listeners",
  5497. value: function listeners() {
  5498. var _this9 = this;
  5499. var container = this.player.elements.container;
  5500. var time;
  5501. this.player.on('canplay', function () {
  5502. _this9.addCuePoints();
  5503. });
  5504. this.player.on('ended', function () {
  5505. _this9.loader.contentComplete();
  5506. });
  5507. this.player.on('timeupdate', function () {
  5508. time = _this9.player.currentTime;
  5509. });
  5510. this.player.on('seeked', function () {
  5511. var seekedTime = _this9.player.currentTime;
  5512. if (is$1.empty(_this9.cuePoints)) {
  5513. return;
  5514. }
  5515. _this9.cuePoints.forEach(function (cuePoint, index) {
  5516. if (time < cuePoint && cuePoint < seekedTime) {
  5517. _this9.manager.discardAdBreak();
  5518. _this9.cuePoints.splice(index, 1);
  5519. }
  5520. });
  5521. }); // Listen to the resizing of the window. And resize ad accordingly
  5522. // TODO: eventually implement ResizeObserver
  5523. window.addEventListener('resize', function () {
  5524. if (_this9.manager) {
  5525. _this9.manager.resize(container.offsetWidth, container.offsetHeight, google.ima.ViewMode.NORMAL);
  5526. }
  5527. });
  5528. }
  5529. /**
  5530. * Initialize the adsManager and start playing advertisements
  5531. */
  5532. }, {
  5533. key: "play",
  5534. value: function play() {
  5535. var _this10 = this;
  5536. var container = this.player.elements.container;
  5537. if (!this.managerPromise) {
  5538. this.resumeContent();
  5539. } // Play the requested advertisement whenever the adsManager is ready
  5540. this.managerPromise.then(function () {
  5541. // Set volume to match player
  5542. _this10.manager.setVolume(_this10.player.volume); // Initialize the container. Must be done via a user action on mobile devices
  5543. _this10.elements.displayContainer.initialize();
  5544. try {
  5545. if (!_this10.initialized) {
  5546. // Initialize the ads manager. Ad rules playlist will start at this time
  5547. _this10.manager.init(container.offsetWidth, container.offsetHeight, google.ima.ViewMode.NORMAL); // Call play to start showing the ad. Single video and overlay ads will
  5548. // start at this time; the call will be ignored for ad rules
  5549. _this10.manager.start();
  5550. }
  5551. _this10.initialized = true;
  5552. } catch (adError) {
  5553. // An error may be thrown if there was a problem with the
  5554. // VAST response
  5555. _this10.onAdError(adError);
  5556. }
  5557. }).catch(function () {});
  5558. }
  5559. /**
  5560. * Resume our video
  5561. */
  5562. }, {
  5563. key: "resumeContent",
  5564. value: function resumeContent() {
  5565. // Hide the advertisement container
  5566. this.elements.container.style.zIndex = ''; // Ad is stopped
  5567. this.playing = false; // Play video
  5568. silencePromise(this.player.media.play());
  5569. }
  5570. /**
  5571. * Pause our video
  5572. */
  5573. }, {
  5574. key: "pauseContent",
  5575. value: function pauseContent() {
  5576. // Show the advertisement container
  5577. this.elements.container.style.zIndex = 3; // Ad is playing
  5578. this.playing = true; // Pause our video.
  5579. this.player.media.pause();
  5580. }
  5581. /**
  5582. * Destroy the adsManager so we can grab new ads after this. If we don't then we're not
  5583. * allowed to call new ads based on google policies, as they interpret this as an accidental
  5584. * video requests. https://developers.google.com/interactive-
  5585. * media-ads/docs/sdks/android/faq#8
  5586. */
  5587. }, {
  5588. key: "cancel",
  5589. value: function cancel() {
  5590. // Pause our video
  5591. if (this.initialized) {
  5592. this.resumeContent();
  5593. } // Tell our instance that we're done for now
  5594. this.trigger('error'); // Re-create our adsManager
  5595. this.loadAds();
  5596. }
  5597. /**
  5598. * Re-create our adsManager
  5599. */
  5600. }, {
  5601. key: "loadAds",
  5602. value: function loadAds() {
  5603. var _this11 = this;
  5604. // Tell our adsManager to go bye bye
  5605. this.managerPromise.then(function () {
  5606. // Destroy our adsManager
  5607. if (_this11.manager) {
  5608. _this11.manager.destroy();
  5609. } // Re-set our adsManager promises
  5610. _this11.managerPromise = new Promise(function (resolve) {
  5611. _this11.on('loaded', resolve);
  5612. _this11.player.debug.log(_this11.manager);
  5613. }); // Now that the manager has been destroyed set it to also be un-initialized
  5614. _this11.initialized = false; // Now request some new advertisements
  5615. _this11.requestAds();
  5616. }).catch(function () {});
  5617. }
  5618. /**
  5619. * Handles callbacks after an ad event was invoked
  5620. * @param {String} event - Event type
  5621. */
  5622. }, {
  5623. key: "trigger",
  5624. value: function trigger(event) {
  5625. var _this12 = this;
  5626. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  5627. args[_key - 1] = arguments[_key];
  5628. }
  5629. var handlers = this.events[event];
  5630. if (is$1.array(handlers)) {
  5631. handlers.forEach(function (handler) {
  5632. if (is$1.function(handler)) {
  5633. handler.apply(_this12, args);
  5634. }
  5635. });
  5636. }
  5637. }
  5638. /**
  5639. * Add event listeners
  5640. * @param {String} event - Event type
  5641. * @param {Function} callback - Callback for when event occurs
  5642. * @return {Ads}
  5643. */
  5644. }, {
  5645. key: "on",
  5646. value: function on(event, callback) {
  5647. if (!is$1.array(this.events[event])) {
  5648. this.events[event] = [];
  5649. }
  5650. this.events[event].push(callback);
  5651. return this;
  5652. }
  5653. /**
  5654. * Setup a safety timer for when the ad network doesn't respond for whatever reason.
  5655. * The advertisement has 12 seconds to get its things together. We stop this timer when the
  5656. * advertisement is playing, or when a user action is required to start, then we clear the
  5657. * timer on ad ready
  5658. * @param {Number} time
  5659. * @param {String} from
  5660. */
  5661. }, {
  5662. key: "startSafetyTimer",
  5663. value: function startSafetyTimer(time, from) {
  5664. var _this13 = this;
  5665. this.player.debug.log("Safety timer invoked from: ".concat(from));
  5666. this.safetyTimer = setTimeout(function () {
  5667. _this13.cancel();
  5668. _this13.clearSafetyTimer('startSafetyTimer()');
  5669. }, time);
  5670. }
  5671. /**
  5672. * Clear our safety timer(s)
  5673. * @param {String} from
  5674. */
  5675. }, {
  5676. key: "clearSafetyTimer",
  5677. value: function clearSafetyTimer(from) {
  5678. if (!is$1.nullOrUndefined(this.safetyTimer)) {
  5679. this.player.debug.log("Safety timer cleared from: ".concat(from));
  5680. clearTimeout(this.safetyTimer);
  5681. this.safetyTimer = null;
  5682. }
  5683. }
  5684. }, {
  5685. key: "enabled",
  5686. get: function get() {
  5687. var config = this.config;
  5688. return this.player.isHTML5 && this.player.isVideo && config.enabled && (!is$1.empty(config.publisherId) || is$1.url(config.tagUrl));
  5689. }
  5690. }, {
  5691. key: "tagUrl",
  5692. get: function get() {
  5693. var config = this.config;
  5694. if (is$1.url(config.tagUrl)) {
  5695. return config.tagUrl;
  5696. }
  5697. var params = {
  5698. AV_PUBLISHERID: '58c25bb0073ef448b1087ad6',
  5699. AV_CHANNELID: '5a0458dc28a06145e4519d21',
  5700. AV_URL: window.location.hostname,
  5701. cb: Date.now(),
  5702. AV_WIDTH: 640,
  5703. AV_HEIGHT: 480,
  5704. AV_CDIM2: config.publisherId
  5705. };
  5706. var base = 'https://go.aniview.com/api/adserver6/vast/';
  5707. return "".concat(base, "?").concat(buildUrlParams(params));
  5708. }
  5709. }]);
  5710. return Ads;
  5711. }();
  5712. var parseVtt = function parseVtt(vttDataString) {
  5713. var processedList = [];
  5714. var frames = vttDataString.split(/\r\n\r\n|\n\n|\r\r/);
  5715. frames.forEach(function (frame) {
  5716. var result = {};
  5717. var lines = frame.split(/\r\n|\n|\r/);
  5718. lines.forEach(function (line) {
  5719. if (!is$1.number(result.startTime)) {
  5720. // The line with start and end times on it is the first line of interest
  5721. var matchTimes = line.match(/([0-9]{2})?:?([0-9]{2}):([0-9]{2}).([0-9]{2,3})( ?--> ?)([0-9]{2})?:?([0-9]{2}):([0-9]{2}).([0-9]{2,3})/); // Note that this currently ignores caption formatting directives that are optionally on the end of this line - fine for non-captions VTT
  5722. if (matchTimes) {
  5723. result.startTime = Number(matchTimes[1] || 0) * 60 * 60 + Number(matchTimes[2]) * 60 + Number(matchTimes[3]) + Number("0.".concat(matchTimes[4]));
  5724. result.endTime = Number(matchTimes[6] || 0) * 60 * 60 + Number(matchTimes[7]) * 60 + Number(matchTimes[8]) + Number("0.".concat(matchTimes[9]));
  5725. }
  5726. } else if (!is$1.empty(line.trim()) && is$1.empty(result.text)) {
  5727. // If we already have the startTime, then we're definitely up to the text line(s)
  5728. var lineSplit = line.trim().split('#xywh=');
  5729. var _lineSplit = _slicedToArray(lineSplit, 1);
  5730. result.text = _lineSplit[0];
  5731. // If there's content in lineSplit[1], then we have sprites. If not, then it's just one frame per image
  5732. if (lineSplit[1]) {
  5733. var _lineSplit$1$split = lineSplit[1].split(',');
  5734. var _lineSplit$1$split2 = _slicedToArray(_lineSplit$1$split, 4);
  5735. result.x = _lineSplit$1$split2[0];
  5736. result.y = _lineSplit$1$split2[1];
  5737. result.w = _lineSplit$1$split2[2];
  5738. result.h = _lineSplit$1$split2[3];
  5739. }
  5740. }
  5741. });
  5742. if (result.text) {
  5743. processedList.push(result);
  5744. }
  5745. });
  5746. return processedList;
  5747. };
  5748. /**
  5749. * Preview thumbnails for seek hover and scrubbing
  5750. * Seeking: Hover over the seek bar (desktop only): shows a small preview container above the seek bar
  5751. * Scrubbing: Click and drag the seek bar (desktop and mobile): shows the preview image over the entire video, as if the video is scrubbing at very high speed
  5752. *
  5753. * Notes:
  5754. * - Thumbs are set via JS settings on Plyr init, not HTML5 'track' property. Using the track property would be a bit gross, because it doesn't support custom 'kinds'. kind=metadata might be used for something else, and we want to allow multiple thumbnails tracks. Tracks must have a unique combination of 'kind' and 'label'. We would have to do something like kind=metadata,label=thumbnails1 / kind=metadata,label=thumbnails2. Square peg, round hole
  5755. * - VTT info: the image URL is relative to the VTT, not the current document. But if the url starts with a slash, it will naturally be relative to the current domain. https://support.jwplayer.com/articles/how-to-add-preview-thumbnails
  5756. * - This implementation uses multiple separate img elements. Other implementations use background-image on one element. This would be nice and simple, but Firefox and Safari have flickering issues with replacing backgrounds of larger images. It seems that YouTube perhaps only avoids this because they don't have the option for high-res previews (even the fullscreen ones, when mousedown/seeking). Images appear over the top of each other, and previous ones are discarded once the new ones have been rendered
  5757. */
  5758. var fitRatio = function fitRatio(ratio, outer) {
  5759. var targetRatio = outer.width / outer.height;
  5760. var result = {};
  5761. if (ratio > targetRatio) {
  5762. result.width = outer.width;
  5763. result.height = 1 / ratio * outer.width;
  5764. } else {
  5765. result.height = outer.height;
  5766. result.width = ratio * outer.height;
  5767. }
  5768. return result;
  5769. };
  5770. var PreviewThumbnails = /*#__PURE__*/function () {
  5771. /**
  5772. * PreviewThumbnails constructor.
  5773. * @param {Plyr} player
  5774. * @return {PreviewThumbnails}
  5775. */
  5776. function PreviewThumbnails(player) {
  5777. _classCallCheck(this, PreviewThumbnails);
  5778. this.player = player;
  5779. this.thumbnails = [];
  5780. this.loaded = false;
  5781. this.lastMouseMoveTime = Date.now();
  5782. this.mouseDown = false;
  5783. this.loadedImages = [];
  5784. this.elements = {
  5785. thumb: {},
  5786. scrubbing: {}
  5787. };
  5788. this.load();
  5789. }
  5790. _createClass(PreviewThumbnails, [{
  5791. key: "load",
  5792. value: function load() {
  5793. var _this = this;
  5794. // Toggle the regular seek tooltip
  5795. if (this.player.elements.display.seekTooltip) {
  5796. this.player.elements.display.seekTooltip.hidden = this.enabled;
  5797. }
  5798. if (!this.enabled) {
  5799. return;
  5800. }
  5801. this.getThumbnails().then(function () {
  5802. if (!_this.enabled) {
  5803. return;
  5804. } // Render DOM elements
  5805. _this.render(); // Check to see if thumb container size was specified manually in CSS
  5806. _this.determineContainerAutoSizing();
  5807. _this.loaded = true;
  5808. });
  5809. } // Download VTT files and parse them
  5810. }, {
  5811. key: "getThumbnails",
  5812. value: function getThumbnails() {
  5813. var _this2 = this;
  5814. return new Promise(function (resolve) {
  5815. var src = _this2.player.config.previewThumbnails.src;
  5816. if (is$1.empty(src)) {
  5817. throw new Error('Missing previewThumbnails.src config attribute');
  5818. } // Resolve promise
  5819. var sortAndResolve = function sortAndResolve() {
  5820. // Sort smallest to biggest (e.g., [120p, 480p, 1080p])
  5821. _this2.thumbnails.sort(function (x, y) {
  5822. return x.height - y.height;
  5823. });
  5824. _this2.player.debug.log('Preview thumbnails', _this2.thumbnails);
  5825. resolve();
  5826. }; // Via callback()
  5827. if (is$1.function(src)) {
  5828. src(function (thumbnails) {
  5829. _this2.thumbnails = thumbnails;
  5830. sortAndResolve();
  5831. });
  5832. } // VTT urls
  5833. else {
  5834. // If string, convert into single-element list
  5835. var urls = is$1.string(src) ? [src] : src; // Loop through each src URL. Download and process the VTT file, storing the resulting data in this.thumbnails
  5836. var promises = urls.map(function (u) {
  5837. return _this2.getThumbnail(u);
  5838. }); // Resolve
  5839. Promise.all(promises).then(sortAndResolve);
  5840. }
  5841. });
  5842. } // Process individual VTT file
  5843. }, {
  5844. key: "getThumbnail",
  5845. value: function getThumbnail(url) {
  5846. var _this3 = this;
  5847. return new Promise(function (resolve) {
  5848. fetch(url).then(function (response) {
  5849. var thumbnail = {
  5850. frames: parseVtt(response),
  5851. height: null,
  5852. urlPrefix: ''
  5853. }; // If the URLs don't start with '/', then we need to set their relative path to be the location of the VTT file
  5854. // If the URLs do start with '/', then they obviously don't need a prefix, so it will remain blank
  5855. // If the thumbnail URLs start with with none of '/', 'http://' or 'https://', then we need to set their relative path to be the location of the VTT file
  5856. if (!thumbnail.frames[0].text.startsWith('/') && !thumbnail.frames[0].text.startsWith('http://') && !thumbnail.frames[0].text.startsWith('https://')) {
  5857. thumbnail.urlPrefix = url.substring(0, url.lastIndexOf('/') + 1);
  5858. } // Download the first frame, so that we can determine/set the height of this thumbnailsDef
  5859. var tempImage = new Image();
  5860. tempImage.onload = function () {
  5861. thumbnail.height = tempImage.naturalHeight;
  5862. thumbnail.width = tempImage.naturalWidth;
  5863. _this3.thumbnails.push(thumbnail);
  5864. resolve();
  5865. };
  5866. tempImage.src = thumbnail.urlPrefix + thumbnail.frames[0].text;
  5867. });
  5868. });
  5869. }
  5870. }, {
  5871. key: "startMove",
  5872. value: function startMove(event) {
  5873. if (!this.loaded) {
  5874. return;
  5875. }
  5876. if (!is$1.event(event) || !['touchmove', 'mousemove'].includes(event.type)) {
  5877. return;
  5878. } // Wait until media has a duration
  5879. if (!this.player.media.duration) {
  5880. return;
  5881. }
  5882. if (event.type === 'touchmove') {
  5883. // Calculate seek hover position as approx video seconds
  5884. this.seekTime = this.player.media.duration * (this.player.elements.inputs.seek.value / 100);
  5885. } else {
  5886. // Calculate seek hover position as approx video seconds
  5887. var clientRect = this.player.elements.progress.getBoundingClientRect();
  5888. var percentage = 100 / clientRect.width * (event.pageX - clientRect.left);
  5889. this.seekTime = this.player.media.duration * (percentage / 100);
  5890. if (this.seekTime < 0) {
  5891. // The mousemove fires for 10+px out to the left
  5892. this.seekTime = 0;
  5893. }
  5894. if (this.seekTime > this.player.media.duration - 1) {
  5895. // Took 1 second off the duration for safety, because different players can disagree on the real duration of a video
  5896. this.seekTime = this.player.media.duration - 1;
  5897. }
  5898. this.mousePosX = event.pageX; // Set time text inside image container
  5899. this.elements.thumb.time.innerText = formatTime(this.seekTime);
  5900. } // Download and show image
  5901. this.showImageAtCurrentTime();
  5902. }
  5903. }, {
  5904. key: "endMove",
  5905. value: function endMove() {
  5906. this.toggleThumbContainer(false, true);
  5907. }
  5908. }, {
  5909. key: "startScrubbing",
  5910. value: function startScrubbing(event) {
  5911. // Only act on left mouse button (0), or touch device (event.button does not exist or is false)
  5912. if (is$1.nullOrUndefined(event.button) || event.button === false || event.button === 0) {
  5913. this.mouseDown = true; // Wait until media has a duration
  5914. if (this.player.media.duration) {
  5915. this.toggleScrubbingContainer(true);
  5916. this.toggleThumbContainer(false, true); // Download and show image
  5917. this.showImageAtCurrentTime();
  5918. }
  5919. }
  5920. }
  5921. }, {
  5922. key: "endScrubbing",
  5923. value: function endScrubbing() {
  5924. var _this4 = this;
  5925. this.mouseDown = false; // Hide scrubbing preview. But wait until the video has successfully seeked before hiding the scrubbing preview
  5926. if (Math.ceil(this.lastTime) === Math.ceil(this.player.media.currentTime)) {
  5927. // The video was already seeked/loaded at the chosen time - hide immediately
  5928. this.toggleScrubbingContainer(false);
  5929. } else {
  5930. // The video hasn't seeked yet. Wait for that
  5931. once.call(this.player, this.player.media, 'timeupdate', function () {
  5932. // Re-check mousedown - we might have already started scrubbing again
  5933. if (!_this4.mouseDown) {
  5934. _this4.toggleScrubbingContainer(false);
  5935. }
  5936. });
  5937. }
  5938. }
  5939. /**
  5940. * Setup hooks for Plyr and window events
  5941. */
  5942. }, {
  5943. key: "listeners",
  5944. value: function listeners() {
  5945. var _this5 = this;
  5946. // Hide thumbnail preview - on mouse click, mouse leave (in listeners.js for now), and video play/seek. All four are required, e.g., for buffering
  5947. this.player.on('play', function () {
  5948. _this5.toggleThumbContainer(false, true);
  5949. });
  5950. this.player.on('seeked', function () {
  5951. _this5.toggleThumbContainer(false);
  5952. });
  5953. this.player.on('timeupdate', function () {
  5954. _this5.lastTime = _this5.player.media.currentTime;
  5955. });
  5956. }
  5957. /**
  5958. * Create HTML elements for image containers
  5959. */
  5960. }, {
  5961. key: "render",
  5962. value: function render() {
  5963. // Create HTML element: plyr__preview-thumbnail-container
  5964. this.elements.thumb.container = createElement('div', {
  5965. class: this.player.config.classNames.previewThumbnails.thumbContainer
  5966. }); // Wrapper for the image for styling
  5967. this.elements.thumb.imageContainer = createElement('div', {
  5968. class: this.player.config.classNames.previewThumbnails.imageContainer
  5969. });
  5970. this.elements.thumb.container.appendChild(this.elements.thumb.imageContainer); // Create HTML element, parent+span: time text (e.g., 01:32:00)
  5971. var timeContainer = createElement('div', {
  5972. class: this.player.config.classNames.previewThumbnails.timeContainer
  5973. });
  5974. this.elements.thumb.time = createElement('span', {}, '00:00');
  5975. timeContainer.appendChild(this.elements.thumb.time);
  5976. this.elements.thumb.container.appendChild(timeContainer); // Inject the whole thumb
  5977. if (is$1.element(this.player.elements.progress)) {
  5978. this.player.elements.progress.appendChild(this.elements.thumb.container);
  5979. } // Create HTML element: plyr__preview-scrubbing-container
  5980. this.elements.scrubbing.container = createElement('div', {
  5981. class: this.player.config.classNames.previewThumbnails.scrubbingContainer
  5982. });
  5983. this.player.elements.wrapper.appendChild(this.elements.scrubbing.container);
  5984. }
  5985. }, {
  5986. key: "destroy",
  5987. value: function destroy() {
  5988. if (this.elements.thumb.container) {
  5989. this.elements.thumb.container.remove();
  5990. }
  5991. if (this.elements.scrubbing.container) {
  5992. this.elements.scrubbing.container.remove();
  5993. }
  5994. }
  5995. }, {
  5996. key: "showImageAtCurrentTime",
  5997. value: function showImageAtCurrentTime() {
  5998. var _this6 = this;
  5999. if (this.mouseDown) {
  6000. this.setScrubbingContainerSize();
  6001. } else {
  6002. this.setThumbContainerSizeAndPos();
  6003. } // Find the desired thumbnail index
  6004. // TODO: Handle a video longer than the thumbs where thumbNum is null
  6005. var thumbNum = this.thumbnails[0].frames.findIndex(function (frame) {
  6006. return _this6.seekTime >= frame.startTime && _this6.seekTime <= frame.endTime;
  6007. });
  6008. var hasThumb = thumbNum >= 0;
  6009. var qualityIndex = 0; // Show the thumb container if we're not scrubbing
  6010. if (!this.mouseDown) {
  6011. this.toggleThumbContainer(hasThumb);
  6012. } // No matching thumb found
  6013. if (!hasThumb) {
  6014. return;
  6015. } // Check to see if we've already downloaded higher quality versions of this image
  6016. this.thumbnails.forEach(function (thumbnail, index) {
  6017. if (_this6.loadedImages.includes(thumbnail.frames[thumbNum].text)) {
  6018. qualityIndex = index;
  6019. }
  6020. }); // Only proceed if either thumbnum or thumbfilename has changed
  6021. if (thumbNum !== this.showingThumb) {
  6022. this.showingThumb = thumbNum;
  6023. this.loadImage(qualityIndex);
  6024. }
  6025. } // Show the image that's currently specified in this.showingThumb
  6026. }, {
  6027. key: "loadImage",
  6028. value: function loadImage() {
  6029. var _this7 = this;
  6030. var qualityIndex = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  6031. var thumbNum = this.showingThumb;
  6032. var thumbnail = this.thumbnails[qualityIndex];
  6033. var urlPrefix = thumbnail.urlPrefix;
  6034. var frame = thumbnail.frames[thumbNum];
  6035. var thumbFilename = thumbnail.frames[thumbNum].text;
  6036. var thumbUrl = urlPrefix + thumbFilename;
  6037. if (!this.currentImageElement || this.currentImageElement.dataset.filename !== thumbFilename) {
  6038. // If we're already loading a previous image, remove its onload handler - we don't want it to load after this one
  6039. // Only do this if not using sprites. Without sprites we really want to show as many images as possible, as a best-effort
  6040. if (this.loadingImage && this.usingSprites) {
  6041. this.loadingImage.onload = null;
  6042. } // We're building and adding a new image. In other implementations of similar functionality (YouTube), background image
  6043. // is instead used. But this causes issues with larger images in Firefox and Safari - switching between background
  6044. // images causes a flicker. Putting a new image over the top does not
  6045. var previewImage = new Image();
  6046. previewImage.src = thumbUrl;
  6047. previewImage.dataset.index = thumbNum;
  6048. previewImage.dataset.filename = thumbFilename;
  6049. this.showingThumbFilename = thumbFilename;
  6050. this.player.debug.log("Loading image: ".concat(thumbUrl)); // For some reason, passing the named function directly causes it to execute immediately. So I've wrapped it in an anonymous function...
  6051. previewImage.onload = function () {
  6052. return _this7.showImage(previewImage, frame, qualityIndex, thumbNum, thumbFilename, true);
  6053. };
  6054. this.loadingImage = previewImage;
  6055. this.removeOldImages(previewImage);
  6056. } else {
  6057. // Update the existing image
  6058. this.showImage(this.currentImageElement, frame, qualityIndex, thumbNum, thumbFilename, false);
  6059. this.currentImageElement.dataset.index = thumbNum;
  6060. this.removeOldImages(this.currentImageElement);
  6061. }
  6062. }
  6063. }, {
  6064. key: "showImage",
  6065. value: function showImage(previewImage, frame, qualityIndex, thumbNum, thumbFilename) {
  6066. var newImage = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : true;
  6067. this.player.debug.log("Showing thumb: ".concat(thumbFilename, ". num: ").concat(thumbNum, ". qual: ").concat(qualityIndex, ". newimg: ").concat(newImage));
  6068. this.setImageSizeAndOffset(previewImage, frame);
  6069. if (newImage) {
  6070. this.currentImageContainer.appendChild(previewImage);
  6071. this.currentImageElement = previewImage;
  6072. if (!this.loadedImages.includes(thumbFilename)) {
  6073. this.loadedImages.push(thumbFilename);
  6074. }
  6075. } // Preload images before and after the current one
  6076. // Show higher quality of the same frame
  6077. // Each step here has a short time delay, and only continues if still hovering/seeking the same spot. This is to protect slow connections from overloading
  6078. this.preloadNearby(thumbNum, true).then(this.preloadNearby(thumbNum, false)).then(this.getHigherQuality(qualityIndex, previewImage, frame, thumbFilename));
  6079. } // Remove all preview images that aren't the designated current image
  6080. }, {
  6081. key: "removeOldImages",
  6082. value: function removeOldImages(currentImage) {
  6083. var _this8 = this;
  6084. // Get a list of all images, convert it from a DOM list to an array
  6085. Array.from(this.currentImageContainer.children).forEach(function (image) {
  6086. if (image.tagName.toLowerCase() !== 'img') {
  6087. return;
  6088. }
  6089. var removeDelay = _this8.usingSprites ? 500 : 1000;
  6090. if (image.dataset.index !== currentImage.dataset.index && !image.dataset.deleting) {
  6091. // Wait 200ms, as the new image can take some time to show on certain browsers (even though it was downloaded before showing). This will prevent flicker, and show some generosity towards slower clients
  6092. // First set attribute 'deleting' to prevent multi-handling of this on repeat firing of this function
  6093. // eslint-disable-next-line no-param-reassign
  6094. image.dataset.deleting = true; // This has to be set before the timeout - to prevent issues switching between hover and scrub
  6095. var currentImageContainer = _this8.currentImageContainer;
  6096. setTimeout(function () {
  6097. currentImageContainer.removeChild(image);
  6098. _this8.player.debug.log("Removing thumb: ".concat(image.dataset.filename));
  6099. }, removeDelay);
  6100. }
  6101. });
  6102. } // Preload images before and after the current one. Only if the user is still hovering/seeking the same frame
  6103. // This will only preload the lowest quality
  6104. }, {
  6105. key: "preloadNearby",
  6106. value: function preloadNearby(thumbNum) {
  6107. var _this9 = this;
  6108. var forward = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  6109. return new Promise(function (resolve) {
  6110. setTimeout(function () {
  6111. var oldThumbFilename = _this9.thumbnails[0].frames[thumbNum].text;
  6112. if (_this9.showingThumbFilename === oldThumbFilename) {
  6113. // Find the nearest thumbs with different filenames. Sometimes it'll be the next index, but in the case of sprites, it might be 100+ away
  6114. var thumbnailsClone;
  6115. if (forward) {
  6116. thumbnailsClone = _this9.thumbnails[0].frames.slice(thumbNum);
  6117. } else {
  6118. thumbnailsClone = _this9.thumbnails[0].frames.slice(0, thumbNum).reverse();
  6119. }
  6120. var foundOne = false;
  6121. thumbnailsClone.forEach(function (frame) {
  6122. var newThumbFilename = frame.text;
  6123. if (newThumbFilename !== oldThumbFilename) {
  6124. // Found one with a different filename. Make sure it hasn't already been loaded on this page visit
  6125. if (!_this9.loadedImages.includes(newThumbFilename)) {
  6126. foundOne = true;
  6127. _this9.player.debug.log("Preloading thumb filename: ".concat(newThumbFilename));
  6128. var urlPrefix = _this9.thumbnails[0].urlPrefix;
  6129. var thumbURL = urlPrefix + newThumbFilename;
  6130. var previewImage = new Image();
  6131. previewImage.src = thumbURL;
  6132. previewImage.onload = function () {
  6133. _this9.player.debug.log("Preloaded thumb filename: ".concat(newThumbFilename));
  6134. if (!_this9.loadedImages.includes(newThumbFilename)) _this9.loadedImages.push(newThumbFilename); // We don't resolve until the thumb is loaded
  6135. resolve();
  6136. };
  6137. }
  6138. }
  6139. }); // If there are none to preload then we want to resolve immediately
  6140. if (!foundOne) {
  6141. resolve();
  6142. }
  6143. }
  6144. }, 300);
  6145. });
  6146. } // If user has been hovering current image for half a second, look for a higher quality one
  6147. }, {
  6148. key: "getHigherQuality",
  6149. value: function getHigherQuality(currentQualityIndex, previewImage, frame, thumbFilename) {
  6150. var _this10 = this;
  6151. if (currentQualityIndex < this.thumbnails.length - 1) {
  6152. // Only use the higher quality version if it's going to look any better - if the current thumb is of a lower pixel density than the thumbnail container
  6153. var previewImageHeight = previewImage.naturalHeight;
  6154. if (this.usingSprites) {
  6155. previewImageHeight = frame.h;
  6156. }
  6157. if (previewImageHeight < this.thumbContainerHeight) {
  6158. // Recurse back to the loadImage function - show a higher quality one, but only if the viewer is on this frame for a while
  6159. setTimeout(function () {
  6160. // Make sure the mouse hasn't already moved on and started hovering at another image
  6161. if (_this10.showingThumbFilename === thumbFilename) {
  6162. _this10.player.debug.log("Showing higher quality thumb for: ".concat(thumbFilename));
  6163. _this10.loadImage(currentQualityIndex + 1);
  6164. }
  6165. }, 300);
  6166. }
  6167. }
  6168. }
  6169. }, {
  6170. key: "toggleThumbContainer",
  6171. value: function toggleThumbContainer() {
  6172. var toggle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  6173. var clearShowing = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  6174. var className = this.player.config.classNames.previewThumbnails.thumbContainerShown;
  6175. this.elements.thumb.container.classList.toggle(className, toggle);
  6176. if (!toggle && clearShowing) {
  6177. this.showingThumb = null;
  6178. this.showingThumbFilename = null;
  6179. }
  6180. }
  6181. }, {
  6182. key: "toggleScrubbingContainer",
  6183. value: function toggleScrubbingContainer() {
  6184. var toggle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  6185. var className = this.player.config.classNames.previewThumbnails.scrubbingContainerShown;
  6186. this.elements.scrubbing.container.classList.toggle(className, toggle);
  6187. if (!toggle) {
  6188. this.showingThumb = null;
  6189. this.showingThumbFilename = null;
  6190. }
  6191. }
  6192. }, {
  6193. key: "determineContainerAutoSizing",
  6194. value: function determineContainerAutoSizing() {
  6195. if (this.elements.thumb.imageContainer.clientHeight > 20 || this.elements.thumb.imageContainer.clientWidth > 20) {
  6196. // This will prevent auto sizing in this.setThumbContainerSizeAndPos()
  6197. this.sizeSpecifiedInCSS = true;
  6198. }
  6199. } // Set the size to be about a quarter of the size of video. Unless option dynamicSize === false, in which case it needs to be set in CSS
  6200. }, {
  6201. key: "setThumbContainerSizeAndPos",
  6202. value: function setThumbContainerSizeAndPos() {
  6203. if (!this.sizeSpecifiedInCSS) {
  6204. var thumbWidth = Math.floor(this.thumbContainerHeight * this.thumbAspectRatio);
  6205. this.elements.thumb.imageContainer.style.height = "".concat(this.thumbContainerHeight, "px");
  6206. this.elements.thumb.imageContainer.style.width = "".concat(thumbWidth, "px");
  6207. } else if (this.elements.thumb.imageContainer.clientHeight > 20 && this.elements.thumb.imageContainer.clientWidth < 20) {
  6208. var _thumbWidth = Math.floor(this.elements.thumb.imageContainer.clientHeight * this.thumbAspectRatio);
  6209. this.elements.thumb.imageContainer.style.width = "".concat(_thumbWidth, "px");
  6210. } else if (this.elements.thumb.imageContainer.clientHeight < 20 && this.elements.thumb.imageContainer.clientWidth > 20) {
  6211. var thumbHeight = Math.floor(this.elements.thumb.imageContainer.clientWidth / this.thumbAspectRatio);
  6212. this.elements.thumb.imageContainer.style.height = "".concat(thumbHeight, "px");
  6213. }
  6214. this.setThumbContainerPos();
  6215. }
  6216. }, {
  6217. key: "setThumbContainerPos",
  6218. value: function setThumbContainerPos() {
  6219. var seekbarRect = this.player.elements.progress.getBoundingClientRect();
  6220. var plyrRect = this.player.elements.container.getBoundingClientRect();
  6221. var container = this.elements.thumb.container; // Find the lowest and highest desired left-position, so we don't slide out the side of the video container
  6222. var minVal = plyrRect.left - seekbarRect.left + 10;
  6223. var maxVal = plyrRect.right - seekbarRect.left - container.clientWidth - 10; // Set preview container position to: mousepos, minus seekbar.left, minus half of previewContainer.clientWidth
  6224. var previewPos = this.mousePosX - seekbarRect.left - container.clientWidth / 2;
  6225. if (previewPos < minVal) {
  6226. previewPos = minVal;
  6227. }
  6228. if (previewPos > maxVal) {
  6229. previewPos = maxVal;
  6230. }
  6231. container.style.left = "".concat(previewPos, "px");
  6232. } // Can't use 100% width, in case the video is a different aspect ratio to the video container
  6233. }, {
  6234. key: "setScrubbingContainerSize",
  6235. value: function setScrubbingContainerSize() {
  6236. var _fitRatio = fitRatio(this.thumbAspectRatio, {
  6237. width: this.player.media.clientWidth,
  6238. height: this.player.media.clientHeight
  6239. }),
  6240. width = _fitRatio.width,
  6241. height = _fitRatio.height;
  6242. this.elements.scrubbing.container.style.width = "".concat(width, "px");
  6243. this.elements.scrubbing.container.style.height = "".concat(height, "px");
  6244. } // Sprites need to be offset to the correct location
  6245. }, {
  6246. key: "setImageSizeAndOffset",
  6247. value: function setImageSizeAndOffset(previewImage, frame) {
  6248. if (!this.usingSprites) {
  6249. return;
  6250. } // Find difference between height and preview container height
  6251. var multiplier = this.thumbContainerHeight / frame.h; // eslint-disable-next-line no-param-reassign
  6252. previewImage.style.height = "".concat(previewImage.naturalHeight * multiplier, "px"); // eslint-disable-next-line no-param-reassign
  6253. previewImage.style.width = "".concat(previewImage.naturalWidth * multiplier, "px"); // eslint-disable-next-line no-param-reassign
  6254. previewImage.style.left = "-".concat(frame.x * multiplier, "px"); // eslint-disable-next-line no-param-reassign
  6255. previewImage.style.top = "-".concat(frame.y * multiplier, "px");
  6256. }
  6257. }, {
  6258. key: "enabled",
  6259. get: function get() {
  6260. return this.player.isHTML5 && this.player.isVideo && this.player.config.previewThumbnails.enabled;
  6261. }
  6262. }, {
  6263. key: "currentImageContainer",
  6264. get: function get() {
  6265. if (this.mouseDown) {
  6266. return this.elements.scrubbing.container;
  6267. }
  6268. return this.elements.thumb.imageContainer;
  6269. }
  6270. }, {
  6271. key: "usingSprites",
  6272. get: function get() {
  6273. return Object.keys(this.thumbnails[0].frames[0]).includes('w');
  6274. }
  6275. }, {
  6276. key: "thumbAspectRatio",
  6277. get: function get() {
  6278. if (this.usingSprites) {
  6279. return this.thumbnails[0].frames[0].w / this.thumbnails[0].frames[0].h;
  6280. }
  6281. return this.thumbnails[0].width / this.thumbnails[0].height;
  6282. }
  6283. }, {
  6284. key: "thumbContainerHeight",
  6285. get: function get() {
  6286. if (this.mouseDown) {
  6287. var _fitRatio2 = fitRatio(this.thumbAspectRatio, {
  6288. width: this.player.media.clientWidth,
  6289. height: this.player.media.clientHeight
  6290. }),
  6291. height = _fitRatio2.height;
  6292. return height;
  6293. } // If css is used this needs to return the css height for sprites to work (see setImageSizeAndOffset)
  6294. if (this.sizeSpecifiedInCSS) {
  6295. return this.elements.thumb.imageContainer.clientHeight;
  6296. }
  6297. return Math.floor(this.player.media.clientWidth / this.thumbAspectRatio / 4);
  6298. }
  6299. }, {
  6300. key: "currentImageElement",
  6301. get: function get() {
  6302. if (this.mouseDown) {
  6303. return this.currentScrubbingImageElement;
  6304. }
  6305. return this.currentThumbnailImageElement;
  6306. },
  6307. set: function set(element) {
  6308. if (this.mouseDown) {
  6309. this.currentScrubbingImageElement = element;
  6310. } else {
  6311. this.currentThumbnailImageElement = element;
  6312. }
  6313. }
  6314. }]);
  6315. return PreviewThumbnails;
  6316. }();
  6317. var source = {
  6318. // Add elements to HTML5 media (source, tracks, etc)
  6319. insertElements: function insertElements(type, attributes) {
  6320. var _this = this;
  6321. if (is$1.string(attributes)) {
  6322. insertElement(type, this.media, {
  6323. src: attributes
  6324. });
  6325. } else if (is$1.array(attributes)) {
  6326. attributes.forEach(function (attribute) {
  6327. insertElement(type, _this.media, attribute);
  6328. });
  6329. }
  6330. },
  6331. // Update source
  6332. // Sources are not checked for support so be careful
  6333. change: function change(input) {
  6334. var _this2 = this;
  6335. if (!getDeep(input, 'sources.length')) {
  6336. this.debug.warn('Invalid source format');
  6337. return;
  6338. } // Cancel current network requests
  6339. html5.cancelRequests.call(this); // Destroy instance and re-setup
  6340. this.destroy.call(this, function () {
  6341. // Reset quality options
  6342. _this2.options.quality = []; // Remove elements
  6343. removeElement(_this2.media);
  6344. _this2.media = null; // Reset class name
  6345. if (is$1.element(_this2.elements.container)) {
  6346. _this2.elements.container.removeAttribute('class');
  6347. } // Set the type and provider
  6348. var sources = input.sources,
  6349. type = input.type;
  6350. var _sources = _slicedToArray(sources, 1),
  6351. _sources$ = _sources[0],
  6352. _sources$$provider = _sources$.provider,
  6353. provider = _sources$$provider === void 0 ? providers.html5 : _sources$$provider,
  6354. src = _sources$.src;
  6355. var tagName = provider === 'html5' ? type : 'div';
  6356. var attributes = provider === 'html5' ? {} : {
  6357. src: src
  6358. };
  6359. Object.assign(_this2, {
  6360. provider: provider,
  6361. type: type,
  6362. // Check for support
  6363. supported: support.check(type, provider, _this2.config.playsinline),
  6364. // Create new element
  6365. media: createElement(tagName, attributes)
  6366. }); // Inject the new element
  6367. _this2.elements.container.appendChild(_this2.media); // Autoplay the new source?
  6368. if (is$1.boolean(input.autoplay)) {
  6369. _this2.config.autoplay = input.autoplay;
  6370. } // Set attributes for audio and video
  6371. if (_this2.isHTML5) {
  6372. if (_this2.config.crossorigin) {
  6373. _this2.media.setAttribute('crossorigin', '');
  6374. }
  6375. if (_this2.config.autoplay) {
  6376. _this2.media.setAttribute('autoplay', '');
  6377. }
  6378. if (!is$1.empty(input.poster)) {
  6379. _this2.poster = input.poster;
  6380. }
  6381. if (_this2.config.loop.active) {
  6382. _this2.media.setAttribute('loop', '');
  6383. }
  6384. if (_this2.config.muted) {
  6385. _this2.media.setAttribute('muted', '');
  6386. }
  6387. if (_this2.config.playsinline) {
  6388. _this2.media.setAttribute('playsinline', '');
  6389. }
  6390. } // Restore class hook
  6391. ui.addStyleHook.call(_this2); // Set new sources for html5
  6392. if (_this2.isHTML5) {
  6393. source.insertElements.call(_this2, 'source', sources);
  6394. } // Set video title
  6395. _this2.config.title = input.title; // Set up from scratch
  6396. media.setup.call(_this2); // HTML5 stuff
  6397. if (_this2.isHTML5) {
  6398. // Setup captions
  6399. if (Object.keys(input).includes('tracks')) {
  6400. source.insertElements.call(_this2, 'track', input.tracks);
  6401. }
  6402. } // If HTML5 or embed but not fully supported, setupInterface and call ready now
  6403. if (_this2.isHTML5 || _this2.isEmbed && !_this2.supported.ui) {
  6404. // Setup interface
  6405. ui.build.call(_this2);
  6406. } // Load HTML5 sources
  6407. if (_this2.isHTML5) {
  6408. _this2.media.load();
  6409. } // Update previewThumbnails config & reload plugin
  6410. if (!is$1.empty(input.previewThumbnails)) {
  6411. Object.assign(_this2.config.previewThumbnails, input.previewThumbnails); // Cleanup previewThumbnails plugin if it was loaded
  6412. if (_this2.previewThumbnails && _this2.previewThumbnails.loaded) {
  6413. _this2.previewThumbnails.destroy();
  6414. _this2.previewThumbnails = null;
  6415. } // Create new instance if it is still enabled
  6416. if (_this2.config.previewThumbnails.enabled) {
  6417. _this2.previewThumbnails = new PreviewThumbnails(_this2);
  6418. }
  6419. } // Update the fullscreen support
  6420. _this2.fullscreen.update();
  6421. }, true);
  6422. }
  6423. };
  6424. /**
  6425. * Returns a number whose value is limited to the given range.
  6426. *
  6427. * Example: limit the output of this computation to between 0 and 255
  6428. * (x * 255).clamp(0, 255)
  6429. *
  6430. * @param {Number} input
  6431. * @param {Number} min The lower boundary of the output range
  6432. * @param {Number} max The upper boundary of the output range
  6433. * @returns A number in the range [min, max]
  6434. * @type Number
  6435. */
  6436. function clamp() {
  6437. var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  6438. var min = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  6439. var max = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 255;
  6440. return Math.min(Math.max(input, min), max);
  6441. }
  6442. // TODO: Use a WeakMap for private globals
  6443. // const globals = new WeakMap();
  6444. // Plyr instance
  6445. var Plyr = /*#__PURE__*/function () {
  6446. function Plyr(target, options) {
  6447. var _this = this;
  6448. _classCallCheck(this, Plyr);
  6449. this.timers = {}; // State
  6450. this.ready = false;
  6451. this.loading = false;
  6452. this.failed = false; // Touch device
  6453. this.touch = support.touch; // Set the media element
  6454. this.media = target; // String selector passed
  6455. if (is$1.string(this.media)) {
  6456. this.media = document.querySelectorAll(this.media);
  6457. } // jQuery, NodeList or Array passed, use first element
  6458. if (window.jQuery && this.media instanceof jQuery || is$1.nodeList(this.media) || is$1.array(this.media)) {
  6459. // eslint-disable-next-line
  6460. this.media = this.media[0];
  6461. } // Set config
  6462. this.config = extend({}, defaults$1, Plyr.defaults, options || {}, function () {
  6463. try {
  6464. return JSON.parse(_this.media.getAttribute('data-plyr-config'));
  6465. } catch (e) {
  6466. return {};
  6467. }
  6468. }()); // Elements cache
  6469. this.elements = {
  6470. container: null,
  6471. fullscreen: null,
  6472. captions: null,
  6473. buttons: {},
  6474. display: {},
  6475. progress: {},
  6476. inputs: {},
  6477. settings: {
  6478. popup: null,
  6479. menu: null,
  6480. panels: {},
  6481. buttons: {}
  6482. }
  6483. }; // Captions
  6484. this.captions = {
  6485. active: null,
  6486. currentTrack: -1,
  6487. meta: new WeakMap()
  6488. }; // Fullscreen
  6489. this.fullscreen = {
  6490. active: false
  6491. }; // Options
  6492. this.options = {
  6493. speed: [],
  6494. quality: []
  6495. }; // Debugging
  6496. // TODO: move to globals
  6497. this.debug = new Console(this.config.debug); // Log config options and support
  6498. this.debug.log('Config', this.config);
  6499. this.debug.log('Support', support); // We need an element to setup
  6500. if (is$1.nullOrUndefined(this.media) || !is$1.element(this.media)) {
  6501. this.debug.error('Setup failed: no suitable element passed');
  6502. return;
  6503. } // Bail if the element is initialized
  6504. if (this.media.plyr) {
  6505. this.debug.warn('Target already setup');
  6506. return;
  6507. } // Bail if not enabled
  6508. if (!this.config.enabled) {
  6509. this.debug.error('Setup failed: disabled by config');
  6510. return;
  6511. } // Bail if disabled or no basic support
  6512. // You may want to disable certain UAs etc
  6513. if (!support.check().api) {
  6514. this.debug.error('Setup failed: no support');
  6515. return;
  6516. } // Cache original element state for .destroy()
  6517. var clone = this.media.cloneNode(true);
  6518. clone.autoplay = false;
  6519. this.elements.original = clone; // Set media type based on tag or data attribute
  6520. // Supported: video, audio, vimeo, youtube
  6521. var type = this.media.tagName.toLowerCase(); // Embed properties
  6522. var iframe = null;
  6523. var url = null; // Different setup based on type
  6524. switch (type) {
  6525. case 'div':
  6526. // Find the frame
  6527. iframe = this.media.querySelector('iframe'); // <iframe> type
  6528. if (is$1.element(iframe)) {
  6529. // Detect provider
  6530. url = parseUrl(iframe.getAttribute('src'));
  6531. this.provider = getProviderByUrl(url.toString()); // Rework elements
  6532. this.elements.container = this.media;
  6533. this.media = iframe; // Reset classname
  6534. this.elements.container.className = ''; // Get attributes from URL and set config
  6535. if (url.search.length) {
  6536. var truthy = ['1', 'true'];
  6537. if (truthy.includes(url.searchParams.get('autoplay'))) {
  6538. this.config.autoplay = true;
  6539. }
  6540. if (truthy.includes(url.searchParams.get('loop'))) {
  6541. this.config.loop.active = true;
  6542. } // TODO: replace fullscreen.iosNative with this playsinline config option
  6543. // YouTube requires the playsinline in the URL
  6544. if (this.isYouTube) {
  6545. this.config.playsinline = truthy.includes(url.searchParams.get('playsinline'));
  6546. this.config.youtube.hl = url.searchParams.get('hl'); // TODO: Should this be setting language?
  6547. } else {
  6548. this.config.playsinline = true;
  6549. }
  6550. }
  6551. } else {
  6552. // <div> with attributes
  6553. this.provider = this.media.getAttribute(this.config.attributes.embed.provider); // Remove attribute
  6554. this.media.removeAttribute(this.config.attributes.embed.provider);
  6555. } // Unsupported or missing provider
  6556. if (is$1.empty(this.provider) || !Object.keys(providers).includes(this.provider)) {
  6557. this.debug.error('Setup failed: Invalid provider');
  6558. return;
  6559. } // Audio will come later for external providers
  6560. this.type = types.video;
  6561. break;
  6562. case 'video':
  6563. case 'audio':
  6564. this.type = type;
  6565. this.provider = providers.html5; // Get config from attributes
  6566. if (this.media.hasAttribute('crossorigin')) {
  6567. this.config.crossorigin = true;
  6568. }
  6569. if (this.media.hasAttribute('autoplay')) {
  6570. this.config.autoplay = true;
  6571. }
  6572. if (this.media.hasAttribute('playsinline') || this.media.hasAttribute('webkit-playsinline')) {
  6573. this.config.playsinline = true;
  6574. }
  6575. if (this.media.hasAttribute('muted')) {
  6576. this.config.muted = true;
  6577. }
  6578. if (this.media.hasAttribute('loop')) {
  6579. this.config.loop.active = true;
  6580. }
  6581. break;
  6582. default:
  6583. this.debug.error('Setup failed: unsupported type');
  6584. return;
  6585. } // Check for support again but with type
  6586. this.supported = support.check(this.type, this.provider, this.config.playsinline); // If no support for even API, bail
  6587. if (!this.supported.api) {
  6588. this.debug.error('Setup failed: no support');
  6589. return;
  6590. }
  6591. this.eventListeners = []; // Create listeners
  6592. this.listeners = new Listeners(this); // Setup local storage for user settings
  6593. this.storage = new Storage(this); // Store reference
  6594. this.media.plyr = this; // Wrap media
  6595. if (!is$1.element(this.elements.container)) {
  6596. this.elements.container = createElement('div', {
  6597. tabindex: 0
  6598. });
  6599. wrap(this.media, this.elements.container);
  6600. } // Migrate custom properties from media to container (so they work 😉)
  6601. ui.migrateStyles.call(this); // Add style hook
  6602. ui.addStyleHook.call(this); // Setup media
  6603. media.setup.call(this); // Listen for events if debugging
  6604. if (this.config.debug) {
  6605. on.call(this, this.elements.container, this.config.events.join(' '), function (event) {
  6606. _this.debug.log("event: ".concat(event.type));
  6607. });
  6608. } // Setup fullscreen
  6609. this.fullscreen = new Fullscreen(this); // Setup interface
  6610. // If embed but not fully supported, build interface now to avoid flash of controls
  6611. if (this.isHTML5 || this.isEmbed && !this.supported.ui) {
  6612. ui.build.call(this);
  6613. } // Container listeners
  6614. this.listeners.container(); // Global listeners
  6615. this.listeners.global(); // Setup ads if provided
  6616. if (this.config.ads.enabled) {
  6617. this.ads = new Ads(this);
  6618. } // Autoplay if required
  6619. if (this.isHTML5 && this.config.autoplay) {
  6620. setTimeout(function () {
  6621. return silencePromise(_this.play());
  6622. }, 10);
  6623. } // Seek time will be recorded (in listeners.js) so we can prevent hiding controls for a few seconds after seek
  6624. this.lastSeekTime = 0; // Setup preview thumbnails if enabled
  6625. if (this.config.previewThumbnails.enabled) {
  6626. this.previewThumbnails = new PreviewThumbnails(this);
  6627. }
  6628. } // ---------------------------------------
  6629. // API
  6630. // ---------------------------------------
  6631. /**
  6632. * Types and provider helpers
  6633. */
  6634. _createClass(Plyr, [{
  6635. key: "play",
  6636. /**
  6637. * Play the media, or play the advertisement (if they are not blocked)
  6638. */
  6639. value: function play() {
  6640. var _this2 = this;
  6641. if (!is$1.function(this.media.play)) {
  6642. return null;
  6643. } // Intecept play with ads
  6644. if (this.ads && this.ads.enabled) {
  6645. this.ads.managerPromise.then(function () {
  6646. return _this2.ads.play();
  6647. }).catch(function () {
  6648. return silencePromise(_this2.media.play());
  6649. });
  6650. } // Return the promise (for HTML5)
  6651. return this.media.play();
  6652. }
  6653. /**
  6654. * Pause the media
  6655. */
  6656. }, {
  6657. key: "pause",
  6658. value: function pause() {
  6659. if (!this.playing || !is$1.function(this.media.pause)) {
  6660. return null;
  6661. }
  6662. return this.media.pause();
  6663. }
  6664. /**
  6665. * Get playing state
  6666. */
  6667. }, {
  6668. key: "togglePlay",
  6669. /**
  6670. * Toggle playback based on current status
  6671. * @param {Boolean} input
  6672. */
  6673. value: function togglePlay(input) {
  6674. // Toggle based on current state if nothing passed
  6675. var toggle = is$1.boolean(input) ? input : !this.playing;
  6676. if (toggle) {
  6677. return this.play();
  6678. }
  6679. return this.pause();
  6680. }
  6681. /**
  6682. * Stop playback
  6683. */
  6684. }, {
  6685. key: "stop",
  6686. value: function stop() {
  6687. if (this.isHTML5) {
  6688. this.pause();
  6689. this.restart();
  6690. } else if (is$1.function(this.media.stop)) {
  6691. this.media.stop();
  6692. }
  6693. }
  6694. /**
  6695. * Restart playback
  6696. */
  6697. }, {
  6698. key: "restart",
  6699. value: function restart() {
  6700. this.currentTime = 0;
  6701. }
  6702. /**
  6703. * Rewind
  6704. * @param {Number} seekTime - how far to rewind in seconds. Defaults to the config.seekTime
  6705. */
  6706. }, {
  6707. key: "rewind",
  6708. value: function rewind(seekTime) {
  6709. this.currentTime -= is$1.number(seekTime) ? seekTime : this.config.seekTime;
  6710. }
  6711. /**
  6712. * Fast forward
  6713. * @param {Number} seekTime - how far to fast forward in seconds. Defaults to the config.seekTime
  6714. */
  6715. }, {
  6716. key: "forward",
  6717. value: function forward(seekTime) {
  6718. this.currentTime += is$1.number(seekTime) ? seekTime : this.config.seekTime;
  6719. }
  6720. /**
  6721. * Seek to a time
  6722. * @param {Number} input - where to seek to in seconds. Defaults to 0 (the start)
  6723. */
  6724. }, {
  6725. key: "increaseVolume",
  6726. /**
  6727. * Increase volume
  6728. * @param {Boolean} step - How much to decrease by (between 0 and 1)
  6729. */
  6730. value: function increaseVolume(step) {
  6731. var volume = this.media.muted ? 0 : this.volume;
  6732. this.volume = volume + (is$1.number(step) ? step : 0);
  6733. }
  6734. /**
  6735. * Decrease volume
  6736. * @param {Boolean} step - How much to decrease by (between 0 and 1)
  6737. */
  6738. }, {
  6739. key: "decreaseVolume",
  6740. value: function decreaseVolume(step) {
  6741. this.increaseVolume(-step);
  6742. }
  6743. /**
  6744. * Set muted state
  6745. * @param {Boolean} mute
  6746. */
  6747. }, {
  6748. key: "toggleCaptions",
  6749. /**
  6750. * Toggle captions
  6751. * @param {Boolean} input - Whether to enable captions
  6752. */
  6753. value: function toggleCaptions(input) {
  6754. captions.toggle.call(this, input, false);
  6755. }
  6756. /**
  6757. * Set the caption track by index
  6758. * @param {Number} - Caption index
  6759. */
  6760. }, {
  6761. key: "airplay",
  6762. /**
  6763. * Trigger the airplay dialog
  6764. * TODO: update player with state, support, enabled
  6765. */
  6766. value: function airplay() {
  6767. // Show dialog if supported
  6768. if (support.airplay) {
  6769. this.media.webkitShowPlaybackTargetPicker();
  6770. }
  6771. }
  6772. /**
  6773. * Toggle the player controls
  6774. * @param {Boolean} [toggle] - Whether to show the controls
  6775. */
  6776. }, {
  6777. key: "toggleControls",
  6778. value: function toggleControls(toggle) {
  6779. // Don't toggle if missing UI support or if it's audio
  6780. if (this.supported.ui && !this.isAudio) {
  6781. // Get state before change
  6782. var isHidden = hasClass(this.elements.container, this.config.classNames.hideControls); // Negate the argument if not undefined since adding the class to hides the controls
  6783. var force = typeof toggle === 'undefined' ? undefined : !toggle; // Apply and get updated state
  6784. var hiding = toggleClass(this.elements.container, this.config.classNames.hideControls, force); // Close menu
  6785. if (hiding && is$1.array(this.config.controls) && this.config.controls.includes('settings') && !is$1.empty(this.config.settings)) {
  6786. controls.toggleMenu.call(this, false);
  6787. } // Trigger event on change
  6788. if (hiding !== isHidden) {
  6789. var eventName = hiding ? 'controlshidden' : 'controlsshown';
  6790. triggerEvent.call(this, this.media, eventName);
  6791. }
  6792. return !hiding;
  6793. }
  6794. return false;
  6795. }
  6796. /**
  6797. * Add event listeners
  6798. * @param {String} event - Event type
  6799. * @param {Function} callback - Callback for when event occurs
  6800. */
  6801. }, {
  6802. key: "on",
  6803. value: function on$1(event, callback) {
  6804. on.call(this, this.elements.container, event, callback);
  6805. }
  6806. /**
  6807. * Add event listeners once
  6808. * @param {String} event - Event type
  6809. * @param {Function} callback - Callback for when event occurs
  6810. */
  6811. }, {
  6812. key: "once",
  6813. value: function once$1(event, callback) {
  6814. once.call(this, this.elements.container, event, callback);
  6815. }
  6816. /**
  6817. * Remove event listeners
  6818. * @param {String} event - Event type
  6819. * @param {Function} callback - Callback for when event occurs
  6820. */
  6821. }, {
  6822. key: "off",
  6823. value: function off$1(event, callback) {
  6824. off(this.elements.container, event, callback);
  6825. }
  6826. /**
  6827. * Destroy an instance
  6828. * Event listeners are removed when elements are removed
  6829. * http://stackoverflow.com/questions/12528049/if-a-dom-element-is-removed-are-its-listeners-also-removed-from-memory
  6830. * @param {Function} callback - Callback for when destroy is complete
  6831. * @param {Boolean} soft - Whether it's a soft destroy (for source changes etc)
  6832. */
  6833. }, {
  6834. key: "destroy",
  6835. value: function destroy(callback) {
  6836. var _this3 = this;
  6837. var soft = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  6838. if (!this.ready) {
  6839. return;
  6840. }
  6841. var done = function done() {
  6842. // Reset overflow (incase destroyed while in fullscreen)
  6843. document.body.style.overflow = ''; // GC for embed
  6844. _this3.embed = null; // If it's a soft destroy, make minimal changes
  6845. if (soft) {
  6846. if (Object.keys(_this3.elements).length) {
  6847. // Remove elements
  6848. removeElement(_this3.elements.buttons.play);
  6849. removeElement(_this3.elements.captions);
  6850. removeElement(_this3.elements.controls);
  6851. removeElement(_this3.elements.wrapper); // Clear for GC
  6852. _this3.elements.buttons.play = null;
  6853. _this3.elements.captions = null;
  6854. _this3.elements.controls = null;
  6855. _this3.elements.wrapper = null;
  6856. } // Callback
  6857. if (is$1.function(callback)) {
  6858. callback();
  6859. }
  6860. } else {
  6861. // Unbind listeners
  6862. unbindListeners.call(_this3); // Replace the container with the original element provided
  6863. replaceElement(_this3.elements.original, _this3.elements.container); // Event
  6864. triggerEvent.call(_this3, _this3.elements.original, 'destroyed', true); // Callback
  6865. if (is$1.function(callback)) {
  6866. callback.call(_this3.elements.original);
  6867. } // Reset state
  6868. _this3.ready = false; // Clear for garbage collection
  6869. setTimeout(function () {
  6870. _this3.elements = null;
  6871. _this3.media = null;
  6872. }, 200);
  6873. }
  6874. }; // Stop playback
  6875. this.stop(); // Clear timeouts
  6876. clearTimeout(this.timers.loading);
  6877. clearTimeout(this.timers.controls);
  6878. clearTimeout(this.timers.resized); // Provider specific stuff
  6879. if (this.isHTML5) {
  6880. // Restore native video controls
  6881. ui.toggleNativeControls.call(this, true); // Clean up
  6882. done();
  6883. } else if (this.isYouTube) {
  6884. // Clear timers
  6885. clearInterval(this.timers.buffering);
  6886. clearInterval(this.timers.playing); // Destroy YouTube API
  6887. if (this.embed !== null && is$1.function(this.embed.destroy)) {
  6888. this.embed.destroy();
  6889. } // Clean up
  6890. done();
  6891. } else if (this.isVimeo) {
  6892. // Destroy Vimeo API
  6893. // then clean up (wait, to prevent postmessage errors)
  6894. if (this.embed !== null) {
  6895. this.embed.unload().then(done);
  6896. } // Vimeo does not always return
  6897. setTimeout(done, 200);
  6898. }
  6899. }
  6900. /**
  6901. * Check for support for a mime type (HTML5 only)
  6902. * @param {String} type - Mime type
  6903. */
  6904. }, {
  6905. key: "supports",
  6906. value: function supports(type) {
  6907. return support.mime.call(this, type);
  6908. }
  6909. /**
  6910. * Check for support
  6911. * @param {String} type - Player type (audio/video)
  6912. * @param {String} provider - Provider (html5/youtube/vimeo)
  6913. * @param {Boolean} inline - Where player has `playsinline` sttribute
  6914. */
  6915. }, {
  6916. key: "isHTML5",
  6917. get: function get() {
  6918. return this.provider === providers.html5;
  6919. }
  6920. }, {
  6921. key: "isEmbed",
  6922. get: function get() {
  6923. return this.isYouTube || this.isVimeo;
  6924. }
  6925. }, {
  6926. key: "isYouTube",
  6927. get: function get() {
  6928. return this.provider === providers.youtube;
  6929. }
  6930. }, {
  6931. key: "isVimeo",
  6932. get: function get() {
  6933. return this.provider === providers.vimeo;
  6934. }
  6935. }, {
  6936. key: "isVideo",
  6937. get: function get() {
  6938. return this.type === types.video;
  6939. }
  6940. }, {
  6941. key: "isAudio",
  6942. get: function get() {
  6943. return this.type === types.audio;
  6944. }
  6945. }, {
  6946. key: "playing",
  6947. get: function get() {
  6948. return Boolean(this.ready && !this.paused && !this.ended);
  6949. }
  6950. /**
  6951. * Get paused state
  6952. */
  6953. }, {
  6954. key: "paused",
  6955. get: function get() {
  6956. return Boolean(this.media.paused);
  6957. }
  6958. /**
  6959. * Get stopped state
  6960. */
  6961. }, {
  6962. key: "stopped",
  6963. get: function get() {
  6964. return Boolean(this.paused && this.currentTime === 0);
  6965. }
  6966. /**
  6967. * Get ended state
  6968. */
  6969. }, {
  6970. key: "ended",
  6971. get: function get() {
  6972. return Boolean(this.media.ended);
  6973. }
  6974. }, {
  6975. key: "currentTime",
  6976. set: function set(input) {
  6977. // Bail if media duration isn't available yet
  6978. if (!this.duration) {
  6979. return;
  6980. } // Validate input
  6981. var inputIsValid = is$1.number(input) && input > 0; // Set
  6982. this.media.currentTime = inputIsValid ? Math.min(input, this.duration) : 0; // Logging
  6983. this.debug.log("Seeking to ".concat(this.currentTime, " seconds"));
  6984. }
  6985. /**
  6986. * Get current time
  6987. */
  6988. ,
  6989. get: function get() {
  6990. return Number(this.media.currentTime);
  6991. }
  6992. /**
  6993. * Get buffered
  6994. */
  6995. }, {
  6996. key: "buffered",
  6997. get: function get() {
  6998. var buffered = this.media.buffered; // YouTube / Vimeo return a float between 0-1
  6999. if (is$1.number(buffered)) {
  7000. return buffered;
  7001. } // HTML5
  7002. // TODO: Handle buffered chunks of the media
  7003. // (i.e. seek to another section buffers only that section)
  7004. if (buffered && buffered.length && this.duration > 0) {
  7005. return buffered.end(0) / this.duration;
  7006. }
  7007. return 0;
  7008. }
  7009. /**
  7010. * Get seeking status
  7011. */
  7012. }, {
  7013. key: "seeking",
  7014. get: function get() {
  7015. return Boolean(this.media.seeking);
  7016. }
  7017. /**
  7018. * Get the duration of the current media
  7019. */
  7020. }, {
  7021. key: "duration",
  7022. get: function get() {
  7023. // Faux duration set via config
  7024. var fauxDuration = parseFloat(this.config.duration); // Media duration can be NaN or Infinity before the media has loaded
  7025. var realDuration = (this.media || {}).duration;
  7026. var duration = !is$1.number(realDuration) || realDuration === Infinity ? 0 : realDuration; // If config duration is funky, use regular duration
  7027. return fauxDuration || duration;
  7028. }
  7029. /**
  7030. * Set the player volume
  7031. * @param {Number} value - must be between 0 and 1. Defaults to the value from local storage and config.volume if not set in storage
  7032. */
  7033. }, {
  7034. key: "volume",
  7035. set: function set(value) {
  7036. var volume = value;
  7037. var max = 1;
  7038. var min = 0;
  7039. if (is$1.string(volume)) {
  7040. volume = Number(volume);
  7041. } // Load volume from storage if no value specified
  7042. if (!is$1.number(volume)) {
  7043. volume = this.storage.get('volume');
  7044. } // Use config if all else fails
  7045. if (!is$1.number(volume)) {
  7046. volume = this.config.volume;
  7047. } // Maximum is volumeMax
  7048. if (volume > max) {
  7049. volume = max;
  7050. } // Minimum is volumeMin
  7051. if (volume < min) {
  7052. volume = min;
  7053. } // Update config
  7054. this.config.volume = volume; // Set the player volume
  7055. this.media.volume = volume; // If muted, and we're increasing volume manually, reset muted state
  7056. if (!is$1.empty(value) && this.muted && volume > 0) {
  7057. this.muted = false;
  7058. }
  7059. }
  7060. /**
  7061. * Get the current player volume
  7062. */
  7063. ,
  7064. get: function get() {
  7065. return Number(this.media.volume);
  7066. }
  7067. }, {
  7068. key: "muted",
  7069. set: function set(mute) {
  7070. var toggle = mute; // Load muted state from storage
  7071. if (!is$1.boolean(toggle)) {
  7072. toggle = this.storage.get('muted');
  7073. } // Use config if all else fails
  7074. if (!is$1.boolean(toggle)) {
  7075. toggle = this.config.muted;
  7076. } // Update config
  7077. this.config.muted = toggle; // Set mute on the player
  7078. this.media.muted = toggle;
  7079. }
  7080. /**
  7081. * Get current muted state
  7082. */
  7083. ,
  7084. get: function get() {
  7085. return Boolean(this.media.muted);
  7086. }
  7087. /**
  7088. * Check if the media has audio
  7089. */
  7090. }, {
  7091. key: "hasAudio",
  7092. get: function get() {
  7093. // Assume yes for all non HTML5 (as we can't tell...)
  7094. if (!this.isHTML5) {
  7095. return true;
  7096. }
  7097. if (this.isAudio) {
  7098. return true;
  7099. } // Get audio tracks
  7100. return Boolean(this.media.mozHasAudio) || Boolean(this.media.webkitAudioDecodedByteCount) || Boolean(this.media.audioTracks && this.media.audioTracks.length);
  7101. }
  7102. /**
  7103. * Set playback speed
  7104. * @param {Number} speed - the speed of playback (0.5-2.0)
  7105. */
  7106. }, {
  7107. key: "speed",
  7108. set: function set(input) {
  7109. var _this4 = this;
  7110. var speed = null;
  7111. if (is$1.number(input)) {
  7112. speed = input;
  7113. }
  7114. if (!is$1.number(speed)) {
  7115. speed = this.storage.get('speed');
  7116. }
  7117. if (!is$1.number(speed)) {
  7118. speed = this.config.speed.selected;
  7119. } // Clamp to min/max
  7120. var min = this.minimumSpeed,
  7121. max = this.maximumSpeed;
  7122. speed = clamp(speed, min, max); // Update config
  7123. this.config.speed.selected = speed; // Set media speed
  7124. setTimeout(function () {
  7125. _this4.media.playbackRate = speed;
  7126. }, 0);
  7127. }
  7128. /**
  7129. * Get current playback speed
  7130. */
  7131. ,
  7132. get: function get() {
  7133. return Number(this.media.playbackRate);
  7134. }
  7135. /**
  7136. * Get the minimum allowed speed
  7137. */
  7138. }, {
  7139. key: "minimumSpeed",
  7140. get: function get() {
  7141. if (this.isYouTube) {
  7142. // https://developers.google.com/youtube/iframe_api_reference#setPlaybackRate
  7143. return Math.min.apply(Math, _toConsumableArray(this.options.speed));
  7144. }
  7145. if (this.isVimeo) {
  7146. // https://github.com/vimeo/player.js/#setplaybackrateplaybackrate-number-promisenumber-rangeerrorerror
  7147. return 0.5;
  7148. } // https://stackoverflow.com/a/32320020/1191319
  7149. return 0.0625;
  7150. }
  7151. /**
  7152. * Get the maximum allowed speed
  7153. */
  7154. }, {
  7155. key: "maximumSpeed",
  7156. get: function get() {
  7157. if (this.isYouTube) {
  7158. // https://developers.google.com/youtube/iframe_api_reference#setPlaybackRate
  7159. return Math.max.apply(Math, _toConsumableArray(this.options.speed));
  7160. }
  7161. if (this.isVimeo) {
  7162. // https://github.com/vimeo/player.js/#setplaybackrateplaybackrate-number-promisenumber-rangeerrorerror
  7163. return 2;
  7164. } // https://stackoverflow.com/a/32320020/1191319
  7165. return 16;
  7166. }
  7167. /**
  7168. * Set playback quality
  7169. * Currently HTML5 & YouTube only
  7170. * @param {Number} input - Quality level
  7171. */
  7172. }, {
  7173. key: "quality",
  7174. set: function set(input) {
  7175. var config = this.config.quality;
  7176. var options = this.options.quality;
  7177. if (!options.length) {
  7178. return;
  7179. }
  7180. var quality = [!is$1.empty(input) && Number(input), this.storage.get('quality'), config.selected, config.default].find(is$1.number);
  7181. var updateStorage = true;
  7182. if (!options.includes(quality)) {
  7183. var value = closest$1(options, quality);
  7184. this.debug.warn("Unsupported quality option: ".concat(quality, ", using ").concat(value, " instead"));
  7185. quality = value; // Don't update storage if quality is not supported
  7186. updateStorage = false;
  7187. } // Update config
  7188. config.selected = quality; // Set quality
  7189. this.media.quality = quality; // Save to storage
  7190. if (updateStorage) {
  7191. this.storage.set({
  7192. quality: quality
  7193. });
  7194. }
  7195. }
  7196. /**
  7197. * Get current quality level
  7198. */
  7199. ,
  7200. get: function get() {
  7201. return this.media.quality;
  7202. }
  7203. /**
  7204. * Toggle loop
  7205. * TODO: Finish fancy new logic. Set the indicator on load as user may pass loop as config
  7206. * @param {Boolean} input - Whether to loop or not
  7207. */
  7208. }, {
  7209. key: "loop",
  7210. set: function set(input) {
  7211. var toggle = is$1.boolean(input) ? input : this.config.loop.active;
  7212. this.config.loop.active = toggle;
  7213. this.media.loop = toggle; // Set default to be a true toggle
  7214. /* const type = ['start', 'end', 'all', 'none', 'toggle'].includes(input) ? input : 'toggle';
  7215. switch (type) {
  7216. case 'start':
  7217. if (this.config.loop.end && this.config.loop.end <= this.currentTime) {
  7218. this.config.loop.end = null;
  7219. }
  7220. this.config.loop.start = this.currentTime;
  7221. // this.config.loop.indicator.start = this.elements.display.played.value;
  7222. break;
  7223. case 'end':
  7224. if (this.config.loop.start >= this.currentTime) {
  7225. return this;
  7226. }
  7227. this.config.loop.end = this.currentTime;
  7228. // this.config.loop.indicator.end = this.elements.display.played.value;
  7229. break;
  7230. case 'all':
  7231. this.config.loop.start = 0;
  7232. this.config.loop.end = this.duration - 2;
  7233. this.config.loop.indicator.start = 0;
  7234. this.config.loop.indicator.end = 100;
  7235. break;
  7236. case 'toggle':
  7237. if (this.config.loop.active) {
  7238. this.config.loop.start = 0;
  7239. this.config.loop.end = null;
  7240. } else {
  7241. this.config.loop.start = 0;
  7242. this.config.loop.end = this.duration - 2;
  7243. }
  7244. break;
  7245. default:
  7246. this.config.loop.start = 0;
  7247. this.config.loop.end = null;
  7248. break;
  7249. } */
  7250. }
  7251. /**
  7252. * Get current loop state
  7253. */
  7254. ,
  7255. get: function get() {
  7256. return Boolean(this.media.loop);
  7257. }
  7258. /**
  7259. * Set new media source
  7260. * @param {Object} input - The new source object (see docs)
  7261. */
  7262. }, {
  7263. key: "source",
  7264. set: function set(input) {
  7265. source.change.call(this, input);
  7266. }
  7267. /**
  7268. * Get current source
  7269. */
  7270. ,
  7271. get: function get() {
  7272. return this.media.currentSrc;
  7273. }
  7274. /**
  7275. * Get a download URL (either source or custom)
  7276. */
  7277. }, {
  7278. key: "download",
  7279. get: function get() {
  7280. var download = this.config.urls.download;
  7281. return is$1.url(download) ? download : this.source;
  7282. }
  7283. /**
  7284. * Set the download URL
  7285. */
  7286. ,
  7287. set: function set(input) {
  7288. if (!is$1.url(input)) {
  7289. return;
  7290. }
  7291. this.config.urls.download = input;
  7292. controls.setDownloadUrl.call(this);
  7293. }
  7294. /**
  7295. * Set the poster image for a video
  7296. * @param {String} input - the URL for the new poster image
  7297. */
  7298. }, {
  7299. key: "poster",
  7300. set: function set(input) {
  7301. if (!this.isVideo) {
  7302. this.debug.warn('Poster can only be set for video');
  7303. return;
  7304. }
  7305. ui.setPoster.call(this, input, false).catch(function () {});
  7306. }
  7307. /**
  7308. * Get the current poster image
  7309. */
  7310. ,
  7311. get: function get() {
  7312. if (!this.isVideo) {
  7313. return null;
  7314. }
  7315. return this.media.getAttribute('poster') || this.media.getAttribute('data-poster');
  7316. }
  7317. /**
  7318. * Get the current aspect ratio in use
  7319. */
  7320. }, {
  7321. key: "ratio",
  7322. get: function get() {
  7323. if (!this.isVideo) {
  7324. return null;
  7325. }
  7326. var ratio = reduceAspectRatio(getAspectRatio.call(this));
  7327. return is$1.array(ratio) ? ratio.join(':') : ratio;
  7328. }
  7329. /**
  7330. * Set video aspect ratio
  7331. */
  7332. ,
  7333. set: function set(input) {
  7334. if (!this.isVideo) {
  7335. this.debug.warn('Aspect ratio can only be set for video');
  7336. return;
  7337. }
  7338. if (!is$1.string(input) || !validateRatio(input)) {
  7339. this.debug.error("Invalid aspect ratio specified (".concat(input, ")"));
  7340. return;
  7341. }
  7342. this.config.ratio = input;
  7343. setAspectRatio.call(this);
  7344. }
  7345. /**
  7346. * Set the autoplay state
  7347. * @param {Boolean} input - Whether to autoplay or not
  7348. */
  7349. }, {
  7350. key: "autoplay",
  7351. set: function set(input) {
  7352. var toggle = is$1.boolean(input) ? input : this.config.autoplay;
  7353. this.config.autoplay = toggle;
  7354. }
  7355. /**
  7356. * Get the current autoplay state
  7357. */
  7358. ,
  7359. get: function get() {
  7360. return Boolean(this.config.autoplay);
  7361. }
  7362. }, {
  7363. key: "currentTrack",
  7364. set: function set(input) {
  7365. captions.set.call(this, input, false);
  7366. }
  7367. /**
  7368. * Get the current caption track index (-1 if disabled)
  7369. */
  7370. ,
  7371. get: function get() {
  7372. var _this$captions = this.captions,
  7373. toggled = _this$captions.toggled,
  7374. currentTrack = _this$captions.currentTrack;
  7375. return toggled ? currentTrack : -1;
  7376. }
  7377. /**
  7378. * Set the wanted language for captions
  7379. * Since tracks can be added later it won't update the actual caption track until there is a matching track
  7380. * @param {String} - Two character ISO language code (e.g. EN, FR, PT, etc)
  7381. */
  7382. }, {
  7383. key: "language",
  7384. set: function set(input) {
  7385. captions.setLanguage.call(this, input, false);
  7386. }
  7387. /**
  7388. * Get the current track's language
  7389. */
  7390. ,
  7391. get: function get() {
  7392. return (captions.getCurrentTrack.call(this) || {}).language;
  7393. }
  7394. /**
  7395. * Toggle picture-in-picture playback on WebKit/MacOS
  7396. * TODO: update player with state, support, enabled
  7397. * TODO: detect outside changes
  7398. */
  7399. }, {
  7400. key: "pip",
  7401. set: function set(input) {
  7402. // Bail if no support
  7403. if (!support.pip) {
  7404. return;
  7405. } // Toggle based on current state if not passed
  7406. var toggle = is$1.boolean(input) ? input : !this.pip; // Toggle based on current state
  7407. // Safari
  7408. if (is$1.function(this.media.webkitSetPresentationMode)) {
  7409. this.media.webkitSetPresentationMode(toggle ? pip.active : pip.inactive);
  7410. } // Chrome
  7411. if (is$1.function(this.media.requestPictureInPicture)) {
  7412. if (!this.pip && toggle) {
  7413. this.media.requestPictureInPicture();
  7414. } else if (this.pip && !toggle) {
  7415. document.exitPictureInPicture();
  7416. }
  7417. }
  7418. }
  7419. /**
  7420. * Get the current picture-in-picture state
  7421. */
  7422. ,
  7423. get: function get() {
  7424. if (!support.pip) {
  7425. return null;
  7426. } // Safari
  7427. if (!is$1.empty(this.media.webkitPresentationMode)) {
  7428. return this.media.webkitPresentationMode === pip.active;
  7429. } // Chrome
  7430. return this.media === document.pictureInPictureElement;
  7431. }
  7432. }], [{
  7433. key: "supported",
  7434. value: function supported(type, provider, inline) {
  7435. return support.check(type, provider, inline);
  7436. }
  7437. /**
  7438. * Load an SVG sprite into the page
  7439. * @param {String} url - URL for the SVG sprite
  7440. * @param {String} [id] - Unique ID
  7441. */
  7442. }, {
  7443. key: "loadSprite",
  7444. value: function loadSprite$1(url, id) {
  7445. return loadSprite(url, id);
  7446. }
  7447. /**
  7448. * Setup multiple instances
  7449. * @param {*} selector
  7450. * @param {Object} options
  7451. */
  7452. }, {
  7453. key: "setup",
  7454. value: function setup(selector) {
  7455. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  7456. var targets = null;
  7457. if (is$1.string(selector)) {
  7458. targets = Array.from(document.querySelectorAll(selector));
  7459. } else if (is$1.nodeList(selector)) {
  7460. targets = Array.from(selector);
  7461. } else if (is$1.array(selector)) {
  7462. targets = selector.filter(is$1.element);
  7463. }
  7464. if (is$1.empty(targets)) {
  7465. return null;
  7466. }
  7467. return targets.map(function (t) {
  7468. return new Plyr(t, options);
  7469. });
  7470. }
  7471. }]);
  7472. return Plyr;
  7473. }();
  7474. Plyr.defaults = cloneDeep(defaults$1);
  7475. return Plyr;
  7476. })));