plyr.mjs 292 KB

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