@untemps/react-vocal 2.0.0-beta.7 → 2.0.0-beta.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.
package/dist/index.es.js CHANGED
@@ -3,661 +3,19 @@ import { cloneElement as e, isValidElement as t, useCallback as n, useEffect as
3
3
  var s = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), c = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
4
4
  if (typeof require < "u") return require.apply(this, arguments);
5
5
  throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
6
- }), l = function(e, t, n) {
7
- return e(n = {
8
- path: t,
9
- exports: {},
10
- require: function(e, t) {
11
- return function() {
12
- throw Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs");
13
- }(t == null && n.path);
14
- }
15
- }, n.exports), n.exports;
16
- }((function(e) {
17
- var t = function(e) {
18
- var t = Object.prototype, n = t.hasOwnProperty, r = typeof Symbol == "function" ? Symbol : {}, i = r.iterator || "@@iterator", a = r.asyncIterator || "@@asyncIterator", o = r.toStringTag || "@@toStringTag";
19
- function s(e, t, n) {
20
- return Object.defineProperty(e, t, {
21
- value: n,
22
- enumerable: !0,
23
- configurable: !0,
24
- writable: !0
25
- }), e[t];
26
- }
27
- try {
28
- s({}, "");
29
- } catch {
30
- s = function(e, t, n) {
31
- return e[t] = n;
32
- };
33
- }
34
- function c(e, t, n, r) {
35
- var i = t && t.prototype instanceof d ? t : d, a = Object.create(i.prototype);
36
- return a._invoke = function(e, t, n) {
37
- var r = "suspendedStart";
38
- return function(i, a) {
39
- if (r === "executing") throw Error("Generator is already running");
40
- if (r === "completed") {
41
- if (i === "throw") throw a;
42
- return T();
43
- }
44
- for (n.method = i, n.arg = a;;) {
45
- var o = n.delegate;
46
- if (o) {
47
- var s = b(o, n);
48
- if (s) {
49
- if (s === u) continue;
50
- return s;
51
- }
52
- }
53
- if (n.method === "next") n.sent = n._sent = n.arg;
54
- else if (n.method === "throw") {
55
- if (r === "suspendedStart") throw r = "completed", n.arg;
56
- n.dispatchException(n.arg);
57
- } else n.method === "return" && n.abrupt("return", n.arg);
58
- r = "executing";
59
- var c = l(e, t, n);
60
- if (c.type === "normal") {
61
- if (r = n.done ? "completed" : "suspendedYield", c.arg === u) continue;
62
- return {
63
- value: c.arg,
64
- done: n.done
65
- };
66
- }
67
- c.type === "throw" && (r = "completed", n.method = "throw", n.arg = c.arg);
68
- }
69
- };
70
- }(e, n, new C(r || [])), a;
71
- }
72
- function l(e, t, n) {
73
- try {
74
- return {
75
- type: "normal",
76
- arg: e.call(t, n)
77
- };
78
- } catch (e) {
79
- return {
80
- type: "throw",
81
- arg: e
82
- };
83
- }
84
- }
85
- e.wrap = c;
86
- var u = {};
87
- function d() {}
88
- function f() {}
89
- function p() {}
90
- var m = {};
91
- m[i] = function() {
92
- return this;
93
- };
94
- var h = Object.getPrototypeOf, g = h && h(h(w([])));
95
- g && g !== t && n.call(g, i) && (m = g);
96
- var _ = p.prototype = d.prototype = Object.create(m);
97
- function v(e) {
98
- [
99
- "next",
100
- "throw",
101
- "return"
102
- ].forEach((function(t) {
103
- s(e, t, (function(e) {
104
- return this._invoke(t, e);
105
- }));
106
- }));
107
- }
108
- function y(e, t) {
109
- var r;
110
- this._invoke = function(i, a) {
111
- function o() {
112
- return new t((function(r, o) {
113
- (function r(i, a, o, s) {
114
- var c = l(e[i], e, a);
115
- if (c.type !== "throw") {
116
- var u = c.arg, d = u.value;
117
- return d && typeof d == "object" && n.call(d, "__await") ? t.resolve(d.__await).then((function(e) {
118
- r("next", e, o, s);
119
- }), (function(e) {
120
- r("throw", e, o, s);
121
- })) : t.resolve(d).then((function(e) {
122
- u.value = e, o(u);
123
- }), (function(e) {
124
- return r("throw", e, o, s);
125
- }));
126
- }
127
- s(c.arg);
128
- })(i, a, r, o);
129
- }));
130
- }
131
- return r = r ? r.then(o, o) : o();
132
- };
133
- }
134
- function b(e, t) {
135
- var n = e.iterator[t.method];
136
- if (n === void 0) {
137
- if (t.delegate = null, t.method === "throw") {
138
- if (e.iterator.return && (t.method = "return", t.arg = void 0, b(e, t), t.method === "throw")) return u;
139
- t.method = "throw", t.arg = /* @__PURE__ */ TypeError("The iterator does not provide a 'throw' method");
140
- }
141
- return u;
142
- }
143
- var r = l(n, e.iterator, t.arg);
144
- if (r.type === "throw") return t.method = "throw", t.arg = r.arg, t.delegate = null, u;
145
- var i = r.arg;
146
- return i ? i.done ? (t[e.resultName] = i.value, t.next = e.nextLoc, t.method !== "return" && (t.method = "next", t.arg = void 0), t.delegate = null, u) : i : (t.method = "throw", t.arg = /* @__PURE__ */ TypeError("iterator result is not an object"), t.delegate = null, u);
147
- }
148
- function x(e) {
149
- var t = { tryLoc: e[0] };
150
- 1 in e && (t.catchLoc = e[1]), 2 in e && (t.finallyLoc = e[2], t.afterLoc = e[3]), this.tryEntries.push(t);
151
- }
152
- function S(e) {
153
- var t = e.completion || {};
154
- t.type = "normal", delete t.arg, e.completion = t;
155
- }
156
- function C(e) {
157
- this.tryEntries = [{ tryLoc: "root" }], e.forEach(x, this), this.reset(!0);
158
- }
159
- function w(e) {
160
- if (e) {
161
- var t = e[i];
162
- if (t) return t.call(e);
163
- if (typeof e.next == "function") return e;
164
- if (!isNaN(e.length)) {
165
- var r = -1, a = function t() {
166
- for (; ++r < e.length;) if (n.call(e, r)) return t.value = e[r], t.done = !1, t;
167
- return t.value = void 0, t.done = !0, t;
168
- };
169
- return a.next = a;
170
- }
171
- }
172
- return { next: T };
173
- }
174
- function T() {
175
- return {
176
- value: void 0,
177
- done: !0
178
- };
179
- }
180
- return f.prototype = _.constructor = p, p.constructor = f, f.displayName = s(p, o, "GeneratorFunction"), e.isGeneratorFunction = function(e) {
181
- var t = typeof e == "function" && e.constructor;
182
- return !!t && (t === f || (t.displayName || t.name) === "GeneratorFunction");
183
- }, e.mark = function(e) {
184
- return Object.setPrototypeOf ? Object.setPrototypeOf(e, p) : (e.__proto__ = p, s(e, o, "GeneratorFunction")), e.prototype = Object.create(_), e;
185
- }, e.awrap = function(e) {
186
- return { __await: e };
187
- }, v(y.prototype), y.prototype[a] = function() {
188
- return this;
189
- }, e.AsyncIterator = y, e.async = function(t, n, r, i, a) {
190
- a === void 0 && (a = Promise);
191
- var o = new y(c(t, n, r, i), a);
192
- return e.isGeneratorFunction(n) ? o : o.next().then((function(e) {
193
- return e.done ? e.value : o.next();
194
- }));
195
- }, v(_), s(_, o, "Generator"), _[i] = function() {
196
- return this;
197
- }, _.toString = function() {
198
- return "[object Generator]";
199
- }, e.keys = function(e) {
200
- var t = [];
201
- for (var n in e) t.push(n);
202
- return t.reverse(), function n() {
203
- for (; t.length;) {
204
- var r = t.pop();
205
- if (r in e) return n.value = r, n.done = !1, n;
206
- }
207
- return n.done = !0, n;
208
- };
209
- }, e.values = w, C.prototype = {
210
- constructor: C,
211
- reset: function(e) {
212
- if (this.prev = 0, this.next = 0, this.sent = this._sent = void 0, this.done = !1, this.delegate = null, this.method = "next", this.arg = void 0, this.tryEntries.forEach(S), !e) for (var t in this) t.charAt(0) === "t" && n.call(this, t) && !isNaN(+t.slice(1)) && (this[t] = void 0);
213
- },
214
- stop: function() {
215
- this.done = !0;
216
- var e = this.tryEntries[0].completion;
217
- if (e.type === "throw") throw e.arg;
218
- return this.rval;
219
- },
220
- dispatchException: function(e) {
221
- if (this.done) throw e;
222
- var t = this;
223
- function r(n, r) {
224
- return o.type = "throw", o.arg = e, t.next = n, r && (t.method = "next", t.arg = void 0), !!r;
225
- }
226
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
227
- var a = this.tryEntries[i], o = a.completion;
228
- if (a.tryLoc === "root") return r("end");
229
- if (a.tryLoc <= this.prev) {
230
- var s = n.call(a, "catchLoc"), c = n.call(a, "finallyLoc");
231
- if (s && c) {
232
- if (this.prev < a.catchLoc) return r(a.catchLoc, !0);
233
- if (this.prev < a.finallyLoc) return r(a.finallyLoc);
234
- } else if (s) {
235
- if (this.prev < a.catchLoc) return r(a.catchLoc, !0);
236
- } else {
237
- if (!c) throw Error("try statement without catch or finally");
238
- if (this.prev < a.finallyLoc) return r(a.finallyLoc);
239
- }
240
- }
241
- }
242
- },
243
- abrupt: function(e, t) {
244
- for (var r = this.tryEntries.length - 1; r >= 0; --r) {
245
- var i = this.tryEntries[r];
246
- if (i.tryLoc <= this.prev && n.call(i, "finallyLoc") && this.prev < i.finallyLoc) {
247
- var a = i;
248
- break;
249
- }
250
- }
251
- a && (e === "break" || e === "continue") && a.tryLoc <= t && t <= a.finallyLoc && (a = null);
252
- var o = a ? a.completion : {};
253
- return o.type = e, o.arg = t, a ? (this.method = "next", this.next = a.finallyLoc, u) : this.complete(o);
254
- },
255
- complete: function(e, t) {
256
- if (e.type === "throw") throw e.arg;
257
- return e.type === "break" || e.type === "continue" ? this.next = e.arg : e.type === "return" ? (this.rval = this.arg = e.arg, this.method = "return", this.next = "end") : e.type === "normal" && t && (this.next = t), u;
258
- },
259
- finish: function(e) {
260
- for (var t = this.tryEntries.length - 1; t >= 0; --t) {
261
- var n = this.tryEntries[t];
262
- if (n.finallyLoc === e) return this.complete(n.completion, n.afterLoc), S(n), u;
263
- }
264
- },
265
- catch: function(e) {
266
- for (var t = this.tryEntries.length - 1; t >= 0; --t) {
267
- var n = this.tryEntries[t];
268
- if (n.tryLoc === e) {
269
- var r = n.completion;
270
- if (r.type === "throw") {
271
- var i = r.arg;
272
- S(n);
273
- }
274
- return i;
275
- }
276
- }
277
- throw Error("illegal catch attempt");
278
- },
279
- delegateYield: function(e, t, n) {
280
- return this.delegate = {
281
- iterator: w(e),
282
- resultName: t,
283
- nextLoc: n
284
- }, this.method === "next" && (this.arg = void 0), u;
285
- }
286
- }, e;
287
- }(e.exports);
288
- try {
289
- regeneratorRuntime = t;
290
- } catch {
291
- Function("r", "regeneratorRuntime = r")(t);
292
- }
293
- }));
294
- function u(e, t, n, r, i, a, o) {
295
- try {
296
- var s = e[a](o), c = s.value;
297
- } catch (e) {
298
- n(e);
299
- return;
300
- }
301
- s.done ? t(c) : Promise.resolve(c).then(r, i);
302
- }
303
- var d = function(e) {
304
- return function() {
305
- var t = this, n = arguments;
306
- return new Promise((function(r, i) {
307
- var a = e.apply(t, n);
308
- function o(e) {
309
- u(a, r, i, o, s, "next", e);
310
- }
311
- function s(e) {
312
- u(a, r, i, o, s, "throw", e);
313
- }
314
- o(void 0);
315
- }));
316
- };
317
- }, f = function(e) {
318
- if (Array.isArray(e)) return e;
319
- }, p = function(e, t) {
320
- if (typeof Symbol < "u" && Symbol.iterator in Object(e)) {
321
- var n = [], r = !0, i = !1, a = void 0;
322
- try {
323
- for (var o, s = e[Symbol.iterator](); !(r = (o = s.next()).done) && (n.push(o.value), !t || n.length !== t); r = !0);
324
- } catch (e) {
325
- i = !0, a = e;
326
- } finally {
327
- try {
328
- r || s.return == null || s.return();
329
- } finally {
330
- if (i) throw a;
331
- }
332
- }
333
- return n;
334
- }
335
- }, m = function(e, t) {
336
- (t == null || t > e.length) && (t = e.length);
337
- for (var n = 0, r = Array(t); n < t; n++) r[n] = e[n];
338
- return r;
339
- }, h = function(e, t) {
340
- if (e) {
341
- if (typeof e == "string") return m(e, t);
342
- var n = Object.prototype.toString.call(e).slice(8, -1);
343
- return n === "Object" && e.constructor && (n = e.constructor.name), n === "Map" || n === "Set" ? Array.from(e) : n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n) ? m(e, t) : void 0;
344
- }
345
- }, g = function() {
346
- throw TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
347
- }, _ = function(e, t) {
348
- return f(e) || p(e, t) || h(e, t) || g();
349
- }, v = function(e, t) {
350
- if (!(e instanceof t)) throw TypeError("Cannot call a class as a function");
351
- };
352
- function y(e, t) {
353
- for (var n = 0; n < t.length; n++) {
354
- var r = t[n];
355
- r.enumerable = r.enumerable || !1, r.configurable = !0, "value" in r && (r.writable = !0), Object.defineProperty(e, r.key, r);
356
- }
357
- }
358
- var b = function(e, t, n) {
359
- return t && y(e.prototype, t), n && y(e, n), e;
360
- }, x = function(e, t, n) {
361
- return t in e ? Object.defineProperty(e, t, {
362
- value: n,
363
- enumerable: !0,
364
- configurable: !0,
365
- writable: !0
366
- }) : e[t] = n, e;
367
- }, S = function() {
368
- return !!navigator.permissions;
369
- }, C = function() {
370
- return !!navigator.mediaDevices;
371
- };
372
- function w(e, t, n, r, i, a, o) {
373
- try {
374
- var s = e[a](o), c = s.value;
375
- } catch (e) {
376
- n(e);
377
- return;
378
- }
379
- s.done ? t(c) : Promise.resolve(c).then(r, i);
380
- }
381
- function T(e) {
382
- return function() {
383
- var t = this, n = arguments;
384
- return new Promise((function(r, i) {
385
- var a = e.apply(t, n);
386
- function o(e) {
387
- w(a, r, i, o, s, "next", e);
388
- }
389
- function s(e) {
390
- w(a, r, i, o, s, "throw", e);
391
- }
392
- o(void 0);
393
- }));
394
- };
395
- }
396
- function E(e, t) {
397
- return function(e) {
398
- if (Array.isArray(e)) return e;
399
- }(e) || function(e, t) {
400
- if (typeof Symbol < "u" && Symbol.iterator in Object(e)) {
401
- var n = [], r = !0, i = !1, a = void 0;
402
- try {
403
- for (var o, s = e[Symbol.iterator](); !(r = (o = s.next()).done) && (n.push(o.value), !t || n.length !== t); r = !0);
404
- } catch (e) {
405
- i = !0, a = e;
406
- } finally {
407
- try {
408
- r || s.return == null || s.return();
409
- } finally {
410
- if (i) throw a;
411
- }
412
- }
413
- return n;
414
- }
415
- }(e, t) || function(e, t) {
416
- if (e) {
417
- if (typeof e == "string") return D(e, t);
418
- var n = Object.prototype.toString.call(e).slice(8, -1);
419
- return n === "Object" && e.constructor && (n = e.constructor.name), n === "Map" || n === "Set" ? Array.from(e) : n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n) ? D(e, t) : void 0;
420
- }
421
- }(e, t) || function() {
422
- throw TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
423
- }();
424
- }
425
- function D(e, t) {
426
- (t == null || t > e.length) && (t = e.length);
427
- for (var n = 0, r = Array(t); n < t; n++) r[n] = e[n];
428
- return r;
429
- }
430
- var O = function() {
431
- var e = T(regeneratorRuntime.mark((function e(t) {
432
- return regeneratorRuntime.wrap((function(e) {
433
- for (;;) switch (e.prev = e.next) {
434
- case 0: return e.abrupt("return", new Promise(function() {
435
- var e = T(regeneratorRuntime.mark((function e(n, r) {
436
- var i, a;
437
- return regeneratorRuntime.wrap((function(e) {
438
- for (;;) switch (e.prev = e.next) {
439
- case 0: return S() || r(new DOMException("Navigator API: permissions not supported", "NOT_SUPPORTED_ERR")), e.prev = 1, e.next = 4, navigator.permissions.query({ name: t });
440
- case 4:
441
- i = e.sent, a = function e(t) {
442
- i.removeEventListener("change", e), k(t.target.state, n, r);
443
- }, i.addEventListener("change", a), k(i.state, n, r), e.next = 13;
444
- break;
445
- case 10: e.prev = 10, e.t0 = e.catch(1), r(e.t0);
446
- case 13:
447
- case "end": return e.stop();
448
- }
449
- }), e, null, [[1, 10]]);
450
- })));
451
- return function(t, n) {
452
- return e.apply(this, arguments);
453
- };
454
- }()));
455
- case 1:
456
- case "end": return e.stop();
457
- }
458
- }), e);
459
- })));
460
- return function(t) {
461
- return e.apply(this, arguments);
462
- };
463
- }(), k = function(e, t, n) {
464
- switch (e) {
465
- case "denied":
466
- n(new DOMException("Permission denied", "NOT_ALLOWED_ERR"));
467
- break;
468
- default: t(e);
469
- }
470
- }, A = function() {
471
- var e = T(regeneratorRuntime.mark((function e(t, n) {
472
- return regeneratorRuntime.wrap((function(e) {
473
- for (;;) switch (e.prev = e.next) {
474
- case 0: return e.abrupt("return", new Promise(function() {
475
- var e = T(regeneratorRuntime.mark((function e(r, i) {
476
- var a, o, s;
477
- return regeneratorRuntime.wrap((function(e) {
478
- for (;;) switch (e.prev = e.next) {
479
- case 0: return S() && C() || i(new DOMException("Navigator API: permissions or Navigator API: mediaDevices not supported", "NOT_SUPPORTED_ERR")), e.prev = 1, e.t0 = Promise, e.next = 5, O(t);
480
- case 5: return e.t1 = e.sent, e.next = 8, navigator.mediaDevices.getUserMedia(n);
481
- case 8: return e.t2 = e.sent, e.t3 = [e.t1, e.t2], e.next = 12, e.t0.all.call(e.t0, e.t3);
482
- case 12:
483
- a = e.sent, o = E(a, 2), s = o[1], r(s), e.next = 21;
484
- break;
485
- case 18: e.prev = 18, e.t4 = e.catch(1), i(e.t4);
486
- case 21:
487
- case "end": return e.stop();
488
- }
489
- }), e, null, [[1, 18]]);
490
- })));
491
- return function(t, n) {
492
- return e.apply(this, arguments);
493
- };
494
- }()));
495
- case 1:
496
- case "end": return e.stop();
497
- }
498
- }), e);
499
- })));
500
- return function(t, n) {
501
- return e.apply(this, arguments);
502
- };
503
- }();
504
- function j(e, t) {
505
- var n = Object.keys(e);
506
- if (Object.getOwnPropertySymbols) {
507
- var r = Object.getOwnPropertySymbols(e);
508
- t && (r = r.filter((function(t) {
509
- return Object.getOwnPropertyDescriptor(e, t).enumerable;
510
- }))), n.push.apply(n, r);
511
- }
512
- return n;
513
- }
514
- function M(e) {
515
- for (var t = 1; t < arguments.length; t++) {
516
- var n = arguments[t] == null ? {} : arguments[t];
517
- t % 2 ? j(Object(n), !0).forEach((function(t) {
518
- x(e, t, n[t]);
519
- })) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) : j(Object(n)).forEach((function(t) {
520
- Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(n, t));
521
- }));
522
- }
523
- return e;
524
- }
525
- var N = function() {
526
- function e(t) {
527
- var n = this;
528
- v(this, e), x(this, "_instance", null), x(this, "_listeners", null);
529
- var r = e._resolveSpeechRecognition();
530
- if (!r) throw new DOMException("SpeechRecognition not supported", "NOT_SUPPORTED_ERR");
531
- this._instance = new r(), this._listeners = {}, Object.entries(M(M({}, e.defaultOptions), t || {})).forEach((function(t) {
532
- var r = _(t, 2), i = r[0], a = r[1];
533
- if (i === "grammars" && !a) {
534
- var o = e._resolveSpeechGrammarList();
535
- o && (a = new o());
536
- }
537
- n._instance[i] = a;
538
- }));
539
- }
540
- var t;
541
- return b(e, null, [{
542
- key: "isSupported",
543
- get: function() {
544
- return !!e._resolveSpeechRecognition() && !!S() && !!C();
545
- },
546
- set: function(e) {
547
- throw Error("You cannot set isSupported directly.");
548
- }
549
- }]), b(e, [
550
- {
551
- key: "start",
552
- value: (t = d(l.mark((function e() {
553
- var t;
554
- return l.wrap((function(e) {
555
- for (;;) switch (e.prev = e.next) {
556
- case 0:
557
- if (!this._instance) {
558
- e.next = 14;
559
- break;
560
- }
561
- return e.prev = 1, e.next = 4, A("microphone", { audio: !0 });
562
- case 4:
563
- if (e.sent) {
564
- e.next = 7;
565
- break;
566
- }
567
- throw Error("Unable to retrieve the stream from media device");
568
- case 7:
569
- this._instance.start(), e.next = 14;
570
- break;
571
- case 10: e.prev = 10, e.t0 = e.catch(1), (t = this._listeners.error) && t(e.t0);
572
- case 14: return e.abrupt("return", this);
573
- case 15:
574
- case "end": return e.stop();
575
- }
576
- }), e, this, [[1, 10]]);
577
- }))), function() {
578
- return t.apply(this, arguments);
579
- })
580
- },
581
- {
582
- key: "stop",
583
- value: function() {
584
- return this._instance && this._instance.stop(), this;
585
- }
586
- },
587
- {
588
- key: "abort",
589
- value: function() {
590
- return this._instance && this._instance.abort(), this;
591
- }
592
- },
593
- {
594
- key: "addEventListener",
595
- value: function(t, n) {
596
- var r = this;
597
- if (this._instance && this._includesEventType(t)) {
598
- this._listeners[t] && this.removeEventListener(t);
599
- var i = function(i) {
600
- var a = [];
601
- t === e.eventTypes.RESULT && i.results && i.results.length > 0 && a.push(i.results[0][0].transcript), n && n.apply(r, [i].concat(a));
602
- };
603
- this._instance.addEventListener(t, i), this._listeners[t] = i;
604
- }
605
- return this;
606
- }
607
- },
608
- {
609
- key: "removeEventListener",
610
- value: function(e) {
611
- var t = this._listeners[e];
612
- return this._instance.removeEventListener(e, t), delete this._listeners[e], this;
613
- }
614
- },
615
- {
616
- key: "cleanup",
617
- value: function() {
618
- var e = this;
619
- return this.stop(), Object.keys(this._listeners).forEach((function(t) {
620
- return e.removeEventListener(t);
621
- })), this._instance = null, this;
622
- }
623
- },
624
- {
625
- key: "_includesEventType",
626
- value: function(t) {
627
- return !!Object.values(e.eventTypes).find((function(e) {
628
- return e === t;
629
- }));
630
- }
631
- },
632
- {
633
- key: "instance",
634
- get: function() {
635
- return this._instance;
636
- },
637
- set: function(e) {
638
- throw Error("You cannot set instance directly.");
639
- }
640
- }
641
- ], [{
642
- key: "_resolveSpeechRecognition",
643
- value: function() {
644
- return window.SpeechRecognition || window.webkitSpeechRecognition || window.mozSpeechRecognition || window.msSpeechRecognition;
645
- }
646
- }, {
647
- key: "_resolveSpeechGrammarList",
648
- value: function() {
649
- return window.SpeechGrammarList || window.webkitSpeechGrammarList || window.mozSpeechGrammarList || window.msSpeechGrammarList;
650
- }
651
- }]), e;
652
- }();
653
- x(N, "defaultOptions", {
654
- grammars: null,
655
- lang: "en-US",
656
- continuous: !1,
657
- interimResults: !1,
658
- maxAlternatives: 1,
659
- serviceURI: null
660
- }), x(N, "eventTypes", {
6
+ }), l = () => !!navigator.permissions, u = () => !!navigator.mediaDevices, d = async (e, t, { signal: n } = {}) => {
7
+ if (!l() || !u()) throw new DOMException("Navigator API: permissions or Navigator API: mediaDevices not supported", "NOT_SUPPORTED_ERR");
8
+ if (n?.throwIfAborted(), (await navigator.permissions.query({ name: e })).state === "denied") throw new DOMException("Permission denied", "NOT_ALLOWED_ERR");
9
+ n?.throwIfAborted();
10
+ let r = navigator.mediaDevices.getUserMedia(t);
11
+ if (!n) return r;
12
+ let i, a = new Promise((e, t) => {
13
+ i = () => t(n.reason), n.addEventListener("abort", i, { once: !0 });
14
+ });
15
+ return Promise.race([r, a]).finally(() => {
16
+ n.removeEventListener("abort", i);
17
+ });
18
+ }, f = {
661
19
  AUDIO_END: "audioend",
662
20
  AUDIO_START: "audiostart",
663
21
  END: "end",
@@ -669,47 +27,181 @@ x(N, "defaultOptions", {
669
27
  SPEECH_END: "speechend",
670
28
  SPEECH_START: "speechstart",
671
29
  START: "start"
672
- });
673
- //#endregion
674
- //#region node_modules/@untemps/utils/dist/function/isFunction.js
675
- var P = (e) => typeof e == "function", F = (e = "en-US", t = null, i = 1, o = !1, s = null) => {
676
- let c = a(null);
677
- return r(() => {
678
- if (N.isSupported) return c.current = s || new N({
679
- lang: e,
680
- grammars: t,
681
- maxAlternatives: i,
682
- continuous: o
683
- }), () => {
684
- c.current.abort(), c.current.cleanup();
30
+ }, p = 1e3, m = new Set([
31
+ "not-allowed",
32
+ "service-not-allowed",
33
+ "audio-capture"
34
+ ]), h = {
35
+ grammars: null,
36
+ lang: "en-US",
37
+ continuous: !1,
38
+ interimResults: !1,
39
+ maxAlternatives: 1
40
+ }, g = () => {
41
+ if (!(typeof window > "u")) return window.SpeechRecognition ?? window.webkitSpeechRecognition ?? window.mozSpeechRecognition ?? window.msSpeechRecognition;
42
+ }, _ = () => window.SpeechGrammarList ?? window.webkitSpeechGrammarList ?? window.mozSpeechGrammarList ?? window.msSpeechGrammarList, v = (e) => e.reduce((e, t) => (t.confidence ?? 0) > (e.confidence ?? 0) ? t : e), y = (e) => {
43
+ let t = e.slice();
44
+ return Object.defineProperty(t, "isFinal", { value: !0 }), Object.defineProperty(t, "item", { value: (e) => t[e] }), t;
45
+ }, b = (e) => {
46
+ let t = e.slice();
47
+ return Object.defineProperty(t, "item", { value: (e) => t[e] }), t;
48
+ }, x = (e) => Object.values(f).includes(e), S = (e) => `Unknown event type "${e}". Valid types are: ${Object.values(f).join(", ")}.`, C = () => !!g() && !!l() && !!u(), w = (e) => {
49
+ let t = g();
50
+ if (!t) throw new DOMException("SpeechRecognition not supported", "NOT_SUPPORTED_ERR");
51
+ let n = new t(), r = {}, i = !1, a = !1, o = 0, s = null, c = !1, l = [], u = {
52
+ ...h,
53
+ ...e ?? {}
54
+ };
55
+ if (n.lang = u.lang, n.continuous = u.continuous, n.interimResults = u.interimResults, n.maxAlternatives = u.maxAlternatives, u.grammars) n.grammars = u.grammars;
56
+ else {
57
+ let e = _();
58
+ n.grammars = e ? new e() : null;
59
+ }
60
+ let C = () => {
61
+ s !== null && (clearTimeout(s), s = null), c = !1;
62
+ }, w = () => !!n && !a && n.continuous, T = () => {
63
+ s = null;
64
+ try {
65
+ n.start(), o = Date.now();
66
+ } catch {
67
+ c = !1, i = !1;
68
+ }
69
+ }, E = () => {
70
+ let e = l;
71
+ if (l = [], e.length === 0 || !r[f.RESULT]?.length) return;
72
+ let t = e.map((e) => v(Array.from(e)).transcript).join(" ").trim(), n = Object.assign(new Event(f.RESULT), {
73
+ resultIndex: 0,
74
+ results: b(e)
75
+ });
76
+ [...r[f.RESULT]].forEach(({ callback: e }) => {
77
+ e(n, t, [t]);
78
+ });
79
+ }, D = [
80
+ [f.END, (e) => {
81
+ if (w()) {
82
+ let t = Math.max(0, p - (Date.now() - o));
83
+ c = !0, s = setTimeout(T, t), e.stopImmediatePropagation();
84
+ return;
85
+ }
86
+ E(), i = !1;
87
+ }],
88
+ [f.START, (e) => {
89
+ c && (e.stopImmediatePropagation(), queueMicrotask(() => {
90
+ c = !1;
91
+ }));
92
+ }],
93
+ [f.ERROR, (e) => {
94
+ m.has(e.error) && (a = !0, C(), i = !1);
95
+ }],
96
+ [f.RESULT, (e) => {
97
+ if (!u.continuous) return;
98
+ let t = e, n = t.results?.[t.resultIndex];
99
+ n?.isFinal && l.push(y(Array.from(n)));
100
+ }]
101
+ ];
102
+ D.forEach(([e, t]) => n.addEventListener(e, t));
103
+ let O = async ({ signal: e } = {}) => {
104
+ if (n) try {
105
+ let t = await d("microphone", { audio: !0 }, { signal: e });
106
+ if (e?.aborted || !n) return;
107
+ if (!t) throw Error("Unable to retrieve the stream from media device");
108
+ a = !1, l = [], n.start(), i = !0, o = Date.now();
109
+ } catch (e) {
110
+ if (e instanceof Error && e.name === "AbortError") return;
111
+ throw e;
112
+ }
113
+ }, k = () => {
114
+ n && (a = !0, C(), n.stop(), i = !1);
115
+ }, A = () => {
116
+ n && (a = !0, C(), l = [], n.abort(), i = !1);
117
+ }, j = (e, t) => {
118
+ if (!x(e)) throw Error(S(e));
119
+ if (!n) return;
120
+ let i = (n) => {
121
+ if (c && (e === f.END || e === f.START)) return;
122
+ if (e !== f.RESULT) {
123
+ t(n);
124
+ return;
125
+ }
126
+ let r = n;
127
+ if (!(r.results?.length > 0) || r.resultIndex >= r.results.length) {
128
+ t(n);
129
+ return;
130
+ }
131
+ let i = r.results[r.resultIndex];
132
+ if (u.continuous && i.isFinal) return;
133
+ let a = Array.from(i);
134
+ t(n, v(a).transcript, a.map((e) => e.transcript));
685
135
  };
136
+ n.addEventListener(e, i), r[e] || (r[e] = []), r[e].push({
137
+ callback: t,
138
+ handler: i
139
+ });
140
+ }, M = (e, t) => {
141
+ if (!x(e)) throw Error(S(e));
142
+ if (!(!n || !r[e])) if (t !== void 0) {
143
+ let i = r[e].findIndex((e) => e.callback === t);
144
+ i !== -1 && (n.removeEventListener(e, r[e][i].handler), r[e].splice(i, 1), r[e].length === 0 && delete r[e]);
145
+ } else r[e].forEach(({ handler: t }) => n.removeEventListener(e, t)), delete r[e];
146
+ };
147
+ return {
148
+ get isRecording() {
149
+ return i;
150
+ },
151
+ start: O,
152
+ stop: k,
153
+ abort: A,
154
+ on: j,
155
+ off: M,
156
+ cleanup: () => {
157
+ k(), Object.keys(r).forEach((e) => M(e)), D.forEach(([e, t]) => n?.removeEventListener(e, t)), n = null;
158
+ }
159
+ };
160
+ }, T = (e) => typeof e == "function", E = (e = "en-US", t = null, s = 1, c = !1, l = null) => {
161
+ let u = a(null), [d, f] = o(!1), p = i(() => C(), []);
162
+ return r(() => {
163
+ if (p) {
164
+ let n = l || w({
165
+ lang: e,
166
+ grammars: t,
167
+ maxAlternatives: s,
168
+ continuous: c
169
+ });
170
+ u.current = n;
171
+ let r = () => f(!0), i = () => f(!1);
172
+ return n.on("start", r), n.on("end", i), n.on("error", i), () => {
173
+ n.off("start", r), n.off("end", i), n.off("error", i), n.abort(), n.cleanup(), f(!1);
174
+ };
175
+ }
686
176
  }, [
687
177
  e,
688
178
  t,
689
- i,
690
- o,
691
- s
692
- ]), [c, {
693
- start: n(() => {
694
- c.current && c.current.start();
179
+ s,
180
+ c,
181
+ l,
182
+ p
183
+ ]), [u, {
184
+ start: n((e) => {
185
+ if (u.current) return f(!0), u.current.start(e);
695
186
  }, []),
696
187
  stop: n(() => {
697
- c.current && c.current.stop();
188
+ u.current && u.current.stop();
698
189
  }, []),
699
190
  abort: n(() => {
700
- c.current && c.current.abort();
191
+ u.current && u.current.abort();
701
192
  }, []),
702
193
  subscribe: n((e, t) => {
703
- c.current && c.current.addEventListener(e, t);
194
+ u.current && u.current.on(e, t);
704
195
  }, []),
705
196
  unsubscribe: n((e, t) => {
706
- c.current && c.current.removeEventListener(e, t);
197
+ u.current && u.current.off(e, t);
707
198
  }, []),
708
199
  clean: n(() => {
709
- c.current && c.current.cleanup();
710
- }, [])
200
+ u.current && u.current.cleanup();
201
+ }, []),
202
+ isRecording: d
711
203
  }];
712
- }, I = (e, t = 0) => {
204
+ }, D = (e, t = 0) => {
713
205
  let i = a(-1), o = n(() => {
714
206
  clearTimeout(i.current), i.current = -1;
715
207
  }, []), s = n(() => {
@@ -720,7 +212,7 @@ var P = (e) => typeof e == "function", F = (e = "en-US", t = null, i = 1, o = !1
720
212
  o
721
213
  ]);
722
214
  return r(() => o, [o]), [s, o];
723
- }, L = (e, t = .4) => {
215
+ }, O = (e, t = .4) => {
724
216
  let n = i(() => e ? Object.entries(e).reduce((e, [t, n]) => ({
725
217
  ...e,
726
218
  [t.toLowerCase()]: n
@@ -761,7 +253,7 @@ var P = (e) => typeof e == "function", F = (e = "en-US", t = null, i = 1, o = !1
761
253
  }
762
254
  return null;
763
255
  };
764
- }, R = /* @__PURE__ */ s(((e) => {
256
+ }, k = /* @__PURE__ */ s(((e) => {
765
257
  var t = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
766
258
  function r(e, n, r) {
767
259
  var i = null;
@@ -776,7 +268,7 @@ var P = (e) => typeof e == "function", F = (e = "en-US", t = null, i = 1, o = !1
776
268
  };
777
269
  }
778
270
  e.Fragment = n, e.jsx = r, e.jsxs = r;
779
- })), z = /* @__PURE__ */ s(((e) => {
271
+ })), A = /* @__PURE__ */ s(((e) => {
780
272
  process.env.NODE_ENV !== "production" && (function() {
781
273
  function t(e) {
782
274
  if (e == null) return null;
@@ -934,89 +426,70 @@ var P = (e) => typeof e == "function", F = (e = "en-US", t = null, i = 1, o = !1
934
426
  return f(e, t, n, !0, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
935
427
  };
936
428
  })();
937
- })), B = (/* @__PURE__ */ s(((e, t) => {
938
- process.env.NODE_ENV === "production" ? t.exports = R() : t.exports = z();
939
- })))(), ee = ({ color: e = "black", activeColor: t = "red", isActive: n = !1 }) => /* @__PURE__ */ (0, B.jsx)("svg", {
429
+ })), j = (/* @__PURE__ */ s(((e, t) => {
430
+ process.env.NODE_ENV === "production" ? t.exports = k() : t.exports = A();
431
+ })))(), M = ({ color: e = "black", activeColor: t = "red", isActive: n = !1 }) => /* @__PURE__ */ (0, j.jsx)("svg", {
940
432
  "data-testid": "__icon-root__",
941
433
  xmlns: "http://www.w3.org/2000/svg",
942
434
  width: "100%",
943
435
  height: "100%",
944
436
  viewBox: "0 0 24 24",
945
- children: /* @__PURE__ */ (0, B.jsxs)("g", { children: [/* @__PURE__ */ (0, B.jsx)("path", {
437
+ children: /* @__PURE__ */ (0, j.jsxs)("g", { children: [/* @__PURE__ */ (0, j.jsx)("path", {
946
438
  "data-testid": "__icon-path__",
947
439
  fill: e,
948
440
  d: "M12 14c1.66 0 2.99-1.34 2.99-3L15 5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm5.3-3c0 3-2.54 5.1-5.3 5.1S6.7 14 6.7 11H5c0 3.41 2.72 6.23 6 6.72V21h2v-3.28c3.28-.48 6-3.3 6-6.72h-1.7z"
949
- }), n && /* @__PURE__ */ (0, B.jsx)("circle", {
441
+ }), n && /* @__PURE__ */ (0, j.jsx)("circle", {
950
442
  "data-testid": "__icon-active__",
951
443
  fill: t,
952
444
  cx: "16",
953
445
  cy: "4",
954
446
  r: "4"
955
447
  })] })
956
- }), te = (e, t) => {
957
- for (let { alternatives: n } of e) for (let e of n) if (t(e) !== null) return;
958
- }, V = ({ children: r, commands: s = null, lang: c = "en-US", grammars: l = null, timeout: u = 3e3, silenceTimeout: d = null, precision: f = .4, maxAlternatives: p = 1, continuous: m = !1, ariaLabel: h = "start recognition", style: g = null, className: _ = null, outlineStyle: v = "2px solid", onStart: y = null, onEnd: b = null, onSpeechStart: x = null, onSpeechEnd: S = null, onResult: C = null, onError: w = null, onNoMatch: T = null, __rsInstance: E }) => {
959
- let D = a(null), [O, k] = o(!1), [, { start: A, stop: j, subscribe: M, unsubscribe: R }] = F(c, l, p, m, E), z = L(s, f), V = a({});
448
+ }), N = (e, t) => {
449
+ for (let n of e) for (let e of n) if (t(e.transcript ?? "") !== null) return;
450
+ }, P = ({ children: r, commands: o = null, lang: s = "en-US", grammars: c = null, timeout: l = 3e3, silenceTimeout: u = null, precision: d = .4, maxAlternatives: f = 1, continuous: p = !1, ariaLabel: m = "start recognition", style: h = null, className: g = null, outlineStyle: _ = "2px solid", onStart: v = null, onEnd: y = null, onSpeechStart: b = null, onSpeechEnd: x = null, onResult: S = null, onError: w = null, onNoMatch: k = null, signal: A = null, __rsInstance: P }) => {
451
+ let F = a(null), I = i(() => C(), []), [, { start: L, stop: R, subscribe: ee, unsubscribe: te, isRecording: z }] = E(s, c, f, p, P), B = O(o, d), V = a({});
960
452
  V.current = {
961
- onStart: y,
962
- onEnd: b,
963
- onSpeechStart: x,
964
- onSpeechEnd: S,
965
- onResult: C,
453
+ onStart: v,
454
+ onEnd: y,
455
+ onSpeechStart: b,
456
+ onSpeechEnd: x,
457
+ onResult: S,
966
458
  onError: w,
967
- onNoMatch: T
459
+ onNoMatch: k
968
460
  };
969
- let H = a(m);
970
- H.current = m;
971
- let U = a({
972
- transcript: "",
973
- event: null
974
- }), W = a(z);
975
- W.current = z;
976
- let G = a(null), ne = a(null), re = a(d);
977
- re.current = d;
978
- let ie = n(() => ne.current?.(), []), [K, q] = I(ie, u), [ae, J] = I(ie, d ?? 0), Y = n(() => {
461
+ let H = a(p);
462
+ H.current = p;
463
+ let U = a(B);
464
+ U.current = B;
465
+ let W = a(null), ne = a(null), G = a(!1), re = a(u);
466
+ re.current = u;
467
+ let ie = n(() => ne.current?.(), []), [K, q] = D(ie, l), [ae, J] = D(ie, u ?? 0), Y = n(() => {
979
468
  try {
980
- k(!1), j();
469
+ R();
981
470
  } catch (e) {
982
- V.current.onError?.(e), G.current?.();
471
+ V.current.onError?.(e), W.current?.();
983
472
  }
984
- }, [j]), oe = n((e) => {
473
+ }, [R]), oe = n((e) => {
985
474
  K(), V.current.onStart?.(e);
986
475
  }, [K]), se = n((e) => {
987
476
  q(), V.current.onSpeechStart?.(e);
988
477
  }, [q]), ce = n((e) => {
989
- K(), V.current.onSpeechEnd?.(e);
990
- }, [K]), le = n((e) => {
991
- let t = Array.from(e?.results ?? [], (e) => {
992
- let t = {
993
- confidence: -Infinity,
994
- transcript: ""
995
- }, n = [];
996
- for (let r = 0; r < e.length; r++) {
997
- let i = e[r];
998
- n.push(i.transcript ?? ""), (i.confidence === void 0 || i.confidence > t.confidence) && (t = i);
999
- }
1000
- return {
1001
- best: t.transcript ?? "",
1002
- alternatives: n
1003
- };
1004
- }), n = t.map((e) => e.best).join("");
1005
- q(), H.current ? (U.current.transcript = n, U.current.event = e, re.current > 0 && ae()) : (te(t, W.current), Y(), V.current.onResult?.(n, e));
1006
- }, [
1007
- q,
1008
- ae,
1009
- Y
1010
- ]), X = n((e) => {
478
+ K(), H.current && re.current > 0 && ae(), V.current.onSpeechEnd?.(e);
479
+ }, [K, ae]), le = n((e, t) => {
480
+ q(), H.current || (N(e?.results ?? [], U.current), Y()), V.current.onResult?.(t, e);
481
+ }, [q, Y]), X = n((e) => {
1011
482
  Y(), V.current.onError?.(e);
1012
483
  }, [Y]), ue = n((e) => {
1013
484
  q(), Y(), V.current.onNoMatch?.(e);
1014
485
  }, [q, Y]), Z = n((e) => {
1015
- q(), J();
1016
- try {
1017
- Y(), G.current?.(), H.current && U.current.transcript && (V.current.onResult?.(U.current.transcript, U.current.event), U.current.transcript = "", U.current.event = null);
1018
- } finally {
1019
- V.current.onEnd?.(e);
486
+ if (!G.current) {
487
+ G.current = !0, q(), J();
488
+ try {
489
+ Y(), W.current?.();
490
+ } finally {
491
+ G.current = !1, V.current.onEnd?.(e);
492
+ }
1020
493
  }
1021
494
  }, [
1022
495
  q,
@@ -1041,49 +514,50 @@ var P = (e) => typeof e == "function", F = (e = "en-US", t = null, i = 1, o = !1
1041
514
  X,
1042
515
  ue
1043
516
  ]);
1044
- G.current = () => Object.entries(Q).forEach(([e, t]) => R?.(e, t));
517
+ W.current = () => Object.entries(Q).forEach(([e, t]) => te?.(e, t));
1045
518
  let $ = n(() => {
1046
519
  try {
1047
- U.current.transcript = "", U.current.event = null, J(), k(!0), Object.entries(Q).forEach(([e, t]) => M(e, t)), A();
520
+ J(), Object.entries(Q).forEach(([e, t]) => ee(e, t)), L({ signal: A })?.catch?.(X);
1048
521
  } catch (e) {
1049
522
  X(e);
1050
523
  }
1051
524
  }, [
1052
525
  Q,
1053
- M,
1054
- A,
526
+ ee,
527
+ L,
1055
528
  J,
1056
- X
529
+ X,
530
+ A
1057
531
  ]), de = () => {
1058
- !_ && v && (D.current.style.outline = v);
532
+ !g && _ && (F.current.style.outline = _);
1059
533
  }, fe = () => {
1060
- !_ && v && (D.current.style.outline = "none");
534
+ !g && _ && (F.current.style.outline = "none");
1061
535
  };
1062
- return N.isSupported ? P(r) ? r($, Y, O) : t(r) ? e(r, { ...!O && { onClick: $ } }) : /* @__PURE__ */ (0, B.jsx)("button", {
536
+ return I ? T(r) ? r($, Y, z) : t(r) ? e(r, { ...!z && { onClick: $ } }) : /* @__PURE__ */ (0, j.jsx)("button", {
1063
537
  "data-testid": "__vocal-root__",
1064
- ref: D,
1065
- "aria-label": h,
1066
- "aria-pressed": O,
1067
- style: _ ? null : {
538
+ ref: F,
539
+ "aria-label": m,
540
+ "aria-pressed": z,
541
+ style: g ? null : {
1068
542
  width: 24,
1069
543
  height: 24,
1070
544
  backgroundColor: "transparent",
1071
545
  border: "none",
1072
546
  padding: 0,
1073
- cursor: !m && O ? "default" : "pointer",
1074
- ...g
547
+ cursor: !p && z ? "default" : "pointer",
548
+ ...h
1075
549
  },
1076
- className: _,
550
+ className: g,
1077
551
  onFocus: de,
1078
552
  onBlur: fe,
1079
- onClick: O ? Y : $,
1080
- children: /* @__PURE__ */ (0, B.jsx)(ee, {
1081
- isActive: O,
553
+ onClick: z ? Y : $,
554
+ children: /* @__PURE__ */ (0, j.jsx)(M, {
555
+ isActive: z,
1082
556
  color: "#aaa"
1083
557
  })
1084
558
  }) : null;
1085
- }, H = N.isSupported, U = V;
559
+ };
1086
560
  //#endregion
1087
- export { U as default, H as isSupported, F as useVocal };
561
+ export { P as default, C as isSupported, E as useVocal };
1088
562
 
1089
563
  //# sourceMappingURL=index.es.js.map