@stonecrop/utilities 0.2.13 → 0.2.20
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 +330 -0
- package/dist/utilities.js.map +1 -0
- package/dist/utilities.umd.cjs +2 -0
- package/dist/utilities.umd.cjs.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,330 @@
|
|
|
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
|
+
}
|
|
5
|
+
function _(e) {
|
|
6
|
+
return typeof e == "function" ? e() : I(e);
|
|
7
|
+
}
|
|
8
|
+
const F = typeof window < "u" && typeof document < "u";
|
|
9
|
+
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
|
|
10
|
+
const q = Object.prototype.toString, N = (e) => q.call(e) === "[object Object]", G = () => {
|
|
11
|
+
};
|
|
12
|
+
function y(e) {
|
|
13
|
+
var t;
|
|
14
|
+
const n = _(e);
|
|
15
|
+
return (t = n == null ? void 0 : n.$el) != null ? t : n;
|
|
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)
|
|
29
|
+
return;
|
|
30
|
+
const p = N(u) ? { ...u } : u;
|
|
31
|
+
i.push(
|
|
32
|
+
...n.flatMap((d) => l.map((E) => r(f, d, E, p)))
|
|
33
|
+
);
|
|
34
|
+
},
|
|
35
|
+
{ immediate: !0, flush: "post" }
|
|
36
|
+
), a = () => {
|
|
37
|
+
c(), o();
|
|
38
|
+
};
|
|
39
|
+
return B(a), a;
|
|
40
|
+
}
|
|
41
|
+
function z(e = {}) {
|
|
42
|
+
var t;
|
|
43
|
+
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();
|
|
55
|
+
};
|
|
56
|
+
return n && (w(n, "blur", (c) => {
|
|
57
|
+
c.relatedTarget === null && r();
|
|
58
|
+
}, !0), w(n, "focus", r, !0)), r(), o;
|
|
59
|
+
}
|
|
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) };
|
|
63
|
+
}
|
|
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;
|
|
71
|
+
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;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
return v(
|
|
77
|
+
() => y(e),
|
|
78
|
+
() => s(),
|
|
79
|
+
{ immediate: !0, flush: "post" }
|
|
80
|
+
), t && w(n || t, "scroll", s, {
|
|
81
|
+
capture: !1,
|
|
82
|
+
passive: !0
|
|
83
|
+
}), l;
|
|
84
|
+
}
|
|
85
|
+
const g = (e) => {
|
|
86
|
+
let t = Q(e).value;
|
|
87
|
+
return t = t && e.offsetHeight > 0, t;
|
|
88
|
+
}, m = (e) => e.tabIndex >= 0, x = (e) => {
|
|
89
|
+
const t = e.target;
|
|
90
|
+
return A(t);
|
|
91
|
+
}, A = (e) => {
|
|
92
|
+
var n;
|
|
93
|
+
let t;
|
|
94
|
+
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);
|
|
99
|
+
}
|
|
100
|
+
} else if (e instanceof HTMLTableRowElement) {
|
|
101
|
+
const l = e.previousElementSibling;
|
|
102
|
+
l && (t = l);
|
|
103
|
+
}
|
|
104
|
+
return t && (!m(t) || !g(t)) ? A(t) : t;
|
|
105
|
+
}, X = (e) => {
|
|
106
|
+
var l;
|
|
107
|
+
const t = e.target;
|
|
108
|
+
let n;
|
|
109
|
+
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);
|
|
114
|
+
}
|
|
115
|
+
} else if (t instanceof HTMLTableRowElement) {
|
|
116
|
+
const s = t.parentElement;
|
|
117
|
+
if (s) {
|
|
118
|
+
const i = s.firstElementChild;
|
|
119
|
+
i && (n = i);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return n && (!m(n) || !g(n)) ? S(n) : n;
|
|
123
|
+
}, D = (e) => {
|
|
124
|
+
const t = e.target;
|
|
125
|
+
return S(t);
|
|
126
|
+
}, S = (e) => {
|
|
127
|
+
var n;
|
|
128
|
+
let t;
|
|
129
|
+
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);
|
|
134
|
+
}
|
|
135
|
+
} else if (e instanceof HTMLTableRowElement) {
|
|
136
|
+
const l = e.nextElementSibling;
|
|
137
|
+
l && (t = l);
|
|
138
|
+
}
|
|
139
|
+
return t && (!m(t) || !g(t)) ? S(t) : t;
|
|
140
|
+
}, Y = (e) => {
|
|
141
|
+
var l;
|
|
142
|
+
const t = e.target;
|
|
143
|
+
let n;
|
|
144
|
+
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);
|
|
149
|
+
}
|
|
150
|
+
} else if (t instanceof HTMLTableRowElement) {
|
|
151
|
+
const s = t.parentElement;
|
|
152
|
+
if (s) {
|
|
153
|
+
const i = s.lastElementChild;
|
|
154
|
+
i && (n = i);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return n && (!m(n) || !g(n)) ? A(n) : n;
|
|
158
|
+
}, R = (e) => {
|
|
159
|
+
const t = e.target;
|
|
160
|
+
return k(t);
|
|
161
|
+
}, k = (e) => {
|
|
162
|
+
var n;
|
|
163
|
+
let t;
|
|
164
|
+
if (e.previousElementSibling)
|
|
165
|
+
t = e.previousElementSibling;
|
|
166
|
+
else {
|
|
167
|
+
const l = (n = e.parentElement) == null ? void 0 : n.previousElementSibling;
|
|
168
|
+
t = l == null ? void 0 : l.lastElementChild;
|
|
169
|
+
}
|
|
170
|
+
return t && (!m(t) || !g(t)) ? k(t) : t;
|
|
171
|
+
}, P = (e) => {
|
|
172
|
+
const t = e.target;
|
|
173
|
+
return L(t);
|
|
174
|
+
}, L = (e) => {
|
|
175
|
+
var n;
|
|
176
|
+
let t;
|
|
177
|
+
if (e.nextElementSibling)
|
|
178
|
+
t = e.nextElementSibling;
|
|
179
|
+
else {
|
|
180
|
+
const l = (n = e.parentElement) == null ? void 0 : n.nextElementSibling;
|
|
181
|
+
t = l == null ? void 0 : l.firstElementChild;
|
|
182
|
+
}
|
|
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;
|
|
187
|
+
}, 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 = {
|
|
191
|
+
ArrowUp: "up",
|
|
192
|
+
ArrowDown: "down",
|
|
193
|
+
ArrowLeft: "left",
|
|
194
|
+
ArrowRight: "right"
|
|
195
|
+
}, ee = {
|
|
196
|
+
"keydown.up": (e) => {
|
|
197
|
+
const t = x(e);
|
|
198
|
+
t && (e.preventDefault(), e.stopPropagation(), t.focus());
|
|
199
|
+
},
|
|
200
|
+
"keydown.down": (e) => {
|
|
201
|
+
const t = D(e);
|
|
202
|
+
t && (e.preventDefault(), e.stopPropagation(), t.focus());
|
|
203
|
+
},
|
|
204
|
+
"keydown.left": (e) => {
|
|
205
|
+
const t = R(e);
|
|
206
|
+
e.preventDefault(), e.stopPropagation(), t && t.focus();
|
|
207
|
+
},
|
|
208
|
+
"keydown.right": (e) => {
|
|
209
|
+
const t = P(e);
|
|
210
|
+
e.preventDefault(), e.stopPropagation(), t && t.focus();
|
|
211
|
+
},
|
|
212
|
+
"keydown.control.up": (e) => {
|
|
213
|
+
const t = X(e);
|
|
214
|
+
t && (e.preventDefault(), e.stopPropagation(), t.focus());
|
|
215
|
+
},
|
|
216
|
+
"keydown.control.down": (e) => {
|
|
217
|
+
const t = Y(e);
|
|
218
|
+
t && (e.preventDefault(), e.stopPropagation(), t.focus());
|
|
219
|
+
},
|
|
220
|
+
"keydown.control.left": (e) => {
|
|
221
|
+
const t = K(e);
|
|
222
|
+
t && (e.preventDefault(), e.stopPropagation(), t.focus());
|
|
223
|
+
},
|
|
224
|
+
"keydown.control.right": (e) => {
|
|
225
|
+
const t = W(e);
|
|
226
|
+
t && (e.preventDefault(), e.stopPropagation(), t.focus());
|
|
227
|
+
},
|
|
228
|
+
"keydown.end": (e) => {
|
|
229
|
+
const t = W(e);
|
|
230
|
+
t && (e.preventDefault(), e.stopPropagation(), t.focus());
|
|
231
|
+
},
|
|
232
|
+
"keydown.enter": (e) => {
|
|
233
|
+
if (e.target instanceof HTMLTableCellElement) {
|
|
234
|
+
e.preventDefault(), e.stopPropagation();
|
|
235
|
+
const n = D(e);
|
|
236
|
+
n && n.focus();
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
"keydown.shift.enter": (e) => {
|
|
240
|
+
if (e.target instanceof HTMLTableCellElement) {
|
|
241
|
+
e.preventDefault(), e.stopPropagation();
|
|
242
|
+
const n = x(e);
|
|
243
|
+
n && n.focus();
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
"keydown.home": (e) => {
|
|
247
|
+
const t = K(e);
|
|
248
|
+
t && (e.preventDefault(), e.stopPropagation(), t.focus());
|
|
249
|
+
},
|
|
250
|
+
"keydown.tab": (e) => {
|
|
251
|
+
const t = P(e);
|
|
252
|
+
t && (e.preventDefault(), e.stopPropagation(), t.focus());
|
|
253
|
+
},
|
|
254
|
+
"keydown.shift.tab": (e) => {
|
|
255
|
+
const t = R(e);
|
|
256
|
+
t && (e.preventDefault(), e.stopPropagation(), t.focus());
|
|
257
|
+
}
|
|
258
|
+
};
|
|
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);
|
|
276
|
+
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);
|
|
294
|
+
});
|
|
295
|
+
if (E.length > 0) {
|
|
296
|
+
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);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
} else
|
|
304
|
+
H || d(r);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
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);
|
|
314
|
+
});
|
|
315
|
+
i.push(d);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}), V(() => {
|
|
319
|
+
for (const o of i)
|
|
320
|
+
o();
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
function le(e) {
|
|
324
|
+
}
|
|
325
|
+
export {
|
|
326
|
+
ee as defaultKeypressHandlers,
|
|
327
|
+
le as install,
|
|
328
|
+
ne as useKeyboardNav
|
|
329
|
+
};
|
|
330
|
+
//# sourceMappingURL=utilities.js.map
|