itell-driverjs
Version:
A patched version of [driver.js](https://github.com/kamranahmedse/driver.js) for usage in ITELL.
700 lines (699 loc) • 26.7 kB
JavaScript
let F = {};
function D(e = {}) {
F = {
animate: !0,
allowClose: !0,
overlayClickBehavior: "close",
overlayOpacity: 0.7,
smoothScroll: !1,
disableActiveInteraction: !1,
showProgress: !1,
stagePadding: 10,
stageRadius: 5,
popoverOffset: 10,
showButtons: ["next", "previous", "close"],
disableButtons: [],
overlayColor: "#000",
...e
};
}
function s(e) {
return e ? F[e] : F;
}
let I = {};
function W(e, o) {
I[e] = o;
}
function _(e) {
var o;
(o = I[e]) == null || o.call(I);
}
function ae() {
I = {};
}
let O = {};
function b(e, o) {
O[e] = o;
}
function c(e) {
return e ? O[e] : O;
}
function K() {
O = {};
}
function N(e, o, t, i) {
return (e /= i / 2) < 1 ? t / 2 * e * e + o : -t / 2 * (--e * (e - 2) - 1) + o;
}
function Z(e) {
const o = 'a[href]:not([disabled]), button:not([disabled]), textarea:not([disabled]), input[type="text"]:not([disabled]), input[type="radio"]:not([disabled]), input[type="checkbox"]:not([disabled]), select:not([disabled])';
return e.flatMap((t) => {
const i = t.matches(o), d = Array.from(
t.querySelectorAll(o)
);
return [
...i ? [t] : [],
...d
];
}).filter((t) => getComputedStyle(t).pointerEvents !== "none" && de(t));
}
function G(e) {
if (!e || le(e))
return;
const o = s("smoothScroll");
e.scrollIntoView({
// Removing the smooth scrolling for elements which exist inside the scrollable parent
// This was causing the highlight to not properly render
behavior: !o || ce(e) ? "auto" : "smooth",
inline: "center",
block: "center"
});
}
function ce(e) {
if (!e || !e.parentElement)
return;
const o = e.parentElement;
return o.scrollHeight > o.clientHeight;
}
function le(e) {
const o = e.getBoundingClientRect();
return o.top >= 0 && o.left >= 0 && o.bottom <= (window.innerHeight || document.documentElement.clientHeight) && o.right <= (window.innerWidth || document.documentElement.clientWidth);
}
function de(e) {
return !!(e.offsetWidth || e.offsetHeight || e.getClientRects().length);
}
const J = (e) => {
if (!document.body.contains(e) && e.classList.contains("content-chunk")) {
const o = e.dataset.subsectionId, t = document.querySelector(`[data-subsection-id="${o}"]`);
if (t)
return t.classList.add("driver-active-element"), b("__activeElement", t), t;
}
return e;
};
function pe(e, o, t, i) {
let d = c("__activeStagePosition");
const n = d || t.getBoundingClientRect(), g = i.getBoundingClientRect(), m = N(
e,
n.x,
g.x - n.x,
o
), r = N(
e,
n.y,
g.y - n.y,
o
), v = N(
e,
n.width,
g.width - n.width,
o
), f = N(
e,
n.height,
g.height - n.height,
o
);
d = {
x: m,
y: r,
width: v,
height: f
}, ee(d), b("__activeStagePosition", d);
}
function U(e) {
if (!e)
return;
let o = e.getBoundingClientRect();
(o.width === 0 || o.height === 0) && (o = J(e).getBoundingClientRect());
const t = {
x: o.x,
y: o.y,
width: o.width,
height: o.height
};
b("__activeStagePosition", t), ee(t);
}
function ue() {
const e = c("__activeStagePosition"), o = c("__overlaySvg");
if (!e)
return;
if (!o) {
console.warn("No stage svg found.");
return;
}
const t = window.innerWidth, i = window.innerHeight;
o.setAttribute("viewBox", `0 0 ${t} ${i}`);
}
function ve(e) {
const o = fe(e);
document.body.appendChild(o), ie(o, (t) => {
t.target.tagName === "path" && _("overlayClick");
}), b("__overlaySvg", o);
}
function ee(e) {
const o = c("__overlaySvg");
if (!o) {
ve(e);
return;
}
const t = o.firstElementChild;
if ((t == null ? void 0 : t.tagName) !== "path")
throw new Error("no path element found in stage svg");
t.setAttribute("d", te(e));
}
function fe(e) {
const o = window.innerWidth, t = window.innerHeight, i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
i.classList.add("driver-overlay", "driver-overlay-animated"), i.setAttribute("viewBox", `0 0 ${o} ${t}`), i.setAttribute("xmlSpace", "preserve"), i.setAttribute("xmlnsXlink", "http://www.w3.org/1999/xlink"), i.setAttribute("version", "1.1"), i.setAttribute("preserveAspectRatio", "xMinYMin slice"), i.style.fillRule = "evenodd", i.style.clipRule = "evenodd", i.style.strokeLinejoin = "round", i.style.strokeMiterlimit = "2", i.style.zIndex = "10000", i.style.position = "fixed", i.style.top = "0", i.style.left = "0", i.style.width = "100%", i.style.height = "100%";
const d = document.createElementNS(
"http://www.w3.org/2000/svg",
"path"
);
return d.setAttribute("d", te(e)), d.style.fill = s("overlayColor") || "rgb(0,0,0)", d.style.opacity = `${s("overlayOpacity")}`, d.style.pointerEvents = "auto", d.style.cursor = "auto", i.appendChild(d), i;
}
function te(e) {
const o = window.innerWidth, t = window.innerHeight, i = s("stagePadding") || 0, d = s("stageRadius") || 0, n = e.width + i * 2, g = e.height + i * 2, m = Math.min(d, n / 2, g / 2), r = Math.floor(Math.max(m, 0)), v = e.x - i + r, f = e.y - i, a = n - r * 2, l = g - r * 2;
return `M${o},0L0,0L0,${t}L${o},${t}L${o},0Z
M${v},${f} h${a} a${r},${r} 0 0 1 ${r},${r} v${l} a${r},${r} 0 0 1 -${r},${r} h-${a} a${r},${r} 0 0 1 -${r},-${r} v-${l} a${r},${r} 0 0 1 ${r},-${r} z`;
}
function he() {
const e = c("__overlaySvg");
e && e.remove();
}
function ge() {
const e = document.getElementById("driver-dummy-element");
if (e)
return e;
const o = document.createElement("div");
return o.id = "driver-dummy-element", o.style.width = "0", o.style.height = "0", o.style.pointerEvents = "none", o.style.opacity = "0", o.style.position = "fixed", o.style.top = "50%", o.style.left = "50%", document.body.appendChild(o), o;
}
function X(e) {
const { element: o } = e;
let t = typeof o == "string" ? document.querySelector(o) : o;
t || (t = ge()), me(t, e);
}
function we() {
const e = c("__activeElement"), o = c("__activeStep");
e && (U(e), ue(), re(e, o));
}
function me(e, o) {
const i = Date.now(), d = c("__activeStep"), n = c("__activeElement") || e, g = !n || n === e, m = e.id === "driver-dummy-element", r = n.id === "driver-dummy-element", v = s("animate"), f = o.onHighlightStarted || s("onHighlightStarted"), a = (o == null ? void 0 : o.onHighlighted) || s("onHighlighted"), l = (d == null ? void 0 : d.onDeselected) || s("onDeselected"), p = s(), w = c();
!g && l && l(r ? void 0 : n, d, {
config: p,
state: w
}), f && f(m ? void 0 : e, o, {
config: p,
state: w
});
const u = !g && v;
let h = !1;
ke(), b("previousStep", d), b("previousElement", n), b("activeStep", o), b("activeElement", e);
const C = () => {
if (c("__transitionCallback") !== C)
return;
const P = Date.now() - i, x = 400 - P <= 400 / 2;
o.popover && x && !h && u && (Y(e, o), h = !0), s("animate") && P < 400 ? pe(P, 400, n, e) : (U(e), a && a(m ? void 0 : e, o, {
config: s(),
state: c()
}), b("__transitionCallback", void 0), b("__previousStep", d), b("__previousElement", n), b("__activeStep", o), b("__activeElement", e)), window.requestAnimationFrame(C);
};
b("__transitionCallback", C), window.requestAnimationFrame(C), G(e), !u && o.popover && Y(e, o), n.classList.remove(
"driver-active-element",
"driver-no-interaction"
), n.removeAttribute("aria-haspopup"), n.removeAttribute("aria-expanded"), n.removeAttribute("aria-controls"), s("disableActiveInteraction") && e.classList.add("driver-no-interaction"), e.classList.add("driver-active-element"), e.setAttribute("aria-haspopup", "dialog"), e.setAttribute("aria-expanded", "true"), e.setAttribute("aria-controls", "driver-popover-content");
}
function ye() {
var e;
(e = document.getElementById("driver-dummy-element")) == null || e.remove(), document.querySelectorAll(".driver-active-element").forEach((o) => {
o.classList.remove("driver-active-element", "driver-no-interaction"), o.removeAttribute("aria-haspopup"), o.removeAttribute("aria-expanded"), o.removeAttribute("aria-controls");
});
}
function M() {
const e = c("__resizeTimeout");
e && window.cancelAnimationFrame(e), b("__resizeTimeout", window.requestAnimationFrame(we));
}
function be(e) {
var r;
if (!c("isInitialized") || !(e.key === "Tab" || e.keyCode === 9))
return;
const i = c("__activeElement"), d = (r = c("popover")) == null ? void 0 : r.wrapper, n = Z([
...d ? [d] : [],
...i ? [i] : []
]), g = n[0], m = n[n.length - 1];
if (e.preventDefault(), e.shiftKey) {
const v = n[n.indexOf(document.activeElement) - 1] || m;
v == null || v.focus();
} else {
const v = n[n.indexOf(document.activeElement) + 1] || g;
v == null || v.focus();
}
}
function oe(e) {
var t;
((t = s("allowKeyboardControl")) == null || t) && (e.key === "Escape" ? _("escapePress") : e.key === "ArrowRight" ? _("arrowRightPress") : e.key === "ArrowLeft" && _("arrowLeftPress"));
}
function ie(e, o, t) {
const i = (n, g) => {
const m = n.target;
e.contains(m) && ((!t || t(m)) && (n.preventDefault(), n.stopPropagation(), n.stopImmediatePropagation()), g == null || g(n));
};
document.addEventListener("pointerdown", i, !0), document.addEventListener("mousedown", i, !0), document.addEventListener("pointerup", i, !0), document.addEventListener("mouseup", i, !0), document.addEventListener(
"click",
(n) => {
i(n, o);
},
!0
);
}
function xe() {
window.addEventListener("keyup", oe, !1), window.addEventListener("keydown", be, !1), window.addEventListener("resize", M), window.addEventListener("scroll", M);
}
function Ce() {
window.removeEventListener("keyup", oe), window.removeEventListener("resize", M), window.removeEventListener("scroll", M);
}
function ke() {
const e = c("popover");
e && (e.wrapper.style.display = "none");
}
function Y(e, o) {
var y, x;
let t = c("popover");
t && document.body.removeChild(t.wrapper), t = Se(), document.body.appendChild(t.wrapper);
const {
title: i,
description: d,
showButtons: n,
disableButtons: g,
showProgress: m,
nextBtnText: r = s("nextBtnText") || "Next →",
prevBtnText: v = s("prevBtnText") || "← Previous",
progressText: f = s("progressText") || "{current} of {total}"
} = o.popover || {};
t.nextButton.innerHTML = r, t.previousButton.innerHTML = v, t.progress.innerHTML = f, i ? (t.title.innerHTML = i, t.title.style.display = "block") : t.title.style.display = "none", d ? (t.description.innerHTML = d, t.description.style.display = "block") : t.description.style.display = "none";
const a = n || s("showButtons"), l = m || s("showProgress") || !1, p = (a == null ? void 0 : a.includes("next")) || (a == null ? void 0 : a.includes("previous")) || l;
t.closeButton.style.display = a.includes("close") ? "block" : "none", p ? (t.footer.style.display = "flex", t.progress.style.display = l ? "block" : "none", t.nextButton.style.display = a.includes("next") ? "block" : "none", t.previousButton.style.display = a.includes(
"previous"
) ? "block" : "none") : t.footer.style.display = "none";
const w = g || s("disableButtons") || [];
w != null && w.includes("next") && (t.nextButton.disabled = !0, t.nextButton.classList.add("driver-popover-btn-disabled")), w != null && w.includes("previous") && (t.previousButton.disabled = !0, t.previousButton.classList.add("driver-popover-btn-disabled")), w != null && w.includes("close") && (t.closeButton.disabled = !0, t.closeButton.classList.add("driver-popover-btn-disabled"));
const u = t.wrapper;
u.style.display = "block", u.style.left = "", u.style.top = "", u.style.bottom = "", u.style.right = "", u.id = "driver-popover-content", u.setAttribute("role", "dialog"), u.setAttribute("aria-labelledby", "driver-popover-title"), u.setAttribute("aria-describedby", "driver-popover-description");
const h = t.arrow;
h.className = "driver-popover-arrow";
const C = ((y = o.popover) == null ? void 0 : y.popoverClass) || s("popoverClass") || "";
u.className = `driver-popover ${C}`.trim(), ie(
t.wrapper,
(S) => {
var B, H, R;
const E = S.target, T = ((B = o.popover) == null ? void 0 : B.onNextClick) || s("onNextClick"), A = ((H = o.popover) == null ? void 0 : H.onPrevClick) || s("onPrevClick"), $ = ((R = o.popover) == null ? void 0 : R.onCloseClick) || s("onCloseClick");
if (E.classList.contains("driver-popover-next-btn"))
return T ? T(e, o, {
config: s(),
state: c()
}) : _("nextClick");
if (E.classList.contains("driver-popover-prev-btn"))
return A ? A(e, o, {
config: s(),
state: c()
}) : _("prevClick");
if (E.classList.contains("driver-popover-close-btn"))
return $ ? $(e, o, {
config: s(),
state: c()
}) : _("closeClick");
},
(S) => !(t != null && t.description.contains(S)) && !(t != null && t.title.contains(S)) && typeof S.className == "string" && S.className.includes("driver-popover")
), b("popover", t);
const k = ((x = o.popover) == null ? void 0 : x.onPopoverRender) || s("onPopoverRender");
k && k(t, {
config: s(),
state: c()
}), re(e, o), G(u);
const L = e.classList.contains("driver-dummy-element"), P = Z([
u,
...L ? [] : [e]
]);
P.length > 0 && P[0].focus();
}
function ne() {
const e = c("popover");
if (!(e != null && e.wrapper))
return;
const o = e.wrapper.getBoundingClientRect(), t = s("stagePadding") || 0, i = s("popoverOffset") || 0;
return {
width: o.width + t + i,
height: o.height + t + i,
realWidth: o.width,
realHeight: o.height
};
}
function j(e, o) {
const {
elementDimensions: t,
popoverDimensions: i,
popoverPadding: d,
popoverArrowDimensions: n
} = o;
return e === "start" ? Math.max(
Math.min(
t.top - d,
window.innerHeight - i.realHeight - n.width
),
n.width
) : e === "end" ? Math.max(
Math.min(
t.top - (i == null ? void 0 : i.realHeight) + t.height + d,
window.innerHeight - (i == null ? void 0 : i.realHeight) - n.width
),
n.width
) : e === "center" ? Math.max(
Math.min(
t.top + t.height / 2 - (i == null ? void 0 : i.realHeight) / 2,
window.innerHeight - (i == null ? void 0 : i.realHeight) - n.width
),
n.width
) : 0;
}
function Q(e, o) {
const {
elementDimensions: t,
popoverDimensions: i,
popoverPadding: d,
popoverArrowDimensions: n
} = o;
return e === "start" ? Math.max(
Math.min(
t.left - d,
window.innerWidth - i.realWidth - n.width
),
n.width
) : e === "end" ? Math.max(
Math.min(
t.left - (i == null ? void 0 : i.realWidth) + t.width + d,
window.innerWidth - (i == null ? void 0 : i.realWidth) - n.width
),
n.width
) : e === "center" ? Math.max(
Math.min(
t.left + t.width / 2 - (i == null ? void 0 : i.realWidth) / 2,
window.innerWidth - (i == null ? void 0 : i.realWidth) - n.width
),
n.width
) : 0;
}
function re(e, o) {
const t = c("popover");
if (!t)
return;
const { align: i = "start", side: d = "left" } = (o == null ? void 0 : o.popover) || {}, n = i, g = e.id === "driver-dummy-element" ? "over" : d, m = s("stagePadding") || 0, r = ne(), v = t.arrow.getBoundingClientRect();
let f = e.getBoundingClientRect();
(f.width === 0 || f.height === 0) && (f = J(e).getBoundingClientRect());
const a = f.top - r.height;
let l = a >= 0;
const p = window.innerHeight - (f.bottom + r.height);
let w = p >= 0;
const u = f.left - r.width;
let h = u >= 0;
const C = window.innerWidth - (f.right + r.width);
let k = C >= 0;
const L = !l && !w && !h && !k;
let P = g;
if (g === "top" && l ? k = h = w = !1 : g === "bottom" && w ? k = h = l = !1 : g === "left" && h ? k = l = w = !1 : g === "right" && k && (h = l = w = !1), g === "over") {
const y = window.innerWidth / 2 - r.realWidth / 2, x = window.innerHeight / 2 - r.realHeight / 2;
t.wrapper.style.left = `${y}px`, t.wrapper.style.right = "auto", t.wrapper.style.top = `${x}px`, t.wrapper.style.bottom = "auto";
} else if (L) {
const y = window.innerWidth / 2 - (r == null ? void 0 : r.realWidth) / 2, x = 10;
t.wrapper.style.left = `${y}px`, t.wrapper.style.right = "auto", t.wrapper.style.bottom = `${x}px`, t.wrapper.style.top = "auto";
} else if (h) {
const y = Math.min(
u,
window.innerWidth - (r == null ? void 0 : r.realWidth) - v.width
), x = j(n, {
elementDimensions: f,
popoverDimensions: r,
popoverPadding: m,
popoverArrowDimensions: v
});
t.wrapper.style.left = `${y}px`, t.wrapper.style.top = `${x}px`, t.wrapper.style.bottom = "auto", t.wrapper.style.right = "auto", P = "left";
} else if (k) {
const y = Math.min(
C,
window.innerWidth - (r == null ? void 0 : r.realWidth) - v.width
), x = j(n, {
elementDimensions: f,
popoverDimensions: r,
popoverPadding: m,
popoverArrowDimensions: v
});
t.wrapper.style.right = `${y}px`, t.wrapper.style.top = `${x}px`, t.wrapper.style.bottom = "auto", t.wrapper.style.left = "auto", P = "right";
} else if (l) {
const y = Math.min(
a,
window.innerHeight - r.realHeight - v.width
);
let x = Q(n, {
elementDimensions: f,
popoverDimensions: r,
popoverPadding: m,
popoverArrowDimensions: v
});
t.wrapper.style.top = `${y}px`, t.wrapper.style.left = `${x}px`, t.wrapper.style.bottom = "auto", t.wrapper.style.right = "auto", P = "top";
} else if (w) {
const y = Math.min(
p,
window.innerHeight - (r == null ? void 0 : r.realHeight) - v.width
);
let x = Q(n, {
elementDimensions: f,
popoverDimensions: r,
popoverPadding: m,
popoverArrowDimensions: v
});
t.wrapper.style.left = `${x}px`, t.wrapper.style.bottom = `${y}px`, t.wrapper.style.top = "auto", t.wrapper.style.right = "auto", P = "bottom";
}
L ? t.arrow.classList.add("driver-popover-arrow-none") : Pe(n, P, e);
}
function Pe(e, o, t) {
const i = c("popover");
if (!i)
return;
const d = t.getBoundingClientRect(), n = ne(), g = i.arrow, m = n.width, r = window.innerWidth, v = d.width, f = d.left, a = n.height, l = window.innerHeight, p = d.top, w = d.height;
g.className = "driver-popover-arrow";
let u = o, h = e;
o === "top" ? (f + v <= 0 ? (u = "right", h = "end") : f + v - m <= 0 && (u = "top", h = "start"), f >= r ? (u = "left", h = "end") : f + m >= r && (u = "top", h = "end")) : o === "bottom" ? (f + v <= 0 ? (u = "right", h = "start") : f + v - m <= 0 && (u = "bottom", h = "start"), f >= r ? (u = "left", h = "start") : f + m >= r && (u = "bottom", h = "end")) : o === "left" ? (p + w <= 0 ? (u = "bottom", h = "end") : p + w - a <= 0 && (u = "left", h = "start"), p >= l ? (u = "top", h = "end") : p + a >= l && (u = "left", h = "end")) : o === "right" && (p + w <= 0 ? (u = "bottom", h = "start") : p + w - a <= 0 && (u = "right", h = "start"), p >= l ? (u = "top", h = "start") : p + a >= l && (u = "right", h = "end")), u ? (g.classList.add(`driver-popover-arrow-side-${u}`), g.classList.add(`driver-popover-arrow-align-${h}`)) : g.classList.add("driver-popover-arrow-none");
}
function Se() {
const e = document.createElement("div");
e.classList.add("driver-popover");
const o = document.createElement("div");
o.classList.add("driver-popover-arrow");
const t = document.createElement("header");
t.id = "driver-popover-title", t.classList.add("driver-popover-title"), t.style.display = "none", t.innerText = "Popover Title";
const i = document.createElement("div");
i.id = "driver-popover-description", i.classList.add("driver-popover-description"), i.style.display = "none", i.innerText = "Popover description is here";
const d = document.createElement("button");
d.type = "button", d.classList.add("driver-popover-close-btn"), d.setAttribute("aria-label", "Close"), d.innerHTML = "×";
const n = document.createElement("footer");
n.classList.add("driver-popover-footer");
const g = document.createElement("span");
g.classList.add("driver-popover-progress-text"), g.innerText = "";
const m = document.createElement("span");
m.classList.add("driver-popover-navigation-btns");
const r = document.createElement("button");
r.type = "button", r.classList.add("driver-popover-prev-btn"), r.innerHTML = "← Previous";
const v = document.createElement("button");
return v.type = "button", v.classList.add("driver-popover-next-btn"), v.innerHTML = "Next →", m.appendChild(r), m.appendChild(v), n.appendChild(g), n.appendChild(m), e.appendChild(d), e.appendChild(o), e.appendChild(t), e.appendChild(i), e.appendChild(n), {
wrapper: e,
arrow: o,
title: t,
description: i,
footer: n,
previousButton: r,
nextButton: v,
closeButton: d,
footerButtons: m,
progress: g
};
}
function _e() {
var o;
const e = c("popover");
e && ((o = e.wrapper.parentElement) == null || o.removeChild(e.wrapper));
}
function Le(e = {}) {
D(e);
function o() {
s("allowClose") && f();
}
function t() {
const a = s("overlayClickBehavior");
if (s("allowClose") && a === "close") {
f();
return;
}
a === "nextStep" && i();
}
function i() {
const a = c("activeIndex"), l = s("steps") || [];
if (typeof a == "undefined")
return;
const p = a + 1;
l[p] ? v(p) : f();
}
function d() {
const a = c("activeIndex"), l = s("steps") || [];
if (typeof a == "undefined")
return;
const p = a - 1;
l[p] ? v(p) : f();
}
function n(a) {
(s("steps") || [])[a] ? v(a) : f();
}
function g() {
var C;
if (c("__transitionCallback"))
return;
const l = c("activeIndex"), p = c("__activeStep"), w = c("__activeElement");
if (typeof l == "undefined" || typeof p == "undefined" || typeof c("activeIndex") == "undefined")
return;
const h = ((C = p.popover) == null ? void 0 : C.onPrevClick) || s("onPrevClick");
if (h)
return h(w, p, {
config: s(),
state: c()
});
d();
}
function m() {
var h;
if (c("__transitionCallback"))
return;
const l = c("activeIndex"), p = c("__activeStep"), w = c("__activeElement");
if (typeof l == "undefined" || typeof p == "undefined")
return;
const u = ((h = p.popover) == null ? void 0 : h.onNextClick) || s("onNextClick");
if (u)
return u(w, p, {
config: s(),
state: c()
});
i();
}
function r() {
c("isInitialized") || (b("isInitialized", !0), document.body.classList.add("driver-active", s("animate") ? "driver-fade" : "driver-simple"), xe(), W("overlayClick", t), W("escapePress", o), W("arrowLeftPress", g), W("arrowRightPress", m));
}
function v(a = 0) {
var A, $, B, H, R, z, q, V;
const l = s("steps");
if (!l) {
console.error("No steps to drive through"), f();
return;
}
if (!l[a]) {
f();
return;
}
b("__activeOnDestroyed", document.activeElement), b("activeIndex", a);
const p = l[a], w = l[a + 1], u = l[a - 1], h = ((A = p.popover) == null ? void 0 : A.doneBtnText) || s("doneBtnText") || "Done", C = s("allowClose"), k = typeof (($ = p.popover) == null ? void 0 : $.showProgress) != "undefined" ? (B = p.popover) == null ? void 0 : B.showProgress : s("showProgress"), P = (((H = p.popover) == null ? void 0 : H.progressText) || s("progressText") || "{{current}} of {{total}}").replace("{{current}}", `${a + 1}`).replace("{{total}}", `${l.length}`), y = ((R = p.popover) == null ? void 0 : R.showButtons) || s("showButtons"), x = [
"next",
"previous",
...C ? ["close"] : []
].filter((se) => !(y != null && y.length) || y.includes(se)), S = ((z = p.popover) == null ? void 0 : z.onNextClick) || s("onNextClick"), E = ((q = p.popover) == null ? void 0 : q.onPrevClick) || s("onPrevClick"), T = ((V = p.popover) == null ? void 0 : V.onCloseClick) || s("onCloseClick");
X({
...p,
popover: {
showButtons: x,
nextBtnText: w ? void 0 : h,
disableButtons: [...u ? [] : ["previous"]],
showProgress: k,
progressText: P,
onNextClick: S || (() => {
w ? v(a + 1) : f();
}),
onPrevClick: E || (() => {
v(a - 1);
}),
onCloseClick: T || (() => {
f();
}),
...(p == null ? void 0 : p.popover) || {}
}
});
}
function f(a = !0) {
const l = c("__activeElement"), p = c("__activeStep"), w = c("__activeOnDestroyed"), u = s("onDestroyStarted");
if (a && u) {
const k = !l || (l == null ? void 0 : l.id) === "driver-dummy-element";
u(k ? void 0 : l, p, {
config: s(),
state: c()
});
return;
}
const h = (p == null ? void 0 : p.onDeselected) || s("onDeselected"), C = s("onDestroyed");
if (document.body.classList.remove("driver-active", "driver-fade", "driver-simple"), Ce(), _e(), ye(), he(), ae(), K(), l && p) {
const k = l.id === "driver-dummy-element";
h && h(k ? void 0 : l, p, {
config: s(),
state: c()
}), C && C(k ? void 0 : l, p, {
config: s(),
state: c()
});
}
w && w.focus();
}
return {
isActive: () => c("isInitialized") || !1,
refresh: M,
drive: (a = 0) => {
r(), v(a);
},
setConfig: D,
setSteps: (a) => {
K(), D({
...s(),
steps: a
});
},
getConfig: s,
getState: c,
getActiveIndex: () => c("activeIndex"),
isFirstStep: () => c("activeIndex") === 0,
isLastStep: () => {
const a = s("steps") || [], l = c("activeIndex");
return l !== void 0 && l === a.length - 1;
},
getActiveStep: () => c("activeStep"),
getActiveElement: () => c("activeElement"),
getPreviousElement: () => c("previousElement"),
getPreviousStep: () => c("previousStep"),
moveNext: i,
movePrevious: d,
moveTo: n,
hasNextStep: () => {
const a = s("steps") || [], l = c("activeIndex");
return l !== void 0 && a[l + 1];
},
hasPreviousStep: () => {
const a = s("steps") || [], l = c("activeIndex");
return l !== void 0 && a[l - 1];
},
highlight: (a) => {
r(), X({
...a,
popover: a.popover ? {
showButtons: [],
showProgress: !1,
progressText: "",
...a.popover
} : void 0
});
},
destroy: () => {
f(!1);
}
};
}
export {
Le as driver
};