@anoki/fse-ui
Version:
FSE UI components library
193 lines (192 loc) • 7.64 kB
JavaScript
import { g as F } from "./index.es469.js";
import { c as y } from "./index.es468.js";
import { c as K, m as n, h as j } from "./index.es467.js";
function Y(P) {
let {
swiper: i,
extendParams: N,
on: o
} = P;
N({
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
}
}), i.a11y = {
clicked: !1
};
let r = null, p, f, L = (/* @__PURE__ */ new Date()).getTime();
function u(e) {
const t = r;
t.length !== 0 && (t.innerHTML = "", t.innerHTML = e);
}
function B(e) {
const t = () => Math.round(16 * Math.random()).toString(16);
return "x".repeat(e).replace(/x/g, t);
}
function g(e) {
e = n(e), e.forEach((t) => {
t.setAttribute("tabIndex", "0");
});
}
function x(e) {
e = n(e), e.forEach((t) => {
t.setAttribute("tabIndex", "-1");
});
}
function m(e, t) {
e = n(e), e.forEach((a) => {
a.setAttribute("role", t);
});
}
function M(e, t) {
e = n(e), e.forEach((a) => {
a.setAttribute("aria-roledescription", t);
});
}
function O(e, t) {
e = n(e), e.forEach((a) => {
a.setAttribute("aria-controls", t);
});
}
function E(e, t) {
e = n(e), e.forEach((a) => {
a.setAttribute("aria-label", t);
});
}
function H(e, t) {
e = n(e), e.forEach((a) => {
a.setAttribute("id", t);
});
}
function q(e, t) {
e = n(e), e.forEach((a) => {
a.setAttribute("aria-live", t);
});
}
function A(e) {
e = n(e), e.forEach((t) => {
t.setAttribute("aria-disabled", !0);
});
}
function w(e) {
e = n(e), e.forEach((t) => {
t.setAttribute("aria-disabled", !1);
});
}
function d(e) {
if (e.keyCode !== 13 && e.keyCode !== 32) return;
const t = i.params.a11y, a = e.target;
if (!(i.pagination && i.pagination.el && (a === i.pagination.el || i.pagination.el.contains(e.target)) && !e.target.matches(y(i.params.pagination.bulletClass)))) {
if (i.navigation && i.navigation.prevEl && i.navigation.nextEl) {
const s = n(i.navigation.prevEl);
n(i.navigation.nextEl).includes(a) && (i.isEnd && !i.params.loop || i.slideNext(), i.isEnd ? u(t.lastSlideMessage) : u(t.nextSlideMessage)), s.includes(a) && (i.isBeginning && !i.params.loop || i.slidePrev(), i.isBeginning ? u(t.firstSlideMessage) : u(t.prevSlideMessage));
}
i.pagination && a.matches(y(i.params.pagination.bulletClass)) && a.click();
}
}
function G() {
if (i.params.loop || i.params.rewind || !i.navigation) return;
const {
nextEl: e,
prevEl: t
} = i.navigation;
t && (i.isBeginning ? (A(t), x(t)) : (w(t), g(t))), e && (i.isEnd ? (A(e), x(e)) : (w(e), g(e)));
}
function k() {
return i.pagination && i.pagination.bullets && i.pagination.bullets.length;
}
function C() {
return k() && i.params.pagination.clickable;
}
function U() {
const e = i.params.a11y;
k() && i.pagination.bullets.forEach((t) => {
i.params.pagination.clickable && (g(t), i.params.pagination.renderBullet || (m(t, "button"), E(t, e.paginationBulletMessage.replace(/\{\{index\}\}/, j(t) + 1)))), t.matches(y(i.params.pagination.bulletActiveClass)) ? t.setAttribute("aria-current", "true") : t.removeAttribute("aria-current");
});
}
const S = (e, t, a) => {
g(e), e.tagName !== "BUTTON" && (m(e, "button"), e.addEventListener("keydown", d)), E(e, a), O(e, t);
}, R = (e) => {
f && f !== e.target && !f.contains(e.target) && (p = !0), i.a11y.clicked = !0;
}, T = () => {
p = !1, requestAnimationFrame(() => {
requestAnimationFrame(() => {
i.destroyed || (i.a11y.clicked = !1);
});
});
}, D = (e) => {
L = (/* @__PURE__ */ new Date()).getTime();
}, h = (e) => {
if (i.a11y.clicked || !i.params.a11y.scrollOnFocus || (/* @__PURE__ */ new Date()).getTime() - L < 100) return;
const t = e.target.closest(`.${i.params.slideClass}, swiper-slide`);
if (!t || !i.slides.includes(t)) return;
f = t;
const a = i.slides.indexOf(t) === i.activeIndex, s = i.params.watchSlidesProgress && i.visibleSlides && i.visibleSlides.includes(t);
a || s || e.sourceCapabilities && e.sourceCapabilities.firesTouchEvents || (i.isHorizontal() ? i.el.scrollLeft = 0 : i.el.scrollTop = 0, requestAnimationFrame(() => {
p || (i.params.loop ? i.slideToLoop(parseInt(t.getAttribute("data-swiper-slide-index")), 0) : i.slideTo(i.slides.indexOf(t), 0), p = !1);
}));
}, I = () => {
const e = i.params.a11y;
e.itemRoleDescriptionMessage && M(i.slides, e.itemRoleDescriptionMessage), e.slideRole && m(i.slides, e.slideRole);
const t = i.slides.length;
e.slideLabelMessage && i.slides.forEach((a, s) => {
const l = i.params.loop ? parseInt(a.getAttribute("data-swiper-slide-index"), 10) : s, c = e.slideLabelMessage.replace(/\{\{index\}\}/, l + 1).replace(/\{\{slidesLength\}\}/, t);
E(a, c);
});
}, V = () => {
const e = i.params.a11y;
i.el.append(r);
const t = i.el;
e.containerRoleDescriptionMessage && M(t, e.containerRoleDescriptionMessage), e.containerMessage && E(t, e.containerMessage), e.containerRole && m(t, e.containerRole);
const a = i.wrapperEl, s = e.id || a.getAttribute("id") || `swiper-wrapper-${B(16)}`, l = i.params.autoplay && i.params.autoplay.enabled ? "off" : "polite";
H(a, s), q(a, l), I();
let {
nextEl: c,
prevEl: v
} = i.navigation ? i.navigation : {};
c = n(c), v = n(v), c && c.forEach((b) => S(b, s, e.nextSlideMessage)), v && v.forEach((b) => S(b, s, e.prevSlideMessage)), C() && n(i.pagination.el).forEach((z) => {
z.addEventListener("keydown", d);
}), F().addEventListener("visibilitychange", D), i.el.addEventListener("focus", h, !0), i.el.addEventListener("focus", h, !0), i.el.addEventListener("pointerdown", R, !0), i.el.addEventListener("pointerup", T, !0);
};
function $() {
r && r.remove();
let {
nextEl: e,
prevEl: t
} = i.navigation ? i.navigation : {};
e = n(e), t = n(t), e && e.forEach((s) => s.removeEventListener("keydown", d)), t && t.forEach((s) => s.removeEventListener("keydown", d)), C() && n(i.pagination.el).forEach((l) => {
l.removeEventListener("keydown", d);
}), F().removeEventListener("visibilitychange", D), i.el && typeof i.el != "string" && (i.el.removeEventListener("focus", h, !0), i.el.removeEventListener("pointerdown", R, !0), i.el.removeEventListener("pointerup", T, !0));
}
o("beforeInit", () => {
r = K("span", i.params.a11y.notificationClass), r.setAttribute("aria-live", "assertive"), r.setAttribute("aria-atomic", "true");
}), o("afterInit", () => {
i.params.a11y.enabled && V();
}), o("slidesLengthChange snapGridLengthChange slidesGridLengthChange", () => {
i.params.a11y.enabled && I();
}), o("fromEdge toEdge afterInit lock unlock", () => {
i.params.a11y.enabled && G();
}), o("paginationUpdate", () => {
i.params.a11y.enabled && U();
}), o("destroy", () => {
i.params.a11y.enabled && $();
});
}
export {
Y as default
};
//# sourceMappingURL=index.es264.js.map