swiper-core.mjs 127 KB

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