swiper-bundle.js 334 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696
  1. /**
  2. * Swiper 11.1.15
  3. * Most modern mobile touch slider and framework with hardware accelerated transitions
  4. * https://swiperjs.com
  5. *
  6. * Copyright 2014-2024 Vladimir Kharlampidi
  7. *
  8. * Released under the MIT License
  9. *
  10. * Released on: November 18, 2024
  11. */
  12. var Swiper = (function () {
  13. 'use strict';
  14. /**
  15. * SSR Window 4.0.2
  16. * Better handling for window object in SSR environment
  17. * https://github.com/nolimits4web/ssr-window
  18. *
  19. * Copyright 2021, Vladimir Kharlampidi
  20. *
  21. * Licensed under MIT
  22. *
  23. * Released on: December 13, 2021
  24. */
  25. /* eslint-disable no-param-reassign */
  26. function isObject$1(obj) {
  27. return obj !== null && typeof obj === 'object' && 'constructor' in obj && obj.constructor === Object;
  28. }
  29. function extend$1(target, src) {
  30. if (target === void 0) {
  31. target = {};
  32. }
  33. if (src === void 0) {
  34. src = {};
  35. }
  36. Object.keys(src).forEach(key => {
  37. if (typeof target[key] === 'undefined') target[key] = src[key];else if (isObject$1(src[key]) && isObject$1(target[key]) && Object.keys(src[key]).length > 0) {
  38. extend$1(target[key], src[key]);
  39. }
  40. });
  41. }
  42. const ssrDocument = {
  43. body: {},
  44. addEventListener() {},
  45. removeEventListener() {},
  46. activeElement: {
  47. blur() {},
  48. nodeName: ''
  49. },
  50. querySelector() {
  51. return null;
  52. },
  53. querySelectorAll() {
  54. return [];
  55. },
  56. getElementById() {
  57. return null;
  58. },
  59. createEvent() {
  60. return {
  61. initEvent() {}
  62. };
  63. },
  64. createElement() {
  65. return {
  66. children: [],
  67. childNodes: [],
  68. style: {},
  69. setAttribute() {},
  70. getElementsByTagName() {
  71. return [];
  72. }
  73. };
  74. },
  75. createElementNS() {
  76. return {};
  77. },
  78. importNode() {
  79. return null;
  80. },
  81. location: {
  82. hash: '',
  83. host: '',
  84. hostname: '',
  85. href: '',
  86. origin: '',
  87. pathname: '',
  88. protocol: '',
  89. search: ''
  90. }
  91. };
  92. function getDocument() {
  93. const doc = typeof document !== 'undefined' ? document : {};
  94. extend$1(doc, ssrDocument);
  95. return doc;
  96. }
  97. const ssrWindow = {
  98. document: ssrDocument,
  99. navigator: {
  100. userAgent: ''
  101. },
  102. location: {
  103. hash: '',
  104. host: '',
  105. hostname: '',
  106. href: '',
  107. origin: '',
  108. pathname: '',
  109. protocol: '',
  110. search: ''
  111. },
  112. history: {
  113. replaceState() {},
  114. pushState() {},
  115. go() {},
  116. back() {}
  117. },
  118. CustomEvent: function CustomEvent() {
  119. return this;
  120. },
  121. addEventListener() {},
  122. removeEventListener() {},
  123. getComputedStyle() {
  124. return {
  125. getPropertyValue() {
  126. return '';
  127. }
  128. };
  129. },
  130. Image() {},
  131. Date() {},
  132. screen: {},
  133. setTimeout() {},
  134. clearTimeout() {},
  135. matchMedia() {
  136. return {};
  137. },
  138. requestAnimationFrame(callback) {
  139. if (typeof setTimeout === 'undefined') {
  140. callback();
  141. return null;
  142. }
  143. return setTimeout(callback, 0);
  144. },
  145. cancelAnimationFrame(id) {
  146. if (typeof setTimeout === 'undefined') {
  147. return;
  148. }
  149. clearTimeout(id);
  150. }
  151. };
  152. function getWindow() {
  153. const win = typeof window !== 'undefined' ? window : {};
  154. extend$1(win, ssrWindow);
  155. return win;
  156. }
  157. function classesToTokens(classes) {
  158. if (classes === void 0) {
  159. classes = '';
  160. }
  161. return classes.trim().split(' ').filter(c => !!c.trim());
  162. }
  163. function deleteProps(obj) {
  164. const object = obj;
  165. Object.keys(object).forEach(key => {
  166. try {
  167. object[key] = null;
  168. } catch (e) {
  169. // no getter for object
  170. }
  171. try {
  172. delete object[key];
  173. } catch (e) {
  174. // something got wrong
  175. }
  176. });
  177. }
  178. function nextTick(callback, delay) {
  179. if (delay === void 0) {
  180. delay = 0;
  181. }
  182. return setTimeout(callback, delay);
  183. }
  184. function now() {
  185. return Date.now();
  186. }
  187. function getComputedStyle$1(el) {
  188. const window = getWindow();
  189. let style;
  190. if (window.getComputedStyle) {
  191. style = window.getComputedStyle(el, null);
  192. }
  193. if (!style && el.currentStyle) {
  194. style = el.currentStyle;
  195. }
  196. if (!style) {
  197. style = el.style;
  198. }
  199. return style;
  200. }
  201. function getTranslate(el, axis) {
  202. if (axis === void 0) {
  203. axis = 'x';
  204. }
  205. const window = getWindow();
  206. let matrix;
  207. let curTransform;
  208. let transformMatrix;
  209. const curStyle = getComputedStyle$1(el);
  210. if (window.WebKitCSSMatrix) {
  211. curTransform = curStyle.transform || curStyle.webkitTransform;
  212. if (curTransform.split(',').length > 6) {
  213. curTransform = curTransform.split(', ').map(a => a.replace(',', '.')).join(', ');
  214. }
  215. // Some old versions of Webkit choke when 'none' is passed; pass
  216. // empty string instead in this case
  217. transformMatrix = new window.WebKitCSSMatrix(curTransform === 'none' ? '' : curTransform);
  218. } else {
  219. transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue('transform').replace('translate(', 'matrix(1, 0, 0, 1,');
  220. matrix = transformMatrix.toString().split(',');
  221. }
  222. if (axis === 'x') {
  223. // Latest Chrome and webkits Fix
  224. if (window.WebKitCSSMatrix) curTransform = transformMatrix.m41;
  225. // Crazy IE10 Matrix
  226. else if (matrix.length === 16) curTransform = parseFloat(matrix[12]);
  227. // Normal Browsers
  228. else curTransform = parseFloat(matrix[4]);
  229. }
  230. if (axis === 'y') {
  231. // Latest Chrome and webkits Fix
  232. if (window.WebKitCSSMatrix) curTransform = transformMatrix.m42;
  233. // Crazy IE10 Matrix
  234. else if (matrix.length === 16) curTransform = parseFloat(matrix[13]);
  235. // Normal Browsers
  236. else curTransform = parseFloat(matrix[5]);
  237. }
  238. return curTransform || 0;
  239. }
  240. function isObject(o) {
  241. return typeof o === 'object' && o !== null && o.constructor && Object.prototype.toString.call(o).slice(8, -1) === 'Object';
  242. }
  243. function isNode(node) {
  244. // eslint-disable-next-line
  245. if (typeof window !== 'undefined' && typeof window.HTMLElement !== 'undefined') {
  246. return node instanceof HTMLElement;
  247. }
  248. return node && (node.nodeType === 1 || node.nodeType === 11);
  249. }
  250. function extend() {
  251. const to = Object(arguments.length <= 0 ? undefined : arguments[0]);
  252. const noExtend = ['__proto__', 'constructor', 'prototype'];
  253. for (let i = 1; i < arguments.length; i += 1) {
  254. const nextSource = i < 0 || arguments.length <= i ? undefined : arguments[i];
  255. if (nextSource !== undefined && nextSource !== null && !isNode(nextSource)) {
  256. const keysArray = Object.keys(Object(nextSource)).filter(key => noExtend.indexOf(key) < 0);
  257. for (let nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex += 1) {
  258. const nextKey = keysArray[nextIndex];
  259. const desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
  260. if (desc !== undefined && desc.enumerable) {
  261. if (isObject(to[nextKey]) && isObject(nextSource[nextKey])) {
  262. if (nextSource[nextKey].__swiper__) {
  263. to[nextKey] = nextSource[nextKey];
  264. } else {
  265. extend(to[nextKey], nextSource[nextKey]);
  266. }
  267. } else if (!isObject(to[nextKey]) && isObject(nextSource[nextKey])) {
  268. to[nextKey] = {};
  269. if (nextSource[nextKey].__swiper__) {
  270. to[nextKey] = nextSource[nextKey];
  271. } else {
  272. extend(to[nextKey], nextSource[nextKey]);
  273. }
  274. } else {
  275. to[nextKey] = nextSource[nextKey];
  276. }
  277. }
  278. }
  279. }
  280. }
  281. return to;
  282. }
  283. function setCSSProperty(el, varName, varValue) {
  284. el.style.setProperty(varName, varValue);
  285. }
  286. function animateCSSModeScroll(_ref) {
  287. let {
  288. swiper,
  289. targetPosition,
  290. side
  291. } = _ref;
  292. const window = getWindow();
  293. const startPosition = -swiper.translate;
  294. let startTime = null;
  295. let time;
  296. const duration = swiper.params.speed;
  297. swiper.wrapperEl.style.scrollSnapType = 'none';
  298. window.cancelAnimationFrame(swiper.cssModeFrameID);
  299. const dir = targetPosition > startPosition ? 'next' : 'prev';
  300. const isOutOfBound = (current, target) => {
  301. return dir === 'next' && current >= target || dir === 'prev' && current <= target;
  302. };
  303. const animate = () => {
  304. time = new Date().getTime();
  305. if (startTime === null) {
  306. startTime = time;
  307. }
  308. const progress = Math.max(Math.min((time - startTime) / duration, 1), 0);
  309. const easeProgress = 0.5 - Math.cos(progress * Math.PI) / 2;
  310. let currentPosition = startPosition + easeProgress * (targetPosition - startPosition);
  311. if (isOutOfBound(currentPosition, targetPosition)) {
  312. currentPosition = targetPosition;
  313. }
  314. swiper.wrapperEl.scrollTo({
  315. [side]: currentPosition
  316. });
  317. if (isOutOfBound(currentPosition, targetPosition)) {
  318. swiper.wrapperEl.style.overflow = 'hidden';
  319. swiper.wrapperEl.style.scrollSnapType = '';
  320. setTimeout(() => {
  321. swiper.wrapperEl.style.overflow = '';
  322. swiper.wrapperEl.scrollTo({
  323. [side]: currentPosition
  324. });
  325. });
  326. window.cancelAnimationFrame(swiper.cssModeFrameID);
  327. return;
  328. }
  329. swiper.cssModeFrameID = window.requestAnimationFrame(animate);
  330. };
  331. animate();
  332. }
  333. function getSlideTransformEl(slideEl) {
  334. return slideEl.querySelector('.swiper-slide-transform') || slideEl.shadowRoot && slideEl.shadowRoot.querySelector('.swiper-slide-transform') || slideEl;
  335. }
  336. function elementChildren(element, selector) {
  337. if (selector === void 0) {
  338. selector = '';
  339. }
  340. const children = [...element.children];
  341. if (element instanceof HTMLSlotElement) {
  342. children.push(...element.assignedElements());
  343. }
  344. if (!selector) {
  345. return children;
  346. }
  347. return children.filter(el => el.matches(selector));
  348. }
  349. function elementIsChildOf(el, parent) {
  350. const isChild = parent.contains(el);
  351. if (!isChild && parent instanceof HTMLSlotElement) {
  352. const children = [...parent.assignedElements()];
  353. return children.includes(el);
  354. }
  355. return isChild;
  356. }
  357. function showWarning(text) {
  358. try {
  359. console.warn(text);
  360. return;
  361. } catch (err) {
  362. // err
  363. }
  364. }
  365. function createElement(tag, classes) {
  366. if (classes === void 0) {
  367. classes = [];
  368. }
  369. const el = document.createElement(tag);
  370. el.classList.add(...(Array.isArray(classes) ? classes : classesToTokens(classes)));
  371. return el;
  372. }
  373. function elementOffset(el) {
  374. const window = getWindow();
  375. const document = getDocument();
  376. const box = el.getBoundingClientRect();
  377. const body = document.body;
  378. const clientTop = el.clientTop || body.clientTop || 0;
  379. const clientLeft = el.clientLeft || body.clientLeft || 0;
  380. const scrollTop = el === window ? window.scrollY : el.scrollTop;
  381. const scrollLeft = el === window ? window.scrollX : el.scrollLeft;
  382. return {
  383. top: box.top + scrollTop - clientTop,
  384. left: box.left + scrollLeft - clientLeft
  385. };
  386. }
  387. function elementPrevAll(el, selector) {
  388. const prevEls = [];
  389. while (el.previousElementSibling) {
  390. const prev = el.previousElementSibling; // eslint-disable-line
  391. if (selector) {
  392. if (prev.matches(selector)) prevEls.push(prev);
  393. } else prevEls.push(prev);
  394. el = prev;
  395. }
  396. return prevEls;
  397. }
  398. function elementNextAll(el, selector) {
  399. const nextEls = [];
  400. while (el.nextElementSibling) {
  401. const next = el.nextElementSibling; // eslint-disable-line
  402. if (selector) {
  403. if (next.matches(selector)) nextEls.push(next);
  404. } else nextEls.push(next);
  405. el = next;
  406. }
  407. return nextEls;
  408. }
  409. function elementStyle(el, prop) {
  410. const window = getWindow();
  411. return window.getComputedStyle(el, null).getPropertyValue(prop);
  412. }
  413. function elementIndex(el) {
  414. let child = el;
  415. let i;
  416. if (child) {
  417. i = 0;
  418. // eslint-disable-next-line
  419. while ((child = child.previousSibling) !== null) {
  420. if (child.nodeType === 1) i += 1;
  421. }
  422. return i;
  423. }
  424. return undefined;
  425. }
  426. function elementParents(el, selector) {
  427. const parents = []; // eslint-disable-line
  428. let parent = el.parentElement; // eslint-disable-line
  429. while (parent) {
  430. if (selector) {
  431. if (parent.matches(selector)) parents.push(parent);
  432. } else {
  433. parents.push(parent);
  434. }
  435. parent = parent.parentElement;
  436. }
  437. return parents;
  438. }
  439. function elementTransitionEnd(el, callback) {
  440. function fireCallBack(e) {
  441. if (e.target !== el) return;
  442. callback.call(el, e);
  443. el.removeEventListener('transitionend', fireCallBack);
  444. }
  445. if (callback) {
  446. el.addEventListener('transitionend', fireCallBack);
  447. }
  448. }
  449. function elementOuterSize(el, size, includeMargins) {
  450. const window = getWindow();
  451. if (includeMargins) {
  452. return el[size === 'width' ? 'offsetWidth' : 'offsetHeight'] + parseFloat(window.getComputedStyle(el, null).getPropertyValue(size === 'width' ? 'margin-right' : 'margin-top')) + parseFloat(window.getComputedStyle(el, null).getPropertyValue(size === 'width' ? 'margin-left' : 'margin-bottom'));
  453. }
  454. return el.offsetWidth;
  455. }
  456. function makeElementsArray(el) {
  457. return (Array.isArray(el) ? el : [el]).filter(e => !!e);
  458. }
  459. function getRotateFix(swiper) {
  460. return v => {
  461. if (Math.abs(v) > 0 && swiper.browser && swiper.browser.need3dFix && Math.abs(v) % 90 === 0) {
  462. return v + 0.001;
  463. }
  464. return v;
  465. };
  466. }
  467. let support;
  468. function calcSupport() {
  469. const window = getWindow();
  470. const document = getDocument();
  471. return {
  472. smoothScroll: document.documentElement && document.documentElement.style && 'scrollBehavior' in document.documentElement.style,
  473. touch: !!('ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch)
  474. };
  475. }
  476. function getSupport() {
  477. if (!support) {
  478. support = calcSupport();
  479. }
  480. return support;
  481. }
  482. let deviceCached;
  483. function calcDevice(_temp) {
  484. let {
  485. userAgent
  486. } = _temp === void 0 ? {} : _temp;
  487. const support = getSupport();
  488. const window = getWindow();
  489. const platform = window.navigator.platform;
  490. const ua = userAgent || window.navigator.userAgent;
  491. const device = {
  492. ios: false,
  493. android: false
  494. };
  495. const screenWidth = window.screen.width;
  496. const screenHeight = window.screen.height;
  497. const android = ua.match(/(Android);?[\s\/]+([\d.]+)?/); // eslint-disable-line
  498. let ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  499. const ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  500. const iphone = !ipad && ua.match(/(iPhone\sOS|iOS)\s([\d_]+)/);
  501. const windows = platform === 'Win32';
  502. let macos = platform === 'MacIntel';
  503. // iPadOs 13 fix
  504. const iPadScreens = ['1024x1366', '1366x1024', '834x1194', '1194x834', '834x1112', '1112x834', '768x1024', '1024x768', '820x1180', '1180x820', '810x1080', '1080x810'];
  505. if (!ipad && macos && support.touch && iPadScreens.indexOf(`${screenWidth}x${screenHeight}`) >= 0) {
  506. ipad = ua.match(/(Version)\/([\d.]+)/);
  507. if (!ipad) ipad = [0, 1, '13_0_0'];
  508. macos = false;
  509. }
  510. // Android
  511. if (android && !windows) {
  512. device.os = 'android';
  513. device.android = true;
  514. }
  515. if (ipad || iphone || ipod) {
  516. device.os = 'ios';
  517. device.ios = true;
  518. }
  519. // Export object
  520. return device;
  521. }
  522. function getDevice(overrides) {
  523. if (overrides === void 0) {
  524. overrides = {};
  525. }
  526. if (!deviceCached) {
  527. deviceCached = calcDevice(overrides);
  528. }
  529. return deviceCached;
  530. }
  531. let browser;
  532. function calcBrowser() {
  533. const window = getWindow();
  534. const device = getDevice();
  535. let needPerspectiveFix = false;
  536. function isSafari() {
  537. const ua = window.navigator.userAgent.toLowerCase();
  538. return ua.indexOf('safari') >= 0 && ua.indexOf('chrome') < 0 && ua.indexOf('android') < 0;
  539. }
  540. if (isSafari()) {
  541. const ua = String(window.navigator.userAgent);
  542. if (ua.includes('Version/')) {
  543. const [major, minor] = ua.split('Version/')[1].split(' ')[0].split('.').map(num => Number(num));
  544. needPerspectiveFix = major < 16 || major === 16 && minor < 2;
  545. }
  546. }
  547. const isWebView = /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(window.navigator.userAgent);
  548. const isSafariBrowser = isSafari();
  549. const need3dFix = isSafariBrowser || isWebView && device.ios;
  550. return {
  551. isSafari: needPerspectiveFix || isSafariBrowser,
  552. needPerspectiveFix,
  553. need3dFix,
  554. isWebView
  555. };
  556. }
  557. function getBrowser() {
  558. if (!browser) {
  559. browser = calcBrowser();
  560. }
  561. return browser;
  562. }
  563. function Resize(_ref) {
  564. let {
  565. swiper,
  566. on,
  567. emit
  568. } = _ref;
  569. const window = getWindow();
  570. let observer = null;
  571. let animationFrame = null;
  572. const resizeHandler = () => {
  573. if (!swiper || swiper.destroyed || !swiper.initialized) return;
  574. emit('beforeResize');
  575. emit('resize');
  576. };
  577. const createObserver = () => {
  578. if (!swiper || swiper.destroyed || !swiper.initialized) return;
  579. observer = new ResizeObserver(entries => {
  580. animationFrame = window.requestAnimationFrame(() => {
  581. const {
  582. width,
  583. height
  584. } = swiper;
  585. let newWidth = width;
  586. let newHeight = height;
  587. entries.forEach(_ref2 => {
  588. let {
  589. contentBoxSize,
  590. contentRect,
  591. target
  592. } = _ref2;
  593. if (target && target !== swiper.el) return;
  594. newWidth = contentRect ? contentRect.width : (contentBoxSize[0] || contentBoxSize).inlineSize;
  595. newHeight = contentRect ? contentRect.height : (contentBoxSize[0] || contentBoxSize).blockSize;
  596. });
  597. if (newWidth !== width || newHeight !== height) {
  598. resizeHandler();
  599. }
  600. });
  601. });
  602. observer.observe(swiper.el);
  603. };
  604. const removeObserver = () => {
  605. if (animationFrame) {
  606. window.cancelAnimationFrame(animationFrame);
  607. }
  608. if (observer && observer.unobserve && swiper.el) {
  609. observer.unobserve(swiper.el);
  610. observer = null;
  611. }
  612. };
  613. const orientationChangeHandler = () => {
  614. if (!swiper || swiper.destroyed || !swiper.initialized) return;
  615. emit('orientationchange');
  616. };
  617. on('init', () => {
  618. if (swiper.params.resizeObserver && typeof window.ResizeObserver !== 'undefined') {
  619. createObserver();
  620. return;
  621. }
  622. window.addEventListener('resize', resizeHandler);
  623. window.addEventListener('orientationchange', orientationChangeHandler);
  624. });
  625. on('destroy', () => {
  626. removeObserver();
  627. window.removeEventListener('resize', resizeHandler);
  628. window.removeEventListener('orientationchange', orientationChangeHandler);
  629. });
  630. }
  631. function Observer(_ref) {
  632. let {
  633. swiper,
  634. extendParams,
  635. on,
  636. emit
  637. } = _ref;
  638. const observers = [];
  639. const window = getWindow();
  640. const attach = function (target, options) {
  641. if (options === void 0) {
  642. options = {};
  643. }
  644. const ObserverFunc = window.MutationObserver || window.WebkitMutationObserver;
  645. const observer = new ObserverFunc(mutations => {
  646. // The observerUpdate event should only be triggered
  647. // once despite the number of mutations. Additional
  648. // triggers are redundant and are very costly
  649. if (swiper.__preventObserver__) return;
  650. if (mutations.length === 1) {
  651. emit('observerUpdate', mutations[0]);
  652. return;
  653. }
  654. const observerUpdate = function observerUpdate() {
  655. emit('observerUpdate', mutations[0]);
  656. };
  657. if (window.requestAnimationFrame) {
  658. window.requestAnimationFrame(observerUpdate);
  659. } else {
  660. window.setTimeout(observerUpdate, 0);
  661. }
  662. });
  663. observer.observe(target, {
  664. attributes: typeof options.attributes === 'undefined' ? true : options.attributes,
  665. childList: swiper.isElement || (typeof options.childList === 'undefined' ? true : options).childList,
  666. characterData: typeof options.characterData === 'undefined' ? true : options.characterData
  667. });
  668. observers.push(observer);
  669. };
  670. const init = () => {
  671. if (!swiper.params.observer) return;
  672. if (swiper.params.observeParents) {
  673. const containerParents = elementParents(swiper.hostEl);
  674. for (let i = 0; i < containerParents.length; i += 1) {
  675. attach(containerParents[i]);
  676. }
  677. }
  678. // Observe container
  679. attach(swiper.hostEl, {
  680. childList: swiper.params.observeSlideChildren
  681. });
  682. // Observe wrapper
  683. attach(swiper.wrapperEl, {
  684. attributes: false
  685. });
  686. };
  687. const destroy = () => {
  688. observers.forEach(observer => {
  689. observer.disconnect();
  690. });
  691. observers.splice(0, observers.length);
  692. };
  693. extendParams({
  694. observer: false,
  695. observeParents: false,
  696. observeSlideChildren: false
  697. });
  698. on('init', init);
  699. on('destroy', destroy);
  700. }
  701. /* eslint-disable no-underscore-dangle */
  702. var eventsEmitter = {
  703. on(events, handler, priority) {
  704. const self = this;
  705. if (!self.eventsListeners || self.destroyed) return self;
  706. if (typeof handler !== 'function') return self;
  707. const method = priority ? 'unshift' : 'push';
  708. events.split(' ').forEach(event => {
  709. if (!self.eventsListeners[event]) self.eventsListeners[event] = [];
  710. self.eventsListeners[event][method](handler);
  711. });
  712. return self;
  713. },
  714. once(events, handler, priority) {
  715. const self = this;
  716. if (!self.eventsListeners || self.destroyed) return self;
  717. if (typeof handler !== 'function') return self;
  718. function onceHandler() {
  719. self.off(events, onceHandler);
  720. if (onceHandler.__emitterProxy) {
  721. delete onceHandler.__emitterProxy;
  722. }
  723. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  724. args[_key] = arguments[_key];
  725. }
  726. handler.apply(self, args);
  727. }
  728. onceHandler.__emitterProxy = handler;
  729. return self.on(events, onceHandler, priority);
  730. },
  731. onAny(handler, priority) {
  732. const self = this;
  733. if (!self.eventsListeners || self.destroyed) return self;
  734. if (typeof handler !== 'function') return self;
  735. const method = priority ? 'unshift' : 'push';
  736. if (self.eventsAnyListeners.indexOf(handler) < 0) {
  737. self.eventsAnyListeners[method](handler);
  738. }
  739. return self;
  740. },
  741. offAny(handler) {
  742. const self = this;
  743. if (!self.eventsListeners || self.destroyed) return self;
  744. if (!self.eventsAnyListeners) return self;
  745. const index = self.eventsAnyListeners.indexOf(handler);
  746. if (index >= 0) {
  747. self.eventsAnyListeners.splice(index, 1);
  748. }
  749. return self;
  750. },
  751. off(events, handler) {
  752. const self = this;
  753. if (!self.eventsListeners || self.destroyed) return self;
  754. if (!self.eventsListeners) return self;
  755. events.split(' ').forEach(event => {
  756. if (typeof handler === 'undefined') {
  757. self.eventsListeners[event] = [];
  758. } else if (self.eventsListeners[event]) {
  759. self.eventsListeners[event].forEach((eventHandler, index) => {
  760. if (eventHandler === handler || eventHandler.__emitterProxy && eventHandler.__emitterProxy === handler) {
  761. self.eventsListeners[event].splice(index, 1);
  762. }
  763. });
  764. }
  765. });
  766. return self;
  767. },
  768. emit() {
  769. const self = this;
  770. if (!self.eventsListeners || self.destroyed) return self;
  771. if (!self.eventsListeners) return self;
  772. let events;
  773. let data;
  774. let context;
  775. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  776. args[_key2] = arguments[_key2];
  777. }
  778. if (typeof args[0] === 'string' || Array.isArray(args[0])) {
  779. events = args[0];
  780. data = args.slice(1, args.length);
  781. context = self;
  782. } else {
  783. events = args[0].events;
  784. data = args[0].data;
  785. context = args[0].context || self;
  786. }
  787. data.unshift(context);
  788. const eventsArray = Array.isArray(events) ? events : events.split(' ');
  789. eventsArray.forEach(event => {
  790. if (self.eventsAnyListeners && self.eventsAnyListeners.length) {
  791. self.eventsAnyListeners.forEach(eventHandler => {
  792. eventHandler.apply(context, [event, ...data]);
  793. });
  794. }
  795. if (self.eventsListeners && self.eventsListeners[event]) {
  796. self.eventsListeners[event].forEach(eventHandler => {
  797. eventHandler.apply(context, data);
  798. });
  799. }
  800. });
  801. return self;
  802. }
  803. };
  804. function updateSize() {
  805. const swiper = this;
  806. let width;
  807. let height;
  808. const el = swiper.el;
  809. if (typeof swiper.params.width !== 'undefined' && swiper.params.width !== null) {
  810. width = swiper.params.width;
  811. } else {
  812. width = el.clientWidth;
  813. }
  814. if (typeof swiper.params.height !== 'undefined' && swiper.params.height !== null) {
  815. height = swiper.params.height;
  816. } else {
  817. height = el.clientHeight;
  818. }
  819. if (width === 0 && swiper.isHorizontal() || height === 0 && swiper.isVertical()) {
  820. return;
  821. }
  822. // Subtract paddings
  823. width = width - parseInt(elementStyle(el, 'padding-left') || 0, 10) - parseInt(elementStyle(el, 'padding-right') || 0, 10);
  824. height = height - parseInt(elementStyle(el, 'padding-top') || 0, 10) - parseInt(elementStyle(el, 'padding-bottom') || 0, 10);
  825. if (Number.isNaN(width)) width = 0;
  826. if (Number.isNaN(height)) height = 0;
  827. Object.assign(swiper, {
  828. width,
  829. height,
  830. size: swiper.isHorizontal() ? width : height
  831. });
  832. }
  833. function updateSlides() {
  834. const swiper = this;
  835. function getDirectionPropertyValue(node, label) {
  836. return parseFloat(node.getPropertyValue(swiper.getDirectionLabel(label)) || 0);
  837. }
  838. const params = swiper.params;
  839. const {
  840. wrapperEl,
  841. slidesEl,
  842. size: swiperSize,
  843. rtlTranslate: rtl,
  844. wrongRTL
  845. } = swiper;
  846. const isVirtual = swiper.virtual && params.virtual.enabled;
  847. const previousSlidesLength = isVirtual ? swiper.virtual.slides.length : swiper.slides.length;
  848. const slides = elementChildren(slidesEl, `.${swiper.params.slideClass}, swiper-slide`);
  849. const slidesLength = isVirtual ? swiper.virtual.slides.length : slides.length;
  850. let snapGrid = [];
  851. const slidesGrid = [];
  852. const slidesSizesGrid = [];
  853. let offsetBefore = params.slidesOffsetBefore;
  854. if (typeof offsetBefore === 'function') {
  855. offsetBefore = params.slidesOffsetBefore.call(swiper);
  856. }
  857. let offsetAfter = params.slidesOffsetAfter;
  858. if (typeof offsetAfter === 'function') {
  859. offsetAfter = params.slidesOffsetAfter.call(swiper);
  860. }
  861. const previousSnapGridLength = swiper.snapGrid.length;
  862. const previousSlidesGridLength = swiper.slidesGrid.length;
  863. let spaceBetween = params.spaceBetween;
  864. let slidePosition = -offsetBefore;
  865. let prevSlideSize = 0;
  866. let index = 0;
  867. if (typeof swiperSize === 'undefined') {
  868. return;
  869. }
  870. if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
  871. spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * swiperSize;
  872. } else if (typeof spaceBetween === 'string') {
  873. spaceBetween = parseFloat(spaceBetween);
  874. }
  875. swiper.virtualSize = -spaceBetween;
  876. // reset margins
  877. slides.forEach(slideEl => {
  878. if (rtl) {
  879. slideEl.style.marginLeft = '';
  880. } else {
  881. slideEl.style.marginRight = '';
  882. }
  883. slideEl.style.marginBottom = '';
  884. slideEl.style.marginTop = '';
  885. });
  886. // reset cssMode offsets
  887. if (params.centeredSlides && params.cssMode) {
  888. setCSSProperty(wrapperEl, '--swiper-centered-offset-before', '');
  889. setCSSProperty(wrapperEl, '--swiper-centered-offset-after', '');
  890. }
  891. const gridEnabled = params.grid && params.grid.rows > 1 && swiper.grid;
  892. if (gridEnabled) {
  893. swiper.grid.initSlides(slides);
  894. } else if (swiper.grid) {
  895. swiper.grid.unsetSlides();
  896. }
  897. // Calc slides
  898. let slideSize;
  899. const shouldResetSlideSize = params.slidesPerView === 'auto' && params.breakpoints && Object.keys(params.breakpoints).filter(key => {
  900. return typeof params.breakpoints[key].slidesPerView !== 'undefined';
  901. }).length > 0;
  902. for (let i = 0; i < slidesLength; i += 1) {
  903. slideSize = 0;
  904. let slide;
  905. if (slides[i]) slide = slides[i];
  906. if (gridEnabled) {
  907. swiper.grid.updateSlide(i, slide, slides);
  908. }
  909. if (slides[i] && elementStyle(slide, 'display') === 'none') continue; // eslint-disable-line
  910. if (params.slidesPerView === 'auto') {
  911. if (shouldResetSlideSize) {
  912. slides[i].style[swiper.getDirectionLabel('width')] = ``;
  913. }
  914. const slideStyles = getComputedStyle(slide);
  915. const currentTransform = slide.style.transform;
  916. const currentWebKitTransform = slide.style.webkitTransform;
  917. if (currentTransform) {
  918. slide.style.transform = 'none';
  919. }
  920. if (currentWebKitTransform) {
  921. slide.style.webkitTransform = 'none';
  922. }
  923. if (params.roundLengths) {
  924. slideSize = swiper.isHorizontal() ? elementOuterSize(slide, 'width', true) : elementOuterSize(slide, 'height', true);
  925. } else {
  926. // eslint-disable-next-line
  927. const width = getDirectionPropertyValue(slideStyles, 'width');
  928. const paddingLeft = getDirectionPropertyValue(slideStyles, 'padding-left');
  929. const paddingRight = getDirectionPropertyValue(slideStyles, 'padding-right');
  930. const marginLeft = getDirectionPropertyValue(slideStyles, 'margin-left');
  931. const marginRight = getDirectionPropertyValue(slideStyles, 'margin-right');
  932. const boxSizing = slideStyles.getPropertyValue('box-sizing');
  933. if (boxSizing && boxSizing === 'border-box') {
  934. slideSize = width + marginLeft + marginRight;
  935. } else {
  936. const {
  937. clientWidth,
  938. offsetWidth
  939. } = slide;
  940. slideSize = width + paddingLeft + paddingRight + marginLeft + marginRight + (offsetWidth - clientWidth);
  941. }
  942. }
  943. if (currentTransform) {
  944. slide.style.transform = currentTransform;
  945. }
  946. if (currentWebKitTransform) {
  947. slide.style.webkitTransform = currentWebKitTransform;
  948. }
  949. if (params.roundLengths) slideSize = Math.floor(slideSize);
  950. } else {
  951. slideSize = (swiperSize - (params.slidesPerView - 1) * spaceBetween) / params.slidesPerView;
  952. if (params.roundLengths) slideSize = Math.floor(slideSize);
  953. if (slides[i]) {
  954. slides[i].style[swiper.getDirectionLabel('width')] = `${slideSize}px`;
  955. }
  956. }
  957. if (slides[i]) {
  958. slides[i].swiperSlideSize = slideSize;
  959. }
  960. slidesSizesGrid.push(slideSize);
  961. if (params.centeredSlides) {
  962. slidePosition = slidePosition + slideSize / 2 + prevSlideSize / 2 + spaceBetween;
  963. if (prevSlideSize === 0 && i !== 0) slidePosition = slidePosition - swiperSize / 2 - spaceBetween;
  964. if (i === 0) slidePosition = slidePosition - swiperSize / 2 - spaceBetween;
  965. if (Math.abs(slidePosition) < 1 / 1000) slidePosition = 0;
  966. if (params.roundLengths) slidePosition = Math.floor(slidePosition);
  967. if (index % params.slidesPerGroup === 0) snapGrid.push(slidePosition);
  968. slidesGrid.push(slidePosition);
  969. } else {
  970. if (params.roundLengths) slidePosition = Math.floor(slidePosition);
  971. if ((index - Math.min(swiper.params.slidesPerGroupSkip, index)) % swiper.params.slidesPerGroup === 0) snapGrid.push(slidePosition);
  972. slidesGrid.push(slidePosition);
  973. slidePosition = slidePosition + slideSize + spaceBetween;
  974. }
  975. swiper.virtualSize += slideSize + spaceBetween;
  976. prevSlideSize = slideSize;
  977. index += 1;
  978. }
  979. swiper.virtualSize = Math.max(swiper.virtualSize, swiperSize) + offsetAfter;
  980. if (rtl && wrongRTL && (params.effect === 'slide' || params.effect === 'coverflow')) {
  981. wrapperEl.style.width = `${swiper.virtualSize + spaceBetween}px`;
  982. }
  983. if (params.setWrapperSize) {
  984. wrapperEl.style[swiper.getDirectionLabel('width')] = `${swiper.virtualSize + spaceBetween}px`;
  985. }
  986. if (gridEnabled) {
  987. swiper.grid.updateWrapperSize(slideSize, snapGrid);
  988. }
  989. // Remove last grid elements depending on width
  990. if (!params.centeredSlides) {
  991. const newSlidesGrid = [];
  992. for (let i = 0; i < snapGrid.length; i += 1) {
  993. let slidesGridItem = snapGrid[i];
  994. if (params.roundLengths) slidesGridItem = Math.floor(slidesGridItem);
  995. if (snapGrid[i] <= swiper.virtualSize - swiperSize) {
  996. newSlidesGrid.push(slidesGridItem);
  997. }
  998. }
  999. snapGrid = newSlidesGrid;
  1000. if (Math.floor(swiper.virtualSize - swiperSize) - Math.floor(snapGrid[snapGrid.length - 1]) > 1) {
  1001. snapGrid.push(swiper.virtualSize - swiperSize);
  1002. }
  1003. }
  1004. if (isVirtual && params.loop) {
  1005. const size = slidesSizesGrid[0] + spaceBetween;
  1006. if (params.slidesPerGroup > 1) {
  1007. const groups = Math.ceil((swiper.virtual.slidesBefore + swiper.virtual.slidesAfter) / params.slidesPerGroup);
  1008. const groupSize = size * params.slidesPerGroup;
  1009. for (let i = 0; i < groups; i += 1) {
  1010. snapGrid.push(snapGrid[snapGrid.length - 1] + groupSize);
  1011. }
  1012. }
  1013. for (let i = 0; i < swiper.virtual.slidesBefore + swiper.virtual.slidesAfter; i += 1) {
  1014. if (params.slidesPerGroup === 1) {
  1015. snapGrid.push(snapGrid[snapGrid.length - 1] + size);
  1016. }
  1017. slidesGrid.push(slidesGrid[slidesGrid.length - 1] + size);
  1018. swiper.virtualSize += size;
  1019. }
  1020. }
  1021. if (snapGrid.length === 0) snapGrid = [0];
  1022. if (spaceBetween !== 0) {
  1023. const key = swiper.isHorizontal() && rtl ? 'marginLeft' : swiper.getDirectionLabel('marginRight');
  1024. slides.filter((_, slideIndex) => {
  1025. if (!params.cssMode || params.loop) return true;
  1026. if (slideIndex === slides.length - 1) {
  1027. return false;
  1028. }
  1029. return true;
  1030. }).forEach(slideEl => {
  1031. slideEl.style[key] = `${spaceBetween}px`;
  1032. });
  1033. }
  1034. if (params.centeredSlides && params.centeredSlidesBounds) {
  1035. let allSlidesSize = 0;
  1036. slidesSizesGrid.forEach(slideSizeValue => {
  1037. allSlidesSize += slideSizeValue + (spaceBetween || 0);
  1038. });
  1039. allSlidesSize -= spaceBetween;
  1040. const maxSnap = allSlidesSize > swiperSize ? allSlidesSize - swiperSize : 0;
  1041. snapGrid = snapGrid.map(snap => {
  1042. if (snap <= 0) return -offsetBefore;
  1043. if (snap > maxSnap) return maxSnap + offsetAfter;
  1044. return snap;
  1045. });
  1046. }
  1047. if (params.centerInsufficientSlides) {
  1048. let allSlidesSize = 0;
  1049. slidesSizesGrid.forEach(slideSizeValue => {
  1050. allSlidesSize += slideSizeValue + (spaceBetween || 0);
  1051. });
  1052. allSlidesSize -= spaceBetween;
  1053. const offsetSize = (params.slidesOffsetBefore || 0) + (params.slidesOffsetAfter || 0);
  1054. if (allSlidesSize + offsetSize < swiperSize) {
  1055. const allSlidesOffset = (swiperSize - allSlidesSize - offsetSize) / 2;
  1056. snapGrid.forEach((snap, snapIndex) => {
  1057. snapGrid[snapIndex] = snap - allSlidesOffset;
  1058. });
  1059. slidesGrid.forEach((snap, snapIndex) => {
  1060. slidesGrid[snapIndex] = snap + allSlidesOffset;
  1061. });
  1062. }
  1063. }
  1064. Object.assign(swiper, {
  1065. slides,
  1066. snapGrid,
  1067. slidesGrid,
  1068. slidesSizesGrid
  1069. });
  1070. if (params.centeredSlides && params.cssMode && !params.centeredSlidesBounds) {
  1071. setCSSProperty(wrapperEl, '--swiper-centered-offset-before', `${-snapGrid[0]}px`);
  1072. setCSSProperty(wrapperEl, '--swiper-centered-offset-after', `${swiper.size / 2 - slidesSizesGrid[slidesSizesGrid.length - 1] / 2}px`);
  1073. const addToSnapGrid = -swiper.snapGrid[0];
  1074. const addToSlidesGrid = -swiper.slidesGrid[0];
  1075. swiper.snapGrid = swiper.snapGrid.map(v => v + addToSnapGrid);
  1076. swiper.slidesGrid = swiper.slidesGrid.map(v => v + addToSlidesGrid);
  1077. }
  1078. if (slidesLength !== previousSlidesLength) {
  1079. swiper.emit('slidesLengthChange');
  1080. }
  1081. if (snapGrid.length !== previousSnapGridLength) {
  1082. if (swiper.params.watchOverflow) swiper.checkOverflow();
  1083. swiper.emit('snapGridLengthChange');
  1084. }
  1085. if (slidesGrid.length !== previousSlidesGridLength) {
  1086. swiper.emit('slidesGridLengthChange');
  1087. }
  1088. if (params.watchSlidesProgress) {
  1089. swiper.updateSlidesOffset();
  1090. }
  1091. swiper.emit('slidesUpdated');
  1092. if (!isVirtual && !params.cssMode && (params.effect === 'slide' || params.effect === 'fade')) {
  1093. const backFaceHiddenClass = `${params.containerModifierClass}backface-hidden`;
  1094. const hasClassBackfaceClassAdded = swiper.el.classList.contains(backFaceHiddenClass);
  1095. if (slidesLength <= params.maxBackfaceHiddenSlides) {
  1096. if (!hasClassBackfaceClassAdded) swiper.el.classList.add(backFaceHiddenClass);
  1097. } else if (hasClassBackfaceClassAdded) {
  1098. swiper.el.classList.remove(backFaceHiddenClass);
  1099. }
  1100. }
  1101. }
  1102. function updateAutoHeight(speed) {
  1103. const swiper = this;
  1104. const activeSlides = [];
  1105. const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
  1106. let newHeight = 0;
  1107. let i;
  1108. if (typeof speed === 'number') {
  1109. swiper.setTransition(speed);
  1110. } else if (speed === true) {
  1111. swiper.setTransition(swiper.params.speed);
  1112. }
  1113. const getSlideByIndex = index => {
  1114. if (isVirtual) {
  1115. return swiper.slides[swiper.getSlideIndexByData(index)];
  1116. }
  1117. return swiper.slides[index];
  1118. };
  1119. // Find slides currently in view
  1120. if (swiper.params.slidesPerView !== 'auto' && swiper.params.slidesPerView > 1) {
  1121. if (swiper.params.centeredSlides) {
  1122. (swiper.visibleSlides || []).forEach(slide => {
  1123. activeSlides.push(slide);
  1124. });
  1125. } else {
  1126. for (i = 0; i < Math.ceil(swiper.params.slidesPerView); i += 1) {
  1127. const index = swiper.activeIndex + i;
  1128. if (index > swiper.slides.length && !isVirtual) break;
  1129. activeSlides.push(getSlideByIndex(index));
  1130. }
  1131. }
  1132. } else {
  1133. activeSlides.push(getSlideByIndex(swiper.activeIndex));
  1134. }
  1135. // Find new height from highest slide in view
  1136. for (i = 0; i < activeSlides.length; i += 1) {
  1137. if (typeof activeSlides[i] !== 'undefined') {
  1138. const height = activeSlides[i].offsetHeight;
  1139. newHeight = height > newHeight ? height : newHeight;
  1140. }
  1141. }
  1142. // Update Height
  1143. if (newHeight || newHeight === 0) swiper.wrapperEl.style.height = `${newHeight}px`;
  1144. }
  1145. function updateSlidesOffset() {
  1146. const swiper = this;
  1147. const slides = swiper.slides;
  1148. // eslint-disable-next-line
  1149. const minusOffset = swiper.isElement ? swiper.isHorizontal() ? swiper.wrapperEl.offsetLeft : swiper.wrapperEl.offsetTop : 0;
  1150. for (let i = 0; i < slides.length; i += 1) {
  1151. slides[i].swiperSlideOffset = (swiper.isHorizontal() ? slides[i].offsetLeft : slides[i].offsetTop) - minusOffset - swiper.cssOverflowAdjustment();
  1152. }
  1153. }
  1154. const toggleSlideClasses$1 = (slideEl, condition, className) => {
  1155. if (condition && !slideEl.classList.contains(className)) {
  1156. slideEl.classList.add(className);
  1157. } else if (!condition && slideEl.classList.contains(className)) {
  1158. slideEl.classList.remove(className);
  1159. }
  1160. };
  1161. function updateSlidesProgress(translate) {
  1162. if (translate === void 0) {
  1163. translate = this && this.translate || 0;
  1164. }
  1165. const swiper = this;
  1166. const params = swiper.params;
  1167. const {
  1168. slides,
  1169. rtlTranslate: rtl,
  1170. snapGrid
  1171. } = swiper;
  1172. if (slides.length === 0) return;
  1173. if (typeof slides[0].swiperSlideOffset === 'undefined') swiper.updateSlidesOffset();
  1174. let offsetCenter = -translate;
  1175. if (rtl) offsetCenter = translate;
  1176. swiper.visibleSlidesIndexes = [];
  1177. swiper.visibleSlides = [];
  1178. let spaceBetween = params.spaceBetween;
  1179. if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
  1180. spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * swiper.size;
  1181. } else if (typeof spaceBetween === 'string') {
  1182. spaceBetween = parseFloat(spaceBetween);
  1183. }
  1184. for (let i = 0; i < slides.length; i += 1) {
  1185. const slide = slides[i];
  1186. let slideOffset = slide.swiperSlideOffset;
  1187. if (params.cssMode && params.centeredSlides) {
  1188. slideOffset -= slides[0].swiperSlideOffset;
  1189. }
  1190. const slideProgress = (offsetCenter + (params.centeredSlides ? swiper.minTranslate() : 0) - slideOffset) / (slide.swiperSlideSize + spaceBetween);
  1191. const originalSlideProgress = (offsetCenter - snapGrid[0] + (params.centeredSlides ? swiper.minTranslate() : 0) - slideOffset) / (slide.swiperSlideSize + spaceBetween);
  1192. const slideBefore = -(offsetCenter - slideOffset);
  1193. const slideAfter = slideBefore + swiper.slidesSizesGrid[i];
  1194. const isFullyVisible = slideBefore >= 0 && slideBefore <= swiper.size - swiper.slidesSizesGrid[i];
  1195. const isVisible = slideBefore >= 0 && slideBefore < swiper.size - 1 || slideAfter > 1 && slideAfter <= swiper.size || slideBefore <= 0 && slideAfter >= swiper.size;
  1196. if (isVisible) {
  1197. swiper.visibleSlides.push(slide);
  1198. swiper.visibleSlidesIndexes.push(i);
  1199. }
  1200. toggleSlideClasses$1(slide, isVisible, params.slideVisibleClass);
  1201. toggleSlideClasses$1(slide, isFullyVisible, params.slideFullyVisibleClass);
  1202. slide.progress = rtl ? -slideProgress : slideProgress;
  1203. slide.originalProgress = rtl ? -originalSlideProgress : originalSlideProgress;
  1204. }
  1205. }
  1206. function updateProgress(translate) {
  1207. const swiper = this;
  1208. if (typeof translate === 'undefined') {
  1209. const multiplier = swiper.rtlTranslate ? -1 : 1;
  1210. // eslint-disable-next-line
  1211. translate = swiper && swiper.translate && swiper.translate * multiplier || 0;
  1212. }
  1213. const params = swiper.params;
  1214. const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
  1215. let {
  1216. progress,
  1217. isBeginning,
  1218. isEnd,
  1219. progressLoop
  1220. } = swiper;
  1221. const wasBeginning = isBeginning;
  1222. const wasEnd = isEnd;
  1223. if (translatesDiff === 0) {
  1224. progress = 0;
  1225. isBeginning = true;
  1226. isEnd = true;
  1227. } else {
  1228. progress = (translate - swiper.minTranslate()) / translatesDiff;
  1229. const isBeginningRounded = Math.abs(translate - swiper.minTranslate()) < 1;
  1230. const isEndRounded = Math.abs(translate - swiper.maxTranslate()) < 1;
  1231. isBeginning = isBeginningRounded || progress <= 0;
  1232. isEnd = isEndRounded || progress >= 1;
  1233. if (isBeginningRounded) progress = 0;
  1234. if (isEndRounded) progress = 1;
  1235. }
  1236. if (params.loop) {
  1237. const firstSlideIndex = swiper.getSlideIndexByData(0);
  1238. const lastSlideIndex = swiper.getSlideIndexByData(swiper.slides.length - 1);
  1239. const firstSlideTranslate = swiper.slidesGrid[firstSlideIndex];
  1240. const lastSlideTranslate = swiper.slidesGrid[lastSlideIndex];
  1241. const translateMax = swiper.slidesGrid[swiper.slidesGrid.length - 1];
  1242. const translateAbs = Math.abs(translate);
  1243. if (translateAbs >= firstSlideTranslate) {
  1244. progressLoop = (translateAbs - firstSlideTranslate) / translateMax;
  1245. } else {
  1246. progressLoop = (translateAbs + translateMax - lastSlideTranslate) / translateMax;
  1247. }
  1248. if (progressLoop > 1) progressLoop -= 1;
  1249. }
  1250. Object.assign(swiper, {
  1251. progress,
  1252. progressLoop,
  1253. isBeginning,
  1254. isEnd
  1255. });
  1256. if (params.watchSlidesProgress || params.centeredSlides && params.autoHeight) swiper.updateSlidesProgress(translate);
  1257. if (isBeginning && !wasBeginning) {
  1258. swiper.emit('reachBeginning toEdge');
  1259. }
  1260. if (isEnd && !wasEnd) {
  1261. swiper.emit('reachEnd toEdge');
  1262. }
  1263. if (wasBeginning && !isBeginning || wasEnd && !isEnd) {
  1264. swiper.emit('fromEdge');
  1265. }
  1266. swiper.emit('progress', progress);
  1267. }
  1268. const toggleSlideClasses = (slideEl, condition, className) => {
  1269. if (condition && !slideEl.classList.contains(className)) {
  1270. slideEl.classList.add(className);
  1271. } else if (!condition && slideEl.classList.contains(className)) {
  1272. slideEl.classList.remove(className);
  1273. }
  1274. };
  1275. function updateSlidesClasses() {
  1276. const swiper = this;
  1277. const {
  1278. slides,
  1279. params,
  1280. slidesEl,
  1281. activeIndex
  1282. } = swiper;
  1283. const isVirtual = swiper.virtual && params.virtual.enabled;
  1284. const gridEnabled = swiper.grid && params.grid && params.grid.rows > 1;
  1285. const getFilteredSlide = selector => {
  1286. return elementChildren(slidesEl, `.${params.slideClass}${selector}, swiper-slide${selector}`)[0];
  1287. };
  1288. let activeSlide;
  1289. let prevSlide;
  1290. let nextSlide;
  1291. if (isVirtual) {
  1292. if (params.loop) {
  1293. let slideIndex = activeIndex - swiper.virtual.slidesBefore;
  1294. if (slideIndex < 0) slideIndex = swiper.virtual.slides.length + slideIndex;
  1295. if (slideIndex >= swiper.virtual.slides.length) slideIndex -= swiper.virtual.slides.length;
  1296. activeSlide = getFilteredSlide(`[data-swiper-slide-index="${slideIndex}"]`);
  1297. } else {
  1298. activeSlide = getFilteredSlide(`[data-swiper-slide-index="${activeIndex}"]`);
  1299. }
  1300. } else {
  1301. if (gridEnabled) {
  1302. activeSlide = slides.filter(slideEl => slideEl.column === activeIndex)[0];
  1303. nextSlide = slides.filter(slideEl => slideEl.column === activeIndex + 1)[0];
  1304. prevSlide = slides.filter(slideEl => slideEl.column === activeIndex - 1)[0];
  1305. } else {
  1306. activeSlide = slides[activeIndex];
  1307. }
  1308. }
  1309. if (activeSlide) {
  1310. if (!gridEnabled) {
  1311. // Next Slide
  1312. nextSlide = elementNextAll(activeSlide, `.${params.slideClass}, swiper-slide`)[0];
  1313. if (params.loop && !nextSlide) {
  1314. nextSlide = slides[0];
  1315. }
  1316. // Prev Slide
  1317. prevSlide = elementPrevAll(activeSlide, `.${params.slideClass}, swiper-slide`)[0];
  1318. if (params.loop && !prevSlide === 0) {
  1319. prevSlide = slides[slides.length - 1];
  1320. }
  1321. }
  1322. }
  1323. slides.forEach(slideEl => {
  1324. toggleSlideClasses(slideEl, slideEl === activeSlide, params.slideActiveClass);
  1325. toggleSlideClasses(slideEl, slideEl === nextSlide, params.slideNextClass);
  1326. toggleSlideClasses(slideEl, slideEl === prevSlide, params.slidePrevClass);
  1327. });
  1328. swiper.emitSlidesClasses();
  1329. }
  1330. const processLazyPreloader = (swiper, imageEl) => {
  1331. if (!swiper || swiper.destroyed || !swiper.params) return;
  1332. const slideSelector = () => swiper.isElement ? `swiper-slide` : `.${swiper.params.slideClass}`;
  1333. const slideEl = imageEl.closest(slideSelector());
  1334. if (slideEl) {
  1335. let lazyEl = slideEl.querySelector(`.${swiper.params.lazyPreloaderClass}`);
  1336. if (!lazyEl && swiper.isElement) {
  1337. if (slideEl.shadowRoot) {
  1338. lazyEl = slideEl.shadowRoot.querySelector(`.${swiper.params.lazyPreloaderClass}`);
  1339. } else {
  1340. // init later
  1341. requestAnimationFrame(() => {
  1342. if (slideEl.shadowRoot) {
  1343. lazyEl = slideEl.shadowRoot.querySelector(`.${swiper.params.lazyPreloaderClass}`);
  1344. if (lazyEl) lazyEl.remove();
  1345. }
  1346. });
  1347. }
  1348. }
  1349. if (lazyEl) lazyEl.remove();
  1350. }
  1351. };
  1352. const unlazy = (swiper, index) => {
  1353. if (!swiper.slides[index]) return;
  1354. const imageEl = swiper.slides[index].querySelector('[loading="lazy"]');
  1355. if (imageEl) imageEl.removeAttribute('loading');
  1356. };
  1357. const preload = swiper => {
  1358. if (!swiper || swiper.destroyed || !swiper.params) return;
  1359. let amount = swiper.params.lazyPreloadPrevNext;
  1360. const len = swiper.slides.length;
  1361. if (!len || !amount || amount < 0) return;
  1362. amount = Math.min(amount, len);
  1363. const slidesPerView = swiper.params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : Math.ceil(swiper.params.slidesPerView);
  1364. const activeIndex = swiper.activeIndex;
  1365. if (swiper.params.grid && swiper.params.grid.rows > 1) {
  1366. const activeColumn = activeIndex;
  1367. const preloadColumns = [activeColumn - amount];
  1368. preloadColumns.push(...Array.from({
  1369. length: amount
  1370. }).map((_, i) => {
  1371. return activeColumn + slidesPerView + i;
  1372. }));
  1373. swiper.slides.forEach((slideEl, i) => {
  1374. if (preloadColumns.includes(slideEl.column)) unlazy(swiper, i);
  1375. });
  1376. return;
  1377. }
  1378. const slideIndexLastInView = activeIndex + slidesPerView - 1;
  1379. if (swiper.params.rewind || swiper.params.loop) {
  1380. for (let i = activeIndex - amount; i <= slideIndexLastInView + amount; i += 1) {
  1381. const realIndex = (i % len + len) % len;
  1382. if (realIndex < activeIndex || realIndex > slideIndexLastInView) unlazy(swiper, realIndex);
  1383. }
  1384. } else {
  1385. for (let i = Math.max(activeIndex - amount, 0); i <= Math.min(slideIndexLastInView + amount, len - 1); i += 1) {
  1386. if (i !== activeIndex && (i > slideIndexLastInView || i < activeIndex)) {
  1387. unlazy(swiper, i);
  1388. }
  1389. }
  1390. }
  1391. };
  1392. function getActiveIndexByTranslate(swiper) {
  1393. const {
  1394. slidesGrid,
  1395. params
  1396. } = swiper;
  1397. const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
  1398. let activeIndex;
  1399. for (let i = 0; i < slidesGrid.length; i += 1) {
  1400. if (typeof slidesGrid[i + 1] !== 'undefined') {
  1401. if (translate >= slidesGrid[i] && translate < slidesGrid[i + 1] - (slidesGrid[i + 1] - slidesGrid[i]) / 2) {
  1402. activeIndex = i;
  1403. } else if (translate >= slidesGrid[i] && translate < slidesGrid[i + 1]) {
  1404. activeIndex = i + 1;
  1405. }
  1406. } else if (translate >= slidesGrid[i]) {
  1407. activeIndex = i;
  1408. }
  1409. }
  1410. // Normalize slideIndex
  1411. if (params.normalizeSlideIndex) {
  1412. if (activeIndex < 0 || typeof activeIndex === 'undefined') activeIndex = 0;
  1413. }
  1414. return activeIndex;
  1415. }
  1416. function updateActiveIndex(newActiveIndex) {
  1417. const swiper = this;
  1418. const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
  1419. const {
  1420. snapGrid,
  1421. params,
  1422. activeIndex: previousIndex,
  1423. realIndex: previousRealIndex,
  1424. snapIndex: previousSnapIndex
  1425. } = swiper;
  1426. let activeIndex = newActiveIndex;
  1427. let snapIndex;
  1428. const getVirtualRealIndex = aIndex => {
  1429. let realIndex = aIndex - swiper.virtual.slidesBefore;
  1430. if (realIndex < 0) {
  1431. realIndex = swiper.virtual.slides.length + realIndex;
  1432. }
  1433. if (realIndex >= swiper.virtual.slides.length) {
  1434. realIndex -= swiper.virtual.slides.length;
  1435. }
  1436. return realIndex;
  1437. };
  1438. if (typeof activeIndex === 'undefined') {
  1439. activeIndex = getActiveIndexByTranslate(swiper);
  1440. }
  1441. if (snapGrid.indexOf(translate) >= 0) {
  1442. snapIndex = snapGrid.indexOf(translate);
  1443. } else {
  1444. const skip = Math.min(params.slidesPerGroupSkip, activeIndex);
  1445. snapIndex = skip + Math.floor((activeIndex - skip) / params.slidesPerGroup);
  1446. }
  1447. if (snapIndex >= snapGrid.length) snapIndex = snapGrid.length - 1;
  1448. if (activeIndex === previousIndex && !swiper.params.loop) {
  1449. if (snapIndex !== previousSnapIndex) {
  1450. swiper.snapIndex = snapIndex;
  1451. swiper.emit('snapIndexChange');
  1452. }
  1453. return;
  1454. }
  1455. if (activeIndex === previousIndex && swiper.params.loop && swiper.virtual && swiper.params.virtual.enabled) {
  1456. swiper.realIndex = getVirtualRealIndex(activeIndex);
  1457. return;
  1458. }
  1459. const gridEnabled = swiper.grid && params.grid && params.grid.rows > 1;
  1460. // Get real index
  1461. let realIndex;
  1462. if (swiper.virtual && params.virtual.enabled && params.loop) {
  1463. realIndex = getVirtualRealIndex(activeIndex);
  1464. } else if (gridEnabled) {
  1465. const firstSlideInColumn = swiper.slides.filter(slideEl => slideEl.column === activeIndex)[0];
  1466. let activeSlideIndex = parseInt(firstSlideInColumn.getAttribute('data-swiper-slide-index'), 10);
  1467. if (Number.isNaN(activeSlideIndex)) {
  1468. activeSlideIndex = Math.max(swiper.slides.indexOf(firstSlideInColumn), 0);
  1469. }
  1470. realIndex = Math.floor(activeSlideIndex / params.grid.rows);
  1471. } else if (swiper.slides[activeIndex]) {
  1472. const slideIndex = swiper.slides[activeIndex].getAttribute('data-swiper-slide-index');
  1473. if (slideIndex) {
  1474. realIndex = parseInt(slideIndex, 10);
  1475. } else {
  1476. realIndex = activeIndex;
  1477. }
  1478. } else {
  1479. realIndex = activeIndex;
  1480. }
  1481. Object.assign(swiper, {
  1482. previousSnapIndex,
  1483. snapIndex,
  1484. previousRealIndex,
  1485. realIndex,
  1486. previousIndex,
  1487. activeIndex
  1488. });
  1489. if (swiper.initialized) {
  1490. preload(swiper);
  1491. }
  1492. swiper.emit('activeIndexChange');
  1493. swiper.emit('snapIndexChange');
  1494. if (swiper.initialized || swiper.params.runCallbacksOnInit) {
  1495. if (previousRealIndex !== realIndex) {
  1496. swiper.emit('realIndexChange');
  1497. }
  1498. swiper.emit('slideChange');
  1499. }
  1500. }
  1501. function updateClickedSlide(el, path) {
  1502. const swiper = this;
  1503. const params = swiper.params;
  1504. let slide = el.closest(`.${params.slideClass}, swiper-slide`);
  1505. if (!slide && swiper.isElement && path && path.length > 1 && path.includes(el)) {
  1506. [...path.slice(path.indexOf(el) + 1, path.length)].forEach(pathEl => {
  1507. if (!slide && pathEl.matches && pathEl.matches(`.${params.slideClass}, swiper-slide`)) {
  1508. slide = pathEl;
  1509. }
  1510. });
  1511. }
  1512. let slideFound = false;
  1513. let slideIndex;
  1514. if (slide) {
  1515. for (let i = 0; i < swiper.slides.length; i += 1) {
  1516. if (swiper.slides[i] === slide) {
  1517. slideFound = true;
  1518. slideIndex = i;
  1519. break;
  1520. }
  1521. }
  1522. }
  1523. if (slide && slideFound) {
  1524. swiper.clickedSlide = slide;
  1525. if (swiper.virtual && swiper.params.virtual.enabled) {
  1526. swiper.clickedIndex = parseInt(slide.getAttribute('data-swiper-slide-index'), 10);
  1527. } else {
  1528. swiper.clickedIndex = slideIndex;
  1529. }
  1530. } else {
  1531. swiper.clickedSlide = undefined;
  1532. swiper.clickedIndex = undefined;
  1533. return;
  1534. }
  1535. if (params.slideToClickedSlide && swiper.clickedIndex !== undefined && swiper.clickedIndex !== swiper.activeIndex) {
  1536. swiper.slideToClickedSlide();
  1537. }
  1538. }
  1539. var update = {
  1540. updateSize,
  1541. updateSlides,
  1542. updateAutoHeight,
  1543. updateSlidesOffset,
  1544. updateSlidesProgress,
  1545. updateProgress,
  1546. updateSlidesClasses,
  1547. updateActiveIndex,
  1548. updateClickedSlide
  1549. };
  1550. function getSwiperTranslate(axis) {
  1551. if (axis === void 0) {
  1552. axis = this.isHorizontal() ? 'x' : 'y';
  1553. }
  1554. const swiper = this;
  1555. const {
  1556. params,
  1557. rtlTranslate: rtl,
  1558. translate,
  1559. wrapperEl
  1560. } = swiper;
  1561. if (params.virtualTranslate) {
  1562. return rtl ? -translate : translate;
  1563. }
  1564. if (params.cssMode) {
  1565. return translate;
  1566. }
  1567. let currentTranslate = getTranslate(wrapperEl, axis);
  1568. currentTranslate += swiper.cssOverflowAdjustment();
  1569. if (rtl) currentTranslate = -currentTranslate;
  1570. return currentTranslate || 0;
  1571. }
  1572. function setTranslate(translate, byController) {
  1573. const swiper = this;
  1574. const {
  1575. rtlTranslate: rtl,
  1576. params,
  1577. wrapperEl,
  1578. progress
  1579. } = swiper;
  1580. let x = 0;
  1581. let y = 0;
  1582. const z = 0;
  1583. if (swiper.isHorizontal()) {
  1584. x = rtl ? -translate : translate;
  1585. } else {
  1586. y = translate;
  1587. }
  1588. if (params.roundLengths) {
  1589. x = Math.floor(x);
  1590. y = Math.floor(y);
  1591. }
  1592. swiper.previousTranslate = swiper.translate;
  1593. swiper.translate = swiper.isHorizontal() ? x : y;
  1594. if (params.cssMode) {
  1595. wrapperEl[swiper.isHorizontal() ? 'scrollLeft' : 'scrollTop'] = swiper.isHorizontal() ? -x : -y;
  1596. } else if (!params.virtualTranslate) {
  1597. if (swiper.isHorizontal()) {
  1598. x -= swiper.cssOverflowAdjustment();
  1599. } else {
  1600. y -= swiper.cssOverflowAdjustment();
  1601. }
  1602. wrapperEl.style.transform = `translate3d(${x}px, ${y}px, ${z}px)`;
  1603. }
  1604. // Check if we need to update progress
  1605. let newProgress;
  1606. const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
  1607. if (translatesDiff === 0) {
  1608. newProgress = 0;
  1609. } else {
  1610. newProgress = (translate - swiper.minTranslate()) / translatesDiff;
  1611. }
  1612. if (newProgress !== progress) {
  1613. swiper.updateProgress(translate);
  1614. }
  1615. swiper.emit('setTranslate', swiper.translate, byController);
  1616. }
  1617. function minTranslate() {
  1618. return -this.snapGrid[0];
  1619. }
  1620. function maxTranslate() {
  1621. return -this.snapGrid[this.snapGrid.length - 1];
  1622. }
  1623. function translateTo(translate, speed, runCallbacks, translateBounds, internal) {
  1624. if (translate === void 0) {
  1625. translate = 0;
  1626. }
  1627. if (speed === void 0) {
  1628. speed = this.params.speed;
  1629. }
  1630. if (runCallbacks === void 0) {
  1631. runCallbacks = true;
  1632. }
  1633. if (translateBounds === void 0) {
  1634. translateBounds = true;
  1635. }
  1636. const swiper = this;
  1637. const {
  1638. params,
  1639. wrapperEl
  1640. } = swiper;
  1641. if (swiper.animating && params.preventInteractionOnTransition) {
  1642. return false;
  1643. }
  1644. const minTranslate = swiper.minTranslate();
  1645. const maxTranslate = swiper.maxTranslate();
  1646. let newTranslate;
  1647. if (translateBounds && translate > minTranslate) newTranslate = minTranslate;else if (translateBounds && translate < maxTranslate) newTranslate = maxTranslate;else newTranslate = translate;
  1648. // Update progress
  1649. swiper.updateProgress(newTranslate);
  1650. if (params.cssMode) {
  1651. const isH = swiper.isHorizontal();
  1652. if (speed === 0) {
  1653. wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = -newTranslate;
  1654. } else {
  1655. if (!swiper.support.smoothScroll) {
  1656. animateCSSModeScroll({
  1657. swiper,
  1658. targetPosition: -newTranslate,
  1659. side: isH ? 'left' : 'top'
  1660. });
  1661. return true;
  1662. }
  1663. wrapperEl.scrollTo({
  1664. [isH ? 'left' : 'top']: -newTranslate,
  1665. behavior: 'smooth'
  1666. });
  1667. }
  1668. return true;
  1669. }
  1670. if (speed === 0) {
  1671. swiper.setTransition(0);
  1672. swiper.setTranslate(newTranslate);
  1673. if (runCallbacks) {
  1674. swiper.emit('beforeTransitionStart', speed, internal);
  1675. swiper.emit('transitionEnd');
  1676. }
  1677. } else {
  1678. swiper.setTransition(speed);
  1679. swiper.setTranslate(newTranslate);
  1680. if (runCallbacks) {
  1681. swiper.emit('beforeTransitionStart', speed, internal);
  1682. swiper.emit('transitionStart');
  1683. }
  1684. if (!swiper.animating) {
  1685. swiper.animating = true;
  1686. if (!swiper.onTranslateToWrapperTransitionEnd) {
  1687. swiper.onTranslateToWrapperTransitionEnd = function transitionEnd(e) {
  1688. if (!swiper || swiper.destroyed) return;
  1689. if (e.target !== this) return;
  1690. swiper.wrapperEl.removeEventListener('transitionend', swiper.onTranslateToWrapperTransitionEnd);
  1691. swiper.onTranslateToWrapperTransitionEnd = null;
  1692. delete swiper.onTranslateToWrapperTransitionEnd;
  1693. swiper.animating = false;
  1694. if (runCallbacks) {
  1695. swiper.emit('transitionEnd');
  1696. }
  1697. };
  1698. }
  1699. swiper.wrapperEl.addEventListener('transitionend', swiper.onTranslateToWrapperTransitionEnd);
  1700. }
  1701. }
  1702. return true;
  1703. }
  1704. var translate = {
  1705. getTranslate: getSwiperTranslate,
  1706. setTranslate,
  1707. minTranslate,
  1708. maxTranslate,
  1709. translateTo
  1710. };
  1711. function setTransition(duration, byController) {
  1712. const swiper = this;
  1713. if (!swiper.params.cssMode) {
  1714. swiper.wrapperEl.style.transitionDuration = `${duration}ms`;
  1715. swiper.wrapperEl.style.transitionDelay = duration === 0 ? `0ms` : '';
  1716. }
  1717. swiper.emit('setTransition', duration, byController);
  1718. }
  1719. function transitionEmit(_ref) {
  1720. let {
  1721. swiper,
  1722. runCallbacks,
  1723. direction,
  1724. step
  1725. } = _ref;
  1726. const {
  1727. activeIndex,
  1728. previousIndex
  1729. } = swiper;
  1730. let dir = direction;
  1731. if (!dir) {
  1732. if (activeIndex > previousIndex) dir = 'next';else if (activeIndex < previousIndex) dir = 'prev';else dir = 'reset';
  1733. }
  1734. swiper.emit(`transition${step}`);
  1735. if (runCallbacks && activeIndex !== previousIndex) {
  1736. if (dir === 'reset') {
  1737. swiper.emit(`slideResetTransition${step}`);
  1738. return;
  1739. }
  1740. swiper.emit(`slideChangeTransition${step}`);
  1741. if (dir === 'next') {
  1742. swiper.emit(`slideNextTransition${step}`);
  1743. } else {
  1744. swiper.emit(`slidePrevTransition${step}`);
  1745. }
  1746. }
  1747. }
  1748. function transitionStart(runCallbacks, direction) {
  1749. if (runCallbacks === void 0) {
  1750. runCallbacks = true;
  1751. }
  1752. const swiper = this;
  1753. const {
  1754. params
  1755. } = swiper;
  1756. if (params.cssMode) return;
  1757. if (params.autoHeight) {
  1758. swiper.updateAutoHeight();
  1759. }
  1760. transitionEmit({
  1761. swiper,
  1762. runCallbacks,
  1763. direction,
  1764. step: 'Start'
  1765. });
  1766. }
  1767. function transitionEnd(runCallbacks, direction) {
  1768. if (runCallbacks === void 0) {
  1769. runCallbacks = true;
  1770. }
  1771. const swiper = this;
  1772. const {
  1773. params
  1774. } = swiper;
  1775. swiper.animating = false;
  1776. if (params.cssMode) return;
  1777. swiper.setTransition(0);
  1778. transitionEmit({
  1779. swiper,
  1780. runCallbacks,
  1781. direction,
  1782. step: 'End'
  1783. });
  1784. }
  1785. var transition = {
  1786. setTransition,
  1787. transitionStart,
  1788. transitionEnd
  1789. };
  1790. function slideTo(index, speed, runCallbacks, internal, initial) {
  1791. if (index === void 0) {
  1792. index = 0;
  1793. }
  1794. if (runCallbacks === void 0) {
  1795. runCallbacks = true;
  1796. }
  1797. if (typeof index === 'string') {
  1798. index = parseInt(index, 10);
  1799. }
  1800. const swiper = this;
  1801. let slideIndex = index;
  1802. if (slideIndex < 0) slideIndex = 0;
  1803. const {
  1804. params,
  1805. snapGrid,
  1806. slidesGrid,
  1807. previousIndex,
  1808. activeIndex,
  1809. rtlTranslate: rtl,
  1810. wrapperEl,
  1811. enabled
  1812. } = swiper;
  1813. if (!enabled && !internal && !initial || swiper.destroyed || swiper.animating && params.preventInteractionOnTransition) {
  1814. return false;
  1815. }
  1816. if (typeof speed === 'undefined') {
  1817. speed = swiper.params.speed;
  1818. }
  1819. const skip = Math.min(swiper.params.slidesPerGroupSkip, slideIndex);
  1820. let snapIndex = skip + Math.floor((slideIndex - skip) / swiper.params.slidesPerGroup);
  1821. if (snapIndex >= snapGrid.length) snapIndex = snapGrid.length - 1;
  1822. const translate = -snapGrid[snapIndex];
  1823. // Normalize slideIndex
  1824. if (params.normalizeSlideIndex) {
  1825. for (let i = 0; i < slidesGrid.length; i += 1) {
  1826. const normalizedTranslate = -Math.floor(translate * 100);
  1827. const normalizedGrid = Math.floor(slidesGrid[i] * 100);
  1828. const normalizedGridNext = Math.floor(slidesGrid[i + 1] * 100);
  1829. if (typeof slidesGrid[i + 1] !== 'undefined') {
  1830. if (normalizedTranslate >= normalizedGrid && normalizedTranslate < normalizedGridNext - (normalizedGridNext - normalizedGrid) / 2) {
  1831. slideIndex = i;
  1832. } else if (normalizedTranslate >= normalizedGrid && normalizedTranslate < normalizedGridNext) {
  1833. slideIndex = i + 1;
  1834. }
  1835. } else if (normalizedTranslate >= normalizedGrid) {
  1836. slideIndex = i;
  1837. }
  1838. }
  1839. }
  1840. // Directions locks
  1841. if (swiper.initialized && slideIndex !== activeIndex) {
  1842. if (!swiper.allowSlideNext && (rtl ? translate > swiper.translate && translate > swiper.minTranslate() : translate < swiper.translate && translate < swiper.minTranslate())) {
  1843. return false;
  1844. }
  1845. if (!swiper.allowSlidePrev && translate > swiper.translate && translate > swiper.maxTranslate()) {
  1846. if ((activeIndex || 0) !== slideIndex) {
  1847. return false;
  1848. }
  1849. }
  1850. }
  1851. if (slideIndex !== (previousIndex || 0) && runCallbacks) {
  1852. swiper.emit('beforeSlideChangeStart');
  1853. }
  1854. // Update progress
  1855. swiper.updateProgress(translate);
  1856. let direction;
  1857. if (slideIndex > activeIndex) direction = 'next';else if (slideIndex < activeIndex) direction = 'prev';else direction = 'reset';
  1858. // initial virtual
  1859. const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
  1860. const isInitialVirtual = isVirtual && initial;
  1861. // Update Index
  1862. if (!isInitialVirtual && (rtl && -translate === swiper.translate || !rtl && translate === swiper.translate)) {
  1863. swiper.updateActiveIndex(slideIndex);
  1864. // Update Height
  1865. if (params.autoHeight) {
  1866. swiper.updateAutoHeight();
  1867. }
  1868. swiper.updateSlidesClasses();
  1869. if (params.effect !== 'slide') {
  1870. swiper.setTranslate(translate);
  1871. }
  1872. if (direction !== 'reset') {
  1873. swiper.transitionStart(runCallbacks, direction);
  1874. swiper.transitionEnd(runCallbacks, direction);
  1875. }
  1876. return false;
  1877. }
  1878. if (params.cssMode) {
  1879. const isH = swiper.isHorizontal();
  1880. const t = rtl ? translate : -translate;
  1881. if (speed === 0) {
  1882. if (isVirtual) {
  1883. swiper.wrapperEl.style.scrollSnapType = 'none';
  1884. swiper._immediateVirtual = true;
  1885. }
  1886. if (isVirtual && !swiper._cssModeVirtualInitialSet && swiper.params.initialSlide > 0) {
  1887. swiper._cssModeVirtualInitialSet = true;
  1888. requestAnimationFrame(() => {
  1889. wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = t;
  1890. });
  1891. } else {
  1892. wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = t;
  1893. }
  1894. if (isVirtual) {
  1895. requestAnimationFrame(() => {
  1896. swiper.wrapperEl.style.scrollSnapType = '';
  1897. swiper._immediateVirtual = false;
  1898. });
  1899. }
  1900. } else {
  1901. if (!swiper.support.smoothScroll) {
  1902. animateCSSModeScroll({
  1903. swiper,
  1904. targetPosition: t,
  1905. side: isH ? 'left' : 'top'
  1906. });
  1907. return true;
  1908. }
  1909. wrapperEl.scrollTo({
  1910. [isH ? 'left' : 'top']: t,
  1911. behavior: 'smooth'
  1912. });
  1913. }
  1914. return true;
  1915. }
  1916. swiper.setTransition(speed);
  1917. swiper.setTranslate(translate);
  1918. swiper.updateActiveIndex(slideIndex);
  1919. swiper.updateSlidesClasses();
  1920. swiper.emit('beforeTransitionStart', speed, internal);
  1921. swiper.transitionStart(runCallbacks, direction);
  1922. if (speed === 0) {
  1923. swiper.transitionEnd(runCallbacks, direction);
  1924. } else if (!swiper.animating) {
  1925. swiper.animating = true;
  1926. if (!swiper.onSlideToWrapperTransitionEnd) {
  1927. swiper.onSlideToWrapperTransitionEnd = function transitionEnd(e) {
  1928. if (!swiper || swiper.destroyed) return;
  1929. if (e.target !== this) return;
  1930. swiper.wrapperEl.removeEventListener('transitionend', swiper.onSlideToWrapperTransitionEnd);
  1931. swiper.onSlideToWrapperTransitionEnd = null;
  1932. delete swiper.onSlideToWrapperTransitionEnd;
  1933. swiper.transitionEnd(runCallbacks, direction);
  1934. };
  1935. }
  1936. swiper.wrapperEl.addEventListener('transitionend', swiper.onSlideToWrapperTransitionEnd);
  1937. }
  1938. return true;
  1939. }
  1940. function slideToLoop(index, speed, runCallbacks, internal) {
  1941. if (index === void 0) {
  1942. index = 0;
  1943. }
  1944. if (runCallbacks === void 0) {
  1945. runCallbacks = true;
  1946. }
  1947. if (typeof index === 'string') {
  1948. const indexAsNumber = parseInt(index, 10);
  1949. index = indexAsNumber;
  1950. }
  1951. const swiper = this;
  1952. if (swiper.destroyed) return;
  1953. if (typeof speed === 'undefined') {
  1954. speed = swiper.params.speed;
  1955. }
  1956. const gridEnabled = swiper.grid && swiper.params.grid && swiper.params.grid.rows > 1;
  1957. let newIndex = index;
  1958. if (swiper.params.loop) {
  1959. if (swiper.virtual && swiper.params.virtual.enabled) {
  1960. // eslint-disable-next-line
  1961. newIndex = newIndex + swiper.virtual.slidesBefore;
  1962. } else {
  1963. let targetSlideIndex;
  1964. if (gridEnabled) {
  1965. const slideIndex = newIndex * swiper.params.grid.rows;
  1966. targetSlideIndex = swiper.slides.filter(slideEl => slideEl.getAttribute('data-swiper-slide-index') * 1 === slideIndex)[0].column;
  1967. } else {
  1968. targetSlideIndex = swiper.getSlideIndexByData(newIndex);
  1969. }
  1970. const cols = gridEnabled ? Math.ceil(swiper.slides.length / swiper.params.grid.rows) : swiper.slides.length;
  1971. const {
  1972. centeredSlides
  1973. } = swiper.params;
  1974. let slidesPerView = swiper.params.slidesPerView;
  1975. if (slidesPerView === 'auto') {
  1976. slidesPerView = swiper.slidesPerViewDynamic();
  1977. } else {
  1978. slidesPerView = Math.ceil(parseFloat(swiper.params.slidesPerView, 10));
  1979. if (centeredSlides && slidesPerView % 2 === 0) {
  1980. slidesPerView = slidesPerView + 1;
  1981. }
  1982. }
  1983. let needLoopFix = cols - targetSlideIndex < slidesPerView;
  1984. if (centeredSlides) {
  1985. needLoopFix = needLoopFix || targetSlideIndex < Math.ceil(slidesPerView / 2);
  1986. }
  1987. if (internal && centeredSlides && swiper.params.slidesPerView !== 'auto' && !gridEnabled) {
  1988. needLoopFix = false;
  1989. }
  1990. if (needLoopFix) {
  1991. const direction = centeredSlides ? targetSlideIndex < swiper.activeIndex ? 'prev' : 'next' : targetSlideIndex - swiper.activeIndex - 1 < swiper.params.slidesPerView ? 'next' : 'prev';
  1992. swiper.loopFix({
  1993. direction,
  1994. slideTo: true,
  1995. activeSlideIndex: direction === 'next' ? targetSlideIndex + 1 : targetSlideIndex - cols + 1,
  1996. slideRealIndex: direction === 'next' ? swiper.realIndex : undefined
  1997. });
  1998. }
  1999. if (gridEnabled) {
  2000. const slideIndex = newIndex * swiper.params.grid.rows;
  2001. newIndex = swiper.slides.filter(slideEl => slideEl.getAttribute('data-swiper-slide-index') * 1 === slideIndex)[0].column;
  2002. } else {
  2003. newIndex = swiper.getSlideIndexByData(newIndex);
  2004. }
  2005. }
  2006. }
  2007. requestAnimationFrame(() => {
  2008. swiper.slideTo(newIndex, speed, runCallbacks, internal);
  2009. });
  2010. return swiper;
  2011. }
  2012. /* eslint no-unused-vars: "off" */
  2013. function slideNext(speed, runCallbacks, internal) {
  2014. if (runCallbacks === void 0) {
  2015. runCallbacks = true;
  2016. }
  2017. const swiper = this;
  2018. const {
  2019. enabled,
  2020. params,
  2021. animating
  2022. } = swiper;
  2023. if (!enabled || swiper.destroyed) return swiper;
  2024. if (typeof speed === 'undefined') {
  2025. speed = swiper.params.speed;
  2026. }
  2027. let perGroup = params.slidesPerGroup;
  2028. if (params.slidesPerView === 'auto' && params.slidesPerGroup === 1 && params.slidesPerGroupAuto) {
  2029. perGroup = Math.max(swiper.slidesPerViewDynamic('current', true), 1);
  2030. }
  2031. const increment = swiper.activeIndex < params.slidesPerGroupSkip ? 1 : perGroup;
  2032. const isVirtual = swiper.virtual && params.virtual.enabled;
  2033. if (params.loop) {
  2034. if (animating && !isVirtual && params.loopPreventsSliding) return false;
  2035. swiper.loopFix({
  2036. direction: 'next'
  2037. });
  2038. // eslint-disable-next-line
  2039. swiper._clientLeft = swiper.wrapperEl.clientLeft;
  2040. if (swiper.activeIndex === swiper.slides.length - 1 && params.cssMode) {
  2041. requestAnimationFrame(() => {
  2042. swiper.slideTo(swiper.activeIndex + increment, speed, runCallbacks, internal);
  2043. });
  2044. return true;
  2045. }
  2046. }
  2047. if (params.rewind && swiper.isEnd) {
  2048. return swiper.slideTo(0, speed, runCallbacks, internal);
  2049. }
  2050. return swiper.slideTo(swiper.activeIndex + increment, speed, runCallbacks, internal);
  2051. }
  2052. /* eslint no-unused-vars: "off" */
  2053. function slidePrev(speed, runCallbacks, internal) {
  2054. if (runCallbacks === void 0) {
  2055. runCallbacks = true;
  2056. }
  2057. const swiper = this;
  2058. const {
  2059. params,
  2060. snapGrid,
  2061. slidesGrid,
  2062. rtlTranslate,
  2063. enabled,
  2064. animating
  2065. } = swiper;
  2066. if (!enabled || swiper.destroyed) return swiper;
  2067. if (typeof speed === 'undefined') {
  2068. speed = swiper.params.speed;
  2069. }
  2070. const isVirtual = swiper.virtual && params.virtual.enabled;
  2071. if (params.loop) {
  2072. if (animating && !isVirtual && params.loopPreventsSliding) return false;
  2073. swiper.loopFix({
  2074. direction: 'prev'
  2075. });
  2076. // eslint-disable-next-line
  2077. swiper._clientLeft = swiper.wrapperEl.clientLeft;
  2078. }
  2079. const translate = rtlTranslate ? swiper.translate : -swiper.translate;
  2080. function normalize(val) {
  2081. if (val < 0) return -Math.floor(Math.abs(val));
  2082. return Math.floor(val);
  2083. }
  2084. const normalizedTranslate = normalize(translate);
  2085. const normalizedSnapGrid = snapGrid.map(val => normalize(val));
  2086. let prevSnap = snapGrid[normalizedSnapGrid.indexOf(normalizedTranslate) - 1];
  2087. if (typeof prevSnap === 'undefined' && params.cssMode) {
  2088. let prevSnapIndex;
  2089. snapGrid.forEach((snap, snapIndex) => {
  2090. if (normalizedTranslate >= snap) {
  2091. // prevSnap = snap;
  2092. prevSnapIndex = snapIndex;
  2093. }
  2094. });
  2095. if (typeof prevSnapIndex !== 'undefined') {
  2096. prevSnap = snapGrid[prevSnapIndex > 0 ? prevSnapIndex - 1 : prevSnapIndex];
  2097. }
  2098. }
  2099. let prevIndex = 0;
  2100. if (typeof prevSnap !== 'undefined') {
  2101. prevIndex = slidesGrid.indexOf(prevSnap);
  2102. if (prevIndex < 0) prevIndex = swiper.activeIndex - 1;
  2103. if (params.slidesPerView === 'auto' && params.slidesPerGroup === 1 && params.slidesPerGroupAuto) {
  2104. prevIndex = prevIndex - swiper.slidesPerViewDynamic('previous', true) + 1;
  2105. prevIndex = Math.max(prevIndex, 0);
  2106. }
  2107. }
  2108. if (params.rewind && swiper.isBeginning) {
  2109. const lastIndex = swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual ? swiper.virtual.slides.length - 1 : swiper.slides.length - 1;
  2110. return swiper.slideTo(lastIndex, speed, runCallbacks, internal);
  2111. } else if (params.loop && swiper.activeIndex === 0 && params.cssMode) {
  2112. requestAnimationFrame(() => {
  2113. swiper.slideTo(prevIndex, speed, runCallbacks, internal);
  2114. });
  2115. return true;
  2116. }
  2117. return swiper.slideTo(prevIndex, speed, runCallbacks, internal);
  2118. }
  2119. /* eslint no-unused-vars: "off" */
  2120. function slideReset(speed, runCallbacks, internal) {
  2121. if (runCallbacks === void 0) {
  2122. runCallbacks = true;
  2123. }
  2124. const swiper = this;
  2125. if (swiper.destroyed) return;
  2126. if (typeof speed === 'undefined') {
  2127. speed = swiper.params.speed;
  2128. }
  2129. return swiper.slideTo(swiper.activeIndex, speed, runCallbacks, internal);
  2130. }
  2131. /* eslint no-unused-vars: "off" */
  2132. function slideToClosest(speed, runCallbacks, internal, threshold) {
  2133. if (runCallbacks === void 0) {
  2134. runCallbacks = true;
  2135. }
  2136. if (threshold === void 0) {
  2137. threshold = 0.5;
  2138. }
  2139. const swiper = this;
  2140. if (swiper.destroyed) return;
  2141. if (typeof speed === 'undefined') {
  2142. speed = swiper.params.speed;
  2143. }
  2144. let index = swiper.activeIndex;
  2145. const skip = Math.min(swiper.params.slidesPerGroupSkip, index);
  2146. const snapIndex = skip + Math.floor((index - skip) / swiper.params.slidesPerGroup);
  2147. const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
  2148. if (translate >= swiper.snapGrid[snapIndex]) {
  2149. // The current translate is on or after the current snap index, so the choice
  2150. // is between the current index and the one after it.
  2151. const currentSnap = swiper.snapGrid[snapIndex];
  2152. const nextSnap = swiper.snapGrid[snapIndex + 1];
  2153. if (translate - currentSnap > (nextSnap - currentSnap) * threshold) {
  2154. index += swiper.params.slidesPerGroup;
  2155. }
  2156. } else {
  2157. // The current translate is before the current snap index, so the choice
  2158. // is between the current index and the one before it.
  2159. const prevSnap = swiper.snapGrid[snapIndex - 1];
  2160. const currentSnap = swiper.snapGrid[snapIndex];
  2161. if (translate - prevSnap <= (currentSnap - prevSnap) * threshold) {
  2162. index -= swiper.params.slidesPerGroup;
  2163. }
  2164. }
  2165. index = Math.max(index, 0);
  2166. index = Math.min(index, swiper.slidesGrid.length - 1);
  2167. return swiper.slideTo(index, speed, runCallbacks, internal);
  2168. }
  2169. function slideToClickedSlide() {
  2170. const swiper = this;
  2171. if (swiper.destroyed) return;
  2172. const {
  2173. params,
  2174. slidesEl
  2175. } = swiper;
  2176. const slidesPerView = params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : params.slidesPerView;
  2177. let slideToIndex = swiper.clickedIndex;
  2178. let realIndex;
  2179. const slideSelector = swiper.isElement ? `swiper-slide` : `.${params.slideClass}`;
  2180. if (params.loop) {
  2181. if (swiper.animating) return;
  2182. realIndex = parseInt(swiper.clickedSlide.getAttribute('data-swiper-slide-index'), 10);
  2183. if (params.centeredSlides) {
  2184. if (slideToIndex < swiper.loopedSlides - slidesPerView / 2 || slideToIndex > swiper.slides.length - swiper.loopedSlides + slidesPerView / 2) {
  2185. swiper.loopFix();
  2186. slideToIndex = swiper.getSlideIndex(elementChildren(slidesEl, `${slideSelector}[data-swiper-slide-index="${realIndex}"]`)[0]);
  2187. nextTick(() => {
  2188. swiper.slideTo(slideToIndex);
  2189. });
  2190. } else {
  2191. swiper.slideTo(slideToIndex);
  2192. }
  2193. } else if (slideToIndex > swiper.slides.length - slidesPerView) {
  2194. swiper.loopFix();
  2195. slideToIndex = swiper.getSlideIndex(elementChildren(slidesEl, `${slideSelector}[data-swiper-slide-index="${realIndex}"]`)[0]);
  2196. nextTick(() => {
  2197. swiper.slideTo(slideToIndex);
  2198. });
  2199. } else {
  2200. swiper.slideTo(slideToIndex);
  2201. }
  2202. } else {
  2203. swiper.slideTo(slideToIndex);
  2204. }
  2205. }
  2206. var slide = {
  2207. slideTo,
  2208. slideToLoop,
  2209. slideNext,
  2210. slidePrev,
  2211. slideReset,
  2212. slideToClosest,
  2213. slideToClickedSlide
  2214. };
  2215. function loopCreate(slideRealIndex) {
  2216. const swiper = this;
  2217. const {
  2218. params,
  2219. slidesEl
  2220. } = swiper;
  2221. if (!params.loop || swiper.virtual && swiper.params.virtual.enabled) return;
  2222. const initSlides = () => {
  2223. const slides = elementChildren(slidesEl, `.${params.slideClass}, swiper-slide`);
  2224. slides.forEach((el, index) => {
  2225. el.setAttribute('data-swiper-slide-index', index);
  2226. });
  2227. };
  2228. const gridEnabled = swiper.grid && params.grid && params.grid.rows > 1;
  2229. const slidesPerGroup = params.slidesPerGroup * (gridEnabled ? params.grid.rows : 1);
  2230. const shouldFillGroup = swiper.slides.length % slidesPerGroup !== 0;
  2231. const shouldFillGrid = gridEnabled && swiper.slides.length % params.grid.rows !== 0;
  2232. const addBlankSlides = amountOfSlides => {
  2233. for (let i = 0; i < amountOfSlides; i += 1) {
  2234. const slideEl = swiper.isElement ? createElement('swiper-slide', [params.slideBlankClass]) : createElement('div', [params.slideClass, params.slideBlankClass]);
  2235. swiper.slidesEl.append(slideEl);
  2236. }
  2237. };
  2238. if (shouldFillGroup) {
  2239. if (params.loopAddBlankSlides) {
  2240. const slidesToAdd = slidesPerGroup - swiper.slides.length % slidesPerGroup;
  2241. addBlankSlides(slidesToAdd);
  2242. swiper.recalcSlides();
  2243. swiper.updateSlides();
  2244. } else {
  2245. showWarning('Swiper Loop Warning: The number of slides is not even to slidesPerGroup, loop mode may not function properly. You need to add more slides (or make duplicates, or empty slides)');
  2246. }
  2247. initSlides();
  2248. } else if (shouldFillGrid) {
  2249. if (params.loopAddBlankSlides) {
  2250. const slidesToAdd = params.grid.rows - swiper.slides.length % params.grid.rows;
  2251. addBlankSlides(slidesToAdd);
  2252. swiper.recalcSlides();
  2253. swiper.updateSlides();
  2254. } else {
  2255. showWarning('Swiper Loop Warning: The number of slides is not even to grid.rows, loop mode may not function properly. You need to add more slides (or make duplicates, or empty slides)');
  2256. }
  2257. initSlides();
  2258. } else {
  2259. initSlides();
  2260. }
  2261. swiper.loopFix({
  2262. slideRealIndex,
  2263. direction: params.centeredSlides ? undefined : 'next'
  2264. });
  2265. }
  2266. function loopFix(_temp) {
  2267. let {
  2268. slideRealIndex,
  2269. slideTo = true,
  2270. direction,
  2271. setTranslate,
  2272. activeSlideIndex,
  2273. byController,
  2274. byMousewheel
  2275. } = _temp === void 0 ? {} : _temp;
  2276. const swiper = this;
  2277. if (!swiper.params.loop) return;
  2278. swiper.emit('beforeLoopFix');
  2279. const {
  2280. slides,
  2281. allowSlidePrev,
  2282. allowSlideNext,
  2283. slidesEl,
  2284. params
  2285. } = swiper;
  2286. const {
  2287. centeredSlides
  2288. } = params;
  2289. swiper.allowSlidePrev = true;
  2290. swiper.allowSlideNext = true;
  2291. if (swiper.virtual && params.virtual.enabled) {
  2292. if (slideTo) {
  2293. if (!params.centeredSlides && swiper.snapIndex === 0) {
  2294. swiper.slideTo(swiper.virtual.slides.length, 0, false, true);
  2295. } else if (params.centeredSlides && swiper.snapIndex < params.slidesPerView) {
  2296. swiper.slideTo(swiper.virtual.slides.length + swiper.snapIndex, 0, false, true);
  2297. } else if (swiper.snapIndex === swiper.snapGrid.length - 1) {
  2298. swiper.slideTo(swiper.virtual.slidesBefore, 0, false, true);
  2299. }
  2300. }
  2301. swiper.allowSlidePrev = allowSlidePrev;
  2302. swiper.allowSlideNext = allowSlideNext;
  2303. swiper.emit('loopFix');
  2304. return;
  2305. }
  2306. let slidesPerView = params.slidesPerView;
  2307. if (slidesPerView === 'auto') {
  2308. slidesPerView = swiper.slidesPerViewDynamic();
  2309. } else {
  2310. slidesPerView = Math.ceil(parseFloat(params.slidesPerView, 10));
  2311. if (centeredSlides && slidesPerView % 2 === 0) {
  2312. slidesPerView = slidesPerView + 1;
  2313. }
  2314. }
  2315. const slidesPerGroup = params.slidesPerGroupAuto ? slidesPerView : params.slidesPerGroup;
  2316. let loopedSlides = slidesPerGroup;
  2317. if (loopedSlides % slidesPerGroup !== 0) {
  2318. loopedSlides += slidesPerGroup - loopedSlides % slidesPerGroup;
  2319. }
  2320. loopedSlides += params.loopAdditionalSlides;
  2321. swiper.loopedSlides = loopedSlides;
  2322. const gridEnabled = swiper.grid && params.grid && params.grid.rows > 1;
  2323. if (slides.length < slidesPerView + loopedSlides) {
  2324. showWarning('Swiper Loop Warning: The number of slides is not enough for loop mode, it will be disabled and not function properly. You need to add more slides (or make duplicates) or lower the values of slidesPerView and slidesPerGroup parameters');
  2325. } else if (gridEnabled && params.grid.fill === 'row') {
  2326. showWarning('Swiper Loop Warning: Loop mode is not compatible with grid.fill = `row`');
  2327. }
  2328. const prependSlidesIndexes = [];
  2329. const appendSlidesIndexes = [];
  2330. let activeIndex = swiper.activeIndex;
  2331. if (typeof activeSlideIndex === 'undefined') {
  2332. activeSlideIndex = swiper.getSlideIndex(slides.filter(el => el.classList.contains(params.slideActiveClass))[0]);
  2333. } else {
  2334. activeIndex = activeSlideIndex;
  2335. }
  2336. const isNext = direction === 'next' || !direction;
  2337. const isPrev = direction === 'prev' || !direction;
  2338. let slidesPrepended = 0;
  2339. let slidesAppended = 0;
  2340. const cols = gridEnabled ? Math.ceil(slides.length / params.grid.rows) : slides.length;
  2341. const activeColIndex = gridEnabled ? slides[activeSlideIndex].column : activeSlideIndex;
  2342. const activeColIndexWithShift = activeColIndex + (centeredSlides && typeof setTranslate === 'undefined' ? -slidesPerView / 2 + 0.5 : 0);
  2343. // prepend last slides before start
  2344. if (activeColIndexWithShift < loopedSlides) {
  2345. slidesPrepended = Math.max(loopedSlides - activeColIndexWithShift, slidesPerGroup);
  2346. for (let i = 0; i < loopedSlides - activeColIndexWithShift; i += 1) {
  2347. const index = i - Math.floor(i / cols) * cols;
  2348. if (gridEnabled) {
  2349. const colIndexToPrepend = cols - index - 1;
  2350. for (let i = slides.length - 1; i >= 0; i -= 1) {
  2351. if (slides[i].column === colIndexToPrepend) prependSlidesIndexes.push(i);
  2352. }
  2353. // slides.forEach((slide, slideIndex) => {
  2354. // if (slide.column === colIndexToPrepend) prependSlidesIndexes.push(slideIndex);
  2355. // });
  2356. } else {
  2357. prependSlidesIndexes.push(cols - index - 1);
  2358. }
  2359. }
  2360. } else if (activeColIndexWithShift + slidesPerView > cols - loopedSlides) {
  2361. slidesAppended = Math.max(activeColIndexWithShift - (cols - loopedSlides * 2), slidesPerGroup);
  2362. for (let i = 0; i < slidesAppended; i += 1) {
  2363. const index = i - Math.floor(i / cols) * cols;
  2364. if (gridEnabled) {
  2365. slides.forEach((slide, slideIndex) => {
  2366. if (slide.column === index) appendSlidesIndexes.push(slideIndex);
  2367. });
  2368. } else {
  2369. appendSlidesIndexes.push(index);
  2370. }
  2371. }
  2372. }
  2373. swiper.__preventObserver__ = true;
  2374. requestAnimationFrame(() => {
  2375. swiper.__preventObserver__ = false;
  2376. });
  2377. if (isPrev) {
  2378. prependSlidesIndexes.forEach(index => {
  2379. slides[index].swiperLoopMoveDOM = true;
  2380. slidesEl.prepend(slides[index]);
  2381. slides[index].swiperLoopMoveDOM = false;
  2382. });
  2383. }
  2384. if (isNext) {
  2385. appendSlidesIndexes.forEach(index => {
  2386. slides[index].swiperLoopMoveDOM = true;
  2387. slidesEl.append(slides[index]);
  2388. slides[index].swiperLoopMoveDOM = false;
  2389. });
  2390. }
  2391. swiper.recalcSlides();
  2392. if (params.slidesPerView === 'auto') {
  2393. swiper.updateSlides();
  2394. } else if (gridEnabled && (prependSlidesIndexes.length > 0 && isPrev || appendSlidesIndexes.length > 0 && isNext)) {
  2395. swiper.slides.forEach((slide, slideIndex) => {
  2396. swiper.grid.updateSlide(slideIndex, slide, swiper.slides);
  2397. });
  2398. }
  2399. if (params.watchSlidesProgress) {
  2400. swiper.updateSlidesOffset();
  2401. }
  2402. if (slideTo) {
  2403. if (prependSlidesIndexes.length > 0 && isPrev) {
  2404. if (typeof slideRealIndex === 'undefined') {
  2405. const currentSlideTranslate = swiper.slidesGrid[activeIndex];
  2406. const newSlideTranslate = swiper.slidesGrid[activeIndex + slidesPrepended];
  2407. const diff = newSlideTranslate - currentSlideTranslate;
  2408. if (byMousewheel) {
  2409. swiper.setTranslate(swiper.translate - diff);
  2410. } else {
  2411. swiper.slideTo(activeIndex + Math.ceil(slidesPrepended), 0, false, true);
  2412. if (setTranslate) {
  2413. swiper.touchEventsData.startTranslate = swiper.touchEventsData.startTranslate - diff;
  2414. swiper.touchEventsData.currentTranslate = swiper.touchEventsData.currentTranslate - diff;
  2415. }
  2416. }
  2417. } else {
  2418. if (setTranslate) {
  2419. const shift = gridEnabled ? prependSlidesIndexes.length / params.grid.rows : prependSlidesIndexes.length;
  2420. swiper.slideTo(swiper.activeIndex + shift, 0, false, true);
  2421. swiper.touchEventsData.currentTranslate = swiper.translate;
  2422. }
  2423. }
  2424. } else if (appendSlidesIndexes.length > 0 && isNext) {
  2425. if (typeof slideRealIndex === 'undefined') {
  2426. const currentSlideTranslate = swiper.slidesGrid[activeIndex];
  2427. const newSlideTranslate = swiper.slidesGrid[activeIndex - slidesAppended];
  2428. const diff = newSlideTranslate - currentSlideTranslate;
  2429. if (byMousewheel) {
  2430. swiper.setTranslate(swiper.translate - diff);
  2431. } else {
  2432. swiper.slideTo(activeIndex - slidesAppended, 0, false, true);
  2433. if (setTranslate) {
  2434. swiper.touchEventsData.startTranslate = swiper.touchEventsData.startTranslate - diff;
  2435. swiper.touchEventsData.currentTranslate = swiper.touchEventsData.currentTranslate - diff;
  2436. }
  2437. }
  2438. } else {
  2439. const shift = gridEnabled ? appendSlidesIndexes.length / params.grid.rows : appendSlidesIndexes.length;
  2440. swiper.slideTo(swiper.activeIndex - shift, 0, false, true);
  2441. }
  2442. }
  2443. }
  2444. swiper.allowSlidePrev = allowSlidePrev;
  2445. swiper.allowSlideNext = allowSlideNext;
  2446. if (swiper.controller && swiper.controller.control && !byController) {
  2447. const loopParams = {
  2448. slideRealIndex,
  2449. direction,
  2450. setTranslate,
  2451. activeSlideIndex,
  2452. byController: true
  2453. };
  2454. if (Array.isArray(swiper.controller.control)) {
  2455. swiper.controller.control.forEach(c => {
  2456. if (!c.destroyed && c.params.loop) c.loopFix({
  2457. ...loopParams,
  2458. slideTo: c.params.slidesPerView === params.slidesPerView ? slideTo : false
  2459. });
  2460. });
  2461. } else if (swiper.controller.control instanceof swiper.constructor && swiper.controller.control.params.loop) {
  2462. swiper.controller.control.loopFix({
  2463. ...loopParams,
  2464. slideTo: swiper.controller.control.params.slidesPerView === params.slidesPerView ? slideTo : false
  2465. });
  2466. }
  2467. }
  2468. swiper.emit('loopFix');
  2469. }
  2470. function loopDestroy() {
  2471. const swiper = this;
  2472. const {
  2473. params,
  2474. slidesEl
  2475. } = swiper;
  2476. if (!params.loop || swiper.virtual && swiper.params.virtual.enabled) return;
  2477. swiper.recalcSlides();
  2478. const newSlidesOrder = [];
  2479. swiper.slides.forEach(slideEl => {
  2480. const index = typeof slideEl.swiperSlideIndex === 'undefined' ? slideEl.getAttribute('data-swiper-slide-index') * 1 : slideEl.swiperSlideIndex;
  2481. newSlidesOrder[index] = slideEl;
  2482. });
  2483. swiper.slides.forEach(slideEl => {
  2484. slideEl.removeAttribute('data-swiper-slide-index');
  2485. });
  2486. newSlidesOrder.forEach(slideEl => {
  2487. slidesEl.append(slideEl);
  2488. });
  2489. swiper.recalcSlides();
  2490. swiper.slideTo(swiper.realIndex, 0);
  2491. }
  2492. var loop = {
  2493. loopCreate,
  2494. loopFix,
  2495. loopDestroy
  2496. };
  2497. function setGrabCursor(moving) {
  2498. const swiper = this;
  2499. if (!swiper.params.simulateTouch || swiper.params.watchOverflow && swiper.isLocked || swiper.params.cssMode) return;
  2500. const el = swiper.params.touchEventsTarget === 'container' ? swiper.el : swiper.wrapperEl;
  2501. if (swiper.isElement) {
  2502. swiper.__preventObserver__ = true;
  2503. }
  2504. el.style.cursor = 'move';
  2505. el.style.cursor = moving ? 'grabbing' : 'grab';
  2506. if (swiper.isElement) {
  2507. requestAnimationFrame(() => {
  2508. swiper.__preventObserver__ = false;
  2509. });
  2510. }
  2511. }
  2512. function unsetGrabCursor() {
  2513. const swiper = this;
  2514. if (swiper.params.watchOverflow && swiper.isLocked || swiper.params.cssMode) {
  2515. return;
  2516. }
  2517. if (swiper.isElement) {
  2518. swiper.__preventObserver__ = true;
  2519. }
  2520. swiper[swiper.params.touchEventsTarget === 'container' ? 'el' : 'wrapperEl'].style.cursor = '';
  2521. if (swiper.isElement) {
  2522. requestAnimationFrame(() => {
  2523. swiper.__preventObserver__ = false;
  2524. });
  2525. }
  2526. }
  2527. var grabCursor = {
  2528. setGrabCursor,
  2529. unsetGrabCursor
  2530. };
  2531. // Modified from https://stackoverflow.com/questions/54520554/custom-element-getrootnode-closest-function-crossing-multiple-parent-shadowd
  2532. function closestElement(selector, base) {
  2533. if (base === void 0) {
  2534. base = this;
  2535. }
  2536. function __closestFrom(el) {
  2537. if (!el || el === getDocument() || el === getWindow()) return null;
  2538. if (el.assignedSlot) el = el.assignedSlot;
  2539. const found = el.closest(selector);
  2540. if (!found && !el.getRootNode) {
  2541. return null;
  2542. }
  2543. return found || __closestFrom(el.getRootNode().host);
  2544. }
  2545. return __closestFrom(base);
  2546. }
  2547. function preventEdgeSwipe(swiper, event, startX) {
  2548. const window = getWindow();
  2549. const {
  2550. params
  2551. } = swiper;
  2552. const edgeSwipeDetection = params.edgeSwipeDetection;
  2553. const edgeSwipeThreshold = params.edgeSwipeThreshold;
  2554. if (edgeSwipeDetection && (startX <= edgeSwipeThreshold || startX >= window.innerWidth - edgeSwipeThreshold)) {
  2555. if (edgeSwipeDetection === 'prevent') {
  2556. event.preventDefault();
  2557. return true;
  2558. }
  2559. return false;
  2560. }
  2561. return true;
  2562. }
  2563. function onTouchStart(event) {
  2564. const swiper = this;
  2565. const document = getDocument();
  2566. let e = event;
  2567. if (e.originalEvent) e = e.originalEvent;
  2568. const data = swiper.touchEventsData;
  2569. if (e.type === 'pointerdown') {
  2570. if (data.pointerId !== null && data.pointerId !== e.pointerId) {
  2571. return;
  2572. }
  2573. data.pointerId = e.pointerId;
  2574. } else if (e.type === 'touchstart' && e.targetTouches.length === 1) {
  2575. data.touchId = e.targetTouches[0].identifier;
  2576. }
  2577. if (e.type === 'touchstart') {
  2578. // don't proceed touch event
  2579. preventEdgeSwipe(swiper, e, e.targetTouches[0].pageX);
  2580. return;
  2581. }
  2582. const {
  2583. params,
  2584. touches,
  2585. enabled
  2586. } = swiper;
  2587. if (!enabled) return;
  2588. if (!params.simulateTouch && e.pointerType === 'mouse') return;
  2589. if (swiper.animating && params.preventInteractionOnTransition) {
  2590. return;
  2591. }
  2592. if (!swiper.animating && params.cssMode && params.loop) {
  2593. swiper.loopFix();
  2594. }
  2595. let targetEl = e.target;
  2596. if (params.touchEventsTarget === 'wrapper') {
  2597. if (!elementIsChildOf(targetEl, swiper.wrapperEl)) return;
  2598. }
  2599. if ('which' in e && e.which === 3) return;
  2600. if ('button' in e && e.button > 0) return;
  2601. if (data.isTouched && data.isMoved) return;
  2602. // change target el for shadow root component
  2603. const swipingClassHasValue = !!params.noSwipingClass && params.noSwipingClass !== '';
  2604. // eslint-disable-next-line
  2605. const eventPath = e.composedPath ? e.composedPath() : e.path;
  2606. if (swipingClassHasValue && e.target && e.target.shadowRoot && eventPath) {
  2607. targetEl = eventPath[0];
  2608. }
  2609. const noSwipingSelector = params.noSwipingSelector ? params.noSwipingSelector : `.${params.noSwipingClass}`;
  2610. const isTargetShadow = !!(e.target && e.target.shadowRoot);
  2611. // use closestElement for shadow root element to get the actual closest for nested shadow root element
  2612. if (params.noSwiping && (isTargetShadow ? closestElement(noSwipingSelector, targetEl) : targetEl.closest(noSwipingSelector))) {
  2613. swiper.allowClick = true;
  2614. return;
  2615. }
  2616. if (params.swipeHandler) {
  2617. if (!targetEl.closest(params.swipeHandler)) return;
  2618. }
  2619. touches.currentX = e.pageX;
  2620. touches.currentY = e.pageY;
  2621. const startX = touches.currentX;
  2622. const startY = touches.currentY;
  2623. // Do NOT start if iOS edge swipe is detected. Otherwise iOS app cannot swipe-to-go-back anymore
  2624. if (!preventEdgeSwipe(swiper, e, startX)) {
  2625. return;
  2626. }
  2627. Object.assign(data, {
  2628. isTouched: true,
  2629. isMoved: false,
  2630. allowTouchCallbacks: true,
  2631. isScrolling: undefined,
  2632. startMoving: undefined
  2633. });
  2634. touches.startX = startX;
  2635. touches.startY = startY;
  2636. data.touchStartTime = now();
  2637. swiper.allowClick = true;
  2638. swiper.updateSize();
  2639. swiper.swipeDirection = undefined;
  2640. if (params.threshold > 0) data.allowThresholdMove = false;
  2641. let preventDefault = true;
  2642. if (targetEl.matches(data.focusableElements)) {
  2643. preventDefault = false;
  2644. if (targetEl.nodeName === 'SELECT') {
  2645. data.isTouched = false;
  2646. }
  2647. }
  2648. if (document.activeElement && document.activeElement.matches(data.focusableElements) && document.activeElement !== targetEl && (e.pointerType === 'mouse' || e.pointerType !== 'mouse' && !targetEl.matches(data.focusableElements))) {
  2649. document.activeElement.blur();
  2650. }
  2651. const shouldPreventDefault = preventDefault && swiper.allowTouchMove && params.touchStartPreventDefault;
  2652. if ((params.touchStartForcePreventDefault || shouldPreventDefault) && !targetEl.isContentEditable) {
  2653. e.preventDefault();
  2654. }
  2655. if (params.freeMode && params.freeMode.enabled && swiper.freeMode && swiper.animating && !params.cssMode) {
  2656. swiper.freeMode.onTouchStart();
  2657. }
  2658. swiper.emit('touchStart', e);
  2659. }
  2660. function onTouchMove(event) {
  2661. const document = getDocument();
  2662. const swiper = this;
  2663. const data = swiper.touchEventsData;
  2664. const {
  2665. params,
  2666. touches,
  2667. rtlTranslate: rtl,
  2668. enabled
  2669. } = swiper;
  2670. if (!enabled) return;
  2671. if (!params.simulateTouch && event.pointerType === 'mouse') return;
  2672. let e = event;
  2673. if (e.originalEvent) e = e.originalEvent;
  2674. if (e.type === 'pointermove') {
  2675. if (data.touchId !== null) return; // return from pointer if we use touch
  2676. const id = e.pointerId;
  2677. if (id !== data.pointerId) return;
  2678. }
  2679. let targetTouch;
  2680. if (e.type === 'touchmove') {
  2681. targetTouch = [...e.changedTouches].filter(t => t.identifier === data.touchId)[0];
  2682. if (!targetTouch || targetTouch.identifier !== data.touchId) return;
  2683. } else {
  2684. targetTouch = e;
  2685. }
  2686. if (!data.isTouched) {
  2687. if (data.startMoving && data.isScrolling) {
  2688. swiper.emit('touchMoveOpposite', e);
  2689. }
  2690. return;
  2691. }
  2692. const pageX = targetTouch.pageX;
  2693. const pageY = targetTouch.pageY;
  2694. if (e.preventedByNestedSwiper) {
  2695. touches.startX = pageX;
  2696. touches.startY = pageY;
  2697. return;
  2698. }
  2699. if (!swiper.allowTouchMove) {
  2700. if (!e.target.matches(data.focusableElements)) {
  2701. swiper.allowClick = false;
  2702. }
  2703. if (data.isTouched) {
  2704. Object.assign(touches, {
  2705. startX: pageX,
  2706. startY: pageY,
  2707. currentX: pageX,
  2708. currentY: pageY
  2709. });
  2710. data.touchStartTime = now();
  2711. }
  2712. return;
  2713. }
  2714. if (params.touchReleaseOnEdges && !params.loop) {
  2715. if (swiper.isVertical()) {
  2716. // Vertical
  2717. if (pageY < touches.startY && swiper.translate <= swiper.maxTranslate() || pageY > touches.startY && swiper.translate >= swiper.minTranslate()) {
  2718. data.isTouched = false;
  2719. data.isMoved = false;
  2720. return;
  2721. }
  2722. } else if (pageX < touches.startX && swiper.translate <= swiper.maxTranslate() || pageX > touches.startX && swiper.translate >= swiper.minTranslate()) {
  2723. return;
  2724. }
  2725. }
  2726. if (document.activeElement && document.activeElement.matches(data.focusableElements) && document.activeElement !== e.target && e.pointerType !== 'mouse') {
  2727. document.activeElement.blur();
  2728. }
  2729. if (document.activeElement) {
  2730. if (e.target === document.activeElement && e.target.matches(data.focusableElements)) {
  2731. data.isMoved = true;
  2732. swiper.allowClick = false;
  2733. return;
  2734. }
  2735. }
  2736. if (data.allowTouchCallbacks) {
  2737. swiper.emit('touchMove', e);
  2738. }
  2739. touches.previousX = touches.currentX;
  2740. touches.previousY = touches.currentY;
  2741. touches.currentX = pageX;
  2742. touches.currentY = pageY;
  2743. const diffX = touches.currentX - touches.startX;
  2744. const diffY = touches.currentY - touches.startY;
  2745. if (swiper.params.threshold && Math.sqrt(diffX ** 2 + diffY ** 2) < swiper.params.threshold) return;
  2746. if (typeof data.isScrolling === 'undefined') {
  2747. let touchAngle;
  2748. if (swiper.isHorizontal() && touches.currentY === touches.startY || swiper.isVertical() && touches.currentX === touches.startX) {
  2749. data.isScrolling = false;
  2750. } else {
  2751. // eslint-disable-next-line
  2752. if (diffX * diffX + diffY * diffY >= 25) {
  2753. touchAngle = Math.atan2(Math.abs(diffY), Math.abs(diffX)) * 180 / Math.PI;
  2754. data.isScrolling = swiper.isHorizontal() ? touchAngle > params.touchAngle : 90 - touchAngle > params.touchAngle;
  2755. }
  2756. }
  2757. }
  2758. if (data.isScrolling) {
  2759. swiper.emit('touchMoveOpposite', e);
  2760. }
  2761. if (typeof data.startMoving === 'undefined') {
  2762. if (touches.currentX !== touches.startX || touches.currentY !== touches.startY) {
  2763. data.startMoving = true;
  2764. }
  2765. }
  2766. if (data.isScrolling || e.type === 'touchmove' && data.preventTouchMoveFromPointerMove) {
  2767. data.isTouched = false;
  2768. return;
  2769. }
  2770. if (!data.startMoving) {
  2771. return;
  2772. }
  2773. swiper.allowClick = false;
  2774. if (!params.cssMode && e.cancelable) {
  2775. e.preventDefault();
  2776. }
  2777. if (params.touchMoveStopPropagation && !params.nested) {
  2778. e.stopPropagation();
  2779. }
  2780. let diff = swiper.isHorizontal() ? diffX : diffY;
  2781. let touchesDiff = swiper.isHorizontal() ? touches.currentX - touches.previousX : touches.currentY - touches.previousY;
  2782. if (params.oneWayMovement) {
  2783. diff = Math.abs(diff) * (rtl ? 1 : -1);
  2784. touchesDiff = Math.abs(touchesDiff) * (rtl ? 1 : -1);
  2785. }
  2786. touches.diff = diff;
  2787. diff *= params.touchRatio;
  2788. if (rtl) {
  2789. diff = -diff;
  2790. touchesDiff = -touchesDiff;
  2791. }
  2792. const prevTouchesDirection = swiper.touchesDirection;
  2793. swiper.swipeDirection = diff > 0 ? 'prev' : 'next';
  2794. swiper.touchesDirection = touchesDiff > 0 ? 'prev' : 'next';
  2795. const isLoop = swiper.params.loop && !params.cssMode;
  2796. const allowLoopFix = swiper.touchesDirection === 'next' && swiper.allowSlideNext || swiper.touchesDirection === 'prev' && swiper.allowSlidePrev;
  2797. if (!data.isMoved) {
  2798. if (isLoop && allowLoopFix) {
  2799. swiper.loopFix({
  2800. direction: swiper.swipeDirection
  2801. });
  2802. }
  2803. data.startTranslate = swiper.getTranslate();
  2804. swiper.setTransition(0);
  2805. if (swiper.animating) {
  2806. const evt = new window.CustomEvent('transitionend', {
  2807. bubbles: true,
  2808. cancelable: true,
  2809. detail: {
  2810. bySwiperTouchMove: true
  2811. }
  2812. });
  2813. swiper.wrapperEl.dispatchEvent(evt);
  2814. }
  2815. data.allowMomentumBounce = false;
  2816. // Grab Cursor
  2817. if (params.grabCursor && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) {
  2818. swiper.setGrabCursor(true);
  2819. }
  2820. swiper.emit('sliderFirstMove', e);
  2821. }
  2822. let loopFixed;
  2823. new Date().getTime();
  2824. if (data.isMoved && data.allowThresholdMove && prevTouchesDirection !== swiper.touchesDirection && isLoop && allowLoopFix && Math.abs(diff) >= 1) {
  2825. Object.assign(touches, {
  2826. startX: pageX,
  2827. startY: pageY,
  2828. currentX: pageX,
  2829. currentY: pageY,
  2830. startTranslate: data.currentTranslate
  2831. });
  2832. data.loopSwapReset = true;
  2833. data.startTranslate = data.currentTranslate;
  2834. return;
  2835. }
  2836. swiper.emit('sliderMove', e);
  2837. data.isMoved = true;
  2838. data.currentTranslate = diff + data.startTranslate;
  2839. let disableParentSwiper = true;
  2840. let resistanceRatio = params.resistanceRatio;
  2841. if (params.touchReleaseOnEdges) {
  2842. resistanceRatio = 0;
  2843. }
  2844. if (diff > 0) {
  2845. if (isLoop && allowLoopFix && !loopFixed && data.allowThresholdMove && data.currentTranslate > (params.centeredSlides ? swiper.minTranslate() - swiper.slidesSizesGrid[swiper.activeIndex + 1] - (params.slidesPerView !== 'auto' && swiper.slides.length - params.slidesPerView >= 2 ? swiper.slidesSizesGrid[swiper.activeIndex + 1] + swiper.params.spaceBetween : 0) - swiper.params.spaceBetween : swiper.minTranslate())) {
  2846. swiper.loopFix({
  2847. direction: 'prev',
  2848. setTranslate: true,
  2849. activeSlideIndex: 0
  2850. });
  2851. }
  2852. if (data.currentTranslate > swiper.minTranslate()) {
  2853. disableParentSwiper = false;
  2854. if (params.resistance) {
  2855. data.currentTranslate = swiper.minTranslate() - 1 + (-swiper.minTranslate() + data.startTranslate + diff) ** resistanceRatio;
  2856. }
  2857. }
  2858. } else if (diff < 0) {
  2859. if (isLoop && allowLoopFix && !loopFixed && data.allowThresholdMove && data.currentTranslate < (params.centeredSlides ? swiper.maxTranslate() + swiper.slidesSizesGrid[swiper.slidesSizesGrid.length - 1] + swiper.params.spaceBetween + (params.slidesPerView !== 'auto' && swiper.slides.length - params.slidesPerView >= 2 ? swiper.slidesSizesGrid[swiper.slidesSizesGrid.length - 1] + swiper.params.spaceBetween : 0) : swiper.maxTranslate())) {
  2860. swiper.loopFix({
  2861. direction: 'next',
  2862. setTranslate: true,
  2863. activeSlideIndex: swiper.slides.length - (params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : Math.ceil(parseFloat(params.slidesPerView, 10)))
  2864. });
  2865. }
  2866. if (data.currentTranslate < swiper.maxTranslate()) {
  2867. disableParentSwiper = false;
  2868. if (params.resistance) {
  2869. data.currentTranslate = swiper.maxTranslate() + 1 - (swiper.maxTranslate() - data.startTranslate - diff) ** resistanceRatio;
  2870. }
  2871. }
  2872. }
  2873. if (disableParentSwiper) {
  2874. e.preventedByNestedSwiper = true;
  2875. }
  2876. // Directions locks
  2877. if (!swiper.allowSlideNext && swiper.swipeDirection === 'next' && data.currentTranslate < data.startTranslate) {
  2878. data.currentTranslate = data.startTranslate;
  2879. }
  2880. if (!swiper.allowSlidePrev && swiper.swipeDirection === 'prev' && data.currentTranslate > data.startTranslate) {
  2881. data.currentTranslate = data.startTranslate;
  2882. }
  2883. if (!swiper.allowSlidePrev && !swiper.allowSlideNext) {
  2884. data.currentTranslate = data.startTranslate;
  2885. }
  2886. // Threshold
  2887. if (params.threshold > 0) {
  2888. if (Math.abs(diff) > params.threshold || data.allowThresholdMove) {
  2889. if (!data.allowThresholdMove) {
  2890. data.allowThresholdMove = true;
  2891. touches.startX = touches.currentX;
  2892. touches.startY = touches.currentY;
  2893. data.currentTranslate = data.startTranslate;
  2894. touches.diff = swiper.isHorizontal() ? touches.currentX - touches.startX : touches.currentY - touches.startY;
  2895. return;
  2896. }
  2897. } else {
  2898. data.currentTranslate = data.startTranslate;
  2899. return;
  2900. }
  2901. }
  2902. if (!params.followFinger || params.cssMode) return;
  2903. // Update active index in free mode
  2904. if (params.freeMode && params.freeMode.enabled && swiper.freeMode || params.watchSlidesProgress) {
  2905. swiper.updateActiveIndex();
  2906. swiper.updateSlidesClasses();
  2907. }
  2908. if (params.freeMode && params.freeMode.enabled && swiper.freeMode) {
  2909. swiper.freeMode.onTouchMove();
  2910. }
  2911. // Update progress
  2912. swiper.updateProgress(data.currentTranslate);
  2913. // Update translate
  2914. swiper.setTranslate(data.currentTranslate);
  2915. }
  2916. function onTouchEnd(event) {
  2917. const swiper = this;
  2918. const data = swiper.touchEventsData;
  2919. let e = event;
  2920. if (e.originalEvent) e = e.originalEvent;
  2921. let targetTouch;
  2922. const isTouchEvent = e.type === 'touchend' || e.type === 'touchcancel';
  2923. if (!isTouchEvent) {
  2924. if (data.touchId !== null) return; // return from pointer if we use touch
  2925. if (e.pointerId !== data.pointerId) return;
  2926. targetTouch = e;
  2927. } else {
  2928. targetTouch = [...e.changedTouches].filter(t => t.identifier === data.touchId)[0];
  2929. if (!targetTouch || targetTouch.identifier !== data.touchId) return;
  2930. }
  2931. if (['pointercancel', 'pointerout', 'pointerleave', 'contextmenu'].includes(e.type)) {
  2932. const proceed = ['pointercancel', 'contextmenu'].includes(e.type) && (swiper.browser.isSafari || swiper.browser.isWebView);
  2933. if (!proceed) {
  2934. return;
  2935. }
  2936. }
  2937. data.pointerId = null;
  2938. data.touchId = null;
  2939. const {
  2940. params,
  2941. touches,
  2942. rtlTranslate: rtl,
  2943. slidesGrid,
  2944. enabled
  2945. } = swiper;
  2946. if (!enabled) return;
  2947. if (!params.simulateTouch && e.pointerType === 'mouse') return;
  2948. if (data.allowTouchCallbacks) {
  2949. swiper.emit('touchEnd', e);
  2950. }
  2951. data.allowTouchCallbacks = false;
  2952. if (!data.isTouched) {
  2953. if (data.isMoved && params.grabCursor) {
  2954. swiper.setGrabCursor(false);
  2955. }
  2956. data.isMoved = false;
  2957. data.startMoving = false;
  2958. return;
  2959. }
  2960. // Return Grab Cursor
  2961. if (params.grabCursor && data.isMoved && data.isTouched && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) {
  2962. swiper.setGrabCursor(false);
  2963. }
  2964. // Time diff
  2965. const touchEndTime = now();
  2966. const timeDiff = touchEndTime - data.touchStartTime;
  2967. // Tap, doubleTap, Click
  2968. if (swiper.allowClick) {
  2969. const pathTree = e.path || e.composedPath && e.composedPath();
  2970. swiper.updateClickedSlide(pathTree && pathTree[0] || e.target, pathTree);
  2971. swiper.emit('tap click', e);
  2972. if (timeDiff < 300 && touchEndTime - data.lastClickTime < 300) {
  2973. swiper.emit('doubleTap doubleClick', e);
  2974. }
  2975. }
  2976. data.lastClickTime = now();
  2977. nextTick(() => {
  2978. if (!swiper.destroyed) swiper.allowClick = true;
  2979. });
  2980. if (!data.isTouched || !data.isMoved || !swiper.swipeDirection || touches.diff === 0 && !data.loopSwapReset || data.currentTranslate === data.startTranslate && !data.loopSwapReset) {
  2981. data.isTouched = false;
  2982. data.isMoved = false;
  2983. data.startMoving = false;
  2984. return;
  2985. }
  2986. data.isTouched = false;
  2987. data.isMoved = false;
  2988. data.startMoving = false;
  2989. let currentPos;
  2990. if (params.followFinger) {
  2991. currentPos = rtl ? swiper.translate : -swiper.translate;
  2992. } else {
  2993. currentPos = -data.currentTranslate;
  2994. }
  2995. if (params.cssMode) {
  2996. return;
  2997. }
  2998. if (params.freeMode && params.freeMode.enabled) {
  2999. swiper.freeMode.onTouchEnd({
  3000. currentPos
  3001. });
  3002. return;
  3003. }
  3004. // Find current slide
  3005. const swipeToLast = currentPos >= -swiper.maxTranslate() && !swiper.params.loop;
  3006. let stopIndex = 0;
  3007. let groupSize = swiper.slidesSizesGrid[0];
  3008. for (let i = 0; i < slidesGrid.length; i += i < params.slidesPerGroupSkip ? 1 : params.slidesPerGroup) {
  3009. const increment = i < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup;
  3010. if (typeof slidesGrid[i + increment] !== 'undefined') {
  3011. if (swipeToLast || currentPos >= slidesGrid[i] && currentPos < slidesGrid[i + increment]) {
  3012. stopIndex = i;
  3013. groupSize = slidesGrid[i + increment] - slidesGrid[i];
  3014. }
  3015. } else if (swipeToLast || currentPos >= slidesGrid[i]) {
  3016. stopIndex = i;
  3017. groupSize = slidesGrid[slidesGrid.length - 1] - slidesGrid[slidesGrid.length - 2];
  3018. }
  3019. }
  3020. let rewindFirstIndex = null;
  3021. let rewindLastIndex = null;
  3022. if (params.rewind) {
  3023. if (swiper.isBeginning) {
  3024. rewindLastIndex = params.virtual && params.virtual.enabled && swiper.virtual ? swiper.virtual.slides.length - 1 : swiper.slides.length - 1;
  3025. } else if (swiper.isEnd) {
  3026. rewindFirstIndex = 0;
  3027. }
  3028. }
  3029. // Find current slide size
  3030. const ratio = (currentPos - slidesGrid[stopIndex]) / groupSize;
  3031. const increment = stopIndex < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup;
  3032. if (timeDiff > params.longSwipesMs) {
  3033. // Long touches
  3034. if (!params.longSwipes) {
  3035. swiper.slideTo(swiper.activeIndex);
  3036. return;
  3037. }
  3038. if (swiper.swipeDirection === 'next') {
  3039. if (ratio >= params.longSwipesRatio) swiper.slideTo(params.rewind && swiper.isEnd ? rewindFirstIndex : stopIndex + increment);else swiper.slideTo(stopIndex);
  3040. }
  3041. if (swiper.swipeDirection === 'prev') {
  3042. if (ratio > 1 - params.longSwipesRatio) {
  3043. swiper.slideTo(stopIndex + increment);
  3044. } else if (rewindLastIndex !== null && ratio < 0 && Math.abs(ratio) > params.longSwipesRatio) {
  3045. swiper.slideTo(rewindLastIndex);
  3046. } else {
  3047. swiper.slideTo(stopIndex);
  3048. }
  3049. }
  3050. } else {
  3051. // Short swipes
  3052. if (!params.shortSwipes) {
  3053. swiper.slideTo(swiper.activeIndex);
  3054. return;
  3055. }
  3056. const isNavButtonTarget = swiper.navigation && (e.target === swiper.navigation.nextEl || e.target === swiper.navigation.prevEl);
  3057. if (!isNavButtonTarget) {
  3058. if (swiper.swipeDirection === 'next') {
  3059. swiper.slideTo(rewindFirstIndex !== null ? rewindFirstIndex : stopIndex + increment);
  3060. }
  3061. if (swiper.swipeDirection === 'prev') {
  3062. swiper.slideTo(rewindLastIndex !== null ? rewindLastIndex : stopIndex);
  3063. }
  3064. } else if (e.target === swiper.navigation.nextEl) {
  3065. swiper.slideTo(stopIndex + increment);
  3066. } else {
  3067. swiper.slideTo(stopIndex);
  3068. }
  3069. }
  3070. }
  3071. function onResize() {
  3072. const swiper = this;
  3073. const {
  3074. params,
  3075. el
  3076. } = swiper;
  3077. if (el && el.offsetWidth === 0) return;
  3078. // Breakpoints
  3079. if (params.breakpoints) {
  3080. swiper.setBreakpoint();
  3081. }
  3082. // Save locks
  3083. const {
  3084. allowSlideNext,
  3085. allowSlidePrev,
  3086. snapGrid
  3087. } = swiper;
  3088. const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
  3089. // Disable locks on resize
  3090. swiper.allowSlideNext = true;
  3091. swiper.allowSlidePrev = true;
  3092. swiper.updateSize();
  3093. swiper.updateSlides();
  3094. swiper.updateSlidesClasses();
  3095. const isVirtualLoop = isVirtual && params.loop;
  3096. if ((params.slidesPerView === 'auto' || params.slidesPerView > 1) && swiper.isEnd && !swiper.isBeginning && !swiper.params.centeredSlides && !isVirtualLoop) {
  3097. swiper.slideTo(swiper.slides.length - 1, 0, false, true);
  3098. } else {
  3099. if (swiper.params.loop && !isVirtual) {
  3100. swiper.slideToLoop(swiper.realIndex, 0, false, true);
  3101. } else {
  3102. swiper.slideTo(swiper.activeIndex, 0, false, true);
  3103. }
  3104. }
  3105. if (swiper.autoplay && swiper.autoplay.running && swiper.autoplay.paused) {
  3106. clearTimeout(swiper.autoplay.resizeTimeout);
  3107. swiper.autoplay.resizeTimeout = setTimeout(() => {
  3108. if (swiper.autoplay && swiper.autoplay.running && swiper.autoplay.paused) {
  3109. swiper.autoplay.resume();
  3110. }
  3111. }, 500);
  3112. }
  3113. // Return locks after resize
  3114. swiper.allowSlidePrev = allowSlidePrev;
  3115. swiper.allowSlideNext = allowSlideNext;
  3116. if (swiper.params.watchOverflow && snapGrid !== swiper.snapGrid) {
  3117. swiper.checkOverflow();
  3118. }
  3119. }
  3120. function onClick(e) {
  3121. const swiper = this;
  3122. if (!swiper.enabled) return;
  3123. if (!swiper.allowClick) {
  3124. if (swiper.params.preventClicks) e.preventDefault();
  3125. if (swiper.params.preventClicksPropagation && swiper.animating) {
  3126. e.stopPropagation();
  3127. e.stopImmediatePropagation();
  3128. }
  3129. }
  3130. }
  3131. function onScroll() {
  3132. const swiper = this;
  3133. const {
  3134. wrapperEl,
  3135. rtlTranslate,
  3136. enabled
  3137. } = swiper;
  3138. if (!enabled) return;
  3139. swiper.previousTranslate = swiper.translate;
  3140. if (swiper.isHorizontal()) {
  3141. swiper.translate = -wrapperEl.scrollLeft;
  3142. } else {
  3143. swiper.translate = -wrapperEl.scrollTop;
  3144. }
  3145. // eslint-disable-next-line
  3146. if (swiper.translate === 0) swiper.translate = 0;
  3147. swiper.updateActiveIndex();
  3148. swiper.updateSlidesClasses();
  3149. let newProgress;
  3150. const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
  3151. if (translatesDiff === 0) {
  3152. newProgress = 0;
  3153. } else {
  3154. newProgress = (swiper.translate - swiper.minTranslate()) / translatesDiff;
  3155. }
  3156. if (newProgress !== swiper.progress) {
  3157. swiper.updateProgress(rtlTranslate ? -swiper.translate : swiper.translate);
  3158. }
  3159. swiper.emit('setTranslate', swiper.translate, false);
  3160. }
  3161. function onLoad(e) {
  3162. const swiper = this;
  3163. processLazyPreloader(swiper, e.target);
  3164. if (swiper.params.cssMode || swiper.params.slidesPerView !== 'auto' && !swiper.params.autoHeight) {
  3165. return;
  3166. }
  3167. swiper.update();
  3168. }
  3169. function onDocumentTouchStart() {
  3170. const swiper = this;
  3171. if (swiper.documentTouchHandlerProceeded) return;
  3172. swiper.documentTouchHandlerProceeded = true;
  3173. if (swiper.params.touchReleaseOnEdges) {
  3174. swiper.el.style.touchAction = 'auto';
  3175. }
  3176. }
  3177. const events = (swiper, method) => {
  3178. const document = getDocument();
  3179. const {
  3180. params,
  3181. el,
  3182. wrapperEl,
  3183. device
  3184. } = swiper;
  3185. const capture = !!params.nested;
  3186. const domMethod = method === 'on' ? 'addEventListener' : 'removeEventListener';
  3187. const swiperMethod = method;
  3188. if (!el || typeof el === 'string') return;
  3189. // Touch Events
  3190. document[domMethod]('touchstart', swiper.onDocumentTouchStart, {
  3191. passive: false,
  3192. capture
  3193. });
  3194. el[domMethod]('touchstart', swiper.onTouchStart, {
  3195. passive: false
  3196. });
  3197. el[domMethod]('pointerdown', swiper.onTouchStart, {
  3198. passive: false
  3199. });
  3200. document[domMethod]('touchmove', swiper.onTouchMove, {
  3201. passive: false,
  3202. capture
  3203. });
  3204. document[domMethod]('pointermove', swiper.onTouchMove, {
  3205. passive: false,
  3206. capture
  3207. });
  3208. document[domMethod]('touchend', swiper.onTouchEnd, {
  3209. passive: true
  3210. });
  3211. document[domMethod]('pointerup', swiper.onTouchEnd, {
  3212. passive: true
  3213. });
  3214. document[domMethod]('pointercancel', swiper.onTouchEnd, {
  3215. passive: true
  3216. });
  3217. document[domMethod]('touchcancel', swiper.onTouchEnd, {
  3218. passive: true
  3219. });
  3220. document[domMethod]('pointerout', swiper.onTouchEnd, {
  3221. passive: true
  3222. });
  3223. document[domMethod]('pointerleave', swiper.onTouchEnd, {
  3224. passive: true
  3225. });
  3226. document[domMethod]('contextmenu', swiper.onTouchEnd, {
  3227. passive: true
  3228. });
  3229. // Prevent Links Clicks
  3230. if (params.preventClicks || params.preventClicksPropagation) {
  3231. el[domMethod]('click', swiper.onClick, true);
  3232. }
  3233. if (params.cssMode) {
  3234. wrapperEl[domMethod]('scroll', swiper.onScroll);
  3235. }
  3236. // Resize handler
  3237. if (params.updateOnWindowResize) {
  3238. swiper[swiperMethod](device.ios || device.android ? 'resize orientationchange observerUpdate' : 'resize observerUpdate', onResize, true);
  3239. } else {
  3240. swiper[swiperMethod]('observerUpdate', onResize, true);
  3241. }
  3242. // Images loader
  3243. el[domMethod]('load', swiper.onLoad, {
  3244. capture: true
  3245. });
  3246. };
  3247. function attachEvents() {
  3248. const swiper = this;
  3249. const {
  3250. params
  3251. } = swiper;
  3252. swiper.onTouchStart = onTouchStart.bind(swiper);
  3253. swiper.onTouchMove = onTouchMove.bind(swiper);
  3254. swiper.onTouchEnd = onTouchEnd.bind(swiper);
  3255. swiper.onDocumentTouchStart = onDocumentTouchStart.bind(swiper);
  3256. if (params.cssMode) {
  3257. swiper.onScroll = onScroll.bind(swiper);
  3258. }
  3259. swiper.onClick = onClick.bind(swiper);
  3260. swiper.onLoad = onLoad.bind(swiper);
  3261. events(swiper, 'on');
  3262. }
  3263. function detachEvents() {
  3264. const swiper = this;
  3265. events(swiper, 'off');
  3266. }
  3267. var events$1 = {
  3268. attachEvents,
  3269. detachEvents
  3270. };
  3271. const isGridEnabled = (swiper, params) => {
  3272. return swiper.grid && params.grid && params.grid.rows > 1;
  3273. };
  3274. function setBreakpoint() {
  3275. const swiper = this;
  3276. const {
  3277. realIndex,
  3278. initialized,
  3279. params,
  3280. el
  3281. } = swiper;
  3282. const breakpoints = params.breakpoints;
  3283. if (!breakpoints || breakpoints && Object.keys(breakpoints).length === 0) return;
  3284. // Get breakpoint for window width and update parameters
  3285. const breakpoint = swiper.getBreakpoint(breakpoints, swiper.params.breakpointsBase, swiper.el);
  3286. if (!breakpoint || swiper.currentBreakpoint === breakpoint) return;
  3287. const breakpointOnlyParams = breakpoint in breakpoints ? breakpoints[breakpoint] : undefined;
  3288. const breakpointParams = breakpointOnlyParams || swiper.originalParams;
  3289. const wasMultiRow = isGridEnabled(swiper, params);
  3290. const isMultiRow = isGridEnabled(swiper, breakpointParams);
  3291. const wasGrabCursor = swiper.params.grabCursor;
  3292. const isGrabCursor = breakpointParams.grabCursor;
  3293. const wasEnabled = params.enabled;
  3294. if (wasMultiRow && !isMultiRow) {
  3295. el.classList.remove(`${params.containerModifierClass}grid`, `${params.containerModifierClass}grid-column`);
  3296. swiper.emitContainerClasses();
  3297. } else if (!wasMultiRow && isMultiRow) {
  3298. el.classList.add(`${params.containerModifierClass}grid`);
  3299. if (breakpointParams.grid.fill && breakpointParams.grid.fill === 'column' || !breakpointParams.grid.fill && params.grid.fill === 'column') {
  3300. el.classList.add(`${params.containerModifierClass}grid-column`);
  3301. }
  3302. swiper.emitContainerClasses();
  3303. }
  3304. if (wasGrabCursor && !isGrabCursor) {
  3305. swiper.unsetGrabCursor();
  3306. } else if (!wasGrabCursor && isGrabCursor) {
  3307. swiper.setGrabCursor();
  3308. }
  3309. // Toggle navigation, pagination, scrollbar
  3310. ['navigation', 'pagination', 'scrollbar'].forEach(prop => {
  3311. if (typeof breakpointParams[prop] === 'undefined') return;
  3312. const wasModuleEnabled = params[prop] && params[prop].enabled;
  3313. const isModuleEnabled = breakpointParams[prop] && breakpointParams[prop].enabled;
  3314. if (wasModuleEnabled && !isModuleEnabled) {
  3315. swiper[prop].disable();
  3316. }
  3317. if (!wasModuleEnabled && isModuleEnabled) {
  3318. swiper[prop].enable();
  3319. }
  3320. });
  3321. const directionChanged = breakpointParams.direction && breakpointParams.direction !== params.direction;
  3322. const needsReLoop = params.loop && (breakpointParams.slidesPerView !== params.slidesPerView || directionChanged);
  3323. const wasLoop = params.loop;
  3324. if (directionChanged && initialized) {
  3325. swiper.changeDirection();
  3326. }
  3327. extend(swiper.params, breakpointParams);
  3328. const isEnabled = swiper.params.enabled;
  3329. const hasLoop = swiper.params.loop;
  3330. Object.assign(swiper, {
  3331. allowTouchMove: swiper.params.allowTouchMove,
  3332. allowSlideNext: swiper.params.allowSlideNext,
  3333. allowSlidePrev: swiper.params.allowSlidePrev
  3334. });
  3335. if (wasEnabled && !isEnabled) {
  3336. swiper.disable();
  3337. } else if (!wasEnabled && isEnabled) {
  3338. swiper.enable();
  3339. }
  3340. swiper.currentBreakpoint = breakpoint;
  3341. swiper.emit('_beforeBreakpoint', breakpointParams);
  3342. if (initialized) {
  3343. if (needsReLoop) {
  3344. swiper.loopDestroy();
  3345. swiper.loopCreate(realIndex);
  3346. swiper.updateSlides();
  3347. } else if (!wasLoop && hasLoop) {
  3348. swiper.loopCreate(realIndex);
  3349. swiper.updateSlides();
  3350. } else if (wasLoop && !hasLoop) {
  3351. swiper.loopDestroy();
  3352. }
  3353. }
  3354. swiper.emit('breakpoint', breakpointParams);
  3355. }
  3356. function getBreakpoint(breakpoints, base, containerEl) {
  3357. if (base === void 0) {
  3358. base = 'window';
  3359. }
  3360. if (!breakpoints || base === 'container' && !containerEl) return undefined;
  3361. let breakpoint = false;
  3362. const window = getWindow();
  3363. const currentHeight = base === 'window' ? window.innerHeight : containerEl.clientHeight;
  3364. const points = Object.keys(breakpoints).map(point => {
  3365. if (typeof point === 'string' && point.indexOf('@') === 0) {
  3366. const minRatio = parseFloat(point.substr(1));
  3367. const value = currentHeight * minRatio;
  3368. return {
  3369. value,
  3370. point
  3371. };
  3372. }
  3373. return {
  3374. value: point,
  3375. point
  3376. };
  3377. });
  3378. points.sort((a, b) => parseInt(a.value, 10) - parseInt(b.value, 10));
  3379. for (let i = 0; i < points.length; i += 1) {
  3380. const {
  3381. point,
  3382. value
  3383. } = points[i];
  3384. if (base === 'window') {
  3385. if (window.matchMedia(`(min-width: ${value}px)`).matches) {
  3386. breakpoint = point;
  3387. }
  3388. } else if (value <= containerEl.clientWidth) {
  3389. breakpoint = point;
  3390. }
  3391. }
  3392. return breakpoint || 'max';
  3393. }
  3394. var breakpoints = {
  3395. setBreakpoint,
  3396. getBreakpoint
  3397. };
  3398. function prepareClasses(entries, prefix) {
  3399. const resultClasses = [];
  3400. entries.forEach(item => {
  3401. if (typeof item === 'object') {
  3402. Object.keys(item).forEach(classNames => {
  3403. if (item[classNames]) {
  3404. resultClasses.push(prefix + classNames);
  3405. }
  3406. });
  3407. } else if (typeof item === 'string') {
  3408. resultClasses.push(prefix + item);
  3409. }
  3410. });
  3411. return resultClasses;
  3412. }
  3413. function addClasses() {
  3414. const swiper = this;
  3415. const {
  3416. classNames,
  3417. params,
  3418. rtl,
  3419. el,
  3420. device
  3421. } = swiper;
  3422. // prettier-ignore
  3423. const suffixes = prepareClasses(['initialized', params.direction, {
  3424. 'free-mode': swiper.params.freeMode && params.freeMode.enabled
  3425. }, {
  3426. 'autoheight': params.autoHeight
  3427. }, {
  3428. 'rtl': rtl
  3429. }, {
  3430. 'grid': params.grid && params.grid.rows > 1
  3431. }, {
  3432. 'grid-column': params.grid && params.grid.rows > 1 && params.grid.fill === 'column'
  3433. }, {
  3434. 'android': device.android
  3435. }, {
  3436. 'ios': device.ios
  3437. }, {
  3438. 'css-mode': params.cssMode
  3439. }, {
  3440. 'centered': params.cssMode && params.centeredSlides
  3441. }, {
  3442. 'watch-progress': params.watchSlidesProgress
  3443. }], params.containerModifierClass);
  3444. classNames.push(...suffixes);
  3445. el.classList.add(...classNames);
  3446. swiper.emitContainerClasses();
  3447. }
  3448. function removeClasses() {
  3449. const swiper = this;
  3450. const {
  3451. el,
  3452. classNames
  3453. } = swiper;
  3454. if (!el || typeof el === 'string') return;
  3455. el.classList.remove(...classNames);
  3456. swiper.emitContainerClasses();
  3457. }
  3458. var classes = {
  3459. addClasses,
  3460. removeClasses
  3461. };
  3462. function checkOverflow() {
  3463. const swiper = this;
  3464. const {
  3465. isLocked: wasLocked,
  3466. params
  3467. } = swiper;
  3468. const {
  3469. slidesOffsetBefore
  3470. } = params;
  3471. if (slidesOffsetBefore) {
  3472. const lastSlideIndex = swiper.slides.length - 1;
  3473. const lastSlideRightEdge = swiper.slidesGrid[lastSlideIndex] + swiper.slidesSizesGrid[lastSlideIndex] + slidesOffsetBefore * 2;
  3474. swiper.isLocked = swiper.size > lastSlideRightEdge;
  3475. } else {
  3476. swiper.isLocked = swiper.snapGrid.length === 1;
  3477. }
  3478. if (params.allowSlideNext === true) {
  3479. swiper.allowSlideNext = !swiper.isLocked;
  3480. }
  3481. if (params.allowSlidePrev === true) {
  3482. swiper.allowSlidePrev = !swiper.isLocked;
  3483. }
  3484. if (wasLocked && wasLocked !== swiper.isLocked) {
  3485. swiper.isEnd = false;
  3486. }
  3487. if (wasLocked !== swiper.isLocked) {
  3488. swiper.emit(swiper.isLocked ? 'lock' : 'unlock');
  3489. }
  3490. }
  3491. var checkOverflow$1 = {
  3492. checkOverflow
  3493. };
  3494. var defaults = {
  3495. init: true,
  3496. direction: 'horizontal',
  3497. oneWayMovement: false,
  3498. swiperElementNodeName: 'SWIPER-CONTAINER',
  3499. touchEventsTarget: 'wrapper',
  3500. initialSlide: 0,
  3501. speed: 300,
  3502. cssMode: false,
  3503. updateOnWindowResize: true,
  3504. resizeObserver: true,
  3505. nested: false,
  3506. createElements: false,
  3507. eventsPrefix: 'swiper',
  3508. enabled: true,
  3509. focusableElements: 'input, select, option, textarea, button, video, label',
  3510. // Overrides
  3511. width: null,
  3512. height: null,
  3513. //
  3514. preventInteractionOnTransition: false,
  3515. // ssr
  3516. userAgent: null,
  3517. url: null,
  3518. // To support iOS's swipe-to-go-back gesture (when being used in-app).
  3519. edgeSwipeDetection: false,
  3520. edgeSwipeThreshold: 20,
  3521. // Autoheight
  3522. autoHeight: false,
  3523. // Set wrapper width
  3524. setWrapperSize: false,
  3525. // Virtual Translate
  3526. virtualTranslate: false,
  3527. // Effects
  3528. effect: 'slide',
  3529. // 'slide' or 'fade' or 'cube' or 'coverflow' or 'flip'
  3530. // Breakpoints
  3531. breakpoints: undefined,
  3532. breakpointsBase: 'window',
  3533. // Slides grid
  3534. spaceBetween: 0,
  3535. slidesPerView: 1,
  3536. slidesPerGroup: 1,
  3537. slidesPerGroupSkip: 0,
  3538. slidesPerGroupAuto: false,
  3539. centeredSlides: false,
  3540. centeredSlidesBounds: false,
  3541. slidesOffsetBefore: 0,
  3542. // in px
  3543. slidesOffsetAfter: 0,
  3544. // in px
  3545. normalizeSlideIndex: true,
  3546. centerInsufficientSlides: false,
  3547. // Disable swiper and hide navigation when container not overflow
  3548. watchOverflow: true,
  3549. // Round length
  3550. roundLengths: false,
  3551. // Touches
  3552. touchRatio: 1,
  3553. touchAngle: 45,
  3554. simulateTouch: true,
  3555. shortSwipes: true,
  3556. longSwipes: true,
  3557. longSwipesRatio: 0.5,
  3558. longSwipesMs: 300,
  3559. followFinger: true,
  3560. allowTouchMove: true,
  3561. threshold: 5,
  3562. touchMoveStopPropagation: false,
  3563. touchStartPreventDefault: true,
  3564. touchStartForcePreventDefault: false,
  3565. touchReleaseOnEdges: false,
  3566. // Unique Navigation Elements
  3567. uniqueNavElements: true,
  3568. // Resistance
  3569. resistance: true,
  3570. resistanceRatio: 0.85,
  3571. // Progress
  3572. watchSlidesProgress: false,
  3573. // Cursor
  3574. grabCursor: false,
  3575. // Clicks
  3576. preventClicks: true,
  3577. preventClicksPropagation: true,
  3578. slideToClickedSlide: false,
  3579. // loop
  3580. loop: false,
  3581. loopAddBlankSlides: true,
  3582. loopAdditionalSlides: 0,
  3583. loopPreventsSliding: true,
  3584. // rewind
  3585. rewind: false,
  3586. // Swiping/no swiping
  3587. allowSlidePrev: true,
  3588. allowSlideNext: true,
  3589. swipeHandler: null,
  3590. // '.swipe-handler',
  3591. noSwiping: true,
  3592. noSwipingClass: 'swiper-no-swiping',
  3593. noSwipingSelector: null,
  3594. // Passive Listeners
  3595. passiveListeners: true,
  3596. maxBackfaceHiddenSlides: 10,
  3597. // NS
  3598. containerModifierClass: 'swiper-',
  3599. // NEW
  3600. slideClass: 'swiper-slide',
  3601. slideBlankClass: 'swiper-slide-blank',
  3602. slideActiveClass: 'swiper-slide-active',
  3603. slideVisibleClass: 'swiper-slide-visible',
  3604. slideFullyVisibleClass: 'swiper-slide-fully-visible',
  3605. slideNextClass: 'swiper-slide-next',
  3606. slidePrevClass: 'swiper-slide-prev',
  3607. wrapperClass: 'swiper-wrapper',
  3608. lazyPreloaderClass: 'swiper-lazy-preloader',
  3609. lazyPreloadPrevNext: 0,
  3610. // Callbacks
  3611. runCallbacksOnInit: true,
  3612. // Internals
  3613. _emitClasses: false
  3614. };
  3615. function moduleExtendParams(params, allModulesParams) {
  3616. return function extendParams(obj) {
  3617. if (obj === void 0) {
  3618. obj = {};
  3619. }
  3620. const moduleParamName = Object.keys(obj)[0];
  3621. const moduleParams = obj[moduleParamName];
  3622. if (typeof moduleParams !== 'object' || moduleParams === null) {
  3623. extend(allModulesParams, obj);
  3624. return;
  3625. }
  3626. if (params[moduleParamName] === true) {
  3627. params[moduleParamName] = {
  3628. enabled: true
  3629. };
  3630. }
  3631. if (moduleParamName === 'navigation' && params[moduleParamName] && params[moduleParamName].enabled && !params[moduleParamName].prevEl && !params[moduleParamName].nextEl) {
  3632. params[moduleParamName].auto = true;
  3633. }
  3634. if (['pagination', 'scrollbar'].indexOf(moduleParamName) >= 0 && params[moduleParamName] && params[moduleParamName].enabled && !params[moduleParamName].el) {
  3635. params[moduleParamName].auto = true;
  3636. }
  3637. if (!(moduleParamName in params && 'enabled' in moduleParams)) {
  3638. extend(allModulesParams, obj);
  3639. return;
  3640. }
  3641. if (typeof params[moduleParamName] === 'object' && !('enabled' in params[moduleParamName])) {
  3642. params[moduleParamName].enabled = true;
  3643. }
  3644. if (!params[moduleParamName]) params[moduleParamName] = {
  3645. enabled: false
  3646. };
  3647. extend(allModulesParams, obj);
  3648. };
  3649. }
  3650. /* eslint no-param-reassign: "off" */
  3651. const prototypes = {
  3652. eventsEmitter,
  3653. update,
  3654. translate,
  3655. transition,
  3656. slide,
  3657. loop,
  3658. grabCursor,
  3659. events: events$1,
  3660. breakpoints,
  3661. checkOverflow: checkOverflow$1,
  3662. classes
  3663. };
  3664. const extendedDefaults = {};
  3665. class Swiper {
  3666. constructor() {
  3667. let el;
  3668. let params;
  3669. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  3670. args[_key] = arguments[_key];
  3671. }
  3672. if (args.length === 1 && args[0].constructor && Object.prototype.toString.call(args[0]).slice(8, -1) === 'Object') {
  3673. params = args[0];
  3674. } else {
  3675. [el, params] = args;
  3676. }
  3677. if (!params) params = {};
  3678. params = extend({}, params);
  3679. if (el && !params.el) params.el = el;
  3680. const document = getDocument();
  3681. if (params.el && typeof params.el === 'string' && document.querySelectorAll(params.el).length > 1) {
  3682. const swipers = [];
  3683. document.querySelectorAll(params.el).forEach(containerEl => {
  3684. const newParams = extend({}, params, {
  3685. el: containerEl
  3686. });
  3687. swipers.push(new Swiper(newParams));
  3688. });
  3689. // eslint-disable-next-line no-constructor-return
  3690. return swipers;
  3691. }
  3692. // Swiper Instance
  3693. const swiper = this;
  3694. swiper.__swiper__ = true;
  3695. swiper.support = getSupport();
  3696. swiper.device = getDevice({
  3697. userAgent: params.userAgent
  3698. });
  3699. swiper.browser = getBrowser();
  3700. swiper.eventsListeners = {};
  3701. swiper.eventsAnyListeners = [];
  3702. swiper.modules = [...swiper.__modules__];
  3703. if (params.modules && Array.isArray(params.modules)) {
  3704. swiper.modules.push(...params.modules);
  3705. }
  3706. const allModulesParams = {};
  3707. swiper.modules.forEach(mod => {
  3708. mod({
  3709. params,
  3710. swiper,
  3711. extendParams: moduleExtendParams(params, allModulesParams),
  3712. on: swiper.on.bind(swiper),
  3713. once: swiper.once.bind(swiper),
  3714. off: swiper.off.bind(swiper),
  3715. emit: swiper.emit.bind(swiper)
  3716. });
  3717. });
  3718. // Extend defaults with modules params
  3719. const swiperParams = extend({}, defaults, allModulesParams);
  3720. // Extend defaults with passed params
  3721. swiper.params = extend({}, swiperParams, extendedDefaults, params);
  3722. swiper.originalParams = extend({}, swiper.params);
  3723. swiper.passedParams = extend({}, params);
  3724. // add event listeners
  3725. if (swiper.params && swiper.params.on) {
  3726. Object.keys(swiper.params.on).forEach(eventName => {
  3727. swiper.on(eventName, swiper.params.on[eventName]);
  3728. });
  3729. }
  3730. if (swiper.params && swiper.params.onAny) {
  3731. swiper.onAny(swiper.params.onAny);
  3732. }
  3733. // Extend Swiper
  3734. Object.assign(swiper, {
  3735. enabled: swiper.params.enabled,
  3736. el,
  3737. // Classes
  3738. classNames: [],
  3739. // Slides
  3740. slides: [],
  3741. slidesGrid: [],
  3742. snapGrid: [],
  3743. slidesSizesGrid: [],
  3744. // isDirection
  3745. isHorizontal() {
  3746. return swiper.params.direction === 'horizontal';
  3747. },
  3748. isVertical() {
  3749. return swiper.params.direction === 'vertical';
  3750. },
  3751. // Indexes
  3752. activeIndex: 0,
  3753. realIndex: 0,
  3754. //
  3755. isBeginning: true,
  3756. isEnd: false,
  3757. // Props
  3758. translate: 0,
  3759. previousTranslate: 0,
  3760. progress: 0,
  3761. velocity: 0,
  3762. animating: false,
  3763. cssOverflowAdjustment() {
  3764. // Returns 0 unless `translate` is > 2**23
  3765. // Should be subtracted from css values to prevent overflow
  3766. return Math.trunc(this.translate / 2 ** 23) * 2 ** 23;
  3767. },
  3768. // Locks
  3769. allowSlideNext: swiper.params.allowSlideNext,
  3770. allowSlidePrev: swiper.params.allowSlidePrev,
  3771. // Touch Events
  3772. touchEventsData: {
  3773. isTouched: undefined,
  3774. isMoved: undefined,
  3775. allowTouchCallbacks: undefined,
  3776. touchStartTime: undefined,
  3777. isScrolling: undefined,
  3778. currentTranslate: undefined,
  3779. startTranslate: undefined,
  3780. allowThresholdMove: undefined,
  3781. // Form elements to match
  3782. focusableElements: swiper.params.focusableElements,
  3783. // Last click time
  3784. lastClickTime: 0,
  3785. clickTimeout: undefined,
  3786. // Velocities
  3787. velocities: [],
  3788. allowMomentumBounce: undefined,
  3789. startMoving: undefined,
  3790. pointerId: null,
  3791. touchId: null
  3792. },
  3793. // Clicks
  3794. allowClick: true,
  3795. // Touches
  3796. allowTouchMove: swiper.params.allowTouchMove,
  3797. touches: {
  3798. startX: 0,
  3799. startY: 0,
  3800. currentX: 0,
  3801. currentY: 0,
  3802. diff: 0
  3803. },
  3804. // Images
  3805. imagesToLoad: [],
  3806. imagesLoaded: 0
  3807. });
  3808. swiper.emit('_swiper');
  3809. // Init
  3810. if (swiper.params.init) {
  3811. swiper.init();
  3812. }
  3813. // Return app instance
  3814. // eslint-disable-next-line no-constructor-return
  3815. return swiper;
  3816. }
  3817. getDirectionLabel(property) {
  3818. if (this.isHorizontal()) {
  3819. return property;
  3820. }
  3821. // prettier-ignore
  3822. return {
  3823. 'width': 'height',
  3824. 'margin-top': 'margin-left',
  3825. 'margin-bottom ': 'margin-right',
  3826. 'margin-left': 'margin-top',
  3827. 'margin-right': 'margin-bottom',
  3828. 'padding-left': 'padding-top',
  3829. 'padding-right': 'padding-bottom',
  3830. 'marginRight': 'marginBottom'
  3831. }[property];
  3832. }
  3833. getSlideIndex(slideEl) {
  3834. const {
  3835. slidesEl,
  3836. params
  3837. } = this;
  3838. const slides = elementChildren(slidesEl, `.${params.slideClass}, swiper-slide`);
  3839. const firstSlideIndex = elementIndex(slides[0]);
  3840. return elementIndex(slideEl) - firstSlideIndex;
  3841. }
  3842. getSlideIndexByData(index) {
  3843. return this.getSlideIndex(this.slides.filter(slideEl => slideEl.getAttribute('data-swiper-slide-index') * 1 === index)[0]);
  3844. }
  3845. recalcSlides() {
  3846. const swiper = this;
  3847. const {
  3848. slidesEl,
  3849. params
  3850. } = swiper;
  3851. swiper.slides = elementChildren(slidesEl, `.${params.slideClass}, swiper-slide`);
  3852. }
  3853. enable() {
  3854. const swiper = this;
  3855. if (swiper.enabled) return;
  3856. swiper.enabled = true;
  3857. if (swiper.params.grabCursor) {
  3858. swiper.setGrabCursor();
  3859. }
  3860. swiper.emit('enable');
  3861. }
  3862. disable() {
  3863. const swiper = this;
  3864. if (!swiper.enabled) return;
  3865. swiper.enabled = false;
  3866. if (swiper.params.grabCursor) {
  3867. swiper.unsetGrabCursor();
  3868. }
  3869. swiper.emit('disable');
  3870. }
  3871. setProgress(progress, speed) {
  3872. const swiper = this;
  3873. progress = Math.min(Math.max(progress, 0), 1);
  3874. const min = swiper.minTranslate();
  3875. const max = swiper.maxTranslate();
  3876. const current = (max - min) * progress + min;
  3877. swiper.translateTo(current, typeof speed === 'undefined' ? 0 : speed);
  3878. swiper.updateActiveIndex();
  3879. swiper.updateSlidesClasses();
  3880. }
  3881. emitContainerClasses() {
  3882. const swiper = this;
  3883. if (!swiper.params._emitClasses || !swiper.el) return;
  3884. const cls = swiper.el.className.split(' ').filter(className => {
  3885. return className.indexOf('swiper') === 0 || className.indexOf(swiper.params.containerModifierClass) === 0;
  3886. });
  3887. swiper.emit('_containerClasses', cls.join(' '));
  3888. }
  3889. getSlideClasses(slideEl) {
  3890. const swiper = this;
  3891. if (swiper.destroyed) return '';
  3892. return slideEl.className.split(' ').filter(className => {
  3893. return className.indexOf('swiper-slide') === 0 || className.indexOf(swiper.params.slideClass) === 0;
  3894. }).join(' ');
  3895. }
  3896. emitSlidesClasses() {
  3897. const swiper = this;
  3898. if (!swiper.params._emitClasses || !swiper.el) return;
  3899. const updates = [];
  3900. swiper.slides.forEach(slideEl => {
  3901. const classNames = swiper.getSlideClasses(slideEl);
  3902. updates.push({
  3903. slideEl,
  3904. classNames
  3905. });
  3906. swiper.emit('_slideClass', slideEl, classNames);
  3907. });
  3908. swiper.emit('_slideClasses', updates);
  3909. }
  3910. slidesPerViewDynamic(view, exact) {
  3911. if (view === void 0) {
  3912. view = 'current';
  3913. }
  3914. if (exact === void 0) {
  3915. exact = false;
  3916. }
  3917. const swiper = this;
  3918. const {
  3919. params,
  3920. slides,
  3921. slidesGrid,
  3922. slidesSizesGrid,
  3923. size: swiperSize,
  3924. activeIndex
  3925. } = swiper;
  3926. let spv = 1;
  3927. if (typeof params.slidesPerView === 'number') return params.slidesPerView;
  3928. if (params.centeredSlides) {
  3929. let slideSize = slides[activeIndex] ? Math.ceil(slides[activeIndex].swiperSlideSize) : 0;
  3930. let breakLoop;
  3931. for (let i = activeIndex + 1; i < slides.length; i += 1) {
  3932. if (slides[i] && !breakLoop) {
  3933. slideSize += Math.ceil(slides[i].swiperSlideSize);
  3934. spv += 1;
  3935. if (slideSize > swiperSize) breakLoop = true;
  3936. }
  3937. }
  3938. for (let i = activeIndex - 1; i >= 0; i -= 1) {
  3939. if (slides[i] && !breakLoop) {
  3940. slideSize += slides[i].swiperSlideSize;
  3941. spv += 1;
  3942. if (slideSize > swiperSize) breakLoop = true;
  3943. }
  3944. }
  3945. } else {
  3946. // eslint-disable-next-line
  3947. if (view === 'current') {
  3948. for (let i = activeIndex + 1; i < slides.length; i += 1) {
  3949. const slideInView = exact ? slidesGrid[i] + slidesSizesGrid[i] - slidesGrid[activeIndex] < swiperSize : slidesGrid[i] - slidesGrid[activeIndex] < swiperSize;
  3950. if (slideInView) {
  3951. spv += 1;
  3952. }
  3953. }
  3954. } else {
  3955. // previous
  3956. for (let i = activeIndex - 1; i >= 0; i -= 1) {
  3957. const slideInView = slidesGrid[activeIndex] - slidesGrid[i] < swiperSize;
  3958. if (slideInView) {
  3959. spv += 1;
  3960. }
  3961. }
  3962. }
  3963. }
  3964. return spv;
  3965. }
  3966. update() {
  3967. const swiper = this;
  3968. if (!swiper || swiper.destroyed) return;
  3969. const {
  3970. snapGrid,
  3971. params
  3972. } = swiper;
  3973. // Breakpoints
  3974. if (params.breakpoints) {
  3975. swiper.setBreakpoint();
  3976. }
  3977. [...swiper.el.querySelectorAll('[loading="lazy"]')].forEach(imageEl => {
  3978. if (imageEl.complete) {
  3979. processLazyPreloader(swiper, imageEl);
  3980. }
  3981. });
  3982. swiper.updateSize();
  3983. swiper.updateSlides();
  3984. swiper.updateProgress();
  3985. swiper.updateSlidesClasses();
  3986. function setTranslate() {
  3987. const translateValue = swiper.rtlTranslate ? swiper.translate * -1 : swiper.translate;
  3988. const newTranslate = Math.min(Math.max(translateValue, swiper.maxTranslate()), swiper.minTranslate());
  3989. swiper.setTranslate(newTranslate);
  3990. swiper.updateActiveIndex();
  3991. swiper.updateSlidesClasses();
  3992. }
  3993. let translated;
  3994. if (params.freeMode && params.freeMode.enabled && !params.cssMode) {
  3995. setTranslate();
  3996. if (params.autoHeight) {
  3997. swiper.updateAutoHeight();
  3998. }
  3999. } else {
  4000. if ((params.slidesPerView === 'auto' || params.slidesPerView > 1) && swiper.isEnd && !params.centeredSlides) {
  4001. const slides = swiper.virtual && params.virtual.enabled ? swiper.virtual.slides : swiper.slides;
  4002. translated = swiper.slideTo(slides.length - 1, 0, false, true);
  4003. } else {
  4004. translated = swiper.slideTo(swiper.activeIndex, 0, false, true);
  4005. }
  4006. if (!translated) {
  4007. setTranslate();
  4008. }
  4009. }
  4010. if (params.watchOverflow && snapGrid !== swiper.snapGrid) {
  4011. swiper.checkOverflow();
  4012. }
  4013. swiper.emit('update');
  4014. }
  4015. changeDirection(newDirection, needUpdate) {
  4016. if (needUpdate === void 0) {
  4017. needUpdate = true;
  4018. }
  4019. const swiper = this;
  4020. const currentDirection = swiper.params.direction;
  4021. if (!newDirection) {
  4022. // eslint-disable-next-line
  4023. newDirection = currentDirection === 'horizontal' ? 'vertical' : 'horizontal';
  4024. }
  4025. if (newDirection === currentDirection || newDirection !== 'horizontal' && newDirection !== 'vertical') {
  4026. return swiper;
  4027. }
  4028. swiper.el.classList.remove(`${swiper.params.containerModifierClass}${currentDirection}`);
  4029. swiper.el.classList.add(`${swiper.params.containerModifierClass}${newDirection}`);
  4030. swiper.emitContainerClasses();
  4031. swiper.params.direction = newDirection;
  4032. swiper.slides.forEach(slideEl => {
  4033. if (newDirection === 'vertical') {
  4034. slideEl.style.width = '';
  4035. } else {
  4036. slideEl.style.height = '';
  4037. }
  4038. });
  4039. swiper.emit('changeDirection');
  4040. if (needUpdate) swiper.update();
  4041. return swiper;
  4042. }
  4043. changeLanguageDirection(direction) {
  4044. const swiper = this;
  4045. if (swiper.rtl && direction === 'rtl' || !swiper.rtl && direction === 'ltr') return;
  4046. swiper.rtl = direction === 'rtl';
  4047. swiper.rtlTranslate = swiper.params.direction === 'horizontal' && swiper.rtl;
  4048. if (swiper.rtl) {
  4049. swiper.el.classList.add(`${swiper.params.containerModifierClass}rtl`);
  4050. swiper.el.dir = 'rtl';
  4051. } else {
  4052. swiper.el.classList.remove(`${swiper.params.containerModifierClass}rtl`);
  4053. swiper.el.dir = 'ltr';
  4054. }
  4055. swiper.update();
  4056. }
  4057. mount(element) {
  4058. const swiper = this;
  4059. if (swiper.mounted) return true;
  4060. // Find el
  4061. let el = element || swiper.params.el;
  4062. if (typeof el === 'string') {
  4063. el = document.querySelector(el);
  4064. }
  4065. if (!el) {
  4066. return false;
  4067. }
  4068. el.swiper = swiper;
  4069. if (el.parentNode && el.parentNode.host && el.parentNode.host.nodeName === swiper.params.swiperElementNodeName.toUpperCase()) {
  4070. swiper.isElement = true;
  4071. }
  4072. const getWrapperSelector = () => {
  4073. return `.${(swiper.params.wrapperClass || '').trim().split(' ').join('.')}`;
  4074. };
  4075. const getWrapper = () => {
  4076. if (el && el.shadowRoot && el.shadowRoot.querySelector) {
  4077. const res = el.shadowRoot.querySelector(getWrapperSelector());
  4078. // Children needs to return slot items
  4079. return res;
  4080. }
  4081. return elementChildren(el, getWrapperSelector())[0];
  4082. };
  4083. // Find Wrapper
  4084. let wrapperEl = getWrapper();
  4085. if (!wrapperEl && swiper.params.createElements) {
  4086. wrapperEl = createElement('div', swiper.params.wrapperClass);
  4087. el.append(wrapperEl);
  4088. elementChildren(el, `.${swiper.params.slideClass}`).forEach(slideEl => {
  4089. wrapperEl.append(slideEl);
  4090. });
  4091. }
  4092. Object.assign(swiper, {
  4093. el,
  4094. wrapperEl,
  4095. slidesEl: swiper.isElement && !el.parentNode.host.slideSlots ? el.parentNode.host : wrapperEl,
  4096. hostEl: swiper.isElement ? el.parentNode.host : el,
  4097. mounted: true,
  4098. // RTL
  4099. rtl: el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl',
  4100. rtlTranslate: swiper.params.direction === 'horizontal' && (el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl'),
  4101. wrongRTL: elementStyle(wrapperEl, 'display') === '-webkit-box'
  4102. });
  4103. return true;
  4104. }
  4105. init(el) {
  4106. const swiper = this;
  4107. if (swiper.initialized) return swiper;
  4108. const mounted = swiper.mount(el);
  4109. if (mounted === false) return swiper;
  4110. swiper.emit('beforeInit');
  4111. // Set breakpoint
  4112. if (swiper.params.breakpoints) {
  4113. swiper.setBreakpoint();
  4114. }
  4115. // Add Classes
  4116. swiper.addClasses();
  4117. // Update size
  4118. swiper.updateSize();
  4119. // Update slides
  4120. swiper.updateSlides();
  4121. if (swiper.params.watchOverflow) {
  4122. swiper.checkOverflow();
  4123. }
  4124. // Set Grab Cursor
  4125. if (swiper.params.grabCursor && swiper.enabled) {
  4126. swiper.setGrabCursor();
  4127. }
  4128. // Slide To Initial Slide
  4129. if (swiper.params.loop && swiper.virtual && swiper.params.virtual.enabled) {
  4130. swiper.slideTo(swiper.params.initialSlide + swiper.virtual.slidesBefore, 0, swiper.params.runCallbacksOnInit, false, true);
  4131. } else {
  4132. swiper.slideTo(swiper.params.initialSlide, 0, swiper.params.runCallbacksOnInit, false, true);
  4133. }
  4134. // Create loop
  4135. if (swiper.params.loop) {
  4136. swiper.loopCreate();
  4137. }
  4138. // Attach events
  4139. swiper.attachEvents();
  4140. const lazyElements = [...swiper.el.querySelectorAll('[loading="lazy"]')];
  4141. if (swiper.isElement) {
  4142. lazyElements.push(...swiper.hostEl.querySelectorAll('[loading="lazy"]'));
  4143. }
  4144. lazyElements.forEach(imageEl => {
  4145. if (imageEl.complete) {
  4146. processLazyPreloader(swiper, imageEl);
  4147. } else {
  4148. imageEl.addEventListener('load', e => {
  4149. processLazyPreloader(swiper, e.target);
  4150. });
  4151. }
  4152. });
  4153. preload(swiper);
  4154. // Init Flag
  4155. swiper.initialized = true;
  4156. preload(swiper);
  4157. // Emit
  4158. swiper.emit('init');
  4159. swiper.emit('afterInit');
  4160. return swiper;
  4161. }
  4162. destroy(deleteInstance, cleanStyles) {
  4163. if (deleteInstance === void 0) {
  4164. deleteInstance = true;
  4165. }
  4166. if (cleanStyles === void 0) {
  4167. cleanStyles = true;
  4168. }
  4169. const swiper = this;
  4170. const {
  4171. params,
  4172. el,
  4173. wrapperEl,
  4174. slides
  4175. } = swiper;
  4176. if (typeof swiper.params === 'undefined' || swiper.destroyed) {
  4177. return null;
  4178. }
  4179. swiper.emit('beforeDestroy');
  4180. // Init Flag
  4181. swiper.initialized = false;
  4182. // Detach events
  4183. swiper.detachEvents();
  4184. // Destroy loop
  4185. if (params.loop) {
  4186. swiper.loopDestroy();
  4187. }
  4188. // Cleanup styles
  4189. if (cleanStyles) {
  4190. swiper.removeClasses();
  4191. if (el && typeof el !== 'string') {
  4192. el.removeAttribute('style');
  4193. }
  4194. if (wrapperEl) {
  4195. wrapperEl.removeAttribute('style');
  4196. }
  4197. if (slides && slides.length) {
  4198. slides.forEach(slideEl => {
  4199. slideEl.classList.remove(params.slideVisibleClass, params.slideFullyVisibleClass, params.slideActiveClass, params.slideNextClass, params.slidePrevClass);
  4200. slideEl.removeAttribute('style');
  4201. slideEl.removeAttribute('data-swiper-slide-index');
  4202. });
  4203. }
  4204. }
  4205. swiper.emit('destroy');
  4206. // Detach emitter events
  4207. Object.keys(swiper.eventsListeners).forEach(eventName => {
  4208. swiper.off(eventName);
  4209. });
  4210. if (deleteInstance !== false) {
  4211. if (swiper.el && typeof swiper.el !== 'string') {
  4212. swiper.el.swiper = null;
  4213. }
  4214. deleteProps(swiper);
  4215. }
  4216. swiper.destroyed = true;
  4217. return null;
  4218. }
  4219. static extendDefaults(newDefaults) {
  4220. extend(extendedDefaults, newDefaults);
  4221. }
  4222. static get extendedDefaults() {
  4223. return extendedDefaults;
  4224. }
  4225. static get defaults() {
  4226. return defaults;
  4227. }
  4228. static installModule(mod) {
  4229. if (!Swiper.prototype.__modules__) Swiper.prototype.__modules__ = [];
  4230. const modules = Swiper.prototype.__modules__;
  4231. if (typeof mod === 'function' && modules.indexOf(mod) < 0) {
  4232. modules.push(mod);
  4233. }
  4234. }
  4235. static use(module) {
  4236. if (Array.isArray(module)) {
  4237. module.forEach(m => Swiper.installModule(m));
  4238. return Swiper;
  4239. }
  4240. Swiper.installModule(module);
  4241. return Swiper;
  4242. }
  4243. }
  4244. Object.keys(prototypes).forEach(prototypeGroup => {
  4245. Object.keys(prototypes[prototypeGroup]).forEach(protoMethod => {
  4246. Swiper.prototype[protoMethod] = prototypes[prototypeGroup][protoMethod];
  4247. });
  4248. });
  4249. Swiper.use([Resize, Observer]);
  4250. function Virtual(_ref) {
  4251. let {
  4252. swiper,
  4253. extendParams,
  4254. on,
  4255. emit
  4256. } = _ref;
  4257. extendParams({
  4258. virtual: {
  4259. enabled: false,
  4260. slides: [],
  4261. cache: true,
  4262. renderSlide: null,
  4263. renderExternal: null,
  4264. renderExternalUpdate: true,
  4265. addSlidesBefore: 0,
  4266. addSlidesAfter: 0
  4267. }
  4268. });
  4269. let cssModeTimeout;
  4270. const document = getDocument();
  4271. swiper.virtual = {
  4272. cache: {},
  4273. from: undefined,
  4274. to: undefined,
  4275. slides: [],
  4276. offset: 0,
  4277. slidesGrid: []
  4278. };
  4279. const tempDOM = document.createElement('div');
  4280. function renderSlide(slide, index) {
  4281. const params = swiper.params.virtual;
  4282. if (params.cache && swiper.virtual.cache[index]) {
  4283. return swiper.virtual.cache[index];
  4284. }
  4285. // eslint-disable-next-line
  4286. let slideEl;
  4287. if (params.renderSlide) {
  4288. slideEl = params.renderSlide.call(swiper, slide, index);
  4289. if (typeof slideEl === 'string') {
  4290. tempDOM.innerHTML = slideEl;
  4291. slideEl = tempDOM.children[0];
  4292. }
  4293. } else if (swiper.isElement) {
  4294. slideEl = createElement('swiper-slide');
  4295. } else {
  4296. slideEl = createElement('div', swiper.params.slideClass);
  4297. }
  4298. slideEl.setAttribute('data-swiper-slide-index', index);
  4299. if (!params.renderSlide) {
  4300. slideEl.innerHTML = slide;
  4301. }
  4302. if (params.cache) {
  4303. swiper.virtual.cache[index] = slideEl;
  4304. }
  4305. return slideEl;
  4306. }
  4307. function update(force, beforeInit) {
  4308. const {
  4309. slidesPerView,
  4310. slidesPerGroup,
  4311. centeredSlides,
  4312. loop: isLoop,
  4313. initialSlide
  4314. } = swiper.params;
  4315. if (beforeInit && !isLoop && initialSlide > 0) {
  4316. return;
  4317. }
  4318. const {
  4319. addSlidesBefore,
  4320. addSlidesAfter
  4321. } = swiper.params.virtual;
  4322. const {
  4323. from: previousFrom,
  4324. to: previousTo,
  4325. slides,
  4326. slidesGrid: previousSlidesGrid,
  4327. offset: previousOffset
  4328. } = swiper.virtual;
  4329. if (!swiper.params.cssMode) {
  4330. swiper.updateActiveIndex();
  4331. }
  4332. const activeIndex = swiper.activeIndex || 0;
  4333. let offsetProp;
  4334. if (swiper.rtlTranslate) offsetProp = 'right';else offsetProp = swiper.isHorizontal() ? 'left' : 'top';
  4335. let slidesAfter;
  4336. let slidesBefore;
  4337. if (centeredSlides) {
  4338. slidesAfter = Math.floor(slidesPerView / 2) + slidesPerGroup + addSlidesAfter;
  4339. slidesBefore = Math.floor(slidesPerView / 2) + slidesPerGroup + addSlidesBefore;
  4340. } else {
  4341. slidesAfter = slidesPerView + (slidesPerGroup - 1) + addSlidesAfter;
  4342. slidesBefore = (isLoop ? slidesPerView : slidesPerGroup) + addSlidesBefore;
  4343. }
  4344. let from = activeIndex - slidesBefore;
  4345. let to = activeIndex + slidesAfter;
  4346. if (!isLoop) {
  4347. from = Math.max(from, 0);
  4348. to = Math.min(to, slides.length - 1);
  4349. }
  4350. let offset = (swiper.slidesGrid[from] || 0) - (swiper.slidesGrid[0] || 0);
  4351. if (isLoop && activeIndex >= slidesBefore) {
  4352. from -= slidesBefore;
  4353. if (!centeredSlides) offset += swiper.slidesGrid[0];
  4354. } else if (isLoop && activeIndex < slidesBefore) {
  4355. from = -slidesBefore;
  4356. if (centeredSlides) offset += swiper.slidesGrid[0];
  4357. }
  4358. Object.assign(swiper.virtual, {
  4359. from,
  4360. to,
  4361. offset,
  4362. slidesGrid: swiper.slidesGrid,
  4363. slidesBefore,
  4364. slidesAfter
  4365. });
  4366. function onRendered() {
  4367. swiper.updateSlides();
  4368. swiper.updateProgress();
  4369. swiper.updateSlidesClasses();
  4370. emit('virtualUpdate');
  4371. }
  4372. if (previousFrom === from && previousTo === to && !force) {
  4373. if (swiper.slidesGrid !== previousSlidesGrid && offset !== previousOffset) {
  4374. swiper.slides.forEach(slideEl => {
  4375. slideEl.style[offsetProp] = `${offset - Math.abs(swiper.cssOverflowAdjustment())}px`;
  4376. });
  4377. }
  4378. swiper.updateProgress();
  4379. emit('virtualUpdate');
  4380. return;
  4381. }
  4382. if (swiper.params.virtual.renderExternal) {
  4383. swiper.params.virtual.renderExternal.call(swiper, {
  4384. offset,
  4385. from,
  4386. to,
  4387. slides: function getSlides() {
  4388. const slidesToRender = [];
  4389. for (let i = from; i <= to; i += 1) {
  4390. slidesToRender.push(slides[i]);
  4391. }
  4392. return slidesToRender;
  4393. }()
  4394. });
  4395. if (swiper.params.virtual.renderExternalUpdate) {
  4396. onRendered();
  4397. } else {
  4398. emit('virtualUpdate');
  4399. }
  4400. return;
  4401. }
  4402. const prependIndexes = [];
  4403. const appendIndexes = [];
  4404. const getSlideIndex = index => {
  4405. let slideIndex = index;
  4406. if (index < 0) {
  4407. slideIndex = slides.length + index;
  4408. } else if (slideIndex >= slides.length) {
  4409. // eslint-disable-next-line
  4410. slideIndex = slideIndex - slides.length;
  4411. }
  4412. return slideIndex;
  4413. };
  4414. if (force) {
  4415. swiper.slides.filter(el => el.matches(`.${swiper.params.slideClass}, swiper-slide`)).forEach(slideEl => {
  4416. slideEl.remove();
  4417. });
  4418. } else {
  4419. for (let i = previousFrom; i <= previousTo; i += 1) {
  4420. if (i < from || i > to) {
  4421. const slideIndex = getSlideIndex(i);
  4422. swiper.slides.filter(el => el.matches(`.${swiper.params.slideClass}[data-swiper-slide-index="${slideIndex}"], swiper-slide[data-swiper-slide-index="${slideIndex}"]`)).forEach(slideEl => {
  4423. slideEl.remove();
  4424. });
  4425. }
  4426. }
  4427. }
  4428. const loopFrom = isLoop ? -slides.length : 0;
  4429. const loopTo = isLoop ? slides.length * 2 : slides.length;
  4430. for (let i = loopFrom; i < loopTo; i += 1) {
  4431. if (i >= from && i <= to) {
  4432. const slideIndex = getSlideIndex(i);
  4433. if (typeof previousTo === 'undefined' || force) {
  4434. appendIndexes.push(slideIndex);
  4435. } else {
  4436. if (i > previousTo) appendIndexes.push(slideIndex);
  4437. if (i < previousFrom) prependIndexes.push(slideIndex);
  4438. }
  4439. }
  4440. }
  4441. appendIndexes.forEach(index => {
  4442. swiper.slidesEl.append(renderSlide(slides[index], index));
  4443. });
  4444. if (isLoop) {
  4445. for (let i = prependIndexes.length - 1; i >= 0; i -= 1) {
  4446. const index = prependIndexes[i];
  4447. swiper.slidesEl.prepend(renderSlide(slides[index], index));
  4448. }
  4449. } else {
  4450. prependIndexes.sort((a, b) => b - a);
  4451. prependIndexes.forEach(index => {
  4452. swiper.slidesEl.prepend(renderSlide(slides[index], index));
  4453. });
  4454. }
  4455. elementChildren(swiper.slidesEl, '.swiper-slide, swiper-slide').forEach(slideEl => {
  4456. slideEl.style[offsetProp] = `${offset - Math.abs(swiper.cssOverflowAdjustment())}px`;
  4457. });
  4458. onRendered();
  4459. }
  4460. function appendSlide(slides) {
  4461. if (typeof slides === 'object' && 'length' in slides) {
  4462. for (let i = 0; i < slides.length; i += 1) {
  4463. if (slides[i]) swiper.virtual.slides.push(slides[i]);
  4464. }
  4465. } else {
  4466. swiper.virtual.slides.push(slides);
  4467. }
  4468. update(true);
  4469. }
  4470. function prependSlide(slides) {
  4471. const activeIndex = swiper.activeIndex;
  4472. let newActiveIndex = activeIndex + 1;
  4473. let numberOfNewSlides = 1;
  4474. if (Array.isArray(slides)) {
  4475. for (let i = 0; i < slides.length; i += 1) {
  4476. if (slides[i]) swiper.virtual.slides.unshift(slides[i]);
  4477. }
  4478. newActiveIndex = activeIndex + slides.length;
  4479. numberOfNewSlides = slides.length;
  4480. } else {
  4481. swiper.virtual.slides.unshift(slides);
  4482. }
  4483. if (swiper.params.virtual.cache) {
  4484. const cache = swiper.virtual.cache;
  4485. const newCache = {};
  4486. Object.keys(cache).forEach(cachedIndex => {
  4487. const cachedEl = cache[cachedIndex];
  4488. const cachedElIndex = cachedEl.getAttribute('data-swiper-slide-index');
  4489. if (cachedElIndex) {
  4490. cachedEl.setAttribute('data-swiper-slide-index', parseInt(cachedElIndex, 10) + numberOfNewSlides);
  4491. }
  4492. newCache[parseInt(cachedIndex, 10) + numberOfNewSlides] = cachedEl;
  4493. });
  4494. swiper.virtual.cache = newCache;
  4495. }
  4496. update(true);
  4497. swiper.slideTo(newActiveIndex, 0);
  4498. }
  4499. function removeSlide(slidesIndexes) {
  4500. if (typeof slidesIndexes === 'undefined' || slidesIndexes === null) return;
  4501. let activeIndex = swiper.activeIndex;
  4502. if (Array.isArray(slidesIndexes)) {
  4503. for (let i = slidesIndexes.length - 1; i >= 0; i -= 1) {
  4504. if (swiper.params.virtual.cache) {
  4505. delete swiper.virtual.cache[slidesIndexes[i]];
  4506. // shift cache indexes
  4507. Object.keys(swiper.virtual.cache).forEach(key => {
  4508. if (key > slidesIndexes) {
  4509. swiper.virtual.cache[key - 1] = swiper.virtual.cache[key];
  4510. swiper.virtual.cache[key - 1].setAttribute('data-swiper-slide-index', key - 1);
  4511. delete swiper.virtual.cache[key];
  4512. }
  4513. });
  4514. }
  4515. swiper.virtual.slides.splice(slidesIndexes[i], 1);
  4516. if (slidesIndexes[i] < activeIndex) activeIndex -= 1;
  4517. activeIndex = Math.max(activeIndex, 0);
  4518. }
  4519. } else {
  4520. if (swiper.params.virtual.cache) {
  4521. delete swiper.virtual.cache[slidesIndexes];
  4522. // shift cache indexes
  4523. Object.keys(swiper.virtual.cache).forEach(key => {
  4524. if (key > slidesIndexes) {
  4525. swiper.virtual.cache[key - 1] = swiper.virtual.cache[key];
  4526. swiper.virtual.cache[key - 1].setAttribute('data-swiper-slide-index', key - 1);
  4527. delete swiper.virtual.cache[key];
  4528. }
  4529. });
  4530. }
  4531. swiper.virtual.slides.splice(slidesIndexes, 1);
  4532. if (slidesIndexes < activeIndex) activeIndex -= 1;
  4533. activeIndex = Math.max(activeIndex, 0);
  4534. }
  4535. update(true);
  4536. swiper.slideTo(activeIndex, 0);
  4537. }
  4538. function removeAllSlides() {
  4539. swiper.virtual.slides = [];
  4540. if (swiper.params.virtual.cache) {
  4541. swiper.virtual.cache = {};
  4542. }
  4543. update(true);
  4544. swiper.slideTo(0, 0);
  4545. }
  4546. on('beforeInit', () => {
  4547. if (!swiper.params.virtual.enabled) return;
  4548. let domSlidesAssigned;
  4549. if (typeof swiper.passedParams.virtual.slides === 'undefined') {
  4550. const slides = [...swiper.slidesEl.children].filter(el => el.matches(`.${swiper.params.slideClass}, swiper-slide`));
  4551. if (slides && slides.length) {
  4552. swiper.virtual.slides = [...slides];
  4553. domSlidesAssigned = true;
  4554. slides.forEach((slideEl, slideIndex) => {
  4555. slideEl.setAttribute('data-swiper-slide-index', slideIndex);
  4556. swiper.virtual.cache[slideIndex] = slideEl;
  4557. slideEl.remove();
  4558. });
  4559. }
  4560. }
  4561. if (!domSlidesAssigned) {
  4562. swiper.virtual.slides = swiper.params.virtual.slides;
  4563. }
  4564. swiper.classNames.push(`${swiper.params.containerModifierClass}virtual`);
  4565. swiper.params.watchSlidesProgress = true;
  4566. swiper.originalParams.watchSlidesProgress = true;
  4567. update(false, true);
  4568. });
  4569. on('setTranslate', () => {
  4570. if (!swiper.params.virtual.enabled) return;
  4571. if (swiper.params.cssMode && !swiper._immediateVirtual) {
  4572. clearTimeout(cssModeTimeout);
  4573. cssModeTimeout = setTimeout(() => {
  4574. update();
  4575. }, 100);
  4576. } else {
  4577. update();
  4578. }
  4579. });
  4580. on('init update resize', () => {
  4581. if (!swiper.params.virtual.enabled) return;
  4582. if (swiper.params.cssMode) {
  4583. setCSSProperty(swiper.wrapperEl, '--swiper-virtual-size', `${swiper.virtualSize}px`);
  4584. }
  4585. });
  4586. Object.assign(swiper.virtual, {
  4587. appendSlide,
  4588. prependSlide,
  4589. removeSlide,
  4590. removeAllSlides,
  4591. update
  4592. });
  4593. }
  4594. /* eslint-disable consistent-return */
  4595. function Keyboard(_ref) {
  4596. let {
  4597. swiper,
  4598. extendParams,
  4599. on,
  4600. emit
  4601. } = _ref;
  4602. const document = getDocument();
  4603. const window = getWindow();
  4604. swiper.keyboard = {
  4605. enabled: false
  4606. };
  4607. extendParams({
  4608. keyboard: {
  4609. enabled: false,
  4610. onlyInViewport: true,
  4611. pageUpDown: true
  4612. }
  4613. });
  4614. function handle(event) {
  4615. if (!swiper.enabled) return;
  4616. const {
  4617. rtlTranslate: rtl
  4618. } = swiper;
  4619. let e = event;
  4620. if (e.originalEvent) e = e.originalEvent; // jquery fix
  4621. const kc = e.keyCode || e.charCode;
  4622. const pageUpDown = swiper.params.keyboard.pageUpDown;
  4623. const isPageUp = pageUpDown && kc === 33;
  4624. const isPageDown = pageUpDown && kc === 34;
  4625. const isArrowLeft = kc === 37;
  4626. const isArrowRight = kc === 39;
  4627. const isArrowUp = kc === 38;
  4628. const isArrowDown = kc === 40;
  4629. // Directions locks
  4630. if (!swiper.allowSlideNext && (swiper.isHorizontal() && isArrowRight || swiper.isVertical() && isArrowDown || isPageDown)) {
  4631. return false;
  4632. }
  4633. if (!swiper.allowSlidePrev && (swiper.isHorizontal() && isArrowLeft || swiper.isVertical() && isArrowUp || isPageUp)) {
  4634. return false;
  4635. }
  4636. if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey) {
  4637. return undefined;
  4638. }
  4639. if (document.activeElement && document.activeElement.nodeName && (document.activeElement.nodeName.toLowerCase() === 'input' || document.activeElement.nodeName.toLowerCase() === 'textarea')) {
  4640. return undefined;
  4641. }
  4642. if (swiper.params.keyboard.onlyInViewport && (isPageUp || isPageDown || isArrowLeft || isArrowRight || isArrowUp || isArrowDown)) {
  4643. let inView = false;
  4644. // Check that swiper should be inside of visible area of window
  4645. if (elementParents(swiper.el, `.${swiper.params.slideClass}, swiper-slide`).length > 0 && elementParents(swiper.el, `.${swiper.params.slideActiveClass}`).length === 0) {
  4646. return undefined;
  4647. }
  4648. const el = swiper.el;
  4649. const swiperWidth = el.clientWidth;
  4650. const swiperHeight = el.clientHeight;
  4651. const windowWidth = window.innerWidth;
  4652. const windowHeight = window.innerHeight;
  4653. const swiperOffset = elementOffset(el);
  4654. if (rtl) swiperOffset.left -= el.scrollLeft;
  4655. const swiperCoord = [[swiperOffset.left, swiperOffset.top], [swiperOffset.left + swiperWidth, swiperOffset.top], [swiperOffset.left, swiperOffset.top + swiperHeight], [swiperOffset.left + swiperWidth, swiperOffset.top + swiperHeight]];
  4656. for (let i = 0; i < swiperCoord.length; i += 1) {
  4657. const point = swiperCoord[i];
  4658. if (point[0] >= 0 && point[0] <= windowWidth && point[1] >= 0 && point[1] <= windowHeight) {
  4659. if (point[0] === 0 && point[1] === 0) continue; // eslint-disable-line
  4660. inView = true;
  4661. }
  4662. }
  4663. if (!inView) return undefined;
  4664. }
  4665. if (swiper.isHorizontal()) {
  4666. if (isPageUp || isPageDown || isArrowLeft || isArrowRight) {
  4667. if (e.preventDefault) e.preventDefault();else e.returnValue = false;
  4668. }
  4669. if ((isPageDown || isArrowRight) && !rtl || (isPageUp || isArrowLeft) && rtl) swiper.slideNext();
  4670. if ((isPageUp || isArrowLeft) && !rtl || (isPageDown || isArrowRight) && rtl) swiper.slidePrev();
  4671. } else {
  4672. if (isPageUp || isPageDown || isArrowUp || isArrowDown) {
  4673. if (e.preventDefault) e.preventDefault();else e.returnValue = false;
  4674. }
  4675. if (isPageDown || isArrowDown) swiper.slideNext();
  4676. if (isPageUp || isArrowUp) swiper.slidePrev();
  4677. }
  4678. emit('keyPress', kc);
  4679. return undefined;
  4680. }
  4681. function enable() {
  4682. if (swiper.keyboard.enabled) return;
  4683. document.addEventListener('keydown', handle);
  4684. swiper.keyboard.enabled = true;
  4685. }
  4686. function disable() {
  4687. if (!swiper.keyboard.enabled) return;
  4688. document.removeEventListener('keydown', handle);
  4689. swiper.keyboard.enabled = false;
  4690. }
  4691. on('init', () => {
  4692. if (swiper.params.keyboard.enabled) {
  4693. enable();
  4694. }
  4695. });
  4696. on('destroy', () => {
  4697. if (swiper.keyboard.enabled) {
  4698. disable();
  4699. }
  4700. });
  4701. Object.assign(swiper.keyboard, {
  4702. enable,
  4703. disable
  4704. });
  4705. }
  4706. /* eslint-disable consistent-return */
  4707. function Mousewheel(_ref) {
  4708. let {
  4709. swiper,
  4710. extendParams,
  4711. on,
  4712. emit
  4713. } = _ref;
  4714. const window = getWindow();
  4715. extendParams({
  4716. mousewheel: {
  4717. enabled: false,
  4718. releaseOnEdges: false,
  4719. invert: false,
  4720. forceToAxis: false,
  4721. sensitivity: 1,
  4722. eventsTarget: 'container',
  4723. thresholdDelta: null,
  4724. thresholdTime: null,
  4725. noMousewheelClass: 'swiper-no-mousewheel'
  4726. }
  4727. });
  4728. swiper.mousewheel = {
  4729. enabled: false
  4730. };
  4731. let timeout;
  4732. let lastScrollTime = now();
  4733. let lastEventBeforeSnap;
  4734. const recentWheelEvents = [];
  4735. function normalize(e) {
  4736. // Reasonable defaults
  4737. const PIXEL_STEP = 10;
  4738. const LINE_HEIGHT = 40;
  4739. const PAGE_HEIGHT = 800;
  4740. let sX = 0;
  4741. let sY = 0; // spinX, spinY
  4742. let pX = 0;
  4743. let pY = 0; // pixelX, pixelY
  4744. // Legacy
  4745. if ('detail' in e) {
  4746. sY = e.detail;
  4747. }
  4748. if ('wheelDelta' in e) {
  4749. sY = -e.wheelDelta / 120;
  4750. }
  4751. if ('wheelDeltaY' in e) {
  4752. sY = -e.wheelDeltaY / 120;
  4753. }
  4754. if ('wheelDeltaX' in e) {
  4755. sX = -e.wheelDeltaX / 120;
  4756. }
  4757. // side scrolling on FF with DOMMouseScroll
  4758. if ('axis' in e && e.axis === e.HORIZONTAL_AXIS) {
  4759. sX = sY;
  4760. sY = 0;
  4761. }
  4762. pX = sX * PIXEL_STEP;
  4763. pY = sY * PIXEL_STEP;
  4764. if ('deltaY' in e) {
  4765. pY = e.deltaY;
  4766. }
  4767. if ('deltaX' in e) {
  4768. pX = e.deltaX;
  4769. }
  4770. if (e.shiftKey && !pX) {
  4771. // if user scrolls with shift he wants horizontal scroll
  4772. pX = pY;
  4773. pY = 0;
  4774. }
  4775. if ((pX || pY) && e.deltaMode) {
  4776. if (e.deltaMode === 1) {
  4777. // delta in LINE units
  4778. pX *= LINE_HEIGHT;
  4779. pY *= LINE_HEIGHT;
  4780. } else {
  4781. // delta in PAGE units
  4782. pX *= PAGE_HEIGHT;
  4783. pY *= PAGE_HEIGHT;
  4784. }
  4785. }
  4786. // Fall-back if spin cannot be determined
  4787. if (pX && !sX) {
  4788. sX = pX < 1 ? -1 : 1;
  4789. }
  4790. if (pY && !sY) {
  4791. sY = pY < 1 ? -1 : 1;
  4792. }
  4793. return {
  4794. spinX: sX,
  4795. spinY: sY,
  4796. pixelX: pX,
  4797. pixelY: pY
  4798. };
  4799. }
  4800. function handleMouseEnter() {
  4801. if (!swiper.enabled) return;
  4802. swiper.mouseEntered = true;
  4803. }
  4804. function handleMouseLeave() {
  4805. if (!swiper.enabled) return;
  4806. swiper.mouseEntered = false;
  4807. }
  4808. function animateSlider(newEvent) {
  4809. if (swiper.params.mousewheel.thresholdDelta && newEvent.delta < swiper.params.mousewheel.thresholdDelta) {
  4810. // Prevent if delta of wheel scroll delta is below configured threshold
  4811. return false;
  4812. }
  4813. if (swiper.params.mousewheel.thresholdTime && now() - lastScrollTime < swiper.params.mousewheel.thresholdTime) {
  4814. // Prevent if time between scrolls is below configured threshold
  4815. return false;
  4816. }
  4817. // If the movement is NOT big enough and
  4818. // if the last time the user scrolled was too close to the current one (avoid continuously triggering the slider):
  4819. // Don't go any further (avoid insignificant scroll movement).
  4820. if (newEvent.delta >= 6 && now() - lastScrollTime < 60) {
  4821. // Return false as a default
  4822. return true;
  4823. }
  4824. // If user is scrolling towards the end:
  4825. // If the slider hasn't hit the latest slide or
  4826. // if the slider is a loop and
  4827. // if the slider isn't moving right now:
  4828. // Go to next slide and
  4829. // emit a scroll event.
  4830. // Else (the user is scrolling towards the beginning) and
  4831. // if the slider hasn't hit the first slide or
  4832. // if the slider is a loop and
  4833. // if the slider isn't moving right now:
  4834. // Go to prev slide and
  4835. // emit a scroll event.
  4836. if (newEvent.direction < 0) {
  4837. if ((!swiper.isEnd || swiper.params.loop) && !swiper.animating) {
  4838. swiper.slideNext();
  4839. emit('scroll', newEvent.raw);
  4840. }
  4841. } else if ((!swiper.isBeginning || swiper.params.loop) && !swiper.animating) {
  4842. swiper.slidePrev();
  4843. emit('scroll', newEvent.raw);
  4844. }
  4845. // If you got here is because an animation has been triggered so store the current time
  4846. lastScrollTime = new window.Date().getTime();
  4847. // Return false as a default
  4848. return false;
  4849. }
  4850. function releaseScroll(newEvent) {
  4851. const params = swiper.params.mousewheel;
  4852. if (newEvent.direction < 0) {
  4853. if (swiper.isEnd && !swiper.params.loop && params.releaseOnEdges) {
  4854. // Return true to animate scroll on edges
  4855. return true;
  4856. }
  4857. } else if (swiper.isBeginning && !swiper.params.loop && params.releaseOnEdges) {
  4858. // Return true to animate scroll on edges
  4859. return true;
  4860. }
  4861. return false;
  4862. }
  4863. function handle(event) {
  4864. let e = event;
  4865. let disableParentSwiper = true;
  4866. if (!swiper.enabled) return;
  4867. // Ignore event if the target or its parents have the swiper-no-mousewheel class
  4868. if (event.target.closest(`.${swiper.params.mousewheel.noMousewheelClass}`)) return;
  4869. const params = swiper.params.mousewheel;
  4870. if (swiper.params.cssMode) {
  4871. e.preventDefault();
  4872. }
  4873. let targetEl = swiper.el;
  4874. if (swiper.params.mousewheel.eventsTarget !== 'container') {
  4875. targetEl = document.querySelector(swiper.params.mousewheel.eventsTarget);
  4876. }
  4877. const targetElContainsTarget = targetEl && targetEl.contains(e.target);
  4878. if (!swiper.mouseEntered && !targetElContainsTarget && !params.releaseOnEdges) return true;
  4879. if (e.originalEvent) e = e.originalEvent; // jquery fix
  4880. let delta = 0;
  4881. const rtlFactor = swiper.rtlTranslate ? -1 : 1;
  4882. const data = normalize(e);
  4883. if (params.forceToAxis) {
  4884. if (swiper.isHorizontal()) {
  4885. if (Math.abs(data.pixelX) > Math.abs(data.pixelY)) delta = -data.pixelX * rtlFactor;else return true;
  4886. } else if (Math.abs(data.pixelY) > Math.abs(data.pixelX)) delta = -data.pixelY;else return true;
  4887. } else {
  4888. delta = Math.abs(data.pixelX) > Math.abs(data.pixelY) ? -data.pixelX * rtlFactor : -data.pixelY;
  4889. }
  4890. if (delta === 0) return true;
  4891. if (params.invert) delta = -delta;
  4892. // Get the scroll positions
  4893. let positions = swiper.getTranslate() + delta * params.sensitivity;
  4894. if (positions >= swiper.minTranslate()) positions = swiper.minTranslate();
  4895. if (positions <= swiper.maxTranslate()) positions = swiper.maxTranslate();
  4896. // When loop is true:
  4897. // the disableParentSwiper will be true.
  4898. // When loop is false:
  4899. // if the scroll positions is not on edge,
  4900. // then the disableParentSwiper will be true.
  4901. // if the scroll on edge positions,
  4902. // then the disableParentSwiper will be false.
  4903. disableParentSwiper = swiper.params.loop ? true : !(positions === swiper.minTranslate() || positions === swiper.maxTranslate());
  4904. if (disableParentSwiper && swiper.params.nested) e.stopPropagation();
  4905. if (!swiper.params.freeMode || !swiper.params.freeMode.enabled) {
  4906. // Register the new event in a variable which stores the relevant data
  4907. const newEvent = {
  4908. time: now(),
  4909. delta: Math.abs(delta),
  4910. direction: Math.sign(delta),
  4911. raw: event
  4912. };
  4913. // Keep the most recent events
  4914. if (recentWheelEvents.length >= 2) {
  4915. recentWheelEvents.shift(); // only store the last N events
  4916. }
  4917. const prevEvent = recentWheelEvents.length ? recentWheelEvents[recentWheelEvents.length - 1] : undefined;
  4918. recentWheelEvents.push(newEvent);
  4919. // If there is at least one previous recorded event:
  4920. // If direction has changed or
  4921. // if the scroll is quicker than the previous one:
  4922. // Animate the slider.
  4923. // Else (this is the first time the wheel is moved):
  4924. // Animate the slider.
  4925. if (prevEvent) {
  4926. if (newEvent.direction !== prevEvent.direction || newEvent.delta > prevEvent.delta || newEvent.time > prevEvent.time + 150) {
  4927. animateSlider(newEvent);
  4928. }
  4929. } else {
  4930. animateSlider(newEvent);
  4931. }
  4932. // If it's time to release the scroll:
  4933. // Return now so you don't hit the preventDefault.
  4934. if (releaseScroll(newEvent)) {
  4935. return true;
  4936. }
  4937. } else {
  4938. // Freemode or scrollContainer:
  4939. // If we recently snapped after a momentum scroll, then ignore wheel events
  4940. // to give time for the deceleration to finish. Stop ignoring after 500 msecs
  4941. // or if it's a new scroll (larger delta or inverse sign as last event before
  4942. // an end-of-momentum snap).
  4943. const newEvent = {
  4944. time: now(),
  4945. delta: Math.abs(delta),
  4946. direction: Math.sign(delta)
  4947. };
  4948. const ignoreWheelEvents = lastEventBeforeSnap && newEvent.time < lastEventBeforeSnap.time + 500 && newEvent.delta <= lastEventBeforeSnap.delta && newEvent.direction === lastEventBeforeSnap.direction;
  4949. if (!ignoreWheelEvents) {
  4950. lastEventBeforeSnap = undefined;
  4951. let position = swiper.getTranslate() + delta * params.sensitivity;
  4952. const wasBeginning = swiper.isBeginning;
  4953. const wasEnd = swiper.isEnd;
  4954. if (position >= swiper.minTranslate()) position = swiper.minTranslate();
  4955. if (position <= swiper.maxTranslate()) position = swiper.maxTranslate();
  4956. swiper.setTransition(0);
  4957. swiper.setTranslate(position);
  4958. swiper.updateProgress();
  4959. swiper.updateActiveIndex();
  4960. swiper.updateSlidesClasses();
  4961. if (!wasBeginning && swiper.isBeginning || !wasEnd && swiper.isEnd) {
  4962. swiper.updateSlidesClasses();
  4963. }
  4964. if (swiper.params.loop) {
  4965. swiper.loopFix({
  4966. direction: newEvent.direction < 0 ? 'next' : 'prev',
  4967. byMousewheel: true
  4968. });
  4969. }
  4970. if (swiper.params.freeMode.sticky) {
  4971. // When wheel scrolling starts with sticky (aka snap) enabled, then detect
  4972. // the end of a momentum scroll by storing recent (N=15?) wheel events.
  4973. // 1. do all N events have decreasing or same (absolute value) delta?
  4974. // 2. did all N events arrive in the last M (M=500?) msecs?
  4975. // 3. does the earliest event have an (absolute value) delta that's
  4976. // at least P (P=1?) larger than the most recent event's delta?
  4977. // 4. does the latest event have a delta that's smaller than Q (Q=6?) pixels?
  4978. // If 1-4 are "yes" then we're near the end of a momentum scroll deceleration.
  4979. // Snap immediately and ignore remaining wheel events in this scroll.
  4980. // See comment above for "remaining wheel events in this scroll" determination.
  4981. // If 1-4 aren't satisfied, then wait to snap until 500ms after the last event.
  4982. clearTimeout(timeout);
  4983. timeout = undefined;
  4984. if (recentWheelEvents.length >= 15) {
  4985. recentWheelEvents.shift(); // only store the last N events
  4986. }
  4987. const prevEvent = recentWheelEvents.length ? recentWheelEvents[recentWheelEvents.length - 1] : undefined;
  4988. const firstEvent = recentWheelEvents[0];
  4989. recentWheelEvents.push(newEvent);
  4990. if (prevEvent && (newEvent.delta > prevEvent.delta || newEvent.direction !== prevEvent.direction)) {
  4991. // Increasing or reverse-sign delta means the user started scrolling again. Clear the wheel event log.
  4992. recentWheelEvents.splice(0);
  4993. } else if (recentWheelEvents.length >= 15 && newEvent.time - firstEvent.time < 500 && firstEvent.delta - newEvent.delta >= 1 && newEvent.delta <= 6) {
  4994. // We're at the end of the deceleration of a momentum scroll, so there's no need
  4995. // to wait for more events. Snap ASAP on the next tick.
  4996. // Also, because there's some remaining momentum we'll bias the snap in the
  4997. // direction of the ongoing scroll because it's better UX for the scroll to snap
  4998. // in the same direction as the scroll instead of reversing to snap. Therefore,
  4999. // if it's already scrolled more than 20% in the current direction, keep going.
  5000. const snapToThreshold = delta > 0 ? 0.8 : 0.2;
  5001. lastEventBeforeSnap = newEvent;
  5002. recentWheelEvents.splice(0);
  5003. timeout = nextTick(() => {
  5004. if (swiper.destroyed || !swiper.params) return;
  5005. swiper.slideToClosest(swiper.params.speed, true, undefined, snapToThreshold);
  5006. }, 0); // no delay; move on next tick
  5007. }
  5008. if (!timeout) {
  5009. // if we get here, then we haven't detected the end of a momentum scroll, so
  5010. // we'll consider a scroll "complete" when there haven't been any wheel events
  5011. // for 500ms.
  5012. timeout = nextTick(() => {
  5013. if (swiper.destroyed || !swiper.params) return;
  5014. const snapToThreshold = 0.5;
  5015. lastEventBeforeSnap = newEvent;
  5016. recentWheelEvents.splice(0);
  5017. swiper.slideToClosest(swiper.params.speed, true, undefined, snapToThreshold);
  5018. }, 500);
  5019. }
  5020. }
  5021. // Emit event
  5022. if (!ignoreWheelEvents) emit('scroll', e);
  5023. // Stop autoplay
  5024. if (swiper.params.autoplay && swiper.params.autoplayDisableOnInteraction) swiper.autoplay.stop();
  5025. // Return page scroll on edge positions
  5026. if (params.releaseOnEdges && (position === swiper.minTranslate() || position === swiper.maxTranslate())) {
  5027. return true;
  5028. }
  5029. }
  5030. }
  5031. if (e.preventDefault) e.preventDefault();else e.returnValue = false;
  5032. return false;
  5033. }
  5034. function events(method) {
  5035. let targetEl = swiper.el;
  5036. if (swiper.params.mousewheel.eventsTarget !== 'container') {
  5037. targetEl = document.querySelector(swiper.params.mousewheel.eventsTarget);
  5038. }
  5039. targetEl[method]('mouseenter', handleMouseEnter);
  5040. targetEl[method]('mouseleave', handleMouseLeave);
  5041. targetEl[method]('wheel', handle);
  5042. }
  5043. function enable() {
  5044. if (swiper.params.cssMode) {
  5045. swiper.wrapperEl.removeEventListener('wheel', handle);
  5046. return true;
  5047. }
  5048. if (swiper.mousewheel.enabled) return false;
  5049. events('addEventListener');
  5050. swiper.mousewheel.enabled = true;
  5051. return true;
  5052. }
  5053. function disable() {
  5054. if (swiper.params.cssMode) {
  5055. swiper.wrapperEl.addEventListener(event, handle);
  5056. return true;
  5057. }
  5058. if (!swiper.mousewheel.enabled) return false;
  5059. events('removeEventListener');
  5060. swiper.mousewheel.enabled = false;
  5061. return true;
  5062. }
  5063. on('init', () => {
  5064. if (!swiper.params.mousewheel.enabled && swiper.params.cssMode) {
  5065. disable();
  5066. }
  5067. if (swiper.params.mousewheel.enabled) enable();
  5068. });
  5069. on('destroy', () => {
  5070. if (swiper.params.cssMode) {
  5071. enable();
  5072. }
  5073. if (swiper.mousewheel.enabled) disable();
  5074. });
  5075. Object.assign(swiper.mousewheel, {
  5076. enable,
  5077. disable
  5078. });
  5079. }
  5080. function createElementIfNotDefined(swiper, originalParams, params, checkProps) {
  5081. if (swiper.params.createElements) {
  5082. Object.keys(checkProps).forEach(key => {
  5083. if (!params[key] && params.auto === true) {
  5084. let element = elementChildren(swiper.el, `.${checkProps[key]}`)[0];
  5085. if (!element) {
  5086. element = createElement('div', checkProps[key]);
  5087. element.className = checkProps[key];
  5088. swiper.el.append(element);
  5089. }
  5090. params[key] = element;
  5091. originalParams[key] = element;
  5092. }
  5093. });
  5094. }
  5095. return params;
  5096. }
  5097. function Navigation(_ref) {
  5098. let {
  5099. swiper,
  5100. extendParams,
  5101. on,
  5102. emit
  5103. } = _ref;
  5104. extendParams({
  5105. navigation: {
  5106. nextEl: null,
  5107. prevEl: null,
  5108. hideOnClick: false,
  5109. disabledClass: 'swiper-button-disabled',
  5110. hiddenClass: 'swiper-button-hidden',
  5111. lockClass: 'swiper-button-lock',
  5112. navigationDisabledClass: 'swiper-navigation-disabled'
  5113. }
  5114. });
  5115. swiper.navigation = {
  5116. nextEl: null,
  5117. prevEl: null
  5118. };
  5119. function getEl(el) {
  5120. let res;
  5121. if (el && typeof el === 'string' && swiper.isElement) {
  5122. res = swiper.el.querySelector(el) || swiper.hostEl.querySelector(el);
  5123. if (res) return res;
  5124. }
  5125. if (el) {
  5126. if (typeof el === 'string') res = [...document.querySelectorAll(el)];
  5127. if (swiper.params.uniqueNavElements && typeof el === 'string' && res && res.length > 1 && swiper.el.querySelectorAll(el).length === 1) {
  5128. res = swiper.el.querySelector(el);
  5129. } else if (res && res.length === 1) {
  5130. res = res[0];
  5131. }
  5132. }
  5133. if (el && !res) return el;
  5134. // if (Array.isArray(res) && res.length === 1) res = res[0];
  5135. return res;
  5136. }
  5137. function toggleEl(el, disabled) {
  5138. const params = swiper.params.navigation;
  5139. el = makeElementsArray(el);
  5140. el.forEach(subEl => {
  5141. if (subEl) {
  5142. subEl.classList[disabled ? 'add' : 'remove'](...params.disabledClass.split(' '));
  5143. if (subEl.tagName === 'BUTTON') subEl.disabled = disabled;
  5144. if (swiper.params.watchOverflow && swiper.enabled) {
  5145. subEl.classList[swiper.isLocked ? 'add' : 'remove'](params.lockClass);
  5146. }
  5147. }
  5148. });
  5149. }
  5150. function update() {
  5151. // Update Navigation Buttons
  5152. const {
  5153. nextEl,
  5154. prevEl
  5155. } = swiper.navigation;
  5156. if (swiper.params.loop) {
  5157. toggleEl(prevEl, false);
  5158. toggleEl(nextEl, false);
  5159. return;
  5160. }
  5161. toggleEl(prevEl, swiper.isBeginning && !swiper.params.rewind);
  5162. toggleEl(nextEl, swiper.isEnd && !swiper.params.rewind);
  5163. }
  5164. function onPrevClick(e) {
  5165. e.preventDefault();
  5166. if (swiper.isBeginning && !swiper.params.loop && !swiper.params.rewind) return;
  5167. swiper.slidePrev();
  5168. emit('navigationPrev');
  5169. }
  5170. function onNextClick(e) {
  5171. e.preventDefault();
  5172. if (swiper.isEnd && !swiper.params.loop && !swiper.params.rewind) return;
  5173. swiper.slideNext();
  5174. emit('navigationNext');
  5175. }
  5176. function init() {
  5177. const params = swiper.params.navigation;
  5178. swiper.params.navigation = createElementIfNotDefined(swiper, swiper.originalParams.navigation, swiper.params.navigation, {
  5179. nextEl: 'swiper-button-next',
  5180. prevEl: 'swiper-button-prev'
  5181. });
  5182. if (!(params.nextEl || params.prevEl)) return;
  5183. let nextEl = getEl(params.nextEl);
  5184. let prevEl = getEl(params.prevEl);
  5185. Object.assign(swiper.navigation, {
  5186. nextEl,
  5187. prevEl
  5188. });
  5189. nextEl = makeElementsArray(nextEl);
  5190. prevEl = makeElementsArray(prevEl);
  5191. const initButton = (el, dir) => {
  5192. if (el) {
  5193. el.addEventListener('click', dir === 'next' ? onNextClick : onPrevClick);
  5194. }
  5195. if (!swiper.enabled && el) {
  5196. el.classList.add(...params.lockClass.split(' '));
  5197. }
  5198. };
  5199. nextEl.forEach(el => initButton(el, 'next'));
  5200. prevEl.forEach(el => initButton(el, 'prev'));
  5201. }
  5202. function destroy() {
  5203. let {
  5204. nextEl,
  5205. prevEl
  5206. } = swiper.navigation;
  5207. nextEl = makeElementsArray(nextEl);
  5208. prevEl = makeElementsArray(prevEl);
  5209. const destroyButton = (el, dir) => {
  5210. el.removeEventListener('click', dir === 'next' ? onNextClick : onPrevClick);
  5211. el.classList.remove(...swiper.params.navigation.disabledClass.split(' '));
  5212. };
  5213. nextEl.forEach(el => destroyButton(el, 'next'));
  5214. prevEl.forEach(el => destroyButton(el, 'prev'));
  5215. }
  5216. on('init', () => {
  5217. if (swiper.params.navigation.enabled === false) {
  5218. // eslint-disable-next-line
  5219. disable();
  5220. } else {
  5221. init();
  5222. update();
  5223. }
  5224. });
  5225. on('toEdge fromEdge lock unlock', () => {
  5226. update();
  5227. });
  5228. on('destroy', () => {
  5229. destroy();
  5230. });
  5231. on('enable disable', () => {
  5232. let {
  5233. nextEl,
  5234. prevEl
  5235. } = swiper.navigation;
  5236. nextEl = makeElementsArray(nextEl);
  5237. prevEl = makeElementsArray(prevEl);
  5238. if (swiper.enabled) {
  5239. update();
  5240. return;
  5241. }
  5242. [...nextEl, ...prevEl].filter(el => !!el).forEach(el => el.classList.add(swiper.params.navigation.lockClass));
  5243. });
  5244. on('click', (_s, e) => {
  5245. let {
  5246. nextEl,
  5247. prevEl
  5248. } = swiper.navigation;
  5249. nextEl = makeElementsArray(nextEl);
  5250. prevEl = makeElementsArray(prevEl);
  5251. const targetEl = e.target;
  5252. let targetIsButton = prevEl.includes(targetEl) || nextEl.includes(targetEl);
  5253. if (swiper.isElement && !targetIsButton) {
  5254. const path = e.path || e.composedPath && e.composedPath();
  5255. if (path) {
  5256. targetIsButton = path.find(pathEl => nextEl.includes(pathEl) || prevEl.includes(pathEl));
  5257. }
  5258. }
  5259. if (swiper.params.navigation.hideOnClick && !targetIsButton) {
  5260. if (swiper.pagination && swiper.params.pagination && swiper.params.pagination.clickable && (swiper.pagination.el === targetEl || swiper.pagination.el.contains(targetEl))) return;
  5261. let isHidden;
  5262. if (nextEl.length) {
  5263. isHidden = nextEl[0].classList.contains(swiper.params.navigation.hiddenClass);
  5264. } else if (prevEl.length) {
  5265. isHidden = prevEl[0].classList.contains(swiper.params.navigation.hiddenClass);
  5266. }
  5267. if (isHidden === true) {
  5268. emit('navigationShow');
  5269. } else {
  5270. emit('navigationHide');
  5271. }
  5272. [...nextEl, ...prevEl].filter(el => !!el).forEach(el => el.classList.toggle(swiper.params.navigation.hiddenClass));
  5273. }
  5274. });
  5275. const enable = () => {
  5276. swiper.el.classList.remove(...swiper.params.navigation.navigationDisabledClass.split(' '));
  5277. init();
  5278. update();
  5279. };
  5280. const disable = () => {
  5281. swiper.el.classList.add(...swiper.params.navigation.navigationDisabledClass.split(' '));
  5282. destroy();
  5283. };
  5284. Object.assign(swiper.navigation, {
  5285. enable,
  5286. disable,
  5287. update,
  5288. init,
  5289. destroy
  5290. });
  5291. }
  5292. function classesToSelector(classes) {
  5293. if (classes === void 0) {
  5294. classes = '';
  5295. }
  5296. return `.${classes.trim().replace(/([\.:!+\/])/g, '\\$1') // eslint-disable-line
  5297. .replace(/ /g, '.')}`;
  5298. }
  5299. function Pagination(_ref) {
  5300. let {
  5301. swiper,
  5302. extendParams,
  5303. on,
  5304. emit
  5305. } = _ref;
  5306. const pfx = 'swiper-pagination';
  5307. extendParams({
  5308. pagination: {
  5309. el: null,
  5310. bulletElement: 'span',
  5311. clickable: false,
  5312. hideOnClick: false,
  5313. renderBullet: null,
  5314. renderProgressbar: null,
  5315. renderFraction: null,
  5316. renderCustom: null,
  5317. progressbarOpposite: false,
  5318. type: 'bullets',
  5319. // 'bullets' or 'progressbar' or 'fraction' or 'custom'
  5320. dynamicBullets: false,
  5321. dynamicMainBullets: 1,
  5322. formatFractionCurrent: number => number,
  5323. formatFractionTotal: number => number,
  5324. bulletClass: `${pfx}-bullet`,
  5325. bulletActiveClass: `${pfx}-bullet-active`,
  5326. modifierClass: `${pfx}-`,
  5327. currentClass: `${pfx}-current`,
  5328. totalClass: `${pfx}-total`,
  5329. hiddenClass: `${pfx}-hidden`,
  5330. progressbarFillClass: `${pfx}-progressbar-fill`,
  5331. progressbarOppositeClass: `${pfx}-progressbar-opposite`,
  5332. clickableClass: `${pfx}-clickable`,
  5333. lockClass: `${pfx}-lock`,
  5334. horizontalClass: `${pfx}-horizontal`,
  5335. verticalClass: `${pfx}-vertical`,
  5336. paginationDisabledClass: `${pfx}-disabled`
  5337. }
  5338. });
  5339. swiper.pagination = {
  5340. el: null,
  5341. bullets: []
  5342. };
  5343. let bulletSize;
  5344. let dynamicBulletIndex = 0;
  5345. function isPaginationDisabled() {
  5346. return !swiper.params.pagination.el || !swiper.pagination.el || Array.isArray(swiper.pagination.el) && swiper.pagination.el.length === 0;
  5347. }
  5348. function setSideBullets(bulletEl, position) {
  5349. const {
  5350. bulletActiveClass
  5351. } = swiper.params.pagination;
  5352. if (!bulletEl) return;
  5353. bulletEl = bulletEl[`${position === 'prev' ? 'previous' : 'next'}ElementSibling`];
  5354. if (bulletEl) {
  5355. bulletEl.classList.add(`${bulletActiveClass}-${position}`);
  5356. bulletEl = bulletEl[`${position === 'prev' ? 'previous' : 'next'}ElementSibling`];
  5357. if (bulletEl) {
  5358. bulletEl.classList.add(`${bulletActiveClass}-${position}-${position}`);
  5359. }
  5360. }
  5361. }
  5362. function getMoveDirection(prevIndex, nextIndex, length) {
  5363. prevIndex = prevIndex % length;
  5364. nextIndex = nextIndex % length;
  5365. if (nextIndex === prevIndex + 1) {
  5366. return 'next';
  5367. } else if (nextIndex === prevIndex - 1) {
  5368. return 'previous';
  5369. }
  5370. return;
  5371. }
  5372. function onBulletClick(e) {
  5373. const bulletEl = e.target.closest(classesToSelector(swiper.params.pagination.bulletClass));
  5374. if (!bulletEl) {
  5375. return;
  5376. }
  5377. e.preventDefault();
  5378. const index = elementIndex(bulletEl) * swiper.params.slidesPerGroup;
  5379. if (swiper.params.loop) {
  5380. if (swiper.realIndex === index) return;
  5381. const moveDirection = getMoveDirection(swiper.realIndex, index, swiper.slides.length);
  5382. if (moveDirection === 'next') {
  5383. swiper.slideNext();
  5384. } else if (moveDirection === 'previous') {
  5385. swiper.slidePrev();
  5386. } else {
  5387. swiper.slideToLoop(index);
  5388. }
  5389. } else {
  5390. swiper.slideTo(index);
  5391. }
  5392. }
  5393. function update() {
  5394. // Render || Update Pagination bullets/items
  5395. const rtl = swiper.rtl;
  5396. const params = swiper.params.pagination;
  5397. if (isPaginationDisabled()) return;
  5398. let el = swiper.pagination.el;
  5399. el = makeElementsArray(el);
  5400. // Current/Total
  5401. let current;
  5402. let previousIndex;
  5403. const slidesLength = swiper.virtual && swiper.params.virtual.enabled ? swiper.virtual.slides.length : swiper.slides.length;
  5404. const total = swiper.params.loop ? Math.ceil(slidesLength / swiper.params.slidesPerGroup) : swiper.snapGrid.length;
  5405. if (swiper.params.loop) {
  5406. previousIndex = swiper.previousRealIndex || 0;
  5407. current = swiper.params.slidesPerGroup > 1 ? Math.floor(swiper.realIndex / swiper.params.slidesPerGroup) : swiper.realIndex;
  5408. } else if (typeof swiper.snapIndex !== 'undefined') {
  5409. current = swiper.snapIndex;
  5410. previousIndex = swiper.previousSnapIndex;
  5411. } else {
  5412. previousIndex = swiper.previousIndex || 0;
  5413. current = swiper.activeIndex || 0;
  5414. }
  5415. // Types
  5416. if (params.type === 'bullets' && swiper.pagination.bullets && swiper.pagination.bullets.length > 0) {
  5417. const bullets = swiper.pagination.bullets;
  5418. let firstIndex;
  5419. let lastIndex;
  5420. let midIndex;
  5421. if (params.dynamicBullets) {
  5422. bulletSize = elementOuterSize(bullets[0], swiper.isHorizontal() ? 'width' : 'height', true);
  5423. el.forEach(subEl => {
  5424. subEl.style[swiper.isHorizontal() ? 'width' : 'height'] = `${bulletSize * (params.dynamicMainBullets + 4)}px`;
  5425. });
  5426. if (params.dynamicMainBullets > 1 && previousIndex !== undefined) {
  5427. dynamicBulletIndex += current - (previousIndex || 0);
  5428. if (dynamicBulletIndex > params.dynamicMainBullets - 1) {
  5429. dynamicBulletIndex = params.dynamicMainBullets - 1;
  5430. } else if (dynamicBulletIndex < 0) {
  5431. dynamicBulletIndex = 0;
  5432. }
  5433. }
  5434. firstIndex = Math.max(current - dynamicBulletIndex, 0);
  5435. lastIndex = firstIndex + (Math.min(bullets.length, params.dynamicMainBullets) - 1);
  5436. midIndex = (lastIndex + firstIndex) / 2;
  5437. }
  5438. bullets.forEach(bulletEl => {
  5439. const classesToRemove = [...['', '-next', '-next-next', '-prev', '-prev-prev', '-main'].map(suffix => `${params.bulletActiveClass}${suffix}`)].map(s => typeof s === 'string' && s.includes(' ') ? s.split(' ') : s).flat();
  5440. bulletEl.classList.remove(...classesToRemove);
  5441. });
  5442. if (el.length > 1) {
  5443. bullets.forEach(bullet => {
  5444. const bulletIndex = elementIndex(bullet);
  5445. if (bulletIndex === current) {
  5446. bullet.classList.add(...params.bulletActiveClass.split(' '));
  5447. } else if (swiper.isElement) {
  5448. bullet.setAttribute('part', 'bullet');
  5449. }
  5450. if (params.dynamicBullets) {
  5451. if (bulletIndex >= firstIndex && bulletIndex <= lastIndex) {
  5452. bullet.classList.add(...`${params.bulletActiveClass}-main`.split(' '));
  5453. }
  5454. if (bulletIndex === firstIndex) {
  5455. setSideBullets(bullet, 'prev');
  5456. }
  5457. if (bulletIndex === lastIndex) {
  5458. setSideBullets(bullet, 'next');
  5459. }
  5460. }
  5461. });
  5462. } else {
  5463. const bullet = bullets[current];
  5464. if (bullet) {
  5465. bullet.classList.add(...params.bulletActiveClass.split(' '));
  5466. }
  5467. if (swiper.isElement) {
  5468. bullets.forEach((bulletEl, bulletIndex) => {
  5469. bulletEl.setAttribute('part', bulletIndex === current ? 'bullet-active' : 'bullet');
  5470. });
  5471. }
  5472. if (params.dynamicBullets) {
  5473. const firstDisplayedBullet = bullets[firstIndex];
  5474. const lastDisplayedBullet = bullets[lastIndex];
  5475. for (let i = firstIndex; i <= lastIndex; i += 1) {
  5476. if (bullets[i]) {
  5477. bullets[i].classList.add(...`${params.bulletActiveClass}-main`.split(' '));
  5478. }
  5479. }
  5480. setSideBullets(firstDisplayedBullet, 'prev');
  5481. setSideBullets(lastDisplayedBullet, 'next');
  5482. }
  5483. }
  5484. if (params.dynamicBullets) {
  5485. const dynamicBulletsLength = Math.min(bullets.length, params.dynamicMainBullets + 4);
  5486. const bulletsOffset = (bulletSize * dynamicBulletsLength - bulletSize) / 2 - midIndex * bulletSize;
  5487. const offsetProp = rtl ? 'right' : 'left';
  5488. bullets.forEach(bullet => {
  5489. bullet.style[swiper.isHorizontal() ? offsetProp : 'top'] = `${bulletsOffset}px`;
  5490. });
  5491. }
  5492. }
  5493. el.forEach((subEl, subElIndex) => {
  5494. if (params.type === 'fraction') {
  5495. subEl.querySelectorAll(classesToSelector(params.currentClass)).forEach(fractionEl => {
  5496. fractionEl.textContent = params.formatFractionCurrent(current + 1);
  5497. });
  5498. subEl.querySelectorAll(classesToSelector(params.totalClass)).forEach(totalEl => {
  5499. totalEl.textContent = params.formatFractionTotal(total);
  5500. });
  5501. }
  5502. if (params.type === 'progressbar') {
  5503. let progressbarDirection;
  5504. if (params.progressbarOpposite) {
  5505. progressbarDirection = swiper.isHorizontal() ? 'vertical' : 'horizontal';
  5506. } else {
  5507. progressbarDirection = swiper.isHorizontal() ? 'horizontal' : 'vertical';
  5508. }
  5509. const scale = (current + 1) / total;
  5510. let scaleX = 1;
  5511. let scaleY = 1;
  5512. if (progressbarDirection === 'horizontal') {
  5513. scaleX = scale;
  5514. } else {
  5515. scaleY = scale;
  5516. }
  5517. subEl.querySelectorAll(classesToSelector(params.progressbarFillClass)).forEach(progressEl => {
  5518. progressEl.style.transform = `translate3d(0,0,0) scaleX(${scaleX}) scaleY(${scaleY})`;
  5519. progressEl.style.transitionDuration = `${swiper.params.speed}ms`;
  5520. });
  5521. }
  5522. if (params.type === 'custom' && params.renderCustom) {
  5523. subEl.innerHTML = params.renderCustom(swiper, current + 1, total);
  5524. if (subElIndex === 0) emit('paginationRender', subEl);
  5525. } else {
  5526. if (subElIndex === 0) emit('paginationRender', subEl);
  5527. emit('paginationUpdate', subEl);
  5528. }
  5529. if (swiper.params.watchOverflow && swiper.enabled) {
  5530. subEl.classList[swiper.isLocked ? 'add' : 'remove'](params.lockClass);
  5531. }
  5532. });
  5533. }
  5534. function render() {
  5535. // Render Container
  5536. const params = swiper.params.pagination;
  5537. if (isPaginationDisabled()) return;
  5538. const slidesLength = swiper.virtual && swiper.params.virtual.enabled ? swiper.virtual.slides.length : swiper.grid && swiper.params.grid.rows > 1 ? swiper.slides.length / Math.ceil(swiper.params.grid.rows) : swiper.slides.length;
  5539. let el = swiper.pagination.el;
  5540. el = makeElementsArray(el);
  5541. let paginationHTML = '';
  5542. if (params.type === 'bullets') {
  5543. let numberOfBullets = swiper.params.loop ? Math.ceil(slidesLength / swiper.params.slidesPerGroup) : swiper.snapGrid.length;
  5544. if (swiper.params.freeMode && swiper.params.freeMode.enabled && numberOfBullets > slidesLength) {
  5545. numberOfBullets = slidesLength;
  5546. }
  5547. for (let i = 0; i < numberOfBullets; i += 1) {
  5548. if (params.renderBullet) {
  5549. paginationHTML += params.renderBullet.call(swiper, i, params.bulletClass);
  5550. } else {
  5551. // prettier-ignore
  5552. paginationHTML += `<${params.bulletElement} ${swiper.isElement ? 'part="bullet"' : ''} class="${params.bulletClass}"></${params.bulletElement}>`;
  5553. }
  5554. }
  5555. }
  5556. if (params.type === 'fraction') {
  5557. if (params.renderFraction) {
  5558. paginationHTML = params.renderFraction.call(swiper, params.currentClass, params.totalClass);
  5559. } else {
  5560. paginationHTML = `<span class="${params.currentClass}"></span>` + ' / ' + `<span class="${params.totalClass}"></span>`;
  5561. }
  5562. }
  5563. if (params.type === 'progressbar') {
  5564. if (params.renderProgressbar) {
  5565. paginationHTML = params.renderProgressbar.call(swiper, params.progressbarFillClass);
  5566. } else {
  5567. paginationHTML = `<span class="${params.progressbarFillClass}"></span>`;
  5568. }
  5569. }
  5570. swiper.pagination.bullets = [];
  5571. el.forEach(subEl => {
  5572. if (params.type !== 'custom') {
  5573. subEl.innerHTML = paginationHTML || '';
  5574. }
  5575. if (params.type === 'bullets') {
  5576. swiper.pagination.bullets.push(...subEl.querySelectorAll(classesToSelector(params.bulletClass)));
  5577. }
  5578. });
  5579. if (params.type !== 'custom') {
  5580. emit('paginationRender', el[0]);
  5581. }
  5582. }
  5583. function init() {
  5584. swiper.params.pagination = createElementIfNotDefined(swiper, swiper.originalParams.pagination, swiper.params.pagination, {
  5585. el: 'swiper-pagination'
  5586. });
  5587. const params = swiper.params.pagination;
  5588. if (!params.el) return;
  5589. let el;
  5590. if (typeof params.el === 'string' && swiper.isElement) {
  5591. el = swiper.el.querySelector(params.el);
  5592. }
  5593. if (!el && typeof params.el === 'string') {
  5594. el = [...document.querySelectorAll(params.el)];
  5595. }
  5596. if (!el) {
  5597. el = params.el;
  5598. }
  5599. if (!el || el.length === 0) return;
  5600. if (swiper.params.uniqueNavElements && typeof params.el === 'string' && Array.isArray(el) && el.length > 1) {
  5601. el = [...swiper.el.querySelectorAll(params.el)];
  5602. // check if it belongs to another nested Swiper
  5603. if (el.length > 1) {
  5604. el = el.filter(subEl => {
  5605. if (elementParents(subEl, '.swiper')[0] !== swiper.el) return false;
  5606. return true;
  5607. })[0];
  5608. }
  5609. }
  5610. if (Array.isArray(el) && el.length === 1) el = el[0];
  5611. Object.assign(swiper.pagination, {
  5612. el
  5613. });
  5614. el = makeElementsArray(el);
  5615. el.forEach(subEl => {
  5616. if (params.type === 'bullets' && params.clickable) {
  5617. subEl.classList.add(...(params.clickableClass || '').split(' '));
  5618. }
  5619. subEl.classList.add(params.modifierClass + params.type);
  5620. subEl.classList.add(swiper.isHorizontal() ? params.horizontalClass : params.verticalClass);
  5621. if (params.type === 'bullets' && params.dynamicBullets) {
  5622. subEl.classList.add(`${params.modifierClass}${params.type}-dynamic`);
  5623. dynamicBulletIndex = 0;
  5624. if (params.dynamicMainBullets < 1) {
  5625. params.dynamicMainBullets = 1;
  5626. }
  5627. }
  5628. if (params.type === 'progressbar' && params.progressbarOpposite) {
  5629. subEl.classList.add(params.progressbarOppositeClass);
  5630. }
  5631. if (params.clickable) {
  5632. subEl.addEventListener('click', onBulletClick);
  5633. }
  5634. if (!swiper.enabled) {
  5635. subEl.classList.add(params.lockClass);
  5636. }
  5637. });
  5638. }
  5639. function destroy() {
  5640. const params = swiper.params.pagination;
  5641. if (isPaginationDisabled()) return;
  5642. let el = swiper.pagination.el;
  5643. if (el) {
  5644. el = makeElementsArray(el);
  5645. el.forEach(subEl => {
  5646. subEl.classList.remove(params.hiddenClass);
  5647. subEl.classList.remove(params.modifierClass + params.type);
  5648. subEl.classList.remove(swiper.isHorizontal() ? params.horizontalClass : params.verticalClass);
  5649. if (params.clickable) {
  5650. subEl.classList.remove(...(params.clickableClass || '').split(' '));
  5651. subEl.removeEventListener('click', onBulletClick);
  5652. }
  5653. });
  5654. }
  5655. if (swiper.pagination.bullets) swiper.pagination.bullets.forEach(subEl => subEl.classList.remove(...params.bulletActiveClass.split(' ')));
  5656. }
  5657. on('changeDirection', () => {
  5658. if (!swiper.pagination || !swiper.pagination.el) return;
  5659. const params = swiper.params.pagination;
  5660. let {
  5661. el
  5662. } = swiper.pagination;
  5663. el = makeElementsArray(el);
  5664. el.forEach(subEl => {
  5665. subEl.classList.remove(params.horizontalClass, params.verticalClass);
  5666. subEl.classList.add(swiper.isHorizontal() ? params.horizontalClass : params.verticalClass);
  5667. });
  5668. });
  5669. on('init', () => {
  5670. if (swiper.params.pagination.enabled === false) {
  5671. // eslint-disable-next-line
  5672. disable();
  5673. } else {
  5674. init();
  5675. render();
  5676. update();
  5677. }
  5678. });
  5679. on('activeIndexChange', () => {
  5680. if (typeof swiper.snapIndex === 'undefined') {
  5681. update();
  5682. }
  5683. });
  5684. on('snapIndexChange', () => {
  5685. update();
  5686. });
  5687. on('snapGridLengthChange', () => {
  5688. render();
  5689. update();
  5690. });
  5691. on('destroy', () => {
  5692. destroy();
  5693. });
  5694. on('enable disable', () => {
  5695. let {
  5696. el
  5697. } = swiper.pagination;
  5698. if (el) {
  5699. el = makeElementsArray(el);
  5700. el.forEach(subEl => subEl.classList[swiper.enabled ? 'remove' : 'add'](swiper.params.pagination.lockClass));
  5701. }
  5702. });
  5703. on('lock unlock', () => {
  5704. update();
  5705. });
  5706. on('click', (_s, e) => {
  5707. const targetEl = e.target;
  5708. const el = makeElementsArray(swiper.pagination.el);
  5709. if (swiper.params.pagination.el && swiper.params.pagination.hideOnClick && el && el.length > 0 && !targetEl.classList.contains(swiper.params.pagination.bulletClass)) {
  5710. if (swiper.navigation && (swiper.navigation.nextEl && targetEl === swiper.navigation.nextEl || swiper.navigation.prevEl && targetEl === swiper.navigation.prevEl)) return;
  5711. const isHidden = el[0].classList.contains(swiper.params.pagination.hiddenClass);
  5712. if (isHidden === true) {
  5713. emit('paginationShow');
  5714. } else {
  5715. emit('paginationHide');
  5716. }
  5717. el.forEach(subEl => subEl.classList.toggle(swiper.params.pagination.hiddenClass));
  5718. }
  5719. });
  5720. const enable = () => {
  5721. swiper.el.classList.remove(swiper.params.pagination.paginationDisabledClass);
  5722. let {
  5723. el
  5724. } = swiper.pagination;
  5725. if (el) {
  5726. el = makeElementsArray(el);
  5727. el.forEach(subEl => subEl.classList.remove(swiper.params.pagination.paginationDisabledClass));
  5728. }
  5729. init();
  5730. render();
  5731. update();
  5732. };
  5733. const disable = () => {
  5734. swiper.el.classList.add(swiper.params.pagination.paginationDisabledClass);
  5735. let {
  5736. el
  5737. } = swiper.pagination;
  5738. if (el) {
  5739. el = makeElementsArray(el);
  5740. el.forEach(subEl => subEl.classList.add(swiper.params.pagination.paginationDisabledClass));
  5741. }
  5742. destroy();
  5743. };
  5744. Object.assign(swiper.pagination, {
  5745. enable,
  5746. disable,
  5747. render,
  5748. update,
  5749. init,
  5750. destroy
  5751. });
  5752. }
  5753. function Scrollbar(_ref) {
  5754. let {
  5755. swiper,
  5756. extendParams,
  5757. on,
  5758. emit
  5759. } = _ref;
  5760. const document = getDocument();
  5761. let isTouched = false;
  5762. let timeout = null;
  5763. let dragTimeout = null;
  5764. let dragStartPos;
  5765. let dragSize;
  5766. let trackSize;
  5767. let divider;
  5768. extendParams({
  5769. scrollbar: {
  5770. el: null,
  5771. dragSize: 'auto',
  5772. hide: false,
  5773. draggable: false,
  5774. snapOnRelease: true,
  5775. lockClass: 'swiper-scrollbar-lock',
  5776. dragClass: 'swiper-scrollbar-drag',
  5777. scrollbarDisabledClass: 'swiper-scrollbar-disabled',
  5778. horizontalClass: `swiper-scrollbar-horizontal`,
  5779. verticalClass: `swiper-scrollbar-vertical`
  5780. }
  5781. });
  5782. swiper.scrollbar = {
  5783. el: null,
  5784. dragEl: null
  5785. };
  5786. function setTranslate() {
  5787. if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return;
  5788. const {
  5789. scrollbar,
  5790. rtlTranslate: rtl
  5791. } = swiper;
  5792. const {
  5793. dragEl,
  5794. el
  5795. } = scrollbar;
  5796. const params = swiper.params.scrollbar;
  5797. const progress = swiper.params.loop ? swiper.progressLoop : swiper.progress;
  5798. let newSize = dragSize;
  5799. let newPos = (trackSize - dragSize) * progress;
  5800. if (rtl) {
  5801. newPos = -newPos;
  5802. if (newPos > 0) {
  5803. newSize = dragSize - newPos;
  5804. newPos = 0;
  5805. } else if (-newPos + dragSize > trackSize) {
  5806. newSize = trackSize + newPos;
  5807. }
  5808. } else if (newPos < 0) {
  5809. newSize = dragSize + newPos;
  5810. newPos = 0;
  5811. } else if (newPos + dragSize > trackSize) {
  5812. newSize = trackSize - newPos;
  5813. }
  5814. if (swiper.isHorizontal()) {
  5815. dragEl.style.transform = `translate3d(${newPos}px, 0, 0)`;
  5816. dragEl.style.width = `${newSize}px`;
  5817. } else {
  5818. dragEl.style.transform = `translate3d(0px, ${newPos}px, 0)`;
  5819. dragEl.style.height = `${newSize}px`;
  5820. }
  5821. if (params.hide) {
  5822. clearTimeout(timeout);
  5823. el.style.opacity = 1;
  5824. timeout = setTimeout(() => {
  5825. el.style.opacity = 0;
  5826. el.style.transitionDuration = '400ms';
  5827. }, 1000);
  5828. }
  5829. }
  5830. function setTransition(duration) {
  5831. if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return;
  5832. swiper.scrollbar.dragEl.style.transitionDuration = `${duration}ms`;
  5833. }
  5834. function updateSize() {
  5835. if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return;
  5836. const {
  5837. scrollbar
  5838. } = swiper;
  5839. const {
  5840. dragEl,
  5841. el
  5842. } = scrollbar;
  5843. dragEl.style.width = '';
  5844. dragEl.style.height = '';
  5845. trackSize = swiper.isHorizontal() ? el.offsetWidth : el.offsetHeight;
  5846. divider = swiper.size / (swiper.virtualSize + swiper.params.slidesOffsetBefore - (swiper.params.centeredSlides ? swiper.snapGrid[0] : 0));
  5847. if (swiper.params.scrollbar.dragSize === 'auto') {
  5848. dragSize = trackSize * divider;
  5849. } else {
  5850. dragSize = parseInt(swiper.params.scrollbar.dragSize, 10);
  5851. }
  5852. if (swiper.isHorizontal()) {
  5853. dragEl.style.width = `${dragSize}px`;
  5854. } else {
  5855. dragEl.style.height = `${dragSize}px`;
  5856. }
  5857. if (divider >= 1) {
  5858. el.style.display = 'none';
  5859. } else {
  5860. el.style.display = '';
  5861. }
  5862. if (swiper.params.scrollbar.hide) {
  5863. el.style.opacity = 0;
  5864. }
  5865. if (swiper.params.watchOverflow && swiper.enabled) {
  5866. scrollbar.el.classList[swiper.isLocked ? 'add' : 'remove'](swiper.params.scrollbar.lockClass);
  5867. }
  5868. }
  5869. function getPointerPosition(e) {
  5870. return swiper.isHorizontal() ? e.clientX : e.clientY;
  5871. }
  5872. function setDragPosition(e) {
  5873. const {
  5874. scrollbar,
  5875. rtlTranslate: rtl
  5876. } = swiper;
  5877. const {
  5878. el
  5879. } = scrollbar;
  5880. let positionRatio;
  5881. positionRatio = (getPointerPosition(e) - elementOffset(el)[swiper.isHorizontal() ? 'left' : 'top'] - (dragStartPos !== null ? dragStartPos : dragSize / 2)) / (trackSize - dragSize);
  5882. positionRatio = Math.max(Math.min(positionRatio, 1), 0);
  5883. if (rtl) {
  5884. positionRatio = 1 - positionRatio;
  5885. }
  5886. const position = swiper.minTranslate() + (swiper.maxTranslate() - swiper.minTranslate()) * positionRatio;
  5887. swiper.updateProgress(position);
  5888. swiper.setTranslate(position);
  5889. swiper.updateActiveIndex();
  5890. swiper.updateSlidesClasses();
  5891. }
  5892. function onDragStart(e) {
  5893. const params = swiper.params.scrollbar;
  5894. const {
  5895. scrollbar,
  5896. wrapperEl
  5897. } = swiper;
  5898. const {
  5899. el,
  5900. dragEl
  5901. } = scrollbar;
  5902. isTouched = true;
  5903. dragStartPos = e.target === dragEl ? getPointerPosition(e) - e.target.getBoundingClientRect()[swiper.isHorizontal() ? 'left' : 'top'] : null;
  5904. e.preventDefault();
  5905. e.stopPropagation();
  5906. wrapperEl.style.transitionDuration = '100ms';
  5907. dragEl.style.transitionDuration = '100ms';
  5908. setDragPosition(e);
  5909. clearTimeout(dragTimeout);
  5910. el.style.transitionDuration = '0ms';
  5911. if (params.hide) {
  5912. el.style.opacity = 1;
  5913. }
  5914. if (swiper.params.cssMode) {
  5915. swiper.wrapperEl.style['scroll-snap-type'] = 'none';
  5916. }
  5917. emit('scrollbarDragStart', e);
  5918. }
  5919. function onDragMove(e) {
  5920. const {
  5921. scrollbar,
  5922. wrapperEl
  5923. } = swiper;
  5924. const {
  5925. el,
  5926. dragEl
  5927. } = scrollbar;
  5928. if (!isTouched) return;
  5929. if (e.preventDefault && e.cancelable) e.preventDefault();else e.returnValue = false;
  5930. setDragPosition(e);
  5931. wrapperEl.style.transitionDuration = '0ms';
  5932. el.style.transitionDuration = '0ms';
  5933. dragEl.style.transitionDuration = '0ms';
  5934. emit('scrollbarDragMove', e);
  5935. }
  5936. function onDragEnd(e) {
  5937. const params = swiper.params.scrollbar;
  5938. const {
  5939. scrollbar,
  5940. wrapperEl
  5941. } = swiper;
  5942. const {
  5943. el
  5944. } = scrollbar;
  5945. if (!isTouched) return;
  5946. isTouched = false;
  5947. if (swiper.params.cssMode) {
  5948. swiper.wrapperEl.style['scroll-snap-type'] = '';
  5949. wrapperEl.style.transitionDuration = '';
  5950. }
  5951. if (params.hide) {
  5952. clearTimeout(dragTimeout);
  5953. dragTimeout = nextTick(() => {
  5954. el.style.opacity = 0;
  5955. el.style.transitionDuration = '400ms';
  5956. }, 1000);
  5957. }
  5958. emit('scrollbarDragEnd', e);
  5959. if (params.snapOnRelease) {
  5960. swiper.slideToClosest();
  5961. }
  5962. }
  5963. function events(method) {
  5964. const {
  5965. scrollbar,
  5966. params
  5967. } = swiper;
  5968. const el = scrollbar.el;
  5969. if (!el) return;
  5970. const target = el;
  5971. const activeListener = params.passiveListeners ? {
  5972. passive: false,
  5973. capture: false
  5974. } : false;
  5975. const passiveListener = params.passiveListeners ? {
  5976. passive: true,
  5977. capture: false
  5978. } : false;
  5979. if (!target) return;
  5980. const eventMethod = method === 'on' ? 'addEventListener' : 'removeEventListener';
  5981. target[eventMethod]('pointerdown', onDragStart, activeListener);
  5982. document[eventMethod]('pointermove', onDragMove, activeListener);
  5983. document[eventMethod]('pointerup', onDragEnd, passiveListener);
  5984. }
  5985. function enableDraggable() {
  5986. if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return;
  5987. events('on');
  5988. }
  5989. function disableDraggable() {
  5990. if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return;
  5991. events('off');
  5992. }
  5993. function init() {
  5994. const {
  5995. scrollbar,
  5996. el: swiperEl
  5997. } = swiper;
  5998. swiper.params.scrollbar = createElementIfNotDefined(swiper, swiper.originalParams.scrollbar, swiper.params.scrollbar, {
  5999. el: 'swiper-scrollbar'
  6000. });
  6001. const params = swiper.params.scrollbar;
  6002. if (!params.el) return;
  6003. let el;
  6004. if (typeof params.el === 'string' && swiper.isElement) {
  6005. el = swiper.el.querySelector(params.el);
  6006. }
  6007. if (!el && typeof params.el === 'string') {
  6008. el = document.querySelectorAll(params.el);
  6009. if (!el.length) return;
  6010. } else if (!el) {
  6011. el = params.el;
  6012. }
  6013. if (swiper.params.uniqueNavElements && typeof params.el === 'string' && el.length > 1 && swiperEl.querySelectorAll(params.el).length === 1) {
  6014. el = swiperEl.querySelector(params.el);
  6015. }
  6016. if (el.length > 0) el = el[0];
  6017. el.classList.add(swiper.isHorizontal() ? params.horizontalClass : params.verticalClass);
  6018. let dragEl;
  6019. if (el) {
  6020. dragEl = el.querySelector(classesToSelector(swiper.params.scrollbar.dragClass));
  6021. if (!dragEl) {
  6022. dragEl = createElement('div', swiper.params.scrollbar.dragClass);
  6023. el.append(dragEl);
  6024. }
  6025. }
  6026. Object.assign(scrollbar, {
  6027. el,
  6028. dragEl
  6029. });
  6030. if (params.draggable) {
  6031. enableDraggable();
  6032. }
  6033. if (el) {
  6034. el.classList[swiper.enabled ? 'remove' : 'add'](...classesToTokens(swiper.params.scrollbar.lockClass));
  6035. }
  6036. }
  6037. function destroy() {
  6038. const params = swiper.params.scrollbar;
  6039. const el = swiper.scrollbar.el;
  6040. if (el) {
  6041. el.classList.remove(...classesToTokens(swiper.isHorizontal() ? params.horizontalClass : params.verticalClass));
  6042. }
  6043. disableDraggable();
  6044. }
  6045. on('changeDirection', () => {
  6046. if (!swiper.scrollbar || !swiper.scrollbar.el) return;
  6047. const params = swiper.params.scrollbar;
  6048. let {
  6049. el
  6050. } = swiper.scrollbar;
  6051. el = makeElementsArray(el);
  6052. el.forEach(subEl => {
  6053. subEl.classList.remove(params.horizontalClass, params.verticalClass);
  6054. subEl.classList.add(swiper.isHorizontal() ? params.horizontalClass : params.verticalClass);
  6055. });
  6056. });
  6057. on('init', () => {
  6058. if (swiper.params.scrollbar.enabled === false) {
  6059. // eslint-disable-next-line
  6060. disable();
  6061. } else {
  6062. init();
  6063. updateSize();
  6064. setTranslate();
  6065. }
  6066. });
  6067. on('update resize observerUpdate lock unlock changeDirection', () => {
  6068. updateSize();
  6069. });
  6070. on('setTranslate', () => {
  6071. setTranslate();
  6072. });
  6073. on('setTransition', (_s, duration) => {
  6074. setTransition(duration);
  6075. });
  6076. on('enable disable', () => {
  6077. const {
  6078. el
  6079. } = swiper.scrollbar;
  6080. if (el) {
  6081. el.classList[swiper.enabled ? 'remove' : 'add'](...classesToTokens(swiper.params.scrollbar.lockClass));
  6082. }
  6083. });
  6084. on('destroy', () => {
  6085. destroy();
  6086. });
  6087. const enable = () => {
  6088. swiper.el.classList.remove(...classesToTokens(swiper.params.scrollbar.scrollbarDisabledClass));
  6089. if (swiper.scrollbar.el) {
  6090. swiper.scrollbar.el.classList.remove(...classesToTokens(swiper.params.scrollbar.scrollbarDisabledClass));
  6091. }
  6092. init();
  6093. updateSize();
  6094. setTranslate();
  6095. };
  6096. const disable = () => {
  6097. swiper.el.classList.add(...classesToTokens(swiper.params.scrollbar.scrollbarDisabledClass));
  6098. if (swiper.scrollbar.el) {
  6099. swiper.scrollbar.el.classList.add(...classesToTokens(swiper.params.scrollbar.scrollbarDisabledClass));
  6100. }
  6101. destroy();
  6102. };
  6103. Object.assign(swiper.scrollbar, {
  6104. enable,
  6105. disable,
  6106. updateSize,
  6107. setTranslate,
  6108. init,
  6109. destroy
  6110. });
  6111. }
  6112. function Parallax(_ref) {
  6113. let {
  6114. swiper,
  6115. extendParams,
  6116. on
  6117. } = _ref;
  6118. extendParams({
  6119. parallax: {
  6120. enabled: false
  6121. }
  6122. });
  6123. const elementsSelector = '[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y], [data-swiper-parallax-opacity], [data-swiper-parallax-scale]';
  6124. const setTransform = (el, progress) => {
  6125. const {
  6126. rtl
  6127. } = swiper;
  6128. const rtlFactor = rtl ? -1 : 1;
  6129. const p = el.getAttribute('data-swiper-parallax') || '0';
  6130. let x = el.getAttribute('data-swiper-parallax-x');
  6131. let y = el.getAttribute('data-swiper-parallax-y');
  6132. const scale = el.getAttribute('data-swiper-parallax-scale');
  6133. const opacity = el.getAttribute('data-swiper-parallax-opacity');
  6134. const rotate = el.getAttribute('data-swiper-parallax-rotate');
  6135. if (x || y) {
  6136. x = x || '0';
  6137. y = y || '0';
  6138. } else if (swiper.isHorizontal()) {
  6139. x = p;
  6140. y = '0';
  6141. } else {
  6142. y = p;
  6143. x = '0';
  6144. }
  6145. if (x.indexOf('%') >= 0) {
  6146. x = `${parseInt(x, 10) * progress * rtlFactor}%`;
  6147. } else {
  6148. x = `${x * progress * rtlFactor}px`;
  6149. }
  6150. if (y.indexOf('%') >= 0) {
  6151. y = `${parseInt(y, 10) * progress}%`;
  6152. } else {
  6153. y = `${y * progress}px`;
  6154. }
  6155. if (typeof opacity !== 'undefined' && opacity !== null) {
  6156. const currentOpacity = opacity - (opacity - 1) * (1 - Math.abs(progress));
  6157. el.style.opacity = currentOpacity;
  6158. }
  6159. let transform = `translate3d(${x}, ${y}, 0px)`;
  6160. if (typeof scale !== 'undefined' && scale !== null) {
  6161. const currentScale = scale - (scale - 1) * (1 - Math.abs(progress));
  6162. transform += ` scale(${currentScale})`;
  6163. }
  6164. if (rotate && typeof rotate !== 'undefined' && rotate !== null) {
  6165. const currentRotate = rotate * progress * -1;
  6166. transform += ` rotate(${currentRotate}deg)`;
  6167. }
  6168. el.style.transform = transform;
  6169. };
  6170. const setTranslate = () => {
  6171. const {
  6172. el,
  6173. slides,
  6174. progress,
  6175. snapGrid,
  6176. isElement
  6177. } = swiper;
  6178. const elements = elementChildren(el, elementsSelector);
  6179. if (swiper.isElement) {
  6180. elements.push(...elementChildren(swiper.hostEl, elementsSelector));
  6181. }
  6182. elements.forEach(subEl => {
  6183. setTransform(subEl, progress);
  6184. });
  6185. slides.forEach((slideEl, slideIndex) => {
  6186. let slideProgress = slideEl.progress;
  6187. if (swiper.params.slidesPerGroup > 1 && swiper.params.slidesPerView !== 'auto') {
  6188. slideProgress += Math.ceil(slideIndex / 2) - progress * (snapGrid.length - 1);
  6189. }
  6190. slideProgress = Math.min(Math.max(slideProgress, -1), 1);
  6191. slideEl.querySelectorAll(`${elementsSelector}, [data-swiper-parallax-rotate]`).forEach(subEl => {
  6192. setTransform(subEl, slideProgress);
  6193. });
  6194. });
  6195. };
  6196. const setTransition = function (duration) {
  6197. if (duration === void 0) {
  6198. duration = swiper.params.speed;
  6199. }
  6200. const {
  6201. el,
  6202. hostEl
  6203. } = swiper;
  6204. const elements = [...el.querySelectorAll(elementsSelector)];
  6205. if (swiper.isElement) {
  6206. elements.push(...hostEl.querySelectorAll(elementsSelector));
  6207. }
  6208. elements.forEach(parallaxEl => {
  6209. let parallaxDuration = parseInt(parallaxEl.getAttribute('data-swiper-parallax-duration'), 10) || duration;
  6210. if (duration === 0) parallaxDuration = 0;
  6211. parallaxEl.style.transitionDuration = `${parallaxDuration}ms`;
  6212. });
  6213. };
  6214. on('beforeInit', () => {
  6215. if (!swiper.params.parallax.enabled) return;
  6216. swiper.params.watchSlidesProgress = true;
  6217. swiper.originalParams.watchSlidesProgress = true;
  6218. });
  6219. on('init', () => {
  6220. if (!swiper.params.parallax.enabled) return;
  6221. setTranslate();
  6222. });
  6223. on('setTranslate', () => {
  6224. if (!swiper.params.parallax.enabled) return;
  6225. setTranslate();
  6226. });
  6227. on('setTransition', (_swiper, duration) => {
  6228. if (!swiper.params.parallax.enabled) return;
  6229. setTransition(duration);
  6230. });
  6231. }
  6232. function Zoom(_ref) {
  6233. let {
  6234. swiper,
  6235. extendParams,
  6236. on,
  6237. emit
  6238. } = _ref;
  6239. const window = getWindow();
  6240. extendParams({
  6241. zoom: {
  6242. enabled: false,
  6243. limitToOriginalSize: false,
  6244. maxRatio: 3,
  6245. minRatio: 1,
  6246. toggle: true,
  6247. containerClass: 'swiper-zoom-container',
  6248. zoomedSlideClass: 'swiper-slide-zoomed'
  6249. }
  6250. });
  6251. swiper.zoom = {
  6252. enabled: false
  6253. };
  6254. let currentScale = 1;
  6255. let isScaling = false;
  6256. let fakeGestureTouched;
  6257. let fakeGestureMoved;
  6258. const evCache = [];
  6259. const gesture = {
  6260. originX: 0,
  6261. originY: 0,
  6262. slideEl: undefined,
  6263. slideWidth: undefined,
  6264. slideHeight: undefined,
  6265. imageEl: undefined,
  6266. imageWrapEl: undefined,
  6267. maxRatio: 3
  6268. };
  6269. const image = {
  6270. isTouched: undefined,
  6271. isMoved: undefined,
  6272. currentX: undefined,
  6273. currentY: undefined,
  6274. minX: undefined,
  6275. minY: undefined,
  6276. maxX: undefined,
  6277. maxY: undefined,
  6278. width: undefined,
  6279. height: undefined,
  6280. startX: undefined,
  6281. startY: undefined,
  6282. touchesStart: {},
  6283. touchesCurrent: {}
  6284. };
  6285. const velocity = {
  6286. x: undefined,
  6287. y: undefined,
  6288. prevPositionX: undefined,
  6289. prevPositionY: undefined,
  6290. prevTime: undefined
  6291. };
  6292. let scale = 1;
  6293. Object.defineProperty(swiper.zoom, 'scale', {
  6294. get() {
  6295. return scale;
  6296. },
  6297. set(value) {
  6298. if (scale !== value) {
  6299. const imageEl = gesture.imageEl;
  6300. const slideEl = gesture.slideEl;
  6301. emit('zoomChange', value, imageEl, slideEl);
  6302. }
  6303. scale = value;
  6304. }
  6305. });
  6306. function getDistanceBetweenTouches() {
  6307. if (evCache.length < 2) return 1;
  6308. const x1 = evCache[0].pageX;
  6309. const y1 = evCache[0].pageY;
  6310. const x2 = evCache[1].pageX;
  6311. const y2 = evCache[1].pageY;
  6312. const distance = Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2);
  6313. return distance;
  6314. }
  6315. function getMaxRatio() {
  6316. const params = swiper.params.zoom;
  6317. const maxRatio = gesture.imageWrapEl.getAttribute('data-swiper-zoom') || params.maxRatio;
  6318. if (params.limitToOriginalSize && gesture.imageEl && gesture.imageEl.naturalWidth) {
  6319. const imageMaxRatio = gesture.imageEl.naturalWidth / gesture.imageEl.offsetWidth;
  6320. return Math.min(imageMaxRatio, maxRatio);
  6321. }
  6322. return maxRatio;
  6323. }
  6324. function getScaleOrigin() {
  6325. if (evCache.length < 2) return {
  6326. x: null,
  6327. y: null
  6328. };
  6329. const box = gesture.imageEl.getBoundingClientRect();
  6330. return [(evCache[0].pageX + (evCache[1].pageX - evCache[0].pageX) / 2 - box.x - window.scrollX) / currentScale, (evCache[0].pageY + (evCache[1].pageY - evCache[0].pageY) / 2 - box.y - window.scrollY) / currentScale];
  6331. }
  6332. function getSlideSelector() {
  6333. return swiper.isElement ? `swiper-slide` : `.${swiper.params.slideClass}`;
  6334. }
  6335. function eventWithinSlide(e) {
  6336. const slideSelector = getSlideSelector();
  6337. if (e.target.matches(slideSelector)) return true;
  6338. if (swiper.slides.filter(slideEl => slideEl.contains(e.target)).length > 0) return true;
  6339. return false;
  6340. }
  6341. function eventWithinZoomContainer(e) {
  6342. const selector = `.${swiper.params.zoom.containerClass}`;
  6343. if (e.target.matches(selector)) return true;
  6344. if ([...swiper.hostEl.querySelectorAll(selector)].filter(containerEl => containerEl.contains(e.target)).length > 0) return true;
  6345. return false;
  6346. }
  6347. // Events
  6348. function onGestureStart(e) {
  6349. if (e.pointerType === 'mouse') {
  6350. evCache.splice(0, evCache.length);
  6351. }
  6352. if (!eventWithinSlide(e)) return;
  6353. const params = swiper.params.zoom;
  6354. fakeGestureTouched = false;
  6355. fakeGestureMoved = false;
  6356. evCache.push(e);
  6357. if (evCache.length < 2) {
  6358. return;
  6359. }
  6360. fakeGestureTouched = true;
  6361. gesture.scaleStart = getDistanceBetweenTouches();
  6362. if (!gesture.slideEl) {
  6363. gesture.slideEl = e.target.closest(`.${swiper.params.slideClass}, swiper-slide`);
  6364. if (!gesture.slideEl) gesture.slideEl = swiper.slides[swiper.activeIndex];
  6365. let imageEl = gesture.slideEl.querySelector(`.${params.containerClass}`);
  6366. if (imageEl) {
  6367. imageEl = imageEl.querySelectorAll('picture, img, svg, canvas, .swiper-zoom-target')[0];
  6368. }
  6369. gesture.imageEl = imageEl;
  6370. if (imageEl) {
  6371. gesture.imageWrapEl = elementParents(gesture.imageEl, `.${params.containerClass}`)[0];
  6372. } else {
  6373. gesture.imageWrapEl = undefined;
  6374. }
  6375. if (!gesture.imageWrapEl) {
  6376. gesture.imageEl = undefined;
  6377. return;
  6378. }
  6379. gesture.maxRatio = getMaxRatio();
  6380. }
  6381. if (gesture.imageEl) {
  6382. const [originX, originY] = getScaleOrigin();
  6383. gesture.originX = originX;
  6384. gesture.originY = originY;
  6385. gesture.imageEl.style.transitionDuration = '0ms';
  6386. }
  6387. isScaling = true;
  6388. }
  6389. function onGestureChange(e) {
  6390. if (!eventWithinSlide(e)) return;
  6391. const params = swiper.params.zoom;
  6392. const zoom = swiper.zoom;
  6393. const pointerIndex = evCache.findIndex(cachedEv => cachedEv.pointerId === e.pointerId);
  6394. if (pointerIndex >= 0) evCache[pointerIndex] = e;
  6395. if (evCache.length < 2) {
  6396. return;
  6397. }
  6398. fakeGestureMoved = true;
  6399. gesture.scaleMove = getDistanceBetweenTouches();
  6400. if (!gesture.imageEl) {
  6401. return;
  6402. }
  6403. zoom.scale = gesture.scaleMove / gesture.scaleStart * currentScale;
  6404. if (zoom.scale > gesture.maxRatio) {
  6405. zoom.scale = gesture.maxRatio - 1 + (zoom.scale - gesture.maxRatio + 1) ** 0.5;
  6406. }
  6407. if (zoom.scale < params.minRatio) {
  6408. zoom.scale = params.minRatio + 1 - (params.minRatio - zoom.scale + 1) ** 0.5;
  6409. }
  6410. gesture.imageEl.style.transform = `translate3d(0,0,0) scale(${zoom.scale})`;
  6411. }
  6412. function onGestureEnd(e) {
  6413. if (!eventWithinSlide(e)) return;
  6414. if (e.pointerType === 'mouse' && e.type === 'pointerout') return;
  6415. const params = swiper.params.zoom;
  6416. const zoom = swiper.zoom;
  6417. const pointerIndex = evCache.findIndex(cachedEv => cachedEv.pointerId === e.pointerId);
  6418. if (pointerIndex >= 0) evCache.splice(pointerIndex, 1);
  6419. if (!fakeGestureTouched || !fakeGestureMoved) {
  6420. return;
  6421. }
  6422. fakeGestureTouched = false;
  6423. fakeGestureMoved = false;
  6424. if (!gesture.imageEl) return;
  6425. zoom.scale = Math.max(Math.min(zoom.scale, gesture.maxRatio), params.minRatio);
  6426. gesture.imageEl.style.transitionDuration = `${swiper.params.speed}ms`;
  6427. gesture.imageEl.style.transform = `translate3d(0,0,0) scale(${zoom.scale})`;
  6428. currentScale = zoom.scale;
  6429. isScaling = false;
  6430. if (zoom.scale > 1 && gesture.slideEl) {
  6431. gesture.slideEl.classList.add(`${params.zoomedSlideClass}`);
  6432. } else if (zoom.scale <= 1 && gesture.slideEl) {
  6433. gesture.slideEl.classList.remove(`${params.zoomedSlideClass}`);
  6434. }
  6435. if (zoom.scale === 1) {
  6436. gesture.originX = 0;
  6437. gesture.originY = 0;
  6438. gesture.slideEl = undefined;
  6439. }
  6440. }
  6441. let allowTouchMoveTimeout;
  6442. function allowTouchMove() {
  6443. swiper.touchEventsData.preventTouchMoveFromPointerMove = false;
  6444. }
  6445. function preventTouchMove() {
  6446. clearTimeout(allowTouchMoveTimeout);
  6447. swiper.touchEventsData.preventTouchMoveFromPointerMove = true;
  6448. allowTouchMoveTimeout = setTimeout(() => {
  6449. if (swiper.destroyed) return;
  6450. allowTouchMove();
  6451. });
  6452. }
  6453. function onTouchStart(e) {
  6454. const device = swiper.device;
  6455. if (!gesture.imageEl) return;
  6456. if (image.isTouched) return;
  6457. if (device.android && e.cancelable) e.preventDefault();
  6458. image.isTouched = true;
  6459. const event = evCache.length > 0 ? evCache[0] : e;
  6460. image.touchesStart.x = event.pageX;
  6461. image.touchesStart.y = event.pageY;
  6462. }
  6463. function onTouchMove(e) {
  6464. if (!eventWithinSlide(e) || !eventWithinZoomContainer(e)) {
  6465. return;
  6466. }
  6467. const zoom = swiper.zoom;
  6468. if (!gesture.imageEl) {
  6469. return;
  6470. }
  6471. if (!image.isTouched || !gesture.slideEl) {
  6472. return;
  6473. }
  6474. if (!image.isMoved) {
  6475. image.width = gesture.imageEl.offsetWidth || gesture.imageEl.clientWidth;
  6476. image.height = gesture.imageEl.offsetHeight || gesture.imageEl.clientHeight;
  6477. image.startX = getTranslate(gesture.imageWrapEl, 'x') || 0;
  6478. image.startY = getTranslate(gesture.imageWrapEl, 'y') || 0;
  6479. gesture.slideWidth = gesture.slideEl.offsetWidth;
  6480. gesture.slideHeight = gesture.slideEl.offsetHeight;
  6481. gesture.imageWrapEl.style.transitionDuration = '0ms';
  6482. }
  6483. // Define if we need image drag
  6484. const scaledWidth = image.width * zoom.scale;
  6485. const scaledHeight = image.height * zoom.scale;
  6486. image.minX = Math.min(gesture.slideWidth / 2 - scaledWidth / 2, 0);
  6487. image.maxX = -image.minX;
  6488. image.minY = Math.min(gesture.slideHeight / 2 - scaledHeight / 2, 0);
  6489. image.maxY = -image.minY;
  6490. image.touchesCurrent.x = evCache.length > 0 ? evCache[0].pageX : e.pageX;
  6491. image.touchesCurrent.y = evCache.length > 0 ? evCache[0].pageY : e.pageY;
  6492. const touchesDiff = Math.max(Math.abs(image.touchesCurrent.x - image.touchesStart.x), Math.abs(image.touchesCurrent.y - image.touchesStart.y));
  6493. if (touchesDiff > 5) {
  6494. swiper.allowClick = false;
  6495. }
  6496. if (!image.isMoved && !isScaling) {
  6497. if (swiper.isHorizontal() && (Math.floor(image.minX) === Math.floor(image.startX) && image.touchesCurrent.x < image.touchesStart.x || Math.floor(image.maxX) === Math.floor(image.startX) && image.touchesCurrent.x > image.touchesStart.x)) {
  6498. image.isTouched = false;
  6499. allowTouchMove();
  6500. return;
  6501. }
  6502. if (!swiper.isHorizontal() && (Math.floor(image.minY) === Math.floor(image.startY) && image.touchesCurrent.y < image.touchesStart.y || Math.floor(image.maxY) === Math.floor(image.startY) && image.touchesCurrent.y > image.touchesStart.y)) {
  6503. image.isTouched = false;
  6504. allowTouchMove();
  6505. return;
  6506. }
  6507. }
  6508. if (e.cancelable) {
  6509. e.preventDefault();
  6510. }
  6511. e.stopPropagation();
  6512. preventTouchMove();
  6513. image.isMoved = true;
  6514. const scaleRatio = (zoom.scale - currentScale) / (gesture.maxRatio - swiper.params.zoom.minRatio);
  6515. const {
  6516. originX,
  6517. originY
  6518. } = gesture;
  6519. image.currentX = image.touchesCurrent.x - image.touchesStart.x + image.startX + scaleRatio * (image.width - originX * 2);
  6520. image.currentY = image.touchesCurrent.y - image.touchesStart.y + image.startY + scaleRatio * (image.height - originY * 2);
  6521. if (image.currentX < image.minX) {
  6522. image.currentX = image.minX + 1 - (image.minX - image.currentX + 1) ** 0.8;
  6523. }
  6524. if (image.currentX > image.maxX) {
  6525. image.currentX = image.maxX - 1 + (image.currentX - image.maxX + 1) ** 0.8;
  6526. }
  6527. if (image.currentY < image.minY) {
  6528. image.currentY = image.minY + 1 - (image.minY - image.currentY + 1) ** 0.8;
  6529. }
  6530. if (image.currentY > image.maxY) {
  6531. image.currentY = image.maxY - 1 + (image.currentY - image.maxY + 1) ** 0.8;
  6532. }
  6533. // Velocity
  6534. if (!velocity.prevPositionX) velocity.prevPositionX = image.touchesCurrent.x;
  6535. if (!velocity.prevPositionY) velocity.prevPositionY = image.touchesCurrent.y;
  6536. if (!velocity.prevTime) velocity.prevTime = Date.now();
  6537. velocity.x = (image.touchesCurrent.x - velocity.prevPositionX) / (Date.now() - velocity.prevTime) / 2;
  6538. velocity.y = (image.touchesCurrent.y - velocity.prevPositionY) / (Date.now() - velocity.prevTime) / 2;
  6539. if (Math.abs(image.touchesCurrent.x - velocity.prevPositionX) < 2) velocity.x = 0;
  6540. if (Math.abs(image.touchesCurrent.y - velocity.prevPositionY) < 2) velocity.y = 0;
  6541. velocity.prevPositionX = image.touchesCurrent.x;
  6542. velocity.prevPositionY = image.touchesCurrent.y;
  6543. velocity.prevTime = Date.now();
  6544. gesture.imageWrapEl.style.transform = `translate3d(${image.currentX}px, ${image.currentY}px,0)`;
  6545. }
  6546. function onTouchEnd() {
  6547. const zoom = swiper.zoom;
  6548. if (!gesture.imageEl) return;
  6549. if (!image.isTouched || !image.isMoved) {
  6550. image.isTouched = false;
  6551. image.isMoved = false;
  6552. return;
  6553. }
  6554. image.isTouched = false;
  6555. image.isMoved = false;
  6556. let momentumDurationX = 300;
  6557. let momentumDurationY = 300;
  6558. const momentumDistanceX = velocity.x * momentumDurationX;
  6559. const newPositionX = image.currentX + momentumDistanceX;
  6560. const momentumDistanceY = velocity.y * momentumDurationY;
  6561. const newPositionY = image.currentY + momentumDistanceY;
  6562. // Fix duration
  6563. if (velocity.x !== 0) momentumDurationX = Math.abs((newPositionX - image.currentX) / velocity.x);
  6564. if (velocity.y !== 0) momentumDurationY = Math.abs((newPositionY - image.currentY) / velocity.y);
  6565. const momentumDuration = Math.max(momentumDurationX, momentumDurationY);
  6566. image.currentX = newPositionX;
  6567. image.currentY = newPositionY;
  6568. // Define if we need image drag
  6569. const scaledWidth = image.width * zoom.scale;
  6570. const scaledHeight = image.height * zoom.scale;
  6571. image.minX = Math.min(gesture.slideWidth / 2 - scaledWidth / 2, 0);
  6572. image.maxX = -image.minX;
  6573. image.minY = Math.min(gesture.slideHeight / 2 - scaledHeight / 2, 0);
  6574. image.maxY = -image.minY;
  6575. image.currentX = Math.max(Math.min(image.currentX, image.maxX), image.minX);
  6576. image.currentY = Math.max(Math.min(image.currentY, image.maxY), image.minY);
  6577. gesture.imageWrapEl.style.transitionDuration = `${momentumDuration}ms`;
  6578. gesture.imageWrapEl.style.transform = `translate3d(${image.currentX}px, ${image.currentY}px,0)`;
  6579. }
  6580. function onTransitionEnd() {
  6581. const zoom = swiper.zoom;
  6582. if (gesture.slideEl && swiper.activeIndex !== swiper.slides.indexOf(gesture.slideEl)) {
  6583. if (gesture.imageEl) {
  6584. gesture.imageEl.style.transform = 'translate3d(0,0,0) scale(1)';
  6585. }
  6586. if (gesture.imageWrapEl) {
  6587. gesture.imageWrapEl.style.transform = 'translate3d(0,0,0)';
  6588. }
  6589. gesture.slideEl.classList.remove(`${swiper.params.zoom.zoomedSlideClass}`);
  6590. zoom.scale = 1;
  6591. currentScale = 1;
  6592. gesture.slideEl = undefined;
  6593. gesture.imageEl = undefined;
  6594. gesture.imageWrapEl = undefined;
  6595. gesture.originX = 0;
  6596. gesture.originY = 0;
  6597. }
  6598. }
  6599. function zoomIn(e) {
  6600. const zoom = swiper.zoom;
  6601. const params = swiper.params.zoom;
  6602. if (!gesture.slideEl) {
  6603. if (e && e.target) {
  6604. gesture.slideEl = e.target.closest(`.${swiper.params.slideClass}, swiper-slide`);
  6605. }
  6606. if (!gesture.slideEl) {
  6607. if (swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual) {
  6608. gesture.slideEl = elementChildren(swiper.slidesEl, `.${swiper.params.slideActiveClass}`)[0];
  6609. } else {
  6610. gesture.slideEl = swiper.slides[swiper.activeIndex];
  6611. }
  6612. }
  6613. let imageEl = gesture.slideEl.querySelector(`.${params.containerClass}`);
  6614. if (imageEl) {
  6615. imageEl = imageEl.querySelectorAll('picture, img, svg, canvas, .swiper-zoom-target')[0];
  6616. }
  6617. gesture.imageEl = imageEl;
  6618. if (imageEl) {
  6619. gesture.imageWrapEl = elementParents(gesture.imageEl, `.${params.containerClass}`)[0];
  6620. } else {
  6621. gesture.imageWrapEl = undefined;
  6622. }
  6623. }
  6624. if (!gesture.imageEl || !gesture.imageWrapEl) return;
  6625. if (swiper.params.cssMode) {
  6626. swiper.wrapperEl.style.overflow = 'hidden';
  6627. swiper.wrapperEl.style.touchAction = 'none';
  6628. }
  6629. gesture.slideEl.classList.add(`${params.zoomedSlideClass}`);
  6630. let touchX;
  6631. let touchY;
  6632. let offsetX;
  6633. let offsetY;
  6634. let diffX;
  6635. let diffY;
  6636. let translateX;
  6637. let translateY;
  6638. let imageWidth;
  6639. let imageHeight;
  6640. let scaledWidth;
  6641. let scaledHeight;
  6642. let translateMinX;
  6643. let translateMinY;
  6644. let translateMaxX;
  6645. let translateMaxY;
  6646. let slideWidth;
  6647. let slideHeight;
  6648. if (typeof image.touchesStart.x === 'undefined' && e) {
  6649. touchX = e.pageX;
  6650. touchY = e.pageY;
  6651. } else {
  6652. touchX = image.touchesStart.x;
  6653. touchY = image.touchesStart.y;
  6654. }
  6655. const forceZoomRatio = typeof e === 'number' ? e : null;
  6656. if (currentScale === 1 && forceZoomRatio) {
  6657. touchX = undefined;
  6658. touchY = undefined;
  6659. image.touchesStart.x = undefined;
  6660. image.touchesStart.y = undefined;
  6661. }
  6662. const maxRatio = getMaxRatio();
  6663. zoom.scale = forceZoomRatio || maxRatio;
  6664. currentScale = forceZoomRatio || maxRatio;
  6665. if (e && !(currentScale === 1 && forceZoomRatio)) {
  6666. slideWidth = gesture.slideEl.offsetWidth;
  6667. slideHeight = gesture.slideEl.offsetHeight;
  6668. offsetX = elementOffset(gesture.slideEl).left + window.scrollX;
  6669. offsetY = elementOffset(gesture.slideEl).top + window.scrollY;
  6670. diffX = offsetX + slideWidth / 2 - touchX;
  6671. diffY = offsetY + slideHeight / 2 - touchY;
  6672. imageWidth = gesture.imageEl.offsetWidth || gesture.imageEl.clientWidth;
  6673. imageHeight = gesture.imageEl.offsetHeight || gesture.imageEl.clientHeight;
  6674. scaledWidth = imageWidth * zoom.scale;
  6675. scaledHeight = imageHeight * zoom.scale;
  6676. translateMinX = Math.min(slideWidth / 2 - scaledWidth / 2, 0);
  6677. translateMinY = Math.min(slideHeight / 2 - scaledHeight / 2, 0);
  6678. translateMaxX = -translateMinX;
  6679. translateMaxY = -translateMinY;
  6680. translateX = diffX * zoom.scale;
  6681. translateY = diffY * zoom.scale;
  6682. if (translateX < translateMinX) {
  6683. translateX = translateMinX;
  6684. }
  6685. if (translateX > translateMaxX) {
  6686. translateX = translateMaxX;
  6687. }
  6688. if (translateY < translateMinY) {
  6689. translateY = translateMinY;
  6690. }
  6691. if (translateY > translateMaxY) {
  6692. translateY = translateMaxY;
  6693. }
  6694. } else {
  6695. translateX = 0;
  6696. translateY = 0;
  6697. }
  6698. if (forceZoomRatio && zoom.scale === 1) {
  6699. gesture.originX = 0;
  6700. gesture.originY = 0;
  6701. }
  6702. gesture.imageWrapEl.style.transitionDuration = '300ms';
  6703. gesture.imageWrapEl.style.transform = `translate3d(${translateX}px, ${translateY}px,0)`;
  6704. gesture.imageEl.style.transitionDuration = '300ms';
  6705. gesture.imageEl.style.transform = `translate3d(0,0,0) scale(${zoom.scale})`;
  6706. }
  6707. function zoomOut() {
  6708. const zoom = swiper.zoom;
  6709. const params = swiper.params.zoom;
  6710. if (!gesture.slideEl) {
  6711. if (swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual) {
  6712. gesture.slideEl = elementChildren(swiper.slidesEl, `.${swiper.params.slideActiveClass}`)[0];
  6713. } else {
  6714. gesture.slideEl = swiper.slides[swiper.activeIndex];
  6715. }
  6716. let imageEl = gesture.slideEl.querySelector(`.${params.containerClass}`);
  6717. if (imageEl) {
  6718. imageEl = imageEl.querySelectorAll('picture, img, svg, canvas, .swiper-zoom-target')[0];
  6719. }
  6720. gesture.imageEl = imageEl;
  6721. if (imageEl) {
  6722. gesture.imageWrapEl = elementParents(gesture.imageEl, `.${params.containerClass}`)[0];
  6723. } else {
  6724. gesture.imageWrapEl = undefined;
  6725. }
  6726. }
  6727. if (!gesture.imageEl || !gesture.imageWrapEl) return;
  6728. if (swiper.params.cssMode) {
  6729. swiper.wrapperEl.style.overflow = '';
  6730. swiper.wrapperEl.style.touchAction = '';
  6731. }
  6732. zoom.scale = 1;
  6733. currentScale = 1;
  6734. image.touchesStart.x = undefined;
  6735. image.touchesStart.y = undefined;
  6736. gesture.imageWrapEl.style.transitionDuration = '300ms';
  6737. gesture.imageWrapEl.style.transform = 'translate3d(0,0,0)';
  6738. gesture.imageEl.style.transitionDuration = '300ms';
  6739. gesture.imageEl.style.transform = 'translate3d(0,0,0) scale(1)';
  6740. gesture.slideEl.classList.remove(`${params.zoomedSlideClass}`);
  6741. gesture.slideEl = undefined;
  6742. gesture.originX = 0;
  6743. gesture.originY = 0;
  6744. }
  6745. // Toggle Zoom
  6746. function zoomToggle(e) {
  6747. const zoom = swiper.zoom;
  6748. if (zoom.scale && zoom.scale !== 1) {
  6749. // Zoom Out
  6750. zoomOut();
  6751. } else {
  6752. // Zoom In
  6753. zoomIn(e);
  6754. }
  6755. }
  6756. function getListeners() {
  6757. const passiveListener = swiper.params.passiveListeners ? {
  6758. passive: true,
  6759. capture: false
  6760. } : false;
  6761. const activeListenerWithCapture = swiper.params.passiveListeners ? {
  6762. passive: false,
  6763. capture: true
  6764. } : true;
  6765. return {
  6766. passiveListener,
  6767. activeListenerWithCapture
  6768. };
  6769. }
  6770. // Attach/Detach Events
  6771. function enable() {
  6772. const zoom = swiper.zoom;
  6773. if (zoom.enabled) return;
  6774. zoom.enabled = true;
  6775. const {
  6776. passiveListener,
  6777. activeListenerWithCapture
  6778. } = getListeners();
  6779. // Scale image
  6780. swiper.wrapperEl.addEventListener('pointerdown', onGestureStart, passiveListener);
  6781. swiper.wrapperEl.addEventListener('pointermove', onGestureChange, activeListenerWithCapture);
  6782. ['pointerup', 'pointercancel', 'pointerout'].forEach(eventName => {
  6783. swiper.wrapperEl.addEventListener(eventName, onGestureEnd, passiveListener);
  6784. });
  6785. // Move image
  6786. swiper.wrapperEl.addEventListener('pointermove', onTouchMove, activeListenerWithCapture);
  6787. }
  6788. function disable() {
  6789. const zoom = swiper.zoom;
  6790. if (!zoom.enabled) return;
  6791. zoom.enabled = false;
  6792. const {
  6793. passiveListener,
  6794. activeListenerWithCapture
  6795. } = getListeners();
  6796. // Scale image
  6797. swiper.wrapperEl.removeEventListener('pointerdown', onGestureStart, passiveListener);
  6798. swiper.wrapperEl.removeEventListener('pointermove', onGestureChange, activeListenerWithCapture);
  6799. ['pointerup', 'pointercancel', 'pointerout'].forEach(eventName => {
  6800. swiper.wrapperEl.removeEventListener(eventName, onGestureEnd, passiveListener);
  6801. });
  6802. // Move image
  6803. swiper.wrapperEl.removeEventListener('pointermove', onTouchMove, activeListenerWithCapture);
  6804. }
  6805. on('init', () => {
  6806. if (swiper.params.zoom.enabled) {
  6807. enable();
  6808. }
  6809. });
  6810. on('destroy', () => {
  6811. disable();
  6812. });
  6813. on('touchStart', (_s, e) => {
  6814. if (!swiper.zoom.enabled) return;
  6815. onTouchStart(e);
  6816. });
  6817. on('touchEnd', (_s, e) => {
  6818. if (!swiper.zoom.enabled) return;
  6819. onTouchEnd();
  6820. });
  6821. on('doubleTap', (_s, e) => {
  6822. if (!swiper.animating && swiper.params.zoom.enabled && swiper.zoom.enabled && swiper.params.zoom.toggle) {
  6823. zoomToggle(e);
  6824. }
  6825. });
  6826. on('transitionEnd', () => {
  6827. if (swiper.zoom.enabled && swiper.params.zoom.enabled) {
  6828. onTransitionEnd();
  6829. }
  6830. });
  6831. on('slideChange', () => {
  6832. if (swiper.zoom.enabled && swiper.params.zoom.enabled && swiper.params.cssMode) {
  6833. onTransitionEnd();
  6834. }
  6835. });
  6836. Object.assign(swiper.zoom, {
  6837. enable,
  6838. disable,
  6839. in: zoomIn,
  6840. out: zoomOut,
  6841. toggle: zoomToggle
  6842. });
  6843. }
  6844. /* eslint no-bitwise: ["error", { "allow": [">>"] }] */
  6845. function Controller(_ref) {
  6846. let {
  6847. swiper,
  6848. extendParams,
  6849. on
  6850. } = _ref;
  6851. extendParams({
  6852. controller: {
  6853. control: undefined,
  6854. inverse: false,
  6855. by: 'slide' // or 'container'
  6856. }
  6857. });
  6858. swiper.controller = {
  6859. control: undefined
  6860. };
  6861. function LinearSpline(x, y) {
  6862. const binarySearch = function search() {
  6863. let maxIndex;
  6864. let minIndex;
  6865. let guess;
  6866. return (array, val) => {
  6867. minIndex = -1;
  6868. maxIndex = array.length;
  6869. while (maxIndex - minIndex > 1) {
  6870. guess = maxIndex + minIndex >> 1;
  6871. if (array[guess] <= val) {
  6872. minIndex = guess;
  6873. } else {
  6874. maxIndex = guess;
  6875. }
  6876. }
  6877. return maxIndex;
  6878. };
  6879. }();
  6880. this.x = x;
  6881. this.y = y;
  6882. this.lastIndex = x.length - 1;
  6883. // Given an x value (x2), return the expected y2 value:
  6884. // (x1,y1) is the known point before given value,
  6885. // (x3,y3) is the known point after given value.
  6886. let i1;
  6887. let i3;
  6888. this.interpolate = function interpolate(x2) {
  6889. if (!x2) return 0;
  6890. // Get the indexes of x1 and x3 (the array indexes before and after given x2):
  6891. i3 = binarySearch(this.x, x2);
  6892. i1 = i3 - 1;
  6893. // We have our indexes i1 & i3, so we can calculate already:
  6894. // y2 := ((x2−x1) × (y3−y1)) ÷ (x3−x1) + y1
  6895. return (x2 - this.x[i1]) * (this.y[i3] - this.y[i1]) / (this.x[i3] - this.x[i1]) + this.y[i1];
  6896. };
  6897. return this;
  6898. }
  6899. function getInterpolateFunction(c) {
  6900. swiper.controller.spline = swiper.params.loop ? new LinearSpline(swiper.slidesGrid, c.slidesGrid) : new LinearSpline(swiper.snapGrid, c.snapGrid);
  6901. }
  6902. function setTranslate(_t, byController) {
  6903. const controlled = swiper.controller.control;
  6904. let multiplier;
  6905. let controlledTranslate;
  6906. const Swiper = swiper.constructor;
  6907. function setControlledTranslate(c) {
  6908. if (c.destroyed) return;
  6909. // this will create an Interpolate function based on the snapGrids
  6910. // x is the Grid of the scrolled scroller and y will be the controlled scroller
  6911. // it makes sense to create this only once and recall it for the interpolation
  6912. // the function does a lot of value caching for performance
  6913. const translate = swiper.rtlTranslate ? -swiper.translate : swiper.translate;
  6914. if (swiper.params.controller.by === 'slide') {
  6915. getInterpolateFunction(c);
  6916. // i am not sure why the values have to be multiplicated this way, tried to invert the snapGrid
  6917. // but it did not work out
  6918. controlledTranslate = -swiper.controller.spline.interpolate(-translate);
  6919. }
  6920. if (!controlledTranslate || swiper.params.controller.by === 'container') {
  6921. multiplier = (c.maxTranslate() - c.minTranslate()) / (swiper.maxTranslate() - swiper.minTranslate());
  6922. if (Number.isNaN(multiplier) || !Number.isFinite(multiplier)) {
  6923. multiplier = 1;
  6924. }
  6925. controlledTranslate = (translate - swiper.minTranslate()) * multiplier + c.minTranslate();
  6926. }
  6927. if (swiper.params.controller.inverse) {
  6928. controlledTranslate = c.maxTranslate() - controlledTranslate;
  6929. }
  6930. c.updateProgress(controlledTranslate);
  6931. c.setTranslate(controlledTranslate, swiper);
  6932. c.updateActiveIndex();
  6933. c.updateSlidesClasses();
  6934. }
  6935. if (Array.isArray(controlled)) {
  6936. for (let i = 0; i < controlled.length; i += 1) {
  6937. if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
  6938. setControlledTranslate(controlled[i]);
  6939. }
  6940. }
  6941. } else if (controlled instanceof Swiper && byController !== controlled) {
  6942. setControlledTranslate(controlled);
  6943. }
  6944. }
  6945. function setTransition(duration, byController) {
  6946. const Swiper = swiper.constructor;
  6947. const controlled = swiper.controller.control;
  6948. let i;
  6949. function setControlledTransition(c) {
  6950. if (c.destroyed) return;
  6951. c.setTransition(duration, swiper);
  6952. if (duration !== 0) {
  6953. c.transitionStart();
  6954. if (c.params.autoHeight) {
  6955. nextTick(() => {
  6956. c.updateAutoHeight();
  6957. });
  6958. }
  6959. elementTransitionEnd(c.wrapperEl, () => {
  6960. if (!controlled) return;
  6961. c.transitionEnd();
  6962. });
  6963. }
  6964. }
  6965. if (Array.isArray(controlled)) {
  6966. for (i = 0; i < controlled.length; i += 1) {
  6967. if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
  6968. setControlledTransition(controlled[i]);
  6969. }
  6970. }
  6971. } else if (controlled instanceof Swiper && byController !== controlled) {
  6972. setControlledTransition(controlled);
  6973. }
  6974. }
  6975. function removeSpline() {
  6976. if (!swiper.controller.control) return;
  6977. if (swiper.controller.spline) {
  6978. swiper.controller.spline = undefined;
  6979. delete swiper.controller.spline;
  6980. }
  6981. }
  6982. on('beforeInit', () => {
  6983. if (typeof window !== 'undefined' && (
  6984. // eslint-disable-line
  6985. typeof swiper.params.controller.control === 'string' || swiper.params.controller.control instanceof HTMLElement)) {
  6986. const controlElements = typeof swiper.params.controller.control === 'string' ? [...document.querySelectorAll(swiper.params.controller.control)] : [swiper.params.controller.control];
  6987. controlElements.forEach(controlElement => {
  6988. if (!swiper.controller.control) swiper.controller.control = [];
  6989. if (controlElement && controlElement.swiper) {
  6990. swiper.controller.control.push(controlElement.swiper);
  6991. } else if (controlElement) {
  6992. const eventName = `${swiper.params.eventsPrefix}init`;
  6993. const onControllerSwiper = e => {
  6994. swiper.controller.control.push(e.detail[0]);
  6995. swiper.update();
  6996. controlElement.removeEventListener(eventName, onControllerSwiper);
  6997. };
  6998. controlElement.addEventListener(eventName, onControllerSwiper);
  6999. }
  7000. });
  7001. return;
  7002. }
  7003. swiper.controller.control = swiper.params.controller.control;
  7004. });
  7005. on('update', () => {
  7006. removeSpline();
  7007. });
  7008. on('resize', () => {
  7009. removeSpline();
  7010. });
  7011. on('observerUpdate', () => {
  7012. removeSpline();
  7013. });
  7014. on('setTranslate', (_s, translate, byController) => {
  7015. if (!swiper.controller.control || swiper.controller.control.destroyed) return;
  7016. swiper.controller.setTranslate(translate, byController);
  7017. });
  7018. on('setTransition', (_s, duration, byController) => {
  7019. if (!swiper.controller.control || swiper.controller.control.destroyed) return;
  7020. swiper.controller.setTransition(duration, byController);
  7021. });
  7022. Object.assign(swiper.controller, {
  7023. setTranslate,
  7024. setTransition
  7025. });
  7026. }
  7027. function A11y(_ref) {
  7028. let {
  7029. swiper,
  7030. extendParams,
  7031. on
  7032. } = _ref;
  7033. extendParams({
  7034. a11y: {
  7035. enabled: true,
  7036. notificationClass: 'swiper-notification',
  7037. prevSlideMessage: 'Previous slide',
  7038. nextSlideMessage: 'Next slide',
  7039. firstSlideMessage: 'This is the first slide',
  7040. lastSlideMessage: 'This is the last slide',
  7041. paginationBulletMessage: 'Go to slide {{index}}',
  7042. slideLabelMessage: '{{index}} / {{slidesLength}}',
  7043. containerMessage: null,
  7044. containerRoleDescriptionMessage: null,
  7045. containerRole: null,
  7046. itemRoleDescriptionMessage: null,
  7047. slideRole: 'group',
  7048. id: null,
  7049. scrollOnFocus: true
  7050. }
  7051. });
  7052. swiper.a11y = {
  7053. clicked: false
  7054. };
  7055. let liveRegion = null;
  7056. let preventFocusHandler;
  7057. let focusTargetSlideEl;
  7058. let visibilityChangedTimestamp = new Date().getTime();
  7059. function notify(message) {
  7060. const notification = liveRegion;
  7061. if (notification.length === 0) return;
  7062. notification.innerHTML = '';
  7063. notification.innerHTML = message;
  7064. }
  7065. function getRandomNumber(size) {
  7066. if (size === void 0) {
  7067. size = 16;
  7068. }
  7069. const randomChar = () => Math.round(16 * Math.random()).toString(16);
  7070. return 'x'.repeat(size).replace(/x/g, randomChar);
  7071. }
  7072. function makeElFocusable(el) {
  7073. el = makeElementsArray(el);
  7074. el.forEach(subEl => {
  7075. subEl.setAttribute('tabIndex', '0');
  7076. });
  7077. }
  7078. function makeElNotFocusable(el) {
  7079. el = makeElementsArray(el);
  7080. el.forEach(subEl => {
  7081. subEl.setAttribute('tabIndex', '-1');
  7082. });
  7083. }
  7084. function addElRole(el, role) {
  7085. el = makeElementsArray(el);
  7086. el.forEach(subEl => {
  7087. subEl.setAttribute('role', role);
  7088. });
  7089. }
  7090. function addElRoleDescription(el, description) {
  7091. el = makeElementsArray(el);
  7092. el.forEach(subEl => {
  7093. subEl.setAttribute('aria-roledescription', description);
  7094. });
  7095. }
  7096. function addElControls(el, controls) {
  7097. el = makeElementsArray(el);
  7098. el.forEach(subEl => {
  7099. subEl.setAttribute('aria-controls', controls);
  7100. });
  7101. }
  7102. function addElLabel(el, label) {
  7103. el = makeElementsArray(el);
  7104. el.forEach(subEl => {
  7105. subEl.setAttribute('aria-label', label);
  7106. });
  7107. }
  7108. function addElId(el, id) {
  7109. el = makeElementsArray(el);
  7110. el.forEach(subEl => {
  7111. subEl.setAttribute('id', id);
  7112. });
  7113. }
  7114. function addElLive(el, live) {
  7115. el = makeElementsArray(el);
  7116. el.forEach(subEl => {
  7117. subEl.setAttribute('aria-live', live);
  7118. });
  7119. }
  7120. function disableEl(el) {
  7121. el = makeElementsArray(el);
  7122. el.forEach(subEl => {
  7123. subEl.setAttribute('aria-disabled', true);
  7124. });
  7125. }
  7126. function enableEl(el) {
  7127. el = makeElementsArray(el);
  7128. el.forEach(subEl => {
  7129. subEl.setAttribute('aria-disabled', false);
  7130. });
  7131. }
  7132. function onEnterOrSpaceKey(e) {
  7133. if (e.keyCode !== 13 && e.keyCode !== 32) return;
  7134. const params = swiper.params.a11y;
  7135. const targetEl = e.target;
  7136. if (swiper.pagination && swiper.pagination.el && (targetEl === swiper.pagination.el || swiper.pagination.el.contains(e.target))) {
  7137. if (!e.target.matches(classesToSelector(swiper.params.pagination.bulletClass))) return;
  7138. }
  7139. if (swiper.navigation && swiper.navigation.prevEl && swiper.navigation.nextEl) {
  7140. const prevEls = makeElementsArray(swiper.navigation.prevEl);
  7141. const nextEls = makeElementsArray(swiper.navigation.nextEl);
  7142. if (nextEls.includes(targetEl)) {
  7143. if (!(swiper.isEnd && !swiper.params.loop)) {
  7144. swiper.slideNext();
  7145. }
  7146. if (swiper.isEnd) {
  7147. notify(params.lastSlideMessage);
  7148. } else {
  7149. notify(params.nextSlideMessage);
  7150. }
  7151. }
  7152. if (prevEls.includes(targetEl)) {
  7153. if (!(swiper.isBeginning && !swiper.params.loop)) {
  7154. swiper.slidePrev();
  7155. }
  7156. if (swiper.isBeginning) {
  7157. notify(params.firstSlideMessage);
  7158. } else {
  7159. notify(params.prevSlideMessage);
  7160. }
  7161. }
  7162. }
  7163. if (swiper.pagination && targetEl.matches(classesToSelector(swiper.params.pagination.bulletClass))) {
  7164. targetEl.click();
  7165. }
  7166. }
  7167. function updateNavigation() {
  7168. if (swiper.params.loop || swiper.params.rewind || !swiper.navigation) return;
  7169. const {
  7170. nextEl,
  7171. prevEl
  7172. } = swiper.navigation;
  7173. if (prevEl) {
  7174. if (swiper.isBeginning) {
  7175. disableEl(prevEl);
  7176. makeElNotFocusable(prevEl);
  7177. } else {
  7178. enableEl(prevEl);
  7179. makeElFocusable(prevEl);
  7180. }
  7181. }
  7182. if (nextEl) {
  7183. if (swiper.isEnd) {
  7184. disableEl(nextEl);
  7185. makeElNotFocusable(nextEl);
  7186. } else {
  7187. enableEl(nextEl);
  7188. makeElFocusable(nextEl);
  7189. }
  7190. }
  7191. }
  7192. function hasPagination() {
  7193. return swiper.pagination && swiper.pagination.bullets && swiper.pagination.bullets.length;
  7194. }
  7195. function hasClickablePagination() {
  7196. return hasPagination() && swiper.params.pagination.clickable;
  7197. }
  7198. function updatePagination() {
  7199. const params = swiper.params.a11y;
  7200. if (!hasPagination()) return;
  7201. swiper.pagination.bullets.forEach(bulletEl => {
  7202. if (swiper.params.pagination.clickable) {
  7203. makeElFocusable(bulletEl);
  7204. if (!swiper.params.pagination.renderBullet) {
  7205. addElRole(bulletEl, 'button');
  7206. addElLabel(bulletEl, params.paginationBulletMessage.replace(/\{\{index\}\}/, elementIndex(bulletEl) + 1));
  7207. }
  7208. }
  7209. if (bulletEl.matches(classesToSelector(swiper.params.pagination.bulletActiveClass))) {
  7210. bulletEl.setAttribute('aria-current', 'true');
  7211. } else {
  7212. bulletEl.removeAttribute('aria-current');
  7213. }
  7214. });
  7215. }
  7216. const initNavEl = (el, wrapperId, message) => {
  7217. makeElFocusable(el);
  7218. if (el.tagName !== 'BUTTON') {
  7219. addElRole(el, 'button');
  7220. el.addEventListener('keydown', onEnterOrSpaceKey);
  7221. }
  7222. addElLabel(el, message);
  7223. addElControls(el, wrapperId);
  7224. };
  7225. const handlePointerDown = e => {
  7226. if (focusTargetSlideEl && focusTargetSlideEl !== e.target && !focusTargetSlideEl.contains(e.target)) {
  7227. preventFocusHandler = true;
  7228. }
  7229. swiper.a11y.clicked = true;
  7230. };
  7231. const handlePointerUp = () => {
  7232. preventFocusHandler = false;
  7233. requestAnimationFrame(() => {
  7234. requestAnimationFrame(() => {
  7235. if (!swiper.destroyed) {
  7236. swiper.a11y.clicked = false;
  7237. }
  7238. });
  7239. });
  7240. };
  7241. const onVisibilityChange = e => {
  7242. visibilityChangedTimestamp = new Date().getTime();
  7243. };
  7244. const handleFocus = e => {
  7245. if (swiper.a11y.clicked || !swiper.params.a11y.scrollOnFocus) return;
  7246. if (new Date().getTime() - visibilityChangedTimestamp < 100) return;
  7247. const slideEl = e.target.closest(`.${swiper.params.slideClass}, swiper-slide`);
  7248. if (!slideEl || !swiper.slides.includes(slideEl)) return;
  7249. focusTargetSlideEl = slideEl;
  7250. const isActive = swiper.slides.indexOf(slideEl) === swiper.activeIndex;
  7251. const isVisible = swiper.params.watchSlidesProgress && swiper.visibleSlides && swiper.visibleSlides.includes(slideEl);
  7252. if (isActive || isVisible) return;
  7253. if (e.sourceCapabilities && e.sourceCapabilities.firesTouchEvents) return;
  7254. if (swiper.isHorizontal()) {
  7255. swiper.el.scrollLeft = 0;
  7256. } else {
  7257. swiper.el.scrollTop = 0;
  7258. }
  7259. requestAnimationFrame(() => {
  7260. if (preventFocusHandler) return;
  7261. if (swiper.params.loop) {
  7262. swiper.slideToLoop(parseInt(slideEl.getAttribute('data-swiper-slide-index')), 0);
  7263. } else {
  7264. swiper.slideTo(swiper.slides.indexOf(slideEl), 0);
  7265. }
  7266. preventFocusHandler = false;
  7267. });
  7268. };
  7269. const initSlides = () => {
  7270. const params = swiper.params.a11y;
  7271. if (params.itemRoleDescriptionMessage) {
  7272. addElRoleDescription(swiper.slides, params.itemRoleDescriptionMessage);
  7273. }
  7274. if (params.slideRole) {
  7275. addElRole(swiper.slides, params.slideRole);
  7276. }
  7277. const slidesLength = swiper.slides.length;
  7278. if (params.slideLabelMessage) {
  7279. swiper.slides.forEach((slideEl, index) => {
  7280. const slideIndex = swiper.params.loop ? parseInt(slideEl.getAttribute('data-swiper-slide-index'), 10) : index;
  7281. const ariaLabelMessage = params.slideLabelMessage.replace(/\{\{index\}\}/, slideIndex + 1).replace(/\{\{slidesLength\}\}/, slidesLength);
  7282. addElLabel(slideEl, ariaLabelMessage);
  7283. });
  7284. }
  7285. };
  7286. const init = () => {
  7287. const params = swiper.params.a11y;
  7288. swiper.el.append(liveRegion);
  7289. // Container
  7290. const containerEl = swiper.el;
  7291. if (params.containerRoleDescriptionMessage) {
  7292. addElRoleDescription(containerEl, params.containerRoleDescriptionMessage);
  7293. }
  7294. if (params.containerMessage) {
  7295. addElLabel(containerEl, params.containerMessage);
  7296. }
  7297. if (params.containerRole) {
  7298. addElRole(containerEl, params.containerRole);
  7299. }
  7300. // Wrapper
  7301. const wrapperEl = swiper.wrapperEl;
  7302. const wrapperId = params.id || wrapperEl.getAttribute('id') || `swiper-wrapper-${getRandomNumber(16)}`;
  7303. const live = swiper.params.autoplay && swiper.params.autoplay.enabled ? 'off' : 'polite';
  7304. addElId(wrapperEl, wrapperId);
  7305. addElLive(wrapperEl, live);
  7306. // Slide
  7307. initSlides();
  7308. // Navigation
  7309. let {
  7310. nextEl,
  7311. prevEl
  7312. } = swiper.navigation ? swiper.navigation : {};
  7313. nextEl = makeElementsArray(nextEl);
  7314. prevEl = makeElementsArray(prevEl);
  7315. if (nextEl) {
  7316. nextEl.forEach(el => initNavEl(el, wrapperId, params.nextSlideMessage));
  7317. }
  7318. if (prevEl) {
  7319. prevEl.forEach(el => initNavEl(el, wrapperId, params.prevSlideMessage));
  7320. }
  7321. // Pagination
  7322. if (hasClickablePagination()) {
  7323. const paginationEl = makeElementsArray(swiper.pagination.el);
  7324. paginationEl.forEach(el => {
  7325. el.addEventListener('keydown', onEnterOrSpaceKey);
  7326. });
  7327. }
  7328. // Tab focus
  7329. const document = getDocument();
  7330. document.addEventListener('visibilitychange', onVisibilityChange);
  7331. swiper.el.addEventListener('focus', handleFocus, true);
  7332. swiper.el.addEventListener('focus', handleFocus, true);
  7333. swiper.el.addEventListener('pointerdown', handlePointerDown, true);
  7334. swiper.el.addEventListener('pointerup', handlePointerUp, true);
  7335. };
  7336. function destroy() {
  7337. if (liveRegion) liveRegion.remove();
  7338. let {
  7339. nextEl,
  7340. prevEl
  7341. } = swiper.navigation ? swiper.navigation : {};
  7342. nextEl = makeElementsArray(nextEl);
  7343. prevEl = makeElementsArray(prevEl);
  7344. if (nextEl) {
  7345. nextEl.forEach(el => el.removeEventListener('keydown', onEnterOrSpaceKey));
  7346. }
  7347. if (prevEl) {
  7348. prevEl.forEach(el => el.removeEventListener('keydown', onEnterOrSpaceKey));
  7349. }
  7350. // Pagination
  7351. if (hasClickablePagination()) {
  7352. const paginationEl = makeElementsArray(swiper.pagination.el);
  7353. paginationEl.forEach(el => {
  7354. el.removeEventListener('keydown', onEnterOrSpaceKey);
  7355. });
  7356. }
  7357. const document = getDocument();
  7358. document.removeEventListener('visibilitychange', onVisibilityChange);
  7359. // Tab focus
  7360. if (swiper.el && typeof swiper.el !== 'string') {
  7361. swiper.el.removeEventListener('focus', handleFocus, true);
  7362. swiper.el.removeEventListener('pointerdown', handlePointerDown, true);
  7363. swiper.el.removeEventListener('pointerup', handlePointerUp, true);
  7364. }
  7365. }
  7366. on('beforeInit', () => {
  7367. liveRegion = createElement('span', swiper.params.a11y.notificationClass);
  7368. liveRegion.setAttribute('aria-live', 'assertive');
  7369. liveRegion.setAttribute('aria-atomic', 'true');
  7370. });
  7371. on('afterInit', () => {
  7372. if (!swiper.params.a11y.enabled) return;
  7373. init();
  7374. });
  7375. on('slidesLengthChange snapGridLengthChange slidesGridLengthChange', () => {
  7376. if (!swiper.params.a11y.enabled) return;
  7377. initSlides();
  7378. });
  7379. on('fromEdge toEdge afterInit lock unlock', () => {
  7380. if (!swiper.params.a11y.enabled) return;
  7381. updateNavigation();
  7382. });
  7383. on('paginationUpdate', () => {
  7384. if (!swiper.params.a11y.enabled) return;
  7385. updatePagination();
  7386. });
  7387. on('destroy', () => {
  7388. if (!swiper.params.a11y.enabled) return;
  7389. destroy();
  7390. });
  7391. }
  7392. function History(_ref) {
  7393. let {
  7394. swiper,
  7395. extendParams,
  7396. on
  7397. } = _ref;
  7398. extendParams({
  7399. history: {
  7400. enabled: false,
  7401. root: '',
  7402. replaceState: false,
  7403. key: 'slides',
  7404. keepQuery: false
  7405. }
  7406. });
  7407. let initialized = false;
  7408. let paths = {};
  7409. const slugify = text => {
  7410. return text.toString().replace(/\s+/g, '-').replace(/[^\w-]+/g, '').replace(/--+/g, '-').replace(/^-+/, '').replace(/-+$/, '');
  7411. };
  7412. const getPathValues = urlOverride => {
  7413. const window = getWindow();
  7414. let location;
  7415. if (urlOverride) {
  7416. location = new URL(urlOverride);
  7417. } else {
  7418. location = window.location;
  7419. }
  7420. const pathArray = location.pathname.slice(1).split('/').filter(part => part !== '');
  7421. const total = pathArray.length;
  7422. const key = pathArray[total - 2];
  7423. const value = pathArray[total - 1];
  7424. return {
  7425. key,
  7426. value
  7427. };
  7428. };
  7429. const setHistory = (key, index) => {
  7430. const window = getWindow();
  7431. if (!initialized || !swiper.params.history.enabled) return;
  7432. let location;
  7433. if (swiper.params.url) {
  7434. location = new URL(swiper.params.url);
  7435. } else {
  7436. location = window.location;
  7437. }
  7438. const slide = swiper.virtual && swiper.params.virtual.enabled ? swiper.slidesEl.querySelector(`[data-swiper-slide-index="${index}"]`) : swiper.slides[index];
  7439. let value = slugify(slide.getAttribute('data-history'));
  7440. if (swiper.params.history.root.length > 0) {
  7441. let root = swiper.params.history.root;
  7442. if (root[root.length - 1] === '/') root = root.slice(0, root.length - 1);
  7443. value = `${root}/${key ? `${key}/` : ''}${value}`;
  7444. } else if (!location.pathname.includes(key)) {
  7445. value = `${key ? `${key}/` : ''}${value}`;
  7446. }
  7447. if (swiper.params.history.keepQuery) {
  7448. value += location.search;
  7449. }
  7450. const currentState = window.history.state;
  7451. if (currentState && currentState.value === value) {
  7452. return;
  7453. }
  7454. if (swiper.params.history.replaceState) {
  7455. window.history.replaceState({
  7456. value
  7457. }, null, value);
  7458. } else {
  7459. window.history.pushState({
  7460. value
  7461. }, null, value);
  7462. }
  7463. };
  7464. const scrollToSlide = (speed, value, runCallbacks) => {
  7465. if (value) {
  7466. for (let i = 0, length = swiper.slides.length; i < length; i += 1) {
  7467. const slide = swiper.slides[i];
  7468. const slideHistory = slugify(slide.getAttribute('data-history'));
  7469. if (slideHistory === value) {
  7470. const index = swiper.getSlideIndex(slide);
  7471. swiper.slideTo(index, speed, runCallbacks);
  7472. }
  7473. }
  7474. } else {
  7475. swiper.slideTo(0, speed, runCallbacks);
  7476. }
  7477. };
  7478. const setHistoryPopState = () => {
  7479. paths = getPathValues(swiper.params.url);
  7480. scrollToSlide(swiper.params.speed, paths.value, false);
  7481. };
  7482. const init = () => {
  7483. const window = getWindow();
  7484. if (!swiper.params.history) return;
  7485. if (!window.history || !window.history.pushState) {
  7486. swiper.params.history.enabled = false;
  7487. swiper.params.hashNavigation.enabled = true;
  7488. return;
  7489. }
  7490. initialized = true;
  7491. paths = getPathValues(swiper.params.url);
  7492. if (!paths.key && !paths.value) {
  7493. if (!swiper.params.history.replaceState) {
  7494. window.addEventListener('popstate', setHistoryPopState);
  7495. }
  7496. return;
  7497. }
  7498. scrollToSlide(0, paths.value, swiper.params.runCallbacksOnInit);
  7499. if (!swiper.params.history.replaceState) {
  7500. window.addEventListener('popstate', setHistoryPopState);
  7501. }
  7502. };
  7503. const destroy = () => {
  7504. const window = getWindow();
  7505. if (!swiper.params.history.replaceState) {
  7506. window.removeEventListener('popstate', setHistoryPopState);
  7507. }
  7508. };
  7509. on('init', () => {
  7510. if (swiper.params.history.enabled) {
  7511. init();
  7512. }
  7513. });
  7514. on('destroy', () => {
  7515. if (swiper.params.history.enabled) {
  7516. destroy();
  7517. }
  7518. });
  7519. on('transitionEnd _freeModeNoMomentumRelease', () => {
  7520. if (initialized) {
  7521. setHistory(swiper.params.history.key, swiper.activeIndex);
  7522. }
  7523. });
  7524. on('slideChange', () => {
  7525. if (initialized && swiper.params.cssMode) {
  7526. setHistory(swiper.params.history.key, swiper.activeIndex);
  7527. }
  7528. });
  7529. }
  7530. function HashNavigation(_ref) {
  7531. let {
  7532. swiper,
  7533. extendParams,
  7534. emit,
  7535. on
  7536. } = _ref;
  7537. let initialized = false;
  7538. const document = getDocument();
  7539. const window = getWindow();
  7540. extendParams({
  7541. hashNavigation: {
  7542. enabled: false,
  7543. replaceState: false,
  7544. watchState: false,
  7545. getSlideIndex(_s, hash) {
  7546. if (swiper.virtual && swiper.params.virtual.enabled) {
  7547. const slideWithHash = swiper.slides.filter(slideEl => slideEl.getAttribute('data-hash') === hash)[0];
  7548. if (!slideWithHash) return 0;
  7549. const index = parseInt(slideWithHash.getAttribute('data-swiper-slide-index'), 10);
  7550. return index;
  7551. }
  7552. return swiper.getSlideIndex(elementChildren(swiper.slidesEl, `.${swiper.params.slideClass}[data-hash="${hash}"], swiper-slide[data-hash="${hash}"]`)[0]);
  7553. }
  7554. }
  7555. });
  7556. const onHashChange = () => {
  7557. emit('hashChange');
  7558. const newHash = document.location.hash.replace('#', '');
  7559. const activeSlideEl = swiper.virtual && swiper.params.virtual.enabled ? swiper.slidesEl.querySelector(`[data-swiper-slide-index="${swiper.activeIndex}"]`) : swiper.slides[swiper.activeIndex];
  7560. const activeSlideHash = activeSlideEl ? activeSlideEl.getAttribute('data-hash') : '';
  7561. if (newHash !== activeSlideHash) {
  7562. const newIndex = swiper.params.hashNavigation.getSlideIndex(swiper, newHash);
  7563. if (typeof newIndex === 'undefined' || Number.isNaN(newIndex)) return;
  7564. swiper.slideTo(newIndex);
  7565. }
  7566. };
  7567. const setHash = () => {
  7568. if (!initialized || !swiper.params.hashNavigation.enabled) return;
  7569. const activeSlideEl = swiper.virtual && swiper.params.virtual.enabled ? swiper.slidesEl.querySelector(`[data-swiper-slide-index="${swiper.activeIndex}"]`) : swiper.slides[swiper.activeIndex];
  7570. const activeSlideHash = activeSlideEl ? activeSlideEl.getAttribute('data-hash') || activeSlideEl.getAttribute('data-history') : '';
  7571. if (swiper.params.hashNavigation.replaceState && window.history && window.history.replaceState) {
  7572. window.history.replaceState(null, null, `#${activeSlideHash}` || '');
  7573. emit('hashSet');
  7574. } else {
  7575. document.location.hash = activeSlideHash || '';
  7576. emit('hashSet');
  7577. }
  7578. };
  7579. const init = () => {
  7580. if (!swiper.params.hashNavigation.enabled || swiper.params.history && swiper.params.history.enabled) return;
  7581. initialized = true;
  7582. const hash = document.location.hash.replace('#', '');
  7583. if (hash) {
  7584. const speed = 0;
  7585. const index = swiper.params.hashNavigation.getSlideIndex(swiper, hash);
  7586. swiper.slideTo(index || 0, speed, swiper.params.runCallbacksOnInit, true);
  7587. }
  7588. if (swiper.params.hashNavigation.watchState) {
  7589. window.addEventListener('hashchange', onHashChange);
  7590. }
  7591. };
  7592. const destroy = () => {
  7593. if (swiper.params.hashNavigation.watchState) {
  7594. window.removeEventListener('hashchange', onHashChange);
  7595. }
  7596. };
  7597. on('init', () => {
  7598. if (swiper.params.hashNavigation.enabled) {
  7599. init();
  7600. }
  7601. });
  7602. on('destroy', () => {
  7603. if (swiper.params.hashNavigation.enabled) {
  7604. destroy();
  7605. }
  7606. });
  7607. on('transitionEnd _freeModeNoMomentumRelease', () => {
  7608. if (initialized) {
  7609. setHash();
  7610. }
  7611. });
  7612. on('slideChange', () => {
  7613. if (initialized && swiper.params.cssMode) {
  7614. setHash();
  7615. }
  7616. });
  7617. }
  7618. /* eslint no-underscore-dangle: "off" */
  7619. /* eslint no-use-before-define: "off" */
  7620. function Autoplay(_ref) {
  7621. let {
  7622. swiper,
  7623. extendParams,
  7624. on,
  7625. emit,
  7626. params
  7627. } = _ref;
  7628. swiper.autoplay = {
  7629. running: false,
  7630. paused: false,
  7631. timeLeft: 0
  7632. };
  7633. extendParams({
  7634. autoplay: {
  7635. enabled: false,
  7636. delay: 3000,
  7637. waitForTransition: true,
  7638. disableOnInteraction: false,
  7639. stopOnLastSlide: false,
  7640. reverseDirection: false,
  7641. pauseOnMouseEnter: false
  7642. }
  7643. });
  7644. let timeout;
  7645. let raf;
  7646. let autoplayDelayTotal = params && params.autoplay ? params.autoplay.delay : 3000;
  7647. let autoplayDelayCurrent = params && params.autoplay ? params.autoplay.delay : 3000;
  7648. let autoplayTimeLeft;
  7649. let autoplayStartTime = new Date().getTime();
  7650. let wasPaused;
  7651. let isTouched;
  7652. let pausedByTouch;
  7653. let touchStartTimeout;
  7654. let slideChanged;
  7655. let pausedByInteraction;
  7656. let pausedByPointerEnter;
  7657. function onTransitionEnd(e) {
  7658. if (!swiper || swiper.destroyed || !swiper.wrapperEl) return;
  7659. if (e.target !== swiper.wrapperEl) return;
  7660. swiper.wrapperEl.removeEventListener('transitionend', onTransitionEnd);
  7661. if (pausedByPointerEnter || e.detail && e.detail.bySwiperTouchMove) {
  7662. return;
  7663. }
  7664. resume();
  7665. }
  7666. const calcTimeLeft = () => {
  7667. if (swiper.destroyed || !swiper.autoplay.running) return;
  7668. if (swiper.autoplay.paused) {
  7669. wasPaused = true;
  7670. } else if (wasPaused) {
  7671. autoplayDelayCurrent = autoplayTimeLeft;
  7672. wasPaused = false;
  7673. }
  7674. const timeLeft = swiper.autoplay.paused ? autoplayTimeLeft : autoplayStartTime + autoplayDelayCurrent - new Date().getTime();
  7675. swiper.autoplay.timeLeft = timeLeft;
  7676. emit('autoplayTimeLeft', timeLeft, timeLeft / autoplayDelayTotal);
  7677. raf = requestAnimationFrame(() => {
  7678. calcTimeLeft();
  7679. });
  7680. };
  7681. const getSlideDelay = () => {
  7682. let activeSlideEl;
  7683. if (swiper.virtual && swiper.params.virtual.enabled) {
  7684. activeSlideEl = swiper.slides.filter(slideEl => slideEl.classList.contains('swiper-slide-active'))[0];
  7685. } else {
  7686. activeSlideEl = swiper.slides[swiper.activeIndex];
  7687. }
  7688. if (!activeSlideEl) return undefined;
  7689. const currentSlideDelay = parseInt(activeSlideEl.getAttribute('data-swiper-autoplay'), 10);
  7690. return currentSlideDelay;
  7691. };
  7692. const run = delayForce => {
  7693. if (swiper.destroyed || !swiper.autoplay.running) return;
  7694. cancelAnimationFrame(raf);
  7695. calcTimeLeft();
  7696. let delay = typeof delayForce === 'undefined' ? swiper.params.autoplay.delay : delayForce;
  7697. autoplayDelayTotal = swiper.params.autoplay.delay;
  7698. autoplayDelayCurrent = swiper.params.autoplay.delay;
  7699. const currentSlideDelay = getSlideDelay();
  7700. if (!Number.isNaN(currentSlideDelay) && currentSlideDelay > 0 && typeof delayForce === 'undefined') {
  7701. delay = currentSlideDelay;
  7702. autoplayDelayTotal = currentSlideDelay;
  7703. autoplayDelayCurrent = currentSlideDelay;
  7704. }
  7705. autoplayTimeLeft = delay;
  7706. const speed = swiper.params.speed;
  7707. const proceed = () => {
  7708. if (!swiper || swiper.destroyed) return;
  7709. if (swiper.params.autoplay.reverseDirection) {
  7710. if (!swiper.isBeginning || swiper.params.loop || swiper.params.rewind) {
  7711. swiper.slidePrev(speed, true, true);
  7712. emit('autoplay');
  7713. } else if (!swiper.params.autoplay.stopOnLastSlide) {
  7714. swiper.slideTo(swiper.slides.length - 1, speed, true, true);
  7715. emit('autoplay');
  7716. }
  7717. } else {
  7718. if (!swiper.isEnd || swiper.params.loop || swiper.params.rewind) {
  7719. swiper.slideNext(speed, true, true);
  7720. emit('autoplay');
  7721. } else if (!swiper.params.autoplay.stopOnLastSlide) {
  7722. swiper.slideTo(0, speed, true, true);
  7723. emit('autoplay');
  7724. }
  7725. }
  7726. if (swiper.params.cssMode) {
  7727. autoplayStartTime = new Date().getTime();
  7728. requestAnimationFrame(() => {
  7729. run();
  7730. });
  7731. }
  7732. };
  7733. if (delay > 0) {
  7734. clearTimeout(timeout);
  7735. timeout = setTimeout(() => {
  7736. proceed();
  7737. }, delay);
  7738. } else {
  7739. requestAnimationFrame(() => {
  7740. proceed();
  7741. });
  7742. }
  7743. // eslint-disable-next-line
  7744. return delay;
  7745. };
  7746. const start = () => {
  7747. autoplayStartTime = new Date().getTime();
  7748. swiper.autoplay.running = true;
  7749. run();
  7750. emit('autoplayStart');
  7751. };
  7752. const stop = () => {
  7753. swiper.autoplay.running = false;
  7754. clearTimeout(timeout);
  7755. cancelAnimationFrame(raf);
  7756. emit('autoplayStop');
  7757. };
  7758. const pause = (internal, reset) => {
  7759. if (swiper.destroyed || !swiper.autoplay.running) return;
  7760. clearTimeout(timeout);
  7761. if (!internal) {
  7762. pausedByInteraction = true;
  7763. }
  7764. const proceed = () => {
  7765. emit('autoplayPause');
  7766. if (swiper.params.autoplay.waitForTransition) {
  7767. swiper.wrapperEl.addEventListener('transitionend', onTransitionEnd);
  7768. } else {
  7769. resume();
  7770. }
  7771. };
  7772. swiper.autoplay.paused = true;
  7773. if (reset) {
  7774. if (slideChanged) {
  7775. autoplayTimeLeft = swiper.params.autoplay.delay;
  7776. }
  7777. slideChanged = false;
  7778. proceed();
  7779. return;
  7780. }
  7781. const delay = autoplayTimeLeft || swiper.params.autoplay.delay;
  7782. autoplayTimeLeft = delay - (new Date().getTime() - autoplayStartTime);
  7783. if (swiper.isEnd && autoplayTimeLeft < 0 && !swiper.params.loop) return;
  7784. if (autoplayTimeLeft < 0) autoplayTimeLeft = 0;
  7785. proceed();
  7786. };
  7787. const resume = () => {
  7788. if (swiper.isEnd && autoplayTimeLeft < 0 && !swiper.params.loop || swiper.destroyed || !swiper.autoplay.running) return;
  7789. autoplayStartTime = new Date().getTime();
  7790. if (pausedByInteraction) {
  7791. pausedByInteraction = false;
  7792. run(autoplayTimeLeft);
  7793. } else {
  7794. run();
  7795. }
  7796. swiper.autoplay.paused = false;
  7797. emit('autoplayResume');
  7798. };
  7799. const onVisibilityChange = () => {
  7800. if (swiper.destroyed || !swiper.autoplay.running) return;
  7801. const document = getDocument();
  7802. if (document.visibilityState === 'hidden') {
  7803. pausedByInteraction = true;
  7804. pause(true);
  7805. }
  7806. if (document.visibilityState === 'visible') {
  7807. resume();
  7808. }
  7809. };
  7810. const onPointerEnter = e => {
  7811. if (e.pointerType !== 'mouse') return;
  7812. pausedByInteraction = true;
  7813. pausedByPointerEnter = true;
  7814. if (swiper.animating || swiper.autoplay.paused) return;
  7815. pause(true);
  7816. };
  7817. const onPointerLeave = e => {
  7818. if (e.pointerType !== 'mouse') return;
  7819. pausedByPointerEnter = false;
  7820. if (swiper.autoplay.paused) {
  7821. resume();
  7822. }
  7823. };
  7824. const attachMouseEvents = () => {
  7825. if (swiper.params.autoplay.pauseOnMouseEnter) {
  7826. swiper.el.addEventListener('pointerenter', onPointerEnter);
  7827. swiper.el.addEventListener('pointerleave', onPointerLeave);
  7828. }
  7829. };
  7830. const detachMouseEvents = () => {
  7831. if (swiper.el && typeof swiper.el !== 'string') {
  7832. swiper.el.removeEventListener('pointerenter', onPointerEnter);
  7833. swiper.el.removeEventListener('pointerleave', onPointerLeave);
  7834. }
  7835. };
  7836. const attachDocumentEvents = () => {
  7837. const document = getDocument();
  7838. document.addEventListener('visibilitychange', onVisibilityChange);
  7839. };
  7840. const detachDocumentEvents = () => {
  7841. const document = getDocument();
  7842. document.removeEventListener('visibilitychange', onVisibilityChange);
  7843. };
  7844. on('init', () => {
  7845. if (swiper.params.autoplay.enabled) {
  7846. attachMouseEvents();
  7847. attachDocumentEvents();
  7848. start();
  7849. }
  7850. });
  7851. on('destroy', () => {
  7852. detachMouseEvents();
  7853. detachDocumentEvents();
  7854. if (swiper.autoplay.running) {
  7855. stop();
  7856. }
  7857. });
  7858. on('_freeModeStaticRelease', () => {
  7859. if (pausedByTouch || pausedByInteraction) {
  7860. resume();
  7861. }
  7862. });
  7863. on('_freeModeNoMomentumRelease', () => {
  7864. if (!swiper.params.autoplay.disableOnInteraction) {
  7865. pause(true, true);
  7866. } else {
  7867. stop();
  7868. }
  7869. });
  7870. on('beforeTransitionStart', (_s, speed, internal) => {
  7871. if (swiper.destroyed || !swiper.autoplay.running) return;
  7872. if (internal || !swiper.params.autoplay.disableOnInteraction) {
  7873. pause(true, true);
  7874. } else {
  7875. stop();
  7876. }
  7877. });
  7878. on('sliderFirstMove', () => {
  7879. if (swiper.destroyed || !swiper.autoplay.running) return;
  7880. if (swiper.params.autoplay.disableOnInteraction) {
  7881. stop();
  7882. return;
  7883. }
  7884. isTouched = true;
  7885. pausedByTouch = false;
  7886. pausedByInteraction = false;
  7887. touchStartTimeout = setTimeout(() => {
  7888. pausedByInteraction = true;
  7889. pausedByTouch = true;
  7890. pause(true);
  7891. }, 200);
  7892. });
  7893. on('touchEnd', () => {
  7894. if (swiper.destroyed || !swiper.autoplay.running || !isTouched) return;
  7895. clearTimeout(touchStartTimeout);
  7896. clearTimeout(timeout);
  7897. if (swiper.params.autoplay.disableOnInteraction) {
  7898. pausedByTouch = false;
  7899. isTouched = false;
  7900. return;
  7901. }
  7902. if (pausedByTouch && swiper.params.cssMode) resume();
  7903. pausedByTouch = false;
  7904. isTouched = false;
  7905. });
  7906. on('slideChange', () => {
  7907. if (swiper.destroyed || !swiper.autoplay.running) return;
  7908. slideChanged = true;
  7909. });
  7910. Object.assign(swiper.autoplay, {
  7911. start,
  7912. stop,
  7913. pause,
  7914. resume
  7915. });
  7916. }
  7917. function Thumb(_ref) {
  7918. let {
  7919. swiper,
  7920. extendParams,
  7921. on
  7922. } = _ref;
  7923. extendParams({
  7924. thumbs: {
  7925. swiper: null,
  7926. multipleActiveThumbs: true,
  7927. autoScrollOffset: 0,
  7928. slideThumbActiveClass: 'swiper-slide-thumb-active',
  7929. thumbsContainerClass: 'swiper-thumbs'
  7930. }
  7931. });
  7932. let initialized = false;
  7933. let swiperCreated = false;
  7934. swiper.thumbs = {
  7935. swiper: null
  7936. };
  7937. function onThumbClick() {
  7938. const thumbsSwiper = swiper.thumbs.swiper;
  7939. if (!thumbsSwiper || thumbsSwiper.destroyed) return;
  7940. const clickedIndex = thumbsSwiper.clickedIndex;
  7941. const clickedSlide = thumbsSwiper.clickedSlide;
  7942. if (clickedSlide && clickedSlide.classList.contains(swiper.params.thumbs.slideThumbActiveClass)) return;
  7943. if (typeof clickedIndex === 'undefined' || clickedIndex === null) return;
  7944. let slideToIndex;
  7945. if (thumbsSwiper.params.loop) {
  7946. slideToIndex = parseInt(thumbsSwiper.clickedSlide.getAttribute('data-swiper-slide-index'), 10);
  7947. } else {
  7948. slideToIndex = clickedIndex;
  7949. }
  7950. if (swiper.params.loop) {
  7951. swiper.slideToLoop(slideToIndex);
  7952. } else {
  7953. swiper.slideTo(slideToIndex);
  7954. }
  7955. }
  7956. function init() {
  7957. const {
  7958. thumbs: thumbsParams
  7959. } = swiper.params;
  7960. if (initialized) return false;
  7961. initialized = true;
  7962. const SwiperClass = swiper.constructor;
  7963. if (thumbsParams.swiper instanceof SwiperClass) {
  7964. swiper.thumbs.swiper = thumbsParams.swiper;
  7965. Object.assign(swiper.thumbs.swiper.originalParams, {
  7966. watchSlidesProgress: true,
  7967. slideToClickedSlide: false
  7968. });
  7969. Object.assign(swiper.thumbs.swiper.params, {
  7970. watchSlidesProgress: true,
  7971. slideToClickedSlide: false
  7972. });
  7973. swiper.thumbs.swiper.update();
  7974. } else if (isObject(thumbsParams.swiper)) {
  7975. const thumbsSwiperParams = Object.assign({}, thumbsParams.swiper);
  7976. Object.assign(thumbsSwiperParams, {
  7977. watchSlidesProgress: true,
  7978. slideToClickedSlide: false
  7979. });
  7980. swiper.thumbs.swiper = new SwiperClass(thumbsSwiperParams);
  7981. swiperCreated = true;
  7982. }
  7983. swiper.thumbs.swiper.el.classList.add(swiper.params.thumbs.thumbsContainerClass);
  7984. swiper.thumbs.swiper.on('tap', onThumbClick);
  7985. return true;
  7986. }
  7987. function update(initial) {
  7988. const thumbsSwiper = swiper.thumbs.swiper;
  7989. if (!thumbsSwiper || thumbsSwiper.destroyed) return;
  7990. const slidesPerView = thumbsSwiper.params.slidesPerView === 'auto' ? thumbsSwiper.slidesPerViewDynamic() : thumbsSwiper.params.slidesPerView;
  7991. // Activate thumbs
  7992. let thumbsToActivate = 1;
  7993. const thumbActiveClass = swiper.params.thumbs.slideThumbActiveClass;
  7994. if (swiper.params.slidesPerView > 1 && !swiper.params.centeredSlides) {
  7995. thumbsToActivate = swiper.params.slidesPerView;
  7996. }
  7997. if (!swiper.params.thumbs.multipleActiveThumbs) {
  7998. thumbsToActivate = 1;
  7999. }
  8000. thumbsToActivate = Math.floor(thumbsToActivate);
  8001. thumbsSwiper.slides.forEach(slideEl => slideEl.classList.remove(thumbActiveClass));
  8002. if (thumbsSwiper.params.loop || thumbsSwiper.params.virtual && thumbsSwiper.params.virtual.enabled) {
  8003. for (let i = 0; i < thumbsToActivate; i += 1) {
  8004. elementChildren(thumbsSwiper.slidesEl, `[data-swiper-slide-index="${swiper.realIndex + i}"]`).forEach(slideEl => {
  8005. slideEl.classList.add(thumbActiveClass);
  8006. });
  8007. }
  8008. } else {
  8009. for (let i = 0; i < thumbsToActivate; i += 1) {
  8010. if (thumbsSwiper.slides[swiper.realIndex + i]) {
  8011. thumbsSwiper.slides[swiper.realIndex + i].classList.add(thumbActiveClass);
  8012. }
  8013. }
  8014. }
  8015. const autoScrollOffset = swiper.params.thumbs.autoScrollOffset;
  8016. const useOffset = autoScrollOffset && !thumbsSwiper.params.loop;
  8017. if (swiper.realIndex !== thumbsSwiper.realIndex || useOffset) {
  8018. const currentThumbsIndex = thumbsSwiper.activeIndex;
  8019. let newThumbsIndex;
  8020. let direction;
  8021. if (thumbsSwiper.params.loop) {
  8022. const newThumbsSlide = thumbsSwiper.slides.filter(slideEl => slideEl.getAttribute('data-swiper-slide-index') === `${swiper.realIndex}`)[0];
  8023. newThumbsIndex = thumbsSwiper.slides.indexOf(newThumbsSlide);
  8024. direction = swiper.activeIndex > swiper.previousIndex ? 'next' : 'prev';
  8025. } else {
  8026. newThumbsIndex = swiper.realIndex;
  8027. direction = newThumbsIndex > swiper.previousIndex ? 'next' : 'prev';
  8028. }
  8029. if (useOffset) {
  8030. newThumbsIndex += direction === 'next' ? autoScrollOffset : -1 * autoScrollOffset;
  8031. }
  8032. if (thumbsSwiper.visibleSlidesIndexes && thumbsSwiper.visibleSlidesIndexes.indexOf(newThumbsIndex) < 0) {
  8033. if (thumbsSwiper.params.centeredSlides) {
  8034. if (newThumbsIndex > currentThumbsIndex) {
  8035. newThumbsIndex = newThumbsIndex - Math.floor(slidesPerView / 2) + 1;
  8036. } else {
  8037. newThumbsIndex = newThumbsIndex + Math.floor(slidesPerView / 2) - 1;
  8038. }
  8039. } else if (newThumbsIndex > currentThumbsIndex && thumbsSwiper.params.slidesPerGroup === 1) ;
  8040. thumbsSwiper.slideTo(newThumbsIndex, initial ? 0 : undefined);
  8041. }
  8042. }
  8043. }
  8044. on('beforeInit', () => {
  8045. const {
  8046. thumbs
  8047. } = swiper.params;
  8048. if (!thumbs || !thumbs.swiper) return;
  8049. if (typeof thumbs.swiper === 'string' || thumbs.swiper instanceof HTMLElement) {
  8050. const document = getDocument();
  8051. const getThumbsElementAndInit = () => {
  8052. const thumbsElement = typeof thumbs.swiper === 'string' ? document.querySelector(thumbs.swiper) : thumbs.swiper;
  8053. if (thumbsElement && thumbsElement.swiper) {
  8054. thumbs.swiper = thumbsElement.swiper;
  8055. init();
  8056. update(true);
  8057. } else if (thumbsElement) {
  8058. const eventName = `${swiper.params.eventsPrefix}init`;
  8059. const onThumbsSwiper = e => {
  8060. thumbs.swiper = e.detail[0];
  8061. thumbsElement.removeEventListener(eventName, onThumbsSwiper);
  8062. init();
  8063. update(true);
  8064. thumbs.swiper.update();
  8065. swiper.update();
  8066. };
  8067. thumbsElement.addEventListener(eventName, onThumbsSwiper);
  8068. }
  8069. return thumbsElement;
  8070. };
  8071. const watchForThumbsToAppear = () => {
  8072. if (swiper.destroyed) return;
  8073. const thumbsElement = getThumbsElementAndInit();
  8074. if (!thumbsElement) {
  8075. requestAnimationFrame(watchForThumbsToAppear);
  8076. }
  8077. };
  8078. requestAnimationFrame(watchForThumbsToAppear);
  8079. } else {
  8080. init();
  8081. update(true);
  8082. }
  8083. });
  8084. on('slideChange update resize observerUpdate', () => {
  8085. update();
  8086. });
  8087. on('setTransition', (_s, duration) => {
  8088. const thumbsSwiper = swiper.thumbs.swiper;
  8089. if (!thumbsSwiper || thumbsSwiper.destroyed) return;
  8090. thumbsSwiper.setTransition(duration);
  8091. });
  8092. on('beforeDestroy', () => {
  8093. const thumbsSwiper = swiper.thumbs.swiper;
  8094. if (!thumbsSwiper || thumbsSwiper.destroyed) return;
  8095. if (swiperCreated) {
  8096. thumbsSwiper.destroy();
  8097. }
  8098. });
  8099. Object.assign(swiper.thumbs, {
  8100. init,
  8101. update
  8102. });
  8103. }
  8104. function freeMode(_ref) {
  8105. let {
  8106. swiper,
  8107. extendParams,
  8108. emit,
  8109. once
  8110. } = _ref;
  8111. extendParams({
  8112. freeMode: {
  8113. enabled: false,
  8114. momentum: true,
  8115. momentumRatio: 1,
  8116. momentumBounce: true,
  8117. momentumBounceRatio: 1,
  8118. momentumVelocityRatio: 1,
  8119. sticky: false,
  8120. minimumVelocity: 0.02
  8121. }
  8122. });
  8123. function onTouchStart() {
  8124. if (swiper.params.cssMode) return;
  8125. const translate = swiper.getTranslate();
  8126. swiper.setTranslate(translate);
  8127. swiper.setTransition(0);
  8128. swiper.touchEventsData.velocities.length = 0;
  8129. swiper.freeMode.onTouchEnd({
  8130. currentPos: swiper.rtl ? swiper.translate : -swiper.translate
  8131. });
  8132. }
  8133. function onTouchMove() {
  8134. if (swiper.params.cssMode) return;
  8135. const {
  8136. touchEventsData: data,
  8137. touches
  8138. } = swiper;
  8139. // Velocity
  8140. if (data.velocities.length === 0) {
  8141. data.velocities.push({
  8142. position: touches[swiper.isHorizontal() ? 'startX' : 'startY'],
  8143. time: data.touchStartTime
  8144. });
  8145. }
  8146. data.velocities.push({
  8147. position: touches[swiper.isHorizontal() ? 'currentX' : 'currentY'],
  8148. time: now()
  8149. });
  8150. }
  8151. function onTouchEnd(_ref2) {
  8152. let {
  8153. currentPos
  8154. } = _ref2;
  8155. if (swiper.params.cssMode) return;
  8156. const {
  8157. params,
  8158. wrapperEl,
  8159. rtlTranslate: rtl,
  8160. snapGrid,
  8161. touchEventsData: data
  8162. } = swiper;
  8163. // Time diff
  8164. const touchEndTime = now();
  8165. const timeDiff = touchEndTime - data.touchStartTime;
  8166. if (currentPos < -swiper.minTranslate()) {
  8167. swiper.slideTo(swiper.activeIndex);
  8168. return;
  8169. }
  8170. if (currentPos > -swiper.maxTranslate()) {
  8171. if (swiper.slides.length < snapGrid.length) {
  8172. swiper.slideTo(snapGrid.length - 1);
  8173. } else {
  8174. swiper.slideTo(swiper.slides.length - 1);
  8175. }
  8176. return;
  8177. }
  8178. if (params.freeMode.momentum) {
  8179. if (data.velocities.length > 1) {
  8180. const lastMoveEvent = data.velocities.pop();
  8181. const velocityEvent = data.velocities.pop();
  8182. const distance = lastMoveEvent.position - velocityEvent.position;
  8183. const time = lastMoveEvent.time - velocityEvent.time;
  8184. swiper.velocity = distance / time;
  8185. swiper.velocity /= 2;
  8186. if (Math.abs(swiper.velocity) < params.freeMode.minimumVelocity) {
  8187. swiper.velocity = 0;
  8188. }
  8189. // this implies that the user stopped moving a finger then released.
  8190. // There would be no events with distance zero, so the last event is stale.
  8191. if (time > 150 || now() - lastMoveEvent.time > 300) {
  8192. swiper.velocity = 0;
  8193. }
  8194. } else {
  8195. swiper.velocity = 0;
  8196. }
  8197. swiper.velocity *= params.freeMode.momentumVelocityRatio;
  8198. data.velocities.length = 0;
  8199. let momentumDuration = 1000 * params.freeMode.momentumRatio;
  8200. const momentumDistance = swiper.velocity * momentumDuration;
  8201. let newPosition = swiper.translate + momentumDistance;
  8202. if (rtl) newPosition = -newPosition;
  8203. let doBounce = false;
  8204. let afterBouncePosition;
  8205. const bounceAmount = Math.abs(swiper.velocity) * 20 * params.freeMode.momentumBounceRatio;
  8206. let needsLoopFix;
  8207. if (newPosition < swiper.maxTranslate()) {
  8208. if (params.freeMode.momentumBounce) {
  8209. if (newPosition + swiper.maxTranslate() < -bounceAmount) {
  8210. newPosition = swiper.maxTranslate() - bounceAmount;
  8211. }
  8212. afterBouncePosition = swiper.maxTranslate();
  8213. doBounce = true;
  8214. data.allowMomentumBounce = true;
  8215. } else {
  8216. newPosition = swiper.maxTranslate();
  8217. }
  8218. if (params.loop && params.centeredSlides) needsLoopFix = true;
  8219. } else if (newPosition > swiper.minTranslate()) {
  8220. if (params.freeMode.momentumBounce) {
  8221. if (newPosition - swiper.minTranslate() > bounceAmount) {
  8222. newPosition = swiper.minTranslate() + bounceAmount;
  8223. }
  8224. afterBouncePosition = swiper.minTranslate();
  8225. doBounce = true;
  8226. data.allowMomentumBounce = true;
  8227. } else {
  8228. newPosition = swiper.minTranslate();
  8229. }
  8230. if (params.loop && params.centeredSlides) needsLoopFix = true;
  8231. } else if (params.freeMode.sticky) {
  8232. let nextSlide;
  8233. for (let j = 0; j < snapGrid.length; j += 1) {
  8234. if (snapGrid[j] > -newPosition) {
  8235. nextSlide = j;
  8236. break;
  8237. }
  8238. }
  8239. if (Math.abs(snapGrid[nextSlide] - newPosition) < Math.abs(snapGrid[nextSlide - 1] - newPosition) || swiper.swipeDirection === 'next') {
  8240. newPosition = snapGrid[nextSlide];
  8241. } else {
  8242. newPosition = snapGrid[nextSlide - 1];
  8243. }
  8244. newPosition = -newPosition;
  8245. }
  8246. if (needsLoopFix) {
  8247. once('transitionEnd', () => {
  8248. swiper.loopFix();
  8249. });
  8250. }
  8251. // Fix duration
  8252. if (swiper.velocity !== 0) {
  8253. if (rtl) {
  8254. momentumDuration = Math.abs((-newPosition - swiper.translate) / swiper.velocity);
  8255. } else {
  8256. momentumDuration = Math.abs((newPosition - swiper.translate) / swiper.velocity);
  8257. }
  8258. if (params.freeMode.sticky) {
  8259. // If freeMode.sticky is active and the user ends a swipe with a slow-velocity
  8260. // event, then durations can be 20+ seconds to slide one (or zero!) slides.
  8261. // It's easy to see this when simulating touch with mouse events. To fix this,
  8262. // limit single-slide swipes to the default slide duration. This also has the
  8263. // nice side effect of matching slide speed if the user stopped moving before
  8264. // lifting finger or mouse vs. moving slowly before lifting the finger/mouse.
  8265. // For faster swipes, also apply limits (albeit higher ones).
  8266. const moveDistance = Math.abs((rtl ? -newPosition : newPosition) - swiper.translate);
  8267. const currentSlideSize = swiper.slidesSizesGrid[swiper.activeIndex];
  8268. if (moveDistance < currentSlideSize) {
  8269. momentumDuration = params.speed;
  8270. } else if (moveDistance < 2 * currentSlideSize) {
  8271. momentumDuration = params.speed * 1.5;
  8272. } else {
  8273. momentumDuration = params.speed * 2.5;
  8274. }
  8275. }
  8276. } else if (params.freeMode.sticky) {
  8277. swiper.slideToClosest();
  8278. return;
  8279. }
  8280. if (params.freeMode.momentumBounce && doBounce) {
  8281. swiper.updateProgress(afterBouncePosition);
  8282. swiper.setTransition(momentumDuration);
  8283. swiper.setTranslate(newPosition);
  8284. swiper.transitionStart(true, swiper.swipeDirection);
  8285. swiper.animating = true;
  8286. elementTransitionEnd(wrapperEl, () => {
  8287. if (!swiper || swiper.destroyed || !data.allowMomentumBounce) return;
  8288. emit('momentumBounce');
  8289. swiper.setTransition(params.speed);
  8290. setTimeout(() => {
  8291. swiper.setTranslate(afterBouncePosition);
  8292. elementTransitionEnd(wrapperEl, () => {
  8293. if (!swiper || swiper.destroyed) return;
  8294. swiper.transitionEnd();
  8295. });
  8296. }, 0);
  8297. });
  8298. } else if (swiper.velocity) {
  8299. emit('_freeModeNoMomentumRelease');
  8300. swiper.updateProgress(newPosition);
  8301. swiper.setTransition(momentumDuration);
  8302. swiper.setTranslate(newPosition);
  8303. swiper.transitionStart(true, swiper.swipeDirection);
  8304. if (!swiper.animating) {
  8305. swiper.animating = true;
  8306. elementTransitionEnd(wrapperEl, () => {
  8307. if (!swiper || swiper.destroyed) return;
  8308. swiper.transitionEnd();
  8309. });
  8310. }
  8311. } else {
  8312. swiper.updateProgress(newPosition);
  8313. }
  8314. swiper.updateActiveIndex();
  8315. swiper.updateSlidesClasses();
  8316. } else if (params.freeMode.sticky) {
  8317. swiper.slideToClosest();
  8318. return;
  8319. } else if (params.freeMode) {
  8320. emit('_freeModeNoMomentumRelease');
  8321. }
  8322. if (!params.freeMode.momentum || timeDiff >= params.longSwipesMs) {
  8323. emit('_freeModeStaticRelease');
  8324. swiper.updateProgress();
  8325. swiper.updateActiveIndex();
  8326. swiper.updateSlidesClasses();
  8327. }
  8328. }
  8329. Object.assign(swiper, {
  8330. freeMode: {
  8331. onTouchStart,
  8332. onTouchMove,
  8333. onTouchEnd
  8334. }
  8335. });
  8336. }
  8337. function Grid(_ref) {
  8338. let {
  8339. swiper,
  8340. extendParams,
  8341. on
  8342. } = _ref;
  8343. extendParams({
  8344. grid: {
  8345. rows: 1,
  8346. fill: 'column'
  8347. }
  8348. });
  8349. let slidesNumberEvenToRows;
  8350. let slidesPerRow;
  8351. let numFullColumns;
  8352. let wasMultiRow;
  8353. const getSpaceBetween = () => {
  8354. let spaceBetween = swiper.params.spaceBetween;
  8355. if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
  8356. spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * swiper.size;
  8357. } else if (typeof spaceBetween === 'string') {
  8358. spaceBetween = parseFloat(spaceBetween);
  8359. }
  8360. return spaceBetween;
  8361. };
  8362. const initSlides = slides => {
  8363. const {
  8364. slidesPerView
  8365. } = swiper.params;
  8366. const {
  8367. rows,
  8368. fill
  8369. } = swiper.params.grid;
  8370. const slidesLength = swiper.virtual && swiper.params.virtual.enabled ? swiper.virtual.slides.length : slides.length;
  8371. numFullColumns = Math.floor(slidesLength / rows);
  8372. if (Math.floor(slidesLength / rows) === slidesLength / rows) {
  8373. slidesNumberEvenToRows = slidesLength;
  8374. } else {
  8375. slidesNumberEvenToRows = Math.ceil(slidesLength / rows) * rows;
  8376. }
  8377. if (slidesPerView !== 'auto' && fill === 'row') {
  8378. slidesNumberEvenToRows = Math.max(slidesNumberEvenToRows, slidesPerView * rows);
  8379. }
  8380. slidesPerRow = slidesNumberEvenToRows / rows;
  8381. };
  8382. const unsetSlides = () => {
  8383. if (swiper.slides) {
  8384. swiper.slides.forEach(slide => {
  8385. if (slide.swiperSlideGridSet) {
  8386. slide.style.height = '';
  8387. slide.style[swiper.getDirectionLabel('margin-top')] = '';
  8388. }
  8389. });
  8390. }
  8391. };
  8392. const updateSlide = (i, slide, slides) => {
  8393. const {
  8394. slidesPerGroup
  8395. } = swiper.params;
  8396. const spaceBetween = getSpaceBetween();
  8397. const {
  8398. rows,
  8399. fill
  8400. } = swiper.params.grid;
  8401. const slidesLength = swiper.virtual && swiper.params.virtual.enabled ? swiper.virtual.slides.length : slides.length;
  8402. // Set slides order
  8403. let newSlideOrderIndex;
  8404. let column;
  8405. let row;
  8406. if (fill === 'row' && slidesPerGroup > 1) {
  8407. const groupIndex = Math.floor(i / (slidesPerGroup * rows));
  8408. const slideIndexInGroup = i - rows * slidesPerGroup * groupIndex;
  8409. const columnsInGroup = groupIndex === 0 ? slidesPerGroup : Math.min(Math.ceil((slidesLength - groupIndex * rows * slidesPerGroup) / rows), slidesPerGroup);
  8410. row = Math.floor(slideIndexInGroup / columnsInGroup);
  8411. column = slideIndexInGroup - row * columnsInGroup + groupIndex * slidesPerGroup;
  8412. newSlideOrderIndex = column + row * slidesNumberEvenToRows / rows;
  8413. slide.style.order = newSlideOrderIndex;
  8414. } else if (fill === 'column') {
  8415. column = Math.floor(i / rows);
  8416. row = i - column * rows;
  8417. if (column > numFullColumns || column === numFullColumns && row === rows - 1) {
  8418. row += 1;
  8419. if (row >= rows) {
  8420. row = 0;
  8421. column += 1;
  8422. }
  8423. }
  8424. } else {
  8425. row = Math.floor(i / slidesPerRow);
  8426. column = i - row * slidesPerRow;
  8427. }
  8428. slide.row = row;
  8429. slide.column = column;
  8430. slide.style.height = `calc((100% - ${(rows - 1) * spaceBetween}px) / ${rows})`;
  8431. slide.style[swiper.getDirectionLabel('margin-top')] = row !== 0 ? spaceBetween && `${spaceBetween}px` : '';
  8432. slide.swiperSlideGridSet = true;
  8433. };
  8434. const updateWrapperSize = (slideSize, snapGrid) => {
  8435. const {
  8436. centeredSlides,
  8437. roundLengths
  8438. } = swiper.params;
  8439. const spaceBetween = getSpaceBetween();
  8440. const {
  8441. rows
  8442. } = swiper.params.grid;
  8443. swiper.virtualSize = (slideSize + spaceBetween) * slidesNumberEvenToRows;
  8444. swiper.virtualSize = Math.ceil(swiper.virtualSize / rows) - spaceBetween;
  8445. if (!swiper.params.cssMode) {
  8446. swiper.wrapperEl.style[swiper.getDirectionLabel('width')] = `${swiper.virtualSize + spaceBetween}px`;
  8447. }
  8448. if (centeredSlides) {
  8449. const newSlidesGrid = [];
  8450. for (let i = 0; i < snapGrid.length; i += 1) {
  8451. let slidesGridItem = snapGrid[i];
  8452. if (roundLengths) slidesGridItem = Math.floor(slidesGridItem);
  8453. if (snapGrid[i] < swiper.virtualSize + snapGrid[0]) newSlidesGrid.push(slidesGridItem);
  8454. }
  8455. snapGrid.splice(0, snapGrid.length);
  8456. snapGrid.push(...newSlidesGrid);
  8457. }
  8458. };
  8459. const onInit = () => {
  8460. wasMultiRow = swiper.params.grid && swiper.params.grid.rows > 1;
  8461. };
  8462. const onUpdate = () => {
  8463. const {
  8464. params,
  8465. el
  8466. } = swiper;
  8467. const isMultiRow = params.grid && params.grid.rows > 1;
  8468. if (wasMultiRow && !isMultiRow) {
  8469. el.classList.remove(`${params.containerModifierClass}grid`, `${params.containerModifierClass}grid-column`);
  8470. numFullColumns = 1;
  8471. swiper.emitContainerClasses();
  8472. } else if (!wasMultiRow && isMultiRow) {
  8473. el.classList.add(`${params.containerModifierClass}grid`);
  8474. if (params.grid.fill === 'column') {
  8475. el.classList.add(`${params.containerModifierClass}grid-column`);
  8476. }
  8477. swiper.emitContainerClasses();
  8478. }
  8479. wasMultiRow = isMultiRow;
  8480. };
  8481. on('init', onInit);
  8482. on('update', onUpdate);
  8483. swiper.grid = {
  8484. initSlides,
  8485. unsetSlides,
  8486. updateSlide,
  8487. updateWrapperSize
  8488. };
  8489. }
  8490. function appendSlide(slides) {
  8491. const swiper = this;
  8492. const {
  8493. params,
  8494. slidesEl
  8495. } = swiper;
  8496. if (params.loop) {
  8497. swiper.loopDestroy();
  8498. }
  8499. const appendElement = slideEl => {
  8500. if (typeof slideEl === 'string') {
  8501. const tempDOM = document.createElement('div');
  8502. tempDOM.innerHTML = slideEl;
  8503. slidesEl.append(tempDOM.children[0]);
  8504. tempDOM.innerHTML = '';
  8505. } else {
  8506. slidesEl.append(slideEl);
  8507. }
  8508. };
  8509. if (typeof slides === 'object' && 'length' in slides) {
  8510. for (let i = 0; i < slides.length; i += 1) {
  8511. if (slides[i]) appendElement(slides[i]);
  8512. }
  8513. } else {
  8514. appendElement(slides);
  8515. }
  8516. swiper.recalcSlides();
  8517. if (params.loop) {
  8518. swiper.loopCreate();
  8519. }
  8520. if (!params.observer || swiper.isElement) {
  8521. swiper.update();
  8522. }
  8523. }
  8524. function prependSlide(slides) {
  8525. const swiper = this;
  8526. const {
  8527. params,
  8528. activeIndex,
  8529. slidesEl
  8530. } = swiper;
  8531. if (params.loop) {
  8532. swiper.loopDestroy();
  8533. }
  8534. let newActiveIndex = activeIndex + 1;
  8535. const prependElement = slideEl => {
  8536. if (typeof slideEl === 'string') {
  8537. const tempDOM = document.createElement('div');
  8538. tempDOM.innerHTML = slideEl;
  8539. slidesEl.prepend(tempDOM.children[0]);
  8540. tempDOM.innerHTML = '';
  8541. } else {
  8542. slidesEl.prepend(slideEl);
  8543. }
  8544. };
  8545. if (typeof slides === 'object' && 'length' in slides) {
  8546. for (let i = 0; i < slides.length; i += 1) {
  8547. if (slides[i]) prependElement(slides[i]);
  8548. }
  8549. newActiveIndex = activeIndex + slides.length;
  8550. } else {
  8551. prependElement(slides);
  8552. }
  8553. swiper.recalcSlides();
  8554. if (params.loop) {
  8555. swiper.loopCreate();
  8556. }
  8557. if (!params.observer || swiper.isElement) {
  8558. swiper.update();
  8559. }
  8560. swiper.slideTo(newActiveIndex, 0, false);
  8561. }
  8562. function addSlide(index, slides) {
  8563. const swiper = this;
  8564. const {
  8565. params,
  8566. activeIndex,
  8567. slidesEl
  8568. } = swiper;
  8569. let activeIndexBuffer = activeIndex;
  8570. if (params.loop) {
  8571. activeIndexBuffer -= swiper.loopedSlides;
  8572. swiper.loopDestroy();
  8573. swiper.recalcSlides();
  8574. }
  8575. const baseLength = swiper.slides.length;
  8576. if (index <= 0) {
  8577. swiper.prependSlide(slides);
  8578. return;
  8579. }
  8580. if (index >= baseLength) {
  8581. swiper.appendSlide(slides);
  8582. return;
  8583. }
  8584. let newActiveIndex = activeIndexBuffer > index ? activeIndexBuffer + 1 : activeIndexBuffer;
  8585. const slidesBuffer = [];
  8586. for (let i = baseLength - 1; i >= index; i -= 1) {
  8587. const currentSlide = swiper.slides[i];
  8588. currentSlide.remove();
  8589. slidesBuffer.unshift(currentSlide);
  8590. }
  8591. if (typeof slides === 'object' && 'length' in slides) {
  8592. for (let i = 0; i < slides.length; i += 1) {
  8593. if (slides[i]) slidesEl.append(slides[i]);
  8594. }
  8595. newActiveIndex = activeIndexBuffer > index ? activeIndexBuffer + slides.length : activeIndexBuffer;
  8596. } else {
  8597. slidesEl.append(slides);
  8598. }
  8599. for (let i = 0; i < slidesBuffer.length; i += 1) {
  8600. slidesEl.append(slidesBuffer[i]);
  8601. }
  8602. swiper.recalcSlides();
  8603. if (params.loop) {
  8604. swiper.loopCreate();
  8605. }
  8606. if (!params.observer || swiper.isElement) {
  8607. swiper.update();
  8608. }
  8609. if (params.loop) {
  8610. swiper.slideTo(newActiveIndex + swiper.loopedSlides, 0, false);
  8611. } else {
  8612. swiper.slideTo(newActiveIndex, 0, false);
  8613. }
  8614. }
  8615. function removeSlide(slidesIndexes) {
  8616. const swiper = this;
  8617. const {
  8618. params,
  8619. activeIndex
  8620. } = swiper;
  8621. let activeIndexBuffer = activeIndex;
  8622. if (params.loop) {
  8623. activeIndexBuffer -= swiper.loopedSlides;
  8624. swiper.loopDestroy();
  8625. }
  8626. let newActiveIndex = activeIndexBuffer;
  8627. let indexToRemove;
  8628. if (typeof slidesIndexes === 'object' && 'length' in slidesIndexes) {
  8629. for (let i = 0; i < slidesIndexes.length; i += 1) {
  8630. indexToRemove = slidesIndexes[i];
  8631. if (swiper.slides[indexToRemove]) swiper.slides[indexToRemove].remove();
  8632. if (indexToRemove < newActiveIndex) newActiveIndex -= 1;
  8633. }
  8634. newActiveIndex = Math.max(newActiveIndex, 0);
  8635. } else {
  8636. indexToRemove = slidesIndexes;
  8637. if (swiper.slides[indexToRemove]) swiper.slides[indexToRemove].remove();
  8638. if (indexToRemove < newActiveIndex) newActiveIndex -= 1;
  8639. newActiveIndex = Math.max(newActiveIndex, 0);
  8640. }
  8641. swiper.recalcSlides();
  8642. if (params.loop) {
  8643. swiper.loopCreate();
  8644. }
  8645. if (!params.observer || swiper.isElement) {
  8646. swiper.update();
  8647. }
  8648. if (params.loop) {
  8649. swiper.slideTo(newActiveIndex + swiper.loopedSlides, 0, false);
  8650. } else {
  8651. swiper.slideTo(newActiveIndex, 0, false);
  8652. }
  8653. }
  8654. function removeAllSlides() {
  8655. const swiper = this;
  8656. const slidesIndexes = [];
  8657. for (let i = 0; i < swiper.slides.length; i += 1) {
  8658. slidesIndexes.push(i);
  8659. }
  8660. swiper.removeSlide(slidesIndexes);
  8661. }
  8662. function Manipulation(_ref) {
  8663. let {
  8664. swiper
  8665. } = _ref;
  8666. Object.assign(swiper, {
  8667. appendSlide: appendSlide.bind(swiper),
  8668. prependSlide: prependSlide.bind(swiper),
  8669. addSlide: addSlide.bind(swiper),
  8670. removeSlide: removeSlide.bind(swiper),
  8671. removeAllSlides: removeAllSlides.bind(swiper)
  8672. });
  8673. }
  8674. function effectInit(params) {
  8675. const {
  8676. effect,
  8677. swiper,
  8678. on,
  8679. setTranslate,
  8680. setTransition,
  8681. overwriteParams,
  8682. perspective,
  8683. recreateShadows,
  8684. getEffectParams
  8685. } = params;
  8686. on('beforeInit', () => {
  8687. if (swiper.params.effect !== effect) return;
  8688. swiper.classNames.push(`${swiper.params.containerModifierClass}${effect}`);
  8689. if (perspective && perspective()) {
  8690. swiper.classNames.push(`${swiper.params.containerModifierClass}3d`);
  8691. }
  8692. const overwriteParamsResult = overwriteParams ? overwriteParams() : {};
  8693. Object.assign(swiper.params, overwriteParamsResult);
  8694. Object.assign(swiper.originalParams, overwriteParamsResult);
  8695. });
  8696. on('setTranslate', () => {
  8697. if (swiper.params.effect !== effect) return;
  8698. setTranslate();
  8699. });
  8700. on('setTransition', (_s, duration) => {
  8701. if (swiper.params.effect !== effect) return;
  8702. setTransition(duration);
  8703. });
  8704. on('transitionEnd', () => {
  8705. if (swiper.params.effect !== effect) return;
  8706. if (recreateShadows) {
  8707. if (!getEffectParams || !getEffectParams().slideShadows) return;
  8708. // remove shadows
  8709. swiper.slides.forEach(slideEl => {
  8710. slideEl.querySelectorAll('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').forEach(shadowEl => shadowEl.remove());
  8711. });
  8712. // create new one
  8713. recreateShadows();
  8714. }
  8715. });
  8716. let requireUpdateOnVirtual;
  8717. on('virtualUpdate', () => {
  8718. if (swiper.params.effect !== effect) return;
  8719. if (!swiper.slides.length) {
  8720. requireUpdateOnVirtual = true;
  8721. }
  8722. requestAnimationFrame(() => {
  8723. if (requireUpdateOnVirtual && swiper.slides && swiper.slides.length) {
  8724. setTranslate();
  8725. requireUpdateOnVirtual = false;
  8726. }
  8727. });
  8728. });
  8729. }
  8730. function effectTarget(effectParams, slideEl) {
  8731. const transformEl = getSlideTransformEl(slideEl);
  8732. if (transformEl !== slideEl) {
  8733. transformEl.style.backfaceVisibility = 'hidden';
  8734. transformEl.style['-webkit-backface-visibility'] = 'hidden';
  8735. }
  8736. return transformEl;
  8737. }
  8738. function effectVirtualTransitionEnd(_ref) {
  8739. let {
  8740. swiper,
  8741. duration,
  8742. transformElements,
  8743. allSlides
  8744. } = _ref;
  8745. const {
  8746. activeIndex
  8747. } = swiper;
  8748. const getSlide = el => {
  8749. if (!el.parentElement) {
  8750. // assume shadow root
  8751. const slide = swiper.slides.filter(slideEl => slideEl.shadowRoot && slideEl.shadowRoot === el.parentNode)[0];
  8752. return slide;
  8753. }
  8754. return el.parentElement;
  8755. };
  8756. if (swiper.params.virtualTranslate && duration !== 0) {
  8757. let eventTriggered = false;
  8758. let transitionEndTarget;
  8759. if (allSlides) {
  8760. transitionEndTarget = transformElements;
  8761. } else {
  8762. transitionEndTarget = transformElements.filter(transformEl => {
  8763. const el = transformEl.classList.contains('swiper-slide-transform') ? getSlide(transformEl) : transformEl;
  8764. return swiper.getSlideIndex(el) === activeIndex;
  8765. });
  8766. }
  8767. transitionEndTarget.forEach(el => {
  8768. elementTransitionEnd(el, () => {
  8769. if (eventTriggered) return;
  8770. if (!swiper || swiper.destroyed) return;
  8771. eventTriggered = true;
  8772. swiper.animating = false;
  8773. const evt = new window.CustomEvent('transitionend', {
  8774. bubbles: true,
  8775. cancelable: true
  8776. });
  8777. swiper.wrapperEl.dispatchEvent(evt);
  8778. });
  8779. });
  8780. }
  8781. }
  8782. function EffectFade(_ref) {
  8783. let {
  8784. swiper,
  8785. extendParams,
  8786. on
  8787. } = _ref;
  8788. extendParams({
  8789. fadeEffect: {
  8790. crossFade: false
  8791. }
  8792. });
  8793. const setTranslate = () => {
  8794. const {
  8795. slides
  8796. } = swiper;
  8797. const params = swiper.params.fadeEffect;
  8798. for (let i = 0; i < slides.length; i += 1) {
  8799. const slideEl = swiper.slides[i];
  8800. const offset = slideEl.swiperSlideOffset;
  8801. let tx = -offset;
  8802. if (!swiper.params.virtualTranslate) tx -= swiper.translate;
  8803. let ty = 0;
  8804. if (!swiper.isHorizontal()) {
  8805. ty = tx;
  8806. tx = 0;
  8807. }
  8808. const slideOpacity = swiper.params.fadeEffect.crossFade ? Math.max(1 - Math.abs(slideEl.progress), 0) : 1 + Math.min(Math.max(slideEl.progress, -1), 0);
  8809. const targetEl = effectTarget(params, slideEl);
  8810. targetEl.style.opacity = slideOpacity;
  8811. targetEl.style.transform = `translate3d(${tx}px, ${ty}px, 0px)`;
  8812. }
  8813. };
  8814. const setTransition = duration => {
  8815. const transformElements = swiper.slides.map(slideEl => getSlideTransformEl(slideEl));
  8816. transformElements.forEach(el => {
  8817. el.style.transitionDuration = `${duration}ms`;
  8818. });
  8819. effectVirtualTransitionEnd({
  8820. swiper,
  8821. duration,
  8822. transformElements,
  8823. allSlides: true
  8824. });
  8825. };
  8826. effectInit({
  8827. effect: 'fade',
  8828. swiper,
  8829. on,
  8830. setTranslate,
  8831. setTransition,
  8832. overwriteParams: () => ({
  8833. slidesPerView: 1,
  8834. slidesPerGroup: 1,
  8835. watchSlidesProgress: true,
  8836. spaceBetween: 0,
  8837. virtualTranslate: !swiper.params.cssMode
  8838. })
  8839. });
  8840. }
  8841. function EffectCube(_ref) {
  8842. let {
  8843. swiper,
  8844. extendParams,
  8845. on
  8846. } = _ref;
  8847. extendParams({
  8848. cubeEffect: {
  8849. slideShadows: true,
  8850. shadow: true,
  8851. shadowOffset: 20,
  8852. shadowScale: 0.94
  8853. }
  8854. });
  8855. const createSlideShadows = (slideEl, progress, isHorizontal) => {
  8856. let shadowBefore = isHorizontal ? slideEl.querySelector('.swiper-slide-shadow-left') : slideEl.querySelector('.swiper-slide-shadow-top');
  8857. let shadowAfter = isHorizontal ? slideEl.querySelector('.swiper-slide-shadow-right') : slideEl.querySelector('.swiper-slide-shadow-bottom');
  8858. if (!shadowBefore) {
  8859. shadowBefore = createElement('div', `swiper-slide-shadow-cube swiper-slide-shadow-${isHorizontal ? 'left' : 'top'}`.split(' '));
  8860. slideEl.append(shadowBefore);
  8861. }
  8862. if (!shadowAfter) {
  8863. shadowAfter = createElement('div', `swiper-slide-shadow-cube swiper-slide-shadow-${isHorizontal ? 'right' : 'bottom'}`.split(' '));
  8864. slideEl.append(shadowAfter);
  8865. }
  8866. if (shadowBefore) shadowBefore.style.opacity = Math.max(-progress, 0);
  8867. if (shadowAfter) shadowAfter.style.opacity = Math.max(progress, 0);
  8868. };
  8869. const recreateShadows = () => {
  8870. // create new ones
  8871. const isHorizontal = swiper.isHorizontal();
  8872. swiper.slides.forEach(slideEl => {
  8873. const progress = Math.max(Math.min(slideEl.progress, 1), -1);
  8874. createSlideShadows(slideEl, progress, isHorizontal);
  8875. });
  8876. };
  8877. const setTranslate = () => {
  8878. const {
  8879. el,
  8880. wrapperEl,
  8881. slides,
  8882. width: swiperWidth,
  8883. height: swiperHeight,
  8884. rtlTranslate: rtl,
  8885. size: swiperSize,
  8886. browser
  8887. } = swiper;
  8888. const r = getRotateFix(swiper);
  8889. const params = swiper.params.cubeEffect;
  8890. const isHorizontal = swiper.isHorizontal();
  8891. const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
  8892. let wrapperRotate = 0;
  8893. let cubeShadowEl;
  8894. if (params.shadow) {
  8895. if (isHorizontal) {
  8896. cubeShadowEl = swiper.wrapperEl.querySelector('.swiper-cube-shadow');
  8897. if (!cubeShadowEl) {
  8898. cubeShadowEl = createElement('div', 'swiper-cube-shadow');
  8899. swiper.wrapperEl.append(cubeShadowEl);
  8900. }
  8901. cubeShadowEl.style.height = `${swiperWidth}px`;
  8902. } else {
  8903. cubeShadowEl = el.querySelector('.swiper-cube-shadow');
  8904. if (!cubeShadowEl) {
  8905. cubeShadowEl = createElement('div', 'swiper-cube-shadow');
  8906. el.append(cubeShadowEl);
  8907. }
  8908. }
  8909. }
  8910. for (let i = 0; i < slides.length; i += 1) {
  8911. const slideEl = slides[i];
  8912. let slideIndex = i;
  8913. if (isVirtual) {
  8914. slideIndex = parseInt(slideEl.getAttribute('data-swiper-slide-index'), 10);
  8915. }
  8916. let slideAngle = slideIndex * 90;
  8917. let round = Math.floor(slideAngle / 360);
  8918. if (rtl) {
  8919. slideAngle = -slideAngle;
  8920. round = Math.floor(-slideAngle / 360);
  8921. }
  8922. const progress = Math.max(Math.min(slideEl.progress, 1), -1);
  8923. let tx = 0;
  8924. let ty = 0;
  8925. let tz = 0;
  8926. if (slideIndex % 4 === 0) {
  8927. tx = -round * 4 * swiperSize;
  8928. tz = 0;
  8929. } else if ((slideIndex - 1) % 4 === 0) {
  8930. tx = 0;
  8931. tz = -round * 4 * swiperSize;
  8932. } else if ((slideIndex - 2) % 4 === 0) {
  8933. tx = swiperSize + round * 4 * swiperSize;
  8934. tz = swiperSize;
  8935. } else if ((slideIndex - 3) % 4 === 0) {
  8936. tx = -swiperSize;
  8937. tz = 3 * swiperSize + swiperSize * 4 * round;
  8938. }
  8939. if (rtl) {
  8940. tx = -tx;
  8941. }
  8942. if (!isHorizontal) {
  8943. ty = tx;
  8944. tx = 0;
  8945. }
  8946. const transform = `rotateX(${r(isHorizontal ? 0 : -slideAngle)}deg) rotateY(${r(isHorizontal ? slideAngle : 0)}deg) translate3d(${tx}px, ${ty}px, ${tz}px)`;
  8947. if (progress <= 1 && progress > -1) {
  8948. wrapperRotate = slideIndex * 90 + progress * 90;
  8949. if (rtl) wrapperRotate = -slideIndex * 90 - progress * 90;
  8950. }
  8951. slideEl.style.transform = transform;
  8952. if (params.slideShadows) {
  8953. createSlideShadows(slideEl, progress, isHorizontal);
  8954. }
  8955. }
  8956. wrapperEl.style.transformOrigin = `50% 50% -${swiperSize / 2}px`;
  8957. wrapperEl.style['-webkit-transform-origin'] = `50% 50% -${swiperSize / 2}px`;
  8958. if (params.shadow) {
  8959. if (isHorizontal) {
  8960. cubeShadowEl.style.transform = `translate3d(0px, ${swiperWidth / 2 + params.shadowOffset}px, ${-swiperWidth / 2}px) rotateX(89.99deg) rotateZ(0deg) scale(${params.shadowScale})`;
  8961. } else {
  8962. const shadowAngle = Math.abs(wrapperRotate) - Math.floor(Math.abs(wrapperRotate) / 90) * 90;
  8963. const multiplier = 1.5 - (Math.sin(shadowAngle * 2 * Math.PI / 360) / 2 + Math.cos(shadowAngle * 2 * Math.PI / 360) / 2);
  8964. const scale1 = params.shadowScale;
  8965. const scale2 = params.shadowScale / multiplier;
  8966. const offset = params.shadowOffset;
  8967. cubeShadowEl.style.transform = `scale3d(${scale1}, 1, ${scale2}) translate3d(0px, ${swiperHeight / 2 + offset}px, ${-swiperHeight / 2 / scale2}px) rotateX(-89.99deg)`;
  8968. }
  8969. }
  8970. const zFactor = (browser.isSafari || browser.isWebView) && browser.needPerspectiveFix ? -swiperSize / 2 : 0;
  8971. wrapperEl.style.transform = `translate3d(0px,0,${zFactor}px) rotateX(${r(swiper.isHorizontal() ? 0 : wrapperRotate)}deg) rotateY(${r(swiper.isHorizontal() ? -wrapperRotate : 0)}deg)`;
  8972. wrapperEl.style.setProperty('--swiper-cube-translate-z', `${zFactor}px`);
  8973. };
  8974. const setTransition = duration => {
  8975. const {
  8976. el,
  8977. slides
  8978. } = swiper;
  8979. slides.forEach(slideEl => {
  8980. slideEl.style.transitionDuration = `${duration}ms`;
  8981. slideEl.querySelectorAll('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').forEach(subEl => {
  8982. subEl.style.transitionDuration = `${duration}ms`;
  8983. });
  8984. });
  8985. if (swiper.params.cubeEffect.shadow && !swiper.isHorizontal()) {
  8986. const shadowEl = el.querySelector('.swiper-cube-shadow');
  8987. if (shadowEl) shadowEl.style.transitionDuration = `${duration}ms`;
  8988. }
  8989. };
  8990. effectInit({
  8991. effect: 'cube',
  8992. swiper,
  8993. on,
  8994. setTranslate,
  8995. setTransition,
  8996. recreateShadows,
  8997. getEffectParams: () => swiper.params.cubeEffect,
  8998. perspective: () => true,
  8999. overwriteParams: () => ({
  9000. slidesPerView: 1,
  9001. slidesPerGroup: 1,
  9002. watchSlidesProgress: true,
  9003. resistanceRatio: 0,
  9004. spaceBetween: 0,
  9005. centeredSlides: false,
  9006. virtualTranslate: true
  9007. })
  9008. });
  9009. }
  9010. function createShadow(suffix, slideEl, side) {
  9011. const shadowClass = `swiper-slide-shadow${side ? `-${side}` : ''}${suffix ? ` swiper-slide-shadow-${suffix}` : ''}`;
  9012. const shadowContainer = getSlideTransformEl(slideEl);
  9013. let shadowEl = shadowContainer.querySelector(`.${shadowClass.split(' ').join('.')}`);
  9014. if (!shadowEl) {
  9015. shadowEl = createElement('div', shadowClass.split(' '));
  9016. shadowContainer.append(shadowEl);
  9017. }
  9018. return shadowEl;
  9019. }
  9020. function EffectFlip(_ref) {
  9021. let {
  9022. swiper,
  9023. extendParams,
  9024. on
  9025. } = _ref;
  9026. extendParams({
  9027. flipEffect: {
  9028. slideShadows: true,
  9029. limitRotation: true
  9030. }
  9031. });
  9032. const createSlideShadows = (slideEl, progress) => {
  9033. let shadowBefore = swiper.isHorizontal() ? slideEl.querySelector('.swiper-slide-shadow-left') : slideEl.querySelector('.swiper-slide-shadow-top');
  9034. let shadowAfter = swiper.isHorizontal() ? slideEl.querySelector('.swiper-slide-shadow-right') : slideEl.querySelector('.swiper-slide-shadow-bottom');
  9035. if (!shadowBefore) {
  9036. shadowBefore = createShadow('flip', slideEl, swiper.isHorizontal() ? 'left' : 'top');
  9037. }
  9038. if (!shadowAfter) {
  9039. shadowAfter = createShadow('flip', slideEl, swiper.isHorizontal() ? 'right' : 'bottom');
  9040. }
  9041. if (shadowBefore) shadowBefore.style.opacity = Math.max(-progress, 0);
  9042. if (shadowAfter) shadowAfter.style.opacity = Math.max(progress, 0);
  9043. };
  9044. const recreateShadows = () => {
  9045. // Set shadows
  9046. swiper.params.flipEffect;
  9047. swiper.slides.forEach(slideEl => {
  9048. let progress = slideEl.progress;
  9049. if (swiper.params.flipEffect.limitRotation) {
  9050. progress = Math.max(Math.min(slideEl.progress, 1), -1);
  9051. }
  9052. createSlideShadows(slideEl, progress);
  9053. });
  9054. };
  9055. const setTranslate = () => {
  9056. const {
  9057. slides,
  9058. rtlTranslate: rtl
  9059. } = swiper;
  9060. const params = swiper.params.flipEffect;
  9061. const rotateFix = getRotateFix(swiper);
  9062. for (let i = 0; i < slides.length; i += 1) {
  9063. const slideEl = slides[i];
  9064. let progress = slideEl.progress;
  9065. if (swiper.params.flipEffect.limitRotation) {
  9066. progress = Math.max(Math.min(slideEl.progress, 1), -1);
  9067. }
  9068. const offset = slideEl.swiperSlideOffset;
  9069. const rotate = -180 * progress;
  9070. let rotateY = rotate;
  9071. let rotateX = 0;
  9072. let tx = swiper.params.cssMode ? -offset - swiper.translate : -offset;
  9073. let ty = 0;
  9074. if (!swiper.isHorizontal()) {
  9075. ty = tx;
  9076. tx = 0;
  9077. rotateX = -rotateY;
  9078. rotateY = 0;
  9079. } else if (rtl) {
  9080. rotateY = -rotateY;
  9081. }
  9082. slideEl.style.zIndex = -Math.abs(Math.round(progress)) + slides.length;
  9083. if (params.slideShadows) {
  9084. createSlideShadows(slideEl, progress);
  9085. }
  9086. const transform = `translate3d(${tx}px, ${ty}px, 0px) rotateX(${rotateFix(rotateX)}deg) rotateY(${rotateFix(rotateY)}deg)`;
  9087. const targetEl = effectTarget(params, slideEl);
  9088. targetEl.style.transform = transform;
  9089. }
  9090. };
  9091. const setTransition = duration => {
  9092. const transformElements = swiper.slides.map(slideEl => getSlideTransformEl(slideEl));
  9093. transformElements.forEach(el => {
  9094. el.style.transitionDuration = `${duration}ms`;
  9095. el.querySelectorAll('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').forEach(shadowEl => {
  9096. shadowEl.style.transitionDuration = `${duration}ms`;
  9097. });
  9098. });
  9099. effectVirtualTransitionEnd({
  9100. swiper,
  9101. duration,
  9102. transformElements
  9103. });
  9104. };
  9105. effectInit({
  9106. effect: 'flip',
  9107. swiper,
  9108. on,
  9109. setTranslate,
  9110. setTransition,
  9111. recreateShadows,
  9112. getEffectParams: () => swiper.params.flipEffect,
  9113. perspective: () => true,
  9114. overwriteParams: () => ({
  9115. slidesPerView: 1,
  9116. slidesPerGroup: 1,
  9117. watchSlidesProgress: true,
  9118. spaceBetween: 0,
  9119. virtualTranslate: !swiper.params.cssMode
  9120. })
  9121. });
  9122. }
  9123. function EffectCoverflow(_ref) {
  9124. let {
  9125. swiper,
  9126. extendParams,
  9127. on
  9128. } = _ref;
  9129. extendParams({
  9130. coverflowEffect: {
  9131. rotate: 50,
  9132. stretch: 0,
  9133. depth: 100,
  9134. scale: 1,
  9135. modifier: 1,
  9136. slideShadows: true
  9137. }
  9138. });
  9139. const setTranslate = () => {
  9140. const {
  9141. width: swiperWidth,
  9142. height: swiperHeight,
  9143. slides,
  9144. slidesSizesGrid
  9145. } = swiper;
  9146. const params = swiper.params.coverflowEffect;
  9147. const isHorizontal = swiper.isHorizontal();
  9148. const transform = swiper.translate;
  9149. const center = isHorizontal ? -transform + swiperWidth / 2 : -transform + swiperHeight / 2;
  9150. const rotate = isHorizontal ? params.rotate : -params.rotate;
  9151. const translate = params.depth;
  9152. const r = getRotateFix(swiper);
  9153. // Each slide offset from center
  9154. for (let i = 0, length = slides.length; i < length; i += 1) {
  9155. const slideEl = slides[i];
  9156. const slideSize = slidesSizesGrid[i];
  9157. const slideOffset = slideEl.swiperSlideOffset;
  9158. const centerOffset = (center - slideOffset - slideSize / 2) / slideSize;
  9159. const offsetMultiplier = typeof params.modifier === 'function' ? params.modifier(centerOffset) : centerOffset * params.modifier;
  9160. let rotateY = isHorizontal ? rotate * offsetMultiplier : 0;
  9161. let rotateX = isHorizontal ? 0 : rotate * offsetMultiplier;
  9162. // var rotateZ = 0
  9163. let translateZ = -translate * Math.abs(offsetMultiplier);
  9164. let stretch = params.stretch;
  9165. // Allow percentage to make a relative stretch for responsive sliders
  9166. if (typeof stretch === 'string' && stretch.indexOf('%') !== -1) {
  9167. stretch = parseFloat(params.stretch) / 100 * slideSize;
  9168. }
  9169. let translateY = isHorizontal ? 0 : stretch * offsetMultiplier;
  9170. let translateX = isHorizontal ? stretch * offsetMultiplier : 0;
  9171. let scale = 1 - (1 - params.scale) * Math.abs(offsetMultiplier);
  9172. // Fix for ultra small values
  9173. if (Math.abs(translateX) < 0.001) translateX = 0;
  9174. if (Math.abs(translateY) < 0.001) translateY = 0;
  9175. if (Math.abs(translateZ) < 0.001) translateZ = 0;
  9176. if (Math.abs(rotateY) < 0.001) rotateY = 0;
  9177. if (Math.abs(rotateX) < 0.001) rotateX = 0;
  9178. if (Math.abs(scale) < 0.001) scale = 0;
  9179. const slideTransform = `translate3d(${translateX}px,${translateY}px,${translateZ}px) rotateX(${r(rotateX)}deg) rotateY(${r(rotateY)}deg) scale(${scale})`;
  9180. const targetEl = effectTarget(params, slideEl);
  9181. targetEl.style.transform = slideTransform;
  9182. slideEl.style.zIndex = -Math.abs(Math.round(offsetMultiplier)) + 1;
  9183. if (params.slideShadows) {
  9184. // Set shadows
  9185. let shadowBeforeEl = isHorizontal ? slideEl.querySelector('.swiper-slide-shadow-left') : slideEl.querySelector('.swiper-slide-shadow-top');
  9186. let shadowAfterEl = isHorizontal ? slideEl.querySelector('.swiper-slide-shadow-right') : slideEl.querySelector('.swiper-slide-shadow-bottom');
  9187. if (!shadowBeforeEl) {
  9188. shadowBeforeEl = createShadow('coverflow', slideEl, isHorizontal ? 'left' : 'top');
  9189. }
  9190. if (!shadowAfterEl) {
  9191. shadowAfterEl = createShadow('coverflow', slideEl, isHorizontal ? 'right' : 'bottom');
  9192. }
  9193. if (shadowBeforeEl) shadowBeforeEl.style.opacity = offsetMultiplier > 0 ? offsetMultiplier : 0;
  9194. if (shadowAfterEl) shadowAfterEl.style.opacity = -offsetMultiplier > 0 ? -offsetMultiplier : 0;
  9195. }
  9196. }
  9197. };
  9198. const setTransition = duration => {
  9199. const transformElements = swiper.slides.map(slideEl => getSlideTransformEl(slideEl));
  9200. transformElements.forEach(el => {
  9201. el.style.transitionDuration = `${duration}ms`;
  9202. el.querySelectorAll('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').forEach(shadowEl => {
  9203. shadowEl.style.transitionDuration = `${duration}ms`;
  9204. });
  9205. });
  9206. };
  9207. effectInit({
  9208. effect: 'coverflow',
  9209. swiper,
  9210. on,
  9211. setTranslate,
  9212. setTransition,
  9213. perspective: () => true,
  9214. overwriteParams: () => ({
  9215. watchSlidesProgress: true
  9216. })
  9217. });
  9218. }
  9219. function EffectCreative(_ref) {
  9220. let {
  9221. swiper,
  9222. extendParams,
  9223. on
  9224. } = _ref;
  9225. extendParams({
  9226. creativeEffect: {
  9227. limitProgress: 1,
  9228. shadowPerProgress: false,
  9229. progressMultiplier: 1,
  9230. perspective: true,
  9231. prev: {
  9232. translate: [0, 0, 0],
  9233. rotate: [0, 0, 0],
  9234. opacity: 1,
  9235. scale: 1
  9236. },
  9237. next: {
  9238. translate: [0, 0, 0],
  9239. rotate: [0, 0, 0],
  9240. opacity: 1,
  9241. scale: 1
  9242. }
  9243. }
  9244. });
  9245. const getTranslateValue = value => {
  9246. if (typeof value === 'string') return value;
  9247. return `${value}px`;
  9248. };
  9249. const setTranslate = () => {
  9250. const {
  9251. slides,
  9252. wrapperEl,
  9253. slidesSizesGrid
  9254. } = swiper;
  9255. const params = swiper.params.creativeEffect;
  9256. const {
  9257. progressMultiplier: multiplier
  9258. } = params;
  9259. const isCenteredSlides = swiper.params.centeredSlides;
  9260. const rotateFix = getRotateFix(swiper);
  9261. if (isCenteredSlides) {
  9262. const margin = slidesSizesGrid[0] / 2 - swiper.params.slidesOffsetBefore || 0;
  9263. wrapperEl.style.transform = `translateX(calc(50% - ${margin}px))`;
  9264. }
  9265. for (let i = 0; i < slides.length; i += 1) {
  9266. const slideEl = slides[i];
  9267. const slideProgress = slideEl.progress;
  9268. const progress = Math.min(Math.max(slideEl.progress, -params.limitProgress), params.limitProgress);
  9269. let originalProgress = progress;
  9270. if (!isCenteredSlides) {
  9271. originalProgress = Math.min(Math.max(slideEl.originalProgress, -params.limitProgress), params.limitProgress);
  9272. }
  9273. const offset = slideEl.swiperSlideOffset;
  9274. const t = [swiper.params.cssMode ? -offset - swiper.translate : -offset, 0, 0];
  9275. const r = [0, 0, 0];
  9276. let custom = false;
  9277. if (!swiper.isHorizontal()) {
  9278. t[1] = t[0];
  9279. t[0] = 0;
  9280. }
  9281. let data = {
  9282. translate: [0, 0, 0],
  9283. rotate: [0, 0, 0],
  9284. scale: 1,
  9285. opacity: 1
  9286. };
  9287. if (progress < 0) {
  9288. data = params.next;
  9289. custom = true;
  9290. } else if (progress > 0) {
  9291. data = params.prev;
  9292. custom = true;
  9293. }
  9294. // set translate
  9295. t.forEach((value, index) => {
  9296. t[index] = `calc(${value}px + (${getTranslateValue(data.translate[index])} * ${Math.abs(progress * multiplier)}))`;
  9297. });
  9298. // set rotates
  9299. r.forEach((value, index) => {
  9300. let val = data.rotate[index] * Math.abs(progress * multiplier);
  9301. r[index] = val;
  9302. });
  9303. slideEl.style.zIndex = -Math.abs(Math.round(slideProgress)) + slides.length;
  9304. const translateString = t.join(', ');
  9305. const rotateString = `rotateX(${rotateFix(r[0])}deg) rotateY(${rotateFix(r[1])}deg) rotateZ(${rotateFix(r[2])}deg)`;
  9306. const scaleString = originalProgress < 0 ? `scale(${1 + (1 - data.scale) * originalProgress * multiplier})` : `scale(${1 - (1 - data.scale) * originalProgress * multiplier})`;
  9307. const opacityString = originalProgress < 0 ? 1 + (1 - data.opacity) * originalProgress * multiplier : 1 - (1 - data.opacity) * originalProgress * multiplier;
  9308. const transform = `translate3d(${translateString}) ${rotateString} ${scaleString}`;
  9309. // Set shadows
  9310. if (custom && data.shadow || !custom) {
  9311. let shadowEl = slideEl.querySelector('.swiper-slide-shadow');
  9312. if (!shadowEl && data.shadow) {
  9313. shadowEl = createShadow('creative', slideEl);
  9314. }
  9315. if (shadowEl) {
  9316. const shadowOpacity = params.shadowPerProgress ? progress * (1 / params.limitProgress) : progress;
  9317. shadowEl.style.opacity = Math.min(Math.max(Math.abs(shadowOpacity), 0), 1);
  9318. }
  9319. }
  9320. const targetEl = effectTarget(params, slideEl);
  9321. targetEl.style.transform = transform;
  9322. targetEl.style.opacity = opacityString;
  9323. if (data.origin) {
  9324. targetEl.style.transformOrigin = data.origin;
  9325. }
  9326. }
  9327. };
  9328. const setTransition = duration => {
  9329. const transformElements = swiper.slides.map(slideEl => getSlideTransformEl(slideEl));
  9330. transformElements.forEach(el => {
  9331. el.style.transitionDuration = `${duration}ms`;
  9332. el.querySelectorAll('.swiper-slide-shadow').forEach(shadowEl => {
  9333. shadowEl.style.transitionDuration = `${duration}ms`;
  9334. });
  9335. });
  9336. effectVirtualTransitionEnd({
  9337. swiper,
  9338. duration,
  9339. transformElements,
  9340. allSlides: true
  9341. });
  9342. };
  9343. effectInit({
  9344. effect: 'creative',
  9345. swiper,
  9346. on,
  9347. setTranslate,
  9348. setTransition,
  9349. perspective: () => swiper.params.creativeEffect.perspective,
  9350. overwriteParams: () => ({
  9351. watchSlidesProgress: true,
  9352. virtualTranslate: !swiper.params.cssMode
  9353. })
  9354. });
  9355. }
  9356. function EffectCards(_ref) {
  9357. let {
  9358. swiper,
  9359. extendParams,
  9360. on
  9361. } = _ref;
  9362. extendParams({
  9363. cardsEffect: {
  9364. slideShadows: true,
  9365. rotate: true,
  9366. perSlideRotate: 2,
  9367. perSlideOffset: 8
  9368. }
  9369. });
  9370. const setTranslate = () => {
  9371. const {
  9372. slides,
  9373. activeIndex,
  9374. rtlTranslate: rtl
  9375. } = swiper;
  9376. const params = swiper.params.cardsEffect;
  9377. const {
  9378. startTranslate,
  9379. isTouched
  9380. } = swiper.touchEventsData;
  9381. const currentTranslate = rtl ? -swiper.translate : swiper.translate;
  9382. for (let i = 0; i < slides.length; i += 1) {
  9383. const slideEl = slides[i];
  9384. const slideProgress = slideEl.progress;
  9385. const progress = Math.min(Math.max(slideProgress, -4), 4);
  9386. let offset = slideEl.swiperSlideOffset;
  9387. if (swiper.params.centeredSlides && !swiper.params.cssMode) {
  9388. swiper.wrapperEl.style.transform = `translateX(${swiper.minTranslate()}px)`;
  9389. }
  9390. if (swiper.params.centeredSlides && swiper.params.cssMode) {
  9391. offset -= slides[0].swiperSlideOffset;
  9392. }
  9393. let tX = swiper.params.cssMode ? -offset - swiper.translate : -offset;
  9394. let tY = 0;
  9395. const tZ = -100 * Math.abs(progress);
  9396. let scale = 1;
  9397. let rotate = -params.perSlideRotate * progress;
  9398. let tXAdd = params.perSlideOffset - Math.abs(progress) * 0.75;
  9399. const slideIndex = swiper.virtual && swiper.params.virtual.enabled ? swiper.virtual.from + i : i;
  9400. const isSwipeToNext = (slideIndex === activeIndex || slideIndex === activeIndex - 1) && progress > 0 && progress < 1 && (isTouched || swiper.params.cssMode) && currentTranslate < startTranslate;
  9401. const isSwipeToPrev = (slideIndex === activeIndex || slideIndex === activeIndex + 1) && progress < 0 && progress > -1 && (isTouched || swiper.params.cssMode) && currentTranslate > startTranslate;
  9402. if (isSwipeToNext || isSwipeToPrev) {
  9403. const subProgress = (1 - Math.abs((Math.abs(progress) - 0.5) / 0.5)) ** 0.5;
  9404. rotate += -28 * progress * subProgress;
  9405. scale += -0.5 * subProgress;
  9406. tXAdd += 96 * subProgress;
  9407. tY = `${-25 * subProgress * Math.abs(progress)}%`;
  9408. }
  9409. if (progress < 0) {
  9410. // next
  9411. tX = `calc(${tX}px ${rtl ? '-' : '+'} (${tXAdd * Math.abs(progress)}%))`;
  9412. } else if (progress > 0) {
  9413. // prev
  9414. tX = `calc(${tX}px ${rtl ? '-' : '+'} (-${tXAdd * Math.abs(progress)}%))`;
  9415. } else {
  9416. tX = `${tX}px`;
  9417. }
  9418. if (!swiper.isHorizontal()) {
  9419. const prevY = tY;
  9420. tY = tX;
  9421. tX = prevY;
  9422. }
  9423. const scaleString = progress < 0 ? `${1 + (1 - scale) * progress}` : `${1 - (1 - scale) * progress}`;
  9424. /* eslint-disable */
  9425. const transform = `
  9426. translate3d(${tX}, ${tY}, ${tZ}px)
  9427. rotateZ(${params.rotate ? rtl ? -rotate : rotate : 0}deg)
  9428. scale(${scaleString})
  9429. `;
  9430. /* eslint-enable */
  9431. if (params.slideShadows) {
  9432. // Set shadows
  9433. let shadowEl = slideEl.querySelector('.swiper-slide-shadow');
  9434. if (!shadowEl) {
  9435. shadowEl = createShadow('cards', slideEl);
  9436. }
  9437. if (shadowEl) shadowEl.style.opacity = Math.min(Math.max((Math.abs(progress) - 0.5) / 0.5, 0), 1);
  9438. }
  9439. slideEl.style.zIndex = -Math.abs(Math.round(slideProgress)) + slides.length;
  9440. const targetEl = effectTarget(params, slideEl);
  9441. targetEl.style.transform = transform;
  9442. }
  9443. };
  9444. const setTransition = duration => {
  9445. const transformElements = swiper.slides.map(slideEl => getSlideTransformEl(slideEl));
  9446. transformElements.forEach(el => {
  9447. el.style.transitionDuration = `${duration}ms`;
  9448. el.querySelectorAll('.swiper-slide-shadow').forEach(shadowEl => {
  9449. shadowEl.style.transitionDuration = `${duration}ms`;
  9450. });
  9451. });
  9452. effectVirtualTransitionEnd({
  9453. swiper,
  9454. duration,
  9455. transformElements
  9456. });
  9457. };
  9458. effectInit({
  9459. effect: 'cards',
  9460. swiper,
  9461. on,
  9462. setTranslate,
  9463. setTransition,
  9464. perspective: () => true,
  9465. overwriteParams: () => ({
  9466. watchSlidesProgress: true,
  9467. virtualTranslate: !swiper.params.cssMode
  9468. })
  9469. });
  9470. }
  9471. /**
  9472. * Swiper 11.1.15
  9473. * Most modern mobile touch slider and framework with hardware accelerated transitions
  9474. * https://swiperjs.com
  9475. *
  9476. * Copyright 2014-2024 Vladimir Kharlampidi
  9477. *
  9478. * Released under the MIT License
  9479. *
  9480. * Released on: November 18, 2024
  9481. */
  9482. // Swiper Class
  9483. const modules = [Virtual, Keyboard, Mousewheel, Navigation, Pagination, Scrollbar, Parallax, Zoom, Controller, A11y, History, HashNavigation, Autoplay, Thumb, freeMode, Grid, Manipulation, EffectFade, EffectCube, EffectFlip, EffectCoverflow, EffectCreative, EffectCards];
  9484. Swiper.use(modules);
  9485. return Swiper;
  9486. })();