swiper-bundle.js 324 KB

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