@stonecrop/utilities 0.3.6 → 0.3.8

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