@apo100l/ace-ui-kit 0.6.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,377 +1,459 @@
1
+ let v = null;
2
+ function Z() {
3
+ return v?.isConnected || (v = document.createElement("section"), v.className = "ak-toaster", v.setAttribute("aria-label", "Уведомления"), document.body.append(v)), v;
4
+ }
5
+ function M(t, { tone: e = "neutral", duration: n, action: o } = {}) {
6
+ const a = Z(), i = document.createElement("div");
7
+ i.className = `ak-toast ak-toast--${e}`, i.setAttribute("role", e === "negative" ? "alert" : "status"), i.setAttribute("aria-live", e === "negative" ? "assertive" : "polite");
8
+ const r = document.createElement("p");
9
+ if (r.className = "ak-toast__text", r.textContent = t, i.append(r), o) {
10
+ const l = document.createElement("button");
11
+ l.type = "button", l.className = "ak-toast__action", l.textContent = o.label, l.addEventListener("click", () => {
12
+ o.onClick(), m();
13
+ }), i.append(l);
14
+ }
15
+ const c = document.createElement("button");
16
+ c.type = "button", c.className = "ak-toast__close", c.setAttribute("aria-label", "Закрыть"), c.textContent = "×", c.addEventListener("click", () => m()), i.append(c), a.append(i);
17
+ const d = a.querySelectorAll(".ak-toast:not([data-leaving])");
18
+ d.length > 4 && d[0]._close?.(), requestAnimationFrame(() => requestAnimationFrame(() => i.setAttribute("data-shown", "")));
19
+ const u = n ?? (e === "negative" ? 0 : 5e3);
20
+ let b = u, h = 0, g = 0;
21
+ const A = () => {
22
+ g && (clearTimeout(g), g = 0, b -= Date.now() - h);
23
+ }, s = () => {
24
+ !u || g || b <= 0 || document.hidden || (h = Date.now(), g = window.setTimeout(m, b));
25
+ }, f = () => document.hidden ? A() : s();
26
+ i.addEventListener("mouseenter", A), i.addEventListener("mouseleave", s), i.addEventListener("focusin", A), i.addEventListener("focusout", s), document.addEventListener("visibilitychange", f), s();
27
+ function m() {
28
+ if (i.hasAttribute("data-leaving")) return;
29
+ A(), document.removeEventListener("visibilitychange", f), i.setAttribute("data-leaving", ""), i.removeAttribute("data-shown");
30
+ const l = () => i.remove();
31
+ i.addEventListener("transitionend", l, { once: !0 }), window.setTimeout(l, 400);
32
+ }
33
+ return i._close = m, { close: m };
34
+ }
35
+ function ee(t = document) {
36
+ t.querySelectorAll("[data-ak-toast]:not([data-ak-bound])").forEach((e) => {
37
+ e.setAttribute("data-ak-bound", "");
38
+ const n = (e instanceof HTMLTemplateElement ? e.content.textContent : e.textContent)?.trim();
39
+ if (!n) return;
40
+ const o = e.dataset.akToast || "neutral", a = e.dataset.akDuration ? Number(e.dataset.akDuration) : void 0;
41
+ M(n, { tone: o, duration: a }), e instanceof HTMLTemplateElement || (e.hidden = !0);
42
+ });
43
+ }
44
+ let _ = !1;
45
+ function te(t) {
46
+ const e = document.createElement("textarea");
47
+ e.value = t, e.setAttribute("readonly", ""), e.style.cssText = "position:fixed;top:0;left:0;opacity:0;pointer-events:none;", document.body.append(e), e.select();
48
+ let n = !1;
49
+ try {
50
+ n = document.execCommand("copy");
51
+ } catch {
52
+ n = !1;
53
+ }
54
+ return e.remove(), n;
55
+ }
56
+ async function ne(t) {
57
+ try {
58
+ return await navigator.clipboard.writeText(t), !0;
59
+ } catch {
60
+ return te(t);
61
+ }
62
+ }
63
+ function oe(t) {
64
+ const e = t.dataset.akCopyFrom;
65
+ if (e === void 0) return { text: t.dataset.akCopy, field: null };
66
+ const n = document.getElementById(e);
67
+ return n instanceof HTMLInputElement || n instanceof HTMLTextAreaElement ? { text: n.value, field: n } : { text: n?.textContent?.trim() ?? void 0, field: null };
68
+ }
69
+ function ae() {
70
+ _ || (_ = !0, document.addEventListener("click", async (t) => {
71
+ const e = t.target?.closest?.("[data-ak-copy], [data-ak-copy-from]");
72
+ if (!e) return;
73
+ const { text: n, field: o } = oe(e);
74
+ n !== void 0 && (t.preventDefault(), await ne(n) ? M(e.dataset.akCopyMessage || `Скопировано: ${n}`, { tone: "positive", duration: 2e3 }) : o ? (o.focus(), o.select()) : M("Не удалось скопировать — выделите текст вручную", { tone: "warning" }));
75
+ }));
76
+ }
1
77
  let D = !1;
