vendor: 4,882 bytes, lines 1-126
1import { c as classesToSelector } from '../shared/classes-to-selector.mjs'; 2import { c as createElementIfNotDefined } from '../shared/create-element-if-not-defined.mjs'; 3import { m as makeElementsArray, f as elementOuterSize, h as elementIndex, a as elementParents } from '../shared/utils.mjs'; 4 5function Pagination(_ref) { 6 let { 7 swiper, 8 extendParams, 9 on, 10 emit 11 } = _ref; 12 const pfx = 'swiper-pagination'; 13 extendParams({ 14 pagination: { 15 el: null, 16 bulletElement: 'span', 17 clickable: false, 18 hideOnClick: false, 19 renderBullet: null, 20 renderProgressbar: null, 21 renderFraction: null, 22 renderCustom: null, 23 progressbarOpposite: false, 24 type: 'bullets', 25 // 'bullets' or 'progressbar' or 'fraction' or 'custom' 26 dynamicBullets: false, 27 dynamicMainBullets: 1, 28 formatFractionCurrent: number => number, 29 formatFractionTotal: number => number, 30 bulletClass: `${pfx}-bullet`, 31 bulletActiveClass: `${pfx}-bullet-active`, 32 modifierClass: `${pfx}-`, 33 currentClass: `${pfx}-current`, 34 totalClass: `${pfx}-total`, 35 hiddenClass: `${pfx}-hidden`, 36 progressbarFillClass: `${pfx}-progressbar-fill`, 37 progressbarOppositeClass: `${pfx}-progressbar-opposite`, 38 clickableClass: `${pfx}-clickable`, 39 lockClass: `${pfx}-lock`, 40 horizontalClass: `${pfx}-horizontal`, 41 verticalClass: `${pfx}-vertical`, 42 paginationDisabledClass: `${pfx}-disabled` 43 } 44 }); 45 swiper.pagination = { 46 el: null, 47 bullets: [] 48 }; 49 let bulletSize; 50 let dynamicBulletIndex = 0; 51 function isPaginationDisabled() { 52 return !swiper.params.pagination.el || !swiper.pagination.el || Array.isArray(swiper.pagination.el) && swiper.pagination.el.length === 0; 53 } 54 function setSideBullets(bulletEl, position) { 55 const { 56 bulletActiveClass 57 } = swiper.params.pagination; 58 if (!bulletEl) return; 59 bulletEl = bulletEl[`${position === 'prev' ? 'previous' : 'next'}ElementSibling`]; 60 if (bulletEl) { 61 bulletEl.classList.add(`${bulletActiveClass}-${position}`); 62 bulletEl = bulletEl[`${position === 'prev' ? 'previous' : 'next'}ElementSibling`]; 63 if (bulletEl) { 64 bulletEl.classList.add(`${bulletActiveClass}-${position}-${position}`); 65 } 66 } 67 } 68 function onBulletClick(e) { 69 const bulletEl = e.target.closest(classesToSelector(swiper.params.pagination.bulletClass)); 70 if (!bulletEl) { 71 return; 72 } 73 e.preventDefault(); 74 const index = elementIndex(bulletEl) * swiper.params.slidesPerGroup; 75 if (swiper.params.loop) { 76 if (swiper.realIndex === index) return; 77 swiper.slideToLoop(index); 78 } else { 79 swiper.slideTo(index); 80 } 81 } 82 function update() { 83 // Render || Update Pagination bullets/items 84 const rtl = swiper.rtl; 85 const params = swiper.params.pagination; 86 if (isPaginationDisabled()) return; 87 let el = swiper.pagination.el; 88 el = makeElementsArray(el); 89 // Current/Total 90 let current; 91 let previousIndex; 92 const slidesLength = swiper.virtual && swiper.params.virtual.enabled ? swiper.virtual.slides.length : swiper.slides.length; 93 const total = swiper.params.loop ? Math.ceil(slidesLength / swiper.params.slidesPerGroup) : swiper.snapGrid.length; 94 if (swiper.params.loop) { 95 previousIndex = swiper.previousRealIndex || 0; 96 current = swiper.params.slidesPerGroup > 1 ? Math.floor(swiper.realIndex / swiper.params.slidesPerGroup) : swiper.realIndex; 97 } else if (typeof swiper.snapIndex !== 'undefined') { 98 current = swiper.snapIndex; 99 previousIndex = swiper.previousSnapIndex; 100 } else { 101 previousIndex = swiper.previousIndex || 0; 102 current = swiper.activeIndex || 0; 103 } 104 // Types 105 if (params.type === 'bullets' && swiper.pagination.bullets && swiper.pagination.bullets.length > 0) { 106 const bullets = swiper.pagination.bullets; 107 let firstIndex; 108 let lastIndex; 109 let midIndex; 110 if (params.dynamicBullets) { 111 bulletSize = elementOuterSize(bullets[0], swiper.isHorizontal() ? 'width' : 'height', true); 112 el.forEach(subEl => { 113 subEl.style[swiper.isHorizontal() ? 'width' : 'height'] = `${bulletSize * (params.dynamicMainBullets + 4)}px`; 114 }); 115 if (params.dynamicMainBullets > 1 && previousIndex !== undefined) { 116 dynamicBulletIndex += current - (previousIndex || 0); 117 if (dynamicBulletIndex > params.dynamicMainBullets - 1) { 118 dynamicBulletIndex = params.dynamicMainBullets - 1; 119 } else if (dynamicBulletIndex < 0) { 120 dynamicBulletIndex = 0; 121 } 122 } 123 firstIndex = Math.max(current - dynamicBulletIndex, 0); 124 lastIndex = firstIndex + (Math.min(bullets.length, params.dynamicMainBullets) - 1); 125 midIndex = (lastIndex + firstIndex) / 2; 126 }
vendor: 5,039 bytes, lines 127-237
127 bullets.forEach(bulletEl => { 128 const classesToRemove = [...['', '-next', '-next-next', '-prev', '-prev-prev', '-main'].map(suffix => `${params.bulletActiveClass}${suffix}`)].map(s => typeof s === 'string' && s.includes(' ') ? s.split(' ') : s).flat(); 129 bulletEl.classList.remove(...classesToRemove); 130 }); 131 if (el.length > 1) { 132 bullets.forEach(bullet => { 133 const bulletIndex = elementIndex(bullet); 134 if (bulletIndex === current) { 135 bullet.classList.add(...params.bulletActiveClass.split(' ')); 136 } else if (swiper.isElement) { 137 bullet.setAttribute('part', 'bullet'); 138 } 139 if (params.dynamicBullets) { 140 if (bulletIndex >= firstIndex && bulletIndex <= lastIndex) { 141 bullet.classList.add(...`${params.bulletActiveClass}-main`.split(' ')); 142 } 143 if (bulletIndex === firstIndex) { 144 setSideBullets(bullet, 'prev'); 145 } 146 if (bulletIndex === lastIndex) { 147 setSideBullets(bullet, 'next'); 148 } 149 } 150 }); 151 } else { 152 const bullet = bullets[current]; 153 if (bullet) { 154 bullet.classList.add(...params.bulletActiveClass.split(' ')); 155 } 156 if (swiper.isElement) { 157 bullets.forEach((bulletEl, bulletIndex) => { 158 bulletEl.setAttribute('part', bulletIndex === current ? 'bullet-active' : 'bullet'); 159 }); 160 } 161 if (params.dynamicBullets) { 162 const firstDisplayedBullet = bullets[firstIndex]; 163 const lastDisplayedBullet = bullets[lastIndex]; 164 for (let i = firstIndex; i <= lastIndex; i += 1) { 165 if (bullets[i]) { 166 bullets[i].classList.add(...`${params.bulletActiveClass}-main`.split(' ')); 167 } 168 } 169 setSideBullets(firstDisplayedBullet, 'prev'); 170 setSideBullets(lastDisplayedBullet, 'next'); 171 } 172 } 173 if (params.dynamicBullets) { 174 const dynamicBulletsLength = Math.min(bullets.length, params.dynamicMainBullets + 4); 175 const bulletsOffset = (bulletSize * dynamicBulletsLength - bulletSize) / 2 - midIndex * bulletSize; 176 const offsetProp = rtl ? 'right' : 'left'; 177 bullets.forEach(bullet => { 178 bullet.style[swiper.isHorizontal() ? offsetProp : 'top'] = `${bulletsOffset}px`; 179 }); 180 } 181 } 182 el.forEach((subEl, subElIndex) => { 183 if (params.type === 'fraction') { 184 subEl.querySelectorAll(classesToSelector(params.currentClass)).forEach(fractionEl => { 185 fractionEl.textContent = params.formatFractionCurrent(current + 1); 186 }); 187 subEl.querySelectorAll(classesToSelector(params.totalClass)).forEach(totalEl => { 188 totalEl.textContent = params.formatFractionTotal(total); 189 }); 190 } 191 if (params.type === 'progressbar') { 192 let progressbarDirection; 193 if (params.progressbarOpposite) { 194 progressbarDirection = swiper.isHorizontal() ? 'vertical' : 'horizontal'; 195 } else { 196 progressbarDirection = swiper.isHorizontal() ? 'horizontal' : 'vertical'; 197 } 198 const scale = (current + 1) / total; 199 let scaleX = 1; 200 let scaleY = 1; 201 if (progressbarDirection === 'horizontal') { 202 scaleX = scale; 203 } else { 204 scaleY = scale; 205 } 206 subEl.querySelectorAll(classesToSelector(params.progressbarFillClass)).forEach(progressEl => { 207 progressEl.style.transform = `translate3d(0,0,0) scaleX(${scaleX}) scaleY(${scaleY})`; 208 progressEl.style.transitionDuration = `${swiper.params.speed}ms`; 209 }); 210 } 211 if (params.type === 'custom' && params.renderCustom) { 212 subEl.innerHTML = params.renderCustom(swiper, current + 1, total); 213 if (subElIndex === 0) emit('paginationRender', subEl); 214 } else { 215 if (subElIndex === 0) emit('paginationRender', subEl); 216 emit('paginationUpdate', subEl); 217 } 218 if (swiper.params.watchOverflow && swiper.enabled) { 219 subEl.classList[swiper.isLocked ? 'add' : 'remove'](params.lockClass); 220 } 221 }); 222 } 223 function render() { 224 // Render Container 225 const params = swiper.params.pagination; 226 if (isPaginationDisabled()) return; 227 const slidesLength = swiper.virtual && swiper.params.virtual.enabled ? swiper.virtual.slides.length : swiper.grid && swiper.params.grid.rows > 1 ? swiper.slides.length / Math.ceil(swiper.params.grid.rows) : swiper.slides.length; 228 let el = swiper.pagination.el; 229 el = makeElementsArray(el); 230 let paginationHTML = ''; 231 if (params.type === 'bullets') { 232 let numberOfBullets = swiper.params.loop ? Math.ceil(slidesLength / swiper.params.slidesPerGroup) : swiper.snapGrid.length; 233 if (swiper.params.freeMode && swiper.params.freeMode.enabled && numberOfBullets > slidesLength) { 234 numberOfBullets = slidesLength; 235 } 236 for (let i = 0; i < numberOfBullets; i += 1) { 237 if (params.renderBullet) {
vendor: 4,108 bytes, lines 238-344
238 paginationHTML += params.renderBullet.call(swiper, i, params.bulletClass); 239 } else { 240 // prettier-ignore 241 paginationHTML += `<${params.bulletElement} ${swiper.isElement ? 'part="bullet"' : ''} class="${params.bulletClass}"></${params.bulletElement}>`; 242 } 243 } 244 } 245 if (params.type === 'fraction') { 246 if (params.renderFraction) { 247 paginationHTML = params.renderFraction.call(swiper, params.currentClass, params.totalClass); 248 } else { 249 paginationHTML = `<span class="${params.currentClass}"></span>` + ' / ' + `<span class="${params.totalClass}"></span>`; 250 } 251 } 252 if (params.type === 'progressbar') { 253 if (params.renderProgressbar) { 254 paginationHTML = params.renderProgressbar.call(swiper, params.progressbarFillClass); 255 } else { 256 paginationHTML = `<span class="${params.progressbarFillClass}"></span>`; 257 } 258 } 259 swiper.pagination.bullets = []; 260 el.forEach(subEl => { 261 if (params.type !== 'custom') { 262 subEl.innerHTML = paginationHTML || ''; 263 } 264 if (params.type === 'bullets') { 265 swiper.pagination.bullets.push(...subEl.querySelectorAll(classesToSelector(params.bulletClass))); 266 } 267 }); 268 if (params.type !== 'custom') { 269 emit('paginationRender', el[0]); 270 } 271 } 272 function init() { 273 swiper.params.pagination = createElementIfNotDefined(swiper, swiper.originalParams.pagination, swiper.params.pagination, { 274 el: 'swiper-pagination' 275 }); 276 const params = swiper.params.pagination; 277 if (!params.el) return; 278 let el; 279 if (typeof params.el === 'string' && swiper.isElement) { 280 el = swiper.el.querySelector(params.el); 281 } 282 if (!el && typeof params.el === 'string') { 283 el = [...document.querySelectorAll(params.el)]; 284 } 285 if (!el) { 286 el = params.el; 287 } 288 if (!el || el.length === 0) return; 289 if (swiper.params.uniqueNavElements && typeof params.el === 'string' && Array.isArray(el) && el.length > 1) { 290 el = [...swiper.el.querySelectorAll(params.el)]; 291 // check if it belongs to another nested Swiper 292 if (el.length > 1) { 293 el = el.filter(subEl => { 294 if (elementParents(subEl, '.swiper')[0] !== swiper.el) return false; 295 return true; 296 })[0]; 297 } 298 } 299 if (Array.isArray(el) && el.length === 1) el = el[0]; 300 Object.assign(swiper.pagination, { 301 el 302 }); 303 el = makeElementsArray(el); 304 el.forEach(subEl => { 305 if (params.type === 'bullets' && params.clickable) { 306 subEl.classList.add(...(params.clickableClass || '').split(' ')); 307 } 308 subEl.classList.add(params.modifierClass + params.type); 309 subEl.classList.add(swiper.isHorizontal() ? params.horizontalClass : params.verticalClass); 310 if (params.type === 'bullets' && params.dynamicBullets) { 311 subEl.classList.add(`${params.modifierClass}${params.type}-dynamic`); 312 dynamicBulletIndex = 0; 313 if (params.dynamicMainBullets < 1) { 314 params.dynamicMainBullets = 1; 315 } 316 } 317 if (params.type === 'progressbar' && params.progressbarOpposite) { 318 subEl.classList.add(params.progressbarOppositeClass); 319 } 320 if (params.clickable) { 321 subEl.addEventListener('click', onBulletClick); 322 } 323 if (!swiper.enabled) { 324 subEl.classList.add(params.lockClass); 325 } 326 }); 327 } 328 function destroy() { 329 const params = swiper.params.pagination; 330 if (isPaginationDisabled()) return; 331 let el = swiper.pagination.el; 332 if (el) { 333 el = makeElementsArray(el); 334 el.forEach(subEl => { 335 subEl.classList.remove(params.hiddenClass); 336 subEl.classList.remove(params.modifierClass + params.type); 337 subEl.classList.remove(swiper.isHorizontal() ? params.horizontalClass : params.verticalClass); 338 if (params.clickable) { 339 subEl.classList.remove(...(params.clickableClass || '').split(' ')); 340 subEl.removeEventListener('click', onBulletClick); 341 } 342 }); 343 } 344 if (swiper.pagination.bullets) swiper.pagination.bullets.forEac
vendor: 2,884 bytes, lines 344-443
344h(subEl => subEl.classList.remove(...params.bulletActiveClass.split(' '))); 345 } 346 on('changeDirection', () => { 347 if (!swiper.pagination || !swiper.pagination.el) return; 348 const params = swiper.params.pagination; 349 let { 350 el 351 } = swiper.pagination; 352 el = makeElementsArray(el); 353 el.forEach(subEl => { 354 subEl.classList.remove(params.horizontalClass, params.verticalClass); 355 subEl.classList.add(swiper.isHorizontal() ? params.horizontalClass : params.verticalClass); 356 }); 357 }); 358 on('init', () => { 359 if (swiper.params.pagination.enabled === false) { 360 // eslint-disable-next-line 361 disable(); 362 } else { 363 init(); 364 render(); 365 update(); 366 } 367 }); 368 on('activeIndexChange', () => { 369 if (typeof swiper.snapIndex === 'undefined') { 370 update(); 371 } 372 }); 373 on('snapIndexChange', () => { 374 update(); 375 }); 376 on('snapGridLengthChange', () => { 377 render(); 378 update(); 379 }); 380 on('destroy', () => { 381 destroy(); 382 }); 383 on('enable disable', () => { 384 let { 385 el 386 } = swiper.pagination; 387 if (el) { 388 el = makeElementsArray(el); 389 el.forEach(subEl => subEl.classList[swiper.enabled ? 'remove' : 'add'](swiper.params.pagination.lockClass)); 390 } 391 }); 392 on('lock unlock', () => { 393 update(); 394 }); 395 on('click', (_s, e) => { 396 const targetEl = e.target; 397 const el = makeElementsArray(swiper.pagination.el); 398 if (swiper.params.pagination.el && swiper.params.pagination.hideOnClick && el && el.length > 0 && !targetEl.classList.contains(swiper.params.pagination.bulletClass)) { 399 if (swiper.navigation && (swiper.navigation.nextEl && targetEl === swiper.navigation.nextEl || swiper.navigation.prevEl && targetEl === swiper.navigation.prevEl)) return; 400 const isHidden = el[0].classList.contains(swiper.params.pagination.hiddenClass); 401 if (isHidden === true) { 402 emit('paginationShow'); 403 } else { 404 emit('paginationHide'); 405 } 406 el.forEach(subEl => subEl.classList.toggle(swiper.params.pagination.hiddenClass)); 407 } 408 }); 409 const enable = () => { 410 swiper.el.classList.remove(swiper.params.pagination.paginationDisabledClass); 411 let { 412 el 413 } = swiper.pagination; 414 if (el) { 415 el = makeElementsArray(el); 416 el.forEach(subEl => subEl.classList.remove(swiper.params.pagination.paginationDisabledClass)); 417 } 418 init(); 419 render(); 420 update(); 421 }; 422 const disable = () => { 423 swiper.el.classList.add(swiper.params.pagination.paginationDisabledClass); 424 let { 425 el 426 } = swiper.pagination; 427 if (el) { 428 el = makeElementsArray(el); 429 el.forEach(subEl => subEl.classList.add(swiper.params.pagination.paginationDisabledClass)); 430 } 431 destroy(); 432 }; 433 Object.assign(swiper.pagination, { 434 enable, 435 disable, 436 render, 437 update, 438 init, 439 destroy 440 }); 441} 442 443export { Pagination as default };
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.