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