swiper-element.js 174 KB

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