@topvisor/ui
Version:
Topvisor UI-kit Vue
198 lines (197 loc) • 7.87 kB
JavaScript
import { defineAsyncComponent as D } from "vue";
import { C as r, E as L, h as P, c as V, j as I, k as M, f as C, _ as R, l as H, m as x, T as N, n as F, o as B, p as W, q as Y } from "./forms-EIQ_3SBd.es.js";
import { TopPopupWorker as l } from "../popup/worker.js";
import { T as j, _ as q } from "./dialogs.vue_vue_type_script_setup_true_lang-B9iya2uP.es.js";
import { isVisible as O } from "../utils/dom.js";
class z {
static isInited = !1;
/**
* Добавить глобальные обработчики
*
* Добавляются на страницу один раз и навсегда
*/
static init() {
this.isInited || (this.isInited = !0, document.addEventListener("mouseover", (e) => {
var o;
!(e.target instanceof HTMLElement) || !((o = e.target.dataset) != null && o.topPopupOpenByHover) || e.target.click();
}), document.addEventListener("scroll", () => {
r.state.isMobile || r.state.isMobileUA || l.getAll().forEach((e) => l.close(e));
}), L.addOnReize((e) => {
r.state.isMobile && e.topEvent.widthDiff && l.getAll().forEach((o) => l.close(o));
}), document.addEventListener("click", this.onclick, { capture: !0 }));
}
/**
* Глобальный обработчик кликов
*
* Обрабатывает клики на открытие Popup
*/
static async onclick(e) {
var n, i, s, a, y;
if (!(e.target instanceof HTMLElement) || e.target.dataset.topPopupDisabled)
return;
let o;
switch (!0) {
case !!((n = e.target.dataset) != null && n.topPopup):
o = e.target;
break;
case !!((i = e.target.parentElement) != null && i.dataset.topPopup):
o = e.target.parentElement;
break;
case !!((a = (s = e.target.parentElement) == null ? void 0 : s.parentElement) != null && a.dataset.topPopup):
o = (y = e.target.parentElement) == null ? void 0 : y.parentElement;
break;
}
o && (o.dataset.topPopupDisabled || o.dataset.topPopupOpened || (e.preventDefault(), await l.openByOpener(o)));
}
}
let _;
const G = {
mounted: async (t, e) => {
_ || (_ = (await import("../utils/dom.js")).storage);
const o = e.arg, n = e.value;
_(t, o, n);
}
};
let g, u = [], w;
const Q = async () => {
const { isVisible: t } = await import("../utils/dom.js");
if (u = u.filter(t), !u.length) return;
u[0].focus(), u = [];
}, U = async (t) => {
g || (g = await import("../utils/lodash.js")), w || (w = g.debounce(Q, 30)), u.push(t), w();
}, J = {
mounted: function(t, e) {
t.__TOP_V_FOCUS_VALUE = e.value ?? !0, (e.value ?? !0) && U(t);
},
updated: function(t, e) {
e.modifiers.onupdate && t.__TOP_V_FOCUS_VALUE !== (e.value ?? !0) && (t.__TOP_V_FOCUS_VALUE = e.value ?? !0, (e.value ?? !0) && U(t));
}
};
let d, h;
const A = (t) => (typeof t == "boolean" || (t ? t = { ...t } : t = {}, t.behavior ??= "smooth", t.block ??= "nearest", t.inline ??= "nearest"), t);
let f, b;
const K = async () => {
if (!f) return;
const t = await E(f);
t.isVisible && f.scrollIntoView(t.scrollIntoViewOptions);
}, $ = async (t) => {
h || (h = await import("../utils/lodash.js")), b || (b = h.debounce(K, 30)), f = t, b();
}, E = async (t, e) => {
d || (d = await import("../utils/dom.js"));
let o = d.storage(t, "v-top-scrollIntoView");
return o || (o = {
isVisible: O(t),
scrollIntoViewOptions: A(e)
}, d.storage(t, "v-top-scrollIntoView", o)), o;
}, X = {
async mounted(t, e) {
await E(t, e.value), e.modifiers.immediate && $(t);
},
async updated(t, e) {
const o = await E(t, e.value);
o.scrollIntoViewOptions = A(e.value);
const n = O(t);
n && o.isVisible !== n && $(t), o.isVisible = n;
}
};
let c;
const Z = {
async mounted(t) {
c || (c = await import("../utils/scroll.js")), c.connectScrollShadow(t);
},
async unmounted(t) {
c || (c = await import("../utils/scroll.js")), c.unconnectScrollShadow(t);
}
};
let p;
const tt = {
mounted(t, e, o) {
const n = e.value || "top-sticky";
p = new IntersectionObserver((i) => {
let s = i[0].intersectionRatio < 1;
s && e.modifiers.bottom && i[0].intersectionRect.y === 0 && (s = !1), t.classList.toggle(n, s);
}, {
threshold: [1]
}), p.observe(t);
},
unmounted(t, e, o) {
p == null || p.disconnect();
}
};
let S = !1, m;
const v = /* @__PURE__ */ new Map(), et = (t, e) => {
const { distance: o, percent: n } = t.directiveSwipUpOptions, i = t.getBoundingClientRect().top, s = e * n / 100 / o, a = (e - i) / s;
a <= o ? t.style.transform = `translateY(${o - a}px)` : t.style.transform = "translateY(0px)";
}, ot = (t) => {
let e = window.innerHeight;
window.addEventListener("scroll", () => {
v.forEach((o) => et(o, e));
}, { passive: !0 }), m = new IntersectionObserver((o) => {
e = window.innerHeight, o.forEach((n) => {
const i = n.target;
if (n.intersectionRatio < 0.1 ? v.delete(i) : v.set(i, i), n.intersectionRatio === 0) {
const { distance: s } = i.directiveSwipUpOptions;
i.style.transform = `translateY(${s}px)`;
}
});
}, {
threshold: 0.1
});
}, nt = {
mounted(t, e, o) {
var n, i;
r.state.isMobileUA || (t.directiveSwipUpOptions = {
distance: ((n = e.value) == null ? void 0 : n.distance) ?? 100,
// количество px на которые блок изначально смещен вниз,
percent: ((i = e.value) == null ? void 0 : i.percent) ?? 30
// процент высоты экрана поднявшись на который блок закончит подплытие
}, S || (ot(), S = !0), m.observe(t));
},
unmounted(t, e, o) {
v.delete(t), m == null || m.unobserve(t);
}
}, T = (t) => {
var e, o;
if (!((o = (e = r.$) == null ? void 0 : e.ui) != null && o.tooltip)) {
console.info("Для работы v-top-tooltip требуется глобальная загрузка jQuery UI Tooltip");
return;
}
return r.$(t);
}, k = (t, e) => {
var n;
const o = t.value ?? {};
return o.content ??= (n = e.props) == null ? void 0 : n.title, o.content = String(o.content).replace(/([^<>])\r?\n([^<>])/g, "$1<br>$2"), o.position ??= {
my: "bottom-18px",
at: "top center"
}, o;
}, it = {
mounted(t, e, o) {
var n;
(n = T(t)) == null || n.tooltip(k(e, o));
},
updated(t, e, o, n) {
var a;
const i = k(e, o), s = (a = T(t)) == null ? void 0 : a.tooltip("instance");
s && (s.options = {
...s.options,
...i
});
},
unmounted(t, e, o) {
var n;
(n = T(t)) == null || n.tooltip("destroy");
}
}, st = D(() => import("./notice-Ci-iQODq.es.js"));
window.vd = console.log;
const pt = {
install: (t, e) => {
t.config.globalProperties.$core = r, t.config.globalProperties.$vd = console.log;
for (const o in e)
r.state[o] = e[o];
e.widthForMobile && (r.widthForMobile = e.widthForMobile), e.themeName && (r.themeName = e.themeName), r._setState(), e.topPopupOptions && (l.options = e.topPopupOptions), z.init(), j.init(e.topDialogOptions), t.directive("top-data", G), t.directive("top-focus", J), t.directive("top-scroll-into-view", X), t.directive("top-scroll-shadow", Z), t.directive("top-sticky", tt), t.directive("top-swim-up", nt), t.directive("top-tooltip", it), t.component("TopAvatar", P), t.component("TopButton", V), t.component("TopCheckbox", I), t.component("TopControlLabel", M), t.component("TopHint", C), t.component("TopInput", R), t.component("TopInputDate", H), t.component("TopInputRange", x), t.component("TopLoadbar", N), t.component("TopRadio", F), t.component("TopSelect", B), t.component("TopSwitcher", W), t.component("TopTextarea", Y), t.component("TopNotice", st), t.component("TopDialogs", q);
}
};
export {
pt as c
};
//# sourceMappingURL=core-BB__WDxl.es.js.map