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