@stonecrop/utilities 0.2.11 → 0.2.18

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,333 +1,330 @@
1
- import { unref as Q, getCurrentScope as U, onScopeDispose as K, ref as B, watch as D, onMounted as W, onBeforeUnmount as V } from "vue";
2
- var v;
3
- const M = typeof window < "u", F = (e) => typeof e == "string", j = () => {
4
- };
5
- M && ((v = window == null ? void 0 : window.navigator) != null && v.userAgent) && /iP(ad|hone|od)/.test(window.navigator.userAgent);
6
- function H(e) {
7
- return typeof e == "function" ? e() : Q(e);
8
- }
9
- function q(e) {
10
- return e;
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;
11
4
  }
12
- function G(e) {
13
- return U() ? (K(e), !0) : !1;
5
+ function _(e) {
6
+ return typeof e == "function" ? e() : I(e);
14
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
+ };
15
12
  function y(e) {
16
13
  var t;
17
- const r = H(e);
18
- return (t = r == null ? void 0 : r.$el) != null ? t : r;
14
+ const n = _(e);
15
+ return (t = n == null ? void 0 : n.$el) != null ? t : n;
19
16
  }
20
- const N = M ? window : void 0;
21
- function z(...e) {
22
- let t, r, n, o;
23
- if (F(e[0]) || Array.isArray(e[0]) ? ([r, n, o] = e, t = N) : [t, r, n, o] = e, !t)
24
- return j;
25
- Array.isArray(r) || (r = [r]), Array.isArray(n) || (n = [n]);
26
- const l = [], s = () => {
27
- l.forEach((c) => c()), l.length = 0;
28
- }, a = (c, g, p, i) => (c.addEventListener(g, p, i), () => c.removeEventListener(g, p, i)), C = D(() => [y(t), H(o)], ([c, g]) => {
29
- s(), c && l.push(...r.flatMap((p) => n.map((i) => a(c, p, i, g))));
30
- }, { immediate: !0, flush: "post" }), d = () => {
31
- C(), s();
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();
32
38
  };
33
- return G(d), d;
39
+ return B(a), a;
34
40
  }
35
- const O = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, T = "__vueuse_ssr_handlers__";
36
- O[T] = O[T] || {};
37
- function J(e, { window: t = N, scrollTarget: r } = {}) {
38
- const n = B(!1), o = () => {
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 = () => {
39
66
  if (!t)
40
67
  return;
41
- const l = t.document, s = y(e);
42
- if (!s)
43
- n.value = !1;
68
+ const i = t.document, o = y(e);
69
+ if (!o)
70
+ l.value = !1;
44
71
  else {
45
- const a = s.getBoundingClientRect();
46
- n.value = a.top <= (t.innerHeight || l.documentElement.clientHeight) && a.left <= (t.innerWidth || l.documentElement.clientWidth) && a.bottom >= 0 && a.right >= 0;
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;
47
74
  }
48
75
  };
49
- return D(() => y(e), () => o(), { immediate: !0, flush: "post" }), t && z(r || t, "scroll", o, {
76
+ return v(
77
+ () => y(e),
78
+ () => s(),
79
+ { immediate: !0, flush: "post" }
80
+ ), t && w(n || t, "scroll", s, {
50
81
  capture: !1,
51
82
  passive: !0
52
- }), n;
83
+ }), l;
53
84
  }
54
- var P;
55
- (function(e) {
56
- e.UP = "UP", e.RIGHT = "RIGHT", e.DOWN = "DOWN", e.LEFT = "LEFT", e.NONE = "NONE";
57
- })(P || (P = {}));
58
- var X = Object.defineProperty, I = Object.getOwnPropertySymbols, Y = Object.prototype.hasOwnProperty, Z = Object.prototype.propertyIsEnumerable, _ = (e, t, r) => t in e ? X(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, ee = (e, t) => {
59
- for (var r in t || (t = {}))
60
- Y.call(t, r) && _(e, r, t[r]);
61
- if (I)
62
- for (var r of I(t))
63
- Z.call(t, r) && _(e, r, t[r]);
64
- return e;
65
- };
66
- const te = {
67
- easeInSine: [0.12, 0, 0.39, 0],
68
- easeOutSine: [0.61, 1, 0.88, 1],
69
- easeInOutSine: [0.37, 0, 0.63, 1],
70
- easeInQuad: [0.11, 0, 0.5, 0],
71
- easeOutQuad: [0.5, 1, 0.89, 1],
72
- easeInOutQuad: [0.45, 0, 0.55, 1],
73
- easeInCubic: [0.32, 0, 0.67, 0],
74
- easeOutCubic: [0.33, 1, 0.68, 1],
75
- easeInOutCubic: [0.65, 0, 0.35, 1],
76
- easeInQuart: [0.5, 0, 0.75, 0],
77
- easeOutQuart: [0.25, 1, 0.5, 1],
78
- easeInOutQuart: [0.76, 0, 0.24, 1],
79
- easeInQuint: [0.64, 0, 0.78, 0],
80
- easeOutQuint: [0.22, 1, 0.36, 1],
81
- easeInOutQuint: [0.83, 0, 0.17, 1],
82
- easeInExpo: [0.7, 0, 0.84, 0],
83
- easeOutExpo: [0.16, 1, 0.3, 1],
84
- easeInOutExpo: [0.87, 0, 0.13, 1],
85
- easeInCirc: [0.55, 0, 1, 0.45],
86
- easeOutCirc: [0, 0.55, 0.45, 1],
87
- easeInOutCirc: [0.85, 0, 0.15, 1],
88
- easeInBack: [0.36, 0, 0.66, -0.56],
89
- easeOutBack: [0.34, 1.56, 0.64, 1],
90
- easeInOutBack: [0.68, -0.6, 0.32, 1.6]
91
- };
92
- ee({
93
- linear: q
94
- }, te);
95
- const f = (e) => {
96
- let t = J(e).value;
85
+ const g = (e) => {
86
+ let t = Q(e).value;
97
87
  return t = t && e.offsetHeight > 0, t;
98
- }, u = (e) => e.tabIndex >= 0, A = (e) => {
88
+ }, m = (e) => e.tabIndex >= 0, x = (e) => {
99
89
  const t = e.target;
100
- return E(t);
101
- }, E = (e) => {
102
- var r;
90
+ return A(t);
91
+ }, A = (e) => {
92
+ var n;
103
93
  let t;
104
94
  if (e instanceof HTMLTableCellElement) {
105
- const n = (r = e.parentElement) == null ? void 0 : r.previousElementSibling;
106
- if (n) {
107
- const l = Array.from(n.children)[e.cellIndex];
108
- l && (t = l);
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);
109
99
  }
110
100
  } else if (e instanceof HTMLTableRowElement) {
111
- const n = e.previousElementSibling;
112
- n && (t = n);
101
+ const l = e.previousElementSibling;
102
+ l && (t = l);
113
103
  }
114
- return t && (!u(t) || !f(t)) ? E(t) : t;
115
- }, ne = (e) => {
116
- var n;
104
+ return t && (!m(t) || !g(t)) ? A(t) : t;
105
+ }, X = (e) => {
106
+ var l;
117
107
  const t = e.target;
118
- let r;
108
+ let n;
119
109
  if (t instanceof HTMLTableCellElement) {
120
- const o = (n = t.parentElement) == null ? void 0 : n.parentElement;
121
- if (o) {
122
- const s = o.firstElementChild.children[t.cellIndex];
123
- s && (r = s);
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);
124
114
  }
125
115
  } else if (t instanceof HTMLTableRowElement) {
126
- const o = t.parentElement;
127
- if (o) {
128
- const l = o.firstElementChild;
129
- l && (r = l);
116
+ const s = t.parentElement;
117
+ if (s) {
118
+ const i = s.firstElementChild;
119
+ i && (n = i);
130
120
  }
131
121
  }
132
- return r && (!u(r) || !f(r)) ? w(r) : r;
133
- }, x = (e) => {
122
+ return n && (!m(n) || !g(n)) ? S(n) : n;
123
+ }, D = (e) => {
134
124
  const t = e.target;
135
- return w(t);
136
- }, w = (e) => {
137
- var r;
125
+ return S(t);
126
+ }, S = (e) => {
127
+ var n;
138
128
  let t;
139
129
  if (e instanceof HTMLTableCellElement) {
140
- const n = (r = e.parentElement) == null ? void 0 : r.nextElementSibling;
141
- if (n) {
142
- const l = Array.from(n.children)[e.cellIndex];
143
- l && (t = l);
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);
144
134
  }
145
135
  } else if (e instanceof HTMLTableRowElement) {
146
- const n = e.nextElementSibling;
147
- n && (t = n);
136
+ const l = e.nextElementSibling;
137
+ l && (t = l);
148
138
  }
149
- return t && (!u(t) || !f(t)) ? w(t) : t;
150
- }, re = (e) => {
151
- var n;
139
+ return t && (!m(t) || !g(t)) ? S(t) : t;
140
+ }, Y = (e) => {
141
+ var l;
152
142
  const t = e.target;
153
- let r;
143
+ let n;
154
144
  if (t instanceof HTMLTableCellElement) {
155
- const o = (n = t.parentElement) == null ? void 0 : n.parentElement;
156
- if (o) {
157
- const s = o.lastElementChild.children[t.cellIndex];
158
- s && (r = s);
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);
159
149
  }
160
150
  } else if (t instanceof HTMLTableRowElement) {
161
- const o = t.parentElement;
162
- if (o) {
163
- const l = o.lastElementChild;
164
- l && (r = l);
151
+ const s = t.parentElement;
152
+ if (s) {
153
+ const i = s.lastElementChild;
154
+ i && (n = i);
165
155
  }
166
156
  }
167
- return r && (!u(r) || !f(r)) ? E(r) : r;
168
- }, k = (e) => {
157
+ return n && (!m(n) || !g(n)) ? A(n) : n;
158
+ }, R = (e) => {
169
159
  const t = e.target;
170
- return h(t);
171
- }, h = (e) => {
172
- var r;
160
+ return k(t);
161
+ }, k = (e) => {
162
+ var n;
173
163
  let t;
174
164
  if (e.previousElementSibling)
175
165
  t = e.previousElementSibling;
176
166
  else {
177
- const n = (r = e.parentElement) == null ? void 0 : r.previousElementSibling;
178
- t = n == null ? void 0 : n.lastElementChild;
167
+ const l = (n = e.parentElement) == null ? void 0 : n.previousElementSibling;
168
+ t = l == null ? void 0 : l.lastElementChild;
179
169
  }
180
- return t && (!u(t) || !f(t)) ? h(t) : t;
181
- }, S = (e) => {
170
+ return t && (!m(t) || !g(t)) ? k(t) : t;
171
+ }, P = (e) => {
182
172
  const t = e.target;
183
- return b(t);
184
- }, b = (e) => {
185
- var r;
173
+ return L(t);
174
+ }, L = (e) => {
175
+ var n;
186
176
  let t;
187
177
  if (e.nextElementSibling)
188
178
  t = e.nextElementSibling;
189
179
  else {
190
- const n = (r = e.parentElement) == null ? void 0 : r.nextElementSibling;
191
- t = n == null ? void 0 : n.firstElementChild;
180
+ const l = (n = e.parentElement) == null ? void 0 : n.nextElementSibling;
181
+ t = l == null ? void 0 : l.firstElementChild;
192
182
  }
193
- return t && (!u(t) || !f(t)) ? b(t) : t;
194
- }, L = (e) => {
195
- const n = e.target.parentElement.firstElementChild;
196
- return n && (!u(n) || !f(n)) ? b(n) : n;
197
- }, R = (e) => {
198
- const n = e.target.parentElement.lastElementChild;
199
- return n && (!u(n) || !f(n)) ? h(n) : n;
200
- }, m = ["alt", "control", "shift", "meta"], oe = {
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 = {
201
191
  ArrowUp: "up",
202
192
  ArrowDown: "down",
203
193
  ArrowLeft: "left",
204
194
  ArrowRight: "right"
205
- }, le = {
195
+ }, ee = {
206
196
  "keydown.up": (e) => {
207
- const t = A(e);
197
+ const t = x(e);
208
198
  t && (e.preventDefault(), e.stopPropagation(), t.focus());
209
199
  },
210
200
  "keydown.down": (e) => {
211
- const t = x(e);
201
+ const t = D(e);
212
202
  t && (e.preventDefault(), e.stopPropagation(), t.focus());
213
203
  },
214
204
  "keydown.left": (e) => {
215
- const t = k(e);
205
+ const t = R(e);
216
206
  e.preventDefault(), e.stopPropagation(), t && t.focus();
217
207
  },
218
208
  "keydown.right": (e) => {
219
- const t = S(e);
209
+ const t = P(e);
220
210
  e.preventDefault(), e.stopPropagation(), t && t.focus();
221
211
  },
222
212
  "keydown.control.up": (e) => {
223
- const t = ne(e);
213
+ const t = X(e);
224
214
  t && (e.preventDefault(), e.stopPropagation(), t.focus());
225
215
  },
226
216
  "keydown.control.down": (e) => {
227
- const t = re(e);
217
+ const t = Y(e);
228
218
  t && (e.preventDefault(), e.stopPropagation(), t.focus());
229
219
  },
230
220
  "keydown.control.left": (e) => {
231
- const t = L(e);
221
+ const t = K(e);
232
222
  t && (e.preventDefault(), e.stopPropagation(), t.focus());
233
223
  },
234
224
  "keydown.control.right": (e) => {
235
- const t = R(e);
225
+ const t = W(e);
236
226
  t && (e.preventDefault(), e.stopPropagation(), t.focus());
237
227
  },
238
228
  "keydown.end": (e) => {
239
- const t = R(e);
229
+ const t = W(e);
240
230
  t && (e.preventDefault(), e.stopPropagation(), t.focus());
241
231
  },
242
232
  "keydown.enter": (e) => {
243
233
  if (e.target instanceof HTMLTableCellElement) {
244
234
  e.preventDefault(), e.stopPropagation();
245
- const r = x(e);
246
- r && r.focus();
235
+ const n = D(e);
236
+ n && n.focus();
247
237
  }
248
238
  },
249
239
  "keydown.shift.enter": (e) => {
250
240
  if (e.target instanceof HTMLTableCellElement) {
251
241
  e.preventDefault(), e.stopPropagation();
252
- const r = A(e);
253
- r && r.focus();
242
+ const n = x(e);
243
+ n && n.focus();
254
244
  }
255
245
  },
256
246
  "keydown.home": (e) => {
257
- const t = L(e);
247
+ const t = K(e);
258
248
  t && (e.preventDefault(), e.stopPropagation(), t.focus());
259
249
  },
260
250
  "keydown.tab": (e) => {
261
- const t = S(e);
251
+ const t = P(e);
262
252
  t && (e.preventDefault(), e.stopPropagation(), t.focus());
263
253
  },
264
254
  "keydown.shift.tab": (e) => {
265
- const t = k(e);
255
+ const t = R(e);
266
256
  t && (e.preventDefault(), e.stopPropagation(), t.focus());
267
257
  }
268
258
  };
269
- function ie(e) {
270
- const t = (n) => {
271
- let o = null;
272
- n.parent && (typeof n.parent == "string" ? o = document.querySelector(n.parent) : n.parent instanceof Element ? o = n.parent : o = n.parent.value);
273
- let l = [];
274
- if (n.selectors)
275
- if (typeof n.selectors == "string")
276
- l = o ? Array.from(o.querySelectorAll(n.selectors)) : Array.from(document.querySelectorAll(n.selectors));
277
- else if (n.selectors instanceof Element)
278
- l.push(n.selectors);
279
- else if (Array.isArray(n.selectors.value))
280
- for (const s of n.selectors.value)
281
- s instanceof Element ? l.push(s) : l.push(s.$el);
282
- else
283
- l.push(n.selectors.value);
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);
284
276
  else
285
- l = Array.from(o.children).filter((a) => u(a) && f(a));
286
- return l;
287
- }, r = (n) => (o) => {
288
- const l = oe[o.key] || o.key.toLowerCase();
289
- if (m.includes(l))
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))
290
286
  return;
291
- const s = n.handlers || le;
292
- for (const a of Object.keys(s)) {
293
- const [C, ...d] = a.split(".");
294
- if (C === "keydown" && d.includes(l)) {
295
- const c = s[a], g = d.filter((i) => m.includes(i)), p = m.some((i) => {
296
- const $ = i.charAt(0).toUpperCase() + i.slice(1);
297
- return o.getModifierState($);
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);
298
294
  });
299
- if (g.length > 0) {
300
- if (p) {
301
- for (const i of m)
302
- if (d.includes(i)) {
303
- const $ = i.charAt(0).toUpperCase() + i.slice(1);
304
- o.getModifierState($) && c(o);
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);
305
301
  }
306
302
  }
307
303
  } else
308
- p || c(o);
304
+ H || d(r);
309
305
  }
310
306
  }
311
- };
312
- W(() => {
313
- for (const n of e) {
314
- const o = t(n);
315
- for (const l of o)
316
- l.addEventListener("keydown", r(n));
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
317
  }
318
318
  }), V(() => {
319
- for (const n of e) {
320
- const o = t(n);
321
- for (const l of o)
322
- l.removeEventListener("keydown", r(n));
323
- }
319
+ for (const o of i)
320
+ o();
324
321
  });
325
322
  }
326
- function ae(e) {
323
+ function le(e) {
327
324
  }
328
325
  export {
329
- le as defaultKeypressHandlers,
330
- ae as install,
331
- ie as useKeyboardNav
326
+ ee as defaultKeypressHandlers,
327
+ le as install,
328
+ ne as useKeyboardNav
332
329
  };
333
330
  //# sourceMappingURL=utilities.js.map