2
- function Y(e) {
3
- e.open || (e.showModal(), document.documentElement.classList.add("ak-dialog-open"));
78
+ function ie(t) {
79
+ t.open || (t.showModal(), document.documentElement.classList.add("ak-dialog-open"));
4
80
  }
5
- function C(e, t) {
6
- e.open && e.close(t);
81
+ function N(t, e) {
82
+ t.open && t.close(e);
7
83
  }
8
- function G() {
9
- const e = document.querySelector("dialog.ak-dialog[open]");
10
- document.documentElement.classList.toggle("ak-dialog-open", !!e);
11
- }
12
- function J() {
13
- D || (D = !0, document.addEventListener("click", (e) => {
14
- const t = e.target instanceof Element ? e.target : null;
15
- if (!t) return;
16
- const n = t.closest("[data-ak-dialog-open]");
84
+ function re() {
85
+ const t = document.querySelector("dialog.ak-dialog[open]");
86
+ document.documentElement.classList.toggle("ak-dialog-open", !!t);
87
+ }
88
+ function se() {
89
+ D || (D = !0, document.addEventListener("click", (t) => {
90
+ const e = t.target instanceof Element ? t.target : null;
91
+ if (!e) return;
92
+ const n = e.closest("[data-ak-dialog-open]");
17
93
  if (n) {
18
94
  const a = document.getElementById(n.dataset.akDialogOpen ?? "");
19
- a instanceof HTMLDialogElement && (e.preventDefault(), Y(a));
95
+ a instanceof HTMLDialogElement && (t.preventDefault(), ie(a));
20
96
  return;
21
97
  }
22
- const o = t.closest("[data-ak-dialog-close]");
98
+ const o = e.closest("[data-ak-dialog-close]");
23
99
  if (o) {
24
100
  const a = o.closest("dialog");
25
- a && C(a, o.dataset.akDialogClose || void 0);
101
+ a && N(a, o.dataset.akDialogClose || void 0);
26
102
  return;
27
103
  }
28
- if (t instanceof HTMLDialogElement && t.open && t.classList.contains("ak-dialog") && !t.hasAttribute("data-ak-static")) {
29
- const a = t.getBoundingClientRect(), { clientX: i, clientY: s } = e;
30
- (i < a.left || i > a.right || s < a.top || s > a.bottom) && C(t, "cancel");
104
+ if (e instanceof HTMLDialogElement && e.open && e.classList.contains("ak-dialog") && !e.hasAttribute("data-ak-static")) {
105
+ const a = e.getBoundingClientRect(), { clientX: i, clientY: r } = t;
106
+ (i < a.left || i > a.right || r < a.top || r > a.bottom) && N(e, "cancel");
31
107
  }
32
- }), document.addEventListener("close", G, !0));
108
+ }), document.addEventListener("close", re, !0));
33
109
  }
34
- const q = "akBound";
35
- function Q(e = document) {
36
- e.querySelectorAll("[data-ak-dismiss]").forEach((t) => {
37
- t.dataset[q] || (t.dataset[q] = "1", t.addEventListener("click", () => {
38
- t.closest("[data-ak-dismissible], .ak-alert")?.remove();
110
+ const I = "akBound";
111
+ function ce(t = document) {
112
+ t.querySelectorAll("[data-ak-dismiss]").forEach((e) => {
113
+ e.dataset[I] || (e.dataset[I] = "1", e.addEventListener("click", () => {
114
+ e.closest("[data-ak-dismissible], .ak-alert")?.remove();
39
115
  }));
40
116
  });
41
117
  }
42
- let N = !1;
43
- const Z = (e) => e < 1024 ? `${e} Б` : e < 1048576 ? `${(e / 1024).toFixed(0)} КБ` : `${(e / 1048576).toFixed(1).replace(".", ",")} МБ`;
44
- function tt(e, t) {
45
- const n = e.querySelector(".ak-file__list");
118
+ let B = !1;
119
+ const le = (t) => t < 1024 ? `${t} Б` : t < 1048576 ? `${(t / 1024).toFixed(0)} КБ` : `${(t / 1048576).toFixed(1).replace(".", ",")} МБ`;
120
+ function de(t, e) {
121
+ const n = t.querySelector(".ak-file__list");
46
122
  if (!n) return;
47
- const o = Number(t.dataset.maxSize) || 1 / 0;
123
+ const o = Number(e.dataset.maxSize) || 1 / 0;
48
124
  n.replaceChildren(
49
- ...[...t.files ?? []].map((i) => {
50
- const s = document.createElement("span");
51
- s.className = "ak-file__item";
52
- const l = i.size > o;
53
- return s.toggleAttribute("data-invalid", l), s.textContent = `${i.name} · ${Z(i.size)}${l ? " — больше допустимого" : ""}`, s;
125
+ ...[...e.files ?? []].map((i) => {
126
+ const r = document.createElement("span");
127
+ r.className = "ak-file__item";
128
+ const c = i.size > o;
129
+ return r.toggleAttribute("data-invalid", c), r.textContent = `${i.name} · ${le(i.size)}${c ? " — больше допустимого" : ""}`, r;
54
130
  })
55
131
  );
56
- const a = [...t.files ?? []].some((i) => i.size > o);
57
- t.setCustomValidity(a ? "Файл больше допустимого размера" : ""), e.toggleAttribute("data-has-files", !!t.files?.length);
132
+ const a = [...e.files ?? []].some((i) => i.size > o);
133
+ e.setCustomValidity(a ? "Файл больше допустимого размера" : ""), t.toggleAttribute("data-has-files", !!e.files?.length);
58
134
  }
59
- function et() {
60
- if (N) return;
61
- N = !0, document.addEventListener("change", (t) => {
62
- const n = t.target;
135
+ function ue() {
136
+ if (B) return;
137
+ B = !0, document.addEventListener("change", (e) => {
138
+ const n = e.target;
63
139
  if (!(n instanceof HTMLInputElement) || n.type !== "file") return;
64
140
  const o = n.closest(".ak-file");
65
- o && tt(o, n);
141
+ o && de(o, n);
66
142
  });
67
- const e = (t) => t.target?.closest?.(".ak-file") ?? null;
68
- document.addEventListener("dragover", (t) => {
69
- const n = e(t);
70
- n && (t.preventDefault(), n.setAttribute("data-dragover", ""));
71
- }), document.addEventListener("dragleave", (t) => {
72
- const n = e(t);
73
- n && !n.contains(t.relatedTarget) && n.removeAttribute("data-dragover");
74
- }), document.addEventListener("drop", (t) => {
75
- const n = e(t);
143
+ const t = (e) => e.target?.closest?.(".ak-file") ?? null;
144
+ document.addEventListener("dragover", (e) => {
145
+ const n = t(e);
146
+ n && (e.preventDefault(), n.setAttribute("data-dragover", ""));
147
+ }), document.addEventListener("dragleave", (e) => {
148
+ const n = t(e);
149
+ n && !n.contains(e.relatedTarget) && n.removeAttribute("data-dragover");
150
+ }), document.addEventListener("drop", (e) => {
151
+ const n = t(e);
76
152
  if (!n) return;
77
- t.preventDefault(), n.removeAttribute("data-dragover");
78
- const o = n.querySelector('input[type="file"]'), a = t.dataTransfer?.files;
153
+ e.preventDefault(), n.removeAttribute("data-dragover");
154
+ const o = n.querySelector('input[type="file"]'), a = e.dataTransfer?.files;
79
155
  if (!o || !a?.length || o.disabled) return;
80
156
  const i = new DataTransfer();
81
- [...a].slice(0, o.multiple ? void 0 : 1).forEach((s) => i.items.add(s)), o.files = i.files, o.dispatchEvent(new Event("change", { bubbles: !0 }));
157
+ [...a].slice(0, o.multiple ? void 0 : 1).forEach((r) => i.items.add(r)), o.files = i.files, o.dispatchEvent(new Event("change", { bubbles: !0 }));
82
158
  });
83
159
  }
84
- let _ = !1;
85
- const v = '.ak-menu__item:not(:disabled):not([aria-disabled="true"])', nt = typeof CSS < "u" && CSS.supports?.("position-area", "block-end");
86
- function ot(e) {
87
- return e.id ? document.querySelector(`[popovertarget="${CSS.escape(e.id)}"]`) : null;
160
+ let O = !1;
161
+ const L = '.ak-menu__item:not(:disabled):not([aria-disabled="true"])', fe = typeof CSS < "u" && CSS.supports?.("position-area", "block-end");
162
+ function me(t) {
163
+ return t.id ? document.querySelector(`[popovertarget="${CSS.escape(t.id)}"]`) : null;
88
164
  }
89
- function at(e, t) {
90
- const n = t.getBoundingClientRect(), o = e.getBoundingClientRect();
91
- let i = e.classList.contains("ak-menu--end") ? n.right - o.width : n.left;
165
+ function pe(t, e) {
166
+ const n = e.getBoundingClientRect(), o = t.getBoundingClientRect();
167
+ let i = t.classList.contains("ak-menu--end") ? n.right - o.width : n.left;
92
168
  i = Math.max(8, Math.min(i, window.innerWidth - o.width - 8));
93
- let s = n.bottom + 4;
94
- s + o.height > window.innerHeight - 8 && n.top - o.height - 4 > 8 && (s = n.top - o.height - 4), e.style.position = "fixed", e.style.left = `${Math.round(i)}px`, e.style.top = `${Math.round(s)}px`, e.style.margin = "0";
169
+ let r = n.bottom + 4;
170
+ r + o.height > window.innerHeight - 8 && n.top - o.height - 4 > 8 && (r = n.top - o.height - 4), t.style.position = "fixed", t.style.left = `${Math.round(i)}px`, t.style.top = `${Math.round(r)}px`, t.style.margin = "0";
95
171
  }
96
- function it() {
97
- _ || (_ = !0, document.addEventListener(
172
+ function be() {
173
+ O || (O = !0, document.addEventListener(
98
174
  "toggle",
99
- (e) => {
100
- const t = e.target;
101
- if (!(t instanceof HTMLElement) || !t.classList.contains("ak-menu")) return;
102
- const n = e.newState === "open", o = ot(t);
103
- o?.setAttribute("aria-expanded", String(n)), n && (o && !nt && at(t, o), t.querySelector(v)?.focus());
175
+ (t) => {
176
+ const e = t.target;
177
+ if (!(e instanceof HTMLElement) || !e.classList.contains("ak-menu")) return;
178
+ const n = t.newState === "open", o = me(e);
179
+ o?.setAttribute("aria-expanded", String(n)), n && (o && !fe && pe(e, o), e.querySelector(L)?.focus());
104
180
  },
105
181
  !0
106
- ), document.addEventListener("keydown", (e) => {
107
- const t = e.target?.closest?.(".ak-menu:popover-open");
108
- if (!t) return;
109
- const n = [...t.querySelectorAll(v)];
182
+ ), document.addEventListener("keydown", (t) => {
183
+ const e = t.target?.closest?.(".ak-menu:popover-open");
184
+ if (!e) return;
185
+ const n = [...e.querySelectorAll(L)];
110
186
  if (!n.length) return;
111
187
  const o = n.indexOf(document.activeElement);
112
188
  let a = -1;
113
- e.key === "ArrowDown" ? a = (o + 1) % n.length : e.key === "ArrowUp" ? a = (o - 1 + n.length) % n.length : e.key === "Home" ? a = 0 : e.key === "End" ? a = n.length - 1 : e.key === "Tab" && t.hidePopover(), a >= 0 && (e.preventDefault(), n[a].focus());
114
- }), document.addEventListener("click", (e) => {
115
- e.target?.closest?.(v)?.closest(".ak-menu:popover-open")?.hidePopover();
189
+ t.key === "ArrowDown" ? a = (o + 1) % n.length : t.key === "ArrowUp" ? a = (o - 1 + n.length) % n.length : t.key === "Home" ? a = 0 : t.key === "End" ? a = n.length - 1 : t.key === "Tab" && e.hidePopover(), a >= 0 && (t.preventDefault(), n[a].focus());
190
+ }), document.addEventListener("click", (t) => {
191
+ t.target?.closest?.(L)?.closest(".ak-menu:popover-open")?.hidePopover();
116
192
  }));
117
193
  }
118
- const L = "ak-mode";
119
- let I = !1;
120
- function st(e) {
121
- const t = document.cookie.match(new RegExp(`(?:^|; )${e.replace(/[.$?*|{}()[\]\\/+^]/g, "\\$&")}=([^;]*)`));
122
- return t ? decodeURIComponent(t[1]) : null;
194
+ const C = "ak-mode";
195
+ let H = !1;
196
+ function ge(t) {
197
+ const e = document.cookie.match(new RegExp(`(?:^|; )${t.replace(/[.$?*|{}()[\]\\/+^]/g, "\\$&")}=([^;]*)`));
198
+ return e ? decodeURIComponent(e[1]) : null;
123
199
  }
124
- function j() {
125
- const e = document.documentElement;
126
- return e.dataset.akMode === "dark" || e.dataset.akTheme === "dark" ? "dark" : "light";
200
+ function G() {
201
+ const t = document.documentElement;
202
+ return t.dataset.akMode === "dark" || t.dataset.akTheme === "dark" ? "dark" : "light";
127
203
  }
128
- function rt(e, t = L) {
204
+ function ke(t, e = C) {
129
205
  const n = document.documentElement;
130
- e === "dark" ? n.dataset.akMode = "dark" : delete n.dataset.akMode, n.dataset.akTheme === "dark" && delete n.dataset.akTheme;
206
+ t === "dark" ? n.dataset.akMode = "dark" : delete n.dataset.akMode, n.dataset.akTheme === "dark" && delete n.dataset.akTheme;
131
207
  const o = location.protocol === "https:" ? "; Secure" : "";
132
- document.cookie = `${t}=${e}; path=/; max-age=31536000; SameSite=Lax${o}`, S(), n.dispatchEvent(new CustomEvent("ak:mode-change", { bubbles: !0, detail: { mode: e } }));
133
- }
134
- function S() {
135
- const e = j() === "dark";
136
- document.querySelectorAll("[data-ak-mode-toggle]").forEach((t) => {
137
- t.setAttribute("aria-pressed", String(e));
138
- const n = e ? t.dataset.akLabelLight : t.dataset.akLabelDark;
139
- n && (t.setAttribute("aria-label", n), t.hasAttribute("title") && (t.title = n));
208
+ document.cookie = `${e}=${t}; path=/; max-age=31536000; SameSite=Lax${o}`, $(), n.dispatchEvent(new CustomEvent("ak:mode-change", { bubbles: !0, detail: { mode: t } }));
209
+ }
210
+ function $() {
211
+ const t = G() === "dark";
212
+ document.querySelectorAll("[data-ak-mode-toggle]").forEach((e) => {
213
+ e.setAttribute("aria-pressed", String(t));
214
+ const n = t ? e.dataset.akLabelLight : e.dataset.akLabelDark;
215
+ n && (e.setAttribute("aria-label", n), e.hasAttribute("title") && (e.title = n));
140
216
  });
141
217
  }
142
- function lt() {
143
- if (I) {
144
- S();
218
+ function he() {
219
+ if (H) {
220
+ $();
145
221
  return;
146
222
  }
147
- I = !0;
148
- const t = document.querySelector("[data-ak-mode-toggle]")?.dataset.akModeToggle || L, n = document.documentElement;
149
- !n.dataset.akMode && st(t) === "dark" && (n.dataset.akMode = "dark"), S(), document.addEventListener("click", (o) => {
223
+ H = !0;
224
+ const e = document.querySelector("[data-ak-mode-toggle]")?.dataset.akModeToggle || C, n = document.documentElement;
225
+ !n.dataset.akMode && ge(e) === "dark" && (n.dataset.akMode = "dark"), $(), document.addEventListener("click", (o) => {
150
226
  const a = o.target?.closest?.("[data-ak-mode-toggle]");
151
- a && (o.preventDefault(), rt(j() === "dark" ? "light" : "dark", a.dataset.akModeToggle || L));
227
+ a && (o.preventDefault(), ke(G() === "dark" ? "light" : "dark", a.dataset.akModeToggle || C));
152
228
  });
153
229
  }
154
- let O = !1;
155
- function y(e, t) {
156
- e.toggleAttribute("data-sidebar-open", t), e.querySelectorAll("[data-ak-sidebar-toggle]").forEach((n) => n.setAttribute("aria-expanded", String(t)));
230
+ let R = !1;
231
+ function S(t, e) {
232
+ t.toggleAttribute("data-sidebar-open", e), t.querySelectorAll("[data-ak-sidebar-toggle]").forEach((n) => n.setAttribute("aria-expanded", String(e)));
157
233
  }
158
- function ct() {
159
- O || (O = !0, document.addEventListener("click", (e) => {
160
- const t = e.target instanceof Element ? e.target : null, n = t?.closest("[data-ak-sidebar-toggle]"), o = t?.closest(".ak-app");
234
+ function ye() {
235
+ R || (R = !0, document.addEventListener("click", (t) => {
236
+ const e = t.target instanceof Element ? t.target : null, n = e?.closest("[data-ak-sidebar-toggle]"), o = e?.closest(".ak-app");
161
237
  if (o) {
162
238
  if (n) {
163
- y(o, !o.hasAttribute("data-sidebar-open"));
239
+ S(o, !o.hasAttribute("data-sidebar-open"));
164
240
  return;
165
241
  }
166
- o.hasAttribute("data-sidebar-open") && !t?.closest(".ak-sidebar") && y(o, !1);
242
+ o.hasAttribute("data-sidebar-open") && !e?.closest(".ak-sidebar") && S(o, !1);
167
243
  }
168
- }), document.addEventListener("keydown", (e) => {
169
- if (e.key !== "Escape") return;
170
- const t = document.querySelector(".ak-app[data-sidebar-open]");
171
- t && (y(t, !1), t.querySelector("[data-ak-sidebar-toggle]")?.focus());
244
+ }), document.addEventListener("keydown", (t) => {
245
+ if (t.key !== "Escape") return;
246
+ const e = document.querySelector(".ak-app[data-sidebar-open]");
247
+ e && (S(e, !1), e.querySelector("[data-ak-sidebar-toggle]")?.focus());
172
248
  }));
173
249
  }
174
- let B = !1;
175
- const f = (e, t) => {
176
- const n = Number(e);
177
- return e !== "" && Number.isFinite(n) ? n : t;
250
+ let F = !1;
251
+ const E = (t, e) => {
252
+ const n = Number(t);
253
+ return t !== "" && Number.isFinite(n) ? n : e;
178
254
  };
179
- function H(e) {
180
- const t = e.querySelector("input");
181
- if (!t) return;
182
- const n = f(t.value, 0);
183
- e.querySelectorAll("[data-ak-step]").forEach((o) => {
255
+ function z(t) {
256
+ const e = t.querySelector("input");
257
+ if (!e) return;
258
+ const n = E(e.value, 0);
259
+ t.querySelectorAll("[data-ak-step]").forEach((o) => {
184
260
  const a = Number(o.dataset.akStep);
185
- o.disabled = t.disabled || (a < 0 ? n <= f(t.min, -1 / 0) : n >= f(t.max, 1 / 0));
261
+ o.disabled = e.disabled || (a < 0 ? n <= E(e.min, -1 / 0) : n >= E(e.max, 1 / 0));
186
262
  });
187
263
  }
188
- function dt(e, t) {
189
- const n = f(e.step, 1) || 1, o = Math.min(f(e.max, 1 / 0), Math.max(f(e.min, -1 / 0), f(e.value, 0) + t * n)), a = (String(n).split(".")[1] ?? "").length;
190
- e.value = o.toFixed(a), e.dispatchEvent(new Event("input", { bubbles: !0 })), e.dispatchEvent(new Event("change", { bubbles: !0 }));
191
- }
192
- function ut(e = document) {
193
- e.querySelectorAll(".ak-stepper").forEach(H), !B && (B = !0, document.addEventListener("click", (t) => {
194
- const n = t.target?.closest?.(".ak-stepper [data-ak-step]"), o = n?.closest(".ak-stepper"), a = o?.querySelector("input");
195
- !n || !o || !a || (t.preventDefault(), dt(a, Number(n.dataset.akStep) || 1));
196
- }), document.addEventListener("input", (t) => {
197
- const n = t.target?.closest?.(".ak-stepper");
198
- n && H(n);
264
+ function ve(t, e) {
265
+ const n = E(t.step, 1) || 1, o = Math.min(E(t.max, 1 / 0), Math.max(E(t.min, -1 / 0), E(t.value, 0) + e * n)), a = (String(n).split(".")[1] ?? "").length;
266
+ t.value = o.toFixed(a), t.dispatchEvent(new Event("input", { bubbles: !0 })), t.dispatchEvent(new Event("change", { bubbles: !0 }));
267
+ }
268
+ function Ee(t = document) {
269
+ t.querySelectorAll(".ak-stepper").forEach(z), !F && (F = !0, document.addEventListener("click", (e) => {
270
+ const n = e.target?.closest?.(".ak-stepper [data-ak-step]"), o = n?.closest(".ak-stepper"), a = o?.querySelector("input");
271
+ !n || !o || !a || (e.preventDefault(), ve(a, Number(n.dataset.akStep) || 1));
272
+ }), document.addEventListener("input", (e) => {
273
+ const n = e.target?.closest?.(".ak-stepper");
274
+ n && z(n);
199
275
  }));
200
276
  }
201
- let A = null;
202
- function R(e) {
203
- const t = e.querySelector(":scope > table");
204
- t && (e.removeAttribute("data-overflow"), e.toggleAttribute("data-overflow", t.scrollWidth > e.clientWidth + 1));
277
+ let T = null;
278
+ function W(t) {
279
+ const e = t.querySelector(":scope > table");
280
+ e && (t.removeAttribute("data-overflow"), t.toggleAttribute("data-overflow", e.scrollWidth > t.clientWidth + 1));
205
281
  }
206
- function ft(e = document) {
207
- typeof ResizeObserver > "u" || (A ??= new ResizeObserver((t) => {
208
- t.forEach((n) => {
282
+ function Ae(t = document) {
283
+ typeof ResizeObserver > "u" || (T ??= new ResizeObserver((e) => {
284
+ e.forEach((n) => {
209
285
  const o = n.target;
210
- R(o.matches(".ak-table-wrap") ? o : o.closest(".ak-table-wrap") ?? o);
286
+ W(o.matches(".ak-table-wrap") ? o : o.closest(".ak-table-wrap") ?? o);
211
287
  });
212
- }), e.querySelectorAll(".ak-table-wrap--page-sticky").forEach((t) => {
213
- if (t.dataset.akObserved) return;
214
- t.dataset.akObserved = "1", A?.observe(t);
215
- const n = t.querySelector(":scope > table");
216
- n && A?.observe(n), R(t);
288
+ }), t.querySelectorAll(".ak-table-wrap--page-sticky").forEach((e) => {
289
+ if (e.dataset.akObserved) return;
290
+ e.dataset.akObserved = "1", T?.observe(e);
291
+ const n = e.querySelector(":scope > table");
292
+ n && T?.observe(n), W(e);
217
293
  }));
218
294
  }
219
- let z = !1;
220
- function w(e) {
221
- return [...e.querySelectorAll(':scope > [role="tab"]')];
295
+ let U = !1;
296
+ function q(t) {
297
+ return [...t.querySelectorAll(':scope > [role="tab"]')];
222
298
  }
223
- function F(e, t = !1) {
224
- const n = e.closest('[role="tablist"]');
225
- if (!(!n || e.getAttribute("aria-disabled") === "true")) {
226
- for (const o of w(n)) {
227
- const a = o === e;
299
+ function P(t, e = !1) {
300
+ const n = t.closest('[role="tablist"]');
301
+ if (!(!n || t.getAttribute("aria-disabled") === "true")) {
302
+ for (const o of q(n)) {
303
+ const a = o === t;
228
304
  o.setAttribute("aria-selected", String(a)), o.tabIndex = a ? 0 : -1;
229
305
  const i = document.getElementById(o.getAttribute("aria-controls") ?? "");
230
306
  i && (i.hidden = !a, i.hasAttribute("tabindex") || (i.tabIndex = 0));
231
307
  }
232
- t && e.focus(), n.dispatchEvent(new CustomEvent("ak:tab-change", { bubbles: !0, detail: { tab: e } }));
308
+ e && t.focus(), n.dispatchEvent(new CustomEvent("ak:tab-change", { bubbles: !0, detail: { tab: t } }));
233
309
  }
234
310
  }
235
- function mt(e = document) {
236
- e.querySelectorAll('[role="tablist"]').forEach((t) => {
237
- const n = w(t), o = n.find((a) => a.getAttribute("aria-selected") === "true") ?? n[0];
311
+ function we(t = document) {
312
+ t.querySelectorAll('[role="tablist"]').forEach((e) => {
313
+ const n = q(e), o = n.find((a) => a.getAttribute("aria-selected") === "true") ?? n[0];
238
314
  n.forEach((a) => a.tabIndex = a === o ? 0 : -1);
239
- }), !z && (z = !0, document.addEventListener("click", (t) => {
240
- const n = t.target?.closest?.('[role="tablist"] > [role="tab"]');
241
- n && F(n);
242
- }), document.addEventListener("keydown", (t) => {
243
- const n = t.target?.closest?.('[role="tablist"] > [role="tab"]');
315
+ }), !U && (U = !0, document.addEventListener("click", (e) => {
316
+ const n = e.target?.closest?.('[role="tablist"] > [role="tab"]');
317
+ n && P(n);
318
+ }), document.addEventListener("keydown", (e) => {
319
+ const n = e.target?.closest?.('[role="tablist"] > [role="tab"]');
244
320
  if (!n) return;
245
- const o = w(n.parentElement).filter((s) => s.getAttribute("aria-disabled") !== "true"), a = o.indexOf(n);
321
+ const o = q(n.parentElement).filter((r) => r.getAttribute("aria-disabled") !== "true"), a = o.indexOf(n);
246
322
  let i;
247
- t.key === "ArrowRight" ? i = o[(a + 1) % o.length] : t.key === "ArrowLeft" ? i = o[(a - 1 + o.length) % o.length] : t.key === "Home" ? i = o[0] : t.key === "End" && (i = o[o.length - 1]), i && (t.preventDefault(), F(i, !0));
323
+ e.key === "ArrowRight" ? i = o[(a + 1) % o.length] : e.key === "ArrowLeft" ? i = o[(a - 1 + o.length) % o.length] : e.key === "Home" ? i = o[0] : e.key === "End" && (i = o[o.length - 1]), i && (e.preventDefault(), P(i, !0));
248
324
  }));
249
325
  }
250
- const bt = 4;
251
- let u = null;
252
- function gt() {
253
- return u?.isConnected || (u = document.createElement("section"), u.className = "ak-toaster", u.setAttribute("aria-label", "Уведомления"), document.body.append(u)), u;
254
- }
255
- function pt(e, { tone: t = "neutral", duration: n, action: o } = {}) {
256
- const a = gt(), i = document.createElement("div");
257
- i.className = `ak-toast ak-toast--${t}`, i.setAttribute("role", t === "negative" ? "alert" : "status"), i.setAttribute("aria-live", t === "negative" ? "assertive" : "polite");
258
- const s = document.createElement("p");
259
- if (s.className = "ak-toast__text", s.textContent = e, i.append(s), o) {
260
- const d = document.createElement("button");
261
- d.type = "button", d.className = "ak-toast__action", d.textContent = o.label, d.addEventListener("click", () => {
262
- o.onClick(), g();
263
- }), i.append(d);
264
- }
265
- const l = document.createElement("button");
266
- l.type = "button", l.className = "ak-toast__close", l.setAttribute("aria-label", "Закрыть"), l.textContent = "×", l.addEventListener("click", () => g()), i.append(l), a.append(i);
267
- const x = a.querySelectorAll(".ak-toast:not([data-leaving])");
268
- x.length > bt && x[0]._close?.(), requestAnimationFrame(() => requestAnimationFrame(() => i.setAttribute("data-shown", "")));
269
- const T = n ?? (t === "negative" ? 0 : 5e3);
270
- let E = T, $ = 0, b = 0;
271
- const p = () => {
272
- b && (clearTimeout(b), b = 0, E -= Date.now() - $);
273
- }, k = () => {
274
- !T || b || E <= 0 || document.hidden || ($ = Date.now(), b = window.setTimeout(g, E));
275
- }, M = () => document.hidden ? p() : k();
276
- i.addEventListener("mouseenter", p), i.addEventListener("mouseleave", k), i.addEventListener("focusin", p), i.addEventListener("focusout", k), document.addEventListener("visibilitychange", M), k();
277
- function g() {
278
- if (i.hasAttribute("data-leaving")) return;
279
- p(), document.removeEventListener("visibilitychange", M), i.setAttribute("data-leaving", ""), i.removeAttribute("data-shown");
280
- const d = () => i.remove();
281
- i.addEventListener("transitionend", d, { once: !0 }), window.setTimeout(d, 400);
326
+ const V = /* @__PURE__ */ new WeakSet();
327
+ function xe(t) {
328
+ const e = t.querySelector(".ak-trend__points")?.textContent ?? "";
329
+ try {
330
+ const n = JSON.parse(e);
331
+ return Array.isArray(n) ? n.filter((o) => Array.isArray(o) && typeof o[0] == "number" && typeof o[1] == "number").map((o) => [o[0], o[1], String(o[2] ?? "")]) : [];
332
+ } catch {
333
+ return [];
282
334
  }
283
- return i._close = g, { close: g };
284
335
  }
285
- function kt(e = document) {
286
- e.querySelectorAll("[data-ak-toast]:not([data-ak-bound])").forEach((t) => {
287
- t.setAttribute("data-ak-bound", "");
288
- const n = (t instanceof HTMLTemplateElement ? t.content.textContent : t.textContent)?.trim();
289
- if (!n) return;
290
- const o = t.dataset.akToast || "neutral", a = t.dataset.akDuration ? Number(t.dataset.akDuration) : void 0;
291
- pt(n, { tone: o, duration: a }), t instanceof HTMLTemplateElement || (t.hidden = !0);
336
+ function Le(t) {
337
+ if (V.has(t)) return;
338
+ const e = t.querySelector(".ak-trend__plot"), n = e?.querySelector("svg"), o = xe(t);
339
+ if (!e || !n || o.length < 2) return;
340
+ V.add(t);
341
+ const a = n.viewBox.baseVal, i = a && a.width ? a.width : 300, r = a && a.height ? a.height : 64, c = document.createElement("span"), d = document.createElement("span"), u = document.createElement("span");
342
+ c.className = "ak-trend__cursor", d.className = "ak-trend__dot", u.className = "ak-trend__tip", u.setAttribute("role", "status");
343
+ for (const s of [c, d, u]) s.hidden = !0;
344
+ e.append(c, d), t.querySelector(".ak-trend__title")?.after(u), e.hasAttribute("tabindex") || (e.tabIndex = 0);
345
+ let b = -1;
346
+ const h = (s) => {
347
+ b = Math.max(0, Math.min(o.length - 1, s));
348
+ const [f, m, l] = o[b], y = `${f / i * 100}%`;
349
+ c.style.left = y, d.style.left = y, d.style.top = `${m / r * 100}%`, u.textContent = l, c.hidden = d.hidden = u.hidden = !1;
350
+ }, g = () => {
351
+ c.hidden = d.hidden = u.hidden = !0;
352
+ }, A = (s) => {
353
+ const f = e.getBoundingClientRect(), m = (s - f.left) / f.width * i;
354
+ let l = 0;
355
+ for (let y = 1; y < o.length; y++)
356
+ Math.abs(o[y][0] - m) < Math.abs(o[l][0] - m) && (l = y);
357
+ return l;
358
+ };
359
+ e.addEventListener("pointermove", (s) => h(A(s.clientX))), e.addEventListener("pointerleave", () => {
360
+ document.activeElement !== e && g();
361
+ }), e.addEventListener("focus", () => h(b < 0 ? o.length - 1 : b)), e.addEventListener("blur", g), e.addEventListener("keydown", (s) => {
362
+ const f = { ArrowLeft: -1, ArrowRight: 1 };
363
+ if (s.key in f) h(b + f[s.key]);
364
+ else if (s.key === "Home") h(0);
365
+ else if (s.key === "End") h(o.length - 1);
366
+ else if (s.key === "Escape") g();
367
+ else return;
368
+ s.preventDefault();
292
369
  });
293
370
  }
294
- const ht = 500, Et = 400;
295
- let W = !1, c = null, r = null, h = 0, K = 0;
296
- function vt() {
297
- return c?.isConnected || (c = document.createElement("div"), c.className = "ak-tooltip", c.id = "ak-tooltip", c.setAttribute("role", "tooltip"), document.body.append(c)), c;
371
+ function Se(t = document) {
372
+ t.querySelectorAll(".ak-trend[data-ak-trend]").forEach(Le);
298
373
  }
299
- function yt(e) {
300
- return (e.dataset.akTooltip || e.getAttribute("aria-label") || e.getAttribute("title") || "").trim();
374
+ const Te = 500, Me = 400;
375
+ let X = !1, k = null, p = null, x = 0, J = 0;
376
+ function Ce() {
377
+ return k?.isConnected || (k = document.createElement("div"), k.className = "ak-tooltip", k.id = "ak-tooltip", k.setAttribute("role", "tooltip"), document.body.append(k)), k;
301
378
  }
302
- function At(e, t) {
303
- const n = e.getBoundingClientRect(), o = t.getBoundingClientRect();
379
+ function $e(t) {
380
+ return (t.dataset.akTooltip || t.getAttribute("aria-label") || t.getAttribute("title") || "").trim();
381
+ }
382
+ function qe(t, e) {
383
+ const n = t.getBoundingClientRect(), o = e.getBoundingClientRect();
304
384
  let a = n.top - o.height - 6, i = "top";
305
385
  a < 8 && (a = n.bottom + 6, i = "bottom");
306
- const s = Math.max(8, Math.min(n.left + n.width / 2 - o.width / 2, window.innerWidth - o.width - 8));
307
- t.style.top = `${Math.round(a)}px`, t.style.left = `${Math.round(s)}px`, t.dataset.side = i;
386
+ const r = Math.max(8, Math.min(n.left + n.width / 2 - o.width / 2, window.innerWidth - o.width - 8));
387
+ e.style.top = `${Math.round(a)}px`, e.style.left = `${Math.round(r)}px`, e.dataset.side = i;
308
388
  }
309
- function U(e, t) {
310
- const n = yt(e);
389
+ function j(t, e) {
390
+ const n = $e(t);
311
391
  if (!n) return;
312
- const o = vt();
313
- r = e, o.textContent = n, o.toggleAttribute("data-instant", t), o.setAttribute("data-open", ""), At(e, o);
314
- const a = e.getAttribute("aria-describedby") ?? "";
315
- a.split(" ").includes(o.id) || e.setAttribute("aria-describedby", `${a} ${o.id}`.trim());
316
- }
317
- function m() {
318
- if (clearTimeout(h), h = 0, !r) return;
319
- const e = (r.getAttribute("aria-describedby") ?? "").split(" ").filter((t) => t && t !== "ak-tooltip");
320
- e.length ? r.setAttribute("aria-describedby", e.join(" ")) : r.removeAttribute("aria-describedby"), r = null, c?.removeAttribute("data-open"), K = Date.now();
321
- }
322
- function P(e, t) {
323
- if (r === e) return;
324
- clearTimeout(h);
325
- const n = !!r || Date.now() - K < Et;
326
- r && m(), t || n ? U(e, n) : h = window.setTimeout(() => U(e, !1), ht);
327
- }
328
- function Lt() {
329
- if (W) return;
330
- W = !0;
331
- const e = (t) => t.target?.closest?.("[data-ak-tooltip]") ?? null;
332
- document.addEventListener("pointerover", (t) => {
333
- if (t.pointerType === "touch") return;
334
- const n = e(t);
335
- n && P(n, !1);
336
- }), document.addEventListener("pointerout", (t) => {
337
- const n = e(t);
338
- n && !n.contains(t.relatedTarget) && m();
339
- }), document.addEventListener("focusin", (t) => {
340
- const n = e(t);
341
- n && n.matches(":focus-visible") && P(n, !0);
342
- }), document.addEventListener("focusout", (t) => {
343
- e(t) && m();
344
- }), document.addEventListener("keydown", (t) => {
345
- t.key === "Escape" && r && m();
346
- }), window.addEventListener("scroll", m, { passive: !0, capture: !0 }), document.addEventListener("pointerdown", m);
392
+ const o = Ce();
393
+ p = t, o.textContent = n, o.toggleAttribute("data-instant", e), o.setAttribute("data-open", ""), qe(t, o);
394
+ const a = t.getAttribute("aria-describedby") ?? "";
395
+ a.split(" ").includes(o.id) || t.setAttribute("aria-describedby", `${a} ${o.id}`.trim());
396
+ }
397
+ function w() {
398
+ if (clearTimeout(x), x = 0, !p) return;
399
+ const t = (p.getAttribute("aria-describedby") ?? "").split(" ").filter((e) => e && e !== "ak-tooltip");
400
+ t.length ? p.setAttribute("aria-describedby", t.join(" ")) : p.removeAttribute("aria-describedby"), p = null, k?.removeAttribute("data-open"), J = Date.now();
401
+ }
402
+ function K(t, e) {
403
+ if (p === t) return;
404
+ clearTimeout(x);
405
+ const n = !!p || Date.now() - J < Me;
406
+ p && w(), e || n ? j(t, n) : x = window.setTimeout(() => j(t, !1), Te);
407
+ }
408
+ function _e() {
409
+ if (X) return;
410
+ X = !0;
411
+ const t = (e) => e.target?.closest?.("[data-ak-tooltip]") ?? null;
412
+ document.addEventListener("pointerover", (e) => {
413
+ if (e.pointerType === "touch") return;
414
+ const n = t(e);
415
+ n && K(n, !1);
416
+ }), document.addEventListener("pointerout", (e) => {
417
+ const n = t(e);
418
+ n && !n.contains(e.relatedTarget) && w();
419
+ }), document.addEventListener("focusin", (e) => {
420
+ const n = t(e);
421
+ n && n.matches(":focus-visible") && K(n, !0);
422
+ }), document.addEventListener("focusout", (e) => {
423
+ t(e) && w();
424
+ }), document.addEventListener("keydown", (e) => {
425
+ e.key === "Escape" && p && w();
426
+ }), window.addEventListener("scroll", w, { passive: !0, capture: !0 }), document.addEventListener("pointerdown", w);
347
427
  }
348
- function St({ root: e = document } = {}) {
349
- J(), it(), ct(), Lt(), lt(), et(), mt(e), ut(e), ft(e), Q(e), kt(e);
428
+ function De({ root: t = document } = {}) {
429
+ se(), ae(), be(), ye(), _e(), he(), ue(), we(t), Ee(t), Ae(t), Se(t), ce(t), ee(t);
350
430
  }
351
- const V = "http://www.w3.org/2000/svg";
352
- let X = "";
353
- function wt(e) {
354
- X = e;
431
+ const Y = "http://www.w3.org/2000/svg";
432
+ let Q = "";
433
+ function Ne(t) {
434
+ Q = t;
355
435
  }
356
- function xt(e, { size: t, label: n, className: o } = {}) {
357
- const a = document.createElementNS(V, "svg");
358
- a.setAttribute("class", ["ak-icon", t && `ak-icon--${t}`, o].filter(Boolean).join(" ")), n ? (a.setAttribute("role", "img"), a.setAttribute("aria-label", n)) : a.setAttribute("aria-hidden", "true"), a.setAttribute("focusable", "false");
359
- const i = document.createElementNS(V, "use");
360
- return i.setAttribute("href", `${X}#${e}`), a.append(i), a;
436
+ function Ie(t, { size: e, label: n, className: o } = {}) {
437
+ const a = document.createElementNS(Y, "svg");
438
+ a.setAttribute("class", ["ak-icon", e && `ak-icon--${e}`, o].filter(Boolean).join(" ")), n ? (a.setAttribute("role", "img"), a.setAttribute("aria-label", n)) : a.setAttribute("aria-hidden", "true"), a.setAttribute("focusable", "false");
439
+ const i = document.createElementNS(Y, "use");
440
+ return i.setAttribute("href", `${Q}#${t}`), a.append(i), a;
361
441
  }
362
442
  export {
363
- C as closeDialog,
364
- Q as dismissible,
365
- j as getMode,
366
- xt as icon,
367
- St as init,
368
- Y as openDialog,
369
- F as selectTab,
370
- wt as setIconSprite,
371
- rt as setMode,
372
- dt as stepBy,
373
- ft as stickyTables,
374
- pt as toast,
375
- kt as toastsFromDom
443
+ N as closeDialog,
444
+ ne as copyText,
445
+ ce as dismissible,
446
+ G as getMode,
447
+ Ie as icon,
448
+ De as init,
449
+ ie as openDialog,
450
+ P as selectTab,
451
+ Ne as setIconSprite,
452
+ ke as setMode,
453
+ ve as stepBy,
454
+ Ae as stickyTables,
455
+ M as toast,
456
+ ee as toastsFromDom,
457
+ Se as trends
376
458
  };
377
459
  //# sourceMappingURL=ace-ui-kit.js.map