(function () { 'use strict'; var AUTOPLAY_MS = 10000; /** * Divide o título em spans por caractere com stagger "middletoedge": * os caracteres do centro animam primeiro, as bordas por último. */ function splitTitle(el) { var text = el.textContent; var chars = Array.from(text); var mid = Math.floor(chars.length / 2); el.setAttribute('aria-label', text.trim()); el.innerHTML = chars.map(function (char, i) { var dist = Math.abs(i - mid); var delay = dist * 20; // 20ms de stagger por caractere a partir do centro if (char === ' ') { return ''; } return ''; }).join(''); } function activateSlide(slide) { if (!slide) return; void slide.offsetWidth; // força reflow para reiniciar as animações CSS slide.classList.add('pa-anim-active'); } function deactivateAllSlides(swiper) { swiper.slides.forEach(function (slide) { slide.classList.remove('pa-anim-active'); }); } function startTimer(timerFill, duration) { if (!timerFill) return; timerFill.style.transition = 'none'; timerFill.style.width = '0%'; requestAnimationFrame(function () { requestAnimationFrame(function () { timerFill.style.transition = 'width ' + duration + 'ms linear'; timerFill.style.width = '100%'; }); }); } document.addEventListener('DOMContentLoaded', function () { // Divide os títulos em caracteres para animação document.querySelectorAll('.pa-slide-title').forEach(splitTitle); var timerFill = document.querySelector('.pa-swiper-timer-fill'); var swiper = new Swiper('.pa-main-swiper', { effect: 'slide', speed: 1500, parallax: true, loop: true, autoplay: { delay: AUTOPLAY_MS, disableOnInteraction: false, pauseOnMouseEnter: true, }, keyboard: { enabled: true, }, navigation: { prevEl: '.pa-swiper-prev', nextEl: '.pa-swiper-next', }, pagination: { el: '.pa-swiper-pagination', clickable: true, }, on: { init: function () { activateSlide(this.slides[this.activeIndex]); startTimer(timerFill, AUTOPLAY_MS); }, slideChangeTransitionStart: function () { deactivateAllSlides(this); }, slideChangeTransitionEnd: function () { activateSlide(this.slides[this.activeIndex]); startTimer(timerFill, AUTOPLAY_MS); }, }, }); }); }());