dictate-button 2.1.0 → 2.2.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.
- package/README.md +1 -1
- package/dist/dictate-button.js +364 -301
- package/dist/libs/injectDictateButton.js +2 -2
- package/package.json +12 -8
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Dictate Button
|
|
2
2
|
[](https://www.npmjs.com/package/dictate-button)
|
|
3
|
-
[](https://github.com/dictate-button/dictate-button/actions/workflows/ci.yml)
|
|
4
4
|
|
|
5
5
|
A customizable web component that adds speech-to-text dictation capabilities to any text input, textarea field, or contenteditable element on your website.
|
|
6
6
|
|
package/dist/dictate-button.js
CHANGED
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
const
|
|
2
|
-
equals:
|
|
1
|
+
const Ut = (t, n) => t === n, Q = {
|
|
2
|
+
equals: Ut
|
|
3
3
|
};
|
|
4
|
-
let
|
|
5
|
-
const
|
|
4
|
+
let At = Mt;
|
|
5
|
+
const k = 1, Y = 2, Tt = {
|
|
6
6
|
owned: null,
|
|
7
7
|
cleanups: null,
|
|
8
8
|
context: null,
|
|
9
9
|
owner: null
|
|
10
10
|
};
|
|
11
|
-
var
|
|
12
|
-
let
|
|
13
|
-
function
|
|
14
|
-
const e =
|
|
11
|
+
var b = null;
|
|
12
|
+
let ct = null, zt = null, g = null, _ = null, A = null, it = 0;
|
|
13
|
+
function Ft(t, n) {
|
|
14
|
+
const e = g, i = b, r = t.length === 0, o = n === void 0 ? i : n, l = r ? Tt : {
|
|
15
15
|
owned: null,
|
|
16
16
|
cleanups: null,
|
|
17
17
|
context: o ? o.context : null,
|
|
18
18
|
owner: o
|
|
19
|
-
}, s = r ? t : () => t(() =>
|
|
20
|
-
|
|
19
|
+
}, s = r ? t : () => t(() => st(() => U(l)));
|
|
20
|
+
b = l, g = null;
|
|
21
21
|
try {
|
|
22
|
-
return
|
|
22
|
+
return F(s, !0);
|
|
23
23
|
} finally {
|
|
24
|
-
|
|
24
|
+
g = e, b = i;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
n = n ? Object.assign({},
|
|
27
|
+
function kt(t, n) {
|
|
28
|
+
n = n ? Object.assign({}, Q, n) : Q;
|
|
29
29
|
const e = {
|
|
30
30
|
value: t,
|
|
31
31
|
observers: null,
|
|
32
32
|
observerSlots: null,
|
|
33
33
|
comparator: n.equals || void 0
|
|
34
|
-
}, i = (r) => (typeof r == "function" && (r = r(e.value)),
|
|
35
|
-
return [
|
|
36
|
-
}
|
|
37
|
-
function
|
|
38
|
-
const i =
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
function
|
|
42
|
-
|
|
43
|
-
const i =
|
|
44
|
-
i.user = !0,
|
|
45
|
-
}
|
|
46
|
-
function
|
|
47
|
-
e = e ? Object.assign({},
|
|
48
|
-
const i =
|
|
49
|
-
return i.observers = null, i.observerSlots = null, i.comparator = e.equals || void 0,
|
|
50
|
-
}
|
|
51
|
-
function
|
|
52
|
-
if (
|
|
53
|
-
const n =
|
|
54
|
-
|
|
34
|
+
}, i = (r) => (typeof r == "function" && (r = r(e.value)), Pt(e, r));
|
|
35
|
+
return [Lt.bind(e), i];
|
|
36
|
+
}
|
|
37
|
+
function tt(t, n, e) {
|
|
38
|
+
const i = pt(t, n, !1, k);
|
|
39
|
+
z(i);
|
|
40
|
+
}
|
|
41
|
+
function Kt(t, n, e) {
|
|
42
|
+
At = qt;
|
|
43
|
+
const i = pt(t, n, !1, k);
|
|
44
|
+
i.user = !0, A ? A.push(i) : z(i);
|
|
45
|
+
}
|
|
46
|
+
function Wt(t, n, e) {
|
|
47
|
+
e = e ? Object.assign({}, Q, e) : Q;
|
|
48
|
+
const i = pt(t, n, !0, 0);
|
|
49
|
+
return i.observers = null, i.observerSlots = null, i.comparator = e.equals || void 0, z(i), Lt.bind(i);
|
|
50
|
+
}
|
|
51
|
+
function st(t) {
|
|
52
|
+
if (g === null) return t();
|
|
53
|
+
const n = g;
|
|
54
|
+
g = null;
|
|
55
55
|
try {
|
|
56
56
|
return t();
|
|
57
57
|
} finally {
|
|
58
|
-
|
|
58
|
+
g = n;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
function
|
|
62
|
-
return
|
|
61
|
+
function vt(t) {
|
|
62
|
+
return b === null || (b.cleanups === null ? b.cleanups = [t] : b.cleanups.push(t)), t;
|
|
63
63
|
}
|
|
64
|
-
function
|
|
64
|
+
function Lt() {
|
|
65
65
|
if (this.sources && this.state)
|
|
66
|
-
if (this.state ===
|
|
66
|
+
if (this.state === k) z(this);
|
|
67
67
|
else {
|
|
68
|
-
const t =
|
|
69
|
-
|
|
68
|
+
const t = _;
|
|
69
|
+
_ = null, F(() => nt(this), !1), _ = t;
|
|
70
70
|
}
|
|
71
|
-
if (
|
|
71
|
+
if (g) {
|
|
72
72
|
const t = this.observers ? this.observers.length : 0;
|
|
73
|
-
|
|
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]);
|
|
74
74
|
}
|
|
75
75
|
return this.value;
|
|
76
76
|
}
|
|
77
|
-
function
|
|
77
|
+
function Pt(t, n, e) {
|
|
78
78
|
let i = t.value;
|
|
79
|
-
return (!t.comparator || !t.comparator(i, n)) && (t.value = n, t.observers && t.observers.length &&
|
|
79
|
+
return (!t.comparator || !t.comparator(i, n)) && (t.value = n, t.observers && t.observers.length && F(() => {
|
|
80
80
|
for (let r = 0; r < t.observers.length; r += 1) {
|
|
81
|
-
const o = t.observers[r], l =
|
|
82
|
-
l &&
|
|
81
|
+
const o = t.observers[r], l = ct && ct.running;
|
|
82
|
+
l && ct.disposed.has(o), (l ? !o.tState : !o.state) && (o.pure ? _.push(o) : A.push(o), o.observers && Rt(o)), l || (o.state = k);
|
|
83
83
|
}
|
|
84
|
-
if (
|
|
85
|
-
throw
|
|
84
|
+
if (_.length > 1e6)
|
|
85
|
+
throw _ = [], new Error();
|
|
86
86
|
}, !1)), n;
|
|
87
87
|
}
|
|
88
|
-
function
|
|
88
|
+
function z(t) {
|
|
89
89
|
if (!t.fn) return;
|
|
90
|
-
|
|
91
|
-
const n =
|
|
92
|
-
|
|
90
|
+
U(t);
|
|
91
|
+
const n = it;
|
|
92
|
+
Ht(t, t.value, n);
|
|
93
93
|
}
|
|
94
|
-
function
|
|
94
|
+
function Ht(t, n, e) {
|
|
95
95
|
let i;
|
|
96
|
-
const r =
|
|
97
|
-
|
|
96
|
+
const r = b, o = g;
|
|
97
|
+
g = b = t;
|
|
98
98
|
try {
|
|
99
99
|
i = t.fn(n);
|
|
100
100
|
} catch (l) {
|
|
101
|
-
return t.pure && (t.state =
|
|
101
|
+
return t.pure && (t.state = k, t.owned && t.owned.forEach(U), t.owned = null), t.updatedAt = e + 1, Ot(l);
|
|
102
102
|
} finally {
|
|
103
|
-
|
|
103
|
+
g = o, b = r;
|
|
104
104
|
}
|
|
105
|
-
(!t.updatedAt || t.updatedAt <= e) && (t.updatedAt != null && "observers" in t ?
|
|
105
|
+
(!t.updatedAt || t.updatedAt <= e) && (t.updatedAt != null && "observers" in t ? Pt(t, i) : t.value = i, t.updatedAt = e);
|
|
106
106
|
}
|
|
107
|
-
function
|
|
107
|
+
function pt(t, n, e, i = k, r) {
|
|
108
108
|
const o = {
|
|
109
109
|
fn: t,
|
|
110
110
|
state: i,
|
|
@@ -114,71 +114,71 @@ function ot(t, n, e, i = T, r) {
|
|
|
114
114
|
sourceSlots: null,
|
|
115
115
|
cleanups: null,
|
|
116
116
|
value: n,
|
|
117
|
-
owner:
|
|
118
|
-
context:
|
|
117
|
+
owner: b,
|
|
118
|
+
context: b ? b.context : null,
|
|
119
119
|
pure: e
|
|
120
120
|
};
|
|
121
|
-
return
|
|
121
|
+
return b === null || b !== Tt && (b.owned ? b.owned.push(o) : b.owned = [o]), o;
|
|
122
122
|
}
|
|
123
|
-
function
|
|
123
|
+
function et(t) {
|
|
124
124
|
if (t.state === 0) return;
|
|
125
|
-
if (t.state ===
|
|
126
|
-
if (t.suspense &&
|
|
125
|
+
if (t.state === Y) return nt(t);
|
|
126
|
+
if (t.suspense && st(t.suspense.inFallback)) return t.suspense.effects.push(t);
|
|
127
127
|
const n = [t];
|
|
128
|
-
for (; (t = t.owner) && (!t.updatedAt || t.updatedAt <
|
|
128
|
+
for (; (t = t.owner) && (!t.updatedAt || t.updatedAt < it); )
|
|
129
129
|
t.state && n.push(t);
|
|
130
130
|
for (let e = n.length - 1; e >= 0; e--)
|
|
131
|
-
if (t = n[e], t.state ===
|
|
132
|
-
|
|
133
|
-
else if (t.state ===
|
|
134
|
-
const i =
|
|
135
|
-
|
|
131
|
+
if (t = n[e], t.state === k)
|
|
132
|
+
z(t);
|
|
133
|
+
else if (t.state === Y) {
|
|
134
|
+
const i = _;
|
|
135
|
+
_ = null, F(() => nt(t, n[0]), !1), _ = i;
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
-
function
|
|
139
|
-
if (
|
|
138
|
+
function F(t, n) {
|
|
139
|
+
if (_) return t();
|
|
140
140
|
let e = !1;
|
|
141
|
-
n || (
|
|
141
|
+
n || (_ = []), A ? e = !0 : A = [], it++;
|
|
142
142
|
try {
|
|
143
143
|
const i = t();
|
|
144
|
-
return
|
|
144
|
+
return Vt(e), i;
|
|
145
145
|
} catch (i) {
|
|
146
|
-
e || (
|
|
146
|
+
e || (A = null), _ = null, Ot(i);
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
function
|
|
150
|
-
if (
|
|
151
|
-
const n =
|
|
152
|
-
|
|
149
|
+
function Vt(t) {
|
|
150
|
+
if (_ && (Mt(_), _ = null), t) return;
|
|
151
|
+
const n = A;
|
|
152
|
+
A = null, n.length && F(() => At(n), !1);
|
|
153
153
|
}
|
|
154
|
-
function
|
|
155
|
-
for (let n = 0; n < t.length; n++)
|
|
154
|
+
function Mt(t) {
|
|
155
|
+
for (let n = 0; n < t.length; n++) et(t[n]);
|
|
156
156
|
}
|
|
157
|
-
function
|
|
157
|
+
function qt(t) {
|
|
158
158
|
let n, e = 0;
|
|
159
159
|
for (n = 0; n < t.length; n++) {
|
|
160
160
|
const i = t[n];
|
|
161
|
-
i.user ? t[e++] = i :
|
|
161
|
+
i.user ? t[e++] = i : et(i);
|
|
162
162
|
}
|
|
163
|
-
for (n = 0; n < e; n++)
|
|
163
|
+
for (n = 0; n < e; n++) et(t[n]);
|
|
164
164
|
}
|
|
165
|
-
function
|
|
165
|
+
function nt(t, n) {
|
|
166
166
|
t.state = 0;
|
|
167
167
|
for (let e = 0; e < t.sources.length; e += 1) {
|
|
168
168
|
const i = t.sources[e];
|
|
169
169
|
if (i.sources) {
|
|
170
170
|
const r = i.state;
|
|
171
|
-
r ===
|
|
171
|
+
r === k ? i !== n && (!i.updatedAt || i.updatedAt < it) && et(i) : r === Y && nt(i, n);
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
|
-
function
|
|
175
|
+
function Rt(t) {
|
|
176
176
|
for (let n = 0; n < t.observers.length; n += 1) {
|
|
177
177
|
const e = t.observers[n];
|
|
178
|
-
e.state || (e.state =
|
|
178
|
+
e.state || (e.state = Y, e.pure ? _.push(e) : A.push(e), e.observers && Rt(e));
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
|
-
function
|
|
181
|
+
function U(t) {
|
|
182
182
|
let n;
|
|
183
183
|
if (t.sources)
|
|
184
184
|
for (; t.sources.length; ) {
|
|
@@ -189,11 +189,11 @@ function j(t) {
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
if (t.tOwned) {
|
|
192
|
-
for (n = t.tOwned.length - 1; n >= 0; n--)
|
|
192
|
+
for (n = t.tOwned.length - 1; n >= 0; n--) U(t.tOwned[n]);
|
|
193
193
|
delete t.tOwned;
|
|
194
194
|
}
|
|
195
195
|
if (t.owned) {
|
|
196
|
-
for (n = t.owned.length - 1; n >= 0; n--)
|
|
196
|
+
for (n = t.owned.length - 1; n >= 0; n--) U(t.owned[n]);
|
|
197
197
|
t.owned = null;
|
|
198
198
|
}
|
|
199
199
|
if (t.cleanups) {
|
|
@@ -202,20 +202,20 @@ function j(t) {
|
|
|
202
202
|
}
|
|
203
203
|
t.state = 0;
|
|
204
204
|
}
|
|
205
|
-
function
|
|
205
|
+
function Jt(t) {
|
|
206
206
|
return t instanceof Error ? t : new Error(typeof t == "string" ? t : "Unknown error", {
|
|
207
207
|
cause: t
|
|
208
208
|
});
|
|
209
209
|
}
|
|
210
|
-
function
|
|
211
|
-
throw
|
|
210
|
+
function Ot(t, n = b) {
|
|
211
|
+
throw Jt(t);
|
|
212
212
|
}
|
|
213
|
-
function
|
|
214
|
-
return
|
|
213
|
+
function X(t, n) {
|
|
214
|
+
return st(() => t(n || {}));
|
|
215
215
|
}
|
|
216
|
-
const
|
|
217
|
-
function
|
|
218
|
-
let i = e.length, r = n.length, o = i, l = 0, s = 0, a = n[r - 1].nextSibling,
|
|
216
|
+
const Z = (t) => Wt(() => t());
|
|
217
|
+
function Gt(t, n, e) {
|
|
218
|
+
let i = e.length, r = n.length, o = i, l = 0, s = 0, a = n[r - 1].nextSibling, h = null;
|
|
219
219
|
for (; l < r || s < o; ) {
|
|
220
220
|
if (n[l] === e[s]) {
|
|
221
221
|
l++, s++;
|
|
@@ -224,36 +224,36 @@ function Ut(t, n, e) {
|
|
|
224
224
|
for (; n[r - 1] === e[o - 1]; )
|
|
225
225
|
r--, o--;
|
|
226
226
|
if (r === l) {
|
|
227
|
-
const
|
|
228
|
-
for (; s < o; ) t.insertBefore(e[s++],
|
|
227
|
+
const d = o < i ? s ? e[s - 1].nextSibling : e[o - s] : a;
|
|
228
|
+
for (; s < o; ) t.insertBefore(e[s++], d);
|
|
229
229
|
} else if (o === s)
|
|
230
230
|
for (; l < r; )
|
|
231
|
-
(!
|
|
231
|
+
(!h || !h.has(n[l])) && n[l].remove(), l++;
|
|
232
232
|
else if (n[l] === e[o - 1] && e[s] === n[r - 1]) {
|
|
233
|
-
const
|
|
234
|
-
t.insertBefore(e[s++], n[l++].nextSibling), t.insertBefore(e[--o],
|
|
233
|
+
const d = n[--r].nextSibling;
|
|
234
|
+
t.insertBefore(e[s++], n[l++].nextSibling), t.insertBefore(e[--o], d), n[r] = e[o];
|
|
235
235
|
} else {
|
|
236
|
-
if (!
|
|
237
|
-
|
|
238
|
-
let
|
|
239
|
-
for (;
|
|
236
|
+
if (!h) {
|
|
237
|
+
h = /* @__PURE__ */ new Map();
|
|
238
|
+
let w = s;
|
|
239
|
+
for (; w < o; ) h.set(e[w], w++);
|
|
240
240
|
}
|
|
241
|
-
const
|
|
242
|
-
if (
|
|
243
|
-
if (s <
|
|
244
|
-
let
|
|
245
|
-
for (; ++
|
|
246
|
-
|
|
247
|
-
if (
|
|
248
|
-
const
|
|
249
|
-
for (; s <
|
|
241
|
+
const d = h.get(n[l]);
|
|
242
|
+
if (d != null)
|
|
243
|
+
if (s < d && d < o) {
|
|
244
|
+
let w = l, C = 1, c;
|
|
245
|
+
for (; ++w < r && w < o && !((c = h.get(n[w])) == null || c !== d + C); )
|
|
246
|
+
C++;
|
|
247
|
+
if (C > d - s) {
|
|
248
|
+
const x = n[l];
|
|
249
|
+
for (; s < d; ) t.insertBefore(e[s++], x);
|
|
250
250
|
} else t.replaceChild(e[s++], n[l++]);
|
|
251
251
|
} else l++;
|
|
252
252
|
else n[l++].remove();
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
|
-
function
|
|
256
|
+
function K(t, n, e, i) {
|
|
257
257
|
let r;
|
|
258
258
|
const o = () => {
|
|
259
259
|
const s = document.createElement("template");
|
|
@@ -261,11 +261,11 @@ function D(t, n, e, i) {
|
|
|
261
261
|
}, l = () => (r || (r = o())).cloneNode(!0);
|
|
262
262
|
return l.cloneNode = l, l;
|
|
263
263
|
}
|
|
264
|
-
function
|
|
264
|
+
function B(t, n, e) {
|
|
265
265
|
e == null ? t.removeAttribute(n) : t.setAttribute(n, e);
|
|
266
266
|
}
|
|
267
|
-
function
|
|
268
|
-
if (!n) return e ?
|
|
267
|
+
function Xt(t, n, e) {
|
|
268
|
+
if (!n) return e ? B(t, "style") : n;
|
|
269
269
|
const i = t.style;
|
|
270
270
|
if (typeof n == "string") return i.cssText = n;
|
|
271
271
|
typeof e == "string" && (i.cssText = e = void 0), e || (e = {}), n || (n = {});
|
|
@@ -276,14 +276,14 @@ function zt(t, n, e) {
|
|
|
276
276
|
r = n[o], r !== e[o] && (i.setProperty(o, r), e[o] = r);
|
|
277
277
|
return e;
|
|
278
278
|
}
|
|
279
|
-
function
|
|
280
|
-
return
|
|
279
|
+
function Zt(t, n, e) {
|
|
280
|
+
return st(() => t(n, e));
|
|
281
281
|
}
|
|
282
|
-
function
|
|
283
|
-
if (e !== void 0 && !i && (i = []), typeof n != "function") return
|
|
284
|
-
|
|
282
|
+
function P(t, n, e, i) {
|
|
283
|
+
if (e !== void 0 && !i && (i = []), typeof n != "function") return rt(t, n, i, e);
|
|
284
|
+
tt((r) => rt(t, n(), r, e), i);
|
|
285
285
|
}
|
|
286
|
-
function
|
|
286
|
+
function rt(t, n, e, i, r) {
|
|
287
287
|
for (; typeof e == "function"; ) e = e();
|
|
288
288
|
if (n === e) return e;
|
|
289
289
|
const o = typeof n, l = i !== void 0;
|
|
@@ -292,61 +292,61 @@ function Z(t, n, e, i, r) {
|
|
|
292
292
|
return e;
|
|
293
293
|
if (l) {
|
|
294
294
|
let s = e[0];
|
|
295
|
-
s && s.nodeType === 3 ? s.data !== n && (s.data = n) : s = document.createTextNode(n), e =
|
|
295
|
+
s && s.nodeType === 3 ? s.data !== n && (s.data = n) : s = document.createTextNode(n), e = O(t, e, i, s);
|
|
296
296
|
} else
|
|
297
297
|
e !== "" && typeof e == "string" ? e = t.firstChild.data = n : e = t.textContent = n;
|
|
298
298
|
} else if (n == null || o === "boolean")
|
|
299
|
-
e =
|
|
299
|
+
e = O(t, e, i);
|
|
300
300
|
else {
|
|
301
301
|
if (o === "function")
|
|
302
|
-
return
|
|
302
|
+
return tt(() => {
|
|
303
303
|
let s = n();
|
|
304
304
|
for (; typeof s == "function"; ) s = s();
|
|
305
|
-
e =
|
|
305
|
+
e = rt(t, s, e, i);
|
|
306
306
|
}), () => e;
|
|
307
307
|
if (Array.isArray(n)) {
|
|
308
308
|
const s = [], a = e && Array.isArray(e);
|
|
309
|
-
if (
|
|
310
|
-
return
|
|
309
|
+
if (ft(s, n, e, r))
|
|
310
|
+
return tt(() => e = rt(t, s, e, i, !0)), () => e;
|
|
311
311
|
if (s.length === 0) {
|
|
312
|
-
if (e =
|
|
313
|
-
} else a ? e.length === 0 ?
|
|
312
|
+
if (e = O(t, e, i), l) return e;
|
|
313
|
+
} else a ? e.length === 0 ? mt(t, s, i) : Gt(t, e, s) : (e && O(t), mt(t, s));
|
|
314
314
|
e = s;
|
|
315
315
|
} else if (n.nodeType) {
|
|
316
316
|
if (Array.isArray(e)) {
|
|
317
|
-
if (l) return e =
|
|
318
|
-
|
|
317
|
+
if (l) return e = O(t, e, i, n);
|
|
318
|
+
O(t, e, null, n);
|
|
319
319
|
} else e == null || e === "" || !t.firstChild ? t.appendChild(n) : t.replaceChild(n, t.firstChild);
|
|
320
320
|
e = n;
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
323
|
return e;
|
|
324
324
|
}
|
|
325
|
-
function
|
|
325
|
+
function ft(t, n, e, i) {
|
|
326
326
|
let r = !1;
|
|
327
327
|
for (let o = 0, l = n.length; o < l; o++) {
|
|
328
|
-
let s = n[o], a = e && e[t.length],
|
|
329
|
-
if (!(s == null || s === !0 || s === !1)) if ((
|
|
328
|
+
let s = n[o], a = e && e[t.length], h;
|
|
329
|
+
if (!(s == null || s === !0 || s === !1)) if ((h = typeof s) == "object" && s.nodeType)
|
|
330
330
|
t.push(s);
|
|
331
331
|
else if (Array.isArray(s))
|
|
332
|
-
r =
|
|
333
|
-
else if (
|
|
332
|
+
r = ft(t, s, a) || r;
|
|
333
|
+
else if (h === "function")
|
|
334
334
|
if (i) {
|
|
335
335
|
for (; typeof s == "function"; ) s = s();
|
|
336
|
-
r =
|
|
336
|
+
r = ft(t, Array.isArray(s) ? s : [s], Array.isArray(a) ? a : [a]) || r;
|
|
337
337
|
} else
|
|
338
338
|
t.push(s), r = !0;
|
|
339
339
|
else {
|
|
340
|
-
const
|
|
341
|
-
a && a.nodeType === 3 && a.data ===
|
|
340
|
+
const d = String(s);
|
|
341
|
+
a && a.nodeType === 3 && a.data === d ? t.push(a) : t.push(document.createTextNode(d));
|
|
342
342
|
}
|
|
343
343
|
}
|
|
344
344
|
return r;
|
|
345
345
|
}
|
|
346
|
-
function
|
|
346
|
+
function mt(t, n, e = null) {
|
|
347
347
|
for (let i = 0, r = n.length; i < r; i++) t.insertBefore(n[i], e);
|
|
348
348
|
}
|
|
349
|
-
function
|
|
349
|
+
function O(t, n, e, i) {
|
|
350
350
|
if (e === void 0) return t.textContent = "";
|
|
351
351
|
const r = i || document.createTextNode("");
|
|
352
352
|
if (n.length) {
|
|
@@ -361,43 +361,43 @@ function $(t, n, e, i) {
|
|
|
361
361
|
} else t.insertBefore(r, e);
|
|
362
362
|
return [r];
|
|
363
363
|
}
|
|
364
|
-
function
|
|
364
|
+
function Qt(t) {
|
|
365
365
|
return Object.keys(t).reduce((e, i) => {
|
|
366
366
|
const r = t[i];
|
|
367
|
-
return e[i] = Object.assign({}, r),
|
|
367
|
+
return e[i] = Object.assign({}, r), It(r.value) && !re(r.value) && !Array.isArray(r.value) && (e[i].value = Object.assign({}, r.value)), Array.isArray(r.value) && (e[i].value = r.value.slice(0)), e;
|
|
368
368
|
}, {});
|
|
369
369
|
}
|
|
370
|
-
function
|
|
370
|
+
function Yt(t) {
|
|
371
371
|
return t ? Object.keys(t).reduce((e, i) => {
|
|
372
372
|
const r = t[i];
|
|
373
|
-
return e[i] =
|
|
373
|
+
return e[i] = It(r) && "value" in r ? r : {
|
|
374
374
|
value: r
|
|
375
|
-
}, e[i].attribute || (e[i].attribute =
|
|
375
|
+
}, e[i].attribute || (e[i].attribute = ne(i)), e[i].parse = "parse" in e[i] ? e[i].parse : typeof e[i].value != "string", e;
|
|
376
376
|
}, {}) : {};
|
|
377
377
|
}
|
|
378
|
-
function
|
|
378
|
+
function te(t) {
|
|
379
379
|
return Object.keys(t).reduce((e, i) => (e[i] = t[i].value, e), {});
|
|
380
380
|
}
|
|
381
|
-
function
|
|
382
|
-
const e =
|
|
381
|
+
function ee(t, n) {
|
|
382
|
+
const e = Qt(n);
|
|
383
383
|
return Object.keys(n).forEach((r) => {
|
|
384
384
|
const o = e[r], l = t.getAttribute(o.attribute), s = t[r];
|
|
385
|
-
l != null && (o.value = o.parse ?
|
|
385
|
+
l != null && (o.value = o.parse ? $t(l) : l), s != null && (o.value = Array.isArray(s) ? s.slice(0) : s), o.reflect && Ct(t, o.attribute, o.value, !!o.parse), Object.defineProperty(t, r, {
|
|
386
386
|
get() {
|
|
387
387
|
return o.value;
|
|
388
388
|
},
|
|
389
389
|
set(a) {
|
|
390
|
-
const
|
|
391
|
-
o.value = a, o.reflect &&
|
|
392
|
-
for (let
|
|
393
|
-
this.__propertyChangedCallbacks[
|
|
390
|
+
const h = o.value;
|
|
391
|
+
o.value = a, o.reflect && Ct(this, o.attribute, o.value, !!o.parse);
|
|
392
|
+
for (let d = 0, w = this.__propertyChangedCallbacks.length; d < w; d++)
|
|
393
|
+
this.__propertyChangedCallbacks[d](r, a, h);
|
|
394
394
|
},
|
|
395
395
|
enumerable: !0,
|
|
396
396
|
configurable: !0
|
|
397
397
|
});
|
|
398
398
|
}), e;
|
|
399
399
|
}
|
|
400
|
-
function
|
|
400
|
+
function $t(t) {
|
|
401
401
|
if (t)
|
|
402
402
|
try {
|
|
403
403
|
return JSON.parse(t);
|
|
@@ -405,25 +405,25 @@ function St(t) {
|
|
|
405
405
|
return t;
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
|
-
function
|
|
408
|
+
function Ct(t, n, e, i) {
|
|
409
409
|
if (e == null || e === !1) return t.removeAttribute(n);
|
|
410
410
|
let r = i ? JSON.stringify(e) : e;
|
|
411
411
|
t.__updating[n] = !0, r === "true" && (r = ""), t.setAttribute(n, r), Promise.resolve().then(() => delete t.__updating[n]);
|
|
412
412
|
}
|
|
413
|
-
function
|
|
413
|
+
function ne(t) {
|
|
414
414
|
return t.replace(/\.?([A-Z]+)/g, (n, e) => "-" + e.toLowerCase()).replace("_", "-").replace(/^-/, "");
|
|
415
415
|
}
|
|
416
|
-
function
|
|
416
|
+
function It(t) {
|
|
417
417
|
return t != null && (typeof t == "object" || typeof t == "function");
|
|
418
418
|
}
|
|
419
|
-
function
|
|
419
|
+
function re(t) {
|
|
420
420
|
return Object.prototype.toString.call(t) === "[object Function]";
|
|
421
421
|
}
|
|
422
|
-
function
|
|
422
|
+
function ie(t) {
|
|
423
423
|
return typeof t == "function" && t.toString().indexOf("class") === 0;
|
|
424
424
|
}
|
|
425
|
-
let
|
|
426
|
-
function
|
|
425
|
+
let ut;
|
|
426
|
+
function se(t, n) {
|
|
427
427
|
const e = Object.keys(n);
|
|
428
428
|
return class extends t {
|
|
429
429
|
static get observedAttributes() {
|
|
@@ -436,16 +436,16 @@ function Xt(t, n) {
|
|
|
436
436
|
}
|
|
437
437
|
connectedCallback() {
|
|
438
438
|
if (this.__initialized) return;
|
|
439
|
-
this.__releaseCallbacks = [], this.__propertyChangedCallbacks = [], this.__updating = {}, this.props =
|
|
440
|
-
const r =
|
|
439
|
+
this.__releaseCallbacks = [], this.__propertyChangedCallbacks = [], this.__updating = {}, this.props = ee(this, n);
|
|
440
|
+
const r = te(this.props), o = this.Component, l = ut;
|
|
441
441
|
try {
|
|
442
|
-
|
|
442
|
+
ut = this, this.__initialized = !0, ie(o) ? new o(r, {
|
|
443
443
|
element: this
|
|
444
444
|
}) : o(r, {
|
|
445
445
|
element: this
|
|
446
446
|
});
|
|
447
447
|
} finally {
|
|
448
|
-
|
|
448
|
+
ut = l;
|
|
449
449
|
}
|
|
450
450
|
}
|
|
451
451
|
async disconnectedCallback() {
|
|
@@ -458,7 +458,7 @@ function Xt(t, n) {
|
|
|
458
458
|
attributeChangedCallback(r, o, l) {
|
|
459
459
|
if (this.__initialized && !this.__updating[r] && (r = this.lookupProp(r), r in n)) {
|
|
460
460
|
if (l == null && !this[r]) return;
|
|
461
|
-
this[r] = n[r].parse ?
|
|
461
|
+
this[r] = n[r].parse ? $t(l) : l;
|
|
462
462
|
}
|
|
463
463
|
}
|
|
464
464
|
lookupProp(r) {
|
|
@@ -478,7 +478,7 @@ function Xt(t, n) {
|
|
|
478
478
|
}
|
|
479
479
|
};
|
|
480
480
|
}
|
|
481
|
-
function
|
|
481
|
+
function oe(t, n = {}, e = {}) {
|
|
482
482
|
const {
|
|
483
483
|
BaseElement: i = HTMLElement,
|
|
484
484
|
extension: r,
|
|
@@ -486,13 +486,13 @@ function Zt(t, n = {}, e = {}) {
|
|
|
486
486
|
} = e;
|
|
487
487
|
return (l) => {
|
|
488
488
|
let s = o.get(t);
|
|
489
|
-
return s ? (s.prototype.Component = l, s) : (s =
|
|
489
|
+
return s ? (s.prototype.Component = l, s) : (s = se(i, Yt(n)), s.prototype.Component = l, s.prototype.registeredTag = t, o.define(t, s, r), s);
|
|
490
490
|
};
|
|
491
491
|
}
|
|
492
|
-
function
|
|
492
|
+
function le(t) {
|
|
493
493
|
const n = Object.keys(t), e = {};
|
|
494
494
|
for (let i = 0; i < n.length; i++) {
|
|
495
|
-
const [r, o] =
|
|
495
|
+
const [r, o] = kt(t[n[i]]);
|
|
496
496
|
Object.defineProperty(e, n[i], {
|
|
497
497
|
get: r,
|
|
498
498
|
set(l) {
|
|
@@ -502,30 +502,30 @@ function Qt(t) {
|
|
|
502
502
|
}
|
|
503
503
|
return e;
|
|
504
504
|
}
|
|
505
|
-
function
|
|
505
|
+
function ae(t) {
|
|
506
506
|
if (t.assignedSlot && t.assignedSlot._$owner) return t.assignedSlot._$owner;
|
|
507
507
|
let n = t.parentNode;
|
|
508
508
|
for (; n && !n._$owner && !(n.assignedSlot && n.assignedSlot._$owner); )
|
|
509
509
|
n = n.parentNode;
|
|
510
510
|
return n && n.assignedSlot ? n.assignedSlot._$owner : t._$owner;
|
|
511
511
|
}
|
|
512
|
-
function
|
|
512
|
+
function ce(t) {
|
|
513
513
|
return (n, e) => {
|
|
514
514
|
const { element: i } = e;
|
|
515
|
-
return
|
|
516
|
-
const o =
|
|
515
|
+
return Ft((r) => {
|
|
516
|
+
const o = le(n);
|
|
517
517
|
i.addPropertyChangedCallback((s, a) => o[s] = a), i.addReleaseCallback(() => {
|
|
518
518
|
i.renderRoot.textContent = "", r();
|
|
519
519
|
});
|
|
520
520
|
const l = t(o, e);
|
|
521
|
-
return
|
|
522
|
-
},
|
|
521
|
+
return P(i.renderRoot, l);
|
|
522
|
+
}, ae(i));
|
|
523
523
|
};
|
|
524
524
|
}
|
|
525
|
-
function
|
|
526
|
-
return arguments.length === 2 && (e = n, n = {}),
|
|
525
|
+
function ue(t, n, e) {
|
|
526
|
+
return arguments.length === 2 && (e = n, n = {}), oe(t, n)(ce(e));
|
|
527
527
|
}
|
|
528
|
-
const
|
|
528
|
+
const de = `
|
|
529
529
|
:host([theme="dark"]) {
|
|
530
530
|
color-scheme: only dark;
|
|
531
531
|
}
|
|
@@ -583,73 +583,122 @@ const ne = `
|
|
|
583
583
|
}
|
|
584
584
|
}
|
|
585
585
|
`;
|
|
586
|
-
var
|
|
587
|
-
console.debug("[dictate-button] version:", "2.
|
|
588
|
-
const
|
|
589
|
-
customElements.get("dictate-button") ? console.debug("[dictate-button] We don't require importing the dictate-button component separately anymore, so you may remove the script tag which imports https://cdn.dictate-button.io/dictate-button.js from the HTML head.") :
|
|
586
|
+
var fe = /* @__PURE__ */ K('<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 type=button part=button class=dictate-button__button>'), pe = /* @__PURE__ */ K('<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">'), he = /* @__PURE__ */ K('<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>'), ge = /* @__PURE__ */ K('<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>'), be = /* @__PURE__ */ K('<svg part=icon class="dictate-button__icon dictate-button__icon--processing"viewBox="0 0 24 24"fill=none stroke=currentColor stroke-width=2 stroke-linecap=round stroke-linejoin=round role=img aria-hidden=true><path d="M12 2v4"></path><path d="M12 18v4"></path><path d="M4.93 4.93l2.83 2.83"></path><path d="M16.24 16.24l2.83 2.83"></path><path d="M2 12h4"></path><path d="M18 12h4"></path><path d="M4.93 19.07l2.83-2.83"></path><path d="M16.24 7.76l2.83-2.83">');
|
|
587
|
+
console.debug("[dictate-button] version:", "2.2.0");
|
|
588
|
+
const ye = "wss://api.dictate-button.io/v2/transcribe", T = "dictate-button.io", we = 2e3, _e = 7e3, dt = -70, St = -10, Et = 0, ve = 4, me = 0.25, Ce = 0.05;
|
|
589
|
+
customElements.get("dictate-button") ? console.debug("[dictate-button] We don't require importing the dictate-button component separately anymore, so you may remove the script tag which imports https://cdn.dictate-button.io/dictate-button.js from the HTML head.") : ue("dictate-button", {
|
|
590
590
|
size: 30,
|
|
591
|
-
apiEndpoint:
|
|
591
|
+
apiEndpoint: ye,
|
|
592
592
|
language: "en"
|
|
593
593
|
}, (t, {
|
|
594
594
|
element: n
|
|
595
595
|
}) => {
|
|
596
596
|
console.debug("[dictate-button] api:", t.apiEndpoint);
|
|
597
|
-
const [e, i] =
|
|
598
|
-
let r = null, o = null, l = null, s = "", a = "",
|
|
599
|
-
const
|
|
600
|
-
let
|
|
601
|
-
for (let
|
|
602
|
-
const p = (u[
|
|
603
|
-
|
|
597
|
+
const [e, i] = kt("idle");
|
|
598
|
+
let r = null, o = null, l = null, s = "", a = "", h = -1, d = "", w = 0, C = null, c = null, x = null, M = null, $ = null, W = !1, I = 0;
|
|
599
|
+
const Dt = (u) => u <= dt ? 0 : u >= St ? 1 : (u - dt) / (St - dt), Nt = (u) => {
|
|
600
|
+
let y = 0;
|
|
601
|
+
for (let m = 0; m < u.length; m++) {
|
|
602
|
+
const p = (u[m] - 128) / 128;
|
|
603
|
+
y += p * p;
|
|
604
604
|
}
|
|
605
|
-
return Math.sqrt(
|
|
606
|
-
},
|
|
607
|
-
const
|
|
608
|
-
if (!
|
|
605
|
+
return Math.sqrt(y / u.length);
|
|
606
|
+
}, jt = (u) => 20 * Math.log10(Math.max(u, 1e-8)), ht = (u) => {
|
|
607
|
+
const y = n.shadowRoot.querySelector(".dictate-button__button");
|
|
608
|
+
if (!y)
|
|
609
609
|
return;
|
|
610
|
-
const
|
|
611
|
-
|
|
612
|
-
},
|
|
613
|
-
if (!
|
|
614
|
-
|
|
615
|
-
const u =
|
|
616
|
-
|
|
617
|
-
},
|
|
618
|
-
|
|
610
|
+
const m = Et + u * (ve - Et), p = 0 + u * 0.4;
|
|
611
|
+
y.style.boxShadow = `0 0 0 ${m}px light-dark(rgba(0, 0, 0, ${p}), rgba(255, 255, 255, ${p}))`;
|
|
612
|
+
}, gt = () => {
|
|
613
|
+
if (!W || !x || !$) return;
|
|
614
|
+
x.getByteTimeDomainData($);
|
|
615
|
+
const u = Nt($), y = jt(u), m = Dt(y), p = m > I ? me : Ce;
|
|
616
|
+
I = p * m + (1 - p) * I, ht(I), requestAnimationFrame(gt);
|
|
617
|
+
}, ot = () => [a, s, d].filter(Boolean).join(" "), H = () => {
|
|
618
|
+
if (e() !== "transcribing") return;
|
|
619
|
+
console.debug("[dictate-button] Connection lost");
|
|
620
|
+
const u = ot();
|
|
621
|
+
u && E(n, "dictate-end", u), E(n, "dictate-error", "Connection lost"), V(), L();
|
|
622
|
+
}, L = () => {
|
|
623
|
+
if (C && (clearInterval(C), C = null), r && (r.close(), r = null), M && (M.disconnect(), M = null), o) {
|
|
624
|
+
for (const u of o.getTracks())
|
|
625
|
+
u.stop();
|
|
626
|
+
o = null;
|
|
627
|
+
}
|
|
628
|
+
l = null, s = "", a = "", h = -1, d = "", W = !1, c && c.state !== "closed" && c.close(), c = null, x = null, $ = null, I = 0, ht(0);
|
|
629
|
+
};
|
|
630
|
+
n.addEventListener("disconnected", L);
|
|
631
|
+
const bt = () => {
|
|
632
|
+
document.visibilityState === "hidden" && e() === "transcribing" && lt();
|
|
633
|
+
};
|
|
634
|
+
document.addEventListener("visibilitychange", bt);
|
|
635
|
+
const yt = () => {
|
|
636
|
+
e() === "transcribing" && H();
|
|
619
637
|
};
|
|
620
|
-
|
|
621
|
-
const
|
|
622
|
-
|
|
638
|
+
window.addEventListener("offline", yt);
|
|
639
|
+
const wt = () => {
|
|
640
|
+
e() === "transcribing" && H();
|
|
623
641
|
};
|
|
624
|
-
|
|
625
|
-
document.removeEventListener("visibilitychange",
|
|
642
|
+
navigator.connection?.addEventListener("change", wt), vt(() => {
|
|
643
|
+
document.removeEventListener("visibilitychange", bt), window.removeEventListener("offline", yt), navigator.connection?.removeEventListener("change", wt);
|
|
626
644
|
});
|
|
627
|
-
const
|
|
645
|
+
const _t = async (u) => {
|
|
628
646
|
if (e() === "idle") {
|
|
629
|
-
l = u, s = "", a = "",
|
|
647
|
+
l = u, s = "", a = "", h = -1, d = "";
|
|
630
648
|
try {
|
|
631
|
-
const
|
|
649
|
+
const y = await navigator.mediaDevices.getUserMedia({
|
|
632
650
|
audio: {
|
|
633
|
-
sampleRate:
|
|
651
|
+
sampleRate: {
|
|
652
|
+
ideal: 16e3
|
|
653
|
+
},
|
|
634
654
|
channelCount: 1,
|
|
635
655
|
echoCancellation: !0,
|
|
636
656
|
noiseSuppression: !0
|
|
637
657
|
}
|
|
638
658
|
});
|
|
639
|
-
o =
|
|
640
|
-
|
|
659
|
+
o = y;
|
|
660
|
+
const D = y.getAudioTracks()[0].getSettings().sampleRate || 48e3;
|
|
661
|
+
c = new (window.AudioContext || // biome-ignore lint/suspicious/noExplicitAny: webkitAudioContext is a vendor prefix
|
|
662
|
+
window.webkitAudioContext)({
|
|
663
|
+
sampleRate: D
|
|
641
664
|
});
|
|
642
|
-
const
|
|
643
|
-
|
|
644
|
-
const
|
|
665
|
+
const f = c.createMediaStreamSource(y);
|
|
666
|
+
x = c.createAnalyser(), x.fftSize = 2048, f.connect(x), $ = new Uint8Array(x.fftSize);
|
|
667
|
+
const at = `
|
|
645
668
|
class PcmProcessor extends AudioWorkletProcessor {
|
|
669
|
+
constructor(options) {
|
|
670
|
+
super()
|
|
671
|
+
this.inputSampleRate = options.processorOptions.inputSampleRate
|
|
672
|
+
this.outputSampleRate = 16000
|
|
673
|
+
this.ratio = this.inputSampleRate / this.outputSampleRate
|
|
674
|
+
this.buffer = []
|
|
675
|
+
this.bufferIndex = 0
|
|
676
|
+
}
|
|
677
|
+
|
|
646
678
|
process(inputs) {
|
|
647
679
|
const input = inputs[0]
|
|
648
680
|
if (input.length > 0) {
|
|
649
681
|
const channelData = input[0]
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
682
|
+
|
|
683
|
+
// Resample to 16kHz if needed
|
|
684
|
+
let resampledData
|
|
685
|
+
if (this.ratio === 1) {
|
|
686
|
+
// No resampling needed
|
|
687
|
+
resampledData = channelData
|
|
688
|
+
} else {
|
|
689
|
+
// Simple decimation for downsampling
|
|
690
|
+
const outputLength = Math.floor(channelData.length / this.ratio)
|
|
691
|
+
resampledData = new Float32Array(outputLength)
|
|
692
|
+
for (let i = 0; i < outputLength; i++) {
|
|
693
|
+
const srcIndex = Math.floor(i * this.ratio)
|
|
694
|
+
resampledData[i] = channelData[srcIndex]
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
// Convert to PCM16
|
|
699
|
+
const pcm16 = new Int16Array(resampledData.length)
|
|
700
|
+
for (let i = 0; i < resampledData.length; i++) {
|
|
701
|
+
const s = Math.max(-1, Math.min(1, resampledData[i]))
|
|
653
702
|
pcm16[i] = s < 0 ? s * 0x8000 : s * 0x7fff
|
|
654
703
|
}
|
|
655
704
|
this.port.postMessage(pcm16.buffer, [pcm16.buffer])
|
|
@@ -658,87 +707,101 @@ customElements.get("dictate-button") ? console.debug("[dictate-button] We don't
|
|
|
658
707
|
}
|
|
659
708
|
}
|
|
660
709
|
registerProcessor('pcm-processor', PcmProcessor)
|
|
661
|
-
`,
|
|
710
|
+
`, J = new Blob([at], {
|
|
662
711
|
type: "application/javascript"
|
|
663
|
-
}),
|
|
664
|
-
await
|
|
665
|
-
|
|
666
|
-
|
|
712
|
+
}), N = URL.createObjectURL(J);
|
|
713
|
+
await c.audioWorklet.addModule(N), URL.revokeObjectURL(N), M = new AudioWorkletNode(c, "pcm-processor", {
|
|
714
|
+
processorOptions: {
|
|
715
|
+
inputSampleRate: D
|
|
716
|
+
}
|
|
717
|
+
}), f.connect(M);
|
|
718
|
+
const j = new URL(t.apiEndpoint);
|
|
719
|
+
t.language && j.searchParams.set("language", t.language), r = new WebSocket(j.toString()), r.onmessage = (S) => {
|
|
720
|
+
w = Date.now();
|
|
667
721
|
try {
|
|
668
722
|
const v = JSON.parse(S.data);
|
|
723
|
+
if (v.type === "heartbeat") return;
|
|
724
|
+
if (v.type === "session_closed") {
|
|
725
|
+
console.debug("[dictate-button] Session closed by server:", v.reason), H();
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
669
728
|
if (v.type === "interim_transcript" && v.text) {
|
|
670
|
-
|
|
671
|
-
const
|
|
672
|
-
|
|
729
|
+
d = v.text;
|
|
730
|
+
const G = [a, s, d].filter(Boolean).join(" ");
|
|
731
|
+
E(n, "dictate-text", G);
|
|
673
732
|
} else if (v.type === "transcript" && v.text) {
|
|
674
|
-
const
|
|
675
|
-
|
|
676
|
-
const
|
|
677
|
-
|
|
678
|
-
} else v.type === "error" && (console.error("[dictate-button] Server error:", v.error),
|
|
733
|
+
const G = v.turn_order ?? 0, R = v.text;
|
|
734
|
+
d = "", G > h ? (s && (a = a ? `${a} ${s}` : s), h = G, s = R) : R.length > s.length && R.startsWith(s.substring(0, Math.min(10, s.length))) ? s = R : s = s ? `${s} ${R}` : R;
|
|
735
|
+
const Bt = a ? `${a} ${s}` : s;
|
|
736
|
+
E(n, "dictate-text", Bt);
|
|
737
|
+
} else v.type === "error" && (console.error("[dictate-button] Server error:", v.error), E(n, "dictate-error", v.error), V(), L());
|
|
679
738
|
} catch (v) {
|
|
680
739
|
console.error("[dictate-button] Error parsing message:", v);
|
|
681
740
|
}
|
|
682
741
|
}, r.onerror = (S) => {
|
|
683
|
-
console.error("[dictate-button] WebSocket error:", S),
|
|
742
|
+
console.error("[dictate-button] WebSocket error:", S), E(n, "dictate-error", "Connection error"), V(), L();
|
|
684
743
|
}, r.onclose = () => {
|
|
685
|
-
},
|
|
744
|
+
}, M.port.onmessage = (S) => {
|
|
686
745
|
r && r.readyState === WebSocket.OPEN && r.send(S.data);
|
|
687
|
-
},
|
|
688
|
-
|
|
689
|
-
|
|
746
|
+
}, E(n, "dictate-start", "Started transcribing"), W = !0, gt(), w = Date.now(), C = setInterval(() => {
|
|
747
|
+
if (e() !== "transcribing") return;
|
|
748
|
+
const S = Date.now() - w;
|
|
749
|
+
S > _e && (console.debug(`[dictate-button] No messages for ${S}ms, connection lost`), H());
|
|
750
|
+
}, we), i("transcribing");
|
|
751
|
+
} catch (y) {
|
|
752
|
+
console.error("[dictate-button] Failed to start:", y), E(n, "dictate-error", "Failed to start transcription"), V(), L();
|
|
690
753
|
}
|
|
691
754
|
}
|
|
692
|
-
},
|
|
755
|
+
}, lt = () => {
|
|
693
756
|
if (e() === "transcribing")
|
|
694
|
-
if (
|
|
757
|
+
if (W = !1, i("finalizing"), r && r.readyState === WebSocket.OPEN)
|
|
695
758
|
r.send(JSON.stringify({
|
|
696
759
|
type: "close"
|
|
697
760
|
})), setTimeout(() => {
|
|
698
|
-
const u =
|
|
699
|
-
u &&
|
|
761
|
+
const u = ot();
|
|
762
|
+
u && E(n, "dictate-end", u), L(), i("idle");
|
|
700
763
|
}, 500);
|
|
701
764
|
else {
|
|
702
|
-
const u =
|
|
703
|
-
u &&
|
|
765
|
+
const u = ot();
|
|
766
|
+
u && E(n, "dictate-end", u), L(), i("idle");
|
|
704
767
|
}
|
|
705
|
-
},
|
|
768
|
+
}, V = () => {
|
|
706
769
|
i("error"), setTimeout(() => i("idle"), 2e3);
|
|
707
770
|
};
|
|
708
|
-
let
|
|
709
|
-
return
|
|
710
|
-
if (!
|
|
711
|
-
const u =
|
|
771
|
+
let q;
|
|
772
|
+
return Kt(() => {
|
|
773
|
+
if (!q) return;
|
|
774
|
+
const u = ke(q, {
|
|
712
775
|
onShortTap: () => {
|
|
713
|
-
e() === "idle" ?
|
|
776
|
+
e() === "idle" ? _t("short-tap") : e() === "transcribing" && l === "short-tap" && lt();
|
|
714
777
|
},
|
|
715
778
|
onLongPressStart: () => {
|
|
716
|
-
e() === "idle" &&
|
|
779
|
+
e() === "idle" && _t("long-press");
|
|
717
780
|
},
|
|
718
781
|
onLongPressEnd: () => {
|
|
719
|
-
e() === "transcribing" && l === "long-press" &&
|
|
782
|
+
e() === "transcribing" && l === "long-press" && lt();
|
|
720
783
|
}
|
|
721
784
|
});
|
|
722
|
-
|
|
785
|
+
vt(u);
|
|
723
786
|
}), (() => {
|
|
724
|
-
var u =
|
|
725
|
-
|
|
726
|
-
var
|
|
727
|
-
return typeof
|
|
728
|
-
var
|
|
729
|
-
return () =>
|
|
730
|
-
})(), null),
|
|
731
|
-
var
|
|
732
|
-
return () =>
|
|
733
|
-
})(), null),
|
|
734
|
-
var
|
|
735
|
-
return () =>
|
|
736
|
-
})(), null),
|
|
737
|
-
var
|
|
738
|
-
return () =>
|
|
739
|
-
})(), null),
|
|
740
|
-
var
|
|
741
|
-
return
|
|
787
|
+
var u = fe(), y = u.firstChild, m = y.nextSibling, p = m.nextSibling;
|
|
788
|
+
P(y, de), P(m, () => xt(e()));
|
|
789
|
+
var D = q;
|
|
790
|
+
return typeof D == "function" ? Zt(D, p) : q = p, P(p, (() => {
|
|
791
|
+
var f = Z(() => e() === "idle");
|
|
792
|
+
return () => f() && X(Ee, {});
|
|
793
|
+
})(), null), P(p, (() => {
|
|
794
|
+
var f = Z(() => e() === "transcribing");
|
|
795
|
+
return () => f() && X(xe, {});
|
|
796
|
+
})(), null), P(p, (() => {
|
|
797
|
+
var f = Z(() => e() === "finalizing");
|
|
798
|
+
return () => f() && X(Te, {});
|
|
799
|
+
})(), null), P(p, (() => {
|
|
800
|
+
var f = Z(() => e() === "error");
|
|
801
|
+
return () => f() && X(Ae, {});
|
|
802
|
+
})(), null), tt((f) => {
|
|
803
|
+
var at = `width:${t.size}px;height:${t.size}px"`, J = Se(e()), N = xt(e()), j = e() === "transcribing", S = e() === "transcribing" || e() === "finalizing";
|
|
804
|
+
return f.e = Xt(p, at, f.e), J !== f.t && B(p, "title", f.t = J), N !== f.a && B(p, "aria-label", f.a = N), j !== f.o && B(p, "aria-pressed", f.o = j), S !== f.i && B(p, "aria-busy", f.i = S), f;
|
|
742
805
|
}, {
|
|
743
806
|
e: void 0,
|
|
744
807
|
t: void 0,
|
|
@@ -748,36 +811,36 @@ customElements.get("dictate-button") ? console.debug("[dictate-button] We don't
|
|
|
748
811
|
}), u;
|
|
749
812
|
})();
|
|
750
813
|
});
|
|
751
|
-
const
|
|
814
|
+
const Se = (t) => {
|
|
752
815
|
switch (t) {
|
|
753
816
|
case "idle":
|
|
754
|
-
return `Start dictation (${
|
|
817
|
+
return `Start dictation (${T})`;
|
|
755
818
|
case "transcribing":
|
|
756
|
-
return `Stop dictation (${
|
|
819
|
+
return `Stop dictation (${T})`;
|
|
757
820
|
case "finalizing":
|
|
758
|
-
return `Finalizing dictation (${
|
|
821
|
+
return `Finalizing dictation (${T})`;
|
|
759
822
|
case "error":
|
|
760
|
-
return `Click to reset (${
|
|
823
|
+
return `Click to reset (${T})`;
|
|
761
824
|
}
|
|
762
|
-
},
|
|
825
|
+
}, xt = (t) => {
|
|
763
826
|
switch (t) {
|
|
764
827
|
case "idle":
|
|
765
|
-
return `Start dictation (${
|
|
828
|
+
return `Start dictation (${T})`;
|
|
766
829
|
case "transcribing":
|
|
767
|
-
return `Transcribing. Click to stop (${
|
|
830
|
+
return `Transcribing. Click to stop (${T})`;
|
|
768
831
|
case "finalizing":
|
|
769
|
-
return `Finalizing dictation. Please wait (${
|
|
832
|
+
return `Finalizing dictation. Please wait (${T})`;
|
|
770
833
|
case "error":
|
|
771
|
-
return `Dictation error. Click to reset (${
|
|
834
|
+
return `Dictation error. Click to reset (${T})`;
|
|
772
835
|
}
|
|
773
|
-
},
|
|
836
|
+
}, E = (t, n, e) => {
|
|
774
837
|
t.dispatchEvent(new CustomEvent(n, {
|
|
775
838
|
detail: e,
|
|
776
839
|
bubbles: !0,
|
|
777
840
|
composed: !0
|
|
778
841
|
}));
|
|
779
|
-
},
|
|
780
|
-
function
|
|
842
|
+
}, Ee = () => pe(), xe = () => he(), Ae = () => ge(), Te = () => be();
|
|
843
|
+
function ke(t, {
|
|
781
844
|
threshold: n = 500,
|
|
782
845
|
preventScroll: e = !0,
|
|
783
846
|
onShortTap: i,
|
|
@@ -785,26 +848,26 @@ function ye(t, {
|
|
|
785
848
|
onLongPressEnd: o
|
|
786
849
|
} = {}) {
|
|
787
850
|
let l, s = !1;
|
|
788
|
-
const a = (c) => c.preventDefault(),
|
|
851
|
+
const a = (c) => c.preventDefault(), h = (c) => {
|
|
789
852
|
l && clearTimeout(l), s = !1, c.preventDefault(), t.setPointerCapture(c.pointerId), l = window.setTimeout(() => {
|
|
790
853
|
s = !0, r?.(c), t.dispatchEvent(new CustomEvent("longpress", {
|
|
791
854
|
detail: c
|
|
792
855
|
}));
|
|
793
856
|
}, n);
|
|
794
|
-
},
|
|
857
|
+
}, d = (c) => {
|
|
795
858
|
l && clearTimeout(l), t.releasePointerCapture(c.pointerId), s ? (o?.(c), t.dispatchEvent(new CustomEvent("longpressend", {
|
|
796
859
|
detail: c
|
|
797
860
|
}))) : (i?.(c), t.dispatchEvent(new CustomEvent("shorttap", {
|
|
798
861
|
detail: c
|
|
799
862
|
})));
|
|
800
|
-
},
|
|
863
|
+
}, w = (c) => {
|
|
801
864
|
l && clearTimeout(l), t.releasePointerCapture(c.pointerId), s && (o?.(c), t.dispatchEvent(new CustomEvent("longpressend", {
|
|
802
865
|
detail: c
|
|
803
866
|
}))), s = !1;
|
|
804
|
-
},
|
|
867
|
+
}, C = (c) => {
|
|
805
868
|
c.preventDefault(), c.stopPropagation();
|
|
806
869
|
};
|
|
807
|
-
return e && (t.style.touchAction = "none", t.addEventListener("contextmenu", a)), t.addEventListener("pointerdown",
|
|
808
|
-
e && t.removeEventListener("contextmenu", a), t.removeEventListener("pointerdown",
|
|
870
|
+
return e && (t.style.touchAction = "none", t.addEventListener("contextmenu", a)), t.addEventListener("pointerdown", h), t.addEventListener("pointerup", d), t.addEventListener("pointercancel", w), t.addEventListener("click", C), () => {
|
|
871
|
+
e && t.removeEventListener("contextmenu", a), t.removeEventListener("pointerdown", h), t.removeEventListener("pointerup", d), t.removeEventListener("pointercancel", w), t.removeEventListener("click", C);
|
|
809
872
|
};
|
|
810
873
|
}
|
|
@@ -15,12 +15,12 @@ function S(t, o = {}) {
|
|
|
15
15
|
const g = v(u);
|
|
16
16
|
e.style.paddingRight = `${n + g * 2}px`;
|
|
17
17
|
const s = document.createElement("dictate-button");
|
|
18
|
-
s.size = n, s.style.position = "absolute", s.style.right = "0", s.style.top = E(
|
|
18
|
+
s.size = n, s.style.position = "absolute", s.style.right = "0", s.style.top = `${E(
|
|
19
19
|
r,
|
|
20
20
|
u,
|
|
21
21
|
e.tagName,
|
|
22
22
|
n
|
|
23
|
-
)
|
|
23
|
+
)}px`, s.style.marginRight = s.style.marginLeft = `${g}px`, s.style.marginTop = "0", s.style.marginBottom = "0", c && (s.apiEndpoint = c), s.language = y();
|
|
24
24
|
let f = null, h = 0;
|
|
25
25
|
s.addEventListener("dictate-start", (p) => {
|
|
26
26
|
l && console.debug("dictate-start", p), f = e.selectionStart ?? e.value.length, h = 0, b(e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dictate-button",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Customizable Web Component that adds speech-to-text dictation capabilities to text fields",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"custom-element",
|
|
@@ -60,20 +60,21 @@
|
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"solid-element": "^1.9.1",
|
|
63
|
-
"solid-js": "^1.9.
|
|
63
|
+
"solid-js": "^1.9.11"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
+
"@biomejs/biome": "^2.4.4",
|
|
66
67
|
"@solidjs/testing-library": "^0.8.10",
|
|
68
|
+
"@testing-library/dom": "^10.4.1",
|
|
67
69
|
"@testing-library/user-event": "^14.6.1",
|
|
68
|
-
"@vitest/ui": "^4.0.
|
|
69
|
-
"jsdom": "^
|
|
70
|
-
"prettier": "^3.8.0",
|
|
70
|
+
"@vitest/ui": "^4.0.18",
|
|
71
|
+
"jsdom": "^28.1.0",
|
|
71
72
|
"typescript": "^5.9.3",
|
|
72
73
|
"vite": "^7.3.1",
|
|
73
74
|
"vite-plugin-dts": "^4.5.4",
|
|
74
75
|
"vite-plugin-solid": "^2.11.10",
|
|
75
|
-
"vite-plugin-static-copy": "^3.
|
|
76
|
-
"vitest": "^4.0.
|
|
76
|
+
"vite-plugin-static-copy": "^3.2.0",
|
|
77
|
+
"vitest": "^4.0.18"
|
|
77
78
|
},
|
|
78
79
|
"homepage": "https://github.com/dictate-button/dictate-button",
|
|
79
80
|
"repository": {
|
|
@@ -85,8 +86,11 @@
|
|
|
85
86
|
},
|
|
86
87
|
"scripts": {
|
|
87
88
|
"build": "vite build",
|
|
88
|
-
"format": "prettier --write './src/**/*.{js,jsx,ts,tsx}'",
|
|
89
89
|
"deploy": "firebase deploy",
|
|
90
|
+
"format": "biome format --write .",
|
|
91
|
+
"lint": "biome lint .",
|
|
92
|
+
"check": "biome check .",
|
|
93
|
+
"typecheck": "tsc --noEmit",
|
|
90
94
|
"test": "vitest run",
|
|
91
95
|
"test:watch": "vitest",
|
|
92
96
|
"test:ui": "vitest --ui"
|