UNPKG

swiper

Version:

Most modern mobile touch slider and framework with hardware accelerated transitions

2 lines 6.52 kB
import{g as getDocument}from"../shared/ssr-window.esm.min.mjs";import{c as classesToSelector}from"../shared/classes-to-selector.min.mjs";import{c as createElement,j as elementIndex,m as makeElementsArray,s as setInnerHTML}from"../shared/utils.min.mjs";function A11y({swiper:e,extendParams:a,on:t}){a({a11y:{enabled:!0,notificationClass:"swiper-notification",prevSlideMessage:"Previous slide",nextSlideMessage:"Next slide",firstSlideMessage:"This is the first slide",lastSlideMessage:"This is the last slide",paginationBulletMessage:"Go to slide {{index}}",slideLabelMessage:"{{index}} / {{slidesLength}}",containerMessage:null,containerRoleDescriptionMessage:null,containerRole:null,itemRoleDescriptionMessage:null,slideRole:"group",id:null,scrollOnFocus:!0,wrapperLiveRegion:!0}}),e.a11y={clicked:!1};let n,i,s=null,r=(new Date).getTime();function l(e){const a=s;0!==a.length&&setInnerHTML(a,e)}function o(e){(e=makeElementsArray(e)).forEach(e=>{e.setAttribute("tabIndex","0")})}function c(e){(e=makeElementsArray(e)).forEach(e=>{e.setAttribute("tabIndex","-1")})}function d(e,a){(e=makeElementsArray(e)).forEach(e=>{e.setAttribute("role",a)})}function m(e,a){(e=makeElementsArray(e)).forEach(e=>{e.setAttribute("aria-roledescription",a)})}function p(e,a){(e=makeElementsArray(e)).forEach(e=>{e.setAttribute("aria-label",a)})}function g(e){(e=makeElementsArray(e)).forEach(e=>{e.setAttribute("aria-disabled",!0)})}function u(e){(e=makeElementsArray(e)).forEach(e=>{e.setAttribute("aria-disabled",!1)})}function E(a){if(13!==a.keyCode&&32!==a.keyCode)return;const t=e.params.a11y,n=a.target;if(!e.pagination||!e.pagination.el||n!==e.pagination.el&&!e.pagination.el.contains(a.target)||a.target.matches(classesToSelector(e.params.pagination.bulletClass))){if(e.navigation&&e.navigation.prevEl&&e.navigation.nextEl){const a=makeElementsArray(e.navigation.prevEl);makeElementsArray(e.navigation.nextEl).includes(n)&&(e.isEnd&&!e.params.loop||e.slideNext(),e.isEnd?l(t.lastSlideMessage):l(t.nextSlideMessage)),a.includes(n)&&(e.isBeginning&&!e.params.loop||e.slidePrev(),e.isBeginning?l(t.firstSlideMessage):l(t.prevSlideMessage))}e.pagination&&n.matches(classesToSelector(e.params.pagination.bulletClass))&&n.click()}}function f(){return e.pagination&&e.pagination.bullets&&e.pagination.bullets.length}function v(){return f()&&e.params.pagination.clickable}const y=(e,a,t)=>{o(e),"BUTTON"!==e.tagName&&(d(e,"button"),e.addEventListener("keydown",E)),p(e,t),function(e,a){(e=makeElementsArray(e)).forEach(e=>{e.setAttribute("aria-controls",a)})}(e,a)},b=a=>{i&&i!==a.target&&!i.contains(a.target)&&(n=!0),e.a11y.clicked=!0},h=()=>{n=!1,requestAnimationFrame(()=>{requestAnimationFrame(()=>{e.destroyed||(e.a11y.clicked=!1)})})},A=e=>{r=(new Date).getTime()},k=a=>{if(e.a11y.clicked||!e.params.a11y.scrollOnFocus)return;if((new Date).getTime()-r<100)return;const t=a.target.closest(`.${e.params.slideClass}, swiper-slide`);if(!t||!e.slides.includes(t))return;i=t;const s=e.slides.indexOf(t)===e.activeIndex,l=e.params.watchSlidesProgress&&e.visibleSlides&&e.visibleSlides.includes(t);s||l||a.sourceCapabilities&&a.sourceCapabilities.firesTouchEvents||(e.isHorizontal()?e.el.scrollLeft=0:e.el.scrollTop=0,requestAnimationFrame(()=>{n||(e.params.loop?e.slideToLoop(e.getSlideIndexWhenGrid(parseInt(t.getAttribute("data-swiper-slide-index"))),0):e.slideTo(e.getSlideIndexWhenGrid(e.slides.indexOf(t)),0),n=!1)}))},x=()=>{const a=e.params.a11y;a.itemRoleDescriptionMessage&&m(e.slides,a.itemRoleDescriptionMessage),a.slideRole&&d(e.slides,a.slideRole);const t=e.slides.length;a.slideLabelMessage&&e.slides.forEach((n,i)=>{const s=e.params.loop?parseInt(n.getAttribute("data-swiper-slide-index"),10):i;p(n,a.slideLabelMessage.replace(/\{\{index\}\}/,s+1).replace(/\{\{slidesLength\}\}/,t))})},L=()=>{const a=e.params.a11y;e.el.append(s);const t=e.el;a.containerRoleDescriptionMessage&&m(t,a.containerRoleDescriptionMessage),a.containerMessage&&p(t,a.containerMessage),a.containerRole&&d(t,a.containerRole);const n=e.wrapperEl,i=a.id||n.getAttribute("id")||`swiper-wrapper-${function(e=16){return"x".repeat(e).replace(/x/g,()=>Math.round(16*Math.random()).toString(16))}(16)}`;var r;if(r=i,makeElementsArray(n).forEach(e=>{e.setAttribute("id",r)}),a.wrapperLiveRegion){!function(e,a){(e=makeElementsArray(e)).forEach(e=>{e.setAttribute("aria-live",a)})}(n,e.params.autoplay&&e.params.autoplay.enabled?"off":"polite")}x();let{nextEl:l,prevEl:o}=e.navigation?e.navigation:{};if(l=makeElementsArray(l),o=makeElementsArray(o),l&&l.forEach(e=>y(e,i,a.nextSlideMessage)),o&&o.forEach(e=>y(e,i,a.prevSlideMessage)),v()){makeElementsArray(e.pagination.el).forEach(e=>{e.addEventListener("keydown",E)})}getDocument().addEventListener("visibilitychange",A),e.el.addEventListener("focus",k,!0),e.el.addEventListener("focus",k,!0),e.el.addEventListener("pointerdown",b,!0),e.el.addEventListener("pointerup",h,!0)};t("beforeInit",()=>{s=createElement("span",e.params.a11y.notificationClass),s.setAttribute("aria-live","assertive"),s.setAttribute("aria-atomic","true")}),t("afterInit",()=>{e.params.a11y.enabled&&L()}),t("slidesLengthChange snapGridLengthChange slidesGridLengthChange",()=>{e.params.a11y.enabled&&x()}),t("fromEdge toEdge afterInit lock unlock",()=>{e.params.a11y.enabled&&function(){if(e.params.loop||e.params.rewind||!e.navigation)return;const{nextEl:a,prevEl:t}=e.navigation;t&&(e.isBeginning?(g(t),c(t)):(u(t),o(t))),a&&(e.isEnd?(g(a),c(a)):(u(a),o(a)))}()}),t("paginationUpdate",()=>{e.params.a11y.enabled&&function(){const a=e.params.a11y;f()&&e.pagination.bullets.forEach(t=>{e.params.pagination.clickable&&(o(t),e.params.pagination.renderBullet||(d(t,"button"),p(t,a.paginationBulletMessage.replace(/\{\{index\}\}/,elementIndex(t)+1)))),t.matches(classesToSelector(e.params.pagination.bulletActiveClass))?t.setAttribute("aria-current","true"):t.removeAttribute("aria-current")})}()}),t("destroy",()=>{e.params.a11y.enabled&&function(){s&&s.remove();let{nextEl:a,prevEl:t}=e.navigation?e.navigation:{};a=makeElementsArray(a),t=makeElementsArray(t),a&&a.forEach(e=>e.removeEventListener("keydown",E)),t&&t.forEach(e=>e.removeEventListener("keydown",E)),v()&&makeElementsArray(e.pagination.el).forEach(e=>{e.removeEventListener("keydown",E)});getDocument().removeEventListener("visibilitychange",A),e.el&&"string"!=typeof e.el&&(e.el.removeEventListener("focus",k,!0),e.el.removeEventListener("pointerdown",b,!0),e.el.removeEventListener("pointerup",h,!0))}()})}export{A11y as default}; //# sourceMappingURL=a11y.min.mjs.map