@stonecrop/utilities 0.2.24 → 0.2.25

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.
package/dist/utilities.js CHANGED
@@ -1,198 +1,238 @@
1
- import { unref as I, getCurrentScope as O, onScopeDispose as U, computed as M, ref as b, watch as v, onMounted as j, onBeforeUnmount as V } from "vue";
2
- function B(e) {
3
- return O() ? (U(e), !0) : !1;
4
- }
1
+ import { unref as N, getCurrentScope as U, onScopeDispose as j, computed as y, ref as v, watch as w, getCurrentInstance as B, onMounted as K, onBeforeUnmount as V } from "vue";
5
2
  function _(e) {
6
- return typeof e == "function" ? e() : I(e);
3
+ return U() ? (j(e), !0) : !1;
4
+ }
5
+ function T(e) {
6
+ return typeof e == "function" ? e() : N(e);
7
7
  }
8
8
  const F = typeof window < "u" && typeof document < "u";
9
9
  typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
10
- const q = Object.prototype.toString, N = (e) => q.call(e) === "[object Object]", G = () => {
10
+ const q = (e) => e != null, G = Object.prototype.toString, z = (e) => G.call(e) === "[object Object]", J = () => {
11
11
  };
12
- function y(e) {
12
+ function C(e) {
13
13
  var t;
14
- const n = _(e);
14
+ const n = T(e);
15
15
  return (t = n == null ? void 0 : n.$el) != null ? t : n;
16
16
  }
17
- const T = F ? window : void 0;
18
- function w(...e) {
19
- let t, n, l, s;
20
- if (typeof e[0] == "string" || Array.isArray(e[0]) ? ([n, l, s] = e, t = T) : [t, n, l, s] = e, !t)
21
- return G;
22
- Array.isArray(n) || (n = [n]), Array.isArray(l) || (l = [l]);
23
- const i = [], o = () => {
24
- i.forEach((f) => f()), i.length = 0;
25
- }, r = (f, u, p, d) => (f.addEventListener(u, p, d), () => f.removeEventListener(u, p, d)), c = v(
26
- () => [y(t), _(s)],
27
- ([f, u]) => {
28
- if (o(), !f)
17
+ const b = F ? window : void 0;
18
+ function S(...e) {
19
+ let t, n, o, c;
20
+ if (typeof e[0] == "string" || Array.isArray(e[0]) ? ([n, o, c] = e, t = b) : [t, n, o, c] = e, !t)
21
+ return J;
22
+ Array.isArray(n) || (n = [n]), Array.isArray(o) || (o = [o]);
23
+ const l = [], r = () => {
24
+ l.forEach((i) => i()), l.length = 0;
25
+ }, s = (i, p, u, d) => (i.addEventListener(p, u, d), () => i.removeEventListener(p, u, d)), a = w(
26
+ () => [C(t), T(c)],
27
+ ([i, p]) => {
28
+ if (r(), !i)
29
29
  return;
30
- const p = N(u) ? { ...u } : u;
31
- i.push(
32
- ...n.flatMap((d) => l.map((E) => r(f, d, E, p)))
30
+ const u = z(p) ? { ...p } : p;
31
+ l.push(
32
+ ...n.flatMap((d) => o.map((E) => s(i, d, E, u)))
33
33
  );
34
34
  },
35
35
  { immediate: !0, flush: "post" }
36
- ), a = () => {
37
- c(), o();
36
+ ), f = () => {
37
+ a(), r();
38
+ };
39
+ return _(f), f;
40
+ }
41
+ function Q() {
42
+ const e = v(!1), t = B();
43
+ return t && K(() => {
44
+ e.value = !0;
45
+ }, t), e;
46
+ }
47
+ function X(e) {
48
+ const t = Q();
49
+ return y(() => (t.value, !!e()));
50
+ }
51
+ function Y(e, t, n = {}) {
52
+ const { window: o = b, ...c } = n;
53
+ let l;
54
+ const r = X(() => o && "MutationObserver" in o), s = () => {
55
+ l && (l.disconnect(), l = void 0);
56
+ }, a = y(() => {
57
+ const u = T(e), d = (Array.isArray(u) ? u : [u]).map(C).filter(q);
58
+ return new Set(d);
59
+ }), f = w(
60
+ () => a.value,
61
+ (u) => {
62
+ s(), r.value && u.size && (l = new MutationObserver(t), u.forEach((d) => l.observe(d, c)));
63
+ },
64
+ { immediate: !0, flush: "post" }
65
+ ), i = () => l == null ? void 0 : l.takeRecords(), p = () => {
66
+ s(), f();
67
+ };
68
+ return _(p), {
69
+ isSupported: r,
70
+ stop: p,
71
+ takeRecords: i
38
72
  };
39
- return B(a), a;
40
73
  }
41
- function z(e = {}) {
74
+ function Z(e = {}) {
42
75
  var t;
43
76
  const {
44
- window: n = T,
45
- deep: l = !0
46
- } = e, s = (t = e.document) != null ? t : n == null ? void 0 : n.document, i = () => {
47
- var c;
48
- let a = s == null ? void 0 : s.activeElement;
49
- if (l)
50
- for (; a != null && a.shadowRoot; )
51
- a = (c = a == null ? void 0 : a.shadowRoot) == null ? void 0 : c.activeElement;
52
- return a;
53
- }, o = b(), r = () => {
54
- o.value = i();
77
+ window: n = b,
78
+ deep: o = !0,
79
+ triggerOnRemoval: c = !1
80
+ } = e, l = (t = e.document) != null ? t : n == null ? void 0 : n.document, r = () => {
81
+ var f;
82
+ let i = l == null ? void 0 : l.activeElement;
83
+ if (o)
84
+ for (; i != null && i.shadowRoot; )
85
+ i = (f = i == null ? void 0 : i.shadowRoot) == null ? void 0 : f.activeElement;
86
+ return i;
87
+ }, s = v(), a = () => {
88
+ s.value = r();
55
89
  };
56
- return n && (w(n, "blur", (c) => {
57
- c.relatedTarget === null && r();
58
- }, !0), w(n, "focus", r, !0)), r(), o;
90
+ return n && (S(n, "blur", (f) => {
91
+ f.relatedTarget === null && a();
92
+ }, !0), S(n, "focus", a, !0)), c && Y(l, (f) => {
93
+ f.filter((i) => i.removedNodes.length).map((i) => Array.from(i.removedNodes)).flat().forEach((i) => {
94
+ i === s.value && a();
95
+ });
96
+ }, {
97
+ childList: !0,
98
+ subtree: !0
99
+ }), a(), s;
59
100
  }
60
- function J(e, t = {}) {
61
- const n = z(t), l = M(() => y(e));
62
- return { focused: M(() => l.value && n.value ? l.value.contains(n.value) : !1) };
101
+ function ee(e, t = {}) {
102
+ const n = Z(t), o = y(() => C(e));
103
+ return { focused: y(() => o.value && n.value ? o.value.contains(n.value) : !1) };
63
104
  }
64
- function Q(e, { window: t = T, scrollTarget: n } = {}) {
65
- const l = b(!1), s = () => {
66
- if (!t)
67
- return;
68
- const i = t.document, o = y(e);
69
- if (!o)
70
- l.value = !1;
105
+ function te(e, { window: t = b, scrollTarget: n } = {}) {
106
+ const o = v(!1), c = () => {
107
+ if (!t) return;
108
+ const l = t.document, r = C(e);
109
+ if (!r)
110
+ o.value = !1;
71
111
  else {
72
- const r = o.getBoundingClientRect();
73
- l.value = r.top <= (t.innerHeight || i.documentElement.clientHeight) && r.left <= (t.innerWidth || i.documentElement.clientWidth) && r.bottom >= 0 && r.right >= 0;
112
+ const s = r.getBoundingClientRect();
113
+ o.value = s.top <= (t.innerHeight || l.documentElement.clientHeight) && s.left <= (t.innerWidth || l.documentElement.clientWidth) && s.bottom >= 0 && s.right >= 0;
74
114
  }
75
115
  };
76
- return v(
77
- () => y(e),
78
- () => s(),
116
+ return w(
117
+ () => C(e),
118
+ () => c(),
79
119
  { immediate: !0, flush: "post" }
80
- ), t && w(n || t, "scroll", s, {
120
+ ), t && S(n || t, "scroll", c, {
81
121
  capture: !1,
82
122
  passive: !0
83
- }), l;
123
+ }), o;
84
124
  }
85
- const g = (e) => {
86
- let t = Q(e).value;
125
+ const m = (e) => {
126
+ let t = te(e).value;
87
127
  return t = t && e.offsetHeight > 0, t;
88
- }, m = (e) => e.tabIndex >= 0, x = (e) => {
128
+ }, g = (e) => e.tabIndex >= 0, x = (e) => {
89
129
  const t = e.target;
90
- return A(t);
91
- }, A = (e) => {
130
+ return M(t);
131
+ }, M = (e) => {
92
132
  var n;
93
133
  let t;
94
134
  if (e instanceof HTMLTableCellElement) {
95
- const l = (n = e.parentElement) == null ? void 0 : n.previousElementSibling;
96
- if (l) {
97
- const i = Array.from(l.children)[e.cellIndex];
98
- i && (t = i);
135
+ const o = (n = e.parentElement) == null ? void 0 : n.previousElementSibling;
136
+ if (o) {
137
+ const l = Array.from(o.children)[e.cellIndex];
138
+ l && (t = l);
99
139
  }
100
140
  } else if (e instanceof HTMLTableRowElement) {
101
- const l = e.previousElementSibling;
102
- l && (t = l);
141
+ const o = e.previousElementSibling;
142
+ o && (t = o);
103
143
  }
104
- return t && (!m(t) || !g(t)) ? A(t) : t;
105
- }, X = (e) => {
106
- var l;
144
+ return t && (!g(t) || !m(t)) ? M(t) : t;
145
+ }, ne = (e) => {
146
+ var o;
107
147
  const t = e.target;
108
148
  let n;
109
149
  if (t instanceof HTMLTableCellElement) {
110
- const s = (l = t.parentElement) == null ? void 0 : l.parentElement;
111
- if (s) {
112
- const o = s.firstElementChild.children[t.cellIndex];
113
- o && (n = o);
150
+ const c = (o = t.parentElement) == null ? void 0 : o.parentElement;
151
+ if (c) {
152
+ const r = c.firstElementChild.children[t.cellIndex];
153
+ r && (n = r);
114
154
  }
115
155
  } else if (t instanceof HTMLTableRowElement) {
116
- const s = t.parentElement;
117
- if (s) {
118
- const i = s.firstElementChild;
119
- i && (n = i);
156
+ const c = t.parentElement;
157
+ if (c) {
158
+ const l = c.firstElementChild;
159
+ l && (n = l);
120
160
  }
121
161
  }
122
- return n && (!m(n) || !g(n)) ? S(n) : n;
162
+ return n && (!g(n) || !m(n)) ? k(n) : n;
123
163
  }, D = (e) => {
124
164
  const t = e.target;
125
- return S(t);
126
- }, S = (e) => {
165
+ return k(t);
166
+ }, k = (e) => {
127
167
  var n;
128
168
  let t;
129
169
  if (e instanceof HTMLTableCellElement) {
130
- const l = (n = e.parentElement) == null ? void 0 : n.nextElementSibling;
131
- if (l) {
132
- const i = Array.from(l.children)[e.cellIndex];
133
- i && (t = i);
170
+ const o = (n = e.parentElement) == null ? void 0 : n.nextElementSibling;
171
+ if (o) {
172
+ const l = Array.from(o.children)[e.cellIndex];
173
+ l && (t = l);
134
174
  }
135
175
  } else if (e instanceof HTMLTableRowElement) {
136
- const l = e.nextElementSibling;
137
- l && (t = l);
176
+ const o = e.nextElementSibling;
177
+ o && (t = o);
138
178
  }
139
- return t && (!m(t) || !g(t)) ? S(t) : t;
140
- }, Y = (e) => {
141
- var l;
179
+ return t && (!g(t) || !m(t)) ? k(t) : t;
180
+ }, oe = (e) => {
181
+ var o;
142
182
  const t = e.target;
143
183
  let n;
144
184
  if (t instanceof HTMLTableCellElement) {
145
- const s = (l = t.parentElement) == null ? void 0 : l.parentElement;
146
- if (s) {
147
- const o = s.lastElementChild.children[t.cellIndex];
148
- o && (n = o);
185
+ const c = (o = t.parentElement) == null ? void 0 : o.parentElement;
186
+ if (c) {
187
+ const r = c.lastElementChild.children[t.cellIndex];
188
+ r && (n = r);
149
189
  }
150
190
  } else if (t instanceof HTMLTableRowElement) {
151
- const s = t.parentElement;
152
- if (s) {
153
- const i = s.lastElementChild;
154
- i && (n = i);
191
+ const c = t.parentElement;
192
+ if (c) {
193
+ const l = c.lastElementChild;
194
+ l && (n = l);
155
195
  }
156
196
  }
157
- return n && (!m(n) || !g(n)) ? A(n) : n;
158
- }, R = (e) => {
197
+ return n && (!g(n) || !m(n)) ? M(n) : n;
198
+ }, P = (e) => {
159
199
  const t = e.target;
160
- return k(t);
161
- }, k = (e) => {
200
+ return L(t);
201
+ }, L = (e) => {
162
202
  var n;
163
203
  let t;
164
204
  if (e.previousElementSibling)
165
205
  t = e.previousElementSibling;
166
206
  else {
167
- const l = (n = e.parentElement) == null ? void 0 : n.previousElementSibling;
168
- t = l == null ? void 0 : l.lastElementChild;
207
+ const o = (n = e.parentElement) == null ? void 0 : n.previousElementSibling;
208
+ t = o == null ? void 0 : o.lastElementChild;
169
209
  }
170
- return t && (!m(t) || !g(t)) ? k(t) : t;
171
- }, P = (e) => {
210
+ return t && (!g(t) || !m(t)) ? L(t) : t;
211
+ }, O = (e) => {
172
212
  const t = e.target;
173
- return L(t);
174
- }, L = (e) => {
213
+ return R(t);
214
+ }, R = (e) => {
175
215
  var n;
176
216
  let t;
177
217
  if (e.nextElementSibling)
178
218
  t = e.nextElementSibling;
179
219
  else {
180
- const l = (n = e.parentElement) == null ? void 0 : n.nextElementSibling;
181
- t = l == null ? void 0 : l.firstElementChild;
220
+ const o = (n = e.parentElement) == null ? void 0 : n.nextElementSibling;
221
+ t = o == null ? void 0 : o.firstElementChild;
182
222
  }
183
- return t && (!m(t) || !g(t)) ? L(t) : t;
184
- }, K = (e) => {
185
- const l = e.target.parentElement.firstElementChild;
186
- return l && (!m(l) || !g(l)) ? L(l) : l;
223
+ return t && (!g(t) || !m(t)) ? R(t) : t;
187
224
  }, W = (e) => {
188
- const l = e.target.parentElement.lastElementChild;
189
- return l && (!m(l) || !g(l)) ? k(l) : l;
190
- }, C = ["alt", "control", "shift", "meta"], Z = {
225
+ const o = e.target.parentElement.firstElementChild;
226
+ return o && (!g(o) || !m(o)) ? R(o) : o;
227
+ }, I = (e) => {
228
+ const o = e.target.parentElement.lastElementChild;
229
+ return o && (!g(o) || !m(o)) ? L(o) : o;
230
+ }, h = ["alt", "control", "shift", "meta"], re = {
191
231
  ArrowUp: "up",
192
232
  ArrowDown: "down",
193
233
  ArrowLeft: "left",
194
234
  ArrowRight: "right"
195
- }, ee = {
235
+ }, le = {
196
236
  "keydown.up": (e) => {
197
237
  const t = x(e);
198
238
  t && (e.preventDefault(), e.stopPropagation(), t.focus());
@@ -202,31 +242,31 @@ const g = (e) => {
202
242
  t && (e.preventDefault(), e.stopPropagation(), t.focus());
203
243
  },
204
244
  "keydown.left": (e) => {
205
- const t = R(e);
245
+ const t = P(e);
206
246
  e.preventDefault(), e.stopPropagation(), t && t.focus();
207
247
  },
208
248
  "keydown.right": (e) => {
209
- const t = P(e);
249
+ const t = O(e);
210
250
  e.preventDefault(), e.stopPropagation(), t && t.focus();
211
251
  },
212
252
  "keydown.control.up": (e) => {
213
- const t = X(e);
253
+ const t = ne(e);
214
254
  t && (e.preventDefault(), e.stopPropagation(), t.focus());
215
255
  },
216
256
  "keydown.control.down": (e) => {
217
- const t = Y(e);
257
+ const t = oe(e);
218
258
  t && (e.preventDefault(), e.stopPropagation(), t.focus());
219
259
  },
220
260
  "keydown.control.left": (e) => {
221
- const t = K(e);
261
+ const t = W(e);
222
262
  t && (e.preventDefault(), e.stopPropagation(), t.focus());
223
263
  },
224
264
  "keydown.control.right": (e) => {
225
- const t = W(e);
265
+ const t = I(e);
226
266
  t && (e.preventDefault(), e.stopPropagation(), t.focus());
227
267
  },
228
268
  "keydown.end": (e) => {
229
- const t = W(e);
269
+ const t = I(e);
230
270
  t && (e.preventDefault(), e.stopPropagation(), t.focus());
231
271
  },
232
272
  "keydown.enter": (e) => {
@@ -244,87 +284,86 @@ const g = (e) => {
244
284
  }
245
285
  },
246
286
  "keydown.home": (e) => {
247
- const t = K(e);
287
+ const t = W(e);
248
288
  t && (e.preventDefault(), e.stopPropagation(), t.focus());
249
289
  },
250
290
  "keydown.tab": (e) => {
251
- const t = P(e);
291
+ const t = O(e);
252
292
  t && (e.preventDefault(), e.stopPropagation(), t.focus());
253
293
  },
254
294
  "keydown.shift.tab": (e) => {
255
- const t = R(e);
295
+ const t = P(e);
256
296
  t && (e.preventDefault(), e.stopPropagation(), t.focus());
257
297
  }
258
298
  };
259
- function ne(e) {
260
- const t = (o) => {
261
- let r = null;
262
- return o.parent && (typeof o.parent == "string" ? r = document.querySelector(o.parent) : o.parent instanceof HTMLElement ? r = o.parent : r = o.parent.value), r;
263
- }, n = (o) => {
264
- const r = t(o);
265
- let c = [];
266
- if (typeof o.selectors == "string")
267
- c = r ? Array.from(r.querySelectorAll(o.selectors)) : Array.from(document.querySelectorAll(o.selectors));
268
- else if (Array.isArray(o.selectors))
269
- for (const a of o.selectors)
270
- a instanceof HTMLElement ? c.push(a) : c.push(a.$el);
271
- else if (o.selectors instanceof HTMLElement)
272
- c.push(o.selectors);
273
- else if (Array.isArray(o.selectors.value))
274
- for (const a of o.selectors.value)
275
- a instanceof HTMLElement ? c.push(a) : c.push(a.$el);
299
+ function ie(e) {
300
+ const t = (r) => {
301
+ let s = null;
302
+ return r.parent && (typeof r.parent == "string" ? s = document.querySelector(r.parent) : r.parent instanceof HTMLElement ? s = r.parent : s = r.parent.value), s;
303
+ }, n = (r) => {
304
+ const s = t(r);
305
+ let a = [];
306
+ if (typeof r.selectors == "string")
307
+ a = s ? Array.from(s.querySelectorAll(r.selectors)) : Array.from(document.querySelectorAll(r.selectors));
308
+ else if (Array.isArray(r.selectors))
309
+ for (const f of r.selectors)
310
+ f instanceof HTMLElement ? a.push(f) : a.push(f.$el);
311
+ else if (r.selectors instanceof HTMLElement)
312
+ a.push(r.selectors);
313
+ else if (Array.isArray(r.selectors.value))
314
+ for (const f of r.selectors.value)
315
+ f instanceof HTMLElement ? a.push(f) : a.push(f.$el);
276
316
  else
277
- c.push(o.selectors.value);
278
- return c;
279
- }, l = (o) => {
280
- const r = t(o);
281
- let c = [];
282
- return o.selectors ? c = n(o) : r && (c = Array.from(r.children).filter((f) => m(f) && g(f))), c;
283
- }, s = (o) => (r) => {
284
- const c = Z[r.key] || r.key.toLowerCase();
285
- if (C.includes(c))
286
- return;
287
- const a = o.handlers || ee;
288
- for (const f of Object.keys(a)) {
289
- const [u, ...p] = f.split(".");
290
- if (u === "keydown" && p.includes(c)) {
291
- const d = a[f], E = p.filter(($) => C.includes($)), H = C.some(($) => {
292
- const h = $.charAt(0).toUpperCase() + $.slice(1);
293
- return r.getModifierState(h);
317
+ a.push(r.selectors.value);
318
+ return a;
319
+ }, o = (r) => {
320
+ const s = t(r);
321
+ let a = [];
322
+ return r.selectors ? a = n(r) : s && (a = Array.from(s.children).filter((i) => g(i) && m(i))), a;
323
+ }, c = (r) => (s) => {
324
+ const a = re[s.key] || s.key.toLowerCase();
325
+ if (h.includes(a)) return;
326
+ const f = r.handlers || le;
327
+ for (const i of Object.keys(f)) {
328
+ const [p, ...u] = i.split(".");
329
+ if (p === "keydown" && u.includes(a)) {
330
+ const d = f[i], E = u.filter(($) => h.includes($)), H = h.some(($) => {
331
+ const A = $.charAt(0).toUpperCase() + $.slice(1);
332
+ return s.getModifierState(A);
294
333
  });
295
334
  if (E.length > 0) {
296
335
  if (H) {
297
- for (const $ of C)
298
- if (p.includes($)) {
299
- const h = $.charAt(0).toUpperCase() + $.slice(1);
300
- r.getModifierState(h) && d(r);
336
+ for (const $ of h)
337
+ if (u.includes($)) {
338
+ const A = $.charAt(0).toUpperCase() + $.slice(1);
339
+ s.getModifierState(A) && d(s);
301
340
  }
302
341
  }
303
342
  } else
304
- H || d(r);
343
+ H || d(s);
305
344
  }
306
345
  }
307
- }, i = [];
308
- j(() => {
309
- for (const o of e) {
310
- const r = t(o), c = l(o), a = s(o), f = r ? [r] : c;
311
- for (const u of f) {
312
- const { focused: p } = J(b(u)), d = v(p, (E) => {
313
- E ? u.addEventListener("keydown", a) : u.removeEventListener("keydown", a);
346
+ }, l = [];
347
+ K(() => {
348
+ for (const r of e) {
349
+ const s = t(r), a = o(r), f = c(r), i = s ? [s] : a;
350
+ for (const p of i) {
351
+ const { focused: u } = ee(v(p)), d = w(u, (E) => {
352
+ E ? p.addEventListener("keydown", f) : p.removeEventListener("keydown", f);
314
353
  });
315
- i.push(d);
354
+ l.push(d);
316
355
  }
317
356
  }
318
357
  }), V(() => {
319
- for (const o of i)
320
- o();
358
+ for (const r of l)
359
+ r();
321
360
  });
322
361
  }
323
- function le(e) {
362
+ function ce(e) {
324
363
  }
325
364
  export {
326
- ee as defaultKeypressHandlers,
327
- le as install,
328
- ne as useKeyboardNav
365
+ le as defaultKeypressHandlers,
366
+ ce as install,
367
+ ie as useKeyboardNav
329
368
  };
330
369
  //# sourceMappingURL=utilities.js.map