swiper-element.js 165 KB

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