swiper-element.js 178 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020
  1. /**
  2. * Swiper Custom Element 11.2.10
  3. * Most modern mobile touch slider and framework with hardware accelerated transitions
  4. * https://swiperjs.com
  5. *
  6. * Copyright 2014-2025 Vladimir Kharlampidi
  7. *
  8. * Released under the MIT License
  9. *
  10. * Released on: June 28, 2025
  11. */
  12. (function () {
  13. 'use strict';
  14. /**
  15. * SSR Window 5.0.1
  16. * Better handling for window object in SSR environment
  17. * https://github.com/nolimits4web/ssr-window
  18. *
  19. * Copyright 2025, Vladimir Kharlampidi
  20. *
  21. * Licensed under MIT
  22. *
  23. * Released on: June 27, 2025
  24. */
  25. /* eslint-disable no-param-reassign */
  26. function isObject$2(obj) {
  27. return obj !== null && typeof obj === 'object' && 'constructor' in obj && obj.constructor === Object;
  28. }
  29. function extend$2(target, src) {
  30. if (target === void 0) {
  31. target = {};
  32. }
  33. if (src === void 0) {
  34. src = {};
  35. }
  36. const noExtend = ['__proto__', 'constructor', 'prototype'];
  37. Object.keys(src).filter(key => noExtend.indexOf(key) < 0).forEach(key => {
  38. if (typeof target[key] === 'undefined') target[key] = src[key];else if (isObject$2(src[key]) && isObject$2(target[key]) && Object.keys(src[key]).length > 0) {
  39. extend$2(target[key], src[key]);
  40. }
  41. });
  42. }
  43. const ssrDocument = {
  44. body: {},
  45. addEventListener() {},
  46. removeEventListener() {},
  47. activeElement: {
  48. blur() {},
  49. nodeName: ''
  50. },
  51. querySelector() {
  52. return null;
  53. },
  54. querySelectorAll() {
  55. return [];
  56. },
  57. getElementById() {
  58. return null;
  59. },
  60. createEvent() {
  61. return {
  62. initEvent() {}
  63. };
  64. },
  65. createElement() {
  66. return {
  67. children: [],
  68. childNodes: [],
  69. style: {},
  70. setAttribute() {},
  71. getElementsByTagName() {
  72. return [];
  73. }
  74. };
  75. },
  76. createElementNS() {
  77. return {};
  78. },
  79. importNode() {
  80. return null;
  81. },
  82. location: {
  83. hash: '',
  84. host: '',
  85. hostname: '',
  86. href: '',
  87. origin: '',
  88. pathname: '',
  89. protocol: '',
  90. search: ''
  91. }
  92. };
  93. function getDocument() {
  94. const doc = typeof document !== 'undefined' ? document : {};
  95. extend$2(doc, ssrDocument);
  96. return doc;
  97. }
  98. const ssrWindow = {
  99. document: ssrDocument,
  100. navigator: {
  101. userAgent: ''
  102. },
  103. location: {
  104. hash: '',
  105. host: '',
  106. hostname: '',
  107. href: '',
  108. origin: '',
  109. pathname: '',
  110. protocol: '',
  111. search: ''
  112. },
  113. history: {
  114. replaceState() {},
  115. pushState() {},
  116. go() {},
  117. back() {}
  118. },
  119. CustomEvent: function CustomEvent() {
  120. return this;
  121. },
  122. addEventListener() {},
  123. removeEventListener() {},
  124. getComputedStyle() {
  125. return {
  126. getPropertyValue() {
  127. return '';
  128. }
  129. };
  130. },
  131. Image() {},
  132. Date() {},
  133. screen: {},
  134. setTimeout() {},
  135. clearTimeout() {},
  136. matchMedia() {
  137. return {};
  138. },
  139. requestAnimationFrame(callback) {
  140. if (typeof setTimeout === 'undefined') {
  141. callback();
  142. return null;
  143. }
  144. return setTimeout(callback, 0);
  145. },
  146. cancelAnimationFrame(id) {
  147. if (typeof setTimeout === 'undefined') {
  148. return;
  149. }
  150. clearTimeout(id);
  151. }
  152. };
  153. function getWindow() {
  154. const win = typeof window !== 'undefined' ? window : {};
  155. extend$2(win, ssrWindow);
  156. return win;
  157. }
  158. function classesToTokens(classes) {
  159. if (classes === void 0) {
  160. classes = '';
  161. }
  162. return classes.trim().split(' ').filter(c => !!c.trim());
  163. }
  164. function deleteProps(obj) {
  165. const object = obj;
  166. Object.keys(object).forEach(key => {
  167. try {
  168. object[key] = null;
  169. } catch (e) {
  170. // no getter for object
  171. }
  172. try {
  173. delete object[key];
  174. } catch (e) {
  175. // something got wrong
  176. }
  177. });
  178. }
  179. function nextTick(callback, delay) {
  180. if (delay === void 0) {
  181. delay = 0;
  182. }
  183. return setTimeout(callback, delay);
  184. }
  185. function now() {
  186. return Date.now();
  187. }
  188. function getComputedStyle$1(el) {
  189. const window = getWindow();
  190. let style;
  191. if (window.getComputedStyle) {
  192. style = window.getComputedStyle(el, null);
  193. }
  194. if (!style && el.currentStyle) {
  195. style = el.currentStyle;
  196. }
  197. if (!style) {
  198. style = el.style;
  199. }
  200. return style;
  201. }
  202. function getTranslate(el, axis) {
  203. if (axis === void 0) {
  204. axis = 'x';
  205. }
  206. const window = getWindow();
  207. let matrix;
  208. let curTransform;
  209. let transformMatrix;
  210. const curStyle = getComputedStyle$1(el);
  211. if (window.WebKitCSSMatrix) {
  212. curTransform = curStyle.transform || curStyle.webkitTransform;
  213. if (curTransform.split(',').length > 6) {
  214. curTransform = curTransform.split(', ').map(a => a.replace(',', '.')).join(', ');
  215. }
  216. // Some old versions of Webkit choke when 'none' is passed; pass
  217. // empty string instead in this case
  218. transformMatrix = new window.WebKitCSSMatrix(curTransform === 'none' ? '' : curTransform);
  219. } else {
  220. transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue('transform').replace('translate(', 'matrix(1, 0, 0, 1,');
  221. matrix = transformMatrix.toString().split(',');
  222. }
  223. if (axis === 'x') {
  224. // Latest Chrome and webkits Fix
  225. if (window.WebKitCSSMatrix) curTransform = transformMatrix.m41;
  226. // Crazy IE10 Matrix
  227. else if (matrix.length === 16) curTransform = parseFloat(matrix[12]);
  228. // Normal Browsers
  229. else curTransform = parseFloat(matrix[4]);
  230. }
  231. if (axis === 'y') {
  232. // Latest Chrome and webkits Fix
  233. if (window.WebKitCSSMatrix) curTransform = transformMatrix.m42;
  234. // Crazy IE10 Matrix
  235. else if (matrix.length === 16) curTransform = parseFloat(matrix[13]);
  236. // Normal Browsers
  237. else curTransform = parseFloat(matrix[5]);
  238. }
  239. return curTransform || 0;
  240. }
  241. function isObject$1(o) {
  242. return typeof o === 'object' && o !== null && o.constructor && Object.prototype.toString.call(o).slice(8, -1) === 'Object';
  243. }
  244. function isNode(node) {
  245. // eslint-disable-next-line
  246. if (typeof window !== 'undefined' && typeof window.HTMLElement !== 'undefined') {
  247. return node instanceof HTMLElement;
  248. }
  249. return node && (node.nodeType === 1 || node.nodeType === 11);
  250. }
  251. function extend$1() {
  252. const to = Object(arguments.length <= 0 ? undefined : arguments[0]);
  253. const noExtend = ['__proto__', 'constructor', 'prototype'];
  254. for (let i = 1; i < arguments.length; i += 1) {
  255. const nextSource = i < 0 || arguments.length <= i ? undefined : arguments[i];
  256. if (nextSource !== undefined && nextSource !== null && !isNode(nextSource)) {
  257. const keysArray = Object.keys(Object(nextSource)).filter(key => noExtend.indexOf(key) < 0);
  258. for (let nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex += 1) {
  259. const nextKey = keysArray[nextIndex];
  260. const desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
  261. if (desc !== undefined && desc.enumerable) {
  262. if (isObject$1(to[nextKey]) && isObject$1(nextSource[nextKey])) {
  263. if (nextSource[nextKey].__swiper__) {
  264. to[nextKey] = nextSource[nextKey];
  265. } else {
  266. extend$1(to[nextKey], nextSource[nextKey]);
  267. }
  268. } else if (!isObject$1(to[nextKey]) && isObject$1(nextSource[nextKey])) {
  269. to[nextKey] = {};
  270. if (nextSource[nextKey].__swiper__) {
  271. to[nextKey] = nextSource[nextKey];
  272. } else {
  273. extend$1(to[nextKey], nextSource[nextKey]);
  274. }
  275. } else {
  276. to[nextKey] = nextSource[nextKey];
  277. }
  278. }
  279. }
  280. }
  281. }
  282. return to;
  283. }
  284. function setCSSProperty(el, varName, varValue) {
  285. el.style.setProperty(varName, varValue);
  286. }
  287. function animateCSSModeScroll(_ref) {
  288. let {
  289. swiper,
  290. targetPosition,
  291. side
  292. } = _ref;
  293. const window = getWindow();
  294. const startPosition = -swiper.translate;
  295. let startTime = null;
  296. let time;
  297. const duration = swiper.params.speed;
  298. swiper.wrapperEl.style.scrollSnapType = 'none';
  299. window.cancelAnimationFrame(swiper.cssModeFrameID);
  300. const dir = targetPosition > startPosition ? 'next' : 'prev';
  301. const isOutOfBound = (current, target) => {
  302. return dir === 'next' && current >= target || dir === 'prev' && current <= target;
  303. };
  304. const animate = () => {
  305. time = new Date().getTime();
  306. if (startTime === null) {
  307. startTime = time;
  308. }
  309. const progress = Math.max(Math.min((time - startTime) / duration, 1), 0);
  310. const easeProgress = 0.5 - Math.cos(progress * Math.PI) / 2;
  311. let currentPosition = startPosition + easeProgress * (targetPosition - startPosition);
  312. if (isOutOfBound(currentPosition, targetPosition)) {
  313. currentPosition = targetPosition;
  314. }
  315. swiper.wrapperEl.scrollTo({
  316. [side]: currentPosition
  317. });
  318. if (isOutOfBound(currentPosition, targetPosition)) {
  319. swiper.wrapperEl.style.overflow = 'hidden';
  320. swiper.wrapperEl.style.scrollSnapType = '';
  321. setTimeout(() => {
  322. swiper.wrapperEl.style.overflow = '';
  323. swiper.wrapperEl.scrollTo({
  324. [side]: currentPosition
  325. });
  326. });
  327. window.cancelAnimationFrame(swiper.cssModeFrameID);
  328. return;
  329. }
  330. swiper.cssModeFrameID = window.requestAnimationFrame(animate);
  331. };
  332. animate();
  333. }
  334. function elementChildren(element, selector) {
  335. if (selector === void 0) {
  336. selector = '';
  337. }
  338. const window = getWindow();
  339. const children = [...element.children];
  340. if (window.HTMLSlotElement && element instanceof HTMLSlotElement) {
  341. children.push(...element.assignedElements());
  342. }
  343. if (!selector) {
  344. return children;
  345. }
  346. return children.filter(el => el.matches(selector));
  347. }
  348. function elementIsChildOfSlot(el, slot) {
  349. // Breadth-first search through all parent's children and assigned elements
  350. const elementsQueue = [slot];
  351. while (elementsQueue.length > 0) {
  352. const elementToCheck = elementsQueue.shift();
  353. if (el === elementToCheck) {
  354. return true;
  355. }
  356. elementsQueue.push(...elementToCheck.children, ...(elementToCheck.shadowRoot ? elementToCheck.shadowRoot.children : []), ...(elementToCheck.assignedElements ? elementToCheck.assignedElements() : []));
  357. }
  358. }
  359. function elementIsChildOf(el, parent) {
  360. const window = getWindow();
  361. let isChild = parent.contains(el);
  362. if (!isChild && window.HTMLSlotElement && parent instanceof HTMLSlotElement) {
  363. const children = [...parent.assignedElements()];
  364. isChild = children.includes(el);
  365. if (!isChild) {
  366. isChild = elementIsChildOfSlot(el, parent);
  367. }
  368. }
  369. return isChild;
  370. }
  371. function showWarning(text) {
  372. try {
  373. console.warn(text);
  374. return;
  375. } catch (err) {
  376. // err
  377. }
  378. }
  379. function createElement(tag, classes) {
  380. if (classes === void 0) {
  381. classes = [];
  382. }
  383. const el = document.createElement(tag);
  384. el.classList.add(...(Array.isArray(classes) ? classes : classesToTokens(classes)));
  385. return el;
  386. }
  387. function elementPrevAll(el, selector) {
  388. const prevEls = [];
  389. while (el.previousElementSibling) {
  390. const prev = el.previousElementSibling; // eslint-disable-line
  391. if (selector) {
  392. if (prev.matches(selector)) prevEls.push(prev);
  393. } else prevEls.push(prev);
  394. el = prev;
  395. }
  396. return prevEls;
  397. }
  398. function elementNextAll(el, selector) {
  399. const nextEls = [];
  400. while (el.nextElementSibling) {
  401. const next = el.nextElementSibling; // eslint-disable-line
  402. if (selector) {
  403. if (next.matches(selector)) nextEls.push(next);
  404. } else nextEls.push(next);
  405. el = next;
  406. }
  407. return nextEls;
  408. }
  409. function elementStyle(el, prop) {
  410. const window = getWindow();
  411. return window.getComputedStyle(el, null).getPropertyValue(prop);
  412. }
  413. function elementIndex(el) {
  414. let child = el;
  415. let i;
  416. if (child) {
  417. i = 0;
  418. // eslint-disable-next-line
  419. while ((child = child.previousSibling) !== null) {
  420. if (child.nodeType === 1) i += 1;
  421. }
  422. return i;
  423. }
  424. return undefined;
  425. }
  426. function elementParents(el, selector) {
  427. const parents = []; // eslint-disable-line
  428. let parent = el.parentElement; // eslint-disable-line
  429. while (parent) {
  430. if (selector) {
  431. if (parent.matches(selector)) parents.push(parent);
  432. } else {
  433. parents.push(parent);
  434. }
  435. parent = parent.parentElement;
  436. }
  437. return parents;
  438. }
  439. function elementOuterSize(el, size, includeMargins) {
  440. const window = getWindow();
  441. if (includeMargins) {
  442. 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'));
  443. }
  444. return el.offsetWidth;
  445. }
  446. function setInnerHTML(el, html) {
  447. if (html === void 0) {
  448. html = '';
  449. }
  450. if (typeof trustedTypes !== 'undefined') {
  451. el.innerHTML = trustedTypes.createPolicy('html', {
  452. createHTML: s => s
  453. }).createHTML(html);
  454. } else {
  455. el.innerHTML = html;
  456. }
  457. }
  458. let support;
  459. function calcSupport() {
  460. const window = getWindow();
  461. const document = getDocument();
  462. return {
  463. smoothScroll: document.documentElement && document.documentElement.style && 'scrollBehavior' in document.documentElement.style,
  464. touch: !!('ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch)
  465. };
  466. }
  467. function getSupport() {
  468. if (!support) {
  469. support = calcSupport();
  470. }
  471. return support;
  472. }
  473. let deviceCached;
  474. function calcDevice(_temp) {
  475. let {
  476. userAgent
  477. } = _temp === void 0 ? {} : _temp;
  478. const support = getSupport();
  479. const window = getWindow();
  480. const platform = window.navigator.platform;
  481. const ua = userAgent || window.navigator.userAgent;
  482. const device = {
  483. ios: false,
  484. android: false
  485. };
  486. const screenWidth = window.screen.width;
  487. const screenHeight = window.screen.height;
  488. const android = ua.match(/(Android);?[\s\/]+([\d.]+)?/); // eslint-disable-line
  489. let ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  490. const ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  491. const iphone = !ipad && ua.match(/(iPhone\sOS|iOS)\s([\d_]+)/);
  492. const windows = platform === 'Win32';
  493. let macos = platform === 'MacIntel';
  494. // iPadOs 13 fix
  495. const iPadScreens = ['1024x1366', '1366x1024', '834x1194', '1194x834', '834x1112', '1112x834', '768x1024', '1024x768', '820x1180', '1180x820', '810x1080', '1080x810'];
  496. if (!ipad && macos && support.touch && iPadScreens.indexOf(`${screenWidth}x${screenHeight}`) >= 0) {
  497. ipad = ua.match(/(Version)\/([\d.]+)/);
  498. if (!ipad) ipad = [0, 1, '13_0_0'];
  499. macos = false;
  500. }
  501. // Android
  502. if (android && !windows) {
  503. device.os = 'android';
  504. device.android = true;
  505. }
  506. if (ipad || iphone || ipod) {
  507. device.os = 'ios';
  508. device.ios = true;
  509. }
  510. // Export object
  511. return device;
  512. }
  513. function getDevice(overrides) {
  514. if (overrides === void 0) {
  515. overrides = {};
  516. }
  517. if (!deviceCached) {
  518. deviceCached = calcDevice(overrides);
  519. }
  520. return deviceCached;
  521. }
  522. let browser;
  523. function calcBrowser() {
  524. const window = getWindow();
  525. const device = getDevice();
  526. let needPerspectiveFix = false;
  527. function isSafari() {
  528. const ua = window.navigator.userAgent.toLowerCase();
  529. return ua.indexOf('safari') >= 0 && ua.indexOf('chrome') < 0 && ua.indexOf('android') < 0;
  530. }
  531. if (isSafari()) {
  532. const ua = String(window.navigator.userAgent);
  533. if (ua.includes('Version/')) {
  534. const [major, minor] = ua.split('Version/')[1].split(' ')[0].split('.').map(num => Number(num));
  535. needPerspectiveFix = major < 16 || major === 16 && minor < 2;
  536. }
  537. }
  538. const isWebView = /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(window.navigator.userAgent);
  539. const isSafariBrowser = isSafari();
  540. const need3dFix = isSafariBrowser || isWebView && device.ios;
  541. return {
  542. isSafari: needPerspectiveFix || isSafariBrowser,
  543. needPerspectiveFix,
  544. need3dFix,
  545. isWebView
  546. };
  547. }
  548. function getBrowser() {
  549. if (!browser) {
  550. browser = calcBrowser();
  551. }
  552. return browser;
  553. }
  554. function Resize(_ref) {
  555. let {
  556. swiper,
  557. on,
  558. emit
  559. } = _ref;
  560. const window = getWindow();
  561. let observer = null;
  562. let animationFrame = null;
  563. const resizeHandler = () => {
  564. if (!swiper || swiper.destroyed || !swiper.initialized) return;
  565. emit('beforeResize');
  566. emit('resize');
  567. };
  568. const createObserver = () => {
  569. if (!swiper || swiper.destroyed || !swiper.initialized) return;
  570. observer = new ResizeObserver(entries => {
  571. animationFrame = window.requestAnimationFrame(() => {
  572. const {
  573. width,
  574. height
  575. } = swiper;
  576. let newWidth = width;
  577. let newHeight = height;
  578. entries.forEach(_ref2 => {
  579. let {
  580. contentBoxSize,
  581. contentRect,
  582. target
  583. } = _ref2;
  584. if (target && target !== swiper.el) return;
  585. newWidth = contentRect ? contentRect.width : (contentBoxSize[0] || contentBoxSize).inlineSize;
  586. newHeight = contentRect ? contentRect.height : (contentBoxSize[0] || contentBoxSize).blockSize;
  587. });
  588. if (newWidth !== width || newHeight !== height) {
  589. resizeHandler();
  590. }
  591. });
  592. });
  593. observer.observe(swiper.el);
  594. };
  595. const removeObserver = () => {
  596. if (animationFrame) {
  597. window.cancelAnimationFrame(animationFrame);
  598. }
  599. if (observer && observer.unobserve && swiper.el) {
  600. observer.unobserve(swiper.el);
  601. observer = null;
  602. }
  603. };
  604. const orientationChangeHandler = () => {
  605. if (!swiper || swiper.destroyed || !swiper.initialized) return;
  606. emit('orientationchange');
  607. };
  608. on('init', () => {
  609. if (swiper.params.resizeObserver && typeof window.ResizeObserver !== 'undefined') {
  610. createObserver();
  611. return;
  612. }
  613. window.addEventListener('resize', resizeHandler);
  614. window.addEventListener('orientationchange', orientationChangeHandler);
  615. });
  616. on('destroy', () => {
  617. removeObserver();
  618. window.removeEventListener('resize', resizeHandler);
  619. window.removeEventListener('orientationchange', orientationChangeHandler);
  620. });
  621. }
  622. function Observer(_ref) {
  623. let {
  624. swiper,
  625. extendParams,
  626. on,
  627. emit
  628. } = _ref;
  629. const observers = [];
  630. const window = getWindow();
  631. const attach = function (target, options) {
  632. if (options === void 0) {
  633. options = {};
  634. }
  635. const ObserverFunc = window.MutationObserver || window.WebkitMutationObserver;
  636. const observer = new ObserverFunc(mutations => {
  637. // The observerUpdate event should only be triggered
  638. // once despite the number of mutations. Additional
  639. // triggers are redundant and are very costly
  640. if (swiper.__preventObserver__) return;
  641. if (mutations.length === 1) {
  642. emit('observerUpdate', mutations[0]);
  643. return;
  644. }
  645. const observerUpdate = function observerUpdate() {
  646. emit('observerUpdate', mutations[0]);
  647. };
  648. if (window.requestAnimationFrame) {
  649. window.requestAnimationFrame(observerUpdate);
  650. } else {
  651. window.setTimeout(observerUpdate, 0);
  652. }
  653. });
  654. observer.observe(target, {
  655. attributes: typeof options.attributes === 'undefined' ? true : options.attributes,
  656. childList: swiper.isElement || (typeof options.childList === 'undefined' ? true : options).childList,
  657. characterData: typeof options.characterData === 'undefined' ? true : options.characterData
  658. });
  659. observers.push(observer);
  660. };
  661. const init = () => {
  662. if (!swiper.params.observer) return;
  663. if (swiper.params.observeParents) {
  664. const containerParents = elementParents(swiper.hostEl);
  665. for (let i = 0; i < containerParents.length; i += 1) {
  666. attach(containerParents[i]);
  667. }
  668. }
  669. // Observe container
  670. attach(swiper.hostEl, {
  671. childList: swiper.params.observeSlideChildren
  672. });
  673. // Observe wrapper
  674. attach(swiper.wrapperEl, {
  675. attributes: false
  676. });
  677. };
  678. const destroy = () => {
  679. observers.forEach(observer => {
  680. observer.disconnect();
  681. });
  682. observers.splice(0, observers.length);
  683. };
  684. extendParams({
  685. observer: false,
  686. observeParents: false,
  687. observeSlideChildren: false
  688. });
  689. on('init', init);
  690. on('destroy', destroy);
  691. }
  692. /* eslint-disable no-underscore-dangle */
  693. var eventsEmitter = {
  694. on(events, handler, priority) {
  695. const self = this;
  696. if (!self.eventsListeners || self.destroyed) return self;
  697. if (typeof handler !== 'function') return self;
  698. const method = priority ? 'unshift' : 'push';
  699. events.split(' ').forEach(event => {
  700. if (!self.eventsListeners[event]) self.eventsListeners[event] = [];
  701. self.eventsListeners[event][method](handler);
  702. });
  703. return self;
  704. },
  705. once(events, handler, priority) {
  706. const self = this;
  707. if (!self.eventsListeners || self.destroyed) return self;
  708. if (typeof handler !== 'function') return self;
  709. function onceHandler() {
  710. self.off(events, onceHandler);
  711. if (onceHandler.__emitterProxy) {
  712. delete onceHandler.__emitterProxy;
  713. }
  714. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  715. args[_key] = arguments[_key];
  716. }
  717. handler.apply(self, args);
  718. }
  719. onceHandler.__emitterProxy = handler;
  720. return self.on(events, onceHandler, priority);
  721. },
  722. onAny(handler, priority) {
  723. const self = this;
  724. if (!self.eventsListeners || self.destroyed) return self;
  725. if (typeof handler !== 'function') return self;
  726. const method = priority ? 'unshift' : 'push';
  727. if (self.eventsAnyListeners.indexOf(handler) < 0) {
  728. self.eventsAnyListeners[method](handler);
  729. }
  730. return self;
  731. },
  732. offAny(handler) {
  733. const self = this;
  734. if (!self.eventsListeners || self.destroyed) return self;
  735. if (!self.eventsAnyListeners) return self;
  736. const index = self.eventsAnyListeners.indexOf(handler);
  737. if (index >= 0) {
  738. self.eventsAnyListeners.splice(index, 1);
  739. }
  740. return self;
  741. },
  742. off(events, handler) {
  743. const self = this;
  744. if (!self.eventsListeners || self.destroyed) return self;
  745. if (!self.eventsListeners) return self;
  746. events.split(' ').forEach(event => {
  747. if (typeof handler === 'undefined') {
  748. self.eventsListeners[event] = [];
  749. } else if (self.eventsListeners[event]) {
  750. self.eventsListeners[event].forEach((eventHandler, index) => {
  751. if (eventHandler === handler || eventHandler.__emitterProxy && eventHandler.__emitterProxy === handler) {
  752. self.eventsListeners[event].splice(index, 1);
  753. }
  754. });
  755. }
  756. });
  757. return self;
  758. },
  759. emit() {
  760. const self = this;
  761. if (!self.eventsListeners || self.destroyed) return self;
  762. if (!self.eventsListeners) return self;
  763. let events;
  764. let data;
  765. let context;
  766. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  767. args[_key2] = arguments[_key2];
  768. }
  769. if (typeof args[0] === 'string' || Array.isArray(args[0])) {
  770. events = args[0];
  771. data = args.slice(1, args.length);
  772. context = self;
  773. } else {
  774. events = args[0].events;
  775. data = args[0].data;
  776. context = args[0].context || self;
  777. }
  778. data.unshift(context);
  779. const eventsArray = Array.isArray(events) ? events : events.split(' ');
  780. eventsArray.forEach(event => {
  781. if (self.eventsAnyListeners && self.eventsAnyListeners.length) {
  782. self.eventsAnyListeners.forEach(eventHandler => {
  783. eventHandler.apply(context, [event, ...data]);
  784. });
  785. }
  786. if (self.eventsListeners && self.eventsListeners[event]) {
  787. self.eventsListeners[event].forEach(eventHandler => {
  788. eventHandler.apply(context, data);
  789. });
  790. }
  791. });
  792. return self;
  793. }
  794. };
  795. function updateSize() {
  796. const swiper = this;
  797. let width;
  798. let height;
  799. const el = swiper.el;
  800. if (typeof swiper.params.width !== 'undefined' && swiper.params.width !== null) {
  801. width = swiper.params.width;
  802. } else {
  803. width = el.clientWidth;
  804. }
  805. if (typeof swiper.params.height !== 'undefined' && swiper.params.height !== null) {
  806. height = swiper.params.height;
  807. } else {
  808. height = el.clientHeight;
  809. }
  810. if (width === 0 && swiper.isHorizontal() || height === 0 && swiper.isVertical()) {
  811. return;
  812. }
  813. // Subtract paddings
  814. width = width - parseInt(elementStyle(el, 'padding-left') || 0, 10) - parseInt(elementStyle(el, 'padding-right') || 0, 10);
  815. height = height - parseInt(elementStyle(el, 'padding-top') || 0, 10) - parseInt(elementStyle(el, 'padding-bottom') || 0, 10);
  816. if (Number.isNaN(width)) width = 0;
  817. if (Number.isNaN(height)) height = 0;
  818. Object.assign(swiper, {
  819. width,
  820. height,
  821. size: swiper.isHorizontal() ? width : height
  822. });
  823. }
  824. function updateSlides() {
  825. const swiper = this;
  826. function getDirectionPropertyValue(node, label) {
  827. return parseFloat(node.getPropertyValue(swiper.getDirectionLabel(label)) || 0);
  828. }
  829. const params = swiper.params;
  830. const {
  831. wrapperEl,
  832. slidesEl,
  833. size: swiperSize,
  834. rtlTranslate: rtl,
  835. wrongRTL
  836. } = swiper;
  837. const isVirtual = swiper.virtual && params.virtual.enabled;
  838. const previousSlidesLength = isVirtual ? swiper.virtual.slides.length : swiper.slides.length;
  839. const slides = elementChildren(slidesEl, `.${swiper.params.slideClass}, swiper-slide`);
  840. const slidesLength = isVirtual ? swiper.virtual.slides.length : slides.length;
  841. let snapGrid = [];
  842. const slidesGrid = [];
  843. const slidesSizesGrid = [];
  844. let offsetBefore = params.slidesOffsetBefore;
  845. if (typeof offsetBefore === 'function') {
  846. offsetBefore = params.slidesOffsetBefore.call(swiper);
  847. }
  848. let offsetAfter = params.slidesOffsetAfter;
  849. if (typeof offsetAfter === 'function') {
  850. offsetAfter = params.slidesOffsetAfter.call(swiper);
  851. }
  852. const previousSnapGridLength = swiper.snapGrid.length;
  853. const previousSlidesGridLength = swiper.slidesGrid.length;
  854. let spaceBetween = params.spaceBetween;
  855. let slidePosition = -offsetBefore;
  856. let prevSlideSize = 0;
  857. let index = 0;
  858. if (typeof swiperSize === 'undefined') {
  859. return;
  860. }
  861. if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
  862. spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * swiperSize;
  863. } else if (typeof spaceBetween === 'string') {
  864. spaceBetween = parseFloat(spaceBetween);
  865. }
  866. swiper.virtualSize = -spaceBetween;
  867. // reset margins
  868. slides.forEach(slideEl => {
  869. if (rtl) {
  870. slideEl.style.marginLeft = '';
  871. } else {
  872. slideEl.style.marginRight = '';
  873. }
  874. slideEl.style.marginBottom = '';
  875. slideEl.style.marginTop = '';
  876. });
  877. // reset cssMode offsets
  878. if (params.centeredSlides && params.cssMode) {
  879. setCSSProperty(wrapperEl, '--swiper-centered-offset-before', '');
  880. setCSSProperty(wrapperEl, '--swiper-centered-offset-after', '');
  881. }
  882. const gridEnabled = params.grid && params.grid.rows > 1 && swiper.grid;
  883. if (gridEnabled) {
  884. swiper.grid.initSlides(slides);
  885. } else if (swiper.grid) {
  886. swiper.grid.unsetSlides();
  887. }
  888. // Calc slides
  889. let slideSize;
  890. const shouldResetSlideSize = params.slidesPerView === 'auto' && params.breakpoints && Object.keys(params.breakpoints).filter(key => {
  891. return typeof params.breakpoints[key].slidesPerView !== 'undefined';
  892. }).length > 0;
  893. for (let i = 0; i < slidesLength; i += 1) {
  894. slideSize = 0;
  895. let slide;
  896. if (slides[i]) slide = slides[i];
  897. if (gridEnabled) {
  898. swiper.grid.updateSlide(i, slide, slides);
  899. }
  900. if (slides[i] && elementStyle(slide, 'display') === 'none') continue; // eslint-disable-line
  901. if (params.slidesPerView === 'auto') {
  902. if (shouldResetSlideSize) {
  903. slides[i].style[swiper.getDirectionLabel('width')] = ``;
  904. }
  905. const slideStyles = getComputedStyle(slide);
  906. const currentTransform = slide.style.transform;
  907. const currentWebKitTransform = slide.style.webkitTransform;
  908. if (currentTransform) {
  909. slide.style.transform = 'none';
  910. }
  911. if (currentWebKitTransform) {
  912. slide.style.webkitTransform = 'none';
  913. }
  914. if (params.roundLengths) {
  915. slideSize = swiper.isHorizontal() ? elementOuterSize(slide, 'width', true) : elementOuterSize(slide, 'height', true);
  916. } else {
  917. // eslint-disable-next-line
  918. const width = getDirectionPropertyValue(slideStyles, 'width');
  919. const paddingLeft = getDirectionPropertyValue(slideStyles, 'padding-left');
  920. const paddingRight = getDirectionPropertyValue(slideStyles, 'padding-right');
  921. const marginLeft = getDirectionPropertyValue(slideStyles, 'margin-left');
  922. const marginRight = getDirectionPropertyValue(slideStyles, 'margin-right');
  923. const boxSizing = slideStyles.getPropertyValue('box-sizing');
  924. if (boxSizing && boxSizing === 'border-box') {
  925. slideSize = width + marginLeft + marginRight;
  926. } else {
  927. const {
  928. clientWidth,
  929. offsetWidth
  930. } = slide;
  931. slideSize = width + paddingLeft + paddingRight + marginLeft + marginRight + (offsetWidth - clientWidth);
  932. }
  933. }
  934. if (currentTransform) {
  935. slide.style.transform = currentTransform;
  936. }
  937. if (currentWebKitTransform) {
  938. slide.style.webkitTransform = currentWebKitTransform;
  939. }
  940. if (params.roundLengths) slideSize = Math.floor(slideSize);
  941. } else {
  942. slideSize = (swiperSize - (params.slidesPerView - 1) * spaceBetween) / params.slidesPerView;
  943. if (params.roundLengths) slideSize = Math.floor(slideSize);
  944. if (slides[i]) {
  945. slides[i].style[swiper.getDirectionLabel('width')] = `${slideSize}px`;
  946. }
  947. }
  948. if (slides[i]) {
  949. slides[i].swiperSlideSize = slideSize;
  950. }
  951. slidesSizesGrid.push(slideSize);
  952. if (params.centeredSlides) {
  953. slidePosition = slidePosition + slideSize / 2 + prevSlideSize / 2 + spaceBetween;
  954. if (prevSlideSize === 0 && i !== 0) slidePosition = slidePosition - swiperSize / 2 - spaceBetween;
  955. if (i === 0) slidePosition = slidePosition - swiperSize / 2 - spaceBetween;
  956. if (Math.abs(slidePosition) < 1 / 1000) slidePosition = 0;
  957. if (params.roundLengths) slidePosition = Math.floor(slidePosition);
  958. if (index % params.slidesPerGroup === 0) snapGrid.push(slidePosition);
  959. slidesGrid.push(slidePosition);
  960. } else {
  961. if (params.roundLengths) slidePosition = Math.floor(slidePosition);
  962. if ((index - Math.min(swiper.params.slidesPerGroupSkip, index)) % swiper.params.slidesPerGroup === 0) snapGrid.push(slidePosition);
  963. slidesGrid.push(slidePosition);
  964. slidePosition = slidePosition + slideSize + spaceBetween;
  965. }
  966. swiper.virtualSize += slideSize + spaceBetween;
  967. prevSlideSize = slideSize;
  968. index += 1;
  969. }
  970. swiper.virtualSize = Math.max(swiper.virtualSize, swiperSize) + offsetAfter;
  971. if (rtl && wrongRTL && (params.effect === 'slide' || params.effect === 'coverflow')) {
  972. wrapperEl.style.width = `${swiper.virtualSize + spaceBetween}px`;
  973. }
  974. if (params.setWrapperSize) {
  975. wrapperEl.style[swiper.getDirectionLabel('width')] = `${swiper.virtualSize + spaceBetween}px`;
  976. }
  977. if (gridEnabled) {
  978. swiper.grid.updateWrapperSize(slideSize, snapGrid);
  979. }
  980. // Remove last grid elements depending on width
  981. if (!params.centeredSlides) {
  982. const newSlidesGrid = [];
  983. for (let i = 0; i < snapGrid.length; i += 1) {
  984. let slidesGridItem = snapGrid[i];
  985. if (params.roundLengths) slidesGridItem = Math.floor(slidesGridItem);
  986. if (snapGrid[i] <= swiper.virtualSize - swiperSize) {
  987. newSlidesGrid.push(slidesGridItem);
  988. }
  989. }
  990. snapGrid = newSlidesGrid;
  991. if (Math.floor(swiper.virtualSize - swiperSize) - Math.floor(snapGrid[snapGrid.length - 1]) > 1) {
  992. snapGrid.push(swiper.virtualSize - swiperSize);
  993. }
  994. }
  995. if (isVirtual && params.loop) {
  996. const size = slidesSizesGrid[0] + spaceBetween;
  997. if (params.slidesPerGroup > 1) {
  998. const groups = Math.ceil((swiper.virtual.slidesBefore + swiper.virtual.slidesAfter) / params.slidesPerGroup);
  999. const groupSize = size * params.slidesPerGroup;
  1000. for (let i = 0; i < groups; i += 1) {
  1001. snapGrid.push(snapGrid[snapGrid.length - 1] + groupSize);
  1002. }
  1003. }
  1004. for (let i = 0; i < swiper.virtual.slidesBefore + swiper.virtual.slidesAfter; i += 1) {
  1005. if (params.slidesPerGroup === 1) {
  1006. snapGrid.push(snapGrid[snapGrid.length - 1] + size);
  1007. }
  1008. slidesGrid.push(slidesGrid[slidesGrid.length - 1] + size);
  1009. swiper.virtualSize += size;
  1010. }
  1011. }
  1012. if (snapGrid.length === 0) snapGrid = [0];
  1013. if (spaceBetween !== 0) {
  1014. const key = swiper.isHorizontal() && rtl ? 'marginLeft' : swiper.getDirectionLabel('marginRight');
  1015. slides.filter((_, slideIndex) => {
  1016. if (!params.cssMode || params.loop) return true;
  1017. if (slideIndex === slides.length - 1) {
  1018. return false;
  1019. }
  1020. return true;
  1021. }).forEach(slideEl => {
  1022. slideEl.style[key] = `${spaceBetween}px`;
  1023. });
  1024. }
  1025. if (params.centeredSlides && params.centeredSlidesBounds) {
  1026. let allSlidesSize = 0;
  1027. slidesSizesGrid.forEach(slideSizeValue => {
  1028. allSlidesSize += slideSizeValue + (spaceBetween || 0);
  1029. });
  1030. allSlidesSize -= spaceBetween;
  1031. const maxSnap = allSlidesSize > swiperSize ? allSlidesSize - swiperSize : 0;
  1032. snapGrid = snapGrid.map(snap => {
  1033. if (snap <= 0) return -offsetBefore;
  1034. if (snap > maxSnap) return maxSnap + offsetAfter;
  1035. return snap;
  1036. });
  1037. }
  1038. if (params.centerInsufficientSlides) {
  1039. let allSlidesSize = 0;
  1040. slidesSizesGrid.forEach(slideSizeValue => {
  1041. allSlidesSize += slideSizeValue + (spaceBetween || 0);
  1042. });
  1043. allSlidesSize -= spaceBetween;
  1044. const offsetSize = (params.slidesOffsetBefore || 0) + (params.slidesOffsetAfter || 0);
  1045. if (allSlidesSize + offsetSize < swiperSize) {
  1046. const allSlidesOffset = (swiperSize - allSlidesSize - offsetSize) / 2;
  1047. snapGrid.forEach((snap, snapIndex) => {
  1048. snapGrid[snapIndex] = snap - allSlidesOffset;
  1049. });
  1050. slidesGrid.forEach((snap, snapIndex) => {
  1051. slidesGrid[snapIndex] = snap + allSlidesOffset;
  1052. });
  1053. }
  1054. }
  1055. Object.assign(swiper, {
  1056. slides,
  1057. snapGrid,
  1058. slidesGrid,
  1059. slidesSizesGrid
  1060. });
  1061. if (params.centeredSlides && params.cssMode && !params.centeredSlidesBounds) {
  1062. setCSSProperty(wrapperEl, '--swiper-centered-offset-before', `${-snapGrid[0]}px`);
  1063. setCSSProperty(wrapperEl, '--swiper-centered-offset-after', `${swiper.size / 2 - slidesSizesGrid[slidesSizesGrid.length - 1] / 2}px`);
  1064. const addToSnapGrid = -swiper.snapGrid[0];
  1065. const addToSlidesGrid = -swiper.slidesGrid[0];
  1066. swiper.snapGrid = swiper.snapGrid.map(v => v + addToSnapGrid);
  1067. swiper.slidesGrid = swiper.slidesGrid.map(v => v + addToSlidesGrid);
  1068. }
  1069. if (slidesLength !== previousSlidesLength) {
  1070. swiper.emit('slidesLengthChange');
  1071. }
  1072. if (snapGrid.length !== previousSnapGridLength) {
  1073. if (swiper.params.watchOverflow) swiper.checkOverflow();
  1074. swiper.emit('snapGridLengthChange');
  1075. }
  1076. if (slidesGrid.length !== previousSlidesGridLength) {
  1077. swiper.emit('slidesGridLengthChange');
  1078. }
  1079. if (params.watchSlidesProgress) {
  1080. swiper.updateSlidesOffset();
  1081. }
  1082. swiper.emit('slidesUpdated');
  1083. if (!isVirtual && !params.cssMode && (params.effect === 'slide' || params.effect === 'fade')) {
  1084. const backFaceHiddenClass = `${params.containerModifierClass}backface-hidden`;
  1085. const hasClassBackfaceClassAdded = swiper.el.classList.contains(backFaceHiddenClass);
  1086. if (slidesLength <= params.maxBackfaceHiddenSlides) {
  1087. if (!hasClassBackfaceClassAdded) swiper.el.classList.add(backFaceHiddenClass);
  1088. } else if (hasClassBackfaceClassAdded) {
  1089. swiper.el.classList.remove(backFaceHiddenClass);
  1090. }
  1091. }
  1092. }
  1093. function updateAutoHeight(speed) {
  1094. const swiper = this;
  1095. const activeSlides = [];
  1096. const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
  1097. let newHeight = 0;
  1098. let i;
  1099. if (typeof speed === 'number') {
  1100. swiper.setTransition(speed);
  1101. } else if (speed === true) {
  1102. swiper.setTransition(swiper.params.speed);
  1103. }
  1104. const getSlideByIndex = index => {
  1105. if (isVirtual) {
  1106. return swiper.slides[swiper.getSlideIndexByData(index)];
  1107. }
  1108. return swiper.slides[index];
  1109. };
  1110. // Find slides currently in view
  1111. if (swiper.params.slidesPerView !== 'auto' && swiper.params.slidesPerView > 1) {
  1112. if (swiper.params.centeredSlides) {
  1113. (swiper.visibleSlides || []).forEach(slide => {
  1114. activeSlides.push(slide);
  1115. });
  1116. } else {
  1117. for (i = 0; i < Math.ceil(swiper.params.slidesPerView); i += 1) {
  1118. const index = swiper.activeIndex + i;
  1119. if (index > swiper.slides.length && !isVirtual) break;
  1120. activeSlides.push(getSlideByIndex(index));
  1121. }
  1122. }
  1123. } else {
  1124. activeSlides.push(getSlideByIndex(swiper.activeIndex));
  1125. }
  1126. // Find new height from highest slide in view
  1127. for (i = 0; i < activeSlides.length; i += 1) {
  1128. if (typeof activeSlides[i] !== 'undefined') {
  1129. const height = activeSlides[i].offsetHeight;
  1130. newHeight = height > newHeight ? height : newHeight;
  1131. }
  1132. }
  1133. // Update Height
  1134. if (newHeight || newHeight === 0) swiper.wrapperEl.style.height = `${newHeight}px`;
  1135. }
  1136. function updateSlidesOffset() {
  1137. const swiper = this;
  1138. const slides = swiper.slides;
  1139. // eslint-disable-next-line
  1140. const minusOffset = swiper.isElement ? swiper.isHorizontal() ? swiper.wrapperEl.offsetLeft : swiper.wrapperEl.offsetTop : 0;
  1141. for (let i = 0; i < slides.length; i += 1) {
  1142. slides[i].swiperSlideOffset = (swiper.isHorizontal() ? slides[i].offsetLeft : slides[i].offsetTop) - minusOffset - swiper.cssOverflowAdjustment();
  1143. }
  1144. }
  1145. const toggleSlideClasses$1 = (slideEl, condition, className) => {
  1146. if (condition && !slideEl.classList.contains(className)) {
  1147. slideEl.classList.add(className);
  1148. } else if (!condition && slideEl.classList.contains(className)) {
  1149. slideEl.classList.remove(className);
  1150. }
  1151. };
  1152. function updateSlidesProgress(translate) {
  1153. if (translate === void 0) {
  1154. translate = this && this.translate || 0;
  1155. }
  1156. const swiper = this;
  1157. const params = swiper.params;
  1158. const {
  1159. slides,
  1160. rtlTranslate: rtl,
  1161. snapGrid
  1162. } = swiper;
  1163. if (slides.length === 0) return;
  1164. if (typeof slides[0].swiperSlideOffset === 'undefined') swiper.updateSlidesOffset();
  1165. let offsetCenter = -translate;
  1166. if (rtl) offsetCenter = translate;
  1167. swiper.visibleSlidesIndexes = [];
  1168. swiper.visibleSlides = [];
  1169. let spaceBetween = params.spaceBetween;
  1170. if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
  1171. spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * swiper.size;
  1172. } else if (typeof spaceBetween === 'string') {
  1173. spaceBetween = parseFloat(spaceBetween);
  1174. }
  1175. for (let i = 0; i < slides.length; i += 1) {
  1176. const slide = slides[i];
  1177. let slideOffset = slide.swiperSlideOffset;
  1178. if (params.cssMode && params.centeredSlides) {
  1179. slideOffset -= slides[0].swiperSlideOffset;
  1180. }
  1181. const slideProgress = (offsetCenter + (params.centeredSlides ? swiper.minTranslate() : 0) - slideOffset) / (slide.swiperSlideSize + spaceBetween);
  1182. const originalSlideProgress = (offsetCenter - snapGrid[0] + (params.centeredSlides ? swiper.minTranslate() : 0) - slideOffset) / (slide.swiperSlideSize + spaceBetween);
  1183. const slideBefore = -(offsetCenter - slideOffset);
  1184. const slideAfter = slideBefore + swiper.slidesSizesGrid[i];
  1185. const isFullyVisible = slideBefore >= 0 && slideBefore <= swiper.size - swiper.slidesSizesGrid[i];
  1186. const isVisible = slideBefore >= 0 && slideBefore < swiper.size - 1 || slideAfter > 1 && slideAfter <= swiper.size || slideBefore <= 0 && slideAfter >= swiper.size;
  1187. if (isVisible) {
  1188. swiper.visibleSlides.push(slide);
  1189. swiper.visibleSlidesIndexes.push(i);
  1190. }
  1191. toggleSlideClasses$1(slide, isVisible, params.slideVisibleClass);
  1192. toggleSlideClasses$1(slide, isFullyVisible, params.slideFullyVisibleClass);
  1193. slide.progress = rtl ? -slideProgress : slideProgress;
  1194. slide.originalProgress = rtl ? -originalSlideProgress : originalSlideProgress;
  1195. }
  1196. }
  1197. function updateProgress(translate) {
  1198. const swiper = this;
  1199. if (typeof translate === 'undefined') {
  1200. const multiplier = swiper.rtlTranslate ? -1 : 1;
  1201. // eslint-disable-next-line
  1202. translate = swiper && swiper.translate && swiper.translate * multiplier || 0;
  1203. }
  1204. const params = swiper.params;
  1205. const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
  1206. let {
  1207. progress,
  1208. isBeginning,
  1209. isEnd,
  1210. progressLoop
  1211. } = swiper;
  1212. const wasBeginning = isBeginning;
  1213. const wasEnd = isEnd;
  1214. if (translatesDiff === 0) {
  1215. progress = 0;
  1216. isBeginning = true;
  1217. isEnd = true;
  1218. } else {
  1219. progress = (translate - swiper.minTranslate()) / translatesDiff;
  1220. const isBeginningRounded = Math.abs(translate - swiper.minTranslate()) < 1;
  1221. const isEndRounded = Math.abs(translate - swiper.maxTranslate()) < 1;
  1222. isBeginning = isBeginningRounded || progress <= 0;
  1223. isEnd = isEndRounded || progress >= 1;
  1224. if (isBeginningRounded) progress = 0;
  1225. if (isEndRounded) progress = 1;
  1226. }
  1227. if (params.loop) {
  1228. const firstSlideIndex = swiper.getSlideIndexByData(0);
  1229. const lastSlideIndex = swiper.getSlideIndexByData(swiper.slides.length - 1);
  1230. const firstSlideTranslate = swiper.slidesGrid[firstSlideIndex];
  1231. const lastSlideTranslate = swiper.slidesGrid[lastSlideIndex];
  1232. const translateMax = swiper.slidesGrid[swiper.slidesGrid.length - 1];
  1233. const translateAbs = Math.abs(translate);
  1234. if (translateAbs >= firstSlideTranslate) {
  1235. progressLoop = (translateAbs - firstSlideTranslate) / translateMax;
  1236. } else {
  1237. progressLoop = (translateAbs + translateMax - lastSlideTranslate) / translateMax;
  1238. }
  1239. if (progressLoop > 1) progressLoop -= 1;
  1240. }
  1241. Object.assign(swiper, {
  1242. progress,
  1243. progressLoop,
  1244. isBeginning,
  1245. isEnd
  1246. });
  1247. if (params.watchSlidesProgress || params.centeredSlides && params.autoHeight) swiper.updateSlidesProgress(translate);
  1248. if (isBeginning && !wasBeginning) {
  1249. swiper.emit('reachBeginning toEdge');
  1250. }
  1251. if (isEnd && !wasEnd) {
  1252. swiper.emit('reachEnd toEdge');
  1253. }
  1254. if (wasBeginning && !isBeginning || wasEnd && !isEnd) {
  1255. swiper.emit('fromEdge');
  1256. }
  1257. swiper.emit('progress', progress);
  1258. }
  1259. const toggleSlideClasses = (slideEl, condition, className) => {
  1260. if (condition && !slideEl.classList.contains(className)) {
  1261. slideEl.classList.add(className);
  1262. } else if (!condition && slideEl.classList.contains(className)) {
  1263. slideEl.classList.remove(className);
  1264. }
  1265. };
  1266. function updateSlidesClasses() {
  1267. const swiper = this;
  1268. const {
  1269. slides,
  1270. params,
  1271. slidesEl,
  1272. activeIndex
  1273. } = swiper;
  1274. const isVirtual = swiper.virtual && params.virtual.enabled;
  1275. const gridEnabled = swiper.grid && params.grid && params.grid.rows > 1;
  1276. const getFilteredSlide = selector => {
  1277. return elementChildren(slidesEl, `.${params.slideClass}${selector}, swiper-slide${selector}`)[0];
  1278. };
  1279. let activeSlide;
  1280. let prevSlide;
  1281. let nextSlide;
  1282. if (isVirtual) {
  1283. if (params.loop) {
  1284. let slideIndex = activeIndex - swiper.virtual.slidesBefore;
  1285. if (slideIndex < 0) slideIndex = swiper.virtual.slides.length + slideIndex;
  1286. if (slideIndex >= swiper.virtual.slides.length) slideIndex -= swiper.virtual.slides.length;
  1287. activeSlide = getFilteredSlide(`[data-swiper-slide-index="${slideIndex}"]`);
  1288. } else {
  1289. activeSlide = getFilteredSlide(`[data-swiper-slide-index="${activeIndex}"]`);
  1290. }
  1291. } else {
  1292. if (gridEnabled) {
  1293. activeSlide = slides.find(slideEl => slideEl.column === activeIndex);
  1294. nextSlide = slides.find(slideEl => slideEl.column === activeIndex + 1);
  1295. prevSlide = slides.find(slideEl => slideEl.column === activeIndex - 1);
  1296. } else {
  1297. activeSlide = slides[activeIndex];
  1298. }
  1299. }
  1300. if (activeSlide) {
  1301. if (!gridEnabled) {
  1302. // Next Slide
  1303. nextSlide = elementNextAll(activeSlide, `.${params.slideClass}, swiper-slide`)[0];
  1304. if (params.loop && !nextSlide) {
  1305. nextSlide = slides[0];
  1306. }
  1307. // Prev Slide
  1308. prevSlide = elementPrevAll(activeSlide, `.${params.slideClass}, swiper-slide`)[0];
  1309. if (params.loop && !prevSlide === 0) {
  1310. prevSlide = slides[slides.length - 1];
  1311. }
  1312. }
  1313. }
  1314. slides.forEach(slideEl => {
  1315. toggleSlideClasses(slideEl, slideEl === activeSlide, params.slideActiveClass);
  1316. toggleSlideClasses(slideEl, slideEl === nextSlide, params.slideNextClass);
  1317. toggleSlideClasses(slideEl, slideEl === prevSlide, params.slidePrevClass);
  1318. });
  1319. swiper.emitSlidesClasses();
  1320. }
  1321. const processLazyPreloader = (swiper, imageEl) => {
  1322. if (!swiper || swiper.destroyed || !swiper.params) return;
  1323. const slideSelector = () => swiper.isElement ? `swiper-slide` : `.${swiper.params.slideClass}`;
  1324. const slideEl = imageEl.closest(slideSelector());
  1325. if (slideEl) {
  1326. let lazyEl = slideEl.querySelector(`.${swiper.params.lazyPreloaderClass}`);
  1327. if (!lazyEl && swiper.isElement) {
  1328. if (slideEl.shadowRoot) {
  1329. lazyEl = slideEl.shadowRoot.querySelector(`.${swiper.params.lazyPreloaderClass}`);
  1330. } else {
  1331. // init later
  1332. requestAnimationFrame(() => {
  1333. if (slideEl.shadowRoot) {
  1334. lazyEl = slideEl.shadowRoot.querySelector(`.${swiper.params.lazyPreloaderClass}`);
  1335. if (lazyEl) lazyEl.remove();
  1336. }
  1337. });
  1338. }
  1339. }
  1340. if (lazyEl) lazyEl.remove();
  1341. }
  1342. };
  1343. const unlazy = (swiper, index) => {
  1344. if (!swiper.slides[index]) return;
  1345. const imageEl = swiper.slides[index].querySelector('[loading="lazy"]');
  1346. if (imageEl) imageEl.removeAttribute('loading');
  1347. };
  1348. const preload = swiper => {
  1349. if (!swiper || swiper.destroyed || !swiper.params) return;
  1350. let amount = swiper.params.lazyPreloadPrevNext;
  1351. const len = swiper.slides.length;
  1352. if (!len || !amount || amount < 0) return;
  1353. amount = Math.min(amount, len);
  1354. const slidesPerView = swiper.params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : Math.ceil(swiper.params.slidesPerView);
  1355. const activeIndex = swiper.activeIndex;
  1356. if (swiper.params.grid && swiper.params.grid.rows > 1) {
  1357. const activeColumn = activeIndex;
  1358. const preloadColumns = [activeColumn - amount];
  1359. preloadColumns.push(...Array.from({
  1360. length: amount
  1361. }).map((_, i) => {
  1362. return activeColumn + slidesPerView + i;
  1363. }));
  1364. swiper.slides.forEach((slideEl, i) => {
  1365. if (preloadColumns.includes(slideEl.column)) unlazy(swiper, i);
  1366. });
  1367. return;
  1368. }
  1369. const slideIndexLastInView = activeIndex + slidesPerView - 1;
  1370. if (swiper.params.rewind || swiper.params.loop) {
  1371. for (let i = activeIndex - amount; i <= slideIndexLastInView + amount; i += 1) {
  1372. const realIndex = (i % len + len) % len;
  1373. if (realIndex < activeIndex || realIndex > slideIndexLastInView) unlazy(swiper, realIndex);
  1374. }
  1375. } else {
  1376. for (let i = Math.max(activeIndex - amount, 0); i <= Math.min(slideIndexLastInView + amount, len - 1); i += 1) {
  1377. if (i !== activeIndex && (i > slideIndexLastInView || i < activeIndex)) {
  1378. unlazy(swiper, i);
  1379. }
  1380. }
  1381. }
  1382. };
  1383. function getActiveIndexByTranslate(swiper) {
  1384. const {
  1385. slidesGrid,
  1386. params
  1387. } = swiper;
  1388. const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
  1389. let activeIndex;
  1390. for (let i = 0; i < slidesGrid.length; i += 1) {
  1391. if (typeof slidesGrid[i + 1] !== 'undefined') {
  1392. if (translate >= slidesGrid[i] && translate < slidesGrid[i + 1] - (slidesGrid[i + 1] - slidesGrid[i]) / 2) {
  1393. activeIndex = i;
  1394. } else if (translate >= slidesGrid[i] && translate < slidesGrid[i + 1]) {
  1395. activeIndex = i + 1;
  1396. }
  1397. } else if (translate >= slidesGrid[i]) {
  1398. activeIndex = i;
  1399. }
  1400. }
  1401. // Normalize slideIndex
  1402. if (params.normalizeSlideIndex) {
  1403. if (activeIndex < 0 || typeof activeIndex === 'undefined') activeIndex = 0;
  1404. }
  1405. return activeIndex;
  1406. }
  1407. function updateActiveIndex(newActiveIndex) {
  1408. const swiper = this;
  1409. const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
  1410. const {
  1411. snapGrid,
  1412. params,
  1413. activeIndex: previousIndex,
  1414. realIndex: previousRealIndex,
  1415. snapIndex: previousSnapIndex
  1416. } = swiper;
  1417. let activeIndex = newActiveIndex;
  1418. let snapIndex;
  1419. const getVirtualRealIndex = aIndex => {
  1420. let realIndex = aIndex - swiper.virtual.slidesBefore;
  1421. if (realIndex < 0) {
  1422. realIndex = swiper.virtual.slides.length + realIndex;
  1423. }
  1424. if (realIndex >= swiper.virtual.slides.length) {
  1425. realIndex -= swiper.virtual.slides.length;
  1426. }
  1427. return realIndex;
  1428. };
  1429. if (typeof activeIndex === 'undefined') {
  1430. activeIndex = getActiveIndexByTranslate(swiper);
  1431. }
  1432. if (snapGrid.indexOf(translate) >= 0) {
  1433. snapIndex = snapGrid.indexOf(translate);
  1434. } else {
  1435. const skip = Math.min(params.slidesPerGroupSkip, activeIndex);
  1436. snapIndex = skip + Math.floor((activeIndex - skip) / params.slidesPerGroup);
  1437. }
  1438. if (snapIndex >= snapGrid.length) snapIndex = snapGrid.length - 1;
  1439. if (activeIndex === previousIndex && !swiper.params.loop) {
  1440. if (snapIndex !== previousSnapIndex) {
  1441. swiper.snapIndex = snapIndex;
  1442. swiper.emit('snapIndexChange');
  1443. }
  1444. return;
  1445. }
  1446. if (activeIndex === previousIndex && swiper.params.loop && swiper.virtual && swiper.params.virtual.enabled) {
  1447. swiper.realIndex = getVirtualRealIndex(activeIndex);
  1448. return;
  1449. }
  1450. const gridEnabled = swiper.grid && params.grid && params.grid.rows > 1;
  1451. // Get real index
  1452. let realIndex;
  1453. if (swiper.virtual && params.virtual.enabled && params.loop) {
  1454. realIndex = getVirtualRealIndex(activeIndex);
  1455. } else if (gridEnabled) {
  1456. const firstSlideInColumn = swiper.slides.find(slideEl => slideEl.column === activeIndex);
  1457. let activeSlideIndex = parseInt(firstSlideInColumn.getAttribute('data-swiper-slide-index'), 10);
  1458. if (Number.isNaN(activeSlideIndex)) {
  1459. activeSlideIndex = Math.max(swiper.slides.indexOf(firstSlideInColumn), 0);
  1460. }
  1461. realIndex = Math.floor(activeSlideIndex / params.grid.rows);
  1462. } else if (swiper.slides[activeIndex]) {
  1463. const slideIndex = swiper.slides[activeIndex].getAttribute('data-swiper-slide-index');
  1464. if (slideIndex) {
  1465. realIndex = parseInt(slideIndex, 10);
  1466. } else {
  1467. realIndex = activeIndex;
  1468. }
  1469. } else {
  1470. realIndex = activeIndex;
  1471. }
  1472. Object.assign(swiper, {
  1473. previousSnapIndex,
  1474. snapIndex,
  1475. previousRealIndex,
  1476. realIndex,
  1477. previousIndex,
  1478. activeIndex
  1479. });
  1480. if (swiper.initialized) {
  1481. preload(swiper);
  1482. }
  1483. swiper.emit('activeIndexChange');
  1484. swiper.emit('snapIndexChange');
  1485. if (swiper.initialized || swiper.params.runCallbacksOnInit) {
  1486. if (previousRealIndex !== realIndex) {
  1487. swiper.emit('realIndexChange');
  1488. }
  1489. swiper.emit('slideChange');
  1490. }
  1491. }
  1492. function updateClickedSlide(el, path) {
  1493. const swiper = this;
  1494. const params = swiper.params;
  1495. let slide = el.closest(`.${params.slideClass}, swiper-slide`);
  1496. if (!slide && swiper.isElement && path && path.length > 1 && path.includes(el)) {
  1497. [...path.slice(path.indexOf(el) + 1, path.length)].forEach(pathEl => {
  1498. if (!slide && pathEl.matches && pathEl.matches(`.${params.slideClass}, swiper-slide`)) {
  1499. slide = pathEl;
  1500. }
  1501. });
  1502. }
  1503. let slideFound = false;
  1504. let slideIndex;
  1505. if (slide) {
  1506. for (let i = 0; i < swiper.slides.length; i += 1) {
  1507. if (swiper.slides[i] === slide) {
  1508. slideFound = true;
  1509. slideIndex = i;
  1510. break;
  1511. }
  1512. }
  1513. }
  1514. if (slide && slideFound) {
  1515. swiper.clickedSlide = slide;
  1516. if (swiper.virtual && swiper.params.virtual.enabled) {
  1517. swiper.clickedIndex = parseInt(slide.getAttribute('data-swiper-slide-index'), 10);
  1518. } else {
  1519. swiper.clickedIndex = slideIndex;
  1520. }
  1521. } else {
  1522. swiper.clickedSlide = undefined;
  1523. swiper.clickedIndex = undefined;
  1524. return;
  1525. }
  1526. if (params.slideToClickedSlide && swiper.clickedIndex !== undefined && swiper.clickedIndex !== swiper.activeIndex) {
  1527. swiper.slideToClickedSlide();
  1528. }
  1529. }
  1530. var update = {
  1531. updateSize,
  1532. updateSlides,
  1533. updateAutoHeight,
  1534. updateSlidesOffset,
  1535. updateSlidesProgress,
  1536. updateProgress,
  1537. updateSlidesClasses,
  1538. updateActiveIndex,
  1539. updateClickedSlide
  1540. };
  1541. function getSwiperTranslate(axis) {
  1542. if (axis === void 0) {
  1543. axis = this.isHorizontal() ? 'x' : 'y';
  1544. }
  1545. const swiper = this;
  1546. const {
  1547. params,
  1548. rtlTranslate: rtl,
  1549. translate,
  1550. wrapperEl
  1551. } = swiper;
  1552. if (params.virtualTranslate) {
  1553. return rtl ? -translate : translate;
  1554. }
  1555. if (params.cssMode) {
  1556. return translate;
  1557. }
  1558. let currentTranslate = getTranslate(wrapperEl, axis);
  1559. currentTranslate += swiper.cssOverflowAdjustment();
  1560. if (rtl) currentTranslate = -currentTranslate;
  1561. return currentTranslate || 0;
  1562. }
  1563. function setTranslate(translate, byController) {
  1564. const swiper = this;
  1565. const {
  1566. rtlTranslate: rtl,
  1567. params,
  1568. wrapperEl,
  1569. progress
  1570. } = swiper;
  1571. let x = 0;
  1572. let y = 0;
  1573. const z = 0;
  1574. if (swiper.isHorizontal()) {
  1575. x = rtl ? -translate : translate;
  1576. } else {
  1577. y = translate;
  1578. }
  1579. if (params.roundLengths) {
  1580. x = Math.floor(x);
  1581. y = Math.floor(y);
  1582. }
  1583. swiper.previousTranslate = swiper.translate;
  1584. swiper.translate = swiper.isHorizontal() ? x : y;
  1585. if (params.cssMode) {
  1586. wrapperEl[swiper.isHorizontal() ? 'scrollLeft' : 'scrollTop'] = swiper.isHorizontal() ? -x : -y;
  1587. } else if (!params.virtualTranslate) {
  1588. if (swiper.isHorizontal()) {
  1589. x -= swiper.cssOverflowAdjustment();
  1590. } else {
  1591. y -= swiper.cssOverflowAdjustment();
  1592. }
  1593. wrapperEl.style.transform = `translate3d(${x}px, ${y}px, ${z}px)`;
  1594. }
  1595. // Check if we need to update progress
  1596. let newProgress;
  1597. const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
  1598. if (translatesDiff === 0) {
  1599. newProgress = 0;
  1600. } else {
  1601. newProgress = (translate - swiper.minTranslate()) / translatesDiff;
  1602. }
  1603. if (newProgress !== progress) {
  1604. swiper.updateProgress(translate);
  1605. }
  1606. swiper.emit('setTranslate', swiper.translate, byController);
  1607. }
  1608. function minTranslate() {
  1609. return -this.snapGrid[0];
  1610. }
  1611. function maxTranslate() {
  1612. return -this.snapGrid[this.snapGrid.length - 1];
  1613. }
  1614. function translateTo(translate, speed, runCallbacks, translateBounds, internal) {
  1615. if (translate === void 0) {
  1616. translate = 0;
  1617. }
  1618. if (speed === void 0) {
  1619. speed = this.params.speed;
  1620. }
  1621. if (runCallbacks === void 0) {
  1622. runCallbacks = true;
  1623. }
  1624. if (translateBounds === void 0) {
  1625. translateBounds = true;
  1626. }
  1627. const swiper = this;
  1628. const {
  1629. params,
  1630. wrapperEl
  1631. } = swiper;
  1632. if (swiper.animating && params.preventInteractionOnTransition) {
  1633. return false;
  1634. }
  1635. const minTranslate = swiper.minTranslate();
  1636. const maxTranslate = swiper.maxTranslate();
  1637. let newTranslate;
  1638. if (translateBounds && translate > minTranslate) newTranslate = minTranslate;else if (translateBounds && translate < maxTranslate) newTranslate = maxTranslate;else newTranslate = translate;
  1639. // Update progress
  1640. swiper.updateProgress(newTranslate);
  1641. if (params.cssMode) {
  1642. const isH = swiper.isHorizontal();
  1643. if (speed === 0) {
  1644. wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = -newTranslate;
  1645. } else {
  1646. if (!swiper.support.smoothScroll) {
  1647. animateCSSModeScroll({
  1648. swiper,
  1649. targetPosition: -newTranslate,
  1650. side: isH ? 'left' : 'top'
  1651. });
  1652. return true;
  1653. }
  1654. wrapperEl.scrollTo({
  1655. [isH ? 'left' : 'top']: -newTranslate,
  1656. behavior: 'smooth'
  1657. });
  1658. }
  1659. return true;
  1660. }
  1661. if (speed === 0) {
  1662. swiper.setTransition(0);
  1663. swiper.setTranslate(newTranslate);
  1664. if (runCallbacks) {
  1665. swiper.emit('beforeTransitionStart', speed, internal);
  1666. swiper.emit('transitionEnd');
  1667. }
  1668. } else {
  1669. swiper.setTransition(speed);
  1670. swiper.setTranslate(newTranslate);
  1671. if (runCallbacks) {
  1672. swiper.emit('beforeTransitionStart', speed, internal);
  1673. swiper.emit('transitionStart');
  1674. }
  1675. if (!swiper.animating) {
  1676. swiper.animating = true;
  1677. if (!swiper.onTranslateToWrapperTransitionEnd) {
  1678. swiper.onTranslateToWrapperTransitionEnd = function transitionEnd(e) {
  1679. if (!swiper || swiper.destroyed) return;
  1680. if (e.target !== this) return;
  1681. swiper.wrapperEl.removeEventListener('transitionend', swiper.onTranslateToWrapperTransitionEnd);
  1682. swiper.onTranslateToWrapperTransitionEnd = null;
  1683. delete swiper.onTranslateToWrapperTransitionEnd;
  1684. swiper.animating = false;
  1685. if (runCallbacks) {
  1686. swiper.emit('transitionEnd');
  1687. }
  1688. };
  1689. }
  1690. swiper.wrapperEl.addEventListener('transitionend', swiper.onTranslateToWrapperTransitionEnd);
  1691. }
  1692. }
  1693. return true;
  1694. }
  1695. var translate = {
  1696. getTranslate: getSwiperTranslate,
  1697. setTranslate,
  1698. minTranslate,
  1699. maxTranslate,
  1700. translateTo
  1701. };
  1702. function setTransition(duration, byController) {
  1703. const swiper = this;
  1704. if (!swiper.params.cssMode) {
  1705. swiper.wrapperEl.style.transitionDuration = `${duration}ms`;
  1706. swiper.wrapperEl.style.transitionDelay = duration === 0 ? `0ms` : '';
  1707. }
  1708. swiper.emit('setTransition', duration, byController);
  1709. }
  1710. function transitionEmit(_ref) {
  1711. let {
  1712. swiper,
  1713. runCallbacks,
  1714. direction,
  1715. step
  1716. } = _ref;
  1717. const {
  1718. activeIndex,
  1719. previousIndex
  1720. } = swiper;
  1721. let dir = direction;
  1722. if (!dir) {
  1723. if (activeIndex > previousIndex) dir = 'next';else if (activeIndex < previousIndex) dir = 'prev';else dir = 'reset';
  1724. }
  1725. swiper.emit(`transition${step}`);
  1726. if (runCallbacks && dir === 'reset') {
  1727. swiper.emit(`slideResetTransition${step}`);
  1728. } else if (runCallbacks && activeIndex !== previousIndex) {
  1729. swiper.emit(`slideChangeTransition${step}`);
  1730. if (dir === 'next') {
  1731. swiper.emit(`slideNextTransition${step}`);
  1732. } else {
  1733. swiper.emit(`slidePrevTransition${step}`);
  1734. }
  1735. }
  1736. }
  1737. function transitionStart(runCallbacks, direction) {
  1738. if (runCallbacks === void 0) {
  1739. runCallbacks = true;
  1740. }
  1741. const swiper = this;
  1742. const {
  1743. params
  1744. } = swiper;
  1745. if (params.cssMode) return;
  1746. if (params.autoHeight) {
  1747. swiper.updateAutoHeight();
  1748. }
  1749. transitionEmit({
  1750. swiper,
  1751. runCallbacks,
  1752. direction,
  1753. step: 'Start'
  1754. });
  1755. }
  1756. function transitionEnd(runCallbacks, direction) {
  1757. if (runCallbacks === void 0) {
  1758. runCallbacks = true;
  1759. }
  1760. const swiper = this;
  1761. const {
  1762. params
  1763. } = swiper;
  1764. swiper.animating = false;
  1765. if (params.cssMode) return;
  1766. swiper.setTransition(0);
  1767. transitionEmit({
  1768. swiper,
  1769. runCallbacks,
  1770. direction,
  1771. step: 'End'
  1772. });
  1773. }
  1774. var transition = {
  1775. setTransition,
  1776. transitionStart,
  1777. transitionEnd
  1778. };
  1779. function slideTo(index, speed, runCallbacks, internal, initial) {
  1780. if (index === void 0) {
  1781. index = 0;
  1782. }
  1783. if (runCallbacks === void 0) {
  1784. runCallbacks = true;
  1785. }
  1786. if (typeof index === 'string') {
  1787. index = parseInt(index, 10);
  1788. }
  1789. const swiper = this;
  1790. let slideIndex = index;
  1791. if (slideIndex < 0) slideIndex = 0;
  1792. const {
  1793. params,
  1794. snapGrid,
  1795. slidesGrid,
  1796. previousIndex,
  1797. activeIndex,
  1798. rtlTranslate: rtl,
  1799. wrapperEl,
  1800. enabled
  1801. } = swiper;
  1802. if (!enabled && !internal && !initial || swiper.destroyed || swiper.animating && params.preventInteractionOnTransition) {
  1803. return false;
  1804. }
  1805. if (typeof speed === 'undefined') {
  1806. speed = swiper.params.speed;
  1807. }
  1808. const skip = Math.min(swiper.params.slidesPerGroupSkip, slideIndex);
  1809. let snapIndex = skip + Math.floor((slideIndex - skip) / swiper.params.slidesPerGroup);
  1810. if (snapIndex >= snapGrid.length) snapIndex = snapGrid.length - 1;
  1811. const translate = -snapGrid[snapIndex];
  1812. // Normalize slideIndex
  1813. if (params.normalizeSlideIndex) {
  1814. for (let i = 0; i < slidesGrid.length; i += 1) {
  1815. const normalizedTranslate = -Math.floor(translate * 100);
  1816. const normalizedGrid = Math.floor(slidesGrid[i] * 100);
  1817. const normalizedGridNext = Math.floor(slidesGrid[i + 1] * 100);
  1818. if (typeof slidesGrid[i + 1] !== 'undefined') {
  1819. if (normalizedTranslate >= normalizedGrid && normalizedTranslate < normalizedGridNext - (normalizedGridNext - normalizedGrid) / 2) {
  1820. slideIndex = i;
  1821. } else if (normalizedTranslate >= normalizedGrid && normalizedTranslate < normalizedGridNext) {
  1822. slideIndex = i + 1;
  1823. }
  1824. } else if (normalizedTranslate >= normalizedGrid) {
  1825. slideIndex = i;
  1826. }
  1827. }
  1828. }
  1829. // Directions locks
  1830. if (swiper.initialized && slideIndex !== activeIndex) {
  1831. if (!swiper.allowSlideNext && (rtl ? translate > swiper.translate && translate > swiper.minTranslate() : translate < swiper.translate && translate < swiper.minTranslate())) {
  1832. return false;
  1833. }
  1834. if (!swiper.allowSlidePrev && translate > swiper.translate && translate > swiper.maxTranslate()) {
  1835. if ((activeIndex || 0) !== slideIndex) {
  1836. return false;
  1837. }
  1838. }
  1839. }
  1840. if (slideIndex !== (previousIndex || 0) && runCallbacks) {
  1841. swiper.emit('beforeSlideChangeStart');
  1842. }
  1843. // Update progress
  1844. swiper.updateProgress(translate);
  1845. let direction;
  1846. if (slideIndex > activeIndex) direction = 'next';else if (slideIndex < activeIndex) direction = 'prev';else direction = 'reset';
  1847. // initial virtual
  1848. const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
  1849. const isInitialVirtual = isVirtual && initial;
  1850. // Update Index
  1851. if (!isInitialVirtual && (rtl && -translate === swiper.translate || !rtl && translate === swiper.translate)) {
  1852. swiper.updateActiveIndex(slideIndex);
  1853. // Update Height
  1854. if (params.autoHeight) {
  1855. swiper.updateAutoHeight();
  1856. }
  1857. swiper.updateSlidesClasses();
  1858. if (params.effect !== 'slide') {
  1859. swiper.setTranslate(translate);
  1860. }
  1861. if (direction !== 'reset') {
  1862. swiper.transitionStart(runCallbacks, direction);
  1863. swiper.transitionEnd(runCallbacks, direction);
  1864. }
  1865. return false;
  1866. }
  1867. if (params.cssMode) {
  1868. const isH = swiper.isHorizontal();
  1869. const t = rtl ? translate : -translate;
  1870. if (speed === 0) {
  1871. if (isVirtual) {
  1872. swiper.wrapperEl.style.scrollSnapType = 'none';
  1873. swiper._immediateVirtual = true;
  1874. }
  1875. if (isVirtual && !swiper._cssModeVirtualInitialSet && swiper.params.initialSlide > 0) {
  1876. swiper._cssModeVirtualInitialSet = true;
  1877. requestAnimationFrame(() => {
  1878. wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = t;
  1879. });
  1880. } else {
  1881. wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = t;
  1882. }
  1883. if (isVirtual) {
  1884. requestAnimationFrame(() => {
  1885. swiper.wrapperEl.style.scrollSnapType = '';
  1886. swiper._immediateVirtual = false;
  1887. });
  1888. }
  1889. } else {
  1890. if (!swiper.support.smoothScroll) {
  1891. animateCSSModeScroll({
  1892. swiper,
  1893. targetPosition: t,
  1894. side: isH ? 'left' : 'top'
  1895. });
  1896. return true;
  1897. }
  1898. wrapperEl.scrollTo({
  1899. [isH ? 'left' : 'top']: t,
  1900. behavior: 'smooth'
  1901. });
  1902. }
  1903. return true;
  1904. }
  1905. const browser = getBrowser();
  1906. const isSafari = browser.isSafari;
  1907. if (isVirtual && !initial && isSafari && swiper.isElement) {
  1908. swiper.virtual.update(false, false, slideIndex);
  1909. }
  1910. swiper.setTransition(speed);
  1911. swiper.setTranslate(translate);
  1912. swiper.updateActiveIndex(slideIndex);
  1913. swiper.updateSlidesClasses();
  1914. swiper.emit('beforeTransitionStart', speed, internal);
  1915. swiper.transitionStart(runCallbacks, direction);
  1916. if (speed === 0) {
  1917. swiper.transitionEnd(runCallbacks, direction);
  1918. } else if (!swiper.animating) {
  1919. swiper.animating = true;
  1920. if (!swiper.onSlideToWrapperTransitionEnd) {
  1921. swiper.onSlideToWrapperTransitionEnd = function transitionEnd(e) {
  1922. if (!swiper || swiper.destroyed) return;
  1923. if (e.target !== this) return;
  1924. swiper.wrapperEl.removeEventListener('transitionend', swiper.onSlideToWrapperTransitionEnd);
  1925. swiper.onSlideToWrapperTransitionEnd = null;
  1926. delete swiper.onSlideToWrapperTransitionEnd;
  1927. swiper.transitionEnd(runCallbacks, direction);
  1928. };
  1929. }
  1930. swiper.wrapperEl.addEventListener('transitionend', swiper.onSlideToWrapperTransitionEnd);
  1931. }
  1932. return true;
  1933. }
  1934. function slideToLoop(index, speed, runCallbacks, internal) {
  1935. if (index === void 0) {
  1936. index = 0;
  1937. }
  1938. if (runCallbacks === void 0) {
  1939. runCallbacks = true;
  1940. }
  1941. if (typeof index === 'string') {
  1942. const indexAsNumber = parseInt(index, 10);
  1943. index = indexAsNumber;
  1944. }
  1945. const swiper = this;
  1946. if (swiper.destroyed) return;
  1947. if (typeof speed === 'undefined') {
  1948. speed = swiper.params.speed;
  1949. }
  1950. const gridEnabled = swiper.grid && swiper.params.grid && swiper.params.grid.rows > 1;
  1951. let newIndex = index;
  1952. if (swiper.params.loop) {
  1953. if (swiper.virtual && swiper.params.virtual.enabled) {
  1954. // eslint-disable-next-line
  1955. newIndex = newIndex + swiper.virtual.slidesBefore;
  1956. } else {
  1957. let targetSlideIndex;
  1958. if (gridEnabled) {
  1959. const slideIndex = newIndex * swiper.params.grid.rows;
  1960. targetSlideIndex = swiper.slides.find(slideEl => slideEl.getAttribute('data-swiper-slide-index') * 1 === slideIndex).column;
  1961. } else {
  1962. targetSlideIndex = swiper.getSlideIndexByData(newIndex);
  1963. }
  1964. const cols = gridEnabled ? Math.ceil(swiper.slides.length / swiper.params.grid.rows) : swiper.slides.length;
  1965. const {
  1966. centeredSlides
  1967. } = swiper.params;
  1968. let slidesPerView = swiper.params.slidesPerView;
  1969. if (slidesPerView === 'auto') {
  1970. slidesPerView = swiper.slidesPerViewDynamic();
  1971. } else {
  1972. slidesPerView = Math.ceil(parseFloat(swiper.params.slidesPerView, 10));
  1973. if (centeredSlides && slidesPerView % 2 === 0) {
  1974. slidesPerView = slidesPerView + 1;
  1975. }
  1976. }
  1977. let needLoopFix = cols - targetSlideIndex < slidesPerView;
  1978. if (centeredSlides) {
  1979. needLoopFix = needLoopFix || targetSlideIndex < Math.ceil(slidesPerView / 2);
  1980. }
  1981. if (internal && centeredSlides && swiper.params.slidesPerView !== 'auto' && !gridEnabled) {
  1982. needLoopFix = false;
  1983. }
  1984. if (needLoopFix) {
  1985. const direction = centeredSlides ? targetSlideIndex < swiper.activeIndex ? 'prev' : 'next' : targetSlideIndex - swiper.activeIndex - 1 < swiper.params.slidesPerView ? 'next' : 'prev';
  1986. swiper.loopFix({
  1987. direction,
  1988. slideTo: true,
  1989. activeSlideIndex: direction === 'next' ? targetSlideIndex + 1 : targetSlideIndex - cols + 1,
  1990. slideRealIndex: direction === 'next' ? swiper.realIndex : undefined
  1991. });
  1992. }
  1993. if (gridEnabled) {
  1994. const slideIndex = newIndex * swiper.params.grid.rows;
  1995. newIndex = swiper.slides.find(slideEl => slideEl.getAttribute('data-swiper-slide-index') * 1 === slideIndex).column;
  1996. } else {
  1997. newIndex = swiper.getSlideIndexByData(newIndex);
  1998. }
  1999. }
  2000. }
  2001. requestAnimationFrame(() => {
  2002. swiper.slideTo(newIndex, speed, runCallbacks, internal);
  2003. });
  2004. return swiper;
  2005. }
  2006. /* eslint no-unused-vars: "off" */
  2007. function slideNext(speed, runCallbacks, internal) {
  2008. if (runCallbacks === void 0) {
  2009. runCallbacks = true;
  2010. }
  2011. const swiper = this;
  2012. const {
  2013. enabled,
  2014. params,
  2015. animating
  2016. } = swiper;
  2017. if (!enabled || swiper.destroyed) return swiper;
  2018. if (typeof speed === 'undefined') {
  2019. speed = swiper.params.speed;
  2020. }
  2021. let perGroup = params.slidesPerGroup;
  2022. if (params.slidesPerView === 'auto' && params.slidesPerGroup === 1 && params.slidesPerGroupAuto) {
  2023. perGroup = Math.max(swiper.slidesPerViewDynamic('current', true), 1);
  2024. }
  2025. const increment = swiper.activeIndex < params.slidesPerGroupSkip ? 1 : perGroup;
  2026. const isVirtual = swiper.virtual && params.virtual.enabled;
  2027. if (params.loop) {
  2028. if (animating && !isVirtual && params.loopPreventsSliding) return false;
  2029. swiper.loopFix({
  2030. direction: 'next'
  2031. });
  2032. // eslint-disable-next-line
  2033. swiper._clientLeft = swiper.wrapperEl.clientLeft;
  2034. if (swiper.activeIndex === swiper.slides.length - 1 && params.cssMode) {
  2035. requestAnimationFrame(() => {
  2036. swiper.slideTo(swiper.activeIndex + increment, speed, runCallbacks, internal);
  2037. });
  2038. return true;
  2039. }
  2040. }
  2041. if (params.rewind && swiper.isEnd) {
  2042. return swiper.slideTo(0, speed, runCallbacks, internal);
  2043. }
  2044. return swiper.slideTo(swiper.activeIndex + increment, speed, runCallbacks, internal);
  2045. }
  2046. /* eslint no-unused-vars: "off" */
  2047. function slidePrev(speed, runCallbacks, internal) {
  2048. if (runCallbacks === void 0) {
  2049. runCallbacks = true;
  2050. }
  2051. const swiper = this;
  2052. const {
  2053. params,
  2054. snapGrid,
  2055. slidesGrid,
  2056. rtlTranslate,
  2057. enabled,
  2058. animating
  2059. } = swiper;
  2060. if (!enabled || swiper.destroyed) return swiper;
  2061. if (typeof speed === 'undefined') {
  2062. speed = swiper.params.speed;
  2063. }
  2064. const isVirtual = swiper.virtual && params.virtual.enabled;
  2065. if (params.loop) {
  2066. if (animating && !isVirtual && params.loopPreventsSliding) return false;
  2067. swiper.loopFix({
  2068. direction: 'prev'
  2069. });
  2070. // eslint-disable-next-line
  2071. swiper._clientLeft = swiper.wrapperEl.clientLeft;
  2072. }
  2073. const translate = rtlTranslate ? swiper.translate : -swiper.translate;
  2074. function normalize(val) {
  2075. if (val < 0) return -Math.floor(Math.abs(val));
  2076. return Math.floor(val);
  2077. }
  2078. const normalizedTranslate = normalize(translate);
  2079. const normalizedSnapGrid = snapGrid.map(val => normalize(val));
  2080. const isFreeMode = params.freeMode && params.freeMode.enabled;
  2081. let prevSnap = snapGrid[normalizedSnapGrid.indexOf(normalizedTranslate) - 1];
  2082. if (typeof prevSnap === 'undefined' && (params.cssMode || isFreeMode)) {
  2083. let prevSnapIndex;
  2084. snapGrid.forEach((snap, snapIndex) => {
  2085. if (normalizedTranslate >= snap) {
  2086. // prevSnap = snap;
  2087. prevSnapIndex = snapIndex;
  2088. }
  2089. });
  2090. if (typeof prevSnapIndex !== 'undefined') {
  2091. prevSnap = isFreeMode ? snapGrid[prevSnapIndex] : snapGrid[prevSnapIndex > 0 ? prevSnapIndex - 1 : prevSnapIndex];
  2092. }
  2093. }
  2094. let prevIndex = 0;
  2095. if (typeof prevSnap !== 'undefined') {
  2096. prevIndex = slidesGrid.indexOf(prevSnap);
  2097. if (prevIndex < 0) prevIndex = swiper.activeIndex - 1;
  2098. if (params.slidesPerView === 'auto' && params.slidesPerGroup === 1 && params.slidesPerGroupAuto) {
  2099. prevIndex = prevIndex - swiper.slidesPerViewDynamic('previous', true) + 1;
  2100. prevIndex = Math.max(prevIndex, 0);
  2101. }
  2102. }
  2103. if (params.rewind && swiper.isBeginning) {
  2104. const lastIndex = swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual ? swiper.virtual.slides.length - 1 : swiper.slides.length - 1;
  2105. return swiper.slideTo(lastIndex, speed, runCallbacks, internal);
  2106. } else if (params.loop && swiper.activeIndex === 0 && params.cssMode) {
  2107. requestAnimationFrame(() => {
  2108. swiper.slideTo(prevIndex, speed, runCallbacks, internal);
  2109. });
  2110. return true;
  2111. }
  2112. return swiper.slideTo(prevIndex, speed, runCallbacks, internal);
  2113. }
  2114. /* eslint no-unused-vars: "off" */
  2115. function slideReset(speed, runCallbacks, internal) {
  2116. if (runCallbacks === void 0) {
  2117. runCallbacks = true;
  2118. }
  2119. const swiper = this;
  2120. if (swiper.destroyed) return;
  2121. if (typeof speed === 'undefined') {
  2122. speed = swiper.params.speed;
  2123. }
  2124. return swiper.slideTo(swiper.activeIndex, speed, runCallbacks, internal);
  2125. }
  2126. /* eslint no-unused-vars: "off" */
  2127. function slideToClosest(speed, runCallbacks, internal, threshold) {
  2128. if (runCallbacks === void 0) {
  2129. runCallbacks = true;
  2130. }
  2131. if (threshold === void 0) {
  2132. threshold = 0.5;
  2133. }
  2134. const swiper = this;
  2135. if (swiper.destroyed) return;
  2136. if (typeof speed === 'undefined') {
  2137. speed = swiper.params.speed;
  2138. }
  2139. let index = swiper.activeIndex;
  2140. const skip = Math.min(swiper.params.slidesPerGroupSkip, index);
  2141. const snapIndex = skip + Math.floor((index - skip) / swiper.params.slidesPerGroup);
  2142. const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
  2143. if (translate >= swiper.snapGrid[snapIndex]) {
  2144. // The current translate is on or after the current snap index, so the choice
  2145. // is between the current index and the one after it.
  2146. const currentSnap = swiper.snapGrid[snapIndex];
  2147. const nextSnap = swiper.snapGrid[snapIndex + 1];
  2148. if (translate - currentSnap > (nextSnap - currentSnap) * threshold) {
  2149. index += swiper.params.slidesPerGroup;
  2150. }
  2151. } else {
  2152. // The current translate is before the current snap index, so the choice
  2153. // is between the current index and the one before it.
  2154. const prevSnap = swiper.snapGrid[snapIndex - 1];
  2155. const currentSnap = swiper.snapGrid[snapIndex];
  2156. if (translate - prevSnap <= (currentSnap - prevSnap) * threshold) {
  2157. index -= swiper.params.slidesPerGroup;
  2158. }
  2159. }
  2160. index = Math.max(index, 0);
  2161. index = Math.min(index, swiper.slidesGrid.length - 1);
  2162. return swiper.slideTo(index, speed, runCallbacks, internal);
  2163. }
  2164. function slideToClickedSlide() {
  2165. const swiper = this;
  2166. if (swiper.destroyed) return;
  2167. const {
  2168. params,
  2169. slidesEl
  2170. } = swiper;
  2171. const slidesPerView = params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : params.slidesPerView;
  2172. let slideToIndex = swiper.getSlideIndexWhenGrid(swiper.clickedIndex);
  2173. let realIndex;
  2174. const slideSelector = swiper.isElement ? `swiper-slide` : `.${params.slideClass}`;
  2175. const isGrid = swiper.grid && swiper.params.grid && swiper.params.grid.rows > 1;
  2176. if (params.loop) {
  2177. if (swiper.animating) return;
  2178. realIndex = parseInt(swiper.clickedSlide.getAttribute('data-swiper-slide-index'), 10);
  2179. if (params.centeredSlides) {
  2180. swiper.slideToLoop(realIndex);
  2181. } else if (slideToIndex > (isGrid ? (swiper.slides.length - slidesPerView) / 2 - (swiper.params.grid.rows - 1) : swiper.slides.length - slidesPerView)) {
  2182. swiper.loopFix();
  2183. slideToIndex = swiper.getSlideIndex(elementChildren(slidesEl, `${slideSelector}[data-swiper-slide-index="${realIndex}"]`)[0]);
  2184. nextTick(() => {
  2185. swiper.slideTo(slideToIndex);
  2186. });
  2187. } else {
  2188. swiper.slideTo(slideToIndex);
  2189. }
  2190. } else {
  2191. swiper.slideTo(slideToIndex);
  2192. }
  2193. }
  2194. var slide = {
  2195. slideTo,
  2196. slideToLoop,
  2197. slideNext,
  2198. slidePrev,
  2199. slideReset,
  2200. slideToClosest,
  2201. slideToClickedSlide
  2202. };
  2203. function loopCreate(slideRealIndex, initial) {
  2204. const swiper = this;
  2205. const {
  2206. params,
  2207. slidesEl
  2208. } = swiper;
  2209. if (!params.loop || swiper.virtual && swiper.params.virtual.enabled) return;
  2210. const initSlides = () => {
  2211. const slides = elementChildren(slidesEl, `.${params.slideClass}, swiper-slide`);
  2212. slides.forEach((el, index) => {
  2213. el.setAttribute('data-swiper-slide-index', index);
  2214. });
  2215. };
  2216. const clearBlankSlides = () => {
  2217. const slides = elementChildren(slidesEl, `.${params.slideBlankClass}`);
  2218. slides.forEach(el => {
  2219. el.remove();
  2220. });
  2221. if (slides.length > 0) {
  2222. swiper.recalcSlides();
  2223. swiper.updateSlides();
  2224. }
  2225. };
  2226. const gridEnabled = swiper.grid && params.grid && params.grid.rows > 1;
  2227. if (params.loopAddBlankSlides && (params.slidesPerGroup > 1 || gridEnabled)) {
  2228. clearBlankSlides();
  2229. }
  2230. const slidesPerGroup = params.slidesPerGroup * (gridEnabled ? params.grid.rows : 1);
  2231. const shouldFillGroup = swiper.slides.length % slidesPerGroup !== 0;
  2232. const shouldFillGrid = gridEnabled && swiper.slides.length % params.grid.rows !== 0;
  2233. const addBlankSlides = amountOfSlides => {
  2234. for (let i = 0; i < amountOfSlides; i += 1) {
  2235. const slideEl = swiper.isElement ? createElement('swiper-slide', [params.slideBlankClass]) : createElement('div', [params.slideClass, params.slideBlankClass]);
  2236. swiper.slidesEl.append(slideEl);
  2237. }
  2238. };
  2239. if (shouldFillGroup) {
  2240. if (params.loopAddBlankSlides) {
  2241. const slidesToAdd = slidesPerGroup - swiper.slides.length % slidesPerGroup;
  2242. addBlankSlides(slidesToAdd);
  2243. swiper.recalcSlides();
  2244. swiper.updateSlides();
  2245. } else {
  2246. showWarning('Swiper Loop Warning: The number of slides is not even to slidesPerGroup, loop mode may not function properly. You need to add more slides (or make duplicates, or empty slides)');
  2247. }
  2248. initSlides();
  2249. } else if (shouldFillGrid) {
  2250. if (params.loopAddBlankSlides) {
  2251. const slidesToAdd = params.grid.rows - swiper.slides.length % params.grid.rows;
  2252. addBlankSlides(slidesToAdd);
  2253. swiper.recalcSlides();
  2254. swiper.updateSlides();
  2255. } else {
  2256. showWarning('Swiper Loop Warning: The number of slides is not even to grid.rows, loop mode may not function properly. You need to add more slides (or make duplicates, or empty slides)');
  2257. }
  2258. initSlides();
  2259. } else {
  2260. initSlides();
  2261. }
  2262. swiper.loopFix({
  2263. slideRealIndex,
  2264. direction: params.centeredSlides ? undefined : 'next',
  2265. initial
  2266. });
  2267. }
  2268. function loopFix(_temp) {
  2269. let {
  2270. slideRealIndex,
  2271. slideTo = true,
  2272. direction,
  2273. setTranslate,
  2274. activeSlideIndex,
  2275. initial,
  2276. byController,
  2277. byMousewheel
  2278. } = _temp === void 0 ? {} : _temp;
  2279. const swiper = this;
  2280. if (!swiper.params.loop) return;
  2281. swiper.emit('beforeLoopFix');
  2282. const {
  2283. slides,
  2284. allowSlidePrev,
  2285. allowSlideNext,
  2286. slidesEl,
  2287. params
  2288. } = swiper;
  2289. const {
  2290. centeredSlides,
  2291. initialSlide
  2292. } = params;
  2293. swiper.allowSlidePrev = true;
  2294. swiper.allowSlideNext = true;
  2295. if (swiper.virtual && params.virtual.enabled) {
  2296. if (slideTo) {
  2297. if (!params.centeredSlides && swiper.snapIndex === 0) {
  2298. swiper.slideTo(swiper.virtual.slides.length, 0, false, true);
  2299. } else if (params.centeredSlides && swiper.snapIndex < params.slidesPerView) {
  2300. swiper.slideTo(swiper.virtual.slides.length + swiper.snapIndex, 0, false, true);
  2301. } else if (swiper.snapIndex === swiper.snapGrid.length - 1) {
  2302. swiper.slideTo(swiper.virtual.slidesBefore, 0, false, true);
  2303. }
  2304. }
  2305. swiper.allowSlidePrev = allowSlidePrev;
  2306. swiper.allowSlideNext = allowSlideNext;
  2307. swiper.emit('loopFix');
  2308. return;
  2309. }
  2310. let slidesPerView = params.slidesPerView;
  2311. if (slidesPerView === 'auto') {
  2312. slidesPerView = swiper.slidesPerViewDynamic();
  2313. } else {
  2314. slidesPerView = Math.ceil(parseFloat(params.slidesPerView, 10));
  2315. if (centeredSlides && slidesPerView % 2 === 0) {
  2316. slidesPerView = slidesPerView + 1;
  2317. }
  2318. }
  2319. const slidesPerGroup = params.slidesPerGroupAuto ? slidesPerView : params.slidesPerGroup;
  2320. let loopedSlides = centeredSlides ? Math.max(slidesPerGroup, Math.ceil(slidesPerView / 2)) : slidesPerGroup;
  2321. if (loopedSlides % slidesPerGroup !== 0) {
  2322. loopedSlides += slidesPerGroup - loopedSlides % slidesPerGroup;
  2323. }
  2324. loopedSlides += params.loopAdditionalSlides;
  2325. swiper.loopedSlides = loopedSlides;
  2326. const gridEnabled = swiper.grid && params.grid && params.grid.rows > 1;
  2327. if (slides.length < slidesPerView + loopedSlides || swiper.params.effect === 'cards' && slides.length < slidesPerView + loopedSlides * 2) {
  2328. showWarning('Swiper Loop Warning: The number of slides is not enough for loop mode, it will be disabled or not function properly. You need to add more slides (or make duplicates) or lower the values of slidesPerView and slidesPerGroup parameters');
  2329. } else if (gridEnabled && params.grid.fill === 'row') {
  2330. showWarning('Swiper Loop Warning: Loop mode is not compatible with grid.fill = `row`');
  2331. }
  2332. const prependSlidesIndexes = [];
  2333. const appendSlidesIndexes = [];
  2334. const cols = gridEnabled ? Math.ceil(slides.length / params.grid.rows) : slides.length;
  2335. const isInitialOverflow = initial && cols - initialSlide < slidesPerView && !centeredSlides;
  2336. let activeIndex = isInitialOverflow ? initialSlide : swiper.activeIndex;
  2337. if (typeof activeSlideIndex === 'undefined') {
  2338. activeSlideIndex = swiper.getSlideIndex(slides.find(el => el.classList.contains(params.slideActiveClass)));
  2339. } else {
  2340. activeIndex = activeSlideIndex;
  2341. }
  2342. const isNext = direction === 'next' || !direction;
  2343. const isPrev = direction === 'prev' || !direction;
  2344. let slidesPrepended = 0;
  2345. let slidesAppended = 0;
  2346. const activeColIndex = gridEnabled ? slides[activeSlideIndex].column : activeSlideIndex;
  2347. const activeColIndexWithShift = activeColIndex + (centeredSlides && typeof setTranslate === 'undefined' ? -slidesPerView / 2 + 0.5 : 0);
  2348. // prepend last slides before start
  2349. if (activeColIndexWithShift < loopedSlides) {
  2350. slidesPrepended = Math.max(loopedSlides - activeColIndexWithShift, slidesPerGroup);
  2351. for (let i = 0; i < loopedSlides - activeColIndexWithShift; i += 1) {
  2352. const index = i - Math.floor(i / cols) * cols;
  2353. if (gridEnabled) {
  2354. const colIndexToPrepend = cols - index - 1;
  2355. for (let i = slides.length - 1; i >= 0; i -= 1) {
  2356. if (slides[i].column === colIndexToPrepend) prependSlidesIndexes.push(i);
  2357. }
  2358. // slides.forEach((slide, slideIndex) => {
  2359. // if (slide.column === colIndexToPrepend) prependSlidesIndexes.push(slideIndex);
  2360. // });
  2361. } else {
  2362. prependSlidesIndexes.push(cols - index - 1);
  2363. }
  2364. }
  2365. } else if (activeColIndexWithShift + slidesPerView > cols - loopedSlides) {
  2366. slidesAppended = Math.max(activeColIndexWithShift - (cols - loopedSlides * 2), slidesPerGroup);
  2367. if (isInitialOverflow) {
  2368. slidesAppended = Math.max(slidesAppended, slidesPerView - cols + initialSlide + 1);
  2369. }
  2370. for (let i = 0; i < slidesAppended; i += 1) {
  2371. const index = i - Math.floor(i / cols) * cols;
  2372. if (gridEnabled) {
  2373. slides.forEach((slide, slideIndex) => {
  2374. if (slide.column === index) appendSlidesIndexes.push(slideIndex);
  2375. });
  2376. } else {
  2377. appendSlidesIndexes.push(index);
  2378. }
  2379. }
  2380. }
  2381. swiper.__preventObserver__ = true;
  2382. requestAnimationFrame(() => {
  2383. swiper.__preventObserver__ = false;
  2384. });
  2385. if (swiper.params.effect === 'cards' && slides.length < slidesPerView + loopedSlides * 2) {
  2386. if (appendSlidesIndexes.includes(activeSlideIndex)) {
  2387. appendSlidesIndexes.splice(appendSlidesIndexes.indexOf(activeSlideIndex), 1);
  2388. }
  2389. if (prependSlidesIndexes.includes(activeSlideIndex)) {
  2390. prependSlidesIndexes.splice(prependSlidesIndexes.indexOf(activeSlideIndex), 1);
  2391. }
  2392. }
  2393. if (isPrev) {
  2394. prependSlidesIndexes.forEach(index => {
  2395. slides[index].swiperLoopMoveDOM = true;
  2396. slidesEl.prepend(slides[index]);
  2397. slides[index].swiperLoopMoveDOM = false;
  2398. });
  2399. }
  2400. if (isNext) {
  2401. appendSlidesIndexes.forEach(index => {
  2402. slides[index].swiperLoopMoveDOM = true;
  2403. slidesEl.append(slides[index]);
  2404. slides[index].swiperLoopMoveDOM = false;
  2405. });
  2406. }
  2407. swiper.recalcSlides();
  2408. if (params.slidesPerView === 'auto') {
  2409. swiper.updateSlides();
  2410. } else if (gridEnabled && (prependSlidesIndexes.length > 0 && isPrev || appendSlidesIndexes.length > 0 && isNext)) {
  2411. swiper.slides.forEach((slide, slideIndex) => {
  2412. swiper.grid.updateSlide(slideIndex, slide, swiper.slides);
  2413. });
  2414. }
  2415. if (params.watchSlidesProgress) {
  2416. swiper.updateSlidesOffset();
  2417. }
  2418. if (slideTo) {
  2419. if (prependSlidesIndexes.length > 0 && isPrev) {
  2420. if (typeof slideRealIndex === 'undefined') {
  2421. const currentSlideTranslate = swiper.slidesGrid[activeIndex];
  2422. const newSlideTranslate = swiper.slidesGrid[activeIndex + slidesPrepended];
  2423. const diff = newSlideTranslate - currentSlideTranslate;
  2424. if (byMousewheel) {
  2425. swiper.setTranslate(swiper.translate - diff);
  2426. } else {
  2427. swiper.slideTo(activeIndex + Math.ceil(slidesPrepended), 0, false, true);
  2428. if (setTranslate) {
  2429. swiper.touchEventsData.startTranslate = swiper.touchEventsData.startTranslate - diff;
  2430. swiper.touchEventsData.currentTranslate = swiper.touchEventsData.currentTranslate - diff;
  2431. }
  2432. }
  2433. } else {
  2434. if (setTranslate) {
  2435. const shift = gridEnabled ? prependSlidesIndexes.length / params.grid.rows : prependSlidesIndexes.length;
  2436. swiper.slideTo(swiper.activeIndex + shift, 0, false, true);
  2437. swiper.touchEventsData.currentTranslate = swiper.translate;
  2438. }
  2439. }
  2440. } else if (appendSlidesIndexes.length > 0 && isNext) {
  2441. if (typeof slideRealIndex === 'undefined') {
  2442. const currentSlideTranslate = swiper.slidesGrid[activeIndex];
  2443. const newSlideTranslate = swiper.slidesGrid[activeIndex - slidesAppended];
  2444. const diff = newSlideTranslate - currentSlideTranslate;
  2445. if (byMousewheel) {
  2446. swiper.setTranslate(swiper.translate - diff);
  2447. } else {
  2448. swiper.slideTo(activeIndex - slidesAppended, 0, false, true);
  2449. if (setTranslate) {
  2450. swiper.touchEventsData.startTranslate = swiper.touchEventsData.startTranslate - diff;
  2451. swiper.touchEventsData.currentTranslate = swiper.touchEventsData.currentTranslate - diff;
  2452. }
  2453. }
  2454. } else {
  2455. const shift = gridEnabled ? appendSlidesIndexes.length / params.grid.rows : appendSlidesIndexes.length;
  2456. swiper.slideTo(swiper.activeIndex - shift, 0, false, true);
  2457. }
  2458. }
  2459. }
  2460. swiper.allowSlidePrev = allowSlidePrev;
  2461. swiper.allowSlideNext = allowSlideNext;
  2462. if (swiper.controller && swiper.controller.control && !byController) {
  2463. const loopParams = {
  2464. slideRealIndex,
  2465. direction,
  2466. setTranslate,
  2467. activeSlideIndex,
  2468. byController: true
  2469. };
  2470. if (Array.isArray(swiper.controller.control)) {
  2471. swiper.controller.control.forEach(c => {
  2472. if (!c.destroyed && c.params.loop) c.loopFix({
  2473. ...loopParams,
  2474. slideTo: c.params.slidesPerView === params.slidesPerView ? slideTo : false
  2475. });
  2476. });
  2477. } else if (swiper.controller.control instanceof swiper.constructor && swiper.controller.control.params.loop) {
  2478. swiper.controller.control.loopFix({
  2479. ...loopParams,
  2480. slideTo: swiper.controller.control.params.slidesPerView === params.slidesPerView ? slideTo : false
  2481. });
  2482. }
  2483. }
  2484. swiper.emit('loopFix');
  2485. }
  2486. function loopDestroy() {
  2487. const swiper = this;
  2488. const {
  2489. params,
  2490. slidesEl
  2491. } = swiper;
  2492. if (!params.loop || !slidesEl || swiper.virtual && swiper.params.virtual.enabled) return;
  2493. swiper.recalcSlides();
  2494. const newSlidesOrder = [];
  2495. swiper.slides.forEach(slideEl => {
  2496. const index = typeof slideEl.swiperSlideIndex === 'undefined' ? slideEl.getAttribute('data-swiper-slide-index') * 1 : slideEl.swiperSlideIndex;
  2497. newSlidesOrder[index] = slideEl;
  2498. });
  2499. swiper.slides.forEach(slideEl => {
  2500. slideEl.removeAttribute('data-swiper-slide-index');
  2501. });
  2502. newSlidesOrder.forEach(slideEl => {
  2503. slidesEl.append(slideEl);
  2504. });
  2505. swiper.recalcSlides();
  2506. swiper.slideTo(swiper.realIndex, 0);
  2507. }
  2508. var loop = {
  2509. loopCreate,
  2510. loopFix,
  2511. loopDestroy
  2512. };
  2513. function setGrabCursor(moving) {
  2514. const swiper = this;
  2515. if (!swiper.params.simulateTouch || swiper.params.watchOverflow && swiper.isLocked || swiper.params.cssMode) return;
  2516. const el = swiper.params.touchEventsTarget === 'container' ? swiper.el : swiper.wrapperEl;
  2517. if (swiper.isElement) {
  2518. swiper.__preventObserver__ = true;
  2519. }
  2520. el.style.cursor = 'move';
  2521. el.style.cursor = moving ? 'grabbing' : 'grab';
  2522. if (swiper.isElement) {
  2523. requestAnimationFrame(() => {
  2524. swiper.__preventObserver__ = false;
  2525. });
  2526. }
  2527. }
  2528. function unsetGrabCursor() {
  2529. const swiper = this;
  2530. if (swiper.params.watchOverflow && swiper.isLocked || swiper.params.cssMode) {
  2531. return;
  2532. }
  2533. if (swiper.isElement) {
  2534. swiper.__preventObserver__ = true;
  2535. }
  2536. swiper[swiper.params.touchEventsTarget === 'container' ? 'el' : 'wrapperEl'].style.cursor = '';
  2537. if (swiper.isElement) {
  2538. requestAnimationFrame(() => {
  2539. swiper.__preventObserver__ = false;
  2540. });
  2541. }
  2542. }
  2543. var grabCursor = {
  2544. setGrabCursor,
  2545. unsetGrabCursor
  2546. };
  2547. // Modified from https://stackoverflow.com/questions/54520554/custom-element-getrootnode-closest-function-crossing-multiple-parent-shadowd
  2548. function closestElement(selector, base) {
  2549. if (base === void 0) {
  2550. base = this;
  2551. }
  2552. function __closestFrom(el) {
  2553. if (!el || el === getDocument() || el === getWindow()) return null;
  2554. if (el.assignedSlot) el = el.assignedSlot;
  2555. const found = el.closest(selector);
  2556. if (!found && !el.getRootNode) {
  2557. return null;
  2558. }
  2559. return found || __closestFrom(el.getRootNode().host);
  2560. }
  2561. return __closestFrom(base);
  2562. }
  2563. function preventEdgeSwipe(swiper, event, startX) {
  2564. const window = getWindow();
  2565. const {
  2566. params
  2567. } = swiper;
  2568. const edgeSwipeDetection = params.edgeSwipeDetection;
  2569. const edgeSwipeThreshold = params.edgeSwipeThreshold;
  2570. if (edgeSwipeDetection && (startX <= edgeSwipeThreshold || startX >= window.innerWidth - edgeSwipeThreshold)) {
  2571. if (edgeSwipeDetection === 'prevent') {
  2572. event.preventDefault();
  2573. return true;
  2574. }
  2575. return false;
  2576. }
  2577. return true;
  2578. }
  2579. function onTouchStart(event) {
  2580. const swiper = this;
  2581. const document = getDocument();
  2582. let e = event;
  2583. if (e.originalEvent) e = e.originalEvent;
  2584. const data = swiper.touchEventsData;
  2585. if (e.type === 'pointerdown') {
  2586. if (data.pointerId !== null && data.pointerId !== e.pointerId) {
  2587. return;
  2588. }
  2589. data.pointerId = e.pointerId;
  2590. } else if (e.type === 'touchstart' && e.targetTouches.length === 1) {
  2591. data.touchId = e.targetTouches[0].identifier;
  2592. }
  2593. if (e.type === 'touchstart') {
  2594. // don't proceed touch event
  2595. preventEdgeSwipe(swiper, e, e.targetTouches[0].pageX);
  2596. return;
  2597. }
  2598. const {
  2599. params,
  2600. touches,
  2601. enabled
  2602. } = swiper;
  2603. if (!enabled) return;
  2604. if (!params.simulateTouch && e.pointerType === 'mouse') return;
  2605. if (swiper.animating && params.preventInteractionOnTransition) {
  2606. return;
  2607. }
  2608. if (!swiper.animating && params.cssMode && params.loop) {
  2609. swiper.loopFix();
  2610. }
  2611. let targetEl = e.target;
  2612. if (params.touchEventsTarget === 'wrapper') {
  2613. if (!elementIsChildOf(targetEl, swiper.wrapperEl)) return;
  2614. }
  2615. if ('which' in e && e.which === 3) return;
  2616. if ('button' in e && e.button > 0) return;
  2617. if (data.isTouched && data.isMoved) return;
  2618. // change target el for shadow root component
  2619. const swipingClassHasValue = !!params.noSwipingClass && params.noSwipingClass !== '';
  2620. // eslint-disable-next-line
  2621. const eventPath = e.composedPath ? e.composedPath() : e.path;
  2622. if (swipingClassHasValue && e.target && e.target.shadowRoot && eventPath) {
  2623. targetEl = eventPath[0];
  2624. }
  2625. const noSwipingSelector = params.noSwipingSelector ? params.noSwipingSelector : `.${params.noSwipingClass}`;
  2626. const isTargetShadow = !!(e.target && e.target.shadowRoot);
  2627. // use closestElement for shadow root element to get the actual closest for nested shadow root element
  2628. if (params.noSwiping && (isTargetShadow ? closestElement(noSwipingSelector, targetEl) : targetEl.closest(noSwipingSelector))) {
  2629. swiper.allowClick = true;
  2630. return;
  2631. }
  2632. if (params.swipeHandler) {
  2633. if (!targetEl.closest(params.swipeHandler)) return;
  2634. }
  2635. touches.currentX = e.pageX;
  2636. touches.currentY = e.pageY;
  2637. const startX = touches.currentX;
  2638. const startY = touches.currentY;
  2639. // Do NOT start if iOS edge swipe is detected. Otherwise iOS app cannot swipe-to-go-back anymore
  2640. if (!preventEdgeSwipe(swiper, e, startX)) {
  2641. return;
  2642. }
  2643. Object.assign(data, {
  2644. isTouched: true,
  2645. isMoved: false,
  2646. allowTouchCallbacks: true,
  2647. isScrolling: undefined,
  2648. startMoving: undefined
  2649. });
  2650. touches.startX = startX;
  2651. touches.startY = startY;
  2652. data.touchStartTime = now();
  2653. swiper.allowClick = true;
  2654. swiper.updateSize();
  2655. swiper.swipeDirection = undefined;
  2656. if (params.threshold > 0) data.allowThresholdMove = false;
  2657. let preventDefault = true;
  2658. if (targetEl.matches(data.focusableElements)) {
  2659. preventDefault = false;
  2660. if (targetEl.nodeName === 'SELECT') {
  2661. data.isTouched = false;
  2662. }
  2663. }
  2664. if (document.activeElement && document.activeElement.matches(data.focusableElements) && document.activeElement !== targetEl && (e.pointerType === 'mouse' || e.pointerType !== 'mouse' && !targetEl.matches(data.focusableElements))) {
  2665. document.activeElement.blur();
  2666. }
  2667. const shouldPreventDefault = preventDefault && swiper.allowTouchMove && params.touchStartPreventDefault;
  2668. if ((params.touchStartForcePreventDefault || shouldPreventDefault) && !targetEl.isContentEditable) {
  2669. e.preventDefault();
  2670. }
  2671. if (params.freeMode && params.freeMode.enabled && swiper.freeMode && swiper.animating && !params.cssMode) {
  2672. swiper.freeMode.onTouchStart();
  2673. }
  2674. swiper.emit('touchStart', e);
  2675. }
  2676. function onTouchMove(event) {
  2677. const document = getDocument();
  2678. const swiper = this;
  2679. const data = swiper.touchEventsData;
  2680. const {
  2681. params,
  2682. touches,
  2683. rtlTranslate: rtl,
  2684. enabled
  2685. } = swiper;
  2686. if (!enabled) return;
  2687. if (!params.simulateTouch && event.pointerType === 'mouse') return;
  2688. let e = event;
  2689. if (e.originalEvent) e = e.originalEvent;
  2690. if (e.type === 'pointermove') {
  2691. if (data.touchId !== null) return; // return from pointer if we use touch
  2692. const id = e.pointerId;
  2693. if (id !== data.pointerId) return;
  2694. }
  2695. let targetTouch;
  2696. if (e.type === 'touchmove') {
  2697. targetTouch = [...e.changedTouches].find(t => t.identifier === data.touchId);
  2698. if (!targetTouch || targetTouch.identifier !== data.touchId) return;
  2699. } else {
  2700. targetTouch = e;
  2701. }
  2702. if (!data.isTouched) {
  2703. if (data.startMoving && data.isScrolling) {
  2704. swiper.emit('touchMoveOpposite', e);
  2705. }
  2706. return;
  2707. }
  2708. const pageX = targetTouch.pageX;
  2709. const pageY = targetTouch.pageY;
  2710. if (e.preventedByNestedSwiper) {
  2711. touches.startX = pageX;
  2712. touches.startY = pageY;
  2713. return;
  2714. }
  2715. if (!swiper.allowTouchMove) {
  2716. if (!e.target.matches(data.focusableElements)) {
  2717. swiper.allowClick = false;
  2718. }
  2719. if (data.isTouched) {
  2720. Object.assign(touches, {
  2721. startX: pageX,
  2722. startY: pageY,
  2723. currentX: pageX,
  2724. currentY: pageY
  2725. });
  2726. data.touchStartTime = now();
  2727. }
  2728. return;
  2729. }
  2730. if (params.touchReleaseOnEdges && !params.loop) {
  2731. if (swiper.isVertical()) {
  2732. // Vertical
  2733. if (pageY < touches.startY && swiper.translate <= swiper.maxTranslate() || pageY > touches.startY && swiper.translate >= swiper.minTranslate()) {
  2734. data.isTouched = false;
  2735. data.isMoved = false;
  2736. return;
  2737. }
  2738. } else if (rtl && (pageX > touches.startX && -swiper.translate <= swiper.maxTranslate() || pageX < touches.startX && -swiper.translate >= swiper.minTranslate())) {
  2739. return;
  2740. } else if (!rtl && (pageX < touches.startX && swiper.translate <= swiper.maxTranslate() || pageX > touches.startX && swiper.translate >= swiper.minTranslate())) {
  2741. return;
  2742. }
  2743. }
  2744. if (document.activeElement && document.activeElement.matches(data.focusableElements) && document.activeElement !== e.target && e.pointerType !== 'mouse') {
  2745. document.activeElement.blur();
  2746. }
  2747. if (document.activeElement) {
  2748. if (e.target === document.activeElement && e.target.matches(data.focusableElements)) {
  2749. data.isMoved = true;
  2750. swiper.allowClick = false;
  2751. return;
  2752. }
  2753. }
  2754. if (data.allowTouchCallbacks) {
  2755. swiper.emit('touchMove', e);
  2756. }
  2757. touches.previousX = touches.currentX;
  2758. touches.previousY = touches.currentY;
  2759. touches.currentX = pageX;
  2760. touches.currentY = pageY;
  2761. const diffX = touches.currentX - touches.startX;
  2762. const diffY = touches.currentY - touches.startY;
  2763. if (swiper.params.threshold && Math.sqrt(diffX ** 2 + diffY ** 2) < swiper.params.threshold) return;
  2764. if (typeof data.isScrolling === 'undefined') {
  2765. let touchAngle;
  2766. if (swiper.isHorizontal() && touches.currentY === touches.startY || swiper.isVertical() && touches.currentX === touches.startX) {
  2767. data.isScrolling = false;
  2768. } else {
  2769. // eslint-disable-next-line
  2770. if (diffX * diffX + diffY * diffY >= 25) {
  2771. touchAngle = Math.atan2(Math.abs(diffY), Math.abs(diffX)) * 180 / Math.PI;
  2772. data.isScrolling = swiper.isHorizontal() ? touchAngle > params.touchAngle : 90 - touchAngle > params.touchAngle;
  2773. }
  2774. }
  2775. }
  2776. if (data.isScrolling) {
  2777. swiper.emit('touchMoveOpposite', e);
  2778. }
  2779. if (typeof data.startMoving === 'undefined') {
  2780. if (touches.currentX !== touches.startX || touches.currentY !== touches.startY) {
  2781. data.startMoving = true;
  2782. }
  2783. }
  2784. if (data.isScrolling || e.type === 'touchmove' && data.preventTouchMoveFromPointerMove) {
  2785. data.isTouched = false;
  2786. return;
  2787. }
  2788. if (!data.startMoving) {
  2789. return;
  2790. }
  2791. swiper.allowClick = false;
  2792. if (!params.cssMode && e.cancelable) {
  2793. e.preventDefault();
  2794. }
  2795. if (params.touchMoveStopPropagation && !params.nested) {
  2796. e.stopPropagation();
  2797. }
  2798. let diff = swiper.isHorizontal() ? diffX : diffY;
  2799. let touchesDiff = swiper.isHorizontal() ? touches.currentX - touches.previousX : touches.currentY - touches.previousY;
  2800. if (params.oneWayMovement) {
  2801. diff = Math.abs(diff) * (rtl ? 1 : -1);
  2802. touchesDiff = Math.abs(touchesDiff) * (rtl ? 1 : -1);
  2803. }
  2804. touches.diff = diff;
  2805. diff *= params.touchRatio;
  2806. if (rtl) {
  2807. diff = -diff;
  2808. touchesDiff = -touchesDiff;
  2809. }
  2810. const prevTouchesDirection = swiper.touchesDirection;
  2811. swiper.swipeDirection = diff > 0 ? 'prev' : 'next';
  2812. swiper.touchesDirection = touchesDiff > 0 ? 'prev' : 'next';
  2813. const isLoop = swiper.params.loop && !params.cssMode;
  2814. const allowLoopFix = swiper.touchesDirection === 'next' && swiper.allowSlideNext || swiper.touchesDirection === 'prev' && swiper.allowSlidePrev;
  2815. if (!data.isMoved) {
  2816. if (isLoop && allowLoopFix) {
  2817. swiper.loopFix({
  2818. direction: swiper.swipeDirection
  2819. });
  2820. }
  2821. data.startTranslate = swiper.getTranslate();
  2822. swiper.setTransition(0);
  2823. if (swiper.animating) {
  2824. const evt = new window.CustomEvent('transitionend', {
  2825. bubbles: true,
  2826. cancelable: true,
  2827. detail: {
  2828. bySwiperTouchMove: true
  2829. }
  2830. });
  2831. swiper.wrapperEl.dispatchEvent(evt);
  2832. }
  2833. data.allowMomentumBounce = false;
  2834. // Grab Cursor
  2835. if (params.grabCursor && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) {
  2836. swiper.setGrabCursor(true);
  2837. }
  2838. swiper.emit('sliderFirstMove', e);
  2839. }
  2840. let loopFixed;
  2841. new Date().getTime();
  2842. if (params._loopSwapReset !== false && data.isMoved && data.allowThresholdMove && prevTouchesDirection !== swiper.touchesDirection && isLoop && allowLoopFix && Math.abs(diff) >= 1) {
  2843. Object.assign(touches, {
  2844. startX: pageX,
  2845. startY: pageY,
  2846. currentX: pageX,
  2847. currentY: pageY,
  2848. startTranslate: data.currentTranslate
  2849. });
  2850. data.loopSwapReset = true;
  2851. data.startTranslate = data.currentTranslate;
  2852. return;
  2853. }
  2854. swiper.emit('sliderMove', e);
  2855. data.isMoved = true;
  2856. data.currentTranslate = diff + data.startTranslate;
  2857. let disableParentSwiper = true;
  2858. let resistanceRatio = params.resistanceRatio;
  2859. if (params.touchReleaseOnEdges) {
  2860. resistanceRatio = 0;
  2861. }
  2862. if (diff > 0) {
  2863. if (isLoop && allowLoopFix && !loopFixed && data.allowThresholdMove && data.currentTranslate > (params.centeredSlides ? swiper.minTranslate() - swiper.slidesSizesGrid[swiper.activeIndex + 1] - (params.slidesPerView !== 'auto' && swiper.slides.length - params.slidesPerView >= 2 ? swiper.slidesSizesGrid[swiper.activeIndex + 1] + swiper.params.spaceBetween : 0) - swiper.params.spaceBetween : swiper.minTranslate())) {
  2864. swiper.loopFix({
  2865. direction: 'prev',
  2866. setTranslate: true,
  2867. activeSlideIndex: 0
  2868. });
  2869. }
  2870. if (data.currentTranslate > swiper.minTranslate()) {
  2871. disableParentSwiper = false;
  2872. if (params.resistance) {
  2873. data.currentTranslate = swiper.minTranslate() - 1 + (-swiper.minTranslate() + data.startTranslate + diff) ** resistanceRatio;
  2874. }
  2875. }
  2876. } else if (diff < 0) {
  2877. if (isLoop && allowLoopFix && !loopFixed && data.allowThresholdMove && data.currentTranslate < (params.centeredSlides ? swiper.maxTranslate() + swiper.slidesSizesGrid[swiper.slidesSizesGrid.length - 1] + swiper.params.spaceBetween + (params.slidesPerView !== 'auto' && swiper.slides.length - params.slidesPerView >= 2 ? swiper.slidesSizesGrid[swiper.slidesSizesGrid.length - 1] + swiper.params.spaceBetween : 0) : swiper.maxTranslate())) {
  2878. swiper.loopFix({
  2879. direction: 'next',
  2880. setTranslate: true,
  2881. activeSlideIndex: swiper.slides.length - (params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : Math.ceil(parseFloat(params.slidesPerView, 10)))
  2882. });
  2883. }
  2884. if (data.currentTranslate < swiper.maxTranslate()) {
  2885. disableParentSwiper = false;
  2886. if (params.resistance) {
  2887. data.currentTranslate = swiper.maxTranslate() + 1 - (swiper.maxTranslate() - data.startTranslate - diff) ** resistanceRatio;
  2888. }
  2889. }
  2890. }
  2891. if (disableParentSwiper) {
  2892. e.preventedByNestedSwiper = true;
  2893. }
  2894. // Directions locks
  2895. if (!swiper.allowSlideNext && swiper.swipeDirection === 'next' && data.currentTranslate < data.startTranslate) {
  2896. data.currentTranslate = data.startTranslate;
  2897. }
  2898. if (!swiper.allowSlidePrev && swiper.swipeDirection === 'prev' && data.currentTranslate > data.startTranslate) {
  2899. data.currentTranslate = data.startTranslate;
  2900. }
  2901. if (!swiper.allowSlidePrev && !swiper.allowSlideNext) {
  2902. data.currentTranslate = data.startTranslate;
  2903. }
  2904. // Threshold
  2905. if (params.threshold > 0) {
  2906. if (Math.abs(diff) > params.threshold || data.allowThresholdMove) {
  2907. if (!data.allowThresholdMove) {
  2908. data.allowThresholdMove = true;
  2909. touches.startX = touches.currentX;
  2910. touches.startY = touches.currentY;
  2911. data.currentTranslate = data.startTranslate;
  2912. touches.diff = swiper.isHorizontal() ? touches.currentX - touches.startX : touches.currentY - touches.startY;
  2913. return;
  2914. }
  2915. } else {
  2916. data.currentTranslate = data.startTranslate;
  2917. return;
  2918. }
  2919. }
  2920. if (!params.followFinger || params.cssMode) return;
  2921. // Update active index in free mode
  2922. if (params.freeMode && params.freeMode.enabled && swiper.freeMode || params.watchSlidesProgress) {
  2923. swiper.updateActiveIndex();
  2924. swiper.updateSlidesClasses();
  2925. }
  2926. if (params.freeMode && params.freeMode.enabled && swiper.freeMode) {
  2927. swiper.freeMode.onTouchMove();
  2928. }
  2929. // Update progress
  2930. swiper.updateProgress(data.currentTranslate);
  2931. // Update translate
  2932. swiper.setTranslate(data.currentTranslate);
  2933. }
  2934. function onTouchEnd(event) {
  2935. const swiper = this;
  2936. const data = swiper.touchEventsData;
  2937. let e = event;
  2938. if (e.originalEvent) e = e.originalEvent;
  2939. let targetTouch;
  2940. const isTouchEvent = e.type === 'touchend' || e.type === 'touchcancel';
  2941. if (!isTouchEvent) {
  2942. if (data.touchId !== null) return; // return from pointer if we use touch
  2943. if (e.pointerId !== data.pointerId) return;
  2944. targetTouch = e;
  2945. } else {
  2946. targetTouch = [...e.changedTouches].find(t => t.identifier === data.touchId);
  2947. if (!targetTouch || targetTouch.identifier !== data.touchId) return;
  2948. }
  2949. if (['pointercancel', 'pointerout', 'pointerleave', 'contextmenu'].includes(e.type)) {
  2950. const proceed = ['pointercancel', 'contextmenu'].includes(e.type) && (swiper.browser.isSafari || swiper.browser.isWebView);
  2951. if (!proceed) {
  2952. return;
  2953. }
  2954. }
  2955. data.pointerId = null;
  2956. data.touchId = null;
  2957. const {
  2958. params,
  2959. touches,
  2960. rtlTranslate: rtl,
  2961. slidesGrid,
  2962. enabled
  2963. } = swiper;
  2964. if (!enabled) return;
  2965. if (!params.simulateTouch && e.pointerType === 'mouse') return;
  2966. if (data.allowTouchCallbacks) {
  2967. swiper.emit('touchEnd', e);
  2968. }
  2969. data.allowTouchCallbacks = false;
  2970. if (!data.isTouched) {
  2971. if (data.isMoved && params.grabCursor) {
  2972. swiper.setGrabCursor(false);
  2973. }
  2974. data.isMoved = false;
  2975. data.startMoving = false;
  2976. return;
  2977. }
  2978. // Return Grab Cursor
  2979. if (params.grabCursor && data.isMoved && data.isTouched && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) {
  2980. swiper.setGrabCursor(false);
  2981. }
  2982. // Time diff
  2983. const touchEndTime = now();
  2984. const timeDiff = touchEndTime - data.touchStartTime;
  2985. // Tap, doubleTap, Click
  2986. if (swiper.allowClick) {
  2987. const pathTree = e.path || e.composedPath && e.composedPath();
  2988. swiper.updateClickedSlide(pathTree && pathTree[0] || e.target, pathTree);
  2989. swiper.emit('tap click', e);
  2990. if (timeDiff < 300 && touchEndTime - data.lastClickTime < 300) {
  2991. swiper.emit('doubleTap doubleClick', e);
  2992. }
  2993. }
  2994. data.lastClickTime = now();
  2995. nextTick(() => {
  2996. if (!swiper.destroyed) swiper.allowClick = true;
  2997. });
  2998. if (!data.isTouched || !data.isMoved || !swiper.swipeDirection || touches.diff === 0 && !data.loopSwapReset || data.currentTranslate === data.startTranslate && !data.loopSwapReset) {
  2999. data.isTouched = false;
  3000. data.isMoved = false;
  3001. data.startMoving = false;
  3002. return;
  3003. }
  3004. data.isTouched = false;
  3005. data.isMoved = false;
  3006. data.startMoving = false;
  3007. let currentPos;
  3008. if (params.followFinger) {
  3009. currentPos = rtl ? swiper.translate : -swiper.translate;
  3010. } else {
  3011. currentPos = -data.currentTranslate;
  3012. }
  3013. if (params.cssMode) {
  3014. return;
  3015. }
  3016. if (params.freeMode && params.freeMode.enabled) {
  3017. swiper.freeMode.onTouchEnd({
  3018. currentPos
  3019. });
  3020. return;
  3021. }
  3022. // Find current slide
  3023. const swipeToLast = currentPos >= -swiper.maxTranslate() && !swiper.params.loop;
  3024. let stopIndex = 0;
  3025. let groupSize = swiper.slidesSizesGrid[0];
  3026. for (let i = 0; i < slidesGrid.length; i += i < params.slidesPerGroupSkip ? 1 : params.slidesPerGroup) {
  3027. const increment = i < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup;
  3028. if (typeof slidesGrid[i + increment] !== 'undefined') {
  3029. if (swipeToLast || currentPos >= slidesGrid[i] && currentPos < slidesGrid[i + increment]) {
  3030. stopIndex = i;
  3031. groupSize = slidesGrid[i + increment] - slidesGrid[i];
  3032. }
  3033. } else if (swipeToLast || currentPos >= slidesGrid[i]) {
  3034. stopIndex = i;
  3035. groupSize = slidesGrid[slidesGrid.length - 1] - slidesGrid[slidesGrid.length - 2];
  3036. }
  3037. }
  3038. let rewindFirstIndex = null;
  3039. let rewindLastIndex = null;
  3040. if (params.rewind) {
  3041. if (swiper.isBeginning) {
  3042. rewindLastIndex = params.virtual && params.virtual.enabled && swiper.virtual ? swiper.virtual.slides.length - 1 : swiper.slides.length - 1;
  3043. } else if (swiper.isEnd) {
  3044. rewindFirstIndex = 0;
  3045. }
  3046. }
  3047. // Find current slide size
  3048. const ratio = (currentPos - slidesGrid[stopIndex]) / groupSize;
  3049. const increment = stopIndex < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup;
  3050. if (timeDiff > params.longSwipesMs) {
  3051. // Long touches
  3052. if (!params.longSwipes) {
  3053. swiper.slideTo(swiper.activeIndex);
  3054. return;
  3055. }
  3056. if (swiper.swipeDirection === 'next') {
  3057. if (ratio >= params.longSwipesRatio) swiper.slideTo(params.rewind && swiper.isEnd ? rewindFirstIndex : stopIndex + increment);else swiper.slideTo(stopIndex);
  3058. }
  3059. if (swiper.swipeDirection === 'prev') {
  3060. if (ratio > 1 - params.longSwipesRatio) {
  3061. swiper.slideTo(stopIndex + increment);
  3062. } else if (rewindLastIndex !== null && ratio < 0 && Math.abs(ratio) > params.longSwipesRatio) {
  3063. swiper.slideTo(rewindLastIndex);
  3064. } else {
  3065. swiper.slideTo(stopIndex);
  3066. }
  3067. }
  3068. } else {
  3069. // Short swipes
  3070. if (!params.shortSwipes) {
  3071. swiper.slideTo(swiper.activeIndex);
  3072. return;
  3073. }
  3074. const isNavButtonTarget = swiper.navigation && (e.target === swiper.navigation.nextEl || e.target === swiper.navigation.prevEl);
  3075. if (!isNavButtonTarget) {
  3076. if (swiper.swipeDirection === 'next') {
  3077. swiper.slideTo(rewindFirstIndex !== null ? rewindFirstIndex : stopIndex + increment);
  3078. }
  3079. if (swiper.swipeDirection === 'prev') {
  3080. swiper.slideTo(rewindLastIndex !== null ? rewindLastIndex : stopIndex);
  3081. }
  3082. } else if (e.target === swiper.navigation.nextEl) {
  3083. swiper.slideTo(stopIndex + increment);
  3084. } else {
  3085. swiper.slideTo(stopIndex);
  3086. }
  3087. }
  3088. }
  3089. function onResize() {
  3090. const swiper = this;
  3091. const {
  3092. params,
  3093. el
  3094. } = swiper;
  3095. if (el && el.offsetWidth === 0) return;
  3096. // Breakpoints
  3097. if (params.breakpoints) {
  3098. swiper.setBreakpoint();
  3099. }
  3100. // Save locks
  3101. const {
  3102. allowSlideNext,
  3103. allowSlidePrev,
  3104. snapGrid
  3105. } = swiper;
  3106. const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
  3107. // Disable locks on resize
  3108. swiper.allowSlideNext = true;
  3109. swiper.allowSlidePrev = true;
  3110. swiper.updateSize();
  3111. swiper.updateSlides();
  3112. swiper.updateSlidesClasses();
  3113. const isVirtualLoop = isVirtual && params.loop;
  3114. if ((params.slidesPerView === 'auto' || params.slidesPerView > 1) && swiper.isEnd && !swiper.isBeginning && !swiper.params.centeredSlides && !isVirtualLoop) {
  3115. swiper.slideTo(swiper.slides.length - 1, 0, false, true);
  3116. } else {
  3117. if (swiper.params.loop && !isVirtual) {
  3118. swiper.slideToLoop(swiper.realIndex, 0, false, true);
  3119. } else {
  3120. swiper.slideTo(swiper.activeIndex, 0, false, true);
  3121. }
  3122. }
  3123. if (swiper.autoplay && swiper.autoplay.running && swiper.autoplay.paused) {
  3124. clearTimeout(swiper.autoplay.resizeTimeout);
  3125. swiper.autoplay.resizeTimeout = setTimeout(() => {
  3126. if (swiper.autoplay && swiper.autoplay.running && swiper.autoplay.paused) {
  3127. swiper.autoplay.resume();
  3128. }
  3129. }, 500);
  3130. }
  3131. // Return locks after resize
  3132. swiper.allowSlidePrev = allowSlidePrev;
  3133. swiper.allowSlideNext = allowSlideNext;
  3134. if (swiper.params.watchOverflow && snapGrid !== swiper.snapGrid) {
  3135. swiper.checkOverflow();
  3136. }
  3137. }
  3138. function onClick(e) {
  3139. const swiper = this;
  3140. if (!swiper.enabled) return;
  3141. if (!swiper.allowClick) {
  3142. if (swiper.params.preventClicks) e.preventDefault();
  3143. if (swiper.params.preventClicksPropagation && swiper.animating) {
  3144. e.stopPropagation();
  3145. e.stopImmediatePropagation();
  3146. }
  3147. }
  3148. }
  3149. function onScroll() {
  3150. const swiper = this;
  3151. const {
  3152. wrapperEl,
  3153. rtlTranslate,
  3154. enabled
  3155. } = swiper;
  3156. if (!enabled) return;
  3157. swiper.previousTranslate = swiper.translate;
  3158. if (swiper.isHorizontal()) {
  3159. swiper.translate = -wrapperEl.scrollLeft;
  3160. } else {
  3161. swiper.translate = -wrapperEl.scrollTop;
  3162. }
  3163. // eslint-disable-next-line
  3164. if (swiper.translate === 0) swiper.translate = 0;
  3165. swiper.updateActiveIndex();
  3166. swiper.updateSlidesClasses();
  3167. let newProgress;
  3168. const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
  3169. if (translatesDiff === 0) {
  3170. newProgress = 0;
  3171. } else {
  3172. newProgress = (swiper.translate - swiper.minTranslate()) / translatesDiff;
  3173. }
  3174. if (newProgress !== swiper.progress) {
  3175. swiper.updateProgress(rtlTranslate ? -swiper.translate : swiper.translate);
  3176. }
  3177. swiper.emit('setTranslate', swiper.translate, false);
  3178. }
  3179. function onLoad(e) {
  3180. const swiper = this;
  3181. processLazyPreloader(swiper, e.target);
  3182. if (swiper.params.cssMode || swiper.params.slidesPerView !== 'auto' && !swiper.params.autoHeight) {
  3183. return;
  3184. }
  3185. swiper.update();
  3186. }
  3187. function onDocumentTouchStart() {
  3188. const swiper = this;
  3189. if (swiper.documentTouchHandlerProceeded) return;
  3190. swiper.documentTouchHandlerProceeded = true;
  3191. if (swiper.params.touchReleaseOnEdges) {
  3192. swiper.el.style.touchAction = 'auto';
  3193. }
  3194. }
  3195. const events = (swiper, method) => {
  3196. const document = getDocument();
  3197. const {
  3198. params,
  3199. el,
  3200. wrapperEl,
  3201. device
  3202. } = swiper;
  3203. const capture = !!params.nested;
  3204. const domMethod = method === 'on' ? 'addEventListener' : 'removeEventListener';
  3205. const swiperMethod = method;
  3206. if (!el || typeof el === 'string') return;
  3207. // Touch Events
  3208. document[domMethod]('touchstart', swiper.onDocumentTouchStart, {
  3209. passive: false,
  3210. capture
  3211. });
  3212. el[domMethod]('touchstart', swiper.onTouchStart, {
  3213. passive: false
  3214. });
  3215. el[domMethod]('pointerdown', swiper.onTouchStart, {
  3216. passive: false
  3217. });
  3218. document[domMethod]('touchmove', swiper.onTouchMove, {
  3219. passive: false,
  3220. capture
  3221. });
  3222. document[domMethod]('pointermove', swiper.onTouchMove, {
  3223. passive: false,
  3224. capture
  3225. });
  3226. document[domMethod]('touchend', swiper.onTouchEnd, {
  3227. passive: true
  3228. });
  3229. document[domMethod]('pointerup', swiper.onTouchEnd, {
  3230. passive: true
  3231. });
  3232. document[domMethod]('pointercancel', swiper.onTouchEnd, {
  3233. passive: true
  3234. });
  3235. document[domMethod]('touchcancel', swiper.onTouchEnd, {
  3236. passive: true
  3237. });
  3238. document[domMethod]('pointerout', swiper.onTouchEnd, {
  3239. passive: true
  3240. });
  3241. document[domMethod]('pointerleave', swiper.onTouchEnd, {
  3242. passive: true
  3243. });
  3244. document[domMethod]('contextmenu', swiper.onTouchEnd, {
  3245. passive: true
  3246. });
  3247. // Prevent Links Clicks
  3248. if (params.preventClicks || params.preventClicksPropagation) {
  3249. el[domMethod]('click', swiper.onClick, true);
  3250. }
  3251. if (params.cssMode) {
  3252. wrapperEl[domMethod]('scroll', swiper.onScroll);
  3253. }
  3254. // Resize handler
  3255. if (params.updateOnWindowResize) {
  3256. swiper[swiperMethod](device.ios || device.android ? 'resize orientationchange observerUpdate' : 'resize observerUpdate', onResize, true);
  3257. } else {
  3258. swiper[swiperMethod]('observerUpdate', onResize, true);
  3259. }
  3260. // Images loader
  3261. el[domMethod]('load', swiper.onLoad, {
  3262. capture: true
  3263. });
  3264. };
  3265. function attachEvents() {
  3266. const swiper = this;
  3267. const {
  3268. params
  3269. } = swiper;
  3270. swiper.onTouchStart = onTouchStart.bind(swiper);
  3271. swiper.onTouchMove = onTouchMove.bind(swiper);
  3272. swiper.onTouchEnd = onTouchEnd.bind(swiper);
  3273. swiper.onDocumentTouchStart = onDocumentTouchStart.bind(swiper);
  3274. if (params.cssMode) {
  3275. swiper.onScroll = onScroll.bind(swiper);
  3276. }
  3277. swiper.onClick = onClick.bind(swiper);
  3278. swiper.onLoad = onLoad.bind(swiper);
  3279. events(swiper, 'on');
  3280. }
  3281. function detachEvents() {
  3282. const swiper = this;
  3283. events(swiper, 'off');
  3284. }
  3285. var events$1 = {
  3286. attachEvents,
  3287. detachEvents
  3288. };
  3289. const isGridEnabled = (swiper, params) => {
  3290. return swiper.grid && params.grid && params.grid.rows > 1;
  3291. };
  3292. function setBreakpoint() {
  3293. const swiper = this;
  3294. const {
  3295. realIndex,
  3296. initialized,
  3297. params,
  3298. el
  3299. } = swiper;
  3300. const breakpoints = params.breakpoints;
  3301. if (!breakpoints || breakpoints && Object.keys(breakpoints).length === 0) return;
  3302. const document = getDocument();
  3303. // Get breakpoint for window/container width and update parameters
  3304. const breakpointsBase = params.breakpointsBase === 'window' || !params.breakpointsBase ? params.breakpointsBase : 'container';
  3305. const breakpointContainer = ['window', 'container'].includes(params.breakpointsBase) || !params.breakpointsBase ? swiper.el : document.querySelector(params.breakpointsBase);
  3306. const breakpoint = swiper.getBreakpoint(breakpoints, breakpointsBase, breakpointContainer);
  3307. if (!breakpoint || swiper.currentBreakpoint === breakpoint) return;
  3308. const breakpointOnlyParams = breakpoint in breakpoints ? breakpoints[breakpoint] : undefined;
  3309. const breakpointParams = breakpointOnlyParams || swiper.originalParams;
  3310. const wasMultiRow = isGridEnabled(swiper, params);
  3311. const isMultiRow = isGridEnabled(swiper, breakpointParams);
  3312. const wasGrabCursor = swiper.params.grabCursor;
  3313. const isGrabCursor = breakpointParams.grabCursor;
  3314. const wasEnabled = params.enabled;
  3315. if (wasMultiRow && !isMultiRow) {
  3316. el.classList.remove(`${params.containerModifierClass}grid`, `${params.containerModifierClass}grid-column`);
  3317. swiper.emitContainerClasses();
  3318. } else if (!wasMultiRow && isMultiRow) {
  3319. el.classList.add(`${params.containerModifierClass}grid`);
  3320. if (breakpointParams.grid.fill && breakpointParams.grid.fill === 'column' || !breakpointParams.grid.fill && params.grid.fill === 'column') {
  3321. el.classList.add(`${params.containerModifierClass}grid-column`);
  3322. }
  3323. swiper.emitContainerClasses();
  3324. }
  3325. if (wasGrabCursor && !isGrabCursor) {
  3326. swiper.unsetGrabCursor();
  3327. } else if (!wasGrabCursor && isGrabCursor) {
  3328. swiper.setGrabCursor();
  3329. }
  3330. // Toggle navigation, pagination, scrollbar
  3331. ['navigation', 'pagination', 'scrollbar'].forEach(prop => {
  3332. if (typeof breakpointParams[prop] === 'undefined') return;
  3333. const wasModuleEnabled = params[prop] && params[prop].enabled;
  3334. const isModuleEnabled = breakpointParams[prop] && breakpointParams[prop].enabled;
  3335. if (wasModuleEnabled && !isModuleEnabled) {
  3336. swiper[prop].disable();
  3337. }
  3338. if (!wasModuleEnabled && isModuleEnabled) {
  3339. swiper[prop].enable();
  3340. }
  3341. });
  3342. const directionChanged = breakpointParams.direction && breakpointParams.direction !== params.direction;
  3343. const needsReLoop = params.loop && (breakpointParams.slidesPerView !== params.slidesPerView || directionChanged);
  3344. const wasLoop = params.loop;
  3345. if (directionChanged && initialized) {
  3346. swiper.changeDirection();
  3347. }
  3348. extend$1(swiper.params, breakpointParams);
  3349. const isEnabled = swiper.params.enabled;
  3350. const hasLoop = swiper.params.loop;
  3351. Object.assign(swiper, {
  3352. allowTouchMove: swiper.params.allowTouchMove,
  3353. allowSlideNext: swiper.params.allowSlideNext,
  3354. allowSlidePrev: swiper.params.allowSlidePrev
  3355. });
  3356. if (wasEnabled && !isEnabled) {
  3357. swiper.disable();
  3358. } else if (!wasEnabled && isEnabled) {
  3359. swiper.enable();
  3360. }
  3361. swiper.currentBreakpoint = breakpoint;
  3362. swiper.emit('_beforeBreakpoint', breakpointParams);
  3363. if (initialized) {
  3364. if (needsReLoop) {
  3365. swiper.loopDestroy();
  3366. swiper.loopCreate(realIndex);
  3367. swiper.updateSlides();
  3368. } else if (!wasLoop && hasLoop) {
  3369. swiper.loopCreate(realIndex);
  3370. swiper.updateSlides();
  3371. } else if (wasLoop && !hasLoop) {
  3372. swiper.loopDestroy();
  3373. }
  3374. }
  3375. swiper.emit('breakpoint', breakpointParams);
  3376. }
  3377. function getBreakpoint(breakpoints, base, containerEl) {
  3378. if (base === void 0) {
  3379. base = 'window';
  3380. }
  3381. if (!breakpoints || base === 'container' && !containerEl) return undefined;
  3382. let breakpoint = false;
  3383. const window = getWindow();
  3384. const currentHeight = base === 'window' ? window.innerHeight : containerEl.clientHeight;
  3385. const points = Object.keys(breakpoints).map(point => {
  3386. if (typeof point === 'string' && point.indexOf('@') === 0) {
  3387. const minRatio = parseFloat(point.substr(1));
  3388. const value = currentHeight * minRatio;
  3389. return {
  3390. value,
  3391. point
  3392. };
  3393. }
  3394. return {
  3395. value: point,
  3396. point
  3397. };
  3398. });
  3399. points.sort((a, b) => parseInt(a.value, 10) - parseInt(b.value, 10));
  3400. for (let i = 0; i < points.length; i += 1) {
  3401. const {
  3402. point,
  3403. value
  3404. } = points[i];
  3405. if (base === 'window') {
  3406. if (window.matchMedia(`(min-width: ${value}px)`).matches) {
  3407. breakpoint = point;
  3408. }
  3409. } else if (value <= containerEl.clientWidth) {
  3410. breakpoint = point;
  3411. }
  3412. }
  3413. return breakpoint || 'max';
  3414. }
  3415. var breakpoints = {
  3416. setBreakpoint,
  3417. getBreakpoint
  3418. };
  3419. function prepareClasses(entries, prefix) {
  3420. const resultClasses = [];
  3421. entries.forEach(item => {
  3422. if (typeof item === 'object') {
  3423. Object.keys(item).forEach(classNames => {
  3424. if (item[classNames]) {
  3425. resultClasses.push(prefix + classNames);
  3426. }
  3427. });
  3428. } else if (typeof item === 'string') {
  3429. resultClasses.push(prefix + item);
  3430. }
  3431. });
  3432. return resultClasses;
  3433. }
  3434. function addClasses() {
  3435. const swiper = this;
  3436. const {
  3437. classNames,
  3438. params,
  3439. rtl,
  3440. el,
  3441. device
  3442. } = swiper;
  3443. // prettier-ignore
  3444. const suffixes = prepareClasses(['initialized', params.direction, {
  3445. 'free-mode': swiper.params.freeMode && params.freeMode.enabled
  3446. }, {
  3447. 'autoheight': params.autoHeight
  3448. }, {
  3449. 'rtl': rtl
  3450. }, {
  3451. 'grid': params.grid && params.grid.rows > 1
  3452. }, {
  3453. 'grid-column': params.grid && params.grid.rows > 1 && params.grid.fill === 'column'
  3454. }, {
  3455. 'android': device.android
  3456. }, {
  3457. 'ios': device.ios
  3458. }, {
  3459. 'css-mode': params.cssMode
  3460. }, {
  3461. 'centered': params.cssMode && params.centeredSlides
  3462. }, {
  3463. 'watch-progress': params.watchSlidesProgress
  3464. }], params.containerModifierClass);
  3465. classNames.push(...suffixes);
  3466. el.classList.add(...classNames);
  3467. swiper.emitContainerClasses();
  3468. }
  3469. function removeClasses() {
  3470. const swiper = this;
  3471. const {
  3472. el,
  3473. classNames
  3474. } = swiper;
  3475. if (!el || typeof el === 'string') return;
  3476. el.classList.remove(...classNames);
  3477. swiper.emitContainerClasses();
  3478. }
  3479. var classes = {
  3480. addClasses,
  3481. removeClasses
  3482. };
  3483. function checkOverflow() {
  3484. const swiper = this;
  3485. const {
  3486. isLocked: wasLocked,
  3487. params
  3488. } = swiper;
  3489. const {
  3490. slidesOffsetBefore
  3491. } = params;
  3492. if (slidesOffsetBefore) {
  3493. const lastSlideIndex = swiper.slides.length - 1;
  3494. const lastSlideRightEdge = swiper.slidesGrid[lastSlideIndex] + swiper.slidesSizesGrid[lastSlideIndex] + slidesOffsetBefore * 2;
  3495. swiper.isLocked = swiper.size > lastSlideRightEdge;
  3496. } else {
  3497. swiper.isLocked = swiper.snapGrid.length === 1;
  3498. }
  3499. if (params.allowSlideNext === true) {
  3500. swiper.allowSlideNext = !swiper.isLocked;
  3501. }
  3502. if (params.allowSlidePrev === true) {
  3503. swiper.allowSlidePrev = !swiper.isLocked;
  3504. }
  3505. if (wasLocked && wasLocked !== swiper.isLocked) {
  3506. swiper.isEnd = false;
  3507. }
  3508. if (wasLocked !== swiper.isLocked) {
  3509. swiper.emit(swiper.isLocked ? 'lock' : 'unlock');
  3510. }
  3511. }
  3512. var checkOverflow$1 = {
  3513. checkOverflow
  3514. };
  3515. var defaults = {
  3516. init: true,
  3517. direction: 'horizontal',
  3518. oneWayMovement: false,
  3519. swiperElementNodeName: 'SWIPER-CONTAINER',
  3520. touchEventsTarget: 'wrapper',
  3521. initialSlide: 0,
  3522. speed: 300,
  3523. cssMode: false,
  3524. updateOnWindowResize: true,
  3525. resizeObserver: true,
  3526. nested: false,
  3527. createElements: false,
  3528. eventsPrefix: 'swiper',
  3529. enabled: true,
  3530. focusableElements: 'input, select, option, textarea, button, video, label',
  3531. // Overrides
  3532. width: null,
  3533. height: null,
  3534. //
  3535. preventInteractionOnTransition: false,
  3536. // ssr
  3537. userAgent: null,
  3538. url: null,
  3539. // To support iOS's swipe-to-go-back gesture (when being used in-app).
  3540. edgeSwipeDetection: false,
  3541. edgeSwipeThreshold: 20,
  3542. // Autoheight
  3543. autoHeight: false,
  3544. // Set wrapper width
  3545. setWrapperSize: false,
  3546. // Virtual Translate
  3547. virtualTranslate: false,
  3548. // Effects
  3549. effect: 'slide',
  3550. // 'slide' or 'fade' or 'cube' or 'coverflow' or 'flip'
  3551. // Breakpoints
  3552. breakpoints: undefined,
  3553. breakpointsBase: 'window',
  3554. // Slides grid
  3555. spaceBetween: 0,
  3556. slidesPerView: 1,
  3557. slidesPerGroup: 1,
  3558. slidesPerGroupSkip: 0,
  3559. slidesPerGroupAuto: false,
  3560. centeredSlides: false,
  3561. centeredSlidesBounds: false,
  3562. slidesOffsetBefore: 0,
  3563. // in px
  3564. slidesOffsetAfter: 0,
  3565. // in px
  3566. normalizeSlideIndex: true,
  3567. centerInsufficientSlides: false,
  3568. // Disable swiper and hide navigation when container not overflow
  3569. watchOverflow: true,
  3570. // Round length
  3571. roundLengths: false,
  3572. // Touches
  3573. touchRatio: 1,
  3574. touchAngle: 45,
  3575. simulateTouch: true,
  3576. shortSwipes: true,
  3577. longSwipes: true,
  3578. longSwipesRatio: 0.5,
  3579. longSwipesMs: 300,
  3580. followFinger: true,
  3581. allowTouchMove: true,
  3582. threshold: 5,
  3583. touchMoveStopPropagation: false,
  3584. touchStartPreventDefault: true,
  3585. touchStartForcePreventDefault: false,
  3586. touchReleaseOnEdges: false,
  3587. // Unique Navigation Elements
  3588. uniqueNavElements: true,
  3589. // Resistance
  3590. resistance: true,
  3591. resistanceRatio: 0.85,
  3592. // Progress
  3593. watchSlidesProgress: false,
  3594. // Cursor
  3595. grabCursor: false,
  3596. // Clicks
  3597. preventClicks: true,
  3598. preventClicksPropagation: true,
  3599. slideToClickedSlide: false,
  3600. // loop
  3601. loop: false,
  3602. loopAddBlankSlides: true,
  3603. loopAdditionalSlides: 0,
  3604. loopPreventsSliding: true,
  3605. // rewind
  3606. rewind: false,
  3607. // Swiping/no swiping
  3608. allowSlidePrev: true,
  3609. allowSlideNext: true,
  3610. swipeHandler: null,
  3611. // '.swipe-handler',
  3612. noSwiping: true,
  3613. noSwipingClass: 'swiper-no-swiping',
  3614. noSwipingSelector: null,
  3615. // Passive Listeners
  3616. passiveListeners: true,
  3617. maxBackfaceHiddenSlides: 10,
  3618. // NS
  3619. containerModifierClass: 'swiper-',
  3620. // NEW
  3621. slideClass: 'swiper-slide',
  3622. slideBlankClass: 'swiper-slide-blank',
  3623. slideActiveClass: 'swiper-slide-active',
  3624. slideVisibleClass: 'swiper-slide-visible',
  3625. slideFullyVisibleClass: 'swiper-slide-fully-visible',
  3626. slideNextClass: 'swiper-slide-next',
  3627. slidePrevClass: 'swiper-slide-prev',
  3628. wrapperClass: 'swiper-wrapper',
  3629. lazyPreloaderClass: 'swiper-lazy-preloader',
  3630. lazyPreloadPrevNext: 0,
  3631. // Callbacks
  3632. runCallbacksOnInit: true,
  3633. // Internals
  3634. _emitClasses: false
  3635. };
  3636. function moduleExtendParams(params, allModulesParams) {
  3637. return function extendParams(obj) {
  3638. if (obj === void 0) {
  3639. obj = {};
  3640. }
  3641. const moduleParamName = Object.keys(obj)[0];
  3642. const moduleParams = obj[moduleParamName];
  3643. if (typeof moduleParams !== 'object' || moduleParams === null) {
  3644. extend$1(allModulesParams, obj);
  3645. return;
  3646. }
  3647. if (params[moduleParamName] === true) {
  3648. params[moduleParamName] = {
  3649. enabled: true
  3650. };
  3651. }
  3652. if (moduleParamName === 'navigation' && params[moduleParamName] && params[moduleParamName].enabled && !params[moduleParamName].prevEl && !params[moduleParamName].nextEl) {
  3653. params[moduleParamName].auto = true;
  3654. }
  3655. if (['pagination', 'scrollbar'].indexOf(moduleParamName) >= 0 && params[moduleParamName] && params[moduleParamName].enabled && !params[moduleParamName].el) {
  3656. params[moduleParamName].auto = true;
  3657. }
  3658. if (!(moduleParamName in params && 'enabled' in moduleParams)) {
  3659. extend$1(allModulesParams, obj);
  3660. return;
  3661. }
  3662. if (typeof params[moduleParamName] === 'object' && !('enabled' in params[moduleParamName])) {
  3663. params[moduleParamName].enabled = true;
  3664. }
  3665. if (!params[moduleParamName]) params[moduleParamName] = {
  3666. enabled: false
  3667. };
  3668. extend$1(allModulesParams, obj);
  3669. };
  3670. }
  3671. /* eslint no-param-reassign: "off" */
  3672. const prototypes = {
  3673. eventsEmitter,
  3674. update,
  3675. translate,
  3676. transition,
  3677. slide,
  3678. loop,
  3679. grabCursor,
  3680. events: events$1,
  3681. breakpoints,
  3682. checkOverflow: checkOverflow$1,
  3683. classes
  3684. };
  3685. const extendedDefaults = {};
  3686. class Swiper {
  3687. constructor() {
  3688. let el;
  3689. let params;
  3690. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  3691. args[_key] = arguments[_key];
  3692. }
  3693. if (args.length === 1 && args[0].constructor && Object.prototype.toString.call(args[0]).slice(8, -1) === 'Object') {
  3694. params = args[0];
  3695. } else {
  3696. [el, params] = args;
  3697. }
  3698. if (!params) params = {};
  3699. params = extend$1({}, params);
  3700. if (el && !params.el) params.el = el;
  3701. const document = getDocument();
  3702. if (params.el && typeof params.el === 'string' && document.querySelectorAll(params.el).length > 1) {
  3703. const swipers = [];
  3704. document.querySelectorAll(params.el).forEach(containerEl => {
  3705. const newParams = extend$1({}, params, {
  3706. el: containerEl
  3707. });
  3708. swipers.push(new Swiper(newParams));
  3709. });
  3710. // eslint-disable-next-line no-constructor-return
  3711. return swipers;
  3712. }
  3713. // Swiper Instance
  3714. const swiper = this;
  3715. swiper.__swiper__ = true;
  3716. swiper.support = getSupport();
  3717. swiper.device = getDevice({
  3718. userAgent: params.userAgent
  3719. });
  3720. swiper.browser = getBrowser();
  3721. swiper.eventsListeners = {};
  3722. swiper.eventsAnyListeners = [];
  3723. swiper.modules = [...swiper.__modules__];
  3724. if (params.modules && Array.isArray(params.modules)) {
  3725. swiper.modules.push(...params.modules);
  3726. }
  3727. const allModulesParams = {};
  3728. swiper.modules.forEach(mod => {
  3729. mod({
  3730. params,
  3731. swiper,
  3732. extendParams: moduleExtendParams(params, allModulesParams),
  3733. on: swiper.on.bind(swiper),
  3734. once: swiper.once.bind(swiper),
  3735. off: swiper.off.bind(swiper),
  3736. emit: swiper.emit.bind(swiper)
  3737. });
  3738. });
  3739. // Extend defaults with modules params
  3740. const swiperParams = extend$1({}, defaults, allModulesParams);
  3741. // Extend defaults with passed params
  3742. swiper.params = extend$1({}, swiperParams, extendedDefaults, params);
  3743. swiper.originalParams = extend$1({}, swiper.params);
  3744. swiper.passedParams = extend$1({}, params);
  3745. // add event listeners
  3746. if (swiper.params && swiper.params.on) {
  3747. Object.keys(swiper.params.on).forEach(eventName => {
  3748. swiper.on(eventName, swiper.params.on[eventName]);
  3749. });
  3750. }
  3751. if (swiper.params && swiper.params.onAny) {
  3752. swiper.onAny(swiper.params.onAny);
  3753. }
  3754. // Extend Swiper
  3755. Object.assign(swiper, {
  3756. enabled: swiper.params.enabled,
  3757. el,
  3758. // Classes
  3759. classNames: [],
  3760. // Slides
  3761. slides: [],
  3762. slidesGrid: [],
  3763. snapGrid: [],
  3764. slidesSizesGrid: [],
  3765. // isDirection
  3766. isHorizontal() {
  3767. return swiper.params.direction === 'horizontal';
  3768. },
  3769. isVertical() {
  3770. return swiper.params.direction === 'vertical';
  3771. },
  3772. // Indexes
  3773. activeIndex: 0,
  3774. realIndex: 0,
  3775. //
  3776. isBeginning: true,
  3777. isEnd: false,
  3778. // Props
  3779. translate: 0,
  3780. previousTranslate: 0,
  3781. progress: 0,
  3782. velocity: 0,
  3783. animating: false,
  3784. cssOverflowAdjustment() {
  3785. // Returns 0 unless `translate` is > 2**23
  3786. // Should be subtracted from css values to prevent overflow
  3787. return Math.trunc(this.translate / 2 ** 23) * 2 ** 23;
  3788. },
  3789. // Locks
  3790. allowSlideNext: swiper.params.allowSlideNext,
  3791. allowSlidePrev: swiper.params.allowSlidePrev,
  3792. // Touch Events
  3793. touchEventsData: {
  3794. isTouched: undefined,
  3795. isMoved: undefined,
  3796. allowTouchCallbacks: undefined,
  3797. touchStartTime: undefined,
  3798. isScrolling: undefined,
  3799. currentTranslate: undefined,
  3800. startTranslate: undefined,
  3801. allowThresholdMove: undefined,
  3802. // Form elements to match
  3803. focusableElements: swiper.params.focusableElements,
  3804. // Last click time
  3805. lastClickTime: 0,
  3806. clickTimeout: undefined,
  3807. // Velocities
  3808. velocities: [],
  3809. allowMomentumBounce: undefined,
  3810. startMoving: undefined,
  3811. pointerId: null,
  3812. touchId: null
  3813. },
  3814. // Clicks
  3815. allowClick: true,
  3816. // Touches
  3817. allowTouchMove: swiper.params.allowTouchMove,
  3818. touches: {
  3819. startX: 0,
  3820. startY: 0,
  3821. currentX: 0,
  3822. currentY: 0,
  3823. diff: 0
  3824. },
  3825. // Images
  3826. imagesToLoad: [],
  3827. imagesLoaded: 0
  3828. });
  3829. swiper.emit('_swiper');
  3830. // Init
  3831. if (swiper.params.init) {
  3832. swiper.init();
  3833. }
  3834. // Return app instance
  3835. // eslint-disable-next-line no-constructor-return
  3836. return swiper;
  3837. }
  3838. getDirectionLabel(property) {
  3839. if (this.isHorizontal()) {
  3840. return property;
  3841. }
  3842. // prettier-ignore
  3843. return {
  3844. 'width': 'height',
  3845. 'margin-top': 'margin-left',
  3846. 'margin-bottom ': 'margin-right',
  3847. 'margin-left': 'margin-top',
  3848. 'margin-right': 'margin-bottom',
  3849. 'padding-left': 'padding-top',
  3850. 'padding-right': 'padding-bottom',
  3851. 'marginRight': 'marginBottom'
  3852. }[property];
  3853. }
  3854. getSlideIndex(slideEl) {
  3855. const {
  3856. slidesEl,
  3857. params
  3858. } = this;
  3859. const slides = elementChildren(slidesEl, `.${params.slideClass}, swiper-slide`);
  3860. const firstSlideIndex = elementIndex(slides[0]);
  3861. return elementIndex(slideEl) - firstSlideIndex;
  3862. }
  3863. getSlideIndexByData(index) {
  3864. return this.getSlideIndex(this.slides.find(slideEl => slideEl.getAttribute('data-swiper-slide-index') * 1 === index));
  3865. }
  3866. getSlideIndexWhenGrid(index) {
  3867. if (this.grid && this.params.grid && this.params.grid.rows > 1) {
  3868. if (this.params.grid.fill === 'column') {
  3869. index = Math.floor(index / this.params.grid.rows);
  3870. } else if (this.params.grid.fill === 'row') {
  3871. index = index % Math.ceil(this.slides.length / this.params.grid.rows);
  3872. }
  3873. }
  3874. return index;
  3875. }
  3876. recalcSlides() {
  3877. const swiper = this;
  3878. const {
  3879. slidesEl,
  3880. params
  3881. } = swiper;
  3882. swiper.slides = elementChildren(slidesEl, `.${params.slideClass}, swiper-slide`);
  3883. }
  3884. enable() {
  3885. const swiper = this;
  3886. if (swiper.enabled) return;
  3887. swiper.enabled = true;
  3888. if (swiper.params.grabCursor) {
  3889. swiper.setGrabCursor();
  3890. }
  3891. swiper.emit('enable');
  3892. }
  3893. disable() {
  3894. const swiper = this;
  3895. if (!swiper.enabled) return;
  3896. swiper.enabled = false;
  3897. if (swiper.params.grabCursor) {
  3898. swiper.unsetGrabCursor();
  3899. }
  3900. swiper.emit('disable');
  3901. }
  3902. setProgress(progress, speed) {
  3903. const swiper = this;
  3904. progress = Math.min(Math.max(progress, 0), 1);
  3905. const min = swiper.minTranslate();
  3906. const max = swiper.maxTranslate();
  3907. const current = (max - min) * progress + min;
  3908. swiper.translateTo(current, typeof speed === 'undefined' ? 0 : speed);
  3909. swiper.updateActiveIndex();
  3910. swiper.updateSlidesClasses();
  3911. }
  3912. emitContainerClasses() {
  3913. const swiper = this;
  3914. if (!swiper.params._emitClasses || !swiper.el) return;
  3915. const cls = swiper.el.className.split(' ').filter(className => {
  3916. return className.indexOf('swiper') === 0 || className.indexOf(swiper.params.containerModifierClass) === 0;
  3917. });
  3918. swiper.emit('_containerClasses', cls.join(' '));
  3919. }
  3920. getSlideClasses(slideEl) {
  3921. const swiper = this;
  3922. if (swiper.destroyed) return '';
  3923. return slideEl.className.split(' ').filter(className => {
  3924. return className.indexOf('swiper-slide') === 0 || className.indexOf(swiper.params.slideClass) === 0;
  3925. }).join(' ');
  3926. }
  3927. emitSlidesClasses() {
  3928. const swiper = this;
  3929. if (!swiper.params._emitClasses || !swiper.el) return;
  3930. const updates = [];
  3931. swiper.slides.forEach(slideEl => {
  3932. const classNames = swiper.getSlideClasses(slideEl);
  3933. updates.push({
  3934. slideEl,
  3935. classNames
  3936. });
  3937. swiper.emit('_slideClass', slideEl, classNames);
  3938. });
  3939. swiper.emit('_slideClasses', updates);
  3940. }
  3941. slidesPerViewDynamic(view, exact) {
  3942. if (view === void 0) {
  3943. view = 'current';
  3944. }
  3945. if (exact === void 0) {
  3946. exact = false;
  3947. }
  3948. const swiper = this;
  3949. const {
  3950. params,
  3951. slides,
  3952. slidesGrid,
  3953. slidesSizesGrid,
  3954. size: swiperSize,
  3955. activeIndex
  3956. } = swiper;
  3957. let spv = 1;
  3958. if (typeof params.slidesPerView === 'number') return params.slidesPerView;
  3959. if (params.centeredSlides) {
  3960. let slideSize = slides[activeIndex] ? Math.ceil(slides[activeIndex].swiperSlideSize) : 0;
  3961. let breakLoop;
  3962. for (let i = activeIndex + 1; i < slides.length; i += 1) {
  3963. if (slides[i] && !breakLoop) {
  3964. slideSize += Math.ceil(slides[i].swiperSlideSize);
  3965. spv += 1;
  3966. if (slideSize > swiperSize) breakLoop = true;
  3967. }
  3968. }
  3969. for (let i = activeIndex - 1; i >= 0; i -= 1) {
  3970. if (slides[i] && !breakLoop) {
  3971. slideSize += slides[i].swiperSlideSize;
  3972. spv += 1;
  3973. if (slideSize > swiperSize) breakLoop = true;
  3974. }
  3975. }
  3976. } else {
  3977. // eslint-disable-next-line
  3978. if (view === 'current') {
  3979. for (let i = activeIndex + 1; i < slides.length; i += 1) {
  3980. const slideInView = exact ? slidesGrid[i] + slidesSizesGrid[i] - slidesGrid[activeIndex] < swiperSize : slidesGrid[i] - slidesGrid[activeIndex] < swiperSize;
  3981. if (slideInView) {
  3982. spv += 1;
  3983. }
  3984. }
  3985. } else {
  3986. // previous
  3987. for (let i = activeIndex - 1; i >= 0; i -= 1) {
  3988. const slideInView = slidesGrid[activeIndex] - slidesGrid[i] < swiperSize;
  3989. if (slideInView) {
  3990. spv += 1;
  3991. }
  3992. }
  3993. }
  3994. }
  3995. return spv;
  3996. }
  3997. update() {
  3998. const swiper = this;
  3999. if (!swiper || swiper.destroyed) return;
  4000. const {
  4001. snapGrid,
  4002. params
  4003. } = swiper;
  4004. // Breakpoints
  4005. if (params.breakpoints) {
  4006. swiper.setBreakpoint();
  4007. }
  4008. [...swiper.el.querySelectorAll('[loading="lazy"]')].forEach(imageEl => {
  4009. if (imageEl.complete) {
  4010. processLazyPreloader(swiper, imageEl);
  4011. }
  4012. });
  4013. swiper.updateSize();
  4014. swiper.updateSlides();
  4015. swiper.updateProgress();
  4016. swiper.updateSlidesClasses();
  4017. function setTranslate() {
  4018. const translateValue = swiper.rtlTranslate ? swiper.translate * -1 : swiper.translate;
  4019. const newTranslate = Math.min(Math.max(translateValue, swiper.maxTranslate()), swiper.minTranslate());
  4020. swiper.setTranslate(newTranslate);
  4021. swiper.updateActiveIndex();
  4022. swiper.updateSlidesClasses();
  4023. }
  4024. let translated;
  4025. if (params.freeMode && params.freeMode.enabled && !params.cssMode) {
  4026. setTranslate();
  4027. if (params.autoHeight) {
  4028. swiper.updateAutoHeight();
  4029. }
  4030. } else {
  4031. if ((params.slidesPerView === 'auto' || params.slidesPerView > 1) && swiper.isEnd && !params.centeredSlides) {
  4032. const slides = swiper.virtual && params.virtual.enabled ? swiper.virtual.slides : swiper.slides;
  4033. translated = swiper.slideTo(slides.length - 1, 0, false, true);
  4034. } else {
  4035. translated = swiper.slideTo(swiper.activeIndex, 0, false, true);
  4036. }
  4037. if (!translated) {
  4038. setTranslate();
  4039. }
  4040. }
  4041. if (params.watchOverflow && snapGrid !== swiper.snapGrid) {
  4042. swiper.checkOverflow();
  4043. }
  4044. swiper.emit('update');
  4045. }
  4046. changeDirection(newDirection, needUpdate) {
  4047. if (needUpdate === void 0) {
  4048. needUpdate = true;
  4049. }
  4050. const swiper = this;
  4051. const currentDirection = swiper.params.direction;
  4052. if (!newDirection) {
  4053. // eslint-disable-next-line
  4054. newDirection = currentDirection === 'horizontal' ? 'vertical' : 'horizontal';
  4055. }
  4056. if (newDirection === currentDirection || newDirection !== 'horizontal' && newDirection !== 'vertical') {
  4057. return swiper;
  4058. }
  4059. swiper.el.classList.remove(`${swiper.params.containerModifierClass}${currentDirection}`);
  4060. swiper.el.classList.add(`${swiper.params.containerModifierClass}${newDirection}`);
  4061. swiper.emitContainerClasses();
  4062. swiper.params.direction = newDirection;
  4063. swiper.slides.forEach(slideEl => {
  4064. if (newDirection === 'vertical') {
  4065. slideEl.style.width = '';
  4066. } else {
  4067. slideEl.style.height = '';
  4068. }
  4069. });
  4070. swiper.emit('changeDirection');
  4071. if (needUpdate) swiper.update();
  4072. return swiper;
  4073. }
  4074. changeLanguageDirection(direction) {
  4075. const swiper = this;
  4076. if (swiper.rtl && direction === 'rtl' || !swiper.rtl && direction === 'ltr') return;
  4077. swiper.rtl = direction === 'rtl';
  4078. swiper.rtlTranslate = swiper.params.direction === 'horizontal' && swiper.rtl;
  4079. if (swiper.rtl) {
  4080. swiper.el.classList.add(`${swiper.params.containerModifierClass}rtl`);
  4081. swiper.el.dir = 'rtl';
  4082. } else {
  4083. swiper.el.classList.remove(`${swiper.params.containerModifierClass}rtl`);
  4084. swiper.el.dir = 'ltr';
  4085. }
  4086. swiper.update();
  4087. }
  4088. mount(element) {
  4089. const swiper = this;
  4090. if (swiper.mounted) return true;
  4091. // Find el
  4092. let el = element || swiper.params.el;
  4093. if (typeof el === 'string') {
  4094. el = document.querySelector(el);
  4095. }
  4096. if (!el) {
  4097. return false;
  4098. }
  4099. el.swiper = swiper;
  4100. if (el.parentNode && el.parentNode.host && el.parentNode.host.nodeName === swiper.params.swiperElementNodeName.toUpperCase()) {
  4101. swiper.isElement = true;
  4102. }
  4103. const getWrapperSelector = () => {
  4104. return `.${(swiper.params.wrapperClass || '').trim().split(' ').join('.')}`;
  4105. };
  4106. const getWrapper = () => {
  4107. if (el && el.shadowRoot && el.shadowRoot.querySelector) {
  4108. const res = el.shadowRoot.querySelector(getWrapperSelector());
  4109. // Children needs to return slot items
  4110. return res;
  4111. }
  4112. return elementChildren(el, getWrapperSelector())[0];
  4113. };
  4114. // Find Wrapper
  4115. let wrapperEl = getWrapper();
  4116. if (!wrapperEl && swiper.params.createElements) {
  4117. wrapperEl = createElement('div', swiper.params.wrapperClass);
  4118. el.append(wrapperEl);
  4119. elementChildren(el, `.${swiper.params.slideClass}`).forEach(slideEl => {
  4120. wrapperEl.append(slideEl);
  4121. });
  4122. }
  4123. Object.assign(swiper, {
  4124. el,
  4125. wrapperEl,
  4126. slidesEl: swiper.isElement && !el.parentNode.host.slideSlots ? el.parentNode.host : wrapperEl,
  4127. hostEl: swiper.isElement ? el.parentNode.host : el,
  4128. mounted: true,
  4129. // RTL
  4130. rtl: el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl',
  4131. rtlTranslate: swiper.params.direction === 'horizontal' && (el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl'),
  4132. wrongRTL: elementStyle(wrapperEl, 'display') === '-webkit-box'
  4133. });
  4134. return true;
  4135. }
  4136. init(el) {
  4137. const swiper = this;
  4138. if (swiper.initialized) return swiper;
  4139. const mounted = swiper.mount(el);
  4140. if (mounted === false) return swiper;
  4141. swiper.emit('beforeInit');
  4142. // Set breakpoint
  4143. if (swiper.params.breakpoints) {
  4144. swiper.setBreakpoint();
  4145. }
  4146. // Add Classes
  4147. swiper.addClasses();
  4148. // Update size
  4149. swiper.updateSize();
  4150. // Update slides
  4151. swiper.updateSlides();
  4152. if (swiper.params.watchOverflow) {
  4153. swiper.checkOverflow();
  4154. }
  4155. // Set Grab Cursor
  4156. if (swiper.params.grabCursor && swiper.enabled) {
  4157. swiper.setGrabCursor();
  4158. }
  4159. // Slide To Initial Slide
  4160. if (swiper.params.loop && swiper.virtual && swiper.params.virtual.enabled) {
  4161. swiper.slideTo(swiper.params.initialSlide + swiper.virtual.slidesBefore, 0, swiper.params.runCallbacksOnInit, false, true);
  4162. } else {
  4163. swiper.slideTo(swiper.params.initialSlide, 0, swiper.params.runCallbacksOnInit, false, true);
  4164. }
  4165. // Create loop
  4166. if (swiper.params.loop) {
  4167. swiper.loopCreate(undefined, true);
  4168. }
  4169. // Attach events
  4170. swiper.attachEvents();
  4171. const lazyElements = [...swiper.el.querySelectorAll('[loading="lazy"]')];
  4172. if (swiper.isElement) {
  4173. lazyElements.push(...swiper.hostEl.querySelectorAll('[loading="lazy"]'));
  4174. }
  4175. lazyElements.forEach(imageEl => {
  4176. if (imageEl.complete) {
  4177. processLazyPreloader(swiper, imageEl);
  4178. } else {
  4179. imageEl.addEventListener('load', e => {
  4180. processLazyPreloader(swiper, e.target);
  4181. });
  4182. }
  4183. });
  4184. preload(swiper);
  4185. // Init Flag
  4186. swiper.initialized = true;
  4187. preload(swiper);
  4188. // Emit
  4189. swiper.emit('init');
  4190. swiper.emit('afterInit');
  4191. return swiper;
  4192. }
  4193. destroy(deleteInstance, cleanStyles) {
  4194. if (deleteInstance === void 0) {
  4195. deleteInstance = true;
  4196. }
  4197. if (cleanStyles === void 0) {
  4198. cleanStyles = true;
  4199. }
  4200. const swiper = this;
  4201. const {
  4202. params,
  4203. el,
  4204. wrapperEl,
  4205. slides
  4206. } = swiper;
  4207. if (typeof swiper.params === 'undefined' || swiper.destroyed) {
  4208. return null;
  4209. }
  4210. swiper.emit('beforeDestroy');
  4211. // Init Flag
  4212. swiper.initialized = false;
  4213. // Detach events
  4214. swiper.detachEvents();
  4215. // Destroy loop
  4216. if (params.loop) {
  4217. swiper.loopDestroy();
  4218. }
  4219. // Cleanup styles
  4220. if (cleanStyles) {
  4221. swiper.removeClasses();
  4222. if (el && typeof el !== 'string') {
  4223. el.removeAttribute('style');
  4224. }
  4225. if (wrapperEl) {
  4226. wrapperEl.removeAttribute('style');
  4227. }
  4228. if (slides && slides.length) {
  4229. slides.forEach(slideEl => {
  4230. slideEl.classList.remove(params.slideVisibleClass, params.slideFullyVisibleClass, params.slideActiveClass, params.slideNextClass, params.slidePrevClass);
  4231. slideEl.removeAttribute('style');
  4232. slideEl.removeAttribute('data-swiper-slide-index');
  4233. });
  4234. }
  4235. }
  4236. swiper.emit('destroy');
  4237. // Detach emitter events
  4238. Object.keys(swiper.eventsListeners).forEach(eventName => {
  4239. swiper.off(eventName);
  4240. });
  4241. if (deleteInstance !== false) {
  4242. if (swiper.el && typeof swiper.el !== 'string') {
  4243. swiper.el.swiper = null;
  4244. }
  4245. deleteProps(swiper);
  4246. }
  4247. swiper.destroyed = true;
  4248. return null;
  4249. }
  4250. static extendDefaults(newDefaults) {
  4251. extend$1(extendedDefaults, newDefaults);
  4252. }
  4253. static get extendedDefaults() {
  4254. return extendedDefaults;
  4255. }
  4256. static get defaults() {
  4257. return defaults;
  4258. }
  4259. static installModule(mod) {
  4260. if (!Swiper.prototype.__modules__) Swiper.prototype.__modules__ = [];
  4261. const modules = Swiper.prototype.__modules__;
  4262. if (typeof mod === 'function' && modules.indexOf(mod) < 0) {
  4263. modules.push(mod);
  4264. }
  4265. }
  4266. static use(module) {
  4267. if (Array.isArray(module)) {
  4268. module.forEach(m => Swiper.installModule(m));
  4269. return Swiper;
  4270. }
  4271. Swiper.installModule(module);
  4272. return Swiper;
  4273. }
  4274. }
  4275. Object.keys(prototypes).forEach(prototypeGroup => {
  4276. Object.keys(prototypes[prototypeGroup]).forEach(protoMethod => {
  4277. Swiper.prototype[protoMethod] = prototypes[prototypeGroup][protoMethod];
  4278. });
  4279. });
  4280. Swiper.use([Resize, Observer]);
  4281. /* underscore in name -> watch for changes */
  4282. const paramsList = ['eventsPrefix', 'injectStyles', 'injectStylesUrls', 'modules', 'init', '_direction', 'oneWayMovement', 'swiperElementNodeName', 'touchEventsTarget', 'initialSlide', '_speed', 'cssMode', 'updateOnWindowResize', 'resizeObserver', 'nested', 'focusableElements', '_enabled', '_width', '_height', 'preventInteractionOnTransition', 'userAgent', 'url', '_edgeSwipeDetection', '_edgeSwipeThreshold', '_freeMode', '_autoHeight', 'setWrapperSize', 'virtualTranslate', '_effect', 'breakpoints', 'breakpointsBase', '_spaceBetween', '_slidesPerView', 'maxBackfaceHiddenSlides', '_grid', '_slidesPerGroup', '_slidesPerGroupSkip', '_slidesPerGroupAuto', '_centeredSlides', '_centeredSlidesBounds', '_slidesOffsetBefore', '_slidesOffsetAfter', 'normalizeSlideIndex', '_centerInsufficientSlides', '_watchOverflow', 'roundLengths', 'touchRatio', 'touchAngle', 'simulateTouch', '_shortSwipes', '_longSwipes', 'longSwipesRatio', 'longSwipesMs', '_followFinger', 'allowTouchMove', '_threshold', 'touchMoveStopPropagation', 'touchStartPreventDefault', 'touchStartForcePreventDefault', 'touchReleaseOnEdges', 'uniqueNavElements', '_resistance', '_resistanceRatio', '_watchSlidesProgress', '_grabCursor', 'preventClicks', 'preventClicksPropagation', '_slideToClickedSlide', '_loop', 'loopAdditionalSlides', 'loopAddBlankSlides', 'loopPreventsSliding', '_rewind', '_allowSlidePrev', '_allowSlideNext', '_swipeHandler', '_noSwiping', 'noSwipingClass', 'noSwipingSelector', 'passiveListeners', 'containerModifierClass', 'slideClass', 'slideActiveClass', 'slideVisibleClass', 'slideFullyVisibleClass', 'slideNextClass', 'slidePrevClass', 'slideBlankClass', 'wrapperClass', 'lazyPreloaderClass', 'lazyPreloadPrevNext', 'runCallbacksOnInit', 'observer', 'observeParents', 'observeSlideChildren',
  4283. // modules
  4284. 'a11y', '_autoplay', '_controller', 'coverflowEffect', 'cubeEffect', 'fadeEffect', 'flipEffect', 'creativeEffect', 'cardsEffect', 'hashNavigation', 'history', 'keyboard', 'mousewheel', '_navigation', '_pagination', 'parallax', '_scrollbar', '_thumbs', 'virtual', 'zoom', 'control'];
  4285. function isObject(o) {
  4286. return typeof o === 'object' && o !== null && o.constructor && Object.prototype.toString.call(o).slice(8, -1) === 'Object' && !o.__swiper__;
  4287. }
  4288. function extend(target, src) {
  4289. const noExtend = ['__proto__', 'constructor', 'prototype'];
  4290. Object.keys(src).filter(key => noExtend.indexOf(key) < 0).forEach(key => {
  4291. if (typeof target[key] === 'undefined') target[key] = src[key];else if (isObject(src[key]) && isObject(target[key]) && Object.keys(src[key]).length > 0) {
  4292. if (src[key].__swiper__) target[key] = src[key];else extend(target[key], src[key]);
  4293. } else {
  4294. target[key] = src[key];
  4295. }
  4296. });
  4297. }
  4298. function needsNavigation(params) {
  4299. if (params === void 0) {
  4300. params = {};
  4301. }
  4302. return params.navigation && typeof params.navigation.nextEl === 'undefined' && typeof params.navigation.prevEl === 'undefined';
  4303. }
  4304. function needsPagination(params) {
  4305. if (params === void 0) {
  4306. params = {};
  4307. }
  4308. return params.pagination && typeof params.pagination.el === 'undefined';
  4309. }
  4310. function needsScrollbar(params) {
  4311. if (params === void 0) {
  4312. params = {};
  4313. }
  4314. return params.scrollbar && typeof params.scrollbar.el === 'undefined';
  4315. }
  4316. function attrToProp(attrName) {
  4317. if (attrName === void 0) {
  4318. attrName = '';
  4319. }
  4320. return attrName.replace(/-[a-z]/g, l => l.toUpperCase().replace('-', ''));
  4321. }
  4322. function updateSwiper(_ref) {
  4323. let {
  4324. swiper,
  4325. slides,
  4326. passedParams,
  4327. changedParams,
  4328. nextEl,
  4329. prevEl,
  4330. scrollbarEl,
  4331. paginationEl
  4332. } = _ref;
  4333. const updateParams = changedParams.filter(key => key !== 'children' && key !== 'direction' && key !== 'wrapperClass');
  4334. const {
  4335. params: currentParams,
  4336. pagination,
  4337. navigation,
  4338. scrollbar,
  4339. virtual,
  4340. thumbs
  4341. } = swiper;
  4342. let needThumbsInit;
  4343. let needControllerInit;
  4344. let needPaginationInit;
  4345. let needScrollbarInit;
  4346. let needNavigationInit;
  4347. let loopNeedDestroy;
  4348. let loopNeedEnable;
  4349. let loopNeedReloop;
  4350. if (changedParams.includes('thumbs') && passedParams.thumbs && passedParams.thumbs.swiper && !passedParams.thumbs.swiper.destroyed && currentParams.thumbs && (!currentParams.thumbs.swiper || currentParams.thumbs.swiper.destroyed)) {
  4351. needThumbsInit = true;
  4352. }
  4353. if (changedParams.includes('controller') && passedParams.controller && passedParams.controller.control && currentParams.controller && !currentParams.controller.control) {
  4354. needControllerInit = true;
  4355. }
  4356. if (changedParams.includes('pagination') && passedParams.pagination && (passedParams.pagination.el || paginationEl) && (currentParams.pagination || currentParams.pagination === false) && pagination && !pagination.el) {
  4357. needPaginationInit = true;
  4358. }
  4359. if (changedParams.includes('scrollbar') && passedParams.scrollbar && (passedParams.scrollbar.el || scrollbarEl) && (currentParams.scrollbar || currentParams.scrollbar === false) && scrollbar && !scrollbar.el) {
  4360. needScrollbarInit = true;
  4361. }
  4362. if (changedParams.includes('navigation') && passedParams.navigation && (passedParams.navigation.prevEl || prevEl) && (passedParams.navigation.nextEl || nextEl) && (currentParams.navigation || currentParams.navigation === false) && navigation && !navigation.prevEl && !navigation.nextEl) {
  4363. needNavigationInit = true;
  4364. }
  4365. const destroyModule = mod => {
  4366. if (!swiper[mod]) return;
  4367. swiper[mod].destroy();
  4368. if (mod === 'navigation') {
  4369. if (swiper.isElement) {
  4370. swiper[mod].prevEl.remove();
  4371. swiper[mod].nextEl.remove();
  4372. }
  4373. currentParams[mod].prevEl = undefined;
  4374. currentParams[mod].nextEl = undefined;
  4375. swiper[mod].prevEl = undefined;
  4376. swiper[mod].nextEl = undefined;
  4377. } else {
  4378. if (swiper.isElement) {
  4379. swiper[mod].el.remove();
  4380. }
  4381. currentParams[mod].el = undefined;
  4382. swiper[mod].el = undefined;
  4383. }
  4384. };
  4385. if (changedParams.includes('loop') && swiper.isElement) {
  4386. if (currentParams.loop && !passedParams.loop) {
  4387. loopNeedDestroy = true;
  4388. } else if (!currentParams.loop && passedParams.loop) {
  4389. loopNeedEnable = true;
  4390. } else {
  4391. loopNeedReloop = true;
  4392. }
  4393. }
  4394. updateParams.forEach(key => {
  4395. if (isObject(currentParams[key]) && isObject(passedParams[key])) {
  4396. Object.assign(currentParams[key], passedParams[key]);
  4397. if ((key === 'navigation' || key === 'pagination' || key === 'scrollbar') && 'enabled' in passedParams[key] && !passedParams[key].enabled) {
  4398. destroyModule(key);
  4399. }
  4400. } else {
  4401. const newValue = passedParams[key];
  4402. if ((newValue === true || newValue === false) && (key === 'navigation' || key === 'pagination' || key === 'scrollbar')) {
  4403. if (newValue === false) {
  4404. destroyModule(key);
  4405. }
  4406. } else {
  4407. currentParams[key] = passedParams[key];
  4408. }
  4409. }
  4410. });
  4411. if (updateParams.includes('controller') && !needControllerInit && swiper.controller && swiper.controller.control && currentParams.controller && currentParams.controller.control) {
  4412. swiper.controller.control = currentParams.controller.control;
  4413. }
  4414. if (changedParams.includes('children') && slides && virtual && currentParams.virtual.enabled) {
  4415. virtual.slides = slides;
  4416. virtual.update(true);
  4417. } else if (changedParams.includes('virtual') && virtual && currentParams.virtual.enabled) {
  4418. if (slides) virtual.slides = slides;
  4419. virtual.update(true);
  4420. }
  4421. if (changedParams.includes('children') && slides && currentParams.loop) {
  4422. loopNeedReloop = true;
  4423. }
  4424. if (needThumbsInit) {
  4425. const initialized = thumbs.init();
  4426. if (initialized) thumbs.update(true);
  4427. }
  4428. if (needControllerInit) {
  4429. swiper.controller.control = currentParams.controller.control;
  4430. }
  4431. if (needPaginationInit) {
  4432. if (swiper.isElement && (!paginationEl || typeof paginationEl === 'string')) {
  4433. paginationEl = document.createElement('div');
  4434. paginationEl.classList.add('swiper-pagination');
  4435. paginationEl.part.add('pagination');
  4436. swiper.el.appendChild(paginationEl);
  4437. }
  4438. if (paginationEl) currentParams.pagination.el = paginationEl;
  4439. pagination.init();
  4440. pagination.render();
  4441. pagination.update();
  4442. }
  4443. if (needScrollbarInit) {
  4444. if (swiper.isElement && (!scrollbarEl || typeof scrollbarEl === 'string')) {
  4445. scrollbarEl = document.createElement('div');
  4446. scrollbarEl.classList.add('swiper-scrollbar');
  4447. scrollbarEl.part.add('scrollbar');
  4448. swiper.el.appendChild(scrollbarEl);
  4449. }
  4450. if (scrollbarEl) currentParams.scrollbar.el = scrollbarEl;
  4451. scrollbar.init();
  4452. scrollbar.updateSize();
  4453. scrollbar.setTranslate();
  4454. }
  4455. if (needNavigationInit) {
  4456. if (swiper.isElement) {
  4457. if (!nextEl || typeof nextEl === 'string') {
  4458. nextEl = document.createElement('div');
  4459. nextEl.classList.add('swiper-button-next');
  4460. setInnerHTML(nextEl, swiper.hostEl.constructor.nextButtonSvg);
  4461. nextEl.part.add('button-next');
  4462. swiper.el.appendChild(nextEl);
  4463. }
  4464. if (!prevEl || typeof prevEl === 'string') {
  4465. prevEl = document.createElement('div');
  4466. prevEl.classList.add('swiper-button-prev');
  4467. setInnerHTML(prevEl, swiper.hostEl.constructor.prevButtonSvg);
  4468. prevEl.part.add('button-prev');
  4469. swiper.el.appendChild(prevEl);
  4470. }
  4471. }
  4472. if (nextEl) currentParams.navigation.nextEl = nextEl;
  4473. if (prevEl) currentParams.navigation.prevEl = prevEl;
  4474. navigation.init();
  4475. navigation.update();
  4476. }
  4477. if (changedParams.includes('allowSlideNext')) {
  4478. swiper.allowSlideNext = passedParams.allowSlideNext;
  4479. }
  4480. if (changedParams.includes('allowSlidePrev')) {
  4481. swiper.allowSlidePrev = passedParams.allowSlidePrev;
  4482. }
  4483. if (changedParams.includes('direction')) {
  4484. swiper.changeDirection(passedParams.direction, false);
  4485. }
  4486. if (loopNeedDestroy || loopNeedReloop) {
  4487. swiper.loopDestroy();
  4488. }
  4489. if (loopNeedEnable || loopNeedReloop) {
  4490. swiper.loopCreate();
  4491. }
  4492. swiper.update();
  4493. }
  4494. const formatValue = val => {
  4495. if (parseFloat(val) === Number(val)) return Number(val);
  4496. if (val === 'true') return true;
  4497. if (val === '') return true;
  4498. if (val === 'false') return false;
  4499. if (val === 'null') return null;
  4500. if (val === 'undefined') return undefined;
  4501. if (typeof val === 'string' && val.includes('{') && val.includes('}') && val.includes('"')) {
  4502. let v;
  4503. try {
  4504. v = JSON.parse(val);
  4505. } catch (err) {
  4506. v = val;
  4507. }
  4508. return v;
  4509. }
  4510. return val;
  4511. };
  4512. const modulesParamsList = ['a11y', 'autoplay', 'controller', 'cards-effect', 'coverflow-effect', 'creative-effect', 'cube-effect', 'fade-effect', 'flip-effect', 'free-mode', 'grid', 'hash-navigation', 'history', 'keyboard', 'mousewheel', 'navigation', 'pagination', 'parallax', 'scrollbar', 'thumbs', 'virtual', 'zoom'];
  4513. function getParams(element, propName, propValue) {
  4514. const params = {};
  4515. const passedParams = {};
  4516. extend(params, defaults);
  4517. const localParamsList = [...paramsList, 'on'];
  4518. const allowedParams = localParamsList.map(key => key.replace(/_/, ''));
  4519. // First check props
  4520. localParamsList.forEach(paramName => {
  4521. paramName = paramName.replace('_', '');
  4522. if (typeof element[paramName] !== 'undefined') {
  4523. passedParams[paramName] = element[paramName];
  4524. }
  4525. });
  4526. // Attributes
  4527. const attrsList = [...element.attributes];
  4528. if (typeof propName === 'string' && typeof propValue !== 'undefined') {
  4529. attrsList.push({
  4530. name: propName,
  4531. value: isObject(propValue) ? {
  4532. ...propValue
  4533. } : propValue
  4534. });
  4535. }
  4536. attrsList.forEach(attr => {
  4537. const moduleParam = modulesParamsList.find(mParam => attr.name.startsWith(`${mParam}-`));
  4538. if (moduleParam) {
  4539. const parentObjName = attrToProp(moduleParam);
  4540. const subObjName = attrToProp(attr.name.split(`${moduleParam}-`)[1]);
  4541. if (typeof passedParams[parentObjName] === 'undefined') {
  4542. passedParams[parentObjName] = {};
  4543. }
  4544. if (passedParams[parentObjName] === true) {
  4545. passedParams[parentObjName] = {
  4546. enabled: true
  4547. };
  4548. }
  4549. if (passedParams[parentObjName] === false) {
  4550. passedParams[parentObjName] = {
  4551. enabled: false
  4552. };
  4553. }
  4554. passedParams[parentObjName][subObjName] = formatValue(attr.value);
  4555. } else {
  4556. const name = attrToProp(attr.name);
  4557. if (!allowedParams.includes(name)) return;
  4558. const value = formatValue(attr.value);
  4559. if (passedParams[name] && modulesParamsList.includes(attr.name) && !isObject(value)) {
  4560. if (passedParams[name].constructor !== Object) {
  4561. passedParams[name] = {};
  4562. }
  4563. passedParams[name].enabled = !!value;
  4564. } else {
  4565. passedParams[name] = value;
  4566. }
  4567. }
  4568. });
  4569. extend(params, passedParams);
  4570. if (params.navigation) {
  4571. params.navigation = {
  4572. prevEl: '.swiper-button-prev',
  4573. nextEl: '.swiper-button-next',
  4574. ...(params.navigation !== true ? params.navigation : {})
  4575. };
  4576. } else if (params.navigation === false) {
  4577. delete params.navigation;
  4578. }
  4579. if (params.scrollbar) {
  4580. params.scrollbar = {
  4581. el: '.swiper-scrollbar',
  4582. ...(params.scrollbar !== true ? params.scrollbar : {})
  4583. };
  4584. } else if (params.scrollbar === false) {
  4585. delete params.scrollbar;
  4586. }
  4587. if (params.pagination) {
  4588. params.pagination = {
  4589. el: '.swiper-pagination',
  4590. ...(params.pagination !== true ? params.pagination : {})
  4591. };
  4592. } else if (params.pagination === false) {
  4593. delete params.pagination;
  4594. }
  4595. return {
  4596. params,
  4597. passedParams
  4598. };
  4599. }
  4600. /**
  4601. * Swiper Custom Element 11.2.10
  4602. * Most modern mobile touch slider and framework with hardware accelerated transitions
  4603. * https://swiperjs.com
  4604. *
  4605. * Copyright 2014-2025 Vladimir Kharlampidi
  4606. *
  4607. * Released under the MIT License
  4608. *
  4609. * Released on: June 28, 2025
  4610. */
  4611. /* eslint-disable spaced-comment */
  4612. const SwiperCSS = `:host{--swiper-theme-color:#007aff}:host{position:relative;display:block;margin-left:auto;margin-right:auto;z-index:1}.swiper{width:100%;height:100%;margin-left:auto;margin-right:auto;position:relative;overflow:hidden;list-style:none;padding:0;z-index:1;display:block}.swiper-vertical>.swiper-wrapper{flex-direction:column}.swiper-wrapper{position:relative;width:100%;height:100%;z-index:1;display:flex;transition-property:transform;transition-timing-function:var(--swiper-wrapper-transition-timing-function,initial);box-sizing:content-box}.swiper-android ::slotted(swiper-slide),.swiper-ios ::slotted(swiper-slide),.swiper-wrapper{transform:translate3d(0px,0,0)}.swiper-horizontal{touch-action:pan-y}.swiper-vertical{touch-action:pan-x}::slotted(swiper-slide){flex-shrink:0;width:100%;height:100%;position:relative;transition-property:transform;display:block}::slotted(.swiper-slide-invisible-blank){visibility:hidden}.swiper-autoheight,.swiper-autoheight ::slotted(swiper-slide){height:auto}.swiper-autoheight .swiper-wrapper{align-items:flex-start;transition-property:transform,height}.swiper-backface-hidden ::slotted(swiper-slide){transform:translateZ(0);-webkit-backface-visibility:hidden;backface-visibility:hidden}.swiper-3d.swiper-css-mode .swiper-wrapper{perspective:1200px}.swiper-3d .swiper-wrapper{transform-style:preserve-3d}.swiper-3d{perspective:1200px}.swiper-3d .swiper-cube-shadow,.swiper-3d ::slotted(swiper-slide){transform-style:preserve-3d}.swiper-css-mode>.swiper-wrapper{overflow:auto;scrollbar-width:none;-ms-overflow-style:none}.swiper-css-mode>.swiper-wrapper::-webkit-scrollbar{display:none}.swiper-css-mode ::slotted(swiper-slide){scroll-snap-align:start start}.swiper-css-mode.swiper-horizontal>.swiper-wrapper{scroll-snap-type:x mandatory}.swiper-css-mode.swiper-vertical>.swiper-wrapper{scroll-snap-type:y mandatory}.swiper-css-mode.swiper-free-mode>.swiper-wrapper{scroll-snap-type:none}.swiper-css-mode.swiper-free-mode ::slotted(swiper-slide){scroll-snap-align:none}.swiper-css-mode.swiper-centered>.swiper-wrapper::before{content:'';flex-shrink:0;order:9999}.swiper-css-mode.swiper-centered ::slotted(swiper-slide){scroll-snap-align:center center;scroll-snap-stop:always}.swiper-css-mode.swiper-centered.swiper-horizontal ::slotted(swiper-slide):first-child{margin-inline-start:var(--swiper-centered-offset-before)}.swiper-css-mode.swiper-centered.swiper-horizontal>.swiper-wrapper::before{height:100%;min-height:1px;width:var(--swiper-centered-offset-after)}.swiper-css-mode.swiper-centered.swiper-vertical ::slotted(swiper-slide):first-child{margin-block-start:var(--swiper-centered-offset-before)}.swiper-css-mode.swiper-centered.swiper-vertical>.swiper-wrapper::before{width:100%;min-width:1px;height:var(--swiper-centered-offset-after)}`;
  4613. const SwiperSlideCSS = `::slotted(.swiper-slide-shadow),::slotted(.swiper-slide-shadow-bottom),::slotted(.swiper-slide-shadow-left),::slotted(.swiper-slide-shadow-right),::slotted(.swiper-slide-shadow-top){position:absolute;left:0;top:0;width:100%;height:100%;pointer-events:none;z-index:10}::slotted(.swiper-slide-shadow){background:rgba(0,0,0,.15)}::slotted(.swiper-slide-shadow-left){background-image:linear-gradient(to left,rgba(0,0,0,.5),rgba(0,0,0,0))}::slotted(.swiper-slide-shadow-right){background-image:linear-gradient(to right,rgba(0,0,0,.5),rgba(0,0,0,0))}::slotted(.swiper-slide-shadow-top){background-image:linear-gradient(to top,rgba(0,0,0,.5),rgba(0,0,0,0))}::slotted(.swiper-slide-shadow-bottom){background-image:linear-gradient(to bottom,rgba(0,0,0,.5),rgba(0,0,0,0))}.swiper-lazy-preloader{animation:swiper-preloader-spin 1s infinite linear;width:42px;height:42px;position:absolute;left:50%;top:50%;margin-left:-21px;margin-top:-21px;z-index:10;transform-origin:50%;box-sizing:border-box;border:4px solid var(--swiper-preloader-color,var(--swiper-theme-color));border-radius:50%;border-top-color:transparent}@keyframes swiper-preloader-spin{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}::slotted(.swiper-slide-shadow-cube.swiper-slide-shadow-bottom),::slotted(.swiper-slide-shadow-cube.swiper-slide-shadow-left),::slotted(.swiper-slide-shadow-cube.swiper-slide-shadow-right),::slotted(.swiper-slide-shadow-cube.swiper-slide-shadow-top){z-index:0;-webkit-backface-visibility:hidden;backface-visibility:hidden}::slotted(.swiper-slide-shadow-flip.swiper-slide-shadow-bottom),::slotted(.swiper-slide-shadow-flip.swiper-slide-shadow-left),::slotted(.swiper-slide-shadow-flip.swiper-slide-shadow-right),::slotted(.swiper-slide-shadow-flip.swiper-slide-shadow-top){z-index:0;-webkit-backface-visibility:hidden;backface-visibility:hidden}::slotted(.swiper-zoom-container){width:100%;height:100%;display:flex;justify-content:center;align-items:center;text-align:center}::slotted(.swiper-zoom-container)>canvas,::slotted(.swiper-zoom-container)>img,::slotted(.swiper-zoom-container)>svg{max-width:100%;max-height:100%;object-fit:contain}`;
  4614. class DummyHTMLElement {}
  4615. const ClassToExtend = typeof window === 'undefined' || typeof HTMLElement === 'undefined' ? DummyHTMLElement : HTMLElement;
  4616. const arrowSvg = `<svg width="11" height="20" viewBox="0 0 11 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0.38296 20.0762C0.111788 19.805 0.111788 19.3654 0.38296 19.0942L9.19758 10.2796L0.38296 1.46497C0.111788 1.19379 0.111788 0.754138 0.38296 0.482966C0.654131 0.211794 1.09379 0.211794 1.36496 0.482966L10.4341 9.55214C10.8359 9.9539 10.8359 10.6053 10.4341 11.007L1.36496 20.0762C1.09379 20.3474 0.654131 20.3474 0.38296 20.0762Z" fill="currentColor"/></svg>
  4617. `;
  4618. const addStyle = (shadowRoot, styles) => {
  4619. if (typeof CSSStyleSheet !== 'undefined' && shadowRoot.adoptedStyleSheets) {
  4620. const styleSheet = new CSSStyleSheet();
  4621. styleSheet.replaceSync(styles);
  4622. shadowRoot.adoptedStyleSheets = [styleSheet];
  4623. } else {
  4624. const style = document.createElement('style');
  4625. style.rel = 'stylesheet';
  4626. style.textContent = styles;
  4627. shadowRoot.appendChild(style);
  4628. }
  4629. };
  4630. class SwiperContainer extends ClassToExtend {
  4631. constructor() {
  4632. super();
  4633. this.attachShadow({
  4634. mode: 'open'
  4635. });
  4636. }
  4637. static get nextButtonSvg() {
  4638. return arrowSvg;
  4639. }
  4640. static get prevButtonSvg() {
  4641. return arrowSvg.replace('/></svg>', ' transform-origin="center" transform="rotate(180)"/></svg>');
  4642. }
  4643. cssStyles() {
  4644. return [SwiperCSS,
  4645. // eslint-disable-line
  4646. ...(this.injectStyles && Array.isArray(this.injectStyles) ? this.injectStyles : [])].join('\n');
  4647. }
  4648. cssLinks() {
  4649. return this.injectStylesUrls || [];
  4650. }
  4651. calcSlideSlots() {
  4652. const currentSideSlots = this.slideSlots || 0;
  4653. // slide slots
  4654. const slideSlotChildren = [...this.querySelectorAll(`[slot^=slide-]`)].map(child => {
  4655. return parseInt(child.getAttribute('slot').split('slide-')[1], 10);
  4656. });
  4657. this.slideSlots = slideSlotChildren.length ? Math.max(...slideSlotChildren) + 1 : 0;
  4658. if (!this.rendered) return;
  4659. if (this.slideSlots > currentSideSlots) {
  4660. for (let i = currentSideSlots; i < this.slideSlots; i += 1) {
  4661. const slideEl = document.createElement('swiper-slide');
  4662. slideEl.setAttribute('part', `slide slide-${i + 1}`);
  4663. const slotEl = document.createElement('slot');
  4664. slotEl.setAttribute('name', `slide-${i + 1}`);
  4665. slideEl.appendChild(slotEl);
  4666. this.shadowRoot.querySelector('.swiper-wrapper').appendChild(slideEl);
  4667. }
  4668. } else if (this.slideSlots < currentSideSlots) {
  4669. const slides = this.swiper.slides;
  4670. for (let i = slides.length - 1; i >= 0; i -= 1) {
  4671. if (i > this.slideSlots) {
  4672. slides[i].remove();
  4673. }
  4674. }
  4675. }
  4676. }
  4677. render() {
  4678. if (this.rendered) return;
  4679. this.calcSlideSlots();
  4680. // local styles
  4681. let localStyles = this.cssStyles();
  4682. if (this.slideSlots > 0) {
  4683. localStyles = localStyles.replace(/::slotted\(([a-z-0-9.]*)\)/g, '$1');
  4684. }
  4685. if (localStyles.length) {
  4686. addStyle(this.shadowRoot, localStyles);
  4687. }
  4688. this.cssLinks().forEach(url => {
  4689. const linkExists = this.shadowRoot.querySelector(`link[href="${url}"]`);
  4690. if (linkExists) return;
  4691. const linkEl = document.createElement('link');
  4692. linkEl.rel = 'stylesheet';
  4693. linkEl.href = url;
  4694. this.shadowRoot.appendChild(linkEl);
  4695. });
  4696. // prettier-ignore
  4697. const el = document.createElement('div');
  4698. el.classList.add('swiper');
  4699. el.part = 'container';
  4700. // prettier-ignore
  4701. setInnerHTML(el, `
  4702. <slot name="container-start"></slot>
  4703. <div class="swiper-wrapper" part="wrapper">
  4704. <slot></slot>
  4705. ${Array.from({
  4706. length: this.slideSlots
  4707. }).map((_, index) => `
  4708. <swiper-slide part="slide slide-${index}">
  4709. <slot name="slide-${index}"></slot>
  4710. </swiper-slide>
  4711. `).join('')}
  4712. </div>
  4713. <slot name="container-end"></slot>
  4714. ${needsNavigation(this.passedParams) ? `
  4715. <div part="button-prev" class="swiper-button-prev">${this.constructor.prevButtonSvg}</div>
  4716. <div part="button-next" class="swiper-button-next">${this.constructor.nextButtonSvg}</div>
  4717. ` : ''}
  4718. ${needsPagination(this.passedParams) ? `
  4719. <div part="pagination" class="swiper-pagination"></div>
  4720. ` : ''}
  4721. ${needsScrollbar(this.passedParams) ? `
  4722. <div part="scrollbar" class="swiper-scrollbar"></div>
  4723. ` : ''}
  4724. `);
  4725. this.shadowRoot.appendChild(el);
  4726. this.rendered = true;
  4727. }
  4728. initialize() {
  4729. var _this = this;
  4730. if (this.swiper && this.swiper.initialized) return;
  4731. const {
  4732. params: swiperParams,
  4733. passedParams
  4734. } = getParams(this);
  4735. this.swiperParams = swiperParams;
  4736. this.passedParams = passedParams;
  4737. delete this.swiperParams.init;
  4738. this.render();
  4739. // eslint-disable-next-line
  4740. this.swiper = new Swiper(this.shadowRoot.querySelector('.swiper'), {
  4741. ...(swiperParams.virtual ? {} : {
  4742. observer: true
  4743. }),
  4744. ...swiperParams,
  4745. touchEventsTarget: 'container',
  4746. onAny: function (name) {
  4747. if (name === 'observerUpdate') {
  4748. _this.calcSlideSlots();
  4749. }
  4750. const eventName = swiperParams.eventsPrefix ? `${swiperParams.eventsPrefix}${name.toLowerCase()}` : name.toLowerCase();
  4751. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  4752. args[_key - 1] = arguments[_key];
  4753. }
  4754. const event = new CustomEvent(eventName, {
  4755. detail: args,
  4756. bubbles: name !== 'hashChange',
  4757. cancelable: true
  4758. });
  4759. _this.dispatchEvent(event);
  4760. }
  4761. });
  4762. }
  4763. connectedCallback() {
  4764. if (this.swiper && this.swiper.initialized && this.nested && this.closest('swiper-slide') && this.closest('swiper-slide').swiperLoopMoveDOM) {
  4765. return;
  4766. }
  4767. if (this.init === false || this.getAttribute('init') === 'false') {
  4768. return;
  4769. }
  4770. this.initialize();
  4771. }
  4772. disconnectedCallback() {
  4773. if (this.nested && this.closest('swiper-slide') && this.closest('swiper-slide').swiperLoopMoveDOM) {
  4774. return;
  4775. }
  4776. if (this.swiper && this.swiper.destroy) {
  4777. this.swiper.destroy();
  4778. }
  4779. }
  4780. updateSwiperOnPropChange(propName, propValue) {
  4781. const {
  4782. params: swiperParams,
  4783. passedParams
  4784. } = getParams(this, propName, propValue);
  4785. this.passedParams = passedParams;
  4786. this.swiperParams = swiperParams;
  4787. if (this.swiper && this.swiper.params[propName] === propValue) {
  4788. return;
  4789. }
  4790. updateSwiper({
  4791. swiper: this.swiper,
  4792. passedParams: this.passedParams,
  4793. changedParams: [attrToProp(propName)],
  4794. ...(propName === 'navigation' && passedParams[propName] ? {
  4795. prevEl: '.swiper-button-prev',
  4796. nextEl: '.swiper-button-next'
  4797. } : {}),
  4798. ...(propName === 'pagination' && passedParams[propName] ? {
  4799. paginationEl: '.swiper-pagination'
  4800. } : {}),
  4801. ...(propName === 'scrollbar' && passedParams[propName] ? {
  4802. scrollbarEl: '.swiper-scrollbar'
  4803. } : {})
  4804. });
  4805. }
  4806. attributeChangedCallback(attr, prevValue, newValue) {
  4807. if (!(this.swiper && this.swiper.initialized)) return;
  4808. if (prevValue === 'true' && newValue === null) {
  4809. newValue = false;
  4810. }
  4811. this.updateSwiperOnPropChange(attr, newValue);
  4812. }
  4813. static get observedAttributes() {
  4814. const attrs = paramsList.filter(param => param.includes('_')).map(param => param.replace(/[A-Z]/g, v => `-${v}`).replace('_', '').toLowerCase());
  4815. return attrs;
  4816. }
  4817. }
  4818. paramsList.forEach(paramName => {
  4819. if (paramName === 'init') return;
  4820. paramName = paramName.replace('_', '');
  4821. Object.defineProperty(SwiperContainer.prototype, paramName, {
  4822. configurable: true,
  4823. get() {
  4824. return (this.passedParams || {})[paramName];
  4825. },
  4826. set(value) {
  4827. if (!this.passedParams) this.passedParams = {};
  4828. this.passedParams[paramName] = value;
  4829. if (!(this.swiper && this.swiper.initialized)) return;
  4830. this.updateSwiperOnPropChange(paramName, value);
  4831. }
  4832. });
  4833. });
  4834. class SwiperSlide extends ClassToExtend {
  4835. constructor() {
  4836. super();
  4837. this.attachShadow({
  4838. mode: 'open'
  4839. });
  4840. }
  4841. render() {
  4842. const lazy = this.lazy || this.getAttribute('lazy') === '' || this.getAttribute('lazy') === 'true';
  4843. addStyle(this.shadowRoot, SwiperSlideCSS);
  4844. this.shadowRoot.appendChild(document.createElement('slot'));
  4845. if (lazy) {
  4846. const lazyDiv = document.createElement('div');
  4847. lazyDiv.classList.add('swiper-lazy-preloader');
  4848. lazyDiv.part.add('preloader');
  4849. this.shadowRoot.appendChild(lazyDiv);
  4850. }
  4851. }
  4852. initialize() {
  4853. this.render();
  4854. }
  4855. connectedCallback() {
  4856. if (this.swiperLoopMoveDOM) {
  4857. return;
  4858. }
  4859. this.initialize();
  4860. }
  4861. }
  4862. // eslint-disable-next-line
  4863. const register = () => {
  4864. if (typeof window === 'undefined') return;
  4865. if (!window.customElements.get('swiper-container')) window.customElements.define('swiper-container', SwiperContainer);
  4866. if (!window.customElements.get('swiper-slide')) window.customElements.define('swiper-slide', SwiperSlide);
  4867. };
  4868. if (typeof window !== 'undefined') {
  4869. window.SwiperElementRegisterParams = params => {
  4870. paramsList.push(...params);
  4871. };
  4872. }
  4873. register();
  4874. })();