dictate-button 0.2.0 → 1.0.0

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.
@@ -0,0 +1,709 @@
1
+ const yt = (t, e) => t === e, N = {
2
+ equals: yt
3
+ };
4
+ let _t = at;
5
+ const m = 1, B = 2, nt = {
6
+ owned: null,
7
+ cleanups: null,
8
+ context: null,
9
+ owner: null
10
+ };
11
+ var y = null;
12
+ let V = null, wt = null, p = null, g = null, S = null, F = 0;
13
+ function Ct(t, e) {
14
+ const n = p, s = y, r = t.length === 0, o = e === void 0 ? s : e, l = r ? nt : {
15
+ owned: null,
16
+ cleanups: null,
17
+ context: o ? o.context : null,
18
+ owner: o
19
+ }, i = r ? t : () => t(() => G(() => E(l)));
20
+ y = l, p = null;
21
+ try {
22
+ return k(i, !0);
23
+ } finally {
24
+ p = n, y = s;
25
+ }
26
+ }
27
+ function rt(t, e) {
28
+ e = e ? Object.assign({}, N, e) : N;
29
+ const n = {
30
+ value: t,
31
+ observers: null,
32
+ observerSlots: null,
33
+ comparator: e.equals || void 0
34
+ }, s = (r) => (typeof r == "function" && (r = r(n.value)), ot(n, r));
35
+ return [st.bind(n), s];
36
+ }
37
+ function R(t, e, n) {
38
+ const s = it(t, e, !1, m);
39
+ L(s);
40
+ }
41
+ function St(t, e, n) {
42
+ n = n ? Object.assign({}, N, n) : N;
43
+ const s = it(t, e, !0, 0);
44
+ return s.observers = null, s.observerSlots = null, s.comparator = n.equals || void 0, L(s), st.bind(s);
45
+ }
46
+ function G(t) {
47
+ if (p === null) return t();
48
+ const e = p;
49
+ p = null;
50
+ try {
51
+ return t();
52
+ } finally {
53
+ p = e;
54
+ }
55
+ }
56
+ function st() {
57
+ if (this.sources && this.state)
58
+ if (this.state === m) L(this);
59
+ else {
60
+ const t = g;
61
+ g = null, k(() => I(this), !1), g = t;
62
+ }
63
+ if (p) {
64
+ const t = this.observers ? this.observers.length : 0;
65
+ p.sources ? (p.sources.push(this), p.sourceSlots.push(t)) : (p.sources = [this], p.sourceSlots = [t]), this.observers ? (this.observers.push(p), this.observerSlots.push(p.sources.length - 1)) : (this.observers = [p], this.observerSlots = [p.sources.length - 1]);
66
+ }
67
+ return this.value;
68
+ }
69
+ function ot(t, e, n) {
70
+ let s = t.value;
71
+ return (!t.comparator || !t.comparator(s, e)) && (t.value = e, t.observers && t.observers.length && k(() => {
72
+ for (let r = 0; r < t.observers.length; r += 1) {
73
+ const o = t.observers[r], l = V && V.running;
74
+ l && V.disposed.has(o), (l ? !o.tState : !o.state) && (o.pure ? g.push(o) : S.push(o), o.observers && ct(o)), l || (o.state = m);
75
+ }
76
+ if (g.length > 1e6)
77
+ throw g = [], new Error();
78
+ }, !1)), e;
79
+ }
80
+ function L(t) {
81
+ if (!t.fn) return;
82
+ E(t);
83
+ const e = F;
84
+ mt(t, t.value, e);
85
+ }
86
+ function mt(t, e, n) {
87
+ let s;
88
+ const r = y, o = p;
89
+ p = y = t;
90
+ try {
91
+ s = t.fn(e);
92
+ } catch (l) {
93
+ return t.pure && (t.state = m, t.owned && t.owned.forEach(E), t.owned = null), t.updatedAt = n + 1, ut(l);
94
+ } finally {
95
+ p = o, y = r;
96
+ }
97
+ (!t.updatedAt || t.updatedAt <= n) && (t.updatedAt != null && "observers" in t ? ot(t, s) : t.value = s, t.updatedAt = n);
98
+ }
99
+ function it(t, e, n, s = m, r) {
100
+ const o = {
101
+ fn: t,
102
+ state: s,
103
+ updatedAt: null,
104
+ owned: null,
105
+ sources: null,
106
+ sourceSlots: null,
107
+ cleanups: null,
108
+ value: e,
109
+ owner: y,
110
+ context: y ? y.context : null,
111
+ pure: n
112
+ };
113
+ return y === null || y !== nt && (y.owned ? y.owned.push(o) : y.owned = [o]), o;
114
+ }
115
+ function lt(t) {
116
+ if (t.state === 0) return;
117
+ if (t.state === B) return I(t);
118
+ if (t.suspense && G(t.suspense.inFallback)) return t.suspense.effects.push(t);
119
+ const e = [t];
120
+ for (; (t = t.owner) && (!t.updatedAt || t.updatedAt < F); )
121
+ t.state && e.push(t);
122
+ for (let n = e.length - 1; n >= 0; n--)
123
+ if (t = e[n], t.state === m)
124
+ L(t);
125
+ else if (t.state === B) {
126
+ const s = g;
127
+ g = null, k(() => I(t, e[0]), !1), g = s;
128
+ }
129
+ }
130
+ function k(t, e) {
131
+ if (g) return t();
132
+ let n = !1;
133
+ e || (g = []), S ? n = !0 : S = [], F++;
134
+ try {
135
+ const s = t();
136
+ return At(n), s;
137
+ } catch (s) {
138
+ n || (S = null), g = null, ut(s);
139
+ }
140
+ }
141
+ function At(t) {
142
+ if (g && (at(g), g = null), t) return;
143
+ const e = S;
144
+ S = null, e.length && k(() => _t(e), !1);
145
+ }
146
+ function at(t) {
147
+ for (let e = 0; e < t.length; e++) lt(t[e]);
148
+ }
149
+ function I(t, e) {
150
+ t.state = 0;
151
+ for (let n = 0; n < t.sources.length; n += 1) {
152
+ const s = t.sources[n];
153
+ if (s.sources) {
154
+ const r = s.state;
155
+ r === m ? s !== e && (!s.updatedAt || s.updatedAt < F) && lt(s) : r === B && I(s, e);
156
+ }
157
+ }
158
+ }
159
+ function ct(t) {
160
+ for (let e = 0; e < t.observers.length; e += 1) {
161
+ const n = t.observers[e];
162
+ n.state || (n.state = B, n.pure ? g.push(n) : S.push(n), n.observers && ct(n));
163
+ }
164
+ }
165
+ function E(t) {
166
+ let e;
167
+ if (t.sources)
168
+ for (; t.sources.length; ) {
169
+ const n = t.sources.pop(), s = t.sourceSlots.pop(), r = n.observers;
170
+ if (r && r.length) {
171
+ const o = r.pop(), l = n.observerSlots.pop();
172
+ s < r.length && (o.sourceSlots[l] = s, r[s] = o, n.observerSlots[s] = l);
173
+ }
174
+ }
175
+ if (t.tOwned) {
176
+ for (e = t.tOwned.length - 1; e >= 0; e--) E(t.tOwned[e]);
177
+ delete t.tOwned;
178
+ }
179
+ if (t.owned) {
180
+ for (e = t.owned.length - 1; e >= 0; e--) E(t.owned[e]);
181
+ t.owned = null;
182
+ }
183
+ if (t.cleanups) {
184
+ for (e = t.cleanups.length - 1; e >= 0; e--) t.cleanups[e]();
185
+ t.cleanups = null;
186
+ }
187
+ t.state = 0;
188
+ }
189
+ function vt(t) {
190
+ return t instanceof Error ? t : new Error(typeof t == "string" ? t : "Unknown error", {
191
+ cause: t
192
+ });
193
+ }
194
+ function ut(t, e = y) {
195
+ throw vt(t);
196
+ }
197
+ function P(t, e) {
198
+ return G(() => t(e || {}));
199
+ }
200
+ const j = (t) => St(() => t());
201
+ function xt(t, e, n) {
202
+ let s = n.length, r = e.length, o = s, l = 0, i = 0, a = e[r - 1].nextSibling, u = null;
203
+ for (; l < r || i < o; ) {
204
+ if (e[l] === n[i]) {
205
+ l++, i++;
206
+ continue;
207
+ }
208
+ for (; e[r - 1] === n[o - 1]; )
209
+ r--, o--;
210
+ if (r === l) {
211
+ const f = o < s ? i ? n[i - 1].nextSibling : n[o - i] : a;
212
+ for (; i < o; ) t.insertBefore(n[i++], f);
213
+ } else if (o === i)
214
+ for (; l < r; )
215
+ (!u || !u.has(e[l])) && e[l].remove(), l++;
216
+ else if (e[l] === n[o - 1] && n[i] === e[r - 1]) {
217
+ const f = e[--r].nextSibling;
218
+ t.insertBefore(n[i++], e[l++].nextSibling), t.insertBefore(n[--o], f), e[r] = n[o];
219
+ } else {
220
+ if (!u) {
221
+ u = /* @__PURE__ */ new Map();
222
+ let b = i;
223
+ for (; b < o; ) u.set(n[b], b++);
224
+ }
225
+ const f = u.get(e[l]);
226
+ if (f != null)
227
+ if (i < f && f < o) {
228
+ let b = l, w = 1, C;
229
+ for (; ++b < r && b < o && !((C = u.get(e[b])) == null || C !== f + w); )
230
+ w++;
231
+ if (w > f - i) {
232
+ const K = e[l];
233
+ for (; i < f; ) t.insertBefore(n[i++], K);
234
+ } else t.replaceChild(n[i++], e[l++]);
235
+ } else l++;
236
+ else e[l++].remove();
237
+ }
238
+ }
239
+ }
240
+ const Z = "_$DX_DELEGATE";
241
+ function T(t, e, n, s) {
242
+ let r;
243
+ const o = () => {
244
+ const i = document.createElement("template");
245
+ return i.innerHTML = t, i.content.firstChild;
246
+ }, l = () => (r || (r = o())).cloneNode(!0);
247
+ return l.cloneNode = l, l;
248
+ }
249
+ function Et(t, e = window.document) {
250
+ const n = e[Z] || (e[Z] = /* @__PURE__ */ new Set());
251
+ for (let s = 0, r = t.length; s < r; s++) {
252
+ const o = t[s];
253
+ n.has(o) || (n.add(o), e.addEventListener(o, Tt));
254
+ }
255
+ }
256
+ function ft(t, e, n) {
257
+ n == null ? t.removeAttribute(e) : t.setAttribute(e, n);
258
+ }
259
+ function kt(t, e, n) {
260
+ if (!e) return n ? ft(t, "style") : e;
261
+ const s = t.style;
262
+ if (typeof e == "string") return s.cssText = e;
263
+ typeof n == "string" && (s.cssText = n = void 0), n || (n = {}), e || (e = {});
264
+ let r, o;
265
+ for (o in n)
266
+ e[o] == null && s.removeProperty(o), delete n[o];
267
+ for (o in e)
268
+ r = e[o], r !== n[o] && (s.setProperty(o, r), n[o] = r);
269
+ return n;
270
+ }
271
+ function x(t, e, n, s) {
272
+ if (n !== void 0 && !s && (s = []), typeof e != "function") return D(t, e, s, n);
273
+ R((r) => D(t, e(), r, n), s);
274
+ }
275
+ function Tt(t) {
276
+ let e = t.target;
277
+ const n = `$$${t.type}`, s = t.target, r = t.currentTarget, o = (a) => Object.defineProperty(t, "target", {
278
+ configurable: !0,
279
+ value: a
280
+ }), l = () => {
281
+ const a = e[n];
282
+ if (a && !e.disabled) {
283
+ const u = e[`${n}Data`];
284
+ if (u !== void 0 ? a.call(e, u, t) : a.call(e, t), t.cancelBubble) return;
285
+ }
286
+ return e.host && typeof e.host != "string" && !e.host._$host && e.contains(t.target) && o(e.host), !0;
287
+ }, i = () => {
288
+ for (; l() && (e = e._$host || e.parentNode || e.host); ) ;
289
+ };
290
+ if (Object.defineProperty(t, "currentTarget", {
291
+ configurable: !0,
292
+ get() {
293
+ return e || document;
294
+ }
295
+ }), t.composedPath) {
296
+ const a = t.composedPath();
297
+ o(a[0]);
298
+ for (let u = 0; u < a.length - 2 && (e = a[u], !!l()); u++) {
299
+ if (e._$host) {
300
+ e = e._$host, i();
301
+ break;
302
+ }
303
+ if (e.parentNode === r)
304
+ break;
305
+ }
306
+ } else i();
307
+ o(s);
308
+ }
309
+ function D(t, e, n, s, r) {
310
+ for (; typeof n == "function"; ) n = n();
311
+ if (e === n) return n;
312
+ const o = typeof e, l = s !== void 0;
313
+ if (t = l && n[0] && n[0].parentNode || t, o === "string" || o === "number") {
314
+ if (o === "number" && (e = e.toString(), e === n))
315
+ return n;
316
+ if (l) {
317
+ let i = n[0];
318
+ i && i.nodeType === 3 ? i.data !== e && (i.data = e) : i = document.createTextNode(e), n = A(t, n, s, i);
319
+ } else
320
+ n !== "" && typeof n == "string" ? n = t.firstChild.data = e : n = t.textContent = e;
321
+ } else if (e == null || o === "boolean")
322
+ n = A(t, n, s);
323
+ else {
324
+ if (o === "function")
325
+ return R(() => {
326
+ let i = e();
327
+ for (; typeof i == "function"; ) i = i();
328
+ n = D(t, i, n, s);
329
+ }), () => n;
330
+ if (Array.isArray(e)) {
331
+ const i = [], a = n && Array.isArray(n);
332
+ if (H(i, e, n, r))
333
+ return R(() => n = D(t, i, n, s, !0)), () => n;
334
+ if (i.length === 0) {
335
+ if (n = A(t, n, s), l) return n;
336
+ } else a ? n.length === 0 ? Q(t, i, s) : xt(t, n, i) : (n && A(t), Q(t, i));
337
+ n = i;
338
+ } else if (e.nodeType) {
339
+ if (Array.isArray(n)) {
340
+ if (l) return n = A(t, n, s, e);
341
+ A(t, n, null, e);
342
+ } else n == null || n === "" || !t.firstChild ? t.appendChild(e) : t.replaceChild(e, t.firstChild);
343
+ n = e;
344
+ }
345
+ }
346
+ return n;
347
+ }
348
+ function H(t, e, n, s) {
349
+ let r = !1;
350
+ for (let o = 0, l = e.length; o < l; o++) {
351
+ let i = e[o], a = n && n[t.length], u;
352
+ if (!(i == null || i === !0 || i === !1)) if ((u = typeof i) == "object" && i.nodeType)
353
+ t.push(i);
354
+ else if (Array.isArray(i))
355
+ r = H(t, i, a) || r;
356
+ else if (u === "function")
357
+ if (s) {
358
+ for (; typeof i == "function"; ) i = i();
359
+ r = H(t, Array.isArray(i) ? i : [i], Array.isArray(a) ? a : [a]) || r;
360
+ } else
361
+ t.push(i), r = !0;
362
+ else {
363
+ const f = String(i);
364
+ a && a.nodeType === 3 && a.data === f ? t.push(a) : t.push(document.createTextNode(f));
365
+ }
366
+ }
367
+ return r;
368
+ }
369
+ function Q(t, e, n = null) {
370
+ for (let s = 0, r = e.length; s < r; s++) t.insertBefore(e[s], n);
371
+ }
372
+ function A(t, e, n, s) {
373
+ if (n === void 0) return t.textContent = "";
374
+ const r = s || document.createTextNode("");
375
+ if (e.length) {
376
+ let o = !1;
377
+ for (let l = e.length - 1; l >= 0; l--) {
378
+ const i = e[l];
379
+ if (r !== i) {
380
+ const a = i.parentNode === t;
381
+ !o && !l ? a ? t.replaceChild(r, i) : t.insertBefore(r, n) : a && i.remove();
382
+ } else o = !0;
383
+ }
384
+ } else t.insertBefore(r, n);
385
+ return [r];
386
+ }
387
+ function $t(t) {
388
+ return Object.keys(t).reduce((n, s) => {
389
+ const r = t[s];
390
+ return n[s] = Object.assign({}, r), ht(r.value) && !Nt(r.value) && !Array.isArray(r.value) && (n[s].value = Object.assign({}, r.value)), Array.isArray(r.value) && (n[s].value = r.value.slice(0)), n;
391
+ }, {});
392
+ }
393
+ function Ot(t) {
394
+ return t ? Object.keys(t).reduce((n, s) => {
395
+ const r = t[s];
396
+ return n[s] = ht(r) && "value" in r ? r : {
397
+ value: r
398
+ }, n[s].attribute || (n[s].attribute = Mt(s)), n[s].parse = "parse" in n[s] ? n[s].parse : typeof n[s].value != "string", n;
399
+ }, {}) : {};
400
+ }
401
+ function Pt(t) {
402
+ return Object.keys(t).reduce((n, s) => (n[s] = t[s].value, n), {});
403
+ }
404
+ function jt(t, e) {
405
+ const n = $t(e);
406
+ return Object.keys(e).forEach((r) => {
407
+ const o = n[r], l = t.getAttribute(o.attribute), i = t[r];
408
+ l != null && (o.value = o.parse ? dt(l) : l), i != null && (o.value = Array.isArray(i) ? i.slice(0) : i), o.reflect && Y(t, o.attribute, o.value, !!o.parse), Object.defineProperty(t, r, {
409
+ get() {
410
+ return o.value;
411
+ },
412
+ set(a) {
413
+ const u = o.value;
414
+ o.value = a, o.reflect && Y(this, o.attribute, o.value, !!o.parse);
415
+ for (let f = 0, b = this.__propertyChangedCallbacks.length; f < b; f++)
416
+ this.__propertyChangedCallbacks[f](r, a, u);
417
+ },
418
+ enumerable: !0,
419
+ configurable: !0
420
+ });
421
+ }), n;
422
+ }
423
+ function dt(t) {
424
+ if (t)
425
+ try {
426
+ return JSON.parse(t);
427
+ } catch {
428
+ return t;
429
+ }
430
+ }
431
+ function Y(t, e, n, s) {
432
+ if (n == null || n === !1) return t.removeAttribute(e);
433
+ let r = s ? JSON.stringify(n) : n;
434
+ t.__updating[e] = !0, r === "true" && (r = ""), t.setAttribute(e, r), Promise.resolve().then(() => delete t.__updating[e]);
435
+ }
436
+ function Mt(t) {
437
+ return t.replace(/\.?([A-Z]+)/g, (e, n) => "-" + n.toLowerCase()).replace("_", "-").replace(/^-/, "");
438
+ }
439
+ function ht(t) {
440
+ return t != null && (typeof t == "object" || typeof t == "function");
441
+ }
442
+ function Nt(t) {
443
+ return Object.prototype.toString.call(t) === "[object Function]";
444
+ }
445
+ function Bt(t) {
446
+ return typeof t == "function" && t.toString().indexOf("class") === 0;
447
+ }
448
+ let q;
449
+ function Rt(t, e) {
450
+ const n = Object.keys(e);
451
+ return class extends t {
452
+ static get observedAttributes() {
453
+ return n.map((r) => e[r].attribute);
454
+ }
455
+ constructor() {
456
+ super(), this.__initialized = !1, this.__released = !1, this.__releaseCallbacks = [], this.__propertyChangedCallbacks = [], this.__updating = {}, this.props = {};
457
+ }
458
+ connectedCallback() {
459
+ if (this.__initialized) return;
460
+ this.__releaseCallbacks = [], this.__propertyChangedCallbacks = [], this.__updating = {}, this.props = jt(this, e);
461
+ const r = Pt(this.props), o = this.Component, l = q;
462
+ try {
463
+ q = this, this.__initialized = !0, Bt(o) ? new o(r, {
464
+ element: this
465
+ }) : o(r, {
466
+ element: this
467
+ });
468
+ } finally {
469
+ q = l;
470
+ }
471
+ }
472
+ async disconnectedCallback() {
473
+ if (await Promise.resolve(), this.isConnected) return;
474
+ this.__propertyChangedCallbacks.length = 0;
475
+ let r = null;
476
+ for (; r = this.__releaseCallbacks.pop(); ) r(this);
477
+ delete this.__initialized, this.__released = !0;
478
+ }
479
+ attributeChangedCallback(r, o, l) {
480
+ if (this.__initialized && !this.__updating[r] && (r = this.lookupProp(r), r in e)) {
481
+ if (l == null && !this[r]) return;
482
+ this[r] = e[r].parse ? dt(l) : l;
483
+ }
484
+ }
485
+ lookupProp(r) {
486
+ if (e)
487
+ return n.find((o) => r === o || r === e[o].attribute);
488
+ }
489
+ get renderRoot() {
490
+ return this.shadowRoot || this.attachShadow({
491
+ mode: "open"
492
+ });
493
+ }
494
+ addReleaseCallback(r) {
495
+ this.__releaseCallbacks.push(r);
496
+ }
497
+ addPropertyChangedCallback(r) {
498
+ this.__propertyChangedCallbacks.push(r);
499
+ }
500
+ };
501
+ }
502
+ function It(t, e = {}, n = {}) {
503
+ const {
504
+ BaseElement: s = HTMLElement,
505
+ extension: r,
506
+ customElements: o = window.customElements
507
+ } = n;
508
+ return (l) => {
509
+ let i = o.get(t);
510
+ return i ? (i.prototype.Component = l, i) : (i = Rt(s, Ot(e)), i.prototype.Component = l, i.prototype.registeredTag = t, o.define(t, i, r), i);
511
+ };
512
+ }
513
+ function Dt(t) {
514
+ const e = Object.keys(t), n = {};
515
+ for (let s = 0; s < e.length; s++) {
516
+ const [r, o] = rt(t[e[s]]);
517
+ Object.defineProperty(n, e[s], {
518
+ get: r,
519
+ set(l) {
520
+ o(() => l);
521
+ }
522
+ });
523
+ }
524
+ return n;
525
+ }
526
+ function Ft(t) {
527
+ if (t.assignedSlot && t.assignedSlot._$owner) return t.assignedSlot._$owner;
528
+ let e = t.parentNode;
529
+ for (; e && !e._$owner && !(e.assignedSlot && e.assignedSlot._$owner); )
530
+ e = e.parentNode;
531
+ return e && e.assignedSlot ? e.assignedSlot._$owner : t._$owner;
532
+ }
533
+ function Lt(t) {
534
+ return (e, n) => {
535
+ const { element: s } = n;
536
+ return Ct((r) => {
537
+ const o = Dt(e);
538
+ s.addPropertyChangedCallback((i, a) => o[i] = a), s.addReleaseCallback(() => {
539
+ s.renderRoot.textContent = "", r();
540
+ });
541
+ const l = t(o, n);
542
+ return x(s.renderRoot, l);
543
+ }, Ft(s));
544
+ };
545
+ }
546
+ function Kt(t, e, n) {
547
+ return arguments.length === 2 && (n = e, e = {}), It(t, e)(Lt(n));
548
+ }
549
+ const Ut = `
550
+ :host([theme="dark"]) {
551
+ color-scheme: only dark;
552
+ }
553
+ :host([theme="light"]) {
554
+ color-scheme: only light;
555
+ }
556
+
557
+ :host .dictate-button__button {
558
+ cursor: pointer;
559
+ padding: 8px;
560
+ display: inline-flex;
561
+ align-items: center;
562
+ justify-content: center;
563
+ color: light-dark(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.95));
564
+ background-color: light-dark(rgba(0, 0, 0, 0.05), rgba(255, 255, 255, 0.7));
565
+ border-radius: 50%;
566
+ border: none;
567
+ transition: box-shadow 0.05s linear;
568
+ box-sizing: border-box;
569
+ }
570
+ :host .dictate-button__button:hover, :host .dictate-button__button:focus {
571
+ background-color: light-dark(rgba(0, 0, 0, 0.1), rgba(255, 255, 255, 0.6));
572
+ }
573
+
574
+ :host .dictate-button__button .dictate-button__icon {
575
+ width: 100%;
576
+ height: 100%;
577
+ }
578
+
579
+ :host .dictate-button__button .dictate-button__icon.dictate-button__icon--processing {
580
+ animation: dictate-button-rotate 1s linear infinite;
581
+ }
582
+
583
+ @keyframes dictate-button-rotate {
584
+ 0% { transform: rotate(0deg); }
585
+ 100% { transform: rotate(360deg); }
586
+ }
587
+ `;
588
+ var Vt = /* @__PURE__ */ T("<div part=container class=dictate-button__container><style></style><button part=button class=dictate-button__button>"), qt = /* @__PURE__ */ T('<svg part=icon class="dictate-button__icon dictate-button__icon--idle"fill=none viewBox="0 0 24 24"stroke-width=1.5 stroke=currentColor><path stroke-linecap=round stroke-linejoin=round d="M12 18.75a6 6 0 0 0 6-6v-1.5m-6 7.5a6 6 0 0 1-6-6v-1.5m6 7.5v3.75m-3.75 0h7.5M12 15.75a3 3 0 0 1-3-3V4.5a3 3 0 1 1 6 0v8.25a3 3 0 0 1-3 3Z">'), zt = /* @__PURE__ */ T('<svg part=icon class="dictate-button__icon dictate-button__icon--recording"viewBox="0 0 24 24"fill=currentColor stroke=none stroke-width=0 stroke-linecap=round stroke-linejoin=round><circle cx=12 cy=12 r=10>'), Ht = /* @__PURE__ */ T('<svg part=icon class="dictate-button__icon dictate-button__icon--processing"viewBox="0 0 24 24"fill=none stroke=currentColor stroke-width=1.5 stroke-linecap=round stroke-linejoin=round><path d="M12 2v4"></path><path d="m16.2 7.8 2.9-2.9"></path><path d="M18 12h4"></path><path d="m16.2 16.2 2.9 2.9"></path><path d="M12 18v4"></path><path d="m4.9 19.1 2.9-2.9"></path><path d="M2 12h4"></path><path d="m4.9 4.9 2.9 2.9">'), Gt = /* @__PURE__ */ T('<svg part=icon class="dictate-button__icon dictate-button__icon--error"viewBox="0 0 24 24"fill=none stroke=currentColor stroke-width=4 stroke-linecap=round stroke-linejoin=round><line x1=12 x2=12 y1=4 y2=14></line><line x1=12 x2=12.01 y1=20 y2=20>');
589
+ console.debug("dictate-button version:", "1.0.0");
590
+ const Wt = "https://api.dictate-button.io/transcribe", M = "dictate-button.io", z = -70, tt = -10, et = 0, Xt = 4, Jt = 0.25, Zt = 0.05;
591
+ Kt("dictate-button", {
592
+ size: 30,
593
+ apiEndpoint: Wt,
594
+ language: void 0
595
+ }, (t, {
596
+ element: e
597
+ }) => {
598
+ const {
599
+ size: n,
600
+ apiEndpoint: s,
601
+ language: r
602
+ } = t;
603
+ console.debug("api", s);
604
+ const [o, l] = rt("idle");
605
+ let i = null, a = [], u = null, f = null, b = null, w = !1, C = 0;
606
+ const K = (d) => d <= z ? 0 : d >= tt ? 1 : (d - z) / (tt - z), pt = (d) => {
607
+ let _ = 0;
608
+ for (let h = 0; h < d.length; h++) {
609
+ const c = (d[h] - 128) / 128;
610
+ _ += c * c;
611
+ }
612
+ return Math.sqrt(_ / d.length);
613
+ }, gt = (d) => 20 * Math.log10(Math.max(d, 1e-8)), W = (d) => {
614
+ const _ = e.shadowRoot.querySelector(".dictate-button__button");
615
+ if (!_)
616
+ return;
617
+ const h = et + d * (Xt - et), c = 0 + d * 0.4;
618
+ _.style.boxShadow = `0 0 0 ${h}px light-dark(rgba(0, 0, 0, ${c}), rgba(255, 255, 255, ${c}))`;
619
+ }, X = () => {
620
+ if (!w || !f || !b) return;
621
+ f.getByteTimeDomainData(b);
622
+ const d = pt(b), _ = gt(d), h = K(_), c = h > C ? Jt : Zt;
623
+ C = c * h + (1 - c) * C, W(C), requestAnimationFrame(X);
624
+ }, U = () => {
625
+ i && i.state !== "inactive" && i.stop(), a = [], w = !1, u && u.state !== "closed" && u.close(), u = null, f = null, b = null, C = 0, W(0);
626
+ };
627
+ e.addEventListener("disconnected", U);
628
+ const bt = async () => {
629
+ if (U(), o() === "idle")
630
+ try {
631
+ const d = await navigator.mediaDevices.getUserMedia({
632
+ audio: !0
633
+ });
634
+ u = new (window.AudioContext || window.webkitAudioContext)();
635
+ const _ = u.createMediaStreamSource(d);
636
+ f = u.createAnalyser(), f.fftSize = 2048, _.connect(f), b = new Uint8Array(f.fftSize), i = new MediaRecorder(d, {
637
+ mimeType: "audio/webm"
638
+ }), a = [], i.ondataavailable = (h) => {
639
+ a.push(h.data);
640
+ }, i.onstop = async () => {
641
+ w = !1, l("processing"), v(e, "transcribing:started", "Started transcribing");
642
+ const h = new Blob(a, {
643
+ type: "audio/webm"
644
+ });
645
+ try {
646
+ const c = new FormData();
647
+ c.append("audio", h, "recording.webm"), c.append("origin", window?.location?.origin), r && c.append("language", r);
648
+ const $ = await fetch(s, {
649
+ method: "POST",
650
+ body: c
651
+ });
652
+ if (!$.ok) throw new Error("Failed to transcribe audio");
653
+ const O = await $.json();
654
+ if (o() !== "processing") return;
655
+ v(e, "transcribing:finished", O.text), l("idle");
656
+ } catch (c) {
657
+ console.error("Failed to transcribe audio:", c), v(e, "transcribing:failed", "Failed to transcribe audio"), J();
658
+ }
659
+ }, i.start(), v(e, "recording:started", "Started recording"), w = !0, X(), l("recording");
660
+ } catch (d) {
661
+ console.error("Failed to start recording:", d), v(e, "recording:failed", "Failed to start recording"), J();
662
+ }
663
+ else
664
+ v(e, "recording:stopped", "Stopped recording"), l("idle"), U();
665
+ }, J = () => {
666
+ l("error"), setTimeout(() => l("idle"), 2e3);
667
+ };
668
+ return (() => {
669
+ var d = Vt(), _ = d.firstChild, h = _.nextSibling;
670
+ return x(_, Ut), h.$$click = bt, x(h, (() => {
671
+ var c = j(() => o() === "idle");
672
+ return () => c() && P(Yt, {});
673
+ })(), null), x(h, (() => {
674
+ var c = j(() => o() === "recording");
675
+ return () => c() && P(te, {});
676
+ })(), null), x(h, (() => {
677
+ var c = j(() => o() === "processing");
678
+ return () => c() && P(ee, {});
679
+ })(), null), x(h, (() => {
680
+ var c = j(() => o() === "error");
681
+ return () => c() && P(ne, {});
682
+ })(), null), R((c) => {
683
+ var $ = `width:${n}px;height:${n}px"`, O = Qt(o());
684
+ return c.e = kt(h, $, c.e), O !== c.t && ft(h, "title", c.t = O), c;
685
+ }, {
686
+ e: void 0,
687
+ t: void 0
688
+ }), d;
689
+ })();
690
+ });
691
+ const Qt = (t) => {
692
+ switch (t) {
693
+ case "idle":
694
+ return `Start dictation (${M})`;
695
+ case "recording":
696
+ return `Stop dictation (${M})`;
697
+ case "processing":
698
+ return `Stop processing (${M})`;
699
+ case "error":
700
+ return `Click to reset (${M})`;
701
+ }
702
+ }, v = (t, e, n) => {
703
+ t.dispatchEvent(new CustomEvent(e, {
704
+ detail: n,
705
+ bubbles: !0,
706
+ composed: !0
707
+ }));
708
+ }, Yt = () => qt(), te = () => zt(), ee = () => Ht(), ne = () => Gt();
709
+ Et(["click"]);