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